clock-imx27.c 22 KB

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