Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1632068 > unrolled thread

[PATCH 1/2] input: touchscreen: ar1021_i2c: enable touch mode during open

Started byMartin Kepplinger <martin.kepplinger@ginzinger.com>
First post2017-04-27 14:30 +0200
Last post2017-04-28 19:10 +0200
Articles 6 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/2] input: touchscreen: ar1021_i2c: enable touch mode during open Martin Kepplinger <martin.kepplinger@ginzinger.com> - 2017-04-27 14:30 +0200
    [PATCH 2/2] input: touchscreen: ar1021_i2c: replace magic number with definition Martin Kepplinger <martin.kepplinger@ginzinger.com> - 2017-04-27 14:30 +0200
      Re: [PATCH 2/2] input: touchscreen: ar1021_i2c: replace magic number  with definition Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-04-28 19:10 +0200
      [PATCH 2/2 v2] input: touchscreen: ar1021_i2c: use BIT to check for a bit Martin Kepplinger <martink@posteo.de> - 2017-04-30 21:40 +0200
        Re: [PATCH 2/2 v2] input: touchscreen: ar1021_i2c: use BIT to check  for a bit Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-05-01 21:40 +0200
    Re: [PATCH 1/2] input: touchscreen: ar1021_i2c: enable touch mode  during open Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-04-28 19:10 +0200

#1632068 — [PATCH 1/2] input: touchscreen: ar1021_i2c: enable touch mode during open

FromMartin Kepplinger <martin.kepplinger@ginzinger.com>
Date2017-04-27 14:30 +0200
Subject[PATCH 1/2] input: touchscreen: ar1021_i2c: enable touch mode during open
Message-ID<tAQIx-xM-5@gated-at.bofh.it>
The device could as well be in command mode, in which this driver cannot
handle the device. When opening the device, let's make sure the device
will be in the mode we expect it to be for this driver.

Signed-off-by: Martin Kepplinger <martin.kepplinger@ginzinger.com>
---
 drivers/input/touchscreen/ar1021_i2c.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/input/touchscreen/ar1021_i2c.c b/drivers/input/touchscreen/ar1021_i2c.c
index 1a94d8b..2a76231 100644
--- a/drivers/input/touchscreen/ar1021_i2c.c
+++ b/drivers/input/touchscreen/ar1021_i2c.c
@@ -18,6 +18,12 @@
 #define AR1021_MAX_X	4095
 #define AR1021_MAX_Y	4095
 
