2 * linux/arch/arm/plat-omap/common.c
4 * Code common to all OMAP machines.
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.
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/delay.h>
14 #include <linux/console.h>
15 #include <linux/serial.h>
16 #include <linux/tty.h>
17 #include <linux/serial_8250.h>
18 #include <linux/serial_reg.h>
19 #include <linux/clk.h>
22 #include <mach/hardware.h>
23 #include <asm/system.h>
24 #include <asm/pgtable.h>
25 #include <asm/mach/map.h>
26 #include <asm/setup.h>
28 #include <mach/common.h>
29 #include <mach/board.h>
30 #include <mach/control.h>
32 #include <mach/fpga.h>
34 #include <mach/clock.h>
36 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
37 # include "../mach-omap2/sdrc.h"
40 #define NO_LENGTH_CHECK 0xffffffff
42 unsigned char omap_bootloader_tag[512];
43 int omap_bootloader_tag_len;
45 struct omap_board_config_kernel *omap_board_config;
46 int omap_board_config_size;
48 static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
50 struct omap_board_config_kernel *kinfo = NULL;
53 #ifdef CONFIG_OMAP_BOOT_TAG
54 struct omap_board_config_entry *info = NULL;
56 if (omap_bootloader_tag_len > 4)
57 info = (struct omap_board_config_entry *) omap_bootloader_tag;
58 while (info != NULL) {
61 if (info->tag == tag) {
67 if ((info->len & 0x03) != 0) {
68 /* We bail out to avoid an alignment fault */
69 printk(KERN_ERR "OMAP peripheral config: Length (%d) not word-aligned (tag %04x)\n",
70 info->len, info->tag);
73 next = (u8 *) info + sizeof(*info) + info->len;
74 if (next >= omap_bootloader_tag + omap_bootloader_tag_len)
77 info = (struct omap_board_config_entry *) next;
80 /* Check the length as a lame attempt to check for
81 * binary inconsistency. */
82 if (len != NO_LENGTH_CHECK) {
85 len = (len + 3) & ~0x03;
86 if (info->len != len) {
87 printk(KERN_ERR "OMAP peripheral config: Length mismatch with tag %x (want %d, got %d)\n",
97 /* Try to find the config from the board-specific structures
99 for (i = 0; i < omap_board_config_size; i++) {
100 if (omap_board_config[i].tag == tag) {
102 kinfo = &omap_board_config[i];
114 const void *__omap_get_config(u16 tag, size_t len, int nr)
116 return get_config(tag, len, nr, NULL);
118 EXPORT_SYMBOL(__omap_get_config);
120 const void *omap_get_var_config(u16 tag, size_t *len)
122 return get_config(tag, NO_LENGTH_CHECK, 0, len);
124 EXPORT_SYMBOL(omap_get_var_config);
126 static int __init omap_add_serial_console(void)
128 const struct omap_serial_console_config *con_info;
129 const struct omap_uart_config *uart_info;
130 static char speed[11], *opt = NULL;
131 int line, i, uart_idx;
133 uart_info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
134 con_info = omap_get_config(OMAP_TAG_SERIAL_CONSOLE,
135 struct omap_serial_console_config);
136 if (uart_info == NULL || con_info == NULL)
139 if (con_info->console_uart == 0)
142 if (con_info->console_speed) {
143 snprintf(speed, sizeof(speed), "%u", con_info->console_speed);
147 uart_idx = con_info->console_uart - 1;
148 if (uart_idx >= OMAP_MAX_NR_PORTS) {
149 printk(KERN_INFO "Console: external UART#%d. "
150 "Not adding it as console this time.\n",
154 if (!(uart_info->enabled_uarts & (1 << uart_idx))) {
155 printk(KERN_ERR "Console: Selected UART#%d is "
156 "not enabled for this platform\n",
161 for (i = 0; i < uart_idx; i++) {
162 if (uart_info->enabled_uarts & (1 << i))
165 return add_preferred_console("ttyS", line, opt);
167 console_initcall(omap_add_serial_console);
171 * 32KHz clocksource ... always available, on pretty most chips except
172 * OMAP 730 and 1510. Other timers could be used as clocksources, with
173 * higher resolution in free-running counter modes (e.g. 12 MHz xtal),
174 * but systems won't necessarily want to spend resources that way.
177 #define OMAP16XX_TIMER_32K_SYNCHRONIZED 0xfffbc410
179 #if !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX))
181 #include <linux/clocksource.h>
183 #ifdef CONFIG_ARCH_OMAP16XX
184 static cycle_t omap16xx_32k_read(struct clocksource *cs)
186 return omap_readl(OMAP16XX_TIMER_32K_SYNCHRONIZED);
189 #define omap16xx_32k_read NULL
192 #ifdef CONFIG_ARCH_OMAP2420
193 static cycle_t omap2420_32k_read(struct clocksource *cs)
195 return omap_readl(OMAP2420_32KSYNCT_BASE + 0x10);
198 #define omap2420_32k_read NULL
201 #ifdef CONFIG_ARCH_OMAP2430
202 static cycle_t omap2430_32k_read(struct clocksource *cs)
204 return omap_readl(OMAP2430_32KSYNCT_BASE + 0x10);
207 #define omap2430_32k_read NULL
210 #ifdef CONFIG_ARCH_OMAP34XX
211 static cycle_t omap34xx_32k_read(struct clocksource *cs)
213 return omap_readl(OMAP3430_32KSYNCT_BASE + 0x10);
216 #define omap34xx_32k_read NULL
220 * Kernel assumes that sched_clock can be called early but may not have
223 static cycle_t omap_32k_read_dummy(struct clocksource *cs)
228 static struct clocksource clocksource_32k = {
229 .name = "32k_counter",
231 .read = omap_32k_read_dummy,
232 .mask = CLOCKSOURCE_MASK(32),
234 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
238 * Returns current time from boot in nsecs. It's OK for this to wrap
239 * around for now, as it's just a relative time stamp.
241 unsigned long long sched_clock(void)
243 unsigned long long ret;
245 ret = (unsigned long long)clocksource_32k.read(&clocksource_32k);
246 ret = (ret * clocksource_32k.mult_orig) >> clocksource_32k.shift;
250 static int __init omap_init_clocksource_32k(void)
252 static char err[] __initdata = KERN_ERR
253 "%s: can't register clocksource!\n";
255 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
256 struct clk *sync_32k_ick;
258 if (cpu_is_omap16xx())
259 clocksource_32k.read = omap16xx_32k_read;
260 else if (cpu_is_omap2420())
261 clocksource_32k.read = omap2420_32k_read;
262 else if (cpu_is_omap2430())
263 clocksource_32k.read = omap2430_32k_read;
264 else if (cpu_is_omap34xx())
265 clocksource_32k.read = omap34xx_32k_read;
269 sync_32k_ick = clk_get(NULL, "omap_32ksync_ick");
271 clk_enable(sync_32k_ick);
273 clocksource_32k.mult = clocksource_hz2mult(32768,
274 clocksource_32k.shift);
276 if (clocksource_register(&clocksource_32k))
277 printk(err, clocksource_32k.name);
281 arch_initcall(omap_init_clocksource_32k);
283 #endif /* !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX)) */
285 /* Global address base setup code */
287 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
289 static void __init __omap2_set_globals(struct omap_globals *omap2_globals)
291 omap2_set_globals_tap(omap2_globals);
292 omap2_set_globals_sdrc(omap2_globals);
293 omap2_set_globals_control(omap2_globals);
294 omap2_set_globals_prcm(omap2_globals);
299 #if defined(CONFIG_ARCH_OMAP2420)
301 static struct omap_globals omap242x_globals = {
302 .class = OMAP242X_CLASS,
303 .tap = OMAP2_IO_ADDRESS(0x48014000),
304 .sdrc = OMAP2_IO_ADDRESS(OMAP2420_SDRC_BASE),
305 .sms = OMAP2_IO_ADDRESS(OMAP2420_SMS_BASE),
306 .ctrl = OMAP2_IO_ADDRESS(OMAP2420_CTRL_BASE),
307 .prm = OMAP2_IO_ADDRESS(OMAP2420_PRM_BASE),
308 .cm = OMAP2_IO_ADDRESS(OMAP2420_CM_BASE),
311 void __init omap2_set_globals_242x(void)
313 __omap2_set_globals(&omap242x_globals);
317 #if defined(CONFIG_ARCH_OMAP2430)
319 static struct omap_globals omap243x_globals = {
320 .class = OMAP243X_CLASS,
321 .tap = OMAP2_IO_ADDRESS(0x4900a000),
322 .sdrc = OMAP2_IO_ADDRESS(OMAP243X_SDRC_BASE),
323 .sms = OMAP2_IO_ADDRESS(OMAP243X_SMS_BASE),
324 .ctrl = OMAP2_IO_ADDRESS(OMAP243X_CTRL_BASE),
325 .prm = OMAP2_IO_ADDRESS(OMAP2430_PRM_BASE),
326 .cm = OMAP2_IO_ADDRESS(OMAP2430_CM_BASE),
329 void __init omap2_set_globals_243x(void)
331 __omap2_set_globals(&omap243x_globals);
335 #if defined(CONFIG_ARCH_OMAP3430)
337 static struct omap_globals omap343x_globals = {
338 .class = OMAP343X_CLASS,
339 .tap = OMAP2_IO_ADDRESS(0x4830A000),
340 .sdrc = OMAP2_IO_ADDRESS(OMAP343X_SDRC_BASE),
341 .sms = OMAP2_IO_ADDRESS(OMAP343X_SMS_BASE),
342 .ctrl = OMAP2_IO_ADDRESS(OMAP343X_CTRL_BASE),
343 .prm = OMAP2_IO_ADDRESS(OMAP3430_PRM_BASE),
344 .cm = OMAP2_IO_ADDRESS(OMAP3430_CM_BASE),
347 void __init omap2_set_globals_343x(void)
349 __omap2_set_globals(&omap343x_globals);