clk-sunxi.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. /*
  2. * Copyright 2013 Emilio López
  3. *
  4. * Emilio López <emilio@elopez.com.ar>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <linux/clk-provider.h>
  17. #include <linux/clkdev.h>
  18. #include <linux/of.h>
  19. #include <linux/of_address.h>
  20. #include <linux/reset-controller.h>
  21. #include "clk-factors.h"
  22. static DEFINE_SPINLOCK(clk_lock);
  23. /* Maximum number of parents our clocks have */
  24. #define SUNXI_MAX_PARENTS 5
  25. /**
  26. * sun4i_get_pll1_factors() - calculates n, k, m, p factors for PLL1
  27. * PLL1 rate is calculated as follows
  28. * rate = (parent_rate * n * (k + 1) >> p) / (m + 1);
  29. * parent_rate is always 24Mhz
  30. */
  31. static void sun4i_get_pll1_factors(u32 *freq, u32 parent_rate,
  32. u8 *n, u8 *k, u8 *m, u8 *p)
  33. {
  34. u8 div;
  35. /* Normalize value to a 6M multiple */
  36. div = *freq / 6000000;
  37. *freq = 6000000 * div;
  38. /* we were called to round the frequency, we can now return */
  39. if (n == NULL)
  40. return;
  41. /* m is always zero for pll1 */
  42. *m = 0;
  43. /* k is 1 only on these cases */
  44. if (*freq >= 768000000 || *freq == 42000000 || *freq == 54000000)
  45. *k = 1;
  46. else
  47. *k = 0;
  48. /* p will be 3 for divs under 10 */
  49. if (div < 10)
  50. *p = 3;
  51. /* p will be 2 for divs between 10 - 20 and odd divs under 32 */
  52. else if (div < 20 || (div < 32 && (div & 1)))
  53. *p = 2;
  54. /* p will be 1 for even divs under 32, divs under 40 and odd pairs
  55. * of divs between 40-62 */
  56. else if (div < 40 || (div < 64 && (div & 2)))
  57. *p = 1;
  58. /* any other entries have p = 0 */
  59. else
  60. *p = 0;
  61. /* calculate a suitable n based on k and p */
  62. div <<= *p;
  63. div /= (*k + 1);
  64. *n = div / 4;
  65. }
  66. /**
  67. * sun6i_a31_get_pll1_factors() - calculates n, k and m factors for PLL1
  68. * PLL1 rate is calculated as follows
  69. * rate = parent_rate * (n + 1) * (k + 1) / (m + 1);
  70. * parent_rate should always be 24MHz
  71. */
  72. static void sun6i_a31_get_pll1_factors(u32 *freq, u32 parent_rate,
  73. u8 *n, u8 *k, u8 *m, u8 *p)
  74. {
  75. /*
  76. * We can operate only on MHz, this will make our life easier
  77. * later.
  78. */
  79. u32 freq_mhz = *freq / 1000000;
  80. u32 parent_freq_mhz = parent_rate / 1000000;
  81. /*
  82. * Round down the frequency to the closest multiple of either
  83. * 6 or 16
  84. */
  85. u32 round_freq_6 = round_down(freq_mhz, 6);
  86. u32 round_freq_16 = round_down(freq_mhz, 16);
  87. if (round_freq_6 > round_freq_16)
  88. freq_mhz = round_freq_6;
  89. else
  90. freq_mhz = round_freq_16;
  91. *freq = freq_mhz * 1000000;
  92. /*
  93. * If the factors pointer are null, we were just called to
  94. * round down the frequency.
  95. * Exit.
  96. */
  97. if (n == NULL)
  98. return;
  99. /* If the frequency is a multiple of 32 MHz, k is always 3 */
  100. if (!(freq_mhz % 32))
  101. *k = 3;
  102. /* If the frequency is a multiple of 9 MHz, k is always 2 */
  103. else if (!(freq_mhz % 9))
  104. *k = 2;
  105. /* If the frequency is a multiple of 8 MHz, k is always 1 */
  106. else if (!(freq_mhz % 8))
  107. *k = 1;
  108. /* Otherwise, we don't use the k factor */
  109. else
  110. *k = 0;
  111. /*
  112. * If the frequency is a multiple of 2 but not a multiple of
  113. * 3, m is 3. This is the first time we use 6 here, yet we
  114. * will use it on several other places.
  115. * We use this number because it's the lowest frequency we can
  116. * generate (with n = 0, k = 0, m = 3), so every other frequency
  117. * somehow relates to this frequency.
  118. */
  119. if ((freq_mhz % 6) == 2 || (freq_mhz % 6) == 4)
  120. *m = 2;
  121. /*
  122. * If the frequency is a multiple of 6MHz, but the factor is
  123. * odd, m will be 3
  124. */
  125. else if ((freq_mhz / 6) & 1)
  126. *m = 3;
  127. /* Otherwise, we end up with m = 1 */
  128. else
  129. *m = 1;
  130. /* Calculate n thanks to the above factors we already got */
  131. *n = freq_mhz * (*m + 1) / ((*k + 1) * parent_freq_mhz) - 1;
  132. /*
  133. * If n end up being outbound, and that we can still decrease
  134. * m, do it.
  135. */
  136. if ((*n + 1) > 31 && (*m + 1) > 1) {
  137. *n = (*n + 1) / 2 - 1;
  138. *m = (*m + 1) / 2 - 1;
  139. }
  140. }
  141. /**
  142. * sun8i_a23_get_pll1_factors() - calculates n, k, m, p factors for PLL1
  143. * PLL1 rate is calculated as follows
  144. * rate = (parent_rate * (n + 1) * (k + 1) >> p) / (m + 1);
  145. * parent_rate is always 24Mhz
  146. */
  147. static void sun8i_a23_get_pll1_factors(u32 *freq, u32 parent_rate,
  148. u8 *n, u8 *k, u8 *m, u8 *p)
  149. {
  150. u8 div;
  151. /* Normalize value to a 6M multiple */
  152. div = *freq / 6000000;
  153. *freq = 6000000 * div;
  154. /* we were called to round the frequency, we can now return */
  155. if (n == NULL)
  156. return;
  157. /* m is always zero for pll1 */
  158. *m = 0;
  159. /* k is 1 only on these cases */
  160. if (*freq >= 768000000 || *freq == 42000000 || *freq == 54000000)
  161. *k = 1;
  162. else
  163. *k = 0;
  164. /* p will be 2 for divs under 20 and odd divs under 32 */
  165. if (div < 20 || (div < 32 && (div & 1)))
  166. *p = 2;
  167. /* p will be 1 for even divs under 32, divs under 40 and odd pairs
  168. * of divs between 40-62 */
  169. else if (div < 40 || (div < 64 && (div & 2)))
  170. *p = 1;
  171. /* any other entries have p = 0 */
  172. else
  173. *p = 0;
  174. /* calculate a suitable n based on k and p */
  175. div <<= *p;
  176. div /= (*k + 1);
  177. *n = div / 4 - 1;
  178. }
  179. /**
  180. * sun4i_get_pll5_factors() - calculates n, k factors for PLL5
  181. * PLL5 rate is calculated as follows
  182. * rate = parent_rate * n * (k + 1)
  183. * parent_rate is always 24Mhz
  184. */
  185. static void sun4i_get_pll5_factors(u32 *freq, u32 parent_rate,
  186. u8 *n, u8 *k, u8 *m, u8 *p)
  187. {
  188. u8 div;
  189. /* Normalize value to a parent_rate multiple (24M) */
  190. div = *freq / parent_rate;
  191. *freq = parent_rate * div;
  192. /* we were called to round the frequency, we can now return */
  193. if (n == NULL)
  194. return;
  195. if (div < 31)
  196. *k = 0;
  197. else if (div / 2 < 31)
  198. *k = 1;
  199. else if (div / 3 < 31)
  200. *k = 2;
  201. else
  202. *k = 3;
  203. *n = DIV_ROUND_UP(div, (*k+1));
  204. }
  205. /**
  206. * sun6i_a31_get_pll6_factors() - calculates n, k factors for A31 PLL6
  207. * PLL6 rate is calculated as follows
  208. * rate = parent_rate * n * (k + 1) / 2
  209. * parent_rate is always 24Mhz
  210. */
  211. static void sun6i_a31_get_pll6_factors(u32 *freq, u32 parent_rate,
  212. u8 *n, u8 *k, u8 *m, u8 *p)
  213. {
  214. u8 div;
  215. /*
  216. * We always have 24MHz / 2, so we can just say that our
  217. * parent clock is 12MHz.
  218. */
  219. parent_rate = parent_rate / 2;
  220. /* Normalize value to a parent_rate multiple (24M / 2) */
  221. div = *freq / parent_rate;
  222. *freq = parent_rate * div;
  223. /* we were called to round the frequency, we can now return */
  224. if (n == NULL)
  225. return;
  226. *k = div / 32;
  227. if (*k > 3)
  228. *k = 3;
  229. *n = DIV_ROUND_UP(div, (*k+1));
  230. }
  231. /**
  232. * sun4i_get_apb1_factors() - calculates m, p factors for APB1
  233. * APB1 rate is calculated as follows
  234. * rate = (parent_rate >> p) / (m + 1);
  235. */
  236. static void sun4i_get_apb1_factors(u32 *freq, u32 parent_rate,
  237. u8 *n, u8 *k, u8 *m, u8 *p)
  238. {
  239. u8 calcm, calcp;
  240. if (parent_rate < *freq)
  241. *freq = parent_rate;
  242. parent_rate = DIV_ROUND_UP(parent_rate, *freq);
  243. /* Invalid rate! */
  244. if (parent_rate > 32)
  245. return;
  246. if (parent_rate <= 4)
  247. calcp = 0;
  248. else if (parent_rate <= 8)
  249. calcp = 1;
  250. else if (parent_rate <= 16)
  251. calcp = 2;
  252. else
  253. calcp = 3;
  254. calcm = (parent_rate >> calcp) - 1;
  255. *freq = (parent_rate >> calcp) / (calcm + 1);
  256. /* we were called to round the frequency, we can now return */
  257. if (n == NULL)
  258. return;
  259. *m = calcm;
  260. *p = calcp;
  261. }
  262. /**
  263. * sun4i_get_mod0_factors() - calculates m, n factors for MOD0-style clocks
  264. * MOD0 rate is calculated as follows
  265. * rate = (parent_rate >> p) / (m + 1);
  266. */
  267. static void sun4i_get_mod0_factors(u32 *freq, u32 parent_rate,
  268. u8 *n, u8 *k, u8 *m, u8 *p)
  269. {
  270. u8 div, calcm, calcp;
  271. /* These clocks can only divide, so we will never be able to achieve
  272. * frequencies higher than the parent frequency */
  273. if (*freq > parent_rate)
  274. *freq = parent_rate;
  275. div = DIV_ROUND_UP(parent_rate, *freq);
  276. if (div < 16)
  277. calcp = 0;
  278. else if (div / 2 < 16)
  279. calcp = 1;
  280. else if (div / 4 < 16)
  281. calcp = 2;
  282. else
  283. calcp = 3;
  284. calcm = DIV_ROUND_UP(div, 1 << calcp);
  285. *freq = (parent_rate >> calcp) / calcm;
  286. /* we were called to round the frequency, we can now return */
  287. if (n == NULL)
  288. return;
  289. *m = calcm - 1;
  290. *p = calcp;
  291. }
  292. /**
  293. * sun7i_a20_get_out_factors() - calculates m, p factors for CLK_OUT_A/B
  294. * CLK_OUT rate is calculated as follows
  295. * rate = (parent_rate >> p) / (m + 1);
  296. */
  297. static void sun7i_a20_get_out_factors(u32 *freq, u32 parent_rate,
  298. u8 *n, u8 *k, u8 *m, u8 *p)
  299. {
  300. u8 div, calcm, calcp;
  301. /* These clocks can only divide, so we will never be able to achieve
  302. * frequencies higher than the parent frequency */
  303. if (*freq > parent_rate)
  304. *freq = parent_rate;
  305. div = DIV_ROUND_UP(parent_rate, *freq);
  306. if (div < 32)
  307. calcp = 0;
  308. else if (div / 2 < 32)
  309. calcp = 1;
  310. else if (div / 4 < 32)
  311. calcp = 2;
  312. else
  313. calcp = 3;
  314. calcm = DIV_ROUND_UP(div, 1 << calcp);
  315. *freq = (parent_rate >> calcp) / calcm;
  316. /* we were called to round the frequency, we can now return */
  317. if (n == NULL)
  318. return;
  319. *m = calcm - 1;
  320. *p = calcp;
  321. }
  322. /**
  323. * clk_sunxi_mmc_phase_control() - configures MMC clock phase control
  324. */
  325. void clk_sunxi_mmc_phase_control(struct clk *clk, u8 sample, u8 output)
  326. {
  327. #define to_clk_composite(_hw) container_of(_hw, struct clk_composite, hw)
  328. #define to_clk_factors(_hw) container_of(_hw, struct clk_factors, hw)
  329. struct clk_hw *hw = __clk_get_hw(clk);
  330. struct clk_composite *composite = to_clk_composite(hw);
  331. struct clk_hw *rate_hw = composite->rate_hw;
  332. struct clk_factors *factors = to_clk_factors(rate_hw);
  333. unsigned long flags = 0;
  334. u32 reg;
  335. if (factors->lock)
  336. spin_lock_irqsave(factors->lock, flags);
  337. reg = readl(factors->reg);
  338. /* set sample clock phase control */
  339. reg &= ~(0x7 << 20);
  340. reg |= ((sample & 0x7) << 20);
  341. /* set output clock phase control */
  342. reg &= ~(0x7 << 8);
  343. reg |= ((output & 0x7) << 8);
  344. writel(reg, factors->reg);
  345. if (factors->lock)
  346. spin_unlock_irqrestore(factors->lock, flags);
  347. }
  348. EXPORT_SYMBOL(clk_sunxi_mmc_phase_control);
  349. /**
  350. * sunxi_factors_clk_setup() - Setup function for factor clocks
  351. */
  352. #define SUNXI_FACTORS_MUX_MASK 0x3
  353. struct factors_data {
  354. int enable;
  355. int mux;
  356. struct clk_factors_config *table;
  357. void (*getter) (u32 *rate, u32 parent_rate, u8 *n, u8 *k, u8 *m, u8 *p);
  358. const char *name;
  359. };
  360. static struct clk_factors_config sun4i_pll1_config = {
  361. .nshift = 8,
  362. .nwidth = 5,
  363. .kshift = 4,
  364. .kwidth = 2,
  365. .mshift = 0,
  366. .mwidth = 2,
  367. .pshift = 16,
  368. .pwidth = 2,
  369. };
  370. static struct clk_factors_config sun6i_a31_pll1_config = {
  371. .nshift = 8,
  372. .nwidth = 5,
  373. .kshift = 4,
  374. .kwidth = 2,
  375. .mshift = 0,
  376. .mwidth = 2,
  377. };
  378. static struct clk_factors_config sun8i_a23_pll1_config = {
  379. .nshift = 8,
  380. .nwidth = 5,
  381. .kshift = 4,
  382. .kwidth = 2,
  383. .mshift = 0,
  384. .mwidth = 2,
  385. .pshift = 16,
  386. .pwidth = 2,
  387. .n_start = 1,
  388. };
  389. static struct clk_factors_config sun4i_pll5_config = {
  390. .nshift = 8,
  391. .nwidth = 5,
  392. .kshift = 4,
  393. .kwidth = 2,
  394. };
  395. static struct clk_factors_config sun6i_a31_pll6_config = {
  396. .nshift = 8,
  397. .nwidth = 5,
  398. .kshift = 4,
  399. .kwidth = 2,
  400. };
  401. static struct clk_factors_config sun4i_apb1_config = {
  402. .mshift = 0,
  403. .mwidth = 5,
  404. .pshift = 16,
  405. .pwidth = 2,
  406. };
  407. /* user manual says "n" but it's really "p" */
  408. static struct clk_factors_config sun4i_mod0_config = {
  409. .mshift = 0,
  410. .mwidth = 4,
  411. .pshift = 16,
  412. .pwidth = 2,
  413. };
  414. /* user manual says "n" but it's really "p" */
  415. static struct clk_factors_config sun7i_a20_out_config = {
  416. .mshift = 8,
  417. .mwidth = 5,
  418. .pshift = 20,
  419. .pwidth = 2,
  420. };
  421. static const struct factors_data sun4i_pll1_data __initconst = {
  422. .enable = 31,
  423. .table = &sun4i_pll1_config,
  424. .getter = sun4i_get_pll1_factors,
  425. };
  426. static const struct factors_data sun6i_a31_pll1_data __initconst = {
  427. .enable = 31,
  428. .table = &sun6i_a31_pll1_config,
  429. .getter = sun6i_a31_get_pll1_factors,
  430. };
  431. static const struct factors_data sun8i_a23_pll1_data __initconst = {
  432. .enable = 31,
  433. .table = &sun8i_a23_pll1_config,
  434. .getter = sun8i_a23_get_pll1_factors,
  435. };
  436. static const struct factors_data sun7i_a20_pll4_data __initconst = {
  437. .enable = 31,
  438. .table = &sun4i_pll5_config,
  439. .getter = sun4i_get_pll5_factors,
  440. };
  441. static const struct factors_data sun4i_pll5_data __initconst = {
  442. .enable = 31,
  443. .table = &sun4i_pll5_config,
  444. .getter = sun4i_get_pll5_factors,
  445. .name = "pll5",
  446. };
  447. static const struct factors_data sun4i_pll6_data __initconst = {
  448. .enable = 31,
  449. .table = &sun4i_pll5_config,
  450. .getter = sun4i_get_pll5_factors,
  451. .name = "pll6",
  452. };
  453. static const struct factors_data sun6i_a31_pll6_data __initconst = {
  454. .enable = 31,
  455. .table = &sun6i_a31_pll6_config,
  456. .getter = sun6i_a31_get_pll6_factors,
  457. };
  458. static const struct factors_data sun4i_apb1_data __initconst = {
  459. .table = &sun4i_apb1_config,
  460. .getter = sun4i_get_apb1_factors,
  461. };
  462. static const struct factors_data sun4i_mod0_data __initconst = {
  463. .enable = 31,
  464. .mux = 24,
  465. .table = &sun4i_mod0_config,
  466. .getter = sun4i_get_mod0_factors,
  467. };
  468. static const struct factors_data sun7i_a20_out_data __initconst = {
  469. .enable = 31,
  470. .mux = 24,
  471. .table = &sun7i_a20_out_config,
  472. .getter = sun7i_a20_get_out_factors,
  473. };
  474. static struct clk * __init sunxi_factors_clk_setup(struct device_node *node,
  475. const struct factors_data *data)
  476. {
  477. struct clk *clk;
  478. struct clk_factors *factors;
  479. struct clk_gate *gate = NULL;
  480. struct clk_mux *mux = NULL;
  481. struct clk_hw *gate_hw = NULL;
  482. struct clk_hw *mux_hw = NULL;
  483. const char *clk_name = node->name;
  484. const char *parents[SUNXI_MAX_PARENTS];
  485. void __iomem *reg;
  486. int i = 0;
  487. reg = of_iomap(node, 0);
  488. /* if we have a mux, we will have >1 parents */
  489. while (i < SUNXI_MAX_PARENTS &&
  490. (parents[i] = of_clk_get_parent_name(node, i)) != NULL)
  491. i++;
  492. /*
  493. * some factor clocks, such as pll5 and pll6, may have multiple
  494. * outputs, and have their name designated in factors_data
  495. */
  496. if (data->name)
  497. clk_name = data->name;
  498. else
  499. of_property_read_string(node, "clock-output-names", &clk_name);
  500. factors = kzalloc(sizeof(struct clk_factors), GFP_KERNEL);
  501. if (!factors)
  502. return NULL;
  503. /* Add a gate if this factor clock can be gated */
  504. if (data->enable) {
  505. gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
  506. if (!gate) {
  507. kfree(factors);
  508. return NULL;
  509. }
  510. /* set up gate properties */
  511. gate->reg = reg;
  512. gate->bit_idx = data->enable;
  513. gate->lock = &clk_lock;
  514. gate_hw = &gate->hw;
  515. }
  516. /* Add a mux if this factor clock can be muxed */
  517. if (data->mux) {
  518. mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL);
  519. if (!mux) {
  520. kfree(factors);
  521. kfree(gate);
  522. return NULL;
  523. }
  524. /* set up gate properties */
  525. mux->reg = reg;
  526. mux->shift = data->mux;
  527. mux->mask = SUNXI_FACTORS_MUX_MASK;
  528. mux->lock = &clk_lock;
  529. mux_hw = &mux->hw;
  530. }
  531. /* set up factors properties */
  532. factors->reg = reg;
  533. factors->config = data->table;
  534. factors->get_factors = data->getter;
  535. factors->lock = &clk_lock;
  536. clk = clk_register_composite(NULL, clk_name,
  537. parents, i,
  538. mux_hw, &clk_mux_ops,
  539. &factors->hw, &clk_factors_ops,
  540. gate_hw, &clk_gate_ops, 0);
  541. if (!IS_ERR(clk)) {
  542. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  543. clk_register_clkdev(clk, clk_name, NULL);
  544. }
  545. return clk;
  546. }
  547. /**
  548. * sunxi_mux_clk_setup() - Setup function for muxes
  549. */
  550. #define SUNXI_MUX_GATE_WIDTH 2
  551. struct mux_data {
  552. u8 shift;
  553. };
  554. static const struct mux_data sun4i_cpu_mux_data __initconst = {
  555. .shift = 16,
  556. };
  557. static const struct mux_data sun6i_a31_ahb1_mux_data __initconst = {
  558. .shift = 12,
  559. };
  560. static const struct mux_data sun4i_apb1_mux_data __initconst = {
  561. .shift = 24,
  562. };
  563. static void __init sunxi_mux_clk_setup(struct device_node *node,
  564. struct mux_data *data)
  565. {
  566. struct clk *clk;
  567. const char *clk_name = node->name;
  568. const char *parents[SUNXI_MAX_PARENTS];
  569. void __iomem *reg;
  570. int i = 0;
  571. reg = of_iomap(node, 0);
  572. while (i < SUNXI_MAX_PARENTS &&
  573. (parents[i] = of_clk_get_parent_name(node, i)) != NULL)
  574. i++;
  575. of_property_read_string(node, "clock-output-names", &clk_name);
  576. clk = clk_register_mux(NULL, clk_name, parents, i,
  577. CLK_SET_RATE_NO_REPARENT, reg,
  578. data->shift, SUNXI_MUX_GATE_WIDTH,
  579. 0, &clk_lock);
  580. if (clk) {
  581. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  582. clk_register_clkdev(clk, clk_name, NULL);
  583. }
  584. }
  585. /**
  586. * sunxi_divider_clk_setup() - Setup function for simple divider clocks
  587. */
  588. struct div_data {
  589. u8 shift;
  590. u8 pow;
  591. u8 width;
  592. const struct clk_div_table *table;
  593. };
  594. static const struct div_data sun4i_axi_data __initconst = {
  595. .shift = 0,
  596. .pow = 0,
  597. .width = 2,
  598. };
  599. static const struct clk_div_table sun8i_a23_axi_table[] __initconst = {
  600. { .val = 0, .div = 1 },
  601. { .val = 1, .div = 2 },
  602. { .val = 2, .div = 3 },
  603. { .val = 3, .div = 4 },
  604. { .val = 4, .div = 4 },
  605. { .val = 5, .div = 4 },
  606. { .val = 6, .div = 4 },
  607. { .val = 7, .div = 4 },
  608. { } /* sentinel */
  609. };
  610. static const struct div_data sun8i_a23_axi_data __initconst = {
  611. .width = 3,
  612. .table = sun8i_a23_axi_table,
  613. };
  614. static const struct div_data sun4i_ahb_data __initconst = {
  615. .shift = 4,
  616. .pow = 1,
  617. .width = 2,
  618. };
  619. static const struct div_data sun4i_apb0_data __initconst = {
  620. .shift = 8,
  621. .pow = 1,
  622. .width = 2,
  623. };
  624. static const struct div_data sun6i_a31_apb2_div_data __initconst = {
  625. .shift = 0,
  626. .pow = 0,
  627. .width = 4,
  628. };
  629. static void __init sunxi_divider_clk_setup(struct device_node *node,
  630. struct div_data *data)
  631. {
  632. struct clk *clk;
  633. const char *clk_name = node->name;
  634. const char *clk_parent;
  635. void __iomem *reg;
  636. reg = of_iomap(node, 0);
  637. clk_parent = of_clk_get_parent_name(node, 0);
  638. of_property_read_string(node, "clock-output-names", &clk_name);
  639. clk = clk_register_divider_table(NULL, clk_name, clk_parent, 0,
  640. reg, data->shift, data->width,
  641. data->pow ? CLK_DIVIDER_POWER_OF_TWO : 0,
  642. data->table, &clk_lock);
  643. if (clk) {
  644. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  645. clk_register_clkdev(clk, clk_name, NULL);
  646. }
  647. }
  648. /**
  649. * sunxi_gates_reset... - reset bits in leaf gate clk registers handling
  650. */
  651. struct gates_reset_data {
  652. void __iomem *reg;
  653. spinlock_t *lock;
  654. struct reset_controller_dev rcdev;
  655. };
  656. static int sunxi_gates_reset_assert(struct reset_controller_dev *rcdev,
  657. unsigned long id)
  658. {
  659. struct gates_reset_data *data = container_of(rcdev,
  660. struct gates_reset_data,
  661. rcdev);
  662. unsigned long flags;
  663. u32 reg;
  664. spin_lock_irqsave(data->lock, flags);
  665. reg = readl(data->reg);
  666. writel(reg & ~BIT(id), data->reg);
  667. spin_unlock_irqrestore(data->lock, flags);
  668. return 0;
  669. }
  670. static int sunxi_gates_reset_deassert(struct reset_controller_dev *rcdev,
  671. unsigned long id)
  672. {
  673. struct gates_reset_data *data = container_of(rcdev,
  674. struct gates_reset_data,
  675. rcdev);
  676. unsigned long flags;
  677. u32 reg;
  678. spin_lock_irqsave(data->lock, flags);
  679. reg = readl(data->reg);
  680. writel(reg | BIT(id), data->reg);
  681. spin_unlock_irqrestore(data->lock, flags);
  682. return 0;
  683. }
  684. static struct reset_control_ops sunxi_gates_reset_ops = {
  685. .assert = sunxi_gates_reset_assert,
  686. .deassert = sunxi_gates_reset_deassert,
  687. };
  688. /**
  689. * sunxi_gates_clk_setup() - Setup function for leaf gates on clocks
  690. */
  691. #define SUNXI_GATES_MAX_SIZE 64
  692. struct gates_data {
  693. DECLARE_BITMAP(mask, SUNXI_GATES_MAX_SIZE);
  694. u32 reset_mask;
  695. };
  696. static const struct gates_data sun4i_axi_gates_data __initconst = {
  697. .mask = {1},
  698. };
  699. static const struct gates_data sun4i_ahb_gates_data __initconst = {
  700. .mask = {0x7F77FFF, 0x14FB3F},
  701. };
  702. static const struct gates_data sun5i_a10s_ahb_gates_data __initconst = {
  703. .mask = {0x147667e7, 0x185915},
  704. };
  705. static const struct gates_data sun5i_a13_ahb_gates_data __initconst = {
  706. .mask = {0x107067e7, 0x185111},
  707. };
  708. static const struct gates_data sun6i_a31_ahb1_gates_data __initconst = {
  709. .mask = {0xEDFE7F62, 0x794F931},
  710. };
  711. static const struct gates_data sun7i_a20_ahb_gates_data __initconst = {
  712. .mask = { 0x12f77fff, 0x16ff3f },
  713. };
  714. static const struct gates_data sun8i_a23_ahb1_gates_data __initconst = {
  715. .mask = {0x25386742, 0x2505111},
  716. };
  717. static const struct gates_data sun4i_apb0_gates_data __initconst = {
  718. .mask = {0x4EF},
  719. };
  720. static const struct gates_data sun5i_a10s_apb0_gates_data __initconst = {
  721. .mask = {0x469},
  722. };
  723. static const struct gates_data sun5i_a13_apb0_gates_data __initconst = {
  724. .mask = {0x61},
  725. };
  726. static const struct gates_data sun7i_a20_apb0_gates_data __initconst = {
  727. .mask = { 0x4ff },
  728. };
  729. static const struct gates_data sun4i_apb1_gates_data __initconst = {
  730. .mask = {0xFF00F7},
  731. };
  732. static const struct gates_data sun5i_a10s_apb1_gates_data __initconst = {
  733. .mask = {0xf0007},
  734. };
  735. static const struct gates_data sun5i_a13_apb1_gates_data __initconst = {
  736. .mask = {0xa0007},
  737. };
  738. static const struct gates_data sun6i_a31_apb1_gates_data __initconst = {
  739. .mask = {0x3031},
  740. };
  741. static const struct gates_data sun8i_a23_apb1_gates_data __initconst = {
  742. .mask = {0x3021},
  743. };
  744. static const struct gates_data sun6i_a31_apb2_gates_data __initconst = {
  745. .mask = {0x3F000F},
  746. };
  747. static const struct gates_data sun7i_a20_apb1_gates_data __initconst = {
  748. .mask = { 0xff80ff },
  749. };
  750. static const struct gates_data sun8i_a23_apb2_gates_data __initconst = {
  751. .mask = {0x1F0007},
  752. };
  753. static const struct gates_data sun4i_a10_usb_gates_data __initconst = {
  754. .mask = {0x1C0},
  755. .reset_mask = 0x07,
  756. };
  757. static const struct gates_data sun5i_a13_usb_gates_data __initconst = {
  758. .mask = {0x140},
  759. .reset_mask = 0x03,
  760. };
  761. static const struct gates_data sun6i_a31_usb_gates_data __initconst = {
  762. .mask = { BIT(18) | BIT(17) | BIT(16) | BIT(10) | BIT(9) | BIT(8) },
  763. .reset_mask = BIT(2) | BIT(1) | BIT(0),
  764. };
  765. static void __init sunxi_gates_clk_setup(struct device_node *node,
  766. struct gates_data *data)
  767. {
  768. struct clk_onecell_data *clk_data;
  769. struct gates_reset_data *reset_data;
  770. const char *clk_parent;
  771. const char *clk_name;
  772. void __iomem *reg;
  773. int qty;
  774. int i = 0;
  775. int j = 0;
  776. reg = of_iomap(node, 0);
  777. clk_parent = of_clk_get_parent_name(node, 0);
  778. /* Worst-case size approximation and memory allocation */
  779. qty = find_last_bit(data->mask, SUNXI_GATES_MAX_SIZE);
  780. clk_data = kmalloc(sizeof(struct clk_onecell_data), GFP_KERNEL);
  781. if (!clk_data)
  782. return;
  783. clk_data->clks = kzalloc((qty+1) * sizeof(struct clk *), GFP_KERNEL);
  784. if (!clk_data->clks) {
  785. kfree(clk_data);
  786. return;
  787. }
  788. for_each_set_bit(i, data->mask, SUNXI_GATES_MAX_SIZE) {
  789. of_property_read_string_index(node, "clock-output-names",
  790. j, &clk_name);
  791. clk_data->clks[i] = clk_register_gate(NULL, clk_name,
  792. clk_parent, 0,
  793. reg + 4 * (i/32), i % 32,
  794. 0, &clk_lock);
  795. WARN_ON(IS_ERR(clk_data->clks[i]));
  796. clk_register_clkdev(clk_data->clks[i], clk_name, NULL);
  797. j++;
  798. }
  799. /* Adjust to the real max */
  800. clk_data->clk_num = i;
  801. of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  802. /* Register a reset controler for gates with reset bits */
  803. if (data->reset_mask == 0)
  804. return;
  805. reset_data = kzalloc(sizeof(*reset_data), GFP_KERNEL);
  806. if (!reset_data)
  807. return;
  808. reset_data->reg = reg;
  809. reset_data->lock = &clk_lock;
  810. reset_data->rcdev.nr_resets = __fls(data->reset_mask) + 1;
  811. reset_data->rcdev.ops = &sunxi_gates_reset_ops;
  812. reset_data->rcdev.of_node = node;
  813. reset_controller_register(&reset_data->rcdev);
  814. }
  815. /**
  816. * sunxi_divs_clk_setup() helper data
  817. */
  818. #define SUNXI_DIVS_MAX_QTY 2
  819. #define SUNXI_DIVISOR_WIDTH 2
  820. struct divs_data {
  821. const struct factors_data *factors; /* data for the factor clock */
  822. struct {
  823. u8 fixed; /* is it a fixed divisor? if not... */
  824. struct clk_div_table *table; /* is it a table based divisor? */
  825. u8 shift; /* otherwise it's a normal divisor with this shift */
  826. u8 pow; /* is it power-of-two based? */
  827. u8 gate; /* is it independently gateable? */
  828. } div[SUNXI_DIVS_MAX_QTY];
  829. };
  830. static struct clk_div_table pll6_sata_tbl[] = {
  831. { .val = 0, .div = 6, },
  832. { .val = 1, .div = 12, },
  833. { .val = 2, .div = 18, },
  834. { .val = 3, .div = 24, },
  835. { } /* sentinel */
  836. };
  837. static const struct divs_data pll5_divs_data __initconst = {
  838. .factors = &sun4i_pll5_data,
  839. .div = {
  840. { .shift = 0, .pow = 0, }, /* M, DDR */
  841. { .shift = 16, .pow = 1, }, /* P, other */
  842. }
  843. };
  844. static const struct divs_data pll6_divs_data __initconst = {
  845. .factors = &sun4i_pll6_data,
  846. .div = {
  847. { .shift = 0, .table = pll6_sata_tbl, .gate = 14 }, /* M, SATA */
  848. { .fixed = 2 }, /* P, other */
  849. }
  850. };
  851. /**
  852. * sunxi_divs_clk_setup() - Setup function for leaf divisors on clocks
  853. *
  854. * These clocks look something like this
  855. * ________________________
  856. * | ___divisor 1---|----> to consumer
  857. * parent >--| pll___/___divisor 2---|----> to consumer
  858. * | \_______________|____> to consumer
  859. * |________________________|
  860. */
  861. static void __init sunxi_divs_clk_setup(struct device_node *node,
  862. struct divs_data *data)
  863. {
  864. struct clk_onecell_data *clk_data;
  865. const char *parent;
  866. const char *clk_name;
  867. struct clk **clks, *pclk;
  868. struct clk_hw *gate_hw, *rate_hw;
  869. const struct clk_ops *rate_ops;
  870. struct clk_gate *gate = NULL;
  871. struct clk_fixed_factor *fix_factor;
  872. struct clk_divider *divider;
  873. void __iomem *reg;
  874. int i = 0;
  875. int flags, clkflags;
  876. /* Set up factor clock that we will be dividing */
  877. pclk = sunxi_factors_clk_setup(node, data->factors);
  878. parent = __clk_get_name(pclk);
  879. reg = of_iomap(node, 0);
  880. clk_data = kmalloc(sizeof(struct clk_onecell_data), GFP_KERNEL);
  881. if (!clk_data)
  882. return;
  883. clks = kzalloc((SUNXI_DIVS_MAX_QTY+1) * sizeof(*clks), GFP_KERNEL);
  884. if (!clks)
  885. goto free_clkdata;
  886. clk_data->clks = clks;
  887. /* It's not a good idea to have automatic reparenting changing
  888. * our RAM clock! */
  889. clkflags = !strcmp("pll5", parent) ? 0 : CLK_SET_RATE_PARENT;
  890. for (i = 0; i < SUNXI_DIVS_MAX_QTY; i++) {
  891. if (of_property_read_string_index(node, "clock-output-names",
  892. i, &clk_name) != 0)
  893. break;
  894. gate_hw = NULL;
  895. rate_hw = NULL;
  896. rate_ops = NULL;
  897. /* If this leaf clock can be gated, create a gate */
  898. if (data->div[i].gate) {
  899. gate = kzalloc(sizeof(*gate), GFP_KERNEL);
  900. if (!gate)
  901. goto free_clks;
  902. gate->reg = reg;
  903. gate->bit_idx = data->div[i].gate;
  904. gate->lock = &clk_lock;
  905. gate_hw = &gate->hw;
  906. }
  907. /* Leaves can be fixed or configurable divisors */
  908. if (data->div[i].fixed) {
  909. fix_factor = kzalloc(sizeof(*fix_factor), GFP_KERNEL);
  910. if (!fix_factor)
  911. goto free_gate;
  912. fix_factor->mult = 1;
  913. fix_factor->div = data->div[i].fixed;
  914. rate_hw = &fix_factor->hw;
  915. rate_ops = &clk_fixed_factor_ops;
  916. } else {
  917. divider = kzalloc(sizeof(*divider), GFP_KERNEL);
  918. if (!divider)
  919. goto free_gate;
  920. flags = data->div[i].pow ? CLK_DIVIDER_POWER_OF_TWO : 0;
  921. divider->reg = reg;
  922. divider->shift = data->div[i].shift;
  923. divider->width = SUNXI_DIVISOR_WIDTH;
  924. divider->flags = flags;
  925. divider->lock = &clk_lock;
  926. divider->table = data->div[i].table;
  927. rate_hw = &divider->hw;
  928. rate_ops = &clk_divider_ops;
  929. }
  930. /* Wrap the (potential) gate and the divisor on a composite
  931. * clock to unify them */
  932. clks[i] = clk_register_composite(NULL, clk_name, &parent, 1,
  933. NULL, NULL,
  934. rate_hw, rate_ops,
  935. gate_hw, &clk_gate_ops,
  936. clkflags);
  937. WARN_ON(IS_ERR(clk_data->clks[i]));
  938. clk_register_clkdev(clks[i], clk_name, NULL);
  939. }
  940. /* The last clock available on the getter is the parent */
  941. clks[i++] = pclk;
  942. /* Adjust to the real max */
  943. clk_data->clk_num = i;
  944. of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  945. return;
  946. free_gate:
  947. kfree(gate);
  948. free_clks:
  949. kfree(clks);
  950. free_clkdata:
  951. kfree(clk_data);
  952. }
  953. /* Matches for factors clocks */
  954. static const struct of_device_id clk_factors_match[] __initconst = {
  955. {.compatible = "allwinner,sun4i-a10-pll1-clk", .data = &sun4i_pll1_data,},
  956. {.compatible = "allwinner,sun6i-a31-pll1-clk", .data = &sun6i_a31_pll1_data,},
  957. {.compatible = "allwinner,sun8i-a23-pll1-clk", .data = &sun8i_a23_pll1_data,},
  958. {.compatible = "allwinner,sun7i-a20-pll4-clk", .data = &sun7i_a20_pll4_data,},
  959. {.compatible = "allwinner,sun6i-a31-pll6-clk", .data = &sun6i_a31_pll6_data,},
  960. {.compatible = "allwinner,sun4i-a10-apb1-clk", .data = &sun4i_apb1_data,},
  961. {.compatible = "allwinner,sun4i-a10-mod0-clk", .data = &sun4i_mod0_data,},
  962. {.compatible = "allwinner,sun7i-a20-out-clk", .data = &sun7i_a20_out_data,},
  963. {}
  964. };
  965. /* Matches for divider clocks */
  966. static const struct of_device_id clk_div_match[] __initconst = {
  967. {.compatible = "allwinner,sun4i-a10-axi-clk", .data = &sun4i_axi_data,},
  968. {.compatible = "allwinner,sun8i-a23-axi-clk", .data = &sun8i_a23_axi_data,},
  969. {.compatible = "allwinner,sun4i-a10-ahb-clk", .data = &sun4i_ahb_data,},
  970. {.compatible = "allwinner,sun4i-a10-apb0-clk", .data = &sun4i_apb0_data,},
  971. {.compatible = "allwinner,sun6i-a31-apb2-div-clk", .data = &sun6i_a31_apb2_div_data,},
  972. {}
  973. };
  974. /* Matches for divided outputs */
  975. static const struct of_device_id clk_divs_match[] __initconst = {
  976. {.compatible = "allwinner,sun4i-a10-pll5-clk", .data = &pll5_divs_data,},
  977. {.compatible = "allwinner,sun4i-a10-pll6-clk", .data = &pll6_divs_data,},
  978. {}
  979. };
  980. /* Matches for mux clocks */
  981. static const struct of_device_id clk_mux_match[] __initconst = {
  982. {.compatible = "allwinner,sun4i-a10-cpu-clk", .data = &sun4i_cpu_mux_data,},
  983. {.compatible = "allwinner,sun4i-a10-apb1-mux-clk", .data = &sun4i_apb1_mux_data,},
  984. {.compatible = "allwinner,sun6i-a31-ahb1-mux-clk", .data = &sun6i_a31_ahb1_mux_data,},
  985. {}
  986. };
  987. /* Matches for gate clocks */
  988. static const struct of_device_id clk_gates_match[] __initconst = {
  989. {.compatible = "allwinner,sun4i-a10-axi-gates-clk", .data = &sun4i_axi_gates_data,},
  990. {.compatible = "allwinner,sun4i-a10-ahb-gates-clk", .data = &sun4i_ahb_gates_data,},
  991. {.compatible = "allwinner,sun5i-a10s-ahb-gates-clk", .data = &sun5i_a10s_ahb_gates_data,},
  992. {.compatible = "allwinner,sun5i-a13-ahb-gates-clk", .data = &sun5i_a13_ahb_gates_data,},
  993. {.compatible = "allwinner,sun6i-a31-ahb1-gates-clk", .data = &sun6i_a31_ahb1_gates_data,},
  994. {.compatible = "allwinner,sun7i-a20-ahb-gates-clk", .data = &sun7i_a20_ahb_gates_data,},
  995. {.compatible = "allwinner,sun8i-a23-ahb1-gates-clk", .data = &sun8i_a23_ahb1_gates_data,},
  996. {.compatible = "allwinner,sun4i-a10-apb0-gates-clk", .data = &sun4i_apb0_gates_data,},
  997. {.compatible = "allwinner,sun5i-a10s-apb0-gates-clk", .data = &sun5i_a10s_apb0_gates_data,},
  998. {.compatible = "allwinner,sun5i-a13-apb0-gates-clk", .data = &sun5i_a13_apb0_gates_data,},
  999. {.compatible = "allwinner,sun7i-a20-apb0-gates-clk", .data = &sun7i_a20_apb0_gates_data,},
  1000. {.compatible = "allwinner,sun4i-a10-apb1-gates-clk", .data = &sun4i_apb1_gates_data,},
  1001. {.compatible = "allwinner,sun5i-a10s-apb1-gates-clk", .data = &sun5i_a10s_apb1_gates_data,},
  1002. {.compatible = "allwinner,sun5i-a13-apb1-gates-clk", .data = &sun5i_a13_apb1_gates_data,},
  1003. {.compatible = "allwinner,sun6i-a31-apb1-gates-clk", .data = &sun6i_a31_apb1_gates_data,},
  1004. {.compatible = "allwinner,sun7i-a20-apb1-gates-clk", .data = &sun7i_a20_apb1_gates_data,},
  1005. {.compatible = "allwinner,sun8i-a23-apb1-gates-clk", .data = &sun8i_a23_apb1_gates_data,},
  1006. {.compatible = "allwinner,sun6i-a31-apb2-gates-clk", .data = &sun6i_a31_apb2_gates_data,},
  1007. {.compatible = "allwinner,sun8i-a23-apb2-gates-clk", .data = &sun8i_a23_apb2_gates_data,},
  1008. {.compatible = "allwinner,sun4i-a10-usb-clk", .data = &sun4i_a10_usb_gates_data,},
  1009. {.compatible = "allwinner,sun5i-a13-usb-clk", .data = &sun5i_a13_usb_gates_data,},
  1010. {.compatible = "allwinner,sun6i-a31-usb-clk", .data = &sun6i_a31_usb_gates_data,},
  1011. {}
  1012. };
  1013. static void __init of_sunxi_table_clock_setup(const struct of_device_id *clk_match,
  1014. void *function)
  1015. {
  1016. struct device_node *np;
  1017. const struct div_data *data;
  1018. const struct of_device_id *match;
  1019. void (*setup_function)(struct device_node *, const void *) = function;
  1020. for_each_matching_node_and_match(np, clk_match, &match) {
  1021. data = match->data;
  1022. setup_function(np, data);
  1023. }
  1024. }
  1025. static void __init sunxi_init_clocks(const char *clocks[], int nclocks)
  1026. {
  1027. unsigned int i;
  1028. /* Register factor clocks */
  1029. of_sunxi_table_clock_setup(clk_factors_match, sunxi_factors_clk_setup);
  1030. /* Register divider clocks */
  1031. of_sunxi_table_clock_setup(clk_div_match, sunxi_divider_clk_setup);
  1032. /* Register divided output clocks */
  1033. of_sunxi_table_clock_setup(clk_divs_match, sunxi_divs_clk_setup);
  1034. /* Register mux clocks */
  1035. of_sunxi_table_clock_setup(clk_mux_match, sunxi_mux_clk_setup);
  1036. /* Register gate clocks */
  1037. of_sunxi_table_clock_setup(clk_gates_match, sunxi_gates_clk_setup);
  1038. /* Protect the clocks that needs to stay on */
  1039. for (i = 0; i < nclocks; i++) {
  1040. struct clk *clk = clk_get(NULL, clocks[i]);
  1041. if (!IS_ERR(clk))
  1042. clk_prepare_enable(clk);
  1043. }
  1044. }
  1045. static const char *sun4i_a10_critical_clocks[] __initdata = {
  1046. "pll5_ddr",
  1047. "ahb_sdram",
  1048. };
  1049. static void __init sun4i_a10_init_clocks(struct device_node *node)
  1050. {
  1051. sunxi_init_clocks(sun4i_a10_critical_clocks,
  1052. ARRAY_SIZE(sun4i_a10_critical_clocks));
  1053. }
  1054. CLK_OF_DECLARE(sun4i_a10_clk_init, "allwinner,sun4i-a10", sun4i_a10_init_clocks);
  1055. static const char *sun5i_critical_clocks[] __initdata = {
  1056. "mbus",
  1057. "pll5_ddr",
  1058. "ahb_sdram",
  1059. };
  1060. static void __init sun5i_init_clocks(struct device_node *node)
  1061. {
  1062. sunxi_init_clocks(sun5i_critical_clocks,
  1063. ARRAY_SIZE(sun5i_critical_clocks));
  1064. }
  1065. CLK_OF_DECLARE(sun5i_a10s_clk_init, "allwinner,sun5i-a10s", sun5i_init_clocks);
  1066. CLK_OF_DECLARE(sun5i_a13_clk_init, "allwinner,sun5i-a13", sun5i_init_clocks);
  1067. CLK_OF_DECLARE(sun7i_a20_clk_init, "allwinner,sun7i-a20", sun5i_init_clocks);
  1068. static const char *sun6i_critical_clocks[] __initdata = {
  1069. "cpu",
  1070. "ahb1_sdram",
  1071. };
  1072. static void __init sun6i_init_clocks(struct device_node *node)
  1073. {
  1074. sunxi_init_clocks(sun6i_critical_clocks,
  1075. ARRAY_SIZE(sun6i_critical_clocks));
  1076. }
  1077. CLK_OF_DECLARE(sun6i_a31_clk_init, "allwinner,sun6i-a31", sun6i_init_clocks);
  1078. CLK_OF_DECLARE(sun8i_a23_clk_init, "allwinner,sun8i-a23", sun6i_init_clocks);