linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
Cc: Dmitry Osipenko <digetx@gmail.com>,
	Henrik Rydberg <rydberg@bitmath.org>,
	James Chen <james.chen@emc.com.tw>,
	Johnny Chuang <johnny.chuang@emc.com.tw>,
	Rob Herring <robh+dt@kernel.org>,
	Scott Liu <scott.liu@emc.com.tw>,
	David Heidelberg <david@ixit.cz>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 5/9] input: elants: refactor elants_i2c_execute_command()
Date: Sat, 25 Apr 2020 22:08:47 -0700	[thread overview]
Message-ID: <20200426050847.GO125362@dtor-ws> (raw)
In-Reply-To: <934e4ed8808de930f7380ce50cb3063c4039514e.1586784389.git.mirq-linux@rere.qmqm.pl>

On Mon, Apr 13, 2020 at 03:32:24PM +0200, Michał Mirosław wrote:
> Apply some DRY-ing to elants_i2c_execute_command() callers.  This pulls
> polling and error printk()s into a single function.
> 
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---
>  drivers/input/touchscreen/elants_i2c.c | 189 +++++++++++++------------
>  1 file changed, 96 insertions(+), 93 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
> index 87d686ce08f2..b0f083f7f2a9 100644
> --- a/drivers/input/touchscreen/elants_i2c.c
> +++ b/drivers/input/touchscreen/elants_i2c.c
> @@ -205,7 +205,8 @@ static int elants_i2c_read(struct i2c_client *client, void *data, size_t size)
>  
>  static int elants_i2c_execute_command(struct i2c_client *client,
>  				      const u8 *cmd, size_t cmd_size,
> -				      u8 *resp, size_t resp_size)
> +				      u8 *resp, size_t resp_size,
> +				      int retries, const char *cmd_name)
>  {
>  	struct i2c_msg msgs[2];
>  	int ret;
> @@ -225,30 +226,55 @@ static int elants_i2c_execute_command(struct i2c_client *client,
>  		break;
>  
>  	default:
> -		dev_err(&client->dev, "%s: invalid command %*ph\n",
> -			__func__, (int)cmd_size, cmd);
> +		dev_err(&client->dev, "(%s): invalid command: %*ph\n",
> +			cmd_name, (int)cmd_size, cmd);
>  		return -EINVAL;
>  	}
>  
> -	msgs[0].addr = client->addr;
> -	msgs[0].flags = client->flags & I2C_M_TEN;
> -	msgs[0].len = cmd_size;
> -	msgs[0].buf = (u8 *)cmd;
> +	for (;;) {
> +		msgs[0].addr = client->addr;
> +		msgs[0].flags = client->flags & I2C_M_TEN;
> +		msgs[0].len = cmd_size;
> +		msgs[0].buf = (u8 *)cmd;
>  
> -	msgs[1].addr = client->addr;
> -	msgs[1].flags = client->flags & I2C_M_TEN;
> -	msgs[1].flags |= I2C_M_RD;
> -	msgs[1].len = resp_size;
> -	msgs[1].buf = resp;
> +		msgs[1].addr = client->addr;
> +		msgs[1].flags = client->flags & I2C_M_TEN;
> +		msgs[1].flags |= I2C_M_RD;
> +		msgs[1].len = resp_size;
> +		msgs[1].buf = resp;
>  
> -	ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
> -	if (ret < 0)
> -		return ret;
> +		ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
> +		if (ret < 0) {
> +			if (--retries > 0) {
> +				dev_dbg(&client->dev,
> +					"(%s) I2C transfer failed: %d (retrying)\n",
> +					cmd_name, ret);
> +				continue;
> +			}
>  
> -	if (ret != ARRAY_SIZE(msgs) || resp[FW_HDR_TYPE] != expected_response)
> -		return -EIO;
> +			dev_err(&client->dev,
> +				"(%s) I2C transfer failed: %d\n",
> +				cmd_name, ret);
> +			return ret;
> +		}
>  
> -	return 0;
> +		if (ret != ARRAY_SIZE(msgs) ||
> +		    resp[FW_HDR_TYPE] != expected_response) {
> +			if (--retries > 0) {
> +				dev_dbg(&client->dev,
> +					"(%s) unexpected response: %*ph (retrying)\n",
> +					cmd_name, ret, resp);
> +				continue;
> +			}
> +
> +			dev_err(&client->dev,
> +				"(%s) unexpected response: %*ph\n",
> +				cmd_name, ret, resp);
> +			return -EIO;
> +		}
> +
> +		return --retries;

I'd prefer if we returned 0 on success and I'd be OK when flashing
firmware to have separate retry counters for the command themselves and
for checking the response.

Thanks.

-- 
Dmitry

  reply	other threads:[~2020-04-26  5:08 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-13 13:32 [PATCH v3 0/9] input: elants: Support Asus TF300T touchscreen Michał Mirosław
2020-04-13 13:32 ` [PATCH v3 3/9] input: elants: remove unused axes Michał Mirosław
2020-04-26  4:52   ` Dmitry Torokhov
2020-04-26  5:07     ` Dmitry Osipenko
2020-04-26 11:21     ` Michał Mirosław
2020-04-26 15:39       ` Dmitry Osipenko
2020-04-26 15:41         ` Dmitry Osipenko
2020-04-26 16:11           ` Dmitry Osipenko
2020-04-26 16:12           ` Michał Mirosław
2020-04-26 16:14             ` Dmitry Osipenko
2020-04-13 13:32 ` [PATCH v3 2/9] input: elants: support old touch report format Michał Mirosław
2020-04-13 13:32 ` [PATCH v3 1/9] input: elants: document some registers and values Michał Mirosław
2020-04-13 13:32 ` [PATCH v3 4/9] input: elants: override touchscreen info with DT properties Michał Mirosław
2020-04-26  5:11   ` Dmitry Torokhov
2020-04-26  5:12     ` Dmitry Torokhov
2020-04-13 13:32 ` [PATCH v3 5/9] input: elants: refactor elants_i2c_execute_command() Michał Mirosław
2020-04-26  5:08   ` Dmitry Torokhov [this message]
2020-04-13 13:32 ` [PATCH v3 6/9] input: elants: read touchscreen size for EKTF3624 Michał Mirosław
2020-04-26  5:10   ` Dmitry Torokhov
2020-04-13 13:32 ` [PATCH v3 7/9] input: elants: support 0x66 reply opcode for reporting touches Michał Mirosław
2020-04-26  5:15   ` Dmitry Torokhov
2020-04-26  5:21     ` Dmitry Osipenko
2020-04-13 13:32 ` [PATCH v3 8/9] dt-bindings: input: elants-i2c: Document common touchscreen properties Michał Mirosław
2020-04-13 13:32 ` [PATCH v3 9/9] dt-bindings: input: elants-i2c: Document eKTF3624 Michał Mirosław

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200426050847.GO125362@dtor-ws \
    --to=dmitry.torokhov@gmail.com \
    --cc=david@ixit.cz \
    --cc=digetx@gmail.com \
    --cc=james.chen@emc.com.tw \
    --cc=johnny.chuang@emc.com.tw \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mirq-linux@rere.qmqm.pl \
    --cc=robh+dt@kernel.org \
    --cc=rydberg@bitmath.org \
    --cc=scott.liu@emc.com.tw \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).