Message ID | 20230418220109.787907-1-chris.packham@alliedtelesis.co.nz (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | hwmon: (adt7475) Handle DT unaware platforms | expand |
On 19/04/23 10:01, Chris Packham wrote: > Configuring the pwm polarity via the adi,pwm-active-state property is an > optional feature. On DT aware platforms of_property_read_u32_array() > returns -EINVAL when the property is absent this is checked for and the > driver probe continues without issue. > > On DT unaware platfroms of_property_read_u32_array() returns -ENOSYS > which caused the driver probe to dev_warn(). Update the code to deal > with -ENOSYS so that the dev_warn() only occurs when there is a genuine > issue. > > 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> > --- > drivers/hwmon/adt7475.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c > index 6e4c92b500b8..af906eee480e 100644 > --- a/drivers/hwmon/adt7475.c > +++ b/drivers/hwmon/adt7475.c > @@ -1607,6 +1607,13 @@ static int adt7475_set_pwm_polarity(struct i2c_client *client) > ret = of_property_read_u32_array(client->dev.of_node, > "adi,pwm-active-state", states, > ARRAY_SIZE(states)); > + /* > + * -EINVAL indicates that the property is absent, -ENOSYS indicates > + * that the platform lacks DT awareness. Neither of these are errors > + * for the optional pwm polarity support. > + */ > + if (ret == -EINVAL || ret == -ENOSYS) > + return 0; I was looking around for why there weren't more checks of -ENOSYS and I suspect the answer is I should be using device_property_read_u32_array() instead. With the indirection I'm not 100% sure that I'll actually get the -EINVAL on a DT unaware platform, can anyone confirm this? > if (ret) > return ret; > > @@ -1741,7 +1748,7 @@ static int adt7475_probe(struct i2c_client *client) > adt7475_read_pwm(client, i); > > ret = adt7475_set_pwm_polarity(client); > - if (ret && ret != -EINVAL) > + if (ret) > dev_warn(&client->dev, "Error configuring pwm polarity\n"); > > /* Start monitoring */
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 6e4c92b500b8..af906eee480e 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -1607,6 +1607,13 @@ static int adt7475_set_pwm_polarity(struct i2c_client *client) ret = of_property_read_u32_array(client->dev.of_node, "adi,pwm-active-state", states, ARRAY_SIZE(states)); + /* + * -EINVAL indicates that the property is absent, -ENOSYS indicates + * that the platform lacks DT awareness. Neither of these are errors + * for the optional pwm polarity support. + */ + if (ret == -EINVAL || ret == -ENOSYS) + return 0; if (ret) return ret; @@ -1741,7 +1748,7 @@ static int adt7475_probe(struct i2c_client *client) adt7475_read_pwm(client, i); ret = adt7475_set_pwm_polarity(client); - if (ret && ret != -EINVAL) + if (ret) dev_warn(&client->dev, "Error configuring pwm polarity\n"); /* Start monitoring */
Configuring the pwm polarity via the adi,pwm-active-state property is an optional feature. On DT aware platforms of_property_read_u32_array() returns -EINVAL when the property is absent this is checked for and the driver probe continues without issue. On DT unaware platfroms of_property_read_u32_array() returns -ENOSYS which caused the driver probe to dev_warn(). Update the code to deal with -ENOSYS so that the dev_warn() only occurs when there is a genuine issue. 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> --- drivers/hwmon/adt7475.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)