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_ldo_enable_pin
187 * Basically, all LDOs are enabled through the I2C commands.
188 * But ALDO 1 ~ 5, 7, DLDO 7, 9, 11 can be enabled by external gpio pins.
190 * @gpio : gpio number which is used for enabling ldos
191 * @init_state : initial gpio state (ex. GPIOF_OUT_INIT_LOW)
193 struct lp8788_ldo_enable_pin
{
199 * struct lp8788_chg_param
200 * @addr : charging control register address (range : 0x11 ~ 0x1C)
201 * @val : charging parameter value
203 struct lp8788_chg_param
{
209 * struct lp8788_charger_platform_data
210 * @adc_vbatt : adc channel name for battery voltage
211 * @adc_batt_temp : adc channel name for battery temperature
212 * @max_vbatt_mv : used for calculating battery capacity
213 * @chg_params : initial charging parameters
214 * @num_chg_params : numbers of charging parameters
215 * @charger_event : the charger event can be reported to the platform side
217 struct lp8788_charger_platform_data
{
218 const char *adc_vbatt
;
219 const char *adc_batt_temp
;
220 unsigned int max_vbatt_mv
;
221 struct lp8788_chg_param
*chg_params
;
223 void (*charger_event
) (struct lp8788
*lp
,
224 enum lp8788_charger_event event
);
228 * struct lp8788_backlight_platform_data
229 * @name : backlight driver name. (default: "lcd-backlight")
230 * @initial_brightness : initial value of backlight brightness
231 * @bl_mode : brightness control by pwm or lp8788 register
232 * @dim_mode : dimming mode selection
233 * @full_scale : full scale current setting
234 * @rise_time : brightness ramp up step time
235 * @fall_time : brightness ramp down step time
236 * @pwm_pol : pwm polarity setting when bl_mode is pwm based
237 * @period_ns : platform specific pwm period value. unit is nano.
238 Only valid when bl_mode is LP8788_BL_COMB_PWM_BASED
240 struct lp8788_backlight_platform_data
{
242 int initial_brightness
;
243 enum lp8788_bl_ctrl_mode bl_mode
;
244 enum lp8788_bl_dim_mode dim_mode
;
245 enum lp8788_bl_full_scale_current full_scale
;
246 enum lp8788_bl_ramp_step rise_time
;
247 enum lp8788_bl_ramp_step fall_time
;
248 enum pwm_polarity pwm_pol
;
249 unsigned int period_ns
;
253 * struct lp8788_led_platform_data
254 * @name : led driver name. (default: "keyboard-backlight")
255 * @scale : current scale
256 * @num : current sink number
257 * @iout_code : current output value (Addr 9Ah ~ 9Bh)
259 struct lp8788_led_platform_data
{
261 enum lp8788_isink_scale scale
;
262 enum lp8788_isink_number num
;
267 * struct lp8788_vib_platform_data
268 * @name : vibrator driver name
269 * @scale : current scale
270 * @num : current sink number
271 * @iout_code : current output value (Addr 9Ah ~ 9Bh)
272 * @pwm_code : PWM code value (Addr 9Ch ~ 9Eh)
274 struct lp8788_vib_platform_data
{
276 enum lp8788_isink_scale scale
;
277 enum lp8788_isink_number num
;
283 * struct lp8788_platform_data
284 * @init_func : used for initializing registers
285 * before mfd driver is registered
286 * @buck_data : regulator initial data for buck
287 * @dldo_data : regulator initial data for digital ldo
288 * @aldo_data : regulator initial data for analog ldo
289 * @buck1_dvs : gpio configurations for buck1 dvs
290 * @buck2_dvs : gpio configurations for buck2 dvs
291 * @ldo_pin : gpio configurations for enabling LDOs
292 * @chg_pdata : platform data for charger driver
293 * @alarm_sel : rtc alarm selection (1 or 2)
294 * @bl_pdata : configurable data for backlight driver
295 * @led_pdata : configurable data for led driver
296 * @vib_pdata : configurable data for vibrator driver
297 * @adc_pdata : iio map data for adc driver
299 struct lp8788_platform_data
{
300 /* general system information */
301 int (*init_func
) (struct lp8788
*lp
);
304 struct regulator_init_data
*buck_data
[LP8788_NUM_BUCKS
];
305 struct regulator_init_data
*dldo_data
[LP8788_NUM_DLDOS
];
306 struct regulator_init_data
*aldo_data
[LP8788_NUM_ALDOS
];
307 struct lp8788_buck1_dvs
*buck1_dvs
;
308 struct lp8788_buck2_dvs
*buck2_dvs
;
309 struct lp8788_ldo_enable_pin
*ldo_pin
[EN_LDOS_MAX
];
312 struct lp8788_charger_platform_data
*chg_pdata
;
315 enum lp8788_alarm_sel alarm_sel
;
318 struct lp8788_backlight_platform_data
*bl_pdata
;
321 struct lp8788_led_platform_data
*led_pdata
;
322 struct lp8788_vib_platform_data
*vib_pdata
;
324 /* adc iio map data */
325 struct iio_map
*adc_pdata
;
330 * @dev : parent device pointer
331 * @regmap : used for i2c communcation on accessing registers
332 * @irqdm : interrupt domain for handling nested interrupt
333 * @irq : pin number of IRQ_N
334 * @pdata : lp8788 platform specific data
338 struct regmap
*regmap
;
339 struct irq_domain
*irqdm
;
341 struct lp8788_platform_data
*pdata
;
344 int lp8788_irq_init(struct lp8788
*lp
, int chip_irq
);
345 void lp8788_irq_exit(struct lp8788
*lp
);
346 int lp8788_read_byte(struct lp8788
*lp
, u8 reg
, u8
*data
);
347 int lp8788_read_multi_bytes(struct lp8788
*lp
, u8 reg
, u8
*data
, size_t count
);
348 int lp8788_write_byte(struct lp8788
*lp
, u8 reg
, u8 data
);
349 int lp8788_update_bits(struct lp8788
*lp
, u8 reg
, u8 mask
, u8 data
);