Skip to content

Commit a77efca

Browse files
Angela CzubakBenjamin Tissoires
authored andcommitted
HID: haptic: add functions handling events
Implement hid_haptic_handle_press_release() which generates haptic feedback as well as saves the pressed state of the haptic device. Add functions to increase and reset the state of the pressure detected by the device. 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 7657bf0 commit a77efca

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

drivers/hid/hid-haptic.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ EXPORT_SYMBOL_GPL(hid_haptic_feature_mapping);
5050
bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic,
5151
struct hid_input *hi, struct hid_field *field)
5252
{
53-
if (field->unit == HID_UNIT_GRAM || field->unit == HID_UNIT_NEWTON)
53+
if (field->unit == HID_UNIT_GRAM || field->unit == HID_UNIT_NEWTON) {
54+
haptic->force_logical_minimum = field->logical_minimum;
55+
haptic->force_physical_minimum = field->physical_minimum;
56+
haptic->force_resolution = input_abs_get_res(hi->input,
57+
ABS_MT_PRESSURE);
5458
return true;
59+
}
5560
return false;
5661
}
5762
EXPORT_SYMBOL_GPL(hid_haptic_check_pressure_unit);
@@ -508,3 +513,16 @@ int hid_haptic_init(struct hid_device *hdev,
508513
return ret;
509514
}
510515
EXPORT_SYMBOL_GPL(hid_haptic_init);
516+
517+
void hid_haptic_pressure_reset(struct hid_haptic_device *haptic)
518+
{
519+
haptic->pressure_sum = 0;
520+
}
521+
EXPORT_SYMBOL_GPL(hid_haptic_pressure_reset);
522+
523+
void hid_haptic_pressure_increase(struct hid_haptic_device *haptic,
524+
__s32 pressure)
525+
{
526+
haptic->pressure_sum += pressure;
527+
}
528+
EXPORT_SYMBOL_GPL(hid_haptic_pressure_increase);

drivers/hid/hid-haptic.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ int hid_haptic_input_configured(struct hid_device *hdev,
7070
struct hid_haptic_device *haptic,
7171
struct hid_input *hi);
7272
int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device **haptic_ptr);
73+
void hid_haptic_handle_press_release(struct hid_haptic_device *haptic);
74+
void hid_haptic_pressure_reset(struct hid_haptic_device *haptic);
75+
void hid_haptic_pressure_increase(struct hid_haptic_device *haptic,
76+
__s32 pressure);
7377
#else
7478
static inline
7579
void hid_haptic_feature_mapping(struct hid_device *hdev,
@@ -103,4 +107,15 @@ int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device **haptic_p
103107
{
104108
return 0;
105109
}
110+
static inline
111+
void hid_haptic_handle_press_release(struct hid_haptic_device *haptic)
112+
{}
113+
static inline
114+
void hid_haptic_pressure_reset(struct hid_haptic_device *haptic)
115+
{}
116+
static inline
117+
void hid_haptic_pressure_increase(struct hid_haptic_device *haptic,
118+
__s32 pressure)
119+
{}
106120
#endif
121+

0 commit comments

Comments
 (0)