[ARM] tegra: ventana: remove BUG() in set_charge.
[linux-2.6.git] / arch / arm / mach-tegra / board-ventana-power.c
1 /*
2  * Copyright (C) 2010 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/tps6586x.h>
24 #include <linux/gpio.h>
25 #include <mach/suspend.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 "power.h"
33 #include "wakeups-t2.h"
34 #include "board.h"
35
36 #define PMC_CTRL                0x0
37  #define PMC_CTRL_INTR_LOW      (1 << 17)
38
39 static int ac_ok                = TEGRA_GPIO_PV3;
40 static int charge_disable       = TEGRA_GPIO_PR6;
41
42 static int charge_init(struct device *dev)
43 {
44         int ret = gpio_request(charge_disable, "chg_disable");
45         if (ret < 0)
46                 return ret;
47
48         ret = gpio_request(ac_ok, "ac_ok");
49         if (ret < 0) {
50                 gpio_free(charge_disable);
51                 return ret;
52         }
53
54         ret = gpio_direction_output(charge_disable, 0);
55         if (ret < 0)
56                 goto cleanup;
57
58         ret = gpio_direction_input(ac_ok);
59         if (ret < 0)
60                 goto cleanup;
61
62         tegra_gpio_enable(ac_ok);
63         tegra_gpio_enable(charge_disable);
64
65         return 0;
66
67 cleanup:
68         gpio_free(ac_ok);
69         gpio_free(charge_disable);
70         return ret;
71 }
72
73 static void charge_exit(struct device *dev)
74 {
75         gpio_free(charge_disable);
76 }
77
78 static int ac_online(void)
79 {
80         return !gpio_get_value(ac_ok);
81 }
82
83 static void set_charge(int flags)
84 {
85         if (flags == PDA_POWER_CHARGE_AC)
86                 gpio_set_value(charge_disable, 0);
87         else if (!flags)
88                 gpio_set_value(charge_disable, 1);
89         /* USB charging not supported on Ventana */
90 }
91
92 static struct resource ventana_pda_resources[] = {
93         [0] = {
94                 .name   = "ac",
95                 .start  = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV3),
96                 .end    = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV3),
97                 .flags  = (IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
98                            IORESOURCE_IRQ_LOWEDGE),
99         },
100 };
101
102 static struct pda_power_pdata ventana_pda_data = {
103         .is_ac_online   = ac_online,
104         .exit           = charge_exit,
105         .init           = charge_init,
106         .set_charge     = set_charge,
107 };
108
109 static struct platform_device ventana_pda_power_device = {
110         .name           = "pda-power",
111         .id             = -1,
112         .resource       = ventana_pda_resources,
113         .num_resources  = ARRAY_SIZE(ventana_pda_resources),
114         .dev    = {
115                 .platform_data  = &ventana_pda_data,
116         },
117 };
118
119
120 static struct regulator_consumer_supply tps658621_sm0_supply[] = {
121         REGULATOR_SUPPLY("vdd_core", NULL),
122 };
123 static struct regulator_consumer_supply tps658621_sm1_supply[] = {
124         REGULATOR_SUPPLY("vdd_cpu", NULL),
125 };
126 static struct regulator_consumer_supply tps658621_sm2_supply[] = {
127         REGULATOR_SUPPLY("vdd_sm2", NULL),
128 };
129 static struct regulator_consumer_supply tps658621_ldo0_supply[] = {
130         REGULATOR_SUPPLY("p_cam_avdd", NULL),
131 };
132 static struct regulator_consumer_supply tps658621_ldo1_supply[] = {
133         REGULATOR_SUPPLY("avdd_pll", NULL),
134 };
135 static struct regulator_consumer_supply tps658621_ldo2_supply[] = {
136         REGULATOR_SUPPLY("vdd_rtc", NULL),
137 };
138 static struct regulator_consumer_supply tps658621_ldo3_supply[] = {
139         REGULATOR_SUPPLY("avdd_usb", NULL),
140         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
141 };
142 static struct regulator_consumer_supply tps658621_ldo4_supply[] = {
143         REGULATOR_SUPPLY("avdd_osc", NULL),
144         REGULATOR_SUPPLY("vddio_sys", "panjit_touch"),
145 };
146 static struct regulator_consumer_supply tps658621_ldo5_supply[] = {
147         REGULATOR_SUPPLY("vcore_mmc", "sdhci-tegra.1"),
148         REGULATOR_SUPPLY("vcore_mmc", "sdhci-tegra.3"),
149 };
150 static struct regulator_consumer_supply tps658621_ldo6_supply[] = {
151         REGULATOR_SUPPLY("vddio_vi", NULL),
152 };
153 static struct regulator_consumer_supply tps658621_ldo7_supply[] = {
154         REGULATOR_SUPPLY("avdd_hdmi", NULL),
155         REGULATOR_SUPPLY("vdd_fuse", NULL),
156 };
157 static struct regulator_consumer_supply tps658621_ldo8_supply[] = {
158         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
159 };
160 static struct regulator_consumer_supply tps658621_ldo9_supply[] = {
161         REGULATOR_SUPPLY("avdd_2v85", NULL),
162         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
163         REGULATOR_SUPPLY("avdd_amp", NULL),
164 };
165
166 #define REGULATOR_INIT(_id, _minmv, _maxmv)                             \
167         {                                                               \
168                 .constraints = {                                        \
169                         .min_uV = (_minmv)*1000,                        \
170                         .max_uV = (_maxmv)*1000,                        \
171                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
172                                              REGULATOR_MODE_STANDBY),   \
173                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
174                                            REGULATOR_CHANGE_STATUS |    \
175                                            REGULATOR_CHANGE_VOLTAGE),   \
176                 },                                                      \
177                 .num_consumer_supplies = ARRAY_SIZE(tps658621_##_id##_supply),\
178                 .consumer_supplies = tps658621_##_id##_supply,          \
179         }
180
181 static struct regulator_init_data sm0_data = REGULATOR_INIT(sm0, 725, 1500);
182 static struct regulator_init_data sm1_data = REGULATOR_INIT(sm1, 725, 1500);
183 static struct regulator_init_data sm2_data = REGULATOR_INIT(sm2, 3000, 4550);
184 static struct regulator_init_data ldo0_data = REGULATOR_INIT(ldo0, 1250, 3300);
185 static struct regulator_init_data ldo1_data = REGULATOR_INIT(ldo1, 725, 1500);
186 static struct regulator_init_data ldo2_data = REGULATOR_INIT(ldo2, 725, 1500);
187 static struct regulator_init_data ldo3_data = REGULATOR_INIT(ldo3, 1250, 3300);
188 static struct regulator_init_data ldo4_data = REGULATOR_INIT(ldo4, 1700, 2475);
189 static struct regulator_init_data ldo5_data = REGULATOR_INIT(ldo5, 1250, 3300);
190 static struct regulator_init_data ldo6_data = REGULATOR_INIT(ldo6, 1250, 3300);
191 static struct regulator_init_data ldo7_data = REGULATOR_INIT(ldo7, 1250, 3300);
192 static struct regulator_init_data ldo8_data = REGULATOR_INIT(ldo8, 1250, 3300);
193 static struct regulator_init_data ldo9_data = REGULATOR_INIT(ldo9, 1250, 3300);
194
195 static struct tps6586x_rtc_platform_data rtc_data = {
196         .irq = TEGRA_NR_IRQS + TPS6586X_INT_RTC_ALM1,
197 };
198
199 #define TPS_REG(_id, _data)                     \
200         {                                       \
201                 .id = TPS6586X_ID_##_id,        \
202                 .name = "tps6586x-regulator",   \
203                 .platform_data = _data,         \
204         }
205
206 static struct tps6586x_subdev_info tps_devs[] = {
207         TPS_REG(SM_0, &sm0_data),
208         TPS_REG(SM_1, &sm1_data),
209         TPS_REG(SM_2, &sm2_data),
210         TPS_REG(LDO_0, &ldo0_data),
211         TPS_REG(LDO_1, &ldo1_data),
212         TPS_REG(LDO_2, &ldo2_data),
213         TPS_REG(LDO_3, &ldo3_data),
214         TPS_REG(LDO_4, &ldo4_data),
215         TPS_REG(LDO_5, &ldo5_data),
216         TPS_REG(LDO_6, &ldo6_data),
217         TPS_REG(LDO_7, &ldo7_data),
218         TPS_REG(LDO_8, &ldo8_data),
219         TPS_REG(LDO_9, &ldo9_data),
220         {
221                 .id     = 0,
222                 .name   = "tps6586x-rtc",
223                 .platform_data = &rtc_data,
224         },
225 };
226
227 static struct tps6586x_platform_data tps_platform = {
228         .irq_base = TEGRA_NR_IRQS,
229         .num_subdevs = ARRAY_SIZE(tps_devs),
230         .subdevs = tps_devs,
231         .gpio_base = TEGRA_NR_GPIOS,
232 };
233
234 static struct i2c_board_info __initdata ventana_regulators[] = {
235         {
236                 I2C_BOARD_INFO("tps6586x", 0x34),
237                 .irq            = INT_EXTERNAL_PMU,
238                 .platform_data  = &tps_platform,
239         },
240 };
241
242 static struct tegra_suspend_platform_data ventana_suspend_data = {
243         .cpu_timer      = 2000,
244         .cpu_off_timer  = 0,
245         .suspend_mode   = TEGRA_SUSPEND_LP1,
246         .core_timer     = 0x7e7e,
247         .core_off_timer = 0,
248         .separate_req   = true,
249         .corereq_high   = false,
250         .sysclkreq_high = true,
251         .wake_enb       = TEGRA_WAKE_GPIO_PV2,
252         .wake_high      = 0,
253         .wake_low       = TEGRA_WAKE_GPIO_PV2,
254         .wake_any       = 0,
255 };
256
257 int __init ventana_regulator_init(void)
258 {
259         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
260         u32 pmc_ctrl;
261
262         /* configure the power management controller to trigger PMU
263          * interrupts when low */
264         pmc_ctrl = readl(pmc + PMC_CTRL);
265         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
266         platform_device_register(&ventana_pda_power_device);
267         i2c_register_board_info(4, ventana_regulators, 1);
268         tegra_init_suspend(&ventana_suspend_data);
269         return 0;
270 }