ARM: dalmore: power: fill max77663 power rails
[linux-3.10.git] / arch / arm / mach-tegra / board-dalmore-power.c
1 /*
2  * arch/arm/mach-tegra/board-dalmore-power.c
3  *
4  * Copyright (C) 2012 NVIDIA Corporation.
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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
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/io.h>
25 #include <linux/regulator/machine.h>
26 #include <linux/regulator/driver.h>
27 #include <linux/mfd/max77663-core.h>
28 #include <linux/regulator/max77663-regulator.h>
29 #include <linux/regulator/tps51632-regulator.h>
30
31 #include <mach/iomap.h>
32 #include <mach/irqs.h>
33 #include <mach/gpio-tegra.h>
34
35 #include "pm.h"
36 #include "board.h"
37 #include "board-dalmore.h"
38
39 #define PMC_CTRL                0x0
40 #define PMC_CTRL_INTR_LOW       (1 << 17)
41
42 static struct regulator_consumer_supply max77663_sd0_supply[] = {
43         REGULATOR_SUPPLY("vdd_core", NULL),
44 };
45
46 static struct regulator_consumer_supply max77663_sd1_supply[] = {
47         REGULATOR_SUPPLY("vddio_ddr", NULL),
48 };
49
50 static struct regulator_consumer_supply max77663_sd2_supply[] = {
51         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
52         REGULATOR_SUPPLY("vddio_cam", NULL),
53         REGULATOR_SUPPLY("avdd_osc", NULL),
54         REGULATOR_SUPPLY("vddio_sys", NULL),
55         REGULATOR_SUPPLY("vddio_bb", NULL),
56         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.0"),
57         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.3"),
58         REGULATOR_SUPPLY("vddio_audio", NULL),
59         REGULATOR_SUPPLY("vddio_uart", NULL),
60         REGULATOR_SUPPLY("vddio_gmi", NULL),
61 };
62
63 static struct regulator_consumer_supply max77663_sd3_supply[] = {
64         REGULATOR_SUPPLY("vdd_emmc_core", NULL),
65 };
66
67 static struct regulator_consumer_supply max77663_ldo0_supply[] = {
68         REGULATOR_SUPPLY("avdd_plla_p_c_s", NULL),
69         REGULATOR_SUPPLY("avdd_pllx", NULL),
70         REGULATOR_SUPPLY("avdd_pllm", NULL),
71         REGULATOR_SUPPLY("avdd_pllu", NULL),
72         REGULATOR_SUPPLY("avdd_hdmmi_pll", NULL),
73         REGULATOR_SUPPLY("avdd_csi_dsi_pll", NULL),
74 };
75
76 static struct regulator_consumer_supply max77663_ldo1_supply[] = {
77         REGULATOR_SUPPLY("vdd_ddr_hs", NULL),
78 };
79
80 static struct regulator_consumer_supply max77663_ldo2_supply[] = {
81         REGULATOR_SUPPLY("vdd_sensor_2v8", NULL),
82 };
83
84 static struct regulator_consumer_supply max77663_ldo3_supply[] = {
85         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
86         REGULATOR_SUPPLY("avdd_usb3_pll", NULL),
87         REGULATOR_SUPPLY("avddio_usb3", NULL),
88 };
89
90 static struct regulator_consumer_supply max77663_ldo4_supply[] = {
91         REGULATOR_SUPPLY("vdd_rtc", NULL),
92 };
93
94 static struct regulator_consumer_supply max77663_ldo5_supply[] = {
95         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
96         REGULATOR_SUPPLY("vddio_hsic", NULL),
97 };
98
99 static struct regulator_consumer_supply max77663_ldo6_supply[] = {
100         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.2"),
101 };
102
103 static struct regulator_consumer_supply max77663_ldo7_supply[] = {
104         REGULATOR_SUPPLY("avdd_cam1", NULL),
105 };
106
107 static struct regulator_consumer_supply max77663_ldo8_supply[] = {
108         REGULATOR_SUPPLY("avdd_cam2", NULL),
109 };
110
111 static struct max77663_regulator_fps_cfg max77663_fps_cfgs[] = {
112         {
113                 .src = FPS_SRC_0,
114                 .en_src = FPS_EN_SRC_EN0,
115                 .time_period = FPS_TIME_PERIOD_DEF,
116         },
117         {
118                 .src = FPS_SRC_1,
119                 .en_src = FPS_EN_SRC_EN1,
120                 .time_period = FPS_TIME_PERIOD_DEF,
121         },
122         {
123                 .src = FPS_SRC_2,
124                 .en_src = FPS_EN_SRC_EN0,
125                 .time_period = FPS_TIME_PERIOD_DEF,
126         },
127 };
128
129 #define MAX77663_PDATA_INIT(_id, _min_uV, _max_uV, _supply_reg,         \
130                 _always_on, _boot_on, _apply_uV,                        \
131                 _init_apply, _init_enable, _init_uV,                    \
132                 _fps_src, _fps_pu_period, _fps_pd_period, _flags)       \
133 static struct max77663_regulator_platform_data max77663_regulator_pdata_##_id =\
134 {                                                                       \
135         .init_data = {                                                  \
136                         .constraints = {                                \
137                                 .min_uV = _min_uV,                      \
138                                 .max_uV = _max_uV,                      \
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(max77663_##_id##_supply),    \
150                         .consumer_supplies = max77663_##_id##_supply,   \
151                         .supply_regulator = _supply_reg,                \
152                 },                                                      \
153                 .init_apply = _init_apply,                              \
154                 .init_enable = _init_enable,                            \
155                 .init_uV = _init_uV,                                    \
156                 .fps_src = _fps_src,                                    \
157                 .fps_pu_period = _fps_pu_period,                        \
158                 .fps_pd_period = _fps_pd_period,                        \
159                 .fps_cfgs = max77663_fps_cfgs,                          \
160                 .flags = _flags,                                        \
161         }
162
163 MAX77663_PDATA_INIT(sd0,  600000, 3387500, NULL, 1, 0, 0,
164                     1, 1, -1, FPS_SRC_1, -1, -1, SD_FSRADE_DISABLE);
165
166 MAX77663_PDATA_INIT(sd1,  800000, 1587500, NULL, 1, 0, 0,
167                     1, 1, -1, FPS_SRC_1, -1, -1, SD_FSRADE_DISABLE);
168
169 MAX77663_PDATA_INIT(sd2,  1800000, 1800000, NULL, 1, 0, 0,
170                     1, 1, -1, FPS_SRC_0, -1, -1, 0);
171
172 MAX77663_PDATA_INIT(sd3,  600000, 3387500, NULL, 1, 0, 0,
173                     1, 1, -1, FPS_SRC_NONE, -1, -1, 0);
174
175 MAX77663_PDATA_INIT(ldo0, 800000, 2350000, max77663_rails(sd2), 1, 0, 0,
176                     1, 1, -1, FPS_SRC_1, -1, -1, 0);
177
178 MAX77663_PDATA_INIT(ldo1, 800000, 2350000, max77663_rails(sd2), 0, 0, 0,
179                     0, 0, -1, FPS_SRC_NONE, -1, -1, 0);
180
181 MAX77663_PDATA_INIT(ldo2, 2850000, 2850000, NULL, 1, 0, 0,
182                     1, 1, -1, FPS_SRC_1, -1, -1, 0);
183
184 MAX77663_PDATA_INIT(ldo3, 800000, 3950000, max77663_rails(sd2), 1, 0, 0,
185                     1, 1, -1, FPS_SRC_NONE, -1, -1, 0);
186
187 MAX77663_PDATA_INIT(ldo4, 800000, 1587500, NULL, 0, 0, 0,
188                     1, 1, 1000000, FPS_SRC_NONE, -1, -1, LDO4_EN_TRACKING);
189
190 MAX77663_PDATA_INIT(ldo5, 800000, 2800000, max77663_rails(sd2), 0, 0, 0,
191                     1, 1, -1, FPS_SRC_NONE, -1, -1, 0);
192
193 MAX77663_PDATA_INIT(ldo6, 800000, 3950000, NULL, 0, 0, 0,
194                     0, 0, -1, FPS_SRC_NONE, -1, -1, 0);
195
196 MAX77663_PDATA_INIT(ldo7, 800000, 3950000, NULL, 0, 0, 0,
197                     0, 0, -1, FPS_SRC_NONE, -1, -1, 0);
198
199 MAX77663_PDATA_INIT(ldo8, 800000, 3950000, NULL, 0, 0, 0,
200                     1, 1, -1, FPS_SRC_1, -1, -1, 0);
201
202 #define MAX77663_REG(_id, _data)                                        \
203         {                                                               \
204                 .name = "max77663-regulator",                           \
205                 .id = MAX77663_REGULATOR_ID_##_id,                      \
206                 .platform_data = &max77663_regulator_pdata_##_data,     \
207                 .pdata_size = sizeof(max77663_regulator_pdata_##_data), \
208         }
209
210 static struct mfd_cell max77663_subdevs[] = {
211         MAX77663_REG(SD0, sd0),
212         MAX77663_REG(SD1, sd1),
213         MAX77663_REG(SD2, sd2),
214         MAX77663_REG(SD3, sd3),
215         MAX77663_REG(LDO0, ldo0),
216         MAX77663_REG(LDO1, ldo1),
217         MAX77663_REG(LDO2, ldo2),
218         MAX77663_REG(LDO3, ldo3),
219         MAX77663_REG(LDO4, ldo4),
220         MAX77663_REG(LDO5, ldo5),
221         MAX77663_REG(LDO6, ldo6),
222         MAX77663_REG(LDO7, ldo7),
223         MAX77663_REG(LDO8, ldo8),
224 };
225
226 static struct max77663_gpio_config max77663_gpio_cfgs[] = {
227         {
228                 .gpio = MAX77663_GPIO0,
229                 .dir = GPIO_DIR_OUT,
230                 .dout = GPIO_DOUT_LOW,
231                 .out_drv = GPIO_OUT_DRV_PUSH_PULL,
232                 .alternate = GPIO_ALT_DISABLE,
233         },
234         {
235                 .gpio = MAX77663_GPIO1,
236                 .dir = GPIO_DIR_IN,
237                 .dout = GPIO_DOUT_HIGH,
238                 .out_drv = GPIO_OUT_DRV_OPEN_DRAIN,
239                 .pull_up = GPIO_PU_ENABLE,
240                 .alternate = GPIO_ALT_DISABLE,
241         },
242         {
243                 .gpio = MAX77663_GPIO2,
244                 .dir = GPIO_DIR_OUT,
245                 .dout = GPIO_DOUT_HIGH,
246                 .out_drv = GPIO_OUT_DRV_OPEN_DRAIN,
247                 .pull_up = GPIO_PU_ENABLE,
248                 .alternate = GPIO_ALT_DISABLE,
249         },
250         {
251                 .gpio = MAX77663_GPIO3,
252                 .dir = GPIO_DIR_OUT,
253                 .dout = GPIO_DOUT_HIGH,
254                 .out_drv = GPIO_OUT_DRV_OPEN_DRAIN,
255                 .pull_up = GPIO_PU_ENABLE,
256                 .alternate = GPIO_ALT_DISABLE,
257         },
258         {
259                 .gpio = MAX77663_GPIO4,
260                 .dir = GPIO_DIR_OUT,
261                 .dout = GPIO_DOUT_HIGH,
262                 .out_drv = GPIO_OUT_DRV_PUSH_PULL,
263                 .alternate = GPIO_ALT_ENABLE,
264         },
265         {
266                 .gpio = MAX77663_GPIO5,
267                 .dir = GPIO_DIR_OUT,
268                 .dout = GPIO_DOUT_LOW,
269                 .out_drv = GPIO_OUT_DRV_PUSH_PULL,
270                 .alternate = GPIO_ALT_DISABLE,
271         },
272         {
273                 .gpio = MAX77663_GPIO6,
274                 .dir = GPIO_DIR_OUT,
275                 .dout = GPIO_DOUT_LOW,
276                 .out_drv = GPIO_OUT_DRV_OPEN_DRAIN,
277                 .alternate = GPIO_ALT_DISABLE,
278         },
279         {
280                 .gpio = MAX77663_GPIO7,
281                 .dir = GPIO_DIR_OUT,
282                 .dout = GPIO_DOUT_LOW,
283                 .out_drv = GPIO_OUT_DRV_OPEN_DRAIN,
284                 .alternate = GPIO_ALT_DISABLE,
285         },
286 };
287
288 static struct max77663_platform_data max7763_pdata = {
289         .irq_base       = MAX77663_IRQ_BASE,
290         .gpio_base      = MAX77663_GPIO_BASE,
291
292         .num_gpio_cfgs  = ARRAY_SIZE(max77663_gpio_cfgs),
293         .gpio_cfgs      = max77663_gpio_cfgs,
294
295
296         .num_subdevs    = ARRAY_SIZE(max77663_subdevs),
297         .sub_devices    = max77663_subdevs,
298
299         .rtc_i2c_addr   = 0x68,
300
301         .use_power_off  = false,
302 };
303
304
305 static struct i2c_board_info __initdata max77663_regulators[] = {
306         {
307                 /* The I2C address was determined by OTP factory setting */
308                 I2C_BOARD_INFO("max77663", 0x3c),
309                 .irq            = INT_EXTERNAL_PMU,
310                 .platform_data  = &max7763_pdata,
311         },
312 };
313
314 /* TPS51632 DC-DC converter */
315 static struct regulator_consumer_supply tps51632_dcdc_supply[] = {
316         REGULATOR_SUPPLY("vdd_cpu", NULL),
317 };
318
319 static struct regulator_init_data tps51632_init_data = {
320         .constraints = {                                                \
321                 .min_uV = 500000,                                       \
322                         .max_uV = 1520000,                              \
323                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
324                                         REGULATOR_MODE_STANDBY),        \
325                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
326                                         REGULATOR_CHANGE_STATUS |       \
327                                         REGULATOR_CHANGE_VOLTAGE),      \
328                         .always_on = 1,                                 \
329                         .boot_on =  1,                                  \
330                         .apply_uV = 0,                                  \
331         },                                                              \
332         .num_consumer_supplies = ARRAY_SIZE(tps51632_dcdc_supply),      \
333                 .consumer_supplies = tps51632_dcdc_supply,              \
334 };
335
336 static struct tps51632_regulator_platform_data tps51632_pdata = {
337         .reg_init_data = &tps51632_init_data,           \
338         .enable_pwm = false,                            \
339         .max_voltage_uV = 1520000,                      \
340         .base_voltage_uV = 500000,                      \
341         .slew_rate_uv_per_us = 6000,                    \
342 };
343
344 static struct i2c_board_info __initdata tps51632_boardinfo[] = {
345         {
346                 I2C_BOARD_INFO("tps51632", 0x43),
347                 .platform_data  = &tps51632_pdata,
348         },
349 };
350
351 static int ac_online(void)
352 {
353         return 1;
354 }
355
356 static struct resource dalmore_pda_resources[] = {
357         [0] = {
358                 .name   = "ac",
359         },
360 };
361
362 static struct pda_power_pdata dalmore_pda_data = {
363         .is_ac_online   = ac_online,
364 };
365
366 static struct platform_device dalmore_pda_power_device = {
367         .name           = "pda-power",
368         .id             = -1,
369         .resource       = dalmore_pda_resources,
370         .num_resources  = ARRAY_SIZE(dalmore_pda_resources),
371         .dev    = {
372                 .platform_data  = &dalmore_pda_data,
373         },
374 };
375
376 static struct tegra_suspend_platform_data dalmore_suspend_data = {
377         .cpu_timer      = 2000,
378         .cpu_off_timer  = 0,
379         .suspend_mode   = TEGRA_SUSPEND_NONE,
380         .core_timer     = 0x7e7e,
381         .core_off_timer = 0,
382         .corereq_high   = false,
383         .sysclkreq_high = true,
384 };
385
386 static int __init dalmore_max77663_regulator_init(void)
387 {
388         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
389         u32 pmc_ctrl;
390
391         /* configure the power management controller to trigger PMU
392          * interrupts when low */
393         pmc_ctrl = readl(pmc + PMC_CTRL);
394         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
395
396         i2c_register_board_info(4, max77663_regulators,
397                                 ARRAY_SIZE(max77663_regulators));
398
399         return 0;
400 }
401
402 int __init dalmore_regulator_init(void)
403 {
404         dalmore_max77663_regulator_init();
405         i2c_register_board_info(4, tps51632_boardinfo, 1);
406         platform_device_register(&dalmore_pda_power_device);
407         return 0;
408 }
409
410 int __init dalmore_suspend_init(void)
411 {
412         tegra_init_suspend(&dalmore_suspend_data);
413         return 0;
414 }
415