Skip to content

Commit d8aaccd

Browse files
KontrabantJiri Kosina
authored andcommitted
HID: sony: Refactor the output report sending functions
Refactor the output report sending functions to allow for the sending of output reports without enqueuing a work item. Output reports for any device can now be sent via the send_output_report function pointer in the sony_sc struct which points to the appropriate output function. The individual state worker functions have been replaced with a universal sony_state_worker function which uses this function pointer. Signed-off-by: Frank Praznik <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 6f1da31 commit d8aaccd

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

drivers/hid/hid-sony.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ struct sony_sc {
10281028
struct led_classdev *leds[MAX_LEDS];
10291029
unsigned long quirks;
10301030
struct work_struct state_worker;
1031+
void(*send_output_report)(struct sony_sc*);
10311032
struct power_supply *battery;
10321033
struct power_supply_desc battery_desc;
10331034
int device_id;
@@ -1789,7 +1790,7 @@ static int sony_leds_init(struct sony_sc *sc)
17891790
return ret;
17901791
}
17911792

1792-
static void sixaxis_state_worker(struct work_struct *work)
1793+
static void sixaxis_send_output_report(struct sony_sc *sc)
17931794
{
17941795
static const union sixaxis_output_report_01 default_report = {
17951796
.buf = {
@@ -1803,7 +1804,6 @@ static void sixaxis_state_worker(struct work_struct *work)
18031804
0x00, 0x00, 0x00, 0x00, 0x00
18041805
}
18051806
};
1806-
struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
18071807
struct sixaxis_output_report *report =
18081808
(struct sixaxis_output_report *)sc->output_report_dmabuf;
18091809
int n;
@@ -1846,9 +1846,8 @@ static void sixaxis_state_worker(struct work_struct *work)
18461846
HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
18471847
}
18481848

1849-
static void dualshock4_state_worker(struct work_struct *work)
1849+
static void dualshock4_send_output_report(struct sony_sc *sc)
18501850
{
1851-
struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
18521851
struct hid_device *hdev = sc->hdev;
18531852
__u8 *buf = sc->output_report_dmabuf;
18541853
int offset;
@@ -1893,9 +1892,8 @@ static void dualshock4_state_worker(struct work_struct *work)
18931892
HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
18941893
}
18951894

1896-
static void motion_state_worker(struct work_struct *work)
1895+
static void motion_send_output_report(struct sony_sc *sc)
18971896
{
1898-
struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
18991897
struct hid_device *hdev = sc->hdev;
19001898
struct motion_output_report_02 *report =
19011899
(struct motion_output_report_02 *)sc->output_report_dmabuf;
@@ -1914,6 +1912,12 @@ static void motion_state_worker(struct work_struct *work)
19141912
hid_hw_output_report(hdev, (__u8 *)report, MOTION_REPORT_0x02_SIZE);
19151913
}
19161914

1915+
static void sony_state_worker(struct work_struct *work)
1916+
{
1917+
struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
1918+
sc->send_output_report(sc);
1919+
}
1920+
19171921
static int sony_allocate_output_report(struct sony_sc *sc)
19181922
{
19191923
if ((sc->quirks & SIXAXIS_CONTROLLER) ||
@@ -2241,11 +2245,13 @@ static void sony_release_device_id(struct sony_sc *sc)
22412245
}
22422246
}
22432247

2244-
static inline void sony_init_work(struct sony_sc *sc,
2245-
void (*worker)(struct work_struct *))
2248+
static inline void sony_init_output_report(struct sony_sc *sc,
2249+
void(*send_output_report)(struct sony_sc*))
22462250
{
2251+
sc->send_output_report = send_output_report;
2252+
22472253
if (!sc->worker_initialized)
2248-
INIT_WORK(&sc->state_worker, worker);
2254+
INIT_WORK(&sc->state_worker, sony_state_worker);
22492255

22502256
sc->worker_initialized = 1;
22512257
}
@@ -2319,7 +2325,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
23192325
hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
23202326
hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID;
23212327
ret = sixaxis_set_operational_usb(hdev);
2322-
sony_init_work(sc, sixaxis_state_worker);
2328+
sony_init_output_report(sc, sixaxis_send_output_report);
23232329
} else if ((sc->quirks & SIXAXIS_CONTROLLER_BT) ||
23242330
(sc->quirks & NAVIGATION_CONTROLLER_BT)) {
23252331
/*
@@ -2328,7 +2334,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
23282334
*/
23292335
hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
23302336
ret = sixaxis_set_operational_bt(hdev);
2331-
sony_init_work(sc, sixaxis_state_worker);
2337+
sony_init_output_report(sc, sixaxis_send_output_report);
23322338
} else if (sc->quirks & DUALSHOCK4_CONTROLLER) {
23332339
if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) {
23342340
/*
@@ -2343,9 +2349,9 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
23432349
}
23442350
}
23452351

2346-
sony_init_work(sc, dualshock4_state_worker);
2352+
sony_init_output_report(sc, dualshock4_send_output_report);
23472353
} else if (sc->quirks & MOTION_CONTROLLER) {
2348-
sony_init_work(sc, motion_state_worker);
2354+
sony_init_output_report(sc, motion_send_output_report);
23492355
} else {
23502356
ret = 0;
23512357
}

0 commit comments

Comments
 (0)