clock-imx35.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /*
  2. * Copyright (C) 2009 by Sascha Hauer, Pengutronix
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. * MA 02110-1301, USA.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/list.h>
  21. #include <linux/clk.h>
  22. #include <linux/io.h>
  23. #include <linux/clkdev.h>
  24. #include <mach/clock.h>
  25. #include <mach/hardware.h>
  26. #include <mach/common.h>
  27. #define CCM_BASE MX35_IO_ADDRESS(MX35_CCM_BASE_ADDR)
  28. #define CCM_CCMR 0x00
  29. #define CCM_PDR0 0x04
  30. #define CCM_PDR1 0x08
  31. #define CCM_PDR2 0x0C
  32. #define CCM_PDR3 0x10
  33. #define CCM_PDR4 0x14
  34. #define CCM_RCSR 0x18
  35. #define CCM_MPCTL 0x1C
  36. #define CCM_PPCTL 0x20
  37. #define CCM_ACMR 0x24
  38. #define CCM_COSR 0x28
  39. #define CCM_CGR0 0x2C
  40. #define CCM_CGR1 0x30
  41. #define CCM_CGR2 0x34
  42. #define CCM_CGR3 0x38
  43. #ifdef HAVE_SET_RATE_SUPPORT
  44. static void calc_dividers(u32 div, u32 *pre, u32 *post, u32 maxpost)
  45. {
  46. u32 min_pre, temp_pre, old_err, err;
  47. min_pre = (div - 1) / maxpost + 1;
  48. old_err = 8;
  49. for (temp_pre = 8; temp_pre >= min_pre; temp_pre--) {
  50. if (div > (temp_pre * maxpost))
  51. break;
  52. if (div < (temp_pre * temp_pre))
  53. continue;
  54. err = div % temp_pre;
  55. if (err == 0) {
  56. *pre = temp_pre;
  57. break;
  58. }
  59. err = temp_pre - err;
  60. if (err < old_err) {
  61. old_err = err;
  62. *pre = temp_pre;
  63. }
  64. }
  65. *post = (div + *pre - 1) / *pre;
  66. }
  67. /* get the best values for a 3-bit divider combined with a 6-bit divider */
  68. static void calc_dividers_3_6(u32 div, u32 *pre, u32 *post)
  69. {
  70. if (div >= 512) {
  71. *pre = 8;
  72. *post = 64;
  73. } else if (div >= 64) {
  74. calc_dividers(div, pre, post, 64);
  75. } else if (div <= 8) {
  76. *pre = div;
  77. *post = 1;
  78. } else {
  79. *pre = 1;
  80. *post = div;
  81. }
  82. }
  83. /* get the best values for two cascaded 3-bit dividers */
  84. static void calc_dividers_3_3(u32 div, u32 *pre, u32 *post)
  85. {
  86. if (div >= 64) {
  87. *pre = *post = 8;
  88. } else if (div > 8) {
  89. calc_dividers(div, pre, post, 8);
  90. } else {
  91. *pre = 1;
  92. *post = div;
  93. }
  94. }
  95. #endif
  96. static unsigned long get_rate_mpll(void)
  97. {
  98. ulong mpctl = __raw_readl(CCM_BASE + CCM_MPCTL);
  99. return mxc_decode_pll(mpctl, 24000000);
  100. }
  101. static unsigned long get_rate_ppll(void)
  102. {
  103. ulong ppctl = __raw_readl(CCM_BASE + CCM_PPCTL);
  104. return mxc_decode_pll(ppctl, 24000000);
  105. }
  106. struct arm_ahb_div {
  107. unsigned char arm, ahb, sel;
  108. };
  109. static struct arm_ahb_div clk_consumer[] = {
  110. { .arm = 1, .ahb = 4, .sel = 0},
  111. { .arm = 1, .ahb = 3, .sel = 1},
  112. { .arm = 2, .ahb = 2, .sel = 0},
  113. { .arm = 0, .ahb = 0, .sel = 0},
  114. { .arm = 0, .ahb = 0, .sel = 0},
  115. { .arm = 0, .ahb = 0, .sel = 0},
  116. { .arm = 4, .ahb = 1, .sel = 0},
  117. { .arm = 1, .ahb = 5, .sel = 0},
  118. { .arm = 1, .ahb = 8, .sel = 0},
  119. { .arm = 1, .ahb = 6, .sel = 1},
  120. { .arm = 2, .ahb = 4, .sel = 0},
  121. { .arm = 0, .ahb = 0, .sel = 0},
  122. { .arm = 0, .ahb = 0, .sel = 0},
  123. { .arm = 0, .ahb = 0, .sel = 0},
  124. { .arm = 4, .ahb = 2, .sel = 0},
  125. { .arm = 0, .ahb = 0, .sel = 0},
  126. };
  127. static unsigned long get_rate_arm(void)
  128. {
  129. unsigned long pdr0 = __raw_readl(CCM_BASE + CCM_PDR0);
  130. struct arm_ahb_div *aad;
  131. unsigned long fref = get_rate_mpll();
  132. aad = &clk_consumer[(pdr0 >> 16) & 0xf];
  133. if (aad->sel)
  134. fref = fref * 3 / 4;
  135. return fref / aad->arm;
  136. }
  137. static unsigned long get_rate_ahb(struct clk *clk)
  138. {
  139. unsigned long pdr0 = __raw_readl(CCM_BASE + CCM_PDR0);
  140. struct arm_ahb_div *aad;
  141. unsigned long fref = get_rate_arm();
  142. aad = &clk_consumer[(pdr0 >> 16) & 0xf];
  143. return fref / aad->ahb;
  144. }
  145. static unsigned long get_rate_ipg(struct clk *clk)
  146. {
  147. return get_rate_ahb(NULL) >> 1;
  148. }
  149. static unsigned long get_rate_uart(struct clk *clk)
  150. {
  151. unsigned long pdr3 = __raw_readl(CCM_BASE + CCM_PDR3);
  152. unsigned long pdr4 = __raw_readl(CCM_BASE + CCM_PDR4);
  153. unsigned long div = ((pdr4 >> 10) & 0x3f) + 1;
  154. if (pdr3 & (1 << 14))
  155. return get_rate_arm() / div;
  156. else
  157. return get_rate_ppll() / div;
  158. }
  159. static unsigned long get_rate_sdhc(struct clk *clk)
  160. {
  161. unsigned long pdr3 = __raw_readl(CCM_BASE + CCM_PDR3);
  162. unsigned long div, rate;
  163. if (pdr3 & (1 << 6))
  164. rate = get_rate_arm();
  165. else
  166. rate = get_rate_ppll();
  167. switch (clk->id) {
  168. default:
  169. case 0:
  170. div = pdr3 & 0x3f;
  171. break;
  172. case 1:
  173. div = (pdr3 >> 8) & 0x3f;
  174. break;
  175. case 2:
  176. div = (pdr3 >> 16) & 0x3f;
  177. break;
  178. }
  179. return rate / (div + 1);
  180. }
  181. static unsigned long get_rate_mshc(struct clk *clk)
  182. {
  183. unsigned long pdr1 = __raw_readl(CCM_BASE + CCM_PDR1);
  184. unsigned long div1, div2, rate;
  185. if (pdr1 & (1 << 7))
  186. rate = get_rate_arm();
  187. else
  188. rate = get_rate_ppll();
  189. div1 = (pdr1 >> 29) & 0x7;
  190. div2 = (pdr1 >> 22) & 0x3f;
  191. return rate / ((div1 + 1) * (div2 + 1));
  192. }
  193. static unsigned long get_rate_ssi(struct clk *clk)
  194. {
  195. unsigned long pdr2 = __raw_readl(CCM_BASE + CCM_PDR2);
  196. unsigned long div1, div2, rate;
  197. if (pdr2 & (1 << 6))
  198. rate = get_rate_arm();
  199. else
  200. rate = get_rate_ppll();
  201. switch (clk->id) {
  202. default:
  203. case 0:
  204. div1 = pdr2 & 0x3f;
  205. div2 = (pdr2 >> 24) & 0x7;
  206. break;
  207. case 1:
  208. div1 = (pdr2 >> 8) & 0x3f;
  209. div2 = (pdr2 >> 27) & 0x7;
  210. break;
  211. }
  212. return rate / ((div1 + 1) * (div2 + 1));
  213. }
  214. static unsigned long get_rate_csi(struct clk *clk)
  215. {
  216. unsigned long pdr2 = __raw_readl(CCM_BASE + CCM_PDR2);
  217. unsigned long rate;
  218. if (pdr2 & (1 << 7))
  219. rate = get_rate_arm();
  220. else
  221. rate = get_rate_ppll();
  222. return rate / (((pdr2 >> 16) & 0x3f) + 1);
  223. }
  224. static unsigned long get_rate_otg(struct clk *clk)
  225. {
  226. unsigned long pdr4 = __raw_readl(CCM_BASE + CCM_PDR4);
  227. unsigned long rate;
  228. if (pdr4 & (1 << 9))
  229. rate = get_rate_arm();
  230. else
  231. rate = get_rate_ppll();
  232. return rate / (((pdr4 >> 22) & 0x3f) + 1);
  233. }
  234. static unsigned long get_rate_ipg_per(struct clk *clk)
  235. {
  236. unsigned long pdr0 = __raw_readl(CCM_BASE + CCM_PDR0);
  237. unsigned long pdr4 = __raw_readl(CCM_BASE + CCM_PDR4);
  238. unsigned long div;
  239. if (pdr0 & (1 << 26)) {
  240. div = (pdr4 >> 16) & 0x3f;
  241. return get_rate_arm() / (div + 1);
  242. } else {
  243. div = (pdr0 >> 12) & 0x7;
  244. return get_rate_ahb(NULL) / (div + 1);
  245. }
  246. }
  247. static unsigned long get_rate_hsp(struct clk *clk)
  248. {
  249. unsigned long hsp_podf = (__raw_readl(CCM_BASE + CCM_PDR0) >> 20) & 0x03;
  250. unsigned long fref = get_rate_mpll();
  251. if (fref > 400 * 1000 * 1000) {
  252. switch (hsp_podf) {
  253. case 0:
  254. return fref >> 2;
  255. case 1:
  256. return fref >> 3;
  257. case 2:
  258. return fref / 3;
  259. }
  260. } else {
  261. switch (hsp_podf) {
  262. case 0:
  263. case 2:
  264. return fref / 3;
  265. case 1:
  266. return fref / 6;
  267. }
  268. }
  269. return 0;
  270. }
  271. static int clk_cgr_enable(struct clk *clk)
  272. {
  273. u32 reg;
  274. reg = __raw_readl(clk->enable_reg);
  275. reg |= 3 << clk->enable_shift;
  276. __raw_writel(reg, clk->enable_reg);
  277. return 0;
  278. }
  279. static void clk_cgr_disable(struct clk *clk)
  280. {
  281. u32 reg;
  282. reg = __raw_readl(clk->enable_reg);
  283. reg &= ~(3 << clk->enable_shift);
  284. __raw_writel(reg, clk->enable_reg);
  285. }
  286. #define DEFINE_CLOCK(name, i, er, es, gr, sr) \
  287. static struct clk name = { \
  288. .id = i, \
  289. .enable_reg = CCM_BASE + er, \
  290. .enable_shift = es, \
  291. .get_rate = gr, \
  292. .set_rate = sr, \
  293. .enable = clk_cgr_enable, \
  294. .disable = clk_cgr_disable, \
  295. }
  296. DEFINE_CLOCK(asrc_clk, 0, CCM_CGR0, 0, NULL, NULL);
  297. DEFINE_CLOCK(ata_clk, 0, CCM_CGR0, 2, get_rate_ipg, NULL);
  298. /* DEFINE_CLOCK(audmux_clk, 0, CCM_CGR0, 4, NULL, NULL); */
  299. DEFINE_CLOCK(can1_clk, 0, CCM_CGR0, 6, get_rate_ipg, NULL);
  300. DEFINE_CLOCK(can2_clk, 1, CCM_CGR0, 8, get_rate_ipg, NULL);
  301. DEFINE_CLOCK(cspi1_clk, 0, CCM_CGR0, 10, get_rate_ipg, NULL);
  302. DEFINE_CLOCK(cspi2_clk, 1, CCM_CGR0, 12, get_rate_ipg, NULL);
  303. DEFINE_CLOCK(ect_clk, 0, CCM_CGR0, 14, get_rate_ipg, NULL);
  304. DEFINE_CLOCK(edio_clk, 0, CCM_CGR0, 16, NULL, NULL);
  305. DEFINE_CLOCK(emi_clk, 0, CCM_CGR0, 18, get_rate_ipg, NULL);
  306. DEFINE_CLOCK(epit1_clk, 0, CCM_CGR0, 20, get_rate_ipg, NULL);
  307. DEFINE_CLOCK(epit2_clk, 1, CCM_CGR0, 22, get_rate_ipg, NULL);
  308. DEFINE_CLOCK(esai_clk, 0, CCM_CGR0, 24, NULL, NULL);
  309. DEFINE_CLOCK(esdhc1_clk, 0, CCM_CGR0, 26, get_rate_sdhc, NULL);
  310. DEFINE_CLOCK(esdhc2_clk, 1, CCM_CGR0, 28, get_rate_sdhc, NULL);
  311. DEFINE_CLOCK(esdhc3_clk, 2, CCM_CGR0, 30, get_rate_sdhc, NULL);
  312. DEFINE_CLOCK(fec_clk, 0, CCM_CGR1, 0, get_rate_ipg, NULL);
  313. DEFINE_CLOCK(gpio1_clk, 0, CCM_CGR1, 2, NULL, NULL);
  314. DEFINE_CLOCK(gpio2_clk, 1, CCM_CGR1, 4, NULL, NULL);
  315. DEFINE_CLOCK(gpio3_clk, 2, CCM_CGR1, 6, NULL, NULL);
  316. DEFINE_CLOCK(gpt_clk, 0, CCM_CGR1, 8, get_rate_ipg, NULL);
  317. DEFINE_CLOCK(i2c1_clk, 0, CCM_CGR1, 10, get_rate_ipg_per, NULL);
  318. DEFINE_CLOCK(i2c2_clk, 1, CCM_CGR1, 12, get_rate_ipg_per, NULL);
  319. DEFINE_CLOCK(i2c3_clk, 2, CCM_CGR1, 14, get_rate_ipg_per, NULL);
  320. DEFINE_CLOCK(iomuxc_clk, 0, CCM_CGR1, 16, NULL, NULL);
  321. DEFINE_CLOCK(ipu_clk, 0, CCM_CGR1, 18, get_rate_hsp, NULL);
  322. DEFINE_CLOCK(kpp_clk, 0, CCM_CGR1, 20, get_rate_ipg, NULL);
  323. DEFINE_CLOCK(mlb_clk, 0, CCM_CGR1, 22, get_rate_ahb, NULL);
  324. DEFINE_CLOCK(mshc_clk, 0, CCM_CGR1, 24, get_rate_mshc, NULL);
  325. DEFINE_CLOCK(owire_clk, 0, CCM_CGR1, 26, get_rate_ipg_per, NULL);
  326. DEFINE_CLOCK(pwm_clk, 0, CCM_CGR1, 28, get_rate_ipg_per, NULL);
  327. DEFINE_CLOCK(rngc_clk, 0, CCM_CGR1, 30, get_rate_ipg, NULL);
  328. DEFINE_CLOCK(rtc_clk, 0, CCM_CGR2, 0, get_rate_ipg, NULL);
  329. DEFINE_CLOCK(rtic_clk, 0, CCM_CGR2, 2, get_rate_ahb, NULL);
  330. DEFINE_CLOCK(scc_clk, 0, CCM_CGR2, 4, get_rate_ipg, NULL);
  331. DEFINE_CLOCK(sdma_clk, 0, CCM_CGR2, 6, NULL, NULL);
  332. DEFINE_CLOCK(spba_clk, 0, CCM_CGR2, 8, get_rate_ipg, NULL);
  333. DEFINE_CLOCK(spdif_clk, 0, CCM_CGR2, 10, NULL, NULL);
  334. DEFINE_CLOCK(ssi1_clk, 0, CCM_CGR2, 12, get_rate_ssi, NULL);
  335. DEFINE_CLOCK(ssi2_clk, 1, CCM_CGR2, 14, get_rate_ssi, NULL);
  336. DEFINE_CLOCK(uart1_clk, 0, CCM_CGR2, 16, get_rate_uart, NULL);
  337. DEFINE_CLOCK(uart2_clk, 1, CCM_CGR2, 18, get_rate_uart, NULL);
  338. DEFINE_CLOCK(uart3_clk, 2, CCM_CGR2, 20, get_rate_uart, NULL);
  339. DEFINE_CLOCK(usbotg_clk, 0, CCM_CGR2, 22, get_rate_otg, NULL);
  340. DEFINE_CLOCK(wdog_clk, 0, CCM_CGR2, 24, NULL, NULL);
  341. DEFINE_CLOCK(max_clk, 0, CCM_CGR2, 26, NULL, NULL);
  342. DEFINE_CLOCK(audmux_clk, 0, CCM_CGR2, 30, NULL, NULL);
  343. DEFINE_CLOCK(csi_clk, 0, CCM_CGR3, 0, get_rate_csi, NULL);
  344. DEFINE_CLOCK(iim_clk, 0, CCM_CGR3, 2, NULL, NULL);
  345. DEFINE_CLOCK(gpu2d_clk, 0, CCM_CGR3, 4, NULL, NULL);
  346. DEFINE_CLOCK(usbahb_clk, 0, 0, 0, get_rate_ahb, NULL);
  347. static int clk_dummy_enable(struct clk *clk)
  348. {
  349. return 0;
  350. }
  351. static void clk_dummy_disable(struct clk *clk)
  352. {
  353. }
  354. static unsigned long get_rate_nfc(struct clk *clk)
  355. {
  356. unsigned long div1;
  357. div1 = (__raw_readl(CCM_BASE + CCM_PDR4) >> 28) + 1;
  358. return get_rate_ahb(NULL) / div1;
  359. }
  360. /* NAND Controller: It seems it can't be disabled */
  361. static struct clk nfc_clk = {
  362. .id = 0,
  363. .enable_reg = 0,
  364. .enable_shift = 0,
  365. .get_rate = get_rate_nfc,
  366. .set_rate = NULL, /* set_rate_nfc, */
  367. .enable = clk_dummy_enable,
  368. .disable = clk_dummy_disable
  369. };
  370. #define _REGISTER_CLOCK(d, n, c) \
  371. { \
  372. .dev_id = d, \
  373. .con_id = n, \
  374. .clk = &c, \
  375. },
  376. static struct clk_lookup lookups[] = {
  377. _REGISTER_CLOCK(NULL, "asrc", asrc_clk)
  378. _REGISTER_CLOCK(NULL, "ata", ata_clk)
  379. _REGISTER_CLOCK("flexcan.0", NULL, can1_clk)
  380. _REGISTER_CLOCK("flexcan.1", NULL, can2_clk)
  381. _REGISTER_CLOCK("imx35-cspi.0", NULL, cspi1_clk)
  382. _REGISTER_CLOCK("imx35-cspi.1", NULL, cspi2_clk)
  383. _REGISTER_CLOCK(NULL, "ect", ect_clk)
  384. _REGISTER_CLOCK(NULL, "edio", edio_clk)
  385. _REGISTER_CLOCK(NULL, "emi", emi_clk)
  386. _REGISTER_CLOCK("imx-epit.0", NULL, epit1_clk)
  387. _REGISTER_CLOCK("imx-epit.1", NULL, epit2_clk)
  388. _REGISTER_CLOCK(NULL, "esai", esai_clk)
  389. _REGISTER_CLOCK("sdhci-esdhc-imx.0", NULL, esdhc1_clk)
  390. _REGISTER_CLOCK("sdhci-esdhc-imx.1", NULL, esdhc2_clk)
  391. _REGISTER_CLOCK("sdhci-esdhc-imx.2", NULL, esdhc3_clk)
  392. _REGISTER_CLOCK("fec.0", NULL, fec_clk)
  393. _REGISTER_CLOCK(NULL, "gpio", gpio1_clk)
  394. _REGISTER_CLOCK(NULL, "gpio", gpio2_clk)
  395. _REGISTER_CLOCK(NULL, "gpio", gpio3_clk)
  396. _REGISTER_CLOCK("gpt.0", NULL, gpt_clk)
  397. _REGISTER_CLOCK("imx-i2c.0", NULL, i2c1_clk)
  398. _REGISTER_CLOCK("imx-i2c.1", NULL, i2c2_clk)
  399. _REGISTER_CLOCK("imx-i2c.2", NULL, i2c3_clk)
  400. _REGISTER_CLOCK(NULL, "iomuxc", iomuxc_clk)
  401. _REGISTER_CLOCK("ipu-core", NULL, ipu_clk)
  402. _REGISTER_CLOCK("mx3_sdc_fb", NULL, ipu_clk)
  403. _REGISTER_CLOCK(NULL, "kpp", kpp_clk)
  404. _REGISTER_CLOCK(NULL, "mlb", mlb_clk)
  405. _REGISTER_CLOCK(NULL, "mshc", mshc_clk)
  406. _REGISTER_CLOCK("mxc_w1", NULL, owire_clk)
  407. _REGISTER_CLOCK(NULL, "pwm", pwm_clk)
  408. _REGISTER_CLOCK(NULL, "rngc", rngc_clk)
  409. _REGISTER_CLOCK(NULL, "rtc", rtc_clk)
  410. _REGISTER_CLOCK(NULL, "rtic", rtic_clk)
  411. _REGISTER_CLOCK(NULL, "scc", scc_clk)
  412. _REGISTER_CLOCK("imx-sdma", NULL, sdma_clk)
  413. _REGISTER_CLOCK(NULL, "spba", spba_clk)
  414. _REGISTER_CLOCK(NULL, "spdif", spdif_clk)
  415. _REGISTER_CLOCK("imx-ssi.0", NULL, ssi1_clk)
  416. _REGISTER_CLOCK("imx-ssi.1", NULL, ssi2_clk)
  417. _REGISTER_CLOCK("imx-uart.0", NULL, uart1_clk)
  418. _REGISTER_CLOCK("imx-uart.1", NULL, uart2_clk)
  419. _REGISTER_CLOCK("imx-uart.2", NULL, uart3_clk)
  420. _REGISTER_CLOCK("mxc-ehci.0", "usb", usbotg_clk)
  421. _REGISTER_CLOCK("mxc-ehci.1", "usb", usbotg_clk)
  422. _REGISTER_CLOCK("mxc-ehci.2", "usb", usbotg_clk)
  423. _REGISTER_CLOCK("fsl-usb2-udc", "usb", usbotg_clk)
  424. _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", usbahb_clk)
  425. _REGISTER_CLOCK("imx2-wdt.0", NULL, wdog_clk)
  426. _REGISTER_CLOCK(NULL, "max", max_clk)
  427. _REGISTER_CLOCK(NULL, "audmux", audmux_clk)
  428. _REGISTER_CLOCK(NULL, "csi", csi_clk)
  429. _REGISTER_CLOCK(NULL, "iim", iim_clk)
  430. _REGISTER_CLOCK(NULL, "gpu2d", gpu2d_clk)
  431. _REGISTER_CLOCK("mxc_nand.0", NULL, nfc_clk)
  432. };
  433. int __init mx35_clocks_init()
  434. {
  435. unsigned int cgr2 = 3 << 26, cgr3 = 0;
  436. #if defined(CONFIG_DEBUG_LL) && !defined(CONFIG_DEBUG_ICEDCC)
  437. cgr2 |= 3 << 16;
  438. #endif
  439. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  440. /* Turn off all clocks except the ones we need to survive, namely:
  441. * EMI, GPIO1/2/3, GPT, IOMUX, MAX and eventually uart
  442. */
  443. __raw_writel((3 << 18), CCM_BASE + CCM_CGR0);
  444. __raw_writel((3 << 2) | (3 << 4) | (3 << 6) | (3 << 8) | (3 << 16),
  445. CCM_BASE + CCM_CGR1);
  446. /*
  447. * Check if we came up in internal boot mode. If yes, we need some
  448. * extra clocks turned on, otherwise the MX35 boot ROM code will
  449. * hang after a watchdog reset.
  450. */
  451. if (!(__raw_readl(CCM_BASE + CCM_RCSR) & (3 << 10))) {
  452. /* Additionally turn on UART1, SCC, and IIM clocks */
  453. cgr2 |= 3 << 16 | 3 << 4;
  454. cgr3 |= 3 << 2;
  455. }
  456. __raw_writel(cgr2, CCM_BASE + CCM_CGR2);
  457. __raw_writel(cgr3, CCM_BASE + CCM_CGR3);
  458. clk_enable(&iim_clk);
  459. mx35_read_cpu_rev();
  460. #ifdef CONFIG_MXC_USE_EPIT
  461. epit_timer_init(&epit1_clk,
  462. MX35_IO_ADDRESS(MX35_EPIT1_BASE_ADDR), MX35_INT_EPIT1);
  463. #else
  464. mxc_timer_init(&gpt_clk,
  465. MX35_IO_ADDRESS(MX35_GPT1_BASE_ADDR), MX35_INT_GPT);
  466. #endif
  467. return 0;
  468. }