[PATCH v2 1/2] hwmon: (adt7475) Use device_property APIs when configuring polarity

Chris Packham posted 2 patches 2 years, 8 months ago
[PATCH v2 1/2] hwmon: (adt7475) Use device_property APIs when configuring polarity
Posted by Chris Packham 2 years, 8 months ago
On DT unaware platforms of_property_read_u32_array() returns -ENOSYS
which wasn't handled by the code treating adi,pwm-active-state as
optional. Update the code to use device_property_read_u32_array() which
deals gracefully with DT unaware platforms.

Fixes: 86da28eed4fb ("hwmon: (adt7475) Add support for inverting pwm output")
Reported-by: Mariusz Białończyk <manio@skyboo.net>
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---

Notes:
    I've not currently got access to a DT unaware platform with an ADT7475
    chip so I'm not 100% sure that this will fix the problem Mariusz
    reported but looking at drivers I think this approach is correct.
    
    Changes in v2:
    - use device_property_read_u32_array instead of checking for -ENOSYS

 drivers/hwmon/adt7475.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index 6e4c92b500b8..6a6ebcc896b1 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -1604,9 +1604,9 @@ static int adt7475_set_pwm_polarity(struct i2c_client *client)
 	int ret, i;
 	u8 val;
 
-	ret = of_property_read_u32_array(client->dev.of_node,
-					 "adi,pwm-active-state", states,
-					 ARRAY_SIZE(states));
+	ret = device_property_read_u32_array(&client->dev,
+					     "adi,pwm-active-state", states,
+					     ARRAY_SIZE(states));
 	if (ret)
 		return ret;
 
-- 
2.40.0
Re: [PATCH v2 1/2] hwmon: (adt7475) Use device_property APIs when configuring polarity
Posted by Guenter Roeck 2 years, 8 months ago
On Wed, Apr 19, 2023 at 11:36:55AM +1200, Chris Packham wrote:
> On DT unaware platforms of_property_read_u32_array() returns -ENOSYS
> which wasn't handled by the code treating adi,pwm-active-state as
> optional. Update the code to use device_property_read_u32_array() which
> deals gracefully with DT unaware platforms.
> 
> Fixes: 86da28eed4fb ("hwmon: (adt7475) Add support for inverting pwm output")
> Reported-by: Mariusz Białończyk <manio@skyboo.net>
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>

Applied.

Thanks,
Guenter

> ---
> 
> Notes:
>     I've not currently got access to a DT unaware platform with an ADT7475
>     chip so I'm not 100% sure that this will fix the problem Mariusz
>     reported but looking at drivers I think this approach is correct.
>     
>     Changes in v2:
>     - use device_property_read_u32_array instead of checking for -ENOSYS
> 
>  drivers/hwmon/adt7475.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
> index 6e4c92b500b8..6a6ebcc896b1 100644
> --- a/drivers/hwmon/adt7475.c
> +++ b/drivers/hwmon/adt7475.c
> @@ -1604,9 +1604,9 @@ static int adt7475_set_pwm_polarity(struct i2c_client *client)
>  	int ret, i;
>  	u8 val;
>  
> -	ret = of_property_read_u32_array(client->dev.of_node,
> -					 "adi,pwm-active-state", states,
> -					 ARRAY_SIZE(states));
> +	ret = device_property_read_u32_array(&client->dev,
> +					     "adi,pwm-active-state", states,
> +					     ARRAY_SIZE(states));
>  	if (ret)
>  		return ret;
>  
Re: [PATCH v2 1/2] hwmon: (adt7475) Use device_property APIs when configuring polarity
Posted by Guenter Roeck 2 years, 8 months ago
On Wed, Apr 19, 2023 at 11:36:55AM +1200, Chris Packham wrote:
> On DT unaware platforms of_property_read_u32_array() returns -ENOSYS
> which wasn't handled by the code treating adi,pwm-active-state as
> optional. Update the code to use device_property_read_u32_array() which
> deals gracefully with DT unaware platforms.
> 
> Fixes: 86da28eed4fb ("hwmon: (adt7475) Add support for inverting pwm output")
> Reported-by: Mariusz Białończyk <manio@skyboo.net>
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
> 
> Notes:
>     I've not currently got access to a DT unaware platform with an ADT7475
>     chip so I'm not 100% sure that this will fix the problem Mariusz
>     reported but looking at drivers I think this approach is correct.
>     

What happens if there is no such property anywhere, neither in
devicetree nor in acpi ?

Guenter

>     Changes in v2:
>     - use device_property_read_u32_array instead of checking for -ENOSYS
> 
>  drivers/hwmon/adt7475.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
> index 6e4c92b500b8..6a6ebcc896b1 100644
> --- a/drivers/hwmon/adt7475.c
> +++ b/drivers/hwmon/adt7475.c
> @@ -1604,9 +1604,9 @@ static int adt7475_set_pwm_polarity(struct i2c_client *client)
>  	int ret, i;
>  	u8 val;
>  
> -	ret = of_property_read_u32_array(client->dev.of_node,
> -					 "adi,pwm-active-state", states,
> -					 ARRAY_SIZE(states));
> +	ret = device_property_read_u32_array(&client->dev,
> +					     "adi,pwm-active-state", states,
> +					     ARRAY_SIZE(states));
>  	if (ret)
>  		return ret;
>  
> -- 
> 2.40.0
>