Subject: [PATCH] [acpi ec] Add interface for writing to device - Add acpi_ec_write() that can be used internally - Uses ->e_sem for synchronization (for both access methods) - Uses common code for both access methods - Add ec_write() for externally-visible interface for writing (for compatibility) Signed-off-by: Patrick Mochel --- drivers/acpi/drivers/ec/Makefile | 2 + drivers/acpi/drivers/ec/write.c | 72 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletions(-) create mode 100644 drivers/acpi/drivers/ec/write.c applies-to: 98397a0ea0e2573495eca23aae43c3892efde46a d576620337fbd4eeaea84a930df767e68db9f36d diff --git a/drivers/acpi/drivers/ec/Makefile b/drivers/acpi/drivers/ec/Makefile index 26f3b7b..0cdbf89 100644 --- a/drivers/acpi/drivers/ec/Makefile +++ b/drivers/acpi/drivers/ec/Makefile @@ -2,7 +2,7 @@ obj-$(CONFIG_ACPI_EC) += ec.o ec-y := driver.o device.o event.o poll.o intr.o ec-y += setup.o -ec-y += resource.o gpe.o read.o +ec-y += resource.o gpe.o read.o write.o ec-$(CONFIG_ACPI_DM_PROC) += proc.o ec-$(CONFIG_ACPI_DM_SYSFS) += sysfs.o diff --git a/drivers/acpi/drivers/ec/write.c b/drivers/acpi/drivers/ec/write.c new file mode 100644 index 0000000..556179c --- /dev/null +++ b/drivers/acpi/drivers/ec/write.c @@ -0,0 +1,72 @@ +/*** + * drivers/acpi/drivers/ec/intr.c - Interrupt-driven EC driver + * + * Copyright (C) 2006 Patrick Mochel + * + * Based on drivers/acpi/ec.c, which was + * + * Copyright (C) 2004 Luming Yu + * Copyright (C) 2001, 2002 Andy Grover + * Copyright (C) 2001, 2002 Paul Diefenbaugh + * + * This file is released under the GPLv2. + */ + +#include "ec.h" + + +static int __write(struct acpi_ec * ec, u8 addr, u8 data) +{ + int ret; + + acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->e_command); + ret = ec->e_wait(ec, ACPI_EC_EVENT_IBE); + if (ret) + dbg("EC Write, IB not empty"); + + acpi_hw_low_level_write(8, addr, &ec->e_data); + ret = ec->e_wait(ec, ACPI_EC_EVENT_IBE); + if (ret) { + dbg("EC Write, IB not empty"); + return ret; + } + acpi_hw_low_level_write(8, data, &ec->e_data); + dbg("Wrote [%#02x] to address [%#02x]", *data, address); + return 0; +} + +int acpi_ec_write(struct acpi_ec * ec, u8 addr, u8 data) +{ + acpi_status status; + u32 glk; + int ret; + + if (ec->e_global_lock) { + status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); + if (ACPI_FAILURE(status)) + return -ENODEV; + } + + down(&ec->e_sem); + ret = __write(ec, addr, data); + up(&ec->e_sem); + + if (ec->e_global_lock) + acpi_release_global_lock(glk); + return ret; +} + + +int ec_write(u8 addr, u8 val) +{ + int ret; + + if (!first_ec) + return -ENODEV; + + ret = acpi_ec_write(first_ec, addr, val); + + return ret; +} + +EXPORT_SYMBOL(ec_write); --- 0.99.9.GIT