1 // SPDX-License-Identifier: GPL-2.0
2 // BQ256XX Battery Charger Driver
3 // Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
7 #include <linux/init.h>
8 #include <linux/interrupt.h>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/gpio/consumer.h>
12 #include <linux/power_supply.h>
13 #include <linux/regmap.h>
14 #include <linux/types.h>
15 #include <linux/usb/phy.h>
16 #include <linux/device.h>
17 #include <linux/moduleparam.h>
18 #include <linux/slab.h>
19 #include <linux/acpi.h>
21 #define BQ256XX_MANUFACTURER "Texas Instruments"
23 #define BQ256XX_INPUT_CURRENT_LIMIT 0x00
24 #define BQ256XX_CHARGER_CONTROL_0 0x01
25 #define BQ256XX_CHARGE_CURRENT_LIMIT 0x02
26 #define BQ256XX_PRECHG_AND_TERM_CURR_LIM 0x03
27 #define BQ256XX_BATTERY_VOLTAGE_LIMIT 0x04
28 #define BQ256XX_CHARGER_CONTROL_1 0x05
29 #define BQ256XX_CHARGER_CONTROL_2 0x06
30 #define BQ256XX_CHARGER_CONTROL_3 0x07
31 #define BQ256XX_CHARGER_STATUS_0 0x08
32 #define BQ256XX_CHARGER_STATUS_1 0x09
33 #define BQ256XX_CHARGER_STATUS_2 0x0a
34 #define BQ256XX_PART_INFORMATION 0x0b
35 #define BQ256XX_CHARGER_CONTROL_4 0x0c
37 #define BQ256XX_IINDPM_MASK GENMASK(4, 0)
38 #define BQ256XX_IINDPM_STEP_uA 100000
39 #define BQ256XX_IINDPM_OFFSET_uA 100000
40 #define BQ256XX_IINDPM_MIN_uA 100000
41 #define BQ256XX_IINDPM_MAX_uA 3200000
42 #define BQ256XX_IINDPM_DEF_uA 2400000
44 #define BQ256XX_TS_IGNORE BIT(6)
45 #define BQ256XX_TS_IGNORE_SHIFT 6
47 #define BQ256XX_VINDPM_MASK GENMASK(3, 0)
48 #define BQ256XX_VINDPM_STEP_uV 100000
49 #define BQ256XX_VINDPM_OFFSET_uV 3900000
50 #define BQ256XX_VINDPM_MIN_uV 3900000
51 #define BQ256XX_VINDPM_MAX_uV 5400000
52 #define BQ256XX_VINDPM_DEF_uV 4500000
54 #define BQ256XX_VBATREG_MASK GENMASK(7, 3)
55 #define BQ2560X_VBATREG_STEP_uV 32000
56 #define BQ2560X_VBATREG_OFFSET_uV 3856000
57 #define BQ2560X_VBATREG_MIN_uV 3856000
58 #define BQ2560X_VBATREG_MAX_uV 4624000
59 #define BQ2560X_VBATREG_DEF_uV 4208000
60 #define BQ25601D_VBATREG_OFFSET_uV 3847000
61 #define BQ25601D_VBATREG_MIN_uV 3847000
62 #define BQ25601D_VBATREG_MAX_uV 4615000
63 #define BQ25601D_VBATREG_DEF_uV 4199000
64 #define BQ2561X_VBATREG_STEP_uV 10000
65 #define BQ25611D_VBATREG_MIN_uV 3494000
66 #define BQ25611D_VBATREG_MAX_uV 4510000
67 #define BQ25611D_VBATREG_DEF_uV 4190000
68 #define BQ25618_VBATREG_MIN_uV 3504000
69 #define BQ25618_VBATREG_MAX_uV 4500000
70 #define BQ25618_VBATREG_DEF_uV 4200000
71 #define BQ256XX_VBATREG_BIT_SHIFT 3
72 #define BQ2561X_VBATREG_THRESH 0x8
73 #define BQ25611D_VBATREG_THRESH_uV 4290000
74 #define BQ25618_VBATREG_THRESH_uV 4300000
76 #define BQ256XX_CHG_CONFIG_MASK BIT(4)
77 #define BQ256XX_CHG_CONFIG_BIT_SHIFT 4
79 #define BQ256XX_ITERM_MASK GENMASK(3, 0)
80 #define BQ256XX_ITERM_STEP_uA 60000
81 #define BQ256XX_ITERM_OFFSET_uA 60000
82 #define BQ256XX_ITERM_MIN_uA 60000
83 #define BQ256XX_ITERM_MAX_uA 780000
84 #define BQ256XX_ITERM_DEF_uA 180000
85 #define BQ25618_ITERM_STEP_uA 20000
86 #define BQ25618_ITERM_OFFSET_uA 20000
87 #define BQ25618_ITERM_MIN_uA 20000
88 #define BQ25618_ITERM_MAX_uA 260000
89 #define BQ25618_ITERM_DEF_uA 60000
91 #define BQ256XX_IPRECHG_MASK GENMASK(7, 4)
92 #define BQ256XX_IPRECHG_STEP_uA 60000
93 #define BQ256XX_IPRECHG_OFFSET_uA 60000
94 #define BQ256XX_IPRECHG_MIN_uA 60000
95 #define BQ256XX_IPRECHG_MAX_uA 780000
96 #define BQ256XX_IPRECHG_DEF_uA 180000
97 #define BQ25618_IPRECHG_STEP_uA 20000
98 #define BQ25618_IPRECHG_OFFSET_uA 20000
99 #define BQ25618_IPRECHG_MIN_uA 20000
100 #define BQ25618_IPRECHG_MAX_uA 260000
101 #define BQ25618_IPRECHG_DEF_uA 40000
102 #define BQ256XX_IPRECHG_BIT_SHIFT 4
104 #define BQ256XX_ICHG_MASK GENMASK(5, 0)
105 #define BQ256XX_ICHG_STEP_uA 60000
106 #define BQ256XX_ICHG_MIN_uA 0
107 #define BQ256XX_ICHG_MAX_uA 3000000
108 #define BQ2560X_ICHG_DEF_uA 2040000
109 #define BQ25611D_ICHG_DEF_uA 1020000
110 #define BQ25618_ICHG_STEP_uA 20000
111 #define BQ25618_ICHG_MIN_uA 0
112 #define BQ25618_ICHG_MAX_uA 1500000
113 #define BQ25618_ICHG_DEF_uA 340000
114 #define BQ25618_ICHG_THRESH 0x3c
115 #define BQ25618_ICHG_THRESH_uA 1180000
117 #define BQ256XX_VBUS_STAT_MASK GENMASK(7, 5)
118 #define BQ256XX_VBUS_STAT_NO_INPUT 0
119 #define BQ256XX_VBUS_STAT_USB_SDP BIT(5)
120 #define BQ256XX_VBUS_STAT_USB_CDP BIT(6)
121 #define BQ256XX_VBUS_STAT_USB_DCP (BIT(6) | BIT(5))
122 #define BQ256XX_VBUS_STAT_USB_OTG (BIT(7) | BIT(6) | BIT(5))
124 #define BQ256XX_CHRG_STAT_MASK GENMASK(4, 3)
125 #define BQ256XX_CHRG_STAT_NOT_CHRGING 0
126 #define BQ256XX_CHRG_STAT_PRECHRGING BIT(3)
127 #define BQ256XX_CHRG_STAT_FAST_CHRGING BIT(4)
128 #define BQ256XX_CHRG_STAT_CHRG_TERM (BIT(4) | BIT(3))
130 #define BQ256XX_PG_STAT_MASK BIT(2)
131 #define BQ256XX_WDT_FAULT_MASK BIT(7)
132 #define BQ256XX_CHRG_FAULT_MASK GENMASK(5, 4)
133 #define BQ256XX_CHRG_FAULT_NORMAL 0
134 #define BQ256XX_CHRG_FAULT_INPUT BIT(4)
135 #define BQ256XX_CHRG_FAULT_THERM BIT(5)
136 #define BQ256XX_CHRG_FAULT_CST_EXPIRE (BIT(5) | BIT(4))
137 #define BQ256XX_BAT_FAULT_MASK BIT(3)
138 #define BQ256XX_NTC_FAULT_MASK GENMASK(2, 0)
139 #define BQ256XX_NTC_FAULT_WARM BIT(1)
140 #define BQ256XX_NTC_FAULT_COOL (BIT(1) | BIT(0))
141 #define BQ256XX_NTC_FAULT_COLD (BIT(2) | BIT(0))
142 #define BQ256XX_NTC_FAULT_HOT (BIT(2) | BIT(1))
144 #define BQ256XX_NUM_WD_VAL 4
145 #define BQ256XX_WATCHDOG_MASK GENMASK(5, 4)
146 #define BQ256XX_WATCHDOG_MAX 1600000
147 #define BQ256XX_WATCHDOG_DIS 0
148 #define BQ256XX_WDT_BIT_SHIFT 4
150 #define BQ256XX_REG_RST BIT(7)
153 * struct bq256xx_init_data -
154 * @ichg: fast charge current
155 * @iindpm: input current limit
156 * @vbatreg: charge voltage
157 * @iterm: termination current
158 * @iprechg: precharge current
159 * @vindpm: input voltage limit
160 * @ichg_max: maximum fast charge current
161 * @vbatreg_max: maximum charge voltage
162 * @ts_ignore: TS_IGNORE flag
164 struct bq256xx_init_data {
177 * struct bq256xx_state -
178 * @vbus_stat: VBUS status according to BQ256XX_CHARGER_STATUS_0
179 * @chrg_stat: charging status according to BQ256XX_CHARGER_STATUS_0
180 * @online: PG status according to BQ256XX_CHARGER_STATUS_0
182 * @wdt_fault: watchdog fault according to BQ256XX_CHARGER_STATUS_1
183 * @bat_fault: battery fault according to BQ256XX_CHARGER_STATUS_1
184 * @chrg_fault: charging fault according to BQ256XX_CHARGER_STATUS_1
185 * @ntc_fault: TS fault according to BQ256XX_CHARGER_STATUS_1
187 struct bq256xx_state {
209 * struct bq256xx_device -
210 * @client: i2c client structure
211 * @regmap: register map structure
212 * @dev: device structure
213 * @charger: power supply registered for the charger
214 * @battery: power supply registered for the battery
215 * @lock: mutex lock structure
217 * @usb2_phy: usb_phy identifier
218 * @usb3_phy: usb_phy identifier
219 * @usb_nb: notifier block
220 * @usb_work: usb work queue
221 * @usb_event: usb_event code
223 * @model_name: i2c name string
225 * @init_data: initialization data
226 * @chip_info: device variant information
227 * @state: device status and faults
228 * @watchdog_timer: watchdog timer value in milliseconds
230 struct bq256xx_device {
231 struct i2c_client *client;
233 struct power_supply *charger;
234 struct power_supply *battery;
236 struct regmap *regmap;
238 struct usb_phy *usb2_phy;
239 struct usb_phy *usb3_phy;
240 struct notifier_block usb_nb;
241 struct work_struct usb_work;
242 unsigned long usb_event;
244 char model_name[I2C_NAME_SIZE];
246 struct bq256xx_init_data init_data;
247 const struct bq256xx_chip_info *chip_info;
248 struct bq256xx_state state;
253 * struct bq256xx_chip_info -
254 * @model_id: device instance
256 * @bq256xx_regmap_config: regmap configuration struct
257 * @bq256xx_get_ichg: pointer to instance specific get_ichg function
258 * @bq256xx_get_iindpm: pointer to instance specific get_iindpm function
259 * @bq256xx_get_vbatreg: pointer to instance specific get_vbatreg function
260 * @bq256xx_get_iterm: pointer to instance specific get_iterm function
261 * @bq256xx_get_iprechg: pointer to instance specific get_iprechg function
262 * @bq256xx_get_vindpm: pointer to instance specific get_vindpm function
264 * @bq256xx_set_ichg: pointer to instance specific set_ichg function
265 * @bq256xx_set_iindpm: pointer to instance specific set_iindpm function
266 * @bq256xx_set_vbatreg: pointer to instance specific set_vbatreg function
267 * @bq256xx_set_iterm: pointer to instance specific set_iterm function
268 * @bq256xx_set_iprechg: pointer to instance specific set_iprechg function
269 * @bq256xx_set_vindpm: pointer to instance specific set_vindpm function
270 * @bq256xx_set_charge_type: pointer to instance specific set_charge_type function
271 * @bq256xx_set_ts_ignore: pointer to instance specific set_ts_ignore function
273 * @bq256xx_def_ichg: default ichg value in microamps
274 * @bq256xx_def_iindpm: default iindpm value in microamps
275 * @bq256xx_def_vbatreg: default vbatreg value in microvolts
276 * @bq256xx_def_iterm: default iterm value in microamps
277 * @bq256xx_def_iprechg: default iprechg value in microamps
278 * @bq256xx_def_vindpm: default vindpm value in microvolts
280 * @bq256xx_max_ichg: maximum charge current in microamps
281 * @bq256xx_max_vbatreg: maximum battery regulation voltage in microvolts
283 * @has_usb_detect: indicates whether device has BC1.2 detection
285 struct bq256xx_chip_info {
288 const struct regmap_config *bq256xx_regmap_config;
290 int (*bq256xx_get_ichg)(struct bq256xx_device *bq);
291 int (*bq256xx_get_iindpm)(struct bq256xx_device *bq);
292 int (*bq256xx_get_vbatreg)(struct bq256xx_device *bq);
293 int (*bq256xx_get_iterm)(struct bq256xx_device *bq);
294 int (*bq256xx_get_iprechg)(struct bq256xx_device *bq);
295 int (*bq256xx_get_vindpm)(struct bq256xx_device *bq);
297 int (*bq256xx_set_ichg)(struct bq256xx_device *bq, int ichg);
298 int (*bq256xx_set_iindpm)(struct bq256xx_device *bq, int iindpm);
299 int (*bq256xx_set_vbatreg)(struct bq256xx_device *bq, int vbatreg);
300 int (*bq256xx_set_iterm)(struct bq256xx_device *bq, int iterm);
301 int (*bq256xx_set_iprechg)(struct bq256xx_device *bq, int iprechg);
302 int (*bq256xx_set_vindpm)(struct bq256xx_device *bq, int vindpm);
303 int (*bq256xx_set_charge_type)(struct bq256xx_device *bq, int type);
304 int (*bq256xx_set_ts_ignore)(struct bq256xx_device *bq, bool ts_ignore);
306 int bq256xx_def_ichg;
307 int bq256xx_def_iindpm;
308 int bq256xx_def_vbatreg;
309 int bq256xx_def_iterm;
310 int bq256xx_def_iprechg;
311 int bq256xx_def_vindpm;
313 int bq256xx_max_ichg;
314 int bq256xx_max_vbatreg;
319 static int bq256xx_watchdog_time[BQ256XX_NUM_WD_VAL] = {
320 0, 40000, 80000, 1600000
323 static const int bq25611d_vbatreg_values[] = {
324 3494000, 3590000, 3686000, 3790000, 3894000, 3990000, 4090000, 4140000,
328 static const int bq25618_619_vbatreg_values[] = {
329 3504000, 3600000, 3696000, 3800000, 3904000, 4000000, 4100000, 4150000,
333 static const int bq25618_619_ichg_values[] = {
334 1290000, 1360000, 1430000, 1500000
337 static enum power_supply_usb_type bq256xx_usb_type[] = {
338 POWER_SUPPLY_USB_TYPE_SDP,
339 POWER_SUPPLY_USB_TYPE_CDP,
340 POWER_SUPPLY_USB_TYPE_DCP,
341 POWER_SUPPLY_USB_TYPE_UNKNOWN,
342 POWER_SUPPLY_USB_TYPE_ACA,
345 static int bq256xx_array_parse(int array_size, int val, const int array[])
352 if (val >= array[array_size - 1])
353 return array_size - 1;
355 for (i = 1; i < array_size; i++) {
359 if (val > array[i - 1] && val < array[i]) {
369 static int bq256xx_usb_notifier(struct notifier_block *nb, unsigned long val,
372 struct bq256xx_device *bq =
373 container_of(nb, struct bq256xx_device, usb_nb);
376 queue_work(system_power_efficient_wq, &bq->usb_work);
381 static void bq256xx_usb_work(struct work_struct *data)
383 struct bq256xx_device *bq =
384 container_of(data, struct bq256xx_device, usb_work);
386 switch (bq->usb_event) {
390 power_supply_changed(bq->charger);
393 dev_err(bq->dev, "Error switching to charger mode.\n");
398 static struct reg_default bq2560x_reg_defs[] = {
399 {BQ256XX_INPUT_CURRENT_LIMIT, 0x17},
400 {BQ256XX_CHARGER_CONTROL_0, 0x1a},
401 {BQ256XX_CHARGE_CURRENT_LIMIT, 0xa2},
402 {BQ256XX_PRECHG_AND_TERM_CURR_LIM, 0x22},
403 {BQ256XX_BATTERY_VOLTAGE_LIMIT, 0x58},
404 {BQ256XX_CHARGER_CONTROL_1, 0x9f},
405 {BQ256XX_CHARGER_CONTROL_2, 0x66},
406 {BQ256XX_CHARGER_CONTROL_3, 0x4c},
409 static struct reg_default bq25611d_reg_defs[] = {
410 {BQ256XX_INPUT_CURRENT_LIMIT, 0x17},
411 {BQ256XX_CHARGER_CONTROL_0, 0x1a},
412 {BQ256XX_CHARGE_CURRENT_LIMIT, 0x91},
413 {BQ256XX_PRECHG_AND_TERM_CURR_LIM, 0x12},
414 {BQ256XX_BATTERY_VOLTAGE_LIMIT, 0x40},
415 {BQ256XX_CHARGER_CONTROL_1, 0x9e},
416 {BQ256XX_CHARGER_CONTROL_2, 0xe6},
417 {BQ256XX_CHARGER_CONTROL_3, 0x4c},
418 {BQ256XX_PART_INFORMATION, 0x54},
419 {BQ256XX_CHARGER_CONTROL_4, 0x75},
422 static struct reg_default bq25618_619_reg_defs[] = {
423 {BQ256XX_INPUT_CURRENT_LIMIT, 0x17},
424 {BQ256XX_CHARGER_CONTROL_0, 0x1a},
425 {BQ256XX_CHARGE_CURRENT_LIMIT, 0x91},
426 {BQ256XX_PRECHG_AND_TERM_CURR_LIM, 0x12},
427 {BQ256XX_BATTERY_VOLTAGE_LIMIT, 0x40},
428 {BQ256XX_CHARGER_CONTROL_1, 0x9e},
429 {BQ256XX_CHARGER_CONTROL_2, 0xe6},
430 {BQ256XX_CHARGER_CONTROL_3, 0x4c},
431 {BQ256XX_PART_INFORMATION, 0x2c},
432 {BQ256XX_CHARGER_CONTROL_4, 0x75},
435 static int bq256xx_get_state(struct bq256xx_device *bq,
436 struct bq256xx_state *state)
438 unsigned int charger_status_0;
439 unsigned int charger_status_1;
442 ret = regmap_read(bq->regmap, BQ256XX_CHARGER_STATUS_0,
447 ret = regmap_read(bq->regmap, BQ256XX_CHARGER_STATUS_1,
452 state->vbus_stat = charger_status_0 & BQ256XX_VBUS_STAT_MASK;
453 state->chrg_stat = charger_status_0 & BQ256XX_CHRG_STAT_MASK;
454 state->online = charger_status_0 & BQ256XX_PG_STAT_MASK;
456 state->wdt_fault = charger_status_1 & BQ256XX_WDT_FAULT_MASK;
457 state->bat_fault = charger_status_1 & BQ256XX_BAT_FAULT_MASK;
458 state->chrg_fault = charger_status_1 & BQ256XX_CHRG_FAULT_MASK;
459 state->ntc_fault = charger_status_1 & BQ256XX_NTC_FAULT_MASK;
464 static int bq256xx_set_charge_type(struct bq256xx_device *bq, int type)
469 case POWER_SUPPLY_CHARGE_TYPE_NONE:
472 case POWER_SUPPLY_CHARGE_TYPE_TRICKLE:
473 case POWER_SUPPLY_CHARGE_TYPE_FAST:
480 return regmap_update_bits(bq->regmap, BQ256XX_CHARGER_CONTROL_0,
481 BQ256XX_CHG_CONFIG_MASK,
482 (chg_config ? 1 : 0) << BQ256XX_CHG_CONFIG_BIT_SHIFT);
485 static int bq256xx_get_ichg_curr(struct bq256xx_device *bq)
487 unsigned int charge_current_limit;
488 unsigned int ichg_reg_code;
491 ret = regmap_read(bq->regmap, BQ256XX_CHARGE_CURRENT_LIMIT,
492 &charge_current_limit);
496 ichg_reg_code = charge_current_limit & BQ256XX_ICHG_MASK;
498 return ichg_reg_code * BQ256XX_ICHG_STEP_uA;
501 static int bq25618_619_get_ichg_curr(struct bq256xx_device *bq)
503 unsigned int charge_current_limit;
504 unsigned int ichg_reg_code;
507 ret = regmap_read(bq->regmap, BQ256XX_CHARGE_CURRENT_LIMIT,
508 &charge_current_limit);
512 ichg_reg_code = charge_current_limit & BQ256XX_ICHG_MASK;
514 if (ichg_reg_code < BQ25618_ICHG_THRESH)
515 return ichg_reg_code * BQ25618_ICHG_STEP_uA;
517 return bq25618_619_ichg_values[ichg_reg_code - BQ25618_ICHG_THRESH];
520 static int bq256xx_set_ichg_curr(struct bq256xx_device *bq, int ichg)
522 unsigned int ichg_reg_code;
523 int ichg_max = bq->init_data.ichg_max;
525 ichg = clamp(ichg, BQ256XX_ICHG_MIN_uA, ichg_max);
526 ichg_reg_code = ichg / BQ256XX_ICHG_STEP_uA;
528 return regmap_update_bits(bq->regmap, BQ256XX_CHARGE_CURRENT_LIMIT,
529 BQ256XX_ICHG_MASK, ichg_reg_code);
532 static int bq25618_619_set_ichg_curr(struct bq256xx_device *bq, int ichg)
534 int array_size = ARRAY_SIZE(bq25618_619_ichg_values);
535 unsigned int ichg_reg_code;
536 int ichg_max = bq->init_data.ichg_max;
538 ichg = clamp(ichg, BQ25618_ICHG_MIN_uA, ichg_max);
540 if (ichg <= BQ25618_ICHG_THRESH_uA) {
541 ichg_reg_code = ichg / BQ25618_ICHG_STEP_uA;
543 ichg_reg_code = bq256xx_array_parse(array_size, ichg,
544 bq25618_619_ichg_values) + BQ25618_ICHG_THRESH;
547 return regmap_update_bits(bq->regmap, BQ256XX_CHARGE_CURRENT_LIMIT,
548 BQ256XX_ICHG_MASK, ichg_reg_code);
551 static int bq25618_619_get_chrg_volt(struct bq256xx_device *bq)
553 unsigned int battery_volt_lim;
554 unsigned int vbatreg_reg_code;
557 ret = regmap_read(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT,
563 vbatreg_reg_code = (battery_volt_lim & BQ256XX_VBATREG_MASK) >>
564 BQ256XX_VBATREG_BIT_SHIFT;
566 if (vbatreg_reg_code > BQ2561X_VBATREG_THRESH)
567 return ((vbatreg_reg_code - BQ2561X_VBATREG_THRESH) *
568 BQ2561X_VBATREG_STEP_uV) +
569 BQ25618_VBATREG_THRESH_uV;
571 return bq25618_619_vbatreg_values[vbatreg_reg_code];
574 static int bq25611d_get_chrg_volt(struct bq256xx_device *bq)
576 unsigned int battery_volt_lim;
577 unsigned int vbatreg_reg_code;
580 ret = regmap_read(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT,
585 vbatreg_reg_code = (battery_volt_lim & BQ256XX_VBATREG_MASK) >>
586 BQ256XX_VBATREG_BIT_SHIFT;
588 if (vbatreg_reg_code > BQ2561X_VBATREG_THRESH)
589 return ((vbatreg_reg_code - BQ2561X_VBATREG_THRESH) *
590 BQ2561X_VBATREG_STEP_uV) +
591 BQ25611D_VBATREG_THRESH_uV;
593 return bq25611d_vbatreg_values[vbatreg_reg_code];
596 static int bq2560x_get_chrg_volt(struct bq256xx_device *bq)
598 unsigned int battery_volt_lim;
599 unsigned int vbatreg_reg_code;
602 ret = regmap_read(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT,
607 vbatreg_reg_code = (battery_volt_lim & BQ256XX_VBATREG_MASK) >>
608 BQ256XX_VBATREG_BIT_SHIFT;
610 return (vbatreg_reg_code * BQ2560X_VBATREG_STEP_uV)
611 + BQ2560X_VBATREG_OFFSET_uV;
614 static int bq25601d_get_chrg_volt(struct bq256xx_device *bq)
616 unsigned int battery_volt_lim;
617 unsigned int vbatreg_reg_code;
620 ret = regmap_read(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT,
625 vbatreg_reg_code = (battery_volt_lim & BQ256XX_VBATREG_MASK) >>
626 BQ256XX_VBATREG_BIT_SHIFT;
628 return (vbatreg_reg_code * BQ2560X_VBATREG_STEP_uV)
629 + BQ25601D_VBATREG_OFFSET_uV;
632 static int bq25618_619_set_chrg_volt(struct bq256xx_device *bq, int vbatreg)
634 int array_size = ARRAY_SIZE(bq25618_619_vbatreg_values);
635 unsigned int vbatreg_reg_code;
636 int vbatreg_max = bq->init_data.vbatreg_max;
638 vbatreg = clamp(vbatreg, BQ25618_VBATREG_MIN_uV, vbatreg_max);
640 if (vbatreg > BQ25618_VBATREG_THRESH_uV)
641 vbatreg_reg_code = ((vbatreg -
642 BQ25618_VBATREG_THRESH_uV) /
643 (BQ2561X_VBATREG_STEP_uV)) + BQ2561X_VBATREG_THRESH;
645 vbatreg_reg_code = bq256xx_array_parse(array_size, vbatreg,
646 bq25618_619_vbatreg_values);
649 return regmap_update_bits(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT,
650 BQ256XX_VBATREG_MASK, vbatreg_reg_code <<
651 BQ256XX_VBATREG_BIT_SHIFT);
654 static int bq25611d_set_chrg_volt(struct bq256xx_device *bq, int vbatreg)
656 int array_size = ARRAY_SIZE(bq25611d_vbatreg_values);
657 unsigned int vbatreg_reg_code;
658 int vbatreg_max = bq->init_data.vbatreg_max;
660 vbatreg = clamp(vbatreg, BQ25611D_VBATREG_MIN_uV, vbatreg_max);
662 if (vbatreg > BQ25611D_VBATREG_THRESH_uV)
663 vbatreg_reg_code = ((vbatreg -
664 BQ25611D_VBATREG_THRESH_uV) /
665 (BQ2561X_VBATREG_STEP_uV)) + BQ2561X_VBATREG_THRESH;
667 vbatreg_reg_code = bq256xx_array_parse(array_size, vbatreg,
668 bq25611d_vbatreg_values);
671 return regmap_update_bits(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT,
672 BQ256XX_VBATREG_MASK, vbatreg_reg_code <<
673 BQ256XX_VBATREG_BIT_SHIFT);
676 static int bq2560x_set_chrg_volt(struct bq256xx_device *bq, int vbatreg)
678 unsigned int vbatreg_reg_code;
679 int vbatreg_max = bq->init_data.vbatreg_max;
681 vbatreg = clamp(vbatreg, BQ2560X_VBATREG_MIN_uV, vbatreg_max);
683 vbatreg_reg_code = (vbatreg - BQ2560X_VBATREG_OFFSET_uV) /
684 BQ2560X_VBATREG_STEP_uV;
686 return regmap_update_bits(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT,
687 BQ256XX_VBATREG_MASK, vbatreg_reg_code <<
688 BQ256XX_VBATREG_BIT_SHIFT);
691 static int bq25601d_set_chrg_volt(struct bq256xx_device *bq, int vbatreg)
693 unsigned int vbatreg_reg_code;
694 int vbatreg_max = bq->init_data.vbatreg_max;
696 vbatreg = clamp(vbatreg, BQ25601D_VBATREG_MIN_uV, vbatreg_max);
698 vbatreg_reg_code = (vbatreg - BQ25601D_VBATREG_OFFSET_uV) /
699 BQ2560X_VBATREG_STEP_uV;
701 return regmap_update_bits(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT,
702 BQ256XX_VBATREG_MASK, vbatreg_reg_code <<
703 BQ256XX_VBATREG_BIT_SHIFT);
706 static int bq256xx_set_ts_ignore(struct bq256xx_device *bq, bool ts_ignore)
708 return regmap_update_bits(bq->regmap, BQ256XX_INPUT_CURRENT_LIMIT,
709 BQ256XX_TS_IGNORE, (ts_ignore ? 1 : 0) << BQ256XX_TS_IGNORE_SHIFT);
712 static int bq256xx_get_prechrg_curr(struct bq256xx_device *bq)
714 unsigned int prechg_and_term_curr_lim;
715 unsigned int iprechg_reg_code;
718 ret = regmap_read(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM,
719 &prechg_and_term_curr_lim);
723 iprechg_reg_code = (prechg_and_term_curr_lim & BQ256XX_IPRECHG_MASK)
724 >> BQ256XX_IPRECHG_BIT_SHIFT;
726 return (iprechg_reg_code * BQ256XX_IPRECHG_STEP_uA) +
727 BQ256XX_IPRECHG_OFFSET_uA;
730 static int bq256xx_set_prechrg_curr(struct bq256xx_device *bq, int iprechg)
732 unsigned int iprechg_reg_code;
734 iprechg = clamp(iprechg, BQ256XX_IPRECHG_MIN_uA,
735 BQ256XX_IPRECHG_MAX_uA);
737 iprechg_reg_code = ((iprechg - BQ256XX_IPRECHG_OFFSET_uA) /
738 BQ256XX_IPRECHG_STEP_uA) << BQ256XX_IPRECHG_BIT_SHIFT;
740 return regmap_update_bits(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM,
741 BQ256XX_IPRECHG_MASK, iprechg_reg_code);
744 static int bq25618_619_get_prechrg_curr(struct bq256xx_device *bq)
746 unsigned int prechg_and_term_curr_lim;
747 unsigned int iprechg_reg_code;
750 ret = regmap_read(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM,
751 &prechg_and_term_curr_lim);
755 iprechg_reg_code = (prechg_and_term_curr_lim & BQ256XX_IPRECHG_MASK)
756 >> BQ256XX_IPRECHG_BIT_SHIFT;
758 return (iprechg_reg_code * BQ25618_IPRECHG_STEP_uA) +
759 BQ25618_IPRECHG_OFFSET_uA;
762 static int bq25618_619_set_prechrg_curr(struct bq256xx_device *bq, int iprechg)
764 unsigned int iprechg_reg_code;
766 iprechg = clamp(iprechg, BQ25618_IPRECHG_MIN_uA,
767 BQ25618_IPRECHG_MAX_uA);
769 iprechg_reg_code = ((iprechg - BQ25618_IPRECHG_OFFSET_uA) /
770 BQ25618_IPRECHG_STEP_uA) << BQ256XX_IPRECHG_BIT_SHIFT;
772 return regmap_update_bits(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM,
773 BQ256XX_IPRECHG_MASK, iprechg_reg_code);
776 static int bq256xx_get_term_curr(struct bq256xx_device *bq)
778 unsigned int prechg_and_term_curr_lim;
779 unsigned int iterm_reg_code;
782 ret = regmap_read(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM,
783 &prechg_and_term_curr_lim);
787 iterm_reg_code = prechg_and_term_curr_lim & BQ256XX_ITERM_MASK;
789 return (iterm_reg_code * BQ256XX_ITERM_STEP_uA) +
790 BQ256XX_ITERM_OFFSET_uA;
793 static int bq256xx_set_term_curr(struct bq256xx_device *bq, int iterm)
795 unsigned int iterm_reg_code;
797 iterm = clamp(iterm, BQ256XX_ITERM_MIN_uA, BQ256XX_ITERM_MAX_uA);
799 iterm_reg_code = (iterm - BQ256XX_ITERM_OFFSET_uA) /
800 BQ256XX_ITERM_STEP_uA;
802 return regmap_update_bits(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM,
803 BQ256XX_ITERM_MASK, iterm_reg_code);
806 static int bq25618_619_get_term_curr(struct bq256xx_device *bq)
808 unsigned int prechg_and_term_curr_lim;
809 unsigned int iterm_reg_code;
812 ret = regmap_read(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM,
813 &prechg_and_term_curr_lim);
817 iterm_reg_code = prechg_and_term_curr_lim & BQ256XX_ITERM_MASK;
819 return (iterm_reg_code * BQ25618_ITERM_STEP_uA) +
820 BQ25618_ITERM_OFFSET_uA;
823 static int bq25618_619_set_term_curr(struct bq256xx_device *bq, int iterm)
825 unsigned int iterm_reg_code;
827 iterm = clamp(iterm, BQ25618_ITERM_MIN_uA, BQ25618_ITERM_MAX_uA);
829 iterm_reg_code = (iterm - BQ25618_ITERM_OFFSET_uA) /
830 BQ25618_ITERM_STEP_uA;
832 return regmap_update_bits(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM,
833 BQ256XX_ITERM_MASK, iterm_reg_code);
836 static int bq256xx_get_input_volt_lim(struct bq256xx_device *bq)
838 unsigned int charger_control_2;
839 unsigned int vindpm_reg_code;
842 ret = regmap_read(bq->regmap, BQ256XX_CHARGER_CONTROL_2,
847 vindpm_reg_code = charger_control_2 & BQ256XX_VINDPM_MASK;
849 return (vindpm_reg_code * BQ256XX_VINDPM_STEP_uV) +
850 BQ256XX_VINDPM_OFFSET_uV;
853 static int bq256xx_set_input_volt_lim(struct bq256xx_device *bq, int vindpm)
855 unsigned int vindpm_reg_code;
857 vindpm = clamp(vindpm, BQ256XX_VINDPM_MIN_uV, BQ256XX_VINDPM_MAX_uV);
859 vindpm_reg_code = (vindpm - BQ256XX_VINDPM_OFFSET_uV) /
860 BQ256XX_VINDPM_STEP_uV;
862 return regmap_update_bits(bq->regmap, BQ256XX_CHARGER_CONTROL_2,
863 BQ256XX_VINDPM_MASK, vindpm_reg_code);
866 static int bq256xx_get_input_curr_lim(struct bq256xx_device *bq)
868 unsigned int input_current_limit;
869 unsigned int iindpm_reg_code;
872 ret = regmap_read(bq->regmap, BQ256XX_INPUT_CURRENT_LIMIT,
873 &input_current_limit);
877 iindpm_reg_code = input_current_limit & BQ256XX_IINDPM_MASK;
879 return (iindpm_reg_code * BQ256XX_IINDPM_STEP_uA) +
880 BQ256XX_IINDPM_OFFSET_uA;
883 static int bq256xx_set_input_curr_lim(struct bq256xx_device *bq, int iindpm)
885 unsigned int iindpm_reg_code;
887 iindpm = clamp(iindpm, BQ256XX_IINDPM_MIN_uA, BQ256XX_IINDPM_MAX_uA);
889 iindpm_reg_code = (iindpm - BQ256XX_IINDPM_OFFSET_uA) /
890 BQ256XX_IINDPM_STEP_uA;
892 return regmap_update_bits(bq->regmap, BQ256XX_INPUT_CURRENT_LIMIT,
893 BQ256XX_IINDPM_MASK, iindpm_reg_code);
896 static void bq256xx_charger_reset(void *data)
898 struct bq256xx_device *bq = data;
900 regmap_update_bits(bq->regmap, BQ256XX_PART_INFORMATION,
901 BQ256XX_REG_RST, BQ256XX_REG_RST);
903 if (!IS_ERR_OR_NULL(bq->usb2_phy))
904 usb_unregister_notifier(bq->usb2_phy, &bq->usb_nb);
906 if (!IS_ERR_OR_NULL(bq->usb3_phy))
907 usb_unregister_notifier(bq->usb3_phy, &bq->usb_nb);
910 static int bq256xx_set_charger_property(struct power_supply *psy,
911 enum power_supply_property prop,
912 const union power_supply_propval *val)
914 struct bq256xx_device *bq = power_supply_get_drvdata(psy);
918 case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
919 ret = bq->chip_info->bq256xx_set_iindpm(bq, val->intval);
924 case POWER_SUPPLY_PROP_STATUS:
927 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
928 ret = bq->chip_info->bq256xx_set_vbatreg(bq, val->intval);
933 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
934 ret = bq->chip_info->bq256xx_set_ichg(bq, val->intval);
939 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
940 ret = bq->chip_info->bq256xx_set_iprechg(bq, val->intval);
945 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
946 ret = bq->chip_info->bq256xx_set_iterm(bq, val->intval);
951 case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
952 ret = bq->chip_info->bq256xx_set_vindpm(bq, val->intval);
957 case POWER_SUPPLY_PROP_CHARGE_TYPE:
958 ret = bq->chip_info->bq256xx_set_charge_type(bq, val->intval);
971 static int bq256xx_get_battery_property(struct power_supply *psy,
972 enum power_supply_property psp,
973 union power_supply_propval *val)
975 struct bq256xx_device *bq = power_supply_get_drvdata(psy);
978 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
979 val->intval = bq->init_data.ichg_max;
982 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
983 val->intval = bq->init_data.vbatreg_max;
993 static int bq256xx_get_charger_property(struct power_supply *psy,
994 enum power_supply_property psp,
995 union power_supply_propval *val)
997 struct bq256xx_device *bq = power_supply_get_drvdata(psy);
998 struct bq256xx_state state;
1001 mutex_lock(&bq->lock);
1002 ret = bq256xx_get_state(bq, &state);
1003 mutex_unlock(&bq->lock);
1008 case POWER_SUPPLY_PROP_STATUS:
1009 if (state.vbus_stat == BQ256XX_VBUS_STAT_NO_INPUT ||
1010 state.vbus_stat == BQ256XX_VBUS_STAT_USB_OTG)
1011 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
1012 else if (state.chrg_stat == BQ256XX_CHRG_STAT_NOT_CHRGING)
1013 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
1014 else if (state.chrg_stat == BQ256XX_CHRG_STAT_CHRG_TERM)
1015 val->intval = POWER_SUPPLY_STATUS_FULL;
1017 val->intval = POWER_SUPPLY_STATUS_CHARGING;
1020 case POWER_SUPPLY_PROP_HEALTH:
1021 val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
1022 if (state.wdt_fault) {
1024 POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE;
1025 } else if (state.bat_fault) {
1026 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
1028 switch (state.chrg_stat) {
1029 case BQ256XX_CHRG_FAULT_INPUT:
1031 POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
1033 case BQ256XX_CHRG_FAULT_THERM:
1034 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
1036 case BQ256XX_CHRG_FAULT_CST_EXPIRE:
1038 POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE;
1044 switch (state.ntc_fault) {
1045 case BQ256XX_NTC_FAULT_WARM:
1046 val->intval = POWER_SUPPLY_HEALTH_WARM;
1048 case BQ256XX_NTC_FAULT_COOL:
1049 val->intval = POWER_SUPPLY_HEALTH_COOL;
1051 case BQ256XX_NTC_FAULT_COLD:
1052 val->intval = POWER_SUPPLY_HEALTH_COLD;
1054 case BQ256XX_NTC_FAULT_HOT:
1055 val->intval = POWER_SUPPLY_HEALTH_HOT;
1058 val->intval = POWER_SUPPLY_HEALTH_GOOD;
1064 case POWER_SUPPLY_PROP_USB_TYPE:
1065 if (bq->chip_info->has_usb_detect) {
1066 switch (state.vbus_stat) {
1067 case BQ256XX_VBUS_STAT_USB_SDP:
1068 val->intval = POWER_SUPPLY_USB_TYPE_SDP;
1070 case BQ256XX_VBUS_STAT_USB_CDP:
1071 val->intval = POWER_SUPPLY_USB_TYPE_CDP;
1073 case BQ256XX_VBUS_STAT_USB_DCP:
1074 val->intval = POWER_SUPPLY_USB_TYPE_DCP;
1076 case BQ256XX_VBUS_STAT_USB_OTG:
1077 val->intval = POWER_SUPPLY_USB_TYPE_ACA;
1080 val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN;
1084 switch (state.vbus_stat) {
1085 case BQ256XX_VBUS_STAT_USB_SDP:
1086 val->intval = POWER_SUPPLY_USB_TYPE_SDP;
1088 case BQ256XX_VBUS_STAT_USB_OTG:
1089 val->intval = POWER_SUPPLY_USB_TYPE_ACA;
1092 val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN;
1098 case POWER_SUPPLY_PROP_CHARGE_TYPE:
1099 switch (state.chrg_stat) {
1100 case BQ256XX_CHRG_STAT_NOT_CHRGING:
1101 val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
1103 case BQ256XX_CHRG_STAT_PRECHRGING:
1104 val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
1106 case BQ256XX_CHRG_STAT_FAST_CHRGING:
1107 val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST;
1109 case BQ256XX_CHRG_STAT_CHRG_TERM:
1110 val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
1113 val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN;
1117 case POWER_SUPPLY_PROP_MANUFACTURER:
1118 val->strval = BQ256XX_MANUFACTURER;
1121 case POWER_SUPPLY_PROP_MODEL_NAME:
1122 val->strval = bq->model_name;
1125 case POWER_SUPPLY_PROP_ONLINE:
1126 val->intval = state.online;
1129 case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
1130 ret = bq->chip_info->bq256xx_get_vindpm(bq);
1136 case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
1137 ret = bq->chip_info->bq256xx_get_iindpm(bq);
1143 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
1144 ret = bq->chip_info->bq256xx_get_vbatreg(bq);
1150 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
1151 ret = bq->chip_info->bq256xx_get_ichg(bq);
1157 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
1158 ret = bq->chip_info->bq256xx_get_iprechg(bq);
1164 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
1165 ret = bq->chip_info->bq256xx_get_iterm(bq);
1178 static bool bq256xx_state_changed(struct bq256xx_device *bq,
1179 struct bq256xx_state *new_state)
1181 struct bq256xx_state old_state;
1183 mutex_lock(&bq->lock);
1184 old_state = bq->state;
1185 mutex_unlock(&bq->lock);
1187 return memcmp(&old_state, new_state, sizeof(struct bq256xx_state)) != 0;
1190 static irqreturn_t bq256xx_irq_handler_thread(int irq, void *private)
1192 struct bq256xx_device *bq = private;
1193 struct bq256xx_state state;
1196 ret = bq256xx_get_state(bq, &state);
1200 if (!bq256xx_state_changed(bq, &state))
1203 mutex_lock(&bq->lock);
1205 mutex_unlock(&bq->lock);
1207 power_supply_changed(bq->charger);
1213 static enum power_supply_property bq256xx_power_supply_props[] = {
1214 POWER_SUPPLY_PROP_MANUFACTURER,
1215 POWER_SUPPLY_PROP_MODEL_NAME,
1216 POWER_SUPPLY_PROP_STATUS,
1217 POWER_SUPPLY_PROP_ONLINE,
1218 POWER_SUPPLY_PROP_HEALTH,
1219 POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT,
1220 POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
1221 POWER_SUPPLY_PROP_CHARGE_TYPE,
1222 POWER_SUPPLY_PROP_USB_TYPE,
1223 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
1224 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
1225 POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
1226 POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
1229 static enum power_supply_property bq256xx_battery_props[] = {
1230 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
1231 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
1234 static int bq256xx_property_is_writeable(struct power_supply *psy,
1235 enum power_supply_property prop)
1238 case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
1239 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
1240 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
1241 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
1242 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
1243 case POWER_SUPPLY_PROP_STATUS:
1244 case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
1245 case POWER_SUPPLY_PROP_CHARGE_TYPE:
1252 static const struct power_supply_desc bq256xx_power_supply_desc = {
1253 .name = "bq256xx-charger",
1254 .type = POWER_SUPPLY_TYPE_USB,
1255 .usb_types = bq256xx_usb_type,
1256 .num_usb_types = ARRAY_SIZE(bq256xx_usb_type),
1257 .properties = bq256xx_power_supply_props,
1258 .num_properties = ARRAY_SIZE(bq256xx_power_supply_props),
1259 .get_property = bq256xx_get_charger_property,
1260 .set_property = bq256xx_set_charger_property,
1261 .property_is_writeable = bq256xx_property_is_writeable,
1264 static struct power_supply_desc bq256xx_battery_desc = {
1265 .name = "bq256xx-battery",
1266 .type = POWER_SUPPLY_TYPE_BATTERY,
1267 .get_property = bq256xx_get_battery_property,
1268 .properties = bq256xx_battery_props,
1269 .num_properties = ARRAY_SIZE(bq256xx_battery_props),
1270 .property_is_writeable = bq256xx_property_is_writeable,
1274 static bool bq256xx_is_volatile_reg(struct device *dev, unsigned int reg)
1277 case BQ256XX_INPUT_CURRENT_LIMIT:
1278 case BQ256XX_CHARGER_STATUS_0...BQ256XX_CHARGER_STATUS_2:
1285 static const struct regmap_config bq25600_regmap_config = {
1289 .max_register = BQ256XX_PART_INFORMATION,
1290 .reg_defaults = bq2560x_reg_defs,
1291 .num_reg_defaults = ARRAY_SIZE(bq2560x_reg_defs),
1292 .cache_type = REGCACHE_FLAT,
1293 .volatile_reg = bq256xx_is_volatile_reg,
1296 static const struct regmap_config bq25611d_regmap_config = {
1300 .max_register = BQ256XX_CHARGER_CONTROL_4,
1301 .reg_defaults = bq25611d_reg_defs,
1302 .num_reg_defaults = ARRAY_SIZE(bq25611d_reg_defs),
1303 .cache_type = REGCACHE_FLAT,
1304 .volatile_reg = bq256xx_is_volatile_reg,
1307 static const struct regmap_config bq25618_619_regmap_config = {
1311 .max_register = BQ256XX_CHARGER_CONTROL_4,
1312 .reg_defaults = bq25618_619_reg_defs,
1313 .num_reg_defaults = ARRAY_SIZE(bq25618_619_reg_defs),
1314 .cache_type = REGCACHE_FLAT,
1315 .volatile_reg = bq256xx_is_volatile_reg,
1318 static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
1320 .model_id = BQ25600,
1321 .bq256xx_regmap_config = &bq25600_regmap_config,
1322 .bq256xx_get_ichg = bq256xx_get_ichg_curr,
1323 .bq256xx_get_iindpm = bq256xx_get_input_curr_lim,
1324 .bq256xx_get_vbatreg = bq2560x_get_chrg_volt,
1325 .bq256xx_get_iterm = bq256xx_get_term_curr,
1326 .bq256xx_get_iprechg = bq256xx_get_prechrg_curr,
1327 .bq256xx_get_vindpm = bq256xx_get_input_volt_lim,
1328 .bq256xx_set_ts_ignore = NULL,
1330 .bq256xx_set_ichg = bq256xx_set_ichg_curr,
1331 .bq256xx_set_iindpm = bq256xx_set_input_curr_lim,
1332 .bq256xx_set_vbatreg = bq2560x_set_chrg_volt,
1333 .bq256xx_set_iterm = bq256xx_set_term_curr,
1334 .bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
1335 .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1336 .bq256xx_set_charge_type = bq256xx_set_charge_type,
1338 .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA,
1339 .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
1340 .bq256xx_def_vbatreg = BQ2560X_VBATREG_DEF_uV,
1341 .bq256xx_def_iterm = BQ256XX_ITERM_DEF_uA,
1342 .bq256xx_def_iprechg = BQ256XX_IPRECHG_DEF_uA,
1343 .bq256xx_def_vindpm = BQ256XX_VINDPM_DEF_uV,
1345 .bq256xx_max_ichg = BQ256XX_ICHG_MAX_uA,
1346 .bq256xx_max_vbatreg = BQ2560X_VBATREG_MAX_uV,
1348 .has_usb_detect = false,
1352 .model_id = BQ25600D,
1353 .bq256xx_regmap_config = &bq25600_regmap_config,
1354 .bq256xx_get_ichg = bq256xx_get_ichg_curr,
1355 .bq256xx_get_iindpm = bq256xx_get_input_curr_lim,
1356 .bq256xx_get_vbatreg = bq2560x_get_chrg_volt,
1357 .bq256xx_get_iterm = bq256xx_get_term_curr,
1358 .bq256xx_get_iprechg = bq256xx_get_prechrg_curr,
1359 .bq256xx_get_vindpm = bq256xx_get_input_volt_lim,
1361 .bq256xx_set_ichg = bq256xx_set_ichg_curr,
1362 .bq256xx_set_iindpm = bq256xx_set_input_curr_lim,
1363 .bq256xx_set_vbatreg = bq2560x_set_chrg_volt,
1364 .bq256xx_set_iterm = bq256xx_set_term_curr,
1365 .bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
1366 .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1367 .bq256xx_set_charge_type = bq256xx_set_charge_type,
1368 .bq256xx_set_ts_ignore = NULL,
1370 .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA,
1371 .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
1372 .bq256xx_def_vbatreg = BQ2560X_VBATREG_DEF_uV,
1373 .bq256xx_def_iterm = BQ256XX_ITERM_DEF_uA,
1374 .bq256xx_def_iprechg = BQ256XX_IPRECHG_DEF_uA,
1375 .bq256xx_def_vindpm = BQ256XX_VINDPM_DEF_uV,
1377 .bq256xx_max_ichg = BQ256XX_ICHG_MAX_uA,
1378 .bq256xx_max_vbatreg = BQ2560X_VBATREG_MAX_uV,
1380 .has_usb_detect = true,
1384 .model_id = BQ25601,
1385 .bq256xx_regmap_config = &bq25600_regmap_config,
1386 .bq256xx_get_ichg = bq256xx_get_ichg_curr,
1387 .bq256xx_get_iindpm = bq256xx_get_input_curr_lim,
1388 .bq256xx_get_vbatreg = bq2560x_get_chrg_volt,
1389 .bq256xx_get_iterm = bq256xx_get_term_curr,
1390 .bq256xx_get_iprechg = bq256xx_get_prechrg_curr,
1391 .bq256xx_get_vindpm = bq256xx_get_input_volt_lim,
1393 .bq256xx_set_ichg = bq256xx_set_ichg_curr,
1394 .bq256xx_set_iindpm = bq256xx_set_input_curr_lim,
1395 .bq256xx_set_vbatreg = bq2560x_set_chrg_volt,
1396 .bq256xx_set_iterm = bq256xx_set_term_curr,
1397 .bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
1398 .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1399 .bq256xx_set_charge_type = bq256xx_set_charge_type,
1400 .bq256xx_set_ts_ignore = NULL,
1402 .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA,
1403 .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
1404 .bq256xx_def_vbatreg = BQ2560X_VBATREG_DEF_uV,
1405 .bq256xx_def_iterm = BQ256XX_ITERM_DEF_uA,
1406 .bq256xx_def_iprechg = BQ256XX_IPRECHG_DEF_uA,
1407 .bq256xx_def_vindpm = BQ256XX_VINDPM_DEF_uV,
1409 .bq256xx_max_ichg = BQ256XX_ICHG_MAX_uA,
1410 .bq256xx_max_vbatreg = BQ2560X_VBATREG_MAX_uV,
1412 .has_usb_detect = false,
1416 .model_id = BQ25601D,
1417 .bq256xx_regmap_config = &bq25600_regmap_config,
1418 .bq256xx_get_ichg = bq256xx_get_ichg_curr,
1419 .bq256xx_get_iindpm = bq256xx_get_input_curr_lim,
1420 .bq256xx_get_vbatreg = bq25601d_get_chrg_volt,
1421 .bq256xx_get_iterm = bq256xx_get_term_curr,
1422 .bq256xx_get_iprechg = bq256xx_get_prechrg_curr,
1423 .bq256xx_get_vindpm = bq256xx_get_input_volt_lim,
1425 .bq256xx_set_ichg = bq256xx_set_ichg_curr,
1426 .bq256xx_set_iindpm = bq256xx_set_input_curr_lim,
1427 .bq256xx_set_vbatreg = bq25601d_set_chrg_volt,
1428 .bq256xx_set_iterm = bq256xx_set_term_curr,
1429 .bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
1430 .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1431 .bq256xx_set_charge_type = bq256xx_set_charge_type,
1432 .bq256xx_set_ts_ignore = NULL,
1434 .bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA,
1435 .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
1436 .bq256xx_def_vbatreg = BQ2560X_VBATREG_DEF_uV,
1437 .bq256xx_def_iterm = BQ256XX_ITERM_DEF_uA,
1438 .bq256xx_def_iprechg = BQ256XX_IPRECHG_DEF_uA,
1439 .bq256xx_def_vindpm = BQ256XX_VINDPM_DEF_uV,
1441 .bq256xx_max_ichg = BQ256XX_ICHG_MAX_uA,
1442 .bq256xx_max_vbatreg = BQ2560X_VBATREG_MAX_uV,
1444 .has_usb_detect = true,
1448 .model_id = BQ25611D,
1449 .bq256xx_regmap_config = &bq25611d_regmap_config,
1450 .bq256xx_get_ichg = bq256xx_get_ichg_curr,
1451 .bq256xx_get_iindpm = bq256xx_get_input_curr_lim,
1452 .bq256xx_get_vbatreg = bq25611d_get_chrg_volt,
1453 .bq256xx_get_iterm = bq256xx_get_term_curr,
1454 .bq256xx_get_iprechg = bq256xx_get_prechrg_curr,
1455 .bq256xx_get_vindpm = bq256xx_get_input_volt_lim,
1457 .bq256xx_set_ichg = bq256xx_set_ichg_curr,
1458 .bq256xx_set_iindpm = bq256xx_set_input_curr_lim,
1459 .bq256xx_set_vbatreg = bq25611d_set_chrg_volt,
1460 .bq256xx_set_iterm = bq256xx_set_term_curr,
1461 .bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
1462 .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1463 .bq256xx_set_charge_type = bq256xx_set_charge_type,
1464 .bq256xx_set_ts_ignore = bq256xx_set_ts_ignore,
1466 .bq256xx_def_ichg = BQ25611D_ICHG_DEF_uA,
1467 .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
1468 .bq256xx_def_vbatreg = BQ25611D_VBATREG_DEF_uV,
1469 .bq256xx_def_iterm = BQ256XX_ITERM_DEF_uA,
1470 .bq256xx_def_iprechg = BQ256XX_IPRECHG_DEF_uA,
1471 .bq256xx_def_vindpm = BQ256XX_VINDPM_DEF_uV,
1473 .bq256xx_max_ichg = BQ256XX_ICHG_MAX_uA,
1474 .bq256xx_max_vbatreg = BQ25611D_VBATREG_MAX_uV,
1476 .has_usb_detect = true,
1480 .model_id = BQ25618,
1481 .bq256xx_regmap_config = &bq25618_619_regmap_config,
1482 .bq256xx_get_ichg = bq25618_619_get_ichg_curr,
1483 .bq256xx_get_iindpm = bq256xx_get_input_curr_lim,
1484 .bq256xx_get_vbatreg = bq25618_619_get_chrg_volt,
1485 .bq256xx_get_iterm = bq25618_619_get_term_curr,
1486 .bq256xx_get_iprechg = bq25618_619_get_prechrg_curr,
1487 .bq256xx_get_vindpm = bq256xx_get_input_volt_lim,
1489 .bq256xx_set_ichg = bq25618_619_set_ichg_curr,
1490 .bq256xx_set_iindpm = bq256xx_set_input_curr_lim,
1491 .bq256xx_set_vbatreg = bq25618_619_set_chrg_volt,
1492 .bq256xx_set_iterm = bq25618_619_set_term_curr,
1493 .bq256xx_set_iprechg = bq25618_619_set_prechrg_curr,
1494 .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1495 .bq256xx_set_charge_type = bq256xx_set_charge_type,
1496 .bq256xx_set_ts_ignore = bq256xx_set_ts_ignore,
1498 .bq256xx_def_ichg = BQ25618_ICHG_DEF_uA,
1499 .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
1500 .bq256xx_def_vbatreg = BQ25618_VBATREG_DEF_uV,
1501 .bq256xx_def_iterm = BQ25618_ITERM_DEF_uA,
1502 .bq256xx_def_iprechg = BQ25618_IPRECHG_DEF_uA,
1503 .bq256xx_def_vindpm = BQ256XX_VINDPM_DEF_uV,
1505 .bq256xx_max_ichg = BQ25618_ICHG_MAX_uA,
1506 .bq256xx_max_vbatreg = BQ25618_VBATREG_MAX_uV,
1508 .has_usb_detect = false,
1512 .model_id = BQ25619,
1513 .bq256xx_regmap_config = &bq25618_619_regmap_config,
1514 .bq256xx_get_ichg = bq25618_619_get_ichg_curr,
1515 .bq256xx_get_iindpm = bq256xx_get_input_curr_lim,
1516 .bq256xx_get_vbatreg = bq25618_619_get_chrg_volt,
1517 .bq256xx_get_iterm = bq25618_619_get_term_curr,
1518 .bq256xx_get_iprechg = bq25618_619_get_prechrg_curr,
1519 .bq256xx_get_vindpm = bq256xx_get_input_volt_lim,
1521 .bq256xx_set_ichg = bq25618_619_set_ichg_curr,
1522 .bq256xx_set_iindpm = bq256xx_set_input_curr_lim,
1523 .bq256xx_set_vbatreg = bq25618_619_set_chrg_volt,
1524 .bq256xx_set_iterm = bq25618_619_set_term_curr,
1525 .bq256xx_set_iprechg = bq25618_619_set_prechrg_curr,
1526 .bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1527 .bq256xx_set_charge_type = bq256xx_set_charge_type,
1528 .bq256xx_set_ts_ignore = bq256xx_set_ts_ignore,
1530 .bq256xx_def_ichg = BQ25618_ICHG_DEF_uA,
1531 .bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
1532 .bq256xx_def_vbatreg = BQ25618_VBATREG_DEF_uV,
1533 .bq256xx_def_iterm = BQ25618_ITERM_DEF_uA,
1534 .bq256xx_def_iprechg = BQ25618_IPRECHG_DEF_uA,
1535 .bq256xx_def_vindpm = BQ256XX_VINDPM_DEF_uV,
1537 .bq256xx_max_ichg = BQ25618_ICHG_MAX_uA,
1538 .bq256xx_max_vbatreg = BQ25618_VBATREG_MAX_uV,
1540 .has_usb_detect = false,
1544 static int bq256xx_power_supply_init(struct bq256xx_device *bq,
1545 struct power_supply_config *psy_cfg, struct device *dev)
1547 bq->charger = devm_power_supply_register(bq->dev,
1548 &bq256xx_power_supply_desc,
1550 if (IS_ERR(bq->charger)) {
1551 dev_err(dev, "power supply register charger failed\n");
1552 return PTR_ERR(bq->charger);
1555 bq->battery = devm_power_supply_register(bq->dev,
1556 &bq256xx_battery_desc,
1558 if (IS_ERR(bq->battery)) {
1559 dev_err(dev, "power supply register battery failed\n");
1560 return PTR_ERR(bq->battery);
1565 static int bq256xx_hw_init(struct bq256xx_device *bq)
1567 struct power_supply_battery_info *bat_info;
1568 int wd_reg_val = BQ256XX_WATCHDOG_DIS;
1572 for (i = 0; i < BQ256XX_NUM_WD_VAL; i++) {
1573 if (bq->watchdog_timer == bq256xx_watchdog_time[i]) {
1577 if (bq->watchdog_timer > bq256xx_watchdog_time[i] &&
1578 bq->watchdog_timer < bq256xx_watchdog_time[i + 1])
1581 ret = regmap_update_bits(bq->regmap, BQ256XX_CHARGER_CONTROL_1,
1582 BQ256XX_WATCHDOG_MASK, wd_reg_val <<
1583 BQ256XX_WDT_BIT_SHIFT);
1585 ret = power_supply_get_battery_info(bq->charger, &bat_info);
1590 dev_warn(bq->dev, "battery info missing, default values will be applied\n");
1592 bat_info->constant_charge_current_max_ua =
1593 bq->chip_info->bq256xx_def_ichg;
1595 bat_info->constant_charge_voltage_max_uv =
1596 bq->chip_info->bq256xx_def_vbatreg;
1598 bat_info->precharge_current_ua =
1599 bq->chip_info->bq256xx_def_iprechg;
1601 bat_info->charge_term_current_ua =
1602 bq->chip_info->bq256xx_def_iterm;
1604 bq->init_data.ichg_max =
1605 bq->chip_info->bq256xx_max_ichg;
1607 bq->init_data.vbatreg_max =
1608 bq->chip_info->bq256xx_max_vbatreg;
1610 bq->init_data.ichg_max =
1611 bat_info->constant_charge_current_max_ua;
1613 bq->init_data.vbatreg_max =
1614 bat_info->constant_charge_voltage_max_uv;
1617 ret = bq->chip_info->bq256xx_set_vindpm(bq, bq->init_data.vindpm);
1621 ret = bq->chip_info->bq256xx_set_iindpm(bq, bq->init_data.iindpm);
1625 ret = bq->chip_info->bq256xx_set_ichg(bq,
1626 bq->chip_info->bq256xx_def_ichg);
1630 ret = bq->chip_info->bq256xx_set_iprechg(bq,
1631 bat_info->precharge_current_ua);
1635 ret = bq->chip_info->bq256xx_set_vbatreg(bq,
1636 bq->chip_info->bq256xx_def_vbatreg);
1640 ret = bq->chip_info->bq256xx_set_iterm(bq,
1641 bat_info->charge_term_current_ua);
1645 if (bq->chip_info->bq256xx_set_ts_ignore) {
1646 ret = bq->chip_info->bq256xx_set_ts_ignore(bq, bq->init_data.ts_ignore);
1651 power_supply_put_battery_info(bq->charger, bat_info);
1656 static int bq256xx_parse_dt(struct bq256xx_device *bq,
1657 struct power_supply_config *psy_cfg, struct device *dev)
1661 psy_cfg->drv_data = bq;
1662 psy_cfg->of_node = dev->of_node;
1664 ret = device_property_read_u32(bq->dev, "ti,watchdog-timeout-ms",
1665 &bq->watchdog_timer);
1667 bq->watchdog_timer = BQ256XX_WATCHDOG_DIS;
1669 if (bq->watchdog_timer > BQ256XX_WATCHDOG_MAX ||
1670 bq->watchdog_timer < BQ256XX_WATCHDOG_DIS)
1673 ret = device_property_read_u32(bq->dev,
1674 "input-voltage-limit-microvolt",
1675 &bq->init_data.vindpm);
1677 bq->init_data.vindpm = bq->chip_info->bq256xx_def_vindpm;
1679 ret = device_property_read_u32(bq->dev,
1680 "input-current-limit-microamp",
1681 &bq->init_data.iindpm);
1683 bq->init_data.iindpm = bq->chip_info->bq256xx_def_iindpm;
1685 bq->init_data.ts_ignore = device_property_read_bool(bq->dev, "ti,no-thermistor");
1690 static int bq256xx_probe(struct i2c_client *client)
1692 const struct i2c_device_id *id = i2c_client_get_device_id(client);
1693 struct device *dev = &client->dev;
1694 struct bq256xx_device *bq;
1695 struct power_supply_config psy_cfg = { };
1699 bq = devm_kzalloc(dev, sizeof(*bq), GFP_KERNEL);
1703 bq->client = client;
1705 bq->chip_info = &bq256xx_chip_info_tbl[id->driver_data];
1707 mutex_init(&bq->lock);
1709 strncpy(bq->model_name, id->name, I2C_NAME_SIZE);
1711 bq->regmap = devm_regmap_init_i2c(client,
1712 bq->chip_info->bq256xx_regmap_config);
1714 if (IS_ERR(bq->regmap)) {
1715 dev_err(dev, "Failed to allocate register map\n");
1716 return PTR_ERR(bq->regmap);
1719 i2c_set_clientdata(client, bq);
1721 ret = bq256xx_parse_dt(bq, &psy_cfg, dev);
1723 dev_err(dev, "Failed to read device tree properties%d\n", ret);
1727 ret = devm_add_action_or_reset(dev, bq256xx_charger_reset, bq);
1732 bq->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
1733 if (!IS_ERR_OR_NULL(bq->usb2_phy)) {
1734 INIT_WORK(&bq->usb_work, bq256xx_usb_work);
1735 bq->usb_nb.notifier_call = bq256xx_usb_notifier;
1736 usb_register_notifier(bq->usb2_phy, &bq->usb_nb);
1739 bq->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
1740 if (!IS_ERR_OR_NULL(bq->usb3_phy)) {
1741 INIT_WORK(&bq->usb_work, bq256xx_usb_work);
1742 bq->usb_nb.notifier_call = bq256xx_usb_notifier;
1743 usb_register_notifier(bq->usb3_phy, &bq->usb_nb);
1747 ret = devm_request_threaded_irq(dev, client->irq, NULL,
1748 bq256xx_irq_handler_thread,
1749 IRQF_TRIGGER_FALLING |
1751 dev_name(&client->dev), bq);
1753 dev_err(dev, "get irq fail: %d\n", ret);
1758 ret = bq256xx_power_supply_init(bq, &psy_cfg, dev);
1760 dev_err(dev, "Failed to register power supply\n");
1764 ret = bq256xx_hw_init(bq);
1766 dev_err(dev, "Cannot initialize the chip.\n");
1773 static const struct i2c_device_id bq256xx_i2c_ids[] = {
1774 { "bq25600", BQ25600 },
1775 { "bq25600d", BQ25600D },
1776 { "bq25601", BQ25601 },
1777 { "bq25601d", BQ25601D },
1778 { "bq25611d", BQ25611D },
1779 { "bq25618", BQ25618 },
1780 { "bq25619", BQ25619 },
1783 MODULE_DEVICE_TABLE(i2c, bq256xx_i2c_ids);
1785 static const struct of_device_id bq256xx_of_match[] = {
1786 { .compatible = "ti,bq25600", .data = (void *)BQ25600 },
1787 { .compatible = "ti,bq25600d", .data = (void *)BQ25600D },
1788 { .compatible = "ti,bq25601", .data = (void *)BQ25601 },
1789 { .compatible = "ti,bq25601d", .data = (void *)BQ25601D },
1790 { .compatible = "ti,bq25611d", .data = (void *)BQ25611D },
1791 { .compatible = "ti,bq25618", .data = (void *)BQ25618 },
1792 { .compatible = "ti,bq25619", .data = (void *)BQ25619 },
1795 MODULE_DEVICE_TABLE(of, bq256xx_of_match);
1797 static const struct acpi_device_id bq256xx_acpi_match[] = {
1798 { "bq25600", BQ25600 },
1799 { "bq25600d", BQ25600D },
1800 { "bq25601", BQ25601 },
1801 { "bq25601d", BQ25601D },
1802 { "bq25611d", BQ25611D },
1803 { "bq25618", BQ25618 },
1804 { "bq25619", BQ25619 },
1807 MODULE_DEVICE_TABLE(acpi, bq256xx_acpi_match);
1809 static struct i2c_driver bq256xx_driver = {
1811 .name = "bq256xx-charger",
1812 .of_match_table = bq256xx_of_match,
1813 .acpi_match_table = bq256xx_acpi_match,
1815 .probe = bq256xx_probe,
1816 .id_table = bq256xx_i2c_ids,
1818 module_i2c_driver(bq256xx_driver);
1820 MODULE_AUTHOR("Ricardo Rivera-Matos <r-rivera-matos@ti.com>");
1821 MODULE_DESCRIPTION("bq256xx charger driver");
1822 MODULE_LICENSE("GPL v2");