diff mbox series

[v1,1/3] i2c: imx: only poll for bus busy in multi master mode

Message ID 20240715151824.90033-2-eichest@gmail.com (mailing list archive)
State Superseded
Headers show
Series i2c: imx: prevent rescheduling in non-dma mode | expand

Commit Message

Stefan Eichenberger July 15, 2024, 3:17 p.m. UTC
From: Stefan Eichenberger <stefan.eichenberger@toradex.com>

According to the reference manual it is only necessary to poll for bus
busy and arbitration lost in multi master mode. This helps to avoid
rescheduling while the i2c bus is busy and avoids SMBus devices to
timeout.

Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
---
 drivers/i2c/busses/i2c-imx.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Frank Li July 15, 2024, 4:32 p.m. UTC | #1
On Mon, Jul 15, 2024 at 05:17:51PM +0200, Stefan Eichenberger wrote:
> From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> 
> According to the reference manual it is only necessary to poll for bus

I supposed it should be "According to i2c spec",

> busy and arbitration lost in multi master mode. This helps to avoid
> rescheduling while the i2c bus is busy and avoids SMBus devices to
> timeout.
> 

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> ---
>  drivers/i2c/busses/i2c-imx.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 3842e527116b7..1add946e3bc20 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -216,6 +216,8 @@ struct imx_i2c_struct {
>  	struct i2c_client	*slave;
>  	enum i2c_slave_event last_slave_event;
>  
> +	bool			multi_master;
> +
>  	/* For checking slave events. */
>  	spinlock_t     slave_lock;
>  	struct hrtimer slave_timer;
> @@ -481,6 +483,9 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool a
>  	unsigned long orig_jiffies = jiffies;
>  	unsigned int temp;
>  
> +	if (!i2c_imx->multi_master)
> +		return 0;
> +
>  	while (1) {
>  		temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
>  
> @@ -540,8 +545,8 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx, bool atomic)
>  		return -ETIMEDOUT;
>  	}
>  
> -	/* check for arbitration lost */
> -	if (i2c_imx->i2csr & I2SR_IAL) {
> +	/* In multi-master mode check for arbitration lost */
> +	if (i2c_imx->multi_master && (i2c_imx->i2csr & I2SR_IAL)) {
>  		dev_dbg(&i2c_imx->adapter.dev, "<%s> Arbitration lost\n", __func__);
>  		i2c_imx_clear_irq(i2c_imx, I2SR_IAL);
>  
> @@ -1468,6 +1473,8 @@ static int i2c_imx_probe(struct platform_device *pdev)
>  		goto rpm_disable;
>  	}
>  
> +	i2c_imx->multi_master = of_property_read_bool(pdev->dev.of_node, "multi-master");
> +
>  	/* Set up clock divider */
>  	i2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ;
>  	ret = of_property_read_u32(pdev->dev.of_node,
> -- 
> 2.43.0
>
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 3842e527116b7..1add946e3bc20 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -216,6 +216,8 @@  struct imx_i2c_struct {
 	struct i2c_client	*slave;
 	enum i2c_slave_event last_slave_event;
 
+	bool			multi_master;
+
 	/* For checking slave events. */
 	spinlock_t     slave_lock;
 	struct hrtimer slave_timer;
@@ -481,6 +483,9 @@  static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool a
 	unsigned long orig_jiffies = jiffies;
 	unsigned int temp;
 
+	if (!i2c_imx->multi_master)
+		return 0;
+
 	while (1) {
 		temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
 
@@ -540,8 +545,8 @@  static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx, bool atomic)
 		return -ETIMEDOUT;
 	}
 
-	/* check for arbitration lost */
-	if (i2c_imx->i2csr & I2SR_IAL) {
+	/* In multi-master mode check for arbitration lost */
+	if (i2c_imx->multi_master && (i2c_imx->i2csr & I2SR_IAL)) {
 		dev_dbg(&i2c_imx->adapter.dev, "<%s> Arbitration lost\n", __func__);
 		i2c_imx_clear_irq(i2c_imx, I2SR_IAL);
 
@@ -1468,6 +1473,8 @@  static int i2c_imx_probe(struct platform_device *pdev)
 		goto rpm_disable;
 	}
 
+	i2c_imx->multi_master = of_property_read_bool(pdev->dev.of_node, "multi-master");
+
 	/* Set up clock divider */
 	i2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ;
 	ret = of_property_read_u32(pdev->dev.of_node,