I.MX6 PWM: Difference between revisions
(Created page with "The PWM controller is accessed through the Linux driver. This will require modifying the kernel or device tree. See the #Compile the Kernel section to get a build enviro...") |
m (Links auto-updated for 2022 re-branding ( https://github.com/embeddedarm/linux-3.10.17-imx6/blob/imx_4.1.15_1.0.0_ga/arch/arm/boot/dts/imx6qdl-ts4900-ts8390.dtsi#L256 → https://github.com/embeddedTS/linux-3.10.17-imx6/blob/imx_4.1.15_1.0.0_ga/arch/arm/boot/dts/imx6qdl-ts4900-ts8390.dtsi#L256)) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
The PWM controller is accessed through the Linux driver. | The PWM controller is accessed through the Linux driver. PWM is available on these pins: | ||
* CN1_19 (channel 1) (LCD Data 8) | |||
* CN1_21 (channel 2) (LCD Data 9) | |||
* CN2_74 (channel 2) (replaces USB_OTG_ID) | |||
* CN1_57 (channel 3) | |||
In this case this is the PWM on the TS-4900 on CN1_57. First the pin must be configured to be PWM and not a GPIO. Add the pinctrl_pwm3 after the imx-ts4900 {: | This will require modifying the kernel or device tree to set up these pins as PWM. See the [[#Compile the Kernel]] section to get a build environment working. You will then need to modify either a baseboard specific device tree, or the fallback arch/arm/boot/dts/imx6qdl-ts4900.dtsi. This example will assume the latter. | ||
In this case this is the example PWM channel 3 on the TS-4900 on CN1_57. First the pin must be configured to be PWM and not a GPIO. Add the pinctrl_pwm3 after the imx-ts4900 {: | |||
<source lang=javascript> | <source lang=javascript> | ||
iomuxc { | iomuxc { | ||
Line 14: | Line 20: | ||
}; | }; | ||
</source> | </source> | ||
The MX6QDL_PAD_SD4_DAT1__PWM3_OUT pad name comes from imx6q-pinfunc.h (or imx6dl-pinfunc.h). The format follows MX6QDL_PAD_<CPU Pad Name>__<Function of that pad>. This specifies SD4_DAT1 to be used as PWM3's output. | |||
At the end of the file enable the PWM controller, and point at this pinctrl: | At the end of the file enable the PWM controller, and point at this pinctrl: | ||
Line 23: | Line 31: | ||
}; | }; | ||
</source> | </source> | ||
This will attach a driver to actually drive that pin that is now configured for PWM. After rebuilding and installing this device tree you will now have a directory "/sys/class/pwm/pwmchip0". This can be used to control the PWM. | |||
After rebuilding and installing this device tree you will now have a directory "/sys/class/pwm/pwmchip0". This can be used to control the PWM. | |||
<source lang=bash> | <source lang=bash> | ||
# Each PWM controller has "1" pwm which will be pwm channel 0 | # Each PWM controller has "1" pwm which will be pwm channel 0 | ||
Line 54: | Line 61: | ||
</source> | </source> | ||
A common use of the PWM is for backlight control which is specified in the device tree. Our TS-TPC-8390 [https://github.com/ | A common use of the PWM is for backlight control which is specified in the device tree. Our TS-TPC-8390 [https://github.com/embeddedTS/linux-3.10.17-imx6/blob/imx_4.1.15_1.0.0_ga/arch/arm/boot/dts/imx6qdl-ts4900-ts8390.dtsi#L256 baseboard device tree] can be used as an example. | ||
In addition to setting up the PWM as demonstrated above, the PWM is connected to the pwm-backlight driver. | In addition to setting up the PWM as demonstrated above, the PWM is connected to the pwm-backlight driver. | ||
Line 66: | Line 73: | ||
}; | }; | ||
</source> | </source> | ||
This specifies PWM3 to run | This specifies PWM3 to run with 5000000 ns periods (200hz) with duty cycles specified in brightness-levels up to 255. This example creates 8 levels of brightness for the backlight, but more duty cycles can be added if more levels are needed. |
Latest revision as of 16:34, 17 January 2022
The PWM controller is accessed through the Linux driver. PWM is available on these pins:
- CN1_19 (channel 1) (LCD Data 8)
- CN1_21 (channel 2) (LCD Data 9)
- CN2_74 (channel 2) (replaces USB_OTG_ID)
- CN1_57 (channel 3)
This will require modifying the kernel or device tree to set up these pins as PWM. See the #Compile the Kernel section to get a build environment working. You will then need to modify either a baseboard specific device tree, or the fallback arch/arm/boot/dts/imx6qdl-ts4900.dtsi. This example will assume the latter.
In this case this is the example PWM channel 3 on the TS-4900 on CN1_57. First the pin must be configured to be PWM and not a GPIO. Add the pinctrl_pwm3 after the imx-ts4900 {:
iomuxc {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_hog>;
imx6-ts4900 {
pinctrl_pwm3: pwm3grp {
fsl,pins = <
MX6QDL_PAD_SD4_DAT1__PWM3_OUT 0x1b088
>;
};
The MX6QDL_PAD_SD4_DAT1__PWM3_OUT pad name comes from imx6q-pinfunc.h (or imx6dl-pinfunc.h). The format follows MX6QDL_PAD_<CPU Pad Name>__<Function of that pad>. This specifies SD4_DAT1 to be used as PWM3's output.
At the end of the file enable the PWM controller, and point at this pinctrl:
&pwm3 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_pwm3>;
status = "okay";
};
This will attach a driver to actually drive that pin that is now configured for PWM. After rebuilding and installing this device tree you will now have a directory "/sys/class/pwm/pwmchip0". This can be used to control the PWM.
# Each PWM controller has "1" pwm which will be pwm channel 0
echo 0 > /sys/class/pwm/pwmchip0/export
This will create a pwm0 directory under pwmchip0 which has these files:
period | Total period, inactive and active time in the PWM cycle specified in nanoseconds. |
duty_cycle | Active time of the PWM signal specified in nanoseconds. Must be less than the period. |
enable | Write 1 to enable, 0 to disable |
polarity | When the pwm is disabled this can be written as "normal" for default behavior or "inversed" to invert the signal. |
As an example, this will set a 50khz signal with 50 percent duty cycle.
# 20us is the period for 50khz
echo 20000 > /sys/class/pwm/pwmchip0/pwm0/period
echo 10000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
A common use of the PWM is for backlight control which is specified in the device tree. Our TS-TPC-8390 baseboard device tree can be used as an example.
In addition to setting up the PWM as demonstrated above, the PWM is connected to the pwm-backlight driver.
backlight_lcd {
compatible = "pwm-backlight";
pwms = <&pwm3 0 5000000>;
brightness-levels = <0 128 140 160 180 200 220 240 255>;
default-brightness-level = <8>;
power-supply = <®_3p3v>;
};
This specifies PWM3 to run with 5000000 ns periods (200hz) with duty cycles specified in brightness-levels up to 255. This example creates 8 levels of brightness for the backlight, but more duty cycles can be added if more levels are needed.