linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frank Li <Frank.Li@nxp.com>
To: "Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>
Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org,
	 imx@lists.linux.dev, linux-iio@vger.kernel.org,
	 joshua.yeong@starfivetech.com, devicetree@vger.kernel.org,
	 Frank Li <Frank.Li@nxp.com>
Subject: [PATCH v6 2/5] i3c: master: svc: Replace bool rnw with union for HDR support
Date: Tue, 14 Oct 2025 12:40:01 -0400	[thread overview]
Message-ID: <20251014-i3c_ddr-v6-2-3afe49773107@nxp.com> (raw)
In-Reply-To: <20251014-i3c_ddr-v6-0-3afe49773107@nxp.com>

Replace the bool rnw field with a union in preparation for adding HDR
support. HDR uses a cmd field instead of the rnw bit to indicate read or
write direction.

Add helper function svc_cmd_is_read() to check transfer direction.

Add a local variable 'rnw' in svc_i3c_master_priv_xfers() to avoid
repeatedly accessing xfers[i].rnw.

No functional change.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/i3c/master/svc-i3c-master.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c
index 701ae165b25b7991360f3a862b34cc1870a9a2ba..956172dc9d5f1f54d76b4c2917f2d9cf3bd21a85 100644
--- a/drivers/i3c/master/svc-i3c-master.c
+++ b/drivers/i3c/master/svc-i3c-master.c
@@ -165,7 +165,11 @@
 
 struct svc_i3c_cmd {
 	u8 addr;
-	bool rnw;
+	union {
+		bool rnw;
+		u8 cmd;
+		u32 rnw_cmd;
+	};
 	u8 *in;
 	const void *out;
 	unsigned int len;
@@ -383,6 +387,11 @@ svc_i3c_master_dev_from_addr(struct svc_i3c_master *master,
 	return master->descs[i];
 }
 
+static bool svc_cmd_is_read(u32 rnw_cmd, u32 type)
+{
+	return rnw_cmd;
+}
+
 static void svc_i3c_master_emit_stop(struct svc_i3c_master *master)
 {
 	writel(SVC_I3C_MCTRL_REQUEST_STOP, master->regs + SVC_I3C_MCTRL);
@@ -1272,10 +1281,11 @@ static int svc_i3c_master_write(struct svc_i3c_master *master,
 }
 
 static int svc_i3c_master_xfer(struct svc_i3c_master *master,
-			       bool rnw, unsigned int xfer_type, u8 addr,
+			       u32 rnw_cmd, unsigned int xfer_type, u8 addr,
 			       u8 *in, const u8 *out, unsigned int xfer_len,
 			       unsigned int *actual_len, bool continued, bool repeat_start)
 {
+	bool rnw = svc_cmd_is_read(rnw_cmd, xfer_type);
 	int retry = repeat_start ? 1 : 2;
 	u32 reg;
 	int ret;
@@ -1463,7 +1473,7 @@ static void svc_i3c_master_start_xfer_locked(struct svc_i3c_master *master)
 	for (i = 0; i < xfer->ncmds; i++) {
 		struct svc_i3c_cmd *cmd = &xfer->cmds[i];
 
-		ret = svc_i3c_master_xfer(master, cmd->rnw, xfer->type,
+		ret = svc_i3c_master_xfer(master, cmd->rnw_cmd, xfer->type,
 					  cmd->addr, cmd->in, cmd->out,
 					  cmd->len, &cmd->actual_len,
 					  cmd->continued, i > 0);
@@ -1656,14 +1666,15 @@ static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev,
 
 	for (i = 0; i < nxfers; i++) {
 		struct svc_i3c_cmd *cmd = &xfer->cmds[i];
+		bool rnw = xfers[i].rnw;
 
 		cmd->xfer = &xfers[i];
 		cmd->addr = master->addrs[data->index];
-		cmd->rnw = xfers[i].rnw;
-		cmd->in = xfers[i].rnw ? xfers[i].data.in : NULL;
-		cmd->out = xfers[i].rnw ? NULL : xfers[i].data.out;
+		cmd->rnw = rnw;
+		cmd->in = rnw ? xfers[i].data.in : NULL;
+		cmd->out = rnw ? NULL : xfers[i].data.out;
 		cmd->len = xfers[i].len;
-		cmd->actual_len = xfers[i].rnw ? xfers[i].len : 0;
+		cmd->actual_len = rnw ? xfers[i].len : 0;
 		cmd->continued = (i + 1) < nxfers;
 	}
 

-- 
2.34.1


  parent reply	other threads:[~2025-10-14 16:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 16:39 [PATCH v6 0/5] i3c: Add basic HDR mode support Frank Li
2025-10-14 16:40 ` [PATCH v6 1/5] i3c: Add HDR API support Frank Li
2025-10-23  8:23   ` Andy Shevchenko
2025-10-23 15:18     ` Frank Li
2025-10-23 18:22       ` Andy Shevchenko
2025-10-23 23:53         ` Frank Li
2025-10-24  6:13           ` Andy Shevchenko
2025-10-24 14:03             ` Frank Li
2025-10-24 16:03               ` Andy Shevchenko
2025-10-24 16:29                 ` Frank Li
2025-10-24 21:12                   ` Alexandre Belloni
2025-10-14 16:40 ` Frank Li [this message]
2025-10-23  8:26   ` [PATCH v6 2/5] i3c: master: svc: Replace bool rnw with union for HDR support Andy Shevchenko
2025-10-23 15:21     ` Frank Li
2025-10-14 16:40 ` [PATCH v6 3/5] i3c: master: svc: Add basic HDR mode support Frank Li
2025-10-23  8:29   ` Andy Shevchenko
2025-10-23 15:24     ` Frank Li
2025-10-23 18:25       ` Andy Shevchenko
2025-10-23 23:44         ` Frank Li
2025-10-14 16:40 ` [PATCH v6 4/5] dt-bindings: trivial-devices: add MEMSIC 3-axis magnetometer Frank Li
2025-10-14 16:40 ` [PATCH v6 5/5] iio: magnetometer: Add mmc5633 sensor Frank Li
2025-10-18 16:52   ` Jonathan Cameron
2025-10-18 16:54     ` Jonathan Cameron
2025-10-23  8:46   ` Andy Shevchenko

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=20251014-i3c_ddr-v6-2-3afe49773107@nxp.com \
    --to=frank.li@nxp.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=imx@lists.linux.dev \
    --cc=jic23@kernel.org \
    --cc=joshua.yeong@starfivetech.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-i3c@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    /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).