blob: 8370f180f625a1ed25cca96f4de855e286e3c028 [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;
83 int (*init)(struct pm8058_chip *pm_chip);
84
85 int num_subdevs;
86 struct mfd_cell *sub_devices;
87 int irq_trigger_flags;
88 struct mfd_cell *charger_sub_device;
89};
90
91struct pm8058_gpio_platform_data {
92 int gpio_base;
93 int irq_base;
94 int (*init)(void);
95};
96
97/* GPIO parameters */
98/* direction */
99#define PM_GPIO_DIR_OUT 0x01
100#define PM_GPIO_DIR_IN 0x02
101#define PM_GPIO_DIR_BOTH (PM_GPIO_DIR_OUT | PM_GPIO_DIR_IN)
102
103/* output_buffer */
104#define PM_GPIO_OUT_BUF_OPEN_DRAIN 1
105#define PM_GPIO_OUT_BUF_CMOS 0
106
107/* pull */
108#define PM_GPIO_PULL_UP_30 0
109#define PM_GPIO_PULL_UP_1P5 1
110#define PM_GPIO_PULL_UP_31P5 2
111#define PM_GPIO_PULL_UP_1P5_30 3
112#define PM_GPIO_PULL_DN 4
113#define PM_GPIO_PULL_NO 5
114
115/* vin_sel: Voltage Input Select */
116#define PM_GPIO_VIN_VPH 0
117#define PM_GPIO_VIN_BB 1
118#define PM_GPIO_VIN_S3 2
119#define PM_GPIO_VIN_L3 3
120#define PM_GPIO_VIN_L7 4
121#define PM_GPIO_VIN_L6 5
122#define PM_GPIO_VIN_L5 6
123#define PM_GPIO_VIN_L2 7
124
125/* out_strength */
126#define PM_GPIO_STRENGTH_NO 0
127#define PM_GPIO_STRENGTH_HIGH 1
128#define PM_GPIO_STRENGTH_MED 2
129#define PM_GPIO_STRENGTH_LOW 3
130
131/* function */
132#define PM_GPIO_FUNC_NORMAL 0
133#define PM_GPIO_FUNC_PAIRED 1
134#define PM_GPIO_FUNC_1 2
135#define PM_GPIO_FUNC_2 3
136#define PM_GPIO_DTEST1 4
137#define PM_GPIO_DTEST2 5
138#define PM_GPIO_DTEST3 6
139#define PM_GPIO_DTEST4 7
140
141struct pm8058_gpio {
142 int direction;
143 int output_buffer;
144 int output_value;
145 int pull;
146 int vin_sel; /* 0..7 */
147 int out_strength;
148 int function;
149 int inv_int_pol; /* invert interrupt polarity */
150 int disable_pin; /* disable pin and tri-state its pad */
151};
152
Terence Hampson13163082011-08-09 10:17:06 -0400153struct pmic8058_charger_data {
154 unsigned int max_source_current;
155 int charger_type;
156};
157
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700158/* chip revision */
159#define PM_8058_REV_1p0 0xE1
160#define PM_8058_REV_2p0 0xE2
161#define PM_8058_REV_2p1 0xE3
162
163/* misc: control mask and flag */
164#define PM8058_UART_MUX_MASK 0x60
165
166#define PM8058_UART_MUX_NO 0x0
167#define PM8058_UART_MUX_1 0x20
168#define PM8058_UART_MUX_2 0x40
169#define PM8058_UART_MUX_3 0x60
170
171enum pon_config{
172 DISABLE_HARD_RESET = 0,
173 SHUTDOWN_ON_HARD_RESET,
174 RESTART_ON_HARD_RESET,
175 MAX_PON_CONFIG,
176};
177
178enum pm8058_smpl_delay {
179 PM8058_SMPL_DELAY_0p5,
180 PM8058_SMPL_DELAY_1p0,
181 PM8058_SMPL_DELAY_1p5,
182 PM8058_SMPL_DELAY_2p0,
183};
184
185/* Note -do not call pm8058_read and pm8058_write in an atomic context */
186int pm8058_read(struct pm8058_chip *pm_chip, u16 addr, u8 *values,
187 unsigned int len);
188int pm8058_write(struct pm8058_chip *pm_chip, u16 addr, u8 *values,
189 unsigned int len);
190
191int pm8058_gpio_config(int gpio, struct pm8058_gpio *param);
192
193int pm8058_rev(struct pm8058_chip *pm_chip);
194
195int pm8058_irq_get_rt_status(struct pm8058_chip *pm_chip, int irq);
196
197int pm8058_misc_control(struct pm8058_chip *pm_chip, int mask, int flag);
198
199#ifdef CONFIG_PMIC8058
200int pm8058_reset_pwr_off(int reset);
201#else
202static inline int pm8058_reset_pwr_off(int reset) { return 0; }
203#endif
204
205
206int pm8058_hard_reset_config(enum pon_config config);
207
208/**
209 * pm8058_smpl_control - enables/disables SMPL detection
210 * @enable: 0 = shutdown PMIC on power loss, 1 = reset PMIC on power loss
211 *
212 * This function enables or disables the Sudden Momentary Power Loss detection
213 * module. If SMPL detection is enabled, then when a sufficiently long power
214 * loss event occurs, the PMIC will automatically reset itself. If SMPL
215 * detection is disabled, then the PMIC will shutdown when power loss occurs.
216 *
217 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
218 */
219int pm8058_smpl_control(int enable);
220
221/**
222 * pm8058_smpl_set_delay - sets the SMPL detection time delay
223 * @delay: enum value corresponding to delay time
224 *
225 * This function sets the time delay of the SMPL detection module. If power
226 * is reapplied within this interval, then the PMIC reset automatically. The
227 * SMPL detection module must be enabled for this delay time to take effect.
228 *
229 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
230 */
231int pm8058_smpl_set_delay(enum pm8058_smpl_delay delay);
232
233/**
234 * pm8058_watchdog_reset_control - enables/disables watchdog reset detection
235 * @enable: 0 = shutdown when PS_HOLD goes low, 1 = reset when PS_HOLD goes low
236 *
237 * This function enables or disables the PMIC watchdog reset detection feature.
238 * If watchdog reset detection is enabled, then the PMIC will reset itself
239 * when PS_HOLD goes low. If it is not enabled, then the PMIC will shutdown
240 * when PS_HOLD goes low.
241 *
242 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
243 */
244int pm8058_watchdog_reset_control(int enable);
Willie Ruan6a3c9142011-07-14 16:52:41 -0700245
246/**
247 * pm8058_stay_on - enables stay_on feature
248 *
249 * PMIC stay-on feature allows PMIC to ignore MSM PS_HOLD=low
250 * signal so that some special functions like debugging could be
251 * performed.
252 *
253 * This feature should not be used in any product release.
254 *
255 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
256 */
257int pm8058_stay_on(void);