Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: pm8941-pwrkey - simulate missed key press events

The status of the keys connected to the KPDPWR_N and RESIN_N pins
is identified by reading corresponding bits in the interrupt real
time status register. If the status has changed by the time that
the interrupt is handled then a press event will be missed.

Maintain a last known status variable to find unbalanced release
events and simulate press events for each accordingly.

Signed-off-by: David Collins <collinsd@codeaurora.org>
Signed-off-by: Anjelique Melendez <quic_amelende@quicinc.com>
Link: https://lore.kernel.org/r/20220422191239.6271-6-quic_amelende@quicinc.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

David Collins and committed by
Dmitry Torokhov
be8fc023 0b65118e

+11
+11
drivers/input/misc/pm8941-pwrkey.c
··· 77 77 u32 code; 78 78 u32 sw_debounce_time_us; 79 79 ktime_t sw_debounce_end_time; 80 + bool last_status; 80 81 const struct pm8941_data *data; 81 82 }; 82 83 ··· 167 166 if (pwrkey->sw_debounce_time_us && !sts) 168 167 pwrkey->sw_debounce_end_time = ktime_add_us(ktime_get(), 169 168 pwrkey->sw_debounce_time_us); 169 + 170 + /* 171 + * Simulate a press event in case a release event occurred without a 172 + * corresponding press event. 173 + */ 174 + if (!pwrkey->last_status && !sts) { 175 + input_report_key(pwrkey->input, pwrkey->code, 1); 176 + input_sync(pwrkey->input); 177 + } 178 + pwrkey->last_status = sts; 170 179 171 180 input_report_key(pwrkey->input, pwrkey->code, sts); 172 181 input_sync(pwrkey->input);