Commit 61ebca93 authored by Frank Praznik's avatar Frank Praznik Committed by Jiri Kosina

HID: sony: Use colors for the Dualshock 4 LED names

Use the naming scheme 'devicename:colour' for the Dualshock 4
LED lightbar controls as specified in Documentation/leds/leds-class.txt
Signed-off-by: default avatarFrank Praznik <frank.praznik@oh.rr.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 58d7027b
...@@ -834,33 +834,39 @@ static int sony_leds_init(struct hid_device *hdev) ...@@ -834,33 +834,39 @@ static int sony_leds_init(struct hid_device *hdev)
struct sony_sc *drv_data; struct sony_sc *drv_data;
int n, ret = 0; int n, ret = 0;
int max_brightness; int max_brightness;
int use_colors;
struct led_classdev *led; struct led_classdev *led;
size_t name_sz; size_t name_sz;
char *name; char *name;
size_t name_len; size_t name_len;
const char *name_fmt; const char *name_fmt;
static const char * const color_str[] = { "red", "green", "blue" };
static const __u8 initial_values[MAX_LEDS] = { 0x00, 0x00, 0x00, 0x00 }; static const __u8 initial_values[MAX_LEDS] = { 0x00, 0x00, 0x00, 0x00 };
drv_data = hid_get_drvdata(hdev); drv_data = hid_get_drvdata(hdev);
BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT)); BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT));
if (drv_data->quirks & BUZZ_CONTROLLER) { if (drv_data->quirks & BUZZ_CONTROLLER) {
drv_data->led_count = 4;
max_brightness = 1;
use_colors = 0;
name_len = strlen("::buzz#"); name_len = strlen("::buzz#");
name_fmt = "%s::buzz%d"; name_fmt = "%s::buzz%d";
/* Validate expected report characteristics. */ /* Validate expected report characteristics. */
if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7)) if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7))
return -ENODEV; return -ENODEV;
} else { } else if (drv_data->quirks & DUALSHOCK4_CONTROLLER_USB) {
name_len = strlen("::sony#");
name_fmt = "%s::sony%d";
}
if (drv_data->quirks & DUALSHOCK4_CONTROLLER_USB) {
drv_data->led_count = 3; drv_data->led_count = 3;
max_brightness = 255; max_brightness = 255;
use_colors = 1;
name_len = 0;
name_fmt = "%s:%s";
} else { } else {
drv_data->led_count = 4; drv_data->led_count = 4;
max_brightness = 1; max_brightness = 1;
use_colors = 0;
name_len = strlen("::sony#");
name_fmt = "%s::sony%d";
} }
/* Clear LEDs as we have no way of reading their initial state. This is /* Clear LEDs as we have no way of reading their initial state. This is
...@@ -871,6 +877,10 @@ static int sony_leds_init(struct hid_device *hdev) ...@@ -871,6 +877,10 @@ static int sony_leds_init(struct hid_device *hdev)
name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1; name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1;
for (n = 0; n < drv_data->led_count; n++) { for (n = 0; n < drv_data->led_count; n++) {
if (use_colors)
name_sz = strlen(dev_name(&hdev->dev)) + strlen(color_str[n]) + 2;
led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL); led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL);
if (!led) { if (!led) {
hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); hid_err(hdev, "Couldn't allocate memory for LED %d\n", n);
...@@ -879,6 +889,9 @@ static int sony_leds_init(struct hid_device *hdev) ...@@ -879,6 +889,9 @@ static int sony_leds_init(struct hid_device *hdev)
} }
name = (void *)(&led[1]); name = (void *)(&led[1]);
if (use_colors)
snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), color_str[n]);
else
snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1); snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1);
led->name = name; led->name = name;
led->brightness = 0; led->brightness = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment