Message ID | 1521607244-29734-1-git-send-email-rrajk@nvidia.com |
---|---|
Headers | show |
Series | Implementation of Tegra Tachometer driver | expand |
On 03/20/2018 09:40 PM, Rajkumar Rampelli wrote: > Add fan device attribute fan1_input in pwm-fan driver > to read speed of fan in rotations per minute. > > Signed-off-by: Rajkumar Rampelli <rrajk@nvidia.com> > --- > > V2: Removed generic-pwm-tachometer driver and using pwm-fan driver as per suggestions > to read fan speed. > Added fan device attribute to report speed of fan in rpms through hwmon sysfs. > > drivers/hwmon/pwm-fan.c | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c > index 70cc0d1..8dda209 100644 > --- a/drivers/hwmon/pwm-fan.c > +++ b/drivers/hwmon/pwm-fan.c > @@ -98,11 +98,34 @@ static ssize_t show_pwm(struct device *dev, > return sprintf(buf, "%u\n", ctx->pwm_value); > } > > +static ssize_t show_rpm(struct device *dev, struct device_attribute *attr, > + char *buf) > +{ > + struct pwm_fan_ctx *ptt = dev_get_drvdata(dev); > + struct pwm_device *pwm = ptt->pwm; > + struct pwm_capture result; > + unsigned int rpm = 0; > + int ret; > + > + ret = pwm_capture(pwm, &result, 0); > + if (ret < 0) { > + pr_err("Failed to capture PWM: %d\n", ret); > + return ret; > + } > + > + if (result.period) > + rpm = DIV_ROUND_CLOSEST_ULL(60ULL * NSEC_PER_SEC, > + result.period); > + > + return sprintf(buf, "%u\n", rpm); > +} > > static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0); > +static SENSOR_DEVICE_ATTR(fan1_input, 0444, show_rpm, NULL, 0); > > static struct attribute *pwm_fan_attrs[] = { > &sensor_dev_attr_pwm1.dev_attr.attr, > + &sensor_dev_attr_fan1_input.dev_attr.attr, This doesn't make sense. The same pwm can not both control the fan speed and report it. Guenter > NULL, > }; > > -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Mar 21, 2018 at 10:10:36AM +0530, Rajkumar Rampelli wrote: > Add support for pwm HW driver which has only capture functionality. > This helps to implement the PWM based Tachometer driver which reads > the PWM output signals from electronic fans. > > PWM Tachometer captures the period and duty cycle of the PWM signal > > Add conditional checks for callabacks enable(), disable(), config() > to check if they are supported by the client driver or not. Skip these > callbacks if they are not supported. > > Signed-off-by: Rajkumar Rampelli <rrajk@nvidia.com> > --- > > V2: Added if conditional checks for pwm callbacks since drivers may > implements only pwm capture functionality. > > drivers/pwm/core.c | 21 +++++++++++++++------ > 1 file changed, 15 insertions(+), 6 deletions(-) > > diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c > index 1581f6a..f70fe68 100644 > --- a/drivers/pwm/core.c > +++ b/drivers/pwm/core.c > @@ -246,6 +246,10 @@ static bool pwm_ops_check(const struct pwm_ops *ops) > if (ops->apply) > return true; > > + /* driver supports capture operation */ > + if (ops->capture) > + return true; > + > return false; > } > > @@ -495,7 +499,8 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) > * ->apply(). > */ > if (pwm->state.enabled) { > - pwm->chip->ops->disable(pwm->chip, pwm); > + if (pwm->chip->ops->disable) > + pwm->chip->ops->disable(pwm->chip, pwm); This is not a good idea. It means that you'll be able to successfully configure a capture-only PWM channel for output. I think all of the output configuration functions should return an error (-ENOSYS?) for capture-only devices, much like we return -ENOSYS for pwm_capture() if the driver doesn't implement capture support. Thierry