diff mbox series

[v3,1/7] firmware: raspberrypi: Introduce rpi_firmware_find_node()

Message ID 20220815-rpi-fix-4k-60-v3-1-fc56729d11fe@cerno.tech (mailing list archive)
State New, archived
Headers show
Series drm/vc4: Fix the core clock behaviour | expand

Commit Message

Maxime Ripard Oct. 13, 2022, 9:13 a.m. UTC
A significant number of RaspberryPi drivers using the firmware don't
have a phandle to it, so end up scanning the device tree to find a node
with the firmware compatible.

That code is duplicated everywhere, so let's introduce a helper instead.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
---
 drivers/firmware/raspberrypi.c             | 7 +++++++
 include/soc/bcm2835/raspberrypi-firmware.h | 7 +++++++
 2 files changed, 14 insertions(+)

Comments

Florian Fainelli Oct. 14, 2022, 7:43 p.m. UTC | #1
On 10/13/22 02:13, Maxime Ripard wrote:
> A significant number of RaspberryPi drivers using the firmware don't
> have a phandle to it, so end up scanning the device tree to find a node
> with the firmware compatible.
> 
> That code is duplicated everywhere, so let's introduce a helper instead.
> 
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
> ---
>   drivers/firmware/raspberrypi.c             | 7 +++++++
>   include/soc/bcm2835/raspberrypi-firmware.h | 7 +++++++
>   2 files changed, 14 insertions(+)
> 
> diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
> index 4b8978b254f9..b916e1e171f8 100644
> --- a/drivers/firmware/raspberrypi.c
> +++ b/drivers/firmware/raspberrypi.c
> @@ -311,6 +311,13 @@ static int rpi_firmware_remove(struct platform_device *pdev)
>   	return 0;
>   }
>   
> +static const struct of_device_id rpi_firmware_of_match[];

This shadows the same variable that is used later for matching the 
firmware driver and probe it as a platform_driver, what am I missing here?
Maxime Ripard Oct. 18, 2022, 7:32 a.m. UTC | #2
Hi Florian

On Fri, Oct 14, 2022 at 12:43:38PM -0700, Florian Fainelli wrote:
> On 10/13/22 02:13, Maxime Ripard wrote:
> > A significant number of RaspberryPi drivers using the firmware don't
> > have a phandle to it, so end up scanning the device tree to find a node
> > with the firmware compatible.
> > 
> > That code is duplicated everywhere, so let's introduce a helper instead.
> > 
> > Signed-off-by: Maxime Ripard <maxime@cerno.tech>
> > ---
> >   drivers/firmware/raspberrypi.c             | 7 +++++++
> >   include/soc/bcm2835/raspberrypi-firmware.h | 7 +++++++
> >   2 files changed, 14 insertions(+)
> > 
> > diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
> > index 4b8978b254f9..b916e1e171f8 100644
> > --- a/drivers/firmware/raspberrypi.c
> > +++ b/drivers/firmware/raspberrypi.c
> > @@ -311,6 +311,13 @@ static int rpi_firmware_remove(struct platform_device *pdev)
> >   	return 0;
> >   }
> > +static const struct of_device_id rpi_firmware_of_match[];
> 
> This shadows the same variable that is used later for matching the firmware
> driver and probe it as a platform_driver, what am I missing here?

I'm not shadowing the variable, but it's a forward-declaration.

Maxime
diff mbox series

Patch

diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
index 4b8978b254f9..b916e1e171f8 100644
--- a/drivers/firmware/raspberrypi.c
+++ b/drivers/firmware/raspberrypi.c
@@ -311,6 +311,13 @@  static int rpi_firmware_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id rpi_firmware_of_match[];
+struct device_node *rpi_firmware_find_node(void)
+{
+	return of_find_matching_node(NULL, rpi_firmware_of_match);
+}
+EXPORT_SYMBOL_GPL(rpi_firmware_find_node);
+
 /**
  * rpi_firmware_get - Get pointer to rpi_firmware structure.
  * @firmware_node:    Pointer to the firmware Device Tree node.
diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h
index 811ea668c4a1..63426082bcb9 100644
--- a/include/soc/bcm2835/raspberrypi-firmware.h
+++ b/include/soc/bcm2835/raspberrypi-firmware.h
@@ -142,6 +142,7 @@  int rpi_firmware_property(struct rpi_firmware *fw,
 int rpi_firmware_property_list(struct rpi_firmware *fw,
 			       void *data, size_t tag_size);
 void rpi_firmware_put(struct rpi_firmware *fw);
+struct device_node *rpi_firmware_find_node(void);
 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);
@@ -159,6 +160,12 @@  static inline int rpi_firmware_property_list(struct rpi_firmware *fw,
 }
 
 static inline void rpi_firmware_put(struct rpi_firmware *fw) { }
+
+static inline struct device_node *rpi_firmware_find_node(void)
+{
+	return NULL;
+}
+
 static inline struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node)
 {
 	return NULL;