clk-cygnus.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * Copyright (C) 2014 Broadcom Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation version 2.
  7. *
  8. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  9. * kind, whether express or implied; without even the implied warranty
  10. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/err.h>
  15. #include <linux/clk-provider.h>
  16. #include <linux/io.h>
  17. #include <linux/of.h>
  18. #include <linux/clkdev.h>
  19. #include <linux/of_address.h>
  20. #include <linux/delay.h>
  21. #include <dt-bindings/clock/bcm-cygnus.h>
  22. #include "clk-iproc.h"
  23. #define REG_VAL(o, s, w) { .offset = o, .shift = s, .width = w, }
  24. #define AON_VAL(o, pw, ps, is) { .offset = o, .pwr_width = pw, \
  25. .pwr_shift = ps, .iso_shift = is }
  26. #define SW_CTRL_VAL(o, s) { .offset = o, .shift = s, }
  27. #define ASIU_DIV_VAL(o, es, hs, hw, ls, lw) \
  28. { .offset = o, .en_shift = es, .high_shift = hs, \
  29. .high_width = hw, .low_shift = ls, .low_width = lw }
  30. #define RESET_VAL(o, rs, prs) { .offset = o, .reset_shift = rs, \
  31. .p_reset_shift = prs }
  32. #define DF_VAL(o, kis, kiw, kps, kpw, kas, kaw) { .offset = o, .ki_shift = kis,\
  33. .ki_width = kiw, .kp_shift = kps, .kp_width = kpw, .ka_shift = kas, \
  34. .ka_width = kaw }
  35. #define VCO_CTRL_VAL(uo, lo) { .u_offset = uo, .l_offset = lo }
  36. #define ENABLE_VAL(o, es, hs, bs) { .offset = o, .enable_shift = es, \
  37. .hold_shift = hs, .bypass_shift = bs }
  38. #define ASIU_GATE_VAL(o, es) { .offset = o, .en_shift = es }
  39. static void __init cygnus_armpll_init(struct device_node *node)
  40. {
  41. iproc_armpll_setup(node);
  42. }
  43. CLK_OF_DECLARE(cygnus_armpll, "brcm,cygnus-armpll", cygnus_armpll_init);
  44. static const struct iproc_pll_ctrl genpll = {
  45. .flags = IPROC_CLK_AON | IPROC_CLK_PLL_HAS_NDIV_FRAC |
  46. IPROC_CLK_PLL_NEEDS_SW_CFG,
  47. .aon = AON_VAL(0x0, 2, 1, 0),
  48. .reset = RESET_VAL(0x0, 11, 10),
  49. .dig_filter = DF_VAL(0x0, 4, 3, 0, 4, 7, 3),
  50. .sw_ctrl = SW_CTRL_VAL(0x10, 31),
  51. .ndiv_int = REG_VAL(0x10, 20, 10),
  52. .ndiv_frac = REG_VAL(0x10, 0, 20),
  53. .pdiv = REG_VAL(0x14, 0, 4),
  54. .vco_ctrl = VCO_CTRL_VAL(0x18, 0x1c),
  55. .status = REG_VAL(0x28, 12, 1),
  56. };
  57. static const struct iproc_clk_ctrl genpll_clk[] = {
  58. [BCM_CYGNUS_GENPLL_AXI21_CLK] = {
  59. .channel = BCM_CYGNUS_GENPLL_AXI21_CLK,
  60. .flags = IPROC_CLK_AON,
  61. .enable = ENABLE_VAL(0x4, 6, 0, 12),
  62. .mdiv = REG_VAL(0x20, 0, 8),
  63. },
  64. [BCM_CYGNUS_GENPLL_250MHZ_CLK] = {
  65. .channel = BCM_CYGNUS_GENPLL_250MHZ_CLK,
  66. .flags = IPROC_CLK_AON,
  67. .enable = ENABLE_VAL(0x4, 7, 1, 13),
  68. .mdiv = REG_VAL(0x20, 10, 8),
  69. },
  70. [BCM_CYGNUS_GENPLL_IHOST_SYS_CLK] = {
  71. .channel = BCM_CYGNUS_GENPLL_IHOST_SYS_CLK,
  72. .flags = IPROC_CLK_AON,
  73. .enable = ENABLE_VAL(0x4, 8, 2, 14),
  74. .mdiv = REG_VAL(0x20, 20, 8),
  75. },
  76. [BCM_CYGNUS_GENPLL_ENET_SW_CLK] = {
  77. .channel = BCM_CYGNUS_GENPLL_ENET_SW_CLK,
  78. .flags = IPROC_CLK_AON,
  79. .enable = ENABLE_VAL(0x4, 9, 3, 15),
  80. .mdiv = REG_VAL(0x24, 0, 8),
  81. },
  82. [BCM_CYGNUS_GENPLL_AUDIO_125_CLK] = {
  83. .channel = BCM_CYGNUS_GENPLL_AUDIO_125_CLK,
  84. .flags = IPROC_CLK_AON,
  85. .enable = ENABLE_VAL(0x4, 10, 4, 16),
  86. .mdiv = REG_VAL(0x24, 10, 8),
  87. },
  88. [BCM_CYGNUS_GENPLL_CAN_CLK] = {
  89. .channel = BCM_CYGNUS_GENPLL_CAN_CLK,
  90. .flags = IPROC_CLK_AON,
  91. .enable = ENABLE_VAL(0x4, 11, 5, 17),
  92. .mdiv = REG_VAL(0x24, 20, 8),
  93. },
  94. };
  95. static void __init cygnus_genpll_clk_init(struct device_node *node)
  96. {
  97. iproc_pll_clk_setup(node, &genpll, NULL, 0, genpll_clk,
  98. ARRAY_SIZE(genpll_clk));
  99. }
  100. CLK_OF_DECLARE(cygnus_genpll, "brcm,cygnus-genpll", cygnus_genpll_clk_init);
  101. static const struct iproc_pll_ctrl lcpll0 = {
  102. .flags = IPROC_CLK_AON | IPROC_CLK_PLL_NEEDS_SW_CFG,
  103. .aon = AON_VAL(0x0, 2, 5, 4),
  104. .reset = RESET_VAL(0x0, 31, 30),
  105. .dig_filter = DF_VAL(0x0, 27, 3, 23, 4, 19, 4),
  106. .sw_ctrl = SW_CTRL_VAL(0x4, 31),
  107. .ndiv_int = REG_VAL(0x4, 16, 10),
  108. .pdiv = REG_VAL(0x4, 26, 4),
  109. .vco_ctrl = VCO_CTRL_VAL(0x10, 0x14),
  110. .status = REG_VAL(0x18, 12, 1),
  111. };
  112. static const struct iproc_clk_ctrl lcpll0_clk[] = {
  113. [BCM_CYGNUS_LCPLL0_PCIE_PHY_REF_CLK] = {
  114. .channel = BCM_CYGNUS_LCPLL0_PCIE_PHY_REF_CLK,
  115. .flags = IPROC_CLK_AON,
  116. .enable = ENABLE_VAL(0x0, 7, 1, 13),
  117. .mdiv = REG_VAL(0x8, 0, 8),
  118. },
  119. [BCM_CYGNUS_LCPLL0_DDR_PHY_CLK] = {
  120. .channel = BCM_CYGNUS_LCPLL0_DDR_PHY_CLK,
  121. .flags = IPROC_CLK_AON,
  122. .enable = ENABLE_VAL(0x0, 8, 2, 14),
  123. .mdiv = REG_VAL(0x8, 10, 8),
  124. },
  125. [BCM_CYGNUS_LCPLL0_SDIO_CLK] = {
  126. .channel = BCM_CYGNUS_LCPLL0_SDIO_CLK,
  127. .flags = IPROC_CLK_AON,
  128. .enable = ENABLE_VAL(0x0, 9, 3, 15),
  129. .mdiv = REG_VAL(0x8, 20, 8),
  130. },
  131. [BCM_CYGNUS_LCPLL0_USB_PHY_REF_CLK] = {
  132. .channel = BCM_CYGNUS_LCPLL0_USB_PHY_REF_CLK,
  133. .flags = IPROC_CLK_AON,
  134. .enable = ENABLE_VAL(0x0, 10, 4, 16),
  135. .mdiv = REG_VAL(0xc, 0, 8),
  136. },
  137. [BCM_CYGNUS_LCPLL0_SMART_CARD_CLK] = {
  138. .channel = BCM_CYGNUS_LCPLL0_SMART_CARD_CLK,
  139. .flags = IPROC_CLK_AON,
  140. .enable = ENABLE_VAL(0x0, 11, 5, 17),
  141. .mdiv = REG_VAL(0xc, 10, 8),
  142. },
  143. [BCM_CYGNUS_LCPLL0_CH5_UNUSED] = {
  144. .channel = BCM_CYGNUS_LCPLL0_CH5_UNUSED,
  145. .flags = IPROC_CLK_AON,
  146. .enable = ENABLE_VAL(0x0, 12, 6, 18),
  147. .mdiv = REG_VAL(0xc, 20, 8),
  148. },
  149. };
  150. static void __init cygnus_lcpll0_clk_init(struct device_node *node)
  151. {
  152. iproc_pll_clk_setup(node, &lcpll0, NULL, 0, lcpll0_clk,
  153. ARRAY_SIZE(lcpll0_clk));
  154. }
  155. CLK_OF_DECLARE(cygnus_lcpll0, "brcm,cygnus-lcpll0", cygnus_lcpll0_clk_init);
  156. /*
  157. * MIPI PLL VCO frequency parameter table
  158. */
  159. static const struct iproc_pll_vco_param mipipll_vco_params[] = {
  160. /* rate (Hz) ndiv_int ndiv_frac pdiv */
  161. { 750000000UL, 30, 0, 1 },
  162. { 1000000000UL, 40, 0, 1 },
  163. { 1350000000ul, 54, 0, 1 },
  164. { 2000000000UL, 80, 0, 1 },
  165. { 2100000000UL, 84, 0, 1 },
  166. { 2250000000UL, 90, 0, 1 },
  167. { 2500000000UL, 100, 0, 1 },
  168. { 2700000000UL, 54, 0, 0 },
  169. { 2975000000UL, 119, 0, 1 },
  170. { 3100000000UL, 124, 0, 1 },
  171. { 3150000000UL, 126, 0, 1 },
  172. };
  173. static const struct iproc_pll_ctrl mipipll = {
  174. .flags = IPROC_CLK_PLL_ASIU | IPROC_CLK_PLL_HAS_NDIV_FRAC |
  175. IPROC_CLK_NEEDS_READ_BACK,
  176. .aon = AON_VAL(0x0, 4, 17, 16),
  177. .asiu = ASIU_GATE_VAL(0x0, 3),
  178. .reset = RESET_VAL(0x0, 11, 10),
  179. .dig_filter = DF_VAL(0x0, 4, 3, 0, 4, 7, 4),
  180. .ndiv_int = REG_VAL(0x10, 20, 10),
  181. .ndiv_frac = REG_VAL(0x10, 0, 20),
  182. .pdiv = REG_VAL(0x14, 0, 4),
  183. .vco_ctrl = VCO_CTRL_VAL(0x18, 0x1c),
  184. .status = REG_VAL(0x28, 12, 1),
  185. };
  186. static const struct iproc_clk_ctrl mipipll_clk[] = {
  187. [BCM_CYGNUS_MIPIPLL_CH0_UNUSED] = {
  188. .channel = BCM_CYGNUS_MIPIPLL_CH0_UNUSED,
  189. .flags = IPROC_CLK_NEEDS_READ_BACK,
  190. .enable = ENABLE_VAL(0x4, 12, 6, 18),
  191. .mdiv = REG_VAL(0x20, 0, 8),
  192. },
  193. [BCM_CYGNUS_MIPIPLL_CH1_LCD] = {
  194. .channel = BCM_CYGNUS_MIPIPLL_CH1_LCD,
  195. .flags = IPROC_CLK_NEEDS_READ_BACK,
  196. .enable = ENABLE_VAL(0x4, 13, 7, 19),
  197. .mdiv = REG_VAL(0x20, 10, 8),
  198. },
  199. [BCM_CYGNUS_MIPIPLL_CH2_V3D] = {
  200. .channel = BCM_CYGNUS_MIPIPLL_CH2_V3D,
  201. .flags = IPROC_CLK_NEEDS_READ_BACK,
  202. .enable = ENABLE_VAL(0x4, 14, 8, 20),
  203. .mdiv = REG_VAL(0x20, 20, 8),
  204. },
  205. [BCM_CYGNUS_MIPIPLL_CH3_UNUSED] = {
  206. .channel = BCM_CYGNUS_MIPIPLL_CH3_UNUSED,
  207. .flags = IPROC_CLK_NEEDS_READ_BACK,
  208. .enable = ENABLE_VAL(0x4, 15, 9, 21),
  209. .mdiv = REG_VAL(0x24, 0, 8),
  210. },
  211. [BCM_CYGNUS_MIPIPLL_CH4_UNUSED] = {
  212. .channel = BCM_CYGNUS_MIPIPLL_CH4_UNUSED,
  213. .flags = IPROC_CLK_NEEDS_READ_BACK,
  214. .enable = ENABLE_VAL(0x4, 16, 10, 22),
  215. .mdiv = REG_VAL(0x24, 10, 8),
  216. },
  217. [BCM_CYGNUS_MIPIPLL_CH5_UNUSED] = {
  218. .channel = BCM_CYGNUS_MIPIPLL_CH5_UNUSED,
  219. .flags = IPROC_CLK_NEEDS_READ_BACK,
  220. .enable = ENABLE_VAL(0x4, 17, 11, 23),
  221. .mdiv = REG_VAL(0x24, 20, 8),
  222. },
  223. };
  224. static void __init cygnus_mipipll_clk_init(struct device_node *node)
  225. {
  226. iproc_pll_clk_setup(node, &mipipll, mipipll_vco_params,
  227. ARRAY_SIZE(mipipll_vco_params), mipipll_clk,
  228. ARRAY_SIZE(mipipll_clk));
  229. }
  230. CLK_OF_DECLARE(cygnus_mipipll, "brcm,cygnus-mipipll", cygnus_mipipll_clk_init);
  231. static const struct iproc_asiu_div asiu_div[] = {
  232. [BCM_CYGNUS_ASIU_KEYPAD_CLK] = ASIU_DIV_VAL(0x0, 31, 16, 10, 0, 10),
  233. [BCM_CYGNUS_ASIU_ADC_CLK] = ASIU_DIV_VAL(0x4, 31, 16, 10, 0, 10),
  234. [BCM_CYGNUS_ASIU_PWM_CLK] = ASIU_DIV_VAL(0x8, 31, 16, 10, 0, 10),
  235. };
  236. static const struct iproc_asiu_gate asiu_gate[] = {
  237. [BCM_CYGNUS_ASIU_KEYPAD_CLK] = ASIU_GATE_VAL(0x0, 7),
  238. [BCM_CYGNUS_ASIU_ADC_CLK] = ASIU_GATE_VAL(0x0, 9),
  239. [BCM_CYGNUS_ASIU_PWM_CLK] = ASIU_GATE_VAL(IPROC_CLK_INVALID_OFFSET, 0),
  240. };
  241. static void __init cygnus_asiu_init(struct device_node *node)
  242. {
  243. iproc_asiu_setup(node, asiu_div, asiu_gate, ARRAY_SIZE(asiu_div));
  244. }
  245. CLK_OF_DECLARE(cygnus_asiu_clk, "brcm,cygnus-asiu-clk", cygnus_asiu_init);