24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/list.h>
27 #include <linux/errno.h>
29 #include <linux/device.h>
33 #include <linux/serial_core.h>
38 #include <mach/hardware.h>
41 #include <mach/regs-clock.h>
42 #include <mach/regs-gpio.h>
45 #include <plat/clock.h>
57 static int s3c2412_clkcon_enable(
struct clk *
clk,
int enable)
59 unsigned int clocks = clk->
ctrlbit;
74 static int s3c2412_upll_enable(
struct clk *clk,
int enable)
77 unsigned long orig = upllcon;
80 upllcon |= S3C2412_PLLCON_OFF;
82 upllcon &= ~S3C2412_PLLCON_OFF;
88 if (enable && (orig & S3C2412_PLLCON_OFF))
96 static struct clk clk_erefclk = {
100 static struct clk clk_urefclk = {
104 static int s3c2412_setparent_usysclk(
struct clk *clk,
struct clk *
parent)
106 unsigned long clksrc =
__raw_readl(S3C2412_CLKSRC);
108 if (parent == &clk_urefclk)
109 clksrc &= ~S3C2412_CLKSRC_USYSCLK_UPLL;
111 clksrc |= S3C2412_CLKSRC_USYSCLK_UPLL;
121 static struct clk clk_usysclk = {
125 .set_parent = s3c2412_setparent_usysclk,
129 static struct clk clk_mrefclk = {
134 static struct clk clk_mdivclk = {
139 static int s3c2412_setparent_usbsrc(
struct clk *clk,
struct clk *parent)
141 unsigned long clksrc =
__raw_readl(S3C2412_CLKSRC);
143 if (parent == &clk_usysclk)
144 clksrc &= ~S3C2412_CLKSRC_USBCLK_HCLK;
145 else if (parent == &clk_h)
146 clksrc |= S3C2412_CLKSRC_USBCLK_HCLK;
156 static unsigned long s3c2412_roundrate_usbsrc(
struct clk *clk,
162 if (rate > parent_rate)
165 div = parent_rate /
rate;
169 return parent_rate /
div;
172 static unsigned long s3c2412_getrate_usbsrc(
struct clk *clk)
177 return parent_rate / ((div & S3C2412_CLKDIVN_USB48DIV) ? 2 : 1);
180 static int s3c2412_setrate_usbsrc(
struct clk *clk,
unsigned long rate)
185 rate = s3c2412_roundrate_usbsrc(clk, rate);
187 if ((parent_rate / rate) == 2)
188 clkdivn |= S3C2412_CLKDIVN_USB48DIV;
190 clkdivn &= ~S3C2412_CLKDIVN_USB48DIV;
196 static struct clk clk_usbsrc = {
199 .get_rate = s3c2412_getrate_usbsrc,
200 .set_rate = s3c2412_setrate_usbsrc,
201 .round_rate = s3c2412_roundrate_usbsrc,
202 .set_parent = s3c2412_setparent_usbsrc,
206 static int s3c2412_setparent_msysclk(
struct clk *clk,
struct clk *parent)
208 unsigned long clksrc =
__raw_readl(S3C2412_CLKSRC);
210 if (parent == &clk_mdivclk)
211 clksrc &= ~S3C2412_CLKSRC_MSYSCLK_MPLL;
213 clksrc |= S3C2412_CLKSRC_MSYSCLK_MPLL;
226 .set_parent = s3c2412_setparent_msysclk,
230 static int s3c2412_setparent_armclk(
struct clk *clk,
struct clk *parent)
233 unsigned long clkdiv;
238 if (parent == &clk_msysclk || parent == &clk_f)
240 else if (parent == &clk_h)
241 dvs = S3C2412_CLKDIVN_DVSEN;
253 clkdiv &= ~S3C2412_CLKDIVN_DVSEN;
262 static struct clk clk_armclk = {
266 .set_parent = s3c2412_setparent_armclk,
274 static unsigned long s3c2412_roundrate_clksrc(
struct clk *clk,
280 if (rate > parent_rate)
285 div = (rate / parent_rate);
292 return parent_rate /
div;
295 static int s3c2412_setparent_uart(
struct clk *clk,
struct clk *parent)
297 unsigned long clksrc =
__raw_readl(S3C2412_CLKSRC);
299 if (parent == &clk_erefclk)
300 clksrc &= ~S3C2412_CLKSRC_UARTCLK_MPLL;
302 clksrc |= S3C2412_CLKSRC_UARTCLK_MPLL;
312 static unsigned long s3c2412_getrate_uart(
struct clk *clk)
317 div &= S3C2412_CLKDIVN_UARTDIV_MASK;
318 div >>= S3C2412_CLKDIVN_UARTDIV_SHIFT;
320 return parent_rate / (div + 1);
323 static int s3c2412_setrate_uart(
struct clk *clk,
unsigned long rate)
328 rate = s3c2412_roundrate_clksrc(clk, rate);
330 clkdivn &= ~S3C2412_CLKDIVN_UARTDIV_MASK;
331 clkdivn |= ((parent_rate /
rate) - 1) << S3C2412_CLKDIVN_UARTDIV_SHIFT;
337 static struct clk clk_uart = {
340 .get_rate = s3c2412_getrate_uart,
341 .set_rate = s3c2412_setrate_uart,
342 .set_parent = s3c2412_setparent_uart,
343 .round_rate = s3c2412_roundrate_clksrc,
347 static int s3c2412_setparent_i2s(
struct clk *clk,
struct clk *parent)
349 unsigned long clksrc =
__raw_readl(S3C2412_CLKSRC);
351 if (parent == &clk_erefclk)
352 clksrc &= ~S3C2412_CLKSRC_I2SCLK_MPLL;
354 clksrc |= S3C2412_CLKSRC_I2SCLK_MPLL;
364 static unsigned long s3c2412_getrate_i2s(
struct clk *clk)
369 div &= S3C2412_CLKDIVN_I2SDIV_MASK;
370 div >>= S3C2412_CLKDIVN_I2SDIV_SHIFT;
372 return parent_rate / (div + 1);
375 static int s3c2412_setrate_i2s(
struct clk *clk,
unsigned long rate)
380 rate = s3c2412_roundrate_clksrc(clk, rate);
382 clkdivn &= ~S3C2412_CLKDIVN_I2SDIV_MASK;
383 clkdivn |= ((parent_rate /
rate) - 1) << S3C2412_CLKDIVN_I2SDIV_SHIFT;
389 static struct clk clk_i2s = {
392 .get_rate = s3c2412_getrate_i2s,
393 .set_rate = s3c2412_setrate_i2s,
394 .set_parent = s3c2412_setparent_i2s,
395 .round_rate = s3c2412_roundrate_clksrc,
399 static int s3c2412_setparent_cam(
struct clk *clk,
struct clk *parent)
401 unsigned long clksrc =
__raw_readl(S3C2412_CLKSRC);
403 if (parent == &clk_usysclk)
404 clksrc &= ~S3C2412_CLKSRC_CAMCLK_HCLK;
405 else if (parent == &clk_h)
406 clksrc |= S3C2412_CLKSRC_CAMCLK_HCLK;
415 static unsigned long s3c2412_getrate_cam(
struct clk *clk)
420 div &= S3C2412_CLKDIVN_CAMDIV_MASK;
421 div >>= S3C2412_CLKDIVN_CAMDIV_SHIFT;
423 return parent_rate / (div + 1);
426 static int s3c2412_setrate_cam(
struct clk *clk,
unsigned long rate)
431 rate = s3c2412_roundrate_clksrc(clk, rate);
433 clkdivn &= ~S3C2412_CLKDIVN_CAMDIV_MASK;
434 clkdivn |= ((parent_rate /
rate) - 1) << S3C2412_CLKDIVN_CAMDIV_SHIFT;
440 static struct clk clk_cam = {
441 .name =
"camif-upll",
443 .get_rate = s3c2412_getrate_cam,
444 .set_rate = s3c2412_setrate_cam,
445 .set_parent = s3c2412_setparent_cam,
446 .round_rate = s3c2412_roundrate_clksrc,
452 static struct clk init_clocks_disable[] = {
456 .enable = s3c2412_clkcon_enable,
457 .ctrlbit = S3C2412_CLKCON_NAND,
461 .enable = s3c2412_clkcon_enable,
462 .ctrlbit = S3C2412_CLKCON_SDI,
466 .enable = s3c2412_clkcon_enable,
467 .ctrlbit = S3C2412_CLKCON_ADC,
471 .enable = s3c2412_clkcon_enable,
472 .ctrlbit = S3C2412_CLKCON_IIC,
476 .enable = s3c2412_clkcon_enable,
477 .ctrlbit = S3C2412_CLKCON_IIS,
481 .enable = s3c2412_clkcon_enable,
482 .ctrlbit = S3C2412_CLKCON_SPI,
486 static struct clk init_clocks[] = {
490 .enable = s3c2412_clkcon_enable,
491 .ctrlbit = S3C2412_CLKCON_DMA0,
495 .enable = s3c2412_clkcon_enable,
496 .ctrlbit = S3C2412_CLKCON_DMA1,
500 .enable = s3c2412_clkcon_enable,
501 .ctrlbit = S3C2412_CLKCON_DMA2,
505 .enable = s3c2412_clkcon_enable,
506 .ctrlbit = S3C2412_CLKCON_DMA3,
510 .enable = s3c2412_clkcon_enable,
511 .ctrlbit = S3C2412_CLKCON_LCDC,
515 .enable = s3c2412_clkcon_enable,
516 .ctrlbit = S3C2412_CLKCON_GPIO,
520 .enable = s3c2412_clkcon_enable,
521 .ctrlbit = S3C2412_CLKCON_USBH,
523 .name =
"usb-device",
525 .enable = s3c2412_clkcon_enable,
526 .ctrlbit = S3C2412_CLKCON_USBD,
530 .enable = s3c2412_clkcon_enable,
531 .ctrlbit = S3C2412_CLKCON_PWMT,
534 .devname =
"s3c2412-uart.0",
536 .enable = s3c2412_clkcon_enable,
537 .ctrlbit = S3C2412_CLKCON_UART0,
540 .devname =
"s3c2412-uart.1",
542 .enable = s3c2412_clkcon_enable,
543 .ctrlbit = S3C2412_CLKCON_UART1,
546 .devname =
"s3c2412-uart.2",
548 .enable = s3c2412_clkcon_enable,
549 .ctrlbit = S3C2412_CLKCON_UART2,
553 .enable = s3c2412_clkcon_enable,
554 .ctrlbit = S3C2412_CLKCON_RTC,
560 .name =
"usb-bus-gadget",
562 .enable = s3c2412_clkcon_enable,
563 .ctrlbit = S3C2412_CLKCON_USB_DEV48,
565 .name =
"usb-bus-host",
567 .enable = s3c2412_clkcon_enable,
568 .ctrlbit = S3C2412_CLKCON_USB_HOST48,
584 .
bit = S3C2412_CLKSRC_USBCLK_HCLK,
585 .src_0 = &clk_urefclk,
589 .
bit = S3C2412_CLKSRC_I2SCLK_MPLL,
590 .src_0 = &clk_erefclk,
594 .
bit = S3C2412_CLKSRC_CAMCLK_HCLK,
595 .src_0 = &clk_usysclk,
599 .bit = S3C2412_CLKSRC_MSYSCLK_MPLL,
600 .src_0 = &clk_mdivclk,
604 .
bit = S3C2412_CLKSRC_UARTCLK_MPLL,
605 .src_0 = &clk_erefclk,
609 .
bit = S3C2412_CLKSRC_USBCLK_HCLK,
610 .src_0 = &clk_usysclk,
615 .
bit = S3C2412_CLKSRC_EREFCLK_EXTCLK,
620 .
bit = S3C2412_CLKSRC_UREFCLK_EXTCLK,
631 static void __init s3c2412_clk_initparents(
void)
633 unsigned long clksrc =
__raw_readl(S3C2412_CLKSRC);
639 for (ptr = 0; ptr <
ARRAY_SIZE(clks_src); ptr++, cip++) {
643 cip->
clk->name, ret);
655 static struct clk *clks[] __initdata = {
662 static struct clk_lookup s3c2412_clk_lookup[] = {
676 clk_upll.enable = s3c2412_upll_enable;
682 s3c2412_clk_initparents();
684 for (ptr = 0; ptr <
ARRAY_SIZE(clks); ptr++) {
716 printk(
"S3C2412: upll %s, %ld.%03ld MHz, usb-bus %ld.%03ld MHz\n",
724 for (ptr = 0; ptr <
ARRAY_SIZE(init_clocks); ptr++, clkp++) {
748 clkp = init_clocks_disable;
749 for (ptr = 0; ptr <
ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
757 s3c2412_clkcon_enable(clkp, 0);