Merge branch 'for-4.8/capture' into for-next
This commit is contained in:
@@ -525,6 +525,33 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *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: PWM device
|
||||
|
@@ -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, "%u %u\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);
|
||||
|
Reference in New Issue
Block a user