4 * Copyright 2012 Texas Instruments
6 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #ifndef __MFD_LP8788_H__
15 #define __MFD_LP8788_H__
17 #include <linux/gpio.h>
18 #include <linux/irqdomain.h>
19 #include <linux/pwm.h>
20 #include <linux/regmap.h>
22 #define LP8788_DEV_BUCK "lp8788-buck"
23 #define LP8788_DEV_DLDO "lp8788-dldo"
24 #define LP8788_DEV_ALDO "lp8788-aldo"
25 #define LP8788_DEV_CHARGER "lp8788-charger"
26 #define LP8788_DEV_RTC "lp8788-rtc"
27 #define LP8788_DEV_BACKLIGHT "lp8788-backlight"
28 #define LP8788_DEV_VIBRATOR "lp8788-vibrator"
29 #define LP8788_DEV_KEYLED "lp8788-keyled"
30 #define LP8788_DEV_ADC "lp8788-adc"
32 #define LP8788_NUM_BUCKS 4
33 #define LP8788_NUM_DLDOS 12
34 #define LP8788_NUM_ALDOS 10
35 #define LP8788_NUM_BUCK2_DVS 2
37 #define LP8788_CHG_IRQ "CHG_IRQ"
38 #define LP8788_PRSW_IRQ "PRSW_IRQ"
39 #define LP8788_BATT_IRQ "BATT_IRQ"
40 #define LP8788_ALM_IRQ "ALARM_IRQ"
43 /* interrup register 1 : Addr 00h */
48 LP8788_INT_PWRON_TIME,
53 /* interrupt register 2 : Addr 01h */
54 LP8788_INT_CHG_INPUT_STATE,
57 LP8788_INT_CHG_RESTART,
58 LP8788_INT_RESTART_TIMEOUT,
59 LP8788_INT_FULLCHG_TIMEOUT,
60 LP8788_INT_PRECHG_TIMEOUT,
62 /* interrupt register 3 : Addr 02h */
63 LP8788_INT_RTC_ALARM1 = 17,
64 LP8788_INT_RTC_ALARM2,
65 LP8788_INT_ENTER_SYS_SUPPORT,
66 LP8788_INT_EXIT_SYS_SUPPORT,
80 enum lp8788_ext_ldo_en_id {
90 enum lp8788_charger_event {
95 enum lp8788_bl_ctrl_mode {
96 LP8788_BL_REGISTER_ONLY,
97 LP8788_BL_COMB_PWM_BASED, /* PWM + I2C, changed by PWM input */
98 LP8788_BL_COMB_REGISTER_BASED, /* PWM + I2C, changed by I2C */
101 enum lp8788_bl_dim_mode {
102 LP8788_DIM_EXPONENTIAL,
106 enum lp8788_bl_full_scale_current {
107 LP8788_FULLSCALE_5000uA,
108 LP8788_FULLSCALE_8500uA,
109 LP8788_FULLSCALE_1200uA,
110 LP8788_FULLSCALE_1550uA,
111 LP8788_FULLSCALE_1900uA,
112 LP8788_FULLSCALE_2250uA,
113 LP8788_FULLSCALE_2600uA,
114 LP8788_FULLSCALE_2950uA,
117 enum lp8788_bl_ramp_step {
128 enum lp8788_isink_scale {
129 LP8788_ISINK_SCALE_100mA,
130 LP8788_ISINK_SCALE_120mA,
133 enum lp8788_isink_number {
139 enum lp8788_alarm_sel {
166 * @gpio : gpio pin number for dvs control
167 * @vsel : dvs selector for buck v1 register
169 struct lp8788_buck1_dvs {
171 enum lp8788_dvs_sel vsel;
176 * @gpio : two gpio pin numbers are used for dvs
177 * @vsel : dvs selector for buck v2 register
179 struct lp8788_buck2_dvs {
180 int gpio[LP8788_NUM_BUCK2_DVS];
181 enum lp8788_dvs_sel vsel;
185 * struct lp8788_chg_param
186 * @addr : charging control register address (range : 0x11 ~ 0x1C)
187 * @val : charging parameter value
189 struct lp8788_chg_param {
195 * struct lp8788_charger_platform_data
196 * @adc_vbatt : adc channel name for battery voltage
197 * @adc_batt_temp : adc channel name for battery temperature
198 * @max_vbatt_mv : used for calculating battery capacity
199 * @chg_params : initial charging parameters
200 * @num_chg_params : numbers of charging parameters
201 * @charger_event : the charger event can be reported to the platform side
203 struct lp8788_charger_platform_data {
204 const char *adc_vbatt;
205 const char *adc_batt_temp;
206 unsigned int max_vbatt_mv;
207 struct lp8788_chg_param *chg_params;
209 void (*charger_event) (struct lp8788 *lp,
210 enum lp8788_charger_event event);
214 * struct lp8788_backlight_platform_data
215 * @name : backlight driver name. (default: "lcd-backlight")
216 * @initial_brightness : initial value of backlight brightness
217 * @bl_mode : brightness control by pwm or lp8788 register
218 * @dim_mode : dimming mode selection
219 * @full_scale : full scale current setting
220 * @rise_time : brightness ramp up step time
221 * @fall_time : brightness ramp down step time
222 * @pwm_pol : pwm polarity setting when bl_mode is pwm based
223 * @period_ns : platform specific pwm period value. unit is nano.
224 Only valid when bl_mode is LP8788_BL_COMB_PWM_BASED
226 struct lp8788_backlight_platform_data {
228 int initial_brightness;
229 enum lp8788_bl_ctrl_mode bl_mode;
230 enum lp8788_bl_dim_mode dim_mode;
231 enum lp8788_bl_full_scale_current full_scale;
232 enum lp8788_bl_ramp_step rise_time;
233 enum lp8788_bl_ramp_step fall_time;
234 enum pwm_polarity pwm_pol;
235 unsigned int period_ns;
239 * struct lp8788_led_platform_data
240 * @name : led driver name. (default: "keyboard-backlight")
241 * @scale : current scale
242 * @num : current sink number
243 * @iout_code : current output value (Addr 9Ah ~ 9Bh)
245 struct lp8788_led_platform_data {
247 enum lp8788_isink_scale scale;
248 enum lp8788_isink_number num;
253 * struct lp8788_vib_platform_data
254 * @name : vibrator driver name
255 * @scale : current scale
256 * @num : current sink number
257 * @iout_code : current output value (Addr 9Ah ~ 9Bh)
258 * @pwm_code : PWM code value (Addr 9Ch ~ 9Eh)
260 struct lp8788_vib_platform_data {
262 enum lp8788_isink_scale scale;
263 enum lp8788_isink_number num;
269 * struct lp8788_platform_data
270 * @init_func : used for initializing registers
271 * before mfd driver is registered
272 * @buck_data : regulator initial data for buck
273 * @dldo_data : regulator initial data for digital ldo
274 * @aldo_data : regulator initial data for analog ldo
275 * @buck1_dvs : gpio configurations for buck1 dvs
276 * @buck2_dvs : gpio configurations for buck2 dvs
277 * @chg_pdata : platform data for charger driver
278 * @alarm_sel : rtc alarm selection (1 or 2)
279 * @bl_pdata : configurable data for backlight driver
280 * @led_pdata : configurable data for led driver
281 * @vib_pdata : configurable data for vibrator driver
282 * @adc_pdata : iio map data for adc driver
284 struct lp8788_platform_data {
285 /* general system information */
286 int (*init_func) (struct lp8788 *lp);
289 struct regulator_init_data *buck_data[LP8788_NUM_BUCKS];
290 struct regulator_init_data *dldo_data[LP8788_NUM_DLDOS];
291 struct regulator_init_data *aldo_data[LP8788_NUM_ALDOS];
292 struct lp8788_buck1_dvs *buck1_dvs;
293 struct lp8788_buck2_dvs *buck2_dvs;
296 struct lp8788_charger_platform_data *chg_pdata;
299 enum lp8788_alarm_sel alarm_sel;
302 struct lp8788_backlight_platform_data *bl_pdata;
305 struct lp8788_led_platform_data *led_pdata;
306 struct lp8788_vib_platform_data *vib_pdata;
308 /* adc iio map data */
309 struct iio_map *adc_pdata;
314 * @dev : parent device pointer
315 * @regmap : used for i2c communcation on accessing registers
316 * @irqdm : interrupt domain for handling nested interrupt
317 * @irq : pin number of IRQ_N
318 * @pdata : lp8788 platform specific data
322 struct regmap *regmap;
323 struct irq_domain *irqdm;
325 struct lp8788_platform_data *pdata;
328 int lp8788_irq_init(struct lp8788 *lp, int chip_irq);
329 void lp8788_irq_exit(struct lp8788 *lp);
330 int lp8788_read_byte(struct lp8788 *lp, u8 reg, u8 *data);
331 int lp8788_read_multi_bytes(struct lp8788 *lp, u8 reg, u8 *data, size_t count);
332 int lp8788_write_byte(struct lp8788 *lp, u8 reg, u8 data);
333 int lp8788_update_bits(struct lp8788 *lp, u8 reg, u8 mask, u8 data);