diff options
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/Kconfig | 18 | ||||
-rw-r--r-- | drivers/acpi/Makefile | 1 | ||||
-rw-r--r-- | drivers/acpi/ec.c | 107 | ||||
-rw-r--r-- | drivers/acpi/ec_sys.c | 160 | ||||
-rw-r--r-- | drivers/acpi/internal.h | 24 |
5 files changed, 217 insertions, 93 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 7464115..08e0140 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -104,6 +104,24 @@ config ACPI_SYSFS_POWER help Say N to disable power /sys interface +config ACPI_EC_DEBUGFS + tristate "EC read/write access through /sys/kernel/debug/ec" + default n + help + Say N to disable Embedded Controller /sys/kernel/debug interface + + Be aware that using this interface can confuse your Embedded + Controller in a way that a normal reboot is not enough. You then + have to power of your system, and remove the laptop battery for + some seconds. + An Embedded Controller typically is available on laptops and reads + sensor values like battery state and temperature. + The kernel accesses the EC through ACPI parsed code provided by BIOS + tables. This option allows to access the EC directly without ACPI + code being involved. + Thus this option is a debug option that helps to write ACPI drivers + and can be used to identify ACPI code or EC firmware bugs. + config ACPI_PROC_EVENT bool "Deprecated /proc/acpi/event support" depends on PROC_FS diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 6ee3316..833b582 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -60,6 +60,7 @@ obj-$(CONFIG_ACPI_SBS) += sbshc.o obj-$(CONFIG_ACPI_SBS) += sbs.o obj-$(CONFIG_ACPI_POWER_METER) += power_meter.o obj-$(CONFIG_ACPI_HED) += hed.o +obj-$(CONFIG_ACPI_EC_DEBUGFS) += ec_sys.o # processor has its own "processor." module_param namespace processor-y := processor_driver.o processor_throttling.o diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 5f2027d..1fa0aaf 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -34,8 +34,6 @@ #include <linux/init.h> #include <linux/types.h> #include <linux/delay.h> -#include <linux/proc_fs.h> -#include <linux/seq_file.h> #include <linux/interrupt.h> #include <linux/list.h> #include <linux/spinlock.h> @@ -45,10 +43,13 @@ #include <acpi/acpi_drivers.h> #include <linux/dmi.h> +#include "internal.h" + #define ACPI_EC_CLASS "embedded_controller" #define ACPI_EC_DEVICE_NAME "Embedded Controller" #define ACPI_EC_FILE_INFO "info" +#undef PREFIX #define PREFIX "ACPI: EC: " /* EC status register */ @@ -106,19 +107,8 @@ struct transaction { bool done; }; -static struct acpi_ec { - acpi_handle handle; - unsigned long gpe; - unsigned long command_addr; - unsigned long data_addr; - unsigned long global_lock; - unsigned long flags; - struct mutex lock; - wait_queue_head_t wait; - struct list_head list; - struct transaction *curr; - spinlock_t curr_lock; -} *boot_ec, *first_ec; +struct acpi_ec *boot_ec, *first_ec; +EXPORT_SYMBOL(first_ec); static int EC_FLAGS_MSI; /* Out-of-spec MSI controller */ static int EC_FLAGS_VALIDATE_ECDT; /* ASUStec ECDTs need to be validated */ @@ -679,72 +669,6 @@ acpi_ec_space_handler(u32 function, acpi_physical_address address, } /* -------------------------------------------------------------------------- - FS Interface (/proc) - -------------------------------------------------------------------------- */ - -static struct proc_dir_entry *acpi_ec_dir; - -static int acpi_ec_read_info(struct seq_file *seq, void *offset) -{ - struct acpi_ec *ec = seq->private; - - if (!ec) - goto end; - - seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe); - seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n", - (unsigned)ec->command_addr, (unsigned)ec->data_addr); - seq_printf(seq, "use global lock:\t%s\n", - ec->global_lock ? "yes" : "no"); - end: - return 0; -} - -static int acpi_ec_info_open_fs(struct inode *inode, struct file *file) -{ - return single_open(file, acpi_ec_read_info, PDE(inode)->data); -} - -static const struct file_operations acpi_ec_info_ops = { - .open = acpi_ec_info_open_fs, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; - -static int acpi_ec_add_fs(struct acpi_device *device) -{ - struct proc_dir_entry *entry = NULL; - - if (!acpi_device_dir(device)) { - acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), - acpi_ec_dir); - if (!acpi_device_dir(device)) - return -ENODEV; - } - - entry = proc_create_data(ACPI_EC_FILE_INFO, S_IRUGO, - acpi_device_dir(device), - &acpi_ec_info_ops, acpi_driver_data(device)); - if (!entry) - return -ENODEV; - return 0; -} - -static int acpi_ec_remove_fs(struct acpi_device *device) -{ - - if (acpi_device_dir(device)) { - remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device)); - remove_proc_entry(acpi_device_bid(device), acpi_ec_dir); - acpi_device_dir(device) = NULL; - } - - return 0; -} - -/* -------------------------------------------------------------------------- Driver Interface -------------------------------------------------------------------------- */ static acpi_status @@ -894,7 +818,12 @@ static int acpi_ec_add(struct acpi_device *device) if (!first_ec) first_ec = ec; device->driver_data = ec; - acpi_ec_add_fs(device); + + WARN(!request_region(ec->data_addr, 1, "EC data"), + "Could not request EC data io port 0x%lx", ec->data_addr); + WARN(!request_region(ec->command_addr, 1, "EC cmd"), + "Could not request EC cmd io port 0x%lx", ec->command_addr); + pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", ec->gpe, ec->command_addr, ec->data_addr); @@ -921,7 +850,8 @@ static int acpi_ec_remove(struct acpi_device *device, int type) kfree(handler); } mutex_unlock(&ec->lock); - acpi_ec_remove_fs(device); + release_region(ec->data_addr, 1); + release_region(ec->command_addr, 1); device->driver_data = NULL; if (ec == first_ec) first_ec = NULL; @@ -1120,16 +1050,10 @@ int __init acpi_ec_init(void) { int result = 0; - acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir); - if (!acpi_ec_dir) - return -ENODEV; - /* Now register the driver for the EC */ result = acpi_bus_register_driver(&acpi_ec_driver); - if (result < 0) { - remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); + if (result < 0) return -ENODEV; - } return result; } @@ -1140,9 +1064,6 @@ static void __exit acpi_ec_exit(void) { acpi_bus_unregister_driver(&acpi_ec_driver); - - remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); - return; } #endif /* 0 */ diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c new file mode 100644 index 0000000..0e869b3 --- /dev/null +++ b/drivers/acpi/ec_sys.c @@ -0,0 +1,160 @@ +/* + * ec_sys.c + * + * Copyright (C) 2010 SUSE Products GmbH/Novell + * Author: + * Thomas Renninger <trenn@suse.de> + * + * This work is licensed under the terms of the GNU GPL, version 2. + */ + +#include <linux/kernel.h> +#include <linux/acpi.h> +#include <linux/debugfs.h> +#include "internal.h" + +MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>"); +MODULE_DESCRIPTION("ACPI EC sysfs access driver"); +MODULE_LICENSE("GPL"); + +static bool write_support; +module_param(write_support, bool, 0644); +MODULE_PARM_DESC(write_support, "Dangerous, reboot and removal of battery may " + "be needed."); + +#define EC_SPACE_SIZE 256 + +struct sysdev_class acpi_ec_sysdev_class = { + .name = "ec", +}; + +static struct dentry *acpi_ec_debugfs_dir; + +static int acpi_ec_open_io(struct inode *i, struct file *f) +{ + f->private_data = i->i_private; + return 0; +} + +static ssize_t acpi_ec_read_io(struct file *f, char __user *buf, + size_t count, loff_t *off) +{ + /* Use this if support reading/writing multiple ECs exists in ec.c: + * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private; + */ + unsigned int size = EC_SPACE_SIZE; + u8 *data = (u8 *) buf; + loff_t init_off = *off; + int err = 0; + + if (*off >= size) + return 0; + if (*off + count >= size) { + size -= *off; + count = size; + } else + size = count; + + while (size) { + err = ec_read(*off, &data[*off - init_off]); + if (err) + return err; + *off += 1; + size--; + } + return count; +} + +static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf, + size_t count, loff_t *off) +{ + /* Use this if support reading/writing multiple ECs exists in ec.c: + * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private; + */ + + unsigned int size = count; + loff_t init_off = *off; + u8 *data = (u8 *) buf; + int err = 0; + + if (*off >= EC_SPACE_SIZE) + return 0; + if (*off + count >= EC_SPACE_SIZE) { + size = EC_SPACE_SIZE - *off; + count = size; + } + + while (size) { + u8 byte_write = data[*off - init_off]; + err = ec_write(*off, byte_write); + if (err) + return err; + + *off += 1; + size--; + } + return count; +} + +static struct file_operations acpi_ec_io_ops = { + .owner = THIS_MODULE, + .open = acpi_ec_open_io, + .read = acpi_ec_read_io, + .write = acpi_ec_write_io, +}; + +int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) +{ + struct dentry *dev_dir; + char name[64]; + mode_t mode = 0400; + + if (ec_device_count == 0) { + acpi_ec_debugfs_dir = debugfs_create_dir("ec", NULL); + if (!acpi_ec_debugfs_dir) + return -ENOMEM; + } + + sprintf(name, "ec%u", ec_device_count); + dev_dir = debugfs_create_dir(name, acpi_ec_debugfs_dir); + if (!dev_dir) { + if (ec_device_count != 0) + goto error; + return -ENOMEM; + } + + if (!debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe)) + goto error; + if (!debugfs_create_bool("use_global_lock", 0444, dev_dir, + (u32 *)&first_ec->global_lock)) + goto error; + + if (write_support) + mode = 0600; + if (!debugfs_create_file("io", mode, dev_dir, ec, &acpi_ec_io_ops)) + goto error; + + return 0; + +error: + debugfs_remove_recursive(acpi_ec_debugfs_dir); + return -ENOMEM; +} + +static int __init acpi_ec_sys_init(void) +{ + int err = 0; + if (first_ec) + err = acpi_ec_add_debugfs(first_ec, 0); + else + err = -ENODEV; + return err; +} + +static void __exit acpi_ec_sys_exit(void) +{ + debugfs_remove_recursive(acpi_ec_debugfs_dir); +} + +module_init(acpi_ec_sys_init); +module_exit(acpi_ec_sys_exit); diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index f8f190e..8ae2726 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -18,6 +18,11 @@ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. */ +#ifndef _ACPI_INTERNAL_H_ +#define _ACPI_INTERNAL_H_ + +#include <linux/sysdev.h> + #define PREFIX "ACPI: " int init_acpi_device_notify(void); @@ -46,6 +51,23 @@ void acpi_early_processor_set_pdc(void); /* -------------------------------------------------------------------------- Embedded Controller -------------------------------------------------------------------------- */ +struct acpi_ec { + acpi_handle handle; + unsigned long gpe; + unsigned long command_addr; + unsigned long data_addr; + unsigned long global_lock; + unsigned long flags; + struct mutex lock; + wait_queue_head_t wait; + struct list_head list; + struct transaction *curr; + spinlock_t curr_lock; + struct sys_device sysdev; +}; + +extern struct acpi_ec *first_ec; + int acpi_ec_init(void); int acpi_ec_ecdt_probe(void); int acpi_boot_ec_enable(void); @@ -63,3 +85,5 @@ int acpi_sleep_proc_init(void); #else static inline int acpi_sleep_proc_init(void) { return 0; } #endif + +#endif /* _ACPI_INTERNAL_H_ */ |