From patchwork Tue May 17 16:46:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Warren X-Patchwork-Id: 623211 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3r8NWv20f5z9sf6 for ; Wed, 18 May 2016 02:46:35 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E2162A754E; Tue, 17 May 2016 18:46:32 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jPFenOteuJMr; Tue, 17 May 2016 18:46:32 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 74218A74DE; Tue, 17 May 2016 18:46:32 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0B7C0A752D for ; Tue, 17 May 2016 18:46:28 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7C9hl3SN1WKZ for ; Tue, 17 May 2016 18:46:27 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from avon.wwwdotorg.org (avon.wwwdotorg.org [70.85.31.133]) by theia.denx.de (Postfix) with ESMTPS id 8BE1DA74C5 for ; Tue, 17 May 2016 18:46:24 +0200 (CEST) Received: from swarren-lx1.nvidia.com (thunderhill.nvidia.com [216.228.112.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by avon.wwwdotorg.org (Postfix) with ESMTPSA id CEC3C1C043C; Tue, 17 May 2016 10:46:21 -0600 (MDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.99 at avon.wwwdotorg.org From: Stephen Warren To: Simon Glass Date: Tue, 17 May 2016 10:46:08 -0600 Message-Id: <1463503568-14682-2-git-send-email-swarren@wwwdotorg.org> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1463503568-14682-1-git-send-email-swarren@wwwdotorg.org> References: <1463503568-14682-1-git-send-email-swarren@wwwdotorg.org> X-NVConfidentiality: public Cc: u-boot@lists.denx.de, Stephen Warren Subject: [U-Boot] [PATCH 2/2] reset: implement a reset test X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Stephen Warren 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 Acked-by: Simon Glass --- arch/sandbox/dts/test.dts | 11 ++++ arch/sandbox/include/asm/reset.h | 21 ++++++++ configs/sandbox_defconfig | 2 + drivers/reset/Kconfig | 8 +++ drivers/reset/Makefile | 2 + drivers/reset/sandbox-reset-test.c | 55 +++++++++++++++++++ drivers/reset/sandbox-reset.c | 108 +++++++++++++++++++++++++++++++++++++ test/dm/Makefile | 1 + test/dm/reset.c | 39 ++++++++++++++ 9 files changed, 247 insertions(+) create mode 100644 arch/sandbox/include/asm/reset.h create mode 100644 drivers/reset/sandbox-reset-test.c create mode 100644 drivers/reset/sandbox-reset.c create mode 100644 test/dm/reset.c diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 686c215aea72..879b30e3ccc6 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -259,6 +259,17 @@ 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 index 000000000000..7146aa5ab270 --- /dev/null +++ b/arch/sandbox/include/asm/reset.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2016, NVIDIA CORPORATION. + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef __SANDBOX_RESET_H +#define __SANDBOX_RESET_H + +#include + +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 diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 8613da2c15f5..9562a4ff73a9 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -170,3 +170,5 @@ CONFIG_UT_ENV=y CONFIG_MISC=y CONFIG_DM_MAILBOX=y CONFIG_SANDBOX_MBOX=y +CONFIG_DM_RESET=y +CONFIG_SANDBOX_RESET=y diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig index 5c449a99d39d..0fe8cc3827f1 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 508608e83f87..71f3b219613e 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 000000000000..6fe588e40ba6 --- /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 +#include +#include +#include +#include + +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 000000000000..e07a95991f7f --- /dev/null +++ b/drivers/reset/sandbox-reset.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2016, NVIDIA CORPORATION. + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include +#include +#include +#include +#include + +#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; +} diff --git a/test/dm/Makefile b/test/dm/Makefile index 9eaf04b9ba98..cad3374e43d6 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -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 index 000000000000..0ae8031540c2 --- /dev/null +++ b/test/dm/reset.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016, NVIDIA CORPORATION. + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include +#include +#include +#include +#include + +/* 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);