]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-h4.c
[PATCH] ARM: OMAP: rework mutex_init() for RT compatibility
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-h4.c
1 /*
2  * linux/arch/arm/mach-omap/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 #include <asm/delay.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 static struct resource h4_smc91x_resources[] = {
140         [0] = {
141                 .flags  = IORESOURCE_MEM,
142         },
143         [1] = {
144                 .start  = OMAP_GPIO_IRQ(OMAP24XX_ETHR_GPIO_IRQ),
145                 .end    = OMAP_GPIO_IRQ(OMAP24XX_ETHR_GPIO_IRQ),
146                 .flags  = IORESOURCE_IRQ,
147         },
148 };
149
150 static struct platform_device h4_smc91x_device = {
151         .name           = "smc91x",
152         .id             = -1,
153         .num_resources  = ARRAY_SIZE(h4_smc91x_resources),
154         .resource       = h4_smc91x_resources,
155 };
156
157 /* Select between the IrDA and aGPS module
158  */
159 #if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
160 static int h4_select_irda(struct device *dev, int state)
161 {
162         unsigned char expa;
163         int err = 0;
164
165         if ((err = read_gpio_expa(&expa, 0x21))) {
166                 printk(KERN_ERR "Error reading from I/O expander\n");
167                 return err;
168         }
169
170         /* 'P6' enable/disable IRDA_TX and IRDA_RX */
171         if (state & IR_SEL) {   /* IrDa */
172                 if ((err = write_gpio_expa(expa | 0x01, 0x21))) {
173                         printk(KERN_ERR "Error writing to I/O expander\n");
174                         return err;
175                 }
176         } else {
177                 if ((err = write_gpio_expa(expa & ~0x01, 0x21))) {
178                         printk(KERN_ERR "Error writing to I/O expander\n");
179                         return err;
180                 }
181         }
182         return err;
183 }
184
185 static void set_trans_mode(void *data)
186 {
187         int *mode = data;
188         unsigned char expa;
189         int err = 0;
190
191         if ((err = read_gpio_expa(&expa, 0x20)) != 0) {
192                 printk(KERN_ERR "Error reading from I/O expander\n");
193         }
194
195         expa &= ~0x01;
196
197         if (!(*mode & IR_SIRMODE)) { /* MIR/FIR */
198                 expa |= 0x01;
199         }
200
201         if ((err = write_gpio_expa(expa, 0x20)) != 0) {
202                 printk(KERN_ERR "Error writing to I/O expander\n");
203         }
204 }
205
206 static int h4_transceiver_mode(struct device *dev, int mode)
207 {
208         struct omap_irda_config *irda_config = dev->platform_data;
209
210         cancel_delayed_work(&irda_config->gpio_expa);
211         PREPARE_WORK(&irda_config->gpio_expa, set_trans_mode, &mode);
212         schedule_work(&irda_config->gpio_expa);
213
214         return 0;
215 }
216 #else
217 static int h4_select_irda(struct device *dev, int state) { return 0; }
218 static int h4_transceiver_mode(struct device *dev, int mode) { return 0; }
219 #endif
220
221 static struct omap_irda_config h4_irda_data = {
222         .transceiver_cap        = IR_SIRMODE | IR_MIRMODE | IR_FIRMODE,
223         .transceiver_mode       = h4_transceiver_mode,
224         .select_irda            = h4_select_irda,
225         .rx_channel             = OMAP24XX_DMA_UART3_RX,
226         .tx_channel             = OMAP24XX_DMA_UART3_TX,
227         .dest_start             = OMAP_UART3_BASE,
228         .src_start              = OMAP_UART3_BASE,
229         .tx_trigger             = OMAP24XX_DMA_UART3_TX,
230         .rx_trigger             = OMAP24XX_DMA_UART3_RX,
231 };
232
233 static struct resource h4_irda_resources[] = {
234         [0] = {
235                 .start  = INT_24XX_UART3_IRQ,
236                 .end    = INT_24XX_UART3_IRQ,
237                 .flags  = IORESOURCE_IRQ,
238         },
239 };
240
241 static struct platform_device h4_irda_device = {
242         .name           = "omapirda",
243         .id             = -1,
244         .dev            = {
245                 .platform_data  = &h4_irda_data,
246         },
247         .num_resources  = 1,
248         .resource       = h4_irda_resources,
249 };
250
251 static struct omap_kp_platform_data h4_kp_data = {
252         .rows           = 6,
253         .cols           = 7,
254         .keymap         = h4_keymap,
255         .rep            = 1,
256         .row_gpios      = row_gpios,
257         .col_gpios      = col_gpios,
258 };
259
260 static struct platform_device h4_kp_device = {
261         .name           = "omap-keypad",
262         .id             = -1,
263         .dev            = {
264                 .platform_data = &h4_kp_data,
265         },
266 };
267
268 static struct platform_device h4_lcd_device = {
269         .name           = "lcd_h4",
270         .id             = -1,
271 };
272
273 static struct platform_device *h4_devices[] __initdata = {
274         &h4_smc91x_device,
275         &h4_flash_device,
276         &h4_irda_device,
277         &h4_kp_device,
278         &h4_lcd_device,
279 };
280
281 /* 2420 Sysboot setup (2430 is different) */
282 static u32 get_sysboot_value(void)
283 {
284         return (omap_readl(OMAP242X_CONTROL_STATUS) & 0xFFF);
285 }
286
287 /* FIXME: This function should be moved to some other file, gpmc.c? */
288
289 /* H4-2420's always used muxed mode, H4-2422's always use non-muxed
290  *
291  * Note: OMAP-GIT doesn't correctly do is_cpu_omap2422 and is_cpu_omap2423
292  *  correctly.  The macro needs to look at production_id not just hawkeye.
293  */
294 static u32 is_gpmc_muxed(void)
295 {
296         u32 mux;
297         mux = get_sysboot_value();
298         if ((mux & 0xF) == 0xd)
299                 return 1;       /* NAND config (could be either) */
300         if (mux & 0x2)          /* if mux'ed */
301                 return 1;
302         else
303                 return 0;
304 }
305
306 static inline void __init h4_init_smc91x(void)
307 {
308         int eth_cs;
309         unsigned long cs_mem_base;
310         unsigned int muxed, rate;
311         struct clk *l3ck;
312
313         eth_cs  = H4_SMC91X_CS;
314
315         l3ck = clk_get(NULL, "core_l3_ck");
316         if (IS_ERR(l3ck))
317                 rate = 100000000;
318         else
319                 rate = clk_get_rate(l3ck);
320
321         if (is_gpmc_muxed())
322                 muxed = 0x200;
323         else
324                 muxed = 0;
325
326         /* Make sure CS1 timings are correct */
327         gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1,
328                           0x00011000 | muxed);
329
330         if (rate >= 160000000) {
331                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
332                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
333                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
334                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
335                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
336         } else if (rate >= 130000000) {
337                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
338                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
339                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
340                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
341                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
342         } else {/* rate = 100000000 */
343                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
344                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
345                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
346                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x031A1F1F);
347                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
348         }
349
350         if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
351                 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
352                 return;
353         }
354         h4_smc91x_resources[0].start = cs_mem_base + 0x300;
355         h4_smc91x_resources[0].end   = cs_mem_base + 0x30f;
356         udelay(100);
357
358         omap_cfg_reg(M15_24XX_GPIO92);
359         if (omap_request_gpio(OMAP24XX_ETHR_GPIO_IRQ) < 0) {
360                 printk(KERN_ERR "Failed to request GPIO%d for smc91x IRQ\n",
361                         OMAP24XX_ETHR_GPIO_IRQ);
362                 gpmc_cs_free(eth_cs);
363                 return;
364         }
365         omap_set_gpio_direction(OMAP24XX_ETHR_GPIO_IRQ, 1);
366
367 }
368
369 static void __init h4_init_flash(void)
370 {
371         unsigned long base;
372
373         if (gpmc_cs_request(H4_FLASH_CS, SZ_64M, &base) < 0) {
374                 printk("Can't request GPMC CS for flash\n");
375                 return;
376         }
377         h4_flash_resource.start = base;
378         h4_flash_resource.end   = base + SZ_64M - 1;
379 }
380
381 static void __init omap_h4_init_irq(void)
382 {
383         omap2_init_common_hw();
384         omap_init_irq();
385         omap_gpio_init();
386         h4_init_smc91x();
387         h4_init_flash();
388 }
389
390 static struct omap_uart_config h4_uart_config __initdata = {
391         .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
392 };
393
394 static struct omap_mmc_config h4_mmc_config __initdata = {
395         .mmc [0] = {
396                 .enabled        = 1,
397                 .wire4          = 1,
398                 .wp_pin         = -1,
399                 .power_pin      = -1,
400                 .switch_pin     = -1,
401         },
402 };
403
404 static struct omap_lcd_config h4_lcd_config __initdata = {
405         .ctrl_name      = "internal",
406 };
407
408 static struct omap_board_config_kernel h4_config[] = {
409         { OMAP_TAG_UART,        &h4_uart_config },
410         { OMAP_TAG_MMC,         &h4_mmc_config },
411         { OMAP_TAG_LCD,         &h4_lcd_config },
412 };
413
414 static void __init omap_h4_init(void)
415 {
416         /*
417          * Make sure the serial ports are muxed on at this point.
418          * You have to mux them off in device drivers later on
419          * if not needed.
420          */
421 #if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
422         omap_cfg_reg(K15_24XX_UART3_TX);
423         omap_cfg_reg(K14_24XX_UART3_RX);
424 #endif
425
426 #if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
427         if (omap_has_menelaus()) {
428                 row_gpios[5] = 0;
429                 col_gpios[2] = 15;
430                 col_gpios[6] = 18;
431         }
432 #endif
433
434         platform_add_devices(h4_devices, ARRAY_SIZE(h4_devices));
435         omap_board_config = h4_config;
436         omap_board_config_size = ARRAY_SIZE(h4_config);
437         omap_serial_init();
438 }
439
440 static void __init omap_h4_map_io(void)
441 {
442         omap2_map_common_io();
443 }
444
445 MACHINE_START(OMAP_H4, "OMAP2420 H4 board")
446         /* Maintainer: Paul Mundt <paul.mundt@nokia.com> */
447         .phys_io        = 0x48000000,
448         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
449         .boot_params    = 0x80000100,
450         .map_io         = omap_h4_map_io,
451         .init_irq       = omap_h4_init_irq,
452         .init_machine   = omap_h4_init,
453         .timer          = &omap_timer,
454 MACHINE_END