1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
2 | /* |
3 | * TI LP8788 MFD Device |
4 | * |
5 | * Copyright 2012 Texas Instruments |
6 | * |
7 | * Author: Milo(Woogyom) Kim <milo.kim@ti.com> |
8 | */ |
9 | |
10 | #ifndef __MFD_LP8788_H__ |
11 | #define __MFD_LP8788_H__ |
12 | |
13 | #include <linux/gpio.h> |
14 | #include <linux/irqdomain.h> |
15 | #include <linux/pwm.h> |
16 | #include <linux/regmap.h> |
17 | |
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" |
27 | |
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 |
32 | |
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" |
37 | |
38 | enum lp8788_int_id { |
39 | /* interrup register 1 : Addr 00h */ |
40 | LP8788_INT_TSDL, |
41 | LP8788_INT_TSDH, |
42 | LP8788_INT_UVLO, |
43 | LP8788_INT_FLAGMON, |
44 | LP8788_INT_PWRON_TIME, |
45 | LP8788_INT_PWRON, |
46 | LP8788_INT_COMP1, |
47 | LP8788_INT_COMP2, |
48 | |
49 | /* interrupt register 2 : Addr 01h */ |
50 | LP8788_INT_CHG_INPUT_STATE, |
51 | LP8788_INT_CHG_STATE, |
52 | LP8788_INT_EOC, |
53 | LP8788_INT_CHG_RESTART, |
54 | LP8788_INT_RESTART_TIMEOUT, |
55 | LP8788_INT_FULLCHG_TIMEOUT, |
56 | LP8788_INT_PRECHG_TIMEOUT, |
57 | |
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, |
63 | LP8788_INT_BATT_LOW, |
64 | LP8788_INT_NO_BATT, |
65 | |
66 | LP8788_INT_MAX = 24, |
67 | }; |
68 | |
69 | enum lp8788_dvs_sel { |
70 | DVS_SEL_V0, |
71 | DVS_SEL_V1, |
72 | DVS_SEL_V2, |
73 | DVS_SEL_V3, |
74 | }; |
75 | |
76 | enum lp8788_ext_ldo_en_id { |
77 | EN_ALDO1, |
78 | EN_ALDO234, |
79 | EN_ALDO5, |
80 | EN_ALDO7, |
81 | EN_DLDO7, |
82 | EN_DLDO911, |
83 | EN_LDOS_MAX, |
84 | }; |
85 | |
86 | enum lp8788_charger_event { |
87 | NO_CHARGER, |
88 | CHARGER_DETECTED, |
89 | }; |
90 | |
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 */ |
95 | }; |
96 | |
97 | enum lp8788_bl_dim_mode { |
98 | LP8788_DIM_EXPONENTIAL, |
99 | LP8788_DIM_LINEAR, |
100 | }; |
101 | |
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, |
111 | }; |
112 | |
113 | enum lp8788_bl_ramp_step { |
114 | LP8788_RAMP_8us, |
115 | LP8788_RAMP_1024us, |
116 | LP8788_RAMP_2048us, |
117 | LP8788_RAMP_4096us, |
118 | LP8788_RAMP_8192us, |
119 | LP8788_RAMP_16384us, |
120 | LP8788_RAMP_32768us, |
121 | LP8788_RAMP_65538us, |
122 | }; |
123 | |
124 | enum lp8788_isink_scale { |
125 | LP8788_ISINK_SCALE_100mA, |
126 | LP8788_ISINK_SCALE_120mA, |
127 | }; |
128 | |
129 | enum lp8788_isink_number { |
130 | LP8788_ISINK_1, |
131 | LP8788_ISINK_2, |
132 | LP8788_ISINK_3, |
133 | }; |
134 | |
135 | enum lp8788_alarm_sel { |
136 | LP8788_ALARM_1, |
137 | LP8788_ALARM_2, |
138 | LP8788_ALARM_MAX, |
139 | }; |
140 | |
141 | enum lp8788_adc_id { |
142 | LPADC_VBATT_5P5, |
143 | LPADC_VIN_CHG, |
144 | LPADC_IBATT, |
145 | LPADC_IC_TEMP, |
146 | LPADC_VBATT_6P0, |
147 | LPADC_VBATT_5P0, |
148 | LPADC_ADC1, |
149 | LPADC_ADC2, |
150 | LPADC_VDD, |
151 | LPADC_VCOIN, |
152 | LPADC_VDD_LDO, |
153 | LPADC_ADC3, |
154 | LPADC_ADC4, |
155 | LPADC_MAX, |
156 | }; |
157 | |
158 | struct lp8788; |
159 | |
160 | /* |
161 | * lp8788_buck1_dvs |
162 | * @gpio : gpio pin number for dvs control |
163 | * @vsel : dvs selector for buck v1 register |
164 | */ |
165 | struct lp8788_buck1_dvs { |
166 | int gpio; |
167 | enum lp8788_dvs_sel vsel; |
168 | }; |
169 | |
170 | /* |
171 | * lp8788_buck2_dvs |
172 | * @gpio : two gpio pin numbers are used for dvs |
173 | * @vsel : dvs selector for buck v2 register |
174 | */ |
175 | struct lp8788_buck2_dvs { |
176 | int gpio[LP8788_NUM_BUCK2_DVS]; |
177 | enum lp8788_dvs_sel vsel; |
178 | }; |
179 | |
180 | /* |
181 | * struct lp8788_chg_param |
182 | * @addr : charging control register address (range : 0x11 ~ 0x1C) |
183 | * @val : charging parameter value |
184 | */ |
185 | struct lp8788_chg_param { |
186 | u8 addr; |
187 | u8 val; |
188 | }; |
189 | |
190 | /* |
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 |
198 | */ |
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; |
204 | int num_chg_params; |
205 | void (*charger_event) (struct lp8788 *lp, |
206 | enum lp8788_charger_event event); |
207 | }; |
208 | |
209 | /* |
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 |
221 | */ |
222 | struct lp8788_backlight_platform_data { |
223 | char *name; |
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; |
232 | }; |
233 | |
234 | /* |
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) |
240 | */ |
241 | struct lp8788_led_platform_data { |
242 | char *name; |
243 | enum lp8788_isink_scale scale; |
244 | enum lp8788_isink_number num; |
245 | int iout_code; |
246 | }; |
247 | |
248 | /* |
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) |
255 | */ |
256 | struct lp8788_vib_platform_data { |
257 | char *name; |
258 | enum lp8788_isink_scale scale; |
259 | enum lp8788_isink_number num; |
260 | int iout_code; |
261 | int pwm_code; |
262 | }; |
263 | |
264 | /* |
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 |
279 | */ |
280 | struct lp8788_platform_data { |
281 | /* general system information */ |
282 | int (*init_func) (struct lp8788 *lp); |
283 | |
284 | /* regulators */ |
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; |
290 | |
291 | /* charger */ |
292 | struct lp8788_charger_platform_data *chg_pdata; |
293 | |
294 | /* rtc alarm */ |
295 | enum lp8788_alarm_sel alarm_sel; |
296 | |
297 | /* backlight */ |
298 | struct lp8788_backlight_platform_data *bl_pdata; |
299 | |
300 | /* current sinks */ |
301 | struct lp8788_led_platform_data *led_pdata; |
302 | struct lp8788_vib_platform_data *vib_pdata; |
303 | |
304 | /* adc iio map data */ |
305 | struct iio_map *adc_pdata; |
306 | }; |
307 | |
308 | /* |
309 | * struct lp8788 |
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 |
315 | */ |
316 | struct lp8788 { |
317 | struct device *dev; |
318 | struct regmap *regmap; |
319 | struct irq_domain *irqdm; |
320 | int irq; |
321 | struct lp8788_platform_data *pdata; |
322 | }; |
323 | |
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); |
330 | #endif |
331 | |