ARM: OMAP4: Add minimal support for omap4
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / arm / plat-omap / common.c
blob66738c3854c3f0599557de0eb1db97b799ff7466
1 /*
2 * linux/arch/arm/plat-omap/common.c
4 * Code common to all OMAP machines.
5 * The file is created by Tony Lindgren <tony@atomide.com>
7 * Copyright (C) 2009 Texas Instruments
8 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
18 #include <linux/pm.h>
19 #include <linux/console.h>
20 #include <linux/serial.h>
21 #include <linux/tty.h>
22 #include <linux/serial_8250.h>
23 #include <linux/serial_reg.h>
24 #include <linux/clk.h>
25 #include <linux/io.h>
27 #include <mach/hardware.h>
28 #include <asm/system.h>
29 #include <asm/pgtable.h>
30 #include <asm/mach/map.h>
31 #include <asm/setup.h>
33 #include <mach/common.h>
34 #include <mach/board.h>
35 #include <mach/control.h>
36 #include <mach/mux.h>
37 #include <mach/fpga.h>
39 #include <mach/clock.h>
41 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
42 # include "../mach-omap2/sdrc.h"
43 #endif
45 #define NO_LENGTH_CHECK 0xffffffff
47 unsigned char omap_bootloader_tag[512];
48 int omap_bootloader_tag_len;
50 struct omap_board_config_kernel *omap_board_config;
51 int omap_board_config_size;
53 static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
55 struct omap_board_config_kernel *kinfo = NULL;
56 int i;
58 #ifdef CONFIG_OMAP_BOOT_TAG
59 struct omap_board_config_entry *info = NULL;
61 if (omap_bootloader_tag_len > 4)
62 info = (struct omap_board_config_entry *) omap_bootloader_tag;
63 while (info != NULL) {
64 u8 *next;
66 if (info->tag == tag) {
67 if (skip == 0)
68 break;
69 skip--;
72 if ((info->len & 0x03) != 0) {
73 /* We bail out to avoid an alignment fault */
74 printk(KERN_ERR "OMAP peripheral config: Length (%d) not word-aligned (tag %04x)\n",
75 info->len, info->tag);
76 return NULL;
78 next = (u8 *) info + sizeof(*info) + info->len;
79 if (next >= omap_bootloader_tag + omap_bootloader_tag_len)
80 info = NULL;
81 else
82 info = (struct omap_board_config_entry *) next;
84 if (info != NULL) {
85 /* Check the length as a lame attempt to check for
86 * binary inconsistency. */
87 if (len != NO_LENGTH_CHECK) {
88 /* Word-align len */
89 if (len & 0x03)
90 len = (len + 3) & ~0x03;
91 if (info->len != len) {
92 printk(KERN_ERR "OMAP peripheral config: Length mismatch with tag %x (want %d, got %d)\n",
93 tag, len, info->len);
94 return NULL;
97 if (len_out != NULL)
98 *len_out = info->len;
99 return info->data;
101 #endif
102 /* Try to find the config from the board-specific structures
103 * in the kernel. */
104 for (i = 0; i < omap_board_config_size; i++) {
105 if (omap_board_config[i].tag == tag) {
106 if (skip == 0) {
107 kinfo = &omap_board_config[i];
108 break;
109 } else {
110 skip--;
114 if (kinfo == NULL)
115 return NULL;
116 return kinfo->data;
119 const void *__omap_get_config(u16 tag, size_t len, int nr)
121 return get_config(tag, len, nr, NULL);
123 EXPORT_SYMBOL(__omap_get_config);
125 const void *omap_get_var_config(u16 tag, size_t *len)
127 return get_config(tag, NO_LENGTH_CHECK, 0, len);
129 EXPORT_SYMBOL(omap_get_var_config);
131 static int __init omap_add_serial_console(void)
133 const struct omap_serial_console_config *con_info;
134 const struct omap_uart_config *uart_info;
135 static char speed[11], *opt = NULL;
136 int line, i, uart_idx;
138 uart_info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
139 con_info = omap_get_config(OMAP_TAG_SERIAL_CONSOLE,
140 struct omap_serial_console_config);
141 if (uart_info == NULL || con_info == NULL)
142 return 0;
144 if (con_info->console_uart == 0)
145 return 0;
147 if (con_info->console_speed) {
148 snprintf(speed, sizeof(speed), "%u", con_info->console_speed);
149 opt = speed;
152 uart_idx = con_info->console_uart - 1;
153 if (uart_idx >= OMAP_MAX_NR_PORTS) {
154 printk(KERN_INFO "Console: external UART#%d. "
155 "Not adding it as console this time.\n",
156 uart_idx + 1);
157 return 0;
159 if (!(uart_info->enabled_uarts & (1 << uart_idx))) {
160 printk(KERN_ERR "Console: Selected UART#%d is "
161 "not enabled for this platform\n",
162 uart_idx + 1);
163 return -1;
165 line = 0;
166 for (i = 0; i < uart_idx; i++) {
167 if (uart_info->enabled_uarts & (1 << i))
168 line++;
170 return add_preferred_console("ttyS", line, opt);
172 console_initcall(omap_add_serial_console);
176 * 32KHz clocksource ... always available, on pretty most chips except
177 * OMAP 730 and 1510. Other timers could be used as clocksources, with
178 * higher resolution in free-running counter modes (e.g. 12 MHz xtal),
179 * but systems won't necessarily want to spend resources that way.
182 #define OMAP16XX_TIMER_32K_SYNCHRONIZED 0xfffbc410
184 #if !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX))
186 #include <linux/clocksource.h>
188 #ifdef CONFIG_ARCH_OMAP16XX
189 static cycle_t omap16xx_32k_read(struct clocksource *cs)
191 return omap_readl(OMAP16XX_TIMER_32K_SYNCHRONIZED);
193 #else
194 #define omap16xx_32k_read NULL
195 #endif
197 #ifdef CONFIG_ARCH_OMAP2420
198 static cycle_t omap2420_32k_read(struct clocksource *cs)
200 return omap_readl(OMAP2420_32KSYNCT_BASE + 0x10);
202 #else
203 #define omap2420_32k_read NULL
204 #endif
206 #ifdef CONFIG_ARCH_OMAP2430
207 static cycle_t omap2430_32k_read(struct clocksource *cs)
209 return omap_readl(OMAP2430_32KSYNCT_BASE + 0x10);
211 #else
212 #define omap2430_32k_read NULL
213 #endif
215 #ifdef CONFIG_ARCH_OMAP34XX
216 static cycle_t omap34xx_32k_read(struct clocksource *cs)
218 return omap_readl(OMAP3430_32KSYNCT_BASE + 0x10);
220 #else
221 #define omap34xx_32k_read NULL
222 #endif
224 #ifdef CONFIG_ARCH_OMAP4
225 static cycle_t omap44xx_32k_read(struct clocksource *cs)
227 return omap_readl(OMAP4430_32KSYNCT_BASE + 0x10);
229 #else
230 #define omap44xx_32k_read NULL
231 #endif
234 * Kernel assumes that sched_clock can be called early but may not have
235 * things ready yet.
237 static cycle_t omap_32k_read_dummy(struct clocksource *cs)
239 return 0;
242 static struct clocksource clocksource_32k = {
243 .name = "32k_counter",
244 .rating = 250,
245 .read = omap_32k_read_dummy,
246 .mask = CLOCKSOURCE_MASK(32),
247 .shift = 10,
248 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
252 * Returns current time from boot in nsecs. It's OK for this to wrap
253 * around for now, as it's just a relative time stamp.
255 unsigned long long sched_clock(void)
257 unsigned long long ret;
259 ret = (unsigned long long)clocksource_32k.read(&clocksource_32k);
260 ret = (ret * clocksource_32k.mult_orig) >> clocksource_32k.shift;
261 return ret;
264 static int __init omap_init_clocksource_32k(void)
266 static char err[] __initdata = KERN_ERR
267 "%s: can't register clocksource!\n";
269 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
270 struct clk *sync_32k_ick;
272 if (cpu_is_omap16xx())
273 clocksource_32k.read = omap16xx_32k_read;
274 else if (cpu_is_omap2420())
275 clocksource_32k.read = omap2420_32k_read;
276 else if (cpu_is_omap2430())
277 clocksource_32k.read = omap2430_32k_read;
278 else if (cpu_is_omap34xx())
279 clocksource_32k.read = omap34xx_32k_read;
280 else if (cpu_is_omap44xx())
281 clocksource_32k.read = omap44xx_32k_read;
282 else
283 return -ENODEV;
285 sync_32k_ick = clk_get(NULL, "omap_32ksync_ick");
286 if (sync_32k_ick)
287 clk_enable(sync_32k_ick);
289 clocksource_32k.mult = clocksource_hz2mult(32768,
290 clocksource_32k.shift);
292 if (clocksource_register(&clocksource_32k))
293 printk(err, clocksource_32k.name);
295 return 0;
297 arch_initcall(omap_init_clocksource_32k);
299 #endif /* !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX)) */
301 /* Global address base setup code */
303 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
305 static void __init __omap2_set_globals(struct omap_globals *omap2_globals)
307 omap2_set_globals_tap(omap2_globals);
308 omap2_set_globals_sdrc(omap2_globals);
309 omap2_set_globals_control(omap2_globals);
310 omap2_set_globals_prcm(omap2_globals);
313 #endif
315 #if defined(CONFIG_ARCH_OMAP2420)
317 static struct omap_globals omap242x_globals = {
318 .class = OMAP242X_CLASS,
319 .tap = OMAP2_IO_ADDRESS(0x48014000),
320 .sdrc = OMAP2_IO_ADDRESS(OMAP2420_SDRC_BASE),
321 .sms = OMAP2_IO_ADDRESS(OMAP2420_SMS_BASE),
322 .ctrl = OMAP2_IO_ADDRESS(OMAP2420_CTRL_BASE),
323 .prm = OMAP2_IO_ADDRESS(OMAP2420_PRM_BASE),
324 .cm = OMAP2_IO_ADDRESS(OMAP2420_CM_BASE),
327 void __init omap2_set_globals_242x(void)
329 __omap2_set_globals(&omap242x_globals);
331 #endif
333 #if defined(CONFIG_ARCH_OMAP2430)
335 static struct omap_globals omap243x_globals = {
336 .class = OMAP243X_CLASS,
337 .tap = OMAP2_IO_ADDRESS(0x4900a000),
338 .sdrc = OMAP2_IO_ADDRESS(OMAP243X_SDRC_BASE),
339 .sms = OMAP2_IO_ADDRESS(OMAP243X_SMS_BASE),
340 .ctrl = OMAP2_IO_ADDRESS(OMAP243X_CTRL_BASE),
341 .prm = OMAP2_IO_ADDRESS(OMAP2430_PRM_BASE),
342 .cm = OMAP2_IO_ADDRESS(OMAP2430_CM_BASE),
345 void __init omap2_set_globals_243x(void)
347 __omap2_set_globals(&omap243x_globals);
349 #endif
351 #if defined(CONFIG_ARCH_OMAP3430)
353 static struct omap_globals omap343x_globals = {
354 .class = OMAP343X_CLASS,
355 .tap = OMAP2_IO_ADDRESS(0x4830A000),
356 .sdrc = OMAP2_IO_ADDRESS(OMAP343X_SDRC_BASE),
357 .sms = OMAP2_IO_ADDRESS(OMAP343X_SMS_BASE),
358 .ctrl = OMAP2_IO_ADDRESS(OMAP343X_CTRL_BASE),
359 .prm = OMAP2_IO_ADDRESS(OMAP3430_PRM_BASE),
360 .cm = OMAP2_IO_ADDRESS(OMAP3430_CM_BASE),
363 void __init omap2_set_globals_343x(void)
365 __omap2_set_globals(&omap343x_globals);
367 #endif
369 #if defined(CONFIG_ARCH_OMAP4)
370 static struct omap_globals omap4_globals = {
371 .class = OMAP443X_CLASS,
372 .tap = OMAP2_IO_ADDRESS(0x4830a000),
373 .ctrl = OMAP2_IO_ADDRESS(OMAP443X_CTRL_BASE),
374 .prm = OMAP2_IO_ADDRESS(OMAP4430_PRM_BASE),
375 .cm = OMAP2_IO_ADDRESS(OMAP4430_CM_BASE),
378 void __init omap2_set_globals_443x(void)
380 omap2_set_globals_tap(&omap4_globals);
381 omap2_set_globals_control(&omap4_globals);
383 #endif