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 int bq256xx_array_parse(int array_size
, int val
, const int array
[])
344 if (val
>= array
[array_size
- 1])
345 return array_size
- 1;
347 for (i
= 1; i
< array_size
; i
++) {
351 if (val
> array
[i
- 1] && val
< array
[i
]) {
361 static int bq256xx_usb_notifier(struct notifier_block
*nb
, unsigned long val
,
364 struct bq256xx_device
*bq
=
365 container_of(nb
, struct bq256xx_device
, usb_nb
);
368 queue_work(system_power_efficient_wq
, &bq
->usb_work
);
373 static void bq256xx_usb_work(struct work_struct
*data
)
375 struct bq256xx_device
*bq
=
376 container_of(data
, struct bq256xx_device
, usb_work
);
378 switch (bq
->usb_event
) {
382 power_supply_changed(bq
->charger
);
385 dev_err(bq
->dev
, "Error switching to charger mode.\n");
390 static struct reg_default bq2560x_reg_defs
[] = {
391 {BQ256XX_INPUT_CURRENT_LIMIT
, 0x17},
392 {BQ256XX_CHARGER_CONTROL_0
, 0x1a},
393 {BQ256XX_CHARGE_CURRENT_LIMIT
, 0xa2},
394 {BQ256XX_PRECHG_AND_TERM_CURR_LIM
, 0x22},
395 {BQ256XX_BATTERY_VOLTAGE_LIMIT
, 0x58},
396 {BQ256XX_CHARGER_CONTROL_1
, 0x9f},
397 {BQ256XX_CHARGER_CONTROL_2
, 0x66},
398 {BQ256XX_CHARGER_CONTROL_3
, 0x4c},
401 static struct reg_default bq25611d_reg_defs
[] = {
402 {BQ256XX_INPUT_CURRENT_LIMIT
, 0x17},
403 {BQ256XX_CHARGER_CONTROL_0
, 0x1a},
404 {BQ256XX_CHARGE_CURRENT_LIMIT
, 0x91},
405 {BQ256XX_PRECHG_AND_TERM_CURR_LIM
, 0x12},
406 {BQ256XX_BATTERY_VOLTAGE_LIMIT
, 0x40},
407 {BQ256XX_CHARGER_CONTROL_1
, 0x9e},
408 {BQ256XX_CHARGER_CONTROL_2
, 0xe6},
409 {BQ256XX_CHARGER_CONTROL_3
, 0x4c},
410 {BQ256XX_PART_INFORMATION
, 0x54},
411 {BQ256XX_CHARGER_CONTROL_4
, 0x75},
414 static struct reg_default bq25618_619_reg_defs
[] = {
415 {BQ256XX_INPUT_CURRENT_LIMIT
, 0x17},
416 {BQ256XX_CHARGER_CONTROL_0
, 0x1a},
417 {BQ256XX_CHARGE_CURRENT_LIMIT
, 0x91},
418 {BQ256XX_PRECHG_AND_TERM_CURR_LIM
, 0x12},
419 {BQ256XX_BATTERY_VOLTAGE_LIMIT
, 0x40},
420 {BQ256XX_CHARGER_CONTROL_1
, 0x9e},
421 {BQ256XX_CHARGER_CONTROL_2
, 0xe6},
422 {BQ256XX_CHARGER_CONTROL_3
, 0x4c},
423 {BQ256XX_PART_INFORMATION
, 0x2c},
424 {BQ256XX_CHARGER_CONTROL_4
, 0x75},
427 static int bq256xx_get_state(struct bq256xx_device
*bq
,
428 struct bq256xx_state
*state
)
430 unsigned int charger_status_0
;
431 unsigned int charger_status_1
;
434 ret
= regmap_read(bq
->regmap
, BQ256XX_CHARGER_STATUS_0
,
439 ret
= regmap_read(bq
->regmap
, BQ256XX_CHARGER_STATUS_1
,
444 state
->vbus_stat
= charger_status_0
& BQ256XX_VBUS_STAT_MASK
;
445 state
->chrg_stat
= charger_status_0
& BQ256XX_CHRG_STAT_MASK
;
446 state
->online
= charger_status_0
& BQ256XX_PG_STAT_MASK
;
448 state
->wdt_fault
= charger_status_1
& BQ256XX_WDT_FAULT_MASK
;
449 state
->bat_fault
= charger_status_1
& BQ256XX_BAT_FAULT_MASK
;
450 state
->chrg_fault
= charger_status_1
& BQ256XX_CHRG_FAULT_MASK
;
451 state
->ntc_fault
= charger_status_1
& BQ256XX_NTC_FAULT_MASK
;
456 static int bq256xx_set_charge_type(struct bq256xx_device
*bq
, int type
)
461 case POWER_SUPPLY_CHARGE_TYPE_NONE
:
464 case POWER_SUPPLY_CHARGE_TYPE_TRICKLE
:
465 case POWER_SUPPLY_CHARGE_TYPE_FAST
:
472 return regmap_update_bits(bq
->regmap
, BQ256XX_CHARGER_CONTROL_0
,
473 BQ256XX_CHG_CONFIG_MASK
,
474 (chg_config
? 1 : 0) << BQ256XX_CHG_CONFIG_BIT_SHIFT
);
477 static int bq256xx_get_ichg_curr(struct bq256xx_device
*bq
)
479 unsigned int charge_current_limit
;
480 unsigned int ichg_reg_code
;
483 ret
= regmap_read(bq
->regmap
, BQ256XX_CHARGE_CURRENT_LIMIT
,
484 &charge_current_limit
);
488 ichg_reg_code
= charge_current_limit
& BQ256XX_ICHG_MASK
;
490 return ichg_reg_code
* BQ256XX_ICHG_STEP_uA
;
493 static int bq25618_619_get_ichg_curr(struct bq256xx_device
*bq
)
495 unsigned int charge_current_limit
;
496 unsigned int ichg_reg_code
;
499 ret
= regmap_read(bq
->regmap
, BQ256XX_CHARGE_CURRENT_LIMIT
,
500 &charge_current_limit
);
504 ichg_reg_code
= charge_current_limit
& BQ256XX_ICHG_MASK
;
506 if (ichg_reg_code
< BQ25618_ICHG_THRESH
)
507 return ichg_reg_code
* BQ25618_ICHG_STEP_uA
;
509 return bq25618_619_ichg_values
[ichg_reg_code
- BQ25618_ICHG_THRESH
];
512 static int bq256xx_set_ichg_curr(struct bq256xx_device
*bq
, int ichg
)
514 unsigned int ichg_reg_code
;
515 int ichg_max
= bq
->init_data
.ichg_max
;
517 ichg
= clamp(ichg
, BQ256XX_ICHG_MIN_uA
, ichg_max
);
518 ichg_reg_code
= ichg
/ BQ256XX_ICHG_STEP_uA
;
520 return regmap_update_bits(bq
->regmap
, BQ256XX_CHARGE_CURRENT_LIMIT
,
521 BQ256XX_ICHG_MASK
, ichg_reg_code
);
524 static int bq25618_619_set_ichg_curr(struct bq256xx_device
*bq
, int ichg
)
526 int array_size
= ARRAY_SIZE(bq25618_619_ichg_values
);
527 unsigned int ichg_reg_code
;
528 int ichg_max
= bq
->init_data
.ichg_max
;
530 ichg
= clamp(ichg
, BQ25618_ICHG_MIN_uA
, ichg_max
);
532 if (ichg
<= BQ25618_ICHG_THRESH_uA
) {
533 ichg_reg_code
= ichg
/ BQ25618_ICHG_STEP_uA
;
535 ichg_reg_code
= bq256xx_array_parse(array_size
, ichg
,
536 bq25618_619_ichg_values
) + BQ25618_ICHG_THRESH
;
539 return regmap_update_bits(bq
->regmap
, BQ256XX_CHARGE_CURRENT_LIMIT
,
540 BQ256XX_ICHG_MASK
, ichg_reg_code
);
543 static int bq25618_619_get_chrg_volt(struct bq256xx_device
*bq
)
545 unsigned int battery_volt_lim
;
546 unsigned int vbatreg_reg_code
;
549 ret
= regmap_read(bq
->regmap
, BQ256XX_BATTERY_VOLTAGE_LIMIT
,
555 vbatreg_reg_code
= (battery_volt_lim
& BQ256XX_VBATREG_MASK
) >>
556 BQ256XX_VBATREG_BIT_SHIFT
;
558 if (vbatreg_reg_code
> BQ2561X_VBATREG_THRESH
)
559 return ((vbatreg_reg_code
- BQ2561X_VBATREG_THRESH
) *
560 BQ2561X_VBATREG_STEP_uV
) +
561 BQ25618_VBATREG_THRESH_uV
;
563 return bq25618_619_vbatreg_values
[vbatreg_reg_code
];
566 static int bq25611d_get_chrg_volt(struct bq256xx_device
*bq
)
568 unsigned int battery_volt_lim
;
569 unsigned int vbatreg_reg_code
;
572 ret
= regmap_read(bq
->regmap
, BQ256XX_BATTERY_VOLTAGE_LIMIT
,
577 vbatreg_reg_code
= (battery_volt_lim
& BQ256XX_VBATREG_MASK
) >>
578 BQ256XX_VBATREG_BIT_SHIFT
;
580 if (vbatreg_reg_code
> BQ2561X_VBATREG_THRESH
)
581 return ((vbatreg_reg_code
- BQ2561X_VBATREG_THRESH
) *
582 BQ2561X_VBATREG_STEP_uV
) +
583 BQ25611D_VBATREG_THRESH_uV
;
585 return bq25611d_vbatreg_values
[vbatreg_reg_code
];
588 static int bq2560x_get_chrg_volt(struct bq256xx_device
*bq
)
590 unsigned int battery_volt_lim
;
591 unsigned int vbatreg_reg_code
;
594 ret
= regmap_read(bq
->regmap
, BQ256XX_BATTERY_VOLTAGE_LIMIT
,
599 vbatreg_reg_code
= (battery_volt_lim
& BQ256XX_VBATREG_MASK
) >>
600 BQ256XX_VBATREG_BIT_SHIFT
;
602 return (vbatreg_reg_code
* BQ2560X_VBATREG_STEP_uV
)
603 + BQ2560X_VBATREG_OFFSET_uV
;
606 static int bq25601d_get_chrg_volt(struct bq256xx_device
*bq
)
608 unsigned int battery_volt_lim
;
609 unsigned int vbatreg_reg_code
;
612 ret
= regmap_read(bq
->regmap
, BQ256XX_BATTERY_VOLTAGE_LIMIT
,
617 vbatreg_reg_code
= (battery_volt_lim
& BQ256XX_VBATREG_MASK
) >>
618 BQ256XX_VBATREG_BIT_SHIFT
;
620 return (vbatreg_reg_code
* BQ2560X_VBATREG_STEP_uV
)
621 + BQ25601D_VBATREG_OFFSET_uV
;
624 static int bq25618_619_set_chrg_volt(struct bq256xx_device
*bq
, int vbatreg
)
626 int array_size
= ARRAY_SIZE(bq25618_619_vbatreg_values
);
627 unsigned int vbatreg_reg_code
;
628 int vbatreg_max
= bq
->init_data
.vbatreg_max
;
630 vbatreg
= clamp(vbatreg
, BQ25618_VBATREG_MIN_uV
, vbatreg_max
);
632 if (vbatreg
> BQ25618_VBATREG_THRESH_uV
)
633 vbatreg_reg_code
= ((vbatreg
-
634 BQ25618_VBATREG_THRESH_uV
) /
635 (BQ2561X_VBATREG_STEP_uV
)) + BQ2561X_VBATREG_THRESH
;
637 vbatreg_reg_code
= bq256xx_array_parse(array_size
, vbatreg
,
638 bq25618_619_vbatreg_values
);
641 return regmap_update_bits(bq
->regmap
, BQ256XX_BATTERY_VOLTAGE_LIMIT
,
642 BQ256XX_VBATREG_MASK
, vbatreg_reg_code
<<
643 BQ256XX_VBATREG_BIT_SHIFT
);
646 static int bq25611d_set_chrg_volt(struct bq256xx_device
*bq
, int vbatreg
)
648 int array_size
= ARRAY_SIZE(bq25611d_vbatreg_values
);
649 unsigned int vbatreg_reg_code
;
650 int vbatreg_max
= bq
->init_data
.vbatreg_max
;
652 vbatreg
= clamp(vbatreg
, BQ25611D_VBATREG_MIN_uV
, vbatreg_max
);
654 if (vbatreg
> BQ25611D_VBATREG_THRESH_uV
)
655 vbatreg_reg_code
= ((vbatreg
-
656 BQ25611D_VBATREG_THRESH_uV
) /
657 (BQ2561X_VBATREG_STEP_uV
)) + BQ2561X_VBATREG_THRESH
;
659 vbatreg_reg_code
= bq256xx_array_parse(array_size
, vbatreg
,
660 bq25611d_vbatreg_values
);
663 return regmap_update_bits(bq
->regmap
, BQ256XX_BATTERY_VOLTAGE_LIMIT
,
664 BQ256XX_VBATREG_MASK
, vbatreg_reg_code
<<
665 BQ256XX_VBATREG_BIT_SHIFT
);
668 static int bq2560x_set_chrg_volt(struct bq256xx_device
*bq
, int vbatreg
)
670 unsigned int vbatreg_reg_code
;
671 int vbatreg_max
= bq
->init_data
.vbatreg_max
;
673 vbatreg
= clamp(vbatreg
, BQ2560X_VBATREG_MIN_uV
, vbatreg_max
);
675 vbatreg_reg_code
= (vbatreg
- BQ2560X_VBATREG_OFFSET_uV
) /
676 BQ2560X_VBATREG_STEP_uV
;
678 return regmap_update_bits(bq
->regmap
, BQ256XX_BATTERY_VOLTAGE_LIMIT
,
679 BQ256XX_VBATREG_MASK
, vbatreg_reg_code
<<
680 BQ256XX_VBATREG_BIT_SHIFT
);
683 static int bq25601d_set_chrg_volt(struct bq256xx_device
*bq
, int vbatreg
)
685 unsigned int vbatreg_reg_code
;
686 int vbatreg_max
= bq
->init_data
.vbatreg_max
;
688 vbatreg
= clamp(vbatreg
, BQ25601D_VBATREG_MIN_uV
, vbatreg_max
);
690 vbatreg_reg_code
= (vbatreg
- BQ25601D_VBATREG_OFFSET_uV
) /
691 BQ2560X_VBATREG_STEP_uV
;
693 return regmap_update_bits(bq
->regmap
, BQ256XX_BATTERY_VOLTAGE_LIMIT
,
694 BQ256XX_VBATREG_MASK
, vbatreg_reg_code
<<
695 BQ256XX_VBATREG_BIT_SHIFT
);
698 static int bq256xx_set_ts_ignore(struct bq256xx_device
*bq
, bool ts_ignore
)
700 return regmap_update_bits(bq
->regmap
, BQ256XX_INPUT_CURRENT_LIMIT
,
701 BQ256XX_TS_IGNORE
, (ts_ignore
? 1 : 0) << BQ256XX_TS_IGNORE_SHIFT
);
704 static int bq256xx_get_prechrg_curr(struct bq256xx_device
*bq
)
706 unsigned int prechg_and_term_curr_lim
;
707 unsigned int iprechg_reg_code
;
710 ret
= regmap_read(bq
->regmap
, BQ256XX_PRECHG_AND_TERM_CURR_LIM
,
711 &prechg_and_term_curr_lim
);
715 iprechg_reg_code
= (prechg_and_term_curr_lim
& BQ256XX_IPRECHG_MASK
)
716 >> BQ256XX_IPRECHG_BIT_SHIFT
;
718 return (iprechg_reg_code
* BQ256XX_IPRECHG_STEP_uA
) +
719 BQ256XX_IPRECHG_OFFSET_uA
;
722 static int bq256xx_set_prechrg_curr(struct bq256xx_device
*bq
, int iprechg
)
724 unsigned int iprechg_reg_code
;
726 iprechg
= clamp(iprechg
, BQ256XX_IPRECHG_MIN_uA
,
727 BQ256XX_IPRECHG_MAX_uA
);
729 iprechg_reg_code
= ((iprechg
- BQ256XX_IPRECHG_OFFSET_uA
) /
730 BQ256XX_IPRECHG_STEP_uA
) << BQ256XX_IPRECHG_BIT_SHIFT
;
732 return regmap_update_bits(bq
->regmap
, BQ256XX_PRECHG_AND_TERM_CURR_LIM
,
733 BQ256XX_IPRECHG_MASK
, iprechg_reg_code
);
736 static int bq25618_619_get_prechrg_curr(struct bq256xx_device
*bq
)
738 unsigned int prechg_and_term_curr_lim
;
739 unsigned int iprechg_reg_code
;
742 ret
= regmap_read(bq
->regmap
, BQ256XX_PRECHG_AND_TERM_CURR_LIM
,
743 &prechg_and_term_curr_lim
);
747 iprechg_reg_code
= (prechg_and_term_curr_lim
& BQ256XX_IPRECHG_MASK
)
748 >> BQ256XX_IPRECHG_BIT_SHIFT
;
750 return (iprechg_reg_code
* BQ25618_IPRECHG_STEP_uA
) +
751 BQ25618_IPRECHG_OFFSET_uA
;
754 static int bq25618_619_set_prechrg_curr(struct bq256xx_device
*bq
, int iprechg
)
756 unsigned int iprechg_reg_code
;
758 iprechg
= clamp(iprechg
, BQ25618_IPRECHG_MIN_uA
,
759 BQ25618_IPRECHG_MAX_uA
);
761 iprechg_reg_code
= ((iprechg
- BQ25618_IPRECHG_OFFSET_uA
) /
762 BQ25618_IPRECHG_STEP_uA
) << BQ256XX_IPRECHG_BIT_SHIFT
;
764 return regmap_update_bits(bq
->regmap
, BQ256XX_PRECHG_AND_TERM_CURR_LIM
,
765 BQ256XX_IPRECHG_MASK
, iprechg_reg_code
);
768 static int bq256xx_get_term_curr(struct bq256xx_device
*bq
)
770 unsigned int prechg_and_term_curr_lim
;
771 unsigned int iterm_reg_code
;
774 ret
= regmap_read(bq
->regmap
, BQ256XX_PRECHG_AND_TERM_CURR_LIM
,
775 &prechg_and_term_curr_lim
);
779 iterm_reg_code
= prechg_and_term_curr_lim
& BQ256XX_ITERM_MASK
;
781 return (iterm_reg_code
* BQ256XX_ITERM_STEP_uA
) +
782 BQ256XX_ITERM_OFFSET_uA
;
785 static int bq256xx_set_term_curr(struct bq256xx_device
*bq
, int iterm
)
787 unsigned int iterm_reg_code
;
789 iterm
= clamp(iterm
, BQ256XX_ITERM_MIN_uA
, BQ256XX_ITERM_MAX_uA
);
791 iterm_reg_code
= (iterm
- BQ256XX_ITERM_OFFSET_uA
) /
792 BQ256XX_ITERM_STEP_uA
;
794 return regmap_update_bits(bq
->regmap
, BQ256XX_PRECHG_AND_TERM_CURR_LIM
,
795 BQ256XX_ITERM_MASK
, iterm_reg_code
);
798 static int bq25618_619_get_term_curr(struct bq256xx_device
*bq
)
800 unsigned int prechg_and_term_curr_lim
;
801 unsigned int iterm_reg_code
;
804 ret
= regmap_read(bq
->regmap
, BQ256XX_PRECHG_AND_TERM_CURR_LIM
,
805 &prechg_and_term_curr_lim
);
809 iterm_reg_code
= prechg_and_term_curr_lim
& BQ256XX_ITERM_MASK
;
811 return (iterm_reg_code
* BQ25618_ITERM_STEP_uA
) +
812 BQ25618_ITERM_OFFSET_uA
;
815 static int bq25618_619_set_term_curr(struct bq256xx_device
*bq
, int iterm
)
817 unsigned int iterm_reg_code
;
819 iterm
= clamp(iterm
, BQ25618_ITERM_MIN_uA
, BQ25618_ITERM_MAX_uA
);
821 iterm_reg_code
= (iterm
- BQ25618_ITERM_OFFSET_uA
) /
822 BQ25618_ITERM_STEP_uA
;
824 return regmap_update_bits(bq
->regmap
, BQ256XX_PRECHG_AND_TERM_CURR_LIM
,
825 BQ256XX_ITERM_MASK
, iterm_reg_code
);
828 static int bq256xx_get_input_volt_lim(struct bq256xx_device
*bq
)
830 unsigned int charger_control_2
;
831 unsigned int vindpm_reg_code
;
834 ret
= regmap_read(bq
->regmap
, BQ256XX_CHARGER_CONTROL_2
,
839 vindpm_reg_code
= charger_control_2
& BQ256XX_VINDPM_MASK
;
841 return (vindpm_reg_code
* BQ256XX_VINDPM_STEP_uV
) +
842 BQ256XX_VINDPM_OFFSET_uV
;
845 static int bq256xx_set_input_volt_lim(struct bq256xx_device
*bq
, int vindpm
)
847 unsigned int vindpm_reg_code
;
849 vindpm
= clamp(vindpm
, BQ256XX_VINDPM_MIN_uV
, BQ256XX_VINDPM_MAX_uV
);
851 vindpm_reg_code
= (vindpm
- BQ256XX_VINDPM_OFFSET_uV
) /
852 BQ256XX_VINDPM_STEP_uV
;
854 return regmap_update_bits(bq
->regmap
, BQ256XX_CHARGER_CONTROL_2
,
855 BQ256XX_VINDPM_MASK
, vindpm_reg_code
);
858 static int bq256xx_get_input_curr_lim(struct bq256xx_device
*bq
)
860 unsigned int input_current_limit
;
861 unsigned int iindpm_reg_code
;
864 ret
= regmap_read(bq
->regmap
, BQ256XX_INPUT_CURRENT_LIMIT
,
865 &input_current_limit
);
869 iindpm_reg_code
= input_current_limit
& BQ256XX_IINDPM_MASK
;
871 return (iindpm_reg_code
* BQ256XX_IINDPM_STEP_uA
) +
872 BQ256XX_IINDPM_OFFSET_uA
;
875 static int bq256xx_set_input_curr_lim(struct bq256xx_device
*bq
, int iindpm
)
877 unsigned int iindpm_reg_code
;
879 iindpm
= clamp(iindpm
, BQ256XX_IINDPM_MIN_uA
, BQ256XX_IINDPM_MAX_uA
);
881 iindpm_reg_code
= (iindpm
- BQ256XX_IINDPM_OFFSET_uA
) /
882 BQ256XX_IINDPM_STEP_uA
;
884 return regmap_update_bits(bq
->regmap
, BQ256XX_INPUT_CURRENT_LIMIT
,
885 BQ256XX_IINDPM_MASK
, iindpm_reg_code
);
888 static void bq256xx_charger_reset(void *data
)
890 struct bq256xx_device
*bq
= data
;
892 regmap_update_bits(bq
->regmap
, BQ256XX_PART_INFORMATION
,
893 BQ256XX_REG_RST
, BQ256XX_REG_RST
);
895 if (!IS_ERR_OR_NULL(bq
->usb2_phy
))
896 usb_unregister_notifier(bq
->usb2_phy
, &bq
->usb_nb
);
898 if (!IS_ERR_OR_NULL(bq
->usb3_phy
))
899 usb_unregister_notifier(bq
->usb3_phy
, &bq
->usb_nb
);
902 static int bq256xx_set_charger_property(struct power_supply
*psy
,
903 enum power_supply_property prop
,
904 const union power_supply_propval
*val
)
906 struct bq256xx_device
*bq
= power_supply_get_drvdata(psy
);
910 case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT
:
911 ret
= bq
->chip_info
->bq256xx_set_iindpm(bq
, val
->intval
);
916 case POWER_SUPPLY_PROP_STATUS
:
919 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE
:
920 ret
= bq
->chip_info
->bq256xx_set_vbatreg(bq
, val
->intval
);
925 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT
:
926 ret
= bq
->chip_info
->bq256xx_set_ichg(bq
, val
->intval
);
931 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT
:
932 ret
= bq
->chip_info
->bq256xx_set_iprechg(bq
, val
->intval
);
937 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT
:
938 ret
= bq
->chip_info
->bq256xx_set_iterm(bq
, val
->intval
);
943 case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT
:
944 ret
= bq
->chip_info
->bq256xx_set_vindpm(bq
, val
->intval
);
949 case POWER_SUPPLY_PROP_CHARGE_TYPE
:
950 ret
= bq
->chip_info
->bq256xx_set_charge_type(bq
, val
->intval
);
963 static int bq256xx_get_battery_property(struct power_supply
*psy
,
964 enum power_supply_property psp
,
965 union power_supply_propval
*val
)
967 struct bq256xx_device
*bq
= power_supply_get_drvdata(psy
);
970 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX
:
971 val
->intval
= bq
->init_data
.ichg_max
;
974 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX
:
975 val
->intval
= bq
->init_data
.vbatreg_max
;
985 static int bq256xx_get_charger_property(struct power_supply
*psy
,
986 enum power_supply_property psp
,
987 union power_supply_propval
*val
)
989 struct bq256xx_device
*bq
= power_supply_get_drvdata(psy
);
990 struct bq256xx_state state
;
993 mutex_lock(&bq
->lock
);
994 ret
= bq256xx_get_state(bq
, &state
);
995 mutex_unlock(&bq
->lock
);
1000 case POWER_SUPPLY_PROP_STATUS
:
1001 if (state
.vbus_stat
== BQ256XX_VBUS_STAT_NO_INPUT
||
1002 state
.vbus_stat
== BQ256XX_VBUS_STAT_USB_OTG
)
1003 val
->intval
= POWER_SUPPLY_STATUS_DISCHARGING
;
1004 else if (state
.chrg_stat
== BQ256XX_CHRG_STAT_NOT_CHRGING
)
1005 val
->intval
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
1006 else if (state
.chrg_stat
== BQ256XX_CHRG_STAT_CHRG_TERM
)
1007 val
->intval
= POWER_SUPPLY_STATUS_FULL
;
1009 val
->intval
= POWER_SUPPLY_STATUS_CHARGING
;
1012 case POWER_SUPPLY_PROP_HEALTH
:
1013 val
->intval
= POWER_SUPPLY_HEALTH_UNKNOWN
;
1014 if (state
.wdt_fault
) {
1016 POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE
;
1017 } else if (state
.bat_fault
) {
1018 val
->intval
= POWER_SUPPLY_HEALTH_OVERVOLTAGE
;
1020 switch (state
.chrg_stat
) {
1021 case BQ256XX_CHRG_FAULT_INPUT
:
1023 POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
;
1025 case BQ256XX_CHRG_FAULT_THERM
:
1026 val
->intval
= POWER_SUPPLY_HEALTH_OVERHEAT
;
1028 case BQ256XX_CHRG_FAULT_CST_EXPIRE
:
1030 POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE
;
1036 switch (state
.ntc_fault
) {
1037 case BQ256XX_NTC_FAULT_WARM
:
1038 val
->intval
= POWER_SUPPLY_HEALTH_WARM
;
1040 case BQ256XX_NTC_FAULT_COOL
:
1041 val
->intval
= POWER_SUPPLY_HEALTH_COOL
;
1043 case BQ256XX_NTC_FAULT_COLD
:
1044 val
->intval
= POWER_SUPPLY_HEALTH_COLD
;
1046 case BQ256XX_NTC_FAULT_HOT
:
1047 val
->intval
= POWER_SUPPLY_HEALTH_HOT
;
1050 val
->intval
= POWER_SUPPLY_HEALTH_GOOD
;
1056 case POWER_SUPPLY_PROP_USB_TYPE
:
1057 if (bq
->chip_info
->has_usb_detect
) {
1058 switch (state
.vbus_stat
) {
1059 case BQ256XX_VBUS_STAT_USB_SDP
:
1060 val
->intval
= POWER_SUPPLY_USB_TYPE_SDP
;
1062 case BQ256XX_VBUS_STAT_USB_CDP
:
1063 val
->intval
= POWER_SUPPLY_USB_TYPE_CDP
;
1065 case BQ256XX_VBUS_STAT_USB_DCP
:
1066 val
->intval
= POWER_SUPPLY_USB_TYPE_DCP
;
1068 case BQ256XX_VBUS_STAT_USB_OTG
:
1069 val
->intval
= POWER_SUPPLY_USB_TYPE_ACA
;
1072 val
->intval
= POWER_SUPPLY_USB_TYPE_UNKNOWN
;
1076 switch (state
.vbus_stat
) {
1077 case BQ256XX_VBUS_STAT_USB_SDP
:
1078 val
->intval
= POWER_SUPPLY_USB_TYPE_SDP
;
1080 case BQ256XX_VBUS_STAT_USB_OTG
:
1081 val
->intval
= POWER_SUPPLY_USB_TYPE_ACA
;
1084 val
->intval
= POWER_SUPPLY_USB_TYPE_UNKNOWN
;
1090 case POWER_SUPPLY_PROP_CHARGE_TYPE
:
1091 switch (state
.chrg_stat
) {
1092 case BQ256XX_CHRG_STAT_NOT_CHRGING
:
1093 val
->intval
= POWER_SUPPLY_CHARGE_TYPE_NONE
;
1095 case BQ256XX_CHRG_STAT_PRECHRGING
:
1096 val
->intval
= POWER_SUPPLY_CHARGE_TYPE_TRICKLE
;
1098 case BQ256XX_CHRG_STAT_FAST_CHRGING
:
1099 val
->intval
= POWER_SUPPLY_CHARGE_TYPE_FAST
;
1101 case BQ256XX_CHRG_STAT_CHRG_TERM
:
1102 val
->intval
= POWER_SUPPLY_CHARGE_TYPE_TRICKLE
;
1105 val
->intval
= POWER_SUPPLY_CHARGE_TYPE_UNKNOWN
;
1109 case POWER_SUPPLY_PROP_MANUFACTURER
:
1110 val
->strval
= BQ256XX_MANUFACTURER
;
1113 case POWER_SUPPLY_PROP_MODEL_NAME
:
1114 val
->strval
= bq
->model_name
;
1117 case POWER_SUPPLY_PROP_ONLINE
:
1118 val
->intval
= state
.online
;
1121 case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT
:
1122 ret
= bq
->chip_info
->bq256xx_get_vindpm(bq
);
1128 case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT
:
1129 ret
= bq
->chip_info
->bq256xx_get_iindpm(bq
);
1135 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE
:
1136 ret
= bq
->chip_info
->bq256xx_get_vbatreg(bq
);
1142 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT
:
1143 ret
= bq
->chip_info
->bq256xx_get_ichg(bq
);
1149 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT
:
1150 ret
= bq
->chip_info
->bq256xx_get_iprechg(bq
);
1156 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT
:
1157 ret
= bq
->chip_info
->bq256xx_get_iterm(bq
);
1170 static bool bq256xx_state_changed(struct bq256xx_device
*bq
,
1171 struct bq256xx_state
*new_state
)
1173 struct bq256xx_state old_state
;
1175 mutex_lock(&bq
->lock
);
1176 old_state
= bq
->state
;
1177 mutex_unlock(&bq
->lock
);
1179 return memcmp(&old_state
, new_state
, sizeof(struct bq256xx_state
)) != 0;
1182 static irqreturn_t
bq256xx_irq_handler_thread(int irq
, void *private)
1184 struct bq256xx_device
*bq
= private;
1185 struct bq256xx_state state
;
1188 ret
= bq256xx_get_state(bq
, &state
);
1192 if (!bq256xx_state_changed(bq
, &state
))
1195 mutex_lock(&bq
->lock
);
1197 mutex_unlock(&bq
->lock
);
1199 power_supply_changed(bq
->charger
);
1205 static enum power_supply_property bq256xx_power_supply_props
[] = {
1206 POWER_SUPPLY_PROP_MANUFACTURER
,
1207 POWER_SUPPLY_PROP_MODEL_NAME
,
1208 POWER_SUPPLY_PROP_STATUS
,
1209 POWER_SUPPLY_PROP_ONLINE
,
1210 POWER_SUPPLY_PROP_HEALTH
,
1211 POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT
,
1212 POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT
,
1213 POWER_SUPPLY_PROP_CHARGE_TYPE
,
1214 POWER_SUPPLY_PROP_USB_TYPE
,
1215 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT
,
1216 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE
,
1217 POWER_SUPPLY_PROP_PRECHARGE_CURRENT
,
1218 POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT
,
1221 static enum power_supply_property bq256xx_battery_props
[] = {
1222 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX
,
1223 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX
,
1226 static int bq256xx_property_is_writeable(struct power_supply
*psy
,
1227 enum power_supply_property prop
)
1230 case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT
:
1231 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE
:
1232 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT
:
1233 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT
:
1234 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT
:
1235 case POWER_SUPPLY_PROP_STATUS
:
1236 case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT
:
1237 case POWER_SUPPLY_PROP_CHARGE_TYPE
:
1244 static const struct power_supply_desc bq256xx_power_supply_desc
= {
1245 .name
= "bq256xx-charger",
1246 .type
= POWER_SUPPLY_TYPE_USB
,
1247 .usb_types
= BIT(POWER_SUPPLY_USB_TYPE_SDP
) |
1248 BIT(POWER_SUPPLY_USB_TYPE_CDP
) |
1249 BIT(POWER_SUPPLY_USB_TYPE_DCP
) |
1250 BIT(POWER_SUPPLY_USB_TYPE_ACA
) |
1251 BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN
),
1252 .properties
= bq256xx_power_supply_props
,
1253 .num_properties
= ARRAY_SIZE(bq256xx_power_supply_props
),
1254 .get_property
= bq256xx_get_charger_property
,
1255 .set_property
= bq256xx_set_charger_property
,
1256 .property_is_writeable
= bq256xx_property_is_writeable
,
1259 static struct power_supply_desc bq256xx_battery_desc
= {
1260 .name
= "bq256xx-battery",
1261 .type
= POWER_SUPPLY_TYPE_BATTERY
,
1262 .get_property
= bq256xx_get_battery_property
,
1263 .properties
= bq256xx_battery_props
,
1264 .num_properties
= ARRAY_SIZE(bq256xx_battery_props
),
1265 .property_is_writeable
= bq256xx_property_is_writeable
,
1269 static bool bq256xx_is_volatile_reg(struct device
*dev
, unsigned int reg
)
1272 case BQ256XX_INPUT_CURRENT_LIMIT
:
1273 case BQ256XX_CHARGER_STATUS_0
...BQ256XX_CHARGER_STATUS_2
:
1280 static const struct regmap_config bq25600_regmap_config
= {
1284 .max_register
= BQ256XX_PART_INFORMATION
,
1285 .reg_defaults
= bq2560x_reg_defs
,
1286 .num_reg_defaults
= ARRAY_SIZE(bq2560x_reg_defs
),
1287 .cache_type
= REGCACHE_FLAT
,
1288 .volatile_reg
= bq256xx_is_volatile_reg
,
1291 static const struct regmap_config bq25611d_regmap_config
= {
1295 .max_register
= BQ256XX_CHARGER_CONTROL_4
,
1296 .reg_defaults
= bq25611d_reg_defs
,
1297 .num_reg_defaults
= ARRAY_SIZE(bq25611d_reg_defs
),
1298 .cache_type
= REGCACHE_FLAT
,
1299 .volatile_reg
= bq256xx_is_volatile_reg
,
1302 static const struct regmap_config bq25618_619_regmap_config
= {
1306 .max_register
= BQ256XX_CHARGER_CONTROL_4
,
1307 .reg_defaults
= bq25618_619_reg_defs
,
1308 .num_reg_defaults
= ARRAY_SIZE(bq25618_619_reg_defs
),
1309 .cache_type
= REGCACHE_FLAT
,
1310 .volatile_reg
= bq256xx_is_volatile_reg
,
1313 static const struct bq256xx_chip_info bq256xx_chip_info_tbl
[] = {
1315 .model_id
= BQ25600
,
1316 .bq256xx_regmap_config
= &bq25600_regmap_config
,
1317 .bq256xx_get_ichg
= bq256xx_get_ichg_curr
,
1318 .bq256xx_get_iindpm
= bq256xx_get_input_curr_lim
,
1319 .bq256xx_get_vbatreg
= bq2560x_get_chrg_volt
,
1320 .bq256xx_get_iterm
= bq256xx_get_term_curr
,
1321 .bq256xx_get_iprechg
= bq256xx_get_prechrg_curr
,
1322 .bq256xx_get_vindpm
= bq256xx_get_input_volt_lim
,
1323 .bq256xx_set_ts_ignore
= NULL
,
1325 .bq256xx_set_ichg
= bq256xx_set_ichg_curr
,
1326 .bq256xx_set_iindpm
= bq256xx_set_input_curr_lim
,
1327 .bq256xx_set_vbatreg
= bq2560x_set_chrg_volt
,
1328 .bq256xx_set_iterm
= bq256xx_set_term_curr
,
1329 .bq256xx_set_iprechg
= bq256xx_set_prechrg_curr
,
1330 .bq256xx_set_vindpm
= bq256xx_set_input_volt_lim
,
1331 .bq256xx_set_charge_type
= bq256xx_set_charge_type
,
1333 .bq256xx_def_ichg
= BQ2560X_ICHG_DEF_uA
,
1334 .bq256xx_def_iindpm
= BQ256XX_IINDPM_DEF_uA
,
1335 .bq256xx_def_vbatreg
= BQ2560X_VBATREG_DEF_uV
,
1336 .bq256xx_def_iterm
= BQ256XX_ITERM_DEF_uA
,
1337 .bq256xx_def_iprechg
= BQ256XX_IPRECHG_DEF_uA
,
1338 .bq256xx_def_vindpm
= BQ256XX_VINDPM_DEF_uV
,
1340 .bq256xx_max_ichg
= BQ256XX_ICHG_MAX_uA
,
1341 .bq256xx_max_vbatreg
= BQ2560X_VBATREG_MAX_uV
,
1343 .has_usb_detect
= false,
1347 .model_id
= BQ25600D
,
1348 .bq256xx_regmap_config
= &bq25600_regmap_config
,
1349 .bq256xx_get_ichg
= bq256xx_get_ichg_curr
,
1350 .bq256xx_get_iindpm
= bq256xx_get_input_curr_lim
,
1351 .bq256xx_get_vbatreg
= bq2560x_get_chrg_volt
,
1352 .bq256xx_get_iterm
= bq256xx_get_term_curr
,
1353 .bq256xx_get_iprechg
= bq256xx_get_prechrg_curr
,
1354 .bq256xx_get_vindpm
= bq256xx_get_input_volt_lim
,
1356 .bq256xx_set_ichg
= bq256xx_set_ichg_curr
,
1357 .bq256xx_set_iindpm
= bq256xx_set_input_curr_lim
,
1358 .bq256xx_set_vbatreg
= bq2560x_set_chrg_volt
,
1359 .bq256xx_set_iterm
= bq256xx_set_term_curr
,
1360 .bq256xx_set_iprechg
= bq256xx_set_prechrg_curr
,
1361 .bq256xx_set_vindpm
= bq256xx_set_input_volt_lim
,
1362 .bq256xx_set_charge_type
= bq256xx_set_charge_type
,
1363 .bq256xx_set_ts_ignore
= NULL
,
1365 .bq256xx_def_ichg
= BQ2560X_ICHG_DEF_uA
,
1366 .bq256xx_def_iindpm
= BQ256XX_IINDPM_DEF_uA
,
1367 .bq256xx_def_vbatreg
= BQ2560X_VBATREG_DEF_uV
,
1368 .bq256xx_def_iterm
= BQ256XX_ITERM_DEF_uA
,
1369 .bq256xx_def_iprechg
= BQ256XX_IPRECHG_DEF_uA
,
1370 .bq256xx_def_vindpm
= BQ256XX_VINDPM_DEF_uV
,
1372 .bq256xx_max_ichg
= BQ256XX_ICHG_MAX_uA
,
1373 .bq256xx_max_vbatreg
= BQ2560X_VBATREG_MAX_uV
,
1375 .has_usb_detect
= true,
1379 .model_id
= BQ25601
,
1380 .bq256xx_regmap_config
= &bq25600_regmap_config
,
1381 .bq256xx_get_ichg
= bq256xx_get_ichg_curr
,
1382 .bq256xx_get_iindpm
= bq256xx_get_input_curr_lim
,
1383 .bq256xx_get_vbatreg
= bq2560x_get_chrg_volt
,
1384 .bq256xx_get_iterm
= bq256xx_get_term_curr
,
1385 .bq256xx_get_iprechg
= bq256xx_get_prechrg_curr
,
1386 .bq256xx_get_vindpm
= bq256xx_get_input_volt_lim
,
1388 .bq256xx_set_ichg
= bq256xx_set_ichg_curr
,
1389 .bq256xx_set_iindpm
= bq256xx_set_input_curr_lim
,
1390 .bq256xx_set_vbatreg
= bq2560x_set_chrg_volt
,
1391 .bq256xx_set_iterm
= bq256xx_set_term_curr
,
1392 .bq256xx_set_iprechg
= bq256xx_set_prechrg_curr
,
1393 .bq256xx_set_vindpm
= bq256xx_set_input_volt_lim
,
1394 .bq256xx_set_charge_type
= bq256xx_set_charge_type
,
1395 .bq256xx_set_ts_ignore
= NULL
,
1397 .bq256xx_def_ichg
= BQ2560X_ICHG_DEF_uA
,
1398 .bq256xx_def_iindpm
= BQ256XX_IINDPM_DEF_uA
,
1399 .bq256xx_def_vbatreg
= BQ2560X_VBATREG_DEF_uV
,
1400 .bq256xx_def_iterm
= BQ256XX_ITERM_DEF_uA
,
1401 .bq256xx_def_iprechg
= BQ256XX_IPRECHG_DEF_uA
,
1402 .bq256xx_def_vindpm
= BQ256XX_VINDPM_DEF_uV
,
1404 .bq256xx_max_ichg
= BQ256XX_ICHG_MAX_uA
,
1405 .bq256xx_max_vbatreg
= BQ2560X_VBATREG_MAX_uV
,
1407 .has_usb_detect
= false,
1411 .model_id
= BQ25601D
,
1412 .bq256xx_regmap_config
= &bq25600_regmap_config
,
1413 .bq256xx_get_ichg
= bq256xx_get_ichg_curr
,
1414 .bq256xx_get_iindpm
= bq256xx_get_input_curr_lim
,
1415 .bq256xx_get_vbatreg
= bq25601d_get_chrg_volt
,
1416 .bq256xx_get_iterm
= bq256xx_get_term_curr
,
1417 .bq256xx_get_iprechg
= bq256xx_get_prechrg_curr
,
1418 .bq256xx_get_vindpm
= bq256xx_get_input_volt_lim
,
1420 .bq256xx_set_ichg
= bq256xx_set_ichg_curr
,
1421 .bq256xx_set_iindpm
= bq256xx_set_input_curr_lim
,
1422 .bq256xx_set_vbatreg
= bq25601d_set_chrg_volt
,
1423 .bq256xx_set_iterm
= bq256xx_set_term_curr
,
1424 .bq256xx_set_iprechg
= bq256xx_set_prechrg_curr
,
1425 .bq256xx_set_vindpm
= bq256xx_set_input_volt_lim
,
1426 .bq256xx_set_charge_type
= bq256xx_set_charge_type
,
1427 .bq256xx_set_ts_ignore
= NULL
,
1429 .bq256xx_def_ichg
= BQ2560X_ICHG_DEF_uA
,
1430 .bq256xx_def_iindpm
= BQ256XX_IINDPM_DEF_uA
,
1431 .bq256xx_def_vbatreg
= BQ2560X_VBATREG_DEF_uV
,
1432 .bq256xx_def_iterm
= BQ256XX_ITERM_DEF_uA
,
1433 .bq256xx_def_iprechg
= BQ256XX_IPRECHG_DEF_uA
,
1434 .bq256xx_def_vindpm
= BQ256XX_VINDPM_DEF_uV
,
1436 .bq256xx_max_ichg
= BQ256XX_ICHG_MAX_uA
,
1437 .bq256xx_max_vbatreg
= BQ2560X_VBATREG_MAX_uV
,
1439 .has_usb_detect
= true,
1443 .model_id
= BQ25611D
,
1444 .bq256xx_regmap_config
= &bq25611d_regmap_config
,
1445 .bq256xx_get_ichg
= bq256xx_get_ichg_curr
,
1446 .bq256xx_get_iindpm
= bq256xx_get_input_curr_lim
,
1447 .bq256xx_get_vbatreg
= bq25611d_get_chrg_volt
,
1448 .bq256xx_get_iterm
= bq256xx_get_term_curr
,
1449 .bq256xx_get_iprechg
= bq256xx_get_prechrg_curr
,
1450 .bq256xx_get_vindpm
= bq256xx_get_input_volt_lim
,
1452 .bq256xx_set_ichg
= bq256xx_set_ichg_curr
,
1453 .bq256xx_set_iindpm
= bq256xx_set_input_curr_lim
,
1454 .bq256xx_set_vbatreg
= bq25611d_set_chrg_volt
,
1455 .bq256xx_set_iterm
= bq256xx_set_term_curr
,
1456 .bq256xx_set_iprechg
= bq256xx_set_prechrg_curr
,
1457 .bq256xx_set_vindpm
= bq256xx_set_input_volt_lim
,
1458 .bq256xx_set_charge_type
= bq256xx_set_charge_type
,
1459 .bq256xx_set_ts_ignore
= bq256xx_set_ts_ignore
,
1461 .bq256xx_def_ichg
= BQ25611D_ICHG_DEF_uA
,
1462 .bq256xx_def_iindpm
= BQ256XX_IINDPM_DEF_uA
,
1463 .bq256xx_def_vbatreg
= BQ25611D_VBATREG_DEF_uV
,
1464 .bq256xx_def_iterm
= BQ256XX_ITERM_DEF_uA
,
1465 .bq256xx_def_iprechg
= BQ256XX_IPRECHG_DEF_uA
,
1466 .bq256xx_def_vindpm
= BQ256XX_VINDPM_DEF_uV
,
1468 .bq256xx_max_ichg
= BQ256XX_ICHG_MAX_uA
,
1469 .bq256xx_max_vbatreg
= BQ25611D_VBATREG_MAX_uV
,
1471 .has_usb_detect
= true,
1475 .model_id
= BQ25618
,
1476 .bq256xx_regmap_config
= &bq25618_619_regmap_config
,
1477 .bq256xx_get_ichg
= bq25618_619_get_ichg_curr
,
1478 .bq256xx_get_iindpm
= bq256xx_get_input_curr_lim
,
1479 .bq256xx_get_vbatreg
= bq25618_619_get_chrg_volt
,
1480 .bq256xx_get_iterm
= bq25618_619_get_term_curr
,
1481 .bq256xx_get_iprechg
= bq25618_619_get_prechrg_curr
,
1482 .bq256xx_get_vindpm
= bq256xx_get_input_volt_lim
,
1484 .bq256xx_set_ichg
= bq25618_619_set_ichg_curr
,
1485 .bq256xx_set_iindpm
= bq256xx_set_input_curr_lim
,
1486 .bq256xx_set_vbatreg
= bq25618_619_set_chrg_volt
,
1487 .bq256xx_set_iterm
= bq25618_619_set_term_curr
,
1488 .bq256xx_set_iprechg
= bq25618_619_set_prechrg_curr
,
1489 .bq256xx_set_vindpm
= bq256xx_set_input_volt_lim
,
1490 .bq256xx_set_charge_type
= bq256xx_set_charge_type
,
1491 .bq256xx_set_ts_ignore
= bq256xx_set_ts_ignore
,
1493 .bq256xx_def_ichg
= BQ25618_ICHG_DEF_uA
,
1494 .bq256xx_def_iindpm
= BQ256XX_IINDPM_DEF_uA
,
1495 .bq256xx_def_vbatreg
= BQ25618_VBATREG_DEF_uV
,
1496 .bq256xx_def_iterm
= BQ25618_ITERM_DEF_uA
,
1497 .bq256xx_def_iprechg
= BQ25618_IPRECHG_DEF_uA
,
1498 .bq256xx_def_vindpm
= BQ256XX_VINDPM_DEF_uV
,
1500 .bq256xx_max_ichg
= BQ25618_ICHG_MAX_uA
,
1501 .bq256xx_max_vbatreg
= BQ25618_VBATREG_MAX_uV
,
1503 .has_usb_detect
= false,
1507 .model_id
= BQ25619
,
1508 .bq256xx_regmap_config
= &bq25618_619_regmap_config
,
1509 .bq256xx_get_ichg
= bq25618_619_get_ichg_curr
,
1510 .bq256xx_get_iindpm
= bq256xx_get_input_curr_lim
,
1511 .bq256xx_get_vbatreg
= bq25618_619_get_chrg_volt
,
1512 .bq256xx_get_iterm
= bq25618_619_get_term_curr
,
1513 .bq256xx_get_iprechg
= bq25618_619_get_prechrg_curr
,
1514 .bq256xx_get_vindpm
= bq256xx_get_input_volt_lim
,
1516 .bq256xx_set_ichg
= bq25618_619_set_ichg_curr
,
1517 .bq256xx_set_iindpm
= bq256xx_set_input_curr_lim
,
1518 .bq256xx_set_vbatreg
= bq25618_619_set_chrg_volt
,
1519 .bq256xx_set_iterm
= bq25618_619_set_term_curr
,
1520 .bq256xx_set_iprechg
= bq25618_619_set_prechrg_curr
,
1521 .bq256xx_set_vindpm
= bq256xx_set_input_volt_lim
,
1522 .bq256xx_set_charge_type
= bq256xx_set_charge_type
,
1523 .bq256xx_set_ts_ignore
= bq256xx_set_ts_ignore
,
1525 .bq256xx_def_ichg
= BQ25618_ICHG_DEF_uA
,
1526 .bq256xx_def_iindpm
= BQ256XX_IINDPM_DEF_uA
,
1527 .bq256xx_def_vbatreg
= BQ25618_VBATREG_DEF_uV
,
1528 .bq256xx_def_iterm
= BQ25618_ITERM_DEF_uA
,
1529 .bq256xx_def_iprechg
= BQ25618_IPRECHG_DEF_uA
,
1530 .bq256xx_def_vindpm
= BQ256XX_VINDPM_DEF_uV
,
1532 .bq256xx_max_ichg
= BQ25618_ICHG_MAX_uA
,
1533 .bq256xx_max_vbatreg
= BQ25618_VBATREG_MAX_uV
,
1535 .has_usb_detect
= false,
1539 static int bq256xx_power_supply_init(struct bq256xx_device
*bq
,
1540 struct power_supply_config
*psy_cfg
, struct device
*dev
)
1542 bq
->charger
= devm_power_supply_register(bq
->dev
,
1543 &bq256xx_power_supply_desc
,
1545 if (IS_ERR(bq
->charger
)) {
1546 dev_err(dev
, "power supply register charger failed\n");
1547 return PTR_ERR(bq
->charger
);
1550 bq
->battery
= devm_power_supply_register(bq
->dev
,
1551 &bq256xx_battery_desc
,
1553 if (IS_ERR(bq
->battery
)) {
1554 dev_err(dev
, "power supply register battery failed\n");
1555 return PTR_ERR(bq
->battery
);
1560 static int bq256xx_hw_init(struct bq256xx_device
*bq
)
1562 struct power_supply_battery_info
*bat_info
;
1563 int wd_reg_val
= BQ256XX_WATCHDOG_DIS
;
1567 for (i
= 0; i
< BQ256XX_NUM_WD_VAL
; i
++) {
1568 if (bq
->watchdog_timer
== bq256xx_watchdog_time
[i
]) {
1572 if (i
+ 1 < BQ256XX_NUM_WD_VAL
&&
1573 bq
->watchdog_timer
> bq256xx_watchdog_time
[i
] &&
1574 bq
->watchdog_timer
< bq256xx_watchdog_time
[i
+ 1])
1577 ret
= regmap_update_bits(bq
->regmap
, BQ256XX_CHARGER_CONTROL_1
,
1578 BQ256XX_WATCHDOG_MASK
, wd_reg_val
<<
1579 BQ256XX_WDT_BIT_SHIFT
);
1583 ret
= power_supply_get_battery_info(bq
->charger
, &bat_info
);
1588 dev_warn(bq
->dev
, "battery info missing, default values will be applied\n");
1590 bat_info
->constant_charge_current_max_ua
=
1591 bq
->chip_info
->bq256xx_def_ichg
;
1593 bat_info
->constant_charge_voltage_max_uv
=
1594 bq
->chip_info
->bq256xx_def_vbatreg
;
1596 bat_info
->precharge_current_ua
=
1597 bq
->chip_info
->bq256xx_def_iprechg
;
1599 bat_info
->charge_term_current_ua
=
1600 bq
->chip_info
->bq256xx_def_iterm
;
1602 bq
->init_data
.ichg_max
=
1603 bq
->chip_info
->bq256xx_max_ichg
;
1605 bq
->init_data
.vbatreg_max
=
1606 bq
->chip_info
->bq256xx_max_vbatreg
;
1608 bq
->init_data
.ichg_max
=
1609 bat_info
->constant_charge_current_max_ua
;
1611 bq
->init_data
.vbatreg_max
=
1612 bat_info
->constant_charge_voltage_max_uv
;
1615 ret
= bq
->chip_info
->bq256xx_set_vindpm(bq
, bq
->init_data
.vindpm
);
1619 ret
= bq
->chip_info
->bq256xx_set_iindpm(bq
, bq
->init_data
.iindpm
);
1623 ret
= bq
->chip_info
->bq256xx_set_ichg(bq
,
1624 bq
->chip_info
->bq256xx_def_ichg
);
1628 ret
= bq
->chip_info
->bq256xx_set_iprechg(bq
,
1629 bat_info
->precharge_current_ua
);
1633 ret
= bq
->chip_info
->bq256xx_set_vbatreg(bq
,
1634 bq
->chip_info
->bq256xx_def_vbatreg
);
1638 ret
= bq
->chip_info
->bq256xx_set_iterm(bq
,
1639 bat_info
->charge_term_current_ua
);
1643 if (bq
->chip_info
->bq256xx_set_ts_ignore
) {
1644 ret
= bq
->chip_info
->bq256xx_set_ts_ignore(bq
, bq
->init_data
.ts_ignore
);
1649 power_supply_put_battery_info(bq
->charger
, bat_info
);
1654 static int bq256xx_parse_dt(struct bq256xx_device
*bq
,
1655 struct power_supply_config
*psy_cfg
, struct device
*dev
)
1659 psy_cfg
->drv_data
= bq
;
1660 psy_cfg
->of_node
= dev
->of_node
;
1662 ret
= device_property_read_u32(bq
->dev
, "ti,watchdog-timeout-ms",
1663 &bq
->watchdog_timer
);
1665 bq
->watchdog_timer
= BQ256XX_WATCHDOG_DIS
;
1667 if (bq
->watchdog_timer
> BQ256XX_WATCHDOG_MAX
||
1668 bq
->watchdog_timer
< BQ256XX_WATCHDOG_DIS
)
1671 ret
= device_property_read_u32(bq
->dev
,
1672 "input-voltage-limit-microvolt",
1673 &bq
->init_data
.vindpm
);
1675 bq
->init_data
.vindpm
= bq
->chip_info
->bq256xx_def_vindpm
;
1677 ret
= device_property_read_u32(bq
->dev
,
1678 "input-current-limit-microamp",
1679 &bq
->init_data
.iindpm
);
1681 bq
->init_data
.iindpm
= bq
->chip_info
->bq256xx_def_iindpm
;
1683 bq
->init_data
.ts_ignore
= device_property_read_bool(bq
->dev
, "ti,no-thermistor");
1688 static int bq256xx_probe(struct i2c_client
*client
)
1690 const struct i2c_device_id
*id
= i2c_client_get_device_id(client
);
1691 struct device
*dev
= &client
->dev
;
1692 struct bq256xx_device
*bq
;
1693 struct power_supply_config psy_cfg
= { };
1697 bq
= devm_kzalloc(dev
, sizeof(*bq
), GFP_KERNEL
);
1701 bq
->client
= client
;
1703 bq
->chip_info
= i2c_get_match_data(client
);
1705 mutex_init(&bq
->lock
);
1707 strscpy(bq
->model_name
, id
->name
, sizeof(bq
->model_name
));
1709 bq
->regmap
= devm_regmap_init_i2c(client
,
1710 bq
->chip_info
->bq256xx_regmap_config
);
1712 if (IS_ERR(bq
->regmap
)) {
1713 dev_err(dev
, "Failed to allocate register map\n");
1714 return PTR_ERR(bq
->regmap
);
1717 i2c_set_clientdata(client
, bq
);
1719 ret
= bq256xx_parse_dt(bq
, &psy_cfg
, dev
);
1721 dev_err(dev
, "Failed to read device tree properties%d\n", ret
);
1725 ret
= devm_add_action_or_reset(dev
, bq256xx_charger_reset
, bq
);
1730 bq
->usb2_phy
= devm_usb_get_phy(dev
, USB_PHY_TYPE_USB2
);
1731 if (!IS_ERR_OR_NULL(bq
->usb2_phy
)) {
1732 INIT_WORK(&bq
->usb_work
, bq256xx_usb_work
);
1733 bq
->usb_nb
.notifier_call
= bq256xx_usb_notifier
;
1734 usb_register_notifier(bq
->usb2_phy
, &bq
->usb_nb
);
1737 bq
->usb3_phy
= devm_usb_get_phy(dev
, USB_PHY_TYPE_USB3
);
1738 if (!IS_ERR_OR_NULL(bq
->usb3_phy
)) {
1739 INIT_WORK(&bq
->usb_work
, bq256xx_usb_work
);
1740 bq
->usb_nb
.notifier_call
= bq256xx_usb_notifier
;
1741 usb_register_notifier(bq
->usb3_phy
, &bq
->usb_nb
);
1745 ret
= devm_request_threaded_irq(dev
, client
->irq
, NULL
,
1746 bq256xx_irq_handler_thread
,
1747 IRQF_TRIGGER_FALLING
|
1749 dev_name(&client
->dev
), bq
);
1751 dev_err(dev
, "get irq fail: %d\n", ret
);
1756 ret
= bq256xx_power_supply_init(bq
, &psy_cfg
, dev
);
1758 dev_err(dev
, "Failed to register power supply\n");
1762 ret
= bq256xx_hw_init(bq
);
1764 dev_err(dev
, "Cannot initialize the chip.\n");
1771 static const struct i2c_device_id bq256xx_i2c_ids
[] = {
1772 { "bq25600", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25600
] },
1773 { "bq25600d", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25600D
] },
1774 { "bq25601", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25601
] },
1775 { "bq25601d", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25601D
] },
1776 { "bq25611d", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25611D
] },
1777 { "bq25618", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25618
] },
1778 { "bq25619", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25619
] },
1781 MODULE_DEVICE_TABLE(i2c
, bq256xx_i2c_ids
);
1783 static const struct of_device_id bq256xx_of_match
[] = {
1784 { .compatible
= "ti,bq25600", .data
= &bq256xx_chip_info_tbl
[BQ25600
] },
1785 { .compatible
= "ti,bq25600d", .data
= &bq256xx_chip_info_tbl
[BQ25600D
] },
1786 { .compatible
= "ti,bq25601", .data
= &bq256xx_chip_info_tbl
[BQ25601
] },
1787 { .compatible
= "ti,bq25601d", .data
= &bq256xx_chip_info_tbl
[BQ25601D
] },
1788 { .compatible
= "ti,bq25611d", .data
= &bq256xx_chip_info_tbl
[BQ25611D
] },
1789 { .compatible
= "ti,bq25618", .data
= &bq256xx_chip_info_tbl
[BQ25618
] },
1790 { .compatible
= "ti,bq25619", .data
= &bq256xx_chip_info_tbl
[BQ25619
] },
1793 MODULE_DEVICE_TABLE(of
, bq256xx_of_match
);
1795 static const struct acpi_device_id bq256xx_acpi_match
[] = {
1796 { "bq25600", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25600
] },
1797 { "bq25600d", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25600D
] },
1798 { "bq25601", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25601
] },
1799 { "bq25601d", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25601D
] },
1800 { "bq25611d", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25611D
] },
1801 { "bq25618", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25618
] },
1802 { "bq25619", (kernel_ulong_t
)&bq256xx_chip_info_tbl
[BQ25619
] },
1805 MODULE_DEVICE_TABLE(acpi
, bq256xx_acpi_match
);
1807 static struct i2c_driver bq256xx_driver
= {
1809 .name
= "bq256xx-charger",
1810 .of_match_table
= bq256xx_of_match
,
1811 .acpi_match_table
= bq256xx_acpi_match
,
1813 .probe
= bq256xx_probe
,
1814 .id_table
= bq256xx_i2c_ids
,
1816 module_i2c_driver(bq256xx_driver
);
1818 MODULE_AUTHOR("Ricardo Rivera-Matos <r-rivera-matos@ti.com>");
1819 MODULE_DESCRIPTION("bq256xx charger driver");
1820 MODULE_LICENSE("GPL v2");