Skip to content

Commit 7657bf0

Browse files
Angela CzubakBenjamin Tissoires
authored andcommitted
HID: input: calculate resolution for pressure
Assume that if the pressure is given in newtons it should be normalized to grams. If the pressure has no unit do not calculate resolution. Signed-off-by: Angela Czubak <aczubak@google.com> Co-developed-by: Jonathan Denose <jdenose@google.com> Signed-off-by: Jonathan Denose <jdenose@google.com> Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
1 parent 344ff35 commit 7657bf0

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

drivers/hid/hid-input.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,19 @@ __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code)
303303
}
304304
break;
305305

306+
case ABS_PRESSURE:
307+
case ABS_MT_PRESSURE:
308+
if (field->unit == HID_UNIT_NEWTON) {
309+
/* Convert to grams, 1 newton is 101.97 grams */
310+
prev = physical_extents;
311+
physical_extents *= 10197;
312+
if (physical_extents < prev)
313+
return 0;
314+
unit_exponent -= 2;
315+
} else if (field->unit != HID_UNIT_GRAM) {
316+
return 0;
317+
}
318+
break;
306319
default:
307320
return 0;
308321
}

0 commit comments

Comments
 (0)