Subject: [PATCH] [acpi driver model] Add New AC Driver - Include base driver: - Registration - Simple device access (for acquiring state) - Kconfig option Signed-off-by: Patrick Mochel --- drivers/acpi/drivers/ac/Kconfig | 9 ++++++ drivers/acpi/drivers/ac/Makefile | 4 ++ drivers/acpi/drivers/ac/ac.h | 20 ++++++++++++ drivers/acpi/drivers/ac/device.c | 31 +++++++++++++++++++ drivers/acpi/drivers/ac/driver.c | 61 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+), 0 deletions(-) create mode 100644 drivers/acpi/drivers/ac/Kconfig create mode 100644 drivers/acpi/drivers/ac/Makefile create mode 100644 drivers/acpi/drivers/ac/ac.h create mode 100644 drivers/acpi/drivers/ac/device.c create mode 100644 drivers/acpi/drivers/ac/driver.c applies-to: 19c872a70960e22ef0c9ffc8f064fe94ce34e52f 6713a099eaa5de8cec2ea12bc27accbc709955aa diff --git a/drivers/acpi/drivers/ac/Kconfig b/drivers/acpi/drivers/ac/Kconfig new file mode 100644 index 0000000..3afdd4c --- /dev/null +++ b/drivers/acpi/drivers/ac/Kconfig @@ -0,0 +1,9 @@ +config ACPI_AC + tristate "AC Adapter" + depends on ACPI_DM && X86 + default y + help + This driver adds support for the AC Adapter object, which indicates + whether a system is on AC, or not. If you have a system that can + switch between A/C and battery, say Y. + diff --git a/drivers/acpi/drivers/ac/Makefile b/drivers/acpi/drivers/ac/Makefile new file mode 100644 index 0000000..2e12353 --- /dev/null +++ b/drivers/acpi/drivers/ac/Makefile @@ -0,0 +1,4 @@ +obj-$(CONFIG_ACPI_AC) += ac.o + +ac-y := driver.o device.o + diff --git a/drivers/acpi/drivers/ac/ac.h b/drivers/acpi/drivers/ac/ac.h new file mode 100644 index 0000000..b175dec --- /dev/null +++ b/drivers/acpi/drivers/ac/ac.h @@ -0,0 +1,20 @@ + +#define err(fmt, ...) printk(PREFIX "ac: " fmt "\n", ## __VA_ARGS__) + + +#define _COMPONENT ACPI_AC_COMPONENT +ACPI_MODULE_NAME("acpi_ac"); + +#define ACPI_AC_HID "ACPI0003" + +#define AC_STATE_OFFLINE 0x00 +#define AC_STATE_ONLINE 0x01 +#define AC_STATUS_UNKNOWN 0xff + +struct acpi_ac { + struct acpi_dev * a_ad; + unsigned long a_state; +}; + + +extern int ac_get_state(struct acpi_ac * ac); diff --git a/drivers/acpi/drivers/ac/device.c b/drivers/acpi/drivers/ac/device.c new file mode 100644 index 0000000..7da4fc4 --- /dev/null +++ b/drivers/acpi/drivers/ac/device.c @@ -0,0 +1,31 @@ +/** + * + * drivers/acpi/drivers/ac/device.c - low-level device access (via AML) + * + * Copyright (C) 2005 Patrick Mochel + * + * Based on drivers/acpi/ac.c, which was: + * Copyright (C) 2001, 2002 Andy Grover + * Copyright (C) 2001, 2002 Paul Diefenbaugh + * + * + * This file is released under the GPLv2. + */ + +#include +#include "ac.h" + + +int ac_get_state(struct acpi_ac * ac) +{ + acpi_status status; + int ret = 0; + + status = acpi_evaluate_integer(ac->a_ad->acpi_device->handle, + "_PSR", NULL, &ac->a_state); + if (ACPI_FAILURE(status)) { + err("Unable to read AC Adapter state"); + ret = -ENODEV; + } + return ret; +} diff --git a/drivers/acpi/drivers/ac/driver.c b/drivers/acpi/drivers/ac/driver.c new file mode 100644 index 0000000..90aa48e --- /dev/null +++ b/drivers/acpi/drivers/ac/driver.c @@ -0,0 +1,61 @@ +/* + * drivers/acpi/drivers/ac.c - New-style ACPI driver ac + * + * Copyright (C) 2005 Patrick Mochel + * + * This file is released under the GPLv2. + * + */ + +#include +#include "ac.h" + +static int ac_add(struct acpi_dev * ad) +{ + struct acpi_ac * ac; + int ret = 0; + + ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL); + if (!ac) + return -ENOMEM; + + ac->a_ad = ad; + ac->a_state = AC_STATUS_UNKNOWN; + + ret = ac_get_state(ac); + if (ret) { + kfree(ac); + return ret; + } + + dev_set_drvdata(&ad->dev, ac); + + printk(KERN_INFO PREFIX "ac [%s] (%s)\n", + acpi_dev_bid(ad), + ac->a_state ? "on-line" : "off-line"); + + return 0; +} + +static int ac_remove(struct acpi_dev * ad) +{ + struct acpi_ac * ac = dev_get_drvdata(&ad->dev); + + dev_set_drvdata(&ad->dev, NULL); + kfree(ac); + return 0; +} + + +acpi_no_start(ac); +acpi_no_stop(ac); +acpi_no_shutdown(ac); +acpi_no_suspend(ac); +acpi_no_resume(ac); + +declare_acpi_driver(ac, ACPI_AC_HID); + + +MODULE_AUTHOR("Patrick Mochel"); +MODULE_DESCRIPTION("ACPI AC Driver"); +MODULE_LICENSE("GPL"); --- 0.99.9.GIT