Translations:GPIO资源/1/en

From WRTnode Wiki
Jump to: navigation, search

WRTnode1 GPIO

Reference mt7620n Datasheet to obtain WRTnode1 GPIO details
Reference mt7688 Datasheet to obtain WRTnode2 GPIO details

WRTnode1 GPIO multiplexing pin definition

According mt7620 datasheet in GPIO pin share schemes and WRTnode gpio pins feature can be used to customize the gpio pin marked as shown below:
GPIO pin share schemes
GPIO1.png
GPIO2.png
Note: the red box is available for the release of the GPIO multiplexing pin.

DTS

Register GPIO in mt7620n.dtsi
We assume that $(TOPDIR) for OpenWrt of compile directory.
Register GPIO in mt7620n.dtsi.The mt7620n.dtsi path is$(TOPDIR)/target/linux/ramips/dts/.
Note: The combination of mt7620 datasheet in GPIO pin share schemes and in mt7620n.dtsi where we see the GPIO#0 to GPIO#72 (middle just do GPO or GPI's) are divided into four groups GPIO0-GPIO3;
GPIO0 includes from GPIO#0 to GPIO#23, a total of 24;
GPIO1 includes from GPIO#24 to GPIO#39, a total of 16;
GPIO2 includes from GPIO#40 to GPIO#71, a total of 32;
GPIO3 includes GPIO#72, only one.
Usergpio1.png
GPIO3.png
GPIO4.png

Registered led and key device

If you want to use the GPIO interface, you must first enable the GPIO and release the GPIO pin multiplexing function:

Enable GPIO

GPIO5.png

Release gpio pin alternate function:

GPIO6.png
Definition pin multiplexing in $(TOPDIR)/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620n/linux-3.10.28/arch/mips/ralink/mt7620.c
Note: The path is not necessarily for this, according to your own kernel version, linux-3.10.xx GPIO7.png
In the same way, the other multiplexed pins are defined as the same.
GPIO8.png

Registered device in WRTNODE.dts

vim $(TOPDIR)/target/linux/ramips/dts/WRTNODE.dts

Note: dts registered in the device is very simple, such as registration gpio-leds is, compatible with Led to drive leds-gpio.c in compatible correspondence, label is the name of the device, the device registration is successful, the file system will be under WRTnode there are /sys/class/leds/wrtnode:blue:wan, we can look commands to control the light off.

echo 1 > /sys/class/leds/wrtnode\:blue\:wan/brightness
echo 0 > /sys/class/leds/wrtnode\:blue\:wan/brightness  

gpios = <& gpio2 0 1>, which is designated corresponding gpio pins (GPIO#40)
GPIO9.png

WRTnode2R/2P GPIO

GPIO multiplexing pin definition

GPIO pin share schemes

2R-GPIO1.png
2R-GPIO3.png
2R-GPIO2.png
Register GPIO in mt7628an.dtsi
A total of three groups of GPIO.
2R-GPIO4.png
Each GPIO contains 32 GPIO; in the WRTnode2R/2P only to the two groups of gpio0 and gpio1.

Add led and buttons

Registered device

vim $(TOPDIR)/target/linux/ramips/dts/WRTNODE2R.dts

or

vim $(TOPDIR)/target/linux/ramips/dts/WRTNODE2P.dts

Then add the following code.

         gpio-leds {
                compatible = "gpio-leds";
                indicator {
                label = "wrtnode:blue:indicator";
                gpios = <&gpio1 12 0>;
                };
          };	
          gpio-keys-polled {
		compatible = "gpio-keys-polled";
	 	#address-cells = <1>;
		#size-cells = <0>;
		poll-interval = <20>;
		reset {
			label = "reset";
			gpios = <&gpio0 5 1>;
			linux,code = <0x198>;
		};
	};

Select driver

LED driver

Kernel modules  ---> LED modules    ---> <*> kmod-leds-gpio.......................................... GPIO LED support
                                         <*> kmod-ledtrig-usbdev............................... LED USB device Trigger

Key driver

Kernel modules  --->Input modules   ---> <*>kmod-input-polldev........................... Polled Input device support
                                         -*- kmod-input-polldev........................... Polled Input device support
                                         -*- kmod-input-polldev........................... Polled Input device support

If you are not registered success, you can view the mt7620.c, modify the code:
Original code:
̩$(TOPDIR)/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.18.20/arch/mips/ralink

static struct rt2880_pmx_func wled_kn_grp_mt7628[] = {
	FUNC("rsvd", 3, 35, 1),
	FUNC("rsvd", 2, 35, 1),
	FUNC("gpio", 1, 35, 1),
	FUNC("wled_kn", 0, 35, 1),
};

Modified GPIO pin:

static struct rt2880_pmx_func wled_kn_grp_mt7628[] = {
	FUNC("rsvd", 3, 44, 1),
	FUNC("rsvd", 2, 44, 1),
	FUNC("gpio", 1, 44, 1),
	FUNC("wled_kn", 0, 44, 1),
};