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