1 From 7069072c10f54de136613947a5b82f504e5f8478 Mon Sep 17 00:00:00 2001
2 From: "maxime@cerno.tech" <maxime@cerno.tech>
3 Date: Thu, 20 Oct 2022 11:12:09 +0200
4 Subject: [PATCH] firmware: raspberrypi: Introduce
5 rpi_firmware_find_node()
7 A significant number of RaspberryPi drivers using the firmware don't
8 have a phandle to it, so end up scanning the device tree to find a node
9 with the firmware compatible.
11 That code is duplicated everywhere, so let's introduce a helper instead.
13 Link: https://lore.kernel.org/r/20220815-rpi-fix-4k-60-v4-1-a1b40526df3e@cerno.tech
14 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
16 drivers/firmware/raspberrypi.c | 18 ++++++++++++------
17 include/soc/bcm2835/raspberrypi-firmware.h | 7 +++++++
18 2 files changed, 19 insertions(+), 6 deletions(-)
20 --- a/drivers/firmware/raspberrypi.c
21 +++ b/drivers/firmware/raspberrypi.c
22 @@ -429,6 +429,18 @@ static int rpi_firmware_remove(struct pl
26 +static const struct of_device_id rpi_firmware_of_match[] = {
27 + { .compatible = "raspberrypi,bcm2835-firmware", },
30 +MODULE_DEVICE_TABLE(of, rpi_firmware_of_match);
32 +struct device_node *rpi_firmware_find_node(void)
34 + return of_find_matching_node(NULL, rpi_firmware_of_match);
36 +EXPORT_SYMBOL_GPL(rpi_firmware_find_node);
39 * rpi_firmware_get - Get pointer to rpi_firmware structure.
40 * @firmware_node: Pointer to the firmware Device Tree node.
41 @@ -484,12 +496,6 @@ struct rpi_firmware *devm_rpi_firmware_g
43 EXPORT_SYMBOL_GPL(devm_rpi_firmware_get);
45 -static const struct of_device_id rpi_firmware_of_match[] = {
46 - { .compatible = "raspberrypi,bcm2835-firmware", },
49 -MODULE_DEVICE_TABLE(of, rpi_firmware_of_match);
51 static struct platform_driver rpi_firmware_driver = {
53 .name = "raspberrypi-firmware",
54 --- a/include/soc/bcm2835/raspberrypi-firmware.h
55 +++ b/include/soc/bcm2835/raspberrypi-firmware.h
56 @@ -168,6 +168,7 @@ int rpi_firmware_property(struct rpi_fir
57 int rpi_firmware_property_list(struct rpi_firmware *fw,
58 void *data, size_t tag_size);
59 void rpi_firmware_put(struct rpi_firmware *fw);
60 +struct device_node *rpi_firmware_find_node(void);
61 struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node);
62 struct rpi_firmware *devm_rpi_firmware_get(struct device *dev,
63 struct device_node *firmware_node);
64 @@ -185,6 +186,12 @@ static inline int rpi_firmware_property_
67 static inline void rpi_firmware_put(struct rpi_firmware *fw) { }
69 +static inline struct device_node *rpi_firmware_find_node(void)
74 static inline struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node)