Skip to content

Commit

Permalink
xpadneo, core: 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 Apr 12, 2021
1 parent c141393 commit 5b3f80b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ docs/_site/**
docs/Gemfile.lock
hid-xpadneo/dkms.conf
hid-xpadneo/src/*.ko*
hid-xpadneo/src/*.mod*
hid-xpadneo/src/*.o*
hid-xpadneo/**/*.mod*
hid-xpadneo/**/*.o*
hid-xpadneo/src/*.symvers*

#FIXME(kakra) remove after source file split
Expand Down
2 changes: 2 additions & 0 deletions hid-xpadneo/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ obj-m += hid-xpadneo.o
hid-xpadneo-y += xpadneo.o
$(obj)/xpadneo.c: $(src)/hid-xpadneo.c
cp $< $@

hid-xpadneo-y += xpadneo/core.o
2 changes: 2 additions & 0 deletions hid-xpadneo/src/xpadneo.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,6 @@ struct xpadneo_devdata {
void *output_report_dmabuf;
};

extern int xpadneo_init_synthetic(struct xpadneo_devdata *, char *, struct input_dev **);

#endif
37 changes: 37 additions & 0 deletions hid-xpadneo/src/xpadneo/core.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* xpadneo driver core
*
* Copyright (c) 2021 Kai Krakow <[email protected]>
*/

#include "../xpadneo.h"

extern 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;
}

0 comments on commit 5b3f80b

Please sign in to comment.