static int acpi_battery_read_state ( char *page, char **start, off_t off, int count, int *eof, void *data) { int result = 0; struct acpi_battery *battery = (struct acpi_battery *) data; struct acpi_battery_status *bst = NULL; char *units = "?"; char *p = page; int len = 0; ACPI_FUNCTION_TRACE("acpi_battery_read_state"); if (!battery || (off != 0)) goto end; if (battery->flags.present) p += sprintf(p, "present: yes\n"); else { p += sprintf(p, "present: no\n"); goto end; } /* Battery Units */ units = battery->flags.power_unit ? ACPI_BATTERY_UNITS_AMPS : ACPI_BATTERY_UNITS_WATTS; /* Battery Status (_BST) */ result = acpi_battery_get_status(battery, &bst); if (result || !bst) { p += sprintf(p, "ERROR: Unable to read battery status\n"); goto end; } if (!(bst->state & 0x04)) p += sprintf(p, "capacity state: ok\n"); else p += sprintf(p, "capacity state: critical\n"); if ((bst->state & 0x01) && (bst->state & 0x02)){ p += sprintf(p, "charging state: charging/discharging\n"); ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Battery Charging and Discharging?\n")); } else if (bst->state & 0x01) p += sprintf(p, "charging state: discharging\n"); else if (bst->state & 0x02) p += sprintf(p, "charging state: charging\n"); else { p += sprintf(p, "charging state: charged\n"); } if (bst->present_rate == ACPI_BATTERY_VALUE_UNKNOWN) p += sprintf(p, "present rate: unknown\n"); else p += sprintf(p, "present rate: %d %s\n", (u32) bst->present_rate, units); if (bst->remaining_capacity == ACPI_BATTERY_VALUE_UNKNOWN) p += sprintf(p, "remaining capacity: unknown\n"); else p += sprintf(p, "remaining capacity: %d %sh\n", (u32) bst->remaining_capacity, units); if (bst->present_voltage == ACPI_BATTERY_VALUE_UNKNOWN) p += sprintf(p, "present voltage: unknown\n"); else p += sprintf(p, "present voltage: %d mV\n", (u32) bst->present_voltage); end: kfree(bst); len = (p - page); if (len <= off+count) *eof = 1; *start = page + off; len -= off; if (len>count) len = count; if (len<0) len = 0; return_VALUE(len); }
static int acpi_battery_read_state(struct seq_file *seq, void *offset) { int result = 0; struct acpi_battery *battery = (struct acpi_battery *)seq->private; struct acpi_battery_status *bst = NULL; char *units = "?"; if (!battery) goto end; if (battery->flags.present) seq_printf(seq, "present: yes\n"); else { seq_printf(seq, "present: no\n"); goto end; } /* Battery Units */ units = battery->flags. power_unit ? ACPI_BATTERY_UNITS_AMPS : ACPI_BATTERY_UNITS_WATTS; /* Battery Status (_BST) */ result = acpi_battery_get_status(battery, &bst); if (result || !bst) { seq_printf(seq, "ERROR: Unable to read battery status\n"); goto end; } if (!(bst->state & 0x04)) seq_printf(seq, "capacity state: ok\n"); else seq_printf(seq, "capacity state: critical\n"); if ((bst->state & 0x01) && (bst->state & 0x02)) { seq_printf(seq, "charging state: charging/discharging\n"); } else if (bst->state & 0x01) seq_printf(seq, "charging state: discharging\n"); else if (bst->state & 0x02) seq_printf(seq, "charging state: charging\n"); else { seq_printf(seq, "charging state: charged\n"); } if (bst->present_rate == ACPI_BATTERY_VALUE_UNKNOWN) seq_printf(seq, "present rate: unknown\n"); else seq_printf(seq, "present rate: %d %s\n", (u32) bst->present_rate, units); if (bst->remaining_capacity == ACPI_BATTERY_VALUE_UNKNOWN) seq_printf(seq, "remaining capacity: unknown\n"); else seq_printf(seq, "remaining capacity: %d %sh\n", (u32) bst->remaining_capacity, units); if (bst->present_voltage == ACPI_BATTERY_VALUE_UNKNOWN) seq_printf(seq, "present voltage: unknown\n"); else seq_printf(seq, "present voltage: %d mV\n", (u32) bst->present_voltage); end: kfree(bst); return 0; }