aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>2014-09-23 12:08:06 -0400
committerJiri Kosina <jkosina@suse.cz>2014-10-01 03:11:22 -0400
commit2546dacd3e0e48c40bbb99caf01455f1ade9bb24 (patch)
tree6c62cd095516c8a28fb8aace135bb5bd019f2606
parent7fefeec5176861c2747b8dcd9656acf42c288ded (diff)
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: Benjamin Tissoires <benjamin.tissoires@redhat.com> Acked-by: Jason Gerecke <killertofu@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/wacom_sys.c96
-rw-r--r--drivers/hid/wacom_wac.h1
2 files changed, 64 insertions, 33 deletions
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 97e1feffc6e4..62f3c899ab98 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -1054,41 +1054,75 @@ static struct input_dev *wacom_allocate_input(struct wacom *wacom)
1054 return input_dev; 1054 return input_dev;
1055} 1055}
1056 1056
1057static void wacom_unregister_inputs(struct wacom *wacom) 1057static void wacom_free_inputs(struct wacom *wacom)
1058{ 1058{
1059 if (wacom->wacom_wac.input) 1059 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1060 input_unregister_device(wacom->wacom_wac.input); 1060
1061 if (wacom->wacom_wac.pad_input) 1061 if (wacom_wac->input)
1062 input_unregister_device(wacom->wacom_wac.pad_input); 1062 input_free_device(wacom_wac->input);
1063 wacom->wacom_wac.input = NULL; 1063 if (wacom_wac->pad_input)
1064 wacom->wacom_wac.pad_input = NULL; 1064 input_free_device(wacom_wac->pad_input);
1065 wacom_destroy_leds(wacom); 1065 wacom_wac->input = NULL;
1066 wacom_wac->pad_input = NULL;
1066} 1067}
1067 1068
1068static int wacom_register_inputs(struct wacom *wacom) 1069static int wacom_allocate_inputs(struct wacom *wacom)
1069{ 1070{
1070 struct input_dev *input_dev, *pad_input_dev; 1071 struct input_dev *input_dev, *pad_input_dev;
1071 struct wacom_wac *wacom_wac = &(wacom->wacom_wac); 1072 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1072 int error;
1073 1073
1074 input_dev = wacom_allocate_input(wacom); 1074 input_dev = wacom_allocate_input(wacom);
1075 pad_input_dev = wacom_allocate_input(wacom); 1075 pad_input_dev = wacom_allocate_input(wacom);
1076 if (!input_dev || !pad_input_dev) { 1076 if (!input_dev || !pad_input_dev) {
1077 error = -ENOMEM; 1077 wacom_free_inputs(wacom);
1078 goto fail_allocate_input; 1078 return -ENOMEM;
1079 } 1079 }
1080 1080
1081 wacom_wac->input = input_dev; 1081 wacom_wac->input = input_dev;
1082 wacom_wac->pad_input = pad_input_dev; 1082 wacom_wac->pad_input = pad_input_dev;
1083 wacom_wac->pad_input->name = wacom_wac->pad_name; 1083 wacom_wac->pad_input->name = wacom_wac->pad_name;
1084 1084
1085 return 0;
1086}
1087
1088static void wacom_clean_inputs(struct wacom *wacom)
1089{
1090 if (wacom->wacom_wac.input) {
1091 if (wacom->wacom_wac.input_registered)
1092 input_unregister_device(wacom->wacom_wac.input);
1093 else
1094 input_free_device(wacom->wacom_wac.input);
1095 }
1096 if (wacom->wacom_wac.pad_input) {
1097 if (wacom->wacom_wac.input_registered)
1098 input_unregister_device(wacom->wacom_wac.pad_input);
1099 else
1100 input_free_device(wacom->wacom_wac.pad_input);
1101 }
1102 wacom->wacom_wac.input = NULL;
1103 wacom->wacom_wac.pad_input = NULL;
1104 wacom_destroy_leds(wacom);
1105}
1106
1107static int wacom_register_inputs(struct wacom *wacom)
1108{
1109 struct input_dev *input_dev, *pad_input_dev;
1110 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1111 int error;
1112
1113 input_dev = wacom_wac->input;
1114 pad_input_dev = wacom_wac->pad_input;
1115
1116 if (!input_dev || !pad_input_dev)
1117 return -EINVAL;
1118
1085 error = wacom_setup_input_capabilities(input_dev, wacom_wac); 1119 error = wacom_setup_input_capabilities(input_dev, wacom_wac);
1086 if (error) 1120 if (error)
1087 goto fail_input_cap; 1121 return error;
1088 1122
1089 error = input_register_device(input_dev); 1123 error = input_register_device(input_dev);
1090 if (error) 1124 if (error)
1091 goto fail_register_input; 1125 return error;
1092 1126
1093 error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac); 1127 error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
1094 if (error) { 1128 if (error) {
@@ -1106,6 +1140,8 @@ static int wacom_register_inputs(struct wacom *wacom)
1106 goto fail_leds; 1140 goto fail_leds;
1107 } 1141 }
1108 1142
1143 wacom_wac->input_registered = true;
1144
1109 return 0; 1145 return 0;
1110 1146
1111fail_leds: 1147fail_leds:
@@ -1113,16 +1149,7 @@ fail_leds:
1113 pad_input_dev = NULL; 1149 pad_input_dev = NULL;
1114fail_register_pad_input: 1150fail_register_pad_input:
1115 input_unregister_device(input_dev); 1151 input_unregister_device(input_dev);
1116 input_dev = NULL;
1117fail_register_input:
1118fail_input_cap:
1119 wacom_wac->input = NULL; 1152 wacom_wac->input = NULL;
1120 wacom_wac->pad_input = NULL;
1121fail_allocate_input:
1122 if (input_dev)
1123 input_free_device(input_dev);
1124 if (pad_input_dev)
1125 input_free_device(pad_input_dev);
1126 return error; 1153 return error;
1127} 1154}
1128 1155
@@ -1147,13 +1174,13 @@ static void wacom_wireless_work(struct work_struct *work)
1147 hdev1 = usb_get_intfdata(usbdev->config->interface[1]); 1174 hdev1 = usb_get_intfdata(usbdev->config->interface[1]);
1148 wacom1 = hid_get_drvdata(hdev1); 1175 wacom1 = hid_get_drvdata(hdev1);
1149 wacom_wac1 = &(wacom1->wacom_wac); 1176 wacom_wac1 = &(wacom1->wacom_wac);
1150 wacom_unregister_inputs(wacom1); 1177 wacom_clean_inputs(wacom1);
1151 1178
1152 /* Touch interface */ 1179 /* Touch interface */
1153 hdev2 = usb_get_intfdata(usbdev->config->interface[2]); 1180 hdev2 = usb_get_intfdata(usbdev->config->interface[2]);
1154 wacom2 = hid_get_drvdata(hdev2); 1181 wacom2 = hid_get_drvdata(hdev2);
1155 wacom_wac2 = &(wacom2->wacom_wac); 1182 wacom_wac2 = &(wacom2->wacom_wac);
1156 wacom_unregister_inputs(wacom2); 1183 wacom_clean_inputs(wacom2);
1157 1184
1158 if (wacom_wac->pid == 0) { 1185 if (wacom_wac->pid == 0) {
1159 hid_info(wacom->hdev, "wireless tablet disconnected\n"); 1186 hid_info(wacom->hdev, "wireless tablet disconnected\n");
@@ -1187,7 +1214,8 @@ static void wacom_wireless_work(struct work_struct *work)
1187 wacom_wac1->shared->touch_max = wacom_wac1->features.touch_max; 1214 wacom_wac1->shared->touch_max = wacom_wac1->features.touch_max;
1188 wacom_wac1->shared->type = wacom_wac1->features.type; 1215 wacom_wac1->shared->type = wacom_wac1->features.type;
1189 wacom_wac1->pid = wacom_wac->pid; 1216 wacom_wac1->pid = wacom_wac->pid;
1190 error = wacom_register_inputs(wacom1); 1217 error = wacom_allocate_inputs(wacom1) ||
1218 wacom_register_inputs(wacom1);
1191 if (error) 1219 if (error)
1192 goto fail; 1220 goto fail;
1193 1221
@@ -1208,7 +1236,8 @@ static void wacom_wireless_work(struct work_struct *work)
1208 snprintf(wacom_wac2->pad_name, WACOM_NAME_MAX, 1236 snprintf(wacom_wac2->pad_name, WACOM_NAME_MAX,
1209 "%s (WL) Pad", wacom_wac2->features.name); 1237 "%s (WL) Pad", wacom_wac2->features.name);
1210 wacom_wac2->pid = wacom_wac->pid; 1238 wacom_wac2->pid = wacom_wac->pid;
1211 error = wacom_register_inputs(wacom2); 1239 error = wacom_allocate_inputs(wacom2) ||
1240 wacom_register_inputs(wacom2);
1212 if (error) 1241 if (error)
1213 goto fail; 1242 goto fail;
1214 1243
@@ -1225,8 +1254,8 @@ static void wacom_wireless_work(struct work_struct *work)
1225 return; 1254 return;
1226 1255
1227fail: 1256fail:
1228 wacom_unregister_inputs(wacom1); 1257 wacom_clean_inputs(wacom1);
1229 wacom_unregister_inputs(wacom2); 1258 wacom_clean_inputs(wacom2);
1230 return; 1259 return;
1231} 1260}
1232 1261
@@ -1400,7 +1429,8 @@ static int wacom_probe(struct hid_device *hdev,
1400 } 1429 }
1401 1430
1402 if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) { 1431 if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) {
1403 error = wacom_register_inputs(wacom); 1432 error = wacom_allocate_inputs(wacom) ||
1433 wacom_register_inputs(wacom);
1404 if (error) 1434 if (error)
1405 goto fail_register_inputs; 1435 goto fail_register_inputs;
1406 } 1436 }
@@ -1434,11 +1464,11 @@ static int wacom_probe(struct hid_device *hdev,
1434 return 0; 1464 return 0;
1435 1465
1436fail_hw_start: 1466fail_hw_start:
1437 wacom_unregister_inputs(wacom); 1467 wacom_clean_inputs(wacom);
1438 if (hdev->bus == BUS_BLUETOOTH) 1468 if (hdev->bus == BUS_BLUETOOTH)
1439 device_remove_file(&hdev->dev, &dev_attr_speed); 1469 device_remove_file(&hdev->dev, &dev_attr_speed);
1440fail_register_inputs: 1470fail_register_inputs:
1441 wacom_unregister_inputs(wacom); 1471 wacom_clean_inputs(wacom);
1442 wacom_destroy_battery(wacom); 1472 wacom_destroy_battery(wacom);
1443fail_battery: 1473fail_battery:
1444 wacom_remove_shared_data(wacom_wac); 1474 wacom_remove_shared_data(wacom_wac);
@@ -1458,7 +1488,7 @@ static void wacom_remove(struct hid_device *hdev)
1458 hid_hw_stop(hdev); 1488 hid_hw_stop(hdev);
1459 1489
1460 cancel_work_sync(&wacom->work); 1490 cancel_work_sync(&wacom->work);
1461 wacom_unregister_inputs(wacom); 1491 wacom_clean_inputs(wacom);
1462 if (hdev->bus == BUS_BLUETOOTH) 1492 if (hdev->bus == BUS_BLUETOOTH)
1463 device_remove_file(&hdev->dev, &dev_attr_speed); 1493 device_remove_file(&hdev->dev, &dev_attr_speed);
1464 wacom_destroy_battery(wacom); 1494 wacom_destroy_battery(wacom);
diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h
index 339ab5d81a2d..72f9ca8e5cd4 100644
--- a/drivers/hid/wacom_wac.h
+++ b/drivers/hid/wacom_wac.h
@@ -167,6 +167,7 @@ struct wacom_wac {
167 struct wacom_shared *shared; 167 struct wacom_shared *shared;
168 struct input_dev *input; 168 struct input_dev *input;
169 struct input_dev *pad_input; 169 struct input_dev *pad_input;
170 bool input_registered;
170 int pid; 171 int pid;
171 int battery_capacity; 172 int battery_capacity;
172 int num_contacts_left; 173 int num_contacts_left;