clock.c 1.5 KB

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