]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/plat-omap/common.c
Merge branch 'omap-fixes'
[linux-2.6-omap-h63xx.git] / arch / arm / plat-omap / common.c
1 /*
2  * linux/arch/arm/plat-omap/common.c
3  *
4  * Code common to all OMAP machines.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/delay.h>
14 #include <linux/pm.h>
15 #include <linux/console.h>
16 #include <linux/serial.h>
17 #include <linux/tty.h>
18 #include <linux/serial_8250.h>
19 #include <linux/serial_reg.h>
20 #include <linux/clk.h>
21 #include <linux/io.h>
22
23 #include <mach/hardware.h>
24 #include <asm/system.h>
25 #include <asm/pgtable.h>
26 #include <asm/mach/map.h>
27 #include <asm/setup.h>
28
29 #include <mach/common.h>
30 #include <mach/board.h>
31 #include <mach/control.h>
32 #include <mach/mux.h>
33 #include <mach/fpga.h>
34
35 #include <mach/clock.h>
36
37 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
38 # include "../mach-omap2/sdrc.h"
39 #endif
40
41 #define NO_LENGTH_CHECK 0xffffffff
42
43 unsigned char omap_bootloader_tag[1024];
44 int omap_bootloader_tag_len;
45
46 struct omap_board_config_kernel *omap_board_config;
47 int omap_board_config_size;
48
49 #ifdef CONFIG_OMAP_BOOT_TAG
50
51 static int __init parse_tag_omap(const struct tag *tag)
52 {
53         u32 size = tag->hdr.size - (sizeof(tag->hdr) >> 2);
54
55         size <<= 2;
56         if (size > sizeof(omap_bootloader_tag))
57                 return -1;
58
59         memcpy(omap_bootloader_tag, tag->u.omap.data, size);
60         omap_bootloader_tag_len = size;
61
62         return 0;
63 }
64
65 __tagtable(ATAG_BOARD, parse_tag_omap);
66
67 #endif
68
69 static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
70 {
71         struct omap_board_config_kernel *kinfo = NULL;
72         int i;
73
74 #ifdef CONFIG_OMAP_BOOT_TAG
75         struct omap_board_config_entry *info = NULL;
76
77         if (omap_bootloader_tag_len > 4)
78                 info = (struct omap_board_config_entry *) omap_bootloader_tag;
79         while (info != NULL) {
80                 u8 *next;
81
82                 if (info->tag == tag) {
83                         if (skip == 0)
84                                 break;
85                         skip--;
86                 }
87
88                 if ((info->len & 0x03) != 0) {
89                         /* We bail out to avoid an alignment fault */
90                         printk(KERN_ERR "OMAP peripheral config: Length (%d) not word-aligned (tag %04x)\n",
91                                info->len, info->tag);
92                         return NULL;
93                 }
94                 next = (u8 *) info + sizeof(*info) + info->len;
95                 if (next >= omap_bootloader_tag + omap_bootloader_tag_len)
96                         info = NULL;
97                 else
98                         info = (struct omap_board_config_entry *) next;
99         }
100         if (info != NULL) {
101                 /* Check the length as a lame attempt to check for
102                  * binary inconsistency. */
103                 if (len != NO_LENGTH_CHECK) {
104                         /* Word-align len */
105                         if (len & 0x03)
106                                 len = (len + 3) & ~0x03;
107                         if (info->len != len) {
108                                 printk(KERN_ERR "OMAP peripheral config: Length mismatch with tag %x (want %d, got %d)\n",
109                                        tag, len, info->len);
110                                 return NULL;
111                         }
112                 }
113                 if (len_out != NULL)
114                         *len_out = info->len;
115                 return info->data;
116         }
117 #endif
118         /* Try to find the config from the board-specific structures
119          * in the kernel. */
120         for (i = 0; i < omap_board_config_size; i++) {
121                 if (omap_board_config[i].tag == tag) {
122                         if (skip == 0) {
123                                 kinfo = &omap_board_config[i];
124                                 break;
125                         } else {
126                                 skip--;
127                         }
128                 }
129         }
130         if (kinfo == NULL)
131                 return NULL;
132         return kinfo->data;
133 }
134
135 const void *__omap_get_config(u16 tag, size_t len, int nr)
136 {
137         return get_config(tag, len, nr, NULL);
138 }
139 EXPORT_SYMBOL(__omap_get_config);
140
141 const void *omap_get_var_config(u16 tag, size_t *len)
142 {
143         return get_config(tag, NO_LENGTH_CHECK, 0, len);
144 }
145 EXPORT_SYMBOL(omap_get_var_config);
146
147 static int __init omap_add_serial_console(void)
148 {
149         const struct omap_serial_console_config *con_info;
150         const struct omap_uart_config *uart_info;
151         static char speed[11], *opt = NULL;
152         int line, i, uart_idx;
153
154         uart_info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
155         con_info = omap_get_config(OMAP_TAG_SERIAL_CONSOLE,
156                                         struct omap_serial_console_config);
157         if (uart_info == NULL || con_info == NULL)
158                 return 0;
159
160         if (con_info->console_uart == 0)
161                 return 0;
162
163         if (con_info->console_speed) {
164                 snprintf(speed, sizeof(speed), "%u", con_info->console_speed);
165                 opt = speed;
166         }
167
168         uart_idx = con_info->console_uart - 1;
169         if (uart_idx >= OMAP_MAX_NR_PORTS) {
170                 printk(KERN_INFO "Console: external UART#%d. "
171                         "Not adding it as console this time.\n",
172                         uart_idx + 1);
173                 return 0;
174         }
175         if (!(uart_info->enabled_uarts & (1 << uart_idx))) {
176                 printk(KERN_ERR "Console: Selected UART#%d is "
177                         "not enabled for this platform\n",
178                         uart_idx + 1);
179                 return -1;
180         }
181         line = 0;
182         for (i = 0; i < uart_idx; i++) {
183                 if (uart_info->enabled_uarts & (1 << i))
184                         line++;
185         }
186         return add_preferred_console("ttyS", line, opt);
187 }
188 console_initcall(omap_add_serial_console);
189
190
191 /*
192  * 32KHz clocksource ... always available, on pretty most chips except
193  * OMAP 730 and 1510.  Other timers could be used as clocksources, with
194  * higher resolution in free-running counter modes (e.g. 12 MHz xtal),
195  * but systems won't necessarily want to spend resources that way.
196  */
197
198 #if defined(CONFIG_ARCH_OMAP16XX)
199 #define TIMER_32K_SYNCHRONIZED          0xfffbc410
200 #elif defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
201 #define TIMER_32K_SYNCHRONIZED          (OMAP2_32KSYNCT_BASE + 0x10)
202 #endif
203
204 #ifdef  TIMER_32K_SYNCHRONIZED
205
206 #include <linux/clocksource.h>
207
208 static cycle_t omap_32k_read(void)
209 {
210         return omap_readl(TIMER_32K_SYNCHRONIZED);
211 }
212
213 static struct clocksource clocksource_32k = {
214         .name           = "32k_counter",
215         .rating         = 250,
216         .read           = omap_32k_read,
217         .mask           = CLOCKSOURCE_MASK(32),
218         .shift          = 10,
219         .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
220 };
221
222 /*
223  * Returns current time from boot in nsecs. It's OK for this to wrap
224  * around for now, as it's just a relative time stamp.
225  */
226 unsigned long long sched_clock(void)
227 {
228         unsigned long long ret;
229
230         ret = (unsigned long long)omap_32k_read();
231         ret = (ret * clocksource_32k.mult_orig) >> clocksource_32k.shift;
232         return ret;
233 }
234
235 static int __init omap_init_clocksource_32k(void)
236 {
237         static char err[] __initdata = KERN_ERR
238                         "%s: can't register clocksource!\n";
239
240         if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
241                 struct clk *sync_32k_ick;
242
243                 sync_32k_ick = clk_get(NULL, "omap_32ksync_ick");
244                 if (sync_32k_ick)
245                         clk_enable(sync_32k_ick);
246
247                 clocksource_32k.mult = clocksource_hz2mult(32768,
248                                             clocksource_32k.shift);
249
250                 if (clocksource_register(&clocksource_32k))
251                         printk(err, clocksource_32k.name);
252         }
253         return 0;
254 }
255 arch_initcall(omap_init_clocksource_32k);
256
257 #endif  /* TIMER_32K_SYNCHRONIZED */
258
259 /* Global address base setup code */
260
261 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
262
263 static struct omap_globals *omap2_globals;
264
265 static void __init __omap2_set_globals(void)
266 {
267         omap2_set_globals_tap(omap2_globals);
268         omap2_set_globals_sdrc(omap2_globals);
269         omap2_set_globals_control(omap2_globals);
270         omap2_set_globals_prcm(omap2_globals);
271 }
272
273 #endif
274
275 #if defined(CONFIG_ARCH_OMAP2420)
276
277 static struct omap_globals omap242x_globals = {
278         .class  = OMAP242X_CLASS,
279         .tap    = OMAP2_IO_ADDRESS(0x48014000),
280         .sdrc   = OMAP2_IO_ADDRESS(OMAP2420_SDRC_BASE),
281         .sms    = OMAP2_IO_ADDRESS(OMAP2420_SMS_BASE),
282         .ctrl   = OMAP2_IO_ADDRESS(OMAP2420_CTRL_BASE),
283         .prm    = OMAP2_IO_ADDRESS(OMAP2420_PRM_BASE),
284         .cm     = OMAP2_IO_ADDRESS(OMAP2420_CM_BASE),
285 };
286
287 void __init omap2_set_globals_242x(void)
288 {
289         omap2_globals = &omap242x_globals;
290         __omap2_set_globals();
291 }
292 #endif
293
294 #if defined(CONFIG_ARCH_OMAP2430)
295
296 static struct omap_globals omap243x_globals = {
297         .class  = OMAP243X_CLASS,
298         .tap    = OMAP2_IO_ADDRESS(0x4900a000),
299         .sdrc   = OMAP2_IO_ADDRESS(OMAP243X_SDRC_BASE),
300         .sms    = OMAP2_IO_ADDRESS(OMAP243X_SMS_BASE),
301         .ctrl   = OMAP2_IO_ADDRESS(OMAP243X_CTRL_BASE),
302         .prm    = OMAP2_IO_ADDRESS(OMAP2430_PRM_BASE),
303         .cm     = OMAP2_IO_ADDRESS(OMAP2430_CM_BASE),
304 };
305
306 void __init omap2_set_globals_243x(void)
307 {
308         omap2_globals = &omap243x_globals;
309         __omap2_set_globals();
310 }
311 #endif
312
313 #if defined(CONFIG_ARCH_OMAP3430)
314
315 static struct omap_globals omap343x_globals = {
316         .class  = OMAP343X_CLASS,
317         .tap    = OMAP2_IO_ADDRESS(0x4830A000),
318         .sdrc   = OMAP2_IO_ADDRESS(OMAP343X_SDRC_BASE),
319         .sms    = OMAP2_IO_ADDRESS(OMAP343X_SMS_BASE),
320         .ctrl   = OMAP2_IO_ADDRESS(OMAP343X_CTRL_BASE),
321         .prm    = OMAP2_IO_ADDRESS(OMAP3430_PRM_BASE),
322         .cm     = OMAP2_IO_ADDRESS(OMAP3430_CM_BASE),
323 };
324
325 void __init omap2_set_globals_343x(void)
326 {
327         omap2_globals = &omap343x_globals;
328         __omap2_set_globals();
329 }
330 #endif
331