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