From miquel.raynal at bootlin.com  Fri Dec  1 03:59:04 2023
From: miquel.raynal at bootlin.com (Miquel Raynal)
Date: Fri, 1 Dec 2023 12:59:04 +0100
Subject: [PATCH v5 7/7] tty: i3c: add TTY over I3C master support
In-Reply-To: <20231130224408.3591288-8-Frank.Li@nxp.com>
References: <20231130224408.3591288-1-Frank.Li@nxp.com>
	<20231130224408.3591288-8-Frank.Li@nxp.com>
Message-ID: <20231201125904.6c8128b1@xps-13>

Hi Frank,

Frank.Li at nxp.com wrote on Thu, 30 Nov 2023 17:44:08 -0500:

> In typical embedded Linux systems, UART consoles require at least two pins,
> TX and RX. In scenarios where I2C/I3C devices like sensors or PMICs are
> present, we can save these two pins by using this driver. Pins is crucial
> resources, especially in small chip packages.
> 
> This introduces support for using the I3C bus to transfer console tty data,
> effectively replacing the need for dedicated UART pins. This not only
> conserves valuable pin resources but also facilitates testing of I3C's
> advanced features, including early termination, in-band interrupt (IBI)
> support, and the creation of more complex data patterns. Additionally,
> it aids in identifying and addressing issues within the I3C controller
> driver.
> 
> Signed-off-by: Frank Li <Frank.Li at nxp.com>
> ---
> 
> Notes:
>     Change from v4 to v5
>     - send in i3c improvememtn patches.

This is not what I said, I believe this patch and the previous patch
should be sent separately.

Thanks,
Miqu?l


From Frank.Li at nxp.com  Fri Dec  1 14:25:26 2023
From: Frank.Li at nxp.com (Frank Li)
Date: Fri,  1 Dec 2023 17:25:26 -0500
Subject: [v5 resend 0/6] i3c: master: some improvment for i3c master
Message-ID: <20231201222532.2431484-1-Frank.Li@nxp.com>

There are three major improvement

1. Add actual size in i3c_transfer because i3c allow target early termiate
transfer.
2. Add API for i3c_dev_gettstatus_format1 for i3c comand GET_STATUS.
3. svc master support hotjoin

Change log see each patches

Frank Li (6):
  i3c: master: add enable(disable) hot join in sys entry
  i3c: master: svc: add hot join support
  i3c: add actual_len in i3c_priv_xfer
  i3c: master: svc: rename read_len as actual_len
  i3c: master: svc: return actual transfer data len
  i3c: add API i3c_dev_gettstatus_format1() to get target device status

 drivers/i3c/device.c                |  24 ++++++
 drivers/i3c/internals.h             |   1 +
 drivers/i3c/master.c                | 109 ++++++++++++++++++++++++++++
 drivers/i3c/master/svc-i3c-master.c |  95 +++++++++++++++++++-----
 include/linux/i3c/device.h          |   3 +
 include/linux/i3c/master.h          |   5 ++
 6 files changed, 220 insertions(+), 17 deletions(-)

-- 
2.34.1



From Frank.Li at nxp.com  Fri Dec  1 14:25:27 2023
From: Frank.Li at nxp.com (Frank Li)
Date: Fri,  1 Dec 2023 17:25:27 -0500
Subject: [v5 resend 1/6] i3c: master: add enable(disable) hot join in sys entry
In-Reply-To: <20231201222532.2431484-1-Frank.Li@nxp.com>
References: <20231201222532.2431484-1-Frank.Li@nxp.com>
Message-ID: <20231201222532.2431484-2-Frank.Li@nxp.com>

Add hotjoin entry in sys file system allow user enable/disable hotjoin
feature.

Add (*enable(disable)_hotjoin)() to i3c_master_controller_ops.
Add api i3c_master_enable(disable)_hotjoin();

Signed-off-by: Frank Li <Frank.Li at nxp.com>
---

Notes:
    Change from v4 to v5
    - using kstrtobool()
    > +	if (!master ||
    > +	    !master->ops ||
    > +	    !master->ops->enable_hotjoin ||
    > +	    !master->ops->disable_hotjoin
    > +	   )
    
    break into two if, which will be more clear. and one line is 101 chars.
    
    Change from v3 to v4
    -none
    Change from v1 to v2.
    - Hotjoin control by sys entry, default enable hotjoin, which standard i3c
    feature, user can disable by echo 0 > /sys/bus/i3c/i3c-0/hotjoin

 drivers/i3c/master.c       | 83 ++++++++++++++++++++++++++++++++++++++
 include/linux/i3c/master.h |  5 +++
 2 files changed, 88 insertions(+)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 08aeb69a78003..d3b56c9f601e2 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -526,6 +526,88 @@ static ssize_t i2c_scl_frequency_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(i2c_scl_frequency);
 
+static int i3c_set_hotjoin(struct i3c_master_controller *master, bool enable)
+{
+	int ret;
+
+	if (!master || !master->ops)
+		return -EINVAL;
+
+	if (!master->ops->enable_hotjoin || !master->ops->disable_hotjoin)
+		return -EINVAL;
+
+	i3c_bus_normaluse_lock(&master->bus);
+
+	if (enable)
+		ret = master->ops->enable_hotjoin(master);
+	else
+		ret = master->ops->disable_hotjoin(master);
+
+	master->hotjoin = enable;
+
+	i3c_bus_normaluse_unlock(&master->bus);
+
+	return ret;
+}
+
+static ssize_t hotjoin_store(struct device *dev, struct device_attribute *attr,
+			     const char *buf, size_t count)
+{
+	struct i3c_bus *i3cbus = dev_to_i3cbus(dev);
+	int ret;
+	bool res;
+
+	if (!i3cbus->cur_master)
+		return -EINVAL;
+
+	if (kstrtobool(buf, &res))
+		return -EINVAL;
+
+	ret = i3c_set_hotjoin(i3cbus->cur_master->common.master, res);
+	if (ret)
+		return ret;
+
+	return count;
+}
+
+/*
+ * i3c_master_enable_hotjoin - Enable hotjoin
+ * @master: I3C master object
+ *
+ * Return: a 0 in case of success, an negative error code otherwise.
+ */
+int i3c_master_enable_hotjoin(struct i3c_master_controller *master)
+{
+	return i3c_set_hotjoin(master, true);
+}
+EXPORT_SYMBOL_GPL(i3c_master_enable_hotjoin);
+
+/*
+ * i3c_master_disable_hotjoin - Disable hotjoin
+ * @master: I3C master object
+ *
+ * Return: a 0 in case of success, an negative error code otherwise.
+ */
+int i3c_master_disable_hotjoin(struct i3c_master_controller *master)
+{
+	return i3c_set_hotjoin(master, false);
+}
+EXPORT_SYMBOL_GPL(i3c_master_disable_hotjoin);
+
+static ssize_t hotjoin_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+	struct i3c_bus *i3cbus = dev_to_i3cbus(dev);
+	ssize_t ret;
+
+	i3c_bus_normaluse_lock(i3cbus);
+	ret = sysfs_emit(buf, "%d\n", i3cbus->cur_master->common.master->hotjoin);
+	i3c_bus_normaluse_unlock(i3cbus);
+
+	return ret;
+}
+
+static DEVICE_ATTR_RW(hotjoin);
+
 static struct attribute *i3c_masterdev_attrs[] = {
 	&dev_attr_mode.attr,
 	&dev_attr_current_master.attr,
@@ -536,6 +618,7 @@ static struct attribute *i3c_masterdev_attrs[] = {
 	&dev_attr_pid.attr,
 	&dev_attr_dynamic_address.attr,
 	&dev_attr_hdrcap.attr,
+	&dev_attr_hotjoin.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(i3c_masterdev);
diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h
index 0b52da4f23467..65b8965968af2 100644
--- a/include/linux/i3c/master.h
+++ b/include/linux/i3c/master.h
@@ -452,6 +452,8 @@ struct i3c_master_controller_ops {
 	int (*disable_ibi)(struct i3c_dev_desc *dev);
 	void (*recycle_ibi_slot)(struct i3c_dev_desc *dev,
 				 struct i3c_ibi_slot *slot);
+	int (*enable_hotjoin)(struct i3c_master_controller *master);
+	int (*disable_hotjoin)(struct i3c_master_controller *master);
 };
 
 /**
@@ -487,6 +489,7 @@ struct i3c_master_controller {
 	const struct i3c_master_controller_ops *ops;
 	unsigned int secondary : 1;
 	unsigned int init_done : 1;
+	unsigned int hotjoin: 1;
 	struct {
 		struct list_head i3c;
 		struct list_head i2c;
@@ -543,6 +546,8 @@ int i3c_master_register(struct i3c_master_controller *master,
 			const struct i3c_master_controller_ops *ops,
 			bool secondary);
 void i3c_master_unregister(struct i3c_master_controller *master);
+int i3c_master_enable_hotjoin(struct i3c_master_controller *master);
+int i3c_master_disable_hotjoin(struct i3c_master_controller *master);
 
 /**
  * i3c_dev_get_master_data() - get master private data attached to an I3C
-- 
2.34.1



From Frank.Li at nxp.com  Fri Dec  1 14:25:31 2023
From: Frank.Li at nxp.com (Frank Li)
Date: Fri,  1 Dec 2023 17:25:31 -0500
Subject: [v5 resend 5/6] i3c: master: svc: return actual transfer data len
In-Reply-To: <20231201222532.2431484-1-Frank.Li@nxp.com>
References: <20231201222532.2431484-1-Frank.Li@nxp.com>
Message-ID: <20231201222532.2431484-6-Frank.Li@nxp.com>

I3C allow devices early terminate data transfer. So set "actual_len" to
indicate how much data get by i3c_priv_xfer.

Reviewed-by: Miquel Raynal <miquel.raynal at bootlin.com>
Signed-off-by: Frank Li <Frank.Li at nxp.com>
---

Notes:
    change from v4 to v5
    update prefix
    add Miquel's review tag

 drivers/i3c/master/svc-i3c-master.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c
index 13a8b3c2aa541..bd10bb698da0f 100644
--- a/drivers/i3c/master/svc-i3c-master.c
+++ b/drivers/i3c/master/svc-i3c-master.c
@@ -138,6 +138,7 @@ struct svc_i3c_cmd {
 	const void *out;
 	unsigned int len;
 	unsigned int actual_len;
+	struct i3c_priv_xfer *xfer;
 	bool continued;
 };
 
@@ -1061,6 +1062,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 
 	if (readl(master->regs + SVC_I3C_MERRWARN) & SVC_I3C_MERRWARN_NACK) {
 		ret = -ENXIO;
+		*actual_len = 0;
 		goto emit_stop;
 	}
 
@@ -1078,6 +1080,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 	 */
 	if (SVC_I3C_MSTATUS_IBIWON(reg)) {
 		ret = -ENXIO;
+		*actual_len = 0;
 		goto emit_stop;
 	}
 
@@ -1173,6 +1176,10 @@ static void svc_i3c_master_start_xfer_locked(struct svc_i3c_master *master)
 					  cmd->addr, cmd->in, cmd->out,
 					  cmd->len, &cmd->actual_len,
 					  cmd->continued);
+		/* cmd->xfer is NULL if I2C or CCC transfer */
+		if (cmd->xfer)
+			cmd->xfer->actual_len = cmd->actual_len;
+
 		if (ret)
 			break;
 	}
