RE: [PATCH v2] pwm: add sysfs interface

From: H Hartley Sweeten
Date: Thu May 30 2013 - 17:23:55 EST


On Thursday, May 30, 2013 12:30 PM, H Hartley Sweeten wrote:
> Add a simple sysfs interface to the generic PWM framework.
>
> /sys/class/pwm/
> `-- pwmchipN/ for each PWM chip
> |-- export (w/o) ask the kernel to export a PWM channel
> |-- npwn (r/o) number of PWM channels in this PWM chip
> |-- pwmX/ for each exported PWM channel (per PWM chip)
> | |-- duty_ns (r/w) duty cycle (in nanoseconds)
> | |-- enable (r/w) enable/disable PWM
> | |-- period_ns (r/w) period (in nanoseconds)
> | `-- polarity (r/w) polarity of PWM
> `-- unexport (w/o) return a PWM channel to the kernel
>
> Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
> Cc: Thierry Reding <thierry.reding@xxxxxxxxx>
> Cc: Lars Poeschel <poeschel@xxxxxxxxxxx>
> Cc: Ryan Mallon <rmallon@xxxxxxxx>
> Cc: Rob Landley <rob@xxxxxxxxxxx>
> ---
> v2: * add API documentation and update Documentation/pwm.txt
> * fix some issues pointed out by Ryan Mallon
> * add the pwm attributes to dev.groups so they are created
> when the device is registered for the exported PWM.
>
> Documentation/ABI/testing/sysfs-class-pwm | 80 +++++++
> Documentation/pwm.txt | 39 ++++
> drivers/pwm/Kconfig | 12 +
> drivers/pwm/Makefile | 1 +
> drivers/pwm/core.c | 25 ++-
> drivers/pwm/pwm-sysfs.c | 350 ++++++++++++++++++++++++++++++
> include/linux/pwm.h | 28 +++
> 7 files changed, 533 insertions(+), 2 deletions(-)
> create mode 100644 Documentation/ABI/testing/sysfs-class-pwm
> create mode 100644 drivers/pwm/pwm-sysfs.c

<snip>

> diff --git a/drivers/pwm/pwm-sysfs.c b/drivers/pwm/pwm-sysfs.c

<snip>

> +void pwmchip_sysfs_export(struct pwm_chip *chip)
> +{
> + /*
> + * If device_create() fails the pwm_chip is still usable by
> + * the kernel its just not exported.
> + */
> + chip->dev = device_create(&pwm_class, chip->dev, MKDEV(0, 0), chip,
> + "pwmchip%d", chip->base);
> +}

I just realized this will not work.

chip->dev is initialized by the PWM driver before calling pwmchip_add().

I'll post a v3 shortly.

Regards,
Hartley

N‹§²æìr¸›yúèšØb²X¬¶ÇvØ^–)Þ{.nÇ+‰·¥Š{±‘êçzX§¶›¡Ü}©ž²ÆzÚ&j:+v‰¨¾«‘êçzZ+€Ê+zf£¢·hšˆ§~†­†Ûiÿûàz¹®w¥¢¸?™¨è­Ú&¢)ßf”ù^jÇy§m…á@A«a¶Úÿ 0¶ìh®å’i