]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-ldp.c
i2c: move twl4030-madc to new registration style
[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/hsmmc.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 #define ENABLE_VAUX1_DEDICATED  0x03
45 #define ENABLE_VAUX1_DEV_GRP    0x20
46
47 #define TWL4030_MSECURE_GPIO    22
48
49 static int ts_gpio;
50
51 static int __init msecure_init(void)
52 {
53         int ret = 0;
54
55 #ifdef CONFIG_RTC_DRV_TWL4030
56         /* 3430ES2.0 doesn't have msecure/gpio-22 line connected to T2 */
57         if (omap_device_type() == OMAP2_DEVICE_TYPE_GP &&
58                         system_rev < 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 = gpio_request(TWL4030_MSECURE_GPIO, "msecure");
64                 if (ret < 0) {
65                         printk(KERN_ERR "msecure_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
75                 tmp = omap_readw(msecure_pad_config_reg);
76                 tmp &= 0xF8;    /* To enable mux mode 03/04 = GPIO_RTC */
77                 tmp |= mux_mask;/* To enable mux mode 03/04 = GPIO_RTC */
78                 omap_writew(tmp, msecure_pad_config_reg);
79
80                 gpio_direction_output(TWL4030_MSECURE_GPIO, 1);
81         }
82 out:
83 #endif
84         return ret;
85 }
86
87 /**
88  * @brief ads7846_dev_init : Requests & sets GPIO line for pen-irq
89  *
90  * @return - void. If request gpio fails then Flag KERN_ERR.
91  */
92 static void ads7846_dev_init(void)
93 {
94         if (omap_request_gpio(ts_gpio) < 0) {
95                 printk(KERN_ERR "can't get ads746 pen down GPIO\n");
96                 return;
97         }
98
99         omap_set_gpio_direction(ts_gpio, 1);
100
101         omap_set_gpio_debounce(ts_gpio, 1);
102         omap_set_gpio_debounce_time(ts_gpio, 0xa);
103 }
104
105 static int ads7846_get_pendown_state(void)
106 {
107         return !omap_get_gpio_datain(ts_gpio);
108 }
109
110 /*
111  * This enable(1)/disable(0) the voltage for TS: uses twl4030 calls
112  */
113 static int ads7846_vaux_control(int vaux_cntrl)
114 {
115         int ret = 0;
116
117 #ifdef CONFIG_TWL4030_CORE
118         /* check for return value of ldo_use: if success it returns 0 */
119         if (vaux_cntrl == VAUX_ENABLE) {
120                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
121                         ENABLE_VAUX1_DEDICATED, TWL4030_VAUX1_DEDICATED))
122                         return -EIO;
123                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
124                         ENABLE_VAUX1_DEV_GRP, TWL4030_VAUX1_DEV_GRP))
125                         return -EIO;
126         } else if (vaux_cntrl == VAUX_DISABLE) {
127                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
128                         0x00, TWL4030_VAUX1_DEDICATED))
129                         return -EIO;
130                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
131                         0x00, TWL4030_VAUX1_DEV_GRP))
132                         return -EIO;
133         }
134 #else
135         ret = -EIO;
136 #endif
137         return ret;
138 }
139
140 static struct ads7846_platform_data tsc2046_config __initdata = {
141         .get_pendown_state      = ads7846_get_pendown_state,
142         .keep_vref_on           = 1,
143         .vaux_control           = ads7846_vaux_control,
144 };
145
146
147 static struct omap2_mcspi_device_config tsc2046_mcspi_config = {
148         .turbo_mode     = 0,
149         .single_channel = 1,  /* 0: slave, 1: master */
150 };
151
152 static struct spi_board_info ldp_spi_board_info[] __initdata = {
153         [0] = {
154                 /*
155                  * TSC2046 operates at a max freqency of 2MHz, so
156                  * operate slightly below at 1.5MHz
157                  */
158                 .modalias               = "ads7846",
159                 .bus_num                = 1,
160                 .chip_select            = 0,
161                 .max_speed_hz           = 1500000,
162                 .controller_data        = &tsc2046_mcspi_config,
163                 .irq                    = 0,
164                 .platform_data          = &tsc2046_config,
165         },
166 };
167
168 static struct platform_device *ldp_devices[] __initdata = {
169 };
170
171 static void __init omap_ldp_init_irq(void)
172 {
173         omap2_init_common_hw(NULL);
174         omap_init_irq();
175         omap_gpio_init();
176 }
177
178 static struct omap_uart_config ldp_uart_config __initdata = {
179         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
180 };
181
182 static struct omap_board_config_kernel ldp_config[] __initdata = {
183         { OMAP_TAG_UART,        &ldp_uart_config },
184 };
185
186 static struct twl4030_usb_data ldp_usb_data = {
187         .usb_mode       = T2_USB_MODE_ULPI,
188 };
189
190 static struct twl4030_gpio_platform_data ldp_gpio_data = {
191         .gpio_base      = OMAP_MAX_GPIO_LINES,
192         .irq_base       = TWL4030_GPIO_IRQ_BASE,
193         .irq_end        = TWL4030_GPIO_IRQ_END,
194 };
195
196 static struct twl4030_madc_platform_data ldp_madc_data = {
197         .irq_line       = 1,
198 };
199
200 static struct twl4030_platform_data ldp_twldata = {
201         .irq_base       = TWL4030_IRQ_BASE,
202         .irq_end        = TWL4030_IRQ_END,
203
204         /* platform_data for children goes here */
205         .madc           = &ldp_madc_data,
206         .usb            = &ldp_usb_data,
207         .gpio           = &ldp_gpio_data,
208 };
209
210 static struct i2c_board_info __initdata ldp_i2c_boardinfo[] = {
211         {
212                 I2C_BOARD_INFO("twl4030", 0x48),
213                 .flags = I2C_CLIENT_WAKE,
214                 .irq = INT_34XX_SYS_NIRQ,
215                 .platform_data = &ldp_twldata,
216         },
217 };
218
219 static int __init omap_i2c_init(void)
220 {
221         omap_register_i2c_bus(1, 2600, ldp_i2c_boardinfo,
222                         ARRAY_SIZE(ldp_i2c_boardinfo));
223         omap_register_i2c_bus(2, 400, NULL, 0);
224         omap_register_i2c_bus(3, 400, NULL, 0);
225         return 0;
226 }
227
228 static void __init omap_ldp_init(void)
229 {
230         omap_i2c_init();
231         platform_add_devices(ldp_devices, ARRAY_SIZE(ldp_devices));
232         omap_board_config = ldp_config;
233         omap_board_config_size = ARRAY_SIZE(ldp_config);
234         ts_gpio = 54;
235         ldp_spi_board_info[0].irq = OMAP_GPIO_IRQ(ts_gpio);
236         spi_register_board_info(ldp_spi_board_info,
237                                 ARRAY_SIZE(ldp_spi_board_info));
238         msecure_init();
239         ads7846_dev_init();
240         twl4030_bci_battery_init();
241         omap_serial_init();
242         usb_musb_init();
243         hsmmc_init();
244 }
245
246 static void __init omap_ldp_map_io(void)
247 {
248         omap2_set_globals_343x();
249         omap2_map_common_io();
250 }
251
252 MACHINE_START(OMAP_LDP, "OMAP LDP board")
253         .phys_io        = 0x48000000,
254         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
255         .boot_params    = 0x80000100,
256         .map_io         = omap_ldp_map_io,
257         .init_irq       = omap_ldp_init_irq,
258         .init_machine   = omap_ldp_init,
259         .timer          = &omap_timer,
260 MACHINE_END