Skip to content

Commit 6fd7f2b

Browse files
Enric Balletbo i SerraLee Jones
authored andcommitted
mfd / platform: cros_ec: Move device sysfs attributes to its own driver
The entire way how cros debugfs attibutes are created is broken. cros_ec_sysfs should be its own driver and its attributes should be associated with the sysfs driver not the mfd driver. The patch also adds the sysfs documentation. Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com> Reviewed-by: Guenter Roeck <groeck@chromium.org> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 6fce0a2 commit 6fd7f2b

8 files changed

Lines changed: 81 additions & 17 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
What: /sys/class/chromeos/<ec-device-name>/flashinfo
2+
Date: August 2015
3+
KernelVersion: 4.2
4+
Description:
5+
Show the EC flash information.
6+
7+
What: /sys/class/chromeos/<ec-device-name>/kb_wake_angle
8+
Date: March 2018
9+
KernelVersion: 4.17
10+
Description:
11+
Control the keyboard wake lid angle. Values are between
12+
0 and 360. This file will also show the keyboard wake lid
13+
angle by querying the hardware.
14+
15+
What: /sys/class/chromeos/<ec-device-name>/reboot
16+
Date: August 2015
17+
KernelVersion: 4.2
18+
Description:
19+
Tell the EC to reboot in various ways. Options are:
20+
"cancel": Cancel a pending reboot.
21+
"ro": Jump to RO without rebooting.
22+
"rw": Jump to RW without rebooting.
23+
"cold": Cold reboot.
24+
"disable-jump": Disable jump until next reboot.
25+
"hibernate": Hibernate the EC.
26+
"at-shutdown": Reboot after an AP shutdown.
27+
28+
What: /sys/class/chromeos/<ec-device-name>/version
29+
Date: August 2015
30+
KernelVersion: 4.2
31+
Description:
32+
Show the information about the EC software and hardware.

‎drivers/mfd/Kconfig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ config MFD_CROS_EC
215215
config MFD_CROS_EC_CHARDEV
216216
tristate "Chrome OS Embedded Controller userspace device interface"
217217
depends on MFD_CROS_EC
218-
select CROS_EC_CTL
219218
---help---
220219
This driver adds support to talk with the ChromeOS EC from userspace.
221220

‎drivers/mfd/cros_ec_dev.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,9 @@
3434
#define CROS_MAX_DEV 128
3535
static int ec_major;
3636

37-
static const struct attribute_group *cros_ec_groups[] = {
38-
&cros_ec_attr_group,
39-
NULL,
40-
};
41-
4237
static struct class cros_class = {
4338
.owner = THIS_MODULE,
4439
.name = "chromeos",
45-
.dev_groups = cros_ec_groups,
4640
};
4741

