rtc: tps80031: register as mfd sub device
[linux-2.6.git] / arch / arm / mach-tegra / board-whistler-power.c
1 /*
2  * Copyright (C) 2010-2011 NVIDIA, Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
16  * 02111-1307, USA
17  */
18 #include <linux/i2c.h>
19 #include <linux/pda_power.h>
20 #include <linux/platform_device.h>
21 #include <linux/resource.h>
22 #include <linux/regulator/machine.h>
23 #include <linux/mfd/max8907c.h>
24 #include <linux/regulator/max8907c-regulator.h>
25 #include <linux/gpio.h>
26 #include <linux/io.h>
27
28 #include <mach/iomap.h>
29 #include <mach/irqs.h>
30
31 #include "gpio-names.h"
32 #include "fuse.h"
33 #include "pm.h"
34 #include "board.h"
35
36 #define PMC_CTRL                0x0
37 #define PMC_CTRL_INTR_LOW       (1 << 17)
38
39 static struct regulator_consumer_supply max8907c_SD1_supply[] = {
40         REGULATOR_SUPPLY("vdd_cpu", NULL),
41 };
42
43 static struct regulator_consumer_supply max8907c_SD2_supply[] = {
44         REGULATOR_SUPPLY("vdd_core", NULL),
45         REGULATOR_SUPPLY("vdd_aon", NULL),
46 };
47
48 static struct regulator_consumer_supply max8907c_SD3_supply[] = {
49         REGULATOR_SUPPLY("vddio_sys", NULL),
50 };
51
52 static struct regulator_consumer_supply max8907c_LDO1_supply[] = {
53         REGULATOR_SUPPLY("vddio_rx_ddr", NULL),
54 };
55
56 static struct regulator_consumer_supply max8907c_LDO2_supply[] = {
57         REGULATOR_SUPPLY("avdd_plla", NULL),
58 };
59
60 static struct regulator_consumer_supply max8907c_LDO3_supply[] = {
61         REGULATOR_SUPPLY("vdd_vcom_1v8b", NULL),
62 };
63
64 static struct regulator_consumer_supply max8907c_LDO4_supply[] = {
65         REGULATOR_SUPPLY("avdd_usb", NULL),
66         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
67 };
68
69 static struct regulator_consumer_supply max8907c_LDO5_supply[] = {
70 };
71
72 static struct regulator_consumer_supply max8907c_LDO6_supply[] = {
73         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
74 };
75
76 static struct regulator_consumer_supply max8907c_LDO7_supply[] = {
77         REGULATOR_SUPPLY("avddio_audio", NULL),
78 };
79
80 static struct regulator_consumer_supply max8907c_LDO8_supply[] = {
81         REGULATOR_SUPPLY("vdd_vcom_3v0", NULL),
82 };
83
84 static struct regulator_consumer_supply max8907c_LDO9_supply[] = {
85         REGULATOR_SUPPLY("vdd_cam1", NULL),
86 };
87
88 static struct regulator_consumer_supply max8907c_LDO10_supply[] = {
89         REGULATOR_SUPPLY("avdd_usb_ic", NULL),
90 };
91
92 static struct regulator_consumer_supply max8907c_LDO11_supply[] = {
93         REGULATOR_SUPPLY("vddio_pex_clk", NULL),
94         REGULATOR_SUPPLY("avdd_hdmi", NULL),
95 };
96
97 static struct regulator_consumer_supply max8907c_LDO12_supply[] = {
98         REGULATOR_SUPPLY("vddio_sdio", NULL),
99 };
100
101 static struct regulator_consumer_supply max8907c_LDO13_supply[] = {
102         REGULATOR_SUPPLY("vdd_vcore_phtn", NULL),
103         REGULATOR_SUPPLY("vdd_vcore_af", NULL),
104 };
105
106 static struct regulator_consumer_supply max8907c_LDO14_supply[] = {
107         REGULATOR_SUPPLY("avdd_vdac", NULL),
108 };
109
110 static struct regulator_consumer_supply max8907c_LDO15_supply[] = {
111         REGULATOR_SUPPLY("vdd_vcore_temp", NULL),
112         REGULATOR_SUPPLY("vdd_vcore_hdcp", NULL),
113 };
114
115 static struct regulator_consumer_supply max8907c_LDO16_supply[] = {
116         REGULATOR_SUPPLY("vdd_vbrtr", NULL),
117 };
118
119 static struct regulator_consumer_supply max8907c_LDO17_supply[] = {
120         REGULATOR_SUPPLY("vddio_mipi", NULL),
121 };
122
123 static struct regulator_consumer_supply max8907c_LDO18_supply[] = {
124         REGULATOR_SUPPLY("vddio_vi", NULL),
125         REGULATOR_SUPPLY("vcsi", "tegra_camera"),
126 };
127
128 static struct regulator_consumer_supply max8907c_LDO19_supply[] = {
129         REGULATOR_SUPPLY("vddio_lx", NULL),
130 };
131
132 static struct regulator_consumer_supply max8907c_LDO20_supply[] = {
133         REGULATOR_SUPPLY("vddio_ddr_1v2", NULL),
134         REGULATOR_SUPPLY("vddio_hsic", NULL),
135 };
136
137 static struct max8907c_chip_regulator_data ldo4_config = {
138         .enable_time_us = 10000,
139 };
140
141 #define MAX8907C_REGULATOR_DEVICE(_id, _minmv, _maxmv, config)                  \
142 static struct regulator_init_data max8907c_##_id##_data = {             \
143         .constraints = {                                                \
144                 .min_uV = (_minmv),                                     \
145                 .max_uV = (_maxmv),                                     \
146                 .valid_modes_mask = (REGULATOR_MODE_NORMAL |            \
147                                      REGULATOR_MODE_STANDBY),           \
148                 .valid_ops_mask = (REGULATOR_CHANGE_MODE |              \
149                                    REGULATOR_CHANGE_STATUS |            \
150                                    REGULATOR_CHANGE_VOLTAGE),           \
151         },                                                              \
152         .num_consumer_supplies = ARRAY_SIZE(max8907c_##_id##_supply),   \
153         .consumer_supplies = max8907c_##_id##_supply,                   \
154         .driver_data = config,          \
155 };                                                                      \
156 static struct platform_device max8907c_##_id##_device = {               \
157         .name   = "max8907c-regulator",                                 \
158         .id     = MAX8907C_##_id,                                       \
159         .dev    = {                                                     \
160                 .platform_data = &max8907c_##_id##_data,                \
161         },                                                              \
162 }
163
164 MAX8907C_REGULATOR_DEVICE(SD1, 637500, 1425000, NULL);
165 MAX8907C_REGULATOR_DEVICE(SD2, 637500, 1425000, NULL);
166 MAX8907C_REGULATOR_DEVICE(SD3, 750000, 3900000, NULL);
167 MAX8907C_REGULATOR_DEVICE(LDO1, 750000, 3900000, NULL);
168 MAX8907C_REGULATOR_DEVICE(LDO2, 650000, 2225000, NULL);
169 MAX8907C_REGULATOR_DEVICE(LDO3, 650000, 2225000, NULL);
170 MAX8907C_REGULATOR_DEVICE(LDO4, 750000, 3900000, &ldo4_config);
171 MAX8907C_REGULATOR_DEVICE(LDO5, 750000, 3900000, NULL);
172 MAX8907C_REGULATOR_DEVICE(LDO6, 750000, 3900000, NULL);
173 MAX8907C_REGULATOR_DEVICE(LDO7, 750000, 3900000, NULL);
174 MAX8907C_REGULATOR_DEVICE(LDO8, 750000, 3900000, NULL);
175 MAX8907C_REGULATOR_DEVICE(LDO9, 750000, 3900000, NULL);
176 MAX8907C_REGULATOR_DEVICE(LDO10, 750000, 3900000, NULL);
177 MAX8907C_REGULATOR_DEVICE(LDO11, 750000, 3900000, NULL);
178 MAX8907C_REGULATOR_DEVICE(LDO12, 750000, 3900000, NULL);
179 MAX8907C_REGULATOR_DEVICE(LDO13, 750000, 3900000, NULL);
180 MAX8907C_REGULATOR_DEVICE(LDO14, 750000, 3900000, NULL);
181 MAX8907C_REGULATOR_DEVICE(LDO15, 750000, 3900000, NULL);
182 MAX8907C_REGULATOR_DEVICE(LDO16, 750000, 3900000, NULL);
183 MAX8907C_REGULATOR_DEVICE(LDO17, 650000, 2225000, NULL);
184 MAX8907C_REGULATOR_DEVICE(LDO18, 650000, 2225000, NULL);
185 MAX8907C_REGULATOR_DEVICE(LDO19, 750000, 3900000, NULL);
186 MAX8907C_REGULATOR_DEVICE(LDO20, 750000, 3900000, NULL);
187
188 static struct platform_device *whistler_max8907c_power_devices[] = {
189         &max8907c_SD1_device,
190         &max8907c_SD2_device,
191         &max8907c_SD3_device,
192         &max8907c_LDO1_device,
193         &max8907c_LDO2_device,
194         &max8907c_LDO3_device,
195         &max8907c_LDO4_device,
196         &max8907c_LDO5_device,
197         &max8907c_LDO6_device,
198         &max8907c_LDO7_device,
199         &max8907c_LDO8_device,
200         &max8907c_LDO9_device,
201         &max8907c_LDO10_device,
202         &max8907c_LDO11_device,
203         &max8907c_LDO12_device,
204         &max8907c_LDO13_device,
205         &max8907c_LDO14_device,
206         &max8907c_LDO15_device,
207         &max8907c_LDO16_device,
208         &max8907c_LDO17_device,
209         &max8907c_LDO18_device,
210         &max8907c_LDO19_device,
211         &max8907c_LDO20_device,
212 };
213
214 static int whistler_max8907c_setup(void)
215 {
216         int ret;
217
218         /*
219          * Configure PWREN, and attach CPU V1 rail to it.
220          * TODO: h/w events (power cycle, reset, battery low) auto-disables PWREN.
221          * Only soft reset (not supported) requires s/w to disable PWREN explicitly
222          */
223         ret = max8907c_pwr_en_config();
224         if (ret != 0)
225                 return ret;
226
227         return max8907c_pwr_en_attach();
228 }
229
230 static struct max8907c_platform_data max8907c_pdata = {
231         .num_subdevs = ARRAY_SIZE(whistler_max8907c_power_devices),
232         .subdevs = whistler_max8907c_power_devices,
233         .irq_base = TEGRA_NR_IRQS,
234         .max8907c_setup = whistler_max8907c_setup,
235         .use_power_off = true,
236 };
237
238 static struct i2c_board_info __initdata whistler_regulators[] = {
239         {
240                 I2C_BOARD_INFO("max8907c", 0x3C),
241                 .irq = INT_EXTERNAL_PMU,
242                 .platform_data  = &max8907c_pdata,
243         },
244 };
245
246 static void whistler_board_suspend(int lp_state, enum suspend_stage stg)
247 {
248         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_SUSPEND_BEFORE_CPU))
249                 tegra_console_uart_suspend();
250 }
251
252 static void whistler_board_resume(int lp_state, enum resume_stage stg)
253 {
254         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_RESUME_AFTER_CPU))
255                 tegra_console_uart_resume();
256 }
257
258 static struct tegra_suspend_platform_data whistler_suspend_data = {
259         .cpu_timer      = 2000,
260         .cpu_off_timer  = 1000,
261         .suspend_mode   = TEGRA_SUSPEND_LP0,
262         .core_timer     = 0x7e,
263         .core_off_timer = 0xc00,
264         .corereq_high   = true,
265         .sysclkreq_high = true,
266         .combined_req   = true,
267         .board_suspend = whistler_board_suspend,
268         .board_resume = whistler_board_resume,
269 };
270
271 int __init whistler_regulator_init(void)
272 {
273         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
274         void __iomem *chip_id = IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804;
275         u32 pmc_ctrl;
276         u32 minor;
277
278         minor = (readl(chip_id) >> 16) & 0xf;
279         /* A03 (but not A03p) chips do not support LP0 */
280         if (minor == 3 && !(tegra_spare_fuse(18) || tegra_spare_fuse(19)))
281                 whistler_suspend_data.suspend_mode = TEGRA_SUSPEND_LP1;
282
283         /* configure the power management controller to trigger PMU
284          * interrupts when low */
285         pmc_ctrl = readl(pmc + PMC_CTRL);
286         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
287
288         i2c_register_board_info(4, whistler_regulators, 1);
289
290         tegra_deep_sleep = max8907c_deep_sleep;
291
292         tegra_init_suspend(&whistler_suspend_data);
293
294         return 0;
295 }