arm: tegra: cardhu: Adding cam-AF power rails
[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         REGULATOR_SUPPLY("vdd_2v8_cam1_af", NULL),
465 };
466 static int gpio_switch_cam1_ldo_en_voltages[] = { 2800};
467
468 /* CAM2_LDO_EN from AP GPIO KB_ROW7 R07*/
469 static struct regulator_consumer_supply gpio_switch_cam2_ldo_en_supply[] = {
470         REGULATOR_SUPPLY("vdd_2v8_cam2", NULL),
471         REGULATOR_SUPPLY("vdd_2v8_cam2_af", NULL),
472 };
473 static int gpio_switch_cam2_ldo_en_voltages[] = { 2800};
474
475 /* CAM3_LDO_EN from AP GPIO KB_ROW8 S00*/
476 static struct regulator_consumer_supply gpio_switch_cam3_ldo_en_supply[] = {
477         REGULATOR_SUPPLY("vdd_cam3", NULL),
478 };
479 static int gpio_switch_cam3_ldo_en_voltages[] = { 3300};
480
481 /* EN_VDD_COM from AP GPIO SDMMC3_DAT5 D00*/
482 static struct regulator_consumer_supply gpio_switch_en_vdd_com_supply[] = {
483         REGULATOR_SUPPLY("vdd_com_bd", NULL),
484 };
485 static int gpio_switch_en_vdd_com_voltages[] = { 3300};
486
487 /* EN_VDD_SDMMC1 from AP GPIO VI_HSYNC D07*/
488 static struct regulator_consumer_supply gpio_switch_en_vdd_sdmmc1_supply[] = {
489         REGULATOR_SUPPLY("vddio_sd_slot", NULL),
490 };
491 static int gpio_switch_en_vdd_sdmmc1_voltages[] = { 3300};
492
493 /* EN_3V3_EMMC from AP GPIO SDMMC3_DAT4 D01*/
494 static struct regulator_consumer_supply gpio_switch_en_3v3_emmc_supply[] = {
495         REGULATOR_SUPPLY("vdd_emmc_core", NULL),
496 };
497 static int gpio_switch_en_3v3_emmc_voltages[] = { 3300};
498
499 /* EN_3V3_PEX_HVDD from AP GPIO VI_D09 L07*/
500 static struct regulator_consumer_supply gpio_switch_en_3v3_pex_hvdd_supply[] = {
501         REGULATOR_SUPPLY("hvdd_pex_3v3", NULL),
502 };
503 static int gpio_switch_en_3v3_pex_hvdd_voltages[] = { 3300};
504
505 /* EN_3v3_FUSE from AP GPIO VI_D08 L06*/
506 static struct regulator_consumer_supply gpio_switch_en_3v3_fuse_supply[] = {
507         REGULATOR_SUPPLY("vpp_fuse_pg", NULL),
508 };
509 static int gpio_switch_en_3v3_fuse_voltages[] = { 3300};
510
511 /* EN_1V8_CAM from AP GPIO GPIO_PBB4 PBB04*/
512 static struct regulator_consumer_supply gpio_switch_en_1v8_cam_supply[] = {
513         REGULATOR_SUPPLY("vdd_1v8_cam1", NULL),
514         REGULATOR_SUPPLY("vdd_1v8_cam2", NULL),
515         REGULATOR_SUPPLY("vdd_1v8_cam3", NULL),
516 };
517 static int gpio_switch_en_1v8_cam_voltages[] = { 1800};
518
519 static struct regulator_consumer_supply gpio_switch_en_vbrtr_supply[] = {
520         REGULATOR_SUPPLY("vdd_vbrtr", NULL),
521 };
522 static int gpio_switch_en_vbrtr_voltages[] = { 3300};
523
524 static int enable_load_switch_rail(
525                 struct gpio_switch_regulator_subdev_data *psubdev_data)
526 {
527         int ret;
528
529         if (psubdev_data->pin_group <= 0)
530                 return -EINVAL;
531
532         /* Tristate and make pin as input*/
533         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
534                                                 TEGRA_TRI_TRISTATE);
535         if (ret < 0)
536                 return ret;
537         return gpio_direction_input(psubdev_data->gpio_nr);
538 }
539
540 static int disable_load_switch_rail(
541                 struct gpio_switch_regulator_subdev_data *psubdev_data)
542 {
543         int ret;
544
545         if (psubdev_data->pin_group <= 0)
546                 return -EINVAL;
547
548         /* Un-tristate and driver low */
549         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
550                                                 TEGRA_TRI_NORMAL);
551         if (ret < 0)
552                 return ret;
553         return gpio_direction_output(psubdev_data->gpio_nr, 0);
554 }
555
556
557 /* Macro for defining gpio switch regulator sub device data */
558 #define GREG_INIT(_id, _var, _name, _input_supply, _gpio_nr, _active_low, \
559                         _init_state, _pg, _enable, _disable)            \
560         static struct gpio_switch_regulator_subdev_data gpio_pdata_##_var =  \
561         {                                                               \
562                 .regulator_name = "gpio-switch-"#_name,                 \
563                 .input_supply   = _input_supply,                        \
564                 .id             = _id,                                  \
565                 .gpio_nr        = _gpio_nr,                             \
566                 .pin_group      = _pg,                                  \
567                 .active_low     = _active_low,                          \
568                 .init_state     = _init_state,                          \
569                 .voltages       = gpio_switch_##_name##_voltages,       \
570                 .n_voltages     = ARRAY_SIZE(gpio_switch_##_name##_voltages), \
571                 .num_consumer_supplies =                                \
572                                 ARRAY_SIZE(gpio_switch_##_name##_supply), \
573                 .consumer_supplies = gpio_switch_##_name##_supply,      \
574                 .constraints = {                                        \
575                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
576                                              REGULATOR_MODE_STANDBY),   \
577                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
578                                            REGULATOR_CHANGE_STATUS |    \
579                                            REGULATOR_CHANGE_VOLTAGE),   \
580                 },                                                      \
581                 .enable_rail = _enable,                                 \
582                 .disable_rail = _disable,                               \
583         }
584
585 /* common to all boards */
586 GREG_INIT(0, en_5v_cp,          en_5v_cp,       NULL,                   TPS6591X_GPIO_GP0,      false,  0,      0,      0,      0);
587 GREG_INIT(1, en_5v0,            en_5v0,         NULL,                   TPS6591X_GPIO_GP2,      false,  0,      0,      0,      0);
588 GREG_INIT(2, en_ddr,            en_ddr,         NULL,                   TPS6591X_GPIO_GP6,      false,  0,      0,      0,      0);
589 GREG_INIT(3, en_3v3_sys,        en_3v3_sys,     NULL,                   TPS6591X_GPIO_GP7,      false,  0,      0,      0,      0);
590 GREG_INIT(4, en_vdd_bl,         en_vdd_bl,      NULL,                   TEGRA_GPIO_PK3,         false,  1,      0,      0,      0);
591 GREG_INIT(5, en_3v3_modem,      en_3v3_modem,   NULL,                   TEGRA_GPIO_PD6,         false,  1,      0,      0,      0);
592 GREG_INIT(6, en_vdd_pnl1,       en_vdd_pnl1,    "vdd_3v3_devices",      TEGRA_GPIO_PL4,         false,  1,      0,      0,      0);
593 GREG_INIT(7, cam3_ldo_en,       cam3_ldo_en,    "vdd_3v3_devices",      TEGRA_GPIO_PS0,         false,  0,      0,      0,      0);
594 GREG_INIT(8, en_vdd_com,        en_vdd_com,     "vdd_3v3_devices",      TEGRA_GPIO_PD0,         false,  1,      0,      0,      0);
595 GREG_INIT(9, en_3v3_fuse,       en_3v3_fuse,    "vdd_3v3_devices",      TEGRA_GPIO_PL6,         false,  0,      0,      0,      0);
596 GREG_INIT(10, en_3v3_emmc,      en_3v3_emmc,    "vdd_3v3_devices",      TEGRA_GPIO_PD1,         false,  1,      0,      0,      0);
597 GREG_INIT(11, en_vdd_sdmmc1,    en_vdd_sdmmc1,  "vdd_3v3_devices",      TEGRA_GPIO_PD7,         false,  1,      0,      0,      0);
598 GREG_INIT(12, en_3v3_pex_hvdd,  en_3v3_pex_hvdd, "vdd_3v3_devices",     TEGRA_GPIO_PL7,         false,  0,      0,      0,      0);
599 GREG_INIT(13, en_1v8_cam,       en_1v8_cam,     "vdd_gen1v8",           TEGRA_GPIO_PBB4,        false,  0,      0,      0,      0);
600
601 /* Specific to E1187/E1186 */
602 GREG_INIT(14, dis_5v_switch_e118x,      dis_5v_switch,          "vdd_5v0_sys",
603                 TEGRA_GPIO_PX2,         true,   0,      0,      0,      0);
604 GREG_INIT(15, en_usb1_vbus_oc_e118x,    en_usb1_vbus_oc,        "master_5v_switch",
605                 TEGRA_GPIO_PI4,         false,  0,      TEGRA_PINGROUP_GMI_RST_N,
606                 enable_load_switch_rail, disable_load_switch_rail);
607 GREG_INIT(16, en_usb3_vbus_oc_e118x,    en_usb3_vbus_oc,        "master_5v_switch",
608                 TEGRA_GPIO_PH7,         false,  0,      TEGRA_PINGROUP_GMI_AD15,
609                 enable_load_switch_rail, disable_load_switch_rail);
610 GREG_INIT(17, en_vddio_vid_oc_e118x,    en_vddio_vid_oc,        "master_5v_switch",
611                 TEGRA_GPIO_PT0,         false,  0,      TEGRA_PINGROUP_VI_PCLK,
612                 enable_load_switch_rail, disable_load_switch_rail);
613
614 /* E1198/E1291 specific  fab < A03 */
615 GREG_INIT(15, en_usb1_vbus_oc,          en_usb1_vbus_oc,        "vdd_5v0_sys",
616                 TEGRA_GPIO_PI4,         false,  0,      TEGRA_PINGROUP_GMI_RST_N,
617                 enable_load_switch_rail, disable_load_switch_rail);
618 GREG_INIT(16, en_usb3_vbus_oc,          en_usb3_vbus_oc,        "vdd_5v0_sys",
619                 TEGRA_GPIO_PH7,         false,  0,      TEGRA_PINGROUP_GMI_AD15,
620                 enable_load_switch_rail, disable_load_switch_rail);
621
622 /* E1198/E1291 specific  fab >= A03 */
623 GREG_INIT(15, en_usb1_vbus_oc_a03,              en_usb1_vbus_oc,        "vdd_5v0_sys",
624                 TEGRA_GPIO_PDD6,                false,  0,      TEGRA_PINGROUP_PEX_L1_CLKREQ_N,
625                 enable_load_switch_rail, disable_load_switch_rail);
626 GREG_INIT(16, en_usb3_vbus_oc_a03,              en_usb3_vbus_oc,        "vdd_5v0_sys",
627                 TEGRA_GPIO_PDD4,                false,  0,      TEGRA_PINGROUP_PEX_L1_PRSNT_N,
628                 enable_load_switch_rail, disable_load_switch_rail);
629
630 /* E1198/E1291 specific */
631 GREG_INIT(17, en_vddio_vid_oc,          en_vddio_vid_oc,        "vdd_5v0_sys",
632                 TEGRA_GPIO_PT0,         false,  0,      TEGRA_PINGROUP_VI_PCLK,
633                 enable_load_switch_rail, disable_load_switch_rail);
634
635 /* E1198/E1291 specific*/
636 GREG_INIT(18, cam1_ldo_en,      cam1_ldo_en,            "vdd_3v3_cam",  TEGRA_GPIO_PR6,         false,  0,      0,      0,      0);
637 GREG_INIT(19, cam2_ldo_en,      cam2_ldo_en,            "vdd_3v3_cam",  TEGRA_GPIO_PR7,         false,  0,      0,      0,      0);
638
639 /* E1291 A03 specific */
640 GREG_INIT(20, en_vdd_bl1_a03,   en_vdd_bl,      NULL,           TEGRA_GPIO_PDD2,        false,  1,      0,      0,      0);
641 GREG_INIT(21, en_vdd_bl2_a03,   en_vdd_bl2,     NULL,           TEGRA_GPIO_PDD0,        false,  1,      0,      0,      0);
642
643 GREG_INIT(22, en_vbrtr, en_vbrtr, "vdd_3v3_devices",    PMU_TCA6416_GPIO_PORT12,                false,  0,      0,      0,      0);
644
645 #define ADD_GPIO_REG(_name) &gpio_pdata_##_name
646 #define COMMON_GPIO_REG \
647         ADD_GPIO_REG(en_5v_cp),                 \
648         ADD_GPIO_REG(en_5v0),                   \
649         ADD_GPIO_REG(en_ddr),                   \
650         ADD_GPIO_REG(en_3v3_sys),               \
651         ADD_GPIO_REG(en_3v3_modem),             \
652         ADD_GPIO_REG(en_vdd_pnl1),              \
653         ADD_GPIO_REG(cam3_ldo_en),              \
654         ADD_GPIO_REG(en_vdd_com),               \
655         ADD_GPIO_REG(en_3v3_fuse),              \
656         ADD_GPIO_REG(en_3v3_emmc),              \
657         ADD_GPIO_REG(en_vdd_sdmmc1),            \
658         ADD_GPIO_REG(en_3v3_pex_hvdd),          \
659         ADD_GPIO_REG(en_1v8_cam),
660
661 #define E118x_GPIO_REG  \
662         ADD_GPIO_REG(en_vdd_bl),                \
663         ADD_GPIO_REG(dis_5v_switch_e118x),      \
664         ADD_GPIO_REG(en_usb1_vbus_oc_e118x),    \
665         ADD_GPIO_REG(en_usb3_vbus_oc_e118x),    \
666         ADD_GPIO_REG(en_vddio_vid_oc_e118x), \
667         ADD_GPIO_REG(en_vbrtr),
668
669 #define E1198_GPIO_REG  \
670         ADD_GPIO_REG(en_vddio_vid_oc),          \
671         ADD_GPIO_REG(cam1_ldo_en),              \
672         ADD_GPIO_REG(cam2_ldo_en),
673
674 #define E1291_1198_A00_GPIO_REG \
675         ADD_GPIO_REG(en_usb1_vbus_oc),          \
676         ADD_GPIO_REG(en_usb3_vbus_oc),          \
677         ADD_GPIO_REG(en_vdd_bl),
678
679 #define E1291_A03_GPIO_REG      \
680         ADD_GPIO_REG(en_usb1_vbus_oc_a03),              \
681         ADD_GPIO_REG(en_usb3_vbus_oc_a03),              \
682         ADD_GPIO_REG(en_vdd_bl1_a03), \
683         ADD_GPIO_REG(en_vdd_bl2_a03),
684
685 /* Gpio switch regulator platform data  for E1186/E1187*/
686
687 /* Gpio switch regulator platform data  for E1186/E1187*/
688 static struct gpio_switch_regulator_subdev_data *gswitch_subdevs_e118x[] = {
689         COMMON_GPIO_REG
690         E118x_GPIO_REG
691 };
692
693 /* Gpio switch regulator platform data for E1198 and E1291*/
694 static struct gpio_switch_regulator_subdev_data *gswitch_subdevs_e1198[] = {
695         COMMON_GPIO_REG
696         E1291_1198_A00_GPIO_REG
697         E1198_GPIO_REG
698 };
699
700 /* Gpio switch regulator platform data for E1291 A03*/
701 static struct gpio_switch_regulator_subdev_data *gswitch_subdevs_e1291_a03[] = {
702         COMMON_GPIO_REG
703         E1291_A03_GPIO_REG
704         E1198_GPIO_REG
705 };
706
707 static struct gpio_switch_regulator_platform_data  gswitch_pdata;
708 static struct platform_device gswitch_regulator_pdata = {
709         .name = "gpio-switch-regulator",
710         .id   = -1,
711         .dev  = {
712              .platform_data = &gswitch_pdata,
713         },
714 };
715
716 int __init cardhu_gpio_switch_regulator_init(void)
717 {
718         int i;
719         struct board_info board_info;
720         tegra_get_board_info(&board_info);
721         switch (board_info.board_id) {
722         case BOARD_E1198:
723                 gswitch_pdata.num_subdevs = ARRAY_SIZE(gswitch_subdevs_e1198);
724                 gswitch_pdata.subdevs = gswitch_subdevs_e1198;
725                 break;
726         case BOARD_E1291:
727                 if (board_info.fab >= 0x3) {
728                         gswitch_pdata.num_subdevs =
729                                         ARRAY_SIZE(gswitch_subdevs_e1291_a03);
730                         gswitch_pdata.subdevs = gswitch_subdevs_e1291_a03;
731                         break;
732                 }
733                 gswitch_pdata.num_subdevs = ARRAY_SIZE(gswitch_subdevs_e1198);
734                 gswitch_pdata.subdevs = gswitch_subdevs_e1198;
735                 break;
736         default:
737                 gswitch_pdata.num_subdevs = ARRAY_SIZE(gswitch_subdevs_e118x);
738                 gswitch_pdata.subdevs = gswitch_subdevs_e118x;
739                 break;
740         }
741
742         for (i = 0; i < gswitch_pdata.num_subdevs; ++i) {
743                 struct gpio_switch_regulator_subdev_data *gswitch_data = gswitch_pdata.subdevs[i];
744                 if (gswitch_data->gpio_nr <= TEGRA_NR_GPIOS)
745                         tegra_gpio_enable(gswitch_data->gpio_nr);
746         }
747
748         return platform_device_register(&gswitch_regulator_pdata);
749 }
750
751 static struct tegra_suspend_platform_data cardhu_suspend_data = {
752         .cpu_timer      = 2000,
753         .cpu_off_timer  = 200,
754         .suspend_mode   = TEGRA_SUSPEND_LP1,
755         .core_timer     = 0x7e7e,
756         .core_off_timer = 0,
757         .separate_req   = true,
758         .corereq_high   = false,
759         .sysclkreq_high = true,
760         .wake_enb       = TEGRA_WAKE_GPIO_PV0 | TEGRA_WAKE_PWR_INT | TEGRA_WAKE_RTC_ALARM,
761         .wake_high      = TEGRA_WAKE_RTC_ALARM,
762         .wake_low       = TEGRA_WAKE_GPIO_PV0 | TEGRA_WAKE_PWR_INT,
763         .wake_any       = 0,
764         .cpu_lp2_min_residency = 2000,
765 };
766
767 int __init cardhu_suspend_init(void)
768 {
769         struct board_info board_info;
770
771         tegra_get_board_info(&board_info);
772         switch (board_info.board_id) {
773         case BOARD_E1291:
774                 /* CORE_PWR_REQ to be high for E1291-A03 */
775                 if (board_info.fab == 0x3)
776                         cardhu_suspend_data.corereq_high = true;
777                 break;
778         case BOARD_E1198:
779                 break;
780         case BOARD_PM269:
781         case BOARD_E1187:
782         case BOARD_E1186:
783                 cardhu_suspend_data.cpu_timer = 5000;
784                 cardhu_suspend_data.cpu_off_timer = 5000;
785                 break;
786         default:
787                 break;
788         }
789
790         tegra_init_suspend(&cardhu_suspend_data);
791         return 0;
792 }
793
794 static void cardhu_power_off(void)
795 {
796         int ret;
797         pr_err("cardhu: Powering off the device\n");
798         ret = tps6591x_power_off();
799         if (ret)
800                 pr_err("cardhu: failed to power off\n");
801
802         while(1);
803 }
804
805 int __init cardhu_power_off_init(void)
806 {
807         pm_power_off = cardhu_power_off;
808         return 0;
809 }
810