]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
drivers: i3c: Add i3c sandbox simple test.
authorDinesh Maniyam <dinesh.maniyam@altera.com>
Wed, 6 Aug 2025 04:32:29 +0000 (12:32 +0800)
committerHeiko Schocher <hs@denx.de>
Wed, 6 Aug 2025 06:40:44 +0000 (08:40 +0200)
Add s simple test for the I3C uclass in sandbox.

Signed-off-by: Dinesh Maniyam <dinesh.maniyam@altera.com>
arch/sandbox/dts/test.dts
drivers/i3c/Kconfig
drivers/i3c/Makefile
drivers/i3c/sandbox_i3c.c [new file with mode: 0644]
test/dm/Makefile
test/dm/i3c.c [new file with mode: 0644]

index bb696c5ef7f4038150b4af2fcd9e84bd565a7c6b..a2c739a2044c728a96b5f4acbf439a42d7e12fb5 100644 (file)
                };
        };
 
+       i3c0 {
+               compatible = "sandbox,i3c";
+       };
+
+       i3c1 {
+               compatible = "sandbox,i3c";
+       };
+
        bootcount@0 {
                compatible = "u-boot,bootcount-rtc";
                rtc = <&rtc_1>;
index d4451057de0d8d5755d529194bb392f9af583af6..d877a7443538c556d5f885aa6cc5a58e0f7ef4eb 100644 (file)
@@ -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"
index 5ddc4743c86b717c5f4d27c9a3edb5fe936371ee..d38d2350c9ae86d833b994c195130925aedb6d8a 100644 (file)
@@ -2,3 +2,4 @@
 
 obj-y                          := i3c-uclass.o device.o master.o
 obj-y                          += master/
+obj-$(CONFIG_I3C_SANDBOX)      += sandbox_i3c.o
diff --git a/drivers/i3c/sandbox_i3c.c b/drivers/i3c/sandbox_i3c.c
new file mode 100644 (file)
index 0000000..e452e98
--- /dev/null
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>
+ */
+
+#include <dm.h>
+#include <errno.h>
+#include <i3c.h>
+#include <linux/i3c/master.h>
+
+struct sandbox_i3c_priv {
+       struct i3c_priv_xfer i3c_xfers;
+};
+
+static int sandbox_i3c_priv_read(struct udevice *dev, u32 dev_number,
+                                u8 *buf, u32 buf_size)
+{
+       struct sandbox_i3c_priv *priv = dev_get_priv(dev);
+       struct i3c_priv_xfer i3c_xfers;
+
+       i3c_xfers = priv->i3c_xfers;
+       i3c_xfers.data.in = buf;
+       i3c_xfers.len = buf_size;
+
+       return 0;
+}
+
+static int sandbox_i3c_priv_write(struct udevice *dev, u32 dev_number,
+                                 u8 *buf, u32 buf_size)
+{
+       struct sandbox_i3c_priv *priv = dev_get_priv(dev);
+       struct i3c_priv_xfer i3c_xfers;
+
+       i3c_xfers = priv->i3c_xfers;
+       i3c_xfers.data.out = buf;
+       i3c_xfers.len = buf_size;
+
+       return 0;
+}
+
+static const struct dm_i3c_ops sandbox_i3c_ops = {
+       .read = sandbox_i3c_priv_read,
+       .write = sandbox_i3c_priv_write,
+};
+
+static const struct udevice_id sandbox_i3c_ids[] = {
+       { .compatible = "sandbox,i3c" },
+       { }
+};
+
+U_BOOT_DRIVER(i3c_sandbox) = {
+       .name = "i3c_sandbox",
+       .id = UCLASS_I3C,
+       .of_match = sandbox_i3c_ids,
+       .ops    = &sandbox_i3c_ops,
+};
index d15859eca30498e24d666228ad8805402c27070c..474e77a2151f351b12fc2b9bcfc0a75ed7a4282d 100644 (file)
@@ -58,6 +58,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
diff --git a/test/dm/i3c.c b/test/dm/i3c.c
new file mode 100644 (file)
index 0000000..81336e6
--- /dev/null
@@ -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);