Skip to content

Commit aa86b18

Browse files
jigpuJiri Kosina
authored andcommitted
HID: wacom: Treat features->device_type values as flags
The USB devices that this driver has historically supported segregate the pen and touch portions of the tablet. Oftentimes the segregation would be done at the interface level, though on occasion (e.g. Cintiq 24HDT) the tablet would combine two totally independent USB devices behind an internal USB hub. Because pen and touch never shared the same interface, it made sense for the 'device_type' to store a single value: "pen" or "touch". Recently, however, some I2C devices have been created which combine the two. A first step to accomodating this is to expand 'device_type' so that it can represent two (or potentially more) types simultaneously. To do this, we treat it as a bitfield and set/check individual bits rather than using the '=' and '==' operators. This should not result in any functional change since no supported devices (that I'm aware of, at least) have HID descriptors that indicate both pen and touch reports on a single interface. Signed-off-by: Jason Gerecke <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 44b5250 commit aa86b18

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

drivers/hid/wacom_sys.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ static void wacom_usage_mapping(struct hid_device *hdev,
197197
* values commonly reported.
198198
*/
199199
if (pen)
200-
features->device_type = BTN_TOOL_PEN;
200+
features->device_type |= WACOM_DEVICETYPE_PEN;
201201
else if (finger)
202-
features->device_type = BTN_TOOL_FINGER;
202+
features->device_type |= WACOM_DEVICETYPE_TOUCH;
203203
else
204204
return;
205205

@@ -411,7 +411,7 @@ static int wacom_query_tablet_data(struct hid_device *hdev,
411411
if (features->type == HID_GENERIC)
412412
return wacom_hid_set_device_mode(hdev);
413413

414-
if (features->device_type == BTN_TOOL_FINGER) {
414+
if (features->device_type & WACOM_DEVICETYPE_TOUCH) {
415415
if (features->type > TABLETPC) {
416416
/* MT Tablet PC touch */
417417
return wacom_set_device_mode(hdev, 3, 4, 4);
@@ -425,7 +425,7 @@ static int wacom_query_tablet_data(struct hid_device *hdev,
425425
else if (features->type == BAMBOO_PAD) {
426426
return wacom_set_device_mode(hdev, 2, 2, 2);
427427
}
428-
} else if (features->device_type == BTN_TOOL_PEN) {
428+
} else if (features->device_type & WACOM_DEVICETYPE_PEN) {
429429
if (features->type <= BAMBOO_PT && features->type != WIRELESS) {
430430
return wacom_set_device_mode(hdev, 2, 2, 2);
431431
}
@@ -454,9 +454,9 @@ static void wacom_retrieve_hid_descriptor(struct hid_device *hdev,
454454
*/
455455
if (features->type == WIRELESS) {
456456
if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
457-
features->device_type = 0;
457+
features->device_type = WACOM_DEVICETYPE_NONE;
458458
} else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) {
459-
features->device_type = BTN_TOOL_FINGER;
459+
features->device_type |= WACOM_DEVICETYPE_TOUCH;
460460
features->pktlen = WACOM_PKGLEN_BBTOUCH3;
461461
}
462462
}
@@ -538,9 +538,9 @@ static int wacom_add_shared_data(struct hid_device *hdev)
538538

539539
wacom_wac->shared = &data->shared;
540540

541-
if (wacom_wac->features.device_type == BTN_TOOL_FINGER)
541+
if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)
542542
wacom_wac->shared->touch = hdev;
543-
else if (wacom_wac->features.device_type == BTN_TOOL_PEN)
543+
else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN)
544544
wacom_wac->shared->pen = hdev;
545545

546546
out:
@@ -892,7 +892,7 @@ static int wacom_initialize_leds(struct wacom *wacom)
892892
case INTUOSPS:
893893
case INTUOSPM:
894894
case INTUOSPL:
895-
if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN) {
895+
if (wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PEN) {
896896
wacom->led.select[0] = 0;
897897
wacom->led.select[1] = 0;
898898
wacom->led.llv = 32;
@@ -948,7 +948,7 @@ static void wacom_destroy_leds(struct wacom *wacom)
948948
case INTUOSPS:
949949
case INTUOSPM:
950950
case INTUOSPL:
951-
if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN)
951+
if (wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PEN)
952952
sysfs_remove_group(&wacom->hdev->dev.kobj,
953953
&intuos5_led_attr_group);
954954
break;
@@ -1296,7 +1296,7 @@ static void wacom_wireless_work(struct work_struct *work)
12961296
/* Stylus interface */
12971297
wacom_wac1->features =
12981298
*((struct wacom_features *)id->driver_data);
1299-
wacom_wac1->features.device_type = BTN_TOOL_PEN;
1299+
wacom_wac1->features.device_type |= WACOM_DEVICETYPE_PEN;
13001300
snprintf(wacom_wac1->name, WACOM_NAME_MAX, "%s (WL) Pen",
13011301
wacom_wac1->features.name);
13021302
snprintf(wacom_wac1->pad_name, WACOM_NAME_MAX, "%s (WL) Pad",
@@ -1315,7 +1315,7 @@ static void wacom_wireless_work(struct work_struct *work)
13151315
wacom_wac2->features =
13161316
*((struct wacom_features *)id->driver_data);
13171317
wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
1318-
wacom_wac2->features.device_type = BTN_TOOL_FINGER;
1318+
wacom_wac2->features.device_type |= WACOM_DEVICETYPE_TOUCH;
13191319
wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
13201320
if (wacom_wac2->features.touch_max)
13211321
snprintf(wacom_wac2->name, WACOM_NAME_MAX,
@@ -1451,11 +1451,11 @@ static void wacom_update_name(struct wacom *wacom)
14511451
snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
14521452
"%s Pad", name);
14531453

1454-
if (features->device_type == BTN_TOOL_PEN) {
1454+
if (features->device_type & WACOM_DEVICETYPE_PEN) {
14551455
snprintf(wacom_wac->name, sizeof(wacom_wac->name),
14561456
"%s Pen", name);
14571457
}
1458-
else if (features->device_type == BTN_TOOL_FINGER) {
1458+
else if (features->device_type & WACOM_DEVICETYPE_TOUCH) {
14591459
if (features->touch_max)
14601460
snprintf(wacom_wac->name, sizeof(wacom_wac->name),
14611461
"%s Finger", name);
@@ -1545,7 +1545,8 @@ static int wacom_probe(struct hid_device *hdev,
15451545
wacom_retrieve_hid_descriptor(hdev, features);
15461546
wacom_setup_device_quirks(wacom);
15471547

1548-
if (!features->device_type && features->type != WIRELESS) {
1548+
if (features->device_type == WACOM_DEVICETYPE_NONE &&
1549+
features->type != WIRELESS) {
15491550
error = features->type == HID_GENERIC ? -ENODEV : 0;
15501551

15511552
dev_warn(&hdev->dev, "Unknown device_type for '%s'. %s.",
@@ -1555,7 +1556,7 @@ static int wacom_probe(struct hid_device *hdev,
15551556
if (error)
15561557
goto fail_shared_data;
15571558

1558-
features->device_type = BTN_TOOL_PEN;
1559+
features->device_type |= WACOM_DEVICETYPE_PEN;
15591560
}
15601561

15611562
wacom_calculate_res(features);
@@ -1604,7 +1605,7 @@ static int wacom_probe(struct hid_device *hdev,
16041605
error = hid_hw_open(hdev);
16051606

16061607
if (wacom_wac->features.type == INTUOSHT && wacom_wac->features.touch_max) {
1607-
if (wacom_wac->features.device_type == BTN_TOOL_FINGER)
1608+
if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)
16081609
wacom_wac->shared->touch_input = wacom_wac->input;
16091610
}
16101611

drivers/hid/wacom_wac.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ void wacom_setup_device_quirks(struct wacom *wacom)
21682168
struct wacom_features *features = &wacom->wacom_wac.features;
21692169

21702170
/* touch device found but size is not defined. use default */
2171-
if (features->device_type == BTN_TOOL_FINGER && !features->x_max) {
2171+
if (features->device_type & WACOM_DEVICETYPE_TOUCH && !features->x_max) {
21722172
features->x_max = 1023;
21732173
features->y_max = 1023;
21742174
}
@@ -2182,7 +2182,7 @@ void wacom_setup_device_quirks(struct wacom *wacom)
21822182
if ((features->type >= INTUOS5S && features->type <= INTUOSHT) ||
21832183
(features->type == BAMBOO_PT)) {
21842184
if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
2185-
features->device_type = BTN_TOOL_FINGER;
2185+
features->device_type |= WACOM_DEVICETYPE_TOUCH;
21862186

21872187
features->x_max = 4096;
21882188
features->y_max = 4096;
@@ -2197,7 +2197,7 @@ void wacom_setup_device_quirks(struct wacom *wacom)
21972197
* so rewrite this one to be of type BTN_TOOL_FINGER.
21982198
*/
21992199
if (features->type == BAMBOO_PAD)
2200-
features->device_type = BTN_TOOL_FINGER;
2200+
features->device_type |= WACOM_DEVICETYPE_TOUCH;
22012201

22022202
if (wacom->hdev->bus == BUS_BLUETOOTH)
22032203
features->quirks |= WACOM_QUIRK_BATTERY;
@@ -2218,7 +2218,7 @@ void wacom_setup_device_quirks(struct wacom *wacom)
22182218
features->quirks |= WACOM_QUIRK_NO_INPUT;
22192219

22202220
/* must be monitor interface if no device_type set */
2221-
if (!features->device_type) {
2221+
if (features->device_type == WACOM_DEVICETYPE_NONE) {
22222222
features->quirks |= WACOM_QUIRK_MONITOR;
22232223
features->quirks |= WACOM_QUIRK_BATTERY;
22242224
}
@@ -2230,7 +2230,7 @@ static void wacom_abs_set_axis(struct input_dev *input_dev,
22302230
{
22312231
struct wacom_features *features = &wacom_wac->features;
22322232

2233-
if (features->device_type == BTN_TOOL_PEN) {
2233+
if (features->device_type & WACOM_DEVICETYPE_PEN) {
22342234
input_set_abs_params(input_dev, ABS_X, features->x_min,
22352235
features->x_max, features->x_fuzz, 0);
22362236
input_set_abs_params(input_dev, ABS_Y, features->y_min,
@@ -2349,7 +2349,7 @@ int wacom_setup_pentouch_input_capabilities(struct input_dev *input_dev,
23492349
case INTUOSPS:
23502350
__set_bit(INPUT_PROP_POINTER, input_dev->propbit);
23512351

2352-
if (features->device_type == BTN_TOOL_PEN) {
2352+
if (features->device_type & WACOM_DEVICETYPE_PEN) {
23532353
input_set_abs_params(input_dev, ABS_DISTANCE, 0,
23542354
features->distance_max,
23552355
0, 0);
@@ -2358,7 +2358,7 @@ int wacom_setup_pentouch_input_capabilities(struct input_dev *input_dev,
23582358
input_abs_set_res(input_dev, ABS_Z, 287);
23592359

23602360
wacom_setup_intuos(wacom_wac);
2361-
} else if (features->device_type == BTN_TOOL_FINGER) {
2361+
} else if (features->device_type & WACOM_DEVICETYPE_TOUCH) {
23622362
__clear_bit(ABS_MISC, input_dev->absbit);
23632363

23642364
input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
@@ -2370,7 +2370,7 @@ int wacom_setup_pentouch_input_capabilities(struct input_dev *input_dev,
23702370
break;
23712371

23722372
case WACOM_24HDT:
2373-
if (features->device_type == BTN_TOOL_FINGER) {
2373+
if (features->device_type & WACOM_DEVICETYPE_TOUCH) {
23742374
input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
23752375
input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, features->x_max, 0, 0);
23762376
input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR, 0, features->y_max, 0, 0);
@@ -2383,7 +2383,7 @@ int wacom_setup_pentouch_input_capabilities(struct input_dev *input_dev,
23832383
case MTTPC:
23842384
case MTTPC_B:
23852385
case TABLETPC2FG:
2386-
if (features->device_type == BTN_TOOL_FINGER && features->touch_max > 1)
2386+
if (features->device_type & WACOM_DEVICETYPE_TOUCH && features->touch_max > 1)
23872387
input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_DIRECT);
23882388
/* fall through */
23892389

@@ -2393,7 +2393,7 @@ int wacom_setup_pentouch_input_capabilities(struct input_dev *input_dev,
23932393

23942394
__set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
23952395

2396-
if (features->device_type != BTN_TOOL_PEN)
2396+
if (!(features->device_type & WACOM_DEVICETYPE_PEN))
23972397
break; /* no need to process stylus stuff */
23982398

23992399
/* fall through */
@@ -2424,7 +2424,7 @@ int wacom_setup_pentouch_input_capabilities(struct input_dev *input_dev,
24242424

24252425
case INTUOSHT:
24262426
if (features->touch_max &&
2427-
features->device_type == BTN_TOOL_FINGER) {
2427+
features->device_type & WACOM_DEVICETYPE_TOUCH) {
24282428
input_dev->evbit[0] |= BIT_MASK(EV_SW);
24292429
__set_bit(SW_MUTE_DEVICE, input_dev->swbit);
24302430
}
@@ -2433,7 +2433,7 @@ int wacom_setup_pentouch_input_capabilities(struct input_dev *input_dev,
24332433
case BAMBOO_PT:
24342434
__clear_bit(ABS_MISC, input_dev->absbit);
24352435

2436-
if (features->device_type == BTN_TOOL_FINGER) {
2436+
if (features->device_type & WACOM_DEVICETYPE_TOUCH) {
24372437

24382438
if (features->touch_max) {
24392439
if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
@@ -2454,7 +2454,7 @@ int wacom_setup_pentouch_input_capabilities(struct input_dev *input_dev,
24542454
/* PAD is setup by wacom_setup_pad_input_capabilities later */
24552455
return 1;
24562456
}
2457-
} else if (features->device_type == BTN_TOOL_PEN) {
2457+
} else if (features->device_type & WACOM_DEVICETYPE_PEN) {
24582458
__set_bit(INPUT_PROP_POINTER, input_dev->propbit);
24592459
__set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
24602460
__set_bit(BTN_TOOL_PEN, input_dev->keybit);
@@ -2619,7 +2619,7 @@ int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
26192619
case INTUOS5S:
26202620
case INTUOSPS:
26212621
/* touch interface does not have the pad device */
2622-
if (features->device_type != BTN_TOOL_PEN)
2622+
if (!(features->device_type & WACOM_DEVICETYPE_PEN))
26232623
return -ENODEV;
26242624

26252625
for (i = 0; i < 7; i++)
@@ -2664,7 +2664,7 @@ int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
26642664
case INTUOSHT:
26652665
case BAMBOO_PT:
26662666
/* pad device is on the touch interface */
2667-
if ((features->device_type != BTN_TOOL_FINGER) ||
2667+
if (!(features->device_type & WACOM_DEVICETYPE_TOUCH) ||
26682668
/* Bamboo Pen only tablet does not have pad */
26692669
((features->type == BAMBOO_PT) && !features->touch_max))
26702670
return -ENODEV;

drivers/hid/wacom_wac.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
#define WACOM_QUIRK_MONITOR 0x0004
7373
#define WACOM_QUIRK_BATTERY 0x0008
7474

75+
/* device types */
76+
#define WACOM_DEVICETYPE_NONE 0x0000
77+
#define WACOM_DEVICETYPE_PEN 0x0001
78+
#define WACOM_DEVICETYPE_TOUCH 0x0002
79+
7580
#define WACOM_VENDORDEFINED_PEN 0xff0d0001
7681

7782
#define WACOM_PEN_FIELD(f) (((f)->logical == HID_DG_STYLUS) || \

0 commit comments

Comments
 (0)