Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1404233pxu; Sat, 12 Dec 2020 11:38:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJzus4GOkYuMEpBSsU6kdfxR1JSmiwuYmIjpN0onk9KlHPUlD+2uUKIqIWGNj9Q52Ao2u8oD X-Received: by 2002:a50:8004:: with SMTP id 4mr3529680eda.329.1607801883360; Sat, 12 Dec 2020 11:38:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607801883; cv=none; d=google.com; s=arc-20160816; b=JuZIWYFnnvOIFf0/1Ux4LwskvU/xMc2Hg8vjz4Nzrc2STp2OhS4oPY1gZ2lUoR4frS c6WKSezU4qBJCQ2M4Tjic+hcoayFMiUvSUvu2nOQjwfY7RueLJCTiRBjDDd/BFu6y4WR EZjoPy4vzHHBbmfxX/dguIjDAUdaLo7mtL+ZHIJY7ZzGYt8Izzv/WnqnZ+Tye22z9jVX FnTSFHU/uBz/tkdjXEGybRuZL8eYpOdXFVh1Ri9OyHpCUpcBBWegXilaJD1Ix/H4lHNS UXnq0fqdkvxWdfVWNUxk1RvtRhBmYsGMGs/nrD+gexg4KdDh1OjUh7SCSyLP9wO8uTDD JxgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=fGysHGQQvacToaduaUBXUFuymlC0nK8SejvojrMbmjE=; b=vaOyFmy3f21Qwd9psrorkh3G2G5kmjR5HiQGxjHmXqiZK8LoelTZLFILJOWyrTZrG7 1Z6ogf1gx+1g5fpX8VR9WHiGuBGTH+t6scouaaVCEGK0WL/BUc2Pi4b1CE9WmhNpTM1f bNyhuHvFTcps1k311Y8508ETMiLmFIuIyS/OEEbCjPtbCXyt34HePPJWyDqDgbjG69s0 rBMEjnfXWvrpokNPS21N/gfKFiQmHnOJEeCRUErQXsNjj5MgiyYeAO4k403EUPkgeVmI 2NDqAjRH4zR+A7ObQIF/nEVFscZwaIP+3sHcwyGx4blexRrtkS7tVLfR51HZW4fRUa8N UFuw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si7113846edb.360.2020.12.12.11.37.40; Sat, 12 Dec 2020 11:38:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390429AbgLKQtv (ORCPT + 99 others); Fri, 11 Dec 2020 11:49:51 -0500 Received: from mx2.suse.de ([195.135.220.15]:34310 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389792AbgLKQsx (ORCPT ); Fri, 11 Dec 2020 11:48:53 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 5FB31B066; Fri, 11 Dec 2020 16:48:10 +0000 (UTC) From: Nicolas Saenz Julienne To: u.kleine-koenig@pengutronix.de, linux-kernel@vger.kernel.org, Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Nicolas Saenz Julienne Cc: linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, wahrenst@gmx.net, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, p.zabel@pengutronix.de, linux-gpio@vger.kernel.org, linus.walleij@linaro.org, linux-clk@vger.kernel.org, sboyd@kernel.org, linux-rpi-kernel@lists.infradead.org, bgolaszewski@baylibre.com, andy.shevchenko@gmail.com Subject: [PATCH v6 02/11] firmware: raspberrypi: Introduce devm_rpi_firmware_get() Date: Fri, 11 Dec 2020 17:47:51 +0100 Message-Id: <20201211164801.7838-3-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201211164801.7838-1-nsaenzjulienne@suse.de> References: <20201211164801.7838-1-nsaenzjulienne@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It'll simplify the firmware handling for most consumers. Suggested-by: Bartosz Golaszewski Signed-off-by: Nicolas Saenz Julienne Reviewed-by: Florian Fainelli --- Changes since v4: - Rearrange function calls for clarity, same functionality Changes since v2: - Create devm_rpi_firmware_get() drivers/firmware/raspberrypi.c | 29 ++++++++++++++++++++++ include/soc/bcm2835/raspberrypi-firmware.h | 8 ++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c index b65e4c495772..250e01680742 100644 --- a/drivers/firmware/raspberrypi.c +++ b/drivers/firmware/raspberrypi.c @@ -243,6 +243,13 @@ void rpi_firmware_put(struct rpi_firmware *fw) } EXPORT_SYMBOL_GPL(rpi_firmware_put); +static void devm_rpi_firmware_put(void *data) +{ + struct rpi_firmware *fw = data; + + rpi_firmware_put(fw); +} + static int rpi_firmware_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -331,6 +338,28 @@ struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node) } EXPORT_SYMBOL_GPL(rpi_firmware_get); +/** + * devm_rpi_firmware_get - Get pointer to rpi_firmware structure. + * @firmware_node: Pointer to the firmware Device Tree node. + * + * Returns NULL is the firmware device is not ready. + */ +struct rpi_firmware *devm_rpi_firmware_get(struct device *dev, + struct device_node *firmware_node) +{ + struct rpi_firmware *fw; + + fw = rpi_firmware_get(firmware_node); + if (!fw) + return NULL; + + if (devm_add_action_or_reset(dev, devm_rpi_firmware_put, fw)) + return NULL; + + return fw; +} +EXPORT_SYMBOL_GPL(devm_rpi_firmware_get); + static const struct of_device_id rpi_firmware_of_match[] = { { .compatible = "raspberrypi,bcm2835-firmware", }, {}, diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h index fdfef7fe40df..73ad784fca96 100644 --- a/include/soc/bcm2835/raspberrypi-firmware.h +++ b/include/soc/bcm2835/raspberrypi-firmware.h @@ -142,6 +142,8 @@ int rpi_firmware_property_list(struct rpi_firmware *fw, void *data, size_t tag_size); void rpi_firmware_put(struct rpi_firmware *fw); struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node); +struct rpi_firmware *devm_rpi_firmware_get(struct device *dev, + struct device_node *firmware_node); #else static inline int rpi_firmware_property(struct rpi_firmware *fw, u32 tag, void *data, size_t len) @@ -160,6 +162,12 @@ static inline struct rpi_firmware *rpi_firmware_get(struct device_node *firmware { return NULL; } + +static inline struct rpi_firmware *devm_rpi_firmware_get(struct device *dev, + struct device_node *firmware_node) +{ + return NULL; +} #endif #endif /* __SOC_RASPBERRY_FIRMWARE_H__ */ -- 2.29.2