clk-cv1800.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2023 Inochi Amaoto <inochiama@outlook.com>
  4. */
  5. #include <linux/module.h>
  6. #include <linux/clk-provider.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/io.h>
  9. #include <linux/spinlock.h>
  10. #include "clk-cv1800.h"
  11. #include "clk-cv18xx-common.h"
  12. #include "clk-cv18xx-ip.h"
  13. #include "clk-cv18xx-pll.h"
  14. struct cv1800_clk_ctrl;
  15. struct cv1800_clk_desc {
  16. struct clk_hw_onecell_data *clks_data;
  17. int (*pre_init)(struct device *dev, void __iomem *base,
  18. struct cv1800_clk_ctrl *ctrl,
  19. const struct cv1800_clk_desc *desc);
  20. };
  21. struct cv1800_clk_ctrl {
  22. const struct cv1800_clk_desc *desc;
  23. spinlock_t lock;
  24. };
  25. #define CV1800_DIV_FLAG \
  26. (CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ROUND_CLOSEST)
  27. static const struct clk_parent_data osc_parents[] = {
  28. { .index = 0 },
  29. };
  30. static const struct cv1800_clk_pll_limit pll_limits[] = {
  31. {
  32. .pre_div = _CV1800_PLL_LIMIT(1, 127),
  33. .div = _CV1800_PLL_LIMIT(6, 127),
  34. .post_div = _CV1800_PLL_LIMIT(1, 127),
  35. .ictrl = _CV1800_PLL_LIMIT(0, 7),
  36. .mode = _CV1800_PLL_LIMIT(0, 3),
  37. },
  38. {
  39. .pre_div = _CV1800_PLL_LIMIT(1, 127),
  40. .div = _CV1800_PLL_LIMIT(6, 127),
  41. .post_div = _CV1800_PLL_LIMIT(1, 127),
  42. .ictrl = _CV1800_PLL_LIMIT(0, 7),
  43. .mode = _CV1800_PLL_LIMIT(0, 3),
  44. },
  45. };
  46. static CV1800_INTEGRAL_PLL(clk_fpll, osc_parents,
  47. REG_FPLL_CSR,
  48. REG_PLL_G6_CTRL, 8,
  49. REG_PLL_G6_STATUS, 2,
  50. pll_limits,
  51. CLK_IS_CRITICAL);
  52. static CV1800_INTEGRAL_PLL(clk_mipimpll, osc_parents,
  53. REG_MIPIMPLL_CSR,
  54. REG_PLL_G2_CTRL, 0,
  55. REG_PLL_G2_STATUS, 0,
  56. pll_limits,
  57. CLK_IS_CRITICAL);
  58. static const struct clk_parent_data clk_mipimpll_parents[] = {
  59. { .hw = &clk_mipimpll.common.hw },
  60. };
  61. static const struct clk_parent_data clk_bypass_mipimpll_parents[] = {
  62. { .index = 0 },
  63. { .hw = &clk_mipimpll.common.hw },
  64. };
  65. static const struct clk_parent_data clk_bypass_fpll_parents[] = {
  66. { .index = 0 },
  67. { .hw = &clk_fpll.common.hw },
  68. };
  69. static struct cv1800_clk_pll_synthesizer clk_mpll_synthesizer = {
  70. .en = CV1800_CLK_BIT(REG_PLL_G6_SSC_SYN_CTRL, 2),
  71. .clk_half = CV1800_CLK_BIT(REG_PLL_G6_SSC_SYN_CTRL, 0),
  72. .ctrl = REG_MPLL_SSC_SYN_CTRL,
  73. .set = REG_MPLL_SSC_SYN_SET,
  74. };
  75. static CV1800_FACTIONAL_PLL(clk_mpll, clk_bypass_mipimpll_parents,
  76. REG_MPLL_CSR,
  77. REG_PLL_G6_CTRL, 0,
  78. REG_PLL_G6_STATUS, 0,
  79. pll_limits,
  80. &clk_mpll_synthesizer,
  81. CLK_IS_CRITICAL);
  82. static struct cv1800_clk_pll_synthesizer clk_tpll_synthesizer = {
  83. .en = CV1800_CLK_BIT(REG_PLL_G6_SSC_SYN_CTRL, 3),
  84. .clk_half = CV1800_CLK_BIT(REG_PLL_G6_SSC_SYN_CTRL, 0),
  85. .ctrl = REG_TPLL_SSC_SYN_CTRL,
  86. .set = REG_TPLL_SSC_SYN_SET,
  87. };
  88. static CV1800_FACTIONAL_PLL(clk_tpll, clk_bypass_mipimpll_parents,
  89. REG_TPLL_CSR,
  90. REG_PLL_G6_CTRL, 4,
  91. REG_PLL_G6_STATUS, 1,
  92. pll_limits,
  93. &clk_tpll_synthesizer,
  94. CLK_IS_CRITICAL);
  95. static struct cv1800_clk_pll_synthesizer clk_a0pll_synthesizer = {
  96. .en = CV1800_CLK_BIT(REG_PLL_G2_SSC_SYN_CTRL, 2),
  97. .clk_half = CV1800_CLK_BIT(REG_PLL_G2_SSC_SYN_CTRL, 0),
  98. .ctrl = REG_A0PLL_SSC_SYN_CTRL,
  99. .set = REG_A0PLL_SSC_SYN_SET,
  100. };
  101. static CV1800_FACTIONAL_PLL(clk_a0pll, clk_bypass_mipimpll_parents,
  102. REG_A0PLL_CSR,
  103. REG_PLL_G2_CTRL, 4,
  104. REG_PLL_G2_STATUS, 1,
  105. pll_limits,
  106. &clk_a0pll_synthesizer,
  107. CLK_IS_CRITICAL);
  108. static struct cv1800_clk_pll_synthesizer clk_disppll_synthesizer = {
  109. .en = CV1800_CLK_BIT(REG_PLL_G2_SSC_SYN_CTRL, 3),
  110. .clk_half = CV1800_CLK_BIT(REG_PLL_G2_SSC_SYN_CTRL, 0),
  111. .ctrl = REG_DISPPLL_SSC_SYN_CTRL,
  112. .set = REG_DISPPLL_SSC_SYN_SET,
  113. };
  114. static CV1800_FACTIONAL_PLL(clk_disppll, clk_bypass_mipimpll_parents,
  115. REG_DISPPLL_CSR,
  116. REG_PLL_G2_CTRL, 8,
  117. REG_PLL_G2_STATUS, 2,
  118. pll_limits,
  119. &clk_disppll_synthesizer,
  120. CLK_IS_CRITICAL);
  121. static struct cv1800_clk_pll_synthesizer clk_cam0pll_synthesizer = {
  122. .en = CV1800_CLK_BIT(REG_PLL_G2_SSC_SYN_CTRL, 4),
  123. .clk_half = CV1800_CLK_BIT(REG_PLL_G2_SSC_SYN_CTRL, 0),
  124. .ctrl = REG_CAM0PLL_SSC_SYN_CTRL,
  125. .set = REG_CAM0PLL_SSC_SYN_SET,
  126. };
  127. static CV1800_FACTIONAL_PLL(clk_cam0pll, clk_bypass_mipimpll_parents,
  128. REG_CAM0PLL_CSR,
  129. REG_PLL_G2_CTRL, 12,
  130. REG_PLL_G2_STATUS, 3,
  131. pll_limits,
  132. &clk_cam0pll_synthesizer,
  133. CLK_IGNORE_UNUSED);
  134. static struct cv1800_clk_pll_synthesizer clk_cam1pll_synthesizer = {
  135. .en = CV1800_CLK_BIT(REG_PLL_G2_SSC_SYN_CTRL, 5),
  136. .clk_half = CV1800_CLK_BIT(REG_PLL_G2_SSC_SYN_CTRL, 0),
  137. .ctrl = REG_CAM1PLL_SSC_SYN_CTRL,
  138. .set = REG_CAM1PLL_SSC_SYN_SET,
  139. };
  140. static CV1800_FACTIONAL_PLL(clk_cam1pll, clk_bypass_mipimpll_parents,
  141. REG_CAM1PLL_CSR,
  142. REG_PLL_G2_CTRL, 16,
  143. REG_PLL_G2_STATUS, 4,
  144. pll_limits,
  145. &clk_cam1pll_synthesizer,
  146. CLK_IS_CRITICAL);
  147. static const struct clk_parent_data clk_cam0pll_parents[] = {
  148. { .hw = &clk_cam0pll.common.hw },
  149. };
  150. /* G2D */
  151. static CV1800_FIXED_DIV(clk_cam0pll_d2, clk_cam0pll_parents,
  152. REG_CAM0PLL_CLK_CSR, 1,
  153. 2,
  154. CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED);
  155. static CV1800_FIXED_DIV(clk_cam0pll_d3, clk_cam0pll_parents,
  156. REG_CAM0PLL_CLK_CSR, 2,
  157. 3,
  158. CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED);
  159. static CV1800_FIXED_DIV(clk_mipimpll_d3, clk_mipimpll_parents,
  160. REG_MIPIMPLL_CLK_CSR, 2,
  161. 3,
  162. CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED);
  163. /* TPU */
  164. static const struct clk_parent_data clk_tpu_parents[] = {
  165. { .index = 0 },
  166. { .hw = &clk_tpll.common.hw },
  167. { .hw = &clk_a0pll.common.hw },
  168. { .hw = &clk_mipimpll.common.hw },
  169. { .hw = &clk_fpll.common.hw },
  170. };
  171. static CV1800_BYPASS_MUX(clk_tpu, clk_tpu_parents,
  172. REG_CLK_EN_0, 4,
  173. REG_DIV_CLK_TPU, 16, 4, 3, CV1800_DIV_FLAG,
  174. REG_DIV_CLK_TPU, 8, 2,
  175. REG_CLK_BYP_0, 3,
  176. 0);
  177. static CV1800_GATE(clk_tpu_fab, clk_mipimpll_parents,
  178. REG_CLK_EN_0, 5,
  179. 0);
  180. /* FABRIC_AXI6 */
  181. static CV1800_BYPASS_DIV(clk_axi6, clk_bypass_fpll_parents,
  182. REG_CLK_EN_2, 2,
  183. REG_DIV_CLK_AXI6, 16, 4, 15, CV1800_DIV_FLAG,
  184. REG_CLK_BYP_0, 20,
  185. CLK_IS_CRITICAL);
  186. static const struct clk_parent_data clk_axi6_bus_parents[] = {
  187. { .hw = &clk_axi6.div.common.hw },
  188. };
  189. static const struct clk_parent_data clk_bypass_axi6_bus_parents[] = {
  190. { .index = 0 },
  191. { .hw = &clk_axi6.div.common.hw },
  192. };
  193. /* FABRIC_AXI4 */
  194. static const struct clk_parent_data clk_axi4_parents[] = {
  195. { .index = 0 },
  196. { .hw = &clk_fpll.common.hw },
  197. { .hw = &clk_disppll.common.hw },
  198. };
  199. static CV1800_BYPASS_MUX(clk_axi4, clk_axi4_parents,
  200. REG_CLK_EN_2, 1,
  201. REG_DIV_CLK_AXI4, 16, 4, 5, CV1800_DIV_FLAG,
  202. REG_DIV_CLK_AXI4, 8, 2,
  203. REG_CLK_BYP_0, 19,
  204. CLK_IS_CRITICAL);
  205. static const struct clk_parent_data clk_axi4_bus_parents[] = {
  206. { .hw = &clk_axi4.mux.common.hw },
  207. };
  208. /* XTAL_MISC */
  209. static CV1800_GATE(clk_xtal_misc, osc_parents,
  210. REG_CLK_EN_0, 14,
  211. CLK_IS_CRITICAL);
  212. static const struct clk_parent_data clk_timer_parents[] = {
  213. { .hw = &clk_xtal_misc.common.hw },
  214. };
  215. /* TOP */
  216. static const struct clk_parent_data clk_cam0_200_parents[] = {
  217. { .index = 0 },
  218. { .index = 0 },
  219. { .hw = &clk_disppll.common.hw },
  220. };
  221. static CV1800_BYPASS_MUX(clk_cam0_200, clk_cam0_200_parents,
  222. REG_CLK_EN_1, 13,
  223. REG_DIV_CLK_CAM0_200, 16, 4, 1, CV1800_DIV_FLAG,
  224. REG_DIV_CLK_CAM0_200, 8, 2,
  225. REG_CLK_BYP_0, 16,
  226. CLK_IS_CRITICAL);
  227. static CV1800_DIV(clk_1m, osc_parents,
  228. REG_CLK_EN_3, 5,
  229. REG_DIV_CLK_1M, 16, 6, 25, CV1800_DIV_FLAG,
  230. CLK_IS_CRITICAL);
  231. static CV1800_GATE(clk_pm, clk_axi6_bus_parents,
  232. REG_CLK_EN_3, 8,
  233. CLK_IS_CRITICAL);
  234. static CV1800_GATE(clk_timer0, clk_timer_parents,
  235. REG_CLK_EN_3, 9,
  236. CLK_IS_CRITICAL);
  237. static CV1800_GATE(clk_timer1, clk_timer_parents,
  238. REG_CLK_EN_3, 10,
  239. CLK_IS_CRITICAL);
  240. static CV1800_GATE(clk_timer2, clk_timer_parents,
  241. REG_CLK_EN_3, 11,
  242. CLK_IS_CRITICAL);
  243. static CV1800_GATE(clk_timer3, clk_timer_parents,
  244. REG_CLK_EN_3, 12,
  245. CLK_IS_CRITICAL);
  246. static CV1800_GATE(clk_timer4, clk_timer_parents,
  247. REG_CLK_EN_3, 13,
  248. CLK_IS_CRITICAL);
  249. static CV1800_GATE(clk_timer5, clk_timer_parents,
  250. REG_CLK_EN_3, 14,
  251. CLK_IS_CRITICAL);
  252. static CV1800_GATE(clk_timer6, clk_timer_parents,
  253. REG_CLK_EN_3, 15,
  254. CLK_IS_CRITICAL);
  255. static CV1800_GATE(clk_timer7, clk_timer_parents,
  256. REG_CLK_EN_3, 16,
  257. CLK_IS_CRITICAL);
  258. static const struct clk_parent_data clk_parents_1m[] = {
  259. { .hw = &clk_1m.common.hw },
  260. };
  261. static const struct clk_parent_data clk_uart_parents[] = {
  262. { .hw = &clk_cam0_200.mux.common.hw },
  263. };
  264. /* AHB ROM */
  265. static CV1800_GATE(clk_ahb_rom, clk_axi4_bus_parents,
  266. REG_CLK_EN_0, 6,
  267. 0);
  268. /* RTC */
  269. static CV1800_GATE(clk_rtc_25m, osc_parents,
  270. REG_CLK_EN_0, 8,
  271. CLK_IS_CRITICAL);
  272. static CV1800_BYPASS_DIV(clk_src_rtc_sys_0, clk_bypass_fpll_parents,
  273. REG_CLK_EN_4, 6,
  274. REG_DIV_CLK_RTCSYS_SRC_0, 16, 4, 5, CV1800_DIV_FLAG,
  275. REG_CLK_BYP_1, 5,
  276. CLK_IS_CRITICAL);
  277. /* TEMPSEN */
  278. static CV1800_GATE(clk_tempsen, osc_parents,
  279. REG_CLK_EN_0, 9,
  280. 0);
  281. /* SARADC */
  282. static CV1800_GATE(clk_saradc, osc_parents,
  283. REG_CLK_EN_0, 10,
  284. 0);
  285. /* EFUSE */
  286. static CV1800_GATE(clk_efuse, osc_parents,
  287. REG_CLK_EN_0, 11,
  288. 0);
  289. static CV1800_GATE(clk_apb_efuse, osc_parents,
  290. REG_CLK_EN_0, 12,
  291. 0);
  292. /* WDT */
  293. static CV1800_GATE(clk_apb_wdt, osc_parents,
  294. REG_CLK_EN_1, 7,
  295. CLK_IS_CRITICAL);
  296. /* WGN */
  297. static CV1800_GATE(clk_wgn, osc_parents,
  298. REG_CLK_EN_3, 22,
  299. 0);
  300. static CV1800_GATE(clk_wgn0, osc_parents,
  301. REG_CLK_EN_3, 23,
  302. 0);
  303. static CV1800_GATE(clk_wgn1, osc_parents,
  304. REG_CLK_EN_3, 24,
  305. 0);
  306. static CV1800_GATE(clk_wgn2, osc_parents,
  307. REG_CLK_EN_3, 25,
  308. 0);
  309. /* KEYSCAN */
  310. static CV1800_GATE(clk_keyscan, osc_parents,
  311. REG_CLK_EN_3, 26,
  312. 0);
  313. /* EMMC */
  314. static CV1800_GATE(clk_axi4_emmc, clk_axi4_bus_parents,
  315. REG_CLK_EN_0, 15,
  316. 0);
  317. static CV1800_BYPASS_MUX(clk_emmc, clk_axi4_parents,
  318. REG_CLK_EN_0, 16,
  319. REG_DIV_CLK_EMMC, 16, 5, 15, CV1800_DIV_FLAG,
  320. REG_DIV_CLK_EMMC, 8, 2,
  321. REG_CLK_BYP_0, 5,
  322. 0);
  323. static CV1800_DIV(clk_emmc_100k, clk_parents_1m,
  324. REG_CLK_EN_0, 17,
  325. REG_DIV_CLK_EMMC_100K, 16, 8, 10, CV1800_DIV_FLAG,
  326. 0);
  327. /* SD */
  328. static CV1800_GATE(clk_axi4_sd0, clk_axi4_bus_parents,
  329. REG_CLK_EN_0, 18,
  330. 0);
  331. static CV1800_BYPASS_MUX(clk_sd0, clk_axi4_parents,
  332. REG_CLK_EN_0, 19,
  333. REG_DIV_CLK_SD0, 16, 5, 15, CV1800_DIV_FLAG,
  334. REG_DIV_CLK_SD0, 8, 2,
  335. REG_CLK_BYP_0, 6,
  336. 0);
  337. static CV1800_DIV(clk_sd0_100k, clk_parents_1m,
  338. REG_CLK_EN_0, 20,
  339. REG_DIV_CLK_SD0_100K, 16, 8, 10, CV1800_DIV_FLAG,
  340. 0);
  341. static CV1800_GATE(clk_axi4_sd1, clk_axi4_bus_parents,
  342. REG_CLK_EN_0, 21,
  343. 0);
  344. static CV1800_BYPASS_MUX(clk_sd1, clk_axi4_parents,
  345. REG_CLK_EN_0, 22,
  346. REG_DIV_CLK_SD1, 16, 5, 15, CV1800_DIV_FLAG,
  347. REG_DIV_CLK_SD1, 8, 2,
  348. REG_CLK_BYP_0, 7,
  349. 0);
  350. static CV1800_DIV(clk_sd1_100k, clk_parents_1m,
  351. REG_CLK_EN_0, 23,
  352. REG_DIV_CLK_SD1_100K, 16, 8, 10, CV1800_DIV_FLAG,
  353. 0);
  354. /* SPI NAND */
  355. static CV1800_BYPASS_MUX(clk_spi_nand, clk_axi4_parents,
  356. REG_CLK_EN_0, 24,
  357. REG_DIV_CLK_SPI_NAND, 16, 5, 8, CV1800_DIV_FLAG,
  358. REG_DIV_CLK_SPI_NAND, 8, 2,
  359. REG_CLK_BYP_0, 8,
  360. 0);
  361. /* GPIO */
  362. static CV1800_DIV(clk_gpio_db, clk_parents_1m,
  363. REG_CLK_EN_0, 31,
  364. REG_DIV_CLK_GPIO_DB, 16, 16, 10, CV1800_DIV_FLAG,
  365. CLK_IS_CRITICAL);
  366. static CV1800_GATE(clk_apb_gpio, clk_axi6_bus_parents,
  367. REG_CLK_EN_0, 29,
  368. CLK_IS_CRITICAL);
  369. static CV1800_GATE(clk_apb_gpio_intr, clk_axi6_bus_parents,
  370. REG_CLK_EN_0, 30,
  371. CLK_IS_CRITICAL);
  372. /* ETH */
  373. static CV1800_BYPASS_DIV(clk_eth0_500m, clk_bypass_fpll_parents,
  374. REG_CLK_EN_0, 25,
  375. REG_DIV_CLK_GPIO_DB, 16, 4, 3, CV1800_DIV_FLAG,
  376. REG_CLK_BYP_0, 9,
  377. 0);
  378. static CV1800_GATE(clk_axi4_eth0, clk_axi4_bus_parents,
  379. REG_CLK_EN_0, 26,
  380. 0);
  381. static CV1800_BYPASS_DIV(clk_eth1_500m, clk_bypass_fpll_parents,
  382. REG_CLK_EN_0, 27,
  383. REG_DIV_CLK_GPIO_DB, 16, 4, 3, CV1800_DIV_FLAG,
  384. REG_CLK_BYP_0, 10,
  385. 0);
  386. static CV1800_GATE(clk_axi4_eth1, clk_axi4_bus_parents,
  387. REG_CLK_EN_0, 28,
  388. 0);
  389. /* SF */
  390. static CV1800_GATE(clk_ahb_sf, clk_axi4_bus_parents,
  391. REG_CLK_EN_1, 0,
  392. 0);
  393. static CV1800_GATE(clk_ahb_sf1, clk_axi4_bus_parents,
  394. REG_CLK_EN_3, 27,
  395. 0);
  396. /* AUDSRC */
  397. static CV1800_ACLK(clk_a24m, clk_mipimpll_parents,
  398. REG_APLL_FRAC_DIV_CTRL, 0,
  399. REG_APLL_FRAC_DIV_CTRL, 3,
  400. REG_APLL_FRAC_DIV_CTRL, 1,
  401. REG_APLL_FRAC_DIV_CTRL, 2,
  402. REG_APLL_FRAC_DIV_M, 0, 22, CV1800_DIV_FLAG,
  403. REG_APLL_FRAC_DIV_N, 0, 22, CV1800_DIV_FLAG,
  404. 24576000,
  405. 0);
  406. static const struct clk_parent_data clk_aud_parents[] = {
  407. { .index = 0 },
  408. { .hw = &clk_a0pll.common.hw },
  409. { .hw = &clk_a24m.common.hw },
  410. };
  411. static CV1800_BYPASS_MUX(clk_audsrc, clk_aud_parents,
  412. REG_CLK_EN_4, 1,
  413. REG_DIV_CLK_AUDSRC, 16, 8, 18, CV1800_DIV_FLAG,
  414. REG_DIV_CLK_AUDSRC, 8, 2,
  415. REG_CLK_BYP_1, 2,
  416. 0);
  417. static CV1800_GATE(clk_apb_audsrc, clk_axi4_bus_parents,
  418. REG_CLK_EN_4, 2,
  419. 0);
  420. /* SDMA */
  421. static CV1800_GATE(clk_sdma_axi, clk_axi4_bus_parents,
  422. REG_CLK_EN_1, 1,
  423. 0);
  424. static CV1800_BYPASS_MUX(clk_sdma_aud0, clk_aud_parents,
  425. REG_CLK_EN_1, 2,
  426. REG_DIV_CLK_SDMA_AUD0, 16, 8, 18, CV1800_DIV_FLAG,
  427. REG_DIV_CLK_SDMA_AUD0, 8, 2,
  428. REG_CLK_BYP_0, 11,
  429. 0);
  430. static CV1800_BYPASS_MUX(clk_sdma_aud1, clk_aud_parents,
  431. REG_CLK_EN_1, 3,
  432. REG_DIV_CLK_SDMA_AUD1, 16, 8, 18, CV1800_DIV_FLAG,
  433. REG_DIV_CLK_SDMA_AUD1, 8, 2,
  434. REG_CLK_BYP_0, 12,
  435. 0);
  436. static CV1800_BYPASS_MUX(clk_sdma_aud2, clk_aud_parents,
  437. REG_CLK_EN_1, 3,
  438. REG_DIV_CLK_SDMA_AUD2, 16, 8, 18, CV1800_DIV_FLAG,
  439. REG_DIV_CLK_SDMA_AUD2, 8, 2,
  440. REG_CLK_BYP_0, 13,
  441. 0);
  442. static CV1800_BYPASS_MUX(clk_sdma_aud3, clk_aud_parents,
  443. REG_CLK_EN_1, 3,
  444. REG_DIV_CLK_SDMA_AUD3, 16, 8, 18, CV1800_DIV_FLAG,
  445. REG_DIV_CLK_SDMA_AUD3, 8, 2,
  446. REG_CLK_BYP_0, 14,
  447. 0);
  448. /* SPI */
  449. static CV1800_GATE(clk_apb_spi0, clk_axi4_bus_parents,
  450. REG_CLK_EN_1, 9,
  451. 0);
  452. static CV1800_GATE(clk_apb_spi1, clk_axi4_bus_parents,
  453. REG_CLK_EN_1, 10,
  454. 0);
  455. static CV1800_GATE(clk_apb_spi2, clk_axi4_bus_parents,
  456. REG_CLK_EN_1, 11,
  457. 0);
  458. static CV1800_GATE(clk_apb_spi3, clk_axi4_bus_parents,
  459. REG_CLK_EN_1, 12,
  460. 0);
  461. static CV1800_BYPASS_DIV(clk_spi, clk_bypass_fpll_parents,
  462. REG_CLK_EN_3, 6,
  463. REG_DIV_CLK_SPI, 16, 6, 8, CV1800_DIV_FLAG,
  464. REG_CLK_BYP_0, 30,
  465. 0);
  466. /* UART */
  467. static CV1800_GATE(clk_uart0, clk_uart_parents,
  468. REG_CLK_EN_1, 14,
  469. CLK_IS_CRITICAL);
  470. static CV1800_GATE(clk_apb_uart0, clk_axi4_bus_parents,
  471. REG_CLK_EN_1, 15,
  472. CLK_IS_CRITICAL);
  473. static CV1800_GATE(clk_uart1, clk_uart_parents,
  474. REG_CLK_EN_1, 16,
  475. 0);
  476. static CV1800_GATE(clk_apb_uart1, clk_axi4_bus_parents,
  477. REG_CLK_EN_1, 17,
  478. 0);
  479. static CV1800_GATE(clk_uart2, clk_uart_parents,
  480. REG_CLK_EN_1, 18,
  481. 0);
  482. static CV1800_GATE(clk_apb_uart2, clk_axi4_bus_parents,
  483. REG_CLK_EN_1, 19,
  484. 0);
  485. static CV1800_GATE(clk_uart3, clk_uart_parents,
  486. REG_CLK_EN_1, 20,
  487. 0);
  488. static CV1800_GATE(clk_apb_uart3, clk_axi4_bus_parents,
  489. REG_CLK_EN_1, 21,
  490. 0);
  491. static CV1800_GATE(clk_uart4, clk_uart_parents,
  492. REG_CLK_EN_1, 22,
  493. 0);
  494. static CV1800_GATE(clk_apb_uart4, clk_axi4_bus_parents,
  495. REG_CLK_EN_1, 23,
  496. 0);
  497. /* I2S */
  498. static CV1800_GATE(clk_apb_i2s0, clk_axi4_bus_parents,
  499. REG_CLK_EN_1, 24,
  500. 0);
  501. static CV1800_GATE(clk_apb_i2s1, clk_axi4_bus_parents,
  502. REG_CLK_EN_1, 25,
  503. 0);
  504. static CV1800_GATE(clk_apb_i2s2, clk_axi4_bus_parents,
  505. REG_CLK_EN_1, 26,
  506. 0);
  507. static CV1800_GATE(clk_apb_i2s3, clk_axi4_bus_parents,
  508. REG_CLK_EN_1, 27,
  509. 0);
  510. /* DEBUG */
  511. static CV1800_GATE(clk_debug, osc_parents,
  512. REG_CLK_EN_0, 13,
  513. CLK_IS_CRITICAL);
  514. static CV1800_BYPASS_DIV(clk_ap_debug, clk_bypass_fpll_parents,
  515. REG_CLK_EN_4, 5,
  516. REG_DIV_CLK_AP_DEBUG, 16, 4, 5, CV1800_DIV_FLAG,
  517. REG_CLK_BYP_1, 4,
  518. CLK_IS_CRITICAL);
  519. /* DDR */
  520. static CV1800_GATE(clk_ddr_axi_reg, clk_axi6_bus_parents,
  521. REG_CLK_EN_0, 7,
  522. CLK_IS_CRITICAL);
  523. /* I2C */
  524. static CV1800_GATE(clk_apb_i2c, clk_axi4_bus_parents,
  525. REG_CLK_EN_1, 6,
  526. 0);
  527. static CV1800_BYPASS_DIV(clk_i2c, clk_bypass_axi6_bus_parents,
  528. REG_CLK_EN_3, 7,
  529. REG_DIV_CLK_I2C, 16, 4, 1, CV1800_DIV_FLAG,
  530. REG_CLK_BYP_0, 31,
  531. 0);
  532. static CV1800_GATE(clk_apb_i2c0, clk_axi4_bus_parents,
  533. REG_CLK_EN_3, 17,
  534. 0);
  535. static CV1800_GATE(clk_apb_i2c1, clk_axi4_bus_parents,
  536. REG_CLK_EN_3, 18,
  537. 0);
  538. static CV1800_GATE(clk_apb_i2c2, clk_axi4_bus_parents,
  539. REG_CLK_EN_3, 19,
  540. 0);
  541. static CV1800_GATE(clk_apb_i2c3, clk_axi4_bus_parents,
  542. REG_CLK_EN_3, 20,
  543. 0);
  544. static CV1800_GATE(clk_apb_i2c4, clk_axi4_bus_parents,
  545. REG_CLK_EN_3, 21,
  546. 0);
  547. /* USB */
  548. static CV1800_GATE(clk_axi4_usb, clk_axi4_bus_parents,
  549. REG_CLK_EN_1, 28,
  550. 0);
  551. static CV1800_GATE(clk_apb_usb, clk_axi4_bus_parents,
  552. REG_CLK_EN_1, 29,
  553. 0);
  554. static CV1800_BYPASS_FIXED_DIV(clk_usb_125m, clk_bypass_fpll_parents,
  555. REG_CLK_EN_1, 30,
  556. 12,
  557. REG_CLK_BYP_0, 17,
  558. CLK_SET_RATE_PARENT);
  559. static CV1800_FIXED_DIV(clk_usb_33k, clk_parents_1m,
  560. REG_CLK_EN_1, 31,
  561. 3,
  562. 0);
  563. static CV1800_BYPASS_FIXED_DIV(clk_usb_12m, clk_bypass_fpll_parents,
  564. REG_CLK_EN_2, 0,
  565. 125,
  566. REG_CLK_BYP_0, 18,
  567. CLK_SET_RATE_PARENT);
  568. /* VIP SYS */
  569. static const struct clk_parent_data clk_vip_sys_parents[] = {
  570. { .index = 0 },
  571. { .hw = &clk_mipimpll.common.hw },
  572. { .hw = &clk_cam0pll.common.hw },
  573. { .hw = &clk_disppll.common.hw },
  574. { .hw = &clk_fpll.common.hw },
  575. };
  576. static const struct clk_parent_data clk_disp_vip_parents[] = {
  577. { .index = 0 },
  578. { .hw = &clk_disppll.common.hw },
  579. };
  580. static CV1800_BYPASS_DIV(clk_dsi_esc, clk_bypass_axi6_bus_parents,
  581. REG_CLK_EN_2, 3,
  582. REG_DIV_CLK_DSI_ESC, 16, 4, 5, CV1800_DIV_FLAG,
  583. REG_CLK_BYP_0, 21,
  584. 0);
  585. static CV1800_BYPASS_MUX(clk_axi_vip, clk_vip_sys_parents,
  586. REG_CLK_EN_2, 4,
  587. REG_DIV_CLK_AXI_VIP, 16, 4, 3, CV1800_DIV_FLAG,
  588. REG_DIV_CLK_AXI_VIP, 8, 2,
  589. REG_CLK_BYP_0, 22,
  590. 0);
  591. static const struct clk_parent_data clk_axi_vip_bus_parents[] = {
  592. { .hw = &clk_axi_vip.mux.common.hw },
  593. };
  594. static CV1800_BYPASS_MUX(clk_src_vip_sys_0, clk_vip_sys_parents,
  595. REG_CLK_EN_2, 5,
  596. REG_DIV_CLK_SRC_VIP_SYS_0, 16, 4, 6, CV1800_DIV_FLAG,
  597. REG_DIV_CLK_SRC_VIP_SYS_0, 8, 2,
  598. REG_CLK_BYP_0, 23,
  599. 0);
  600. static CV1800_BYPASS_MUX(clk_src_vip_sys_1, clk_vip_sys_parents,
  601. REG_CLK_EN_2, 6,
  602. REG_DIV_CLK_SRC_VIP_SYS_1, 16, 4, 6, CV1800_DIV_FLAG,
  603. REG_DIV_CLK_SRC_VIP_SYS_1, 8, 2,
  604. REG_CLK_BYP_0, 24,
  605. 0);
  606. static CV1800_BYPASS_DIV(clk_disp_src_vip, clk_disp_vip_parents,
  607. REG_CLK_EN_2, 7,
  608. REG_DIV_CLK_DISP_SRC_VIP, 16, 4, 8, CV1800_DIV_FLAG,
  609. REG_CLK_BYP_0, 25,
  610. 0);
  611. static CV1800_BYPASS_MUX(clk_src_vip_sys_2, clk_vip_sys_parents,
  612. REG_CLK_EN_3, 29,
  613. REG_DIV_CLK_SRC_VIP_SYS_2, 16, 4, 2, CV1800_DIV_FLAG,
  614. REG_DIV_CLK_SRC_VIP_SYS_2, 8, 2,
  615. REG_CLK_BYP_1, 1,
  616. 0);
  617. static CV1800_GATE(clk_csi_mac0_vip, clk_axi_vip_bus_parents,
  618. REG_CLK_EN_2, 18,
  619. 0);
  620. static CV1800_GATE(clk_csi_mac1_vip, clk_axi_vip_bus_parents,
  621. REG_CLK_EN_2, 19,
  622. 0);
  623. static CV1800_GATE(clk_isp_top_vip, clk_axi_vip_bus_parents,
  624. REG_CLK_EN_2, 20,
  625. 0);
  626. static CV1800_GATE(clk_img_d_vip, clk_axi_vip_bus_parents,
  627. REG_CLK_EN_2, 21,
  628. 0);
  629. static CV1800_GATE(clk_img_v_vip, clk_axi_vip_bus_parents,
  630. REG_CLK_EN_2, 22,
  631. 0);
  632. static CV1800_GATE(clk_sc_top_vip, clk_axi_vip_bus_parents,
  633. REG_CLK_EN_2, 23,
  634. 0);
  635. static CV1800_GATE(clk_sc_d_vip, clk_axi_vip_bus_parents,
  636. REG_CLK_EN_2, 24,
  637. 0);
  638. static CV1800_GATE(clk_sc_v1_vip, clk_axi_vip_bus_parents,
  639. REG_CLK_EN_2, 25,
  640. 0);
  641. static CV1800_GATE(clk_sc_v2_vip, clk_axi_vip_bus_parents,
  642. REG_CLK_EN_2, 26,
  643. 0);
  644. static CV1800_GATE(clk_sc_v3_vip, clk_axi_vip_bus_parents,
  645. REG_CLK_EN_2, 27,
  646. 0);
  647. static CV1800_GATE(clk_dwa_vip, clk_axi_vip_bus_parents,
  648. REG_CLK_EN_2, 28,
  649. 0);
  650. static CV1800_GATE(clk_bt_vip, clk_axi_vip_bus_parents,
  651. REG_CLK_EN_2, 29,
  652. 0);
  653. static CV1800_GATE(clk_disp_vip, clk_axi_vip_bus_parents,
  654. REG_CLK_EN_2, 30,
  655. 0);
  656. static CV1800_GATE(clk_dsi_mac_vip, clk_axi_vip_bus_parents,
  657. REG_CLK_EN_2, 31,
  658. 0);
  659. static CV1800_GATE(clk_lvds0_vip, clk_axi_vip_bus_parents,
  660. REG_CLK_EN_3, 0,
  661. 0);
  662. static CV1800_GATE(clk_lvds1_vip, clk_axi_vip_bus_parents,
  663. REG_CLK_EN_3, 1,
  664. 0);
  665. static CV1800_GATE(clk_csi0_rx_vip, clk_axi_vip_bus_parents,
  666. REG_CLK_EN_3, 2,
  667. 0);
  668. static CV1800_GATE(clk_csi1_rx_vip, clk_axi_vip_bus_parents,
  669. REG_CLK_EN_3, 3,
  670. 0);
  671. static CV1800_GATE(clk_pad_vi_vip, clk_axi_vip_bus_parents,
  672. REG_CLK_EN_3, 4,
  673. 0);
  674. static CV1800_GATE(clk_pad_vi1_vip, clk_axi_vip_bus_parents,
  675. REG_CLK_EN_3, 30,
  676. 0);
  677. static CV1800_GATE(clk_cfg_reg_vip, clk_axi6_bus_parents,
  678. REG_CLK_EN_3, 31,
  679. 0);
  680. static CV1800_GATE(clk_pad_vi2_vip, clk_axi_vip_bus_parents,
  681. REG_CLK_EN_4, 7,
  682. 0);
  683. static CV1800_GATE(clk_csi_be_vip, clk_axi_vip_bus_parents,
  684. REG_CLK_EN_4, 8,
  685. 0);
  686. static CV1800_GATE(clk_vip_ip0, clk_axi_vip_bus_parents,
  687. REG_CLK_EN_4, 9,
  688. 0);
  689. static CV1800_GATE(clk_vip_ip1, clk_axi_vip_bus_parents,
  690. REG_CLK_EN_4, 10,
  691. 0);
  692. static CV1800_GATE(clk_vip_ip2, clk_axi_vip_bus_parents,
  693. REG_CLK_EN_4, 11,
  694. 0);
  695. static CV1800_GATE(clk_vip_ip3, clk_axi_vip_bus_parents,
  696. REG_CLK_EN_4, 12,
  697. 0);
  698. static CV1800_BYPASS_MUX(clk_src_vip_sys_3, clk_vip_sys_parents,
  699. REG_CLK_EN_4, 15,
  700. REG_DIV_CLK_SRC_VIP_SYS_3, 16, 4, 2, CV1800_DIV_FLAG,
  701. REG_DIV_CLK_SRC_VIP_SYS_3, 8, 2,
  702. REG_CLK_BYP_1, 8,
  703. 0);
  704. static CV1800_BYPASS_MUX(clk_src_vip_sys_4, clk_vip_sys_parents,
  705. REG_CLK_EN_4, 16,
  706. REG_DIV_CLK_SRC_VIP_SYS_4, 16, 4, 3, CV1800_DIV_FLAG,
  707. REG_DIV_CLK_SRC_VIP_SYS_4, 8, 2,
  708. REG_CLK_BYP_1, 9,
  709. 0);
  710. static CV1800_GATE(clk_ive_vip, clk_axi_vip_bus_parents,
  711. REG_CLK_EN_4, 17,
  712. 0);
  713. static CV1800_GATE(clk_raw_vip, clk_axi_vip_bus_parents,
  714. REG_CLK_EN_4, 18,
  715. 0);
  716. static CV1800_GATE(clk_osdc_vip, clk_axi_vip_bus_parents,
  717. REG_CLK_EN_4, 19,
  718. 0);
  719. static CV1800_GATE(clk_csi_mac2_vip, clk_axi_vip_bus_parents,
  720. REG_CLK_EN_4, 20,
  721. 0);
  722. static CV1800_GATE(clk_cam0_vip, clk_axi_vip_bus_parents,
  723. REG_CLK_EN_4, 21,
  724. 0);
  725. /* CAM OUT */
  726. static const struct clk_parent_data clk_cam_parents[] = {
  727. { .hw = &clk_cam0pll.common.hw },
  728. { .hw = &clk_cam0pll_d2.common.hw },
  729. { .hw = &clk_cam0pll_d3.common.hw },
  730. { .hw = &clk_mipimpll_d3.common.hw },
  731. };
  732. static CV1800_MUX(clk_cam0, clk_cam_parents,
  733. REG_CLK_EN_2, 16,
  734. REG_CLK_CAM0_SRC_DIV, 16, 6, 0, CV1800_DIV_FLAG,
  735. REG_CLK_CAM0_SRC_DIV, 8, 2,
  736. CLK_IGNORE_UNUSED);
  737. static CV1800_MUX(clk_cam1, clk_cam_parents,
  738. REG_CLK_EN_2, 17,
  739. REG_CLK_CAM1_SRC_DIV, 16, 6, 0, CV1800_DIV_FLAG,
  740. REG_CLK_CAM1_SRC_DIV, 8, 2,
  741. CLK_IGNORE_UNUSED);
  742. /* VIDEO SUBSYS */
  743. static const struct clk_parent_data clk_axi_video_codec_parents[] = {
  744. { .index = 0 },
  745. { .hw = &clk_a0pll.common.hw },
  746. { .hw = &clk_mipimpll.common.hw },
  747. { .hw = &clk_cam1pll.common.hw },
  748. { .hw = &clk_fpll.common.hw },
  749. };
  750. static const struct clk_parent_data clk_vc_src0_parents[] = {
  751. { .index = 0 },
  752. { .hw = &clk_disppll.common.hw },
  753. { .hw = &clk_mipimpll.common.hw },
  754. { .hw = &clk_cam1pll.common.hw },
  755. { .hw = &clk_fpll.common.hw },
  756. };
  757. static const struct clk_parent_data clk_vc_src1_parents[] = {
  758. { .index = 0 },
  759. { .hw = &clk_cam1pll.common.hw },
  760. };
  761. static CV1800_BYPASS_MUX(clk_axi_video_codec, clk_axi_video_codec_parents,
  762. REG_CLK_EN_2, 8,
  763. REG_DIV_CLK_AXI_VIDEO_CODEC, 16, 4, 2, CV1800_DIV_FLAG,
  764. REG_DIV_CLK_AXI_VIDEO_CODEC, 8, 2,
  765. REG_CLK_BYP_0, 26,
  766. 0);
  767. static const struct clk_parent_data clk_axi_video_codec_bus_parents[] = {
  768. { .hw = &clk_axi_video_codec.mux.common.hw },
  769. };
  770. static CV1800_BYPASS_MUX(clk_vc_src0, clk_vc_src0_parents,
  771. REG_CLK_EN_2, 9,
  772. REG_DIV_CLK_VC_SRC0, 16, 4, 2, CV1800_DIV_FLAG,
  773. REG_DIV_CLK_VC_SRC0, 8, 2,
  774. REG_CLK_BYP_0, 27,
  775. 0);
  776. static CV1800_GATE(clk_h264c, clk_axi_video_codec_bus_parents,
  777. REG_CLK_EN_2, 10,
  778. 0);
  779. static CV1800_GATE(clk_h265c, clk_axi_video_codec_bus_parents,
  780. REG_CLK_EN_2, 11,
  781. 0);
  782. static CV1800_GATE(clk_jpeg, clk_axi_video_codec_bus_parents,
  783. REG_CLK_EN_2, 12,
  784. CLK_IGNORE_UNUSED);
  785. static CV1800_GATE(clk_apb_jpeg, clk_axi6_bus_parents,
  786. REG_CLK_EN_2, 13,
  787. CLK_IGNORE_UNUSED);
  788. static CV1800_GATE(clk_apb_h264c, clk_axi6_bus_parents,
  789. REG_CLK_EN_2, 14,
  790. 0);
  791. static CV1800_GATE(clk_apb_h265c, clk_axi6_bus_parents,
  792. REG_CLK_EN_2, 15,
  793. 0);
  794. static CV1800_BYPASS_FIXED_DIV(clk_vc_src1, clk_vc_src1_parents,
  795. REG_CLK_EN_3, 28,
  796. 2,
  797. REG_CLK_BYP_1, 0,
  798. CLK_SET_RATE_PARENT);
  799. static CV1800_BYPASS_FIXED_DIV(clk_vc_src2, clk_bypass_fpll_parents,
  800. REG_CLK_EN_4, 3,
  801. 3,
  802. REG_CLK_BYP_1, 3,
  803. CLK_SET_RATE_PARENT);
  804. /* VC SYS */
  805. static CV1800_GATE(clk_cfg_reg_vc, clk_axi6_bus_parents,
  806. REG_CLK_EN_4, 0,
  807. CLK_IGNORE_UNUSED);
  808. /* PWM */
  809. static CV1800_BYPASS_MUX(clk_pwm_src, clk_axi4_parents,
  810. REG_CLK_EN_4, 4,
  811. REG_DIV_CLK_PWM_SRC_0, 16, 6, 10, CV1800_DIV_FLAG,
  812. REG_DIV_CLK_PWM_SRC_0, 8, 2,
  813. REG_CLK_BYP_0, 15,
  814. CLK_IS_CRITICAL);
  815. static const struct clk_parent_data clk_pwm_parents[] = {
  816. { .hw = &clk_pwm_src.mux.common.hw },
  817. };
  818. static CV1800_GATE(clk_pwm, clk_pwm_parents,
  819. REG_CLK_EN_1, 8,
  820. CLK_IS_CRITICAL);
  821. /* C906 */
  822. static const struct clk_parent_data clk_c906_0_parents[] = {
  823. { .index = 0 },
  824. { .hw = &clk_tpll.common.hw },
  825. { .hw = &clk_a0pll.common.hw },
  826. { .hw = &clk_mipimpll.common.hw },
  827. { .hw = &clk_mpll.common.hw },
  828. { .hw = &clk_fpll.common.hw },
  829. };
  830. static const struct clk_parent_data clk_c906_1_parents[] = {
  831. { .index = 0 },
  832. { .hw = &clk_tpll.common.hw },
  833. { .hw = &clk_a0pll.common.hw },
  834. { .hw = &clk_disppll.common.hw },
  835. { .hw = &clk_mpll.common.hw },
  836. { .hw = &clk_fpll.common.hw },
  837. };
  838. static const s8 clk_c906_parent2sel[] = {
  839. -1, /* osc */
  840. 0, /* mux 0: clk_tpll(c906_0), clk_tpll(c906_1) */
  841. 0, /* mux 0: clk_a0pll(c906_0), clk_a0pll(c906_1) */
  842. 0, /* mux 0: clk_mipimpll(c906_0), clk_disppll(c906_1) */
  843. 0, /* mux 0: clk_mpll(c906_0), clk_mpll(c906_1) */
  844. 1 /* mux 1: clk_fpll(c906_0), clk_fpll(c906_1) */
  845. };
  846. static const u8 clk_c906_sel2parent[2][4] = {
  847. [0] = {
  848. 1,
  849. 2,
  850. 3,
  851. 4
  852. },
  853. [1] = {
  854. 5,
  855. 5,
  856. 5,
  857. 5
  858. },
  859. };
  860. static CV1800_MMUX(clk_c906_0, clk_c906_0_parents,
  861. REG_CLK_EN_4, 13,
  862. REG_DIV_CLK_C906_0_0, 16, 4, 1, CV1800_DIV_FLAG,
  863. REG_DIV_CLK_C906_0_1, 16, 4, 2, CV1800_DIV_FLAG,
  864. REG_DIV_CLK_C906_0_0, 8, 2,
  865. REG_DIV_CLK_C906_0_1, 8, 2,
  866. REG_CLK_BYP_1, 6,
  867. REG_CLK_SEL_0, 23,
  868. clk_c906_parent2sel,
  869. clk_c906_sel2parent[0], clk_c906_sel2parent[1],
  870. CLK_IS_CRITICAL | CLK_GET_RATE_NOCACHE);
  871. static CV1800_MMUX(clk_c906_1, clk_c906_1_parents,
  872. REG_CLK_EN_4, 14,
  873. REG_DIV_CLK_C906_1_0, 16, 4, 2, CV1800_DIV_FLAG,
  874. REG_DIV_CLK_C906_1_1, 16, 4, 3, CV1800_DIV_FLAG,
  875. REG_DIV_CLK_C906_1_0, 8, 2,
  876. REG_DIV_CLK_C906_1_1, 8, 2,
  877. REG_CLK_BYP_1, 7,
  878. REG_CLK_SEL_0, 24,
  879. clk_c906_parent2sel,
  880. clk_c906_sel2parent[0], clk_c906_sel2parent[1],
  881. CLK_IS_CRITICAL | CLK_GET_RATE_NOCACHE);
  882. /* A53 */
  883. static CV1800_BYPASS_DIV(clk_cpu_axi0, clk_axi4_parents,
  884. REG_CLK_EN_0, 1,
  885. REG_DIV_CLK_CPU_AXI0, 16, 4, 3, CV1800_DIV_FLAG,
  886. REG_CLK_BYP_0, 1,
  887. CLK_IS_CRITICAL);
  888. static CV1800_BYPASS_DIV(clk_cpu_gic, clk_bypass_fpll_parents,
  889. REG_CLK_EN_0, 2,
  890. REG_DIV_CLK_CPU_GIC, 16, 4, 5, CV1800_DIV_FLAG,
  891. REG_CLK_BYP_0, 2,
  892. CLK_IS_CRITICAL);
  893. static CV1800_GATE(clk_xtal_ap, osc_parents,
  894. REG_CLK_EN_0, 3,
  895. CLK_IS_CRITICAL);
  896. static const struct clk_parent_data clk_a53_parents[] = {
  897. { .index = 0 },
  898. { .hw = &clk_tpll.common.hw },
  899. { .hw = &clk_a0pll.common.hw },
  900. { .hw = &clk_mipimpll.common.hw },
  901. { .hw = &clk_mpll.common.hw },
  902. { .hw = &clk_fpll.common.hw },
  903. };
  904. static const s8 clk_a53_parent2sel[] = {
  905. -1, /* osc */
  906. 0, /* mux 0: clk_tpll */
  907. 0, /* mux 0: clk_a0pll */
  908. 0, /* mux 0: clk_mipimpll */
  909. 0, /* mux 0: clk_mpll */
  910. 1 /* mux 1: clk_fpll */
  911. };
  912. static const u8 clk_a53_sel2parent[2][4] = {
  913. [0] = {
  914. 1,
  915. 2,
  916. 3,
  917. 4
  918. },
  919. [1] = {
  920. 5,
  921. 5,
  922. 5,
  923. 5
  924. },
  925. };
  926. /*
  927. * Clock for A53 cpu in the CV18XX/SG200X series.
  928. * For CV180X and CV181X series, this clock is not used, but can not
  929. * be set to bypass mode, or the SoC will hang.
  930. */
  931. static CV1800_MMUX(clk_a53, clk_a53_parents,
  932. REG_CLK_EN_0, 0,
  933. REG_DIV_CLK_A53_0, 16, 4, 1, CV1800_DIV_FLAG,
  934. REG_DIV_CLK_A53_1, 16, 4, 2, CV1800_DIV_FLAG,
  935. REG_DIV_CLK_A53_0, 8, 2,
  936. REG_DIV_CLK_A53_1, 8, 2,
  937. REG_CLK_BYP_0, 0,
  938. REG_CLK_SEL_0, 0,
  939. clk_a53_parent2sel,
  940. clk_a53_sel2parent[0], clk_a53_sel2parent[1],
  941. CLK_IS_CRITICAL | CLK_GET_RATE_NOCACHE);
  942. static struct clk_hw_onecell_data cv1800_hw_clks = {
  943. .num = CV1800_CLK_MAX,
  944. .hws = {
  945. [CLK_MPLL] = &clk_mpll.common.hw,
  946. [CLK_TPLL] = &clk_tpll.common.hw,
  947. [CLK_FPLL] = &clk_fpll.common.hw,
  948. [CLK_MIPIMPLL] = &clk_mipimpll.common.hw,
  949. [CLK_A0PLL] = &clk_a0pll.common.hw,
  950. [CLK_DISPPLL] = &clk_disppll.common.hw,
  951. [CLK_CAM0PLL] = &clk_cam0pll.common.hw,
  952. [CLK_CAM1PLL] = &clk_cam1pll.common.hw,
  953. [CLK_MIPIMPLL_D3] = &clk_mipimpll_d3.common.hw,
  954. [CLK_CAM0PLL_D2] = &clk_cam0pll_d2.common.hw,
  955. [CLK_CAM0PLL_D3] = &clk_cam0pll_d3.common.hw,
  956. [CLK_TPU] = &clk_tpu.mux.common.hw,
  957. [CLK_TPU_FAB] = &clk_tpu_fab.common.hw,
  958. [CLK_AHB_ROM] = &clk_ahb_rom.common.hw,
  959. [CLK_DDR_AXI_REG] = &clk_ddr_axi_reg.common.hw,
  960. [CLK_RTC_25M] = &clk_rtc_25m.common.hw,
  961. [CLK_SRC_RTC_SYS_0] = &clk_src_rtc_sys_0.div.common.hw,
  962. [CLK_TEMPSEN] = &clk_tempsen.common.hw,
  963. [CLK_SARADC] = &clk_saradc.common.hw,
  964. [CLK_EFUSE] = &clk_efuse.common.hw,
  965. [CLK_APB_EFUSE] = &clk_apb_efuse.common.hw,
  966. [CLK_DEBUG] = &clk_debug.common.hw,
  967. [CLK_AP_DEBUG] = &clk_ap_debug.div.common.hw,
  968. [CLK_XTAL_MISC] = &clk_xtal_misc.common.hw,
  969. [CLK_AXI4_EMMC] = &clk_axi4_emmc.common.hw,
  970. [CLK_EMMC] = &clk_emmc.mux.common.hw,
  971. [CLK_EMMC_100K] = &clk_emmc_100k.common.hw,
  972. [CLK_AXI4_SD0] = &clk_axi4_sd0.common.hw,
  973. [CLK_SD0] = &clk_sd0.mux.common.hw,
  974. [CLK_SD0_100K] = &clk_sd0_100k.common.hw,
  975. [CLK_AXI4_SD1] = &clk_axi4_sd1.common.hw,
  976. [CLK_SD1] = &clk_sd1.mux.common.hw,
  977. [CLK_SD1_100K] = &clk_sd1_100k.common.hw,
  978. [CLK_SPI_NAND] = &clk_spi_nand.mux.common.hw,
  979. [CLK_ETH0_500M] = &clk_eth0_500m.div.common.hw,
  980. [CLK_AXI4_ETH0] = &clk_axi4_eth0.common.hw,
  981. [CLK_ETH1_500M] = &clk_eth1_500m.div.common.hw,
  982. [CLK_AXI4_ETH1] = &clk_axi4_eth1.common.hw,
  983. [CLK_APB_GPIO] = &clk_apb_gpio.common.hw,
  984. [CLK_APB_GPIO_INTR] = &clk_apb_gpio_intr.common.hw,
  985. [CLK_GPIO_DB] = &clk_gpio_db.common.hw,
  986. [CLK_AHB_SF] = &clk_ahb_sf.common.hw,
  987. [CLK_AHB_SF1] = &clk_ahb_sf1.common.hw,
  988. [CLK_A24M] = &clk_a24m.common.hw,
  989. [CLK_AUDSRC] = &clk_audsrc.mux.common.hw,
  990. [CLK_APB_AUDSRC] = &clk_apb_audsrc.common.hw,
  991. [CLK_SDMA_AXI] = &clk_sdma_axi.common.hw,
  992. [CLK_SDMA_AUD0] = &clk_sdma_aud0.mux.common.hw,
  993. [CLK_SDMA_AUD1] = &clk_sdma_aud1.mux.common.hw,
  994. [CLK_SDMA_AUD2] = &clk_sdma_aud2.mux.common.hw,
  995. [CLK_SDMA_AUD3] = &clk_sdma_aud3.mux.common.hw,
  996. [CLK_I2C] = &clk_i2c.div.common.hw,
  997. [CLK_APB_I2C] = &clk_apb_i2c.common.hw,
  998. [CLK_APB_I2C0] = &clk_apb_i2c0.common.hw,
  999. [CLK_APB_I2C1] = &clk_apb_i2c1.common.hw,
  1000. [CLK_APB_I2C2] = &clk_apb_i2c2.common.hw,
  1001. [CLK_APB_I2C3] = &clk_apb_i2c3.common.hw,
  1002. [CLK_APB_I2C4] = &clk_apb_i2c4.common.hw,
  1003. [CLK_APB_WDT] = &clk_apb_wdt.common.hw,
  1004. [CLK_PWM_SRC] = &clk_pwm_src.mux.common.hw,
  1005. [CLK_PWM] = &clk_pwm.common.hw,
  1006. [CLK_SPI] = &clk_spi.div.common.hw,
  1007. [CLK_APB_SPI0] = &clk_apb_spi0.common.hw,
  1008. [CLK_APB_SPI1] = &clk_apb_spi1.common.hw,
  1009. [CLK_APB_SPI2] = &clk_apb_spi2.common.hw,
  1010. [CLK_APB_SPI3] = &clk_apb_spi3.common.hw,
  1011. [CLK_1M] = &clk_1m.common.hw,
  1012. [CLK_CAM0_200] = &clk_cam0_200.mux.common.hw,
  1013. [CLK_PM] = &clk_pm.common.hw,
  1014. [CLK_TIMER0] = &clk_timer0.common.hw,
  1015. [CLK_TIMER1] = &clk_timer1.common.hw,
  1016. [CLK_TIMER2] = &clk_timer2.common.hw,
  1017. [CLK_TIMER3] = &clk_timer3.common.hw,
  1018. [CLK_TIMER4] = &clk_timer4.common.hw,
  1019. [CLK_TIMER5] = &clk_timer5.common.hw,
  1020. [CLK_TIMER6] = &clk_timer6.common.hw,
  1021. [CLK_TIMER7] = &clk_timer7.common.hw,
  1022. [CLK_UART0] = &clk_uart0.common.hw,
  1023. [CLK_APB_UART0] = &clk_apb_uart0.common.hw,
  1024. [CLK_UART1] = &clk_uart1.common.hw,
  1025. [CLK_APB_UART1] = &clk_apb_uart1.common.hw,
  1026. [CLK_UART2] = &clk_uart2.common.hw,
  1027. [CLK_APB_UART2] = &clk_apb_uart2.common.hw,
  1028. [CLK_UART3] = &clk_uart3.common.hw,
  1029. [CLK_APB_UART3] = &clk_apb_uart3.common.hw,
  1030. [CLK_UART4] = &clk_uart4.common.hw,
  1031. [CLK_APB_UART4] = &clk_apb_uart4.common.hw,
  1032. [CLK_APB_I2S0] = &clk_apb_i2s0.common.hw,
  1033. [CLK_APB_I2S1] = &clk_apb_i2s1.common.hw,
  1034. [CLK_APB_I2S2] = &clk_apb_i2s2.common.hw,
  1035. [CLK_APB_I2S3] = &clk_apb_i2s3.common.hw,
  1036. [CLK_AXI4_USB] = &clk_axi4_usb.common.hw,
  1037. [CLK_APB_USB] = &clk_apb_usb.common.hw,
  1038. [CLK_USB_125M] = &clk_usb_125m.div.common.hw,
  1039. [CLK_USB_33K] = &clk_usb_33k.common.hw,
  1040. [CLK_USB_12M] = &clk_usb_12m.div.common.hw,
  1041. [CLK_AXI4] = &clk_axi4.mux.common.hw,
  1042. [CLK_AXI6] = &clk_axi6.div.common.hw,
  1043. [CLK_DSI_ESC] = &clk_dsi_esc.div.common.hw,
  1044. [CLK_AXI_VIP] = &clk_axi_vip.mux.common.hw,
  1045. [CLK_SRC_VIP_SYS_0] = &clk_src_vip_sys_0.mux.common.hw,
  1046. [CLK_SRC_VIP_SYS_1] = &clk_src_vip_sys_1.mux.common.hw,
  1047. [CLK_SRC_VIP_SYS_2] = &clk_src_vip_sys_2.mux.common.hw,
  1048. [CLK_SRC_VIP_SYS_3] = &clk_src_vip_sys_3.mux.common.hw,
  1049. [CLK_SRC_VIP_SYS_4] = &clk_src_vip_sys_4.mux.common.hw,
  1050. [CLK_CSI_BE_VIP] = &clk_csi_be_vip.common.hw,
  1051. [CLK_CSI_MAC0_VIP] = &clk_csi_mac0_vip.common.hw,
  1052. [CLK_CSI_MAC1_VIP] = &clk_csi_mac1_vip.common.hw,
  1053. [CLK_CSI_MAC2_VIP] = &clk_csi_mac2_vip.common.hw,
  1054. [CLK_CSI0_RX_VIP] = &clk_csi0_rx_vip.common.hw,
  1055. [CLK_CSI1_RX_VIP] = &clk_csi1_rx_vip.common.hw,
  1056. [CLK_ISP_TOP_VIP] = &clk_isp_top_vip.common.hw,
  1057. [CLK_IMG_D_VIP] = &clk_img_d_vip.common.hw,
  1058. [CLK_IMG_V_VIP] = &clk_img_v_vip.common.hw,
  1059. [CLK_SC_TOP_VIP] = &clk_sc_top_vip.common.hw,
  1060. [CLK_SC_D_VIP] = &clk_sc_d_vip.common.hw,
  1061. [CLK_SC_V1_VIP] = &clk_sc_v1_vip.common.hw,
  1062. [CLK_SC_V2_VIP] = &clk_sc_v2_vip.common.hw,
  1063. [CLK_SC_V3_VIP] = &clk_sc_v3_vip.common.hw,
  1064. [CLK_DWA_VIP] = &clk_dwa_vip.common.hw,
  1065. [CLK_BT_VIP] = &clk_bt_vip.common.hw,
  1066. [CLK_DISP_VIP] = &clk_disp_vip.common.hw,
  1067. [CLK_DSI_MAC_VIP] = &clk_dsi_mac_vip.common.hw,
  1068. [CLK_LVDS0_VIP] = &clk_lvds0_vip.common.hw,
  1069. [CLK_LVDS1_VIP] = &clk_lvds1_vip.common.hw,
  1070. [CLK_PAD_VI_VIP] = &clk_pad_vi_vip.common.hw,
  1071. [CLK_PAD_VI1_VIP] = &clk_pad_vi1_vip.common.hw,
  1072. [CLK_PAD_VI2_VIP] = &clk_pad_vi2_vip.common.hw,
  1073. [CLK_CFG_REG_VIP] = &clk_cfg_reg_vip.common.hw,
  1074. [CLK_VIP_IP0] = &clk_vip_ip0.common.hw,
  1075. [CLK_VIP_IP1] = &clk_vip_ip1.common.hw,
  1076. [CLK_VIP_IP2] = &clk_vip_ip2.common.hw,
  1077. [CLK_VIP_IP3] = &clk_vip_ip3.common.hw,
  1078. [CLK_IVE_VIP] = &clk_ive_vip.common.hw,
  1079. [CLK_RAW_VIP] = &clk_raw_vip.common.hw,
  1080. [CLK_OSDC_VIP] = &clk_osdc_vip.common.hw,
  1081. [CLK_CAM0_VIP] = &clk_cam0_vip.common.hw,
  1082. [CLK_AXI_VIDEO_CODEC] = &clk_axi_video_codec.mux.common.hw,
  1083. [CLK_VC_SRC0] = &clk_vc_src0.mux.common.hw,
  1084. [CLK_VC_SRC1] = &clk_vc_src1.div.common.hw,
  1085. [CLK_VC_SRC2] = &clk_vc_src2.div.common.hw,
  1086. [CLK_H264C] = &clk_h264c.common.hw,
  1087. [CLK_APB_H264C] = &clk_apb_h264c.common.hw,
  1088. [CLK_H265C] = &clk_h265c.common.hw,
  1089. [CLK_APB_H265C] = &clk_apb_h265c.common.hw,
  1090. [CLK_JPEG] = &clk_jpeg.common.hw,
  1091. [CLK_APB_JPEG] = &clk_apb_jpeg.common.hw,
  1092. [CLK_CAM0] = &clk_cam0.common.hw,
  1093. [CLK_CAM1] = &clk_cam1.common.hw,
  1094. [CLK_WGN] = &clk_wgn.common.hw,
  1095. [CLK_WGN0] = &clk_wgn0.common.hw,
  1096. [CLK_WGN1] = &clk_wgn1.common.hw,
  1097. [CLK_WGN2] = &clk_wgn2.common.hw,
  1098. [CLK_KEYSCAN] = &clk_keyscan.common.hw,
  1099. [CLK_CFG_REG_VC] = &clk_cfg_reg_vc.common.hw,
  1100. [CLK_C906_0] = &clk_c906_0.common.hw,
  1101. [CLK_C906_1] = &clk_c906_1.common.hw,
  1102. [CLK_A53] = &clk_a53.common.hw,
  1103. [CLK_CPU_AXI0] = &clk_cpu_axi0.div.common.hw,
  1104. [CLK_CPU_GIC] = &clk_cpu_gic.div.common.hw,
  1105. [CLK_XTAL_AP] = &clk_xtal_ap.common.hw,
  1106. },
  1107. };
  1108. static void cv18xx_clk_disable_auto_pd(void __iomem *base)
  1109. {
  1110. static const u16 CV1800_PD_CLK[] = {
  1111. REG_MIPIMPLL_CLK_CSR,
  1112. REG_A0PLL_CLK_CSR,
  1113. REG_DISPPLL_CLK_CSR,
  1114. REG_CAM0PLL_CLK_CSR,
  1115. REG_CAM1PLL_CLK_CSR,
  1116. };
  1117. u32 val;
  1118. int i;
  1119. /* disable auto power down */
  1120. for (i = 0; i < ARRAY_SIZE(CV1800_PD_CLK); i++) {
  1121. u32 reg = CV1800_PD_CLK[i];
  1122. val = readl(base + reg);
  1123. val |= GENMASK(12, 9);
  1124. val &= ~BIT(8);
  1125. writel(val, base + reg);
  1126. }
  1127. }
  1128. static void cv18xx_clk_disable_a53(void __iomem *base)
  1129. {
  1130. u32 val = readl(base + REG_CLK_BYP_0);
  1131. /* Set bypass clock for clk_a53 */
  1132. val |= BIT(0);
  1133. /* Set bypass clock for clk_cpu_axi0 */
  1134. val |= BIT(1);
  1135. /* Set bypass clock for clk_cpu_gic */
  1136. val |= BIT(2);
  1137. writel(val, base + REG_CLK_BYP_0);
  1138. }
  1139. static int cv1800_pre_init(struct device *dev, void __iomem *base,
  1140. struct cv1800_clk_ctrl *ctrl,
  1141. const struct cv1800_clk_desc *desc)
  1142. {
  1143. u32 val = readl(base + REG_CLK_EN_2);
  1144. /* disable unsupported clk_disp_src_vip */
  1145. val &= ~BIT(7);
  1146. writel(val, base + REG_CLK_EN_2);
  1147. cv18xx_clk_disable_a53(base);
  1148. cv18xx_clk_disable_auto_pd(base);
  1149. return 0;
  1150. }
  1151. static const struct cv1800_clk_desc cv1800_desc = {
  1152. .clks_data = &cv1800_hw_clks,
  1153. .pre_init = cv1800_pre_init,
  1154. };
  1155. static struct clk_hw_onecell_data cv1810_hw_clks = {
  1156. .num = CV1810_CLK_MAX,
  1157. .hws = {
  1158. [CLK_MPLL] = &clk_mpll.common.hw,
  1159. [CLK_TPLL] = &clk_tpll.common.hw,
  1160. [CLK_FPLL] = &clk_fpll.common.hw,
  1161. [CLK_MIPIMPLL] = &clk_mipimpll.common.hw,
  1162. [CLK_A0PLL] = &clk_a0pll.common.hw,
  1163. [CLK_DISPPLL] = &clk_disppll.common.hw,
  1164. [CLK_CAM0PLL] = &clk_cam0pll.common.hw,
  1165. [CLK_CAM1PLL] = &clk_cam1pll.common.hw,
  1166. [CLK_MIPIMPLL_D3] = &clk_mipimpll_d3.common.hw,
  1167. [CLK_CAM0PLL_D2] = &clk_cam0pll_d2.common.hw,
  1168. [CLK_CAM0PLL_D3] = &clk_cam0pll_d3.common.hw,
  1169. [CLK_TPU] = &clk_tpu.mux.common.hw,
  1170. [CLK_TPU_FAB] = &clk_tpu_fab.common.hw,
  1171. [CLK_AHB_ROM] = &clk_ahb_rom.common.hw,
  1172. [CLK_DDR_AXI_REG] = &clk_ddr_axi_reg.common.hw,
  1173. [CLK_RTC_25M] = &clk_rtc_25m.common.hw,
  1174. [CLK_SRC_RTC_SYS_0] = &clk_src_rtc_sys_0.div.common.hw,
  1175. [CLK_TEMPSEN] = &clk_tempsen.common.hw,
  1176. [CLK_SARADC] = &clk_saradc.common.hw,
  1177. [CLK_EFUSE] = &clk_efuse.common.hw,
  1178. [CLK_APB_EFUSE] = &clk_apb_efuse.common.hw,
  1179. [CLK_DEBUG] = &clk_debug.common.hw,
  1180. [CLK_AP_DEBUG] = &clk_ap_debug.div.common.hw,
  1181. [CLK_XTAL_MISC] = &clk_xtal_misc.common.hw,
  1182. [CLK_AXI4_EMMC] = &clk_axi4_emmc.common.hw,
  1183. [CLK_EMMC] = &clk_emmc.mux.common.hw,
  1184. [CLK_EMMC_100K] = &clk_emmc_100k.common.hw,
  1185. [CLK_AXI4_SD0] = &clk_axi4_sd0.common.hw,
  1186. [CLK_SD0] = &clk_sd0.mux.common.hw,
  1187. [CLK_SD0_100K] = &clk_sd0_100k.common.hw,
  1188. [CLK_AXI4_SD1] = &clk_axi4_sd1.common.hw,
  1189. [CLK_SD1] = &clk_sd1.mux.common.hw,
  1190. [CLK_SD1_100K] = &clk_sd1_100k.common.hw,
  1191. [CLK_SPI_NAND] = &clk_spi_nand.mux.common.hw,
  1192. [CLK_ETH0_500M] = &clk_eth0_500m.div.common.hw,
  1193. [CLK_AXI4_ETH0] = &clk_axi4_eth0.common.hw,
  1194. [CLK_ETH1_500M] = &clk_eth1_500m.div.common.hw,
  1195. [CLK_AXI4_ETH1] = &clk_axi4_eth1.common.hw,
  1196. [CLK_APB_GPIO] = &clk_apb_gpio.common.hw,
  1197. [CLK_APB_GPIO_INTR] = &clk_apb_gpio_intr.common.hw,
  1198. [CLK_GPIO_DB] = &clk_gpio_db.common.hw,
  1199. [CLK_AHB_SF] = &clk_ahb_sf.common.hw,
  1200. [CLK_AHB_SF1] = &clk_ahb_sf1.common.hw,
  1201. [CLK_A24M] = &clk_a24m.common.hw,
  1202. [CLK_AUDSRC] = &clk_audsrc.mux.common.hw,
  1203. [CLK_APB_AUDSRC] = &clk_apb_audsrc.common.hw,
  1204. [CLK_SDMA_AXI] = &clk_sdma_axi.common.hw,
  1205. [CLK_SDMA_AUD0] = &clk_sdma_aud0.mux.common.hw,
  1206. [CLK_SDMA_AUD1] = &clk_sdma_aud1.mux.common.hw,
  1207. [CLK_SDMA_AUD2] = &clk_sdma_aud2.mux.common.hw,
  1208. [CLK_SDMA_AUD3] = &clk_sdma_aud3.mux.common.hw,
  1209. [CLK_I2C] = &clk_i2c.div.common.hw,
  1210. [CLK_APB_I2C] = &clk_apb_i2c.common.hw,
  1211. [CLK_APB_I2C0] = &clk_apb_i2c0.common.hw,
  1212. [CLK_APB_I2C1] = &clk_apb_i2c1.common.hw,
  1213. [CLK_APB_I2C2] = &clk_apb_i2c2.common.hw,
  1214. [CLK_APB_I2C3] = &clk_apb_i2c3.common.hw,
  1215. [CLK_APB_I2C4] = &clk_apb_i2c4.common.hw,
  1216. [CLK_APB_WDT] = &clk_apb_wdt.common.hw,
  1217. [CLK_PWM_SRC] = &clk_pwm_src.mux.common.hw,
  1218. [CLK_PWM] = &clk_pwm.common.hw,
  1219. [CLK_SPI] = &clk_spi.div.common.hw,
  1220. [CLK_APB_SPI0] = &clk_apb_spi0.common.hw,
  1221. [CLK_APB_SPI1] = &clk_apb_spi1.common.hw,
  1222. [CLK_APB_SPI2] = &clk_apb_spi2.common.hw,
  1223. [CLK_APB_SPI3] = &clk_apb_spi3.common.hw,
  1224. [CLK_1M] = &clk_1m.common.hw,
  1225. [CLK_CAM0_200] = &clk_cam0_200.mux.common.hw,
  1226. [CLK_PM] = &clk_pm.common.hw,
  1227. [CLK_TIMER0] = &clk_timer0.common.hw,
  1228. [CLK_TIMER1] = &clk_timer1.common.hw,
  1229. [CLK_TIMER2] = &clk_timer2.common.hw,
  1230. [CLK_TIMER3] = &clk_timer3.common.hw,
  1231. [CLK_TIMER4] = &clk_timer4.common.hw,
  1232. [CLK_TIMER5] = &clk_timer5.common.hw,
  1233. [CLK_TIMER6] = &clk_timer6.common.hw,
  1234. [CLK_TIMER7] = &clk_timer7.common.hw,
  1235. [CLK_UART0] = &clk_uart0.common.hw,
  1236. [CLK_APB_UART0] = &clk_apb_uart0.common.hw,
  1237. [CLK_UART1] = &clk_uart1.common.hw,
  1238. [CLK_APB_UART1] = &clk_apb_uart1.common.hw,
  1239. [CLK_UART2] = &clk_uart2.common.hw,
  1240. [CLK_APB_UART2] = &clk_apb_uart2.common.hw,
  1241. [CLK_UART3] = &clk_uart3.common.hw,
  1242. [CLK_APB_UART3] = &clk_apb_uart3.common.hw,
  1243. [CLK_UART4] = &clk_uart4.common.hw,
  1244. [CLK_APB_UART4] = &clk_apb_uart4.common.hw,
  1245. [CLK_APB_I2S0] = &clk_apb_i2s0.common.hw,
  1246. [CLK_APB_I2S1] = &clk_apb_i2s1.common.hw,
  1247. [CLK_APB_I2S2] = &clk_apb_i2s2.common.hw,
  1248. [CLK_APB_I2S3] = &clk_apb_i2s3.common.hw,
  1249. [CLK_AXI4_USB] = &clk_axi4_usb.common.hw,
  1250. [CLK_APB_USB] = &clk_apb_usb.common.hw,
  1251. [CLK_USB_125M] = &clk_usb_125m.div.common.hw,
  1252. [CLK_USB_33K] = &clk_usb_33k.common.hw,
  1253. [CLK_USB_12M] = &clk_usb_12m.div.common.hw,
  1254. [CLK_AXI4] = &clk_axi4.mux.common.hw,
  1255. [CLK_AXI6] = &clk_axi6.div.common.hw,
  1256. [CLK_DSI_ESC] = &clk_dsi_esc.div.common.hw,
  1257. [CLK_AXI_VIP] = &clk_axi_vip.mux.common.hw,
  1258. [CLK_SRC_VIP_SYS_0] = &clk_src_vip_sys_0.mux.common.hw,
  1259. [CLK_SRC_VIP_SYS_1] = &clk_src_vip_sys_1.mux.common.hw,
  1260. [CLK_SRC_VIP_SYS_2] = &clk_src_vip_sys_2.mux.common.hw,
  1261. [CLK_SRC_VIP_SYS_3] = &clk_src_vip_sys_3.mux.common.hw,
  1262. [CLK_SRC_VIP_SYS_4] = &clk_src_vip_sys_4.mux.common.hw,
  1263. [CLK_CSI_BE_VIP] = &clk_csi_be_vip.common.hw,
  1264. [CLK_CSI_MAC0_VIP] = &clk_csi_mac0_vip.common.hw,
  1265. [CLK_CSI_MAC1_VIP] = &clk_csi_mac1_vip.common.hw,
  1266. [CLK_CSI_MAC2_VIP] = &clk_csi_mac2_vip.common.hw,
  1267. [CLK_CSI0_RX_VIP] = &clk_csi0_rx_vip.common.hw,
  1268. [CLK_CSI1_RX_VIP] = &clk_csi1_rx_vip.common.hw,
  1269. [CLK_ISP_TOP_VIP] = &clk_isp_top_vip.common.hw,
  1270. [CLK_IMG_D_VIP] = &clk_img_d_vip.common.hw,
  1271. [CLK_IMG_V_VIP] = &clk_img_v_vip.common.hw,
  1272. [CLK_SC_TOP_VIP] = &clk_sc_top_vip.common.hw,
  1273. [CLK_SC_D_VIP] = &clk_sc_d_vip.common.hw,
  1274. [CLK_SC_V1_VIP] = &clk_sc_v1_vip.common.hw,
  1275. [CLK_SC_V2_VIP] = &clk_sc_v2_vip.common.hw,
  1276. [CLK_SC_V3_VIP] = &clk_sc_v3_vip.common.hw,
  1277. [CLK_DWA_VIP] = &clk_dwa_vip.common.hw,
  1278. [CLK_BT_VIP] = &clk_bt_vip.common.hw,
  1279. [CLK_DISP_VIP] = &clk_disp_vip.common.hw,
  1280. [CLK_DSI_MAC_VIP] = &clk_dsi_mac_vip.common.hw,
  1281. [CLK_LVDS0_VIP] = &clk_lvds0_vip.common.hw,
  1282. [CLK_LVDS1_VIP] = &clk_lvds1_vip.common.hw,
  1283. [CLK_PAD_VI_VIP] = &clk_pad_vi_vip.common.hw,
  1284. [CLK_PAD_VI1_VIP] = &clk_pad_vi1_vip.common.hw,
  1285. [CLK_PAD_VI2_VIP] = &clk_pad_vi2_vip.common.hw,
  1286. [CLK_CFG_REG_VIP] = &clk_cfg_reg_vip.common.hw,
  1287. [CLK_VIP_IP0] = &clk_vip_ip0.common.hw,
  1288. [CLK_VIP_IP1] = &clk_vip_ip1.common.hw,
  1289. [CLK_VIP_IP2] = &clk_vip_ip2.common.hw,
  1290. [CLK_VIP_IP3] = &clk_vip_ip3.common.hw,
  1291. [CLK_IVE_VIP] = &clk_ive_vip.common.hw,
  1292. [CLK_RAW_VIP] = &clk_raw_vip.common.hw,
  1293. [CLK_OSDC_VIP] = &clk_osdc_vip.common.hw,
  1294. [CLK_CAM0_VIP] = &clk_cam0_vip.common.hw,
  1295. [CLK_AXI_VIDEO_CODEC] = &clk_axi_video_codec.mux.common.hw,
  1296. [CLK_VC_SRC0] = &clk_vc_src0.mux.common.hw,
  1297. [CLK_VC_SRC1] = &clk_vc_src1.div.common.hw,
  1298. [CLK_VC_SRC2] = &clk_vc_src2.div.common.hw,
  1299. [CLK_H264C] = &clk_h264c.common.hw,
  1300. [CLK_APB_H264C] = &clk_apb_h264c.common.hw,
  1301. [CLK_H265C] = &clk_h265c.common.hw,
  1302. [CLK_APB_H265C] = &clk_apb_h265c.common.hw,
  1303. [CLK_JPEG] = &clk_jpeg.common.hw,
  1304. [CLK_APB_JPEG] = &clk_apb_jpeg.common.hw,
  1305. [CLK_CAM0] = &clk_cam0.common.hw,
  1306. [CLK_CAM1] = &clk_cam1.common.hw,
  1307. [CLK_WGN] = &clk_wgn.common.hw,
  1308. [CLK_WGN0] = &clk_wgn0.common.hw,
  1309. [CLK_WGN1] = &clk_wgn1.common.hw,
  1310. [CLK_WGN2] = &clk_wgn2.common.hw,
  1311. [CLK_KEYSCAN] = &clk_keyscan.common.hw,
  1312. [CLK_CFG_REG_VC] = &clk_cfg_reg_vc.common.hw,
  1313. [CLK_C906_0] = &clk_c906_0.common.hw,
  1314. [CLK_C906_1] = &clk_c906_1.common.hw,
  1315. [CLK_A53] = &clk_a53.common.hw,
  1316. [CLK_CPU_AXI0] = &clk_cpu_axi0.div.common.hw,
  1317. [CLK_CPU_GIC] = &clk_cpu_gic.div.common.hw,
  1318. [CLK_XTAL_AP] = &clk_xtal_ap.common.hw,
  1319. [CLK_DISP_SRC_VIP] = &clk_disp_src_vip.div.common.hw,
  1320. },
  1321. };
  1322. static int cv1810_pre_init(struct device *dev, void __iomem *base,
  1323. struct cv1800_clk_ctrl *ctrl,
  1324. const struct cv1800_clk_desc *desc)
  1325. {
  1326. cv18xx_clk_disable_a53(base);
  1327. cv18xx_clk_disable_auto_pd(base);
  1328. return 0;
  1329. }
  1330. static const struct cv1800_clk_desc cv1810_desc = {
  1331. .clks_data = &cv1810_hw_clks,
  1332. .pre_init = cv1810_pre_init,
  1333. };
  1334. static int sg2000_pre_init(struct device *dev, void __iomem *base,
  1335. struct cv1800_clk_ctrl *ctrl,
  1336. const struct cv1800_clk_desc *desc)
  1337. {
  1338. cv18xx_clk_disable_auto_pd(base);
  1339. return 0;
  1340. }
  1341. static const struct cv1800_clk_desc sg2000_desc = {
  1342. .clks_data = &cv1810_hw_clks,
  1343. .pre_init = sg2000_pre_init,
  1344. };
  1345. static int cv1800_clk_init_ctrl(struct device *dev, void __iomem *reg,
  1346. struct cv1800_clk_ctrl *ctrl,
  1347. const struct cv1800_clk_desc *desc)
  1348. {
  1349. int i, ret;
  1350. ctrl->desc = desc;
  1351. spin_lock_init(&ctrl->lock);
  1352. for (i = 0; i < desc->clks_data->num; i++) {
  1353. struct clk_hw *hw = desc->clks_data->hws[i];
  1354. struct cv1800_clk_common *common;
  1355. const char *name;
  1356. if (!hw)
  1357. continue;
  1358. name = hw->init->name;
  1359. common = hw_to_cv1800_clk_common(hw);
  1360. common->base = reg;
  1361. common->lock = &ctrl->lock;
  1362. ret = devm_clk_hw_register(dev, hw);
  1363. if (ret) {
  1364. dev_err(dev, "Couldn't register clock %d - %s\n",
  1365. i, name);
  1366. return ret;
  1367. }
  1368. }
  1369. return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
  1370. desc->clks_data);
  1371. }
  1372. static int cv1800_clk_probe(struct platform_device *pdev)
  1373. {
  1374. struct device *dev = &pdev->dev;
  1375. void __iomem *reg;
  1376. int ret;
  1377. const struct cv1800_clk_desc *desc;
  1378. struct cv1800_clk_ctrl *ctrl;
  1379. reg = devm_platform_ioremap_resource(pdev, 0);
  1380. if (IS_ERR(reg))
  1381. return PTR_ERR(reg);
  1382. desc = device_get_match_data(dev);
  1383. if (!desc) {
  1384. dev_err(dev, "no match data for platform\n");
  1385. return -EINVAL;
  1386. }
  1387. ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL);
  1388. if (!ctrl)
  1389. return -ENOMEM;
  1390. if (desc->pre_init) {
  1391. ret = desc->pre_init(dev, reg, ctrl, desc);
  1392. if (ret)
  1393. return ret;
  1394. }
  1395. return cv1800_clk_init_ctrl(dev, reg, ctrl, desc);
  1396. }
  1397. static const struct of_device_id cv1800_clk_ids[] = {
  1398. { .compatible = "sophgo,cv1800-clk", .data = &cv1800_desc },
  1399. { .compatible = "sophgo,cv1810-clk", .data = &cv1810_desc },
  1400. { .compatible = "sophgo,sg2000-clk", .data = &sg2000_desc },
  1401. { }
  1402. };
  1403. MODULE_DEVICE_TABLE(of, cv1800_clk_ids);
  1404. static struct platform_driver cv1800_clk_driver = {
  1405. .probe = cv1800_clk_probe,
  1406. .driver = {
  1407. .name = "cv1800-clk",
  1408. .suppress_bind_attrs = true,
  1409. .of_match_table = cv1800_clk_ids,
  1410. },
  1411. };
  1412. module_platform_driver(cv1800_clk_driver);
  1413. MODULE_DESCRIPTION("Sophgo CV1800 series SoCs clock controller");
  1414. MODULE_LICENSE("GPL");