]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-3430sdp.c
Merge current mainline tree into linux-omap tree
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-3430sdp.c
1 /*
2  * linux/arch/arm/mach-omap2/board-3430sdp.c
3  *
4  * Copyright (C) 2007 Texas Instruments
5  *
6  * Modified from mach-omap2/board-generic.c
7  *
8  * Initial code: Syed Mohammed Khasim
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19 #include <linux/input.h>
20 #include <linux/workqueue.h>
21 #include <linux/err.h>
22 #include <linux/clk.h>
23 #include <linux/i2c/twl4030.h>
24 #include <linux/spi/spi.h>
25 #include <linux/spi/ads7846.h>
26
27 #include <mach/hardware.h>
28 #include <asm/mach-types.h>
29 #include <asm/mach/arch.h>
30 #include <asm/mach/map.h>
31
32 #include <mach/mcspi.h>
33 #include <mach/gpio.h>
34 #include <mach/mux.h>
35 #include <mach/board.h>
36 #include <mach/usb-musb.h>
37 #include <mach/usb-ehci.h>
38 #include <mach/hsmmc.h>
39 #include <mach/common.h>
40 #include <mach/keypad.h>
41 #include <mach/dma.h>
42 #include <mach/gpmc.h>
43 #include <linux/i2c/twl4030-rtc.h>
44
45 #include <asm/io.h>
46 #include <asm/delay.h>
47 #include <mach/control.h>
48
49 #include "sdram-qimonda-hyb18m512160af-6.h"
50
51 #define SDP3430_SMC91X_CS       3
52
53 #define ENABLE_VAUX3_DEDICATED  0x03
54 #define ENABLE_VAUX3_DEV_GRP    0x20
55
56
57 #define TWL4030_MSECURE_GPIO 22
58
59 static struct resource sdp3430_smc91x_resources[] = {
60         [0] = {
61                 .start  = OMAP34XX_ETHR_START,
62                 .end    = OMAP34XX_ETHR_START + SZ_4K,
63                 .flags  = IORESOURCE_MEM,
64         },
65         [1] = {
66                 .start  = 0,
67                 .end    = 0,
68                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
69         },
70 };
71
72 static struct platform_device sdp3430_smc91x_device = {
73         .name           = "smc91x",
74         .id             = -1,
75         .num_resources  = ARRAY_SIZE(sdp3430_smc91x_resources),
76         .resource       = sdp3430_smc91x_resources,
77 };
78
79 static int sdp3430_keymap[] = {
80         KEY(0, 0, KEY_LEFT),
81         KEY(0, 1, KEY_RIGHT),
82         KEY(0, 2, KEY_A),
83         KEY(0, 3, KEY_B),
84         KEY(0, 4, KEY_C),
85         KEY(1, 0, KEY_DOWN),
86         KEY(1, 1, KEY_UP),
87         KEY(1, 2, KEY_E),
88         KEY(1, 3, KEY_F),
89         KEY(1, 4, KEY_G),
90         KEY(2, 0, KEY_ENTER),
91         KEY(2, 1, KEY_I),
92         KEY(2, 2, KEY_J),
93         KEY(2, 3, KEY_K),
94         KEY(2, 4, KEY_3),
95         KEY(3, 0, KEY_M),
96         KEY(3, 1, KEY_N),
97         KEY(3, 2, KEY_O),
98         KEY(3, 3, KEY_P),
99         KEY(3, 4, KEY_Q),
100         KEY(4, 0, KEY_R),
101         KEY(4, 1, KEY_4),
102         KEY(4, 2, KEY_T),
103         KEY(4, 3, KEY_U),
104         KEY(4, 4, KEY_D),
105         KEY(5, 0, KEY_V),
106         KEY(5, 1, KEY_W),
107         KEY(5, 2, KEY_L),
108         KEY(5, 3, KEY_S),
109         KEY(5, 4, KEY_H),
110         0
111 };
112
113 static struct omap_kp_platform_data sdp3430_kp_data = {
114         .rows           = 5,
115         .cols           = 6,
116         .keymap         = sdp3430_keymap,
117         .keymapsize     = ARRAY_SIZE(sdp3430_keymap),
118         .rep            = 1,
119 };
120
121 static struct platform_device sdp3430_kp_device = {
122         .name           = "omap_twl4030keypad",
123         .id             = -1,
124         .dev            = {
125                 .platform_data  = &sdp3430_kp_data,
126         },
127 };
128
129 static int ts_gpio;
130
131 #ifdef CONFIG_RTC_DRV_TWL4030
132 static int twl4030_rtc_init(void)
133 {
134         int ret = 0;
135
136         /* 3430ES2.0 doesn't have msecure/gpio-22 line connected to T2 */
137         if (is_device_type_gp() && is_sil_rev_less_than(OMAP3430_REV_ES2_0)) {
138                 u32 msecure_pad_config_reg = omap_ctrl_base_get() + 0xA3C;
139                 int mux_mask = 0x04;
140                 u16 tmp;
141
142                 ret = omap_request_gpio(TWL4030_MSECURE_GPIO);
143                 if (ret < 0) {
144                         printk(KERN_ERR "twl4030_rtc_init: can't"
145                                 "reserve GPIO:%d !\n", TWL4030_MSECURE_GPIO);
146                         goto out;
147                 }
148                 /*
149                  * TWL4030 will be in secure mode if msecure line from OMAP
150                  * is low. Make msecure line high in order to change the
151                  * TWL4030 RTC time and calender registers.
152                  */
153                 omap_set_gpio_direction(TWL4030_MSECURE_GPIO, 0);
154
155                 tmp = omap_readw(msecure_pad_config_reg);
156                 tmp &= 0xF8; /* To enable mux mode 03/04 = GPIO_RTC */
157                 tmp |= mux_mask;/* To enable mux mode 03/04 = GPIO_RTC */
158                 omap_writew(tmp, msecure_pad_config_reg);
159
160                 omap_set_gpio_dataout(TWL4030_MSECURE_GPIO, 1);
161         }
162 out:
163         return ret;
164 }
165
166 static void twl4030_rtc_exit(void)
167 {
168         if (is_device_type_gp() &&
169                         is_sil_rev_less_than(OMAP3430_REV_ES2_0)) {
170                 omap_free_gpio(TWL4030_MSECURE_GPIO);
171         }
172 }
173
174 static struct twl4030rtc_platform_data sdp3430_twl4030rtc_data = {
175         .init = &twl4030_rtc_init,
176         .exit = &twl4030_rtc_exit,
177 };
178
179 static struct platform_device sdp3430_twl4030rtc_device = {
180         .name = "twl4030_rtc",
181         .id = -1,
182         .dev = {
183         .platform_data = &sdp3430_twl4030rtc_data,
184         },
185 };
186 #endif
187
188 /**
189  * @brief ads7846_dev_init : Requests & sets GPIO line for pen-irq
190  *
191  * @return - void. If request gpio fails then Flag KERN_ERR.
192  */
193 static void ads7846_dev_init(void)
194 {
195         if (omap_request_gpio(ts_gpio) < 0) {
196                 printk(KERN_ERR "can't get ads746 pen down GPIO\n");
197                 return;
198         }
199
200         omap_set_gpio_direction(ts_gpio, 1);
201
202         omap_set_gpio_debounce(ts_gpio, 1);
203         omap_set_gpio_debounce_time(ts_gpio, 0xa);
204 }
205
206 static int ads7846_get_pendown_state(void)
207 {
208         return !omap_get_gpio_datain(ts_gpio);
209 }
210
211 /*
212  * This enable(1)/disable(0) the voltage for TS: uses twl4030 calls
213  */
214 static int ads7846_vaux_control(int vaux_cntrl)
215 {
216         int ret = 0;
217
218 #ifdef CONFIG_TWL4030_CORE
219         /* check for return value of ldo_use: if success it returns 0 */
220         if (vaux_cntrl == VAUX_ENABLE) {
221                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
222                         ENABLE_VAUX3_DEDICATED, TWL4030_VAUX3_DEDICATED))
223                         return -EIO;
224                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
225                         ENABLE_VAUX3_DEV_GRP, TWL4030_VAUX3_DEV_GRP))
226                         return -EIO;
227         } else if (vaux_cntrl == VAUX_DISABLE) {
228                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
229                         0x00, TWL4030_VAUX3_DEDICATED))
230                         return -EIO;
231                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
232                         0x00, TWL4030_VAUX3_DEV_GRP))
233                         return -EIO;
234         }
235 #else
236         ret = -EIO;
237 #endif
238         return ret;
239 }
240
241 static struct ads7846_platform_data tsc2046_config __initdata = {
242         .get_pendown_state      = ads7846_get_pendown_state,
243         .keep_vref_on           = 1,
244         .vaux_control           = ads7846_vaux_control,
245 };
246
247
248 static struct omap2_mcspi_device_config tsc2046_mcspi_config = {
249         .turbo_mode     = 0,
250         .single_channel = 1,  /* 0: slave, 1: master */
251 };
252
253 static struct spi_board_info sdp3430_spi_board_info[] __initdata = {
254         [0] = {
255                 /*
256                  * TSC2046 operates at a max freqency of 2MHz, so
257                  * operate slightly below at 1.5MHz
258                  */
259                 .modalias               = "ads7846",
260                 .bus_num                = 1,
261                 .chip_select            = 0,
262                 .max_speed_hz           = 1500000,
263                 .controller_data        = &tsc2046_mcspi_config,
264                 .irq                    = 0,
265                 .platform_data          = &tsc2046_config,
266         },
267 };
268
269 static struct platform_device sdp3430_lcd_device = {
270         .name           = "sdp2430_lcd",
271         .id             = -1,
272 };
273
274 static struct platform_device *sdp3430_devices[] __initdata = {
275         &sdp3430_smc91x_device,
276         &sdp3430_kp_device,
277         &sdp3430_lcd_device,
278 #ifdef CONFIG_RTC_DRV_TWL4030
279         &sdp3430_twl4030rtc_device,
280 #endif
281 };
282
283 static inline void __init sdp3430_init_smc91x(void)
284 {
285         int eth_cs;
286         unsigned long cs_mem_base;
287         int eth_gpio = 0;
288
289         eth_cs = SDP3430_SMC91X_CS;
290
291         if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
292                 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
293                 return;
294         }
295
296         sdp3430_smc91x_resources[0].start = cs_mem_base + 0x0;
297         sdp3430_smc91x_resources[0].end   = cs_mem_base + 0xf;
298         udelay(100);
299
300         if (is_sil_rev_greater_than(OMAP3430_REV_ES1_0))
301                 eth_gpio = OMAP34XX_ETHR_GPIO_IRQ_SDPV2;
302         else
303                 eth_gpio = OMAP34XX_ETHR_GPIO_IRQ_SDPV1;
304
305         sdp3430_smc91x_resources[1].start = OMAP_GPIO_IRQ(eth_gpio);
306
307         if (omap_request_gpio(eth_gpio) < 0) {
308                 printk(KERN_ERR "Failed to request GPIO%d for smc91x IRQ\n",
309                         eth_gpio);
310                 return;
311         }
312         omap_set_gpio_direction(eth_gpio, 1);
313 }
314
315 static void __init omap_3430sdp_init_irq(void)
316 {
317         omap2_init_common_hw(hyb18m512160af6_sdrc_params);
318         omap_init_irq();
319         omap_gpio_init();
320         sdp3430_init_smc91x();
321 }
322
323 static struct omap_uart_config sdp3430_uart_config __initdata = {
324         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
325 };
326
327 static struct omap_lcd_config sdp3430_lcd_config __initdata = {
328         .ctrl_name      = "internal",
329 };
330
331 static struct omap_mmc_config sdp3430_mmc_config __initdata = {
332         .mmc [0] = {
333                 .enabled        = 1,
334                 .wire4          = 1,
335         },
336 };
337
338 static struct omap_board_config_kernel sdp3430_config[] __initdata = {
339         { OMAP_TAG_UART,        &sdp3430_uart_config },
340         {OMAP_TAG_LCD,          &sdp3430_lcd_config},
341         {OMAP_TAG_MMC,          &sdp3430_mmc_config },
342 };
343
344 static int __init omap3430_i2c_init(void)
345 {
346         omap_register_i2c_bus(1, 2600, NULL, 0);
347         omap_register_i2c_bus(2, 400, NULL, 0);
348         omap_register_i2c_bus(3, 400, NULL, 0);
349         return 0;
350 }
351
352 extern void __init sdp3430_flash_init(void);
353
354 static void __init omap_3430sdp_init(void)
355 {
356         platform_add_devices(sdp3430_devices, ARRAY_SIZE(sdp3430_devices));
357         omap_board_config = sdp3430_config;
358         omap_board_config_size = ARRAY_SIZE(sdp3430_config);
359         if (is_sil_rev_greater_than(OMAP3430_REV_ES1_0))
360                 ts_gpio = OMAP34XX_TS_GPIO_IRQ_SDPV2;
361         else
362                 ts_gpio = OMAP34XX_TS_GPIO_IRQ_SDPV1;
363         sdp3430_spi_board_info[0].irq = OMAP_GPIO_IRQ(ts_gpio);
364         spi_register_board_info(sdp3430_spi_board_info,
365                                 ARRAY_SIZE(sdp3430_spi_board_info));
366         ads7846_dev_init();
367         sdp3430_flash_init();
368         twl4030_bci_battery_init();
369         omap_serial_init();
370         usb_musb_init();
371         usb_ehci_init();
372         hsmmc_init();
373 }
374
375 static void __init omap_3430sdp_map_io(void)
376 {
377         omap2_set_globals_343x();
378         omap2_map_common_io();
379 }
380 arch_initcall(omap3430_i2c_init);
381
382 MACHINE_START(OMAP_3430SDP, "OMAP3430 3430SDP board")
383         /* Maintainer: Syed Khasim - Texas Instruments Inc */
384         .phys_io        = 0x48000000,
385         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
386         .boot_params    = 0x80000100,
387         .map_io         = omap_3430sdp_map_io,
388         .init_irq       = omap_3430sdp_init_irq,
389         .init_machine   = omap_3430sdp_init,
390         .timer          = &omap_timer,
391 MACHINE_END