clock-mx23.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. /*
  2. * Copyright (C) 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include <linux/mm.h>
  19. #include <linux/delay.h>
  20. #include <linux/clk.h>
  21. #include <linux/io.h>
  22. #include <linux/jiffies.h>
  23. #include <linux/clkdev.h>
  24. #include <asm/clkdev.h>
  25. #include <asm/div64.h>
  26. #include <mach/mx23.h>
  27. #include <mach/common.h>
  28. #include <mach/clock.h>
  29. #include "regs-clkctrl-mx23.h"
  30. #define CLKCTRL_BASE_ADDR MX23_IO_ADDRESS(MX23_CLKCTRL_BASE_ADDR)
  31. #define DIGCTRL_BASE_ADDR MX23_IO_ADDRESS(MX23_DIGCTL_BASE_ADDR)
  32. #define PARENT_RATE_SHIFT 8
  33. static int _raw_clk_enable(struct clk *clk)
  34. {
  35. u32 reg;
  36. if (clk->enable_reg) {
  37. reg = __raw_readl(clk->enable_reg);
  38. reg &= ~(1 << clk->enable_shift);
  39. __raw_writel(reg, clk->enable_reg);
  40. }
  41. return 0;
  42. }
  43. static void _raw_clk_disable(struct clk *clk)
  44. {
  45. u32 reg;
  46. if (clk->enable_reg) {
  47. reg = __raw_readl(clk->enable_reg);
  48. reg |= 1 << clk->enable_shift;
  49. __raw_writel(reg, clk->enable_reg);
  50. }
  51. }
  52. /*
  53. * ref_xtal_clk
  54. */
  55. static unsigned long ref_xtal_clk_get_rate(struct clk *clk)
  56. {
  57. return 24000000;
  58. }
  59. static struct clk ref_xtal_clk = {
  60. .get_rate = ref_xtal_clk_get_rate,
  61. };
  62. /*
  63. * pll_clk
  64. */
  65. static unsigned long pll_clk_get_rate(struct clk *clk)
  66. {
  67. return 480000000;
  68. }
  69. static int pll_clk_enable(struct clk *clk)
  70. {
  71. __raw_writel(BM_CLKCTRL_PLLCTRL0_POWER |
  72. BM_CLKCTRL_PLLCTRL0_EN_USB_CLKS,
  73. CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLLCTRL0_SET);
  74. /* Only a 10us delay is need. PLLCTRL1 LOCK bitfied is only a timer
  75. * and is incorrect (excessive). Per definition of the PLLCTRL0
  76. * POWER field, waiting at least 10us.
  77. */
  78. udelay(10);
  79. return 0;
  80. }
  81. static void pll_clk_disable(struct clk *clk)
  82. {
  83. __raw_writel(BM_CLKCTRL_PLLCTRL0_POWER |
  84. BM_CLKCTRL_PLLCTRL0_EN_USB_CLKS,
  85. CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLLCTRL0_CLR);
  86. }
  87. static struct clk pll_clk = {
  88. .get_rate = pll_clk_get_rate,
  89. .enable = pll_clk_enable,
  90. .disable = pll_clk_disable,
  91. .parent = &ref_xtal_clk,
  92. };
  93. /*
  94. * ref_clk
  95. */
  96. #define _CLK_GET_RATE_REF(name, sr, ss) \
  97. static unsigned long name##_get_rate(struct clk *clk) \
  98. { \
  99. unsigned long parent_rate; \
  100. u32 reg, div; \
  101. \
  102. reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##sr); \
  103. div = (reg >> BP_CLKCTRL_##sr##_##ss##FRAC) & 0x3f; \
  104. parent_rate = clk_get_rate(clk->parent); \
  105. \
  106. return SH_DIV((parent_rate >> PARENT_RATE_SHIFT) * 18, \
  107. div, PARENT_RATE_SHIFT); \
  108. }
  109. _CLK_GET_RATE_REF(ref_cpu_clk, FRAC, CPU)
  110. _CLK_GET_RATE_REF(ref_emi_clk, FRAC, EMI)
  111. _CLK_GET_RATE_REF(ref_pix_clk, FRAC, PIX)
  112. _CLK_GET_RATE_REF(ref_io_clk, FRAC, IO)
  113. #define _DEFINE_CLOCK_REF(name, er, es) \
  114. static struct clk name = { \
  115. .enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_##er, \
  116. .enable_shift = BP_CLKCTRL_##er##_CLKGATE##es, \
  117. .get_rate = name##_get_rate, \
  118. .enable = _raw_clk_enable, \
  119. .disable = _raw_clk_disable, \
  120. .parent = &pll_clk, \
  121. }
  122. _DEFINE_CLOCK_REF(ref_cpu_clk, FRAC, CPU);
  123. _DEFINE_CLOCK_REF(ref_emi_clk, FRAC, EMI);
  124. _DEFINE_CLOCK_REF(ref_pix_clk, FRAC, PIX);
  125. _DEFINE_CLOCK_REF(ref_io_clk, FRAC, IO);
  126. /*
  127. * General clocks
  128. *
  129. * clk_get_rate
  130. */
  131. static unsigned long rtc_clk_get_rate(struct clk *clk)
  132. {
  133. /* ref_xtal_clk is implemented as the only parent */
  134. return clk_get_rate(clk->parent) / 768;
  135. }
  136. static unsigned long clk32k_clk_get_rate(struct clk *clk)
  137. {
  138. return clk->parent->get_rate(clk->parent) / 750;
  139. }
  140. #define _CLK_GET_RATE(name, rs) \
  141. static unsigned long name##_get_rate(struct clk *clk) \
  142. { \
  143. u32 reg, div; \
  144. \
  145. reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##rs); \
  146. \
  147. if (clk->parent == &ref_xtal_clk) \
  148. div = (reg & BM_CLKCTRL_##rs##_DIV_XTAL) >> \
  149. BP_CLKCTRL_##rs##_DIV_XTAL; \
  150. else \
  151. div = (reg & BM_CLKCTRL_##rs##_DIV_##rs) >> \
  152. BP_CLKCTRL_##rs##_DIV_##rs; \
  153. \
  154. if (!div) \
  155. return -EINVAL; \
  156. \
  157. return clk_get_rate(clk->parent) / div; \
  158. }
  159. _CLK_GET_RATE(cpu_clk, CPU)
  160. _CLK_GET_RATE(emi_clk, EMI)
  161. #define _CLK_GET_RATE1(name, rs) \
  162. static unsigned long name##_get_rate(struct clk *clk) \
  163. { \
  164. u32 reg, div; \
  165. \
  166. reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##rs); \
  167. div = (reg & BM_CLKCTRL_##rs##_DIV) >> BP_CLKCTRL_##rs##_DIV; \
  168. \
  169. if (!div) \
  170. return -EINVAL; \
  171. \
  172. return clk_get_rate(clk->parent) / div; \
  173. }
  174. _CLK_GET_RATE1(hbus_clk, HBUS)
  175. _CLK_GET_RATE1(xbus_clk, XBUS)
  176. _CLK_GET_RATE1(ssp_clk, SSP)
  177. _CLK_GET_RATE1(gpmi_clk, GPMI)
  178. _CLK_GET_RATE1(lcdif_clk, PIX)
  179. #define _CLK_GET_RATE_STUB(name) \
  180. static unsigned long name##_get_rate(struct clk *clk) \
  181. { \
  182. return clk_get_rate(clk->parent); \
  183. }
  184. _CLK_GET_RATE_STUB(uart_clk)
  185. _CLK_GET_RATE_STUB(audio_clk)
  186. _CLK_GET_RATE_STUB(pwm_clk)
  187. /*
  188. * clk_set_rate
  189. */
  190. static int cpu_clk_set_rate(struct clk *clk, unsigned long rate)
  191. {
  192. u32 reg, bm_busy, div_max, d, f, div, frac;
  193. unsigned long diff, parent_rate, calc_rate;
  194. int i;
  195. parent_rate = clk_get_rate(clk->parent);
  196. if (clk->parent == &ref_xtal_clk) {
  197. div_max = BM_CLKCTRL_CPU_DIV_XTAL >> BP_CLKCTRL_CPU_DIV_XTAL;
  198. bm_busy = BM_CLKCTRL_CPU_BUSY_REF_XTAL;
  199. div = DIV_ROUND_UP(parent_rate, rate);
  200. if (div == 0 || div > div_max)
  201. return -EINVAL;
  202. } else {
  203. div_max = BM_CLKCTRL_CPU_DIV_CPU >> BP_CLKCTRL_CPU_DIV_CPU;
  204. bm_busy = BM_CLKCTRL_CPU_BUSY_REF_CPU;
  205. rate >>= PARENT_RATE_SHIFT;
  206. parent_rate >>= PARENT_RATE_SHIFT;
  207. diff = parent_rate;
  208. div = frac = 1;
  209. for (d = 1; d <= div_max; d++) {
  210. f = parent_rate * 18 / d / rate;
  211. if ((parent_rate * 18 / d) % rate)
  212. f++;
  213. if (f < 18 || f > 35)
  214. continue;
  215. calc_rate = parent_rate * 18 / f / d;
  216. if (calc_rate > rate)
  217. continue;
  218. if (rate - calc_rate < diff) {
  219. frac = f;
  220. div = d;
  221. diff = rate - calc_rate;
  222. }
  223. if (diff == 0)
  224. break;
  225. }
  226. if (diff == parent_rate)
  227. return -EINVAL;
  228. reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_FRAC);
  229. reg &= ~BM_CLKCTRL_FRAC_CPUFRAC;
  230. reg |= frac;
  231. __raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_FRAC);
  232. }
  233. reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_CPU);
  234. reg &= ~BM_CLKCTRL_CPU_DIV_CPU;
  235. reg |= div << BP_CLKCTRL_CPU_DIV_CPU;
  236. __raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_CPU);
  237. for (i = 10000; i; i--)
  238. if (!(__raw_readl(CLKCTRL_BASE_ADDR +
  239. HW_CLKCTRL_CPU) & bm_busy))
  240. break;
  241. if (!i) {
  242. pr_err("%s: divider writing timeout\n", __func__);
  243. return -ETIMEDOUT;
  244. }
  245. return 0;
  246. }
  247. #define _CLK_SET_RATE(name, dr) \
  248. static int name##_set_rate(struct clk *clk, unsigned long rate) \
  249. { \
  250. u32 reg, div_max, div; \
  251. unsigned long parent_rate; \
  252. int i; \
  253. \
  254. parent_rate = clk_get_rate(clk->parent); \
  255. div_max = BM_CLKCTRL_##dr##_DIV >> BP_CLKCTRL_##dr##_DIV; \
  256. \
  257. div = DIV_ROUND_UP(parent_rate, rate); \
  258. if (div == 0 || div > div_max) \
  259. return -EINVAL; \
  260. \
  261. reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##dr); \
  262. reg &= ~BM_CLKCTRL_##dr##_DIV; \
  263. reg |= div << BP_CLKCTRL_##dr##_DIV; \
  264. if (reg & (1 << clk->enable_shift)) { \
  265. pr_err("%s: clock is gated\n", __func__); \
  266. return -EINVAL; \
  267. } \
  268. __raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_##dr); \
  269. \
  270. for (i = 10000; i; i--) \
  271. if (!(__raw_readl(CLKCTRL_BASE_ADDR + \
  272. HW_CLKCTRL_##dr) & BM_CLKCTRL_##dr##_BUSY)) \
  273. break; \
  274. if (!i) { \
  275. pr_err("%s: divider writing timeout\n", __func__); \
  276. return -ETIMEDOUT; \
  277. } \
  278. \
  279. return 0; \
  280. }
  281. _CLK_SET_RATE(xbus_clk, XBUS)
  282. _CLK_SET_RATE(ssp_clk, SSP)
  283. _CLK_SET_RATE(gpmi_clk, GPMI)
  284. _CLK_SET_RATE(lcdif_clk, PIX)
  285. #define _CLK_SET_RATE_STUB(name) \
  286. static int name##_set_rate(struct clk *clk, unsigned long rate) \
  287. { \
  288. return -EINVAL; \
  289. }
  290. _CLK_SET_RATE_STUB(emi_clk)
  291. _CLK_SET_RATE_STUB(uart_clk)
  292. _CLK_SET_RATE_STUB(audio_clk)
  293. _CLK_SET_RATE_STUB(pwm_clk)
  294. _CLK_SET_RATE_STUB(clk32k_clk)
  295. /*
  296. * clk_set_parent
  297. */
  298. #define _CLK_SET_PARENT(name, bit) \
  299. static int name##_set_parent(struct clk *clk, struct clk *parent) \
  300. { \
  301. if (parent != clk->parent) { \
  302. __raw_writel(BM_CLKCTRL_CLKSEQ_BYPASS_##bit, \
  303. CLKCTRL_BASE_ADDR + HW_CLKCTRL_CLKSEQ_TOG); \
  304. clk->parent = parent; \
  305. } \
  306. \
  307. return 0; \
  308. }
  309. _CLK_SET_PARENT(cpu_clk, CPU)
  310. _CLK_SET_PARENT(emi_clk, EMI)
  311. _CLK_SET_PARENT(ssp_clk, SSP)
  312. _CLK_SET_PARENT(gpmi_clk, GPMI)
  313. _CLK_SET_PARENT(lcdif_clk, PIX)
  314. #define _CLK_SET_PARENT_STUB(name) \
  315. static int name##_set_parent(struct clk *clk, struct clk *parent) \
  316. { \
  317. if (parent != clk->parent) \
  318. return -EINVAL; \
  319. else \
  320. return 0; \
  321. }
  322. _CLK_SET_PARENT_STUB(uart_clk)
  323. _CLK_SET_PARENT_STUB(audio_clk)
  324. _CLK_SET_PARENT_STUB(pwm_clk)
  325. _CLK_SET_PARENT_STUB(clk32k_clk)
  326. /*
  327. * clk definition
  328. */
  329. static struct clk cpu_clk = {
  330. .get_rate = cpu_clk_get_rate,
  331. .set_rate = cpu_clk_set_rate,
  332. .set_parent = cpu_clk_set_parent,
  333. .parent = &ref_cpu_clk,
  334. };
  335. static struct clk hbus_clk = {
  336. .get_rate = hbus_clk_get_rate,
  337. .parent = &cpu_clk,
  338. };
  339. static struct clk xbus_clk = {
  340. .get_rate = xbus_clk_get_rate,
  341. .set_rate = xbus_clk_set_rate,
  342. .parent = &ref_xtal_clk,
  343. };
  344. static struct clk rtc_clk = {
  345. .get_rate = rtc_clk_get_rate,
  346. .parent = &ref_xtal_clk,
  347. };
  348. /* usb_clk gate is controlled in DIGCTRL other than CLKCTRL */
  349. static struct clk usb_clk = {
  350. .enable_reg = DIGCTRL_BASE_ADDR,
  351. .enable_shift = 2,
  352. .enable = _raw_clk_enable,
  353. .disable = _raw_clk_disable,
  354. .parent = &pll_clk,
  355. };
  356. #define _DEFINE_CLOCK(name, er, es, p) \
  357. static struct clk name = { \
  358. .enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_##er, \
  359. .enable_shift = BP_CLKCTRL_##er##_##es, \
  360. .get_rate = name##_get_rate, \
  361. .set_rate = name##_set_rate, \
  362. .set_parent = name##_set_parent, \
  363. .enable = _raw_clk_enable, \
  364. .disable = _raw_clk_disable, \
  365. .parent = p, \
  366. }
  367. _DEFINE_CLOCK(emi_clk, EMI, CLKGATE, &ref_xtal_clk);
  368. _DEFINE_CLOCK(ssp_clk, SSP, CLKGATE, &ref_xtal_clk);
  369. _DEFINE_CLOCK(gpmi_clk, GPMI, CLKGATE, &ref_xtal_clk);
  370. _DEFINE_CLOCK(lcdif_clk, PIX, CLKGATE, &ref_xtal_clk);
  371. _DEFINE_CLOCK(uart_clk, XTAL, UART_CLK_GATE, &ref_xtal_clk);
  372. _DEFINE_CLOCK(audio_clk, XTAL, FILT_CLK24M_GATE, &ref_xtal_clk);
  373. _DEFINE_CLOCK(pwm_clk, XTAL, PWM_CLK24M_GATE, &ref_xtal_clk);
  374. _DEFINE_CLOCK(clk32k_clk, XTAL, TIMROT_CLK32K_GATE, &ref_xtal_clk);
  375. #define _REGISTER_CLOCK(d, n, c) \
  376. { \
  377. .dev_id = d, \
  378. .con_id = n, \
  379. .clk = &c, \
  380. },
  381. static struct clk_lookup lookups[] = {
  382. /* for amba bus driver */
  383. _REGISTER_CLOCK("duart", "apb_pclk", xbus_clk)
  384. /* for amba-pl011 driver */
  385. _REGISTER_CLOCK("duart", NULL, uart_clk)
  386. _REGISTER_CLOCK("mxs-auart.0", NULL, uart_clk)
  387. _REGISTER_CLOCK("rtc", NULL, rtc_clk)
  388. _REGISTER_CLOCK("mxs-dma-apbh", NULL, hbus_clk)
  389. _REGISTER_CLOCK("mxs-dma-apbx", NULL, xbus_clk)
  390. _REGISTER_CLOCK("mxs-mmc.0", NULL, ssp_clk)
  391. _REGISTER_CLOCK("mxs-mmc.1", NULL, ssp_clk)
  392. _REGISTER_CLOCK(NULL, "usb", usb_clk)
  393. _REGISTER_CLOCK(NULL, "audio", audio_clk)
  394. _REGISTER_CLOCK("mxs-pwm.0", NULL, pwm_clk)
  395. _REGISTER_CLOCK("mxs-pwm.1", NULL, pwm_clk)
  396. _REGISTER_CLOCK("mxs-pwm.2", NULL, pwm_clk)
  397. _REGISTER_CLOCK("mxs-pwm.3", NULL, pwm_clk)
  398. _REGISTER_CLOCK("mxs-pwm.4", NULL, pwm_clk)
  399. _REGISTER_CLOCK("imx23-fb", NULL, lcdif_clk)
  400. };
  401. static int clk_misc_init(void)
  402. {
  403. u32 reg;
  404. int i;
  405. /* Fix up parent per register setting */
  406. reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_CLKSEQ);
  407. cpu_clk.parent = (reg & BM_CLKCTRL_CLKSEQ_BYPASS_CPU) ?
  408. &ref_xtal_clk : &ref_cpu_clk;
  409. emi_clk.parent = (reg & BM_CLKCTRL_CLKSEQ_BYPASS_EMI) ?
  410. &ref_xtal_clk : &ref_emi_clk;
  411. ssp_clk.parent = (reg & BM_CLKCTRL_CLKSEQ_BYPASS_SSP) ?
  412. &ref_xtal_clk : &ref_io_clk;
  413. gpmi_clk.parent = (reg & BM_CLKCTRL_CLKSEQ_BYPASS_GPMI) ?
  414. &ref_xtal_clk : &ref_io_clk;
  415. lcdif_clk.parent = (reg & BM_CLKCTRL_CLKSEQ_BYPASS_PIX) ?
  416. &ref_xtal_clk : &ref_pix_clk;
  417. /* Use int div over frac when both are available */
  418. __raw_writel(BM_CLKCTRL_CPU_DIV_XTAL_FRAC_EN,
  419. CLKCTRL_BASE_ADDR + HW_CLKCTRL_CPU_CLR);
  420. __raw_writel(BM_CLKCTRL_CPU_DIV_CPU_FRAC_EN,
  421. CLKCTRL_BASE_ADDR + HW_CLKCTRL_CPU_CLR);
  422. __raw_writel(BM_CLKCTRL_HBUS_DIV_FRAC_EN,
  423. CLKCTRL_BASE_ADDR + HW_CLKCTRL_HBUS_CLR);
  424. reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_XBUS);
  425. reg &= ~BM_CLKCTRL_XBUS_DIV_FRAC_EN;
  426. __raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_XBUS);
  427. reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_SSP);
  428. reg &= ~BM_CLKCTRL_SSP_DIV_FRAC_EN;
  429. __raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_SSP);
  430. reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_GPMI);
  431. reg &= ~BM_CLKCTRL_GPMI_DIV_FRAC_EN;
  432. __raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_GPMI);
  433. reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_PIX);
  434. reg &= ~BM_CLKCTRL_PIX_DIV_FRAC_EN;
  435. __raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_PIX);
  436. /*
  437. * Set safe hbus clock divider. A divider of 3 ensure that
  438. * the Vddd voltage required for the cpu clock is sufficiently
  439. * high for the hbus clock.
  440. */
  441. reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_HBUS);
  442. reg &= BM_CLKCTRL_HBUS_DIV;
  443. reg |= 3 << BP_CLKCTRL_HBUS_DIV;
  444. __raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_HBUS);
  445. for (i = 10000; i; i--)
  446. if (!(__raw_readl(CLKCTRL_BASE_ADDR +
  447. HW_CLKCTRL_HBUS) & BM_CLKCTRL_HBUS_BUSY))
  448. break;
  449. if (!i) {
  450. pr_err("%s: divider writing timeout\n", __func__);
  451. return -ETIMEDOUT;
  452. }
  453. /* Gate off cpu clock in WFI for power saving */
  454. __raw_writel(BM_CLKCTRL_CPU_INTERRUPT_WAIT,
  455. CLKCTRL_BASE_ADDR + HW_CLKCTRL_CPU_SET);
  456. /*
  457. * 480 MHz seems too high to be ssp clock source directly,
  458. * so set frac to get a 288 MHz ref_io.
  459. */
  460. reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_FRAC);
  461. reg &= ~BM_CLKCTRL_FRAC_IOFRAC;
  462. reg |= 30 << BP_CLKCTRL_FRAC_IOFRAC;
  463. __raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_FRAC);
  464. return 0;
  465. }
  466. int __init mx23_clocks_init(void)
  467. {
  468. clk_misc_init();
  469. /*
  470. * source ssp clock from ref_io than ref_xtal,
  471. * as ref_xtal only provides 24 MHz as maximum.
  472. */
  473. clk_set_parent(&ssp_clk, &ref_io_clk);
  474. clk_enable(&cpu_clk);
  475. clk_enable(&hbus_clk);
  476. clk_enable(&xbus_clk);
  477. clk_enable(&emi_clk);
  478. clk_enable(&uart_clk);
  479. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  480. mxs_timer_init(&clk32k_clk, MX23_INT_TIMER0);
  481. return 0;
  482. }