All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Gerlach <d-gerlach@ti.com>
To: u-boot@lists.denx.de
Subject: [PATCH 2/8] test: Add tests for SOC uclass
Date: Mon, 29 Jun 2020 23:38:47 -0500	[thread overview]
Message-ID: <20200630043853.13276-3-d-gerlach@ti.com> (raw)
In-Reply-To: <20200630043853.13276-1-d-gerlach@ti.com>

Add a sandbox SOC driver, and some tests for the SOC uclass.

Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
---
 arch/sandbox/dts/test.dts          |   4 +
 configs/sandbox64_defconfig        |   1 +
 configs/sandbox_defconfig          |   1 +
 configs/sandbox_flattree_defconfig |   1 +
 configs/sandbox_spl_defconfig      |   1 +
 drivers/soc/Makefile               |   1 +
 drivers/soc/soc_sandbox.c          |  56 ++++++++++++++
 test/dm/Makefile                   |   1 +
 test/dm/soc.c                      | 120 +++++++++++++++++++++++++++++
 9 files changed, 186 insertions(+)
 create mode 100644 drivers/soc/soc_sandbox.c
 create mode 100644 test/dm/soc.c

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 5ce5e2847642..20404c4a0ce9 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -492,6 +492,10 @@
 		};
 	};
 
