From patchwork Tue Feb 26 20:31:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Goldschmidt X-Patchwork-Id: 1048549 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="D0ElVDqP"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 4489YC6Xddz9s7T for ; Wed, 27 Feb 2019 07:35:11 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 6D1CEC21D74; Tue, 26 Feb 2019 20:33:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 49C4AC21EDE; Tue, 26 Feb 2019 20:32:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 42C12C21EE4; Tue, 26 Feb 2019 20:32:19 +0000 (UTC) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by lists.denx.de (Postfix) with ESMTPS id 6BE6FC21E30 for ; Tue, 26 Feb 2019 20:32:15 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id r5so15436996wrg.9 for ; Tue, 26 Feb 2019 12:32:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2xlbwwijybmfpIoOeqQvSfJsnXXYG0pnuQFRS3i5Di8=; b=D0ElVDqPqw1Nl4UelQHW44b0zGbzbQGczUTqkZqnbUtmwIAn7W6bp+IhJmHEVwc+bk PwdXrfIF9uCbqie5/fg7ItjkV3g8Of6ZLZDFmGHWzVrGEGWuL0ZBz7pw6xLSK+s1t9fB qpAH9PZgTPMFkfGHr5Up3SekuCDnFUKZQJ1cG1V4BU3hOtiYiI7nKyHV89Z1aKm1F9yQ RqJTfDM8dXRdDM0nMnldoJ2I7nhG13HdwL3WJ0moO5qwid14hkVrMTg9Sg0P847G/k+G 2wxXDJ48K8DpKGfG++ZGBOLs1lgpoG1zDydtYmgDK5kDxffY28vwkyEplfsxlobW7fMm tMag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2xlbwwijybmfpIoOeqQvSfJsnXXYG0pnuQFRS3i5Di8=; b=aoatj1mJPV4hSG+K74Veuj5mj5S+tkt7ly8DiDjD2h6w70fgvvc8aa/VFmoVGNqezl R8uclNTDIMj90u2j6phXi5jHsGmtQYXC3otPC0EV67W9wOwPjTaIx5GfsEIyLhqwXnLh Bn7VX/1JxYEUzKcimJqT/PQSW6fx7Qf92F/3i1Dk8XPMXse+JbNzkUxzuwG2P9bzILON LAL9ji7f4IbQeX8Htgijhkh76XaC8zVXXiwO81i6/pVe9OBXcgGXhNs8SfaigZZcB2W6 o7pEW6vdHt6hcd+V2H9HdGDlHs5+ovaxU0UDtYp+iD/5PLf8twSF6cBcNi17BpY/lMgB K7bw== X-Gm-Message-State: AHQUAuYbf+DG4BYHCLHSbBMF9ELGzOGDlnPOrswKf86aEqBVrkK4mtMq Pb/dbUdDeLWOkuIMnJim3u0= X-Google-Smtp-Source: AHgI3IYc45yuaMPP82TrW3GrqJBpX0mWHw1G7O/1ADYYK2BKLLNchR7mFd1shXA1wbmYUIw15DyLWA== X-Received: by 2002:adf:a4c9:: with SMTP id h9mr17433095wrb.254.1551213135052; Tue, 26 Feb 2019 12:32:15 -0800 (PST) Received: from ubuntu.home ([2a02:8071:6a3:700:9065:254c:ff38:3288]) by smtp.gmail.com with ESMTPSA id x17sm21467423wrd.95.2019.02.26.12.32.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 12:32:13 -0800 (PST) From: Simon Goldschmidt To: Marek Vasut , u-boot@lists.denx.de Date: Tue, 26 Feb 2019 21:31:52 +0100 Message-Id: <20190226203156.6404-5-simon.k.r.goldschmidt@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190226203156.6404-1-simon.k.r.goldschmidt@gmail.com> References: <20190226203156.6404-1-simon.k.r.goldschmidt@gmail.com> Subject: [U-Boot] [PATCH v3 4/8] reset: socfpga: add reset handling for old kernels X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" This adds code to take peripherals out of reset based on an environment variable. This is in preparation for removing the code that does this from SPL. However, some drivers even in current Linux cannot handle peripheral reset, so until this works, we need a compatibility workaround. This workaround is implemented in the 'assert' and 'remove' callbacks of this reset driver: the 'assert' callback does not disable peripherals that were already taken out of reset, while the 'remove' callback, which is called on OS_PREPARE, deasserts all peripheral resets if the environment variable "socfpga_legacy_reset_compat" is set to 1, which is what the gen5 SPL did up to now. This is in preparation to clean up the SPL and implementing proper reset handling for U-Boot. Signed-off-by: Simon Goldschmidt --- Changes in v3: - fix falcon mode in SPL should work, too - change env var name "socfpga_permodrst_ungate" to "socfpga_legacy_reset_compat" - in compat mode, don't reset peripherals once they are enabled Changes in v2: - moved from Kernel option "OLD_SOCFPGA_KERNEL_COMPAT" to environment variable "socfpga_permodrst_ungate" drivers/reset/reset-socfpga.c | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/reset/reset-socfpga.c b/drivers/reset/reset-socfpga.c index b2acfcd2ec..39d0b9e8f2 100644 --- a/drivers/reset/reset-socfpga.c +++ b/drivers/reset/reset-socfpga.c @@ -27,6 +27,36 @@ struct socfpga_reset_data { void __iomem *membase; }; +/* + * For compatibility with Kernels that don't support peripheral reset, this + * driver can keep the old behaviour of not asserting peripheral reset before + * starting the OS and deasserting all peripheral resets (enabling all + * peripherals). + * + * For that, the reset driver checks the environment variable + * "socfpga_legacy_reset_compat". If this variable is '1', perihperals are not + * reset again once taken out of reset and all peripherals in 'permodrst' are + * taken out of reset before booting into the OS. + * Note that this should be required for gen5 systems only that are running + * Linux kernels without proper peripheral reset support for all drivers used. + */ +static bool socfpga_reset_keep_enabled(void) +{ +#if !defined(CONFIG_SPL_BUILD) || CONFIG_IS_ENABLED(ENV_SUPPORT) + const char *env_str; + long val; + + env_str = env_get("socfpga_legacy_reset_compat"); + if (env_str) { + val = simple_strtol(env_str, NULL, 0); + if (val == 1) + return true; + } +#endif + + return false; +} + static int socfpga_reset_assert(struct reset_ctl *reset_ctl) { struct socfpga_reset_data *data = dev_get_priv(reset_ctl->dev); @@ -89,6 +119,18 @@ static int socfpga_reset_probe(struct udevice *dev) return 0; } +static int socfpga_reset_remove(struct udevice *dev) +{ + struct socfpga_reset_data *data = dev_get_priv(dev); + + if (socfpga_reset_keep_enabled()) { + puts("Deasserting all peripheral resets\n"); + writel(0, data->membase + 4); + } + + return 0; +} + static const struct udevice_id socfpga_reset_match[] = { { .compatible = "altr,rst-mgr" }, { /* sentinel */ }, @@ -101,4 +143,6 @@ U_BOOT_DRIVER(socfpga_reset) = { .probe = socfpga_reset_probe, .priv_auto_alloc_size = sizeof(struct socfpga_reset_data), .ops = &socfpga_reset_ops, + .remove = socfpga_reset_remove, + .flags = DM_FLAG_OS_PREPARE, };