ext3: retry block allocation if new blocks are allocated from system zone
[linux-2.6/mini2440.git] / arch / arm / plat-omap / common.c
blobbd1cef2c3c1485fbef1fe4105d98186249124982
1 /*
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.
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>
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>
29 #include <asm/arch/board.h>
30 #include <asm/arch/control.h>
31 #include <asm/arch/mux.h>
32 #include <asm/arch/fpga.h>
34 #include <asm/arch/clock.h>
36 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
37 # include "../mach-omap2/sdrc.h"
38 #endif
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;
51 int i;
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) {
59 u8 *next;
61 if (info->tag == tag) {
62 if (skip == 0)
63 break;
64 skip--;
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);
71 return NULL;
73 next = (u8 *) info + sizeof(*info) + info->len;
74 if (next >= omap_bootloader_tag + omap_bootloader_tag_len)
75 info = NULL;
76 else
77 info = (struct omap_board_config_entry *) next;
79 if (info != NULL) {
80 /* Check the length as a lame attempt to check for
81 * binary inconsistency. */
82 if (len != NO_LENGTH_CHECK) {
83 /* Word-align len */
84 if (len & 0x03)
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",
88 tag, len, info->len);
89 return NULL;
92 if (len_out != NULL)
93 *len_out = info->len;
94 return info->data;
96 #endif
97 /* Try to find the config from the board-specific structures
98 * in the kernel. */
99 for (i = 0; i < omap_board_config_size; i++) {
100 if (omap_board_config[i].tag == tag) {
101 if (skip == 0) {
102 kinfo = &omap_board_config[i];
103 break;
104 } else {
105 skip--;
109 if (kinfo == NULL)
110 return NULL;
111 return kinfo->data;
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)
137 return 0;
139 if (con_info->console_uart == 0)
140 return 0;
142 if (con_info->console_speed) {
143 snprintf(speed, sizeof(speed), "%u", con_info->console_speed);
144 opt = 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",
151 uart_idx + 1);
152 return 0;
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",
157 uart_idx + 1);
158 return -1;
160 line = 0;
161 for (i = 0; i < uart_idx; i++) {
162 if (uart_info->enabled_uarts & (1 << i))
163 line++;
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 #if defined(CONFIG_ARCH_OMAP16XX)
178 #define TIMER_32K_SYNCHRONIZED 0xfffbc410
179 #elif defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
180 #define TIMER_32K_SYNCHRONIZED (OMAP2_32KSYNCT_BASE + 0x10)
181 #endif
183 #ifdef TIMER_32K_SYNCHRONIZED
185 #include <linux/clocksource.h>
187 static cycle_t omap_32k_read(void)
189 return omap_readl(TIMER_32K_SYNCHRONIZED);
192 static struct clocksource clocksource_32k = {
193 .name = "32k_counter",
194 .rating = 250,
195 .read = omap_32k_read,
196 .mask = CLOCKSOURCE_MASK(32),
197 .shift = 10,
198 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
202 * Rounds down to nearest nsec.
204 unsigned long long omap_32k_ticks_to_nsecs(unsigned long ticks_32k)
206 return cyc2ns(&clocksource_32k, ticks_32k);
210 * Returns current time from boot in nsecs. It's OK for this to wrap
211 * around for now, as it's just a relative time stamp.
213 unsigned long long sched_clock(void)
215 return omap_32k_ticks_to_nsecs(omap_32k_read());
218 static int __init omap_init_clocksource_32k(void)
220 static char err[] __initdata = KERN_ERR
221 "%s: can't register clocksource!\n";
223 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
224 struct clk *sync_32k_ick;
226 sync_32k_ick = clk_get(NULL, "omap_32ksync_ick");
227 if (sync_32k_ick)
228 clk_enable(sync_32k_ick);
230 clocksource_32k.mult = clocksource_hz2mult(32768,
231 clocksource_32k.shift);
233 if (clocksource_register(&clocksource_32k))
234 printk(err, clocksource_32k.name);
236 return 0;
238 arch_initcall(omap_init_clocksource_32k);
240 #endif /* TIMER_32K_SYNCHRONIZED */
242 /* Global address base setup code */
244 #if defined(CONFIG_ARCH_OMAP2420)
245 void __init omap2_set_globals_242x(void)
247 omap2_sdrc_base = OMAP2420_SDRC_BASE;
248 omap2_sms_base = OMAP2420_SMS_BASE;
249 omap_ctrl_base_set(OMAP2420_CTRL_BASE);
251 #endif
253 #if defined(CONFIG_ARCH_OMAP2430)
254 void __init omap2_set_globals_243x(void)
256 omap2_sdrc_base = OMAP243X_SDRC_BASE;
257 omap2_sms_base = OMAP243X_SMS_BASE;
258 omap_ctrl_base_set(OMAP243X_CTRL_BASE);
260 #endif
262 #if defined(CONFIG_ARCH_OMAP3430)
263 void __init omap2_set_globals_343x(void)
265 omap2_sdrc_base = OMAP343X_SDRC_BASE;
266 omap2_sms_base = OMAP343X_SMS_BASE;
267 omap_ctrl_base_set(OMAP343X_CTRL_BASE);
269 #endif