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