]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-2430sdp.c
ARM: OMAP: Clean-up MMC device init
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-2430sdp.c
1 /*
2  * linux/arch/arm/mach-omap2/board-2430sdp.c
3  *
4  * Copyright (C) 2006 Texas Instruments
5  *
6  * Modified from mach-omap2/board-generic.c
7  *
8  * Initial Code : Based on a patch from Komal Shah and Richard Woodruff
9  * Updated the Code for 2430 SDP : Syed Mohammed Khasim
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2 as
13  * published by the Free Software Foundation.
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/mtd/mtd.h>
20 #include <linux/mtd/partitions.h>
21 #include <linux/delay.h>
22 #include <linux/input.h>
23 #include <linux/i2c/twl4030.h>
24 #include <linux/err.h>
25 #include <linux/clk.h>
26 #include <linux/spi/spi.h>
27 #include <linux/spi/ads7846.h>
28 #include <linux/i2c/twl4030-rtc.h>
29
30 #include <mach/hardware.h>
31 #include <asm/mach-types.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
34 #include <asm/mach/flash.h>
35
36 #include <mach/gpio.h>
37 #include <mach/mux.h>
38 #include <mach/board.h>
39 #include <mach/usb-musb.h>
40 #include <mach/hsmmc.h>
41 #include <mach/common.h>
42 #include <mach/keypad.h>
43 #include <mach/gpmc.h>
44 #include <mach/mcspi.h>
45
46 #include <asm/io.h>
47
48 #define SDP2430_FLASH_CS        0
49 #define SDP2430_SMC91X_CS       5
50
51 /* GPIO used for TSC2046 (touchscreen)
52  *
53  * Also note that the tsc2046 is the same silicon as the ads7846, so
54  * that driver is used for the touchscreen. */
55 #define TS_GPIO                 24
56
57 #define TWL4030_MSECURE_GPIO    118
58 #define SECONDARY_LCD_GPIO      147
59
60 static struct mtd_partition sdp2430_partitions[] = {
61         /* bootloader (U-Boot, etc) in first sector */
62         {
63                 .name           = "bootloader",
64                 .offset         = 0,
65                 .size           = SZ_256K,
66                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
67          },
68         /* bootloader params in the next sector */
69         {
70                 .name           = "params",
71                 .offset         = MTDPART_OFS_APPEND,
72                 .size           = SZ_128K,
73                 .mask_flags     = 0,
74          },
75         /* kernel */
76         {
77                 .name           = "kernel",
78                 .offset         = MTDPART_OFS_APPEND,
79                 .size           = SZ_2M,
80                 .mask_flags     = 0
81         },
82         /* file system */
83         {
84                 .name           = "filesystem",
85                 .offset         = MTDPART_OFS_APPEND,
86                 .size           = MTDPART_SIZ_FULL,
87                 .mask_flags     = 0
88         }
89 };
90
91 static struct flash_platform_data sdp2430_flash_data = {
92         .map_name       = "cfi_probe",
93         .width          = 2,
94         .parts          = sdp2430_partitions,
95         .nr_parts       = ARRAY_SIZE(sdp2430_partitions),
96 };
97
98 static struct resource sdp2430_flash_resource = {
99         .start          = SDP2430_CS0_BASE,
100         .end            = SDP2430_CS0_BASE + SZ_64M - 1,
101         .flags          = IORESOURCE_MEM,
102 };
103
104 static struct platform_device sdp2430_flash_device = {
105         .name           = "omapflash",
106         .id             = 0,
107         .dev = {
108                 .platform_data  = &sdp2430_flash_data,
109         },
110         .num_resources  = 1,
111         .resource       = &sdp2430_flash_resource,
112 };
113
114 static struct resource sdp2430_smc91x_resources[] = {
115         [0] = {
116                 .start  = SDP2430_CS0_BASE,
117                 .end    = SDP2430_CS0_BASE + SZ_64M - 1,
118                 .flags  = IORESOURCE_MEM,
119         },
120         [1] = {
121                 .start  = OMAP_GPIO_IRQ(OMAP24XX_ETHR_GPIO_IRQ),
122                 .end    = OMAP_GPIO_IRQ(OMAP24XX_ETHR_GPIO_IRQ),
123                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
124         },
125 };
126
127 static struct platform_device sdp2430_lcd_device = {
128         .name           = "sdp2430_lcd",
129         .id             = -1,
130 };
131
132 static struct platform_device sdp2430_smc91x_device = {
133         .name           = "smc91x",
134         .id             = -1,
135         .num_resources  = ARRAY_SIZE(sdp2430_smc91x_resources),
136         .resource       = sdp2430_smc91x_resources,
137 };
138
139 /*
140  * Key mapping for 2430 SDP board
141  */
142
143 static int sdp2430_keymap[] = {
144         KEY(0, 0, KEY_LEFT),
145         KEY(0, 1, KEY_RIGHT),
146         KEY(0, 2, KEY_A),
147         KEY(0, 3, KEY_B),
148         KEY(0, 4, KEY_C),
149         KEY(1, 0, KEY_DOWN),
150         KEY(1, 1, KEY_UP),
151         KEY(1, 2, KEY_E),
152         KEY(1, 3, KEY_F),
153         KEY(1, 4, KEY_G),
154         KEY(2, 0, KEY_ENTER),
155         KEY(2, 1, KEY_I),
156         KEY(2, 2, KEY_J),
157         KEY(2, 3, KEY_K),
158         KEY(2, 4, KEY_3),
159         KEY(3, 0, KEY_M),
160         KEY(3, 1, KEY_N),
161         KEY(3, 2, KEY_O),
162         KEY(3, 3, KEY_P),
163         KEY(3, 4, KEY_Q),
164         KEY(4, 0, KEY_R),
165         KEY(4, 1, KEY_4),
166         KEY(4, 2, KEY_T),
167         KEY(4, 3, KEY_U),
168         KEY(4, 4, KEY_D),
169         KEY(5, 0, KEY_V),
170         KEY(5, 1, KEY_W),
171         KEY(5, 2, KEY_L),
172         KEY(5, 3, KEY_S),
173         KEY(5, 4, KEY_H),
174         0
175 };
176
177 static struct omap_kp_platform_data sdp2430_kp_data = {
178         .rows           = 5,
179         .cols           = 6,
180         .keymap         = sdp2430_keymap,
181         .keymapsize     = ARRAY_SIZE(sdp2430_keymap),
182         .rep            = 1,
183         .irq            = TWL4030_MODIRQ_KEYPAD,
184 };
185
186 static struct platform_device sdp2430_kp_device = {
187         .name           = "omap_twl4030keypad",
188         .id             = -1,
189         .dev            = {
190                 .platform_data  = &sdp2430_kp_data,
191         },
192 };
193
194 static int twl4030_rtc_init(void)
195 {
196         int ret = 0;
197
198         ret = omap_request_gpio(TWL4030_MSECURE_GPIO);
199         if (ret < 0) {
200                 printk(KERN_ERR "twl4030_rtc_init: can't reserve GPIO:%d !\n",
201                         TWL4030_MSECURE_GPIO);
202                 goto out;
203         }
204         /*
205          * TWL4030 will be in secure mode if msecure line from OMAP is low.
206          * Make msecure line high in order to change the TWL4030 RTC time
207          * and calender registers.
208          */
209         omap_set_gpio_direction(TWL4030_MSECURE_GPIO, 0);       /*dir out */
210         omap_set_gpio_dataout(TWL4030_MSECURE_GPIO, 1);
211 out:
212         return ret;
213 }
214
215 static void twl4030_rtc_exit(void)
216 {
217         omap_free_gpio(TWL4030_MSECURE_GPIO);
218 }
219
220 static struct twl4030rtc_platform_data sdp2430_twl4030rtc_data = {
221         .init = &twl4030_rtc_init,
222         .exit = &twl4030_rtc_exit,
223 };
224
225 static struct platform_device sdp2430_twl4030rtc_device = {
226         .name           = "twl4030_rtc",
227         .id             = -1,
228         .dev            = {
229                 .platform_data  = &sdp2430_twl4030rtc_data,
230         },
231 };
232
233 static struct platform_device *sdp2430_devices[] __initdata = {
234         &sdp2430_smc91x_device,
235         &sdp2430_flash_device,
236         &sdp2430_kp_device,
237         &sdp2430_lcd_device,
238         &sdp2430_twl4030rtc_device,     
239 };
240
241 static void ads7846_dev_init(void)
242 {
243         if (omap_request_gpio(TS_GPIO) < 0)
244                 printk(KERN_ERR "can't get ads746 pen down GPIO\n");
245
246         omap_set_gpio_direction(TS_GPIO, 1);
247
248         omap_set_gpio_debounce(TS_GPIO, 1);
249         omap_set_gpio_debounce_time(TS_GPIO, 0xa);
250 }
251
252 static int ads7846_get_pendown_state(void)
253 {
254         return !omap_get_gpio_datain(TS_GPIO);
255 }
256
257 static struct ads7846_platform_data tsc2046_config __initdata = {
258         .get_pendown_state = ads7846_get_pendown_state,
259         .keep_vref_on      = 1,
260 };
261
262 static struct omap2_mcspi_device_config tsc2046_mcspi_config = {
263         .turbo_mode     = 0,
264         .single_channel = 0,  /* 0: slave, 1: master */
265 };
266
267 static struct omap_lcd_config sdp2430_lcd_config __initdata = {
268         .ctrl_name      = "internal",
269 };
270
271 static struct spi_board_info sdp2430_spi_board_info[] __initdata = {
272         [0] = {
273                 /*
274                  * TSC2046 operates at a max freqency of 2MHz, so
275                  * operate slightly below at 1.5MHz
276                  */
277                 .modalias        = "ads7846",
278                 .bus_num         = 1,
279                 .chip_select     = 0,
280                 .max_speed_hz    = 1500000,
281                 .controller_data = &tsc2046_mcspi_config,
282                 .irq             = OMAP_GPIO_IRQ(TS_GPIO),
283                 .platform_data   = &tsc2046_config,
284         },
285 };
286
287 static inline void __init sdp2430_init_smc91x(void)
288 {
289         int eth_cs;
290         unsigned long cs_mem_base;
291         unsigned int rate;
292         struct clk *gpmc_fck;
293
294         eth_cs = SDP2430_SMC91X_CS;
295
296         gpmc_fck = clk_get(NULL, "gpmc_fck");   /* Always on ENABLE_ON_INIT */
297         if (IS_ERR(gpmc_fck)) {
298                 WARN_ON(1);
299                 return;
300         }
301
302         clk_enable(gpmc_fck);
303         rate = clk_get_rate(gpmc_fck);
304
305         /* Make sure CS1 timings are correct, for 2430 always muxed */
306         gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1, 0x00011200);
307
308         if (rate >= 160000000) {
309                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
310                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
311                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
312                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
313                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
314         } else if (rate >= 130000000) {
315                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
316                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
317                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
318                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
319                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
320         } else { /* rate = 100000000 */
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, 0x031A1F1F);
325                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
326         }
327
328         if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
329                 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
330                 goto out;
331         }
332
333         sdp2430_smc91x_resources[0].start = cs_mem_base + 0x300;
334         sdp2430_smc91x_resources[0].end = cs_mem_base + 0x30f;
335         udelay(100);
336
337         if (omap_request_gpio(OMAP24XX_ETHR_GPIO_IRQ) < 0) {
338                 printk(KERN_ERR "Failed to request GPIO%d for smc91x IRQ\n",
339                         OMAP24XX_ETHR_GPIO_IRQ);
340                 gpmc_cs_free(eth_cs);
341                 goto out;
342         }
343         omap_set_gpio_direction(OMAP24XX_ETHR_GPIO_IRQ, 1);
344
345 out:
346         clk_disable(gpmc_fck);
347         clk_put(gpmc_fck);
348 }
349
350 static void __init omap_2430sdp_init_irq(void)
351 {
352         omap2_init_common_hw(NULL);
353         omap_init_irq();
354         omap_gpio_init();
355         sdp2430_init_smc91x();
356 }
357
358 static struct omap_uart_config sdp2430_uart_config __initdata = {
359         .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
360 };
361
362 static
363 struct omap_serial_console_config sdp2430_serial_console_config __initdata = {
364         .console_uart = 1,
365         .console_speed = 115200,
366 };
367
368 static struct omap_board_config_kernel sdp2430_config[] __initdata = {
369         {OMAP_TAG_UART, &sdp2430_uart_config},
370         {OMAP_TAG_LCD, &sdp2430_lcd_config},
371         {OMAP_TAG_SERIAL_CONSOLE, &sdp2430_serial_console_config},
372 };
373
374 static int __init omap2430_i2c_init(void)
375 {
376         /*
377          * Registering bus 2 first to avoid twl4030 misbehaving as 2430SDP
378          * has twl4030 on bus 2
379          */
380         omap_register_i2c_bus(2, 2600, NULL, 0);
381         omap_register_i2c_bus(1, 400, NULL, 0);
382         return 0;
383 }
384
385 static void __init omap_2430sdp_init(void)
386 {
387         platform_add_devices(sdp2430_devices, ARRAY_SIZE(sdp2430_devices));
388         omap_board_config = sdp2430_config;
389         omap_board_config_size = ARRAY_SIZE(sdp2430_config);
390         omap_serial_init();
391
392         sdp2430_flash_init();
393         usb_musb_init();
394
395         spi_register_board_info(sdp2430_spi_board_info,
396                                 ARRAY_SIZE(sdp2430_spi_board_info));
397         ads7846_dev_init();
398         hsmmc_init();
399
400         /* turn off secondary LCD backlight */
401         omap_set_gpio_direction(SECONDARY_LCD_GPIO, 0);
402         omap_set_gpio_dataout(SECONDARY_LCD_GPIO, 0);
403 }
404
405 static void __init omap_2430sdp_map_io(void)
406 {
407         omap2_set_globals_243x();
408         omap2_map_common_io();
409 }
410
411 arch_initcall(omap2430_i2c_init);
412
413 MACHINE_START(OMAP_2430SDP, "OMAP2430 sdp2430 board")
414         /* Maintainer: Syed Khasim - Texas Instruments Inc */
415         .phys_io        = 0x48000000,
416         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
417         .boot_params    = 0x80000100,
418         .map_io         = omap_2430sdp_map_io,
419         .init_irq       = omap_2430sdp_init_irq,
420         .init_machine   = omap_2430sdp_init,
421         .timer          = &omap_timer,
422 MACHINE_END