]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test: Add tests for the multiplexer framework
authorJean-Jacques Hiblot <jjhiblot@ti.com>
Fri, 16 Oct 2020 10:46:34 +0000 (16:16 +0530)
committerTom Rini <trini@konsulko.com>
Wed, 28 Oct 2020 15:49:31 +0000 (11:49 -0400)
Provide tests to check the behavior of the multiplexer framework.

Two sets of tests are added. One is using an emulated multiplexer driver
that can be used to test basic functionality like select, deselect, etc.
The other is using the mmio mux which adds tests specific to it.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
arch/sandbox/dts/test.dts
configs/sandbox_defconfig
test/dm/Makefile
test/dm/mux-emul.c [new file with mode: 0644]
test/dm/mux-mmio.c [new file with mode: 0644]

index fa84b2c10f3bc8af412478b3eede0c300de294b5..70ccb4951ad3a5eef2444d33177f579b1be49185 100644 (file)
@@ -3,6 +3,7 @@
 #include <dt-bindings/gpio/gpio.h>
 #include <dt-bindings/gpio/sandbox-gpio.h>
 #include <dt-bindings/pinctrl/sandbox-pinmux.h>
+#include <dt-bindings/mux/mux.h>
 
 / {
        model = "sandbox";
                interrupts-extended = <&irq 3 0>;
                acpi,name = "GHIJ";
                phandle-value = <&gpio_c 10>, <0xFFFFFFFF 20>, <&gpio_a 30>;
+
+               mux-controls = <&muxcontroller0 0>, <&muxcontroller0 1>,
+                              <&muxcontroller0 2>, <&muxcontroller0 3>,
+                              <&muxcontroller1>;
+               mux-control-names = "mux0", "mux1", "mux2", "mux3", "mux4";
+               mux-syscon = <&syscon3>;
        };
 
        junk {
                compatible = "denx,u-boot-fdt-test";
                ping-expect = <3>;
                ping-add = <3>;
+
+               mux-controls = <&muxcontroller0 0>;
+               mux-control-names = "mux0";
        };
 
        phy_provider0: gen_phy@0 {
                        0x58 8>;
        };
 
