Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
[sfrench/cifs-2.6.git] / arch / arm / mach-omap2 / board-zoom-peripherals.c
1 /*
2  * Copyright (C) 2009 Texas Instruments Inc.
3  *
4  * Modified from mach-omap2/board-zoom2.c
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/input.h>
15 #include <linux/input/matrix_keypad.h>
16 #include <linux/gpio.h>
17 #include <linux/i2c/twl.h>
18 #include <linux/regulator/machine.h>
19 #include <linux/regulator/fixed.h>
20 #include <linux/wl12xx.h>
21
22 #include <asm/mach-types.h>
23 #include <asm/mach/arch.h>
24 #include <asm/mach/map.h>
25
26 #include <plat/common.h>
27 #include <plat/usb.h>
28
29 #include <mach/board-zoom.h>
30
31 #include "mux.h"
32 #include "hsmmc.h"
33
34 #define OMAP_ZOOM_WLAN_PMENA_GPIO       (101)
35 #define OMAP_ZOOM_WLAN_IRQ_GPIO         (162)
36
37 /* Zoom2 has Qwerty keyboard*/
38 static int board_keymap[] = {
39         KEY(0, 0, KEY_E),
40         KEY(0, 1, KEY_R),
41         KEY(0, 2, KEY_T),
42         KEY(0, 3, KEY_HOME),
43         KEY(0, 6, KEY_I),
44         KEY(0, 7, KEY_LEFTSHIFT),
45         KEY(1, 0, KEY_D),
46         KEY(1, 1, KEY_F),
47         KEY(1, 2, KEY_G),
48         KEY(1, 3, KEY_SEND),
49         KEY(1, 6, KEY_K),
50         KEY(1, 7, KEY_ENTER),
51         KEY(2, 0, KEY_X),
52         KEY(2, 1, KEY_C),
53         KEY(2, 2, KEY_V),
54         KEY(2, 3, KEY_END),
55         KEY(2, 6, KEY_DOT),
56         KEY(2, 7, KEY_CAPSLOCK),
57         KEY(3, 0, KEY_Z),
58         KEY(3, 1, KEY_KPPLUS),
59         KEY(3, 2, KEY_B),
60         KEY(3, 3, KEY_F1),
61         KEY(3, 6, KEY_O),
62         KEY(3, 7, KEY_SPACE),
63         KEY(4, 0, KEY_W),
64         KEY(4, 1, KEY_Y),
65         KEY(4, 2, KEY_U),
66         KEY(4, 3, KEY_F2),
67         KEY(4, 4, KEY_VOLUMEUP),
68         KEY(4, 6, KEY_L),
69         KEY(4, 7, KEY_LEFT),
70         KEY(5, 0, KEY_S),
71         KEY(5, 1, KEY_H),
72         KEY(5, 2, KEY_J),
73         KEY(5, 3, KEY_F3),
74         KEY(5, 4, KEY_UNKNOWN),
75         KEY(5, 5, KEY_VOLUMEDOWN),
76         KEY(5, 6, KEY_M),
77         KEY(5, 7, KEY_RIGHT),
78         KEY(6, 0, KEY_Q),
79         KEY(6, 1, KEY_A),
80         KEY(6, 2, KEY_N),
81         KEY(6, 3, KEY_BACKSPACE),
82         KEY(6, 6, KEY_P),
83         KEY(6, 7, KEY_UP),
84         KEY(7, 0, KEY_PROG1),   /*MACRO 1 <User defined> */
85         KEY(7, 1, KEY_PROG2),   /*MACRO 2 <User defined> */
86         KEY(7, 2, KEY_PROG3),   /*MACRO 3 <User defined> */
87         KEY(7, 3, KEY_PROG4),   /*MACRO 4 <User defined> */
88         KEY(7, 6, KEY_SELECT),
89         KEY(7, 7, KEY_DOWN)
90 };
91
92 static struct matrix_keymap_data board_map_data = {
93         .keymap                 = board_keymap,
94         .keymap_size            = ARRAY_SIZE(board_keymap),
95 };
96
97 static struct twl4030_keypad_data zoom_kp_twl4030_data = {
98         .keymap_data    = &board_map_data,
99         .rows           = 8,
100         .cols           = 8,
101         .rep            = 1,
102 };
103
104 static struct regulator_consumer_supply zoom_vmmc1_supply = {
105         .supply         = "vmmc",
106 };
107
108 static struct regulator_consumer_supply zoom_vsim_supply = {
109         .supply         = "vmmc_aux",
110 };
111
112 static struct regulator_consumer_supply zoom_vmmc2_supply = {
113         .supply         = "vmmc",
114 };
115
116 static struct regulator_consumer_supply zoom_vmmc3_supply = {
117         .supply         = "vmmc",
118         .dev_name       = "mmci-omap-hs.2",
119 };
120
121 /* VMMC1 for OMAP VDD_MMC1 (i/o) and MMC1 card */
122 static struct regulator_init_data zoom_vmmc1 = {
123         .constraints = {
124                 .min_uV                 = 1850000,
125                 .max_uV                 = 3150000,
126                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
127                                         | REGULATOR_MODE_STANDBY,
128                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
129                                         | REGULATOR_CHANGE_MODE
130                                         | REGULATOR_CHANGE_STATUS,
131         },
132         .num_consumer_supplies  = 1,
133         .consumer_supplies      = &zoom_vmmc1_supply,
134 };
135
136 /* VMMC2 for MMC2 card */
137 static struct regulator_init_data zoom_vmmc2 = {
138         .constraints = {
139                 .min_uV                 = 1850000,
140                 .max_uV                 = 1850000,
141                 .apply_uV               = true,
142                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
143                                         | REGULATOR_MODE_STANDBY,
144                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
145                                         | REGULATOR_CHANGE_STATUS,
146         },
147         .num_consumer_supplies  = 1,
148         .consumer_supplies      = &zoom_vmmc2_supply,
149 };
150
151 /* VSIM for OMAP VDD_MMC1A (i/o for DAT4..DAT7) */
152 static struct regulator_init_data zoom_vsim = {
153         .constraints = {
154                 .min_uV                 = 1800000,
155                 .max_uV                 = 3000000,
156                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
157                                         | REGULATOR_MODE_STANDBY,
158                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
159                                         | REGULATOR_CHANGE_MODE
160                                         | REGULATOR_CHANGE_STATUS,
161         },
162         .num_consumer_supplies  = 1,
163         .consumer_supplies      = &zoom_vsim_supply,
164 };
165
166 static struct regulator_init_data zoom_vmmc3 = {
167         .constraints = {
168                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
169         },
170         .num_consumer_supplies  = 1,
171         .consumer_supplies = &zoom_vmmc3_supply,
172 };
173
174 static struct fixed_voltage_config zoom_vwlan = {
175         .supply_name            = "vwl1271",
176         .microvolts             = 1800000, /* 1.8V */
177         .gpio                   = OMAP_ZOOM_WLAN_PMENA_GPIO,
178         .startup_delay          = 70000, /* 70msec */
179         .enable_high            = 1,
180         .enabled_at_boot        = 0,
181         .init_data              = &zoom_vmmc3,
182 };
183
184 static struct platform_device omap_vwlan_device = {
185         .name           = "reg-fixed-voltage",
186         .id             = 1,
187         .dev = {
188                 .platform_data  = &zoom_vwlan,
189         },
190 };
191
192 struct wl12xx_platform_data omap_zoom_wlan_data __initdata = {
193         .irq = OMAP_GPIO_IRQ(OMAP_ZOOM_WLAN_IRQ_GPIO),
194         /* ZOOM ref clock is 26 MHz */
195         .board_ref_clock = 1,
196 };
197
198 static struct omap2_hsmmc_info mmc[] __initdata = {
199         {
200                 .name           = "external",
201                 .mmc            = 1,
202                 .wires          = 4,
203                 .gpio_wp        = -EINVAL,
204                 .power_saving   = true,
205         },
206         {
207                 .name           = "internal",
208                 .mmc            = 2,
209                 .wires          = 8,
210                 .gpio_cd        = -EINVAL,
211                 .gpio_wp        = -EINVAL,
212                 .nonremovable   = true,
213                 .power_saving   = true,
214         },
215         {
216                 .name           = "wl1271",
217                 .mmc            = 3,
218                 .caps           = MMC_CAP_4_BIT_DATA,
219                 .gpio_wp        = -EINVAL,
220                 .gpio_cd        = -EINVAL,
221                 .nonremovable   = true,
222         },
223         {}      /* Terminator */
224 };
225
226 static int zoom_twl_gpio_setup(struct device *dev,
227                 unsigned gpio, unsigned ngpio)
228 {
229         /* gpio + 0 is "mmc0_cd" (input/IRQ) */
230         mmc[0].gpio_cd = gpio + 0;
231         omap2_hsmmc_init(mmc);
232
233         /* link regulators to MMC adapters ... we "know" the
234          * regulators will be set up only *after* we return.
235         */
236         zoom_vmmc1_supply.dev = mmc[0].dev;
237         zoom_vsim_supply.dev = mmc[0].dev;
238         zoom_vmmc2_supply.dev = mmc[1].dev;
239
240         return 0;
241 }
242
243 /* EXTMUTE callback function */
244 void zoom2_set_hs_extmute(int mute)
245 {
246         gpio_set_value(ZOOM2_HEADSET_EXTMUTE_GPIO, mute);
247 }
248
249 static int zoom_batt_table[] = {
250 /* 0 C*/
251 30800, 29500, 28300, 27100,
252 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
253 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
254 11600, 11200, 10800, 10400, 10000, 9630,  9280,  8950,  8620,  8310,
255 8020,  7730,  7460,  7200,  6950,  6710,  6470,  6250,  6040,  5830,
256 5640,  5450,  5260,  5090,  4920,  4760,  4600,  4450,  4310,  4170,
257 4040,  3910,  3790,  3670,  3550
258 };
259
260 static struct twl4030_bci_platform_data zoom_bci_data = {
261         .battery_tmp_tbl        = zoom_batt_table,
262         .tblsize                = ARRAY_SIZE(zoom_batt_table),
263 };
264
265 static struct twl4030_usb_data zoom_usb_data = {
266         .usb_mode       = T2_USB_MODE_ULPI,
267 };
268
269 static struct twl4030_gpio_platform_data zoom_gpio_data = {
270         .gpio_base      = OMAP_MAX_GPIO_LINES,
271         .irq_base       = TWL4030_GPIO_IRQ_BASE,
272         .irq_end        = TWL4030_GPIO_IRQ_END,
273         .setup          = zoom_twl_gpio_setup,
274 };
275
276 static struct twl4030_madc_platform_data zoom_madc_data = {
277         .irq_line       = 1,
278 };
279
280 static struct twl4030_codec_audio_data zoom_audio_data = {
281         .audio_mclk = 26000000,
282 };
283
284 static struct twl4030_codec_data zoom_codec_data = {
285         .audio_mclk = 26000000,
286         .audio = &zoom_audio_data,
287 };
288
289 static struct twl4030_platform_data zoom_twldata = {
290         .irq_base       = TWL4030_IRQ_BASE,
291         .irq_end        = TWL4030_IRQ_END,
292
293         /* platform_data for children goes here */
294         .bci            = &zoom_bci_data,
295         .madc           = &zoom_madc_data,
296         .usb            = &zoom_usb_data,
297         .gpio           = &zoom_gpio_data,
298         .keypad         = &zoom_kp_twl4030_data,
299         .codec          = &zoom_codec_data,
300         .vmmc1          = &zoom_vmmc1,
301         .vmmc2          = &zoom_vmmc2,
302         .vsim           = &zoom_vsim,
303
304 };
305
306 static struct i2c_board_info __initdata zoom_i2c_boardinfo[] = {
307         {
308                 I2C_BOARD_INFO("twl5030", 0x48),
309                 .flags          = I2C_CLIENT_WAKE,
310                 .irq            = INT_34XX_SYS_NIRQ,
311                 .platform_data  = &zoom_twldata,
312         },
313 };
314
315 static int __init omap_i2c_init(void)
316 {
317         if (machine_is_omap_zoom2()) {
318                 zoom_audio_data.ramp_delay_value = 3;   /* 161 ms */
319                 zoom_audio_data.hs_extmute = 1;
320                 zoom_audio_data.set_hs_extmute = zoom2_set_hs_extmute;
321         }
322         omap_register_i2c_bus(1, 2400, zoom_i2c_boardinfo,
323                         ARRAY_SIZE(zoom_i2c_boardinfo));
324         omap_register_i2c_bus(2, 400, NULL, 0);
325         omap_register_i2c_bus(3, 400, NULL, 0);
326         return 0;
327 }
328
329 static struct omap_musb_board_data musb_board_data = {
330         .interface_type         = MUSB_INTERFACE_ULPI,
331         .mode                   = MUSB_OTG,
332         .power                  = 100,
333 };
334
335 static void enable_board_wakeup_source(void)
336 {
337         /* T2 interrupt line (keypad) */
338         omap_mux_init_signal("sys_nirq",
339                 OMAP_WAKEUP_EN | OMAP_PIN_INPUT_PULLUP);
340 }
341
342 void __init zoom_peripherals_init(void)
343 {
344         if (wl12xx_set_platform_data(&omap_zoom_wlan_data))
345                 pr_err("error setting wl12xx data\n");
346
347         omap_i2c_init();
348         platform_device_register(&omap_vwlan_device);
349         usb_musb_init(&musb_board_data);
350         enable_board_wakeup_source();
351 }