Revert "Merge commit 'main-jb-2012.08.03-B4' into t114-0806"
[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 <asm/mach-types.h>
37
38 #include <mach/edp.h>
39 #include <mach/iomap.h>
40 #include <mach/irqs.h>
41 #include <mach/pinmux.h>
42 #include <mach/gpio-tegra.h>
43
44 #include "gpio-names.h"
45 #include "board.h"
46 #include "board-enterprise.h"
47 #include "pm.h"
48 #include "tegra3_tsensor.h"
49
50 #define PMC_CTRL                0x0
51 #define PMC_CTRL_INTR_LOW       (1 << 17)
52
53 #define PMC_DPD_PADS_ORIDE              0x01c
54 #define PMC_DPD_PADS_ORIDE_BLINK        (1 << 20)
55
56 /************************ TPS80031 based regulator ****************/
57 static struct regulator_consumer_supply tps80031_vio_supply_a02[] = {
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_vio_supply_a03[] = {
89         REGULATOR_SUPPLY("vio_1v8", NULL),
90         REGULATOR_SUPPLY("vddio_sys", NULL),
91         REGULATOR_SUPPLY("vddio_uart", NULL),
92         REGULATOR_SUPPLY("pwrdet_uart", NULL),
93         REGULATOR_SUPPLY("vddio_lcd", NULL),
94         REGULATOR_SUPPLY("pwrdet_lcd", NULL),
95         REGULATOR_SUPPLY("vddio_audio", NULL),
96         REGULATOR_SUPPLY("pwrdet_audio", NULL),
97         REGULATOR_SUPPLY("vddio_bb", NULL),
98         REGULATOR_SUPPLY("pwrdet_bb", NULL),
99         REGULATOR_SUPPLY("vddio_gmi", NULL),
100         REGULATOR_SUPPLY("vddio_cam", NULL),
101         REGULATOR_SUPPLY("pwrdet_cam", NULL),
102         REGULATOR_SUPPLY("vddio_sdmmc1", NULL),
103         REGULATOR_SUPPLY("pwrdet_sdmmc1", NULL),
104         REGULATOR_SUPPLY("vddio_sdmmc4", NULL),
105         REGULATOR_SUPPLY("pwrdet_sdmmc4", NULL),
106         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
107         REGULATOR_SUPPLY("vddio_gps", NULL),
108         REGULATOR_SUPPLY("vdd_lcd_buffered", NULL),
109         REGULATOR_SUPPLY("vddio_nand", NULL),
110         REGULATOR_SUPPLY("pwrdet_nand", NULL),
111         REGULATOR_SUPPLY("vddio_sd", NULL),
112         REGULATOR_SUPPLY("vdd_bat", NULL),
113         REGULATOR_SUPPLY("vdd_io", NULL),
114         REGULATOR_SUPPLY("pwrdet_pex_ctl", NULL),
115 };
116
117 static struct regulator_consumer_supply tps80031_smps1_supply_common[] = {
118         REGULATOR_SUPPLY("vdd_cpu", NULL),
119 };
120
121 static struct regulator_consumer_supply tps80031_smps2_supply_common[] = {
122         REGULATOR_SUPPLY("vdd_core", NULL),
123 };
124
125 static struct regulator_consumer_supply tps80031_smps3_supply_common[] = {
126         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
127         REGULATOR_SUPPLY("vddio_ddr", NULL),
128         REGULATOR_SUPPLY("vdd_lpddr", NULL),
129         REGULATOR_SUPPLY("ddr_comp_pu", NULL),
130 };
131
132 static struct regulator_consumer_supply tps80031_smps4_supply_a02[] = {
133         REGULATOR_SUPPLY("vddio_sdmmc_2v85", NULL),
134         REGULATOR_SUPPLY("pwrdet_sdmmc3", NULL),
135 };
136
137 static struct regulator_consumer_supply tps80031_smps4_supply_a03[] = {
138         REGULATOR_SUPPLY("vddio_sdmmc_2v85", NULL),
139         REGULATOR_SUPPLY("pwrdet_sdmmc3", NULL),
140         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
141         REGULATOR_SUPPLY("vddf_core_emmc", NULL),
142 };
143
144 static struct regulator_consumer_supply tps80031_vana_supply_a02[] = {
145         REGULATOR_SUPPLY("unused_vana", NULL),
146 };
147 #define tps80031_vana_supply_a03 tps80031_vana_supply_a02
148
149 static struct regulator_consumer_supply tps80031_ldo1_supply_a02[] = {
150         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
151         REGULATOR_SUPPLY("avdd_hsic", NULL),
152         REGULATOR_SUPPLY("pwrdet_mipi", NULL),
153 };
154
155 static struct regulator_consumer_supply tps80031_ldo1_supply_a03[] = {
156         REGULATOR_SUPPLY("vdd_ddr_hs", NULL),
157 };
158
159 static struct regulator_consumer_supply tps80031_ldo2_supply_common[] = {
160         REGULATOR_SUPPLY("vdd_rtc", NULL),
161 };
162
163 static struct regulator_consumer_supply tps80031_ldo3_supply_common[] = {
164         REGULATOR_SUPPLY("vdd_vbrtr", NULL),
165 };
166
167 static struct regulator_consumer_supply tps80031_ldo4_supply_a02[] = {
168         REGULATOR_SUPPLY("avdd_lcd", NULL),
169 };
170
171 static struct regulator_consumer_supply tps80031_ldo4_supply_a03[] = {
172         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
173         REGULATOR_SUPPLY("avdd_hsic", NULL),
174         REGULATOR_SUPPLY("pwrdet_mipi", NULL),
175 };
176
177 static struct regulator_consumer_supply tps80031_ldo5_supply_common[] = {
178         REGULATOR_SUPPLY("vdd_sensor", NULL),
179         REGULATOR_SUPPLY("vdd_compass", NULL),
180         REGULATOR_SUPPLY("vdd_als", NULL),
181         REGULATOR_SUPPLY("vdd_gyro", NULL),
182         REGULATOR_SUPPLY("vdd_touch", NULL),
183         REGULATOR_SUPPLY("vdd_proxim_diode", NULL),
184 };
185
186 static struct regulator_consumer_supply tps80031_ldo6_supply_a02[] = {
187         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
188         REGULATOR_SUPPLY("vddf_core_emmc", NULL),
189 };
190
191 static struct regulator_consumer_supply tps80031_ldo6_supply_a03[] = {
192         REGULATOR_SUPPLY("avdd_osc", NULL),
193         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
194 };
195
196 static struct regulator_consumer_supply tps80031_ldo7_supply_a02[] = {
197         REGULATOR_SUPPLY("vdd_plla_p_c_s", NULL),
198         REGULATOR_SUPPLY("vdd_pllm", NULL),
199         REGULATOR_SUPPLY("vdd_pllu_d", NULL),
200         REGULATOR_SUPPLY("vdd_pllx", NULL),
201 };
202
203 static struct regulator_consumer_supply tps80031_ldo7_supply_a03[] = {
204         REGULATOR_SUPPLY("avdd_lcd", NULL),
205 };
206
207 static struct regulator_consumer_supply tps80031_ldoln_supply_a02[] = {
208         REGULATOR_SUPPLY("vdd_ddr_hs", NULL),
209 };
210
211 static struct regulator_consumer_supply tps80031_ldoln_supply_a03[] = {
212         REGULATOR_SUPPLY("vdd_plla_p_c_s", NULL),
213         REGULATOR_SUPPLY("vdd_pllm", NULL),
214         REGULATOR_SUPPLY("vdd_pllu_d", NULL),
215         REGULATOR_SUPPLY("vdd_pllx", NULL),
216 };
217
218 static struct regulator_consumer_supply tps80031_ldousb_supply_a02[] = {
219         REGULATOR_SUPPLY("unused_ldousb", NULL),
220 };
221
222 static struct regulator_consumer_supply tps80031_ldousb_supply_a03[] = {
223         REGULATOR_SUPPLY("avdd_usb_hdmi_3v3", NULL),
224         REGULATOR_SUPPLY("avdd_usb", NULL),
225         REGULATOR_SUPPLY("avdd_hdmi", NULL),
226         REGULATOR_SUPPLY("vdd", "4-004c"),
227 };
228
229 static struct regulator_consumer_supply tps80031_vbus_supply_common[] = {
230         REGULATOR_SUPPLY("usb_vbus", NULL),
231 };
232
233 static struct regulator_consumer_supply tps80031_battery_charge_supply[] = {
234         REGULATOR_SUPPLY("usb_bat_chg", NULL),
235 };
236
237 #define TPS_PDATA_INIT(_id, _sname, _minmv, _maxmv, _supply_reg, _always_on,            \
238         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply,                       \
239         _flags, _ectrl, _delay)                                                         \
240         static struct tps80031_regulator_platform_data pdata_##_id##_##_sname = {       \
241                 .regulator = {                                                          \
242                         .constraints = {                                                \
243                                 .min_uV = (_minmv)*1000,                                \
244                                 .max_uV = (_maxmv)*1000,                                \
245                                 .valid_modes_mask = (REGULATOR_MODE_NORMAL |            \
246                                                 REGULATOR_MODE_STANDBY),                \
247                                 .valid_ops_mask = (REGULATOR_CHANGE_MODE |              \
248                                                 REGULATOR_CHANGE_STATUS |               \
249                                                 REGULATOR_CHANGE_VOLTAGE),              \
250                                 .always_on = _always_on,                                \
251                                 .boot_on = _boot_on,                                    \
252                                 .apply_uV = _apply_uv,                                  \
253                         },                                                              \
254                         .num_consumer_supplies =                                        \
255                                 ARRAY_SIZE(tps80031_##_id##_supply_##_sname),           \
256                         .consumer_supplies = tps80031_##_id##_supply_##_sname,          \
257                         .supply_regulator = _supply_reg,                                \
258                 },                                                                      \
259                 .init_uV =  _init_uV * 1000,                                            \
260                 .init_enable = _init_enable,                                            \
261                 .init_apply = _init_apply,                                              \
262                 .flags = _flags,                                                        \
263                 .ext_ctrl_flag = _ectrl,                                                \
264                 .delay_us = _delay,                                                     \
265         }
266
267 TPS_PDATA_INIT(vio, a02,   600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0);
268 TPS_PDATA_INIT(vio, a03,   600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0);
269 TPS_PDATA_INIT(smps1, common, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ2 | PWR_OFF_ON_SLEEP, 0);
270 TPS_PDATA_INIT(smps2, common, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
271 TPS_PDATA_INIT(smps3, common, 600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0);
272 TPS_PDATA_INIT(smps4, a02, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
273 TPS_PDATA_INIT(smps4, a03, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
274 TPS_PDATA_INIT(ldo1, a02, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0, 0, 0, 0);
275 TPS_PDATA_INIT(ldo1, a03, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
276 TPS_PDATA_INIT(ldo2, common, 1000, 3300, 0, 1, 1, 1, 1000, 1, 1, 0, 0, 0);
277 TPS_PDATA_INIT(ldo3, common, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0, 0, PWR_OFF_ON_SLEEP, 0);
278 TPS_PDATA_INIT(ldo4, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
279 TPS_PDATA_INIT(ldo4, a03, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
280 TPS_PDATA_INIT(ldo5, common, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
281 TPS_PDATA_INIT(ldo6, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
282 TPS_PDATA_INIT(ldo6, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
283 TPS_PDATA_INIT(ldo7, a02, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
284 TPS_PDATA_INIT(ldo7, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
285 TPS_PDATA_INIT(ldoln, a02, 1000, 3300, tps80031_rails(SMPS3), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
286 TPS_PDATA_INIT(ldoln, a03, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
287 TPS_PDATA_INIT(ldousb, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, USBLDO_INPUT_VSYS, PWR_OFF_ON_SLEEP, 0);
288 TPS_PDATA_INIT(ldousb, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, USBLDO_INPUT_VSYS, PWR_REQ_INPUT_PREQ1, 0);
289 TPS_PDATA_INIT(vana, a02,  1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
290 TPS_PDATA_INIT(vana, a03,  1000, 3300, 0, 0, 0, 0, -1, 0, 1, 0, PWR_OFF_ON_SLEEP, 0);
291 TPS_PDATA_INIT(vbus, common,  0, 5000, 0, 0, 0, 0, -1, 0, 0, (VBUS_SW_ONLY | VBUS_DISCHRG_EN_PDN), 0, 100000);
292
293 static struct tps80031_rtc_platform_data rtc_data = {
294         .irq = ENT_TPS80031_IRQ_BASE + TPS80031_INT_RTC_ALARM,
295         .time = {
296                 .tm_year = 2011,
297                 .tm_mon = 0,
298                 .tm_mday = 1,
299                 .tm_hour = 1,
300                 .tm_min = 2,
301                 .tm_sec = 3,
302         },
303         .msecure_gpio = TEGRA_GPIO_PF7,
304 };
305
306 int battery_charger_init(void *board_data)
307 {
308         int ret;
309         ret = gpio_request(TEGRA_GPIO_PF6, "lcd_d14-bat_charge");
310         if (ret < 0) {
311                 pr_err("%s() The gpio_request for battery"
312                                 " charger fails\n", __func__);
313         }
314         gpio_direction_output(TEGRA_GPIO_PF6, 1);
315         return 0;
316 }
317
318 static struct tps80031_charger_platform_data bcharger_pdata = {
319         .max_charge_volt_mV = 4100,
320         .max_charge_current_mA = 1000,
321         .charging_term_current_mA = 100,
322         .watch_time_sec = 100,
323         .irq_base = ENT_TPS80031_IRQ_BASE,
324         .consumer_supplies = tps80031_battery_charge_supply,
325         .num_consumer_supplies = ARRAY_SIZE(tps80031_battery_charge_supply),
326         .board_init = battery_charger_init,
327         .board_data = NULL,
328 };
329
330 static struct tps80031_bg_platform_data battery_gauge_data = {
331         .irq_base = ENT_TPS80031_IRQ_BASE,
332         .battery_present = 1,
333 };
334
335 #define TPS_RTC()                               \
336         {                                               \
337                 .id     = 0,            \
338                 .name   = "rtc_tps80031",       \
339                 .platform_data = &rtc_data,     \
340         }
341
342 #define TPS_REG(_id, _data, _sname)                             \
343         {                                                       \
344                 .id      = TPS80031_ID_##_id,                   \
345                 .name   = "tps80031-regulator",                 \
346                 .platform_data  = &pdata_##_data##_##_sname,    \
347         }
348 #define TPS_BATTERY()                                   \
349         {                                               \
350                 .name   = "tps80031-charger",           \
351                 .platform_data = &bcharger_pdata,       \
352         }
353 #define TPS_BATTERY_GAUGE()                             \
354         {                                               \
355                 .name   = "tps80031-battery-gauge",     \
356                 .platform_data = &battery_gauge_data,   \
357         }
358 #define TPS_GPADC()                                     \
359         {                                               \
360                 .name   = "tps80031-gpadc",             \
361         }
362
363 #define TPS80031_DEVS_COMMON            \
364         TPS_REG(SMPS1, smps1, common),  \
365         TPS_REG(SMPS2, smps2, common),  \
366         TPS_REG(SMPS3, smps3, common),  \
367         TPS_REG(LDO2, ldo2, common),    \
368         TPS_REG(LDO3, ldo3, common),    \
369         TPS_REG(LDO5, ldo5, common),    \
370         TPS_REG(VBUS, vbus, common),    \
371         TPS_RTC(),                      \
372         TPS_BATTERY(),                  \
373         TPS_BATTERY_GAUGE(),            \
374         TPS_GPADC()
375
376
377 static struct tps80031_subdev_info tps80031_devs_a02[] = {
378         TPS_REG(VIO, vio, a02),
379         TPS80031_DEVS_COMMON,
380         TPS_REG(SMPS4, smps4, a02),
381         TPS_REG(LDO1, ldo1, a02),
382         TPS_REG(LDO4, ldo4, a02),
383         TPS_REG(LDO6, ldo6, a02),
384         TPS_REG(LDO7, ldo7, a02),
385         TPS_REG(LDOLN, ldoln, a02),
386         TPS_REG(LDOUSB, ldousb, a02),
387         TPS_REG(VANA, vana, a02),
388
389 };
390
391 static struct tps80031_subdev_info tps80031_devs_a03[] = {
392         TPS_REG(VIO, vio, a03),
393         TPS80031_DEVS_COMMON,
394         TPS_REG(SMPS4, smps4, a03),
395         TPS_REG(LDO1, ldo1, a03),
396         TPS_REG(LDO4, ldo4, a03),
397         TPS_REG(LDO6, ldo6, a03),
398         TPS_REG(LDO7, ldo7, a03),
399         TPS_REG(LDOLN, ldoln, a03),
400         TPS_REG(LDOUSB, ldousb, a03),
401         TPS_REG(VANA, vana, a03),
402
403 };
404
405 static struct tps80031_clk32k_init_data clk32k_idata[] = {
406         {
407                 .clk32k_nr = TPS80031_CLOCK32K_G,
408                 .enable = true,
409                 .ext_ctrl_flag = 0,
410         },
411         {
412                 .clk32k_nr = TPS80031_CLOCK32K_AUDIO,
413                 .enable = true,
414                 .ext_ctrl_flag = 0,
415         },
416
417
418 };
419
420 static struct tps80031_gpio_init_data gpio_idata_a03[] = {
421         {
422                 .gpio_nr = TPS80031_GPIO_REGEN1,
423                 .ext_ctrl_flag = PWR_REQ_INPUT_PREQ1,
424         },
425         {
426                 .gpio_nr = TPS80031_GPIO_REGEN2,
427                 .ext_ctrl_flag = PWR_REQ_INPUT_PREQ1,
428         },
429         {
430                 .gpio_nr = TPS80031_GPIO_SYSEN,
431                 .ext_ctrl_flag = PWR_REQ_INPUT_PREQ1,
432         },
433 };
434
435 static struct tps80031_pupd_init_data pupd_idata[] = {
436         {
437                 .input_pin = TPS80031_PREQ1,
438                 .setting = TPS80031_PUPD_PULLUP,
439         },
440 };
441
442 static struct tps80031_platform_data tps_platform = {
443         .irq_base       = ENT_TPS80031_IRQ_BASE,
444         .gpio_base      = ENT_TPS80031_GPIO_BASE,
445         .clk32k_init_data       = clk32k_idata,
446         .clk32k_init_data_size  = ARRAY_SIZE(clk32k_idata),
447         .use_power_off  = true,
448 };
449
450 static struct i2c_board_info __initdata enterprise_regulators[] = {
451         {
452                 I2C_BOARD_INFO("tps80031", 0x4A),
453                 .irq            = INT_EXTERNAL_PMU,
454                 .platform_data  = &tps_platform,
455         },
456 };
457
458 /************************ GPIO based fixed regulator ****************/
459 /* REGEN1 from PMU*/
460 static struct regulator_consumer_supply fixed_reg_pmu_5v15_en_supply[] = {
461         REGULATOR_SUPPLY("vdd_5v15", NULL),
462 };
463
464 /* REGEN2 from PMU*/
465 static struct regulator_consumer_supply fixed_reg_pmu_3v3_en_supply[] = {
466         REGULATOR_SUPPLY("avdd_usb_hdmi_3v3", NULL),
467         REGULATOR_SUPPLY("avdd_usb", NULL),
468         REGULATOR_SUPPLY("avdd_hdmi", NULL),
469         REGULATOR_SUPPLY("vdd", "4-004c"),
470 };
471
472 /* SYSEN from PMU*/
473 static struct regulator_consumer_supply fixed_reg_pmu_hdmi_5v0_en_supply[] = {
474         REGULATOR_SUPPLY("hdmi_5v0", NULL),
475 };
476
477 /* LCD-D16 (GPIO M0) from T30*/
478 static struct regulator_consumer_supply fixed_reg_vdd_fuse_en_supply[] = {
479         REGULATOR_SUPPLY("vdd_fuse", NULL),
480 };
481
482 /* LCD-D17 (GPIO M1) from T30*/
483 static struct regulator_consumer_supply gpio_reg_sdmmc3_vdd_sel_supply[] = {
484         REGULATOR_SUPPLY("vddio_sdmmc3_2v85_1v8", NULL),
485         REGULATOR_SUPPLY("sdmmc3_compu_pu", NULL),
486         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.2"),
487         REGULATOR_SUPPLY("vsys_3v7", NULL),
488 };
489
490 /* LCD-D23 (GPIO M7) from T30*/
491 /* 2-0036 is dev_name of ar0832 in Enterprise A01*/
492 /* 2-0032 is alternative dev_name of ar0832 Enterprise A01*/
493 /* 2-0010 is dev_name of ov9726 */
494 /* 2-0070 is dev_name of PCA9546 in Enterprise A02*/
495 /* 6-0036 is dev_name of ar0832 in Enterprise A02 */
496 /* 7-0036 is dev_name of ar0832 in Enterprise A02 */
497 static struct regulator_consumer_supply fixed_reg_cam_ldo_2v8_en_supply[] = {
498         REGULATOR_SUPPLY("vaa", "2-0036"),
499         REGULATOR_SUPPLY("vaa", "2-0032"),
500         REGULATOR_SUPPLY("avdd", "2-0010"),
501         REGULATOR_SUPPLY("vdd_2v8_cam", NULL),
502         REGULATOR_SUPPLY("vcc", "2-0070"),
503         REGULATOR_SUPPLY("vaa", "6-0036"),
504         REGULATOR_SUPPLY("vaa", "7-0036"),
505 };
506
507 /* LCD-D9 (GPIO F1) from T30*/
508 /* 2-0036 is dev_name of ar0832 in Enterprise A01*/
509 /* 2-0032 is alternative dev_name of ar0832 Enterprise A01*/
510 /* 2-0010 is dev_name of ov9726 */
511 /* 2-0033 is dev_name of tps61050 */
512 /* 2-0070 is dev_name of PCA9546 in Enterprise A02*/
513 /* 6-0036 is dev_name of ar0832 in Enterprise A02 */
514 /* 7-0036 is dev_name of ar0832 in Enterprise A02 */
515 static struct regulator_consumer_supply fixed_reg_cam_ldo_1v8_en_supply[] = {
516         REGULATOR_SUPPLY("vdd", "2-0036"),
517         REGULATOR_SUPPLY("vdd", "2-0032"),
518         REGULATOR_SUPPLY("dovdd", "2-0010"),
519         REGULATOR_SUPPLY("vdd_1v8_cam", NULL),
520         REGULATOR_SUPPLY("vdd_i2c", "2-0033"),
521         REGULATOR_SUPPLY("vcc_i2c", "2-0070"),
522         REGULATOR_SUPPLY("vdd", "6-0036"),
523         REGULATOR_SUPPLY("vdd", "7-0036"),
524 };
525
526 /* LCD-D10 (GPIO F2) from T30*/
527 static struct regulator_consumer_supply fixed_reg_vdd_sdmmc3_2v85_en_supply[] = {
528         REGULATOR_SUPPLY("en_vdd_sdmmc3", NULL),
529         REGULATOR_SUPPLY("vddio_sd_slot", "sdhci-tegra.2"),
530 };
531
532 /* LCD_PWR0 (GPIO B2) from T30*/
533 static struct regulator_consumer_supply fixed_reg_lcd_1v8_en_supply[] = {
534         REGULATOR_SUPPLY("lcd_vddio_en", NULL),
535 };
536
537 static struct gpio_regulator_state gpio_reg_sdmmc3_vdd_sel_states[] = {
538         {
539                 .gpios = 0,
540                 .value = 2850000,
541         },
542         {
543                 .gpios = 1,
544                 .value = 1800000,
545         },
546 };
547
548 static struct gpio gpio_reg_sdmmc3_vdd_sel_gpios[] = {
549         {
550                 .gpio = TEGRA_GPIO_PM1,
551                 .flags = 0,
552                 .label = "sdmmc3_vdd_sel",
553         },
554 };
555
556 /* Macro for defining gpio regulator device data */
557 #define GPIO_REG(_id, _name, _input_supply, _active_high,               \
558         _boot_state, _delay_us, _minmv, _maxmv)                         \
559         static struct regulator_init_data ri_data_##_name =             \
560         {                                                               \
561                 .supply_regulator = _input_supply,                      \
562                 .num_consumer_supplies =                                \
563                         ARRAY_SIZE(gpio_reg_##_name##_supply),          \
564                 .consumer_supplies = gpio_reg_##_name##_supply,         \
565                 .constraints = {                                        \
566                         .name = "gpio_reg_"#_name,                      \
567                         .min_uV = (_minmv)*1000,                        \
568                         .max_uV = (_maxmv)*1000,                        \
569                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
570                                         REGULATOR_MODE_STANDBY),        \
571                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
572                                         REGULATOR_CHANGE_STATUS |       \
573                                         REGULATOR_CHANGE_VOLTAGE),      \
574                 },                                                      \
575         };                                                              \
576         static struct gpio_regulator_config gpio_reg_##_name##_pdata =  \
577         {                                                               \
578                 .supply_name = _input_supply,                           \
579                 .enable_gpio = -EINVAL,                                 \
580                 .enable_high = _active_high,                            \
581                 .enabled_at_boot = _boot_state,                         \
582                 .startup_delay = _delay_us,                             \
583                 .gpios = gpio_reg_##_name##_gpios,                      \
584                 .nr_gpios = ARRAY_SIZE(gpio_reg_##_name##_gpios),       \
585                 .states = gpio_reg_##_name##_states,                    \
586                 .nr_states = ARRAY_SIZE(gpio_reg_##_name##_states),     \
587                 .type = REGULATOR_VOLTAGE,                              \
588                 .init_data = &ri_data_##_name,                          \
589         };                                                              \
590         static struct platform_device gpio_reg_##_name##_dev = {        \
591                 .name   = "gpio-regulator",                             \
592                 .id = _id,                                              \
593                 .dev    = {                                             \
594                         .platform_data = &gpio_reg_##_name##_pdata,     \
595                 },                                                      \
596         }
597
598 GPIO_REG(4, sdmmc3_vdd_sel,  tps80031_rails(SMPS4),
599                 true, false, 0, 1000, 3300);
600
601 /* Macro for defining fixed regulator sub device data */
602 #define FIXED_REG(_id, _name, _input_supply, _gpio_nr, _active_high,    \
603                         _millivolts, _boot_state, _sdelay)              \
604         static struct regulator_init_data ri_data_##_name =             \
605         {                                                               \
606                 .supply_regulator = _input_supply,                      \
607                 .num_consumer_supplies =                                \
608                         ARRAY_SIZE(fixed_reg_##_name##_supply),         \
609                 .consumer_supplies = fixed_reg_##_name##_supply,        \
610                 .constraints = {                                        \
611                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
612                                         REGULATOR_MODE_STANDBY),        \
613                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
614                                         REGULATOR_CHANGE_STATUS |       \
615                                         REGULATOR_CHANGE_VOLTAGE),      \
616                 },                                                      \
617         };                                                              \
618         static struct fixed_voltage_config fixed_reg_##_name##_pdata =  \
619         {                                                               \
620                 .supply_name = "fixed_reg_"#_name,                      \
621                 .microvolts = _millivolts * 1000,                       \
622                 .gpio = _gpio_nr,                                       \
623                 .enable_high = _active_high,                            \
624                 .enabled_at_boot = _boot_state,                         \
625                 .init_data = &ri_data_##_name,                          \
626                 .startup_delay = _sdelay,                               \
627         };                                                              \
628         static struct platform_device fixed_reg_##_name##_dev = {       \
629                 .name   = "reg-fixed-voltage",                          \
630                 .id     = _id,                                          \
631                 .dev    = {                                             \
632                         .platform_data = &fixed_reg_##_name##_pdata,    \
633                 },                                                      \
634         }
635
636 FIXED_REG(0, pmu_5v15_en,     NULL,
637                 ENT_TPS80031_GPIO_REGEN1, true, 5000, 0 , 0);
638 FIXED_REG(2, pmu_hdmi_5v0_en, "fixed_reg_pmu_5v15_en",
639                 ENT_TPS80031_GPIO_SYSEN, true, 5000, 0, 0);
640 FIXED_REG(3, vdd_fuse_en,     "fixed_reg_pmu_3v3_en",
641                 TEGRA_GPIO_PM0, true, 3300, 0, 0);
642 FIXED_REG(5, cam_ldo_2v8_en,  NULL,
643                 TEGRA_GPIO_PM7, true, 2800, 0, 0);
644 FIXED_REG(6, cam_ldo_1v8_en,  NULL,
645                 TEGRA_GPIO_PF1, true, 1800, 0, 0);
646
647 /* Enterprise A02- specific */
648 FIXED_REG(1, pmu_3v3_en,      "fixed_reg_pmu_5v15_en",
649                 ENT_TPS80031_GPIO_REGEN2, true, 3300, 0, 500);
650
651 /* Enterprise A03+ specific */
652 FIXED_REG(7, vdd_sdmmc3_2v85_en,  NULL,
653                 TEGRA_GPIO_PF2, true, 2850, 0, 0);
654 FIXED_REG(8, lcd_1v8_en,  NULL,
655                 TEGRA_GPIO_PB2, true, 1800, 0, 0);
656
657 #define ADD_FIXED_REG(_name)    (&fixed_reg_##_name##_dev)
658
659 #define FIXED_REGS_COMMON               \
660         ADD_FIXED_REG(pmu_5v15_en),     \
661         ADD_FIXED_REG(pmu_hdmi_5v0_en), \
662         ADD_FIXED_REG(vdd_fuse_en),     \
663         ADD_FIXED_REG(cam_ldo_2v8_en),  \
664         ADD_FIXED_REG(cam_ldo_1v8_en)
665
666 static struct platform_device *fixed_regs_devices_a02[] = {
667         ADD_FIXED_REG(pmu_5v15_en),     \
668         ADD_FIXED_REG(pmu_3v3_en),      \
669         ADD_FIXED_REG(pmu_hdmi_5v0_en), \
670         ADD_FIXED_REG(vdd_fuse_en),     \
671         ADD_FIXED_REG(cam_ldo_2v8_en),  \
672         ADD_FIXED_REG(cam_ldo_1v8_en)
673 };
674
675 static struct platform_device *fixed_regs_devices_a03[] = {
676         FIXED_REGS_COMMON,
677         ADD_FIXED_REG(vdd_sdmmc3_2v85_en),
678         ADD_FIXED_REG(lcd_1v8_en),
679 };
680
681 #define ADD_GPIO_REG(_name) (&gpio_reg_##_name##_dev)
682 static struct platform_device *gpio_regs_devices[] = {
683         ADD_GPIO_REG(sdmmc3_vdd_sel),
684 };
685
686 static int __init enterprise_fixed_regulator_init(void)
687 {
688         struct board_info board_info;
689         struct platform_device **fixed_regs_devices;
690         int nfixreg_devs;
691
692         tegra_get_board_info(&board_info);
693
694         if (board_info.fab < BOARD_FAB_A03) {
695                 fixed_regs_devices = fixed_regs_devices_a02;
696                 nfixreg_devs = ARRAY_SIZE(fixed_regs_devices_a02);
697         } else {
698                 fixed_regs_devices = fixed_regs_devices_a03;
699                 nfixreg_devs = ARRAY_SIZE(fixed_regs_devices_a03);
700         }
701
702         return platform_add_devices(fixed_regs_devices, nfixreg_devs);
703 }
704
705 static int __init enterprise_gpio_regulator_init(void)
706 {
707         return platform_add_devices(gpio_regs_devices,
708                                     ARRAY_SIZE(gpio_regs_devices));
709 }
710
711 static int __init enterprise_regulators_fixed_gpio_init(void)
712 {
713         int ret;
714
715         if (!machine_is_tegra_enterprise())
716                 return 0;
717
718         ret = enterprise_fixed_regulator_init();
719         if (ret)
720                 return ret;
721
722         ret = enterprise_gpio_regulator_init();
723         return ret;
724 }
725 subsys_initcall_sync(enterprise_regulators_fixed_gpio_init);
726
727 int __init enterprise_regulator_init(void)
728 {
729         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
730         u32 pmc_ctrl;
731         u32 pmc_dpd_pads;
732         struct board_info board_info;
733
734         tegra_get_board_info(&board_info);
735
736         /* configure the power management controller to trigger PMU
737          * interrupts when low */
738
739         pmc_ctrl = readl(pmc + PMC_CTRL);
740         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
741
742         pmc_dpd_pads = readl(pmc + PMC_DPD_PADS_ORIDE);
743         writel(pmc_dpd_pads & ~PMC_DPD_PADS_ORIDE_BLINK , pmc + PMC_DPD_PADS_ORIDE);
744
745         /* Setting CPU voltage tolerance in lower side for 3000uV */
746         pdata_smps1_common.tolerance_uv = 3000;
747
748         /* Disable battery charging if power adapter is connected. */
749         if (get_power_supply_type() == POWER_SUPPLY_TYPE_MAINS) {
750                 bcharger_pdata.num_consumer_supplies = 0;
751                 bcharger_pdata.consumer_supplies = NULL;
752                 battery_gauge_data.battery_present = 0;
753         }
754
755         tegra_gpio_enable(TEGRA_GPIO_PF7);
756
757         if (board_info.fab < BOARD_FAB_A03) {
758                 tps_platform.num_subdevs = ARRAY_SIZE(tps80031_devs_a02);
759                 tps_platform.subdevs = tps80031_devs_a02;
760         } else {
761                 tps_platform.num_subdevs = ARRAY_SIZE(tps80031_devs_a03);
762                 tps_platform.subdevs = tps80031_devs_a03;
763                 tps_platform.pupd_init_data = pupd_idata;
764                 tps_platform.pupd_init_data_size = ARRAY_SIZE(pupd_idata);
765                 tps_platform.gpio_init_data = gpio_idata_a03;
766                 tps_platform.gpio_init_data_size = ARRAY_SIZE(gpio_idata_a03);
767         }
768
769         i2c_register_board_info(4, enterprise_regulators, 1);
770         return 0;
771 }
772
773 static void enterprise_board_suspend(int lp_state, enum suspend_stage stg)
774 {
775         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_SUSPEND_BEFORE_CPU))
776                 tegra_console_uart_suspend();
777 }
778
779 static void enterprise_board_resume(int lp_state, enum resume_stage stg)
780 {
781         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_RESUME_AFTER_CPU))
782                 tegra_console_uart_resume();
783 }
784
785 static struct tegra_suspend_platform_data enterprise_suspend_data = {
786         .cpu_timer      = 2000,
787         .cpu_off_timer  = 200,
788         .suspend_mode   = TEGRA_SUSPEND_LP0,
789         .core_timer     = 0x7e7e,
790         .core_off_timer = 0,
791         .corereq_high   = true,
792         .sysclkreq_high = true,
793         .board_suspend = enterprise_board_suspend,
794         .board_resume = enterprise_board_resume,
795 };
796
797 static void enterprise_init_deep_sleep_mode(void)
798 {
799         struct board_info bi;
800         tegra_get_board_info(&bi);
801
802         if (bi.board_id == BOARD_E1205 && bi.fab == BOARD_FAB_A01)
803                 enterprise_suspend_data.suspend_mode = TEGRA_SUSPEND_LP1;
804
805         if ((bi.board_id == BOARD_E1205 && (bi.sku & BOARD_SKU_VF_BIT) == 0) ||
806             (bi.board_id == BOARD_E1197 && (bi.sku & BOARD_SKU_VF_BIT)))
807                 enterprise_suspend_data.cpu_timer = 8000;
808 }
809
810 int __init enterprise_suspend_init(void)
811 {
812         enterprise_init_deep_sleep_mode();
813         tegra_init_suspend(&enterprise_suspend_data);
814         return 0;
815 }
816
817 #ifdef CONFIG_TEGRA_EDP_LIMITS
818
819 int __init enterprise_edp_init(void)
820 {
821         unsigned int regulator_mA;
822
823         regulator_mA = get_maximum_cpu_current_supported();
824         if (!regulator_mA) {
825                 regulator_mA = 2500; /* regular AP30 */
826         }
827         pr_info("%s: CPU regulator %d mA\n", __func__, regulator_mA);
828
829         tegra_init_cpu_edp_limits(regulator_mA);
830         tegra_init_system_edp_limits(TEGRA_BPC_CPU_PWR_LIMIT);
831         return 0;
832 }
833 #endif
834
835 static struct tegra_bpc_mgmt_platform_data bpc_mgmt_platform_data = {
836         .gpio_trigger = TEGRA_BPC_TRIGGER,
837         .bpc_mgmt_timeout = TEGRA_BPC_TIMEOUT,
838 };
839
840 static struct platform_device enterprise_bpc_mgmt_device = {
841         .name           = "tegra-bpc-mgmt",
842         .id             = -1,
843         .dev            = {
844                 .platform_data = &bpc_mgmt_platform_data,
845         },
846 };
847
848 void __init enterprise_bpc_mgmt_init(void)
849 {
850 #ifdef CONFIG_SMP
851         int int_gpio = gpio_to_irq(TEGRA_BPC_TRIGGER);
852
853         cpumask_setall(&(bpc_mgmt_platform_data.affinity_mask));
854         irq_set_affinity_hint(int_gpio,
855                                 &(bpc_mgmt_platform_data.affinity_mask));
856         irq_set_affinity(int_gpio, &(bpc_mgmt_platform_data.affinity_mask));
857 #endif
858         platform_device_register(&enterprise_bpc_mgmt_device);
859
860         return;
861 }