From patchwork Wed Jun 1 12:53:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 12866891 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 56908C433EF for ; Wed, 1 Jun 2022 12:57:13 +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=pCPrVirAJj0cMIyZWkcKQ/b0TpnOAtpVF72um7vJuI4=; b=GcJczv0gVl95ln ufiAU70HXJqc2Ax2PcTqB6hJIBg/MR0X+oyrwUO9hs6/SJYCavCN0G8FBvBQVBHNcqiVOZlgdoF6S j5FD1v5ngwczIXUcFRamma8PQiudVHRS1p+FZhJZqwhgSKLtah7Lb2uHftyLOgYZTCfCCD7iXq9KL GbzcGfSl1vO7cMbQNdsJkJhrabaIfxWjGl0XlEY8mvD1O7rDEGzNPBleOsZiwy6SUNPwu2sxYGmFy NxivE0qLXbPXBmPFJBZiGXE7eHu/a5kfVaLfzUkaQs91/BmaXnxCkUz/slEV48fO0bFLfpbAG+zQd hs7CIAOpTdCmJtf/AH4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nwNtC-00G8EI-EC; Wed, 01 Jun 2022 12:55:54 +0000 Received: from mout.kundenserver.de ([217.72.192.73]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nwNrZ-00G7Xv-VR; Wed, 01 Jun 2022 12:54:17 +0000 Received: from localhost.localdomain ([37.4.249.170]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N8XLj-1nixbe314D-014ULV; Wed, 01 Jun 2022 14:54:03 +0200 From: Stefan Wahren To: Florian Fainelli , Ray Jui , Scott Branden , Nicolas Saenz Julienne , Lee Jones Cc: Peter Robinson , Melissa Wen , Phil Elwell , bcm-kernel-feedback-list@broadcom.com, Maxime Ripard , devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Nicolas Saenz Julienne , Stefan Wahren Subject: [PATCH V2 06/11] mfd: bcm2835-pm: Use 'reg-names' to get resources Date: Wed, 1 Jun 2022 14:53:39 +0200 Message-Id: <20220601125344.60602-7-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601125344.60602-1-stefan.wahren@i2se.com> References: <20220601125344.60602-1-stefan.wahren@i2se.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:KRIALsDrTjSa+6xmrcLvnKCepvkokoF2ewcSsTHi1pIqsHCzucn /gqn6GxvXN5JyhD+rUR7k5CKXp7LTqriSCHXopR297+BQ01F4xHjYT1d3QVUh3J+6SNqH30 jLSOAvtWgzSpJRO6HUiW8W8W26d1aSCydazBxlHem+Eu5qhsZrc26sdhAWJ1TWFSkyohlx0 rrsn6WgWswrCFIvbZDvLQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:lFQyxgRSU2Y=:kPPRWky3gL/f6rWgRiosNQ bWm9fHyelePdomYcnX5LuVIuFcDE/5Sk9M67NXYKJY6p/OU7+EKVvU8SSndCeylgzXJvmChKl e48lRoAyl/LGTykwNYpIEf4q9BHN8C9/hrtyItLiWEhQ8PAlXf89wAk8g0P3ibg7hYySEELkt 8pfUy97kZQfbA6z2RbQZezSYTblXyBEpF9tSczSxLr7hEKy7/tgAdRnwaL/m0w4DvlH6wRx5j MLWxB0B/9d5fDgJGSfhul9PDKG1Yds9sz/IEjpEgc1mBc+jr65YS5EuaAZA4ggzTMcgSKlZ5u SaFGtZ0ex4p39IMN/Dd80GERwsA/xNsmddV3QNFBXsKCGUXuQx4i4aQChr6dSNu9mcRk8zRG5 TSL8aCUVBtVNRRGuhFCB2Pymm/AftFHVxi+pEzpGBY7QCyuo+/V80+2SAXMQ1TaAzgqIxL2YV ygB/0fqbJq4UeXrRDMHrI8bJ6lEaItyjfKwLqkDFNxzgg8RzjDN4MVIxeucdKynP/ybxaffeP bUMkEDj25nmOCVY0u+z2zXC2cI3ImDcXO3f5YeSzIMTggLNd1e1loBVyh2bFqvIV3tJR8DyvX jJ6z5E6pXw1nP1C/HgliCFqmCmfal01PFblW20gzueOHc1wL5D/Y5VSSOxurmqisgLJ+f3wxH iPPTiy3KdI8YC0go1qc4Zof+Y26eeLM6ENaDbbyTJn8yb5xib0e7CtRrfTE+YR5Ndrt9jCCEw ah0tvMmPoUs0YmMKRZ+sb5uG01hEWWqMWGEXdZ4/Zaz83N0PMzz1j1khhYY= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220601_055414_414217_60C2979B X-CRM114-Status: GOOD ( 16.77 ) 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..c1e81a4541d7 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; }