+	chipid: chipid {
+		compatible = "sandbox,soc";
+	};
+
 	i2s: i2s {
 		compatible = "sandbox,i2s";
 		#sound-dai-cells = <1>;
diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index a3f049e124e1..3ded31f4a9a7 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -114,6 +114,7 @@ CONFIG_LED_GPIO=y
 CONFIG_DM_MAILBOX=y
 CONFIG_SANDBOX_MBOX=y
 CONFIG_MISC=y
+CONFIG_SOC_DEVICE=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_I2C=y
 CONFIG_CROS_EC_LPC=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 5b7569319b73..b19f337f3f0c 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -133,6 +133,7 @@ CONFIG_LED_GPIO=y
 CONFIG_DM_MAILBOX=y
 CONFIG_SANDBOX_MBOX=y
 CONFIG_MISC=y
+CONFIG_SOC_DEVICE=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_I2C=y
 CONFIG_CROS_EC_LPC=y
diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig
index 21f9047046a3..b889ecb058c8 100644
--- a/configs/sandbox_flattree_defconfig
+++ b/configs/sandbox_flattree_defconfig
@@ -99,6 +99,7 @@ CONFIG_LED_GPIO=y
 CONFIG_DM_MAILBOX=y
 CONFIG_SANDBOX_MBOX=y
 CONFIG_MISC=y
+CONFIG_SOC_DEVICE=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_I2C=y
 CONFIG_CROS_EC_LPC=y
diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig
index fc8b26e88cfe..45cb9e78d769 100644
--- a/configs/sandbox_spl_defconfig
+++ b/configs/sandbox_spl_defconfig
@@ -118,6 +118,7 @@ CONFIG_LED_GPIO=y
 CONFIG_DM_MAILBOX=y
 CONFIG_SANDBOX_MBOX=y
 CONFIG_MISC=y
+CONFIG_SOC_DEVICE=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_I2C=y
 CONFIG_CROS_EC_LPC=y
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 1c09a8465670..649e92b3906d 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -4,3 +4,4 @@
 
 obj-$(CONFIG_SOC_TI) += ti/
 obj-$(CONFIG_SOC_DEVICE) += soc-uclass.o
+obj-$(CONFIG_SANDBOX) += soc_sandbox.o
diff --git a/drivers/soc/soc_sandbox.c b/drivers/soc/soc_sandbox.c
new file mode 100644
index 000000000000..5c82ad84fc21
--- /dev/null
+++ b/drivers/soc/soc_sandbox.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Sandbox driver for the SOC uclass
+ *
+ * (C) Copyright 2020 - Texas Instruments Incorporated - http://www.ti.com/
+ * Dave Gerlach <d-gerlach@ti.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <soc.h>
+
+int soc_sandbox_get_family(struct udevice *dev, char *buf, int size)
+{
+	snprintf(buf, size, "SANDBOX1xx");
+
+	return 0;
+}
+
+int soc_sandbox_get_machine(struct udevice *dev, char *buf, int size)
+{
+	snprintf(buf, size, "SANDBOX123");
+
+	return 0;
+}
+
+int soc_sandbox_get_revision(struct udevice *dev, char *buf, int size)
+{
+	snprintf(buf, size, "1.0");
+
+	return 0;
+}
+
+static const struct soc_ops soc_sandbox_ops = {
+	.get_family = soc_sandbox_get_family,
+	.get_revision = soc_sandbox_get_revision,
+	.get_machine = soc_sandbox_get_machine,
+};
+
+int soc_sandbox_probe(struct udevice *dev)
+{
+	return 0;
+}
+
+static const struct udevice_id soc_sandbox_ids[] = {
+	{ .compatible = "sandbox,soc" },
+	{ }
+};
+
+U_BOOT_DRIVER(soc_sandbox) = {
+	.name           = "soc_sandbox",
+	.id             = UCLASS_SOC,
+	.ops		= &soc_sandbox_ops,
+	.of_match       = soc_sandbox_ids,
+	.probe          = soc_sandbox_probe,
+};
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 6c18fd04ce1c..9d570d3f5b89 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -66,6 +66,7 @@ obj-$(CONFIG_AXI) += axi.o
 obj-$(CONFIG_MISC) += misc.o
 obj-$(CONFIG_DM_SERIAL) += serial.o
 obj-$(CONFIG_CPU) += cpu.o
+obj-$(CONFIG_SOC_DEVICE) += soc.o
 obj-$(CONFIG_SOUND) += sound.o
 obj-$(CONFIG_TEE) += tee.o
 obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o
diff --git a/test/dm/soc.c b/test/dm/soc.c
new file mode 100644
index 000000000000..17918d7d47b0
--- /dev/null
+++ b/test/dm/soc.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for the SOC uclass
+ *
+ * (C) Copyright 2020 - Texas Instruments Incorporated - http://www.ti.com/
+ *	Dave Gerlach <d-gerlach@ti.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/test.h>
+#include <dm/uclass-internal.h>
+#include <soc.h>
+#include <test/ut.h>
+
+struct sb_soc_data {
+	unsigned long param;
+};
+
+static int dm_test_soc(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	char text[128];
+	const struct soc_device_attribute *soc_data;
+	const struct sb_soc_data *match_data;
+
+	static const struct sb_soc_data soc_sandbox1_sr10_data = { 0x91919191 };
+	static const struct sb_soc_data soc_sandbox123_data    = { 0x84848484 };
+
+	static const struct soc_device_attribute sb_soc_devices_full[] = {
+		{
+			.family = "SANDBOX0xx",
+			.machine = "SANDBOX012",
+			.revision = "1.0",
+			.data = NULL,
+		},
+		{
+			.family = "SANDBOX1xx",
+			.machine = "SANDBOX107",
+			.revision = "1.0",
+			.data = NULL,
+		},
+		{
+			.family = "SANDBOX1xx",
+			.machine = "SANDBOX123",
+			.revision = "1.0",
+			.data = &soc_sandbox123_data,
+		},
+		{
+			.family = "SANDBOX1xx",
+			.machine = "SANDBOX131",
+			.revision = "2.0",
+			.data = NULL,
+		},
+		{ /* sentinel */ }
+	};
+
+	static const struct soc_device_attribute sb_soc_devices_partial[] = {
+		{
+			.family = "SANDBOX0xx",
+			.revision = "1.0",
+			.data = NULL,
+		},
+		{
+			.family = "SANDBOX1xx",
+			.revision = "1.0",
+			.data = &soc_sandbox1_sr10_data,
+		},
+		{
+			.family = "SANDBOX1xx",
+			.revision = "2.0",
+			.data = NULL,
+		},
+		{ /* sentinel */ }
+	};
+
+	static const struct soc_device_attribute sb_soc_devices_nomatch[] = {
+		{
+			.family = "SANDBOX0xx",
+			.revision = "1.0",
+			.data = NULL,
+		},
+		{
+			.family = "SANDBOX1xx",
+			.revision = "2.0",
+			.data = NULL,
+		},
+		{ /* sentinel */ }
+	};
+
+	ut_assertok(soc_get(&dev));
+
+	ut_assertok(soc_get_machine(dev, text, sizeof(text)));
+	ut_assertok(strcmp(text, "SANDBOX123"));
+
+	ut_assertok(soc_get_family(dev, text, sizeof(text)));
+	ut_assertok(strcmp(text, "SANDBOX1xx"));
+
+	ut_assertok(soc_get_revision(dev, text, sizeof(text)));
+	ut_asserteq_str(text, "1.0");
+
+	soc_data = soc_device_match(sb_soc_devices_full);
+	ut_assert(soc_data);
+
+	match_data = soc_data->data;
+	ut_asserteq(match_data->param, 0x84848484);
+
+	soc_data = soc_device_match(sb_soc_devices_partial);
+	ut_assert(soc_data);
+
+	match_data = soc_data->data;
+	ut_asserteq(match_data->param, 0x91919191);
+
+	soc_data = soc_device_match(sb_soc_devices_nomatch);
+	ut_asserteq_ptr(soc_data, NULL);
+
+	return 0;
+}
+
+DM_TEST(dm_test_soc, DM_TESTF_SCAN_FDT);
-- 
2.20.1

  parent reply	other threads:[~2020-06-30  4:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-30  4:38 [PATCH 0/8] Introduce UCLASS_SOC Dave Gerlach
2020-06-30  4:38 ` [PATCH 1/8] dm: soc: Introduce UCLASS_SOC for SOC ID and attribute matching Dave Gerlach
2020-06-30 12:43   ` Tom Rini
2020-07-08 21:28     ` Dave Gerlach
2020-07-03  3:50   ` Simon Glass
2020-07-08 23:16     ` Dave Gerlach
2020-06-30  4:38 ` Dave Gerlach [this message]
2020-07-03  3:50   ` [PATCH 2/8] test: Add tests for SOC uclass Simon Glass
2020-06-30  4:38 ` [PATCH 3/8] dm: soc: Introduce soc_ti_k3 driver for TI K3 SoCs Dave Gerlach
2020-06-30  4:38 ` [PATCH 4/8] arm: dts: k3-am65-wakeup: Introduce chipid node Dave Gerlach
2020-06-30  4:38 ` [PATCH 5/8] arm: dts: k3-j721e-mcu-wakeup: " Dave Gerlach
2020-06-30  4:38 ` [PATCH 6/8] configs: am65x_evm: Enable CONFIG_SOC_DEVICE and CONFIG_SOC_DEVICE_TI_K3 Dave Gerlach
2020-06-30  4:38 ` [PATCH 7/8] configs: j721e_evm: " Dave Gerlach
2020-06-30  4:38 ` [PATCH 8/8] arm: mach-k3: Use SOC driver for device identification Dave Gerlach
2020-07-08  8:14 ` [PATCH 0/8] Introduce UCLASS_SOC Lokesh Vutla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200630043853.13276-3-d-gerlach@ti.com \
    --to=d-gerlach@ti.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.