clk-common.c 21 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. /*
  2. * common clks module for all SiRF SoCs
  3. *
  4. * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
  5. *
  6. * Licensed under GPLv2 or later.
  7. */
  8. #define KHZ 1000
  9. #define MHZ (KHZ * KHZ)
  10. static void *sirfsoc_clk_vbase;
  11. static void *sirfsoc_rsc_vbase;
  12. static struct clk_onecell_data clk_data;
  13. /*
  14. * SiRFprimaII clock controller
  15. * - 2 oscillators: osc-26MHz, rtc-32.768KHz
  16. * - 3 standard configurable plls: pll1, pll2 & pll3
  17. * - 2 exclusive plls: usb phy pll and sata phy pll
  18. * - 8 clock domains: cpu/cpudiv, mem/memdiv, sys/io, dsp, graphic, multimedia,
  19. * display and sdphy.
  20. * Each clock domain can select its own clock source from five clock sources,
  21. * X_XIN, X_XINW, PLL1, PLL2 and PLL3. The domain clock is used as the source
  22. * clock of the group clock.
  23. * - dsp domain: gps, mf
  24. * - io domain: dmac, nand, audio, uart, i2c, spi, usp, pwm, pulse
  25. * - sys domain: security
  26. */
  27. struct clk_pll {
  28. struct clk_hw hw;
  29. unsigned short regofs; /* register offset */
  30. };
  31. #define to_pllclk(_hw) container_of(_hw, struct clk_pll, hw)
  32. struct clk_dmn {
  33. struct clk_hw hw;
  34. signed char enable_bit; /* enable bit: 0 ~ 63 */
  35. unsigned short regofs; /* register offset */
  36. };
  37. #define to_dmnclk(_hw) container_of(_hw, struct clk_dmn, hw)
  38. struct clk_std {
  39. struct clk_hw hw;
  40. signed char enable_bit; /* enable bit: 0 ~ 63 */
  41. };
  42. #define to_stdclk(_hw) container_of(_hw, struct clk_std, hw)
  43. static int std_clk_is_enabled(struct clk_hw *hw);
  44. static int std_clk_enable(struct clk_hw *hw);
  45. static void std_clk_disable(struct clk_hw *hw);
  46. static inline unsigned long clkc_readl(unsigned reg)
  47. {
  48. return readl(sirfsoc_clk_vbase + reg);
  49. }
  50. static inline void clkc_writel(u32 val, unsigned reg)
  51. {
  52. writel(val, sirfsoc_clk_vbase + reg);
  53. }
  54. /*
  55. * std pll
  56. */
  57. static unsigned long pll_clk_recalc_rate(struct clk_hw *hw,
  58. unsigned long parent_rate)
  59. {
  60. unsigned long fin = parent_rate;
  61. struct clk_pll *clk = to_pllclk(hw);
  62. u32 regcfg2 = clk->regofs + SIRFSOC_CLKC_PLL1_CFG2 -
  63. SIRFSOC_CLKC_PLL1_CFG0;
  64. if (clkc_readl(regcfg2) & BIT(2)) {
  65. /* pll bypass mode */
  66. return fin;
  67. } else {
  68. /* fout = fin * nf / nr / od */
  69. u32 cfg0 = clkc_readl(clk->regofs);
  70. u32 nf = (cfg0 & (BIT(13) - 1)) + 1;
  71. u32 nr = ((cfg0 >> 13) & (BIT(6) - 1)) + 1;
  72. u32 od = ((cfg0 >> 19) & (BIT(4) - 1)) + 1;
  73. WARN_ON(fin % MHZ);
  74. return fin / MHZ * nf / nr / od * MHZ;
  75. }
  76. }
  77. static long pll_clk_round_rate(struct clk_hw *hw, unsigned long rate,
  78. unsigned long *parent_rate)
  79. {
  80. unsigned long fin, nf, nr, od;
  81. u64 dividend;
  82. /*
  83. * fout = fin * nf / (nr * od);
  84. * set od = 1, nr = fin/MHz, so fout = nf * MHz
  85. */
  86. rate = rate - rate % MHZ;
  87. nf = rate / MHZ;
  88. if (nf > BIT(13))
  89. nf = BIT(13);
  90. if (nf < 1)
  91. nf = 1;
  92. fin = *parent_rate;
  93. nr = fin / MHZ;
  94. if (nr > BIT(6))
  95. nr = BIT(6);
  96. od = 1;
  97. dividend = (u64)fin * nf;
  98. do_div(dividend, nr * od);
  99. return (long)dividend;
  100. }
  101. static int pll_clk_set_rate(struct clk_hw *hw, unsigned long rate,
  102. unsigned long parent_rate)
  103. {
  104. struct clk_pll *clk = to_pllclk(hw);
  105. unsigned long fin, nf, nr, od, reg;
  106. /*
  107. * fout = fin * nf / (nr * od);
  108. * set od = 1, nr = fin/MHz, so fout = nf * MHz
  109. */
  110. nf = rate / MHZ;
  111. if (unlikely((rate % MHZ) || nf > BIT(13) || nf < 1))
  112. return -EINVAL;
  113. fin = parent_rate;
  114. BUG_ON(fin < MHZ);
  115. nr = fin / MHZ;
  116. BUG_ON((fin % MHZ) || nr > BIT(6));
  117. od = 1;
  118. reg = (nf - 1) | ((nr - 1) << 13) | ((od - 1) << 19);
  119. clkc_writel(reg, clk->regofs);
  120. reg = clk->regofs + SIRFSOC_CLKC_PLL1_CFG1 - SIRFSOC_CLKC_PLL1_CFG0;
  121. clkc_writel((nf >> 1) - 1, reg);
  122. reg = clk->regofs + SIRFSOC_CLKC_PLL1_CFG2 - SIRFSOC_CLKC_PLL1_CFG0;
  123. while (!(clkc_readl(reg) & BIT(6)))
  124. cpu_relax();
  125. return 0;
  126. }
  127. static long cpu_clk_round_rate(struct clk_hw *hw, unsigned long rate,
  128. unsigned long *parent_rate)
  129. {
  130. /*
  131. * SiRF SoC has not cpu clock control,
  132. * So bypass to it's parent pll.
  133. */
  134. struct clk *parent_clk = clk_get_parent(hw->clk);
  135. struct clk *pll_parent_clk = clk_get_parent(parent_clk);
  136. unsigned long pll_parent_rate = clk_get_rate(pll_parent_clk);
  137. return pll_clk_round_rate(__clk_get_hw(parent_clk), rate, &pll_parent_rate);
  138. }
  139. static unsigned long cpu_clk_recalc_rate(struct clk_hw *hw,
  140. unsigned long parent_rate)
  141. {
  142. /*
  143. * SiRF SoC has not cpu clock control,
  144. * So return the parent pll rate.
  145. */
  146. struct clk *parent_clk = clk_get_parent(hw->clk);
  147. return __clk_get_rate(parent_clk);
  148. }
  149. static struct clk_ops std_pll_ops = {
  150. .recalc_rate = pll_clk_recalc_rate,
  151. .round_rate = pll_clk_round_rate,
  152. .set_rate = pll_clk_set_rate,
  153. };
  154. static const char *pll_clk_parents[] = {
  155. "osc",
  156. };
  157. static struct clk_init_data clk_pll1_init = {
  158. .name = "pll1",
  159. .ops = &std_pll_ops,
  160. .parent_names = pll_clk_parents,
  161. .num_parents = ARRAY_SIZE(pll_clk_parents),
  162. };
  163. static struct clk_init_data clk_pll2_init = {
  164. .name = "pll2",
  165. .ops = &std_pll_ops,
  166. .parent_names = pll_clk_parents,
  167. .num_parents = ARRAY_SIZE(pll_clk_parents),
  168. };
  169. static struct clk_init_data clk_pll3_init = {
  170. .name = "pll3",
  171. .ops = &std_pll_ops,
  172. .parent_names = pll_clk_parents,
  173. .num_parents = ARRAY_SIZE(pll_clk_parents),
  174. };
  175. static struct clk_pll clk_pll1 = {
  176. .regofs = SIRFSOC_CLKC_PLL1_CFG0,
  177. .hw = {
  178. .init = &clk_pll1_init,
  179. },
  180. };
  181. static struct clk_pll clk_pll2 = {
  182. .regofs = SIRFSOC_CLKC_PLL2_CFG0,
  183. .hw = {
  184. .init = &clk_pll2_init,
  185. },
  186. };
  187. static struct clk_pll clk_pll3 = {
  188. .regofs = SIRFSOC_CLKC_PLL3_CFG0,
  189. .hw = {
  190. .init = &clk_pll3_init,
  191. },
  192. };
  193. /*
  194. * usb uses specified pll
  195. */
  196. static int usb_pll_clk_enable(struct clk_hw *hw)
  197. {
  198. u32 reg = readl(sirfsoc_rsc_vbase + SIRFSOC_USBPHY_PLL_CTRL);
  199. reg &= ~(SIRFSOC_USBPHY_PLL_POWERDOWN | SIRFSOC_USBPHY_PLL_BYPASS);
  200. writel(reg, sirfsoc_rsc_vbase + SIRFSOC_USBPHY_PLL_CTRL);
  201. while (!(readl(sirfsoc_rsc_vbase + SIRFSOC_USBPHY_PLL_CTRL) &
  202. SIRFSOC_USBPHY_PLL_LOCK))
  203. cpu_relax();
  204. return 0;
  205. }
  206. static void usb_pll_clk_disable(struct clk_hw *clk)
  207. {
  208. u32 reg = readl(sirfsoc_rsc_vbase + SIRFSOC_USBPHY_PLL_CTRL);
  209. reg |= (SIRFSOC_USBPHY_PLL_POWERDOWN | SIRFSOC_USBPHY_PLL_BYPASS);
  210. writel(reg, sirfsoc_rsc_vbase + SIRFSOC_USBPHY_PLL_CTRL);
  211. }
  212. static unsigned long usb_pll_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
  213. {
  214. u32 reg = readl(sirfsoc_rsc_vbase + SIRFSOC_USBPHY_PLL_CTRL);
  215. return (reg & SIRFSOC_USBPHY_PLL_BYPASS) ? parent_rate : 48*MHZ;
  216. }
  217. static struct clk_ops usb_pll_ops = {
  218. .enable = usb_pll_clk_enable,
  219. .disable = usb_pll_clk_disable,
  220. .recalc_rate = usb_pll_clk_recalc_rate,
  221. };
  222. static struct clk_init_data clk_usb_pll_init = {
  223. .name = "usb_pll",
  224. .ops = &usb_pll_ops,
  225. .parent_names = pll_clk_parents,
  226. .num_parents = ARRAY_SIZE(pll_clk_parents),
  227. };
  228. static struct clk_hw usb_pll_clk_hw = {
  229. .init = &clk_usb_pll_init,
  230. };
  231. /*
  232. * clock domains - cpu, mem, sys/io, dsp, gfx
  233. */
  234. static const char *dmn_clk_parents[] = {
  235. "rtc",
  236. "osc",
  237. "pll1",
  238. "pll2",
  239. "pll3",
  240. };
  241. static u8 dmn_clk_get_parent(struct clk_hw *hw)
  242. {
  243. struct clk_dmn *clk = to_dmnclk(hw);
  244. u32 cfg = clkc_readl(clk->regofs);
  245. /* parent of io domain can only be pll3 */
  246. if (strcmp(hw->init->name, "io") == 0)
  247. return 4;
  248. WARN_ON((cfg & (BIT(3) - 1)) > 4);
  249. return cfg & (BIT(3) - 1);
  250. }
  251. static int dmn_clk_set_parent(struct clk_hw *hw, u8 parent)
  252. {
  253. struct clk_dmn *clk = to_dmnclk(hw);
  254. u32 cfg = clkc_readl(clk->regofs);
  255. /* parent of io domain can only be pll3 */
  256. if (strcmp(hw->init->name, "io") == 0)
  257. return -EINVAL;
  258. cfg &= ~(BIT(3) - 1);
  259. clkc_writel(cfg | parent, clk->regofs);
  260. /* BIT(3) - switching status: 1 - busy, 0 - done */
  261. while (clkc_readl(clk->regofs) & BIT(3))
  262. cpu_relax();
  263. return 0;
  264. }
  265. static unsigned long dmn_clk_recalc_rate(struct clk_hw *hw,
  266. unsigned long parent_rate)
  267. {
  268. unsigned long fin = parent_rate;
  269. struct clk_dmn *clk = to_dmnclk(hw);
  270. u32 cfg = clkc_readl(clk->regofs);
  271. if (cfg & BIT(24)) {
  272. /* fcd bypass mode */
  273. return fin;
  274. } else {
  275. /*
  276. * wait count: bit[19:16], hold count: bit[23:20]
  277. */
  278. u32 wait = (cfg >> 16) & (BIT(4) - 1);
  279. u32 hold = (cfg >> 20) & (BIT(4) - 1);
  280. return fin / (wait + hold + 2);
  281. }
  282. }
  283. static long dmn_clk_round_rate(struct clk_hw *hw, unsigned long rate,
  284. unsigned long *parent_rate)
  285. {
  286. unsigned long fin;
  287. unsigned ratio, wait, hold;
  288. unsigned bits = (strcmp(hw->init->name, "mem") == 0) ? 3 : 4;
  289. fin = *parent_rate;
  290. ratio = fin / rate;
  291. if (ratio < 2)
  292. ratio = 2;
  293. if (ratio > BIT(bits + 1))
  294. ratio = BIT(bits + 1);
  295. wait = (ratio >> 1) - 1;
  296. hold = ratio - wait - 2;
  297. return fin / (wait + hold + 2);
  298. }
  299. static int dmn_clk_set_rate(struct clk_hw *hw, unsigned long rate,
  300. unsigned long parent_rate)
  301. {
  302. struct clk_dmn *clk = to_dmnclk(hw);
  303. unsigned long fin;
  304. unsigned ratio, wait, hold, reg;
  305. unsigned bits = (strcmp(hw->init->name, "mem") == 0) ? 3 : 4;
  306. fin = parent_rate;
  307. ratio = fin / rate;
  308. if (unlikely(ratio < 2 || ratio > BIT(bits + 1)))
  309. return -EINVAL;
  310. WARN_ON(fin % rate);
  311. wait = (ratio >> 1) - 1;
  312. hold = ratio - wait - 2;
  313. reg = clkc_readl(clk->regofs);
  314. reg &= ~(((BIT(bits) - 1) << 16) | ((BIT(bits) - 1) << 20));
  315. reg |= (wait << 16) | (hold << 20) | BIT(25);
  316. clkc_writel(reg, clk->regofs);
  317. /* waiting FCD been effective */
  318. while (clkc_readl(clk->regofs) & BIT(25))
  319. cpu_relax();
  320. return 0;
  321. }
  322. static int cpu_clk_set_rate(struct clk_hw *hw, unsigned long rate,
  323. unsigned long parent_rate)
  324. {
  325. int ret1, ret2;
  326. struct clk *cur_parent;
  327. if (rate == clk_get_rate(clk_pll1.hw.clk)) {
  328. ret1 = clk_set_parent(hw->clk, clk_pll1.hw.clk);
  329. return ret1;
  330. }
  331. if (rate == clk_get_rate(clk_pll2.hw.clk)) {
  332. ret1 = clk_set_parent(hw->clk, clk_pll2.hw.clk);
  333. return ret1;
  334. }
  335. if (rate == clk_get_rate(clk_pll3.hw.clk)) {
  336. ret1 = clk_set_parent(hw->clk, clk_pll3.hw.clk);
  337. return ret1;
  338. }
  339. cur_parent = clk_get_parent(hw->clk);
  340. /* switch to tmp pll before setting parent clock's rate */
  341. if (cur_parent == clk_pll1.hw.clk) {
  342. ret1 = clk_set_parent(hw->clk, clk_pll2.hw.clk);
  343. BUG_ON(ret1);
  344. }
  345. ret2 = clk_set_rate(clk_pll1.hw.clk, rate);
  346. ret1 = clk_set_parent(hw->clk, clk_pll1.hw.clk);
  347. return ret2 ? ret2 : ret1;
  348. }
  349. static struct clk_ops msi_ops = {
  350. .set_rate = dmn_clk_set_rate,
  351. .round_rate = dmn_clk_round_rate,
  352. .recalc_rate = dmn_clk_recalc_rate,
  353. .set_parent = dmn_clk_set_parent,
  354. .get_parent = dmn_clk_get_parent,
  355. };
  356. static struct clk_init_data clk_mem_init = {
  357. .name = "mem",
  358. .ops = &msi_ops,
  359. .parent_names = dmn_clk_parents,
  360. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  361. };
  362. static struct clk_dmn clk_mem = {
  363. .regofs = SIRFSOC_CLKC_MEM_CFG,
  364. .hw = {
  365. .init = &clk_mem_init,
  366. },
  367. };
  368. static struct clk_init_data clk_sys_init = {
  369. .name = "sys",
  370. .ops = &msi_ops,
  371. .parent_names = dmn_clk_parents,
  372. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  373. .flags = CLK_SET_RATE_GATE,
  374. };
  375. static struct clk_dmn clk_sys = {
  376. .regofs = SIRFSOC_CLKC_SYS_CFG,
  377. .hw = {
  378. .init = &clk_sys_init,
  379. },
  380. };
  381. static struct clk_init_data clk_io_init = {
  382. .name = "io",
  383. .ops = &msi_ops,
  384. .parent_names = dmn_clk_parents,
  385. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  386. };
  387. static struct clk_dmn clk_io = {
  388. .regofs = SIRFSOC_CLKC_IO_CFG,
  389. .hw = {
  390. .init = &clk_io_init,
  391. },
  392. };
  393. static struct clk_ops cpu_ops = {
  394. .set_parent = dmn_clk_set_parent,
  395. .get_parent = dmn_clk_get_parent,
  396. .set_rate = cpu_clk_set_rate,
  397. .round_rate = cpu_clk_round_rate,
  398. .recalc_rate = cpu_clk_recalc_rate,
  399. };
  400. static struct clk_init_data clk_cpu_init = {
  401. .name = "cpu",
  402. .ops = &cpu_ops,
  403. .parent_names = dmn_clk_parents,
  404. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  405. .flags = CLK_SET_RATE_PARENT,
  406. };
  407. static struct clk_dmn clk_cpu = {
  408. .regofs = SIRFSOC_CLKC_CPU_CFG,
  409. .hw = {
  410. .init = &clk_cpu_init,
  411. },
  412. };
  413. static struct clk_ops dmn_ops = {
  414. .is_enabled = std_clk_is_enabled,
  415. .enable = std_clk_enable,
  416. .disable = std_clk_disable,
  417. .set_rate = dmn_clk_set_rate,
  418. .round_rate = dmn_clk_round_rate,
  419. .recalc_rate = dmn_clk_recalc_rate,
  420. .set_parent = dmn_clk_set_parent,
  421. .get_parent = dmn_clk_get_parent,
  422. };
  423. /* dsp, gfx, mm, lcd and vpp domain */
  424. static struct clk_init_data clk_dsp_init = {
  425. .name = "dsp",
  426. .ops = &dmn_ops,
  427. .parent_names = dmn_clk_parents,
  428. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  429. };
  430. static struct clk_dmn clk_dsp = {
  431. .regofs = SIRFSOC_CLKC_DSP_CFG,
  432. .enable_bit = 0,
  433. .hw = {
  434. .init = &clk_dsp_init,
  435. },
  436. };
  437. static struct clk_init_data clk_gfx_init = {
  438. .name = "gfx",
  439. .ops = &dmn_ops,
  440. .parent_names = dmn_clk_parents,
  441. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  442. };
  443. static struct clk_dmn clk_gfx = {
  444. .regofs = SIRFSOC_CLKC_GFX_CFG,
  445. .enable_bit = 8,
  446. .hw = {
  447. .init = &clk_gfx_init,
  448. },
  449. };
  450. static struct clk_init_data clk_mm_init = {
  451. .name = "mm",
  452. .ops = &dmn_ops,
  453. .parent_names = dmn_clk_parents,
  454. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  455. };
  456. static struct clk_dmn clk_mm = {
  457. .regofs = SIRFSOC_CLKC_MM_CFG,
  458. .enable_bit = 9,
  459. .hw = {
  460. .init = &clk_mm_init,
  461. },
  462. };
  463. /*
  464. * for atlas6, gfx2d holds the bit of prima2's clk_mm
  465. */
  466. #define clk_gfx2d clk_mm
  467. static struct clk_init_data clk_lcd_init = {
  468. .name = "lcd",
  469. .ops = &dmn_ops,
  470. .parent_names = dmn_clk_parents,
  471. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  472. };
  473. static struct clk_dmn clk_lcd = {
  474. .regofs = SIRFSOC_CLKC_LCD_CFG,
  475. .enable_bit = 10,
  476. .hw = {
  477. .init = &clk_lcd_init,
  478. },
  479. };
  480. static struct clk_init_data clk_vpp_init = {
  481. .name = "vpp",
  482. .ops = &dmn_ops,
  483. .parent_names = dmn_clk_parents,
  484. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  485. };
  486. static struct clk_dmn clk_vpp = {
  487. .regofs = SIRFSOC_CLKC_LCD_CFG,
  488. .enable_bit = 11,
  489. .hw = {
  490. .init = &clk_vpp_init,
  491. },
  492. };
  493. static struct clk_init_data clk_mmc01_init = {
  494. .name = "mmc01",
  495. .ops = &dmn_ops,
  496. .parent_names = dmn_clk_parents,
  497. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  498. };
  499. static struct clk_init_data clk_mmc23_init = {
  500. .name = "mmc23",
  501. .ops = &dmn_ops,
  502. .parent_names = dmn_clk_parents,
  503. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  504. };
  505. static struct clk_init_data clk_mmc45_init = {
  506. .name = "mmc45",
  507. .ops = &dmn_ops,
  508. .parent_names = dmn_clk_parents,
  509. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  510. };
  511. /*
  512. * peripheral controllers in io domain
  513. */
  514. static int std_clk_is_enabled(struct clk_hw *hw)
  515. {
  516. u32 reg;
  517. int bit;
  518. struct clk_std *clk = to_stdclk(hw);
  519. bit = clk->enable_bit % 32;
  520. reg = clk->enable_bit / 32;
  521. reg = SIRFSOC_CLKC_CLK_EN0 + reg * sizeof(reg);
  522. return !!(clkc_readl(reg) & BIT(bit));
  523. }
  524. static int std_clk_enable(struct clk_hw *hw)
  525. {
  526. u32 val, reg;
  527. int bit;
  528. struct clk_std *clk = to_stdclk(hw);
  529. BUG_ON(clk->enable_bit < 0 || clk->enable_bit > 63);
  530. bit = clk->enable_bit % 32;
  531. reg = clk->enable_bit / 32;
  532. reg = SIRFSOC_CLKC_CLK_EN0 + reg * sizeof(reg);
  533. val = clkc_readl(reg) | BIT(bit);
  534. clkc_writel(val, reg);
  535. return 0;
  536. }
  537. static void std_clk_disable(struct clk_hw *hw)
  538. {
  539. u32 val, reg;
  540. int bit;
  541. struct clk_std *clk = to_stdclk(hw);
  542. BUG_ON(clk->enable_bit < 0 || clk->enable_bit > 63);
  543. bit = clk->enable_bit % 32;
  544. reg = clk->enable_bit / 32;
  545. reg = SIRFSOC_CLKC_CLK_EN0 + reg * sizeof(reg);
  546. val = clkc_readl(reg) & ~BIT(bit);
  547. clkc_writel(val, reg);
  548. }
  549. static const char *std_clk_io_parents[] = {
  550. "io",
  551. };
  552. static struct clk_ops ios_ops = {
  553. .is_enabled = std_clk_is_enabled,
  554. .enable = std_clk_enable,
  555. .disable = std_clk_disable,
  556. };
  557. static struct clk_init_data clk_cphif_init = {
  558. .name = "cphif",
  559. .ops = &ios_ops,
  560. .parent_names = std_clk_io_parents,
  561. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  562. };
  563. static struct clk_std clk_cphif = {
  564. .enable_bit = 20,
  565. .hw = {
  566. .init = &clk_cphif_init,
  567. },
  568. };
  569. static struct clk_init_data clk_dmac0_init = {
  570. .name = "dmac0",
  571. .ops = &ios_ops,
  572. .parent_names = std_clk_io_parents,
  573. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  574. };
  575. static struct clk_std clk_dmac0 = {
  576. .enable_bit = 32,
  577. .hw = {
  578. .init = &clk_dmac0_init,
  579. },
  580. };
  581. static struct clk_init_data clk_dmac1_init = {
  582. .name = "dmac1",
  583. .ops = &ios_ops,
  584. .parent_names = std_clk_io_parents,
  585. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  586. };
  587. static struct clk_std clk_dmac1 = {
  588. .enable_bit = 33,
  589. .hw = {
  590. .init = &clk_dmac1_init,
  591. },
  592. };
  593. static struct clk_init_data clk_audio_init = {
  594. .name = "audio",
  595. .ops = &ios_ops,
  596. .parent_names = std_clk_io_parents,
  597. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  598. };
  599. static struct clk_std clk_audio = {
  600. .enable_bit = 35,
  601. .hw = {
  602. .init = &clk_audio_init,
  603. },
  604. };
  605. static struct clk_init_data clk_uart0_init = {
  606. .name = "uart0",
  607. .ops = &ios_ops,
  608. .parent_names = std_clk_io_parents,
  609. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  610. };
  611. static struct clk_std clk_uart0 = {
  612. .enable_bit = 36,
  613. .hw = {
  614. .init = &clk_uart0_init,
  615. },
  616. };
  617. static struct clk_init_data clk_uart1_init = {
  618. .name = "uart1",
  619. .ops = &ios_ops,
  620. .parent_names = std_clk_io_parents,
  621. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  622. };
  623. static struct clk_std clk_uart1 = {
  624. .enable_bit = 37,
  625. .hw = {
  626. .init = &clk_uart1_init,
  627. },
  628. };
  629. static struct clk_init_data clk_uart2_init = {
  630. .name = "uart2",
  631. .ops = &ios_ops,
  632. .parent_names = std_clk_io_parents,
  633. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  634. };
  635. static struct clk_std clk_uart2 = {
  636. .enable_bit = 38,
  637. .hw = {
  638. .init = &clk_uart2_init,
  639. },
  640. };
  641. static struct clk_init_data clk_usp0_init = {
  642. .name = "usp0",
  643. .ops = &ios_ops,
  644. .parent_names = std_clk_io_parents,
  645. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  646. };
  647. static struct clk_std clk_usp0 = {
  648. .enable_bit = 39,
  649. .hw = {
  650. .init = &clk_usp0_init,
  651. },
  652. };
  653. static struct clk_init_data clk_usp1_init = {
  654. .name = "usp1",
  655. .ops = &ios_ops,
  656. .parent_names = std_clk_io_parents,
  657. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  658. };
  659. static struct clk_std clk_usp1 = {
  660. .enable_bit = 40,
  661. .hw = {
  662. .init = &clk_usp1_init,
  663. },
  664. };
  665. static struct clk_init_data clk_usp2_init = {
  666. .name = "usp2",
  667. .ops = &ios_ops,
  668. .parent_names = std_clk_io_parents,
  669. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  670. };
  671. static struct clk_std clk_usp2 = {
  672. .enable_bit = 41,
  673. .hw = {
  674. .init = &clk_usp2_init,
  675. },
  676. };
  677. static struct clk_init_data clk_vip_init = {
  678. .name = "vip",
  679. .ops = &ios_ops,
  680. .parent_names = std_clk_io_parents,
  681. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  682. };
  683. static struct clk_std clk_vip = {
  684. .enable_bit = 42,
  685. .hw = {
  686. .init = &clk_vip_init,
  687. },
  688. };
  689. static struct clk_init_data clk_spi0_init = {
  690. .name = "spi0",
  691. .ops = &ios_ops,
  692. .parent_names = std_clk_io_parents,
  693. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  694. };
  695. static struct clk_std clk_spi0 = {
  696. .enable_bit = 43,
  697. .hw = {
  698. .init = &clk_spi0_init,
  699. },
  700. };
  701. static struct clk_init_data clk_spi1_init = {
  702. .name = "spi1",
  703. .ops = &ios_ops,
  704. .parent_names = std_clk_io_parents,
  705. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  706. };
  707. static struct clk_std clk_spi1 = {
  708. .enable_bit = 44,
  709. .hw = {
  710. .init = &clk_spi1_init,
  711. },
  712. };
  713. static struct clk_init_data clk_tsc_init = {
  714. .name = "tsc",
  715. .ops = &ios_ops,
  716. .parent_names = std_clk_io_parents,
  717. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  718. };
  719. static struct clk_std clk_tsc = {
  720. .enable_bit = 45,
  721. .hw = {
  722. .init = &clk_tsc_init,
  723. },
  724. };
  725. static struct clk_init_data clk_i2c0_init = {
  726. .name = "i2c0",
  727. .ops = &ios_ops,
  728. .parent_names = std_clk_io_parents,
  729. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  730. };
  731. static struct clk_std clk_i2c0 = {
  732. .enable_bit = 46,
  733. .hw = {
  734. .init = &clk_i2c0_init,
  735. },
  736. };
  737. static struct clk_init_data clk_i2c1_init = {
  738. .name = "i2c1",
  739. .ops = &ios_ops,
  740. .parent_names = std_clk_io_parents,
  741. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  742. };
  743. static struct clk_std clk_i2c1 = {
  744. .enable_bit = 47,
  745. .hw = {
  746. .init = &clk_i2c1_init,
  747. },
  748. };
  749. static struct clk_init_data clk_pwmc_init = {
  750. .name = "pwmc",
  751. .ops = &ios_ops,
  752. .parent_names = std_clk_io_parents,
  753. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  754. };
  755. static struct clk_std clk_pwmc = {
  756. .enable_bit = 48,
  757. .hw = {
  758. .init = &clk_pwmc_init,
  759. },
  760. };
  761. static struct clk_init_data clk_efuse_init = {
  762. .name = "efuse",
  763. .ops = &ios_ops,
  764. .parent_names = std_clk_io_parents,
  765. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  766. };
  767. static struct clk_std clk_efuse = {
  768. .enable_bit = 49,
  769. .hw = {
  770. .init = &clk_efuse_init,
  771. },
  772. };
  773. static struct clk_init_data clk_pulse_init = {
  774. .name = "pulse",
  775. .ops = &ios_ops,
  776. .parent_names = std_clk_io_parents,
  777. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  778. };
  779. static struct clk_std clk_pulse = {
  780. .enable_bit = 50,
  781. .hw = {
  782. .init = &clk_pulse_init,
  783. },
  784. };
  785. static const char *std_clk_dsp_parents[] = {
  786. "dsp",
  787. };
  788. static struct clk_init_data clk_gps_init = {
  789. .name = "gps",
  790. .ops = &ios_ops,
  791. .parent_names = std_clk_dsp_parents,
  792. .num_parents = ARRAY_SIZE(std_clk_dsp_parents),
  793. };
  794. static struct clk_std clk_gps = {
  795. .enable_bit = 1,
  796. .hw = {
  797. .init = &clk_gps_init,
  798. },
  799. };
  800. static struct clk_init_data clk_mf_init = {
  801. .name = "mf",
  802. .ops = &ios_ops,
  803. .parent_names = std_clk_io_parents,
  804. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  805. };
  806. static struct clk_std clk_mf = {
  807. .enable_bit = 2,
  808. .hw = {
  809. .init = &clk_mf_init,
  810. },
  811. };
  812. static const char *std_clk_sys_parents[] = {
  813. "sys",
  814. };
  815. static struct clk_init_data clk_security_init = {
  816. .name = "security",
  817. .ops = &ios_ops,
  818. .parent_names = std_clk_sys_parents,
  819. .num_parents = ARRAY_SIZE(std_clk_sys_parents),
  820. };
  821. static struct clk_std clk_security = {
  822. .enable_bit = 19,
  823. .hw = {
  824. .init = &clk_security_init,
  825. },
  826. };
  827. static const char *std_clk_usb_parents[] = {
  828. "usb_pll",
  829. };
  830. static struct clk_init_data clk_usb0_init = {
  831. .name = "usb0",
  832. .ops = &ios_ops,
  833. .parent_names = std_clk_usb_parents,
  834. .num_parents = ARRAY_SIZE(std_clk_usb_parents),
  835. };
  836. static struct clk_std clk_usb0 = {
  837. .enable_bit = 16,
  838. .hw = {
  839. .init = &clk_usb0_init,
  840. },
  841. };
  842. static struct clk_init_data clk_usb1_init = {
  843. .name = "usb1",
  844. .ops = &ios_ops,
  845. .parent_names = std_clk_usb_parents,
  846. .num_parents = ARRAY_SIZE(std_clk_usb_parents),
  847. };
  848. static struct clk_std clk_usb1 = {
  849. .enable_bit = 17,
  850. .hw = {
  851. .init = &clk_usb1_init,
  852. },
  853. };