]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-ldp.c
91fd0889a3581890df5335856c8f56d1d1b57c56
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-ldp.c
1 /*
2  * linux/arch/arm/mach-omap2/board-ldp.c
3  *
4  * Copyright (C) 2008 Texas Instruments Inc.
5  * Nishant Kamat <nskamat@ti.com>
6  *
7  * Modified from mach-omap2/board-3430sdp.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/delay.h>
18 #include <linux/input.h>
19 #include <linux/gpio_keys.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/board.h>
35 #include <mach/common.h>
36 #include <mach/gpmc.h>
37 #include <mach/usb.h>
38
39 #include <asm/io.h>
40 #include <asm/delay.h>
41 #include <mach/control.h>
42
43 #include "mmc-twl4030.h"
44
45 #define LDP_SMC911X_CS          1
46 #define LDP_SMC911X_GPIO        152
47 #define DEBUG_BASE              0x08000000
48 #define LDP_ETHR_START          DEBUG_BASE
49 #define ENABLE_VAUX1_DEDICATED  0x03
50 #define ENABLE_VAUX1_DEV_GRP    0x20
51
52 #define TWL4030_MSECURE_GPIO    22
53
54 static struct resource ldp_smc911x_resources[] = {
55         [0] = {
56                 .start  = LDP_ETHR_START,
57                 .end    = LDP_ETHR_START + SZ_4K,
58                 .flags  = IORESOURCE_MEM,
59         },
60         [1] = {
61                 .start  = 0,
62                 .end    = 0,
63                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
64         },
65 };
66
67 static struct platform_device ldp_smc911x_device = {
68         .name           = "smc911x",
69         .id             = -1,
70         .num_resources  = ARRAY_SIZE(ldp_smc911x_resources),
71         .resource       = ldp_smc911x_resources,
72 };
73
74 static int ldp_twl4030_keymap[] = {
75         KEY(0, 0, KEY_1),
76         KEY(1, 0, KEY_2),
77         KEY(2, 0, KEY_3),
78         KEY(0, 1, KEY_4),
79         KEY(1, 1, KEY_5),
80         KEY(2, 1, KEY_6),
81         KEY(3, 1, KEY_F5),
82         KEY(0, 2, KEY_7),
83         KEY(1, 2, KEY_8),
84         KEY(2, 2, KEY_9),
85         KEY(3, 2, KEY_F6),
86         KEY(0, 3, KEY_F7),
87         KEY(1, 3, KEY_0),
88         KEY(2, 3, KEY_F8),
89         PERSISTENT_KEY(4, 5),
90         KEY(4, 4, KEY_VOLUMEUP),
91         KEY(5, 5, KEY_VOLUMEDOWN),
92         0
93 };
94
95 static struct twl4030_keypad_data ldp_kp_twl4030_data = {
96         .rows           = 6,
97         .cols           = 6,
98         .keymap         = ldp_twl4030_keymap,
99         .keymapsize     = ARRAY_SIZE(ldp_twl4030_keymap),
100         .rep            = 1,
101 };
102
103 static struct gpio_keys_button ldp_gpio_keys_buttons[] = {
104         [0] = {
105                 .code                   = KEY_ENTER,
106                 .gpio                   = 101,
107                 .desc                   = "enter sw",
108                 .active_low             = 1,
109                 .debounce_interval      = 30,
110         },
111         [1] = {
112                 .code                   = KEY_F1,
113                 .gpio                   = 102,
114                 .desc                   = "func 1",
115                 .active_low             = 1,
116                 .debounce_interval      = 30,
117         },
118         [2] = {
119                 .code                   = KEY_F2,
120                 .gpio                   = 103,
121                 .desc                   = "func 2",
122                 .active_low             = 1,
123                 .debounce_interval      = 30,
124         },
125         [3] = {
126                 .code                   = KEY_F3,
127                 .gpio                   = 104,
128                 .desc                   = "func 3",
129                 .active_low             = 1,
130                 .debounce_interval      = 30,
131         },
132         [4] = {
133                 .code                   = KEY_F4,
134                 .gpio                   = 105,
135                 .desc                   = "func 4",
136                 .active_low             = 1,
137                 .debounce_interval      = 30,
138         },
139         [5] = {
140                 .code                   = KEY_LEFT,
141                 .gpio                   = 106,
142                 .desc                   = "left sw",
143                 .active_low             = 1,
144                 .debounce_interval      = 30,
145         },
146         [6] = {
147                 .code                   = KEY_RIGHT,
148                 .gpio                   = 107,
149                 .desc                   = "right sw",
150                 .active_low             = 1,
151                 .debounce_interval      = 30,
152         },
153         [7] = {
154                 .code                   = KEY_UP,
155                 .gpio                   = 108,
156                 .desc                   = "up sw",
157                 .active_low             = 1,
158                 .debounce_interval      = 30,
159         },
160         [8] = {
161                 .code                   = KEY_DOWN,
162                 .gpio                   = 109,
163                 .desc                   = "down sw",
164                 .active_low             = 1,
165                 .debounce_interval      = 30,
166         },
167 };
168
169 static struct gpio_keys_platform_data ldp_gpio_keys = {
170         .buttons                = ldp_gpio_keys_buttons,
171         .nbuttons               = ARRAY_SIZE(ldp_gpio_keys_buttons),
172         .rep                    = 1,
173 };
174
175 static struct platform_device ldp_gpio_keys_device = {
176         .name           = "gpio-keys",
177         .id             = -1,
178         .dev            = {
179                 .platform_data  = &ldp_gpio_keys,
180         },
181 };
182
183 static int ts_gpio;
184
185 static int __init msecure_init(void)
186 {
187         int ret = 0;
188
189 #ifdef CONFIG_RTC_DRV_TWL4030
190         /* 3430ES2.0 doesn't have msecure/gpio-22 line connected to T2 */
191         if (omap_type() == OMAP2_DEVICE_TYPE_GP &&
192                         omap_rev() < OMAP3430_REV_ES2_0) {
193                 void __iomem *msecure_pad_config_reg =
194                         omap_ctrl_base_get() + 0xA3C;
195                 int mux_mask = 0x04;
196                 u16 tmp;
197
198                 ret = gpio_request(TWL4030_MSECURE_GPIO, "msecure");
199                 if (ret < 0) {
200                         printk(KERN_ERR "msecure_init: can't"
201                                 "reserve GPIO:%d !\n", TWL4030_MSECURE_GPIO);
202                         goto out;
203                 }
204                 /*
205                  * TWL4030 will be in secure mode if msecure line from OMAP
206                  * is low. Make msecure line high in order to change the
207                  * TWL4030 RTC time and calender registers.
208                  */
209
210                 tmp = __raw_readw(msecure_pad_config_reg);
211                 tmp &= 0xF8;    /* To enable mux mode 03/04 = GPIO_RTC */
212                 tmp |= mux_mask;/* To enable mux mode 03/04 = GPIO_RTC */
213                 __raw_writew(tmp, msecure_pad_config_reg);
214
215                 gpio_direction_output(TWL4030_MSECURE_GPIO, 1);
216         }
217 out:
218 #endif
219         return ret;
220 }
221
222 /**
223  * @brief ads7846_dev_init : Requests & sets GPIO line for pen-irq
224  *
225  * @return - void. If request gpio fails then Flag KERN_ERR.
226  */
227 static void ads7846_dev_init(void)
228 {
229         if (gpio_request(ts_gpio, "ads7846 irq") < 0) {
230                 printk(KERN_ERR "can't get ads746 pen down GPIO\n");
231                 return;
232         }
233
234         gpio_direction_input(ts_gpio);
235
236         omap_set_gpio_debounce(ts_gpio, 1);
237         omap_set_gpio_debounce_time(ts_gpio, 0xa);
238 }
239
240 static int ads7846_get_pendown_state(void)
241 {
242         return !gpio_get_value(ts_gpio);
243 }
244
245 /*
246  * This enable(1)/disable(0) the voltage for TS: uses twl4030 calls
247  */
248 static int ads7846_vaux_control(int vaux_cntrl)
249 {
250         int ret = 0;
251
252 #ifdef CONFIG_TWL4030_CORE
253         /* check for return value of ldo_use: if success it returns 0 */
254         if (vaux_cntrl == VAUX_ENABLE) {
255                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
256                         ENABLE_VAUX1_DEDICATED, TWL4030_VAUX1_DEDICATED))
257                         return -EIO;
258                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
259                         ENABLE_VAUX1_DEV_GRP, TWL4030_VAUX1_DEV_GRP))
260                         return -EIO;
261         } else if (vaux_cntrl == VAUX_DISABLE) {
262                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
263                         0x00, TWL4030_VAUX1_DEDICATED))
264                         return -EIO;
265                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
266                         0x00, TWL4030_VAUX1_DEV_GRP))
267                         return -EIO;
268         }
269 #else
270         ret = -EIO;
271 #endif
272         return ret;
273 }
274
275 static struct ads7846_platform_data tsc2046_config __initdata = {
276         .get_pendown_state      = ads7846_get_pendown_state,
277         .keep_vref_on           = 1,
278         .vaux_control           = ads7846_vaux_control,
279 };
280
281
282 static struct omap2_mcspi_device_config tsc2046_mcspi_config = {
283         .turbo_mode     = 0,
284         .single_channel = 1,    /* 0: slave, 1: master */
285 };
286
287 static struct spi_board_info ldp_spi_board_info[] __initdata = {
288         [0] = {
289                 /*
290                  * TSC2046 operates at a max freqency of 2MHz, so
291                  * operate slightly below at 1.5MHz
292                  */
293                 .modalias               = "ads7846",
294                 .bus_num                = 1,
295                 .chip_select            = 0,
296                 .max_speed_hz           = 1500000,
297                 .controller_data        = &tsc2046_mcspi_config,
298                 .irq                    = 0,
299                 .platform_data          = &tsc2046_config,
300         },
301 };
302
303 static struct platform_device ldp_lcd_device = {
304         .name           = "ldp_lcd",
305         .id             = -1,
306 };
307
308 static struct platform_device *ldp_devices[] __initdata = {
309         &ldp_smc911x_device,
310         &ldp_lcd_device,
311         &ldp_gpio_keys_device,
312 };
313
314 static inline void __init ldp_init_smc911x(void)
315 {
316         int eth_cs;
317         unsigned long cs_mem_base;
318         int eth_gpio = 0;
319
320         eth_cs = LDP_SMC911X_CS;
321
322         if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
323                 printk(KERN_ERR "Failed to request GPMC mem for smc911x\n");
324                 return;
325         }
326
327         ldp_smc911x_resources[0].start = cs_mem_base + 0x0;
328         ldp_smc911x_resources[0].end   = cs_mem_base + 0xff;
329         udelay(100);
330
331         eth_gpio = LDP_SMC911X_GPIO;
332
333         ldp_smc911x_resources[1].start = OMAP_GPIO_IRQ(eth_gpio);
334
335         if (gpio_request(eth_gpio, "smc911x irq") < 0) {
336                 printk(KERN_ERR "Failed to request GPIO%d for smc911x IRQ\n",
337                                 eth_gpio);
338                 return;
339         }
340         gpio_direction_input(eth_gpio);
341 }
342
343
344 static void __init omap_ldp_init_irq(void)
345 {
346         omap2_init_common_hw(NULL);
347         omap_init_irq();
348         omap_gpio_init();
349         ldp_init_smc911x();
350 }
351
352 static struct omap_uart_config ldp_uart_config __initdata = {
353         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
354 };
355
356 static struct omap_lcd_config ldp_lcd_config __initdata = {
357         .ctrl_name      = "internal",
358 };
359
360 static struct omap_board_config_kernel ldp_config[] __initdata = {
361         { OMAP_TAG_UART,        &ldp_uart_config },
362         { OMAP_TAG_LCD,         &ldp_lcd_config },
363 };
364
365 static int ldp_batt_table[] = {
366 /* 0 C*/
367 30800, 29500, 28300, 27100,
368 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
369 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
370 11600, 11200, 10800, 10400, 10000, 9630,   9280,   8950,   8620,   8310,
371 8020,   7730,   7460,   7200,   6950,   6710,   6470,   6250,   6040,   5830,
372 5640,   5450,   5260,   5090,   4920,   4760,   4600,   4450,   4310,   4170,
373 4040,   3910,   3790,   3670,   3550
374 };
375
376 static struct twl4030_ins __initdata sleep_on_seq[] = {
377 /*
378  * Turn off VDD1 and VDD2.
379  */
380         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_OFF), 4},
381         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_OFF), 2},
382 #ifdef CONFIG_DISABLE_HFCLK
383 /*
384  * And also turn off the OMAP3 PLLs and the sysclk output.
385  */
386         {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_OFF), 3},
387         {MSG_SINGULAR(DEV_GRP_P1, 0x19, RES_STATE_OFF), 3},
388 #endif
389 };
390
391 static struct twl4030_script sleep_on_script __initdata = {
392         .script = sleep_on_seq,
393         .size   = ARRAY_SIZE(sleep_on_seq),
394         .flags  = TRITON_SLEEP_SCRIPT,
395 };
396
397 static struct twl4030_ins wakeup_seq[] __initdata = {
398 #ifndef CONFIG_DISABLE_HFCLK
399 /*
400  * Wakeup VDD1 and VDD2.
401  */
402         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_ACTIVE), 4},
403         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_ACTIVE), 2},
404 #else
405 /*
406  * Reenable the OMAP3 PLLs.
407  * Wakeup VDD1 and VDD2.
408  * Reenable sysclk output.
409  */
410         {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_ACTIVE), 0x30},
411         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_ACTIVE), 0x30},
412         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_ACTIVE), 0x37},
413         {MSG_SINGULAR(DEV_GRP_P1, 0x19, RES_STATE_ACTIVE), 3},
414 #endif /* #ifndef CONFIG_DISABLE_HFCLK */
415 };
416
417 static struct twl4030_script wakeup_script __initdata = {
418         .script = wakeup_seq,
419         .size   = ARRAY_SIZE(wakeup_seq),
420         .flags  = TRITON_WAKEUP12_SCRIPT | TRITON_WAKEUP3_SCRIPT,
421 };
422
423 static struct twl4030_ins wrst_seq[] __initdata = {
424 /*
425  * Reset twl4030.
426  * Reset VDD1 regulator.
427  * Reset VDD2 regulator.
428  * Reset VPLL1 regulator.
429  * Enable sysclk output.
430  * Reenable twl4030.
431  */
432         {MSG_SINGULAR(DEV_GRP_NULL, 0x1b, RES_STATE_OFF), 2},
433         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_WRST), 15},
434         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_WRST), 15},
435         {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_WRST), 0x60},
436         {MSG_SINGULAR(DEV_GRP_P1, 0x19, RES_STATE_ACTIVE), 2},
437         {MSG_SINGULAR(DEV_GRP_NULL, 0x1b, RES_STATE_ACTIVE), 2},
438 };
439
440 static struct twl4030_script wrst_script __initdata = {
441         .script = wrst_seq,
442         .size   = ARRAY_SIZE(wakeup_seq),
443         .flags  = TRITON_WRST_SCRIPT,
444 };
445
446 static struct twl4030_script *twl4030_scripts[] __initdata = {
447         &sleep_on_script,
448         &wakeup_script,
449         &wrst_script,
450 };
451
452 static struct twl4030_power_data sdp3430_t2scripts_data __initdata = {
453         .scripts        = twl4030_scripts,
454         .size           = ARRAY_SIZE(twl4030_scripts),
455 };
456
457 static struct twl4030_bci_platform_data ldp_bci_data = {
458         .battery_tmp_tbl        = ldp_batt_table,
459         .tblsize                = ARRAY_SIZE(ldp_batt_table),
460 };
461
462 static struct twl4030_usb_data ldp_usb_data = {
463         .usb_mode       = T2_USB_MODE_ULPI,
464 };
465
466 static struct twl4030_gpio_platform_data ldp_gpio_data = {
467         .gpio_base      = OMAP_MAX_GPIO_LINES,
468         .irq_base       = TWL4030_GPIO_IRQ_BASE,
469         .irq_end        = TWL4030_GPIO_IRQ_END,
470 };
471
472 static struct twl4030_madc_platform_data ldp_madc_data = {
473         .irq_line       = 1,
474 };
475
476 static struct twl4030_platform_data ldp_twldata = {
477         .irq_base       = TWL4030_IRQ_BASE,
478         .irq_end        = TWL4030_IRQ_END,
479
480         /* platform_data for children goes here */
481         .bci            = &ldp_bci_data,
482         .madc           = &ldp_madc_data,
483         .usb            = &ldp_usb_data,
484         .power          = &sdp3430_t2scripts_data,
485         .gpio           = &ldp_gpio_data,
486         .keypad         = &ldp_kp_twl4030_data,
487 };
488
489 static struct i2c_board_info __initdata ldp_i2c_boardinfo[] = {
490         {
491                 I2C_BOARD_INFO("twl4030", 0x48),
492                 .flags = I2C_CLIENT_WAKE,
493                 .irq = INT_34XX_SYS_NIRQ,
494                 .platform_data = &ldp_twldata,
495         },
496 };
497
498 static int __init omap_i2c_init(void)
499 {
500         omap_register_i2c_bus(1, 2600, ldp_i2c_boardinfo,
501                         ARRAY_SIZE(ldp_i2c_boardinfo));
502         omap_register_i2c_bus(2, 400, NULL, 0);
503         omap_register_i2c_bus(3, 400, NULL, 0);
504         return 0;
505 }
506
507 static struct twl4030_hsmmc_info mmc[] __initdata = {
508         {
509                 .mmc            = 1,
510                 .wires          = 4,
511                 .gpio_cd        = -EINVAL,
512                 .gpio_wp        = -EINVAL,
513         },
514         {}      /* Terminator */
515 };
516
517 static void __init omap_ldp_init(void)
518 {
519         omap_i2c_init();
520         platform_add_devices(ldp_devices, ARRAY_SIZE(ldp_devices));
521         omap_board_config = ldp_config;
522         omap_board_config_size = ARRAY_SIZE(ldp_config);
523         ts_gpio = 54;
524         ldp_spi_board_info[0].irq = gpio_to_irq(ts_gpio);
525         spi_register_board_info(ldp_spi_board_info,
526                                 ARRAY_SIZE(ldp_spi_board_info));
527         msecure_init();
528         ads7846_dev_init();
529         omap_serial_init();
530         usb_musb_init();
531         twl4030_mmc_init(mmc);
532 }
533
534 static void __init omap_ldp_map_io(void)
535 {
536         omap2_set_globals_343x();
537         omap2_map_common_io();
538 }
539
540 MACHINE_START(OMAP_LDP, "OMAP LDP board")
541         .phys_io        = 0x48000000,
542         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
543         .boot_params    = 0x80000100,
544         .map_io         = omap_ldp_map_io,
545         .init_irq       = omap_ldp_init_irq,
546         .init_machine   = omap_ldp_init,
547         .timer          = &omap_timer,
548 MACHINE_END