diff mbox series

[v3,1/2] input: touch: eeti: move ISR code to own function

Message ID 20190429063038.17773-1-daniel@zonque.org (mailing list archive)
State Superseded
Headers show
Series [v3,1/2] input: touch: eeti: move ISR code to own function | expand

Commit Message

Daniel Mack April 29, 2019, 6:30 a.m. UTC
Move the ISR handling code to its own function and change the logic to bail
immediately in case of .running is false or if the attn_gpio is available
but unasserted.

This allows us to call the function at any time to check for the state of
attn_gpio.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
v3: break out at the end of the loop for setups with !eeti->attn_gpio

 drivers/input/touchscreen/eeti_ts.c | 33 ++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 10 deletions(-)

Comments

Dmitry Torokhov April 29, 2019, 7:30 a.m. UTC | #1
On Mon, Apr 29, 2019 at 08:30:37AM +0200, Daniel Mack wrote:
> Move the ISR handling code to its own function and change the logic to bail
> immediately in case of .running is false or if the attn_gpio is available
> but unasserted.
> 
> This allows us to call the function at any time to check for the state of
> attn_gpio.
> 
> Signed-off-by: Daniel Mack <daniel@zonque.org>
> ---
> v3: break out at the end of the loop for setups with !eeti->attn_gpio
> 
>  drivers/input/touchscreen/eeti_ts.c | 33 ++++++++++++++++++++---------
>  1 file changed, 23 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/eeti_ts.c b/drivers/input/touchscreen/eeti_ts.c
> index 7fe41965c5d1..67c54413ad2b 100644
> --- a/drivers/input/touchscreen/eeti_ts.c
> +++ b/drivers/input/touchscreen/eeti_ts.c
> @@ -75,14 +75,19 @@ static void eeti_ts_report_event(struct eeti_ts *eeti, u8 *buf)
>  	input_sync(eeti->input);
>  }
>  
> -static irqreturn_t eeti_ts_isr(int irq, void *dev_id)
> +static void eeti_ts_read(struct eeti_ts *eeti)
>  {
> -	struct eeti_ts *eeti = dev_id;
> -	int len;
> -	int error;
> +	int len, error;
>  	char buf[6];
>  
> -	do {
> +	for (;;) {
> +		if (!eeti->running)
> +			break;
> +
> +		if (eeti->attn_gpio &&
> +		    gpiod_get_value_cansleep(eeti->attn_gpio) == 0)
> +			break;
> +

This became a bit messy IMO. Maybe we should define eeti_ts_read as only
the code below (up to while) and from resume do:

	if (!eeti->attn_gpio || gpiod_get_value_cansleep(eeti->attn_gpio))
		eeti_ts_read(eeti);

>  		len = i2c_master_recv(eeti->client, buf, sizeof(buf));
>  		if (len != sizeof(buf)) {
>  			error = len < 0 ? len : -EIO;
> @@ -92,12 +97,20 @@ static irqreturn_t eeti_ts_isr(int irq, void *dev_id)
>  			break;
>  		}
>  
> -		if (buf[0] & 0x80) {
> -			/* Motion packet */
> +		/* Motion packet */
> +		if (buf[0] & 0x80)
>  			eeti_ts_report_event(eeti, buf);
> -		}
> -	} while (eeti->running &&
> -		 eeti->attn_gpio && gpiod_get_value_cansleep(eeti->attn_gpio));
> +
> +		if (!eeti->attn_gpio)
> +			break;
> +	}
> +}
> +
> +static irqreturn_t eeti_ts_isr(int irq, void *dev_id)
> +{
> +	struct eeti_ts *eeti = dev_id;
> +
> +	eeti_ts_read(eeti);
>  
>  	return IRQ_HANDLED;
>  }
> -- 
> 2.20.1
> 

