Raspberry Pi PoE HAT fan support
Subsystems (10)
v5 cover Raspberry Pi PoE HAT fan support
The aim of this series is to add support to the fan found on RPi's PoE HAT. Some commentary on the design can be found below. But the imporant part to the people CC'd here not involved with PWM is that, in order to achieve this properly, we also have to fix the firmware interface the driver uses to communicate with the PWM bus (and many other low level functions). Specifically, we have to make sure the firmware interface isn't unbound while consumers are still up. So, patch #1 & #2 introduce reference counting in the firwmware interface driver and patches #3 to #8 update all firmware users. Patches #9 to #11 introduce the new PWM driver.
I sent everything as a single series as the final version of the PWM drivers depends on the firwmare fixes, but I'll be happy to split this into two separate series if you think it's better.
--- Original cover letter below ---
This series aims at adding support to RPi's official PoE HAT fan[1].
The HW setup is the following:
| Raspberry Pi | PoE HAT |
arm core -> Mailbox -> RPi co-processor -> I2C -> Atmel MCU -> PWM -> FAN
The arm cores have only access to the mailbox interface, as i2c0, even if physically accessible, is to be used solely by the co-processor (VideoCore 4/6).
This series implements a PWM bus, and has pwm-fan sitting on top of it as per this discussion: https://lkml.org/lkml/2018/9/2/486. Although this design has a series of shortcomings:
- It depends on a DT binding: it's not flexible if a new hat shows up with new functionality, we're not 100% sure we'll be able to expand it without breaking backwards compatibility. But without it we can't make use of DT thermal-zones, which IMO is overkill.
- We're using pwm-fan, writing a hwmon driver would, again, give us more flexibility, but it's not really needed at the moment.
I personally think that it's not worth the effort, it's unlikely we'll get things right in advance. And ultimately, if the RPi people come up with something new, we can always write a new driver/bindings from scratch (as in not reusing previous code).
That said, I'm more than happy to change things if there is a consensus that another design will do the trick.
[1] https://www.raspberrypi.org/blog/introducing-power-over-ethernet-poe-hat/
---
Changes since v4:
- Cleanup devm calls
- Rename compatible string so it's unique to the PoE HAT
Changes since v3:
- Split first patch, #1 introduces refcount, then #2 the devm function
- Fix touchscreen function
- Use kref
Changes since v2:
- Introduce devm_rpi_firmware_get()
- Small cleanups in PWM driver
Changes since v1:
- Address PWM driver changes
- Fix binding, now with 2 cells
Nicolas Saenz Julienne (11):
firmware: raspberrypi: Keep count of all consumers
firmware: raspberrypi: Introduce devm_rpi_firmware_get()
clk: bcm: rpi: Release firmware handle on unbind
gpio: raspberrypi-exp: Release firmware handle on unbind
reset: raspberrypi: Release firmware handle on unbind
soc: bcm: raspberrypi-power: Release firmware handle on unbind
staging: vchiq: Release firmware handle on unbind
input: raspberrypi-ts: Release firmware handle when not needed
dt-bindings: pwm: Add binding for RPi firmware PWM bus DO NOT MERGE: ARM: dts: Add RPi's official PoE hat support
pwm: Add Raspberry Pi Firmware based PWM bus
.../arm/bcm/raspberrypi,bcm2835-firmware.yaml | 20 ++ arch/arm/boot/dts/bcm2711-rpi-4-b.dts | 54 +++++ drivers/clk/bcm/clk-raspberrypi.c | 2 +- drivers/firmware/raspberrypi.c | 66 +++++- drivers/gpio/gpio-raspberrypi-exp.c | 2 +- drivers/input/touchscreen/raspberrypi-ts.c | 2 +- drivers/pwm/Kconfig | 9 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-raspberrypi-poe.c | 216 ++++++++++++++++++ drivers/reset/reset-raspberrypi.c | 2 +- drivers/soc/bcm/raspberrypi-power.c | 2 +- .../interface/vchiq_arm/vchiq_arm.c | 2 +- .../pwm/raspberrypi,firmware-poe-pwm.h | 13 ++ include/soc/bcm2835/raspberrypi-firmware.h | 10 + 14 files changed, 391 insertions(+), 10 deletions(-) create mode 100644 drivers/pwm/pwm-raspberrypi-poe.c create mode 100644 include/dt-bindings/pwm/raspberrypi,firmware-poe-pwm.h
Signature · 1 line
2.29.2
PATCH v5 1/11 firmware: raspberrypi: Keep count of all consumers
When unbinding the firmware device we need to make sure it has no consumers left. Otherwise we'd leave them with a firmware handle pointing at freed memory.
Keep a reference count of all consumers and introduce rpi_firmware_put() which will permit automatically decrease the reference count upon unbinding consumer drivers.
---
Changes since v3:
- Use kref instead of waiting on refcount
drivers/firmware/raspberrypi.c | 37 +++++++++++++++++++--- include/soc/bcm2835/raspberrypi-firmware.h | 2 ++ 2 files changed, 35 insertions(+), 4 deletions(-)
drivers/firmware/raspberrypi.c +33 -4
@@ -7,6 +7,7 @@*/ #include <linux/dma-mapping.h> +#include <linux/kref.h> #include <linux/mailbox_client.h> #include <linux/module.h> #include <linux/of_platform.h>
@@ -27,6 +28,8 @@ struct rpi_firmware {struct mbox_chan *chan;/* The property channel. */ struct completion c;u32 enabled; + +struct kref consumers; };static DEFINE_MUTEX (transaction_lock);
@@ -225,12 +228,27 @@ static void rpi_register_clk_driver(struct device *dev) -1, NULL, 0); } +static void rpi_firmware_delete (struct kref *kref) +{ + struct rpi_firmware *fw = container_of(kref, struct rpi_firmware, + consumers); + +mbox_free_channel (fw->chan); +kfree (fw); +} + +void rpi_firmware_put (struct rpi_firmware *fw) +{ +kref_put (&fw->consumers, rpi_firmware_delete); +} +EXPORT_SYMBOL_GPL (rpi_firmware_put); +static int rpi_firmware_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;struct rpi_firmware *fw; - fw =devm_kzalloc (dev,sizeof (*fw),GFP_KERNEL ); + fw =kzalloc (sizeof (*fw),GFP_KERNEL );if (!fw)return -ENOMEM ;
@@ -247,6 +265,7 @@ static int rpi_firmware_probe(struct platform_device *pdev) }init_completion (&fw->c); +kref_init (&fw->consumers);platform_set_drvdata (pdev, fw);
@@ -275,25 +294,35 @@ static int rpi_firmware_remove(struct platform_device *pdev) rpi_hwmon =NULL ;platform_device_unregister (rpi_clk); rpi_clk =NULL ; -mbox_free_channel (fw->chan); + +rpi_firmware_put (fw);return 0 ; }/** -* rpi_firmware_get - Get pointer to rpi_firmware structure. * @firmware_node: Pointer to the firmware Device Tree node. * +* The reference to rpi_firmware has to be released with rpi_firmware_put(). +* * Returns NULL is the firmware device is not ready. */ struct rpi_firmware *rpi_firmware_get (struct device_node *firmware_node) {struct platform_device *pdev =of_find_device_by_node (firmware_node); +struct rpi_firmware *fw;if (!pdev)return NULL ; -return platform_get_drvdata (pdev); + fw =platform_get_drvdata (pdev); +if (!fw) +return NULL ; + +if (!kref_get_unless_zero (&fw->consumers)) +return NULL ; + +return fw; }EXPORT_SYMBOL_GPL (rpi_firmware_get);
include/soc/bcm2835/raspberrypi-firmware.h +2 -0
@@ -140,6 +140,7 @@ int rpi_firmware_property(struct rpi_firmware *fw, u32 tag, void *data, size_t len);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);#else static inline int rpi_firmware_property(struct rpi_firmware *fw, u32 tag,
@@ -154,6 +155,7 @@ static inline int rpi_firmware_property_list(struct rpi_firmware *fw,return -ENOSYS ; } +static inline void rpi_firmware_put (struct rpi_firmware *fw) { }static inline struct rpi_firmware *rpi_firmware_get (struct device_node *firmware_node) {return NULL ;
Signature · 1 line
2.29.2
Re: [PATCH v5 01/11] firmware: raspberrypi: Keep count of all consumers
Quoted 10 lines · Nicolas Saenz Julienne
When unbinding the firmware device we need to make sure it has no consumers left. Otherwise we'd leave them with a firmware handle pointing at freed memory.
Keep a reference count of all consumers and introduce
rpi_firmware_put()which will permit automatically decrease the reference count upon unbinding consumer drivers.Suggested-by Uwe Kleine-König <[email protected]>Signed-off-by Nicolas Saenz Julienne <[email protected]>
This looks fine to me, just one nit below:
[snip]
Quoted 2 lines
/**
- *rpi_firmware_get- Get pointer torpi_firmwarestructure.
Is not removing this line going to create a kernel doc warning?
With that fixed:
Signature · 1 line
Florian
Re: [PATCH v5 01/11] firmware: raspberrypi: Keep count of all consumers
In reply to Nicolas Saenz JulienneQuoted 56 lines · Nicolas Saenz Julienne
When unbinding the firmware device we need to make sure it has no consumers left. Otherwise we'd leave them with a firmware handle pointing at freed memory.
Keep a reference count of all consumers and introduce
rpi_firmware_put()which will permit automatically decrease the reference count upon unbinding consumer drivers.Suggested-by Uwe Kleine-König <[email protected]>Signed-off-by Nicolas Saenz Julienne <[email protected]>---
Changes since v3:
- Use kref instead of waiting on refcountdrivers/firmware/raspberrypi.c | 37 +++++++++++++++++++--- include/soc/bcm2835/raspberrypi-firmware.h | 2 ++ 2 files changed, 35 insertions(+), 4 deletions(-)drivers/firmware/raspberrypi.c +14
-0@@ -7,6 +7,7 @@*/ #include <linux/dma-mapping.h> +#include <linux/kref.h> #include <linux/mailbox_client.h> #include <linux/module.h> #include <linux/of_platform.h> @@ -27,6 +28,8 @@ struct rpi_firmware {struct mbox_chan *chan;/* The property channel. */ struct completion c;u32 enabled; + +struct kref consumers; };static DEFINE_MUTEX (transaction_lock);@@ -225,12 +228,27 @@ static void rpi_register_clk_driver(struct device *dev) -1, NULL, 0); } +static void rpi_firmware_delete (struct kref *kref) +{ + struct rpi_firmware *fw = container_of(kref, struct rpi_firmware, + consumers); + +mbox_free_channel (fw->chan); +kfree (fw); +} + +void rpi_firmware_put (struct rpi_firmware *fw) +{
drivers/firmware/raspberrypi.c static void rpi_register_clk_driver(struct device *dev) · line 233
Quoted 10 lines
drivers/firmware/raspberrypi.c +4
-1+kref_put (&fw->consumers, rpi_firmware_delete); +} +EXPORT_SYMBOL_GPL (rpi_firmware_put); +static int rpi_firmware_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;struct rpi_firmware *fw; - fw =devm_kzalloc (dev,sizeof (*fw),GFP_KERNEL );
One nit from my side: maybe add a comment here saying that you really want to use non-managed kzalloc() because you're going to get people blindly converting it to devm_kzalloc() very soon.
Bartosz
Quoted 74 lines
drivers/firmware/raspberrypi.c +15
-3+ fw =kzalloc (sizeof (*fw),GFP_KERNEL );if (!fw)return -ENOMEM ;@@ -247,6 +265,7 @@ static int rpi_firmware_probe(struct platform_device *pdev) }init_completion (&fw->c); +kref_init (&fw->consumers);platform_set_drvdata (pdev, fw);@@ -275,25 +294,35 @@ static int rpi_firmware_remove(struct platform_device *pdev) rpi_hwmon =NULL ;platform_device_unregister (rpi_clk); rpi_clk =NULL ; -mbox_free_channel (fw->chan); + +rpi_firmware_put (fw);return 0 ; }/** -* rpi_firmware_get - Get pointer to rpi_firmware structure. * @firmware_node: Pointer to the firmware Device Tree node. * +* The reference to rpi_firmware has to be released with rpi_firmware_put(). +* * Returns NULL is the firmware device is not ready. */ struct rpi_firmware *rpi_firmware_get (struct device_node *firmware_node) {struct platform_device *pdev =of_find_device_by_node (firmware_node); +struct rpi_firmware *fw;if (!pdev)return NULL ; -return platform_get_drvdata (pdev); + fw =platform_get_drvdata (pdev); +if (!fw) +return NULL ; + +if (!kref_get_unless_zero (&fw->consumers)) +return NULL ; + +return fw; }EXPORT_SYMBOL_GPL (rpi_firmware_get);include/soc/bcm2835/raspberrypi-firmware.h +2
-1@@ -140,6 +140,7 @@ int rpi_firmware_property(struct rpi_firmware *fw, u32 tag, void *data, size_t len);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);#else static inline int rpi_firmware_property(struct rpi_firmware *fw, u32 tag,@@ -154,6 +155,7 @@ static inline int rpi_firmware_property_list(struct rpi_firmware *fw,return -ENOSYS ; } +static inline void rpi_firmware_put (struct rpi_firmware *fw) { }static inline struct rpi_firmware *rpi_firmware_get (struct device_node *firmware_node) {return NULL ; --2.29.2
Re: [PATCH v5 01/11] firmware: raspberrypi: Keep count of all consumers
Quoted 67 lines · Bartosz Golaszewski
Quoted 65 lines · Nicolas Saenz Julienne
When unbinding the firmware device we need to make sure it has no consumers left. Otherwise we'd leave them with a firmware handle pointing at freed memory.
Keep a reference count of all consumers and introduce
rpi_firmware_put()which will permit automatically decrease the reference count upon unbinding consumer drivers.Suggested-by Uwe Kleine-König <[email protected]>Signed-off-by Nicolas Saenz Julienne <[email protected]>---
Changes since v3:
- Use kref instead of waiting on refcountdrivers/firmware/raspberrypi.c | 37 +++++++++++++++++++---
include/soc/bcm2835/raspberrypi-firmware.h | 2 ++2 files changed, 35 insertions(+), 4 deletions(-)drivers/firmware/raspberrypi.c +1
-0@@ -7,6 +7,7 @@*/ #include <linux/dma-mapping.h> +#include <linux/kref.h> #include <linux/mailbox_client.h> #include <linux/module.h> #include <linux/of_platform.h>@@ -27,6 +28,8 @@ struct rpi_firmware {struct
mbox_chan*chan; /* The property channel. */ struct completion c;
u32 enabled;drivers/firmware/raspberrypi.c +2
-0+ +struct kref consumers;};
static
DEFINE_MUTEX(transaction_lock);drivers/firmware/raspberrypi.c +15
-0@@ -225,12 +228,27 @@ static void rpi_register_clk_driver(struct device *dev) -1, NULL, 0); } +static void rpi_firmware_delete (struct kref *kref) +{ + struct rpi_firmware *fw = container_of(kref, struct rpi_firmware, + consumers); + +mbox_free_channel (fw->chan); +kfree (fw); +} + +void rpi_firmware_put (struct rpi_firmware *fw) +{ +kref_put (&fw->consumers, rpi_firmware_delete); +} +EXPORT_SYMBOL_GPL (rpi_firmware_put); + static int rpi_firmware_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct rpi_firmware *fw;
Quoted 5 lines
drivers/firmware/raspberrypi.c static void rpi_register_clk_driver(struct device *dev) · line 233
Quoted 1 line
drivers/firmware/raspberrypi.c +0
-1- fw =devm_kzalloc (dev,sizeof (*fw),GFP_KERNEL );One nit from my side: maybe add a comment here saying that you really want to use non-managed
kzalloc()because you're going to get people blindly converting it todevm_kzalloc()very soon.
Good point, I'll change it.
Regards,
Nicolas
PATCH v5 2/11 firmware: raspberrypi: Introduce devm_rpi_firmware_get()
In reply to Nicolas Saenz JulienneIt'll simplify the firmware handling for most consumers.
---
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(+)
drivers/firmware/raspberrypi.c +29 -0
@@ -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;
@@ -326,6 +333,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" , }, {},
include/soc/bcm2835/raspberrypi-firmware.h +8 -0
@@ -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__ */
Signature · 1 line
2.29.2
Re: [PATCH v5 02/11] firmware: raspberrypi: Introduce devm_rpi_firmware_get()
Quoted 4 lines · Nicolas Saenz Julienne
It'll simplify the firmware handling for most consumers.
Suggested-by Bartosz Golaszewski <[email protected]>Signed-off-by Nicolas Saenz Julienne <[email protected]>
Signature · 1 line
Florian
PATCH v5 3/11 clk: bcm: rpi: Release firmware handle on unbind
In reply to Nicolas Saenz JulienneUse devm_rpi_firmware_get() so as to make sure we release RPi's firmware interface when unbinding the device.
---
Changes since v2:
- Use devm_rpi_firmware_get(), instead of remove function
drivers/clk/bcm/clk-raspberrypi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/bcm/clk-raspberrypi.c +1 -1
@@ -314,7 +314,7 @@ static int raspberrypi_clk_probe(struct platform_device *pdev)return -ENOENT ; } - firmware =rpi_firmware_get (firmware_node); + firmware =devm_rpi_firmware_get (&pdev->dev, firmware_node);of_node_put (firmware_node);if (!firmware)return -EPROBE_DEFER ;
Signature · 1 line
2.29.2
Re: [PATCH v5 03/11] clk: bcm: rpi: Release firmware handle on unbind
Quoted 4 lines · Nicolas Saenz Julienne
Use
devm_rpi_firmware_get()so as to make sure we release RPi's firmware interface when unbinding the device.Signed-off-by Nicolas Saenz Julienne <[email protected]>
Signature · 1 line
Florian
PATCH v5 4/11 gpio: raspberrypi-exp: Release firmware handle on unbind
In reply to Nicolas Saenz JulienneUse devm_rpi_firmware_get() so as to make sure we release RPi's firmware interface when unbinding the device.
---
Changes since v2:
- Use devm_rpi_firmware_get(), instead of remove function
drivers/gpio/gpio-raspberrypi-exp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-raspberrypi-exp.c +1 -1
@@ -208,7 +208,7 @@ static int rpi_exp_gpio_probe(struct platform_device *pdev)return -ENOENT ; } - fw =rpi_firmware_get (fw_node); + fw =devm_rpi_firmware_get (&pdev->dev, fw_node);of_node_put (fw_node);if (!fw)return -EPROBE_DEFER ;
Signature · 1 line
2.29.2
Re: [PATCH v5 04/11] gpio: raspberrypi-exp: Release firmware handle on unbind
Quoted 5 lines · Nicolas Saenz Julienne
Use
devm_rpi_firmware_get()so as to make sure we release RPi's firmware interface when unbinding the device.Signed-off-by Nicolas Saenz Julienne <[email protected]>
Signature · 1 line
Florian
PATCH v5 5/11 reset: raspberrypi: Release firmware handle on unbind
In reply to Nicolas Saenz JulienneUse devm_rpi_firmware_get() so as to make sure we release RPi's firmware interface when unbinding the device.
---
Changes since v2:
- Use devm_rpi_firmware_get(), instead of remove function
drivers/reset/reset-raspberrypi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/reset/reset-raspberrypi.c +1 -1
@@ -82,7 +82,7 @@ static int rpi_reset_probe(struct platform_device *pdev)return -ENOENT ; } - fw =rpi_firmware_get (np); + fw =devm_rpi_firmware_get (&pdev->dev, np);of_node_put (np);if (!fw)return -EPROBE_DEFER ;
Signature · 1 line
2.29.2
Re: [PATCH v5 05/11] reset: raspberrypi: Release firmware handle on unbind
Quoted 4 lines · Nicolas Saenz Julienne
Use
devm_rpi_firmware_get()so as to make sure we release RPi's firmware interface when unbinding the device.Signed-off-by Nicolas Saenz Julienne <[email protected]>
Signature · 1 line
Florian
PATCH v5 6/11 soc: bcm: raspberrypi-power: Release firmware handle on unbind
In reply to Nicolas Saenz JulienneUse devm_rpi_firmware_get() so as to make sure we release RPi's firmware interface when unbinding the device.
---
Changes since v2:
- Use devm_rpi_firmware_get(), instead of remove function
drivers/soc/bcm/raspberrypi-power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/bcm/raspberrypi-power.c +1 -1
@@ -177,7 +177,7 @@ static int rpi_power_probe(struct platform_device *pdev)return -ENODEV ; } - rpi_domains->fw =rpi_firmware_get (fw_np); + rpi_domains->fw =devm_rpi_firmware_get (&pdev->dev, fw_np);of_node_put (fw_np);if (!rpi_domains->fw)return -EPROBE_DEFER ;
Signature · 1 line
2.29.2
Re: [PATCH v5 06/11] soc: bcm: raspberrypi-power: Release firmware handle on unbind
Quoted 4 lines · Nicolas Saenz Julienne
Use
devm_rpi_firmware_get()so as to make sure we release RPi's firmware interface when unbinding the device.Signed-off-by Nicolas Saenz Julienne <[email protected]>
Signature · 1 line
Florian
PATCH v5 7/11 staging: vchiq: Release firmware handle on unbind
In reply to Nicolas Saenz JulienneUse devm_rpi_firmware_get() so as to make sure we release RPi's firmware interface when unbinding the device.
---
Changes since v2:
- Use devm_rpi_firmware_get(), instead of remove function
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +1 -1
@@ -2732,7 +2732,7 @@ static int vchiq_probe(struct platform_device *pdev)return -ENOENT ; } - drvdata->fw =rpi_firmware_get (fw_node); + drvdata->fw =devm_rpi_firmware_get (&pdev->dev, fw_node);of_node_put (fw_node);if (!drvdata->fw)return -EPROBE_DEFER ;
Signature · 1 line
2.29.2
Re: [PATCH v5 07/11] staging: vchiq: Release firmware handle on unbind
Quoted 4 lines · Nicolas Saenz Julienne
Use
devm_rpi_firmware_get()so as to make sure we release RPi's firmware interface when unbinding the device.Signed-off-by Nicolas Saenz Julienne <[email protected]>
Signature · 1 line
Florian
PATCH v5 8/11 input: raspberrypi-ts: Release firmware handle when not needed
In reply to Nicolas Saenz JulienneUse devm_rpi_firmware_get() so as to make sure we release RPi's firmware interface when unbinding the device.
---
Changes since v3:
- Release firmware handle in probe function
Changes since v2:
- Use devm_rpi_firmware_get(), instead of remove function
drivers/input/touchscreen/raspberrypi-ts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/touchscreen/raspberrypi-ts.c +1 -1
@@ -160,7 +160,7 @@ static int rpi_ts_probe(struct platform_device *pdev) touchbuf = (u32 )ts->fw_regs_phys; error =rpi_firmware_property (fw,RPI_FIRMWARE_FRAMEBUFFER_SET_TOUCHBUF , &touchbuf,sizeof (touchbuf)); - +rpi_firmware_put (fw);if (error || touchbuf !=0 ) {dev_warn (dev,"Failed to set touchbuf, %d\n" , error);return error;
Signature · 1 line
2.29.2
Re: [PATCH v5 08/11] input: raspberrypi-ts: Release firmware handle when not needed
Hi Nicolas,
Quoted 2 lines · Nicolas Saenz Julienne
Use
devm_rpi_firmware_get()so as to make sure we release RPi's firmware interface when unbinding the device.
I do not believe this comment is correct any longer. Otherwise:
Quoted 30 lines
Signed-off-by Nicolas Saenz Julienne <[email protected]>---
Changes since v3:
- Release firmware handle in probe functionChanges since v2:
- Usedevm_rpi_firmware_get(), instead of remove functiondrivers/input/touchscreen/raspberrypi-ts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/input/touchscreen/raspberrypi-ts.c +1
-1@@ -160,7 +160,7 @@ static int rpi_ts_probe(struct platform_device *pdev) touchbuf = (u32 )ts->fw_regs_phys; error =rpi_firmware_property (fw,RPI_FIRMWARE_FRAMEBUFFER_SET_TOUCHBUF , &touchbuf,sizeof (touchbuf)); - +rpi_firmware_put (fw);if (error || touchbuf !=0 ) {dev_warn (dev,"Failed to set touchbuf, %d\n" , error);return error;Signature · 1 line
2.29.2
Signature · 1 line
Dmitry
Re: [PATCH v5 08/11] input: raspberrypi-ts: Release firmware handle when not needed
Quoted 9 lines · Dmitry Torokhov
Hi Nicolas,
Quoted 2 lines · Nicolas Saenz Julienne
Use
devm_rpi_firmware_get()so as to make sure we release RPi's firmware interface when unbinding the device.I do not believe this comment is correct any longer. Otherwise:
Acked-by Dmitry Torokhov <[email protected]>
Yes, sorry for that. I'll update it.
Regards,
Nicolas
PATCH v5 9/11 dt-bindings: pwm: Add binding for RPi firmware PWM bus
In reply to Nicolas Saenz JulienneThe PWM bus controlling the fan in RPi's official PoE hat can only be controlled by the board's co-processor.
---
Changes since v4:
- Rename compatible string to be more explicit with the bus' limitations
Changes since v3:
- Fix example
Changes since v1:
- Update bindings to use 2 #pwm-cells
.../arm/bcm/raspberrypi,bcm2835-firmware.yaml | 20 +++++++++++++++++++ .../pwm/raspberrypi,firmware-poe-pwm.h | 13 ++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 include/dt-bindings/pwm/raspberrypi,firmware-poe-pwm.h
Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-firmware.yaml +20 -0
@@ -64,6 +64,21 @@ properties: - compatible - "#reset-cells" + pwm: + type: object + + properties: + compatible: + const: raspberrypi,firmware-poe-pwm + + "#pwm-cells": + # See pwm.yaml in this directory for a description of the cells format. + const: 2 + + required: + - compatible + - "#pwm-cells" + additionalProperties: false required:
@@ -87,5 +102,10 @@ examples: compatible = "raspberrypi,firmware-reset"; #reset-cells = <1>; }; + + pwm: pwm { + compatible = "raspberrypi,firmware-poe-pwm"; + #pwm-cells = <2>; + }; }; ...
include/dt-bindings/pwm/raspberrypi,firmware-poe-pwm.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2020 Nicolas Saenz Julienne +* Author: Nicolas Saenz Julienne <[email protected]> +*/ + +#ifndef _DT_BINDINGS_RASPBERRYPI_FIRMWARE_PWM_H +#define _DT_BINDINGS_RASPBERRYPI_FIRMWARE_PWM_H + +#define RASPBERRYPI_FIRMWARE_PWM_POE 0 +#define RASPBERRYPI_FIRMWARE_PWM_NUM 1 + +#endif
Signature · 1 line
2.29.2
PATCH v5 10/11 DO NOT MERGE: ARM: dts: Add RPi's official PoE hat support
In reply to Nicolas Saenz JulienneThis is an example on how to enable the fan on top of RPi's official PoE hat.
---
Changes since v1:
- Update patch to use 2 pwm cells
arch/arm/boot/dts/bcm2711-rpi-4-b.dts | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
arch/arm/boot/dts/bcm2711-rpi-4-b.dts +54 -0
@@ -5,6 +5,7 @@ #include "bcm283x-rpi-usb-peripheral.dtsi" #include <dt-bindings/reset/raspberrypi,firmware-reset.h> +#include <dt-bindings/pwm/raspberrypi,firmware-poe-pwm.h> / { compatible = "raspberrypi,4-model-b", "brcm,bcm2711";
@@ -68,6 +69,54 @@ sd_vcc_reg: sd_vcc_reg { enable-active-high; gpio = <&expgpio 6 GPIO_ACTIVE_HIGH>; }; + + fan: pwm-fan { + compatible = "pwm-fan"; + cooling-levels = <0 50 150 255>; + #cooling-cells = <2>; + pwms = <&fwpwm RASPBERRYPI_FIRMWARE_PWM_POE 80000>; + }; + + thermal-zones { + cpu_thermal: cpu-thermal { + trips { + threshold: trip-point@0 { + temperature = <45000>; + hysteresis = <5000>; + type = "active"; + }; + + target: trip-point@1 { + temperature = <50000>; + hysteresis = <2000>; + type = "active"; + }; + + cpu_hot: cpu_hot@0 { + temperature = <55000>; + hysteresis = <2000>; + type = "active"; + }; + }; + + cooling-maps { + map0 { + trip = <&threshold>; + cooling-device = <&fan 0 1>; + }; + + map1 { + trip = <&target>; + cooling-device = <&fan 1 2>; + }; + + map2 { + trip = <&cpu_hot>; + cooling-device = <&fan 2 3>; + }; + }; + }; + }; }; &ddc0 {
@@ -103,6 +152,11 @@ reset: reset { compatible = "raspberrypi,firmware-reset"; #reset-cells = <1>; }; + + fwpwm: pwm { + compatible = "raspberrypi,firmware-poe-pwm"; + #pwm-cells = <2>; + }; }; &gpio {
Signature · 1 line
2.29.2
PATCH v5 11/11 pwm: Add Raspberry Pi Firmware based PWM bus
In reply to Nicolas Saenz JulienneAdds support to control the PWM bus available in official Raspberry Pi PoE HAT. Only RPi's co-processor has access to it, so commands have to be sent through RPi's firmware mailbox interface.
---
Changes since v3:
- Rename compatible string to be more explicit WRT to bus's limitations
Changes since v2:
- Use devm_rpi_firmware_get()
- Rename driver
- Small cleanups
Changes since v1:
- Use default pwm bindings and get rid of xlate() function
- Correct spelling errors
- Correct apply() function
- Round values
- Fix divisions in arm32 mode
- Small cleanups
drivers/pwm/Kconfig | 9 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-raspberrypi-poe.c | 216 ++++++++++++++++++++++++++++++ 3 files changed, 226 insertions(+) create mode 100644 drivers/pwm/pwm-raspberrypi-poe.c
drivers/pwm/Kconfig +9 -0
@@ -423,6 +423,15 @@ config PWM_PXA To compile this driver as a module, choose M here: the module will be called pwm-pxa. +config PWM_RASPBERRYPI_POE + tristate "Raspberry Pi Firwmware PoE Hat PWM support" + # Make sure not 'y' when RASPBERRYPI_FIRMWARE is 'm'. This can only + # happen when COMPILE_TEST=y, hence the added !RASPBERRYPI_FIRMWARE. + depends on RASPBERRYPI_FIRMWARE || (COMPILE_TEST && !RASPBERRYPI_FIRMWARE) + help + Enable Raspberry Pi firmware controller PWM bus used to control the + official RPI PoE hat + config PWM_RCAR tristate "Renesas R-Car PWM support" depends on ARCH_RENESAS || COMPILE_TEST
drivers/pwm/Makefile +1 -0
@@ -38,6 +38,7 @@ obj-$(CONFIG_PWM_MXS) += pwm-mxs.o obj-$(CONFIG_PWM_OMAP_DMTIMER) += pwm-omap-dmtimer.o obj-$(CONFIG_PWM_PCA9685) += pwm-pca9685.o obj-$(CONFIG_PWM_PXA) += pwm-pxa.o +obj-$(CONFIG_PWM_RASPBERRYPI_POE) += pwm-raspberrypi-poe.o obj-$(CONFIG_PWM_RCAR) += pwm-rcar.o obj-$(CONFIG_PWM_RENESAS_TPU) += pwm-renesas-tpu.o obj-$(CONFIG_PWM_ROCKCHIP) += pwm-rockchip.o
drivers/pwm/pwm-raspberrypi-poe.c new file +216 -0
216 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [PATCH v5 11/11] pwm: Add Raspberry Pi Firmware based PWM bus
Hi All,
Quoted 6 lines · Nicolas Saenz Julienne
Adds support to control the PWM bus available in official Raspberry Pi PoE HAT. Only RPi's co-processor has access to it, so commands have to be sent through RPi's firmware mailbox interface.
Signed-off-by Nicolas Saenz Julienne <[email protected]>
I'll soon send a v6 of this series and was wondering if there is any more feedback for this patch.
Regards,
Nicolas