clk-bcm63xx-gate.c 11 KB

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