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