blob: 66738c3854c3f0599557de0eb1db97b799ff7466 [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.
Santosh Shilimkar44169072009-05-28 14:16:04 -07005 * The file is created by Tony Lindgren <tony@atomide.com>
6 *
7 * Copyright (C) 2009 Texas Instruments
8 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01009 *
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.
13 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010014#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>
Russell Kingf8ce2542006-01-07 16:15:52 +000024#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010025#include <linux/io.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010026
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/hardware.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010028#include <asm/system.h>
29#include <asm/pgtable.h>
30#include <asm/mach/map.h>
Tony Lindgren92105bb2005-09-07 17:20:26 +010031#include <asm/setup.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010032
Russell Kinga09e64f2008-08-05 16:14:15 +010033#include <mach/common.h>
34#include <mach/board.h>
35#include <mach/control.h>
36#include <mach/mux.h>
37#include <mach/fpga.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010038
Russell Kinga09e64f2008-08-05 16:14:15 +010039#include <mach/clock.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010040
Paul Walmsley44595982008-03-18 10:04:51 +020041#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
42# include "../mach-omap2/sdrc.h"
43#endif
44
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010045#define NO_LENGTH_CHECK 0xffffffff
46
Tony Lindgren92105bb2005-09-07 17:20:26 +010047unsigned char omap_bootloader_tag[512];
48int omap_bootloader_tag_len;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010049
50struct omap_board_config_kernel *omap_board_config;
Tony Lindgren92105bb2005-09-07 17:20:26 +010051int omap_board_config_size;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010052
53static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
54{
55 struct omap_board_config_kernel *kinfo = NULL;
56 int i;
57
58#ifdef CONFIG_OMAP_BOOT_TAG
59 struct omap_board_config_entry *info = NULL;
60
61 if (omap_bootloader_tag_len > 4)
62 info = (struct omap_board_config_entry *) omap_bootloader_tag;
63 while (info != NULL) {
64 u8 *next;
65
66 if (info->tag == tag) {
67 if (skip == 0)
68 break;
69 skip--;
70 }
71
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;
77 }
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;
83 }
84 if (info != NULL) {
85 /* Check the length as a lame attempt to check for
Simon Arlott6cbdc8c2007-05-11 20:40:30 +010086 * binary inconsistency. */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010087 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;
95 }
96 }
97 if (len_out != NULL)
98 *len_out = info->len;
99 return info->data;
100 }
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) {
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800106 if (skip == 0) {
107 kinfo = &omap_board_config[i];
108 break;
109 } else {
110 skip--;
111 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100112 }
113 }
114 if (kinfo == NULL)
115 return NULL;
116 return kinfo->data;
117}
118
119const void *__omap_get_config(u16 tag, size_t len, int nr)
120{
121 return get_config(tag, len, nr, NULL);
122}
123EXPORT_SYMBOL(__omap_get_config);
124
125const void *omap_get_var_config(u16 tag, size_t *len)
126{
127 return get_config(tag, NO_LENGTH_CHECK, 0, len);
128}
129EXPORT_SYMBOL(omap_get_var_config);
130
131static int __init omap_add_serial_console(void)
132{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000133 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;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100137
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000138 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;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100143
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000144 if (con_info->console_uart == 0)
145 return 0;
146
147 if (con_info->console_speed) {
148 snprintf(speed, sizeof(speed), "%u", con_info->console_speed);
149 opt = speed;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100150 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000151
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;
158 }
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;
164 }
165 line = 0;
166 for (i = 0; i < uart_idx; i++) {
167 if (uart_info->enabled_uarts & (1 << i))
168 line++;
169 }
170 return add_preferred_console("ttyS", line, opt);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100171}
172console_initcall(omap_add_serial_console);
Kevin Hilman075192a2007-03-08 20:32:19 +0100173
174
175/*
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.
180 */
181
Tony Lindgrenbed8b972009-05-25 11:08:33 -0700182#define OMAP16XX_TIMER_32K_SYNCHRONIZED 0xfffbc410
Kevin Hilman075192a2007-03-08 20:32:19 +0100183
Tony Lindgrenbed8b972009-05-25 11:08:33 -0700184#if !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX))
Kevin Hilman075192a2007-03-08 20:32:19 +0100185
186#include <linux/clocksource.h>
187
Tony Lindgrenbed8b972009-05-25 11:08:33 -0700188#ifdef CONFIG_ARCH_OMAP16XX
189static cycle_t omap16xx_32k_read(struct clocksource *cs)
Kevin Hilman075192a2007-03-08 20:32:19 +0100190{
Tony Lindgrenbed8b972009-05-25 11:08:33 -0700191 return omap_readl(OMAP16XX_TIMER_32K_SYNCHRONIZED);
192}
193#else
194#define omap16xx_32k_read NULL
195#endif
196
197#ifdef CONFIG_ARCH_OMAP2420
198static cycle_t omap2420_32k_read(struct clocksource *cs)
199{
200 return omap_readl(OMAP2420_32KSYNCT_BASE + 0x10);
201}
202#else
203#define omap2420_32k_read NULL
204#endif
205
206#ifdef CONFIG_ARCH_OMAP2430
207static cycle_t omap2430_32k_read(struct clocksource *cs)
208{
209 return omap_readl(OMAP2430_32KSYNCT_BASE + 0x10);
210}
211#else
212#define omap2430_32k_read NULL
213#endif
214
215#ifdef CONFIG_ARCH_OMAP34XX
216static cycle_t omap34xx_32k_read(struct clocksource *cs)
217{
218 return omap_readl(OMAP3430_32KSYNCT_BASE + 0x10);
219}
220#else
221#define omap34xx_32k_read NULL
222#endif
223
Santosh Shilimkar44169072009-05-28 14:16:04 -0700224#ifdef CONFIG_ARCH_OMAP4
225static cycle_t omap44xx_32k_read(struct clocksource *cs)
226{
227 return omap_readl(OMAP4430_32KSYNCT_BASE + 0x10);
228}
229#else
230#define omap44xx_32k_read NULL
231#endif
232
Tony Lindgrenbed8b972009-05-25 11:08:33 -0700233/*
234 * Kernel assumes that sched_clock can be called early but may not have
235 * things ready yet.
236 */
237static cycle_t omap_32k_read_dummy(struct clocksource *cs)
238{
239 return 0;
Kevin Hilman075192a2007-03-08 20:32:19 +0100240}
241
242static struct clocksource clocksource_32k = {
243 .name = "32k_counter",
244 .rating = 250,
Tony Lindgrenbed8b972009-05-25 11:08:33 -0700245 .read = omap_32k_read_dummy,
Kevin Hilman075192a2007-03-08 20:32:19 +0100246 .mask = CLOCKSOURCE_MASK(32),
247 .shift = 10,
248 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
249};
250
Kevin Hilmanf258b0c2007-11-12 23:24:03 -0800251/*
Kevin Hilmanf258b0c2007-11-12 23:24:03 -0800252 * 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.
254 */
255unsigned long long sched_clock(void)
256{
Aaro Koskinen80ea3ba2009-03-04 10:07:41 -0800257 unsigned long long ret;
258
Tony Lindgrenbed8b972009-05-25 11:08:33 -0700259 ret = (unsigned long long)clocksource_32k.read(&clocksource_32k);
Aaro Koskinen80ea3ba2009-03-04 10:07:41 -0800260 ret = (ret * clocksource_32k.mult_orig) >> clocksource_32k.shift;
261 return ret;
Kevin Hilmanf258b0c2007-11-12 23:24:03 -0800262}
263
Kevin Hilman075192a2007-03-08 20:32:19 +0100264static int __init omap_init_clocksource_32k(void)
265{
266 static char err[] __initdata = KERN_ERR
267 "%s: can't register clocksource!\n";
268
Paul Walmsley44595982008-03-18 10:04:51 +0200269 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
270 struct clk *sync_32k_ick;
271
Tony Lindgrenbed8b972009-05-25 11:08:33 -0700272 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;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700280 else if (cpu_is_omap44xx())
281 clocksource_32k.read = omap44xx_32k_read;
Tony Lindgrenbed8b972009-05-25 11:08:33 -0700282 else
283 return -ENODEV;
284
Paul Walmsley44595982008-03-18 10:04:51 +0200285 sync_32k_ick = clk_get(NULL, "omap_32ksync_ick");
286 if (sync_32k_ick)
287 clk_enable(sync_32k_ick);
288
Kevin Hilman075192a2007-03-08 20:32:19 +0100289 clocksource_32k.mult = clocksource_hz2mult(32768,
290 clocksource_32k.shift);
291
292 if (clocksource_register(&clocksource_32k))
293 printk(err, clocksource_32k.name);
294 }
295 return 0;
296}
297arch_initcall(omap_init_clocksource_32k);
298
Tony Lindgrenbed8b972009-05-25 11:08:33 -0700299#endif /* !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX)) */
Paul Walmsley44595982008-03-18 10:04:51 +0200300
301/* Global address base setup code */
302
Tony Lindgrena58caad2008-07-03 12:24:44 +0300303#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
304
Santosh Shilimkar00aeeff2009-05-25 11:08:37 -0700305static void __init __omap2_set_globals(struct omap_globals *omap2_globals)
Tony Lindgrena58caad2008-07-03 12:24:44 +0300306{
Tony Lindgren0e564842008-10-06 15:49:16 +0300307 omap2_set_globals_tap(omap2_globals);
Paul Walmsleyf2ab9972009-01-28 12:27:37 -0700308 omap2_set_globals_sdrc(omap2_globals);
Tony Lindgrena58caad2008-07-03 12:24:44 +0300309 omap2_set_globals_control(omap2_globals);
310 omap2_set_globals_prcm(omap2_globals);
311}
312
313#endif
314
Paul Walmsley44595982008-03-18 10:04:51 +0200315#if defined(CONFIG_ARCH_OMAP2420)
Tony Lindgrena58caad2008-07-03 12:24:44 +0300316
317static struct omap_globals omap242x_globals = {
Tony Lindgren0e564842008-10-06 15:49:16 +0300318 .class = OMAP242X_CLASS,
Russell Kinge8a91c92008-09-01 22:07:37 +0100319 .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),
Tony Lindgrena58caad2008-07-03 12:24:44 +0300325};
326
Paul Walmsley44595982008-03-18 10:04:51 +0200327void __init omap2_set_globals_242x(void)
328{
Santosh Shilimkar00aeeff2009-05-25 11:08:37 -0700329 __omap2_set_globals(&omap242x_globals);
Paul Walmsley44595982008-03-18 10:04:51 +0200330}
331#endif
332
333#if defined(CONFIG_ARCH_OMAP2430)
Tony Lindgrena58caad2008-07-03 12:24:44 +0300334
335static struct omap_globals omap243x_globals = {
Tony Lindgren0e564842008-10-06 15:49:16 +0300336 .class = OMAP243X_CLASS,
Russell Kinge8a91c92008-09-01 22:07:37 +0100337 .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),
Tony Lindgrena58caad2008-07-03 12:24:44 +0300343};
344
Paul Walmsley44595982008-03-18 10:04:51 +0200345void __init omap2_set_globals_243x(void)
346{
Santosh Shilimkar00aeeff2009-05-25 11:08:37 -0700347 __omap2_set_globals(&omap243x_globals);
Paul Walmsley44595982008-03-18 10:04:51 +0200348}
349#endif
350
351#if defined(CONFIG_ARCH_OMAP3430)
Tony Lindgrena58caad2008-07-03 12:24:44 +0300352
353static struct omap_globals omap343x_globals = {
Tony Lindgren0e564842008-10-06 15:49:16 +0300354 .class = OMAP343X_CLASS,
Russell Kinge8a91c92008-09-01 22:07:37 +0100355 .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),
Tony Lindgrena58caad2008-07-03 12:24:44 +0300361};
362
Paul Walmsley44595982008-03-18 10:04:51 +0200363void __init omap2_set_globals_343x(void)
364{
Santosh Shilimkar00aeeff2009-05-25 11:08:37 -0700365 __omap2_set_globals(&omap343x_globals);
Paul Walmsley44595982008-03-18 10:04:51 +0200366}
367#endif
368
Santosh Shilimkar44169072009-05-28 14:16:04 -0700369#if defined(CONFIG_ARCH_OMAP4)
370static 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),
376};
377
378void __init omap2_set_globals_443x(void)
379{
380 omap2_set_globals_tap(&omap4_globals);
381 omap2_set_globals_control(&omap4_globals);
382}
383#endif
384