Lines Matching +full:system +full:- +full:critical +full:- +full:regulator
1 // SPDX-License-Identifier: GPL-2.0-only
115 /* platform callbacks for battery low and critical events */
129 return ((mV - 2650) << 8) / 2650;
140 struct da9030_charger *charger = s->private;
142 seq_printf(s, "charger is %s\n", str_on_off(charger->is_on));
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));
180 charger->debug_file = debugfs_create_file("charger", 0666, NULL,
182 return charger->debug_file;
187 debugfs_remove(charger->debug_file);
202 da903x_reads(charger->master, DA9030_VBAT_RES,
210 da903x_read(charger->master, DA9030_CHARGE_CONTROL, &val);
211 charger->is_on = (val & DA9030_CHRG_CHARGER_ENABLE) ? 1 : 0;
212 charger->mA = ((val >> 3) & 0xf) * 100;
213 charger->mV = (val & 0x7) * 50 + 4000;
215 da9030_read_adc(charger, &charger->adc);
216 da903x_read(charger->master, DA9030_FAULT_LOG, &charger->fault);
217 charger->chdet = da903x_query_status(charger->master,
227 val |= (charger->charge_milliamp / 100) << 3;
228 val |= (charger->charge_millivolt - 4000) / 50;
229 charger->is_on = 1;
232 charger->is_on = 0;
235 da903x_write(charger->master, DA9030_CHARGE_CONTROL, val);
237 power_supply_changed(charger->psy);
245 if (!charger->is_on) {
246 if ((charger->chdet) &&
247 (charger->adc.vbat_res <
248 charger->thresholds.vbat_charge_start)) {
253 if (!charger->chdet) {
258 if (charger->adc.vbat_res >=
259 charger->thresholds.vbat_charge_stop) {
261 da903x_write(charger->master, DA9030_VBATMON,
262 charger->thresholds.vbat_charge_restart);
263 } else if (charger->adc.vbat_res >
264 charger->thresholds.vbat_low) {
268 da903x_write(charger->master, DA9030_VBATMON,
269 charger->thresholds.vbat_low);
271 if (charger->adc.vchmax_res > charger->thresholds.vcharge_max ||
272 charger->adc.vchmin_res < charger->thresholds.vcharge_min ||
274 charger->adc.tbat_res < charger->thresholds.tbat_high ||
275 charger->adc.tbat_res > charger->thresholds.tbat_low) {
291 schedule_delayed_work(&charger->work, charger->interval);
308 if (charger->chdet) {
309 if (charger->is_on)
310 val->intval = POWER_SUPPLY_STATUS_CHARGING;
312 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
314 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
321 if (charger->fault & DA9030_FAULT_LOG_OVER_TEMP)
322 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
323 else if (charger->fault & DA9030_FAULT_LOG_VBAT_OVER)
324 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
326 val->intval = POWER_SUPPLY_HEALTH_GOOD;
343 val->intval = charger->battery_info->technology;
346 val->intval = charger->battery_info->voltage_max_design;
349 val->intval = charger->battery_info->voltage_min_design;
352 val->intval = da9030_reg_to_mV(charger->adc.vbat_res) * 1000;
355 val->intval =
356 da9030_reg_to_mA(charger->adc.ichaverage_res) * 1000;
359 val->strval = charger->battery_info->name;
370 da9030_read_adc(charger, &charger->adc);
372 if (charger->is_on)
375 if (charger->adc.vbat_res < charger->thresholds.vbat_low) {
376 /* set VBAT threshold for critical */
377 da903x_write(charger->master, DA9030_VBATMON,
378 charger->thresholds.vbat_crit);
379 if (charger->battery_low)
380 charger->battery_low();
381 } else if (charger->adc.vbat_res <
382 charger->thresholds.vbat_crit) {
383 /* notify the system of battery critical */
384 if (charger->battery_critical)
385 charger->battery_critical();
397 cancel_delayed_work_sync(&charger->work);
398 schedule_work(&charger->work.work);
415 charger->thresholds.tbat_low = pdata->tbat_low;
416 charger->thresholds.tbat_high = pdata->tbat_high;
417 charger->thresholds.tbat_restart = pdata->tbat_restart;
419 charger->thresholds.vbat_low =
420 da9030_millivolt_to_reg(pdata->vbat_low);
421 charger->thresholds.vbat_crit =
422 da9030_millivolt_to_reg(pdata->vbat_crit);
423 charger->thresholds.vbat_charge_start =
424 da9030_millivolt_to_reg(pdata->vbat_charge_start);
425 charger->thresholds.vbat_charge_stop =
426 da9030_millivolt_to_reg(pdata->vbat_charge_stop);
427 charger->thresholds.vbat_charge_restart =
428 da9030_millivolt_to_reg(pdata->vbat_charge_restart);
430 charger->thresholds.vcharge_min =
431 da9030_millivolt_to_reg(pdata->vcharge_min);
432 charger->thresholds.vcharge_max =
433 da9030_millivolt_to_reg(pdata->vcharge_max);
438 struct power_supply_desc *psy_desc = &charger->psy_desc;
439 struct power_supply_info *info = charger->battery_info;
441 psy_desc->name = info->name;
442 psy_desc->use_for_apm = info->use_for_apm;
443 psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
444 psy_desc->get_property = da9030_battery_get_property;
446 psy_desc->properties = da9030_battery_props;
447 psy_desc->num_properties = ARRAY_SIZE(da9030_battery_props);
455 v[0] = v[1] = charger->thresholds.vbat_low;
456 v[2] = charger->thresholds.tbat_high;
457 v[3] = charger->thresholds.tbat_restart;
458 v[4] = charger->thresholds.tbat_low;
460 ret = da903x_writes(charger->master, DA9030_VBATMON, 5, v);
466 * regulator. Must be set before ADC measurements can be made.
468 ret = da903x_write(charger->master, DA9030_ADC_MAN_CONTROL,
475 return da903x_write(charger->master, DA9030_ADC_AUTO_CONTROL,
486 struct da9030_battery_info *pdata = pdev->dev.platform_data;
490 return -EINVAL;
492 if (pdata->charge_milliamp >= 1500 ||
493 pdata->charge_millivolt < 4000 ||
494 pdata->charge_millivolt > 4350)
495 return -EINVAL;
497 charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
499 return -ENOMEM;
501 charger->master = pdev->dev.parent;
505 charger->interval = msecs_to_jiffies(
506 (pdata->batmon_interval ? : 10) * 1000);
508 charger->charge_milliamp = pdata->charge_milliamp;
509 charger->charge_millivolt = pdata->charge_millivolt;
510 charger->battery_info = pdata->battery_info;
511 charger->battery_low = pdata->battery_low;
512 charger->battery_critical = pdata->battery_critical;
520 INIT_DELAYED_WORK(&charger->work, da9030_charging_monitor);
521 schedule_delayed_work(&charger->work, charger->interval);
523 charger->nb.notifier_call = da9030_battery_event;
524 ret = da903x_register_notifier(charger->master, &charger->nb,
534 charger->psy = devm_power_supply_register(&pdev->dev,
535 &charger->psy_desc,
537 if (IS_ERR(charger->psy)) {
538 ret = PTR_ERR(charger->psy);
542 charger->debug_file = da9030_bat_create_debugfs(charger);
547 da903x_unregister_notifier(charger->master, &charger->nb,
551 cancel_delayed_work(&charger->work);
563 da903x_unregister_notifier(charger->master, &charger->nb,
566 cancel_delayed_work_sync(&charger->work);
572 .name = "da903x-battery",