]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-h4.c
913ab3d24cd804bfb65c9393a071470ee6b8bec6
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-h4.c
1 /*
2  * linux/arch/arm/mach-omap/omap2/board-h4.c
3  *
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>
20 #include <linux/workqueue.h>
21 #include <linux/input.h>
22
23 #include <asm/hardware.h>
24 #include <asm/mach-types.h>
25 #include <asm/mach/arch.h>
26 #include <asm/mach/map.h>
27 #include <asm/mach/flash.h>
28
29 #include <asm/arch/gpio.h>
30 #include <asm/arch/gpioexpander.h>
31 #include <asm/arch/mux.h>
32 #include <asm/arch/usb.h>
33 #include <asm/arch/irda.h>
34 #include <asm/arch/board.h>
35 #include <asm/arch/common.h>
36 #include <asm/arch/keypad.h>
37 #include <asm/arch/menelaus.h>
38 #include "prcm-regs.h"
39
40 #include <asm/io.h>
41 #include <asm/delay.h>
42
43 static unsigned int row_gpios[6] = { 88, 89, 124, 11, 6, 96 };
44 static unsigned int col_gpios[7] = { 90, 91, 100, 36, 12, 97, 98 };
45
46 static int h4_keymap[] = {
47         KEY(0, 0, KEY_LEFT),
48         KEY(0, 1, KEY_RIGHT),
49         KEY(0, 2, KEY_A),
50         KEY(0, 3, KEY_B),
51         KEY(0, 4, KEY_C),
52         KEY(1, 0, KEY_DOWN),
53         KEY(1, 1, KEY_UP),
54         KEY(1, 2, KEY_E),
55         KEY(1, 3, KEY_F),
56         KEY(1, 4, KEY_G),
57         KEY(2, 0, KEY_ENTER),
58         KEY(2, 1, KEY_I),
59         KEY(2, 2, KEY_J),
60         KEY(2, 3, KEY_K),
61         KEY(2, 4, KEY_3),
62         KEY(3, 0, KEY_M),
63         KEY(3, 1, KEY_N),
64         KEY(3, 2, KEY_O),
65         KEY(3, 3, KEY_P),
66         KEY(3, 4, KEY_Q),
67         KEY(4, 0, KEY_R),
68         KEY(4, 1, KEY_4),
69         KEY(4, 2, KEY_T),
70         KEY(4, 3, KEY_U),
71         KEY(4, 4, KEY_ENTER),
72         KEY(5, 0, KEY_V),
73         KEY(5, 1, KEY_W),
74         KEY(5, 2, KEY_L),
75         KEY(5, 3, KEY_S),
76         KEY(5, 4, KEY_ENTER),
77         0
78 };
79
80 static struct mtd_partition h4_partitions[] = {
81         /* bootloader (U-Boot, etc) in first sector */
82         {
83               .name             = "bootloader",
84               .offset           = 0,
85               .size             = SZ_128K,
86               .mask_flags       = MTD_WRITEABLE, /* force read-only */
87         },
88         /* bootloader params in the next sector */
89         {
90               .name             = "params",
91               .offset           = MTDPART_OFS_APPEND,
92               .size             = SZ_128K,
93               .mask_flags       = 0,
94         },
95         /* kernel */
96         {
97               .name             = "kernel",
98               .offset           = MTDPART_OFS_APPEND,
99               .size             = SZ_2M,
100               .mask_flags       = 0
101         },
102         /* file system */
103         {
104               .name             = "filesystem",
105               .offset           = MTDPART_OFS_APPEND,
106               .size             = MTDPART_SIZ_FULL,
107               .mask_flags       = 0
108         }
109 };
110
111 static struct flash_platform_data h4_flash_data = {
112         .map_name       = "cfi_probe",
113         .width          = 2,
114         .parts          = h4_partitions,
115         .nr_parts       = ARRAY_SIZE(h4_partitions),
116 };
117
118 static struct resource h4_flash_resource = {
119         .start          = H4_CS0_BASE,
120         .end            = H4_CS0_BASE + SZ_64M - 1,
121         .flags          = IORESOURCE_MEM,
122 };
123
124 static struct platform_device h4_flash_device = {
125         .name           = "omapflash",
126         .id             = 0,
127         .dev            = {
128                 .platform_data  = &h4_flash_data,
129         },
130         .num_resources  = 1,
131         .resource       = &h4_flash_resource,
132 };
133
134 static struct resource h4_smc91x_resources[] = {
135         [0] = {
136                 .start  = OMAP24XX_ETHR_START,          /* Physical */
137                 .end    = OMAP24XX_ETHR_START + 0xf,
138                 .flags  = IORESOURCE_MEM,
139         },
140         [1] = {
141                 .start  = OMAP_GPIO_IRQ(OMAP24XX_ETHR_GPIO_IRQ),
142                 .end    = OMAP_GPIO_IRQ(OMAP24XX_ETHR_GPIO_IRQ),
143                 .flags  = IORESOURCE_IRQ,
144         },
145 };
146
147 static struct platform_device h4_smc91x_device = {
148         .name           = "smc91x",
149         .id             = -1,
150         .num_resources  = ARRAY_SIZE(h4_smc91x_resources),
151         .resource       = h4_smc91x_resources,
152 };
153
154 /* Select between the IrDA and aGPS module
155  */
156 static int h4_select_irda(struct device *dev, int state)
157 {
158         unsigned char expa;
159         int err = 0;
160
161         if ((err = read_gpio_expa(&expa, 0x21))) {
162                 printk(KERN_ERR "Error reading from I/O expander\n");
163                 return err;
164         }
165
166         /* 'P6' enable/disable IRDA_TX and IRDA_RX */
167         if (state & IR_SEL) {   /* IrDa */
168                 if ((err = write_gpio_expa(expa | 0x01, 0x21))) {
169                         printk(KERN_ERR "Error writing to I/O expander\n");
170                         return err;
171                 }
172         } else {
173                 if ((err = write_gpio_expa(expa & ~0x01, 0x21))) {
174                         printk(KERN_ERR "Error writing to I/O expander\n");
175                         return err;
176                 }
177         }
178         return err;
179 }
180
181 static void set_trans_mode(void *data)
182 {
183         int *mode = data;
184         unsigned char expa;
185         int err = 0;
186
187         if ((err = read_gpio_expa(&expa, 0x20)) != 0) {
188                 printk(KERN_ERR "Error reading from I/O expander\n");
189         }
190
191         expa &= ~0x01;
192
193         if (!(*mode & IR_SIRMODE)) { /* MIR/FIR */
194                 expa |= 0x01;
195         }
196
197         if ((err = write_gpio_expa(expa, 0x20)) != 0) {
198                 printk(KERN_ERR "Error writing to I/O expander\n");
199         }
200 }
201
202 static int h4_transceiver_mode(struct device *dev, int mode)
203 {
204         struct omap_irda_config *irda_config = dev->platform_data;
205
206         cancel_delayed_work(&irda_config->gpio_expa);
207         PREPARE_WORK(&irda_config->gpio_expa, set_trans_mode, &mode);
208         schedule_work(&irda_config->gpio_expa);
209
210         return 0;
211 }
212
213 static struct omap_irda_config h4_irda_data = {
214         .transceiver_cap        = IR_SIRMODE | IR_MIRMODE | IR_FIRMODE,
215         .transceiver_mode       = h4_transceiver_mode,
216         .select_irda            = h4_select_irda,
217 };
218
219 static struct resource h4_irda_resources[] = {
220         [0] = {
221                 .start  = INT_24XX_UART3_IRQ,
222                 .end    = INT_24XX_UART3_IRQ,
223                 .flags  = IORESOURCE_IRQ,
224         },
225 };
226
227 static struct platform_device h4_irda_device = {
228         .name           = "omapirda",
229         .id             = -1,
230         .dev            = {
231                 .platform_data  = &h4_irda_data,
232         },
233         .num_resources  = 1,
234         .resource       = h4_irda_resources,
235 };
236
237 static struct omap_kp_platform_data h4_kp_data = {
238         .rows           = 6,
239         .cols           = 7,
240         .keymap         = h4_keymap,
241         .rep            = 1,
242         .row_gpios      = row_gpios,
243         .col_gpios      = col_gpios,
244 };
245
246 static struct platform_device h4_kp_device = {
247         .name           = "omap-keypad",
248         .id             = -1,
249         .dev            = {
250                 .platform_data = &h4_kp_data,
251         },
252 };
253
254 static struct platform_device h4_lcd_device = {
255         .name           = "lcd_h4",
256         .id             = -1,
257 };
258
259 static struct platform_device *h4_devices[] __initdata = {
260         &h4_smc91x_device,
261         &h4_flash_device,
262         &h4_irda_device,
263         &h4_kp_device,
264         &h4_lcd_device,
265 };
266
267 static inline void __init h4_init_smc91x(void)
268 {
269         /* Make sure CS1 timings are correct */
270         GPMC_CONFIG1_1 = 0x00011200;
271         GPMC_CONFIG2_1 = 0x001f1f01;
272         GPMC_CONFIG3_1 = 0x00080803;
273         GPMC_CONFIG4_1 = 0x1c091c09;
274         GPMC_CONFIG5_1 = 0x041f1f1f;
275         GPMC_CONFIG6_1 = 0x000004c4;
276         GPMC_CONFIG7_1 = 0x00000f40 | (0x08000000 >> 24);
277         udelay(100);
278
279         omap_cfg_reg(M15_24XX_GPIO92);
280         if (omap_request_gpio(OMAP24XX_ETHR_GPIO_IRQ) < 0) {
281                 printk(KERN_ERR "Failed to request GPIO%d for smc91x IRQ\n",
282                         OMAP24XX_ETHR_GPIO_IRQ);
283                 return;
284         }
285         omap_set_gpio_direction(OMAP24XX_ETHR_GPIO_IRQ, 1);
286 }
287
288 static void __init omap_h4_init_irq(void)
289 {
290         omap2_init_common_hw();
291         omap_init_irq();
292         omap_gpio_init();
293         h4_init_smc91x();
294 }
295
296 static struct omap_uart_config h4_uart_config __initdata = {
297         .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
298 };
299
300 static struct omap_mmc_config h4_mmc_config __initdata = {
301         .mmc [0] = {
302                 .enabled        = 1,
303                 .wire4          = 1,
304                 .wp_pin         = -1,
305                 .power_pin      = -1,
306                 .switch_pin     = -1,
307         },
308 };
309
310 static struct omap_lcd_config h4_lcd_config __initdata = {
311         .ctrl_name      = "internal",
312 };
313
314 static struct omap_board_config_kernel h4_config[] = {
315         { OMAP_TAG_UART,        &h4_uart_config },
316         { OMAP_TAG_MMC,         &h4_mmc_config },
317         { OMAP_TAG_LCD,         &h4_lcd_config },
318 };
319
320 static void __init omap_h4_init(void)
321 {
322         /*
323          * Make sure the serial ports are muxed on at this point.
324          * You have to mux them off in device drivers later on
325          * if not needed.
326          */
327 #if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
328         omap_cfg_reg(K15_24XX_UART3_TX);
329         omap_cfg_reg(K14_24XX_UART3_RX);
330 #endif
331
332 #if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
333         if (omap_has_menelaus()) {
334                 row_gpios[5] = 0;
335                 col_gpios[2] = 15;
336                 col_gpios[6] = 18;
337         }
338 #endif
339
340         platform_add_devices(h4_devices, ARRAY_SIZE(h4_devices));
341         omap_board_config = h4_config;
342         omap_board_config_size = ARRAY_SIZE(h4_config);
343         omap_serial_init();
344 }
345
346 static void __init omap_h4_map_io(void)
347 {
348         omap2_map_common_io();
349 }
350
351 MACHINE_START(OMAP_H4, "OMAP2420 H4 board")
352         /* Maintainer: Paul Mundt <paul.mundt@nokia.com> */
353         .phys_io        = 0x48000000,
354         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
355         .boot_params    = 0x80000100,
356         .map_io         = omap_h4_map_io,
357         .init_irq       = omap_h4_init_irq,
358         .init_machine   = omap_h4_init,
359         .timer          = &omap_timer,
360 MACHINE_END