clock_imx27.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /*
  2. * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  3. * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
  4. * Copyright 2008 Martin Fuzzey, mfuzzey@gmail.com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. * MA 02110-1301, USA.
  19. */
  20. #include <linux/clk.h>
  21. #include <linux/io.h>
  22. #include <linux/module.h>
  23. #include <asm/clkdev.h>
  24. #include <asm/div64.h>
  25. #include <mach/clock.h>
  26. #include <mach/common.h>
  27. #include <mach/hardware.h>
  28. /* Register offsets */
  29. #define CCM_CSCR (IO_ADDRESS(CCM_BASE_ADDR) + 0x0)
  30. #define CCM_MPCTL0 (IO_ADDRESS(CCM_BASE_ADDR) + 0x4)
  31. #define CCM_MPCTL1 (IO_ADDRESS(CCM_BASE_ADDR) + 0x8)
  32. #define CCM_SPCTL0 (IO_ADDRESS(CCM_BASE_ADDR) + 0xC)
  33. #define CCM_SPCTL1 (IO_ADDRESS(CCM_BASE_ADDR) + 0x10)
  34. #define CCM_OSC26MCTL (IO_ADDRESS(CCM_BASE_ADDR) + 0x14)
  35. #define CCM_PCDR0 (IO_ADDRESS(CCM_BASE_ADDR) + 0x18)
  36. #define CCM_PCDR1 (IO_ADDRESS(CCM_BASE_ADDR) + 0x1c)
  37. #define CCM_PCCR0 (IO_ADDRESS(CCM_BASE_ADDR) + 0x20)
  38. #define CCM_PCCR1 (IO_ADDRESS(CCM_BASE_ADDR) + 0x24)
  39. #define CCM_CCSR (IO_ADDRESS(CCM_BASE_ADDR) + 0x28)
  40. #define CCM_PMCTL (IO_ADDRESS(CCM_BASE_ADDR) + 0x2c)
  41. #define CCM_PMCOUNT (IO_ADDRESS(CCM_BASE_ADDR) + 0x30)
  42. #define CCM_WKGDCTL (IO_ADDRESS(CCM_BASE_ADDR) + 0x34)
  43. #define CCM_CSCR_UPDATE_DIS (1 << 31)
  44. #define CCM_CSCR_SSI2 (1 << 23)
  45. #define CCM_CSCR_SSI1 (1 << 22)
  46. #define CCM_CSCR_VPU (1 << 21)
  47. #define CCM_CSCR_MSHC (1 << 20)
  48. #define CCM_CSCR_SPLLRES (1 << 19)
  49. #define CCM_CSCR_MPLLRES (1 << 18)
  50. #define CCM_CSCR_SP (1 << 17)
  51. #define CCM_CSCR_MCU (1 << 16)
  52. #define CCM_CSCR_OSC26MDIV (1 << 4)
  53. #define CCM_CSCR_OSC26M (1 << 3)
  54. #define CCM_CSCR_FPM (1 << 2)
  55. #define CCM_CSCR_SPEN (1 << 1)
  56. #define CCM_CSCR_MPEN (1 << 0)
  57. /* i.MX27 TO 2+ */
  58. #define CCM_CSCR_ARM_SRC (1 << 15)
  59. #define CCM_SPCTL1_LF (1 << 15)
  60. #define CCM_SPCTL1_BRMO (1 << 6)
  61. static struct clk mpll_main1_clk, mpll_main2_clk;
  62. static int clk_pccr_enable(struct clk *clk)
  63. {
  64. unsigned long reg;
  65. if (!clk->enable_reg)
  66. return 0;
  67. reg = __raw_readl(clk->enable_reg);
  68. reg |= 1 << clk->enable_shift;
  69. __raw_writel(reg, clk->enable_reg);
  70. return 0;
  71. }
  72. static void clk_pccr_disable(struct clk *clk)
  73. {
  74. unsigned long reg;
  75. if (!clk->enable_reg)
  76. return;
  77. reg = __raw_readl(clk->enable_reg);
  78. reg &= ~(1 << clk->enable_shift);
  79. __raw_writel(reg, clk->enable_reg);
  80. }
  81. static int clk_spll_enable(struct clk *clk)
  82. {
  83. unsigned long reg;
  84. reg = __raw_readl(CCM_CSCR);
  85. reg |= CCM_CSCR_SPEN;
  86. __raw_writel(reg, CCM_CSCR);
  87. while (!(__raw_readl(CCM_SPCTL1) & CCM_SPCTL1_LF));
  88. return 0;
  89. }
  90. static void clk_spll_disable(struct clk *clk)
  91. {
  92. unsigned long reg;
  93. reg = __raw_readl(CCM_CSCR);
  94. reg &= ~CCM_CSCR_SPEN;
  95. __raw_writel(reg, CCM_CSCR);
  96. }
  97. static int clk_cpu_set_parent(struct clk *clk, struct clk *parent)
  98. {
  99. int cscr = __raw_readl(CCM_CSCR);
  100. if (clk->parent == parent)
  101. return 0;
  102. if (mx27_revision() >= CHIP_REV_2_0) {
  103. if (parent == &mpll_main1_clk) {
  104. cscr |= CCM_CSCR_ARM_SRC;
  105. } else {
  106. if (parent == &mpll_main2_clk)
  107. cscr &= ~CCM_CSCR_ARM_SRC;
  108. else
  109. return -EINVAL;
  110. }
  111. __raw_writel(cscr, CCM_CSCR);
  112. clk->parent = parent;
  113. return 0;
  114. }
  115. return -ENODEV;
  116. }
  117. static unsigned long round_rate_cpu(struct clk *clk, unsigned long rate)
  118. {
  119. int div;
  120. unsigned long parent_rate;
  121. parent_rate = clk_get_rate(clk->parent);
  122. div = parent_rate / rate;
  123. if (parent_rate % rate)
  124. div++;
  125. if (div > 4)
  126. div = 4;
  127. return parent_rate / div;
  128. }
  129. static int set_rate_cpu(struct clk *clk, unsigned long rate)
  130. {
  131. unsigned int div;
  132. uint32_t reg;
  133. unsigned long parent_rate;
  134. parent_rate = clk_get_rate(clk->parent);
  135. div = parent_rate / rate;
  136. if (div > 4 || div < 1 || ((parent_rate / div) != rate))
  137. return -EINVAL;
  138. div--;
  139. reg = __raw_readl(CCM_CSCR);
  140. if (mx27_revision() >= CHIP_REV_2_0) {
  141. reg &= ~(3 << 12);
  142. reg |= div << 12;
  143. reg &= ~(CCM_CSCR_FPM | CCM_CSCR_SPEN);
  144. __raw_writel(reg | CCM_CSCR_UPDATE_DIS, CCM_CSCR);
  145. } else {
  146. printk(KERN_ERR "Can't set CPU frequency!\n");
  147. }
  148. return 0;
  149. }
  150. static unsigned long round_rate_per(struct clk *clk, unsigned long rate)
  151. {
  152. u32 div;
  153. unsigned long parent_rate;
  154. parent_rate = clk_get_rate(clk->parent);
  155. div = parent_rate / rate;
  156. if (parent_rate % rate)
  157. div++;
  158. if (div > 64)
  159. div = 64;
  160. return parent_rate / div;
  161. }
  162. static int set_rate_per(struct clk *clk, unsigned long rate)
  163. {
  164. u32 reg;
  165. u32 div;
  166. unsigned long parent_rate;
  167. parent_rate = clk_get_rate(clk->parent);
  168. if (clk->id < 0 || clk->id > 3)
  169. return -EINVAL;
  170. div = parent_rate / rate;
  171. if (div > 64 || div < 1 || ((parent_rate / div) != rate))
  172. return -EINVAL;
  173. div--;
  174. reg = __raw_readl(CCM_PCDR1) & ~(0x3f << (clk->id << 3));
  175. reg |= div << (clk->id << 3);
  176. __raw_writel(reg, CCM_PCDR1);
  177. return 0;
  178. }
  179. static unsigned long get_rate_usb(struct clk *clk)
  180. {
  181. unsigned long usb_pdf;
  182. unsigned long parent_rate;
  183. parent_rate = clk_get_rate(clk->parent);
  184. usb_pdf = (__raw_readl(CCM_CSCR) >> 28) & 0x7;
  185. return parent_rate / (usb_pdf + 1U);
  186. }
  187. static unsigned long get_rate_ssix(struct clk *clk, unsigned long pdf)
  188. {
  189. unsigned long parent_rate;
  190. parent_rate = clk_get_rate(clk->parent);
  191. if (mx27_revision() >= CHIP_REV_2_0)
  192. pdf += 4; /* MX27 TO2+ */
  193. else
  194. pdf = (pdf < 2) ? 124UL : pdf; /* MX21 & MX27 TO1 */
  195. return 2UL * parent_rate / pdf;
  196. }
  197. static unsigned long get_rate_ssi1(struct clk *clk)
  198. {
  199. return get_rate_ssix(clk, (__raw_readl(CCM_PCDR0) >> 16) & 0x3f);
  200. }
  201. static unsigned long get_rate_ssi2(struct clk *clk)
  202. {
  203. return get_rate_ssix(clk, (__raw_readl(CCM_PCDR0) >> 26) & 0x3f);
  204. }
  205. static unsigned long get_rate_nfc(struct clk *clk)
  206. {
  207. unsigned long nfc_pdf;
  208. unsigned long parent_rate;
  209. parent_rate = clk_get_rate(clk->parent);
  210. if (mx27_revision() >= CHIP_REV_2_0)
  211. nfc_pdf = (__raw_readl(CCM_PCDR0) >> 6) & 0xf;
  212. else
  213. nfc_pdf = (__raw_readl(CCM_PCDR0) >> 12) & 0xf;
  214. return parent_rate / (nfc_pdf + 1);
  215. }
  216. static unsigned long get_rate_vpu(struct clk *clk)
  217. {
  218. unsigned long vpu_pdf;
  219. unsigned long parent_rate;
  220. parent_rate = clk_get_rate(clk->parent);
  221. if (mx27_revision() >= CHIP_REV_2_0) {
  222. vpu_pdf = (__raw_readl(CCM_PCDR0) >> 10) & 0x3f;
  223. vpu_pdf += 4;
  224. } else {
  225. vpu_pdf = (__raw_readl(CCM_PCDR0) >> 8) & 0xf;
  226. vpu_pdf = (vpu_pdf < 2) ? 124 : vpu_pdf;
  227. }
  228. return 2UL * parent_rate / vpu_pdf;
  229. }
  230. static unsigned long round_rate_parent(struct clk *clk, unsigned long rate)
  231. {
  232. return clk->parent->round_rate(clk->parent, rate);
  233. }
  234. static unsigned long get_rate_parent(struct clk *clk)
  235. {
  236. return clk_get_rate(clk->parent);
  237. }
  238. static int set_rate_parent(struct clk *clk, unsigned long rate)
  239. {
  240. return clk->parent->set_rate(clk->parent, rate);
  241. }
  242. /* in Hz */
  243. static unsigned long external_high_reference = 26000000;
  244. static unsigned long get_rate_high_reference(struct clk *clk)
  245. {
  246. return external_high_reference;
  247. }
  248. /* in Hz */
  249. static unsigned long external_low_reference = 32768;
  250. static unsigned long get_rate_low_reference(struct clk *clk)
  251. {
  252. return external_low_reference;
  253. }
  254. static unsigned long get_rate_fpm(struct clk *clk)
  255. {
  256. return clk_get_rate(clk->parent) * 1024;
  257. }
  258. static unsigned long get_rate_mpll(struct clk *clk)
  259. {
  260. return mxc_decode_pll(__raw_readl(CCM_MPCTL0),
  261. clk_get_rate(clk->parent));
  262. }
  263. static unsigned long get_rate_mpll_main(struct clk *clk)
  264. {
  265. unsigned long parent_rate;
  266. parent_rate = clk_get_rate(clk->parent);
  267. /* i.MX27 TO2:
  268. * clk->id == 0: arm clock source path 1 which is from 2 * MPLL / 2
  269. * clk->id == 1: arm clock source path 2 which is from 2 * MPLL / 3
  270. */
  271. if (mx27_revision() >= CHIP_REV_2_0 && clk->id == 1)
  272. return 2UL * parent_rate / 3UL;
  273. return parent_rate;
  274. }
  275. static unsigned long get_rate_spll(struct clk *clk)
  276. {
  277. uint32_t reg;
  278. unsigned long rate;
  279. rate = clk_get_rate(clk->parent);
  280. reg = __raw_readl(CCM_SPCTL0);
  281. /* On TO2 we have to write the value back. Otherwise we
  282. * read 0 from this register the next time.
  283. */
  284. if (mx27_revision() >= CHIP_REV_2_0)
  285. __raw_writel(reg, CCM_SPCTL0);
  286. return mxc_decode_pll(reg, rate);
  287. }
  288. static unsigned long get_rate_cpu(struct clk *clk)
  289. {
  290. u32 div;
  291. unsigned long rate;
  292. if (mx27_revision() >= CHIP_REV_2_0)
  293. div = (__raw_readl(CCM_CSCR) >> 12) & 0x3;
  294. else
  295. div = (__raw_readl(CCM_CSCR) >> 13) & 0x7;
  296. rate = clk_get_rate(clk->parent);
  297. return rate / (div + 1);
  298. }
  299. static unsigned long get_rate_ahb(struct clk *clk)
  300. {
  301. unsigned long rate, bclk_pdf;
  302. if (mx27_revision() >= CHIP_REV_2_0)
  303. bclk_pdf = (__raw_readl(CCM_CSCR) >> 8) & 0x3;
  304. else
  305. bclk_pdf = (__raw_readl(CCM_CSCR) >> 9) & 0xf;
  306. rate = clk_get_rate(clk->parent);
  307. return rate / (bclk_pdf + 1);
  308. }
  309. static unsigned long get_rate_ipg(struct clk *clk)
  310. {
  311. unsigned long rate, ipg_pdf;
  312. if (mx27_revision() >= CHIP_REV_2_0)
  313. return clk_get_rate(clk->parent);
  314. else
  315. ipg_pdf = (__raw_readl(CCM_CSCR) >> 8) & 1;
  316. rate = clk_get_rate(clk->parent);
  317. return rate / (ipg_pdf + 1);
  318. }
  319. static unsigned long get_rate_per(struct clk *clk)
  320. {
  321. unsigned long perclk_pdf, parent_rate;
  322. parent_rate = clk_get_rate(clk->parent);
  323. if (clk->id < 0 || clk->id > 3)
  324. return 0;
  325. perclk_pdf = (__raw_readl(CCM_PCDR1) >> (clk->id << 3)) & 0x3f;
  326. return parent_rate / (perclk_pdf + 1);
  327. }
  328. /*
  329. * the high frequency external clock reference
  330. * Default case is 26MHz. Could be changed at runtime
  331. * with a call to change_external_high_reference()
  332. */
  333. static struct clk ckih_clk = {
  334. .get_rate = get_rate_high_reference,
  335. };
  336. static struct clk mpll_clk = {
  337. .parent = &ckih_clk,
  338. .get_rate = get_rate_mpll,
  339. };
  340. /* For i.MX27 TO2, it is the MPLL path 1 of ARM core
  341. * It provides the clock source whose rate is same as MPLL
  342. */
  343. static struct clk mpll_main1_clk = {
  344. .id = 0,
  345. .parent = &mpll_clk,
  346. .get_rate = get_rate_mpll_main,
  347. };
  348. /* For i.MX27 TO2, it is the MPLL path 2 of ARM core
  349. * It provides the clock source whose rate is same MPLL * 2 / 3
  350. */
  351. static struct clk mpll_main2_clk = {
  352. .id = 1,
  353. .parent = &mpll_clk,
  354. .get_rate = get_rate_mpll_main,
  355. };
  356. static struct clk ahb_clk = {
  357. .parent = &mpll_main2_clk,
  358. .get_rate = get_rate_ahb,
  359. };
  360. static struct clk ipg_clk = {
  361. .parent = &ahb_clk,
  362. .get_rate = get_rate_ipg,
  363. };
  364. static struct clk cpu_clk = {
  365. .parent = &mpll_main2_clk,
  366. .set_parent = clk_cpu_set_parent,
  367. .round_rate = round_rate_cpu,
  368. .get_rate = get_rate_cpu,
  369. .set_rate = set_rate_cpu,
  370. };
  371. static struct clk spll_clk = {
  372. .parent = &ckih_clk,
  373. .get_rate = get_rate_spll,
  374. .enable = clk_spll_enable,
  375. .disable = clk_spll_disable,
  376. };
  377. /*
  378. * the low frequency external clock reference
  379. * Default case is 32.768kHz.
  380. */
  381. static struct clk ckil_clk = {
  382. .get_rate = get_rate_low_reference,
  383. };
  384. /* Output of frequency pre multiplier */
  385. static struct clk fpm_clk = {
  386. .parent = &ckil_clk,
  387. .get_rate = get_rate_fpm,
  388. };
  389. #define PCCR0 CCM_PCCR0
  390. #define PCCR1 CCM_PCCR1
  391. #define DEFINE_CLOCK(name, i, er, es, gr, s, p) \
  392. static struct clk name = { \
  393. .id = i, \
  394. .enable_reg = er, \
  395. .enable_shift = es, \
  396. .get_rate = gr, \
  397. .enable = clk_pccr_enable, \
  398. .disable = clk_pccr_disable, \
  399. .secondary = s, \
  400. .parent = p, \
  401. }
  402. #define DEFINE_CLOCK1(name, i, er, es, getsetround, s, p) \
  403. static struct clk name = { \
  404. .id = i, \
  405. .enable_reg = er, \
  406. .enable_shift = es, \
  407. .get_rate = get_rate_##getsetround, \
  408. .set_rate = set_rate_##getsetround, \
  409. .round_rate = round_rate_##getsetround, \
  410. .enable = clk_pccr_enable, \
  411. .disable = clk_pccr_disable, \
  412. .secondary = s, \
  413. .parent = p, \
  414. }
  415. /* Forward declaration to keep the following list in order */
  416. static struct clk slcdc_clk1, sahara2_clk1, rtic_clk1, fec_clk1, emma_clk1,
  417. dma_clk1, lcdc_clk2, vpu_clk1;
  418. /* All clocks we can gate through PCCRx in the order of PCCRx bits */
  419. DEFINE_CLOCK(ssi2_clk1, 1, PCCR0, 0, NULL, NULL, &ipg_clk);
  420. DEFINE_CLOCK(ssi1_clk1, 0, PCCR0, 1, NULL, NULL, &ipg_clk);
  421. DEFINE_CLOCK(slcdc_clk, 0, PCCR0, 2, NULL, &slcdc_clk1, &ahb_clk);
  422. DEFINE_CLOCK(sdhc3_clk1, 0, PCCR0, 3, NULL, NULL, &ipg_clk);
  423. DEFINE_CLOCK(sdhc2_clk1, 0, PCCR0, 4, NULL, NULL, &ipg_clk);
  424. DEFINE_CLOCK(sdhc1_clk1, 0, PCCR0, 5, NULL, NULL, &ipg_clk);
  425. DEFINE_CLOCK(scc_clk, 0, PCCR0, 6, NULL, NULL, &ipg_clk);
  426. DEFINE_CLOCK(sahara2_clk, 0, PCCR0, 7, NULL, &sahara2_clk1, &ahb_clk);
  427. DEFINE_CLOCK(rtic_clk, 0, PCCR0, 8, NULL, &rtic_clk1, &ahb_clk);
  428. DEFINE_CLOCK(rtc_clk, 0, PCCR0, 9, NULL, NULL, &ipg_clk);
  429. DEFINE_CLOCK(pwm_clk1, 0, PCCR0, 11, NULL, NULL, &ipg_clk);
  430. DEFINE_CLOCK(owire_clk, 0, PCCR0, 12, NULL, NULL, &ipg_clk);
  431. DEFINE_CLOCK(mstick_clk1, 0, PCCR0, 13, NULL, NULL, &ipg_clk);
  432. DEFINE_CLOCK(lcdc_clk1, 0, PCCR0, 14, NULL, &lcdc_clk2, &ipg_clk);
  433. DEFINE_CLOCK(kpp_clk, 0, PCCR0, 15, NULL, NULL, &ipg_clk);
  434. DEFINE_CLOCK(iim_clk, 0, PCCR0, 16, NULL, NULL, &ipg_clk);
  435. DEFINE_CLOCK(i2c2_clk, 1, PCCR0, 17, NULL, NULL, &ipg_clk);
  436. DEFINE_CLOCK(i2c1_clk, 0, PCCR0, 18, NULL, NULL, &ipg_clk);
  437. DEFINE_CLOCK(gpt6_clk1, 0, PCCR0, 29, NULL, NULL, &ipg_clk);
  438. DEFINE_CLOCK(gpt5_clk1, 0, PCCR0, 20, NULL, NULL, &ipg_clk);
  439. DEFINE_CLOCK(gpt4_clk1, 0, PCCR0, 21, NULL, NULL, &ipg_clk);
  440. DEFINE_CLOCK(gpt3_clk1, 0, PCCR0, 22, NULL, NULL, &ipg_clk);
  441. DEFINE_CLOCK(gpt2_clk1, 0, PCCR0, 23, NULL, NULL, &ipg_clk);
  442. DEFINE_CLOCK(gpt1_clk1, 0, PCCR0, 24, NULL, NULL, &ipg_clk);
  443. DEFINE_CLOCK(gpio_clk, 0, PCCR0, 25, NULL, NULL, &ipg_clk);
  444. DEFINE_CLOCK(fec_clk, 0, PCCR0, 26, NULL, &fec_clk1, &ahb_clk);
  445. DEFINE_CLOCK(emma_clk, 0, PCCR0, 27, NULL, &emma_clk1, &ahb_clk);
  446. DEFINE_CLOCK(dma_clk, 0, PCCR0, 28, NULL, &dma_clk1, &ahb_clk);
  447. DEFINE_CLOCK(cspi13_clk1, 0, PCCR0, 29, NULL, NULL, &ipg_clk);
  448. DEFINE_CLOCK(cspi2_clk1, 0, PCCR0, 30, NULL, NULL, &ipg_clk);
  449. DEFINE_CLOCK(cspi1_clk1, 0, PCCR0, 31, NULL, NULL, &ipg_clk);
  450. DEFINE_CLOCK(mstick_clk, 0, PCCR1, 2, NULL, &mstick_clk1, &ipg_clk);
  451. DEFINE_CLOCK(nfc_clk, 0, PCCR1, 3, get_rate_nfc, NULL, &cpu_clk);
  452. DEFINE_CLOCK(ssi2_clk, 1, PCCR1, 4, get_rate_ssi2, &ssi2_clk1, &mpll_main2_clk);
  453. DEFINE_CLOCK(ssi1_clk, 0, PCCR1, 5, get_rate_ssi1, &ssi1_clk1, &mpll_main2_clk);
  454. DEFINE_CLOCK(vpu_clk, 0, PCCR1, 6, get_rate_vpu, &vpu_clk1, &mpll_main2_clk);
  455. DEFINE_CLOCK1(per4_clk, 3, PCCR1, 7, per, NULL, &mpll_main2_clk);
  456. DEFINE_CLOCK1(per3_clk, 2, PCCR1, 8, per, NULL, &mpll_main2_clk);
  457. DEFINE_CLOCK1(per2_clk, 1, PCCR1, 9, per, NULL, &mpll_main2_clk);
  458. DEFINE_CLOCK1(per1_clk, 0, PCCR1, 10, per, NULL, &mpll_main2_clk);
  459. DEFINE_CLOCK(usb_clk1, 0, PCCR1, 11, NULL, NULL, &ahb_clk);
  460. DEFINE_CLOCK(slcdc_clk1, 0, PCCR1, 12, NULL, NULL, &ahb_clk);
  461. DEFINE_CLOCK(sahara2_clk1, 0, PCCR1, 13, NULL, NULL, &ahb_clk);
  462. DEFINE_CLOCK(rtic_clk1, 0, PCCR1, 14, NULL, NULL, &ahb_clk);
  463. DEFINE_CLOCK(lcdc_clk2, 0, PCCR1, 15, NULL, NULL, &ahb_clk);
  464. DEFINE_CLOCK(vpu_clk1, 0, PCCR1, 16, NULL, NULL, &ahb_clk);
  465. DEFINE_CLOCK(fec_clk1, 0, PCCR1, 17, NULL, NULL, &ahb_clk);
  466. DEFINE_CLOCK(emma_clk1, 0, PCCR1, 18, NULL, NULL, &ahb_clk);
  467. DEFINE_CLOCK(emi_clk, 0, PCCR1, 19, NULL, NULL, &ahb_clk);
  468. DEFINE_CLOCK(dma_clk1, 0, PCCR1, 20, NULL, NULL, &ahb_clk);
  469. DEFINE_CLOCK(csi_clk1, 0, PCCR1, 21, NULL, NULL, &ahb_clk);
  470. DEFINE_CLOCK(brom_clk, 0, PCCR1, 22, NULL, NULL, &ahb_clk);
  471. DEFINE_CLOCK(ata_clk, 0, PCCR1, 23, NULL, NULL, &ahb_clk);
  472. DEFINE_CLOCK(wdog_clk, 0, PCCR1, 24, NULL, NULL, &ipg_clk);
  473. DEFINE_CLOCK(usb_clk, 0, PCCR1, 25, get_rate_usb, &usb_clk1, &spll_clk);
  474. DEFINE_CLOCK(uart6_clk1, 0, PCCR1, 26, NULL, NULL, &ipg_clk);
  475. DEFINE_CLOCK(uart5_clk1, 0, PCCR1, 27, NULL, NULL, &ipg_clk);
  476. DEFINE_CLOCK(uart4_clk1, 0, PCCR1, 28, NULL, NULL, &ipg_clk);
  477. DEFINE_CLOCK(uart3_clk1, 0, PCCR1, 29, NULL, NULL, &ipg_clk);
  478. DEFINE_CLOCK(uart2_clk1, 0, PCCR1, 30, NULL, NULL, &ipg_clk);
  479. DEFINE_CLOCK(uart1_clk1, 0, PCCR1, 31, NULL, NULL, &ipg_clk);
  480. /* Clocks we cannot directly gate, but drivers need their rates */
  481. DEFINE_CLOCK(cspi1_clk, 0, 0, 0, NULL, &cspi1_clk1, &per2_clk);
  482. DEFINE_CLOCK(cspi2_clk, 1, 0, 0, NULL, &cspi2_clk1, &per2_clk);
  483. DEFINE_CLOCK(cspi3_clk, 2, 0, 0, NULL, &cspi13_clk1, &per2_clk);
  484. DEFINE_CLOCK(sdhc1_clk, 0, 0, 0, NULL, &sdhc1_clk1, &per2_clk);
  485. DEFINE_CLOCK(sdhc2_clk, 1, 0, 0, NULL, &sdhc2_clk1, &per2_clk);
  486. DEFINE_CLOCK(sdhc3_clk, 2, 0, 0, NULL, &sdhc3_clk1, &per2_clk);
  487. DEFINE_CLOCK(pwm_clk, 0, 0, 0, NULL, &pwm_clk1, &per1_clk);
  488. DEFINE_CLOCK(gpt1_clk, 0, 0, 0, NULL, &gpt1_clk1, &per1_clk);
  489. DEFINE_CLOCK(gpt2_clk, 1, 0, 0, NULL, &gpt2_clk1, &per1_clk);
  490. DEFINE_CLOCK(gpt3_clk, 2, 0, 0, NULL, &gpt3_clk1, &per1_clk);
  491. DEFINE_CLOCK(gpt4_clk, 3, 0, 0, NULL, &gpt4_clk1, &per1_clk);
  492. DEFINE_CLOCK(gpt5_clk, 4, 0, 0, NULL, &gpt5_clk1, &per1_clk);
  493. DEFINE_CLOCK(gpt6_clk, 5, 0, 0, NULL, &gpt6_clk1, &per1_clk);
  494. DEFINE_CLOCK(uart1_clk, 0, 0, 0, NULL, &uart1_clk1, &per1_clk);
  495. DEFINE_CLOCK(uart2_clk, 1, 0, 0, NULL, &uart2_clk1, &per1_clk);
  496. DEFINE_CLOCK(uart3_clk, 2, 0, 0, NULL, &uart3_clk1, &per1_clk);
  497. DEFINE_CLOCK(uart4_clk, 3, 0, 0, NULL, &uart4_clk1, &per1_clk);
  498. DEFINE_CLOCK(uart5_clk, 4, 0, 0, NULL, &uart5_clk1, &per1_clk);
  499. DEFINE_CLOCK(uart6_clk, 5, 0, 0, NULL, &uart6_clk1, &per1_clk);
  500. DEFINE_CLOCK1(lcdc_clk, 0, 0, 0, parent, &lcdc_clk1, &per3_clk);
  501. DEFINE_CLOCK1(csi_clk, 0, 0, 0, parent, &csi_clk1, &per4_clk);
  502. #define _REGISTER_CLOCK(d, n, c) \
  503. { \
  504. .dev_id = d, \
  505. .con_id = n, \
  506. .clk = &c, \
  507. },
  508. static struct clk_lookup lookups[] = {
  509. _REGISTER_CLOCK("imx-uart.0", NULL, uart1_clk)
  510. _REGISTER_CLOCK("imx-uart.1", NULL, uart2_clk)
  511. _REGISTER_CLOCK("imx-uart.2", NULL, uart3_clk)
  512. _REGISTER_CLOCK("imx-uart.3", NULL, uart4_clk)
  513. _REGISTER_CLOCK("imx-uart.4", NULL, uart5_clk)
  514. _REGISTER_CLOCK("imx-uart.5", NULL, uart6_clk)
  515. _REGISTER_CLOCK(NULL, "gpt1", gpt1_clk)
  516. _REGISTER_CLOCK(NULL, "gpt2", gpt2_clk)
  517. _REGISTER_CLOCK(NULL, "gpt3", gpt3_clk)
  518. _REGISTER_CLOCK(NULL, "gpt4", gpt4_clk)
  519. _REGISTER_CLOCK(NULL, "gpt5", gpt5_clk)
  520. _REGISTER_CLOCK(NULL, "gpt6", gpt6_clk)
  521. _REGISTER_CLOCK("mxc_pwm.0", NULL, pwm_clk)
  522. _REGISTER_CLOCK("mxc-mmc.0", NULL, sdhc1_clk)
  523. _REGISTER_CLOCK("mxc-mmc.1", NULL, sdhc2_clk)
  524. _REGISTER_CLOCK("mxc-mmc.2", NULL, sdhc3_clk)
  525. _REGISTER_CLOCK(NULL, "cspi1", cspi1_clk)
  526. _REGISTER_CLOCK(NULL, "cspi2", cspi2_clk)
  527. _REGISTER_CLOCK(NULL, "cspi3", cspi3_clk)
  528. _REGISTER_CLOCK("imx-fb.0", NULL, lcdc_clk)
  529. _REGISTER_CLOCK(NULL, "csi", csi_clk)
  530. _REGISTER_CLOCK(NULL, "usb", usb_clk)
  531. _REGISTER_CLOCK(NULL, "ssi1", ssi1_clk)
  532. _REGISTER_CLOCK(NULL, "ssi2", ssi2_clk)
  533. _REGISTER_CLOCK("mxc_nand.0", NULL, nfc_clk)
  534. _REGISTER_CLOCK(NULL, "vpu", vpu_clk)
  535. _REGISTER_CLOCK(NULL, "dma", dma_clk)
  536. _REGISTER_CLOCK(NULL, "rtic", rtic_clk)
  537. _REGISTER_CLOCK(NULL, "brom", brom_clk)
  538. _REGISTER_CLOCK(NULL, "emma", emma_clk)
  539. _REGISTER_CLOCK(NULL, "slcdc", slcdc_clk)
  540. _REGISTER_CLOCK("fec.0", NULL, fec_clk)
  541. _REGISTER_CLOCK(NULL, "emi", emi_clk)
  542. _REGISTER_CLOCK(NULL, "sahara2", sahara2_clk)
  543. _REGISTER_CLOCK(NULL, "ata", ata_clk)
  544. _REGISTER_CLOCK(NULL, "mstick", mstick_clk)
  545. _REGISTER_CLOCK(NULL, "wdog", wdog_clk)
  546. _REGISTER_CLOCK(NULL, "gpio", gpio_clk)
  547. _REGISTER_CLOCK("imx-i2c.0", NULL, i2c1_clk)
  548. _REGISTER_CLOCK("imx-i2c.1", NULL, i2c2_clk)
  549. _REGISTER_CLOCK(NULL, "iim", iim_clk)
  550. _REGISTER_CLOCK(NULL, "kpp", kpp_clk)
  551. _REGISTER_CLOCK("mxc_w1.0", NULL, owire_clk)
  552. _REGISTER_CLOCK(NULL, "rtc", rtc_clk)
  553. _REGISTER_CLOCK(NULL, "scc", scc_clk)
  554. };
  555. /* Adjust the clock path for TO2 and later */
  556. static void __init to2_adjust_clocks(void)
  557. {
  558. unsigned long cscr = __raw_readl(CCM_CSCR);
  559. if (mx27_revision() >= CHIP_REV_2_0) {
  560. if (cscr & CCM_CSCR_ARM_SRC)
  561. cpu_clk.parent = &mpll_main1_clk;
  562. if (!(cscr & CCM_CSCR_SSI2))
  563. ssi1_clk.parent = &spll_clk;
  564. if (!(cscr & CCM_CSCR_SSI1))
  565. ssi1_clk.parent = &spll_clk;
  566. if (!(cscr & CCM_CSCR_VPU))
  567. vpu_clk.parent = &spll_clk;
  568. } else {
  569. cpu_clk.parent = &mpll_clk;
  570. cpu_clk.set_parent = NULL;
  571. cpu_clk.round_rate = NULL;
  572. cpu_clk.set_rate = NULL;
  573. ahb_clk.parent = &mpll_clk;
  574. per1_clk.parent = &mpll_clk;
  575. per2_clk.parent = &mpll_clk;
  576. per3_clk.parent = &mpll_clk;
  577. per4_clk.parent = &mpll_clk;
  578. ssi1_clk.parent = &mpll_clk;
  579. ssi2_clk.parent = &mpll_clk;
  580. vpu_clk.parent = &mpll_clk;
  581. }
  582. }
  583. /*
  584. * must be called very early to get information about the
  585. * available clock rate when the timer framework starts
  586. */
  587. int __init mx27_clocks_init(unsigned long fref)
  588. {
  589. u32 cscr = __raw_readl(CCM_CSCR);
  590. int i;
  591. external_high_reference = fref;
  592. /* detect clock reference for both system PLLs */
  593. if (cscr & CCM_CSCR_MCU)
  594. mpll_clk.parent = &ckih_clk;
  595. else
  596. mpll_clk.parent = &fpm_clk;
  597. if (cscr & CCM_CSCR_SP)
  598. spll_clk.parent = &ckih_clk;
  599. else
  600. spll_clk.parent = &fpm_clk;
  601. to2_adjust_clocks();
  602. for (i = 0; i < ARRAY_SIZE(lookups); i++)
  603. clkdev_add(&lookups[i]);
  604. /* Turn off all clocks we do not need */
  605. __raw_writel(0, CCM_PCCR0);
  606. __raw_writel((1 << 10) | (1 << 19), CCM_PCCR1);
  607. spll_clk.disable(&spll_clk);
  608. /* enable basic clocks */
  609. clk_enable(&per1_clk);
  610. clk_enable(&gpio_clk);
  611. clk_enable(&emi_clk);
  612. clk_enable(&iim_clk);
  613. #ifdef CONFIG_DEBUG_LL_CONSOLE
  614. clk_enable(&uart1_clk);
  615. #endif
  616. mxc_timer_init(&gpt1_clk);
  617. return 0;
  618. }