aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/ec_sys.c
diff options
context:
space:
mode:
authorThomas Renninger <trenn@suse.de>2010-07-16 07:11:32 -0400
committerMatthew Garrett <mjg@redhat.com>2010-08-03 09:49:08 -0400
commit9827886dce77c47c378ce3154689cea2c45c731d (patch)
tree1e017588d4c4fcbced1f8e8725fff57a3889d015 /drivers/acpi/ec_sys.c
parent1195a098168fcacfef1cd80d05358e52fb366bf6 (diff)
ACPI: Provide /sys/kernel/debug//ec/ec0/io for binary access to the EC
A userspace app to easily read/write the EC can be found here: ftp://ftp.suse.com/pub/people/trenn/sources/ec/ec_access.c Multiple ECs are not supported, but shouldn't be hard to add as soon as the ec driver itself will support them. Signed-off-by: Thomas Renninger <trenn@suse.de> CC: Alexey Starikovskiy <astarikovskiy@suse.de> CC: Len Brown <lenb@kernel.org> CC: linux-kernel@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org Signed-off-by: Matthew Garrett <mjg@redhat.com>
Diffstat (limited to 'drivers/acpi/ec_sys.c')
-rw-r--r--drivers/acpi/ec_sys.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
index 834c21a42d67..3ef978185c73 100644
--- a/drivers/acpi/ec_sys.c
+++ b/drivers/acpi/ec_sys.c
@@ -1,3 +1,13 @@
1/*
2 * ec_sys.c
3 *
4 * Copyright (C) 2010 SUSE Products GmbH/Novell
5 * Author:
6 * Thomas Renninger <trenn@suse.de>
7 *
8 * This work is licensed under the terms of the GNU GPL, version 2.
9 */
10
1#include <linux/kernel.h> 11#include <linux/kernel.h>
2#include <linux/acpi.h> 12#include <linux/acpi.h>
3#include <linux/debugfs.h> 13#include <linux/debugfs.h>
@@ -7,12 +17,87 @@ MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
7MODULE_DESCRIPTION("ACPI EC sysfs access driver"); 17MODULE_DESCRIPTION("ACPI EC sysfs access driver");
8MODULE_LICENSE("GPL"); 18MODULE_LICENSE("GPL");
9 19
20#define EC_SPACE_SIZE 256
21
10struct sysdev_class acpi_ec_sysdev_class = { 22struct sysdev_class acpi_ec_sysdev_class = {
11 .name = "ec", 23 .name = "ec",
12}; 24};
13 25
14static struct dentry *acpi_ec_debugfs_dir; 26static struct dentry *acpi_ec_debugfs_dir;
15 27
28static int acpi_ec_open_io(struct inode *i, struct file *f)
29{
30 f->private_data = i->i_private;
31 return 0;
32}
33
34static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
35 size_t count, loff_t *off)
36{
37 /* Use this if support reading/writing multiple ECs exists in ec.c:
38 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
39 */
40 unsigned int size = EC_SPACE_SIZE;
41 u8 *data = (u8 *) buf;
42 loff_t init_off = *off;
43 int err = 0;
44
45 if (*off >= size)
46 return 0;
47 if (*off + count >= size) {
48 size -= *off;
49 count = size;
50 } else
51 size = count;
52
53 while (size) {
54 err = ec_read(*off, &data[*off - init_off]);
55 if (err)
56 return err;
57 *off += 1;
58 size--;
59 }
60 return count;
61}
62
63static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
64 size_t count, loff_t *off)
65{
66 /* Use this if support reading/writing multiple ECs exists in ec.c:
67 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
68 */
69
70 unsigned int size = count;
71 loff_t init_off = *off;
72 u8 *data = (u8 *) buf;
73 int err = 0;
74
75 if (*off >= EC_SPACE_SIZE)
76 return 0;
77 if (*off + count >= EC_SPACE_SIZE) {
78 size = EC_SPACE_SIZE - *off;
79 count = size;
80 }
81
82 while (size) {
83 u8 byte_write = data[*off - init_off];
84 err = ec_write(*off, byte_write);
85 if (err)
86 return err;
87
88 *off += 1;
89 size--;
90 }
91 return count;
92}
93
94static struct file_operations acpi_ec_io_ops = {
95 .owner = THIS_MODULE,
96 .open = acpi_ec_open_io,
97 .read = acpi_ec_read_io,
98 .write = acpi_ec_write_io,
99};
100
16int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) 101int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count)
17{ 102{
18 struct dentry *dev_dir; 103 struct dentry *dev_dir;
@@ -35,6 +120,7 @@ int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count)
35 debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe); 120 debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe);
36 debugfs_create_bool("use_global_lock", 0444, dev_dir, 121 debugfs_create_bool("use_global_lock", 0444, dev_dir,
37 (u32 *)&first_ec->global_lock); 122 (u32 *)&first_ec->global_lock);
123 debugfs_create_file("io", 0666, dev_dir, ec, &acpi_ec_io_ops);
38 return 0; 124 return 0;
39} 125}
40 126