]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
reset: implement a reset test
authorStephen Warren <swarren@nvidia.com>
Fri, 17 Jun 2016 15:43:59 +0000 (09:43 -0600)
committerSimon Glass <sjg@chromium.org>
Sun, 19 Jun 2016 23:05:55 +0000 (17:05 -0600)
This adds a sandbox reset implementation (provider), a test client
device, instantiates them both from Sandbox's DT, and adds a DM test
that excercises everything.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>
arch/sandbox/dts/test.dts
arch/sandbox/include/asm/reset.h [new file with mode: 0644]
configs/sandbox_defconfig
drivers/reset/Kconfig
drivers/reset/Makefile
drivers/reset/sandbox-reset-test.c [new file with mode: 0644]
drivers/reset/sandbox-reset.c [new file with mode: 0644]
test/dm/Makefile
test/dm/reset.c [new file with mode: 0644]

index 686c215aea72ccadbe591aa0bda7313a9b915d92..879b30e3ccc6f8a0566c44ff860b5433b65c600f 100644 (file)
                compatible = "sandbox,reset";
        };
 
+       resetc: reset-ctl {
+               compatible = "sandbox,reset-ctl";
+               #reset-cells = <1>;
+       };
+
+       reset-ctl-test {
+               compatible = "sandbox,reset-ctl-test";
+               resets = <&resetc 100>, <&resetc 2>;
+               reset-names = "other", "test";
+       };
+
        rproc_1: rproc@1 {
                compatible = "sandbox,test-processor";
                remoteproc-name = "remoteproc-test-dev1";
diff --git a/arch/sandbox/include/asm/reset.h b/arch/sandbox/include/asm/reset.h
new file mode 100644 (file)
index 0000000..7146aa5
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2016, NVIDIA CORPORATION.
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#ifndef __SANDBOX_RESET_H
+#define __SANDBOX_RESET_H
+
+#include <common.h>
+
+struct udevice;
+
+int sandbox_reset_query(struct udevice *dev, unsigned long id);
+
+int sandbox_reset_test_get(struct udevice *dev);
+int sandbox_reset_test_assert(struct udevice *dev);
+int sandbox_reset_test_deassert(struct udevice *dev);
+int sandbox_reset_test_free(struct udevice *dev);
+
+#endif
index 4eb3c224fdc075c0d313005bfe5c97f8d9c1ecb5..94253a65e4f9667edaa10dc283b6e763bffa5b07 100644 (file)
@@ -1,4 +1,5 @@
 CONFIG_SYS_MALLOC_F_LEN=0x2000
+CONFIG_BLK=y
 CONFIG_MMC=y
 CONFIG_PCI=y
 CONFIG_DEFAULT_DEVICE_TREE="sandbox"
@@ -70,7 +71,6 @@ CONFIG_DEVRES=y
 CONFIG_DEBUG_DEVRES=y
 CONFIG_ADC=y
 CONFIG_ADC_SANDBOX=y
-CONFIG_BLK=y
 CONFIG_CLK=y
 CONFIG_CPU=y
 CONFIG_DM_DEMO=y
@@ -89,6 +89,9 @@ CONFIG_I2C_ARB_GPIO_CHALLENGE=y
 CONFIG_CROS_EC_KEYB=y
 CONFIG_LED=y
 CONFIG_LED_GPIO=y
+CONFIG_DM_MAILBOX=y
+CONFIG_SANDBOX_MBOX=y
+CONFIG_MISC=y
 CONFIG_CMD_CROS_EC=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_I2C=y
@@ -140,6 +143,8 @@ CONFIG_DM_REGULATOR_SANDBOX=y
 CONFIG_REGULATOR_TPS65090=y
 CONFIG_RAM=y
 CONFIG_REMOTEPROC_SANDBOX=y
+CONFIG_DM_RESET=y
+CONFIG_SANDBOX_RESET=y
 CONFIG_DM_RTC=y
 CONFIG_SANDBOX_SERIAL=y
 CONFIG_SOUND=y
@@ -170,6 +175,3 @@ CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
 CONFIG_UT_ENV=y
-CONFIG_MISC=y
-CONFIG_DM_MAILBOX=y
-CONFIG_SANDBOX_MBOX=y
index 5c449a99d39d9490fc892430f26e0c109b9941c6..0fe8cc3827f14bea1f04e9ff29722a09182aa621 100644 (file)
@@ -12,4 +12,12 @@ config DM_RESET
          although driving such reset isgnals using GPIOs may be more
          appropriate in this case.
 
+config SANDBOX_RESET
+       bool "Enable the sandbox reset test driver"
+       depends on DM_MAILBOX && SANDBOX
+       help
+         Enable support for a test reset controller implementation, which
+         simply accepts requests to reset various HW modules without actually
+         doing anything beyond a little error checking.
+
 endmenu
index 508608e83f875644844f665bf699bd6d2ea4960e..71f3b219613ef183f54a59d8887f69b3d9e2c83f 100644 (file)
@@ -3,3 +3,5 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_DM_RESET) += reset-uclass.o
+obj-$(CONFIG_SANDBOX_MBOX) += sandbox-reset.o
+obj-$(CONFIG_SANDBOX_MBOX) += sandbox-reset-test.o
diff --git a/drivers/reset/sandbox-reset-test.c b/drivers/reset/sandbox-reset-test.c
new file mode 100644 (file)
index 0000000..e37d6c9
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2016, NVIDIA CORPORATION.
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <reset.h>
+#include <asm/io.h>
+#include <asm/reset.h>
+
+struct sandbox_reset_test {
+       struct reset_ctl ctl;
+};
+
+int sandbox_reset_test_get(struct udevice *dev)
+{
+       struct sandbox_reset_test *sbrt = dev_get_priv(dev);
+
+       return reset_get_by_name(dev, "test", &sbrt->ctl);
+}
+
+int sandbox_reset_test_assert(struct udevice *dev)
+{
+       struct sandbox_reset_test *sbrt = dev_get_priv(dev);
+
+       return reset_assert(&sbrt->ctl);
+}
+
+int sandbox_reset_test_deassert(struct udevice *dev)
+{
+       struct sandbox_reset_test *sbrt = dev_get_priv(dev);
+
+       return reset_deassert(&sbrt->ctl);
+}
+
+int sandbox_reset_test_free(struct udevice *dev)
+{
+       struct sandbox_reset_test *sbrt = dev_get_priv(dev);
+
+       return reset_free(&sbrt->ctl);
+}
+
+static const struct udevice_id sandbox_reset_test_ids[] = {
+       { .compatible = "sandbox,reset-ctl-test" },
+       { }
+};
+
+U_BOOT_DRIVER(sandbox_reset_test) = {
+       .name = "sandbox_reset_test",
+       .id = UCLASS_MISC,
+       .of_match = sandbox_reset_test_ids,
+       .priv_auto_alloc_size = sizeof(struct sandbox_reset_test),
+};
diff --git a/drivers/reset/sandbox-reset.c b/drivers/reset/sandbox-reset.c
new file mode 100644 (file)
index 0000000..4258af5
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2016, NVIDIA CORPORATION.
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <reset-uclass.h>
+#include <asm/io.h>
+#include <asm/reset.h>
+
+#define SANDBOX_RESET_SIGNALS 3
+
+struct sandbox_reset_signal {
+       bool asserted;
+};
+
+struct sandbox_reset {
+       struct sandbox_reset_signal signals[SANDBOX_RESET_SIGNALS];
+};
+
+static int sandbox_reset_request(struct reset_ctl *reset_ctl)
+{
+       debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
+
+       if (reset_ctl->id >= SANDBOX_RESET_SIGNALS)
+               return -EINVAL;
+
+       return 0;
+}
+
+static int sandbox_reset_free(struct reset_ctl *reset_ctl)
+{
+       debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
+
+       return 0;
+}
+
+static int sandbox_reset_assert(struct reset_ctl *reset_ctl)
+{
+       struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
+
+       debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
+
+       sbr->signals[reset_ctl->id].asserted = true;
+
+       return 0;
+}
+
+static int sandbox_reset_deassert(struct reset_ctl *reset_ctl)
+{
+       struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
+
+       debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
+
+       sbr->signals[reset_ctl->id].asserted = false;
+
+       return 0;
+}
+
+static int sandbox_reset_bind(struct udevice *dev)
+{
+       debug("%s(dev=%p)\n", __func__, dev);
+
+       return 0;
+}
+
+static int sandbox_reset_probe(struct udevice *dev)
+{
+       debug("%s(dev=%p)\n", __func__, dev);
+
+       return 0;
+}
+
+static const struct udevice_id sandbox_reset_ids[] = {
+       { .compatible = "sandbox,reset-ctl" },
+       { }
+};
+
+struct reset_ops sandbox_reset_reset_ops = {
+       .request = sandbox_reset_request,
+       .free = sandbox_reset_free,
+       .rst_assert = sandbox_reset_assert,
+       .rst_deassert = sandbox_reset_deassert,
+};
+
+U_BOOT_DRIVER(sandbox_reset) = {
+       .name = "sandbox_reset",
+       .id = UCLASS_RESET,
+       .of_match = sandbox_reset_ids,
+       .bind = sandbox_reset_bind,
+       .probe = sandbox_reset_probe,
+       .priv_auto_alloc_size = sizeof(struct sandbox_reset),
+       .ops = &sandbox_reset_reset_ops,
+};
+
+int sandbox_reset_query(struct udevice *dev, unsigned long id)
+{
+       struct sandbox_reset *sbr = dev_get_priv(dev);
+
+       debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
+
+       if (id >= SANDBOX_RESET_SIGNALS)
+               return -EINVAL;
+
+       return sbr->signals[id].asserted;
+}
index 9eaf04b9ba98cd06739e8cab87a06ae95bcb09d4..cad3374e43d67694b32804af00a47691800fd1fb 100644 (file)
@@ -27,6 +27,7 @@ obj-$(CONFIG_DM_PCI) += pci.o
 obj-$(CONFIG_RAM) += ram.o
 obj-y += regmap.o
 obj-$(CONFIG_REMOTEPROC) += remoteproc.o
