aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Reding <thierry.reding@gmail.com>2016-07-25 10:23:39 -0400
committerThierry Reding <thierry.reding@gmail.com>2016-07-25 10:23:39 -0400
commitbd2686122d3b45db1398776921bd47fedfd6d6a5 (patch)
treea4c9e124eefb9da5434e39f628ee732a597d30c5
parent489babeae6b9386af25fe6dc3bc727a51ff5d962 (diff)
parent1a366fe9153f445e950a7a344932b7419aa83094 (diff)
Merge branch 'for-4.8/capture' into for-next
-rw-r--r--Documentation/ABI/testing/sysfs-class-pwm9
-rw-r--r--drivers/pwm/core.c27
-rw-r--r--drivers/pwm/sysfs.c17
-rw-r--r--include/linux/pwm.h24
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
81What: /sys/class/pwm/pwmchipN/pwmX/capture
82Date: June 2016
83KernelVersion: 4.8
84Contact: Lee Jones <lee.jones@linaro.org>
85Description:
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)
526EXPORT_SYMBOL_GPL(pwm_apply_state); 526EXPORT_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 */
536int 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}
553EXPORT_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
211static 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
211static DEVICE_ATTR_RW(period); 226static DEVICE_ATTR_RW(period);
212static DEVICE_ATTR_RW(duty_cycle); 227static DEVICE_ATTR_RW(duty_cycle);
213static DEVICE_ATTR_RW(enable); 228static DEVICE_ATTR_RW(enable);
214static DEVICE_ATTR_RW(polarity); 229static DEVICE_ATTR_RW(polarity);
230static DEVICE_ATTR_RO(capture);
215 231
216static struct attribute *pwm_attrs[] = { 232static 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};
223ATTRIBUTE_GROUPS(pwm); 240ATTRIBUTE_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
8struct pwm_capture;
8struct seq_file; 9struct seq_file;
10
9struct pwm_chip; 11struct 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 */
313struct 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 */
305struct pwm_device *pwm_request(int pwm_id, const char *label); 320struct 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 */
430int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result,
431 unsigned long timeout);
415int pwm_set_chip_data(struct pwm_device *pwm, void *data); 432int pwm_set_chip_data(struct pwm_device *pwm, void *data);
416void *pwm_get_chip_data(struct pwm_device *pwm); 433void *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
483static inline int pwm_capture(struct pwm_device *pwm,
484 struct pwm_capture *result,
485 unsigned long timeout)
486{
487 return -EINVAL;
488}
489
466static inline int pwm_set_polarity(struct pwm_device *pwm, 490static inline int pwm_set_polarity(struct pwm_device *pwm,
467 enum pwm_polarity polarity) 491 enum pwm_polarity polarity)
468{ 492{