2 * Copyright (C) 2010 NVIDIA, Inc.
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.
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.
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
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>
28 #include <mach/iomap.h>
29 #include <mach/irqs.h>
31 #include "gpio-names.h"
33 #include "wakeups-t2.h"
37 #define PMC_CTRL_INTR_LOW (1 << 17)
39 static int ac_ok = TEGRA_GPIO_PV3;
40 static int charge_disable = TEGRA_GPIO_PR6;
42 static int charge_init(struct device *dev)
44 int ret = gpio_request(charge_disable, "chg_disable");
48 ret = gpio_request(ac_ok, "ac_ok");
50 gpio_free(charge_disable);
54 ret = gpio_direction_output(charge_disable, 0);
58 ret = gpio_direction_input(ac_ok);
62 tegra_gpio_enable(ac_ok);
63 tegra_gpio_enable(charge_disable);
69 gpio_free(charge_disable);
73 static void charge_exit(struct device *dev)
75 gpio_free(charge_disable);
78 static int ac_online(void)
80 return !gpio_get_value(ac_ok);
83 static void set_charge(int flags)
85 if (flags == PDA_POWER_CHARGE_AC)
86 gpio_set_value(charge_disable, 0);
88 gpio_set_value(charge_disable, 1);
89 /* USB charging not supported on Ventana */
92 static struct resource ventana_pda_resources[] = {
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),
102 static struct pda_power_pdata ventana_pda_data = {
103 .is_ac_online = ac_online,
106 .set_charge = set_charge,
109 static struct platform_device ventana_pda_power_device = {
112 .resource = ventana_pda_resources,
113 .num_resources = ARRAY_SIZE(ventana_pda_resources),
115 .platform_data = &ventana_pda_data,
120 static struct regulator_consumer_supply tps658621_sm0_supply[] = {
121 REGULATOR_SUPPLY("vdd_core", NULL),
123 static struct regulator_consumer_supply tps658621_sm1_supply[] = {
124 REGULATOR_SUPPLY("vdd_cpu", NULL),
126 static struct regulator_consumer_supply tps658621_sm2_supply[] = {
127 REGULATOR_SUPPLY("vdd_sm2", NULL),
129 static struct regulator_consumer_supply tps658621_ldo0_supply[] = {
130 REGULATOR_SUPPLY("p_cam_avdd", NULL),
132 static struct regulator_consumer_supply tps658621_ldo1_supply[] = {
133 REGULATOR_SUPPLY("avdd_pll", NULL),
135 static struct regulator_consumer_supply tps658621_ldo2_supply[] = {
136 REGULATOR_SUPPLY("vdd_rtc", NULL),
138 static struct regulator_consumer_supply tps658621_ldo3_supply[] = {
139 REGULATOR_SUPPLY("avdd_usb", NULL),
140 REGULATOR_SUPPLY("avdd_usb_pll", NULL),
141 REGULATOR_SUPPLY("avdd_lvds", NULL),
143 static struct regulator_consumer_supply tps658621_ldo4_supply[] = {
144 REGULATOR_SUPPLY("avdd_osc", NULL),
145 REGULATOR_SUPPLY("vddio_sys", "panjit_touch"),
147 static struct regulator_consumer_supply tps658621_ldo5_supply[] = {
148 REGULATOR_SUPPLY("vcore_mmc", "sdhci-tegra.1"),
149 REGULATOR_SUPPLY("vcore_mmc", "sdhci-tegra.3"),
151 static struct regulator_consumer_supply tps658621_ldo6_supply[] = {
152 REGULATOR_SUPPLY("vddio_vi", NULL),
154 static struct regulator_consumer_supply tps658621_ldo7_supply[] = {
155 REGULATOR_SUPPLY("avdd_hdmi", NULL),
156 REGULATOR_SUPPLY("vdd_fuse", NULL),
158 static struct regulator_consumer_supply tps658621_ldo8_supply[] = {
159 REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
161 static struct regulator_consumer_supply tps658621_ldo9_supply[] = {
162 REGULATOR_SUPPLY("avdd_2v85", NULL),
163 REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
164 REGULATOR_SUPPLY("avdd_amp", NULL),
167 #define REGULATOR_INIT(_id, _minmv, _maxmv) \
170 .min_uV = (_minmv)*1000, \
171 .max_uV = (_maxmv)*1000, \
172 .valid_modes_mask = (REGULATOR_MODE_NORMAL | \
173 REGULATOR_MODE_STANDBY), \
174 .valid_ops_mask = (REGULATOR_CHANGE_MODE | \
175 REGULATOR_CHANGE_STATUS | \
176 REGULATOR_CHANGE_VOLTAGE), \
178 .num_consumer_supplies = ARRAY_SIZE(tps658621_##_id##_supply),\
179 .consumer_supplies = tps658621_##_id##_supply, \
182 static struct regulator_init_data sm0_data = REGULATOR_INIT(sm0, 725, 1500);
183 static struct regulator_init_data sm1_data = REGULATOR_INIT(sm1, 725, 1500);
184 static struct regulator_init_data sm2_data = REGULATOR_INIT(sm2, 3000, 4550);
185 static struct regulator_init_data ldo0_data = REGULATOR_INIT(ldo0, 1250, 3300);
186 static struct regulator_init_data ldo1_data = REGULATOR_INIT(ldo1, 725, 1500);
187 static struct regulator_init_data ldo2_data = REGULATOR_INIT(ldo2, 725, 1500);
188 static struct regulator_init_data ldo3_data = REGULATOR_INIT(ldo3, 1250, 3300);
189 static struct regulator_init_data ldo4_data = REGULATOR_INIT(ldo4, 1700, 2475);
190 static struct regulator_init_data ldo5_data = REGULATOR_INIT(ldo5, 1250, 3300);
191 static struct regulator_init_data ldo6_data = REGULATOR_INIT(ldo6, 1250, 3300);
192 static struct regulator_init_data ldo7_data = REGULATOR_INIT(ldo7, 1250, 3300);
193 static struct regulator_init_data ldo8_data = REGULATOR_INIT(ldo8, 1250, 3300);
194 static struct regulator_init_data ldo9_data = REGULATOR_INIT(ldo9, 1250, 3300);
196 static struct tps6586x_rtc_platform_data rtc_data = {
197 .irq = TEGRA_NR_IRQS + TPS6586X_INT_RTC_ALM1,
200 #define TPS_REG(_id, _data) \
202 .id = TPS6586X_ID_##_id, \
203 .name = "tps6586x-regulator", \
204 .platform_data = _data, \
207 static struct tps6586x_subdev_info tps_devs[] = {
208 TPS_REG(SM_0, &sm0_data),
209 TPS_REG(SM_1, &sm1_data),
210 TPS_REG(SM_2, &sm2_data),
211 TPS_REG(LDO_0, &ldo0_data),
212 TPS_REG(LDO_1, &ldo1_data),
213 TPS_REG(LDO_2, &ldo2_data),
214 TPS_REG(LDO_3, &ldo3_data),
215 TPS_REG(LDO_4, &ldo4_data),
216 TPS_REG(LDO_5, &ldo5_data),
217 TPS_REG(LDO_6, &ldo6_data),
218 TPS_REG(LDO_7, &ldo7_data),
219 TPS_REG(LDO_8, &ldo8_data),
220 TPS_REG(LDO_9, &ldo9_data),
223 .name = "tps6586x-rtc",
224 .platform_data = &rtc_data,
228 static struct tps6586x_platform_data tps_platform = {
229 .irq_base = TEGRA_NR_IRQS,
230 .num_subdevs = ARRAY_SIZE(tps_devs),
232 .gpio_base = TEGRA_NR_GPIOS,
235 static struct i2c_board_info __initdata ventana_regulators[] = {
237 I2C_BOARD_INFO("tps6586x", 0x34),
238 .irq = INT_EXTERNAL_PMU,
239 .platform_data = &tps_platform,
243 static struct tegra_suspend_platform_data ventana_suspend_data = {
246 .suspend_mode = TEGRA_SUSPEND_LP1,
247 .core_timer = 0x7e7e,
249 .separate_req = true,
250 .corereq_high = false,
251 .sysclkreq_high = true,
252 .wake_enb = TEGRA_WAKE_GPIO_PV2,
254 .wake_low = TEGRA_WAKE_GPIO_PV2,
258 int __init ventana_regulator_init(void)
260 void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
263 /* configure the power management controller to trigger PMU
264 * interrupts when low */
265 pmc_ctrl = readl(pmc + PMC_CTRL);
266 writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
267 platform_device_register(&ventana_pda_power_device);
268 i2c_register_board_info(4, ventana_regulators, 1);
269 tegra_init_suspend(&ventana_suspend_data);