]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-h4.c
[PATCH] ARM: OMAP: Use gpmc_cs_get_base_addr for H4 smc91x
[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 static unsigned int row_gpios[6] = { 88, 89, 124, 11, 6, 96 };
48 static unsigned int col_gpios[7] = { 90, 91, 100, 36, 12, 97, 98 };
49
50 static int h4_keymap[] = {
51         KEY(0, 0, KEY_LEFT),
52         KEY(0, 1, KEY_RIGHT),
53         KEY(0, 2, KEY_A),
54         KEY(0, 3, KEY_B),
55         KEY(0, 4, KEY_C),
56         KEY(1, 0, KEY_DOWN),
57         KEY(1, 1, KEY_UP),
58         KEY(1, 2, KEY_E),
59         KEY(1, 3, KEY_F),
60         KEY(1, 4, KEY_G),
61         KEY(2, 0, KEY_ENTER),
62         KEY(2, 1, KEY_I),
63         KEY(2, 2, KEY_J),
64         KEY(2, 3, KEY_K),
65         KEY(2, 4, KEY_3),
66         KEY(3, 0, KEY_M),
67         KEY(3, 1, KEY_N),
68         KEY(3, 2, KEY_O),
69         KEY(3, 3, KEY_P),
70         KEY(3, 4, KEY_Q),
71         KEY(4, 0, KEY_R),
72         KEY(4, 1, KEY_4),
73         KEY(4, 2, KEY_T),
74         KEY(4, 3, KEY_U),
75         KEY(4, 4, KEY_ENTER),
76         KEY(5, 0, KEY_V),
77         KEY(5, 1, KEY_W),
78         KEY(5, 2, KEY_L),
79         KEY(5, 3, KEY_S),
80         KEY(5, 4, KEY_ENTER),
81         0
82 };
83
84 static struct mtd_partition h4_partitions[] = {
85         /* bootloader (U-Boot, etc) in first sector */
86         {
87               .name             = "bootloader",
88               .offset           = 0,
89               .size             = SZ_128K,
90               .mask_flags       = MTD_WRITEABLE, /* force read-only */
91         },
92         /* bootloader params in the next sector */
93         {
94               .name             = "params",
95               .offset           = MTDPART_OFS_APPEND,
96               .size             = SZ_128K,
97               .mask_flags       = 0,
98         },
99         /* kernel */
100         {
101               .name             = "kernel",
102               .offset           = MTDPART_OFS_APPEND,
103               .size             = SZ_2M,
104               .mask_flags       = 0
105         },
106         /* file system */
107         {
108               .name             = "filesystem",
109               .offset           = MTDPART_OFS_APPEND,
110               .size             = MTDPART_SIZ_FULL,
111               .mask_flags       = 0
112         }
113 };
114
115 static struct flash_platform_data h4_flash_data = {
116         .map_name       = "cfi_probe",
117         .width          = 2,
118         .parts          = h4_partitions,
119         .nr_parts       = ARRAY_SIZE(h4_partitions),
120 };
121
122 static struct resource h4_flash_resource = {
123         .start          = H4_CS0_BASE,
124         .end            = H4_CS0_BASE + SZ_64M - 1,
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 static struct resource h4_smc91x_resources[] = {
139         [0] = {
140                 .flags  = IORESOURCE_MEM,
141         },
142         [1] = {
143                 .start  = OMAP_GPIO_IRQ(OMAP24XX_ETHR_GPIO_IRQ),
144                 .end    = OMAP_GPIO_IRQ(OMAP24XX_ETHR_GPIO_IRQ),
145                 .flags  = IORESOURCE_IRQ,
146         },
147 };
148
149 static struct platform_device h4_smc91x_device = {
150         .name           = "smc91x",
151         .id             = -1,
152         .num_resources  = ARRAY_SIZE(h4_smc91x_resources),
153         .resource       = h4_smc91x_resources,
154 };
155
156 /* Select between the IrDA and aGPS module
157  */
158 static int h4_select_irda(struct device *dev, int state)
159 {
160         unsigned char expa;
161         int err = 0;
162
163         if ((err = read_gpio_expa(&expa, 0x21))) {
164                 printk(KERN_ERR "Error reading from I/O expander\n");
165                 return err;
166         }
167
168         /* 'P6' enable/disable IRDA_TX and IRDA_RX */
169         if (state & IR_SEL) {   /* IrDa */
170                 if ((err = write_gpio_expa(expa | 0x01, 0x21))) {
171                         printk(KERN_ERR "Error writing to I/O expander\n");
172                         return err;
173                 }
174         } else {
175                 if ((err = write_gpio_expa(expa & ~0x01, 0x21))) {
176                         printk(KERN_ERR "Error writing to I/O expander\n");
177                         return err;
178                 }
179         }
180         return err;
181 }
182
183 static void set_trans_mode(void *data)
184 {
185         int *mode = data;
186         unsigned char expa;
187         int err = 0;
188
189         if ((err = read_gpio_expa(&expa, 0x20)) != 0) {
190                 printk(KERN_ERR "Error reading from I/O expander\n");
191         }
192
193         expa &= ~0x01;
194
195         if (!(*mode & IR_SIRMODE)) { /* MIR/FIR */
196                 expa |= 0x01;
197         }
198
199         if ((err = write_gpio_expa(expa, 0x20)) != 0) {
200                 printk(KERN_ERR "Error writing to I/O expander\n");
201         }
202 }
203
204 static int h4_transceiver_mode(struct device *dev, int mode)
205 {
206         struct omap_irda_config *irda_config = dev->platform_data;
207
208         cancel_delayed_work(&irda_config->gpio_expa);
209         PREPARE_WORK(&irda_config->gpio_expa, set_trans_mode, &mode);
210         schedule_work(&irda_config->gpio_expa);
211
212         return 0;
213 }
214
215 static struct omap_irda_config h4_irda_data = {
216         .transceiver_cap        = IR_SIRMODE | IR_MIRMODE | IR_FIRMODE,
217         .transceiver_mode       = h4_transceiver_mode,
218         .select_irda            = h4_select_irda,
219         .rx_channel             = OMAP24XX_DMA_UART3_RX,
220         .tx_channel             = OMAP24XX_DMA_UART3_TX,
221         .dest_start             = OMAP_UART3_BASE,
222         .src_start              = OMAP_UART3_BASE,
223         .tx_trigger             = OMAP24XX_DMA_UART3_TX,
224         .rx_trigger             = OMAP24XX_DMA_UART3_RX,
225 };
226
227 static struct resource h4_irda_resources[] = {
228         [0] = {
229                 .start  = INT_24XX_UART3_IRQ,
230                 .end    = INT_24XX_UART3_IRQ,
231                 .flags  = IORESOURCE_IRQ,
232         },
233 };
234
235 static struct platform_device h4_irda_device = {
236         .name           = "omapirda",
237         .id             = -1,
238         .dev            = {
239                 .platform_data  = &h4_irda_data,
240         },
241         .num_resources  = 1,
242         .resource       = h4_irda_resources,
243 };
244
245 static struct omap_kp_platform_data h4_kp_data = {
246         .rows           = 6,
247         .cols           = 7,
248         .keymap         = h4_keymap,
249         .rep            = 1,
250         .row_gpios      = row_gpios,
251         .col_gpios      = col_gpios,
252 };
253
254 static struct platform_device h4_kp_device = {
255         .name           = "omap-keypad",
256         .id             = -1,
257         .dev            = {
258                 .platform_data = &h4_kp_data,
259         },
260 };
261
262 static struct platform_device h4_lcd_device = {
263         .name           = "lcd_h4",
264         .id             = -1,
265 };
266
267 static struct platform_device *h4_devices[] __initdata = {
268         &h4_smc91x_device,
269         &h4_flash_device,
270         &h4_irda_device,
271         &h4_kp_device,
272         &h4_lcd_device,
273 };
274
275 /* 2420 Sysboot setup (2430 is different) */
276 static u32 get_sysboot_value(void)
277 {
278         return (omap_readl(OMAP242X_CONTROL_STATUS) & 0xFFF);
279 }
280
281 /* FIXME: This function should be moved to some other file, gpmc.c? */
282
283 /* H4-2420's always used muxed mode, H4-2422's always use non-muxed
284  *
285  * Note: OMAP-GIT doesn't correctly do is_cpu_omap2422 and is_cpu_omap2423
286  *  correctly.  The macro needs to look at production_id not just hawkeye.
287  */
288 static u32 is_gpmc_muxed(void)
289 {
290         u32 mux;
291         mux = get_sysboot_value();
292         if ((mux & 0xF) == 0xd)
293                 return 1;       /* NAND config (could be either) */
294         if (mux & 0x2)          /* if mux'ed */
295                 return 1;
296         else
297                 return 0;
298 }
299
300 #define SMC91X_CS       1
301
302 static inline void __init h4_init_smc91x(void)
303 {
304         int eth_cs;
305         unsigned int muxed, rate;
306         struct clk *l3ck;
307
308         eth_cs  = SMC91X_CS;
309
310         l3ck = clk_get(NULL, "core_l3_ck");
311         if (IS_ERR(l3ck))
312                 rate = 100000000;
313         else
314                 rate = clk_get_rate(l3ck);
315
316         if (is_gpmc_muxed())
317                 muxed = 0x200;
318         else
319                 muxed = 0;
320
321         /* Make sure CS1 timings are correct */
322         gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1,
323                           0x00011000 | muxed);
324
325         if (rate >= 160000000) {
326                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
327                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
328                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
329                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
330                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
331         } else if (rate >= 130000000) {
332                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
333                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
334                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
335                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
336                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
337         } else {/* rate = 100000000 */
338                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
339                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
340                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
341                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x031A1F1F);
342                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
343         }
344
345         gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG7,
346                           0x00000f40 | (0x08000000 >> 24));
347         udelay(100);
348
349         omap_cfg_reg(M15_24XX_GPIO92);
350         if (omap_request_gpio(OMAP24XX_ETHR_GPIO_IRQ) < 0) {
351                 printk(KERN_ERR "Failed to request GPIO%d for smc91x IRQ\n",
352                         OMAP24XX_ETHR_GPIO_IRQ);
353                 return;
354         }
355         omap_set_gpio_direction(OMAP24XX_ETHR_GPIO_IRQ, 1);
356
357         h4_smc91x_resources[0].start = gpmc_cs_get_base_addr(1) + 0x300;
358         h4_smc91x_resources[0].end   = h4_smc91x_resources[0].start + 0xf;
359 }
360
361 static void __init omap_h4_init_irq(void)
362 {
363         omap2_init_common_hw();
364         omap_init_irq();
365         omap_gpio_init();
366         h4_init_smc91x();
367 }
368
369 static struct omap_uart_config h4_uart_config __initdata = {
370         .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
371 };
372
373 static struct omap_mmc_config h4_mmc_config __initdata = {
374         .mmc [0] = {
375                 .enabled        = 1,
376                 .wire4          = 1,
377                 .wp_pin         = -1,
378                 .power_pin      = -1,
379                 .switch_pin     = -1,
380         },
381 };
382
383 static struct omap_lcd_config h4_lcd_config __initdata = {
384         .ctrl_name      = "internal",
385 };
386
387 static struct omap_board_config_kernel h4_config[] = {
388         { OMAP_TAG_UART,        &h4_uart_config },
389         { OMAP_TAG_MMC,         &h4_mmc_config },
390         { OMAP_TAG_LCD,         &h4_lcd_config },
391 };
392
393 static void __init omap_h4_init(void)
394 {
395         /*
396          * Make sure the serial ports are muxed on at this point.
397          * You have to mux them off in device drivers later on
398          * if not needed.
399          */
400 #if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
401         omap_cfg_reg(K15_24XX_UART3_TX);
402         omap_cfg_reg(K14_24XX_UART3_RX);
403 #endif
404
405 #if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
406         if (omap_has_menelaus()) {
407                 row_gpios[5] = 0;
408                 col_gpios[2] = 15;
409                 col_gpios[6] = 18;
410         }
411 #endif
412
413         platform_add_devices(h4_devices, ARRAY_SIZE(h4_devices));
414         omap_board_config = h4_config;
415         omap_board_config_size = ARRAY_SIZE(h4_config);
416         omap_serial_init();
417 }
418
419 static void __init omap_h4_map_io(void)
420 {
421         omap2_map_common_io();
422 }
423
424 MACHINE_START(OMAP_H4, "OMAP2420 H4 board")
425         /* Maintainer: Paul Mundt <paul.mundt@nokia.com> */
426         .phys_io        = 0x48000000,
427         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
428         .boot_params    = 0x80000100,
429         .map_io         = omap_h4_map_io,
430         .init_irq       = omap_h4_init_irq,
431         .init_machine   = omap_h4_init,
432         .timer          = &omap_timer,
433 MACHINE_END