ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / arm / mach-s3c2410 / s3c2410.c
1 /* linux/arch/arm/mach-s3c2410/s3c2410.c
2  *
3  * Copyright (c) 2003 Simtec Electronics
4  * Ben Dooks <ben@simtec.co.uk>
5  *
6  * http://www.simtec.co.uk/products/EB2410ITX/
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 version 2 as
10  * published by the Free Software Foundation.
11  *
12  * Modifications:
13  *     16-May-2003 BJD  Created initial version
14  *     16-Aug-2003 BJD  Fixed header files and copyright, added URL
15  *     05-Sep-2003 BJD  Moved to kernel v2.6
16  *     18-Jan-2003 BJD  Added serial port configuration
17 */
18
19 #include <linux/kernel.h>
20 #include <linux/types.h>
21 #include <linux/interrupt.h>
22 #include <linux/list.h>
23 #include <linux/timer.h>
24 #include <linux/init.h>
25 #include <linux/device.h>
26
27 #include <asm/mach/arch.h>
28 #include <asm/mach/map.h>
29 #include <asm/mach/irq.h>
30
31 #include <asm/hardware.h>
32 #include <asm/io.h>
33 #include <asm/irq.h>
34 #include <asm/mach-types.h>
35
36 #include <asm/arch/regs-clock.h>
37 #include <asm/arch/regs-serial.h>
38
39 int s3c2410_clock_tick_rate = 12*1000*1000;  /* current timers at 12MHz */
40
41 /* serial port setup */
42
43 struct s3c2410_uartcfg *s3c2410_uartcfgs;
44
45 /* clock info */
46
47 unsigned long s3c2410_fclk;
48 unsigned long s3c2410_hclk;
49 unsigned long s3c2410_pclk;
50
51 #ifndef MHZ
52 #define MHZ (1000*1000)
53 #endif
54
55 #define print_mhz(m) ((m) / MHZ), ((m / 1000) % 1000)
56
57 #define IODESC_ENT(x) { S3C2410_VA_##x, S3C2410_PA_##x, S3C2410_SZ_##x, MT_DEVICE }
58
59 static struct map_desc s3c2410_iodesc[] __initdata = {
60   IODESC_ENT(IRQ),
61   IODESC_ENT(MEMCTRL),
62   IODESC_ENT(USBHOST),
63   IODESC_ENT(DMA),
64   IODESC_ENT(CLKPWR),
65   IODESC_ENT(LCD),
66   IODESC_ENT(NAND),
67   IODESC_ENT(UART),
68   IODESC_ENT(TIMER),
69   IODESC_ENT(USBDEV),
70   IODESC_ENT(WATCHDOG),
71   IODESC_ENT(IIC),
72   IODESC_ENT(IIS),
73   IODESC_ENT(GPIO),
74   IODESC_ENT(RTC),
75   IODESC_ENT(ADC),
76   IODESC_ENT(SPI),
77   IODESC_ENT(SDI)
78 };
79
80 static struct resource s3c_uart0_resource[] = {
81         [0] = {
82                 .start = S3C2410_PA_UART0,
83                 .end   = S3C2410_PA_UART0 + 0x3fff,
84                 .flags = IORESOURCE_MEM,
85         },
86         [1] = {
87                 .start = IRQ_S3CUART_RX0,
88                 .end   = IRQ_S3CUART_ERR0,
89                 .flags = IORESOURCE_IRQ,
90         }
91
92 };
93
94 static struct resource s3c_uart1_resource[] = {
95         [0] = {
96                 .start = S3C2410_PA_UART1,
97                 .end   = S3C2410_PA_UART1 + 0x3fff,
98                 .flags = IORESOURCE_MEM,
99         },
100         [1] = {
101                 .start = IRQ_S3CUART_RX1,
102                 .end   = IRQ_S3CUART_ERR1,
103                 .flags = IORESOURCE_IRQ,
104         }
105 };
106
107 static struct resource s3c_uart2_resource[] = {
108         [0] = {
109                 .start = S3C2410_PA_UART2,
110                 .end   = S3C2410_PA_UART2 + 0x3fff,
111                 .flags = IORESOURCE_MEM,
112         },
113         [1] = {
114                 .start = IRQ_S3CUART_RX2,
115                 .end   = IRQ_S3CUART_ERR2,
116                 .flags = IORESOURCE_IRQ,
117         }
118 };
119
120 /* our uart devices */
121
122 static struct platform_device s3c_uart0 = {
123         .name             = "s3c2410-uart",
124         .id               = 0,
125         .num_resources    = ARRAY_SIZE(s3c_uart0_resource),
126         .resource         = s3c_uart0_resource,
127 };
128
129
130 static struct platform_device s3c_uart1 = {
131         .name             = "s3c2410-uart",
132         .id               = 1,
133         .num_resources    = ARRAY_SIZE(s3c_uart1_resource),
134         .resource         = s3c_uart1_resource,
135 };
136
137 static struct platform_device s3c_uart2 = {
138         .name             = "s3c2410-uart",
139         .id               = 2,
140         .num_resources    = ARRAY_SIZE(s3c_uart2_resource),
141         .resource         = s3c_uart2_resource,
142 };
143
144 static struct platform_device *uart_devices[] __initdata = {
145         &s3c_uart0,
146         &s3c_uart1,
147         &s3c_uart2
148 };
149
150 void __init s3c2410_map_io(struct map_desc *mach_desc, int size)
151 {
152         unsigned long tmp;
153
154         /* register our io-tables */
155
156         iotable_init(s3c2410_iodesc, ARRAY_SIZE(s3c2410_iodesc));
157         iotable_init(mach_desc, size);
158
159         /* now we've got our machine bits initialised, work out what
160          * clocks we've got */
161
162         s3c2410_fclk = s3c2410_get_pll(__raw_readl(S3C2410_MPLLCON), 12*MHZ);
163
164         tmp = __raw_readl(S3C2410_CLKDIVN);
165         //printk("tmp=%08x, fclk=%d\n", tmp, s3c2410_fclk);
166
167         /* work out clock scalings */
168
169         s3c2410_hclk = s3c2410_fclk / ((tmp & S3C2410_CLKDIVN_HDIVN) ? 2 : 1);
170         s3c2410_pclk = s3c2410_hclk / ((tmp & S3C2410_CLKDIVN_PDIVN) ? 2 : 1);
171
172         /* print brieft summary of clocks, etc */
173
174         printk("S3C2410: core %ld.%03ld MHz, memory %ld.%03ld MHz, peripheral %ld.%03ld MHz\n",
175                print_mhz(s3c2410_fclk), print_mhz(s3c2410_hclk),
176                print_mhz(s3c2410_pclk));
177 }
178
179
180 static int __init s3c2410_init(void)
181 {
182         int ret;
183
184         printk("S3C2410: Initialising architecture\n");
185
186         ret = platform_add_devices(uart_devices, ARRAY_SIZE(uart_devices));
187
188         return ret;
189 }
190
191 arch_initcall(s3c2410_init);