Skip to content

Commit 5be5996

Browse files
committed
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 <[email protected]>
1 parent fa41a04 commit 5be5996

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

hid-xpadneo/src/hid-xpadneo.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,36 @@ static int xpadneo_init_hw(struct hid_device *hdev)
11611161
return ret;
11621162
}
11631163

1164+
static int xpadneo_init_synthetic(struct xpadneo_devdata *xdata, char *suffix,
1165+
struct input_dev **devp)
1166+
{
1167+
struct hid_device *hdev = xdata->hdev;
1168+
struct input_dev *input_dev = devm_input_allocate_device(&hdev->dev);
1169+
size_t suffix_len, name_len;
1170+
1171+
if (!input_dev)
1172+
return -ENOMEM;
1173+
1174+
name_len = strlen(hdev->name);
1175+
suffix_len = strlen(suffix);
1176+
if ((name_len < suffix_len) || strcmp(xdata->hdev->name + name_len - suffix_len, suffix)) {
1177+
input_dev->name = kasprintf(GFP_KERNEL, "%s %s", hdev->name, suffix);
1178+
if (!input_dev->name)
1179+
return -ENOMEM;
1180+
}
1181+
1182+
dev_set_drvdata(&input_dev->dev, xdata);
1183+
input_dev->phys = hdev->phys;
1184+
input_dev->uniq = hdev->uniq;
1185+
input_dev->id.bustype = hdev->bus;
1186+
input_dev->id.vendor = hdev->vendor;
1187+
input_dev->id.product = hdev->product;
1188+
input_dev->id.version = hdev->version;
1189+
1190+
*devp = input_dev;
1191+
return 0;
1192+
}
1193+
11641194
static int xpadneo_probe(struct hid_device *hdev, const struct hid_device_id *id)
11651195
{
11661196
int ret;

0 commit comments

Comments
 (0)