]> git.karo-electronics.de Git - mv-sheeva.git/blob - arch/arm/mach-omap2/board-h4.c
x86_64: fix incorrect comments
[mv-sheeva.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/i2c.h>
22 #include <linux/i2c/at24.h>
23 #include <linux/input.h>
24 #include <linux/err.h>
25 #include <linux/clk.h>
26 #include <linux/io.h>
27
28 #include <mach/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 <mach/control.h>
35 #include <mach/gpio.h>
36 #include <mach/gpioexpander.h>
37 #include <mach/mux.h>
38 #include <mach/usb.h>
39 #include <mach/irda.h>
40 #include <mach/board.h>
41 #include <mach/common.h>
42 #include <mach/keypad.h>
43 #include <mach/menelaus.h>
44 #include <mach/dma.h>
45 #include <mach/gpmc.h>
46
47 #define H4_FLASH_CS     0
48 #define H4_SMC91X_CS    1
49
50 #define H4_ETHR_GPIO_IRQ                92
51
52 static unsigned int row_gpios[6] = { 88, 89, 124, 11, 6, 96 };
53 static unsigned int col_gpios[7] = { 90, 91, 100, 36, 12, 97, 98 };
54
55 static int h4_keymap[] = {
56         KEY(0, 0, KEY_LEFT),
57         KEY(0, 1, KEY_RIGHT),
58         KEY(0, 2, KEY_A),
59         KEY(0, 3, KEY_B),
60         KEY(0, 4, KEY_C),
61         KEY(1, 0, KEY_DOWN),
62         KEY(1, 1, KEY_UP),
63         KEY(1, 2, KEY_E),
64         KEY(1, 3, KEY_F),
65         KEY(1, 4, KEY_G),
66         KEY(2, 0, KEY_ENTER),
67         KEY(2, 1, KEY_I),
68         KEY(2, 2, KEY_J),
69         KEY(2, 3, KEY_K),
70         KEY(2, 4, KEY_3),
71         KEY(3, 0, KEY_M),
72         KEY(3, 1, KEY_N),
73         KEY(3, 2, KEY_O),
74         KEY(3, 3, KEY_P),
75         KEY(3, 4, KEY_Q),
76         KEY(4, 0, KEY_R),
77         KEY(4, 1, KEY_4),
78         KEY(4, 2, KEY_T),
79         KEY(4, 3, KEY_U),
80         KEY(4, 4, KEY_ENTER),
81         KEY(5, 0, KEY_V),
82         KEY(5, 1, KEY_W),
83         KEY(5, 2, KEY_L),
84         KEY(5, 3, KEY_S),
85         KEY(5, 4, KEY_ENTER),
86         0
87 };
88
89 static struct mtd_partition h4_partitions[] = {
90         /* bootloader (U-Boot, etc) in first sector */
91         {
92               .name             = "bootloader",
93               .offset           = 0,
94               .size             = SZ_128K,
95               .mask_flags       = MTD_WRITEABLE, /* force read-only */
96         },
97         /* bootloader params in the next sector */
98         {
99               .name             = "params",
100               .offset           = MTDPART_OFS_APPEND,
101               .size             = SZ_128K,
102               .mask_flags       = 0,
103         },
104         /* kernel */
105         {
106               .name             = "kernel",
107               .offset           = MTDPART_OFS_APPEND,
108               .size             = SZ_2M,
109               .mask_flags       = 0
110         },
111         /* file system */
112         {
113               .name             = "filesystem",
114               .offset           = MTDPART_OFS_APPEND,
115               .size             = MTDPART_SIZ_FULL,
116               .mask_flags       = 0
117         }
118 };
119
120 static struct flash_platform_data h4_flash_data = {
121         .map_name       = "cfi_probe",
122         .width          = 2,
123         .parts          = h4_partitions,
124         .nr_parts       = ARRAY_SIZE(h4_partitions),
125 };
126
127 static struct resource h4_flash_resource = {
128         .flags          = IORESOURCE_MEM,
129 };
130
131 static struct platform_device h4_flash_device = {
132         .name           = "omapflash",
133         .id             = 0,
134         .dev            = {
135                 .platform_data  = &h4_flash_data,
136         },
137         .num_resources  = 1,
138         .resource       = &h4_flash_resource,
139 };
140
141 /* Select between the IrDA and aGPS module
142  */
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
203 static struct omap_irda_config h4_irda_data = {
204         .transceiver_cap        = IR_SIRMODE | IR_MIRMODE | IR_FIRMODE,
205         .transceiver_mode       = h4_transceiver_mode,
206         .select_irda            = h4_select_irda,
207         .rx_channel             = OMAP24XX_DMA_UART3_RX,
208         .tx_channel             = OMAP24XX_DMA_UART3_TX,
209         .dest_start             = OMAP_UART3_BASE,
210         .src_start              = OMAP_UART3_BASE,
211         .tx_trigger             = OMAP24XX_DMA_UART3_TX,
212         .rx_trigger             = OMAP24XX_DMA_UART3_RX,
213 };
214
215 static struct resource h4_irda_resources[] = {
216         [0] = {
217                 .start  = INT_24XX_UART3_IRQ,
218                 .end    = INT_24XX_UART3_IRQ,
219                 .flags  = IORESOURCE_IRQ,
220         },
221 };
222
223 static struct platform_device h4_irda_device = {
224         .name           = "omapirda",
225         .id             = -1,
226         .dev            = {
227                 .platform_data  = &h4_irda_data,
228         },
229         .num_resources  = 1,
230         .resource       = h4_irda_resources,
231 };
232
233 static struct omap_kp_platform_data h4_kp_data = {
234         .rows           = 6,
235         .cols           = 7,
236         .keymap         = h4_keymap,
237         .keymapsize     = ARRAY_SIZE(h4_keymap),
238         .rep            = 1,
239         .row_gpios      = row_gpios,
240         .col_gpios      = col_gpios,
241 };
242
243 static struct platform_device h4_kp_device = {
244         .name           = "omap-keypad",
245         .id             = -1,
246         .dev            = {
247                 .platform_data = &h4_kp_data,
248         },
249 };
250
251 static struct platform_device h4_lcd_device = {
252         .name           = "lcd_h4",
253         .id             = -1,
254 };
255
256 static struct platform_device *h4_devices[] __initdata = {
257         &h4_flash_device,
258         &h4_irda_device,
259         &h4_kp_device,
260         &h4_lcd_device,
261 };
262
263 /* 2420 Sysboot setup (2430 is different) */
264 static u32 get_sysboot_value(void)
265 {
266         return (omap_ctrl_readl(OMAP24XX_CONTROL_STATUS) &
267                 (OMAP2_SYSBOOT_5_MASK | OMAP2_SYSBOOT_4_MASK |
268                  OMAP2_SYSBOOT_3_MASK | OMAP2_SYSBOOT_2_MASK |
269                  OMAP2_SYSBOOT_1_MASK | OMAP2_SYSBOOT_0_MASK));
270 }
271
272 /* H4-2420's always used muxed mode, H4-2422's always use non-muxed
273  *
274  * Note: OMAP-GIT doesn't correctly do is_cpu_omap2422 and is_cpu_omap2423
275  *  correctly.  The macro needs to look at production_id not just hawkeye.
276  */
277 static u32 is_gpmc_muxed(void)
278 {
279         u32 mux;
280         mux = get_sysboot_value();
281         if ((mux & 0xF) == 0xd)
282                 return 1;       /* NAND config (could be either) */
283         if (mux & 0x2)          /* if mux'ed */
284                 return 1;
285         else
286                 return 0;
287 }
288
289 static inline void __init h4_init_debug(void)
290 {
291         int eth_cs;
292         unsigned long cs_mem_base;
293         unsigned int muxed, rate;
294         struct clk *gpmc_fck;
295
296         eth_cs  = H4_SMC91X_CS;
297
298         gpmc_fck = clk_get(NULL, "gpmc_fck");   /* Always on ENABLE_ON_INIT */
299         if (IS_ERR(gpmc_fck)) {
300                 WARN_ON(1);
301                 return;
302         }
303
304         clk_enable(gpmc_fck);
305         rate = clk_get_rate(gpmc_fck);
306         clk_disable(gpmc_fck);
307         clk_put(gpmc_fck);
308
309         if (is_gpmc_muxed())
310                 muxed = 0x200;
311         else
312                 muxed = 0;
313
314         /* Make sure CS1 timings are correct */
315         gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1,
316                           0x00011000 | muxed);
317
318         if (rate >= 160000000) {
319                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
320                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
321                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
322                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
323                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
324         } else if (rate >= 130000000) {
325                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
326                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
327                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
328                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
329                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
330         } else {/* rate = 100000000 */
331                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
332                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
333                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
334                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x031A1F1F);
335                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
336         }
337
338         if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
339                 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
340                 goto out;
341         }
342
343         udelay(100);
344
345         omap_cfg_reg(M15_24XX_GPIO92);
346         if (debug_card_init(cs_mem_base, H4_ETHR_GPIO_IRQ) < 0)
347                 gpmc_cs_free(eth_cs);
348
349 out:
350         clk_disable(gpmc_fck);
351         clk_put(gpmc_fck);
352 }
353
354 static void __init h4_init_flash(void)
355 {
356         unsigned long base;
357
358         if (gpmc_cs_request(H4_FLASH_CS, SZ_64M, &base) < 0) {
359                 printk("Can't request GPMC CS for flash\n");
360                 return;
361         }
362         h4_flash_resource.start = base;
363         h4_flash_resource.end   = base + SZ_64M - 1;
364 }
365
366 static void __init omap_h4_init_irq(void)
367 {
368         omap2_init_common_hw(NULL);
369         omap_init_irq();
370         omap_gpio_init();
371         h4_init_flash();
372 }
373
374 static struct omap_uart_config h4_uart_config __initdata = {
375         .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
376 };
377
378 static struct omap_lcd_config h4_lcd_config __initdata = {
379         .ctrl_name      = "internal",
380 };
381
382 static struct omap_usb_config h4_usb_config __initdata = {
383 #ifdef  CONFIG_MACH_OMAP2_H4_USB1
384         /* NOTE:  usb1 could also be used with 3 wire signaling */
385         .pins[1]        = 4,
386 #endif
387
388 #ifdef  CONFIG_MACH_OMAP_H4_OTG
389         /* S1.10 ON -- USB OTG port
390          * usb0 switched to Mini-AB port and isp1301 transceiver;
391          * S2.POS3 = OFF, S2.POS4 = ON ... to allow battery charging
392          */
393         .otg            = 1,
394         .pins[0]        = 4,
395 #ifdef  CONFIG_USB_GADGET_OMAP
396         /* use OTG cable, or standard A-to-MiniB */
397         .hmc_mode       = 0x14, /* 0:dev/otg 1:host 2:disable */
398 #elif   defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
399         /* use OTG cable, or NONSTANDARD (B-to-MiniB) */
400         .hmc_mode       = 0x11, /* 0:host 1:host 2:disable */
401 #endif  /* XX */
402
403 #else
404         /* S1.10 OFF -- usb "download port"
405          * usb0 switched to Mini-B port and isp1105 transceiver;
406          * S2.POS3 = ON, S2.POS4 = OFF ... to enable battery charging
407          */
408         .register_dev   = 1,
409         .pins[0]        = 3,
410 /*      .hmc_mode       = 0x14,*/       /* 0:dev 1:host 2:disable */
411         .hmc_mode       = 0x00,         /* 0:dev|otg 1:disable 2:disable */
412 #endif
413 };
414
415 static struct omap_board_config_kernel h4_config[] = {
416         { OMAP_TAG_UART,        &h4_uart_config },
417         { OMAP_TAG_LCD,         &h4_lcd_config },
418 };
419
420 static struct at24_platform_data m24c01 = {
421         .byte_len       = SZ_1K / 8,
422         .page_size      = 16,
423 };
424
425 static struct i2c_board_info __initdata h4_i2c_board_info[] = {
426         {
427                 I2C_BOARD_INFO("isp1301_omap", 0x2d),
428                 .irq            = OMAP_GPIO_IRQ(125),
429         },
430         {       /* EEPROM on mainboard */
431                 I2C_BOARD_INFO("24c01", 0x52),
432                 .platform_data  = &m24c01,
433         },
434         {       /* EEPROM on cpu card */
435                 I2C_BOARD_INFO("24c01", 0x57),
436                 .platform_data  = &m24c01,
437         },
438 };
439
440 static void __init omap_h4_init(void)
441 {
442         /*
443          * Make sure the serial ports are muxed on at this point.
444          * You have to mux them off in device drivers later on
445          * if not needed.
446          */
447 #if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
448         omap_cfg_reg(K15_24XX_UART3_TX);
449         omap_cfg_reg(K14_24XX_UART3_RX);
450 #endif
451
452 #if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
453         if (omap_has_menelaus()) {
454                 row_gpios[5] = 0;
455                 col_gpios[2] = 15;
456                 col_gpios[6] = 18;
457         }
458 #endif
459
460         i2c_register_board_info(1, h4_i2c_board_info,
461                         ARRAY_SIZE(h4_i2c_board_info));
462
463         platform_add_devices(h4_devices, ARRAY_SIZE(h4_devices));
464         omap_board_config = h4_config;
465         omap_board_config_size = ARRAY_SIZE(h4_config);
466         omap_usb_init(&h4_usb_config);
467         omap_serial_init();
468 }
469
470 static void __init omap_h4_map_io(void)
471 {
472         omap2_set_globals_242x();
473         omap2_map_common_io();
474 }
475
476 MACHINE_START(OMAP_H4, "OMAP2420 H4 board")
477         /* Maintainer: Paul Mundt <paul.mundt@nokia.com> */
478         .phys_io        = 0x48000000,
479         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
480         .boot_params    = 0x80000100,
481         .map_io         = omap_h4_map_io,
482         .init_irq       = omap_h4_init_irq,
483         .init_machine   = omap_h4_init,
484         .timer          = &omap_timer,
485 MACHINE_END