clk-common.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035
  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 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 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 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 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 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 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. /* parent of io domain can only be pll3 */
  248. if (strcmp(hw->init->name, "io") == 0)
  249. return 4;
  250. WARN_ON((cfg & (BIT(3) - 1)) > 4);
  251. return cfg & (BIT(3) - 1);
  252. }
  253. static int dmn_clk_set_parent(struct clk_hw *hw, u8 parent)
  254. {
  255. struct clk_dmn *clk = to_dmnclk(hw);
  256. u32 cfg = clkc_readl(clk->regofs);
  257. /* parent of io domain can only be pll3 */
  258. if (strcmp(hw->init->name, "io") == 0)
  259. return -EINVAL;
  260. cfg &= ~(BIT(3) - 1);
  261. clkc_writel(cfg | parent, clk->regofs);
  262. /* BIT(3) - switching status: 1 - busy, 0 - done */
  263. while (clkc_readl(clk->regofs) & BIT(3))
  264. cpu_relax();
  265. return 0;
  266. }
  267. static unsigned long dmn_clk_recalc_rate(struct clk_hw *hw,
  268. unsigned long parent_rate)
  269. {
  270. unsigned long fin = parent_rate;
  271. struct clk_dmn *clk = to_dmnclk(hw);
  272. u32 cfg = clkc_readl(clk->regofs);
  273. if (cfg & BIT(24)) {
  274. /* fcd bypass mode */
  275. return fin;
  276. } else {
  277. /*
  278. * wait count: bit[19:16], hold count: bit[23:20]
  279. */
  280. u32 wait = (cfg >> 16) & (BIT(4) - 1);
  281. u32 hold = (cfg >> 20) & (BIT(4) - 1);
  282. return fin / (wait + hold + 2);
  283. }
  284. }
  285. static long dmn_clk_round_rate(struct clk_hw *hw, unsigned long rate,
  286. unsigned long *parent_rate)
  287. {
  288. unsigned long fin;
  289. unsigned ratio, wait, hold;
  290. unsigned bits = (strcmp(hw->init->name, "mem") == 0) ? 3 : 4;
  291. fin = *parent_rate;
  292. ratio = fin / rate;
  293. if (ratio < 2)
  294. ratio = 2;
  295. if (ratio > BIT(bits + 1))
  296. ratio = BIT(bits + 1);
  297. wait = (ratio >> 1) - 1;
  298. hold = ratio - wait - 2;
  299. return fin / (wait + hold + 2);
  300. }
  301. static int dmn_clk_set_rate(struct clk_hw *hw, unsigned long rate,
  302. unsigned long parent_rate)
  303. {
  304. struct clk_dmn *clk = to_dmnclk(hw);
  305. unsigned long fin;
  306. unsigned ratio, wait, hold, reg;
  307. unsigned bits = (strcmp(hw->init->name, "mem") == 0) ? 3 : 4;
  308. fin = parent_rate;
  309. ratio = fin / rate;
  310. if (unlikely(ratio < 2 || ratio > BIT(bits + 1)))
  311. return -EINVAL;
  312. WARN_ON(fin % rate);
  313. wait = (ratio >> 1) - 1;
  314. hold = ratio - wait - 2;
  315. reg = clkc_readl(clk->regofs);
  316. reg &= ~(((BIT(bits) - 1) << 16) | ((BIT(bits) - 1) << 20));
  317. reg |= (wait << 16) | (hold << 20) | BIT(25);
  318. clkc_writel(reg, clk->regofs);
  319. /* waiting FCD been effective */
  320. while (clkc_readl(clk->regofs) & BIT(25))
  321. cpu_relax();
  322. return 0;
  323. }
  324. static int cpu_clk_set_rate(struct clk_hw *hw, unsigned long rate,
  325. unsigned long parent_rate)
  326. {
  327. int ret1, ret2;
  328. struct clk *cur_parent;
  329. if (rate == clk_get_rate(clk_pll1.hw.clk)) {
  330. ret1 = clk_set_parent(hw->clk, clk_pll1.hw.clk);
  331. return ret1;
  332. }
  333. if (rate == clk_get_rate(clk_pll2.hw.clk)) {
  334. ret1 = clk_set_parent(hw->clk, clk_pll2.hw.clk);
  335. return ret1;
  336. }
  337. if (rate == clk_get_rate(clk_pll3.hw.clk)) {
  338. ret1 = clk_set_parent(hw->clk, clk_pll3.hw.clk);
  339. return ret1;
  340. }
  341. cur_parent = clk_get_parent(hw->clk);
  342. /* switch to tmp pll before setting parent clock's rate */
  343. if (cur_parent == clk_pll1.hw.clk) {
  344. ret1 = clk_set_parent(hw->clk, clk_pll2.hw.clk);
  345. BUG_ON(ret1);
  346. }
  347. ret2 = clk_set_rate(clk_pll1.hw.clk, rate);
  348. ret1 = clk_set_parent(hw->clk, clk_pll1.hw.clk);
  349. return ret2 ? ret2 : ret1;
  350. }
  351. static struct clk_ops msi_ops = {
  352. .set_rate = dmn_clk_set_rate,
  353. .round_rate = dmn_clk_round_rate,
  354. .recalc_rate = dmn_clk_recalc_rate,
  355. .set_parent = dmn_clk_set_parent,
  356. .get_parent = dmn_clk_get_parent,
  357. };
  358. static struct clk_init_data clk_mem_init = {
  359. .name = "mem",
  360. .ops = &msi_ops,
  361. .parent_names = dmn_clk_parents,
  362. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  363. };
  364. static struct clk_dmn clk_mem = {
  365. .regofs = SIRFSOC_CLKC_MEM_CFG,
  366. .hw = {
  367. .init = &clk_mem_init,
  368. },
  369. };
  370. static struct clk_init_data clk_sys_init = {
  371. .name = "sys",
  372. .ops = &msi_ops,
  373. .parent_names = dmn_clk_parents,
  374. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  375. .flags = CLK_SET_RATE_GATE,
  376. };
  377. static struct clk_dmn clk_sys = {
  378. .regofs = SIRFSOC_CLKC_SYS_CFG,
  379. .hw = {
  380. .init = &clk_sys_init,
  381. },
  382. };
  383. static struct clk_init_data clk_io_init = {
  384. .name = "io",
  385. .ops = &msi_ops,
  386. .parent_names = dmn_clk_parents,
  387. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  388. };
  389. static struct clk_dmn clk_io = {
  390. .regofs = SIRFSOC_CLKC_IO_CFG,
  391. .hw = {
  392. .init = &clk_io_init,
  393. },
  394. };
  395. static struct clk_ops cpu_ops = {
  396. .set_parent = dmn_clk_set_parent,
  397. .get_parent = dmn_clk_get_parent,
  398. .set_rate = cpu_clk_set_rate,
  399. .round_rate = cpu_clk_round_rate,
  400. .recalc_rate = cpu_clk_recalc_rate,
  401. };
  402. static struct clk_init_data clk_cpu_init = {
  403. .name = "cpu",
  404. .ops = &cpu_ops,
  405. .parent_names = dmn_clk_parents,
  406. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  407. .flags = CLK_SET_RATE_PARENT,
  408. };
  409. static struct clk_dmn clk_cpu = {
  410. .regofs = SIRFSOC_CLKC_CPU_CFG,
  411. .hw = {
  412. .init = &clk_cpu_init,
  413. },
  414. };
  415. static struct clk_ops dmn_ops = {
  416. .is_enabled = std_clk_is_enabled,
  417. .enable = std_clk_enable,
  418. .disable = std_clk_disable,
  419. .set_rate = dmn_clk_set_rate,
  420. .round_rate = dmn_clk_round_rate,
  421. .recalc_rate = dmn_clk_recalc_rate,
  422. .set_parent = dmn_clk_set_parent,
  423. .get_parent = dmn_clk_get_parent,
  424. };
  425. /* dsp, gfx, mm, lcd and vpp domain */
  426. static struct clk_init_data clk_dsp_init = {
  427. .name = "dsp",
  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_dsp = {
  433. .regofs = SIRFSOC_CLKC_DSP_CFG,
  434. .enable_bit = 0,
  435. .hw = {
  436. .init = &clk_dsp_init,
  437. },
  438. };
  439. static struct clk_init_data clk_gfx_init = {
  440. .name = "gfx",
  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_gfx = {
  446. .regofs = SIRFSOC_CLKC_GFX_CFG,
  447. .enable_bit = 8,
  448. .hw = {
  449. .init = &clk_gfx_init,
  450. },
  451. };
  452. static struct clk_init_data clk_mm_init = {
  453. .name = "mm",
  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_mm = {
  459. .regofs = SIRFSOC_CLKC_MM_CFG,
  460. .enable_bit = 9,
  461. .hw = {
  462. .init = &clk_mm_init,
  463. },
  464. };
  465. /*
  466. * for atlas6, gfx2d holds the bit of prima2's clk_mm
  467. */
  468. #define clk_gfx2d clk_mm
  469. static struct clk_init_data clk_lcd_init = {
  470. .name = "lcd",
  471. .ops = &dmn_ops,
  472. .parent_names = dmn_clk_parents,
  473. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  474. };
  475. static struct clk_dmn clk_lcd = {
  476. .regofs = SIRFSOC_CLKC_LCD_CFG,
  477. .enable_bit = 10,
  478. .hw = {
  479. .init = &clk_lcd_init,
  480. },
  481. };
  482. static struct clk_init_data clk_vpp_init = {
  483. .name = "vpp",
  484. .ops = &dmn_ops,
  485. .parent_names = dmn_clk_parents,
  486. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  487. };
  488. static struct clk_dmn clk_vpp = {
  489. .regofs = SIRFSOC_CLKC_LCD_CFG,
  490. .enable_bit = 11,
  491. .hw = {
  492. .init = &clk_vpp_init,
  493. },
  494. };
  495. static struct clk_init_data clk_mmc01_init = {
  496. .name = "mmc01",
  497. .ops = &dmn_ops,
  498. .parent_names = dmn_clk_parents,
  499. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  500. };
  501. static struct clk_init_data clk_mmc23_init = {
  502. .name = "mmc23",
  503. .ops = &dmn_ops,
  504. .parent_names = dmn_clk_parents,
  505. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  506. };
  507. static struct clk_init_data clk_mmc45_init = {
  508. .name = "mmc45",
  509. .ops = &dmn_ops,
  510. .parent_names = dmn_clk_parents,
  511. .num_parents = ARRAY_SIZE(dmn_clk_parents),
  512. };
  513. /*
  514. * peripheral controllers in io domain
  515. */
  516. static int std_clk_is_enabled(struct clk_hw *hw)
  517. {
  518. u32 reg;
  519. int bit;
  520. struct clk_std *clk = to_stdclk(hw);
  521. bit = clk->enable_bit % 32;
  522. reg = clk->enable_bit / 32;
  523. reg = SIRFSOC_CLKC_CLK_EN0 + reg * sizeof(reg);
  524. return !!(clkc_readl(reg) & BIT(bit));
  525. }
  526. static int std_clk_enable(struct clk_hw *hw)
  527. {
  528. u32 val, reg;
  529. int bit;
  530. struct clk_std *clk = to_stdclk(hw);
  531. BUG_ON(clk->enable_bit < 0 || clk->enable_bit > 63);
  532. bit = clk->enable_bit % 32;
  533. reg = clk->enable_bit / 32;
  534. reg = SIRFSOC_CLKC_CLK_EN0 + reg * sizeof(reg);
  535. val = clkc_readl(reg) | BIT(bit);
  536. clkc_writel(val, reg);
  537. return 0;
  538. }
  539. static void std_clk_disable(struct clk_hw *hw)
  540. {
  541. u32 val, reg;
  542. int bit;
  543. struct clk_std *clk = to_stdclk(hw);
  544. BUG_ON(clk->enable_bit < 0 || clk->enable_bit > 63);
  545. bit = clk->enable_bit % 32;
  546. reg = clk->enable_bit / 32;
  547. reg = SIRFSOC_CLKC_CLK_EN0 + reg * sizeof(reg);
  548. val = clkc_readl(reg) & ~BIT(bit);
  549. clkc_writel(val, reg);
  550. }
  551. static const char * const std_clk_io_parents[] = {
  552. "io",
  553. };
  554. static struct clk_ops ios_ops = {
  555. .is_enabled = std_clk_is_enabled,
  556. .enable = std_clk_enable,
  557. .disable = std_clk_disable,
  558. };
  559. static struct clk_init_data clk_cphif_init = {
  560. .name = "cphif",
  561. .ops = &ios_ops,
  562. .parent_names = std_clk_io_parents,
  563. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  564. };
  565. static struct clk_std clk_cphif = {
  566. .enable_bit = 20,
  567. .hw = {
  568. .init = &clk_cphif_init,
  569. },
  570. };
  571. static struct clk_init_data clk_dmac0_init = {
  572. .name = "dmac0",
  573. .ops = &ios_ops,
  574. .parent_names = std_clk_io_parents,
  575. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  576. };
  577. static struct clk_std clk_dmac0 = {
  578. .enable_bit = 32,
  579. .hw = {
  580. .init = &clk_dmac0_init,
  581. },
  582. };
  583. static struct clk_init_data clk_dmac1_init = {
  584. .name = "dmac1",
  585. .ops = &ios_ops,
  586. .parent_names = std_clk_io_parents,
  587. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  588. };
  589. static struct clk_std clk_dmac1 = {
  590. .enable_bit = 33,
  591. .hw = {
  592. .init = &clk_dmac1_init,
  593. },
  594. };
  595. static struct clk_init_data clk_audio_init = {
  596. .name = "audio",
  597. .ops = &ios_ops,
  598. .parent_names = std_clk_io_parents,
  599. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  600. };
  601. static struct clk_std clk_audio = {
  602. .enable_bit = 35,
  603. .hw = {
  604. .init = &clk_audio_init,
  605. },
  606. };
  607. static struct clk_init_data clk_uart0_init = {
  608. .name = "uart0",
  609. .ops = &ios_ops,
  610. .parent_names = std_clk_io_parents,
  611. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  612. };
  613. static struct clk_std clk_uart0 = {
  614. .enable_bit = 36,
  615. .hw = {
  616. .init = &clk_uart0_init,
  617. },
  618. };
  619. static struct clk_init_data clk_uart1_init = {
  620. .name = "uart1",
  621. .ops = &ios_ops,
  622. .parent_names = std_clk_io_parents,
  623. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  624. };
  625. static struct clk_std clk_uart1 = {
  626. .enable_bit = 37,
  627. .hw = {
  628. .init = &clk_uart1_init,
  629. },
  630. };
  631. static struct clk_init_data clk_uart2_init = {
  632. .name = "uart2",
  633. .ops = &ios_ops,
  634. .parent_names = std_clk_io_parents,
  635. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  636. };
  637. static struct clk_std clk_uart2 = {
  638. .enable_bit = 38,
  639. .hw = {
  640. .init = &clk_uart2_init,
  641. },
  642. };
  643. static struct clk_init_data clk_usp0_init = {
  644. .name = "usp0",
  645. .ops = &ios_ops,
  646. .parent_names = std_clk_io_parents,
  647. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  648. };
  649. static struct clk_std clk_usp0 = {
  650. .enable_bit = 39,
  651. .hw = {
  652. .init = &clk_usp0_init,
  653. },
  654. };
  655. static struct clk_init_data clk_usp1_init = {
  656. .name = "usp1",
  657. .ops = &ios_ops,
  658. .parent_names = std_clk_io_parents,
  659. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  660. };
  661. static struct clk_std clk_usp1 = {
  662. .enable_bit = 40,
  663. .hw = {
  664. .init = &clk_usp1_init,
  665. },
  666. };
  667. static struct clk_init_data clk_usp2_init = {
  668. .name = "usp2",
  669. .ops = &ios_ops,
  670. .parent_names = std_clk_io_parents,
  671. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  672. };
  673. static struct clk_std clk_usp2 = {
  674. .enable_bit = 41,
  675. .hw = {
  676. .init = &clk_usp2_init,
  677. },
  678. };
  679. static struct clk_init_data clk_vip_init = {
  680. .name = "vip",
  681. .ops = &ios_ops,
  682. .parent_names = std_clk_io_parents,
  683. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  684. };
  685. static struct clk_std clk_vip = {
  686. .enable_bit = 42,
  687. .hw = {
  688. .init = &clk_vip_init,
  689. },
  690. };
  691. static struct clk_init_data clk_spi0_init = {
  692. .name = "spi0",
  693. .ops = &ios_ops,
  694. .parent_names = std_clk_io_parents,
  695. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  696. };
  697. static struct clk_std clk_spi0 = {
  698. .enable_bit = 43,
  699. .hw = {
  700. .init = &clk_spi0_init,
  701. },
  702. };
  703. static struct clk_init_data clk_spi1_init = {
  704. .name = "spi1",
  705. .ops = &ios_ops,
  706. .parent_names = std_clk_io_parents,
  707. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  708. };
  709. static struct clk_std clk_spi1 = {
  710. .enable_bit = 44,
  711. .hw = {
  712. .init = &clk_spi1_init,
  713. },
  714. };
  715. static struct clk_init_data clk_tsc_init = {
  716. .name = "tsc",
  717. .ops = &ios_ops,
  718. .parent_names = std_clk_io_parents,
  719. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  720. };
  721. static struct clk_std clk_tsc = {
  722. .enable_bit = 45,
  723. .hw = {
  724. .init = &clk_tsc_init,
  725. },
  726. };
  727. static struct clk_init_data clk_i2c0_init = {
  728. .name = "i2c0",
  729. .ops = &ios_ops,
  730. .parent_names = std_clk_io_parents,
  731. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  732. };
  733. static struct clk_std clk_i2c0 = {
  734. .enable_bit = 46,
  735. .hw = {
  736. .init = &clk_i2c0_init,
  737. },
  738. };
  739. static struct clk_init_data clk_i2c1_init = {
  740. .name = "i2c1",
  741. .ops = &ios_ops,
  742. .parent_names = std_clk_io_parents,
  743. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  744. };
  745. static struct clk_std clk_i2c1 = {
  746. .enable_bit = 47,
  747. .hw = {
  748. .init = &clk_i2c1_init,
  749. },
  750. };
  751. static struct clk_init_data clk_pwmc_init = {
  752. .name = "pwmc",
  753. .ops = &ios_ops,
  754. .parent_names = std_clk_io_parents,
  755. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  756. };
  757. static struct clk_std clk_pwmc = {
  758. .enable_bit = 48,
  759. .hw = {
  760. .init = &clk_pwmc_init,
  761. },
  762. };
  763. static struct clk_init_data clk_efuse_init = {
  764. .name = "efuse",
  765. .ops = &ios_ops,
  766. .parent_names = std_clk_io_parents,
  767. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  768. };
  769. static struct clk_std clk_efuse = {
  770. .enable_bit = 49,
  771. .hw = {
  772. .init = &clk_efuse_init,
  773. },
  774. };
  775. static struct clk_init_data clk_pulse_init = {
  776. .name = "pulse",
  777. .ops = &ios_ops,
  778. .parent_names = std_clk_io_parents,
  779. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  780. };
  781. static struct clk_std clk_pulse = {
  782. .enable_bit = 50,
  783. .hw = {
  784. .init = &clk_pulse_init,
  785. },
  786. };
  787. static const char * const std_clk_dsp_parents[] = {
  788. "dsp",
  789. };
  790. static struct clk_init_data clk_gps_init = {
  791. .name = "gps",
  792. .ops = &ios_ops,
  793. .parent_names = std_clk_dsp_parents,
  794. .num_parents = ARRAY_SIZE(std_clk_dsp_parents),
  795. };
  796. static struct clk_std clk_gps = {
  797. .enable_bit = 1,
  798. .hw = {
  799. .init = &clk_gps_init,
  800. },
  801. };
  802. static struct clk_init_data clk_mf_init = {
  803. .name = "mf",
  804. .ops = &ios_ops,
  805. .parent_names = std_clk_io_parents,
  806. .num_parents = ARRAY_SIZE(std_clk_io_parents),
  807. };
  808. static struct clk_std clk_mf = {
  809. .enable_bit = 2,
  810. .hw = {
  811. .init = &clk_mf_init,
  812. },
  813. };
  814. static const char * const std_clk_sys_parents[] = {
  815. "sys",
  816. };
  817. static struct clk_init_data clk_security_init = {
  818. .name = "security",
  819. .ops = &ios_ops,
  820. .parent_names = std_clk_sys_parents,
  821. .num_parents = ARRAY_SIZE(std_clk_sys_parents),
  822. };
  823. static struct clk_std clk_security = {
  824. .enable_bit = 19,
  825. .hw = {
  826. .init = &clk_security_init,
  827. },
  828. };
  829. static const char * const std_clk_usb_parents[] = {
  830. "usb_pll",
  831. };
  832. static struct clk_init_data clk_usb0_init = {
  833. .name = "usb0",
  834. .ops = &ios_ops,
  835. .parent_names = std_clk_usb_parents,
  836. .num_parents = ARRAY_SIZE(std_clk_usb_parents),
  837. };
  838. static struct clk_std clk_usb0 = {
  839. .enable_bit = 16,
  840. .hw = {
  841. .init = &clk_usb0_init,
  842. },
  843. };
  844. static struct clk_init_data clk_usb1_init = {
  845. .name = "usb1",
  846. .ops = &ios_ops,
  847. .parent_names = std_clk_usb_parents,
  848. .num_parents = ARRAY_SIZE(std_clk_usb_parents),
  849. };
  850. static struct clk_std clk_usb1 = {
  851. .enable_bit = 17,
  852. .hw = {
  853. .init = &clk_usb1_init,
  854. },
  855. };