clk-prima2.c 23 KB

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