Lines Matching full:charger

3  * Battery charger driver for Dialog Semiconductor DA9030
105 /* charger status */
139 struct da9030_charger *charger = s->private; in bat_debug_show() local
141 seq_printf(s, "charger is %s\n", charger->is_on ? "on" : "off"); in bat_debug_show()
142 if (charger->chdet) { in bat_debug_show()
144 charger->mA, charger->mV); in bat_debug_show()
148 charger->adc.vbat_res, in bat_debug_show()
149 da9030_reg_to_mV(charger->adc.vbat_res)); in bat_debug_show()
151 charger->adc.vbatmin_res, in bat_debug_show()
152 da9030_reg_to_mV(charger->adc.vbatmin_res)); in bat_debug_show()
154 charger->adc.vbatmintxon, in bat_debug_show()
155 da9030_reg_to_mV(charger->adc.vbatmintxon)); in bat_debug_show()
157 charger->adc.ichmax_res, in bat_debug_show()
158 da9030_reg_to_mV(charger->adc.ichmax_res)); in bat_debug_show()
160 charger->adc.ichmin_res, in bat_debug_show()
161 da9030_reg_to_mA(charger->adc.ichmin_res)); in bat_debug_show()
163 charger->adc.ichaverage_res, in bat_debug_show()
164 da9030_reg_to_mA(charger->adc.ichaverage_res)); in bat_debug_show()
166 charger->adc.vchmax_res, in bat_debug_show()
167 da9030_reg_to_mA(charger->adc.vchmax_res)); in bat_debug_show()
169 charger->adc.vchmin_res, in bat_debug_show()
170 da9030_reg_to_mV(charger->adc.vchmin_res)); in bat_debug_show()
177 static struct dentry *da9030_bat_create_debugfs(struct da9030_charger *charger) in da9030_bat_create_debugfs() argument
179 charger->debug_file = debugfs_create_file("charger", 0666, NULL, in da9030_bat_create_debugfs()
180 charger, &bat_debug_fops); in da9030_bat_create_debugfs()
181 return charger->debug_file; in da9030_bat_create_debugfs()
184 static void da9030_bat_remove_debugfs(struct da9030_charger *charger) in da9030_bat_remove_debugfs() argument
186 debugfs_remove(charger->debug_file); in da9030_bat_remove_debugfs()
189 static inline struct dentry *da9030_bat_create_debugfs(struct da9030_charger *charger) in da9030_bat_create_debugfs() argument
193 static inline void da9030_bat_remove_debugfs(struct da9030_charger *charger) in da9030_bat_remove_debugfs() argument
198 static inline void da9030_read_adc(struct da9030_charger *charger, in da9030_read_adc() argument
201 da903x_reads(charger->master, DA9030_VBAT_RES, in da9030_read_adc()
205 static void da9030_charger_update_state(struct da9030_charger *charger) in da9030_charger_update_state() argument
209 da903x_read(charger->master, DA9030_CHARGE_CONTROL, &val); in da9030_charger_update_state()
210 charger->is_on = (val & DA9030_CHRG_CHARGER_ENABLE) ? 1 : 0; in da9030_charger_update_state()
211 charger->mA = ((val >> 3) & 0xf) * 100; in da9030_charger_update_state()
212 charger->mV = (val & 0x7) * 50 + 4000; in da9030_charger_update_state()
214 da9030_read_adc(charger, &charger->adc); in da9030_charger_update_state()
215 da903x_read(charger->master, DA9030_FAULT_LOG, &charger->fault); in da9030_charger_update_state()
216 charger->chdet = da903x_query_status(charger->master, in da9030_charger_update_state()
220 static void da9030_set_charge(struct da9030_charger *charger, int on) in da9030_set_charge() argument
226 val |= (charger->charge_milliamp / 100) << 3; in da9030_set_charge()
227 val |= (charger->charge_millivolt - 4000) / 50; in da9030_set_charge()
228 charger->is_on = 1; in da9030_set_charge()
231 charger->is_on = 0; in da9030_set_charge()
234 da903x_write(charger->master, DA9030_CHARGE_CONTROL, val); in da9030_set_charge()
236 power_supply_changed(charger->psy); in da9030_set_charge()
239 static void da9030_charger_check_state(struct da9030_charger *charger) in da9030_charger_check_state() argument
241 da9030_charger_update_state(charger); in da9030_charger_check_state()
244 if (!charger->is_on) { in da9030_charger_check_state()
245 if ((charger->chdet) && in da9030_charger_check_state()
246 (charger->adc.vbat_res < in da9030_charger_check_state()
247 charger->thresholds.vbat_charge_start)) { in da9030_charger_check_state()
248 da9030_set_charge(charger, 1); in da9030_charger_check_state()
251 /* Charger has been pulled out */ in da9030_charger_check_state()
252 if (!charger->chdet) { in da9030_charger_check_state()
253 da9030_set_charge(charger, 0); in da9030_charger_check_state()
257 if (charger->adc.vbat_res >= in da9030_charger_check_state()
258 charger->thresholds.vbat_charge_stop) { in da9030_charger_check_state()
259 da9030_set_charge(charger, 0); in da9030_charger_check_state()
260 da903x_write(charger->master, DA9030_VBATMON, in da9030_charger_check_state()
261 charger->thresholds.vbat_charge_restart); in da9030_charger_check_state()
262 } else if (charger->adc.vbat_res > in da9030_charger_check_state()
263 charger->thresholds.vbat_low) { in da9030_charger_check_state()
267 da903x_write(charger->master, DA9030_VBATMON, in da9030_charger_check_state()
268 charger->thresholds.vbat_low); in da9030_charger_check_state()
270 if (charger->adc.vchmax_res > charger->thresholds.vcharge_max || in da9030_charger_check_state()
271 charger->adc.vchmin_res < charger->thresholds.vcharge_min || in da9030_charger_check_state()
273 charger->adc.tbat_res < charger->thresholds.tbat_high || in da9030_charger_check_state()
274 charger->adc.tbat_res > charger->thresholds.tbat_low) { in da9030_charger_check_state()
275 /* disable charger */ in da9030_charger_check_state()
276 da9030_set_charge(charger, 0); in da9030_charger_check_state()
283 struct da9030_charger *charger; in da9030_charging_monitor() local
285 charger = container_of(work, struct da9030_charger, work.work); in da9030_charging_monitor()
287 da9030_charger_check_state(charger); in da9030_charging_monitor()
290 schedule_delayed_work(&charger->work, charger->interval); in da9030_charging_monitor()
304 static void da9030_battery_check_status(struct da9030_charger *charger, in da9030_battery_check_status() argument
307 if (charger->chdet) { in da9030_battery_check_status()
308 if (charger->is_on) in da9030_battery_check_status()
317 static void da9030_battery_check_health(struct da9030_charger *charger, in da9030_battery_check_health() argument
320 if (charger->fault & DA9030_FAULT_LOG_OVER_TEMP) in da9030_battery_check_health()
322 else if (charger->fault & DA9030_FAULT_LOG_VBAT_OVER) in da9030_battery_check_health()
332 struct da9030_charger *charger = power_supply_get_drvdata(psy); in da9030_battery_get_property() local
336 da9030_battery_check_status(charger, val); in da9030_battery_get_property()
339 da9030_battery_check_health(charger, val); in da9030_battery_get_property()
342 val->intval = charger->battery_info->technology; in da9030_battery_get_property()
345 val->intval = charger->battery_info->voltage_max_design; in da9030_battery_get_property()
348 val->intval = charger->battery_info->voltage_min_design; in da9030_battery_get_property()
351 val->intval = da9030_reg_to_mV(charger->adc.vbat_res) * 1000; in da9030_battery_get_property()
355 da9030_reg_to_mA(charger->adc.ichaverage_res) * 1000; in da9030_battery_get_property()
358 val->strval = charger->battery_info->name; in da9030_battery_get_property()
367 static void da9030_battery_vbat_event(struct da9030_charger *charger) in da9030_battery_vbat_event() argument
369 da9030_read_adc(charger, &charger->adc); in da9030_battery_vbat_event()
371 if (charger->is_on) in da9030_battery_vbat_event()
374 if (charger->adc.vbat_res < charger->thresholds.vbat_low) { in da9030_battery_vbat_event()
376 da903x_write(charger->master, DA9030_VBATMON, in da9030_battery_vbat_event()
377 charger->thresholds.vbat_crit); in da9030_battery_vbat_event()
378 if (charger->battery_low) in da9030_battery_vbat_event()
379 charger->battery_low(); in da9030_battery_vbat_event()
380 } else if (charger->adc.vbat_res < in da9030_battery_vbat_event()
381 charger->thresholds.vbat_crit) { in da9030_battery_vbat_event()
383 if (charger->battery_critical) in da9030_battery_vbat_event()
384 charger->battery_critical(); in da9030_battery_vbat_event()
391 struct da9030_charger *charger = in da9030_battery_event() local
396 cancel_delayed_work_sync(&charger->work); in da9030_battery_event()
397 schedule_work(&charger->work.work); in da9030_battery_event()
400 da9030_battery_vbat_event(charger); in da9030_battery_event()
404 da9030_set_charge(charger, 0); in da9030_battery_event()
411 static void da9030_battery_convert_thresholds(struct da9030_charger *charger, in da9030_battery_convert_thresholds() argument
414 charger->thresholds.tbat_low = pdata->tbat_low; in da9030_battery_convert_thresholds()
415 charger->thresholds.tbat_high = pdata->tbat_high; in da9030_battery_convert_thresholds()
416 charger->thresholds.tbat_restart = pdata->tbat_restart; in da9030_battery_convert_thresholds()
418 charger->thresholds.vbat_low = in da9030_battery_convert_thresholds()
420 charger->thresholds.vbat_crit = in da9030_battery_convert_thresholds()
422 charger->thresholds.vbat_charge_start = in da9030_battery_convert_thresholds()
424 charger->thresholds.vbat_charge_stop = in da9030_battery_convert_thresholds()
426 charger->thresholds.vbat_charge_restart = in da9030_battery_convert_thresholds()
429 charger->thresholds.vcharge_min = in da9030_battery_convert_thresholds()
431 charger->thresholds.vcharge_max = in da9030_battery_convert_thresholds()
435 static void da9030_battery_setup_psy(struct da9030_charger *charger) in da9030_battery_setup_psy() argument
437 struct power_supply_desc *psy_desc = &charger->psy_desc; in da9030_battery_setup_psy()
438 struct power_supply_info *info = charger->battery_info; in da9030_battery_setup_psy()
449 static int da9030_battery_charger_init(struct da9030_charger *charger) in da9030_battery_charger_init() argument
454 v[0] = v[1] = charger->thresholds.vbat_low; in da9030_battery_charger_init()
455 v[2] = charger->thresholds.tbat_high; in da9030_battery_charger_init()
456 v[3] = charger->thresholds.tbat_restart; in da9030_battery_charger_init()
457 v[4] = charger->thresholds.tbat_low; in da9030_battery_charger_init()
459 ret = da903x_writes(charger->master, DA9030_VBATMON, 5, v); in da9030_battery_charger_init()
467 ret = da903x_write(charger->master, DA9030_ADC_MAN_CONTROL, in da9030_battery_charger_init()
474 return da903x_write(charger->master, DA9030_ADC_AUTO_CONTROL, in da9030_battery_charger_init()
483 struct da9030_charger *charger; in da9030_battery_probe() local
496 charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); in da9030_battery_probe()
497 if (charger == NULL) in da9030_battery_probe()
500 charger->master = pdev->dev.parent; in da9030_battery_probe()
504 charger->interval = msecs_to_jiffies( in da9030_battery_probe()
507 charger->charge_milliamp = pdata->charge_milliamp; in da9030_battery_probe()
508 charger->charge_millivolt = pdata->charge_millivolt; in da9030_battery_probe()
509 charger->battery_info = pdata->battery_info; in da9030_battery_probe()
510 charger->battery_low = pdata->battery_low; in da9030_battery_probe()
511 charger->battery_critical = pdata->battery_critical; in da9030_battery_probe()
513 da9030_battery_convert_thresholds(charger, pdata); in da9030_battery_probe()
515 ret = da9030_battery_charger_init(charger); in da9030_battery_probe()
519 INIT_DELAYED_WORK(&charger->work, da9030_charging_monitor); in da9030_battery_probe()
520 schedule_delayed_work(&charger->work, charger->interval); in da9030_battery_probe()
522 charger->nb.notifier_call = da9030_battery_event; in da9030_battery_probe()
523 ret = da903x_register_notifier(charger->master, &charger->nb, in da9030_battery_probe()
531 da9030_battery_setup_psy(charger); in da9030_battery_probe()
532 psy_cfg.drv_data = charger; in da9030_battery_probe()
533 charger->psy = power_supply_register(&pdev->dev, &charger->psy_desc, in da9030_battery_probe()
535 if (IS_ERR(charger->psy)) { in da9030_battery_probe()
536 ret = PTR_ERR(charger->psy); in da9030_battery_probe()
540 charger->debug_file = da9030_bat_create_debugfs(charger); in da9030_battery_probe()
541 platform_set_drvdata(pdev, charger); in da9030_battery_probe()
545 da903x_unregister_notifier(charger->master, &charger->nb, in da9030_battery_probe()
549 cancel_delayed_work(&charger->work); in da9030_battery_probe()
557 struct da9030_charger *charger = platform_get_drvdata(dev); in da9030_battery_remove() local
559 da9030_bat_remove_debugfs(charger); in da9030_battery_remove()
561 da903x_unregister_notifier(charger->master, &charger->nb, in da9030_battery_remove()
564 cancel_delayed_work_sync(&charger->work); in da9030_battery_remove()
565 da9030_set_charge(charger, 0); in da9030_battery_remove()
566 power_supply_unregister(charger->psy); in da9030_battery_remove()
581 MODULE_DESCRIPTION("DA9030 battery charger driver");