From patchwork Tue Jun 7 20:42:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 12872372 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 CFAA2C433EF for ; Tue, 7 Jun 2022 20:46:33 +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=fKvd/UjFVq/Yod AzOZBqwc/0miXg9DNev0+5ad+AoWgkyB8Hr5gSXqyYrCpaIXaXj0KXQZSSjgrPMzHlflA3gbcSBbI p4sULfqHby4mTP6MXm/va3ixdN/WyQ/uKp5OI792tEEqDmvQgqF2k8FGtXVO4HGzsv15TlD0yFfuD t0SQ1j2wb5QbhW8UYJeojTySDPc1l+GPcj+hB+dWix43aSYLeQmZXD/hhuotfWQRG9pDqlgEAVFdS boIXSDwrcTMPM2ZDEZgQgXaQ0ikS7yvEfL55cPuZsMiPDUdxoblCS5/RbmiMVrQMx1TwDApK/unGe 1GOS5FYV+KSEPQNtyWOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nyg4r-009axC-N8; Tue, 07 Jun 2022 20:45:26 +0000 Received: from mout.kundenserver.de ([217.72.192.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nyg2b-009Zcq-EI for linux-arm-kernel@lists.infradead.org; Tue, 07 Jun 2022 20:43:07 +0000 Received: from localhost.localdomain ([37.4.249.155]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MauJJ-1nMJPg3BQh-00cPYl; Tue, 07 Jun 2022 22:42:55 +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 V3 08/11] soc: bcm: bcm2835-power: Refactor ASB control Date: Tue, 7 Jun 2022 22:42:23 +0200 Message-Id: <20220607204226.8703-9-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220607204226.8703-1-stefan.wahren@i2se.com> References: <20220607204226.8703-1-stefan.wahren@i2se.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:WFPoiHPB+UjDxwBJeyOPFDIsAZ2kFHIp5hl9lhT0C5P23iX8MAL hs3ueGpJWcZvTQvL5Z7lU09ZxQbRpKJ8cyCjk3ugL5KcurH9fqifJyrWeYIKYfAyEiXkFPj cdyVFM2q9qTC5ob6RzyAqEa3cjC9TKtxo8BgXaWT1cIBtzPg0Xj179/nqowi1x2il/X9fm/ oqgL4QjvRsh7yKx1srTww== X-UI-Out-Filterresults: notjunk:1;V03:K0:3PxX7hzxzDY=:2Rxbo+3IaeIwrBEm7e8a84 WwGYUk2bcj0HVIgHRla2bMbFA8ZdmBVTCn+gUMao483mw3xC+KkRSMxV5eXIAhAVzVGLK5jQj qo9AnE8OxtBqUwPFQR9Nvd3olQpSDG6jvB1XK1atq1sMOo0XwF607d07HhjUcSRE4ZDhjVsMl xtXf1GFTC7cvfCbslbCBQOGT9v12sm7M94BKIp8kpfO/lfx0dhOxRHMosDrjNpVVKxjYZEsaJ UvAJLwzHr6WyBGGGMzuAzPFQv3DFLJ2xPOX84WxBqcVZ5jgR+TfNa1CGnBKGAsUJue4dMjoZk GrVa8eRNBUCxu8nrcmeCoAq+yNV77zOBGUdPzrkG3967XnkPQlruTmadE74JoNh8Uvnt517Y9 +09+sF1KdY4FYhUT0NF8xcKqBGYUIVLexH166EBo+7r7aImFEqXSnz4CY4yaEX6sY6w3+kZgU onSO+e3L4qae8Is0QHJJ4ZCXEegWJUdATfcCGuWihzqbgRdcaSNlbzT2mRoMgRBmNSv20qx0t LtbQj7ggncMdUgHeOQHe+015eCYruphbf7j5viJZDc8eO1g8dD1CUQZOci0mNmyxwCRiqkw5C iVJon2qqroKguCI1aI2b3MFVLHdZ1ypmMi30CJxVA+nUe3zZEf/ttfM4LqSI1Q/4RwoKl8+ia kRk/N8AlG5oEl2GNEAic55D0LIDUjGIIa9dViQ1gqA+NjNJlfnmriBKlhAtlzuhDyjtJriSWI UibXpMZAIzORog1R+kF5wZK4lQaQPmni6D8SOLZjrYt3Oe6ILF3OMaX0OmY= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220607_134305_886592_A544CDF3 X-CRM114-Status: GOOD ( 14.66 ) 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 --- 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)