|
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 @@ static int lb_send_empty_cmd(struct cros_ec_dev *ec, uint8_t cmd) |
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 @@ int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable) |
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[] = { |
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 = { |
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); |
0 commit comments