]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-ldp.c
c7b67857fa91709e5d63cb5b6cc02ff1e0c992e0
[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 #include <linux/i2c/twl4030-rtc.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/hsmmc.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 #define ENABLE_VAUX1_DEDICATED  0x03
46 #define ENABLE_VAUX1_DEV_GRP    0x20
47
48 #define TWL4030_MSECURE_GPIO    22
49
50 static int ts_gpio;
51
52 #ifdef CONFIG_RTC_DRV_TWL4030
53 static int twl4030_rtc_init(void)
54 {
55         int ret = 0;
56
57         /* 3430ES2.0 doesn't have msecure/gpio-22 line connected to T2 */
58         if (is_device_type_gp() && is_sil_rev_less_than(OMAP3430_REV_ES2_0)) {
59                 u32 msecure_pad_config_reg = omap_ctrl_base_get() + 0xA3C;
60                 int mux_mask = 0x04;
61                 u16 tmp;
62
63                 ret = omap_request_gpio(TWL4030_MSECURE_GPIO);
64                 if (ret < 0) {
65                         printk(KERN_ERR "twl4030_rtc_init: can't"
66                                 "reserve GPIO:%d !\n", TWL4030_MSECURE_GPIO);
67                         goto out;
68                 }
69                 /*
70                  * TWL4030 will be in secure mode if msecure line from OMAP
71                  * is low. Make msecure line high in order to change the
72                  * TWL4030 RTC time and calender registers.
73                  */
74                 omap_set_gpio_direction(TWL4030_MSECURE_GPIO, 0);
75
76                 tmp = omap_readw(msecure_pad_config_reg);
77                 tmp &= 0xF8;    /* To enable mux mode 03/04 = GPIO_RTC */
78                 tmp |= mux_mask;/* To enable mux mode 03/04 = GPIO_RTC */
79                 omap_writew(tmp, msecure_pad_config_reg);
80
81                 omap_set_gpio_dataout(TWL4030_MSECURE_GPIO, 1);
82         }
83 out:
84         return ret;
85 }
86
87 static void twl4030_rtc_exit(void)
88 {
89         omap_free_gpio(TWL4030_MSECURE_GPIO);
90 }
91
92 static struct twl4030rtc_platform_data ldp_twl4030rtc_data = {
93         .init = &twl4030_rtc_init,
94         .exit = &twl4030_rtc_exit,
95 };
96
97 static struct platform_device ldp_twl4030rtc_device = {
98         .name           = "twl4030_rtc",
99         .id             = -1,
100         .dev            = {
101                 .platform_data  = &ldp_twl4030rtc_data,
102         },
103 };
104 #endif
105
106 /**
107  * @brief ads7846_dev_init : Requests & sets GPIO line for pen-irq
108  *
109  * @return - void. If request gpio fails then Flag KERN_ERR.
110  */
111 static void ads7846_dev_init(void)
112 {
113         if (omap_request_gpio(ts_gpio) < 0) {
114                 printk(KERN_ERR "can't get ads746 pen down GPIO\n");
115                 return;
116         }
117
118         omap_set_gpio_direction(ts_gpio, 1);
119
120         omap_set_gpio_debounce(ts_gpio, 1);
121         omap_set_gpio_debounce_time(ts_gpio, 0xa);
122 }
123
124 static int ads7846_get_pendown_state(void)
125 {
126         return !omap_get_gpio_datain(ts_gpio);
127 }
128
129 /*
130  * This enable(1)/disable(0) the voltage for TS: uses twl4030 calls
131  */
132 static int ads7846_vaux_control(int vaux_cntrl)
133 {
134         int ret = 0;
135
136 #ifdef CONFIG_TWL4030_CORE
137         /* check for return value of ldo_use: if success it returns 0 */
138         if (vaux_cntrl == VAUX_ENABLE) {
139                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
140                         ENABLE_VAUX1_DEDICATED, TWL4030_VAUX1_DEDICATED))
141                         return -EIO;
142                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
143                         ENABLE_VAUX1_DEV_GRP, TWL4030_VAUX1_DEV_GRP))
144                         return -EIO;
145         } else if (vaux_cntrl == VAUX_DISABLE) {
146                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
147                         0x00, TWL4030_VAUX1_DEDICATED))
148                         return -EIO;
149                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
150                         0x00, TWL4030_VAUX1_DEV_GRP))
151                         return -EIO;
152         }
153 #else
154         ret = -EIO;
155 #endif
156         return ret;
157 }
158
159 static struct ads7846_platform_data tsc2046_config __initdata = {
160         .get_pendown_state      = ads7846_get_pendown_state,
161         .keep_vref_on           = 1,
162         .vaux_control           = ads7846_vaux_control,
163 };
164
165
166 static struct omap2_mcspi_device_config tsc2046_mcspi_config = {
167         .turbo_mode     = 0,
168         .single_channel = 1,  /* 0: slave, 1: master */
169 };
170
171 static struct spi_board_info ldp_spi_board_info[] __initdata = {
172         [0] = {
173                 /*
174                  * TSC2046 operates at a max freqency of 2MHz, so
175                  * operate slightly below at 1.5MHz
176                  */
177                 .modalias               = "ads7846",
178                 .bus_num                = 1,
179                 .chip_select            = 0,
180                 .max_speed_hz           = 1500000,
181                 .controller_data        = &tsc2046_mcspi_config,
182                 .irq                    = 0,
183                 .platform_data          = &tsc2046_config,
184         },
185 };
186
187 static struct platform_device *ldp_devices[] __initdata = {
188 #ifdef CONFIG_RTC_DRV_TWL4030
189         &ldp_twl4030rtc_device,
190 #endif
191 };
192
193 static void __init omap_ldp_init_irq(void)
194 {
195         omap2_init_common_hw(NULL);
196         omap_init_irq();
197         omap_gpio_init();
198 }
199
200 static struct omap_uart_config ldp_uart_config __initdata = {
201         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
202 };
203
204 static struct omap_board_config_kernel ldp_config[] __initdata = {
205         { OMAP_TAG_UART,        &ldp_uart_config },
206 };
207
208 static int __init omap_i2c_init(void)
209 {
210         omap_register_i2c_bus(1, 2600, NULL, 0);
211         omap_register_i2c_bus(2, 400, NULL, 0);
212         omap_register_i2c_bus(3, 400, NULL, 0);
213         return 0;
214 }
215
216 static void __init omap_ldp_init(void)
217 {
218         omap_i2c_init();
219         platform_add_devices(ldp_devices, ARRAY_SIZE(ldp_devices));
220         omap_board_config = ldp_config;
221         omap_board_config_size = ARRAY_SIZE(ldp_config);
222         ts_gpio = 54;
223         ldp_spi_board_info[0].irq = OMAP_GPIO_IRQ(ts_gpio);
224         spi_register_board_info(ldp_spi_board_info,
225                                 ARRAY_SIZE(ldp_spi_board_info));
226         ads7846_dev_init();
227         twl4030_bci_battery_init();
228         omap_serial_init();
229         usb_musb_init();
230         hsmmc_init();
231 }
232
233 static void __init omap_ldp_map_io(void)
234 {
235         omap2_set_globals_343x();
236         omap2_map_common_io();
237 }
238
239 MACHINE_START(OMAP_LDP, "OMAP LDP board")
240         .phys_io        = 0x48000000,
241         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
242         .boot_params    = 0x80000100,
243         .map_io         = omap_ldp_map_io,
244         .init_irq       = omap_ldp_init_irq,
245         .init_machine   = omap_ldp_init,
246         .timer          = &omap_timer,
247 MACHINE_END