From patchwork Sat Jun 25 11:36:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 12895334 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 3FCD6C43334 for ; Sat, 25 Jun 2022 11:38:51 +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:MIME-Version:References: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=mun4OQyMX2K/LO2l1JXpHs1Vh9x50coBiAp3ff/4u44=; b=JO8+UQf1OpnAPX 4re9ybExRjGaH3QaYO89dVoR3atlYr5Rgzitt/4rTUEmP5p5staZlcr66pbz5csX93B4a1ESeddN3 t41eMfYau/ZQqH6FfNh79itbIPD1ZrlP0WyGGUJnKBIBUbuZvC7m6c2RNweorCdBI6QlIecJrtTGB p/VpoK8c8vjyvLR/mtJUXqMAZWKFmaSj0OlwIgKT+AgmtZjkclEllThejIdRgngkgGJukwIddYv+L OvGudHNxPDivsp5uyVbkegpTf2xt52bqZ5rsn4o1BohVHelnEhvieOE+ZzySv7pMykZzXHd0edtXV Q/ws/R5OfcaHAl/s3K7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o546n-005mks-M5; Sat, 25 Jun 2022 11:37:49 +0000 Received: from mout.kundenserver.de ([212.227.17.10]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o546A-005mZ0-Pt for linux-arm-kernel@lists.infradead.org; Sat, 25 Jun 2022 11:37:13 +0000 Received: from localhost.localdomain ([37.4.249.155]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N8XDT-1naHdB2HRp-014Q3j; Sat, 25 Jun 2022 13:37:04 +0200 From: Stefan Wahren To: Florian Fainelli , Ray Jui , Scott Branden , Lee Jones Cc: Peter Robinson , Melissa Wen , Phil Elwell , bcm-kernel-feedback-list@broadcom.com, Maxime Ripard , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Stefan Wahren Subject: [PATCH V4 08/11] soc: bcm: bcm2835-power: Refactor ASB control Date: Sat, 25 Jun 2022 13:36:16 +0200 Message-Id: <20220625113619.15944-9-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220625113619.15944-1-stefan.wahren@i2se.com> References: <20220625113619.15944-1-stefan.wahren@i2se.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:AQyuJ6BWAMS7izam3rfsN3EezkqlAy92xousHG1PtVIeKYqyY7u RIR9wN5UaeeQMb9/mq1P3lU012jDucCarYPA6qgdur5ZJ3ZqHoxpz2fEbzwxbMVbERG9LAD kB0wGWkxYlkHlxq8eBwTp6VOHqIwN3gdLOt9beS1YcFlSdPUd+v6aX7gTKovjZATVT2Dham Kjo3RUgFNJZdKioC1RigA== X-UI-Out-Filterresults: notjunk:1;V03:K0:dUze6tolySQ=:U8PQGkgT9Hw8WUHhlPNETh R5vsr+Ipoo7/OR3QQAyLpCoIfIhrooybsW2dCRlau2/UHa5mLNIQaE6HGdOQ50d6yAEq4llDG WvdwERA4nWFfwbmfs8DQmNv+vIrJwJqNUTfFMh38K/lOFoXQwlN3qDMPpkvomEBb02+iPmCtJ RdRG6znpu3Up3X0W3RoEvF3QFOU3kjon22nQDmsZtdtOdrMV3Ui0ACb5CmHcPU07q5i2k7CX7 PTcg3SkRDN/XsZ5QLyD0ElvEJe89N3PaCUnTOmYO709OASbIOSzcBEKAJFj7zj9mp2mZesRw8 IV9tgpucpX4KDJ9uXsGjc76RkEi0ws141tkV0drcsUyPT0wr6iz+iMVEKancBGqwHhxyf8Q6x F8mPrOXcsk/COp+ba5uL/rqlE3H3b9KD398N40j4I5/JZiBxFM6WsPAIs32Lmw+ry5JFhKD6n ZqXA1Lggddd2bi5tCtYFOjj2Z76tw0tijrJUeTNcuCCFFWUgT3tEp9W9opn5gZE7ziqDVP48N Atbuh90Yp5pFNb8eNUNyJayBSeCzlvYTLL2kj2DtjBXBHsYdcVE/ktetQ/CwLOXehPOp907qY afVB7QeqAaFDBrBzTET0L0CrWhLxtS9Glp4cxitCISs+rtB95sUCqHKgzFN2R6LWX6zEIXvs0 Zb3WMeWDiIVAE34P/DtPzgn4r04FHQPP7sps2pB2gfgu4Y3gv8DmSmmJoQcVZNQ+aQ18IyFMf Pe8LPYQOZD0UAiREtJbIf8iG/2C3KW7bqHHhfHpeCoEFVPVeZFVc/xj4Htw= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220625_043711_182453_029BCC37 X-CRM114-Status: GOOD ( 13.80 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The functions to control the async AXI bridges are almost identical. So define a general function to handle it and keep the original ones as wrapper. This should make this driver easier to extend. Signed-off-by: Stefan Wahren Reviewed-by: Peter Robinson Acked-by: Florian Fainelli --- drivers/soc/bcm/bcm2835-power.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/drivers/soc/bcm/bcm2835-power.c b/drivers/soc/bcm/bcm2835-power.c index 1e0041ec8132..77dc9e62b207 100644 --- a/drivers/soc/bcm/bcm2835-power.c +++ b/drivers/soc/bcm/bcm2835-power.c @@ -148,7 +148,7 @@ struct bcm2835_power { struct reset_controller_dev reset; }; -static int bcm2835_asb_enable(struct bcm2835_power *power, u32 reg) +static int bcm2835_asb_control(struct bcm2835_power *power, u32 reg, bool enable) { u64 start; @@ -158,7 +158,12 @@ static int bcm2835_asb_enable(struct bcm2835_power *power, u32 reg) start = ktime_get_ns(); /* Enable the module's async AXI bridges. */ - ASB_WRITE(reg, ASB_READ(reg) & ~ASB_REQ_STOP); + if (enable) { + ASB_WRITE(reg, ASB_READ(reg) & ~ASB_REQ_STOP); + } else { + ASB_WRITE(reg, ASB_READ(reg) | ASB_REQ_STOP); + } + while (ASB_READ(reg) & ASB_ACK) { cpu_relax(); if (ktime_get_ns() - start >= 1000) @@ -168,24 +173,14 @@ static int bcm2835_asb_enable(struct bcm2835_power *power, u32 reg) return 0; } -static int bcm2835_asb_disable(struct bcm2835_power *power, u32 reg) +static int bcm2835_asb_enable(struct bcm2835_power *power, u32 reg) { - u64 start; - - if (!reg) - return 0; - - start = ktime_get_ns(); - - /* Enable the module's async AXI bridges. */ - ASB_WRITE(reg, ASB_READ(reg) | ASB_REQ_STOP); - while (!(ASB_READ(reg) & ASB_ACK)) { - cpu_relax(); - if (ktime_get_ns() - start >= 1000) - return -ETIMEDOUT; - } + return bcm2835_asb_control(power, reg, true); +} - return 0; +static int bcm2835_asb_disable(struct bcm2835_power *power, u32 reg) +{ + return bcm2835_asb_control(power, reg, false); } static int bcm2835_power_power_off(struct bcm2835_power_domain *pd, u32 pm_reg)