85 #include <linux/export.h>
86 #include <linux/kernel.h>
87 #include <linux/list.h>
88 #include <linux/errno.h>
89 #include <linux/device.h>
97 #include <mach/hardware.h>
98 #include <mach/platform.h>
104 static int usb_pll_enable, usb_pll_valid;
106 static struct clk clk_armpll;
107 static struct clk clk_usbpll;
112 static const u32 pll_postdivs[4] = {1, 2, 4, 8};
114 static unsigned long local_return_parent_rate(
struct clk *
clk)
120 while (clk->
rate == 0)
127 static struct clk osc_32KHz = {
129 .get_rate = local_return_parent_rate,
132 static int local_pll397_enable(
struct clk *clk,
int enable)
154 LPC32XX_CLKPWR_SYSCTRL_PLL397_STS) == 0)
161 static int local_oscmain_enable(
struct clk *clk,
int enable)
183 LPC32XX_CLKPWR_MOSC_DISABLE) != 0)
190 static struct clk osc_pll397 = {
191 .parent = &osc_32KHz,
192 .
enable = local_pll397_enable,
194 .get_rate = local_return_parent_rate,
197 static struct clk osc_main = {
198 .enable = local_oscmain_enable,
200 .get_rate = local_return_parent_rate,
203 static struct clk clk_sys;
221 pllcfg.
pll_m = 1 + ((regval >> 1) & 0xFF);
222 pllcfg.
pll_n = 1 + ((regval >> 9) & 0x3);
223 pllcfg.
pll_p = pll_postdivs[((regval >> 11) & 0x3)];
258 static void local_update_armpll_rate(
void)
262 clkin = clk_armpll.parent->rate;
271 static u32 local_clk_find_pll_cfg(
u32 pllin_freq,
u32 target_freq,
277 freqtol = target_freq / 250;
281 if (
abs(pllin_freq - target_freq) <= freqtol) {
286 pllsetup->
pll_p = pll_postdivs[0];
290 }
else if (target_freq <= ifreq) {
297 for (p = 0; p <= 3; p++) {
298 pllsetup->
pll_p = pll_postdivs[
p];
300 if (
abs(target_freq - fclkout) <= freqtol)
310 pllsetup->
pll_p = pll_postdivs[0];
311 for (m = 1; m <= 256; m++) {
312 for (n = 1; n <= 4; n++) {
318 if (
abs(target_freq - fclkout) <=
329 for (m = 1; m <= 256; m++) {
330 for (n = 1; n <= 4; n++) {
331 for (p = 0; p < 4; p++) {
333 pllsetup->
pll_p = pll_postdivs[
p];
338 if (
abs(target_freq - fclkout) <= freqtol)
349 for (m = 1; m <= 256; m++) {
350 for (n = 1; n <= 4; n++) {
351 for (p = 0; p < 4; p++) {
353 pllsetup->
pll_p = pll_postdivs[
p];
358 if (
abs(target_freq - fclkout) <= freqtol)
367 static struct clk clk_armpll = {
369 .get_rate = local_return_parent_rate,
377 u32 reg, tmp = local_clk_pll_setup(pHCLKPllSetup);
387 static int local_usbpll_enable(
struct clk *clk,
int enable)
401 if (enable && usb_pll_valid && usb_pll_enable) {
443 }
else if ((enable == 0) && usb_pll_valid && usb_pll_enable) {
451 static unsigned long local_usbpll_round_rate(
struct clk *clk,
466 clkin = clkin / usbdiv;
469 if (local_clk_find_pll_cfg(clkin, rate, &pllsetup) == 0)
475 static int local_usbpll_set_rate(
struct clk *clk,
unsigned long rate)
490 clkin = clkin / usbdiv;
493 if (local_clk_find_pll_cfg(clkin, rate, &pllsetup) == 0)
499 local_usbpll_enable(clk, 0);
501 local_clk_usbpll_setup(&pllsetup);
510 ret = local_usbpll_enable(clk, 1);
517 static struct clk clk_usbpll = {
520 .enable = local_usbpll_enable,
522 .get_rate = local_return_parent_rate,
523 .round_rate = local_usbpll_round_rate,
526 static u32 clk_get_hclk_div(
void)
528 static const u32 hclkdivs[4] = {1, 2, 4, 4};
533 static struct clk clk_hclk = {
534 .parent = &clk_armpll,
535 .
get_rate = local_return_parent_rate,
538 static struct clk clk_pclk = {
539 .parent = &clk_armpll,
540 .
get_rate = local_return_parent_rate,
543 static int local_onoff_enable(
struct clk *clk,
int enable)
560 static struct clk clk_timer0 = {
562 .
enable = local_onoff_enable,
565 .get_rate = local_return_parent_rate,
567 static struct clk clk_timer1 = {
569 .
enable = local_onoff_enable,
572 .get_rate = local_return_parent_rate,
574 static struct clk clk_timer2 = {
576 .
enable = local_onoff_enable,
579 .get_rate = local_return_parent_rate,
581 static struct clk clk_timer3 = {
583 .
enable = local_onoff_enable,
586 .get_rate = local_return_parent_rate,
588 static struct clk clk_wdt = {
590 .
enable = local_onoff_enable,
593 .get_rate = local_return_parent_rate,
595 static struct clk clk_vfp9 = {
597 .
enable = local_onoff_enable,
600 .get_rate = local_return_parent_rate,
602 static struct clk clk_dma = {
604 .
enable = local_onoff_enable,
607 .get_rate = local_return_parent_rate,
610 static struct clk clk_pwm = {
612 .
enable = local_onoff_enable,
620 .get_rate = local_return_parent_rate,
623 static struct clk clk_uart3 = {
625 .
enable = local_onoff_enable,
628 .get_rate = local_return_parent_rate,
631 static struct clk clk_uart4 = {
633 .
enable = local_onoff_enable,
636 .get_rate = local_return_parent_rate,
639 static struct clk clk_uart5 = {
641 .
enable = local_onoff_enable,
644 .get_rate = local_return_parent_rate,
647 static struct clk clk_uart6 = {
649 .
enable = local_onoff_enable,
652 .get_rate = local_return_parent_rate,
655 static struct clk clk_i2c0 = {
657 .
enable = local_onoff_enable,
660 .get_rate = local_return_parent_rate,
663 static struct clk clk_i2c1 = {
665 .
enable = local_onoff_enable,
668 .get_rate = local_return_parent_rate,
671 static struct clk clk_i2c2 = {
673 .
enable = local_onoff_enable,
676 .get_rate = local_return_parent_rate,
679 static struct clk clk_ssp0 = {
681 .
enable = local_onoff_enable,
684 .get_rate = local_return_parent_rate,
687 static struct clk clk_ssp1 = {
689 .
enable = local_onoff_enable,
692 .get_rate = local_return_parent_rate,
695 static struct clk clk_kscan = {
696 .parent = &osc_32KHz,
697 .
enable = local_onoff_enable,
700 .get_rate = local_return_parent_rate,
703 static struct clk clk_nand = {
705 .
enable = local_onoff_enable,
709 .get_rate = local_return_parent_rate,
712 static struct clk clk_nand_mlc = {
714 .
enable = local_onoff_enable,
719 .get_rate = local_return_parent_rate,
722 static struct clk clk_i2s0 = {
724 .
enable = local_onoff_enable,
727 .get_rate = local_return_parent_rate,
730 static struct clk clk_i2s1 = {
732 .
enable = local_onoff_enable,
736 .get_rate = local_return_parent_rate,
739 static struct clk clk_net = {
741 .
enable = local_onoff_enable,
746 .
get_rate = local_return_parent_rate,
749 static struct clk clk_rtc = {
750 .parent = &osc_32KHz,
752 .get_rate = local_return_parent_rate,
755 static int local_usb_enable(
struct clk *clk,
int enable)
766 return local_onoff_enable(clk, enable);
769 static struct clk clk_usbd = {
770 .parent = &clk_usbpll,
771 .
enable = local_usb_enable,
774 .get_rate = local_return_parent_rate,
777 #define OTG_ALWAYS_MASK (LPC32XX_USB_OTG_OTG_CLOCK_ON | \
778 LPC32XX_USB_OTG_I2C_CLOCK_ON)
780 static int local_usb_otg_enable(
struct clk *clk,
int enable)
804 static struct clk clk_usb_otg_dev = {
805 .parent = &clk_usbpll,
806 .
enable = local_usb_otg_enable,
812 .get_rate = local_return_parent_rate,
815 static struct clk clk_usb_otg_host = {
816 .parent = &clk_usbpll,
817 .
enable = local_usb_otg_enable,
823 .get_rate = local_return_parent_rate,
826 static int tsc_onoff_enable(
struct clk *clk,
int enable)
843 static struct clk clk_tsc = {
844 .parent = &osc_32KHz,
845 .
enable = tsc_onoff_enable,
848 .get_rate = local_return_parent_rate,
851 static int adc_onoff_enable(
struct clk *clk,
int enable)
863 divider = clk->
get_rate(clk) / 4500000 + 1;
878 static struct clk clk_adc = {
880 .
enable = adc_onoff_enable,
883 .get_rate = local_return_parent_rate,
886 static int mmc_onoff_enable(
struct clk *clk,
int enable)
908 static unsigned long mmc_get_rate(
struct clk *clk)
931 static unsigned long mmc_round_rate(
struct clk *clk,
unsigned long rate)
948 static int mmc_set_rate(
struct clk *clk,
unsigned long rate)
951 unsigned long prate,
div, crate = mmc_round_rate(clk, rate);
967 static struct clk clk_mmc = {
968 .parent = &clk_armpll,
970 .get_rate = mmc_get_rate,
971 .round_rate = mmc_round_rate,
972 .enable = mmc_onoff_enable,
977 static unsigned long clcd_get_rate(
struct clk *clk)
994 div = (tmp & 0x1F) | ((tmp & 0xF8) >> 22);
995 tmp = rate / (2 +
div);
1000 static int clcd_set_rate(
struct clk *clk,
unsigned long rate)
1020 tmp &= ~(0xF800001F);
1021 tmp |= (div & 0x1F);
1022 tmp |= (((div >> 5) & 0x1F) << 27);
1031 static unsigned long clcd_round_rate(
struct clk *clk,
unsigned long rate)
1050 static struct clk clk_lcd = {
1051 .parent = &clk_hclk,
1053 .get_rate = clcd_get_rate,
1054 .round_rate = clcd_round_rate,
1055 .enable = local_onoff_enable,
1060 static void local_clk_disable(
struct clk *clk)
1072 local_clk_disable(clk->
parent);
1076 static int local_clk_enable(
struct clk *clk)
1082 ret = local_clk_enable(clk->
parent);
1087 ret = clk->
enable(clk, 1);
1092 local_clk_disable(clk->
parent);
1104 unsigned long flags;
1107 ret = local_clk_enable(clk);
1108 spin_unlock_irqrestore(&global_clkregs_lock, flags);
1119 unsigned long flags;
1122 local_clk_disable(clk);
1123 spin_unlock_irqrestore(&global_clkregs_lock, flags);
1224 CLKDEV_INIT(
"31020000.usbd",
"ck_usbd", &clk_usbd),
1225 CLKDEV_INIT(
"31020000.ohci",
"ck_usbd", &clk_usbd),
1226 CLKDEV_INIT(
"31020000.usbd",
"ck_usb_otg", &clk_usb_otg_dev),
1227 CLKDEV_INIT(
"31020000.ohci",
"ck_usb_otg", &clk_usb_otg_host),
1244 clk_sys.parent = &osc_main;
1246 clk_sys.parent = &osc_pll397;
1248 clk_sys.rate = clk_sys.parent->rate;
1251 local_update_armpll_rate();
1254 clk_hclk.
rate = clk_hclk.
parent->rate / clk_get_hclk_div();