Using the PWM sysfs user space interface

The PWM sysfs at startup interface will create a directory called /sys/class/pwm/pwmchip0.

For any PWM line you want to use you have to export it.

~# echo 0 > /sys/class/pwm/pwmchip0/export
~# echo 1 > /sys/class/pwm/pwmchip0/export
~# echo 2 > /sys/class/pwm/pwmchip0/export
~# echo 3 > /sys/class/pwm/pwmchip0/export
...

To use again that line ad generic GPIO you can unexport it:

~# echo 0 > /sys/class/pwm/pwmchip0/unexport
~# echo 1 > /sys/class/pwm/pwmchip0/unexport
~# echo 2 > /sys/class/pwm/pwmchip0/unexport
~# echo 3 > /sys/class/pwm/pwmchip0/unexport
...

For any exported channel a directory called pwmX wil be created with the following structure:

/sys/class/pwm/pwmchip0/pwmX/
      |-- duty_cycle (r/w) duty cycle (in nanoseconds)
      |-- enable     (r/w) enable/disable PWM
      |-- period     (r/w) period (in nanoseconds)
      |-- polarity   (r/w) polarity of PWM
      |-- power
      `-- uevent

The follow example illustrate how enable a PWM signale with a period of 1mS with a 0.5mS of duty cycle:

~# echo 1000000 > /sys/class/pwm/pwmchip0/pwm0/period
~# echo 500000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
~# echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable