ACPI: AC: Add sysfs interface
Refer to Documentation/power_supply_class.txt for interface description. Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de> Signed-off-by: Len Brown <len.brown@intel.com>hifive-unleashed-5.1
parent
8bd9553206
commit
d5b4a3d0ef
|
@ -88,7 +88,7 @@ config ACPI_PROC_EVENT
|
||||||
|
|
||||||
config ACPI_AC
|
config ACPI_AC
|
||||||
tristate "AC Adapter"
|
tristate "AC Adapter"
|
||||||
depends on X86
|
depends on X86 && POWER_SUPPLY
|
||||||
default y
|
default y
|
||||||
help
|
help
|
||||||
This driver adds support for the AC Adapter object, which indicates
|
This driver adds support for the AC Adapter object, which indicates
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <linux/proc_fs.h>
|
#include <linux/proc_fs.h>
|
||||||
#include <linux/seq_file.h>
|
#include <linux/seq_file.h>
|
||||||
|
#include <linux/power_supply.h>
|
||||||
#include <acpi/acpi_bus.h>
|
#include <acpi/acpi_bus.h>
|
||||||
#include <acpi/acpi_drivers.h>
|
#include <acpi/acpi_drivers.h>
|
||||||
|
|
||||||
|
@ -72,16 +73,37 @@ static struct acpi_driver acpi_ac_driver = {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct acpi_ac {
|
struct acpi_ac {
|
||||||
|
struct power_supply charger;
|
||||||
struct acpi_device * device;
|
struct acpi_device * device;
|
||||||
unsigned long state;
|
unsigned long state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define to_acpi_ac(x) container_of(x, struct acpi_ac, charger);
|
||||||
|
|
||||||
static const struct file_operations acpi_ac_fops = {
|
static const struct file_operations acpi_ac_fops = {
|
||||||
.open = acpi_ac_open_fs,
|
.open = acpi_ac_open_fs,
|
||||||
.read = seq_read,
|
.read = seq_read,
|
||||||
.llseek = seq_lseek,
|
.llseek = seq_lseek,
|
||||||
.release = single_release,
|
.release = single_release,
|
||||||
};
|
};
|
||||||
|
static int get_ac_property(struct power_supply *psy,
|
||||||
|
enum power_supply_property psp,
|
||||||
|
union power_supply_propval *val)
|
||||||
|
{
|
||||||
|
struct acpi_ac *ac = to_acpi_ac(psy);
|
||||||
|
switch (psp) {
|
||||||
|
case POWER_SUPPLY_PROP_ONLINE:
|
||||||
|
val->intval = ac->state;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static enum power_supply_property ac_props[] = {
|
||||||
|
POWER_SUPPLY_PROP_ONLINE,
|
||||||
|
};
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------
|
||||||
AC Adapter Management
|
AC Adapter Management
|
||||||
|
@ -208,6 +230,7 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
|
||||||
acpi_bus_generate_netlink_event(device->pnp.device_class,
|
acpi_bus_generate_netlink_event(device->pnp.device_class,
|
||||||
device->dev.bus_id, event,
|
device->dev.bus_id, event,
|
||||||
(u32) ac->state);
|
(u32) ac->state);
|
||||||
|
kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
|
||||||
|
@ -244,7 +267,12 @@ static int acpi_ac_add(struct acpi_device *device)
|
||||||
result = acpi_ac_add_fs(device);
|
result = acpi_ac_add_fs(device);
|
||||||
if (result)
|
if (result)
|
||||||
goto end;
|
goto end;
|
||||||
|
ac->charger.name = acpi_device_bid(device);
|
||||||
|
ac->charger.type = POWER_SUPPLY_TYPE_MAINS;
|
||||||
|
ac->charger.properties = ac_props;
|
||||||
|
ac->charger.num_properties = ARRAY_SIZE(ac_props);
|
||||||
|
ac->charger.get_property = get_ac_property;
|
||||||
|
power_supply_register(&ac->device->dev, &ac->charger);
|
||||||
status = acpi_install_notify_handler(device->handle,
|
status = acpi_install_notify_handler(device->handle,
|
||||||
ACPI_ALL_NOTIFY, acpi_ac_notify,
|
ACPI_ALL_NOTIFY, acpi_ac_notify,
|
||||||
ac);
|
ac);
|
||||||
|
@ -279,7 +307,8 @@ static int acpi_ac_remove(struct acpi_device *device, int type)
|
||||||
|
|
||||||
status = acpi_remove_notify_handler(device->handle,
|
status = acpi_remove_notify_handler(device->handle,
|
||||||
ACPI_ALL_NOTIFY, acpi_ac_notify);
|
ACPI_ALL_NOTIFY, acpi_ac_notify);
|
||||||
|
if (ac->charger.dev)
|
||||||
|
power_supply_unregister(&ac->charger);
|
||||||
acpi_ac_remove_fs(device);
|
acpi_ac_remove_fs(device);
|
||||||
|
|
||||||
kfree(ac);
|
kfree(ac);
|
||||||
|
|
Loading…
Reference in New Issue