Skip to content

Commit ecf8a6c

Browse files
Enric Balletbo i SerraLee Jones
authored andcommitted
mfd / platform: cros_ec: Move lightbar attributes to its own driver
The entire way how cros sysfs attibutes are created is broken. cros_ec_lightbar should be its own driver and its attributes should be associated with a lightbar driver not the mfd driver. In order to retain the path, the lightbar attributes are attached to the cros_class. 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 4bc59c2 commit ecf8a6c

7 files changed

Lines changed: 173 additions & 41 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
What: /sys/class/chromeos/<ec-device-name>/lightbar/brightness
2+
Date: August 2015
3+
KernelVersion: 4.2
4+
Description:
5+
Writing to this file adjusts the overall brightness of
6+
the lightbar, separate from any color intensity. The
7+
valid range is 0 (off) to 255 (maximum brightness).
8+
9+
What: /sys/class/chromeos/<ec-device-name>/lightbar/interval_msec
10+
Date: August 2015
11+
KernelVersion: 4.2
12+
Description:
13+
The lightbar is controlled by an embedded controller (EC),
14+
which also manages the keyboard, battery charging, fans,
15+
and other system hardware. To prevent unprivileged users
16+
from interfering with the other EC functions, the rate at
17+
which the lightbar control files can be read or written is
18+
limited.
19+
20+
Reading this file will return the number of milliseconds
21+
that must elapse between accessing any of the lightbar
22+
functions through this interface. Going faster will simply
23+
block until the necessary interval has lapsed. The interval
24+
applies uniformly to all accesses of any kind by any user.
25+
26+
What: /sys/class/chromeos/<ec-device-name>/lightbar/led_rgb
27+
Date: August 2015
28+
KernelVersion: 4.2
29+
Description:
30+
This allows you to control each LED segment. If the
31+
lightbar is already running one of the automatic
32+
sequences, you probably won’t see anything change because
33+
your color setting will be almost immediately replaced.
34+
To get useful results, you should stop the lightbar
35+
sequence first.
36+
37+
The values written to this file are sets of four integers,
38+
indicating LED, RED, GREEN, BLUE. The LED number is 0 to 3
39+
to select a single segment, or 4 to set all four segments
40+
to the same value at once. The RED, GREEN, and BLUE
41+
numbers should be in the range 0 (off) to 255 (maximum).
42+
You can update more than one segment at a time by writing
43+
more than one set of four integers.
44+
45+
What: /sys/class/chromeos/<ec-device-name>/lightbar/program
46+
Date: August 2015
47+
KernelVersion: 4.2
48+
Description:
49+
This allows you to upload and run custom lightbar sequences.
50+
51+
What: /sys/class/chromeos/<ec-device-name>/lightbar/sequence
52+
Date: August 2015
53+
KernelVersion: 4.2
54+
Description:
55+
The Pixel lightbar has a number of built-in sequences
56+
that it displays under various conditions, such as at
57+
power on, shut down, or while running. Reading from this
58+
file displays the current sequence that the lightbar is
59+
displaying. Writing to this file allows you to change the
60+
sequence.
61+
62+
What: /sys/class/chromeos/<ec-device-name>/lightbar/userspace_control
63+
Date: August 2015
64+
KernelVersion: 4.2
65+
Description:
66+
This allows you to take the control of the lightbar. This
67+
prevents the kernel from going through its normal
68+
sequences.
69+
70+
What: /sys/class/chromeos/<ec-device-name>/lightbar/version
71+
Date: August 2015
72+
KernelVersion: 4.2
73+
Description:
74+
Show the information about the lightbar version.

‎drivers/mfd/cros_ec_dev.c‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ static int ec_major;
3636

3737
static const struct attribute_group *cros_ec_groups[] = {
3838
&cros_ec_attr_group,
39-
&cros_ec_lightbar_attr_group,
4039
&cros_ec_vbc_attr_group,
4140
NULL,
4241
};
@@ -395,6 +394,10 @@ static const struct mfd_cell cros_usbpd_charger_cells[] = {
395394
{ .name = "cros-usbpd-charger" }
396395
};
397396

397+
static const struct mfd_cell cros_ec_platform_cells[] = {
398+
{ .name = "cros-ec-lightbar" },
399+
};
400+
398401
static int ec_device_probe(struct platform_device *pdev)
399402
{
400403
int retval = -ENOMEM;
@@ -470,16 +473,22 @@ static int ec_device_probe(struct platform_device *pdev)
470473
retval);
471474
}
472475

