ec_sys.c (1195a098168fcacfef1cd80d05358e52fb366bf6) ec_sys.c (9827886dce77c47c378ce3154689cea2c45c731d)
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>
2#include <linux/acpi.h>
3#include <linux/debugfs.h>
4#include "internal.h"
5
6MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
7MODULE_DESCRIPTION("ACPI EC sysfs access driver");
8MODULE_LICENSE("GPL");
9
11#include <linux/kernel.h>
12#include <linux/acpi.h>
13#include <linux/debugfs.h>
14#include "internal.h"
15
16MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
17MODULE_DESCRIPTION("ACPI EC sysfs access driver");
18MODULE_LICENSE("GPL");
19
20#define EC_SPACE_SIZE 256
21
10struct sysdev_class acpi_ec_sysdev_class = {
11 .name = "ec",
12};
13
14static struct dentry *acpi_ec_debugfs_dir;
15
22struct sysdev_class acpi_ec_sysdev_class = {
23 .name = "ec",
24};
25
26static struct dentry *acpi_ec_debugfs_dir;
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)
17{
18 struct dentry *dev_dir;
19 char name[64];
20 if (ec_device_count == 0) {
21 acpi_ec_debugfs_dir = debugfs_create_dir("ec", NULL);
22 if (!acpi_ec_debugfs_dir)
23 return -ENOMEM;

--- 6 unchanged lines hidden (view full) ---

30 debugfs_remove_recursive(acpi_ec_debugfs_dir);
31 /* TBD: Proper cleanup for multiple ECs */
32 return -ENOMEM;
33 }
34
35 debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe);
36 debugfs_create_bool("use_global_lock", 0444, dev_dir,
37 (u32 *)&first_ec->global_lock);
101int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count)
102{
103 struct dentry *dev_dir;
104 char name[64];
105 if (ec_device_count == 0) {
106 acpi_ec_debugfs_dir = debugfs_create_dir("ec", NULL);
107 if (!acpi_ec_debugfs_dir)
108 return -ENOMEM;

--- 6 unchanged lines hidden (view full) ---

115 debugfs_remove_recursive(acpi_ec_debugfs_dir);
116 /* TBD: Proper cleanup for multiple ECs */
117 return -ENOMEM;
118 }
119
120 debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe);
121 debugfs_create_bool("use_global_lock", 0444, dev_dir,
122 (u32 *)&first_ec->global_lock);
123 debugfs_create_file("io", 0666, dev_dir, ec, &acpi_ec_io_ops);
38 return 0;
39}
40
41static int __init acpi_ec_sys_init(void)
42{
43 int err = 0;
44 if (first_ec)
45 err = acpi_ec_add_debugfs(first_ec, 0);

--- 12 unchanged lines hidden ---
124 return 0;
125}
126
127static int __init acpi_ec_sys_init(void)
128{
129 int err = 0;
130 if (first_ec)
131 err = acpi_ec_add_debugfs(first_ec, 0);

--- 12 unchanged lines hidden ---