Skip to contentSkip to conversation

Add Synopsys MIPI I3C Driver support

PATCH RESEND Superseded [email protected] 3 participants 19 messages Apr 17, 2025 – Apr 24, 2025

Subsystems (2)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add Synopsys MIPI I3C Driver support

From: Dinesh Maniyam <[email protected]>

This patchset add Synopsys MIPI I3C Driver support for Intel Agilex5 devices.

The i3c driver is leveraged from the master/dw-i3c-master.c, i3c/device.c and i3c/master.c Linux version 6.6.37 LTS And few header files included to be
part of the migration; i3c/internals.h, include/linux/i3c/ccc.h, include/linux/i3c/device.h and include/linux/i3c/master.h. Additional i3c uclass driver and command files added to support i3c read and write in U-Boot.

Patch status:

Detail changelog can find in commit message.

v4->v3:
--------
Resolve ci test:
- Add i3c node in index.rst
- Formating error in i3c.rst
- Resolve cpu_relax undefined for sandbox

v3->v2:
--------
- Squash commit 10 to commit 9
- Resolve index for new files to pass the checkpatch

Commit: sandbox_defconfig: Enable configs for sandbox i3c
Commit: agilex5_defconfig: Enable i3c configs for agilex5
- use savedefconfig

drivers: Enabled Kconfig and Makefile for i3c support
- Add maintainer for i3c

drivers: i3c: Enabled Kconfig and Makefile for DWI3C
- Add empty lines for if/endif

drivers: i3c: Add i3c sandbox simple test.
- Removed DECLARE_GLOBAL_DATA_PTR

v1->v2:
--------
Reorder commits.

Added commits:
- drivers: i3c: Add i3c sandbox simple test.
- test: cmd: Add simple test for i3c
- configs: sandbox_defconfig: Enable configs for sandbox i3c
- configs: agilex5_defconfig: Enable i3c configs for agilex5

History:
--------
[v1]: https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/
[v2]: https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/
[v3]: https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/

Dinesh Maniyam (12):
drivers: i3c: Add new i3c uclass id
drivers: i3c: Add driver for MIPI DWI3C
drivers: i3c: Add i3c uclass driver.
drivers: Enabled Kconfig and Makefile for i3c support
drivers: i3c: Enabled Kconfig and Makefile for DWI3C
drivers: i3c: Add i3c sandbox simple test.
drivers: i3c: master: Enable probe i3c without slave device
i3c: master: dw-i3c-master: Fix OD_TIMING for spike filter
cmd: Add i3c command support.
test: cmd: Add simple test for i3c
configs: sandbox_defconfig: Enable configs for sandbox i3c
configs: agilex5_defconfig: Enable i3c configs for agilex5

 MAINTAINERS                        |    7 +
 arch/sandbox/dts/test.dts          |    8 +
 cmd/Kconfig                        |    6 +
 cmd/Makefile                       |    1 +
 cmd/i3c.c                          |  193 +++
 configs/sandbox_defconfig          |    4 +
 configs/socfpga_agilex5_defconfig  |    3 +
 doc/usage/cmd/i3c.rst              |   98 ++
 doc/usage/index.rst                |    1 +
 drivers/Kconfig                    |    2 +
 drivers/Makefile                   |    1 +
 drivers/i3c/Kconfig                |   27 +
 drivers/i3c/Makefile               |    5 +
 drivers/i3c/device.c               |  262 ++++
 drivers/i3c/i3c-uclass.c           |   38 +
 drivers/i3c/internals.h            |   26 +
 drivers/i3c/master.c               | 2070 ++++++++++++++++++++++++++++
 drivers/i3c/master/Kconfig         |   11 +
 drivers/i3c/master/Makefile        |    3 +
 drivers/i3c/master/dw-i3c-master.c | 1062 ++++++++++++++
 drivers/i3c/sandbox_i3c.c          |   56 +
 include/dm/device.h                |    2 +
 include/dm/uclass-id.h             |    1 +
 include/dw-i3c.h                   |  252 ++++
 include/i3c.h                      |   67 +
 include/linux/i3c/ccc.h            |  385 ++++++
 include/linux/i3c/device.h         |  286 ++++
 include/linux/i3c/master.h         |  698 ++++++++++
 test/cmd/Makefile                  |    1 +
 test/cmd/i3c.c                     |   52 +
 test/dm/Makefile                   |    1 +
 test/dm/i3c.c                      |   34 +
 32 files changed, 5663 insertions(+)
 create mode 100644 cmd/i3c.c
 create mode 100644 doc/usage/cmd/i3c.rst
 create mode 100644 drivers/i3c/Kconfig
 create mode 100644 drivers/i3c/Makefile
 create mode 100644 drivers/i3c/device.c
 create mode 100644 drivers/i3c/i3c-uclass.c
 create mode 100644 drivers/i3c/internals.h
 create mode 100644 drivers/i3c/master.c
 create mode 100644 drivers/i3c/master/Kconfig
 create mode 100644 drivers/i3c/master/Makefile
 create mode 100644 drivers/i3c/master/dw-i3c-master.c
 create mode 100644 drivers/i3c/sandbox_i3c.c
 create mode 100644 include/dw-i3c.h
 create mode 100644 include/i3c.h
 create mode 100644 include/linux/i3c/ccc.h
 create mode 100644 include/linux/i3c/device.h
 create mode 100644 include/linux/i3c/master.h
 create mode 100644 test/cmd/i3c.c
 create mode 100644 test/dm/i3c.c
Signature · 1 line
2.35.3
#1 lore raw

PATCH RESEND v4 1/12 drivers: i3c: Add new i3c uclass id

From: Dinesh Maniyam <[email protected]>

Add i3c general uclass id.

---
 include/dm/uclass-id.h | 1 +
 1 file changed, 1 insertion(+)
