[ARM] tegra: i2s: Continuous DMA support
[firefly-linux-kernel-4.4.55.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         REGULATOR_SUPPLY("avdd_lvds", NULL),
142 };
143 static struct regulator_consumer_supply tps658621_ldo4_supply[] = {
144         REGULATOR_SUPPLY("avdd_osc", NULL),
145         REGULATOR_SUPPLY("vddio_sys", "panjit_touch"),
146 };
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"),
150 };
151 static struct regulator_consumer_supply tps658621_ldo6_supply[] = {
152         REGULATOR_SUPPLY("vddio_vi", NULL),
153 };
154 static struct regulator_consumer_supply tps658621_ldo7_supply[] = {
155         REGULATOR_SUPPLY("avdd_hdmi", NULL),
156         REGULATOR_SUPPLY("vdd_fuse", NULL),
157 };
158 static struct regulator_consumer_supply tps658621_ldo8_supply[] = {
159         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
160 };
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),
165 };
166
167 #define REGULATOR_INIT(_id, _minmv, _maxmv)                             \
168         {                                                               \
169                 .constraints = {                                        \
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),   \
177                 },                                                      \
178                 .num_consumer_supplies = ARRAY_SIZE(tps658621_##_id##_supply),\
179                 .consumer_supplies = tps658621_##_id##_supply,          \
180         }
181
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);
195
196 static struct tps6586x_rtc_platform_data rtc_data = {
197         .irq = TEGRA_NR_IRQS + TPS6586X_INT_RTC_ALM1,
198 };
199
200 #define TPS_REG(_id, _data)                     \
201         {                                       \
202                 .id = TPS6586X_ID_##_id,        \
203                 .name = "tps6586x-regulator",   \
204                 .platform_data = _data,         \
205         }
206
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),
221         {
222                 .id     = 0,
223                 .name   = "tps6586x-rtc",
224                 .platform_data = &rtc_data,
225         },
226 };
227
228 static struct tps6586x_platform_data tps_platform = {
229         .irq_base = TEGRA_NR_IRQS,
230         .num_subdevs = ARRAY_SIZE(tps_devs),
231         .subdevs = tps_devs,
232         .gpio_base = TEGRA_NR_GPIOS,
233 };
234
235 static struct i2c_board_info __initdata ventana_regulators[] = {
236         {
237                 I2C_BOARD_INFO("tps6586x", 0x34),
238                 .irq            = INT_EXTERNAL_PMU,
239                 .platform_data  = &tps_platform,
240         },
241 };
242
243 static struct tegra_suspend_platform_data ventana_suspend_data = {
244         .cpu_timer      = 2000,
245         .cpu_off_timer  = 0,
246         .suspend_mode   = TEGRA_SUSPEND_LP1,
247         .core_timer     = 0x7e7e,
248         .core_off_timer = 0,
249         .separate_req   = true,
250         .corereq_high   = false,
251         .sysclkreq_high = true,
252         .wake_enb       = TEGRA_WAKE_GPIO_PV2,
253         .wake_high      = 0,
254         .wake_low       = TEGRA_WAKE_GPIO_PV2,
255         .wake_any       = 0,
256 };
257
258 int __init ventana_regulator_init(void)
259 {
260         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
261         u32 pmc_ctrl;
262
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);
270         return 0;
271 }