* fix bst.status. We mark some bits, but forgot to reset all of them

before.  The symptom is that the battery inform us its charge and discharge
  at the same time...

* fix bst.rate to correctly output the (dis)charging rate.  We'll use
  the current average over one minute command and not the at_rate command.
  Note that this method is not correct if the capacity_mode is set, but
  since we don't set it ourself, it is not a problem.

  The at_rate do not give the actual rate but is used to compute the
  estimated time for (dis)charging a battery.  We should actually
  write an estimation of the actual rate using at_rate cmd and then
  perform a read to the various estimators.

Approved by:	njl
MFC after:	2 days
This commit is contained in:
Bruno Ducrot 2006-01-12 21:56:37 +00:00
parent 04b3fa1623
commit ab033fa0e3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=154273

View File

@ -341,27 +341,28 @@ acpi_smbat_get_bst(device_t dev, struct acpi_bst *bst)
if (acpi_smbus_read_2(sc, addr, SMBATT_CMD_BATTERY_STATUS, &val))
goto out;
if (val & SMBATT_BS_DISCHARGING) {
sc->bst.state = 0;
if (val & SMBATT_BS_DISCHARGING)
sc->bst.state |= ACPI_BATT_STAT_DISCHARG;
/*
* If the rate is negative, it is discharging. Otherwise,
* it is charging.
*/
if (acpi_smbus_read_2(sc, addr, SMBATT_CMD_AT_RATE, &val))
goto out;
if (val < 0)
sc->bst.rate = (-val) * factor;
else
sc->bst.rate = -1;
} else {
sc->bst.state |= ACPI_BATT_STAT_CHARGING;
sc->bst.rate = -1;
}
if (val & SMBATT_BS_REMAINING_CAPACITY_ALARM)
sc->bst.state |= ACPI_BATT_STAT_CRITICAL;
/*
* If the rate is negative, it is discharging. Otherwise,
* it is charging.
*/
if (acpi_smbus_read_2(sc, addr, SMBATT_CMD_CURRENT, &val))
goto out;
if (val > 0) {
sc->bst.rate = val * factor;
sc->bst.state |= ACPI_BATT_STAT_CHARGING;
} else if (val < 0)
sc->bst.rate = (-val) * factor;
else
sc->bst.rate = 0;
if (acpi_smbus_read_2(sc, addr, SMBATT_CMD_REMAINING_CAPACITY, &val))
goto out;
sc->bst.cap = val * factor;