clk-bcm63xx-gate.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/clk-provider.h>
  3. #include <linux/init.h>
  4. #include <linux/of.h>
  5. #include <linux/platform_device.h>
  6. #include <dt-bindings/clock/bcm3368-clock.h>
  7. #include <dt-bindings/clock/bcm6318-clock.h>
  8. #include <dt-bindings/clock/bcm6328-clock.h>
  9. #include <dt-bindings/clock/bcm6358-clock.h>
  10. #include <dt-bindings/clock/bcm6362-clock.h>
  11. #include <dt-bindings/clock/bcm6368-clock.h>
  12. #include <dt-bindings/clock/bcm63268-clock.h>
  13. struct clk_bcm63xx_table_entry {
  14. const char * const name;
  15. u8 bit;
  16. unsigned long flags;
  17. };
  18. struct clk_bcm63xx_hw {
  19. void __iomem *regs;
  20. spinlock_t lock;
  21. struct clk_hw_onecell_data data;
  22. };
  23. static const struct clk_bcm63xx_table_entry bcm3368_clocks[] = {
  24. {
  25. .name = "mac",
  26. .bit = BCM3368_CLK_MAC,
  27. }, {
  28. .name = "tc",
  29. .bit = BCM3368_CLK_TC,
  30. }, {
  31. .name = "us_top",
  32. .bit = BCM3368_CLK_US_TOP,
  33. }, {
  34. .name = "ds_top",
  35. .bit = BCM3368_CLK_DS_TOP,
  36. }, {
  37. .name = "acm",
  38. .bit = BCM3368_CLK_ACM,
  39. }, {
  40. .name = "spi",
  41. .bit = BCM3368_CLK_SPI,
  42. }, {
  43. .name = "usbs",
  44. .bit = BCM3368_CLK_USBS,
  45. }, {
  46. .name = "bmu",
  47. .bit = BCM3368_CLK_BMU,
  48. }, {
  49. .name = "pcm",
  50. .bit = BCM3368_CLK_PCM,
  51. }, {
  52. .name = "ntp",
  53. .bit = BCM3368_CLK_NTP,
  54. }, {
  55. .name = "acp_b",
  56. .bit = BCM3368_CLK_ACP_B,
  57. }, {
  58. .name = "acp_a",
  59. .bit = BCM3368_CLK_ACP_A,
  60. }, {
  61. .name = "emusb",
  62. .bit = BCM3368_CLK_EMUSB,
  63. }, {
  64. .name = "enet0",
  65. .bit = BCM3368_CLK_ENET0,
  66. }, {
  67. .name = "enet1",
  68. .bit = BCM3368_CLK_ENET1,
  69. }, {
  70. .name = "usbsu",
  71. .bit = BCM3368_CLK_USBSU,
  72. }, {
  73. .name = "ephy",
  74. .bit = BCM3368_CLK_EPHY,
  75. }, {
  76. /* sentinel */
  77. },
  78. };
  79. static const struct clk_bcm63xx_table_entry bcm6318_clocks[] = {
  80. {
  81. .name = "adsl_asb",
  82. .bit = BCM6318_CLK_ADSL_ASB,
  83. }, {
  84. .name = "usb_asb",
  85. .bit = BCM6318_CLK_USB_ASB,
  86. }, {
  87. .name = "mips_asb",
  88. .bit = BCM6318_CLK_MIPS_ASB,
  89. }, {
  90. .name = "pcie_asb",
  91. .bit = BCM6318_CLK_PCIE_ASB,
  92. }, {
  93. .name = "phymips_asb",
  94. .bit = BCM6318_CLK_PHYMIPS_ASB,
  95. }, {
  96. .name = "robosw_asb",
  97. .bit = BCM6318_CLK_ROBOSW_ASB,
  98. }, {
  99. .name = "sar_asb",
  100. .bit = BCM6318_CLK_SAR_ASB,
  101. }, {
  102. .name = "sdr_asb",
  103. .bit = BCM6318_CLK_SDR_ASB,
  104. }, {
  105. .name = "swreg_asb",
  106. .bit = BCM6318_CLK_SWREG_ASB,
  107. }, {
  108. .name = "periph_asb",
  109. .bit = BCM6318_CLK_PERIPH_ASB,
  110. }, {
  111. .name = "cpubus160",
  112. .bit = BCM6318_CLK_CPUBUS160,
  113. }, {
  114. .name = "adsl",
  115. .bit = BCM6318_CLK_ADSL,
  116. }, {
  117. .name = "sar125",
  118. .bit = BCM6318_CLK_SAR125,
  119. }, {
  120. .name = "mips",
  121. .bit = BCM6318_CLK_MIPS,
  122. .flags = CLK_IS_CRITICAL,
  123. }, {
  124. .name = "pcie",
  125. .bit = BCM6318_CLK_PCIE,
  126. }, {
  127. .name = "robosw250",
  128. .bit = BCM6318_CLK_ROBOSW250,
  129. }, {
  130. .name = "robosw025",
  131. .bit = BCM6318_CLK_ROBOSW025,
  132. }, {
  133. .name = "sdr",
  134. .bit = BCM6318_CLK_SDR,
  135. .flags = CLK_IS_CRITICAL,
  136. }, {
  137. .name = "usbd",
  138. .bit = BCM6318_CLK_USBD,
  139. }, {
  140. .name = "hsspi",
  141. .bit = BCM6318_CLK_HSSPI,
  142. }, {
  143. .name = "pcie25",
  144. .bit = BCM6318_CLK_PCIE25,
  145. }, {
  146. .name = "phymips",
  147. .bit = BCM6318_CLK_PHYMIPS,
  148. }, {
  149. .name = "afe",
  150. .bit = BCM6318_CLK_AFE,
  151. }, {
  152. .name = "qproc",
  153. .bit = BCM6318_CLK_QPROC,
  154. }, {
  155. /* sentinel */
  156. },
  157. };
  158. static const struct clk_bcm63xx_table_entry bcm6318_ubus_clocks[] = {
  159. {
  160. .name = "adsl-ubus",
  161. .bit = BCM6318_UCLK_ADSL,
  162. }, {
  163. .name = "arb-ubus",
  164. .bit = BCM6318_UCLK_ARB,
  165. .flags = CLK_IS_CRITICAL,
  166. }, {
  167. .name = "mips-ubus",
  168. .bit = BCM6318_UCLK_MIPS,
  169. .flags = CLK_IS_CRITICAL,
  170. }, {
  171. .name = "pcie-ubus",
  172. .bit = BCM6318_UCLK_PCIE,
  173. }, {
  174. .name = "periph-ubus",
  175. .bit = BCM6318_UCLK_PERIPH,
  176. .flags = CLK_IS_CRITICAL,
  177. }, {
  178. .name = "phymips-ubus",
  179. .bit = BCM6318_UCLK_PHYMIPS,
  180. }, {
  181. .name = "robosw-ubus",
  182. .bit = BCM6318_UCLK_ROBOSW,
  183. }, {
  184. .name = "sar-ubus",
  185. .bit = BCM6318_UCLK_SAR,
  186. }, {
  187. .name = "sdr-ubus",
  188. .bit = BCM6318_UCLK_SDR,
  189. }, {
  190. .name = "usb-ubus",
  191. .bit = BCM6318_UCLK_USB,
  192. }, {
  193. /* sentinel */
  194. },
  195. };
  196. static const struct clk_bcm63xx_table_entry bcm6328_clocks[] = {
  197. {
  198. .name = "phy_mips",
  199. .bit = BCM6328_CLK_PHYMIPS,
  200. }, {
  201. .name = "adsl_qproc",
  202. .bit = BCM6328_CLK_ADSL_QPROC,
  203. }, {
  204. .name = "adsl_afe",
  205. .bit = BCM6328_CLK_ADSL_AFE,
  206. }, {
  207. .name = "adsl",
  208. .bit = BCM6328_CLK_ADSL,
  209. }, {
  210. .name = "mips",
  211. .bit = BCM6328_CLK_MIPS,
  212. .flags = CLK_IS_CRITICAL,
  213. }, {
  214. .name = "sar",
  215. .bit = BCM6328_CLK_SAR,
  216. }, {
  217. .name = "pcm",
  218. .bit = BCM6328_CLK_PCM,
  219. }, {
  220. .name = "usbd",
  221. .bit = BCM6328_CLK_USBD,
  222. }, {
  223. .name = "usbh",
  224. .bit = BCM6328_CLK_USBH,
  225. }, {
  226. .name = "hsspi",
  227. .bit = BCM6328_CLK_HSSPI,
  228. }, {
  229. .name = "pcie",
  230. .bit = BCM6328_CLK_PCIE,
  231. }, {
  232. .name = "robosw",
  233. .bit = BCM6328_CLK_ROBOSW,
  234. }, {
  235. /* sentinel */
  236. },
  237. };
  238. static const struct clk_bcm63xx_table_entry bcm6358_clocks[] = {
  239. {
  240. .name = "enet",
  241. .bit = BCM6358_CLK_ENET,
  242. }, {
  243. .name = "adslphy",
  244. .bit = BCM6358_CLK_ADSLPHY,
  245. }, {
  246. .name = "pcm",
  247. .bit = BCM6358_CLK_PCM,
  248. }, {
  249. .name = "spi",
  250. .bit = BCM6358_CLK_SPI,
  251. }, {
  252. .name = "usbs",
  253. .bit = BCM6358_CLK_USBS,
  254. }, {
  255. .name = "sar",
  256. .bit = BCM6358_CLK_SAR,
  257. }, {
  258. .name = "emusb",
  259. .bit = BCM6358_CLK_EMUSB,
  260. }, {
  261. .name = "enet0",
  262. .bit = BCM6358_CLK_ENET0,
  263. }, {
  264. .name = "enet1",
  265. .bit = BCM6358_CLK_ENET1,
  266. }, {
  267. .name = "usbsu",
  268. .bit = BCM6358_CLK_USBSU,
  269. }, {
  270. .name = "ephy",
  271. .bit = BCM6358_CLK_EPHY,
  272. }, {
  273. /* sentinel */
  274. },
  275. };
  276. static const struct clk_bcm63xx_table_entry bcm6362_clocks[] = {
  277. {
  278. .name = "adsl_qproc",
  279. .bit = BCM6362_CLK_ADSL_QPROC,
  280. }, {
  281. .name = "adsl_afe",
  282. .bit = BCM6362_CLK_ADSL_AFE,
  283. }, {
  284. .name = "adsl",
  285. .bit = BCM6362_CLK_ADSL,
  286. }, {
  287. .name = "mips",
  288. .bit = BCM6362_CLK_MIPS,
  289. .flags = CLK_IS_CRITICAL,
  290. }, {
  291. .name = "wlan_ocp",
  292. .bit = BCM6362_CLK_WLAN_OCP,
  293. }, {
  294. .name = "swpkt_usb",
  295. .bit = BCM6362_CLK_SWPKT_USB,
  296. }, {
  297. .name = "swpkt_sar",
  298. .bit = BCM6362_CLK_SWPKT_SAR,
  299. }, {
  300. .name = "sar",
  301. .bit = BCM6362_CLK_SAR,
  302. }, {
  303. .name = "robosw",
  304. .bit = BCM6362_CLK_ROBOSW,
  305. }, {
  306. .name = "pcm",
  307. .bit = BCM6362_CLK_PCM,
  308. }, {
  309. .name = "usbd",
  310. .bit = BCM6362_CLK_USBD,
  311. }, {
  312. .name = "usbh",
  313. .bit = BCM6362_CLK_USBH,
  314. }, {
  315. .name = "ipsec",
  316. .bit = BCM6362_CLK_IPSEC,
  317. }, {
  318. .name = "spi",
  319. .bit = BCM6362_CLK_SPI,
  320. }, {
  321. .name = "hsspi",
  322. .bit = BCM6362_CLK_HSSPI,
  323. }, {
  324. .name = "pcie",
  325. .bit = BCM6362_CLK_PCIE,
  326. }, {
  327. .name = "fap",
  328. .bit = BCM6362_CLK_FAP,
  329. }, {
  330. .name = "phymips",
  331. .bit = BCM6362_CLK_PHYMIPS,
  332. }, {
  333. .name = "nand",
  334. .bit = BCM6362_CLK_NAND,
  335. }, {
  336. /* sentinel */
  337. },
  338. };
  339. static const struct clk_bcm63xx_table_entry bcm6368_clocks[] = {
  340. {
  341. .name = "vdsl_qproc",
  342. .bit = BCM6368_CLK_VDSL_QPROC,
  343. }, {
  344. .name = "vdsl_afe",
  345. .bit = BCM6368_CLK_VDSL_AFE,
  346. }, {
  347. .name = "vdsl_bonding",
  348. .bit = BCM6368_CLK_VDSL_BONDING,
  349. }, {
  350. .name = "vdsl",
  351. .bit = BCM6368_CLK_VDSL,
  352. }, {
  353. .name = "phymips",
  354. .bit = BCM6368_CLK_PHYMIPS,
  355. }, {
  356. .name = "swpkt_usb",
  357. .bit = BCM6368_CLK_SWPKT_USB,
  358. }, {
  359. .name = "swpkt_sar",
  360. .bit = BCM6368_CLK_SWPKT_SAR,
  361. }, {
  362. .name = "spi",
  363. .bit = BCM6368_CLK_SPI,
  364. }, {
  365. .name = "usbd",
  366. .bit = BCM6368_CLK_USBD,
  367. }, {
  368. .name = "sar",
  369. .bit = BCM6368_CLK_SAR,
  370. }, {
  371. .name = "robosw",
  372. .bit = BCM6368_CLK_ROBOSW,
  373. }, {
  374. .name = "utopia",
  375. .bit = BCM6368_CLK_UTOPIA,
  376. }, {
  377. .name = "pcm",
  378. .bit = BCM6368_CLK_PCM,
  379. }, {
  380. .name = "usbh",
  381. .bit = BCM6368_CLK_USBH,
  382. }, {
  383. .name = "disable_gless",
  384. .bit = BCM6368_CLK_DIS_GLESS,
  385. }, {
  386. .name = "nand",
  387. .bit = BCM6368_CLK_NAND,
  388. }, {
  389. .name = "ipsec",
  390. .bit = BCM6368_CLK_IPSEC,
  391. }, {
  392. /* sentinel */
  393. },
  394. };
  395. static const struct clk_bcm63xx_table_entry bcm63268_clocks[] = {
  396. {
  397. .name = "disable_gless",
  398. .bit = BCM63268_CLK_DIS_GLESS,
  399. }, {
  400. .name = "vdsl_qproc",
  401. .bit = BCM63268_CLK_VDSL_QPROC,
  402. }, {
  403. .name = "vdsl_afe",
  404. .bit = BCM63268_CLK_VDSL_AFE,
  405. }, {
  406. .name = "vdsl",
  407. .bit = BCM63268_CLK_VDSL,
  408. }, {
  409. .name = "mips",
  410. .bit = BCM63268_CLK_MIPS,
  411. .flags = CLK_IS_CRITICAL,
  412. }, {
  413. .name = "wlan_ocp",
  414. .bit = BCM63268_CLK_WLAN_OCP,
  415. }, {
  416. .name = "dect",
  417. .bit = BCM63268_CLK_DECT,
  418. }, {
  419. .name = "fap0",
  420. .bit = BCM63268_CLK_FAP0,
  421. }, {
  422. .name = "fap1",
  423. .bit = BCM63268_CLK_FAP1,
  424. }, {
  425. .name = "sar",
  426. .bit = BCM63268_CLK_SAR,
  427. }, {
  428. .name = "robosw",
  429. .bit = BCM63268_CLK_ROBOSW,
  430. }, {
  431. .name = "pcm",
  432. .bit = BCM63268_CLK_PCM,
  433. }, {
  434. .name = "usbd",
  435. .bit = BCM63268_CLK_USBD,
  436. }, {
  437. .name = "usbh",
  438. .bit = BCM63268_CLK_USBH,
  439. }, {
  440. .name = "ipsec",
  441. .bit = BCM63268_CLK_IPSEC,
  442. }, {
  443. .name = "spi",
  444. .bit = BCM63268_CLK_SPI,
  445. }, {
  446. .name = "hsspi",
  447. .bit = BCM63268_CLK_HSSPI,
  448. }, {
  449. .name = "pcie",
  450. .bit = BCM63268_CLK_PCIE,
  451. }, {
  452. .name = "phymips",
  453. .bit = BCM63268_CLK_PHYMIPS,
  454. }, {
  455. .name = "gmac",
  456. .bit = BCM63268_CLK_GMAC,
  457. }, {
  458. .name = "nand",
  459. .bit = BCM63268_CLK_NAND,
  460. }, {
  461. .name = "tbus",
  462. .bit = BCM63268_CLK_TBUS,
  463. }, {
  464. .name = "robosw250",
  465. .bit = BCM63268_CLK_ROBOSW250,
  466. }, {
  467. /* sentinel */
  468. },
  469. };
  470. static int clk_bcm63xx_probe(struct platform_device *pdev)
  471. {
  472. const struct clk_bcm63xx_table_entry *entry, *table;
  473. struct clk_bcm63xx_hw *hw;
  474. u8 maxbit = 0;
  475. int i, ret;
  476. table = of_device_get_match_data(&pdev->dev);
  477. if (!table)
  478. return -EINVAL;
  479. for (entry = table; entry->name; entry++)
  480. maxbit = max_t(u8, maxbit, entry->bit);
  481. maxbit++;
  482. hw = devm_kzalloc(&pdev->dev, struct_size(hw, data.hws, maxbit),
  483. GFP_KERNEL);
  484. if (!hw)
  485. return -ENOMEM;
  486. platform_set_drvdata(pdev, hw);
  487. spin_lock_init(&hw->lock);
  488. hw->data.num = maxbit;
  489. for (i = 0; i < maxbit; i++)
  490. hw->data.hws[i] = ERR_PTR(-ENODEV);
  491. hw->regs = devm_platform_ioremap_resource(pdev, 0);
  492. if (IS_ERR(hw->regs))
  493. return PTR_ERR(hw->regs);
  494. for (entry = table; entry->name; entry++) {
  495. struct clk_hw *clk;
  496. clk = clk_hw_register_gate(&pdev->dev, entry->name, NULL,
  497. entry->flags, hw->regs, entry->bit,
  498. CLK_GATE_BIG_ENDIAN, &hw->lock);
  499. if (IS_ERR(clk)) {
  500. ret = PTR_ERR(clk);
  501. goto out_err;
  502. }
  503. hw->data.hws[entry->bit] = clk;
  504. }
  505. ret = of_clk_add_hw_provider(pdev->dev.of_node, of_clk_hw_onecell_get,
  506. &hw->data);
  507. if (!ret)
  508. return 0;
  509. out_err:
  510. for (i = 0; i < hw->data.num; i++) {
  511. if (!IS_ERR(hw->data.hws[i]))
  512. clk_hw_unregister_gate(hw->data.hws[i]);
  513. }
  514. return ret;
  515. }
  516. static void clk_bcm63xx_remove(struct platform_device *pdev)
  517. {
  518. struct clk_bcm63xx_hw *hw = platform_get_drvdata(pdev);
  519. int i;
  520. of_clk_del_provider(pdev->dev.of_node);
  521. for (i = 0; i < hw->data.num; i++) {
  522. if (!IS_ERR(hw->data.hws[i]))
  523. clk_hw_unregister_gate(hw->data.hws[i]);
  524. }
  525. }
  526. static const struct of_device_id clk_bcm63xx_dt_ids[] = {
  527. { .compatible = "brcm,bcm3368-clocks", .data = &bcm3368_clocks, },
  528. { .compatible = "brcm,bcm6318-clocks", .data = &bcm6318_clocks, },
  529. { .compatible = "brcm,bcm6318-ubus-clocks", .data = &bcm6318_ubus_clocks, },
  530. { .compatible = "brcm,bcm6328-clocks", .data = &bcm6328_clocks, },
  531. { .compatible = "brcm,bcm6358-clocks", .data = &bcm6358_clocks, },
  532. { .compatible = "brcm,bcm6362-clocks", .data = &bcm6362_clocks, },
  533. { .compatible = "brcm,bcm6368-clocks", .data = &bcm6368_clocks, },
  534. { .compatible = "brcm,bcm63268-clocks", .data = &bcm63268_clocks, },
  535. { }
  536. };
  537. static struct platform_driver clk_bcm63xx = {
  538. .probe = clk_bcm63xx_probe,
  539. .remove = clk_bcm63xx_remove,
  540. .driver = {
  541. .name = "bcm63xx-clock",
  542. .of_match_table = clk_bcm63xx_dt_ids,
  543. },
  544. };
  545. builtin_platform_driver(clk_bcm63xx);