summaryrefslogtreecommitdiff
path: root/drivers/reset
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2016-06-17 09:43:59 -0600
committerSimon Glass <sjg@chromium.org>2016-06-19 17:05:55 -0600
commit4581b717b1bf0fb04e7d9fcaf3d4c23d357154ac (patch)
treed59cea67293deab951e1322d4ab8add35ed555de /drivers/reset
parent89c1e2da78f82a09685006291ce8bb44f635fa25 (diff)
reset: implement a reset test
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>
Diffstat (limited to 'drivers/reset')
-rw-r--r--drivers/reset/Kconfig8
-rw-r--r--drivers/reset/Makefile2
-rw-r--r--drivers/reset/sandbox-reset-test.c55
-rw-r--r--drivers/reset/sandbox-reset.c108
4 files changed, 173 insertions, 0 deletions
diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index 5c449a99d3..0fe8cc3827 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -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
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index 508608e83f..71f3b21961 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -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
index 0000000000..e37d6c91ef
--- /dev/null
+++ b/drivers/reset/sandbox-reset-test.c
@@ -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
index 0000000000..4258af521b
--- /dev/null
+++ b/drivers/reset/sandbox-reset.c
@@ -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;
+}