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