Skip to content

Commit

Permalink
xpadneo, devices: Add support for synthetic devices
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kakra committed Mar 28, 2021
1 parent fa41a04 commit 5be5996
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions hid-xpadneo/src/hid-xpadneo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,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;
Expand Down

0 comments on commit 5be5996

Please sign in to comment.