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