arm/omap: Replace board_ref_clock with enum values
[pandora-kernel.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 #include <linux/mmc/host.h>
22 #include <linux/platform_data/gpio-omap.h>
23
24 #include <asm/mach-types.h>
25 #include <asm/mach/arch.h>
26 #include <asm/mach/map.h>
27
28 #include "common.h"
29 #include <plat/usb.h>
30
31 #include <mach/board-zoom.h>
32
33 #include "mux.h"
34 #include "hsmmc.h"
35 #include "common-board-devices.h"
36
37 #define OMAP_ZOOM_WLAN_PMENA_GPIO       (101)
38 #define OMAP_ZOOM_WLAN_IRQ_GPIO         (162)
39
40 #define LCD_PANEL_ENABLE_GPIO           (7 + OMAP_MAX_GPIO_LINES)
41
42 /* Zoom2 has Qwerty keyboard*/
43 static uint32_t board_keymap[] = {
44         KEY(0, 0, KEY_E),
45         KEY(0, 1, KEY_R),
46         KEY(0, 2, KEY_T),
47         KEY(0, 3, KEY_HOME),
48         KEY(0, 6, KEY_I),
49         KEY(0, 7, KEY_LEFTSHIFT),
50         KEY(1, 0, KEY_D),
51         KEY(1, 1, KEY_F),
52         KEY(1, 2, KEY_G),
53         KEY(1, 3, KEY_SEND),
54         KEY(1, 6, KEY_K),
55         KEY(1, 7, KEY_ENTER),
56         KEY(2, 0, KEY_X),
57         KEY(2, 1, KEY_C),
58         KEY(2, 2, KEY_V),
59         KEY(2, 3, KEY_END),
60         KEY(2, 6, KEY_DOT),
61         KEY(2, 7, KEY_CAPSLOCK),
62         KEY(3, 0, KEY_Z),
63         KEY(3, 1, KEY_KPPLUS),
64         KEY(3, 2, KEY_B),
65         KEY(3, 3, KEY_F1),
66         KEY(3, 6, KEY_O),
67         KEY(3, 7, KEY_SPACE),
68         KEY(4, 0, KEY_W),
69         KEY(4, 1, KEY_Y),
70         KEY(4, 2, KEY_U),
71         KEY(4, 3, KEY_F2),
72         KEY(4, 4, KEY_VOLUMEUP),
73         KEY(4, 6, KEY_L),
74         KEY(4, 7, KEY_LEFT),
75         KEY(5, 0, KEY_S),
76         KEY(5, 1, KEY_H),
77         KEY(5, 2, KEY_J),
78         KEY(5, 3, KEY_F3),
79         KEY(5, 4, KEY_UNKNOWN),
80         KEY(5, 5, KEY_VOLUMEDOWN),
81         KEY(5, 6, KEY_M),
82         KEY(5, 7, KEY_RIGHT),
83         KEY(6, 0, KEY_Q),
84         KEY(6, 1, KEY_A),
85         KEY(6, 2, KEY_N),
86         KEY(6, 3, KEY_BACKSPACE),
87         KEY(6, 6, KEY_P),
88         KEY(6, 7, KEY_UP),
89         KEY(7, 0, KEY_PROG1),   /*MACRO 1 <User defined> */
90         KEY(7, 1, KEY_PROG2),   /*MACRO 2 <User defined> */
91         KEY(7, 2, KEY_PROG3),   /*MACRO 3 <User defined> */
92         KEY(7, 3, KEY_PROG4),   /*MACRO 4 <User defined> */
93         KEY(7, 6, KEY_SELECT),
94         KEY(7, 7, KEY_DOWN)
95 };
96
97 static struct matrix_keymap_data board_map_data = {
98         .keymap                 = board_keymap,
99         .keymap_size            = ARRAY_SIZE(board_keymap),
100 };
101
102 static struct twl4030_keypad_data zoom_kp_twl4030_data = {
103         .keymap_data    = &board_map_data,
104         .rows           = 8,
105         .cols           = 8,
106         .rep            = 1,
107 };
108
109 static struct regulator_consumer_supply zoom_vmmc1_supply[] = {
110         REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
111 };
112
113 static struct regulator_consumer_supply zoom_vsim_supply[] = {
114         REGULATOR_SUPPLY("vmmc_aux", "omap_hsmmc.0"),
115 };
116
117 static struct regulator_consumer_supply zoom_vmmc2_supply[] = {
118         REGULATOR_SUPPLY("vmmc", "omap_hsmmc.1"),
119 };
120
121 static struct regulator_consumer_supply zoom_vmmc3_supply[] = {
122         REGULATOR_SUPPLY("vmmc", "omap_hsmmc.2"),
123 };
124
125 /* VMMC1 for OMAP VDD_MMC1 (i/o) and MMC1 card */
126 static struct regulator_init_data zoom_vmmc1 = {
127         .constraints = {
128                 .min_uV                 = 1850000,
129                 .max_uV                 = 3150000,
130                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
131                                         | REGULATOR_MODE_STANDBY,
132                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
133                                         | REGULATOR_CHANGE_MODE
134                                         | REGULATOR_CHANGE_STATUS,
135         },
136         .num_consumer_supplies  = ARRAY_SIZE(zoom_vmmc1_supply),
137         .consumer_supplies      = zoom_vmmc1_supply,
138 };
139
140 /* VMMC2 for MMC2 card */
141 static struct regulator_init_data zoom_vmmc2 = {
142         .constraints = {
143                 .min_uV                 = 1850000,
144                 .max_uV                 = 1850000,
145                 .apply_uV               = true,
146                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
147                                         | REGULATOR_MODE_STANDBY,
148                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
149                                         | REGULATOR_CHANGE_STATUS,
150         },
151         .num_consumer_supplies  = ARRAY_SIZE(zoom_vmmc2_supply),
152         .consumer_supplies      = zoom_vmmc2_supply,
153 };
154
155 /* VSIM for OMAP VDD_MMC1A (i/o for DAT4..DAT7) */
156 static struct regulator_init_data zoom_vsim = {
157         .constraints = {
158                 .min_uV                 = 1800000,
159                 .max_uV                 = 3000000,
160                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
161                                         | REGULATOR_MODE_STANDBY,
162                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
163                                         | REGULATOR_CHANGE_MODE
164                                         | REGULATOR_CHANGE_STATUS,
165         },
166         .num_consumer_supplies  = ARRAY_SIZE(zoom_vsim_supply),
167         .consumer_supplies      = zoom_vsim_supply,
168 };
169
170 static struct regulator_init_data zoom_vmmc3 = {
171         .constraints = {
172                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
173         },
174         .num_consumer_supplies  = ARRAY_SIZE(zoom_vmmc3_supply),
175         .consumer_supplies      = zoom_vmmc3_supply,
176 };
177
178 static struct fixed_voltage_config zoom_vwlan = {
179         .supply_name            = "vwl1271",
180         .microvolts             = 1800000, /* 1.8V */
181         .gpio                   = OMAP_ZOOM_WLAN_PMENA_GPIO,
182         .startup_delay          = 70000, /* 70msec */
183         .enable_high            = 1,
184         .enabled_at_boot        = 0,
185         .init_data              = &zoom_vmmc3,
186 };
187
188 static struct platform_device omap_vwlan_device = {
189         .name           = "reg-fixed-voltage",
190         .id             = 1,
191         .dev = {
192                 .platform_data  = &zoom_vwlan,
193         },
194 };
195
196 static struct wl12xx_platform_data omap_zoom_wlan_data __initdata = {
197         .board_ref_clock = WL12XX_REFCLOCK_26, /* 26 MHz */
198 };
199
200 static struct omap2_hsmmc_info mmc[] = {
201         {
202                 .name           = "external",
203                 .mmc            = 1,
204                 .caps           = MMC_CAP_4_BIT_DATA,
205                 .gpio_wp        = -EINVAL,
206                 .power_saving   = true,
207                 .deferred       = true,
208         },
209         {
210                 .name           = "internal",
211                 .mmc            = 2,
212                 .caps           = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
213                 .gpio_cd        = -EINVAL,
214                 .gpio_wp        = -EINVAL,
215                 .nonremovable   = true,
216                 .power_saving   = true,
217         },
218         {
219                 .name           = "wl1271",
220                 .mmc            = 3,
221                 .caps           = MMC_CAP_4_BIT_DATA | MMC_CAP_POWER_OFF_CARD,
222                 .gpio_wp        = -EINVAL,
223                 .gpio_cd        = -EINVAL,
224                 .nonremovable   = true,
225         },
226         {}      /* Terminator */
227 };
228
229 static int zoom_twl_gpio_setup(struct device *dev,
230                 unsigned gpio, unsigned ngpio)
231 {
232         int ret;
233
234         /* gpio + 0 is "mmc0_cd" (input/IRQ) */
235         mmc[0].gpio_cd = gpio + 0;
236         omap_hsmmc_late_init(mmc);
237
238         ret = gpio_request_one(LCD_PANEL_ENABLE_GPIO, GPIOF_OUT_INIT_LOW,
239                                "lcd enable");
240         if (ret)
241                 pr_err("Failed to get LCD_PANEL_ENABLE_GPIO (gpio%d).\n",
242                                 LCD_PANEL_ENABLE_GPIO);
243
244         return ret;
245 }
246
247 /* EXTMUTE callback function */
248 static void zoom2_set_hs_extmute(int mute)
249 {
250         gpio_set_value(ZOOM2_HEADSET_EXTMUTE_GPIO, mute);
251 }
252
253 static struct twl4030_gpio_platform_data zoom_gpio_data = {
254         .setup          = zoom_twl_gpio_setup,
255 };
256
257 static struct twl4030_platform_data zoom_twldata = {
258         /* platform_data for children goes here */
259         .gpio           = &zoom_gpio_data,
260         .keypad         = &zoom_kp_twl4030_data,
261         .vmmc1          = &zoom_vmmc1,
262         .vmmc2          = &zoom_vmmc2,
263         .vsim           = &zoom_vsim,
264 };
265
266 static int __init omap_i2c_init(void)
267 {
268         omap3_pmic_get_config(&zoom_twldata,
269                         TWL_COMMON_PDATA_USB | TWL_COMMON_PDATA_BCI |
270                         TWL_COMMON_PDATA_MADC | TWL_COMMON_PDATA_AUDIO,
271                         TWL_COMMON_REGULATOR_VDAC | TWL_COMMON_REGULATOR_VPLL2);
272
273         if (machine_is_omap_zoom2()) {
274                 struct twl4030_codec_data *codec_data;
275                 codec_data = zoom_twldata.audio->codec;
276
277                 codec_data->ramp_delay_value = 3;       /* 161 ms */
278                 codec_data->hs_extmute = 1;
279                 codec_data->set_hs_extmute = zoom2_set_hs_extmute;
280         }
281         omap_pmic_init(1, 2400, "twl5030", 7 + OMAP_INTC_START, &zoom_twldata);
282         omap_register_i2c_bus(2, 400, NULL, 0);
283         omap_register_i2c_bus(3, 400, NULL, 0);
284         return 0;
285 }
286
287 static void enable_board_wakeup_source(void)
288 {
289         /* T2 interrupt line (keypad) */
290         omap_mux_init_signal("sys_nirq",
291                 OMAP_WAKEUP_EN | OMAP_PIN_INPUT_PULLUP);
292 }
293
294 void __init zoom_peripherals_init(void)
295 {
296         int ret;
297
298         omap_zoom_wlan_data.irq = gpio_to_irq(OMAP_ZOOM_WLAN_IRQ_GPIO);
299         ret = wl12xx_set_platform_data(&omap_zoom_wlan_data);
300
301         if (ret)
302                 pr_err("error setting wl12xx data: %d\n", ret);
303
304         omap_hsmmc_init(mmc);
305         omap_i2c_init();
306         platform_device_register(&omap_vwlan_device);
307         usb_musb_init(NULL);
308         enable_board_wakeup_source();
309         omap_serial_init();
310 }