clk-common.c 22 KB

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