+obj-$(CONFIG_DM_RESET) += reset.o
 obj-$(CONFIG_SYSRESET) += sysreset.o
 obj-$(CONFIG_DM_RTC) += rtc.o
 obj-$(CONFIG_DM_SPI_FLASH) += sf.o
diff --git a/test/dm/reset.c b/test/dm/reset.c
new file mode 100644 (file)
index 0000000..0ae8031
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2016, NVIDIA CORPORATION.
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/test.h>
+#include <asm/reset.h>
+#include <test/ut.h>
+
+/* This must match the specifier for mbox-names="test" in the DT node */
+#define TEST_RESET_ID 2
+
+static int dm_test_reset(struct unit_test_state *uts)
+{
+       struct udevice *dev_reset;
+       struct udevice *dev_test;
+
+       ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
+                                             &dev_reset));
+       ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
+
+       ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
+                                             &dev_test));
+       ut_assertok(sandbox_reset_test_get(dev_test));
+
+       ut_assertok(sandbox_reset_test_assert(dev_test));
+       ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
+
+       ut_assertok(sandbox_reset_test_deassert(dev_test));
+       ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
+
+       ut_assertok(sandbox_reset_test_free(dev_test));
+
+       return 0;
+}
+DM_TEST(dm_test_reset, DM_TESTF_SCAN_FDT);