Merge with /home/shaggy/git/linus-clean/
[linux-2.6] / arch / arm / plat-omap / common.c
1 /*
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  */
10 #include <linux/config.h>
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/delay.h>
15 #include <linux/pm.h>
16 #include <linux/console.h>
17 #include <linux/serial.h>
18 #include <linux/tty.h>
19 #include <linux/serial_8250.h>
20 #include <linux/serial_reg.h>
21 #include <linux/clk.h>
22
23 #include <asm/hardware.h>
24 #include <asm/system.h>
25 #include <asm/pgtable.h>
26 #include <asm/mach/map.h>
27 #include <asm/io.h>
28 #include <asm/setup.h>
29
30 #include <asm/arch/board.h>
31 #include <asm/arch/mux.h>
32 #include <asm/arch/fpga.h>
33
34 #include <asm/arch/clock.h>
35
36 #define NO_LENGTH_CHECK 0xffffffff
37
38 unsigned char omap_bootloader_tag[512];
39 int omap_bootloader_tag_len;
40
41 struct omap_board_config_kernel *omap_board_config;
42 int omap_board_config_size;
43
44 static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
45 {
46         struct omap_board_config_kernel *kinfo = NULL;
47         int i;
48
49 #ifdef CONFIG_OMAP_BOOT_TAG
50         struct omap_board_config_entry *info = NULL;
51
52         if (omap_bootloader_tag_len > 4)
53                 info = (struct omap_board_config_entry *) omap_bootloader_tag;
54         while (info != NULL) {
55                 u8 *next;
56
57                 if (info->tag == tag) {
58                         if (skip == 0)
59                                 break;
60                         skip--;
61                 }
62
63                 if ((info->len & 0x03) != 0) {
64                         /* We bail out to avoid an alignment fault */
65                         printk(KERN_ERR "OMAP peripheral config: Length (%d) not word-aligned (tag %04x)\n",
66                                info->len, info->tag);
67                         return NULL;
68                 }
69                 next = (u8 *) info + sizeof(*info) + info->len;
70                 if (next >= omap_bootloader_tag + omap_bootloader_tag_len)
71                         info = NULL;
72                 else
73                         info = (struct omap_board_config_entry *) next;
74         }
75         if (info != NULL) {
76                 /* Check the length as a lame attempt to check for
77                  * binary inconsistancy. */
78                 if (len != NO_LENGTH_CHECK) {
79                         /* Word-align len */
80                         if (len & 0x03)
81                                 len = (len + 3) & ~0x03;
82                         if (info->len != len) {
83                                 printk(KERN_ERR "OMAP peripheral config: Length mismatch with tag %x (want %d, got %d)\n",
84                                        tag, len, info->len);
85                                 return NULL;
86                         }
87                 }
88                 if (len_out != NULL)
89                         *len_out = info->len;
90                 return info->data;
91         }
92 #endif
93         /* Try to find the config from the board-specific structures
94          * in the kernel. */
95         for (i = 0; i < omap_board_config_size; i++) {
96                 if (omap_board_config[i].tag == tag) {
97                         kinfo = &omap_board_config[i];
98                         break;
99                 }
100         }
101         if (kinfo == NULL)
102                 return NULL;
103         return kinfo->data;
104 }
105
106 const void *__omap_get_config(u16 tag, size_t len, int nr)
107 {
108         return get_config(tag, len, nr, NULL);
109 }
110 EXPORT_SYMBOL(__omap_get_config);
111
112 const void *omap_get_var_config(u16 tag, size_t *len)
113 {
114         return get_config(tag, NO_LENGTH_CHECK, 0, len);
115 }
116 EXPORT_SYMBOL(omap_get_var_config);
117
118 static int __init omap_add_serial_console(void)
119 {
120         const struct omap_serial_console_config *con_info;
121         const struct omap_uart_config *uart_info;
122         static char speed[11], *opt = NULL;
123         int line, i, uart_idx;
124
125         uart_info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
126         con_info = omap_get_config(OMAP_TAG_SERIAL_CONSOLE,
127                                         struct omap_serial_console_config);
128         if (uart_info == NULL || con_info == NULL)
129                 return 0;
130
131         if (con_info->console_uart == 0)
132                 return 0;
133
134         if (con_info->console_speed) {
135                 snprintf(speed, sizeof(speed), "%u", con_info->console_speed);
136                 opt = speed;
137         }
138
139         uart_idx = con_info->console_uart - 1;
140         if (uart_idx >= OMAP_MAX_NR_PORTS) {
141                 printk(KERN_INFO "Console: external UART#%d. "
142                         "Not adding it as console this time.\n",
143                         uart_idx + 1);
144                 return 0;
145         }
146         if (!(uart_info->enabled_uarts & (1 << uart_idx))) {
147                 printk(KERN_ERR "Console: Selected UART#%d is "
148                         "not enabled for this platform\n",
149                         uart_idx + 1);
150                 return -1;
151         }
152         line = 0;
153         for (i = 0; i < uart_idx; i++) {
154                 if (uart_info->enabled_uarts & (1 << i))
155                         line++;
156         }
157         return add_preferred_console("ttyS", line, opt);
158 }
159 console_initcall(omap_add_serial_console);