arm: tegra: enterprise: Updating power rail info for TPS80031
[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 #include <linux/i2c/twl.h>
32
33 #include <mach/iomap.h>
34 #include <mach/irqs.h>
35 #include <mach/pinmux.h>
36
37 #include "gpio-names.h"
38 #include "board-enterprise.h"
39 #include "power.h"
40 #include "wakeups-t3.h"
41
42 /************************ TPS80031 based regulator ****************/
43 static struct regulator_consumer_supply tps80031_vio_supply[] = {
44         REGULATOR_SUPPLY("avdd_osc", NULL),
45         REGULATOR_SUPPLY("vddio_sys", NULL),
46         REGULATOR_SUPPLY("vddio_uart", NULL),
47         REGULATOR_SUPPLY("vddio_audio", NULL),
48         REGULATOR_SUPPLY("vddio_bb", NULL),
49         REGULATOR_SUPPLY("vddio_cam", NULL),
50         REGULATOR_SUPPLY("vddio_sdmmc1", NULL),
51 };
52
53 static struct regulator_consumer_supply tps80031_smps1_supply[] = {
54         REGULATOR_SUPPLY("vdd_cpu", NULL),
55 };
56
57 static struct regulator_consumer_supply tps80031_smps2_supply[] = {
58         REGULATOR_SUPPLY("vdd_core", NULL),
59 };
60
61 static struct regulator_consumer_supply tps80031_smps3_supply[] = {
62         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
63 };
64
65 static struct regulator_consumer_supply tps80031_smps4_supply[] = {
66         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
67 };
68
69 static struct regulator_consumer_supply tps80031_vana_supply[] = {
70         REGULATOR_SUPPLY("unused_vana", NULL),
71 };
72
73 static struct regulator_consumer_supply tps80031_ldo1_supply[] = {
74         REGULATOR_SUPPLY("unused_ldo1", NULL),
75 };
76
77 static struct regulator_consumer_supply tps80031_ldo2_supply[] = {
78         REGULATOR_SUPPLY("vdd_rtc", NULL),
79 };
80
81 static struct regulator_consumer_supply tps80031_ldo3_supply[] = {
82         REGULATOR_SUPPLY("vdd_vbrtr", NULL),
83 };
84
85 static struct regulator_consumer_supply tps80031_ldo4_supply[] = {
86         REGULATOR_SUPPLY("unused_ldo4", NULL),
87 };
88
89 static struct regulator_consumer_supply tps80031_ldo5_supply[] = {
90         REGULATOR_SUPPLY("unused_ldo5", NULL),
91 };
92
93 static struct regulator_consumer_supply tps80031_ldo6_supply[] = {
94         REGULATOR_SUPPLY("vddio_sdmmc3", NULL),
95 };
96
97 static struct regulator_consumer_supply tps80031_ldo7_supply[] = {
98         REGULATOR_SUPPLY("vdd_plla_p_c_s", NULL),
99         REGULATOR_SUPPLY("vdd_pllm", NULL),
100         REGULATOR_SUPPLY("vdd_pllu_d", NULL),
101         REGULATOR_SUPPLY("vdd_pllx", NULL),
102 };
103
104 static struct regulator_consumer_supply tps80031_ldoln_supply[] = {
105         REGULATOR_SUPPLY("unused_ldoln", NULL),
106 };
107
108 static struct regulator_consumer_supply tps80031_ldousb_supply[] = {
109         REGULATOR_SUPPLY("unused_ldousb", NULL),
110 };
111
112 #define TPS_PDATA_INIT(_id, _minmv, _maxmv, _supply_reg, _always_on,    \
113         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply)       \
114         static struct tps80031_regulator_platform_data pdata_##_id = {  \
115                 .regulator = {                                          \
116                         .constraints = {                                \
117                                 .min_uV = (_minmv)*1000,                \
118                                 .max_uV = (_maxmv)*1000,                \
119                                 .valid_modes_mask = (REGULATOR_MODE_NORMAL |  \
120                                                 REGULATOR_MODE_STANDBY),      \
121                                 .valid_ops_mask = (REGULATOR_CHANGE_MODE |    \
122                                                 REGULATOR_CHANGE_STATUS |     \
123                                                 REGULATOR_CHANGE_VOLTAGE),    \
124                                 .always_on = _always_on,                \
125                                 .boot_on = _boot_on,                    \
126                                 .apply_uV = _apply_uv,                  \
127                         },                                              \
128                         .num_consumer_supplies =                        \
129                                 ARRAY_SIZE(tps80031_##_id##_supply),    \
130                         .consumer_supplies = tps80031_##_id##_supply,   \
131                         .supply_regulator = _supply_reg,                \
132                 },                                                      \
133                 .init_uV =  _init_uV * 1000,                            \
134                 .init_enable = _init_enable,                            \
135                 .init_apply = _init_apply,                              \
136         }
137
138 TPS_PDATA_INIT(vio,   600, 2100, 0, 0, 0, 0, -1, 0, 0);
139 TPS_PDATA_INIT(smps1, 600, 2100, 0, 0, 0, 0, -1, 0, 0);
140 TPS_PDATA_INIT(smps2, 600, 2100, 0, 0, 0, 0, -1, 0, 0);
141 TPS_PDATA_INIT(smps3, 600, 2100, 0, 0, 0, 0, -1, 0, 0);
142 TPS_PDATA_INIT(smps4, 600, 2100, 0, 0, 0, 0, -1, 0, 0);
143
144 TPS_PDATA_INIT(ldo1, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0);
145 TPS_PDATA_INIT(ldo2, 1000, 3300, 0, 0, 0, 0, -1, 0, 0);
146 TPS_PDATA_INIT(ldo3, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0);
147 TPS_PDATA_INIT(ldo4, 1000, 3300, 0, 0, 0, 0, -1, 0, 0);
148 TPS_PDATA_INIT(ldo5, 1000, 3300, 0, 0, 0, 0, -1, 0, 0);
149 TPS_PDATA_INIT(ldo6, 1000, 3300, 0, 0, 0, 0, -1, 0, 0);
150 TPS_PDATA_INIT(ldo7, 1000, 3300, tps80031_rails(VIO), 0, 0, 0, -1, 0, 0);
151 TPS_PDATA_INIT(ldoln, 1000, 3300, tps80031_rails(SMPS3), 0, 0, 0, -1, 0, 0);
152 TPS_PDATA_INIT(ldousb, 1000, 3300, 0, 0, 0, 0, -1, 0, 0);
153 TPS_PDATA_INIT(vana,  1000, 3300, 0, 0, 0, 0, -1, 0, 0);
154
155 #define TPS_REG(_id, _data)                             \
156         {                                               \
157                 .id      = TPS80031_ID_##_id,           \
158                 .name   = "tps80031-regulator",         \
159                 .platform_data  = &pdata_##_data,       \
160         }
161
162 static struct tps80031_subdev_info tps80031_devs[] = {
163         TPS_REG(VIO, vio),
164         TPS_REG(SMPS1, smps1),
165         TPS_REG(SMPS2, smps2),
166         TPS_REG(SMPS3, smps3),
167         TPS_REG(SMPS4, smps4),
168         TPS_REG(LDO1, ldo1),
169         TPS_REG(LDO2, ldo2),
170         TPS_REG(LDO3, ldo3),
171         TPS_REG(LDO4, ldo4),
172         TPS_REG(LDO5, ldo5),
173         TPS_REG(LDO6, ldo6),
174         TPS_REG(LDO7, ldo7),
175         TPS_REG(LDOLN, ldoln),
176         TPS_REG(LDOUSB, ldousb),
177         TPS_REG(VANA, vana),
178 };
179
180 struct tps80031_32kclock_plat_data clk32k_pdata = {
181         .en_clk32kg = 1,
182 };
183 static struct tps80031_platform_data tps_platform = {
184         .num_subdevs    = ARRAY_SIZE(tps80031_devs),
185         .subdevs        = tps80031_devs,
186         .irq_base       = TPS80031_IRQ_BASE,
187         .gpio_base      = TPS80031_GPIO_BASE,
188         .clk32k_pdata   = &clk32k_pdata,
189 };
190
191 static struct i2c_board_info __initdata enterprise_regulators[] = {
192         {
193                 I2C_BOARD_INFO("tps80031", 0x48),
194                 .irq            = INT_EXTERNAL_PMU,
195                 .platform_data  = &tps_platform,
196         },
197 };
198
199 /************************ GPIO based switch regulator ****************/
200
201 /* REGEN2 from PMU*/
202 static struct regulator_consumer_supply gpio_switch_pmu_regen2_supply[] = {
203         REGULATOR_SUPPLY("avdd_usb", NULL),
204         REGULATOR_SUPPLY("avdd_hdmi", NULL),
205         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
206 };
207 static int gpio_switch_pmu_regen2_voltages[] = {3300};
208
209 /* Macro for defining gpio switch regulator sub device data */
210 #define GREG_INIT(_id, _var, _name, _input_supply, _gpio_nr, _active_low, \
211                         _init_state, _pg, _enable, _disable)            \
212         static struct gpio_switch_regulator_subdev_data gpio_pdata_##_var =  \
213         {                                                               \
214                 .regulator_name = "gpio-switch-"#_name,                 \
215                 .input_supply   = _input_supply,                        \
216                 .id             = _id,                                  \
217                 .gpio_nr        = _gpio_nr,                             \
218                 .pin_group      = _pg,                                  \
219                 .active_low     = _active_low,                          \
220                 .init_state     = _init_state,                          \
221                 .voltages       = gpio_switch_##_name##_voltages,       \
222                 .n_voltages     = ARRAY_SIZE(gpio_switch_##_name##_voltages), \
223                 .num_consumer_supplies =                                \
224                                 ARRAY_SIZE(gpio_switch_##_name##_supply), \
225                 .consumer_supplies = gpio_switch_##_name##_supply,      \
226                 .constraints = {                                        \
227                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
228                                         REGULATOR_MODE_STANDBY),        \
229                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
230                                         REGULATOR_CHANGE_STATUS |       \
231                                         REGULATOR_CHANGE_VOLTAGE),      \
232                 },                                                      \
233                 .enable_rail = _enable,                                 \
234                 .disable_rail = _disable,                               \
235         }
236
237 GREG_INIT(0, pmu_regen2, pmu_regen2, NULL, TPS80031_GPIO_REGEN2, false, 0, 0, 0, 0);
238
239 #define ADD_GPIO_REG(_name)     (&gpio_pdata_##_name)
240 static struct gpio_switch_regulator_subdev_data *gswitch_subdevs[] = {
241         ADD_GPIO_REG(pmu_regen2),
242 };
243
244 static struct gpio_switch_regulator_platform_data  gswitch_pdata = {
245         .num_subdevs = ARRAY_SIZE(gswitch_subdevs),
246         .subdevs = gswitch_subdevs,
247 };
248
249 static struct platform_device gswitch_regulator_pdata = {
250         .name   = "gpio-switch-regulator",
251         .id     = -1,
252         .dev    = {
253                 .platform_data = &gswitch_pdata,
254         },
255 };
256
257 static int __init enterprise_gpio_switch_regulator_init(void)
258 {
259         int i;
260         for (i = 0; i < gswitch_pdata.num_subdevs; ++i) {
261                 struct gpio_switch_regulator_subdev_data *gswitch_data =
262                                                 gswitch_pdata.subdevs[i];
263                 if (gswitch_data->gpio_nr <= TEGRA_NR_GPIOS)
264                         tegra_gpio_enable(gswitch_data->gpio_nr);
265         }
266         return platform_device_register(&gswitch_regulator_pdata);
267 }
268
269 int __init enterprise_regulator_init(void)
270 {
271         i2c_register_board_info(4, enterprise_regulators, 1);
272         enterprise_gpio_switch_regulator_init();
273         return 0;
274 }
275
276 static struct tegra_suspend_platform_data enterprise_suspend_data = {
277         .cpu_timer      = 2000,
278         .cpu_off_timer  = 0,
279         .suspend_mode   = TEGRA_SUSPEND_NONE,
280         .core_timer     = 0x7e7e,
281         .core_off_timer = 0,
282         .separate_req   = true,
283         .corereq_high   = false,
284         .sysclkreq_high = true,
285         .wake_enb       = 0,
286         .wake_high      = 0,
287         .wake_low       = 0,
288         .wake_any       = 0,
289 };
290
291 int __init enterprise_suspend_init(void)
292 {
293         tegra_init_suspend(&enterprise_suspend_data);
294         return 0;
295 }