Message ID | 20240424090453.2292185-2-peter@korsgaard.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [1/2] dt-bindings: hwmon: pwm-fan: Document target-pwm property | expand |
On 4/24/24 02:04, Peter Korsgaard wrote: > For some use cases defaulting the PWM to full fan speed is not ideal > (noise, power consumption, ..), so support an optional target-pwm > property (0..255) to override the default PWM value. > > Signed-off-by: Peter Korsgaard <peter@korsgaard.com> > --- > drivers/hwmon/pwm-fan.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c > index b67bc9e833c0..ebdefbd5789c 100644 > --- a/drivers/hwmon/pwm-fan.c > +++ b/drivers/hwmon/pwm-fan.c > @@ -482,6 +482,7 @@ static int pwm_fan_probe(struct platform_device *pdev) > const struct hwmon_channel_info **channels; > u32 *fan_channel_config; > int channel_count = 1; /* We always have a PWM channel. */ > + u32 target_pwm = MAX_PWM; > int i; > > ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); > @@ -527,11 +528,17 @@ static int pwm_fan_probe(struct platform_device *pdev) > > ctx->enable_mode = pwm_disable_reg_enable; > > + of_property_read_u32(dev->of_node, "target-pwm", &target_pwm); > + if (target_pwm > (u32)MAX_PWM) { > + dev_err(dev, "Invalid target-pwm: %u > %d\n", target_pwm, MAX_PWM); > + return -EINVAL; > + } > + > /* > - * Set duty cycle to maximum allowed and enable PWM output as well as > + * Set duty cycle to target and enable PWM output as well as > * the regulator. In case of error nothing is changed > */ > - ret = set_pwm(ctx, MAX_PWM); > + ret = set_pwm(ctx, target_pwm); > if (ret) { > dev_err(dev, "Failed to configure PWM: %d\n", ret); > return ret; A much better name would be default-pwm for the property name. target-pwm is misleading and doesn't really make sense because there is no "target", just a value that is being set. Guenter
On 4/24/24 02:04, Peter Korsgaard wrote: > For some use cases defaulting the PWM to full fan speed is not ideal > (noise, power consumption, ..), so support an optional target-pwm > property (0..255) to override the default PWM value. > > Signed-off-by: Peter Korsgaard <peter@korsgaard.com> > --- > drivers/hwmon/pwm-fan.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c > index b67bc9e833c0..ebdefbd5789c 100644 > --- a/drivers/hwmon/pwm-fan.c > +++ b/drivers/hwmon/pwm-fan.c > @@ -482,6 +482,7 @@ static int pwm_fan_probe(struct platform_device *pdev) > const struct hwmon_channel_info **channels; > u32 *fan_channel_config; > int channel_count = 1; /* We always have a PWM channel. */ > + u32 target_pwm = MAX_PWM; > int i; > > ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); > @@ -527,11 +528,17 @@ static int pwm_fan_probe(struct platform_device *pdev) > > ctx->enable_mode = pwm_disable_reg_enable; > > + of_property_read_u32(dev->of_node, "target-pwm", &target_pwm); > + if (target_pwm > (u32)MAX_PWM) { Unnecessary type cast. Guenter > + dev_err(dev, "Invalid target-pwm: %u > %d\n", target_pwm, MAX_PWM); > + return -EINVAL; > + } > + > /* > - * Set duty cycle to maximum allowed and enable PWM output as well as > + * Set duty cycle to target and enable PWM output as well as > * the regulator. In case of error nothing is changed > */ > - ret = set_pwm(ctx, MAX_PWM); > + ret = set_pwm(ctx, target_pwm); > if (ret) { > dev_err(dev, "Failed to configure PWM: %d\n", ret); > return ret;
diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index b67bc9e833c0..ebdefbd5789c 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -482,6 +482,7 @@ static int pwm_fan_probe(struct platform_device *pdev) const struct hwmon_channel_info **channels; u32 *fan_channel_config; int channel_count = 1; /* We always have a PWM channel. */ + u32 target_pwm = MAX_PWM; int i; ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); @@ -527,11 +528,17 @@ static int pwm_fan_probe(struct platform_device *pdev) ctx->enable_mode = pwm_disable_reg_enable; + of_property_read_u32(dev->of_node, "target-pwm", &target_pwm); + if (target_pwm > (u32)MAX_PWM) { + dev_err(dev, "Invalid target-pwm: %u > %d\n", target_pwm, MAX_PWM); + return -EINVAL; + } + /* - * Set duty cycle to maximum allowed and enable PWM output as well as + * Set duty cycle to target and enable PWM output as well as * the regulator. In case of error nothing is changed */ - ret = set_pwm(ctx, MAX_PWM); + ret = set_pwm(ctx, target_pwm); if (ret) { dev_err(dev, "Failed to configure PWM: %d\n", ret); return ret;
For some use cases defaulting the PWM to full fan speed is not ideal (noise, power consumption, ..), so support an optional target-pwm property (0..255) to override the default PWM value. Signed-off-by: Peter Korsgaard <peter@korsgaard.com> --- drivers/hwmon/pwm-fan.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)