ARM: tegra: power: Set cpu_pwr_off timer to 200us for PMIC
[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 #if defined(CONFIG_RTC_DRV_TPS6591x)
243 static struct tps6591x_rtc_platform_data rtc_data = {
244         .irq = TEGRA_NR_IRQS + TPS6591X_INT_RTC_ALARM,
245         .time = {
246                 .tm_year = 2000,
247                 .tm_mon = 0,
248                 .tm_mday = 1,
249                 .tm_hour = 0,
250                 .tm_min = 0,
251                 .tm_sec = 0,
252         },
253 };
254
255 #define TPS_RTC_REG()                           \
256         {                                               \
257                 .id     = 0,            \
258                 .name   = "rtc_tps6591x",       \
259                 .platform_data = &rtc_data,     \
260         }
261 #endif
262
263 #define TPS_REG(_id, _data)                             \
264         {                                               \
265                 .id     = TPS6591X_ID_##_id,            \
266                 .name   = "tps6591x-regulator",         \
267                 .platform_data  = &pdata_##_data,       \
268         }
269
270 static struct tps6591x_subdev_info tps_devs_e118x[] = {
271         TPS_REG(VIO, vio),
272         TPS_REG(VDD_1, vdd1),
273         TPS_REG(VDD_2, vdd2),
274         TPS_REG(VDDCTRL, vddctrl),
275         TPS_REG(LDO_1, ldo1),
276         TPS_REG(LDO_2, ldo2),
277         TPS_REG(LDO_3, ldo3_e118x),
278         TPS_REG(LDO_4, ldo4),
279         TPS_REG(LDO_5, ldo5_e118x),
280         TPS_REG(LDO_6, ldo6),
281         TPS_REG(LDO_7, ldo7),
282         TPS_REG(LDO_8, ldo8),
283 #if defined(CONFIG_RTC_DRV_TPS6591x)
284         TPS_RTC_REG(),
285 #endif
286 };
287
288 static struct tps6591x_subdev_info tps_devs_e1198[] = {
289         TPS_REG(VIO, vio),
290         TPS_REG(VDD_1, vdd1),
291         TPS_REG(VDD_2, vdd2),
292         TPS_REG(VDDCTRL, vddctrl),
293         TPS_REG(LDO_1, ldo1),
294         TPS_REG(LDO_2, ldo2),
295         TPS_REG(LDO_3, ldo3_e1198),
296         TPS_REG(LDO_4, ldo4),
297         TPS_REG(LDO_5, ldo5_e1198),
298         TPS_REG(LDO_6, ldo6),
299         TPS_REG(LDO_7, ldo7),
300         TPS_REG(LDO_8, ldo8),
301 #if defined(CONFIG_RTC_DRV_TPS6591x)
302         TPS_RTC_REG(),
303 #endif
304 };
305
306 static struct tps6591x_platform_data tps_platform = {
307         .irq_base       = TPS6591X_IRQ_BASE,
308         .gpio_base      = TPS6591X_GPIO_BASE,
309 };
310
311 static struct i2c_board_info __initdata cardhu_regulators[] = {
312         {
313                 I2C_BOARD_INFO("tps6591x", 0x2D),
314                 .irq            = INT_EXTERNAL_PMU,
315                 .platform_data  = &tps_platform,
316         },
317 };
318
319 int __init cardhu_regulator_init(void)
320 {
321         struct board_info board_info;
322         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
323         u32 pmc_ctrl;
324         /* configure the power management controller to trigger PMU
325          * interrupts when low */
326         pmc_ctrl = readl(pmc + PMC_CTRL);
327         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
328
329         tegra_get_board_info(&board_info);
330         if ((board_info.board_id == BOARD_E1198) ||
331                 (board_info.board_id == BOARD_E1291)) {
332                 tps_platform.num_subdevs = ARRAY_SIZE(tps_devs_e1198);
333                 tps_platform.subdevs = tps_devs_e1198;
334         } else {
335                 tps_platform.num_subdevs = ARRAY_SIZE(tps_devs_e118x);
336                 tps_platform.subdevs = tps_devs_e118x;
337         }
338
339         i2c_register_board_info(4, cardhu_regulators, 1);
340         return 0;
341 }
342
343 /* EN_5V_CP from PMU GP0 */
344 static struct regulator_consumer_supply gpio_switch_en_5v_cp_supply[] = {
345         REGULATOR_SUPPLY("vdd_5v0_sby", NULL),
346         REGULATOR_SUPPLY("vdd_hall", NULL),
347         REGULATOR_SUPPLY("vterm_ddr", NULL),
348         REGULATOR_SUPPLY("v2ref_ddr", NULL),
349 };
350 static int gpio_switch_en_5v_cp_voltages[] = { 5000};
351
352 /* EN_5V0 From PMU GP2 */
353 static struct regulator_consumer_supply gpio_switch_en_5v0_supply[] = {
354         REGULATOR_SUPPLY("vdd_5v0_sys", NULL),
355 };
356 static int gpio_switch_en_5v0_voltages[] = { 5000};
357
358 /* EN_DDR From PMU GP6 */
359 static struct regulator_consumer_supply gpio_switch_en_ddr_supply[] = {
360         REGULATOR_SUPPLY("mem_vddio_ddr", NULL),
361         REGULATOR_SUPPLY("t30_vddio_ddr", NULL),
362 };
363 static int gpio_switch_en_ddr_voltages[] = { 1500};
364
365 /* EN_3V3_SYS From PMU GP7 */
366 static struct regulator_consumer_supply gpio_switch_en_3v3_sys_supply[] = {
367         REGULATOR_SUPPLY("vdd_lvds", NULL),
368         REGULATOR_SUPPLY("vdd_pnl", NULL),
369         REGULATOR_SUPPLY("vcom_3v3", NULL),
370         REGULATOR_SUPPLY("vdd_3v3", NULL),
371         REGULATOR_SUPPLY("vcore_mmc", NULL),
372         REGULATOR_SUPPLY("vddio_pex_ctl", NULL),
373         REGULATOR_SUPPLY("hvdd_pex", NULL),
374         REGULATOR_SUPPLY("avdd_hdmi", NULL),
375         REGULATOR_SUPPLY("vpp_fuse", NULL),
376         REGULATOR_SUPPLY("avdd_usb", NULL),
377         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
378         REGULATOR_SUPPLY("vcore_nand", NULL),
379         REGULATOR_SUPPLY("hvdd_sata", NULL),
380         REGULATOR_SUPPLY("vddio_gmi_pmu", NULL),
381         REGULATOR_SUPPLY("avdd_cam1", NULL),
382         REGULATOR_SUPPLY("vdd_af", NULL),
383         REGULATOR_SUPPLY("avdd_cam2", NULL),
384         REGULATOR_SUPPLY("vdd_acc", NULL),
385         REGULATOR_SUPPLY("vdd_phtl", NULL),
386         REGULATOR_SUPPLY("vddio_tp", NULL),
387         REGULATOR_SUPPLY("vdd_led", NULL),
388         REGULATOR_SUPPLY("vddio_cec", NULL),
389         REGULATOR_SUPPLY("vdd_cmps", NULL),
390         REGULATOR_SUPPLY("vdd_temp", NULL),
391         REGULATOR_SUPPLY("vpp_kfuse", NULL),
392         REGULATOR_SUPPLY("vddio_ts", NULL),
393         REGULATOR_SUPPLY("vdd_ir_led", NULL),
394         REGULATOR_SUPPLY("vddio_1wire", NULL),
395         REGULATOR_SUPPLY("avddio_audio", NULL),
396         REGULATOR_SUPPLY("vdd_ec", NULL),
397         REGULATOR_SUPPLY("vcom_pa", NULL),
398         REGULATOR_SUPPLY("vdd_3v3_devices", NULL),
399         REGULATOR_SUPPLY("vdd_3v3_dock", NULL),
400         REGULATOR_SUPPLY("vdd_3v3_edid", NULL),
401         REGULATOR_SUPPLY("vdd_3v3_hdmi_cec", NULL),
402         REGULATOR_SUPPLY("vdd_3v3_gmi", NULL),
403         REGULATOR_SUPPLY("vdd_3v3_spk_amp", NULL),
404         REGULATOR_SUPPLY("vdd_3v3_sensor", NULL),
405         REGULATOR_SUPPLY("vdd_3v3_cam", NULL),
406         REGULATOR_SUPPLY("vdd_3v3_als", NULL),
407         REGULATOR_SUPPLY("debug_cons", NULL),
408 };
409 static int gpio_switch_en_3v3_sys_voltages[] = { 3300};
410
411 /* DIS_5V_SWITCH from AP SPI2_SCK X02 */
412 static struct regulator_consumer_supply gpio_switch_dis_5v_switch_supply[] = {
413         REGULATOR_SUPPLY("master_5v_switch", NULL),
414 };
415 static int gpio_switch_dis_5v_switch_voltages[] = { 5000};
416
417 /* EN_VDD_BL */
418 static struct regulator_consumer_supply gpio_switch_en_vdd_bl_supply[] = {
419         REGULATOR_SUPPLY("vdd_backlight", NULL),
420         REGULATOR_SUPPLY("vdd_backlight1", NULL),
421 };
422 static int gpio_switch_en_vdd_bl_voltages[] = { 5000};
423
424 /* EN_VDD_BL2 (E1291-A03) from AP PEX_L0_PRSNT_N DD.00 */
425 static struct regulator_consumer_supply gpio_switch_en_vdd_bl2_supply[] = {
426         REGULATOR_SUPPLY("vdd_backlight2", NULL),
427 };
428 static int gpio_switch_en_vdd_bl2_voltages[] = { 5000};
429
430 /* EN_3V3_MODEM from AP GPIO VI_VSYNCH D06*/
431 static struct regulator_consumer_supply gpio_switch_en_3v3_modem_supply[] = {
432         REGULATOR_SUPPLY("vdd_3v3_mini_card", NULL),
433         REGULATOR_SUPPLY("vdd_mini_card", NULL),
434 };
435 static int gpio_switch_en_3v3_modem_voltages[] = { 3300};
436
437 /* EN_USB1_VBUS_OC*/
438 static struct regulator_consumer_supply gpio_switch_en_usb1_vbus_oc_supply[] = {
439         REGULATOR_SUPPLY("vdd_vbus_micro_usb", NULL),
440 };
441 static int gpio_switch_en_usb1_vbus_oc_voltages[] = { 5000};
442
443 /*EN_USB3_VBUS_OC*/
444 static struct regulator_consumer_supply gpio_switch_en_usb3_vbus_oc_supply[] = {
445         REGULATOR_SUPPLY("vdd_vbus_typea_usb", NULL),
446 };
447 static int gpio_switch_en_usb3_vbus_oc_voltages[] = { 5000};
448
449 /* EN_VDDIO_VID_OC from AP GPIO VI_PCLK T00*/
450 static struct regulator_consumer_supply gpio_switch_en_vddio_vid_oc_supply[] = {
451         REGULATOR_SUPPLY("vdd_hdmi_con", NULL),
452 };
453 static int gpio_switch_en_vddio_vid_oc_voltages[] = { 5000};
454
455 /* EN_VDD_PNL1 from AP GPIO VI_D6 L04*/
456 static struct regulator_consumer_supply gpio_switch_en_vdd_pnl1_supply[] = {
457         REGULATOR_SUPPLY("vdd_lcd_panel", NULL),
458 };
459 static int gpio_switch_en_vdd_pnl1_voltages[] = { 3300};
460
461 /* CAM1_LDO_EN from AP GPIO KB_ROW6 R06*/
462 static struct regulator_consumer_supply gpio_switch_cam1_ldo_en_supply[] = {
463         REGULATOR_SUPPLY("vdd_2v8_cam1", NULL),
464 };
465 static int gpio_switch_cam1_ldo_en_voltages[] = { 2800};
466
467 /* CAM2_LDO_EN from AP GPIO KB_ROW7 R07*/
468 static struct regulator_consumer_supply gpio_switch_cam2_ldo_en_supply[] = {
469         REGULATOR_SUPPLY("vdd_2v8_cam2", NULL),
470 };
471 static int gpio_switch_cam2_ldo_en_voltages[] = { 2800};
472
473 /* CAM3_LDO_EN from AP GPIO KB_ROW8 S00*/
474 static struct regulator_consumer_supply gpio_switch_cam3_ldo_en_supply[] = {
475         REGULATOR_SUPPLY("vdd_cam3", NULL),
476 };
477 static int gpio_switch_cam3_ldo_en_voltages[] = { 3300};
478
479 /* EN_VDD_COM from AP GPIO SDMMC3_DAT5 D00*/
480 static struct regulator_consumer_supply gpio_switch_en_vdd_com_supply[] = {
481         REGULATOR_SUPPLY("vdd_com_bd", NULL),
482 };
483 static int gpio_switch_en_vdd_com_voltages[] = { 3300};
484
485 /* EN_VDD_SDMMC1 from AP GPIO VI_HSYNC D07*/
486 static struct regulator_consumer_supply gpio_switch_en_vdd_sdmmc1_supply[] = {
487         REGULATOR_SUPPLY("vddio_sd_slot", NULL),
488 };
489 static int gpio_switch_en_vdd_sdmmc1_voltages[] = { 3300};
490
491 /* EN_3V3_EMMC from AP GPIO SDMMC3_DAT4 D01*/
492 static struct regulator_consumer_supply gpio_switch_en_3v3_emmc_supply[] = {
493         REGULATOR_SUPPLY("vdd_emmc_core", NULL),
494 };
495 static int gpio_switch_en_3v3_emmc_voltages[] = { 3300};
496
497 /* EN_3V3_PEX_HVDD from AP GPIO VI_D09 L07*/
498 static struct regulator_consumer_supply gpio_switch_en_3v3_pex_hvdd_supply[] = {
499         REGULATOR_SUPPLY("hvdd_pex_3v3", NULL),
500 };
501 static int gpio_switch_en_3v3_pex_hvdd_voltages[] = { 3300};
502
503 /* EN_3v3_FUSE from AP GPIO VI_D08 L06*/
504 static struct regulator_consumer_supply gpio_switch_en_3v3_fuse_supply[] = {
505         REGULATOR_SUPPLY("vpp_fuse_pg", NULL),
506 };
507 static int gpio_switch_en_3v3_fuse_voltages[] = { 3300};
508
509 /* EN_1V8_CAM from AP GPIO GPIO_PBB4 PBB04*/
510 static struct regulator_consumer_supply gpio_switch_en_1v8_cam_supply[] = {
511         REGULATOR_SUPPLY("vdd_1v8_cam1", NULL),
512         REGULATOR_SUPPLY("vdd_1v8_cam2", NULL),
513         REGULATOR_SUPPLY("vdd_1v8_cam3", NULL),
514 };
515 static int gpio_switch_en_1v8_cam_voltages[] = { 1800};
516
517 static struct regulator_consumer_supply gpio_switch_en_vbrtr_supply[] = {
518         REGULATOR_SUPPLY("vdd_vbrtr", NULL),
519 };
520 static int gpio_switch_en_vbrtr_voltages[] = { 3300};
521
522 static int enable_load_switch_rail(
523                 struct gpio_switch_regulator_subdev_data *psubdev_data)
524 {
525         int ret;
526
527         if (psubdev_data->pin_group <= 0)
528                 return -EINVAL;
529
530         /* Tristate and make pin as input*/
531         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
532                                                 TEGRA_TRI_TRISTATE);
533         if (ret < 0)
534                 return ret;
535         return gpio_direction_input(psubdev_data->gpio_nr);
536 }
537
538 static int disable_load_switch_rail(
539                 struct gpio_switch_regulator_subdev_data *psubdev_data)
540 {
541         int ret;
542
543         if (psubdev_data->pin_group <= 0)
544                 return -EINVAL;
545
546         /* Un-tristate and driver low */
547         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
548                                                 TEGRA_TRI_NORMAL);
549         if (ret < 0)
550                 return ret;
551         return gpio_direction_output(psubdev_data->gpio_nr, 0);
552 }
553
554
555 /* Macro for defining gpio switch regulator sub device data */
556 #define GREG_INIT(_id, _var, _name, _input_supply, _gpio_nr, _active_low, \
557                         _init_state, _pg, _enable, _disable)            \
558         static struct gpio_switch_regulator_subdev_data gpio_pdata_##_var =  \
559         {                                                               \
560                 .regulator_name = "gpio-switch-"#_name,                 \
561                 .input_supply   = _input_supply,                        \
562                 .id             = _id,                                  \
563                 .gpio_nr        = _gpio_nr,                             \
564                 .pin_group      = _pg,                                  \
565                 .active_low     = _active_low,                          \
566                 .init_state     = _init_state,                          \
567                 .voltages       = gpio_switch_##_name##_voltages,       \
568                 .n_voltages     = ARRAY_SIZE(gpio_switch_##_name##_voltages), \
569                 .num_consumer_supplies =                                \
570                                 ARRAY_SIZE(gpio_switch_##_name##_supply), \
571                 .consumer_supplies = gpio_switch_##_name##_supply,      \
572                 .constraints = {                                        \
573                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
574                                              REGULATOR_MODE_STANDBY),   \
575                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
576                                            REGULATOR_CHANGE_STATUS |    \
577                                            REGULATOR_CHANGE_VOLTAGE),   \
578                 },                                                      \
579                 .enable_rail = _enable,                                 \
580                 .disable_rail = _disable,                               \
581         }
582
583 /* common to all boards */
584 GREG_INIT(0, en_5v_cp,          en_5v_cp,       NULL,                   TPS6591X_GPIO_GP0,      false,  0,      0,      0,      0);
585 GREG_INIT(1, en_5v0,            en_5v0,         NULL,                   TPS6591X_GPIO_GP2,      false,  0,      0,      0,      0);
586 GREG_INIT(2, en_ddr,            en_ddr,         NULL,                   TPS6591X_GPIO_GP6,      false,  0,      0,      0,      0);
587 GREG_INIT(3, en_3v3_sys,        en_3v3_sys,     NULL,                   TPS6591X_GPIO_GP7,      false,  0,      0,      0,      0);
588 GREG_INIT(4, en_vdd_bl,         en_vdd_bl,      NULL,                   TEGRA_GPIO_PK3,         false,  1,      0,      0,      0);
589 GREG_INIT(5, en_3v3_modem,      en_3v3_modem,   NULL,                   TEGRA_GPIO_PD6,         false,  1,      0,      0,      0);
590 GREG_INIT(6, en_vdd_pnl1,       en_vdd_pnl1,    "vdd_3v3_devices",      TEGRA_GPIO_PL4,         false,  1,      0,      0,      0);
591 GREG_INIT(7, cam3_ldo_en,       cam3_ldo_en,    "vdd_3v3_devices",      TEGRA_GPIO_PS0,         false,  0,      0,      0,      0);
592 GREG_INIT(8, en_vdd_com,        en_vdd_com,     "vdd_3v3_devices",      TEGRA_GPIO_PD0,         false,  1,      0,      0,      0);
593 GREG_INIT(9, en_3v3_fuse,       en_3v3_fuse,    "vdd_3v3_devices",      TEGRA_GPIO_PL6,         false,  0,      0,      0,      0);
594 GREG_INIT(10, en_3v3_emmc,      en_3v3_emmc,    "vdd_3v3_devices",      TEGRA_GPIO_PD1,         false,  1,      0,      0,      0);
595 GREG_INIT(11, en_vdd_sdmmc1,    en_vdd_sdmmc1,  "vdd_3v3_devices",      TEGRA_GPIO_PD7,         false,  1,      0,      0,      0);
596 GREG_INIT(12, en_3v3_pex_hvdd,  en_3v3_pex_hvdd, "vdd_3v3_devices",     TEGRA_GPIO_PL7,         false,  0,      0,      0,      0);
597 GREG_INIT(13, en_1v8_cam,       en_1v8_cam,     "vdd_gen1v8",           TEGRA_GPIO_PBB4,        false,  0,      0,      0,      0);
598
599 /* Specific to E1187/E1186 */
600 GREG_INIT(14, dis_5v_switch_e118x,      dis_5v_switch,          "vdd_5v0_sys",
601                 TEGRA_GPIO_PX2,         true,   0,      0,      0,      0);
602 GREG_INIT(15, en_usb1_vbus_oc_e118x,    en_usb1_vbus_oc,        "master_5v_switch",
603                 TEGRA_GPIO_PI4,         false,  0,      TEGRA_PINGROUP_GMI_RST_N,
604                 enable_load_switch_rail, disable_load_switch_rail);
605 GREG_INIT(16, en_usb3_vbus_oc_e118x,    en_usb3_vbus_oc,        "master_5v_switch",
606                 TEGRA_GPIO_PH7,         false,  0,      TEGRA_PINGROUP_GMI_AD15,
607                 enable_load_switch_rail, disable_load_switch_rail);
608 GREG_INIT(17, en_vddio_vid_oc_e118x,    en_vddio_vid_oc,        "master_5v_switch",
609                 TEGRA_GPIO_PT0,         false,  0,      TEGRA_PINGROUP_VI_PCLK,
610                 enable_load_switch_rail, disable_load_switch_rail);
611
612 /* E1198/E1291 specific  fab < A03 */
613 GREG_INIT(15, en_usb1_vbus_oc,          en_usb1_vbus_oc,        "vdd_5v0_sys",
614                 TEGRA_GPIO_PI4,         false,  0,      TEGRA_PINGROUP_GMI_RST_N,
615                 enable_load_switch_rail, disable_load_switch_rail);
616 GREG_INIT(16, en_usb3_vbus_oc,          en_usb3_vbus_oc,        "vdd_5v0_sys",
617                 TEGRA_GPIO_PH7,         false,  0,      TEGRA_PINGROUP_GMI_AD15,
618                 enable_load_switch_rail, disable_load_switch_rail);
619
620 /* E1198/E1291 specific  fab >= A03 */
621 GREG_INIT(15, en_usb1_vbus_oc_a03,              en_usb1_vbus_oc,        "vdd_5v0_sys",
622                 TEGRA_GPIO_PDD6,                false,  0,      TEGRA_PINGROUP_PEX_L1_CLKREQ_N,
623                 enable_load_switch_rail, disable_load_switch_rail);
624 GREG_INIT(16, en_usb3_vbus_oc_a03,              en_usb3_vbus_oc,        "vdd_5v0_sys",
625                 TEGRA_GPIO_PDD4,                false,  0,      TEGRA_PINGROUP_PEX_L1_PRSNT_N,
626                 enable_load_switch_rail, disable_load_switch_rail);
627
628 /* E1198/E1291 specific */
629 GREG_INIT(17, en_vddio_vid_oc,          en_vddio_vid_oc,        "vdd_5v0_sys",
630                 TEGRA_GPIO_PT0,         false,  0,      TEGRA_PINGROUP_VI_PCLK,
631                 enable_load_switch_rail, disable_load_switch_rail);
632
633 /* E1198/E1291 specific*/
634 GREG_INIT(18, cam1_ldo_en,      cam1_ldo_en,            "vdd_3v3_cam",  TEGRA_GPIO_PR6,         false,  0,      0,      0,      0);
635 GREG_INIT(19, cam2_ldo_en,      cam2_ldo_en,            "vdd_3v3_cam",  TEGRA_GPIO_PR7,         false,  0,      0,      0,      0);
636
637 /* E1291 A03 specific */
638 GREG_INIT(20, en_vdd_bl1_a03,   en_vdd_bl,      NULL,           TEGRA_GPIO_PDD2,        false,  1,      0,      0,      0);
639 GREG_INIT(21, en_vdd_bl2_a03,   en_vdd_bl2,     NULL,           TEGRA_GPIO_PDD0,        false,  1,      0,      0,      0);
640
641 GREG_INIT(22, en_vbrtr, en_vbrtr, "vdd_3v3_devices",    PMU_TCA6416_GPIO_PORT12,                false,  0,      0,      0,      0);
642
643 #define ADD_GPIO_REG(_name) &gpio_pdata_##_name
644 #define COMMON_GPIO_REG \
645         ADD_GPIO_REG(en_5v_cp),                 \
646         ADD_GPIO_REG(en_5v0),                   \
647         ADD_GPIO_REG(en_ddr),                   \
648         ADD_GPIO_REG(en_3v3_sys),               \
649         ADD_GPIO_REG(en_3v3_modem),             \
650         ADD_GPIO_REG(en_vdd_pnl1),              \
651         ADD_GPIO_REG(cam3_ldo_en),              \
652         ADD_GPIO_REG(en_vdd_com),               \
653         ADD_GPIO_REG(en_3v3_fuse),              \
654         ADD_GPIO_REG(en_3v3_emmc),              \
655         ADD_GPIO_REG(en_vdd_sdmmc1),            \
656         ADD_GPIO_REG(en_3v3_pex_hvdd),          \
657         ADD_GPIO_REG(en_1v8_cam),
658
659 #define E118x_GPIO_REG  \
660         ADD_GPIO_REG(en_vdd_bl),                \
661         ADD_GPIO_REG(dis_5v_switch_e118x),      \
662         ADD_GPIO_REG(en_usb1_vbus_oc_e118x),    \
663         ADD_GPIO_REG(en_usb3_vbus_oc_e118x),    \
664         ADD_GPIO_REG(en_vddio_vid_oc_e118x), \
665         ADD_GPIO_REG(en_vbrtr),
666
667 #define E1198_GPIO_REG  \
668         ADD_GPIO_REG(en_vddio_vid_oc),          \
669         ADD_GPIO_REG(cam1_ldo_en),              \
670         ADD_GPIO_REG(cam2_ldo_en),
671
672 #define E1291_1198_A00_GPIO_REG \
673         ADD_GPIO_REG(en_usb1_vbus_oc),          \
674         ADD_GPIO_REG(en_usb3_vbus_oc),          \
675         ADD_GPIO_REG(en_vdd_bl),
676
677 #define E1291_A03_GPIO_REG      \
678         ADD_GPIO_REG(en_usb1_vbus_oc_a03),              \
679         ADD_GPIO_REG(en_usb3_vbus_oc_a03),              \
680         ADD_GPIO_REG(en_vdd_bl1_a03), \
681         ADD_GPIO_REG(en_vdd_bl2_a03),
682
683 /* Gpio switch regulator platform data  for E1186/E1187*/
684
685 /* Gpio switch regulator platform data  for E1186/E1187*/
686 static struct gpio_switch_regulator_subdev_data *gswitch_subdevs_e118x[] = {
687         COMMON_GPIO_REG
688         E118x_GPIO_REG
689 };
690
691 /* Gpio switch regulator platform data for E1198 and E1291*/
692 static struct gpio_switch_regulator_subdev_data *gswitch_subdevs_e1198[] = {
693         COMMON_GPIO_REG
694         E1291_1198_A00_GPIO_REG
695         E1198_GPIO_REG
696 };
697
698 /* Gpio switch regulator platform data for E1291 A03*/
699 static struct gpio_switch_regulator_subdev_data *gswitch_subdevs_e1291_a03[] = {
700         COMMON_GPIO_REG
701         E1291_A03_GPIO_REG
702         E1198_GPIO_REG
703 };
704
705 static struct gpio_switch_regulator_platform_data  gswitch_pdata;
706 static struct platform_device gswitch_regulator_pdata = {
707         .name = "gpio-switch-regulator",
708         .id   = -1,
709         .dev  = {
710              .platform_data = &gswitch_pdata,
711         },
712 };
713
714 int __init cardhu_gpio_switch_regulator_init(void)
715 {
716         int i;
717         struct board_info board_info;
718         tegra_get_board_info(&board_info);
719         switch (board_info.board_id) {
720         case BOARD_E1198:
721                 gswitch_pdata.num_subdevs = ARRAY_SIZE(gswitch_subdevs_e1198);
722                 gswitch_pdata.subdevs = gswitch_subdevs_e1198;
723                 break;
724         case BOARD_E1291:
725                 if (board_info.fab >= 0x3) {
726                         gswitch_pdata.num_subdevs =
727                                         ARRAY_SIZE(gswitch_subdevs_e1291_a03);
728                         gswitch_pdata.subdevs = gswitch_subdevs_e1291_a03;
729                         break;
730                 }
731                 gswitch_pdata.num_subdevs = ARRAY_SIZE(gswitch_subdevs_e1198);
732                 gswitch_pdata.subdevs = gswitch_subdevs_e1198;
733                 break;
734         default:
735                 gswitch_pdata.num_subdevs = ARRAY_SIZE(gswitch_subdevs_e118x);
736                 gswitch_pdata.subdevs = gswitch_subdevs_e118x;
737                 break;
738         }
739
740         for (i = 0; i < gswitch_pdata.num_subdevs; ++i) {
741                 struct gpio_switch_regulator_subdev_data *gswitch_data = gswitch_pdata.subdevs[i];
742                 if (gswitch_data->gpio_nr <= TEGRA_NR_GPIOS)
743                         tegra_gpio_enable(gswitch_data->gpio_nr);
744         }
745
746         return platform_device_register(&gswitch_regulator_pdata);
747 }
748
749 static struct tegra_suspend_platform_data cardhu_suspend_data = {
750         .cpu_timer      = 2000,
751         .cpu_off_timer  = 200,
752         .suspend_mode   = TEGRA_SUSPEND_LP1,
753         .core_timer     = 0x7e7e,
754         .core_off_timer = 0,
755         .separate_req   = true,
756         .corereq_high   = false,
757         .sysclkreq_high = true,
758         .wake_enb       = TEGRA_WAKE_GPIO_PV0 | TEGRA_WAKE_PWR_INT | TEGRA_WAKE_RTC_ALARM,
759         .wake_high      = TEGRA_WAKE_RTC_ALARM,
760         .wake_low       = TEGRA_WAKE_GPIO_PV0 | TEGRA_WAKE_PWR_INT,
761         .wake_any       = 0,
762         .cpu_lp2_min_residency = 2000,
763 };
764
765 int __init cardhu_suspend_init(void)
766 {
767         struct board_info board_info;
768
769         tegra_get_board_info(&board_info);
770         switch (board_info.board_id) {
771         case BOARD_E1291:
772                 /* CORE_PWR_REQ to be high for E1291-A03 */
773                 if (board_info.fab == 0x3)
774                         cardhu_suspend_data.corereq_high = true;
775                 break;
776         case BOARD_E1198:
777                 break;
778         case BOARD_PM269:
779         case BOARD_E1187:
780         case BOARD_E1186:
781                 cardhu_suspend_data.cpu_timer = 5000;
782                 cardhu_suspend_data.cpu_off_timer = 5000;
783                 break;
784         default:
785                 break;
786         }
787
788         tegra_init_suspend(&cardhu_suspend_data);
789         return 0;
790 }
791
792 static void cardhu_power_off(void)
793 {
794         int ret;
795         pr_err("cardhu: Powering off the device\n");
796         ret = tps6591x_power_off();
797         if (ret)
798                 pr_err("cardhu: failed to power off\n");
799
800         while(1);
801 }
802
803 int __init cardhu_power_off_init(void)
804 {
805         pm_power_off = cardhu_power_off;
806         return 0;
807 }
808