From b7eeae7b0d3b1fc034b95ae3cc86c413b6b2efb2 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Sun, 28 Mar 2021 16:05:52 +0200 Subject: [PATCH] xpadneo, devices: Add support for synthetic devices In preparation for mouse mode and keyboard emulation, we need to be able to create virtual devices associated with the controller. Signed-off-by: Kai Krakow --- hid-xpadneo/src/hid-xpadneo.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/hid-xpadneo/src/hid-xpadneo.c b/hid-xpadneo/src/hid-xpadneo.c index 509768de..c933992f 100644 --- a/hid-xpadneo/src/hid-xpadneo.c +++ b/hid-xpadneo/src/hid-xpadneo.c @@ -1224,6 +1224,36 @@ static int xpadneo_init_hw(struct hid_device *hdev) return ret; } +static int xpadneo_init_synthetic(struct xpadneo_devdata *xdata, char *suffix, + struct input_dev **devp) +{ + struct hid_device *hdev = xdata->hdev; + struct input_dev *input_dev = devm_input_allocate_device(&hdev->dev); + size_t suffix_len, name_len; + + if (!input_dev) + return -ENOMEM; + + name_len = strlen(hdev->name); + suffix_len = strlen(suffix); + if ((name_len < suffix_len) || strcmp(xdata->hdev->name + name_len - suffix_len, suffix)) { + input_dev->name = kasprintf(GFP_KERNEL, "%s %s", hdev->name, suffix); + if (!input_dev->name) + return -ENOMEM; + } + + dev_set_drvdata(&input_dev->dev, xdata); + input_dev->phys = hdev->phys; + input_dev->uniq = hdev->uniq; + input_dev->id.bustype = hdev->bus; + input_dev->id.vendor = hdev->vendor; + input_dev->id.product = hdev->product; + input_dev->id.version = hdev->version; + + *devp = input_dev; + return 0; +} + static int xpadneo_probe(struct hid_device *hdev, const struct hid_device_id *id) { int ret;