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