+#define AR1021_CMD	0x55
+#define AR1021_TOUCH	0x80
+
+#define AR1021_CMD_ENABLE_TOUCH		0x12
+#define AR1021_CMD_DISABLE_TOUCH	0x13
+
 struct ar1021_i2c {
 	struct i2c_client *client;
 	struct input_dev *input;
@@ -58,6 +64,15 @@ static int ar1021_i2c_open(struct input_dev *dev)
 {
 	struct ar1021_i2c *ar1021 = input_get_drvdata(dev);
 	struct i2c_client *client = ar1021->client;
+	int error;
+	u8 cmd_enable_touch[3] = {AR1021_CMD,
+				  0x01, /* number of bytes after this */
+				  AR1021_CMD_ENABLE_TOUCH };
+
+	error = i2c_master_send(ar1021->client, cmd_enable_touch,
+				sizeof(cmd_enable_touch));
+	if (error < 0)
+		return error;
 
 	enable_irq(client->irq);
 
-- 
2.1.4

[toc] | [next] | [standalone]


#1632070 — [PATCH 2/2] input: touchscreen: ar1021_i2c: replace magic number with definition

FromMartin Kepplinger <martin.kepplinger@ginzinger.com>
Date2017-04-27 14:30 +0200
Subject[PATCH 2/2] input: touchscreen: ar1021_i2c: replace magic number with definition
Message-ID<tAQIy-xM-15@gated-at.bofh.it>
In reply to#1632068
We now have a few of this device's definitions. Let's avoid magic numbers
and use them.

Signed-off-by: Martin Kepplinger <martin.kepplinger@ginzinger.com>
---
 drivers/input/touchscreen/ar1021_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/ar1021_i2c.c b/drivers/input/touchscreen/ar1021_i2c.c
index 2a76231..edd5268 100644
--- a/drivers/input/touchscreen/ar1021_i2c.c
+++ b/drivers/input/touchscreen/ar1021_i2c.c
@@ -44,7 +44,7 @@ static irqreturn_t ar1021_i2c_irq(int irq, void *dev_id)
 		goto out;
 
 	/* sync bit set ? */
-	if ((data[0] & 0x80) == 0)
+	if ((data[0] & AR1021_TOUCH) == 0)
 		goto out;
 
 	button = data[0] & BIT(0);
-- 
2.1.4

[toc] | [prev] | [next] | [standalone]


#1633033 — Re: [PATCH 2/2] input: touchscreen: ar1021_i2c: replace magic number with definition

FromDmitry Torokhov <dmitry.torokhov@gmail.com>
Date2017-04-28 19:10 +0200
SubjectRe: [PATCH 2/2] input: touchscreen: ar1021_i2c: replace magic number with definition
Message-ID<tBhz4-1Yt-23@gated-at.bofh.it>
In reply to#1632070
On Thu, Apr 27, 2017 at 02:22:36PM +0200, Martin Kepplinger wrote:
> We now have a few of this device's definitions. Let's avoid magic numbers
> and use them.
> 
> Signed-off-by: Martin Kepplinger <martin.kepplinger@ginzinger.com>
> ---
>  drivers/input/touchscreen/ar1021_i2c.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/input/touchscreen/ar1021_i2c.c b/drivers/input/touchscreen/ar1021_i2c.c
> index 2a76231..edd5268 100644
> --- a/drivers/input/touchscreen/ar1021_i2c.c
> +++ b/drivers/input/touchscreen/ar1021_i2c.c
> @@ -44,7 +44,7 @@ static irqreturn_t ar1021_i2c_irq(int irq, void *dev_id)
>  		goto out;
>  
>  	/* sync bit set ? */
> -	if ((data[0] & 0x80) == 0)
> +	if ((data[0] & AR1021_TOUCH) == 0)

I'd rather have it as "(data & BIT(7))". This constant does not provide
any better meaning than number 0x80. At least the latter shows that we
test the MSB or the first byte, while the former obfuscates it.

Thanks.

-- 
Dmitry

[toc] | [prev] | [next] | [standalone]


#1633485 — [PATCH 2/2 v2] input: touchscreen: ar1021_i2c: use BIT to check for a bit

FromMartin Kepplinger <martink@posteo.de>
Date2017-04-30 21:40 +0200
Subject[PATCH 2/2 v2] input: touchscreen: ar1021_i2c: use BIT to check for a bit
Message-ID<tC2Rj-7gG-3@gated-at.bofh.it>
In reply to#1632070
The MSB for the first byte of touch data transmission is always 1. Make
it a little more obvious we're testing this bit by using BIT(7).

Signed-off-by: Martin Kepplinger <martink@posteo.de>
---

I'd still use the definition :) but otherwise I'd write the following.
It really doesn't matter though.

thanks for the quick support Dmitry,

                    martin


 drivers/input/touchscreen/ar1021_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/ar1021_i2c.c b/drivers/input/touchscreen/ar1021_i2c.c
index eb1874fe52c2..8c76aa435903 100644
--- a/drivers/input/touchscreen/ar1021_i2c.c
+++ b/drivers/input/touchscreen/ar1021_i2c.c
@@ -44,7 +44,7 @@ static irqreturn_t ar1021_i2c_irq(int irq, void *dev_id)
 		goto out;
 
 	/* sync bit set ? */
-	if ((data[0] & 0x80) == 0)
+	if (!(data[0] & BIT(7)))
 		goto out;
 
 	button = data[0] & BIT(0);
-- 
2.11.0

[toc] | [prev] | [next] | [standalone]


#1633829 — Re: [PATCH 2/2 v2] input: touchscreen: ar1021_i2c: use BIT to check for a bit

FromDmitry Torokhov <dmitry.torokhov@gmail.com>
Date2017-05-01 21:40 +0200
SubjectRe: [PATCH 2/2 v2] input: touchscreen: ar1021_i2c: use BIT to check for a bit
Message-ID<tCpkS-4KF-17@gated-at.bofh.it>
In reply to#1633485
On Sun, Apr 30, 2017 at 09:38:53PM +0200, Martin Kepplinger wrote:
> The MSB for the first byte of touch data transmission is always 1. Make
> it a little more obvious we're testing this bit by using BIT(7).
> 
> Signed-off-by: Martin Kepplinger <martink@posteo.de>

Applied, thank you.

> ---
> 
> I'd still use the definition :) but otherwise I'd write the following.
> It really doesn't matter though.
> 
> thanks for the quick support Dmitry,
> 
>                     martin
> 
> 
>  drivers/input/touchscreen/ar1021_i2c.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/input/touchscreen/ar1021_i2c.c b/drivers/input/touchscreen/ar1021_i2c.c
> index eb1874fe52c2..8c76aa435903 100644
> --- a/drivers/input/touchscreen/ar1021_i2c.c
> +++ b/drivers/input/touchscreen/ar1021_i2c.c
> @@ -44,7 +44,7 @@ static irqreturn_t ar1021_i2c_irq(int irq, void *dev_id)
>  		goto out;
>  
>  	/* sync bit set ? */
> -	if ((data[0] & 0x80) == 0)
> +	if (!(data[0] & BIT(7)))
>  		goto out;
>  
>  	button = data[0] & BIT(0);
> -- 
> 2.11.0
> 

-- 
Dmitry

[toc] | [prev] | [next] | [standalone]


#1633030 — Re: [PATCH 1/2] input: touchscreen: ar1021_i2c: enable touch mode during open

FromDmitry Torokhov <dmitry.torokhov@gmail.com>
Date2017-04-28 19:10 +0200
SubjectRe: [PATCH 1/2] input: touchscreen: ar1021_i2c: enable touch mode during open
Message-ID<tBhz3-1Yt-11@gated-at.bofh.it>
In reply to#1632068
On Thu, Apr 27, 2017 at 02:22:35PM +0200, Martin Kepplinger wrote:
> The device could as well be in command mode, in which this driver cannot
> handle the device. When opening the device, let's make sure the device
> will be in the mode we expect it to be for this driver.
> 
> Signed-off-by: Martin Kepplinger <martin.kepplinger@ginzinger.com>
> ---
>  drivers/input/touchscreen/ar1021_i2c.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/drivers/input/touchscreen/ar1021_i2c.c b/drivers/input/touchscreen/ar1021_i2c.c
> index 1a94d8b..2a76231 100644
> --- a/drivers/input/touchscreen/ar1021_i2c.c
> +++ b/drivers/input/touchscreen/ar1021_i2c.c
> @@ -18,6 +18,12 @@
>  #define AR1021_MAX_X	4095
>  #define AR1021_MAX_Y	4095
>  
> +#define AR1021_CMD	0x55
> +#define AR1021_TOUCH	0x80
> +
> +#define AR1021_CMD_ENABLE_TOUCH		0x12
> +#define AR1021_CMD_DISABLE_TOUCH	0x13
> +
>  struct ar1021_i2c {
>  	struct i2c_client *client;
>  	struct input_dev *input;
> @@ -58,6 +64,15 @@ static int ar1021_i2c_open(struct input_dev *dev)
>  {
>  	struct ar1021_i2c *ar1021 = input_get_drvdata(dev);
>  	struct i2c_client *client = ar1021->client;
> +	int error;
> +	u8 cmd_enable_touch[3] = {AR1021_CMD,
> +				  0x01, /* number of bytes after this */
> +				  AR1021_CMD_ENABLE_TOUCH };

Changed to static const and applied, thank you.

> +
> +	error = i2c_master_send(ar1021->client, cmd_enable_touch,
> +				sizeof(cmd_enable_touch));
> +	if (error < 0)
> +		return error;
>  
>  	enable_irq(client->irq);
>  
> -- 
> 2.1.4
> 

-- 
Dmitry

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web