* input: ps2-gpio: use ktime for IRQ timekeeping
@ 2022-02-11 21:22 Danilo Krummrich
2022-02-11 21:22 ` [PATCH 1/3] " Danilo Krummrich
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Danilo Krummrich @ 2022-02-11 21:22 UTC (permalink / raw)
To: dmitry.torokhov, linux-input, linux-kernel; +Cc: linus.walleij
This patch series implements the usage of ktime for IRQ timekeeping to
overcome:
(1) The resolution limitations of jiffies.
(2) Potential spurious IRQs generated by gpio controllers.
Besides that, based on the newly implemented timekeeping, it fixes a wrongly
suspected extra clock cycle for TX transfers and a race condition when
starting an immediate TX transfer based on data received from an RX transfer.
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 1/3] input: ps2-gpio: use ktime for IRQ timekeeping
2022-02-11 21:22 input: ps2-gpio: use ktime for IRQ timekeeping Danilo Krummrich
@ 2022-02-11 21:22 ` Danilo Krummrich
2022-02-15 6:14 ` Dmitry Torokhov
2022-02-11 21:22 ` [PATCH 2/3] input: ps2-gpio: remove tx timeout from ps2_gpio_irq_tx() Danilo Krummrich
2022-02-11 21:22 ` [PATCH 3/3] input: ps2-gpio: don't send rx data before the stop bit Danilo Krummrich
2 siblings, 1 reply; 7+ messages in thread
From: Danilo Krummrich @ 2022-02-11 21:22 UTC (permalink / raw)
To: dmitry.torokhov, linux-input, linux-kernel
Cc: linus.walleij, Danilo Krummrich
Using jiffies for the IRQ timekeeping is not sufficient for two reasons:
(1) Usually jiffies have a resolution of 1ms to 10ms. The IRQ intervals
based on the clock frequency of PS2 protocol specification (10kHz -
16.7kHz) are between ~60us and 100us only. Therefore only those IRQ
intervals can be detected which are either at the end of a transfer
or are overly delayed. While this is sufficient in most cases, since
we have quite a lot of ways to detect faulty transfers, it can
produce false positives in rare cases: When the jiffies value
changes right between two interrupt that are in time, we wrongly
assume that we missed one or more clock cycles.
(2) Some gpio controllers (e.g. the one in the bcm283x chips) may generate
spurious IRQs when processing interrupts in the frequency given by PS2
devices.
Both issues can be fixed by using ktime resolution for IRQ timekeeping.
However, it is still possible to miss clock cycles without detecting
them. When the PS2 device generates the falling edge of the clock signal
we have between ~30us and 50us to sample the data line, because after
this time we reach the next rising edge at which the device changes the
data signal already. But, the only thing we can detect is whether the
IRQ interval is within the given period. Therefore it is possible to
have an IRQ latency greater than ~30us to 50us, sample the wrong bit on
the data line and still be on time with the next IRQ. However, this can
only happen when within a given transfer the IRQ latency increases
slowly.
___ ______ ______ ______ ___
\ / \ / \ / \ /
\ / \ / \ / \ /
\______/ \______/ \______/ \______/
|-----------------| |--------|
60us/100us 30us/50us
Signed-off-by: Danilo Krummrich <danilokrummrich@dk-develop.de>
---
drivers/input/serio/ps2-gpio.c | 81 ++++++++++++++++++++++++++++------
1 file changed, 67 insertions(+), 14 deletions(-)
diff --git a/drivers/input/serio/ps2-gpio.c b/drivers/input/serio/ps2-gpio.c
index 8970b49ea09a..7fef4176bdd1 100644
--- a/drivers/input/serio/ps2-gpio.c
+++ b/drivers/input/serio/ps2-gpio.c
@@ -19,6 +19,7 @@
#include <linux/of.h>
#include <linux/jiffies.h>
#include <linux/delay.h>
+#include <linux/timekeeping.h>
#define DRIVER_NAME "ps2-gpio"
@@ -44,6 +45,29 @@
#define PS2_CMD_RESEND 0xfe
+/* The PS2 protocol specifies a clock frequency between 10kHz and 16.7kHz,
+ * therefore the maximal interrupt interval should be 100us and the minimum
+ * interrupt interval should be ~60us. Let's allow +/- 20us for frequency
+ * deviations and interrupt latency.
+ *
+ * The data line must be samples after ~30us to 50us after the falling edge,
+ * since the device updates the data line at the rising edge.
+ *
+ * ___ ______ ______ ______ ___
+ * \ / \ / \ / \ /
+ * \ / \ / \ / \ /
+ * \______/ \______/ \______/ \______/
+ *
+ * |-----------------| |--------|
+ * 60us/100us 30us/50us
+ */
+#define PS2_CLK_FREQ_MIN_HZ 10000
+#define PS2_CLK_FREQ_MAX_HZ 16700
+#define PS2_CLK_MIN_INTERVAL_US ((1000 * 1000) / PS2_CLK_FREQ_MAX_HZ)
+#define PS2_CLK_MAX_INTERVAL_US ((1000 * 1000) / PS2_CLK_FREQ_MIN_HZ)
+#define PS2_IRQ_MIN_INTERVAL_US (PS2_CLK_MIN_INTERVAL_US - 20)
+#define PS2_IRQ_MAX_INTERVAL_US (PS2_CLK_MAX_INTERVAL_US + 20)
+
struct ps2_gpio_data {
struct device *dev;
struct serio *serio;
@@ -59,6 +83,8 @@ struct ps2_gpio_data {
struct completion tx_done;
struct mutex tx_mutex;
struct delayed_work tx_work;
+ ktime_t tx_start;
+ ktime_t tx_end;
};
static int ps2_gpio_open(struct serio *serio)
@@ -118,6 +144,7 @@ static void ps2_gpio_tx_work_fn(struct work_struct *work)
struct ps2_gpio_data,
tx_work);
+ drvdata->tx_start = ktime_get();
enable_irq(drvdata->irq);
gpiod_direction_output(drvdata->gpio_data, 0);
gpiod_direction_input(drvdata->gpio_clk);
@@ -128,20 +155,33 @@ static irqreturn_t ps2_gpio_irq_rx(struct ps2_gpio_data *drvdata)
unsigned char byte, cnt;
int data;
int rxflags = 0;
- static unsigned long old_jiffies;
+ static ktime_t t_last, t_now;
+ s64 us_delta;
byte = drvdata->rx_byte;
cnt = drvdata->rx_cnt;
- if (old_jiffies == 0)
- old_jiffies = jiffies;
+ t_now = ktime_get();
+ if (t_last == 0)
+ t_last = t_now;
- if ((jiffies - old_jiffies) > usecs_to_jiffies(100)) {
+ /* We need to consider spurious interrupts happening right after a TX xfer
+ * finished.
+ */
+ if (unlikely(ktime_us_delta(t_now, drvdata->tx_end) <
+ PS2_IRQ_MIN_INTERVAL_US))
+ goto end;
+
+ us_delta = ktime_us_delta(t_now, t_last);
+ if (us_delta > PS2_IRQ_MAX_INTERVAL_US && cnt) {
dev_err(drvdata->dev,
"RX: timeout, probably we missed an interrupt\n");
goto err;
+ } else if (us_delta < PS2_IRQ_MIN_INTERVAL_US && t_now != t_last) {
+ /* Ignore spurious IRQs. */
+ goto end;
}
- old_jiffies = jiffies;
+ t_last = t_now;
data = gpiod_get_value(drvdata->gpio_data);
if (unlikely(data < 0)) {
@@ -205,7 +245,7 @@ static irqreturn_t ps2_gpio_irq_rx(struct ps2_gpio_data *drvdata)
goto err;
}
cnt = byte = 0;
- old_jiffies = 0;
+
goto end; /* success */
default:
dev_err(drvdata->dev, "RX: got out of sync with the device\n");
@@ -217,7 +257,6 @@ static irqreturn_t ps2_gpio_irq_rx(struct ps2_gpio_data *drvdata)
err:
cnt = byte = 0;
- old_jiffies = 0;
__ps2_gpio_write(drvdata->serio, PS2_CMD_RESEND);
end:
drvdata->rx_cnt = cnt;
@@ -229,20 +268,34 @@ static irqreturn_t ps2_gpio_irq_tx(struct ps2_gpio_data *drvdata)
{
unsigned char byte, cnt;
int data;
- static unsigned long old_jiffies;
+ static ktime_t t_last, t_now;
+ s64 us_delta;
cnt = drvdata->tx_cnt;
byte = drvdata->tx_byte;
- if (old_jiffies == 0)
- old_jiffies = jiffies;
+ t_now = ktime_get();
+ if (t_last == 0)
+ t_last = t_now;
+
+ /* There might be pending IRQs since we disabled IRQs in __ps2_gpio_write().
+ * We can expect at least one clock period until the device generates the
+ * first falling edge after releasing the clock line.
+ */
+ if (unlikely(ktime_us_delta(t_now, drvdata->tx_start) <
+ PS2_CLK_MIN_INTERVAL_US))
+ goto end;
- if ((jiffies - old_jiffies) > usecs_to_jiffies(100)) {
+ us_delta = ktime_us_delta(t_now, t_last);
+ if (us_delta > PS2_IRQ_MAX_INTERVAL_US && cnt > 1) {
dev_err(drvdata->dev,
"TX: timeout, probably we missed an interrupt\n");
goto err;
+ } else if (us_delta < PS2_IRQ_MIN_INTERVAL_US && t_now != t_last) {
+ /* Ignore spurious IRQs. */
+ goto end;
}
- old_jiffies = jiffies;
+ t_last = t_now;
switch (cnt) {
case PS2_START_BIT:
@@ -283,11 +336,11 @@ static irqreturn_t ps2_gpio_irq_tx(struct ps2_gpio_data *drvdata)
goto err;
}
+ drvdata->tx_end = ktime_get();
drvdata->mode = PS2_MODE_RX;
complete(&drvdata->tx_done);
cnt = 1;
- old_jiffies = 0;
goto end; /* success */
default:
/* Probably we missed the stop bit. Therefore we release data
@@ -303,7 +356,6 @@ static irqreturn_t ps2_gpio_irq_tx(struct ps2_gpio_data *drvdata)
err:
cnt = 1;
- old_jiffies = 0;
gpiod_direction_input(drvdata->gpio_data);
__ps2_gpio_write(drvdata->serio, drvdata->tx_byte);
end:
@@ -399,6 +451,7 @@ static int ps2_gpio_probe(struct platform_device *pdev)
drvdata->serio = serio;
drvdata->dev = dev;
drvdata->mode = PS2_MODE_RX;
+ drvdata->tx_end = 0;
/* Tx count always starts at 1, as the start bit is sent implicitly by
* host-to-device communication initialization.
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 1/3] input: ps2-gpio: use ktime for IRQ timekeeping
2022-02-11 21:22 ` [PATCH 1/3] " Danilo Krummrich
@ 2022-02-15 6:14 ` Dmitry Torokhov
2022-02-15 12:09 ` Danilo Krummrich
0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2022-02-15 6:14 UTC (permalink / raw)
To: Danilo Krummrich; +Cc: linux-input, linux-kernel, linus.walleij
Hi Danilo,
On Fri, Feb 11, 2022 at 10:22:56PM +0100, Danilo Krummrich wrote:
> Using jiffies for the IRQ timekeeping is not sufficient for two reasons:
>
> (1) Usually jiffies have a resolution of 1ms to 10ms. The IRQ intervals
> based on the clock frequency of PS2 protocol specification (10kHz -
> 16.7kHz) are between ~60us and 100us only. Therefore only those IRQ
> intervals can be detected which are either at the end of a transfer
> or are overly delayed. While this is sufficient in most cases, since
> we have quite a lot of ways to detect faulty transfers, it can
> produce false positives in rare cases: When the jiffies value
> changes right between two interrupt that are in time, we wrongly
> assume that we missed one or more clock cycles.
>
> (2) Some gpio controllers (e.g. the one in the bcm283x chips) may generate
> spurious IRQs when processing interrupts in the frequency given by PS2
> devices.
>
> Both issues can be fixed by using ktime resolution for IRQ timekeeping.
>
> However, it is still possible to miss clock cycles without detecting
> them. When the PS2 device generates the falling edge of the clock signal
> we have between ~30us and 50us to sample the data line, because after
> this time we reach the next rising edge at which the device changes the
> data signal already. But, the only thing we can detect is whether the
> IRQ interval is within the given period. Therefore it is possible to
> have an IRQ latency greater than ~30us to 50us, sample the wrong bit on
> the data line and still be on time with the next IRQ. However, this can
> only happen when within a given transfer the IRQ latency increases
> slowly.
>
> ___ ______ ______ ______ ___
> \ / \ / \ / \ /
> \ / \ / \ / \ /
> \______/ \______/ \______/ \______/
>
> |-----------------| |--------|
> 60us/100us 30us/50us
>
> Signed-off-by: Danilo Krummrich <danilokrummrich@dk-develop.de>
> ---
> drivers/input/serio/ps2-gpio.c | 81 ++++++++++++++++++++++++++++------
> 1 file changed, 67 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/input/serio/ps2-gpio.c b/drivers/input/serio/ps2-gpio.c
> index 8970b49ea09a..7fef4176bdd1 100644
> --- a/drivers/input/serio/ps2-gpio.c
> +++ b/drivers/input/serio/ps2-gpio.c
> @@ -19,6 +19,7 @@
> #include <linux/of.h>
> #include <linux/jiffies.h>
> #include <linux/delay.h>
> +#include <linux/timekeeping.h>
>
> #define DRIVER_NAME "ps2-gpio"
>
> @@ -44,6 +45,29 @@
>
> #define PS2_CMD_RESEND 0xfe
>
> +/* The PS2 protocol specifies a clock frequency between 10kHz and 16.7kHz,
> + * therefore the maximal interrupt interval should be 100us and the minimum
> + * interrupt interval should be ~60us. Let's allow +/- 20us for frequency
> + * deviations and interrupt latency.
> + *
> + * The data line must be samples after ~30us to 50us after the falling edge,
> + * since the device updates the data line at the rising edge.
> + *
> + * ___ ______ ______ ______ ___
> + * \ / \ / \ / \ /
> + * \ / \ / \ / \ /
> + * \______/ \______/ \______/ \______/
> + *
> + * |-----------------| |--------|
> + * 60us/100us 30us/50us
> + */
> +#define PS2_CLK_FREQ_MIN_HZ 10000
> +#define PS2_CLK_FREQ_MAX_HZ 16700
> +#define PS2_CLK_MIN_INTERVAL_US ((1000 * 1000) / PS2_CLK_FREQ_MAX_HZ)
> +#define PS2_CLK_MAX_INTERVAL_US ((1000 * 1000) / PS2_CLK_FREQ_MIN_HZ)
> +#define PS2_IRQ_MIN_INTERVAL_US (PS2_CLK_MIN_INTERVAL_US - 20)
> +#define PS2_IRQ_MAX_INTERVAL_US (PS2_CLK_MAX_INTERVAL_US + 20)
> +
> struct ps2_gpio_data {
> struct device *dev;
> struct serio *serio;
> @@ -59,6 +83,8 @@ struct ps2_gpio_data {
> struct completion tx_done;
> struct mutex tx_mutex;
> struct delayed_work tx_work;
> + ktime_t tx_start;
> + ktime_t tx_end;
> };
>
> static int ps2_gpio_open(struct serio *serio)
> @@ -118,6 +144,7 @@ static void ps2_gpio_tx_work_fn(struct work_struct *work)
> struct ps2_gpio_data,
> tx_work);
>
> + drvdata->tx_start = ktime_get();
> enable_irq(drvdata->irq);
> gpiod_direction_output(drvdata->gpio_data, 0);
> gpiod_direction_input(drvdata->gpio_clk);
> @@ -128,20 +155,33 @@ static irqreturn_t ps2_gpio_irq_rx(struct ps2_gpio_data *drvdata)
> unsigned char byte, cnt;
> int data;
> int rxflags = 0;
> - static unsigned long old_jiffies;
> + static ktime_t t_last, t_now;
> + s64 us_delta;
>
> byte = drvdata->rx_byte;
> cnt = drvdata->rx_cnt;
>
> - if (old_jiffies == 0)
> - old_jiffies = jiffies;
> + t_now = ktime_get();
> + if (t_last == 0)
Instead of checking this every time, do you think we could seed the
value in ps2_gpio_open() (and also make it per-port, not static)?
> + t_last = t_now;
>
> - if ((jiffies - old_jiffies) > usecs_to_jiffies(100)) {
> + /* We need to consider spurious interrupts happening right after a TX xfer
> + * finished.
> + */
> + if (unlikely(ktime_us_delta(t_now, drvdata->tx_end) <
> + PS2_IRQ_MIN_INTERVAL_US))
> + goto end;
> +
> + us_delta = ktime_us_delta(t_now, t_last);
> + if (us_delta > PS2_IRQ_MAX_INTERVAL_US && cnt) {
> dev_err(drvdata->dev,
> "RX: timeout, probably we missed an interrupt\n");
> goto err;
> + } else if (us_delta < PS2_IRQ_MIN_INTERVAL_US && t_now != t_last) {
> + /* Ignore spurious IRQs. */
> + goto end;
> }
> - old_jiffies = jiffies;
> + t_last = t_now;
>
> data = gpiod_get_value(drvdata->gpio_data);
> if (unlikely(data < 0)) {
> @@ -205,7 +245,7 @@ static irqreturn_t ps2_gpio_irq_rx(struct ps2_gpio_data *drvdata)
> goto err;
> }
> cnt = byte = 0;
> - old_jiffies = 0;
> +
> goto end; /* success */
> default:
> dev_err(drvdata->dev, "RX: got out of sync with the device\n");
> @@ -217,7 +257,6 @@ static irqreturn_t ps2_gpio_irq_rx(struct ps2_gpio_data *drvdata)
>
> err:
> cnt = byte = 0;
> - old_jiffies = 0;
> __ps2_gpio_write(drvdata->serio, PS2_CMD_RESEND);
> end:
> drvdata->rx_cnt = cnt;
> @@ -229,20 +268,34 @@ static irqreturn_t ps2_gpio_irq_tx(struct ps2_gpio_data *drvdata)
> {
> unsigned char byte, cnt;
> int data;
> - static unsigned long old_jiffies;
> + static ktime_t t_last, t_now;
> + s64 us_delta;
>
> cnt = drvdata->tx_cnt;
> byte = drvdata->tx_byte;
>
> - if (old_jiffies == 0)
> - old_jiffies = jiffies;
> + t_now = ktime_get();
> + if (t_last == 0)
> + t_last = t_now;
> +
> + /* There might be pending IRQs since we disabled IRQs in __ps2_gpio_write().
> + * We can expect at least one clock period until the device generates the
> + * first falling edge after releasing the clock line.
> + */
> + if (unlikely(ktime_us_delta(t_now, drvdata->tx_start) <
> + PS2_CLK_MIN_INTERVAL_US))
> + goto end;
>
> - if ((jiffies - old_jiffies) > usecs_to_jiffies(100)) {
> + us_delta = ktime_us_delta(t_now, t_last);
> + if (us_delta > PS2_IRQ_MAX_INTERVAL_US && cnt > 1) {
> dev_err(drvdata->dev,
> "TX: timeout, probably we missed an interrupt\n");
> goto err;
> + } else if (us_delta < PS2_IRQ_MIN_INTERVAL_US && t_now != t_last) {
> + /* Ignore spurious IRQs. */
> + goto end;
> }
> - old_jiffies = jiffies;
> + t_last = t_now;
>
> switch (cnt) {
> case PS2_START_BIT:
> @@ -283,11 +336,11 @@ static irqreturn_t ps2_gpio_irq_tx(struct ps2_gpio_data *drvdata)
> goto err;
> }
>
> + drvdata->tx_end = ktime_get();
> drvdata->mode = PS2_MODE_RX;
> complete(&drvdata->tx_done);
>
> cnt = 1;
> - old_jiffies = 0;
> goto end; /* success */
> default:
> /* Probably we missed the stop bit. Therefore we release data
> @@ -303,7 +356,6 @@ static irqreturn_t ps2_gpio_irq_tx(struct ps2_gpio_data *drvdata)
>
> err:
> cnt = 1;
> - old_jiffies = 0;
> gpiod_direction_input(drvdata->gpio_data);
> __ps2_gpio_write(drvdata->serio, drvdata->tx_byte);
> end:
> @@ -399,6 +451,7 @@ static int ps2_gpio_probe(struct platform_device *pdev)
> drvdata->serio = serio;
> drvdata->dev = dev;
> drvdata->mode = PS2_MODE_RX;
> + drvdata->tx_end = 0;
>
> /* Tx count always starts at 1, as the start bit is sent implicitly by
> * host-to-device communication initialization.
> --
> 2.34.1
>
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 1/3] input: ps2-gpio: use ktime for IRQ timekeeping
2022-02-15 6:14 ` Dmitry Torokhov
@ 2022-02-15 12:09 ` Danilo Krummrich
0 siblings, 0 replies; 7+ messages in thread
From: Danilo Krummrich @ 2022-02-15 12:09 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-input, linux-kernel, linus.walleij
Hi Dmitry,
On Mon, Feb 14, 2022 at 10:14:24PM -0800, Dmitry Torokhov wrote:
> Hi Danilo,
>
> On Fri, Feb 11, 2022 at 10:22:56PM +0100, Danilo Krummrich wrote:
> > @@ -128,20 +155,33 @@ static irqreturn_t ps2_gpio_irq_rx(struct ps2_gpio_data *drvdata)
> > unsigned char byte, cnt;
> > int data;
> > int rxflags = 0;
> > - static unsigned long old_jiffies;
> > + static ktime_t t_last, t_now;
> > + s64 us_delta;
> >
> > byte = drvdata->rx_byte;
> > cnt = drvdata->rx_cnt;
> >
> > - if (old_jiffies == 0)
> > - old_jiffies = jiffies;
> > + t_now = ktime_get();
> > + if (t_last == 0)
>
> Instead of checking this every time, do you think we could seed the
> value in ps2_gpio_open() (and also make it per-port, not static)?
Oops! Sure, I'll send a v2.
I will also add another patch to refactor struct ps2_gpio_data to clearly
separate rx and tx state data, otherwise it might start to become a bit messy.
>
> Thanks.
>
> --
> Dmitry
- Danilo
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/3] input: ps2-gpio: remove tx timeout from ps2_gpio_irq_tx()
2022-02-11 21:22 input: ps2-gpio: use ktime for IRQ timekeeping Danilo Krummrich
2022-02-11 21:22 ` [PATCH 1/3] " Danilo Krummrich
@ 2022-02-11 21:22 ` Danilo Krummrich
2022-02-11 21:22 ` [PATCH 3/3] input: ps2-gpio: don't send rx data before the stop bit Danilo Krummrich
2 siblings, 0 replies; 7+ messages in thread
From: Danilo Krummrich @ 2022-02-11 21:22 UTC (permalink / raw)
To: dmitry.torokhov, linux-input, linux-kernel
Cc: linus.walleij, Danilo Krummrich
Actually, there's no extra clock pulse to wait for.
The assumption of an extra clock pulse was mistakenly derived from the
fact that by the time this driver was introduced the GPIO controller of
the test machine (bcm2835) generated spurious interrupts.
Since now spurious interrupts are handled properly this can and must be
removed in order to make TX xfers work properly.
While at it, remove duplicate gpiod_direction_input(). The data gpio
must already be configured to act as input when receiving the ACK bit.
This patch is tested with the original hardware (peripherals and board)
the driver was developed on.
Signed-off-by: Danilo Krummrich <danilokrummrich@dk-develop.de>
---
drivers/input/serio/ps2-gpio.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/input/serio/ps2-gpio.c b/drivers/input/serio/ps2-gpio.c
index 7fef4176bdd1..336928a8a127 100644
--- a/drivers/input/serio/ps2-gpio.c
+++ b/drivers/input/serio/ps2-gpio.c
@@ -37,8 +37,7 @@
#define PS2_DATA_BIT7 8
#define PS2_PARITY_BIT 9
#define PS2_STOP_BIT 10
-#define PS2_TX_TIMEOUT 11
-#define PS2_ACK_BIT 12
+#define PS2_ACK_BIT 11
#define PS2_DEV_RET_ACK 0xfa
#define PS2_DEV_RET_NACK 0xfe
@@ -323,13 +322,7 @@ static irqreturn_t ps2_gpio_irq_tx(struct ps2_gpio_data *drvdata)
/* release data line to generate stop bit */
gpiod_direction_input(drvdata->gpio_data);
break;
- case PS2_TX_TIMEOUT:
- /* Devices generate one extra clock pulse before sending the
- * acknowledgment.
- */
- break;
case PS2_ACK_BIT:
- gpiod_direction_input(drvdata->gpio_data);
data = gpiod_get_value(drvdata->gpio_data);
if (data) {
dev_warn(drvdata->dev, "TX: received NACK, retry\n");
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 3/3] input: ps2-gpio: don't send rx data before the stop bit
2022-02-11 21:22 input: ps2-gpio: use ktime for IRQ timekeeping Danilo Krummrich
2022-02-11 21:22 ` [PATCH 1/3] " Danilo Krummrich
2022-02-11 21:22 ` [PATCH 2/3] input: ps2-gpio: remove tx timeout from ps2_gpio_irq_tx() Danilo Krummrich
@ 2022-02-11 21:22 ` Danilo Krummrich
2 siblings, 0 replies; 7+ messages in thread
From: Danilo Krummrich @ 2022-02-11 21:22 UTC (permalink / raw)
To: dmitry.torokhov, linux-input, linux-kernel
Cc: linus.walleij, Danilo Krummrich
Sending the data before processing the stop bit from the device already
saves the data of the current xfer in case the stop bit is missed.
However, when TX xfers are enabled this introduces a race condition when
a peripheral driver using the bus immediately requests a TX xfer from IRQ
context.
Therefore the data must be send after receiving the stop bit, although
it is possible the data is lost when missing the stop bit.
Signed-off-by: Danilo Krummrich <danilokrummrich@dk-develop.de>
---
drivers/input/serio/ps2-gpio.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/drivers/input/serio/ps2-gpio.c b/drivers/input/serio/ps2-gpio.c
index 336928a8a127..460d520ac865 100644
--- a/drivers/input/serio/ps2-gpio.c
+++ b/drivers/input/serio/ps2-gpio.c
@@ -217,6 +217,13 @@ static irqreturn_t ps2_gpio_irq_rx(struct ps2_gpio_data *drvdata)
if (!drvdata->write_enable)
goto err;
}
+ break;
+ case PS2_STOP_BIT:
+ /* stop bit should be high */
+ if (unlikely(!data)) {
+ dev_err(drvdata->dev, "RX: stop bit should be high\n");
+ goto err;
+ }
/* Do not send spurious ACK's and NACK's when write fn is
* not provided.
@@ -228,21 +235,9 @@ static irqreturn_t ps2_gpio_irq_rx(struct ps2_gpio_data *drvdata)
break;
}
- /* Let's send the data without waiting for the stop bit to be
- * sent. It may happen that we miss the stop bit. When this
- * happens we have no way to recover from this, certainly
- * missing the parity bit would be recognized when processing
- * the stop bit. When missing both, data is lost.
- */
serio_interrupt(drvdata->serio, byte, rxflags);
dev_dbg(drvdata->dev, "RX: sending byte 0x%x\n", byte);
- break;
- case PS2_STOP_BIT:
- /* stop bit should be high */
- if (unlikely(!data)) {
- dev_err(drvdata->dev, "RX: stop bit should be high\n");
- goto err;
- }
+
cnt = byte = 0;
goto end; /* success */
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] input: ps2-gpio: don't send rx data before the stop bit
@ 2022-02-12 10:39 kernel test robot
0 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2022-02-12 10:39 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 23640 bytes --]
CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20220211212258.80345-4-danilokrummrich@dk-develop.de>
References: <20220211212258.80345-4-danilokrummrich@dk-develop.de>
TO: Danilo Krummrich <danilokrummrich@dk-develop.de>
TO: dmitry.torokhov(a)gmail.com
TO: linux-input(a)vger.kernel.org
TO: linux-kernel(a)vger.kernel.org
CC: linus.walleij(a)linaro.org
CC: Danilo Krummrich <danilokrummrich@dk-develop.de>
Hi Danilo,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on dtor-input/next]
[also build test WARNING on hid/for-next linux/master linus/master v5.17-rc3 next-20220211]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Danilo-Krummrich/input-ps2-gpio-use-ktime-for-IRQ-timekeeping/20220212-062327
base: https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
:::::: branch date: 12 hours ago
:::::: commit date: 12 hours ago
config: mips-randconfig-c004-20220211 (https://download.01.org/0day-ci/archive/20220212/202202121815.P1KN65lf-lkp(a)intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project c7eb84634519e6497be42f5fe323f9a04ed67127)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install mips cross compiling tool for clang build
# apt-get install binutils-mips-linux-gnu
# https://github.com/0day-ci/linux/commit/01c1b8646b0bd235aef95354f4852676493ac784
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Danilo-Krummrich/input-ps2-gpio-use-ktime-for-IRQ-timekeeping/20220212-062327
git checkout 01c1b8646b0bd235aef95354f4852676493ac784
# save the config file to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips clang-analyzer
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
clang-analyzer warnings: (new ones prefixed by >>)
drivers/extcon/extcon-fsa9480.c:281:2: note: Taking false branch
if (IS_ERR(info->edev)) {
^
drivers/extcon/extcon-fsa9480.c:288:6: note: Assuming 'ret' is 0
if (ret) {
^~~
drivers/extcon/extcon-fsa9480.c:288:2: note: Taking false branch
if (ret) {
^
drivers/extcon/extcon-fsa9480.c:294:2: note: Taking false branch
if (IS_ERR(info->regmap)) {
^
drivers/extcon/extcon-fsa9480.c:316:6: note: Assuming 'ret' is 0
if (ret) {
^~~
drivers/extcon/extcon-fsa9480.c:316:2: note: Taking false branch
if (ret) {
^
drivers/extcon/extcon-fsa9480.c:322:2: note: Calling 'fsa9480_detect_dev'
fsa9480_detect_dev(info);
^~~~~~~~~~~~~~~~~~~~~~~~
drivers/extcon/extcon-fsa9480.c:227:6: note: Assuming 'val1' is >= 0
if (val1 < 0 || val2 < 0) {
^~~~~~~~
drivers/extcon/extcon-fsa9480.c:227:6: note: Left side of '||' is false
drivers/extcon/extcon-fsa9480.c:227:18: note: Assuming 'val2' is >= 0
if (val1 < 0 || val2 < 0) {
^~~~~~~~
drivers/extcon/extcon-fsa9480.c:227:2: note: Taking false branch
if (val1 < 0 || val2 < 0) {
^
drivers/extcon/extcon-fsa9480.c:233:2: note: Loop condition is false. Exiting loop
dev_info(usbsw->dev, "dev1: 0x%x, dev2: 0x%x\n", val1, val2);
^
include/linux/dev_printk.h:150:2: note: expanded from macro 'dev_info'
dev_printk_index_wrap(_dev_info, KERN_INFO, dev, dev_fmt(fmt), ##__VA_ARGS__)
^
include/linux/dev_printk.h:109:3: note: expanded from macro 'dev_printk_index_wrap'
dev_printk_index_emit(level, fmt); \
^
include/linux/dev_printk.h:105:2: note: expanded from macro 'dev_printk_index_emit'
printk_index_subsys_emit("%s %s: ", level, fmt)
^
include/linux/printk.h:417:2: note: expanded from macro 'printk_index_subsys_emit'
__printk_index_emit(fmt, level, subsys_fmt_prefix)
^
include/linux/printk.h:396:34: note: expanded from macro '__printk_index_emit'
#define __printk_index_emit(...) do {} while (0)
^
drivers/extcon/extcon-fsa9480.c:236:2: note: Calling 'fsa9480_handle_change'
fsa9480_handle_change(usbsw, usbsw->cable & ~val, false);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/extcon/extcon-fsa9480.c:205:2: note: Loop condition is true. Entering loop body
while (mask) {
^
drivers/extcon/extcon-fsa9480.c:206:3: note: 'dev' initialized to 63
int dev = fls64(mask) - 1;
^~~~~~~
drivers/extcon/extcon-fsa9480.c:207:3: note: Assigned value is garbage or undefined
u64 cables = cable_types[dev];
^ ~~~~~~~~~~~~~~~~
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
7 warnings generated.
fs/configfs/symlink.c:70:3: warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
strcpy(s,"../");
^~~~~~
fs/configfs/symlink.c:70:3: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
strcpy(s,"../");
^~~~~~
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
9 warnings generated.
fs/xfs/libxfs/xfs_refcount.c:114:19: warning: Value stored to 'agno' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
xfs_agnumber_t agno = cur->bc_ag.pag->pag_agno;
^~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
fs/xfs/libxfs/xfs_refcount.c:114:19: note: Value stored to 'agno' during its initialization is never read
xfs_agnumber_t agno = cur->bc_ag.pag->pag_agno;
^~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
Suppressed 8 warnings (8 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
8 warnings generated.
Suppressed 8 warnings (8 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
8 warnings generated.
Suppressed 8 warnings (8 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
8 warnings generated.
Suppressed 8 warnings (8 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
8 warnings generated.
Suppressed 8 warnings (8 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
8 warnings generated.
Suppressed 8 warnings (8 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
7 warnings generated.
>> drivers/input/serio/ps2-gpio.c:215:4: warning: Value stored to 'rxflags' is never read [clang-analyzer-deadcode.DeadStores]
rxflags |= SERIO_PARITY;
^
drivers/input/serio/ps2-gpio.c:215:4: note: Value stored to 'rxflags' is never read
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
7 warnings generated.
fs/sysv/dir.c:339:2: warning: Value stored to 'err' is never read [clang-analyzer-deadcode.DeadStores]
err = dir_commit_chunk(page, pos, SYSV_DIRSIZE);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/sysv/dir.c:339:2: note: Value stored to 'err' is never read
err = dir_commit_chunk(page, pos, SYSV_DIRSIZE);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
7 warnings generated.
drivers/usb/serial/usb_wwan.c:151:2: warning: Value stored to 'i' is never read [clang-analyzer-deadcode.DeadStores]
i = 0;
^ ~
drivers/usb/serial/usb_wwan.c:151:2: note: Value stored to 'i' is never read
i = 0;
^ ~
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
8 warnings generated.
Suppressed 8 warnings (8 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
8 warnings generated.
Suppressed 8 warnings (8 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
4 warnings generated.
Suppressed 4 warnings (4 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
5 warnings generated.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
5 warnings generated.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
1 warning generated.
Suppressed 1 warnings (1 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
5 warnings generated.
Suppressed 5 warnings (5 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
13 warnings generated.
Suppressed 13 warnings (13 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
6 warnings generated.
Suppressed 6 warnings (6 in non-user code).
vim +/rxflags +215 drivers/input/serio/ps2-gpio.c
9ee0a0558819e6 Danilo Krummrich 2017-08-28 151
9ee0a0558819e6 Danilo Krummrich 2017-08-28 152 static irqreturn_t ps2_gpio_irq_rx(struct ps2_gpio_data *drvdata)
9ee0a0558819e6 Danilo Krummrich 2017-08-28 153 {
9ee0a0558819e6 Danilo Krummrich 2017-08-28 154 unsigned char byte, cnt;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 155 int data;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 156 int rxflags = 0;
dc1a5808b83032 Danilo Krummrich 2022-02-11 157 static ktime_t t_last, t_now;
dc1a5808b83032 Danilo Krummrich 2022-02-11 158 s64 us_delta;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 159
9ee0a0558819e6 Danilo Krummrich 2017-08-28 160 byte = drvdata->rx_byte;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 161 cnt = drvdata->rx_cnt;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 162
dc1a5808b83032 Danilo Krummrich 2022-02-11 163 t_now = ktime_get();
dc1a5808b83032 Danilo Krummrich 2022-02-11 164 if (t_last == 0)
dc1a5808b83032 Danilo Krummrich 2022-02-11 165 t_last = t_now;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 166
dc1a5808b83032 Danilo Krummrich 2022-02-11 167 /* We need to consider spurious interrupts happening right after a TX xfer
dc1a5808b83032 Danilo Krummrich 2022-02-11 168 * finished.
dc1a5808b83032 Danilo Krummrich 2022-02-11 169 */
dc1a5808b83032 Danilo Krummrich 2022-02-11 170 if (unlikely(ktime_us_delta(t_now, drvdata->tx_end) <
dc1a5808b83032 Danilo Krummrich 2022-02-11 171 PS2_IRQ_MIN_INTERVAL_US))
dc1a5808b83032 Danilo Krummrich 2022-02-11 172 goto end;
dc1a5808b83032 Danilo Krummrich 2022-02-11 173
dc1a5808b83032 Danilo Krummrich 2022-02-11 174 us_delta = ktime_us_delta(t_now, t_last);
dc1a5808b83032 Danilo Krummrich 2022-02-11 175 if (us_delta > PS2_IRQ_MAX_INTERVAL_US && cnt) {
9ee0a0558819e6 Danilo Krummrich 2017-08-28 176 dev_err(drvdata->dev,
9ee0a0558819e6 Danilo Krummrich 2017-08-28 177 "RX: timeout, probably we missed an interrupt\n");
9ee0a0558819e6 Danilo Krummrich 2017-08-28 178 goto err;
dc1a5808b83032 Danilo Krummrich 2022-02-11 179 } else if (us_delta < PS2_IRQ_MIN_INTERVAL_US && t_now != t_last) {
dc1a5808b83032 Danilo Krummrich 2022-02-11 180 /* Ignore spurious IRQs. */
dc1a5808b83032 Danilo Krummrich 2022-02-11 181 goto end;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 182 }
dc1a5808b83032 Danilo Krummrich 2022-02-11 183 t_last = t_now;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 184
9ee0a0558819e6 Danilo Krummrich 2017-08-28 185 data = gpiod_get_value(drvdata->gpio_data);
9ee0a0558819e6 Danilo Krummrich 2017-08-28 186 if (unlikely(data < 0)) {
9ee0a0558819e6 Danilo Krummrich 2017-08-28 187 dev_err(drvdata->dev, "RX: failed to get data gpio val: %d\n",
9ee0a0558819e6 Danilo Krummrich 2017-08-28 188 data);
9ee0a0558819e6 Danilo Krummrich 2017-08-28 189 goto err;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 190 }
9ee0a0558819e6 Danilo Krummrich 2017-08-28 191
9ee0a0558819e6 Danilo Krummrich 2017-08-28 192 switch (cnt) {
9ee0a0558819e6 Danilo Krummrich 2017-08-28 193 case PS2_START_BIT:
9ee0a0558819e6 Danilo Krummrich 2017-08-28 194 /* start bit should be low */
9ee0a0558819e6 Danilo Krummrich 2017-08-28 195 if (unlikely(data)) {
9ee0a0558819e6 Danilo Krummrich 2017-08-28 196 dev_err(drvdata->dev, "RX: start bit should be low\n");
9ee0a0558819e6 Danilo Krummrich 2017-08-28 197 goto err;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 198 }
9ee0a0558819e6 Danilo Krummrich 2017-08-28 199 break;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 200 case PS2_DATA_BIT0:
9ee0a0558819e6 Danilo Krummrich 2017-08-28 201 case PS2_DATA_BIT1:
9ee0a0558819e6 Danilo Krummrich 2017-08-28 202 case PS2_DATA_BIT2:
9ee0a0558819e6 Danilo Krummrich 2017-08-28 203 case PS2_DATA_BIT3:
9ee0a0558819e6 Danilo Krummrich 2017-08-28 204 case PS2_DATA_BIT4:
9ee0a0558819e6 Danilo Krummrich 2017-08-28 205 case PS2_DATA_BIT5:
9ee0a0558819e6 Danilo Krummrich 2017-08-28 206 case PS2_DATA_BIT6:
9ee0a0558819e6 Danilo Krummrich 2017-08-28 207 case PS2_DATA_BIT7:
9ee0a0558819e6 Danilo Krummrich 2017-08-28 208 /* processing data bits */
9ee0a0558819e6 Danilo Krummrich 2017-08-28 209 if (data)
9ee0a0558819e6 Danilo Krummrich 2017-08-28 210 byte |= (data << (cnt - 1));
9ee0a0558819e6 Danilo Krummrich 2017-08-28 211 break;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 212 case PS2_PARITY_BIT:
9ee0a0558819e6 Danilo Krummrich 2017-08-28 213 /* check odd parity */
9ee0a0558819e6 Danilo Krummrich 2017-08-28 214 if (!((hweight8(byte) & 1) ^ data)) {
9ee0a0558819e6 Danilo Krummrich 2017-08-28 @215 rxflags |= SERIO_PARITY;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 216 dev_warn(drvdata->dev, "RX: parity error\n");
9ee0a0558819e6 Danilo Krummrich 2017-08-28 217 if (!drvdata->write_enable)
9ee0a0558819e6 Danilo Krummrich 2017-08-28 218 goto err;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 219 }
01c1b8646b0bd2 Danilo Krummrich 2022-02-11 220 break;
01c1b8646b0bd2 Danilo Krummrich 2022-02-11 221 case PS2_STOP_BIT:
01c1b8646b0bd2 Danilo Krummrich 2022-02-11 222 /* stop bit should be high */
01c1b8646b0bd2 Danilo Krummrich 2022-02-11 223 if (unlikely(!data)) {
01c1b8646b0bd2 Danilo Krummrich 2022-02-11 224 dev_err(drvdata->dev, "RX: stop bit should be high\n");
01c1b8646b0bd2 Danilo Krummrich 2022-02-11 225 goto err;
01c1b8646b0bd2 Danilo Krummrich 2022-02-11 226 }
9ee0a0558819e6 Danilo Krummrich 2017-08-28 227
9ee0a0558819e6 Danilo Krummrich 2017-08-28 228 /* Do not send spurious ACK's and NACK's when write fn is
9ee0a0558819e6 Danilo Krummrich 2017-08-28 229 * not provided.
9ee0a0558819e6 Danilo Krummrich 2017-08-28 230 */
9ee0a0558819e6 Danilo Krummrich 2017-08-28 231 if (!drvdata->write_enable) {
9ee0a0558819e6 Danilo Krummrich 2017-08-28 232 if (byte == PS2_DEV_RET_NACK)
9ee0a0558819e6 Danilo Krummrich 2017-08-28 233 goto err;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 234 else if (byte == PS2_DEV_RET_ACK)
9ee0a0558819e6 Danilo Krummrich 2017-08-28 235 break;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 236 }
9ee0a0558819e6 Danilo Krummrich 2017-08-28 237
9ee0a0558819e6 Danilo Krummrich 2017-08-28 238 serio_interrupt(drvdata->serio, byte, rxflags);
9ee0a0558819e6 Danilo Krummrich 2017-08-28 239 dev_dbg(drvdata->dev, "RX: sending byte 0x%x\n", byte);
01c1b8646b0bd2 Danilo Krummrich 2022-02-11 240
9ee0a0558819e6 Danilo Krummrich 2017-08-28 241 cnt = byte = 0;
dc1a5808b83032 Danilo Krummrich 2022-02-11 242
9ee0a0558819e6 Danilo Krummrich 2017-08-28 243 goto end; /* success */
9ee0a0558819e6 Danilo Krummrich 2017-08-28 244 default:
9ee0a0558819e6 Danilo Krummrich 2017-08-28 245 dev_err(drvdata->dev, "RX: got out of sync with the device\n");
9ee0a0558819e6 Danilo Krummrich 2017-08-28 246 goto err;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 247 }
9ee0a0558819e6 Danilo Krummrich 2017-08-28 248
9ee0a0558819e6 Danilo Krummrich 2017-08-28 249 cnt++;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 250 goto end; /* success */
9ee0a0558819e6 Danilo Krummrich 2017-08-28 251
9ee0a0558819e6 Danilo Krummrich 2017-08-28 252 err:
9ee0a0558819e6 Danilo Krummrich 2017-08-28 253 cnt = byte = 0;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 254 __ps2_gpio_write(drvdata->serio, PS2_CMD_RESEND);
9ee0a0558819e6 Danilo Krummrich 2017-08-28 255 end:
9ee0a0558819e6 Danilo Krummrich 2017-08-28 256 drvdata->rx_cnt = cnt;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 257 drvdata->rx_byte = byte;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 258 return IRQ_HANDLED;
9ee0a0558819e6 Danilo Krummrich 2017-08-28 259 }
9ee0a0558819e6 Danilo Krummrich 2017-08-28 260
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-02-15 12:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-11 21:22 input: ps2-gpio: use ktime for IRQ timekeeping Danilo Krummrich
2022-02-11 21:22 ` [PATCH 1/3] " Danilo Krummrich
2022-02-15 6:14 ` Dmitry Torokhov
2022-02-15 12:09 ` Danilo Krummrich
2022-02-11 21:22 ` [PATCH 2/3] input: ps2-gpio: remove tx timeout from ps2_gpio_irq_tx() Danilo Krummrich
2022-02-11 21:22 ` [PATCH 3/3] input: ps2-gpio: don't send rx data before the stop bit Danilo Krummrich
-- strict thread matches above, loose matches on Subject: below --
2022-02-12 10:39 kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.