blob: 6cb20aea7f518b22dbd9b25a6d93cc6ac93fd1ff [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 */
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>
Tony Lindgren92105bb2005-09-07 17:20:26 +010029#include <asm/setup.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010030
31#include <asm/arch/board.h>
32#include <asm/arch/mux.h>
33#include <asm/arch/fpga.h>
34
35#include "clock.h"
36
37#define NO_LENGTH_CHECK 0xffffffff
38
Tony Lindgren92105bb2005-09-07 17:20:26 +010039unsigned char omap_bootloader_tag[512];
40int omap_bootloader_tag_len;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010041
42struct omap_board_config_kernel *omap_board_config;
Tony Lindgren92105bb2005-09-07 17:20:26 +010043int omap_board_config_size;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010044
45static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
46{
47 struct omap_board_config_kernel *kinfo = NULL;
48 int i;
49
50#ifdef CONFIG_OMAP_BOOT_TAG
51 struct omap_board_config_entry *info = NULL;
52
53 if (omap_bootloader_tag_len > 4)
54 info = (struct omap_board_config_entry *) omap_bootloader_tag;
55 while (info != NULL) {
56 u8 *next;
57
58 if (info->tag == tag) {
59 if (skip == 0)
60 break;
61 skip--;
62 }
63
64 if ((info->len & 0x03) != 0) {
65 /* We bail out to avoid an alignment fault */
66 printk(KERN_ERR "OMAP peripheral config: Length (%d) not word-aligned (tag %04x)\n",
67 info->len, info->tag);
68 return NULL;
69 }
70 next = (u8 *) info + sizeof(*info) + info->len;
71 if (next >= omap_bootloader_tag + omap_bootloader_tag_len)
72 info = NULL;
73 else
74 info = (struct omap_board_config_entry *) next;
75 }
76 if (info != NULL) {
77 /* Check the length as a lame attempt to check for
78 * binary inconsistancy. */
79 if (len != NO_LENGTH_CHECK) {
80 /* Word-align len */
81 if (len & 0x03)
82 len = (len + 3) & ~0x03;
83 if (info->len != len) {
84 printk(KERN_ERR "OMAP peripheral config: Length mismatch with tag %x (want %d, got %d)\n",
85 tag, len, info->len);
86 return NULL;
87 }
88 }
89 if (len_out != NULL)
90 *len_out = info->len;
91 return info->data;
92 }
93#endif
94 /* Try to find the config from the board-specific structures
95 * in the kernel. */
96 for (i = 0; i < omap_board_config_size; i++) {
97 if (omap_board_config[i].tag == tag) {
98 kinfo = &omap_board_config[i];
99 break;
100 }
101 }
102 if (kinfo == NULL)
103 return NULL;
104 return kinfo->data;
105}
106
107const void *__omap_get_config(u16 tag, size_t len, int nr)
108{
109 return get_config(tag, len, nr, NULL);
110}
111EXPORT_SYMBOL(__omap_get_config);
112
113const void *omap_get_var_config(u16 tag, size_t *len)
114{
115 return get_config(tag, NO_LENGTH_CHECK, 0, len);
116}
117EXPORT_SYMBOL(omap_get_var_config);
118
119static int __init omap_add_serial_console(void)
120{
121 const struct omap_serial_console_config *info;
122
123 info = omap_get_config(OMAP_TAG_SERIAL_CONSOLE,
124 struct omap_serial_console_config);
125 if (info != NULL && info->console_uart) {
126 static char speed[11], *opt = NULL;
127
128 if (info->console_speed) {
129 snprintf(speed, sizeof(speed), "%u", info->console_speed);
130 opt = speed;
131 }
132 return add_preferred_console("ttyS", info->console_uart - 1, opt);
133 }
134 return 0;
135}
136console_initcall(omap_add_serial_console);