ARM: tegra: cardhu: Adjust cpu-suspend timers on some boards.
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu-power.c
1 /*
2  * arch/arm/mach-tegra/board-cardhu-power.c
3  *
4  * Copyright (C) 2011 NVIDIA, Inc.
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  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18  * 02111-1307, USA
19  */
20 #include <linux/i2c.h>
21 #include <linux/pda_power.h>
22 #include <linux/platform_device.h>
23 #include <linux/resource.h>
24 #include <linux/regulator/machine.h>
25 #include <linux/mfd/tps6591x.h>
26 #include <linux/gpio.h>
27 #include <mach/suspend.h>
28 #include <linux/io.h>
29 #include <linux/regulator/gpio-switch-regulator.h>
30 #include <linux/regulator/tps6591x-regulator.h>
31
32 #include <mach/iomap.h>
33 #include <mach/irqs.h>
34 #include <mach/pinmux.h>
35
36 #include "gpio-names.h"
37 #include "board.h"
38 #include "board-cardhu.h"
39 #include "power.h"
40 #include "wakeups-t3.h"
41
42 #define PMC_CTRL                0x0
43 #define PMC_CTRL_INTR_LOW       (1 << 17)
44
45 static struct regulator_consumer_supply tps6591x_vdd1_supply[] = {
46         REGULATOR_SUPPLY("vdd_core", NULL),
47         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
48 };
49
50 static struct regulator_consumer_supply tps6591x_vdd2_supply[] = {
51         REGULATOR_SUPPLY("vdd_gen1v5", NULL),
52         REGULATOR_SUPPLY("vcore_lcd", NULL),
53         REGULATOR_SUPPLY("track_ldo1", NULL),
54         REGULATOR_SUPPLY("external_ldo_1v2", NULL),
55         REGULATOR_SUPPLY("vcore_cam1", NULL),
56         REGULATOR_SUPPLY("vcore_cam2", NULL),
57 };
58
59 static struct regulator_consumer_supply tps6591x_vddctrl_supply[] = {
60         REGULATOR_SUPPLY("vdd_cpu_pmu", NULL),
61         REGULATOR_SUPPLY("vdd_cpu", NULL),
62         REGULATOR_SUPPLY("vdd_sys", NULL),
63 };
64
65 static struct regulator_consumer_supply tps6591x_vio_supply[] = {
66         REGULATOR_SUPPLY("vdd_gen1v8", NULL),
67         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
68         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
69         REGULATOR_SUPPLY("avdd_osc", NULL),
70         REGULATOR_SUPPLY("vddio_sys", NULL),
71         REGULATOR_SUPPLY("vddio_sdmmc4", NULL),
72         REGULATOR_SUPPLY("vdd1v8_satelite", NULL),
73         REGULATOR_SUPPLY("vddio_uart", NULL),
74         REGULATOR_SUPPLY("vddio_audio", NULL),
75         REGULATOR_SUPPLY("vddio_bb", NULL),
76         REGULATOR_SUPPLY("vddio_lcd_pmu", NULL),
77         REGULATOR_SUPPLY("vddio_cam", NULL),
78         REGULATOR_SUPPLY("vddio_vi", NULL),
79         REGULATOR_SUPPLY("ldo6", NULL),
80         REGULATOR_SUPPLY("ldo7", NULL),
81         REGULATOR_SUPPLY("ldo8", NULL),
82         REGULATOR_SUPPLY("vcore_audio", NULL),
83         REGULATOR_SUPPLY("avcore_audio", NULL),
84         REGULATOR_SUPPLY("vddio_sdmmc3", NULL),
85         REGULATOR_SUPPLY("vcore1_lpddr2", NULL),
86         REGULATOR_SUPPLY("vcom_1v8", NULL),
87         REGULATOR_SUPPLY("pmuio_1v8", NULL),
88         REGULATOR_SUPPLY("avdd_ic_usb", NULL),
89 };
90
91 static struct regulator_consumer_supply tps6591x_ldo1_supply[] = {
92         REGULATOR_SUPPLY("avdd_pexb", NULL),
93         REGULATOR_SUPPLY("vdd_pexb", NULL),
94         REGULATOR_SUPPLY("avdd_pex_pll", NULL),
95         REGULATOR_SUPPLY("avdd_pexa", NULL),
96         REGULATOR_SUPPLY("vdd_pexa", NULL),
97 };
98
99 static struct regulator_consumer_supply tps6591x_ldo2_supply[] = {
100         REGULATOR_SUPPLY("avdd_sata", NULL),
101         REGULATOR_SUPPLY("vdd_sata", NULL),
102         REGULATOR_SUPPLY("avdd_sata_pll", NULL),
103         REGULATOR_SUPPLY("avdd_plle", NULL),
104 };
105
106 static struct regulator_consumer_supply tps6591x_ldo3_supply_e118x[] = {
107         REGULATOR_SUPPLY("vddio_sdmmc1", NULL),
108 };
109
110 static struct regulator_consumer_supply tps6591x_ldo3_supply_e1198[] = {
111         REGULATOR_SUPPLY("unused_rail_ldo3", NULL),
112 };
113
114 static struct regulator_consumer_supply tps6591x_ldo4_supply[] = {
115         REGULATOR_SUPPLY("vdd_rtc", NULL),
116 };
117
118 static struct regulator_consumer_supply tps6591x_ldo5_supply_e118x[] = {
119         REGULATOR_SUPPLY("avdd_vdac", NULL),
120 };
121
122 static struct regulator_consumer_supply tps6591x_ldo5_supply_e1198[] = {
123         REGULATOR_SUPPLY("avdd_vdac", NULL),
124         REGULATOR_SUPPLY("vddio_sdmmc1", NULL),
125 };
126
127 static struct regulator_consumer_supply tps6591x_ldo6_supply[] = {
128         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
129 };
130 static struct regulator_consumer_supply tps6591x_ldo7_supply[] = {
131         REGULATOR_SUPPLY("avdd_plla_p_c_s", NULL),
132         REGULATOR_SUPPLY("avdd_pllm", NULL),
133         REGULATOR_SUPPLY("avdd_pllu_d", NULL),
134         REGULATOR_SUPPLY("avdd_pllu_d2", NULL),
135         REGULATOR_SUPPLY("avdd_pllx", NULL),
136 };
137
138 static struct regulator_consumer_supply tps6591x_ldo8_supply[] = {
139         REGULATOR_SUPPLY("vdd_ddr_hs", NULL),
140 };
141
142 #define TPS_PDATA_INIT_SUPPLY(_id, _minmv, _maxmv, _supply_reg, _always_on, \
143         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply, _ectrl) \
144         static struct tps6591x_regulator_platform_data pdata_##_id =    \
145         {                                                               \
146                 .regulator = {                                          \
147                         .constraints = {                                \
148                                 .min_uV = (_minmv)*1000,                \
149                                 .max_uV = (_maxmv)*1000,                \
150                                 .valid_modes_mask = (REGULATOR_MODE_NORMAL |  \
151                                                      REGULATOR_MODE_STANDBY), \
152                                 .valid_ops_mask = (REGULATOR_CHANGE_MODE |    \
153                                                    REGULATOR_CHANGE_STATUS |  \
154                                                    REGULATOR_CHANGE_VOLTAGE), \
155                                 .always_on = _always_on,                \
156                                 .boot_on = _boot_on,                    \
157                                 .apply_uV = _apply_uv,                  \
158                         },                                              \
159                         .num_consumer_supplies =                        \
160                                 ARRAY_SIZE(tps6591x_##_id##_supply),    \
161                         .consumer_supplies = tps6591x_##_id##_supply,   \
162                         .supply_regulator = tps6591x_rails(_supply_reg), \
163                 },                                                      \
164                 .init_uV =  _init_uV * 1000,                            \
165                 .init_enable = _init_enable,                            \
166                 .init_apply = _init_apply,                              \
167                 .ectrl = _ectrl                                         \
168         }
169
170 #define TPS_PDATA_INIT(_id, _minmv, _maxmv, _supply_reg, _always_on,    \
171         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply, _ectrl) \
172         static struct tps6591x_regulator_platform_data pdata_##_id =    \
173         {                                                               \
174                 .regulator = {                                          \
175                         .constraints = {                                \
176                                 .min_uV = (_minmv)*1000,                \
177                                 .max_uV = (_maxmv)*1000,                \
178                                 .valid_modes_mask = (REGULATOR_MODE_NORMAL |  \
179                                                      REGULATOR_MODE_STANDBY), \
180                                 .valid_ops_mask = (REGULATOR_CHANGE_MODE |    \
181                                                    REGULATOR_CHANGE_STATUS |  \
182                                                    REGULATOR_CHANGE_VOLTAGE), \
183                                 .always_on = _always_on,                \
184                                 .boot_on = _boot_on,                    \
185                                 .apply_uV = _apply_uv,                  \
186                         },                                              \
187                         .num_consumer_supplies =                        \
188                                 ARRAY_SIZE(tps6591x_##_id##_supply),    \
189                         .consumer_supplies = tps6591x_##_id##_supply,   \
190                 },                                                      \
191                 .init_uV =  _init_uV * 1000,                            \
192                 .init_enable = _init_enable,                            \
193                 .init_apply = _init_apply,                              \
194                 .ectrl = _ectrl                                         \
195         }
196
197 #define TPS_PDATA_INIT_BOARD(_id, _board, _minmv, _maxmv, _supply_reg, _always_on,      \
198         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply, _ectrl) \
199         static struct tps6591x_regulator_platform_data pdata_##_id##_##_board = \
200         {                                                               \
201                 .regulator = {                                          \
202                         .constraints = {                                \
203                                 .min_uV = (_minmv)*1000,                \
204                                 .max_uV = (_maxmv)*1000,                \
205                                 .valid_modes_mask = (REGULATOR_MODE_NORMAL |  \
206                                                      REGULATOR_MODE_STANDBY), \
207                                 .valid_ops_mask = (REGULATOR_CHANGE_MODE |    \
208                                                    REGULATOR_CHANGE_STATUS |  \
209                                                    REGULATOR_CHANGE_VOLTAGE), \
210                                 .always_on = _always_on,                \
211                                 .boot_on = _boot_on,                    \
212                                 .apply_uV = _apply_uv,                  \
213                         },                                              \
214                         .num_consumer_supplies =                        \
215                                 ARRAY_SIZE(tps6591x_##_id##_supply##_##_board),  \
216                         .consumer_supplies = tps6591x_##_id##_supply##_##_board, \
217                 },                                                      \
218                 .init_uV =  _init_uV * 1000,                            \
219                 .init_enable = _init_enable,                            \
220                 .init_apply = _init_apply,                              \
221                 .ectrl = _ectrl                                         \
222         }
223
224 TPS_PDATA_INIT(vdd1,    600, 1500, 0, 1, 1, 0, -1, 0, 0, 0);
225 TPS_PDATA_INIT(vdd2,    600, 1500, 0, 1, 1, 0, -1, 0, 0, 0);
226 TPS_PDATA_INIT(vddctrl, 600, 1400, 0, 1, 1, 0, -1, 0, 0, EXT_CTRL_EN1);
227 TPS_PDATA_INIT(vio,    1500, 3300, 0, 1, 1, 0, -1, 0, 0, 0);
228
229 TPS_PDATA_INIT_SUPPLY(ldo1, 1000, 3300, VDD_2, 0, 0, 0, -1, 0, 0, 0);
230 TPS_PDATA_INIT_SUPPLY(ldo2, 1000, 3300, VDD_2, 0, 0, 0, -1, 0, 0, 0);
231
232 TPS_PDATA_INIT_BOARD(ldo3, e118x, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0);
233 TPS_PDATA_INIT_BOARD(ldo3, e1198, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0);
234 TPS_PDATA_INIT(ldo4, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0);
235 TPS_PDATA_INIT_BOARD(ldo5, e118x, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0);
236 TPS_PDATA_INIT_BOARD(ldo5, e1198, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0);
237
238 TPS_PDATA_INIT_SUPPLY(ldo6, 1000, 3300, VIO, 0, 0, 0, -1, 0, 0, 0);
239 TPS_PDATA_INIT_SUPPLY(ldo7, 1000, 3300, VIO, 0, 0, 0, -1, 0, 0, 0);
240 TPS_PDATA_INIT_SUPPLY(ldo8, 1000, 3300, VIO, 0, 0, 0, -1, 0, 0, 0);
241
242 static struct tps6591x_rtc_platform_data rtc_data = {
243         .irq = TEGRA_NR_IRQS + TPS6591X_INT_RTC_ALARM,
244 };
245
246 #define TPS_REG(_id, _data)                             \
247         {                                               \
248                 .id     = TPS6591X_ID_##_id,            \
249                 .name   = "tps6591x-regulator",         \
250                 .platform_data  = &pdata_##_data,       \
251         }
252
253 #define TPS_RTC_REG()                           \
254         {                                               \
255                 .id     = 0,            \
256                 .name   = "rtc_tps6591x",       \
257                 .platform_data = &rtc_data,     \
258         }
259
260 static struct tps6591x_subdev_info tps_devs_e118x[] = {
261         TPS_REG(VIO, vio),
262         TPS_REG(VDD_1, vdd1),
263         TPS_REG(VDD_2, vdd2),
264         TPS_REG(VDDCTRL, vddctrl),
265         TPS_REG(LDO_1, ldo1),
266         TPS_REG(LDO_2, ldo2),
267         TPS_REG(LDO_3, ldo3_e118x),
268         TPS_REG(LDO_4, ldo4),
269         TPS_REG(LDO_5, ldo5_e118x),
270         TPS_REG(LDO_6, ldo6),
271         TPS_REG(LDO_7, ldo7),
272         TPS_REG(LDO_8, ldo8),
273         TPS_RTC_REG(),
274 };
275
276 static struct tps6591x_subdev_info tps_devs_e1198[] = {
277         TPS_REG(VIO, vio),
278         TPS_REG(VDD_1, vdd1),
279         TPS_REG(VDD_2, vdd2),
280         TPS_REG(VDDCTRL, vddctrl),
281         TPS_REG(LDO_1, ldo1),
282         TPS_REG(LDO_2, ldo2),
283         TPS_REG(LDO_3, ldo3_e1198),
284         TPS_REG(LDO_4, ldo4),
285         TPS_REG(LDO_5, ldo5_e1198),
286         TPS_REG(LDO_6, ldo6),
287         TPS_REG(LDO_7, ldo7),
288         TPS_REG(LDO_8, ldo8),
289         TPS_RTC_REG(),
290 };
291
292 static struct tps6591x_platform_data tps_platform = {
293         .irq_base       = TPS6591X_IRQ_BASE,
294         .gpio_base      = TPS6591X_GPIO_BASE,
295 };
296
297 static struct i2c_board_info __initdata cardhu_regulators[] = {
298         {
299                 I2C_BOARD_INFO("tps6591x", 0x2D),
300                 .irq            = INT_EXTERNAL_PMU,
301                 .platform_data  = &tps_platform,
302         },
303 };
304
305 int __init cardhu_regulator_init(void)
306 {
307         struct board_info board_info;
308         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
309         u32 pmc_ctrl;
310         /* configure the power management controller to trigger PMU
311          * interrupts when low */
312         pmc_ctrl = readl(pmc + PMC_CTRL);
313         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
314
315         tegra_get_board_info(&board_info);
316         if ((board_info.board_id == BOARD_E1198) ||
317                 (board_info.board_id == BOARD_E1291)) {
318                 tps_platform.num_subdevs = ARRAY_SIZE(tps_devs_e1198);
319                 tps_platform.subdevs = tps_devs_e1198;
320         } else {
321                 tps_platform.num_subdevs = ARRAY_SIZE(tps_devs_e118x);
322                 tps_platform.subdevs = tps_devs_e118x;
323         }
324
325         i2c_register_board_info(4, cardhu_regulators, 1);
326         return 0;
327 }
328
329 /* EN_5V_CP from PMU GP0 */
330 static struct regulator_consumer_supply gpio_switch_en_5v_cp_supply[] = {
331         REGULATOR_SUPPLY("vdd_5v0_sby", NULL),
332         REGULATOR_SUPPLY("vdd_hall", NULL),
333         REGULATOR_SUPPLY("vterm_ddr", NULL),
334         REGULATOR_SUPPLY("v2ref_ddr", NULL),
335 };
336 static int gpio_switch_en_5v_cp_voltages[] = { 5000};
337
338 /* EN_5V0 From PMU GP2 */
339 static struct regulator_consumer_supply gpio_switch_en_5v0_supply[] = {
340         REGULATOR_SUPPLY("vdd_5v0_sys", NULL),
341 };
342 static int gpio_switch_en_5v0_voltages[] = { 5000};
343
344 /* EN_DDR From PMU GP6 */
345 static struct regulator_consumer_supply gpio_switch_en_ddr_supply[] = {
346         REGULATOR_SUPPLY("mem_vddio_ddr", NULL),
347         REGULATOR_SUPPLY("t30_vddio_ddr", NULL),
348 };
349 static int gpio_switch_en_ddr_voltages[] = { 1500};
350
351 /* EN_3V3_SYS From PMU GP7 */
352 static struct regulator_consumer_supply gpio_switch_en_3v3_sys_supply[] = {
353         REGULATOR_SUPPLY("vdd_lvds", NULL),
354         REGULATOR_SUPPLY("vdd_pnl", NULL),
355         REGULATOR_SUPPLY("vcom_3v3", NULL),
356         REGULATOR_SUPPLY("vdd_3v3", NULL),
357         REGULATOR_SUPPLY("vcore_mmc", NULL),
358         REGULATOR_SUPPLY("vddio_pex_ctl", NULL),
359         REGULATOR_SUPPLY("hvdd_pex", NULL),
360         REGULATOR_SUPPLY("avdd_hdmi", NULL),
361         REGULATOR_SUPPLY("vpp_fuse", NULL),
362         REGULATOR_SUPPLY("avdd_usb", NULL),
363         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
364         REGULATOR_SUPPLY("vcore_nand", NULL),
365         REGULATOR_SUPPLY("hvdd_sata", NULL),
366         REGULATOR_SUPPLY("vddio_gmi_pmu", NULL),
367         REGULATOR_SUPPLY("avdd_cam1", NULL),
368         REGULATOR_SUPPLY("vdd_af", NULL),
369         REGULATOR_SUPPLY("avdd_cam2", NULL),
370         REGULATOR_SUPPLY("vdd_acc", NULL),
371         REGULATOR_SUPPLY("vdd_phtl", NULL),
372         REGULATOR_SUPPLY("vddio_tp", NULL),
373         REGULATOR_SUPPLY("vdd_led", NULL),
374         REGULATOR_SUPPLY("vddio_cec", NULL),
375         REGULATOR_SUPPLY("vdd_cmps", NULL),
376         REGULATOR_SUPPLY("vdd_temp", NULL),
377         REGULATOR_SUPPLY("vpp_kfuse", NULL),
378         REGULATOR_SUPPLY("vddio_ts", NULL),
379         REGULATOR_SUPPLY("vdd_ir_led", NULL),
380         REGULATOR_SUPPLY("vddio_1wire", NULL),
381         REGULATOR_SUPPLY("avddio_audio", NULL),
382         REGULATOR_SUPPLY("vdd_ec", NULL),
383         REGULATOR_SUPPLY("vcom_pa", NULL),
384         REGULATOR_SUPPLY("vdd_3v3_devices", NULL),
385         REGULATOR_SUPPLY("vdd_3v3_dock", NULL),
386         REGULATOR_SUPPLY("vdd_3v3_edid", NULL),
387         REGULATOR_SUPPLY("vdd_3v3_hdmi_cec", NULL),
388         REGULATOR_SUPPLY("vdd_3v3_gmi", NULL),
389         REGULATOR_SUPPLY("vdd_3v3_spk_amp", NULL),
390         REGULATOR_SUPPLY("vdd_3v3_sensor", NULL),
391         REGULATOR_SUPPLY("vdd_3v3_cam", NULL),
392         REGULATOR_SUPPLY("vdd_3v3_als", NULL),
393         REGULATOR_SUPPLY("debug_cons", NULL),
394 };
395 static int gpio_switch_en_3v3_sys_voltages[] = { 3300};
396
397 /* DIS_5V_SWITCH from AP SPI2_SCK X02 */
398 static struct regulator_consumer_supply gpio_switch_dis_5v_switch_supply[] = {
399         REGULATOR_SUPPLY("master_5v_switch", NULL),
400 };
401 static int gpio_switch_dis_5v_switch_voltages[] = { 5000};
402
403 /* EN_VDD_BL */
404 static struct regulator_consumer_supply gpio_switch_en_vdd_bl_supply[] = {
405         REGULATOR_SUPPLY("vdd_backlight", NULL),
406         REGULATOR_SUPPLY("vdd_backlight1", NULL),
407 };
408 static int gpio_switch_en_vdd_bl_voltages[] = { 5000};
409
410 /* EN_VDD_BL2 (E1291-A03) from AP PEX_L0_PRSNT_N DD.00 */
411 static struct regulator_consumer_supply gpio_switch_en_vdd_bl2_supply[] = {
412         REGULATOR_SUPPLY("vdd_backlight2", NULL),
413 };
414 static int gpio_switch_en_vdd_bl2_voltages[] = { 5000};
415
416 /* EN_3V3_MODEM from AP GPIO VI_VSYNCH D06*/
417 static struct regulator_consumer_supply gpio_switch_en_3v3_modem_supply[] = {
418         REGULATOR_SUPPLY("vdd_3v3_mini_card", NULL),
419         REGULATOR_SUPPLY("vdd_mini_card", NULL),
420 };
421 static int gpio_switch_en_3v3_modem_voltages[] = { 3300};
422
423 /* EN_USB1_VBUS_OC*/
424 static struct regulator_consumer_supply gpio_switch_en_usb1_vbus_oc_supply[] = {
425         REGULATOR_SUPPLY("vdd_vbus_micro_usb", NULL),
426 };
427 static int gpio_switch_en_usb1_vbus_oc_voltages[] = { 5000};
428
429 /*EN_USB3_VBUS_OC*/
430 static struct regulator_consumer_supply gpio_switch_en_usb3_vbus_oc_supply[] = {
431         REGULATOR_SUPPLY("vdd_vbus_typea_usb", NULL),
432 };
433 static int gpio_switch_en_usb3_vbus_oc_voltages[] = { 5000};
434
435 /* EN_VDDIO_VID_OC from AP GPIO VI_PCLK T00*/
436 static struct regulator_consumer_supply gpio_switch_en_vddio_vid_oc_supply[] = {
437         REGULATOR_SUPPLY("vdd_hdmi_con", NULL),
438 };
439 static int gpio_switch_en_vddio_vid_oc_voltages[] = { 5000};
440
441 /* EN_VDD_PNL1 from AP GPIO VI_D6 L04*/
442 static struct regulator_consumer_supply gpio_switch_en_vdd_pnl1_supply[] = {
443         REGULATOR_SUPPLY("vdd_lcd_panel", NULL),
444 };
445 static int gpio_switch_en_vdd_pnl1_voltages[] = { 3300};
446
447 /* CAM1_LDO_EN from AP GPIO KB_ROW6 R06*/
448 static struct regulator_consumer_supply gpio_switch_cam1_ldo_en_supply[] = {
449         REGULATOR_SUPPLY("vdd_2v8_cam1", NULL),
450 };
451 static int gpio_switch_cam1_ldo_en_voltages[] = { 2800};
452
453 /* CAM2_LDO_EN from AP GPIO KB_ROW7 R07*/
454 static struct regulator_consumer_supply gpio_switch_cam2_ldo_en_supply[] = {
455         REGULATOR_SUPPLY("vdd_2v8_cam2", NULL),
456 };
457 static int gpio_switch_cam2_ldo_en_voltages[] = { 2800};
458
459 /* CAM3_LDO_EN from AP GPIO KB_ROW8 S00*/
460 static struct regulator_consumer_supply gpio_switch_cam3_ldo_en_supply[] = {
461         REGULATOR_SUPPLY("vdd_cam3", NULL),
462 };
463 static int gpio_switch_cam3_ldo_en_voltages[] = { 3300};
464
465 /* EN_VDD_COM from AP GPIO SDMMC3_DAT5 D00*/
466 static struct regulator_consumer_supply gpio_switch_en_vdd_com_supply[] = {
467         REGULATOR_SUPPLY("vdd_com_bd", NULL),
468 };
469 static int gpio_switch_en_vdd_com_voltages[] = { 3300};
470
471 /* EN_VDD_SDMMC1 from AP GPIO VI_HSYNC D07*/
472 static struct regulator_consumer_supply gpio_switch_en_vdd_sdmmc1_supply[] = {
473         REGULATOR_SUPPLY("vddio_sd_slot", NULL),
474 };
475 static int gpio_switch_en_vdd_sdmmc1_voltages[] = { 3300};
476
477 /* EN_3V3_EMMC from AP GPIO SDMMC3_DAT4 D01*/
478 static struct regulator_consumer_supply gpio_switch_en_3v3_emmc_supply[] = {
479         REGULATOR_SUPPLY("vdd_emmc_core", NULL),
480 };
481 static int gpio_switch_en_3v3_emmc_voltages[] = { 3300};
482
483 /* EN_3V3_PEX_HVDD from AP GPIO VI_D09 L07*/
484 static struct regulator_consumer_supply gpio_switch_en_3v3_pex_hvdd_supply[] = {
485         REGULATOR_SUPPLY("hvdd_pex_3v3", NULL),
486 };
487 static int gpio_switch_en_3v3_pex_hvdd_voltages[] = { 3300};
488
489 /* EN_3v3_FUSE from AP GPIO VI_D08 L06*/
490 static struct regulator_consumer_supply gpio_switch_en_3v3_fuse_supply[] = {
491         REGULATOR_SUPPLY("vpp_fuse_pg", NULL),
492 };
493 static int gpio_switch_en_3v3_fuse_voltages[] = { 3300};
494
495 /* EN_1V8_CAM from AP GPIO GPIO_PBB4 PBB04*/
496 static struct regulator_consumer_supply gpio_switch_en_1v8_cam_supply[] = {
497         REGULATOR_SUPPLY("vdd_1v8_cam1", NULL),
498         REGULATOR_SUPPLY("vdd_1v8_cam2", NULL),
499         REGULATOR_SUPPLY("vdd_1v8_cam3", NULL),
500 };
501 static int gpio_switch_en_1v8_cam_voltages[] = { 1800};
502
503 static int enable_load_switch_rail(
504                 struct gpio_switch_regulator_subdev_data *psubdev_data)
505 {
506         int ret;
507
508         if (psubdev_data->pin_group <= 0)
509                 return -EINVAL;
510
511         /* Tristate and make pin as input*/
512         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
513                                                 TEGRA_TRI_TRISTATE);
514         if (ret < 0)
515                 return ret;
516         return gpio_direction_input(psubdev_data->gpio_nr);
517 }
518
519 static int disable_load_switch_rail(
520                 struct gpio_switch_regulator_subdev_data *psubdev_data)
521 {
522         int ret;
523
524         if (psubdev_data->pin_group <= 0)
525                 return -EINVAL;
526
527         /* Un-tristate and driver low */
528         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
529                                                 TEGRA_TRI_NORMAL);
530         if (ret < 0)
531                 return ret;
532         return gpio_direction_output(psubdev_data->gpio_nr, 0);
533 }
534
535
536 /* Macro for defining gpio switch regulator sub device data */
537 #define GREG_INIT(_id, _var, _name, _input_supply, _gpio_nr, _active_low, \
538                         _init_state, _pg, _enable, _disable)            \
539         static struct gpio_switch_regulator_subdev_data gpio_pdata_##_var =  \
540         {                                                               \
541                 .regulator_name = "gpio-switch-"#_name,                 \
542                 .input_supply   = _input_supply,                        \
543                 .id             = _id,                                  \
544                 .gpio_nr        = _gpio_nr,                             \
545                 .pin_group      = _pg,                                  \
546                 .active_low     = _active_low,                          \
547                 .init_state     = _init_state,                          \
548                 .voltages       = gpio_switch_##_name##_voltages,       \
549                 .n_voltages     = ARRAY_SIZE(gpio_switch_##_name##_voltages), \
550                 .num_consumer_supplies =                                \
551                                 ARRAY_SIZE(gpio_switch_##_name##_supply), \
552                 .consumer_supplies = gpio_switch_##_name##_supply,      \
553                 .constraints = {                                        \
554                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
555                                              REGULATOR_MODE_STANDBY),   \
556                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
557                                            REGULATOR_CHANGE_STATUS |    \
558                                            REGULATOR_CHANGE_VOLTAGE),   \
559                 },                                                      \
560                 .enable_rail = _enable,                                 \
561                 .disable_rail = _disable,                               \
562         }
563
564 /* common to all boards */
565 GREG_INIT(0, en_5v_cp,          en_5v_cp,       NULL,                   TPS6591X_GPIO_GP0,      false,  0,      0,      0,      0);
566 GREG_INIT(1, en_5v0,            en_5v0,         NULL,                   TPS6591X_GPIO_GP2,      false,  0,      0,      0,      0);
567 GREG_INIT(2, en_ddr,            en_ddr,         NULL,                   TPS6591X_GPIO_GP6,      false,  0,      0,      0,      0);
568 GREG_INIT(3, en_3v3_sys,        en_3v3_sys,     NULL,                   TPS6591X_GPIO_GP7,      false,  0,      0,      0,      0);
569 GREG_INIT(4, en_vdd_bl,         en_vdd_bl,      NULL,                   TEGRA_GPIO_PK3,         false,  1,      0,      0,      0);
570 GREG_INIT(5, en_3v3_modem,      en_3v3_modem,   NULL,                   TEGRA_GPIO_PD6,         false,  1,      0,      0,      0);
571 GREG_INIT(6, en_vdd_pnl1,       en_vdd_pnl1,    "vdd_3v3_devices",      TEGRA_GPIO_PL4,         false,  1,      0,      0,      0);
572 GREG_INIT(7, cam3_ldo_en,       cam3_ldo_en,    "vdd_3v3_devices",      TEGRA_GPIO_PS0,         false,  0,      0,      0,      0);
573 GREG_INIT(8, en_vdd_com,        en_vdd_com,     "vdd_3v3_devices",      TEGRA_GPIO_PD0,         false,  1,      0,      0,      0);
574 GREG_INIT(9, en_3v3_fuse,       en_3v3_fuse,    "vdd_3v3_devices",      TEGRA_GPIO_PL6,         false,  0,      0,      0,      0);
575 GREG_INIT(10, en_3v3_emmc,      en_3v3_emmc,    "vdd_3v3_devices",      TEGRA_GPIO_PD1,         false,  1,      0,      0,      0);
576 GREG_INIT(11, en_vdd_sdmmc1,    en_vdd_sdmmc1,  "vdd_3v3_devices",      TEGRA_GPIO_PD7,         false,  1,      0,      0,      0);
577 GREG_INIT(12, en_3v3_pex_hvdd,  en_3v3_pex_hvdd, "vdd_3v3_devices",     TEGRA_GPIO_PL7,         false,  0,      0,      0,      0);
578 GREG_INIT(13, en_1v8_cam,       en_1v8_cam,     "vdd_gen1v8",           TEGRA_GPIO_PBB4,        false,  0,      0,      0,      0);
579
580 /* Specific to E1187/E1186 */
581 GREG_INIT(14, dis_5v_switch_e118x,      dis_5v_switch,          "vdd_5v0_sys",
582                 TEGRA_GPIO_PX2,         true,   0,      0,      0,      0);
583 GREG_INIT(15, en_usb1_vbus_oc_e118x,    en_usb1_vbus_oc,        "master_5v_switch",
584                 TEGRA_GPIO_PI4,         false,  0,      TEGRA_PINGROUP_GMI_RST_N,
585                 enable_load_switch_rail, disable_load_switch_rail);
586 GREG_INIT(16, en_usb3_vbus_oc_e118x,    en_usb3_vbus_oc,        "master_5v_switch",
587                 TEGRA_GPIO_PH7,         false,  0,      TEGRA_PINGROUP_GMI_AD15,
588                 enable_load_switch_rail, disable_load_switch_rail);
589 GREG_INIT(17, en_vddio_vid_oc_e118x,    en_vddio_vid_oc,        "master_5v_switch",
590                 TEGRA_GPIO_PT0,         false,  0,      TEGRA_PINGROUP_VI_PCLK,
591                 enable_load_switch_rail, disable_load_switch_rail);
592
593 /* E1198/E1291 specific  fab < A03 */
594 GREG_INIT(15, en_usb1_vbus_oc,          en_usb1_vbus_oc,        "vdd_5v0_sys",
595                 TEGRA_GPIO_PI4,         false,  0,      TEGRA_PINGROUP_GMI_RST_N,
596                 enable_load_switch_rail, disable_load_switch_rail);
597 GREG_INIT(16, en_usb3_vbus_oc,          en_usb3_vbus_oc,        "vdd_5v0_sys",
598                 TEGRA_GPIO_PH7,         false,  0,      TEGRA_PINGROUP_GMI_AD15,
599                 enable_load_switch_rail, disable_load_switch_rail);
600
601 /* E1198/E1291 specific  fab >= A03 */
602 GREG_INIT(15, en_usb1_vbus_oc_a03,              en_usb1_vbus_oc,        "vdd_5v0_sys",
603                 TEGRA_GPIO_PDD6,                false,  0,      TEGRA_PINGROUP_PEX_L1_CLKREQ_N,
604                 enable_load_switch_rail, disable_load_switch_rail);
605 GREG_INIT(16, en_usb3_vbus_oc_a03,              en_usb3_vbus_oc,        "vdd_5v0_sys",
606                 TEGRA_GPIO_PDD4,                false,  0,      TEGRA_PINGROUP_PEX_L1_PRSNT_N,
607                 enable_load_switch_rail, disable_load_switch_rail);
608
609 /* E1198/E1291 specific */
610 GREG_INIT(17, en_vddio_vid_oc,          en_vddio_vid_oc,        "vdd_5v0_sys",
611                 TEGRA_GPIO_PT0,         false,  0,      TEGRA_PINGROUP_VI_PCLK,
612                 enable_load_switch_rail, disable_load_switch_rail);
613
614 /* E1198/E1291 specific*/
615 GREG_INIT(18, cam1_ldo_en,      cam1_ldo_en,            "vdd_3v3_cam",  TEGRA_GPIO_PR6,         false,  0,      0,      0,      0);
616 GREG_INIT(19, cam2_ldo_en,      cam2_ldo_en,            "vdd_3v3_cam",  TEGRA_GPIO_PR7,         false,  0,      0,      0,      0);
617
618 /* E1291 A03 specific */
619 GREG_INIT(20, en_vdd_bl1_a03,   en_vdd_bl,      NULL,           TEGRA_GPIO_PDD2,        false,  1,      0,      0,      0);
620 GREG_INIT(21, en_vdd_bl2_a03,   en_vdd_bl2,     NULL,           TEGRA_GPIO_PDD0,        false,  1,      0,      0,      0);
621
622 #define ADD_GPIO_REG(_name) &gpio_pdata_##_name
623 #define COMMON_GPIO_REG \
624         ADD_GPIO_REG(en_5v_cp),                 \
625         ADD_GPIO_REG(en_5v0),                   \
626         ADD_GPIO_REG(en_ddr),                   \
627         ADD_GPIO_REG(en_3v3_sys),               \
628         ADD_GPIO_REG(en_3v3_modem),             \
629         ADD_GPIO_REG(en_vdd_pnl1),              \
630         ADD_GPIO_REG(cam3_ldo_en),              \
631         ADD_GPIO_REG(en_vdd_com),               \
632         ADD_GPIO_REG(en_3v3_fuse),              \
633         ADD_GPIO_REG(en_3v3_emmc),              \
634         ADD_GPIO_REG(en_vdd_sdmmc1),            \
635         ADD_GPIO_REG(en_3v3_pex_hvdd),          \
636         ADD_GPIO_REG(en_1v8_cam),
637
638 #define E118x_GPIO_REG  \
639         ADD_GPIO_REG(en_vdd_bl),                \
640         ADD_GPIO_REG(dis_5v_switch_e118x),      \
641         ADD_GPIO_REG(en_usb1_vbus_oc_e118x),    \
642         ADD_GPIO_REG(en_usb3_vbus_oc_e118x),    \
643         ADD_GPIO_REG(en_vddio_vid_oc_e118x),
644
645 #define E1198_GPIO_REG  \
646         ADD_GPIO_REG(en_vddio_vid_oc),          \
647         ADD_GPIO_REG(cam1_ldo_en),              \
648         ADD_GPIO_REG(cam2_ldo_en),
649
650 #define E1291_1198_A00_GPIO_REG \
651         ADD_GPIO_REG(en_usb1_vbus_oc),          \
652         ADD_GPIO_REG(en_usb3_vbus_oc),          \
653         ADD_GPIO_REG(en_vdd_bl),
654
655 #define E1291_A03_GPIO_REG      \
656         ADD_GPIO_REG(en_usb1_vbus_oc_a03),              \
657         ADD_GPIO_REG(en_usb3_vbus_oc_a03),              \
658         ADD_GPIO_REG(en_vdd_bl1_a03), \
659         ADD_GPIO_REG(en_vdd_bl2_a03),
660
661 /* Gpio switch regulator platform data  for E1186/E1187*/
662
663 /* Gpio switch regulator platform data  for E1186/E1187*/
664 static struct gpio_switch_regulator_subdev_data *gswitch_subdevs_e118x[] = {
665         COMMON_GPIO_REG
666         E118x_GPIO_REG
667 };
668
669 /* Gpio switch regulator platform data for E1198 and E1291*/
670 static struct gpio_switch_regulator_subdev_data *gswitch_subdevs_e1198[] = {
671         COMMON_GPIO_REG
672         E1291_1198_A00_GPIO_REG
673         E1198_GPIO_REG
674 };
675
676 /* Gpio switch regulator platform data for E1291 A03*/
677 static struct gpio_switch_regulator_subdev_data *gswitch_subdevs_e1291_a03[] = {
678         COMMON_GPIO_REG
679         E1291_A03_GPIO_REG
680         E1198_GPIO_REG
681 };
682
683 static struct gpio_switch_regulator_platform_data  gswitch_pdata;
684 static struct platform_device gswitch_regulator_pdata = {
685         .name = "gpio-switch-regulator",
686         .id   = -1,
687         .dev  = {
688              .platform_data = &gswitch_pdata,
689         },
690 };
691
692 int __init cardhu_gpio_switch_regulator_init(void)
693 {
694         int i;
695         struct board_info board_info;
696         tegra_get_board_info(&board_info);
697         switch (board_info.board_id) {
698         case BOARD_E1198:
699                 gswitch_pdata.num_subdevs = ARRAY_SIZE(gswitch_subdevs_e1198);
700                 gswitch_pdata.subdevs = gswitch_subdevs_e1198;
701                 break;
702         case BOARD_E1291:
703                 if (board_info.fab >= 0x3) {
704                         gswitch_pdata.num_subdevs =
705                                         ARRAY_SIZE(gswitch_subdevs_e1291_a03);
706                         gswitch_pdata.subdevs = gswitch_subdevs_e1291_a03;
707                         break;
708                 }
709                 gswitch_pdata.num_subdevs = ARRAY_SIZE(gswitch_subdevs_e1198);
710                 gswitch_pdata.subdevs = gswitch_subdevs_e1198;
711                 break;
712         default:
713                 gswitch_pdata.num_subdevs = ARRAY_SIZE(gswitch_subdevs_e118x);
714                 gswitch_pdata.subdevs = gswitch_subdevs_e118x;
715                 break;
716         }
717
718         for (i = 0; i < gswitch_pdata.num_subdevs; ++i) {
719                 struct gpio_switch_regulator_subdev_data *gswitch_data = gswitch_pdata.subdevs[i];
720                 if (gswitch_data->gpio_nr <= TEGRA_NR_GPIOS)
721                         tegra_gpio_enable(gswitch_data->gpio_nr);
722         }
723
724         return platform_device_register(&gswitch_regulator_pdata);
725 }
726
727 static struct tegra_suspend_platform_data cardhu_suspend_data = {
728         .cpu_timer      = 2000,
729         .cpu_off_timer  = 0,
730         .suspend_mode   = TEGRA_SUSPEND_LP1,
731         .core_timer     = 0x7e7e,
732         .core_off_timer = 0,
733         .separate_req   = true,
734         .corereq_high   = false,
735         .sysclkreq_high = true,
736         .wake_enb       = TEGRA_WAKE_GPIO_PV0 | TEGRA_WAKE_PWR_INT,
737         .wake_high      = 0,
738         .wake_low       = TEGRA_WAKE_GPIO_PV0 | TEGRA_WAKE_PWR_INT,
739         .wake_any       = 0,
740 };
741
742 int __init cardhu_suspend_init(void)
743 {
744         struct board_info board_info;
745
746         tegra_get_board_info(&board_info);
747         switch (board_info.board_id) {
748         case BOARD_E1291:
749         case BOARD_E1198:
750                 break;
751         case BOARD_PM269:
752         case BOARD_E1187:
753         case BOARD_E1186:
754                 cardhu_suspend_data.cpu_timer = 5000;
755                 cardhu_suspend_data.cpu_off_timer = 5000;
756                 break;
757         default:
758                 break;
759         }
760
761         tegra_init_suspend(&cardhu_suspend_data);
762         return 0;
763 }
764
765 static void cardhu_power_off(void)
766 {
767         int ret;
768         pr_err("cardhu: Powering off the device\n");
769         ret = tps6591x_power_off();
770         if (ret)
771                 pr_err("cardhu: failed to power off\n");
772
773         while(1);
774 }
775
776 int __init cardhu_power_off_init(void)
777 {
778         pm_power_off = cardhu_power_off;
779         return 0;
780 }
781