blob: 71226973eee7c3ebc7d4d3644004d85a52f00451 [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>
Jean Delvare9df013b2008-10-14 17:30:02 +020021#include <linux/i2c.h>
David Brownell6a769ed2008-12-10 17:36:33 -080022#include <linux/i2c/at24.h>
Tony Lindgren9b6553c2006-04-02 17:46:30 +010023#include <linux/input.h>
Paul Walmsley44595982008-03-18 10:04:51 +020024#include <linux/err.h>
25#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010026#include <linux/io.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000027
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/hardware.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000029#include <asm/mach-types.h>
30#include <asm/mach/arch.h>
31#include <asm/mach/map.h>
32#include <asm/mach/flash.h>
33
Russell Kinga09e64f2008-08-05 16:14:15 +010034#include <mach/control.h>
35#include <mach/gpio.h>
36#include <mach/gpioexpander.h>
37#include <mach/mux.h>
38#include <mach/usb.h>
39#include <mach/irda.h>
40#include <mach/board.h>
41#include <mach/common.h>
42#include <mach/keypad.h>
43#include <mach/menelaus.h>
44#include <mach/dma.h>
45#include <mach/gpmc.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000046
Paul Walmsley44595982008-03-18 10:04:51 +020047#define H4_FLASH_CS 0
48#define H4_SMC91X_CS 1
49
Tony Lindgren40662d772009-03-23 18:07:36 -070050#define H4_ETHR_GPIO_IRQ 92
51
Tony Lindgren9b6553c2006-04-02 17:46:30 +010052static unsigned int row_gpios[6] = { 88, 89, 124, 11, 6, 96 };
53static unsigned int col_gpios[7] = { 90, 91, 100, 36, 12, 97, 98 };
54
55static int h4_keymap[] = {
56 KEY(0, 0, KEY_LEFT),
57 KEY(0, 1, KEY_RIGHT),
58 KEY(0, 2, KEY_A),
59 KEY(0, 3, KEY_B),
60 KEY(0, 4, KEY_C),
61 KEY(1, 0, KEY_DOWN),
62 KEY(1, 1, KEY_UP),
63 KEY(1, 2, KEY_E),
64 KEY(1, 3, KEY_F),
65 KEY(1, 4, KEY_G),
66 KEY(2, 0, KEY_ENTER),
67 KEY(2, 1, KEY_I),
68 KEY(2, 2, KEY_J),
69 KEY(2, 3, KEY_K),
70 KEY(2, 4, KEY_3),
71 KEY(3, 0, KEY_M),
72 KEY(3, 1, KEY_N),
73 KEY(3, 2, KEY_O),
74 KEY(3, 3, KEY_P),
75 KEY(3, 4, KEY_Q),
76 KEY(4, 0, KEY_R),
77 KEY(4, 1, KEY_4),
78 KEY(4, 2, KEY_T),
79 KEY(4, 3, KEY_U),
80 KEY(4, 4, KEY_ENTER),
81 KEY(5, 0, KEY_V),
82 KEY(5, 1, KEY_W),
83 KEY(5, 2, KEY_L),
84 KEY(5, 3, KEY_S),
85 KEY(5, 4, KEY_ENTER),
86 0
87};
88
Tony Lindgren1dbae812005-11-10 14:26:51 +000089static struct mtd_partition h4_partitions[] = {
90 /* bootloader (U-Boot, etc) in first sector */
91 {
92 .name = "bootloader",
93 .offset = 0,
94 .size = SZ_128K,
95 .mask_flags = MTD_WRITEABLE, /* force read-only */
96 },
97 /* bootloader params in the next sector */
98 {
99 .name = "params",
100 .offset = MTDPART_OFS_APPEND,
101 .size = SZ_128K,
102 .mask_flags = 0,
103 },
104 /* kernel */
105 {
106 .name = "kernel",
107 .offset = MTDPART_OFS_APPEND,
108 .size = SZ_2M,
109 .mask_flags = 0
110 },
111 /* file system */
112 {
113 .name = "filesystem",
114 .offset = MTDPART_OFS_APPEND,
115 .size = MTDPART_SIZ_FULL,
116 .mask_flags = 0
117 }
118};
119
120static struct flash_platform_data h4_flash_data = {
121 .map_name = "cfi_probe",
122 .width = 2,
123 .parts = h4_partitions,
124 .nr_parts = ARRAY_SIZE(h4_partitions),
125};
126
127static struct resource h4_flash_resource = {
Tony Lindgren1dbae812005-11-10 14:26:51 +0000128 .flags = IORESOURCE_MEM,
129};
130
131static struct platform_device h4_flash_device = {
132 .name = "omapflash",
133 .id = 0,
134 .dev = {
135 .platform_data = &h4_flash_data,
136 },
137 .num_resources = 1,
138 .resource = &h4_flash_resource,
139};
140
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100141/* Select between the IrDA and aGPS module
142 */
143static int h4_select_irda(struct device *dev, int state)
144{
145 unsigned char expa;
146 int err = 0;
147
148 if ((err = read_gpio_expa(&expa, 0x21))) {
149 printk(KERN_ERR "Error reading from I/O expander\n");
150 return err;
151 }
152
153 /* 'P6' enable/disable IRDA_TX and IRDA_RX */
154 if (state & IR_SEL) { /* IrDa */
155 if ((err = write_gpio_expa(expa | 0x01, 0x21))) {
156 printk(KERN_ERR "Error writing to I/O expander\n");
157 return err;
158 }
159 } else {
160 if ((err = write_gpio_expa(expa & ~0x01, 0x21))) {
161 printk(KERN_ERR "Error writing to I/O expander\n");
162 return err;
163 }
164 }
165 return err;
166}
167
Dirk Behme060ebf92007-01-25 16:29:17 -0800168static void set_trans_mode(struct work_struct *work)
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100169{
Dirk Behme060ebf92007-01-25 16:29:17 -0800170 struct omap_irda_config *irda_config =
171 container_of(work, struct omap_irda_config, gpio_expa.work);
172 int mode = irda_config->mode;
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100173 unsigned char expa;
174 int err = 0;
175
176 if ((err = read_gpio_expa(&expa, 0x20)) != 0) {
177 printk(KERN_ERR "Error reading from I/O expander\n");
178 }
179
180 expa &= ~0x01;
181
Dirk Behme060ebf92007-01-25 16:29:17 -0800182 if (!(mode & IR_SIRMODE)) { /* MIR/FIR */
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100183 expa |= 0x01;
184 }
185
186 if ((err = write_gpio_expa(expa, 0x20)) != 0) {
187 printk(KERN_ERR "Error writing to I/O expander\n");
188 }
189}
190
191static int h4_transceiver_mode(struct device *dev, int mode)
192{
193 struct omap_irda_config *irda_config = dev->platform_data;
194
Dirk Behme060ebf92007-01-25 16:29:17 -0800195 irda_config->mode = mode;
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100196 cancel_delayed_work(&irda_config->gpio_expa);
Dirk Behme060ebf92007-01-25 16:29:17 -0800197 PREPARE_DELAYED_WORK(&irda_config->gpio_expa, set_trans_mode);
David Howells6d5aefb2006-12-05 19:36:26 +0000198 schedule_delayed_work(&irda_config->gpio_expa, 0);
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100199
200 return 0;
201}
202
203static struct omap_irda_config h4_irda_data = {
204 .transceiver_cap = IR_SIRMODE | IR_MIRMODE | IR_FIRMODE,
205 .transceiver_mode = h4_transceiver_mode,
206 .select_irda = h4_select_irda,
207 .rx_channel = OMAP24XX_DMA_UART3_RX,
208 .tx_channel = OMAP24XX_DMA_UART3_TX,
209 .dest_start = OMAP_UART3_BASE,
210 .src_start = OMAP_UART3_BASE,
211 .tx_trigger = OMAP24XX_DMA_UART3_TX,
212 .rx_trigger = OMAP24XX_DMA_UART3_RX,
213};
214
215static struct resource h4_irda_resources[] = {
216 [0] = {
217 .start = INT_24XX_UART3_IRQ,
218 .end = INT_24XX_UART3_IRQ,
219 .flags = IORESOURCE_IRQ,
220 },
221};
222
223static struct platform_device h4_irda_device = {
224 .name = "omapirda",
225 .id = -1,
226 .dev = {
227 .platform_data = &h4_irda_data,
228 },
229 .num_resources = 1,
230 .resource = h4_irda_resources,
231};
232
233static struct omap_kp_platform_data h4_kp_data = {
234 .rows = 6,
235 .cols = 7,
236 .keymap = h4_keymap,
Komal Shah4d246072006-09-29 01:59:20 -0700237 .keymapsize = ARRAY_SIZE(h4_keymap),
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100238 .rep = 1,
239 .row_gpios = row_gpios,
240 .col_gpios = col_gpios,
241};
242
243static struct platform_device h4_kp_device = {
244 .name = "omap-keypad",
245 .id = -1,
246 .dev = {
247 .platform_data = &h4_kp_data,
248 },
249};
250
251static struct platform_device h4_lcd_device = {
252 .name = "lcd_h4",
253 .id = -1,
254};
255
Tony Lindgren1dbae812005-11-10 14:26:51 +0000256static struct platform_device *h4_devices[] __initdata = {
Tony Lindgren1dbae812005-11-10 14:26:51 +0000257 &h4_flash_device,
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100258 &h4_irda_device,
259 &h4_kp_device,
260 &h4_lcd_device,
Tony Lindgren1dbae812005-11-10 14:26:51 +0000261};
262
Paul Walmsley44595982008-03-18 10:04:51 +0200263/* 2420 Sysboot setup (2430 is different) */
264static u32 get_sysboot_value(void)
265{
266 return (omap_ctrl_readl(OMAP24XX_CONTROL_STATUS) &
267 (OMAP2_SYSBOOT_5_MASK | OMAP2_SYSBOOT_4_MASK |
268 OMAP2_SYSBOOT_3_MASK | OMAP2_SYSBOOT_2_MASK |
269 OMAP2_SYSBOOT_1_MASK | OMAP2_SYSBOOT_0_MASK));
270}
271
272/* H4-2420's always used muxed mode, H4-2422's always use non-muxed
273 *
274 * Note: OMAP-GIT doesn't correctly do is_cpu_omap2422 and is_cpu_omap2423
275 * correctly. The macro needs to look at production_id not just hawkeye.
276 */
277static u32 is_gpmc_muxed(void)
278{
279 u32 mux;
280 mux = get_sysboot_value();
281 if ((mux & 0xF) == 0xd)
282 return 1; /* NAND config (could be either) */
283 if (mux & 0x2) /* if mux'ed */
284 return 1;
285 else
286 return 0;
287}
288
David Brownellf6049312006-12-06 17:14:03 -0800289static inline void __init h4_init_debug(void)
Tony Lindgren1dbae812005-11-10 14:26:51 +0000290{
Paul Walmsley44595982008-03-18 10:04:51 +0200291 int eth_cs;
292 unsigned long cs_mem_base;
293 unsigned int muxed, rate;
294 struct clk *gpmc_fck;
295
296 eth_cs = H4_SMC91X_CS;
297
298 gpmc_fck = clk_get(NULL, "gpmc_fck"); /* Always on ENABLE_ON_INIT */
299 if (IS_ERR(gpmc_fck)) {
300 WARN_ON(1);
301 return;
302 }
303
304 clk_enable(gpmc_fck);
305 rate = clk_get_rate(gpmc_fck);
306 clk_disable(gpmc_fck);
307 clk_put(gpmc_fck);
308
309 if (is_gpmc_muxed())
310 muxed = 0x200;
311 else
312 muxed = 0;
313
Tony Lindgren1dbae812005-11-10 14:26:51 +0000314 /* Make sure CS1 timings are correct */
Paul Walmsley44595982008-03-18 10:04:51 +0200315 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1,
316 0x00011000 | muxed);
317
318 if (rate >= 160000000) {
319 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
320 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
321 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
322 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
323 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
324 } else if (rate >= 130000000) {
325 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
326 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
327 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
328 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
329 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
330 } else {/* rate = 100000000 */
331 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
332 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
333 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
334 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x031A1F1F);
335 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
336 }
337
338 if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
339 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
340 goto out;
341 }
342
Tony Lindgren1dbae812005-11-10 14:26:51 +0000343 udelay(100);
344
345 omap_cfg_reg(M15_24XX_GPIO92);
Tony Lindgren40662d772009-03-23 18:07:36 -0700346 if (debug_card_init(cs_mem_base, H4_ETHR_GPIO_IRQ) < 0)
David Brownellf6049312006-12-06 17:14:03 -0800347 gpmc_cs_free(eth_cs);
Paul Walmsley44595982008-03-18 10:04:51 +0200348
349out:
350 clk_disable(gpmc_fck);
351 clk_put(gpmc_fck);
352}
353
354static void __init h4_init_flash(void)
355{
356 unsigned long base;
357
358 if (gpmc_cs_request(H4_FLASH_CS, SZ_64M, &base) < 0) {
359 printk("Can't request GPMC CS for flash\n");
360 return;
361 }
362 h4_flash_resource.start = base;
363 h4_flash_resource.end = base + SZ_64M - 1;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000364}
365
366static void __init omap_h4_init_irq(void)
367{
Tony Lindgren18f49ea2006-02-08 22:06:47 +0000368 omap2_init_common_hw();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000369 omap_init_irq();
370 omap_gpio_init();
Paul Walmsley44595982008-03-18 10:04:51 +0200371 h4_init_flash();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000372}
373
374static struct omap_uart_config h4_uart_config __initdata = {
375 .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
376};
377
Tony Lindgren1dbae812005-11-10 14:26:51 +0000378static struct omap_lcd_config h4_lcd_config __initdata = {
Tony Lindgren1dbae812005-11-10 14:26:51 +0000379 .ctrl_name = "internal",
380};
381
382static struct omap_board_config_kernel h4_config[] = {
383 { OMAP_TAG_UART, &h4_uart_config },
Tony Lindgren1dbae812005-11-10 14:26:51 +0000384 { OMAP_TAG_LCD, &h4_lcd_config },
385};
386
David Brownell6a769ed2008-12-10 17:36:33 -0800387static struct at24_platform_data m24c01 = {
388 .byte_len = SZ_1K / 8,
389 .page_size = 16,
390};
391
Jean Delvare9df013b2008-10-14 17:30:02 +0200392static struct i2c_board_info __initdata h4_i2c_board_info[] = {
393 {
394 I2C_BOARD_INFO("isp1301_omap", 0x2d),
395 .irq = OMAP_GPIO_IRQ(125),
396 },
David Brownell6a769ed2008-12-10 17:36:33 -0800397 { /* EEPROM on mainboard */
398 I2C_BOARD_INFO("24c01", 0x52),
399 .platform_data = &m24c01,
400 },
401 { /* EEPROM on cpu card */
402 I2C_BOARD_INFO("24c01", 0x57),
403 .platform_data = &m24c01,
404 },
Jean Delvare9df013b2008-10-14 17:30:02 +0200405};
406
Tony Lindgren1dbae812005-11-10 14:26:51 +0000407static void __init omap_h4_init(void)
408{
409 /*
410 * Make sure the serial ports are muxed on at this point.
411 * You have to mux them off in device drivers later on
412 * if not needed.
413 */
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100414#if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
415 omap_cfg_reg(K15_24XX_UART3_TX);
416 omap_cfg_reg(K14_24XX_UART3_RX);
417#endif
418
419#if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
420 if (omap_has_menelaus()) {
421 row_gpios[5] = 0;
422 col_gpios[2] = 15;
423 col_gpios[6] = 18;
424 }
425#endif
426
Jean Delvare9df013b2008-10-14 17:30:02 +0200427 i2c_register_board_info(1, h4_i2c_board_info,
428 ARRAY_SIZE(h4_i2c_board_info));
429
Tony Lindgren1dbae812005-11-10 14:26:51 +0000430 platform_add_devices(h4_devices, ARRAY_SIZE(h4_devices));
431 omap_board_config = h4_config;
432 omap_board_config_size = ARRAY_SIZE(h4_config);
433 omap_serial_init();
434}
435
436static void __init omap_h4_map_io(void)
437{
Paul Walmsleyc8d2eb82008-05-07 16:55:13 -0700438 omap2_set_globals_242x();
Tony Lindgren18f49ea2006-02-08 22:06:47 +0000439 omap2_map_common_io();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000440}
441
442MACHINE_START(OMAP_H4, "OMAP2420 H4 board")
443 /* Maintainer: Paul Mundt <paul.mundt@nokia.com> */
Tony Lindgren1dbae812005-11-10 14:26:51 +0000444 .phys_io = 0x48000000,
445 .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc,
446 .boot_params = 0x80000100,
447 .map_io = omap_h4_map_io,
448 .init_irq = omap_h4_init_irq,
449 .init_machine = omap_h4_init,
450 .timer = &omap_timer,
451MACHINE_END