Commit bd268612 authored by Thierry Reding's avatar Thierry Reding

Merge branch 'for-4.8/capture' into for-next

parents 489babea 1a366fe9
...@@ -77,3 +77,12 @@ Description: ...@@ -77,3 +77,12 @@ Description:
Enable/disable the PWM signal. Enable/disable the PWM signal.
0 is disabled 0 is disabled
1 is enabled 1 is enabled
What: /sys/class/pwm/pwmchipN/pwmX/capture
Date: June 2016
KernelVersion: 4.8
Contact: Lee Jones <lee.jones@linaro.org>
Description:
Capture information about a PWM signal. The output format is a
pair unsigned integers (period and duty cycle), separated by a
single space.
...@@ -525,6 +525,33 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) ...@@ -525,6 +525,33 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
} }
EXPORT_SYMBOL_GPL(pwm_apply_state); EXPORT_SYMBOL_GPL(pwm_apply_state);
/**
* pwm_capture() - capture and report a PWM signal
* @pwm: PWM device
* @result: structure to fill with capture result
* @timeout: time to wait, in milliseconds, before giving up on capture
*
* Returns: 0 on success or a negative error code on failure.
*/
int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result,
unsigned long timeout)
{
int err;
if (!pwm || !pwm->chip->ops)
return -EINVAL;
if (!pwm->chip->ops->capture)
return -ENOSYS;
mutex_lock(&pwm_lock);
err = pwm->chip->ops->capture(pwm->chip, pwm, result, timeout);
mutex_unlock(&pwm_lock);
return err;
}
EXPORT_SYMBOL_GPL(pwm_capture);
/** /**
* pwm_adjust_config() - adjust the current PWM config to the PWM arguments * pwm_adjust_config() - adjust the current PWM config to the PWM arguments
* @pwm: PWM device * @pwm: PWM device
......
...@@ -208,16 +208,33 @@ static ssize_t polarity_store(struct device *child, ...@@ -208,16 +208,33 @@ static ssize_t polarity_store(struct device *child,
return ret ? : size; 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, "%u %u\n", result.period, result.duty_cycle);
}
static DEVICE_ATTR_RW(period); static DEVICE_ATTR_RW(period);
static DEVICE_ATTR_RW(duty_cycle); static DEVICE_ATTR_RW(duty_cycle);
static DEVICE_ATTR_RW(enable); static DEVICE_ATTR_RW(enable);
static DEVICE_ATTR_RW(polarity); static DEVICE_ATTR_RW(polarity);
static DEVICE_ATTR_RO(capture);
static struct attribute *pwm_attrs[] = { static struct attribute *pwm_attrs[] = {
&dev_attr_period.attr, &dev_attr_period.attr,
&dev_attr_duty_cycle.attr, &dev_attr_duty_cycle.attr,
&dev_attr_enable.attr, &dev_attr_enable.attr,
&dev_attr_polarity.attr, &dev_attr_polarity.attr,
&dev_attr_capture.attr,
NULL NULL
}; };
ATTRIBUTE_GROUPS(pwm); ATTRIBUTE_GROUPS(pwm);
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/of.h> #include <linux/of.h>
struct pwm_capture;
struct seq_file; struct seq_file;
struct pwm_chip; struct pwm_chip;
/** /**
...@@ -241,6 +243,7 @@ pwm_set_relative_duty_cycle(struct pwm_state *state, unsigned int duty_cycle, ...@@ -241,6 +243,7 @@ pwm_set_relative_duty_cycle(struct pwm_state *state, unsigned int duty_cycle,
* @free: optional hook for freeing a PWM * @free: optional hook for freeing a PWM
* @config: configure duty cycles and period length for this PWM * @config: configure duty cycles and period length for this PWM
* @set_polarity: configure the polarity of this PWM * @set_polarity: configure the polarity of this PWM
* @capture: capture and report PWM signal
* @enable: enable PWM output toggling * @enable: enable PWM output toggling
* @disable: disable PWM output toggling * @disable: disable PWM output toggling
* @apply: atomically apply a new PWM config. The state argument * @apply: atomically apply a new PWM config. The state argument
...@@ -260,6 +263,8 @@ struct pwm_ops { ...@@ -260,6 +263,8 @@ struct pwm_ops {
int duty_ns, int period_ns); int duty_ns, int period_ns);
int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm, int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm,
enum pwm_polarity polarity); enum pwm_polarity polarity);
int (*capture)(struct pwm_chip *chip, struct pwm_device *pwm,
struct pwm_capture *result, unsigned long timeout);
int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm); int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm);
void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm); void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm);
int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm, int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm,
...@@ -300,6 +305,16 @@ struct pwm_chip { ...@@ -300,6 +305,16 @@ struct pwm_chip {
bool can_sleep; bool can_sleep;
}; };
/**
* struct pwm_capture - PWM capture data
* @period: period of the PWM signal (in nanoseconds)
* @duty_cycle: duty cycle of the PWM signal (in nanoseconds)
*/
struct pwm_capture {
unsigned int period;
unsigned int duty_cycle;
};
#if IS_ENABLED(CONFIG_PWM) #if IS_ENABLED(CONFIG_PWM)
/* PWM user APIs */ /* PWM user APIs */
struct pwm_device *pwm_request(int pwm_id, const char *label); 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,6 +427,8 @@ static inline void pwm_disable(struct pwm_device *pwm)
} }
/* PWM provider APIs */ /* PWM provider APIs */
int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result,
unsigned long timeout);
int pwm_set_chip_data(struct pwm_device *pwm, void *data); int pwm_set_chip_data(struct pwm_device *pwm, void *data);
void *pwm_get_chip_data(struct pwm_device *pwm); void *pwm_get_chip_data(struct pwm_device *pwm);
...@@ -463,6 +480,13 @@ static inline int pwm_config(struct pwm_device *pwm, int duty_ns, ...@@ -463,6 +480,13 @@ static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
return -EINVAL; return -EINVAL;
} }
static inline int pwm_capture(struct pwm_device *pwm,
struct pwm_capture *result,
unsigned long timeout)
{
return -EINVAL;
}
static inline int pwm_set_polarity(struct pwm_device *pwm, static inline int pwm_set_polarity(struct pwm_device *pwm,
enum pwm_polarity polarity) enum pwm_polarity polarity)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment