clk-common.c 21 KB

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