linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: busses: i2c-cadence: fix message length when receive block message
@ 2022-05-19 12:50 Adam Wujek
  2022-05-19 23:11 ` [PATCH v2] " Adam Wujek
  0 siblings, 1 reply; 3+ messages in thread
From: Adam Wujek @ 2022-05-19 12:50 UTC (permalink / raw)
  Cc: Adam Wujek, Michal Simek, linux-arm-kernel, linux-i2c, linux-kernel

Needed by hwmon/pmbus_core driver to correctly calculate PEC.
The hwmon/pmbus_core driver relies on bus drivers to update the message length
of received block transfers. Only in this type of smbus transfer, in which the
length is not known before the transfer is started.

Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
 drivers/i2c/busses/i2c-cadence.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 20ac432a37ea..65f1979d4e6f 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -830,6 +830,11 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
 		return -ETIMEDOUT;
 	}

+	/* Update message len, as i2c/smbus driver (function
+	 * i2c_smbus_xfer_emulated) relies on i2c device drivers to do this */
+	if ((msg->flags & I2C_M_RECV_LEN) && (msg->flags & I2C_M_RD))
+		msg->len = msg->buf[0] + 2; /* add len byte + PEC byte */
+
 	cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK,
 			  CDNS_I2C_IDR_OFFSET);

--
2.17.1



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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2] i2c: busses: i2c-cadence: fix message length when receive block message
  2022-05-19 12:50 [PATCH] i2c: busses: i2c-cadence: fix message length when receive block message Adam Wujek
@ 2022-05-19 23:11 ` Adam Wujek
  2022-05-24 15:05   ` Michal Simek
  0 siblings, 1 reply; 3+ messages in thread
From: Adam Wujek @ 2022-05-19 23:11 UTC (permalink / raw)
  Cc: Adam Wujek, Michal Simek, linux-arm-kernel, linux-i2c, linux-kernel

Needed by hwmon/pmbus_core driver to calculate PEC correctly.
The hwmon/pmbus_core driver relies on bus drivers to update the message
length of receive block transfers. Only in this type of smbus transfer
the length is not known before the transfer is started.

Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
Notes:
    Changes in v2:
    - fix multiline comment

 drivers/i2c/busses/i2c-cadence.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 805c77143a0f..a679eb390ef5 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -794,6 +794,13 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
 		return -ETIMEDOUT;
 	}

+	/*
+	 * Update message len, as i2c/smbus driver (function
+	 * i2c_smbus_xfer_emulated) relies on i2c device drivers to do this.
+	 */
+	if ((msg->flags & I2C_M_RECV_LEN) && (msg->flags & I2C_M_RD))
+		msg->len = msg->buf[0] + 2; /* add len byte + PEC byte */
+
 	cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK,
 			  CDNS_I2C_IDR_OFFSET);

--
2.17.1



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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] i2c: busses: i2c-cadence: fix message length when receive block message
  2022-05-19 23:11 ` [PATCH v2] " Adam Wujek
@ 2022-05-24 15:05   ` Michal Simek
  0 siblings, 0 replies; 3+ messages in thread
From: Michal Simek @ 2022-05-24 15:05 UTC (permalink / raw)
  To: Adam Wujek, Shubhrajyoti Datta
  Cc: Michal Simek, linux-arm-kernel, linux-i2c, linux-kernel



On 5/20/22 01:11, Adam Wujek wrote:
> Needed by hwmon/pmbus_core driver to calculate PEC correctly.
> The hwmon/pmbus_core driver relies on bus drivers to update the message
> length of receive block transfers. Only in this type of smbus transfer
> the length is not known before the transfer is started.
> 
> Signed-off-by: Adam Wujek <dev_public@wujek.eu>
> ---
> Notes:
>      Changes in v2:
>      - fix multiline comment
> 
>   drivers/i2c/busses/i2c-cadence.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
> index 805c77143a0f..a679eb390ef5 100644
> --- a/drivers/i2c/busses/i2c-cadence.c
> +++ b/drivers/i2c/busses/i2c-cadence.c
> @@ -794,6 +794,13 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
>   		return -ETIMEDOUT;
>   	}
> 
> +	/*
> +	 * Update message len, as i2c/smbus driver (function
> +	 * i2c_smbus_xfer_emulated) relies on i2c device drivers to do this.
> +	 */
> +	if ((msg->flags & I2C_M_RECV_LEN) && (msg->flags & I2C_M_RD))
> +		msg->len = msg->buf[0] + 2; /* add len byte + PEC byte */
> +
>   	cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK,
>   			  CDNS_I2C_IDR_OFFSET);
> 
> --
> 2.17.1
> 
> 

Shubhrajyoti: Can you please test it?

Thanks,
Michal

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-24 15:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-19 12:50 [PATCH] i2c: busses: i2c-cadence: fix message length when receive block message Adam Wujek
2022-05-19 23:11 ` [PATCH v2] " Adam Wujek
2022-05-24 15:05   ` Michal Simek

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).