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 struct sysdev_class acpi_ec_sysdev_class
= {
31 static struct dentry
*acpi_ec_debugfs_dir
;
33 static int acpi_ec_open_io(struct inode
*i
, struct file
*f
)
35 f
->private_data
= i
->i_private
;
39 static ssize_t
acpi_ec_read_io(struct file
*f
, char __user
*buf
,
40 size_t count
, loff_t
*off
)
42 /* Use this if support reading/writing multiple ECs exists in ec.c:
43 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
45 unsigned int size
= EC_SPACE_SIZE
;
46 u8
*data
= (u8
*) buf
;
47 loff_t init_off
= *off
;
52 if (*off
+ count
>= size
) {
59 err
= ec_read(*off
, &data
[*off
- init_off
]);
68 static ssize_t
acpi_ec_write_io(struct file
*f
, const char __user
*buf
,
69 size_t count
, loff_t
*off
)
71 /* Use this if support reading/writing multiple ECs exists in ec.c:
72 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
75 unsigned int size
= count
;
76 loff_t init_off
= *off
;
77 u8
*data
= (u8
*) buf
;
80 if (*off
>= EC_SPACE_SIZE
)
82 if (*off
+ count
>= EC_SPACE_SIZE
) {
83 size
= EC_SPACE_SIZE
- *off
;
88 u8 byte_write
= data
[*off
- init_off
];
89 err
= ec_write(*off
, byte_write
);
99 static struct file_operations acpi_ec_io_ops
= {
100 .owner
= THIS_MODULE
,
101 .open
= acpi_ec_open_io
,
102 .read
= acpi_ec_read_io
,
103 .write
= acpi_ec_write_io
,
104 .llseek
= default_llseek
,
107 int acpi_ec_add_debugfs(struct acpi_ec
*ec
, unsigned int ec_device_count
)
109 struct dentry
*dev_dir
;
113 if (ec_device_count
== 0) {
114 acpi_ec_debugfs_dir
= debugfs_create_dir("ec", NULL
);
115 if (!acpi_ec_debugfs_dir
)
119 sprintf(name
, "ec%u", ec_device_count
);
120 dev_dir
= debugfs_create_dir(name
, acpi_ec_debugfs_dir
);
122 if (ec_device_count
!= 0)
127 if (!debugfs_create_x32("gpe", 0444, dev_dir
, (u32
*)&first_ec
->gpe
))
129 if (!debugfs_create_bool("use_global_lock", 0444, dev_dir
,
130 (u32
*)&first_ec
->global_lock
))
135 if (!debugfs_create_file("io", mode
, dev_dir
, ec
, &acpi_ec_io_ops
))
141 debugfs_remove_recursive(acpi_ec_debugfs_dir
);
145 static int __init
acpi_ec_sys_init(void)
149 err
= acpi_ec_add_debugfs(first_ec
, 0);
155 static void __exit
acpi_ec_sys_exit(void)
157 debugfs_remove_recursive(acpi_ec_debugfs_dir
);
160 module_init(acpi_ec_sys_init
);
161 module_exit(acpi_ec_sys_exit
);