aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid
diff options
context:
space:
mode:
authorFrank Praznik <frank.praznik@oh.rr.com>2014-01-20 12:27:02 -0500
committerJiri Kosina <jkosina@suse.cz>2014-01-21 01:59:17 -0500
commit61ebca937f2609e66fe6749f8f5df57ff387e2eb (patch)
tree4c5f008608a12ef1d11c704e1cb4f3fcc797378a /drivers/hid
parent58d7027b7f92b1c4d883126a54782c656a76cafd (diff)
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: Frank Praznik <frank.praznik@oh.rr.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r--drivers/hid/hid-sony.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 62765c76c56a..12354055d474 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -834,33 +834,39 @@ static int sony_leds_init(struct hid_device *hdev)
834 struct sony_sc *drv_data; 834 struct sony_sc *drv_data;
835 int n, ret = 0; 835 int n, ret = 0;
836 int max_brightness; 836 int max_brightness;
837 int use_colors;
837 struct led_classdev *led; 838 struct led_classdev *led;
838 size_t name_sz; 839 size_t name_sz;
839 char *name; 840 char *name;
840 size_t name_len; 841 size_t name_len;
841 const char *name_fmt; 842 const char *name_fmt;
843 static const char * const color_str[] = { "red", "green", "blue" };
842 static const __u8 initial_values[MAX_LEDS] = { 0x00, 0x00, 0x00, 0x00 }; 844 static const __u8 initial_values[MAX_LEDS] = { 0x00, 0x00, 0x00, 0x00 };
843 845
844 drv_data = hid_get_drvdata(hdev); 846 drv_data = hid_get_drvdata(hdev);
845 BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT)); 847 BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT));
846 848
847 if (drv_data->quirks & BUZZ_CONTROLLER) { 849 if (drv_data->quirks & BUZZ_CONTROLLER) {
850 drv_data->led_count = 4;
851 max_brightness = 1;
852 use_colors = 0;
848 name_len = strlen("::buzz#"); 853 name_len = strlen("::buzz#");
849 name_fmt = "%s::buzz%d"; 854 name_fmt = "%s::buzz%d";
850 /* Validate expected report characteristics. */ 855 /* Validate expected report characteristics. */
851 if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7)) 856 if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7))
852 return -ENODEV; 857 return -ENODEV;
853 } else { 858 } else if (drv_data->quirks & DUALSHOCK4_CONTROLLER_USB) {
854 name_len = strlen("::sony#");
855 name_fmt = "%s::sony%d";
856 }
857
858 if (drv_data->quirks & DUALSHOCK4_CONTROLLER_USB) {
859 drv_data->led_count = 3; 859 drv_data->led_count = 3;
860 max_brightness = 255; 860 max_brightness = 255;
861 use_colors = 1;
862 name_len = 0;
863 name_fmt = "%s:%s";
861 } else { 864 } else {
862 drv_data->led_count = 4; 865 drv_data->led_count = 4;
863 max_brightness = 1; 866 max_brightness = 1;
867 use_colors = 0;
868 name_len = strlen("::sony#");
869 name_fmt = "%s::sony%d";
864 } 870 }
865 871
866 /* Clear LEDs as we have no way of reading their initial state. This is 872 /* 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 name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1; 877 name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1;
872 878
873 for (n = 0; n < drv_data->led_count; n++) { 879 for (n = 0; n < drv_data->led_count; n++) {
880
881 if (use_colors)
882 name_sz = strlen(dev_name(&hdev->dev)) + strlen(color_str[n]) + 2;
883
874 led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL); 884 led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL);
875 if (!led) { 885 if (!led) {
876 hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); 886 hid_err(hdev, "Couldn't allocate memory for LED %d\n", n);
@@ -879,7 +889,10 @@ static int sony_leds_init(struct hid_device *hdev)
879 } 889 }
880 890
881 name = (void *)(&led[1]); 891 name = (void *)(&led[1]);
882 snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1); 892 if (use_colors)
893 snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), color_str[n]);
894 else
895 snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1);
883 led->name = name; 896 led->name = name;
884 led->brightness = 0; 897 led->brightness = 0;
885 led->max_brightness = max_brightness; 898 led->max_brightness = max_brightness;