[PATCH 06/10] drivers: i3c: Add i3c uclass driver.
dinesh.maniyam at intel.com
dinesh.maniyam at intel.com
Tue Feb 18 03:57:01 CET 2025
From: Dinesh Maniyam <dinesh.maniyam at intel.com>
Enable i3c general uclass driver. This uclass driver will have
genaral read and write api to call the specific i3c driver.
Signed-off-by: Dinesh Maniyam <dinesh.maniyam at intel.com>
---
drivers/i3c/Makefile | 1 +
drivers/i3c/i3c-uclass.c | 38 ++++++++++++++++++++++++
include/dw-i3c.h | 1 +
include/i3c.h | 63 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 103 insertions(+)
create mode 100644 drivers/i3c/i3c-uclass.c
create mode 100644 include/i3c.h
diff --git a/drivers/i3c/Makefile b/drivers/i3c/Makefile
index 2d42864d79..d560939145 100644
--- a/drivers/i3c/Makefile
+++ b/drivers/i3c/Makefile
@@ -1,3 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-only
+obj-y += i3c-uclass.o
obj-$(CONFIG_DW_I3C_MASTER) += dw-i3c-master.o
\ No newline at end of file
diff --git a/drivers/i3c/i3c-uclass.c b/drivers/i3c/i3c-uclass.c
new file mode 100644
index 0000000000..644f578889
--- /dev/null
+++ b/drivers/i3c/i3c-uclass.c
@@ -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",
+};
diff --git a/include/dw-i3c.h b/include/dw-i3c.h
index e37fd4dc32..920f18bccb 100644
--- a/include/dw-i3c.h
+++ b/include/dw-i3c.h
@@ -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>
diff --git a/include/i3c.h b/include/i3c.h
new file mode 100644
index 0000000000..6ef4982dcf
--- /dev/null
+++ b/include/i3c.h
@@ -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.
+ */
+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.
+ *
+ * @return @see i3c_transfer
+ */
+ int (*i3c_xfers)(struct i3c_dev_desc *dev,
+ struct i3c_priv_xfer *i3c_xfers,
+ int i3c_nxfers);
+};
+
+#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.
+ *
+ * @return 0 for success
+ */
+int dm_i3c_write(struct udevice *dev, u8 dev_number,
+ u8 *buf, int num_bytes);
+
+/**
+ * @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.
+ * @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);
--
2.26.2
More information about the U-Boot
mailing list