TS-7970 PWM: Difference between revisions

From embeddedTS Manuals
(Created page with "The CPU exposes one PWM on HD1_IRQ (HD1 pin 21). By default, this pin is a GPIO which is used as an interrupt for daughter cards. To use this as PWM a modification to the de...")
 
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))
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
The CPU exposes one PWM on HD1_IRQ (HD1 pin 21).  By default, this pin is a GPIO which is used as an interrupt for daughter cards.  To use this as PWM a modification to the device tree will be required.  See the [[#Compile the Kernel]] section to get a build environment working.  You will then need to modify arch/arm/boot/dts/imx6qdl-ts7970.dtsi.
The CPU exposes one PWM on HD1_IRQ (HD1 pin 21).  By default, this pin is a GPIO which is used as an interrupt for daughter cards.  To use this as PWM a modification to the device tree will be required.  See the [[#Compile the Kernel]] section to get a build environment working.  The file "arch/arm/boot/dts/imx6qdl-ts7970.dtsi" will need to be modified.


First the pin must be configured to be PWM and not a GPIO.  Find the line:
First the pin must be configured to be PWM and not a GPIO.  Find the line:
   MX6QDL_PAD_DISP0_DAT9__GPIO4_IO30 0x1b088 /* HD1_IRQ */
   MX6QDL_PAD_DISP0_DAT9__GPIO4_IO30 0x1b088 /* HD1_IRQ */
and remoe this.
and remove it.


Add the pinctrl_pwm2 after the imx-ts4900 {:
Add the "pinctrl_pwm2" block below as a new section in the "imx6-ts7970" section:
<source lang=javascript>
<source lang=javascript>
iomuxc {
iomuxc {
Line 19: Line 19:
</source>
</source>


The MX6QDL_PAD_DISP0_DAT9__PWM2_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 DISP0_DAT9 to be used as PWM2's output.
The "MX6QDL_PAD_DISP0_DAT9__PWM2_OUT" pad name comes from "imx6q-pinfunc.h" or "imx6dl-pinfunc.h" files.  The format follows "MX6QDL_PAD_<CPU Pad Name>__<Function of that pad>".  This specifies that the pad "DISP0_DAT9" to be used as PWM2's output.


At the end of the file enable the PWM controller, and point at this pinctrl:
At the end of the file, add the following block which enables the PWM controller and connects the iomuxc pinctrl created above:
<source lang=javascript>
<source lang=javascript>
&pwm2 {
&pwm2 {
pinctrl-names = "default";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_pwm3>;
pinctrl-0 = <&pinctrl_pwm2>;
status = "okay";
status = "okay";
};
};
</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 updated device tree, the directory "/sys/class/pwm/pwmchip0/" will be available to control the PWM as outlined below.
<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 35: Line 37:
</source>
</source>


This will create a pwm0 directory under pwmchip0 which has these files:
 
This will create a "pwm0/" directory under "pwmchip0/" which has the following files:
{| class=wikitable
{| class=wikitable
|-
|-
Line 51: Line 54:
|}
|}


As an example, this will set a 50khz signal with 50 percent duty cycle.
As an example, this will set a 50 khz signal with a 50% duty cycle.
<source lang=bash>
<source lang=bash>
# 20us is the period for 50khz
# 20us is the period for 50khz
Line 59: Line 62:
</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/embeddedarm/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.
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.

Latest revision as of 17:26, 17 January 2022

The CPU exposes one PWM on HD1_IRQ (HD1 pin 21). By default, this pin is a GPIO which is used as an interrupt for daughter cards. To use this as PWM a modification to the device tree will be required. See the #Compile the Kernel section to get a build environment working. The file "arch/arm/boot/dts/imx6qdl-ts7970.dtsi" will need to be modified.

First the pin must be configured to be PWM and not a GPIO. Find the line:

 MX6QDL_PAD_DISP0_DAT9__GPIO4_IO30	0x1b088 /* HD1_IRQ */

and remove it.

Add the "pinctrl_pwm2" block below as a new section in the "imx6-ts7970" section:

iomuxc {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_hog>;

	imx6-ts7970 {
		pinctrl_pwm2: pwm2grp {
			fsl,pins = <
				MX6QDL_PAD_DISP0_DAT9__PWM2_OUT		0x1b088
			>;
		};

The "MX6QDL_PAD_DISP0_DAT9__PWM2_OUT" pad name comes from "imx6q-pinfunc.h" or "imx6dl-pinfunc.h" files. The format follows "MX6QDL_PAD_<CPU Pad Name>__<Function of that pad>". This specifies that the pad "DISP0_DAT9" to be used as PWM2's output.

At the end of the file, add the following block which enables the PWM controller and connects the iomuxc pinctrl created above:

&pwm2 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_pwm2>;
	status = "okay";
};


After rebuilding and installing this updated device tree, the directory "/sys/class/pwm/pwmchip0/" will be available to control the PWM as outlined below.

# 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 the following 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 50 khz signal with a 50% 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 = <&reg_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.