2 * TI BQ24257 charger driver
4 * Copyright (C) 2015 Intel Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
18 #include <linux/module.h>
19 #include <linux/i2c.h>
20 #include <linux/power_supply.h>
21 #include <linux/regmap.h>
22 #include <linux/types.h>
23 #include <linux/gpio/consumer.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
27 #include <linux/acpi.h>
30 #define BQ24257_REG_1 0x00
31 #define BQ24257_REG_2 0x01
32 #define BQ24257_REG_3 0x02
33 #define BQ24257_REG_4 0x03
34 #define BQ24257_REG_5 0x04
35 #define BQ24257_REG_6 0x05
36 #define BQ24257_REG_7 0x06
38 #define BQ24257_MANUFACTURER "Texas Instruments"
39 #define BQ24257_STAT_IRQ "stat"
40 #define BQ24257_PG_GPIO "pg"
42 #define BQ24257_ILIM_SET_DELAY 1000 /* msec */
45 F_WD_FAULT
, F_WD_EN
, F_STAT
, F_FAULT
, /* REG 1 */
46 F_RESET
, F_IILIMIT
, F_EN_STAT
, F_EN_TERM
, F_CE
, F_HZ_MODE
, /* REG 2 */
47 F_VBAT
, F_USB_DET
, /* REG 3 */
48 F_ICHG
, F_ITERM
, /* REG 4 */
49 F_LOOP_STATUS
, F_LOW_CHG
, F_DPDM_EN
, F_CE_STATUS
, F_VINDPM
, /* REG 5 */
50 F_X2_TMR_EN
, F_TMR
, F_SYSOFF
, F_TS_STAT
, /* REG 6 */
51 F_VOVP
, F_CLR_VDP
, F_FORCE_BATDET
, F_FORCE_PTM
, /* REG 7 */
56 /* initial field values, converted from uV/uA */
57 struct bq24257_init_data
{
58 u8 ichg
; /* charge current */
59 u8 vbat
; /* regulation voltage */
60 u8 iterm
; /* termination current */
63 struct bq24257_state
{
69 struct bq24257_device
{
70 struct i2c_client
*client
;
72 struct power_supply
*charger
;
75 struct regmap_field
*rmap_fields
[F_MAX_FIELDS
];
79 struct delayed_work iilimit_setup_work
;
81 struct bq24257_init_data init_data
;
82 struct bq24257_state state
;
84 struct mutex lock
; /* protect state data */
87 static bool bq24257_is_volatile_reg(struct device
*dev
, unsigned int reg
)
99 static const struct regmap_config bq24257_regmap_config
= {
103 .max_register
= BQ24257_REG_7
,
104 .cache_type
= REGCACHE_RBTREE
,
106 .volatile_reg
= bq24257_is_volatile_reg
,
109 static const struct reg_field bq24257_reg_fields
[] = {
111 [F_WD_FAULT
] = REG_FIELD(BQ24257_REG_1
, 7, 7),
112 [F_WD_EN
] = REG_FIELD(BQ24257_REG_1
, 6, 6),
113 [F_STAT
] = REG_FIELD(BQ24257_REG_1
, 4, 5),
114 [F_FAULT
] = REG_FIELD(BQ24257_REG_1
, 0, 3),
116 [F_RESET
] = REG_FIELD(BQ24257_REG_2
, 7, 7),
117 [F_IILIMIT
] = REG_FIELD(BQ24257_REG_2
, 4, 6),
118 [F_EN_STAT
] = REG_FIELD(BQ24257_REG_2
, 3, 3),
119 [F_EN_TERM
] = REG_FIELD(BQ24257_REG_2
, 2, 2),
120 [F_CE
] = REG_FIELD(BQ24257_REG_2
, 1, 1),
121 [F_HZ_MODE
] = REG_FIELD(BQ24257_REG_2
, 0, 0),
123 [F_VBAT
] = REG_FIELD(BQ24257_REG_3
, 2, 7),
124 [F_USB_DET
] = REG_FIELD(BQ24257_REG_3
, 0, 1),
126 [F_ICHG
] = REG_FIELD(BQ24257_REG_4
, 3, 7),
127 [F_ITERM
] = REG_FIELD(BQ24257_REG_4
, 0, 2),
129 [F_LOOP_STATUS
] = REG_FIELD(BQ24257_REG_5
, 6, 7),
130 [F_LOW_CHG
] = REG_FIELD(BQ24257_REG_5
, 5, 5),
131 [F_DPDM_EN
] = REG_FIELD(BQ24257_REG_5
, 4, 4),
132 [F_CE_STATUS
] = REG_FIELD(BQ24257_REG_5
, 3, 3),
133 [F_VINDPM
] = REG_FIELD(BQ24257_REG_5
, 0, 2),
135 [F_X2_TMR_EN
] = REG_FIELD(BQ24257_REG_6
, 7, 7),
136 [F_TMR
] = REG_FIELD(BQ24257_REG_6
, 5, 6),
137 [F_SYSOFF
] = REG_FIELD(BQ24257_REG_6
, 4, 4),
138 [F_TS_STAT
] = REG_FIELD(BQ24257_REG_6
, 0, 2),
140 [F_VOVP
] = REG_FIELD(BQ24257_REG_7
, 5, 7),
141 [F_CLR_VDP
] = REG_FIELD(BQ24257_REG_7
, 4, 4),
142 [F_FORCE_BATDET
] = REG_FIELD(BQ24257_REG_7
, 3, 3),
143 [F_FORCE_PTM
] = REG_FIELD(BQ24257_REG_7
, 2, 2)
146 static const u32 bq24257_vbat_map
[] = {
147 3500000, 3520000, 3540000, 3560000, 3580000, 3600000, 3620000, 3640000,
148 3660000, 3680000, 3700000, 3720000, 3740000, 3760000, 3780000, 3800000,
149 3820000, 3840000, 3860000, 3880000, 3900000, 3920000, 3940000, 3960000,
150 3980000, 4000000, 4020000, 4040000, 4060000, 4080000, 4100000, 4120000,
151 4140000, 4160000, 4180000, 4200000, 4220000, 4240000, 4260000, 4280000,
152 4300000, 4320000, 4340000, 4360000, 4380000, 4400000, 4420000, 4440000
155 #define BQ24257_VBAT_MAP_SIZE ARRAY_SIZE(bq24257_vbat_map)
157 static const u32 bq24257_ichg_map
[] = {
158 500000, 550000, 600000, 650000, 700000, 750000, 800000, 850000, 900000,
159 950000, 1000000, 1050000, 1100000, 1150000, 1200000, 1250000, 1300000,
160 1350000, 1400000, 1450000, 1500000, 1550000, 1600000, 1650000, 1700000,
161 1750000, 1800000, 1850000, 1900000, 1950000, 2000000
164 #define BQ24257_ICHG_MAP_SIZE ARRAY_SIZE(bq24257_ichg_map)
166 static const u32 bq24257_iterm_map
[] = {
167 50000, 75000, 100000, 125000, 150000, 175000, 200000, 225000
170 #define BQ24257_ITERM_MAP_SIZE ARRAY_SIZE(bq24257_iterm_map)
172 static int bq24257_field_read(struct bq24257_device
*bq
,
173 enum bq24257_fields field_id
)
178 ret
= regmap_field_read(bq
->rmap_fields
[field_id
], &val
);
185 static int bq24257_field_write(struct bq24257_device
*bq
,
186 enum bq24257_fields field_id
, u8 val
)
188 return regmap_field_write(bq
->rmap_fields
[field_id
], val
);
191 static u8
bq24257_find_idx(u32 value
, const u32
*map
, u8 map_size
)
195 for (idx
= 1; idx
< map_size
; idx
++)
196 if (value
< map
[idx
])
202 enum bq24257_status
{
204 STATUS_CHARGE_IN_PROGRESS
,
223 static int bq24257_power_supply_get_property(struct power_supply
*psy
,
224 enum power_supply_property psp
,
225 union power_supply_propval
*val
)
227 struct bq24257_device
*bq
= power_supply_get_drvdata(psy
);
228 struct bq24257_state state
;
230 mutex_lock(&bq
->lock
);
232 mutex_unlock(&bq
->lock
);
235 case POWER_SUPPLY_PROP_STATUS
:
236 if (!state
.power_good
)
237 val
->intval
= POWER_SUPPLY_STATUS_DISCHARGING
;
238 else if (state
.status
== STATUS_READY
)
239 val
->intval
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
240 else if (state
.status
== STATUS_CHARGE_IN_PROGRESS
)
241 val
->intval
= POWER_SUPPLY_STATUS_CHARGING
;
242 else if (state
.status
== STATUS_CHARGE_DONE
)
243 val
->intval
= POWER_SUPPLY_STATUS_FULL
;
245 val
->intval
= POWER_SUPPLY_STATUS_UNKNOWN
;
248 case POWER_SUPPLY_PROP_MANUFACTURER
:
249 val
->strval
= BQ24257_MANUFACTURER
;
252 case POWER_SUPPLY_PROP_ONLINE
:
253 val
->intval
= state
.power_good
;
256 case POWER_SUPPLY_PROP_HEALTH
:
257 switch (state
.fault
) {
259 val
->intval
= POWER_SUPPLY_HEALTH_GOOD
;
262 case FAULT_INPUT_OVP
:
264 val
->intval
= POWER_SUPPLY_HEALTH_OVERVOLTAGE
;
269 val
->intval
= POWER_SUPPLY_HEALTH_OVERHEAT
;
273 val
->intval
= POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE
;
277 val
->intval
= POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
;
283 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT
:
284 val
->intval
= bq24257_ichg_map
[bq
->init_data
.ichg
];
287 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX
:
288 val
->intval
= bq24257_ichg_map
[BQ24257_ICHG_MAP_SIZE
- 1];
291 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE
:
292 val
->intval
= bq24257_vbat_map
[bq
->init_data
.vbat
];
295 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX
:
296 val
->intval
= bq24257_vbat_map
[BQ24257_VBAT_MAP_SIZE
- 1];
299 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT
:
300 val
->intval
= bq24257_iterm_map
[bq
->init_data
.iterm
];
310 static int bq24257_get_chip_state(struct bq24257_device
*bq
,
311 struct bq24257_state
*state
)
315 ret
= bq24257_field_read(bq
, F_STAT
);
321 ret
= bq24257_field_read(bq
, F_FAULT
);
327 state
->power_good
= !gpiod_get_value_cansleep(bq
->pg
);
332 static bool bq24257_state_changed(struct bq24257_device
*bq
,
333 struct bq24257_state
*new_state
)
337 mutex_lock(&bq
->lock
);
338 ret
= (bq
->state
.status
!= new_state
->status
||
339 bq
->state
.fault
!= new_state
->fault
||
340 bq
->state
.power_good
!= new_state
->power_good
);
341 mutex_unlock(&bq
->lock
);
346 enum bq24257_loop_status
{
349 LOOP_STATUS_IN_CURRENT_LIMIT
,
353 enum bq24257_in_ilimit
{
364 enum bq24257_port_type
{
365 PORT_TYPE_DCP
, /* Dedicated Charging Port */
366 PORT_TYPE_CDP
, /* Charging Downstream Port */
367 PORT_TYPE_SDP
, /* Standard Downstream Port */
368 PORT_TYPE_NON_STANDARD
,
371 enum bq24257_safety_timer
{
378 static int bq24257_iilimit_autoset(struct bq24257_device
*bq
)
384 const u8 new_iilimit
[] = {
385 [PORT_TYPE_DCP
] = IILIMIT_2000
,
386 [PORT_TYPE_CDP
] = IILIMIT_2000
,
387 [PORT_TYPE_SDP
] = IILIMIT_500
,
388 [PORT_TYPE_NON_STANDARD
] = IILIMIT_500
391 ret
= bq24257_field_read(bq
, F_LOOP_STATUS
);
397 ret
= bq24257_field_read(bq
, F_IILIMIT
);
404 * All USB ports should be able to handle 500mA. If not, DPM will lower
405 * the charging current to accommodate the power source. No need to set
406 * a lower IILIMIT value.
408 if (loop_status
== LOOP_STATUS_IN_DPM
&& iilimit
== IILIMIT_500
)
411 ret
= bq24257_field_read(bq
, F_USB_DET
);
417 ret
= bq24257_field_write(bq
, F_IILIMIT
, new_iilimit
[port_type
]);
421 ret
= bq24257_field_write(bq
, F_TMR
, SAFETY_TIMER_360
);
425 ret
= bq24257_field_write(bq
, F_CLR_VDP
, 1);
429 dev_dbg(bq
->dev
, "port/loop = %d/%d -> iilimit = %d\n",
430 port_type
, loop_status
, new_iilimit
[port_type
]);
435 dev_err(bq
->dev
, "%s: Error communicating with the chip.\n", __func__
);
439 static void bq24257_iilimit_setup_work(struct work_struct
*work
)
441 struct bq24257_device
*bq
= container_of(work
, struct bq24257_device
,
442 iilimit_setup_work
.work
);
444 bq24257_iilimit_autoset(bq
);
447 static void bq24257_handle_state_change(struct bq24257_device
*bq
,
448 struct bq24257_state
*new_state
)
451 struct bq24257_state old_state
;
452 bool reset_iilimit
= false;
453 bool config_iilimit
= false;
455 mutex_lock(&bq
->lock
);
456 old_state
= bq
->state
;
457 mutex_unlock(&bq
->lock
);
459 if (!new_state
->power_good
) { /* power removed */
460 cancel_delayed_work_sync(&bq
->iilimit_setup_work
);
462 /* activate D+/D- port detection algorithm */
463 ret
= bq24257_field_write(bq
, F_DPDM_EN
, 1);
467 reset_iilimit
= true;
468 } else if (!old_state
.power_good
) { /* power inserted */
469 config_iilimit
= true;
470 } else if (new_state
->fault
== FAULT_NO_BAT
) { /* battery removed */
471 cancel_delayed_work_sync(&bq
->iilimit_setup_work
);
473 reset_iilimit
= true;
474 } else if (old_state
.fault
== FAULT_NO_BAT
) { /* battery connected */
475 config_iilimit
= true;
476 } else if (new_state
->fault
== FAULT_TIMER
) { /* safety timer expired */
477 dev_err(bq
->dev
, "Safety timer expired! Battery dead?\n");
481 ret
= bq24257_field_write(bq
, F_IILIMIT
, IILIMIT_500
);
484 } else if (config_iilimit
) {
485 schedule_delayed_work(&bq
->iilimit_setup_work
,
486 msecs_to_jiffies(BQ24257_ILIM_SET_DELAY
));
492 dev_err(bq
->dev
, "%s: Error communicating with the chip.\n", __func__
);
495 static irqreturn_t
bq24257_irq_handler_thread(int irq
, void *private)
498 struct bq24257_device
*bq
= private;
499 struct bq24257_state state
;
501 ret
= bq24257_get_chip_state(bq
, &state
);
505 if (!bq24257_state_changed(bq
, &state
))
508 dev_dbg(bq
->dev
, "irq(state changed): status/fault/pg = %d/%d/%d\n",
509 state
.status
, state
.fault
, state
.power_good
);
511 bq24257_handle_state_change(bq
, &state
);
513 mutex_lock(&bq
->lock
);
515 mutex_unlock(&bq
->lock
);
517 power_supply_changed(bq
->charger
);
522 static int bq24257_hw_init(struct bq24257_device
*bq
)
526 struct bq24257_state state
;
532 {F_ICHG
, bq
->init_data
.ichg
},
533 {F_VBAT
, bq
->init_data
.vbat
},
534 {F_ITERM
, bq
->init_data
.iterm
}
538 * Disable the watchdog timer to prevent the IC from going back to
539 * default settings after 50 seconds of I2C inactivity.
541 ret
= bq24257_field_write(bq
, F_WD_EN
, 0);
545 /* configure the charge currents and voltages */
546 for (i
= 0; i
< ARRAY_SIZE(init_data
); i
++) {
547 ret
= bq24257_field_write(bq
, init_data
[i
].field
,
553 ret
= bq24257_get_chip_state(bq
, &state
);
557 mutex_lock(&bq
->lock
);
559 mutex_unlock(&bq
->lock
);
561 if (!state
.power_good
)
562 /* activate D+/D- detection algorithm */
563 ret
= bq24257_field_write(bq
, F_DPDM_EN
, 1);
564 else if (state
.fault
!= FAULT_NO_BAT
)
565 ret
= bq24257_iilimit_autoset(bq
);
570 static enum power_supply_property bq24257_power_supply_props
[] = {
571 POWER_SUPPLY_PROP_MANUFACTURER
,
572 POWER_SUPPLY_PROP_STATUS
,
573 POWER_SUPPLY_PROP_ONLINE
,
574 POWER_SUPPLY_PROP_HEALTH
,
575 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT
,
576 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX
,
577 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE
,
578 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX
,
579 POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT
,
582 static char *bq24257_charger_supplied_to
[] = {
586 static const struct power_supply_desc bq24257_power_supply_desc
= {
587 .name
= "bq24257-charger",
588 .type
= POWER_SUPPLY_TYPE_USB
,
589 .properties
= bq24257_power_supply_props
,
590 .num_properties
= ARRAY_SIZE(bq24257_power_supply_props
),
591 .get_property
= bq24257_power_supply_get_property
,
594 static int bq24257_power_supply_init(struct bq24257_device
*bq
)
596 struct power_supply_config psy_cfg
= { .drv_data
= bq
, };
598 psy_cfg
.supplied_to
= bq24257_charger_supplied_to
;
599 psy_cfg
.num_supplicants
= ARRAY_SIZE(bq24257_charger_supplied_to
);
601 bq
->charger
= power_supply_register(bq
->dev
, &bq24257_power_supply_desc
,
603 if (IS_ERR(bq
->charger
))
604 return PTR_ERR(bq
->charger
);
609 static int bq24257_irq_probe(struct bq24257_device
*bq
)
611 struct gpio_desc
*stat_irq
;
613 stat_irq
= devm_gpiod_get_index(bq
->dev
, BQ24257_STAT_IRQ
, 0, GPIOD_IN
);
614 if (IS_ERR(stat_irq
)) {
615 dev_err(bq
->dev
, "could not probe stat_irq pin\n");
616 return PTR_ERR(stat_irq
);
619 return gpiod_to_irq(stat_irq
);
622 static int bq24257_pg_gpio_probe(struct bq24257_device
*bq
)
624 bq
->pg
= devm_gpiod_get_index(bq
->dev
, BQ24257_PG_GPIO
, 0, GPIOD_IN
);
625 if (IS_ERR(bq
->pg
)) {
626 dev_err(bq
->dev
, "could not probe PG pin\n");
627 return PTR_ERR(bq
->pg
);
633 static int bq24257_fw_probe(struct bq24257_device
*bq
)
638 ret
= device_property_read_u32(bq
->dev
, "ti,charge-current", &property
);
642 bq
->init_data
.ichg
= bq24257_find_idx(property
, bq24257_ichg_map
,
643 BQ24257_ICHG_MAP_SIZE
);
645 ret
= device_property_read_u32(bq
->dev
, "ti,battery-regulation-voltage",
650 bq
->init_data
.vbat
= bq24257_find_idx(property
, bq24257_vbat_map
,
651 BQ24257_VBAT_MAP_SIZE
);
653 ret
= device_property_read_u32(bq
->dev
, "ti,termination-current",
658 bq
->init_data
.iterm
= bq24257_find_idx(property
, bq24257_iterm_map
,
659 BQ24257_ITERM_MAP_SIZE
);
664 static int bq24257_probe(struct i2c_client
*client
,
665 const struct i2c_device_id
*id
)
667 struct i2c_adapter
*adapter
= to_i2c_adapter(client
->dev
.parent
);
668 struct device
*dev
= &client
->dev
;
669 struct bq24257_device
*bq
;
673 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
)) {
674 dev_err(dev
, "No support for SMBUS_BYTE_DATA\n");
678 bq
= devm_kzalloc(dev
, sizeof(*bq
), GFP_KERNEL
);
685 mutex_init(&bq
->lock
);
687 bq
->rmap
= devm_regmap_init_i2c(client
, &bq24257_regmap_config
);
688 if (IS_ERR(bq
->rmap
)) {
689 dev_err(dev
, "failed to allocate register map\n");
690 return PTR_ERR(bq
->rmap
);
693 for (i
= 0; i
< ARRAY_SIZE(bq24257_reg_fields
); i
++) {
694 const struct reg_field
*reg_fields
= bq24257_reg_fields
;
696 bq
->rmap_fields
[i
] = devm_regmap_field_alloc(dev
, bq
->rmap
,
698 if (IS_ERR(bq
->rmap_fields
[i
])) {
699 dev_err(dev
, "cannot allocate regmap field\n");
700 return PTR_ERR(bq
->rmap_fields
[i
]);
704 i2c_set_clientdata(client
, bq
);
706 INIT_DELAYED_WORK(&bq
->iilimit_setup_work
, bq24257_iilimit_setup_work
);
708 if (!dev
->platform_data
) {
709 ret
= bq24257_fw_probe(bq
);
711 dev_err(dev
, "Cannot read device properties.\n");
718 /* we can only check Power Good status by probing the PG pin */
719 ret
= bq24257_pg_gpio_probe(bq
);
723 /* reset all registers to defaults */
724 ret
= bq24257_field_write(bq
, F_RESET
, 1);
729 * Put the RESET bit back to 0, in cache. For some reason the HW always
730 * returns 1 on this bit, so this is the only way to avoid resetting the
731 * chip every time we update another field in this register.
733 ret
= bq24257_field_write(bq
, F_RESET
, 0);
737 ret
= bq24257_hw_init(bq
);
739 dev_err(dev
, "Cannot initialize the chip.\n");
743 if (client
->irq
<= 0)
744 client
->irq
= bq24257_irq_probe(bq
);
746 if (client
->irq
< 0) {
747 dev_err(dev
, "no irq resource found\n");
751 ret
= devm_request_threaded_irq(dev
, client
->irq
, NULL
,
752 bq24257_irq_handler_thread
,
753 IRQF_TRIGGER_FALLING
|
754 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
755 BQ24257_STAT_IRQ
, bq
);
759 ret
= bq24257_power_supply_init(bq
);
761 dev_err(dev
, "Failed to register power supply\n");
766 static int bq24257_remove(struct i2c_client
*client
)
768 struct bq24257_device
*bq
= i2c_get_clientdata(client
);
770 cancel_delayed_work_sync(&bq
->iilimit_setup_work
);
772 power_supply_unregister(bq
->charger
);
774 bq24257_field_write(bq
, F_RESET
, 1); /* reset to defaults */
779 #ifdef CONFIG_PM_SLEEP
780 static int bq24257_suspend(struct device
*dev
)
782 struct bq24257_device
*bq
= dev_get_drvdata(dev
);
785 cancel_delayed_work_sync(&bq
->iilimit_setup_work
);
787 /* reset all registers to default (and activate standalone mode) */
788 ret
= bq24257_field_write(bq
, F_RESET
, 1);
790 dev_err(bq
->dev
, "Cannot reset chip to standalone mode.\n");
795 static int bq24257_resume(struct device
*dev
)
798 struct bq24257_device
*bq
= dev_get_drvdata(dev
);
800 ret
= regcache_drop_region(bq
->rmap
, BQ24257_REG_1
, BQ24257_REG_7
);
804 ret
= bq24257_field_write(bq
, F_RESET
, 0);
808 ret
= bq24257_hw_init(bq
);
810 dev_err(bq
->dev
, "Cannot init chip after resume.\n");
814 /* signal userspace, maybe state changed while suspended */
815 power_supply_changed(bq
->charger
);
821 static const struct dev_pm_ops bq24257_pm
= {
822 SET_SYSTEM_SLEEP_PM_OPS(bq24257_suspend
, bq24257_resume
)
825 static const struct i2c_device_id bq24257_i2c_ids
[] = {
829 MODULE_DEVICE_TABLE(i2c
, bq24257_i2c_ids
);
831 static const struct of_device_id bq24257_of_match
[] = {
832 { .compatible
= "ti,bq24257", },
835 MODULE_DEVICE_TABLE(of
, bq24257_of_match
);
837 static const struct acpi_device_id bq24257_acpi_match
[] = {
841 MODULE_DEVICE_TABLE(acpi
, bq24257_acpi_match
);
843 static struct i2c_driver bq24257_driver
= {
845 .name
= "bq24257-charger",
846 .of_match_table
= of_match_ptr(bq24257_of_match
),
847 .acpi_match_table
= ACPI_PTR(bq24257_acpi_match
),
850 .probe
= bq24257_probe
,
851 .remove
= bq24257_remove
,
852 .id_table
= bq24257_i2c_ids
,
854 module_i2c_driver(bq24257_driver
);
856 MODULE_AUTHOR("Laurentiu Palcu <laurentiu.palcu@intel.com>");
857 MODULE_DESCRIPTION("bq24257 charger driver");
858 MODULE_LICENSE("GPL");