clk-mt6735.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  1. /*
  2. * Copyright (c) 2014 MediaTek Inc.
  3. * Author: James Liao <jamesjj.liao@mediatek.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/slab.h>
  17. #include "clk-mtk-v1.h"
  18. #include "clk-pll-v1.h"
  19. #include "clk-gate-v1.h"
  20. #include "clk-mt6735-pll.h"
  21. #include <dt-bindings/clock/mt6735-clk.h>
  22. #if !defined(MT_CCF_DEBUG) || !defined(MT_CCF_BRINGUP)
  23. #define MT_CCF_DEBUG 0
  24. #define MT_CCF_BRINGUP 0
  25. #endif
  26. /*
  27. * platform clocks
  28. */
  29. /* ROOT */
  30. #define clk_null "clk_null"
  31. #define clk26m "clk26m"
  32. #define clk32k "clk32k"
  33. #define clkph_mck_o "clkph_mck_o"
  34. #define dpi_ck "dpi_ck"
  35. /* PLL */
  36. #define armpll "armpll"
  37. #define mainpll "mainpll"
  38. #define msdcpll "msdcpll"
  39. #define univpll "univpll"
  40. #define mmpll "mmpll"
  41. #define vencpll "vencpll"
  42. #define tvdpll "tvdpll"
  43. #define apll1 "apll1"
  44. #define apll2 "apll2"
  45. /* DIV */
  46. #define ad_apll1_ck "ad_apll1_ck"
  47. #define ad_sys_26m_ck "ad_sys_26m_ck"
  48. #define ad_sys_26m_d2 "ad_sys_26m_d2"
  49. #define dmpll_ck "dmpll_ck"
  50. #define dmpll_d2 "dmpll_d2"
  51. #define dmpll_d4 "dmpll_d4"
  52. #define dmpll_d8 "dmpll_d8"
  53. #define dpi_ck "dpi_ck"
  54. #define mmpll_ck "mmpll_ck"
  55. #define msdcpll_ck "msdcpll_ck"
  56. #define msdcpll_d16 "msdcpll_d16"
  57. #define msdcpll_d2 "msdcpll_d2"
  58. #define msdcpll_d4 "msdcpll_d4"
  59. #define msdcpll_d8 "msdcpll_d8"
  60. #define syspll_d2 "syspll_d2"
  61. #define syspll_d3 "syspll_d3"
  62. #define syspll_d5 "syspll_d5"
  63. #define syspll1_d16 "syspll1_d16"
  64. #define syspll1_d2 "syspll1_d2"
  65. #define syspll1_d4 "syspll1_d4"
  66. #define syspll1_d8 "syspll1_d8"
  67. #define syspll2_d2 "syspll2_d2"
  68. #define syspll2_d4 "syspll2_d4"
  69. #define syspll3_d2 "syspll3_d2"
  70. #define syspll3_d4 "syspll3_d4"
  71. #define syspll4_d2 "syspll4_d2"
  72. #define syspll4_d2_d8 "syspll4_d2_d8"
  73. #define syspll4_d4 "syspll4_d4"
  74. #define tvdpll_ck "tvdpll_ck"
  75. #define tvdpll_d2 "tvdpll_d2"
  76. #define tvdpll_d4 "tvdpll_d4"
  77. #define univpll_d2 "univpll_d2"
  78. #define univpll_d26 "univpll_d26"
  79. #define univpll_d3 "univpll_d3"
  80. #define univpll_d5 "univpll_d5"
  81. #define univpll1_d2 "univpll1_d2"
  82. #define univpll1_d4 "univpll1_d4"
  83. #define univpll1_d8 "univpll1_d8"
  84. #define univpll2_d2 "univpll2_d2"
  85. #define univpll2_d4 "univpll2_d4"
  86. #define univpll2_d8 "univpll2_d8"
  87. #define univpll3_d2 "univpll3_d2"
  88. #define univpll3_d4 "univpll3_d4"
  89. #define vencpll_ck "vencpll_ck"
  90. #define vencpll_d3 "vencpll_d3"
  91. #define whpll_audio_ck "whpll_audio_ck"
  92. /* TOP */
  93. #define axi_sel "axi_sel"
  94. #define mem_sel "mem_sel"
  95. #define ddrphycfg_sel "ddrphycfg_sel"
  96. #define mm_sel "mm_sel"
  97. #define pwm_sel "pwm_sel"
  98. #define vdec_sel "vdec_sel"
  99. #define mfg_sel "mfg_sel"
  100. #define camtg_sel "camtg_sel"
  101. #define uart_sel "uart_sel"
  102. #define spi_sel "spi_sel"
  103. #define usb20_sel "usb20_sel"
  104. #define msdc50_0_sel "msdc50_0_sel"
  105. #define msdc30_0_sel "msdc30_0_sel"
  106. #define msdc30_1_sel "msdc30_1_sel"
  107. #define msdc30_2_sel "msdc30_2_sel"
  108. #define msdc30_3_sel "msdc30_3_sel"
  109. #define audio_sel "audio_sel"
  110. #define aud_intbus_sel "aud_intbus_sel"
  111. #define pmicspi_sel "pmicspi_sel"
  112. #define scp_sel "scp_sel"
  113. #define atb_sel "atb_sel"
  114. #define dpi0_sel "dpi0_sel"
  115. #define scam_sel "scam_sel"
  116. #define mfg13m_sel "mfg13m_sel"
  117. #define aud_1_sel "aud_1_sel"
  118. #define aud_2_sel "aud_2_sel"
  119. #define irda_sel "irda_sel"
  120. #define irtx_sel "irtx_sel"
  121. #define disppwm_sel "disppwm_sel"
  122. /* INFRA */
  123. #define infra_dbgclk "infra_dbgclk"
  124. #define infra_gce "infra_gce"
  125. #define infra_trbg "infra_trbg"
  126. #define infra_cpum "infra_cpum"
  127. #define infra_devapc "infra_devapc"
  128. #define infra_audio "infra_audio"
  129. #define infra_gcpu "infra_gcpu"
  130. #define infra_l2csram "infra_l2csram"
  131. #define infra_m4u "infra_m4u"
  132. #define infra_cldma "infra_cldma"
  133. #define infra_connmcubus "infra_connmcubus"
  134. #define infra_kp "infra_kp"
  135. #define infra_apxgpt "infra_apxgpt"
  136. #define infra_sej "infra_sej"
  137. #define infra_ccif0ap "infra_ccif0ap"
  138. #define infra_ccif1ap "infra_ccif1ap"
  139. #define infra_pmicspi "infra_pmicspi"
  140. #define infra_pmicwrap "infra_pmicwrap"
  141. /* PERI */
  142. #define peri_disp_pwm "peri_disp_pwm"
  143. #define peri_therm "peri_therm"
  144. #define peri_pwm1 "peri_pwm1"
  145. #define peri_pwm2 "peri_pwm2"
  146. #define peri_pwm3 "peri_pwm3"
  147. #define peri_pwm4 "peri_pwm4"
  148. #define peri_pwm5 "peri_pwm5"
  149. #define peri_pwm6 "peri_pwm6"
  150. #define peri_pwm7 "peri_pwm7"
  151. #define peri_pwm "peri_pwm"
  152. #define peri_usb0 "peri_usb0"
  153. #define peri_irda "peri_irda"
  154. #define peri_apdma "peri_apdma"
  155. #define peri_msdc30_0 "peri_msdc30_0"
  156. #define peri_msdc30_1 "peri_msdc30_1"
  157. #define peri_msdc30_2 "peri_msdc30_2"
  158. #define peri_msdc30_3 "peri_msdc30_3"
  159. #define peri_uart0 "peri_uart0"
  160. #define peri_uart1 "peri_uart1"
  161. #define peri_uart2 "peri_uart2"
  162. #define peri_uart3 "peri_uart3"
  163. #define peri_uart4 "peri_uart4"
  164. #define peri_btif "peri_btif"
  165. #define peri_i2c0 "peri_i2c0"
  166. #define peri_i2c1 "peri_i2c1"
  167. #define peri_i2c2 "peri_i2c2"
  168. #define peri_i2c3 "peri_i2c3"
  169. #define peri_auxadc "peri_auxadc"
  170. #define peri_spi0 "peri_spi0"
  171. #define peri_irtx "peri_irtx"
  172. /* MFG */
  173. #define mfg_bg3d "mfg_bg3d"
  174. /* IMG */
  175. #define img_image_larb2_smi "img_image_larb2_smi"
  176. #define img_image_cam_smi "img_image_cam_smi"
  177. #define img_image_cam_cam "img_image_cam_cam"
  178. #define img_image_sen_tg "img_image_sen_tg"
  179. #define img_image_sen_cam "img_image_sen_cam"
  180. #define img_image_cam_sv "img_image_cam_sv"
  181. #define img_image_sufod "img_image_sufod"
  182. #define img_image_fd "img_image_fd"
  183. /* MM_SYS */
  184. #define mm_disp0_smi_common "mm_disp0_smi_common"
  185. #define mm_disp0_smi_larb0 "mm_disp0_smi_larb0"
  186. #define mm_disp0_cam_mdp "mm_disp0_cam_mdp"
  187. #define mm_disp0_mdp_rdma "mm_disp0_mdp_rdma"
  188. #define mm_disp0_mdp_rsz0 "mm_disp0_mdp_rsz0"
  189. #define mm_disp0_mdp_rsz1 "mm_disp0_mdp_rsz1"
  190. #define mm_disp0_mdp_tdshp "mm_disp0_mdp_tdshp"
  191. #define mm_disp0_mdp_wdma "mm_disp0_mdp_wdma"
  192. #define mm_disp0_mdp_wrot "mm_disp0_mdp_wrot"
  193. #define mm_disp0_fake_eng "mm_disp0_fake_eng"
  194. #define mm_disp0_disp_ovl0 "mm_disp0_disp_ovl0"
  195. #define mm_disp0_disp_rdma0 "mm_disp0_disp_rdma0"
  196. #define mm_disp0_disp_rdma1 "mm_disp0_disp_rdma1"
  197. #define mm_disp0_disp_wdma0 "mm_disp0_disp_wdma0"
  198. #define mm_disp0_disp_color "mm_disp0_disp_color"
  199. #define mm_disp0_disp_ccorr "mm_disp0_disp_ccorr"
  200. #define mm_disp0_disp_aal "mm_disp0_disp_aal"
  201. #define mm_disp0_disp_gamma "mm_disp0_disp_gamma"
  202. #define mm_disp0_disp_dither "mm_disp0_disp_dither"
  203. #define mm_disp1_dsi_engine "mm_disp1_dsi_engine"
  204. #define mm_disp1_dsi_digital "mm_disp1_dsi_digital"
  205. #define mm_disp1_dpi_engine "mm_disp1_dpi_engine"
  206. #define mm_disp1_dpi_pixel "mm_disp1_dpi_pixel"
  207. /* VDEC */
  208. #define vdec0_vdec "vdec0_vdec"
  209. #define vdec1_larb "vdec1_larb"
  210. /* VENC */
  211. #define venc_larb "venc_larb"
  212. #define venc_venc "venc_venc"
  213. #define venc_jpgenc "venc_jpgenc"
  214. #define venc_jpgdec "venc_jpgdec"
  215. /* AUDIO */
  216. #define audio_afe "audio_afe"
  217. #define audio_i2s "audio_i2s"
  218. #define audio_22m "audio_22m"
  219. #define audio_24m "audio_24m"
  220. #define audio_apll2_tuner "audio_apll2_tuner"
  221. #define audio_apll_tuner "audio_apll_tuner"
  222. #define audio_adc "audio_adc"
  223. #define audio_dac "audio_dac"
  224. #define audio_dac_predis "audio_dac_predis"
  225. #define audio_tml "audio_tml"
  226. struct mtk_fixed_factor {
  227. int id;
  228. const char *name;
  229. const char *parent_name;
  230. int mult;
  231. int div;
  232. };
  233. #define FACTOR(_id, _name, _parent, _mult, _div) { \
  234. .id = _id, \
  235. .name = _name, \
  236. .parent_name = _parent, \
  237. .mult = _mult, \
  238. .div = _div, \
  239. }
  240. static void __init init_factors(struct mtk_fixed_factor *clks, int num,
  241. struct clk_onecell_data *clk_data)
  242. {
  243. int i;
  244. struct clk *clk;
  245. for (i = 0; i < num; i++) {
  246. struct mtk_fixed_factor *ff = &clks[i];
  247. clk = clk_register_fixed_factor(NULL, ff->name, ff->parent_name,
  248. 0, ff->mult, ff->div);
  249. if (IS_ERR(clk)) {
  250. pr_err("Failed to register clk %s: %ld\n",
  251. ff->name, PTR_ERR(clk));
  252. continue;
  253. }
  254. if (clk_data)
  255. clk_data->clks[ff->id] = clk;
  256. #if MT_CCF_DEBUG
  257. pr_debug("[CCF] factor %3d: %s\n", i, ff->name);
  258. #endif /* MT_CCF_DEBUG */
  259. }
  260. }
  261. static struct mtk_fixed_factor root_clk_alias[] __initdata = {
  262. FACTOR(TOP_CLKPH_MCK_O, clkph_mck_o, clk_null, 1, 1),
  263. FACTOR(TOP_DPI_CK, dpi_ck, clk_null, 1, 1),
  264. };
  265. static void __init init_clk_root_alias(struct clk_onecell_data *clk_data)
  266. {
  267. init_factors(root_clk_alias, ARRAY_SIZE(root_clk_alias), clk_data);
  268. }
  269. static struct mtk_fixed_factor top_divs[] __initdata = {
  270. FACTOR(TOP_UNIVPLL_D2, univpll_d2, univpll, 1, 1),
  271. FACTOR(TOP_UNIVPLL_D3, univpll_d3, univpll, 1, 1),
  272. FACTOR(TOP_UNIVPLL1_D2, univpll1_d2, univpll, 1, 1),
  273. FACTOR(TOP_AD_APLL1_CK, ad_apll1_ck, apll1, 1, 1),
  274. FACTOR(TOP_AD_SYS_26M_CK, ad_sys_26m_ck, clk26m, 1, 1),
  275. FACTOR(TOP_AD_SYS_26M_D2, ad_sys_26m_d2, clk26m, 1, 1),
  276. FACTOR(TOP_DMPLL_CK, dmpll_ck, clkph_mck_o, 1, 1),
  277. FACTOR(TOP_DMPLL_D2, dmpll_d2, clkph_mck_o, 1, 1),
  278. FACTOR(TOP_DMPLL_D4, dmpll_d4, clkph_mck_o, 1, 1),
  279. FACTOR(TOP_DMPLL_D8, dmpll_d8, clkph_mck_o, 1, 1),
  280. FACTOR(TOP_MMPLL_CK, mmpll_ck, mmpll, 1, 1),
  281. FACTOR(TOP_MSDCPLL_CK, msdcpll_ck, msdcpll, 1, 1),
  282. FACTOR(TOP_MSDCPLL_D16, msdcpll_d16, msdcpll, 1, 1),
  283. FACTOR(TOP_MSDCPLL_D2, msdcpll_d2, msdcpll, 1, 1),
  284. FACTOR(TOP_MSDCPLL_D4, msdcpll_d4, msdcpll, 1, 1),
  285. FACTOR(TOP_MSDCPLL_D8, msdcpll_d8, msdcpll, 1, 1),
  286. FACTOR(TOP_SYSPLL_D2, syspll_d2, mainpll, 1, 1),
  287. FACTOR(TOP_SYSPLL_D3, syspll_d3, mainpll, 1, 1),
  288. FACTOR(TOP_SYSPLL_D5, syspll_d5, mainpll, 1, 1),
  289. FACTOR(TOP_SYSPLL1_D16, syspll1_d16, mainpll, 1, 1),
  290. FACTOR(TOP_SYSPLL1_D2, syspll1_d2, mainpll, 1, 1),
  291. FACTOR(TOP_SYSPLL1_D4, syspll1_d4, mainpll, 1, 1),
  292. FACTOR(TOP_SYSPLL1_D8, syspll1_d8, mainpll, 1, 1),
  293. FACTOR(TOP_SYSPLL2_D2, syspll2_d2, mainpll, 1, 1),
  294. FACTOR(TOP_SYSPLL2_D4, syspll2_d4, mainpll, 1, 1),
  295. FACTOR(TOP_SYSPLL3_D2, syspll3_d2, mainpll, 1, 1),
  296. FACTOR(TOP_SYSPLL3_D4, syspll3_d4, mainpll, 1, 1),
  297. FACTOR(TOP_SYSPLL4_D2, syspll4_d2, mainpll, 1, 1),
  298. FACTOR(TOP_SYSPLL4_D2_D8, syspll4_d2_d8, mainpll, 1, 1),
  299. FACTOR(TOP_SYSPLL4_D4, syspll4_d4, mainpll, 1, 1),
  300. FACTOR(TOP_TVDPLL_CK, tvdpll_ck, tvdpll, 1, 1),
  301. FACTOR(TOP_TVDPLL_D2, tvdpll_d2, tvdpll, 1, 1),
  302. FACTOR(TOP_TVDPLL_D4, tvdpll_d4, tvdpll, 1, 1),
  303. FACTOR(TOP_UNIVPLL_D26, univpll_d26, univpll, 1, 1),
  304. FACTOR(TOP_UNIVPLL_D5, univpll_d5, univpll, 1, 1),
  305. FACTOR(TOP_UNIVPLL1_D4, univpll1_d4, univpll, 1, 1),
  306. FACTOR(TOP_UNIVPLL1_D8, univpll1_d8, univpll, 1, 1),
  307. FACTOR(TOP_UNIVPLL2_D2, univpll2_d2, univpll, 1, 1),
  308. FACTOR(TOP_UNIVPLL2_D4, univpll2_d4, univpll, 1, 1),
  309. FACTOR(TOP_UNIVPLL2_D8, univpll2_d8, univpll, 1, 1),
  310. FACTOR(TOP_UNIVPLL3_D2, univpll3_d2, univpll, 1, 1),
  311. FACTOR(TOP_UNIVPLL3_D4, univpll3_d4, univpll, 1, 1),
  312. FACTOR(TOP_VENCPLL_CK, vencpll_ck, vencpll, 1, 1),
  313. FACTOR(TOP_VENCPLL_D3, vencpll_d3, vencpll, 1, 1),
  314. FACTOR(TOP_WHPLL_AUDIO_CK, whpll_audio_ck, clk_null, 1, 1),
  315. };
  316. static void __init init_clk_top_div(struct clk_onecell_data *clk_data)
  317. {
  318. init_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
  319. }
  320. static const char *axi_parents[] __initconst = {
  321. clk26m,
  322. syspll1_d2,
  323. syspll_d5,
  324. syspll1_d4,
  325. univpll_d5,
  326. univpll2_d2,
  327. dmpll_ck,
  328. dmpll_d2};
  329. static const char *mem_parents[] __initconst = {
  330. clk26m,
  331. dmpll_ck};
  332. static const char *ddrphycfg_parents[] __initconst = {
  333. clk26m,
  334. syspll1_d8};
  335. static const char *mm_parents[] __initconst = {
  336. clk26m,
  337. vencpll_ck,
  338. syspll1_d2,
  339. syspll_d5,
  340. syspll1_d4,
  341. univpll_d5,
  342. univpll2_d2,
  343. dmpll_ck};
  344. static const char *pwm_parents[] __initconst = {
  345. clk26m,
  346. univpll2_d4,
  347. univpll3_d2,
  348. univpll1_d4};
  349. static const char *vdec_parents[] __initconst = {
  350. clk26m,
  351. syspll1_d2,
  352. syspll_d5,
  353. syspll1_d4,
  354. univpll_d5,
  355. syspll_d2,
  356. syspll2_d2,
  357. msdcpll_d2};
  358. static const char *mfg_parents[] __initconst = {
  359. clk26m,
  360. mmpll_ck,
  361. clk26m,
  362. clk26m,
  363. clk26m,
  364. clk26m,
  365. clk26m,
  366. clk26m,
  367. clk26m,
  368. syspll_d3,
  369. syspll1_d2,
  370. syspll_d5,
  371. univpll_d3,
  372. univpll1_d2
  373. };
  374. static const char *camtg_parents[] __initconst = {
  375. clk26m,
  376. univpll_d26,
  377. univpll2_d2,
  378. syspll3_d2,
  379. syspll3_d4,
  380. msdcpll_d4
  381. };
  382. static const char *uart_parents[] __initconst = {
  383. clk26m,
  384. univpll2_d8
  385. };
  386. static const char *spi_parents[] __initconst = {
  387. clk26m,
  388. syspll3_d2,
  389. msdcpll_d8,
  390. syspll2_d4,
  391. syspll4_d2,
  392. univpll2_d4,
  393. univpll1_d8
  394. };
  395. static const char *usb20_parents[] __initconst = {
  396. clk26m,
  397. univpll1_d8,
  398. univpll3_d4
  399. };
  400. static const char *msdc50_0_parents[] __initconst = {
  401. clk26m,
  402. syspll1_d2,
  403. syspll2_d2,
  404. syspll4_d2,
  405. univpll_d5,
  406. univpll1_d4
  407. };
  408. static const char *msdc30_0_parents[] __initconst = {
  409. clk26m,
  410. msdcpll_ck,
  411. msdcpll_d2,
  412. msdcpll_d4,
  413. syspll2_d2,
  414. syspll1_d4,
  415. univpll1_d4,
  416. univpll_d3,
  417. univpll_d26,
  418. syspll2_d4,
  419. univpll_d2
  420. };
  421. static const char *msdc30_1_parents[] __initconst = {
  422. clk26m,
  423. univpll2_d2,
  424. msdcpll_d4,
  425. syspll2_d2,
  426. syspll1_d4,
  427. univpll1_d4,
  428. univpll_d26,
  429. syspll2_d4
  430. };
  431. static const char *msdc30_2_parents[] __initconst = {
  432. clk26m,
  433. univpll2_d2,
  434. msdcpll_d4,
  435. syspll2_d2,
  436. syspll1_d4,
  437. univpll1_d4,
  438. univpll_d26,
  439. syspll2_d4
  440. };
  441. static const char *msdc30_3_parents[] __initconst = {
  442. clk26m,
  443. univpll2_d2,
  444. msdcpll_d4,
  445. syspll2_d2,
  446. syspll1_d4,
  447. univpll1_d4,
  448. univpll_d26,
  449. msdcpll_d16,
  450. syspll2_d4
  451. };
  452. static const char *audio_parents[] __initconst = {
  453. clk26m,
  454. syspll3_d4,
  455. syspll4_d4,
  456. syspll1_d16
  457. };
  458. static const char *aud_intbus_parents[] __initconst = {
  459. clk26m,
  460. syspll1_d4,
  461. syspll4_d2,
  462. dmpll_d4
  463. };
  464. static const char *pmicspi_parents[] __initconst = {
  465. clk26m,
  466. syspll1_d8,
  467. syspll3_d4,
  468. syspll1_d16,
  469. univpll3_d4,
  470. univpll_d26,
  471. dmpll_d4,
  472. dmpll_d8
  473. };
  474. static const char *scp_parents[] __initconst = {
  475. clk26m,
  476. syspll1_d8,
  477. dmpll_d2,
  478. dmpll_d4
  479. };
  480. static const char *atb_parents[] __initconst = {
  481. clk26m,
  482. syspll1_d2,
  483. syspll_d5,
  484. dmpll_ck
  485. };
  486. static const char *dpi0_parents[] __initconst = {
  487. clk26m,
  488. tvdpll_ck,
  489. tvdpll_d2,
  490. tvdpll_d4,
  491. dpi_ck
  492. };
  493. static const char *scam_parents[] __initconst = {
  494. clk26m,
  495. syspll3_d2,
  496. univpll2_d4,
  497. vencpll_d3
  498. };
  499. static const char *mfg13m_parents[] __initconst = {
  500. clk26m,
  501. ad_sys_26m_d2
  502. };
  503. static const char *aud_1_parents[] __initconst = {
  504. clk26m,
  505. ad_apll1_ck
  506. };
  507. static const char *aud_2_parents[] __initconst = {
  508. clk26m,
  509. whpll_audio_ck
  510. };
  511. static const char *irda_parents[] __initconst = {
  512. clk26m,
  513. univpll2_d4
  514. };
  515. static const char *irtx_parents[] __initconst = {
  516. clk26m,
  517. ad_sys_26m_ck
  518. };
  519. static const char *disppwm_parents[] __initconst = {
  520. clk26m,
  521. univpll2_d4,
  522. syspll4_d2_d8,
  523. ad_sys_26m_ck
  524. };
  525. struct mtk_mux {
  526. int id;
  527. const char *name;
  528. uint32_t reg;
  529. int shift;
  530. int width;
  531. int gate;
  532. const char **parent_names;
  533. int num_parents;
  534. };
  535. #define MUX(_id, _name, _parents, _reg, _shift, _width, _gate) { \
  536. .id = _id, \
  537. .name = _name, \
  538. .reg = _reg, \
  539. .shift = _shift, \
  540. .width = _width, \
  541. .gate = _gate, \
  542. .parent_names = (const char **)_parents, \
  543. .num_parents = ARRAY_SIZE(_parents), \
  544. }
  545. static struct mtk_mux top_muxes[] __initdata = {
  546. MUX(TOP_MUX_AXI, axi_sel, axi_parents, 0x0040, 0, 3, INVALID_MUX_GATE_BIT),
  547. MUX(TOP_MUX_MEM, mem_sel, mem_parents, 0x0040, 8, 1, INVALID_MUX_GATE_BIT),
  548. MUX(TOP_MUX_DDRPHY, ddrphycfg_sel, ddrphycfg_parents, 0x0040, 16, 1, INVALID_MUX_GATE_BIT),
  549. MUX(TOP_MUX_MM, mm_sel, mm_parents, 0x0040, 24, 3, 31),
  550. MUX(TOP_MUX_PWM, pwm_sel, pwm_parents, 0x0050, 0, 2, 7),
  551. MUX(TOP_MUX_VDEC, vdec_sel, vdec_parents, 0x0050, 8, 3, 15),
  552. MUX(TOP_MUX_MFG, mfg_sel, mfg_parents, 0x0050, 16, 4, 23),
  553. MUX(TOP_MUX_CAMTG, camtg_sel, camtg_parents, 0x0050, 24, 3, 31),
  554. MUX(TOP_MUX_UART, uart_sel, uart_parents, 0x0060, 0, 1, 7),
  555. MUX(TOP_MUX_SPI, spi_sel, spi_parents, 0x0060, 8, 3, 15),
  556. MUX(TOP_MUX_USB20, usb20_sel, usb20_parents, 0x0060, 16, 2, 23),
  557. MUX(TOP_MUX_MSDC50_0, msdc50_0_sel, msdc50_0_parents, 0x0060, 24, 3, 31),
  558. MUX(TOP_MUX_MSDC30_0, msdc30_0_sel, msdc30_0_parents, 0x0070, 0, 4, 7),
  559. MUX(TOP_MUX_MSDC30_1, msdc30_1_sel, msdc30_1_parents, 0x0070, 8, 3, 15),
  560. MUX(TOP_MUX_MSDC30_2, msdc30_2_sel, msdc30_2_parents, 0x0070, 16, 3, 23),
  561. MUX(TOP_MUX_MSDC30_3, msdc30_3_sel, msdc30_3_parents, 0x0070, 24, 4, 31),
  562. MUX(TOP_MUX_AUDIO, audio_sel, audio_parents, 0x0080, 0, 2, 7),
  563. MUX(TOP_MUX_AUDINTBUS, aud_intbus_sel, aud_intbus_parents, 0x0080, 8, 2, 15),
  564. MUX(TOP_MUX_PMICSPI, pmicspi_sel, pmicspi_parents, 0x0080, 16, 3, INVALID_MUX_GATE_BIT),
  565. MUX(TOP_MUX_SCP, scp_sel, scp_parents, 0x0080, 24, 2, 31),
  566. MUX(TOP_MUX_ATB, atb_sel, atb_parents, 0x0090, 0, 2, 7),
  567. MUX(TOP_MUX_DPI0, dpi0_sel, dpi0_parents, 0x0090, 8, 3, 15),
  568. MUX(TOP_MUX_SCAM, scam_sel, scam_parents, 0x0090, 16, 2, 23),
  569. MUX(TOP_MUX_MFG13M, mfg13m_sel, mfg13m_parents, 0x0090, 24, 1, 31),
  570. MUX(TOP_MUX_AUD1, aud_1_sel, aud_1_parents, 0x00a0, 0, 1, 7),
  571. MUX(TOP_MUX_AUD2, aud_2_sel, aud_2_parents, 0x00a0, 8, 1, 15),
  572. MUX(TOP_MUX_IRDA, irda_sel, irda_parents, 0x00a0, 16, 1, 23),
  573. MUX(TOP_MUX_IRTX, irtx_sel, irtx_parents, 0x00a0, 24, 1, 31),
  574. MUX(TOP_MUX_DISPPWM, disppwm_sel, disppwm_parents, 0x00b0, 0, 2, 7),
  575. };
  576. static void __init init_clk_topckgen(void __iomem *top_base,
  577. struct clk_onecell_data *clk_data)
  578. {
  579. int i;
  580. struct clk *clk;
  581. for (i = 0; i < ARRAY_SIZE(top_muxes); i++) {
  582. struct mtk_mux *mux = &top_muxes[i];
  583. clk = mtk_clk_register_mux(mux->name,
  584. mux->parent_names, mux->num_parents,
  585. top_base + mux->reg, mux->shift, mux->width, mux->gate);
  586. if (IS_ERR(clk)) {
  587. pr_err("Failed to register clk %s: %ld\n",
  588. mux->name, PTR_ERR(clk));
  589. continue;
  590. }
  591. if (clk_data)
  592. clk_data->clks[mux->id] = clk;
  593. #if MT_CCF_DEBUG
  594. pr_debug("[CCF] mux %3d: %s\n", i, mux->name);
  595. #endif /* MT_CCF_DEBUG */
  596. }
  597. }
  598. struct mtk_pll {
  599. int id;
  600. const char *name;
  601. const char *parent_name;
  602. uint32_t reg;
  603. uint32_t pwr_reg;
  604. uint32_t en_mask;
  605. unsigned int flags;
  606. const struct clk_ops *ops;
  607. };
  608. #define PLL(_id, _name, _parent, _reg, _pwr_reg, _en_mask, _flags, _ops) { \
  609. .id = _id, \
  610. .name = _name, \
  611. .parent_name = _parent, \
  612. .reg = _reg, \
  613. .pwr_reg = _pwr_reg, \
  614. .en_mask = _en_mask, \
  615. .flags = _flags, \
  616. .ops = _ops, \
  617. }
  618. static struct mtk_pll plls[] __initdata = {
  619. PLL(APMIXED_ARMPLL, armpll, clk26m, 0x0200, 0x020C, 0x00000001, HAVE_PLL_HP, &mt_clk_arm_pll_ops),
  620. PLL(APMIXED_MAINPLL, mainpll, clk26m, 0x0210, 0x021C, 0xF0000101, HAVE_PLL_HP, &mt_clk_sdm_pll_ops),
  621. PLL(APMIXED_MSDCPLL, msdcpll, clk26m, 0x0240, 0x024C, 0x00000001, HAVE_PLL_HP, &mt_clk_sdm_pll_ops),
  622. PLL(APMIXED_UNIVPLL, univpll, clk26m, 0x0220, 0x022C, 0xFC000001, HAVE_PLL_HP, &mt_clk_univ_pll_ops),
  623. PLL(APMIXED_MMPLL, mmpll, clk26m, 0x0230, 0x023C, 0x00000001, HAVE_PLL_HP, &mt_clk_mm_pll_ops),
  624. PLL(APMIXED_VENCPLL, vencpll, clk26m, 0x0250, 0x025C, 0x00000001, HAVE_PLL_HP, &mt_clk_sdm_pll_ops),
  625. PLL(APMIXED_TVDPLL, tvdpll, clk26m, 0x0260, 0x026C, 0x00000001, HAVE_PLL_HP, &mt_clk_sdm_pll_ops),
  626. PLL(APMIXED_APLL1, apll1, clk26m, 0x0270, 0x0280, 0x00000001, HAVE_PLL_HP, &mt_clk_aud_pll_ops),
  627. PLL(APMIXED_APLL2, apll2, clk26m, 0x0284, 0x0294, 0x00000001, HAVE_PLL_HP, &mt_clk_aud_pll_ops),
  628. };
  629. static void __init init_clk_apmixedsys(void __iomem *apmixed_base,
  630. struct clk_onecell_data *clk_data)
  631. {
  632. int i;
  633. struct clk *clk;
  634. for (i = 0; i < ARRAY_SIZE(plls); i++) {
  635. struct mtk_pll *pll = &plls[i];
  636. clk = mtk_clk_register_pll(pll->name, pll->parent_name,
  637. apmixed_base + pll->reg,
  638. apmixed_base + pll->pwr_reg,
  639. pll->en_mask, pll->flags, pll->ops);
  640. if (IS_ERR(clk)) {
  641. pr_err("Failed to register clk %s: %ld\n",
  642. pll->name, PTR_ERR(clk));
  643. continue;
  644. }
  645. if (clk_data)
  646. clk_data->clks[pll->id] = clk;
  647. #if MT_CCF_DEBUG
  648. pr_debug("[CCF] pll %3d: %s\n", i, pll->name);
  649. #endif /* MT_CCF_DEBUG */
  650. }
  651. }
  652. struct mtk_gate_regs {
  653. u32 sta_ofs;
  654. u32 clr_ofs;
  655. u32 set_ofs;
  656. };
  657. struct mtk_gate {
  658. int id;
  659. const char *name;
  660. const char *parent_name;
  661. struct mtk_gate_regs *regs;
  662. int shift;
  663. uint32_t flags;
  664. };
  665. #define GATE(_id, _name, _parent, _regs, _shift, _flags) { \
  666. .id = _id, \
  667. .name = _name, \
  668. .parent_name = _parent, \
  669. .regs = &_regs, \
  670. .shift = _shift, \
  671. .flags = _flags, \
  672. }
  673. static void __init init_clk_gates(
  674. void __iomem *reg_base,
  675. struct mtk_gate *clks, int num,
  676. struct clk_onecell_data *clk_data)
  677. {
  678. int i;
  679. struct clk *clk;
  680. for (i = 0; i < num; i++) {
  681. struct mtk_gate *gate = &clks[i];
  682. clk = mtk_clk_register_gate(gate->name, gate->parent_name,
  683. reg_base + gate->regs->set_ofs,
  684. reg_base + gate->regs->clr_ofs,
  685. reg_base + gate->regs->sta_ofs,
  686. gate->shift, gate->flags);
  687. if (IS_ERR(clk)) {
  688. pr_err("Failed to register clk %s: %ld\n",
  689. gate->name, PTR_ERR(clk));
  690. continue;
  691. }
  692. if (clk_data)
  693. clk_data->clks[gate->id] = clk;
  694. #if MT_CCF_DEBUG
  695. pr_debug("[CCF] gate %3d: %s\n", i, gate->name);
  696. #endif /* MT_CCF_DEBUG */
  697. }
  698. }
  699. static struct mtk_gate_regs infra_cg_regs = {
  700. .set_ofs = 0x0040,
  701. .clr_ofs = 0x0044,
  702. .sta_ofs = 0x0048,
  703. };
  704. static struct mtk_gate infra_clks[] __initdata = {
  705. GATE(INFRA_DBGCLK, infra_dbgclk, axi_sel, infra_cg_regs, 0, 0),
  706. GATE(INFRA_GCE, infra_gce, axi_sel, infra_cg_regs, 1, 0),
  707. GATE(INFRA_TRBG, infra_trbg, axi_sel, infra_cg_regs, 2, 0),
  708. GATE(INFRA_CPUM, infra_cpum, axi_sel, infra_cg_regs, 3, 0),
  709. GATE(INFRA_DEVAPC, infra_devapc, axi_sel, infra_cg_regs, 4, 0),
  710. GATE(INFRA_AUDIO, infra_audio, aud_intbus_sel, infra_cg_regs, 5, 0),
  711. GATE(INFRA_GCPU, infra_gcpu, axi_sel, infra_cg_regs, 6, 0),
  712. GATE(INFRA_L2C_SRAM, infra_l2csram, axi_sel, infra_cg_regs, 7, 0),
  713. GATE(INFRA_M4U, infra_m4u, axi_sel, infra_cg_regs, 8, 0),
  714. GATE(INFRA_CLDMA, infra_cldma, axi_sel, infra_cg_regs, 12, 0),
  715. GATE(INFRA_CONNMCU_BUS, infra_connmcubus, axi_sel, infra_cg_regs, 15, 0),
  716. GATE(INFRA_KP, infra_kp, axi_sel, infra_cg_regs, 16, 0),
  717. GATE(INFRA_APXGPT, infra_apxgpt, axi_sel, infra_cg_regs, 18, 0),
  718. GATE(INFRA_SEJ, infra_sej, axi_sel, infra_cg_regs, 19, 0),
  719. GATE(INFRA_CCIF0_AP, infra_ccif0ap, axi_sel, infra_cg_regs, 20, 0),
  720. GATE(INFRA_CCIF1_AP, infra_ccif1ap, axi_sel, infra_cg_regs, 21, 0),
  721. GATE(INFRA_PMIC_SPI, infra_pmicspi, pmicspi_sel, infra_cg_regs, 22, 0),
  722. GATE(INFRA_PMIC_WRAP, infra_pmicwrap, axi_sel, infra_cg_regs, 23, 0),
  723. };
  724. static void __init init_clk_infrasys(void __iomem *infrasys_base,
  725. struct clk_onecell_data *clk_data)
  726. {
  727. pr_debug("[CCF] init infrasys gates:\n");
  728. init_clk_gates(infrasys_base, infra_clks, ARRAY_SIZE(infra_clks),
  729. clk_data);
  730. }
  731. static struct mtk_gate_regs peri0_cg_regs = {
  732. .set_ofs = 0x0008,
  733. .clr_ofs = 0x0010,
  734. .sta_ofs = 0x0018,
  735. };
  736. static struct mtk_gate peri_clks[] __initdata = {
  737. GATE(PERI_DISP_PWM, peri_disp_pwm, disppwm_sel, peri0_cg_regs, 0, 0),
  738. GATE(PERI_THERM, peri_therm, axi_sel, peri0_cg_regs, 1, 0),
  739. GATE(PERI_PWM1, peri_pwm1, axi_sel, peri0_cg_regs, 2, 0),
  740. GATE(PERI_PWM2, peri_pwm2, axi_sel, peri0_cg_regs, 3, 0),
  741. GATE(PERI_PWM3, peri_pwm3, axi_sel, peri0_cg_regs, 4, 0),
  742. GATE(PERI_PWM4, peri_pwm4, axi_sel, peri0_cg_regs, 5, 0),
  743. GATE(PERI_PWM5, peri_pwm5, axi_sel, peri0_cg_regs, 6, 0),
  744. GATE(PERI_PWM6, peri_pwm6, axi_sel, peri0_cg_regs, 7, 0),
  745. GATE(PERI_PWM7, peri_pwm7, axi_sel, peri0_cg_regs, 8, 0),
  746. GATE(PERI_PWM, peri_pwm, axi_sel, peri0_cg_regs, 9, 0),
  747. GATE(PERI_USB0, peri_usb0, usb20_sel, peri0_cg_regs, 10, 0),
  748. GATE(PERI_IRDA, peri_irda, irda_sel, peri0_cg_regs, 11, 0),
  749. GATE(PERI_APDMA, peri_apdma, axi_sel, peri0_cg_regs, 12, 0),
  750. GATE(PERI_MSDC30_0, peri_msdc30_0, msdc30_0_sel, peri0_cg_regs, 13, 0),
  751. GATE(PERI_MSDC30_1, peri_msdc30_1, msdc30_1_sel, peri0_cg_regs, 14, 0),
  752. GATE(PERI_MSDC30_2, peri_msdc30_2, msdc30_2_sel, peri0_cg_regs, 15, 0),
  753. GATE(PERI_MSDC30_3, peri_msdc30_3, msdc30_3_sel, peri0_cg_regs, 16, 0),
  754. GATE(PERI_UART0, peri_uart0, uart_sel, peri0_cg_regs, 17, 0),
  755. GATE(PERI_UART1, peri_uart1, uart_sel, peri0_cg_regs, 18, 0),
  756. GATE(PERI_UART2, peri_uart2, uart_sel, peri0_cg_regs, 19, 0),
  757. GATE(PERI_UART3, peri_uart3, uart_sel, peri0_cg_regs, 20, 0),
  758. GATE(PERI_UART4, peri_uart4, uart_sel, peri0_cg_regs, 21, 0),
  759. GATE(PERI_BTIF, peri_btif, axi_sel, peri0_cg_regs, 22, 0),
  760. GATE(PERI_I2C0, peri_i2c0, axi_sel, peri0_cg_regs, 23, 0),
  761. GATE(PERI_I2C1, peri_i2c1, axi_sel, peri0_cg_regs, 24, 0),
  762. GATE(PERI_I2C2, peri_i2c2, axi_sel, peri0_cg_regs, 25, 0),
  763. GATE(PERI_I2C3, peri_i2c3, axi_sel, peri0_cg_regs, 26, 0),
  764. GATE(PERI_AUXADC, peri_auxadc, axi_sel, peri0_cg_regs, 27, 0),
  765. GATE(PERI_SPI0, peri_spi0, spi_sel, peri0_cg_regs, 28, 0),
  766. GATE(PERI_IRTX, peri_irtx, irtx_sel, peri0_cg_regs, 29, 0),
  767. };
  768. static void __init init_clk_perisys(void __iomem *perisys_base,
  769. struct clk_onecell_data *clk_data)
  770. {
  771. pr_debug("[CCF] init perisys gates:\n");
  772. init_clk_gates(perisys_base, peri_clks, ARRAY_SIZE(peri_clks),
  773. clk_data);
  774. }
  775. static struct mtk_gate_regs mfg_cg_regs = {
  776. .set_ofs = 0x0004,
  777. .clr_ofs = 0x0008,
  778. .sta_ofs = 0x0000,
  779. };
  780. static struct mtk_gate mfg_clks[] __initdata = {
  781. GATE(MFG_BG3D, mfg_bg3d, mfg_sel, mfg_cg_regs, 0, 0),
  782. };
  783. static void __init init_clk_mfgsys(void __iomem *mfgsys_base,
  784. struct clk_onecell_data *clk_data)
  785. {
  786. pr_debug("[CCF] init mfgsys gates:\n");
  787. init_clk_gates(mfgsys_base, mfg_clks, ARRAY_SIZE(mfg_clks), clk_data);
  788. }
  789. static struct mtk_gate_regs img_cg_regs = {
  790. .set_ofs = 0x0004,
  791. .clr_ofs = 0x0008,
  792. .sta_ofs = 0x0000,
  793. };
  794. static struct mtk_gate img_clks[] __initdata = {
  795. GATE(IMG_IMAGE_LARB2_SMI, img_image_larb2_smi, mm_sel, img_cg_regs, 0, 0),
  796. GATE(IMG_IMAGE_CAM_SMI, img_image_cam_smi, mm_sel, img_cg_regs, 5, 0),
  797. GATE(IMG_IMAGE_CAM_CAM, img_image_cam_cam, mm_sel, img_cg_regs, 6, 0),
  798. GATE(IMG_IMAGE_SEN_TG, img_image_sen_tg, mm_sel, img_cg_regs, 7, 0),
  799. GATE(IMG_IMAGE_SEN_CAM, img_image_sen_cam, camtg_sel, img_cg_regs, 8, 0),
  800. GATE(IMG_IMAGE_CAM_SV, img_image_cam_sv, mm_sel, img_cg_regs, 9, 0),
  801. GATE(IMG_IMAGE_SUFOD, img_image_sufod, mm_sel, img_cg_regs, 10, 0),
  802. GATE(IMG_IMAGE_FD, img_image_fd, mm_sel, img_cg_regs, 11, 0),
  803. };
  804. static void __init init_clk_imgsys(void __iomem *imgsys_base,
  805. struct clk_onecell_data *clk_data)
  806. {
  807. pr_debug("[CCF] init imgsys gates:\n");
  808. init_clk_gates(imgsys_base, img_clks, ARRAY_SIZE(img_clks), clk_data);
  809. }
  810. static struct mtk_gate_regs mm0_cg_regs = {
  811. .set_ofs = 0x0104,
  812. .clr_ofs = 0x0108,
  813. .sta_ofs = 0x0100,
  814. };
  815. static struct mtk_gate_regs mm1_cg_regs = {
  816. .set_ofs = 0x0114,
  817. .clr_ofs = 0x0118,
  818. .sta_ofs = 0x0110,
  819. };
  820. static struct mtk_gate mm_clks[] __initdata = {
  821. /* MM0 */
  822. GATE(MM_DISP0_SMI_COMMON, mm_disp0_smi_common, mm_sel, mm0_cg_regs, 0, 0),
  823. GATE(MM_DISP0_SMI_LARB0, mm_disp0_smi_larb0, mm_sel, mm0_cg_regs, 1, 0),
  824. GATE(MM_DISP0_CAM_MDP, mm_disp0_cam_mdp, mm_sel, mm0_cg_regs, 2, 0),
  825. GATE(MM_DISP0_MDP_RDMA, mm_disp0_mdp_rdma, mm_sel, mm0_cg_regs, 3, 0),
  826. GATE(MM_DISP0_MDP_RSZ0, mm_disp0_mdp_rsz0, mm_sel, mm0_cg_regs, 4, 0),
  827. GATE(MM_DISP0_MDP_RSZ1, mm_disp0_mdp_rsz1, mm_sel, mm0_cg_regs, 5, 0),
  828. GATE(MM_DISP0_MDP_TDSHP, mm_disp0_mdp_tdshp, mm_sel, mm0_cg_regs, 6, 0),
  829. GATE(MM_DISP0_MDP_WDMA, mm_disp0_mdp_wdma, mm_sel, mm0_cg_regs, 7, 0),
  830. GATE(MM_DISP0_MDP_WROT, mm_disp0_mdp_wrot, mm_sel, mm0_cg_regs, 8, 0),
  831. GATE(MM_DISP0_FAKE_ENG, mm_disp0_fake_eng, mm_sel, mm0_cg_regs, 9, 0),
  832. GATE(MM_DISP0_DISP_OVL0, mm_disp0_disp_ovl0, mm_sel, mm0_cg_regs, 10, 0),
  833. GATE(MM_DISP0_DISP_RDMA0, mm_disp0_disp_rdma0, mm_sel, mm0_cg_regs, 11, 0),
  834. GATE(MM_DISP0_DISP_RDMA1, mm_disp0_disp_rdma1, mm_sel, mm0_cg_regs, 12, 0),
  835. GATE(MM_DISP0_DISP_WDMA0, mm_disp0_disp_wdma0, mm_sel, mm0_cg_regs, 13, 0),
  836. GATE(MM_DISP0_DISP_COLOR, mm_disp0_disp_color, mm_sel, mm0_cg_regs, 14, 0),
  837. GATE(MM_DISP0_DISP_CCORR, mm_disp0_disp_ccorr, mm_sel, mm0_cg_regs, 15, 0),
  838. GATE(MM_DISP0_DISP_AAL, mm_disp0_disp_aal, mm_sel, mm0_cg_regs, 16, 0),
  839. GATE(MM_DISP0_DISP_GAMMA, mm_disp0_disp_gamma, mm_sel, mm0_cg_regs, 17, 0),
  840. GATE(MM_DISP0_DISP_DITHER, mm_disp0_disp_dither, mm_sel, mm0_cg_regs, 18, 0),
  841. /* MM1 */
  842. GATE(MM_DISP1_DSI_ENGINE, mm_disp1_dsi_engine, mm_sel, mm1_cg_regs, 2, 0),
  843. GATE(MM_DISP1_DSI_DIGITAL, mm_disp1_dsi_digital, mm_sel, mm1_cg_regs, 3, 0),
  844. GATE(MM_DISP1_DPI_ENGINE, mm_disp1_dpi_engine, mm_sel, mm1_cg_regs, 4, 0),
  845. GATE(MM_DISP1_DPI_PIXEL, mm_disp1_dpi_pixel, dpi0_sel, mm1_cg_regs, 5, 0),
  846. };
  847. static void __init init_clk_mmsys(void __iomem *mmsys_base,
  848. struct clk_onecell_data *clk_data)
  849. {
  850. pr_debug("[CCF] init mmsys gates:\n");
  851. init_clk_gates(mmsys_base, mm_clks, ARRAY_SIZE(mm_clks),
  852. clk_data);
  853. }
  854. static struct mtk_gate_regs vdec0_cg_regs = {
  855. .set_ofs = 0x0000,
  856. .clr_ofs = 0x0004,
  857. .sta_ofs = 0x0000,
  858. };
  859. static struct mtk_gate_regs vdec1_cg_regs = {
  860. .set_ofs = 0x0008,
  861. .clr_ofs = 0x000c,
  862. .sta_ofs = 0x0008,
  863. };
  864. static struct mtk_gate vdec_clks[] __initdata = {
  865. GATE(VDEC0_VDEC, vdec0_vdec, vdec_sel, vdec0_cg_regs, 0, CLK_GATE_INVERSE),
  866. GATE(VDEC1_LARB, vdec1_larb, vdec_sel, vdec1_cg_regs, 0, CLK_GATE_INVERSE),
  867. };
  868. static void __init init_clk_vdecsys(void __iomem *vdecsys_base,
  869. struct clk_onecell_data *clk_data)
  870. {
  871. pr_debug("[CCF] init vdecsys gates:\n");
  872. init_clk_gates(vdecsys_base, vdec_clks, ARRAY_SIZE(vdec_clks),
  873. clk_data);
  874. }
  875. static struct mtk_gate_regs venc_cg_regs = {
  876. .set_ofs = 0x0004,
  877. .clr_ofs = 0x0008,
  878. .sta_ofs = 0x0000,
  879. };
  880. static struct mtk_gate venc_clks[] __initdata = {
  881. GATE(VENC_LARB, venc_larb, mm_sel, venc_cg_regs, 0, CLK_GATE_INVERSE),
  882. GATE(VENC_VENC, venc_venc, mm_sel, venc_cg_regs, 4, CLK_GATE_INVERSE),
  883. GATE(VENC_JPGENC, venc_jpgenc, mm_sel, venc_cg_regs, 8, CLK_GATE_INVERSE),
  884. GATE(VENC_JPGDEC, venc_jpgdec, mm_sel, venc_cg_regs, 12, CLK_GATE_INVERSE),
  885. };
  886. static void __init init_clk_vencsys(void __iomem *vencsys_base,
  887. struct clk_onecell_data *clk_data)
  888. {
  889. pr_debug("[CCF] init vencsys gates:\n");
  890. init_clk_gates(vencsys_base, venc_clks, ARRAY_SIZE(venc_clks),
  891. clk_data);
  892. }
  893. static struct mtk_gate_regs aud_cg_regs = {
  894. .set_ofs = 0x0000,
  895. .clr_ofs = 0x0000,
  896. .sta_ofs = 0x0000,
  897. };
  898. static struct mtk_gate audio_clks[] __initdata = {
  899. GATE(AUDIO_AFE, audio_afe, aud_intbus_sel, aud_cg_regs, 2, CLK_GATE_NO_SETCLR_REG),
  900. GATE(AUDIO_I2S, audio_i2s, aud_intbus_sel, aud_cg_regs, 6, CLK_GATE_NO_SETCLR_REG),
  901. GATE(AUDIO_22M, audio_22m, aud_intbus_sel, aud_cg_regs, 8, CLK_GATE_NO_SETCLR_REG),
  902. GATE(AUDIO_24M, audio_24m, aud_intbus_sel, aud_cg_regs, 9, CLK_GATE_NO_SETCLR_REG),
  903. GATE(AUDIO_APLL2_TUNER, audio_apll2_tuner, aud_intbus_sel, aud_cg_regs, 18, CLK_GATE_NO_SETCLR_REG),
  904. GATE(AUDIO_APLL_TUNER, audio_apll_tuner, aud_intbus_sel, aud_cg_regs, 19, CLK_GATE_NO_SETCLR_REG),
  905. GATE(AUDIO_ADC, audio_adc, aud_intbus_sel, aud_cg_regs, 24, CLK_GATE_NO_SETCLR_REG),
  906. GATE(AUDIO_DAC, audio_dac, aud_intbus_sel, aud_cg_regs, 25, CLK_GATE_NO_SETCLR_REG),
  907. GATE(AUDIO_DAC_PREDIS, audio_dac_predis, aud_intbus_sel, aud_cg_regs, 26, CLK_GATE_NO_SETCLR_REG),
  908. GATE(AUDIO_TML, audio_tml, aud_intbus_sel, aud_cg_regs, 27, CLK_GATE_NO_SETCLR_REG),
  909. };
  910. static void __init init_clk_audiosys(void __iomem *audiosys_base,
  911. struct clk_onecell_data *clk_data)
  912. {
  913. pr_debug("[CCF] init audiosys gates:\n");
  914. init_clk_gates(audiosys_base, audio_clks, ARRAY_SIZE(audio_clks),
  915. clk_data);
  916. }
  917. /*
  918. * device tree support
  919. */
  920. static struct clk_onecell_data *alloc_clk_data(unsigned int clk_num)
  921. {
  922. int i;
  923. struct clk_onecell_data *clk_data;
  924. clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
  925. if (!clk_data)
  926. return NULL;
  927. clk_data->clks = kcalloc(clk_num, sizeof(struct clk *), GFP_KERNEL);
  928. if (!clk_data->clks) {
  929. kfree(clk_data);
  930. return NULL;
  931. }
  932. clk_data->clk_num = clk_num;
  933. for (i = 0; i < clk_num; ++i)
  934. clk_data->clks[i] = ERR_PTR(-ENOENT);
  935. return clk_data;
  936. }
  937. static void __iomem *get_reg(struct device_node *np, int index)
  938. {
  939. #if DUMMY_REG_TEST
  940. return kzalloc(PAGE_SIZE, GFP_KERNEL);
  941. #else
  942. return of_iomap(np, index);
  943. #endif
  944. }
  945. static void __init mt_topckgen_init(struct device_node *node)
  946. {
  947. struct clk_onecell_data *clk_data;
  948. void __iomem *base;
  949. int r;
  950. pr_debug("[CCF] %s: %s\n", __func__, node->name);
  951. base = get_reg(node, 0);
  952. if (!base) {
  953. pr_err("ioremap topckgen failed\n");
  954. return;
  955. }
  956. clk_data = alloc_clk_data(TOP_NR_CLK);
  957. init_clk_root_alias(clk_data);
  958. init_clk_top_div(clk_data);
  959. init_clk_topckgen(base, clk_data);
  960. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  961. if (r)
  962. pr_err("could not register clock provide\n");
  963. }
  964. CLK_OF_DECLARE(mtk_topckgen, "mediatek,mt6735-topckgen", mt_topckgen_init);
  965. static void __init mt_apmixedsys_init(struct device_node *node)
  966. {
  967. struct clk_onecell_data *clk_data;
  968. void __iomem *base;
  969. int r;
  970. pr_debug("[CCF] %s: %s\n", __func__, node->name);
  971. base = get_reg(node, 0);
  972. if (!base) {
  973. pr_err("ioremap apmixedsys failed\n");
  974. return;
  975. }
  976. clk_data = alloc_clk_data(APMIXED_NR_CLK);
  977. init_clk_apmixedsys(base, clk_data);
  978. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  979. if (r)
  980. pr_err("could not register clock provide\n");
  981. }
  982. CLK_OF_DECLARE(mtk_apmixedsys, "mediatek,mt6735-apmixedsys",
  983. mt_apmixedsys_init);
  984. static void __init mt_infrasys_init(struct device_node *node)
  985. {
  986. struct clk_onecell_data *clk_data;
  987. void __iomem *base;
  988. int r;
  989. pr_debug("[CCF] %s: %s\n", __func__, node->name);
  990. base = get_reg(node, 0);
  991. if (!base) {
  992. pr_err("ioremap infrasys failed\n");
  993. return;
  994. }
  995. clk_data = alloc_clk_data(INFRA_NR_CLK);
  996. init_clk_infrasys(base, clk_data);
  997. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  998. if (r)
  999. pr_err("could not register clock provide\n");
  1000. }
  1001. CLK_OF_DECLARE(mtk_infrasys, "mediatek,mt6735-infrasys", mt_infrasys_init);
  1002. static void __init mt_perisys_init(struct device_node *node)
  1003. {
  1004. struct clk_onecell_data *clk_data;
  1005. void __iomem *base;
  1006. int r;
  1007. pr_debug("[CCF] %s: %s\n", __func__, node->name);
  1008. base = get_reg(node, 0);
  1009. if (!base) {
  1010. pr_err("ioremap perisys failed\n");
  1011. return;
  1012. }
  1013. clk_data = alloc_clk_data(PERI_NR_CLK);
  1014. init_clk_perisys(base, clk_data);
  1015. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  1016. if (r)
  1017. pr_err("could not register clock provide\n");
  1018. }
  1019. CLK_OF_DECLARE(mtk_perisys, "mediatek,mt6735-perisys", mt_perisys_init);
  1020. static void __init mt_mfgsys_init(struct device_node *node)
  1021. {
  1022. struct clk_onecell_data *clk_data;
  1023. void __iomem *base;
  1024. int r;
  1025. pr_debug("[CCF] %s: %s\n", __func__, node->name);
  1026. base = get_reg(node, 0);
  1027. if (!base) {
  1028. pr_err("ioremap mfgsys failed\n");
  1029. return;
  1030. }
  1031. clk_data = alloc_clk_data(MFG_NR_CLK);
  1032. init_clk_mfgsys(base, clk_data);
  1033. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  1034. if (r)
  1035. pr_err("could not register clock provide\n");
  1036. }
  1037. CLK_OF_DECLARE(mtk_mfgsys, "mediatek,mt6735-mfgsys", mt_mfgsys_init);
  1038. static void __init mt_imgsys_init(struct device_node *node)
  1039. {
  1040. struct clk_onecell_data *clk_data;
  1041. void __iomem *base;
  1042. int r;
  1043. pr_debug("[CCF] %s: %s\n", __func__, node->name);
  1044. base = get_reg(node, 0);
  1045. if (!base) {
  1046. pr_err("ioremap imgsys failed\n");
  1047. return;
  1048. }
  1049. clk_data = alloc_clk_data(IMG_NR_CLK);
  1050. init_clk_imgsys(base, clk_data);
  1051. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  1052. if (r)
  1053. pr_err("could not register clock provide\n");
  1054. }
  1055. CLK_OF_DECLARE(mtk_imgsys, "mediatek,mt6735-imgsys", mt_imgsys_init);
  1056. static void __init mt_mmsys_init(struct device_node *node)
  1057. {
  1058. struct clk_onecell_data *clk_data;
  1059. void __iomem *base;
  1060. int r;
  1061. pr_debug("[CCF] %s: %s\n", __func__, node->name);
  1062. base = get_reg(node, 0);
  1063. if (!base) {
  1064. pr_err("ioremap mmsys failed\n");
  1065. return;
  1066. }
  1067. clk_data = alloc_clk_data(MM_NR_CLK);
  1068. init_clk_mmsys(base, clk_data);
  1069. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  1070. if (r)
  1071. pr_err("could not register clock provide\n");
  1072. }
  1073. CLK_OF_DECLARE(mtk_mmsys, "mediatek,mt6735-mmsys", mt_mmsys_init);
  1074. static void __init mt_vdecsys_init(struct device_node *node)
  1075. {
  1076. struct clk_onecell_data *clk_data;
  1077. void __iomem *base;
  1078. int r;
  1079. pr_debug("[CCF] %s: %s\n", __func__, node->name);
  1080. base = get_reg(node, 0);
  1081. if (!base) {
  1082. pr_err("ioremap vdecsys failed\n");
  1083. return;
  1084. }
  1085. clk_data = alloc_clk_data(VDEC_NR_CLK);
  1086. init_clk_vdecsys(base, clk_data);
  1087. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  1088. if (r)
  1089. pr_err("could not register clock provide\n");
  1090. }
  1091. CLK_OF_DECLARE(mtk_vdecsys, "mediatek,mt6735-vdecsys", mt_vdecsys_init);
  1092. static void __init mt_vencsys_init(struct device_node *node)
  1093. {
  1094. struct clk_onecell_data *clk_data;
  1095. void __iomem *base;
  1096. int r;
  1097. pr_debug("[CCF] %s: %s\n", __func__, node->name);
  1098. base = get_reg(node, 0);
  1099. if (!base) {
  1100. pr_err("ioremap vencsys failed\n");
  1101. return;
  1102. }
  1103. clk_data = alloc_clk_data(VENC_NR_CLK);
  1104. init_clk_vencsys(base, clk_data);
  1105. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  1106. if (r)
  1107. pr_err("could not register clock provide\n");
  1108. }
  1109. CLK_OF_DECLARE(mtk_vencsys, "mediatek,mt6735-vencsys", mt_vencsys_init);
  1110. static void __init mt_audiosys_init(struct device_node *node)
  1111. {
  1112. struct clk_onecell_data *clk_data;
  1113. void __iomem *base;
  1114. int r;
  1115. pr_debug("[CCF] %s: %s\n", __func__, node->name);
  1116. base = get_reg(node, 0);
  1117. if (!base) {
  1118. pr_err("ioremap audiosys failed\n");
  1119. return;
  1120. }
  1121. clk_data = alloc_clk_data(AUDIO_NR_CLK);
  1122. init_clk_audiosys(base, clk_data);
  1123. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  1124. if (r)
  1125. pr_err("could not register clock provide\n");
  1126. }
  1127. CLK_OF_DECLARE(mtk_audiosys, "mediatek,mt6735-audiosys", mt_audiosys_init);