Lines Matching full:charger

2  * Battery charger driver for TI BQ24735
32 #include <linux/power/bq24735-charger.h>
47 struct power_supply *charger; member
108 static int bq24735_config_charger(struct bq24735 *charger) in bq24735_config_charger() argument
110 struct bq24735_platform *pdata = charger->pdata; in bq24735_config_charger()
120 ret = bq24735_write_word(charger->client, in bq24735_config_charger()
123 dev_err(&charger->client->dev, in bq24735_config_charger()
124 "Failed to write charger current : %d\n", in bq24735_config_charger()
133 ret = bq24735_write_word(charger->client, in bq24735_config_charger()
136 dev_err(&charger->client->dev, in bq24735_config_charger()
137 "Failed to write charger voltage : %d\n", in bq24735_config_charger()
146 ret = bq24735_write_word(charger->client, in bq24735_config_charger()
149 dev_err(&charger->client->dev, in bq24735_config_charger()
159 static inline int bq24735_enable_charging(struct bq24735 *charger) in bq24735_enable_charging() argument
163 if (charger->pdata->ext_control) in bq24735_enable_charging()
166 ret = bq24735_config_charger(charger); in bq24735_enable_charging()
170 return bq24735_update_word(charger->client, BQ24735_CHG_OPT, in bq24735_enable_charging()
174 static inline int bq24735_disable_charging(struct bq24735 *charger) in bq24735_disable_charging() argument
176 if (charger->pdata->ext_control) in bq24735_disable_charging()
179 return bq24735_update_word(charger->client, BQ24735_CHG_OPT, in bq24735_disable_charging()
184 static bool bq24735_charger_is_present(struct bq24735 *charger) in bq24735_charger_is_present() argument
186 if (charger->status_gpio) { in bq24735_charger_is_present()
187 return !gpiod_get_value_cansleep(charger->status_gpio); in bq24735_charger_is_present()
191 ac = bq24735_read_word(charger->client, BQ24735_CHG_OPT); in bq24735_charger_is_present()
193 dev_dbg(&charger->client->dev, in bq24735_charger_is_present()
194 "Failed to read charger options : %d\n", in bq24735_charger_is_present()
204 static int bq24735_charger_is_charging(struct bq24735 *charger) in bq24735_charger_is_charging() argument
208 if (!bq24735_charger_is_present(charger)) in bq24735_charger_is_charging()
211 ret = bq24735_read_word(charger->client, BQ24735_CHG_OPT); in bq24735_charger_is_charging()
218 static void bq24735_update(struct bq24735 *charger) in bq24735_update() argument
220 mutex_lock(&charger->lock); in bq24735_update()
222 if (charger->charging && bq24735_charger_is_present(charger)) in bq24735_update()
223 bq24735_enable_charging(charger); in bq24735_update()
225 bq24735_disable_charging(charger); in bq24735_update()
227 mutex_unlock(&charger->lock); in bq24735_update()
229 power_supply_changed(charger->charger); in bq24735_update()
235 struct bq24735 *charger = to_bq24735(psy); in bq24735_charger_isr() local
237 bq24735_update(charger); in bq24735_charger_isr()
244 struct bq24735 *charger = container_of(work, struct bq24735, poll.work); in bq24735_poll() local
246 bq24735_update(charger); in bq24735_poll()
248 schedule_delayed_work(&charger->poll, in bq24735_poll()
249 msecs_to_jiffies(charger->poll_interval)); in bq24735_poll()
256 struct bq24735 *charger = to_bq24735(psy); in bq24735_charger_get_property() local
260 val->intval = bq24735_charger_is_present(charger) ? 1 : 0; in bq24735_charger_get_property()
263 switch (bq24735_charger_is_charging(charger)) { in bq24735_charger_get_property()
286 struct bq24735 *charger = to_bq24735(psy); in bq24735_charger_set_property() local
293 mutex_lock(&charger->lock); in bq24735_charger_set_property()
294 charger->charging = true; in bq24735_charger_set_property()
295 ret = bq24735_enable_charging(charger); in bq24735_charger_set_property()
296 mutex_unlock(&charger->lock); in bq24735_charger_set_property()
302 mutex_lock(&charger->lock); in bq24735_charger_set_property()
303 charger->charging = false; in bq24735_charger_set_property()
304 ret = bq24735_disable_charging(charger); in bq24735_charger_set_property()
305 mutex_unlock(&charger->lock); in bq24735_charger_set_property()
356 struct bq24735 *charger; in bq24735_charger_probe() local
361 charger = devm_kzalloc(&client->dev, sizeof(*charger), GFP_KERNEL); in bq24735_charger_probe()
362 if (!charger) in bq24735_charger_probe()
365 mutex_init(&charger->lock); in bq24735_charger_probe()
366 charger->charging = true; in bq24735_charger_probe()
367 charger->pdata = client->dev.platform_data; in bq24735_charger_probe()
369 if (IS_ENABLED(CONFIG_OF) && !charger->pdata && client->dev.of_node) in bq24735_charger_probe()
370 charger->pdata = bq24735_parse_dt_data(client); in bq24735_charger_probe()
372 if (!charger->pdata) { in bq24735_charger_probe()
377 name = (char *)charger->pdata->name; in bq24735_charger_probe()
388 charger->client = client; in bq24735_charger_probe()
390 supply_desc = &charger->charger_desc; in bq24735_charger_probe()
401 psy_cfg.supplied_to = charger->pdata->supplied_to; in bq24735_charger_probe()
402 psy_cfg.num_supplicants = charger->pdata->num_supplicants; in bq24735_charger_probe()
404 psy_cfg.drv_data = charger; in bq24735_charger_probe()
406 i2c_set_clientdata(client, charger); in bq24735_charger_probe()
408 charger->status_gpio = devm_gpiod_get_optional(&client->dev, in bq24735_charger_probe()
411 if (IS_ERR(charger->status_gpio)) { in bq24735_charger_probe()
412 ret = PTR_ERR(charger->status_gpio); in bq24735_charger_probe()
417 if (bq24735_charger_is_present(charger)) { in bq24735_charger_probe()
439 ret = bq24735_enable_charging(charger); in bq24735_charger_probe()
446 charger->charger = devm_power_supply_register(&client->dev, supply_desc, in bq24735_charger_probe()
448 if (IS_ERR(charger->charger)) { in bq24735_charger_probe()
449 ret = PTR_ERR(charger->charger); in bq24735_charger_probe()
462 charger->charger); in bq24735_charger_probe()
471 &charger->poll_interval); in bq24735_charger_probe()
474 if (!charger->poll_interval) in bq24735_charger_probe()
477 INIT_DELAYED_WORK(&charger->poll, bq24735_poll); in bq24735_charger_probe()
478 schedule_delayed_work(&charger->poll, in bq24735_charger_probe()
479 msecs_to_jiffies(charger->poll_interval)); in bq24735_charger_probe()
487 struct bq24735 *charger = i2c_get_clientdata(client); in bq24735_charger_remove() local
489 if (charger->poll_interval) in bq24735_charger_remove()
490 cancel_delayed_work_sync(&charger->poll); in bq24735_charger_remove()
496 { "bq24735-charger", 0 },
509 .name = "bq24735-charger",