Skip to content

Commit

Permalink
HID: sony: Use colors for the Dualshock 4 LED names
Browse files Browse the repository at this point in the history
Use the naming scheme 'devicename:colour' for the Dualshock 4
LED lightbar controls as specified in Documentation/leds/leds-class.txt

Signed-off-by: Frank Praznik <frank.praznik@oh.rr.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Frank Praznik authored and Jiri Kosina committed Jan 21, 2014
1 parent 58d7027 commit 61ebca9
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions drivers/hid/hid-sony.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,33 +834,39 @@ static int sony_leds_init(struct hid_device *hdev)
struct sony_sc *drv_data;
int n, ret = 0;
int max_brightness;
int use_colors;
struct led_classdev *led;
size_t name_sz;
char *name;
size_t name_len;
const char *name_fmt;
static const char * const color_str[] = { "red", "green", "blue" };
static const __u8 initial_values[MAX_LEDS] = { 0x00, 0x00, 0x00, 0x00 };

drv_data = hid_get_drvdata(hdev);
BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT));

if (drv_data->quirks & BUZZ_CONTROLLER) {
drv_data->led_count = 4;
max_brightness = 1;
use_colors = 0;
name_len = strlen("::buzz#");
name_fmt = "%s::buzz%d";
/* Validate expected report characteristics. */
if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7))
return -ENODEV;
} else {
name_len = strlen("::sony#");
name_fmt = "%s::sony%d";
}

if (drv_data->quirks & DUALSHOCK4_CONTROLLER_USB) {
} else if (drv_data->quirks & DUALSHOCK4_CONTROLLER_USB) {
drv_data->led_count = 3;
max_brightness = 255;
use_colors = 1;
name_len = 0;
name_fmt = "%s:%s";
} else {
drv_data->led_count = 4;
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
Expand All @@ -871,6 +877,10 @@ static int sony_leds_init(struct hid_device *hdev)
name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1;

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);
if (!led) {
hid_err(hdev, "Couldn't allocate memory for LED %d\n", n);
Expand All @@ -879,7 +889,10 @@ static int sony_leds_init(struct hid_device *hdev)
}

name = (void *)(&led[1]);
snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 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);
led->name = name;
led->brightness = 0;
led->max_brightness = max_brightness;
Expand Down

0 comments on commit 61ebca9

Please sign in to comment.