Skip to content

Commit

Permalink
* fix bst.status. We mark some bits, but forgot to reset all of them
Browse files Browse the repository at this point in the history
  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
  • Loading branch information
bruno authored and bruno committed Jan 12, 2006
1 parent 91d3ed7 commit 7f7a28f
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions sys/dev/acpica/acpi_smbat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7f7a28f

Please sign in to comment.