All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Simek <michal.simek@xilinx.com>
To: ext-jaakko.laine@vaisala.com, wsa@the-dreams.de
Cc: linux-i2c@vger.kernel.org, michal.simek@xilinx.com,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 3/3] i2c: xiic: Support forcing single-master in DT
Date: Thu, 27 Aug 2020 17:57:03 +0200	[thread overview]
Message-ID: <5da57a1d-577f-e532-eaeb-32a1bde5a6ff@xilinx.com> (raw)
In-Reply-To: <20200827144848.12107-4-ext-jaakko.laine@vaisala.com>



On 27. 08. 20 16:48, ext-jaakko.laine@vaisala.com wrote:
> From: Jaakko Laine <ext-jaakko.laine@vaisala.com>
> 
> I2C master operating in multimaster mode can get stuck
> indefinitely if I2C start is detected on bus, but no master
> has a transaction going.
> 
> This is a weakness in I2C standard, which defines no way
> to recover, since all masters are indefinitely disallowed
> from interrupting the currently operating master. A start
> condition can be created for example by an electromagnetic
> discharge applied near physical I2C lines. Or a already
> operating master could get reset immediately after sending
> a start.
> 
> If it is known during device tree creation that only a single
> I2C master will be present on the bus, this deadlock of the
> I2C bus could be avoided in the driver by ignoring the
> bus_is_busy register of the xiic, since bus can never be
> reserved by any other master.
> 
> This patch adds this support for detecting single-master flag
> in device tree and when provided, improves I2C reliability by
> ignoring the therefore unnecessary xiic bus_is_busy register.
> 
> Error can be reproduced by pulling I2C SDA -line temporarily low
> by shorting it to ground, while linux I2C master is operating on
> it using the xiic driver. The application using the bus will
> start receiving linux error code 16: "Device or resource busy"
> indefinitely:
> 
> kernel: pca953x 0-0020: failed writing register
> app: Error writing file, error: 16
> 
> With multi-master disabled device will instead receive error
> code 5: "I/O error" while SDA is grounded, but recover normal
> operation once short is removed.
> 
> kernel: pca953x 0-0020: failed reading register
> app: Error reading file, error: 5
> 
> Signed-off-by: Jaakko Laine <ext-jaakko.laine@vaisala.com>
> ---
>  drivers/i2c/busses/i2c-xiic.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
> index 1453d82bb664..087b2951942e 100644
> --- a/drivers/i2c/busses/i2c-xiic.c
> +++ b/drivers/i2c/busses/i2c-xiic.c
> @@ -59,6 +59,7 @@ enum xiic_endian {
>   * @endianness: big/little-endian byte order
>   * @clk: Pointer to AXI4-lite input clock
>   * @state: See STATE_
> + * @singlemaster: Indicates bus is single master
>   */
>  struct xiic_i2c {
>  	struct device *dev;
> @@ -74,6 +75,7 @@ struct xiic_i2c {
>  	enum xiic_endian endianness;
>  	struct clk *clk;
>  	enum xilinx_i2c_state state;
> +	bool singlemaster;
>  };
>  
>  
> @@ -526,6 +528,15 @@ static int xiic_busy(struct xiic_i2c *i2c)
>  	if (i2c->tx_msg)
>  		return -EBUSY;
>  
> +	/* In single master mode bus can only be busy, when in use by this
> +	 * driver. If the register indicates bus being busy for some reason we
> +	 * should ignore it, since bus will never be released and i2c will be
> +	 * stuck forever.
> +	 */
> +	if (i2c->singlemaster) {
> +		return 0;
> +	}
> +
>  	/* for instance if previous transfer was terminated due to TX error
>  	 * it might be that the bus is on it's way to become available
>  	 * give it at most 3 ms to wake
> @@ -811,6 +822,9 @@ static int xiic_i2c_probe(struct platform_device *pdev)
>  		goto err_clk_dis;
>  	}
>  
> +	i2c->singlemaster =
> +		of_property_read_bool(pdev->dev.of_node, "single-master");
> +
>  	/*
>  	 * Detect endianness
>  	 * Try to reset the TX FIFO. Then check the EMPTY flag. If it is not
> 

Acked-by: Michal Simek <michal.simek@xilinx.com>

Thanks,
Michal

WARNING: multiple messages have this Message-ID (diff)
From: Michal Simek <michal.simek@xilinx.com>
To: ext-jaakko.laine@vaisala.com, wsa@the-dreams.de
Cc: linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	michal.simek@xilinx.com
Subject: Re: [PATCH 3/3] i2c: xiic: Support forcing single-master in DT
Date: Thu, 27 Aug 2020 17:57:03 +0200	[thread overview]
Message-ID: <5da57a1d-577f-e532-eaeb-32a1bde5a6ff@xilinx.com> (raw)
In-Reply-To: <20200827144848.12107-4-ext-jaakko.laine@vaisala.com>



On 27. 08. 20 16:48, ext-jaakko.laine@vaisala.com wrote:
> From: Jaakko Laine <ext-jaakko.laine@vaisala.com>
> 
> I2C master operating in multimaster mode can get stuck
> indefinitely if I2C start is detected on bus, but no master
> has a transaction going.
> 
> This is a weakness in I2C standard, which defines no way
> to recover, since all masters are indefinitely disallowed
> from interrupting the currently operating master. A start
> condition can be created for example by an electromagnetic
> discharge applied near physical I2C lines. Or a already
> operating master could get reset immediately after sending
> a start.
> 
> If it is known during device tree creation that only a single
> I2C master will be present on the bus, this deadlock of the
> I2C bus could be avoided in the driver by ignoring the
> bus_is_busy register of the xiic, since bus can never be
> reserved by any other master.
> 
> This patch adds this support for detecting single-master flag
> in device tree and when provided, improves I2C reliability by
> ignoring the therefore unnecessary xiic bus_is_busy register.
> 
> Error can be reproduced by pulling I2C SDA -line temporarily low
> by shorting it to ground, while linux I2C master is operating on
> it using the xiic driver. The application using the bus will
> start receiving linux error code 16: "Device or resource busy"
> indefinitely:
> 
> kernel: pca953x 0-0020: failed writing register
> app: Error writing file, error: 16
> 
> With multi-master disabled device will instead receive error
> code 5: "I/O error" while SDA is grounded, but recover normal
> operation once short is removed.
> 
> kernel: pca953x 0-0020: failed reading register
> app: Error reading file, error: 5
> 
> Signed-off-by: Jaakko Laine <ext-jaakko.laine@vaisala.com>
> ---
>  drivers/i2c/busses/i2c-xiic.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
> index 1453d82bb664..087b2951942e 100644
> --- a/drivers/i2c/busses/i2c-xiic.c
> +++ b/drivers/i2c/busses/i2c-xiic.c
> @@ -59,6 +59,7 @@ enum xiic_endian {
>   * @endianness: big/little-endian byte order
>   * @clk: Pointer to AXI4-lite input clock
>   * @state: See STATE_
> + * @singlemaster: Indicates bus is single master
>   */
>  struct xiic_i2c {
>  	struct device *dev;
> @@ -74,6 +75,7 @@ struct xiic_i2c {
>  	enum xiic_endian endianness;
>  	struct clk *clk;
>  	enum xilinx_i2c_state state;
> +	bool singlemaster;
>  };
>  
>  
> @@ -526,6 +528,15 @@ static int xiic_busy(struct xiic_i2c *i2c)
>  	if (i2c->tx_msg)
>  		return -EBUSY;
>  
> +	/* In single master mode bus can only be busy, when in use by this
> +	 * driver. If the register indicates bus being busy for some reason we
> +	 * should ignore it, since bus will never be released and i2c will be
> +	 * stuck forever.
> +	 */
> +	if (i2c->singlemaster) {
> +		return 0;
> +	}
> +
>  	/* for instance if previous transfer was terminated due to TX error
>  	 * it might be that the bus is on it's way to become available
>  	 * give it at most 3 ms to wake
> @@ -811,6 +822,9 @@ static int xiic_i2c_probe(struct platform_device *pdev)
>  		goto err_clk_dis;
>  	}
>  
> +	i2c->singlemaster =
> +		of_property_read_bool(pdev->dev.of_node, "single-master");
> +
>  	/*
>  	 * Detect endianness
>  	 * Try to reset the TX FIFO. Then check the EMPTY flag. If it is not
> 

Acked-by: Michal Simek <michal.simek@xilinx.com>

Thanks,
Michal

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-08-27 15:57 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-27 14:48 [PATCH 0/3] i2c: xiic: Support forcing single-master in DT ext-jaakko.laine
2020-08-27 14:48 ` ext-jaakko.laine
2020-08-27 14:48 ` [PATCH 1/3] i2c: xiic: Change code alignment to 1 space only ext-jaakko.laine
2020-08-27 14:48   ` ext-jaakko.laine
2020-08-28  7:02   ` Wolfram Sang
2020-08-28  7:02     ` Wolfram Sang
2020-08-27 14:48 ` [PATCH 2/3] i2c: xiic: Improve struct memory alignment ext-jaakko.laine
2020-08-27 14:48   ` ext-jaakko.laine
2020-08-27 15:56   ` Michal Simek
2020-08-27 15:56     ` Michal Simek
2020-08-28  7:02   ` Wolfram Sang
2020-08-28  7:02     ` Wolfram Sang
2020-08-27 14:48 ` [PATCH 3/3] i2c: xiic: Support forcing single-master in DT ext-jaakko.laine
2020-08-27 14:48   ` ext-jaakko.laine
2020-08-27 15:57   ` Michal Simek [this message]
2020-08-27 15:57     ` Michal Simek
2020-08-28  7:02   ` Wolfram Sang
2020-08-28  7:02     ` Wolfram Sang

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=5da57a1d-577f-e532-eaeb-32a1bde5a6ff@xilinx.com \
    --to=michal.simek@xilinx.com \
    --cc=ext-jaakko.laine@vaisala.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=wsa@the-dreams.de \
    /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 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.