aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPing Cheng <pinglinux@gmail.com>2015-04-24 18:32:51 -0400
committerJiri Kosina <jkosina@suse.cz>2015-04-27 05:08:12 -0400
commitc24eab4e0e449845ba98e649b0605ab0450193db (patch)
treee194a2d1fc3b57c8aa1338327f40cdab8f9840d6
parent007760cf082392b65a05c40eb615c5f8294b441a (diff)
HID: wacom: retrieve name from HID descriptor for generic devices
HID generic devices share the same default name, "Wacom HID". This causes userland programs to show same device names for different devices, which would confuse end users with same device names for different devices too. This patch uses name retrieved from HID descriptor, if a meaningful name is reported. Otherwise, affix its product ID to "Wacom HID". Names from descriptor may contain extra whitespaces. To comfort readers' eyes, we removed those extra whitespaces too. Signed-off-by: Ping Cheng <pingc@wacom.com> Reviewed-by: Jason Gerecke <killertofu@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/wacom_sys.c58
1 files changed, 47 insertions, 11 deletions
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index b3c6f111093b..9c57ac092f77 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -1402,6 +1402,52 @@ static size_t wacom_compute_pktlen(struct hid_device *hdev)
1402 return size; 1402 return size;
1403} 1403}
1404 1404
1405static void wacom_update_name(struct wacom *wacom)
1406{
1407 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1408 struct wacom_features *features = &wacom_wac->features;
1409
1410 /* Generic devices name unspecified */
1411 if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) {
1412 if (strstr(wacom->hdev->name, "Wacom") ||
1413 strstr(wacom->hdev->name, "wacom") ||
1414 strstr(wacom->hdev->name, "WACOM")) {
1415 /* name is in HID descriptor, use it */
1416 strlcpy(wacom_wac->name, wacom->hdev->name,
1417 sizeof(wacom_wac->name));
1418
1419 /* strip out excess whitespaces */
1420 while (1) {
1421 char *gap = strstr(wacom_wac->name, " ");
1422 if (gap == NULL)
1423 break;
1424 /* shift everything including the terminator */
1425 memmove(gap, gap+1, strlen(gap));
1426 }
1427 /* get rid of trailing whitespace */
1428 if (wacom_wac->name[strlen(wacom_wac->name)-1] == ' ')
1429 wacom_wac->name[strlen(wacom_wac->name)-1] = '\0';
1430 } else {
1431 /* no meaningful name retrieved. use product ID */
1432 snprintf(wacom_wac->name, sizeof(wacom_wac->name),
1433 "%s %X", features->name, wacom->hdev->product);
1434 }
1435 } else {
1436 strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));
1437 }
1438
1439 /* Append the device type to the name */
1440 snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
1441 "%s Pad", wacom_wac->name);
1442
1443 if (features->device_type != BTN_TOOL_FINGER)
1444 strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX);
1445 else if (features->touch_max)
1446 strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX);
1447 else
1448 strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX);
1449}
1450
1405static int wacom_probe(struct hid_device *hdev, 1451static int wacom_probe(struct hid_device *hdev,
1406 const struct hid_device_id *id) 1452 const struct hid_device_id *id)
1407{ 1453{
@@ -1484,17 +1530,7 @@ static int wacom_probe(struct hid_device *hdev,
1484 wacom_setup_device_quirks(wacom); 1530 wacom_setup_device_quirks(wacom);
1485 wacom_calculate_res(features); 1531 wacom_calculate_res(features);
1486 1532
1487 strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name)); 1533 wacom_update_name(wacom);
1488 snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
1489 "%s Pad", features->name);
1490
1491 /* Append the device type to the name */
1492 if (features->device_type != BTN_TOOL_FINGER)
1493 strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX);
1494 else if (features->touch_max)
1495 strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX);
1496 else
1497 strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX);
1498 1534
1499 error = wacom_add_shared_data(hdev); 1535 error = wacom_add_shared_data(hdev);
1500 if (error) 1536 if (error)