Message ID | 20160608092135.21184-11-lee.jones@linaro.org |
---|---|
State | Accepted |
Headers | show |
On Wed, Jun 08, 2016 at 10:21:25AM +0100, Lee Jones wrote: > Allow a user to read PWM Capture results from /sysfs. > > To start a capture and read the result, simply read the file: > > $ cat $PWMCHIP/capture > > The output format is "<period>:<duty_cycle>". The format below is "<period> <duty cycle>". No need to rev the series for this, I can take patches 8 and 10 as-is and make those modifications myself. Thierry
On Fri, 10 Jun 2016, Thierry Reding wrote: > On Wed, Jun 08, 2016 at 10:21:25AM +0100, Lee Jones wrote: > > Allow a user to read PWM Capture results from /sysfs. > > > > To start a capture and read the result, simply read the file: > > > > $ cat $PWMCHIP/capture > > > > The output format is "<period>:<duty_cycle>". > > The format below is "<period> <duty cycle>". > > No need to rev the series for this, I can take patches 8 and 10 as-is > and make those modifications myself. Ideal, thanks.
diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c index d985992..901e647 100644 --- a/drivers/pwm/sysfs.c +++ b/drivers/pwm/sysfs.c @@ -208,16 +208,33 @@ static ssize_t polarity_store(struct device *child, return ret ? : size; } +static ssize_t capture_show(struct device *child, + struct device_attribute *attr, + char *buf) +{ + struct pwm_device *pwm = child_to_pwm_device(child); + struct pwm_capture result; + int ret; + + ret = pwm_capture(pwm, &result, jiffies_to_msecs(HZ)); + if (ret) + return ret; + + return sprintf(buf, "%llu %llu\n", result.period, result.duty_cycle); +} + static DEVICE_ATTR_RW(period); static DEVICE_ATTR_RW(duty_cycle); static DEVICE_ATTR_RW(enable); static DEVICE_ATTR_RW(polarity); +static DEVICE_ATTR_RO(capture); static struct attribute *pwm_attrs[] = { &dev_attr_period.attr, &dev_attr_duty_cycle.attr, &dev_attr_enable.attr, &dev_attr_polarity.attr, + &dev_attr_capture.attr, NULL }; ATTRIBUTE_GROUPS(pwm);
Allow a user to read PWM Capture results from /sysfs. To start a capture and read the result, simply read the file: $ cat $PWMCHIP/capture The output format is "<period>:<duty_cycle>". Signed-off-by: Lee Jones <lee.jones@linaro.org> --- drivers/pwm/sysfs.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)