+       syscon3: syscon@3 {
+               compatible = "simple-mfd", "syscon";
+               reg = <0x000100 0x10>;
+
+               muxcontroller0: a-mux-controller {
+                       compatible = "mmio-mux";
+                       #mux-control-cells = <1>;
+
+                       mux-reg-masks = <0x0 0x30>, /* 0: reg 0x0, bits 5:4 */
+                                       <0xc 0x1E>, /* 1: reg 0xc, bits 4:1 */
+                                       <0x4 0xFF>; /* 2: reg 0x4, bits 7:0 */
+                       idle-states = <MUX_IDLE_AS_IS>, <0x02>, <0x73>;
+                       u-boot,mux-autoprobe;
+               };
+       };
+
+       muxcontroller1: emul-mux-controller {
+               compatible = "mux-emul";
+               #mux-control-cells = <0>;
+               u-boot,mux-autoprobe;
+               idle-state = <0xabcd>;
+       };
+
        timer@0 {
                compatible = "sandbox,timer";
                clock-frequency = <1000000>;
index b15b1889e07bff3339cbd7ae24c0ac17a64a5635..1b0475243bcf9a250c0bfd79dba141a1bb451d30 100644 (file)
@@ -179,6 +179,8 @@ CONFIG_SPI_FLASH_SPANSION=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_SST=y
 CONFIG_SPI_FLASH_WINBOND=y
+CONFIG_MULTIPLEXER=y
+CONFIG_MUX_MMIO=y
 CONFIG_DM_ETH=y
 CONFIG_NVME=y
 CONFIG_PCI=y
index e2b07983885a61107174b5fdc1a3dfe121ac9fd7..93484b48ebfca4b1af3033dd30f70c63faff112f 100644 (file)
@@ -57,6 +57,8 @@ obj-$(CONFIG_DM_SPI_FLASH) += sf.o
 obj-$(CONFIG_SMEM) += smem.o
 obj-$(CONFIG_DM_SPI) += spi.o
 obj-y += syscon.o
+obj-$(CONFIG_MUX_MMIO) += mux-mmio.o
+obj-$(CONFIG_MULTIPLEXER) += mux-emul.o
 obj-$(CONFIG_DM_USB) += usb.o
 obj-$(CONFIG_DM_PMIC) += pmic.o
 obj-$(CONFIG_DM_REGULATOR) += regulator.o
diff --git a/test/dm/mux-emul.c b/test/dm/mux-emul.c
new file mode 100644 (file)
index 0000000..141fd4d
--- /dev/null
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
+ * Pratyush Yadav <p.yadav@ti.com>
+ */
+#include <common.h>
+#include <dm.h>
+#include <mux.h>
+#include <mux-internal.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+struct mux_emul_priv {
+       u32 state;
+};
+
+static int mux_emul_set(struct mux_control *mux, int state)
+{
+       struct mux_emul_priv *priv = dev_get_priv(mux->dev);
+
+       priv->state = state;
+       return 0;
+}
+
+static int mux_emul_probe(struct udevice *dev)
+{
+       struct mux_chip *mux_chip = dev_get_uclass_priv(dev);
+       struct mux_control *mux;
+       u32 idle_state;
+       int ret;
+
+       ret = mux_alloc_controllers(dev, 1);
+       if (ret < 0)
+               return ret;
+
+       mux = &mux_chip->mux[0];
+
+       ret = dev_read_u32(dev, "idle-state", &idle_state);
+       if (ret)
+               return ret;
+
+       mux->idle_state = idle_state;
+       mux->states = 0x100000;
+
+       return 0;
+}
+
+static const struct mux_control_ops mux_emul_ops = {
+       .set = mux_emul_set,
+};
+
+static const struct udevice_id mux_emul_of_match[] = {
+       { .compatible = "mux-emul" },
+       { /* sentinel */ },
+};
+
+U_BOOT_DRIVER(emul_mux) = {
+       .name = "mux-emul",
+       .id = UCLASS_MUX,
+       .of_match = mux_emul_of_match,
+       .ops = &mux_emul_ops,
+       .probe = mux_emul_probe,
+       .priv_auto_alloc_size = sizeof(struct mux_emul_priv),
+};
+
+static int dm_test_mux_emul_default_state(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+       struct mux_control *mux;
+       struct mux_emul_priv *priv;
+
+       ut_assertok(uclass_get_device_by_name(UCLASS_TEST_FDT, "a-test",
+                                             &dev));
+       ut_assertok(mux_control_get(dev, "mux4", &mux));
+
+       priv = dev_get_priv(mux->dev);
+
+       ut_asserteq(0xabcd, priv->state);
+
+       return 0;
+}
+DM_TEST(dm_test_mux_emul_default_state, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+static int dm_test_mux_emul_select_deselect(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+       struct mux_control *mux;
+       struct mux_emul_priv *priv;
+
+       gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
+       ut_assertok(uclass_get_device_by_name(UCLASS_TEST_FDT, "a-test",
+                                             &dev));
+       ut_assertok(mux_control_get(dev, "mux4", &mux));
+
+       priv = dev_get_priv(mux->dev);
+
+       ut_assertok(mux_control_select(mux, 0x1234));
+       ut_asserteq(priv->state, 0x1234);
+
+       ut_assertok(mux_control_deselect(mux));
+       ut_asserteq(priv->state, 0xabcd);
+
+       return 0;
+}
+DM_TEST(dm_test_mux_emul_select_deselect, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
diff --git a/test/dm/mux-mmio.c b/test/dm/mux-mmio.c
new file mode 100644 (file)
index 0000000..fd353d8
--- /dev/null
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
+ * Jean-Jacques Hiblot <jjhiblot@ti.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <mux.h>
+#include <regmap.h>
+#include <syscon.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <dm/device-internal.h>
+#include <test/ut.h>
+
+static int dm_test_mux_mmio_select(struct unit_test_state *uts)
+{
+       struct udevice *dev, *dev_b;
+       struct regmap *map;
+       struct mux_control *ctl0_a, *ctl0_b;
+       struct mux_control *ctl1;
+       struct mux_control *ctl_err;
+       u32 val;
+       int i;
+
+       sandbox_set_enable_memio(true);
+
+       ut_assertok(uclass_get_device_by_name(UCLASS_TEST_FDT, "a-test",
+                                             &dev));
+       ut_assertok(uclass_get_device_by_name(UCLASS_TEST_FDT, "b-test",
+                                             &dev_b));
+       map = syscon_regmap_lookup_by_phandle(dev, "mux-syscon");
+       ut_assertok_ptr(map);
+       ut_assert(map);
+
+       ut_assertok(mux_control_get(dev, "mux0", &ctl0_a));
+       ut_assertok(mux_control_get(dev, "mux1", &ctl1));
+       ut_asserteq(-ERANGE, mux_control_get(dev, "mux3", &ctl_err));
+       ut_asserteq(-ENODATA, mux_control_get(dev, "dummy", &ctl_err));
+       ut_assertok(mux_control_get(dev_b, "mux0", &ctl0_b));
+
+       for (i = 0; i < mux_control_states(ctl0_a); i++) {
+               /* Select a new state and verify the value in the regmap. */
+               ut_assertok(mux_control_select(ctl0_a, i));
+               ut_assertok(regmap_read(map, 0, &val));
+               ut_asserteq(i, (val & 0x30) >> 4);
+               /*
+                * Deselect the mux and verify that the value in the regmap
+                * reflects the idle state (fixed to MUX_IDLE_AS_IS).
+                */
+               ut_assertok(mux_control_deselect(ctl0_a));
+               ut_assertok(regmap_read(map, 0, &val));
+               ut_asserteq(i, (val & 0x30) >> 4);
+       }
+
+       for (i = 0; i < mux_control_states(ctl1); i++) {
+               /* Select a new state and verify the value in the regmap. */
+               ut_assertok(mux_control_select(ctl1, i));
+               ut_assertok(regmap_read(map, 0xc, &val));
+               ut_asserteq(i, (val & 0x1E) >> 1);
+               /*
+                * Deselect the mux and verify that the value in the regmap
+                * reflects the idle state (fixed to 2).
+                */
+               ut_assertok(mux_control_deselect(ctl1));
+               ut_assertok(regmap_read(map, 0xc, &val));
+               ut_asserteq(2, (val & 0x1E) >> 1);
+       }
+
+       /* Try unbalanced selection/deselection. */
+       ut_assertok(mux_control_select(ctl0_a, 0));
+       ut_asserteq(-EBUSY, mux_control_select(ctl0_a, 1));
+       ut_asserteq(-EBUSY, mux_control_select(ctl0_a, 0));
+       ut_assertok(mux_control_deselect(ctl0_a));
+
+       /* Try concurrent selection. */
+       ut_assertok(mux_control_select(ctl0_a, 0));
+       ut_assert(mux_control_select(ctl0_b, 0));
+       ut_assertok(mux_control_deselect(ctl0_a));
+       ut_assertok(mux_control_select(ctl0_b, 0));
+       ut_assert(mux_control_select(ctl0_a, 0));
+       ut_assertok(mux_control_deselect(ctl0_b));
+       ut_assertok(mux_control_select(ctl0_a, 0));
+       ut_assertok(mux_control_deselect(ctl0_a));
+
+       return 0;
+}
+DM_TEST(dm_test_mux_mmio_select, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Test that managed API for mux work correctly */
+static int dm_test_devm_mux_mmio(struct unit_test_state *uts)
+{
+       struct udevice *dev, *dev_b;
+       struct mux_control *ctl0_a, *ctl0_b;
+       struct mux_control *ctl1;
+       struct mux_control *ctl_err;
+
+       sandbox_set_enable_memio(true);
+
+       ut_assertok(uclass_get_device_by_name(UCLASS_TEST_FDT, "a-test",
+                                             &dev));
+       ut_assertok(uclass_get_device_by_name(UCLASS_TEST_FDT, "b-test",
+                                             &dev_b));
+
+       ctl0_a = devm_mux_control_get(dev, "mux0");
+       ut_assertok_ptr(ctl0_a);
+       ut_assert(ctl0_a);
+       ctl1 = devm_mux_control_get(dev, "mux1");
+       ut_assertok_ptr(ctl1);
+       ut_assert(ctl1);
+       ctl_err = devm_mux_control_get(dev, "mux3");
+       ut_asserteq(-ERANGE, PTR_ERR(ctl_err));
+       ctl_err = devm_mux_control_get(dev, "dummy");
+       ut_asserteq(-ENODATA, PTR_ERR(ctl_err));
+
+       ctl0_b = devm_mux_control_get(dev_b, "mux0");
+       ut_assertok_ptr(ctl0_b);
+       ut_assert(ctl0_b);
+
+       /* Try concurrent selection. */
+       ut_assertok(mux_control_select(ctl0_a, 0));
+       ut_assert(mux_control_select(ctl0_b, 0));
+       ut_assertok(mux_control_deselect(ctl0_a));
+       ut_assertok(mux_control_select(ctl0_b, 0));
+       ut_assert(mux_control_select(ctl0_a, 0));
+       ut_assertok(mux_control_deselect(ctl0_b));
+
+       /* Remove one device and check that the mux is released. */
+       ut_assertok(mux_control_select(ctl0_a, 0));
+       ut_assert(mux_control_select(ctl0_b, 0));
+       device_remove(dev, DM_REMOVE_NORMAL);
+       ut_assertok(mux_control_select(ctl0_b, 0));
+
+       device_remove(dev_b, DM_REMOVE_NORMAL);
+       return 0;
+}
+DM_TEST(dm_test_devm_mux_mmio, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);