arm: tegra: cardhu: Defining base irq number for tps6591x
[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/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-cardhu.h"
38 #include "power.h"
39 #include "wakeups-t3.h"
40
41 #ifdef CONFIG_MFD_TPS6591X
42 static struct regulator_consumer_supply tps6591x_vdd1_supply[] = {
43         REGULATOR_SUPPLY("vdd_core", NULL),
44         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
45 };
46
47 static struct regulator_consumer_supply tps6591x_vdd2_supply[] = {
48         REGULATOR_SUPPLY("vdd_gen1v5", NULL),
49         REGULATOR_SUPPLY("vcore_lcd", NULL),
50         REGULATOR_SUPPLY("track_ldo1", NULL),
51         REGULATOR_SUPPLY("external_ldo_1v2", NULL),
52         REGULATOR_SUPPLY("vcore_cam1", NULL),
53         REGULATOR_SUPPLY("vcore_cam2", NULL),
54 };
55
56 static struct regulator_consumer_supply tps6591x_vddctrl_supply[] = {
57         REGULATOR_SUPPLY("vdd_cpu_pmu", NULL),
58         REGULATOR_SUPPLY("vdd_cpu", NULL),
59         REGULATOR_SUPPLY("vdd_sys", NULL),
60 };
61
62 static struct regulator_consumer_supply tps6591x_vio_supply[] = {
63         REGULATOR_SUPPLY("vdd_gen1v8", NULL),
64         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
65         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
66         REGULATOR_SUPPLY("avdd_osc", NULL),
67         REGULATOR_SUPPLY("vddio_sys", NULL),
68         REGULATOR_SUPPLY("vddio_sdmmc4", NULL),
69         REGULATOR_SUPPLY("vdd1v8_satelite", NULL),
70         REGULATOR_SUPPLY("vddio_uart", NULL),
71         REGULATOR_SUPPLY("vddio_audio", NULL),
72         REGULATOR_SUPPLY("vddio_bb", NULL),
73         REGULATOR_SUPPLY("vddio_lcd_pmu", NULL),
74         REGULATOR_SUPPLY("vddio_cam", NULL),
75         REGULATOR_SUPPLY("vddio_vi", NULL),
76         REGULATOR_SUPPLY("ldo6", NULL),
77         REGULATOR_SUPPLY("ldo7", NULL),
78         REGULATOR_SUPPLY("ldo8", NULL),
79         REGULATOR_SUPPLY("vcore_audio", NULL),
80         REGULATOR_SUPPLY("avcore_audio", NULL),
81         REGULATOR_SUPPLY("vddio_sdmmc3", NULL),
82         REGULATOR_SUPPLY("vcore1_lpddr2", NULL),
83         REGULATOR_SUPPLY("vcom_1v8", NULL),
84         REGULATOR_SUPPLY("pmuio_1v8", NULL),
85         REGULATOR_SUPPLY("avdd_ic_usb", NULL),
86 };
87
88 static struct regulator_consumer_supply tps6591x_ldo1_supply[] = {
89         REGULATOR_SUPPLY("avdd_pexb", NULL),
90         REGULATOR_SUPPLY("vdd_pexb", NULL),
91         REGULATOR_SUPPLY("avdd_pex_pll", NULL),
92         REGULATOR_SUPPLY("avdd_pexa", NULL),
93         REGULATOR_SUPPLY("vdd_pexa", NULL),
94 };
95
96 static struct regulator_consumer_supply tps6591x_ldo2_supply[] = {
97         REGULATOR_SUPPLY("avdd_sata", NULL),
98         REGULATOR_SUPPLY("vdd_sata", NULL),
99         REGULATOR_SUPPLY("avdd_sata_pll", NULL),
100         REGULATOR_SUPPLY("avdd_plle", NULL),
101 };
102
103 #if defined(CONFIG_TEGRA_VERBIER_E1187)
104 static struct regulator_consumer_supply tps6591x_ldo3_supply[] = {
105         REGULATOR_SUPPLY("vddio_sdmmc1", NULL),
106 };
107 #else
108 static struct regulator_consumer_supply tps6591x_ldo3_supply[] = {
109         REGULATOR_SUPPLY("unused_rail_ldo3", NULL),
110 };
111 #endif
112
113 static struct regulator_consumer_supply tps6591x_ldo4_supply[] = {
114         REGULATOR_SUPPLY("vdd_rtc", NULL),
115 };
116
117 static struct regulator_consumer_supply tps6591x_ldo5_supply[] = {
118         REGULATOR_SUPPLY("avdd_vdac", NULL),
119 #if !defined(CONFIG_TEGRA_VERBIER_E1187)
120         REGULATOR_SUPPLY("vddio_sdmmc1", NULL),
121 #endif
122 };
123 static struct regulator_consumer_supply tps6591x_ldo6_supply[] = {
124         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
125 };
126 static struct regulator_consumer_supply tps6591x_ldo7_supply[] = {
127         REGULATOR_SUPPLY("avdd_plla_p_c_s", NULL),
128         REGULATOR_SUPPLY("avdd_pllm", NULL),
129         REGULATOR_SUPPLY("avdd_pllu_d", NULL),
130         REGULATOR_SUPPLY("avdd_pllu_d2", NULL),
131         REGULATOR_SUPPLY("avdd_pllx", NULL),
132 };
133
134 static struct regulator_consumer_supply tps6591x_ldo8_supply[] = {
135         REGULATOR_SUPPLY("vdd_ddr_hs", NULL),
136 };
137
138 #define TPS_PDATA_INIT_SUPPLY(_id, _minmv, _maxmv, _supply_reg, _always_on, \
139         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply, _ectrl) \
140         static struct tps6591x_regulator_platform_data pdata_##_id =    \
141         {                                                               \
142                 .regulator = {                                          \
143                         .constraints = {                                \
144                                 .min_uV = (_minmv)*1000,                \
145                                 .max_uV = (_maxmv)*1000,                \
146                                 .valid_modes_mask = (REGULATOR_MODE_NORMAL |  \
147                                                      REGULATOR_MODE_STANDBY), \
148                                 .valid_ops_mask = (REGULATOR_CHANGE_MODE |    \
149                                                    REGULATOR_CHANGE_STATUS |  \
150                                                    REGULATOR_CHANGE_VOLTAGE), \
151                                 .always_on = _always_on,                \
152                                 .boot_on = _boot_on,                    \
153                                 .apply_uV = _apply_uv,                  \
154                         },                                              \
155                         .num_consumer_supplies =                        \
156                                 ARRAY_SIZE(tps6591x_##_id##_supply),    \
157                         .consumer_supplies = tps6591x_##_id##_supply,   \
158                         .supply_regulator = tps6591x_rails(_supply_reg), \
159                 },                                                      \
160                 .init_uV =  _init_uV * 1000,                            \
161                 .init_enable = _init_enable,                            \
162                 .init_apply = _init_apply,                              \
163                 .ectrl = _ectrl                                         \
164         }
165
166 #define TPS_PDATA_INIT(_id, _minmv, _maxmv, _supply_reg, _always_on,    \
167         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply, _ectrl) \
168         static struct tps6591x_regulator_platform_data pdata_##_id =    \
169         {                                                               \
170                 .regulator = {                                          \
171                         .constraints = {                                \
172                                 .min_uV = (_minmv)*1000,                \
173                                 .max_uV = (_maxmv)*1000,                \
174                                 .valid_modes_mask = (REGULATOR_MODE_NORMAL |  \
175                                                      REGULATOR_MODE_STANDBY), \
176                                 .valid_ops_mask = (REGULATOR_CHANGE_MODE |    \
177                                                    REGULATOR_CHANGE_STATUS |  \
178                                                    REGULATOR_CHANGE_VOLTAGE), \
179                                 .always_on = _always_on,                \
180                                 .boot_on = _boot_on,                    \
181                                 .apply_uV = _apply_uv,                  \
182                         },                                              \
183                         .num_consumer_supplies =                        \
184                                 ARRAY_SIZE(tps6591x_##_id##_supply),    \
185                         .consumer_supplies = tps6591x_##_id##_supply,   \
186                 },                                                      \
187                 .init_uV =  _init_uV * 1000,                            \
188                 .init_enable = _init_enable,                            \
189                 .init_apply = _init_apply,                              \
190                 .ectrl = _ectrl                                         \
191         }
192
193 TPS_PDATA_INIT(vdd1,    600, 1500, 0, 1, 1, 0, -1, 0, 0, 0);
194 TPS_PDATA_INIT(vdd2,    600, 1500, 0, 1, 1, 0, -1, 0, 0, 0);
195 TPS_PDATA_INIT(vddctrl, 600, 1400, 0, 1, 1, 0, -1, 0, 0, EXT_CTRL_EN1);
196 TPS_PDATA_INIT(vio,    1500, 3300, 0, 1, 1, 0, -1, 0, 0, 0);
197
198 TPS_PDATA_INIT_SUPPLY(ldo1, 1000, 3300, VDD_2, 0, 0, 0, -1, 0, 0, 0);
199 TPS_PDATA_INIT_SUPPLY(ldo2, 1000, 3300, VDD_2, 0, 0, 0, -1, 0, 0, 0);
200
201 TPS_PDATA_INIT(ldo3, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0);
202 TPS_PDATA_INIT(ldo4, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0);
203 TPS_PDATA_INIT(ldo5, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0);
204
205 TPS_PDATA_INIT_SUPPLY(ldo6, 1000, 3300, VIO, 0, 0, 0, -1, 0, 0, 0);
206 TPS_PDATA_INIT_SUPPLY(ldo7, 1000, 3300, VIO, 0, 0, 0, -1, 0, 0, 0);
207 TPS_PDATA_INIT_SUPPLY(ldo8, 1000, 3300, VIO, 0, 0, 0, -1, 0, 0, 0);
208 /* Currently tps6591x-rtc driver is not available need to enable once driver is ready */
209 /*
210 static struct tps6591x_rtc_platform_data rtc_data = {
211         .irq = TEGRA_NR_IRQS + TPS6591X_INT_RTC_ALARM,
212 };
213 */
214 #define TPS_REG(_id, _data)                             \
215         {                                               \
216                 .id     = TPS6591X_ID_##_id,            \
217                 .name   = "tps6591x-regulator",         \
218                 .platform_data  = &pdata_##_data,       \
219         }
220
221 static struct tps6591x_subdev_info tps_devs[] = {
222         TPS_REG(VIO, vio),
223         TPS_REG(VDD_1, vdd1),
224         TPS_REG(VDD_2, vdd2),
225         TPS_REG(VDDCTRL, vddctrl),
226         TPS_REG(LDO_1, ldo1),
227         TPS_REG(LDO_2, ldo2),
228         TPS_REG(LDO_3, ldo3),
229         TPS_REG(LDO_4, ldo4),
230         TPS_REG(LDO_5, ldo5),
231         TPS_REG(LDO_6, ldo6),
232         TPS_REG(LDO_7, ldo7),
233         TPS_REG(LDO_8, ldo8),
234         /* Currently tps6591x-rtc driver is not available need to enable once driver is ready */
235         /*{
236                 .id     = 0,
237                 .name   = "tps6591x-rtc",
238                 .platform_data = &rtc_data,
239         },*/
240 };
241
242 static struct tps6591x_platform_data tps_platform = {
243         .irq_base       = TPS6591X_IRQ_BASE,
244         .num_subdevs    = ARRAY_SIZE(tps_devs),
245         .subdevs        = tps_devs,
246         .gpio_base      = TPS6591X_GPIO_BASE,
247 };
248
249 static struct i2c_board_info __initdata cardhu_regulators[] = {
250         {
251                 I2C_BOARD_INFO("tps6591x", 0x2D),
252                 .irq            = INT_EXTERNAL_PMU,
253                 .platform_data  = &tps_platform,
254         },
255 };
256
257 int __init cardhu_regulator_init(void)
258 {
259         i2c_register_board_info(4, cardhu_regulators, 1);
260         return 0;
261 }
262 #else
263 int __init cardhu_regulator_init(void)
264 {
265         return 0;
266 }
267 #endif
268
269 #ifdef CONFIG_REGULATOR_GPIO_SWITCH
270
271 /* EN_5V_CP from PMU GP0 */
272 static struct regulator_consumer_supply gpio_switch_en_5v_cp_supply[] = {
273         REGULATOR_SUPPLY("vdd_5v0_sby", NULL),
274         REGULATOR_SUPPLY("vdd_hall", NULL),
275         REGULATOR_SUPPLY("vterm_ddr", NULL),
276         REGULATOR_SUPPLY("v2ref_ddr", NULL),
277 };
278 static int gpio_switch_en_5v_cp_voltages[] = { 5000};
279
280 /* EN_5V0 From PMU GP2 */
281 static struct regulator_consumer_supply gpio_switch_en_5v0_supply[] = {
282         REGULATOR_SUPPLY("vdd_5v0_sys", NULL),
283 };
284 static int gpio_switch_en_5v0_voltages[] = { 5000};
285
286 /* EN_DDR From PMU GP6 */
287 static struct regulator_consumer_supply gpio_switch_en_ddr_supply[] = {
288         REGULATOR_SUPPLY("mem_vddio_ddr", NULL),
289         REGULATOR_SUPPLY("t30_vddio_ddr", NULL),
290 };
291 static int gpio_switch_en_ddr_voltages[] = { 1500};
292
293 /* EN_3V3_SYS From PMU GP7 */
294 static struct regulator_consumer_supply gpio_switch_en_3v3_sys_supply[] = {
295         REGULATOR_SUPPLY("vdd_lvds", NULL),
296         REGULATOR_SUPPLY("vdd_pnl", NULL),
297         REGULATOR_SUPPLY("vcom_3v3", NULL),
298         REGULATOR_SUPPLY("vdd_3v3", NULL),
299         REGULATOR_SUPPLY("vcore_mmc", NULL),
300         REGULATOR_SUPPLY("vddio_pex_ctl", NULL),
301         REGULATOR_SUPPLY("hvdd_pex", NULL),
302         REGULATOR_SUPPLY("avdd_hdmi", NULL),
303         REGULATOR_SUPPLY("vpp_fuse", NULL),
304         REGULATOR_SUPPLY("avdd_usb", NULL),
305         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
306         REGULATOR_SUPPLY("vcore_nand", NULL),
307         REGULATOR_SUPPLY("hvdd_sata", NULL),
308         REGULATOR_SUPPLY("vddio_gmi_pmu", NULL),
309         REGULATOR_SUPPLY("avdd_cam1", NULL),
310         REGULATOR_SUPPLY("vdd_af", NULL),
311         REGULATOR_SUPPLY("avdd_cam2", NULL),
312         REGULATOR_SUPPLY("vdd_acc", NULL),
313         REGULATOR_SUPPLY("vdd_phtl", NULL),
314         REGULATOR_SUPPLY("vddio_tp", NULL),
315         REGULATOR_SUPPLY("vdd_led", NULL),
316         REGULATOR_SUPPLY("vddio_cec", NULL),
317         REGULATOR_SUPPLY("vdd_cmps", NULL),
318         REGULATOR_SUPPLY("vdd_temp", NULL),
319         REGULATOR_SUPPLY("vpp_kfuse", NULL),
320         REGULATOR_SUPPLY("vddio_ts", NULL),
321         REGULATOR_SUPPLY("vdd_ir_led", NULL),
322         REGULATOR_SUPPLY("vddio_1wire", NULL),
323         REGULATOR_SUPPLY("avddio_audio", NULL),
324         REGULATOR_SUPPLY("vdd_ec", NULL),
325         REGULATOR_SUPPLY("vcom_pa", NULL),
326         REGULATOR_SUPPLY("vdd_3v3_devices", NULL),
327         REGULATOR_SUPPLY("vdd_3v3_dock", NULL),
328         REGULATOR_SUPPLY("vdd_3v3_edid", NULL),
329         REGULATOR_SUPPLY("vdd_3v3_hdmi_cec", NULL),
330         REGULATOR_SUPPLY("vdd_3v3_gmi", NULL),
331         REGULATOR_SUPPLY("vdd_3v3_spk_amp", NULL),
332         REGULATOR_SUPPLY("vdd_3v3_sensor", NULL),
333         REGULATOR_SUPPLY("vdd_3v3_cam", NULL),
334         REGULATOR_SUPPLY("vdd_3v3_als", NULL),
335         REGULATOR_SUPPLY("debug_cons", NULL),
336 };
337 static int gpio_switch_en_3v3_sys_voltages[] = { 3300};
338
339 /* DIS_5V_SWITCH from AP SPI2_SCK X02 */
340 static struct regulator_consumer_supply gpio_switch_dis_5v_switch_supply[] = {
341         REGULATOR_SUPPLY("master_5v_switch", NULL),
342 };
343 static int gpio_switch_dis_5v_switch_voltages[] = { 5000};
344
345 /* EN_VDD_BL from AP GPIO GMI_CS2  K03 */
346 static struct regulator_consumer_supply gpio_switch_en_vdd_bl_supply[] = {
347         REGULATOR_SUPPLY("vdd_backlight", NULL),
348 };
349 static int gpio_switch_en_vdd_bl_voltages[] = { 5000};
350
351 /* EN_3V3_MODEM from AP GPIO VI_VSYNCH D06*/
352 static struct regulator_consumer_supply gpio_switch_en_3v3_modem_supply[] = {
353         REGULATOR_SUPPLY("vdd_3v3_mini_card", NULL),
354         REGULATOR_SUPPLY("vdd_mini_card", NULL),
355 };
356 static int gpio_switch_en_3v3_modem_voltages[] = { 3300};
357
358 /* EN_USB1_VBUS_OC from AP GPIO GMI_RST I04*/
359 static struct regulator_consumer_supply gpio_switch_en_usb1_vbus_oc_supply[] = {
360         REGULATOR_SUPPLY("vdd_vbus_micro_usb", NULL),
361 };
362 static int gpio_switch_en_usb1_vbus_oc_voltages[] = { 5000};
363
364 /*EN_USB3_VBUS_OC from AP GPIO GMI_AD15 H07*/
365 static struct regulator_consumer_supply gpio_switch_en_usb3_vbus_oc_supply[] = {
366         REGULATOR_SUPPLY("vdd_vbus_typea_usb", NULL),
367 };
368 static int gpio_switch_en_usb3_vbus_oc_voltages[] = { 5000};
369
370 /* EN_VDDIO_VID_OC from AP GPIO VI_PCLK T00*/
371 static struct regulator_consumer_supply gpio_switch_en_vddio_vid_oc_supply[] = {
372         REGULATOR_SUPPLY("vdd_hdmi_con", NULL),
373 };
374 static int gpio_switch_en_vddio_vid_oc_voltages[] = { 5000};
375
376 /* EN_VDD_PNL1 from AP GPIO VI_D6 L04*/
377 static struct regulator_consumer_supply gpio_switch_en_vdd_pnl1_supply[] = {
378         REGULATOR_SUPPLY("vdd_lcd_panel", NULL),
379 };
380 static int gpio_switch_en_vdd_pnl1_voltages[] = { 3300};
381
382 /* CAM1_LDO_EN from AP GPIO KB_ROW6 R06*/
383 static struct regulator_consumer_supply gpio_switch_cam1_ldo_en_supply[] = {
384         REGULATOR_SUPPLY("vdd_2v8_cam1", NULL),
385 };
386 static int gpio_switch_cam1_ldo_en_voltages[] = { 2800};
387
388 /* CAM2_LDO_EN from AP GPIO KB_ROW7 R07*/
389 static struct regulator_consumer_supply gpio_switch_cam2_ldo_en_supply[] = {
390         REGULATOR_SUPPLY("vdd_2v8_cam2", NULL),
391 };
392 static int gpio_switch_cam2_ldo_en_voltages[] = { 2800};
393
394 /* CAM3_LDO_EN from AP GPIO KB_ROW8 S00*/
395 static struct regulator_consumer_supply gpio_switch_cam3_ldo_en_supply[] = {
396         REGULATOR_SUPPLY("vdd_cam3", NULL),
397 };
398 static int gpio_switch_cam3_ldo_en_voltages[] = { 3300};
399
400 /* EN_VDD_COM from AP GPIO SDMMC3_DAT5 D00*/
401 static struct regulator_consumer_supply gpio_switch_en_vdd_com_supply[] = {
402         REGULATOR_SUPPLY("vdd_com_bd", NULL),
403 };
404 static int gpio_switch_en_vdd_com_voltages[] = { 3300};
405
406 /* EN_VDD_SDMMC1 from AP GPIO VI_HSYNC D07*/
407 static struct regulator_consumer_supply gpio_switch_en_vdd_sdmmc1_supply[] = {
408         REGULATOR_SUPPLY("vddio_sd_slot", NULL),
409 };
410 static int gpio_switch_en_vdd_sdmmc1_voltages[] = { 3300};
411
412 /* EN_3V3_EMMC from AP GPIO SDMMC3_DAT4 D01*/
413 static struct regulator_consumer_supply gpio_switch_en_3v3_emmc_supply[] = {
414         REGULATOR_SUPPLY("vdd_emmc_core", NULL),
415 };
416 static int gpio_switch_en_3v3_emmc_voltages[] = { 3300};
417
418 /* EN_3V3_PEX_HVDD from AP GPIO VI_D09 L07*/
419 static struct regulator_consumer_supply gpio_switch_en_3v3_pex_hvdd_supply[] = {
420         REGULATOR_SUPPLY("hvdd_pex_3v3", NULL),
421 };
422 static int gpio_switch_en_3v3_pex_hvdd_voltages[] = { 3300};
423
424 /* EN_3v3_FUSE from AP GPIO VI_D08 L06*/
425 static struct regulator_consumer_supply gpio_switch_en_3v3_fuse_supply[] = {
426         REGULATOR_SUPPLY("vpp_fuse_pg", NULL),
427 };
428 static int gpio_switch_en_3v3_fuse_voltages[] = { 3300};
429
430 /* EN_1V8_CAM from AP GPIO GPIO_PBB4 PBB04*/
431 static struct regulator_consumer_supply gpio_switch_en_1v8_cam_supply[] = {
432         REGULATOR_SUPPLY("vdd_1v8_cam1", NULL),
433         REGULATOR_SUPPLY("vdd_1v8_cam2", NULL),
434         REGULATOR_SUPPLY("vdd_1v8_cam3", NULL),
435 };
436 static int gpio_switch_en_1v8_cam_voltages[] = { 1800};
437
438 static int enable_load_switch_rail(
439                 struct gpio_switch_regulator_subdev_data *psubdev_data)
440 {
441         int ret;
442
443         if (psubdev_data->pin_group <= 0)
444                 return -EINVAL;
445
446         /* Tristate and make pin as input*/
447         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
448                                                 TEGRA_TRI_TRISTATE);
449         if (ret < 0)
450                 return ret;
451         return gpio_direction_input(psubdev_data->gpio_nr);
452 }
453
454 static int disable_load_switch_rail(
455                 struct gpio_switch_regulator_subdev_data *psubdev_data)
456 {
457         int ret;
458
459         if (psubdev_data->pin_group <= 0)
460                 return -EINVAL;
461
462         /* Un-tristate and driver low */
463         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
464                                                 TEGRA_TRI_NORMAL);
465         if (ret < 0)
466                 return ret;
467         return gpio_direction_output(psubdev_data->gpio_nr, 0);
468 }
469
470 /* Macro for defining gpio switch regulator sub device data */
471 #define GREG_INIT(_id, _name, _input_supply, _gpio_nr, _active_low,     \
472                         _init_state, _pg, _enable, _disable)            \
473         [_id] = {                                                       \
474                 .regulator_name = "gpio-switch-"#_name,                 \
475                 .input_supply   = _input_supply,                        \
476                 .id             = _id,                                  \
477                 .gpio_nr        = _gpio_nr,                             \
478                 .pin_group      = _pg,                                  \
479                 .active_low     = _active_low,                          \
480                 .init_state     = _init_state,                          \
481                 .voltages       = gpio_switch_##_name##_voltages,       \
482                 .n_voltages     = ARRAY_SIZE(gpio_switch_##_name##_voltages), \
483                 .num_consumer_supplies =                                \
484                                 ARRAY_SIZE(gpio_switch_##_name##_supply), \
485                 .consumer_supplies = gpio_switch_##_name##_supply,      \
486                 .constraints = {                                        \
487                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
488                                              REGULATOR_MODE_STANDBY),   \
489                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
490                                            REGULATOR_CHANGE_STATUS |    \
491                                            REGULATOR_CHANGE_VOLTAGE),   \
492                 },                                                      \
493                 .enable_rail = _enable,                                 \
494                 .disable_rail = _disable,                               \
495         },
496
497 static struct gpio_switch_regulator_subdev_data gswitch_subdevs[] = {
498 /* Gpio switch regulator platform data */
499 GREG_INIT(0, en_5v_cp,   NULL, TPS6591X_GPIO_GP0, false, 0, 0, 0, 0)
500 GREG_INIT(1, en_5v0,     NULL, TPS6591X_GPIO_GP2, false, 0, 0, 0, 0)
501 GREG_INIT(2, en_ddr,     NULL, TPS6591X_GPIO_GP6, false, 0, 0, 0, 0)
502 GREG_INIT(3, en_3v3_sys, NULL, TPS6591X_GPIO_GP7, false, 0, 0, 0, 0)
503
504 GREG_INIT(4, dis_5v_switch,   "vdd_5v0_sys", TEGRA_GPIO_PX2,
505                         true, 0, 0, 0, 0)
506 GREG_INIT(5, en_vdd_bl,       NULL,          TEGRA_GPIO_PK3,
507                         false, 1, 0, 0, 0)
508 GREG_INIT(6, en_3v3_modem,    NULL,          TEGRA_GPIO_PD6,
509                         false, 1, 0, 0, 0)
510 GREG_INIT(7, en_usb1_vbus_oc, "master_5v_switch", TEGRA_GPIO_PI4,
511                         false, 0, TEGRA_PINGROUP_GMI_RST_N,
512                         enable_load_switch_rail, disable_load_switch_rail)
513 GREG_INIT(8, en_usb3_vbus_oc, "master_5v_switch", TEGRA_GPIO_PH7,
514                         false, 0, TEGRA_PINGROUP_GMI_AD15,
515                         enable_load_switch_rail, disable_load_switch_rail)
516 GREG_INIT(9, en_vddio_vid_oc, "master_5v_switch", TEGRA_GPIO_PT0,
517                         false, 0, TEGRA_PINGROUP_VI_PCLK,
518                         enable_load_switch_rail, disable_load_switch_rail)
519
520 GREG_INIT(10, en_vdd_pnl1, "vdd_3v3_devices", TEGRA_GPIO_PL4,
521                         false, 1, 0, 0, 0)
522 GREG_INIT(11, cam3_ldo_en, "vdd_3v3_devices", TEGRA_GPIO_PS0,
523                         false, 0, 0, 0, 0)
524 GREG_INIT(12, en_vdd_com,  "vdd_3v3_devices", TEGRA_GPIO_PD0,
525                         false, 1, 0, 0, 0)
526 GREG_INIT(13, en_3v3_fuse, "vdd_3v3_devices", TEGRA_GPIO_PL6,
527                         false, 0, 0, 0, 0)
528 GREG_INIT(14, en_3v3_emmc, "vdd_3v3_devices", TEGRA_GPIO_PD1,
529                         false, 1, 0, 0, 0)
530 GREG_INIT(15, en_vdd_sdmmc1, "vdd_3v3_devices", TEGRA_GPIO_PD7,
531                         false, 1, 0, 0, 0)
532 GREG_INIT(16, en_3v3_pex_hvdd, "vdd_3v3_devices", TEGRA_GPIO_PL7,
533                         false, 0, 0, 0, 0)
534
535 GREG_INIT(17, en_1v8_cam,  "vdd_gen1v8", TEGRA_GPIO_PBB4,
536                         false, 0, 0, 0, 0)
537
538 GREG_INIT(18, cam1_ldo_en, "vdd_3v3_cam", TEGRA_GPIO_PR6,
539                         false, 0, 0, 0, 0)
540 GREG_INIT(19, cam2_ldo_en, "vdd_3v3_cam", TEGRA_GPIO_PR7,
541                         false, 0, 0, 0, 0)
542 };
543
544 static struct gpio_switch_regulator_platform_data  gswitch_pdata = {
545         .num_subdevs = ARRAY_SIZE(gswitch_subdevs),
546         .subdevs = gswitch_subdevs,
547 };
548
549 static struct platform_device gswitch_regulator_pdata = {       \
550         .name = "gpio-switch-regulator",                        \
551         .id   = -1,                                             \
552         .dev  = {                                               \
553              .platform_data = &gswitch_pdata,                   \
554         },                                                      \
555 };
556 int __init cardhu_gpio_switch_regulator_init(void)
557 {
558         int i;
559         for (i = 0; i < ARRAY_SIZE(gswitch_subdevs); ++i) {
560                 if (gswitch_subdevs[i].gpio_nr <= TEGRA_NR_GPIOS)
561                         tegra_gpio_enable(gswitch_subdevs[i].gpio_nr);
562         }
563
564         return platform_device_register(&gswitch_regulator_pdata);
565 }
566 #else
567 int __init cardhu_gpio_switch_regulator_init(void)
568 {
569         return 0;
570 }
571 #endif
572
573 static struct tegra_suspend_platform_data cardhu_suspend_data = {
574         .cpu_timer      = 2000,
575         .cpu_off_timer  = 0,
576         .suspend_mode   = TEGRA_SUSPEND_NONE,
577         .core_timer     = 0x7e7e,
578         .core_off_timer = 0,
579         .separate_req   = true,
580         .corereq_high   = false,
581         .sysclkreq_high = true,
582         .wake_enb       = 0,
583         .wake_high      = 0,
584         .wake_low       = 0,
585         .wake_any       = 0,
586 };
587
588 int __init cardhu_suspend_init(void)
589 {
590         tegra_init_suspend(&cardhu_suspend_data);
591         return 0;
592
593 }