arm: tegra: cardhu: Use fixed regulator
[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/mfd/max77663-core.h>
27 #include <linux/gpio.h>
28 #include <linux/io.h>
29 #include <linux/regulator/gpio-switch-regulator.h>
30 #include <linux/regulator/fixed.h>
31 #include <linux/regulator/tps6591x-regulator.h>
32 #include <linux/regulator/tps6236x-regulator.h>
33 #include <linux/power/gpio-charger.h>
34
35 #include <asm/mach-types.h>
36
37 #include <mach/iomap.h>
38 #include <mach/irqs.h>
39 #include <mach/pinmux.h>
40 #include <mach/edp.h>
41
42 #include "gpio-names.h"
43 #include "board.h"
44 #include "board-cardhu.h"
45 #include "pm.h"
46 #include "wakeups-t3.h"
47 #include "tegra3_tsensor.h"
48
49 #define PMC_CTRL                0x0
50 #define PMC_CTRL_INTR_LOW       (1 << 17)
51
52 static bool is_cardhu_machine = false;
53
54 static struct regulator_consumer_supply tps6591x_vdd1_supply_skubit0_0[] = {
55         REGULATOR_SUPPLY("vdd_core", NULL),
56         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
57 };
58
59 static struct regulator_consumer_supply tps6591x_vdd1_supply_skubit0_1[] = {
60         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
61 };
62
63 static struct regulator_consumer_supply tps6591x_vdd2_supply_0[] = {
64         REGULATOR_SUPPLY("vdd_gen1v5", NULL),
65         REGULATOR_SUPPLY("vcore_lcd", NULL),
66         REGULATOR_SUPPLY("track_ldo1", NULL),
67         REGULATOR_SUPPLY("external_ldo_1v2", NULL),
68         REGULATOR_SUPPLY("vcore_cam1", NULL),
69         REGULATOR_SUPPLY("vcore_cam2", NULL),
70 };
71
72 static struct regulator_consumer_supply tps6591x_vddctrl_supply_0[] = {
73         REGULATOR_SUPPLY("vdd_cpu_pmu", NULL),
74         REGULATOR_SUPPLY("vdd_cpu", NULL),
75         REGULATOR_SUPPLY("vdd_sys", NULL),
76 };
77
78 static struct regulator_consumer_supply tps6591x_vio_supply_0[] = {
79         REGULATOR_SUPPLY("vdd_gen1v8", NULL),
80         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
81         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
82         REGULATOR_SUPPLY("avdd_osc", NULL),
83         REGULATOR_SUPPLY("vddio_sys", NULL),
84         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.3"),
85         REGULATOR_SUPPLY("pwrdet_sdmmc4", NULL),
86         REGULATOR_SUPPLY("vdd1v8_satelite", NULL),
87         REGULATOR_SUPPLY("vddio_uart", NULL),
88         REGULATOR_SUPPLY("pwrdet_uart", NULL),
89         REGULATOR_SUPPLY("vddio_audio", NULL),
90         REGULATOR_SUPPLY("pwrdet_audio", NULL),
91         REGULATOR_SUPPLY("vddio_bb", NULL),
92         REGULATOR_SUPPLY("pwrdet_bb", NULL),
93         REGULATOR_SUPPLY("vddio_lcd_pmu", NULL),
94         REGULATOR_SUPPLY("pwrdet_lcd", NULL),
95         REGULATOR_SUPPLY("vddio_cam", NULL),
96         REGULATOR_SUPPLY("pwrdet_cam", NULL),
97         REGULATOR_SUPPLY("vddio_vi", NULL),
98         REGULATOR_SUPPLY("pwrdet_vi", NULL),
99         REGULATOR_SUPPLY("ldo6", NULL),
100         REGULATOR_SUPPLY("ldo7", NULL),
101         REGULATOR_SUPPLY("ldo8", NULL),
102         REGULATOR_SUPPLY("vcore_audio", NULL),
103         REGULATOR_SUPPLY("avcore_audio", NULL),
104         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.2"),
105         REGULATOR_SUPPLY("pwrdet_sdmmc3", NULL),
106         REGULATOR_SUPPLY("vcore1_lpddr2", NULL),
107         REGULATOR_SUPPLY("vcom_1v8", NULL),
108         REGULATOR_SUPPLY("pmuio_1v8", NULL),
109         REGULATOR_SUPPLY("avdd_ic_usb", NULL),
110 };
111
112 static struct regulator_consumer_supply tps6591x_ldo1_supply_0[] = {
113         REGULATOR_SUPPLY("avdd_pexb", NULL),
114         REGULATOR_SUPPLY("vdd_pexb", NULL),
115         REGULATOR_SUPPLY("avdd_pex_pll", NULL),
116         REGULATOR_SUPPLY("avdd_pexa", NULL),
117         REGULATOR_SUPPLY("vdd_pexa", NULL),
118 };
119
120 static struct regulator_consumer_supply tps6591x_ldo2_supply_0[] = {
121         REGULATOR_SUPPLY("avdd_sata", NULL),
122         REGULATOR_SUPPLY("vdd_sata", NULL),
123         REGULATOR_SUPPLY("avdd_sata_pll", NULL),
124         REGULATOR_SUPPLY("avdd_plle", NULL),
125 };
126
127 static struct regulator_consumer_supply tps6591x_ldo3_supply_e118x[] = {
128         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.0"),
129         REGULATOR_SUPPLY("pwrdet_sdmmc1", NULL),
130 };
131
132 static struct regulator_consumer_supply tps6591x_ldo3_supply_e1198[] = {
133         REGULATOR_SUPPLY("unused_rail_ldo3", NULL),
134 };
135
136 static struct regulator_consumer_supply tps6591x_ldo4_supply_0[] = {
137         REGULATOR_SUPPLY("vdd_rtc", NULL),
138 };
139
140 static struct regulator_consumer_supply tps6591x_ldo5_supply_e118x[] = {
141         REGULATOR_SUPPLY("avdd_vdac", NULL),
142 };
143
144 static struct regulator_consumer_supply tps6591x_ldo5_supply_e1198[] = {
145         REGULATOR_SUPPLY("avdd_vdac", NULL),
146         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.0"),
147         REGULATOR_SUPPLY("pwrdet_sdmmc1", NULL),
148 };
149
150 static struct regulator_consumer_supply tps6591x_ldo6_supply_0[] = {
151         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
152         REGULATOR_SUPPLY("pwrdet_mipi", NULL),
153 };
154 static struct regulator_consumer_supply tps6591x_ldo7_supply_0[] = {
155         REGULATOR_SUPPLY("avdd_plla_p_c_s", NULL),
156         REGULATOR_SUPPLY("avdd_pllm", NULL),
157         REGULATOR_SUPPLY("avdd_pllu_d", NULL),
158         REGULATOR_SUPPLY("avdd_pllu_d2", NULL),
159         REGULATOR_SUPPLY("avdd_pllx", NULL),
160 };
161
162 static struct regulator_consumer_supply tps6591x_ldo8_supply_0[] = {
163         REGULATOR_SUPPLY("vdd_ddr_hs", NULL),
164 };
165
166 #define TPS_PDATA_INIT(_name, _sname, _minmv, _maxmv, _supply_reg, _always_on, \
167         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply, _ectrl, _flags) \
168         static struct tps6591x_regulator_platform_data pdata_##_name##_##_sname = \
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_##_name##_supply_##_sname), \
185                         .consumer_supplies = tps6591x_##_name##_supply_##_sname,        \
186                         .supply_regulator = _supply_reg,                \
187                 },                                                      \
188                 .init_uV =  _init_uV * 1000,                            \
189                 .init_enable = _init_enable,                            \
190                 .init_apply = _init_apply,                              \
191                 .ectrl = _ectrl,                                        \
192                 .flags = _flags,                                        \
193         }
194
195 TPS_PDATA_INIT(vdd1, skubit0_0, 600,  1500, 0, 1, 1, 0, -1, 0, 0, EXT_CTRL_SLEEP_OFF, 0);
196 TPS_PDATA_INIT(vdd1, skubit0_1, 600,  1500, 0, 1, 1, 0, -1, 0, 0, EXT_CTRL_SLEEP_OFF, 0);
197 TPS_PDATA_INIT(vdd2, 0,         600,  1500, 0, 1, 1, 0, -1, 0, 0, 0, 0);
198 TPS_PDATA_INIT(vddctrl, 0,      600,  1400, 0, 1, 1, 0, -1, 0, 0, EXT_CTRL_EN1, 0);
199 TPS_PDATA_INIT(vio,  0,         1500, 3300, 0, 1, 1, 0, -1, 0, 0, 0, 0);
200
201 TPS_PDATA_INIT(ldo1, 0,         1000, 3300, tps6591x_rails(VDD_2), 0, 0, 0, -1, 0, 1, 0, 0);
202 TPS_PDATA_INIT(ldo2, 0,         1050, 1050, tps6591x_rails(VDD_2), 0, 0, 1, -1, 0, 1, 0, 0);
203
204 TPS_PDATA_INIT(ldo3, e118x,     1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0);
205 TPS_PDATA_INIT(ldo3, e1198,     1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0);
206 TPS_PDATA_INIT(ldo4, 0,         1000, 3300, 0, 1, 0, 0, -1, 0, 0, 0, 0);
207 TPS_PDATA_INIT(ldo5, e118x,     1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0);
208 TPS_PDATA_INIT(ldo5, e1198,     1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0);
209
210 TPS_PDATA_INIT(ldo6, 0,         1200, 1200, tps6591x_rails(VIO), 0, 0, 1, -1, 0, 0, 0, 0);
211 TPS_PDATA_INIT(ldo7, 0,         1200, 1200, tps6591x_rails(VIO), 1, 1, 1, -1, 0, 0, EXT_CTRL_SLEEP_OFF, LDO_LOW_POWER_ON_SUSPEND);
212 TPS_PDATA_INIT(ldo8, 0,         1000, 3300, tps6591x_rails(VIO), 1, 0, 0, -1, 0, 0, EXT_CTRL_SLEEP_OFF, LDO_LOW_POWER_ON_SUSPEND);
213
214 #if defined(CONFIG_RTC_DRV_TPS6591x)
215 static struct tps6591x_rtc_platform_data rtc_data = {
216         .irq = TEGRA_NR_IRQS + TPS6591X_INT_RTC_ALARM,
217         .time = {
218                 .tm_year = 2000,
219                 .tm_mon = 0,
220                 .tm_mday = 1,
221                 .tm_hour = 0,
222                 .tm_min = 0,
223                 .tm_sec = 0,
224         },
225 };
226
227 #define TPS_RTC_REG()                                   \
228         {                                               \
229                 .id     = 0,                            \
230                 .name   = "rtc_tps6591x",               \
231                 .platform_data = &rtc_data,             \
232         }
233 #endif
234
235 #define TPS_REG(_id, _name, _sname)                             \
236         {                                                       \
237                 .id     = TPS6591X_ID_##_id,                    \
238                 .name   = "tps6591x-regulator",                 \
239                 .platform_data  = &pdata_##_name##_##_sname,    \
240         }
241
242 #define TPS6591X_DEV_COMMON_E118X               \
243         TPS_REG(VDD_2, vdd2, 0),                \
244         TPS_REG(VDDCTRL, vddctrl, 0),           \
245         TPS_REG(LDO_1, ldo1, 0),                \
246         TPS_REG(LDO_2, ldo2, 0),                \
247         TPS_REG(LDO_3, ldo3, e118x),            \
248         TPS_REG(LDO_4, ldo4, 0),                \
249         TPS_REG(LDO_5, ldo5, e118x),            \
250         TPS_REG(LDO_6, ldo6, 0),                \
251         TPS_REG(LDO_7, ldo7, 0),                \
252         TPS_REG(LDO_8, ldo8, 0)
253
254 static struct tps6591x_subdev_info tps_devs_e118x_skubit0_0[] = {
255         TPS_REG(VIO, vio, 0),
256         TPS_REG(VDD_1, vdd1, skubit0_0),
257         TPS6591X_DEV_COMMON_E118X,
258 #if defined(CONFIG_RTC_DRV_TPS6591x)
259         TPS_RTC_REG(),
260 #endif
261 };
262
263 static struct tps6591x_subdev_info tps_devs_e118x_skubit0_1[] = {
264         TPS_REG(VIO, vio, 0),
265         TPS_REG(VDD_1, vdd1, skubit0_1),
266         TPS6591X_DEV_COMMON_E118X,
267 #if defined(CONFIG_RTC_DRV_TPS6591x)
268         TPS_RTC_REG(),
269 #endif
270 };
271
272 #define TPS6591X_DEV_COMMON_CARDHU              \
273         TPS_REG(VDD_2, vdd2, 0),                \
274         TPS_REG(VDDCTRL, vddctrl, 0),           \
275         TPS_REG(LDO_1, ldo1, 0),                \
276         TPS_REG(LDO_2, ldo2, 0),                \
277         TPS_REG(LDO_3, ldo3, e1198),            \
278         TPS_REG(LDO_4, ldo4, 0),                \
279         TPS_REG(LDO_5, ldo5, e1198),            \
280         TPS_REG(LDO_6, ldo6, 0),                \
281         TPS_REG(LDO_7, ldo7, 0),                \
282         TPS_REG(LDO_8, ldo8, 0)
283
284 static struct tps6591x_subdev_info tps_devs_e1198_skubit0_0[] = {
285         TPS_REG(VIO, vio, 0),
286         TPS_REG(VDD_1, vdd1, skubit0_0),
287         TPS6591X_DEV_COMMON_CARDHU,
288 #if defined(CONFIG_RTC_DRV_TPS6591x)
289         TPS_RTC_REG(),
290 #endif
291 };
292
293 static struct tps6591x_subdev_info tps_devs_e1198_skubit0_1[] = {
294         TPS_REG(VIO, vio, 0),
295         TPS_REG(VDD_1, vdd1, skubit0_1),
296         TPS6591X_DEV_COMMON_CARDHU,
297 #if defined(CONFIG_RTC_DRV_TPS6591x)
298         TPS_RTC_REG(),
299 #endif
300 };
301
302 #define TPS_GPIO_INIT_PDATA(gpio_nr, _init_apply, _sleep_en, _pulldn_en, _output_en, _output_val)       \
303         [gpio_nr] = {                                   \
304                         .sleep_en       = _sleep_en,    \
305                         .pulldn_en      = _pulldn_en,   \
306                         .output_mode_en = _output_en,   \
307                         .output_val     = _output_val,  \
308                         .init_apply     = _init_apply,  \
309                      }
310 static struct tps6591x_gpio_init_data tps_gpio_pdata_e1291_a04[] =  {
311         TPS_GPIO_INIT_PDATA(0, 0, 0, 0, 0, 0),
312         TPS_GPIO_INIT_PDATA(1, 0, 0, 0, 0, 0),
313         TPS_GPIO_INIT_PDATA(2, 1, 1, 0, 1, 1),
314         TPS_GPIO_INIT_PDATA(3, 0, 0, 0, 0, 0),
315         TPS_GPIO_INIT_PDATA(4, 0, 0, 0, 0, 0),
316         TPS_GPIO_INIT_PDATA(5, 0, 0, 0, 0, 0),
317         TPS_GPIO_INIT_PDATA(6, 0, 0, 0, 0, 0),
318         TPS_GPIO_INIT_PDATA(7, 0, 0, 0, 0, 0),
319         TPS_GPIO_INIT_PDATA(8, 0, 0, 0, 0, 0),
320 };
321
322 static struct tps6591x_sleep_keepon_data tps_slp_keepon = {
323         .clkout32k_keepon = 1,
324 };
325
326 static struct tps6591x_platform_data tps_platform = {
327         .irq_base       = TPS6591X_IRQ_BASE,
328         .gpio_base      = TPS6591X_GPIO_BASE,
329         .dev_slp_en     = true,
330         .slp_keepon     = &tps_slp_keepon,
331 };
332
333 static struct i2c_board_info __initdata cardhu_regulators[] = {
334         {
335                 I2C_BOARD_INFO("tps6591x", 0x2D),
336                 .irq            = INT_EXTERNAL_PMU,
337                 .platform_data  = &tps_platform,
338         },
339 };
340
341 /* TPS62361B DC-DC converter */
342 static struct regulator_consumer_supply tps6236x_dcdc_supply[] = {
343         REGULATOR_SUPPLY("vdd_core", NULL),
344 };
345
346 static struct tps6236x_regulator_platform_data tps6236x_pdata = {
347         .reg_init_data = {                                      \
348                 .constraints = {                                \
349                         .min_uV = 500000,                       \
350                         .max_uV = 1770000,                      \
351                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |  \
352                                              REGULATOR_MODE_STANDBY), \
353                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |    \
354                                            REGULATOR_CHANGE_STATUS |  \
355                                            REGULATOR_CHANGE_VOLTAGE), \
356                         .always_on = 1,                         \
357                         .boot_on =  1,                          \
358                         .apply_uV = 0,                          \
359                 },                                              \
360                 .num_consumer_supplies = ARRAY_SIZE(tps6236x_dcdc_supply), \
361                 .consumer_supplies = tps6236x_dcdc_supply,              \
362                 },                                                      \
363         .internal_pd_enable = 0,                                        \
364         .enable_discharge = true,                                       \
365         .vsel = 3,                                                      \
366         .init_uV = -1,                                                  \
367         .init_apply = 0,                                                \
368 };
369
370 static struct i2c_board_info __initdata tps6236x_boardinfo[] = {
371         {
372                 I2C_BOARD_INFO("tps62361B", 0x60),
373                 .platform_data  = &tps6236x_pdata,
374         },
375 };
376
377 int __init cardhu_regulator_init(void)
378 {
379         struct board_info board_info;
380         struct board_info pmu_board_info;
381         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
382         u32 pmc_ctrl;
383
384         /* configure the power management controller to trigger PMU
385          * interrupts when low */
386
387         pmc_ctrl = readl(pmc + PMC_CTRL);
388         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
389
390         tegra_get_board_info(&board_info);
391         tegra_get_pmu_board_info(&pmu_board_info);
392
393         if (pmu_board_info.board_id == BOARD_PMU_PM298)
394                 return cardhu_pm298_regulator_init();
395
396         if (pmu_board_info.board_id == BOARD_PMU_PM299)
397                 return cardhu_pm299_regulator_init();
398
399         /* The regulator details have complete constraints */
400         regulator_has_full_constraints();
401
402         /* PMU-E1208, the ldo2 should be set to 1200mV */
403         if (pmu_board_info.board_id == BOARD_E1208) {
404                 pdata_ldo2_0.regulator.constraints.min_uV = 1200000;
405                 pdata_ldo2_0.regulator.constraints.max_uV = 1200000;
406         }
407
408         if ((board_info.board_id == BOARD_E1198) ||
409                 (board_info.board_id == BOARD_E1291)) {
410                 if (board_info.sku & SKU_DCDC_TPS62361_SUPPORT) {
411                         tps_platform.num_subdevs =
412                                         ARRAY_SIZE(tps_devs_e1198_skubit0_1);
413                         tps_platform.subdevs = tps_devs_e1198_skubit0_1;
414                 } else {
415                         tps_platform.num_subdevs =
416                                         ARRAY_SIZE(tps_devs_e1198_skubit0_0);
417                         tps_platform.subdevs = tps_devs_e1198_skubit0_0;
418                 }
419         } else {
420                 if (board_info.board_id == BOARD_PM269)
421                         pdata_ldo3_e118x.slew_rate_uV_per_us = 250;
422
423                 if (pmu_board_info.sku & SKU_DCDC_TPS62361_SUPPORT) {
424                         tps_platform.num_subdevs = ARRAY_SIZE(tps_devs_e118x_skubit0_1);
425                         tps_platform.subdevs = tps_devs_e118x_skubit0_1;
426                 } else {
427                         tps_platform.num_subdevs = ARRAY_SIZE(tps_devs_e118x_skubit0_0);
428                         tps_platform.subdevs = tps_devs_e118x_skubit0_0;
429                 }
430         }
431
432         /* E1291-A04/A05: Enable DEV_SLP and enable sleep on GPIO2 */
433         if ((board_info.board_id == BOARD_E1291) &&
434                         ((board_info.fab == BOARD_FAB_A04) ||
435                          (board_info.fab == BOARD_FAB_A05))) {
436                 tps_platform.dev_slp_en = true;
437                 tps_platform.gpio_init_data = tps_gpio_pdata_e1291_a04;
438                 tps_platform.num_gpioinit_data =
439                                         ARRAY_SIZE(tps_gpio_pdata_e1291_a04);
440         }
441
442         i2c_register_board_info(4, cardhu_regulators, 1);
443
444         /* Resgister the TPS6236x for all boards whose sku bit 0 is set. */
445         if ((board_info.sku & SKU_DCDC_TPS62361_SUPPORT) ||
446                         (pmu_board_info.sku & SKU_DCDC_TPS62361_SUPPORT)) {
447                 pr_info("Registering the device TPS62361B\n");
448                 i2c_register_board_info(4, tps6236x_boardinfo, 1);
449         }
450         is_cardhu_machine = true;
451         return 0;
452 }
453
454
455 /**************** GPIO based fixed regulator *****************/
456 /* EN_5V_CP from PMU GP0 */
457 static struct regulator_consumer_supply fixed_reg_en_5v_cp_supply[] = {
458         REGULATOR_SUPPLY("vdd_5v0_sby", NULL),
459         REGULATOR_SUPPLY("vdd_hall", NULL),
460         REGULATOR_SUPPLY("vterm_ddr", NULL),
461         REGULATOR_SUPPLY("v2ref_ddr", NULL),
462 };
463
464 /* EN_5V0 From PMU GP2 */
465 static struct regulator_consumer_supply fixed_reg_en_5v0_supply[] = {
466         REGULATOR_SUPPLY("vdd_5v0_sys", NULL),
467 };
468
469 /* EN_DDR From PMU GP6 */
470 static struct regulator_consumer_supply fixed_reg_en_ddr_supply[] = {
471         REGULATOR_SUPPLY("mem_vddio_ddr", NULL),
472         REGULATOR_SUPPLY("t30_vddio_ddr", NULL),
473 };
474
475 /* EN_3V3_SYS From PMU GP7 */
476 static struct regulator_consumer_supply fixed_reg_en_3v3_sys_supply[] = {
477         REGULATOR_SUPPLY("vdd_lvds", NULL),
478         REGULATOR_SUPPLY("vdd_pnl", NULL),
479         REGULATOR_SUPPLY("vcom_3v3", NULL),
480         REGULATOR_SUPPLY("vdd_3v3", NULL),
481         REGULATOR_SUPPLY("vcore_mmc", NULL),
482         REGULATOR_SUPPLY("vddio_pex_ctl", NULL),
483         REGULATOR_SUPPLY("pwrdet_pex_ctl", NULL),
484         REGULATOR_SUPPLY("hvdd_pex_pmu", NULL),
485         REGULATOR_SUPPLY("avdd_hdmi", NULL),
486         REGULATOR_SUPPLY("vpp_fuse", NULL),
487         REGULATOR_SUPPLY("avdd_usb", NULL),
488         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
489         REGULATOR_SUPPLY("vcore_nand", NULL),
490         REGULATOR_SUPPLY("hvdd_sata", NULL),
491         REGULATOR_SUPPLY("vddio_gmi_pmu", NULL),
492         REGULATOR_SUPPLY("pwrdet_nand", NULL),
493         REGULATOR_SUPPLY("avdd_cam1", NULL),
494         REGULATOR_SUPPLY("vdd_af", NULL),
495         REGULATOR_SUPPLY("avdd_cam2", NULL),
496         REGULATOR_SUPPLY("vdd_acc", NULL),
497         REGULATOR_SUPPLY("vdd_phtl", NULL),
498         REGULATOR_SUPPLY("vddio_tp", NULL),
499         REGULATOR_SUPPLY("vdd_led", NULL),
500         REGULATOR_SUPPLY("vddio_cec", NULL),
501         REGULATOR_SUPPLY("vdd_cmps", NULL),
502         REGULATOR_SUPPLY("vdd_temp", NULL),
503         REGULATOR_SUPPLY("vpp_kfuse", NULL),
504         REGULATOR_SUPPLY("vddio_ts", NULL),
505         REGULATOR_SUPPLY("vdd_ir_led", NULL),
506         REGULATOR_SUPPLY("vddio_1wire", NULL),
507         REGULATOR_SUPPLY("avddio_audio", NULL),
508         REGULATOR_SUPPLY("vdd_ec", NULL),
509         REGULATOR_SUPPLY("vcom_pa", NULL),
510         REGULATOR_SUPPLY("vdd_3v3_devices", NULL),
511         REGULATOR_SUPPLY("vdd_3v3_dock", NULL),
512         REGULATOR_SUPPLY("vdd_3v3_edid", NULL),
513         REGULATOR_SUPPLY("vdd_3v3_hdmi_cec", NULL),
514         REGULATOR_SUPPLY("vdd_3v3_gmi", NULL),
515         REGULATOR_SUPPLY("vdd_spk_amp", "tegra-snd-wm8903"),
516         REGULATOR_SUPPLY("vdd_3v3_sensor", NULL),
517         REGULATOR_SUPPLY("vdd_3v3_cam", NULL),
518         REGULATOR_SUPPLY("vdd_3v3_als", NULL),
519         REGULATOR_SUPPLY("debug_cons", NULL),
520         REGULATOR_SUPPLY("vdd", "4-004c"),
521 };
522
523 /* DIS_5V_SWITCH from AP SPI2_SCK X02 */
524 static struct regulator_consumer_supply fixed_reg_dis_5v_switch_supply[] = {
525         REGULATOR_SUPPLY("master_5v_switch", NULL),
526 };
527
528 /* EN_VDD_BL */
529 static struct regulator_consumer_supply fixed_reg_en_vdd_bl_supply[] = {
530         REGULATOR_SUPPLY("vdd_backlight", NULL),
531         REGULATOR_SUPPLY("vdd_backlight1", NULL),
532 };
533
534 /* EN_VDD_BL2 (E1291-A03) from AP PEX_L0_PRSNT_N DD.00 */
535 static struct regulator_consumer_supply fixed_reg_en_vdd_bl2_supply[] = {
536         REGULATOR_SUPPLY("vdd_backlight2", NULL),
537 };
538
539 /* EN_3V3_MODEM from AP GPIO VI_VSYNCH D06*/
540 static struct regulator_consumer_supply fixed_reg_en_3v3_modem_supply[] = {
541         REGULATOR_SUPPLY("vdd_3v3_mini_card", NULL),
542         REGULATOR_SUPPLY("vdd_mini_card", NULL),
543 };
544
545 /* EN_VDD_PNL1 from AP GPIO VI_D6 L04*/
546 static struct regulator_consumer_supply fixed_reg_en_vdd_pnl1_supply[] = {
547         REGULATOR_SUPPLY("vdd_lcd_panel", NULL),
548 };
549
550 /* CAM1_LDO_EN from AP GPIO KB_ROW6 R06*/
551 static struct regulator_consumer_supply fixed_reg_cam1_ldo_en_supply[] = {
552         REGULATOR_SUPPLY("vdd_2v8_cam1", NULL),
553         REGULATOR_SUPPLY("vdd", "6-0072"),
554 };
555
556 /* CAM2_LDO_EN from AP GPIO KB_ROW7 R07*/
557 static struct regulator_consumer_supply fixed_reg_cam2_ldo_en_supply[] = {
558         REGULATOR_SUPPLY("vdd_2v8_cam2", NULL),
559         REGULATOR_SUPPLY("vdd", "7-0072"),
560 };
561
562 /* CAM3_LDO_EN from AP GPIO KB_ROW8 S00*/
563 static struct regulator_consumer_supply fixed_reg_cam3_ldo_en_supply[] = {
564         REGULATOR_SUPPLY("vdd_cam3", NULL),
565 };
566
567 /* EN_VDD_COM from AP GPIO SDMMC3_DAT5 D00*/
568 static struct regulator_consumer_supply fixed_reg_en_vdd_com_supply[] = {
569         REGULATOR_SUPPLY("vdd_com_bd", NULL),
570 };
571
572 /* EN_VDD_SDMMC1 from AP GPIO VI_HSYNC D07*/
573 static struct regulator_consumer_supply fixed_reg_en_vdd_sdmmc1_supply[] = {
574         REGULATOR_SUPPLY("vddio_sd_slot", "sdhci-tegra.0"),
575 };
576
577 /* EN_3V3_EMMC from AP GPIO SDMMC3_DAT4 D01*/
578 static struct regulator_consumer_supply fixed_reg_en_3v3_emmc_supply[] = {
579         REGULATOR_SUPPLY("vdd_emmc_core", NULL),
580 };
581
582 /* EN_3V3_PEX_HVDD from AP GPIO VI_D09 L07*/
583 static struct regulator_consumer_supply fixed_reg_en_3v3_pex_hvdd_supply[] = {
584         REGULATOR_SUPPLY("hvdd_pex", NULL),
585 };
586
587 /* EN_3v3_FUSE from AP GPIO VI_D08 L06*/
588 static struct regulator_consumer_supply fixed_reg_en_3v3_fuse_supply[] = {
589         REGULATOR_SUPPLY("vdd_fuse", NULL),
590 };
591
592 /* EN_1V8_CAM from AP GPIO GPIO_PBB4 PBB04*/
593 static struct regulator_consumer_supply fixed_reg_en_1v8_cam_supply[] = {
594         REGULATOR_SUPPLY("vdd_1v8_cam1", NULL),
595         REGULATOR_SUPPLY("vdd_1v8_cam2", NULL),
596         REGULATOR_SUPPLY("vdd_1v8_cam3", NULL),
597         REGULATOR_SUPPLY("vdd_i2c", "6-0072"),
598         REGULATOR_SUPPLY("vdd_i2c", "7-0072"),
599         REGULATOR_SUPPLY("vdd_i2c", "2-0033"),
600 };
601
602 static struct regulator_consumer_supply fixed_reg_en_vbrtr_supply[] = {
603         REGULATOR_SUPPLY("vdd_vbrtr", NULL),
604 };
605
606 /* EN_USB1_VBUS_OC*/
607 static struct regulator_consumer_supply gpio_switch_en_usb1_vbus_oc_supply[] = {
608         REGULATOR_SUPPLY("vdd_vbus_micro_usb", NULL),
609 };
610 static int gpio_switch_en_usb1_vbus_oc_voltages[] = { 5000};
611
612 /*EN_USB3_VBUS_OC*/
613 static struct regulator_consumer_supply gpio_switch_en_usb3_vbus_oc_supply[] = {
614         REGULATOR_SUPPLY("vdd_vbus_typea_usb", NULL),
615 };
616 static int gpio_switch_en_usb3_vbus_oc_voltages[] = { 5000};
617
618 /* EN_VDDIO_VID_OC from AP GPIO VI_PCLK T00*/
619 static struct regulator_consumer_supply gpio_switch_en_vddio_vid_oc_supply[] = {
620         REGULATOR_SUPPLY("vdd_hdmi_con", NULL),
621 };
622 static int gpio_switch_en_vddio_vid_oc_voltages[] = { 5000};
623
624 static int enable_load_switch_rail(
625                 struct gpio_switch_regulator_subdev_data *psubdev_data)
626 {
627         int ret;
628
629         if (psubdev_data->pin_group <= 0)
630                 return -EINVAL;
631
632         /* Tristate and make pin as input*/
633         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
634                                                 TEGRA_TRI_TRISTATE);
635         if (ret < 0)
636                 return ret;
637         return gpio_direction_input(psubdev_data->gpio_nr);
638 }
639
640 static int disable_load_switch_rail(
641                 struct gpio_switch_regulator_subdev_data *psubdev_data)
642 {
643         int ret;
644
645         if (psubdev_data->pin_group <= 0)
646                 return -EINVAL;
647
648         /* Un-tristate and driver low */
649         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
650                                                 TEGRA_TRI_NORMAL);
651         if (ret < 0)
652                 return ret;
653         return gpio_direction_output(psubdev_data->gpio_nr, 0);
654 }
655
656 /* Macro for defining gpio switch regulator sub device data */
657 #define GREG_INIT(_id, _var, _name, _input_supply, _always_on, _boot_on, \
658         _gpio_nr, _active_low, _init_state, _pg, _enable, _disable)      \
659         static struct gpio_switch_regulator_subdev_data gpio_pdata_##_var =  \
660         {                                                               \
661                 .regulator_name = "gpio-switch-"#_name,                 \
662                 .input_supply   = _input_supply,                        \
663                 .id             = _id,                                  \
664                 .gpio_nr        = _gpio_nr,                             \
665                 .pin_group      = _pg,                                  \
666                 .active_low     = _active_low,                          \
667                 .init_state     = _init_state,                          \
668                 .voltages       = gpio_switch_##_name##_voltages,       \
669                 .n_voltages     = ARRAY_SIZE(gpio_switch_##_name##_voltages), \
670                 .num_consumer_supplies =                                \
671                                 ARRAY_SIZE(gpio_switch_##_name##_supply), \
672                 .consumer_supplies = gpio_switch_##_name##_supply,      \
673                 .constraints = {                                        \
674                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
675                                              REGULATOR_MODE_STANDBY),   \
676                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
677                                            REGULATOR_CHANGE_STATUS |    \
678                                            REGULATOR_CHANGE_VOLTAGE),   \
679                         .always_on = _always_on,                        \
680                         .boot_on = _boot_on,                            \
681                 },                                                      \
682                 .enable_rail = _enable,                                 \
683                 .disable_rail = _disable,                               \
684         };                                                              \
685         static struct gpio_switch_regulator_subdev_data                 \
686                                 *gpio_pdata_##_var##_list[] = { \
687                 &gpio_pdata_##_var,                                     \
688         };                                                              \
689         static struct gpio_switch_regulator_platform_data gs_##_var##_pdata = \
690         {                                                               \
691                 .num_subdevs = 1,                                       \
692                 .subdevs = gpio_pdata_##_var##_list,                    \
693         };                                                              \
694         static struct platform_device gswitch_reg_##_var##_dev = {      \
695                 .name = "gpio-switch-regulator",                        \
696                 .id   = _id,                                            \
697                 .dev  = {                                               \
698                      .platform_data = &gs_##_var##_pdata,               \
699                 },                                                      \
700         }
701
702 /* Macro for defining fixed regulator sub device data */
703 #define FIXED_SUPPLY(_name) "fixed_reg_"#_name
704 #define FIXED_REG(_id, _var, _name, _in_supply, _always_on, _boot_on,   \
705                  _gpio_nr, _active_high, _boot_state, _millivolts)      \
706         static struct regulator_init_data ri_data_##_var =              \
707         {                                                               \
708                 .supply_regulator = _in_supply,                         \
709                 .num_consumer_supplies =                                \
710                         ARRAY_SIZE(fixed_reg_##_name##_supply),         \
711                 .consumer_supplies = fixed_reg_##_name##_supply,        \
712                 .constraints = {                                        \
713                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
714                                         REGULATOR_MODE_STANDBY),        \
715                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
716                                         REGULATOR_CHANGE_STATUS |       \
717                                         REGULATOR_CHANGE_VOLTAGE),      \
718                         .always_on = _always_on,                        \
719                         .boot_on = _boot_on,                            \
720                 },                                                      \
721         };                                                              \
722         static struct fixed_voltage_config fixed_reg_##_var##_pdata =   \
723         {                                                               \
724                 .supply_name = FIXED_SUPPLY(_name),                     \
725                 .microvolts = _millivolts * 1000,                       \
726                 .gpio = _gpio_nr,                                       \
727                 .enable_high = _active_high,                            \
728                 .enabled_at_boot = _boot_state,                         \
729                 .init_data = &ri_data_##_var,                           \
730         };                                                              \
731         static struct platform_device fixed_reg_##_var##_dev = {        \
732                 .name   = "reg-fixed-voltage",                          \
733                 .id     = _id,                                          \
734                 .dev    = {                                             \
735                         .platform_data = &fixed_reg_##_var##_pdata,     \
736                 },                                                      \
737         }
738
739 /* common to most of boards*/
740 FIXED_REG(0, en_5v_cp,          en_5v_cp,       NULL,                           1,      0,      TPS6591X_GPIO_0,        true,   1, 5000);
741 FIXED_REG(1, en_5v0,            en_5v0,         NULL,                           0,      0,      TPS6591X_GPIO_2,        true,   0, 5000);
742 FIXED_REG(2, en_ddr,            en_ddr,         NULL,                           1,      0,      TPS6591X_GPIO_6,        true,   1, 1500);
743 FIXED_REG(3, en_3v3_sys,        en_3v3_sys,     NULL,                           0,      0,      TPS6591X_GPIO_7,        true,   1, 3300);
744 FIXED_REG(4, en_vdd_bl,         en_vdd_bl,      NULL,                           0,      0,      TEGRA_GPIO_PK3,         true,   1, 5000);
745 FIXED_REG(5, en_3v3_modem,      en_3v3_modem,   NULL,                           1,      0,      TEGRA_GPIO_PD6,         true,   1, 3300);
746 FIXED_REG(6, en_vdd_pnl1,       en_vdd_pnl1,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PL4,         true,   1, 3300);
747 FIXED_REG(7, cam3_ldo_en,       cam3_ldo_en,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PS0,         true,   0, 3300);
748 FIXED_REG(8, en_vdd_com,        en_vdd_com,     FIXED_SUPPLY(en_3v3_sys),       1,      0,      TEGRA_GPIO_PD0,         true,   1, 3300);
749 FIXED_REG(9, en_3v3_fuse,       en_3v3_fuse,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PL6,         true,   0, 3300);
750 FIXED_REG(10, en_3v3_emmc,      en_3v3_emmc,    FIXED_SUPPLY(en_3v3_sys),       1,      0,      TEGRA_GPIO_PD1,         true,   1, 3300);
751 FIXED_REG(11, en_vdd_sdmmc1,    en_vdd_sdmmc1,  FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PD7,         true,   1, 3300);
752 FIXED_REG(12, en_3v3_pex_hvdd,  en_3v3_pex_hvdd, FIXED_SUPPLY(en_3v3_sys),      0,      0,      TEGRA_GPIO_PL7,         true,   0, 3300);
753 FIXED_REG(13, en_1v8_cam,       en_1v8_cam,     tps6591x_rails(VIO),            0,      0,      TEGRA_GPIO_PBB4,        true,   0, 1800);
754
755 /* Specific to E1187/E1186/E1256 */
756 FIXED_REG(14, dis_5v_switch_e118x,      dis_5v_switch,  FIXED_SUPPLY(en_5v0),   0,      0,      TEGRA_GPIO_PX2,         false,  0, 5000);
757
758 /* E1291-A04/A05 specific */
759 FIXED_REG(1, en_5v0_a04,        en_5v0,         NULL,                           0,      0,      TPS6591X_GPIO_8,        true,   0, 5000);
760 FIXED_REG(2, en_ddr_a04,        en_ddr,         NULL,                           1,      0,      TPS6591X_GPIO_7,        true,   1, 1500);
761 FIXED_REG(3, en_3v3_sys_a04,    en_3v3_sys,     NULL,                           0,      0,      TPS6591X_GPIO_6,        true,   1, 3300);
762
763 /* Specific to pm269 */
764 FIXED_REG(4, en_vdd_bl_pm269,           en_vdd_bl,              NULL,                           0,      0,      TEGRA_GPIO_PH3, true,   1, 5000);
765 FIXED_REG(6, en_vdd_pnl1_pm269,         en_vdd_pnl1,            FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PW1, true,   1, 3300);
766 FIXED_REG(9, en_3v3_fuse_pm269,         en_3v3_fuse,            FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PC1, true,   0, 3300);
767 FIXED_REG(12, en_3v3_pex_hvdd_pm269,    en_3v3_pex_hvdd,        FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PC6, true,   0, 3300);
768
769 /* E1198/E1291 specific*/
770 FIXED_REG(18, cam1_ldo_en,      cam1_ldo_en,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PR6,         true,   0, 2800);
771 FIXED_REG(19, cam2_ldo_en,      cam2_ldo_en,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PR7,         true,   0, 2800);
772
773 /* E1291 A03 specific */
774 FIXED_REG(20, en_vdd_bl1_a03,   en_vdd_bl,      NULL,                           0,      0,      TEGRA_GPIO_PDD2,        true,   1, 5000);
775 FIXED_REG(21, en_vdd_bl2_a03,   en_vdd_bl2,     NULL,                           0,      0,      TEGRA_GPIO_PDD0,        true,   1, 5000);
776 FIXED_REG(22, en_vbrtr,         en_vbrtr,       FIXED_SUPPLY(en_3v3_sys),       0,      0,      PMU_TCA6416_GPIO_PORT12,true,   0, 3300);
777
778 /* PM313 display board specific */
779 FIXED_REG(4, en_vdd_bl_pm313,   en_vdd_bl,      NULL,                           0,      0,      TEGRA_GPIO_PK3,         true,  1, 5000);
780 FIXED_REG(6, en_vdd_pnl1_pm313, en_vdd_pnl1,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PH3,         true,  1, 3300);
781
782
783 /****************** Open collector Load switches *******/
784 /*Specific to pm269*/
785 GREG_INIT(17, en_vddio_vid_oc_pm269,    en_vddio_vid_oc,        "master_5v_switch", 0,      0,      TEGRA_GPIO_PP2,     false,  0,      TEGRA_PINGROUP_DAP3_DOUT,
786         enable_load_switch_rail, disable_load_switch_rail);
787
788 /* Specific to pm311 */
789 GREG_INIT(15, en_usb1_vbus_oc_pm311,    en_usb1_vbus_oc,        "master_5v_switch", 0,      0,      TEGRA_GPIO_PCC7,            false,  0,      TEGRA_PINGROUP_GMI_RST_N,
790                 enable_load_switch_rail, disable_load_switch_rail);
791 GREG_INIT(16, en_usb3_vbus_oc_pm311,    en_usb3_vbus_oc,        "master_5v_switch", 0,      0,      TEGRA_GPIO_PCC6,            false,  0,      TEGRA_PINGROUP_GMI_AD15,
792                 enable_load_switch_rail, disable_load_switch_rail);
793
794 /* Specific to E1187/E1186/E1256 */
795 GREG_INIT(15, en_usb1_vbus_oc_e118x,    en_usb1_vbus_oc,        "master_5v_switch", 0,      0,      TEGRA_GPIO_PI4,             false,  0,      TEGRA_PINGROUP_GMI_RST_N,
796                 enable_load_switch_rail, disable_load_switch_rail);
797 GREG_INIT(16, en_usb3_vbus_oc_e118x,    en_usb3_vbus_oc,        "master_5v_switch", 0,      0,      TEGRA_GPIO_PH7,             false,  0,      TEGRA_PINGROUP_GMI_AD15,
798                 enable_load_switch_rail, disable_load_switch_rail);
799 GREG_INIT(17, en_vddio_vid_oc_e118x,    en_vddio_vid_oc,        "master_5v_switch", 0,      0,      TEGRA_GPIO_PT0,             false,  0,      TEGRA_PINGROUP_VI_PCLK,
800                 enable_load_switch_rail, disable_load_switch_rail);
801
802 /* E1198/E1291 specific  fab < A03 */
803 GREG_INIT(15, en_usb1_vbus_oc,          en_usb1_vbus_oc,        "vdd_5v0_sys", 0,      0,      TEGRA_GPIO_PI4,          false,  0,      TEGRA_PINGROUP_GMI_RST_N,
804                 enable_load_switch_rail, disable_load_switch_rail);
805 GREG_INIT(16, en_usb3_vbus_oc,          en_usb3_vbus_oc,        "vdd_5v0_sys", 0,      0,      TEGRA_GPIO_PH7,          false,  0,      TEGRA_PINGROUP_GMI_AD15,
806                 enable_load_switch_rail, disable_load_switch_rail);
807
808 /* E1198/E1291 specific  fab >= A03 */
809 GREG_INIT(15, en_usb1_vbus_oc_a03,      en_usb1_vbus_oc,        "vdd_5v0_sys", 0,      0,      TEGRA_GPIO_PDD6,         false,  0,      TEGRA_PINGROUP_PEX_L1_CLKREQ_N,
810                 enable_load_switch_rail, disable_load_switch_rail);
811 GREG_INIT(16, en_usb3_vbus_oc_a03,      en_usb3_vbus_oc,        "vdd_5v0_sys", 0,      0,      TEGRA_GPIO_PDD4,         false,  0,      TEGRA_PINGROUP_PEX_L1_PRSNT_N,
812                 enable_load_switch_rail, disable_load_switch_rail);
813
814 /* E1198/E1291 specific */
815 GREG_INIT(17, en_vddio_vid_oc,          en_vddio_vid_oc,        "vdd_5v0_sys", 0,      0,      TEGRA_GPIO_PT0,          false,  0,      TEGRA_PINGROUP_VI_PCLK,
816                 enable_load_switch_rail, disable_load_switch_rail);
817
818 /*
819  * Creating the fixed/gpio-switch regulator device tables for different boards
820  */
821 #define ADD_FIXED_REG(_name)    (&fixed_reg_##_name##_dev)
822 #define ADD_GPIO_REG(_name)     (&gswitch_reg_##_name##_dev)
823
824 #define COMMON_FIXED_REG                        \
825         ADD_FIXED_REG(en_5v_cp),                \
826         ADD_FIXED_REG(en_5v0),                  \
827         ADD_FIXED_REG(en_ddr),                  \
828         ADD_FIXED_REG(en_3v3_sys),              \
829         ADD_FIXED_REG(en_3v3_modem),            \
830         ADD_FIXED_REG(en_vdd_pnl1),             \
831         ADD_FIXED_REG(cam3_ldo_en),             \
832         ADD_FIXED_REG(en_vdd_com),              \
833         ADD_FIXED_REG(en_3v3_fuse),             \
834         ADD_FIXED_REG(en_3v3_emmc),             \
835         ADD_FIXED_REG(en_vdd_sdmmc1),           \
836         ADD_FIXED_REG(en_3v3_pex_hvdd),         \
837         ADD_FIXED_REG(en_1v8_cam),
838
839 #define COMMON_FIXED_REG_E1291_A04              \
840         ADD_FIXED_REG(en_5v_cp),                \
841         ADD_FIXED_REG(en_5v0_a04),              \
842         ADD_FIXED_REG(en_ddr_a04),              \
843         ADD_FIXED_REG(en_3v3_sys_a04),          \
844         ADD_FIXED_REG(en_3v3_modem),            \
845         ADD_FIXED_REG(en_vdd_pnl1),             \
846         ADD_FIXED_REG(cam3_ldo_en),             \
847         ADD_FIXED_REG(en_vdd_com),              \
848         ADD_FIXED_REG(en_3v3_fuse),             \
849         ADD_FIXED_REG(en_3v3_emmc),             \
850         ADD_FIXED_REG(en_vdd_sdmmc1),           \
851         ADD_FIXED_REG(en_3v3_pex_hvdd),         \
852         ADD_FIXED_REG(en_1v8_cam),
853
854 #define PM269_FIXED_REG                         \
855         ADD_FIXED_REG(en_5v_cp),                \
856         ADD_FIXED_REG(en_5v0),                  \
857         ADD_FIXED_REG(en_ddr),                  \
858         ADD_FIXED_REG(en_3v3_sys),              \
859         ADD_FIXED_REG(en_3v3_modem),            \
860         ADD_FIXED_REG(cam1_ldo_en),             \
861         ADD_FIXED_REG(cam2_ldo_en),             \
862         ADD_FIXED_REG(cam3_ldo_en),             \
863         ADD_FIXED_REG(en_vdd_com),              \
864         ADD_FIXED_REG(en_3v3_fuse_pm269),       \
865         ADD_FIXED_REG(en_3v3_emmc),             \
866         ADD_FIXED_REG(en_3v3_pex_hvdd_pm269),   \
867         ADD_FIXED_REG(en_1v8_cam),              \
868         ADD_FIXED_REG(dis_5v_switch_e118x),     \
869         ADD_GPIO_REG(en_usb1_vbus_oc_e118x),    \
870         ADD_GPIO_REG(en_usb3_vbus_oc_e118x),    \
871         ADD_GPIO_REG(en_vddio_vid_oc_pm269),
872
873 #define PM311_FIXED_REG                         \
874         ADD_FIXED_REG(en_5v_cp),                \
875         ADD_FIXED_REG(en_5v0),                  \
876         ADD_FIXED_REG(en_ddr),                  \
877         ADD_FIXED_REG(en_3v3_sys),              \
878         ADD_FIXED_REG(en_3v3_modem),            \
879         ADD_FIXED_REG(cam1_ldo_en),             \
880         ADD_FIXED_REG(cam2_ldo_en),             \
881         ADD_FIXED_REG(cam3_ldo_en),             \
882         ADD_FIXED_REG(en_vdd_com),              \
883         ADD_FIXED_REG(en_3v3_fuse_pm269),       \
884         ADD_FIXED_REG(en_3v3_emmc),             \
885         ADD_FIXED_REG(en_3v3_pex_hvdd_pm269),   \
886         ADD_FIXED_REG(en_1v8_cam),              \
887         ADD_FIXED_REG(dis_5v_switch_e118x),     \
888         ADD_GPIO_REG(en_usb1_vbus_oc_pm311),    \
889         ADD_GPIO_REG(en_usb3_vbus_oc_pm311),    \
890         ADD_GPIO_REG(en_vddio_vid_oc_pm269),
891
892
893 #define E1247_DISPLAY_FIXED_REG                 \
894         ADD_FIXED_REG(en_vdd_bl_pm269),         \
895         ADD_FIXED_REG(en_vdd_pnl1_pm269),
896
897 #define PM313_DISPLAY_FIXED_REG                 \
898         ADD_FIXED_REG(en_vdd_bl_pm313),         \
899         ADD_FIXED_REG(en_vdd_pnl1_pm313),
900
901 #define E118x_FIXED_REG                         \
902         ADD_FIXED_REG(en_5v_cp),                \
903         ADD_FIXED_REG(en_5v0),                  \
904         ADD_FIXED_REG(en_ddr),                  \
905         ADD_FIXED_REG(en_3v3_sys),              \
906         ADD_FIXED_REG(en_3v3_modem),            \
907         ADD_FIXED_REG(cam3_ldo_en),             \
908         ADD_FIXED_REG(en_vdd_com),              \
909         ADD_FIXED_REG(en_3v3_fuse),             \
910         ADD_FIXED_REG(en_3v3_emmc),             \
911         ADD_FIXED_REG(en_vdd_sdmmc1),           \
912         ADD_FIXED_REG(en_3v3_pex_hvdd),         \
913         ADD_FIXED_REG(en_1v8_cam),              \
914         ADD_FIXED_REG(dis_5v_switch_e118x),     \
915         ADD_FIXED_REG(en_vbrtr),                \
916         ADD_GPIO_REG(en_usb1_vbus_oc_e118x),    \
917         ADD_GPIO_REG(en_usb3_vbus_oc_e118x),    \
918         ADD_GPIO_REG(en_vddio_vid_oc_e118x),
919
920 #define E1198_FIXED_REG                         \
921         ADD_FIXED_REG(cam1_ldo_en),             \
922         ADD_FIXED_REG(cam2_ldo_en),             \
923         ADD_GPIO_REG(en_vddio_vid_oc),
924
925 #define E1291_1198_A00_FIXED_REG                \
926         ADD_FIXED_REG(en_vdd_bl),               \
927         ADD_GPIO_REG(en_usb1_vbus_oc),          \
928         ADD_GPIO_REG(en_usb3_vbus_oc),
929
930 #define E1291_A03_FIXED_REG                     \
931         ADD_FIXED_REG(en_vdd_bl1_a03),          \
932         ADD_FIXED_REG(en_vdd_bl2_a03),          \
933         ADD_GPIO_REG(en_usb1_vbus_oc_a03),      \
934         ADD_GPIO_REG(en_usb3_vbus_oc_a03),
935
936 /* Fixed regulator devices for E1186/E1187/E1256 */
937 static struct platform_device *fixed_reg_devs_e118x[] = {
938         E118x_FIXED_REG
939         E1247_DISPLAY_FIXED_REG
940 };
941
942 /* Fixed regulator devices for E1186/E1187/E1256 */
943 static struct platform_device *fixed_reg_devs_e118x_pm313[] = {
944         E118x_FIXED_REG
945         PM313_DISPLAY_FIXED_REG
946 };
947
948 /* Fixed regulator devices for E1198 and E1291 */
949 static struct platform_device *fixed_reg_devs_e1198_base[] = {
950         COMMON_FIXED_REG
951         E1291_1198_A00_FIXED_REG
952         E1198_FIXED_REG
953 };
954
955 static struct platform_device *fixed_reg_devs_e1198_a02[] = {
956         ADD_FIXED_REG(en_5v_cp),
957         ADD_FIXED_REG(en_5v0),
958         ADD_FIXED_REG(en_ddr_a04),
959         ADD_FIXED_REG(en_3v3_sys_a04),
960         ADD_FIXED_REG(en_3v3_modem),
961         ADD_FIXED_REG(en_vdd_pnl1),
962         ADD_FIXED_REG(cam3_ldo_en),
963         ADD_FIXED_REG(en_vdd_com),
964         ADD_FIXED_REG(en_3v3_fuse),
965         ADD_FIXED_REG(en_3v3_emmc),
966         ADD_FIXED_REG(en_vdd_sdmmc1),
967         ADD_FIXED_REG(en_3v3_pex_hvdd),
968         ADD_FIXED_REG(en_1v8_cam),
969         ADD_FIXED_REG(en_vdd_bl1_a03),
970         ADD_FIXED_REG(en_vdd_bl2_a03),
971         ADD_FIXED_REG(cam1_ldo_en),
972         ADD_FIXED_REG(cam2_ldo_en),
973         ADD_GPIO_REG(en_usb1_vbus_oc_a03),
974         ADD_GPIO_REG(en_usb3_vbus_oc_a03),
975         ADD_GPIO_REG(en_vddio_vid_oc),
976 };
977
978 /* Fixed regulator devices for PM269 */
979 static struct platform_device *fixed_reg_devs_pm269[] = {
980         PM269_FIXED_REG
981         E1247_DISPLAY_FIXED_REG
982 };
983
984 /* Fixed regulator devices for PM269 */
985 static struct platform_device *fixed_reg_devs_pm269_pm313[] = {
986         PM269_FIXED_REG
987         PM313_DISPLAY_FIXED_REG
988 };
989
990 /* Fixed regulator devices for PM311 */
991 static struct platform_device *fixed_reg_devs_pm311[] = {
992         PM311_FIXED_REG
993         E1247_DISPLAY_FIXED_REG
994 };
995
996 /* Fixed regulator devices for PM11 */
997 static struct platform_device *fixed_reg_devs_pm311_pm313[] = {
998         PM311_FIXED_REG
999         PM313_DISPLAY_FIXED_REG
1000 };
1001
1002 /* Fixed regulator devices for E1291 A03 */
1003 static struct platform_device *fixed_reg_devs_e1291_a03[] = {
1004         COMMON_FIXED_REG
1005         E1291_A03_FIXED_REG
1006         E1198_FIXED_REG
1007 };
1008
1009 /* Fixed regulator devices for E1291 A04/A05 */
1010 static struct platform_device *fixed_reg_devs_e1291_a04[] = {
1011         COMMON_FIXED_REG_E1291_A04
1012         E1291_A03_FIXED_REG
1013         E1198_FIXED_REG
1014 };
1015
1016 int __init cardhu_fixed_regulator_init(void)
1017 {
1018         int i;
1019         struct board_info board_info;
1020         struct board_info pmu_board_info;
1021         struct board_info display_board_info;
1022         struct platform_device **fixed_reg_devs;
1023         int    nfixreg_devs;
1024
1025         if (!is_cardhu_machine)
1026                 return 0;
1027
1028         tegra_get_board_info(&board_info);
1029         tegra_get_pmu_board_info(&pmu_board_info);
1030         tegra_get_display_board_info(&display_board_info);
1031
1032         if (pmu_board_info.board_id == BOARD_PMU_PM298)
1033                 return cardhu_pm298_gpio_switch_regulator_init();
1034
1035         if (pmu_board_info.board_id == BOARD_PMU_PM299)
1036                 return cardhu_pm299_gpio_switch_regulator_init();
1037
1038         switch (board_info.board_id) {
1039         case BOARD_E1198:
1040                 if (board_info.fab <= BOARD_FAB_A01) {
1041                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e1198_base);
1042                         fixed_reg_devs = fixed_reg_devs_e1198_base;
1043                 } else {
1044                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e1198_a02);
1045                         fixed_reg_devs = fixed_reg_devs_e1198_a02;
1046                 }
1047                 break;
1048
1049         case BOARD_E1291:
1050                 if (board_info.fab == BOARD_FAB_A03) {
1051                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e1291_a03);
1052                         fixed_reg_devs = fixed_reg_devs_e1291_a03;
1053                 } else if ((board_info.fab == BOARD_FAB_A04) ||
1054                                 (board_info.fab == BOARD_FAB_A05)) {
1055                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e1291_a04);
1056                         fixed_reg_devs = fixed_reg_devs_e1291_a04;
1057                 } else {
1058                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e1198_base);
1059                         fixed_reg_devs = fixed_reg_devs_e1198_base;
1060                 }
1061                 break;
1062
1063         case BOARD_PM311:
1064         case BOARD_PM305:
1065                 nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_pm311);
1066                 fixed_reg_devs = fixed_reg_devs_pm311;
1067                 if (display_board_info.board_id == BOARD_DISPLAY_PM313) {
1068                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_pm311_pm313);
1069                         fixed_reg_devs = fixed_reg_devs_pm311_pm313;
1070                 }
1071                 break;
1072
1073         case BOARD_PM269:
1074         case BOARD_E1257:
1075                 nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_pm269);
1076                 fixed_reg_devs = fixed_reg_devs_pm269;
1077                 if (display_board_info.board_id == BOARD_DISPLAY_PM313) {
1078                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_pm269_pm313);
1079                         fixed_reg_devs = fixed_reg_devs_pm269_pm313;
1080                 } else {
1081                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_pm269);
1082                         fixed_reg_devs = fixed_reg_devs_pm269;
1083                 }
1084                 break;
1085
1086         default:
1087                 if (display_board_info.board_id == BOARD_DISPLAY_PM313) {
1088                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e118x_pm313);
1089                         fixed_reg_devs = fixed_reg_devs_e118x_pm313;
1090                 } else {
1091                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e118x);
1092                         fixed_reg_devs = fixed_reg_devs_e118x;
1093                 }
1094                 break;
1095         }
1096
1097         for (i = 0; i < nfixreg_devs; ++i) {
1098                 int gpio_nr;
1099                 if (!strncmp(fixed_reg_devs[i]->name, "gpio", 4)) {
1100                         struct gpio_switch_regulator_platform_data *gs_pdata =
1101                                 fixed_reg_devs[i]->dev.platform_data;
1102                         gpio_nr = gs_pdata->subdevs[0]->gpio_nr;
1103                 } else {
1104                         struct fixed_voltage_config *fixed_reg_pdata =
1105                                 fixed_reg_devs[i]->dev.platform_data;
1106                         gpio_nr = fixed_reg_pdata->gpio;
1107                 }
1108
1109                 if (gpio_nr < TEGRA_NR_GPIOS)
1110                         tegra_gpio_enable(gpio_nr);
1111         }
1112         return platform_add_devices(fixed_reg_devs, nfixreg_devs);
1113 }
1114 subsys_initcall_sync(cardhu_fixed_regulator_init);
1115
1116 static void cardhu_board_suspend(int lp_state, enum suspend_stage stg)
1117 {
1118         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_SUSPEND_BEFORE_CPU))
1119                 tegra_console_uart_suspend();
1120 }
1121
1122 static void cardhu_board_resume(int lp_state, enum resume_stage stg)
1123 {
1124         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_RESUME_AFTER_CPU))
1125                 tegra_console_uart_resume();
1126 }
1127
1128 static struct tegra_suspend_platform_data cardhu_suspend_data = {
1129         .cpu_timer      = 2000,
1130         .cpu_off_timer  = 200,
1131         .suspend_mode   = TEGRA_SUSPEND_LP0,
1132         .core_timer     = 0x7e7e,
1133         .core_off_timer = 0,
1134         .corereq_high   = true,
1135         .sysclkreq_high = true,
1136         .cpu_lp2_min_residency = 2000,
1137         .board_suspend = cardhu_board_suspend,
1138         .board_resume = cardhu_board_resume,
1139 };
1140
1141 int __init cardhu_suspend_init(void)
1142 {
1143         struct board_info board_info;
1144         struct board_info pmu_board_info;
1145
1146         tegra_get_board_info(&board_info);
1147         tegra_get_pmu_board_info(&pmu_board_info);
1148
1149         /* For PMU Fab A03, A04 and A05 make core_pwr_req to high */
1150         if ((pmu_board_info.fab == BOARD_FAB_A03) ||
1151                 (pmu_board_info.fab == BOARD_FAB_A04) ||
1152                  (pmu_board_info.fab == BOARD_FAB_A05))
1153                 cardhu_suspend_data.corereq_high = true;
1154
1155         /* CORE_PWR_REQ to be high for all processor/pmu board whose sku bit 0
1156          * is set. This is require to enable the dc-dc converter tps62361x */
1157         if ((board_info.sku & SKU_DCDC_TPS62361_SUPPORT) || (pmu_board_info.sku & SKU_DCDC_TPS62361_SUPPORT))
1158                 cardhu_suspend_data.corereq_high = true;
1159
1160         switch (board_info.board_id) {
1161         case BOARD_E1291:
1162                 /* CORE_PWR_REQ to be high for E1291-A03 */
1163                 if (board_info.fab == BOARD_FAB_A03)
1164                         cardhu_suspend_data.corereq_high = true;
1165                 break;
1166         case BOARD_E1198:
1167         case BOARD_PM269:
1168         case BOARD_PM305:
1169         case BOARD_PM311:
1170                 break;
1171         case BOARD_E1187:
1172         case BOARD_E1186:
1173         case BOARD_E1256:
1174         case BOARD_E1257:
1175                 cardhu_suspend_data.cpu_timer = 5000;
1176                 cardhu_suspend_data.cpu_off_timer = 5000;
1177                 break;
1178         default:
1179                 break;
1180         }
1181
1182         tegra_init_suspend(&cardhu_suspend_data);
1183         return 0;
1184 }
1185
1186 static void cardhu_power_off(void)
1187 {
1188         int ret;
1189         pr_err("cardhu: Powering off the device\n");
1190         ret = tps6591x_power_off();
1191         if (ret)
1192                 pr_err("cardhu: failed to power off\n");
1193
1194         while (1);
1195 }
1196
1197 static void cardhu_pm298_power_off(void)
1198 {
1199         int ret;
1200         pr_err("cardhu-pm298: Powering off the device\n");
1201         ret = max77663_power_off();
1202         if (ret)
1203                 pr_err("cardhu-pm298: failed to power off\n");
1204
1205         while (1);
1206 }
1207
1208 int __init cardhu_power_off_init(void)
1209 {
1210         struct board_info pmu_board_info;
1211
1212         tegra_get_pmu_board_info(&pmu_board_info);
1213
1214         if (pmu_board_info.board_id == BOARD_PMU_PM298)
1215                 pm_power_off = cardhu_pm298_power_off;
1216         else
1217                 pm_power_off = cardhu_power_off;
1218
1219         return 0;
1220 }
1221
1222 static struct tegra_tsensor_pmu_data  tpdata = {
1223         .poweroff_reg_addr = 0x3F,
1224         .poweroff_reg_data = 0x80,
1225         .reset_tegra = 1,
1226         .controller_type = 0,
1227         .i2c_controller_id = 4,
1228         .pinmux = 0,
1229         .pmu_16bit_ops = 0,
1230         .pmu_i2c_addr = 0x2D,
1231 };
1232
1233 void __init cardhu_tsensor_init(void)
1234 {
1235         tegra3_tsensor_init(&tpdata);
1236 }
1237
1238 #ifdef CONFIG_TEGRA_EDP_LIMITS
1239
1240 int __init cardhu_edp_init(void)
1241 {
1242         unsigned int regulator_mA;
1243
1244         regulator_mA = get_maximum_cpu_current_supported();
1245         if (!regulator_mA) {
1246                 regulator_mA = 6000; /* regular T30/s */
1247         }
1248         pr_info("%s: CPU regulator %d mA\n", __func__, regulator_mA);
1249
1250         tegra_init_cpu_edp_limits(regulator_mA);
1251         return 0;
1252 }
1253 #endif
1254
1255 static char *cardhu_battery[] = {
1256         "bq27510-0",
1257 };
1258
1259 static struct gpio_charger_platform_data cardhu_charger_pdata = {
1260         .name = "ac",
1261         .type = POWER_SUPPLY_TYPE_MAINS,
1262         .gpio = AC_PRESENT_GPIO,
1263         .gpio_active_low = 0,
1264         .supplied_to = cardhu_battery,
1265         .num_supplicants = ARRAY_SIZE(cardhu_battery),
1266 };
1267
1268 static struct platform_device cardhu_charger_device = {
1269         .name = "gpio-charger",
1270         .dev = {
1271                 .platform_data = &cardhu_charger_pdata,
1272         },
1273 };
1274
1275 static int __init cardhu_charger_late_init(void)
1276 {
1277         if (!machine_is_cardhu())
1278                 return 0;
1279
1280         platform_device_register(&cardhu_charger_device);
1281         return 0;
1282 }
1283
1284 late_initcall(cardhu_charger_late_init);