/sys/class/gpio/export #decide if it will be input or output echo "out" > /sys/class/gpio/gpio5/direction #last line turns GPIO on or off with 1 or 0: echo "1" > /sys/class/gpio/gpio5/value"> /sys/class/gpio/export #decide if it will be input or output echo "out" > /sys/class/gpio/gpio5/direction #last line turns GPIO on or off with 1 or 0: echo "1" > /sys/class/gpio/gpio5/value"> /sys/class/gpio/export #decide if it will be input or output echo "out" > /sys/class/gpio/gpio5/direction #last line turns GPIO on or off with 1 or 0: echo "1" > /sys/class/gpio/gpio5/value">
#make GPIO number available
echo "5" > /sys/class/gpio/export

#decide if it will be input or output
echo "out" > /sys/class/gpio/gpio5/direction

#last line turns GPIO on or off with 1 or 0:
echo "1" > /sys/class/gpio/gpio5/value

LEDs


Buttons


release/src/router/rc/init.c

		/* gpio */
		/* HW reset, 2 | LOW */
		nvram_set_int("led_pwr_gpio", 3|GPIO_ACTIVE_LOW);
#ifdef RTCONFIG_LED_BTN
		nvram_set_int("btn_led_gpio", 4|GPIO_ACTIVE_LOW);
#endif
		nvram_set_int("led_wan_gpio", 5);
		/* MDC_4709 RGMII, 6 */
		/* MDIO_4709 RGMII, 7 */
		nvram_set_int("pwr_usb_gpio", 9|GPIO_ACTIVE_LOW);
		nvram_set_int("reset_switch_gpio", 10);
		nvram_set_int("btn_rst_gpio", 11|GPIO_ACTIVE_LOW);
		/* UART1_RX,  12 */
		/* UART1_TX,  13 */
		/* UART1_CTS, 14*/
		/* UART1_RTS, 15 */
		nvram_set_int("led_usb_gpio", 16|GPIO_ACTIVE_LOW);
		nvram_set_int("led_usb3_gpio", 17|GPIO_ACTIVE_LOW);
		//nvram_set_int("led_mmc_gpio",  17|GPIO_ACTIVE_LOW);	/* abort */
		nvram_set_int("led_wps_gpio", 19|GPIO_ACTIVE_LOW);
		if(model == MODEL_RTAC5300) {
			nvram_set_int("btn_wltog_gpio", 20|GPIO_ACTIVE_LOW);
			nvram_set_int("btn_wps_gpio", 18|GPIO_ACTIVE_LOW);
			nvram_set_int("fan_gpio", 15);
			nvram_set_int("rpm_fan_gpio", 14|GPIO_ACTIVE_LOW);
		} else {
			nvram_set_int("btn_wltog_gpio", 18|GPIO_ACTIVE_LOW);
			nvram_set_int("btn_wps_gpio", 20|GPIO_ACTIVE_LOW);
		}
		nvram_set_int("led_lan_gpio", 21|GPIO_ACTIVE_LOW);	/* FAN CTRL: reserved */
		/* PA 5V/3.3V switch, 22 */
		/* SDIO_EN_1P8, 23 | HIGH */

asuswrt-merlin.ng/init.c at master · RMerl/asuswrt-merlin.ng


release/src-rt-6.x.4708/cfe/cfe/arch/common/board/bcm947xx/src/ui_bcm947xx.c

#ifdef RTL8365MB
#define SMI_SCK_GPIO	(1 << 6)	// GPIO 6
#define SMI_SDA_GPIO	(1 << 7)	// GPIO 7
#endif	/*~RTL8365MB*/

asuswrt-merlin.ng/ui_bcm947xx.c at 6b60627c8c9c5c0271e956c914afb5277f81f9c4 · RMerl/asuswrt-merlin.ng

Shell scripts used to test GPIO LEDs and buttons, fork and improve based on http://wiki.openwrt.org/doc/devel/add.new.device

LEDs

Testing [GPIO0]...
[GPIO0] Trying value 0
[GPIO0] Trying value 1

Testing [GPIO1]...
[GPIO1] Trying value 0
[GPIO1] Trying value 1

