UPSTREAM: pwm: sysfs: Add PWM capture support
authorLee Jones <lee.jones@linaro.org>
Wed, 8 Jun 2016 09:21:25 +0000 (10:21 +0100)
committerHuang, Tao <huangtao@rock-chips.com>
Mon, 6 Mar 2017 10:28:40 +0000 (18:28 +0800)
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>
(cherry picked from commit 1a366fe9153f445e950a7a344932b7419aa83094)

Change-Id: I86326709c373630a9189232a1cf2804a1a6ed380
Signed-off-by: David Wu <david.wu@rock-chips.com>
Documentation/ABI/testing/sysfs-class-pwm
drivers/pwm/sysfs.c

index c479d77b67c540ab6c643942d992d37d9043d1c8..c20e61354561db0b1023a4a15b4499de06958029 100644 (file)
@@ -77,3 +77,12 @@ Description:
                Enable/disable the PWM signal.
                0 is disabled
                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.
index 2cb39f17a54a716519c1c149f6e879efeb15551f..a813239300c3d46bba1320caac77ec7adc8363a8 100644 (file)
@@ -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);