501a5006ea6ba4c3b876a0ae1e161c99cb919e1e
[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 <mach/suspend.h>
30 #include <linux/io.h>
31
32 #include <mach/iomap.h>
33 #include <mach/irqs.h>
34 #include <mach/pinmux.h>
35
36 #include "gpio-names.h"
37 #include "board-enterprise.h"
38 #include "power.h"
39 #include "wakeups-t3.h"
40
41 /************************ TPS80031 based regulator ****************/
42 static struct regulator_consumer_supply tps80031_vio_supply[] = {
43         REGULATOR_SUPPLY("vio_1v8", NULL),
44         REGULATOR_SUPPLY("avdd_osc", NULL),
45         REGULATOR_SUPPLY("vddio_sys", NULL),
46         REGULATOR_SUPPLY("vddio_uart", NULL),
47         REGULATOR_SUPPLY("vddio_lcd", NULL),
48         REGULATOR_SUPPLY("vddio_audio", NULL),
49         REGULATOR_SUPPLY("vddio_bb", NULL),
50         REGULATOR_SUPPLY("vddio_gmi", NULL),
51         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
52         REGULATOR_SUPPLY("vddio_cam", NULL),
53         REGULATOR_SUPPLY("vddio_sdmmc1", NULL),
54         REGULATOR_SUPPLY("vddio_sdmmc4", NULL),
55         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
56         REGULATOR_SUPPLY("vddio_gps", NULL),
57         REGULATOR_SUPPLY("vdd_lcd_buffered", NULL),
58         REGULATOR_SUPPLY("vddio_nand", NULL),
59         REGULATOR_SUPPLY("vddio_sd", NULL),
60         REGULATOR_SUPPLY("vdd_bat", NULL),
61         REGULATOR_SUPPLY("vdd_io", NULL),
62 };
63
64 static struct regulator_consumer_supply tps80031_smps1_supply[] = {
65         REGULATOR_SUPPLY("vdd_cpu", NULL),
66 };
67
68 static struct regulator_consumer_supply tps80031_smps2_supply[] = {
69         REGULATOR_SUPPLY("vdd_core", NULL),
70 };
71
72 static struct regulator_consumer_supply tps80031_smps3_supply[] = {
73         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
74         REGULATOR_SUPPLY("vddio_ddr", NULL),
75         REGULATOR_SUPPLY("vdd_lpddr", NULL),
76         REGULATOR_SUPPLY("ddr_comp_pu", NULL),
77 };
78
79 static struct regulator_consumer_supply tps80031_smps4_supply[] = {
80         REGULATOR_SUPPLY("vddio_sdmmc_2v85", NULL),
81 };
82
83 static struct regulator_consumer_supply tps80031_vana_supply[] = {
84         REGULATOR_SUPPLY("unused_vana", NULL),
85 };
86
87 static struct regulator_consumer_supply tps80031_ldo1_supply[] = {
88         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
89 };
90
91 static struct regulator_consumer_supply tps80031_ldo2_supply[] = {
92         REGULATOR_SUPPLY("vdd_rtc", NULL),
93 };
94
95 static struct regulator_consumer_supply tps80031_ldo3_supply[] = {
96         REGULATOR_SUPPLY("vdd_vbrtr", NULL),
97 };
98
99 static struct regulator_consumer_supply tps80031_ldo4_supply[] = {
100         REGULATOR_SUPPLY("avdd_lcd", NULL),
101 };
102
103 static struct regulator_consumer_supply tps80031_ldo5_supply[] = {
104         REGULATOR_SUPPLY("vdd_sensor", NULL),
105         REGULATOR_SUPPLY("vdd_compass", NULL),
106         REGULATOR_SUPPLY("vdd_als", NULL),
107         REGULATOR_SUPPLY("vdd_gyro", NULL),
108         REGULATOR_SUPPLY("vdd_touch", NULL),
109         REGULATOR_SUPPLY("vdd_proxim_diode", NULL),
110 };
111
112 static struct regulator_consumer_supply tps80031_ldo6_supply[] = {
113         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
114         REGULATOR_SUPPLY("vddf_core_emmc", NULL),
115 };
116
117 static struct regulator_consumer_supply tps80031_ldo7_supply[] = {
118         REGULATOR_SUPPLY("vdd_plla_p_c_s", NULL),
119         REGULATOR_SUPPLY("vdd_pllm", NULL),
120         REGULATOR_SUPPLY("vdd_pllu_d", NULL),
121         REGULATOR_SUPPLY("vdd_pllx", NULL),
122 };
123
124 static struct regulator_consumer_supply tps80031_ldoln_supply[] = {
125         REGULATOR_SUPPLY("vdd_ddr_hs", NULL),
126 };
127
128 static struct regulator_consumer_supply tps80031_ldousb_supply[] = {
129         REGULATOR_SUPPLY("unused_ldousb", NULL),
130 };
131
132 #define TPS_PDATA_INIT(_id, _minmv, _maxmv, _supply_reg, _always_on,    \
133         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply)       \
134         static struct tps80031_regulator_platform_data pdata_##_id = {  \
135                 .regulator = {                                          \
136                         .constraints = {                                \
137                                 .min_uV = (_minmv)*1000,                \
138                                 .max_uV = (_maxmv)*1000,                \
139                                 .valid_modes_mask = (REGULATOR_MODE_NORMAL |  \
140                                                 REGULATOR_MODE_STANDBY),      \
141                                 .valid_ops_mask = (REGULATOR_CHANGE_MODE |    \
142                                                 REGULATOR_CHANGE_STATUS |     \
143                                                 REGULATOR_CHANGE_VOLTAGE),    \
144                                 .always_on = _always_on,                \
145                                 .boot_on = _boot_on,                    \
146                                 .apply_uV = _apply_uv,                  \
147                         },                                              \
148                         .num_consumer_supplies =                        \
149                                 ARRAY_SIZE(tps80031_##_id##_supply),    \
150                         .consumer_supplies = tps80031_##_id##_supply,   \
151                         .supply_regulator = _supply_reg,                \
152                 },                                                      \
153                 .init_uV =  _init_uV * 1000,                            \
154                 .init_enable = _init_enable,                            \
155                 .init_apply = _init_apply,                              \
156         }
157
158 TPS_PDATA_INIT(vio,   600, 2100, 0, 0, 0, 0, -1, 0, 0);
159 TPS_PDATA_INIT(smps1, 600, 2100, 0, 0, 0, 0, -1, 0, 0);
160 TPS_PDATA_INIT(smps2, 600, 2100, 0, 0, 0, 0, -1, 0, 0);
161 TPS_PDATA_INIT(smps3, 600, 2100, 0, 0, 0, 0, -1, 0, 0);
162 TPS_PDATA_INIT(smps4, 600, 2100, 0, 0, 0, 0, -1, 0, 0);
163
164 TPS_PDATA_INIT(ldo1, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0);
165 TPS_PDATA_INIT(ldo2, 1000, 3300, 0, 0, 0, 0, -1, 0, 0);
166 TPS_PDATA_INIT(ldo3, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0);
167 TPS_PDATA_INIT(ldo4, 1000, 3300, 0, 0, 0, 0, -1, 0, 0);
168 TPS_PDATA_INIT(ldo5, 1000, 3300, 0, 0, 0, 0, -1, 0, 0);
169 TPS_PDATA_INIT(ldo6, 1000, 3300, 0, 0, 0, 0, -1, 0, 0);
170 TPS_PDATA_INIT(ldo7, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0);
171 TPS_PDATA_INIT(ldoln, 1000, 3300, tps80031_rails(SMPS3), 0, 0, 0, -1, 0, 0);
172 TPS_PDATA_INIT(ldousb, 1000, 3300, 0, 0, 0, 0, -1, 0, 0);
173 TPS_PDATA_INIT(vana,  1000, 3300, 0, 0, 0, 0, -1, 0, 0);
174
175 #define TPS_REG(_id, _data)                             \
176         {                                               \
177                 .id      = TPS80031_ID_##_id,           \
178                 .name   = "tps80031-regulator",         \
179                 .platform_data  = &pdata_##_data,       \
180         }
181
182 static struct tps80031_subdev_info tps80031_devs[] = {
183         TPS_REG(VIO, vio),
184         TPS_REG(SMPS1, smps1),
185         TPS_REG(SMPS2, smps2),
186         TPS_REG(SMPS3, smps3),
187         TPS_REG(SMPS4, smps4),
188         TPS_REG(LDO1, ldo1),
189         TPS_REG(LDO2, ldo2),
190         TPS_REG(LDO3, ldo3),
191         TPS_REG(LDO4, ldo4),
192         TPS_REG(LDO5, ldo5),
193         TPS_REG(LDO6, ldo6),
194         TPS_REG(LDO7, ldo7),
195         TPS_REG(LDOLN, ldoln),
196         TPS_REG(LDOUSB, ldousb),
197         TPS_REG(VANA, vana),
198 };
199
200 struct tps80031_32kclock_plat_data clk32k_pdata = {
201         .en_clk32kg = 1,
202 };
203 static struct tps80031_platform_data tps_platform = {
204         .num_subdevs    = ARRAY_SIZE(tps80031_devs),
205         .subdevs        = tps80031_devs,
206         .irq_base       = TPS80031_IRQ_BASE,
207         .gpio_base      = TPS80031_GPIO_BASE,
208         .clk32k_pdata   = &clk32k_pdata,
209 };
210
211 static struct i2c_board_info __initdata enterprise_regulators[] = {
212         {
213                 I2C_BOARD_INFO("tps80031", 0x48),
214                 .irq            = INT_EXTERNAL_PMU,
215                 .platform_data  = &tps_platform,
216         },
217 };
218
219 /************************ GPIO based switch regulator ****************/
220
221 /* REGEN1 from PMU*/
222 static struct regulator_consumer_supply gpio_switch_pmu_5v15_en_supply[] = {
223         REGULATOR_SUPPLY("vdd_5v15", NULL),
224 };
225 static int gpio_switch_pmu_5v15_en_voltages[] = {5000};
226
227 /* REGEN2 from PMU*/
228 static struct regulator_consumer_supply gpio_switch_pmu_3v3_en_supply[] = {
229         REGULATOR_SUPPLY("avdd_usb_hdmi_3v3", NULL),
230         REGULATOR_SUPPLY("avdd_usb", NULL),
231         REGULATOR_SUPPLY("avdd_hdmi", NULL),
232         REGULATOR_SUPPLY("vdd_nct1008", NULL),
233 };
234 static int gpio_switch_pmu_3v3_en_voltages[] = {3300};
235
236 /* SYSEN from PMU*/
237 static struct regulator_consumer_supply gpio_switch_pmu_hdmi_5v0_en_supply[] = {
238         REGULATOR_SUPPLY("hdmi_5v0", NULL),
239 };
240 static int gpio_switch_pmu_hdmi_5v0_en_voltages[] = {5000};
241
242 /* LCD-D16 (GPIO M0) from T30*/
243 static struct regulator_consumer_supply gpio_switch_vdd_fuse_en_supply[] = {
244         REGULATOR_SUPPLY("vpp_fuse", NULL),
245 };
246 static int gpio_switch_vdd_fuse_en_voltages[] = {3300};
247
248 /* LCD-D17 (GPIO M1) from T30*/
249 static struct regulator_consumer_supply gpio_switch_sdmmc3_vdd_sel_supply[] = {
250         REGULATOR_SUPPLY("vddio_sdmmc3_2v85_1v8", NULL),
251         REGULATOR_SUPPLY("sdmmc3_compu_pu", NULL),
252         REGULATOR_SUPPLY("vddio_sdmmc3", NULL),
253 };
254 static int gpio_switch_sdmmc3_vdd_sel_voltages[] = {2850};
255
256 /* LCD-D23 (GPIO M7) from T30*/
257 static struct regulator_consumer_supply gpio_switch_cam_ldo_2v8_en_supply[] = {
258         REGULATOR_SUPPLY("vdd_2v8_cam", NULL),
259 };
260 static int gpio_switch_cam_ldo_2v8_en_voltages[] = {2800};
261
262 /* LCD-D9 (GPIO F1) from T30*/
263 static struct regulator_consumer_supply gpio_switch_cam_ldo_1v8_en_supply[] = {
264         REGULATOR_SUPPLY("vdd_1v8_cam", NULL),
265 };
266 static int gpio_switch_cam_ldo_1v8_en_voltages[] = {1800};
267
268 /* Macro for defining gpio switch regulator sub device data */
269 #define GREG_INIT(_id, _name, _input_supply, _gpio_nr, _active_low, \
270                         _init_state, _pg, _enable, _disable)            \
271         static struct gpio_switch_regulator_subdev_data gpio_pdata_##_name =  \
272         {                                                               \
273                 .regulator_name = "gpio-switch-"#_name,                 \
274                 .input_supply   = _input_supply,                        \
275                 .id             = _id,                                  \
276                 .gpio_nr        = _gpio_nr,                             \
277                 .pin_group      = _pg,                                  \
278                 .active_low     = _active_low,                          \
279                 .init_state     = _init_state,                          \
280                 .voltages       = gpio_switch_##_name##_voltages,       \
281                 .n_voltages     = ARRAY_SIZE(gpio_switch_##_name##_voltages), \
282                 .num_consumer_supplies =                                \
283                                 ARRAY_SIZE(gpio_switch_##_name##_supply), \
284                 .consumer_supplies = gpio_switch_##_name##_supply,      \
285                 .constraints = {                                        \
286                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
287                                         REGULATOR_MODE_STANDBY),        \
288                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
289                                         REGULATOR_CHANGE_STATUS |       \
290                                         REGULATOR_CHANGE_VOLTAGE),      \
291                 },                                                      \
292                 .enable_rail = _enable,                                 \
293                 .disable_rail = _disable,                               \
294         }
295
296 GREG_INIT(0, pmu_5v15_en,     NULL,      TPS80031_GPIO_REGEN1, false, 0, 0, 0, 0);
297 GREG_INIT(1, pmu_3v3_en,      "vdd_5v15", TPS80031_GPIO_REGEN2, false, 0, 0, 0, 0);
298 GREG_INIT(2, pmu_hdmi_5v0_en, "vdd_5v15", TPS80031_GPIO_SYSEN, false, 0, 0, 0, 0);
299
300 GREG_INIT(3, vdd_fuse_en,    "avdd_usb_hdmi_3v3", TEGRA_GPIO_PM0, false, 0, 0, 0, 0);
301 GREG_INIT(4, sdmmc3_vdd_sel, "vddio_sdmmc_2v85", TEGRA_GPIO_PM1, false, 0, 0, 0, 0);
302 GREG_INIT(5, cam_ldo_2v8_en,    NULL, TEGRA_GPIO_PM7, false, 0, 0, 0, 0);
303 GREG_INIT(6, cam_ldo_1v8_en,    NULL, TEGRA_GPIO_PF1, false, 0, 0, 0, 0);
304
305 #define ADD_GPIO_REG(_name)     (&gpio_pdata_##_name)
306 static struct gpio_switch_regulator_subdev_data *gswitch_subdevs[] = {
307         ADD_GPIO_REG(pmu_5v15_en),
308         ADD_GPIO_REG(pmu_3v3_en),
309         ADD_GPIO_REG(pmu_hdmi_5v0_en),
310         ADD_GPIO_REG(vdd_fuse_en),
311         ADD_GPIO_REG(sdmmc3_vdd_sel),
312         ADD_GPIO_REG(cam_ldo_2v8_en),
313         ADD_GPIO_REG(cam_ldo_1v8_en),
314 };
315
316 static struct gpio_switch_regulator_platform_data  gswitch_pdata = {
317         .num_subdevs = ARRAY_SIZE(gswitch_subdevs),
318         .subdevs = gswitch_subdevs,
319 };
320
321 static struct platform_device gswitch_regulator_pdata = {
322         .name   = "gpio-switch-regulator",
323         .id     = -1,
324         .dev    = {
325                 .platform_data = &gswitch_pdata,
326         },
327 };
328
329 static int __init enterprise_gpio_switch_regulator_init(void)
330 {
331         int i;
332         for (i = 0; i < gswitch_pdata.num_subdevs; ++i) {
333                 struct gpio_switch_regulator_subdev_data *gswitch_data =
334                                                 gswitch_pdata.subdevs[i];
335                 if (gswitch_data->gpio_nr <= TEGRA_NR_GPIOS)
336                         tegra_gpio_enable(gswitch_data->gpio_nr);
337         }
338         return platform_device_register(&gswitch_regulator_pdata);
339 }
340
341 int __init enterprise_regulator_init(void)
342 {
343         i2c_register_board_info(4, enterprise_regulators, 1);
344         enterprise_gpio_switch_regulator_init();
345         return 0;
346 }
347
348 static struct tegra_suspend_platform_data enterprise_suspend_data = {
349         .cpu_timer      = 2000,
350         .cpu_off_timer  = 0,
351         .suspend_mode   = TEGRA_SUSPEND_NONE,
352         .core_timer     = 0x7e7e,
353         .core_off_timer = 0,
354         .separate_req   = true,
355         .corereq_high   = false,
356         .sysclkreq_high = true,
357         .wake_enb       = 0,
358         .wake_high      = 0,
359         .wake_low       = 0,
360         .wake_any       = 0,
361 };
362
363 int __init enterprise_suspend_init(void)
364 {
365         tegra_init_suspend(&enterprise_suspend_data);
366         return 0;
367 }