Testing [GPIO3]...
sh: write error: Resource busy
Failed to export [GPIO3]

Testing [GPIO4]...
sh: write error: Resource busy
Failed to export [GPIO4]

Testing [GPIO5]...
sh: write error: Resource busy
Failed to export [GPIO5]

Testing [GPIO6]...
[GPIO6] Trying value 0
[GPIO6] Trying value 1

Testing [GPIO7]...
[GPIO7] Trying value 0
[GPIO7] Trying value 1

Testing [GPIO8]...
[GPIO8] Trying value 0
[GPIO8] Trying value 1

Testing [GPIO9]...
sh: write error: Resource busy
Failed to export [GPIO9]

Testing [GPIO10]...
[GPIO10] Trying value 0
[GPIO10] Trying value 1

Testing [GPIO11]...
sh: write error: Resource busy
Failed to export [GPIO11]

Testing [GPIO12]...
[GPIO12] Trying value 0
[GPIO12] Trying value 1

Testing [GPIO13]...
[GPIO13] Trying value 0
[GPIO13] Trying value 1

Testing [GPIO14]...
[GPIO14] Trying value 0
[GPIO14] Trying value 1

Testing [GPIO15]...
[GPIO15] Trying value 0
[GPIO15] Trying value 1

Testing [GPIO16]...
sh: write error: Resource busy
Failed to export [GPIO16]

Testing [GPIO17]...
sh: write error: Resource busy
Failed to export [GPIO17]

Testing [GPIO18]...
sh: write error: Resource busy
Failed to export [GPIO18]

Testing [GPIO19]...
sh: write error: Resource busy
Failed to export [GPIO19]

Testing [GPIO20]...
sh: write error: Resource busy
Failed to export [GPIO20]

Testing [GPIO21]...
sh: write error: Resource busy
Failed to export [GPIO21]

Testing [GPIO22]...
[GPIO22] Trying value 0
[GPIO22] Trying value 1

Testing [GPIO23]...
[GPIO23] Trying value 0
[GPIO23] Trying value 1

Testing [GPIO24]...
[GPIO24] Trying value 0
[GPIO24] Trying value 1

Testing [GPIO25]...
[GPIO25] Trying value 0
[GPIO25] Trying value 1

Testing [GPIO26]...
sh: write error: Resource busy
[GPIO26] Trying value 0
[GPIO26] Trying value 1

Testing [GPIO27]...
[GPIO27] Trying value 0
[GPIO27] Trying value 1

Testing [GPIO28]...
[GPIO28] Trying value 0
[GPIO28] Trying value 1

Testing [GPIO29]...
[GPIO29] Trying value 0
[GPIO29] Trying value 1

Testing [GPIO30]...
[GPIO30] Trying value 0
[GPIO30] Trying value 1

Testing [GPIO31]...
[GPIO31] Trying value 0
[GPIO31] Trying value 1

Buttons

[GPIO0] value 0
[GPIO1] value 0
[GPIO2] value 1

sh: write error: Resource busy
Failed to export [GPIO3]

sh: write error: Resource busy
Failed to export [GPIO4]

sh: write error: Resource busy
Failed to export [GPIO5]

[GPIO6] value 1
[GPIO7] value 1
[GPIO8] value 0

sh: write error: Resource busy
Failed to export [GPIO9]

[GPIO10] value 1

sh: write error: Resource busy
Failed to export [GPIO11]

[GPIO12] value 0
[GPIO13] value 0
[GPIO14] value 0
[GPIO15] value 0

sh: write error: Resource busy
Failed to export [GPIO16]

sh: write error: Resource busy
Failed to export [GPIO17]

sh: write error: Resource busy
Failed to export [GPIO18]

sh: write error: Resource busy
Failed to export [GPIO19]

sh: write error: Resource busy
Failed to export [GPIO20]

[GPIO21] value 0
[GPIO22] value 0
[GPIO23] value 0
[GPIO24] value 0
[GPIO25] value 0
[GPIO26] value 0
[GPIO27] value 0
[GPIO28] value 0
[GPIO29] value 0
[GPIO30] value 0
[GPIO31] value 0