]> 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/spi/spi.h>
24 #include <linux/spi/ads7846.h>
25 #include <linux/i2c/twl4030.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/common.h>
39 #include <mach/keypad.h>
40 #include <mach/dma.h>
41 #include <mach/gpmc.h>
42
43 #include <asm/io.h>
44 #include <asm/delay.h>
45 #include <mach/control.h>
46
47 #include "sdram-qimonda-hyb18m512160af-6.h"
48 #include "mmc-twl4030.h"
49
50 #define CONFIG_DISABLE_HFCLK 1
51
52 #define SDP3430_SMC91X_CS       3
53
54 #define ENABLE_VAUX3_DEDICATED  0x03
55 #define ENABLE_VAUX3_DEV_GRP    0x20
56
57
58 #define TWL4030_MSECURE_GPIO 22
59
60 static struct resource sdp3430_smc91x_resources[] = {
61         [0] = {
62                 .start  = OMAP34XX_ETHR_START,
63                 .end    = OMAP34XX_ETHR_START + SZ_4K,
64                 .flags  = IORESOURCE_MEM,
65         },
66         [1] = {
67                 .start  = 0,
68                 .end    = 0,
69                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
70         },
71 };
72
73 static struct platform_device sdp3430_smc91x_device = {
74         .name           = "smc91x",
75         .id             = -1,
76         .num_resources  = ARRAY_SIZE(sdp3430_smc91x_resources),
77         .resource       = sdp3430_smc91x_resources,
78 };
79
80 static int sdp3430_keymap[] = {
81         KEY(0, 0, KEY_LEFT),
82         KEY(0, 1, KEY_RIGHT),
83         KEY(0, 2, KEY_A),
84         KEY(0, 3, KEY_B),
85         KEY(0, 4, KEY_C),
86         KEY(1, 0, KEY_DOWN),
87         KEY(1, 1, KEY_UP),
88         KEY(1, 2, KEY_E),
89         KEY(1, 3, KEY_F),
90         KEY(1, 4, KEY_G),
91         KEY(2, 0, KEY_ENTER),
92         KEY(2, 1, KEY_I),
93         KEY(2, 2, KEY_J),
94         KEY(2, 3, KEY_K),
95         KEY(2, 4, KEY_3),
96         KEY(3, 0, KEY_M),
97         KEY(3, 1, KEY_N),
98         KEY(3, 2, KEY_O),
99         KEY(3, 3, KEY_P),
100         KEY(3, 4, KEY_Q),
101         KEY(4, 0, KEY_R),
102         KEY(4, 1, KEY_4),
103         KEY(4, 2, KEY_T),
104         KEY(4, 3, KEY_U),
105         KEY(4, 4, KEY_D),
106         KEY(5, 0, KEY_V),
107         KEY(5, 1, KEY_W),
108         KEY(5, 2, KEY_L),
109         KEY(5, 3, KEY_S),
110         KEY(5, 4, KEY_H),
111         0
112 };
113
114 static struct twl4030_keypad_data sdp3430_kp_data = {
115         .rows           = 5,
116         .cols           = 6,
117         .keymap         = sdp3430_keymap,
118         .keymapsize     = ARRAY_SIZE(sdp3430_keymap),
119         .rep            = 1,
120 };
121
122 static int ts_gpio;
123
124 static int __init msecure_init(void)
125 {
126         int ret = 0;
127
128 #ifdef CONFIG_RTC_DRV_TWL4030
129         /* 3430ES2.0 doesn't have msecure/gpio-22 line connected to T2 */
130         if (omap_type() == OMAP2_DEVICE_TYPE_GP &&
131                         omap_rev() < OMAP3430_REV_ES2_0) {
132                 void __iomem *msecure_pad_config_reg = omap_ctrl_base_get() +
133                         0xA3C;
134                 int mux_mask = 0x04;
135                 u16 tmp;
136
137                 ret = gpio_request(TWL4030_MSECURE_GPIO, "msecure");
138                 if (ret < 0) {
139                         printk(KERN_ERR "msecure_init: can't"
140                                 "reserve GPIO:%d !\n", TWL4030_MSECURE_GPIO);
141                         goto out;
142                 }
143                 /*
144                  * TWL4030 will be in secure mode if msecure line from OMAP
145                  * is low. Make msecure line high in order to change the
146                  * TWL4030 RTC time and calender registers.
147                  */
148                 tmp = __raw_readw(msecure_pad_config_reg);
149                 tmp &= 0xF8; /* To enable mux mode 03/04 = GPIO_RTC */
150                 tmp |= mux_mask;/* To enable mux mode 03/04 = GPIO_RTC */
151                 __raw_writew(tmp, msecure_pad_config_reg);
152
153                 gpio_direction_output(TWL4030_MSECURE_GPIO, 1);
154         }
155 out:
156 #endif
157         return ret;
158 }
159
160 /**
161  * @brief ads7846_dev_init : Requests & sets GPIO line for pen-irq
162  *
163  * @return - void. If request gpio fails then Flag KERN_ERR.
164  */
165 static void ads7846_dev_init(void)
166 {
167         if (gpio_request(ts_gpio, "ADS7846 pendown") < 0) {
168                 printk(KERN_ERR "can't get ads746 pen down GPIO\n");
169                 return;
170         }
171
172         gpio_direction_input(ts_gpio);
173
174         omap_set_gpio_debounce(ts_gpio, 1);
175         omap_set_gpio_debounce_time(ts_gpio, 0xa);
176 }
177
178 static int ads7846_get_pendown_state(void)
179 {
180         return !gpio_get_value(ts_gpio);
181 }
182
183 /*
184  * This enable(1)/disable(0) the voltage for TS: uses twl4030 calls
185  */
186 static int ads7846_vaux_control(int vaux_cntrl)
187 {
188         int ret = 0;
189
190 #ifdef CONFIG_TWL4030_CORE
191         /* check for return value of ldo_use: if success it returns 0 */
192         if (vaux_cntrl == VAUX_ENABLE) {
193                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
194                         ENABLE_VAUX3_DEDICATED, TWL4030_VAUX3_DEDICATED))
195                         return -EIO;
196                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
197                         ENABLE_VAUX3_DEV_GRP, TWL4030_VAUX3_DEV_GRP))
198                         return -EIO;
199         } else if (vaux_cntrl == VAUX_DISABLE) {
200                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
201                         0x00, TWL4030_VAUX3_DEDICATED))
202                         return -EIO;
203                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
204                         0x00, TWL4030_VAUX3_DEV_GRP))
205                         return -EIO;
206         }
207 #else
208         ret = -EIO;
209 #endif
210         return ret;
211 }
212
213 static struct ads7846_platform_data tsc2046_config __initdata = {
214         .get_pendown_state      = ads7846_get_pendown_state,
215         .keep_vref_on           = 1,
216         .vaux_control           = ads7846_vaux_control,
217 };
218
219
220 static struct omap2_mcspi_device_config tsc2046_mcspi_config = {
221         .turbo_mode     = 0,
222         .single_channel = 1,  /* 0: slave, 1: master */
223 };
224
225 static struct spi_board_info sdp3430_spi_board_info[] __initdata = {
226         [0] = {
227                 /*
228                  * TSC2046 operates at a max freqency of 2MHz, so
229                  * operate slightly below at 1.5MHz
230                  */
231                 .modalias               = "ads7846",
232                 .bus_num                = 1,
233                 .chip_select            = 0,
234                 .max_speed_hz           = 1500000,
235                 .controller_data        = &tsc2046_mcspi_config,
236                 .irq                    = 0,
237                 .platform_data          = &tsc2046_config,
238         },
239 };
240
241 static struct platform_device sdp3430_lcd_device = {
242         .name           = "sdp2430_lcd",
243         .id             = -1,
244 };
245
246 static struct platform_device *sdp3430_devices[] __initdata = {
247         &sdp3430_smc91x_device,
248         &sdp3430_lcd_device,
249 };
250
251 static inline void __init sdp3430_init_smc91x(void)
252 {
253         int eth_cs;
254         unsigned long cs_mem_base;
255         int eth_gpio = 0;
256
257         eth_cs = SDP3430_SMC91X_CS;
258
259         if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
260                 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
261                 return;
262         }
263
264         sdp3430_smc91x_resources[0].start = cs_mem_base + 0x0;
265         sdp3430_smc91x_resources[0].end   = cs_mem_base + 0xf;
266         udelay(100);
267
268         if (omap_rev() > OMAP3430_REV_ES1_0)
269                 eth_gpio = OMAP34XX_ETHR_GPIO_IRQ_SDPV2;
270         else
271                 eth_gpio = OMAP34XX_ETHR_GPIO_IRQ_SDPV1;
272
273         sdp3430_smc91x_resources[1].start = gpio_to_irq(eth_gpio);
274
275         if (gpio_request(eth_gpio, "SMC91x irq") < 0) {
276                 printk(KERN_ERR "Failed to request GPIO%d for smc91x IRQ\n",
277                         eth_gpio);
278                 return;
279         }
280         gpio_direction_input(eth_gpio);
281 }
282
283 static void __init omap_3430sdp_init_irq(void)
284 {
285         omap2_init_common_hw(hyb18m512160af6_sdrc_params);
286         omap_init_irq();
287         omap_gpio_init();
288         sdp3430_init_smc91x();
289 }
290
291 static struct omap_uart_config sdp3430_uart_config __initdata = {
292         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
293 };
294
295 static struct omap_lcd_config sdp3430_lcd_config __initdata = {
296         .ctrl_name      = "internal",
297 };
298
299 static struct omap_board_config_kernel sdp3430_config[] __initdata = {
300         { OMAP_TAG_UART,        &sdp3430_uart_config },
301         { OMAP_TAG_LCD,         &sdp3430_lcd_config },
302 };
303
304 static int sdp3430_batt_table[] = {
305 /* 0 C*/
306 30800, 29500, 28300, 27100,
307 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
308 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
309 11600, 11200, 10800, 10400, 10000, 9630,   9280,   8950,   8620,   8310,
310 8020,   7730,   7460,   7200,   6950,   6710,   6470,   6250,   6040,   5830,
311 5640,   5450,   5260,   5090,   4920,   4760,   4600,   4450,   4310,   4170,
312 4040,   3910,   3790,   3670,   3550
313 };
314
315 static struct twl4030_bci_platform_data sdp3430_bci_data = {
316       .battery_tmp_tbl  = sdp3430_batt_table,
317       .tblsize          = ARRAY_SIZE(sdp3430_batt_table),
318 };
319
320 static struct twl4030_gpio_platform_data sdp3430_gpio_data = {
321         .gpio_base      = OMAP_MAX_GPIO_LINES,
322         .irq_base       = TWL4030_GPIO_IRQ_BASE,
323         .irq_end        = TWL4030_GPIO_IRQ_END,
324 };
325
326 static struct twl4030_usb_data sdp3430_usb_data = {
327         .usb_mode       = T2_USB_MODE_ULPI,
328 };
329
330 static struct twl4030_madc_platform_data sdp3430_madc_data = {
331         .irq_line       = 1,
332 };
333
334
335 static struct twl4030_ins __initdata sleep_on_seq[] = {
336 /*
337  * Turn off VDD1 and VDD2.
338  */
339         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_OFF), 4},
340         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_OFF), 2},
341 #ifdef CONFIG_DISABLE_HFCLK
342 /*
343  * And also turn off the OMAP3 PLLs and the sysclk output.
344  */
345         {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_OFF), 3},
346         {MSG_SINGULAR(DEV_GRP_P1, 0x19, RES_STATE_OFF), 3},
347 #endif
348 };
349
350 static struct twl4030_script sleep_on_script __initdata = {
351         .script = sleep_on_seq,
352         .size   = ARRAY_SIZE(sleep_on_seq),
353         .flags  = TRITON_SLEEP_SCRIPT,
354 };
355
356 static struct twl4030_ins wakeup_seq[] __initdata = {
357 #ifndef CONFIG_DISABLE_HFCLK
358 /*
359  * Wakeup VDD1 and VDD2.
360  */
361         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_ACTIVE), 4},
362         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_ACTIVE), 2},
363 #else
364 /*
365  * Reenable the OMAP3 PLLs.
366  * Wakeup VDD1 and VDD2.
367  * Reenable sysclk output.
368  */
369         {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_ACTIVE), 0x30},
370         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_ACTIVE), 0x30},
371         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_ACTIVE), 0x37},
372         {MSG_SINGULAR(DEV_GRP_P1, 0x19, RES_STATE_ACTIVE), 3},
373 #endif /* #ifndef CONFIG_DISABLE_HFCLK */
374 };
375
376 static struct twl4030_script wakeup_script __initdata = {
377         .script = wakeup_seq,
378         .size   = ARRAY_SIZE(wakeup_seq),
379         .flags  = TRITON_WAKEUP12_SCRIPT | TRITON_WAKEUP3_SCRIPT,
380 };
381
382 static struct twl4030_ins wrst_seq[] __initdata = {
383 /*
384  * Reset twl4030.
385  * Reset VDD1 regulator.
386  * Reset VDD2 regulator.
387  * Reset VPLL1 regulator.
388  * Enable sysclk output.
389  * Reenable twl4030.
390  */
391         {MSG_SINGULAR(DEV_GRP_NULL, 0x1b, RES_STATE_OFF), 2},
392         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_WRST), 15},
393         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_WRST), 15},
394         {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_WRST), 0x60},
395         {MSG_SINGULAR(DEV_GRP_P1, 0x19, RES_STATE_ACTIVE), 2},
396         {MSG_SINGULAR(DEV_GRP_NULL, 0x1b, RES_STATE_ACTIVE), 2},
397 };
398 static struct twl4030_script wrst_script __initdata = {
399         .script = wrst_seq,
400         .size   = ARRAY_SIZE(wakeup_seq),
401         .flags  = TRITON_WRST_SCRIPT,
402 };
403
404 static struct twl4030_script *twl4030_scripts[] __initdata = {
405         &sleep_on_script,
406         &wakeup_script,
407         &wrst_script,
408 };
409
410 static struct twl4030_power_data sdp3430_t2scripts_data __initdata = {
411         .scripts        = twl4030_scripts,
412         .size           = ARRAY_SIZE(twl4030_scripts),
413 };
414
415 static struct twl4030_platform_data sdp3430_twldata = {
416         .irq_base       = TWL4030_IRQ_BASE,
417         .irq_end        = TWL4030_IRQ_END,
418
419         /* platform_data for children goes here */
420         .bci            = &sdp3430_bci_data,
421         .gpio           = &sdp3430_gpio_data,
422         .madc           = &sdp3430_madc_data,
423         .keypad         = &sdp3430_kp_data,
424         .power          = &sdp3430_t2scripts_data,
425         .usb            = &sdp3430_usb_data,
426 };
427
428 static struct i2c_board_info __initdata sdp3430_i2c_boardinfo[] = {
429         {
430                 I2C_BOARD_INFO("twl4030", 0x48),
431                 .flags = I2C_CLIENT_WAKE,
432                 .irq = INT_34XX_SYS_NIRQ,
433                 .platform_data = &sdp3430_twldata,
434         },
435 };
436
437 static int __init omap3430_i2c_init(void)
438 {
439         omap_register_i2c_bus(1, 2600, sdp3430_i2c_boardinfo,
440                         ARRAY_SIZE(sdp3430_i2c_boardinfo));
441         omap_register_i2c_bus(2, 400, NULL, 0);
442         omap_register_i2c_bus(3, 400, NULL, 0);
443         return 0;
444 }
445
446 static struct twl4030_hsmmc_info mmc[] __initdata = {
447         {
448                 .mmc            = 1,
449                 .wires          = 8,
450                 .gpio_cd        = -EINVAL,
451                 .gpio_wp        = -EINVAL,
452         },
453         {
454                 .mmc            = 2,
455                 .wires          = 8,
456                 .gpio_cd        = -EINVAL,
457                 .gpio_wp        = -EINVAL,
458         },
459         {}      /* Terminator */
460 };
461
462 extern void __init sdp3430_flash_init(void);
463
464 static void __init omap_3430sdp_init(void)
465 {
466         omap3430_i2c_init();
467         platform_add_devices(sdp3430_devices, ARRAY_SIZE(sdp3430_devices));
468         omap_board_config = sdp3430_config;
469         omap_board_config_size = ARRAY_SIZE(sdp3430_config);
470         if (omap_rev() > OMAP3430_REV_ES1_0)
471                 ts_gpio = OMAP34XX_TS_GPIO_IRQ_SDPV2;
472         else
473                 ts_gpio = OMAP34XX_TS_GPIO_IRQ_SDPV1;
474         sdp3430_spi_board_info[0].irq = gpio_to_irq(ts_gpio);
475         spi_register_board_info(sdp3430_spi_board_info,
476                                 ARRAY_SIZE(sdp3430_spi_board_info));
477         ads7846_dev_init();
478         sdp3430_flash_init();
479         msecure_init();
480         omap_serial_init();
481         usb_musb_init();
482         usb_ehci_init();
483         twl4030_mmc_init(mmc);
484 }
485
486 static void __init omap_3430sdp_map_io(void)
487 {
488         omap2_set_globals_343x();
489         omap2_map_common_io();
490 }
491
492 MACHINE_START(OMAP_3430SDP, "OMAP3430 3430SDP board")
493         /* Maintainer: Syed Khasim - Texas Instruments Inc */
494         .phys_io        = 0x48000000,
495         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
496         .boot_params    = 0x80000100,
497         .map_io         = omap_3430sdp_map_io,
498         .init_irq       = omap_3430sdp_init_irq,
499         .init_machine   = omap_3430sdp_init,
500         .timer          = &omap_timer,
501 MACHINE_END