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>
This commit is contained in:
committed by
Lee Jones
parent
4bc59c2f7e
commit
ecf8a6cd94
@@ -111,4 +111,15 @@ config CROS_KBD_LED_BACKLIGHT
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called cros_kbd_led_backlight.
|
||||
|
||||
config CROS_EC_LIGHTBAR
|
||||
tristate "Chromebook Pixel's lightbar support"
|
||||
depends on MFD_CROS_EC_CHARDEV
|
||||
default MFD_CROS_EC_CHARDEV
|
||||
help
|
||||
This option exposes the Chromebook Pixel's lightbar to
|
||||
userspace.
|
||||
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called cros_ec_lightbar.
|
||||
|
||||
endif # CHROMEOS_PLATFORMS
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o
|
||||
obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o
|
||||
obj-$(CONFIG_CHROMEOS_TBMC) += chromeos_tbmc.o
|
||||
cros_ec_ctl-objs := cros_ec_sysfs.o cros_ec_lightbar.o \
|
||||
cros_ec_ctl-objs := cros_ec_sysfs.o \
|
||||
cros_ec_vbc.o cros_ec_debugfs.o
|
||||
obj-$(CONFIG_CROS_EC_CTL) += cros_ec_ctl.o
|
||||
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
|
||||
obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o
|
||||
obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o
|
||||
obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o
|
||||
obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#define DRV_NAME "cros-ec-lightbar"
|
||||
|
||||
/* Rate-limit the lightbar interface to prevent DoS. */
|
||||
static unsigned long lb_interval_jiffies = 50 * HZ / 1000;
|
||||
|
||||
@@ -373,7 +375,7 @@ error:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable)
|
||||
static int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable)
|
||||
{
|
||||
struct ec_params_lightbar *param;
|
||||
struct cros_ec_command *msg;
|
||||
@@ -408,25 +410,6 @@ error:
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(lb_manual_suspend_ctrl);
|
||||
|
||||
int lb_suspend(struct cros_ec_dev *ec)
|
||||
{
|
||||
if (userspace_control || ec != ec_with_lightbar)
|
||||
return 0;
|
||||
|
||||
return lb_send_empty_cmd(ec, LIGHTBAR_CMD_SUSPEND);
|
||||
}
|
||||
EXPORT_SYMBOL(lb_suspend);
|
||||
|
||||
int lb_resume(struct cros_ec_dev *ec)
|
||||
{
|
||||
if (userspace_control || ec != ec_with_lightbar)
|
||||
return 0;
|
||||
|
||||
return lb_send_empty_cmd(ec, LIGHTBAR_CMD_RESUME);
|
||||
}
|
||||
EXPORT_SYMBOL(lb_resume);
|
||||
|
||||
static ssize_t sequence_store(struct device *dev, struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
@@ -584,7 +567,7 @@ static struct attribute *__lb_cmds_attrs[] = {
|
||||
NULL,
|
||||
};
|
||||
|
||||
bool ec_has_lightbar(struct cros_ec_dev *ec)
|
||||
static bool ec_has_lightbar(struct cros_ec_dev *ec)
|
||||
{
|
||||
return !!get_lightbar_version(ec, NULL, NULL);
|
||||
}
|
||||
@@ -616,4 +599,72 @@ struct attribute_group cros_ec_lightbar_attr_group = {
|
||||
.attrs = __lb_cmds_attrs,
|
||||
.is_visible = cros_ec_lightbar_attrs_are_visible,
|
||||
};
|
||||
EXPORT_SYMBOL(cros_ec_lightbar_attr_group);
|
||||
|
||||
static int cros_ec_lightbar_probe(struct platform_device *pd)
|
||||
{
|
||||
struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
|
||||
struct device *dev = &pd->dev;
|
||||
int ret;
|
||||
|
||||
/* Take control of the lightbar from the EC. */
|
||||
lb_manual_suspend_ctrl(ec_dev, 1);
|
||||
|
||||
ret = sysfs_create_group(&ec_dev->class_dev.kobj,
|
||||
&cros_ec_lightbar_attr_group);
|
||||
if (ret < 0)
|
||||
dev_err(dev, "failed to create %s attributes. err=%d\n",
|
||||
cros_ec_lightbar_attr_group.name, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int cros_ec_lightbar_remove(struct platform_device *pd)
|
||||
{
|
||||
struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
|
||||
|
||||
sysfs_remove_group(&ec_dev->class_dev.kobj,
|
||||
&cros_ec_lightbar_attr_group);
|
||||
|
||||
/* Let the EC take over the lightbar again. */
|
||||
lb_manual_suspend_ctrl(ec_dev, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __maybe_unused cros_ec_lightbar_resume(struct device *dev)
|
||||
{
|
||||
struct cros_ec_dev *ec_dev = dev_get_drvdata(dev);
|
||||
|
||||
if (userspace_control || ec_dev != ec_with_lightbar)
|
||||
return 0;
|
||||
|
||||
return lb_send_empty_cmd(ec_dev, LIGHTBAR_CMD_RESUME);
|
||||
}
|
||||
|
||||
static int __maybe_unused cros_ec_lightbar_suspend(struct device *dev)
|
||||
{
|
||||
struct cros_ec_dev *ec_dev = dev_get_drvdata(dev);
|
||||
|
||||
if (userspace_control || ec_dev != ec_with_lightbar)
|
||||
return 0;
|
||||
|
||||
return lb_send_empty_cmd(ec_dev, LIGHTBAR_CMD_SUSPEND);
|
||||
}
|
||||
|
||||
static SIMPLE_DEV_PM_OPS(cros_ec_lightbar_pm_ops,
|
||||
cros_ec_lightbar_suspend, cros_ec_lightbar_resume);
|
||||
|
||||
static struct platform_driver cros_ec_lightbar_driver = {
|
||||
.driver = {
|
||||
.name = DRV_NAME,
|
||||
.pm = &cros_ec_lightbar_pm_ops,
|
||||
},
|
||||
.probe = cros_ec_lightbar_probe,
|
||||
.remove = cros_ec_lightbar_remove,
|
||||
};
|
||||
|
||||
module_platform_driver(cros_ec_lightbar_driver);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("Expose the Chromebook Pixel's lightbar to userspace");
|
||||
MODULE_ALIAS("platform:" DRV_NAME);
|
||||
|
||||
Reference in New Issue
Block a user