blob: 70b68ef83201d79343ed4203fcafa3b0f2cef79c [file] [log] [blame]
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001/*
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 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010010#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>
Russell Kingf8ce2542006-01-07 16:15:52 +000020#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010021#include <linux/io.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010022
Russell Kinga09e64f2008-08-05 16:14:15 +010023#include <mach/hardware.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010024#include <asm/system.h>
25#include <asm/pgtable.h>
26#include <asm/mach/map.h>
Tony Lindgren92105bb2005-09-07 17:20:26 +010027#include <asm/setup.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010028
Russell Kinga09e64f2008-08-05 16:14:15 +010029#include <mach/common.h>
30#include <mach/board.h>
31#include <mach/control.h>
32#include <mach/mux.h>
33#include <mach/fpga.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010034
Russell Kinga09e64f2008-08-05 16:14:15 +010035#include <mach/clock.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010036
Paul Walmsley44595982008-03-18 10:04:51 +020037#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
38# include "../mach-omap2/sdrc.h"
39#endif
40
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010041#define NO_LENGTH_CHECK 0xffffffff
42
Tony Lindgren92105bb2005-09-07 17:20:26 +010043unsigned char omap_bootloader_tag[512];
44int omap_bootloader_tag_len;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010045
46struct omap_board_config_kernel *omap_board_config;
Tony Lindgren92105bb2005-09-07 17:20:26 +010047int omap_board_config_size;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010048
49static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
50{
51 struct omap_board_config_kernel *kinfo = NULL;
52 int i;
53
54#ifdef CONFIG_OMAP_BOOT_TAG
55 struct omap_board_config_entry *info = NULL;
56
57 if (omap_bootloader_tag_len > 4)
58 info = (struct omap_board_config_entry *) omap_bootloader_tag;
59 while (info != NULL) {
60 u8 *next;
61
62 if (info->tag == tag) {
63 if (skip == 0)
64 break;
65 skip--;
66 }
67
68 if ((info->len & 0x03) != 0) {
69 /* We bail out to avoid an alignment fault */
70 printk(KERN_ERR "OMAP peripheral config: Length (%d) not word-aligned (tag %04x)\n",
71 info->len, info->tag);
72 return NULL;
73 }
74 next = (u8 *) info + sizeof(*info) + info->len;
75 if (next >= omap_bootloader_tag + omap_bootloader_tag_len)
76 info = NULL;
77 else
78 info = (struct omap_board_config_entry *) next;
79 }
80 if (info != NULL) {
81 /* Check the length as a lame attempt to check for
Simon Arlott6cbdc8c2007-05-11 20:40:30 +010082 * binary inconsistency. */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010083 if (len != NO_LENGTH_CHECK) {
84 /* Word-align len */
85 if (len & 0x03)
86 len = (len + 3) & ~0x03;
87 if (info->len != len) {
88 printk(KERN_ERR "OMAP peripheral config: Length mismatch with tag %x (want %d, got %d)\n",
89 tag, len, info->len);
90 return NULL;
91 }
92 }
93 if (len_out != NULL)
94 *len_out = info->len;
95 return info->data;
96 }
97#endif
98 /* Try to find the config from the board-specific structures
99 * in the kernel. */
100 for (i = 0; i < omap_board_config_size; i++) {
101 if (omap_board_config[i].tag == tag) {
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800102 if (skip == 0) {
103 kinfo = &omap_board_config[i];
104 break;
105 } else {
106 skip--;
107 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100108 }
109 }
110 if (kinfo == NULL)
111 return NULL;
112 return kinfo->data;
113}
114
115const void *__omap_get_config(u16 tag, size_t len, int nr)
116{
117 return get_config(tag, len, nr, NULL);
118}
119EXPORT_SYMBOL(__omap_get_config);
120
121const void *omap_get_var_config(u16 tag, size_t *len)
122{
123 return get_config(tag, NO_LENGTH_CHECK, 0, len);
124}
125EXPORT_SYMBOL(omap_get_var_config);
126
127static int __init omap_add_serial_console(void)
128{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000129 const struct omap_serial_console_config *con_info;
130 const struct omap_uart_config *uart_info;
131 static char speed[11], *opt = NULL;
132 int line, i, uart_idx;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100133
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000134 uart_info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
135 con_info = omap_get_config(OMAP_TAG_SERIAL_CONSOLE,
136 struct omap_serial_console_config);
137 if (uart_info == NULL || con_info == NULL)
138 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100139
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000140 if (con_info->console_uart == 0)
141 return 0;
142
143 if (con_info->console_speed) {
144 snprintf(speed, sizeof(speed), "%u", con_info->console_speed);
145 opt = speed;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100146 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000147
148 uart_idx = con_info->console_uart - 1;
149 if (uart_idx >= OMAP_MAX_NR_PORTS) {
150 printk(KERN_INFO "Console: external UART#%d. "
151 "Not adding it as console this time.\n",
152 uart_idx + 1);
153 return 0;
154 }
155 if (!(uart_info->enabled_uarts & (1 << uart_idx))) {
156 printk(KERN_ERR "Console: Selected UART#%d is "
157 "not enabled for this platform\n",
158 uart_idx + 1);
159 return -1;
160 }
161 line = 0;
162 for (i = 0; i < uart_idx; i++) {
163 if (uart_info->enabled_uarts & (1 << i))
164 line++;
165 }
166 return add_preferred_console("ttyS", line, opt);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100167}
168console_initcall(omap_add_serial_console);
Kevin Hilman075192a2007-03-08 20:32:19 +0100169
170
171/*
172 * 32KHz clocksource ... always available, on pretty most chips except
173 * OMAP 730 and 1510. Other timers could be used as clocksources, with
174 * higher resolution in free-running counter modes (e.g. 12 MHz xtal),
175 * but systems won't necessarily want to spend resources that way.
176 */
177
Tony Lindgrena4ab0d82009-05-25 11:26:41 -0700178#define OMAP16XX_TIMER_32K_SYNCHRONIZED 0xfffbc410
Kevin Hilman075192a2007-03-08 20:32:19 +0100179
Tony Lindgrena4ab0d82009-05-25 11:26:41 -0700180#if !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX))
Kevin Hilman075192a2007-03-08 20:32:19 +0100181
182#include <linux/clocksource.h>
183
Tony Lindgrena4ab0d82009-05-25 11:26:41 -0700184#ifdef CONFIG_ARCH_OMAP16XX
185static cycle_t omap16xx_32k_read(struct clocksource *cs)
Kevin Hilman075192a2007-03-08 20:32:19 +0100186{
Tony Lindgrena4ab0d82009-05-25 11:26:41 -0700187 return omap_readl(OMAP16XX_TIMER_32K_SYNCHRONIZED);
188}
189#else
190#define omap16xx_32k_read NULL
191#endif
192
193#ifdef CONFIG_ARCH_OMAP2420
194static cycle_t omap2420_32k_read(struct clocksource *cs)
195{
196 return omap_readl(OMAP2420_32KSYNCT_BASE + 0x10);
197}
198#else
199#define omap2420_32k_read NULL
200#endif
201
202#ifdef CONFIG_ARCH_OMAP2430
203static cycle_t omap2430_32k_read(struct clocksource *cs)
204{
205 return omap_readl(OMAP2430_32KSYNCT_BASE + 0x10);
206}
207#else
208#define omap2430_32k_read NULL
209#endif
210
211#ifdef CONFIG_ARCH_OMAP34XX
212static cycle_t omap34xx_32k_read(struct clocksource *cs)
213{
214 return omap_readl(OMAP3430_32KSYNCT_BASE + 0x10);
215}
216#else
217#define omap34xx_32k_read NULL
218#endif
219
220/*
221 * Kernel assumes that sched_clock can be called early but may not have
222 * things ready yet.
223 */
224static cycle_t omap_32k_read_dummy(struct clocksource *cs)
225{
226 return 0;
Kevin Hilman075192a2007-03-08 20:32:19 +0100227}
228
229static struct clocksource clocksource_32k = {
230 .name = "32k_counter",
231 .rating = 250,
Tony Lindgrena4ab0d82009-05-25 11:26:41 -0700232 .read = omap_32k_read_dummy,
Kevin Hilman075192a2007-03-08 20:32:19 +0100233 .mask = CLOCKSOURCE_MASK(32),
234 .shift = 10,
235 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
236};
237
Kevin Hilmanf258b0c2007-11-12 23:24:03 -0800238/*
Kevin Hilmanf258b0c2007-11-12 23:24:03 -0800239 * Returns current time from boot in nsecs. It's OK for this to wrap
240 * around for now, as it's just a relative time stamp.
241 */
242unsigned long long sched_clock(void)
243{
Aaro Koskinen80ea3ba2009-03-04 10:07:41 -0800244 unsigned long long ret;
245
Tony Lindgrena4ab0d82009-05-25 11:26:41 -0700246 ret = (unsigned long long)clocksource_32k.read(&clocksource_32k);
Aaro Koskinen80ea3ba2009-03-04 10:07:41 -0800247 ret = (ret * clocksource_32k.mult_orig) >> clocksource_32k.shift;
248 return ret;
Kevin Hilmanf258b0c2007-11-12 23:24:03 -0800249}
250
Kevin Hilman075192a2007-03-08 20:32:19 +0100251static int __init omap_init_clocksource_32k(void)
252{
253 static char err[] __initdata = KERN_ERR
254 "%s: can't register clocksource!\n";
255
Paul Walmsley44595982008-03-18 10:04:51 +0200256 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
257 struct clk *sync_32k_ick;
258
Tony Lindgrena4ab0d82009-05-25 11:26:41 -0700259 if (cpu_is_omap16xx())
260 clocksource_32k.read = omap16xx_32k_read;
261 else if (cpu_is_omap2420())
262 clocksource_32k.read = omap2420_32k_read;
263 else if (cpu_is_omap2430())
264 clocksource_32k.read = omap2430_32k_read;
265 else if (cpu_is_omap34xx())
266 clocksource_32k.read = omap34xx_32k_read;
267 else
268 return -ENODEV;
269
Paul Walmsley44595982008-03-18 10:04:51 +0200270 sync_32k_ick = clk_get(NULL, "omap_32ksync_ick");
271 if (sync_32k_ick)
272 clk_enable(sync_32k_ick);
273
Kevin Hilman075192a2007-03-08 20:32:19 +0100274 clocksource_32k.mult = clocksource_hz2mult(32768,
275 clocksource_32k.shift);
276
277 if (clocksource_register(&clocksource_32k))
278 printk(err, clocksource_32k.name);
279 }
280 return 0;
281}
282arch_initcall(omap_init_clocksource_32k);
283
Tony Lindgrena4ab0d82009-05-25 11:26:41 -0700284#endif /* !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX)) */
Paul Walmsley44595982008-03-18 10:04:51 +0200285
286/* Global address base setup code */
287
Tony Lindgrena58caad2008-07-03 12:24:44 +0300288#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
289
Santosh Shilimkar8f9ccfe2009-05-25 11:26:48 -0700290static void __init __omap2_set_globals(struct omap_globals *omap2_globals)
Tony Lindgrena58caad2008-07-03 12:24:44 +0300291{
Tony Lindgren0e564842008-10-06 15:49:16 +0300292 omap2_set_globals_tap(omap2_globals);
Paul Walmsleyf2ab9972009-01-28 12:27:37 -0700293 omap2_set_globals_sdrc(omap2_globals);
Tony Lindgrena58caad2008-07-03 12:24:44 +0300294 omap2_set_globals_control(omap2_globals);
295 omap2_set_globals_prcm(omap2_globals);
296}
297
298#endif
299
Paul Walmsley44595982008-03-18 10:04:51 +0200300#if defined(CONFIG_ARCH_OMAP2420)
Tony Lindgrena58caad2008-07-03 12:24:44 +0300301
302static struct omap_globals omap242x_globals = {
Tony Lindgren0e564842008-10-06 15:49:16 +0300303 .class = OMAP242X_CLASS,
Russell Kinge8a91c92008-09-01 22:07:37 +0100304 .tap = OMAP2_IO_ADDRESS(0x48014000),
305 .sdrc = OMAP2_IO_ADDRESS(OMAP2420_SDRC_BASE),
306 .sms = OMAP2_IO_ADDRESS(OMAP2420_SMS_BASE),
307 .ctrl = OMAP2_IO_ADDRESS(OMAP2420_CTRL_BASE),
308 .prm = OMAP2_IO_ADDRESS(OMAP2420_PRM_BASE),
309 .cm = OMAP2_IO_ADDRESS(OMAP2420_CM_BASE),
Tony Lindgrena58caad2008-07-03 12:24:44 +0300310};
311
Paul Walmsley44595982008-03-18 10:04:51 +0200312void __init omap2_set_globals_242x(void)
313{
Santosh Shilimkar8f9ccfe2009-05-25 11:26:48 -0700314 __omap2_set_globals(&omap242x_globals);
Paul Walmsley44595982008-03-18 10:04:51 +0200315}
316#endif
317
318#if defined(CONFIG_ARCH_OMAP2430)
Tony Lindgrena58caad2008-07-03 12:24:44 +0300319
320static struct omap_globals omap243x_globals = {
Tony Lindgren0e564842008-10-06 15:49:16 +0300321 .class = OMAP243X_CLASS,
Russell Kinge8a91c92008-09-01 22:07:37 +0100322 .tap = OMAP2_IO_ADDRESS(0x4900a000),
323 .sdrc = OMAP2_IO_ADDRESS(OMAP243X_SDRC_BASE),
324 .sms = OMAP2_IO_ADDRESS(OMAP243X_SMS_BASE),
325 .ctrl = OMAP2_IO_ADDRESS(OMAP243X_CTRL_BASE),
326 .prm = OMAP2_IO_ADDRESS(OMAP2430_PRM_BASE),
327 .cm = OMAP2_IO_ADDRESS(OMAP2430_CM_BASE),
Tony Lindgrena58caad2008-07-03 12:24:44 +0300328};
329
Paul Walmsley44595982008-03-18 10:04:51 +0200330void __init omap2_set_globals_243x(void)
331{
Santosh Shilimkar8f9ccfe2009-05-25 11:26:48 -0700332 __omap2_set_globals(&omap243x_globals);
Paul Walmsley44595982008-03-18 10:04:51 +0200333}
334#endif
335
336#if defined(CONFIG_ARCH_OMAP3430)
Tony Lindgrena58caad2008-07-03 12:24:44 +0300337
338static struct omap_globals omap343x_globals = {
Tony Lindgren0e564842008-10-06 15:49:16 +0300339 .class = OMAP343X_CLASS,
Russell Kinge8a91c92008-09-01 22:07:37 +0100340 .tap = OMAP2_IO_ADDRESS(0x4830A000),
341 .sdrc = OMAP2_IO_ADDRESS(OMAP343X_SDRC_BASE),
342 .sms = OMAP2_IO_ADDRESS(OMAP343X_SMS_BASE),
343 .ctrl = OMAP2_IO_ADDRESS(OMAP343X_CTRL_BASE),
344 .prm = OMAP2_IO_ADDRESS(OMAP3430_PRM_BASE),
345 .cm = OMAP2_IO_ADDRESS(OMAP3430_CM_BASE),
Tony Lindgrena58caad2008-07-03 12:24:44 +0300346};
347
Paul Walmsley44595982008-03-18 10:04:51 +0200348void __init omap2_set_globals_343x(void)
349{
Santosh Shilimkar8f9ccfe2009-05-25 11:26:48 -0700350 __omap2_set_globals(&omap343x_globals);
Paul Walmsley44595982008-03-18 10:04:51 +0200351}
352#endif
353