LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: u.kleine-koenig@pengutronix.de
Cc: f.fainelli@gmail.com, linux-kernel@vger.kernel.org,
	linux-pwm@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com,
	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,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Subject: [PATCH v8 02/11] firmware: raspberrypi: Introduce devm_rpi_firmware_get()
Date: Fri, 12 Mar 2021 13:24:45 +0100	[thread overview]
Message-ID: <20210312122454.24480-3-nsaenzjulienne@suse.de> (raw)
In-Reply-To: <20210312122454.24480-1-nsaenzjulienne@suse.de>

It'll simplify the firmware handling for most consumers.

Suggested-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---

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.30.1


  parent reply	other threads:[~2021-03-12 12:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-12 12:24 [PATCH v8 00/11] Raspberry Pi PoE HAT fan support Nicolas Saenz Julienne
2021-03-12 12:24 ` [PATCH v8 01/11] firmware: raspberrypi: Keep count of all consumers Nicolas Saenz Julienne
2021-03-12 12:24 ` Nicolas Saenz Julienne [this message]
2021-03-12 12:24 ` [PATCH v8 03/11] clk: bcm: rpi: Release firmware handle on unbind Nicolas Saenz Julienne
2021-03-12 12:24 ` [PATCH v8 04/11] gpio: raspberrypi-exp: " Nicolas Saenz Julienne
2021-03-12 12:24 ` [PATCH v8 05/11] reset: raspberrypi: " Nicolas Saenz Julienne
2021-03-12 12:24 ` [PATCH v8 06/11] soc: bcm: raspberrypi-power: " Nicolas Saenz Julienne
2021-03-12 12:24 ` [PATCH v8 07/11] staging: vchiq: " Nicolas Saenz Julienne
2021-03-12 12:24 ` [PATCH v8 08/11] input: raspberrypi-ts: Release firmware handle when not needed Nicolas Saenz Julienne
2021-03-12 12:24 ` [PATCH v8 09/11] dt-bindings: pwm: Add binding for RPi firmware PWM bus Nicolas Saenz Julienne
2021-03-12 12:24 ` [PATCH v8 10/11] DO NOT MERGE: ARM: dts: Add RPi's official PoE hat support Nicolas Saenz Julienne
2021-03-12 12:24 ` [PATCH v8 11/11] pwm: Add Raspberry Pi Firmware based PWM bus Nicolas Saenz Julienne
2021-03-12 20:12   ` Uwe Kleine-König
2021-03-15 16:12     ` Nicolas Saenz Julienne
2021-03-22 11:56   ` Thierry Reding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210312122454.24480-3-nsaenzjulienne@suse.de \
    --to=nsaenzjulienne@suse.de \
    --cc=andy.shevchenko@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=f.fainelli@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=p.zabel@pengutronix.de \
    --cc=sboyd@kernel.org \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=wahrenst@gmx.net \
    --subject='Re: [PATCH v8 02/11] firmware: raspberrypi: Introduce devm_rpi_firmware_get()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).