Merge current mainline tree into linux-omap tree
[pandora-kernel.git] / arch / arm / mach-omap1 / board-h2.c
1 /*
2  * linux/arch/arm/mach-omap1/board-h2.c
3  *
4  * Board specific inits for OMAP-1610 H2
5  *
6  * Copyright (C) 2001 RidgeRun, Inc.
7  * Author: Greg Lonnon <glonnon@ridgerun.com>
8  *
9  * Copyright (C) 2002 MontaVista Software, Inc.
10  *
11  * Separated FPGA interrupts from innovator1510.c and cleaned up for 2.6
12  * Copyright (C) 2004 Nokia Corporation by Tony Lindrgen <tony@atomide.com>
13  *
14  * H2 specific changes and cleanup
15  * Copyright (C) 2004 Nokia Corporation by Imre Deak <imre.deak@nokia.com>
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License version 2 as
19  * published by the Free Software Foundation.
20  */
21
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/platform_device.h>
25 #include <linux/delay.h>
26 #include <linux/i2c.h>
27 #include <linux/mtd/mtd.h>
28 #include <linux/mtd/nand.h>
29 #include <linux/mtd/partitions.h>
30 #include <linux/input.h>
31 #include <linux/i2c/tps65010.h>
32 #include <linux/workqueue.h>
33 #include <linux/spi/spi.h>
34 #include <linux/spi/tsc2101.h>
35 #include <linux/clk.h>
36
37 #include <mach/hardware.h>
38 #include <asm/gpio.h>
39
40 #include <asm/mach-types.h>
41 #include <asm/mach/arch.h>
42 #include <asm/mach/flash.h>
43 #include <asm/mach/map.h>
44
45 #include <mach/gpio.h>
46 #include <mach/gpio-switch.h>
47 #include <mach/mux.h>
48 #include <mach/tc.h>
49 #include <mach/nand.h>
50 #include <mach/irda.h>
51 #include <mach/usb.h>
52 #include <mach/keypad.h>
53 #include <mach/common.h>
54 #include <mach/mcbsp.h>
55 #include <mach/omap-alsa.h>
56
57 static int h2_keymap[] = {
58         KEY(0, 0, KEY_LEFT),
59         KEY(0, 1, KEY_RIGHT),
60         KEY(0, 2, KEY_3),
61         KEY(0, 3, KEY_F10),
62         KEY(0, 4, KEY_F5),
63         KEY(0, 5, KEY_9),
64         KEY(1, 0, KEY_DOWN),
65         KEY(1, 1, KEY_UP),
66         KEY(1, 2, KEY_2),
67         KEY(1, 3, KEY_F9),
68         KEY(1, 4, KEY_F7),
69         KEY(1, 5, KEY_0),
70         KEY(2, 0, KEY_ENTER),
71         KEY(2, 1, KEY_6),
72         KEY(2, 2, KEY_1),
73         KEY(2, 3, KEY_F2),
74         KEY(2, 4, KEY_F6),
75         KEY(2, 5, KEY_HOME),
76         KEY(3, 0, KEY_8),
77         KEY(3, 1, KEY_5),
78         KEY(3, 2, KEY_F12),
79         KEY(3, 3, KEY_F3),
80         KEY(3, 4, KEY_F8),
81         KEY(3, 5, KEY_END),
82         KEY(4, 0, KEY_7),
83         KEY(4, 1, KEY_4),
84         KEY(4, 2, KEY_F11),
85         KEY(4, 3, KEY_F1),
86         KEY(4, 4, KEY_F4),
87         KEY(4, 5, KEY_ESC),
88         KEY(5, 0, KEY_F13),
89         KEY(5, 1, KEY_F14),
90         KEY(5, 2, KEY_F15),
91         KEY(5, 3, KEY_F16),
92         KEY(5, 4, KEY_SLEEP),
93         0
94 };
95
96 static struct mtd_partition h2_nor_partitions[] = {
97         /* bootloader (U-Boot, etc) in first sector */
98         {
99               .name             = "bootloader",
100               .offset           = 0,
101               .size             = SZ_128K,
102               .mask_flags       = MTD_WRITEABLE, /* force read-only */
103         },
104         /* bootloader params in the next sector */
105         {
106               .name             = "params",
107               .offset           = MTDPART_OFS_APPEND,
108               .size             = SZ_128K,
109               .mask_flags       = 0,
110         },
111         /* kernel */
112         {
113               .name             = "kernel",
114               .offset           = MTDPART_OFS_APPEND,
115               .size             = SZ_2M,
116               .mask_flags       = 0
117         },
118         /* file system */
119         {
120               .name             = "filesystem",
121               .offset           = MTDPART_OFS_APPEND,
122               .size             = MTDPART_SIZ_FULL,
123               .mask_flags       = 0
124         }
125 };
126
127 static struct flash_platform_data h2_nor_data = {
128         .map_name       = "cfi_probe",
129         .width          = 2,
130         .parts          = h2_nor_partitions,
131         .nr_parts       = ARRAY_SIZE(h2_nor_partitions),
132 };
133
134 static struct resource h2_nor_resource = {
135         /* This is on CS3, wherever it's mapped */
136         .flags          = IORESOURCE_MEM,
137 };
138
139 static struct platform_device h2_nor_device = {
140         .name           = "omapflash",
141         .id             = 0,
142         .dev            = {
143                 .platform_data  = &h2_nor_data,
144         },
145         .num_resources  = 1,
146         .resource       = &h2_nor_resource,
147 };
148
149 static struct mtd_partition h2_nand_partitions[] = {
150 #if 0
151         /* REVISIT:  enable these partitions if you make NAND BOOT
152          * work on your H2 (rev C or newer); published versions of
153          * x-load only support P2 and H3.
154          */
155         {
156                 .name           = "xloader",
157                 .offset         = 0,
158                 .size           = 64 * 1024,
159                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
160         },
161         {
162                 .name           = "bootloader",
163                 .offset         = MTDPART_OFS_APPEND,
164                 .size           = 256 * 1024,
165                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
166         },
167         {
168                 .name           = "params",
169                 .offset         = MTDPART_OFS_APPEND,
170                 .size           = 192 * 1024,
171         },
172         {
173                 .name           = "kernel",
174                 .offset         = MTDPART_OFS_APPEND,
175                 .size           = 2 * SZ_1M,
176         },
177 #endif
178         {
179                 .name           = "filesystem",
180                 .size           = MTDPART_SIZ_FULL,
181                 .offset         = MTDPART_OFS_APPEND,
182         },
183 };
184
185 /* dip switches control NAND chip access:  8 bit, 16 bit, or neither */
186 static struct omap_nand_platform_data h2_nand_data = {
187         .options        = NAND_SAMSUNG_LP_OPTIONS,
188         .parts          = h2_nand_partitions,
189         .nr_parts       = ARRAY_SIZE(h2_nand_partitions),
190 };
191
192 static struct resource h2_nand_resource = {
193         .flags          = IORESOURCE_MEM,
194 };
195
196 static struct platform_device h2_nand_device = {
197         .name           = "omapnand",
198         .id             = 0,
199         .dev            = {
200                 .platform_data  = &h2_nand_data,
201         },
202         .num_resources  = 1,
203         .resource       = &h2_nand_resource,
204 };
205
206 static struct resource h2_smc91x_resources[] = {
207         [0] = {
208                 .start  = OMAP1610_ETHR_START,          /* Physical */
209                 .end    = OMAP1610_ETHR_START + 0xf,
210                 .flags  = IORESOURCE_MEM,
211         },
212         [1] = {
213                 .start  = OMAP_GPIO_IRQ(0),
214                 .end    = OMAP_GPIO_IRQ(0),
215                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE,
216         },
217 };
218
219 static struct platform_device h2_smc91x_device = {
220         .name           = "smc91x",
221         .id             = 0,
222         .num_resources  = ARRAY_SIZE(h2_smc91x_resources),
223         .resource       = h2_smc91x_resources,
224 };
225
226 static struct resource h2_kp_resources[] = {
227         [0] = {
228                 .start  = INT_KEYBOARD,
229                 .end    = INT_KEYBOARD,
230                 .flags  = IORESOURCE_IRQ,
231         },
232 };
233
234 static struct omap_kp_platform_data h2_kp_data = {
235         .rows           = 8,
236         .cols           = 8,
237         .keymap         = h2_keymap,
238         .keymapsize     = ARRAY_SIZE(h2_keymap),
239         .rep            = 1,
240         .delay          = 9,
241         .dbounce        = 1,
242 };
243
244 static struct platform_device h2_kp_device = {
245         .name           = "omap-keypad",
246         .id             = -1,
247         .dev            = {
248                 .platform_data = &h2_kp_data,
249         },
250         .num_resources  = ARRAY_SIZE(h2_kp_resources),
251         .resource       = h2_kp_resources,
252 };
253
254 #define H2_IRDA_FIRSEL_GPIO_PIN 17
255
256 #if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
257 static int h2_transceiver_mode(struct device *dev, int state)
258 {
259         if (state & IR_SIRMODE)
260                 omap_set_gpio_dataout(H2_IRDA_FIRSEL_GPIO_PIN, 0);
261         else    /* MIR/FIR */
262                 omap_set_gpio_dataout(H2_IRDA_FIRSEL_GPIO_PIN, 1);
263
264         return 0;
265 }
266 #endif
267
268 static struct omap_irda_config h2_irda_data = {
269         .transceiver_cap        = IR_SIRMODE | IR_MIRMODE | IR_FIRMODE,
270         .rx_channel             = OMAP_DMA_UART3_RX,
271         .tx_channel             = OMAP_DMA_UART3_TX,
272         .dest_start             = UART3_THR,
273         .src_start              = UART3_RHR,
274         .tx_trigger             = 0,
275         .rx_trigger             = 0,
276 };
277
278 static struct resource h2_irda_resources[] = {
279         [0] = {
280                 .start  = INT_UART3,
281                 .end    = INT_UART3,
282                 .flags  = IORESOURCE_IRQ,
283         },
284 };
285
286 static u64 irda_dmamask = 0xffffffff;
287
288 static struct platform_device h2_irda_device = {
289         .name           = "omapirda",
290         .id             = 0,
291         .dev            = {
292                 .platform_data  = &h2_irda_data,
293                 .dma_mask       = &irda_dmamask,
294         },
295         .num_resources  = ARRAY_SIZE(h2_irda_resources),
296         .resource       = h2_irda_resources,
297 };
298
299 static struct platform_device h2_lcd_device = {
300         .name           = "lcd_h2",
301         .id             = -1,
302 };
303
304 struct {
305         struct clk      *mclk;
306         int             initialized;
307 } h2_tsc2101;
308
309 #define TSC2101_MUX_MCLK_ON     R10_1610_MCLK_ON
310 #define TSC2101_MUX_MCLK_OFF    R10_1610_MCLK_OFF
311
312 static void h2_lcd_dev_init(struct spi_device *tsc2101)
313 {
314         /* The LCD is connected to the GPIO pins of the TSC2101, so
315          * we have to tie them here. We can also register the LCD driver
316          * first only here, where we know that the TSC driver is ready.
317          */
318
319         h2_lcd_device.dev.platform_data = tsc2101;
320         platform_device_register(&h2_lcd_device);
321 }
322
323 static struct omap_mcbsp_reg_cfg mcbsp_regs = {
324         .spcr2 = FREE | FRST | GRST | XRST | XINTM(3),
325         .spcr1 = RINTM(3) | RRST,
326         .rcr2  = RPHASE | RFRLEN2(OMAP_MCBSP_WORD_8) |
327                         RWDLEN2(OMAP_MCBSP_WORD_16) | RDATDLY(1),
328         .rcr1  = RFRLEN1(OMAP_MCBSP_WORD_8) | RWDLEN1(OMAP_MCBSP_WORD_16),
329         .xcr2  = XPHASE | XFRLEN2(OMAP_MCBSP_WORD_8) |
330                         XWDLEN2(OMAP_MCBSP_WORD_16) | XDATDLY(1) | XFIG,
331         .xcr1  = XFRLEN1(OMAP_MCBSP_WORD_8) | XWDLEN1(OMAP_MCBSP_WORD_16),
332         .srgr1 = FWID(15),
333         .srgr2 = GSYNC | CLKSP | FSGM | FPER(31),
334         .pcr0  = CLKXM | CLKRM | FSXP | FSRP | CLKXP | CLKRP,
335         /*.pcr0 = CLKXP | CLKRP,*/        /* mcbsp: slave */
336 };
337
338 static struct omap_alsa_codec_config alsa_config = {
339         .name                   = "H2 TSC2101",
340         .mcbsp_regs_alsa        = &mcbsp_regs,
341 };
342
343 static struct platform_device h2_mcbsp1_device = {
344         .name   = "omap_alsa_mcbsp",
345         .id     = 1,
346         .dev = {
347                 .platform_data  = &alsa_config,
348         },
349 };
350
351 static void h2_audio_dev_init(struct spi_device *tsc2101)
352 {
353         h2_mcbsp1_device.dev.platform_data = tsc2101;
354         platform_device_register(&h2_mcbsp1_device);
355 }
356
357 static int h2_tsc2101_init(struct spi_device *spi)
358 {
359         int r;
360
361         if (h2_tsc2101.initialized) {
362                 printk(KERN_ERR "tsc2101: already initialized\n");
363                 return -ENODEV;
364         }
365
366         /* Get the MCLK */
367         h2_tsc2101.mclk = clk_get(&spi->dev, "mclk");
368         if (IS_ERR(h2_tsc2101.mclk)) {
369                 dev_err(&spi->dev, "unable to get the clock MCLK\n");
370                 return PTR_ERR(h2_tsc2101.mclk);
371         }
372         if ((r = clk_set_rate(h2_tsc2101.mclk, 12000000)) < 0) {
373                 dev_err(&spi->dev, "unable to set rate to the MCLK\n");
374                 goto err;
375         }
376
377         omap_cfg_reg(TSC2101_MUX_MCLK_OFF);
378         omap_cfg_reg(N15_1610_UWIRE_CS1);
379
380         h2_lcd_dev_init(spi);
381         h2_audio_dev_init(spi);
382
383         return 0;
384 err:
385         clk_put(h2_tsc2101.mclk);
386         return r;
387 }
388
389 static void h2_tsc2101_cleanup(struct spi_device *spi)
390 {
391         clk_put(h2_tsc2101.mclk);
392         omap_cfg_reg(TSC2101_MUX_MCLK_OFF);
393 }
394
395 static void h2_tsc2101_enable_mclk(struct spi_device *spi)
396 {
397         omap_cfg_reg(TSC2101_MUX_MCLK_ON);
398         clk_enable(h2_tsc2101.mclk);
399 }
400
401 static void h2_tsc2101_disable_mclk(struct spi_device *spi)
402 {
403         clk_disable(h2_tsc2101.mclk);
404         omap_cfg_reg(R10_1610_MCLK_OFF);
405 }
406
407 static struct tsc2101_platform_data h2_tsc2101_platform_data = {
408         .init           = h2_tsc2101_init,
409         .cleanup        = h2_tsc2101_cleanup,
410         .enable_mclk    = h2_tsc2101_enable_mclk,
411         .disable_mclk   = h2_tsc2101_disable_mclk,
412 };
413
414 static struct spi_board_info h2_spi_board_info[] __initdata = {
415         [0] = {
416                 .modalias       = "tsc2101",
417                 .bus_num        = 2,
418                 .chip_select    = 1,
419                 .max_speed_hz   = 16000000,
420                 .platform_data  = &h2_tsc2101_platform_data,
421         },
422 };
423
424 static struct platform_device *h2_devices[] __initdata = {
425         &h2_nor_device,
426         &h2_nand_device,
427         &h2_smc91x_device,
428         &h2_irda_device,
429         &h2_kp_device,
430 };
431
432 static void __init h2_init_smc91x(void)
433 {
434         if ((omap_request_gpio(0)) < 0) {
435                 printk("Error requesting gpio 0 for smc91x irq\n");
436                 return;
437         }
438 }
439
440 static int tps_setup(struct i2c_client *client, void *context)
441 {
442         tps65010_config_vregs1(TPS_LDO2_ENABLE | TPS_VLDO2_3_0V |
443                                 TPS_LDO1_ENABLE | TPS_VLDO1_3_0V);
444
445         return 0;
446 }
447
448 static struct tps65010_board tps_board = {
449         .base           = H2_TPS_GPIO_BASE,
450         .outmask        = 0x0f,
451         .setup          = tps_setup,
452 };
453
454 static struct i2c_board_info __initdata h2_i2c_board_info[] = {
455         {
456                 I2C_BOARD_INFO("tps65010", 0x48),
457                 .irq            = OMAP_GPIO_IRQ(58),
458                 .platform_data  = &tps_board,
459         }, {
460                 I2C_BOARD_INFO("isp1301_omap", 0x2d),
461                 .irq            = OMAP_GPIO_IRQ(2),
462         },
463 };
464
465 static void __init h2_init_irq(void)
466 {
467         omap1_init_common_hw();
468         omap_init_irq();
469         omap_gpio_init();
470         h2_init_smc91x();
471 }
472
473 static struct omap_usb_config h2_usb_config __initdata = {
474         /* usb1 has a Mini-AB port and external isp1301 transceiver */
475         .otg            = 2,
476
477 #ifdef  CONFIG_USB_GADGET_OMAP
478         .hmc_mode       = 19,   /* 0:host(off) 1:dev|otg 2:disabled */
479         /* .hmc_mode    = 21,*/ /* 0:host(off) 1:dev(loopback) 2:host(loopback) */
480 #elif   defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
481         /* needs OTG cable, or NONSTANDARD (B-to-MiniB) */
482         .hmc_mode       = 20,   /* 1:dev|otg(off) 1:host 2:disabled */
483 #endif
484
485         .pins[1]        = 3,
486 };
487
488 static struct omap_uart_config h2_uart_config __initdata = {
489         .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
490 };
491
492 static struct omap_lcd_config h2_lcd_config __initdata = {
493         .ctrl_name      = "internal",
494 };
495
496 static struct omap_board_config_kernel h2_config[] __initdata = {
497         { OMAP_TAG_USB,         &h2_usb_config },
498         { OMAP_TAG_UART,        &h2_uart_config },
499         { OMAP_TAG_LCD,         &h2_lcd_config },
500 };
501
502 #define H2_NAND_RB_GPIO_PIN     62
503
504 static int h2_nand_dev_ready(struct omap_nand_platform_data *data)
505 {
506         return omap_get_gpio_datain(H2_NAND_RB_GPIO_PIN);
507 }
508
509 static void __init h2_init(void)
510 {
511         /* Here we assume the NOR boot config:  NOR on CS3 (possibly swapped
512          * to address 0 by a dip switch), NAND on CS2B.  The NAND driver will
513          * notice whether a NAND chip is enabled at probe time.
514          *
515          * FIXME revC boards (and H3) support NAND-boot, with a dip switch to
516          * put NOR on CS2B and NAND (which on H2 may be 16bit) on CS3.  Try
517          * detecting that in code here, to avoid probing every possible flash
518          * configuration...
519          */
520         h2_nor_resource.end = h2_nor_resource.start = omap_cs3_phys();
521         h2_nor_resource.end += SZ_32M - 1;
522
523         h2_nand_resource.end = h2_nand_resource.start = OMAP_CS2B_PHYS;
524         h2_nand_resource.end += SZ_4K - 1;
525         if (!(omap_request_gpio(H2_NAND_RB_GPIO_PIN)))
526                 h2_nand_data.dev_ready = h2_nand_dev_ready;
527
528         omap_cfg_reg(L3_1610_FLASH_CS2B_OE);
529         omap_cfg_reg(M8_1610_FLASH_CS2B_WE);
530
531         /* MMC:  card detect and WP */
532         /* omap_cfg_reg(U19_ARMIO1); */         /* CD */
533         omap_cfg_reg(BALLOUT_V8_ARMIO3);        /* WP */
534
535         /* Irda */
536 #if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
537         omap_writel(omap_readl(FUNC_MUX_CTRL_A) | 7, FUNC_MUX_CTRL_A);
538         if (!(omap_request_gpio(H2_IRDA_FIRSEL_GPIO_PIN))) {
539                 omap_set_gpio_direction(H2_IRDA_FIRSEL_GPIO_PIN, 0);
540                 h2_irda_data.transceiver_mode = h2_transceiver_mode;
541         }
542 #endif
543
544         platform_add_devices(h2_devices, ARRAY_SIZE(h2_devices));
545         spi_register_board_info(h2_spi_board_info,
546                                 ARRAY_SIZE(h2_spi_board_info));
547         omap_board_config = h2_config;
548         omap_board_config_size = ARRAY_SIZE(h2_config);
549         omap_serial_init();
550         omap_register_i2c_bus(1, 100, h2_i2c_board_info,
551                               ARRAY_SIZE(h2_i2c_board_info));
552         h2_mmc_init();
553 }
554
555 static void __init h2_map_io(void)
556 {
557         omap1_map_common_io();
558 }
559
560 MACHINE_START(OMAP_H2, "TI-H2")
561         /* Maintainer: Imre Deak <imre.deak@nokia.com> */
562         .phys_io        = 0xfff00000,
563         .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
564         .boot_params    = 0x10000100,
565         .map_io         = h2_map_io,
566         .init_irq       = h2_init_irq,
567         .init_machine   = h2_init,
568         .timer          = &omap_timer,
569 MACHINE_END