blob: 7de0506e1e29729dae45effb0919edb6b9777910 [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 Lindgren9b6553c2006-04-02 17:46:30 +010050static unsigned int row_gpios[6] = { 88, 89, 124, 11, 6, 96 };
51static unsigned int col_gpios[7] = { 90, 91, 100, 36, 12, 97, 98 };
52
53static int h4_keymap[] = {
54 KEY(0, 0, KEY_LEFT),
55 KEY(0, 1, KEY_RIGHT),
56 KEY(0, 2, KEY_A),
57 KEY(0, 3, KEY_B),
58 KEY(0, 4, KEY_C),
59 KEY(1, 0, KEY_DOWN),
60 KEY(1, 1, KEY_UP),
61 KEY(1, 2, KEY_E),
62 KEY(1, 3, KEY_F),
63 KEY(1, 4, KEY_G),
64 KEY(2, 0, KEY_ENTER),
65 KEY(2, 1, KEY_I),
66 KEY(2, 2, KEY_J),
67 KEY(2, 3, KEY_K),
68 KEY(2, 4, KEY_3),
69 KEY(3, 0, KEY_M),
70 KEY(3, 1, KEY_N),
71 KEY(3, 2, KEY_O),
72 KEY(3, 3, KEY_P),
73 KEY(3, 4, KEY_Q),
74 KEY(4, 0, KEY_R),
75 KEY(4, 1, KEY_4),
76 KEY(4, 2, KEY_T),
77 KEY(4, 3, KEY_U),
78 KEY(4, 4, KEY_ENTER),
79 KEY(5, 0, KEY_V),
80 KEY(5, 1, KEY_W),
81 KEY(5, 2, KEY_L),
82 KEY(5, 3, KEY_S),
83 KEY(5, 4, KEY_ENTER),
84 0
85};
86
Tony Lindgren1dbae812005-11-10 14:26:51 +000087static struct mtd_partition h4_partitions[] = {
88 /* bootloader (U-Boot, etc) in first sector */
89 {
90 .name = "bootloader",
91 .offset = 0,
92 .size = SZ_128K,
93 .mask_flags = MTD_WRITEABLE, /* force read-only */
94 },
95 /* bootloader params in the next sector */
96 {
97 .name = "params",
98 .offset = MTDPART_OFS_APPEND,
99 .size = SZ_128K,
100 .mask_flags = 0,
101 },
102 /* kernel */
103 {
104 .name = "kernel",
105 .offset = MTDPART_OFS_APPEND,
106 .size = SZ_2M,
107 .mask_flags = 0
108 },
109 /* file system */
110 {
111 .name = "filesystem",
112 .offset = MTDPART_OFS_APPEND,
113 .size = MTDPART_SIZ_FULL,
114 .mask_flags = 0
115 }
116};
117
118static struct flash_platform_data h4_flash_data = {
119 .map_name = "cfi_probe",
120 .width = 2,
121 .parts = h4_partitions,
122 .nr_parts = ARRAY_SIZE(h4_partitions),
123};
124
125static struct resource h4_flash_resource = {
Tony Lindgren1dbae812005-11-10 14:26:51 +0000126 .flags = IORESOURCE_MEM,
127};
128
129static struct platform_device h4_flash_device = {
130 .name = "omapflash",
131 .id = 0,
132 .dev = {
133 .platform_data = &h4_flash_data,
134 },
135 .num_resources = 1,
136 .resource = &h4_flash_resource,
137};
138
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100139/* Select between the IrDA and aGPS module
140 */
141static int h4_select_irda(struct device *dev, int state)
142{
143 unsigned char expa;
144 int err = 0;
145
146 if ((err = read_gpio_expa(&expa, 0x21))) {
147 printk(KERN_ERR "Error reading from I/O expander\n");
148 return err;
149 }
150
151 /* 'P6' enable/disable IRDA_TX and IRDA_RX */
152 if (state & IR_SEL) { /* IrDa */
153 if ((err = write_gpio_expa(expa | 0x01, 0x21))) {
154 printk(KERN_ERR "Error writing to I/O expander\n");
155 return err;
156 }
157 } else {
158 if ((err = write_gpio_expa(expa & ~0x01, 0x21))) {
159 printk(KERN_ERR "Error writing to I/O expander\n");
160 return err;
161 }
162 }
163 return err;
164}
165
Dirk Behme060ebf92007-01-25 16:29:17 -0800166static void set_trans_mode(struct work_struct *work)
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100167{
Dirk Behme060ebf92007-01-25 16:29:17 -0800168 struct omap_irda_config *irda_config =
169 container_of(work, struct omap_irda_config, gpio_expa.work);
170 int mode = irda_config->mode;
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100171 unsigned char expa;
172 int err = 0;
173
174 if ((err = read_gpio_expa(&expa, 0x20)) != 0) {
175 printk(KERN_ERR "Error reading from I/O expander\n");
176 }
177
178 expa &= ~0x01;
179
Dirk Behme060ebf92007-01-25 16:29:17 -0800180 if (!(mode & IR_SIRMODE)) { /* MIR/FIR */
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100181 expa |= 0x01;
182 }
183
184 if ((err = write_gpio_expa(expa, 0x20)) != 0) {
185 printk(KERN_ERR "Error writing to I/O expander\n");
186 }
187}
188
189static int h4_transceiver_mode(struct device *dev, int mode)
190{
191 struct omap_irda_config *irda_config = dev->platform_data;
192
Dirk Behme060ebf92007-01-25 16:29:17 -0800193 irda_config->mode = mode;
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100194 cancel_delayed_work(&irda_config->gpio_expa);
Dirk Behme060ebf92007-01-25 16:29:17 -0800195 PREPARE_DELAYED_WORK(&irda_config->gpio_expa, set_trans_mode);
David Howells6d5aefb2006-12-05 19:36:26 +0000196 schedule_delayed_work(&irda_config->gpio_expa, 0);
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100197
198 return 0;
199}
200
201static struct omap_irda_config h4_irda_data = {
202 .transceiver_cap = IR_SIRMODE | IR_MIRMODE | IR_FIRMODE,
203 .transceiver_mode = h4_transceiver_mode,
204 .select_irda = h4_select_irda,
205 .rx_channel = OMAP24XX_DMA_UART3_RX,
206 .tx_channel = OMAP24XX_DMA_UART3_TX,
207 .dest_start = OMAP_UART3_BASE,
208 .src_start = OMAP_UART3_BASE,
209 .tx_trigger = OMAP24XX_DMA_UART3_TX,
210 .rx_trigger = OMAP24XX_DMA_UART3_RX,
211};
212
213static struct resource h4_irda_resources[] = {
214 [0] = {
215 .start = INT_24XX_UART3_IRQ,
216 .end = INT_24XX_UART3_IRQ,
217 .flags = IORESOURCE_IRQ,
218 },
219};
220
221static struct platform_device h4_irda_device = {
222 .name = "omapirda",
223 .id = -1,
224 .dev = {
225 .platform_data = &h4_irda_data,
226 },
227 .num_resources = 1,
228 .resource = h4_irda_resources,
229};
230
231static struct omap_kp_platform_data h4_kp_data = {
232 .rows = 6,
233 .cols = 7,
234 .keymap = h4_keymap,
Komal Shah4d246072006-09-29 01:59:20 -0700235 .keymapsize = ARRAY_SIZE(h4_keymap),
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100236 .rep = 1,
237 .row_gpios = row_gpios,
238 .col_gpios = col_gpios,
239};
240
241static struct platform_device h4_kp_device = {
242 .name = "omap-keypad",
243 .id = -1,
244 .dev = {
245 .platform_data = &h4_kp_data,
246 },
247};
248
249static struct platform_device h4_lcd_device = {
250 .name = "lcd_h4",
251 .id = -1,
252};
253
Tony Lindgren1dbae812005-11-10 14:26:51 +0000254static struct platform_device *h4_devices[] __initdata = {
Tony Lindgren1dbae812005-11-10 14:26:51 +0000255 &h4_flash_device,
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100256 &h4_irda_device,
257 &h4_kp_device,
258 &h4_lcd_device,
Tony Lindgren1dbae812005-11-10 14:26:51 +0000259};
260
Paul Walmsley44595982008-03-18 10:04:51 +0200261/* 2420 Sysboot setup (2430 is different) */
262static u32 get_sysboot_value(void)
263{
264 return (omap_ctrl_readl(OMAP24XX_CONTROL_STATUS) &
265 (OMAP2_SYSBOOT_5_MASK | OMAP2_SYSBOOT_4_MASK |
266 OMAP2_SYSBOOT_3_MASK | OMAP2_SYSBOOT_2_MASK |
267 OMAP2_SYSBOOT_1_MASK | OMAP2_SYSBOOT_0_MASK));
268}
269
270/* H4-2420's always used muxed mode, H4-2422's always use non-muxed
271 *
272 * Note: OMAP-GIT doesn't correctly do is_cpu_omap2422 and is_cpu_omap2423
273 * correctly. The macro needs to look at production_id not just hawkeye.
274 */
275static u32 is_gpmc_muxed(void)
276{
277 u32 mux;
278 mux = get_sysboot_value();
279 if ((mux & 0xF) == 0xd)
280 return 1; /* NAND config (could be either) */
281 if (mux & 0x2) /* if mux'ed */
282 return 1;
283 else
284 return 0;
285}
286
David Brownellf6049312006-12-06 17:14:03 -0800287static inline void __init h4_init_debug(void)
Tony Lindgren1dbae812005-11-10 14:26:51 +0000288{
Paul Walmsley44595982008-03-18 10:04:51 +0200289 int eth_cs;
290 unsigned long cs_mem_base;
291 unsigned int muxed, rate;
292 struct clk *gpmc_fck;
293
294 eth_cs = H4_SMC91X_CS;
295
296 gpmc_fck = clk_get(NULL, "gpmc_fck"); /* Always on ENABLE_ON_INIT */
297 if (IS_ERR(gpmc_fck)) {
298 WARN_ON(1);
299 return;
300 }
301
302 clk_enable(gpmc_fck);
303 rate = clk_get_rate(gpmc_fck);
304 clk_disable(gpmc_fck);
305 clk_put(gpmc_fck);
306
307 if (is_gpmc_muxed())
308 muxed = 0x200;
309 else
310 muxed = 0;
311
Tony Lindgren1dbae812005-11-10 14:26:51 +0000312 /* Make sure CS1 timings are correct */
Paul Walmsley44595982008-03-18 10:04:51 +0200313 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1,
314 0x00011000 | muxed);
315
316 if (rate >= 160000000) {
317 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
318 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
319 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
320 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
321 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
322 } else if (rate >= 130000000) {
323 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
324 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
325 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
326 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
327 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
328 } else {/* rate = 100000000 */
329 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
330 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
331 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
332 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x031A1F1F);
333 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
334 }
335
336 if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
337 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
338 goto out;
339 }
340
Tony Lindgren1dbae812005-11-10 14:26:51 +0000341 udelay(100);
342
343 omap_cfg_reg(M15_24XX_GPIO92);
David Brownellf6049312006-12-06 17:14:03 -0800344 if (debug_card_init(cs_mem_base, OMAP24XX_ETHR_GPIO_IRQ) < 0)
345 gpmc_cs_free(eth_cs);
Paul Walmsley44595982008-03-18 10:04:51 +0200346
347out:
348 clk_disable(gpmc_fck);
349 clk_put(gpmc_fck);
350}
351
352static void __init h4_init_flash(void)
353{
354 unsigned long base;
355
356 if (gpmc_cs_request(H4_FLASH_CS, SZ_64M, &base) < 0) {
357 printk("Can't request GPMC CS for flash\n");
358 return;
359 }
360 h4_flash_resource.start = base;
361 h4_flash_resource.end = base + SZ_64M - 1;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000362}
363
364static void __init omap_h4_init_irq(void)
365{
Tony Lindgren18f49ea2006-02-08 22:06:47 +0000366 omap2_init_common_hw();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000367 omap_init_irq();
368 omap_gpio_init();
Paul Walmsley44595982008-03-18 10:04:51 +0200369 h4_init_flash();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000370}
371
372static struct omap_uart_config h4_uart_config __initdata = {
373 .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
374};
375
376static struct omap_mmc_config h4_mmc_config __initdata = {
377 .mmc [0] = {
378 .enabled = 1,
379 .wire4 = 1,
380 .wp_pin = -1,
381 .power_pin = -1,
382 .switch_pin = -1,
383 },
384};
385
386static struct omap_lcd_config h4_lcd_config __initdata = {
Tony Lindgren1dbae812005-11-10 14:26:51 +0000387 .ctrl_name = "internal",
388};
389
390static struct omap_board_config_kernel h4_config[] = {
391 { OMAP_TAG_UART, &h4_uart_config },
392 { OMAP_TAG_MMC, &h4_mmc_config },
393 { OMAP_TAG_LCD, &h4_lcd_config },
394};
395
David Brownell6a769ed2008-12-10 17:36:33 -0800396static struct at24_platform_data m24c01 = {
397 .byte_len = SZ_1K / 8,
398 .page_size = 16,
399};
400
Jean Delvare9df013b2008-10-14 17:30:02 +0200401static struct i2c_board_info __initdata h4_i2c_board_info[] = {
402 {
403 I2C_BOARD_INFO("isp1301_omap", 0x2d),
404 .irq = OMAP_GPIO_IRQ(125),
405 },
David Brownell6a769ed2008-12-10 17:36:33 -0800406 { /* EEPROM on mainboard */
407 I2C_BOARD_INFO("24c01", 0x52),
408 .platform_data = &m24c01,
409 },
410 { /* EEPROM on cpu card */
411 I2C_BOARD_INFO("24c01", 0x57),
412 .platform_data = &m24c01,
413 },
Jean Delvare9df013b2008-10-14 17:30:02 +0200414};
415
Tony Lindgren1dbae812005-11-10 14:26:51 +0000416static void __init omap_h4_init(void)
417{
418 /*
419 * Make sure the serial ports are muxed on at this point.
420 * You have to mux them off in device drivers later on
421 * if not needed.
422 */
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100423#if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
424 omap_cfg_reg(K15_24XX_UART3_TX);
425 omap_cfg_reg(K14_24XX_UART3_RX);
426#endif
427
428#if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
429 if (omap_has_menelaus()) {
430 row_gpios[5] = 0;
431 col_gpios[2] = 15;
432 col_gpios[6] = 18;
433 }
434#endif
435
Jean Delvare9df013b2008-10-14 17:30:02 +0200436 i2c_register_board_info(1, h4_i2c_board_info,
437 ARRAY_SIZE(h4_i2c_board_info));
438
Tony Lindgren1dbae812005-11-10 14:26:51 +0000439 platform_add_devices(h4_devices, ARRAY_SIZE(h4_devices));
440 omap_board_config = h4_config;
441 omap_board_config_size = ARRAY_SIZE(h4_config);
442 omap_serial_init();
443}
444
445static void __init omap_h4_map_io(void)
446{
Paul Walmsleyc8d2eb82008-05-07 16:55:13 -0700447 omap2_set_globals_242x();
Tony Lindgren18f49ea2006-02-08 22:06:47 +0000448 omap2_map_common_io();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000449}
450
451MACHINE_START(OMAP_H4, "OMAP2420 H4 board")
452 /* Maintainer: Paul Mundt <paul.mundt@nokia.com> */
Tony Lindgren1dbae812005-11-10 14:26:51 +0000453 .phys_io = 0x48000000,
454 .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc,
455 .boot_params = 0x80000100,
456 .map_io = omap_h4_map_io,
457 .init_irq = omap_h4_init_irq,
458 .init_machine = omap_h4_init,
459 .timer = &omap_timer,
460MACHINE_END