blob: 4d9f2579199e1534e322fdc1f888bcaed76ec6c1 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13/*
14 * Qualcomm PMIC8058 driver header file
15 *
16 */
17
18#include <linux/irq.h>
19#include <linux/mfd/core.h>
20
21#define PM8058_GPIOS 40
22#define PM8058_MPPS 12
23
24#define PM8058_IRQ_BLOCK_BIT(block, bit) ((block) * 8 + (bit))
25
26/* MPPs and GPIOs [0,N) */
27#define PM8058_MPP_IRQ(base, mpp) ((base) + \
28 PM8058_IRQ_BLOCK_BIT(16, (mpp)))
29#define PM8058_GPIO_IRQ(base, gpio) ((base) + \
30 PM8058_IRQ_BLOCK_BIT(24, (gpio)))
31
32#define PM8058_KEYPAD_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(9, 2))
33#define PM8058_KEYSTUCK_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(9, 3))
34
35#define PM8058_VCP_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(1, 0))
36#define PM8058_CHGILIM_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(1, 3))
37#define PM8058_VBATDET_LOW_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(1, 4))
38#define PM8058_BATT_REPLACE_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(1, 5))
39#define PM8058_CHGINVAL_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(1, 6))
40#define PM8058_CHGVAL_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(1, 7))
41#define PM8058_CHG_END_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 0))
42#define PM8058_FASTCHG_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 1))
43#define PM8058_CHGSTATE_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 3))
44#define PM8058_AUTO_CHGFAIL_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 4))
45#define PM8058_AUTO_CHGDONE_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 5))
46#define PM8058_ATCFAIL_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 6))
47#define PM8058_ATC_DONE_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 7))
48#define PM8058_OVP_OK_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 0))
49#define PM8058_COARSE_DET_OVP_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 1))
50#define PM8058_VCPMAJOR_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 2))
51#define PM8058_CHG_GONE_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 3))
52#define PM8058_CHGTLIMIT_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 4))
53#define PM8058_CHGHOT_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 5))
54#define PM8058_BATTTEMP_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 6))
55#define PM8058_BATTCONNECT_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 7))
56#define PM8058_BATFET_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(5, 4))
57#define PM8058_VBATDET_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(5, 5))
58#define PM8058_VBAT_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(5, 6))
59
60#define PM8058_CBLPWR_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(4, 3))
61
62#define PM8058_PWRKEY_REL_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(6, 2))
63#define PM8058_PWRKEY_PRESS_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(6, 3))
64#define PM8058_SW_0_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(7, 1))
65#define PM8058_IR_0_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(7, 0))
66#define PM8058_SW_1_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(7, 3))
67#define PM8058_IR_1_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(7, 2))
68#define PM8058_SW_2_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(7, 5))
69#define PM8058_IR_2_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(7, 4))
70#define PM8058_RTC_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(6, 5))
71#define PM8058_RTC_ALARM_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(4, 7))
72#define PM8058_ADC_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(9, 4))
73#define PM8058_TEMP_ALARM_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(6, 7))
74#define PM8058_OSCHALT_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(4, 6))
75#define PM8058_BATT_ALARM_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(5, 6))
Abhijeet Dharmapurikar6d565fd2011-09-15 18:49:56 -070076#define PM8058_RESOUT_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(6, 4))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070077
78struct pm8058_chip;
79
80struct pm8058_platform_data {
81 /* This table is only needed for misc interrupts. */
82 int irq_base;
Anirudh Ghayal9d9cdc22011-10-10 17:17:07 +053083 int irq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070084 int (*init)(struct pm8058_chip *pm_chip);
85
86 int num_subdevs;
87 struct mfd_cell *sub_devices;
88 int irq_trigger_flags;
89 struct mfd_cell *charger_sub_device;
90};
91
92struct pm8058_gpio_platform_data {
93 int gpio_base;
94 int irq_base;
95 int (*init)(void);
96};
97
98/* GPIO parameters */
99/* direction */
100#define PM_GPIO_DIR_OUT 0x01
101#define PM_GPIO_DIR_IN 0x02
102#define PM_GPIO_DIR_BOTH (PM_GPIO_DIR_OUT | PM_GPIO_DIR_IN)
103
104/* output_buffer */
105#define PM_GPIO_OUT_BUF_OPEN_DRAIN 1
106#define PM_GPIO_OUT_BUF_CMOS 0
107
108/* pull */
109#define PM_GPIO_PULL_UP_30 0
110#define PM_GPIO_PULL_UP_1P5 1
111#define PM_GPIO_PULL_UP_31P5 2
112#define PM_GPIO_PULL_UP_1P5_30 3
113#define PM_GPIO_PULL_DN 4
114#define PM_GPIO_PULL_NO 5
115
116/* vin_sel: Voltage Input Select */
117#define PM_GPIO_VIN_VPH 0
118#define PM_GPIO_VIN_BB 1
119#define PM_GPIO_VIN_S3 2
120#define PM_GPIO_VIN_L3 3
121#define PM_GPIO_VIN_L7 4
122#define PM_GPIO_VIN_L6 5
123#define PM_GPIO_VIN_L5 6
124#define PM_GPIO_VIN_L2 7
125
126/* out_strength */
127#define PM_GPIO_STRENGTH_NO 0
128#define PM_GPIO_STRENGTH_HIGH 1
129#define PM_GPIO_STRENGTH_MED 2
130#define PM_GPIO_STRENGTH_LOW 3
131
132/* function */
133#define PM_GPIO_FUNC_NORMAL 0
134#define PM_GPIO_FUNC_PAIRED 1
135#define PM_GPIO_FUNC_1 2
136#define PM_GPIO_FUNC_2 3
137#define PM_GPIO_DTEST1 4
138#define PM_GPIO_DTEST2 5
139#define PM_GPIO_DTEST3 6
140#define PM_GPIO_DTEST4 7
141
142struct pm8058_gpio {
143 int direction;
144 int output_buffer;
145 int output_value;
146 int pull;
147 int vin_sel; /* 0..7 */
148 int out_strength;
149 int function;
150 int inv_int_pol; /* invert interrupt polarity */
151 int disable_pin; /* disable pin and tri-state its pad */
152};
153
Terence Hampson13163082011-08-09 10:17:06 -0400154struct pmic8058_charger_data {
155 unsigned int max_source_current;
156 int charger_type;
157};
158
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700159/* chip revision */
160#define PM_8058_REV_1p0 0xE1
161#define PM_8058_REV_2p0 0xE2
162#define PM_8058_REV_2p1 0xE3
163
164/* misc: control mask and flag */
165#define PM8058_UART_MUX_MASK 0x60
166
167#define PM8058_UART_MUX_NO 0x0
168#define PM8058_UART_MUX_1 0x20
169#define PM8058_UART_MUX_2 0x40
170#define PM8058_UART_MUX_3 0x60
171
172enum pon_config{
173 DISABLE_HARD_RESET = 0,
174 SHUTDOWN_ON_HARD_RESET,
175 RESTART_ON_HARD_RESET,
176 MAX_PON_CONFIG,
177};
178
179enum pm8058_smpl_delay {
180 PM8058_SMPL_DELAY_0p5,
181 PM8058_SMPL_DELAY_1p0,
182 PM8058_SMPL_DELAY_1p5,
183 PM8058_SMPL_DELAY_2p0,
184};
185
186/* Note -do not call pm8058_read and pm8058_write in an atomic context */
187int pm8058_read(struct pm8058_chip *pm_chip, u16 addr, u8 *values,
188 unsigned int len);
189int pm8058_write(struct pm8058_chip *pm_chip, u16 addr, u8 *values,
190 unsigned int len);
191
192int pm8058_gpio_config(int gpio, struct pm8058_gpio *param);
193
194int pm8058_rev(struct pm8058_chip *pm_chip);
195
196int pm8058_irq_get_rt_status(struct pm8058_chip *pm_chip, int irq);
197
198int pm8058_misc_control(struct pm8058_chip *pm_chip, int mask, int flag);
199
200#ifdef CONFIG_PMIC8058
201int pm8058_reset_pwr_off(int reset);
202#else
203static inline int pm8058_reset_pwr_off(int reset) { return 0; }
204#endif
205
206
207int pm8058_hard_reset_config(enum pon_config config);
208
209/**
210 * pm8058_smpl_control - enables/disables SMPL detection
211 * @enable: 0 = shutdown PMIC on power loss, 1 = reset PMIC on power loss
212 *
213 * This function enables or disables the Sudden Momentary Power Loss detection
214 * module. If SMPL detection is enabled, then when a sufficiently long power
215 * loss event occurs, the PMIC will automatically reset itself. If SMPL
216 * detection is disabled, then the PMIC will shutdown when power loss occurs.
217 *
218 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
219 */
220int pm8058_smpl_control(int enable);
221
222/**
223 * pm8058_smpl_set_delay - sets the SMPL detection time delay
224 * @delay: enum value corresponding to delay time
225 *
226 * This function sets the time delay of the SMPL detection module. If power
227 * is reapplied within this interval, then the PMIC reset automatically. The
228 * SMPL detection module must be enabled for this delay time to take effect.
229 *
230 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
231 */
232int pm8058_smpl_set_delay(enum pm8058_smpl_delay delay);
233
234/**
235 * pm8058_watchdog_reset_control - enables/disables watchdog reset detection
236 * @enable: 0 = shutdown when PS_HOLD goes low, 1 = reset when PS_HOLD goes low
237 *
238 * This function enables or disables the PMIC watchdog reset detection feature.
239 * If watchdog reset detection is enabled, then the PMIC will reset itself
240 * when PS_HOLD goes low. If it is not enabled, then the PMIC will shutdown
241 * when PS_HOLD goes low.
242 *
243 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
244 */
245int pm8058_watchdog_reset_control(int enable);
Willie Ruan6a3c9142011-07-14 16:52:41 -0700246
247/**
248 * pm8058_stay_on - enables stay_on feature
249 *
250 * PMIC stay-on feature allows PMIC to ignore MSM PS_HOLD=low
251 * signal so that some special functions like debugging could be
252 * performed.
253 *
254 * This feature should not be used in any product release.
255 *
256 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
257 */
258int pm8058_stay_on(void);