hid-steam.c (cd11d1a6114bd4bc6450ae59f6e110ec47362126) hid-steam.c (eeeec27d68204701cc5d49d79f7ba811e8438109)
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * HID driver for Valve Steam Controller
4 *
5 * Copyright (c) 2018 Rodrigo Rivas Costa <rodrigorivascosta@gmail.com>
6 *
7 * Supports both the wired and wireless interfaces.
8 *

--- 120 unchanged lines hidden (view full) ---

129static int steam_recv_report(struct steam_device *steam,
130 u8 *data, int size)
131{
132 struct hid_report *r;
133 u8 *buf;
134 int ret;
135
136 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * HID driver for Valve Steam Controller
4 *
5 * Copyright (c) 2018 Rodrigo Rivas Costa <rodrigorivascosta@gmail.com>
6 *
7 * Supports both the wired and wireless interfaces.
8 *

--- 120 unchanged lines hidden (view full) ---

129static int steam_recv_report(struct steam_device *steam,
130 u8 *data, int size)
131{
132 struct hid_report *r;
133 u8 *buf;
134 int ret;
135
136 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
137 if (!r) {
138 hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n");
139 return -EINVAL;
140 }
141
142 if (hid_report_len(r) < 64)
143 return -EINVAL;
144
145 buf = hid_alloc_report_buf(r, GFP_KERNEL);
146 if (!buf)
147 return -ENOMEM;
148
149 /*

--- 15 unchanged lines hidden (view full) ---

165 u8 *cmd, int size)
166{
167 struct hid_report *r;
168 u8 *buf;
169 unsigned int retries = 50;
170 int ret;
171
172 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
137 if (hid_report_len(r) < 64)
138 return -EINVAL;
139
140 buf = hid_alloc_report_buf(r, GFP_KERNEL);
141 if (!buf)
142 return -ENOMEM;
143
144 /*

--- 15 unchanged lines hidden (view full) ---

160 u8 *cmd, int size)
161{
162 struct hid_report *r;
163 u8 *buf;
164 unsigned int retries = 50;
165 int ret;
166
167 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
173 if (!r) {
174 hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n");
175 return -EINVAL;
176 }
177
178 if (hid_report_len(r) < 64)
179 return -EINVAL;
180
181 buf = hid_alloc_report_buf(r, GFP_KERNEL);
182 if (!buf)
183 return -ENOMEM;
184
185 /* The report ID is always 0 */

--- 65 unchanged lines hidden (view full) ---

251 if (ret < 0)
252 return ret;
253 ret = steam_recv_report(steam, reply, sizeof(reply));
254 if (ret < 0)
255 return ret;
256 if (reply[0] != 0xae || reply[1] != 0x15 || reply[2] != 0x01)
257 return -EIO;
258 reply[3 + STEAM_SERIAL_LEN] = 0;
168 if (hid_report_len(r) < 64)
169 return -EINVAL;
170
171 buf = hid_alloc_report_buf(r, GFP_KERNEL);
172 if (!buf)
173 return -ENOMEM;
174
175 /* The report ID is always 0 */

--- 65 unchanged lines hidden (view full) ---

241 if (ret < 0)
242 return ret;
243 ret = steam_recv_report(steam, reply, sizeof(reply));
244 if (ret < 0)
245 return ret;
246 if (reply[0] != 0xae || reply[1] != 0x15 || reply[2] != 0x01)
247 return -EIO;
248 reply[3 + STEAM_SERIAL_LEN] = 0;
259 strlcpy(steam->serial_no, reply + 3, sizeof(steam->serial_no));
249 strscpy(steam->serial_no, reply + 3, sizeof(steam->serial_no));
260 return 0;
261}
262
263/*
264 * This command requests the wireless adaptor to post an event
265 * with the connection status. Useful if this driver is loaded when
266 * the controller is already connected.
267 */

--- 251 unchanged lines hidden (view full) ---

519 */
520 if (!steam->serial_no[0]) {
521 /*
522 * Unlikely, but getting the serial could fail, and it is not so
523 * important, so make up a serial number and go on.
524 */
525 mutex_lock(&steam->mutex);
526 if (steam_get_serial(steam) < 0)
250 return 0;
251}
252
253/*
254 * This command requests the wireless adaptor to post an event
255 * with the connection status. Useful if this driver is loaded when
256 * the controller is already connected.
257 */

--- 251 unchanged lines hidden (view full) ---

509 */
510 if (!steam->serial_no[0]) {
511 /*
512 * Unlikely, but getting the serial could fail, and it is not so
513 * important, so make up a serial number and go on.
514 */
515 mutex_lock(&steam->mutex);
516 if (steam_get_serial(steam) < 0)
527 strlcpy(steam->serial_no, "XXXXXXXXXX",
517 strscpy(steam->serial_no, "XXXXXXXXXX",
528 sizeof(steam->serial_no));
529 mutex_unlock(&steam->mutex);
530
531 hid_info(steam->hdev, "Steam Controller '%s' connected",
532 steam->serial_no);
533
534 /* ignore battery errors, we can live without it */
535 if (steam->quirks & STEAM_QUIRK_WIRELESS)

--- 158 unchanged lines hidden (view full) ---

694 client_hdev->ll_driver = &steam_client_ll_driver;
695 client_hdev->dev.parent = hdev->dev.parent;
696 client_hdev->bus = hdev->bus;
697 client_hdev->vendor = hdev->vendor;
698 client_hdev->product = hdev->product;
699 client_hdev->version = hdev->version;
700 client_hdev->type = hdev->type;
701 client_hdev->country = hdev->country;
518 sizeof(steam->serial_no));
519 mutex_unlock(&steam->mutex);
520
521 hid_info(steam->hdev, "Steam Controller '%s' connected",
522 steam->serial_no);
523
524 /* ignore battery errors, we can live without it */
525 if (steam->quirks & STEAM_QUIRK_WIRELESS)

--- 158 unchanged lines hidden (view full) ---

684 client_hdev->ll_driver = &steam_client_ll_driver;
685 client_hdev->dev.parent = hdev->dev.parent;
686 client_hdev->bus = hdev->bus;
687 client_hdev->vendor = hdev->vendor;
688 client_hdev->product = hdev->product;
689 client_hdev->version = hdev->version;
690 client_hdev->type = hdev->type;
691 client_hdev->country = hdev->country;
702 strlcpy(client_hdev->name, hdev->name,
692 strscpy(client_hdev->name, hdev->name,
703 sizeof(client_hdev->name));
693 sizeof(client_hdev->name));
704 strlcpy(client_hdev->phys, hdev->phys,
694 strscpy(client_hdev->phys, hdev->phys,
705 sizeof(client_hdev->phys));
706 /*
707 * Since we use the same device info than the real interface to
708 * trick userspace, we will be calling steam_probe recursively.
709 * We need to recognize the client interface somehow.
710 */
711 client_hdev->group = HID_GROUP_STEAM;
712 return client_hdev;

--- 445 unchanged lines hidden ---
695 sizeof(client_hdev->phys));
696 /*
697 * Since we use the same device info than the real interface to
698 * trick userspace, we will be calling steam_probe recursively.
699 * We need to recognize the client interface somehow.
700 */
701 client_hdev->group = HID_GROUP_STEAM;
702 return client_hdev;

--- 445 unchanged lines hidden ---