Lines Matching full:sbs
3 * sbs.c - ACPI Smart Battery System Driver ($Revision: 2.0 $)
28 #define ACPI_SBS_CLASS "sbs"
57 struct acpi_sbs *sbs; member
134 struct acpi_sbs *sbs = to_acpi_sbs(psy); in sbs_get_ac_property() local
137 val->intval = sbs->charger_present; in sbs_get_ac_property()
285 .name = "sbs-charger",
326 static int acpi_manager_get_info(struct acpi_sbs *sbs) in acpi_manager_get_info() argument
331 result = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBS_MANAGER, in acpi_manager_get_info()
334 sbs->batteries_supported = battery_system_info & 0x000f; in acpi_manager_get_info()
343 result = acpi_smbus_read(battery->sbs->hc, in acpi_battery_get_info()
364 result = acpi_smbus_read(battery->sbs->hc, in acpi_battery_get_state()
380 return acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, in acpi_battery_get_alarm()
387 struct acpi_sbs *sbs = battery->sbs; in acpi_battery_set_alarm() local
393 if (sbs->manager_present) { in acpi_battery_set_alarm()
394 ret = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBS_MANAGER, in acpi_battery_set_alarm()
401 ret = acpi_smbus_write(sbs->hc, SMBUS_WRITE_WORD, in acpi_battery_set_alarm()
408 ret = acpi_smbus_write(sbs->hc, SMBUS_WRITE_WORD, ACPI_SBS_BATTERY, in acpi_battery_set_alarm()
414 static int acpi_ac_get_present(struct acpi_sbs *sbs) in acpi_ac_get_present() argument
419 result = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBS_CHARGER, in acpi_ac_get_present()
427 * that the implementation doesn't support an SBS charger. in acpi_ac_get_present()
431 * wrong, so ignore the SBS charger for those too. in acpi_ac_get_present()
436 sbs->charger_present = (status >> 15) & 0x1; in acpi_ac_get_present()
484 if (battery->sbs->manager_present) { in acpi_battery_read()
485 result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, in acpi_battery_read()
497 acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD, in acpi_battery_read()
523 static int acpi_battery_add(struct acpi_sbs *sbs, int id) in acpi_battery_add() argument
525 struct acpi_battery *battery = &sbs->battery[id]; in acpi_battery_add()
533 battery->sbs = sbs; in acpi_battery_add()
551 battery->bat = power_supply_register(&sbs->device->dev, in acpi_battery_add()
561 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), in acpi_battery_add()
566 static void acpi_battery_remove(struct acpi_sbs *sbs, int id) in acpi_battery_remove() argument
568 struct acpi_battery *battery = &sbs->battery[id]; in acpi_battery_remove()
574 static int acpi_charger_add(struct acpi_sbs *sbs) in acpi_charger_add() argument
577 struct power_supply_config psy_cfg = { .drv_data = sbs, }; in acpi_charger_add()
579 result = acpi_ac_get_present(sbs); in acpi_charger_add()
583 sbs->charger_exists = 1; in acpi_charger_add()
584 sbs->charger = power_supply_register(&sbs->device->dev, in acpi_charger_add()
586 if (IS_ERR(sbs->charger)) { in acpi_charger_add()
587 result = PTR_ERR(sbs->charger); in acpi_charger_add()
588 sbs->charger = NULL; in acpi_charger_add()
591 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), in acpi_charger_add()
592 ACPI_AC_DIR_NAME, sbs->charger_present ? "on-line" : "off-line"); in acpi_charger_add()
597 static void acpi_charger_remove(struct acpi_sbs *sbs) in acpi_charger_remove() argument
599 if (sbs->charger) in acpi_charger_remove()
600 power_supply_unregister(sbs->charger); in acpi_charger_remove()
606 struct acpi_sbs *sbs = context; in acpi_sbs_callback() local
608 u8 saved_charger_state = sbs->charger_present; in acpi_sbs_callback()
611 if (sbs->charger_exists) { in acpi_sbs_callback()
612 acpi_ac_get_present(sbs); in acpi_sbs_callback()
613 if (sbs->charger_present != saved_charger_state) in acpi_sbs_callback()
614 power_supply_changed(sbs->charger); in acpi_sbs_callback()
617 if (sbs->manager_present) { in acpi_sbs_callback()
619 if (!(sbs->batteries_supported & (1 << id))) in acpi_sbs_callback()
621 bat = &sbs->battery[id]; in acpi_sbs_callback()
633 struct acpi_sbs *sbs; in acpi_sbs_add() local
637 sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL); in acpi_sbs_add()
638 if (!sbs) { in acpi_sbs_add()
643 mutex_init(&sbs->lock); in acpi_sbs_add()
645 sbs->hc = acpi_driver_data(acpi_dev_parent(device)); in acpi_sbs_add()
646 sbs->device = device; in acpi_sbs_add()
649 device->driver_data = sbs; in acpi_sbs_add()
651 result = acpi_charger_add(sbs); in acpi_sbs_add()
658 result = acpi_manager_get_info(sbs); in acpi_sbs_add()
660 sbs->manager_present = 1; in acpi_sbs_add()
662 if ((sbs->batteries_supported & (1 << id))) in acpi_sbs_add()
663 acpi_battery_add(sbs, id); in acpi_sbs_add()
667 if (!sbs->manager_present) in acpi_sbs_add()
668 acpi_battery_add(sbs, 0); in acpi_sbs_add()
670 acpi_smbus_register_callback(sbs->hc, acpi_sbs_callback, sbs); in acpi_sbs_add()
679 struct acpi_sbs *sbs; in acpi_sbs_remove() local
684 sbs = acpi_driver_data(device); in acpi_sbs_remove()
685 if (!sbs) in acpi_sbs_remove()
687 mutex_lock(&sbs->lock); in acpi_sbs_remove()
688 acpi_smbus_unregister_callback(sbs->hc); in acpi_sbs_remove()
690 acpi_battery_remove(sbs, id); in acpi_sbs_remove()
691 acpi_charger_remove(sbs); in acpi_sbs_remove()
692 mutex_unlock(&sbs->lock); in acpi_sbs_remove()
693 mutex_destroy(&sbs->lock); in acpi_sbs_remove()
694 kfree(sbs); in acpi_sbs_remove()
700 struct acpi_sbs *sbs; in acpi_sbs_resume() local
703 sbs = to_acpi_device(dev)->driver_data; in acpi_sbs_resume()
704 acpi_sbs_callback(sbs); in acpi_sbs_resume()
714 .name = "sbs",