ap807_clocks_init.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2018 Marvell International Ltd.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. * https://spdx.org/licenses
  6. */
  7. #include <drivers/delay_timer.h>
  8. #include <drivers/marvell/aro.h>
  9. #include <lib/mmio.h>
  10. #include <a8k_plat_def.h>
  11. /* Notify bootloader on DRAM setup */
  12. #define AP807_CPU_ARO_CTRL(cluster) \
  13. (MVEBU_RFU_BASE + 0x82A8 + (0xA58 * (cluster)))
  14. /* 0 - ARO clock is enabled, 1 - ARO clock is disabled */
  15. #define AP807_CPU_ARO_CLK_EN_OFFSET 0
  16. #define AP807_CPU_ARO_CLK_EN_MASK (0x1 << AP807_CPU_ARO_CLK_EN_OFFSET)
  17. /* 0 - ARO is the clock source, 1 - PLL is the clock source */
  18. #define AP807_CPU_ARO_SEL_PLL_OFFSET 5
  19. #define AP807_CPU_ARO_SEL_PLL_MASK (0x1 << AP807_CPU_ARO_SEL_PLL_OFFSET)
  20. /* AP807 clusters count */
  21. #define AP807_CLUSTER_NUM 2
  22. /* PLL frequency values */
  23. #define PLL_FREQ_1200 0x2AE5F002 /* 1200 */
  24. #define PLL_FREQ_2000 0x2FC9F002 /* 2000 */
  25. #define PLL_FREQ_2200 0x2AC57001 /* 2200 */
  26. #define PLL_FREQ_2400 0x2AE5F001 /* 2400 */
  27. /* CPU PLL control registers */
  28. #define AP807_CPU_PLL_CTRL(cluster) \
  29. (MVEBU_RFU_BASE + 0x82E0 + (0x8 * (cluster)))
  30. #define AP807_CPU_PLL_PARAM(cluster) AP807_CPU_PLL_CTRL(cluster)
  31. #define AP807_CPU_PLL_CFG(cluster) (AP807_CPU_PLL_CTRL(cluster) + 0x4)
  32. #define AP807_CPU_PLL_CFG_BYPASS_MODE (0x1)
  33. #define AP807_CPU_PLL_FRC_DSCHG (0x2)
  34. #define AP807_CPU_PLL_CFG_USE_REG_FILE (0x1 << 9)
  35. static void pll_set_freq(unsigned int freq_val)
  36. {
  37. int i;
  38. if (freq_val != PLL_FREQ_2200)
  39. return;
  40. for (i = 0 ; i < AP807_CLUSTER_NUM ; i++) {
  41. /* Set parameter of cluster i PLL to 2.2GHz */
  42. mmio_write_32(AP807_CPU_PLL_PARAM(i), freq_val);
  43. /* Set apll_lpf_frc_dschg - Control
  44. * voltage of internal VCO is discharged
  45. */
  46. mmio_write_32(AP807_CPU_PLL_CFG(i),
  47. AP807_CPU_PLL_FRC_DSCHG);
  48. /* Set use_rf_conf load PLL parameter from register */
  49. mmio_write_32(AP807_CPU_PLL_CFG(i),
  50. AP807_CPU_PLL_FRC_DSCHG |
  51. AP807_CPU_PLL_CFG_USE_REG_FILE);
  52. /* Un-set apll_lpf_frc_dschg */
  53. mmio_write_32(AP807_CPU_PLL_CFG(i),
  54. AP807_CPU_PLL_CFG_USE_REG_FILE);
  55. }
  56. }
  57. /* Switch to ARO from PLL in ap807 */
  58. static void aro_to_pll(void)
  59. {
  60. unsigned int reg;
  61. int i;
  62. for (i = 0 ; i < AP807_CLUSTER_NUM ; i++) {
  63. /* switch from ARO to PLL */
  64. reg = mmio_read_32(AP807_CPU_ARO_CTRL(i));
  65. reg |= AP807_CPU_ARO_SEL_PLL_MASK;
  66. mmio_write_32(AP807_CPU_ARO_CTRL(i), reg);
  67. mdelay(100);
  68. /* disable ARO clk driver */
  69. reg = mmio_read_32(AP807_CPU_ARO_CTRL(i));
  70. reg |= (AP807_CPU_ARO_CLK_EN_MASK);
  71. mmio_write_32(AP807_CPU_ARO_CTRL(i), reg);
  72. }
  73. }
  74. /* switch from ARO to PLL
  75. * in case of default frequency option, configure PLL registers
  76. * to be aligned with new default frequency.
  77. */
  78. void ap807_clocks_init(unsigned int freq_option)
  79. {
  80. /* Modifications in frequency table:
  81. * 0x0: 764x: change to 2000 MHz.
  82. * 0x2: 744x change to 1800 MHz, 764x change to 2200/2400.
  83. * 0x3: 3900/744x/764x change to 1200 MHz.
  84. */
  85. if (freq_option == CPU_2200_DDR_1200_RCLK_1200)
  86. pll_set_freq(PLL_FREQ_2200);
  87. /* Switch from ARO to PLL */
  88. aro_to_pll();
  89. }