HID: sony: Convert startup and shutdown functions to use a uniform parameter type

Convert all of the local initialization and shutdown functions to take a
parameter type of struct sony_sc* instead of using a mix of struct sony_sc* and
struct hid_device*.

Allows for the removal of some calls to hid_get_drvdata().

Signed-off-by: Frank Praznik <frank.praznik@oh.rr.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
This commit is contained in:
Frank Praznik 2014-04-14 10:11:33 -04:00 committed by Jiri Kosina
parent 55d3b664d4
commit fa57a8107b
1 changed files with 32 additions and 35 deletions

View File

@ -1096,19 +1096,18 @@ static void buzz_set_leds(struct hid_device *hdev, const __u8 *leds)
hid_hw_request(hdev, report, HID_REQ_SET_REPORT); hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
} }
static void sony_set_leds(struct hid_device *hdev, const __u8 *leds, int count) static void sony_set_leds(struct sony_sc *sc, const __u8 *leds, int count)
{ {
struct sony_sc *drv_data = hid_get_drvdata(hdev);
int n; int n;
BUG_ON(count > MAX_LEDS); BUG_ON(count > MAX_LEDS);
if (drv_data->quirks & BUZZ_CONTROLLER && count == 4) { if (sc->quirks & BUZZ_CONTROLLER && count == 4) {
buzz_set_leds(hdev, leds); buzz_set_leds(sc->hdev, leds);
} else { } else {
for (n = 0; n < count; n++) for (n = 0; n < count; n++)
drv_data->led_state[n] = leds[n]; sc->led_state[n] = leds[n];
schedule_work(&drv_data->state_worker); schedule_work(&sc->state_worker);
} }
} }
@ -1131,7 +1130,8 @@ static void sony_led_set_brightness(struct led_classdev *led,
if (led == drv_data->leds[n]) { if (led == drv_data->leds[n]) {
if (value != drv_data->led_state[n]) { if (value != drv_data->led_state[n]) {
drv_data->led_state[n] = value; drv_data->led_state[n] = value;
sony_set_leds(hdev, drv_data->led_state, drv_data->led_count); sony_set_leds(drv_data, drv_data->led_state,
drv_data->led_count);
} }
break; break;
} }
@ -1160,30 +1160,28 @@ static enum led_brightness sony_led_get_brightness(struct led_classdev *led)
return LED_OFF; return LED_OFF;
} }
static void sony_leds_remove(struct hid_device *hdev) static void sony_leds_remove(struct sony_sc *sc)
{ {
struct sony_sc *drv_data;
struct led_classdev *led; struct led_classdev *led;
int n; int n;
drv_data = hid_get_drvdata(hdev); BUG_ON(!(sc->quirks & SONY_LED_SUPPORT));
BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT));
for (n = 0; n < drv_data->led_count; n++) { for (n = 0; n < sc->led_count; n++) {
led = drv_data->leds[n]; led = sc->leds[n];
drv_data->leds[n] = NULL; sc->leds[n] = NULL;
if (!led) if (!led)
continue; continue;
led_classdev_unregister(led); led_classdev_unregister(led);
kfree(led); kfree(led);
} }
drv_data->led_count = 0; sc->led_count = 0;
} }
static int sony_leds_init(struct hid_device *hdev) static int sony_leds_init(struct sony_sc *sc)
{ {
struct sony_sc *drv_data; struct hid_device *hdev = sc->hdev;
int n, ret = 0; int n, ret = 0;
int max_brightness; int max_brightness;
int use_colors; int use_colors;
@ -1195,11 +1193,10 @@ static int sony_leds_init(struct hid_device *hdev)
static const char * const color_str[] = { "red", "green", "blue" }; 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); BUG_ON(!(sc->quirks & SONY_LED_SUPPORT));
BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT));
if (drv_data->quirks & BUZZ_CONTROLLER) { if (sc->quirks & BUZZ_CONTROLLER) {
drv_data->led_count = 4; sc->led_count = 4;
max_brightness = 1; max_brightness = 1;
use_colors = 0; use_colors = 0;
name_len = strlen("::buzz#"); name_len = strlen("::buzz#");
@ -1207,14 +1204,14 @@ static int sony_leds_init(struct hid_device *hdev)
/* 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 if (drv_data->quirks & DUALSHOCK4_CONTROLLER) { } else if (sc->quirks & DUALSHOCK4_CONTROLLER) {
drv_data->led_count = 3; sc->led_count = 3;
max_brightness = 255; max_brightness = 255;
use_colors = 1; use_colors = 1;
name_len = 0; name_len = 0;
name_fmt = "%s:%s"; name_fmt = "%s:%s";
} else { } else {
drv_data->led_count = 4; sc->led_count = 4;
max_brightness = 1; max_brightness = 1;
use_colors = 0; use_colors = 0;
name_len = strlen("::sony#"); name_len = strlen("::sony#");
@ -1226,11 +1223,11 @@ static int sony_leds_init(struct hid_device *hdev)
* 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
*/ */
sony_set_leds(hdev, initial_values, drv_data->led_count); sony_set_leds(sc, initial_values, sc->led_count);
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 < sc->led_count; n++) {
if (use_colors) if (use_colors)
name_sz = strlen(dev_name(&hdev->dev)) + strlen(color_str[n]) + 2; name_sz = strlen(dev_name(&hdev->dev)) + strlen(color_str[n]) + 2;
@ -1260,13 +1257,13 @@ static int sony_leds_init(struct hid_device *hdev)
goto error_leds; goto error_leds;
} }
drv_data->leds[n] = led; sc->leds[n] = led;
} }
return ret; return ret;
error_leds: error_leds:
sony_leds_remove(hdev); sony_leds_remove(sc);
return ret; return ret;
} }
@ -1355,9 +1352,9 @@ static int sony_play_effect(struct input_dev *dev, void *data,
return 0; return 0;
} }
static int sony_init_ff(struct hid_device *hdev) static int sony_init_ff(struct sony_sc *sc)
{ {
struct hid_input *hidinput = list_entry(hdev->inputs.next, struct hid_input *hidinput = list_entry(sc->hdev->inputs.next,
struct hid_input, list); struct hid_input, list);
struct input_dev *input_dev = hidinput->input; struct input_dev *input_dev = hidinput->input;
@ -1366,7 +1363,7 @@ static int sony_init_ff(struct hid_device *hdev)
} }
#else #else
static int sony_init_ff(struct hid_device *hdev) static int sony_init_ff(struct sony_sc *sc)
{ {
return 0; return 0;
} }
@ -1718,7 +1715,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
goto err_stop; goto err_stop;
if (sc->quirks & SONY_LED_SUPPORT) { if (sc->quirks & SONY_LED_SUPPORT) {
ret = sony_leds_init(hdev); ret = sony_leds_init(sc);
if (ret < 0) if (ret < 0)
goto err_stop; goto err_stop;
} }
@ -1737,7 +1734,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
} }
if (sc->quirks & SONY_FF_SUPPORT) { if (sc->quirks & SONY_FF_SUPPORT) {
ret = sony_init_ff(hdev); ret = sony_init_ff(sc);
if (ret < 0) if (ret < 0)
goto err_close; goto err_close;
} }
@ -1747,7 +1744,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
hid_hw_close(hdev); hid_hw_close(hdev);
err_stop: err_stop:
if (sc->quirks & SONY_LED_SUPPORT) if (sc->quirks & SONY_LED_SUPPORT)
sony_leds_remove(hdev); sony_leds_remove(sc);
if (sc->quirks & SONY_BATTERY_SUPPORT) if (sc->quirks & SONY_BATTERY_SUPPORT)
sony_battery_remove(sc); sony_battery_remove(sc);
sony_cancel_work_sync(sc); sony_cancel_work_sync(sc);
@ -1761,7 +1758,7 @@ static void sony_remove(struct hid_device *hdev)
struct sony_sc *sc = hid_get_drvdata(hdev); struct sony_sc *sc = hid_get_drvdata(hdev);
if (sc->quirks & SONY_LED_SUPPORT) if (sc->quirks & SONY_LED_SUPPORT)
sony_leds_remove(hdev); sony_leds_remove(sc);
if (sc->quirks & SONY_BATTERY_SUPPORT) { if (sc->quirks & SONY_BATTERY_SUPPORT) {
hid_hw_close(hdev); hid_hw_close(hdev);