473-
/* Take control of the lightbar from the EC. */
474-
lb_manual_suspend_ctrl(ec, 1);
475-
476476
/* We can now add the sysfs class, we know which parameter to show */
477477
retval = cdev_device_add(&ec->cdev, &ec->class_dev);
478478
if (retval) {
479479
dev_err(dev, "cdev_device_add failed => %d\n", retval);
480480
goto failed;
481481
}
482482

483+
retval = mfd_add_devices(ec->dev, PLATFORM_DEVID_AUTO,
484+
cros_ec_platform_cells,
485+
ARRAY_SIZE(cros_ec_platform_cells),
486+
NULL, 0, NULL);
487+
if (retval)
488+
dev_warn(ec->dev,
489+
"failed to add cros-ec platform devices: %d\n",
490+
retval);
491+
483492
if (cros_ec_debugfs_init(ec))
484493
dev_warn(dev, "failed to create debugfs directory\n");
485494

@@ -494,9 +503,6 @@ static int ec_device_remove(struct platform_device *pdev)
494503
{
495504
struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev);
496505

497-
/* Let the EC take over the lightbar again. */
498-
lb_manual_suspend_ctrl(ec, 0);
499-
500506
cros_ec_debugfs_remove(ec);
501507

502508
mfd_remove_devices(ec->dev);
@@ -525,8 +531,6 @@ static __maybe_unused int ec_device_suspend(struct device *dev)
525531

526532
cros_ec_debugfs_suspend(ec);
527533

528-
lb_suspend(ec);
529-
530534
return 0;
531535
}
532536

@@ -536,8 +540,6 @@ static __maybe_unused int ec_device_resume(struct device *dev)
536540

537541
cros_ec_debugfs_resume(ec);
538542

539-
lb_resume(ec);
540-
541543
return 0;
542544
}
543545

‎drivers/mfd/cros_ec_dev.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,4 @@ struct cros_ec_readmem {
4444
#define CROS_EC_DEV_IOCXCMD _IOWR(CROS_EC_DEV_IOC, 0, struct cros_ec_command)
4545
#define CROS_EC_DEV_IOCRDMEM _IOWR(CROS_EC_DEV_IOC, 1, struct cros_ec_readmem)
4646

47-
/* Lightbar utilities */
48-
extern bool ec_has_lightbar(struct cros_ec_dev *ec);
49-
extern int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable);
50-
extern int lb_suspend(struct cros_ec_dev *ec);
51-
extern int lb_resume(struct cros_ec_dev *ec);
52-
5347
#endif /* _CROS_EC_DEV_H_ */

‎drivers/platform/chrome/Kconfig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,15 @@ config CROS_KBD_LED_BACKLIGHT
111111
To compile this driver as a module, choose M here: the
112112
module will be called cros_kbd_led_backlight.
113113

114+
config CROS_EC_LIGHTBAR
115+
tristate "Chromebook Pixel's lightbar support"
116+
depends on MFD_CROS_EC_CHARDEV
117+
default MFD_CROS_EC_CHARDEV
118+
help
119+
This option exposes the Chromebook Pixel's lightbar to
120+
userspace.
121+
122+
To compile this driver as a module, choose M here: the
123+
module will be called cros_ec_lightbar.
124+
114125
endif # CHROMEOS_PLATFORMS

‎drivers/platform/chrome/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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 cros_ec_lightbar.o \
6+
cros_ec_ctl-objs := cros_ec_sysfs.o \
77
cros_ec_vbc.o cros_ec_debugfs.o
88
obj-$(CONFIG_CROS_EC_CTL) += cros_ec_ctl.o
99
obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o
@@ -13,3 +13,4 @@ cros_ec_lpcs-$(CONFIG_CROS_EC_LPC_MEC) += cros_ec_lpc_mec.o
1313
obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o
1414
obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o
1515
obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o
16+
obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o

‎drivers/platform/chrome/cros_ec_lightbar.c‎

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include <linux/uaccess.h>
3434
#include <linux/slab.h>
3535

36+
#define DRV_NAME "cros-ec-lightbar"
37+
3638
/* Rate-limit the lightbar interface to prevent DoS. */
3739
static unsigned long lb_interval_jiffies = 50 * HZ / 1000;
3840

@@ -373,7 +375,7 @@ static int lb_send_empty_cmd(struct cros_ec_dev *ec, uint8_t cmd)
373375
return ret;
374376
}
375377

376-
int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable)
378+
static int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable)
377379
{
378380
struct ec_params_lightbar *param;
379381
struct cros_ec_command *msg;
@@ -408,25 +410,6 @@ int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable)
408410

