}
}
-static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
+static void wacom_wac_battery_usage_mapping(struct hid_device *hdev,
struct hid_field *field, struct hid_usage *usage)
{
struct wacom *wacom = hid_get_drvdata(hdev);
struct wacom_wac *wacom_wac = &wacom->wacom_wac;
struct wacom_features *features = &wacom_wac->features;
- struct input_dev *input = wacom_wac->pad_input;
unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
switch (equivalent_usage) {
+ case HID_DG_BATTERYSTRENGTH:
case WACOM_HID_WD_BATTERY_LEVEL:
case WACOM_HID_WD_BATTERY_CHARGING:
features->quirks |= WACOM_QUIRK_BATTERY;
break;
+ }
+}
+
+static void wacom_wac_battery_event(struct hid_device *hdev, struct hid_field *field,
+ struct hid_usage *usage, __s32 value)
+{
+ struct wacom *wacom = hid_get_drvdata(hdev);
+ struct wacom_wac *wacom_wac = &wacom->wacom_wac;
+ unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
+
+ switch (equivalent_usage) {
+ case HID_DG_BATTERYSTRENGTH:
+ if (value == 0) {
+ wacom_wac->hid_data.bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
+ }
+ else {
+ value = value * 100 / (field->logical_maximum - field->logical_minimum);
+ wacom_wac->hid_data.battery_capacity = value;
+ wacom_wac->hid_data.bat_connected = 1;
+ wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
+ }
+ break;
+ case WACOM_HID_WD_BATTERY_LEVEL:
+ value = value * 100 / (field->logical_maximum - field->logical_minimum);
+ wacom_wac->hid_data.battery_capacity = value;
+ wacom_wac->hid_data.bat_connected = 1;
+ wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
+ break;
+ case WACOM_HID_WD_BATTERY_CHARGING:
+ wacom_wac->hid_data.bat_charging = value;
+ wacom_wac->hid_data.ps_connected = value;
+ wacom_wac->hid_data.bat_connected = 1;
+ wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
+ break;
+ }
+}
+
+static void wacom_wac_battery_pre_report(struct hid_device *hdev,
+ struct hid_report *report)
+{
+ return;
+}
+
+static void wacom_wac_battery_report(struct hid_device *hdev,
+ struct hid_report *report)
+{
+ struct wacom *wacom = hid_get_drvdata(hdev);
+ struct wacom_wac *wacom_wac = &wacom->wacom_wac;
+ struct wacom_features *features = &wacom_wac->features;
+
+ if (features->quirks & WACOM_QUIRK_BATTERY) {
+ int status = wacom_wac->hid_data.bat_status;
+ int capacity = wacom_wac->hid_data.battery_capacity;
+ bool charging = wacom_wac->hid_data.bat_charging;
+ bool connected = wacom_wac->hid_data.bat_connected;
+ bool powered = wacom_wac->hid_data.ps_connected;
+
+ wacom_notify_battery(wacom_wac, status, capacity, charging,
+ connected, powered);
+ }
+}
+
+static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
+ struct hid_field *field, struct hid_usage *usage)
+{
+ struct wacom *wacom = hid_get_drvdata(hdev);
+ struct wacom_wac *wacom_wac = &wacom->wacom_wac;
+ struct wacom_features *features = &wacom_wac->features;
+ struct input_dev *input = wacom_wac->pad_input;
+ unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
+
+ switch (equivalent_usage) {
case WACOM_HID_WD_ACCELEROMETER_X:
__set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 0);
}
}
-static void wacom_wac_pad_battery_event(struct hid_device *hdev, struct hid_field *field,
- struct hid_usage *usage, __s32 value)
-{
- struct wacom *wacom = hid_get_drvdata(hdev);
- struct wacom_wac *wacom_wac = &wacom->wacom_wac;
- unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
-
- switch (equivalent_usage) {
- case WACOM_HID_WD_BATTERY_LEVEL:
- value = value * 100 / (field->logical_maximum - field->logical_minimum);
- wacom_wac->hid_data.battery_capacity = value;
- wacom_wac->hid_data.bat_connected = 1;
- wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
- break;
-
- case WACOM_HID_WD_BATTERY_CHARGING:
- wacom_wac->hid_data.bat_charging = value;
- wacom_wac->hid_data.ps_connected = value;
- wacom_wac->hid_data.bat_connected = 1;
- break;
- }
-}
-
static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field,
struct hid_usage *usage, __s32 value)
{
wacom_wac->hid_data.inrange_state = 0;
}
-static void wacom_wac_pad_battery_report(struct hid_device *hdev,
- struct hid_report *report)
-{
- struct wacom *wacom = hid_get_drvdata(hdev);
- struct wacom_wac *wacom_wac = &wacom->wacom_wac;
- struct wacom_features *features = &wacom_wac->features;
-
- if (features->quirks & WACOM_QUIRK_BATTERY) {
- int status = wacom_wac->hid_data.bat_status;
- int capacity = wacom_wac->hid_data.battery_capacity;
- bool charging = wacom_wac->hid_data.bat_charging;
- bool connected = wacom_wac->hid_data.bat_connected;
- bool powered = wacom_wac->hid_data.ps_connected;
-
- wacom_notify_battery(wacom_wac, status, capacity,
- charging, connected, powered);
- }
-}
-
static void wacom_wac_pad_report(struct hid_device *hdev,
struct hid_report *report)
{
case HID_DG_INRANGE:
wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
break;
- case HID_DG_BATTERYSTRENGTH:
- features->quirks |= WACOM_QUIRK_BATTERY;
- break;
case HID_DG_INVERT:
wacom_map_usage(input, usage, field, EV_KEY,
BTN_TOOL_RUBBER, 0);
if (!(features->quirks & WACOM_QUIRK_SENSE))
wacom_wac->hid_data.sense_state = value;
return;
- case HID_DG_BATTERYSTRENGTH:
- if (value == 0) {
- wacom_wac->hid_data.bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
- }
- else {
- value = value * 100 / (field->logical_maximum - field->logical_minimum);
- wacom_wac->hid_data.battery_capacity = value;
- wacom_wac->hid_data.bat_connected = 1;
- wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
- }
- break;
case HID_DG_INVERT:
wacom_wac->hid_data.invert_state = value;
return;
input_sync(input);
}
- wacom_wac_pad_battery_report(hdev, report);
-
if (!prox) {
wacom_wac->tool[0] = 0;
wacom_wac->id[0] = 0;
if (WACOM_DIRECT_DEVICE(field))
features->device_type |= WACOM_DEVICETYPE_DIRECT;
- if (WACOM_PAD_FIELD(field))
+ /* usage tests must precede field tests */
+ if (WACOM_BATTERY_USAGE(usage))
+ wacom_wac_battery_usage_mapping(hdev, field, usage);
+ else if (WACOM_PAD_FIELD(field))
wacom_wac_pad_usage_mapping(hdev, field, usage);
else if (WACOM_PEN_FIELD(field))
wacom_wac_pen_usage_mapping(hdev, field, usage);
if (value > field->logical_maximum || value < field->logical_minimum)
return;
- if (WACOM_PAD_FIELD(field)) {
- wacom_wac_pad_battery_event(hdev, field, usage, value);
- if (wacom->wacom_wac.pad_input)
- wacom_wac_pad_event(hdev, field, usage, value);
- } else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
+ /* usage tests must precede field tests */
+ if (WACOM_BATTERY_USAGE(usage))
+ wacom_wac_battery_event(hdev, field, usage, value);
+ else if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
+ wacom_wac_pad_event(hdev, field, usage, value);
+ else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
wacom_wac_pen_event(hdev, field, usage, value);
else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
wacom_wac_finger_event(hdev, field, usage, value);
if (wacom_wac->features.type != HID_GENERIC)
return;
+ wacom_wac_battery_pre_report(hdev, report);
+
if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
wacom_wac_pad_pre_report(hdev, report);
else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
if (report->type != HID_INPUT_REPORT)
return;
- if (WACOM_PAD_FIELD(field)) {
- wacom_wac_pad_battery_report(hdev, report);
- if (wacom->wacom_wac.pad_input)
- wacom_wac_pad_report(hdev, report);
- } else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
+ wacom_wac_battery_report(hdev, report);
+
+ if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
+ wacom_wac_pad_report(hdev, report);
+ else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
wacom_wac_pen_report(hdev, report);
else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
wacom_wac_finger_report(hdev, report);