diff options
author | Lee Jones <lee.jones@linaro.org> | 2016-06-08 05:21:25 -0400 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2016-06-10 10:01:40 -0400 |
commit | 1a366fe9153f445e950a7a344932b7419aa83094 (patch) | |
tree | b6d66b37c862446d280a03179c178913d9090aad | |
parent | 3a3d1a4e32ab47323d7b8c8b7631a8d36a3098b2 (diff) |
pwm: sysfs: Add PWM capture support
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>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
-rw-r--r-- | Documentation/ABI/testing/sysfs-class-pwm | 9 | ||||
-rw-r--r-- | drivers/pwm/sysfs.c | 17 |
2 files changed, 26 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-class-pwm b/Documentation/ABI/testing/sysfs-class-pwm index c479d77b67c5..c20e61354561 100644 --- a/Documentation/ABI/testing/sysfs-class-pwm +++ b/Documentation/ABI/testing/sysfs-class-pwm | |||
@@ -77,3 +77,12 @@ Description: | |||
77 | Enable/disable the PWM signal. | 77 | Enable/disable the PWM signal. |
78 | 0 is disabled | 78 | 0 is disabled |
79 | 1 is enabled | 79 | 1 is enabled |
80 | |||
81 | What: /sys/class/pwm/pwmchipN/pwmX/capture | ||
82 | Date: June 2016 | ||
83 | KernelVersion: 4.8 | ||
84 | Contact: Lee Jones <lee.jones@linaro.org> | ||
85 | Description: | ||
86 | Capture information about a PWM signal. The output format is a | ||
87 | pair unsigned integers (period and duty cycle), separated by a | ||
88 | single space. | ||
diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c index d98599249a05..c3b1b563480e 100644 --- a/drivers/pwm/sysfs.c +++ b/drivers/pwm/sysfs.c | |||
@@ -208,16 +208,33 @@ static ssize_t polarity_store(struct device *child, | |||
208 | return ret ? : size; | 208 | return ret ? : size; |
209 | } | 209 | } |
210 | 210 | ||
211 | static ssize_t capture_show(struct device *child, | ||
212 | struct device_attribute *attr, | ||
213 | char *buf) | ||
214 | { | ||
215 | struct pwm_device *pwm = child_to_pwm_device(child); | ||
216 | struct pwm_capture result; | ||
217 | int ret; | ||
218 | |||
219 | ret = pwm_capture(pwm, &result, jiffies_to_msecs(HZ)); | ||
220 | if (ret) | ||
221 | return ret; | ||
222 | |||
223 | return sprintf(buf, "%u %u\n", result.period, result.duty_cycle); | ||
224 | } | ||
225 | |||
211 | static DEVICE_ATTR_RW(period); | 226 | static DEVICE_ATTR_RW(period); |
212 | static DEVICE_ATTR_RW(duty_cycle); | 227 | static DEVICE_ATTR_RW(duty_cycle); |
213 | static DEVICE_ATTR_RW(enable); | 228 | static DEVICE_ATTR_RW(enable); |
214 | static DEVICE_ATTR_RW(polarity); | 229 | static DEVICE_ATTR_RW(polarity); |
230 | static DEVICE_ATTR_RO(capture); | ||
215 | 231 | ||
216 | static struct attribute *pwm_attrs[] = { | 232 | static struct attribute *pwm_attrs[] = { |
217 | &dev_attr_period.attr, | 233 | &dev_attr_period.attr, |
218 | &dev_attr_duty_cycle.attr, | 234 | &dev_attr_duty_cycle.attr, |
219 | &dev_attr_enable.attr, | 235 | &dev_attr_enable.attr, |
220 | &dev_attr_polarity.attr, | 236 | &dev_attr_polarity.attr, |
237 | &dev_attr_capture.attr, | ||
221 | NULL | 238 | NULL |
222 | }; | 239 | }; |
223 | ATTRIBUTE_GROUPS(pwm); | 240 | ATTRIBUTE_GROUPS(pwm); |