コード例 #1
0
static ssize_t brightness_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t size)
{
	struct led_classdev *led_cdev = dev_get_drvdata(dev);
	unsigned long state;
	ssize_t ret;

	mutex_lock(&led_cdev->led_access);

	if (led_sysfs_is_disabled(led_cdev)) {
		ret = -EBUSY;
		goto unlock;
	}

	ret = kstrtoul(buf, 10, &state);
	if (ret)
		goto unlock;

	if (state == LED_OFF)
		led_trigger_remove(led_cdev);
	led_set_brightness(led_cdev, state);

	ret = size;
unlock:
	mutex_unlock(&led_cdev->led_access);
	return ret;
}
コード例 #2
0
ファイル: light.c プロジェクト: gregkh/greybus
static ssize_t color_store(struct device *dev, struct device_attribute *attr,
			   const char *buf, size_t size)
{
	struct led_classdev *cdev = dev_get_drvdata(dev);
	struct gb_channel *channel = get_channel_from_cdev(cdev);
	u32 color;
	int ret;

	led_lock(cdev);
	if (led_sysfs_is_disabled(cdev)) {
		ret = -EBUSY;
		goto unlock;
	}
	ret = kstrtou32(buf, 0, &color);
	if (ret < 0) {
		dev_err(dev, "could not parse color value %d\n", ret);
		goto unlock;
	}

	ret = gb_lights_color_set(channel, color);
	if (ret < 0)
		goto unlock;

	channel->color = color;
	ret = size;
unlock:
	led_unlock(cdev);
	return ret;
}