Pull bugzilla-5452 into release branch
[pandora-kernel.git] / arch / arm / mach-omap1 / board-h3.c
1 /*
2  * linux/arch/arm/mach-omap1/board-h3.c
3  *
4  * This file contains OMAP1710 H3 specific code.
5  *
6  * Copyright (C) 2004 Texas Instruments, Inc.
7  * Copyright (C) 2002 MontaVista Software, Inc.
8  * Copyright (C) 2001 RidgeRun, Inc.
9  * Author: RidgeRun, Inc.
10  *         Greg Lonnon (glonnon@ridgerun.com) or info@ridgerun.com
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License version 2 as
14  * published by the Free Software Foundation.
15  */
16
17 #include <linux/config.h>
18 #include <linux/types.h>
19 #include <linux/init.h>
20 #include <linux/major.h>
21 #include <linux/kernel.h>
22 #include <linux/platform_device.h>
23 #include <linux/errno.h>
24 #include <linux/workqueue.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/nand.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/input.h>
29
30 #include <asm/setup.h>
31 #include <asm/page.h>
32 #include <asm/hardware.h>
33 #include <asm/mach-types.h>
34 #include <asm/mach/arch.h>
35 #include <asm/mach/flash.h>
36 #include <asm/mach/map.h>
37
38 #include <asm/arch/gpio.h>
39 #include <asm/arch/gpioexpander.h>
40 #include <asm/arch/irqs.h>
41 #include <asm/arch/mux.h>
42 #include <asm/arch/tc.h>
43 #include <asm/arch/irda.h>
44 #include <asm/arch/usb.h>
45 #include <asm/arch/keypad.h>
46 #include <asm/arch/dma.h>
47 #include <asm/arch/common.h>
48
49 extern int omap_gpio_init(void);
50
51 static int h3_keymap[] = {
52         KEY(0, 0, KEY_LEFT),
53         KEY(0, 1, KEY_RIGHT),
54         KEY(0, 2, KEY_3),
55         KEY(0, 3, KEY_F10),
56         KEY(0, 4, KEY_F5),
57         KEY(0, 5, KEY_9),
58         KEY(1, 0, KEY_DOWN),
59         KEY(1, 1, KEY_UP),
60         KEY(1, 2, KEY_2),
61         KEY(1, 3, KEY_F9),
62         KEY(1, 4, KEY_F7),
63         KEY(1, 5, KEY_0),
64         KEY(2, 0, KEY_ENTER),
65         KEY(2, 1, KEY_6),
66         KEY(2, 2, KEY_1),
67         KEY(2, 3, KEY_F2),
68         KEY(2, 4, KEY_F6),
69         KEY(2, 5, KEY_HOME),
70         KEY(3, 0, KEY_8),
71         KEY(3, 1, KEY_5),
72         KEY(3, 2, KEY_F12),
73         KEY(3, 3, KEY_F3),
74         KEY(3, 4, KEY_F8),
75         KEY(3, 5, KEY_END),
76         KEY(4, 0, KEY_7),
77         KEY(4, 1, KEY_4),
78         KEY(4, 2, KEY_F11),
79         KEY(4, 3, KEY_F1),
80         KEY(4, 4, KEY_F4),
81         KEY(4, 5, KEY_ESC),
82         KEY(5, 0, KEY_F13),
83         KEY(5, 1, KEY_F14),
84         KEY(5, 2, KEY_F15),
85         KEY(5, 3, KEY_F16),
86         KEY(5, 4, KEY_SLEEP),
87         0
88 };
89
90
91 static struct mtd_partition nor_partitions[] = {
92         /* bootloader (U-Boot, etc) in first sector */
93         {
94               .name             = "bootloader",
95               .offset           = 0,
96               .size             = SZ_128K,
97               .mask_flags       = MTD_WRITEABLE, /* force read-only */
98         },
99         /* bootloader params in the next sector */
100         {
101               .name             = "params",
102               .offset           = MTDPART_OFS_APPEND,
103               .size             = SZ_128K,
104               .mask_flags       = 0,
105         },
106         /* kernel */
107         {
108               .name             = "kernel",
109               .offset           = MTDPART_OFS_APPEND,
110               .size             = SZ_2M,
111               .mask_flags       = 0
112         },
113         /* file system */
114         {
115               .name             = "filesystem",
116               .offset           = MTDPART_OFS_APPEND,
117               .size             = MTDPART_SIZ_FULL,
118               .mask_flags       = 0
119         }
120 };
121
122 static struct flash_platform_data nor_data = {
123         .map_name       = "cfi_probe",
124         .width          = 2,
125         .parts          = nor_partitions,
126         .nr_parts       = ARRAY_SIZE(nor_partitions),
127 };
128
129 static struct resource nor_resource = {
130         /* This is on CS3, wherever it's mapped */
131         .flags          = IORESOURCE_MEM,
132 };
133
134 static struct platform_device nor_device = {
135         .name           = "omapflash",
136         .id             = 0,
137         .dev            = {
138                 .platform_data  = &nor_data,
139         },
140         .num_resources  = 1,
141         .resource       = &nor_resource,
142 };
143
144 static struct mtd_partition nand_partitions[] = {
145 #if 0
146         /* REVISIT: enable these partitions if you make NAND BOOT work */
147         {
148                 .name           = "xloader",
149                 .offset         = 0,
150                 .size           = 64 * 1024,
151                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
152         },
153         {
154                 .name           = "bootloader",
155                 .offset         = MTDPART_OFS_APPEND,
156                 .size           = 256 * 1024,
157                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
158         },
159         {
160                 .name           = "params",
161                 .offset         = MTDPART_OFS_APPEND,
162                 .size           = 192 * 1024,
163         },
164         {
165                 .name           = "kernel",
166                 .offset         = MTDPART_OFS_APPEND,
167                 .size           = 2 * SZ_1M,
168         },
169 #endif
170         {
171                 .name           = "filesystem",
172                 .size           = MTDPART_SIZ_FULL,
173                 .offset         = MTDPART_OFS_APPEND,
174         },
175 };
176
177 /* dip switches control NAND chip access:  8 bit, 16 bit, or neither */
178 static struct nand_platform_data nand_data = {
179         .options        = NAND_SAMSUNG_LP_OPTIONS,
180         .parts          = nand_partitions,
181         .nr_parts       = ARRAY_SIZE(nand_partitions),
182 };
183
184 static struct resource nand_resource = {
185         .flags          = IORESOURCE_MEM,
186 };
187
188 static struct platform_device nand_device = {
189         .name           = "omapnand",
190         .id             = 0,
191         .dev            = {
192                 .platform_data  = &nand_data,
193         },
194         .num_resources  = 1,
195         .resource       = &nand_resource,
196 };
197
198 static struct resource smc91x_resources[] = {
199         [0] = {
200                 .start  = OMAP1710_ETHR_START,          /* Physical */
201                 .end    = OMAP1710_ETHR_START + 0xf,
202                 .flags  = IORESOURCE_MEM,
203         },
204         [1] = {
205                 .start  = OMAP_GPIO_IRQ(40),
206                 .end    = OMAP_GPIO_IRQ(40),
207                 .flags  = IORESOURCE_IRQ,
208         },
209 };
210
211 static struct platform_device smc91x_device = {
212         .name           = "smc91x",
213         .id             = 0,
214         .num_resources  = ARRAY_SIZE(smc91x_resources),
215         .resource       = smc91x_resources,
216 };
217
218 #define GPTIMER_BASE            0xFFFB1400
219 #define GPTIMER_REGS(x) (0xFFFB1400 + (x * 0x800))
220 #define GPTIMER_REGS_SIZE       0x46
221
222 static struct resource intlat_resources[] = {
223         [0] = {
224                 .start  = GPTIMER_REGS(0),            /* Physical */
225                 .end    = GPTIMER_REGS(0) + GPTIMER_REGS_SIZE,
226                 .flags  = IORESOURCE_MEM,
227         },
228         [1] = {
229                 .start  = INT_1610_GPTIMER1,
230                 .end    = INT_1610_GPTIMER1,
231                 .flags  = IORESOURCE_IRQ,
232         },
233 };
234
235 static struct platform_device intlat_device = {
236         .name      = "omap_intlat",
237         .id          = 0,
238         .num_resources  = ARRAY_SIZE(intlat_resources),
239         .resource       = intlat_resources,
240 };
241
242 static struct resource h3_kp_resources[] = {
243         [0] = {
244                 .start  = INT_KEYBOARD,
245                 .end    = INT_KEYBOARD,
246                 .flags  = IORESOURCE_IRQ,
247         },
248 };
249
250 static struct omap_kp_platform_data h3_kp_data = {
251         .rows   = 8,
252         .cols   = 8,
253         .keymap = h3_keymap,
254         .rep    = 1,
255 };
256
257 static struct platform_device h3_kp_device = {
258         .name           = "omap-keypad",
259         .id             = -1,
260         .dev            = {
261                 .platform_data = &h3_kp_data,
262         },
263         .num_resources  = ARRAY_SIZE(h3_kp_resources),
264         .resource       = h3_kp_resources,
265 };
266
267
268 /* Select between the IrDA and aGPS module
269  */
270 static int h3_select_irda(struct device *dev, int state)
271 {
272         unsigned char expa;
273         int err = 0;
274
275         if ((err = read_gpio_expa(&expa, 0x26))) {
276                 printk(KERN_ERR "Error reading from I/O EXPANDER \n");
277                 return err;
278         }
279
280         /* 'P6' enable/disable IRDA_TX and IRDA_RX */
281         if (state & IR_SEL) { /* IrDA */
282                 if ((err = write_gpio_expa(expa | 0x40, 0x26))) {
283                         printk(KERN_ERR "Error writing to I/O EXPANDER \n");
284                         return err;
285                 }
286         } else {
287                 if ((err = write_gpio_expa(expa & ~0x40, 0x26))) {
288                         printk(KERN_ERR "Error writing to I/O EXPANDER \n");
289                         return err;
290                 }
291         }
292         return err;
293 }
294
295 static void set_trans_mode(void *data)
296 {
297         int *mode = data;
298         unsigned char expa;
299         int err = 0;
300
301         if ((err = read_gpio_expa(&expa, 0x27)) != 0) {
302                 printk(KERN_ERR "Error reading from I/O expander\n");
303         }
304
305         expa &= ~0x03;
306
307         if (*mode & IR_SIRMODE) {
308                 expa |= 0x01;
309         } else { /* MIR/FIR */
310                 expa |= 0x03;
311         }
312
313         if ((err = write_gpio_expa(expa, 0x27)) != 0) {
314                 printk(KERN_ERR "Error writing to I/O expander\n");
315         }
316 }
317
318 static int h3_transceiver_mode(struct device *dev, int mode)
319 {
320         struct omap_irda_config *irda_config = dev->platform_data;
321
322         cancel_delayed_work(&irda_config->gpio_expa);
323         PREPARE_WORK(&irda_config->gpio_expa, set_trans_mode, &mode);
324         schedule_work(&irda_config->gpio_expa);
325
326         return 0;
327 }
328
329 static struct omap_irda_config h3_irda_data = {
330         .transceiver_cap        = IR_SIRMODE | IR_MIRMODE | IR_FIRMODE,
331         .transceiver_mode       = h3_transceiver_mode,
332         .select_irda            = h3_select_irda,
333         .rx_channel             = OMAP_DMA_UART3_RX,
334         .tx_channel             = OMAP_DMA_UART3_TX,
335         .dest_start             = UART3_THR,
336         .src_start              = UART3_RHR,
337         .tx_trigger             = 0,
338         .rx_trigger             = 0,
339 };
340
341 static struct resource h3_irda_resources[] = {
342         [0] = {
343                 .start  = INT_UART3,
344                 .end    = INT_UART3,
345                 .flags  = IORESOURCE_IRQ,
346         },
347 };
348
349 static struct platform_device h3_irda_device = {
350         .name           = "omapirda",
351         .id             = 0,
352         .dev            = {
353                 .platform_data  = &h3_irda_data,
354         },
355         .num_resources  = ARRAY_SIZE(h3_irda_resources),
356         .resource       = h3_irda_resources,
357 };
358
359 static struct platform_device h3_lcd_device = {
360         .name           = "lcd_h3",
361         .id             = -1,
362 };
363
364 static struct platform_device *devices[] __initdata = {
365         &nor_device,
366         &nand_device,
367         &smc91x_device,
368         &intlat_device,
369         &h3_irda_device,
370         &h3_kp_device,
371         &h3_lcd_device,
372 };
373
374 static struct omap_usb_config h3_usb_config __initdata = {
375         /* usb1 has a Mini-AB port and external isp1301 transceiver */
376         .otg        = 2,
377
378 #ifdef CONFIG_USB_GADGET_OMAP
379         .hmc_mode       = 19,   /* 0:host(off) 1:dev|otg 2:disabled */
380 #elif  defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
381         /* NONSTANDARD CABLE NEEDED (B-to-Mini-B) */
382         .hmc_mode       = 20,   /* 1:dev|otg(off) 1:host 2:disabled */
383 #endif
384
385         .pins[1]        = 3,
386 };
387
388 static struct omap_mmc_config h3_mmc_config __initdata = {
389         .mmc[0] = {
390                 .enabled        = 1,
391                 .power_pin      = -1,   /* tps65010 GPIO4 */
392                 .switch_pin     = OMAP_MPUIO(1),
393         },
394 };
395
396 static struct omap_uart_config h3_uart_config __initdata = {
397         .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
398 };
399
400 static struct omap_lcd_config h3_lcd_config __initdata = {
401         .ctrl_name      = "internal",
402 };
403
404 static struct omap_board_config_kernel h3_config[] = {
405         { OMAP_TAG_USB,         &h3_usb_config },
406         { OMAP_TAG_MMC,         &h3_mmc_config },
407         { OMAP_TAG_UART,        &h3_uart_config },
408         { OMAP_TAG_LCD,         &h3_lcd_config },
409 };
410
411 #define H3_NAND_RB_GPIO_PIN     10
412
413 static int nand_dev_ready(struct nand_platform_data *data)
414 {
415         return omap_get_gpio_datain(H3_NAND_RB_GPIO_PIN);
416 }
417
418 static void __init h3_init(void)
419 {
420         /* Here we assume the NOR boot config:  NOR on CS3 (possibly swapped
421          * to address 0 by a dip switch), NAND on CS2B.  The NAND driver will
422          * notice whether a NAND chip is enabled at probe time.
423          *
424          * H3 support NAND-boot, with a dip switch to put NOR on CS2B and NAND
425          * (which on H2 may be 16bit) on CS3.  Try detecting that in code here,
426          * to avoid probing every possible flash configuration...
427          */
428         nor_resource.end = nor_resource.start = omap_cs3_phys();
429         nor_resource.end += SZ_32M - 1;
430
431         nand_resource.end = nand_resource.start = OMAP_CS2B_PHYS;
432         nand_resource.end += SZ_4K - 1;
433         if (!(omap_request_gpio(H3_NAND_RB_GPIO_PIN)))
434                 nand_data.dev_ready = nand_dev_ready;
435
436         /* GPIO10 Func_MUX_CTRL reg bit 29:27, Configure V2 to mode1 as GPIO */
437         /* GPIO10 pullup/down register, Enable pullup on GPIO10 */
438         omap_cfg_reg(V2_1710_GPIO10);
439
440         platform_add_devices(devices, ARRAY_SIZE(devices));
441         omap_board_config = h3_config;
442         omap_board_config_size = ARRAY_SIZE(h3_config);
443         omap_serial_init();
444 }
445
446 static void __init h3_init_smc91x(void)
447 {
448         omap_cfg_reg(W15_1710_GPIO40);
449         if (omap_request_gpio(40) < 0) {
450                 printk("Error requesting gpio 40 for smc91x irq\n");
451                 return;
452         }
453 }
454
455 void h3_init_irq(void)
456 {
457         omap1_init_common_hw();
458         omap_init_irq();
459         omap_gpio_init();
460         h3_init_smc91x();
461 }
462
463 static void __init h3_map_io(void)
464 {
465         omap1_map_common_io();
466 }
467
468 MACHINE_START(OMAP_H3, "TI OMAP1710 H3 board")
469         /* Maintainer: Texas Instruments, Inc. */
470         .phys_io        = 0xfff00000,
471         .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
472         .boot_params    = 0x10000100,
473         .map_io         = h3_map_io,
474         .init_irq       = h3_init_irq,
475         .init_machine   = h3_init,
476         .timer          = &omap_timer,
477 MACHINE_END