clock_imx27.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  1. /*
  2. * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  3. * Copyright 2008 Juergen Beisert, 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/clk.h>
  20. #include <linux/io.h>
  21. #include <linux/module.h>
  22. #include <linux/spinlock.h>
  23. #include <mach/clock.h>
  24. #include <mach/common.h>
  25. #include <asm/div64.h>
  26. #include "crm_regs.h"
  27. static struct clk ckil_clk;
  28. static struct clk mpll_clk;
  29. static struct clk mpll_main_clk[];
  30. static struct clk spll_clk;
  31. static int _clk_enable(struct clk *clk)
  32. {
  33. unsigned long reg;
  34. reg = __raw_readl(clk->enable_reg);
  35. reg |= 1 << clk->enable_shift;
  36. __raw_writel(reg, clk->enable_reg);
  37. return 0;
  38. }
  39. static void _clk_disable(struct clk *clk)
  40. {
  41. unsigned long reg;
  42. reg = __raw_readl(clk->enable_reg);
  43. reg &= ~(1 << clk->enable_shift);
  44. __raw_writel(reg, clk->enable_reg);
  45. }
  46. static int _clk_spll_enable(struct clk *clk)
  47. {
  48. unsigned long reg;
  49. reg = __raw_readl(CCM_CSCR);
  50. reg |= CCM_CSCR_SPEN;
  51. __raw_writel(reg, CCM_CSCR);
  52. while ((__raw_readl(CCM_SPCTL1) & CCM_SPCTL1_LF) == 0)
  53. ;
  54. return 0;
  55. }
  56. static void _clk_spll_disable(struct clk *clk)
  57. {
  58. unsigned long reg;
  59. reg = __raw_readl(CCM_CSCR);
  60. reg &= ~CCM_CSCR_SPEN;
  61. __raw_writel(reg, CCM_CSCR);
  62. }
  63. static void _clk_pccr01_enable(unsigned long mask0, unsigned long mask1)
  64. {
  65. unsigned long reg;
  66. reg = __raw_readl(CCM_PCCR0);
  67. reg |= mask0;
  68. __raw_writel(reg, CCM_PCCR0);
  69. reg = __raw_readl(CCM_PCCR1);
  70. reg |= mask1;
  71. __raw_writel(reg, CCM_PCCR1);
  72. }
  73. static void _clk_pccr01_disable(unsigned long mask0, unsigned long mask1)
  74. {
  75. unsigned long reg;
  76. reg = __raw_readl(CCM_PCCR0);
  77. reg &= ~mask0;
  78. __raw_writel(reg, CCM_PCCR0);
  79. reg = __raw_readl(CCM_PCCR1);
  80. reg &= ~mask1;
  81. __raw_writel(reg, CCM_PCCR1);
  82. }
  83. static void _clk_pccr10_enable(unsigned long mask1, unsigned long mask0)
  84. {
  85. unsigned long reg;
  86. reg = __raw_readl(CCM_PCCR1);
  87. reg |= mask1;
  88. __raw_writel(reg, CCM_PCCR1);
  89. reg = __raw_readl(CCM_PCCR0);
  90. reg |= mask0;
  91. __raw_writel(reg, CCM_PCCR0);
  92. }
  93. static void _clk_pccr10_disable(unsigned long mask1, unsigned long mask0)
  94. {
  95. unsigned long reg;
  96. reg = __raw_readl(CCM_PCCR1);
  97. reg &= ~mask1;
  98. __raw_writel(reg, CCM_PCCR1);
  99. reg = __raw_readl(CCM_PCCR0);
  100. reg &= ~mask0;
  101. __raw_writel(reg, CCM_PCCR0);
  102. }
  103. static int _clk_dma_enable(struct clk *clk)
  104. {
  105. _clk_pccr01_enable(CCM_PCCR0_DMA_MASK, CCM_PCCR1_HCLK_DMA_MASK);
  106. return 0;
  107. }
  108. static void _clk_dma_disable(struct clk *clk)
  109. {
  110. _clk_pccr01_disable(CCM_PCCR0_DMA_MASK, CCM_PCCR1_HCLK_DMA_MASK);
  111. }
  112. static int _clk_rtic_enable(struct clk *clk)
  113. {
  114. _clk_pccr01_enable(CCM_PCCR0_RTIC_MASK, CCM_PCCR1_HCLK_RTIC_MASK);
  115. return 0;
  116. }
  117. static void _clk_rtic_disable(struct clk *clk)
  118. {
  119. _clk_pccr01_disable(CCM_PCCR0_RTIC_MASK, CCM_PCCR1_HCLK_RTIC_MASK);
  120. }
  121. static int _clk_emma_enable(struct clk *clk)
  122. {
  123. _clk_pccr01_enable(CCM_PCCR0_EMMA_MASK, CCM_PCCR1_HCLK_EMMA_MASK);
  124. return 0;
  125. }
  126. static void _clk_emma_disable(struct clk *clk)
  127. {
  128. _clk_pccr01_disable(CCM_PCCR0_EMMA_MASK, CCM_PCCR1_HCLK_EMMA_MASK);
  129. }
  130. static int _clk_slcdc_enable(struct clk *clk)
  131. {
  132. _clk_pccr01_enable(CCM_PCCR0_SLCDC_MASK, CCM_PCCR1_HCLK_SLCDC_MASK);
  133. return 0;
  134. }
  135. static void _clk_slcdc_disable(struct clk *clk)
  136. {
  137. _clk_pccr01_disable(CCM_PCCR0_SLCDC_MASK, CCM_PCCR1_HCLK_SLCDC_MASK);
  138. }
  139. static int _clk_fec_enable(struct clk *clk)
  140. {
  141. _clk_pccr01_enable(CCM_PCCR0_FEC_MASK, CCM_PCCR1_HCLK_FEC_MASK);
  142. return 0;
  143. }
  144. static void _clk_fec_disable(struct clk *clk)
  145. {
  146. _clk_pccr01_disable(CCM_PCCR0_FEC_MASK, CCM_PCCR1_HCLK_FEC_MASK);
  147. }
  148. static int _clk_vpu_enable(struct clk *clk)
  149. {
  150. unsigned long reg;
  151. reg = __raw_readl(CCM_PCCR1);
  152. reg |= CCM_PCCR1_VPU_BAUD_MASK | CCM_PCCR1_HCLK_VPU_MASK;
  153. __raw_writel(reg, CCM_PCCR1);
  154. return 0;
  155. }
  156. static void _clk_vpu_disable(struct clk *clk)
  157. {
  158. unsigned long reg;
  159. reg = __raw_readl(CCM_PCCR1);
  160. reg &= ~(CCM_PCCR1_VPU_BAUD_MASK | CCM_PCCR1_HCLK_VPU_MASK);
  161. __raw_writel(reg, CCM_PCCR1);
  162. }
  163. static int _clk_sahara2_enable(struct clk *clk)
  164. {
  165. _clk_pccr01_enable(CCM_PCCR0_SAHARA_MASK, CCM_PCCR1_HCLK_SAHARA_MASK);
  166. return 0;
  167. }
  168. static void _clk_sahara2_disable(struct clk *clk)
  169. {
  170. _clk_pccr01_disable(CCM_PCCR0_SAHARA_MASK, CCM_PCCR1_HCLK_SAHARA_MASK);
  171. }
  172. static int _clk_mstick1_enable(struct clk *clk)
  173. {
  174. _clk_pccr10_enable(CCM_PCCR1_MSHC_BAUD_MASK, CCM_PCCR0_MSHC_MASK);
  175. return 0;
  176. }
  177. static void _clk_mstick1_disable(struct clk *clk)
  178. {
  179. _clk_pccr10_disable(CCM_PCCR1_MSHC_BAUD_MASK, CCM_PCCR0_MSHC_MASK);
  180. }
  181. #define CSCR() (__raw_readl(CCM_CSCR))
  182. #define PCDR0() (__raw_readl(CCM_PCDR0))
  183. #define PCDR1() (__raw_readl(CCM_PCDR1))
  184. static int _clk_cpu_set_parent(struct clk *clk, struct clk *parent)
  185. {
  186. int cscr = CSCR();
  187. if (clk->parent == parent)
  188. return 0;
  189. if (mx27_revision() >= CHIP_REV_2_0) {
  190. if (parent == &mpll_main_clk[0]) {
  191. cscr |= CCM_CSCR_ARM_SRC;
  192. } else {
  193. if (parent == &mpll_main_clk[1])
  194. cscr &= ~CCM_CSCR_ARM_SRC;
  195. else
  196. return -EINVAL;
  197. }
  198. __raw_writel(cscr, CCM_CSCR);
  199. } else
  200. return -ENODEV;
  201. clk->parent = parent;
  202. return 0;
  203. }
  204. static unsigned long _clk_cpu_round_rate(struct clk *clk, unsigned long rate)
  205. {
  206. int div;
  207. unsigned long parent_rate;
  208. parent_rate = clk_get_rate(clk->parent);
  209. div = parent_rate / rate;
  210. if (parent_rate % rate)
  211. div++;
  212. if (div > 4)
  213. div = 4;
  214. return parent_rate / div;
  215. }
  216. static int _clk_cpu_set_rate(struct clk *clk, unsigned long rate)
  217. {
  218. unsigned int div;
  219. uint32_t reg;
  220. unsigned long parent_rate;
  221. parent_rate = clk_get_rate(clk->parent);
  222. div = parent_rate / rate;
  223. if (div > 4 || div < 1 || ((parent_rate / div) != rate))
  224. return -EINVAL;
  225. div--;
  226. reg = __raw_readl(CCM_CSCR);
  227. if (mx27_revision() >= CHIP_REV_2_0) {
  228. reg &= ~CCM_CSCR_ARM_MASK;
  229. reg |= div << CCM_CSCR_ARM_OFFSET;
  230. reg &= ~0x06;
  231. __raw_writel(reg | 0x80000000, CCM_CSCR);
  232. } else {
  233. printk(KERN_ERR "Cant set CPU frequency!\n");
  234. }
  235. return 0;
  236. }
  237. static unsigned long _clk_perclkx_round_rate(struct clk *clk,
  238. unsigned long rate)
  239. {
  240. u32 div;
  241. unsigned long parent_rate;
  242. parent_rate = clk_get_rate(clk->parent);
  243. div = parent_rate / rate;
  244. if (parent_rate % rate)
  245. div++;
  246. if (div > 64)
  247. div = 64;
  248. return parent_rate / div;
  249. }
  250. static int _clk_perclkx_set_rate(struct clk *clk, unsigned long rate)
  251. {
  252. u32 reg;
  253. u32 div;
  254. unsigned long parent_rate;
  255. parent_rate = clk_get_rate(clk->parent);
  256. if (clk->id < 0 || clk->id > 3)
  257. return -EINVAL;
  258. div = parent_rate / rate;
  259. if (div > 64 || div < 1 || ((parent_rate / div) != rate))
  260. return -EINVAL;
  261. div--;
  262. reg =
  263. __raw_readl(CCM_PCDR1) & ~(CCM_PCDR1_PERDIV1_MASK <<
  264. (clk->id << 3));
  265. reg |= div << (clk->id << 3);
  266. __raw_writel(reg, CCM_PCDR1);
  267. return 0;
  268. }
  269. static unsigned long _clk_usb_recalc(struct clk *clk)
  270. {
  271. unsigned long usb_pdf;
  272. unsigned long parent_rate;
  273. parent_rate = clk_get_rate(clk->parent);
  274. usb_pdf = (CSCR() & CCM_CSCR_USB_MASK) >> CCM_CSCR_USB_OFFSET;
  275. return parent_rate / (usb_pdf + 1U);
  276. }
  277. static unsigned long _clk_ssi1_recalc(struct clk *clk)
  278. {
  279. unsigned long ssi1_pdf;
  280. unsigned long parent_rate;
  281. parent_rate = clk_get_rate(clk->parent);
  282. ssi1_pdf = (PCDR0() & CCM_PCDR0_SSI1BAUDDIV_MASK) >>
  283. CCM_PCDR0_SSI1BAUDDIV_OFFSET;
  284. if (mx27_revision() >= CHIP_REV_2_0)
  285. ssi1_pdf += 4;
  286. else
  287. ssi1_pdf = (ssi1_pdf < 2) ? 124UL : ssi1_pdf;
  288. return 2UL * parent_rate / ssi1_pdf;
  289. }
  290. static unsigned long _clk_ssi2_recalc(struct clk *clk)
  291. {
  292. unsigned long ssi2_pdf;
  293. unsigned long parent_rate;
  294. parent_rate = clk_get_rate(clk->parent);
  295. ssi2_pdf = (PCDR0() & CCM_PCDR0_SSI2BAUDDIV_MASK) >>
  296. CCM_PCDR0_SSI2BAUDDIV_OFFSET;
  297. if (mx27_revision() >= CHIP_REV_2_0)
  298. ssi2_pdf += 4;
  299. else
  300. ssi2_pdf = (ssi2_pdf < 2) ? 124UL : ssi2_pdf;
  301. return 2UL * parent_rate / ssi2_pdf;
  302. }
  303. static unsigned long _clk_nfc_recalc(struct clk *clk)
  304. {
  305. unsigned long nfc_pdf;
  306. unsigned long parent_rate;
  307. parent_rate = clk_get_rate(clk->parent);
  308. if (mx27_revision() >= CHIP_REV_2_0) {
  309. nfc_pdf =
  310. (PCDR0() & CCM_PCDR0_NFCDIV2_MASK) >>
  311. CCM_PCDR0_NFCDIV2_OFFSET;
  312. } else {
  313. nfc_pdf =
  314. (PCDR0() & CCM_PCDR0_NFCDIV_MASK) >>
  315. CCM_PCDR0_NFCDIV_OFFSET;
  316. }
  317. return parent_rate / (nfc_pdf + 1);
  318. }
  319. static unsigned long _clk_vpu_recalc(struct clk *clk)
  320. {
  321. unsigned long vpu_pdf;
  322. unsigned long parent_rate;
  323. parent_rate = clk_get_rate(clk->parent);
  324. if (mx27_revision() >= CHIP_REV_2_0) {
  325. vpu_pdf =
  326. (PCDR0() & CCM_PCDR0_VPUDIV2_MASK) >>
  327. CCM_PCDR0_VPUDIV2_OFFSET;
  328. vpu_pdf += 4;
  329. } else {
  330. vpu_pdf =
  331. (PCDR0() & CCM_PCDR0_VPUDIV_MASK) >>
  332. CCM_PCDR0_VPUDIV_OFFSET;
  333. vpu_pdf = (vpu_pdf < 2) ? 124 : vpu_pdf;
  334. }
  335. return 2UL * parent_rate / vpu_pdf;
  336. }
  337. static unsigned long _clk_parent_round_rate(struct clk *clk, unsigned long rate)
  338. {
  339. return clk->parent->round_rate(clk->parent, rate);
  340. }
  341. static int _clk_parent_set_rate(struct clk *clk, unsigned long rate)
  342. {
  343. return clk->parent->set_rate(clk->parent, rate);
  344. }
  345. /* in Hz */
  346. static unsigned long external_high_reference = 26000000;
  347. static unsigned long get_high_reference_clock_rate(struct clk *clk)
  348. {
  349. return external_high_reference;
  350. }
  351. /*
  352. * the high frequency external clock reference
  353. * Default case is 26MHz. Could be changed at runtime
  354. * with a call to change_external_high_reference()
  355. */
  356. static struct clk ckih_clk = {
  357. .name = "ckih",
  358. .get_rate = get_high_reference_clock_rate,
  359. };
  360. /* in Hz */
  361. static unsigned long external_low_reference = 32768;
  362. static unsigned long get_low_reference_clock_rate(struct clk *clk)
  363. {
  364. return external_low_reference;
  365. }
  366. /*
  367. * the low frequency external clock reference
  368. * Default case is 32.768kHz Could be changed at runtime
  369. * with a call to change_external_low_reference()
  370. */
  371. static struct clk ckil_clk = {
  372. .name = "ckil",
  373. .get_rate = get_low_reference_clock_rate,
  374. };
  375. static unsigned long get_mpll_clk(struct clk *clk)
  376. {
  377. return mxc_decode_pll(__raw_readl(CCM_MPCTL0),
  378. clk_get_rate(clk->parent));
  379. }
  380. static struct clk mpll_clk = {
  381. .name = "mpll",
  382. .parent = &ckih_clk,
  383. .get_rate = get_mpll_clk,
  384. };
  385. static unsigned long _clk_mpll_main_get_rate(struct clk *clk)
  386. {
  387. unsigned long parent_rate;
  388. parent_rate = clk_get_rate(clk->parent);
  389. /* i.MX27 TO2:
  390. * clk->id == 0: arm clock source path 1 which is from 2*MPLL/DIV_2
  391. * clk->id == 1: arm clock source path 2 which is from 2*MPLL/DIV_3
  392. */
  393. if (mx27_revision() >= CHIP_REV_2_0 && clk->id == 1)
  394. return 2UL * parent_rate / 3UL;
  395. return parent_rate;
  396. }
  397. static struct clk mpll_main_clk[] = {
  398. {
  399. /* For i.MX27 TO2, it is the MPLL path 1 of ARM core
  400. * It provide the clock source whose rate is same as MPLL
  401. */
  402. .name = "mpll_main",
  403. .id = 0,
  404. .parent = &mpll_clk,
  405. .get_rate = _clk_mpll_main_get_rate
  406. }, {
  407. /* For i.MX27 TO2, it is the MPLL path 2 of ARM core
  408. * It provide the clock source whose rate is same MPLL * 2/3
  409. */
  410. .name = "mpll_main",
  411. .id = 1,
  412. .parent = &mpll_clk,
  413. .get_rate = _clk_mpll_main_get_rate
  414. }
  415. };
  416. static unsigned long get_spll_clk(struct clk *clk)
  417. {
  418. uint32_t reg;
  419. unsigned long ref_clk;
  420. ref_clk = clk_get_rate(clk->parent);
  421. reg = __raw_readl(CCM_SPCTL0);
  422. /* On TO2 we have to write the value back. Otherwise we
  423. * read 0 from this register the next time.
  424. */
  425. if (mx27_revision() >= CHIP_REV_2_0)
  426. __raw_writel(reg, CCM_SPCTL0);
  427. return mxc_decode_pll(reg, ref_clk);
  428. }
  429. static struct clk spll_clk = {
  430. .name = "spll",
  431. .parent = &ckih_clk,
  432. .get_rate = get_spll_clk,
  433. .enable = _clk_spll_enable,
  434. .disable = _clk_spll_disable,
  435. };
  436. static unsigned long get_cpu_clk(struct clk *clk)
  437. {
  438. u32 div;
  439. unsigned long rate;
  440. if (mx27_revision() >= CHIP_REV_2_0)
  441. div = (CSCR() & CCM_CSCR_ARM_MASK) >> CCM_CSCR_ARM_OFFSET;
  442. else
  443. div = (CSCR() & CCM_CSCR_PRESC_MASK) >> CCM_CSCR_PRESC_OFFSET;
  444. rate = clk_get_rate(clk->parent);
  445. return rate / (div + 1);
  446. }
  447. static struct clk cpu_clk = {
  448. .name = "cpu_clk",
  449. .parent = &mpll_main_clk[1],
  450. .set_parent = _clk_cpu_set_parent,
  451. .round_rate = _clk_cpu_round_rate,
  452. .get_rate = get_cpu_clk,
  453. .set_rate = _clk_cpu_set_rate,
  454. };
  455. static unsigned long get_ahb_clk(struct clk *clk)
  456. {
  457. unsigned long rate;
  458. unsigned long bclk_pdf;
  459. if (mx27_revision() >= CHIP_REV_2_0)
  460. bclk_pdf = (CSCR() & CCM_CSCR_AHB_MASK)
  461. >> CCM_CSCR_AHB_OFFSET;
  462. else
  463. bclk_pdf = (CSCR() & CCM_CSCR_BCLK_MASK)
  464. >> CCM_CSCR_BCLK_OFFSET;
  465. rate = clk_get_rate(clk->parent);
  466. return rate / (bclk_pdf + 1);
  467. }
  468. static struct clk ahb_clk = {
  469. .name = "ahb_clk",
  470. .parent = &mpll_main_clk[1],
  471. .get_rate = get_ahb_clk,
  472. };
  473. static unsigned long get_ipg_clk(struct clk *clk)
  474. {
  475. unsigned long rate;
  476. unsigned long ipg_pdf;
  477. if (mx27_revision() >= CHIP_REV_2_0)
  478. return clk_get_rate(clk->parent);
  479. else
  480. ipg_pdf = (CSCR() & CCM_CSCR_IPDIV) >> CCM_CSCR_IPDIV_OFFSET;
  481. rate = clk_get_rate(clk->parent);
  482. return rate / (ipg_pdf + 1);
  483. }
  484. static struct clk ipg_clk = {
  485. .name = "ipg_clk",
  486. .parent = &ahb_clk,
  487. .get_rate = get_ipg_clk,
  488. };
  489. static unsigned long _clk_perclkx_recalc(struct clk *clk)
  490. {
  491. unsigned long perclk_pdf;
  492. unsigned long parent_rate;
  493. parent_rate = clk_get_rate(clk->parent);
  494. if (clk->id < 0 || clk->id > 3)
  495. return 0;
  496. perclk_pdf = (PCDR1() >> (clk->id << 3)) & CCM_PCDR1_PERDIV1_MASK;
  497. return parent_rate / (perclk_pdf + 1);
  498. }
  499. static struct clk per_clk[] = {
  500. {
  501. .name = "per_clk",
  502. .id = 0,
  503. .parent = &mpll_main_clk[1],
  504. .get_rate = _clk_perclkx_recalc,
  505. .enable = _clk_enable,
  506. .enable_reg = CCM_PCCR1,
  507. .enable_shift = CCM_PCCR1_PERCLK1_OFFSET,
  508. .disable = _clk_disable,
  509. }, {
  510. .name = "per_clk",
  511. .id = 1,
  512. .parent = &mpll_main_clk[1],
  513. .get_rate = _clk_perclkx_recalc,
  514. .enable = _clk_enable,
  515. .enable_reg = CCM_PCCR1,
  516. .enable_shift = CCM_PCCR1_PERCLK2_OFFSET,
  517. .disable = _clk_disable,
  518. }, {
  519. .name = "per_clk",
  520. .id = 2,
  521. .parent = &mpll_main_clk[1],
  522. .round_rate = _clk_perclkx_round_rate,
  523. .set_rate = _clk_perclkx_set_rate,
  524. .get_rate = _clk_perclkx_recalc,
  525. .enable = _clk_enable,
  526. .enable_reg = CCM_PCCR1,
  527. .enable_shift = CCM_PCCR1_PERCLK3_OFFSET,
  528. .disable = _clk_disable,
  529. }, {
  530. .name = "per_clk",
  531. .id = 3,
  532. .parent = &mpll_main_clk[1],
  533. .round_rate = _clk_perclkx_round_rate,
  534. .set_rate = _clk_perclkx_set_rate,
  535. .get_rate = _clk_perclkx_recalc,
  536. .enable = _clk_enable,
  537. .enable_reg = CCM_PCCR1,
  538. .enable_shift = CCM_PCCR1_PERCLK4_OFFSET,
  539. .disable = _clk_disable,
  540. },
  541. };
  542. struct clk uart1_clk[] = {
  543. {
  544. .name = "uart",
  545. .id = 0,
  546. .parent = &per_clk[0],
  547. .secondary = &uart1_clk[1],
  548. }, {
  549. .name = "uart_ipg_clk",
  550. .id = 0,
  551. .parent = &ipg_clk,
  552. .enable = _clk_enable,
  553. .enable_reg = CCM_PCCR1,
  554. .enable_shift = CCM_PCCR1_UART1_OFFSET,
  555. .disable = _clk_disable,
  556. },
  557. };
  558. struct clk uart2_clk[] = {
  559. {
  560. .name = "uart",
  561. .id = 1,
  562. .parent = &per_clk[0],
  563. .secondary = &uart2_clk[1],
  564. }, {
  565. .name = "uart_ipg_clk",
  566. .id = 1,
  567. .parent = &ipg_clk,
  568. .enable = _clk_enable,
  569. .enable_reg = CCM_PCCR1,
  570. .enable_shift = CCM_PCCR1_UART2_OFFSET,
  571. .disable = _clk_disable,
  572. },
  573. };
  574. struct clk uart3_clk[] = {
  575. {
  576. .name = "uart",
  577. .id = 2,
  578. .parent = &per_clk[0],
  579. .secondary = &uart3_clk[1],
  580. }, {
  581. .name = "uart_ipg_clk",
  582. .id = 2,
  583. .parent = &ipg_clk,
  584. .enable = _clk_enable,
  585. .enable_reg = CCM_PCCR1,
  586. .enable_shift = CCM_PCCR1_UART3_OFFSET,
  587. .disable = _clk_disable,
  588. },
  589. };
  590. struct clk uart4_clk[] = {
  591. {
  592. .name = "uart",
  593. .id = 3,
  594. .parent = &per_clk[0],
  595. .secondary = &uart4_clk[1],
  596. }, {
  597. .name = "uart_ipg_clk",
  598. .id = 3,
  599. .parent = &ipg_clk,
  600. .enable = _clk_enable,
  601. .enable_reg = CCM_PCCR1,
  602. .enable_shift = CCM_PCCR1_UART4_OFFSET,
  603. .disable = _clk_disable,
  604. },
  605. };
  606. struct clk uart5_clk[] = {
  607. {
  608. .name = "uart",
  609. .id = 4,
  610. .parent = &per_clk[0],
  611. .secondary = &uart5_clk[1],
  612. }, {
  613. .name = "uart_ipg_clk",
  614. .id = 4,
  615. .parent = &ipg_clk,
  616. .enable = _clk_enable,
  617. .enable_reg = CCM_PCCR1,
  618. .enable_shift = CCM_PCCR1_UART5_OFFSET,
  619. .disable = _clk_disable,
  620. },
  621. };
  622. struct clk uart6_clk[] = {
  623. {
  624. .name = "uart",
  625. .id = 5,
  626. .parent = &per_clk[0],
  627. .secondary = &uart6_clk[1],
  628. }, {
  629. .name = "uart_ipg_clk",
  630. .id = 5,
  631. .parent = &ipg_clk,
  632. .enable = _clk_enable,
  633. .enable_reg = CCM_PCCR1,
  634. .enable_shift = CCM_PCCR1_UART6_OFFSET,
  635. .disable = _clk_disable,
  636. },
  637. };
  638. static struct clk gpt1_clk[] = {
  639. {
  640. .name = "gpt_clk",
  641. .id = 0,
  642. .parent = &per_clk[0],
  643. .secondary = &gpt1_clk[1],
  644. }, {
  645. .name = "gpt_ipg_clk",
  646. .id = 0,
  647. .parent = &ipg_clk,
  648. .enable = _clk_enable,
  649. .enable_reg = CCM_PCCR0,
  650. .enable_shift = CCM_PCCR0_GPT1_OFFSET,
  651. .disable = _clk_disable,
  652. },
  653. };
  654. static struct clk gpt2_clk[] = {
  655. {
  656. .name = "gpt_clk",
  657. .id = 1,
  658. .parent = &per_clk[0],
  659. .secondary = &gpt2_clk[1],
  660. }, {
  661. .name = "gpt_ipg_clk",
  662. .id = 1,
  663. .parent = &ipg_clk,
  664. .enable = _clk_enable,
  665. .enable_reg = CCM_PCCR0,
  666. .enable_shift = CCM_PCCR0_GPT2_OFFSET,
  667. .disable = _clk_disable,
  668. },
  669. };
  670. static struct clk gpt3_clk[] = {
  671. {
  672. .name = "gpt_clk",
  673. .id = 2,
  674. .parent = &per_clk[0],
  675. .secondary = &gpt3_clk[1],
  676. }, {
  677. .name = "gpt_ipg_clk",
  678. .id = 2,
  679. .parent = &ipg_clk,
  680. .enable = _clk_enable,
  681. .enable_reg = CCM_PCCR0,
  682. .enable_shift = CCM_PCCR0_GPT3_OFFSET,
  683. .disable = _clk_disable,
  684. },
  685. };
  686. static struct clk gpt4_clk[] = {
  687. {
  688. .name = "gpt_clk",
  689. .id = 3,
  690. .parent = &per_clk[0],
  691. .secondary = &gpt4_clk[1],
  692. }, {
  693. .name = "gpt_ipg_clk",
  694. .id = 3,
  695. .parent = &ipg_clk,
  696. .enable = _clk_enable,
  697. .enable_reg = CCM_PCCR0,
  698. .enable_shift = CCM_PCCR0_GPT4_OFFSET,
  699. .disable = _clk_disable,
  700. },
  701. };
  702. static struct clk gpt5_clk[] = {
  703. {
  704. .name = "gpt_clk",
  705. .id = 4,
  706. .parent = &per_clk[0],
  707. .secondary = &gpt5_clk[1],
  708. }, {
  709. .name = "gpt_ipg_clk",
  710. .id = 4,
  711. .parent = &ipg_clk,
  712. .enable = _clk_enable,
  713. .enable_reg = CCM_PCCR0,
  714. .enable_shift = CCM_PCCR0_GPT5_OFFSET,
  715. .disable = _clk_disable,
  716. },
  717. };
  718. static struct clk gpt6_clk[] = {
  719. {
  720. .name = "gpt_clk",
  721. .id = 5,
  722. .parent = &per_clk[0],
  723. .secondary = &gpt6_clk[1],
  724. }, {
  725. .name = "gpt_ipg_clk",
  726. .id = 5,
  727. .parent = &ipg_clk,
  728. .enable = _clk_enable,
  729. .enable_reg = CCM_PCCR0,
  730. .enable_shift = CCM_PCCR0_GPT6_OFFSET,
  731. .disable = _clk_disable,
  732. },
  733. };
  734. static struct clk pwm_clk[] = {
  735. {
  736. .name = "pwm_clk",
  737. .parent = &per_clk[0],
  738. .secondary = &pwm_clk[1],
  739. }, {
  740. .name = "pwm_clk",
  741. .parent = &ipg_clk,
  742. .enable = _clk_enable,
  743. .enable_reg = CCM_PCCR0,
  744. .enable_shift = CCM_PCCR0_PWM_OFFSET,
  745. .disable = _clk_disable,
  746. },
  747. };
  748. static struct clk sdhc1_clk[] = {
  749. {
  750. .name = "sdhc_clk",
  751. .id = 0,
  752. .parent = &per_clk[1],
  753. .secondary = &sdhc1_clk[1],
  754. }, {
  755. .name = "sdhc_ipg_clk",
  756. .id = 0,
  757. .parent = &ipg_clk,
  758. .enable = _clk_enable,
  759. .enable_reg = CCM_PCCR0,
  760. .enable_shift = CCM_PCCR0_SDHC1_OFFSET,
  761. .disable = _clk_disable,
  762. },
  763. };
  764. static struct clk sdhc2_clk[] = {
  765. {
  766. .name = "sdhc_clk",
  767. .id = 1,
  768. .parent = &per_clk[1],
  769. .secondary = &sdhc2_clk[1],
  770. }, {
  771. .name = "sdhc_ipg_clk",
  772. .id = 1,
  773. .parent = &ipg_clk,
  774. .enable = _clk_enable,
  775. .enable_reg = CCM_PCCR0,
  776. .enable_shift = CCM_PCCR0_SDHC2_OFFSET,
  777. .disable = _clk_disable,
  778. },
  779. };
  780. static struct clk sdhc3_clk[] = {
  781. {
  782. .name = "sdhc_clk",
  783. .id = 2,
  784. .parent = &per_clk[1],
  785. .secondary = &sdhc3_clk[1],
  786. }, {
  787. .name = "sdhc_ipg_clk",
  788. .id = 2,
  789. .parent = &ipg_clk,
  790. .enable = _clk_enable,
  791. .enable_reg = CCM_PCCR0,
  792. .enable_shift = CCM_PCCR0_SDHC3_OFFSET,
  793. .disable = _clk_disable,
  794. },
  795. };
  796. static struct clk cspi1_clk[] = {
  797. {
  798. .name = "cspi_clk",
  799. .id = 0,
  800. .parent = &per_clk[1],
  801. .secondary = &cspi1_clk[1],
  802. }, {
  803. .name = "cspi_ipg_clk",
  804. .id = 0,
  805. .parent = &ipg_clk,
  806. .enable = _clk_enable,
  807. .enable_reg = CCM_PCCR0,
  808. .enable_shift = CCM_PCCR0_CSPI1_OFFSET,
  809. .disable = _clk_disable,
  810. },
  811. };
  812. static struct clk cspi2_clk[] = {
  813. {
  814. .name = "cspi_clk",
  815. .id = 1,
  816. .parent = &per_clk[1],
  817. .secondary = &cspi2_clk[1],
  818. }, {
  819. .name = "cspi_ipg_clk",
  820. .id = 1,
  821. .parent = &ipg_clk,
  822. .enable = _clk_enable,
  823. .enable_reg = CCM_PCCR0,
  824. .enable_shift = CCM_PCCR0_CSPI2_OFFSET,
  825. .disable = _clk_disable,
  826. },
  827. };
  828. static struct clk cspi3_clk[] = {
  829. {
  830. .name = "cspi_clk",
  831. .id = 2,
  832. .parent = &per_clk[1],
  833. .secondary = &cspi3_clk[1],
  834. }, {
  835. .name = "cspi_ipg_clk",
  836. .id = 2,
  837. .parent = &ipg_clk,
  838. .enable = _clk_enable,
  839. .enable_reg = CCM_PCCR0,
  840. .enable_shift = CCM_PCCR0_CSPI3_OFFSET,
  841. .disable = _clk_disable,
  842. },
  843. };
  844. static struct clk lcdc_clk[] = {
  845. {
  846. .name = "lcdc_clk",
  847. .parent = &per_clk[2],
  848. .secondary = &lcdc_clk[1],
  849. .round_rate = _clk_parent_round_rate,
  850. .set_rate = _clk_parent_set_rate,
  851. }, {
  852. .name = "lcdc_ipg_clk",
  853. .parent = &ipg_clk,
  854. .secondary = &lcdc_clk[2],
  855. .enable = _clk_enable,
  856. .enable_reg = CCM_PCCR0,
  857. .enable_shift = CCM_PCCR0_LCDC_OFFSET,
  858. .disable = _clk_disable,
  859. }, {
  860. .name = "lcdc_ahb_clk",
  861. .parent = &ahb_clk,
  862. .enable = _clk_enable,
  863. .enable_reg = CCM_PCCR1,
  864. .enable_shift = CCM_PCCR1_HCLK_LCDC_OFFSET,
  865. .disable = _clk_disable,
  866. },
  867. };
  868. static struct clk csi_clk[] = {
  869. {
  870. .name = "csi_perclk",
  871. .parent = &per_clk[3],
  872. .secondary = &csi_clk[1],
  873. .round_rate = _clk_parent_round_rate,
  874. .set_rate = _clk_parent_set_rate,
  875. }, {
  876. .name = "csi_ahb_clk",
  877. .parent = &ahb_clk,
  878. .enable = _clk_enable,
  879. .enable_reg = CCM_PCCR1,
  880. .enable_shift = CCM_PCCR1_HCLK_CSI_OFFSET,
  881. .disable = _clk_disable,
  882. },
  883. };
  884. static struct clk usb_clk[] = {
  885. {
  886. .name = "usb_clk",
  887. .parent = &spll_clk,
  888. .get_rate = _clk_usb_recalc,
  889. .enable = _clk_enable,
  890. .enable_reg = CCM_PCCR1,
  891. .enable_shift = CCM_PCCR1_USBOTG_OFFSET,
  892. .disable = _clk_disable,
  893. }, {
  894. .name = "usb_ahb_clk",
  895. .parent = &ahb_clk,
  896. .enable = _clk_enable,
  897. .enable_reg = CCM_PCCR1,
  898. .enable_shift = CCM_PCCR1_HCLK_USBOTG_OFFSET,
  899. .disable = _clk_disable,
  900. }
  901. };
  902. static struct clk ssi1_clk[] = {
  903. {
  904. .name = "ssi_clk",
  905. .id = 0,
  906. .parent = &mpll_main_clk[1],
  907. .secondary = &ssi1_clk[1],
  908. .get_rate = _clk_ssi1_recalc,
  909. .enable = _clk_enable,
  910. .enable_reg = CCM_PCCR1,
  911. .enable_shift = CCM_PCCR1_SSI1_BAUD_OFFSET,
  912. .disable = _clk_disable,
  913. }, {
  914. .name = "ssi_ipg_clk",
  915. .id = 0,
  916. .parent = &ipg_clk,
  917. .enable = _clk_enable,
  918. .enable_reg = CCM_PCCR0,
  919. .enable_shift = CCM_PCCR0_SSI1_IPG_OFFSET,
  920. .disable = _clk_disable,
  921. },
  922. };
  923. static struct clk ssi2_clk[] = {
  924. {
  925. .name = "ssi_clk",
  926. .id = 1,
  927. .parent = &mpll_main_clk[1],
  928. .secondary = &ssi2_clk[1],
  929. .get_rate = _clk_ssi2_recalc,
  930. .enable = _clk_enable,
  931. .enable_reg = CCM_PCCR1,
  932. .enable_shift = CCM_PCCR1_SSI2_BAUD_OFFSET,
  933. .disable = _clk_disable,
  934. }, {
  935. .name = "ssi_ipg_clk",
  936. .id = 1,
  937. .parent = &ipg_clk,
  938. .enable = _clk_enable,
  939. .enable_reg = CCM_PCCR0,
  940. .enable_shift = CCM_PCCR0_SSI2_IPG_OFFSET,
  941. .disable = _clk_disable,
  942. },
  943. };
  944. static struct clk nfc_clk = {
  945. .name = "nfc",
  946. .parent = &cpu_clk,
  947. .get_rate = _clk_nfc_recalc,
  948. .enable = _clk_enable,
  949. .enable_reg = CCM_PCCR1,
  950. .enable_shift = CCM_PCCR1_NFC_BAUD_OFFSET,
  951. .disable = _clk_disable,
  952. };
  953. static struct clk vpu_clk = {
  954. .name = "vpu_clk",
  955. .parent = &mpll_main_clk[1],
  956. .get_rate = _clk_vpu_recalc,
  957. .enable = _clk_vpu_enable,
  958. .disable = _clk_vpu_disable,
  959. };
  960. static struct clk dma_clk = {
  961. .name = "dma",
  962. .parent = &ahb_clk,
  963. .enable = _clk_dma_enable,
  964. .disable = _clk_dma_disable,
  965. };
  966. static struct clk rtic_clk = {
  967. .name = "rtic_clk",
  968. .parent = &ahb_clk,
  969. .enable = _clk_rtic_enable,
  970. .disable = _clk_rtic_disable,
  971. };
  972. static struct clk brom_clk = {
  973. .name = "brom_clk",
  974. .parent = &ahb_clk,
  975. .enable = _clk_enable,
  976. .enable_reg = CCM_PCCR1,
  977. .enable_shift = CCM_PCCR1_HCLK_BROM_OFFSET,
  978. .disable = _clk_disable,
  979. };
  980. static struct clk emma_clk = {
  981. .name = "emma_clk",
  982. .parent = &ahb_clk,
  983. .enable = _clk_emma_enable,
  984. .disable = _clk_emma_disable,
  985. };
  986. static struct clk slcdc_clk = {
  987. .name = "slcdc_clk",
  988. .parent = &ahb_clk,
  989. .enable = _clk_slcdc_enable,
  990. .disable = _clk_slcdc_disable,
  991. };
  992. static struct clk fec_clk = {
  993. .name = "fec_clk",
  994. .parent = &ahb_clk,
  995. .enable = _clk_fec_enable,
  996. .disable = _clk_fec_disable,
  997. };
  998. static struct clk emi_clk = {
  999. .name = "emi_clk",
  1000. .parent = &ahb_clk,
  1001. .enable = _clk_enable,
  1002. .enable_reg = CCM_PCCR1,
  1003. .enable_shift = CCM_PCCR1_HCLK_EMI_OFFSET,
  1004. .disable = _clk_disable,
  1005. };
  1006. static struct clk sahara2_clk = {
  1007. .name = "sahara_clk",
  1008. .parent = &ahb_clk,
  1009. .enable = _clk_sahara2_enable,
  1010. .disable = _clk_sahara2_disable,
  1011. };
  1012. static struct clk ata_clk = {
  1013. .name = "ata_clk",
  1014. .parent = &ahb_clk,
  1015. .enable = _clk_enable,
  1016. .enable_reg = CCM_PCCR1,
  1017. .enable_shift = CCM_PCCR1_HCLK_ATA_OFFSET,
  1018. .disable = _clk_disable,
  1019. };
  1020. static struct clk mstick1_clk = {
  1021. .name = "mstick1_clk",
  1022. .parent = &ipg_clk,
  1023. .enable = _clk_mstick1_enable,
  1024. .disable = _clk_mstick1_disable,
  1025. };
  1026. static struct clk wdog_clk = {
  1027. .name = "wdog_clk",
  1028. .parent = &ipg_clk,
  1029. .enable = _clk_enable,
  1030. .enable_reg = CCM_PCCR1,
  1031. .enable_shift = CCM_PCCR1_WDT_OFFSET,
  1032. .disable = _clk_disable,
  1033. };
  1034. static struct clk gpio_clk = {
  1035. .name = "gpio_clk",
  1036. .parent = &ipg_clk,
  1037. .enable = _clk_enable,
  1038. .enable_reg = CCM_PCCR1,
  1039. .enable_shift = CCM_PCCR0_GPIO_OFFSET,
  1040. .disable = _clk_disable,
  1041. };
  1042. static struct clk i2c_clk[] = {
  1043. {
  1044. .name = "i2c_clk",
  1045. .id = 0,
  1046. .parent = &ipg_clk,
  1047. .enable = _clk_enable,
  1048. .enable_reg = CCM_PCCR0,
  1049. .enable_shift = CCM_PCCR0_I2C1_OFFSET,
  1050. .disable = _clk_disable,
  1051. }, {
  1052. .name = "i2c_clk",
  1053. .id = 1,
  1054. .parent = &ipg_clk,
  1055. .enable = _clk_enable,
  1056. .enable_reg = CCM_PCCR0,
  1057. .enable_shift = CCM_PCCR0_I2C2_OFFSET,
  1058. .disable = _clk_disable,
  1059. },
  1060. };
  1061. static struct clk iim_clk = {
  1062. .name = "iim_clk",
  1063. .parent = &ipg_clk,
  1064. .enable = _clk_enable,
  1065. .enable_reg = CCM_PCCR0,
  1066. .enable_shift = CCM_PCCR0_IIM_OFFSET,
  1067. .disable = _clk_disable,
  1068. };
  1069. static struct clk kpp_clk = {
  1070. .name = "kpp_clk",
  1071. .parent = &ipg_clk,
  1072. .enable = _clk_enable,
  1073. .enable_reg = CCM_PCCR0,
  1074. .enable_shift = CCM_PCCR0_KPP_OFFSET,
  1075. .disable = _clk_disable,
  1076. };
  1077. static struct clk owire_clk = {
  1078. .name = "owire",
  1079. .parent = &ipg_clk,
  1080. .enable = _clk_enable,
  1081. .enable_reg = CCM_PCCR0,
  1082. .enable_shift = CCM_PCCR0_OWIRE_OFFSET,
  1083. .disable = _clk_disable,
  1084. };
  1085. static struct clk rtc_clk = {
  1086. .name = "rtc_clk",
  1087. .parent = &ipg_clk,
  1088. .enable = _clk_enable,
  1089. .enable_reg = CCM_PCCR0,
  1090. .enable_shift = CCM_PCCR0_RTC_OFFSET,
  1091. .disable = _clk_disable,
  1092. };
  1093. static struct clk scc_clk = {
  1094. .name = "scc_clk",
  1095. .parent = &ipg_clk,
  1096. .enable = _clk_enable,
  1097. .enable_reg = CCM_PCCR0,
  1098. .enable_shift = CCM_PCCR0_SCC_OFFSET,
  1099. .disable = _clk_disable,
  1100. };
  1101. static unsigned long _clk_clko_round_rate(struct clk *clk, unsigned long rate)
  1102. {
  1103. u32 div;
  1104. unsigned long parent_rate;
  1105. parent_rate = clk_get_rate(clk->parent);
  1106. div = parent_rate / rate;
  1107. if (parent_rate % rate)
  1108. div++;
  1109. if (div > 8)
  1110. div = 8;
  1111. return parent_rate / div;
  1112. }
  1113. static int _clk_clko_set_rate(struct clk *clk, unsigned long rate)
  1114. {
  1115. u32 reg;
  1116. u32 div;
  1117. unsigned long parent_rate;
  1118. parent_rate = clk_get_rate(clk->parent);
  1119. div = parent_rate / rate;
  1120. if (div > 8 || div < 1 || ((parent_rate / div) != rate))
  1121. return -EINVAL;
  1122. div--;
  1123. reg = __raw_readl(CCM_PCDR0) & ~CCM_PCDR0_CLKODIV_MASK;
  1124. reg |= div << CCM_PCDR0_CLKODIV_OFFSET;
  1125. __raw_writel(reg, CCM_PCDR0);
  1126. return 0;
  1127. }
  1128. static unsigned long _clk_clko_recalc(struct clk *clk)
  1129. {
  1130. u32 div;
  1131. unsigned long parent_rate;
  1132. parent_rate = clk_get_rate(clk->parent);
  1133. div = __raw_readl(CCM_PCDR0) & CCM_PCDR0_CLKODIV_MASK >>
  1134. CCM_PCDR0_CLKODIV_OFFSET;
  1135. div++;
  1136. return parent_rate / div;
  1137. }
  1138. static int _clk_clko_set_parent(struct clk *clk, struct clk *parent)
  1139. {
  1140. u32 reg;
  1141. reg = __raw_readl(CCM_CCSR) & ~CCM_CCSR_CLKOSEL_MASK;
  1142. if (parent == &ckil_clk)
  1143. reg |= 0 << CCM_CCSR_CLKOSEL_OFFSET;
  1144. else if (parent == &ckih_clk)
  1145. reg |= 2 << CCM_CCSR_CLKOSEL_OFFSET;
  1146. else if (parent == mpll_clk.parent)
  1147. reg |= 3 << CCM_CCSR_CLKOSEL_OFFSET;
  1148. else if (parent == spll_clk.parent)
  1149. reg |= 4 << CCM_CCSR_CLKOSEL_OFFSET;
  1150. else if (parent == &mpll_clk)
  1151. reg |= 5 << CCM_CCSR_CLKOSEL_OFFSET;
  1152. else if (parent == &spll_clk)
  1153. reg |= 6 << CCM_CCSR_CLKOSEL_OFFSET;
  1154. else if (parent == &cpu_clk)
  1155. reg |= 7 << CCM_CCSR_CLKOSEL_OFFSET;
  1156. else if (parent == &ahb_clk)
  1157. reg |= 8 << CCM_CCSR_CLKOSEL_OFFSET;
  1158. else if (parent == &ipg_clk)
  1159. reg |= 9 << CCM_CCSR_CLKOSEL_OFFSET;
  1160. else if (parent == &per_clk[0])
  1161. reg |= 0xA << CCM_CCSR_CLKOSEL_OFFSET;
  1162. else if (parent == &per_clk[1])
  1163. reg |= 0xB << CCM_CCSR_CLKOSEL_OFFSET;
  1164. else if (parent == &per_clk[2])
  1165. reg |= 0xC << CCM_CCSR_CLKOSEL_OFFSET;
  1166. else if (parent == &per_clk[3])
  1167. reg |= 0xD << CCM_CCSR_CLKOSEL_OFFSET;
  1168. else if (parent == &ssi1_clk[0])
  1169. reg |= 0xE << CCM_CCSR_CLKOSEL_OFFSET;
  1170. else if (parent == &ssi2_clk[0])
  1171. reg |= 0xF << CCM_CCSR_CLKOSEL_OFFSET;
  1172. else if (parent == &nfc_clk)
  1173. reg |= 0x10 << CCM_CCSR_CLKOSEL_OFFSET;
  1174. else if (parent == &mstick1_clk)
  1175. reg |= 0x11 << CCM_CCSR_CLKOSEL_OFFSET;
  1176. else if (parent == &vpu_clk)
  1177. reg |= 0x12 << CCM_CCSR_CLKOSEL_OFFSET;
  1178. else if (parent == &usb_clk[0])
  1179. reg |= 0x15 << CCM_CCSR_CLKOSEL_OFFSET;
  1180. else
  1181. return -EINVAL;
  1182. __raw_writel(reg, CCM_CCSR);
  1183. return 0;
  1184. }
  1185. static int _clk_clko_enable(struct clk *clk)
  1186. {
  1187. u32 reg;
  1188. reg = __raw_readl(CCM_PCDR0) | CCM_PCDR0_CLKO_EN;
  1189. __raw_writel(reg, CCM_PCDR0);
  1190. return 0;
  1191. }
  1192. static void _clk_clko_disable(struct clk *clk)
  1193. {
  1194. u32 reg;
  1195. reg = __raw_readl(CCM_PCDR0) & ~CCM_PCDR0_CLKO_EN;
  1196. __raw_writel(reg, CCM_PCDR0);
  1197. }
  1198. static struct clk clko_clk = {
  1199. .name = "clko_clk",
  1200. .get_rate = _clk_clko_recalc,
  1201. .set_rate = _clk_clko_set_rate,
  1202. .round_rate = _clk_clko_round_rate,
  1203. .set_parent = _clk_clko_set_parent,
  1204. .enable = _clk_clko_enable,
  1205. .disable = _clk_clko_disable,
  1206. };
  1207. static struct clk *mxc_clks[] = {
  1208. &ckih_clk,
  1209. &ckil_clk,
  1210. &mpll_clk,
  1211. &mpll_main_clk[0],
  1212. &mpll_main_clk[1],
  1213. &spll_clk,
  1214. &cpu_clk,
  1215. &ahb_clk,
  1216. &ipg_clk,
  1217. &per_clk[0],
  1218. &per_clk[1],
  1219. &per_clk[2],
  1220. &per_clk[3],
  1221. &clko_clk,
  1222. &uart1_clk[0],
  1223. &uart1_clk[1],
  1224. &uart2_clk[0],
  1225. &uart2_clk[1],
  1226. &uart3_clk[0],
  1227. &uart3_clk[1],
  1228. &uart4_clk[0],
  1229. &uart4_clk[1],
  1230. &uart5_clk[0],
  1231. &uart5_clk[1],
  1232. &uart6_clk[0],
  1233. &uart6_clk[1],
  1234. &gpt1_clk[0],
  1235. &gpt1_clk[1],
  1236. &gpt2_clk[0],
  1237. &gpt2_clk[1],
  1238. &gpt3_clk[0],
  1239. &gpt3_clk[1],
  1240. &gpt4_clk[0],
  1241. &gpt4_clk[1],
  1242. &gpt5_clk[0],
  1243. &gpt5_clk[1],
  1244. &gpt6_clk[0],
  1245. &gpt6_clk[1],
  1246. &pwm_clk[0],
  1247. &pwm_clk[1],
  1248. &sdhc1_clk[0],
  1249. &sdhc1_clk[1],
  1250. &sdhc2_clk[0],
  1251. &sdhc2_clk[1],
  1252. &sdhc3_clk[0],
  1253. &sdhc3_clk[1],
  1254. &cspi1_clk[0],
  1255. &cspi1_clk[1],
  1256. &cspi2_clk[0],
  1257. &cspi2_clk[1],
  1258. &cspi3_clk[0],
  1259. &cspi3_clk[1],
  1260. &lcdc_clk[0],
  1261. &lcdc_clk[1],
  1262. &lcdc_clk[2],
  1263. &csi_clk[0],
  1264. &csi_clk[1],
  1265. &usb_clk[0],
  1266. &usb_clk[1],
  1267. &ssi1_clk[0],
  1268. &ssi1_clk[1],
  1269. &ssi2_clk[0],
  1270. &ssi2_clk[1],
  1271. &nfc_clk,
  1272. &vpu_clk,
  1273. &dma_clk,
  1274. &rtic_clk,
  1275. &brom_clk,
  1276. &emma_clk,
  1277. &slcdc_clk,
  1278. &fec_clk,
  1279. &emi_clk,
  1280. &sahara2_clk,
  1281. &ata_clk,
  1282. &mstick1_clk,
  1283. &wdog_clk,
  1284. &gpio_clk,
  1285. &i2c_clk[0],
  1286. &i2c_clk[1],
  1287. &iim_clk,
  1288. &kpp_clk,
  1289. &owire_clk,
  1290. &rtc_clk,
  1291. &scc_clk,
  1292. };
  1293. void __init change_external_low_reference(unsigned long new_ref)
  1294. {
  1295. external_low_reference = new_ref;
  1296. }
  1297. unsigned long __init clk_early_get_timer_rate(void)
  1298. {
  1299. return clk_get_rate(&per_clk[0]);
  1300. }
  1301. static void __init probe_mxc_clocks(void)
  1302. {
  1303. int i;
  1304. if (mx27_revision() >= CHIP_REV_2_0) {
  1305. if (CSCR() & 0x8000)
  1306. cpu_clk.parent = &mpll_main_clk[0];
  1307. if (!(CSCR() & 0x00800000))
  1308. ssi2_clk[0].parent = &spll_clk;
  1309. if (!(CSCR() & 0x00400000))
  1310. ssi1_clk[0].parent = &spll_clk;
  1311. if (!(CSCR() & 0x00200000))
  1312. vpu_clk.parent = &spll_clk;
  1313. } else {
  1314. cpu_clk.parent = &mpll_clk;
  1315. cpu_clk.set_parent = NULL;
  1316. cpu_clk.round_rate = NULL;
  1317. cpu_clk.set_rate = NULL;
  1318. ahb_clk.parent = &mpll_clk;
  1319. for (i = 0; i < sizeof(per_clk) / sizeof(per_clk[0]); i++)
  1320. per_clk[i].parent = &mpll_clk;
  1321. ssi1_clk[0].parent = &mpll_clk;
  1322. ssi2_clk[0].parent = &mpll_clk;
  1323. vpu_clk.parent = &mpll_clk;
  1324. }
  1325. }
  1326. /*
  1327. * must be called very early to get information about the
  1328. * available clock rate when the timer framework starts
  1329. */
  1330. int __init mx27_clocks_init(unsigned long fref)
  1331. {
  1332. u32 cscr;
  1333. struct clk **clkp;
  1334. external_high_reference = fref;
  1335. /* detect clock reference for both system PLL */
  1336. cscr = CSCR();
  1337. if (cscr & CCM_CSCR_MCU)
  1338. mpll_clk.parent = &ckih_clk;
  1339. else
  1340. mpll_clk.parent = &ckil_clk;
  1341. if (cscr & CCM_CSCR_SP)
  1342. spll_clk.parent = &ckih_clk;
  1343. else
  1344. spll_clk.parent = &ckil_clk;
  1345. probe_mxc_clocks();
  1346. per_clk[0].enable(&per_clk[0]);
  1347. gpt1_clk[1].enable(&gpt1_clk[1]);
  1348. for (clkp = mxc_clks; clkp < mxc_clks + ARRAY_SIZE(mxc_clks); clkp++)
  1349. clk_register(*clkp);
  1350. /* Turn off all possible clocks */
  1351. __raw_writel(CCM_PCCR0_GPT1_MASK, CCM_PCCR0);
  1352. __raw_writel(CCM_PCCR1_PERCLK1_MASK | CCM_PCCR1_HCLK_EMI_MASK,
  1353. CCM_PCCR1);
  1354. spll_clk.disable(&spll_clk);
  1355. /* This will propagate to all children and init all the clock rates */
  1356. clk_enable(&emi_clk);
  1357. clk_enable(&gpio_clk);
  1358. clk_enable(&iim_clk);
  1359. clk_enable(&gpt1_clk[0]);
  1360. #ifdef CONFIG_DEBUG_LL_CONSOLE
  1361. clk_enable(&uart1_clk[0]);
  1362. #endif
  1363. mxc_timer_init(&gpt1_clk[0]);
  1364. return 0;
  1365. }