diff options
author | Thierry Reding <thierry.reding@gmail.com> | 2016-07-25 10:23:39 -0400 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2016-07-25 10:23:39 -0400 |
commit | bd2686122d3b45db1398776921bd47fedfd6d6a5 (patch) | |
tree | a4c9e124eefb9da5434e39f628ee732a597d30c5 | |
parent | 489babeae6b9386af25fe6dc3bc727a51ff5d962 (diff) | |
parent | 1a366fe9153f445e950a7a344932b7419aa83094 (diff) |
Merge branch 'for-4.8/capture' into for-next
-rw-r--r-- | Documentation/ABI/testing/sysfs-class-pwm | 9 | ||||
-rw-r--r-- | drivers/pwm/core.c | 27 | ||||
-rw-r--r-- | drivers/pwm/sysfs.c | 17 | ||||
-rw-r--r-- | include/linux/pwm.h | 24 |
4 files changed, 77 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/core.c b/drivers/pwm/core.c index ed337a8c34ab..0dbd29e287db 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c | |||
@@ -526,6 +526,33 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) | |||
526 | EXPORT_SYMBOL_GPL(pwm_apply_state); | 526 | EXPORT_SYMBOL_GPL(pwm_apply_state); |
527 | 527 | ||
528 | /** | 528 | /** |
529 | * pwm_capture() - capture and report a PWM signal | ||
530 | * @pwm: PWM device | ||
531 | * @result: structure to fill with capture result | ||
532 | * @timeout: time to wait, in milliseconds, before giving up on capture | ||
533 | * | ||
534 | * Returns: 0 on success or a negative error code on failure. | ||
535 | */ | ||
536 | int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result, | ||
537 | unsigned long timeout) | ||
538 | { | ||
539 | int err; | ||
540 | |||
541 | if (!pwm || !pwm->chip->ops) | ||
542 | return -EINVAL; | ||
543 | |||
544 | if (!pwm->chip->ops->capture) | ||
545 | return -ENOSYS; | ||
546 | |||
547 | mutex_lock(&pwm_lock); | ||
548 | err = pwm->chip->ops->capture(pwm->chip, pwm, result, timeout); | ||
549 | mutex_unlock(&pwm_lock); | ||
550 | |||
551 | return err; | ||
552 | } | ||
553 | EXPORT_SYMBOL_GPL(pwm_capture); | ||
554 | |||
555 | /** | ||
529 | * pwm_adjust_config() - adjust the current PWM config to the PWM arguments | 556 | * pwm_adjust_config() - adjust the current PWM config to the PWM arguments |
530 | * @pwm: PWM device | 557 | * @pwm: PWM device |
531 | * | 558 | * |
diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c index 01695d48dd54..18ed725594c3 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); |
diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 47e66bfb8cb4..f1bbae014889 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h | |||
@@ -5,7 +5,9 @@ | |||
5 | #include <linux/mutex.h> | 5 | #include <linux/mutex.h> |
6 | #include <linux/of.h> | 6 | #include <linux/of.h> |
7 | 7 | ||
8 | struct pwm_capture; | ||
8 | struct seq_file; | 9 | struct seq_file; |
10 | |||
9 | struct pwm_chip; | 11 | struct pwm_chip; |
10 | 12 | ||
11 | /** | 13 | /** |
@@ -241,6 +243,7 @@ pwm_set_relative_duty_cycle(struct pwm_state *state, unsigned int duty_cycle, | |||
241 | * @free: optional hook for freeing a PWM | 243 | * @free: optional hook for freeing a PWM |
242 | * @config: configure duty cycles and period length for this PWM | 244 | * @config: configure duty cycles and period length for this PWM |
243 | * @set_polarity: configure the polarity of this PWM | 245 | * @set_polarity: configure the polarity of this PWM |
246 | * @capture: capture and report PWM signal | ||
244 | * @enable: enable PWM output toggling | 247 | * @enable: enable PWM output toggling |
245 | * @disable: disable PWM output toggling | 248 | * @disable: disable PWM output toggling |
246 | * @apply: atomically apply a new PWM config. The state argument | 249 | * @apply: atomically apply a new PWM config. The state argument |
@@ -260,6 +263,8 @@ struct pwm_ops { | |||
260 | int duty_ns, int period_ns); | 263 | int duty_ns, int period_ns); |
261 | int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm, | 264 | int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm, |
262 | enum pwm_polarity polarity); | 265 | enum pwm_polarity polarity); |
266 | int (*capture)(struct pwm_chip *chip, struct pwm_device *pwm, | ||
267 | struct pwm_capture *result, unsigned long timeout); | ||
263 | int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm); | 268 | int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm); |
264 | void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm); | 269 | void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm); |
265 | int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm, | 270 | int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm, |
@@ -300,6 +305,16 @@ struct pwm_chip { | |||
300 | bool can_sleep; | 305 | bool can_sleep; |
301 | }; | 306 | }; |
302 | 307 | ||
308 | /** | ||
309 | * struct pwm_capture - PWM capture data | ||
310 | * @period: period of the PWM signal (in nanoseconds) | ||
311 | * @duty_cycle: duty cycle of the PWM signal (in nanoseconds) | ||
312 | */ | ||
313 | struct pwm_capture { | ||
314 | unsigned int period; | ||
315 | unsigned int duty_cycle; | ||
316 | }; | ||
317 | |||
303 | #if IS_ENABLED(CONFIG_PWM) | 318 | #if IS_ENABLED(CONFIG_PWM) |
304 | /* PWM user APIs */ | 319 | /* PWM user APIs */ |
305 | struct pwm_device *pwm_request(int pwm_id, const char *label); | 320 | struct pwm_device *pwm_request(int pwm_id, const char *label); |
@@ -412,6 +427,8 @@ static inline void pwm_disable(struct pwm_device *pwm) | |||
412 | } | 427 | } |
413 | 428 | ||
414 | /* PWM provider APIs */ | 429 | /* PWM provider APIs */ |
430 | int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result, | ||
431 | unsigned long timeout); | ||
415 | int pwm_set_chip_data(struct pwm_device *pwm, void *data); | 432 | int pwm_set_chip_data(struct pwm_device *pwm, void *data); |
416 | void *pwm_get_chip_data(struct pwm_device *pwm); | 433 | void *pwm_get_chip_data(struct pwm_device *pwm); |
417 | 434 | ||
@@ -463,6 +480,13 @@ static inline int pwm_config(struct pwm_device *pwm, int duty_ns, | |||
463 | return -EINVAL; | 480 | return -EINVAL; |
464 | } | 481 | } |
465 | 482 | ||
483 | static inline int pwm_capture(struct pwm_device *pwm, | ||
484 | struct pwm_capture *result, | ||
485 | unsigned long timeout) | ||
486 | { | ||
487 | return -EINVAL; | ||
488 | } | ||
489 | |||
466 | static inline int pwm_set_polarity(struct pwm_device *pwm, | 490 | static inline int pwm_set_polarity(struct pwm_device *pwm, |
467 | enum pwm_polarity polarity) | 491 | enum pwm_polarity polarity) |
468 | { | 492 | { |