Skip to content

Commit fd5f92b

Browse files
bentissJiri Kosina
authored andcommitted
HID: wacom: reuse wacom_parse_and_register() in wireless_work
Removes duplicated code. The only difference is that we now need to stop and start the attached hid device, but this is a small cost. Signed-off-by: Benjamin Tissoires <[email protected]> Acked-by: Ping Cheng <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent a2f091a commit fd5f92b

File tree

1 file changed

+16
-45
lines changed

1 file changed

+16
-45
lines changed

drivers/hid/wacom_sys.c

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ static size_t wacom_compute_pktlen(struct hid_device *hdev)
15251525
return size;
15261526
}
15271527

1528-
static void wacom_update_name(struct wacom *wacom)
1528+
static void wacom_update_name(struct wacom *wacom, const char *suffix)
15291529
{
15301530
struct wacom_wac *wacom_wac = &wacom->wacom_wac;
15311531
struct wacom_features *features = &wacom_wac->features;
@@ -1561,14 +1561,14 @@ static void wacom_update_name(struct wacom *wacom)
15611561

15621562
/* Append the device type to the name */
15631563
snprintf(wacom_wac->pen_name, sizeof(wacom_wac->pen_name),
1564-
"%s Pen", name);
1564+
"%s%s Pen", name, suffix);
15651565
snprintf(wacom_wac->touch_name, sizeof(wacom_wac->touch_name),
1566-
"%s Finger", name);
1566+
"%s%s Finger", name, suffix);
15671567
snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
1568-
"%s Pad", name);
1568+
"%s%s Pad", name, suffix);
15691569
}
15701570

1571-
static int wacom_parse_and_register(struct wacom *wacom)
1571+
static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
15721572
{
15731573
struct wacom_wac *wacom_wac = &wacom->wacom_wac;
15741574
struct wacom_features *features = &wacom_wac->features;
@@ -1622,7 +1622,7 @@ static int wacom_parse_and_register(struct wacom *wacom)
16221622

16231623
wacom_calculate_res(features);
16241624

1625-
wacom_update_name(wacom);
1625+
wacom_update_name(wacom, wireless ? " (WL)" : "");
16261626

16271627
error = wacom_add_shared_data(hdev);
16281628
if (error)
@@ -1649,8 +1649,10 @@ static int wacom_parse_and_register(struct wacom *wacom)
16491649
goto fail_hw_start;
16501650
}
16511651

1652-
/* Note that if query fails it is not a hard failure */
1653-
wacom_query_tablet_data(hdev, features);
1652+
if (!wireless) {
1653+
/* Note that if query fails it is not a hard failure */
1654+
wacom_query_tablet_data(hdev, features);
1655+
}
16541656

16551657
/* touch only Bamboo doesn't support pen */
16561658
if ((features->type == BAMBOO_TOUCH) &&
@@ -1745,22 +1747,10 @@ static void wacom_wireless_work(struct work_struct *work)
17451747
/* Stylus interface */
17461748
wacom_wac1->features =
17471749
*((struct wacom_features *)id->driver_data);
1748-
wacom_wac1->features.device_type |= WACOM_DEVICETYPE_PEN;
1749-
wacom_set_default_phy(&wacom_wac1->features);
1750-
wacom_calculate_res(&wacom_wac1->features);
1751-
snprintf(wacom_wac1->pen_name, WACOM_NAME_MAX, "%s (WL) Pen",
1752-
wacom_wac1->features.name);
1753-
if (wacom_wac1->features.type < BAMBOO_PEN ||
1754-
wacom_wac1->features.type > BAMBOO_PT) {
1755-
snprintf(wacom_wac1->pad_name, WACOM_NAME_MAX,
1756-
"%s (WL) Pad", wacom_wac1->features.name);
1757-
wacom_wac1->features.device_type |= WACOM_DEVICETYPE_PAD;
1758-
}
1759-
wacom_wac1->shared->touch_max = wacom_wac1->features.touch_max;
1760-
wacom_wac1->shared->type = wacom_wac1->features.type;
1750+
17611751
wacom_wac1->pid = wacom_wac->pid;
1762-
error = wacom_allocate_inputs(wacom1) ||
1763-
wacom_register_inputs(wacom1);
1752+
hid_hw_stop(hdev1);
1753+
error = wacom_parse_and_register(wacom1, true);
17641754
if (error)
17651755
goto fail;
17661756

@@ -1770,30 +1760,11 @@ static void wacom_wireless_work(struct work_struct *work)
17701760
wacom_wac1->features.type <= BAMBOO_PT)) {
17711761
wacom_wac2->features =
17721762
*((struct wacom_features *)id->driver_data);
1773-
wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
1774-
wacom_set_default_phy(&wacom_wac2->features);
1775-
wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
1776-
wacom_calculate_res(&wacom_wac2->features);
1777-
snprintf(wacom_wac2->touch_name, WACOM_NAME_MAX,
1778-
"%s (WL) Finger", wacom_wac2->features.name);
1779-
if (wacom_wac1->features.touch_max)
1780-
wacom_wac2->features.device_type |= WACOM_DEVICETYPE_TOUCH;
1781-
if (wacom_wac1->features.type >= INTUOSHT &&
1782-
wacom_wac1->features.type <= BAMBOO_PT) {
1783-
snprintf(wacom_wac2->pad_name, WACOM_NAME_MAX,
1784-
"%s (WL) Pad", wacom_wac2->features.name);
1785-
wacom_wac2->features.device_type |= WACOM_DEVICETYPE_PAD;
1786-
}
17871763
wacom_wac2->pid = wacom_wac->pid;
1788-
error = wacom_allocate_inputs(wacom2) ||
1789-
wacom_register_inputs(wacom2);
1764+
hid_hw_stop(hdev2);
1765+
error = wacom_parse_and_register(wacom2, true);
17901766
if (error)
17911767
goto fail;
1792-
1793-
if ((wacom_wac1->features.type == INTUOSHT ||
1794-
wacom_wac1->features.type == INTUOSHT2) &&
1795-
wacom_wac1->features.touch_max)
1796-
wacom_wac->shared->touch_input = wacom_wac2->touch_input;
17971768
}
17981769

17991770
error = wacom_initialize_battery(wacom);
@@ -1855,7 +1826,7 @@ static int wacom_probe(struct hid_device *hdev,
18551826
goto fail_parse;
18561827
}
18571828

1858-
error = wacom_parse_and_register(wacom);
1829+
error = wacom_parse_and_register(wacom, false);
18591830
if (error)
18601831
goto fail_parse;
18611832

0 commit comments

Comments
 (0)