Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2361230rwb; Thu, 29 Sep 2022 09:13:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM40I8fAsuG9NVGXyquHR2WmQh3347AgCdXfnYKGmyTUuQqdc5nUduG5rOpbgMMEgZXVy27w X-Received: by 2002:a17:907:7f86:b0:787:7693:7947 with SMTP id qk6-20020a1709077f8600b0078776937947mr3344046ejc.621.1664468018986; Thu, 29 Sep 2022 09:13:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664468018; cv=none; d=google.com; s=arc-20160816; b=o8SwQRUWoOavTICH5L45vHev76jjuuBXs3lpczsE5WvjSr19Og3A7KlgwWRB4BJxpO 6F1GY6TF7uM/Lf9DIfOa/RHMtVw3sJcULS1ymdY6BQYPytsn7/QeU7bUw6Ot6KqVkcNX HRZXWrvsXw2tQ1mX3niq2AbMlwRVUschuGiH8uiPMpAWDNCgnGRbAGjo3qyUw6y4kKF9 h9/axmtfn1LbgtwirRXlbduFZemrEJEo5I8OrpuLlOtMB8pY96AGz72uxLsrlT6fDsqN MM2tpbbHKfPWANpa8mTZZphyPY51/BHgSi+Z4Vxukyaamcm0mPspOuZqsOSMGh66Er3C FnEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:references:in-reply-to:message-id :date:subject:cc:to:from; bh=d1fP5I4exB5f6pBkdk5x6PnFIgusioaxSaH4dbLusiE=; b=uzzcZxJ9bHJxIbZ4W0vlADv5hd8+gH22ZEgA8Z6hhpBOykEw8oWubwvG5gE1L0YmML zvqhJiY4P8dzDJozKogXr5WJkWmCfnKp2zR5vJooODh0w7zpuC71oMfSIlDMiVfQgk99 IbndG2AnayAYhBYKgWsNLsoh+a2t+EsbW/Zj7Svzg3Ua8je8Dmi3maHNXyhU4E/d3wSD +y3iDD4geOWMDFwyALiw2cL4D0ea2LnsCUWpD1AHq2O/4mBdmt1PM97NcWYW9ctO8gED SuB3i7QGQXP5e3gM0YudTdOw0LgZR6uetPQzHXlJSMu/qlwSE2Jve4S1ljwx8uqHgBYT e52Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt13-20020a1709072d8d00b0077bb3c728c5si9701657ejc.20.2022.09.29.09.13.12; Thu, 29 Sep 2022 09:13:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235303AbiI2QIP (ORCPT + 99 others); Thu, 29 Sep 2022 12:08:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236002AbiI2QIL (ORCPT ); Thu, 29 Sep 2022 12:08:11 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.67.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DDDD1D263E; Thu, 29 Sep 2022 09:08:05 -0700 (PDT) X-QQ-Spam: true X-QQ-mid: bizesmtp84t1664461982tyvda2ps Received: from localhost.localdomain ( [113.72.145.157]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Sep 2022 22:33:00 +0800 (CST) X-QQ-SSF: 01000000002000201000B00A0000000 From: Hal Feng To: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-clk@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Marc Zyngier , Philipp Zabel , Stephen Boyd , Michael Turquette , Linus Walleij , Emil Renner Berthing , Hal Feng , linux-kernel@vger.kernel.org Subject: [PATCH v1 08/30] reset: starfive: jh7100: Use regmap APIs to operate registers Date: Thu, 29 Sep 2022 22:32:03 +0800 Message-Id: <20220929143225.17907-9-hal.feng@linux.starfivetech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220929143225.17907-1-hal.feng@linux.starfivetech.com> References: <20220929143225.17907-1-hal.feng@linux.starfivetech.com> X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:linux.starfivetech.com:qybglogicsvr:qybglogicsvr2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reset registers address region is shared with clock controller on the new StarFive JH7110 SoC. Change to use regmap framework to allow base address sharing and preparation for JH7110 reset support. Signed-off-by: Hal Feng --- drivers/reset/reset-starfive-jh7100.c | 61 +++++++++++++++------------ 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/drivers/reset/reset-starfive-jh7100.c b/drivers/reset/reset-starfive-jh7100.c index a6e0945071e9..8cba62348a16 100644 --- a/drivers/reset/reset-starfive-jh7100.c +++ b/drivers/reset/reset-starfive-jh7100.c @@ -3,15 +3,14 @@ * Reset driver for the StarFive JH7100 SoC * * Copyright (C) 2021 Emil Renner Berthing + * Copyright (C) 2021-2022 StarFive Technology Co., Ltd. */ -#include -#include -#include -#include +#include +#include #include +#include #include -#include #include @@ -49,9 +48,7 @@ static const u32 jh7100_reset_asserted[4] = { struct jh7100_reset { struct reset_controller_dev rcdev; - /* protect registers against concurrent read-modify-write */ - spinlock_t lock; - void __iomem *base; + struct regmap *regmap; }; static inline struct jh7100_reset * @@ -64,31 +61,34 @@ static int jh7100_reset_update(struct reset_controller_dev *rcdev, unsigned long id, bool assert) { struct jh7100_reset *data = jh7100_reset_from(rcdev); - unsigned long offset = id / 32; + u32 offset = id / 32; u32 mask = BIT(id % 32); - void __iomem *reg_assert = data->base + JH7100_RESET_ASSERT0 + offset * sizeof(u32); - void __iomem *reg_status = data->base + JH7100_RESET_STATUS0 + offset * sizeof(u32); + u32 reg_assert = JH7100_RESET_ASSERT0 + offset * sizeof(u32); + u32 reg_status = JH7100_RESET_STATUS0 + offset * sizeof(u32); u32 done = jh7100_reset_asserted[offset] & mask; u32 value; - unsigned long flags; int ret; if (!assert) done ^= mask; - spin_lock_irqsave(&data->lock, flags); - - value = readl(reg_assert); if (assert) - value |= mask; + ret = regmap_update_bits(data->regmap, reg_assert, mask, mask); else - value &= ~mask; - writel(value, reg_assert); + ret = regmap_update_bits(data->regmap, reg_assert, mask, 0); + + if (ret) + return ret; /* if the associated clock is gated, deasserting might otherwise hang forever */ - ret = readl_poll_timeout_atomic(reg_status, value, (value & mask) == done, 0, 1000); + ret = regmap_read_poll_timeout_atomic(data->regmap, + reg_status, + value, (value & mask) == done, + 0, 1000); + if (ret) + dev_warn(rcdev->dev, "id:%ld bank:%d, mask:%#x assert:%#x status:%#x ret:%d\n", + id, offset, mask, reg_assert, reg_status, ret); - spin_unlock_irqrestore(&data->lock, flags); return ret; } @@ -120,10 +120,15 @@ static int jh7100_reset_status(struct reset_controller_dev *rcdev, unsigned long id) { struct jh7100_reset *data = jh7100_reset_from(rcdev); - unsigned long offset = id / 32; + u32 offset = id / 32; u32 mask = BIT(id % 32); - void __iomem *reg_status = data->base + JH7100_RESET_STATUS0 + offset * sizeof(u32); - u32 value = readl(reg_status); + u32 reg_status = JH7100_RESET_STATUS0 + offset * sizeof(u32); + u32 value; + int ret; + + ret = regmap_read(data->regmap, reg_status, &value); + if (ret) + return ret; return !((value ^ jh7100_reset_asserted[offset]) & mask); } @@ -143,16 +148,18 @@ static int __init jh7100_reset_probe(struct platform_device *pdev) if (!data) return -ENOMEM; - data->base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(data->base)) - return PTR_ERR(data->base); + data->regmap = device_node_to_regmap(pdev->dev.of_node); + if (IS_ERR(data->regmap)) { + dev_err(&pdev->dev, "failed to get regmap (error %ld)\n", + PTR_ERR(data->regmap)); + return PTR_ERR(data->regmap); + } data->rcdev.ops = &jh7100_reset_ops; data->rcdev.owner = THIS_MODULE; data->rcdev.nr_resets = JH7100_RSTN_END; data->rcdev.dev = &pdev->dev; data->rcdev.of_node = pdev->dev.of_node; - spin_lock_init(&data->lock); return devm_reset_controller_register(&pdev->dev, &data->rcdev); } -- 2.17.1