409411
return ret;
410412
}
411-
EXPORT_SYMBOL(lb_manual_suspend_ctrl);
412-
413-
int lb_suspend(struct cros_ec_dev *ec)
414-
{
415-
if (userspace_control || ec != ec_with_lightbar)
416-
return 0;
417-
418-
return lb_send_empty_cmd(ec, LIGHTBAR_CMD_SUSPEND);
419-
}
420-
EXPORT_SYMBOL(lb_suspend);
421-
422-
int lb_resume(struct cros_ec_dev *ec)
423-
{
424-
if (userspace_control || ec != ec_with_lightbar)
425-
return 0;
426-
427-
return lb_send_empty_cmd(ec, LIGHTBAR_CMD_RESUME);
428-
}
429-
EXPORT_SYMBOL(lb_resume);
430413

431414
static ssize_t sequence_store(struct device *dev, struct device_attribute *attr,
432415
const char *buf, size_t count)
@@ -584,7 +567,7 @@ static struct attribute *__lb_cmds_attrs[] = {
584567
NULL,
585568
};
586569

587-
bool ec_has_lightbar(struct cros_ec_dev *ec)
570+
static bool ec_has_lightbar(struct cros_ec_dev *ec)
588571
{
589572
return !!get_lightbar_version(ec, NULL, NULL);
590573
}
@@ -616,4 +599,72 @@ struct attribute_group cros_ec_lightbar_attr_group = {
616599
.attrs = __lb_cmds_attrs,
617600
.is_visible = cros_ec_lightbar_attrs_are_visible,
618601
};
619-
EXPORT_SYMBOL(cros_ec_lightbar_attr_group);
602+
603+
static int cros_ec_lightbar_probe(struct platform_device *pd)
604+
{
605+
struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
606+
struct device *dev = &pd->dev;
607+
int ret;
608+
609+
/* Take control of the lightbar from the EC. */
610+
lb_manual_suspend_ctrl(ec_dev, 1);
611+
612+
ret = sysfs_create_group(&ec_dev->class_dev.kobj,
613+
&cros_ec_lightbar_attr_group);
614+
if (ret < 0)
615+
dev_err(dev, "failed to create %s attributes. err=%d\n",
616+
cros_ec_lightbar_attr_group.name, ret);
617+
618+
return ret;
619+
}
620+
621+
static int cros_ec_lightbar_remove(struct platform_device *pd)
622+
{
623+
struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
624+
625+
sysfs_remove_group(&ec_dev->class_dev.kobj,
626+
&cros_ec_lightbar_attr_group);
627+
628+
/* Let the EC take over the lightbar again. */
629+
lb_manual_suspend_ctrl(ec_dev, 0);
630+
631+
return 0;
632+
}
633+
634+
static int __maybe_unused cros_ec_lightbar_resume(struct device *dev)
635+
{
636+
struct cros_ec_dev *ec_dev = dev_get_drvdata(dev);
637+
638+
if (userspace_control || ec_dev != ec_with_lightbar)
639+
return 0;
640+
641+
return lb_send_empty_cmd(ec_dev, LIGHTBAR_CMD_RESUME);
642+
}
643+
644+
static int __maybe_unused cros_ec_lightbar_suspend(struct device *dev)
645+
{
646+
struct cros_ec_dev *ec_dev = dev_get_drvdata(dev);
647+
648+
if (userspace_control || ec_dev != ec_with_lightbar)
649+
return 0;
650+
651+
return lb_send_empty_cmd(ec_dev, LIGHTBAR_CMD_SUSPEND);
652+
}
653+
654+
static SIMPLE_DEV_PM_OPS(cros_ec_lightbar_pm_ops,
655+
cros_ec_lightbar_suspend, cros_ec_lightbar_resume);
656+
657+
static struct platform_driver cros_ec_lightbar_driver = {
658+
.driver = {
659+
.name = DRV_NAME,
660+
.pm = &cros_ec_lightbar_pm_ops,
661+
},
662+
.probe = cros_ec_lightbar_probe,
663+
.remove = cros_ec_lightbar_remove,
664+
};
665+
666+
module_platform_driver(cros_ec_lightbar_driver);
667+
668+
MODULE_LICENSE("GPL");
669+
MODULE_DESCRIPTION("Expose the Chromebook Pixel's lightbar to userspace");
670+
MODULE_ALIAS("platform:" DRV_NAME);

‎include/linux/mfd/cros_ec.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);
327327

328328
/* sysfs stuff */
329329
extern struct attribute_group cros_ec_attr_group;
330-
extern struct attribute_group cros_ec_lightbar_attr_group;
331330
extern struct attribute_group cros_ec_vbc_attr_group;
332331

333332
/* debugfs stuff */

0 commit comments

Comments
 (0)