Lines Matching refs:charger
2 * Battery charger driver for Dialog Semiconductor DA9030
106 /* charger status */
140 struct da9030_charger *charger = s->private;
142 seq_printf(s, "charger is %s\n", charger->is_on ? "on" : "off");
143 if (charger->chdet) {
145 charger->mA, charger->mV);
149 charger->adc.vbat_res,
150 da9030_reg_to_mV(charger->adc.vbat_res));
152 charger->adc.vbatmin_res,
153 da9030_reg_to_mV(charger->adc.vbatmin_res));
155 charger->adc.vbatmintxon,
156 da9030_reg_to_mV(charger->adc.vbatmintxon));
158 charger->adc.ichmax_res,
159 da9030_reg_to_mV(charger->adc.ichmax_res));
161 charger->adc.ichmin_res,
162 da9030_reg_to_mA(charger->adc.ichmin_res));
164 charger->adc.ichaverage_res,
165 da9030_reg_to_mA(charger->adc.ichaverage_res));
167 charger->adc.vchmax_res,
168 da9030_reg_to_mA(charger->adc.vchmax_res));
170 charger->adc.vchmin_res,
171 da9030_reg_to_mV(charger->adc.vchmin_res));
188 static struct dentry *da9030_bat_create_debugfs(struct da9030_charger *charger)
190 charger->debug_file = debugfs_create_file("charger", 0666, 0, charger,
192 return charger->debug_file;
195 static void da9030_bat_remove_debugfs(struct da9030_charger *charger)
197 debugfs_remove(charger->debug_file);
200 static inline struct dentry *da9030_bat_create_debugfs(struct da9030_charger *charger)
204 static inline void da9030_bat_remove_debugfs(struct da9030_charger *charger)
209 static inline void da9030_read_adc(struct da9030_charger *charger,
212 da903x_reads(charger->master, DA9030_VBAT_RES,
216 static void da9030_charger_update_state(struct da9030_charger *charger)
220 da903x_read(charger->master, DA9030_CHARGE_CONTROL, &val);
221 charger->is_on = (val & DA9030_CHRG_CHARGER_ENABLE) ? 1 : 0;
222 charger->mA = ((val >> 3) & 0xf) * 100;
223 charger->mV = (val & 0x7) * 50 + 4000;
225 da9030_read_adc(charger, &charger->adc);
226 da903x_read(charger->master, DA9030_FAULT_LOG, &charger->fault);
227 charger->chdet = da903x_query_status(charger->master,
231 static void da9030_set_charge(struct da9030_charger *charger, int on)
237 val |= (charger->charge_milliamp / 100) << 3;
238 val |= (charger->charge_millivolt - 4000) / 50;
239 charger->is_on = 1;
242 charger->is_on = 0;
245 da903x_write(charger->master, DA9030_CHARGE_CONTROL, val);
247 power_supply_changed(&charger->psy);
250 static void da9030_charger_check_state(struct da9030_charger *charger)
252 da9030_charger_update_state(charger);
255 if (!charger->is_on) {
256 if ((charger->chdet) &&
257 (charger->adc.vbat_res <
258 charger->thresholds.vbat_charge_start)) {
259 da9030_set_charge(charger, 1);
263 if (!charger->chdet) {
264 da9030_set_charge(charger, 0);
268 if (charger->adc.vbat_res >=
269 charger->thresholds.vbat_charge_stop) {
270 da9030_set_charge(charger, 0);
271 da903x_write(charger->master, DA9030_VBATMON,
272 charger->thresholds.vbat_charge_restart);
273 } else if (charger->adc.vbat_res >
274 charger->thresholds.vbat_low) {
278 da903x_write(charger->master, DA9030_VBATMON,
279 charger->thresholds.vbat_low);
281 if (charger->adc.vchmax_res > charger->thresholds.vcharge_max ||
282 charger->adc.vchmin_res < charger->thresholds.vcharge_min ||
284 charger->adc.tbat_res < charger->thresholds.tbat_high ||
285 charger->adc.tbat_res > charger->thresholds.tbat_low) {
286 /* disable charger */
287 da9030_set_charge(charger, 0);
294 struct da9030_charger *charger;
296 charger = container_of(work, struct da9030_charger, work.work);
298 da9030_charger_check_state(charger);
301 schedule_delayed_work(&charger->work, charger->interval);
315 static void da9030_battery_check_status(struct da9030_charger *charger,
318 if (charger->chdet) {
319 if (charger->is_on)
328 static void da9030_battery_check_health(struct da9030_charger *charger,
331 if (charger->fault & DA9030_FAULT_LOG_OVER_TEMP)
333 else if (charger->fault & DA9030_FAULT_LOG_VBAT_OVER)
343 struct da9030_charger *charger;
344 charger = container_of(psy, struct da9030_charger, psy);
348 da9030_battery_check_status(charger, val);
351 da9030_battery_check_health(charger, val);
354 val->intval = charger->battery_info->technology;
357 val->intval = charger->battery_info->voltage_max_design;
360 val->intval = charger->battery_info->voltage_min_design;
363 val->intval = da9030_reg_to_mV(charger->adc.vbat_res) * 1000;
367 da9030_reg_to_mA(charger->adc.ichaverage_res) * 1000;
370 val->strval = charger->battery_info->name;
379 static void da9030_battery_vbat_event(struct da9030_charger *charger)
381 da9030_read_adc(charger, &charger->adc);
383 if (charger->is_on)
386 if (charger->adc.vbat_res < charger->thresholds.vbat_low) {
388 da903x_write(charger->master, DA9030_VBATMON,
389 charger->thresholds.vbat_crit);
390 if (charger->battery_low)
391 charger->battery_low();
392 } else if (charger->adc.vbat_res <
393 charger->thresholds.vbat_crit) {
395 if (charger->battery_critical)
396 charger->battery_critical();
403 struct da9030_charger *charger =
408 cancel_delayed_work_sync(&charger->work);
409 schedule_work(&charger->work.work);
412 da9030_battery_vbat_event(charger);
416 da9030_set_charge(charger, 0);
423 static void da9030_battery_convert_thresholds(struct da9030_charger *charger,
426 charger->thresholds.tbat_low = pdata->tbat_low;
427 charger->thresholds.tbat_high = pdata->tbat_high;
428 charger->thresholds.tbat_restart = pdata->tbat_restart;
430 charger->thresholds.vbat_low =
432 charger->thresholds.vbat_crit =
434 charger->thresholds.vbat_charge_start =
436 charger->thresholds.vbat_charge_stop =
438 charger->thresholds.vbat_charge_restart =
441 charger->thresholds.vcharge_min =
443 charger->thresholds.vcharge_max =
447 static void da9030_battery_setup_psy(struct da9030_charger *charger)
449 struct power_supply *psy = &charger->psy;
450 struct power_supply_info *info = charger->battery_info;
461 static int da9030_battery_charger_init(struct da9030_charger *charger)
466 v[0] = v[1] = charger->thresholds.vbat_low;
467 v[2] = charger->thresholds.tbat_high;
468 v[3] = charger->thresholds.tbat_restart;
469 v[4] = charger->thresholds.tbat_low;
471 ret = da903x_writes(charger->master, DA9030_VBATMON, 5, v);
479 ret = da903x_write(charger->master, DA9030_ADC_MAN_CONTROL,
486 return da903x_write(charger->master, DA9030_ADC_AUTO_CONTROL,
495 struct da9030_charger *charger;
507 charger = kzalloc(sizeof(*charger), GFP_KERNEL);
508 if (charger == NULL)
511 charger->master = pdev->dev.parent;
515 charger->interval = msecs_to_jiffies(
518 charger->charge_milliamp = pdata->charge_milliamp;
519 charger->charge_millivolt = pdata->charge_millivolt;
520 charger->battery_info = pdata->battery_info;
521 charger->battery_low = pdata->battery_low;
522 charger->battery_critical = pdata->battery_critical;
524 da9030_battery_convert_thresholds(charger, pdata);
526 ret = da9030_battery_charger_init(charger);
530 INIT_DELAYED_WORK(&charger->work, da9030_charging_monitor);
531 schedule_delayed_work(&charger->work, charger->interval);
533 charger->nb.notifier_call = da9030_battery_event;
534 ret = da903x_register_notifier(charger->master, &charger->nb,
542 da9030_battery_setup_psy(charger);
543 ret = power_supply_register(&pdev->dev, &charger->psy);
547 charger->debug_file = da9030_bat_create_debugfs(charger);
548 platform_set_drvdata(pdev, charger);
552 da903x_unregister_notifier(charger->master, &charger->nb,
556 cancel_delayed_work(&charger->work);
559 kfree(charger);
566 struct da9030_charger *charger = platform_get_drvdata(dev);
568 da9030_bat_remove_debugfs(charger);
570 da903x_unregister_notifier(charger->master, &charger->nb,
573 cancel_delayed_work_sync(&charger->work);
574 da9030_set_charge(charger, 0);
575 power_supply_unregister(&charger->psy);
577 kfree(charger);
604 MODULE_DESCRIPTION("DA9030 battery charger driver");