Lines Matching full:charger
2 * Battery charger driver for TI BQ24735
32 #include <linux/power/bq24735-charger.h>
50 struct power_supply *charger; member
111 static int bq24735_config_charger(struct bq24735 *charger) in bq24735_config_charger() argument
113 struct bq24735_platform *pdata = charger->pdata; in bq24735_config_charger()
123 ret = bq24735_write_word(charger->client, in bq24735_config_charger()
126 dev_err(&charger->client->dev, in bq24735_config_charger()
127 "Failed to write charger current : %d\n", in bq24735_config_charger()
136 ret = bq24735_write_word(charger->client, in bq24735_config_charger()
139 dev_err(&charger->client->dev, in bq24735_config_charger()
140 "Failed to write charger voltage : %d\n", in bq24735_config_charger()
149 ret = bq24735_write_word(charger->client, in bq24735_config_charger()
152 dev_err(&charger->client->dev, in bq24735_config_charger()
162 static inline int bq24735_enable_charging(struct bq24735 *charger) in bq24735_enable_charging() argument
166 if (charger->pdata->ext_control) in bq24735_enable_charging()
169 ret = bq24735_config_charger(charger); in bq24735_enable_charging()
173 return bq24735_update_word(charger->client, BQ24735_CHARGE_OPT, in bq24735_enable_charging()
177 static inline int bq24735_disable_charging(struct bq24735 *charger) in bq24735_disable_charging() argument
179 if (charger->pdata->ext_control) in bq24735_disable_charging()
182 return bq24735_update_word(charger->client, BQ24735_CHARGE_OPT, in bq24735_disable_charging()
187 static bool bq24735_charger_is_present(struct bq24735 *charger) in bq24735_charger_is_present() argument
189 if (charger->status_gpio) { in bq24735_charger_is_present()
190 return !gpiod_get_value_cansleep(charger->status_gpio); in bq24735_charger_is_present()
194 ac = bq24735_read_word(charger->client, BQ24735_CHARGE_OPT); in bq24735_charger_is_present()
196 dev_dbg(&charger->client->dev, in bq24735_charger_is_present()
197 "Failed to read charger options : %d\n", in bq24735_charger_is_present()
207 static int bq24735_charger_is_charging(struct bq24735 *charger) in bq24735_charger_is_charging() argument
211 if (!bq24735_charger_is_present(charger)) in bq24735_charger_is_charging()
214 ret = bq24735_read_word(charger->client, BQ24735_CHARGE_OPT); in bq24735_charger_is_charging()
221 static void bq24735_update(struct bq24735 *charger) in bq24735_update() argument
223 mutex_lock(&charger->lock); in bq24735_update()
225 if (charger->charging && bq24735_charger_is_present(charger)) in bq24735_update()
226 bq24735_enable_charging(charger); in bq24735_update()
228 bq24735_disable_charging(charger); in bq24735_update()
230 mutex_unlock(&charger->lock); in bq24735_update()
232 power_supply_changed(charger->charger); in bq24735_update()
238 struct bq24735 *charger = to_bq24735(psy); in bq24735_charger_isr() local
240 bq24735_update(charger); in bq24735_charger_isr()
247 struct bq24735 *charger = container_of(work, struct bq24735, poll.work); in bq24735_poll() local
249 bq24735_update(charger); in bq24735_poll()
251 schedule_delayed_work(&charger->poll, in bq24735_poll()
252 msecs_to_jiffies(charger->poll_interval)); in bq24735_poll()
259 struct bq24735 *charger = to_bq24735(psy); in bq24735_charger_get_property() local
263 val->intval = bq24735_charger_is_present(charger) ? 1 : 0; in bq24735_charger_get_property()
266 switch (bq24735_charger_is_charging(charger)) { in bq24735_charger_get_property()
289 struct bq24735 *charger = to_bq24735(psy); in bq24735_charger_set_property() local
296 mutex_lock(&charger->lock); in bq24735_charger_set_property()
297 charger->charging = true; in bq24735_charger_set_property()
298 ret = bq24735_enable_charging(charger); in bq24735_charger_set_property()
299 mutex_unlock(&charger->lock); in bq24735_charger_set_property()
305 mutex_lock(&charger->lock); in bq24735_charger_set_property()
306 charger->charging = false; in bq24735_charger_set_property()
307 ret = bq24735_disable_charging(charger); in bq24735_charger_set_property()
308 mutex_unlock(&charger->lock); in bq24735_charger_set_property()
358 struct bq24735 *charger; in bq24735_charger_probe() local
363 charger = devm_kzalloc(&client->dev, sizeof(*charger), GFP_KERNEL); in bq24735_charger_probe()
364 if (!charger) in bq24735_charger_probe()
367 mutex_init(&charger->lock); in bq24735_charger_probe()
368 charger->charging = true; in bq24735_charger_probe()
369 charger->pdata = client->dev.platform_data; in bq24735_charger_probe()
371 if (IS_ENABLED(CONFIG_OF) && !charger->pdata && client->dev.of_node) in bq24735_charger_probe()
372 charger->pdata = bq24735_parse_dt_data(client); in bq24735_charger_probe()
374 if (!charger->pdata) { in bq24735_charger_probe()
379 name = (char *)charger->pdata->name; in bq24735_charger_probe()
390 charger->client = client; in bq24735_charger_probe()
392 supply_desc = &charger->charger_desc; in bq24735_charger_probe()
403 psy_cfg.supplied_to = charger->pdata->supplied_to; in bq24735_charger_probe()
404 psy_cfg.num_supplicants = charger->pdata->num_supplicants; in bq24735_charger_probe()
406 psy_cfg.drv_data = charger; in bq24735_charger_probe()
408 i2c_set_clientdata(client, charger); in bq24735_charger_probe()
410 charger->status_gpio = devm_gpiod_get_optional(&client->dev, in bq24735_charger_probe()
413 if (IS_ERR(charger->status_gpio)) { in bq24735_charger_probe()
414 ret = PTR_ERR(charger->status_gpio); in bq24735_charger_probe()
419 if (bq24735_charger_is_present(charger)) { in bq24735_charger_probe()
441 ret = bq24735_enable_charging(charger); in bq24735_charger_probe()
448 charger->charger = devm_power_supply_register(&client->dev, supply_desc, in bq24735_charger_probe()
450 if (IS_ERR(charger->charger)) { in bq24735_charger_probe()
451 ret = PTR_ERR(charger->charger); in bq24735_charger_probe()
464 charger->charger); in bq24735_charger_probe()
473 &charger->poll_interval); in bq24735_charger_probe()
476 if (!charger->poll_interval) in bq24735_charger_probe()
479 ret = devm_delayed_work_autocancel(&client->dev, &charger->poll, in bq24735_charger_probe()
484 schedule_delayed_work(&charger->poll, in bq24735_charger_probe()
485 msecs_to_jiffies(charger->poll_interval)); in bq24735_charger_probe()
492 { "bq24735-charger" },
505 .name = "bq24735-charger",