From patchwork Mon Jan 4 16:45:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 11997051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E728C433DB for ; Mon, 4 Jan 2021 16:45:22 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9CCA3207BC for ; Mon, 4 Jan 2021 16:45:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9CCA3207BC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=lSaAtND5PdwkOaRZaOoSeW2uE3MrxE4RwYqNv7gocTc=; b=i+iWa7hfOEDBdL97UexllJ2f51 Z4YoJRPyMympm+PEZ7Wh/ve2SJcJNnJ6TCMIUVQGnpwF4P+OaRB61ZjolQB6wWbeO1ET7TNG8ZHbp buxkF+mmyyMru3vhlqP3zt27pjEtC5rhnMGRYc+qRbe6uGJUHAKM/i2hfpRs4eq6lahZeww8HST5L S3bIceDbzc/zdzCaE6knWEUtwVlSfIyahxbEkrgAvFI/RCJ9cE9Hp8jo8aJ2IFJYq/tK3t7cwfz58 lAivJ3GTXqRr/BJ/kmEikXSQDCh4VZbuwI6Ls5YmVNfTqJbp3Gv5QDf5XbsSx9jc65TKLTy+fqkQS U0a3ETFQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kwSym-0003n0-P5; Mon, 04 Jan 2021 16:45:12 +0000 Received: from baptiste.telenet-ops.be ([2a02:1800:120:4::f00:13]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kwSyk-0003lm-2g for linux-riscv@lists.infradead.org; Mon, 04 Jan 2021 16:45:11 +0000 Received: from ramsan.of.borg ([84.195.186.194]) by baptiste.telenet-ops.be with bizsmtp id Cgl32400H4C55Sk01gl3d3; Mon, 04 Jan 2021 17:45:03 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kwSyc-001AP6-Th; Mon, 04 Jan 2021 17:45:02 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1kwSyc-005V5O-BI; Mon, 04 Jan 2021 17:45:02 +0100 From: Geert Uytterhoeven To: Karol Gugala , Mateusz Holenko Subject: [PATCH v2] drivers/soc/litex: Add restart handler Date: Mon, 4 Jan 2021 17:45:00 +0100 Message-Id: <20210104164500.1311091-1-geert@linux-m68k.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210104_114510_255489_C6346DAD X-CRM114-Status: GOOD ( 15.67 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gabriel Somlo , Geert Uytterhoeven , Stafford Horne , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Let the LiteX SoC Controller a register a restart handler, which resets the LiteX SoC by writing 1 to CSR_CTRL_RESET_ADDR. Signed-off-by: Geert Uytterhoeven --- Tested with linux-on-litex-vexriscv. This patch is based on upstream, i.e. not on top of Gabriel Somlo's "[PATCH v5 0/4] drivers/soc/litex: support 32-bit subregisters, 64-bit CPUs" (https://lore.kernel.org/lkml/20201227161320.2194830-1-gsomlo@gmail.com/) v2: - Rebase on top of v5.11-rc1, - Change reset handler priority to recommended default value of 128 (was 192). (v1 was not sent to a mailing list) --- drivers/soc/litex/litex_soc_ctrl.c | 33 +++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/drivers/soc/litex/litex_soc_ctrl.c b/drivers/soc/litex/litex_soc_ctrl.c index 1217cafdfd4d1d2b..d729ad50d4ffca5e 100644 --- a/drivers/soc/litex/litex_soc_ctrl.c +++ b/drivers/soc/litex/litex_soc_ctrl.c @@ -15,6 +15,11 @@ #include #include #include +#include + +/* reset register located at the base address */ +#define RESET_REG_OFF 0x00 +#define RESET_REG_VALUE 0x00000001 /* * LiteX SoC Generator, depending on the configuration, can split a single @@ -136,8 +141,20 @@ static int litex_check_csr_access(void __iomem *reg_addr) return 0; } -struct litex_soc_ctrl_device { +static struct litex_soc_ctrl_device { void __iomem *base; +} *soc_ctrl_dev; + +static int litex_reset_handler(struct notifier_block *this, unsigned long mode, + void *cmd) +{ + litex_write32(soc_ctrl_dev->base + RESET_REG_OFF, RESET_REG_VALUE); + return NOTIFY_DONE; +} + +static struct notifier_block litex_reset_nb = { + .notifier_call = litex_reset_handler, + .priority = 128, }; static const struct of_device_id litex_soc_ctrl_of_match[] = { @@ -149,7 +166,7 @@ MODULE_DEVICE_TABLE(of, litex_soc_ctrl_of_match); static int litex_soc_ctrl_probe(struct platform_device *pdev) { - struct litex_soc_ctrl_device *soc_ctrl_dev; + int error; soc_ctrl_dev = devm_kzalloc(&pdev->dev, sizeof(*soc_ctrl_dev), GFP_KERNEL); if (!soc_ctrl_dev) @@ -159,7 +176,17 @@ static int litex_soc_ctrl_probe(struct platform_device *pdev) if (IS_ERR(soc_ctrl_dev->base)) return PTR_ERR(soc_ctrl_dev->base); - return litex_check_csr_access(soc_ctrl_dev->base); + error = litex_check_csr_access(soc_ctrl_dev->base); + if (error) + return error; + + error = register_restart_handler(&litex_reset_nb); + if (error) { + dev_warn(&pdev->dev, "cannot register restart handler: %d\n", + error); + } + + return 0; } static struct platform_driver litex_soc_ctrl_driver = {