ARM: tegra: enterprise: Update tps80031 power off
[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/fixed.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 #include <linux/cpumask.h>
32 #include <linux/platform_data/tegra_bpc_mgmt.h>
33 #include <linux/regulator/driver.h>
34 #include <linux/regulator/gpio-regulator.h>
35
36 #include <mach/edp.h>
37 #include <mach/iomap.h>
38 #include <mach/irqs.h>
39 #include <mach/pinmux.h>
40
41 #include "gpio-names.h"
42 #include "board.h"
43 #include "board-enterprise.h"
44 #include "pm.h"
45 #include "wakeups-t3.h"
46 #include "tegra3_tsensor.h"
47
48 #define PMC_CTRL                0x0
49 #define PMC_CTRL_INTR_LOW       (1 << 17)
50
51 #define PMC_DPD_PADS_ORIDE              0x01c
52 #define PMC_DPD_PADS_ORIDE_BLINK        (1 << 20)
53
54 static bool is_enterprise_machine = false;
55
56 /************************ TPS80031 based regulator ****************/
57 static struct regulator_consumer_supply tps80031_vio_supply[] = {
58         REGULATOR_SUPPLY("vio_1v8", NULL),
59         REGULATOR_SUPPLY("avdd_osc", NULL),
60         REGULATOR_SUPPLY("vddio_sys", NULL),
61         REGULATOR_SUPPLY("vddio_uart", NULL),
62         REGULATOR_SUPPLY("pwrdet_uart", NULL),
63         REGULATOR_SUPPLY("vddio_lcd", NULL),
64         REGULATOR_SUPPLY("pwrdet_lcd", NULL),
65         REGULATOR_SUPPLY("vddio_audio", NULL),
66         REGULATOR_SUPPLY("pwrdet_audio", NULL),
67         REGULATOR_SUPPLY("vddio_bb", NULL),
68         REGULATOR_SUPPLY("pwrdet_bb", NULL),
69         REGULATOR_SUPPLY("vddio_gmi", NULL),
70         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
71         REGULATOR_SUPPLY("vddio_cam", NULL),
72         REGULATOR_SUPPLY("pwrdet_cam", NULL),
73         REGULATOR_SUPPLY("vddio_sdmmc1", NULL),
74         REGULATOR_SUPPLY("pwrdet_sdmmc1", NULL),
75         REGULATOR_SUPPLY("vddio_sdmmc4", NULL),
76         REGULATOR_SUPPLY("pwrdet_sdmmc4", NULL),
77         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
78         REGULATOR_SUPPLY("vddio_gps", NULL),
79         REGULATOR_SUPPLY("vdd_lcd_buffered", NULL),
80         REGULATOR_SUPPLY("vddio_nand", NULL),
81         REGULATOR_SUPPLY("pwrdet_nand", NULL),
82         REGULATOR_SUPPLY("vddio_sd", NULL),
83         REGULATOR_SUPPLY("vdd_bat", NULL),
84         REGULATOR_SUPPLY("vdd_io", NULL),
85         REGULATOR_SUPPLY("pwrdet_pex_ctl", NULL),
86 };
87
88 static struct regulator_consumer_supply tps80031_smps1_supply[] = {
89         REGULATOR_SUPPLY("vdd_cpu", NULL),
90 };
91
92 static struct regulator_consumer_supply tps80031_smps2_supply[] = {
93         REGULATOR_SUPPLY("vdd_core", NULL),
94 };
95
96 static struct regulator_consumer_supply tps80031_smps3_supply[] = {
97         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
98         REGULATOR_SUPPLY("vddio_ddr", NULL),
99         REGULATOR_SUPPLY("vdd_lpddr", NULL),
100         REGULATOR_SUPPLY("ddr_comp_pu", NULL),
101 };
102
103 static struct regulator_consumer_supply tps80031_smps4_supply[] = {
104         REGULATOR_SUPPLY("vddio_sdmmc_2v85", NULL),
105         REGULATOR_SUPPLY("pwrdet_sdmmc3", NULL),
106 };
107
108 static struct regulator_consumer_supply tps80031_vana_supply[] = {
109         REGULATOR_SUPPLY("unused_vana", NULL),
110 };
111
112 static struct regulator_consumer_supply tps80031_ldo1_supply[] = {
113         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
114         REGULATOR_SUPPLY("pwrdet_mipi", NULL),
115 };
116
117 static struct regulator_consumer_supply tps80031_ldo2_supply[] = {
118         REGULATOR_SUPPLY("vdd_rtc", NULL),
119 };
120
121 static struct regulator_consumer_supply tps80031_ldo3_supply[] = {
122         REGULATOR_SUPPLY("vdd_vbrtr", NULL),
123 };
124
125 static struct regulator_consumer_supply tps80031_ldo4_supply[] = {
126         REGULATOR_SUPPLY("avdd_lcd", NULL),
127 };
128
129 static struct regulator_consumer_supply tps80031_ldo5_supply[] = {
130         REGULATOR_SUPPLY("vdd_sensor", NULL),
131         REGULATOR_SUPPLY("vdd_compass", NULL),
132         REGULATOR_SUPPLY("vdd_als", NULL),
133         REGULATOR_SUPPLY("vdd_gyro", NULL),
134         REGULATOR_SUPPLY("vdd_touch", NULL),
135         REGULATOR_SUPPLY("vdd_proxim_diode", NULL),
136 };
137
138 static struct regulator_consumer_supply tps80031_ldo6_supply[] = {
139         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
140         REGULATOR_SUPPLY("vddf_core_emmc", NULL),
141 };
142
143 static struct regulator_consumer_supply tps80031_ldo7_supply[] = {
144         REGULATOR_SUPPLY("vdd_plla_p_c_s", NULL),
145         REGULATOR_SUPPLY("vdd_pllm", NULL),
146         REGULATOR_SUPPLY("vdd_pllu_d", NULL),
147         REGULATOR_SUPPLY("vdd_pllx", NULL),
148 };
149
150 static struct regulator_consumer_supply tps80031_ldoln_supply[] = {
151         REGULATOR_SUPPLY("vdd_ddr_hs", NULL),
152 };
153
154 static struct regulator_consumer_supply tps80031_ldousb_supply[] = {
155         REGULATOR_SUPPLY("unused_ldousb", NULL),
156 };
157
158 static struct regulator_consumer_supply tps80031_vbus_supply[] = {
159         REGULATOR_SUPPLY("usb_vbus", NULL),
160 };
161
162 static struct regulator_consumer_supply tps80031_battery_charge_supply[] = {
163         REGULATOR_SUPPLY("usb_bat_chg", NULL),
164 };
165
166 #define TPS_PDATA_INIT(_id, _minmv, _maxmv, _supply_reg, _always_on,    \
167         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply,       \
168         _flags, _ectrl, _delay)                                         \
169         static struct tps80031_regulator_platform_data pdata_##_id = {  \
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(tps80031_##_id##_supply),    \
185                         .consumer_supplies = tps80031_##_id##_supply,   \
186                         .supply_regulator = _supply_reg,                \
187                 },                                                      \
188                 .init_uV =  _init_uV * 1000,                            \
189                 .init_enable = _init_enable,                            \
190                 .init_apply = _init_apply,                              \
191                 .flags = _flags,                                        \
192                 .ext_ctrl_flag = _ectrl,                                \
193                 .delay_us = _delay,                                     \
194         }
195
196 TPS_PDATA_INIT(vio,   600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0);
197 TPS_PDATA_INIT(smps1, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ2 | PWR_OFF_ON_SLEEP, 0);
198 TPS_PDATA_INIT(smps2, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
199 TPS_PDATA_INIT(smps3, 600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0);
200 TPS_PDATA_INIT(smps4, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
201 TPS_PDATA_INIT(ldo1, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0, 0, 0, 0);
202 TPS_PDATA_INIT(ldo2, 1000, 3300, 0, 1, 1, 1, 1000, 1, 1, 0, 0, 0);
203 TPS_PDATA_INIT(ldo3, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0, 0, PWR_OFF_ON_SLEEP, 0);
204 TPS_PDATA_INIT(ldo4, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
205 TPS_PDATA_INIT(ldo5, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
206 TPS_PDATA_INIT(ldo6, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
207 TPS_PDATA_INIT(ldo7, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
208 TPS_PDATA_INIT(ldoln, 1000, 3300, tps80031_rails(SMPS3), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
209 TPS_PDATA_INIT(ldousb, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, USBLDO_INPUT_VSYS, PWR_OFF_ON_SLEEP, 0);
210 TPS_PDATA_INIT(vana,  1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
211 TPS_PDATA_INIT(vbus,  0, 5000, 0, 0, 0, 0, -1, 0, 0, (VBUS_SW_ONLY | VBUS_DISCHRG_EN_PDN), 0, 100000);
212
213 static struct tps80031_rtc_platform_data rtc_data = {
214         .irq = ENT_TPS80031_IRQ_BASE + TPS80031_INT_RTC_ALARM,
215         .time = {
216                 .tm_year = 2011,
217                 .tm_mon = 0,
218                 .tm_mday = 1,
219                 .tm_hour = 1,
220                 .tm_min = 2,
221                 .tm_sec = 3,
222         },
223 };
224
225 int battery_charger_init(void *board_data)
226 {
227         int ret;
228         ret = gpio_request(TEGRA_GPIO_PF6, "lcd_d14-bat_charge");
229         if (ret < 0) {
230                 pr_err("%s() The gpio_request for battery"
231                                 " charger fails\n", __func__);
232         }
233         gpio_direction_output(TEGRA_GPIO_PF6, 1);
234         tegra_gpio_enable(TEGRA_GPIO_PF6);
235         return 0;
236 }
237
238 static struct tps80031_charger_platform_data bcharger_pdata = {
239         .max_charge_volt_mV = 4100,
240         .max_charge_current_mA = 1000,
241         .charging_term_current_mA = 100,
242         .watch_time_sec = 100,
243         .irq_base = ENT_TPS80031_IRQ_BASE,
244         .consumer_supplies = tps80031_battery_charge_supply,
245         .num_consumer_supplies = ARRAY_SIZE(tps80031_battery_charge_supply),
246         .board_init = battery_charger_init,
247         .board_data = NULL,
248 };
249
250 static struct tps80031_bg_platform_data battery_gauge_data = {
251         .irq_base = ENT_TPS80031_IRQ_BASE,
252         .battery_present = 1,
253 };
254
255 #define TPS_RTC()                               \
256         {                                               \
257                 .id     = 0,            \
258                 .name   = "rtc_tps80031",       \
259                 .platform_data = &rtc_data,     \
260         }
261
262 #define TPS_REG(_id, _data)                             \
263         {                                               \
264                 .id      = TPS80031_ID_##_id,           \
265                 .name   = "tps80031-regulator",         \
266                 .platform_data  = &pdata_##_data,       \
267         }
268 #define TPS_BATTERY()                                   \
269         {                                               \
270                 .name   = "tps80031-charger",           \
271                 .platform_data = &bcharger_pdata,       \
272         }
273 #define TPS_BATTERY_GAUGE()                             \
274         {                                               \
275                 .name   = "tps80031-battery-gauge",     \
276                 .platform_data = &battery_gauge_data,   \
277         }
278 #define TPS_GPADC()                                     \
279         {                                               \
280                 .name   = "tps80031-gpadc",             \
281         }
282
283 static struct tps80031_subdev_info tps80031_devs[] = {
284         TPS_REG(VIO, vio),
285         TPS_REG(SMPS1, smps1),
286         TPS_REG(SMPS2, smps2),
287         TPS_REG(SMPS3, smps3),
288         TPS_REG(SMPS4, smps4),
289         TPS_REG(LDO1, ldo1),
290         TPS_REG(LDO2, ldo2),
291         TPS_REG(LDO3, ldo3),
292         TPS_REG(LDO4, ldo4),
293         TPS_REG(LDO5, ldo5),
294         TPS_REG(LDO6, ldo6),
295         TPS_REG(LDO7, ldo7),
296         TPS_REG(LDOLN, ldoln),
297         TPS_REG(LDOUSB, ldousb),
298         TPS_REG(VANA, vana),
299         TPS_REG(VBUS, vbus),
300         TPS_RTC(),
301         TPS_BATTERY(),
302         TPS_BATTERY_GAUGE(),
303         TPS_GPADC(),
304 };
305
306 struct tps80031_clk32k_init_data clk32k_idata[] = {
307         {
308                 .clk32k_nr = TPS80031_CLOCK32K_G,
309                 .enable = true,
310                 .ext_ctrl_flag = 0,
311         },
312         {
313                 .clk32k_nr = TPS80031_CLOCK32K_AUDIO,
314                 .enable = true,
315                 .ext_ctrl_flag = 0,
316         },
317 };
318
319 static struct tps80031_platform_data tps_platform = {
320         .num_subdevs    = ARRAY_SIZE(tps80031_devs),
321         .subdevs        = tps80031_devs,
322         .irq_base       = ENT_TPS80031_IRQ_BASE,
323         .gpio_base      = ENT_TPS80031_GPIO_BASE,
324         .clk32k_init_data       = clk32k_idata,
325         .clk32k_init_data_size  = ARRAY_SIZE(clk32k_idata),
326         .use_power_off  = true,
327 };
328
329 static struct i2c_board_info __initdata enterprise_regulators[] = {
330         {
331                 I2C_BOARD_INFO("tps80031", 0x4A),
332                 .irq            = INT_EXTERNAL_PMU,
333                 .platform_data  = &tps_platform,
334         },
335 };
336
337 /************************ GPIO based fixed regulator ****************/
338 /* REGEN1 from PMU*/
339 static struct regulator_consumer_supply fixed_reg_pmu_5v15_en_supply[] = {
340         REGULATOR_SUPPLY("vdd_5v15", NULL),
341 };
342
343 /* REGEN2 from PMU*/
344 static struct regulator_consumer_supply fixed_reg_pmu_3v3_en_supply[] = {
345         REGULATOR_SUPPLY("avdd_usb_hdmi_3v3", NULL),
346         REGULATOR_SUPPLY("avdd_usb", NULL),
347         REGULATOR_SUPPLY("avdd_hdmi", NULL),
348         REGULATOR_SUPPLY("vdd", "4-004c"),
349 };
350
351 /* SYSEN from PMU*/
352 static struct regulator_consumer_supply fixed_reg_pmu_hdmi_5v0_en_supply[] = {
353         REGULATOR_SUPPLY("hdmi_5v0", NULL),
354 };
355
356 /* LCD-D16 (GPIO M0) from T30*/
357 static struct regulator_consumer_supply fixed_reg_vdd_fuse_en_supply[] = {
358         REGULATOR_SUPPLY("vdd_fuse", NULL),
359 };
360
361 /* LCD-D17 (GPIO M1) from T30*/
362 static struct regulator_consumer_supply gpio_reg_sdmmc3_vdd_sel_supply[] = {
363         REGULATOR_SUPPLY("vddio_sdmmc3_2v85_1v8", NULL),
364         REGULATOR_SUPPLY("sdmmc3_compu_pu", NULL),
365         REGULATOR_SUPPLY("vddio_sdmmc3", NULL),
366         REGULATOR_SUPPLY("vsys_3v7", NULL),
367 };
368
369 /* LCD-D23 (GPIO M7) from T30*/
370 /* 2-0036 is dev_name of ar0832 in Enterprise A01*/
371 /* 2-0032 is alternative dev_name of ar0832 Enterprise A01*/
372 /* 2-0010 is dev_name of ov9726 */
373 /* 2-0070 is dev_name of PCA9546 in Enterprise A02*/
374 /* 6-0036 is dev_name of ar0832 in Enterprise A02 */
375 /* 7-0036 is dev_name of ar0832 in Enterprise A02 */
376 static struct regulator_consumer_supply fixed_reg_cam_ldo_2v8_en_supply[] = {
377         REGULATOR_SUPPLY("vaa", "2-0036"),
378         REGULATOR_SUPPLY("vaa", "2-0032"),
379         REGULATOR_SUPPLY("avdd", "2-0010"),
380         REGULATOR_SUPPLY("vdd_2v8_cam", NULL),
381         REGULATOR_SUPPLY("vcc", "2-0070"),
382         REGULATOR_SUPPLY("vaa", "6-0036"),
383         REGULATOR_SUPPLY("vaa", "7-0036"),
384 };
385
386 /* LCD-D9 (GPIO F1) from T30*/
387 /* 2-0036 is dev_name of ar0832 in Enterprise A01*/
388 /* 2-0032 is alternative dev_name of ar0832 Enterprise A01*/
389 /* 2-0010 is dev_name of ov9726 */
390 /* 2-0033 is dev_name of tps61050 */
391 /* 2-0070 is dev_name of PCA9546 in Enterprise A02*/
392 /* 6-0036 is dev_name of ar0832 in Enterprise A02 */
393 /* 7-0036 is dev_name of ar0832 in Enterprise A02 */
394 static struct regulator_consumer_supply fixed_reg_cam_ldo_1v8_en_supply[] = {
395         REGULATOR_SUPPLY("vdd", "2-0036"),
396         REGULATOR_SUPPLY("vdd", "2-0032"),
397         REGULATOR_SUPPLY("dovdd", "2-0010"),
398         REGULATOR_SUPPLY("vdd_1v8_cam", NULL),
399         REGULATOR_SUPPLY("vdd_i2c", "2-0033"),
400         REGULATOR_SUPPLY("vcc_i2c", "2-0070"),
401         REGULATOR_SUPPLY("vdd", "6-0036"),
402         REGULATOR_SUPPLY("vdd", "7-0036"),
403 };
404
405 static struct gpio_regulator_state gpio_reg_sdmmc3_vdd_sel_states[] = {
406         {
407                 .gpios = 0,
408                 .value = 2850000,
409         },
410         {
411                 .gpios = 1,
412                 .value = 1800000,
413         },
414 };
415
416 static struct gpio gpio_reg_sdmmc3_vdd_sel_gpios[] = {
417         {
418                 .gpio = TEGRA_GPIO_PM1,
419                 .flags = 0,
420                 .label = "sdmmc3_vdd_sel",
421         },
422 };
423
424 /* Macro for defining gpio regulator device data */
425 #define GPIO_REG(_id, _name, _input_supply, _active_high,               \
426         _boot_state, _delay_us, _minmv, _maxmv)                         \
427         static struct regulator_init_data ri_data_##_name =             \
428         {                                                               \
429                 .supply_regulator = _input_supply,                      \
430                 .num_consumer_supplies =                                \
431                         ARRAY_SIZE(gpio_reg_##_name##_supply),          \
432                 .consumer_supplies = gpio_reg_##_name##_supply,         \
433                 .constraints = {                                        \
434                         .name = "gpio_reg_"#_name,                      \
435                         .min_uV = (_minmv)*1000,                        \
436                         .max_uV = (_maxmv)*1000,                        \
437                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
438                                         REGULATOR_MODE_STANDBY),        \
439                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
440                                         REGULATOR_CHANGE_STATUS |       \
441                                         REGULATOR_CHANGE_VOLTAGE),      \
442                 },                                                      \
443         };                                                              \
444         static struct gpio_regulator_config gpio_reg_##_name##_pdata =  \
445         {                                                               \
446                 .supply_name = _input_supply,                           \
447                 .enable_gpio = -EINVAL,                                 \
448                 .enable_high = _active_high,                            \
449                 .enabled_at_boot = _boot_state,                         \
450                 .startup_delay = _delay_us,                             \
451                 .gpios = gpio_reg_##_name##_gpios,                      \
452                 .nr_gpios = ARRAY_SIZE(gpio_reg_##_name##_gpios),       \
453                 .states = gpio_reg_##_name##_states,                    \
454                 .nr_states = ARRAY_SIZE(gpio_reg_##_name##_states),     \
455                 .type = REGULATOR_VOLTAGE,                              \
456                 .init_data = &ri_data_##_name,                          \
457         };                                                              \
458         static struct platform_device gpio_reg_##_name##_dev = {        \
459                 .name   = "gpio-regulator",                             \
460                 .id = _id,                                              \
461                 .dev    = {                                             \
462                         .platform_data = &gpio_reg_##_name##_pdata,     \
463                 },                                                      \
464         }
465
466 GPIO_REG(4, sdmmc3_vdd_sel,  tps80031_rails(SMPS4),
467                 true, false, 0, 1000, 3300);
468
469 /* Macro for defining fixed regulator sub device data */
470 #define FIXED_REG(_id, _name, _input_supply, _gpio_nr, _active_high,    \
471                         _millivolts, _boot_state)                       \
472         static struct regulator_init_data ri_data_##_name =             \
473         {                                                               \
474                 .supply_regulator = _input_supply,                      \
475                 .num_consumer_supplies =                                \
476                         ARRAY_SIZE(fixed_reg_##_name##_supply),         \
477                 .consumer_supplies = fixed_reg_##_name##_supply,        \
478                 .constraints = {                                        \
479                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
480                                         REGULATOR_MODE_STANDBY),        \
481                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
482                                         REGULATOR_CHANGE_STATUS |       \
483                                         REGULATOR_CHANGE_VOLTAGE),      \
484                 },                                                      \
485         };                                                              \
486         static struct fixed_voltage_config fixed_reg_##_name##_pdata =  \
487         {                                                               \
488                 .supply_name = "fixed_reg_"#_name,                      \
489                 .microvolts = _millivolts * 1000,                       \
490                 .gpio = _gpio_nr,                                       \
491                 .enable_high = _active_high,                            \
492                 .enabled_at_boot = _boot_state,                         \
493                 .init_data = &ri_data_##_name,                          \
494         };                                                              \
495         static struct platform_device fixed_reg_##_name##_dev = {       \
496                 .name   = "reg-fixed-voltage",                          \
497                 .id     = _id,                                          \
498                 .dev    = {                                             \
499                         .platform_data = &fixed_reg_##_name##_pdata,    \
500                 },                                                      \
501         }
502
503 FIXED_REG(0, pmu_5v15_en,     NULL,
504                 ENT_TPS80031_GPIO_REGEN1, true, 5000, 0 );
505 FIXED_REG(1, pmu_3v3_en,      "fixed_reg_pmu_5v15_en",
506                 ENT_TPS80031_GPIO_REGEN2, true, 3300, 0);
507 FIXED_REG(2, pmu_hdmi_5v0_en, "fixed_reg_pmu_5v15_en",
508                 ENT_TPS80031_GPIO_SYSEN, true, 5000, 0);
509 FIXED_REG(3, vdd_fuse_en,     "fixed_reg_pmu_3v3_en",
510                 TEGRA_GPIO_PM0, true, 3300, 0);
511 FIXED_REG(5, cam_ldo_2v8_en,  NULL,
512                 TEGRA_GPIO_PM7, true, 2800, 0);
513 FIXED_REG(6, cam_ldo_1v8_en,  NULL,
514                 TEGRA_GPIO_PF1, true, 1800, 0);
515
516 #define ADD_FIXED_REG(_name)    (&fixed_reg_##_name##_dev)
517 static struct platform_device *fixed_regs_devices[] = {
518         ADD_FIXED_REG(pmu_5v15_en),
519         ADD_FIXED_REG(pmu_3v3_en),
520         ADD_FIXED_REG(pmu_hdmi_5v0_en),
521         ADD_FIXED_REG(vdd_fuse_en),
522         ADD_FIXED_REG(cam_ldo_2v8_en),
523         ADD_FIXED_REG(cam_ldo_1v8_en),
524 };
525
526 #define ADD_GPIO_REG(_name) (&gpio_reg_##_name##_dev)
527 static struct platform_device *gpio_regs_devices[] = {
528         ADD_GPIO_REG(sdmmc3_vdd_sel),
529 };
530
531 static int __init enterprise_fixed_regulator_init(void)
532 {
533         int i;
534
535         for (i = 0; i < ARRAY_SIZE(fixed_regs_devices); ++i) {
536                 struct fixed_voltage_config *fixed_reg_pdata =
537                                 fixed_regs_devices[i]->dev.platform_data;
538                 if (fixed_reg_pdata->gpio < TEGRA_NR_GPIOS)
539                         tegra_gpio_enable(fixed_reg_pdata->gpio);
540         }
541         return platform_add_devices(fixed_regs_devices,
542                                 ARRAY_SIZE(fixed_regs_devices));
543 }
544
545 static int __init enterprise_gpio_regulator_init(void)
546 {
547         int i, j;
548
549         for (i = 0; i < ARRAY_SIZE(gpio_regs_devices); ++i) {
550                 struct gpio_regulator_config *gpio_reg_pdata =
551                         gpio_regs_devices[i]->dev.platform_data;
552                 for (j = 0; j < gpio_reg_pdata->nr_gpios; ++j) {
553                         if (gpio_reg_pdata->gpios[j].gpio < TEGRA_NR_GPIOS)
554                                 tegra_gpio_enable(gpio_reg_pdata->gpios[j].gpio);
555                 }
556         }
557         return platform_add_devices(gpio_regs_devices,
558                                     ARRAY_SIZE(gpio_regs_devices));
559 }
560
561 static int __init enterprise_regulators_fixed_gpio_init(void)
562 {
563         int ret;
564
565         if (!is_enterprise_machine)
566                 return 0;
567
568         ret = enterprise_fixed_regulator_init();
569         if (ret)
570                 return ret;
571
572         ret = enterprise_gpio_regulator_init();
573         return ret;
574 }
575 subsys_initcall_sync(enterprise_regulators_fixed_gpio_init);
576
577 void __init enterprise_tsensor_init(void)
578 {
579         tegra3_tsensor_init(NULL);
580 }
581
582 int __init enterprise_regulator_init(void)
583 {
584         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
585         u32 pmc_ctrl;
586         u32 pmc_dpd_pads;
587
588         /* configure the power management controller to trigger PMU
589          * interrupts when low */
590
591         pmc_ctrl = readl(pmc + PMC_CTRL);
592         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
593
594         pmc_dpd_pads = readl(pmc + PMC_DPD_PADS_ORIDE);
595         writel(pmc_dpd_pads & ~PMC_DPD_PADS_ORIDE_BLINK , pmc + PMC_DPD_PADS_ORIDE);
596
597         /* Disable battery charging if power adapter is connected. */
598         if (get_power_supply_type() == POWER_SUPPLY_TYPE_MAINS) {
599                 bcharger_pdata.num_consumer_supplies = 0;
600                 bcharger_pdata.consumer_supplies = NULL;
601                 battery_gauge_data.battery_present = 0;
602         }
603
604         i2c_register_board_info(4, enterprise_regulators, 1);
605         is_enterprise_machine = true;
606
607         return 0;
608 }
609
610 static void enterprise_board_suspend(int lp_state, enum suspend_stage stg)
611 {
612         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_SUSPEND_BEFORE_CPU))
613                 tegra_console_uart_suspend();
614 }
615
616 static void enterprise_board_resume(int lp_state, enum resume_stage stg)
617 {
618         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_RESUME_AFTER_CPU))
619                 tegra_console_uart_resume();
620 }
621
622 static struct tegra_suspend_platform_data enterprise_suspend_data = {
623         .cpu_timer      = 2000,
624         .cpu_off_timer  = 200,
625         .suspend_mode   = TEGRA_SUSPEND_LP0,
626         .core_timer     = 0x7e7e,
627         .core_off_timer = 0,
628         .corereq_high   = true,
629         .sysclkreq_high = true,
630         .board_suspend = enterprise_board_suspend,
631         .board_resume = enterprise_board_resume,
632 };
633
634 static void enterprise_init_deep_sleep_mode(void)
635 {
636         struct board_info bi;
637         tegra_get_board_info(&bi);
638
639         if (bi.board_id == BOARD_E1205 && bi.fab == BOARD_FAB_A01)
640                 enterprise_suspend_data.suspend_mode = TEGRA_SUSPEND_LP1;
641
642         if ((bi.board_id == BOARD_E1205 && (bi.sku & BOARD_SKU_VF_BIT) == 0) ||
643             (bi.board_id == BOARD_E1197 && (bi.sku & BOARD_SKU_VF_BIT)))
644                 enterprise_suspend_data.cpu_timer = 8000;
645 }
646
647 int __init enterprise_suspend_init(void)
648 {
649         enterprise_init_deep_sleep_mode();
650         tegra_init_suspend(&enterprise_suspend_data);
651         return 0;
652 }
653
654 #ifdef CONFIG_TEGRA_EDP_LIMITS
655
656 int __init enterprise_edp_init(void)
657 {
658         unsigned int regulator_mA;
659
660         regulator_mA = get_maximum_cpu_current_supported();
661         if (!regulator_mA) {
662                 regulator_mA = 2500; /* regular AP30 */
663         }
664         pr_info("%s: CPU regulator %d mA\n", __func__, regulator_mA);
665
666         tegra_init_cpu_edp_limits(regulator_mA);
667         tegra_init_system_edp_limits(TEGRA_BPC_CPU_PWR_LIMIT);
668         return 0;
669 }
670 #endif
671
672 static struct tegra_bpc_mgmt_platform_data bpc_mgmt_platform_data = {
673         .gpio_trigger = TEGRA_BPC_TRIGGER,
674         .bpc_mgmt_timeout = TEGRA_BPC_TIMEOUT,
675 };
676
677 static struct platform_device enterprise_bpc_mgmt_device = {
678         .name           = "tegra-bpc-mgmt",
679         .id             = -1,
680         .dev            = {
681                 .platform_data = &bpc_mgmt_platform_data,
682         },
683 };
684
685 void __init enterprise_bpc_mgmt_init(void)
686 {
687         int int_gpio = TEGRA_GPIO_TO_IRQ(TEGRA_BPC_TRIGGER);
688
689         tegra_gpio_enable(TEGRA_BPC_TRIGGER);
690
691 #ifdef CONFIG_SMP
692         cpumask_setall(&(bpc_mgmt_platform_data.affinity_mask));
693         irq_set_affinity_hint(int_gpio,
694                                 &(bpc_mgmt_platform_data.affinity_mask));
695         irq_set_affinity(int_gpio, &(bpc_mgmt_platform_data.affinity_mask));
696 #endif
697         platform_device_register(&enterprise_bpc_mgmt_device);
698
699         return;
700 }