Skip to content

Commit 2a6cdbd

Browse files
jigpuJiri Kosina
authored andcommitted
HID: wacom: Introduce new 'touch_input' device
Instead of having a single 'input_dev' device that will take either pen or touch data depending on the type of the device, create seperate devices devices for each. By splitting things like this, we can support devices (e.g. the I2C "AES" sensors in some newer tablet PCs) that send both pen and touch reports from a single endpoint. Signed-off-by: Jason Gerecke <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 2636a3f commit 2a6cdbd

File tree

3 files changed

+139
-101
lines changed

3 files changed

+139
-101
lines changed

drivers/hid/wacom_sys.c

Lines changed: 70 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static void wacom_post_parse_hid(struct hid_device *hdev,
253253
if (features->type == HID_GENERIC) {
254254
/* Any last-minute generic device setup */
255255
if (features->touch_max > 1) {
256-
input_mt_init_slots(wacom_wac->input, wacom_wac->features.touch_max,
256+
input_mt_init_slots(wacom_wac->touch_input, wacom_wac->features.touch_max,
257257
INPUT_MT_DIRECT);
258258
}
259259
}
@@ -1130,7 +1130,7 @@ static struct input_dev *wacom_allocate_input(struct wacom *wacom)
11301130
if (!input_dev)
11311131
return NULL;
11321132

1133-
input_dev->name = wacom_wac->name;
1133+
input_dev->name = wacom_wac->pen_name;
11341134
input_dev->phys = hdev->phys;
11351135
input_dev->dev.parent = &hdev->dev;
11361136
input_dev->open = wacom_open;
@@ -1149,27 +1149,33 @@ static void wacom_free_inputs(struct wacom *wacom)
11491149
{
11501150
struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
11511151

1152-
if (wacom_wac->input)
1153-
input_free_device(wacom_wac->input);
1152+
if (wacom_wac->pen_input)
1153+
input_free_device(wacom_wac->pen_input);
1154+
if (wacom_wac->touch_input)
1155+
input_free_device(wacom_wac->touch_input);
11541156
if (wacom_wac->pad_input)
11551157
input_free_device(wacom_wac->pad_input);
1156-
wacom_wac->input = NULL;
1158+
wacom_wac->pen_input = NULL;
1159+
wacom_wac->touch_input = NULL;
11571160
wacom_wac->pad_input = NULL;
11581161
}
11591162

11601163
static int wacom_allocate_inputs(struct wacom *wacom)
11611164
{
1162-
struct input_dev *input_dev, *pad_input_dev;
1165+
struct input_dev *pen_input_dev, *touch_input_dev, *pad_input_dev;
11631166
struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
11641167

1165-
input_dev = wacom_allocate_input(wacom);
1168+
pen_input_dev = wacom_allocate_input(wacom);
1169+
touch_input_dev = wacom_allocate_input(wacom);
11661170
pad_input_dev = wacom_allocate_input(wacom);
1167-
if (!input_dev || !pad_input_dev) {
1171+
if (!pen_input_dev || !touch_input_dev || !pad_input_dev) {
11681172
wacom_free_inputs(wacom);
11691173
return -ENOMEM;
11701174
}
11711175

1172-
wacom_wac->input = input_dev;
1176+
wacom_wac->pen_input = pen_input_dev;
1177+
wacom_wac->touch_input = touch_input_dev;
1178+
wacom_wac->touch_input->name = wacom_wac->touch_name;
11731179
wacom_wac->pad_input = pad_input_dev;
11741180
wacom_wac->pad_input->name = wacom_wac->pad_name;
11751181

@@ -1178,45 +1184,67 @@ static int wacom_allocate_inputs(struct wacom *wacom)
11781184

11791185
static void wacom_clean_inputs(struct wacom *wacom)
11801186
{
1181-
if (wacom->wacom_wac.input) {
1182-
if (wacom->wacom_wac.input_registered)
1183-
input_unregister_device(wacom->wacom_wac.input);
1187+
if (wacom->wacom_wac.pen_input) {
1188+
if (wacom->wacom_wac.pen_registered)
1189+
input_unregister_device(wacom->wacom_wac.pen_input);
11841190
else
1185-
input_free_device(wacom->wacom_wac.input);
1191+
input_free_device(wacom->wacom_wac.pen_input);
1192+
}
1193+
if (wacom->wacom_wac.touch_input) {
1194+
if (wacom->wacom_wac.touch_registered)
1195+
input_unregister_device(wacom->wacom_wac.touch_input);
1196+
else
1197+
input_free_device(wacom->wacom_wac.touch_input);
11861198
}
11871199
if (wacom->wacom_wac.pad_input) {
11881200
if (wacom->wacom_wac.pad_registered)
11891201
input_unregister_device(wacom->wacom_wac.pad_input);
11901202
else
11911203
input_free_device(wacom->wacom_wac.pad_input);
11921204
}
1193-
wacom->wacom_wac.input = NULL;
1205+
wacom->wacom_wac.pen_input = NULL;
1206+
wacom->wacom_wac.touch_input = NULL;
11941207
wacom->wacom_wac.pad_input = NULL;
11951208
wacom_destroy_leds(wacom);
11961209
}
11971210

11981211
static int wacom_register_inputs(struct wacom *wacom)
11991212
{
1200-
struct input_dev *input_dev, *pad_input_dev;
1213+
struct input_dev *pen_input_dev, *touch_input_dev, *pad_input_dev;
12011214
struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1202-
struct wacom_features *features = &wacom_wac->features;
12031215
int error = 0;
12041216

1205-
input_dev = wacom_wac->input;
1217+
pen_input_dev = wacom_wac->pen_input;
1218+
touch_input_dev = wacom_wac->touch_input;
12061219
pad_input_dev = wacom_wac->pad_input;
12071220

1208-
if (!input_dev || !pad_input_dev)
1221+
if (!pen_input_dev || !touch_input_dev || !pad_input_dev)
12091222
return -EINVAL;
12101223

1211-
if (features->device_type & WACOM_DEVICETYPE_PEN)
1212-
error = wacom_setup_pen_input_capabilities(input_dev, wacom_wac);
1213-
if (!error && features->device_type & WACOM_DEVICETYPE_TOUCH)
1214-
error = wacom_setup_touch_input_capabilities(input_dev, wacom_wac);
1215-
if (!error) {
1216-
error = input_register_device(input_dev);
1224+
error = wacom_setup_pen_input_capabilities(pen_input_dev, wacom_wac);
1225+
if (error) {
1226+
/* no pen in use on this interface */
1227+
input_free_device(pen_input_dev);
1228+
wacom_wac->pen_input = NULL;
1229+
pen_input_dev = NULL;
1230+
} else {
1231+
error = input_register_device(pen_input_dev);
1232+
if (error)
1233+
goto fail_register_pen_input;
1234+
wacom_wac->pen_registered = true;
1235+
}
1236+
1237+
error = wacom_setup_touch_input_capabilities(touch_input_dev, wacom_wac);
1238+
if (error) {
1239+
/* no touch in use on this interface */
1240+
input_free_device(touch_input_dev);
1241+
wacom_wac->touch_input = NULL;
1242+
touch_input_dev = NULL;
1243+
} else {
1244+
error = input_register_device(touch_input_dev);
12171245
if (error)
1218-
return error;
1219-
wacom_wac->input_registered = true;
1246+
goto fail_register_touch_input;
1247+
wacom_wac->touch_registered = true;
12201248
}
12211249

12221250
error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
@@ -1243,9 +1271,14 @@ static int wacom_register_inputs(struct wacom *wacom)
12431271
pad_input_dev = NULL;
12441272
wacom_wac->pad_registered = false;
12451273
fail_register_pad_input:
1246-
input_unregister_device(input_dev);
1247-
wacom_wac->input = NULL;
1248-
wacom_wac->input_registered = false;
1274+
input_unregister_device(touch_input_dev);
1275+
wacom_wac->touch_input = NULL;
1276+
wacom_wac->touch_registered = false;
1277+
fail_register_touch_input:
1278+
input_unregister_device(pen_input_dev);
1279+
wacom_wac->pen_input = NULL;
1280+
wacom_wac->pen_registered = false;
1281+
fail_register_pen_input:
12491282
return error;
12501283
}
12511284

@@ -1306,7 +1339,7 @@ static void wacom_wireless_work(struct work_struct *work)
13061339
if (wacom_wac1->features.type != INTUOSHT &&
13071340
wacom_wac1->features.type != BAMBOO_PT)
13081341
wacom_wac1->features.device_type |= WACOM_DEVICETYPE_PAD;
1309-
snprintf(wacom_wac1->name, WACOM_NAME_MAX, "%s (WL) Pen",
1342+
snprintf(wacom_wac1->pen_name, WACOM_NAME_MAX, "%s (WL) Pen",
13101343
wacom_wac1->features.name);
13111344
snprintf(wacom_wac1->pad_name, WACOM_NAME_MAX, "%s (WL) Pad",
13121345
wacom_wac1->features.name);
@@ -1325,7 +1358,7 @@ static void wacom_wireless_work(struct work_struct *work)
13251358
*((struct wacom_features *)id->driver_data);
13261359
wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
13271360
wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
1328-
snprintf(wacom_wac2->name, WACOM_NAME_MAX,
1361+
snprintf(wacom_wac2->touch_name, WACOM_NAME_MAX,
13291362
"%s (WL) Finger",wacom_wac2->features.name);
13301363
snprintf(wacom_wac2->pad_name, WACOM_NAME_MAX,
13311364
"%s (WL) Pad",wacom_wac2->features.name);
@@ -1342,7 +1375,7 @@ static void wacom_wireless_work(struct work_struct *work)
13421375

13431376
if (wacom_wac1->features.type == INTUOSHT &&
13441377
wacom_wac1->features.touch_max)
1345-
wacom_wac->shared->touch_input = wacom_wac2->input;
1378+
wacom_wac->shared->touch_input = wacom_wac2->touch_input;
13461379
}
13471380

13481381
error = wacom_initialize_battery(wacom);
@@ -1457,21 +1490,12 @@ static void wacom_update_name(struct wacom *wacom)
14571490
}
14581491

14591492
/* Append the device type to the name */
1493+
snprintf(wacom_wac->pen_name, sizeof(wacom_wac->pen_name),
1494+
"%s Pen", name);
1495+
snprintf(wacom_wac->touch_name, sizeof(wacom_wac->touch_name),
1496+
"%s Finger", name);
14601497
snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
14611498
"%s Pad", name);
1462-
1463-
if (features->device_type & WACOM_DEVICETYPE_PEN) {
1464-
snprintf(wacom_wac->name, sizeof(wacom_wac->name),
1465-
"%s Pen", name);
1466-
}
1467-
else if (features->device_type & WACOM_DEVICETYPE_TOUCH) {
1468-
snprintf(wacom_wac->name, sizeof(wacom_wac->name),
1469-
"%s Finger", name);
1470-
}
1471-
else if (features->device_type & WACOM_DEVICETYPE_PAD) {
1472-
snprintf(wacom_wac->name, sizeof(wacom_wac->name),
1473-
"%s Pad", name);
1474-
}
14751499
}
14761500

14771501
static int wacom_probe(struct hid_device *hdev,
@@ -1615,7 +1639,7 @@ static int wacom_probe(struct hid_device *hdev,
16151639

16161640
if (wacom_wac->features.type == INTUOSHT &&
16171641
wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) {
1618-
wacom_wac->shared->touch_input = wacom_wac->input;
1642+
wacom_wac->shared->touch_input = wacom_wac->touch_input;
16191643
}
16201644

16211645
return 0;

0 commit comments

Comments
 (0)