Skip to content

Commit 1195a09

Browse files
watologo1Matthew Garrett
authored andcommitted
ACPI: Provide /sys/kernel/debug/ec/...
This patch provides the same information through debugfs, which previously was provided through /proc/acpi/embedded_controller/*/info This is the gpe the EC is connected to and whether the global lock gets used. The io ports used are added to /proc/ioports in another patch. Beside the fact that /proc/acpi is deprecated for quite some time, this info is not needed for applications and thus can be moved to debugfs instead of a public interface like /sys. Signed-off-by: Thomas Renninger <[email protected]> CC: Alexey Starikovskiy <[email protected]> CC: Len Brown <[email protected]> CC: [email protected] CC: [email protected] CC: Bjorn Helgaas <[email protected]> CC: [email protected] Signed-off-by: Matthew Garrett <[email protected]>
1 parent cd89e08 commit 1195a09

File tree

5 files changed

+100
-13
lines changed

5 files changed

+100
-13
lines changed

drivers/acpi/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ config ACPI_SYSFS_POWER
104104
help
105105
Say N to disable power /sys interface
106106

107+
config ACPI_EC_DEBUGFS
108+
tristate "EC read/write access through /sys/kernel/debug/ec"
109+
default y
110+
help
111+
Say N to disable Embedded Controller /sys/kernel/debug interface
112+
113+
An Embedded Controller typically is available on laptops and reads
114+
sensor values like battery state and temperature.
115+
The kernel access the EC through ACPI parsed code provided by BIOS
116+
tables.
117+
Thus this option is a debug option that helps to write ACPI drivers
118+
and can be used to identify ACPI code or EC firmware bugs.
119+
107120
config ACPI_PROC_EVENT
108121
bool "Deprecated /proc/acpi/event support"
109122
depends on PROC_FS

drivers/acpi/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ obj-$(CONFIG_ACPI_SBS) += sbshc.o
6060
obj-$(CONFIG_ACPI_SBS) += sbs.o
6161
obj-$(CONFIG_ACPI_POWER_METER) += power_meter.o
6262
obj-$(CONFIG_ACPI_HED) += hed.o
63+
obj-$(CONFIG_ACPI_EC_DEBUGFS) += ec_sys.o
6364

6465
# processor has its own "processor." module_param namespace
6566
processor-y := processor_driver.o processor_throttling.o

drivers/acpi/ec.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@
4343
#include <acpi/acpi_drivers.h>
4444
#include <linux/dmi.h>
4545

46+
#include "internal.h"
47+
4648
#define ACPI_EC_CLASS "embedded_controller"
4749
#define ACPI_EC_DEVICE_NAME "Embedded Controller"
4850
#define ACPI_EC_FILE_INFO "info"
4951

52+
#undef PREFIX
5053
#define PREFIX "ACPI: EC: "
5154

5255
/* EC status register */
@@ -104,19 +107,8 @@ struct transaction {
104107
bool done;
105108
};
106109

107-
static struct acpi_ec {
108-
acpi_handle handle;
109-
unsigned long gpe;
110-
unsigned long command_addr;
111-
unsigned long data_addr;
112-
unsigned long global_lock;
113-
unsigned long flags;
114-
struct mutex lock;
115-
wait_queue_head_t wait;
116-
struct list_head list;
117-
struct transaction *curr;
118-
spinlock_t curr_lock;
119-
} *boot_ec, *first_ec;
110+
struct acpi_ec *boot_ec, *first_ec;
111+
EXPORT_SYMBOL(first_ec);
120112

121113
static int EC_FLAGS_MSI; /* Out-of-spec MSI controller */
122114
static int EC_FLAGS_VALIDATE_ECDT; /* ASUStec ECDTs need to be validated */

drivers/acpi/ec_sys.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <linux/kernel.h>
2+
#include <linux/acpi.h>
3+
#include <linux/debugfs.h>
4+
#include "internal.h"
5+
6+
MODULE_AUTHOR("Thomas Renninger <[email protected]>");
7+
MODULE_DESCRIPTION("ACPI EC sysfs access driver");
8+
MODULE_LICENSE("GPL");
9+
10+
struct sysdev_class acpi_ec_sysdev_class = {
11+
.name = "ec",
12+
};
13+
14+
static struct dentry *acpi_ec_debugfs_dir;
15+
16+
int 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;
24+
}
25+
26+
sprintf(name, "ec%u", ec_device_count);
27+
dev_dir = debugfs_create_dir(name, acpi_ec_debugfs_dir);
28+
if (!dev_dir) {
29+
if (ec_device_count == 0)
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);
38+
return 0;
39+
}
40+
41+
static 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);
46+
else
47+
err = -ENODEV;
48+
return err;
49+
}
50+
51+
static void __exit acpi_ec_sys_exit(void)
52+
{
53+
debugfs_remove_recursive(acpi_ec_debugfs_dir);
54+
}
55+
56+
module_init(acpi_ec_sys_init);
57+
module_exit(acpi_ec_sys_exit);

drivers/acpi/internal.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
1919
*/
2020

21+
#ifndef _ACPI_INTERNAL_H_
22+
#define _ACPI_INTERNAL_H_
23+
24+
#include <linux/sysdev.h>
25+
2126
#define PREFIX "ACPI: "
2227

2328
int init_acpi_device_notify(void);
@@ -46,6 +51,23 @@ void acpi_early_processor_set_pdc(void);
4651
/* --------------------------------------------------------------------------
4752
Embedded Controller
4853
-------------------------------------------------------------------------- */
54+
struct acpi_ec {
55+
acpi_handle handle;
56+
unsigned long gpe;
57+
unsigned long command_addr;
58+
unsigned long data_addr;
59+
unsigned long global_lock;
60+
unsigned long flags;
61+
struct mutex lock;
62+
wait_queue_head_t wait;
63+
struct list_head list;
64+
struct transaction *curr;
65+
spinlock_t curr_lock;
66+
struct sys_device sysdev;
67+
};
68+
69+
extern struct acpi_ec *first_ec;
70+
4971
int acpi_ec_init(void);
5072
int acpi_ec_ecdt_probe(void);
5173
int acpi_boot_ec_enable(void);
@@ -63,3 +85,5 @@ int acpi_sleep_proc_init(void);
6385
#else
6486
static inline int acpi_sleep_proc_init(void) { return 0; }
6587
#endif
88+
89+
#endif /* _ACPI_INTERNAL_H_ */

0 commit comments

Comments
 (0)