Commit 2546dacd authored by Benjamin Tissoires's avatar Benjamin Tissoires Committed by Jiri Kosina

HID: wacom: split out input allocation and registration

If the input can be created earlier during probe, we can already populate
them while reading the report descriptor. This way, we can rely on the
hid subsystem directly for tablets which already provide a meaningful
report descriptor (like ISDv4-5).

This patch only splits the allocation and registration, but do not
change where we allocate the input. This will come in a later patch.
Signed-off-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Acked-by: default avatarJason Gerecke <killertofu@gmail.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 7fefeec5
...@@ -1054,41 +1054,75 @@ static struct input_dev *wacom_allocate_input(struct wacom *wacom) ...@@ -1054,41 +1054,75 @@ static struct input_dev *wacom_allocate_input(struct wacom *wacom)
return input_dev; return input_dev;
} }
static void wacom_unregister_inputs(struct wacom *wacom) static void wacom_free_inputs(struct wacom *wacom)
{ {
if (wacom->wacom_wac.input) struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
input_unregister_device(wacom->wacom_wac.input);
if (wacom->wacom_wac.pad_input) if (wacom_wac->input)
input_unregister_device(wacom->wacom_wac.pad_input); input_free_device(wacom_wac->input);
wacom->wacom_wac.input = NULL; if (wacom_wac->pad_input)
wacom->wacom_wac.pad_input = NULL; input_free_device(wacom_wac->pad_input);
wacom_destroy_leds(wacom); wacom_wac->input = NULL;
wacom_wac->pad_input = NULL;
} }
static int wacom_register_inputs(struct wacom *wacom) static int wacom_allocate_inputs(struct wacom *wacom)
{ {
struct input_dev *input_dev, *pad_input_dev; struct input_dev *input_dev, *pad_input_dev;
struct wacom_wac *wacom_wac = &(wacom->wacom_wac); struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
int error;
input_dev = wacom_allocate_input(wacom); input_dev = wacom_allocate_input(wacom);
pad_input_dev = wacom_allocate_input(wacom); pad_input_dev = wacom_allocate_input(wacom);
if (!input_dev || !pad_input_dev) { if (!input_dev || !pad_input_dev) {
error = -ENOMEM; wacom_free_inputs(wacom);
goto fail_allocate_input; return -ENOMEM;
} }
wacom_wac->input = input_dev; wacom_wac->input = input_dev;
wacom_wac->pad_input = pad_input_dev; wacom_wac->pad_input = pad_input_dev;
wacom_wac->pad_input->name = wacom_wac->pad_name; wacom_wac->pad_input->name = wacom_wac->pad_name;
return 0;
}
static void wacom_clean_inputs(struct wacom *wacom)
{
if (wacom->wacom_wac.input) {
if (wacom->wacom_wac.input_registered)
input_unregister_device(wacom->wacom_wac.input);
else
input_free_device(wacom->wacom_wac.input);
}
if (wacom->wacom_wac.pad_input) {
if (wacom->wacom_wac.input_registered)
input_unregister_device(wacom->wacom_wac.pad_input);
else
input_free_device(wacom->wacom_wac.pad_input);
}
wacom->wacom_wac.input = NULL;
wacom->wacom_wac.pad_input = NULL;
wacom_destroy_leds(wacom);
}
static int wacom_register_inputs(struct wacom *wacom)
{
struct input_dev *input_dev, *pad_input_dev;
struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
int error;
input_dev = wacom_wac->input;
pad_input_dev = wacom_wac->pad_input;
if (!input_dev || !pad_input_dev)
return -EINVAL;
error = wacom_setup_input_capabilities(input_dev, wacom_wac); error = wacom_setup_input_capabilities(input_dev, wacom_wac);
if (error) if (error)
goto fail_input_cap; return error;
error = input_register_device(input_dev); error = input_register_device(input_dev);
if (error) if (error)
goto fail_register_input; return error;
error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac); error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
if (error) { if (error) {
...@@ -1106,6 +1140,8 @@ static int wacom_register_inputs(struct wacom *wacom) ...@@ -1106,6 +1140,8 @@ static int wacom_register_inputs(struct wacom *wacom)
goto fail_leds; goto fail_leds;
} }
wacom_wac->input_registered = true;
return 0; return 0;
fail_leds: fail_leds:
...@@ -1113,16 +1149,7 @@ static int wacom_register_inputs(struct wacom *wacom) ...@@ -1113,16 +1149,7 @@ static int wacom_register_inputs(struct wacom *wacom)
pad_input_dev = NULL; pad_input_dev = NULL;
fail_register_pad_input: fail_register_pad_input:
input_unregister_device(input_dev); input_unregister_device(input_dev);
input_dev = NULL;
fail_register_input:
fail_input_cap:
wacom_wac->input = NULL; wacom_wac->input = NULL;
wacom_wac->pad_input = NULL;
fail_allocate_input:
if (input_dev)
input_free_device(input_dev);
if (pad_input_dev)
input_free_device(pad_input_dev);
return error; return error;
} }
...@@ -1147,13 +1174,13 @@ static void wacom_wireless_work(struct work_struct *work) ...@@ -1147,13 +1174,13 @@ static void wacom_wireless_work(struct work_struct *work)
hdev1 = usb_get_intfdata(usbdev->config->interface[1]); hdev1 = usb_get_intfdata(usbdev->config->interface[1]);
wacom1 = hid_get_drvdata(hdev1); wacom1 = hid_get_drvdata(hdev1);
wacom_wac1 = &(wacom1->wacom_wac); wacom_wac1 = &(wacom1->wacom_wac);
wacom_unregister_inputs(wacom1); wacom_clean_inputs(wacom1);
/* Touch interface */ /* Touch interface */
hdev2 = usb_get_intfdata(usbdev->config->interface[2]); hdev2 = usb_get_intfdata(usbdev->config->interface[2]);
wacom2 = hid_get_drvdata(hdev2); wacom2 = hid_get_drvdata(hdev2);
wacom_wac2 = &(wacom2->wacom_wac); wacom_wac2 = &(wacom2->wacom_wac);
wacom_unregister_inputs(wacom2); wacom_clean_inputs(wacom2);
if (wacom_wac->pid == 0) { if (wacom_wac->pid == 0) {
hid_info(wacom->hdev, "wireless tablet disconnected\n"); hid_info(wacom->hdev, "wireless tablet disconnected\n");
...@@ -1187,7 +1214,8 @@ static void wacom_wireless_work(struct work_struct *work) ...@@ -1187,7 +1214,8 @@ static void wacom_wireless_work(struct work_struct *work)
wacom_wac1->shared->touch_max = wacom_wac1->features.touch_max; wacom_wac1->shared->touch_max = wacom_wac1->features.touch_max;
wacom_wac1->shared->type = wacom_wac1->features.type; wacom_wac1->shared->type = wacom_wac1->features.type;
wacom_wac1->pid = wacom_wac->pid; wacom_wac1->pid = wacom_wac->pid;
error = wacom_register_inputs(wacom1); error = wacom_allocate_inputs(wacom1) ||
wacom_register_inputs(wacom1);
if (error) if (error)
goto fail; goto fail;
...@@ -1208,7 +1236,8 @@ static void wacom_wireless_work(struct work_struct *work) ...@@ -1208,7 +1236,8 @@ static void wacom_wireless_work(struct work_struct *work)
snprintf(wacom_wac2->pad_name, WACOM_NAME_MAX, snprintf(wacom_wac2->pad_name, WACOM_NAME_MAX,
"%s (WL) Pad", wacom_wac2->features.name); "%s (WL) Pad", wacom_wac2->features.name);
wacom_wac2->pid = wacom_wac->pid; wacom_wac2->pid = wacom_wac->pid;
error = wacom_register_inputs(wacom2); error = wacom_allocate_inputs(wacom2) ||
wacom_register_inputs(wacom2);
if (error) if (error)
goto fail; goto fail;
...@@ -1225,8 +1254,8 @@ static void wacom_wireless_work(struct work_struct *work) ...@@ -1225,8 +1254,8 @@ static void wacom_wireless_work(struct work_struct *work)
return; return;
fail: fail:
wacom_unregister_inputs(wacom1); wacom_clean_inputs(wacom1);
wacom_unregister_inputs(wacom2); wacom_clean_inputs(wacom2);
return; return;
} }
...@@ -1400,7 +1429,8 @@ static int wacom_probe(struct hid_device *hdev, ...@@ -1400,7 +1429,8 @@ static int wacom_probe(struct hid_device *hdev,
} }
if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) { if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) {
error = wacom_register_inputs(wacom); error = wacom_allocate_inputs(wacom) ||
wacom_register_inputs(wacom);
if (error) if (error)
goto fail_register_inputs; goto fail_register_inputs;
} }
...@@ -1434,11 +1464,11 @@ static int wacom_probe(struct hid_device *hdev, ...@@ -1434,11 +1464,11 @@ static int wacom_probe(struct hid_device *hdev,
return 0; return 0;
fail_hw_start: fail_hw_start:
wacom_unregister_inputs(wacom); wacom_clean_inputs(wacom);
if (hdev->bus == BUS_BLUETOOTH) if (hdev->bus == BUS_BLUETOOTH)
device_remove_file(&hdev->dev, &dev_attr_speed); device_remove_file(&hdev->dev, &dev_attr_speed);
fail_register_inputs: fail_register_inputs:
wacom_unregister_inputs(wacom); wacom_clean_inputs(wacom);
wacom_destroy_battery(wacom); wacom_destroy_battery(wacom);
fail_battery: fail_battery:
wacom_remove_shared_data(wacom_wac); wacom_remove_shared_data(wacom_wac);
...@@ -1458,7 +1488,7 @@ static void wacom_remove(struct hid_device *hdev) ...@@ -1458,7 +1488,7 @@ static void wacom_remove(struct hid_device *hdev)
hid_hw_stop(hdev); hid_hw_stop(hdev);
cancel_work_sync(&wacom->work); cancel_work_sync(&wacom->work);
wacom_unregister_inputs(wacom); wacom_clean_inputs(wacom);
if (hdev->bus == BUS_BLUETOOTH) if (hdev->bus == BUS_BLUETOOTH)
device_remove_file(&hdev->dev, &dev_attr_speed); device_remove_file(&hdev->dev, &dev_attr_speed);
wacom_destroy_battery(wacom); wacom_destroy_battery(wacom);
......
...@@ -167,6 +167,7 @@ struct wacom_wac { ...@@ -167,6 +167,7 @@ struct wacom_wac {
struct wacom_shared *shared; struct wacom_shared *shared;
struct input_dev *input; struct input_dev *input;
struct input_dev *pad_input; struct input_dev *pad_input;
bool input_registered;
int pid; int pid;
int battery_capacity; int battery_capacity;
int num_contacts_left; int num_contacts_left;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment