arm: tegra: enterprise: Configure rails for sleep state
[linux-2.6.git] / arch / arm / mach-tegra / board-enterprise-power.c
1 /*
2  * arch/arm/mach-tegra/board-enterprise-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/regulator/gpio-switch-regulator.h>
26 #include <linux/mfd/tps80031.h>
27 #include <linux/regulator/tps80031-regulator.h>
28 #include <linux/tps80031-charger.h>
29 #include <linux/gpio.h>
30 #include <linux/io.h>
31
32 #include <mach/edp.h>
33 #include <mach/iomap.h>
34 #include <mach/irqs.h>
35 #include <mach/pinmux.h>
36 #include <mach/tsensor.h>
37
38 #include "gpio-names.h"
39 #include "board.h"
40 #include "board-enterprise.h"
41 #include "pm.h"
42 #include "wakeups-t3.h"
43
44 #define PMC_CTRL                0x0
45 #define PMC_CTRL_INTR_LOW       (1 << 17)
46
47 /************************ TPS80031 based regulator ****************/
48 static struct regulator_consumer_supply tps80031_vio_supply[] = {
49         REGULATOR_SUPPLY("vio_1v8", NULL),
50         REGULATOR_SUPPLY("avdd_osc", NULL),
51         REGULATOR_SUPPLY("vddio_sys", NULL),
52         REGULATOR_SUPPLY("vddio_uart", NULL),
53         REGULATOR_SUPPLY("pwrdet_uart", NULL),
54         REGULATOR_SUPPLY("vddio_lcd", NULL),
55         REGULATOR_SUPPLY("pwrdet_lcd", NULL),
56         REGULATOR_SUPPLY("vddio_audio", NULL),
57         REGULATOR_SUPPLY("pwrdet_audio", NULL),
58         REGULATOR_SUPPLY("vddio_bb", NULL),
59         REGULATOR_SUPPLY("pwrdet_bb", NULL),
60         REGULATOR_SUPPLY("vddio_gmi", NULL),
61         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
62         REGULATOR_SUPPLY("vddio_cam", NULL),
63         REGULATOR_SUPPLY("pwrdet_cam", NULL),
64         REGULATOR_SUPPLY("vddio_sdmmc1", NULL),
65         REGULATOR_SUPPLY("pwrdet_sdmmc1", NULL),
66         REGULATOR_SUPPLY("vddio_sdmmc4", NULL),
67         REGULATOR_SUPPLY("pwrdet_sdmmc4", NULL),
68         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
69         REGULATOR_SUPPLY("vddio_gps", NULL),
70         REGULATOR_SUPPLY("vdd_lcd_buffered", NULL),
71         REGULATOR_SUPPLY("vddio_nand", NULL),
72         REGULATOR_SUPPLY("pwrdet_nand", NULL),
73         REGULATOR_SUPPLY("vddio_sd", NULL),
74         REGULATOR_SUPPLY("vdd_bat", NULL),
75         REGULATOR_SUPPLY("vdd_io", NULL),
76         REGULATOR_SUPPLY("pwrdet_pex_ctl", NULL),
77 };
78
79 static struct regulator_consumer_supply tps80031_smps1_supply[] = {
80         REGULATOR_SUPPLY("vdd_cpu", NULL),
81 };
82
83 static struct regulator_consumer_supply tps80031_smps2_supply[] = {
84         REGULATOR_SUPPLY("vdd_core", NULL),
85 };
86
87 static struct regulator_consumer_supply tps80031_smps3_supply[] = {
88         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
89         REGULATOR_SUPPLY("vddio_ddr", NULL),
90         REGULATOR_SUPPLY("vdd_lpddr", NULL),
91         REGULATOR_SUPPLY("ddr_comp_pu", NULL),
92 };
93
94 static struct regulator_consumer_supply tps80031_smps4_supply[] = {
95         REGULATOR_SUPPLY("vddio_sdmmc_2v85", NULL),
96         REGULATOR_SUPPLY("pwrdet_sdmmc3", NULL),
97 };
98
99 static struct regulator_consumer_supply tps80031_vana_supply[] = {
100         REGULATOR_SUPPLY("unused_vana", NULL),
101 };
102
103 static struct regulator_consumer_supply tps80031_ldo1_supply[] = {
104         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
105         REGULATOR_SUPPLY("pwrdet_mipi", NULL),
106 };
107
108 static struct regulator_consumer_supply tps80031_ldo2_supply[] = {
109         REGULATOR_SUPPLY("vdd_rtc", NULL),
110 };
111
112 static struct regulator_consumer_supply tps80031_ldo3_supply[] = {
113         REGULATOR_SUPPLY("vdd_vbrtr", NULL),
114 };
115
116 static struct regulator_consumer_supply tps80031_ldo4_supply[] = {
117         REGULATOR_SUPPLY("avdd_lcd", NULL),
118 };
119
120 static struct regulator_consumer_supply tps80031_ldo5_supply[] = {
121         REGULATOR_SUPPLY("vdd_sensor", NULL),
122         REGULATOR_SUPPLY("vdd_compass", NULL),
123         REGULATOR_SUPPLY("vdd_als", NULL),
124         REGULATOR_SUPPLY("vdd_gyro", NULL),
125         REGULATOR_SUPPLY("vdd_touch", NULL),
126         REGULATOR_SUPPLY("vdd_proxim_diode", NULL),
127 };
128
129 static struct regulator_consumer_supply tps80031_ldo6_supply[] = {
130         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
131         REGULATOR_SUPPLY("vddf_core_emmc", NULL),
132 };
133
134 static struct regulator_consumer_supply tps80031_ldo7_supply[] = {
135         REGULATOR_SUPPLY("vdd_plla_p_c_s", NULL),
136         REGULATOR_SUPPLY("vdd_pllm", NULL),
137         REGULATOR_SUPPLY("vdd_pllu_d", NULL),
138         REGULATOR_SUPPLY("vdd_pllx", NULL),
139 };
140
141 static struct regulator_consumer_supply tps80031_ldoln_supply[] = {
142         REGULATOR_SUPPLY("vdd_ddr_hs", NULL),
143 };
144
145 static struct regulator_consumer_supply tps80031_ldousb_supply[] = {
146         REGULATOR_SUPPLY("unused_ldousb", NULL),
147 };
148
149 static struct regulator_consumer_supply tps80031_vbus_supply[] = {
150         REGULATOR_SUPPLY("usb_vbus", NULL),
151 };
152
153 static struct regulator_consumer_supply tps80031_battery_charge_supply[] = {
154         REGULATOR_SUPPLY("usb_bat_chg", NULL),
155 };
156
157 #define TPS_PDATA_INIT(_id, _minmv, _maxmv, _supply_reg, _always_on,    \
158         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply,       \
159         _flags, _ectrl, _delay)                                         \
160         static struct tps80031_regulator_platform_data pdata_##_id = {  \
161                 .regulator = {                                          \
162                         .constraints = {                                \
163                                 .min_uV = (_minmv)*1000,                \
164                                 .max_uV = (_maxmv)*1000,                \
165                                 .valid_modes_mask = (REGULATOR_MODE_NORMAL |  \
166                                                 REGULATOR_MODE_STANDBY),      \
167                                 .valid_ops_mask = (REGULATOR_CHANGE_MODE |    \
168                                                 REGULATOR_CHANGE_STATUS |     \
169                                                 REGULATOR_CHANGE_VOLTAGE),    \
170                                 .always_on = _always_on,                \
171                                 .boot_on = _boot_on,                    \
172                                 .apply_uV = _apply_uv,                  \
173                         },                                              \
174                         .num_consumer_supplies =                        \
175                                 ARRAY_SIZE(tps80031_##_id##_supply),    \
176                         .consumer_supplies = tps80031_##_id##_supply,   \
177                         .supply_regulator = _supply_reg,                \
178                 },                                                      \
179                 .init_uV =  _init_uV * 1000,                            \
180                 .init_enable = _init_enable,                            \
181                 .init_apply = _init_apply,                              \
182                 .flags = _flags,                                        \
183                 .ext_ctrl_flag = _ectrl,                                \
184                 .delay_us = _delay,                                     \
185         }
186
187 TPS_PDATA_INIT(vio,   600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0);
188 TPS_PDATA_INIT(smps1, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ2 | PWR_OFF_ON_SLEEP, 0);
189 TPS_PDATA_INIT(smps2, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
190 TPS_PDATA_INIT(smps3, 600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0);
191 TPS_PDATA_INIT(smps4, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
192 TPS_PDATA_INIT(ldo1, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0, 0, 0, 0);
193 TPS_PDATA_INIT(ldo2, 1000, 3300, 0, 1, 1, 1, 1000, 1, 1, 0, 0, 0);
194 TPS_PDATA_INIT(ldo3, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0, 0, PWR_OFF_ON_SLEEP, 0);
195 TPS_PDATA_INIT(ldo4, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
196 TPS_PDATA_INIT(ldo5, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
197 TPS_PDATA_INIT(ldo6, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
198 TPS_PDATA_INIT(ldo7, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
199 TPS_PDATA_INIT(ldoln, 1000, 3300, tps80031_rails(SMPS3), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
200 TPS_PDATA_INIT(ldousb, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, USBLDO_INPUT_VSYS, PWR_OFF_ON_SLEEP, 0);
201 TPS_PDATA_INIT(vana,  1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
202 TPS_PDATA_INIT(vbus,  0, 5000, 0, 0, 0, 0, -1, 0, 0, (VBUS_SW_ONLY | VBUS_DISCHRG_EN_PDN), 0, 100000);
203
204 static struct tps80031_rtc_platform_data rtc_data = {
205         .irq = ENT_TPS80031_IRQ_BASE + TPS80031_INT_RTC_ALARM,
206         .time = {
207                 .tm_year = 2011,
208                 .tm_mon = 0,
209                 .tm_mday = 1,
210                 .tm_hour = 1,
211                 .tm_min = 2,
212                 .tm_sec = 3,
213         },
214 };
215
216 int battery_charger_init(void *board_data)
217 {
218         int ret;
219         ret = gpio_request(TEGRA_GPIO_PF6, "lcd_d14-bat_charge");
220         if (ret < 0) {
221                 pr_err("%s() The gpio_request for battery"
222                                 " charger fails\n", __func__);
223         }
224         gpio_direction_output(TEGRA_GPIO_PF6, 1);
225         tegra_gpio_enable(TEGRA_GPIO_PF6);
226         return 0;
227 }
228
229 static struct tps80031_charger_platform_data bcharger_pdata = {
230         .max_charge_volt_mV = 4100,
231         .max_charge_current_mA = 1000,
232         .charging_term_current_mA = 100,
233         .watch_time_sec = 100,
234         .irq_base = ENT_TPS80031_IRQ_BASE,
235         .consumer_supplies = tps80031_battery_charge_supply,
236         .num_consumer_supplies = ARRAY_SIZE(tps80031_battery_charge_supply),
237         .board_init = battery_charger_init,
238         .board_data = NULL,
239 };
240
241 static struct tps80031_bg_platform_data battery_gauge_data = {
242         .irq_base = ENT_TPS80031_IRQ_BASE,
243         .battery_present = 1,
244 };
245
246 #define TPS_RTC()                               \
247         {                                               \
248                 .id     = 0,            \
249                 .name   = "rtc_tps80031",       \
250                 .platform_data = &rtc_data,     \
251         }
252
253 #define TPS_REG(_id, _data)                             \
254         {                                               \
255                 .id      = TPS80031_ID_##_id,           \
256                 .name   = "tps80031-regulator",         \
257                 .platform_data  = &pdata_##_data,       \
258         }
259 #define TPS_BATTERY()                                   \
260         {                                               \
261                 .name   = "tps80031-charger",           \
262                 .platform_data = &bcharger_pdata,       \
263         }
264 #define TPS_BATTERY_GAUGE()                             \
265         {                                               \
266                 .name   = "tps80031-battery-gauge",     \
267                 .platform_data = &battery_gauge_data,   \
268         }
269 #define TPS_GPADC()                                     \
270         {                                               \
271                 .name   = "tps80031-gpadc",             \
272         }
273
274 static struct tps80031_subdev_info tps80031_devs[] = {
275         TPS_REG(VIO, vio),
276         TPS_REG(SMPS1, smps1),
277         TPS_REG(SMPS2, smps2),
278         TPS_REG(SMPS3, smps3),
279         TPS_REG(SMPS4, smps4),
280         TPS_REG(LDO1, ldo1),
281         TPS_REG(LDO2, ldo2),
282         TPS_REG(LDO3, ldo3),
283         TPS_REG(LDO4, ldo4),
284         TPS_REG(LDO5, ldo5),
285         TPS_REG(LDO6, ldo6),
286         TPS_REG(LDO7, ldo7),
287         TPS_REG(LDOLN, ldoln),
288         TPS_REG(LDOUSB, ldousb),
289         TPS_REG(VANA, vana),
290         TPS_REG(VBUS, vbus),
291         TPS_RTC(),
292         TPS_BATTERY(),
293         TPS_BATTERY_GAUGE(),
294         TPS_GPADC(),
295 };
296
297 struct tps80031_clk32k_init_data clk32k_idata[] = {
298         {
299                 .clk32k_nr = TPS80031_CLOCK32K_G,
300                 .enable = true,
301                 .ext_ctrl_flag = PWR_REQ_INPUT_PREQ1,
302         },
303         {
304                 .clk32k_nr = TPS80031_CLOCK32K_AUDIO,
305                 .enable = true,
306                 .ext_ctrl_flag = PWR_REQ_INPUT_PREQ1,
307         },
308 };
309
310 static struct tps80031_platform_data tps_platform = {
311         .num_subdevs    = ARRAY_SIZE(tps80031_devs),
312         .subdevs        = tps80031_devs,
313         .irq_base       = ENT_TPS80031_IRQ_BASE,
314         .gpio_base      = ENT_TPS80031_GPIO_BASE,
315         .clk32k_init_data       = clk32k_idata,
316         .clk32k_init_data_size  = ARRAY_SIZE(clk32k_idata),
317 };
318
319 static struct i2c_board_info __initdata enterprise_regulators[] = {
320         {
321                 I2C_BOARD_INFO("tps80031", 0x4A),
322                 .irq            = INT_EXTERNAL_PMU,
323                 .platform_data  = &tps_platform,
324         },
325 };
326
327 /************************ GPIO based switch regulator ****************/
328
329 /* REGEN1 from PMU*/
330 static struct regulator_consumer_supply gpio_switch_pmu_5v15_en_supply[] = {
331         REGULATOR_SUPPLY("vdd_5v15", NULL),
332 };
333 static int gpio_switch_pmu_5v15_en_voltages[] = {5000};
334
335 /* REGEN2 from PMU*/
336 static struct regulator_consumer_supply gpio_switch_pmu_3v3_en_supply[] = {
337         REGULATOR_SUPPLY("avdd_usb_hdmi_3v3", NULL),
338         REGULATOR_SUPPLY("avdd_usb", NULL),
339         REGULATOR_SUPPLY("avdd_hdmi", NULL),
340         REGULATOR_SUPPLY("vdd", "4-004c"),
341 };
342 static int gpio_switch_pmu_3v3_en_voltages[] = {3300};
343
344 /* SYSEN from PMU*/
345 static struct regulator_consumer_supply gpio_switch_pmu_hdmi_5v0_en_supply[] = {
346         REGULATOR_SUPPLY("hdmi_5v0", NULL),
347 };
348 static int gpio_switch_pmu_hdmi_5v0_en_voltages[] = {5000};
349
350 /* LCD-D16 (GPIO M0) from T30*/
351 static struct regulator_consumer_supply gpio_switch_vdd_fuse_en_supply[] = {
352         REGULATOR_SUPPLY("vdd_fuse", NULL),
353 };
354 static int gpio_switch_vdd_fuse_en_voltages[] = {3300};
355
356 /* LCD-D17 (GPIO M1) from T30*/
357 static struct regulator_consumer_supply gpio_switch_sdmmc3_vdd_sel_supply[] = {
358         REGULATOR_SUPPLY("vddio_sdmmc3_2v85_1v8", NULL),
359         REGULATOR_SUPPLY("sdmmc3_compu_pu", NULL),
360         REGULATOR_SUPPLY("vddio_sdmmc3", NULL),
361         REGULATOR_SUPPLY("vsys_3v7", NULL),
362 };
363 static int gpio_switch_sdmmc3_vdd_sel_voltages[] = {2850};
364
365 /* LCD-D23 (GPIO M7) from T30*/
366 /* 2-0036 is dev_name of ar0832 in Enterprise A01*/
367 /* 2-0032 is alternative dev_name of ar0832 Enterprise A01*/
368 /* 2-0010 is dev_name of ov9726 */
369 /* 2-0070 is dev_name of PCA9546 in Enterprise A02*/
370 /* 6-0036 is dev_name of ar0832 in Enterprise A02 */
371 /* 7-0036 is dev_name of ar0832 in Enterprise A02 */
372 static struct regulator_consumer_supply gpio_switch_cam_ldo_2v8_en_supply[] = {
373         REGULATOR_SUPPLY("vaa", "2-0036"),
374         REGULATOR_SUPPLY("vaa", "2-0032"),
375         REGULATOR_SUPPLY("avdd", "2-0010"),
376         REGULATOR_SUPPLY("vdd_2v8_cam", NULL),
377         REGULATOR_SUPPLY("vcc", "2-0070"),
378         REGULATOR_SUPPLY("vaa", "6-0036"),
379         REGULATOR_SUPPLY("vaa", "7-0036"),
380 };
381 static int gpio_switch_cam_ldo_2v8_en_voltages[] = {2800};
382
383 /* LCD-D9 (GPIO F1) from T30*/
384 /* 2-0036 is dev_name of ar0832 in Enterprise A01*/
385 /* 2-0032 is alternative dev_name of ar0832 Enterprise A01*/
386 /* 2-0010 is dev_name of ov9726 */
387 /* 2-0070 is dev_name of PCA9546 in Enterprise A02*/
388 /* 6-0036 is dev_name of ar0832 in Enterprise A02 */
389 /* 7-0036 is dev_name of ar0832 in Enterprise A02 */
390 static struct regulator_consumer_supply gpio_switch_cam_ldo_1v8_en_supply[] = {
391         REGULATOR_SUPPLY("vdd", "2-0036"),
392         REGULATOR_SUPPLY("vdd", "2-0032"),
393         REGULATOR_SUPPLY("dovdd", "2-0010"),
394         REGULATOR_SUPPLY("vdd_1v8_cam", NULL),
395         REGULATOR_SUPPLY("vcc_i2c", "2-0070"),
396         REGULATOR_SUPPLY("vdd", "6-0036"),
397         REGULATOR_SUPPLY("vdd", "7-0036"),
398 };
399 static int gpio_switch_cam_ldo_1v8_en_voltages[] = {1800};
400
401 /* Macro for defining gpio switch regulator sub device data */
402 #define GREG_INIT(_id, _name, _input_supply, _gpio_nr, _active_low, \
403                         _init_state, _pg, _enable, _disable)            \
404         static struct gpio_switch_regulator_subdev_data gpio_pdata_##_name =  \
405         {                                                               \
406                 .regulator_name = "gpio-switch-"#_name,                 \
407                 .input_supply   = _input_supply,                        \
408                 .id             = _id,                                  \
409                 .gpio_nr        = _gpio_nr,                             \
410                 .pin_group      = _pg,                                  \
411                 .active_low     = _active_low,                          \
412                 .init_state     = _init_state,                          \
413                 .voltages       = gpio_switch_##_name##_voltages,       \
414                 .n_voltages     = ARRAY_SIZE(gpio_switch_##_name##_voltages), \
415                 .num_consumer_supplies =                                \
416                                 ARRAY_SIZE(gpio_switch_##_name##_supply), \
417                 .consumer_supplies = gpio_switch_##_name##_supply,      \
418                 .constraints = {                                        \
419                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
420                                         REGULATOR_MODE_STANDBY),        \
421                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
422                                         REGULATOR_CHANGE_STATUS |       \
423                                         REGULATOR_CHANGE_VOLTAGE),      \
424                 },                                                      \
425                 .enable_rail = _enable,                                 \
426                 .disable_rail = _disable,                               \
427         }
428
429 GREG_INIT(0, pmu_5v15_en,     NULL,      ENT_TPS80031_GPIO_REGEN1, false, 0, 0, 0, 0);
430 GREG_INIT(1, pmu_3v3_en,      "vdd_5v15", ENT_TPS80031_GPIO_REGEN2, false, 0, 0, 0, 0);
431 GREG_INIT(2, pmu_hdmi_5v0_en, "vdd_5v15", ENT_TPS80031_GPIO_SYSEN, false, 0, 0, 0, 0);
432
433 GREG_INIT(3, vdd_fuse_en, "avdd_usb_hdmi_3v3", TEGRA_GPIO_PM0, false, 0, 0, 0, 0);
434 GREG_INIT(4, sdmmc3_vdd_sel, "vddio_sdmmc_2v85", TEGRA_GPIO_PM1, false, 0, 0, 0, 0);
435 GREG_INIT(5, cam_ldo_2v8_en, NULL, TEGRA_GPIO_PM7, false, 0, 0, 0, 0);
436 GREG_INIT(6, cam_ldo_1v8_en, NULL, TEGRA_GPIO_PF1, false, 0, 0, 0, 0);
437
438 #define ADD_GPIO_REG(_name)     (&gpio_pdata_##_name)
439 static struct gpio_switch_regulator_subdev_data *gswitch_subdevs[] = {
440         ADD_GPIO_REG(pmu_5v15_en),
441         ADD_GPIO_REG(pmu_3v3_en),
442         ADD_GPIO_REG(pmu_hdmi_5v0_en),
443         ADD_GPIO_REG(vdd_fuse_en),
444         ADD_GPIO_REG(sdmmc3_vdd_sel),
445         ADD_GPIO_REG(cam_ldo_2v8_en),
446         ADD_GPIO_REG(cam_ldo_1v8_en),
447 };
448
449 static struct gpio_switch_regulator_platform_data  gswitch_pdata = {
450         .num_subdevs = ARRAY_SIZE(gswitch_subdevs),
451         .subdevs = gswitch_subdevs,
452 };
453
454 static struct platform_device gswitch_regulator_pdata = {
455         .name   = "gpio-switch-regulator",
456         .id     = -1,
457         .dev    = {
458                 .platform_data = &gswitch_pdata,
459         },
460 };
461
462 static int __init enterprise_gpio_switch_regulator_init(void)
463 {
464         int i;
465         for (i = 0; i < gswitch_pdata.num_subdevs; ++i) {
466                 struct gpio_switch_regulator_subdev_data *gswitch_data =
467                                                 gswitch_pdata.subdevs[i];
468                 if (gswitch_data->gpio_nr <= TEGRA_NR_GPIOS)
469                         tegra_gpio_enable(gswitch_data->gpio_nr);
470         }
471         return platform_device_register(&gswitch_regulator_pdata);
472 }
473
474 static void enterprise_power_off(void)
475 {
476         int ret;
477         pr_info("enterprise: Powering off the device\n");
478         ret = tps80031_power_off();
479         if (ret)
480                 pr_err("enterprise: failed to power off\n");
481         while(1);
482 }
483
484 void __init enterprise_tsensor_init(void)
485 {
486         tegra3_tsensor_init(NULL);
487 }
488
489 int __init enterprise_regulator_init(void)
490 {
491         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
492         u32 pmc_ctrl;
493
494         /* configure the power management controller to trigger PMU
495          * interrupts when low */
496
497         pmc_ctrl = readl(pmc + PMC_CTRL);
498         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
499
500         /* Disable battery charging if power adapter is connected. */
501         if (get_power_supply_type() == POWER_SUPPLY_TYPE_MAINS) {
502                 bcharger_pdata.num_consumer_supplies = 0;
503                 bcharger_pdata.consumer_supplies = NULL;
504                 battery_gauge_data.battery_present = 0;
505         }
506
507         i2c_register_board_info(4, enterprise_regulators, 1);
508         enterprise_gpio_switch_regulator_init();
509         pm_power_off = enterprise_power_off;
510
511         return 0;
512 }
513
514 static void enterprise_board_suspend(int lp_state, enum suspend_stage stg)
515 {
516         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_SUSPEND_BEFORE_CPU))
517                 tegra_console_uart_suspend();
518 }
519
520 static void enterprise_board_resume(int lp_state, enum resume_stage stg)
521 {
522         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_RESUME_AFTER_CPU))
523                 tegra_console_uart_resume();
524 }
525
526 static struct tegra_suspend_platform_data enterprise_suspend_data = {
527         .cpu_timer      = 2000,
528         .cpu_off_timer  = 200,
529         .suspend_mode   = TEGRA_SUSPEND_LP0,
530         .core_timer     = 0x7e7e,
531         .core_off_timer = 0,
532         .corereq_high   = true,
533         .sysclkreq_high = true,
534         .board_suspend = enterprise_board_suspend,
535         .board_resume = enterprise_board_resume,
536 };
537
538 static void enterprise_init_deep_sleep_mode(void)
539 {
540         struct board_info bi;
541         tegra_get_board_info(&bi);
542
543         if (bi.board_id == BOARD_E1205 && bi.fab == BOARD_FAB_A01)
544                 enterprise_suspend_data.suspend_mode = TEGRA_SUSPEND_LP1;
545
546         if ((bi.board_id == BOARD_E1205 && (bi.sku & BOARD_SKU_VF_BIT) == 0) ||
547             (bi.board_id == BOARD_E1197 && (bi.sku & BOARD_SKU_VF_BIT)))
548                 enterprise_suspend_data.cpu_timer = 8000;
549 }
550
551 int __init enterprise_suspend_init(void)
552 {
553         enterprise_init_deep_sleep_mode();
554         tegra_init_suspend(&enterprise_suspend_data);
555         return 0;
556 }
557
558 #ifdef CONFIG_TEGRA_EDP_LIMITS
559
560 int __init enterprise_edp_init(void)
561 {
562         unsigned int regulator_mA;
563
564         regulator_mA = get_maximum_cpu_current_supported();
565         if (!regulator_mA) {
566                 regulator_mA = 2500; /* regular AP30 */
567         }
568         pr_info("%s: CPU regulator %d mA\n", __func__, regulator_mA);
569
570         tegra_init_cpu_edp_limits(regulator_mA);
571         return 0;
572 }
573 #endif