Thanks.
Daniel Mack April 29, 2019, 3:23 p.m. UTC | #2
On 29/4/2019 9:30 AM, Dmitry Torokhov wrote:
> On Mon, Apr 29, 2019 at 08:30:37AM +0200, Daniel Mack wrote:
>> Move the ISR handling code to its own function and change the logic to bail
>> immediately in case of .running is false or if the attn_gpio is available
>> but unasserted.
>>
>> This allows us to call the function at any time to check for the state of
>> attn_gpio.
>>
>> Signed-off-by: Daniel Mack <daniel@zonque.org>
>> ---
>> v3: break out at the end of the loop for setups with !eeti->attn_gpio
>>
>>  drivers/input/touchscreen/eeti_ts.c | 33 ++++++++++++++++++++---------
>>  1 file changed, 23 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/input/touchscreen/eeti_ts.c b/drivers/input/touchscreen/eeti_ts.c
>> index 7fe41965c5d1..67c54413ad2b 100644
>> --- a/drivers/input/touchscreen/eeti_ts.c
>> +++ b/drivers/input/touchscreen/eeti_ts.c
>> @@ -75,14 +75,19 @@ static void eeti_ts_report_event(struct eeti_ts *eeti, u8 *buf)
>>  	input_sync(eeti->input);
>>  }
>>  
>> -static irqreturn_t eeti_ts_isr(int irq, void *dev_id)
>> +static void eeti_ts_read(struct eeti_ts *eeti)
>>  {
>> -	struct eeti_ts *eeti = dev_id;
>> -	int len;
>> -	int error;
>> +	int len, error;
>>  	char buf[6];
>>  
>> -	do {
>> +	for (;;) {
>> +		if (!eeti->running)
>> +			break;
>> +
>> +		if (eeti->attn_gpio &&
>> +		    gpiod_get_value_cansleep(eeti->attn_gpio) == 0)
>> +			break;
>> +
> 
> This became a bit messy IMO. Maybe we should define eeti_ts_read as only
> the code below (up to while) and from resume do:

You're right, that's cleaner. v4 coming up.

Thanks again!
Daniel
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/eeti_ts.c b/drivers/input/touchscreen/eeti_ts.c
index 7fe41965c5d1..67c54413ad2b 100644
--- a/drivers/input/touchscreen/eeti_ts.c
+++ b/drivers/input/touchscreen/eeti_ts.c
@@ -75,14 +75,19 @@  static void eeti_ts_report_event(struct eeti_ts *eeti, u8 *buf)
 	input_sync(eeti->input);
 }
 
-static irqreturn_t eeti_ts_isr(int irq, void *dev_id)
+static void eeti_ts_read(struct eeti_ts *eeti)
 {
-	struct eeti_ts *eeti = dev_id;
-	int len;
-	int error;
+	int len, error;
 	char buf[6];
 
-	do {
+	for (;;) {
+		if (!eeti->running)
+			break;
+
+		if (eeti->attn_gpio &&
+		    gpiod_get_value_cansleep(eeti->attn_gpio) == 0)
+			break;
+
 		len = i2c_master_recv(eeti->client, buf, sizeof(buf));
 		if (len != sizeof(buf)) {
 			error = len < 0 ? len : -EIO;
@@ -92,12 +97,20 @@  static irqreturn_t eeti_ts_isr(int irq, void *dev_id)
 			break;
 		}
 
-		if (buf[0] & 0x80) {
-			/* Motion packet */
+		/* Motion packet */
+		if (buf[0] & 0x80)
 			eeti_ts_report_event(eeti, buf);
-		}
-	} while (eeti->running &&
-		 eeti->attn_gpio && gpiod_get_value_cansleep(eeti->attn_gpio));
+
+		if (!eeti->attn_gpio)
+			break;
+	}
+}
+
+static irqreturn_t eeti_ts_isr(int irq, void *dev_id)
+{
+	struct eeti_ts *eeti = dev_id;
+
+	eeti_ts_read(eeti);
 
 	return IRQ_HANDLED;
 }