* [PATCH v2 0/3] Add helper methods i3c_writel_fifo() and i3c_readl_fifo()
@ 2025-06-22 9:18 Jorge Marques
2025-06-22 9:18 ` [PATCH v2 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo() Jorge Marques
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Jorge Marques @ 2025-06-22 9:18 UTC (permalink / raw)
To: Alexandre Belloni, Frank Li, Przemysław Gaj
Cc: linux-i3c, linux-kernel, Jorge Marques
The i3c abstraction excepts u8 buffers, but some controllers have a bus
width of 32-bits and don't support flagging valid bytes, so it is
required to read/write long words and to use memcpy on the remainder of
the number of bytes by 32-bits to not write/read outside the buffer
bounds.
Add two auxiliary methods to include/linux/i3c/master.h and use in the dw
and cdns i3c controller drivers. The adi controller driver will also use
these methods.
Related thread: https://lore.kernel.org/linux-i3c/aFNziEj7j31xy%2FmY@lizhi-Precision-Tower-5810/
Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
Changes in v2:
- Rename to i3c_readl_fifo() and i3c_writel_fifo()
- Change type u8 *bytes to void *bytes
- Move methods to internals.h
- Reword commit messages to include new names and ().
- Fixup dw read fifo address (master -> master->reg)
- Link to v1: https://lore.kernel.org/r/20250620-i3c-writesl-readsl-v1-0-e0aa1c014dff@analog.com
---
Jorge Marques (3):
i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo()
i3c: master: cdns: Use i3c_master_writesl() and i3c_master_readsl()
i3c: master: dw: Use i3c_master_writesl() and i3c_master_readsl()
drivers/i3c/internals.h | 37 ++++++++++++++++++++++++++++++++++++
drivers/i3c/master/dw-i3c-master.c | 25 ++++--------------------
drivers/i3c/master/i3c-master-cdns.c | 25 +++++-------------------
3 files changed, 46 insertions(+), 41 deletions(-)
---
base-commit: 51963783b876a2f493a3eac0ea9eba271cb6809a
change-id: 20250620-i3c-writesl-readsl-e2836534b665
Best regards,
--
Jorge Marques <jorge.marques@analog.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo()
2025-06-22 9:18 [PATCH v2 0/3] Add helper methods i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
@ 2025-06-22 9:18 ` Jorge Marques
2025-06-23 15:43 ` Frank Li
2025-06-23 19:53 ` Wolfram Sang
2025-06-22 9:18 ` [PATCH v2 2/3] i3c: master: cdns: Use i3c_master_writesl() and i3c_master_readsl() Jorge Marques
2025-06-22 9:19 ` [PATCH v2 3/3] i3c: master: dw: " Jorge Marques
2 siblings, 2 replies; 9+ messages in thread
From: Jorge Marques @ 2025-06-22 9:18 UTC (permalink / raw)
To: Alexandre Belloni, Frank Li, Przemysław Gaj
Cc: linux-i3c, linux-kernel, Jorge Marques
The i3c abstraction excepts u8 buffers, but some controllers have a bus
width of 32-bits and don't support flagging valid bytes, so it is
required to read/write long words and to use memcpy on the remainder of
the number of bytes by 32-bits to not write/read outside the buffer
bounds.
Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
drivers/i3c/internals.h | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h
index 433f6088b7cec8c77288ee24dbee8b18338aa1eb..88887b12122efafac81bcfdd093d943259e13a08 100644
--- a/drivers/i3c/internals.h
+++ b/drivers/i3c/internals.h
@@ -22,4 +22,41 @@ int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev);
int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev,
const struct i3c_ibi_setup *req);
void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev);
+
+/**
+ * i3c_master_writesl- Write bytes to long memory region from byte array
+ * @addr: Register to write to
+ * @bytes: Pointer to the data bytes to write
+ * @nbytes: Number of bytes to write
+ */
+static inline void i3c_writel_fifo(void __iomem *addr, const void *bytes,
+ int nbytes)
+{
+ writesl(addr, bytes, nbytes / 4);
+ if (nbytes & 3) {
+ u32 tmp = 0;
+
+ memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
+ writel(tmp, addr);
+ }
+}
+
+/**
+ * i3c_master_readsl - Read bytes from long memory region to byte array
+ * @addr: Register to read from
+ * @bytes: Pointer to the buffer to store read bytes
+ * @nbytes: Number of bytes to read
+ */
+static inline void i3c_readl_fifo(const void __iomem *addr, void *bytes,
+ int nbytes)
+{
+ readsl(addr, bytes, nbytes / 4);
+ if (nbytes & 3) {
+ u32 tmp;
+
+ tmp = readl(addr);
+ memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
+ }
+}
+
#endif /* I3C_INTERNAL_H */
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/3] i3c: master: cdns: Use i3c_master_writesl() and i3c_master_readsl()
2025-06-22 9:18 [PATCH v2 0/3] Add helper methods i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
2025-06-22 9:18 ` [PATCH v2 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo() Jorge Marques
@ 2025-06-22 9:18 ` Jorge Marques
2025-06-23 15:45 ` Frank Li
2025-06-22 9:19 ` [PATCH v2 3/3] i3c: master: dw: " Jorge Marques
2 siblings, 1 reply; 9+ messages in thread
From: Jorge Marques @ 2025-06-22 9:18 UTC (permalink / raw)
To: Alexandre Belloni, Frank Li, Przemysław Gaj
Cc: linux-i3c, linux-kernel, Jorge Marques
Use common inline i3c_master_writesl()/i3c_master_readsl() methods to
simplify code since the FIFO of controller is a 32bit width.
Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
drivers/i3c/master/i3c-master-cdns.c | 25 +++++--------------------
1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
index fd3752cea654954ed1e37337754e45fddbbbf68e..321c04d2109ec1951f2b07a9d1b88c6aaf055c95 100644
--- a/drivers/i3c/master/i3c-master-cdns.c
+++ b/drivers/i3c/master/i3c-master-cdns.c
@@ -23,6 +23,8 @@
#include <linux/spinlock.h>
#include <linux/workqueue.h>
+#include "../internals.h"
+
#define DEV_ID 0x0
#define DEV_ID_I3C_MASTER 0x5034
@@ -427,25 +429,13 @@ to_cdns_i3c_master(struct i3c_master_controller *master)
static void cdns_i3c_master_wr_to_tx_fifo(struct cdns_i3c_master *master,
const u8 *bytes, int nbytes)
{
- writesl(master->regs + TX_FIFO, bytes, nbytes / 4);
- if (nbytes & 3) {
- u32 tmp = 0;
-
- memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
- writesl(master->regs + TX_FIFO, &tmp, 1);
- }
+ i3c_writel_fifo(master->regs + TX_FIFO, bytes, nbytes);
}
static void cdns_i3c_master_rd_from_rx_fifo(struct cdns_i3c_master *master,
u8 *bytes, int nbytes)
{
- readsl(master->regs + RX_FIFO, bytes, nbytes / 4);
- if (nbytes & 3) {
- u32 tmp;
-
- readsl(master->regs + RX_FIFO, &tmp, 1);
- memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
- }
+ i3c_readl_fifo(master->regs + RX_FIFO, bytes, nbytes);
}
static bool cdns_i3c_master_supports_ccc_cmd(struct i3c_master_controller *m,
@@ -1330,12 +1320,7 @@ static void cdns_i3c_master_handle_ibi(struct cdns_i3c_master *master,
buf = slot->data;
nbytes = IBIR_XFER_BYTES(ibir);
- readsl(master->regs + IBI_DATA_FIFO, buf, nbytes / 4);
- if (nbytes % 3) {
- u32 tmp = __raw_readl(master->regs + IBI_DATA_FIFO);
-
- memcpy(buf + (nbytes & ~3), &tmp, nbytes & 3);
- }
+ i3c_readl_fifo(master->regs + IBI_DATA_FIFO, buf, nbytes);
slot->len = min_t(unsigned int, IBIR_XFER_BYTES(ibir),
dev->ibi->max_payload_len);
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/3] i3c: master: dw: Use i3c_master_writesl() and i3c_master_readsl()
2025-06-22 9:18 [PATCH v2 0/3] Add helper methods i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
2025-06-22 9:18 ` [PATCH v2 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo() Jorge Marques
2025-06-22 9:18 ` [PATCH v2 2/3] i3c: master: cdns: Use i3c_master_writesl() and i3c_master_readsl() Jorge Marques
@ 2025-06-22 9:19 ` Jorge Marques
2 siblings, 0 replies; 9+ messages in thread
From: Jorge Marques @ 2025-06-22 9:19 UTC (permalink / raw)
To: Alexandre Belloni, Frank Li, Przemysław Gaj
Cc: linux-i3c, linux-kernel, Jorge Marques
Use common inline i3c_master_writesl()/i3c_master_readsl() methods to
simplify code since the FIFO of controller is a 32bit width.
Signed-off-by: Jorge Marques <jorge.marques@analog.com>
---
drivers/i3c/master/dw-i3c-master.c | 25 ++++---------------------
1 file changed, 4 insertions(+), 21 deletions(-)
diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index 611c22b72c1572ddf717c8ad473e44a3b8fcceaf..886f8b74defda31ae93248467d144f9c8c561581 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -23,6 +23,7 @@
#include <linux/reset.h>
#include <linux/slab.h>
+#include "../internals.h"
#include "dw-i3c-master.h"
#define DEVICE_CTRL 0x0
@@ -336,37 +337,19 @@ static int dw_i3c_master_get_free_pos(struct dw_i3c_master *master)
static void dw_i3c_master_wr_tx_fifo(struct dw_i3c_master *master,
const u8 *bytes, int nbytes)
{
- writesl(master->regs + RX_TX_DATA_PORT, bytes, nbytes / 4);
- if (nbytes & 3) {
- u32 tmp = 0;
-
- memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
- writesl(master->regs + RX_TX_DATA_PORT, &tmp, 1);
- }
-}
-
-static void dw_i3c_master_read_fifo(struct dw_i3c_master *master,
- int reg, u8 *bytes, int nbytes)
-{
- readsl(master->regs + reg, bytes, nbytes / 4);
- if (nbytes & 3) {
- u32 tmp;
-
- readsl(master->regs + reg, &tmp, 1);
- memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
- }
+ i3c_writel_fifo(master->regs + RX_TX_DATA_PORT, bytes, nbytes);
}
static void dw_i3c_master_read_rx_fifo(struct dw_i3c_master *master,
u8 *bytes, int nbytes)
{
- return dw_i3c_master_read_fifo(master, RX_TX_DATA_PORT, bytes, nbytes);
+ i3c_readl_fifo(master->regs + RX_TX_DATA_PORT, bytes, nbytes);
}
static void dw_i3c_master_read_ibi_fifo(struct dw_i3c_master *master,
u8 *bytes, int nbytes)
{
- return dw_i3c_master_read_fifo(master, IBI_QUEUE_STATUS, bytes, nbytes);
+ i3c_readl_fifo(master->regs + IBI_QUEUE_STATUS, bytes, nbytes);
}
static struct dw_i3c_xfer *
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo()
2025-06-22 9:18 ` [PATCH v2 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo() Jorge Marques
@ 2025-06-23 15:43 ` Frank Li
2025-06-24 8:50 ` Jorge Marques
2025-06-23 19:53 ` Wolfram Sang
1 sibling, 1 reply; 9+ messages in thread
From: Frank Li @ 2025-06-23 15:43 UTC (permalink / raw)
To: Jorge Marques
Cc: Alexandre Belloni, Przemysław Gaj, linux-i3c, linux-kernel
On Sun, Jun 22, 2025 at 11:18:58AM +0200, Jorge Marques wrote:
> The i3c abstraction excepts u8 buffers, but some controllers have a bus
^ expects?
> width of 32-bits and don't support flagging valid bytes, so it is
> required to read/write long words and to use memcpy on the remainder of
> the number of bytes by 32-bits to not write/read outside the buffer
> bounds.
The I3C abstraction expects u8 buffers, but some controllers operate with
a 32-bit bus width FIFO and cannot flag valid bytes individually. To avoid
reading or writing outside the buffer bounds, use 32-bit accesses where
possible and apply memcpy for any remaining bytes.
Frank
>
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> ---
> drivers/i3c/internals.h | 37 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 37 insertions(+)
>
> diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h
> index 433f6088b7cec8c77288ee24dbee8b18338aa1eb..88887b12122efafac81bcfdd093d943259e13a08 100644
> --- a/drivers/i3c/internals.h
> +++ b/drivers/i3c/internals.h
> @@ -22,4 +22,41 @@ int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev);
> int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev,
> const struct i3c_ibi_setup *req);
> void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev);
> +
> +/**
> + * i3c_master_writesl- Write bytes to long memory region from byte array
i3c_writel_fifo - Write data buffer to 32bit FIFO
> + * @addr: Register to write to
FIFO address
> + * @bytes: Pointer to the data bytes to write
bytes and nbytes is too similar, can you rename bytes to buf?
Check read_fifo also.
Frank
> + * @nbytes: Number of bytes to write
> + */
> +static inline void i3c_writel_fifo(void __iomem *addr, const void *bytes,
> + int nbytes)
> +{
> + writesl(addr, bytes, nbytes / 4);
> + if (nbytes & 3) {
> + u32 tmp = 0;
> +
> + memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
> + writel(tmp, addr);
> + }
> +}
> +
> +/**
> + * i3c_master_readsl - Read bytes from long memory region to byte array
> + * @addr: Register to read from
> + * @bytes: Pointer to the buffer to store read bytes
> + * @nbytes: Number of bytes to read
> + */
> +static inline void i3c_readl_fifo(const void __iomem *addr, void *bytes,
> + int nbytes)
> +{
> + readsl(addr, bytes, nbytes / 4);
> + if (nbytes & 3) {
> + u32 tmp;
> +
> + tmp = readl(addr);
> + memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
> + }
> +}
> +
> #endif /* I3C_INTERNAL_H */
>
> --
> 2.49.0
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/3] i3c: master: cdns: Use i3c_master_writesl() and i3c_master_readsl()
2025-06-22 9:18 ` [PATCH v2 2/3] i3c: master: cdns: Use i3c_master_writesl() and i3c_master_readsl() Jorge Marques
@ 2025-06-23 15:45 ` Frank Li
2025-06-24 8:55 ` Jorge Marques
0 siblings, 1 reply; 9+ messages in thread
From: Frank Li @ 2025-06-23 15:45 UTC (permalink / raw)
To: Jorge Marques
Cc: Alexandre Belloni, Przemysław Gaj, linux-i3c, linux-kernel
On Sun, Jun 22, 2025 at 11:18:59AM +0200, Jorge Marques wrote:
> Use common inline i3c_master_writesl()/i3c_master_readsl() methods to
API name changed, you need update it also, include subject.
Frank
> simplify code since the FIFO of controller is a 32bit width.
>
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> ---
> drivers/i3c/master/i3c-master-cdns.c | 25 +++++--------------------
> 1 file changed, 5 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
> index fd3752cea654954ed1e37337754e45fddbbbf68e..321c04d2109ec1951f2b07a9d1b88c6aaf055c95 100644
> --- a/drivers/i3c/master/i3c-master-cdns.c
> +++ b/drivers/i3c/master/i3c-master-cdns.c
> @@ -23,6 +23,8 @@
> #include <linux/spinlock.h>
> #include <linux/workqueue.h>
>
> +#include "../internals.h"
> +
> #define DEV_ID 0x0
> #define DEV_ID_I3C_MASTER 0x5034
>
> @@ -427,25 +429,13 @@ to_cdns_i3c_master(struct i3c_master_controller *master)
> static void cdns_i3c_master_wr_to_tx_fifo(struct cdns_i3c_master *master,
> const u8 *bytes, int nbytes)
> {
> - writesl(master->regs + TX_FIFO, bytes, nbytes / 4);
> - if (nbytes & 3) {
> - u32 tmp = 0;
> -
> - memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
> - writesl(master->regs + TX_FIFO, &tmp, 1);
> - }
> + i3c_writel_fifo(master->regs + TX_FIFO, bytes, nbytes);
> }
>
> static void cdns_i3c_master_rd_from_rx_fifo(struct cdns_i3c_master *master,
> u8 *bytes, int nbytes)
> {
> - readsl(master->regs + RX_FIFO, bytes, nbytes / 4);
> - if (nbytes & 3) {
> - u32 tmp;
> -
> - readsl(master->regs + RX_FIFO, &tmp, 1);
> - memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
> - }
> + i3c_readl_fifo(master->regs + RX_FIFO, bytes, nbytes);
> }
>
> static bool cdns_i3c_master_supports_ccc_cmd(struct i3c_master_controller *m,
> @@ -1330,12 +1320,7 @@ static void cdns_i3c_master_handle_ibi(struct cdns_i3c_master *master,
> buf = slot->data;
>
> nbytes = IBIR_XFER_BYTES(ibir);
> - readsl(master->regs + IBI_DATA_FIFO, buf, nbytes / 4);
> - if (nbytes % 3) {
> - u32 tmp = __raw_readl(master->regs + IBI_DATA_FIFO);
> -
> - memcpy(buf + (nbytes & ~3), &tmp, nbytes & 3);
> - }
> + i3c_readl_fifo(master->regs + IBI_DATA_FIFO, buf, nbytes);
>
> slot->len = min_t(unsigned int, IBIR_XFER_BYTES(ibir),
> dev->ibi->max_payload_len);
>
> --
> 2.49.0
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo()
2025-06-22 9:18 ` [PATCH v2 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo() Jorge Marques
2025-06-23 15:43 ` Frank Li
@ 2025-06-23 19:53 ` Wolfram Sang
1 sibling, 0 replies; 9+ messages in thread
From: Wolfram Sang @ 2025-06-23 19:53 UTC (permalink / raw)
To: Jorge Marques
Cc: Alexandre Belloni, Frank Li, Przemysław Gaj, linux-i3c,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 601 bytes --]
On Sun, Jun 22, 2025 at 11:18:58AM +0200, Jorge Marques wrote:
> The i3c abstraction excepts u8 buffers, but some controllers have a bus
> width of 32-bits and don't support flagging valid bytes, so it is
> required to read/write long words and to use memcpy on the remainder of
> the number of bytes by 32-bits to not write/read outside the buffer
> bounds.
>
> Signed-off-by: Jorge Marques <jorge.marques@analog.com>
Despite Frank's valid comments, I tested this code with the Renesas
driver and it worked so far. Thanks!
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo()
2025-06-23 15:43 ` Frank Li
@ 2025-06-24 8:50 ` Jorge Marques
0 siblings, 0 replies; 9+ messages in thread
From: Jorge Marques @ 2025-06-24 8:50 UTC (permalink / raw)
To: Frank Li
Cc: Jorge Marques, Alexandre Belloni, Przemysław Gaj, linux-i3c,
linux-kernel
On Mon, Jun 23, 2025 at 11:43:19AM -0400, Frank Li wrote:
> On Sun, Jun 22, 2025 at 11:18:58AM +0200, Jorge Marques wrote:
> > The i3c abstraction excepts u8 buffers, but some controllers have a bus
> ^ expects?
>
> > width of 32-bits and don't support flagging valid bytes, so it is
> > required to read/write long words and to use memcpy on the remainder of
> > the number of bytes by 32-bits to not write/read outside the buffer
> > bounds.
>
> The I3C abstraction expects u8 buffers, but some controllers operate with
> a 32-bit bus width FIFO and cannot flag valid bytes individually. To avoid
> reading or writing outside the buffer bounds, use 32-bit accesses where
> possible and apply memcpy for any remaining bytes.
Hi Frank,
gotcha,
>
> Frank
> >
> > Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> > ---
> > drivers/i3c/internals.h | 37 +++++++++++++++++++++++++++++++++++++
> > 1 file changed, 37 insertions(+)
> >
> > diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h
> > index 433f6088b7cec8c77288ee24dbee8b18338aa1eb..88887b12122efafac81bcfdd093d943259e13a08 100644
> > --- a/drivers/i3c/internals.h
> > +++ b/drivers/i3c/internals.h
> > @@ -22,4 +22,41 @@ int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev);
> > int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev,
> > const struct i3c_ibi_setup *req);
> > void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev);
> > +
> > +/**
> > + * i3c_master_writesl- Write bytes to long memory region from byte array
>
> i3c_writel_fifo - Write data buffer to 32bit FIFO
>
> > + * @addr: Register to write to
>
> FIFO address
>
> > + * @bytes: Pointer to the data bytes to write
>
> bytes and nbytes is too similar, can you rename bytes to buf?
Yep
>
> Check read_fifo also.
Ack
>
> Frank
Regards,
Jorge
> > + * @nbytes: Number of bytes to write
> > + */
> > +static inline void i3c_writel_fifo(void __iomem *addr, const void *bytes,
> > + int nbytes)
> > +{
> > + writesl(addr, bytes, nbytes / 4);
> > + if (nbytes & 3) {
> > + u32 tmp = 0;
> > +
> > + memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
> > + writel(tmp, addr);
> > + }
> > +}
> > +
> > +/**
> > + * i3c_master_readsl - Read bytes from long memory region to byte array
> > + * @addr: Register to read from
> > + * @bytes: Pointer to the buffer to store read bytes
> > + * @nbytes: Number of bytes to read
> > + */
> > +static inline void i3c_readl_fifo(const void __iomem *addr, void *bytes,
> > + int nbytes)
> > +{
> > + readsl(addr, bytes, nbytes / 4);
> > + if (nbytes & 3) {
> > + u32 tmp;
> > +
> > + tmp = readl(addr);
> > + memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
> > + }
> > +}
> > +
> > #endif /* I3C_INTERNAL_H */
> >
> > --
> > 2.49.0
> >
> >
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/3] i3c: master: cdns: Use i3c_master_writesl() and i3c_master_readsl()
2025-06-23 15:45 ` Frank Li
@ 2025-06-24 8:55 ` Jorge Marques
0 siblings, 0 replies; 9+ messages in thread
From: Jorge Marques @ 2025-06-24 8:55 UTC (permalink / raw)
To: Frank Li
Cc: Jorge Marques, Alexandre Belloni, Przemysław Gaj, linux-i3c,
linux-kernel
On Mon, Jun 23, 2025 at 11:45:19AM -0400, Frank Li wrote:
> On Sun, Jun 22, 2025 at 11:18:59AM +0200, Jorge Marques wrote:
> > Use common inline i3c_master_writesl()/i3c_master_readsl() methods to
>
> API name changed, you need update it also, include subject.
>
> Frank
>
Ack
Regards,
Jorge
> > simplify code since the FIFO of controller is a 32bit width.
> >
> > Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> > ---
> > drivers/i3c/master/i3c-master-cdns.c | 25 +++++--------------------
> > 1 file changed, 5 insertions(+), 20 deletions(-)
> >
> > diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
> > index fd3752cea654954ed1e37337754e45fddbbbf68e..321c04d2109ec1951f2b07a9d1b88c6aaf055c95 100644
> > --- a/drivers/i3c/master/i3c-master-cdns.c
> > +++ b/drivers/i3c/master/i3c-master-cdns.c
> > @@ -23,6 +23,8 @@
> > #include <linux/spinlock.h>
> > #include <linux/workqueue.h>
> >
> > +#include "../internals.h"
> > +
> > #define DEV_ID 0x0
> > #define DEV_ID_I3C_MASTER 0x5034
> >
> > @@ -427,25 +429,13 @@ to_cdns_i3c_master(struct i3c_master_controller *master)
> > static void cdns_i3c_master_wr_to_tx_fifo(struct cdns_i3c_master *master,
> > const u8 *bytes, int nbytes)
> > {
> > - writesl(master->regs + TX_FIFO, bytes, nbytes / 4);
> > - if (nbytes & 3) {
> > - u32 tmp = 0;
> > -
> > - memcpy(&tmp, bytes + (nbytes & ~3), nbytes & 3);
> > - writesl(master->regs + TX_FIFO, &tmp, 1);
> > - }
> > + i3c_writel_fifo(master->regs + TX_FIFO, bytes, nbytes);
> > }
> >
> > static void cdns_i3c_master_rd_from_rx_fifo(struct cdns_i3c_master *master,
> > u8 *bytes, int nbytes)
> > {
> > - readsl(master->regs + RX_FIFO, bytes, nbytes / 4);
> > - if (nbytes & 3) {
> > - u32 tmp;
> > -
> > - readsl(master->regs + RX_FIFO, &tmp, 1);
> > - memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
> > - }
> > + i3c_readl_fifo(master->regs + RX_FIFO, bytes, nbytes);
> > }
> >
> > static bool cdns_i3c_master_supports_ccc_cmd(struct i3c_master_controller *m,
> > @@ -1330,12 +1320,7 @@ static void cdns_i3c_master_handle_ibi(struct cdns_i3c_master *master,
> > buf = slot->data;
> >
> > nbytes = IBIR_XFER_BYTES(ibir);
> > - readsl(master->regs + IBI_DATA_FIFO, buf, nbytes / 4);
> > - if (nbytes % 3) {
> > - u32 tmp = __raw_readl(master->regs + IBI_DATA_FIFO);
> > -
> > - memcpy(buf + (nbytes & ~3), &tmp, nbytes & 3);
> > - }
> > + i3c_readl_fifo(master->regs + IBI_DATA_FIFO, buf, nbytes);
> >
> > slot->len = min_t(unsigned int, IBIR_XFER_BYTES(ibir),
> > dev->ibi->max_payload_len);
> >
> > --
> > 2.49.0
> >
> >
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-06-24 8:55 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-22 9:18 [PATCH v2 0/3] Add helper methods i3c_writel_fifo() and i3c_readl_fifo() Jorge Marques
2025-06-22 9:18 ` [PATCH v2 1/3] i3c: master: Add inline i3c_readl_fifo() and i3c_writel_fifo() Jorge Marques
2025-06-23 15:43 ` Frank Li
2025-06-24 8:50 ` Jorge Marques
2025-06-23 19:53 ` Wolfram Sang
2025-06-22 9:18 ` [PATCH v2 2/3] i3c: master: cdns: Use i3c_master_writesl() and i3c_master_readsl() Jorge Marques
2025-06-23 15:45 ` Frank Li
2025-06-24 8:55 ` Jorge Marques
2025-06-22 9:19 ` [PATCH v2 3/3] i3c: master: dw: " Jorge Marques
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).