1 /* linux/arch/arm/mach-s3c2410/s3c2440.c
3 * Copyright (c) 2004-2005 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
6 * Samsung S3C2440 Mobile CPU support
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 * 24-Aug-2004 BJD Start of s3c2440 support
14 * 12-Oct-2004 BJD Moved clock info out to clock.c
15 * 01-Nov-2004 BJD Fixed clock build code
16 * 09-Nov-2004 BJD Added sysdev for power management
17 * 04-Nov-2004 BJD New serial registration
18 * 15-Nov-2004 BJD Rename the i2c device for the s3c2440
19 * 14-Jan-2005 BJD Moved clock init code into seperate function
20 * 14-Jan-2005 BJD Removed un-used clock bits
23 #include <linux/kernel.h>
24 #include <linux/types.h>
25 #include <linux/interrupt.h>
26 #include <linux/list.h>
27 #include <linux/timer.h>
28 #include <linux/init.h>
29 #include <linux/device.h>
30 #include <linux/sysdev.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
34 #include <asm/mach/irq.h>
36 #include <asm/hardware.h>
39 #include <asm/hardware/clock.h>
41 #include <asm/arch/regs-clock.h>
42 #include <asm/arch/regs-serial.h>
43 #include <asm/arch/regs-gpio.h>
44 #include <asm/arch/regs-gpioj.h>
45 #include <asm/arch/regs-dsc.h>
54 static struct map_desc s3c2440_iodesc[] __initdata = {
63 static struct resource s3c_uart0_resource[] = {
65 .start = S3C2410_PA_UART0,
66 .end = S3C2410_PA_UART0 + 0x3fff,
67 .flags = IORESOURCE_MEM,
70 .start = IRQ_S3CUART_RX0,
71 .end = IRQ_S3CUART_ERR0,
72 .flags = IORESOURCE_IRQ,
77 static struct resource s3c_uart1_resource[] = {
79 .start = S3C2410_PA_UART1,
80 .end = S3C2410_PA_UART1 + 0x3fff,
81 .flags = IORESOURCE_MEM,
84 .start = IRQ_S3CUART_RX1,
85 .end = IRQ_S3CUART_ERR1,
86 .flags = IORESOURCE_IRQ,
90 static struct resource s3c_uart2_resource[] = {
92 .start = S3C2410_PA_UART2,
93 .end = S3C2410_PA_UART2 + 0x3fff,
94 .flags = IORESOURCE_MEM,
97 .start = IRQ_S3CUART_RX2,
98 .end = IRQ_S3CUART_ERR2,
99 .flags = IORESOURCE_IRQ,
103 /* our uart devices */
105 static struct platform_device s3c_uart0 = {
106 .name = "s3c2440-uart",
108 .num_resources = ARRAY_SIZE(s3c_uart0_resource),
109 .resource = s3c_uart0_resource,
112 static struct platform_device s3c_uart1 = {
113 .name = "s3c2440-uart",
115 .num_resources = ARRAY_SIZE(s3c_uart1_resource),
116 .resource = s3c_uart1_resource,
119 static struct platform_device s3c_uart2 = {
120 .name = "s3c2440-uart",
122 .num_resources = ARRAY_SIZE(s3c_uart2_resource),
123 .resource = s3c_uart2_resource,
126 static struct platform_device *uart_devices[] __initdata = {
132 /* uart initialisation */
134 static int __initdata s3c2440_uart_count;
136 void __init s3c2440_init_uarts(struct s3c2410_uartcfg *cfg, int no)
138 struct platform_device *platdev;
141 for (uart = 0; uart < no; uart++, cfg++) {
142 platdev = uart_devices[cfg->hwport];
144 s3c24xx_uart_devs[uart] = platdev;
145 platdev->dev.platform_data = cfg;
148 s3c2440_uart_count = uart;
154 struct sleep_save s3c2440_sleep[] = {
155 SAVE_ITEM(S3C2440_DSC0),
156 SAVE_ITEM(S3C2440_DSC1),
157 SAVE_ITEM(S3C2440_GPJDAT),
158 SAVE_ITEM(S3C2440_GPJCON),
159 SAVE_ITEM(S3C2440_GPJUP)
162 static int s3c2440_suspend(struct sys_device *dev, pm_message_t state)
164 s3c2410_pm_do_save(s3c2440_sleep, ARRAY_SIZE(s3c2440_sleep));
168 static int s3c2440_resume(struct sys_device *dev)
170 s3c2410_pm_do_restore(s3c2440_sleep, ARRAY_SIZE(s3c2440_sleep));
175 #define s3c2440_suspend NULL
176 #define s3c2440_resume NULL
179 struct sysdev_class s3c2440_sysclass = {
180 set_kset_name("s3c2440-core"),
181 .suspend = s3c2440_suspend,
182 .resume = s3c2440_resume
185 static struct sys_device s3c2440_sysdev = {
186 .cls = &s3c2440_sysclass,
189 void __init s3c2440_map_io(struct map_desc *mach_desc, int size)
191 /* register our io-tables */
193 iotable_init(s3c2440_iodesc, ARRAY_SIZE(s3c2440_iodesc));
194 iotable_init(mach_desc, size);
196 /* rename any peripherals used differing from the s3c2410 */
198 s3c_device_i2c.name = "s3c2440-i2c";
199 s3c_device_nand.name = "s3c2440-nand";
201 /* change irq for watchdog */
203 s3c_device_wdt.resource[1].start = IRQ_S3C2440_WDT;
204 s3c_device_wdt.resource[1].end = IRQ_S3C2440_WDT;
207 void __init s3c2440_init_clocks(int xtal)
209 unsigned long clkdiv;
210 unsigned long camdiv;
211 unsigned long hclk, fclk, pclk;
214 /* now we've got our machine bits initialised, work out what
215 * clocks we've got */
217 fclk = s3c2410_get_pll(__raw_readl(S3C2410_MPLLCON), xtal) * 2;
219 clkdiv = __raw_readl(S3C2410_CLKDIVN);
220 camdiv = __raw_readl(S3C2440_CAMDIVN);
222 /* work out clock scalings */
224 switch (clkdiv & S3C2440_CLKDIVN_HDIVN_MASK) {
225 case S3C2440_CLKDIVN_HDIVN_1:
229 case S3C2440_CLKDIVN_HDIVN_2:
233 case S3C2440_CLKDIVN_HDIVN_4_8:
234 hdiv = (camdiv & S3C2440_CAMDIVN_HCLK4_HALF) ? 8 : 4;
237 case S3C2440_CLKDIVN_HDIVN_3_6:
238 hdiv = (camdiv & S3C2440_CAMDIVN_HCLK3_HALF) ? 6 : 3;
243 pclk = hclk / ((clkdiv & S3C2440_CLKDIVN_PDIVN)? 2:1);
245 /* print brief summary of clocks, etc */
247 printk("S3C2440: core %ld.%03ld MHz, memory %ld.%03ld MHz, peripheral %ld.%03ld MHz\n",
248 print_mhz(fclk), print_mhz(hclk), print_mhz(pclk));
250 /* initialise the clocks here, to allow other things like the
251 * console to use them, and to add new ones after the initialisation
254 s3c24xx_setup_clocks(xtal, fclk, hclk, pclk);
257 /* need to register class before we actually register the device, and
258 * we also need to ensure that it has been initialised before any of the
259 * drivers even try to use it (even if not on an s3c2440 based system)
260 * as a driver which may support both 2410 and 2440 may try and use it.
263 int __init s3c2440_core_init(void)
265 return sysdev_class_register(&s3c2440_sysclass);
268 core_initcall(s3c2440_core_init);
270 int __init s3c2440_init(void)
274 printk("S3C2440: Initialising architecture\n");
276 ret = sysdev_register(&s3c2440_sysdev);
278 printk(KERN_ERR "failed to register sysdev for s3c2440\n");
280 ret = platform_add_devices(s3c24xx_uart_devs, s3c2440_uart_count);