Commit 2251b85f authored by Sven Eckelmann's avatar Sven Eckelmann Committed by Jiri Kosina

HID: sony: Move LED data to the main structure

It is not necessary to keep the LED information in an extra struct which is
only used by the Buzz device. It can also be used by other devices.
Signed-off-by: default avatarSven Eckelmann <sven@narfation.org>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent c5382519
...@@ -223,6 +223,7 @@ static const unsigned int buzz_keymap[] = { ...@@ -223,6 +223,7 @@ static const unsigned int buzz_keymap[] = {
}; };
struct sony_sc { struct sony_sc {
struct led_classdev *leds[4];
unsigned long quirks; unsigned long quirks;
#ifdef CONFIG_SONY_FF #ifdef CONFIG_SONY_FF
...@@ -232,12 +233,7 @@ struct sony_sc { ...@@ -232,12 +233,7 @@ struct sony_sc {
__u8 right; __u8 right;
#endif #endif
void *extra; __u8 led_state;
};
struct buzz_extra {
int led_state;
struct led_classdev *leds[4];
}; };
static __u8 *ps3remote_fixup(struct hid_device *hdev, __u8 *rdesc, static __u8 *ps3remote_fixup(struct hid_device *hdev, __u8 *rdesc,
...@@ -472,26 +468,24 @@ static void sony_led_set_brightness(struct led_classdev *led, ...@@ -472,26 +468,24 @@ static void sony_led_set_brightness(struct led_classdev *led,
struct device *dev = led->dev->parent; struct device *dev = led->dev->parent;
struct hid_device *hdev = container_of(dev, struct hid_device, dev); struct hid_device *hdev = container_of(dev, struct hid_device, dev);
struct sony_sc *drv_data; struct sony_sc *drv_data;
struct buzz_extra *buzz;
int n; int n;
drv_data = hid_get_drvdata(hdev); drv_data = hid_get_drvdata(hdev);
if (!drv_data || !drv_data->extra) { if (!drv_data) {
hid_err(hdev, "No device data\n"); hid_err(hdev, "No device data\n");
return; return;
} }
buzz = drv_data->extra;
for (n = 0; n < 4; n++) { for (n = 0; n < 4; n++) {
if (led == buzz->leds[n]) { if (led == drv_data->leds[n]) {
int on = !! (buzz->led_state & (1 << n)); int on = !!(drv_data->led_state & (1 << n));
if (value == LED_OFF && on) { if (value == LED_OFF && on) {
buzz->led_state &= ~(1 << n); drv_data->led_state &= ~(1 << n);
buzz_set_leds(hdev, buzz->led_state); buzz_set_leds(hdev, drv_data->led_state);
} else if (value != LED_OFF && !on) { } else if (value != LED_OFF && !on) {
buzz->led_state |= (1 << n); drv_data->led_state |= (1 << n);
buzz_set_leds(hdev, buzz->led_state); buzz_set_leds(hdev, drv_data->led_state);
} }
break; break;
} }
...@@ -503,21 +497,19 @@ static enum led_brightness sony_led_get_brightness(struct led_classdev *led) ...@@ -503,21 +497,19 @@ static enum led_brightness sony_led_get_brightness(struct led_classdev *led)
struct device *dev = led->dev->parent; struct device *dev = led->dev->parent;
struct hid_device *hdev = container_of(dev, struct hid_device, dev); struct hid_device *hdev = container_of(dev, struct hid_device, dev);
struct sony_sc *drv_data; struct sony_sc *drv_data;
struct buzz_extra *buzz;
int n; int n;
int on = 0; int on = 0;
drv_data = hid_get_drvdata(hdev); drv_data = hid_get_drvdata(hdev);
if (!drv_data || !drv_data->extra) { if (!drv_data) {
hid_err(hdev, "No device data\n"); hid_err(hdev, "No device data\n");
return LED_OFF; return LED_OFF;
} }
buzz = drv_data->extra;
for (n = 0; n < 4; n++) { for (n = 0; n < 4; n++) {
if (led == buzz->leds[n]) { if (led == drv_data->leds[n]) {
on = !! (buzz->led_state & (1 << n)); on = !!(drv_data->led_state & (1 << n));
break; break;
} }
} }
...@@ -528,7 +520,6 @@ static enum led_brightness sony_led_get_brightness(struct led_classdev *led) ...@@ -528,7 +520,6 @@ static enum led_brightness sony_led_get_brightness(struct led_classdev *led)
static int sony_leds_init(struct hid_device *hdev) static int sony_leds_init(struct hid_device *hdev)
{ {
struct sony_sc *drv_data; struct sony_sc *drv_data;
struct buzz_extra *buzz;
int n, ret = 0; int n, ret = 0;
struct led_classdev *led; struct led_classdev *led;
size_t name_sz; size_t name_sz;
...@@ -541,13 +532,6 @@ static int sony_leds_init(struct hid_device *hdev) ...@@ -541,13 +532,6 @@ static int sony_leds_init(struct hid_device *hdev)
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;
buzz = kzalloc(sizeof(*buzz), GFP_KERNEL);
if (!buzz) {
hid_err(hdev, "Insufficient memory, cannot allocate driver data\n");
return -ENOMEM;
}
drv_data->extra = buzz;
/* 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
* only relevant if the driver is loaded after somebody actively set the * only relevant if the driver is loaded after somebody actively set the
* LEDs to on */ * LEDs to on */
...@@ -576,49 +560,41 @@ static int sony_leds_init(struct hid_device *hdev) ...@@ -576,49 +560,41 @@ static int sony_leds_init(struct hid_device *hdev)
goto error_leds; goto error_leds;
} }
buzz->leds[n] = led; drv_data->leds[n] = led;
} }
return ret; return ret;
error_leds: error_leds:
for (n = 0; n < 4; n++) { for (n = 0; n < 4; n++) {
led = buzz->leds[n]; led = drv_data->leds[n];
buzz->leds[n] = NULL; drv_data->leds[n] = NULL;
if (!led) if (!led)
continue; continue;
led_classdev_unregister(led); led_classdev_unregister(led);
kfree(led); kfree(led);
} }
kfree(drv_data->extra);
drv_data->extra = NULL;
return ret; return ret;
} }
static void sony_leds_remove(struct hid_device *hdev) static void sony_leds_remove(struct hid_device *hdev)
{ {
struct sony_sc *drv_data; struct sony_sc *drv_data;
struct buzz_extra *buzz;
struct led_classdev *led; struct led_classdev *led;
int n; int n;
drv_data = hid_get_drvdata(hdev); drv_data = hid_get_drvdata(hdev);
BUG_ON(!(drv_data->quirks & BUZZ_CONTROLLER)); BUG_ON(!(drv_data->quirks & BUZZ_CONTROLLER));
buzz = drv_data->extra;
for (n = 0; n < 4; n++) { for (n = 0; n < 4; n++) {
led = buzz->leds[n]; led = drv_data->leds[n];
buzz->leds[n] = NULL; drv_data->leds[n] = NULL;
if (!led) if (!led)
continue; continue;
led_classdev_unregister(led); led_classdev_unregister(led);
kfree(led); kfree(led);
} }
kfree(drv_data->extra);
drv_data->extra = NULL;
} }
#ifdef CONFIG_SONY_FF #ifdef CONFIG_SONY_FF
......
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