vserver 1.9.3
[linux-2.6.git] / arch / arm / mach-s3c2410 / s3c2410.c
1 /* linux/arch/arm/mach-s3c2410/s3c2410.c
2  *
3  * Copyright (c) 2003,2004 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-2004 BJD  Added serial port configuration
17  *     21-Aug-2004 BJD  Added new struct s3c2410_board handler
18 */
19
20 #include <linux/kernel.h>
21 #include <linux/types.h>
22 #include <linux/interrupt.h>
23 #include <linux/list.h>
24 #include <linux/timer.h>
25 #include <linux/init.h>
26 #include <linux/device.h>
27
28 #include <asm/mach/arch.h>
29 #include <asm/mach/map.h>
30 #include <asm/mach/irq.h>
31
32 #include <asm/hardware.h>
33 #include <asm/io.h>
34 #include <asm/irq.h>
35
36 #include <asm/arch/regs-clock.h>
37 #include <asm/arch/regs-serial.h>
38
39 #include "s3c2410.h"
40 #include "cpu.h"
41
42 int s3c2410_clock_tick_rate = 12*1000*1000;  /* current timers at 12MHz */
43
44 /* serial port setup */
45
46 struct s3c2410_uartcfg *s3c2410_uartcfgs;
47
48 /* clock info */
49
50 unsigned long s3c2410_fclk;
51 unsigned long s3c2410_hclk;
52 unsigned long s3c2410_pclk;
53
54 static struct map_desc s3c2410_iodesc[] __initdata = {
55         IODESC_ENT(USBHOST),
56         IODESC_ENT(CLKPWR),
57         IODESC_ENT(LCD),
58         IODESC_ENT(UART),
59         IODESC_ENT(TIMER),
60         IODESC_ENT(ADC),
61         IODESC_ENT(WATCHDOG)
62 };
63
64 static struct resource s3c_uart0_resource[] = {
65         [0] = {
66                 .start = S3C2410_PA_UART0,
67                 .end   = S3C2410_PA_UART0 + 0x3fff,
68                 .flags = IORESOURCE_MEM,
69         },
70         [1] = {
71                 .start = IRQ_S3CUART_RX0,
72                 .end   = IRQ_S3CUART_ERR0,
73                 .flags = IORESOURCE_IRQ,
74         }
75
76 };
77
78 static struct resource s3c_uart1_resource[] = {
79         [0] = {
80                 .start = S3C2410_PA_UART1,
81                 .end   = S3C2410_PA_UART1 + 0x3fff,
82                 .flags = IORESOURCE_MEM,
83         },
84         [1] = {
85                 .start = IRQ_S3CUART_RX1,
86                 .end   = IRQ_S3CUART_ERR1,
87                 .flags = IORESOURCE_IRQ,
88         }
89 };
90
91 static struct resource s3c_uart2_resource[] = {
92         [0] = {
93                 .start = S3C2410_PA_UART2,
94                 .end   = S3C2410_PA_UART2 + 0x3fff,
95                 .flags = IORESOURCE_MEM,
96         },
97         [1] = {
98                 .start = IRQ_S3CUART_RX2,
99                 .end   = IRQ_S3CUART_ERR2,
100                 .flags = IORESOURCE_IRQ,
101         }
102 };
103
104 /* our uart devices */
105
106 static struct platform_device s3c_uart0 = {
107         .name             = "s3c2410-uart",
108         .id               = 0,
109         .num_resources    = ARRAY_SIZE(s3c_uart0_resource),
110         .resource         = s3c_uart0_resource,
111 };
112
113
114 static struct platform_device s3c_uart1 = {
115         .name             = "s3c2410-uart",
116         .id               = 1,
117         .num_resources    = ARRAY_SIZE(s3c_uart1_resource),
118         .resource         = s3c_uart1_resource,
119 };
120
121 static struct platform_device s3c_uart2 = {
122         .name             = "s3c2410-uart",
123         .id               = 2,
124         .num_resources    = ARRAY_SIZE(s3c_uart2_resource),
125         .resource         = s3c_uart2_resource,
126 };
127
128 static struct platform_device *uart_devices[] __initdata = {
129         &s3c_uart0,
130         &s3c_uart1,
131         &s3c_uart2
132 };
133
134 void __init s3c2410_map_io(struct map_desc *mach_desc, int mach_size)
135 {
136         unsigned long tmp;
137
138         /* register our io-tables */
139
140         iotable_init(s3c2410_iodesc, ARRAY_SIZE(s3c2410_iodesc));
141         iotable_init(mach_desc, mach_size);
142
143         printk("machine_initted %p,%d\n", mach_desc, mach_size);
144
145         /* now we've got our machine bits initialised, work out what
146          * clocks we've got */
147
148         s3c2410_fclk = s3c2410_get_pll(__raw_readl(S3C2410_MPLLCON), 12*MHZ);
149
150         tmp = __raw_readl(S3C2410_CLKDIVN);
151         //printk("tmp=%08x, fclk=%d\n", tmp, s3c2410_fclk);
152
153         /* work out clock scalings */
154
155         s3c2410_hclk = s3c2410_fclk / ((tmp & S3C2410_CLKDIVN_HDIVN) ? 2 : 1);
156         s3c2410_pclk = s3c2410_hclk / ((tmp & S3C2410_CLKDIVN_PDIVN) ? 2 : 1);
157
158         /* print brieft summary of clocks, etc */
159
160         printk("S3C2410: core %ld.%03ld MHz, memory %ld.%03ld MHz, peripheral %ld.%03ld MHz\n",
161                print_mhz(s3c2410_fclk), print_mhz(s3c2410_hclk),
162                print_mhz(s3c2410_pclk));
163 }
164
165 static struct s3c2410_board *board;
166
167 void s3c2410_set_board(struct s3c2410_board *b)
168 {
169         board = b;
170 }
171
172 void s3c2410_init_uarts(struct s3c2410_uartcfg *cfg, int no)
173 {
174         s3c2410_uartcfgs = cfg;
175 }
176
177 int __init s3c2410_init(void)
178 {
179         int ret;
180
181         printk("S3C2410: Initialising architecture\n");
182
183         ret = platform_add_devices(uart_devices, ARRAY_SIZE(uart_devices));
184         if (ret)
185                 return ret;
186
187         if (board != NULL) {
188                 if (board->devices != NULL) {
189                         ret = platform_add_devices(board->devices,
190                                                    board->devices_count);
191
192                         if (ret) {
193                                 printk(KERN_ERR "s3c2410: failed to add board devices (%d)\n", ret);
194                         }
195                 }
196
197                 /* not adding board devices may not be fatal */
198                 ret = 0;
199         }
200
201         return ret;
202 }