1 /* SPDX-License-Identifier: GPL-2.0-only */
5 * Copyright 2012 Texas Instruments
7 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
10 #ifndef __MFD_LP8788_H__
11 #define __MFD_LP8788_H__
13 #include <linux/gpio.h>
14 #include <linux/irqdomain.h>
15 #include <linux/pwm.h>
16 #include <linux/regmap.h>
18 #define LP8788_DEV_BUCK "lp8788-buck"
19 #define LP8788_DEV_DLDO "lp8788-dldo"
20 #define LP8788_DEV_ALDO "lp8788-aldo"
21 #define LP8788_DEV_CHARGER "lp8788-charger"
22 #define LP8788_DEV_RTC "lp8788-rtc"
23 #define LP8788_DEV_BACKLIGHT "lp8788-backlight"
24 #define LP8788_DEV_VIBRATOR "lp8788-vibrator"
25 #define LP8788_DEV_KEYLED "lp8788-keyled"
26 #define LP8788_DEV_ADC "lp8788-adc"
28 #define LP8788_NUM_BUCKS 4
29 #define LP8788_NUM_DLDOS 12
30 #define LP8788_NUM_ALDOS 10
31 #define LP8788_NUM_BUCK2_DVS 2
33 #define LP8788_CHG_IRQ "CHG_IRQ"
34 #define LP8788_PRSW_IRQ "PRSW_IRQ"
35 #define LP8788_BATT_IRQ "BATT_IRQ"
36 #define LP8788_ALM_IRQ "ALARM_IRQ"
39 /* interrup register 1 : Addr 00h */
44 LP8788_INT_PWRON_TIME,
49 /* interrupt register 2 : Addr 01h */
50 LP8788_INT_CHG_INPUT_STATE,
53 LP8788_INT_CHG_RESTART,
54 LP8788_INT_RESTART_TIMEOUT,
55 LP8788_INT_FULLCHG_TIMEOUT,
56 LP8788_INT_PRECHG_TIMEOUT,
58 /* interrupt register 3 : Addr 02h */
59 LP8788_INT_RTC_ALARM1 = 17,
60 LP8788_INT_RTC_ALARM2,
61 LP8788_INT_ENTER_SYS_SUPPORT,
62 LP8788_INT_EXIT_SYS_SUPPORT,
76 enum lp8788_ext_ldo_en_id {
86 enum lp8788_charger_event {
91 enum lp8788_bl_ctrl_mode {
92 LP8788_BL_REGISTER_ONLY,
93 LP8788_BL_COMB_PWM_BASED, /* PWM + I2C, changed by PWM input */
94 LP8788_BL_COMB_REGISTER_BASED, /* PWM + I2C, changed by I2C */
97 enum lp8788_bl_dim_mode {
98 LP8788_DIM_EXPONENTIAL,
102 enum lp8788_bl_full_scale_current {
103 LP8788_FULLSCALE_5000uA,
104 LP8788_FULLSCALE_8500uA,
105 LP8788_FULLSCALE_1200uA,
106 LP8788_FULLSCALE_1550uA,
107 LP8788_FULLSCALE_1900uA,
108 LP8788_FULLSCALE_2250uA,
109 LP8788_FULLSCALE_2600uA,
110 LP8788_FULLSCALE_2950uA,
113 enum lp8788_bl_ramp_step {
124 enum lp8788_isink_scale {
125 LP8788_ISINK_SCALE_100mA,
126 LP8788_ISINK_SCALE_120mA,
129 enum lp8788_isink_number {
135 enum lp8788_alarm_sel {
162 * @gpio : gpio pin number for dvs control
163 * @vsel : dvs selector for buck v1 register
165 struct lp8788_buck1_dvs {
167 enum lp8788_dvs_sel vsel;
172 * @gpio : two gpio pin numbers are used for dvs
173 * @vsel : dvs selector for buck v2 register
175 struct lp8788_buck2_dvs {
176 int gpio[LP8788_NUM_BUCK2_DVS];
177 enum lp8788_dvs_sel vsel;
181 * struct lp8788_chg_param
182 * @addr : charging control register address (range : 0x11 ~ 0x1C)
183 * @val : charging parameter value
185 struct lp8788_chg_param {
191 * struct lp8788_charger_platform_data
192 * @adc_vbatt : adc channel name for battery voltage
193 * @adc_batt_temp : adc channel name for battery temperature
194 * @max_vbatt_mv : used for calculating battery capacity
195 * @chg_params : initial charging parameters
196 * @num_chg_params : numbers of charging parameters
197 * @charger_event : the charger event can be reported to the platform side
199 struct lp8788_charger_platform_data {
200 const char *adc_vbatt;
201 const char *adc_batt_temp;
202 unsigned int max_vbatt_mv;
203 struct lp8788_chg_param *chg_params;
205 void (*charger_event) (struct lp8788 *lp,
206 enum lp8788_charger_event event);
210 * struct lp8788_backlight_platform_data
211 * @name : backlight driver name. (default: "lcd-backlight")
212 * @initial_brightness : initial value of backlight brightness
213 * @bl_mode : brightness control by pwm or lp8788 register
214 * @dim_mode : dimming mode selection
215 * @full_scale : full scale current setting
216 * @rise_time : brightness ramp up step time
217 * @fall_time : brightness ramp down step time
218 * @pwm_pol : pwm polarity setting when bl_mode is pwm based
219 * @period_ns : platform specific pwm period value. unit is nano.
220 Only valid when bl_mode is LP8788_BL_COMB_PWM_BASED
222 struct lp8788_backlight_platform_data {
224 int initial_brightness;
225 enum lp8788_bl_ctrl_mode bl_mode;
226 enum lp8788_bl_dim_mode dim_mode;
227 enum lp8788_bl_full_scale_current full_scale;
228 enum lp8788_bl_ramp_step rise_time;
229 enum lp8788_bl_ramp_step fall_time;
230 enum pwm_polarity pwm_pol;
231 unsigned int period_ns;
235 * struct lp8788_led_platform_data
236 * @name : led driver name. (default: "keyboard-backlight")
237 * @scale : current scale
238 * @num : current sink number
239 * @iout_code : current output value (Addr 9Ah ~ 9Bh)
241 struct lp8788_led_platform_data {
243 enum lp8788_isink_scale scale;
244 enum lp8788_isink_number num;
249 * struct lp8788_vib_platform_data
250 * @name : vibrator driver name
251 * @scale : current scale
252 * @num : current sink number
253 * @iout_code : current output value (Addr 9Ah ~ 9Bh)
254 * @pwm_code : PWM code value (Addr 9Ch ~ 9Eh)
256 struct lp8788_vib_platform_data {
258 enum lp8788_isink_scale scale;
259 enum lp8788_isink_number num;
265 * struct lp8788_platform_data
266 * @init_func : used for initializing registers
267 * before mfd driver is registered
268 * @buck_data : regulator initial data for buck
269 * @dldo_data : regulator initial data for digital ldo
270 * @aldo_data : regulator initial data for analog ldo
271 * @buck1_dvs : gpio configurations for buck1 dvs
272 * @buck2_dvs : gpio configurations for buck2 dvs
273 * @chg_pdata : platform data for charger driver
274 * @alarm_sel : rtc alarm selection (1 or 2)
275 * @bl_pdata : configurable data for backlight driver
276 * @led_pdata : configurable data for led driver
277 * @vib_pdata : configurable data for vibrator driver
278 * @adc_pdata : iio map data for adc driver
280 struct lp8788_platform_data {
281 /* general system information */
282 int (*init_func) (struct lp8788 *lp);
285 struct regulator_init_data *buck_data[LP8788_NUM_BUCKS];
286 struct regulator_init_data *dldo_data[LP8788_NUM_DLDOS];
287 struct regulator_init_data *aldo_data[LP8788_NUM_ALDOS];
288 struct lp8788_buck1_dvs *buck1_dvs;
289 struct lp8788_buck2_dvs *buck2_dvs;
292 struct lp8788_charger_platform_data *chg_pdata;
295 enum lp8788_alarm_sel alarm_sel;
298 struct lp8788_backlight_platform_data *bl_pdata;
301 struct lp8788_led_platform_data *led_pdata;
302 struct lp8788_vib_platform_data *vib_pdata;
304 /* adc iio map data */
305 struct iio_map *adc_pdata;
310 * @dev : parent device pointer
311 * @regmap : used for i2c communcation on accessing registers
312 * @irqdm : interrupt domain for handling nested interrupt
313 * @irq : pin number of IRQ_N
314 * @pdata : lp8788 platform specific data
318 struct regmap *regmap;
319 struct irq_domain *irqdm;
321 struct lp8788_platform_data *pdata;
324 int lp8788_irq_init(struct lp8788 *lp, int chip_irq);
325 void lp8788_irq_exit(struct lp8788 *lp);
326 int lp8788_read_byte(struct lp8788 *lp, u8 reg, u8 *data);
327 int lp8788_read_multi_bytes(struct lp8788 *lp, u8 reg, u8 *data, size_t count);
328 int lp8788_write_byte(struct lp8788 *lp, u8 reg, u8 data);
329 int lp8788_update_bits(struct lp8788 *lp, u8 reg, u8 mask, u8 data);