]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-h4.c
a4defbf7a59a444262acd39725c777c32b9601ff
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-h4.c
1 /*
2  * linux/arch/arm/mach-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 #include <linux/err.h>
23 #include <linux/clk.h>
24 #include <linux/i2c.h>
25 #include <linux/spi/spi.h>
26 #include <linux/spi/tsc210x.h>
27
28 #include <asm/hardware.h>
29 #include <asm/mach-types.h>
30 #include <asm/mach/arch.h>
31 #include <asm/mach/map.h>
32 #include <asm/mach/flash.h>
33
34 #include <asm/arch/gpio.h>
35 #include <asm/arch/gpioexpander.h>
36 #include <asm/arch/mux.h>
37 #include <asm/arch/usb.h>
38 #include <asm/arch/irda.h>
39 #include <asm/arch/board.h>
40 #include <asm/arch/common.h>
41 #include <asm/arch/keypad.h>
42 #include <asm/arch/menelaus.h>
43 #include <asm/arch/dma.h>
44 #include <asm/arch/gpmc.h>
45
46 #include <asm/io.h>
47
48 #define H4_FLASH_CS     0
49 #define H4_SMC91X_CS    1
50
51 static unsigned int row_gpios[6] = { 88, 89, 124, 11, 6, 96 };
52 static unsigned int col_gpios[7] = { 90, 91, 100, 36, 12, 97, 98 };
53
54 static int h4_keymap[] = {
55         KEY(0, 0, KEY_LEFT),
56         KEY(0, 1, KEY_RIGHT),
57         KEY(0, 2, KEY_A),
58         KEY(0, 3, KEY_B),
59         KEY(0, 4, KEY_C),
60         KEY(1, 0, KEY_DOWN),
61         KEY(1, 1, KEY_UP),
62         KEY(1, 2, KEY_E),
63         KEY(1, 3, KEY_F),
64         KEY(1, 4, KEY_G),
65         KEY(2, 0, KEY_ENTER),
66         KEY(2, 1, KEY_I),
67         KEY(2, 2, KEY_J),
68         KEY(2, 3, KEY_K),
69         KEY(2, 4, KEY_3),
70         KEY(3, 0, KEY_M),
71         KEY(3, 1, KEY_N),
72         KEY(3, 2, KEY_O),
73         KEY(3, 3, KEY_P),
74         KEY(3, 4, KEY_Q),
75         KEY(4, 0, KEY_R),
76         KEY(4, 1, KEY_4),
77         KEY(4, 2, KEY_T),
78         KEY(4, 3, KEY_U),
79         KEY(4, 4, KEY_ENTER),
80         KEY(5, 0, KEY_V),
81         KEY(5, 1, KEY_W),
82         KEY(5, 2, KEY_L),
83         KEY(5, 3, KEY_S),
84         KEY(5, 4, KEY_ENTER),
85         0
86 };
87
88 static struct mtd_partition h4_partitions[] = {
89         /* bootloader (U-Boot, etc) in first sector */
90         {
91               .name             = "bootloader",
92               .offset           = 0,
93               .size             = SZ_128K,
94               .mask_flags       = MTD_WRITEABLE, /* force read-only */
95         },
96         /* bootloader params in the next sector */
97         {
98               .name             = "params",
99               .offset           = MTDPART_OFS_APPEND,
100               .size             = SZ_128K,
101               .mask_flags       = 0,
102         },
103         /* kernel */
104         {
105               .name             = "kernel",
106               .offset           = MTDPART_OFS_APPEND,
107               .size             = SZ_2M,
108               .mask_flags       = 0
109         },
110         /* file system */
111         {
112               .name             = "filesystem",
113               .offset           = MTDPART_OFS_APPEND,
114               .size             = MTDPART_SIZ_FULL,
115               .mask_flags       = 0
116         }
117 };
118
119 static struct flash_platform_data h4_flash_data = {
120         .map_name       = "cfi_probe",
121         .width          = 2,
122         .parts          = h4_partitions,
123         .nr_parts       = ARRAY_SIZE(h4_partitions),
124 };
125
126 static struct resource h4_flash_resource = {
127         .flags          = IORESOURCE_MEM,
128 };
129
130 static struct platform_device h4_flash_device = {
131         .name           = "omapflash",
132         .id             = 0,
133         .dev            = {
134                 .platform_data  = &h4_flash_data,
135         },
136         .num_resources  = 1,
137         .resource       = &h4_flash_resource,
138 };
139
140 /* Select between the IrDA and aGPS module
141  */
142 #if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
143 static 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
168 static void set_trans_mode(struct work_struct *work)
169 {
170         struct omap_irda_config *irda_config =
171                 container_of(work, struct omap_irda_config, gpio_expa.work);
172         int mode = irda_config->mode;
173         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
182         if (!(mode & IR_SIRMODE)) { /* MIR/FIR */
183                 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
191 static int h4_transceiver_mode(struct device *dev, int mode)
192 {
193         struct omap_irda_config *irda_config = dev->platform_data;
194
195         irda_config->mode = mode;
196         cancel_delayed_work(&irda_config->gpio_expa);
197         PREPARE_DELAYED_WORK(&irda_config->gpio_expa, set_trans_mode);
198         schedule_delayed_work(&irda_config->gpio_expa, 0);
199
200         return 0;
201 }
202 #else
203 static int h4_select_irda(struct device *dev, int state) { return 0; }
204 static int h4_transceiver_mode(struct device *dev, int mode) { return 0; }
205 #endif
206
207 static struct omap_irda_config h4_irda_data = {
208         .transceiver_cap        = IR_SIRMODE | IR_MIRMODE | IR_FIRMODE,
209         .transceiver_mode       = h4_transceiver_mode,
210         .select_irda            = h4_select_irda,
211         .rx_channel             = OMAP24XX_DMA_UART3_RX,
212         .tx_channel             = OMAP24XX_DMA_UART3_TX,
213         .dest_start             = OMAP_UART3_BASE,
214         .src_start              = OMAP_UART3_BASE,
215         .tx_trigger             = OMAP24XX_DMA_UART3_TX,
216         .rx_trigger             = OMAP24XX_DMA_UART3_RX,
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         .keymapsize     = ARRAY_SIZE(h4_keymap),
242         .rep            = 1,
243         .row_gpios      = row_gpios,
244         .col_gpios      = col_gpios,
245 };
246
247 static struct platform_device h4_kp_device = {
248         .name           = "omap-keypad",
249         .id             = -1,
250         .dev            = {
251                 .platform_data = &h4_kp_data,
252         },
253 };
254
255 static struct platform_device h4_lcd_device = {
256         .name           = "lcd_h4",
257         .id             = -1,
258 };
259
260 static struct platform_device *h4_devices[] __initdata = {
261         &h4_flash_device,
262         &h4_irda_device,
263         &h4_kp_device,
264         &h4_lcd_device,
265 };
266
267 /* 2420 Sysboot setup (2430 is different) */
268 static u32 get_sysboot_value(void)
269 {
270         return (omap_readl(OMAP24XX_CONTROL_STATUS) & 0xFFF);
271 }
272
273 /* FIXME: This function should be moved to some other file, gpmc.c? */
274
275 /* H4-2420's always used muxed mode, H4-2422's always use non-muxed
276  *
277  * Note: OMAP-GIT doesn't correctly do is_cpu_omap2422 and is_cpu_omap2423
278  *  correctly.  The macro needs to look at production_id not just hawkeye.
279  */
280 static u32 is_gpmc_muxed(void)
281 {
282         u32 mux;
283         mux = get_sysboot_value();
284         if ((mux & 0xF) == 0xd)
285                 return 1;       /* NAND config (could be either) */
286         if (mux & 0x2)          /* if mux'ed */
287                 return 1;
288         else
289                 return 0;
290 }
291
292 static inline void __init h4_init_debug(void)
293 {
294         int eth_cs;
295         unsigned long cs_mem_base;
296         unsigned int muxed, rate;
297         struct clk *l3ck;
298
299         eth_cs  = H4_SMC91X_CS;
300
301         l3ck = clk_get(NULL, "core_l3_ck");
302         if (IS_ERR(l3ck))
303                 rate = 100000000;
304         else
305                 rate = clk_get_rate(l3ck);
306
307         if (is_gpmc_muxed())
308                 muxed = 0x200;
309         else
310                 muxed = 0;
311
312         /* Make sure CS1 timings are correct */
313         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                 return;
339         }
340
341         udelay(100);
342
343         omap_cfg_reg(M15_24XX_GPIO92);
344         if (debug_card_init(cs_mem_base, OMAP24XX_ETHR_GPIO_IRQ) < 0)
345                 gpmc_cs_free(eth_cs);
346 }
347
348 static void __init h4_init_flash(void)
349 {
350         unsigned long base;
351
352         if (gpmc_cs_request(H4_FLASH_CS, SZ_64M, &base) < 0) {
353                 printk("Can't request GPMC CS for flash\n");
354                 return;
355         }
356         h4_flash_resource.start = base;
357         h4_flash_resource.end   = base + SZ_64M - 1;
358 }
359
360 static void __init omap_h4_init_irq(void)
361 {
362         omap2_init_common_hw();
363         omap_init_irq();
364         omap_gpio_init();
365         h4_init_flash();
366 }
367
368 static struct omap_uart_config h4_uart_config __initdata = {
369 #ifdef  CONFIG_MACH_OMAP2_H4_USB1
370         .enabled_uarts = ((1 << 0) | (1 << 1)),
371 #else
372         .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
373 #endif
374 };
375
376 static 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
386 static struct omap_lcd_config h4_lcd_config __initdata = {
387         .ctrl_name      = "internal",
388 };
389
390 static struct omap_usb_config h4_usb_config __initdata = {
391 #ifdef  CONFIG_MACH_OMAP2_H4_USB1
392         /* NOTE:  usb1 could also be used with 3 wire signaling */
393         .pins[1]        = 4,
394 #endif
395
396 #ifdef  CONFIG_MACH_OMAP_H4_OTG
397         /* S1.10 ON -- USB OTG port
398          * usb0 switched to Mini-AB port and isp1301 transceiver;
399          * S2.POS3 = OFF, S2.POS4 = ON ... to allow battery charging
400          */
401         .otg            = 1,
402         .pins[0]        = 4,
403 #ifdef  CONFIG_USB_GADGET_OMAP
404         /* use OTG cable, or standard A-to-MiniB */
405         .hmc_mode       = 0x14, /* 0:dev/otg 1:host 2:disable */
406 #elif   defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
407         /* use OTG cable, or NONSTANDARD (B-to-MiniB) */
408         .hmc_mode       = 0x11, /* 0:host 1:host 2:disable */
409 #endif  /* XX */
410
411 #else
412         /* S1.10 OFF -- usb "download port"
413          * usb0 switched to Mini-B port and isp1105 transceiver;
414          * S2.POS3 = ON, S2.POS4 = OFF ... to enable battery charging
415          */
416         .register_dev   = 1,
417         .pins[0]        = 3,
418 //      .hmc_mode       = 0x14, /* 0:dev 1:host 2:disable */
419         .hmc_mode       = 0x00, /* 0:dev|otg 1:disable 2:disable */
420 #endif
421 };
422
423 /* ----------------------------------------------------------------------- */
424
425 static struct tsc210x_config tsc_platform_data = {
426         .use_internal           = 1,
427         .monitor                = TSC_VBAT | TSC_TEMP,
428         /* REVISIT temp calibration data -- board-specific; from EEPROM? */
429         .mclk                   = "sys_clkout",
430 };
431
432 static struct spi_board_info h4_spi_board_info[] __initdata = {
433         {
434                 .modalias       = "tsc2101",
435                 .bus_num        = 1,
436                 .chip_select    = 0,
437                 .mode           = SPI_MODE_1,
438                 .irq            = OMAP_GPIO_IRQ(93),
439                 .max_speed_hz   = 16000000,
440                 .platform_data  = &tsc_platform_data,
441         },
442
443         /* nCS1 -- to lcd board, but unused
444          * nCS2 -- to WLAN/miniPCI
445          */
446 };
447
448 /* ----------------------------------------------------------------------- */
449
450 static struct omap_board_config_kernel h4_config[] __initdata = {
451         { OMAP_TAG_UART,        &h4_uart_config },
452         { OMAP_TAG_MMC,         &h4_mmc_config },
453         { OMAP_TAG_LCD,         &h4_lcd_config },
454         { OMAP_TAG_USB,         &h4_usb_config },
455 };
456
457 #ifdef  CONFIG_MACH_OMAP_H4_TUSB
458
459 #include <linux/usb/musb.h>
460
461 static struct musb_hdrc_platform_data tusb_data = {
462         .mode           = MUSB_OTG,
463         .min_power      = 25,   /* x2 = 50 mA drawn from VBUS as peripheral */
464
465         /* 1.8V supplied by Menelaus, other voltages supplied by VBAT;
466          * so no switching.
467          */
468 };
469
470 static void __init tusb_evm_setup(void)
471 {
472         static char     announce[] __initdata =
473                                 KERN_INFO "TUSB 6010 EVM\n";
474         int             irq;
475         unsigned        dmachan = 0;
476
477         /* There are at least 32 different combinations of boards that
478          * are loosely called "H4", with a 2420 ... different OMAP chip
479          * revisions (with pin mux changes for DMAREQ, GPMC errata, etc),
480          * modifications of the CPU board, mainboard, EVM, TUSB etc.
481          * Plus omap2422, omap2423, etc.
482          *
483          * So you might need to tweak this setup to make the TUSB EVM
484          * behave on your particular setup ...
485          */
486
487         /* Already set up:  GPMC AD[0..15], CLK, nOE, nWE, nADV_ALE */
488         omap_cfg_reg(E2_GPMC_NCS2);
489         omap_cfg_reg(L2_GPMC_NCS7);
490         omap_cfg_reg(M1_GPMC_WAIT2);
491
492         switch ((system_rev >> 8) & 0x0f) {
493         case 0:         /* ES 1.0 */
494         case 1:         /* ES 2.0 */
495                 /* Assume early board revision without optional ES2.0
496                  * rework to swap J15 & AA10 so DMAREQ0 works
497                  */
498                 omap_cfg_reg(AA10_242X_GPIO13);
499                 irq = 13;
500                 // omap_cfg_reg(J15_24XX_DMAREQ0);
501                 break;
502         default:
503                 /* Later Menelaus boards can support all 6 DMA request
504                  * lines, at the price of boot flash A23-A26.
505                  */
506                 omap_cfg_reg(J15_24XX_GPIO99);
507                 irq = 99;
508                 dmachan = (1 << 1) | (1 << 0);
509 #if !(defined(CONFIG_MTD_OMAP_NOR) || defined(CONFIG_MTD_OMAP_NOR_MODULE))
510                 dmachan |= (1 << 5) | (1 << 4) (1 << 3) | (1 << 2);
511 #endif
512                 break;
513         }
514
515         if (tusb6010_setup_interface(&tusb_data,
516                         TUSB6010_REFCLK_24, /* waitpin */ 2,
517                         /* async cs */ 2, /* sync cs */ 7,
518                         irq, dmachan) == 0)
519                 printk(announce);
520 }
521
522 #endif
523
524 static struct i2c_board_info __initdata h4_i2c_board_info[] = {
525         {
526                 I2C_BOARD_INFO("rtc-rs5c372", 0x32),
527                 .type = "rv5c387a",
528                 /* no IRQ wired to OMAP; nINTB goes to AGPS */
529         },
530         {
531                 I2C_BOARD_INFO("menelaus", 0x72),
532                 .irq = INT_24XX_SYS_NIRQ,
533         },
534 };
535
536 static void __init omap_h4_init(void)
537 {
538         /*
539          * Make sure the serial ports are muxed on at this point.
540          * You have to mux them off in device drivers later on
541          * if not needed.
542          */
543 #if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
544         omap_cfg_reg(K15_24XX_UART3_TX);
545         omap_cfg_reg(K14_24XX_UART3_RX);
546 #endif
547
548 #if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
549         if (omap_has_menelaus()) {
550                 row_gpios[5] = 0;
551                 col_gpios[2] = 15;
552                 col_gpios[6] = 18;
553         }
554 #endif
555
556 #ifdef  CONFIG_MACH_OMAP2_H4_USB1
557         /* S3.3 controls whether these pins are for UART2 or USB1 */
558         omap_cfg_reg(N14_24XX_USB1_SE0);
559         omap_cfg_reg(P15_24XX_USB1_DAT);
560         omap_cfg_reg(W20_24XX_USB1_TXEN);
561         omap_cfg_reg(V19_24XX_USB1_RCV);
562 #endif
563
564         /* Menelaus interrupt */
565         omap_cfg_reg(W19_24XX_SYS_NIRQ);
566
567         i2c_register_board_info(1, h4_i2c_board_info,
568                         ARRAY_SIZE(h4_i2c_board_info));
569
570         platform_add_devices(h4_devices, ARRAY_SIZE(h4_devices));
571         omap_board_config = h4_config;
572         omap_board_config_size = ARRAY_SIZE(h4_config);
573         omap_serial_init();
574
575         /* smc91x, debug leds, ps/2, extra uarts */
576         h4_init_debug();
577
578 #ifdef  CONFIG_MACH_OMAP_H4_TUSB
579         tusb_evm_setup();
580 #endif
581
582         /* defaults seem ok for:
583          * omap_cfg_reg(U18_24XX_SPI1_SCK);
584          * omap_cfg_reg(V20_24XX_SPI1_MOSI);
585          * omap_cfg_reg(T18_24XX_SPI1_MISO);
586          * omap_cfg_reg(U19_24XX_SPI1_NCS0);
587          */
588
589         /* TSC2101 */
590         omap_cfg_reg(P20_24XX_GPIO93);
591         gpio_request(93, "tsc_irq");
592         gpio_direction_input(93);
593
594         omap_cfg_reg(W14_24XX_SYS_CLKOUT);      /* mclk */
595         /* defaults seem ok for:
596          * omap_cfg_reg(Y15_EAC_AC_SCLK);       // bclk
597          * omap_cfg_reg(R14_EAC_AC_FS);
598          * omap_cfg_reg(V15_EAC_AC_DOUT);
599          * omap_cfg_reg(W15_EAC_AC_DIN);
600          */
601
602         spi_register_board_info(h4_spi_board_info,
603                                 ARRAY_SIZE(h4_spi_board_info));
604 }
605
606 static void __init omap_h4_map_io(void)
607 {
608         omap2_map_common_io();
609 }
610
611 MACHINE_START(OMAP_H4, "OMAP2420 H4 board")
612         /* Maintainer: Paul Mundt <paul.mundt@nokia.com> */
613         .phys_io        = 0x48000000,
614         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
615         .boot_params    = 0x80000100,
616         .map_io         = omap_h4_map_io,
617         .init_irq       = omap_h4_init_irq,
618         .init_machine   = omap_h4_init,
619         .timer          = &omap_timer,
620 MACHINE_END