Skip to content

Commit 37cf6e6

Browse files
bentissJiri Kosina
authored andcommitted
HID: export hidinput_calc_abs_res
Exporting the function allows us to calculate the resolution in third party drivers like hid-multitouch. This patch also complete the function with additional valid axes. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com> Acked-by: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 976bace commit 37cf6e6

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎drivers/hid/hid-input.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static int hidinput_setkeycode(struct input_dev *dev,
208208
* Only exponent 1 length units are processed. Centimeters and inches are
209209
* converted to millimeters. Degrees are converted to radians.
210210
*/
211-
static __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code)
211+
__s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code)
212212
{
213213
__s32 unit_exponent = field->unit_exponent;
214214
__s32 logical_extents = field->logical_maximum -
@@ -229,6 +229,12 @@ static __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code)
229229
case ABS_X:
230230
case ABS_Y:
231231
case ABS_Z:
232+
case ABS_MT_POSITION_X:
233+
case ABS_MT_POSITION_Y:
234+
case ABS_MT_TOOL_X:
235+
case ABS_MT_TOOL_Y:
236+
case ABS_MT_TOUCH_MAJOR:
237+
case ABS_MT_TOUCH_MINOR:
232238
if (field->unit == 0x11) { /* If centimeters */
233239
/* Convert to millimeters */
234240
unit_exponent += 1;
@@ -283,6 +289,7 @@ static __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code)
283289
/* Calculate resolution */
284290
return logical_extents / physical_extents;
285291
}
292+
EXPORT_SYMBOL_GPL(hidinput_calc_abs_res);
286293

287294
#ifdef CONFIG_HID_BATTERY_STRENGTH
288295
static enum power_supply_property hidinput_battery_props[] = {

‎drivers/hid/hid-multitouch.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ static void set_abs(struct input_dev *input, unsigned int code,
297297
int fmax = field->logical_maximum;
298298
int fuzz = snratio ? (fmax - fmin) / snratio : 0;
299299
input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
300+
input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
300301
}
301302

302303
static void mt_store_field(struct hid_usage *usage, struct mt_device *td,

‎include/linux/hid.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ int hid_input_report(struct hid_device *, int type, u8 *, int, int);
706706
int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field);
707707
struct hid_field *hidinput_get_led_field(struct hid_device *hid);
708708
unsigned int hidinput_count_leds(struct hid_device *hid);
709+
__s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code);
709710
void hid_output_report(struct hid_report *report, __u8 *data);
710711
struct hid_device *hid_allocate_device(void);
711712
struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id);

0 commit comments

Comments
 (0)