@@ -1360,6 +1367,7 @@ 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];
 
+		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;
-- 
2.34.1



From Frank.Li at nxp.com  Fri Dec  1 14:25:32 2023
From: Frank.Li at nxp.com (Frank Li)
Date: Fri,  1 Dec 2023 17:25:32 -0500
Subject: [v5 resend 6/6] i3c: add API i3c_dev_gettstatus_format1() to get target device status
In-Reply-To: <20231201222532.2431484-1-Frank.Li@nxp.com>
References: <20231201222532.2431484-1-Frank.Li@nxp.com>
Message-ID: <20231201222532.2431484-7-Frank.Li@nxp.com>

I3C standard 5.1.9.3.15 Get Device Status (GETSTATUS):
Get request for one I3C Target Device to return its current status.

Add API to fetch it with format1.

Signed-off-by: Frank Li <Frank.Li at nxp.com>
---

Notes:
    See below patch, which call i3c_dev_gettstatus_format1()
    https://lore.kernel.org/imx/202311070330.5mylauLR-lkp at intel.com/T/#t
    
    Change from v4 to v5
    - none

 drivers/i3c/device.c       | 24 ++++++++++++++++++++++++
 drivers/i3c/internals.h    |  1 +
 drivers/i3c/master.c       | 26 ++++++++++++++++++++++++++
 include/linux/i3c/device.h |  1 +
 4 files changed, 52 insertions(+)

diff --git a/drivers/i3c/device.c b/drivers/i3c/device.c
index 1a6a8703dbc3a..aa26cf50ab9c6 100644
--- a/drivers/i3c/device.c
+++ b/drivers/i3c/device.c
@@ -196,6 +196,30 @@ void i3c_device_free_ibi(struct i3c_device *dev)
 }
 EXPORT_SYMBOL_GPL(i3c_device_free_ibi);
 
+/**
+ * i3c_device_getstatus_format1() - Get device status with format 1.
+ * @dev: device for which you want to get status.
+ * @status: I3C status format 1
+ *
+ * Return: 0 in case of success, a negative error core otherwise.
+ */
+int i3c_device_getstatus_format1(struct i3c_device *dev, u16 *status)
+{
+	int ret = -EINVAL;
+
+	if (!status)
+		return -EINVAL;
+
+	i3c_bus_normaluse_lock(dev->bus);
+	if (dev->desc)
+		ret = i3c_dev_getstatus_format1_locked(dev->desc, status);
+
+	i3c_bus_normaluse_unlock(dev->bus);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(i3c_device_getstatus_format1);
+
 /**
  * i3cdev_to_dev() - Returns the device embedded in @i3cdev
  * @i3cdev: I3C device
diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h
index 908a807badaf9..976ad26ca79c2 100644
--- a/drivers/i3c/internals.h
+++ b/drivers/i3c/internals.h
@@ -24,4 +24,5 @@ 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);
+int i3c_dev_getstatus_format1_locked(struct i3c_dev_desc *dev, u16 *status);
 #endif /* I3C_INTERNAL_H */
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index d3b56c9f601e2..81611a3e3585a 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -2923,6 +2923,32 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev)
 	dev->ibi = NULL;
 }
 
