History

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.

Enric Balletbo i Serra committed 7 years ago

Commit ecf8a6c1 parent 4bc59c27 files · +173 −41Browse files

Unified · Split

7 files
  1. Documentation/ABI/testing/sysfs-class-chromeos-driver-cros-ec-lightbar +74 −0
  2. drivers/mfd/cros_ec_dev.c +13 −11
  3. drivers/mfd/cros_ec_dev.h +0 −6
  4. drivers/platform/chrome/Kconfig +11 −0
  5. drivers/platform/chrome/Makefile +2 −1
  6. drivers/platform/chrome/cros_ec_lightbar.c +73 −22
  7. include/linux/mfd/cros_ec.h +0 −1
Documentation/ABI/testing/sysfs-class-chromeos-driver-cros-ec-lightbar+74−0
@@ -0,0 +1,74 @@
1What: /sys/class/chromeos/<ec-device-name>/lightbar/brightness
2Date: August 2015
3KernelVersion: 4.2
4Description:
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
9What: /sys/class/chromeos/<ec-device-name>/lightbar/interval_msec
10Date: August 2015
11KernelVersion: 4.2
12Description:
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
26What: /sys/class/chromeos/<ec-device-name>/lightbar/led_rgb
27Date: August 2015
28KernelVersion: 4.2
29Description:
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
45What: /sys/class/chromeos/<ec-device-name>/lightbar/program
46Date: August 2015
47KernelVersion: 4.2
48Description:
49 This allows you to upload and run custom lightbar sequences.
50
51What: /sys/class/chromeos/<ec-device-name>/lightbar/sequence
52Date: August 2015
53KernelVersion: 4.2
54Description:
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
62What: /sys/class/chromeos/<ec-device-name>/lightbar/userspace_control
63Date: August 2015
64KernelVersion: 4.2
65Description:
66 This allows you to take the control of the lightbar. This
67 prevents the kernel from going through its normal
68 sequences.
69
70What: /sys/class/chromeos/<ec-device-name>/lightbar/version
71Date: August 2015
72KernelVersion: 4.2
73Description:
74 Show the information about the lightbar version.
drivers/mfd/cros_ec_dev.c+13−11
@@ -36,7 +36,6 @@ static int ec_major; · 35 unmodified lines
36 36
37static const struct attribute_group *cros_ec_groups[] = {37static const struct attribute_group *cros_ec_groups[] = {
38 &cros_ec_attr_group,38 &cros_ec_attr_group,
39 &cros_ec_lightbar_attr_group,
40 &cros_ec_vbc_attr_group,39 &cros_ec_vbc_attr_group,
41 NULL,40 NULL,
42};41};
@@ -395,6 +394,10 @@ static const struct mfd_cell cros_usbpd_charger_cells[] = { · 352 unmodified lines
395 { .name = "cros-usbpd-charger" }394 { .name = "cros-usbpd-charger" }
396};395};
397 396
397static const struct mfd_cell cros_ec_platform_cells[] = {
398 { .name = "cros-ec-lightbar" },
399};
400
398static int ec_device_probe(struct platform_device *pdev)401static int ec_device_probe(struct platform_device *pdev)
399{402{
400 int retval = -ENOMEM;403 int retval = -ENOMEM;
@@ -470,9 +473,6 @@ static int ec_device_probe(struct platform_device *pdev) · 69 unmodified lines
470 retval);473 retval);
471 }474 }
472 475
473 /* Take control of the lightbar from the EC. */
474 lb_manual_suspend_ctrl(ec, 1);
475
476 /* We can now add the sysfs class, we know which parameter to show */476 /* We can now add the sysfs class, we know which parameter to show */
477 retval = cdev_device_add(&ec->cdev, &ec->class_dev);477 retval = cdev_device_add(&ec->cdev, &ec->class_dev);
478 if (retval) {478 if (retval) {
@@ -480,6 +480,15 @@ static int ec_device_probe(struct platform_device *pdev) · 1 unmodified line
480 goto failed;480 goto failed;
481 }481 }
482 482
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
483 if (cros_ec_debugfs_init(ec))492 if (cros_ec_debugfs_init(ec))
484 dev_warn(dev, "failed to create debugfs directory\n");493 dev_warn(dev, "failed to create debugfs directory\n");
485 494
@@ -494,9 +503,6 @@ static int ec_device_remove(struct platform_device *pdev) · 8 unmodified lines
494{503{
495 struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev);504 struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev);
496 505
497 /* Let the EC take over the lightbar again. */
498 lb_manual_suspend_ctrl(ec, 0);
499
500 cros_ec_debugfs_remove(ec);506 cros_ec_debugfs_remove(ec);
501 507
502 mfd_remove_devices(ec->dev);508 mfd_remove_devices(ec->dev);
@@ -525,8 +531,6 @@ static __maybe_unused int ec_device_suspend(struct device *dev) · 22 unmodified lines
525 531
526 cros_ec_debugfs_suspend(ec);532 cros_ec_debugfs_suspend(ec);
527 533
528 lb_suspend(ec);
529
530 return 0;534 return 0;
531}535}
532 536
@@ -536,8 +540,6 @@ static __maybe_unused int ec_device_resume(struct device *dev) · 3 unmodified lines
536 540
537 cros_ec_debugfs_resume(ec);541 cros_ec_debugfs_resume(ec);
538 542
539 lb_resume(ec);
540
541 return 0;543 return 0;
542}544}
543 545
drivers/mfd/cros_ec_dev.h+0−6
@@ -44,10 +44,4 @@ struct cros_ec_readmem { · 43 unmodified lines
44#define CROS_EC_DEV_IOCXCMD _IOWR(CROS_EC_DEV_IOC, 0, struct cros_ec_command)44#define CROS_EC_DEV_IOCXCMD _IOWR(CROS_EC_DEV_IOC, 0, struct cros_ec_command)
45#define CROS_EC_DEV_IOCRDMEM _IOWR(CROS_EC_DEV_IOC, 1, struct cros_ec_readmem)45#define CROS_EC_DEV_IOCRDMEM _IOWR(CROS_EC_DEV_IOC, 1, struct cros_ec_readmem)
46 46
47/* Lightbar utilities */
48extern bool ec_has_lightbar(struct cros_ec_dev *ec);
49extern int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable);
50extern int lb_suspend(struct cros_ec_dev *ec);
51extern int lb_resume(struct cros_ec_dev *ec);
52
53#endif /* _CROS_EC_DEV_H_ */47#endif /* _CROS_EC_DEV_H_ */
drivers/platform/chrome/Kconfig+11−0
@@ -111,4 +111,15 @@ config CROS_KBD_LED_BACKLIGHT · 110 unmodified lines
111 To compile this driver as a module, choose M here: the111 To compile this driver as a module, choose M here: the
112 module will be called cros_kbd_led_backlight.112 module will be called cros_kbd_led_backlight.
113 113
114config 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
114endif # CHROMEOS_PLATFORMS125endif # CHROMEOS_PLATFORMS
drivers/platform/chrome/Makefile+2−1
@@ -3,7 +3,7 @@ · 2 unmodified lines
3obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o3obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o
4obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o4obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o
5obj-$(CONFIG_CHROMEOS_TBMC) += chromeos_tbmc.o5obj-$(CONFIG_CHROMEOS_TBMC) += chromeos_tbmc.o
6cros_ec_ctl-objs := cros_ec_sysfs.o cros_ec_lightbar.o \6cros_ec_ctl-objs := cros_ec_sysfs.o \
7 cros_ec_vbc.o cros_ec_debugfs.o7 cros_ec_vbc.o cros_ec_debugfs.o
8obj-$(CONFIG_CROS_EC_CTL) += cros_ec_ctl.o8obj-$(CONFIG_CROS_EC_CTL) += cros_ec_ctl.o
9obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o9obj-$(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 · 3 unmodified lines
13obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o13obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o
14obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o14obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o
15obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o15obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o
16obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o
drivers/platform/chrome/cros_ec_lightbar.c+73−22
@@ -33,6 +33,8 @@ · 32 unmodified lines
33#include <linux/uaccess.h>33#include <linux/uaccess.h>
34#include <linux/slab.h>34#include <linux/slab.h>
35 35
36#define DRV_NAME "cros-ec-lightbar"
37
36/* Rate-limit the lightbar interface to prevent DoS. */38/* Rate-limit the lightbar interface to prevent DoS. */
37static unsigned long lb_interval_jiffies = 50 * HZ / 1000;39static unsigned long lb_interval_jiffies = 50 * HZ / 1000;
38 40
@@ -373,7 +375,7 @@ error: · 334 unmodified lines
373 return ret;375 return ret;
374}376}
375 377
376int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable)378static int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable)
377{379{
378 struct ec_params_lightbar *param;380 struct ec_params_lightbar *param;
379 struct cros_ec_command *msg;381 struct cros_ec_command *msg;
@@ -408,25 +410,6 @@ error: · 28 unmodified lines
408 410
409 return ret;411 return ret;
410}412}
411EXPORT_SYMBOL(lb_manual_suspend_ctrl);
412
413int 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}
420EXPORT_SYMBOL(lb_suspend);
421
422int 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}
429EXPORT_SYMBOL(lb_resume);
430 413
431static ssize_t sequence_store(struct device *dev, struct device_attribute *attr,414static ssize_t sequence_store(struct device *dev, struct device_attribute *attr,
432 const char *buf, size_t count)415 const char *buf, size_t count)
@@ -584,7 +567,7 @@ static struct attribute *__lb_cmds_attrs[] = { · 151 unmodified lines
584 NULL,567 NULL,
585};568};
586 569
587bool ec_has_lightbar(struct cros_ec_dev *ec)570static bool ec_has_lightbar(struct cros_ec_dev *ec)
588{571{
589 return !!get_lightbar_version(ec, NULL, NULL);572 return !!get_lightbar_version(ec, NULL, NULL);
590}573}
@@ -616,4 +599,72 @@ struct attribute_group cros_ec_lightbar_attr_group = { · 25 unmodified lines
616 .attrs = __lb_cmds_attrs,599 .attrs = __lb_cmds_attrs,
617 .is_visible = cros_ec_lightbar_attrs_are_visible,600 .is_visible = cros_ec_lightbar_attrs_are_visible,
618};601};
619EXPORT_SYMBOL(cros_ec_lightbar_attr_group);602
603static 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
621static 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
634static 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
644static 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
654static SIMPLE_DEV_PM_OPS(cros_ec_lightbar_pm_ops,
655 cros_ec_lightbar_suspend, cros_ec_lightbar_resume);
656
657static 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
666module_platform_driver(cros_ec_lightbar_driver);
667
668MODULE_LICENSE("GPL");
669MODULE_DESCRIPTION("Expose the Chromebook Pixel's lightbar to userspace");
670MODULE_ALIAS("platform:" DRV_NAME);
include/linux/mfd/cros_ec.h+0−1
@@ -327,7 +327,6 @@ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); · 326 unmodified lines
327 327
328/* sysfs stuff */328/* sysfs stuff */
329extern struct attribute_group cros_ec_attr_group;329extern struct attribute_group cros_ec_attr_group;
330extern struct attribute_group cros_ec_lightbar_attr_group;
331extern struct attribute_group cros_ec_vbc_attr_group;330extern struct attribute_group cros_ec_vbc_attr_group;
332 331
333/* debugfs stuff */332/* debugfs stuff */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t