Lines Matching refs:battery
90 struct acpi_battery battery[MAX_SBS_BAT]; member
100 static int acpi_battery_get_state(struct acpi_battery *battery);
110 static inline int acpi_battery_vscale(struct acpi_battery *battery) in acpi_battery_vscale() argument
112 return battery_scale((battery->spec & 0x0f00) >> 8); in acpi_battery_vscale()
115 static inline int acpi_battery_ipscale(struct acpi_battery *battery) in acpi_battery_ipscale() argument
117 return battery_scale((battery->spec & 0xf000) >> 12); in acpi_battery_ipscale()
120 static inline int acpi_battery_mode(struct acpi_battery *battery) in acpi_battery_mode() argument
122 return (battery->mode & 0x8000); in acpi_battery_mode()
125 static inline int acpi_battery_scale(struct acpi_battery *battery) in acpi_battery_scale() argument
127 return (acpi_battery_mode(battery) ? 10 : 1) * in acpi_battery_scale()
128 acpi_battery_ipscale(battery); in acpi_battery_scale()
146 static int acpi_battery_technology(struct acpi_battery *battery) in acpi_battery_technology() argument
148 if (!strcasecmp("NiCd", battery->device_chemistry)) in acpi_battery_technology()
150 if (!strcasecmp("NiMH", battery->device_chemistry)) in acpi_battery_technology()
152 if (!strcasecmp("LION", battery->device_chemistry)) in acpi_battery_technology()
154 if (!strcasecmp("LiP", battery->device_chemistry)) in acpi_battery_technology()
163 struct acpi_battery *battery = to_acpi_battery(psy); in acpi_sbs_battery_get_property() local
165 if ((!battery->present) && psp != POWER_SUPPLY_PROP_PRESENT) in acpi_sbs_battery_get_property()
168 acpi_battery_get_state(battery); in acpi_sbs_battery_get_property()
171 if (battery->rate_now < 0) in acpi_sbs_battery_get_property()
173 else if (battery->rate_now > 0) in acpi_sbs_battery_get_property()
179 val->intval = battery->present; in acpi_sbs_battery_get_property()
182 val->intval = acpi_battery_technology(battery); in acpi_sbs_battery_get_property()
185 val->intval = battery->cycle_count; in acpi_sbs_battery_get_property()
188 val->intval = battery->design_voltage * in acpi_sbs_battery_get_property()
189 acpi_battery_vscale(battery) * 1000; in acpi_sbs_battery_get_property()
192 val->intval = battery->voltage_now * in acpi_sbs_battery_get_property()
193 acpi_battery_vscale(battery) * 1000; in acpi_sbs_battery_get_property()
197 val->intval = abs(battery->rate_now) * in acpi_sbs_battery_get_property()
198 acpi_battery_ipscale(battery) * 1000; in acpi_sbs_battery_get_property()
199 val->intval *= (acpi_battery_mode(battery)) ? in acpi_sbs_battery_get_property()
200 (battery->voltage_now * in acpi_sbs_battery_get_property()
201 acpi_battery_vscale(battery) / 1000) : 1; in acpi_sbs_battery_get_property()
205 val->intval = abs(battery->rate_avg) * in acpi_sbs_battery_get_property()
206 acpi_battery_ipscale(battery) * 1000; in acpi_sbs_battery_get_property()
207 val->intval *= (acpi_battery_mode(battery)) ? in acpi_sbs_battery_get_property()
208 (battery->voltage_now * in acpi_sbs_battery_get_property()
209 acpi_battery_vscale(battery) / 1000) : 1; in acpi_sbs_battery_get_property()
212 val->intval = battery->state_of_charge; in acpi_sbs_battery_get_property()
216 val->intval = battery->design_capacity * in acpi_sbs_battery_get_property()
217 acpi_battery_scale(battery) * 1000; in acpi_sbs_battery_get_property()
221 val->intval = battery->full_charge_capacity * in acpi_sbs_battery_get_property()
222 acpi_battery_scale(battery) * 1000; in acpi_sbs_battery_get_property()
226 val->intval = battery->capacity_now * in acpi_sbs_battery_get_property()
227 acpi_battery_scale(battery) * 1000; in acpi_sbs_battery_get_property()
230 val->intval = battery->temp_now - 2730; // dK -> dC in acpi_sbs_battery_get_property()
233 val->strval = battery->device_name; in acpi_sbs_battery_get_property()
236 val->strval = battery->manufacturer_name; in acpi_sbs_battery_get_property()
339 static int acpi_battery_get_info(struct acpi_battery *battery) in acpi_battery_get_info() argument
344 result = acpi_smbus_read(battery->sbs->hc, in acpi_battery_get_info()
348 (u8 *) battery + in acpi_battery_get_info()
356 static int acpi_battery_get_state(struct acpi_battery *battery) in acpi_battery_get_state() argument
360 if (battery->update_time && in acpi_battery_get_state()
361 time_before(jiffies, battery->update_time + in acpi_battery_get_state()
365 result = acpi_smbus_read(battery->sbs->hc, in acpi_battery_get_state()
369 (u8 *)battery + in acpi_battery_get_state()
375 battery->update_time = jiffies; in acpi_battery_get_state()
379 static int acpi_battery_get_alarm(struct acpi_battery *battery) in acpi_battery_get_alarm() argument
381 return acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, in acpi_battery_get_alarm()
383 (u8 *)&battery->alarm_capacity); in acpi_battery_get_alarm()
386 static int acpi_battery_set_alarm(struct acpi_battery *battery) in acpi_battery_set_alarm() argument
388 struct acpi_sbs *sbs = battery->sbs; in acpi_battery_set_alarm()
389 u16 value, sel = 1 << (battery->id + 12); in acpi_battery_set_alarm()
410 0x01, (u8 *)&battery->alarm_capacity, 2); in acpi_battery_set_alarm()
445 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); in acpi_battery_alarm_show() local
446 acpi_battery_get_alarm(battery); in acpi_battery_alarm_show()
447 return sprintf(buf, "%d\n", battery->alarm_capacity * in acpi_battery_alarm_show()
448 acpi_battery_scale(battery) * 1000); in acpi_battery_alarm_show()
456 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); in acpi_battery_alarm_store() local
458 battery->alarm_capacity = x / in acpi_battery_alarm_store()
459 (1000 * acpi_battery_scale(battery)); in acpi_battery_alarm_store()
460 if (battery->present) in acpi_battery_alarm_store()
461 acpi_battery_set_alarm(battery); in acpi_battery_alarm_store()
474 static int acpi_battery_read(struct acpi_battery *battery) in acpi_battery_read() argument
476 int result = 0, saved_present = battery->present; in acpi_battery_read()
479 if (battery->sbs->manager_present) { in acpi_battery_read()
480 result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, in acpi_battery_read()
483 battery->present = state & (1 << battery->id); in acpi_battery_read()
485 state |= 1 << (battery->id + 12); in acpi_battery_read()
486 acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD, in acpi_battery_read()
488 } else if (battery->id == 0) in acpi_battery_read()
489 battery->present = 1; in acpi_battery_read()
491 if (result || !battery->present) in acpi_battery_read()
494 if (saved_present != battery->present) { in acpi_battery_read()
495 battery->update_time = 0; in acpi_battery_read()
496 result = acpi_battery_get_info(battery); in acpi_battery_read()
498 battery->present = 0; in acpi_battery_read()
502 result = acpi_battery_get_state(battery); in acpi_battery_read()
504 battery->present = 0; in acpi_battery_read()
511 struct acpi_battery *battery = &sbs->battery[id]; in acpi_battery_add() local
512 struct power_supply_config psy_cfg = { .drv_data = battery, }; in acpi_battery_add()
515 battery->id = id; in acpi_battery_add()
516 battery->sbs = sbs; in acpi_battery_add()
517 result = acpi_battery_read(battery); in acpi_battery_add()
521 sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id); in acpi_battery_add()
522 battery->bat_desc.name = battery->name; in acpi_battery_add()
523 battery->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY; in acpi_battery_add()
524 if (!acpi_battery_mode(battery)) { in acpi_battery_add()
525 battery->bat_desc.properties = sbs_charge_battery_props; in acpi_battery_add()
526 battery->bat_desc.num_properties = in acpi_battery_add()
529 battery->bat_desc.properties = sbs_energy_battery_props; in acpi_battery_add()
530 battery->bat_desc.num_properties = in acpi_battery_add()
533 battery->bat_desc.get_property = acpi_sbs_battery_get_property; in acpi_battery_add()
534 battery->bat = power_supply_register(&sbs->device->dev, in acpi_battery_add()
535 &battery->bat_desc, &psy_cfg); in acpi_battery_add()
536 if (IS_ERR(battery->bat)) { in acpi_battery_add()
537 result = PTR_ERR(battery->bat); in acpi_battery_add()
538 battery->bat = NULL; in acpi_battery_add()
542 result = device_create_file(&battery->bat->dev, &alarm_attr); in acpi_battery_add()
545 battery->have_sysfs_alarm = 1; in acpi_battery_add()
549 battery->name, battery->present ? "present" : "absent"); in acpi_battery_add()
555 struct acpi_battery *battery = &sbs->battery[id]; in acpi_battery_remove() local
557 if (battery->bat) { in acpi_battery_remove()
558 if (battery->have_sysfs_alarm) in acpi_battery_remove()
559 device_remove_file(&battery->bat->dev, &alarm_attr); in acpi_battery_remove()
560 power_supply_unregister(battery->bat); in acpi_battery_remove()
611 bat = &sbs->battery[id]; in acpi_sbs_callback()