+int i3c_dev_getstatus_format1_locked(struct i3c_dev_desc *dev, u16 *status)
+{
+	struct i3c_master_controller *master = i3c_dev_get_master(dev);
+	struct i3c_ccc_getstatus *format1;
+	struct i3c_ccc_cmd_dest dest;
+	struct i3c_ccc_cmd cmd;
+	int ret;
+
+	format1 = i3c_ccc_cmd_dest_init(&dest, dev->info.dyn_addr, sizeof(*format1));
+	if (!format1)
+		return -ENOMEM;
+
+	i3c_ccc_cmd_init(&cmd, true, I3C_CCC_GETSTATUS, &dest, 1);
+
+	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
+	if (ret)
+		goto out;
+
+	*status = be16_to_cpu(format1->status);
+
+out:
+	i3c_ccc_cmd_dest_cleanup(&dest);
+
+	return ret;
+}
+
 static int __init i3c_init(void)
 {
 	int res;
diff --git a/include/linux/i3c/device.h b/include/linux/i3c/device.h
index ef6217da8253b..5f511bd400f11 100644
--- a/include/linux/i3c/device.h
+++ b/include/linux/i3c/device.h
@@ -345,4 +345,5 @@ void i3c_device_free_ibi(struct i3c_device *dev);
 int i3c_device_enable_ibi(struct i3c_device *dev);
 int i3c_device_disable_ibi(struct i3c_device *dev);
 
+int i3c_device_getstatus_format1(struct i3c_device *dev, u16 *status);
 #endif /* I3C_DEV_H */
-- 
2.34.1



From Frank.Li at nxp.com  Fri Dec  1 14:25:29 2023
From: Frank.Li at nxp.com (Frank Li)
Date: Fri,  1 Dec 2023 17:25:29 -0500
Subject: [v5 resend 3/6] i3c: add actual_len in i3c_priv_xfer
In-Reply-To: <20231201222532.2431484-1-Frank.Li@nxp.com>
References: <20231201222532.2431484-1-Frank.Li@nxp.com>
Message-ID: <20231201222532.2431484-4-Frank.Li@nxp.com>

In MIPI I3C Specification:

"Ninth Bit of SDR Target Returned (Read) Data as End-of-Data: In I2C, the
ninth Data bit from Target to Controller is an ACK by the Controller. By
contrast, in I3C this bit allows the Target to end a Read, and allows the
Controller to Abort a Read. In SDR terms, the ninth bit of Read data is
referred to as the T-Bit (for ?Transition?)"

I3C allow devices early terminate data transfer. So need "actual_len" field
to indicate how much get by i3c_priv_xfer.

Reviewed-by: Miquel Raynal <miquel.raynal at bootlin.com>
Signed-off-by: Frank Li <Frank.Li at nxp.com>
---

Notes:
    change from v4 to v5
    - Add Miquel review tag

 include/linux/i3c/device.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/i3c/device.h b/include/linux/i3c/device.h
index 90fa83464f003..ef6217da8253b 100644
--- a/include/linux/i3c/device.h
+++ b/include/linux/i3c/device.h
@@ -54,6 +54,7 @@ enum i3c_hdr_mode {
  * struct i3c_priv_xfer - I3C SDR private transfer
  * @rnw: encodes the transfer direction. true for a read, false for a write
  * @len: transfer length in bytes of the transfer
+ * @actual_len: actual length in bytes are transferred by the controller
  * @data: input/output buffer
  * @data.in: input buffer. Must point to a DMA-able buffer
  * @data.out: output buffer. Must point to a DMA-able buffer
@@ -62,6 +63,7 @@ enum i3c_hdr_mode {
 struct i3c_priv_xfer {
 	u8 rnw;
 	u16 len;
+	u16 actual_len;
 	union {
 		void *in;
 		const void *out;
-- 
2.34.1



From Frank.Li at nxp.com  Fri Dec  1 14:25:28 2023
From: Frank.Li at nxp.com (Frank Li)
Date: Fri,  1 Dec 2023 17:25:28 -0500
Subject: [v5 resend 2/6] i3c: master: svc: add hot join support
In-Reply-To: <20231201222532.2431484-1-Frank.Li@nxp.com>
References: <20231201222532.2431484-1-Frank.Li@nxp.com>
Message-ID: <20231201222532.2431484-3-Frank.Li@nxp.com>

Add hot join support for svc master controller. Disable hot join defaultly.
User can use sys entry to enable hot join.

Signed-off-by: Frank Li <Frank.Li at nxp.com>
---

Notes:
    Change from v4 to v5
    - default disable hotjoin
    - add help func is_events_enabled()
    
    Change from v3 to v4
    -fix build warning
    
    All warnings (new ones prefixed by >>):
    
       drivers/i3c/master/svc-i3c-master.c:212: warning: Function parameter or member 'lock' not described in 'svc_i3c_master'
    >> drivers/i3c/master/svc-i3c-master.c:212: warning: Function parameter or member 'enabled_events' not described in 'svc_i3c_master'
       2 warnings as Errors

 drivers/i3c/master/svc-i3c-master.c | 61 +++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 4 deletions(-)

diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c
index 6b6bdd163af4f..f2058a36f869b 100644
--- a/drivers/i3c/master/svc-i3c-master.c
+++ b/drivers/i3c/master/svc-i3c-master.c
@@ -128,6 +128,9 @@
 /* This parameter depends on the implementation and may be tuned */
 #define SVC_I3C_FIFO_SIZE 16
 
+#define SVC_I3C_EVENT_IBI	BIT(0)
+#define SVC_I3C_EVENT_HOTJOIN	BIT(1)
+
 struct svc_i3c_cmd {
 	u8 addr;
 	bool rnw;
@@ -176,6 +179,7 @@ struct svc_i3c_regs_save {
  * @ibi.tbq_slot: To be queued IBI slot
  * @ibi.lock: IBI lock
  * @lock: Transfer lock, protect between IBI work thread and callbacks from master
+ * @enabled_events: Bit masks for enable events (IBI, HotJoin).
  */
 struct svc_i3c_master {
 	struct i3c_master_controller base;
@@ -205,6 +209,7 @@ struct svc_i3c_master {
 		spinlock_t lock;
 	} ibi;
 	struct mutex lock;
+	int enabled_events;
 };
 
 /**
@@ -219,6 +224,11 @@ struct svc_i3c_i2c_dev_data {
 	struct i3c_generic_ibi_pool *ibi_pool;
 };
 
+static inline bool is_events_enabled(struct svc_i3c_master *master, u32 mask)
+{
+	return !!(master->enabled_events & mask);
+}
+
 static bool svc_i3c_master_error(struct svc_i3c_master *master)
 {
 	u32 mstatus, merrwarn;
@@ -428,13 +438,16 @@ static void svc_i3c_master_ibi_work(struct work_struct *work)
 	switch (ibitype) {
 	case SVC_I3C_MSTATUS_IBITYPE_IBI:
 		dev = svc_i3c_master_dev_from_addr(master, ibiaddr);
-		if (!dev)
+		if (!dev || !is_events_enabled(master, SVC_I3C_EVENT_IBI))
 			svc_i3c_master_nack_ibi(master);
 		else
 			svc_i3c_master_handle_ibi(master, dev);
 		break;
 	case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN:
-		svc_i3c_master_ack_ibi(master, false);
+		if (is_events_enabled(master, SVC_I3C_EVENT_HOTJOIN))
+			svc_i3c_master_ack_ibi(master, false);
+		else
+			svc_i3c_master_nack_ibi(master);
 		break;
 	case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST:
 		svc_i3c_master_nack_ibi(master);
@@ -471,7 +484,9 @@ static void svc_i3c_master_ibi_work(struct work_struct *work)
 		svc_i3c_master_emit_stop(master);
 		break;
 	case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN:
-		queue_work(master->base.wq, &master->hj_work);
+		svc_i3c_master_emit_stop(master);
+		if (is_events_enabled(master, SVC_I3C_EVENT_HOTJOIN))
+			queue_work(master->base.wq, &master->hj_work);
 		break;
 	case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST:
 	default:
@@ -1471,6 +1486,7 @@ static int svc_i3c_master_enable_ibi(struct i3c_dev_desc *dev)
 		return ret;
 	}
 
+	master->enabled_events |= SVC_I3C_EVENT_IBI;
 	svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART);
 
 	return i3c_master_enec_locked(m, dev->info.dyn_addr, I3C_CCC_EVENT_SIR);
@@ -1482,7 +1498,9 @@ static int svc_i3c_master_disable_ibi(struct i3c_dev_desc *dev)
 	struct svc_i3c_master *master = to_svc_i3c_master(m);
 	int ret;
 
-	svc_i3c_master_disable_interrupts(master);
+	master->enabled_events &= ~SVC_I3C_EVENT_IBI;
+	if (!master->enabled_events)
+		svc_i3c_master_disable_interrupts(master);
 
 	ret = i3c_master_disec_locked(m, dev->info.dyn_addr, I3C_CCC_EVENT_SIR);
 
@@ -1492,6 +1510,39 @@ static int svc_i3c_master_disable_ibi(struct i3c_dev_desc *dev)
 	return ret;
 }
 
+static int svc_i3c_master_enable_hotjoin(struct i3c_master_controller *m)
+{
+	struct svc_i3c_master *master = to_svc_i3c_master(m);
+	int ret;
+
+	ret = pm_runtime_resume_and_get(master->dev);
+	if (ret < 0) {
+		dev_err(master->dev, "<%s> Cannot get runtime PM.\n", __func__);
+		return ret;
+	}
+
+	master->enabled_events |= SVC_I3C_EVENT_HOTJOIN;
+
+	svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART);
+
+	return 0;
+}
+
+static int svc_i3c_master_disable_hotjoin(struct i3c_master_controller *m)
+{
+	struct svc_i3c_master *master = to_svc_i3c_master(m);
+
+	master->enabled_events &= ~SVC_I3C_EVENT_HOTJOIN;
+
+	if (!master->enabled_events)
+		svc_i3c_master_disable_interrupts(master);
+
+	pm_runtime_mark_last_busy(master->dev);
+	pm_runtime_put_autosuspend(master->dev);
+
+	return 0;
+}
+
 static void svc_i3c_master_recycle_ibi_slot(struct i3c_dev_desc *dev,
 					    struct i3c_ibi_slot *slot)
 {
@@ -1518,6 +1569,8 @@ static const struct i3c_master_controller_ops svc_i3c_master_ops = {
 	.recycle_ibi_slot = svc_i3c_master_recycle_ibi_slot,
 	.enable_ibi = svc_i3c_master_enable_ibi,
 	.disable_ibi = svc_i3c_master_disable_ibi,
+	.enable_hotjoin = svc_i3c_master_enable_hotjoin,
+	.disable_hotjoin = svc_i3c_master_disable_hotjoin,
 };
 
 static int svc_i3c_master_prepare_clks(struct svc_i3c_master *master)
-- 
2.34.1



From Frank.Li at nxp.com  Fri Dec  1 14:25:30 2023
From: Frank.Li at nxp.com (Frank Li)
Date: Fri,  1 Dec 2023 17:25:30 -0500
Subject: [v5 resend 4/6] i3c: master: svc: rename read_len as actual_len
In-Reply-To: <20231201222532.2431484-1-Frank.Li@nxp.com>
References: <20231201222532.2431484-1-Frank.Li@nxp.com>
Message-ID: <20231201222532.2431484-5-Frank.Li@nxp.com>

I3C transfer (SDR), target can early terminate read transfer.
I3C transfer (HDR), target can end write transfer.
I2C transfer, target can NACK write transfer.

'actual_len' is better name than 'read_len'.

Reviewed-by: Miquel Raynal <miquel.raynal at bootlin.com>
Signed-off-by: Frank Li <Frank.Li at nxp.com>
---

Notes:
    change from v4 to v5:
    use i3c: master: svc: prefix

 drivers/i3c/master/svc-i3c-master.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c
index f2058a36f869b..13a8b3c2aa541 100644
--- a/drivers/i3c/master/svc-i3c-master.c
+++ b/drivers/i3c/master/svc-i3c-master.c
@@ -137,7 +137,7 @@ struct svc_i3c_cmd {
 	u8 *in;
 	const void *out;
 	unsigned int len;
-	unsigned int read_len;
+	unsigned int actual_len;
 	bool continued;
 };
 
@@ -1038,7 +1038,7 @@ 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,
 			       u8 *in, const u8 *out, unsigned int xfer_len,
-			       unsigned int *read_len, bool continued)
+			       unsigned int *actual_len, bool continued)
 {
 	u32 reg;
 	int ret;
@@ -1051,7 +1051,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 	       SVC_I3C_MCTRL_IBIRESP_NACK |
 	       SVC_I3C_MCTRL_DIR(rnw) |
 	       SVC_I3C_MCTRL_ADDR(addr) |
-	       SVC_I3C_MCTRL_RDTERM(*read_len),
+	       SVC_I3C_MCTRL_RDTERM(*actual_len),
 	       master->regs + SVC_I3C_MCTRL);
 
 	ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg,
@@ -1089,7 +1089,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 		goto emit_stop;
 
 	if (rnw)
-		*read_len = ret;
+		*actual_len = ret;
 
 	ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg,
 				 SVC_I3C_MSTATUS_COMPLETE(reg), 0, 1000);
@@ -1171,7 +1171,7 @@ static void svc_i3c_master_start_xfer_locked(struct svc_i3c_master *master)
 
 		ret = svc_i3c_master_xfer(master, cmd->rnw, xfer->type,
 					  cmd->addr, cmd->in, cmd->out,
-					  cmd->len, &cmd->read_len,
+					  cmd->len, &cmd->actual_len,
 					  cmd->continued);
 		if (ret)
 			break;
@@ -1257,7 +1257,7 @@ static int svc_i3c_master_send_bdcast_ccc_cmd(struct svc_i3c_master *master,
 	cmd->in = NULL;
 	cmd->out = buf;
 	cmd->len = xfer_len;
-	cmd->read_len = 0;
+	cmd->actual_len = 0;
 	cmd->continued = false;
 
 	mutex_lock(&master->lock);
@@ -1277,7 +1277,7 @@ static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master,
 					      struct i3c_ccc_cmd *ccc)
 {
 	unsigned int xfer_len = ccc->dests[0].payload.len;
-	unsigned int read_len = ccc->rnw ? xfer_len : 0;
+	unsigned int actual_len = ccc->rnw ? xfer_len : 0;
 	struct svc_i3c_xfer *xfer;
 	struct svc_i3c_cmd *cmd;
 	int ret;
@@ -1295,7 +1295,7 @@ static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master,
 	cmd->in = NULL;
 	cmd->out = &ccc->id;
 	cmd->len = 1;
-	cmd->read_len = 0;
+	cmd->actual_len = 0;
 	cmd->continued = true;
 
 	/* Directed message */
@@ -1305,7 +1305,7 @@ static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master,
 	cmd->in = ccc->rnw ? ccc->dests[0].payload.data : NULL;
 	cmd->out = ccc->rnw ? NULL : ccc->dests[0].payload.data,
 	cmd->len = xfer_len;
-	cmd->read_len = read_len;
+	cmd->actual_len = actual_len;
 	cmd->continued = false;
 
 	mutex_lock(&master->lock);
@@ -1314,8 +1314,8 @@ static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master,
 		svc_i3c_master_dequeue_xfer(master, xfer);
 	mutex_unlock(&master->lock);
 
-	if (cmd->read_len != xfer_len)
-		ccc->dests[0].payload.len = cmd->read_len;
+	if (cmd->actual_len != xfer_len)
+		ccc->dests[0].payload.len = cmd->actual_len;
 
 	ret = xfer->ret;
 	svc_i3c_master_free_xfer(xfer);
@@ -1365,7 +1365,7 @@ static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev,
 		cmd->in = xfers[i].rnw ? xfers[i].data.in : NULL;
 		cmd->out = xfers[i].rnw ? NULL : xfers[i].data.out;
 		cmd->len = xfers[i].len;
-		cmd->read_len = xfers[i].rnw ? xfers[i].len : 0;
+		cmd->actual_len = xfers[i].rnw ? xfers[i].len : 0;
 		cmd->continued = (i + 1) < nxfers;
 	}
 
@@ -1405,7 +1405,7 @@ static int svc_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
 		cmd->in = cmd->rnw ? xfers[i].buf : NULL;
 		cmd->out = cmd->rnw ? NULL : xfers[i].buf;
 		cmd->len = xfers[i].len;
-		cmd->read_len = cmd->rnw ? xfers[i].len : 0;
+		cmd->actual_len = cmd->rnw ? xfers[i].len : 0;
 		cmd->continued = (i + 1 < nxfers);
 	}
 
-- 
2.34.1



From jirislaby at kernel.org  Tue Dec  5 01:56:09 2023
From: jirislaby at kernel.org (Jiri Slaby)
Date: Tue, 5 Dec 2023 10:56:09 +0100
Subject: [PATCH v5 7/7] tty: i3c: add TTY over I3C master support
In-Reply-To: <20231130224408.3591288-8-Frank.Li@nxp.com>
References: <20231130224408.3591288-1-Frank.Li@nxp.com>
 <20231130224408.3591288-8-Frank.Li@nxp.com>
Message-ID: <2c3824d7-0960-4de7-8fae-01478fdef8fe@kernel.org>

On 30. 11. 23, 23:44, Frank Li wrote:
> In typical embedded Linux systems, UART consoles require at least two pins,
> TX and RX. In scenarios where I2C/I3C devices like sensors or PMICs are
> present, we can save these two pins by using this driver. Pins is crucial
> resources, especially in small chip packages.
> 
> This introduces support for using the I3C bus to transfer console tty data,
> effectively replacing the need for dedicated UART pins. This not only
> conserves valuable pin resources but also facilitates testing of I3C's
> advanced features, including early termination, in-band interrupt (IBI)
> support, and the creation of more complex data patterns. Additionally,
> it aids in identifying and addressing issues within the I3C controller
> driver.
> 
> Signed-off-by: Frank Li <Frank.Li at nxp.com>
...
> --- a/drivers/tty/Kconfig
> +++ b/drivers/tty/Kconfig
> @@ -412,6 +412,19 @@ config RPMSG_TTY
>   	  To compile this driver as a module, choose M here: the module will be
>   	  called rpmsg_tty.
>   
> +config I3C_TTY
> +	tristate "TTY over I3C"
> +	depends on I3C
> +	help
> +	  Select this options if you'd like use TTY over I3C master controller

this option
to use
add a period to the end.

> +
> +	  This makes it possible for user-space programs to send and receive
> +	  data as a standard tty protocol. I3C provide relatively higher data
> +	  transfer rate and less pin numbers, SDA/SCL are shared with other
> +	  devices.
> +
> +	  If unsure, say N
> +
>   endif # TTY
>   
>   source "drivers/tty/serdev/Kconfig"
...
> --- /dev/null
> +++ b/drivers/tty/i3c_tty.c
> @@ -0,0 +1,443 @@
...
> +struct ttyi3c_port {
> +	struct tty_port port;
> +	int minor;
> +	spinlock_t xlock; /* protect xmit */
> +	char tx_buff[I3C_TTY_TRANS_SIZE];
> +	char rx_buff[I3C_TTY_TRANS_SIZE];

These should be u8 as per the other changes throughout the tty layer.

> +	struct i3c_device *i3cdev;
> +	struct work_struct txwork;
> +	struct work_struct rxwork;
> +	struct completion txcomplete;
> +	unsigned long status;
> +	int buf_overrun;

Can this be ever negative?

> +};
> +
> +struct workqueue_struct *workqueue;

Is this related:
     Still below items not be fixed (according to Jiri Slaby's comments)
     - rxwork thread: need trigger from two position.
     - common thread queue: need some suggestion
?

As I don't remember, could you elaborate again why you need your own 
workqueue? You need to do it in the commit log anyway.

...
> +static ssize_t i3c_write(struct tty_struct *tty, const unsigned char *buf, size_t count)
> +{
> +	struct ttyi3c_port *sport = tty->driver_data;
> +	unsigned long flags;
> +	bool is_empty;
> +	int ret;
> +
> +	spin_lock_irqsave(&sport->xlock, flags);
> +	ret = kfifo_in(&sport->port.xmit_fifo, buf, count);
> +	is_empty = kfifo_is_empty(&sport->port.xmit_fifo);
> +	spin_unlock_irqrestore(&sport->xlock, flags);
> +
> +	if (!is_empty)
> +		queue_work(workqueue, &sport->txwork);
> +
> +	return ret;
> +}
> +
> +static int i3c_put_char(struct tty_struct *tty, unsigned char ch)
> +{
> +	struct ttyi3c_port *sport = tty->driver_data;
> +	unsigned long flags;
> +	int ret = 0;

Unneeded initialization.

> +
> +	spin_lock_irqsave(&sport->xlock, flags);
> +	ret = kfifo_put(&sport->port.xmit_fifo, ch);
> +	spin_unlock_irqrestore(&sport->xlock, flags);
> +
> +	return ret;
> +}
...
> +static void tty_i3c_rxwork(struct work_struct *work)
> +{
> +	struct ttyi3c_port *sport = container_of(work, struct ttyi3c_port, rxwork);
> +	struct i3c_priv_xfer xfers;
> +	int retry = I3C_TTY_RETRY;

Likely, should be unsigned.

> +	u16 status = BIT(0);
> +	int ret;
> +
> +	memset(&xfers, 0, sizeof(xfers));
> +	xfers.data.in = sport->rx_buff;
> +	xfers.len = I3C_TTY_TRANS_SIZE;
> +	xfers.rnw = 1;
> +
> +	do {
> +		if (test_bit(I3C_TTY_RX_STOP, &sport->status))
> +			break;
> +
> +		i3c_device_do_priv_xfers(sport->i3cdev, &xfers, 1);
> +
> +		if (xfers.actual_len) {
> +			ret = tty_insert_flip_string(&sport->port, sport->rx_buff,
> +						     xfers.actual_len);
> +			if (ret < xfers.actual_len)
> +				sport->buf_overrun++;
> +
> +			retry = I3C_TTY_RETRY;
> +			continue;
> +		}
> +
> +		status = BIT(0);
> +		i3c_device_getstatus_format1(sport->i3cdev, &status);
> +		/*
> +		 * Target side needs some time to fill data into fifo. Target side may not
> +		 * have hardware update status in real time. Software update status always
> +		 * needs some delays.
> +		 *
> +		 * Generally, target side have circular buffer in memory, it will be moved
> +		 * into FIFO by CPU or DMA. 'status' just show if circular buffer empty. But
> +		 * there are gap, especially CPU have not response irq to fill FIFO in time.
> +		 * So xfers.actual will be zero, wait for little time to avoid flood
> +		 * transfer in i3c bus.
> +		 */
> +		usleep_range(I3C_TTY_YIELD_US, 10 * I3C_TTY_YIELD_US);
> +		retry--;
> +
> +	} while (retry && (status & BIT(0)));
> +
> +	tty_flip_buffer_push(&sport->port);
> +}
> +
> +static void tty_i3c_txwork(struct work_struct *work)
> +{
> +	struct ttyi3c_port *sport = container_of(work, struct ttyi3c_port, txwork);
> +	struct i3c_priv_xfer xfers;
> +	int retry = I3C_TTY_RETRY;

Detto.

> +	unsigned long flags;
> +	int ret;
> +
> +	xfers.rnw = 0;
> +	xfers.data.out = sport->tx_buff;
> +
> +	while (!kfifo_is_empty(&sport->port.xmit_fifo) && retry) {
> +		xfers.len = kfifo_len(&sport->port.xmit_fifo);
> +		xfers.len = min_t(u16, I3C_TTY_TRANS_SIZE, xfers.len);
> +
> +		xfers.len = kfifo_out_peek(&sport->port.xmit_fifo, sport->tx_buff, xfers.len);

Can this simply be:
xfers.len = kfifo_out_peek(&sport->port.xmit_fifo, sport->tx_buff, 
I3C_TTY_TRANS_SIZE);
?

> +
> +		ret = i3c_device_do_priv_xfers(sport->i3cdev, &xfers, 1);
> +		if (ret) {
> +			/*
> +			 * Target side may not move data out of FIFO. delay can't resolve problem,
> +			 * just reduce some possiblity. Target can't end I3C SDR mode write
> +			 * transfer, discard data is reasonable when FIFO overrun.
> +			 */
> +			usleep_range(I3C_TTY_YIELD_US, 10 * I3C_TTY_YIELD_US);
> +			retry--;
> +		} else {
> +			retry = I3C_TTY_RETRY;
> +			ret = kfifo_out(&sport->port.xmit_fifo, sport->tx_buff, xfers.len);

Just to make sure: xfers.len is nor overwritten by 
i3c_device_do_priv_xfers(), right?

> +		}
> +	}
> +
> +	spin_lock_irqsave(&sport->xlock, flags);

Why do you take the lock here, but not during the kfifo operations above?

> +	if (kfifo_is_empty(&sport->port.xmit_fifo))
> +		complete(&sport->txcomplete);
> +	spin_unlock_irqrestore(&sport->xlock, flags);
> +}

> +static int __init i3c_tty_init(void)
> +{
> +	int ret;
> +
> +	i3c_tty_driver = tty_alloc_driver(I3C_TTY_MINORS,
> +					  TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV);
> +
> +	if (IS_ERR(i3c_tty_driver))
> +		return PTR_ERR(i3c_tty_driver);
> +
> +	i3c_tty_driver->driver_name = "ttyI3C";
> +	i3c_tty_driver->name = "ttyI3C";
> +	i3c_tty_driver->minor_start = 0,
> +	i3c_tty_driver->type = TTY_DRIVER_TYPE_SERIAL,
> +	i3c_tty_driver->subtype = SERIAL_TYPE_NORMAL,
> +	i3c_tty_driver->init_termios = tty_std_termios;
> +	i3c_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL |
> +					       CLOCAL;
> +	i3c_tty_driver->init_termios.c_lflag = 0;
> +
> +	tty_set_operations(i3c_tty_driver, &i3c_tty_ops);
> +
> +	ret = tty_register_driver(i3c_tty_driver);
> +	if (ret)
> +		goto err_tty_register_driver;
> +
> +	ret = i3c_driver_register(&i3c_driver);
> +	if (ret)
> +		goto err_i3c_driver_register;
> +
> +	workqueue = alloc_workqueue("ttyI3C", 0, 0);

Can it happen that you already queue something on this wq, while not 
allocated yet? I mean: should this be done first in i3c_tty_init()?

> +	if (!workqueue) {
> +		ret = PTR_ERR(workqueue);
> +		goto err_alloc_workqueue;
> +	}
> +
> +	return 0;
> +
> +err_alloc_workqueue:
> +	i3c_driver_unregister(&i3c_driver);
> +
> +err_i3c_driver_register:
> +	tty_unregister_driver(i3c_tty_driver);
> +
> +err_tty_register_driver:
> +	tty_driver_kref_put(i3c_tty_driver);
> +
> +	return ret;
> +}
> +
> +static void __exit i3c_tty_exit(void)
> +{
> +	i3c_driver_unregister(&i3c_driver);
> +	tty_unregister_driver(i3c_tty_driver);
> +	tty_driver_kref_put(i3c_tty_driver);
> +	idr_destroy(&i3c_tty_minors);

What about the wq?

> +}

regards,
-- 
js
suse labs



From Frank.li at nxp.com  Tue Dec  5 07:50:46 2023
From: Frank.li at nxp.com (Frank Li)
Date: Tue, 5 Dec 2023 10:50:46 -0500
Subject: [PATCH v5 7/7] tty: i3c: add TTY over I3C master support
In-Reply-To: <2c3824d7-0960-4de7-8fae-01478fdef8fe@kernel.org>
References: <20231130224408.3591288-1-Frank.Li@nxp.com>
 <20231130224408.3591288-8-Frank.Li@nxp.com>
 <2c3824d7-0960-4de7-8fae-01478fdef8fe@kernel.org>
Message-ID: <ZW9G1qVlYOS2TQ+l@lizhi-Precision-Tower-5810>

On Tue, Dec 05, 2023 at 10:56:09AM +0100, Jiri Slaby wrote:
> On 30. 11. 23, 23:44, Frank Li wrote:
> > In typical embedded Linux systems, UART consoles require at least two pins,
> > TX and RX. In scenarios where I2C/I3C devices like sensors or PMICs are
> > present, we can save these two pins by using this driver. Pins is crucial
> > resources, especially in small chip packages.
> > 
> > This introduces support for using the I3C bus to transfer console tty data,
> > effectively replacing the need for dedicated UART pins. This not only
> > conserves valuable pin resources but also facilitates testing of I3C's
> > advanced features, including early termination, in-band interrupt (IBI)
> > support, and the creation of more complex data patterns. Additionally,
> > it aids in identifying and addressing issues within the I3C controller
> > driver.
> > 
> > Signed-off-by: Frank Li <Frank.Li at nxp.com>
> ...
> > --- a/drivers/tty/Kconfig
> > +++ b/drivers/tty/Kconfig
> > @@ -412,6 +412,19 @@ config RPMSG_TTY
> >   	  To compile this driver as a module, choose M here: the module will be
> >   	  called rpmsg_tty.
> > +config I3C_TTY
> > +	tristate "TTY over I3C"
> > +	depends on I3C
> > +	help
> > +	  Select this options if you'd like use TTY over I3C master controller
> 
> this option
> to use
> add a period to the end.
> 
> > +
> > +	  This makes it possible for user-space programs to send and receive
> > +	  data as a standard tty protocol. I3C provide relatively higher data
> > +	  transfer rate and less pin numbers, SDA/SCL are shared with other
> > +	  devices.
> > +
> > +	  If unsure, say N
> > +
> >   endif # TTY
> >   source "drivers/tty/serdev/Kconfig"
> ...
> > --- /dev/null
> > +++ b/drivers/tty/i3c_tty.c
> > @@ -0,0 +1,443 @@
> ...
> > +struct ttyi3c_port {
> > +	struct tty_port port;
> > +	int minor;
> > +	spinlock_t xlock; /* protect xmit */
> > +	char tx_buff[I3C_TTY_TRANS_SIZE];
> > +	char rx_buff[I3C_TTY_TRANS_SIZE];
> 
> These should be u8 as per the other changes throughout the tty layer.
> 
> > +	struct i3c_device *i3cdev;
> > +	struct work_struct txwork;
> > +	struct work_struct rxwork;
> > +	struct completion txcomplete;
> > +	unsigned long status;
> > +	int buf_overrun;
> 
> Can this be ever negative?
> 
> > +};
> > +
> > +struct workqueue_struct *workqueue;
> 
> Is this related:
>     Still below items not be fixed (according to Jiri Slaby's comments)
>     - rxwork thread: need trigger from two position.
>     - common thread queue: need some suggestion
> ?
> 
> As I don't remember, could you elaborate again why you need your own
> workqueue? You need to do it in the commit log anyway.

I just learn from other drivers, such as USB ACM, usb gadget ACM driver.
If use common workqueue, which one prefered.

I will send fixed version after i3c part accepted.

Frank
> 
> ...
> > +static ssize_t i3c_write(struct tty_struct *tty, const unsigned char *buf, size_t count)
> > +{
> > +	struct ttyi3c_port *sport = tty->driver_data;
> > +	unsigned long flags;
> > +	bool is_empty;
> > +	int ret;
> > +
> > +	spin_lock_irqsave(&sport->xlock, flags);
> > +	ret = kfifo_in(&sport->port.xmit_fifo, buf, count);
> > +	is_empty = kfifo_is_empty(&sport->port.xmit_fifo);
> > +	spin_unlock_irqrestore(&sport->xlock, flags);
> > +
> > +	if (!is_empty)
> > +		queue_work(workqueue, &sport->txwork);
> > +
> > +	return ret;
> > +}
> > +
> > +static int i3c_put_char(struct tty_struct *tty, unsigned char ch)
> > +{
> > +	struct ttyi3c_port *sport = tty->driver_data;
> > +	unsigned long flags;
> > +	int ret = 0;
> 
> Unneeded initialization.
> 
> > +
> > +	spin_lock_irqsave(&sport->xlock, flags);
> > +	ret = kfifo_put(&sport->port.xmit_fifo, ch);
> > +	spin_unlock_irqrestore(&sport->xlock, flags);
> > +
> > +	return ret;
> > +}
> ...
> > +static void tty_i3c_rxwork(struct work_struct *work)
> > +{
> > +	struct ttyi3c_port *sport = container_of(work, struct ttyi3c_port, rxwork);
> > +	struct i3c_priv_xfer xfers;
> > +	int retry = I3C_TTY_RETRY;
> 
> Likely, should be unsigned.
> 
> > +	u16 status = BIT(0);
> > +	int ret;
> > +
> > +	memset(&xfers, 0, sizeof(xfers));
> > +	xfers.data.in = sport->rx_buff;
> > +	xfers.len = I3C_TTY_TRANS_SIZE;
> > +	xfers.rnw = 1;
> > +
> > +	do {
> > +		if (test_bit(I3C_TTY_RX_STOP, &sport->status))
> > +			break;
> > +
> > +		i3c_device_do_priv_xfers(sport->i3cdev, &xfers, 1);
> > +
> > +		if (xfers.actual_len) {
> > +			ret = tty_insert_flip_string(&sport->port, sport->rx_buff,
> > +						     xfers.actual_len);
> > +			if (ret < xfers.actual_len)
> > +				sport->buf_overrun++;
> > +
> > +			retry = I3C_TTY_RETRY;
> > +			continue;
> > +		}
> > +
> > +		status = BIT(0);
> > +		i3c_device_getstatus_format1(sport->i3cdev, &status);
> > +		/*
> > +		 * Target side needs some time to fill data into fifo. Target side may not
> > +		 * have hardware update status in real time. Software update status always
> > +		 * needs some delays.
> > +		 *
> > +		 * Generally, target side have circular buffer in memory, it will be moved
> > +		 * into FIFO by CPU or DMA. 'status' just show if circular buffer empty. But
> > +		 * there are gap, especially CPU have not response irq to fill FIFO in time.
> > +		 * So xfers.actual will be zero, wait for little time to avoid flood
> > +		 * transfer in i3c bus.
> > +		 */
> > +		usleep_range(I3C_TTY_YIELD_US, 10 * I3C_TTY_YIELD_US);
> > +		retry--;
> > +
> > +	} while (retry && (status & BIT(0)));
> > +
> > +	tty_flip_buffer_push(&sport->port);
> > +}
> > +
> > +static void tty_i3c_txwork(struct work_struct *work)
> > +{
> > +	struct ttyi3c_port *sport = container_of(work, struct ttyi3c_port, txwork);
> > +	struct i3c_priv_xfer xfers;
> > +	int retry = I3C_TTY_RETRY;
> 
> Detto.
> 
> > +	unsigned long flags;
> > +	int ret;
> > +
> > +	xfers.rnw = 0;
> > +	xfers.data.out = sport->tx_buff;
> > +
> > +	while (!kfifo_is_empty(&sport->port.xmit_fifo) && retry) {
> > +		xfers.len = kfifo_len(&sport->port.xmit_fifo);
> > +		xfers.len = min_t(u16, I3C_TTY_TRANS_SIZE, xfers.len);
> > +
> > +		xfers.len = kfifo_out_peek(&sport->port.xmit_fifo, sport->tx_buff, xfers.len);
> 
> Can this simply be:
> xfers.len = kfifo_out_peek(&sport->port.xmit_fifo, sport->tx_buff,
> I3C_TTY_TRANS_SIZE);
> ?
> 
> > +
> > +		ret = i3c_device_do_priv_xfers(sport->i3cdev, &xfers, 1);
> > +		if (ret) {
> > +			/*
> > +			 * Target side may not move data out of FIFO. delay can't resolve problem,
> > +			 * just reduce some possiblity. Target can't end I3C SDR mode write
> > +			 * transfer, discard data is reasonable when FIFO overrun.
> > +			 */
> > +			usleep_range(I3C_TTY_YIELD_US, 10 * I3C_TTY_YIELD_US);
> > +			retry--;
> > +		} else {
> > +			retry = I3C_TTY_RETRY;
> > +			ret = kfifo_out(&sport->port.xmit_fifo, sport->tx_buff, xfers.len);
> 
> Just to make sure: xfers.len is nor overwritten by
> i3c_device_do_priv_xfers(), right?
> 
> > +		}
> > +	}
> > +
> > +	spin_lock_irqsave(&sport->xlock, flags);
> 
> Why do you take the lock here, but not during the kfifo operations above?
> 
> > +	if (kfifo_is_empty(&sport->port.xmit_fifo))
> > +		complete(&sport->txcomplete);
> > +	spin_unlock_irqrestore(&sport->xlock, flags);
> > +}
> 
> > +static int __init i3c_tty_init(void)
> > +{
> > +	int ret;
> > +
> > +	i3c_tty_driver = tty_alloc_driver(I3C_TTY_MINORS,
> > +					  TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV);
> > +
> > +	if (IS_ERR(i3c_tty_driver))
> > +		return PTR_ERR(i3c_tty_driver);
> > +
> > +	i3c_tty_driver->driver_name = "ttyI3C";
> > +	i3c_tty_driver->name = "ttyI3C";
> > +	i3c_tty_driver->minor_start = 0,
> > +	i3c_tty_driver->type = TTY_DRIVER_TYPE_SERIAL,
> > +	i3c_tty_driver->subtype = SERIAL_TYPE_NORMAL,
> > +	i3c_tty_driver->init_termios = tty_std_termios;
> > +	i3c_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL |
> > +					       CLOCAL;
> > +	i3c_tty_driver->init_termios.c_lflag = 0;
> > +
> > +	tty_set_operations(i3c_tty_driver, &i3c_tty_ops);
> > +
> > +	ret = tty_register_driver(i3c_tty_driver);
> > +	if (ret)
> > +		goto err_tty_register_driver;
> > +
> > +	ret = i3c_driver_register(&i3c_driver);
> > +	if (ret)
> > +		goto err_i3c_driver_register;
> > +
> > +	workqueue = alloc_workqueue("ttyI3C", 0, 0);
> 
> Can it happen that you already queue something on this wq, while not
> allocated yet? I mean: should this be done first in i3c_tty_init()?
> 
> > +	if (!workqueue) {
> > +		ret = PTR_ERR(workqueue);
> > +		goto err_alloc_workqueue;
> > +	}
> > +
> > +	return 0;
> > +
> > +err_alloc_workqueue:
> > +	i3c_driver_unregister(&i3c_driver);
> > +
> > +err_i3c_driver_register:
> > +	tty_unregister_driver(i3c_tty_driver);
> > +
> > +err_tty_register_driver:
> > +	tty_driver_kref_put(i3c_tty_driver);
> > +
> > +	return ret;
> > +}
> > +
> > +static void __exit i3c_tty_exit(void)
> > +{
> > +	i3c_driver_unregister(&i3c_driver);
> > +	tty_unregister_driver(i3c_tty_driver);
> > +	tty_driver_kref_put(i3c_tty_driver);
> > +	idr_destroy(&i3c_tty_minors);
> 
> What about the wq?
> 
> > +}
> 
> regards,
> -- 
> js
> suse labs
> 


From Frank.li at nxp.com  Tue Dec  5 21:46:15 2023
From: Frank.li at nxp.com (Frank Li)
Date: Wed, 6 Dec 2023 00:46:15 -0500
Subject: [PATCH v2 2/2] arm64: dts: freescale: imx93: add i3c1 and i3c2
In-Reply-To: <20231127-cherisher-falsify-8193656e8872@wendy>
References: <20231017194657.3199749-1-Frank.Li@nxp.com>
 <20231017194657.3199749-2-Frank.Li@nxp.com>
 <ZUz/8fBWtnwdSW9w@lizhi-Precision-Tower-5810>
 <20231127022140.GJ87953@dragon>
 <20231127-cherisher-falsify-8193656e8872@wendy>
Message-ID: <ZXAKp1WS97cAI5X2@lizhi-Precision-Tower-5810>

On Mon, Nov 27, 2023 at 09:35:39AM +0000, Conor Dooley wrote:
> On Mon, Nov 27, 2023 at 10:21:40AM +0800, Shawn Guo wrote:
> > On Thu, Nov 09, 2023 at 10:51:13AM -0500, Frank Li wrote:
> > > On Tue, Oct 17, 2023 at 03:46:57PM -0400, Frank Li wrote:
> > > > Add I3C1 and I3C2.
> > > > 
> > > > Signed-off-by: Frank Li <Frank.Li at nxp.com>
> > > > ---
> > > 
> > > @Guo Shawn:
> > > 
> > > Driver part already merged. 
> > > 
> > > Please pick up dts part
> > 
> > Rob had a comment [1] about SoC specific compatible.  That's not what we
> > want?
> > 
> > Shawn
> > 
> > [1] https://lkml.iu.edu/hypermail/linux/kernel/2310.2/03035.html
> 
> Yeah, Rob's request here looks valid to me. Should just be a bindings
> change Frank & fall back to the "silvaco,i3c-master-v1" compatible.
> 
> Cheers,
> Conor.

@shawn:
	rob agree on "silvaco,i3c-master-v1" compatible.

Frank


From shawnguo at kernel.org  Wed Dec  6 01:31:06 2023
From: shawnguo at kernel.org (Shawn Guo)
Date: Wed, 6 Dec 2023 17:31:06 +0800
Subject: [PATCH v2 2/2] arm64: dts: freescale: imx93: add i3c1 and i3c2
In-Reply-To: <ZXAKp1WS97cAI5X2@lizhi-Precision-Tower-5810>
References: <20231017194657.3199749-1-Frank.Li@nxp.com>
 <20231017194657.3199749-2-Frank.Li@nxp.com>
 <ZUz/8fBWtnwdSW9w@lizhi-Precision-Tower-5810>
 <20231127022140.GJ87953@dragon>
 <20231127-cherisher-falsify-8193656e8872@wendy>
 <ZXAKp1WS97cAI5X2@lizhi-Precision-Tower-5810>
Message-ID: <20231206093106.GE270430@dragon>

On Wed, Dec 06, 2023 at 12:46:15AM -0500, Frank Li wrote:
> On Mon, Nov 27, 2023 at 09:35:39AM +0000, Conor Dooley wrote:
> > On Mon, Nov 27, 2023 at 10:21:40AM +0800, Shawn Guo wrote:
> > > On Thu, Nov 09, 2023 at 10:51:13AM -0500, Frank Li wrote:
> > > > On Tue, Oct 17, 2023 at 03:46:57PM -0400, Frank Li wrote:
> > > > > Add I3C1 and I3C2.
> > > > > 
> > > > > Signed-off-by: Frank Li <Frank.Li at nxp.com>
> > > > > ---
> > > > 
> > > > @Guo Shawn:
> > > > 
> > > > Driver part already merged. 
> > > > 
> > > > Please pick up dts part
> > > 
> > > Rob had a comment [1] about SoC specific compatible.  That's not what we
> > > want?
> > > 
> > > Shawn
> > > 
> > > [1] https://lkml.iu.edu/hypermail/linux/kernel/2310.2/03035.html
> > 
> > Yeah, Rob's request here looks valid to me. Should just be a bindings
> > change Frank & fall back to the "silvaco,i3c-master-v1" compatible.
> > 
> > Cheers,
> > Conor.
> 
> @shawn:
> 	rob agree on "silvaco,i3c-master-v1" compatible.

Hmm, not sure I have seen that.  Here is what I saw from Rob:

"
The real problem here is not whether we have "v1" or not, but you need
an SoC specific compatible. Unless there's a public spec where we can
know exactly how many resets, clocks, interrupts, etc.
"

Shawn


From Frank.li at nxp.com  Wed Dec  6 08:33:44 2023
From: Frank.li at nxp.com (Frank Li)
Date: Wed, 6 Dec 2023 11:33:44 -0500
Subject: [PATCH v2 2/2] arm64: dts: freescale: imx93: add i3c1 and i3c2
In-Reply-To: <20231206093106.GE270430@dragon>
References: <20231017194657.3199749-1-Frank.Li@nxp.com>
 <20231017194657.3199749-2-Frank.Li@nxp.com>
 <ZUz/8fBWtnwdSW9w@lizhi-Precision-Tower-5810>
 <20231127022140.GJ87953@dragon>
 <20231127-cherisher-falsify-8193656e8872@wendy>
 <ZXAKp1WS97cAI5X2@lizhi-Precision-Tower-5810>
 <20231206093106.GE270430@dragon>
Message-ID: <ZXCiaKfMYYShoiXK@lizhi-Precision-Tower-5810>

On Wed, Dec 06, 2023 at 05:31:06PM +0800, Shawn Guo wrote:
> On Wed, Dec 06, 2023 at 12:46:15AM -0500, Frank Li wrote:
> > On Mon, Nov 27, 2023 at 09:35:39AM +0000, Conor Dooley wrote:
> > > On Mon, Nov 27, 2023 at 10:21:40AM +0800, Shawn Guo wrote:
> > > > On Thu, Nov 09, 2023 at 10:51:13AM -0500, Frank Li wrote:
> > > > > On Tue, Oct 17, 2023 at 03:46:57PM -0400, Frank Li wrote:
> > > > > > Add I3C1 and I3C2.
> > > > > > 
> > > > > > Signed-off-by: Frank Li <Frank.Li at nxp.com>
> > > > > > ---
> > > > > 
> > > > > @Guo Shawn:
> > > > > 
> > > > > Driver part already merged. 
> > > > > 
> > > > > Please pick up dts part
> > > > 
> > > > Rob had a comment [1] about SoC specific compatible.  That's not what we
> > > > want?
> > > > 
> > > > Shawn
> > > > 
> > > > [1] https://lkml.iu.edu/hypermail/linux/kernel/2310.2/03035.html
> > > 
> > > Yeah, Rob's request here looks valid to me. Should just be a bindings
> > > change Frank & fall back to the "silvaco,i3c-master-v1" compatible.
> > > 
> > > Cheers,
> > > Conor.
> > 
> > @shawn:
> > 	rob agree on "silvaco,i3c-master-v1" compatible.
> 
> Hmm, not sure I have seen that.  Here is what I saw from Rob:
> 
> "
> The real problem here is not whether we have "v1" or not, but you need
> an SoC specific compatible. Unless there's a public spec where we can
> know exactly how many resets, clocks, interrupts, etc.
> "

@Rob:
	Previous existed binding doc is "silvaco,i3c-master-v1". So far
this IP in our difference SOC have the same resets and clocks, and only one
interrrupts.
	current existed i3c controller compatible string is

	snps,dw-i3c-master-1.00a
	cdns,i3c-master
	mipi-i3c-hci

	mipi-i3c-hci is standard. "snps", "cdns" are similar as prefix
"silivaco".
	I think the same IP vendor and same IP version should have same
resets, clocks, and interrupts. So far still not met exception yet.

Frank


> 
> Shawn


From shawnguo at kernel.org  Wed Dec 13 00:12:23 2023
From: shawnguo at kernel.org (Shawn Guo)
Date: Wed, 13 Dec 2023 16:12:23 +0800
Subject: [PATCH v2 2/2] arm64: dts: freescale: imx93: add i3c1 and i3c2
In-Reply-To: <20231017194657.3199749-2-Frank.Li@nxp.com>
References: <20231017194657.3199749-1-Frank.Li@nxp.com>
 <20231017194657.3199749-2-Frank.Li@nxp.com>
Message-ID: <20231213081223.GH270430@dragon>

On Tue, Oct 17, 2023 at 03:46:57PM -0400, Frank Li wrote:
> Add I3C1 and I3C2.
> 
> Signed-off-by: Frank Li <Frank.Li at nxp.com>

Applied, thanks!


From Frank.li at nxp.com  Tue Dec 19 08:29:22 2023
From: Frank.li at nxp.com (Frank Li)
Date: Tue, 19 Dec 2023 11:29:22 -0500
Subject: [v5 resend 0/6] i3c: master: some improvment for i3c master
In-Reply-To: <20231201222532.2431484-1-Frank.Li@nxp.com>
References: <20231201222532.2431484-1-Frank.Li@nxp.com>
Message-ID: <ZYHE4rl7snpYJPSy@lizhi-Precision-Tower-5810>

On Fri, Dec 01, 2023 at 05:25:26PM -0500, Frank Li wrote:
> There are three major improvement
> 
> 1. Add actual size in i3c_transfer because i3c allow target early termiate
> transfer.
> 2. Add API for i3c_dev_gettstatus_format1 for i3c comand GET_STATUS.
> 3. svc master support hotjoin

Friendly ping. Any addtional comment about these patches?

Frank LI

> 
> Change log see each patches
> 
> Frank Li (6):
>   i3c: master: add enable(disable) hot join in sys entry
>   i3c: master: svc: add hot join support
>   i3c: add actual_len in i3c_priv_xfer
>   i3c: master: svc: rename read_len as actual_len
>   i3c: master: svc: return actual transfer data len
>   i3c: add API i3c_dev_gettstatus_format1() to get target device status
> 
>  drivers/i3c/device.c                |  24 ++++++
>  drivers/i3c/internals.h             |   1 +
>  drivers/i3c/master.c                | 109 ++++++++++++++++++++++++++++
>  drivers/i3c/master/svc-i3c-master.c |  95 +++++++++++++++++++-----
>  include/linux/i3c/device.h          |   3 +
>  include/linux/i3c/master.h          |   5 ++
>  6 files changed, 220 insertions(+), 17 deletions(-)
> 
> -- 
> 2.34.1
> 


From joshua.yeong at starfivetech.com  Tue Dec 19 17:51:17 2023
From: joshua.yeong at starfivetech.com (Joshua Yeong)
Date: Wed, 20 Dec 2023 09:51:17 +0800
Subject: [v5 resend 3/6] i3c: add actual_len in i3c_priv_xfer
In-Reply-To: <20231201222532.2431484-4-Frank.Li@nxp.com>
References: <20231201222532.2431484-1-Frank.Li@nxp.com>
 <20231201222532.2431484-4-Frank.Li@nxp.com>
Message-ID: <8564662f-f33b-4656-969c-bc41f04fada6@starfivetech.com>


On 02/12/2023 6:25 AM, Frank Li wrote:
> In MIPI I3C Specification:
>
> "Ninth Bit of SDR Target Returned (Read) Data as End-of-Data: In I2C, the
> ninth Data bit from Target to Controller is an ACK by the Controller. By
> contrast, in I3C this bit allows the Target to end a Read, and allows the
> Controller to Abort a Read. In SDR terms, the ninth bit of Read data is
> referred to as the T-Bit (for ?Transition?)"
>
> I3C allow devices early terminate data transfer. So need "actual_len" field
> to indicate how much get by i3c_priv_xfer.
>
> Reviewed-by: Miquel Raynal <miquel.raynal at bootlin.com>
> Signed-off-by: Frank Li <Frank.Li at nxp.com>
> ---
>
> Notes:
>      change from v4 to v5
>      - Add Miquel review tag
>
>   include/linux/i3c/device.h | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/include/linux/i3c/device.h b/include/linux/i3c/device.h
> index 90fa83464f003..ef6217da8253b 100644
> --- a/include/linux/i3c/device.h
> +++ b/include/linux/i3c/device.h
> @@ -54,6 +54,7 @@ enum i3c_hdr_mode {
>    * struct i3c_priv_xfer - I3C SDR private transfer
>    * @rnw: encodes the transfer direction. true for a read, false for a write
>    * @len: transfer length in bytes of the transfer
> + * @actual_len: actual length in bytes are transferred by the controller
>    * @data: input/output buffer
>    * @data.in: input buffer. Must point to a DMA-able buffer
>    * @data.out: output buffer. Must point to a DMA-able buffer
> @@ -62,6 +63,7 @@ enum i3c_hdr_mode {
>   struct i3c_priv_xfer {
>   	u8 rnw;
>   	u16 len;
What happens if I3C device does not terminate the T-Bit because it 
expects extra length from master?
> +	u16 actual_len;
>   	union {
>   		void *in;
>   		const void *out;


From joshua.yeong at starfivetech.com  Tue Dec 19 17:55:26 2023
From: joshua.yeong at starfivetech.com (Joshua Yeong)
Date: Wed, 20 Dec 2023 09:55:26 +0800
Subject: [v5 resend 3/6] i3c: add actual_len in i3c_priv_xfer
In-Reply-To: <20231201222532.2431484-4-Frank.Li@nxp.com>
References: <20231201222532.2431484-1-Frank.Li@nxp.com>
 <20231201222532.2431484-4-Frank.Li@nxp.com>
Message-ID: <2cfc670f-56ad-4453-82f3-d72dcfd05840@starfivetech.com>


On 02/12/2023 6:25 AM, Frank Li wrote:
> In MIPI I3C Specification:
>
> "Ninth Bit of SDR Target Returned (Read) Data as End-of-Data: In I2C, the
> ninth Data bit from Target to Controller is an ACK by the Controller. By
> contrast, in I3C this bit allows the Target to end a Read, and allows the
> Controller to Abort a Read. In SDR terms, the ninth bit of Read data is
> referred to as the T-Bit (for ?Transition?)"
>
> I3C allow devices early terminate data transfer. So need "actual_len" field
> to indicate how much get by i3c_priv_xfer.
>
> Reviewed-by: Miquel Raynal <miquel.raynal at bootlin.com>
> Signed-off-by: Frank Li <Frank.Li at nxp.com>
> ---
>
> Notes:
>      change from v4 to v5
>      - Add Miquel review tag
>
>   include/linux/i3c/device.h | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/include/linux/i3c/device.h b/include/linux/i3c/device.h
> index 90fa83464f003..ef6217da8253b 100644
> --- a/include/linux/i3c/device.h
> +++ b/include/linux/i3c/device.h
> @@ -54,6 +54,7 @@ enum i3c_hdr_mode {
>    * struct i3c_priv_xfer - I3C SDR private transfer
>    * @rnw: encodes the transfer direction. true for a read, false for a write
>    * @len: transfer length in bytes of the transfer
> + * @actual_len: actual length in bytes are transferred by the controller
>    * @data: input/output buffer
>    * @data.in: input buffer. Must point to a DMA-able buffer
>    * @data.out: output buffer. Must point to a DMA-able buffer
> @@ -62,6 +63,7 @@ enum i3c_hdr_mode {
>   struct i3c_priv_xfer {
>   	u8 rnw;
>   	u16 len;
What happens if I3C device does not terminate the T-Bit because it 
expects extra length from master?
> +	u16 actual_len;
>   	union {
>   		void *in;
>   		const void *out;


From Frank.li at nxp.com  Wed Dec 20 12:55:59 2023
From: Frank.li at nxp.com (Frank Li)
Date: Wed, 20 Dec 2023 15:55:59 -0500
Subject: [v5 resend 3/6] i3c: add actual_len in i3c_priv_xfer
In-Reply-To: <2cfc670f-56ad-4453-82f3-d72dcfd05840@starfivetech.com>
References: <20231201222532.2431484-1-Frank.Li@nxp.com>
 <20231201222532.2431484-4-Frank.Li@nxp.com>
 <2cfc670f-56ad-4453-82f3-d72dcfd05840@starfivetech.com>
Message-ID: <ZYNU36BoLwMVyHPv@lizhi-Precision-Tower-5810>

On Wed, Dec 20, 2023 at 09:55:26AM +0800, Joshua Yeong wrote:
> 
> On 02/12/2023 6:25 AM, Frank Li wrote:
> > In MIPI I3C Specification:
> > 
> > "Ninth Bit of SDR Target Returned (Read) Data as End-of-Data: In I2C, the
> > ninth Data bit from Target to Controller is an ACK by the Controller. By
> > contrast, in I3C this bit allows the Target to end a Read, and allows the
> > Controller to Abort a Read. In SDR terms, the ninth bit of Read data is
> > referred to as the T-Bit (for ?Transition?)"
> > 
> > I3C allow devices early terminate data transfer. So need "actual_len" field
> > to indicate how much get by i3c_priv_xfer.
> > 
> > Reviewed-by: Miquel Raynal <miquel.raynal at bootlin.com>
> > Signed-off-by: Frank Li <Frank.Li at nxp.com>
> > ---
> > 
> > Notes:
> >      change from v4 to v5
> >      - Add Miquel review tag
> > 
> >   include/linux/i3c/device.h | 2 ++
> >   1 file changed, 2 insertions(+)
> > 
> > diff --git a/include/linux/i3c/device.h b/include/linux/i3c/device.h
> > index 90fa83464f003..ef6217da8253b 100644
> > --- a/include/linux/i3c/device.h
> > +++ b/include/linux/i3c/device.h
> > @@ -54,6 +54,7 @@ enum i3c_hdr_mode {
> >    * struct i3c_priv_xfer - I3C SDR private transfer
> >    * @rnw: encodes the transfer direction. true for a read, false for a write
> >    * @len: transfer length in bytes of the transfer
> > + * @actual_len: actual length in bytes are transferred by the controller
> >    * @data: input/output buffer
> >    * @data.in: input buffer. Must point to a DMA-able buffer
> >    * @data.out: output buffer. Must point to a DMA-able buffer
> > @@ -62,6 +63,7 @@ enum i3c_hdr_mode {
> >   struct i3c_priv_xfer {
> >   	u8 rnw;
> >   	u16 len;
> What happens if I3C device does not terminate the T-Bit because it expects
> extra length from master?

If devices don't terminate T, there are two cases.

1. Master send STOP, then START new transfer. I3C Devices can decide start
new transfer, or continue transfer left data, which is totally up to how
I3C device and devices' driver implementation.

2. Master continue toggle SCL to get extra data. Just like a low frequency
at short period.

Frank

> > +	u16 actual_len;
> >   	union {
> >   		void *in;
> >   		const void *out;


From rdunlap at infradead.org  Fri Dec 22 21:05:42 2023
From: rdunlap at infradead.org (Randy Dunlap)
Date: Fri, 22 Dec 2023 21:05:42 -0800
Subject: [PATCH] i3c: master: fix Excess kernel-doc description warning
Message-ID: <20231223050542.13930-1-rdunlap@infradead.org>

Remove the @boardinfo: line to prevent the kernel-doc warning:

include/linux/i3c/master.h:98: warning: Excess struct member 'boardinfo' description in 'i2c_dev_desc'

Signed-off-by: Randy Dunlap <rdunlap at infradead.org>
Cc: Alexandre Belloni <alexandre.belloni at bootlin.com>
Cc: linux-i3c at lists.infradead.org
---
 include/linux/i3c/master.h |    1 -
 1 file changed, 1 deletion(-)

diff -- a/include/linux/i3c/master.h b/include/linux/i3c/master.h
--- a/include/linux/i3c/master.h
+++ b/include/linux/i3c/master.h
@@ -76,7 +76,6 @@ struct i2c_dev_boardinfo {
 /**
  * struct i2c_dev_desc - I2C device descriptor
  * @common: common part of the I2C device descriptor
- * @boardinfo: pointer to the boardinfo attached to this I2C device
  * @dev: I2C device object registered to the I2C framework
  * @addr: I2C device address
  * @lvr: LVR (Legacy Virtual Register) needed by the I3C core to know about


From harshitshah.opendev at gmail.com  Sat Dec 30 01:11:23 2023
From: harshitshah.opendev at gmail.com (Harshit Shah)
Date: Sat, 30 Dec 2023 14:41:23 +0530
Subject: [PATCH] i3c: master: cdns: Update maximum prescaler value for i2c clock
Message-ID: <1703927483-28682-1-git-send-email-harshitshah.opendev@gmail.com>

As per the Cadence IP document fixed the I2C clock divider value limit from
16 bits instead of 10 bits. Without this change setting up the I2C clock to
low frequencies will not work as the prescaler value might be greater than
10 bit number.

I3C clock divider value is 10 bits only. Updating the macro names for both.

Signed-off-by: Harshit Shah <harshitshah.opendev at gmail.com>
---
 drivers/i3c/master/i3c-master-cdns.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
index bcbe8f9..c1627f3 100644
--- a/drivers/i3c/master/i3c-master-cdns.c
+++ b/drivers/i3c/master/i3c-master-cdns.c
@@ -76,7 +76,8 @@
 #define PRESCL_CTRL0			0x14
 #define PRESCL_CTRL0_I2C(x)		((x) << 16)
 #define PRESCL_CTRL0_I3C(x)		(x)
-#define PRESCL_CTRL0_MAX		GENMASK(9, 0)
+#define PRESCL_CTRL0_I3C_MAX		GENMASK(9, 0)
+#define PRESCL_CTRL0_I2C_MAX		GENMASK(15, 0)
 
 #define PRESCL_CTRL1			0x18
 #define PRESCL_CTRL1_PP_LOW_MASK	GENMASK(15, 8)
@@ -1233,7 +1234,7 @@ static int cdns_i3c_master_bus_init(struct i3c_master_controller *m)
 		return -EINVAL;
 
 	pres = DIV_ROUND_UP(sysclk_rate, (bus->scl_rate.i3c * 4)) - 1;
-	if (pres > PRESCL_CTRL0_MAX)
+	if (pres > PRESCL_CTRL0_I3C_MAX)
 		return -ERANGE;
 
 	bus->scl_rate.i3c = sysclk_rate / ((pres + 1) * 4);
@@ -1246,7 +1247,7 @@ static int cdns_i3c_master_bus_init(struct i3c_master_controller *m)
 	max_i2cfreq = bus->scl_rate.i2c;
 
 	pres = (sysclk_rate / (max_i2cfreq * 5)) - 1;
-	if (pres > PRESCL_CTRL0_MAX)
+	if (pres > PRESCL_CTRL0_I2C_MAX)
 		return -ERANGE;
 
 	bus->scl_rate.i2c = sysclk_rate / ((pres + 1) * 5);
-- 
1.9.1



