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