From patchwork Sun Feb 13 22:56:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Robinson X-Patchwork-Id: 12744724 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 03C38C433F5 for ; Sun, 13 Feb 2022 23:00:50 +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=DLIk2iindFvlN12CZturW5L+Psj0B9Jh2oV6I3kgKTs=; b=QWJWbYnvYjTIbv 3ZWPhcX75ZQ79T/wWF+vKutjhGiOWXoWvCo0Kn20WxrYp49+wn4TedPFdG/+LNk7B7C7a/18Lbl9U sFv1MQ+bdlScOUynJ6HzMpwCwDP15NI8rFSUWqzDjW41n+ezcumVIf8zqXj3FZYtoPE7RkJclKRh5 +PM7idrgzjiscimh/jiwiLxdL74B5ZfTzaFwE+rFvncdfgaR23m3YzfH5jQdIMsrBPYWfWuk2tIyt y6Ueh3vZkXJFfU19uNvjWGQAUFqwdJ9GCon51BI+lJHK30uc3H1Cpd0PtPEvObbDyZMd1tJFv/AoE Xli/NnrIAa+Zd+hy/nhA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJNps-00Cia0-9X; Sun, 13 Feb 2022 22:59:16 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJNol-00Ci59-AW; Sun, 13 Feb 2022 22:58:08 +0000 Received: by mail-ed1-x533.google.com with SMTP id z21so3342130edb.13; Sun, 13 Feb 2022 14:58:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+88MzjtKS6j33NfAKjT3ZitqU5pJbrVp5tu84yNOBq8=; b=b7REtzY/JvhBJbXT0D8NzJcn4SOWmJeDBABbRL+qh81EYjhvpor1acp5gx6VaWzpBc MA0gXh6UpiLtlnJM7Q2oULI8CXPuW3hDGWweJ7TmlaQAiOdt+NRoAHf6t/qFd1dEKiFh xe8UqM5PBIgHMVgvIa97DfxxQpGC5weN7KD0ExPnP3mKvHkOYYhKVCFNVVajWNI3z6sL GAfJLwGoZPqSPG5EhXXP9l5sDWEZTNgCTom4RJshogG1egcxRL/oYqvmFqV4D5TssDms clPVC7ycCGSjp9BH4tTDTyNUp1z+yEY7c5zaHhJ9EX0TZjFVESXHT/n+1H3oFKKGoRQ4 42tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+88MzjtKS6j33NfAKjT3ZitqU5pJbrVp5tu84yNOBq8=; b=PPIM8bILOEwQCUYHw9Zejw6xm9VEM37NGBPyM/Q19I8gfDuMxBsFWAv9VtXGZe+ok8 hAgMoNmONOPQmBEZcW2FbBLEbxojqzi1mLoK000ydtDof9c7bLYvqKFBBzDLOWUmCvl9 tIXEQ8uLq4pgt4x5vcJSa5LFJggvBtZp6MhkK0befAUu0pVS9OWCqJnkDgPdR17xYdfJ TjAuVIu8dj1VwRyMXiQFTcteaGJsVCCDVt4b7J2uflF1LC27zl0OCLGgnCru/Bm+otTf wrxXAKniEHBXXaF/YeuwZ29a6Mw8/7ys7XSh2yFs8JsB9ljD/i0pfnWX6dbQGt3sCXVV CWWQ== X-Gm-Message-State: AOAM532XhISnkUwKR1IAWotLKtRD1PovWwKdxYMGefqhllAdben+vUV8 +zp9jRkDrCQ8BGIwYst+pAM= X-Google-Smtp-Source: ABdhPJxvbQaHzI63ftYUju86HpJS58ngGCI8VPlF27GSAWqVjn0k5gIlPOm+FppvaTyiik2aOpwk8A== X-Received: by 2002:aa7:da13:: with SMTP id r19mr11509923eds.266.1644793085496; Sun, 13 Feb 2022 14:58:05 -0800 (PST) Received: from morpheus.home.roving-it.com (3.e.2.0.0.0.0.0.0.0.0.0.0.0.0.0.1.8.6.2.1.1.b.f.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:fb11:2681::2e3]) by smtp.googlemail.com with ESMTPSA id g14sm3189163edb.55.2022.02.13.14.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Feb 2022 14:58:05 -0800 (PST) From: Peter Robinson To: Nicolas Saenz Julienne , Rob Herring , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Lee Jones , Emma Anholt , David Airlie , Daniel Vetter , Russell King , Arnd Bergmann , Catalin Marinas , Will Deacon Cc: Nicolas Saenz Julienne , Peter Robinson Subject: [PATCH v4 06/15] mfd: bcm2835-pm: Use 'reg-names' to get resources Date: Sun, 13 Feb 2022 22:56:38 +0000 Message-Id: <20220213225646.67761-7-pbrobinson@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220213225646.67761-1-pbrobinson@gmail.com> References: <20220213225646.67761-1-pbrobinson@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220213_145807_418738_E57A826B X-CRM114-Status: GOOD ( 17.70 ) 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: Peter Robinson --- Changes since v2: - correct names drivers/mfd/bcm2835-pm.c | 55 ++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/drivers/mfd/bcm2835-pm.c b/drivers/mfd/bcm2835-pm.c index 42fe67f1538e..36fede92775c 100644 --- a/drivers/mfd/bcm2835-pm.c +++ b/drivers/mfd/bcm2835-pm.c @@ -25,9 +25,37 @@ 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, "Old devicetree detected, please update your firmware.\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); + if (IS_ERR(pm->asb)) + pm->asb = NULL; + } else { + pm->base = devm_platform_ioremap_resource_byname(pdev, "pm"); + if (IS_ERR(pm->base)) + return PTR_ERR(pm->base); + + pm->asb = devm_platform_ioremap_resource_byname(pdev, "asb"); + if (IS_ERR(pm->base)) + 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 +67,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 +81,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; }