From patchwork Sat Jun 25 11:36:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 12895339 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 EF27CC43334 for ; Sat, 25 Jun 2022 11:40:35 +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=UOjs7ff6SKXzRQEjAFpHmsn/VvRyAgCxZFeIjSB1lp8=; b=JRteck5t2ybPau 4TA3B2/eQfr7rCqR+kwuDMDnBPKxyyUXUZ4fJrXkN9KH1HRNKec0hn8eCTcdp+Fswa458FiSou729 GubeNVzQj7IVDQtYf/zHfQMhrnmghnESYjzZLYpNCUKGZy6+Y8hj1+6euU4JBi6s1nWj7omOfOo76 JuFyfYmw6nA1BHveyEsb4aKJBmdUJatQRf51qZ/nIgTjCg5N+cw+mq2gc82FhJdiS/Hb8Xm5gnax4 RwDdosJhb8FqILj7eqik6n5Fh/gFcM0ZCn8s0n7GRfbkYzYbA2vBiC63uB05rfwRH84Va6ffm0saU B1PoIc0jZ19ZuytGnRxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o548Q-005nY3-EZ; Sat, 25 Jun 2022 11:39:30 +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 1o546B-005mZ2-0K for linux-arm-kernel@lists.infradead.org; Sat, 25 Jun 2022 11:37:15 +0000 Received: from localhost.localdomain ([37.4.249.155]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MN4ux-1oLm022tlN-00J2bb; Sat, 25 Jun 2022 13:37:03 +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 V4 06/11] mfd: bcm2835-pm: Use 'reg-names' to get resources Date: Sat, 25 Jun 2022 13:36:14 +0200 Message-Id: <20220625113619.15944-7-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:Ugnti44o7yL+JwvplNxLQ411MRmMUBvCV+ZWKFIrGgVUrwju5NF 1LYHQTAgCgY05WAEvaUEwu0gieCM8CKrAr85QOe32CINg8B1eetZRSO2mtXr4flbHktgJe0 1osFZHOAqkfb5B47JfPmnxfkuGeLlA489VUxAHc4hA5B7vnjdLlVH0br3z+N7R6UfTaFUBy MBlVPyBs603vCHNM95tvQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:dJnlFu0L3U0=:ukHMvfuynzxy+kApSIYOtT LAThcdySVM1zkbhRf9NCuRHvou3f1KzubMJ0qxefYBGGOsnn5nfjEpWgIjXLQO16Yimo8ByZf rAW3xeHJB6Jc3egCFIV9B7aHLjD6o948THWWGpD7pV5/3dk780AAdF8AYhbktQHyPu1KDiFv0 +6uCqwq0/2LtL4rz6hssR9NddmzJMGmAffkX4URgcZk9+p89vKi73rmdL9cIQXLIkLYja3uBi iJyAwioQ9jDlDbMSszvdAW5A8KpbO0y65hxRuA5o10DPHLEIAK/7d1AQy+NuYlKvyqm3sjCBt BI0hMvXRh8vYU8BNympa/XXbSPOhV9B5JFnh+1cdDoUBL4A7To7a5KCjkz7oR1JpbSsKhXsLd LtnKDK6XTTcbFkMJe7BfRVzeffBcwL3IpU/SA8vtO748heMnaQqkJAAGbJ2GnzDwd3mfEEkfn 93/vGLTc5BH8k4Mo8HpJQsdcXbTDD1K8+CL+ouNHCTLKSk0YriLKzMUt2okHIvBm8FUjVH7FM oeMoodA+w2L5m631w9dNI0+wT+XGwSh4ta6gg5MofGbtMjl8Cp0cZH3L1Gi8aCv5m6TH9IAcm sNtnRjaQrQIRiiO3tmFhb85AeS8GJ4hKXHW6OGNiThwaoBi0nynLaTrdfBZMQQyn2X6opzUB6 i9d4xr8UQYJBvmD0hOIR4c+iM0yft9bWsgWsf9nyzmLws31MB3J3xhh3wMNmIDPJ1KC+GgBNg bddJgmYOhfzyrAOnULbGlB/a6mRbfOF63ALoPnJEyY3f0o6+M15ZsjhU27Y= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220625_043711_403741_2570E369 X-CRM114-Status: GOOD ( 17.21 ) 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 Acked-by: Florian Fainelli --- drivers/mfd/bcm2835-pm.c | 61 +++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/drivers/mfd/bcm2835-pm.c b/drivers/mfd/bcm2835-pm.c index 42fe67f1538e..418c8a16427d 100644 --- a/drivers/mfd/bcm2835-pm.c +++ b/drivers/mfd/bcm2835-pm.c @@ -25,9 +25,40 @@ 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 (of_find_property(pm->dev->of_node, "reg-names", NULL)) { + 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; + } + + /* If no 'reg-names' property is found we can assume we're using old DTB. */ + 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); + 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 +70,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), @@ -50,24 +80,15 @@ static int bcm2835_pm_probe(struct platform_device *pdev) if (ret) return ret; - /* We'll use the presence of the AXI ASB regs in the + /* + * We'll use the presence of the AXI ASB regs in the * 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; }