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