clock.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. /*
  2. * arch/arm/mach-lpc32xx/clock.c
  3. *
  4. * Author: Kevin Wells <kevin.wells@nxp.com>
  5. *
  6. * Copyright (C) 2010 NXP Semiconductors
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. /*
  19. * LPC32xx clock management driver overview
  20. *
  21. * The LPC32XX contains a number of high level system clocks that can be
  22. * generated from different sources. These system clocks are used to
  23. * generate the CPU and bus rates and the individual peripheral clocks in
  24. * the system. When Linux is started by the boot loader, the system
  25. * clocks are already running. Stopping a system clock during normal
  26. * Linux operation should never be attempted, as peripherals that require
  27. * those clocks will quit working (ie, DRAM).
  28. *
  29. * The LPC32xx high level clock tree looks as follows. Clocks marked with
  30. * an asterisk are always on and cannot be disabled. Clocks marked with
  31. * an ampersand can only be disabled in CPU suspend mode. Clocks marked
  32. * with a caret are always on if it is the selected clock for the SYSCLK
  33. * source. The clock that isn't used for SYSCLK can be enabled and
  34. * disabled normally.
  35. * 32KHz oscillator*
  36. * / | \
  37. * RTC* PLL397^ TOUCH
  38. * /
  39. * Main oscillator^ /
  40. * | \ /
  41. * | SYSCLK&
  42. * | \
  43. * | \
  44. * USB_PLL HCLK_PLL&
  45. * | | |
  46. * USB host/device PCLK& |
  47. * | |
  48. * Peripherals
  49. *
  50. * The CPU and chip bus rates are derived from the HCLK PLL, which can
  51. * generate various clock rates up to 266MHz and beyond. The internal bus
  52. * rates (PCLK and HCLK) are generated from dividers based on the HCLK
  53. * PLL rate. HCLK can be a ratio of 1:1, 1:2, or 1:4 or HCLK PLL rate,
  54. * while PCLK can be 1:1 to 1:32 of HCLK PLL rate. Most peripherals high
  55. * level clocks are based on either HCLK or PCLK, but have their own
  56. * dividers as part of the IP itself. Because of this, the system clock
  57. * rates should not be changed.
  58. *
  59. * The HCLK PLL is clocked from SYSCLK, which can be derived from the
  60. * main oscillator or PLL397. PLL397 generates a rate that is 397 times
  61. * the 32KHz oscillator rate. The main oscillator runs at the selected
  62. * oscillator/crystal rate on the mosc_in pin of the LPC32xx. This rate
  63. * is normally 13MHz, but depends on the selection of external crystals
  64. * or oscillators. If USB operation is required, the main oscillator must
  65. * be used in the system.
  66. *
  67. * Switching SYSCLK between sources during normal Linux operation is not
  68. * supported. SYSCLK is preset in the bootloader. Because of the
  69. * complexities of clock management during clock frequency changes,
  70. * there are some limitations to the clock driver explained below:
  71. * - The PLL397 and main oscillator can be enabled and disabled by the
  72. * clk_enable() and clk_disable() functions unless SYSCLK is based
  73. * on that clock. This allows the other oscillator that isn't driving
  74. * the HCLK PLL to be used as another system clock that can be routed
  75. * to an external pin.
  76. * - The muxed SYSCLK input and HCLK_PLL rate cannot be changed with
  77. * this driver.
  78. * - HCLK and PCLK rates cannot be changed as part of this driver.
  79. * - Most peripherals have their own dividers are part of the peripheral
  80. * block. Changing SYSCLK, HCLK PLL, HCLK, or PCLK sources or rates
  81. * will also impact the individual peripheral rates.
  82. */
  83. #include <linux/export.h>
  84. #include <linux/kernel.h>
  85. #include <linux/list.h>
  86. #include <linux/errno.h>
  87. #include <linux/device.h>
  88. #include <linux/delay.h>
  89. #include <linux/err.h>
  90. #include <linux/clk.h>
  91. #include <linux/amba/bus.h>
  92. #include <linux/amba/clcd.h>
  93. #include <linux/clkdev.h>
  94. #include <mach/hardware.h>
  95. #include <mach/platform.h>
  96. #include "clock.h"
  97. #include "common.h"
  98. static DEFINE_SPINLOCK(global_clkregs_lock);
  99. static int usb_pll_enable, usb_pll_valid;
  100. static struct clk clk_armpll;
  101. static struct clk clk_usbpll;
  102. /*
  103. * Post divider values for PLLs based on selected register value
  104. */
  105. static const u32 pll_postdivs[4] = {1, 2, 4, 8};
  106. static unsigned long local_return_parent_rate(struct clk *clk)
  107. {
  108. /*
  109. * If a clock has a rate of 0, then it inherits it's parent
  110. * clock rate
  111. */
  112. while (clk->rate == 0)
  113. clk = clk->parent;
  114. return clk->rate;
  115. }
  116. /* 32KHz clock has a fixed rate and is not stoppable */
  117. static struct clk osc_32KHz = {
  118. .rate = LPC32XX_CLOCK_OSC_FREQ,
  119. .get_rate = local_return_parent_rate,
  120. };
  121. static int local_pll397_enable(struct clk *clk, int enable)
  122. {
  123. u32 reg;
  124. unsigned long timeout = jiffies + msecs_to_jiffies(10);
  125. reg = __raw_readl(LPC32XX_CLKPWR_PLL397_CTRL);
  126. if (enable == 0) {
  127. reg |= LPC32XX_CLKPWR_SYSCTRL_PLL397_DIS;
  128. __raw_writel(reg, LPC32XX_CLKPWR_PLL397_CTRL);
  129. } else {
  130. /* Enable PLL397 */
  131. reg &= ~LPC32XX_CLKPWR_SYSCTRL_PLL397_DIS;
  132. __raw_writel(reg, LPC32XX_CLKPWR_PLL397_CTRL);
  133. /* Wait for PLL397 lock */
  134. while (((__raw_readl(LPC32XX_CLKPWR_PLL397_CTRL) &
  135. LPC32XX_CLKPWR_SYSCTRL_PLL397_STS) == 0) &&
  136. time_before(jiffies, timeout))
  137. cpu_relax();
  138. if ((__raw_readl(LPC32XX_CLKPWR_PLL397_CTRL) &
  139. LPC32XX_CLKPWR_SYSCTRL_PLL397_STS) == 0)
  140. return -ENODEV;
  141. }
  142. return 0;
  143. }
  144. static int local_oscmain_enable(struct clk *clk, int enable)
  145. {
  146. u32 reg;
  147. unsigned long timeout = jiffies + msecs_to_jiffies(10);
  148. reg = __raw_readl(LPC32XX_CLKPWR_MAIN_OSC_CTRL);
  149. if (enable == 0) {
  150. reg |= LPC32XX_CLKPWR_MOSC_DISABLE;
  151. __raw_writel(reg, LPC32XX_CLKPWR_MAIN_OSC_CTRL);
  152. } else {
  153. /* Enable main oscillator */
  154. reg &= ~LPC32XX_CLKPWR_MOSC_DISABLE;
  155. __raw_writel(reg, LPC32XX_CLKPWR_MAIN_OSC_CTRL);
  156. /* Wait for main oscillator to start */
  157. while (((__raw_readl(LPC32XX_CLKPWR_MAIN_OSC_CTRL) &
  158. LPC32XX_CLKPWR_MOSC_DISABLE) != 0) &&
  159. time_before(jiffies, timeout))
  160. cpu_relax();
  161. if ((__raw_readl(LPC32XX_CLKPWR_MAIN_OSC_CTRL) &
  162. LPC32XX_CLKPWR_MOSC_DISABLE) != 0)
  163. return -ENODEV;
  164. }
  165. return 0;
  166. }
  167. static struct clk osc_pll397 = {
  168. .parent = &osc_32KHz,
  169. .enable = local_pll397_enable,
  170. .rate = LPC32XX_CLOCK_OSC_FREQ * 397,
  171. .get_rate = local_return_parent_rate,
  172. };
  173. static struct clk osc_main = {
  174. .enable = local_oscmain_enable,
  175. .rate = LPC32XX_MAIN_OSC_FREQ,
  176. .get_rate = local_return_parent_rate,
  177. };
  178. static struct clk clk_sys;
  179. /*
  180. * Convert a PLL register value to a PLL output frequency
  181. */
  182. u32 clk_get_pllrate_from_reg(u32 inputclk, u32 regval)
  183. {
  184. struct clk_pll_setup pllcfg;
  185. pllcfg.cco_bypass_b15 = 0;
  186. pllcfg.direct_output_b14 = 0;
  187. pllcfg.fdbk_div_ctrl_b13 = 0;
  188. if ((regval & LPC32XX_CLKPWR_HCLKPLL_CCO_BYPASS) != 0)
  189. pllcfg.cco_bypass_b15 = 1;
  190. if ((regval & LPC32XX_CLKPWR_HCLKPLL_POSTDIV_BYPASS) != 0)
  191. pllcfg.direct_output_b14 = 1;
  192. if ((regval & LPC32XX_CLKPWR_HCLKPLL_FDBK_SEL_FCLK) != 0)
  193. pllcfg.fdbk_div_ctrl_b13 = 1;
  194. pllcfg.pll_m = 1 + ((regval >> 1) & 0xFF);
  195. pllcfg.pll_n = 1 + ((regval >> 9) & 0x3);
  196. pllcfg.pll_p = pll_postdivs[((regval >> 11) & 0x3)];
  197. return clk_check_pll_setup(inputclk, &pllcfg);
  198. }
  199. /*
  200. * Setup the HCLK PLL with a PLL structure
  201. */
  202. static u32 local_clk_pll_setup(struct clk_pll_setup *PllSetup)
  203. {
  204. u32 tv, tmp = 0;
  205. if (PllSetup->analog_on != 0)
  206. tmp |= LPC32XX_CLKPWR_HCLKPLL_POWER_UP;
  207. if (PllSetup->cco_bypass_b15 != 0)
  208. tmp |= LPC32XX_CLKPWR_HCLKPLL_CCO_BYPASS;
  209. if (PllSetup->direct_output_b14 != 0)
  210. tmp |= LPC32XX_CLKPWR_HCLKPLL_POSTDIV_BYPASS;
  211. if (PllSetup->fdbk_div_ctrl_b13 != 0)
  212. tmp |= LPC32XX_CLKPWR_HCLKPLL_FDBK_SEL_FCLK;
  213. tv = ffs(PllSetup->pll_p) - 1;
  214. if ((!is_power_of_2(PllSetup->pll_p)) || (tv > 3))
  215. return 0;
  216. tmp |= LPC32XX_CLKPWR_HCLKPLL_POSTDIV_2POW(tv);
  217. tmp |= LPC32XX_CLKPWR_HCLKPLL_PREDIV_PLUS1(PllSetup->pll_n - 1);
  218. tmp |= LPC32XX_CLKPWR_HCLKPLL_PLLM(PllSetup->pll_m - 1);
  219. return tmp;
  220. }
  221. /*
  222. * Update the ARM core PLL frequency rate variable from the actual PLL setting
  223. */
  224. static void local_update_armpll_rate(void)
  225. {
  226. u32 clkin, pllreg;
  227. clkin = clk_armpll.parent->rate;
  228. pllreg = __raw_readl(LPC32XX_CLKPWR_HCLKPLL_CTRL) & 0x1FFFF;
  229. clk_armpll.rate = clk_get_pllrate_from_reg(clkin, pllreg);
  230. }
  231. /*
  232. * Find a PLL configuration for the selected input frequency
  233. */
  234. static u32 local_clk_find_pll_cfg(u32 pllin_freq, u32 target_freq,
  235. struct clk_pll_setup *pllsetup)
  236. {
  237. u32 ifreq, freqtol, m, n, p, fclkout;
  238. /* Determine frequency tolerance limits */
  239. freqtol = target_freq / 250;
  240. ifreq = pllin_freq;
  241. /* Is direct bypass mode possible? */
  242. if (abs(pllin_freq - target_freq) <= freqtol) {
  243. pllsetup->analog_on = 0;
  244. pllsetup->cco_bypass_b15 = 1;
  245. pllsetup->direct_output_b14 = 1;
  246. pllsetup->fdbk_div_ctrl_b13 = 1;
  247. pllsetup->pll_p = pll_postdivs[0];
  248. pllsetup->pll_n = 1;
  249. pllsetup->pll_m = 1;
  250. return clk_check_pll_setup(ifreq, pllsetup);
  251. } else if (target_freq <= ifreq) {
  252. pllsetup->analog_on = 0;
  253. pllsetup->cco_bypass_b15 = 1;
  254. pllsetup->direct_output_b14 = 0;
  255. pllsetup->fdbk_div_ctrl_b13 = 1;
  256. pllsetup->pll_n = 1;
  257. pllsetup->pll_m = 1;
  258. for (p = 0; p <= 3; p++) {
  259. pllsetup->pll_p = pll_postdivs[p];
  260. fclkout = clk_check_pll_setup(ifreq, pllsetup);
  261. if (abs(target_freq - fclkout) <= freqtol)
  262. return fclkout;
  263. }
  264. }
  265. /* Is direct mode possible? */
  266. pllsetup->analog_on = 1;
  267. pllsetup->cco_bypass_b15 = 0;
  268. pllsetup->direct_output_b14 = 1;
  269. pllsetup->fdbk_div_ctrl_b13 = 0;
  270. pllsetup->pll_p = pll_postdivs[0];
  271. for (m = 1; m <= 256; m++) {
  272. for (n = 1; n <= 4; n++) {
  273. /* Compute output frequency for this value */
  274. pllsetup->pll_n = n;
  275. pllsetup->pll_m = m;
  276. fclkout = clk_check_pll_setup(ifreq,
  277. pllsetup);
  278. if (abs(target_freq - fclkout) <=
  279. freqtol)
  280. return fclkout;
  281. }
  282. }
  283. /* Is integer mode possible? */
  284. pllsetup->analog_on = 1;
  285. pllsetup->cco_bypass_b15 = 0;
  286. pllsetup->direct_output_b14 = 0;
  287. pllsetup->fdbk_div_ctrl_b13 = 1;
  288. for (m = 1; m <= 256; m++) {
  289. for (n = 1; n <= 4; n++) {
  290. for (p = 0; p < 4; p++) {
  291. /* Compute output frequency */
  292. pllsetup->pll_p = pll_postdivs[p];
  293. pllsetup->pll_n = n;
  294. pllsetup->pll_m = m;
  295. fclkout = clk_check_pll_setup(
  296. ifreq, pllsetup);
  297. if (abs(target_freq - fclkout) <= freqtol)
  298. return fclkout;
  299. }
  300. }
  301. }
  302. /* Try non-integer mode */
  303. pllsetup->analog_on = 1;
  304. pllsetup->cco_bypass_b15 = 0;
  305. pllsetup->direct_output_b14 = 0;
  306. pllsetup->fdbk_div_ctrl_b13 = 0;
  307. for (m = 1; m <= 256; m++) {
  308. for (n = 1; n <= 4; n++) {
  309. for (p = 0; p < 4; p++) {
  310. /* Compute output frequency */
  311. pllsetup->pll_p = pll_postdivs[p];
  312. pllsetup->pll_n = n;
  313. pllsetup->pll_m = m;
  314. fclkout = clk_check_pll_setup(
  315. ifreq, pllsetup);
  316. if (abs(target_freq - fclkout) <= freqtol)
  317. return fclkout;
  318. }
  319. }
  320. }
  321. return 0;
  322. }
  323. static struct clk clk_armpll = {
  324. .parent = &clk_sys,
  325. .get_rate = local_return_parent_rate,
  326. };
  327. /*
  328. * Setup the USB PLL with a PLL structure
  329. */
  330. static u32 local_clk_usbpll_setup(struct clk_pll_setup *pHCLKPllSetup)
  331. {
  332. u32 reg, tmp = local_clk_pll_setup(pHCLKPllSetup);
  333. reg = __raw_readl(LPC32XX_CLKPWR_USB_CTRL) & ~0x1FFFF;
  334. reg |= tmp;
  335. __raw_writel(reg, LPC32XX_CLKPWR_USB_CTRL);
  336. return clk_check_pll_setup(clk_usbpll.parent->rate,
  337. pHCLKPllSetup);
  338. }
  339. static int local_usbpll_enable(struct clk *clk, int enable)
  340. {
  341. u32 reg;
  342. int ret = 0;
  343. unsigned long timeout = jiffies + msecs_to_jiffies(20);
  344. reg = __raw_readl(LPC32XX_CLKPWR_USB_CTRL);
  345. __raw_writel(reg & ~(LPC32XX_CLKPWR_USBCTRL_CLK_EN2 |
  346. LPC32XX_CLKPWR_USBCTRL_PLL_PWRUP),
  347. LPC32XX_CLKPWR_USB_CTRL);
  348. __raw_writel(reg & ~LPC32XX_CLKPWR_USBCTRL_CLK_EN1,
  349. LPC32XX_CLKPWR_USB_CTRL);
  350. if (enable && usb_pll_valid && usb_pll_enable) {
  351. ret = -ENODEV;
  352. /*
  353. * If the PLL rate has been previously set, then the rate
  354. * in the PLL register is valid and can be enabled here.
  355. * Otherwise, it needs to be enabled as part of setrate.
  356. */
  357. /*
  358. * Gate clock into PLL
  359. */
  360. reg |= LPC32XX_CLKPWR_USBCTRL_CLK_EN1;
  361. __raw_writel(reg, LPC32XX_CLKPWR_USB_CTRL);
  362. /*
  363. * Enable PLL
  364. */
  365. reg |= LPC32XX_CLKPWR_USBCTRL_PLL_PWRUP;
  366. __raw_writel(reg, LPC32XX_CLKPWR_USB_CTRL);
  367. /*
  368. * Wait for PLL to lock
  369. */
  370. while (time_before(jiffies, timeout) && (ret == -ENODEV)) {
  371. reg = __raw_readl(LPC32XX_CLKPWR_USB_CTRL);
  372. if (reg & LPC32XX_CLKPWR_USBCTRL_PLL_STS)
  373. ret = 0;
  374. else
  375. udelay(10);
  376. }
  377. /*
  378. * Gate clock from PLL if PLL is locked
  379. */
  380. if (ret == 0) {
  381. __raw_writel(reg | LPC32XX_CLKPWR_USBCTRL_CLK_EN2,
  382. LPC32XX_CLKPWR_USB_CTRL);
  383. } else {
  384. __raw_writel(reg & ~(LPC32XX_CLKPWR_USBCTRL_CLK_EN1 |
  385. LPC32XX_CLKPWR_USBCTRL_PLL_PWRUP),
  386. LPC32XX_CLKPWR_USB_CTRL);
  387. }
  388. } else if ((enable == 0) && usb_pll_valid && usb_pll_enable) {
  389. usb_pll_valid = 0;
  390. usb_pll_enable = 0;
  391. }
  392. return ret;
  393. }
  394. static unsigned long local_usbpll_round_rate(struct clk *clk,
  395. unsigned long rate)
  396. {
  397. u32 clkin, usbdiv;
  398. struct clk_pll_setup pllsetup;
  399. /*
  400. * Unlike other clocks, this clock has a KHz input rate, so bump
  401. * it up to work with the PLL function
  402. */
  403. rate = rate * 1000;
  404. clkin = clk->get_rate(clk);
  405. usbdiv = (__raw_readl(LPC32XX_CLKPWR_USBCLK_PDIV) &
  406. LPC32XX_CLKPWR_USBPDIV_PLL_MASK) + 1;
  407. clkin = clkin / usbdiv;
  408. /* Try to find a good rate setup */
  409. if (local_clk_find_pll_cfg(clkin, rate, &pllsetup) == 0)
  410. return 0;
  411. return clk_check_pll_setup(clkin, &pllsetup);
  412. }
  413. static int local_usbpll_set_rate(struct clk *clk, unsigned long rate)
  414. {
  415. int ret = -ENODEV;
  416. u32 clkin, usbdiv;
  417. struct clk_pll_setup pllsetup;
  418. /*
  419. * Unlike other clocks, this clock has a KHz input rate, so bump
  420. * it up to work with the PLL function
  421. */
  422. rate = rate * 1000;
  423. clkin = clk->get_rate(clk->parent);
  424. usbdiv = (__raw_readl(LPC32XX_CLKPWR_USBCLK_PDIV) &
  425. LPC32XX_CLKPWR_USBPDIV_PLL_MASK) + 1;
  426. clkin = clkin / usbdiv;
  427. /* Try to find a good rate setup */
  428. if (local_clk_find_pll_cfg(clkin, rate, &pllsetup) == 0)
  429. return -EINVAL;
  430. /*
  431. * Disable PLL clocks during PLL change
  432. */
  433. local_usbpll_enable(clk, 0);
  434. pllsetup.analog_on = 0;
  435. local_clk_usbpll_setup(&pllsetup);
  436. /*
  437. * Start USB PLL and check PLL status
  438. */
  439. usb_pll_valid = 1;
  440. usb_pll_enable = 1;
  441. ret = local_usbpll_enable(clk, 1);
  442. if (ret >= 0)
  443. clk->rate = clk_check_pll_setup(clkin, &pllsetup);
  444. return ret;
  445. }
  446. static struct clk clk_usbpll = {
  447. .parent = &osc_main,
  448. .set_rate = local_usbpll_set_rate,
  449. .enable = local_usbpll_enable,
  450. .rate = 48000, /* In KHz */
  451. .get_rate = local_return_parent_rate,
  452. .round_rate = local_usbpll_round_rate,
  453. };
  454. static u32 clk_get_hclk_div(void)
  455. {
  456. static const u32 hclkdivs[4] = {1, 2, 4, 4};
  457. return hclkdivs[LPC32XX_CLKPWR_HCLKDIV_DIV_2POW(
  458. __raw_readl(LPC32XX_CLKPWR_HCLK_DIV))];
  459. }
  460. static struct clk clk_hclk = {
  461. .parent = &clk_armpll,
  462. .get_rate = local_return_parent_rate,
  463. };
  464. static struct clk clk_pclk = {
  465. .parent = &clk_armpll,
  466. .get_rate = local_return_parent_rate,
  467. };
  468. static int local_onoff_enable(struct clk *clk, int enable)
  469. {
  470. u32 tmp;
  471. tmp = __raw_readl(clk->enable_reg);
  472. if (enable == 0)
  473. tmp &= ~clk->enable_mask;
  474. else
  475. tmp |= clk->enable_mask;
  476. __raw_writel(tmp, clk->enable_reg);
  477. return 0;
  478. }
  479. /* Peripheral clock sources */
  480. static struct clk clk_timer0 = {
  481. .parent = &clk_pclk,
  482. .enable = local_onoff_enable,
  483. .enable_reg = LPC32XX_CLKPWR_TIMERS_PWMS_CLK_CTRL_1,
  484. .enable_mask = LPC32XX_CLKPWR_TMRPWMCLK_TIMER0_EN,
  485. .get_rate = local_return_parent_rate,
  486. };
  487. static struct clk clk_timer1 = {
  488. .parent = &clk_pclk,
  489. .enable = local_onoff_enable,
  490. .enable_reg = LPC32XX_CLKPWR_TIMERS_PWMS_CLK_CTRL_1,
  491. .enable_mask = LPC32XX_CLKPWR_TMRPWMCLK_TIMER1_EN,
  492. .get_rate = local_return_parent_rate,
  493. };
  494. static struct clk clk_timer2 = {
  495. .parent = &clk_pclk,
  496. .enable = local_onoff_enable,
  497. .enable_reg = LPC32XX_CLKPWR_TIMERS_PWMS_CLK_CTRL_1,
  498. .enable_mask = LPC32XX_CLKPWR_TMRPWMCLK_TIMER2_EN,
  499. .get_rate = local_return_parent_rate,
  500. };
  501. static struct clk clk_timer3 = {
  502. .parent = &clk_pclk,
  503. .enable = local_onoff_enable,
  504. .enable_reg = LPC32XX_CLKPWR_TIMERS_PWMS_CLK_CTRL_1,
  505. .enable_mask = LPC32XX_CLKPWR_TMRPWMCLK_TIMER3_EN,
  506. .get_rate = local_return_parent_rate,
  507. };
  508. static struct clk clk_wdt = {
  509. .parent = &clk_pclk,
  510. .enable = local_onoff_enable,
  511. .enable_reg = LPC32XX_CLKPWR_TIMER_CLK_CTRL,
  512. .enable_mask = LPC32XX_CLKPWR_PWMCLK_WDOG_EN,
  513. .get_rate = local_return_parent_rate,
  514. };
  515. static struct clk clk_vfp9 = {
  516. .parent = &clk_pclk,
  517. .enable = local_onoff_enable,
  518. .enable_reg = LPC32XX_CLKPWR_DEBUG_CTRL,
  519. .enable_mask = LPC32XX_CLKPWR_VFP_CLOCK_ENABLE_BIT,
  520. .get_rate = local_return_parent_rate,
  521. };
  522. static struct clk clk_dma = {
  523. .parent = &clk_hclk,
  524. .enable = local_onoff_enable,
  525. .enable_reg = LPC32XX_CLKPWR_DMA_CLK_CTRL,
  526. .enable_mask = LPC32XX_CLKPWR_DMACLKCTRL_CLK_EN,
  527. .get_rate = local_return_parent_rate,
  528. };
  529. static struct clk clk_uart3 = {
  530. .parent = &clk_pclk,
  531. .enable = local_onoff_enable,
  532. .enable_reg = LPC32XX_CLKPWR_UART_CLK_CTRL,
  533. .enable_mask = LPC32XX_CLKPWR_UARTCLKCTRL_UART3_EN,
  534. .get_rate = local_return_parent_rate,
  535. };
  536. static struct clk clk_uart4 = {
  537. .parent = &clk_pclk,
  538. .enable = local_onoff_enable,
  539. .enable_reg = LPC32XX_CLKPWR_UART_CLK_CTRL,
  540. .enable_mask = LPC32XX_CLKPWR_UARTCLKCTRL_UART4_EN,
  541. .get_rate = local_return_parent_rate,
  542. };
  543. static struct clk clk_uart5 = {
  544. .parent = &clk_pclk,
  545. .enable = local_onoff_enable,
  546. .enable_reg = LPC32XX_CLKPWR_UART_CLK_CTRL,
  547. .enable_mask = LPC32XX_CLKPWR_UARTCLKCTRL_UART5_EN,
  548. .get_rate = local_return_parent_rate,
  549. };
  550. static struct clk clk_uart6 = {
  551. .parent = &clk_pclk,
  552. .enable = local_onoff_enable,
  553. .enable_reg = LPC32XX_CLKPWR_UART_CLK_CTRL,
  554. .enable_mask = LPC32XX_CLKPWR_UARTCLKCTRL_UART6_EN,
  555. .get_rate = local_return_parent_rate,
  556. };
  557. static struct clk clk_i2c0 = {
  558. .parent = &clk_hclk,
  559. .enable = local_onoff_enable,
  560. .enable_reg = LPC32XX_CLKPWR_I2C_CLK_CTRL,
  561. .enable_mask = LPC32XX_CLKPWR_I2CCLK_I2C1CLK_EN,
  562. .get_rate = local_return_parent_rate,
  563. };
  564. static struct clk clk_i2c1 = {
  565. .parent = &clk_hclk,
  566. .enable = local_onoff_enable,
  567. .enable_reg = LPC32XX_CLKPWR_I2C_CLK_CTRL,
  568. .enable_mask = LPC32XX_CLKPWR_I2CCLK_I2C2CLK_EN,
  569. .get_rate = local_return_parent_rate,
  570. };
  571. static struct clk clk_i2c2 = {
  572. .parent = &clk_pclk,
  573. .enable = local_onoff_enable,
  574. .enable_reg = io_p2v(LPC32XX_USB_BASE + 0xFF4),
  575. .enable_mask = 0x4,
  576. .get_rate = local_return_parent_rate,
  577. };
  578. static struct clk clk_ssp0 = {
  579. .parent = &clk_hclk,
  580. .enable = local_onoff_enable,
  581. .enable_reg = LPC32XX_CLKPWR_SSP_CLK_CTRL,
  582. .enable_mask = LPC32XX_CLKPWR_SSPCTRL_SSPCLK0_EN,
  583. .get_rate = local_return_parent_rate,
  584. };
  585. static struct clk clk_ssp1 = {
  586. .parent = &clk_hclk,
  587. .enable = local_onoff_enable,
  588. .enable_reg = LPC32XX_CLKPWR_SSP_CLK_CTRL,
  589. .enable_mask = LPC32XX_CLKPWR_SSPCTRL_SSPCLK1_EN,
  590. .get_rate = local_return_parent_rate,
  591. };
  592. static struct clk clk_kscan = {
  593. .parent = &osc_32KHz,
  594. .enable = local_onoff_enable,
  595. .enable_reg = LPC32XX_CLKPWR_KEY_CLK_CTRL,
  596. .enable_mask = LPC32XX_CLKPWR_KEYCLKCTRL_CLK_EN,
  597. .get_rate = local_return_parent_rate,
  598. };
  599. static struct clk clk_nand = {
  600. .parent = &clk_hclk,
  601. .enable = local_onoff_enable,
  602. .enable_reg = LPC32XX_CLKPWR_NAND_CLK_CTRL,
  603. .enable_mask = LPC32XX_CLKPWR_NANDCLK_SLCCLK_EN,
  604. .get_rate = local_return_parent_rate,
  605. };
  606. static struct clk clk_i2s0 = {
  607. .parent = &clk_hclk,
  608. .enable = local_onoff_enable,
  609. .enable_reg = LPC32XX_CLKPWR_I2S_CLK_CTRL,
  610. .enable_mask = LPC32XX_CLKPWR_I2SCTRL_I2SCLK0_EN,
  611. .get_rate = local_return_parent_rate,
  612. };
  613. static struct clk clk_i2s1 = {
  614. .parent = &clk_hclk,
  615. .enable = local_onoff_enable,
  616. .enable_reg = LPC32XX_CLKPWR_I2S_CLK_CTRL,
  617. .enable_mask = LPC32XX_CLKPWR_I2SCTRL_I2SCLK1_EN,
  618. .get_rate = local_return_parent_rate,
  619. };
  620. static struct clk clk_net = {
  621. .parent = &clk_hclk,
  622. .enable = local_onoff_enable,
  623. .enable_reg = LPC32XX_CLKPWR_MACCLK_CTRL,
  624. .enable_mask = (LPC32XX_CLKPWR_MACCTRL_DMACLK_EN |
  625. LPC32XX_CLKPWR_MACCTRL_MMIOCLK_EN |
  626. LPC32XX_CLKPWR_MACCTRL_HRCCLK_EN),
  627. .get_rate = local_return_parent_rate,
  628. };
  629. static struct clk clk_rtc = {
  630. .parent = &osc_32KHz,
  631. .rate = 1, /* 1 Hz */
  632. .get_rate = local_return_parent_rate,
  633. };
  634. static struct clk clk_usbd = {
  635. .parent = &clk_usbpll,
  636. .enable = local_onoff_enable,
  637. .enable_reg = LPC32XX_CLKPWR_USB_CTRL,
  638. .enable_mask = LPC32XX_CLKPWR_USBCTRL_HCLK_EN,
  639. .get_rate = local_return_parent_rate,
  640. };
  641. static int tsc_onoff_enable(struct clk *clk, int enable)
  642. {
  643. u32 tmp;
  644. /* Make sure 32KHz clock is the selected clock */
  645. tmp = __raw_readl(LPC32XX_CLKPWR_ADC_CLK_CTRL_1);
  646. tmp &= ~LPC32XX_CLKPWR_ADCCTRL1_PCLK_SEL;
  647. __raw_writel(tmp, LPC32XX_CLKPWR_ADC_CLK_CTRL_1);
  648. if (enable == 0)
  649. __raw_writel(0, clk->enable_reg);
  650. else
  651. __raw_writel(clk->enable_mask, clk->enable_reg);
  652. return 0;
  653. }
  654. static struct clk clk_tsc = {
  655. .parent = &osc_32KHz,
  656. .enable = tsc_onoff_enable,
  657. .enable_reg = LPC32XX_CLKPWR_ADC_CLK_CTRL,
  658. .enable_mask = LPC32XX_CLKPWR_ADC32CLKCTRL_CLK_EN,
  659. .get_rate = local_return_parent_rate,
  660. };
  661. static int adc_onoff_enable(struct clk *clk, int enable)
  662. {
  663. u32 tmp;
  664. u32 divider;
  665. /* Use PERIPH_CLOCK */
  666. tmp = __raw_readl(LPC32XX_CLKPWR_ADC_CLK_CTRL_1);
  667. tmp |= LPC32XX_CLKPWR_ADCCTRL1_PCLK_SEL;
  668. /*
  669. * Set clock divider so that we have equal to or less than
  670. * 4.5MHz clock at ADC
  671. */
  672. divider = clk->get_rate(clk) / 4500000 + 1;
  673. tmp |= divider;
  674. __raw_writel(tmp, LPC32XX_CLKPWR_ADC_CLK_CTRL_1);
  675. /* synchronize rate of this clock w/ actual HW setting */
  676. clk->rate = clk->get_rate(clk->parent) / divider;
  677. if (enable == 0)
  678. __raw_writel(0, clk->enable_reg);
  679. else
  680. __raw_writel(clk->enable_mask, clk->enable_reg);
  681. return 0;
  682. }
  683. static struct clk clk_adc = {
  684. .parent = &clk_pclk,
  685. .enable = adc_onoff_enable,
  686. .enable_reg = LPC32XX_CLKPWR_ADC_CLK_CTRL,
  687. .enable_mask = LPC32XX_CLKPWR_ADC32CLKCTRL_CLK_EN,
  688. .get_rate = local_return_parent_rate,
  689. };
  690. static int mmc_onoff_enable(struct clk *clk, int enable)
  691. {
  692. u32 tmp;
  693. tmp = __raw_readl(LPC32XX_CLKPWR_MS_CTRL) &
  694. ~LPC32XX_CLKPWR_MSCARD_SDCARD_EN;
  695. /* If rate is 0, disable clock */
  696. if (enable != 0)
  697. tmp |= LPC32XX_CLKPWR_MSCARD_SDCARD_EN;
  698. __raw_writel(tmp, LPC32XX_CLKPWR_MS_CTRL);
  699. return 0;
  700. }
  701. static unsigned long mmc_get_rate(struct clk *clk)
  702. {
  703. u32 div, rate, oldclk;
  704. /* The MMC clock must be on when accessing an MMC register */
  705. oldclk = __raw_readl(LPC32XX_CLKPWR_MS_CTRL);
  706. __raw_writel(oldclk | LPC32XX_CLKPWR_MSCARD_SDCARD_EN,
  707. LPC32XX_CLKPWR_MS_CTRL);
  708. div = __raw_readl(LPC32XX_CLKPWR_MS_CTRL);
  709. __raw_writel(oldclk, LPC32XX_CLKPWR_MS_CTRL);
  710. /* Get the parent clock rate */
  711. rate = clk->parent->get_rate(clk->parent);
  712. /* Get the MMC controller clock divider value */
  713. div = div & LPC32XX_CLKPWR_MSCARD_SDCARD_DIV(0xf);
  714. if (!div)
  715. div = 1;
  716. return rate / div;
  717. }
  718. static unsigned long mmc_round_rate(struct clk *clk, unsigned long rate)
  719. {
  720. unsigned long div, prate;
  721. /* Get the parent clock rate */
  722. prate = clk->parent->get_rate(clk->parent);
  723. if (rate >= prate)
  724. return prate;
  725. div = prate / rate;
  726. if (div > 0xf)
  727. div = 0xf;
  728. return prate / div;
  729. }
  730. static int mmc_set_rate(struct clk *clk, unsigned long rate)
  731. {
  732. u32 oldclk, tmp;
  733. unsigned long prate, div, crate = mmc_round_rate(clk, rate);
  734. prate = clk->parent->get_rate(clk->parent);
  735. div = prate / crate;
  736. /* The MMC clock must be on when accessing an MMC register */
  737. oldclk = __raw_readl(LPC32XX_CLKPWR_MS_CTRL);
  738. __raw_writel(oldclk | LPC32XX_CLKPWR_MSCARD_SDCARD_EN,
  739. LPC32XX_CLKPWR_MS_CTRL);
  740. tmp = __raw_readl(LPC32XX_CLKPWR_MS_CTRL) &
  741. ~LPC32XX_CLKPWR_MSCARD_SDCARD_DIV(0xf);
  742. tmp |= LPC32XX_CLKPWR_MSCARD_SDCARD_DIV(div);
  743. __raw_writel(tmp, LPC32XX_CLKPWR_MS_CTRL);
  744. __raw_writel(oldclk, LPC32XX_CLKPWR_MS_CTRL);
  745. return 0;
  746. }
  747. static struct clk clk_mmc = {
  748. .parent = &clk_armpll,
  749. .set_rate = mmc_set_rate,
  750. .get_rate = mmc_get_rate,
  751. .round_rate = mmc_round_rate,
  752. .enable = mmc_onoff_enable,
  753. .enable_reg = LPC32XX_CLKPWR_MS_CTRL,
  754. .enable_mask = LPC32XX_CLKPWR_MSCARD_SDCARD_EN,
  755. };
  756. static unsigned long clcd_get_rate(struct clk *clk)
  757. {
  758. u32 tmp, div, rate, oldclk;
  759. /* The LCD clock must be on when accessing an LCD register */
  760. oldclk = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL);
  761. __raw_writel(oldclk | LPC32XX_CLKPWR_LCDCTRL_CLK_EN,
  762. LPC32XX_CLKPWR_LCDCLK_CTRL);
  763. tmp = __raw_readl(io_p2v(LPC32XX_LCD_BASE + CLCD_TIM2));
  764. __raw_writel(oldclk, LPC32XX_CLKPWR_LCDCLK_CTRL);
  765. rate = clk->parent->get_rate(clk->parent);
  766. /* Only supports internal clocking */
  767. if (tmp & TIM2_BCD)
  768. return rate;
  769. div = (tmp & 0x1F) | ((tmp & 0xF8) >> 22);
  770. tmp = rate / (2 + div);
  771. return tmp;
  772. }
  773. static int clcd_set_rate(struct clk *clk, unsigned long rate)
  774. {
  775. u32 tmp, prate, div, oldclk;
  776. /* The LCD clock must be on when accessing an LCD register */
  777. oldclk = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL);
  778. __raw_writel(oldclk | LPC32XX_CLKPWR_LCDCTRL_CLK_EN,
  779. LPC32XX_CLKPWR_LCDCLK_CTRL);
  780. tmp = __raw_readl(io_p2v(LPC32XX_LCD_BASE + CLCD_TIM2)) | TIM2_BCD;
  781. prate = clk->parent->get_rate(clk->parent);
  782. if (rate < prate) {
  783. /* Find closest divider */
  784. div = prate / rate;
  785. if (div >= 2) {
  786. div -= 2;
  787. tmp &= ~TIM2_BCD;
  788. }
  789. tmp &= ~(0xF800001F);
  790. tmp |= (div & 0x1F);
  791. tmp |= (((div >> 5) & 0x1F) << 27);
  792. }
  793. __raw_writel(tmp, io_p2v(LPC32XX_LCD_BASE + CLCD_TIM2));
  794. __raw_writel(oldclk, LPC32XX_CLKPWR_LCDCLK_CTRL);
  795. return 0;
  796. }
  797. static unsigned long clcd_round_rate(struct clk *clk, unsigned long rate)
  798. {
  799. u32 prate, div;
  800. prate = clk->parent->get_rate(clk->parent);
  801. if (rate >= prate)
  802. rate = prate;
  803. else {
  804. div = prate / rate;
  805. if (div > 0x3ff)
  806. div = 0x3ff;
  807. rate = prate / div;
  808. }
  809. return rate;
  810. }
  811. static struct clk clk_lcd = {
  812. .parent = &clk_hclk,
  813. .set_rate = clcd_set_rate,
  814. .get_rate = clcd_get_rate,
  815. .round_rate = clcd_round_rate,
  816. .enable = local_onoff_enable,
  817. .enable_reg = LPC32XX_CLKPWR_LCDCLK_CTRL,
  818. .enable_mask = LPC32XX_CLKPWR_LCDCTRL_CLK_EN,
  819. };
  820. static void local_clk_disable(struct clk *clk)
  821. {
  822. /* Don't attempt to disable clock if it has no users */
  823. if (clk->usecount > 0) {
  824. clk->usecount--;
  825. /* Only disable clock when it has no more users */
  826. if ((clk->usecount == 0) && (clk->enable))
  827. clk->enable(clk, 0);
  828. /* Check parent clocks, they may need to be disabled too */
  829. if (clk->parent)
  830. local_clk_disable(clk->parent);
  831. }
  832. }
  833. static int local_clk_enable(struct clk *clk)
  834. {
  835. int ret = 0;
  836. /* Enable parent clocks first and update use counts */
  837. if (clk->parent)
  838. ret = local_clk_enable(clk->parent);
  839. if (!ret) {
  840. /* Only enable clock if it's currently disabled */
  841. if ((clk->usecount == 0) && (clk->enable))
  842. ret = clk->enable(clk, 1);
  843. if (!ret)
  844. clk->usecount++;
  845. else if (clk->parent)
  846. local_clk_disable(clk->parent);
  847. }
  848. return ret;
  849. }
  850. /*
  851. * clk_enable - inform the system when the clock source should be running.
  852. */
  853. int clk_enable(struct clk *clk)
  854. {
  855. int ret;
  856. unsigned long flags;
  857. spin_lock_irqsave(&global_clkregs_lock, flags);
  858. ret = local_clk_enable(clk);
  859. spin_unlock_irqrestore(&global_clkregs_lock, flags);
  860. return ret;
  861. }
  862. EXPORT_SYMBOL(clk_enable);
  863. /*
  864. * clk_disable - inform the system when the clock source is no longer required
  865. */
  866. void clk_disable(struct clk *clk)
  867. {
  868. unsigned long flags;
  869. spin_lock_irqsave(&global_clkregs_lock, flags);
  870. local_clk_disable(clk);
  871. spin_unlock_irqrestore(&global_clkregs_lock, flags);
  872. }
  873. EXPORT_SYMBOL(clk_disable);
  874. /*
  875. * clk_get_rate - obtain the current clock rate (in Hz) for a clock source
  876. */
  877. unsigned long clk_get_rate(struct clk *clk)
  878. {
  879. return clk->get_rate(clk);
  880. }
  881. EXPORT_SYMBOL(clk_get_rate);
  882. /*
  883. * clk_set_rate - set the clock rate for a clock source
  884. */
  885. int clk_set_rate(struct clk *clk, unsigned long rate)
  886. {
  887. int ret = -EINVAL;
  888. /*
  889. * Most system clocks can only be enabled or disabled, with
  890. * the actual rate set as part of the peripheral dividers
  891. * instead of high level clock control
  892. */
  893. if (clk->set_rate)
  894. ret = clk->set_rate(clk, rate);
  895. return ret;
  896. }
  897. EXPORT_SYMBOL(clk_set_rate);
  898. /*
  899. * clk_round_rate - adjust a rate to the exact rate a clock can provide
  900. */
  901. long clk_round_rate(struct clk *clk, unsigned long rate)
  902. {
  903. if (clk->round_rate)
  904. rate = clk->round_rate(clk, rate);
  905. else
  906. rate = clk->get_rate(clk);
  907. return rate;
  908. }
  909. EXPORT_SYMBOL(clk_round_rate);
  910. /*
  911. * clk_set_parent - set the parent clock source for this clock
  912. */
  913. int clk_set_parent(struct clk *clk, struct clk *parent)
  914. {
  915. /* Clock re-parenting is not supported */
  916. return -EINVAL;
  917. }
  918. EXPORT_SYMBOL(clk_set_parent);
  919. /*
  920. * clk_get_parent - get the parent clock source for this clock
  921. */
  922. struct clk *clk_get_parent(struct clk *clk)
  923. {
  924. return clk->parent;
  925. }
  926. EXPORT_SYMBOL(clk_get_parent);
  927. #define _REGISTER_CLOCK(d, n, c) \
  928. { \
  929. .dev_id = (d), \
  930. .con_id = (n), \
  931. .clk = &(c), \
  932. },
  933. static struct clk_lookup lookups[] = {
  934. _REGISTER_CLOCK(NULL, "osc_32KHz", osc_32KHz)
  935. _REGISTER_CLOCK(NULL, "osc_pll397", osc_pll397)
  936. _REGISTER_CLOCK(NULL, "osc_main", osc_main)
  937. _REGISTER_CLOCK(NULL, "sys_ck", clk_sys)
  938. _REGISTER_CLOCK(NULL, "arm_pll_ck", clk_armpll)
  939. _REGISTER_CLOCK(NULL, "ck_pll5", clk_usbpll)
  940. _REGISTER_CLOCK(NULL, "hclk_ck", clk_hclk)
  941. _REGISTER_CLOCK(NULL, "pclk_ck", clk_pclk)
  942. _REGISTER_CLOCK(NULL, "timer0_ck", clk_timer0)
  943. _REGISTER_CLOCK(NULL, "timer1_ck", clk_timer1)
  944. _REGISTER_CLOCK(NULL, "timer2_ck", clk_timer2)
  945. _REGISTER_CLOCK(NULL, "timer3_ck", clk_timer3)
  946. _REGISTER_CLOCK(NULL, "vfp9_ck", clk_vfp9)
  947. _REGISTER_CLOCK(NULL, "clk_dmac", clk_dma)
  948. _REGISTER_CLOCK("pnx4008-watchdog", NULL, clk_wdt)
  949. _REGISTER_CLOCK(NULL, "uart3_ck", clk_uart3)
  950. _REGISTER_CLOCK(NULL, "uart4_ck", clk_uart4)
  951. _REGISTER_CLOCK(NULL, "uart5_ck", clk_uart5)
  952. _REGISTER_CLOCK(NULL, "uart6_ck", clk_uart6)
  953. _REGISTER_CLOCK("pnx-i2c.0", NULL, clk_i2c0)
  954. _REGISTER_CLOCK("pnx-i2c.1", NULL, clk_i2c1)
  955. _REGISTER_CLOCK("pnx-i2c.2", NULL, clk_i2c2)
  956. _REGISTER_CLOCK("dev:ssp0", NULL, clk_ssp0)
  957. _REGISTER_CLOCK("dev:ssp1", NULL, clk_ssp1)
  958. _REGISTER_CLOCK("lpc32xx_keys.0", NULL, clk_kscan)
  959. _REGISTER_CLOCK("lpc32xx-nand.0", "nand_ck", clk_nand)
  960. _REGISTER_CLOCK("lpc32xx-adc", NULL, clk_adc)
  961. _REGISTER_CLOCK(NULL, "i2s0_ck", clk_i2s0)
  962. _REGISTER_CLOCK(NULL, "i2s1_ck", clk_i2s1)
  963. _REGISTER_CLOCK("ts-lpc32xx", NULL, clk_tsc)
  964. _REGISTER_CLOCK("dev:mmc0", NULL, clk_mmc)
  965. _REGISTER_CLOCK("lpc-eth.0", NULL, clk_net)
  966. _REGISTER_CLOCK("dev:clcd", NULL, clk_lcd)
  967. _REGISTER_CLOCK("lpc32xx_udc", "ck_usbd", clk_usbd)
  968. _REGISTER_CLOCK("lpc32xx_rtc", NULL, clk_rtc)
  969. };
  970. static int __init clk_init(void)
  971. {
  972. int i;
  973. for (i = 0; i < ARRAY_SIZE(lookups); i++)
  974. clkdev_add(&lookups[i]);
  975. /*
  976. * Setup muxed SYSCLK for HCLK PLL base -this selects the
  977. * parent clock used for the ARM PLL and is used to derive
  978. * the many system clock rates in the device.
  979. */
  980. if (clk_is_sysclk_mainosc() != 0)
  981. clk_sys.parent = &osc_main;
  982. else
  983. clk_sys.parent = &osc_pll397;
  984. clk_sys.rate = clk_sys.parent->rate;
  985. /* Compute the current ARM PLL and USB PLL frequencies */
  986. local_update_armpll_rate();
  987. /* Compute HCLK and PCLK bus rates */
  988. clk_hclk.rate = clk_hclk.parent->rate / clk_get_hclk_div();
  989. clk_pclk.rate = clk_pclk.parent->rate / clk_get_pclk_div();
  990. /*
  991. * Enable system clocks - this step is somewhat formal, as the
  992. * clocks are already running, but it does get the clock data
  993. * inline with the actual system state. Never disable these
  994. * clocks as they will only stop if the system is going to sleep.
  995. * In that case, the chip/system power management functions will
  996. * handle clock gating.
  997. */
  998. if (clk_enable(&clk_hclk) || clk_enable(&clk_pclk))
  999. printk(KERN_ERR "Error enabling system HCLK and PCLK\n");
  1000. /*
  1001. * Timers 0 and 1 were enabled and are being used by the high
  1002. * resolution tick function prior to this driver being initialized.
  1003. * Tag them now as used.
  1004. */
  1005. if (clk_enable(&clk_timer0) || clk_enable(&clk_timer1))
  1006. printk(KERN_ERR "Error enabling timer tick clocks\n");
  1007. return 0;
  1008. }
  1009. core_initcall(clk_init);