From patchwork Mon Jan 10 11:49:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Paracuellos X-Patchwork-Id: 12708602 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0AA2C4167B for ; Mon, 10 Jan 2022 11:50:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245175AbiAJLul (ORCPT ); Mon, 10 Jan 2022 06:50:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245093AbiAJLth (ORCPT ); Mon, 10 Jan 2022 06:49:37 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 721EAC06175B; Mon, 10 Jan 2022 03:49:37 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id x4so1061063wru.7; Mon, 10 Jan 2022 03:49:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6RA5/HJJmVlMA5txu/YniwjTRZxIND85s5ggXhBk9yU=; b=hab8/uh0IJZLbdjLdpPTpa7bZzxs6tSzo/t4MddfVwKGrmNwr27pBzkn6oVpkCl1Ae RzWRcGGoDIMi2yvJVkjG0a/zT4bdwPB5CbDJ2UsEMeXM0i8Vayj4oqsbsFHd/aa2o1tJ hADFsem9NxuMBriyOO7ZUZZXfXj0W7MM+8QIciIkK+Y0tFuCjzmDDfWaiz1t6Vlf/Yj7 TBrIyez/Ap6GTDYkVckwWEJ7qIxOsyo0DI/hayg2lpmRVjo3aJFuHDIbCBwIoSijQcvZ CIKKp+3hwR7KgJ5KK1IwpgfobgrJHLR+eWA/f/D0/Nl7GeWwgmc8BkeDhpNZI/dWvJnA aaZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6RA5/HJJmVlMA5txu/YniwjTRZxIND85s5ggXhBk9yU=; b=aher3cxutKIEVQFAHjeCrTu65irSGhOTdpnZaPR7zUb3vLvZaNmKnb8uGr01NVOW7d kDyOgHe9YVd4lzNI7TbtTEcdlx4m75jTBaRHYfwO1SyIQMYJGaZj9jViyeBmEuEBvVCh eJ4fKL1CXxeK90/dCgH5e88za4gH6zDfLyB4QKQI+aylHhjSOkaZQ0Qa+w8nW+udJKrj 02Z8lB5g2UsqItFQtE2aoU+gbGUOmpTo9+ExUDWCpjriSq8EApy9/zPkqYNyVGUTBcK0 tSPNvuoQAr9SBWiBgZqFvXgGRRRZF2pGufFLQeaYuagPtCOYeTBRWwza7ZflKOh/wxoW lBZQ== X-Gm-Message-State: AOAM532/RiTVmUqOg1ReOJ831cg8tYRJHvmRhsCeJCYvxar2shbuARDP dfsVi/sSQmnp+xu6bYWnJmVRVmK9h47Tdw== X-Google-Smtp-Source: ABdhPJw1/pLJqo/haicWXi1EcmsfpsK9GX+kjxiMkCdLXaTAg9GL8dmaFWRwHoNhpuQDCAbyKhp76w== X-Received: by 2002:adf:ebc5:: with SMTP id v5mr64843552wrn.194.1641815375091; Mon, 10 Jan 2022 03:49:35 -0800 (PST) Received: from localhost.localdomain (198.red-81-44-130.dynamicip.rima-tde.net. [81.44.130.198]) by smtp.gmail.com with ESMTPSA id 9sm8090252wrz.90.2022.01.10.03.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jan 2022 03:49:34 -0800 (PST) From: Sergio Paracuellos To: linux-clk@vger.kernel.org Cc: john@phrozen.org, linux-staging@lists.linux.dev, gregkh@linuxfoundation.org, neil@brown.name, p.zabel@pengutronix.de, linux-kernel@vger.kernel.org, sboyd@kernel.org Subject: [PATCH v8 3/4] clk: ralink: make system controller node a reset provider Date: Mon, 10 Jan 2022 12:49:29 +0100 Message-Id: <20220110114930.1406665-4-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220110114930.1406665-1-sergio.paracuellos@gmail.com> References: <20220110114930.1406665-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org MT7621 system controller node is already providing the clocks for the whole system but must also serve as a reset provider. Hence, add reset controller related code to the clock driver itself. To get resets properly ready for the rest of the world we need to move platform driver initialization process to 'arch_initcall'. CC: Philipp Zabel Signed-off-by: Sergio Paracuellos Reviewed-by: Philipp Zabel --- drivers/clk/ralink/clk-mt7621.c | 92 ++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/drivers/clk/ralink/clk-mt7621.c b/drivers/clk/ralink/clk-mt7621.c index a2c045390f00..99256659dd96 100644 --- a/drivers/clk/ralink/clk-mt7621.c +++ b/drivers/clk/ralink/clk-mt7621.c @@ -11,14 +11,17 @@ #include #include #include +#include #include #include +#include /* Configuration registers */ #define SYSC_REG_SYSTEM_CONFIG0 0x10 #define SYSC_REG_SYSTEM_CONFIG1 0x14 #define SYSC_REG_CLKCFG0 0x2c #define SYSC_REG_CLKCFG1 0x30 +#define SYSC_REG_RESET_CTRL 0x34 #define SYSC_REG_CUR_CLK_STS 0x44 #define MEMC_REG_CPU_PLL 0x648 @@ -398,6 +401,82 @@ static void __init mt7621_clk_init(struct device_node *node) } CLK_OF_DECLARE_DRIVER(mt7621_clk, "mediatek,mt7621-sysc", mt7621_clk_init); +struct mt7621_rst { + struct reset_controller_dev rcdev; + struct regmap *sysc; +}; + +static struct mt7621_rst *to_mt7621_rst(struct reset_controller_dev *dev) +{ + return container_of(dev, struct mt7621_rst, rcdev); +} + +static int mt7621_assert_device(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct mt7621_rst *data = to_mt7621_rst(rcdev); + struct regmap *sysc = data->sysc; + + return regmap_update_bits(sysc, SYSC_REG_RESET_CTRL, BIT(id), BIT(id)); +} + +static int mt7621_deassert_device(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct mt7621_rst *data = to_mt7621_rst(rcdev); + struct regmap *sysc = data->sysc; + + return regmap_update_bits(sysc, SYSC_REG_RESET_CTRL, BIT(id), 0); +} + +static int mt7621_reset_device(struct reset_controller_dev *rcdev, + unsigned long id) +{ + int ret; + + ret = mt7621_assert_device(rcdev, id); + if (ret < 0) + return ret; + + return mt7621_deassert_device(rcdev, id); +} + +static int mt7621_rst_xlate(struct reset_controller_dev *rcdev, + const struct of_phandle_args *reset_spec) +{ + unsigned long id = reset_spec->args[0]; + + if (id == MT7621_RST_SYS || id >= rcdev->nr_resets) + return -EINVAL; + + return id; +} + +static const struct reset_control_ops reset_ops = { + .reset = mt7621_reset_device, + .assert = mt7621_assert_device, + .deassert = mt7621_deassert_device +}; + +static int mt7621_reset_init(struct device *dev, struct regmap *sysc) +{ + struct mt7621_rst *rst_data; + + rst_data = devm_kzalloc(dev, sizeof(*rst_data), GFP_KERNEL); + if (!rst_data) + return -ENOMEM; + + rst_data->sysc = sysc; + rst_data->rcdev.ops = &reset_ops; + rst_data->rcdev.owner = THIS_MODULE; + rst_data->rcdev.nr_resets = 32; + rst_data->rcdev.of_reset_n_cells = 1; + rst_data->rcdev.of_xlate = mt7621_rst_xlate; + rst_data->rcdev.of_node = dev_of_node(dev); + + return devm_reset_controller_register(dev, &rst_data->rcdev); +} + static int mt7621_clk_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -424,6 +503,12 @@ static int mt7621_clk_probe(struct platform_device *pdev) return ret; } + ret = mt7621_reset_init(dev, priv->sysc); + if (ret) { + dev_err(dev, "Could not init reset controller\n"); + return ret; + } + count = ARRAY_SIZE(mt7621_clks_base) + ARRAY_SIZE(mt7621_fixed_clks) + ARRAY_SIZE(mt7621_gates); clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, count), @@ -485,4 +570,9 @@ static struct platform_driver mt7621_clk_driver = { .of_match_table = mt7621_clk_of_match, }, }; -builtin_platform_driver(mt7621_clk_driver); + +static int __init mt7621_clk_reset_init(void) +{ + return platform_driver_register(&mt7621_clk_driver); +} +arch_initcall(mt7621_clk_reset_init);