225-v6.3-clk-mediatek-Switch-to-mtk_clk_simple_probe-where-po.patch 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. From c26e28015b74af73e0b299f6ad3ff22931e600b4 Mon Sep 17 00:00:00 2001
  2. From: AngeloGioacchino Del Regno <[email protected]>
  3. Date: Fri, 20 Jan 2023 10:20:41 +0100
  4. Subject: [PATCH 05/15] clk: mediatek: Switch to mtk_clk_simple_probe() where
  5. possible
  6. mtk_clk_simple_probe() is a function that registers mtk gate clocks
  7. and, if reset data is present, a reset controller and across all of
  8. the MTK clock drivers, such a function is duplicated many times:
  9. switch to the common mtk_clk_simple_probe() function for all of the
  10. clock drivers that are registering as platform drivers.
  11. Signed-off-by: AngeloGioacchino Del Regno <[email protected]>
  12. Reviewed-by: Miles Chen <[email protected]>
  13. Tested-by: Miles Chen <[email protected]>
  14. Link: https://lore.kernel.org/r/[email protected]
  15. Tested-by: Mingming Su <[email protected]>
  16. Signed-off-by: Stephen Boyd <[email protected]>
  17. [[email protected]: removed parts not relevant for OpenWrt]
  18. ---
  19. drivers/clk/mediatek/clk-mt2701-aud.c | 31 ++++++----
  20. drivers/clk/mediatek/clk-mt2701-eth.c | 36 ++++--------
  21. drivers/clk/mediatek/clk-mt2701-g3d.c | 56 ++++--------------
  22. drivers/clk/mediatek/clk-mt2701-hif.c | 38 ++++--------
  23. drivers/clk/mediatek/clk-mt2712.c | 83 ++++++++++----------------
  24. drivers/clk/mediatek/clk-mt7622-aud.c | 54 ++++++-----------
  25. drivers/clk/mediatek/clk-mt7622-eth.c | 82 +++++---------------------
  26. drivers/clk/mediatek/clk-mt7622-hif.c | 85 +++++----------------------
  27. drivers/clk/mediatek/clk-mt7629-hif.c | 85 +++++----------------------
  28. 9 files changed, 144 insertions(+), 406 deletions(-)
  29. --- a/drivers/clk/mediatek/clk-mt2701-aud.c
  30. +++ b/drivers/clk/mediatek/clk-mt2701-aud.c
  31. @@ -52,6 +52,7 @@ static const struct mtk_gate_regs audio3
  32. };
  33. static const struct mtk_gate audio_clks[] = {
  34. + GATE_DUMMY(CLK_DUMMY, "aud_dummy"),
  35. /* AUDIO0 */
  36. GATE_AUDIO0(CLK_AUD_AFE, "audio_afe", "aud_intbus_sel", 2),
  37. GATE_AUDIO0(CLK_AUD_HDMI, "audio_hdmi", "audpll_sel", 20),
  38. @@ -114,29 +115,27 @@ static const struct mtk_gate audio_clks[
  39. GATE_AUDIO3(CLK_AUD_MEM_ASRC5, "audio_mem_asrc5", "asm_h_sel", 14),
  40. };
  41. +static const struct mtk_clk_desc audio_desc = {
  42. + .clks = audio_clks,
  43. + .num_clks = ARRAY_SIZE(audio_clks),
  44. +};
  45. +
  46. static const struct of_device_id of_match_clk_mt2701_aud[] = {
  47. - { .compatible = "mediatek,mt2701-audsys", },
  48. - {}
  49. + { .compatible = "mediatek,mt2701-audsys", .data = &audio_desc },
  50. + { /* sentinel */ }
  51. };
  52. static int clk_mt2701_aud_probe(struct platform_device *pdev)
  53. {
  54. - struct clk_hw_onecell_data *clk_data;
  55. - struct device_node *node = pdev->dev.of_node;
  56. int r;
  57. - clk_data = mtk_alloc_clk_data(CLK_AUD_NR);
  58. -
  59. - mtk_clk_register_gates(&pdev->dev, node, audio_clks,
  60. - ARRAY_SIZE(audio_clks), clk_data);
  61. -
  62. - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  63. + r = mtk_clk_simple_probe(pdev);
  64. if (r) {
  65. dev_err(&pdev->dev,
  66. "could not register clock provider: %s: %d\n",
  67. pdev->name, r);
  68. - goto err_clk_provider;
  69. + return r;
  70. }
  71. r = devm_of_platform_populate(&pdev->dev);
  72. @@ -146,13 +145,19 @@ static int clk_mt2701_aud_probe(struct p
  73. return 0;
  74. err_plat_populate:
  75. - of_clk_del_provider(node);
  76. -err_clk_provider:
  77. + mtk_clk_simple_remove(pdev);
  78. return r;
  79. }
  80. +static int clk_mt2701_aud_remove(struct platform_device *pdev)
  81. +{
  82. + of_platform_depopulate(&pdev->dev);
  83. + return mtk_clk_simple_remove(pdev);
  84. +}
  85. +
  86. static struct platform_driver clk_mt2701_aud_drv = {
  87. .probe = clk_mt2701_aud_probe,
  88. + .remove = clk_mt2701_aud_remove,
  89. .driver = {
  90. .name = "clk-mt2701-aud",
  91. .of_match_table = of_match_clk_mt2701_aud,
  92. --- a/drivers/clk/mediatek/clk-mt2701-eth.c
  93. +++ b/drivers/clk/mediatek/clk-mt2701-eth.c
  94. @@ -20,6 +20,7 @@ static const struct mtk_gate_regs eth_cg
  95. GATE_MTK(_id, _name, _parent, &eth_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  96. static const struct mtk_gate eth_clks[] = {
  97. + GATE_DUMMY(CLK_DUMMY, "eth_dummy"),
  98. GATE_ETH(CLK_ETHSYS_HSDMA, "hsdma_clk", "ethif_sel", 5),
  99. GATE_ETH(CLK_ETHSYS_ESW, "esw_clk", "ethpll_500m_ck", 6),
  100. GATE_ETH(CLK_ETHSYS_GP2, "gp2_clk", "trgpll", 7),
  101. @@ -38,35 +39,20 @@ static const struct mtk_clk_rst_desc clk
  102. .rst_bank_nr = ARRAY_SIZE(rst_ofs),
  103. };
  104. -static const struct of_device_id of_match_clk_mt2701_eth[] = {
  105. - { .compatible = "mediatek,mt2701-ethsys", },
  106. - {}
  107. +static const struct mtk_clk_desc eth_desc = {
  108. + .clks = eth_clks,
  109. + .num_clks = ARRAY_SIZE(eth_clks),
  110. + .rst_desc = &clk_rst_desc,
  111. };
  112. -static int clk_mt2701_eth_probe(struct platform_device *pdev)
  113. -{
  114. - struct clk_hw_onecell_data *clk_data;
  115. - int r;
  116. - struct device_node *node = pdev->dev.of_node;
  117. -
  118. - clk_data = mtk_alloc_clk_data(CLK_ETHSYS_NR);
  119. -
  120. - mtk_clk_register_gates(&pdev->dev, node, eth_clks,
  121. - ARRAY_SIZE(eth_clks), clk_data);
  122. -
  123. - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  124. - if (r)
  125. - dev_err(&pdev->dev,
  126. - "could not register clock provider: %s: %d\n",
  127. - pdev->name, r);
  128. -
  129. - mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  130. -
  131. - return r;
  132. -}
  133. +static const struct of_device_id of_match_clk_mt2701_eth[] = {
  134. + { .compatible = "mediatek,mt2701-ethsys", .data = &eth_desc },
  135. + { /* sentinel */ }
  136. +};
  137. static struct platform_driver clk_mt2701_eth_drv = {
  138. - .probe = clk_mt2701_eth_probe,
  139. + .probe = mtk_clk_simple_probe,
  140. + .remove = mtk_clk_simple_remove,
  141. .driver = {
  142. .name = "clk-mt2701-eth",
  143. .of_match_table = of_match_clk_mt2701_eth,
  144. --- a/drivers/clk/mediatek/clk-mt2701-g3d.c
  145. +++ b/drivers/clk/mediatek/clk-mt2701-g3d.c
  146. @@ -26,6 +26,7 @@ static const struct mtk_gate_regs g3d_cg
  147. };
  148. static const struct mtk_gate g3d_clks[] = {
  149. + GATE_DUMMY(CLK_DUMMY, "g3d_dummy"),
  150. GATE_G3D(CLK_G3DSYS_CORE, "g3d_core", "mfg_sel", 0),
  151. };
  152. @@ -37,57 +38,20 @@ static const struct mtk_clk_rst_desc clk
  153. .rst_bank_nr = ARRAY_SIZE(rst_ofs),
  154. };
  155. -static int clk_mt2701_g3dsys_init(struct platform_device *pdev)
  156. -{
  157. - struct clk_hw_onecell_data *clk_data;
  158. - struct device_node *node = pdev->dev.of_node;
  159. - int r;
  160. -
  161. - clk_data = mtk_alloc_clk_data(CLK_G3DSYS_NR);
  162. -
  163. - mtk_clk_register_gates(&pdev->dev, node, g3d_clks, ARRAY_SIZE(g3d_clks),
  164. - clk_data);
  165. -
  166. - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  167. - if (r)
  168. - dev_err(&pdev->dev,
  169. - "could not register clock provider: %s: %d\n",
  170. - pdev->name, r);
  171. -
  172. - mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  173. -
  174. - return r;
  175. -}
  176. +static const struct mtk_clk_desc g3d_desc = {
  177. + .clks = g3d_clks,
  178. + .num_clks = ARRAY_SIZE(g3d_clks),
  179. + .rst_desc = &clk_rst_desc,
  180. +};
  181. static const struct of_device_id of_match_clk_mt2701_g3d[] = {
  182. - {
  183. - .compatible = "mediatek,mt2701-g3dsys",
  184. - .data = clk_mt2701_g3dsys_init,
  185. - }, {
  186. - /* sentinel */
  187. - }
  188. + { .compatible = "mediatek,mt2701-g3dsys", .data = &g3d_desc },
  189. + { /* sentinel */ }
  190. };
  191. -static int clk_mt2701_g3d_probe(struct platform_device *pdev)
  192. -{
  193. - int (*clk_init)(struct platform_device *);
  194. - int r;
  195. -
  196. - clk_init = of_device_get_match_data(&pdev->dev);
  197. - if (!clk_init)
  198. - return -EINVAL;
  199. -
  200. - r = clk_init(pdev);
  201. - if (r)
  202. - dev_err(&pdev->dev,
  203. - "could not register clock provider: %s: %d\n",
  204. - pdev->name, r);
  205. -
  206. - return r;
  207. -}
  208. -
  209. static struct platform_driver clk_mt2701_g3d_drv = {
  210. - .probe = clk_mt2701_g3d_probe,
  211. + .probe = mtk_clk_simple_probe,
  212. + .remove = mtk_clk_simple_remove,
  213. .driver = {
  214. .name = "clk-mt2701-g3d",
  215. .of_match_table = of_match_clk_mt2701_g3d,
  216. --- a/drivers/clk/mediatek/clk-mt2701-hif.c
  217. +++ b/drivers/clk/mediatek/clk-mt2701-hif.c
  218. @@ -20,6 +20,7 @@ static const struct mtk_gate_regs hif_cg
  219. GATE_MTK(_id, _name, _parent, &hif_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  220. static const struct mtk_gate hif_clks[] = {
  221. + GATE_DUMMY(CLK_DUMMY, "hif_dummy"),
  222. GATE_HIF(CLK_HIFSYS_USB0PHY, "usb0_phy_clk", "ethpll_500m_ck", 21),
  223. GATE_HIF(CLK_HIFSYS_USB1PHY, "usb1_phy_clk", "ethpll_500m_ck", 22),
  224. GATE_HIF(CLK_HIFSYS_PCIE0, "pcie0_clk", "ethpll_500m_ck", 24),
  225. @@ -35,37 +36,20 @@ static const struct mtk_clk_rst_desc clk
  226. .rst_bank_nr = ARRAY_SIZE(rst_ofs),
  227. };
  228. -static const struct of_device_id of_match_clk_mt2701_hif[] = {
  229. - { .compatible = "mediatek,mt2701-hifsys", },
  230. - {}
  231. +static const struct mtk_clk_desc hif_desc = {
  232. + .clks = hif_clks,
  233. + .num_clks = ARRAY_SIZE(hif_clks),
  234. + .rst_desc = &clk_rst_desc,
  235. };
  236. -static int clk_mt2701_hif_probe(struct platform_device *pdev)
  237. -{
  238. - struct clk_hw_onecell_data *clk_data;
  239. - int r;
  240. - struct device_node *node = pdev->dev.of_node;
  241. -
  242. - clk_data = mtk_alloc_clk_data(CLK_HIFSYS_NR);
  243. -
  244. - mtk_clk_register_gates(&pdev->dev, node, hif_clks,
  245. - ARRAY_SIZE(hif_clks), clk_data);
  246. -
  247. - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  248. - if (r) {
  249. - dev_err(&pdev->dev,
  250. - "could not register clock provider: %s: %d\n",
  251. - pdev->name, r);
  252. - return r;
  253. - }
  254. -
  255. - mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  256. -
  257. - return 0;
  258. -}
  259. +static const struct of_device_id of_match_clk_mt2701_hif[] = {
  260. + { .compatible = "mediatek,mt2701-hifsys", .data = &hif_desc },
  261. + { /* sentinel */ }
  262. +};
  263. static struct platform_driver clk_mt2701_hif_drv = {
  264. - .probe = clk_mt2701_hif_probe,
  265. + .probe = mtk_clk_simple_probe,
  266. + .remove = mtk_clk_simple_remove,
  267. .driver = {
  268. .name = "clk-mt2701-hif",
  269. .of_match_table = of_match_clk_mt2701_hif,
  270. --- a/drivers/clk/mediatek/clk-mt2712.c
  271. +++ b/drivers/clk/mediatek/clk-mt2712.c
  272. @@ -1337,50 +1337,6 @@ static int clk_mt2712_top_probe(struct p
  273. return r;
  274. }
  275. -static int clk_mt2712_infra_probe(struct platform_device *pdev)
  276. -{
  277. - struct clk_hw_onecell_data *clk_data;
  278. - int r;
  279. - struct device_node *node = pdev->dev.of_node;
  280. -
  281. - clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
  282. -
  283. - mtk_clk_register_gates(&pdev->dev, node, infra_clks,
  284. - ARRAY_SIZE(infra_clks), clk_data);
  285. -
  286. - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  287. -
  288. - if (r != 0)
  289. - pr_err("%s(): could not register clock provider: %d\n",
  290. - __func__, r);
  291. -
  292. - mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc[0]);
  293. -
  294. - return r;
  295. -}
  296. -
  297. -static int clk_mt2712_peri_probe(struct platform_device *pdev)
  298. -{
  299. - struct clk_hw_onecell_data *clk_data;
  300. - int r;
  301. - struct device_node *node = pdev->dev.of_node;
  302. -
  303. - clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);
  304. -
  305. - mtk_clk_register_gates(&pdev->dev, node, peri_clks,
  306. - ARRAY_SIZE(peri_clks), clk_data);
  307. -
  308. - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  309. -
  310. - if (r != 0)
  311. - pr_err("%s(): could not register clock provider: %d\n",
  312. - __func__, r);
  313. -
  314. - mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc[1]);
  315. -
  316. - return r;
  317. -}
  318. -
  319. static int clk_mt2712_mcu_probe(struct platform_device *pdev)
  320. {
  321. struct clk_hw_onecell_data *clk_data;
  322. @@ -1419,12 +1375,6 @@ static const struct of_device_id of_matc
  323. .compatible = "mediatek,mt2712-topckgen",
  324. .data = clk_mt2712_top_probe,
  325. }, {
  326. - .compatible = "mediatek,mt2712-infracfg",
  327. - .data = clk_mt2712_infra_probe,
  328. - }, {
  329. - .compatible = "mediatek,mt2712-pericfg",
  330. - .data = clk_mt2712_peri_probe,
  331. - }, {
  332. .compatible = "mediatek,mt2712-mcucfg",
  333. .data = clk_mt2712_mcu_probe,
  334. }, {
  335. @@ -1450,6 +1400,33 @@ static int clk_mt2712_probe(struct platf
  336. return r;
  337. }
  338. +static const struct mtk_clk_desc infra_desc = {
  339. + .clks = infra_clks,
  340. + .num_clks = ARRAY_SIZE(infra_clks),
  341. + .rst_desc = &clk_rst_desc[0],
  342. +};
  343. +
  344. +static const struct mtk_clk_desc peri_desc = {
  345. + .clks = peri_clks,
  346. + .num_clks = ARRAY_SIZE(peri_clks),
  347. + .rst_desc = &clk_rst_desc[1],
  348. +};
  349. +
  350. +static const struct of_device_id of_match_clk_mt2712_simple[] = {
  351. + { .compatible = "mediatek,mt2712-infracfg", .data = &infra_desc },
  352. + { .compatible = "mediatek,mt2712-pericfg", .data = &peri_desc, },
  353. + { /* sentinel */ }
  354. +};
  355. +
  356. +static struct platform_driver clk_mt2712_simple_drv = {
  357. + .probe = mtk_clk_simple_probe,
  358. + .remove = mtk_clk_simple_remove,
  359. + .driver = {
  360. + .name = "clk-mt2712-simple",
  361. + .of_match_table = of_match_clk_mt2712_simple,
  362. + },
  363. +};
  364. +
  365. static struct platform_driver clk_mt2712_drv = {
  366. .probe = clk_mt2712_probe,
  367. .driver = {
  368. @@ -1460,7 +1437,11 @@ static struct platform_driver clk_mt2712
  369. static int __init clk_mt2712_init(void)
  370. {
  371. - return platform_driver_register(&clk_mt2712_drv);
  372. + int ret = platform_driver_register(&clk_mt2712_drv);
  373. +
  374. + if (ret)
  375. + return ret;
  376. + return platform_driver_register(&clk_mt2712_simple_drv);
  377. }
  378. arch_initcall(clk_mt2712_init);
  379. --- a/drivers/clk/mediatek/clk-mt7622-aud.c
  380. +++ b/drivers/clk/mediatek/clk-mt7622-aud.c
  381. @@ -106,24 +106,22 @@ static const struct mtk_gate audio_clks[
  382. GATE_AUDIO3(CLK_AUDIO_MEM_ASRC5, "audio_mem_asrc5", "asm_h_sel", 14),
  383. };
  384. -static int clk_mt7622_audiosys_init(struct platform_device *pdev)
  385. +static const struct mtk_clk_desc audio_desc = {
  386. + .clks = audio_clks,
  387. + .num_clks = ARRAY_SIZE(audio_clks),
  388. +};
  389. +
  390. +static int clk_mt7622_aud_probe(struct platform_device *pdev)
  391. {
  392. - struct clk_hw_onecell_data *clk_data;
  393. - struct device_node *node = pdev->dev.of_node;
  394. int r;
  395. - clk_data = mtk_alloc_clk_data(CLK_AUDIO_NR_CLK);
  396. -
  397. - mtk_clk_register_gates(&pdev->dev, node, audio_clks,
  398. - ARRAY_SIZE(audio_clks), clk_data);
  399. -
  400. - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  401. + r = mtk_clk_simple_probe(pdev);
  402. if (r) {
  403. dev_err(&pdev->dev,
  404. "could not register clock provider: %s: %d\n",
  405. pdev->name, r);
  406. - goto err_clk_provider;
  407. + return r;
  408. }
  409. r = devm_of_platform_populate(&pdev->dev);
  410. @@ -133,40 +131,24 @@ static int clk_mt7622_audiosys_init(stru
  411. return 0;
  412. err_plat_populate:
  413. - of_clk_del_provider(node);
  414. -err_clk_provider:
  415. + mtk_clk_simple_remove(pdev);
  416. return r;
  417. }
  418. -static const struct of_device_id of_match_clk_mt7622_aud[] = {
  419. - {
  420. - .compatible = "mediatek,mt7622-audsys",
  421. - .data = clk_mt7622_audiosys_init,
  422. - }, {
  423. - /* sentinel */
  424. - }
  425. -};
  426. -
  427. -static int clk_mt7622_aud_probe(struct platform_device *pdev)
  428. +static int clk_mt7622_aud_remove(struct platform_device *pdev)
  429. {
  430. - int (*clk_init)(struct platform_device *);
  431. - int r;
  432. -
  433. - clk_init = of_device_get_match_data(&pdev->dev);
  434. - if (!clk_init)
  435. - return -EINVAL;
  436. -
  437. - r = clk_init(pdev);
  438. - if (r)
  439. - dev_err(&pdev->dev,
  440. - "could not register clock provider: %s: %d\n",
  441. - pdev->name, r);
  442. -
  443. - return r;
  444. + of_platform_depopulate(&pdev->dev);
  445. + return mtk_clk_simple_remove(pdev);
  446. }
  447. +static const struct of_device_id of_match_clk_mt7622_aud[] = {
  448. + { .compatible = "mediatek,mt7622-audsys", .data = &audio_desc },
  449. + { /* sentinel */ }
  450. +};
  451. +
  452. static struct platform_driver clk_mt7622_aud_drv = {
  453. .probe = clk_mt7622_aud_probe,
  454. + .remove = clk_mt7622_aud_remove,
  455. .driver = {
  456. .name = "clk-mt7622-aud",
  457. .of_match_table = of_match_clk_mt7622_aud,
  458. --- a/drivers/clk/mediatek/clk-mt7622-eth.c
  459. +++ b/drivers/clk/mediatek/clk-mt7622-eth.c
  460. @@ -61,80 +61,26 @@ static const struct mtk_clk_rst_desc clk
  461. .rst_bank_nr = ARRAY_SIZE(rst_ofs),
  462. };
  463. -static int clk_mt7622_ethsys_init(struct platform_device *pdev)
  464. -{
  465. - struct clk_hw_onecell_data *clk_data;
  466. - struct device_node *node = pdev->dev.of_node;
  467. - int r;
  468. -
  469. - clk_data = mtk_alloc_clk_data(CLK_ETH_NR_CLK);
  470. -
  471. - mtk_clk_register_gates(&pdev->dev, node, eth_clks,
  472. - ARRAY_SIZE(eth_clks), clk_data);
  473. -
  474. - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  475. - if (r)
  476. - dev_err(&pdev->dev,
  477. - "could not register clock provider: %s: %d\n",
  478. - pdev->name, r);
  479. -
  480. - mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  481. -
  482. - return r;
  483. -}
  484. -
  485. -static int clk_mt7622_sgmiisys_init(struct platform_device *pdev)
  486. -{
  487. - struct clk_hw_onecell_data *clk_data;
  488. - struct device_node *node = pdev->dev.of_node;
  489. - int r;
  490. -
  491. - clk_data = mtk_alloc_clk_data(CLK_SGMII_NR_CLK);
  492. -
  493. - mtk_clk_register_gates(&pdev->dev, node, sgmii_clks,
  494. - ARRAY_SIZE(sgmii_clks), clk_data);
  495. -
  496. - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  497. - if (r)
  498. - dev_err(&pdev->dev,
  499. - "could not register clock provider: %s: %d\n",
  500. - pdev->name, r);
  501. +static const struct mtk_clk_desc eth_desc = {
  502. + .clks = eth_clks,
  503. + .num_clks = ARRAY_SIZE(eth_clks),
  504. + .rst_desc = &clk_rst_desc,
  505. +};
  506. - return r;
  507. -}
  508. +static const struct mtk_clk_desc sgmii_desc = {
  509. + .clks = sgmii_clks,
  510. + .num_clks = ARRAY_SIZE(sgmii_clks),
  511. +};
  512. static const struct of_device_id of_match_clk_mt7622_eth[] = {
  513. - {
  514. - .compatible = "mediatek,mt7622-ethsys",
  515. - .data = clk_mt7622_ethsys_init,
  516. - }, {
  517. - .compatible = "mediatek,mt7622-sgmiisys",
  518. - .data = clk_mt7622_sgmiisys_init,
  519. - }, {
  520. - /* sentinel */
  521. - }
  522. + { .compatible = "mediatek,mt7622-ethsys", .data = &eth_desc },
  523. + { .compatible = "mediatek,mt7622-sgmiisys", .data = &sgmii_desc },
  524. + { /* sentinel */ }
  525. };
  526. -static int clk_mt7622_eth_probe(struct platform_device *pdev)
  527. -{
  528. - int (*clk_init)(struct platform_device *);
  529. - int r;
  530. -
  531. - clk_init = of_device_get_match_data(&pdev->dev);
  532. - if (!clk_init)
  533. - return -EINVAL;
  534. -
  535. - r = clk_init(pdev);
  536. - if (r)
  537. - dev_err(&pdev->dev,
  538. - "could not register clock provider: %s: %d\n",
  539. - pdev->name, r);
  540. -
  541. - return r;
  542. -}
  543. -
  544. static struct platform_driver clk_mt7622_eth_drv = {
  545. - .probe = clk_mt7622_eth_probe,
  546. + .probe = mtk_clk_simple_probe,
  547. + .remove = mtk_clk_simple_remove,
  548. .driver = {
  549. .name = "clk-mt7622-eth",
  550. .of_match_table = of_match_clk_mt7622_eth,
  551. --- a/drivers/clk/mediatek/clk-mt7622-hif.c
  552. +++ b/drivers/clk/mediatek/clk-mt7622-hif.c
  553. @@ -72,82 +72,27 @@ static const struct mtk_clk_rst_desc clk
  554. .rst_bank_nr = ARRAY_SIZE(rst_ofs),
  555. };
  556. -static int clk_mt7622_ssusbsys_init(struct platform_device *pdev)
  557. -{
  558. - struct clk_hw_onecell_data *clk_data;
  559. - struct device_node *node = pdev->dev.of_node;
  560. - int r;
  561. -
  562. - clk_data = mtk_alloc_clk_data(CLK_SSUSB_NR_CLK);
  563. -
  564. - mtk_clk_register_gates(&pdev->dev, node, ssusb_clks,
  565. - ARRAY_SIZE(ssusb_clks), clk_data);
  566. -
  567. - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  568. - if (r)
  569. - dev_err(&pdev->dev,
  570. - "could not register clock provider: %s: %d\n",
  571. - pdev->name, r);
  572. -
  573. - mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  574. -
  575. - return r;
  576. -}
  577. -
  578. -static int clk_mt7622_pciesys_init(struct platform_device *pdev)
  579. -{
  580. - struct clk_hw_onecell_data *clk_data;
  581. - struct device_node *node = pdev->dev.of_node;
  582. - int r;
  583. -
  584. - clk_data = mtk_alloc_clk_data(CLK_PCIE_NR_CLK);
  585. -
  586. - mtk_clk_register_gates(&pdev->dev, node, pcie_clks,
  587. - ARRAY_SIZE(pcie_clks), clk_data);
  588. -
  589. - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  590. - if (r)
  591. - dev_err(&pdev->dev,
  592. - "could not register clock provider: %s: %d\n",
  593. - pdev->name, r);
  594. -
  595. - mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  596. +static const struct mtk_clk_desc ssusb_desc = {
  597. + .clks = ssusb_clks,
  598. + .num_clks = ARRAY_SIZE(ssusb_clks),
  599. + .rst_desc = &clk_rst_desc,
  600. +};
  601. - return r;
  602. -}
  603. +static const struct mtk_clk_desc pcie_desc = {
  604. + .clks = pcie_clks,
  605. + .num_clks = ARRAY_SIZE(pcie_clks),
  606. + .rst_desc = &clk_rst_desc,
  607. +};
  608. static const struct of_device_id of_match_clk_mt7622_hif[] = {
  609. - {
  610. - .compatible = "mediatek,mt7622-pciesys",
  611. - .data = clk_mt7622_pciesys_init,
  612. - }, {
  613. - .compatible = "mediatek,mt7622-ssusbsys",
  614. - .data = clk_mt7622_ssusbsys_init,
  615. - }, {
  616. - /* sentinel */
  617. - }
  618. + { .compatible = "mediatek,mt7622-pciesys", .data = &pcie_desc },
  619. + { .compatible = "mediatek,mt7622-ssusbsys", .data = &ssusb_desc },
  620. + { /* sentinel */ }
  621. };
  622. -static int clk_mt7622_hif_probe(struct platform_device *pdev)
  623. -{
  624. - int (*clk_init)(struct platform_device *);
  625. - int r;
  626. -
  627. - clk_init = of_device_get_match_data(&pdev->dev);
  628. - if (!clk_init)
  629. - return -EINVAL;
  630. -
  631. - r = clk_init(pdev);
  632. - if (r)
  633. - dev_err(&pdev->dev,
  634. - "could not register clock provider: %s: %d\n",
  635. - pdev->name, r);
  636. -
  637. - return r;
  638. -}
  639. -
  640. static struct platform_driver clk_mt7622_hif_drv = {
  641. - .probe = clk_mt7622_hif_probe,
  642. + .probe = mtk_clk_simple_probe,
  643. + .remove = mtk_clk_simple_remove,
  644. .driver = {
  645. .name = "clk-mt7622-hif",
  646. .of_match_table = of_match_clk_mt7622_hif,
  647. --- a/drivers/clk/mediatek/clk-mt7629-hif.c
  648. +++ b/drivers/clk/mediatek/clk-mt7629-hif.c
  649. @@ -67,82 +67,27 @@ static const struct mtk_clk_rst_desc clk
  650. .rst_bank_nr = ARRAY_SIZE(rst_ofs),
  651. };
  652. -static int clk_mt7629_ssusbsys_init(struct platform_device *pdev)
  653. -{
  654. - struct clk_hw_onecell_data *clk_data;
  655. - struct device_node *node = pdev->dev.of_node;
  656. - int r;
  657. -
  658. - clk_data = mtk_alloc_clk_data(CLK_SSUSB_NR_CLK);
  659. -
  660. - mtk_clk_register_gates(&pdev->dev, node, ssusb_clks,
  661. - ARRAY_SIZE(ssusb_clks), clk_data);
  662. -
  663. - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  664. - if (r)
  665. - dev_err(&pdev->dev,
  666. - "could not register clock provider: %s: %d\n",
  667. - pdev->name, r);
  668. -
  669. - mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  670. -
  671. - return r;
  672. -}
  673. -
  674. -static int clk_mt7629_pciesys_init(struct platform_device *pdev)
  675. -{
  676. - struct clk_hw_onecell_data *clk_data;
  677. - struct device_node *node = pdev->dev.of_node;
  678. - int r;
  679. -
  680. - clk_data = mtk_alloc_clk_data(CLK_PCIE_NR_CLK);
  681. -
  682. - mtk_clk_register_gates(&pdev->dev, node, pcie_clks,
  683. - ARRAY_SIZE(pcie_clks), clk_data);
  684. -
  685. - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  686. - if (r)
  687. - dev_err(&pdev->dev,
  688. - "could not register clock provider: %s: %d\n",
  689. - pdev->name, r);
  690. -
  691. - mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  692. +static const struct mtk_clk_desc ssusb_desc = {
  693. + .clks = ssusb_clks,
  694. + .num_clks = ARRAY_SIZE(ssusb_clks),
  695. + .rst_desc = &clk_rst_desc,
  696. +};
  697. - return r;
  698. -}
  699. +static const struct mtk_clk_desc pcie_desc = {
  700. + .clks = pcie_clks,
  701. + .num_clks = ARRAY_SIZE(pcie_clks),
  702. + .rst_desc = &clk_rst_desc,
  703. +};
  704. static const struct of_device_id of_match_clk_mt7629_hif[] = {
  705. - {
  706. - .compatible = "mediatek,mt7629-pciesys",
  707. - .data = clk_mt7629_pciesys_init,
  708. - }, {
  709. - .compatible = "mediatek,mt7629-ssusbsys",
  710. - .data = clk_mt7629_ssusbsys_init,
  711. - }, {
  712. - /* sentinel */
  713. - }
  714. + { .compatible = "mediatek,mt7629-pciesys", .data = &pcie_desc },
  715. + { .compatible = "mediatek,mt7629-ssusbsys", .data = &ssusb_desc },
  716. + { /* sentinel */ }
  717. };
  718. -static int clk_mt7629_hif_probe(struct platform_device *pdev)
  719. -{
  720. - int (*clk_init)(struct platform_device *);
  721. - int r;
  722. -
  723. - clk_init = of_device_get_match_data(&pdev->dev);
  724. - if (!clk_init)
  725. - return -EINVAL;
  726. -
  727. - r = clk_init(pdev);
  728. - if (r)
  729. - dev_err(&pdev->dev,
  730. - "could not register clock provider: %s: %d\n",
  731. - pdev->name, r);
  732. -
  733. - return r;
  734. -}
  735. -
  736. static struct platform_driver clk_mt7629_hif_drv = {
  737. - .probe = clk_mt7629_hif_probe,
  738. + .probe = mtk_clk_simple_probe,
  739. + .remove = mtk_clk_simple_remove,
  740. .driver = {
  741. .name = "clk-mt7629-hif",
  742. .of_match_table = of_match_clk_mt7629_hif,