blob: d4e3b6fc4705fe9335835911a13828ecc5fbfae7 [file] [log] [blame]
Tony Lindgren1dbae812005-11-10 14:26:51 +00001/*
Uwe Zeisbergerf30c2262006-10-03 23:01:26 +02002 * linux/arch/arm/mach-omap2/board-h4.c
Tony Lindgren1dbae812005-11-10 14:26:51 +00003 *
4 * Copyright (C) 2005 Nokia Corporation
5 * Author: Paul Mundt <paul.mundt@nokia.com>
6 *
7 * Modified from mach-omap/omap1/board-generic.c
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/platform_device.h>
17#include <linux/mtd/mtd.h>
18#include <linux/mtd/partitions.h>
19#include <linux/delay.h>
Tony Lindgren9b6553c2006-04-02 17:46:30 +010020#include <linux/workqueue.h>
21#include <linux/input.h>
Paul Walmsley44595982008-03-18 10:04:51 +020022#include <linux/err.h>
23#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010024#include <linux/io.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000025
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/hardware.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000027#include <asm/mach-types.h>
28#include <asm/mach/arch.h>
29#include <asm/mach/map.h>
30#include <asm/mach/flash.h>
31
Russell Kinga09e64f2008-08-05 16:14:15 +010032#include <mach/control.h>
33#include <mach/gpio.h>
34#include <mach/gpioexpander.h>
35#include <mach/mux.h>
36#include <mach/usb.h>
37#include <mach/irda.h>
38#include <mach/board.h>
39#include <mach/common.h>
40#include <mach/keypad.h>
41#include <mach/menelaus.h>
42#include <mach/dma.h>
43#include <mach/gpmc.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000044
Paul Walmsley44595982008-03-18 10:04:51 +020045#define H4_FLASH_CS 0
46#define H4_SMC91X_CS 1
47
Tony Lindgren9b6553c2006-04-02 17:46:30 +010048static unsigned int row_gpios[6] = { 88, 89, 124, 11, 6, 96 };
49static unsigned int col_gpios[7] = { 90, 91, 100, 36, 12, 97, 98 };
50
51static int h4_keymap[] = {
52 KEY(0, 0, KEY_LEFT),
53 KEY(0, 1, KEY_RIGHT),
54 KEY(0, 2, KEY_A),
55 KEY(0, 3, KEY_B),
56 KEY(0, 4, KEY_C),
57 KEY(1, 0, KEY_DOWN),
58 KEY(1, 1, KEY_UP),
59 KEY(1, 2, KEY_E),
60 KEY(1, 3, KEY_F),
61 KEY(1, 4, KEY_G),
62 KEY(2, 0, KEY_ENTER),
63 KEY(2, 1, KEY_I),
64 KEY(2, 2, KEY_J),
65 KEY(2, 3, KEY_K),
66 KEY(2, 4, KEY_3),
67 KEY(3, 0, KEY_M),
68 KEY(3, 1, KEY_N),
69 KEY(3, 2, KEY_O),
70 KEY(3, 3, KEY_P),
71 KEY(3, 4, KEY_Q),
72 KEY(4, 0, KEY_R),
73 KEY(4, 1, KEY_4),
74 KEY(4, 2, KEY_T),
75 KEY(4, 3, KEY_U),
76 KEY(4, 4, KEY_ENTER),
77 KEY(5, 0, KEY_V),
78 KEY(5, 1, KEY_W),
79 KEY(5, 2, KEY_L),
80 KEY(5, 3, KEY_S),
81 KEY(5, 4, KEY_ENTER),
82 0
83};
84
Tony Lindgren1dbae812005-11-10 14:26:51 +000085static struct mtd_partition h4_partitions[] = {
86 /* bootloader (U-Boot, etc) in first sector */
87 {
88 .name = "bootloader",
89 .offset = 0,
90 .size = SZ_128K,
91 .mask_flags = MTD_WRITEABLE, /* force read-only */
92 },
93 /* bootloader params in the next sector */
94 {
95 .name = "params",
96 .offset = MTDPART_OFS_APPEND,
97 .size = SZ_128K,
98 .mask_flags = 0,
99 },
100 /* kernel */
101 {
102 .name = "kernel",
103 .offset = MTDPART_OFS_APPEND,
104 .size = SZ_2M,
105 .mask_flags = 0
106 },
107 /* file system */
108 {
109 .name = "filesystem",
110 .offset = MTDPART_OFS_APPEND,
111 .size = MTDPART_SIZ_FULL,
112 .mask_flags = 0
113 }
114};
115
116static struct flash_platform_data h4_flash_data = {
117 .map_name = "cfi_probe",
118 .width = 2,
119 .parts = h4_partitions,
120 .nr_parts = ARRAY_SIZE(h4_partitions),
121};
122
123static struct resource h4_flash_resource = {
Tony Lindgren1dbae812005-11-10 14:26:51 +0000124 .flags = IORESOURCE_MEM,
125};
126
127static struct platform_device h4_flash_device = {
128 .name = "omapflash",
129 .id = 0,
130 .dev = {
131 .platform_data = &h4_flash_data,
132 },
133 .num_resources = 1,
134 .resource = &h4_flash_resource,
135};
136
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100137/* Select between the IrDA and aGPS module
138 */
139static int h4_select_irda(struct device *dev, int state)
140{
141 unsigned char expa;
142 int err = 0;
143
144 if ((err = read_gpio_expa(&expa, 0x21))) {
145 printk(KERN_ERR "Error reading from I/O expander\n");
146 return err;
147 }
148
149 /* 'P6' enable/disable IRDA_TX and IRDA_RX */
150 if (state & IR_SEL) { /* IrDa */
151 if ((err = write_gpio_expa(expa | 0x01, 0x21))) {
152 printk(KERN_ERR "Error writing to I/O expander\n");
153 return err;
154 }
155 } else {
156 if ((err = write_gpio_expa(expa & ~0x01, 0x21))) {
157 printk(KERN_ERR "Error writing to I/O expander\n");
158 return err;
159 }
160 }
161 return err;
162}
163
Dirk Behme060ebf92007-01-25 16:29:17 -0800164static void set_trans_mode(struct work_struct *work)
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100165{
Dirk Behme060ebf92007-01-25 16:29:17 -0800166 struct omap_irda_config *irda_config =
167 container_of(work, struct omap_irda_config, gpio_expa.work);
168 int mode = irda_config->mode;
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100169 unsigned char expa;
170 int err = 0;
171
172 if ((err = read_gpio_expa(&expa, 0x20)) != 0) {
173 printk(KERN_ERR "Error reading from I/O expander\n");
174 }
175
176 expa &= ~0x01;
177
Dirk Behme060ebf92007-01-25 16:29:17 -0800178 if (!(mode & IR_SIRMODE)) { /* MIR/FIR */
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100179 expa |= 0x01;
180 }
181
182 if ((err = write_gpio_expa(expa, 0x20)) != 0) {
183 printk(KERN_ERR "Error writing to I/O expander\n");
184 }
185}
186
187static int h4_transceiver_mode(struct device *dev, int mode)
188{
189 struct omap_irda_config *irda_config = dev->platform_data;
190
Dirk Behme060ebf92007-01-25 16:29:17 -0800191 irda_config->mode = mode;
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100192 cancel_delayed_work(&irda_config->gpio_expa);
Dirk Behme060ebf92007-01-25 16:29:17 -0800193 PREPARE_DELAYED_WORK(&irda_config->gpio_expa, set_trans_mode);
David Howells6d5aefb2006-12-05 19:36:26 +0000194 schedule_delayed_work(&irda_config->gpio_expa, 0);
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100195
196 return 0;
197}
198
199static struct omap_irda_config h4_irda_data = {
200 .transceiver_cap = IR_SIRMODE | IR_MIRMODE | IR_FIRMODE,
201 .transceiver_mode = h4_transceiver_mode,
202 .select_irda = h4_select_irda,
203 .rx_channel = OMAP24XX_DMA_UART3_RX,
204 .tx_channel = OMAP24XX_DMA_UART3_TX,
205 .dest_start = OMAP_UART3_BASE,
206 .src_start = OMAP_UART3_BASE,
207 .tx_trigger = OMAP24XX_DMA_UART3_TX,
208 .rx_trigger = OMAP24XX_DMA_UART3_RX,
209};
210
211static struct resource h4_irda_resources[] = {
212 [0] = {
213 .start = INT_24XX_UART3_IRQ,
214 .end = INT_24XX_UART3_IRQ,
215 .flags = IORESOURCE_IRQ,
216 },
217};
218
219static struct platform_device h4_irda_device = {
220 .name = "omapirda",
221 .id = -1,
222 .dev = {
223 .platform_data = &h4_irda_data,
224 },
225 .num_resources = 1,
226 .resource = h4_irda_resources,
227};
228
229static struct omap_kp_platform_data h4_kp_data = {
230 .rows = 6,
231 .cols = 7,
232 .keymap = h4_keymap,
Komal Shah4d246072006-09-29 01:59:20 -0700233 .keymapsize = ARRAY_SIZE(h4_keymap),
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100234 .rep = 1,
235 .row_gpios = row_gpios,
236 .col_gpios = col_gpios,
237};
238
239static struct platform_device h4_kp_device = {
240 .name = "omap-keypad",
241 .id = -1,
242 .dev = {
243 .platform_data = &h4_kp_data,
244 },
245};
246
247static struct platform_device h4_lcd_device = {
248 .name = "lcd_h4",
249 .id = -1,
250};
251
Tony Lindgren1dbae812005-11-10 14:26:51 +0000252static struct platform_device *h4_devices[] __initdata = {
Tony Lindgren1dbae812005-11-10 14:26:51 +0000253 &h4_flash_device,
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100254 &h4_irda_device,
255 &h4_kp_device,
256 &h4_lcd_device,
Tony Lindgren1dbae812005-11-10 14:26:51 +0000257};
258
Paul Walmsley44595982008-03-18 10:04:51 +0200259/* 2420 Sysboot setup (2430 is different) */
260static u32 get_sysboot_value(void)
261{
262 return (omap_ctrl_readl(OMAP24XX_CONTROL_STATUS) &
263 (OMAP2_SYSBOOT_5_MASK | OMAP2_SYSBOOT_4_MASK |
264 OMAP2_SYSBOOT_3_MASK | OMAP2_SYSBOOT_2_MASK |
265 OMAP2_SYSBOOT_1_MASK | OMAP2_SYSBOOT_0_MASK));
266}
267
268/* H4-2420's always used muxed mode, H4-2422's always use non-muxed
269 *
270 * Note: OMAP-GIT doesn't correctly do is_cpu_omap2422 and is_cpu_omap2423
271 * correctly. The macro needs to look at production_id not just hawkeye.
272 */
273static u32 is_gpmc_muxed(void)
274{
275 u32 mux;
276 mux = get_sysboot_value();
277 if ((mux & 0xF) == 0xd)
278 return 1; /* NAND config (could be either) */
279 if (mux & 0x2) /* if mux'ed */
280 return 1;
281 else
282 return 0;
283}
284
David Brownellf6049312006-12-06 17:14:03 -0800285static inline void __init h4_init_debug(void)
Tony Lindgren1dbae812005-11-10 14:26:51 +0000286{
Paul Walmsley44595982008-03-18 10:04:51 +0200287 int eth_cs;
288 unsigned long cs_mem_base;
289 unsigned int muxed, rate;
290 struct clk *gpmc_fck;
291
292 eth_cs = H4_SMC91X_CS;
293
294 gpmc_fck = clk_get(NULL, "gpmc_fck"); /* Always on ENABLE_ON_INIT */
295 if (IS_ERR(gpmc_fck)) {
296 WARN_ON(1);
297 return;
298 }
299
300 clk_enable(gpmc_fck);
301 rate = clk_get_rate(gpmc_fck);
302 clk_disable(gpmc_fck);
303 clk_put(gpmc_fck);
304
305 if (is_gpmc_muxed())
306 muxed = 0x200;
307 else
308 muxed = 0;
309
Tony Lindgren1dbae812005-11-10 14:26:51 +0000310 /* Make sure CS1 timings are correct */
Paul Walmsley44595982008-03-18 10:04:51 +0200311 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1,
312 0x00011000 | muxed);
313
314 if (rate >= 160000000) {
315 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
316 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
317 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
318 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
319 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
320 } else if (rate >= 130000000) {
321 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
322 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
323 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
324 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
325 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
326 } else {/* rate = 100000000 */
327 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
328 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
329 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
330 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x031A1F1F);
331 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
332 }
333
334 if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
335 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
336 goto out;
337 }
338
Tony Lindgren1dbae812005-11-10 14:26:51 +0000339 udelay(100);
340
341 omap_cfg_reg(M15_24XX_GPIO92);
David Brownellf6049312006-12-06 17:14:03 -0800342 if (debug_card_init(cs_mem_base, OMAP24XX_ETHR_GPIO_IRQ) < 0)
343 gpmc_cs_free(eth_cs);
Paul Walmsley44595982008-03-18 10:04:51 +0200344
345out:
346 clk_disable(gpmc_fck);
347 clk_put(gpmc_fck);
348}
349
350static void __init h4_init_flash(void)
351{
352 unsigned long base;
353
354 if (gpmc_cs_request(H4_FLASH_CS, SZ_64M, &base) < 0) {
355 printk("Can't request GPMC CS for flash\n");
356 return;
357 }
358 h4_flash_resource.start = base;
359 h4_flash_resource.end = base + SZ_64M - 1;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000360}
361
362static void __init omap_h4_init_irq(void)
363{
Tony Lindgren18f49ea2006-02-08 22:06:47 +0000364 omap2_init_common_hw();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000365 omap_init_irq();
366 omap_gpio_init();
Paul Walmsley44595982008-03-18 10:04:51 +0200367 h4_init_flash();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000368}
369
370static struct omap_uart_config h4_uart_config __initdata = {
371 .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
372};
373
374static struct omap_mmc_config h4_mmc_config __initdata = {
375 .mmc [0] = {
376 .enabled = 1,
377 .wire4 = 1,
378 .wp_pin = -1,
379 .power_pin = -1,
380 .switch_pin = -1,
381 },
382};
383
384static struct omap_lcd_config h4_lcd_config __initdata = {
Tony Lindgren1dbae812005-11-10 14:26:51 +0000385 .ctrl_name = "internal",
386};
387
388static struct omap_board_config_kernel h4_config[] = {
389 { OMAP_TAG_UART, &h4_uart_config },
390 { OMAP_TAG_MMC, &h4_mmc_config },
391 { OMAP_TAG_LCD, &h4_lcd_config },
392};
393
394static void __init omap_h4_init(void)
395{
396 /*
397 * Make sure the serial ports are muxed on at this point.
398 * You have to mux them off in device drivers later on
399 * if not needed.
400 */
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100401#if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
402 omap_cfg_reg(K15_24XX_UART3_TX);
403 omap_cfg_reg(K14_24XX_UART3_RX);
404#endif
405
406#if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
407 if (omap_has_menelaus()) {
408 row_gpios[5] = 0;
409 col_gpios[2] = 15;
410 col_gpios[6] = 18;
411 }
412#endif
413
Tony Lindgren1dbae812005-11-10 14:26:51 +0000414 platform_add_devices(h4_devices, ARRAY_SIZE(h4_devices));
415 omap_board_config = h4_config;
416 omap_board_config_size = ARRAY_SIZE(h4_config);
417 omap_serial_init();
418}
419
420static void __init omap_h4_map_io(void)
421{
Paul Walmsleyc8d2eb82008-05-07 16:55:13 -0700422 omap2_set_globals_242x();
Tony Lindgren18f49ea2006-02-08 22:06:47 +0000423 omap2_map_common_io();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000424}
425
426MACHINE_START(OMAP_H4, "OMAP2420 H4 board")
427 /* Maintainer: Paul Mundt <paul.mundt@nokia.com> */
Tony Lindgren1dbae812005-11-10 14:26:51 +0000428 .phys_io = 0x48000000,
429 .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc,
430 .boot_params = 0x80000100,
431 .map_io = omap_h4_map_io,
432 .init_irq = omap_h4_init_irq,
433 .init_machine = omap_h4_init,
434 .timer = &omap_timer,
435MACHINE_END