clock-imx31.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /*
  2. * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  3. * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  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
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17. * MA 02110-1301, USA.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/delay.h>
  22. #include <linux/clk.h>
  23. #include <linux/err.h>
  24. #include <linux/io.h>
  25. #include <linux/clkdev.h>
  26. #include <asm/div64.h>
  27. #include <mach/clock.h>
  28. #include <mach/hardware.h>
  29. #include <mach/mx31.h>
  30. #include <mach/common.h>
  31. #include "crmregs-imx31.h"
  32. #define PRE_DIV_MIN_FREQ 10000000 /* Minimum Frequency after Predivider */
  33. static void __calc_pre_post_dividers(u32 div, u32 *pre, u32 *post)
  34. {
  35. u32 min_pre, temp_pre, old_err, err;
  36. if (div >= 512) {
  37. *pre = 8;
  38. *post = 64;
  39. } else if (div >= 64) {
  40. min_pre = (div - 1) / 64 + 1;
  41. old_err = 8;
  42. for (temp_pre = 8; temp_pre >= min_pre; temp_pre--) {
  43. err = div % temp_pre;
  44. if (err == 0) {
  45. *pre = temp_pre;
  46. break;
  47. }
  48. err = temp_pre - err;
  49. if (err < old_err) {
  50. old_err = err;
  51. *pre = temp_pre;
  52. }
  53. }
  54. *post = (div + *pre - 1) / *pre;
  55. } else if (div <= 8) {
  56. *pre = div;
  57. *post = 1;
  58. } else {
  59. *pre = 1;
  60. *post = div;
  61. }
  62. }
  63. static struct clk mcu_pll_clk;
  64. static struct clk serial_pll_clk;
  65. static struct clk ipg_clk;
  66. static struct clk ckih_clk;
  67. static int cgr_enable(struct clk *clk)
  68. {
  69. u32 reg;
  70. if (!clk->enable_reg)
  71. return 0;
  72. reg = __raw_readl(clk->enable_reg);
  73. reg |= 3 << clk->enable_shift;
  74. __raw_writel(reg, clk->enable_reg);
  75. return 0;
  76. }
  77. static void cgr_disable(struct clk *clk)
  78. {
  79. u32 reg;
  80. if (!clk->enable_reg)
  81. return;
  82. reg = __raw_readl(clk->enable_reg);
  83. reg &= ~(3 << clk->enable_shift);
  84. /* special case for EMI clock */
  85. if (clk->enable_reg == MXC_CCM_CGR2 && clk->enable_shift == 8)
  86. reg |= (1 << clk->enable_shift);
  87. __raw_writel(reg, clk->enable_reg);
  88. }
  89. static unsigned long pll_ref_get_rate(void)
  90. {
  91. unsigned long ccmr;
  92. unsigned int prcs;
  93. ccmr = __raw_readl(MXC_CCM_CCMR);
  94. prcs = (ccmr & MXC_CCM_CCMR_PRCS_MASK) >> MXC_CCM_CCMR_PRCS_OFFSET;
  95. if (prcs == 0x1)
  96. return CKIL_CLK_FREQ * 1024;
  97. else
  98. return clk_get_rate(&ckih_clk);
  99. }
  100. static unsigned long usb_pll_get_rate(struct clk *clk)
  101. {
  102. unsigned long reg;
  103. reg = __raw_readl(MXC_CCM_UPCTL);
  104. return mxc_decode_pll(reg, pll_ref_get_rate());
  105. }
  106. static unsigned long serial_pll_get_rate(struct clk *clk)
  107. {
  108. unsigned long reg;
  109. reg = __raw_readl(MXC_CCM_SRPCTL);
  110. return mxc_decode_pll(reg, pll_ref_get_rate());
  111. }
  112. static unsigned long mcu_pll_get_rate(struct clk *clk)
  113. {
  114. unsigned long reg, ccmr;
  115. ccmr = __raw_readl(MXC_CCM_CCMR);
  116. if (!(ccmr & MXC_CCM_CCMR_MPE) || (ccmr & MXC_CCM_CCMR_MDS))
  117. return clk_get_rate(&ckih_clk);
  118. reg = __raw_readl(MXC_CCM_MPCTL);
  119. return mxc_decode_pll(reg, pll_ref_get_rate());
  120. }
  121. static int usb_pll_enable(struct clk *clk)
  122. {
  123. u32 reg;
  124. reg = __raw_readl(MXC_CCM_CCMR);
  125. reg |= MXC_CCM_CCMR_UPE;
  126. __raw_writel(reg, MXC_CCM_CCMR);
  127. /* No lock bit on MX31, so using max time from spec */
  128. udelay(80);
  129. return 0;
  130. }
  131. static void usb_pll_disable(struct clk *clk)
  132. {
  133. u32 reg;
  134. reg = __raw_readl(MXC_CCM_CCMR);
  135. reg &= ~MXC_CCM_CCMR_UPE;
  136. __raw_writel(reg, MXC_CCM_CCMR);
  137. }
  138. static int serial_pll_enable(struct clk *clk)
  139. {
  140. u32 reg;
  141. reg = __raw_readl(MXC_CCM_CCMR);
  142. reg |= MXC_CCM_CCMR_SPE;
  143. __raw_writel(reg, MXC_CCM_CCMR);
  144. /* No lock bit on MX31, so using max time from spec */
  145. udelay(80);
  146. return 0;
  147. }
  148. static void serial_pll_disable(struct clk *clk)
  149. {
  150. u32 reg;
  151. reg = __raw_readl(MXC_CCM_CCMR);
  152. reg &= ~MXC_CCM_CCMR_SPE;
  153. __raw_writel(reg, MXC_CCM_CCMR);
  154. }
  155. #define PDR0(mask, off) ((__raw_readl(MXC_CCM_PDR0) & mask) >> off)
  156. #define PDR1(mask, off) ((__raw_readl(MXC_CCM_PDR1) & mask) >> off)
  157. #define PDR2(mask, off) ((__raw_readl(MXC_CCM_PDR2) & mask) >> off)
  158. static unsigned long mcu_main_get_rate(struct clk *clk)
  159. {
  160. u32 pmcr0 = __raw_readl(MXC_CCM_PMCR0);
  161. if ((pmcr0 & MXC_CCM_PMCR0_DFSUP1) == MXC_CCM_PMCR0_DFSUP1_SPLL)
  162. return clk_get_rate(&serial_pll_clk);
  163. else
  164. return clk_get_rate(&mcu_pll_clk);
  165. }
  166. static unsigned long ahb_get_rate(struct clk *clk)
  167. {
  168. unsigned long max_pdf;
  169. max_pdf = PDR0(MXC_CCM_PDR0_MAX_PODF_MASK,
  170. MXC_CCM_PDR0_MAX_PODF_OFFSET);
  171. return clk_get_rate(clk->parent) / (max_pdf + 1);
  172. }
  173. static unsigned long ipg_get_rate(struct clk *clk)
  174. {
  175. unsigned long ipg_pdf;
  176. ipg_pdf = PDR0(MXC_CCM_PDR0_IPG_PODF_MASK,
  177. MXC_CCM_PDR0_IPG_PODF_OFFSET);
  178. return clk_get_rate(clk->parent) / (ipg_pdf + 1);
  179. }
  180. static unsigned long nfc_get_rate(struct clk *clk)
  181. {
  182. unsigned long nfc_pdf;
  183. nfc_pdf = PDR0(MXC_CCM_PDR0_NFC_PODF_MASK,
  184. MXC_CCM_PDR0_NFC_PODF_OFFSET);
  185. return clk_get_rate(clk->parent) / (nfc_pdf + 1);
  186. }
  187. static unsigned long hsp_get_rate(struct clk *clk)
  188. {
  189. unsigned long hsp_pdf;
  190. hsp_pdf = PDR0(MXC_CCM_PDR0_HSP_PODF_MASK,
  191. MXC_CCM_PDR0_HSP_PODF_OFFSET);
  192. return clk_get_rate(clk->parent) / (hsp_pdf + 1);
  193. }
  194. static unsigned long usb_get_rate(struct clk *clk)
  195. {
  196. unsigned long usb_pdf, usb_prepdf;
  197. usb_pdf = PDR1(MXC_CCM_PDR1_USB_PODF_MASK,
  198. MXC_CCM_PDR1_USB_PODF_OFFSET);
  199. usb_prepdf = PDR1(MXC_CCM_PDR1_USB_PRDF_MASK,
  200. MXC_CCM_PDR1_USB_PRDF_OFFSET);
  201. return clk_get_rate(clk->parent) / (usb_prepdf + 1) / (usb_pdf + 1);
  202. }
  203. static unsigned long csi_get_rate(struct clk *clk)
  204. {
  205. u32 reg, pre, post;
  206. reg = __raw_readl(MXC_CCM_PDR0);
  207. pre = (reg & MXC_CCM_PDR0_CSI_PRDF_MASK) >>
  208. MXC_CCM_PDR0_CSI_PRDF_OFFSET;
  209. pre++;
  210. post = (reg & MXC_CCM_PDR0_CSI_PODF_MASK) >>
  211. MXC_CCM_PDR0_CSI_PODF_OFFSET;
  212. post++;
  213. return clk_get_rate(clk->parent) / (pre * post);
  214. }
  215. static unsigned long csi_round_rate(struct clk *clk, unsigned long rate)
  216. {
  217. u32 pre, post, parent = clk_get_rate(clk->parent);
  218. u32 div = parent / rate;
  219. if (parent % rate)
  220. div++;
  221. __calc_pre_post_dividers(div, &pre, &post);
  222. return parent / (pre * post);
  223. }
  224. static int csi_set_rate(struct clk *clk, unsigned long rate)
  225. {
  226. u32 reg, div, pre, post, parent = clk_get_rate(clk->parent);
  227. div = parent / rate;
  228. if ((parent / div) != rate)
  229. return -EINVAL;
  230. __calc_pre_post_dividers(div, &pre, &post);
  231. /* Set CSI clock divider */
  232. reg = __raw_readl(MXC_CCM_PDR0) &
  233. ~(MXC_CCM_PDR0_CSI_PODF_MASK | MXC_CCM_PDR0_CSI_PRDF_MASK);
  234. reg |= (post - 1) << MXC_CCM_PDR0_CSI_PODF_OFFSET;
  235. reg |= (pre - 1) << MXC_CCM_PDR0_CSI_PRDF_OFFSET;
  236. __raw_writel(reg, MXC_CCM_PDR0);
  237. return 0;
  238. }
  239. static unsigned long ssi1_get_rate(struct clk *clk)
  240. {
  241. unsigned long ssi1_pdf, ssi1_prepdf;
  242. ssi1_pdf = PDR1(MXC_CCM_PDR1_SSI1_PODF_MASK,
  243. MXC_CCM_PDR1_SSI1_PODF_OFFSET);
  244. ssi1_prepdf = PDR1(MXC_CCM_PDR1_SSI1_PRE_PODF_MASK,
  245. MXC_CCM_PDR1_SSI1_PRE_PODF_OFFSET);
  246. return clk_get_rate(clk->parent) / (ssi1_prepdf + 1) / (ssi1_pdf + 1);
  247. }
  248. static unsigned long ssi2_get_rate(struct clk *clk)
  249. {
  250. unsigned long ssi2_pdf, ssi2_prepdf;
  251. ssi2_pdf = PDR1(MXC_CCM_PDR1_SSI2_PODF_MASK,
  252. MXC_CCM_PDR1_SSI2_PODF_OFFSET);
  253. ssi2_prepdf = PDR1(MXC_CCM_PDR1_SSI2_PRE_PODF_MASK,
  254. MXC_CCM_PDR1_SSI2_PRE_PODF_OFFSET);
  255. return clk_get_rate(clk->parent) / (ssi2_prepdf + 1) / (ssi2_pdf + 1);
  256. }
  257. static unsigned long firi_get_rate(struct clk *clk)
  258. {
  259. unsigned long firi_pdf, firi_prepdf;
  260. firi_pdf = PDR1(MXC_CCM_PDR1_FIRI_PODF_MASK,
  261. MXC_CCM_PDR1_FIRI_PODF_OFFSET);
  262. firi_prepdf = PDR1(MXC_CCM_PDR1_FIRI_PRE_PODF_MASK,
  263. MXC_CCM_PDR1_FIRI_PRE_PODF_OFFSET);
  264. return clk_get_rate(clk->parent) / (firi_prepdf + 1) / (firi_pdf + 1);
  265. }
  266. static unsigned long firi_round_rate(struct clk *clk, unsigned long rate)
  267. {
  268. u32 pre, post;
  269. u32 parent = clk_get_rate(clk->parent);
  270. u32 div = parent / rate;
  271. if (parent % rate)
  272. div++;
  273. __calc_pre_post_dividers(div, &pre, &post);
  274. return parent / (pre * post);
  275. }
  276. static int firi_set_rate(struct clk *clk, unsigned long rate)
  277. {
  278. u32 reg, div, pre, post, parent = clk_get_rate(clk->parent);
  279. div = parent / rate;
  280. if ((parent / div) != rate)
  281. return -EINVAL;
  282. __calc_pre_post_dividers(div, &pre, &post);
  283. /* Set FIRI clock divider */
  284. reg = __raw_readl(MXC_CCM_PDR1) &
  285. ~(MXC_CCM_PDR1_FIRI_PODF_MASK | MXC_CCM_PDR1_FIRI_PRE_PODF_MASK);
  286. reg |= (pre - 1) << MXC_CCM_PDR1_FIRI_PRE_PODF_OFFSET;
  287. reg |= (post - 1) << MXC_CCM_PDR1_FIRI_PODF_OFFSET;
  288. __raw_writel(reg, MXC_CCM_PDR1);
  289. return 0;
  290. }
  291. static unsigned long mbx_get_rate(struct clk *clk)
  292. {
  293. return clk_get_rate(clk->parent) / 2;
  294. }
  295. static unsigned long mstick1_get_rate(struct clk *clk)
  296. {
  297. unsigned long msti_pdf;
  298. msti_pdf = PDR2(MXC_CCM_PDR2_MST1_PDF_MASK,
  299. MXC_CCM_PDR2_MST1_PDF_OFFSET);
  300. return clk_get_rate(clk->parent) / (msti_pdf + 1);
  301. }
  302. static unsigned long mstick2_get_rate(struct clk *clk)
  303. {
  304. unsigned long msti_pdf;
  305. msti_pdf = PDR2(MXC_CCM_PDR2_MST2_PDF_MASK,
  306. MXC_CCM_PDR2_MST2_PDF_OFFSET);
  307. return clk_get_rate(clk->parent) / (msti_pdf + 1);
  308. }
  309. static unsigned long ckih_rate;
  310. static unsigned long clk_ckih_get_rate(struct clk *clk)
  311. {
  312. return ckih_rate;
  313. }
  314. static unsigned long clk_ckil_get_rate(struct clk *clk)
  315. {
  316. return CKIL_CLK_FREQ;
  317. }
  318. static struct clk ckih_clk = {
  319. .get_rate = clk_ckih_get_rate,
  320. };
  321. static struct clk mcu_pll_clk = {
  322. .parent = &ckih_clk,
  323. .get_rate = mcu_pll_get_rate,
  324. };
  325. static struct clk mcu_main_clk = {
  326. .parent = &mcu_pll_clk,
  327. .get_rate = mcu_main_get_rate,
  328. };
  329. static struct clk serial_pll_clk = {
  330. .parent = &ckih_clk,
  331. .get_rate = serial_pll_get_rate,
  332. .enable = serial_pll_enable,
  333. .disable = serial_pll_disable,
  334. };
  335. static struct clk usb_pll_clk = {
  336. .parent = &ckih_clk,
  337. .get_rate = usb_pll_get_rate,
  338. .enable = usb_pll_enable,
  339. .disable = usb_pll_disable,
  340. };
  341. static struct clk ahb_clk = {
  342. .parent = &mcu_main_clk,
  343. .get_rate = ahb_get_rate,
  344. };
  345. #define DEFINE_CLOCK(name, i, er, es, gr, s, p) \
  346. static struct clk name = { \
  347. .id = i, \
  348. .enable_reg = er, \
  349. .enable_shift = es, \
  350. .get_rate = gr, \
  351. .enable = cgr_enable, \
  352. .disable = cgr_disable, \
  353. .secondary = s, \
  354. .parent = p, \
  355. }
  356. #define DEFINE_CLOCK1(name, i, er, es, getsetround, s, p) \
  357. static struct clk name = { \
  358. .id = i, \
  359. .enable_reg = er, \
  360. .enable_shift = es, \
  361. .get_rate = getsetround##_get_rate, \
  362. .set_rate = getsetround##_set_rate, \
  363. .round_rate = getsetround##_round_rate, \
  364. .enable = cgr_enable, \
  365. .disable = cgr_disable, \
  366. .secondary = s, \
  367. .parent = p, \
  368. }
  369. DEFINE_CLOCK(perclk_clk, 0, NULL, 0, NULL, NULL, &ipg_clk);
  370. DEFINE_CLOCK(ckil_clk, 0, NULL, 0, clk_ckil_get_rate, NULL, NULL);
  371. DEFINE_CLOCK(sdhc1_clk, 0, MXC_CCM_CGR0, 0, NULL, NULL, &perclk_clk);
  372. DEFINE_CLOCK(sdhc2_clk, 1, MXC_CCM_CGR0, 2, NULL, NULL, &perclk_clk);
  373. DEFINE_CLOCK(gpt_clk, 0, MXC_CCM_CGR0, 4, NULL, NULL, &perclk_clk);
  374. DEFINE_CLOCK(epit1_clk, 0, MXC_CCM_CGR0, 6, NULL, NULL, &perclk_clk);
  375. DEFINE_CLOCK(epit2_clk, 1, MXC_CCM_CGR0, 8, NULL, NULL, &perclk_clk);
  376. DEFINE_CLOCK(iim_clk, 0, MXC_CCM_CGR0, 10, NULL, NULL, &ipg_clk);
  377. DEFINE_CLOCK(ata_clk, 0, MXC_CCM_CGR0, 12, NULL, NULL, &ipg_clk);
  378. DEFINE_CLOCK(sdma_clk1, 0, MXC_CCM_CGR0, 14, NULL, NULL, &ahb_clk);
  379. DEFINE_CLOCK(cspi3_clk, 2, MXC_CCM_CGR0, 16, NULL, NULL, &ipg_clk);
  380. DEFINE_CLOCK(rng_clk, 0, MXC_CCM_CGR0, 18, NULL, NULL, &ipg_clk);
  381. DEFINE_CLOCK(uart1_clk, 0, MXC_CCM_CGR0, 20, NULL, NULL, &perclk_clk);
  382. DEFINE_CLOCK(uart2_clk, 1, MXC_CCM_CGR0, 22, NULL, NULL, &perclk_clk);
  383. DEFINE_CLOCK(ssi1_clk, 0, MXC_CCM_CGR0, 24, ssi1_get_rate, NULL, &serial_pll_clk);
  384. DEFINE_CLOCK(i2c1_clk, 0, MXC_CCM_CGR0, 26, NULL, NULL, &perclk_clk);
  385. DEFINE_CLOCK(i2c2_clk, 1, MXC_CCM_CGR0, 28, NULL, NULL, &perclk_clk);
  386. DEFINE_CLOCK(i2c3_clk, 2, MXC_CCM_CGR0, 30, NULL, NULL, &perclk_clk);
  387. DEFINE_CLOCK(mpeg4_clk, 0, MXC_CCM_CGR1, 0, NULL, NULL, &ahb_clk);
  388. DEFINE_CLOCK(mstick1_clk, 0, MXC_CCM_CGR1, 2, mstick1_get_rate, NULL, &usb_pll_clk);
  389. DEFINE_CLOCK(mstick2_clk, 1, MXC_CCM_CGR1, 4, mstick2_get_rate, NULL, &usb_pll_clk);
  390. DEFINE_CLOCK1(csi_clk, 0, MXC_CCM_CGR1, 6, csi, NULL, &serial_pll_clk);
  391. DEFINE_CLOCK(rtc_clk, 0, MXC_CCM_CGR1, 8, NULL, NULL, &ckil_clk);
  392. DEFINE_CLOCK(wdog_clk, 0, MXC_CCM_CGR1, 10, NULL, NULL, &ipg_clk);
  393. DEFINE_CLOCK(pwm_clk, 0, MXC_CCM_CGR1, 12, NULL, NULL, &perclk_clk);
  394. DEFINE_CLOCK(usb_clk2, 0, MXC_CCM_CGR1, 18, usb_get_rate, NULL, &ahb_clk);
  395. DEFINE_CLOCK(kpp_clk, 0, MXC_CCM_CGR1, 20, NULL, NULL, &ipg_clk);
  396. DEFINE_CLOCK(ipu_clk, 0, MXC_CCM_CGR1, 22, hsp_get_rate, NULL, &mcu_main_clk);
  397. DEFINE_CLOCK(uart3_clk, 2, MXC_CCM_CGR1, 24, NULL, NULL, &perclk_clk);
  398. DEFINE_CLOCK(uart4_clk, 3, MXC_CCM_CGR1, 26, NULL, NULL, &perclk_clk);
  399. DEFINE_CLOCK(uart5_clk, 4, MXC_CCM_CGR1, 28, NULL, NULL, &perclk_clk);
  400. DEFINE_CLOCK(owire_clk, 0, MXC_CCM_CGR1, 30, NULL, NULL, &perclk_clk);
  401. DEFINE_CLOCK(ssi2_clk, 1, MXC_CCM_CGR2, 0, ssi2_get_rate, NULL, &serial_pll_clk);
  402. DEFINE_CLOCK(cspi1_clk, 0, MXC_CCM_CGR2, 2, NULL, NULL, &ipg_clk);
  403. DEFINE_CLOCK(cspi2_clk, 1, MXC_CCM_CGR2, 4, NULL, NULL, &ipg_clk);
  404. DEFINE_CLOCK(mbx_clk, 0, MXC_CCM_CGR2, 6, mbx_get_rate, NULL, &ahb_clk);
  405. DEFINE_CLOCK(emi_clk, 0, MXC_CCM_CGR2, 8, NULL, NULL, &ahb_clk);
  406. DEFINE_CLOCK(rtic_clk, 0, MXC_CCM_CGR2, 10, NULL, NULL, &ahb_clk);
  407. DEFINE_CLOCK1(firi_clk, 0, MXC_CCM_CGR2, 12, firi, NULL, &usb_pll_clk);
  408. DEFINE_CLOCK(sdma_clk2, 0, NULL, 0, NULL, NULL, &ipg_clk);
  409. DEFINE_CLOCK(usb_clk1, 0, NULL, 0, usb_get_rate, NULL, &usb_pll_clk);
  410. DEFINE_CLOCK(nfc_clk, 0, NULL, 0, nfc_get_rate, NULL, &ahb_clk);
  411. DEFINE_CLOCK(scc_clk, 0, NULL, 0, NULL, NULL, &ipg_clk);
  412. DEFINE_CLOCK(ipg_clk, 0, NULL, 0, ipg_get_rate, NULL, &ahb_clk);
  413. #define _REGISTER_CLOCK(d, n, c) \
  414. { \
  415. .dev_id = d, \
  416. .con_id = n, \
  417. .clk = &c, \
  418. },
  419. static struct clk_lookup lookups[] = {
  420. _REGISTER_CLOCK(NULL, "emi", emi_clk)
  421. _REGISTER_CLOCK("imx31-cspi.0", NULL, cspi1_clk)
  422. _REGISTER_CLOCK("imx31-cspi.1", NULL, cspi2_clk)
  423. _REGISTER_CLOCK("imx31-cspi.2", NULL, cspi3_clk)
  424. _REGISTER_CLOCK(NULL, "gpt", gpt_clk)
  425. _REGISTER_CLOCK(NULL, "pwm", pwm_clk)
  426. _REGISTER_CLOCK("imx2-wdt.0", NULL, wdog_clk)
  427. _REGISTER_CLOCK(NULL, "rtc", rtc_clk)
  428. _REGISTER_CLOCK(NULL, "epit", epit1_clk)
  429. _REGISTER_CLOCK(NULL, "epit", epit2_clk)
  430. _REGISTER_CLOCK("mxc_nand.0", NULL, nfc_clk)
  431. _REGISTER_CLOCK("ipu-core", NULL, ipu_clk)
  432. _REGISTER_CLOCK("mx3_sdc_fb", NULL, ipu_clk)
  433. _REGISTER_CLOCK(NULL, "kpp", kpp_clk)
  434. _REGISTER_CLOCK("mxc-ehci.0", "usb", usb_clk1)
  435. _REGISTER_CLOCK("mxc-ehci.0", "usb_ahb", usb_clk2)
  436. _REGISTER_CLOCK("mxc-ehci.1", "usb", usb_clk1)
  437. _REGISTER_CLOCK("mxc-ehci.1", "usb_ahb", usb_clk2)
  438. _REGISTER_CLOCK("mxc-ehci.2", "usb", usb_clk1)
  439. _REGISTER_CLOCK("mxc-ehci.2", "usb_ahb", usb_clk2)
  440. _REGISTER_CLOCK("fsl-usb2-udc", "usb", usb_clk1)
  441. _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", usb_clk2)
  442. _REGISTER_CLOCK("mx3-camera.0", NULL, csi_clk)
  443. _REGISTER_CLOCK("imx-uart.0", NULL, uart1_clk)
  444. _REGISTER_CLOCK("imx-uart.1", NULL, uart2_clk)
  445. _REGISTER_CLOCK("imx-uart.2", NULL, uart3_clk)
  446. _REGISTER_CLOCK("imx-uart.3", NULL, uart4_clk)
  447. _REGISTER_CLOCK("imx-uart.4", NULL, uart5_clk)
  448. _REGISTER_CLOCK("imx-i2c.0", NULL, i2c1_clk)
  449. _REGISTER_CLOCK("imx-i2c.1", NULL, i2c2_clk)
  450. _REGISTER_CLOCK("imx-i2c.2", NULL, i2c3_clk)
  451. _REGISTER_CLOCK("mxc_w1.0", NULL, owire_clk)
  452. _REGISTER_CLOCK("mxc-mmc.0", NULL, sdhc1_clk)
  453. _REGISTER_CLOCK("mxc-mmc.1", NULL, sdhc2_clk)
  454. _REGISTER_CLOCK("imx-ssi.0", NULL, ssi1_clk)
  455. _REGISTER_CLOCK("imx-ssi.1", NULL, ssi2_clk)
  456. _REGISTER_CLOCK(NULL, "firi", firi_clk)
  457. _REGISTER_CLOCK(NULL, "ata", ata_clk)
  458. _REGISTER_CLOCK(NULL, "rtic", rtic_clk)
  459. _REGISTER_CLOCK(NULL, "rng", rng_clk)
  460. _REGISTER_CLOCK("imx-sdma", NULL, sdma_clk1)
  461. _REGISTER_CLOCK(NULL, "sdma_ipg", sdma_clk2)
  462. _REGISTER_CLOCK(NULL, "mstick", mstick1_clk)
  463. _REGISTER_CLOCK(NULL, "mstick", mstick2_clk)
  464. _REGISTER_CLOCK(NULL, "scc", scc_clk)
  465. _REGISTER_CLOCK(NULL, "iim", iim_clk)
  466. _REGISTER_CLOCK(NULL, "mpeg4", mpeg4_clk)
  467. _REGISTER_CLOCK(NULL, "mbx", mbx_clk)
  468. };
  469. int __init mx31_clocks_init(unsigned long fref)
  470. {
  471. u32 reg;
  472. ckih_rate = fref;
  473. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  474. /* change the csi_clk parent if necessary */
  475. reg = __raw_readl(MXC_CCM_CCMR);
  476. if (!(reg & MXC_CCM_CCMR_CSCS))
  477. if (clk_set_parent(&csi_clk, &usb_pll_clk))
  478. pr_err("%s: error changing csi_clk parent\n", __func__);
  479. /* Turn off all possible clocks */
  480. __raw_writel((3 << 4), MXC_CCM_CGR0);
  481. __raw_writel(0, MXC_CCM_CGR1);
  482. __raw_writel((3 << 8) | (3 << 14) | (3 << 16)|
  483. 1 << 27 | 1 << 28, /* Bit 27 and 28 are not defined for
  484. MX32, but still required to be set */
  485. MXC_CCM_CGR2);
  486. /*
  487. * Before turning off usb_pll make sure ipg_per_clk is generated
  488. * by ipg_clk and not usb_pll.
  489. */
  490. __raw_writel(__raw_readl(MXC_CCM_CCMR) | (1 << 24), MXC_CCM_CCMR);
  491. usb_pll_disable(&usb_pll_clk);
  492. pr_info("Clock input source is %ld\n", clk_get_rate(&ckih_clk));
  493. clk_enable(&gpt_clk);
  494. clk_enable(&emi_clk);
  495. clk_enable(&iim_clk);
  496. clk_enable(&serial_pll_clk);
  497. mx31_read_cpu_rev();
  498. if (mx31_revision() >= IMX_CHIP_REVISION_2_0) {
  499. reg = __raw_readl(MXC_CCM_PMCR1);
  500. /* No PLL restart on DVFS switch; enable auto EMI handshake */
  501. reg |= MXC_CCM_PMCR1_PLLRDIS | MXC_CCM_PMCR1_EMIRQ_EN;
  502. __raw_writel(reg, MXC_CCM_PMCR1);
  503. }
  504. mxc_timer_init(&ipg_clk, MX31_IO_ADDRESS(MX31_GPT1_BASE_ADDR),
  505. MX31_INT_GPT);
  506. return 0;
  507. }