Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp688234pxb; Wed, 20 Jan 2021 18:37:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJyOqtsCVLW/NM1SwcvGM4fcga+galWTy6cspDcD/pUymurlOhCj8Z0K3aGhDy9hhNm2dZdP X-Received: by 2002:a17:906:2454:: with SMTP id a20mr7750932ejb.203.1611196562777; Wed, 20 Jan 2021 18:36:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611196562; cv=none; d=google.com; s=arc-20160816; b=BkfIHDW5RQ/xTTnYNWS6pbDkteAT2QWjG5qxix9UE4JCCdn+8VhJpnG7O8iG7Acmm4 H/RBr9NDDrB8ZRuQM4D4QDSjU/uVxONGjf0xIjcFzHa+V3bhE95MSiJEl5qc3WQQHgRg IvnlX0lx+n8L3PHqD2oW9u2L1YezUm1NswH003g61y4d3t8llCloSuWtcVB8NQQoVRMT 7zEgcHCV2QIQ2E/YRFoFvZD84Wf7ei5pRZQX3B7yg5LBHmsu9Sm6FvpCes213mBUbqY0 LkNXCRZEkINI/QdPzvAqCq0PGiDJ1yDeXAxjrHcAsD6xdlKqVw6e80Ws+epxS+3XceWv j2KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=g8NzCUdMQMvN88u/fqxqFMGHYAw7U6x8lsT5MGWH9Hc=; b=JrvX3B1tUMbM9spaTLrHfaTGzbZp5or+ShwIGbq0WCKJ4YkW1fOhwJedxhg1Om6eVk ZMd3qPbEWijDw4qALvl/rYuxjZGHdSnObAHx8IJ3jLSeMIUzSgBanCBJgeg9x6wZvXI6 KOpJUXmy3SpUyoLo5MjWxJ3T533enYtDDm5zmzJaOWyKpl2WB+WqT6AxA9UFJFzW+2aI VcQO0qM+ZTLDczX8ehh5pnIITdetNl+gMgpf1cwK2xdNq8Q/oZx8+fzstXkiHdqc5OFX TnRA33TO7iW3Qthmi1N5G7MaEwcvHW9g8bV1xa7kfkLyv72uvgv0/AlT8Xnnk/cduKY8 n0zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@jms.id.au header.s=google header.b=Mmyvs9Ml; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p4si1519466eds.521.2021.01.20.18.35.39; Wed, 20 Jan 2021 18:36:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@jms.id.au header.s=google header.b=Mmyvs9Ml; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732754AbhAUAEw (ORCPT + 99 others); Wed, 20 Jan 2021 19:04:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732597AbhATVrI (ORCPT ); Wed, 20 Jan 2021 16:47:08 -0500 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15F75C061575 for ; Wed, 20 Jan 2021 13:46:28 -0800 (PST) Received: by mail-qk1-x72e.google.com with SMTP id b64so26873089qkc.12 for ; Wed, 20 Jan 2021 13:46:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jms.id.au; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=g8NzCUdMQMvN88u/fqxqFMGHYAw7U6x8lsT5MGWH9Hc=; b=Mmyvs9MlyfnrDINk81HyfAnsbRaFbIBGDIcca4EOSKkbAOJXgUuEVD9DyT5RtUR3TE K0sGViTJkkvPUdy2vtZtp549g8+fypsnJwHYAlUkbCTmpIXjYECA9A4vobKDiZL8GlL8 F9OPFb8gEbQmzW5h8LnjmnZAnjhOU1ND9kroE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=g8NzCUdMQMvN88u/fqxqFMGHYAw7U6x8lsT5MGWH9Hc=; b=XljmeG8DkXkkRV62zjgWbw3kq+1ShDsqADgBjzzo54JvwU40es211kwoTjyFKtbUmb C89lgfPc7QDjFp8rOIUi6KO4v0zJltfjPBOe4q/ZMhWT2IoA/wRTYvh37UArrgvaHd4r meIxsZeSFOTJaBk/XVKDtDm3ILSOfoi3KWEelmleubHt5/Cz+3PqZBYk769I3y2h9rnU yb06C7RTVx3mZ3izJtUQ9hZ6vIES7YDNvdw5WzIXGZdMbsXGH6e+L5D/TMrCpbhlIKhl qfKpDp79e7MWD3eFL6y7jpj6IOQ6fx3Rsf89oe6CIUR5gPK9UhoSBzJOmcEf6EbJVDgK PuYQ== X-Gm-Message-State: AOAM530qJhSSZnwKgrvIRg/Zid61RInUX+TREMxuIrEPqJinXTIreCw6 hKBp9ac4MLn0zwhrlNo8ZqOIq5IQpwn96aG0KPU= X-Received: by 2002:a37:a085:: with SMTP id j127mr11405768qke.273.1611179186264; Wed, 20 Jan 2021 13:46:26 -0800 (PST) MIME-Version: 1.0 References: <20210119080938.1832733-1-geert@linux-m68k.org> In-Reply-To: <20210119080938.1832733-1-geert@linux-m68k.org> From: Joel Stanley Date: Wed, 20 Jan 2021 21:46:13 +0000 Message-ID: Subject: Re: [PATCH v4] drivers/soc/litex: Add restart handler To: Geert Uytterhoeven Cc: Stafford Horne , Karol Gugala , Mateusz Holenko , Gabriel Somlo , linux-riscv@lists.infradead.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 19 Jan 2021 at 08:14, Geert Uytterhoeven wrote: > > Let the LiteX SoC Controller register a restart handler, which resets > the LiteX SoC by writing 1 to CSR_CTRL_RESET_ADDR. > > Signed-off-by: Geert Uytterhoeven Reviewed-by: Joel Stanley > --- > v4: > - Drop bogus "a" from description, > - Get rid of static litex_soc_ctrl_device and litex_reset_nb > instances, > - Unregister handler on driver unbind, > > v3: > - Rebase on top of openrisc/for-next, > > 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 | 42 +++++++++++++++++++++++++++++- > 1 file changed, 41 insertions(+), 1 deletion(-) > > diff --git a/drivers/soc/litex/litex_soc_ctrl.c b/drivers/soc/litex/litex_soc_ctrl.c > index da17ba56b7956c84..a7dd5be9fd5bd8ad 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 > > #define SCRATCH_REG_OFF 0x04 > #define SCRATCH_REG_VALUE 0x12345678 > @@ -66,8 +71,19 @@ static int litex_check_csr_access(void __iomem *reg_addr) > > struct litex_soc_ctrl_device { > void __iomem *base; > + struct notifier_block reset_nb; > }; > > +static int litex_reset_handler(struct notifier_block *this, unsigned long mode, > + void *cmd) > +{ > + struct litex_soc_ctrl_device *soc_ctrl_dev = > + container_of(this, struct litex_soc_ctrl_device, reset_nb); > + > + litex_write32(soc_ctrl_dev->base + RESET_REG_OFF, RESET_REG_VALUE); > + return NOTIFY_DONE; > +} > + > static const struct of_device_id litex_soc_ctrl_of_match[] = { > {.compatible = "litex,soc-controller"}, > {}, > @@ -78,6 +94,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) > @@ -87,7 +104,29 @@ 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; > + > + platform_set_drvdata(pdev, soc_ctrl_dev); > + > + soc_ctrl_dev->reset_nb.notifier_call = litex_reset_handler; > + soc_ctrl_dev->reset_nb.priority = 128; > + error = register_restart_handler(&soc_ctrl_dev->reset_nb); > + if (error) { > + dev_warn(&pdev->dev, "cannot register restart handler: %d\n", > + error); > + } > + > + return 0; > +} > + > +static int litex_soc_ctrl_remove(struct platform_device *pdev) > +{ > + struct litex_soc_ctrl_device *soc_ctrl_dev = platform_get_drvdata(pdev); > + > + unregister_restart_handler(&soc_ctrl_dev->reset_nb); > + return 0; > } > > static struct platform_driver litex_soc_ctrl_driver = { > @@ -96,6 +135,7 @@ static struct platform_driver litex_soc_ctrl_driver = { > .of_match_table = of_match_ptr(litex_soc_ctrl_of_match) > }, > .probe = litex_soc_ctrl_probe, > + .remove = litex_soc_ctrl_remove, > }; > > module_platform_driver(litex_soc_ctrl_driver); > -- > 2.25.1 >