From patchwork Tue Sep 12 02:49:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kwanghoon Son X-Patchwork-Id: 13380567 X-Patchwork-Delegate: mail@conchuod.ie Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9DB4DCA0ECB for ; Tue, 12 Sep 2023 02:49:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:References:MIME-Version:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=psVZ2jNRjydZC9MZS7xcTBsnVrUnHoPXg5gm0CKOrng=; b=KAgGReqLccwVCj EQ6ZaN0ySzDy70n7Go9/kGncn6Jntgh9zPhTOOYQHeoOFoMyhJ9+3fWTp68epsU7yc+IPw08apcsL nPotpHsvJL4wIcoMHXb6mPDs/ypr0Jjl4wJQdUY0R+tMTB7+nN8jCvG1MIEpWKyne9xwtCAnLTNdk 1u+6UONRyhW2/x9/QeDgnt+Bqv4ZLCv2GIRdMIVdhjOT9WJBogCjEQyDc+1nlwz8jGh2JeQDGP2wD sQphuffXHScQ3dPtV3mEN8kv1bMXosuT4yWIP/5uNF4cU/eRJipOC7X7dkRRRD4xyKLyJqZXfKHO8 /mzXe2pfL9NfH5cfK50g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qftT7-001zLM-12; Tue, 12 Sep 2023 02:49:37 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qftSx-001zJ1-28 for linux-riscv@lists.infradead.org; Tue, 12 Sep 2023 02:49:35 +0000 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20230912024919epoutp02649a18eb9d80d79cb48dda28e130c584~EBul09S4Z2435524355epoutp02P for ; Tue, 12 Sep 2023 02:49:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20230912024919epoutp02649a18eb9d80d79cb48dda28e130c584~EBul09S4Z2435524355epoutp02P DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1694486959; bh=jDYZmDUeTmt2O3a/Ef2SDGzOD2Hkcty68MUJtsHU2FY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kgdyA6mbbdnNaf24wjf8rAAh9vyDRXYJfGme1gb2+AMkQl9PPWQlv0QO0TcqjStTk 4+9adBtw0ORVaId2Fv2RkYWSmXwJawasONC3Ck/dTaXnCsAOVnwnaJtS8L/C6xc16L vBxYLn8UmHs+cNfSbSm2CXA/NQZCsnYUsxk7ZLQ4= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20230912024919epcas1p1f7ca91929217cf85eed9ae9da76f319e~EBulT1dF90079800798epcas1p1N; Tue, 12 Sep 2023 02:49:19 +0000 (GMT) Received: from epsmgec1p1-new.samsung.com (unknown [182.195.36.134]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4Rl7Md6QgPz4x9Q1; Tue, 12 Sep 2023 02:49:17 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmgec1p1-new.samsung.com (Symantec Messaging Gateway) with SMTP id 1C.CF.18968.DA1DFF46; Tue, 12 Sep 2023 11:49:17 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230912024917epcas1p26c59f79ab6904823417d625d6a711d36~EBuj65lQh1134811348epcas1p2p; Tue, 12 Sep 2023 02:49:17 +0000 (GMT) Received: from epsmgmc1p1new.samsung.com (unknown [182.195.42.40]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230912024917epsmtrp23542eae371122245bb0958d57aa2d4ff~EBuj6GoCx1886418864epsmtrp2g; Tue, 12 Sep 2023 02:49:17 +0000 (GMT) X-AuditID: b6c32a4c-a9bff70000004a18-7e-64ffd1ad18dc Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgmc1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 63.A7.08649.DA1DFF46; Tue, 12 Sep 2023 11:49:17 +0900 (KST) Received: from mediaserver.. (unknown [10.113.111.131]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230912024917epsmtip153395a4c23ac602aa74f5c5e34d07309~EBujrGCwI0225002250epsmtip1F; Tue, 12 Sep 2023 02:49:17 +0000 (GMT) From: k.son@samsung.com To: p.zabel@pengutronix.de, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, jszhang@kernel.org, guoren@kernel.org, wefu@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, inki.dae@samsung.com Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Kwanghoon Son Subject: [PATCH 2/3] reset: Add th1520 reset driver support Date: Tue, 12 Sep 2023 02:49:13 +0000 Message-Id: <20230912024914.3769440-3-k.son@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912024914.3769440-1-k.son@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrPJsWRmVeS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vc8BY3Wmy3eQN91xf/rSffPXcc5+p0xVMCo35+cTWrIpY+Pru/Zcv 2d9KKJyTWb3W4PH3eIUJIqLftaXMu7q47ygK5r3J8C3b+9Py/KVJVbdOFbJUVu198O25eq6S 0Iad8S1TE59fvvF+JZMzr5SQN7+at8bdbr59LiwhNf/XNYV+nDDn366+84+WPpxYKihlJfNd iaU4I9FQi7moOBEAAIRXDxgDAAA= X-CMS-MailID: 20230912024917epcas1p26c59f79ab6904823417d625d6a711d36 X-Msg-Generator: CA X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230912024917epcas1p26c59f79ab6904823417d625d6a711d36 References: <20230912024914.3769440-1-k.son@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230911_194928_262061_5D5DACAA X-CRM114-Status: GOOD ( 24.28 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Kwanghoon Son This driver supports th1520 T-HEAD SoC reset platform device. Signed-off-by: Kwanghoon Son --- drivers/reset/Kconfig | 10 ++++ drivers/reset/Makefile | 1 + drivers/reset/reset-th1520.c | 109 +++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 drivers/reset/reset-th1520.c diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig index ccd59ddd7610..ec69e6bbba6e 100644 --- a/drivers/reset/Kconfig +++ b/drivers/reset/Kconfig @@ -253,6 +253,16 @@ config RESET_SUNXI help This enables the reset driver for Allwinner SoCs. +config RESET_TH1520 + bool "TH1520 Reset Driver" + depends on (ARCH_THEAD || COMPILE_TEST) && OF + select MFD_SYSCON + default ARCH_THEAD + help + Support for the T-HEAD 1520 RISC-V SoC reset controller. + Say Y if you want to control reset signals provided by this + controller. + config RESET_TI_SCI tristate "TI System Control Interface (TI-SCI) reset driver" depends on TI_SCI_PROTOCOL || (COMPILE_TEST && TI_SCI_PROTOCOL=n) diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile index 8270da8a4baa..5c858e62241a 100644 --- a/drivers/reset/Makefile +++ b/drivers/reset/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_RESET_SIMPLE) += reset-simple.o obj-$(CONFIG_RESET_SOCFPGA) += reset-socfpga.o obj-$(CONFIG_RESET_SUNPLUS) += reset-sunplus.o obj-$(CONFIG_RESET_SUNXI) += reset-sunxi.o +obj-$(CONFIG_RESET_TH1520) += reset-th1520.o obj-$(CONFIG_RESET_TI_SCI) += reset-ti-sci.o obj-$(CONFIG_RESET_TI_SYSCON) += reset-ti-syscon.o obj-$(CONFIG_RESET_TI_TPS380X) += reset-tps380x.o diff --git a/drivers/reset/reset-th1520.c b/drivers/reset/reset-th1520.c new file mode 100644 index 000000000000..4c781377ac23 --- /dev/null +++ b/drivers/reset/reset-th1520.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include + +struct th1520_rst_signal { + unsigned int offset, bit; +}; + +struct th1520_rst { + struct reset_controller_dev rcdev; + struct regmap *regmap; + const struct th1520_rst_signal *signals; +}; + +enum th1520_rst_registers { + RST_WDT0 = 0x0034, + RST_WDT1 = 0x0038, +}; + +static int th1520_reset_update(struct th1520_rst *rst, unsigned long id, + unsigned int value) +{ + const struct th1520_rst_signal *signal = &rst->signals[id]; + + return regmap_update_bits(rst->regmap, signal->offset, signal->bit, + value); +} + +static const struct th1520_rst_signal th1520_rst_signals[] = { + [TH1520_RESET_WDT0] = { RST_WDT0, BIT(0) }, + [TH1520_RESET_WDT1] = { RST_WDT1, BIT(0) }, +}; + +static struct th1520_rst *to_th1520_rst(struct reset_controller_dev *rcdev) +{ + return container_of(rcdev, struct th1520_rst, rcdev); +} + +static int th1520_reset_set(struct reset_controller_dev *rcdev, + unsigned long id, bool assert) +{ + struct th1520_rst *rst = to_th1520_rst(rcdev); + const unsigned int bit = rst->signals[id].bit; + unsigned int value = assert ? bit : 0; + + return th1520_reset_update(rst, id, value); +} + +static int th1520_reset_assert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + return th1520_reset_set(rcdev, id, false); +} + +static int th1520_reset_deassert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + return th1520_reset_set(rcdev, id, true); +} + +static const struct reset_control_ops th1520_rst_ops = { + .assert = th1520_reset_assert, + .deassert = th1520_reset_deassert, +}; + +static int th1520_reset_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct th1520_rst *rst; + struct regmap_config config = { .name = "rst" }; + + rst = devm_kzalloc(dev, sizeof(*rst), GFP_KERNEL); + if (!rst) + return -ENOMEM; + + rst->signals = th1520_rst_signals; + rst->regmap = syscon_node_to_regmap(dev->of_node); + if (IS_ERR(rst->regmap)) + return PTR_ERR(rst->regmap); + + regmap_attach_dev(dev, rst->regmap, &config); + + rst->rcdev.owner = THIS_MODULE; + rst->rcdev.dev = dev; + rst->rcdev.of_node = dev->of_node; + rst->rcdev.ops = &th1520_rst_ops; + rst->rcdev.nr_resets = ARRAY_SIZE(th1520_rst_signals); + + return devm_reset_controller_register(dev, &rst->rcdev); +} + +static const struct of_device_id th1520_reset_dt_ids[] = { + { .compatible = "thead,th1520-reset" }, + { /* sentinel */ }, +}; + +static struct platform_driver th1520_reset_driver = { + .probe = th1520_reset_probe, + .driver = { + .name = "th1520-reset", + .of_match_table = th1520_reset_dt_ids, + }, +}; +builtin_platform_driver(th1520_reset_driver);