include/dm/uclass-id.h +1 -0
index 270088ad94f..1d259b439ff 100644
@@ -78,6 +78,7 @@ enum uclass_id {
 	UCLASS_I2C_GENERIC,	/* Generic I2C device */
 	UCLASS_I2C_MUX,		/* I2C multiplexer */
 	UCLASS_I2S,		/* I2S bus */
+	UCLASS_I3C,		/* I3C bus */
 	UCLASS_IDE,		/* IDE device */
 	UCLASS_IOMMU,		/* IOMMU */
 	UCLASS_IRQ,		/* Interrupt controller */
Signature · 1 line
2.35.3
#2 lore raw

PATCH RESEND v4 2/12 drivers: i3c: Add driver for MIPI DWI3C

In reply to [email protected]

From: Dinesh Maniyam <[email protected]>

Enable driver for Synopsis MIPI DWI3C for the family device agilex5. This driver is migrated from linux version 6.6.37 LTS

---
 drivers/i3c/device.c               |  262 ++++
 drivers/i3c/internals.h            |   26 +
 drivers/i3c/master.c               | 2064 ++++++++++++++++++++++++++++
 drivers/i3c/master/dw-i3c-master.c | 1006 ++++++++++++++
 include/dm/device.h                |    2 +
 include/dw-i3c.h                   |  248 ++++
 include/linux/i3c/ccc.h            |  385 ++++++
 include/linux/i3c/device.h         |  286 ++++
 include/linux/i3c/master.h         |  697 ++++++++++
 9 files changed, 4976 insertions(+)
 create mode 100644 drivers/i3c/device.c
 create mode 100644 drivers/i3c/internals.h
 create mode 100644 drivers/i3c/master.c
 create mode 100644 drivers/i3c/master/dw-i3c-master.c
 create mode 100644 include/dw-i3c.h
 create mode 100644 include/linux/i3c/ccc.h
 create mode 100644 include/linux/i3c/device.h
 create mode 100644 include/linux/i3c/master.h
drivers/i3c/device.c new file +262 -0
new file mode 100644
index 00000000000..32c57bccc42
@@ -0,0 +1,262 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2018 Cadence Design Systems Inc.
+ *
+ * Author: Boris Brezillon <[email protected]>
+ */
+
+#include <linux/bug.h>
+#include <linux/completion.h>
+#include <dm/device.h>
+
+#include "internals.h"
+
+/* i3c */
+
+#define I3C_MATCH_DCR			0x1
+#define I3C_MATCH_MANUF			0x2
+#define I3C_MATCH_PART			0x4
+#define I3C_MATCH_EXTRA_INFO		0x8
+
+struct i3c_device_id {
+	__u8 match_flags;
+	__u8 dcr;
+	__u16 manuf_id;
+	__u16 part_id;
+	__u16 extra_info;
+
+	const void *data;
+};
+
+/**
+ * i3c_device_do_priv_xfers() - do I3C SDR private transfers directed to a
+ *				specific device
+ *
+ * @dev: device with which the transfers should be done
+ * @xfers: array of transfers
+ * @nxfers: number of transfers
+ *
+ * Initiate one or several private SDR transfers with @dev.
+ *
+ * This function can sleep and thus cannot be called in atomic context.
+ *
+ * Return: 0 in case of success, a negative error core otherwise.
+ */
+int i3c_device_do_priv_xfers(struct i3c_device *dev,
+			     struct i3c_priv_xfer *xfers,
+			     int nxfers)
+{
+	int ret, i;
+
+	if (nxfers < 1)
+		return 0;
+
+	for (i = 0; i < nxfers; i++) {
+		if (!xfers[i].len || !xfers[i].data.in)
+			return -EINVAL;
+	}
+
+	i3c_bus_normaluse_lock(dev->bus);
+	ret = i3c_dev_do_priv_xfers_locked(dev->desc, xfers, nxfers);
+	i3c_bus_normaluse_unlock(dev->bus);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(i3c_device_do_priv_xfers);
+
+/**
+ * i3c_device_get_info() - get I3C device information
+ *
+ * @dev: device we want information on
+ * @info: the information object to fill in
+ *
+ * Retrieve I3C dev info.
+ */
+void i3c_device_get_info(struct i3c_device *dev,
+			 struct i3c_device_info *info)
+{
+	if (!info)
+		return;
+
+	i3c_bus_normaluse_lock(dev->bus);
+	if (dev->desc)
+		*info = dev->desc->info;
+	i3c_bus_normaluse_unlock(dev->bus);
+}
+EXPORT_SYMBOL_GPL(i3c_device_get_info);
+
+/**
+ * i3c_device_disable_ibi() - Disable IBIs coming from a specific device
+ * @dev: device on which IBIs should be disabled
+ *
+ * This function disable IBIs coming from a specific device and wait for
+ * all pending IBIs to be processed.
+ *
+ * Return: 0 in case of success, a negative error core otherwise.
+ */
+int i3c_device_disable_ibi(struct i3c_device *dev)
+{
+	int ret = -ENOENT;
+
+	i3c_bus_normaluse_lock(dev->bus);
+	if (dev->desc) {
+		mutex_lock(&dev->desc->ibi_lock);
+		ret = i3c_dev_disable_ibi_locked(dev->desc);
+		mutex_unlock(&dev->desc->ibi_lock);
+	}
+	i3c_bus_normaluse_unlock(dev->bus);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(i3c_device_disable_ibi);
+
+/**
+ * i3c_device_enable_ibi() - Enable IBIs coming from a specific device
+ * @dev: device on which IBIs should be enabled
+ *
+ * This function enable IBIs coming from a specific device and wait for
+ * all pending IBIs to be processed. This should be called on a device
+ * where i3c_device_request_ibi() has succeeded.
+ *
+ * Note that IBIs from this device might be received before this function
+ * returns to its caller.
+ *
+ * Return: 0 in case of success, a negative error core otherwise.
+ */
+int i3c_device_enable_ibi(struct i3c_device *dev)
+{
+	int ret = -ENOENT;
+
+	i3c_bus_normaluse_lock(dev->bus);
+	if (dev->desc) {
+		mutex_lock(&dev->desc->ibi_lock);
+		ret = i3c_dev_enable_ibi_locked(dev->desc);
+		mutex_unlock(&dev->desc->ibi_lock);
+	}
+	i3c_bus_normaluse_unlock(dev->bus);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(i3c_device_enable_ibi);
+
+/**
+ * i3c_device_request_ibi() - Request an IBI
+ * @dev: device for which we should enable IBIs
+ * @req: setup requested for this IBI
+ *
+ * This function is responsible for pre-allocating all resources needed to
+ * process IBIs coming from @dev. When this function returns, the IBI is not
+ * enabled until i3c_device_enable_ibi() is called.
+ *
+ * Return: 0 in case of success, a negative error core otherwise.
+ */
+int i3c_device_request_ibi(struct i3c_device *dev,
+			   const struct i3c_ibi_setup *req)
+{
+	int ret = -ENOENT;
+
+	if (!req->handler || !req->num_slots)
+		return -EINVAL;
+
+	i3c_bus_normaluse_lock(dev->bus);
+	if (dev->desc) {
+		mutex_lock(&dev->desc->ibi_lock);
+		ret = i3c_dev_request_ibi_locked(dev->desc, req);
+		mutex_unlock(&dev->desc->ibi_lock);
+	}
+	i3c_bus_normaluse_unlock(dev->bus);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(i3c_device_request_ibi);
+
+/**
+ * i3c_device_free_ibi() - Free all resources needed for IBI handling
+ * @dev: device on which you want to release IBI resources
+ *
+ * This function is responsible for de-allocating resources previously
+ * allocated by i3c_device_request_ibi(). It should be called after disabling
+ * IBIs with i3c_device_disable_ibi().
+ */
+void i3c_device_free_ibi(struct i3c_device *dev)
+{
+	i3c_bus_normaluse_lock(dev->bus);
+	if (dev->desc) {
+		mutex_lock(&dev->desc->ibi_lock);
+		i3c_dev_free_ibi_locked(dev->desc);
+		mutex_unlock(&dev->desc->ibi_lock);
+	}
+	i3c_bus_normaluse_unlock(dev->bus);
+}
+EXPORT_SYMBOL_GPL(i3c_device_free_ibi);
+
+/**
+ * i3cdev_to_dev() - Returns the device embedded in @i3cdev
+ * @i3cdev: I3C device
+ *
+ * Return: a pointer to a device object.
+ */
+struct udevice *i3cdev_to_dev(struct i3c_device *i3cdev)
+{
+	return &i3cdev->dev;
+}
+EXPORT_SYMBOL_GPL(i3cdev_to_dev);
+
+/**
+ * dev_to_i3cdev() - Returns the I3C device containing @dev
+ * @dev: device object
+ *
+ * Return: a pointer to an I3C device object.
+ */
+struct i3c_device *dev_to_i3cdev(struct udevice *dev)
+{
+	return container_of(dev, struct i3c_device, dev);
+}
+EXPORT_SYMBOL_GPL(dev_to_i3cdev);
+
+/**
+ * i3c_device_match_id() - Returns the i3c_device_id entry matching @i3cdev
+ * @i3cdev: I3C device
+ * @id_table: I3C device match table
+ *
+ * Return: a pointer to an i3c_device_id object or NULL if there's no match.
+ */
+const struct i3c_device_id *
+i3c_device_match_id(struct i3c_device *i3cdev,
+		    const struct i3c_device_id *id_table)
+{
+	struct i3c_device_info devinfo;
+	const struct i3c_device_id *id;
+	u16 manuf, part, ext_info;
+	bool rndpid;
+
+	i3c_device_get_info(i3cdev, &devinfo);
+
+	manuf = I3C_PID_MANUF_ID(devinfo.pid);
+	part = I3C_PID_PART_ID(devinfo.pid);
+	ext_info = I3C_PID_EXTRA_INFO(devinfo.pid);
+	rndpid = I3C_PID_RND_LOWER_32BITS(devinfo.pid);
+
+	for (id = id_table; id->match_flags != 0; id++) {
+		if ((id->match_flags & I3C_MATCH_DCR) &&
+		    id->dcr != devinfo.dcr)
+			continue;
+
+		if ((id->match_flags & I3C_MATCH_MANUF) &&
+		    id->manuf_id != manuf)
+			continue;
+
+		if ((id->match_flags & I3C_MATCH_PART) &&
+		    (rndpid || id->part_id != part))
+			continue;
+
+		if ((id->match_flags & I3C_MATCH_EXTRA_INFO) &&
+		    (rndpid || id->extra_info != ext_info))
+			continue;
+
+		return id;
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(i3c_device_match_id);
drivers/i3c/internals.h new file +26 -0
new file mode 100644
index 00000000000..86b7b44cfca
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2018 Cadence Design Systems Inc.
+ *
+ * Author: Boris Brezillon <[email protected]>
+ */
+
+#ifndef I3C_INTERNALS_H
+#define I3C_INTERNALS_H
+
+#include <linux/i3c/master.h>
+
+extern struct bus_type i3c_bus_type;
+
+void i3c_bus_normaluse_lock(struct i3c_bus *bus);
+void i3c_bus_normaluse_unlock(struct i3c_bus *bus);
+
+int i3c_dev_do_priv_xfers_locked(struct i3c_dev_desc *dev,
+				 struct i3c_priv_xfer *xfers,
+				 int nxfers);
+int i3c_dev_disable_ibi_locked(struct i3c_dev_desc *dev);
+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);
+#endif /* I3C_INTERNAL_H */
drivers/i3c/master.c new file +2064 -0

2,064 lines not on this page · raw message

drivers/i3c/master/dw-i3c-master.c new file +1006 -0

648 lines not on this page · raw message

include/dm/device.h +2 -0
index add67f9ec06..0ea3882ace3 100644

Lines of this file are not shown. View the raw message.

include/dw-i3c.h new file +248 -0

248 lines not on this page · raw message

include/linux/i3c/ccc.h new file +385 -0

385 lines not on this page · raw message

include/linux/i3c/device.h new file +286 -0

286 lines not on this page · raw message

include/linux/i3c/master.h new file +697 -0

697 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.35.3

Part of the diff is not shown here. View the raw message.

#3 lore raw

PATCH RESEND v4 3/12 drivers: i3c: Add i3c uclass driver.

In reply to [email protected]

From: Dinesh Maniyam <[email protected]>

Enable i3c general uclass driver. This uclass driver will have genaral read and write api to call the specific i3c driver.

---
 drivers/i3c/i3c-uclass.c | 38 ++++++++++++++++++++++++
 include/dw-i3c.h         |  1 +
 include/i3c.h            | 63 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 102 insertions(+)
 create mode 100644 drivers/i3c/i3c-uclass.c
 create mode 100644 include/i3c.h
drivers/i3c/i3c-uclass.c new file +38 -0
new file mode 100644
index 00000000000..644f5788898
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>
+ */
+
+#include <dm.h>
+#include <i3c.h>
+#include <errno.h>
+#include <log.h>
+#include <dm/device-internal.h>
+#include <linux/ctype.h>
+
+int dm_i3c_read(struct udevice *dev, u8 dev_number,
+		u8 *buf, int num_bytes)
+{
+	struct dm_i3c_ops *ops = i3c_get_ops(dev);
+
+	if (!ops->read)
+		return -ENOSYS;
+
+	return ops->read(dev, dev_number, buf, num_bytes);
+}
+
+int dm_i3c_write(struct udevice *dev, u8 dev_number,
+		 u8 *buf, int num_bytes)
+{
+	struct dm_i3c_ops *ops = i3c_get_ops(dev);
+
+	if (!ops->write)
+		return -ENOSYS;
+
+	return ops->write(dev, dev_number, buf, num_bytes);
+}
+
+UCLASS_DRIVER(i3c) = {
+	.id		= UCLASS_I3C,
+	.name		= "i3c",
+};
include/dw-i3c.h +1 -0
index e37fd4dc325..920f18bccb4 100644
@@ -7,6 +7,7 @@
 #define _DW_I3C_H_
 
 #include <clk.h>
+#include <i3c.h>
 #include <reset.h>
 #include <dm/device.h>
 #include <linux/bitops.h>
include/i3c.h new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
2.35.3
#4 lore raw

Re: [resend v4 03/12] drivers: i3c: Add i3c uclass driver.

Quoted 90 lines · On 4/17/25 04:18, [email protected] wrote:

From: Dinesh Maniyam <[email protected]>

Enable i3c general uclass driver. This uclass driver will have genaral read and write api to call the specific i3c driver.

---
  drivers/i3c/i3c-uclass.c | 38 ++++++++++++++++++++++++
  include/dw-i3c.h         |  1 +
  include/i3c.h            | 63 ++++++++++++++++++++++++++++++++++++++++
  3 files changed, 102 insertions(+)

create mode 100644 drivers/i3c/i3c-uclass.c
create mode 100644 include/i3c.h

drivers/i3c/i3c-uclass.c new file +38 -0
new file mode 100644
index 00000000000..644f5788898
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>
+ */
+
+#include <dm.h>
+#include <i3c.h>
+#include <errno.h>
+#include <log.h>
+#include <dm/device-internal.h>
+#include <linux/ctype.h>
+
+int dm_i3c_read(struct udevice *dev, u8 dev_number,
+		u8 *buf, int num_bytes)
+{
+	struct dm_i3c_ops *ops = i3c_get_ops(dev);
+
+	if (!ops->read)
+		return -ENOSYS;
+
+	return ops->read(dev, dev_number, buf, num_bytes);
+}
+
+int dm_i3c_write(struct udevice *dev, u8 dev_number,
+		 u8 *buf, int num_bytes)
+{
+	struct dm_i3c_ops *ops = i3c_get_ops(dev);
+
+	if (!ops->write)
+		return -ENOSYS;
+
+	return ops->write(dev, dev_number, buf, num_bytes);
+}
+
+UCLASS_DRIVER(i3c) = {
+	.id		= UCLASS_I3C,
+	.name		= "i3c",
+};
include/dw-i3c.h +1 -0
index e37fd4dc325..920f18bccb4 100644
@@ -7,6 +7,7 @@
  #define _DW_I3C_H_
 
  #include <clk.h>
+#include <i3c.h>
  #include <reset.h>
  #include <dm/device.h>
  #include <linux/bitops.h>
include/i3c.h new file +14 -0
new file mode 100644
index 00000000000..6ef4982dcf6
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>
+ */
+
+#include <linux/i3c/master.h>
+
+/**
+ * struct dm_i3c_ops - driver operations for i3c uclass
+ *
+ * Drivers should support these operations unless otherwise noted. These
+ * operations are intended to be used by uclass code, not directly from
+ * other code.
+ */

include/i3c.h line 24

Quoted 10 lines
include/i3c.h new file +10 -0
+struct dm_i3c_ops {
+	/**
+	 * Transfer messages in I3C mode.
+	 *
+	 * @see i3c_transfer
+	 *
+	 * @param dev Pointer to controller device driver instance.
+	 * @param target Pointer to target device descriptor.
+	 * @param msg Pointer to I3C messages.
+	 * @param num_msgs Number of messages to transfer.

We follow
https://docs.kernel.org/doc-guide/kernel-doc.html#function-documentation

@param looks wrong.

Please, provide formally valid descriptions.

include/i3c.h line 26

Quoted 2 lines
include/i3c.h new file +2 -0
+	 *
+	 * @return @see i3c_transfer

%s/@return/Return:/

include/i3c.h line 27

Quoted 1 line
include/i3c.h new file +1 -0
+	 */

Please, add the header to doc/api/ and run make htmldocs. This will highlight all formal documentation errors.

include/i3c.h line 30

Quoted 3 lines
include/i3c.h new file +3 -0
+	int (*i3c_xfers)(struct i3c_dev_desc *dev,
+			 struct i3c_priv_xfer *i3c_xfers,
+			 int i3c_nxfers);

Why do you allow negative values of i3c_nxfers?

The parameter names should match the description.

include/i3c.h line 32

Quoted 2 lines
include/i3c.h new file +2 -0
+};
+

Please, add the missing documentation of the macro.

include/i3c.h line 43

Quoted 11 lines
include/i3c.h new file +11 -0
+#define i3c_get_ops(dev)	((struct dm_i3c_ops *)(dev)->driver->ops)
+
+/**
+ * @brief Do i3c write
+ *
+ * Uclass general function to start write to i3c target
+ *
+ * @udevice pointer to i3c controller.
+ * @dev_number target device number.
+ * @buf target Buffer to write.
+ * @num_bytes length of bytes to write.

After each parameter a colon ':' is missing.

include/i3c.h line 45

Quoted 2 lines
include/i3c.h new file +2 -0
+ *
+ * @return 0 for success

%s/@return/Return:/

include/i3c.h line 48

Quoted 3 lines
include/i3c.h new file +3 -0
+ */
+int dm_i3c_write(struct udevice *dev, u8 dev_number,
+		 u8 *buf, int num_bytes);

What would be the meaning of a negative value of num_bytes? An unsigned type probably would be more appropriate.

Quoted 5 lines
include/i3c.h new file +5 -0
+
+/**
+ * @brief Do i3c read
+ *
+ * Uclass general function to start read from i3c target

include/i3c.h line 63

Quoted 10 lines
include/i3c.h new file +10 -0
+ *
+ * @udevice pointer to i3c controller.
+ * @dev_number target device number.
+ * @buf target Buffer to read.
+ * @num_bytes length of bytes to read.
+ *
+ * @return 0 for success
+ */
+int dm_i3c_read(struct udevice *dev, u8 dev_number,
+		u8 *buf, int num_bytes);

ditto

Best regards

Heinrich

#5 lore raw

RE: [resend v4 03/12] drivers: i3c: Add i3c uclass driver.

Quoted 127 lines

-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: Thursday, 17 April 2025 3:40 pm
To: Maniyam, Dinesh <[email protected]>
Cc: Marek <[email protected]>; Simon <[email protected]>; Simon Glass <[email protected]>; Tom Rini <[email protected]>; Dario Binacchi <[email protected]>; Ilias Apalodimas <[email protected]>; Jerome Forissier <[email protected]>; Mattijs Korpershoek <[email protected]>; Ibai Erkiaga <ibai.erkiaga- [email protected]>; Michal Simek <[email protected]>; Dmitry Rokosov <[email protected]>; Jonas Karlman <[email protected]>; Sebastian Reichel <[email protected]>; Meng, Tingting <[email protected]>; Chee, Tien Fong <[email protected]>; Hea, Kok Kiang <[email protected]>; Ng, Boon Khai <[email protected]>; Yuslaimi, Alif Zakuan <[email protected]>; Zamri, Muhammad Hazim Izzat <[email protected]>; Lim, Jit Loon <[email protected]>; Tang, Sieu Mun <[email protected]>; u- [email protected]
Subject: Re: [resend v4 03/12] drivers: i3c: Add i3c uclass driver.

[CAUTION: This email is from outside your organization. Unless you trust the sender, do not click on links or open attachments as it may be a fraudulent email attempting to steal your information and/or compromise your computer.]

Quoted 85 lines · On 4/17/25 04:18, [email protected] wrote:

From: Dinesh Maniyam <[email protected]>

Enable i3c general uclass driver. This uclass driver will have genaral read and write api to call the specific i3c driver.

---
  drivers/i3c/i3c-uclass.c | 38 ++++++++++++++++++++++++
  include/dw-i3c.h         |  1 +
  include/i3c.h            | 63 ++++++++++++++++++++++++++++++++++++++++
  3 files changed, 102 insertions(+)

create mode 100644 drivers/i3c/i3c-uclass.c
create mode 100644 include/i3c.h

drivers/i3c/i3c-uclass.c new renamed from drivers/i3c/i3c-uclass.c +0 -0

file mode 100644 index 00000000000..644f5788898

drivers/i3c/i3c-uclass.c new file +34 -0
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>  */
+
+#include <dm.h>
+#include <i3c.h>
+#include <errno.h>
+#include <log.h>
+#include <dm/device-internal.h>
+#include <linux/ctype.h>
+
+int dm_i3c_read(struct udevice *dev, u8 dev_number,
+             u8 *buf, int num_bytes)
+{
+     struct dm_i3c_ops *ops = i3c_get_ops(dev);
+
+     if (!ops->read)
+             return -ENOSYS;
+
+     return ops->read(dev, dev_number, buf, num_bytes); }
+
+int dm_i3c_write(struct udevice *dev, u8 dev_number,
+              u8 *buf, int num_bytes) {
+     struct dm_i3c_ops *ops = i3c_get_ops(dev);
+
+     if (!ops->write)
+             return -ENOSYS;
+
+     return ops->write(dev, dev_number, buf, num_bytes); }
+
+UCLASS_DRIVER(i3c) = {
+     .id             = UCLASS_I3C,
+     .name           = "i3c",
+};
include/dw-i3c.h index renamed from include/dw-i3c.h +0 -0

e37fd4dc325..920f18bccb4 100644

include/dw-i3c.h +1 -0
@@ -7,6 +7,7 @@
  #define _DW_I3C_H_
 
  #include <clk.h>
+#include <i3c.h>
  #include <reset.h>
  #include <dm/device.h>
  #include <linux/bitops.h>
include/i3c.h new file mode 100644 index renamed from include/i3c.h +0 -0

00000000000..6ef4982dcf6

include/i3c.h new file +15 -0
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>  */
+
+#include <linux/i3c/master.h>
+
+/**
+ * struct dm_i3c_ops - driver operations for i3c uclass
+ *
+ * Drivers should support these operations unless otherwise noted.
+These
+ * operations are intended to be used by uclass code, not directly
+from
+ * other code.
+ */

include/i3c.h line 25

Quoted 10 lines
include/i3c.h new file +10 -0
+struct dm_i3c_ops {
+     /**
+      * Transfer messages in I3C mode.
+      *
+      * @see i3c_transfer
+      *
+      * @param dev Pointer to controller device driver instance.
+      * @param target Pointer to target device descriptor.
+      * @param msg Pointer to I3C messages.
+      * @param num_msgs Number of messages to transfer.

We follow
https://docs.kernel.org/doc-guide/kernel-doc.html#function-documentation

Quoted 4 lines

@param looks wrong.

Please, provide formally valid descriptions.

Noted, will update the param and provide valid descriptions as per the documentation.

Quoted 5 lines

include/i3c.h line 27

Quoted 2 lines
include/i3c.h new file +2 -0
+      *
+      * @return @see i3c_transfer

%s/@return/Return:/

Will be replaced.

Quoted 5 lines

include/i3c.h line 28

Quoted 1 line
include/i3c.h new file +1 -0
+      */

Please, add the header to doc/api/ and run make htmldocs. This will highlight all formal documentation errors.

Noted. Will add the header to check for the error in the documentation.

Quoted 6 lines

include/i3c.h line 30

Quoted 3 lines
include/i3c.h new file +3 -0
+     int (*i3c_xfers)(struct i3c_dev_desc *dev,
+                      struct i3c_priv_xfer *i3c_xfers,
+                      int i3c_nxfers);

Why do you allow negative values of i3c_nxfers?

Should avoid the negative value. Will use the unsigned.

Quoted 1 line

The parameter names should match the description.

Will recheck the parameter names.

Quoted 5 lines

include/i3c.h line 33

Quoted 2 lines
include/i3c.h new file +2 -0
+};
+

Please, add the missing documentation of the macro.

Noted. I will add it.

Quoted 5 lines
Quoted 5 lines
include/i3c.h new file +5 -0
+#define i3c_get_ops(dev)     ((struct dm_i3c_ops *)(dev)->driver->ops)
+
+/**
+ * @brief Do i3c write
+ *
Quoted 9 lines

include/i3c.h line 43

Quoted 6 lines
include/i3c.h new file +6 -0
+ * Uclass general function to start write to i3c target
+ *
+ * @udevice pointer to i3c controller.
+ * @dev_number target device number.
+ * @buf target Buffer to write.
+ * @num_bytes length of bytes to write.

After each parameter a colon ':' is missing.

Will correct it.

Quoted 5 lines

include/i3c.h line 46

Quoted 2 lines
include/i3c.h new file +2 -0
+ *
+ * @return 0 for success

%s/@return/Return:/

Will be replaced.

Quoted 7 lines

include/i3c.h line 48

Quoted 3 lines
include/i3c.h new file +3 -0
+ */
+int dm_i3c_write(struct udevice *dev, u8 dev_number,
+              u8 *buf, int num_bytes);

What would be the meaning of a negative value of num_bytes? An unsigned type probably would be more appropriate.

Yes you are right. Will use the unsigned.

Quoted 9 lines
Quoted 9 lines
include/i3c.h new file +9 -0
+
+/**
+ * @brief Do i3c read
+ *
+ * Uclass general function to start read from i3c target
+ *
+ * @udevice pointer to i3c controller.
+ * @dev_number target device number.
+ * @buf target Buffer to read.
Quoted 9 lines

include/i3c.h line 63

Quoted 6 lines
include/i3c.h new file +6 -0
+ * @num_bytes length of bytes to read.
+ *
+ * @return 0 for success
+ */
+int dm_i3c_read(struct udevice *dev, u8 dev_number,
+             u8 *buf, int num_bytes);

ditto

Will use the unsigned.

Quoted 3 lines

Best regards

Heinrich

Thanks for your time.
I will rework the comments and submit v5.

Dinesh

#6 lore raw

PATCH RESEND v4 4/12 drivers: Enabled Kconfig and Makefile for i3c support

In reply to [email protected]

From: Dinesh Maniyam <[email protected]>

Add new i3c driver to U-Boot drivers.

---
 MAINTAINERS          |  7 +++++++
 drivers/Kconfig      |  2 ++
 drivers/Makefile     |  1 +
 drivers/i3c/Kconfig  | 16 ++++++++++++++++
 drivers/i3c/Makefile |  3 +++
 5 files changed, 29 insertions(+)
 create mode 100644 drivers/i3c/Kconfig
 create mode 100644 drivers/i3c/Makefile
MAINTAINERS +7 -0
index 0315c606744..6dcc566eb72 100644
@@ -1230,6 +1230,13 @@ S:	Maintained
 T:	git https://source.denx.de/u-boot/custodians/u-boot-i2c.git
 F:	drivers/i2c/
 
+I3C
+M:	Dinesh <[email protected]>
+S:	Maintained
+T:	git https://source.denx.de/u-boot/u-boot.git
+F:	cmd/i3c.c
+F:	drivers/i3c/
+
 KWBIMAGE / KWBOOT TOOLS
 M:	Pali Rohár <[email protected]>
 M:	Marek Behún <[email protected]>
drivers/Kconfig +2 -0
index a073230c26d..0b0c610e629 100644
@@ -56,6 +56,8 @@ source "drivers/hwspinlock/Kconfig"
 
 source "drivers/i2c/Kconfig"
 
+source "drivers/i3c/Kconfig"
+
 source "drivers/input/Kconfig"
 
 source "drivers/iommu/Kconfig"
drivers/Makefile +1 -0
index 0e1f58c515b..fd155835ab6 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_$(PHASE_)DRIVERS_MISC) += misc/
 obj-$(CONFIG_$(PHASE_)SYSRESET) += sysreset/
 obj-$(CONFIG_$(PHASE_)FIRMWARE) +=firmware/
 obj-$(CONFIG_$(PHASE_)I2C) += i2c/
+obj-$(CONFIG_$(PHASE_)I3C) += i3c/
 obj-$(CONFIG_$(PHASE_)INPUT) += input/
 obj-$(CONFIG_$(PHASE_)LED) += led/
 obj-$(CONFIG_$(PHASE_)MMC) += mmc/
drivers/i3c/Kconfig new file +16 -0
new file mode 100644
index 00000000000..fa68612787b
@@ -0,0 +1,16 @@
+menuconfig I3C
+	tristate "I3C support"
+	select I2C
+	help
+	  I3C is a serial protocol standardized by the MIPI alliance.
+
+	  It's supposed to be backward compatible with I2C while providing
+	  support for high speed transfers and native interrupt support
+	  without the need for extra pins.
+
+	  The I3C protocol also standardizes the slave device types and is
+	  mainly designed to communicate with sensors.
+
+	  If you want I3C support, you should say Y here and also to the
+	  specific driver for your bus adapter(s) below.
+
drivers/i3c/Makefile new file +3 -0
new file mode 100644
index 00000000000..5bb44a8d64f
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y				:= i3c-uclass.o device.o master.o
Signature · 1 line
2.35.3
#7 lore raw

PATCH RESEND v4 5/12 drivers: i3c: Enabled Kconfig and Makefile for DWI3C

In reply to [email protected]

From: Dinesh Maniyam <[email protected]>

Enable the Kconfig and Makefile for the MIPI DWI3C driver.

---
 drivers/i3c/Kconfig         |  5 +++++
 drivers/i3c/Makefile        |  1 +
 drivers/i3c/master/Kconfig  | 11 +++++++++++
 drivers/i3c/master/Makefile |  3 +++
 4 files changed, 20 insertions(+)
 create mode 100644 drivers/i3c/master/Kconfig
 create mode 100644 drivers/i3c/master/Makefile
drivers/i3c/Kconfig +5 -0
index fa68612787b..d4451057de0 100644
@@ -14,3 +14,8 @@ menuconfig I3C
 	  If you want I3C support, you should say Y here and also to the
 	  specific driver for your bus adapter(s) below.
 
+if I3C
+
+source "drivers/i3c/master/Kconfig"
+
+endif # I3C
drivers/i3c/Makefile +1 -0
index 5bb44a8d64f..5ddc4743c86 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-y				:= i3c-uclass.o device.o master.o
+obj-y				+= master/
drivers/i3c/master/Kconfig new file +11 -0
new file mode 100644
index 00000000000..22bb7c21ea1
@@ -0,0 +1,11 @@
+config DW_I3C_MASTER
+	tristate "Synospsys DesignWare I3C master driver"
+	depends on I3C
+	help
+	  Support for Synopsys DesignWare MIPI I3C Controller.
+
+	  For details please see
+	  https://www.synopsys.com/dw/ipdir.php?ds=mipi_i3c
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called dw-i3c-master.
drivers/i3c/master/Makefile new file +3 -0
new file mode 100644
index 00000000000..c7562f1aa33
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_DW_I3C_MASTER) += dw-i3c-master.o
Signature · 1 line
2.35.3
#8 lore raw

PATCH RESEND v4 6/12 drivers: i3c: Add i3c sandbox simple test.

In reply to [email protected]

From: Dinesh Maniyam <[email protected]>

Add s simple test for the I3C uclass in sandbox.

---
 arch/sandbox/dts/test.dts |  8 ++++++
 drivers/i3c/Kconfig       |  6 +++++
 drivers/i3c/Makefile      |  1 +
 drivers/i3c/sandbox_i3c.c | 56 +++++++++++++++++++++++++++++++++++++++
 test/dm/Makefile          |  1 +
 test/dm/i3c.c             | 34 ++++++++++++++++++++++++
 6 files changed, 106 insertions(+)
 create mode 100644 drivers/i3c/sandbox_i3c.c
 create mode 100644 test/dm/i3c.c
arch/sandbox/dts/test.dts +8 -0
index b8f3012873e..491c7dd56b1 100644
@@ -935,6 +935,14 @@
 		};
 	};
 
+	i3c0 {
+		compatible = "sandbox,i3c";
+	};
+
+	i3c1 {
+		compatible = "sandbox,i3c";
+	};
+
 	bootcount@0 {
 		compatible = "u-boot,bootcount-rtc";
 		rtc = <&rtc_1>;
drivers/i3c/Kconfig +6 -0
index d4451057de0..d877a744353 100644
@@ -14,6 +14,12 @@ menuconfig I3C
 	  If you want I3C support, you should say Y here and also to the
 	  specific driver for your bus adapter(s) below.
 
+config I3C_SANDBOX
+	bool "Enable support for the sandbox I3C"
+	help
+	  This is a sandbox I3C used for testing. It provides 2 interfaces and
+	  records the settings passed into it.
+
 if I3C
 
 source "drivers/i3c/master/Kconfig"
drivers/i3c/Makefile +1 -0
index 5ddc4743c86..d38d2350c9a 100644
@@ -2,3 +2,4 @@
 
 obj-y				:= i3c-uclass.o device.o master.o
 obj-y				+= master/
+obj-$(CONFIG_I3C_SANDBOX) 	+= sandbox_i3c.o
drivers/i3c/sandbox_i3c.c new file +56 -0

56 lines not on this page · raw message

test/dm/Makefile +1 -0
index e44f3d89e77..c6c12713d7f 100644
@@ -59,6 +59,7 @@ obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata.o
 obj-$(CONFIG_SANDBOX) += host.o
 obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o
 obj-$(CONFIG_DM_I2C) += i2c.o
+obj-$(CONFIG_I3C) += i3c.o
 obj-$(CONFIG_SOUND) += i2s.o
 obj-$(CONFIG_CLK_K210_SET_RATE) += k210_pll.o
 obj-$(CONFIG_IOMMU) += iommu.o
test/dm/i3c.c new file +34 -0
new file mode 100644
index 00000000000..81336e67555
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>
+ */
+
+#include <dm.h>
+#include <i3c.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Basic test of the i3c uclass */
+static int dm_test_i3c_base(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+
+	ut_assertok(uclass_get_device(UCLASS_I3C, 0, &dev));
+	ut_assertok(dm_i3c_read(dev, 0, NULL, 1));
+	ut_assertok(dm_i3c_read(dev, 0, NULL, 4));
+	ut_assertok(dm_i3c_write(dev, 0, "AABB", 2));
+	ut_assertok(dm_i3c_write(dev, 0, "AABBCCDD", 4));
+
+	ut_assertok(uclass_get_device(UCLASS_I3C, 1, &dev));
+	ut_assertok(dm_i3c_read(dev, 1, NULL, 1));
+	ut_assertok(dm_i3c_read(dev, 1, NULL, 4));
+	ut_assertok(dm_i3c_write(dev, 1, "AABB", 2));
+	ut_assertok(dm_i3c_write(dev, 1, "AABBCCDD", 4));
+
+	ut_asserteq(-ENODEV, uclass_get_device(UCLASS_I3C, 2, &dev));
+
+	return 0;
+}
+DM_TEST(dm_test_i3c_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
Signature · 1 line
2.35.3
#9 lore raw

PATCH RESEND v4 7/12 drivers: i3c: master: Enable probe i3c without slave device

In reply to [email protected]

From: Dinesh Maniyam <[email protected]>

Picked linux i3c driver upstraming patch to fix the issue to probe for i3c controller without slave device attached. With this fix, the ret check will be on command error and will success without slave device attached.

---
 drivers/i3c/master.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/i3c/master.c +6 -0
index fe12a2a1b46..909d650e951 100644
@@ -452,6 +452,9 @@ static int i3c_master_rstdaa_locked(struct i3c_master_controller *master,
 
 	i3c_ccc_cmd_dest_cleanup(&dest);
 
+	if (ret)
+		ret = cmd.err;
+
 	return ret;
 }
 
@@ -507,6 +510,9 @@ static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
 	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
 	i3c_ccc_cmd_dest_cleanup(&dest);
 
+	if (ret)
+		ret = cmd.err;
+
 	return ret;
 }
 
Signature · 1 line
2.35.3
#10 lore raw

PATCH RESEND v4 8/12 i3c: master: dw-i3c-master: Fix OD_TIMING for spike filter

In reply to [email protected]

From: Dinesh Maniyam <[email protected]>

Fix the I3C device with spike filter unable to detect issue by setting tHIGH_INIT to 200ns for first broadcast address.
This is according to MIPI SPEC 1.1.1 for first broadcast address which is already part of linux upstreamed patch.

---
 drivers/i3c/master/dw-i3c-master.c | 23 +++++++++++++++++++++++
 include/dw-i3c.h                   |  1 +
 include/linux/i3c/master.h         |  1 +
 3 files changed, 25 insertions(+)
drivers/i3c/master/dw-i3c-master.c +23 -0
index a693845d32e..bf5d57937c7 100644
@@ -334,6 +334,14 @@ static int dw_i3c_clk_cfg(struct dw_i3c_master *master)
 	if (hcnt < SCL_I3C_TIMING_CNT_MIN)
 		hcnt = SCL_I3C_TIMING_CNT_MIN;
 
+	/* set back to THIGH_MAX_NS, after disable spike filter */
+	if (!master->first_broadcast) {
+		lcnt = SCL_I3C_TIMING_LCNT(readl(master->regs + SCL_I3C_OD_TIMING));
+		scl_timing = SCL_I3C_TIMING_HCNT(hcnt) | lcnt;
+		writel(scl_timing, master->regs + SCL_I3C_OD_TIMING);
+		return 0;
+	}
+
 	lcnt = DIV_ROUND_UP(core_rate, master->base.bus.scl_rate.i3c) - hcnt;
 	if (lcnt < SCL_I3C_TIMING_CNT_MIN)
 		lcnt = SCL_I3C_TIMING_CNT_MIN;
@@ -351,6 +359,9 @@ static int dw_i3c_clk_cfg(struct dw_i3c_master *master)
 	lcnt = max_t(u8,
 		     DIV_ROUND_UP(I3C_BUS_TLOW_OD_MIN_NS, core_period), lcnt);
 
+	/* first broadcast thigh to 200ns, to disable spike filter */
+	hcnt = DIV_ROUND_UP(I3C_BUS_THIGH_INIT_OD_MIN_NS, core_period);
+
 	scl_timing = SCL_I3C_TIMING_HCNT(hcnt) | SCL_I3C_TIMING_LCNT(lcnt);
 	writel(scl_timing, master->regs + SCL_I3C_OD_TIMING);
 
@@ -406,6 +417,9 @@ static int dw_i3c_master_bus_init(struct i3c_master_controller *m)
 	u32 thld_ctrl;
 	int ret;
 
+	/* first broadcast to disable spike filter */
+	master->first_broadcast = true;
+
 	switch (bus->mode) {
 	case I3C_BUS_MODE_MIXED_FAST:
 	case I3C_BUS_MODE_MIXED_LIMITED:
@@ -485,6 +499,15 @@ static void dw_i3c_master_irq_handler(struct dw_i3c_master *master)
 	if (status & INTR_TRANSFER_ERR_STAT)
 		writel(INTR_TRANSFER_ERR_STAT, master->regs + INTR_STATUS);
 
+	/* set back to THIGH_MAX_NS, after disable spike filter */
+	if (master->first_broadcast) {
+		master->first_broadcast = false;
+		int ret = dw_i3c_clk_cfg(master);
+
+		if (ret)
+			pr_err("Failed to set clk cfg\n");
+	}
+
 	spin_unlock(&master->xferqueue.lock);
 }
 
include/dw-i3c.h +1 -0
index 920f18bccb4..42c37d6dfa2 100644
@@ -240,6 +240,7 @@ struct dw_i3c_master {
 	char version[5];
 	char type[5];
 	u8 addrs[MAX_DEVS];
+	bool first_broadcast;
 };
 
 struct dw_i3c_i2c_dev_data {
include/linux/i3c/master.h +1 -0
index bafb1448b57..c2391170ae1 100644
@@ -278,6 +278,7 @@ struct i3c_device {
 #define I3C_BUS_I2C_FM_PLUS_SCL_RATE	1000000
 #define I3C_BUS_I2C_FM_SCL_RATE		400000
 #define I3C_BUS_TLOW_OD_MIN_NS		200
+#define I3C_BUS_THIGH_INIT_OD_MIN_NS	200
 
 /**
  * enum i3c_bus_mode - I3C bus mode
Signature · 1 line
2.35.3
#11 lore raw

PATCH RESEND v4 9/12 cmd: Add i3c command support.

In reply to [email protected]

From: Dinesh Maniyam <[email protected]>

Add i3c command file to support select, get i3c device target list, read and write operation.

---
 cmd/Kconfig                        |   6 +
 cmd/Makefile                       |   1 +
 cmd/i3c.c                          | 193 +++++++++++++++++++++++++++++
 doc/usage/cmd/i3c.rst              |  98 +++++++++++++++
 doc/usage/index.rst                |   1 +
 drivers/i3c/master/dw-i3c-master.c |  35 +++++-
 include/dw-i3c.h                   |   2 +
 include/i3c.h                      |   4 +
 8 files changed, 339 insertions(+), 1 deletion(-)
 create mode 100644 cmd/i3c.c
 create mode 100644 doc/usage/cmd/i3c.rst
cmd/Kconfig +6 -0
index 642cc1116e8..551959731f0 100644
@@ -1327,6 +1327,12 @@ config CMD_I2C
 	help
 	  I2C support.
 
+config CMD_I3C
+	bool "i3c"
+	help
+	  Enable command to list i3c devices connected to the i3c controller
+	  and perform read and write on the connected i3c devices.
+
 config CMD_W1
 	depends on W1
 	default y if W1
cmd/Makefile +1 -0
index 8410be576bb..082470fa104 100644
@@ -95,6 +95,7 @@ obj-$(CONFIG_CMD_GPIO) += gpio.o
 obj-$(CONFIG_CMD_HISTORY) += history.o
 obj-$(CONFIG_CMD_HVC) += smccc.o
 obj-$(CONFIG_CMD_I2C) += i2c.o
+obj-$(CONFIG_CMD_I3C) += i3c.o
 obj-$(CONFIG_CMD_IOTRACE) += iotrace.o
 obj-$(CONFIG_CMD_HASH) += hash.o
 obj-$(CONFIG_CMD_IDE) += ide.o disk.o
cmd/i3c.c new file +193 -0

193 lines not on this page · raw message

doc/usage/cmd/i3c.rst new file +98 -0

98 lines not on this page · raw message

doc/usage/index.rst +1 -0
index bf2335dc8f0..718b606b162 100644
@@ -80,6 +80,7 @@ Shell commands
    cmd/if
    cmd/itest
    cmd/imxtract
+   cmd/i3c
    cmd/load
    cmd/loadb
    cmd/loadm
drivers/i3c/master/dw-i3c-master.c +34 -1
index bf5d57937c7..623f5b01dbb 100644
@@ -674,8 +674,11 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
 	newdevs &= ~olddevs;
 
 	for (pos = 0; pos < master->maxdevs; pos++) {
-		if (newdevs & BIT(pos))
+		if (newdevs & BIT(pos)) {
 			i3c_master_add_i3c_dev_locked(m, master->addrs[pos]);
+			master->i3cdev[pos] = m->this;
+			master->num_i3cdevs++;
+		}
 	}
 
 	dw_i3c_master_free_xfer(xfer);
@@ -1010,8 +1013,38 @@ err_assert_rst:
 	return ret;
 }
 
+static int dw_i3c_master_priv_read(struct udevice *dev, u8 dev_number,
+				   u8 *buf, int buf_size)
+{
+	struct dw_i3c_master *master = dev_get_priv(dev);
+	struct i3c_dev_desc *i3cdev = master->i3cdev[dev_number];
+	struct i3c_priv_xfer i3c_xfers;
+
+	i3c_xfers.data.in = buf;
+	i3c_xfers.len = buf_size;
+	i3c_xfers.rnw = I3C_MSG_READ;
+
+	return dw_i3c_master_priv_xfers(i3cdev, &i3c_xfers, 1);
+}
+
+static int dw_i3c_master_priv_write(struct udevice *dev, u8 dev_number,
+				    u8 *buf, int buf_size)
+{
+	struct dw_i3c_master *master = dev_get_priv(dev);
+	struct i3c_dev_desc *i3cdev = master->i3cdev[dev_number];
+	struct i3c_priv_xfer i3c_xfers;
+
+	i3c_xfers.data.out = buf;
+	i3c_xfers.len = buf_size;
+	i3c_xfers.rnw = I3C_MSG_WRITE;
+
+	return dw_i3c_master_priv_xfers(i3cdev, &i3c_xfers, 1);
+}
+
 static const struct dm_i3c_ops dw_i3c_ops = {
 	.i3c_xfers = dw_i3c_master_priv_xfers,
+	.read = dw_i3c_master_priv_read,
+	.write = dw_i3c_master_priv_write,
 };
 
 static const struct udevice_id dw_i3c_ids[] = {
include/dw-i3c.h +2 -0
index 42c37d6dfa2..c652de77404 100644
@@ -241,6 +241,8 @@ struct dw_i3c_master {
 	char type[5];
 	u8 addrs[MAX_DEVS];
 	bool first_broadcast;
+	struct i3c_dev_desc *i3cdev[I3C_BUS_MAX_DEVS];
+	u16 num_i3cdevs;
 };
 
 struct dw_i3c_i2c_dev_data {
include/i3c.h +4 -0
index 6ef4982dcf6..969753ae49d 100644
@@ -28,6 +28,10 @@ struct dm_i3c_ops {
 	int (*i3c_xfers)(struct i3c_dev_desc *dev,
 			 struct i3c_priv_xfer *i3c_xfers,
 			 int i3c_nxfers);
+	int (*read)(struct udevice *dev, u8 dev_number,
+		    u8 *buf, int num_bytes);
+	int (*write)(struct udevice *dev, u8 dev_number,
+		     u8 *buf, int num_bytes);
 };
 
 #define i3c_get_ops(dev)	((struct dm_i3c_ops *)(dev)->driver->ops)
Signature · 1 line
2.35.3
#12 lore raw

Re: [resend v4 09/12] cmd: Add i3c command support.

Quoted 110 lines · On 4/17/25 04:18, [email protected] wrote:

From: Dinesh Maniyam <[email protected]>

Add i3c command file to support select, get i3c device target list, read and write operation.

---
  cmd/Kconfig                        |   6 +
  cmd/Makefile                       |   1 +
  cmd/i3c.c                          | 193 +++++++++++++++++++++++++++++
  doc/usage/cmd/i3c.rst              |  98 +++++++++++++++
  doc/usage/index.rst                |   1 +
  drivers/i3c/master/dw-i3c-master.c |  35 +++++-
  include/dw-i3c.h                   |   2 +
  include/i3c.h                      |   4 +
  8 files changed, 339 insertions(+), 1 deletion(-)

create mode 100644 cmd/i3c.c
create mode 100644 doc/usage/cmd/i3c.rst

cmd/Kconfig +6 -0
index 642cc1116e8..551959731f0 100644
@@ -1327,6 +1327,12 @@ config CMD_I2C
  	help
  	  I2C support.
 
+config CMD_I3C
+	bool "i3c"
+	help
+	  Enable command to list i3c devices connected to the i3c controller
+	  and perform read and write on the connected i3c devices.
+
  config CMD_W1
  	depends on W1
  	default y if W1
cmd/Makefile +1 -0
index 8410be576bb..082470fa104 100644
@@ -95,6 +95,7 @@ obj-$(CONFIG_CMD_GPIO) += gpio.o
  obj-$(CONFIG_CMD_HISTORY) += history.o
  obj-$(CONFIG_CMD_HVC) += smccc.o
  obj-$(CONFIG_CMD_I2C) += i2c.o
+obj-$(CONFIG_CMD_I3C) += i3c.o
  obj-$(CONFIG_CMD_IOTRACE) += iotrace.o
  obj-$(CONFIG_CMD_HASH) += hash.o
  obj-$(CONFIG_CMD_IDE) += ide.o disk.o
cmd/i3c.c new file +56 -0
new file mode 100644
index 00000000000..5631f487cc2
@@ -0,0 +1,193 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2023 Intel Coporation.
+ */
+
+#include <bootretry.h>
+#include <cli.h>
+#include <command.h>
+#include <console.h>
+#include <dm.h>
+#include <dw-i3c.h>
+#include <edid.h>
+#include <errno.h>
+#include <log.h>
+#include <malloc.h>
+#include <asm/byteorder.h>
+#include <linux/compiler.h>
+#include <linux/delay.h>
+#include <u-boot/crc.h>
+#include <linux/i3c/master.h>
+
+static struct udevice *currdev;
+static struct udevice *prevdev;
+static struct dw_i3c_master *master;
+
+void low_to_high_bytes(void *data, size_t size)
+{
+	unsigned char *byte_data = (unsigned char *)data;
+	size_t start = 0;
+	size_t end = size - 1;
+
+	while (start < end) {
+		unsigned char temp = byte_data[start];
+
+		byte_data[start] = byte_data[end];
+		byte_data[end] = temp;
+		start++;
+		end--;
+	}
+}
+
+/**
+ * do_i3c() - Handle the "i3c" command-line command
+ * @cmdtp:    Command data struct pointer
+ * @flag:    Command flag
+ * @argc:    Command-line argument count
+ * @argv:    Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
+ * on error.
+ */
+static int do_i3c(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	struct uclass *uc;
+	int ret;
+	struct udevice *dev_list;

cmd/i3c.c line 66

Quoted 10 lines
cmd/i3c.c new file +10 -0
+	u32 length, bytes;
+	u8 *data;
+	u8 *rdata;
+	u8 device_num;
+
+	if (argc > 1) {
+		ret = uclass_get_device_by_name(UCLASS_I3C, argv[1], &currdev);
+		if (ret) {
+			if (!strcmp(argv[1], "help"))
+				return CMD_RET_USAGE;

You don't need to check for "help". Just return CMD_RET_USAGE if the first argument does not match any of the subcommands.

Quoted 17 lines
cmd/i3c.c new file +17 -0
+
+			currdev = prevdev;
+			if (!currdev) {
+				ret = uclass_get(UCLASS_I3C, &uc);
+				if (ret)
+					return CMD_RET_FAILURE;
+
+				uclass_foreach_dev(dev_list, uc)
+					printf("%s (%s)\n", dev_list->name, dev_list->driver->name);
+
+				printf("i3c master controller is not initialized: %s\n", argv[1]);
+				return CMD_RET_FAILURE;
+			}
+		} else {
+			master = dev_get_priv(currdev);
+			printf("current dev: %s\n", currdev->name);
+			prevdev = currdev;

cmd/i3c.c line 93

Quoted 10 lines
cmd/i3c.c new file +10 -0
+		}
+	} else {
+		if (!currdev) {
+			printf("No i3c device set!\n");
+			return CMD_RET_FAILURE;
+		}
+		printf("dev: %s\n", currdev->name);
+	}
+
+	if (!strcmp(argv[1], "list")) {

Why would you want to reach this if statment for argc == 1?

Quoted 16 lines
cmd/i3c.c new file +16 -0
+		ret = uclass_get(UCLASS_I3C, &uc);
+		if (ret)
+			return CMD_RET_FAILURE;
+
+		uclass_foreach_dev(dev_list, uc)
+		printf("%s (%s)\n", dev_list->name, dev_list->driver->name);
+	}
+
+	if (!strcmp(argv[1], "current")) {
+		if (!currdev)
+			printf("no current dev!\n");
+		else
+			printf("current dev: %s\n", currdev->name);
+	}
+
+	if ((!strcmp(argv[1], "write")) && !(argv[2] == NULL) && !(argv[3] == NULL) &&

cmd/i3c.c line 119

Quoted 10 lines
cmd/i3c.c new file +10 -0
+	    !(argv[4] == NULL)) {
+		length = hextoul(argv[3], NULL);
+
+		data = (u8 *)malloc(sizeof(u8) * length);
+		if (!data) {
+			debug("Memory allocation for data failed\n");
+			return -ENOMEM;
+		}
+
+		device_num = hextoul(argv[4], NULL);

device_num is u8. You should check that the value returned by hextoul does not exceed 0xff.

cmd/i3c.c line 120

Quoted 1 line
cmd/i3c.c new file +1 -0
+		bytes = hextoul(argv[2], NULL);

Bytes is only 32bit wide. But the number returned by hextoul can be larger than UINT_MAX leading to truncation.

Please, check the value range.

cmd/i3c.c line 126

Quoted 6 lines
cmd/i3c.c new file +6 -0
+
+		for (int i = 0; i < length; i++)
+			data[i] = (u8)((bytes >> (8 * i)) & 0xFF);
+
+		low_to_high_bytes(data, length);
+		ret = dm_i3c_write(currdev, device_num, data, length);

For unknown reasons you have defined the num_bytes parameter as signed int. So length > INT_MAX will be transferred as a negative number.

Please, be consistent.

cmd/i3c.c line 134

Quoted 8 lines
cmd/i3c.c new file +8 -0
+		if (ret) {
+			ret = CMD_RET_FAILURE;
+			goto write_out;
+		}
+	}
+
+	if (!strcmp(argv[1], "read") && !(argv[2] == NULL) && !(argv[3] == NULL)) {
+		length = hextoul(argv[2], NULL);

Each subcommand should be handled in a separate static function to avoid sphaghetti code.

cmd/i3c.c line 136

Quoted 2 lines
cmd/i3c.c new file +2 -0
+
+		rdata = (u8 *) malloc(sizeof(u8) * length);

This is not C++ code. Please, remove the (u8 *) conversion.

I would not expect sizeof(u8) to differ from 1. So remove it.

cmd/i3c.c line 142

Quoted 6 lines
cmd/i3c.c new file +6 -0
+		if (!rdata) {
+			debug("Memory allocation for rdata failed\n");
+			return -ENOMEM;
+		}
+
+		device_num = hextoul(argv[3], NULL);

Check that hextoul() returns a number in the 0 - 255 range.

cmd/i3c.c line 146

Quoted 4 lines
cmd/i3c.c new file +4 -0
+
+		ret = dm_i3c_read(currdev, device_num, rdata, length);
+		if (ret) {
+			ret =  CMD_RET_FAILURE;

Please, avoid duplicate space after '='.

cmd/i3c.c line 149

Quoted 3 lines
cmd/i3c.c new file +3 -0
+		} else {
+			printf("Read buff: ");
+			for (size_t i = 0; i < length; ++i)

length is u32. Why use a larger type for the index?

cmd/i3c.c line 150

Quoted 1 line
cmd/i3c.c new file +1 -0
+				printf("%02x", rdata[i]);

Please, use print_hex_dump() here. This is especially helpful when reading hundres of bytes.

To be honest, it would make more sense to provide an address in memory to receive the data than printing up to INT_MAX bytes.

Quoted 30 lines
cmd/i3c.c new file +30 -0
+
+			printf("\n");
+		}
+
+		goto read_out;
+	}
+
+	if (!strcmp(argv[1], "device_list")) {
+		if (master) {
+			for (int i = 0; i < master->num_i3cdevs; i++) {
+				printf("device:%d\n", i);
+				printf("dynamic address:0x%X\n", master->i3cdev[i]->info.dyn_addr);
+				printf("PID:%llx\n", master->i3cdev[i]->info.pid);
+				printf("BCR:%X\n", master->i3cdev[i]->info.bcr);
+				printf("DCR:%X\n", master->i3cdev[i]->info.dcr);
+				printf("Max Read DS:%X\n", master->i3cdev[i]->info.max_read_ds);
+				printf("Max Write DS:%X\n", master->i3cdev[i]->info.max_write_ds);
+				printf("\n");
+			}
+		}
+	}
+
+	return CMD_RET_SUCCESS;
+
+read_out:
+	free(rdata);
+	return ret;
+
+write_out:
+	free(data);

cmd/i3c.c line 190

Quoted 10 lines
cmd/i3c.c new file +10 -0
+	return ret;
+}
+
+U_BOOT_CMD(
+	i3c,    5,    1,     do_i3c,
+	"access the system i3c\n",
+	"i3c write<data><length><device_number> - write to device.\n"
+	"i3c read<length><device_number> - read from device.\n"
+	"i3c device_list   - List valid target devices\n"
+	"i3c <i3c name>   - Select i3c controller.\n"

%s/i3c name/host controller/

Quoted 13 lines
cmd/i3c.c new file +3 -0
+	"i3c list   - List all the available i3c controller.\n"
+	"i3c current   - print current i3c controller.\n"
+);
doc/usage/cmd/i3c.rst new file +4 -0
new file mode 100644
index 00000000000..ade7b5c7fc4
@@ -0,0 +1,98 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+.. index::
+   single: i3c (command)

doc/usage/cmd/i3c.rst line 14

Quoted 10 lines
doc/usage/cmd/i3c.rst new file +10 -0
+
+i3c command
+===========
+
+Synopsis
+--------
+
+::
+
+    i3c <i3c name>

%s/i3c name/host_controller/

doc/usage/cmd/i3c.rst line 18

Quoted 4 lines
doc/usage/cmd/i3c.rst new file +4 -0
+    i3c current
+    i3c list
+    i3c device_list
+    i3c write <data> <length> <device_number>

For sending large amounts of data it would be preferable to replace direct data by a memory start address.

I would not want to type all bytes needed for displaying an image on an LCD screen.

doc/usage/cmd/i3c.rst line 19

Quoted 1 line
doc/usage/cmd/i3c.rst new file +1 -0
+    i3c read <length> <device_number>

Same for reading. When reading a camera image you don't want megabytes of data flooding the screen.

doc/usage/cmd/i3c.rst line 25

Quoted 6 lines
doc/usage/cmd/i3c.rst new file +6 -0
+
+
+Description
+-----------
+
+The ``i3c`` command is used to probe i3c master controller and perform read

%s/i3c master/an I3C host/

doc/usage/cmd/i3c.rst line 26

Quoted 1 line
doc/usage/cmd/i3c.rst new file +1 -0
+and write on the i3c devices.

%s/write on the i3c/write operations on the connected I3C/

i3c
---

Probe an I3C host controller and select it for the other sub-commands.

host_controller
name of the host controller to be probed and selected

doc/usage/cmd/i3c.rst line 31

Quoted 5 lines
doc/usage/cmd/i3c.rst new file +5 -0
+
+i3c current
+------------
+
+* Display the current probed i3c controller.

%s/current probed i3c/currently selected I3C host/

doc/usage/cmd/i3c.rst line 36

Quoted 5 lines
doc/usage/cmd/i3c.rst new file +5 -0
+
+i3c list
+----------
+
+List all the i3c controllers defined in the DT.

%s/i3c/I3C/

%s/DT/device-tree/

doc/usage/cmd/i3c.rst line 42

Quoted 6 lines
doc/usage/cmd/i3c.rst new file +6 -0
+
+i3c device_list
+----------------
+
+List all the i3c devices' device number, dynamic address, PID, BCR, DCR,
+Max Write Speed and Max Read Speed of the probed i3c controller.

List all the I3C devices connected to the current host controller, displaying

* device number
* dynamic address
* provisional ID (PID)
* value of the Bus Characteristics Register (BCR)
* value of the Device Characteristics Register (DCR)
* maximum write speed in MHz
* maximum read speed in MHz

Why wouldn't you print the static address, too?

doc/usage/cmd/i3c.rst line 52

Quoted 10 lines
doc/usage/cmd/i3c.rst new file +10 -0
+
+i3c write
+-----------
+
+Perform write to the i3c device.
+
+i3c read
+-----------
+
+Perform read from the i3c device.

Parameters
----------

doc/usage/cmd/i3c.rst line 54

Quoted 2 lines
doc/usage/cmd/i3c.rst new file +2 -0
+
+i3c name

host_controller

doc/usage/cmd/i3c.rst line 55

Quoted 1 line
doc/usage/cmd/i3c.rst new file +1 -0
+    i3c name defined in DT

Name of the host controller as defined in the device-tree

doc/usage/cmd/i3c.rst line 61

Quoted 6 lines
doc/usage/cmd/i3c.rst new file +6 -0
+
+length
+    Size of the data.
+
+device_number
+    device number that connected to i3c controller.

It is unclear what is meant by device number. Is it the static address or a device number in the driver model?

doc/usage/cmd/i3c.rst line 73

Quoted 12 lines
doc/usage/cmd/i3c.rst new file +12 -0
+
+data
+    Bytes to be written to device.
+
+Examples
+--------
+
+Probe i3c0::
+
+    => i3c i3c0
+
+Check cuurent i3c controller::

Display current I3C host controller::

doc/usage/cmd/i3c.rst line 81

Quoted 8 lines
doc/usage/cmd/i3c.rst new file +8 -0
+
+    => i3c current
+
+Check the device number and PID of the connected devices::
+
+    => i3c device_list
+
+Perform write AA byte to a device 0::

Do you mean:

Write a single byte 0xaa to the device with static address 0 on the selected host controller.

doc/usage/cmd/i3c.rst line 83

Quoted 2 lines
doc/usage/cmd/i3c.rst new file +2 -0
+
+    => i3c write AA 1 0

It is unclear how to format multiple bytes to be written. Please, provide an example with multiple bytes.

Does the data have to be capitalized or is lower case working, too?

doc/usage/cmd/i3c.rst line 87

Quoted 4 lines
doc/usage/cmd/i3c.rst new file +4 -0
+
+Perform read from a device 0::
+
+    => i3c read 1 0

Where is the example output?

Best regards

Heinrich

Quoted 107 lines
doc/usage/cmd/i3c.rst new file +11 -0
+
+Configuration
+-------------
+
+The ``i3c`` command is only available if CONFIG_CMD_I3C=y.
+
+Return value
+------------
+
+If the command succeeds, the return value ``$?`` is set to 0. If an error occurs, the
+return value ``$?`` is set to 1.
doc/usage/index.rst +1 -0
index bf2335dc8f0..718b606b162 100644
@@ -80,6 +80,7 @@ Shell commands
     cmd/if
     cmd/itest
     cmd/imxtract
+   cmd/i3c
     cmd/load
     cmd/loadb
     cmd/loadm
drivers/i3c/master/dw-i3c-master.c +34 -1
index bf5d57937c7..623f5b01dbb 100644
@@ -674,8 +674,11 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
  	newdevs &= ~olddevs;
 
  	for (pos = 0; pos < master->maxdevs; pos++) {
-		if (newdevs & BIT(pos))
+		if (newdevs & BIT(pos)) {
  			i3c_master_add_i3c_dev_locked(m, master->addrs[pos]);
+			master->i3cdev[pos] = m->this;
+			master->num_i3cdevs++;
+		}
  	}
 
  	dw_i3c_master_free_xfer(xfer);
@@ -1010,8 +1013,38 @@ err_assert_rst:
  	return ret;
  }
 
+static int dw_i3c_master_priv_read(struct udevice *dev, u8 dev_number,
+				   u8 *buf, int buf_size)
+{
+	struct dw_i3c_master *master = dev_get_priv(dev);
+	struct i3c_dev_desc *i3cdev = master->i3cdev[dev_number];
+	struct i3c_priv_xfer i3c_xfers;
+
+	i3c_xfers.data.in = buf;
+	i3c_xfers.len = buf_size;
+	i3c_xfers.rnw = I3C_MSG_READ;
+
+	return dw_i3c_master_priv_xfers(i3cdev, &i3c_xfers, 1);
+}
+
+static int dw_i3c_master_priv_write(struct udevice *dev, u8 dev_number,
+				    u8 *buf, int buf_size)
+{
+	struct dw_i3c_master *master = dev_get_priv(dev);
+	struct i3c_dev_desc *i3cdev = master->i3cdev[dev_number];
+	struct i3c_priv_xfer i3c_xfers;
+
+	i3c_xfers.data.out = buf;
+	i3c_xfers.len = buf_size;
+	i3c_xfers.rnw = I3C_MSG_WRITE;
+
+	return dw_i3c_master_priv_xfers(i3cdev, &i3c_xfers, 1);
+}
+
  static const struct dm_i3c_ops dw_i3c_ops = {
  	.i3c_xfers = dw_i3c_master_priv_xfers,
+	.read = dw_i3c_master_priv_read,
+	.write = dw_i3c_master_priv_write,
  };
 
  static const struct udevice_id dw_i3c_ids[] = {
include/dw-i3c.h +2 -0
index 42c37d6dfa2..c652de77404 100644
@@ -241,6 +241,8 @@ struct dw_i3c_master {
  	char type[5];
  	u8 addrs[MAX_DEVS];
  	bool first_broadcast;
+	struct i3c_dev_desc *i3cdev[I3C_BUS_MAX_DEVS];
+	u16 num_i3cdevs;
  };
 
  struct dw_i3c_i2c_dev_data {
include/i3c.h +4 -0
index 6ef4982dcf6..969753ae49d 100644
@@ -28,6 +28,10 @@ struct dm_i3c_ops {
  	int (*i3c_xfers)(struct i3c_dev_desc *dev,
  			 struct i3c_priv_xfer *i3c_xfers,
  			 int i3c_nxfers);
+	int (*read)(struct udevice *dev, u8 dev_number,
+		    u8 *buf, int num_bytes);
+	int (*write)(struct udevice *dev, u8 dev_number,
+		     u8 *buf, int num_bytes);
  };
 
  #define i3c_get_ops(dev)	((struct dm_i3c_ops *)(dev)->driver->ops)
#13 lore raw

RE: [resend v4 09/12] cmd: Add i3c command support.

Quoted 141 lines

-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: Thursday, 17 April 2025 3:25 pm
To: Maniyam, Dinesh <[email protected]>
Cc: Marek <[email protected]>; Simon <[email protected]>; Simon Glass <[email protected]>; Tom Rini <[email protected]>; Dario Binacchi <[email protected]>; Ilias Apalodimas <[email protected]>; Jerome Forissier <[email protected]>; Mattijs Korpershoek <[email protected]>; Ibai Erkiaga <ibai.erkiaga- [email protected]>; Michal Simek <[email protected]>; Dmitry Rokosov <[email protected]>; Jonas Karlman <[email protected]>; Sebastian Reichel <[email protected]>; Meng, Tingting <[email protected]>; Chee, Tien Fong <[email protected]>; Hea, Kok Kiang <[email protected]>; Ng, Boon Khai <[email protected]>; Yuslaimi, Alif Zakuan <[email protected]>; Zamri, Muhammad Hazim Izzat <[email protected]>; Lim, Jit Loon <[email protected]>; Tang, Sieu Mun <[email protected]>; u- [email protected]
Subject: Re: [resend v4 09/12] cmd: Add i3c command support.

[CAUTION: This email is from outside your organization. Unless you trust the sender, do not click on links or open attachments as it may be a fraudulent email attempting to steal your information and/or compromise your computer.]

Quoted 113 lines · On 4/17/25 04:18, [email protected] wrote:

From: Dinesh Maniyam <[email protected]>

Add i3c command file to support select, get i3c device target list, read and write operation.

---
  cmd/Kconfig                        |   6 +
  cmd/Makefile                       |   1 +
  cmd/i3c.c                          | 193 +++++++++++++++++++++++++++++
  doc/usage/cmd/i3c.rst              |  98 +++++++++++++++
  doc/usage/index.rst                |   1 +
  drivers/i3c/master/dw-i3c-master.c |  35 +++++-
  include/dw-i3c.h                   |   2 +
  include/i3c.h                      |   4 +
  8 files changed, 339 insertions(+), 1 deletion(-)

create mode 100644 cmd/i3c.c
create mode 100644 doc/usage/cmd/i3c.rst

cmd/Kconfig index 642cc1116e8..551959731f0 renamed from cmd/Kconfig +0 -0

100644

cmd/Kconfig +6 -0
@@ -1327,6 +1327,12 @@ config CMD_I2C
      help
        I2C support.
 
+config CMD_I3C
+     bool "i3c"
+     help
+       Enable command to list i3c devices connected to the i3c controller
+       and perform read and write on the connected i3c devices.
+
  config CMD_W1
      depends on W1
      default y if W1
cmd/Makefile index renamed from cmd/Makefile +0 -0

8410be576bb..082470fa104 100644

cmd/Makefile +1 -0
@@ -95,6 +95,7 @@ obj-$(CONFIG_CMD_GPIO) += gpio.o
  obj-$(CONFIG_CMD_HISTORY) += history.o
  obj-$(CONFIG_CMD_HVC) += smccc.o
  obj-$(CONFIG_CMD_I2C) += i2c.o
+obj-$(CONFIG_CMD_I3C) += i3c.o
  obj-$(CONFIG_CMD_IOTRACE) += iotrace.o
  obj-$(CONFIG_CMD_HASH) += hash.o
  obj-$(CONFIG_CMD_IDE) += ide.o disk.o diff --git a/cmd/i3c.c

b/cmd/i3c.c new file mode 100644 index 00000000000..5631f487cc2

cmd/i3c.c new file +61 -0
@@ -0,0 +1,193 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2023 Intel Coporation.
+ */
+
+#include <bootretry.h>
+#include <cli.h>
+#include <command.h>
+#include <console.h>
+#include <dm.h>
+#include <dw-i3c.h>
+#include <edid.h>
+#include <errno.h>
+#include <log.h>
+#include <malloc.h>
+#include <asm/byteorder.h>
+#include <linux/compiler.h>
+#include <linux/delay.h>
+#include <u-boot/crc.h>
+#include <linux/i3c/master.h>
+
+static struct udevice *currdev;
+static struct udevice *prevdev;
+static struct dw_i3c_master *master;
+
+void low_to_high_bytes(void *data, size_t size) {
+     unsigned char *byte_data = (unsigned char *)data;
+     size_t start = 0;
+     size_t end = size - 1;
+
+     while (start < end) {
+             unsigned char temp = byte_data[start];
+
+             byte_data[start] = byte_data[end];
+             byte_data[end] = temp;
+             start++;
+             end--;
+     }
+}
+
+/**
+ * do_i3c() - Handle the "i3c" command-line command
+ * @cmdtp:    Command data struct pointer
+ * @flag:    Command flag
+ * @argc:    Command-line argument count
+ * @argv:    Array of command-line arguments
+ *
+ * Returns zero on success, CMD_RET_USAGE in case of misuse and
+negative
+ * on error.
+ */
+static int do_i3c(struct cmd_tbl *cmdtp, int flag, int argc, char
+*const argv[]) {
+     struct uclass *uc;
+     int ret;
+     struct udevice *dev_list;
+     u32 length, bytes;
+     u8 *data;
+     u8 *rdata;
+     u8 device_num;
+
Quoted 8 lines

cmd/i3c.c line 66

Quoted 5 lines
cmd/i3c.c new file +5 -0
+     if (argc > 1) {
+             ret = uclass_get_device_by_name(UCLASS_I3C, argv[1], &currdev);
+             if (ret) {
+                     if (!strcmp(argv[1], "help"))
+                             return CMD_RET_USAGE;

You don't need to check for "help". Just return CMD_RET_USAGE if the first argument does not match any of the subcommands.

Will remove this and return CMD_RET_USAGE.

Quoted 23 lines
Quoted 23 lines
cmd/i3c.c new file +22 -0
+
+                     currdev = prevdev;
+                     if (!currdev) {
+                             ret = uclass_get(UCLASS_I3C, &uc);
+                             if (ret)
+                                     return CMD_RET_FAILURE;
+
+                             uclass_foreach_dev(dev_list, uc)
+                                     printf("%s (%s)\n",
+ dev_list->name, dev_list->driver->name);
+
+                             printf("i3c master controller is not initialized: %s\n", argv[1]);
+                             return CMD_RET_FAILURE;
+                     }
+             } else {
+                     master = dev_get_priv(currdev);
+                     printf("current dev: %s\n", currdev->name);
+                     prevdev = currdev;
+             }
+     } else {
+             if (!currdev) {
+                     printf("No i3c device set!\n");
Quoted 8 lines

cmd/i3c.c line 93

Quoted 6 lines
cmd/i3c.c new file +6 -0
+                     return CMD_RET_FAILURE;
+             }
+             printf("dev: %s\n", currdev->name);
+     }
+
+     if (!strcmp(argv[1], "list")) {

Why would you want to reach this if statment for argc == 1?

To list how many instances bind to the drivers.

Quoted 32 lines
Quoted 7 lines
cmd/i3c.c new file +6 -0
+             ret = uclass_get(UCLASS_I3C, &uc);
+             if (ret)
+                     return CMD_RET_FAILURE;
+
+             uclass_foreach_dev(dev_list, uc)
+             printf("%s (%s)\n", dev_list->name, dev_list->driver->name);

cmd/i3c.c

Quoted 10 lines
cmd/i3c.c new file +10 -0
+     }
+
+     if (!strcmp(argv[1], "current")) {
+             if (!currdev)
+                     printf("no current dev!\n");
+             else
+                     printf("current dev: %s\n", currdev->name);
+     }
+
+     if ((!strcmp(argv[1], "write")) && !(argv[2] == NULL) && !(argv[3] == NULL)

&&

cmd/i3c.c line 119

Quoted 10 lines
cmd/i3c.c new file +10 -0
+         !(argv[4] == NULL)) {
+             length = hextoul(argv[3], NULL);
+
+             data = (u8 *)malloc(sizeof(u8) * length);
+             if (!data) {
+                     debug("Memory allocation for data failed\n");
+                     return -ENOMEM;
+             }
+
+             device_num = hextoul(argv[4], NULL);

device_num is u8. You should check that the value returned by hextoul does not exceed 0xff.

Quoted 7 lines

cmd/i3c.c line 120

Quoted 1 line
cmd/i3c.c new file +1 -0
+             bytes = hextoul(argv[2], NULL);

Bytes is only 32bit wide. But the number returned by hextoul can be larger than UINT_MAX leading to truncation.

Please, check the value range.

Sure, I will check the value range and update it.

Quoted 10 lines

cmd/i3c.c line 126

Quoted 6 lines
cmd/i3c.c new file +6 -0
+
+             for (int i = 0; i < length; i++)
+                     data[i] = (u8)((bytes >> (8 * i)) & 0xFF);
+
+             low_to_high_bytes(data, length);
+             ret = dm_i3c_write(currdev, device_num, data, length);

For unknown reasons you have defined the num_bytes parameter as signed int. So length > INT_MAX will be transferred as a negative number.

Quoted 2 lines

Please, be consistent.

Noted, I will take note on this.

Quoted 9 lines

cmd/i3c.c line 134

Quoted 8 lines
cmd/i3c.c new file +8 -0
+             if (ret) {
+                     ret = CMD_RET_FAILURE;
+                     goto write_out;
+             }
+     }
+
+     if (!strcmp(argv[1], "read") && !(argv[2] == NULL) && !(argv[3] == NULL)) {
+             length = hextoul(argv[2], NULL);
Quoted 3 lines

Each subcommand should be handled in a separate static function to avoid sphaghetti code.

Sure, will create a separate static functions for each subcommand.

Quoted 7 lines

cmd/i3c.c line 137

Quoted 2 lines
cmd/i3c.c new file +2 -0
+
+             rdata = (u8 *) malloc(sizeof(u8) * length);

This is not C++ code. Please, remove the (u8 *) conversion.

I would not expect sizeof(u8) to differ from 1. So remove it.

Will remove it.

Quoted 7 lines

cmd/i3c.c line 142

Quoted 6 lines
cmd/i3c.c new file +6 -0
+             if (!rdata) {
+                     debug("Memory allocation for rdata failed\n");
+                     return -ENOMEM;
+             }
+
+             device_num = hextoul(argv[3], NULL);
Quoted 8 lines

Check that hextoul() returns a number in the 0 - 255 range.

cmd/i3c.c line 146

Quoted 4 lines
cmd/i3c.c new file +4 -0
+
+             ret = dm_i3c_read(currdev, device_num, rdata, length);
+             if (ret) {
+                     ret =  CMD_RET_FAILURE;

Please, avoid duplicate space after '='.

Will correct it.

Quoted 6 lines

cmd/i3c.c line 149

Quoted 4 lines
cmd/i3c.c new file +3 -0
+             } else {
+                     printf("Read buff: ");
+                     for (size_t i = 0; i < length; ++i)

length is u32. Why use a larger type for the index?

Not supposed to use larger type of index, will take note on this and be more consistent.

Quoted 6 lines

cmd/i3c.c line 150

Quoted 2 lines
cmd/i3c.c new file +1 -0
+                             printf("%02x", rdata[i]);

Please, use print_hex_dump() here. This is especially helpful when reading hundres of bytes.

Noted. Will replace with print_hex_dump()

Quoted 3 lines

To be honest, it would make more sense to provide an address in memory to receive the data than printing up to INT_MAX bytes.

You are right. To handle larger data byte, better using address in memory to send and receive the data. Will rework.

Quoted 37 lines
Quoted 37 lines
cmd/i3c.c new file +12 -0
+
+                     printf("\n");
+             }
+
+             goto read_out;
+     }
+
+     if (!strcmp(argv[1], "device_list")) {
+             if (master) {
+                     for (int i = 0; i < master->num_i3cdevs; i++) {
+                             printf("device:%d\n", i);
+                             printf("dynamic address:0x%X\n", master->i3cdev[i]-

info.dyn_addr);

cmd/i3c.c new file +4 -0
+                             printf("PID:%llx\n", master->i3cdev[i]->info.pid);
+                             printf("BCR:%X\n", master->i3cdev[i]->info.bcr);
+                             printf("DCR:%X\n", master->i3cdev[i]->info.dcr);
+                             printf("Max Read DS:%X\n", master->i3cdev[i]-

info.max_read_ds);
+ printf("Max Write DS:%X\n", master->i3cdev[i]-
info.max_write_ds);

cmd/i3c.c new file +17 -0
+                             printf("\n");
+                     }
+             }
+     }
+
+     return CMD_RET_SUCCESS;
+
+read_out:
+     free(rdata);
+     return ret;
+
+write_out:
+     free(data);
+     return ret;
+}
+
+U_BOOT_CMD(
Quoted 9 lines

cmd/i3c.c line 190

Quoted 6 lines
cmd/i3c.c new file +6 -0
+     i3c,    5,    1,     do_i3c,
+     "access the system i3c\n",
+     "i3c write<data><length><device_number> - write to device.\n"
+     "i3c read<length><device_number> - read from device.\n"
+     "i3c device_list   - List valid target devices\n"
+     "i3c <i3c name>   - Select i3c controller.\n"

%s/i3c name/host controller/

Will be replaced.

Quoted 16 lines
Quoted 16 lines
cmd/i3c.c new file +3 -0
+     "i3c list   - List all the available i3c controller.\n"
+     "i3c current   - print current i3c controller.\n"
+);
doc/usage/cmd/i3c.rst new file renamed from doc/usage/cmd/i3c.rst +0 -0

mode 100644 index 00000000000..ade7b5c7fc4

doc/usage/cmd/i3c.rst new file +8 -0
@@ -0,0 +1,98 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+.. index::
+   single: i3c (command)
+
+i3c command
+===========
+
Quoted 9 lines

doc/usage/cmd/i3c.rst line 14

Quoted 6 lines
doc/usage/cmd/i3c.rst new file +6 -0
+Synopsis
+--------
+
+::
+
+    i3c <i3c name>

%s/i3c name/host_controller/

Will be replaced.

Quoted 11 lines

doc/usage/cmd/i3c.rst line 18

Quoted 4 lines
doc/usage/cmd/i3c.rst new file +4 -0
+    i3c current
+    i3c list
+    i3c device_list
+    i3c write <data> <length> <device_number>

For sending large amounts of data it would be preferable to replace direct data by a memory start address.

I would not want to type all bytes needed for displaying an image on an LCD screen.

You are right. To handle larger data byte, better using address in memory to send and receive the data. Will rework.

Quoted 6 lines

doc/usage/cmd/i3c.rst line 19

Quoted 2 lines
doc/usage/cmd/i3c.rst new file +1 -0
+    i3c read <length> <device_number>

Same for reading. When reading a camera image you don't want megabytes of data flooding the screen.

Quoted 10 lines

doc/usage/cmd/i3c.rst

Quoted 7 lines
doc/usage/cmd/i3c.rst new file +7 -0
+
+
+Description
+-----------
+
+The ``i3c`` command is used to probe i3c master controller and
+perform read

%s/i3c master/an I3C host/

Will be replaced.

Quoted 4 lines

doc/usage/cmd/i3c.rst line 26

Quoted 1 line
doc/usage/cmd/i3c.rst new file +1 -0
+and write on the i3c devices.

%s/write on the i3c/write operations on the connected I3C/

Will be replaced.

Quoted 8 lines

i3c
---

Probe an I3C host controller and select it for the other sub-commands.

host_controller
name of the host controller to be probed and selected

Quoted 8 lines

doc/usage/cmd/i3c.rst line 31

Quoted 5 lines
doc/usage/cmd/i3c.rst new file +5 -0
+
+i3c current
+------------
+
+* Display the current probed i3c controller.

%s/current probed i3c/currently selected I3C host/

Will be replaced.

Quoted 8 lines

doc/usage/cmd/i3c.rst line 36

Quoted 5 lines
doc/usage/cmd/i3c.rst new file +5 -0
+
+i3c list
+----------
+
+List all the i3c controllers defined in the DT.

%s/i3c/I3C/

Will be replaced.

Quoted 1 line

%s/DT/device-tree/

Will be replaced.

Quoted 19 lines

doc/usage/cmd/i3c.rst line 42

Quoted 8 lines
doc/usage/cmd/i3c.rst new file +7 -0
+
+i3c device_list
+----------------
+
+List all the i3c devices' device number, dynamic address, PID, BCR,
+DCR,
+Max Write Speed and Max Read Speed of the probed i3c controller.

List all the I3C devices connected to the current host controller, displaying

* device number
* dynamic address
* provisional ID (PID)
* value of the Bus Characteristics Register (BCR)
* value of the Device Characteristics Register (DCR)
* maximum write speed in MHz
* maximum read speed in MHz

Quoted 2 lines

Why wouldn't you print the static address, too?

Will include the static address.

Quoted 15 lines

doc/usage/cmd/i3c.rst line 52

Quoted 10 lines
doc/usage/cmd/i3c.rst new file +10 -0
+
+i3c write
+-----------
+
+Perform write to the i3c device.
+
+i3c read
+-----------
+
+Perform read from the i3c device.

Parameters
----------

Quoted 9 lines

doc/usage/cmd/i3c.rst line 56

Quoted 2 lines
doc/usage/cmd/i3c.rst new file +2 -0
+
+i3c name

host_controller

doc/usage/cmd/i3c.rst line 55

Quoted 1 line
doc/usage/cmd/i3c.rst new file +1 -0
+    i3c name defined in DT

Name of the host controller as defined in the device-tree

This will be replaced.

Quoted 10 lines

doc/usage/cmd/i3c.rst line 61

Quoted 6 lines
doc/usage/cmd/i3c.rst new file +6 -0
+
+length
+    Size of the data.
+
+device_number
+    device number that connected to i3c controller.

It is unclear what is meant by device number. Is it the static address or a device number in the driver model?

It should be a device number.

Quoted 6 lines
Quoted 6 lines
doc/usage/cmd/i3c.rst new file +6 -0
+
+data
+    Bytes to be written to device.
+
+Examples
+--------
Quoted 9 lines

doc/usage/cmd/i3c.rst line 73

Quoted 6 lines
doc/usage/cmd/i3c.rst new file +6 -0
+
+Probe i3c0::
+
+    => i3c i3c0
+
+Check cuurent i3c controller::

Display current I3C host controller::

Will be replaced.

Quoted 11 lines

doc/usage/cmd/i3c.rst line 81

Quoted 8 lines
doc/usage/cmd/i3c.rst new file +8 -0
+
+    => i3c current
+
+Check the device number and PID of the connected devices::
+
+    => i3c device_list
+
+Perform write AA byte to a device 0::

Do you mean:

Quoted 3 lines

Write a single byte 0xaa to the device with static address 0 on the selected host controller.

No. device 0 is the device number in the driver model.

Quoted 8 lines

doc/usage/cmd/i3c.rst line 83

Quoted 2 lines
doc/usage/cmd/i3c.rst new file +2 -0
+
+    => i3c write AA 1 0

It is unclear how to format multiple bytes to be written. Please, provide an example with multiple bytes.

Does the data have to be capitalized or is lower case working, too?

Will provide the example for multiple bytes on next version. Lower case is already working and taken care of.

Quoted 7 lines

doc/usage/cmd/i3c.rst line 87

Quoted 4 lines
doc/usage/cmd/i3c.rst new file +4 -0
+
+Perform read from a device 0::
+
+    => i3c read 1 0

Where is the example output?

Missing output. Will add it.

Quoted 4 lines

Best regards

Heinrich

Please expect v5, which I will rework based on the comments.

Regards
Dinesh

Quoted 107 lines

drivers/i3c/master/dw-i3c-master.c static int dw_i3c_master_daa(struct

Quoted 30 lines
doc/usage/cmd/i3c.rst new file +11 -0
+
+Configuration
+-------------
+
+The ``i3c`` command is only available if CONFIG_CMD_I3C=y.
+
+Return value
+------------
+
+If the command succeeds, the return value ``$?`` is set to 0. If an
+error occurs, the return value ``$?`` is set to 1.
doc/usage/index.rst index renamed from doc/usage/index.rst +0 -0

bf2335dc8f0..718b606b162 100644

doc/usage/index.rst +1 -0
@@ -80,6 +80,7 @@ Shell commands
     cmd/if
     cmd/itest
     cmd/imxtract
+   cmd/i3c
     cmd/load
     cmd/loadb
     cmd/loadm
drivers/i3c/master/dw-i3c-master.c +0 -0
index bf5d57937c7..623f5b01dbb 100644
@@ -674,8 +674,11 @@ static int dw_i3c_master_daa(struct

i3c_master_controller *m)

Quoted 76 lines
drivers/i3c/master/dw-i3c-master.c +4 -1
      newdevs &= ~olddevs;
 
      for (pos = 0; pos < master->maxdevs; pos++) {
-             if (newdevs & BIT(pos))
+             if (newdevs & BIT(pos)) {
                      i3c_master_add_i3c_dev_locked(m,
 master->addrs[pos]);
+                     master->i3cdev[pos] = m->this;
+                     master->num_i3cdevs++;
+             }
      }
 
      dw_i3c_master_free_xfer(xfer);
drivers/i3c/master/dw-i3c-master.c +26 -0
@@ -1010,8 +1013,38 @@ err_assert_rst:
      return ret;
  }
 
+static int dw_i3c_master_priv_read(struct udevice *dev, u8 dev_number,
+                                u8 *buf, int buf_size) {
+     struct dw_i3c_master *master = dev_get_priv(dev);
+     struct i3c_dev_desc *i3cdev = master->i3cdev[dev_number];
+     struct i3c_priv_xfer i3c_xfers;
+
+     i3c_xfers.data.in = buf;
+     i3c_xfers.len = buf_size;
+     i3c_xfers.rnw = I3C_MSG_READ;
+
+     return dw_i3c_master_priv_xfers(i3cdev, &i3c_xfers, 1); }
+
+static int dw_i3c_master_priv_write(struct udevice *dev, u8 dev_number,
+                                 u8 *buf, int buf_size) {
+     struct dw_i3c_master *master = dev_get_priv(dev);
+     struct i3c_dev_desc *i3cdev = master->i3cdev[dev_number];
+     struct i3c_priv_xfer i3c_xfers;
+
+     i3c_xfers.data.out = buf;
+     i3c_xfers.len = buf_size;
+     i3c_xfers.rnw = I3C_MSG_WRITE;
+
+     return dw_i3c_master_priv_xfers(i3cdev, &i3c_xfers, 1); }
+
  static const struct dm_i3c_ops dw_i3c_ops = {
      .i3c_xfers = dw_i3c_master_priv_xfers,
+     .read = dw_i3c_master_priv_read,
+     .write = dw_i3c_master_priv_write,
  };
 
  static const struct udevice_id dw_i3c_ids[] = { diff --git

a/include/dw-i3c.h b/include/dw-i3c.h index 42c37d6dfa2..c652de77404 100644

include/dw-i3c.h +2 -0
@@ -241,6 +241,8 @@ struct dw_i3c_master {
      char type[5];
      u8 addrs[MAX_DEVS];
      bool first_broadcast;
+     struct i3c_dev_desc *i3cdev[I3C_BUS_MAX_DEVS];
+     u16 num_i3cdevs;
  };
 
  struct dw_i3c_i2c_dev_data {
include/i3c.h index renamed from include/i3c.h +0 -0

6ef4982dcf6..969753ae49d 100644

include/i3c.h +4 -0
@@ -28,6 +28,10 @@ struct dm_i3c_ops {
      int (*i3c_xfers)(struct i3c_dev_desc *dev,
                       struct i3c_priv_xfer *i3c_xfers,
                       int i3c_nxfers);
+     int (*read)(struct udevice *dev, u8 dev_number,
+                 u8 *buf, int num_bytes);
+     int (*write)(struct udevice *dev, u8 dev_number,
+                  u8 *buf, int num_bytes);
  };
 
  #define i3c_get_ops(dev)    ((struct dm_i3c_ops *)(dev)->driver->ops)
#14 lore raw

PATCH RESEND v4 10/12 test: cmd: Add simple test for i3c

In reply to [email protected]

From: Dinesh Maniyam <[email protected]>

Add simple test to check i3c controller defined in sandbox test DT. Basically, this test case will check validity of the i3c controller by probing it and perform basic commands of cmd/i3c.c

---
 test/cmd/Makefile |  1 +
 test/cmd/i3c.c    | 52 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
 create mode 100644 test/cmd/i3c.c
test/cmd/Makefile +1 -0
index d8a5e77402d..d1c49e2c97a 100644
@@ -34,6 +34,7 @@ obj-$(CONFIG_CMD_PWM) += pwm.o
 obj-$(CONFIG_CMD_READ) += rw.o
 obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
 obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o
+obj-$(CONFIG_CMD_I3C) += i3c.o
 ifdef CONFIG_NET
 obj-$(CONFIG_CMD_WGET) += wget.o
 endif
test/cmd/i3c.c new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
2.35.3
#15 lore raw

PATCH RESEND v4 11/12 configs: sandbox_defconfig: Enable configs for sandbox i3c

In reply to [email protected]

From: Dinesh Maniyam <[email protected]>

Enable configs for sandbox i3c.

---
 configs/sandbox_defconfig | 4 ++++
 1 file changed, 4 insertions(+)
configs/sandbox_defconfig +4 -0
index 861a1f4cd90..ba98cb0ae99 100644
@@ -85,6 +85,7 @@ CONFIG_CMD_GPT=y
 CONFIG_CMD_GPT_RENAME=y
 CONFIG_CMD_IDE=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_I3C=y
 CONFIG_CMD_LOADM=y
 CONFIG_CMD_LSBLK=y
 CONFIG_CMD_MTD=y
@@ -206,6 +207,9 @@ CONFIG_I2C_CROS_EC_LDO=y
 CONFIG_DM_I2C_GPIO=y
 CONFIG_I2C_MUX=y
 CONFIG_I2C_ARB_GPIO_CHALLENGE=y
+CONFIG_I3C=y
+CONFIG_I3C_SANDBOX=y
+CONFIG_DW_I3C_MASTER=y
 CONFIG_CROS_EC_KEYB=y
 CONFIG_I8042_KEYB=y
 CONFIG_IOMMU=y
Signature · 1 line
2.35.3
#16 lore raw

PATCH RESEND v4 12/12 configs: agilex5_defconfig: Enable i3c configs for agilex5

In reply to [email protected]

From: Dinesh Maniyam <[email protected]>

Enable configs for i3c in agilex5.

---
 configs/socfpga_agilex5_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/socfpga_agilex5_defconfig +3 -0
index 8577ac610c2..87febc9f4ce 100644
@@ -44,6 +44,7 @@ CONFIG_CMD_NVEDIT_SELECT=y
 CONFIG_CMD_MEMTEST=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_I3C=y
 CONFIG_CMD_MTD=y
 CONFIG_CMD_SPI=y
 CONFIG_CMD_USB=y
@@ -66,6 +67,8 @@ CONFIG_SPL_ALTERA_SDRAM=y
 CONFIG_DWAPB_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_DW=y
+CONFIG_I3C=y
+CONFIG_DW_I3C_MASTER=y
 CONFIG_MISC=y
 CONFIG_DM_MTD=y
 CONFIG_SPI_FLASH_SPANSION=y
Signature · 1 line
2.35.3
#17 lore raw
In reply to [email protected]
Quoted 13 lines · On Thu, Apr 17, 2025 at 10:18:28AM +0800, [email protected] wrote:

From: Dinesh Maniyam <[email protected]>

This patchset add Synopsys MIPI I3C Driver support for Intel Agilex5 devices.

The i3c driver is leveraged from the master/dw-i3c-master.c, i3c/device.c and i3c/master.c Linux version 6.6.37 LTS And few header files included to be
part of the migration; i3c/internals.h, include/linux/i3c/ccc.h, include/linux/i3c/device.h and include/linux/i3c/master.h. Additional i3c uclass driver and command files added to support i3c read and write in U-Boot.

Quoted 3 lines

Patch status:

Detail changelog can find in commit message.

If there's a v5, please drop "resend" from the subject line, thanks.

Signature · 1 line
Tom
#18 lore raw
Quoted 23 lines

-----Original Message-----
From: Tom Rini <[email protected]>
Sent: Thursday, 17 April 2025 9:57 pm
To: Maniyam, Dinesh <[email protected]>
Cc: [email protected]; Marek <[email protected]>; Simon <[email protected]>; Simon Glass <[email protected]>; Dario Binacchi <[email protected]>; Ilias Apalodimas <[email protected]>; Heinrich Schuchardt <[email protected]>; Jerome Forissier <[email protected]>; Mattijs Korpershoek <[email protected]>; Ibai Erkiaga <[email protected]>; Michal Simek <[email protected]>; Dmitry Rokosov <[email protected]>; Jonas Karlman <[email protected]>; Sebastian Reichel <[email protected]>; Meng, Tingting <[email protected]>; Chee, Tien Fong <[email protected]>; Hea, Kok Kiang <[email protected]>; Ng, Boon Khai <[email protected]>; Yuslaimi, Alif Zakuan <[email protected]>; Zamri, Muhammad Hazim Izzat <[email protected]>; Lim, Jit Loon <[email protected]>; Tang, Sieu Mun <[email protected]>
Subject: Re: [resend v4 00/12] Add Synopsys MIPI I3C Driver support

Quoted 3 lines

[CAUTION: This email is from outside your organization. Unless you trust the sender, do not click on links or open attachments as it may be a fraudulent email attempting to steal your information and/or compromise your computer.]

Hi Tom,

Sure, Noted.

Dinesh