0146-clk-mediatek-Add-MT2712-clock-support.patch 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296
  1. From ec5192303a3938d0972fde3b1f2526d8d6dd02d7 Mon Sep 17 00:00:00 2001
  2. From: "[email protected]" <[email protected]>
  3. Date: Mon, 23 Oct 2017 12:10:34 +0800
  4. Subject: [PATCH 146/224] clk: mediatek: Add MT2712 clock support
  5. Add MT2712 clock support, include topckgen, apmixedsys,
  6. infracfg, pericfg, mcucfg and subsystem clocks.
  7. Signed-off-by: Weiyi Lu <[email protected]>
  8. [[email protected]: Static on top_clk_data]
  9. Signed-off-by: Stephen Boyd <[email protected]>
  10. ---
  11. drivers/clk/mediatek/Kconfig | 50 ++
  12. drivers/clk/mediatek/Makefile | 8 +
  13. drivers/clk/mediatek/clk-mt2712-bdp.c | 102 +++
  14. drivers/clk/mediatek/clk-mt2712-img.c | 80 ++
  15. drivers/clk/mediatek/clk-mt2712-jpgdec.c | 76 ++
  16. drivers/clk/mediatek/clk-mt2712-mfg.c | 75 ++
  17. drivers/clk/mediatek/clk-mt2712-mm.c | 170 ++++
  18. drivers/clk/mediatek/clk-mt2712-vdec.c | 94 ++
  19. drivers/clk/mediatek/clk-mt2712-venc.c | 77 ++
  20. drivers/clk/mediatek/clk-mt2712.c | 1435 ++++++++++++++++++++++++++++++
  21. drivers/clk/mediatek/clk-mtk.h | 2 +
  22. drivers/clk/mediatek/clk-pll.c | 13 +-
  23. 12 files changed, 2180 insertions(+), 2 deletions(-)
  24. create mode 100644 drivers/clk/mediatek/clk-mt2712-bdp.c
  25. create mode 100644 drivers/clk/mediatek/clk-mt2712-img.c
  26. create mode 100644 drivers/clk/mediatek/clk-mt2712-jpgdec.c
  27. create mode 100644 drivers/clk/mediatek/clk-mt2712-mfg.c
  28. create mode 100644 drivers/clk/mediatek/clk-mt2712-mm.c
  29. create mode 100644 drivers/clk/mediatek/clk-mt2712-vdec.c
  30. create mode 100644 drivers/clk/mediatek/clk-mt2712-venc.c
  31. create mode 100644 drivers/clk/mediatek/clk-mt2712.c
  32. --- a/drivers/clk/mediatek/Kconfig
  33. +++ b/drivers/clk/mediatek/Kconfig
  34. @@ -50,6 +50,56 @@ config COMMON_CLK_MT2701_BDPSYS
  35. ---help---
  36. This driver supports Mediatek MT2701 bdpsys clocks.
  37. +config COMMON_CLK_MT2712
  38. + bool "Clock driver for Mediatek MT2712"
  39. + depends on (ARCH_MEDIATEK && ARM64) || COMPILE_TEST
  40. + select COMMON_CLK_MEDIATEK
  41. + default ARCH_MEDIATEK && ARM64
  42. + ---help---
  43. + This driver supports Mediatek MT2712 basic clocks.
  44. +
  45. +config COMMON_CLK_MT2712_BDPSYS
  46. + bool "Clock driver for Mediatek MT2712 bdpsys"
  47. + depends on COMMON_CLK_MT2712
  48. + ---help---
  49. + This driver supports Mediatek MT2712 bdpsys clocks.
  50. +
  51. +config COMMON_CLK_MT2712_IMGSYS
  52. + bool "Clock driver for Mediatek MT2712 imgsys"
  53. + depends on COMMON_CLK_MT2712
  54. + ---help---
  55. + This driver supports Mediatek MT2712 imgsys clocks.
  56. +
  57. +config COMMON_CLK_MT2712_JPGDECSYS
  58. + bool "Clock driver for Mediatek MT2712 jpgdecsys"
  59. + depends on COMMON_CLK_MT2712
  60. + ---help---
  61. + This driver supports Mediatek MT2712 jpgdecsys clocks.
  62. +
  63. +config COMMON_CLK_MT2712_MFGCFG
  64. + bool "Clock driver for Mediatek MT2712 mfgcfg"
  65. + depends on COMMON_CLK_MT2712
  66. + ---help---
  67. + This driver supports Mediatek MT2712 mfgcfg clocks.
  68. +
  69. +config COMMON_CLK_MT2712_MMSYS
  70. + bool "Clock driver for Mediatek MT2712 mmsys"
  71. + depends on COMMON_CLK_MT2712
  72. + ---help---
  73. + This driver supports Mediatek MT2712 mmsys clocks.
  74. +
  75. +config COMMON_CLK_MT2712_VDECSYS
  76. + bool "Clock driver for Mediatek MT2712 vdecsys"
  77. + depends on COMMON_CLK_MT2712
  78. + ---help---
  79. + This driver supports Mediatek MT2712 vdecsys clocks.
  80. +
  81. +config COMMON_CLK_MT2712_VENCSYS
  82. + bool "Clock driver for Mediatek MT2712 vencsys"
  83. + depends on COMMON_CLK_MT2712
  84. + ---help---
  85. + This driver supports Mediatek MT2712 vencsys clocks.
  86. +
  87. config COMMON_CLK_MT6797
  88. bool "Clock driver for Mediatek MT6797"
  89. depends on (ARCH_MEDIATEK && ARM64) || COMPILE_TEST
  90. --- a/drivers/clk/mediatek/Makefile
  91. +++ b/drivers/clk/mediatek/Makefile
  92. @@ -13,5 +13,13 @@ obj-$(CONFIG_COMMON_CLK_MT2701_HIFSYS) +
  93. obj-$(CONFIG_COMMON_CLK_MT2701_IMGSYS) += clk-mt2701-img.o
  94. obj-$(CONFIG_COMMON_CLK_MT2701_MMSYS) += clk-mt2701-mm.o
  95. obj-$(CONFIG_COMMON_CLK_MT2701_VDECSYS) += clk-mt2701-vdec.o
  96. +obj-$(CONFIG_COMMON_CLK_MT2712) += clk-mt2712.o
  97. +obj-$(CONFIG_COMMON_CLK_MT2712_BDPSYS) += clk-mt2712-bdp.o
  98. +obj-$(CONFIG_COMMON_CLK_MT2712_IMGSYS) += clk-mt2712-img.o
  99. +obj-$(CONFIG_COMMON_CLK_MT2712_JPGDECSYS) += clk-mt2712-jpgdec.o
  100. +obj-$(CONFIG_COMMON_CLK_MT2712_MFGCFG) += clk-mt2712-mfg.o
  101. +obj-$(CONFIG_COMMON_CLK_MT2712_MMSYS) += clk-mt2712-mm.o
  102. +obj-$(CONFIG_COMMON_CLK_MT2712_VDECSYS) += clk-mt2712-vdec.o
  103. +obj-$(CONFIG_COMMON_CLK_MT2712_VENCSYS) += clk-mt2712-venc.o
  104. obj-$(CONFIG_COMMON_CLK_MT8135) += clk-mt8135.o
  105. obj-$(CONFIG_COMMON_CLK_MT8173) += clk-mt8173.o
  106. --- /dev/null
  107. +++ b/drivers/clk/mediatek/clk-mt2712-bdp.c
  108. @@ -0,0 +1,102 @@
  109. +/*
  110. + * Copyright (c) 2017 MediaTek Inc.
  111. + * Author: Weiyi Lu <[email protected]>
  112. + *
  113. + * This program is free software; you can redistribute it and/or modify
  114. + * it under the terms of the GNU General Public License version 2 as
  115. + * published by the Free Software Foundation.
  116. + *
  117. + * This program is distributed in the hope that it will be useful,
  118. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  119. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  120. + * GNU General Public License for more details.
  121. + */
  122. +
  123. +#include <linux/clk-provider.h>
  124. +#include <linux/platform_device.h>
  125. +
  126. +#include "clk-mtk.h"
  127. +#include "clk-gate.h"
  128. +
  129. +#include <dt-bindings/clock/mt2712-clk.h>
  130. +
  131. +static const struct mtk_gate_regs bdp_cg_regs = {
  132. + .set_ofs = 0x100,
  133. + .clr_ofs = 0x100,
  134. + .sta_ofs = 0x100,
  135. +};
  136. +
  137. +#define GATE_BDP(_id, _name, _parent, _shift) { \
  138. + .id = _id, \
  139. + .name = _name, \
  140. + .parent_name = _parent, \
  141. + .regs = &bdp_cg_regs, \
  142. + .shift = _shift, \
  143. + .ops = &mtk_clk_gate_ops_no_setclr, \
  144. + }
  145. +
  146. +static const struct mtk_gate bdp_clks[] = {
  147. + GATE_BDP(CLK_BDP_BRIDGE_B, "bdp_bridge_b", "mm_sel", 0),
  148. + GATE_BDP(CLK_BDP_BRIDGE_DRAM, "bdp_bridge_d", "mm_sel", 1),
  149. + GATE_BDP(CLK_BDP_LARB_DRAM, "bdp_larb_d", "mm_sel", 2),
  150. + GATE_BDP(CLK_BDP_WR_CHANNEL_VDI_PXL, "bdp_vdi_pxl", "tvd_sel", 3),
  151. + GATE_BDP(CLK_BDP_WR_CHANNEL_VDI_DRAM, "bdp_vdi_d", "mm_sel", 4),
  152. + GATE_BDP(CLK_BDP_WR_CHANNEL_VDI_B, "bdp_vdi_b", "mm_sel", 5),
  153. + GATE_BDP(CLK_BDP_MT_B, "bdp_fmt_b", "mm_sel", 9),
  154. + GATE_BDP(CLK_BDP_DISPFMT_27M, "bdp_27m", "di_sel", 10),
  155. + GATE_BDP(CLK_BDP_DISPFMT_27M_VDOUT, "bdp_27m_vdout", "di_sel", 11),
  156. + GATE_BDP(CLK_BDP_DISPFMT_27_74_74, "bdp_27_74_74", "di_sel", 12),
  157. + GATE_BDP(CLK_BDP_DISPFMT_2FS, "bdp_2fs", "di_sel", 13),
  158. + GATE_BDP(CLK_BDP_DISPFMT_2FS_2FS74_148, "bdp_2fs74_148", "di_sel", 14),
  159. + GATE_BDP(CLK_BDP_DISPFMT_B, "bdp_b", "mm_sel", 15),
  160. + GATE_BDP(CLK_BDP_VDO_DRAM, "bdp_vdo_d", "mm_sel", 16),
  161. + GATE_BDP(CLK_BDP_VDO_2FS, "bdp_vdo_2fs", "di_sel", 17),
  162. + GATE_BDP(CLK_BDP_VDO_B, "bdp_vdo_b", "mm_sel", 18),
  163. + GATE_BDP(CLK_BDP_WR_CHANNEL_DI_PXL, "bdp_di_pxl", "di_sel", 19),
  164. + GATE_BDP(CLK_BDP_WR_CHANNEL_DI_DRAM, "bdp_di_d", "mm_sel", 20),
  165. + GATE_BDP(CLK_BDP_WR_CHANNEL_DI_B, "bdp_di_b", "mm_sel", 21),
  166. + GATE_BDP(CLK_BDP_NR_AGENT, "bdp_nr_agent", "nr_sel", 22),
  167. + GATE_BDP(CLK_BDP_NR_DRAM, "bdp_nr_d", "mm_sel", 23),
  168. + GATE_BDP(CLK_BDP_NR_B, "bdp_nr_b", "mm_sel", 24),
  169. + GATE_BDP(CLK_BDP_BRIDGE_RT_B, "bdp_bridge_rt_b", "mm_sel", 25),
  170. + GATE_BDP(CLK_BDP_BRIDGE_RT_DRAM, "bdp_bridge_rt_d", "mm_sel", 26),
  171. + GATE_BDP(CLK_BDP_LARB_RT_DRAM, "bdp_larb_rt_d", "mm_sel", 27),
  172. + GATE_BDP(CLK_BDP_TVD_TDC, "bdp_tvd_tdc", "mm_sel", 28),
  173. + GATE_BDP(CLK_BDP_TVD_54, "bdp_tvd_clk_54", "tvd_sel", 29),
  174. + GATE_BDP(CLK_BDP_TVD_CBUS, "bdp_tvd_cbus", "mm_sel", 30),
  175. +};
  176. +
  177. +static int clk_mt2712_bdp_probe(struct platform_device *pdev)
  178. +{
  179. + struct clk_onecell_data *clk_data;
  180. + int r;
  181. + struct device_node *node = pdev->dev.of_node;
  182. +
  183. + clk_data = mtk_alloc_clk_data(CLK_BDP_NR_CLK);
  184. +
  185. + mtk_clk_register_gates(node, bdp_clks, ARRAY_SIZE(bdp_clks),
  186. + clk_data);
  187. +
  188. + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  189. +
  190. + if (r != 0)
  191. + pr_err("%s(): could not register clock provider: %d\n",
  192. + __func__, r);
  193. +
  194. + return r;
  195. +}
  196. +
  197. +static const struct of_device_id of_match_clk_mt2712_bdp[] = {
  198. + { .compatible = "mediatek,mt2712-bdpsys", },
  199. + {}
  200. +};
  201. +
  202. +static struct platform_driver clk_mt2712_bdp_drv = {
  203. + .probe = clk_mt2712_bdp_probe,
  204. + .driver = {
  205. + .name = "clk-mt2712-bdp",
  206. + .of_match_table = of_match_clk_mt2712_bdp,
  207. + },
  208. +};
  209. +
  210. +builtin_platform_driver(clk_mt2712_bdp_drv);
  211. --- /dev/null
  212. +++ b/drivers/clk/mediatek/clk-mt2712-img.c
  213. @@ -0,0 +1,80 @@
  214. +/*
  215. + * Copyright (c) 2017 MediaTek Inc.
  216. + * Author: Weiyi Lu <[email protected]>
  217. + *
  218. + * This program is free software; you can redistribute it and/or modify
  219. + * it under the terms of the GNU General Public License version 2 as
  220. + * published by the Free Software Foundation.
  221. + *
  222. + * This program is distributed in the hope that it will be useful,
  223. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  224. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  225. + * GNU General Public License for more details.
  226. + */
  227. +
  228. +#include <linux/clk-provider.h>
  229. +#include <linux/platform_device.h>
  230. +
  231. +#include "clk-mtk.h"
  232. +#include "clk-gate.h"
  233. +
  234. +#include <dt-bindings/clock/mt2712-clk.h>
  235. +
  236. +static const struct mtk_gate_regs img_cg_regs = {
  237. + .set_ofs = 0x0,
  238. + .clr_ofs = 0x0,
  239. + .sta_ofs = 0x0,
  240. +};
  241. +
  242. +#define GATE_IMG(_id, _name, _parent, _shift) { \
  243. + .id = _id, \
  244. + .name = _name, \
  245. + .parent_name = _parent, \
  246. + .regs = &img_cg_regs, \
  247. + .shift = _shift, \
  248. + .ops = &mtk_clk_gate_ops_no_setclr, \
  249. + }
  250. +
  251. +static const struct mtk_gate img_clks[] = {
  252. + GATE_IMG(CLK_IMG_SMI_LARB2, "img_smi_larb2", "mm_sel", 0),
  253. + GATE_IMG(CLK_IMG_SENINF_SCAM_EN, "img_scam_en", "csi0", 3),
  254. + GATE_IMG(CLK_IMG_SENINF_CAM_EN, "img_cam_en", "mm_sel", 8),
  255. + GATE_IMG(CLK_IMG_CAM_SV_EN, "img_cam_sv_en", "mm_sel", 9),
  256. + GATE_IMG(CLK_IMG_CAM_SV1_EN, "img_cam_sv1_en", "mm_sel", 10),
  257. + GATE_IMG(CLK_IMG_CAM_SV2_EN, "img_cam_sv2_en", "mm_sel", 11),
  258. +};
  259. +
  260. +static int clk_mt2712_img_probe(struct platform_device *pdev)
  261. +{
  262. + struct clk_onecell_data *clk_data;
  263. + int r;
  264. + struct device_node *node = pdev->dev.of_node;
  265. +
  266. + clk_data = mtk_alloc_clk_data(CLK_IMG_NR_CLK);
  267. +
  268. + mtk_clk_register_gates(node, img_clks, ARRAY_SIZE(img_clks),
  269. + clk_data);
  270. +
  271. + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  272. +
  273. + if (r != 0)
  274. + pr_err("%s(): could not register clock provider: %d\n",
  275. + __func__, r);
  276. +
  277. + return r;
  278. +}
  279. +
  280. +static const struct of_device_id of_match_clk_mt2712_img[] = {
  281. + { .compatible = "mediatek,mt2712-imgsys", },
  282. + {}
  283. +};
  284. +
  285. +static struct platform_driver clk_mt2712_img_drv = {
  286. + .probe = clk_mt2712_img_probe,
  287. + .driver = {
  288. + .name = "clk-mt2712-img",
  289. + .of_match_table = of_match_clk_mt2712_img,
  290. + },
  291. +};
  292. +
  293. +builtin_platform_driver(clk_mt2712_img_drv);
  294. --- /dev/null
  295. +++ b/drivers/clk/mediatek/clk-mt2712-jpgdec.c
  296. @@ -0,0 +1,76 @@
  297. +/*
  298. + * Copyright (c) 2017 MediaTek Inc.
  299. + * Author: Weiyi Lu <[email protected]>
  300. + *
  301. + * This program is free software; you can redistribute it and/or modify
  302. + * it under the terms of the GNU General Public License version 2 as
  303. + * published by the Free Software Foundation.
  304. + *
  305. + * This program is distributed in the hope that it will be useful,
  306. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  307. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  308. + * GNU General Public License for more details.
  309. + */
  310. +
  311. +#include <linux/clk-provider.h>
  312. +#include <linux/platform_device.h>
  313. +
  314. +#include "clk-mtk.h"
  315. +#include "clk-gate.h"
  316. +
  317. +#include <dt-bindings/clock/mt2712-clk.h>
  318. +
  319. +static const struct mtk_gate_regs jpgdec_cg_regs = {
  320. + .set_ofs = 0x4,
  321. + .clr_ofs = 0x8,
  322. + .sta_ofs = 0x0,
  323. +};
  324. +
  325. +#define GATE_JPGDEC(_id, _name, _parent, _shift) { \
  326. + .id = _id, \
  327. + .name = _name, \
  328. + .parent_name = _parent, \
  329. + .regs = &jpgdec_cg_regs, \
  330. + .shift = _shift, \
  331. + .ops = &mtk_clk_gate_ops_setclr_inv, \
  332. + }
  333. +
  334. +static const struct mtk_gate jpgdec_clks[] = {
  335. + GATE_JPGDEC(CLK_JPGDEC_JPGDEC1, "jpgdec_jpgdec1", "jpgdec_sel", 0),
  336. + GATE_JPGDEC(CLK_JPGDEC_JPGDEC, "jpgdec_jpgdec", "jpgdec_sel", 4),
  337. +};
  338. +
  339. +static int clk_mt2712_jpgdec_probe(struct platform_device *pdev)
  340. +{
  341. + struct clk_onecell_data *clk_data;
  342. + int r;
  343. + struct device_node *node = pdev->dev.of_node;
  344. +
  345. + clk_data = mtk_alloc_clk_data(CLK_JPGDEC_NR_CLK);
  346. +
  347. + mtk_clk_register_gates(node, jpgdec_clks, ARRAY_SIZE(jpgdec_clks),
  348. + clk_data);
  349. +
  350. + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  351. +
  352. + if (r != 0)
  353. + pr_err("%s(): could not register clock provider: %d\n",
  354. + __func__, r);
  355. +
  356. + return r;
  357. +}
  358. +
  359. +static const struct of_device_id of_match_clk_mt2712_jpgdec[] = {
  360. + { .compatible = "mediatek,mt2712-jpgdecsys", },
  361. + {}
  362. +};
  363. +
  364. +static struct platform_driver clk_mt2712_jpgdec_drv = {
  365. + .probe = clk_mt2712_jpgdec_probe,
  366. + .driver = {
  367. + .name = "clk-mt2712-jpgdec",
  368. + .of_match_table = of_match_clk_mt2712_jpgdec,
  369. + },
  370. +};
  371. +
  372. +builtin_platform_driver(clk_mt2712_jpgdec_drv);
  373. --- /dev/null
  374. +++ b/drivers/clk/mediatek/clk-mt2712-mfg.c
  375. @@ -0,0 +1,75 @@
  376. +/*
  377. + * Copyright (c) 2017 MediaTek Inc.
  378. + * Author: Weiyi Lu <[email protected]>
  379. + *
  380. + * This program is free software; you can redistribute it and/or modify
  381. + * it under the terms of the GNU General Public License version 2 as
  382. + * published by the Free Software Foundation.
  383. + *
  384. + * This program is distributed in the hope that it will be useful,
  385. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  386. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  387. + * GNU General Public License for more details.
  388. + */
  389. +
  390. +#include <linux/clk-provider.h>
  391. +#include <linux/platform_device.h>
  392. +
  393. +#include "clk-mtk.h"
  394. +#include "clk-gate.h"
  395. +
  396. +#include <dt-bindings/clock/mt2712-clk.h>
  397. +
  398. +static const struct mtk_gate_regs mfg_cg_regs = {
  399. + .set_ofs = 0x4,
  400. + .clr_ofs = 0x8,
  401. + .sta_ofs = 0x0,
  402. +};
  403. +
  404. +#define GATE_MFG(_id, _name, _parent, _shift) { \
  405. + .id = _id, \
  406. + .name = _name, \
  407. + .parent_name = _parent, \
  408. + .regs = &mfg_cg_regs, \
  409. + .shift = _shift, \
  410. + .ops = &mtk_clk_gate_ops_setclr, \
  411. + }
  412. +
  413. +static const struct mtk_gate mfg_clks[] = {
  414. + GATE_MFG(CLK_MFG_BG3D, "mfg_bg3d", "mfg_sel", 0),
  415. +};
  416. +
  417. +static int clk_mt2712_mfg_probe(struct platform_device *pdev)
  418. +{
  419. + struct clk_onecell_data *clk_data;
  420. + int r;
  421. + struct device_node *node = pdev->dev.of_node;
  422. +
  423. + clk_data = mtk_alloc_clk_data(CLK_MFG_NR_CLK);
  424. +
  425. + mtk_clk_register_gates(node, mfg_clks, ARRAY_SIZE(mfg_clks),
  426. + clk_data);
  427. +
  428. + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  429. +
  430. + if (r != 0)
  431. + pr_err("%s(): could not register clock provider: %d\n",
  432. + __func__, r);
  433. +
  434. + return r;
  435. +}
  436. +
  437. +static const struct of_device_id of_match_clk_mt2712_mfg[] = {
  438. + { .compatible = "mediatek,mt2712-mfgcfg", },
  439. + {}
  440. +};
  441. +
  442. +static struct platform_driver clk_mt2712_mfg_drv = {
  443. + .probe = clk_mt2712_mfg_probe,
  444. + .driver = {
  445. + .name = "clk-mt2712-mfg",
  446. + .of_match_table = of_match_clk_mt2712_mfg,
  447. + },
  448. +};
  449. +
  450. +builtin_platform_driver(clk_mt2712_mfg_drv);
  451. --- /dev/null
  452. +++ b/drivers/clk/mediatek/clk-mt2712-mm.c
  453. @@ -0,0 +1,170 @@
  454. +/*
  455. + * Copyright (c) 2017 MediaTek Inc.
  456. + * Author: Weiyi Lu <[email protected]>
  457. + *
  458. + * This program is free software; you can redistribute it and/or modify
  459. + * it under the terms of the GNU General Public License version 2 as
  460. + * published by the Free Software Foundation.
  461. + *
  462. + * This program is distributed in the hope that it will be useful,
  463. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  464. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  465. + * GNU General Public License for more details.
  466. + */
  467. +
  468. +#include <linux/clk-provider.h>
  469. +#include <linux/platform_device.h>
  470. +
  471. +#include "clk-mtk.h"
  472. +#include "clk-gate.h"
  473. +
  474. +#include <dt-bindings/clock/mt2712-clk.h>
  475. +
  476. +static const struct mtk_gate_regs mm0_cg_regs = {
  477. + .set_ofs = 0x104,
  478. + .clr_ofs = 0x108,
  479. + .sta_ofs = 0x100,
  480. +};
  481. +
  482. +static const struct mtk_gate_regs mm1_cg_regs = {
  483. + .set_ofs = 0x114,
  484. + .clr_ofs = 0x118,
  485. + .sta_ofs = 0x110,
  486. +};
  487. +
  488. +static const struct mtk_gate_regs mm2_cg_regs = {
  489. + .set_ofs = 0x224,
  490. + .clr_ofs = 0x228,
  491. + .sta_ofs = 0x220,
  492. +};
  493. +
  494. +#define GATE_MM0(_id, _name, _parent, _shift) { \
  495. + .id = _id, \
  496. + .name = _name, \
  497. + .parent_name = _parent, \
  498. + .regs = &mm0_cg_regs, \
  499. + .shift = _shift, \
  500. + .ops = &mtk_clk_gate_ops_setclr, \
  501. + }
  502. +
  503. +#define GATE_MM1(_id, _name, _parent, _shift) { \
  504. + .id = _id, \
  505. + .name = _name, \
  506. + .parent_name = _parent, \
  507. + .regs = &mm1_cg_regs, \
  508. + .shift = _shift, \
  509. + .ops = &mtk_clk_gate_ops_setclr, \
  510. + }
  511. +
  512. +#define GATE_MM2(_id, _name, _parent, _shift) { \
  513. + .id = _id, \
  514. + .name = _name, \
  515. + .parent_name = _parent, \
  516. + .regs = &mm2_cg_regs, \
  517. + .shift = _shift, \
  518. + .ops = &mtk_clk_gate_ops_setclr, \
  519. + }
  520. +
  521. +static const struct mtk_gate mm_clks[] = {
  522. + /* MM0 */
  523. + GATE_MM0(CLK_MM_SMI_COMMON, "mm_smi_common", "mm_sel", 0),
  524. + GATE_MM0(CLK_MM_SMI_LARB0, "mm_smi_larb0", "mm_sel", 1),
  525. + GATE_MM0(CLK_MM_CAM_MDP, "mm_cam_mdp", "mm_sel", 2),
  526. + GATE_MM0(CLK_MM_MDP_RDMA0, "mm_mdp_rdma0", "mm_sel", 3),
  527. + GATE_MM0(CLK_MM_MDP_RDMA1, "mm_mdp_rdma1", "mm_sel", 4),
  528. + GATE_MM0(CLK_MM_MDP_RSZ0, "mm_mdp_rsz0", "mm_sel", 5),
  529. + GATE_MM0(CLK_MM_MDP_RSZ1, "mm_mdp_rsz1", "mm_sel", 6),
  530. + GATE_MM0(CLK_MM_MDP_RSZ2, "mm_mdp_rsz2", "mm_sel", 7),
  531. + GATE_MM0(CLK_MM_MDP_TDSHP0, "mm_mdp_tdshp0", "mm_sel", 8),
  532. + GATE_MM0(CLK_MM_MDP_TDSHP1, "mm_mdp_tdshp1", "mm_sel", 9),
  533. + GATE_MM0(CLK_MM_MDP_CROP, "mm_mdp_crop", "mm_sel", 10),
  534. + GATE_MM0(CLK_MM_MDP_WDMA, "mm_mdp_wdma", "mm_sel", 11),
  535. + GATE_MM0(CLK_MM_MDP_WROT0, "mm_mdp_wrot0", "mm_sel", 12),
  536. + GATE_MM0(CLK_MM_MDP_WROT1, "mm_mdp_wrot1", "mm_sel", 13),
  537. + GATE_MM0(CLK_MM_FAKE_ENG, "mm_fake_eng", "mm_sel", 14),
  538. + GATE_MM0(CLK_MM_MUTEX_32K, "mm_mutex_32k", "clk32k", 15),
  539. + GATE_MM0(CLK_MM_DISP_OVL0, "mm_disp_ovl0", "mm_sel", 16),
  540. + GATE_MM0(CLK_MM_DISP_OVL1, "mm_disp_ovl1", "mm_sel", 17),
  541. + GATE_MM0(CLK_MM_DISP_RDMA0, "mm_disp_rdma0", "mm_sel", 18),
  542. + GATE_MM0(CLK_MM_DISP_RDMA1, "mm_disp_rdma1", "mm_sel", 19),
  543. + GATE_MM0(CLK_MM_DISP_RDMA2, "mm_disp_rdma2", "mm_sel", 20),
  544. + GATE_MM0(CLK_MM_DISP_WDMA0, "mm_disp_wdma0", "mm_sel", 21),
  545. + GATE_MM0(CLK_MM_DISP_WDMA1, "mm_disp_wdma1", "mm_sel", 22),
  546. + GATE_MM0(CLK_MM_DISP_COLOR0, "mm_disp_color0", "mm_sel", 23),
  547. + GATE_MM0(CLK_MM_DISP_COLOR1, "mm_disp_color1", "mm_sel", 24),
  548. + GATE_MM0(CLK_MM_DISP_AAL, "mm_disp_aal", "mm_sel", 25),
  549. + GATE_MM0(CLK_MM_DISP_GAMMA, "mm_disp_gamma", "mm_sel", 26),
  550. + GATE_MM0(CLK_MM_DISP_UFOE, "mm_disp_ufoe", "mm_sel", 27),
  551. + GATE_MM0(CLK_MM_DISP_SPLIT0, "mm_disp_split0", "mm_sel", 28),
  552. + GATE_MM0(CLK_MM_DISP_OD, "mm_disp_od", "mm_sel", 31),
  553. + /* MM1 */
  554. + GATE_MM1(CLK_MM_DISP_PWM0_MM, "mm_pwm0_mm", "mm_sel", 0),
  555. + GATE_MM1(CLK_MM_DISP_PWM0_26M, "mm_pwm0_26m", "pwm_sel", 1),
  556. + GATE_MM1(CLK_MM_DISP_PWM1_MM, "mm_pwm1_mm", "mm_sel", 2),
  557. + GATE_MM1(CLK_MM_DISP_PWM1_26M, "mm_pwm1_26m", "pwm_sel", 3),
  558. + GATE_MM1(CLK_MM_DSI0_ENGINE, "mm_dsi0_engine", "mm_sel", 4),
  559. + GATE_MM1(CLK_MM_DSI0_DIGITAL, "mm_dsi0_digital", "dsi0_lntc", 5),
  560. + GATE_MM1(CLK_MM_DSI1_ENGINE, "mm_dsi1_engine", "mm_sel", 6),
  561. + GATE_MM1(CLK_MM_DSI1_DIGITAL, "mm_dsi1_digital", "dsi1_lntc", 7),
  562. + GATE_MM1(CLK_MM_DPI_PIXEL, "mm_dpi_pixel", "vpll_dpix", 8),
  563. + GATE_MM1(CLK_MM_DPI_ENGINE, "mm_dpi_engine", "mm_sel", 9),
  564. + GATE_MM1(CLK_MM_DPI1_PIXEL, "mm_dpi1_pixel", "vpll3_dpix", 10),
  565. + GATE_MM1(CLK_MM_DPI1_ENGINE, "mm_dpi1_engine", "mm_sel", 11),
  566. + GATE_MM1(CLK_MM_LVDS_PIXEL, "mm_lvds_pixel", "vpll_dpix", 16),
  567. + GATE_MM1(CLK_MM_LVDS_CTS, "mm_lvds_cts", "lvdstx", 17),
  568. + GATE_MM1(CLK_MM_SMI_LARB4, "mm_smi_larb4", "mm_sel", 18),
  569. + GATE_MM1(CLK_MM_SMI_COMMON1, "mm_smi_common1", "mm_sel", 21),
  570. + GATE_MM1(CLK_MM_SMI_LARB5, "mm_smi_larb5", "mm_sel", 22),
  571. + GATE_MM1(CLK_MM_MDP_RDMA2, "mm_mdp_rdma2", "mm_sel", 23),
  572. + GATE_MM1(CLK_MM_MDP_TDSHP2, "mm_mdp_tdshp2", "mm_sel", 24),
  573. + GATE_MM1(CLK_MM_DISP_OVL2, "mm_disp_ovl2", "mm_sel", 25),
  574. + GATE_MM1(CLK_MM_DISP_WDMA2, "mm_disp_wdma2", "mm_sel", 26),
  575. + GATE_MM1(CLK_MM_DISP_COLOR2, "mm_disp_color2", "mm_sel", 27),
  576. + GATE_MM1(CLK_MM_DISP_AAL1, "mm_disp_aal1", "mm_sel", 28),
  577. + GATE_MM1(CLK_MM_DISP_OD1, "mm_disp_od1", "mm_sel", 29),
  578. + GATE_MM1(CLK_MM_LVDS1_PIXEL, "mm_lvds1_pixel", "vpll3_dpix", 30),
  579. + GATE_MM1(CLK_MM_LVDS1_CTS, "mm_lvds1_cts", "lvdstx3", 31),
  580. + /* MM2 */
  581. + GATE_MM2(CLK_MM_SMI_LARB7, "mm_smi_larb7", "mm_sel", 0),
  582. + GATE_MM2(CLK_MM_MDP_RDMA3, "mm_mdp_rdma3", "mm_sel", 1),
  583. + GATE_MM2(CLK_MM_MDP_WROT2, "mm_mdp_wrot2", "mm_sel", 2),
  584. + GATE_MM2(CLK_MM_DSI2, "mm_dsi2", "mm_sel", 3),
  585. + GATE_MM2(CLK_MM_DSI2_DIGITAL, "mm_dsi2_digital", "dsi0_lntc", 4),
  586. + GATE_MM2(CLK_MM_DSI3, "mm_dsi3", "mm_sel", 5),
  587. + GATE_MM2(CLK_MM_DSI3_DIGITAL, "mm_dsi3_digital", "dsi1_lntc", 6),
  588. +};
  589. +
  590. +static int clk_mt2712_mm_probe(struct platform_device *pdev)
  591. +{
  592. + struct clk_onecell_data *clk_data;
  593. + int r;
  594. + struct device_node *node = pdev->dev.of_node;
  595. +
  596. + clk_data = mtk_alloc_clk_data(CLK_MM_NR_CLK);
  597. +
  598. + mtk_clk_register_gates(node, mm_clks, ARRAY_SIZE(mm_clks),
  599. + clk_data);
  600. +
  601. + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  602. +
  603. + if (r != 0)
  604. + pr_err("%s(): could not register clock provider: %d\n",
  605. + __func__, r);
  606. +
  607. + return r;
  608. +}
  609. +
  610. +static const struct of_device_id of_match_clk_mt2712_mm[] = {
  611. + { .compatible = "mediatek,mt2712-mmsys", },
  612. + {}
  613. +};
  614. +
  615. +static struct platform_driver clk_mt2712_mm_drv = {
  616. + .probe = clk_mt2712_mm_probe,
  617. + .driver = {
  618. + .name = "clk-mt2712-mm",
  619. + .of_match_table = of_match_clk_mt2712_mm,
  620. + },
  621. +};
  622. +
  623. +builtin_platform_driver(clk_mt2712_mm_drv);
  624. --- /dev/null
  625. +++ b/drivers/clk/mediatek/clk-mt2712-vdec.c
  626. @@ -0,0 +1,94 @@
  627. +/*
  628. + * Copyright (c) 2017 MediaTek Inc.
  629. + * Author: Weiyi Lu <[email protected]>
  630. + *
  631. + * This program is free software; you can redistribute it and/or modify
  632. + * it under the terms of the GNU General Public License version 2 as
  633. + * published by the Free Software Foundation.
  634. + *
  635. + * This program is distributed in the hope that it will be useful,
  636. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  637. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  638. + * GNU General Public License for more details.
  639. + */
  640. +
  641. +#include <linux/clk-provider.h>
  642. +#include <linux/platform_device.h>
  643. +
  644. +#include "clk-mtk.h"
  645. +#include "clk-gate.h"
  646. +
  647. +#include <dt-bindings/clock/mt2712-clk.h>
  648. +
  649. +static const struct mtk_gate_regs vdec0_cg_regs = {
  650. + .set_ofs = 0x0,
  651. + .clr_ofs = 0x4,
  652. + .sta_ofs = 0x0,
  653. +};
  654. +
  655. +static const struct mtk_gate_regs vdec1_cg_regs = {
  656. + .set_ofs = 0x8,
  657. + .clr_ofs = 0xc,
  658. + .sta_ofs = 0x8,
  659. +};
  660. +
  661. +#define GATE_VDEC0(_id, _name, _parent, _shift) { \
  662. + .id = _id, \
  663. + .name = _name, \
  664. + .parent_name = _parent, \
  665. + .regs = &vdec0_cg_regs, \
  666. + .shift = _shift, \
  667. + .ops = &mtk_clk_gate_ops_setclr_inv, \
  668. + }
  669. +
  670. +#define GATE_VDEC1(_id, _name, _parent, _shift) { \
  671. + .id = _id, \
  672. + .name = _name, \
  673. + .parent_name = _parent, \
  674. + .regs = &vdec1_cg_regs, \
  675. + .shift = _shift, \
  676. + .ops = &mtk_clk_gate_ops_setclr_inv, \
  677. + }
  678. +
  679. +static const struct mtk_gate vdec_clks[] = {
  680. + /* VDEC0 */
  681. + GATE_VDEC0(CLK_VDEC_CKEN, "vdec_cken", "vdec_sel", 0),
  682. + /* VDEC1 */
  683. + GATE_VDEC1(CLK_VDEC_LARB1_CKEN, "vdec_larb1_cken", "vdec_sel", 0),
  684. + GATE_VDEC1(CLK_VDEC_IMGRZ_CKEN, "vdec_imgrz_cken", "vdec_sel", 1),
  685. +};
  686. +
  687. +static int clk_mt2712_vdec_probe(struct platform_device *pdev)
  688. +{
  689. + struct clk_onecell_data *clk_data;
  690. + int r;
  691. + struct device_node *node = pdev->dev.of_node;
  692. +
  693. + clk_data = mtk_alloc_clk_data(CLK_VDEC_NR_CLK);
  694. +
  695. + mtk_clk_register_gates(node, vdec_clks, ARRAY_SIZE(vdec_clks),
  696. + clk_data);
  697. +
  698. + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  699. +
  700. + if (r != 0)
  701. + pr_err("%s(): could not register clock provider: %d\n",
  702. + __func__, r);
  703. +
  704. + return r;
  705. +}
  706. +
  707. +static const struct of_device_id of_match_clk_mt2712_vdec[] = {
  708. + { .compatible = "mediatek,mt2712-vdecsys", },
  709. + {}
  710. +};
  711. +
  712. +static struct platform_driver clk_mt2712_vdec_drv = {
  713. + .probe = clk_mt2712_vdec_probe,
  714. + .driver = {
  715. + .name = "clk-mt2712-vdec",
  716. + .of_match_table = of_match_clk_mt2712_vdec,
  717. + },
  718. +};
  719. +
  720. +builtin_platform_driver(clk_mt2712_vdec_drv);
  721. --- /dev/null
  722. +++ b/drivers/clk/mediatek/clk-mt2712-venc.c
  723. @@ -0,0 +1,77 @@
  724. +/*
  725. + * Copyright (c) 2017 MediaTek Inc.
  726. + * Author: Weiyi Lu <[email protected]>
  727. + *
  728. + * This program is free software; you can redistribute it and/or modify
  729. + * it under the terms of the GNU General Public License version 2 as
  730. + * published by the Free Software Foundation.
  731. + *
  732. + * This program is distributed in the hope that it will be useful,
  733. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  734. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  735. + * GNU General Public License for more details.
  736. + */
  737. +
  738. +#include <linux/clk-provider.h>
  739. +#include <linux/platform_device.h>
  740. +
  741. +#include "clk-mtk.h"
  742. +#include "clk-gate.h"
  743. +
  744. +#include <dt-bindings/clock/mt2712-clk.h>
  745. +
  746. +static const struct mtk_gate_regs venc_cg_regs = {
  747. + .set_ofs = 0x4,
  748. + .clr_ofs = 0x8,
  749. + .sta_ofs = 0x0,
  750. +};
  751. +
  752. +#define GATE_VENC(_id, _name, _parent, _shift) { \
  753. + .id = _id, \
  754. + .name = _name, \
  755. + .parent_name = _parent, \
  756. + .regs = &venc_cg_regs, \
  757. + .shift = _shift, \
  758. + .ops = &mtk_clk_gate_ops_setclr_inv, \
  759. + }
  760. +
  761. +static const struct mtk_gate venc_clks[] = {
  762. + GATE_VENC(CLK_VENC_SMI_COMMON_CON, "venc_smi", "mm_sel", 0),
  763. + GATE_VENC(CLK_VENC_VENC, "venc_venc", "venc_sel", 4),
  764. + GATE_VENC(CLK_VENC_SMI_LARB6, "venc_smi_larb6", "jpgdec_sel", 12),
  765. +};
  766. +
  767. +static int clk_mt2712_venc_probe(struct platform_device *pdev)
  768. +{
  769. + struct clk_onecell_data *clk_data;
  770. + int r;
  771. + struct device_node *node = pdev->dev.of_node;
  772. +
  773. + clk_data = mtk_alloc_clk_data(CLK_VENC_NR_CLK);
  774. +
  775. + mtk_clk_register_gates(node, venc_clks, ARRAY_SIZE(venc_clks),
  776. + clk_data);
  777. +
  778. + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  779. +
  780. + if (r != 0)
  781. + pr_err("%s(): could not register clock provider: %d\n",
  782. + __func__, r);
  783. +
  784. + return r;
  785. +}
  786. +
  787. +static const struct of_device_id of_match_clk_mt2712_venc[] = {
  788. + { .compatible = "mediatek,mt2712-vencsys", },
  789. + {}
  790. +};
  791. +
  792. +static struct platform_driver clk_mt2712_venc_drv = {
  793. + .probe = clk_mt2712_venc_probe,
  794. + .driver = {
  795. + .name = "clk-mt2712-venc",
  796. + .of_match_table = of_match_clk_mt2712_venc,
  797. + },
  798. +};
  799. +
  800. +builtin_platform_driver(clk_mt2712_venc_drv);
  801. --- /dev/null
  802. +++ b/drivers/clk/mediatek/clk-mt2712.c
  803. @@ -0,0 +1,1435 @@
  804. +/*
  805. + * Copyright (c) 2017 MediaTek Inc.
  806. + * Author: Weiyi Lu <[email protected]>
  807. + *
  808. + * This program is free software; you can redistribute it and/or modify
  809. + * it under the terms of the GNU General Public License version 2 as
  810. + * published by the Free Software Foundation.
  811. + *
  812. + * This program is distributed in the hope that it will be useful,
  813. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  814. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  815. + * GNU General Public License for more details.
  816. + */
  817. +
  818. +#include <linux/clk.h>
  819. +#include <linux/delay.h>
  820. +#include <linux/mfd/syscon.h>
  821. +#include <linux/of.h>
  822. +#include <linux/of_address.h>
  823. +#include <linux/of_device.h>
  824. +#include <linux/platform_device.h>
  825. +#include <linux/slab.h>
  826. +
  827. +#include "clk-mtk.h"
  828. +#include "clk-gate.h"
  829. +
  830. +#include <dt-bindings/clock/mt2712-clk.h>
  831. +
  832. +static DEFINE_SPINLOCK(mt2712_clk_lock);
  833. +
  834. +static const struct mtk_fixed_clk top_fixed_clks[] = {
  835. + FIXED_CLK(CLK_TOP_VPLL3_DPIX, "vpll3_dpix", NULL, 200000000),
  836. + FIXED_CLK(CLK_TOP_VPLL_DPIX, "vpll_dpix", NULL, 200000000),
  837. + FIXED_CLK(CLK_TOP_LTEPLL_FS26M, "ltepll_fs26m", NULL, 26000000),
  838. + FIXED_CLK(CLK_TOP_DMPLL, "dmpll_ck", NULL, 350000000),
  839. + FIXED_CLK(CLK_TOP_DSI0_LNTC, "dsi0_lntc", NULL, 143000000),
  840. + FIXED_CLK(CLK_TOP_DSI1_LNTC, "dsi1_lntc", NULL, 143000000),
  841. + FIXED_CLK(CLK_TOP_LVDSTX3_CLKDIG_CTS, "lvdstx3", NULL, 140000000),
  842. + FIXED_CLK(CLK_TOP_LVDSTX_CLKDIG_CTS, "lvdstx", NULL, 140000000),
  843. + FIXED_CLK(CLK_TOP_CLKRTC_EXT, "clkrtc_ext", NULL, 32768),
  844. + FIXED_CLK(CLK_TOP_CLKRTC_INT, "clkrtc_int", NULL, 32747),
  845. + FIXED_CLK(CLK_TOP_CSI0, "csi0", NULL, 26000000),
  846. + FIXED_CLK(CLK_TOP_CVBSPLL, "cvbspll", NULL, 108000000),
  847. +};
  848. +
  849. +static const struct mtk_fixed_factor top_early_divs[] = {
  850. + FACTOR(CLK_TOP_SYS_26M, "sys_26m", "clk26m", 1,
  851. + 1),
  852. + FACTOR(CLK_TOP_CLK26M_D2, "clk26m_d2", "sys_26m", 1,
  853. + 2),
  854. +};
  855. +
  856. +static const struct mtk_fixed_factor top_divs[] = {
  857. + FACTOR(CLK_TOP_ARMCA35PLL, "armca35pll_ck", "armca35pll", 1,
  858. + 1),
  859. + FACTOR(CLK_TOP_ARMCA35PLL_600M, "armca35pll_600m", "armca35pll_ck", 1,
  860. + 2),
  861. + FACTOR(CLK_TOP_ARMCA35PLL_400M, "armca35pll_400m", "armca35pll_ck", 1,
  862. + 3),
  863. + FACTOR(CLK_TOP_ARMCA72PLL, "armca72pll_ck", "armca72pll", 1,
  864. + 1),
  865. + FACTOR(CLK_TOP_SYSPLL, "syspll_ck", "mainpll", 1,
  866. + 1),
  867. + FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "syspll_ck", 1,
  868. + 2),
  869. + FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "syspll_d2", 1,
  870. + 2),
  871. + FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "syspll_d2", 1,
  872. + 4),
  873. + FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "syspll_d2", 1,
  874. + 8),
  875. + FACTOR(CLK_TOP_SYSPLL1_D16, "syspll1_d16", "syspll_d2", 1,
  876. + 16),
  877. + FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "syspll_ck", 1,
  878. + 3),
  879. + FACTOR(CLK_TOP_SYSPLL2_D2, "syspll2_d2", "syspll_d3", 1,
  880. + 2),
  881. + FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "syspll_d3", 1,
  882. + 4),
  883. + FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "syspll_ck", 1,
  884. + 5),
  885. + FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "syspll_d5", 1,
  886. + 2),
  887. + FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "syspll_d5", 1,
  888. + 4),
  889. + FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "syspll_ck", 1,
  890. + 7),
  891. + FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "syspll_d7", 1,
  892. + 2),
  893. + FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "syspll_d7", 1,
  894. + 4),
  895. + FACTOR(CLK_TOP_UNIVPLL, "univpll_ck", "univpll", 1,
  896. + 1),
  897. + FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll_ck", 1,
  898. + 7),
  899. + FACTOR(CLK_TOP_UNIVPLL_D26, "univpll_d26", "univpll_ck", 1,
  900. + 26),
  901. + FACTOR(CLK_TOP_UNIVPLL_D52, "univpll_d52", "univpll_ck", 1,
  902. + 52),
  903. + FACTOR(CLK_TOP_UNIVPLL_D104, "univpll_d104", "univpll_ck", 1,
  904. + 104),
  905. + FACTOR(CLK_TOP_UNIVPLL_D208, "univpll_d208", "univpll_ck", 1,
  906. + 208),
  907. + FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll_ck", 1,
  908. + 2),
  909. + FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll_d2", 1,
  910. + 2),
  911. + FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll_d2", 1,
  912. + 4),
  913. + FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univpll_d2", 1,
  914. + 8),
  915. + FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll_ck", 1,
  916. + 3),
  917. + FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll_d3", 1,
  918. + 2),
  919. + FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll_d3", 1,
  920. + 4),
  921. + FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll_d3", 1,
  922. + 8),
  923. + FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll_ck", 1,
  924. + 5),
  925. + FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univpll_d5", 1,
  926. + 2),
  927. + FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univpll_d5", 1,
  928. + 4),
  929. + FACTOR(CLK_TOP_UNIVPLL3_D8, "univpll3_d8", "univpll_d5", 1,
  930. + 8),
  931. + FACTOR(CLK_TOP_F_MP0_PLL1, "f_mp0_pll1_ck", "univpll_d2", 1,
  932. + 1),
  933. + FACTOR(CLK_TOP_F_MP0_PLL2, "f_mp0_pll2_ck", "univpll1_d2", 1,
  934. + 1),
  935. + FACTOR(CLK_TOP_F_BIG_PLL1, "f_big_pll1_ck", "univpll_d2", 1,
  936. + 1),
  937. + FACTOR(CLK_TOP_F_BIG_PLL2, "f_big_pll2_ck", "univpll1_d2", 1,
  938. + 1),
  939. + FACTOR(CLK_TOP_F_BUS_PLL1, "f_bus_pll1_ck", "univpll_d2", 1,
  940. + 1),
  941. + FACTOR(CLK_TOP_F_BUS_PLL2, "f_bus_pll2_ck", "univpll1_d2", 1,
  942. + 1),
  943. + FACTOR(CLK_TOP_APLL1, "apll1_ck", "apll1", 1,
  944. + 1),
  945. + FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", "apll1_ck", 1,
  946. + 2),
  947. + FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "apll1_ck", 1,
  948. + 4),
  949. + FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", "apll1_ck", 1,
  950. + 8),
  951. + FACTOR(CLK_TOP_APLL1_D16, "apll1_d16", "apll1_ck", 1,
  952. + 16),
  953. + FACTOR(CLK_TOP_APLL2, "apll2_ck", "apll2", 1,
  954. + 1),
  955. + FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", "apll2_ck", 1,
  956. + 2),
  957. + FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "apll2_ck", 1,
  958. + 4),
  959. + FACTOR(CLK_TOP_APLL2_D8, "apll2_d8", "apll2_ck", 1,
  960. + 8),
  961. + FACTOR(CLK_TOP_APLL2_D16, "apll2_d16", "apll2_ck", 1,
  962. + 16),
  963. + FACTOR(CLK_TOP_LVDSPLL, "lvdspll_ck", "lvdspll", 1,
  964. + 1),
  965. + FACTOR(CLK_TOP_LVDSPLL_D2, "lvdspll_d2", "lvdspll_ck", 1,
  966. + 2),
  967. + FACTOR(CLK_TOP_LVDSPLL_D4, "lvdspll_d4", "lvdspll_ck", 1,
  968. + 4),
  969. + FACTOR(CLK_TOP_LVDSPLL_D8, "lvdspll_d8", "lvdspll_ck", 1,
  970. + 8),
  971. + FACTOR(CLK_TOP_LVDSPLL2, "lvdspll2_ck", "lvdspll2", 1,
  972. + 1),
  973. + FACTOR(CLK_TOP_LVDSPLL2_D2, "lvdspll2_d2", "lvdspll2_ck", 1,
  974. + 2),
  975. + FACTOR(CLK_TOP_LVDSPLL2_D4, "lvdspll2_d4", "lvdspll2_ck", 1,
  976. + 4),
  977. + FACTOR(CLK_TOP_LVDSPLL2_D8, "lvdspll2_d8", "lvdspll2_ck", 1,
  978. + 8),
  979. + FACTOR(CLK_TOP_ETHERPLL_125M, "etherpll_125m", "etherpll", 1,
  980. + 1),
  981. + FACTOR(CLK_TOP_ETHERPLL_50M, "etherpll_50m", "etherpll", 1,
  982. + 1),
  983. + FACTOR(CLK_TOP_CVBS, "cvbs", "cvbspll", 1,
  984. + 1),
  985. + FACTOR(CLK_TOP_CVBS_D2, "cvbs_d2", "cvbs", 1,
  986. + 2),
  987. + FACTOR(CLK_TOP_MMPLL, "mmpll_ck", "mmpll", 1,
  988. + 1),
  989. + FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", "mmpll_ck", 1,
  990. + 2),
  991. + FACTOR(CLK_TOP_VENCPLL, "vencpll_ck", "vencpll", 1,
  992. + 1),
  993. + FACTOR(CLK_TOP_VENCPLL_D2, "vencpll_d2", "vencpll_ck", 1,
  994. + 2),
  995. + FACTOR(CLK_TOP_VCODECPLL, "vcodecpll_ck", "vcodecpll", 1,
  996. + 1),
  997. + FACTOR(CLK_TOP_VCODECPLL_D2, "vcodecpll_d2", "vcodecpll_ck", 1,
  998. + 2),
  999. + FACTOR(CLK_TOP_TVDPLL, "tvdpll_ck", "tvdpll", 1,
  1000. + 1),
  1001. + FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll_ck", 1,
  1002. + 2),
  1003. + FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll_ck", 1,
  1004. + 4),
  1005. + FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll_ck", 1,
  1006. + 8),
  1007. + FACTOR(CLK_TOP_TVDPLL_429M, "tvdpll_429m", "tvdpll", 1,
  1008. + 1),
  1009. + FACTOR(CLK_TOP_TVDPLL_429M_D2, "tvdpll_429m_d2", "tvdpll_429m", 1,
  1010. + 2),
  1011. + FACTOR(CLK_TOP_TVDPLL_429M_D4, "tvdpll_429m_d4", "tvdpll_429m", 1,
  1012. + 4),
  1013. + FACTOR(CLK_TOP_MSDCPLL, "msdcpll_ck", "msdcpll", 1,
  1014. + 1),
  1015. + FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll_ck", 1,
  1016. + 2),
  1017. + FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll_ck", 1,
  1018. + 4),
  1019. + FACTOR(CLK_TOP_MSDCPLL2, "msdcpll2_ck", "msdcpll2", 1,
  1020. + 1),
  1021. + FACTOR(CLK_TOP_MSDCPLL2_D2, "msdcpll2_d2", "msdcpll2_ck", 1,
  1022. + 2),
  1023. + FACTOR(CLK_TOP_MSDCPLL2_D4, "msdcpll2_d4", "msdcpll2_ck", 1,
  1024. + 4),
  1025. + FACTOR(CLK_TOP_D2A_ULCLK_6P5M, "d2a_ulclk_6p5m", "clk26m", 1,
  1026. + 4),
  1027. +};
  1028. +
  1029. +static const char * const axi_parents[] = {
  1030. + "clk26m",
  1031. + "syspll1_d2",
  1032. + "syspll_d5",
  1033. + "syspll1_d4",
  1034. + "univpll_d5",
  1035. + "univpll2_d2",
  1036. + "msdcpll2_ck"
  1037. +};
  1038. +
  1039. +static const char * const mem_parents[] = {
  1040. + "clk26m",
  1041. + "dmpll_ck"
  1042. +};
  1043. +
  1044. +static const char * const mm_parents[] = {
  1045. + "clk26m",
  1046. + "vencpll_ck",
  1047. + "syspll_d3",
  1048. + "syspll1_d2",
  1049. + "syspll_d5",
  1050. + "syspll1_d4",
  1051. + "univpll1_d2",
  1052. + "univpll2_d2"
  1053. +};
  1054. +
  1055. +static const char * const pwm_parents[] = {
  1056. + "clk26m",
  1057. + "univpll2_d4",
  1058. + "univpll3_d2",
  1059. + "univpll1_d4"
  1060. +};
  1061. +
  1062. +static const char * const vdec_parents[] = {
  1063. + "clk26m",
  1064. + "vcodecpll_ck",
  1065. + "tvdpll_429m",
  1066. + "univpll_d3",
  1067. + "vencpll_ck",
  1068. + "syspll_d3",
  1069. + "univpll1_d2",
  1070. + "mmpll_d2",
  1071. + "syspll3_d2",
  1072. + "tvdpll_ck"
  1073. +};
  1074. +
  1075. +static const char * const venc_parents[] = {
  1076. + "clk26m",
  1077. + "univpll1_d2",
  1078. + "mmpll_d2",
  1079. + "tvdpll_d2",
  1080. + "syspll1_d2",
  1081. + "univpll_d5",
  1082. + "vcodecpll_d2",
  1083. + "univpll2_d2",
  1084. + "syspll3_d2"
  1085. +};
  1086. +
  1087. +static const char * const mfg_parents[] = {
  1088. + "clk26m",
  1089. + "mmpll_ck",
  1090. + "univpll_d3",
  1091. + "clk26m",
  1092. + "clk26m",
  1093. + "clk26m",
  1094. + "clk26m",
  1095. + "clk26m",
  1096. + "clk26m",
  1097. + "syspll_d3",
  1098. + "syspll1_d2",
  1099. + "syspll_d5",
  1100. + "univpll_d3",
  1101. + "univpll1_d2",
  1102. + "univpll_d5",
  1103. + "univpll2_d2"
  1104. +};
  1105. +
  1106. +static const char * const camtg_parents[] = {
  1107. + "clk26m",
  1108. + "univpll_d52",
  1109. + "univpll_d208",
  1110. + "univpll_d104",
  1111. + "clk26m_d2",
  1112. + "univpll_d26",
  1113. + "univpll2_d8",
  1114. + "syspll3_d4",
  1115. + "syspll3_d2",
  1116. + "univpll1_d4",
  1117. + "univpll2_d2"
  1118. +};
  1119. +
  1120. +static const char * const uart_parents[] = {
  1121. + "clk26m",
  1122. + "univpll2_d8"
  1123. +};
  1124. +
  1125. +static const char * const spi_parents[] = {
  1126. + "clk26m",
  1127. + "univpll2_d4",
  1128. + "univpll1_d4",
  1129. + "univpll2_d2",
  1130. + "univpll3_d2",
  1131. + "univpll1_d8"
  1132. +};
  1133. +
  1134. +static const char * const usb20_parents[] = {
  1135. + "clk26m",
  1136. + "univpll1_d8",
  1137. + "univpll3_d4"
  1138. +};
  1139. +
  1140. +static const char * const usb30_parents[] = {
  1141. + "clk26m",
  1142. + "univpll3_d2",
  1143. + "univpll3_d4",
  1144. + "univpll2_d4"
  1145. +};
  1146. +
  1147. +static const char * const msdc50_0_h_parents[] = {
  1148. + "clk26m",
  1149. + "syspll1_d2",
  1150. + "syspll2_d2",
  1151. + "syspll4_d2",
  1152. + "univpll_d5",
  1153. + "univpll1_d4"
  1154. +};
  1155. +
  1156. +static const char * const msdc50_0_parents[] = {
  1157. + "clk26m",
  1158. + "msdcpll_ck",
  1159. + "msdcpll_d2",
  1160. + "univpll1_d4",
  1161. + "syspll2_d2",
  1162. + "msdcpll_d4",
  1163. + "vencpll_d2",
  1164. + "univpll1_d2",
  1165. + "msdcpll2_ck",
  1166. + "msdcpll2_d2",
  1167. + "msdcpll2_d4"
  1168. +};
  1169. +
  1170. +static const char * const msdc30_1_parents[] = {
  1171. + "clk26m",
  1172. + "univpll2_d2",
  1173. + "msdcpll_d2",
  1174. + "univpll1_d4",
  1175. + "syspll2_d2",
  1176. + "univpll_d7",
  1177. + "vencpll_d2"
  1178. +};
  1179. +
  1180. +static const char * const msdc30_3_parents[] = {
  1181. + "clk26m",
  1182. + "msdcpll2_ck",
  1183. + "msdcpll2_d2",
  1184. + "univpll2_d2",
  1185. + "msdcpll2_d4",
  1186. + "univpll1_d4",
  1187. + "syspll2_d2",
  1188. + "syspll_d7",
  1189. + "univpll_d7",
  1190. + "vencpll_d2",
  1191. + "msdcpll_ck",
  1192. + "msdcpll_d2",
  1193. + "msdcpll_d4"
  1194. +};
  1195. +
  1196. +static const char * const audio_parents[] = {
  1197. + "clk26m",
  1198. + "syspll3_d4",
  1199. + "syspll4_d4",
  1200. + "syspll1_d16"
  1201. +};
  1202. +
  1203. +static const char * const aud_intbus_parents[] = {
  1204. + "clk26m",
  1205. + "syspll1_d4",
  1206. + "syspll4_d2",
  1207. + "univpll3_d2",
  1208. + "univpll2_d8",
  1209. + "syspll3_d2",
  1210. + "syspll3_d4"
  1211. +};
  1212. +
  1213. +static const char * const pmicspi_parents[] = {
  1214. + "clk26m",
  1215. + "syspll1_d8",
  1216. + "syspll3_d4",
  1217. + "syspll1_d16",
  1218. + "univpll3_d4",
  1219. + "univpll_d26",
  1220. + "syspll3_d4"
  1221. +};
  1222. +
  1223. +static const char * const dpilvds1_parents[] = {
  1224. + "clk26m",
  1225. + "lvdspll2_ck",
  1226. + "lvdspll2_d2",
  1227. + "lvdspll2_d4",
  1228. + "lvdspll2_d8",
  1229. + "clkfpc"
  1230. +};
  1231. +
  1232. +static const char * const atb_parents[] = {
  1233. + "clk26m",
  1234. + "syspll1_d2",
  1235. + "univpll_d5",
  1236. + "syspll_d5"
  1237. +};
  1238. +
  1239. +static const char * const nr_parents[] = {
  1240. + "clk26m",
  1241. + "univpll1_d4",
  1242. + "syspll2_d2",
  1243. + "syspll1_d4",
  1244. + "univpll1_d8",
  1245. + "univpll3_d2",
  1246. + "univpll2_d2",
  1247. + "syspll_d5"
  1248. +};
  1249. +
  1250. +static const char * const nfi2x_parents[] = {
  1251. + "clk26m",
  1252. + "syspll4_d4",
  1253. + "univpll3_d4",
  1254. + "univpll1_d8",
  1255. + "syspll2_d4",
  1256. + "univpll3_d2",
  1257. + "syspll_d7",
  1258. + "syspll2_d2",
  1259. + "univpll2_d2",
  1260. + "syspll_d5",
  1261. + "syspll1_d2"
  1262. +};
  1263. +
  1264. +static const char * const irda_parents[] = {
  1265. + "clk26m",
  1266. + "univpll2_d4",
  1267. + "syspll2_d4",
  1268. + "univpll2_d8"
  1269. +};
  1270. +
  1271. +static const char * const cci400_parents[] = {
  1272. + "clk26m",
  1273. + "vencpll_ck",
  1274. + "armca35pll_600m",
  1275. + "armca35pll_400m",
  1276. + "univpll_d2",
  1277. + "syspll_d2",
  1278. + "msdcpll_ck",
  1279. + "univpll_d3"
  1280. +};
  1281. +
  1282. +static const char * const aud_1_parents[] = {
  1283. + "clk26m",
  1284. + "apll1_ck",
  1285. + "univpll2_d4",
  1286. + "univpll2_d8"
  1287. +};
  1288. +
  1289. +static const char * const aud_2_parents[] = {
  1290. + "clk26m",
  1291. + "apll2_ck",
  1292. + "univpll2_d4",
  1293. + "univpll2_d8"
  1294. +};
  1295. +
  1296. +static const char * const mem_mfg_parents[] = {
  1297. + "clk26m",
  1298. + "mmpll_ck",
  1299. + "univpll_d3"
  1300. +};
  1301. +
  1302. +static const char * const axi_mfg_parents[] = {
  1303. + "clk26m",
  1304. + "axi_sel",
  1305. + "univpll_d5"
  1306. +};
  1307. +
  1308. +static const char * const scam_parents[] = {
  1309. + "clk26m",
  1310. + "syspll3_d2",
  1311. + "univpll2_d4",
  1312. + "syspll2_d4"
  1313. +};
  1314. +
  1315. +static const char * const nfiecc_parents[] = {
  1316. + "clk26m",
  1317. + "nfi2x_sel",
  1318. + "syspll_d7",
  1319. + "syspll2_d2",
  1320. + "univpll2_d2",
  1321. + "univpll_d5",
  1322. + "syspll1_d2"
  1323. +};
  1324. +
  1325. +static const char * const pe2_mac_p0_parents[] = {
  1326. + "clk26m",
  1327. + "syspll1_d8",
  1328. + "syspll4_d2",
  1329. + "syspll2_d4",
  1330. + "univpll2_d4",
  1331. + "syspll3_d2"
  1332. +};
  1333. +
  1334. +static const char * const dpilvds_parents[] = {
  1335. + "clk26m",
  1336. + "lvdspll_ck",
  1337. + "lvdspll_d2",
  1338. + "lvdspll_d4",
  1339. + "lvdspll_d8",
  1340. + "clkfpc"
  1341. +};
  1342. +
  1343. +static const char * const hdcp_parents[] = {
  1344. + "clk26m",
  1345. + "syspll4_d2",
  1346. + "syspll3_d4",
  1347. + "univpll2_d4"
  1348. +};
  1349. +
  1350. +static const char * const hdcp_24m_parents[] = {
  1351. + "clk26m",
  1352. + "univpll_d26",
  1353. + "univpll_d52",
  1354. + "univpll2_d8"
  1355. +};
  1356. +
  1357. +static const char * const rtc_parents[] = {
  1358. + "clkrtc_int",
  1359. + "clkrtc_ext",
  1360. + "clk26m",
  1361. + "univpll3_d8"
  1362. +};
  1363. +
  1364. +static const char * const spinor_parents[] = {
  1365. + "clk26m",
  1366. + "clk26m_d2",
  1367. + "syspll4_d4",
  1368. + "univpll2_d8",
  1369. + "univpll3_d4",
  1370. + "syspll4_d2",
  1371. + "syspll2_d4",
  1372. + "univpll2_d4",
  1373. + "etherpll_125m",
  1374. + "syspll1_d4"
  1375. +};
  1376. +
  1377. +static const char * const apll_parents[] = {
  1378. + "clk26m",
  1379. + "apll1_ck",
  1380. + "apll1_d2",
  1381. + "apll1_d4",
  1382. + "apll1_d8",
  1383. + "apll1_d16",
  1384. + "apll2_ck",
  1385. + "apll2_d2",
  1386. + "apll2_d4",
  1387. + "apll2_d8",
  1388. + "apll2_d16",
  1389. + "clk26m",
  1390. + "clk26m"
  1391. +};
  1392. +
  1393. +static const char * const a1sys_hp_parents[] = {
  1394. + "clk26m",
  1395. + "apll1_ck",
  1396. + "apll1_d2",
  1397. + "apll1_d4",
  1398. + "apll1_d8"
  1399. +};
  1400. +
  1401. +static const char * const a2sys_hp_parents[] = {
  1402. + "clk26m",
  1403. + "apll2_ck",
  1404. + "apll2_d2",
  1405. + "apll2_d4",
  1406. + "apll2_d8"
  1407. +};
  1408. +
  1409. +static const char * const asm_l_parents[] = {
  1410. + "clk26m",
  1411. + "univpll2_d4",
  1412. + "univpll2_d2",
  1413. + "syspll_d5"
  1414. +};
  1415. +
  1416. +static const char * const i2so1_parents[] = {
  1417. + "clk26m",
  1418. + "apll1_ck",
  1419. + "apll2_ck"
  1420. +};
  1421. +
  1422. +static const char * const ether_125m_parents[] = {
  1423. + "clk26m",
  1424. + "etherpll_125m",
  1425. + "univpll3_d2"
  1426. +};
  1427. +
  1428. +static const char * const ether_50m_parents[] = {
  1429. + "clk26m",
  1430. + "etherpll_50m",
  1431. + "univpll_d26",
  1432. + "univpll3_d4"
  1433. +};
  1434. +
  1435. +static const char * const jpgdec_parents[] = {
  1436. + "clk26m",
  1437. + "univpll_d3",
  1438. + "tvdpll_429m",
  1439. + "vencpll_ck",
  1440. + "syspll_d3",
  1441. + "vcodecpll_ck",
  1442. + "univpll1_d2",
  1443. + "armca35pll_400m",
  1444. + "tvdpll_429m_d2",
  1445. + "tvdpll_429m_d4"
  1446. +};
  1447. +
  1448. +static const char * const spislv_parents[] = {
  1449. + "clk26m",
  1450. + "univpll2_d4",
  1451. + "univpll1_d4",
  1452. + "univpll2_d2",
  1453. + "univpll3_d2",
  1454. + "univpll1_d8",
  1455. + "univpll1_d2",
  1456. + "univpll_d5"
  1457. +};
  1458. +
  1459. +static const char * const ether_parents[] = {
  1460. + "clk26m",
  1461. + "etherpll_50m",
  1462. + "univpll_d26"
  1463. +};
  1464. +
  1465. +static const char * const di_parents[] = {
  1466. + "clk26m",
  1467. + "tvdpll_d2",
  1468. + "tvdpll_d4",
  1469. + "tvdpll_d8",
  1470. + "vencpll_ck",
  1471. + "vencpll_d2",
  1472. + "cvbs",
  1473. + "cvbs_d2"
  1474. +};
  1475. +
  1476. +static const char * const tvd_parents[] = {
  1477. + "clk26m",
  1478. + "cvbs_d2",
  1479. + "univpll2_d8"
  1480. +};
  1481. +
  1482. +static const char * const i2c_parents[] = {
  1483. + "clk26m",
  1484. + "univpll_d26",
  1485. + "univpll2_d4",
  1486. + "univpll3_d2",
  1487. + "univpll1_d4"
  1488. +};
  1489. +
  1490. +static const char * const msdc0p_aes_parents[] = {
  1491. + "clk26m",
  1492. + "msdcpll_ck",
  1493. + "univpll_d3",
  1494. + "vcodecpll_ck"
  1495. +};
  1496. +
  1497. +static const char * const cmsys_parents[] = {
  1498. + "clk26m",
  1499. + "univpll_d3",
  1500. + "syspll_d3",
  1501. + "syspll1_d2",
  1502. + "syspll2_d2"
  1503. +};
  1504. +
  1505. +static const char * const gcpu_parents[] = {
  1506. + "clk26m",
  1507. + "syspll_d3",
  1508. + "syspll1_d2",
  1509. + "univpll1_d2",
  1510. + "univpll_d5",
  1511. + "univpll3_d2",
  1512. + "univpll_d3"
  1513. +};
  1514. +
  1515. +static const char * const aud_apll1_parents[] = {
  1516. + "apll1",
  1517. + "clkaud_ext_i_1"
  1518. +};
  1519. +
  1520. +static const char * const aud_apll2_parents[] = {
  1521. + "apll2",
  1522. + "clkaud_ext_i_2"
  1523. +};
  1524. +
  1525. +static const char * const audull_vtx_parents[] = {
  1526. + "d2a_ulclk_6p5m",
  1527. + "clkaud_ext_i_0"
  1528. +};
  1529. +
  1530. +static struct mtk_composite top_muxes[] = {
  1531. + /* CLK_CFG_0 */
  1532. + MUX_GATE_FLAGS(CLK_TOP_AXI_SEL, "axi_sel", axi_parents, 0x040, 0, 3,
  1533. + 7, CLK_IS_CRITICAL),
  1534. + MUX_GATE_FLAGS(CLK_TOP_MEM_SEL, "mem_sel", mem_parents, 0x040, 8, 1,
  1535. + 15, CLK_IS_CRITICAL),
  1536. + MUX_GATE(CLK_TOP_MM_SEL, "mm_sel",
  1537. + mm_parents, 0x040, 24, 3, 31),
  1538. + /* CLK_CFG_1 */
  1539. + MUX_GATE(CLK_TOP_PWM_SEL, "pwm_sel",
  1540. + pwm_parents, 0x050, 0, 2, 7),
  1541. + MUX_GATE(CLK_TOP_VDEC_SEL, "vdec_sel",
  1542. + vdec_parents, 0x050, 8, 4, 15),
  1543. + MUX_GATE(CLK_TOP_VENC_SEL, "venc_sel",
  1544. + venc_parents, 0x050, 16, 4, 23),
  1545. + MUX_GATE(CLK_TOP_MFG_SEL, "mfg_sel",
  1546. + mfg_parents, 0x050, 24, 4, 31),
  1547. + /* CLK_CFG_2 */
  1548. + MUX_GATE(CLK_TOP_CAMTG_SEL, "camtg_sel",
  1549. + camtg_parents, 0x060, 0, 4, 7),
  1550. + MUX_GATE(CLK_TOP_UART_SEL, "uart_sel",
  1551. + uart_parents, 0x060, 8, 1, 15),
  1552. + MUX_GATE(CLK_TOP_SPI_SEL, "spi_sel",
  1553. + spi_parents, 0x060, 16, 3, 23),
  1554. + MUX_GATE(CLK_TOP_USB20_SEL, "usb20_sel",
  1555. + usb20_parents, 0x060, 24, 2, 31),
  1556. + /* CLK_CFG_3 */
  1557. + MUX_GATE(CLK_TOP_USB30_SEL, "usb30_sel",
  1558. + usb30_parents, 0x070, 0, 2, 7),
  1559. + MUX_GATE(CLK_TOP_MSDC50_0_HCLK_SEL, "msdc50_0_h_sel",
  1560. + msdc50_0_h_parents, 0x070, 8, 3, 15),
  1561. + MUX_GATE(CLK_TOP_MSDC50_0_SEL, "msdc50_0_sel",
  1562. + msdc50_0_parents, 0x070, 16, 4, 23),
  1563. + MUX_GATE(CLK_TOP_MSDC30_1_SEL, "msdc30_1_sel",
  1564. + msdc30_1_parents, 0x070, 24, 3, 31),
  1565. + /* CLK_CFG_4 */
  1566. + MUX_GATE(CLK_TOP_MSDC30_2_SEL, "msdc30_2_sel",
  1567. + msdc30_1_parents, 0x080, 0, 3, 7),
  1568. + MUX_GATE(CLK_TOP_MSDC30_3_SEL, "msdc30_3_sel",
  1569. + msdc30_3_parents, 0x080, 8, 4, 15),
  1570. + MUX_GATE(CLK_TOP_AUDIO_SEL, "audio_sel",
  1571. + audio_parents, 0x080, 16, 2, 23),
  1572. + MUX_GATE(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel",
  1573. + aud_intbus_parents, 0x080, 24, 3, 31),
  1574. + /* CLK_CFG_5 */
  1575. + MUX_GATE(CLK_TOP_PMICSPI_SEL, "pmicspi_sel",
  1576. + pmicspi_parents, 0x090, 0, 3, 7),
  1577. + MUX_GATE(CLK_TOP_DPILVDS1_SEL, "dpilvds1_sel",
  1578. + dpilvds1_parents, 0x090, 8, 3, 15),
  1579. + MUX_GATE(CLK_TOP_ATB_SEL, "atb_sel",
  1580. + atb_parents, 0x090, 16, 2, 23),
  1581. + MUX_GATE(CLK_TOP_NR_SEL, "nr_sel",
  1582. + nr_parents, 0x090, 24, 3, 31),
  1583. + /* CLK_CFG_6 */
  1584. + MUX_GATE(CLK_TOP_NFI2X_SEL, "nfi2x_sel",
  1585. + nfi2x_parents, 0x0a0, 0, 4, 7),
  1586. + MUX_GATE(CLK_TOP_IRDA_SEL, "irda_sel",
  1587. + irda_parents, 0x0a0, 8, 2, 15),
  1588. + MUX_GATE(CLK_TOP_CCI400_SEL, "cci400_sel",
  1589. + cci400_parents, 0x0a0, 16, 3, 23),
  1590. + MUX_GATE(CLK_TOP_AUD_1_SEL, "aud_1_sel",
  1591. + aud_1_parents, 0x0a0, 24, 2, 31),
  1592. + /* CLK_CFG_7 */
  1593. + MUX_GATE(CLK_TOP_AUD_2_SEL, "aud_2_sel",
  1594. + aud_2_parents, 0x0b0, 0, 2, 7),
  1595. + MUX_GATE(CLK_TOP_MEM_MFG_IN_AS_SEL, "mem_mfg_sel",
  1596. + mem_mfg_parents, 0x0b0, 8, 2, 15),
  1597. + MUX_GATE(CLK_TOP_AXI_MFG_IN_AS_SEL, "axi_mfg_sel",
  1598. + axi_mfg_parents, 0x0b0, 16, 2, 23),
  1599. + MUX_GATE(CLK_TOP_SCAM_SEL, "scam_sel",
  1600. + scam_parents, 0x0b0, 24, 2, 31),
  1601. + /* CLK_CFG_8 */
  1602. + MUX_GATE(CLK_TOP_NFIECC_SEL, "nfiecc_sel",
  1603. + nfiecc_parents, 0x0c0, 0, 3, 7),
  1604. + MUX_GATE(CLK_TOP_PE2_MAC_P0_SEL, "pe2_mac_p0_sel",
  1605. + pe2_mac_p0_parents, 0x0c0, 8, 3, 15),
  1606. + MUX_GATE(CLK_TOP_PE2_MAC_P1_SEL, "pe2_mac_p1_sel",
  1607. + pe2_mac_p0_parents, 0x0c0, 16, 3, 23),
  1608. + MUX_GATE(CLK_TOP_DPILVDS_SEL, "dpilvds_sel",
  1609. + dpilvds_parents, 0x0c0, 24, 3, 31),
  1610. + /* CLK_CFG_9 */
  1611. + MUX_GATE(CLK_TOP_MSDC50_3_HCLK_SEL, "msdc50_3_h_sel",
  1612. + msdc50_0_h_parents, 0x0d0, 0, 3, 7),
  1613. + MUX_GATE(CLK_TOP_HDCP_SEL, "hdcp_sel",
  1614. + hdcp_parents, 0x0d0, 8, 2, 15),
  1615. + MUX_GATE(CLK_TOP_HDCP_24M_SEL, "hdcp_24m_sel",
  1616. + hdcp_24m_parents, 0x0d0, 16, 2, 23),
  1617. + MUX_GATE_FLAGS(CLK_TOP_RTC_SEL, "rtc_sel", rtc_parents, 0x0d0, 24, 2,
  1618. + 31, CLK_IS_CRITICAL),
  1619. + /* CLK_CFG_10 */
  1620. + MUX_GATE(CLK_TOP_SPINOR_SEL, "spinor_sel",
  1621. + spinor_parents, 0x500, 0, 4, 7),
  1622. + MUX_GATE(CLK_TOP_APLL_SEL, "apll_sel",
  1623. + apll_parents, 0x500, 8, 4, 15),
  1624. + MUX_GATE(CLK_TOP_APLL2_SEL, "apll2_sel",
  1625. + apll_parents, 0x500, 16, 4, 23),
  1626. + MUX_GATE(CLK_TOP_A1SYS_HP_SEL, "a1sys_hp_sel",
  1627. + a1sys_hp_parents, 0x500, 24, 3, 31),
  1628. + /* CLK_CFG_11 */
  1629. + MUX_GATE(CLK_TOP_A2SYS_HP_SEL, "a2sys_hp_sel",
  1630. + a2sys_hp_parents, 0x510, 0, 3, 7),
  1631. + MUX_GATE(CLK_TOP_ASM_L_SEL, "asm_l_sel",
  1632. + asm_l_parents, 0x510, 8, 2, 15),
  1633. + MUX_GATE(CLK_TOP_ASM_M_SEL, "asm_m_sel",
  1634. + asm_l_parents, 0x510, 16, 2, 23),
  1635. + MUX_GATE(CLK_TOP_ASM_H_SEL, "asm_h_sel",
  1636. + asm_l_parents, 0x510, 24, 2, 31),
  1637. + /* CLK_CFG_12 */
  1638. + MUX_GATE(CLK_TOP_I2SO1_SEL, "i2so1_sel",
  1639. + i2so1_parents, 0x520, 0, 2, 7),
  1640. + MUX_GATE(CLK_TOP_I2SO2_SEL, "i2so2_sel",
  1641. + i2so1_parents, 0x520, 8, 2, 15),
  1642. + MUX_GATE(CLK_TOP_I2SO3_SEL, "i2so3_sel",
  1643. + i2so1_parents, 0x520, 16, 2, 23),
  1644. + MUX_GATE(CLK_TOP_TDMO0_SEL, "tdmo0_sel",
  1645. + i2so1_parents, 0x520, 24, 2, 31),
  1646. + /* CLK_CFG_13 */
  1647. + MUX_GATE(CLK_TOP_TDMO1_SEL, "tdmo1_sel",
  1648. + i2so1_parents, 0x530, 0, 2, 7),
  1649. + MUX_GATE(CLK_TOP_I2SI1_SEL, "i2si1_sel",
  1650. + i2so1_parents, 0x530, 8, 2, 15),
  1651. + MUX_GATE(CLK_TOP_I2SI2_SEL, "i2si2_sel",
  1652. + i2so1_parents, 0x530, 16, 2, 23),
  1653. + MUX_GATE(CLK_TOP_I2SI3_SEL, "i2si3_sel",
  1654. + i2so1_parents, 0x530, 24, 2, 31),
  1655. + /* CLK_CFG_14 */
  1656. + MUX_GATE(CLK_TOP_ETHER_125M_SEL, "ether_125m_sel",
  1657. + ether_125m_parents, 0x540, 0, 2, 7),
  1658. + MUX_GATE(CLK_TOP_ETHER_50M_SEL, "ether_50m_sel",
  1659. + ether_50m_parents, 0x540, 8, 2, 15),
  1660. + MUX_GATE(CLK_TOP_JPGDEC_SEL, "jpgdec_sel",
  1661. + jpgdec_parents, 0x540, 16, 4, 23),
  1662. + MUX_GATE(CLK_TOP_SPISLV_SEL, "spislv_sel",
  1663. + spislv_parents, 0x540, 24, 3, 31),
  1664. + /* CLK_CFG_15 */
  1665. + MUX_GATE(CLK_TOP_ETHER_50M_RMII_SEL, "ether_sel",
  1666. + ether_parents, 0x550, 0, 2, 7),
  1667. + MUX_GATE(CLK_TOP_CAM2TG_SEL, "cam2tg_sel",
  1668. + camtg_parents, 0x550, 8, 4, 15),
  1669. + MUX_GATE(CLK_TOP_DI_SEL, "di_sel",
  1670. + di_parents, 0x550, 16, 3, 23),
  1671. + MUX_GATE(CLK_TOP_TVD_SEL, "tvd_sel",
  1672. + tvd_parents, 0x550, 24, 2, 31),
  1673. + /* CLK_CFG_16 */
  1674. + MUX_GATE(CLK_TOP_I2C_SEL, "i2c_sel",
  1675. + i2c_parents, 0x560, 0, 3, 7),
  1676. + MUX_GATE(CLK_TOP_PWM_INFRA_SEL, "pwm_infra_sel",
  1677. + pwm_parents, 0x560, 8, 2, 15),
  1678. + MUX_GATE(CLK_TOP_MSDC0P_AES_SEL, "msdc0p_aes_sel",
  1679. + msdc0p_aes_parents, 0x560, 16, 2, 23),
  1680. + MUX_GATE(CLK_TOP_CMSYS_SEL, "cmsys_sel",
  1681. + cmsys_parents, 0x560, 24, 3, 31),
  1682. + /* CLK_CFG_17 */
  1683. + MUX_GATE(CLK_TOP_GCPU_SEL, "gcpu_sel",
  1684. + gcpu_parents, 0x570, 0, 3, 7),
  1685. + /* CLK_AUDDIV_4 */
  1686. + MUX(CLK_TOP_AUD_APLL1_SEL, "aud_apll1_sel",
  1687. + aud_apll1_parents, 0x134, 0, 1),
  1688. + MUX(CLK_TOP_AUD_APLL2_SEL, "aud_apll2_sel",
  1689. + aud_apll2_parents, 0x134, 1, 1),
  1690. + MUX(CLK_TOP_DA_AUDULL_VTX_6P5M_SEL, "audull_vtx_sel",
  1691. + audull_vtx_parents, 0x134, 31, 1),
  1692. +};
  1693. +
  1694. +static const char * const mcu_mp0_parents[] = {
  1695. + "clk26m",
  1696. + "armca35pll_ck",
  1697. + "f_mp0_pll1_ck",
  1698. + "f_mp0_pll2_ck"
  1699. +};
  1700. +
  1701. +static const char * const mcu_mp2_parents[] = {
  1702. + "clk26m",
  1703. + "armca72pll_ck",
  1704. + "f_big_pll1_ck",
  1705. + "f_big_pll2_ck"
  1706. +};
  1707. +
  1708. +static const char * const mcu_bus_parents[] = {
  1709. + "clk26m",
  1710. + "cci400_sel",
  1711. + "f_bus_pll1_ck",
  1712. + "f_bus_pll2_ck"
  1713. +};
  1714. +
  1715. +static struct mtk_composite mcu_muxes[] = {
  1716. + /* mp0_pll_divider_cfg */
  1717. + MUX_GATE_FLAGS(CLK_MCU_MP0_SEL, "mcu_mp0_sel", mcu_mp0_parents, 0x7A0,
  1718. + 9, 2, -1, CLK_IS_CRITICAL),
  1719. + /* mp2_pll_divider_cfg */
  1720. + MUX_GATE_FLAGS(CLK_MCU_MP2_SEL, "mcu_mp2_sel", mcu_mp2_parents, 0x7A8,
  1721. + 9, 2, -1, CLK_IS_CRITICAL),
  1722. + /* bus_pll_divider_cfg */
  1723. + MUX_GATE_FLAGS(CLK_MCU_BUS_SEL, "mcu_bus_sel", mcu_bus_parents, 0x7C0,
  1724. + 9, 2, -1, CLK_IS_CRITICAL),
  1725. +};
  1726. +
  1727. +static const struct mtk_clk_divider top_adj_divs[] = {
  1728. + DIV_ADJ(CLK_TOP_APLL_DIV0, "apll_div0", "i2so1_sel", 0x124, 0, 8),
  1729. + DIV_ADJ(CLK_TOP_APLL_DIV1, "apll_div1", "i2so2_sel", 0x124, 8, 8),
  1730. + DIV_ADJ(CLK_TOP_APLL_DIV2, "apll_div2", "i2so3_sel", 0x124, 16, 8),
  1731. + DIV_ADJ(CLK_TOP_APLL_DIV3, "apll_div3", "tdmo0_sel", 0x124, 24, 8),
  1732. + DIV_ADJ(CLK_TOP_APLL_DIV4, "apll_div4", "tdmo1_sel", 0x128, 0, 8),
  1733. + DIV_ADJ(CLK_TOP_APLL_DIV5, "apll_div5", "i2si1_sel", 0x128, 8, 8),
  1734. + DIV_ADJ(CLK_TOP_APLL_DIV6, "apll_div6", "i2si2_sel", 0x128, 16, 8),
  1735. + DIV_ADJ(CLK_TOP_APLL_DIV7, "apll_div7", "i2si3_sel", 0x128, 24, 8),
  1736. +};
  1737. +
  1738. +static const struct mtk_gate_regs top_cg_regs = {
  1739. + .set_ofs = 0x120,
  1740. + .clr_ofs = 0x120,
  1741. + .sta_ofs = 0x120,
  1742. +};
  1743. +
  1744. +#define GATE_TOP(_id, _name, _parent, _shift) { \
  1745. + .id = _id, \
  1746. + .name = _name, \
  1747. + .parent_name = _parent, \
  1748. + .regs = &top_cg_regs, \
  1749. + .shift = _shift, \
  1750. + .ops = &mtk_clk_gate_ops_no_setclr, \
  1751. + }
  1752. +
  1753. +static const struct mtk_gate top_clks[] = {
  1754. + GATE_TOP(CLK_TOP_APLL_DIV_PDN0, "apll_div_pdn0", "i2so1_sel", 0),
  1755. + GATE_TOP(CLK_TOP_APLL_DIV_PDN1, "apll_div_pdn1", "i2so2_sel", 1),
  1756. + GATE_TOP(CLK_TOP_APLL_DIV_PDN2, "apll_div_pdn2", "i2so3_sel", 2),
  1757. + GATE_TOP(CLK_TOP_APLL_DIV_PDN3, "apll_div_pdn3", "tdmo0_sel", 3),
  1758. + GATE_TOP(CLK_TOP_APLL_DIV_PDN4, "apll_div_pdn4", "tdmo1_sel", 4),
  1759. + GATE_TOP(CLK_TOP_APLL_DIV_PDN5, "apll_div_pdn5", "i2si1_sel", 5),
  1760. + GATE_TOP(CLK_TOP_APLL_DIV_PDN6, "apll_div_pdn6", "i2si2_sel", 6),
  1761. + GATE_TOP(CLK_TOP_APLL_DIV_PDN7, "apll_div_pdn7", "i2si3_sel", 7),
  1762. +};
  1763. +
  1764. +static const struct mtk_gate_regs infra_cg_regs = {
  1765. + .set_ofs = 0x40,
  1766. + .clr_ofs = 0x44,
  1767. + .sta_ofs = 0x40,
  1768. +};
  1769. +
  1770. +#define GATE_INFRA(_id, _name, _parent, _shift) { \
  1771. + .id = _id, \
  1772. + .name = _name, \
  1773. + .parent_name = _parent, \
  1774. + .regs = &infra_cg_regs, \
  1775. + .shift = _shift, \
  1776. + .ops = &mtk_clk_gate_ops_setclr, \
  1777. + }
  1778. +
  1779. +static const struct mtk_gate infra_clks[] = {
  1780. + GATE_INFRA(CLK_INFRA_DBGCLK, "infra_dbgclk", "axi_sel", 0),
  1781. + GATE_INFRA(CLK_INFRA_GCE, "infra_gce", "axi_sel", 6),
  1782. + GATE_INFRA(CLK_INFRA_M4U, "infra_m4u", "mem_sel", 8),
  1783. + GATE_INFRA(CLK_INFRA_KP, "infra_kp", "axi_sel", 16),
  1784. + GATE_INFRA(CLK_INFRA_AO_SPI0, "infra_ao_spi0", "spi_sel", 24),
  1785. + GATE_INFRA(CLK_INFRA_AO_SPI1, "infra_ao_spi1", "spislv_sel", 25),
  1786. + GATE_INFRA(CLK_INFRA_AO_UART5, "infra_ao_uart5", "axi_sel", 26),
  1787. +};
  1788. +
  1789. +static const struct mtk_gate_regs peri0_cg_regs = {
  1790. + .set_ofs = 0x8,
  1791. + .clr_ofs = 0x10,
  1792. + .sta_ofs = 0x18,
  1793. +};
  1794. +
  1795. +static const struct mtk_gate_regs peri1_cg_regs = {
  1796. + .set_ofs = 0xc,
  1797. + .clr_ofs = 0x14,
  1798. + .sta_ofs = 0x1c,
  1799. +};
  1800. +
  1801. +static const struct mtk_gate_regs peri2_cg_regs = {
  1802. + .set_ofs = 0x42c,
  1803. + .clr_ofs = 0x42c,
  1804. + .sta_ofs = 0x42c,
  1805. +};
  1806. +
  1807. +#define GATE_PERI0(_id, _name, _parent, _shift) { \
  1808. + .id = _id, \
  1809. + .name = _name, \
  1810. + .parent_name = _parent, \
  1811. + .regs = &peri0_cg_regs, \
  1812. + .shift = _shift, \
  1813. + .ops = &mtk_clk_gate_ops_setclr, \
  1814. + }
  1815. +
  1816. +#define GATE_PERI1(_id, _name, _parent, _shift) { \
  1817. + .id = _id, \
  1818. + .name = _name, \
  1819. + .parent_name = _parent, \
  1820. + .regs = &peri1_cg_regs, \
  1821. + .shift = _shift, \
  1822. + .ops = &mtk_clk_gate_ops_setclr, \
  1823. + }
  1824. +
  1825. +#define GATE_PERI2(_id, _name, _parent, _shift) { \
  1826. + .id = _id, \
  1827. + .name = _name, \
  1828. + .parent_name = _parent, \
  1829. + .regs = &peri2_cg_regs, \
  1830. + .shift = _shift, \
  1831. + .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  1832. + }
  1833. +
  1834. +static const struct mtk_gate peri_clks[] = {
  1835. + /* PERI0 */
  1836. + GATE_PERI0(CLK_PERI_NFI, "per_nfi",
  1837. + "axi_sel", 0),
  1838. + GATE_PERI0(CLK_PERI_THERM, "per_therm",
  1839. + "axi_sel", 1),
  1840. + GATE_PERI0(CLK_PERI_PWM0, "per_pwm0",
  1841. + "pwm_sel", 2),
  1842. + GATE_PERI0(CLK_PERI_PWM1, "per_pwm1",
  1843. + "pwm_sel", 3),
  1844. + GATE_PERI0(CLK_PERI_PWM2, "per_pwm2",
  1845. + "pwm_sel", 4),
  1846. + GATE_PERI0(CLK_PERI_PWM3, "per_pwm3",
  1847. + "pwm_sel", 5),
  1848. + GATE_PERI0(CLK_PERI_PWM4, "per_pwm4",
  1849. + "pwm_sel", 6),
  1850. + GATE_PERI0(CLK_PERI_PWM5, "per_pwm5",
  1851. + "pwm_sel", 7),
  1852. + GATE_PERI0(CLK_PERI_PWM6, "per_pwm6",
  1853. + "pwm_sel", 8),
  1854. + GATE_PERI0(CLK_PERI_PWM7, "per_pwm7",
  1855. + "pwm_sel", 9),
  1856. + GATE_PERI0(CLK_PERI_PWM, "per_pwm",
  1857. + "pwm_sel", 10),
  1858. + GATE_PERI0(CLK_PERI_AP_DMA, "per_ap_dma",
  1859. + "axi_sel", 13),
  1860. + GATE_PERI0(CLK_PERI_MSDC30_0, "per_msdc30_0",
  1861. + "msdc50_0_sel", 14),
  1862. + GATE_PERI0(CLK_PERI_MSDC30_1, "per_msdc30_1",
  1863. + "msdc30_1_sel", 15),
  1864. + GATE_PERI0(CLK_PERI_MSDC30_2, "per_msdc30_2",
  1865. + "msdc30_2_sel", 16),
  1866. + GATE_PERI0(CLK_PERI_MSDC30_3, "per_msdc30_3",
  1867. + "msdc30_3_sel", 17),
  1868. + GATE_PERI0(CLK_PERI_UART0, "per_uart0",
  1869. + "uart_sel", 20),
  1870. + GATE_PERI0(CLK_PERI_UART1, "per_uart1",
  1871. + "uart_sel", 21),
  1872. + GATE_PERI0(CLK_PERI_UART2, "per_uart2",
  1873. + "uart_sel", 22),
  1874. + GATE_PERI0(CLK_PERI_UART3, "per_uart3",
  1875. + "uart_sel", 23),
  1876. + GATE_PERI0(CLK_PERI_I2C0, "per_i2c0",
  1877. + "axi_sel", 24),
  1878. + GATE_PERI0(CLK_PERI_I2C1, "per_i2c1",
  1879. + "axi_sel", 25),
  1880. + GATE_PERI0(CLK_PERI_I2C2, "per_i2c2",
  1881. + "axi_sel", 26),
  1882. + GATE_PERI0(CLK_PERI_I2C3, "per_i2c3",
  1883. + "axi_sel", 27),
  1884. + GATE_PERI0(CLK_PERI_I2C4, "per_i2c4",
  1885. + "axi_sel", 28),
  1886. + GATE_PERI0(CLK_PERI_AUXADC, "per_auxadc",
  1887. + "ltepll_fs26m", 29),
  1888. + GATE_PERI0(CLK_PERI_SPI0, "per_spi0",
  1889. + "spi_sel", 30),
  1890. + /* PERI1 */
  1891. + GATE_PERI1(CLK_PERI_SPI, "per_spi",
  1892. + "spinor_sel", 1),
  1893. + GATE_PERI1(CLK_PERI_I2C5, "per_i2c5",
  1894. + "axi_sel", 3),
  1895. + GATE_PERI1(CLK_PERI_SPI2, "per_spi2",
  1896. + "spi_sel", 5),
  1897. + GATE_PERI1(CLK_PERI_SPI3, "per_spi3",
  1898. + "spi_sel", 6),
  1899. + GATE_PERI1(CLK_PERI_SPI5, "per_spi5",
  1900. + "spi_sel", 8),
  1901. + GATE_PERI1(CLK_PERI_UART4, "per_uart4",
  1902. + "uart_sel", 9),
  1903. + GATE_PERI1(CLK_PERI_SFLASH, "per_sflash",
  1904. + "uart_sel", 11),
  1905. + GATE_PERI1(CLK_PERI_GMAC, "per_gmac",
  1906. + "uart_sel", 12),
  1907. + GATE_PERI1(CLK_PERI_PCIE0, "per_pcie0",
  1908. + "uart_sel", 14),
  1909. + GATE_PERI1(CLK_PERI_PCIE1, "per_pcie1",
  1910. + "uart_sel", 15),
  1911. + GATE_PERI1(CLK_PERI_GMAC_PCLK, "per_gmac_pclk",
  1912. + "uart_sel", 16),
  1913. + /* PERI2 */
  1914. + GATE_PERI2(CLK_PERI_MSDC50_0_EN, "per_msdc50_0_en",
  1915. + "msdc50_0_sel", 0),
  1916. + GATE_PERI2(CLK_PERI_MSDC30_1_EN, "per_msdc30_1_en",
  1917. + "msdc30_1_sel", 1),
  1918. + GATE_PERI2(CLK_PERI_MSDC30_2_EN, "per_msdc30_2_en",
  1919. + "msdc30_2_sel", 2),
  1920. + GATE_PERI2(CLK_PERI_MSDC30_3_EN, "per_msdc30_3_en",
  1921. + "msdc30_3_sel", 3),
  1922. + GATE_PERI2(CLK_PERI_MSDC50_0_HCLK_EN, "per_msdc50_0_h",
  1923. + "msdc50_0_h_sel", 4),
  1924. + GATE_PERI2(CLK_PERI_MSDC50_3_HCLK_EN, "per_msdc50_3_h",
  1925. + "msdc50_3_h_sel", 5),
  1926. +};
  1927. +
  1928. +#define MT2712_PLL_FMAX (3000UL * MHZ)
  1929. +
  1930. +#define CON0_MT2712_RST_BAR BIT(24)
  1931. +
  1932. +#define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  1933. + _pd_reg, _pd_shift, _tuner_reg, _tuner_en_reg, \
  1934. + _tuner_en_bit, _pcw_reg, _pcw_shift, \
  1935. + _div_table) { \
  1936. + .id = _id, \
  1937. + .name = _name, \
  1938. + .reg = _reg, \
  1939. + .pwr_reg = _pwr_reg, \
  1940. + .en_mask = _en_mask, \
  1941. + .flags = _flags, \
  1942. + .rst_bar_mask = CON0_MT2712_RST_BAR, \
  1943. + .fmax = MT2712_PLL_FMAX, \
  1944. + .pcwbits = _pcwbits, \
  1945. + .pd_reg = _pd_reg, \
  1946. + .pd_shift = _pd_shift, \
  1947. + .tuner_reg = _tuner_reg, \
  1948. + .tuner_en_reg = _tuner_en_reg, \
  1949. + .tuner_en_bit = _tuner_en_bit, \
  1950. + .pcw_reg = _pcw_reg, \
  1951. + .pcw_shift = _pcw_shift, \
  1952. + .div_table = _div_table, \
  1953. + }
  1954. +
  1955. +#define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  1956. + _pd_reg, _pd_shift, _tuner_reg, _tuner_en_reg, \
  1957. + _tuner_en_bit, _pcw_reg, _pcw_shift) \
  1958. + PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
  1959. + _pcwbits, _pd_reg, _pd_shift, _tuner_reg, \
  1960. + _tuner_en_reg, _tuner_en_bit, _pcw_reg, \
  1961. + _pcw_shift, NULL)
  1962. +
  1963. +static const struct mtk_pll_div_table armca35pll_div_table[] = {
  1964. + { .div = 0, .freq = MT2712_PLL_FMAX },
  1965. + { .div = 1, .freq = 1202500000 },
  1966. + { .div = 2, .freq = 500500000 },
  1967. + { .div = 3, .freq = 315250000 },
  1968. + { .div = 4, .freq = 157625000 },
  1969. + { } /* sentinel */
  1970. +};
  1971. +
  1972. +static const struct mtk_pll_div_table armca72pll_div_table[] = {
  1973. + { .div = 0, .freq = MT2712_PLL_FMAX },
  1974. + { .div = 1, .freq = 994500000 },
  1975. + { .div = 2, .freq = 520000000 },
  1976. + { .div = 3, .freq = 315250000 },
  1977. + { .div = 4, .freq = 157625000 },
  1978. + { } /* sentinel */
  1979. +};
  1980. +
  1981. +static const struct mtk_pll_div_table mmpll_div_table[] = {
  1982. + { .div = 0, .freq = MT2712_PLL_FMAX },
  1983. + { .div = 1, .freq = 1001000000 },
  1984. + { .div = 2, .freq = 601250000 },
  1985. + { .div = 3, .freq = 250250000 },
  1986. + { .div = 4, .freq = 125125000 },
  1987. + { } /* sentinel */
  1988. +};
  1989. +
  1990. +static const struct mtk_pll_data plls[] = {
  1991. + PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0230, 0x023C, 0xf0000101,
  1992. + HAVE_RST_BAR, 31, 0x0230, 4, 0, 0, 0, 0x0234, 0),
  1993. + PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x0240, 0x024C, 0xfe000101,
  1994. + HAVE_RST_BAR, 31, 0x0240, 4, 0, 0, 0, 0x0244, 0),
  1995. + PLL(CLK_APMIXED_VCODECPLL, "vcodecpll", 0x0320, 0x032C, 0xc0000101,
  1996. + 0, 31, 0x0320, 4, 0, 0, 0, 0x0324, 0),
  1997. + PLL(CLK_APMIXED_VENCPLL, "vencpll", 0x0280, 0x028C, 0x00000101,
  1998. + 0, 31, 0x0280, 4, 0, 0, 0, 0x0284, 0),
  1999. + PLL(CLK_APMIXED_APLL1, "apll1", 0x0330, 0x0340, 0x00000101,
  2000. + 0, 31, 0x0330, 4, 0x0338, 0x0014, 0, 0x0334, 0),
  2001. + PLL(CLK_APMIXED_APLL2, "apll2", 0x0350, 0x0360, 0x00000101,
  2002. + 0, 31, 0x0350, 4, 0x0358, 0x0014, 1, 0x0354, 0),
  2003. + PLL(CLK_APMIXED_LVDSPLL, "lvdspll", 0x0370, 0x037c, 0x00000101,
  2004. + 0, 31, 0x0370, 4, 0, 0, 0, 0x0374, 0),
  2005. + PLL(CLK_APMIXED_LVDSPLL2, "lvdspll2", 0x0390, 0x039C, 0x00000101,
  2006. + 0, 31, 0x0390, 4, 0, 0, 0, 0x0394, 0),
  2007. + PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0270, 0x027C, 0x00000101,
  2008. + 0, 31, 0x0270, 4, 0, 0, 0, 0x0274, 0),
  2009. + PLL(CLK_APMIXED_MSDCPLL2, "msdcpll2", 0x0410, 0x041C, 0x00000101,
  2010. + 0, 31, 0x0410, 4, 0, 0, 0, 0x0414, 0),
  2011. + PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x0290, 0x029C, 0xc0000101,
  2012. + 0, 31, 0x0290, 4, 0, 0, 0, 0x0294, 0),
  2013. + PLL_B(CLK_APMIXED_MMPLL, "mmpll", 0x0250, 0x0260, 0x00000101,
  2014. + 0, 31, 0x0250, 4, 0, 0, 0, 0x0254, 0,
  2015. + mmpll_div_table),
  2016. + PLL_B(CLK_APMIXED_ARMCA35PLL, "armca35pll", 0x0100, 0x0110, 0xf0000101,
  2017. + HAVE_RST_BAR, 31, 0x0100, 4, 0, 0, 0, 0x0104, 0,
  2018. + armca35pll_div_table),
  2019. + PLL_B(CLK_APMIXED_ARMCA72PLL, "armca72pll", 0x0210, 0x0220, 0x00000101,
  2020. + 0, 31, 0x0210, 4, 0, 0, 0, 0x0214, 0,
  2021. + armca72pll_div_table),
  2022. + PLL(CLK_APMIXED_ETHERPLL, "etherpll", 0x0300, 0x030C, 0xc0000101,
  2023. + 0, 31, 0x0300, 4, 0, 0, 0, 0x0304, 0),
  2024. +};
  2025. +
  2026. +static int clk_mt2712_apmixed_probe(struct platform_device *pdev)
  2027. +{
  2028. + struct clk_onecell_data *clk_data;
  2029. + int r;
  2030. + struct device_node *node = pdev->dev.of_node;
  2031. +
  2032. + clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
  2033. +
  2034. + mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  2035. +
  2036. + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  2037. +
  2038. + if (r != 0)
  2039. + pr_err("%s(): could not register clock provider: %d\n",
  2040. + __func__, r);
  2041. +
  2042. + return r;
  2043. +}
  2044. +
  2045. +static struct clk_onecell_data *top_clk_data;
  2046. +
  2047. +static void clk_mt2712_top_init_early(struct device_node *node)
  2048. +{
  2049. + int r, i;
  2050. +
  2051. + if (!top_clk_data) {
  2052. + top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
  2053. +
  2054. + for (i = 0; i < CLK_TOP_NR_CLK; i++)
  2055. + top_clk_data->clks[i] = ERR_PTR(-EPROBE_DEFER);
  2056. + }
  2057. +
  2058. + mtk_clk_register_factors(top_early_divs, ARRAY_SIZE(top_early_divs),
  2059. + top_clk_data);
  2060. +
  2061. + r = of_clk_add_provider(node, of_clk_src_onecell_get, top_clk_data);
  2062. + if (r)
  2063. + pr_err("%s(): could not register clock provider: %d\n",
  2064. + __func__, r);
  2065. +}
  2066. +
  2067. +CLK_OF_DECLARE_DRIVER(mt2712_topckgen, "mediatek,mt2712-topckgen",
  2068. + clk_mt2712_top_init_early);
  2069. +
  2070. +static int clk_mt2712_top_probe(struct platform_device *pdev)
  2071. +{
  2072. + int r, i;
  2073. + struct device_node *node = pdev->dev.of_node;
  2074. + void __iomem *base;
  2075. + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2076. +
  2077. + base = devm_ioremap_resource(&pdev->dev, res);
  2078. + if (IS_ERR(base)) {
  2079. + pr_err("%s(): ioremap failed\n", __func__);
  2080. + return PTR_ERR(base);
  2081. + }
  2082. +
  2083. + if (!top_clk_data) {
  2084. + top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
  2085. + } else {
  2086. + for (i = 0; i < CLK_TOP_NR_CLK; i++) {
  2087. + if (top_clk_data->clks[i] == ERR_PTR(-EPROBE_DEFER))
  2088. + top_clk_data->clks[i] = ERR_PTR(-ENOENT);
  2089. + }
  2090. + }
  2091. +
  2092. + mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
  2093. + top_clk_data);
  2094. + mtk_clk_register_factors(top_early_divs, ARRAY_SIZE(top_early_divs),
  2095. + top_clk_data);
  2096. + mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), top_clk_data);
  2097. + mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base,
  2098. + &mt2712_clk_lock, top_clk_data);
  2099. + mtk_clk_register_dividers(top_adj_divs, ARRAY_SIZE(top_adj_divs), base,
  2100. + &mt2712_clk_lock, top_clk_data);
  2101. + mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
  2102. + top_clk_data);
  2103. +
  2104. + r = of_clk_add_provider(node, of_clk_src_onecell_get, top_clk_data);
  2105. +
  2106. + if (r != 0)
  2107. + pr_err("%s(): could not register clock provider: %d\n",
  2108. + __func__, r);
  2109. +
  2110. + return r;
  2111. +}
  2112. +
  2113. +static int clk_mt2712_infra_probe(struct platform_device *pdev)
  2114. +{
  2115. + struct clk_onecell_data *clk_data;
  2116. + int r;
  2117. + struct device_node *node = pdev->dev.of_node;
  2118. +
  2119. + clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
  2120. +
  2121. + mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
  2122. + clk_data);
  2123. +
  2124. + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  2125. +
  2126. + if (r != 0)
  2127. + pr_err("%s(): could not register clock provider: %d\n",
  2128. + __func__, r);
  2129. +
  2130. + mtk_register_reset_controller(node, 2, 0x30);
  2131. +
  2132. + return r;
  2133. +}
  2134. +
  2135. +static int clk_mt2712_peri_probe(struct platform_device *pdev)
  2136. +{
  2137. + struct clk_onecell_data *clk_data;
  2138. + int r;
  2139. + struct device_node *node = pdev->dev.of_node;
  2140. +
  2141. + clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);
  2142. +
  2143. + mtk_clk_register_gates(node, peri_clks, ARRAY_SIZE(peri_clks),
  2144. + clk_data);
  2145. +
  2146. + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  2147. +
  2148. + if (r != 0)
  2149. + pr_err("%s(): could not register clock provider: %d\n",
  2150. + __func__, r);
  2151. +
  2152. + mtk_register_reset_controller(node, 2, 0);
  2153. +
  2154. + return r;
  2155. +}
  2156. +
  2157. +static int clk_mt2712_mcu_probe(struct platform_device *pdev)
  2158. +{
  2159. + struct clk_onecell_data *clk_data;
  2160. + int r;
  2161. + struct device_node *node = pdev->dev.of_node;
  2162. + void __iomem *base;
  2163. + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2164. +
  2165. + base = devm_ioremap_resource(&pdev->dev, res);
  2166. + if (IS_ERR(base)) {
  2167. + pr_err("%s(): ioremap failed\n", __func__);
  2168. + return PTR_ERR(base);
  2169. + }
  2170. +
  2171. + clk_data = mtk_alloc_clk_data(CLK_MCU_NR_CLK);
  2172. +
  2173. + mtk_clk_register_composites(mcu_muxes, ARRAY_SIZE(mcu_muxes), base,
  2174. + &mt2712_clk_lock, clk_data);
  2175. +
  2176. + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  2177. +
  2178. + if (r != 0)
  2179. + pr_err("%s(): could not register clock provider: %d\n",
  2180. + __func__, r);
  2181. +
  2182. + return r;
  2183. +}
  2184. +
  2185. +static const struct of_device_id of_match_clk_mt2712[] = {
  2186. + {
  2187. + .compatible = "mediatek,mt2712-apmixedsys",
  2188. + .data = clk_mt2712_apmixed_probe,
  2189. + }, {
  2190. + .compatible = "mediatek,mt2712-topckgen",
  2191. + .data = clk_mt2712_top_probe,
  2192. + }, {
  2193. + .compatible = "mediatek,mt2712-infracfg",
  2194. + .data = clk_mt2712_infra_probe,
  2195. + }, {
  2196. + .compatible = "mediatek,mt2712-pericfg",
  2197. + .data = clk_mt2712_peri_probe,
  2198. + }, {
  2199. + .compatible = "mediatek,mt2712-mcucfg",
  2200. + .data = clk_mt2712_mcu_probe,
  2201. + }, {
  2202. + /* sentinel */
  2203. + }
  2204. +};
  2205. +
  2206. +static int clk_mt2712_probe(struct platform_device *pdev)
  2207. +{
  2208. + int (*clk_probe)(struct platform_device *);
  2209. + int r;
  2210. +
  2211. + clk_probe = of_device_get_match_data(&pdev->dev);
  2212. + if (!clk_probe)
  2213. + return -EINVAL;
  2214. +
  2215. + r = clk_probe(pdev);
  2216. + if (r != 0)
  2217. + dev_err(&pdev->dev,
  2218. + "could not register clock provider: %s: %d\n",
  2219. + pdev->name, r);
  2220. +
  2221. + return r;
  2222. +}
  2223. +
  2224. +static struct platform_driver clk_mt2712_drv = {
  2225. + .probe = clk_mt2712_probe,
  2226. + .driver = {
  2227. + .name = "clk-mt2712",
  2228. + .owner = THIS_MODULE,
  2229. + .of_match_table = of_match_clk_mt2712,
  2230. + },
  2231. +};
  2232. +
  2233. +static int __init clk_mt2712_init(void)
  2234. +{
  2235. + return platform_driver_register(&clk_mt2712_drv);
  2236. +}
  2237. +
  2238. +arch_initcall(clk_mt2712_init);
  2239. --- a/drivers/clk/mediatek/clk-mtk.h
  2240. +++ b/drivers/clk/mediatek/clk-mtk.h
  2241. @@ -207,6 +207,8 @@ struct mtk_pll_data {
  2242. uint32_t en_mask;
  2243. uint32_t pd_reg;
  2244. uint32_t tuner_reg;
  2245. + uint32_t tuner_en_reg;
  2246. + uint8_t tuner_en_bit;
  2247. int pd_shift;
  2248. unsigned int flags;
  2249. const struct clk_ops *ops;
  2250. --- a/drivers/clk/mediatek/clk-pll.c
  2251. +++ b/drivers/clk/mediatek/clk-pll.c
  2252. @@ -47,6 +47,7 @@ struct mtk_clk_pll {
  2253. void __iomem *pd_addr;
  2254. void __iomem *pwr_addr;
  2255. void __iomem *tuner_addr;
  2256. + void __iomem *tuner_en_addr;
  2257. void __iomem *pcw_addr;
  2258. const struct mtk_pll_data *data;
  2259. };
  2260. @@ -227,7 +228,10 @@ static int mtk_pll_prepare(struct clk_hw
  2261. r |= pll->data->en_mask;
  2262. writel(r, pll->base_addr + REG_CON0);
  2263. - if (pll->tuner_addr) {
  2264. + if (pll->tuner_en_addr) {
  2265. + r = readl(pll->tuner_en_addr) | BIT(pll->data->tuner_en_bit);
  2266. + writel(r, pll->tuner_en_addr);
  2267. + } else if (pll->tuner_addr) {
  2268. r = readl(pll->tuner_addr) | AUDPLL_TUNER_EN;
  2269. writel(r, pll->tuner_addr);
  2270. }
  2271. @@ -254,7 +258,10 @@ static void mtk_pll_unprepare(struct clk
  2272. writel(r, pll->base_addr + REG_CON0);
  2273. }
  2274. - if (pll->tuner_addr) {
  2275. + if (pll->tuner_en_addr) {
  2276. + r = readl(pll->tuner_en_addr) & ~BIT(pll->data->tuner_en_bit);
  2277. + writel(r, pll->tuner_en_addr);
  2278. + } else if (pll->tuner_addr) {
  2279. r = readl(pll->tuner_addr) & ~AUDPLL_TUNER_EN;
  2280. writel(r, pll->tuner_addr);
  2281. }
  2282. @@ -297,6 +304,8 @@ static struct clk *mtk_clk_register_pll(
  2283. pll->pcw_addr = base + data->pcw_reg;
  2284. if (data->tuner_reg)
  2285. pll->tuner_addr = base + data->tuner_reg;
  2286. + if (data->tuner_en_reg)
  2287. + pll->tuner_en_addr = base + data->tuner_en_reg;
  2288. pll->hw.init = &init;
  2289. pll->data = data;