]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test: Add tests for SOC uclass
authorDave Gerlach <d-gerlach@ti.com>
Thu, 16 Jul 2020 04:39:58 +0000 (23:39 -0500)
committerSimon Glass <sjg@chromium.org>
Mon, 20 Jul 2020 17:37:47 +0000 (11:37 -0600)
Add a sandbox SOC driver, and some tests for the SOC uclass.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
arch/sandbox/dts/test.dts
configs/sandbox64_defconfig
configs/sandbox_defconfig
configs/sandbox_flattree_defconfig
configs/sandbox_spl_defconfig
drivers/soc/Makefile
drivers/soc/soc_sandbox.c [new file with mode: 0644]
test/dm/Makefile
test/dm/soc.c [new file with mode: 0644]

index 3744a466030073c79e08dc089a518654a69aad37..2ae42397216f3f21a2f01a94aa0f4685891a11bc 100644 (file)
                };
        };
 
+       chipid: chipid {
+               compatible = "sandbox,soc";
+       };
+
        i2s: i2s {
                compatible = "sandbox,i2s";
                #sound-dai-cells = <1>;
index dcf2f44b584a1af9a36ed742a150cc24d198b478..a3b7ff444f0caae8272f39ff0c199bae8292c8a1 100644 (file)
@@ -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
index 6059d668af770d2e890bb62345a1b2d2c8d4515c..17c9b332f5a1f3047b922eddd7b3d7d7df51eb01 100644 (file)
@@ -139,6 +139,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
index 4158b9b86d4fb48843f3088525b32524df1edbaf..93ab210ebbf1981dc7b4661e28854b04a9c84717 100644 (file)
@@ -103,6 +103,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
index b3274a93b4169f2a83ff527bb876a47e2fd868a3..25c974f6fe714da3e1efd5a3ea6ef4face8ab6be 100644 (file)
@@ -120,6 +120,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
index 1c09a84656704371a904ff38d00e46e87fa47085..649e92b3906d5bec76fa0737488212dc0051f2df 100644 (file)
@@ -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 (file)
index 0000000..5c82ad8
--- /dev/null
@@ -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,
+};
index b03c96da06228454ccb71d2f7499f498e2ec40e7..839111791b9ce1331907eb73351b3a3449c27859 100644 (file)
@@ -68,6 +68,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 (file)
index 0000000..3ad0f56
--- /dev/null
@@ -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_attr *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_attr 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_attr 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_attr 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);