Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp254614pxb; Wed, 6 Oct 2021 04:26:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzt4iT0zY5jx6hixhE4XLcttIRnYJJlVBYNO9LmHZw4QAdTm9I8QpWgJeIQ9xv0Oz9Knxrf X-Received: by 2002:a17:90a:1a58:: with SMTP id 24mr10400892pjl.45.1633519568279; Wed, 06 Oct 2021 04:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633519568; cv=none; d=google.com; s=arc-20160816; b=VFzdONBpUsgXM8D9hYTuqpEm4JG+mgWXO/zlMGNn+FIxmdlak+nu/EkU/N5iuxj6Ty +L3rs92DhvbRpyNX2G+fQyd+HEvzSU4Adeco3/5wPZZf+dtEv9Um9WhKv/lWPLXlY+uU 17ynXDuQ050vYVuZ5o4L67COZAdF6wGMeSrbkvh9XeMzkaKqPlqWi3QgAbzjvy+KMF+m FDh8LwBDzoBtJE4D8dnd72bJLnSpr1NYtSyqYRk/o715YVJoU5NwTqTL0yGnlFqoyLfi cwu6jCRaO0Gyrz2023OSskA9Vh6nErWrgvhykp09VzSmnyGxoEJ/vcMXU/Tr6G6MYDh9 83vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Nw+gRBKSlBdLJR5JCN9jZoWbWkQnZuEzAoNBrLU9lmY=; b=jj9hh4gTjkeVPgF1xTnbdmrQp1GIc4+a5rP44tQl+U7R4VHqHe3DBHtpJwPdJqkc8z 8daV8+xtA4tCw/oNvV6kb8LfKpBA4Or66CiIkg/yd7u+skudBbNXKz8hGzsQ1ZDNIsgX AoUgYK+iD30T17uJ6yOW0FJgtjUcqJLl+AeFKgD5X4EzsNr9ndoT9eaJrkcW2CHbRDcd gSo14Z2s1s1OYZFUT2ul1jR4AySMqujbN4NTIgy6+lIkgxXzK7N79ElEXgLUcVnPUWF1 bLTuatGe4cYSJ0neXIRYqTqjDcm7vRRfUIiAm8Vqaevu7VeeDoo8m+GBM4OURyuIu8Ow 4dtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ww78qLVz; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z15si5626367pgu.381.2021.10.06.04.25.55; Wed, 06 Oct 2021 04:26:08 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b=Ww78qLVz; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238548AbhJFLZX (ORCPT + 99 others); Wed, 6 Oct 2021 07:25:23 -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-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