[ARM] tegra: ventana: enable battery charging at boot up
[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 "fuse.h"
33 #include "power.h"
34 #include "wakeups-t2.h"
35 #include "board.h"
36
37 #define PMC_CTRL                0x0
38 #define PMC_CTRL_INTR_LOW       (1 << 17)
39
40 #define ventana_ac_ok   TEGRA_GPIO_PV3
41
42 int __init ventana_charge_init(void)
43 {
44         gpio_request(ventana_ac_ok, "ac_ok");
45         gpio_direction_input(ventana_ac_ok);
46         tegra_gpio_enable(ventana_ac_ok);
47         return 0;
48 }
49
50 static struct regulator_consumer_supply tps658621_sm0_supply[] = {
51         REGULATOR_SUPPLY("vdd_core", NULL),
52 };
53 static struct regulator_consumer_supply tps658621_sm1_supply[] = {
54         REGULATOR_SUPPLY("vdd_cpu", NULL),
55 };
56 static struct regulator_consumer_supply tps658621_sm2_supply[] = {
57         REGULATOR_SUPPLY("vdd_sm2", NULL),
58 };
59 static struct regulator_consumer_supply tps658621_ldo0_supply[] = {
60         REGULATOR_SUPPLY("p_cam_avdd", NULL),
61 };
62 static struct regulator_consumer_supply tps658621_ldo1_supply[] = {
63         REGULATOR_SUPPLY("avdd_pll", NULL),
64 };
65 static struct regulator_consumer_supply tps658621_ldo2_supply[] = {
66         REGULATOR_SUPPLY("vdd_rtc", NULL),
67         REGULATOR_SUPPLY("vdd_aon", NULL),
68 };
69 static struct regulator_consumer_supply tps658621_ldo3_supply[] = {
70         REGULATOR_SUPPLY("avdd_usb", NULL),
71         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
72         REGULATOR_SUPPLY("avdd_lvds", NULL),
73 };
74 static struct regulator_consumer_supply tps658621_ldo4_supply[] = {
75         REGULATOR_SUPPLY("avdd_osc", NULL),
76         REGULATOR_SUPPLY("vddio_sys", "panjit_touch"),
77 };
78 static struct regulator_consumer_supply tps658621_ldo5_supply[] = {
79         REGULATOR_SUPPLY("vcore_mmc", "sdhci-tegra.1"),
80         REGULATOR_SUPPLY("vcore_mmc", "sdhci-tegra.3"),
81 };
82 static struct regulator_consumer_supply tps658621_ldo6_supply[] = {
83         REGULATOR_SUPPLY("vcsi", "tegra_camera"),
84 };
85 static struct regulator_consumer_supply tps658621_ldo7_supply[] = {
86         REGULATOR_SUPPLY("avdd_hdmi", NULL),
87         REGULATOR_SUPPLY("vdd_fuse", NULL),
88 };
89 static struct regulator_consumer_supply tps658621_ldo8_supply[] = {
90         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
91 };
92 static struct regulator_consumer_supply tps658621_ldo9_supply[] = {
93         REGULATOR_SUPPLY("avdd_2v85", NULL),
94         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
95         REGULATOR_SUPPLY("avdd_amp", NULL),
96 };
97
98 #define REGULATOR_INIT(_id, _minmv, _maxmv)                             \
99         {                                                               \
100                 .constraints = {                                        \
101                         .min_uV = (_minmv)*1000,                        \
102                         .max_uV = (_maxmv)*1000,                        \
103                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
104                                              REGULATOR_MODE_STANDBY),   \
105                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
106                                            REGULATOR_CHANGE_STATUS |    \
107                                            REGULATOR_CHANGE_VOLTAGE),   \
108                 },                                                      \
109                 .num_consumer_supplies = ARRAY_SIZE(tps658621_##_id##_supply),\
110                 .consumer_supplies = tps658621_##_id##_supply,          \
111         }
112
113 static struct regulator_init_data sm0_data = REGULATOR_INIT(sm0, 725, 1500);
114 static struct regulator_init_data sm1_data = REGULATOR_INIT(sm1, 725, 1500);
115 static struct regulator_init_data sm2_data = REGULATOR_INIT(sm2, 3000, 4550);
116 static struct regulator_init_data ldo0_data = REGULATOR_INIT(ldo0, 1250, 3300);
117 static struct regulator_init_data ldo1_data = REGULATOR_INIT(ldo1, 725, 1500);
118 static struct regulator_init_data ldo2_data = REGULATOR_INIT(ldo2, 725, 1500);
119 static struct regulator_init_data ldo3_data = REGULATOR_INIT(ldo3, 1250, 3300);
120 static struct regulator_init_data ldo4_data = REGULATOR_INIT(ldo4, 1700, 2475);
121 static struct regulator_init_data ldo5_data = REGULATOR_INIT(ldo5, 1250, 3300);
122 static struct regulator_init_data ldo6_data = REGULATOR_INIT(ldo6, 1250, 1800);
123 static struct regulator_init_data ldo7_data = REGULATOR_INIT(ldo7, 1250, 3300);
124 static struct regulator_init_data ldo8_data = REGULATOR_INIT(ldo8, 1250, 3300);
125 static struct regulator_init_data ldo9_data = REGULATOR_INIT(ldo9, 1250, 3300);
126
127 static struct tps6586x_rtc_platform_data rtc_data = {
128         .irq = TEGRA_NR_IRQS + TPS6586X_INT_RTC_ALM1,
129 };
130
131 #define TPS_REG(_id, _data)                     \
132         {                                       \
133                 .id = TPS6586X_ID_##_id,        \
134                 .name = "tps6586x-regulator",   \
135                 .platform_data = _data,         \
136         }
137
138 static struct tps6586x_subdev_info tps_devs[] = {
139         TPS_REG(SM_0, &sm0_data),
140         TPS_REG(SM_1, &sm1_data),
141         TPS_REG(SM_2, &sm2_data),
142         TPS_REG(LDO_0, &ldo0_data),
143         TPS_REG(LDO_1, &ldo1_data),
144         TPS_REG(LDO_2, &ldo2_data),
145         TPS_REG(LDO_3, &ldo3_data),
146         TPS_REG(LDO_4, &ldo4_data),
147         TPS_REG(LDO_5, &ldo5_data),
148         TPS_REG(LDO_6, &ldo6_data),
149         TPS_REG(LDO_7, &ldo7_data),
150         TPS_REG(LDO_8, &ldo8_data),
151         TPS_REG(LDO_9, &ldo9_data),
152         {
153                 .id     = 0,
154                 .name   = "tps6586x-rtc",
155                 .platform_data = &rtc_data,
156         },
157 };
158
159 static struct tps6586x_platform_data tps_platform = {
160         .irq_base = TEGRA_NR_IRQS,
161         .num_subdevs = ARRAY_SIZE(tps_devs),
162         .subdevs = tps_devs,
163         .gpio_base = TEGRA_NR_GPIOS,
164 };
165
166 static struct i2c_board_info __initdata ventana_regulators[] = {
167         {
168                 I2C_BOARD_INFO("tps6586x", 0x34),
169                 .irq            = INT_EXTERNAL_PMU,
170                 .platform_data  = &tps_platform,
171         },
172 };
173
174 static struct tegra_suspend_platform_data ventana_suspend_data = {
175         /*
176          * Check power on time and crystal oscillator start time
177          * for appropriate settings.
178          */
179         .cpu_timer      = 2000,
180         .cpu_off_timer  = 100,
181         .suspend_mode   = TEGRA_SUSPEND_LP0,
182         .core_timer     = 0x7e7e,
183         .core_off_timer = 0xf,
184         .separate_req   = true,
185         .corereq_high   = false,
186         .sysclkreq_high = true,
187         .wake_enb       = TEGRA_WAKE_GPIO_PV2,
188         .wake_high      = 0,
189         .wake_low       = TEGRA_WAKE_GPIO_PV2,
190         .wake_any       = 0,
191 };
192
193 int __init ventana_regulator_init(void)
194 {
195         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
196         void __iomem *chip_id = IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804;
197         u32 pmc_ctrl;
198         u32 minor;
199
200         minor = (readl(chip_id) >> 16) & 0xf;
201         /* A03 (but not A03p) chips do not support LP0 */
202         if (minor == 3 && !(tegra_spare_fuse(18) || tegra_spare_fuse(19)))
203                 ventana_suspend_data.suspend_mode = TEGRA_SUSPEND_LP1;
204
205         /* configure the power management controller to trigger PMU
206          * interrupts when low */
207         pmc_ctrl = readl(pmc + PMC_CTRL);
208         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
209         i2c_register_board_info(4, ventana_regulators, 1);
210         tegra_init_suspend(&ventana_suspend_data);
211         return 0;
212 }