clock.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * (C) Copyright 2007-2012
  3. * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
  4. * Tom Cubie <tangliang@allwinnertech.com>
  5. *
  6. * (C) Copyright 2013 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/clock.h>
  13. #include <asm/arch/gpio.h>
  14. #include <asm/arch/prcm.h>
  15. #include <asm/arch/gtbus.h>
  16. #include <asm/arch/sys_proto.h>
  17. __weak void clock_init_sec(void)
  18. {
  19. }
  20. __weak void gtbus_init(void)
  21. {
  22. }
  23. int clock_init(void)
  24. {
  25. #ifdef CONFIG_SPL_BUILD
  26. clock_init_safe();
  27. gtbus_init();
  28. #endif
  29. clock_init_uart();
  30. clock_init_sec();
  31. return 0;
  32. }
  33. /* These functions are shared between various SoCs so put them here. */
  34. #if defined CONFIG_SUNXI_GEN_SUN6I && !defined CONFIG_MACH_SUN9I
  35. int clock_twi_onoff(int port, int state)
  36. {
  37. struct sunxi_ccm_reg *const ccm =
  38. (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
  39. if (port == 5) {
  40. if (state)
  41. prcm_apb0_enable(
  42. PRCM_APB0_GATE_PIO | PRCM_APB0_GATE_I2C);
  43. else
  44. prcm_apb0_disable(
  45. PRCM_APB0_GATE_PIO | PRCM_APB0_GATE_I2C);
  46. return 0;
  47. }
  48. /* set the apb clock gate and reset for twi */
  49. if (state) {
  50. setbits_le32(&ccm->apb2_gate,
  51. CLK_GATE_OPEN << (APB2_GATE_TWI_SHIFT + port));
  52. setbits_le32(&ccm->apb2_reset_cfg,
  53. 1 << (APB2_RESET_TWI_SHIFT + port));
  54. } else {
  55. clrbits_le32(&ccm->apb2_reset_cfg,
  56. 1 << (APB2_RESET_TWI_SHIFT + port));
  57. clrbits_le32(&ccm->apb2_gate,
  58. CLK_GATE_OPEN << (APB2_GATE_TWI_SHIFT + port));
  59. }
  60. return 0;
  61. }
  62. #endif