From patchwork Tue Jun 7 20:42:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 12872364 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 58351C43334 for ; Tue, 7 Jun 2022 20:44:26 +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=ngLv+Bbg1fJ0qAv+2pMPkn/JNmTew6ye9ud6WHHjhfQ=; b=UOFxHMaqD/gU3/ Nna1HMdr9nna1I35d1CFj+HiaD0oPoZbsRZpmu8UjT9v1Ce7gl/NXUUw+UUVcnA0fyiSpXZLlTfQM db1Uwdt+iaDp7og8t/R36Ep8iHcQm3R1drtEGkZn38LyM9aifEOn72H2CqyQF+oLsazW3A+kRGkFZ SmG4FjjrsZTZqwUI5h66N6OtwWOmGznVbpy2qSuqpjVoJ1nkA2k4x3b6C9EasTavgcsr37/6kQXvD H7IClD0T0ILDLddX0wYxr/Oc6G8aPQXTT6gP8IAZijNggHvEJgdDdR6EovWWCmPyIXsp2aUmHoCxC yCXl3SQLosyoD/Q+9zyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nyg2w-009ZuA-QI; Tue, 07 Jun 2022 20:43:26 +0000 Received: from mout.kundenserver.de ([217.72.192.74]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nyg2X-009Zax-QZ for linux-arm-kernel@lists.infradead.org; Tue, 07 Jun 2022 20:43:04 +0000 Received: from localhost.localdomain ([37.4.249.155]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MeC5x-1nNQPR3QkJ-00bK9z; Tue, 07 Jun 2022 22:42:54 +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, Nicolas Saenz Julienne , Stefan Wahren Subject: [PATCH V3 06/11] mfd: bcm2835-pm: Use 'reg-names' to get resources Date: Tue, 7 Jun 2022 22:42:21 +0200 Message-Id: <20220607204226.8703-7-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:cG6fF3HSl3wZfTdJIQrZ3NSavkU6zLTMc+DF7as8181ABXIf328 26k5rYqFUQfdBJVscR2loQHpdwcnqlsf8x/USEycm3kC1UZoOv5j8N0tohhcA3+W9Pzqci3 zZx4n+JyAn8V0VVqBlWpC7KLYmriT5gM9MU8gPcKlXrLr579VMd7U1WBqkl8vviEejDoVC1 SnhLXJapQ4DUBVBG9HMOw== X-UI-Out-Filterresults: notjunk:1;V03:K0:vPnd2XOPMCc=:w5NZEE7QONOlEW8iiUbdSy jwX/weY8plWR32CEYu32DPRdcRiOiYcLU8efhcXfSt4YKaXLLtt23oE5qCBQF6vmBocl7w05M QspjP9b7GyFMPj3Y3P2iXbFoC+p7k72v/Pp2tY9aDSN7gni9EE9uA/kAKxAnwzhKL8pO8BYqp 3lDR3YGil1V2jVia8NCjfv7spm66axanCQ5ApmHwYCzUqPKucbrm5xJtMnnrmaWmkgy6PpTYy c06IZ8B924eFpzQsBzneZNeP7yu/l4HQIwhNxRhGdD72fZ+VLcsZ5Pvr4u+QqR9XxZVWXr+z/ vgbng/7YawuNqYz5KqMnntTy8Ylyy+vgXas5pjj2iyODa1/kQgdvmxF70feRF3LU/JlhzYuZp pfIuXyk91A1O2FnQw8j5l6JIPUE9jS0pXwGLl6IZpcZ3yX0FHN6O0x0ZeBKvVBAyiLm5p1+mr 5p3Hu30o6RelUA2d/FA9CZJLj+PKeVGtNKIG2pUTuAVwjMe7UIaBctx7eOvBYTRDcCdJwdGaA UQeJ7TVAbD298FaItvy/t66coc28Nt8cXcoqyBkE90+WDoz0Ez+33dIEgXYoCyD1WOhjr+8NN VYsjKytqGRuMIQL+CupbttWof5asW+LGGxBV6e25T1rM1uE9b/dyyCw9c6pOkdyYX58nleZDk UbH4tdUXQpQRVBZ6pH0cSj6ZFcpGDmNoWcp1l8JbKjXfJvFTQDRhpWKyefpPlOQLlup3haXJk S4ySMsZGaqmXucnQHV8jjVvNegpJ4k1VOfrjNNvqCr+Tp03y7L2gMQ+MwNo= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220607_134302_200343_1982B6E1 X-CRM114-Status: GOOD ( 16.93 ) 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 From: Nicolas Saenz Julienne If available in firmware, find resources by their 'reg-names' position instead of relying on hardcoded offsets. Care is taken to support old firmware nonetheless. Signed-off-by: Nicolas Saenz Julienne Signed-off-by: Stefan Wahren Reviewed-by: Peter Robinson --- drivers/mfd/bcm2835-pm.c | 59 +++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/drivers/mfd/bcm2835-pm.c b/drivers/mfd/bcm2835-pm.c index 42fe67f1538e..ff0dae5a026d 100644 --- a/drivers/mfd/bcm2835-pm.c +++ b/drivers/mfd/bcm2835-pm.c @@ -25,9 +25,41 @@ static const struct mfd_cell bcm2835_power_devs[] = { { .name = "bcm2835-power" }, }; +static int bcm2835_pm_get_pdata(struct platform_device *pdev, + struct bcm2835_pm *pm) +{ + /* If no 'reg-names' property is found we can assume we're using old + * firmware. + */ + if (!of_find_property(pm->dev->of_node, "reg-names", NULL)) { + dev_warn(pm->dev, "reg-names are missing, please update your DTB.\n"); + + pm->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(pm->base)) + return PTR_ERR(pm->base); + + pm->asb = devm_platform_ioremap_resource(pdev, 1); + } else { + struct resource *res; + + pm->base = devm_platform_ioremap_resource_byname(pdev, "pm"); + if (IS_ERR(pm->base)) + return PTR_ERR(pm->base); + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, + "asb"); + if (res) + pm->asb = devm_ioremap_resource(&pdev->dev, res); + } + + if (IS_ERR(pm->asb)) + pm->asb = NULL; + + return 0; +} + static int bcm2835_pm_probe(struct platform_device *pdev) { - struct resource *res; struct device *dev = &pdev->dev; struct bcm2835_pm *pm; int ret; @@ -39,10 +71,9 @@ static int bcm2835_pm_probe(struct platform_device *pdev) pm->dev = dev; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - pm->base = devm_ioremap_resource(dev, res); - if (IS_ERR(pm->base)) - return PTR_ERR(pm->base); + ret = bcm2835_pm_get_pdata(pdev, pm); + if (ret) + return ret; ret = devm_mfd_add_devices(dev, -1, bcm2835_pm_devs, ARRAY_SIZE(bcm2835_pm_devs), @@ -54,20 +85,10 @@ static int bcm2835_pm_probe(struct platform_device *pdev) * bcm2835-pm binding as the key for whether we can reference * the full PM register range and support power domains. */ - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); - if (res) { - pm->asb = devm_ioremap_resource(dev, res); - if (IS_ERR(pm->asb)) - return PTR_ERR(pm->asb); - - ret = devm_mfd_add_devices(dev, -1, - bcm2835_power_devs, - ARRAY_SIZE(bcm2835_power_devs), - NULL, 0, NULL); - if (ret) - return ret; - } - + if (pm->asb) + return devm_mfd_add_devices(dev, -1, bcm2835_power_devs, + ARRAY_SIZE(bcm2835_power_devs), + NULL, 0, NULL); return 0; }