]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-ldp.c
use gpio_direction_input (OMAP tree only)
[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/workqueue.h>
20 #include <linux/err.h>
21 #include <linux/clk.h>
22 #include <linux/spi/spi.h>
23 #include <linux/spi/ads7846.h>
24 #include <linux/i2c/twl4030.h>
25
26 #include <mach/hardware.h>
27 #include <asm/mach-types.h>
28 #include <asm/mach/arch.h>
29 #include <asm/mach/map.h>
30
31 #include <mach/board-ldp.h>
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/mmc.h>
38 #include <mach/usb-musb.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 CONFIG_DISABLE_HFCLK 1
48
49 #define ENABLE_VAUX1_DEDICATED  0x03
50 #define ENABLE_VAUX1_DEV_GRP    0x20
51
52 #define TWL4030_MSECURE_GPIO    22
53
54 static int ts_gpio;
55
56 static int __init msecure_init(void)
57 {
58         int ret = 0;
59
60 #ifdef CONFIG_RTC_DRV_TWL4030
61         /* 3430ES2.0 doesn't have msecure/gpio-22 line connected to T2 */
62         if (omap_type() == OMAP2_DEVICE_TYPE_GP &&
63                         omap_rev() < OMAP3430_REV_ES2_0) {
64                 void __iomem *msecure_pad_config_reg =
65                         omap_ctrl_base_get() + 0xA3C;
66                 int mux_mask = 0x04;
67                 u16 tmp;
68
69                 ret = gpio_request(TWL4030_MSECURE_GPIO, "msecure");
70                 if (ret < 0) {
71                         printk(KERN_ERR "msecure_init: can't"
72                                 "reserve GPIO:%d !\n", TWL4030_MSECURE_GPIO);
73                         goto out;
74                 }
75                 /*
76                  * TWL4030 will be in secure mode if msecure line from OMAP
77                  * is low. Make msecure line high in order to change the
78                  * TWL4030 RTC time and calender registers.
79                  */
80
81                 tmp = __raw_readw(msecure_pad_config_reg);
82                 tmp &= 0xF8;    /* To enable mux mode 03/04 = GPIO_RTC */
83                 tmp |= mux_mask;/* To enable mux mode 03/04 = GPIO_RTC */
84                 __raw_writew(tmp, msecure_pad_config_reg);
85
86                 gpio_direction_output(TWL4030_MSECURE_GPIO, 1);
87         }
88 out:
89 #endif
90         return ret;
91 }
92
93 /**
94  * @brief ads7846_dev_init : Requests & sets GPIO line for pen-irq
95  *
96  * @return - void. If request gpio fails then Flag KERN_ERR.
97  */
98 static void ads7846_dev_init(void)
99 {
100         if (omap_request_gpio(ts_gpio) < 0) {
101                 printk(KERN_ERR "can't get ads746 pen down GPIO\n");
102                 return;
103         }
104
105         gpio_direction_input(ts_gpio);
106
107         omap_set_gpio_debounce(ts_gpio, 1);
108         omap_set_gpio_debounce_time(ts_gpio, 0xa);
109 }
110
111 static int ads7846_get_pendown_state(void)
112 {
113         return !gpio_get_value(ts_gpio);
114 }
115
116 /*
117  * This enable(1)/disable(0) the voltage for TS: uses twl4030 calls
118  */
119 static int ads7846_vaux_control(int vaux_cntrl)
120 {
121         int ret = 0;
122
123 #ifdef CONFIG_TWL4030_CORE
124         /* check for return value of ldo_use: if success it returns 0 */
125         if (vaux_cntrl == VAUX_ENABLE) {
126                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
127                         ENABLE_VAUX1_DEDICATED, TWL4030_VAUX1_DEDICATED))
128                         return -EIO;
129                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
130                         ENABLE_VAUX1_DEV_GRP, TWL4030_VAUX1_DEV_GRP))
131                         return -EIO;
132         } else if (vaux_cntrl == VAUX_DISABLE) {
133                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
134                         0x00, TWL4030_VAUX1_DEDICATED))
135                         return -EIO;
136                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
137                         0x00, TWL4030_VAUX1_DEV_GRP))
138                         return -EIO;
139         }
140 #else
141         ret = -EIO;
142 #endif
143         return ret;
144 }
145
146 static struct ads7846_platform_data tsc2046_config __initdata = {
147         .get_pendown_state      = ads7846_get_pendown_state,
148         .keep_vref_on           = 1,
149         .vaux_control           = ads7846_vaux_control,
150 };
151
152
153 static struct omap2_mcspi_device_config tsc2046_mcspi_config = {
154         .turbo_mode     = 0,
155         .single_channel = 1,    /* 0: slave, 1: master */
156 };
157
158 static struct spi_board_info ldp_spi_board_info[] __initdata = {
159         [0] = {
160                 /*
161                  * TSC2046 operates at a max freqency of 2MHz, so
162                  * operate slightly below at 1.5MHz
163                  */
164                 .modalias               = "ads7846",
165                 .bus_num                = 1,
166                 .chip_select            = 0,
167                 .max_speed_hz           = 1500000,
168                 .controller_data        = &tsc2046_mcspi_config,
169                 .irq                    = 0,
170                 .platform_data          = &tsc2046_config,
171         },
172 };
173
174 static struct platform_device ldp_lcd_device = {
175         .name           = "ldp_lcd",
176         .id             = -1,
177 };
178
179 static struct platform_device *ldp_devices[] __initdata = {
180         &ldp_lcd_device,
181 };
182
183 static void __init omap_ldp_init_irq(void)
184 {
185         omap2_init_common_hw(NULL);
186         omap_init_irq();
187         omap_gpio_init();
188 }
189
190 static struct omap_uart_config ldp_uart_config __initdata = {
191         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
192 };
193
194 static struct omap_lcd_config ldp_lcd_config __initdata = {
195         .ctrl_name      = "internal",
196 };
197
198 static struct omap_board_config_kernel ldp_config[] __initdata = {
199         { OMAP_TAG_UART,        &ldp_uart_config },
200         { OMAP_TAG_LCD,         &ldp_lcd_config },
201 };
202
203 static int ldp_batt_table[] = {
204 /* 0 C*/
205 30800, 29500, 28300, 27100,
206 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
207 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
208 11600, 11200, 10800, 10400, 10000, 9630,   9280,   8950,   8620,   8310,
209 8020,   7730,   7460,   7200,   6950,   6710,   6470,   6250,   6040,   5830,
210 5640,   5450,   5260,   5090,   4920,   4760,   4600,   4450,   4310,   4170,
211 4040,   3910,   3790,   3670,   3550
212 };
213
214 static struct twl4030_ins __initdata sleep_on_seq[] = {
215 /*
216  * Turn off VDD1 and VDD2.
217  */
218         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_OFF), 4},
219         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_OFF), 2},
220 #ifdef CONFIG_DISABLE_HFCLK
221 /*
222  * And also turn off the OMAP3 PLLs and the sysclk output.
223  */
224         {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_OFF), 3},
225         {MSG_SINGULAR(DEV_GRP_P1, 0x19, RES_STATE_OFF), 3},
226 #endif
227 };
228
229 static struct twl4030_script sleep_on_script __initdata = {
230         .script = sleep_on_seq,
231         .size   = ARRAY_SIZE(sleep_on_seq),
232         .flags  = TRITON_SLEEP_SCRIPT,
233 };
234
235 static struct twl4030_ins wakeup_seq[] __initdata = {
236 #ifndef CONFIG_DISABLE_HFCLK
237 /*
238  * Wakeup VDD1 and VDD2.
239  */
240         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_ACTIVE), 4},
241         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_ACTIVE), 2},
242 #else
243 /*
244  * Reenable the OMAP3 PLLs.
245  * Wakeup VDD1 and VDD2.
246  * Reenable sysclk output.
247  */
248         {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_ACTIVE), 0x30},
249         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_ACTIVE), 0x30},
250         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_ACTIVE), 0x37},
251         {MSG_SINGULAR(DEV_GRP_P1, 0x19, RES_STATE_ACTIVE), 3},
252 #endif /* #ifndef CONFIG_DISABLE_HFCLK */
253 };
254
255 static struct twl4030_script wakeup_script __initdata = {
256         .script = wakeup_seq,
257         .size   = ARRAY_SIZE(wakeup_seq),
258         .flags  = TRITON_WAKEUP12_SCRIPT | TRITON_WAKEUP3_SCRIPT,
259 };
260
261 static struct twl4030_ins wrst_seq[] __initdata = {
262 /*
263  * Reset twl4030.
264  * Reset VDD1 regulator.
265  * Reset VDD2 regulator.
266  * Reset VPLL1 regulator.
267  * Enable sysclk output.
268  * Reenable twl4030.
269  */
270         {MSG_SINGULAR(DEV_GRP_NULL, 0x1b, RES_STATE_OFF), 2},
271         {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_WRST), 15},
272         {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_WRST), 15},
273         {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_WRST), 0x60},
274         {MSG_SINGULAR(DEV_GRP_P1, 0x19, RES_STATE_ACTIVE), 2},
275         {MSG_SINGULAR(DEV_GRP_NULL, 0x1b, RES_STATE_ACTIVE), 2},
276 };
277
278 static struct twl4030_script wrst_script __initdata = {
279         .script = wrst_seq,
280         .size   = ARRAY_SIZE(wakeup_seq),
281         .flags  = TRITON_WRST_SCRIPT,
282 };
283
284 static struct twl4030_script *twl4030_scripts[] __initdata = {
285         &sleep_on_script,
286         &wakeup_script,
287         &wrst_script,
288 };
289
290 static struct twl4030_power_data sdp3430_t2scripts_data __initdata = {
291         .scripts        = twl4030_scripts,
292         .size           = ARRAY_SIZE(twl4030_scripts),
293 };
294
295 static struct twl4030_bci_platform_data ldp_bci_data = {
296         .battery_tmp_tbl        = ldp_batt_table,
297         .tblsize                = ARRAY_SIZE(ldp_batt_table),
298 };
299
300 static struct twl4030_usb_data ldp_usb_data = {
301         .usb_mode       = T2_USB_MODE_ULPI,
302 };
303
304 static struct twl4030_gpio_platform_data ldp_gpio_data = {
305         .gpio_base      = OMAP_MAX_GPIO_LINES,
306         .irq_base       = TWL4030_GPIO_IRQ_BASE,
307         .irq_end        = TWL4030_GPIO_IRQ_END,
308 };
309
310 static struct twl4030_madc_platform_data ldp_madc_data = {
311         .irq_line       = 1,
312 };
313
314 static struct twl4030_platform_data ldp_twldata = {
315         .irq_base       = TWL4030_IRQ_BASE,
316         .irq_end        = TWL4030_IRQ_END,
317
318         /* platform_data for children goes here */
319         .bci            = &ldp_bci_data,
320         .madc           = &ldp_madc_data,
321         .usb            = &ldp_usb_data,
322         .power          = &sdp3430_t2scripts_data,
323         .gpio           = &ldp_gpio_data,
324 };
325
326 static struct i2c_board_info __initdata ldp_i2c_boardinfo[] = {
327         {
328                 I2C_BOARD_INFO("twl4030", 0x48),
329                 .flags = I2C_CLIENT_WAKE,
330                 .irq = INT_34XX_SYS_NIRQ,
331                 .platform_data = &ldp_twldata,
332         },
333 };
334
335 static int __init omap_i2c_init(void)
336 {
337         omap_register_i2c_bus(1, 2600, ldp_i2c_boardinfo,
338                         ARRAY_SIZE(ldp_i2c_boardinfo));
339         omap_register_i2c_bus(2, 400, NULL, 0);
340         omap_register_i2c_bus(3, 400, NULL, 0);
341         return 0;
342 }
343
344 static struct twl4030_hsmmc_info mmc[] __initdata = {
345         {
346                 .mmc            = 1,
347                 .wires          = 4,
348                 .gpio_cd        = -EINVAL,
349                 .gpio_wp        = -EINVAL,
350         },
351         {}      /* Terminator */
352 };
353
354 static void __init omap_ldp_init(void)
355 {
356         omap_i2c_init();
357         platform_add_devices(ldp_devices, ARRAY_SIZE(ldp_devices));
358         omap_board_config = ldp_config;
359         omap_board_config_size = ARRAY_SIZE(ldp_config);
360         ts_gpio = 54;
361         ldp_spi_board_info[0].irq = OMAP_GPIO_IRQ(ts_gpio);
362         spi_register_board_info(ldp_spi_board_info,
363                                 ARRAY_SIZE(ldp_spi_board_info));
364         msecure_init();
365         ads7846_dev_init();
366         omap_serial_init();
367         usb_musb_init();
368         hsmmc_init(mmc);
369 }
370
371 static void __init omap_ldp_map_io(void)
372 {
373         omap2_set_globals_343x();
374         omap2_map_common_io();
375 }
376
377 MACHINE_START(OMAP_LDP, "OMAP LDP board")
378         .phys_io        = 0x48000000,
379         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
380         .boot_params    = 0x80000100,
381         .map_io         = omap_ldp_map_io,
382         .init_irq       = omap_ldp_init_irq,
383         .init_machine   = omap_ldp_init,
384         .timer          = &omap_timer,
385 MACHINE_END