clk-ns2.c 8.8 KB

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