1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * HID driver for PhoenixRC 8-axis flight controller
5 * Copyright (C) 2022 Marcus Folkesson <marcus.folkesson@gmail.com>
8 #include <linux/device.h>
10 #include <linux/module.h>
20 static __u8 pxrc_rdesc_fixed[] = {
21 0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
22 0x09, 0x04, // Usage (Joystick)
23 0xA1, 0x01, // Collection (Application)
24 0x09, 0x01, // Usage (Pointer)
25 0xA1, 0x00, // Collection (Physical)
26 0x09, 0x30, // Usage (X)
27 0x09, 0x36, // Usage (Slider)
28 0x09, 0x31, // Usage (Y)
29 0x09, 0x32, // Usage (Z)
30 0x09, 0x33, // Usage (Rx)
31 0x09, 0x34, // Usage (Ry)
32 0x09, 0x35, // Usage (Rz)
33 0x09, 0x37, // Usage (Dial)
34 0x15, 0x00, // Logical Minimum (0)
35 0x26, 0xFF, 0x00, // Logical Maximum (255)
36 0x35, 0x00, // Physical Minimum (0)
37 0x46, 0xFF, 0x00, // Physical Maximum (255)
38 0x75, 0x08, // Report Size (8)
39 0x95, 0x08, // Report Count (8)
40 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
41 0xC0, // End Collection
42 0xC0, // End Collection
45 static __u8 *pxrc_report_fixup(struct hid_device *hdev, __u8 *rdesc,
48 hid_info(hdev, "fixing up PXRC report descriptor\n");
49 *rsize = sizeof(pxrc_rdesc_fixed);
50 return pxrc_rdesc_fixed;
53 static int pxrc_raw_event(struct hid_device *hdev, struct hid_report *report,
56 struct pxrc_priv *priv = hid_get_drvdata(hdev);
59 priv->slider = data[7];
63 data[1] = priv->slider;
66 priv->alternate = !priv->alternate;
70 static int pxrc_probe(struct hid_device *hdev, const struct hid_device_id *id)
73 struct pxrc_priv *priv;
75 priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL);
78 hid_set_drvdata(hdev, priv);
80 ret = hid_parse(hdev);
82 hid_err(hdev, "parse failed\n");
86 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
88 hid_err(hdev, "hw start failed\n");
95 static const struct hid_device_id pxrc_devices[] = {
96 { HID_USB_DEVICE(USB_VENDOR_ID_MULTIPLE_1781, USB_DEVICE_ID_PHOENIXRC) },
99 MODULE_DEVICE_TABLE(hid, pxrc_devices);
101 static struct hid_driver pxrc_driver = {
103 .id_table = pxrc_devices,
104 .report_fixup = pxrc_report_fixup,
106 .raw_event = pxrc_raw_event,
108 module_hid_driver(pxrc_driver);
110 MODULE_AUTHOR("Marcus Folkesson <marcus.folkesson@gmail.com>");
111 MODULE_DESCRIPTION("HID driver for PXRC 8-axis flight controller");
112 MODULE_LICENSE("GPL");