4 * Copyright (C) 2010 SUSE Products GmbH/Novell
6 * Thomas Renninger <trenn@suse.de>
8 * This work is licensed under the terms of the GNU GPL, version 2.
11 #include <linux/kernel.h>
12 #include <linux/acpi.h>
13 #include <linux/debugfs.h>
16 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
17 MODULE_DESCRIPTION("ACPI EC sysfs access driver");
18 MODULE_LICENSE("GPL");
20 static bool write_support
;
21 module_param(write_support
, bool, 0644);
22 MODULE_PARM_DESC(write_support
, "Dangerous, reboot and removal of battery may "
25 #define EC_SPACE_SIZE 256
27 static struct dentry
*acpi_ec_debugfs_dir
;
29 static int acpi_ec_open_io(struct inode
*i
, struct file
*f
)
31 f
->private_data
= i
->i_private
;
35 static ssize_t
acpi_ec_read_io(struct file
*f
, char __user
*buf
,
36 size_t count
, loff_t
*off
)
38 /* Use this if support reading/writing multiple ECs exists in ec.c:
39 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
41 unsigned int size
= EC_SPACE_SIZE
;
42 u8
*data
= (u8
*) buf
;
43 loff_t init_off
= *off
;
48 if (*off
+ count
>= size
) {
55 err
= ec_read(*off
, &data
[*off
- init_off
]);
64 static ssize_t
acpi_ec_write_io(struct file
*f
, const char __user
*buf
,
65 size_t count
, loff_t
*off
)
67 /* Use this if support reading/writing multiple ECs exists in ec.c:
68 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
71 unsigned int size
= count
;
72 loff_t init_off
= *off
;
73 u8
*data
= (u8
*) buf
;
76 if (*off
>= EC_SPACE_SIZE
)
78 if (*off
+ count
>= EC_SPACE_SIZE
) {
79 size
= EC_SPACE_SIZE
- *off
;
84 u8 byte_write
= data
[*off
- init_off
];
85 err
= ec_write(*off
, byte_write
);
95 static const struct file_operations acpi_ec_io_ops
= {
97 .open
= acpi_ec_open_io
,
98 .read
= acpi_ec_read_io
,
99 .write
= acpi_ec_write_io
,
100 .llseek
= default_llseek
,
103 int acpi_ec_add_debugfs(struct acpi_ec
*ec
, unsigned int ec_device_count
)
105 struct dentry
*dev_dir
;
109 if (ec_device_count
== 0) {
110 acpi_ec_debugfs_dir
= debugfs_create_dir("ec", NULL
);
111 if (!acpi_ec_debugfs_dir
)
115 sprintf(name
, "ec%u", ec_device_count
);
116 dev_dir
= debugfs_create_dir(name
, acpi_ec_debugfs_dir
);
118 if (ec_device_count
!= 0)
123 if (!debugfs_create_x32("gpe", 0444, dev_dir
, (u32
*)&first_ec
->gpe
))
125 if (!debugfs_create_bool("use_global_lock", 0444, dev_dir
,
126 (u32
*)&first_ec
->global_lock
))
131 if (!debugfs_create_file("io", mode
, dev_dir
, ec
, &acpi_ec_io_ops
))
137 debugfs_remove_recursive(acpi_ec_debugfs_dir
);
141 static int __init
acpi_ec_sys_init(void)
145 err
= acpi_ec_add_debugfs(first_ec
, 0);
151 static void __exit
acpi_ec_sys_exit(void)
153 debugfs_remove_recursive(acpi_ec_debugfs_dir
);
156 module_init(acpi_ec_sys_init
);
157 module_exit(acpi_ec_sys_exit
);