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/irqdomain.h> |
14 | #include <linux/pwm.h> |
15 | #include <linux/regmap.h> |
16 | |
17 | #define LP8788_DEV_BUCK "lp8788-buck" |
18 | #define LP8788_DEV_DLDO "lp8788-dldo" |
19 | #define LP8788_DEV_ALDO "lp8788-aldo" |
20 | #define LP8788_DEV_CHARGER "lp8788-charger" |
21 | #define LP8788_DEV_RTC "lp8788-rtc" |
22 | #define LP8788_DEV_BACKLIGHT "lp8788-backlight" |
23 | #define LP8788_DEV_VIBRATOR "lp8788-vibrator" |
24 | #define LP8788_DEV_KEYLED "lp8788-keyled" |
25 | #define LP8788_DEV_ADC "lp8788-adc" |
26 | |
27 | #define LP8788_NUM_BUCKS 4 |
28 | #define LP8788_NUM_DLDOS 12 |
29 | #define LP8788_NUM_ALDOS 10 |
30 | #define LP8788_NUM_BUCK2_DVS 2 |
31 | |
32 | #define LP8788_CHG_IRQ "CHG_IRQ" |
33 | #define LP8788_PRSW_IRQ "PRSW_IRQ" |
34 | #define LP8788_BATT_IRQ "BATT_IRQ" |
35 | #define LP8788_ALM_IRQ "ALARM_IRQ" |
36 | |
37 | enum lp8788_int_id { |
38 | /* interrup register 1 : Addr 00h */ |
39 | LP8788_INT_TSDL, |
40 | LP8788_INT_TSDH, |
41 | LP8788_INT_UVLO, |
42 | LP8788_INT_FLAGMON, |
43 | LP8788_INT_PWRON_TIME, |
44 | LP8788_INT_PWRON, |
45 | LP8788_INT_COMP1, |
46 | LP8788_INT_COMP2, |
47 | |
48 | /* interrupt register 2 : Addr 01h */ |
49 | LP8788_INT_CHG_INPUT_STATE, |
50 | LP8788_INT_CHG_STATE, |
51 | LP8788_INT_EOC, |
52 | LP8788_INT_CHG_RESTART, |
53 | LP8788_INT_RESTART_TIMEOUT, |
54 | LP8788_INT_FULLCHG_TIMEOUT, |
55 | LP8788_INT_PRECHG_TIMEOUT, |
56 | |
57 | /* interrupt register 3 : Addr 02h */ |
58 | LP8788_INT_RTC_ALARM1 = 17, |
59 | LP8788_INT_RTC_ALARM2, |
60 | LP8788_INT_ENTER_SYS_SUPPORT, |
61 | LP8788_INT_EXIT_SYS_SUPPORT, |
62 | LP8788_INT_BATT_LOW, |
63 | LP8788_INT_NO_BATT, |
64 | |
65 | LP8788_INT_MAX = 24, |
66 | }; |
67 | |
68 | enum lp8788_dvs_sel { |
69 | DVS_SEL_V0, |
70 | DVS_SEL_V1, |
71 | DVS_SEL_V2, |
72 | DVS_SEL_V3, |
73 | }; |
74 | |
75 | enum lp8788_ext_ldo_en_id { |
76 | EN_ALDO1, |
77 | EN_ALDO234, |
78 | EN_ALDO5, |
79 | EN_ALDO7, |
80 | EN_DLDO7, |
81 | EN_DLDO911, |
82 | EN_LDOS_MAX, |
83 | }; |
84 | |
85 | enum lp8788_charger_event { |
86 | NO_CHARGER, |
87 | CHARGER_DETECTED, |
88 | }; |
89 | |
90 | enum lp8788_bl_ctrl_mode { |
91 | LP8788_BL_REGISTER_ONLY, |
92 | LP8788_BL_COMB_PWM_BASED, /* PWM + I2C, changed by PWM input */ |
93 | LP8788_BL_COMB_REGISTER_BASED, /* PWM + I2C, changed by I2C */ |
94 | }; |
95 | |
96 | enum lp8788_bl_dim_mode { |
97 | LP8788_DIM_EXPONENTIAL, |
98 | LP8788_DIM_LINEAR, |
99 | }; |
100 | |
101 | enum lp8788_bl_full_scale_current { |
102 | LP8788_FULLSCALE_5000uA, |
103 | LP8788_FULLSCALE_8500uA, |
104 | LP8788_FULLSCALE_1200uA, |
105 | LP8788_FULLSCALE_1550uA, |
106 | LP8788_FULLSCALE_1900uA, |
107 | LP8788_FULLSCALE_2250uA, |
108 | LP8788_FULLSCALE_2600uA, |
109 | LP8788_FULLSCALE_2950uA, |
110 | }; |
111 | |
112 | enum lp8788_bl_ramp_step { |
113 | LP8788_RAMP_8us, |
114 | LP8788_RAMP_1024us, |
115 | LP8788_RAMP_2048us, |
116 | LP8788_RAMP_4096us, |
117 | LP8788_RAMP_8192us, |
118 | LP8788_RAMP_16384us, |
119 | LP8788_RAMP_32768us, |
120 | LP8788_RAMP_65538us, |
121 | }; |
122 | |
123 | enum lp8788_isink_scale { |
124 | LP8788_ISINK_SCALE_100mA, |
125 | LP8788_ISINK_SCALE_120mA, |
126 | }; |
127 | |
128 | enum lp8788_isink_number { |
129 | LP8788_ISINK_1, |
130 | LP8788_ISINK_2, |
131 | LP8788_ISINK_3, |
132 | }; |
133 | |
134 | enum lp8788_alarm_sel { |
135 | LP8788_ALARM_1, |
136 | LP8788_ALARM_2, |
137 | LP8788_ALARM_MAX, |
138 | }; |
139 | |
140 | enum lp8788_adc_id { |
141 | LPADC_VBATT_5P5, |
142 | LPADC_VIN_CHG, |
143 | LPADC_IBATT, |
144 | LPADC_IC_TEMP, |
145 | LPADC_VBATT_6P0, |
146 | LPADC_VBATT_5P0, |
147 | LPADC_ADC1, |
148 | LPADC_ADC2, |
149 | LPADC_VDD, |
150 | LPADC_VCOIN, |
151 | LPADC_VDD_LDO, |
152 | LPADC_ADC3, |
153 | LPADC_ADC4, |
154 | LPADC_MAX, |
155 | }; |
156 | |
157 | struct lp8788; |
158 | |
159 | /* |
160 | * lp8788_buck1_dvs |
161 | * @vsel : dvs selector for buck v1 register |
162 | */ |
163 | struct lp8788_buck1_dvs { |
164 | enum lp8788_dvs_sel vsel; |
165 | }; |
166 | |
167 | /* |
168 | * lp8788_buck2_dvs |
169 | * @vsel : dvs selector for buck v2 register |
170 | */ |
171 | struct lp8788_buck2_dvs { |
172 | enum lp8788_dvs_sel vsel; |
173 | }; |
174 | |
175 | /* |
176 | * struct lp8788_chg_param |
177 | * @addr : charging control register address (range : 0x11 ~ 0x1C) |
178 | * @val : charging parameter value |
179 | */ |
180 | struct lp8788_chg_param { |
181 | u8 addr; |
182 | u8 val; |
183 | }; |
184 | |
185 | /* |
186 | * struct lp8788_charger_platform_data |
187 | * @adc_vbatt : adc channel name for battery voltage |
188 | * @adc_batt_temp : adc channel name for battery temperature |
189 | * @max_vbatt_mv : used for calculating battery capacity |
190 | * @chg_params : initial charging parameters |
191 | * @num_chg_params : numbers of charging parameters |
192 | * @charger_event : the charger event can be reported to the platform side |
193 | */ |
194 | struct lp8788_charger_platform_data { |
195 | const char *adc_vbatt; |
196 | const char *adc_batt_temp; |
197 | unsigned int max_vbatt_mv; |
198 | struct lp8788_chg_param *chg_params; |
199 | int num_chg_params; |
200 | void (*charger_event) (struct lp8788 *lp, |
201 | enum lp8788_charger_event event); |
202 | }; |
203 | |
204 | /* |
205 | * struct lp8788_backlight_platform_data |
206 | * @name : backlight driver name. (default: "lcd-backlight") |
207 | * @initial_brightness : initial value of backlight brightness |
208 | * @bl_mode : brightness control by pwm or lp8788 register |
209 | * @dim_mode : dimming mode selection |
210 | * @full_scale : full scale current setting |
211 | * @rise_time : brightness ramp up step time |
212 | * @fall_time : brightness ramp down step time |
213 | * @pwm_pol : pwm polarity setting when bl_mode is pwm based |
214 | * @period_ns : platform specific pwm period value. unit is nano. |
215 | Only valid when bl_mode is LP8788_BL_COMB_PWM_BASED |
216 | */ |
217 | struct lp8788_backlight_platform_data { |
218 | char *name; |
219 | int initial_brightness; |
220 | enum lp8788_bl_ctrl_mode bl_mode; |
221 | enum lp8788_bl_dim_mode dim_mode; |
222 | enum lp8788_bl_full_scale_current full_scale; |
223 | enum lp8788_bl_ramp_step rise_time; |
224 | enum lp8788_bl_ramp_step fall_time; |
225 | enum pwm_polarity pwm_pol; |
226 | unsigned int period_ns; |
227 | }; |
228 | |
229 | /* |
230 | * struct lp8788_led_platform_data |
231 | * @name : led driver name. (default: "keyboard-backlight") |
232 | * @scale : current scale |
233 | * @num : current sink number |
234 | * @iout_code : current output value (Addr 9Ah ~ 9Bh) |
235 | */ |
236 | struct lp8788_led_platform_data { |
237 | char *name; |
238 | enum lp8788_isink_scale scale; |
239 | enum lp8788_isink_number num; |
240 | int iout_code; |
241 | }; |
242 | |
243 | /* |
244 | * struct lp8788_vib_platform_data |
245 | * @name : vibrator driver name |
246 | * @scale : current scale |
247 | * @num : current sink number |
248 | * @iout_code : current output value (Addr 9Ah ~ 9Bh) |
249 | * @pwm_code : PWM code value (Addr 9Ch ~ 9Eh) |
250 | */ |
251 | struct lp8788_vib_platform_data { |
252 | char *name; |
253 | enum lp8788_isink_scale scale; |
254 | enum lp8788_isink_number num; |
255 | int iout_code; |
256 | int pwm_code; |
257 | }; |
258 | |
259 | /* |
260 | * struct lp8788_platform_data |
261 | * @init_func : used for initializing registers |
262 | * before mfd driver is registered |
263 | * @buck_data : regulator initial data for buck |
264 | * @dldo_data : regulator initial data for digital ldo |
265 | * @aldo_data : regulator initial data for analog ldo |
266 | * @buck1_dvs : configurations for buck1 dvs |
267 | * @buck2_dvs : configurations for buck2 dvs |
268 | * @chg_pdata : platform data for charger driver |
269 | * @alarm_sel : rtc alarm selection (1 or 2) |
270 | * @bl_pdata : configurable data for backlight driver |
271 | * @led_pdata : configurable data for led driver |
272 | * @vib_pdata : configurable data for vibrator driver |
273 | * @adc_pdata : iio map data for adc driver |
274 | */ |
275 | struct lp8788_platform_data { |
276 | /* general system information */ |
277 | int (*init_func) (struct lp8788 *lp); |
278 | |
279 | /* regulators */ |
280 | struct regulator_init_data *buck_data[LP8788_NUM_BUCKS]; |
281 | struct regulator_init_data *dldo_data[LP8788_NUM_DLDOS]; |
282 | struct regulator_init_data *aldo_data[LP8788_NUM_ALDOS]; |
283 | struct lp8788_buck1_dvs *buck1_dvs; |
284 | struct lp8788_buck2_dvs *buck2_dvs; |
285 | |
286 | /* charger */ |
287 | struct lp8788_charger_platform_data *chg_pdata; |
288 | |
289 | /* rtc alarm */ |
290 | enum lp8788_alarm_sel alarm_sel; |
291 | |
292 | /* backlight */ |
293 | struct lp8788_backlight_platform_data *bl_pdata; |
294 | |
295 | /* current sinks */ |
296 | struct lp8788_led_platform_data *led_pdata; |
297 | struct lp8788_vib_platform_data *vib_pdata; |
298 | |
299 | /* adc iio map data */ |
300 | struct iio_map *adc_pdata; |
301 | }; |
302 | |
303 | /* |
304 | * struct lp8788 |
305 | * @dev : parent device pointer |
306 | * @regmap : used for i2c communcation on accessing registers |
307 | * @irqdm : interrupt domain for handling nested interrupt |
308 | * @irq : pin number of IRQ_N |
309 | * @pdata : lp8788 platform specific data |
310 | */ |
311 | struct lp8788 { |
312 | struct device *dev; |
313 | struct regmap *regmap; |
314 | struct irq_domain *irqdm; |
315 | int irq; |
316 | struct lp8788_platform_data *pdata; |
317 | }; |
318 | |
319 | int lp8788_irq_init(struct lp8788 *lp, int chip_irq); |
320 | void lp8788_irq_exit(struct lp8788 *lp); |
321 | int lp8788_read_byte(struct lp8788 *lp, u8 reg, u8 *data); |
322 | int lp8788_read_multi_bytes(struct lp8788 *lp, u8 reg, u8 *data, size_t count); |
323 | int lp8788_write_byte(struct lp8788 *lp, u8 reg, u8 data); |
324 | int lp8788_update_bits(struct lp8788 *lp, u8 reg, u8 mask, u8 data); |
325 | #endif |
326 | |