clk-ns2.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. // Copyright (C) 2015 Broadcom Corporation
  3. #include <linux/kernel.h>
  4. #include <linux/err.h>
  5. #include <linux/clk-provider.h>
  6. #include <linux/io.h>
  7. #include <linux/of.h>
  8. #include <linux/of_address.h>
  9. #include <dt-bindings/clock/bcm-ns2.h>
  10. #include "clk-iproc.h"
  11. #define REG_VAL(o, s, w) { .offset = o, .shift = s, .width = w, }
  12. #define AON_VAL(o, pw, ps, is) { .offset = o, .pwr_width = pw, \
  13. .pwr_shift = ps, .iso_shift = is }
  14. #define RESET_VAL(o, rs, prs) { .offset = o, .reset_shift = rs, \
  15. .p_reset_shift = prs }
  16. #define DF_VAL(o, kis, kiw, kps, kpw, kas, kaw) { .offset = o, .ki_shift = kis,\
  17. .ki_width = kiw, .kp_shift = kps, .kp_width = kpw, .ka_shift = kas, \
  18. .ka_width = kaw }
  19. #define VCO_CTRL_VAL(uo, lo) { .u_offset = uo, .l_offset = lo }
  20. #define ENABLE_VAL(o, es, hs, bs) { .offset = o, .enable_shift = es, \
  21. .hold_shift = hs, .bypass_shift = bs }
  22. static const struct iproc_pll_ctrl genpll_scr = {
  23. .flags = IPROC_CLK_AON | IPROC_CLK_PLL_SPLIT_STAT_CTRL,
  24. .aon = AON_VAL(0x0, 1, 15, 12),
  25. .reset = RESET_VAL(0x4, 2, 1),
  26. .dig_filter = DF_VAL(0x0, 9, 3, 5, 4, 2, 3),
  27. .ndiv_int = REG_VAL(0x8, 4, 10),
  28. .pdiv = REG_VAL(0x8, 0, 4),
  29. .vco_ctrl = VCO_CTRL_VAL(0x10, 0xc),
  30. .status = REG_VAL(0x0, 27, 1),
  31. };
  32. static const struct iproc_clk_ctrl genpll_scr_clk[] = {
  33. /* bypass_shift, the last value passed into ENABLE_VAL(), is not defined
  34. * in NS2. However, it doesn't appear to be used anywhere, so setting
  35. * it to 0.
  36. */
  37. [BCM_NS2_GENPLL_SCR_SCR_CLK] = {
  38. .channel = BCM_NS2_GENPLL_SCR_SCR_CLK,
  39. .flags = IPROC_CLK_AON,
  40. .enable = ENABLE_VAL(0x0, 18, 12, 0),
  41. .mdiv = REG_VAL(0x18, 0, 8),
  42. },
  43. [BCM_NS2_GENPLL_SCR_FS_CLK] = {
  44. .channel = BCM_NS2_GENPLL_SCR_FS_CLK,
  45. .flags = IPROC_CLK_AON,
  46. .enable = ENABLE_VAL(0x0, 19, 13, 0),
  47. .mdiv = REG_VAL(0x18, 8, 8),
  48. },
  49. [BCM_NS2_GENPLL_SCR_AUDIO_CLK] = {
  50. .channel = BCM_NS2_GENPLL_SCR_AUDIO_CLK,
  51. .flags = IPROC_CLK_AON,
  52. .enable = ENABLE_VAL(0x0, 20, 14, 0),
  53. .mdiv = REG_VAL(0x14, 0, 8),
  54. },
  55. [BCM_NS2_GENPLL_SCR_CH3_UNUSED] = {
  56. .channel = BCM_NS2_GENPLL_SCR_CH3_UNUSED,
  57. .flags = IPROC_CLK_AON,
  58. .enable = ENABLE_VAL(0x0, 21, 15, 0),
  59. .mdiv = REG_VAL(0x14, 8, 8),
  60. },
  61. [BCM_NS2_GENPLL_SCR_CH4_UNUSED] = {
  62. .channel = BCM_NS2_GENPLL_SCR_CH4_UNUSED,
  63. .flags = IPROC_CLK_AON,
  64. .enable = ENABLE_VAL(0x0, 22, 16, 0),
  65. .mdiv = REG_VAL(0x14, 16, 8),
  66. },
  67. [BCM_NS2_GENPLL_SCR_CH5_UNUSED] = {
  68. .channel = BCM_NS2_GENPLL_SCR_CH5_UNUSED,
  69. .flags = IPROC_CLK_AON,
  70. .enable = ENABLE_VAL(0x0, 23, 17, 0),
  71. .mdiv = REG_VAL(0x14, 24, 8),
  72. },
  73. };
  74. static void __init ns2_genpll_scr_clk_init(struct device_node *node)
  75. {
  76. iproc_pll_clk_setup(node, &genpll_scr, NULL, 0, genpll_scr_clk,
  77. ARRAY_SIZE(genpll_scr_clk));
  78. }
  79. CLK_OF_DECLARE(ns2_genpll_src_clk, "brcm,ns2-genpll-scr",
  80. ns2_genpll_scr_clk_init);
  81. static const struct iproc_pll_ctrl genpll_sw = {
  82. .flags = IPROC_CLK_AON | IPROC_CLK_PLL_SPLIT_STAT_CTRL,
  83. .aon = AON_VAL(0x0, 1, 11, 10),
  84. .reset = RESET_VAL(0x4, 2, 1),
  85. .dig_filter = DF_VAL(0x0, 9, 3, 5, 4, 2, 3),
  86. .ndiv_int = REG_VAL(0x8, 4, 10),
  87. .pdiv = REG_VAL(0x8, 0, 4),
  88. .vco_ctrl = VCO_CTRL_VAL(0x10, 0xc),
  89. .status = REG_VAL(0x0, 13, 1),
  90. };
  91. static const struct iproc_clk_ctrl genpll_sw_clk[] = {
  92. /* bypass_shift, the last value passed into ENABLE_VAL(), is not defined
  93. * in NS2. However, it doesn't appear to be used anywhere, so setting
  94. * it to 0.
  95. */
  96. [BCM_NS2_GENPLL_SW_RPE_CLK] = {
  97. .channel = BCM_NS2_GENPLL_SW_RPE_CLK,
  98. .flags = IPROC_CLK_AON,
  99. .enable = ENABLE_VAL(0x0, 18, 12, 0),
  100. .mdiv = REG_VAL(0x18, 0, 8),
  101. },
  102. [BCM_NS2_GENPLL_SW_250_CLK] = {
  103. .channel = BCM_NS2_GENPLL_SW_250_CLK,
  104. .flags = IPROC_CLK_AON,
  105. .enable = ENABLE_VAL(0x0, 19, 13, 0),
  106. .mdiv = REG_VAL(0x18, 8, 8),
  107. },
  108. [BCM_NS2_GENPLL_SW_NIC_CLK] = {
  109. .channel = BCM_NS2_GENPLL_SW_NIC_CLK,
  110. .flags = IPROC_CLK_AON,
  111. .enable = ENABLE_VAL(0x0, 20, 14, 0),
  112. .mdiv = REG_VAL(0x14, 0, 8),
  113. },
  114. [BCM_NS2_GENPLL_SW_CHIMP_CLK] = {
  115. .channel = BCM_NS2_GENPLL_SW_CHIMP_CLK,
  116. .flags = IPROC_CLK_AON,
  117. .enable = ENABLE_VAL(0x0, 21, 15, 0),
  118. .mdiv = REG_VAL(0x14, 8, 8),
  119. },
  120. [BCM_NS2_GENPLL_SW_PORT_CLK] = {
  121. .channel = BCM_NS2_GENPLL_SW_PORT_CLK,
  122. .flags = IPROC_CLK_AON,
  123. .enable = ENABLE_VAL(0x0, 22, 16, 0),
  124. .mdiv = REG_VAL(0x14, 16, 8),
  125. },
  126. [BCM_NS2_GENPLL_SW_SDIO_CLK] = {
  127. .channel = BCM_NS2_GENPLL_SW_SDIO_CLK,
  128. .flags = IPROC_CLK_AON,
  129. .enable = ENABLE_VAL(0x0, 23, 17, 0),
  130. .mdiv = REG_VAL(0x14, 24, 8),
  131. },
  132. };
  133. static void __init ns2_genpll_sw_clk_init(struct device_node *node)
  134. {
  135. iproc_pll_clk_setup(node, &genpll_sw, NULL, 0, genpll_sw_clk,
  136. ARRAY_SIZE(genpll_sw_clk));
  137. }
  138. CLK_OF_DECLARE(ns2_genpll_sw_clk, "brcm,ns2-genpll-sw",
  139. ns2_genpll_sw_clk_init);
  140. static const struct iproc_pll_ctrl lcpll_ddr = {
  141. .flags = IPROC_CLK_AON | IPROC_CLK_PLL_SPLIT_STAT_CTRL,
  142. .aon = AON_VAL(0x0, 2, 1, 0),
  143. .reset = RESET_VAL(0x4, 2, 1),
  144. .dig_filter = DF_VAL(0x0, 9, 3, 5, 4, 1, 4),
  145. .ndiv_int = REG_VAL(0x8, 4, 10),
  146. .pdiv = REG_VAL(0x8, 0, 4),
  147. .vco_ctrl = VCO_CTRL_VAL(0x10, 0xc),
  148. .status = REG_VAL(0x0, 0, 1),
  149. };
  150. static const struct iproc_clk_ctrl lcpll_ddr_clk[] = {
  151. /* bypass_shift, the last value passed into ENABLE_VAL(), is not defined
  152. * in NS2. However, it doesn't appear to be used anywhere, so setting
  153. * it to 0.
  154. */
  155. [BCM_NS2_LCPLL_DDR_PCIE_SATA_USB_CLK] = {
  156. .channel = BCM_NS2_LCPLL_DDR_PCIE_SATA_USB_CLK,
  157. .flags = IPROC_CLK_AON,
  158. .enable = ENABLE_VAL(0x0, 18, 12, 0),
  159. .mdiv = REG_VAL(0x14, 0, 8),
  160. },
  161. [BCM_NS2_LCPLL_DDR_DDR_CLK] = {
  162. .channel = BCM_NS2_LCPLL_DDR_DDR_CLK,
  163. .flags = IPROC_CLK_AON,
  164. .enable = ENABLE_VAL(0x0, 19, 13, 0),
  165. .mdiv = REG_VAL(0x14, 8, 8),
  166. },
  167. [BCM_NS2_LCPLL_DDR_CH2_UNUSED] = {
  168. .channel = BCM_NS2_LCPLL_DDR_CH2_UNUSED,
  169. .flags = IPROC_CLK_AON,
  170. .enable = ENABLE_VAL(0x0, 20, 14, 0),
  171. .mdiv = REG_VAL(0x10, 0, 8),
  172. },
  173. [BCM_NS2_LCPLL_DDR_CH3_UNUSED] = {
  174. .channel = BCM_NS2_LCPLL_DDR_CH3_UNUSED,
  175. .flags = IPROC_CLK_AON,
  176. .enable = ENABLE_VAL(0x0, 21, 15, 0),
  177. .mdiv = REG_VAL(0x10, 8, 8),
  178. },
  179. [BCM_NS2_LCPLL_DDR_CH4_UNUSED] = {
  180. .channel = BCM_NS2_LCPLL_DDR_CH4_UNUSED,
  181. .flags = IPROC_CLK_AON,
  182. .enable = ENABLE_VAL(0x0, 22, 16, 0),
  183. .mdiv = REG_VAL(0x10, 16, 8),
  184. },
  185. [BCM_NS2_LCPLL_DDR_CH5_UNUSED] = {
  186. .channel = BCM_NS2_LCPLL_DDR_CH5_UNUSED,
  187. .flags = IPROC_CLK_AON,
  188. .enable = ENABLE_VAL(0x0, 23, 17, 0),
  189. .mdiv = REG_VAL(0x10, 24, 8),
  190. },
  191. };
  192. static void __init ns2_lcpll_ddr_clk_init(struct device_node *node)
  193. {
  194. iproc_pll_clk_setup(node, &lcpll_ddr, NULL, 0, lcpll_ddr_clk,
  195. ARRAY_SIZE(lcpll_ddr_clk));
  196. }
  197. CLK_OF_DECLARE(ns2_lcpll_ddr_clk, "brcm,ns2-lcpll-ddr",
  198. ns2_lcpll_ddr_clk_init);
  199. static const struct iproc_pll_ctrl lcpll_ports = {
  200. .flags = IPROC_CLK_AON | IPROC_CLK_PLL_SPLIT_STAT_CTRL,
  201. .aon = AON_VAL(0x0, 2, 5, 4),
  202. .reset = RESET_VAL(0x4, 2, 1),
  203. .dig_filter = DF_VAL(0x0, 9, 3, 5, 4, 1, 4),
  204. .ndiv_int = REG_VAL(0x8, 4, 10),
  205. .pdiv = REG_VAL(0x8, 0, 4),
  206. .vco_ctrl = VCO_CTRL_VAL(0x10, 0xc),
  207. .status = REG_VAL(0x0, 0, 1),
  208. };
  209. static const struct iproc_clk_ctrl lcpll_ports_clk[] = {
  210. /* bypass_shift, the last value passed into ENABLE_VAL(), is not defined
  211. * in NS2. However, it doesn't appear to be used anywhere, so setting
  212. * it to 0.
  213. */
  214. [BCM_NS2_LCPLL_PORTS_WAN_CLK] = {
  215. .channel = BCM_NS2_LCPLL_PORTS_WAN_CLK,
  216. .flags = IPROC_CLK_AON,
  217. .enable = ENABLE_VAL(0x0, 18, 12, 0),
  218. .mdiv = REG_VAL(0x14, 0, 8),
  219. },
  220. [BCM_NS2_LCPLL_PORTS_RGMII_CLK] = {
  221. .channel = BCM_NS2_LCPLL_PORTS_RGMII_CLK,
  222. .flags = IPROC_CLK_AON,
  223. .enable = ENABLE_VAL(0x0, 19, 13, 0),
  224. .mdiv = REG_VAL(0x14, 8, 8),
  225. },
  226. [BCM_NS2_LCPLL_PORTS_CH2_UNUSED] = {
  227. .channel = BCM_NS2_LCPLL_PORTS_CH2_UNUSED,
  228. .flags = IPROC_CLK_AON,
  229. .enable = ENABLE_VAL(0x0, 20, 14, 0),
  230. .mdiv = REG_VAL(0x10, 0, 8),
  231. },
  232. [BCM_NS2_LCPLL_PORTS_CH3_UNUSED] = {
  233. .channel = BCM_NS2_LCPLL_PORTS_CH3_UNUSED,
  234. .flags = IPROC_CLK_AON,
  235. .enable = ENABLE_VAL(0x0, 21, 15, 0),
  236. .mdiv = REG_VAL(0x10, 8, 8),
  237. },
  238. [BCM_NS2_LCPLL_PORTS_CH4_UNUSED] = {
  239. .channel = BCM_NS2_LCPLL_PORTS_CH4_UNUSED,
  240. .flags = IPROC_CLK_AON,
  241. .enable = ENABLE_VAL(0x0, 22, 16, 0),
  242. .mdiv = REG_VAL(0x10, 16, 8),
  243. },
  244. [BCM_NS2_LCPLL_PORTS_CH5_UNUSED] = {
  245. .channel = BCM_NS2_LCPLL_PORTS_CH5_UNUSED,
  246. .flags = IPROC_CLK_AON,
  247. .enable = ENABLE_VAL(0x0, 23, 17, 0),
  248. .mdiv = REG_VAL(0x10, 24, 8),
  249. },
  250. };
  251. static void __init ns2_lcpll_ports_clk_init(struct device_node *node)
  252. {
  253. iproc_pll_clk_setup(node, &lcpll_ports, NULL, 0, lcpll_ports_clk,
  254. ARRAY_SIZE(lcpll_ports_clk));
  255. }
  256. CLK_OF_DECLARE(ns2_lcpll_ports_clk, "brcm,ns2-lcpll-ports",
  257. ns2_lcpll_ports_clk_init);