linux-4.9-at91
the PWM could be configured using the new Linux PWM framework support called atomic PWM. This allow changing the PWM parameters without the need of disable and re-enable the correspondent PWM channel.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
make menuconfig Device drivers -> Pulse-Width Modulation (PWM) SupportTo enable the SAMA5D2 PWM driver just enable the CONFIG_PWM_ATMEL flag:
make menuconfig Device drivers -> Pulse-Width Modulation (PWM) Support -> Atmel PWM support
/sys/class/pwm/*The PWM chips which are present in the system are listed in
/sys/class/pwm
root@sama5d2-xplained:~# ls -l /sys/class/pwm/ total 0 lrwxrwxrwx 1 root root 0 Jun 6 16:06 pwmchip0 -> ../../devices/platform/ahb/ahb:apb/f802c000.pwm/pwm/pwmchip0The presence of
pwmchip0
suggest that there is one PWM chip on the system.
npwm
file could be used.
For instance, to check how many PWM channels supports PWM chip pwmchip0
above the following command could be used:
root@sama5d2-xplained:~# cat /sys/class/pwm/pwmchip0/npwm 4This means
pwmchip0
supports 4 PWM channels.
/sys/class/pwm/pwmchipX/export
file.
root@sama5d2-xplained:~# echo 2 > /sys/class/pwm/pwmchip0/exportAfter that, the PWM 2 channel is exported in sysfs and it’s parameters could be changed.
root@sama5d2-xplained:~# ls -l /sys/class/pwm/pwmchip0/ total 0 lrwxrwxrwx 1 root root 0 Jun 6 15:17 device -> ../../../f802c000.pwm --w------- 1 root root 4096 Jun 6 15:16 export -r--r--r-- 1 root root 4096 Jun 6 15:17 npwm drwxr-xr-x 2 root root 0 Jun 6 15:17 power drwxr-xr-x 3 root root 0 Jun 6 15:17 pwm2 lrwxrwxrwx 1 root root 0 Jun 6 15:17 subsystem -> ../../../../../../../class/pwm -rw-r--r-- 1 root root 4096 Jun 6 15:15 uevent --w------- 1 root root 4096 Jun 6 15:17 unexport root@sama5d2-xplained:~# ls -l /sys/class/pwm/pwmchip0/pwm2/ total 0 -r--r--r-- 1 root root 4096 Jun 6 15:18 capture -rw-r--r-- 1 root root 4096 Jun 6 15:18 duty_cycle -rw-r--r-- 1 root root 4096 Jun 6 15:18 enable -rw-r--r-- 1 root root 4096 Jun 6 15:18 period -rw-r--r-- 1 root root 4096 Jun 6 15:18 polarity drwxr-xr-x 2 root root 0 Jun 6 15:18 power -rw-r--r-- 1 root root 4096 Jun 6 15:18 ueventA new fresh exported signal has the following parameters:
period = 0
duty_cycle = 0
polarity = normal
enable = 0
cat
on the files from /sys/class/pwm/pwmchipX/pwmY
will print these values.
TIPS:: The capture
file could be used to capture the PWM signal. The Atmel products doesn’t support this feature.
period
file.
For instance, to configure a 0.5 seconds period for PWM 2 channel use the following command:
echo 500000000 > /sys/class/pwm/pwmchip0/pwm2/period
duty_cycle
file.
For instance, to configure a 0.25 seconds duty cycle for PWM 2 channel use the following command:
echo 250000000 > /sys/class/pwm/pwmchip0/pwm2/duty_cycle
normal
and inversed
polarities for PWM signals.
To configure signal polarity for a PWM channel write one of these strings to polarity
file.
For instance, to configure inversed
polarity for PWM 2 channel use the following command:
echo inversed > /sys/class/pwm/pwmchip0/pwm2/polarity
1
or a 0
in the enable file.
For instance, to enable PWM 2 channel use the following command:
echo 1 > /sys/class/pwm/pwmchip0/pwm2/enableBelow is a picture with PWM signals (PWMH and PWML) on PWM channel 2, configured with above parameters, on SAMA5D2 Xplained board: After a channel was exported and configured its parameters could be changed. Starting with
linux-4.9-at91
the parameters could be changed on the fly. With version below linux-4.9-at91
, if a PWM channel was exported and configured a new configuration imply to first disable the channel, reconfigure and then re-enable it.
pwms
binding.
For instance, the PWM regulator could request PWM channel 2 using the following device tree bindings:
pwm_regulator { compatible = "pwm-regulator"; pwms = <&pwm0 2 500000000 0>; regulator-name = "PWM_REGULATOR"; regulator-min-microvolt = <0>; regulator-max-microvolt = <3300000>; regulator-always-on; };- the first parameter of
pwms
binding specify the label of PWM controller in device tree 0 = normal
, 1 = inversed
) /sys/kernel/debug
which could be used to see the state of PWM channels.
root@sama5d2-xplained:~# cat /sys/kernel/debug/pwm platform/f802c000.pwm, 4 PWM devices pwm-0 ((null) ): period: 0 ns duty: 0 ns polarity: normal mode: complementary trigger: none pwm-1 ((null) ): period: 0 ns duty: 0 ns polarity: normal mode: complementary trigger: none pwm-2 (sysfs ): requested enabled period: 500000000 ns duty: 250000000 ns polarity: normal pwm-3 ((null) ): period: 0 ns duty: 0 ns polarity: normal mode: complementary trigger: none-- Claudiu Beznea - 2017-07-03
|
|||||||||||||||
Copyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.
Microchip and others, are registered trademarks or trademarks of Microchip Technology Inc. and its subsidiaries.
Arm® and others are registered trademarks or trademarks of Arm Limited (or its affiliates). Other terms and product names may be trademarks of others.
Ideas, requests, contributions ? Connect to LinksToCommunities page.