]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-h4.c
Merge omap historic
[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/delay.h>
25
26 #include <asm/hardware.h>
27 #include <asm/mach-types.h>
28 #include <asm/mach/arch.h>
29 #include <asm/mach/map.h>
30 #include <asm/mach/flash.h>
31
32 #include <asm/arch/gpio.h>
33 #include <asm/arch/gpioexpander.h>
34 #include <asm/arch/mux.h>
35 #include <asm/arch/usb.h>
36 #include <asm/arch/irda.h>
37 #include <asm/arch/board.h>
38 #include <asm/arch/common.h>
39 #include <asm/arch/keypad.h>
40 #include <asm/arch/menelaus.h>
41 #include <asm/arch/dma.h>
42 #include <asm/arch/gpmc.h>
43 #include "prcm-regs.h"
44
45 #include <asm/io.h>
46
47 #define H4_FLASH_CS     0
48 #define H4_SMC91X_CS    1
49
50 static unsigned int row_gpios[6] = { 88, 89, 124, 11, 6, 96 };
51 static unsigned int col_gpios[7] = { 90, 91, 100, 36, 12, 97, 98 };
52
53 static 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
87 static 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
118 static 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
125 static struct resource h4_flash_resource = {
126         .flags          = IORESOURCE_MEM,
127 };
128
129 static 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
139 /* Select between the IrDA and aGPS module
140  */
141 #if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
142 static int h4_select_irda(struct device *dev, int state)
143 {
144         unsigned char expa;
145         int err = 0;
146
147         if ((err = read_gpio_expa(&expa, 0x21))) {
148                 printk(KERN_ERR "Error reading from I/O expander\n");
149                 return err;
150         }
151
152         /* 'P6' enable/disable IRDA_TX and IRDA_RX */
153         if (state & IR_SEL) {   /* IrDa */
154                 if ((err = write_gpio_expa(expa | 0x01, 0x21))) {
155                         printk(KERN_ERR "Error writing to I/O expander\n");
156                         return err;
157                 }
158         } else {
159                 if ((err = write_gpio_expa(expa & ~0x01, 0x21))) {
160                         printk(KERN_ERR "Error writing to I/O expander\n");
161                         return err;
162                 }
163         }
164         return err;
165 }
166
167 static void set_trans_mode(struct work_struct *work)
168 {
169         struct omap_irda_config *irda_config =
170                 container_of(work, struct omap_irda_config, gpio_expa.work);
171         int mode = irda_config->mode;
172         unsigned char expa;
173         int err = 0;
174
175         if ((err = read_gpio_expa(&expa, 0x20)) != 0) {
176                 printk(KERN_ERR "Error reading from I/O expander\n");
177         }
178
179         expa &= ~0x01;
180
181         if (!(mode & IR_SIRMODE)) { /* MIR/FIR */
182                 expa |= 0x01;
183         }
184
185         if ((err = write_gpio_expa(expa, 0x20)) != 0) {
186                 printk(KERN_ERR "Error writing to I/O expander\n");
187         }
188 }
189
190 static int h4_transceiver_mode(struct device *dev, int mode)
191 {
192         struct omap_irda_config *irda_config = dev->platform_data;
193
194         irda_config->mode = mode;
195         cancel_delayed_work(&irda_config->gpio_expa);
196         PREPARE_DELAYED_WORK(&irda_config->gpio_expa, set_trans_mode);
197         schedule_delayed_work(&irda_config->gpio_expa, 0);
198
199         return 0;
200 }
201 #else
202 static int h4_select_irda(struct device *dev, int state) { return 0; }
203 static int h4_transceiver_mode(struct device *dev, int mode) { return 0; }
204 #endif
205
206 static struct omap_irda_config h4_irda_data = {
207         .transceiver_cap        = IR_SIRMODE | IR_MIRMODE | IR_FIRMODE,
208         .transceiver_mode       = h4_transceiver_mode,
209         .select_irda            = h4_select_irda,
210         .rx_channel             = OMAP24XX_DMA_UART3_RX,
211         .tx_channel             = OMAP24XX_DMA_UART3_TX,
212         .dest_start             = OMAP_UART3_BASE,
213         .src_start              = OMAP_UART3_BASE,
214         .tx_trigger             = OMAP24XX_DMA_UART3_TX,
215         .rx_trigger             = OMAP24XX_DMA_UART3_RX,
216 };
217
218 static struct resource h4_irda_resources[] = {
219         [0] = {
220                 .start  = INT_24XX_UART3_IRQ,
221                 .end    = INT_24XX_UART3_IRQ,
222                 .flags  = IORESOURCE_IRQ,
223         },
224 };
225
226 static struct platform_device h4_irda_device = {
227         .name           = "omapirda",
228         .id             = -1,
229         .dev            = {
230                 .platform_data  = &h4_irda_data,
231         },
232         .num_resources  = 1,
233         .resource       = h4_irda_resources,
234 };
235
236 static struct omap_kp_platform_data h4_kp_data = {
237         .rows           = 6,
238         .cols           = 7,
239         .keymap         = h4_keymap,
240         .keymapsize     = ARRAY_SIZE(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_flash_device,
261         &h4_irda_device,
262         &h4_kp_device,
263         &h4_lcd_device,
264 };
265
266 /* 2420 Sysboot setup (2430 is different) */
267 static u32 get_sysboot_value(void)
268 {
269         return (omap_readl(OMAP242X_CONTROL_STATUS) & 0xFFF);
270 }
271
272 /* FIXME: This function should be moved to some other file, gpmc.c? */
273
274 /* H4-2420's always used muxed mode, H4-2422's always use non-muxed
275  *
276  * Note: OMAP-GIT doesn't correctly do is_cpu_omap2422 and is_cpu_omap2423
277  *  correctly.  The macro needs to look at production_id not just hawkeye.
278  */
279 static u32 is_gpmc_muxed(void)
280 {
281         u32 mux;
282         mux = get_sysboot_value();
283         if ((mux & 0xF) == 0xd)
284                 return 1;       /* NAND config (could be either) */
285         if (mux & 0x2)          /* if mux'ed */
286                 return 1;
287         else
288                 return 0;
289 }
290
291 static inline void __init h4_init_debug(void)
292 {
293         int eth_cs;
294         unsigned long cs_mem_base;
295         unsigned int muxed, rate;
296         struct clk *l3ck;
297
298         eth_cs  = H4_SMC91X_CS;
299
300         l3ck = clk_get(NULL, "core_l3_ck");
301         if (IS_ERR(l3ck))
302                 rate = 100000000;
303         else
304                 rate = clk_get_rate(l3ck);
305
306         if (is_gpmc_muxed())
307                 muxed = 0x200;
308         else
309                 muxed = 0;
310
311         /* Make sure CS1 timings are correct */
312         gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1,
313                           0x00011000 | muxed);
314
315         if (rate >= 160000000) {
316                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
317                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
318                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
319                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
320                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
321         } else if (rate >= 130000000) {
322                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
323                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
324                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
325                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
326                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
327         } else {/* rate = 100000000 */
328                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
329                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
330                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
331                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x031A1F1F);
332                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
333         }
334
335         if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
336                 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
337                 return;
338         }
339
340         udelay(100);
341
342         omap_cfg_reg(M15_24XX_GPIO92);
343         if (debug_card_init(cs_mem_base, OMAP24XX_ETHR_GPIO_IRQ) < 0)
344                 gpmc_cs_free(eth_cs);
345 }
346
347 static void __init h4_init_flash(void)
348 {
349         unsigned long base;
350
351         if (gpmc_cs_request(H4_FLASH_CS, SZ_64M, &base) < 0) {
352                 printk("Can't request GPMC CS for flash\n");
353                 return;
354         }
355         h4_flash_resource.start = base;
356         h4_flash_resource.end   = base + SZ_64M - 1;
357 }
358
359 static void __init omap_h4_init_irq(void)
360 {
361         omap2_init_common_hw();
362         omap_init_irq();
363         omap_gpio_init();
364         h4_init_flash();
365 }
366
367 static struct omap_uart_config h4_uart_config __initdata = {
368 #ifdef  CONFIG_MACH_OMAP2_H4_USB1
369         .enabled_uarts = ((1 << 0) | (1 << 1)),
370 #else
371         .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
372 #endif
373 };
374
375 static struct omap_mmc_config h4_mmc_config __initdata = {
376         .mmc [0] = {
377                 .enabled        = 1,
378                 .wire4          = 1,
379                 .wp_pin         = -1,
380                 .power_pin      = -1,
381                 .switch_pin     = -1,
382         },
383 };
384
385 static struct omap_lcd_config h4_lcd_config __initdata = {
386         .ctrl_name      = "internal",
387 };
388
389 static struct omap_usb_config h4_usb_config __initdata = {
390 #ifdef  CONFIG_MACH_OMAP2_H4_USB1
391         /* NOTE:  usb1 could also be used with 3 wire signaling */
392         .pins[1]        = 4,
393 #endif
394
395 #ifdef  CONFIG_MACH_OMAP_H4_OTG
396         /* S1.10 ON -- USB OTG port
397          * usb0 switched to Mini-AB port and isp1301 transceiver;
398          * S2.POS3 = OFF, S2.POS4 = ON ... to allow battery charging
399          */
400         .otg            = 1,
401         .pins[0]        = 4,
402 #ifdef  CONFIG_USB_GADGET_OMAP
403         /* use OTG cable, or standard A-to-MiniB */
404         .hmc_mode       = 0x14, /* 0:dev/otg 1:host 2:disable */
405 #elif   defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
406         /* use OTG cable, or NONSTANDARD (B-to-MiniB) */
407         .hmc_mode       = 0x11, /* 0:host 1:host 2:disable */
408 #endif  /* XX */
409
410 #else
411         /* S1.10 OFF -- usb "download port"
412          * usb0 switched to Mini-B port and isp1105 transceiver;
413          * S2.POS3 = ON, S2.POS4 = OFF ... to enable battery charging
414          */
415         .register_dev   = 1,
416         .pins[0]        = 3,
417 //      .hmc_mode       = 0x14, /* 0:dev 1:host 2:disable */
418         .hmc_mode       = 0x00, /* 0:dev|otg 1:disable 2:disable */
419 #endif
420 };
421
422 static struct omap_board_config_kernel h4_config[] = {
423         { OMAP_TAG_UART,        &h4_uart_config },
424         { OMAP_TAG_MMC,         &h4_mmc_config },
425         { OMAP_TAG_LCD,         &h4_lcd_config },
426         { OMAP_TAG_USB,         &h4_usb_config },
427 };
428
429 #ifdef  CONFIG_MACH_OMAP_H4_TUSB
430
431 #include <linux/usb/musb.h>
432
433 static struct musb_hdrc_platform_data tusb_data = {
434         .mode           = MUSB_OTG,
435         .min_power      = 25,   /* x2 = 50 mA drawn from VBUS as peripheral */
436
437         /* 1.8V supplied by Menelaus, other voltages supplied by VBAT;
438          * so no switching.
439          */
440 };
441
442 static void __init tusb_evm_setup(void)
443 {
444         static char     announce[] __initdata =
445                                 KERN_INFO "TUSB 6010 EVM\n";
446         int             irq;
447         unsigned        dmachan = 0;
448
449         /* There are at least 32 different combinations of boards that
450          * are loosely called "H4", with a 2420 ... different OMAP chip
451          * revisions (with pin mux changes for DMAREQ, GPMC errata, etc),
452          * modifications of the CPU board, mainboard, EVM, TUSB etc.
453          * Plus omap2422, omap2423, etc.
454          *
455          * So you might need to tweak this setup to make the TUSB EVM
456          * behave on your particular setup ...
457          */
458
459         /* Already set up:  GPMC AD[0..15], CLK, nOE, nWE, nADV_ALE */
460         omap_cfg_reg(E2_GPMC_NCS2);
461         omap_cfg_reg(L2_GPMC_NCS7);
462         omap_cfg_reg(M1_GPMC_WAIT2);
463
464         switch ((system_rev >> 8) & 0x0f) {
465         case 0:         /* ES 1.0 */
466         case 1:         /* ES 2.0 */
467                 /* Assume early board revision without optional ES2.0
468                  * rework to swap J15 & AA10 so DMAREQ0 works
469                  */
470                 omap_cfg_reg(AA10_242X_GPIO13);
471                 irq = 13;
472                 // omap_cfg_reg(J15_24XX_DMAREQ0);
473                 break;
474         default:
475                 /* Later Menelaus boards can support all 6 DMA request
476                  * lines, at the price of boot flash A23-A26.
477                  */
478                 omap_cfg_reg(J15_24XX_GPIO99);
479                 irq = 99;
480                 dmachan = (1 << 1) | (1 << 0);
481 #if !(defined(CONFIG_MTD_OMAP_NOR) || defined(CONFIG_MTD_OMAP_NOR_MODULE))
482                 dmachan |= (1 << 5) | (1 << 4) (1 << 3) | (1 << 2);
483 #endif
484                 break;
485         }
486
487         if (tusb6010_setup_interface(&tusb_data,
488                         TUSB6010_REFCLK_24, /* waitpin */ 2,
489                         /* async cs */ 2, /* sync cs */ 7,
490                         irq, dmachan) == 0)
491                 printk(announce);
492 }
493
494 #endif
495
496 static void __init omap_h4_init(void)
497 {
498         /*
499          * Make sure the serial ports are muxed on at this point.
500          * You have to mux them off in device drivers later on
501          * if not needed.
502          */
503 #if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
504         omap_cfg_reg(K15_24XX_UART3_TX);
505         omap_cfg_reg(K14_24XX_UART3_RX);
506 #endif
507
508 #if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
509         if (omap_has_menelaus()) {
510                 row_gpios[5] = 0;
511                 col_gpios[2] = 15;
512                 col_gpios[6] = 18;
513         }
514 #endif
515
516 #ifdef  CONFIG_MACH_OMAP2_H4_USB1
517         /* S3.3 controls whether these pins are for UART2 or USB1 */
518         omap_cfg_reg(N14_24XX_USB1_SE0);
519         omap_cfg_reg(P15_24XX_USB1_DAT);
520         omap_cfg_reg(W20_24XX_USB1_TXEN);
521         omap_cfg_reg(V19_24XX_USB1_RCV);
522 #endif
523
524         platform_add_devices(h4_devices, ARRAY_SIZE(h4_devices));
525         omap_board_config = h4_config;
526         omap_board_config_size = ARRAY_SIZE(h4_config);
527         omap_serial_init();
528
529         /* smc91x, debug leds, ps/2, extra uarts */
530         h4_init_debug();
531
532 #ifdef  CONFIG_MACH_OMAP_H4_TUSB
533         tusb_evm_setup();
534 #endif
535
536 }
537
538 static void __init omap_h4_map_io(void)
539 {
540         omap2_map_common_io();
541 }
542
543 MACHINE_START(OMAP_H4, "OMAP2420 H4 board")
544         /* Maintainer: Paul Mundt <paul.mundt@nokia.com> */
545         .phys_io        = 0x48000000,
546         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
547         .boot_params    = 0x80000100,
548         .map_io         = omap_h4_map_io,
549         .init_irq       = omap_h4_init_irq,
550         .init_machine   = omap_h4_init,
551         .timer          = &omap_timer,
552 MACHINE_END