diff --git a/.gitignore b/.gitignore index 8459306b..bd1f559e 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/hid-xpadneo/src/Makefile b/hid-xpadneo/src/Makefile index e999daaf..eb523f57 100644 --- a/hid-xpadneo/src/Makefile +++ b/hid-xpadneo/src/Makefile @@ -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 diff --git a/hid-xpadneo/src/xpadneo.h b/hid-xpadneo/src/xpadneo.h index a78383f9..20336d12 100644 --- a/hid-xpadneo/src/xpadneo.h +++ b/hid-xpadneo/src/xpadneo.h @@ -178,4 +178,6 @@ struct xpadneo_devdata { void *output_report_dmabuf; }; +extern int xpadneo_init_synthetic(struct xpadneo_devdata *, char *, struct input_dev **); + #endif diff --git a/hid-xpadneo/src/xpadneo/core.c b/hid-xpadneo/src/xpadneo/core.c new file mode 100644 index 00000000..580d72b6 --- /dev/null +++ b/hid-xpadneo/src/xpadneo/core.c @@ -0,0 +1,37 @@ +/* + * xpadneo driver core + * + * Copyright (c) 2021 Kai Krakow + */ + +#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; +}