Add attribute group for kb_led_color
Create the attribute groups for kb_led_color and set the `groups` field in kb_led. While touching it, also change its show method to use sysfs_emit() instead of sprintf(). Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
parent
c169971892
commit
b82bcba7d9
|
|
@ -357,7 +357,11 @@ static ssize_t kb_led_color_show(
|
||||||
|
|
||||||
led = (struct led_classdev *)dev->driver_data;
|
led = (struct led_classdev *)dev->driver_data;
|
||||||
data = container_of(led, struct system76_data, kb_led);
|
data = container_of(led, struct system76_data, kb_led);
|
||||||
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)
|
||||||
|
return sysfs_emit(buf, "%06X\n", data->kb_color);
|
||||||
|
#else
|
||||||
return sprintf(buf, "%06X\n", data->kb_color);
|
return sprintf(buf, "%06X\n", data->kb_color);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the keyboard LED color
|
// Set the keyboard LED color
|
||||||
|
|
@ -385,7 +389,7 @@ static ssize_t kb_led_color_store(
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct device_attribute kb_led_color_dev_attr = {
|
static struct device_attribute dev_attr_kb_led_color = {
|
||||||
.attr = {
|
.attr = {
|
||||||
.name = "color",
|
.name = "color",
|
||||||
.mode = 0644,
|
.mode = 0644,
|
||||||
|
|
@ -394,6 +398,13 @@ static const struct device_attribute kb_led_color_dev_attr = {
|
||||||
.store = kb_led_color_store,
|
.store = kb_led_color_store,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct attribute *system76_kb_led_color_attrs[] = {
|
||||||
|
&dev_attr_kb_led_color.attr,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
ATTRIBUTE_GROUPS(system76_kb_led_color);
|
||||||
|
|
||||||
// Notify that the keyboard LED was changed by hardware
|
// Notify that the keyboard LED was changed by hardware
|
||||||
static void kb_led_notify(struct system76_data *data)
|
static void kb_led_notify(struct system76_data *data)
|
||||||
{
|
{
|
||||||
|
|
@ -698,6 +709,7 @@ static int system76_add(struct acpi_device *acpi_dev)
|
||||||
data->kb_led.brightness_set_blocking = kb_led_set;
|
data->kb_led.brightness_set_blocking = kb_led_set;
|
||||||
if (acpi_has_method(acpi_device_handle(data->acpi_dev), "SKBC")) {
|
if (acpi_has_method(acpi_device_handle(data->acpi_dev), "SKBC")) {
|
||||||
data->kb_led.max_brightness = 255;
|
data->kb_led.max_brightness = 255;
|
||||||
|
data->kb_led.groups = system76_kb_led_color_groups;
|
||||||
data->kb_toggle_brightness = 72;
|
data->kb_toggle_brightness = 72;
|
||||||
data->kb_color = 0xffffff;
|
data->kb_color = 0xffffff;
|
||||||
system76_set(data, "SKBC", data->kb_color);
|
system76_set(data, "SKBC", data->kb_color);
|
||||||
|
|
@ -709,15 +721,6 @@ static int system76_add(struct acpi_device *acpi_dev)
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (data->kb_color >= 0) {
|
|
||||||
err = device_create_file(
|
|
||||||
data->kb_led.dev,
|
|
||||||
&kb_led_color_dev_attr
|
|
||||||
);
|
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
data->input = devm_input_allocate_device(&acpi_dev->dev);
|
data->input = devm_input_allocate_device(&acpi_dev->dev);
|
||||||
if (!data->input)
|
if (!data->input)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
@ -766,9 +769,6 @@ static int system76_remove(struct acpi_device *acpi_dev)
|
||||||
|
|
||||||
system76_battery_exit();
|
system76_battery_exit();
|
||||||
|
|
||||||
if (data->kb_color >= 0)
|
|
||||||
device_remove_file(data->kb_led.dev, &kb_led_color_dev_attr);
|
|
||||||
|
|
||||||
devm_led_classdev_unregister(&acpi_dev->dev, &data->ap_led);
|
devm_led_classdev_unregister(&acpi_dev->dev, &data->ap_led);
|
||||||
devm_led_classdev_unregister(&acpi_dev->dev, &data->kb_led);
|
devm_led_classdev_unregister(&acpi_dev->dev, &data->kb_led);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue