From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76588C433EF for ; Wed, 6 Oct 2021 11:25:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F42961166 for ; Wed, 6 Oct 2021 11:25:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238596AbhJFLZZ (ORCPT ); Wed, 6 Oct 2021 07:25:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238270AbhJFLZE (ORCPT ); Wed, 6 Oct 2021 07:25:04 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AE2EC061749; Wed, 6 Oct 2021 04:23:12 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id r18so7781817wrg.6; Wed, 06 Oct 2021 04:23:12 -0700 (PDT) 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=Nw+gRBKSlBdLJR5JCN9jZoWbWkQnZuEzAoNBrLU9lmY=; b=Ww78qLVzY61h+k6gNMOOU3DRQKzM8hQZlLDGESLtWFcvQgE8ZSoINAuxX0WrsdG9N1 aR14p6vPJf/Fn0UL48+vAS3qfIXEXvGBDjH2WXyfFAJ+7Es0Qk1IcM8ySpjoVtgg2+Ws ayPZkEpeZ/sdDSGatogPb4ZQA1wAqb7GIYYW1kIDKrCjjrsZ3GF5G3p3QNFfaWnc98u5 4rgMQdYL6a4O09J+JexBm1PK8ASFcjrR+nad9FTNPM3/W0xuB2VGSRcWR2eohrWIEFjB spHP6Z+aLVWu+ncNPEGMXVpDS0yNN3qi7QtnChYjaRj4W/9QMxrlF7+4nWkBIjO+Y2Jc KUZg== 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=Nw+gRBKSlBdLJR5JCN9jZoWbWkQnZuEzAoNBrLU9lmY=; b=Ebxy2++ydNibY4T9FL+KVF1BR9oC3Z7SAexeuigqo4RocK7ItYFpPTF1WeCfeU4x7t lftZpPH6UpX9cKjwWlV4VgSUj8vqf6aHFxyl22B9Uy1m5x1D1c79r3eOBd59eXkaZFXv mnZUcxWCqByPrCZdkuWf/tu29Rb365t8l2aGvAU1I59MK/kLO47YnjjbLnP3OQ4oSQSo H8mpNnG1MSIaCRZ3WQRiFOba0y2jcv6g8dgW0G+OhLZU3K18nbmxJIrakoySZFXmF8Py 0Q8eBgncC9zIS5SFk4PZF0ltylL5ajHDjSevYed02GdyErTMVgIoZE3FFXd+jsbQtQt+ +vkQ== X-Gm-Message-State: AOAM530IEBeA2+qURLItcqCiAbtWsxX1lS4M6zaWXUvY8Uj5DpbsNiAR rkrxmF8OrTWA3wGa7OdFgjM= X-Google-Smtp-Source: ABdhPJyYJhfhOzDvyH7laJTeI5RmyTJlxWWlF2G/04PM0PpJLMb9zaJ286MTQc0nux8IxL8UoEUatQ== X-Received: by 2002:a05:600c:4ec6:: with SMTP id g6mr9304916wmq.95.1633519390776; Wed, 06 Oct 2021 04:23:10 -0700 (PDT) Received: from localhost.localdomain (252.red-83-54-181.dynamicip.rima-tde.net. [83.54.181.252]) by smtp.gmail.com with ESMTPSA id e14sm10801985wrw.33.2021.10.06.04.23.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Oct 2021 04:23:10 -0700 (PDT) From: Sergio Paracuellos To: sboyd@kernel.org Cc: linux-clk@vger.kernel.org, gregkh@linuxfoundation.org, devicetree@vger.kernel.org, robh+dt@kernel.org, linux-staging@lists.linux.dev, neil@brown.name, linux-kernel@vger.kernel.org, john@phrozen.org Subject: [PATCH v2 3/4] clk: ralink: make system controller node a reset provider Date: Wed, 6 Oct 2021 13:23:05 +0200 Message-Id: <20211006112306.4691-4-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211006112306.4691-1-sergio.paracuellos@gmail.com> References: <20211006112306.4691-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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. Signed-off-by: Sergio Paracuellos --- drivers/clk/ralink/clk-mt7621.c | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/drivers/clk/ralink/clk-mt7621.c b/drivers/clk/ralink/clk-mt7621.c index a2c045390f00..7a474bb4c877 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,76 @@ 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; + + if (id == MT7621_RST_SYS) + return -EINVAL; + + 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; + + if (id == MT7621_RST_SYS) + return -EINVAL; + + 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 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_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 +497,12 @@ static int mt7621_clk_probe(struct platform_device *pdev) return ret; } + ret = mt7621_reset_init(dev, priv->sysc); + if (ret) { + pr_err("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), -- 2.33.0