/* 0 - every time, > 0 - by update_time */
static unsigned int update_time = 120;
-static unsigned int capacity_mode = CAPACITY_UNIT;
+static unsigned int mode = CAPACITY_UNIT;
module_param(update_time, uint, 0644);
-module_param(capacity_mode, uint, 0444);
+module_param(mode, uint, 0444);
static int acpi_sbs_add(struct acpi_device *device);
static int acpi_sbs_remove(struct acpi_device *device, int type);
},
};
-struct acpi_ac {
- int ac_present;
-};
-
-struct acpi_battery_info {
- int capacity_mode;
- s16 full_charge_capacity;
- s16 design_capacity;
- s16 design_voltage;
- int vscale;
- int ipscale;
- s16 serial_number;
- char manufacturer_name[ACPI_SBS_BLOCK_MAX + 3];
- char device_name[ACPI_SBS_BLOCK_MAX + 3];
- char device_chemistry[ACPI_SBS_BLOCK_MAX + 3];
-};
-
-struct acpi_battery_state {
- s16 voltage;
- s16 amperage;
- s16 remaining_capacity;
- s16 battery_state;
-};
-
-struct acpi_battery_alarm {
- s16 remaining_capacity;
-};
-
struct acpi_battery {
- int alive;
- int id;
- int init_state;
- int battery_present;
struct acpi_sbs *sbs;
- struct acpi_battery_info info;
- struct acpi_battery_state state;
- struct acpi_battery_alarm alarm;
- struct proc_dir_entry *battery_entry;
+ struct proc_dir_entry *proc_entry;
+ int vscale;
+ int ipscale;
+ char manufacturer_name[ACPI_SBS_BLOCK_MAX];
+ char device_name[ACPI_SBS_BLOCK_MAX];
+ char device_chemistry[ACPI_SBS_BLOCK_MAX];
+ u16 full_charge_capacity;
+ u16 design_capacity;
+ u16 design_voltage;
+ u16 serial_number;
+ u16 voltage_now;
+ s16 current_now;
+ u16 capacity_now;
+ u16 state;
+ u16 alarm_capacity;
+ u16 mode;
+ u8 id;
+ u8 alive:1;
+ u8 init_state:1;
+ u8 present:1;
};
struct acpi_sbs {
struct acpi_device *device;
struct acpi_smb_hc *hc;
struct mutex mutex;
- int sbsm_present;
- int sbsm_batteries_supported;
struct proc_dir_entry *ac_entry;
- struct acpi_ac ac;
struct acpi_battery battery[MAX_SBS_BAT];
int zombie;
struct timer_list update_timer;
int run_cnt;
int update_proc_flg;
+ u8 batteries_supported;
+ u8 manager_present:1;
+ u8 charger_present:1;
};
static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type);
if (!result) {
is_present = (state & 0x000f) & (1 << battery->id);
}
- battery->battery_present = is_present;
+ battery->present = is_present;
return result;
}
s16 state;
int foo;
- if (sbs->sbsm_present) {
+ if (sbs->manager_present) {
/* Take special care not to knobble other nibbles of
* state (aka selector_state), since
* it causes charging to halt on SBSELs */
- result =
- acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SBSM_SMBUS_ADDR, 0x01, (u8 *)&state);
+ result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD,
+ ACPI_SBSM_SMBUS_ADDR, 0x01, (u8 *)&state);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_read() failed"));
}
foo = (state & 0x0fff) | (1 << (battery->id + 12));
- result =
- acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD, ACPI_SBSM_SMBUS_ADDR, 0x01, (u8 *)&foo, 2);
+ result = acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD,
+ ACPI_SBSM_SMBUS_ADDR, 0x01, (u8 *)&foo, 2);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_write() failed"));
"acpi_smbus_read() failed"));
goto end;
}
- sbs->sbsm_present = 1;
- sbs->sbsm_batteries_supported = battery_system_info & 0x000f;
+ sbs->manager_present = 1;
end:
"acpi_smbus_read() failed"));
goto end;
}
- battery->info.capacity_mode = (battery_mode & 0x8000) >> 15;
+ battery->mode = (battery_mode & 0x8000) >> 15;
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SB_SMBUS_ADDR, 0x10,
- (u8 *)&battery->info.full_charge_capacity);
+ (u8 *)&battery->full_charge_capacity);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_read() failed"));
}
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SB_SMBUS_ADDR, 0x18,
- (u8 *)&battery->info.design_capacity);
+ (u8 *)&battery->design_capacity);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
}
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SB_SMBUS_ADDR, 0x19,
- (u8 *)&battery->info.design_voltage);
+ (u8 *)&battery->design_voltage);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_read() failed"));
switch ((specification_info & 0x0f00) >> 8) {
case 1:
- battery->info.vscale = 10;
+ battery->vscale = 10;
break;
case 2:
- battery->info.vscale = 100;
+ battery->vscale = 100;
break;
case 3:
- battery->info.vscale = 1000;
+ battery->vscale = 1000;
break;
default:
- battery->info.vscale = 1;
+ battery->vscale = 1;
}
switch ((specification_info & 0xf000) >> 12) {
case 1:
- battery->info.ipscale = 10;
+ battery->ipscale = 10;
break;
case 2:
- battery->info.ipscale = 100;
+ battery->ipscale = 100;
break;
case 3:
- battery->info.ipscale = 1000;
+ battery->ipscale = 1000;
break;
default:
- battery->info.ipscale = 1;
+ battery->ipscale = 1;
}
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SB_SMBUS_ADDR, 0x1c,
- (u8 *)&battery->info.serial_number);
+ (u8 *)&battery->serial_number);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_read() failed"));
}
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_BLOCK, ACPI_SB_SMBUS_ADDR, 0x20,
- (u8 *)battery->info.manufacturer_name);
+ (u8 *)battery->manufacturer_name);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_sbs_read_str() failed"));
}
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_BLOCK, ACPI_SB_SMBUS_ADDR, 0x21,
- (u8 *)battery->info.device_name);
+ (u8 *)battery->device_name);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_sbs_read_str() failed"));
}
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_BLOCK, ACPI_SB_SMBUS_ADDR, 0x22,
- (u8 *)battery->info.device_chemistry);
+ (u8 *)battery->device_chemistry);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_sbs_read_str() failed"));
int result = 0;
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SB_SMBUS_ADDR, 0x09,
- (u8 *)&battery->state.voltage);
+ (u8 *)&battery->voltage_now);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_read() failed"));
}
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SB_SMBUS_ADDR, 0x0a,
- (u8 *)&battery->state.amperage);
+ (u8 *)&battery->current_now);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_read() failed"));
}
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SB_SMBUS_ADDR, 0x0f,
- (u8 *)&battery->state.remaining_capacity);
+ (u8 *)&battery->capacity_now);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_read() failed"));
}
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SB_SMBUS_ADDR, 0x16,
- (u8 *)&battery->state.battery_state);
+ (u8 *)&battery->state);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_read() failed"));
int result = 0;
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SB_SMBUS_ADDR, 0x01,
- (u8 *)&battery->alarm.remaining_capacity);
+ (u8 *)&battery->alarm_capacity);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_read() failed"));
}
}
- foo = alarm / (battery->info.capacity_mode ? 10 : 1);
- result = acpi_smbus_write(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SB_SMBUS_ADDR, 0x01, (u8 *)&foo, 2);
+ foo = alarm / (battery->mode ? 10 : 1);
+ result = acpi_smbus_write(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SB_SMBUS_ADDR, 0x01,
+ (u8 *)&foo, 2);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_write() failed"));
int result = 0;
s16 battery_mode;
- if (capacity_mode == DEF_CAPACITY_UNIT) {
+ if (mode == DEF_CAPACITY_UNIT) {
goto end;
}
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD,
- ACPI_SB_SMBUS_ADDR, 0x03, (u8 *)&battery_mode);
+ ACPI_SB_SMBUS_ADDR, 0x03, (u8 *)&battery_mode);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_read() failed"));
goto end;
}
- if (capacity_mode == MAH_CAPACITY_UNIT) {
+ if (mode == MAH_CAPACITY_UNIT) {
battery_mode &= 0x7fff;
} else {
battery_mode |= 0x8000;
}
result = acpi_smbus_write(battery->sbs->hc, SMBUS_READ_WORD,
- ACPI_SB_SMBUS_ADDR, 0x03, (u8 *)&battery_mode, 2);
+ ACPI_SB_SMBUS_ADDR, 0x03, (u8 *)&battery_mode, 2);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_write() failed"));
}
result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD,
- ACPI_SB_SMBUS_ADDR, 0x03, (u8 *)&battery_mode);
+ ACPI_SB_SMBUS_ADDR, 0x03, (u8 *)&battery_mode);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_read() failed"));
s16 charger_status;
result = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBC_SMBUS_ADDR, 0x13,
- (u8 *)&charger_status);
+ (u8 *)&charger_status);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
goto end;
}
- sbs->ac.ac_present = (charger_status & 0x8000) >> 15;
+ sbs->charger_present = (charger_status & 0x8000) >> 15;
end:
}
}
- if (battery->battery_present) {
+ if (battery->present) {
seq_printf(seq, "present: yes\n");
} else {
seq_printf(seq, "present: no\n");
goto end;
}
- if (battery->info.capacity_mode) {
- cscale = battery->info.vscale * battery->info.ipscale;
+ if (battery->mode) {
+ cscale = battery->vscale * battery->ipscale;
} else {
- cscale = battery->info.ipscale;
+ cscale = battery->ipscale;
}
seq_printf(seq, "design capacity: %i%s\n",
- battery->info.design_capacity * cscale,
- battery->info.capacity_mode ? "0 mWh" : " mAh");
+ battery->design_capacity * cscale,
+ battery->mode ? "0 mWh" : " mAh");
seq_printf(seq, "last full capacity: %i%s\n",
- battery->info.full_charge_capacity * cscale,
- battery->info.capacity_mode ? "0 mWh" : " mAh");
+ battery->full_charge_capacity * cscale,
+ battery->mode ? "0 mWh" : " mAh");
seq_printf(seq, "battery technology: rechargeable\n");
seq_printf(seq, "design voltage: %i mV\n",
- battery->info.design_voltage * battery->info.vscale);
+ battery->design_voltage * battery->vscale);
seq_printf(seq, "design capacity warning: unknown\n");
seq_printf(seq, "design capacity low: unknown\n");
seq_printf(seq, "capacity granularity 2: unknown\n");
seq_printf(seq, "model number: %s\n",
- battery->info.device_name);
+ battery->device_name);
seq_printf(seq, "serial number: %i\n",
- battery->info.serial_number);
+ battery->serial_number);
seq_printf(seq, "battery type: %s\n",
- battery->info.device_chemistry);
+ battery->device_chemistry);
seq_printf(seq, "OEM info: %s\n",
- battery->info.manufacturer_name);
+ battery->manufacturer_name);
end:
}
}
- if (battery->battery_present) {
+ if (battery->present) {
seq_printf(seq, "present: yes\n");
} else {
seq_printf(seq, "present: no\n");
goto end;
}
- if (battery->info.capacity_mode) {
- cscale = battery->info.vscale * battery->info.ipscale;
+ if (battery->mode) {
+ cscale = battery->vscale * battery->ipscale;
} else {
- cscale = battery->info.ipscale;
+ cscale = battery->ipscale;
}
- if (battery->state.battery_state & 0x0010) {
+ if (battery->state & 0x0010) {
seq_printf(seq, "capacity state: critical\n");
} else {
seq_printf(seq, "capacity state: ok\n");
}
- foo = (s16) battery->state.amperage * battery->info.ipscale;
- if (battery->info.capacity_mode) {
- foo = foo * battery->info.design_voltage / 1000;
+ foo = (s16) battery->current_now * battery->ipscale;
+ if (battery->mode) {
+ foo = foo * battery->design_voltage / 1000;
}
- if (battery->state.amperage < 0) {
+ if (battery->current_now < 0) {
seq_printf(seq, "charging state: discharging\n");
seq_printf(seq, "present rate: %d %s\n",
- -foo, battery->info.capacity_mode ? "mW" : "mA");
- } else if (battery->state.amperage > 0) {
+ -foo, battery->mode ? "mW" : "mA");
+ } else if (battery->current_now > 0) {
seq_printf(seq, "charging state: charging\n");
seq_printf(seq, "present rate: %d %s\n",
- foo, battery->info.capacity_mode ? "mW" : "mA");
+ foo, battery->mode ? "mW" : "mA");
} else {
seq_printf(seq, "charging state: charged\n");
seq_printf(seq, "present rate: 0 %s\n",
- battery->info.capacity_mode ? "mW" : "mA");
+ battery->mode ? "mW" : "mA");
}
seq_printf(seq, "remaining capacity: %i%s\n",
- battery->state.remaining_capacity * cscale,
- battery->info.capacity_mode ? "0 mWh" : " mAh");
+ battery->capacity_now * cscale,
+ battery->mode ? "0 mWh" : " mAh");
seq_printf(seq, "present voltage: %i mV\n",
- battery->state.voltage * battery->info.vscale);
+ battery->voltage_now * battery->vscale);
end:
}
}
- if (!battery->battery_present) {
+ if (!battery->present) {
seq_printf(seq, "present: no\n");
goto end;
}
- if (battery->info.capacity_mode) {
- cscale = battery->info.vscale * battery->info.ipscale;
+ if (battery->mode) {
+ cscale = battery->vscale * battery->ipscale;
} else {
- cscale = battery->info.ipscale;
+ cscale = battery->ipscale;
}
seq_printf(seq, "alarm: ");
- if (battery->alarm.remaining_capacity) {
+ if (battery->alarm_capacity) {
seq_printf(seq, "%i%s\n",
- battery->alarm.remaining_capacity * cscale,
- battery->info.capacity_mode ? "0 mWh" : " mAh");
+ battery->alarm_capacity * cscale,
+ battery->mode ? "0 mWh" : " mAh");
} else {
seq_printf(seq, "disabled\n");
}
if (result)
goto end;
- if (!battery->battery_present) {
+ if (!battery->present) {
result = -ENODEV;
goto end;
}
alarm_string[count] = 0;
- old_alarm = battery->alarm.remaining_capacity;
+ old_alarm = battery->alarm_capacity;
new_alarm = simple_strtoul(alarm_string, NULL, 0);
result = acpi_battery_set_alarm(battery, new_alarm);
}
seq_printf(seq, "state: %s\n",
- sbs->ac.ac_present ? "on-line" : "off-line");
+ sbs->charger_present ? "on-line" : "off-line");
sbs_mutex_unlock(sbs);
goto end;
}
- is_present = battery->battery_present;
+ is_present = battery->present;
if (is_present) {
result = acpi_battery_init(battery);
sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
- result = acpi_sbs_generic_add_fs(&battery->battery_entry,
+ result = acpi_sbs_generic_add_fs(&battery->proc_entry,
acpi_battery_dir,
dir_name,
&acpi_battery_info_fops,
printk(KERN_INFO PREFIX "%s [%s]: Battery Slot [%s] (battery %s)\n",
ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), dir_name,
- sbs->battery->battery_present ? "present" : "absent");
+ sbs->battery->present ? "present" : "absent");
end:
return result;
static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
{
- if (sbs->battery[id].battery_entry) {
- acpi_sbs_generic_remove_fs(&(sbs->battery[id].battery_entry),
+ if (sbs->battery[id].proc_entry) {
+ acpi_sbs_generic_remove_fs(&(sbs->battery[id].proc_entry),
acpi_battery_dir);
}
}
printk(KERN_INFO PREFIX "%s [%s]: AC Adapter [%s] (%s)\n",
ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device),
- ACPI_AC_DIR_NAME, sbs->ac.ac_present ? "on-line" : "off-line");
+ ACPI_AC_DIR_NAME, sbs->charger_present ? "on-line" : "off-line");
end:
struct acpi_battery *battery;
int result = 0, cnt;
int old_ac_present = -1;
- int old_battery_present = -1;
+ int old_present = -1;
int new_ac_present = -1;
- int new_battery_present = -1;
+ int new_present = -1;
int id_min = 0, id_max = MAX_SBS_BAT - 1;
char dir_name[32];
int do_battery_init = 0, do_ac_init = 0;
sbs->run_cnt++;
- old_ac_present = sbs->ac.ac_present;
+ if (!update_battery) {
+ goto end;
+ }
+
+ old_ac_present = sbs->charger_present;
result = acpi_ac_get_present(sbs);
if (result) {
"acpi_ac_get_present() failed"));
}
- new_ac_present = sbs->ac.ac_present;
+ new_ac_present = sbs->charger_present;
do_ac_init = (old_ac_present != new_ac_present);
if (sbs->run_cnt == 1 && data_type == DATA_TYPE_COMMON) {
continue;
}
- old_remaining_capacity = battery->state.remaining_capacity;
+ old_remaining_capacity = battery->capacity_now;
- old_battery_present = battery->battery_present;
+ old_present = battery->present;
result = acpi_battery_select(battery);
if (result) {
"acpi_battery_get_present() failed"));
}
- new_battery_present = battery->battery_present;
+ new_present = battery->present;
- do_battery_init = ((old_battery_present != new_battery_present)
- && new_battery_present);
- if (!new_battery_present)
+ do_battery_init = ((old_present != new_present)
+ && new_present);
+ if (!new_present)
goto event;
if (do_ac_init || do_battery_init) {
result = acpi_battery_init(battery);
if ((data_type == DATA_TYPE_COMMON
|| data_type == DATA_TYPE_INFO)
- && new_battery_present) {
+ && new_present) {
result = acpi_battery_get_info(battery);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
if ((data_type == DATA_TYPE_COMMON
|| data_type == DATA_TYPE_STATE)
- && new_battery_present) {
+ && new_present) {
result = acpi_battery_get_state(battery);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
if ((data_type == DATA_TYPE_COMMON
|| data_type == DATA_TYPE_ALARM)
- && new_battery_present) {
+ && new_present) {
result = acpi_battery_get_alarm(battery);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
event:
- if (old_battery_present != new_battery_present || do_ac_init ||
+ if (old_present != new_present || do_ac_init ||
old_remaining_capacity !=
- battery->state.remaining_capacity) {
+ battery->capacity_now) {
sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
result = acpi_bus_generate_proc_event4(ACPI_BATTERY_CLASS,
dir_name,
ACPI_SBS_BATTERY_NOTIFY_STATUS,
- new_battery_present);
+ new_present);
acpi_bus_generate_netlink_event(ACPI_BATTERY_CLASS, dir_name,
ACPI_SBS_BATTERY_NOTIFY_STATUS,
- new_battery_present);
+ new_present);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_bus_generate_proc_event4() "
acpi_sbsm_get_info(sbs);
- if (!sbs->sbsm_present) {
+ if (!sbs->manager_present) {
result = acpi_battery_add(sbs, 0);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
}
} else {
for (id = 0; id < MAX_SBS_BAT; id++) {
- if ((sbs->sbsm_batteries_supported & (1 << id))) {
+ if ((sbs->batteries_supported & (1 << id))) {
result = acpi_battery_add(sbs, id);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
if (acpi_disabled)
return -ENODEV;
- if (capacity_mode != DEF_CAPACITY_UNIT
- && capacity_mode != MAH_CAPACITY_UNIT
- && capacity_mode != MWH_CAPACITY_UNIT) {
+ if (mode != DEF_CAPACITY_UNIT
+ && mode != MAH_CAPACITY_UNIT
+ && mode != MWH_CAPACITY_UNIT) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
- "invalid capacity_mode = %d", capacity_mode));
+ "invalid mode = %d", mode));
return -EINVAL;
}