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