Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 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 | */ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 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> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 20 | #include <linux/clk.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 21 | |
| 22 | #include <asm/hardware.h> |
| 23 | #include <asm/system.h> |
| 24 | #include <asm/pgtable.h> |
| 25 | #include <asm/mach/map.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 26 | #include <asm/io.h> |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 27 | #include <asm/setup.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 28 | |
| 29 | #include <asm/arch/board.h> |
Paul Walmsley | 4459598 | 2008-03-18 10:04:51 +0200 | [diff] [blame] | 30 | #include <asm/arch/control.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 31 | #include <asm/arch/mux.h> |
| 32 | #include <asm/arch/fpga.h> |
| 33 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 34 | #include <asm/arch/clock.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 35 | |
Paul Walmsley | 4459598 | 2008-03-18 10:04:51 +0200 | [diff] [blame] | 36 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
| 37 | # include "../mach-omap2/sdrc.h" |
| 38 | #endif |
| 39 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 40 | #define NO_LENGTH_CHECK 0xffffffff |
| 41 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 42 | unsigned char omap_bootloader_tag[512]; |
| 43 | int omap_bootloader_tag_len; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 44 | |
| 45 | struct omap_board_config_kernel *omap_board_config; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 46 | int omap_board_config_size; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 47 | |
| 48 | static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out) |
| 49 | { |
| 50 | struct omap_board_config_kernel *kinfo = NULL; |
| 51 | int i; |
| 52 | |
| 53 | #ifdef CONFIG_OMAP_BOOT_TAG |
| 54 | struct omap_board_config_entry *info = NULL; |
| 55 | |
| 56 | if (omap_bootloader_tag_len > 4) |
| 57 | info = (struct omap_board_config_entry *) omap_bootloader_tag; |
| 58 | while (info != NULL) { |
| 59 | u8 *next; |
| 60 | |
| 61 | if (info->tag == tag) { |
| 62 | if (skip == 0) |
| 63 | break; |
| 64 | skip--; |
| 65 | } |
| 66 | |
| 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; |
| 72 | } |
| 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; |
| 78 | } |
| 79 | if (info != NULL) { |
| 80 | /* Check the length as a lame attempt to check for |
Simon Arlott | 6cbdc8c | 2007-05-11 20:40:30 +0100 | [diff] [blame] | 81 | * binary inconsistency. */ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 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; |
| 90 | } |
| 91 | } |
| 92 | if (len_out != NULL) |
| 93 | *len_out = info->len; |
| 94 | return info->data; |
| 95 | } |
| 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) { |
Tony Lindgren | c40fae9 | 2006-12-07 13:58:10 -0800 | [diff] [blame] | 101 | if (skip == 0) { |
| 102 | kinfo = &omap_board_config[i]; |
| 103 | break; |
| 104 | } else { |
| 105 | skip--; |
| 106 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | if (kinfo == NULL) |
| 110 | return NULL; |
| 111 | return kinfo->data; |
| 112 | } |
| 113 | |
| 114 | const void *__omap_get_config(u16 tag, size_t len, int nr) |
| 115 | { |
| 116 | return get_config(tag, len, nr, NULL); |
| 117 | } |
| 118 | EXPORT_SYMBOL(__omap_get_config); |
| 119 | |
| 120 | const void *omap_get_var_config(u16 tag, size_t *len) |
| 121 | { |
| 122 | return get_config(tag, NO_LENGTH_CHECK, 0, len); |
| 123 | } |
| 124 | EXPORT_SYMBOL(omap_get_var_config); |
| 125 | |
| 126 | static int __init omap_add_serial_console(void) |
| 127 | { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 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; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 132 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 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; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 138 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 139 | if (con_info->console_uart == 0) |
| 140 | return 0; |
| 141 | |
| 142 | if (con_info->console_speed) { |
| 143 | snprintf(speed, sizeof(speed), "%u", con_info->console_speed); |
| 144 | opt = speed; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 145 | } |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 146 | |
| 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; |
| 153 | } |
| 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; |
| 159 | } |
| 160 | line = 0; |
| 161 | for (i = 0; i < uart_idx; i++) { |
| 162 | if (uart_info->enabled_uarts & (1 << i)) |
| 163 | line++; |
| 164 | } |
| 165 | return add_preferred_console("ttyS", line, opt); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 166 | } |
| 167 | console_initcall(omap_add_serial_console); |
Kevin Hilman | 075192a | 2007-03-08 20:32:19 +0100 | [diff] [blame] | 168 | |
| 169 | |
| 170 | /* |
| 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. |
| 175 | */ |
| 176 | |
| 177 | #if defined(CONFIG_ARCH_OMAP16XX) |
| 178 | #define TIMER_32K_SYNCHRONIZED 0xfffbc410 |
Paul Walmsley | 4459598 | 2008-03-18 10:04:51 +0200 | [diff] [blame] | 179 | #elif defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
| 180 | #define TIMER_32K_SYNCHRONIZED (OMAP2_32KSYNCT_BASE + 0x10) |
Kevin Hilman | 075192a | 2007-03-08 20:32:19 +0100 | [diff] [blame] | 181 | #endif |
| 182 | |
| 183 | #ifdef TIMER_32K_SYNCHRONIZED |
| 184 | |
| 185 | #include <linux/clocksource.h> |
| 186 | |
| 187 | static cycle_t omap_32k_read(void) |
| 188 | { |
| 189 | return omap_readl(TIMER_32K_SYNCHRONIZED); |
| 190 | } |
| 191 | |
| 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, |
| 199 | }; |
| 200 | |
Kevin Hilman | f258b0c | 2007-11-12 23:24:03 -0800 | [diff] [blame] | 201 | /* |
| 202 | * Rounds down to nearest nsec. |
| 203 | */ |
| 204 | unsigned long long omap_32k_ticks_to_nsecs(unsigned long ticks_32k) |
| 205 | { |
| 206 | return cyc2ns(&clocksource_32k, ticks_32k); |
| 207 | } |
| 208 | |
| 209 | /* |
| 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. |
| 212 | */ |
| 213 | unsigned long long sched_clock(void) |
| 214 | { |
| 215 | return omap_32k_ticks_to_nsecs(omap_32k_read()); |
| 216 | } |
| 217 | |
Kevin Hilman | 075192a | 2007-03-08 20:32:19 +0100 | [diff] [blame] | 218 | static int __init omap_init_clocksource_32k(void) |
| 219 | { |
| 220 | static char err[] __initdata = KERN_ERR |
| 221 | "%s: can't register clocksource!\n"; |
| 222 | |
Paul Walmsley | 4459598 | 2008-03-18 10:04:51 +0200 | [diff] [blame] | 223 | if (cpu_is_omap16xx() || cpu_class_is_omap2()) { |
| 224 | struct clk *sync_32k_ick; |
| 225 | |
| 226 | sync_32k_ick = clk_get(NULL, "omap_32ksync_ick"); |
| 227 | if (sync_32k_ick) |
| 228 | clk_enable(sync_32k_ick); |
| 229 | |
Kevin Hilman | 075192a | 2007-03-08 20:32:19 +0100 | [diff] [blame] | 230 | clocksource_32k.mult = clocksource_hz2mult(32768, |
| 231 | clocksource_32k.shift); |
| 232 | |
| 233 | if (clocksource_register(&clocksource_32k)) |
| 234 | printk(err, clocksource_32k.name); |
| 235 | } |
| 236 | return 0; |
| 237 | } |
| 238 | arch_initcall(omap_init_clocksource_32k); |
| 239 | |
| 240 | #endif /* TIMER_32K_SYNCHRONIZED */ |
Paul Walmsley | 4459598 | 2008-03-18 10:04:51 +0200 | [diff] [blame] | 241 | |
| 242 | /* Global address base setup code */ |
| 243 | |
| 244 | #if defined(CONFIG_ARCH_OMAP2420) |
| 245 | void __init omap2_set_globals_242x(void) |
| 246 | { |
| 247 | omap2_sdrc_base = OMAP2420_SDRC_BASE; |
| 248 | omap2_sms_base = OMAP2420_SMS_BASE; |
| 249 | omap_ctrl_base_set(OMAP2420_CTRL_BASE); |
| 250 | } |
| 251 | #endif |
| 252 | |
| 253 | #if defined(CONFIG_ARCH_OMAP2430) |
| 254 | void __init omap2_set_globals_243x(void) |
| 255 | { |
| 256 | omap2_sdrc_base = OMAP243X_SDRC_BASE; |
| 257 | omap2_sms_base = OMAP243X_SMS_BASE; |
| 258 | omap_ctrl_base_set(OMAP243X_CTRL_BASE); |
| 259 | } |
| 260 | #endif |
| 261 | |
| 262 | #if defined(CONFIG_ARCH_OMAP3430) |
| 263 | void __init omap2_set_globals_343x(void) |
| 264 | { |
| 265 | omap2_sdrc_base = OMAP343X_SDRC_BASE; |
| 266 | omap2_sms_base = OMAP343X_SMS_BASE; |
| 267 | omap_ctrl_base_set(OMAP343X_CTRL_BASE); |
| 268 | } |
| 269 | #endif |
| 270 | |