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.
Unified · Split
| @@ -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. | |
| @@ -36,7 +36,6 @@ static int ec_major; · 35 unmodified lines | ||
| 36 | 36 | |
| 37 | 37 | static const struct attribute_group *cros_ec_groups[] = { |
| 38 | 38 | &cros_ec_attr_group, |
| 39 | − &cros_ec_lightbar_attr_group, | |
| 40 | 39 | &cros_ec_vbc_attr_group, |
| 41 | 40 | NULL, |
| 42 | 41 | }; |
| @@ -395,6 +394,10 @@ static const struct mfd_cell cros_usbpd_charger_cells[] = { · 352 unmodified lines | ||
| 395 | 394 | { .name = "cros-usbpd-charger" } |
| 396 | 395 | }; |
| 397 | 396 | |
| 397 | +static const struct mfd_cell cros_ec_platform_cells[] = { | |
| 398 | + { .name = "cros-ec-lightbar" }, | |
| 399 | +}; | |
| 400 | + | |
| 398 | 401 | static int ec_device_probe(struct platform_device *pdev) |
| 399 | 402 | { |
| 400 | 403 | int retval = -ENOMEM; |
| @@ -470,9 +473,6 @@ static int ec_device_probe(struct platform_device *pdev) · 69 unmodified lines | ||
| 470 | 473 | retval); |
| 471 | 474 | } |
| 472 | 475 | |
| 473 | − /* Take control of the lightbar from the EC. */ | |
| 474 | − lb_manual_suspend_ctrl(ec, 1); | |
| 475 | − | |
| 476 | 476 | /* We can now add the sysfs class, we know which parameter to show */ |
| 477 | 477 | retval = cdev_device_add(&ec->cdev, &ec->class_dev); |
| 478 | 478 | if (retval) { |
| @@ -480,6 +480,15 @@ static int ec_device_probe(struct platform_device *pdev) · 1 unmodified line | ||
| 480 | 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 | 492 | if (cros_ec_debugfs_init(ec)) |
| 484 | 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 | 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 | 506 | cros_ec_debugfs_remove(ec); |
| 501 | 507 | |
| 502 | 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 | 532 | cros_ec_debugfs_suspend(ec); |
| 527 | 533 | |
| 528 | − lb_suspend(ec); | |
| 529 | − | |
| 530 | 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 | 541 | cros_ec_debugfs_resume(ec); |
| 538 | 542 | |
| 539 | − lb_resume(ec); | |
| 540 | − | |
| 541 | 543 | return 0; |
| 542 | 544 | } |
| 543 | 545 | |
| @@ -44,10 +44,4 @@ struct cros_ec_readmem { · 43 unmodified lines | ||
| 44 | 44 | #define CROS_EC_DEV_IOCXCMD _IOWR(CROS_EC_DEV_IOC, 0, struct cros_ec_command) |
| 45 | 45 | #define CROS_EC_DEV_IOCRDMEM _IOWR(CROS_EC_DEV_IOC, 1, struct cros_ec_readmem) |
| 46 | 46 | |
| 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 | − | |
| 53 | 47 | #endif /* _CROS_EC_DEV_H_ */ |
| @@ -111,4 +111,15 @@ config CROS_KBD_LED_BACKLIGHT · 110 unmodified lines | ||
| 111 | 111 | To compile this driver as a module, choose M here: the |
| 112 | 112 | module will be called cros_kbd_led_backlight. |
| 113 | 113 | |
| 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 | + | |
| 114 | 125 | endif # CHROMEOS_PLATFORMS |
| @@ -3,7 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o |
| 4 | 4 | obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o |
| 5 | 5 | 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 \ | |
| 7 | 7 | cros_ec_vbc.o cros_ec_debugfs.o |
| 8 | 8 | obj-$(CONFIG_CROS_EC_CTL) += cros_ec_ctl.o |
| 9 | 9 | 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 · 3 unmodified lines | ||
| 13 | 13 | obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o |
| 14 | 14 | obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o |
| 15 | 15 | obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o |
| 16 | +obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o | |
| @@ -33,6 +33,8 @@ · 32 unmodified lines | ||
| 33 | 33 | #include <linux/uaccess.h> |
| 34 | 34 | #include <linux/slab.h> |
| 35 | 35 | |
| 36 | +#define DRV_NAME "cros-ec-lightbar" | |
| 37 | + | |
| 36 | 38 | /* Rate-limit the lightbar interface to prevent DoS. */ |
| 37 | 39 | static unsigned long lb_interval_jiffies = 50 * HZ / 1000; |
| 38 | 40 | |
| @@ -373,7 +375,7 @@ error: · 334 unmodified lines | ||
| 373 | 375 | return ret; |
| 374 | 376 | } |
| 375 | 377 | |
| 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) | |
| 377 | 379 | { |
| 378 | 380 | struct ec_params_lightbar *param; |
| 379 | 381 | struct cros_ec_command *msg; |
| @@ -408,25 +410,6 @@ error: · 28 unmodified lines | ||
| 408 | 410 | |
| 409 | 411 | return ret; |
| 410 | 412 | } |
| 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); | |
| 430 | 413 | |
| 431 | 414 | static ssize_t sequence_store(struct device *dev, struct device_attribute *attr, |
| 432 | 415 | const char *buf, size_t count) |
| @@ -584,7 +567,7 @@ static struct attribute *__lb_cmds_attrs[] = { · 151 unmodified lines | ||
| 584 | 567 | NULL, |
| 585 | 568 | }; |
| 586 | 569 | |
| 587 | −bool ec_has_lightbar(struct cros_ec_dev *ec) | |
| 570 | +static bool ec_has_lightbar(struct cros_ec_dev *ec) | |
| 588 | 571 | { |
| 589 | 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 | 599 | .attrs = __lb_cmds_attrs, |
| 617 | 600 | .is_visible = cros_ec_lightbar_attrs_are_visible, |
| 618 | 601 | }; |
| 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); | |
| @@ -327,7 +327,6 @@ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); · 326 unmodified lines | ||
| 327 | 327 | |
| 328 | 328 | /* sysfs stuff */ |
| 329 | 329 | extern struct attribute_group cros_ec_attr_group; |
| 330 | −extern struct attribute_group cros_ec_lightbar_attr_group; | |
| 331 | 330 | extern struct attribute_group cros_ec_vbc_attr_group; |
| 332 | 331 | |
| 333 | 332 | /* debugfs stuff */ |