4842
/* Basic communication */
@@ -396,6 +390,7 @@ static const struct mfd_cell cros_usbpd_charger_cells[] = {
396390
static const struct mfd_cell cros_ec_platform_cells[] = {
397391
{ .name = "cros-ec-debugfs" },
398392
{ .name = "cros-ec-lightbar" },
393+
{ .name = "cros-ec-sysfs" },
399394
{ .name = "cros-ec-vbc" },
400395
};
401396

‎drivers/platform/chrome/Kconfig‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ config CHROMEOS_TBMC
4949
To compile this driver as a module, choose M here: the
5050
module will be called chromeos_tbmc.
5151

52-
config CROS_EC_CTL
53-
tristate
54-
5552
config CROS_EC_I2C
5653
tristate "ChromeOS Embedded Controller (I2C)"
5754
depends on MFD_CROS_EC && I2C
@@ -144,4 +141,15 @@ config CROS_EC_DEBUGFS
144141
To compile this driver as a module, choose M here: the
145142
module will be called cros_ec_debugfs.
146143

144+
config CROS_EC_SYSFS
145+
tristate "ChromeOS EC control and information through sysfs"
146+
depends on MFD_CROS_EC_CHARDEV && SYSFS
147+
default MFD_CROS_EC_CHARDEV
148+
help
149+
This option exposes some sysfs attributes to control and get
150+
information from ChromeOS EC.
151+
152+
To compile this driver as a module, choose M here: the
153+
module will be called cros_ec_sysfs.
154+
147155
endif # CHROMEOS_PLATFORMS

‎drivers/platform/chrome/Makefile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o
44
obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o
55
obj-$(CONFIG_CHROMEOS_TBMC) += chromeos_tbmc.o
6-
cros_ec_ctl-objs := cros_ec_sysfs.o
7-
obj-$(CONFIG_CROS_EC_CTL) += cros_ec_ctl.o
86
obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o
97
obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o
108
cros_ec_lpcs-objs := cros_ec_lpc.o cros_ec_lpc_reg.o
@@ -15,3 +13,4 @@ obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o
1513
obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o
1614
obj-$(CONFIG_CROS_EC_VBC) += cros_ec_vbc.o
1715
obj-$(CONFIG_CROS_EC_DEBUGFS) += cros_ec_debugfs.o
16+
obj-$(CONFIG_CROS_EC_SYSFS) += cros_ec_sysfs.o

‎drivers/platform/chrome/cros_ec_lightbar.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ static umode_t cros_ec_lightbar_attrs_are_visible(struct kobject *kobj,
594594
return 0;
595595
}
596596

597-
struct attribute_group cros_ec_lightbar_attr_group = {
597+
static struct attribute_group cros_ec_lightbar_attr_group = {
598598
.name = "lightbar",
599599
.attrs = __lb_cmds_attrs,
600600
.is_visible = cros_ec_lightbar_attrs_are_visible,

‎drivers/platform/chrome/cros_ec_sysfs.c‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include <linux/types.h>
3535
#include <linux/uaccess.h>
3636

37+
#define DRV_NAME "cros-ec-sysfs"
38+
3739
/* Accessor functions */
3840

3941
static ssize_t reboot_show(struct device *dev,
@@ -353,7 +355,39 @@ struct attribute_group cros_ec_attr_group = {
353355
.attrs = __ec_attrs,
354356
.is_visible = cros_ec_ctrl_visible,
355357
};
356-
EXPORT_SYMBOL(cros_ec_attr_group);
358+
359+
static int cros_ec_sysfs_probe(struct platform_device *pd)
360+
{
361+
struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
362+
struct device *dev = &pd->dev;
363+
int ret;
364+
365+
ret = sysfs_create_group(&ec_dev->class_dev.kobj, &cros_ec_attr_group);
366+
if (ret < 0)
367+
dev_err(dev, "failed to create attributes. err=%d\n", ret);
368+
369+
return ret;
370+
}
371+
372+
static int cros_ec_sysfs_remove(struct platform_device *pd)
373+
{
374+
struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
375+
376+
sysfs_remove_group(&ec_dev->class_dev.kobj, &cros_ec_attr_group);
377+
378+
return 0;
379+
}
380+
381+
static struct platform_driver cros_ec_sysfs_driver = {
382+
.driver = {
383+
.name = DRV_NAME,
384+
},
385+
.probe = cros_ec_sysfs_probe,
386+
.remove = cros_ec_sysfs_remove,
387+
};
388+
389+
module_platform_driver(cros_ec_sysfs_driver);
357390

358391
MODULE_LICENSE("GPL");
359392
MODULE_DESCRIPTION("ChromeOS EC control driver");
393+
MODULE_ALIAS("platform:" DRV_NAME);

‎include/linux/mfd/cros_ec.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,4 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event);
325325
*/
326326
u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);
327327

328-
/* sysfs stuff */
329-
extern struct attribute_group cros_ec_attr_group;
330-
331328
#endif /* __LINUX_MFD_CROS_EC_H */

0 commit comments

Comments
 (0)