タグ: GPIO

OpenWrtのgpio-export関連メモ

最近投げたPRでツッコミがあったり、GPIOのexport関連がちょっと込み入った状況なので自分用にメモ。
OpenWrtプロジェクトの中でもexportの用途(RESET等)によってはどれを使うかが明確に決まっていない状況なので、どれを使うべきというのは断言できない。
本来RESETを制御するGPIOは “reset-gpios” が使用されるべきながら、OpenWrtのRTL836xドライバ等ではreset-gpiosの実装が無い(?)などのため、代替としてGPIOをexportすることで対処。

gpio-export

固定でGPIOのexportが必要な場合、OpenWrtで従来から使用されていた方法。
ただしmainline (Linux Kernel)ではrejectされており、あくまでOpenWrt独自の実装方法。

コード例

/ {
...
	gpio-export {
		compatible = "gpio-export";
		#size-cells = <0>;

		gpio_switch_reset {
			gpio-export,name = "buffalo:usb-power";
			gpio-export,output = <1>;
			gpios = <&gpio 13 GPIO_ACTIVE_HIGH>;
		};
	};
};

  

fixed-regulator

電圧固定のレギュレータ。USB Vbus用にGPIOをexportする場合はもちろんのこと、SwitchチップのRESETラインも実態としては同じように特定の電圧を流すかどうかなので、fixed-regulatorを使用してRESETライン用のexportを定義したコードもある。
しかしながら、RESETラインの場合regulatorの本来の用途とは異なるので、今はあまり推奨されない(?)
USB VBusの場合はこれを使用。

コード例

/ {
...
	reg_usb_vbus: reg_usb_vbus {
		compatible = "regulator-fixed";
		regulator-name = "usb_vbus";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		gpio = <&gpio 8 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};
};
  

gpio-hog

OpenWrtのgpio-exportに似た実装で、mainlineに既に存在するもの。
Linux source code: Documentation/devicetree/bindings/gpio/gpio.txt (v4.14.106) – Bootlin
最近投げたPRで、前述の状況からOpenWrtでの実装が定まっていないため、DTS内で記述する方法としてこちらを提案された。

コード例

&gpio {
	rtl8367rb_reset {
		gpio-hog;
		gpios = <0 GPIO_ACTIVE_HIGH>;
		output-high;
		line-name = "rtl8367rb-reset";
	};
};
  

ath9kノード内の場合

&pcie {
	status = "okay";

	ath9k: wifi@0,0 {
		compatible = "pci168c,0030";
		reg = <0x0000 0 0 0 0>;
		qca,no-eeprom;
		#gpio-cells = <2>;
		gpio-controller;

		usb-hub-reset {
			gpio-hog;
			gpios = <10 GPIO_ACTIVE_HIGH>;
			output-high;
		};
	};
};
  

gpio-hog関連ログ(WN-AC733GR3の例)

[    0.489851] rt2880_gpio 10000600.gpio: registering 24 gpios
[    0.500886] rt2880_gpio 10000600.gpio: registering 24 irq handlers
[    0.513143] GPIO line 0 (rtl8367rb-reset) hogged as output/high
  

ユーザースペースでの実装

これまで書いたDeviceTree方面の実装とは別に、ブート時に実行されるスクリプトでGPIOのexportを設定するもの。正直なところ、この方法はあまり正確に把握していないので詳細は割愛。
target/linux/ramips/base-files/etc/board.d/03_gpio_switches
などが例らしい(?)。
広告

WG1400HP GPIOメモ

WG1400HPでのGPIOのレジスタを調べたメモ。整理するのが面倒なのでテキストのメモそのまま。

boot> debug memory read 0xb8040000 70
b8040000:00a6031f 20bcee2d 0000ec00 00000000 .... ..-........
b8040010:00000000 00000000 00000000 00000000 ................
b8040020:00000000 00000000 00000000 00000000 ................
b8040030:0c080900 00160000 00000000 07000000 ................
b8040040:00000006 00000908 00000000 00000000 ................
b8040050:00000000 14130000 80808080 80808080 ................
b8040060:80808080 80808080 00000000 00000002 ................

# Output Enable
val: 0xa6031f

IN: 0, 1, 2, 3, 4, 8, 9, 17, 18, 21, 23
OUT: 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 19, 20, 22

# Input Value
val: 0x20bcee2d

INPUT=1: 0, 2, 3, 5, 9, 10, 11, 13, 14, 15, 18, 19, 20, 21, 23
INPUT=0: 1, 4, 6, 7, 8, 12, 16, 17, 22

# Output Value
val: 0xec00 (kernel: 0x40ec00)

OUTPUT=1: 10, 11, 13, 14, 15

### Used
GPIO IN: 2, 3, 8, 9, 17, 18, 19, 20, 23
GPIO OUT: 5, 6, 7, 10, 11, 22

?: 19 (FUNCTION: reserved (7))
?: 20 (FUNCTION: reserved (6))
I2C_DATA: 0x14 (20)
I2C_CLK: 0x13 (19)

WR8750N switch&GPIO

どうもSwitch (AR8327)の有効化にGPIO13が絡んでいる様なので、GPIO_OE (Output Enable)をBootloader上でGPIO13のビットを無効化した際の比較。

gpio-export無し

IPL:HARD-RESET
memory test ... ok
flinstall OK

boot version: 1.0.0

PKG "Orthos-HP"
CPU "Atheros/AR9344"
Revision 212.1 CLOCK 560.0 MHz
HEAP MEMORY 262144 bytes
Boot:InitFilesystem
phy0.1: "Atheros/AR8327(SW)"
phy0.0: "Atheros/AR8327(phy)"
active ch:0
post start
TP module load fail
post load fail [-2]

rebooting 3
key abort

welcome to boot console
Password:
boot> tftpd
tftpd start 192.168.0.1
boot> start tftp load openwrt-ath79-tiny-nec_wr8750n-i
end tftp load length = 3225264
start memory load ... 
memory load complete
  begin  : 0x80060000
  length : 3225240
  startup: 0x80060000

boot> debug memory write ?
write [byte|short|word] ADDRESS DATA
default access mode is word(32bit)
# ex) write byte 0x2000 0x10
boot> debug memory read 0xb8040000 1
b8040000:0003db1f                            ....
boot> debug memory write 0xb8040000 0x3fb1f
0xb8040000 <- 0x3fb1f
boot> debug memory read 0xb8040000 1       
b8040000:0003fb1f                            ....
boot> boot
begin  : 0x80060000
length : 3225572
startup: 0x80060000
option: 0x0


OpenWrt kernel loader for AR7XXX/AR9XXX
Copyright (C) 2011 Gabor Juhos 
Decompressing kernel... done!
Starting kernel at 80060000...

[    0.000000] Linux version 4.14.94 (jenkins@tofu-z77hvub18_openwrt) (gcc version 7.4.0 (OpenWrt GCC 7.4.0 r0+9105-9d407488e5)) #0 Wed Jan 23 08:37:31 2019
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 0001974c (MIPS 74Kc)
[    0.000000] MIPS: machine is NEC Aterm WR8750N
[    0.000000] SoC: Atheros AR9344 rev 1
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 08000000 @ 00000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 bytes
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] random: get_random_bytes called from 0x8045972c with crng_init=0
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 32512
[    0.000000] Kernel command line: console=ttyS0,9600 rootfstype=squashfs,jffs2
[    0.000000] PID hash table entries: 512 (order: -1, 2048 bytes)
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Writing ErrCtl register=00000000
[    0.000000] Readback ErrCtl register=00000000
[    0.000000] Memory: 118520K/131072K available (3450K kernel code, 138K rwdata, 472K rodata, 6684K init, 195K bss, 12552K reserved, 0K cma-reserved)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 51
[    0.000000] CPU clock: 560.000 MHz
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 6825930166 ns
[    0.000010] sched_clock: 32 bits at 280MHz, resolution 3ns, wraps every 7669584382ns
[    0.092708] Calibrating delay loop... 278.93 BogoMIPS (lpj=1394688)
[    0.237624] pid_max: default: 32768 minimum: 301
[    0.293065] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.372219] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.461148] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.578794] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.651744] pinctrl core: initialized pinctrl subsystem
[    0.715206] NET: Registered protocol family 16
[    0.769106] Can't analyze schedule() prologue at 803ba51c
[    0.836083] PCI host bridge /ahb/apb/pcie-controller@180c0000 ranges:
[    0.913158]  MEM 0x0000000010000000..0x0000000013ffffff
[    0.975617]   IO 0x0000000000000000..0x0000000000000000
[    1.055138] PCI host bridge to bus 0000:00
[    1.104102] pci_bus 0000:00: root bus resource [mem 0x10000000-0x13ffffff]
[    1.186320] pci_bus 0000:00: root bus resource [io  0x0000]
[    1.252983] pci_bus 0000:00: root bus resource [??? 0x00000000 flags 0x0]
[    1.334207] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.429520] pci 0000:00:00.0: BAR 0: assigned [mem 0x10000000-0x1001ffff 64bit]
[    1.516979] pci 0000:00:00.0: BAR 6: assigned [mem 0x10020000-0x1002ffff pref]
[    1.603966] clocksource: Switched to clocksource MIPS
[    1.665570] NET: Registered protocol family 2
[    1.718515] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[    1.801848] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    1.877834] TCP: Hash tables configured (established 1024 bind 1024)
[    1.954005] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    2.023755] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    2.098972] NET: Registered protocol family 1
[    2.286701] Crashlog allocated RAM at address 0x3f00000
[    2.350522] workingset: timestamp_bits=30 max_order=15 bucket_order=0
[    2.432600] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    2.502364] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    2.693839] io scheduler noop registered
[    2.740737] io scheduler deadline registered (default)
[    2.802483] ar7200-usb-phy usb-phy: phy reset is missing
[    2.868303] pinctrl-single 1804002c.pinmux: 544 pins at pa b804002c size 68
[    2.952737] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    3.029571] console [ttyS0] disabled
[    3.072328] 18020000.uart: ttyS0 at MMIO 0x18020000 (irq = 8, base_baud = 2500000) is a 16550A
[    3.175343] console [ttyS0] enabled
[    3.175343] console [ttyS0] enabled
[    3.258626] bootconsole [early0] disabled
[    3.258626] bootconsole [early0] disabled
[    3.360576] m25p80 spi0.0: mx25l6405d (8192 Kbytes)
[    3.418981] 5 fixed-partitions partitions found on MTD device spi0.0
[    3.495024] Creating 5 MTD partitions on "spi0.0":
[    3.552336] 0x000000000000-0x000000020000 : "u-boot"
[    3.612562] 0x000000020000-0x000000022000 : "config"
[    3.672799] 0x000000022000-0x000000030000 : "reserved"
[    3.735050] 0x000000030000-0x000000040000 : "art"
[    3.792126] 0x000000040000-0x000000800000 : "firmware"
[    3.864353] libphy: Fixed MDIO Bus: probed
[    4.244363] libphy: ag71xx_mdio: probed
[    4.290345] mdio_bus mdio-bus.0: MDIO device at address 0 is missing.
[    4.705072] ag71xx 19000000.eth: Could not connect to PHY device
[    4.778846] NET: Registered protocol family 10
[    4.835002] Segment Routing with IPv6
[    4.878892] NET: Registered protocol family 17
[    4.932402] 8021q: 802.1Q VLAN Support v1.8
[    5.017188] Freeing unused kernel memory: 6684K
[    5.071366] This architecture does not have kernel memory protection.
[    5.162176] init: Console is alive
[    5.203161] init: - watchdog -
[    5.262291] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    5.355309] usbcore: registered new interface driver usbfs
[    5.421018] usbcore: registered new interface driver hub
[    5.484657] usbcore: registered new device driver usb
[    5.551117] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    5.631012] ehci-platform: EHCI generic platform driver
[    5.693819] ehci-platform 1b000000.usb: EHCI Host Controller
[    5.761556] ehci-platform 1b000000.usb: new USB bus registered, assigned bus number 1
[    5.855294] ehci-platform 1b000000.usb: irq 3, io mem 0x1b000000
[    5.954013] ehci-platform 1b000000.usb: USB 2.0 started, EHCI 1.00
[    6.028916] hub 1-0:1.0: USB hub found
[    6.074241] hub 1-0:1.0: 1 port detected
[    6.122693] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    6.219592] init: - preinit -
[    6.472881] random: jshn: uninitialized urandom read (4 bytes read)
[    6.547943] usb 1-1: new full-speed USB device number 2 using ehci-platform
[    6.722825] random: jshn: uninitialized urandom read (4 bytes read)
[    6.916328] usb 1-1: not running at top speed; connect to a high speed hub
[    7.086201] random: procd: uninitialized urandom read (4 bytes read)
[    7.162679] hub 1-1:1.0: USB hub found
[    7.235111] hub 1-1:1.0: 4 ports detected
[    7.507891] urandom_read: 3 callbacks suppressed
[    7.507900] random: jshn: uninitialized urandom read (4 bytes read)
[    7.731573] random: jshn: uninitialized urandom read (4 bytes read)
Failed to connect to the switch. Use the "list" command to see which switches are available.
Failed to connect to the switch. Use the "list" command to see which switches are available.
Failed to connect to the switch. Use the "list" command to see which switches are available.
Failed to connect to the switch. Use the "list" command to see which switches are available.
Press the [f] key and hit [enter] to enter failsafe mode
Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level
[    9.203965] random: fast init done
[   11.066076] procd: - early -
[   11.100650] procd: - watchdog -
[   11.688297] procd: - watchdog -
[   11.726150] procd: - ubus -
[   11.767355] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.844579] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.922037] procd: - init -
Please press Enter to activate this console.
[   12.145500] kmodloader: loading kernel modules from /etc/modules.d/*
[   12.226031] ip6_tables: (C) 2000-2006 Netfilter Core Team
[   12.301139] Loading modules backported from Linux version v4.19.7-0-g61c68f2a2af0
[   12.390721] Backport generated by backports.git v4.19.7-1-0-g148b072d
[   12.470763] ip_tables: (C) 2000-2006 Netfilter Core Team
[   12.542643] nf_conntrack version 0.5.0 (2048 buckets, 8192 max)
[   12.672963] xt_time: kernel timezone is -0000
[   12.780921] PPP generic driver version 2.4.2
[   12.834609] NET: Registered protocol family 24
[   12.947620] ieee80211 phy0: Atheros AR9340 Rev:1 mem=0xb8100000, irq=11
[   13.030790] ath9k 0000:00:00.0: Direct firmware load for ath9k-eeprom-pci-0000:00:00.0.bin failed with error -2
[   13.151582] ath9k 0000:00:00.0: Falling back to user helper
[   13.637519] ieee80211 phy1: Atheros AR9300 Rev:3 mem=0xb0000000, irq=13
[   13.814381] kmodloader: done loading kernel modules from /etc/modules.d/*



BusyBox v1.30.0 () built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt SNAPSHOT, r0+9108-9d8dd1dc7a
 -----------------------------------------------------
=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
root@OpenWrt:/#

gpio-export追加後

IPL:HARD-RESET
memory test ... ok
flinstall OK

boot version: 1.0.0

PKG "Orthos-HP"
CPU "Atheros/AR9344"
Revision 212.1 CLOCK 560.0 MHz
HEAP MEMORY 262144 bytes
Boot:InitFilesystem
phy0.1: "Atheros/AR8327(SW)"
phy0.0: "Atheros/AR8327(phy)"
active ch:0
post start
TP module load fail
post load fail [-2]

rebooting 3
key abort

welcome to boot console
Password:
boot> tftpd
tftpd start 192.168.0.1
boot> start tftp load openwrt-ath79-tiny-nec_wr8750n-i
end tftp load length = 3225264
start memory load ... 
memory load complete
  begin  : 0x80060000
  length : 3225240
  startup: 0x80060000

boot> debug memory write ?
write [byte|short|word] ADDRESS DATA
default access mode is word(32bit)
# ex) write byte 0x2000 0x10
boot> debug memory read 0xb8040000 1
b8040000:0003db1f                            ....
boot> debug memory write 0xb8040000 0x3fb1f
0xb8040000 <- 0x3fb1f
boot> debug memory read 0xb8040000 1       
b8040000:0003fb1f                            ....
boot> boot
begin  : 0x80060000
length : 3225240
startup: 0x80060000
option: 0x0


OpenWrt kernel loader for AR7XXX/AR9XXX
Copyright (C) 2011 Gabor Juhos 
Decompressing kernel... done!
Starting kernel at 80060000...

[    0.000000] Linux version 4.14.94 (jenkins@tofu-z77hvub18_openwrt) (gcc version 7.4.0 (OpenWrt GCC 7.4.0 r0+9105-9d407488e5)) #0 Wed Jan 23 16:51:28 2019
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 0001974c (MIPS 74Kc)
[    0.000000] MIPS: machine is NEC Aterm WR8750N
[    0.000000] SoC: Atheros AR9344 rev 1
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 08000000 @ 00000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 bytes
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] random: get_random_bytes called from 0x8045972c with crng_init=0
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 32512
[    0.000000] Kernel command line: console=ttyS0,9600 rootfstype=squashfs,jffs2
[    0.000000] PID hash table entries: 512 (order: -1, 2048 bytes)
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Writing ErrCtl register=00000000
[    0.000000] Readback ErrCtl register=00000000
[    0.000000] Memory: 118520K/131072K available (3450K kernel code, 138K rwdata, 472K rodata, 6684K init, 195K bss, 12552K reserved, 0K cma-reserved)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 51
[    0.000000] CPU clock: 560.000 MHz
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 6825930166 ns
[    0.000011] sched_clock: 32 bits at 280MHz, resolution 3ns, wraps every 7669584382ns
[    0.092709] Calibrating delay loop... 278.93 BogoMIPS (lpj=1394688)
[    0.237625] pid_max: default: 32768 minimum: 301
[    0.293066] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.372219] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.461166] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.578794] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.651744] pinctrl core: initialized pinctrl subsystem
[    0.715211] NET: Registered protocol family 16
[    0.769103] Can't analyze schedule() prologue at 803ba51c
[    0.836079] PCI host bridge /ahb/apb/pcie-controller@180c0000 ranges:
[    0.913158]  MEM 0x0000000010000000..0x0000000013ffffff
[    0.975617]   IO 0x0000000000000000..0x0000000000000000
[    1.055448] PCI host bridge to bus 0000:00
[    1.104416] pci_bus 0000:00: root bus resource [mem 0x10000000-0x13ffffff]
[    1.186635] pci_bus 0000:00: root bus resource [io  0x0000]
[    1.253295] pci_bus 0000:00: root bus resource [??? 0x00000000 flags 0x0]
[    1.334519] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.429831] pci 0000:00:00.0: BAR 0: assigned [mem 0x10000000-0x1001ffff 64bit]
[    1.517292] pci 0000:00:00.0: BAR 6: assigned [mem 0x10020000-0x1002ffff pref]
[    1.604285] clocksource: Switched to clocksource MIPS
[    1.665872] NET: Registered protocol family 2
[    1.718830] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[    1.802158] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    1.878145] TCP: Hash tables configured (established 1024 bind 1024)
[    1.954317] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    2.024067] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    2.099293] NET: Registered protocol family 1
[    2.286897] Crashlog allocated RAM at address 0x3f00000
[    2.350730] workingset: timestamp_bits=30 max_order=15 bucket_order=0
[    2.432797] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    2.502572] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    2.693963] io scheduler noop registered
[    2.740842] io scheduler deadline registered (default)
[    2.802581] ar7200-usb-phy usb-phy: phy reset is missing
[    2.868418] pinctrl-single 1804002c.pinmux: 544 pins at pa b804002c size 68
[    2.952302] gpio-export gpio-export: 1 gpio(s) exported
[    3.015603] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    3.092383] console [ttyS0] disabled
[    3.135144] 18020000.uart: ttyS0 at MMIO 0x18020000 (irq = 8, base_baud = 2500000) is a 16550A
[    3.238160] console [ttyS0] enabled
[    3.238160] console [ttyS0] enabled
[    3.321437] bootconsole [early0] disabled
[    3.321437] bootconsole [early0] disabled
[    3.423644] m25p80 spi0.0: mx25l6405d (8192 Kbytes)
[    3.482102] 5 fixed-partitions partitions found on MTD device spi0.0
[    3.558146] Creating 5 MTD partitions on "spi0.0":
[    3.615458] 0x000000000000-0x000000020000 : "u-boot"
[    3.675689] 0x000000020000-0x000000022000 : "config"
[    3.735920] 0x000000022000-0x000000030000 : "reserved"
[    3.798168] 0x000000030000-0x000000040000 : "art"
[    3.855263] 0x000000040000-0x000000800000 : "firmware"
[    3.927358] libphy: Fixed MDIO Bus: probed
[    4.314677] libphy: ag71xx_mdio: probed
[    4.385208] switch0: Atheros AR8327 rev. 2 switch registered on mdio-bus.0
[    5.455463] ag71xx 19000000.eth: connected to PHY at mdio-bus.0:00 [uid=004dd033, driver=Atheros AR8216/AR8236/AR8316]
[    5.584146] eth0: Atheros AG71xx at 0xb9000000, irq 4, mode:RGMII
[    5.659064] NET: Registered protocol family 10
[    5.715873] Segment Routing with IPv6
[    5.759778] NET: Registered protocol family 17
[    5.813285] 8021q: 802.1Q VLAN Support v1.8
[    5.898005] Freeing unused kernel memory: 6684K
[    5.952134] This architecture does not have kernel memory protection.
[    6.042871] init: Console is alive
[    6.083814] init: - watchdog -
[    6.143011] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    6.235254] usbcore: registered new interface driver usbfs
[    6.300947] usbcore: registered new interface driver hub
[    6.364600] usbcore: registered new device driver usb
[    6.431060] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    6.510955] ehci-platform: EHCI generic platform driver
[    6.573756] ehci-platform 1b000000.usb: EHCI Host Controller
[    6.641508] ehci-platform 1b000000.usb: new USB bus registered, assigned bus number 1
[    6.735238] ehci-platform 1b000000.usb: irq 3, io mem 0x1b000000
[    6.817349] random: fast init done
[    6.858045] ehci-platform 1b000000.usb: USB 2.0 started, EHCI 1.00
[    6.932953] hub 1-0:1.0: USB hub found
[    6.978274] hub 1-0:1.0: 1 port detected
[    7.026764] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    7.123648] init: - preinit -
[    7.383363] random: jshn: uninitialized urandom read (4 bytes read)
[    7.458456] usb 1-1: new full-speed USB device number 2 using ehci-platform
[    7.631781] random: jshn: uninitialized urandom read (4 bytes read)
[    7.827269] usb 1-1: not running at top speed; connect to a high speed hub
[    7.997287] random: procd: uninitialized urandom read (4 bytes read)
[    8.073767] hub 1-1:1.0: USB hub found
[    8.142337] hub 1-1:1.0: 4 ports detected
[    8.415341] urandom_read: 3 callbacks suppressed
[    8.415350] random: jshn: uninitialized urandom read (4 bytes read)
[    8.638829] random: jshn: uninitialized urandom read (4 bytes read)
[    9.470813] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[    9.540678] IPv6: ADDRCONF(NETDEV_UP): eth0.1: link is not ready
Press the [f] key and hit [enter] to enter failsafe mode
Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level
[   10.615562] eth0: link up (1000Mbps/Full duplex)
[   10.670896] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   10.748560] IPv6: ADDRCONF(NETDEV_CHANGE): eth0.1: link becomes ready
[   12.923211] procd: - early -
[   12.958728] procd: - watchdog -
[   13.546909] procd: - watchdog -
[   13.584843] procd: - ubus -
[   13.626022] random: ubusd: uninitialized urandom read (4 bytes read)
[   13.703217] random: ubusd: uninitialized urandom read (4 bytes read)
[   13.780750] procd: - init -
[   13.814352] eth0: link down
Please press Enter to activate this console.
[   14.040001] kmodloader: loading kernel modules from /etc/modules.d/*
[   14.120538] ip6_tables: (C) 2000-2006 Netfilter Core Team
[   14.195648] Loading modules backported from Linux version v4.19.7-0-g61c68f2a2af0
[   14.285177] Backport generated by backports.git v4.19.7-1-0-g148b072d
[   14.365276] ip_tables: (C) 2000-2006 Netfilter Core Team
[   14.437318] nf_conntrack version 0.5.0 (2048 buckets, 8192 max)
[   14.565708] xt_time: kernel timezone is -0000
[   14.674548] PPP generic driver version 2.4.2
[   14.728163] NET: Registered protocol family 24
[   14.839568] ieee80211 phy0: Atheros AR9340 Rev:1 mem=0xb8100000, irq=11
[   14.922743] ath9k 0000:00:00.0: Direct firmware load for ath9k-eeprom-pci-0000:00:00.0.bin failed with error -2
[   15.043543] ath9k 0000:00:00.0: Falling back to user helper
[   15.532696] ieee80211 phy1: Atheros AR9300 Rev:3 mem=0xb0000000, irq=14
[   15.714701] kmodloader: done loading kernel modules from /etc/modules.d/*
[   27.302322] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[   27.373470] eth0: link up (1000Mbps/Full duplex)
[   27.560442] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   27.665778] br-lan: port 1(eth0.1) entered blocking state
[   27.730394] br-lan: port 1(eth0.1) entered disabled state
[   27.795282] device eth0.1 entered promiscuous mode
[   27.852575] device eth0 entered promiscuous mode
[   28.235690] br-lan: port 1(eth0.1) entered blocking state
[   28.300310] br-lan: port 1(eth0.1) entered forwarding state
[   28.367361] IPv6: ADDRCONF(NETDEV_UP): br-lan: link is not ready
[   28.439614] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready



BusyBox v1.30.0 () built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt SNAPSHOT, r0+9108-749028c7cc
 -----------------------------------------------------
=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
root@OpenWrt:/#

WR8750N GPIOレジスタメモ

### ===== switch uninitialized ===== ###
boot> debug memory read 0xb8040000 70
b8040000:0003db1f 00039639 00040000 00000000 .......9........
b8040010:00000000 00000000 00000000 00000000 ................
b8040020:00000000 00000000 000f8000 00000000 ................
b8040030:0b0a0900 00180000 00000000 2f2e0000 ............/...
b8040040:00000000 00000908 00000000 00000000 ................
b8040050:00000c0b 00000000 00000000 00000000 ................
b8040060:00000000 0d0f110e 00000000 00000002 ................

# GPIO Output Enable: 0x18040000 (0xb8040000) -> 0x3db1f
GPIO (enabled): 5, 6, 7, 10, 13, 18, 19, 20, 21, 22

# GPIO Input Value: 0x18040004 (0xb8040004) -> 0x39639
GPIO0: 1
GPIO3: 1
GPIO4: 1
GPIO5: 1
GPIO9: 1
GPIO10: 1
GPIO12: 1
GPIO15: 1
GPIO16: 1
GPIO17: 1

# GPIO Output Value: 0x18040008 (0xb8040008) -> 0x40000
GPIO18: 1 (HIGH)
(other): 0 (LOW)

### ===== switch initialized ===== ###
boot> debug memory read 0xb8040000 70
b8040000:0003db1f 0003b639 00042000 00000000 .......9.. .....
b8040010:00000000 00000000 00000000 00000000 ................
b8040020:00000000 00000000 000f8000 00000000 ................
b8040030:0b0a0900 00180000 00000000 2f2e0000 ............/...
b8040040:00000000 00000908 00000000 00000000 ................
b8040050:00000c0b 00000000 00000000 00000000 ................
b8040060:00000000 0d0f110e 00000000 00000002 ................

# GPIO Output Enable: 0x18040000 (0xb8040000) -> 0x3db1f
GPIO (enabled): 5, 6, 7, 10, 13, 18, 19, 20, 21, 22

# GPIO Input Value: 0x18040004 (0xb8040004) -> 0x3b639
GPIO0: 1
GPIO3: 1
GPIO4: 1
GPIO5: 1
GPIO9: 1
GPIO10: 1
GPIO12: 1
GPIO13: 1
GPIO15: 1
GPIO16: 1
GPIO17: 1

# GPIO Output Value: 0x18040008 (0xb8040008) -> 0x42000
GPIO13: 1
GPIO18: 1
(other): 0

WXR-2533DHP pinmux ctl_reg

それっぽい値が取れたのでメモ。

レジスタ参考

計算式等

pinmux_base:	0x800000
ctl_reg_offset:	0x1000 + 0x10 * pin_id
ctl_reg:		pinmux_base + ctl_reg_offset

mux_bit: 2
pull_bit: 0
drv_bit: 6

# func (mux)
func = (ctl_reg >> mux_bit) & 7

# pull (bias)
pull = (ctl_reg >> pull_bit) & 3

# drive strength
drive_strength = (((ctl_reg >> drv_bit) & 7) + 1) * 2

static const char * const pulls_keeper[] = { /* ipq806xはこっち? */
	"no pull",
	"pull down",
	"keeper",
	"pull up"
};

static const char * const pulls_no_keeper[] = {
	"no pull",
	"pull down",
	"pull up",
};

devmem2を利用して取得した実際の値

###  U-Boot
pin  reg     val  func  pull  drv
0    801000  c4   1     0     8
1    801010  2c4  1     0     8
2    801020  1    0     1     2
3    801030  1    0     1     2
4    801040  1    0     1     2
5    801050  1    0     1     2
6    801060  100  0     0     a   (=10)
7    801070  300  0     0     a
8    801080  300  0     0     a
9    801090  300  0     0     a
10   8010a0  344  1     0     c   (=12)
11   8010b0  344  1     0     c
12   8010c0  4    1     0     2
13   8010d0  4    1     0     2
14   8010e0  1    0     1     2
15   8010f0  300  0     0     a
16   801100  300  0     0     a
17   801110  1    0     1     2
18   801120  105  1     1     a
19   801130  105  1     1     a
20   801140  303  0     3     a
21   801150  1c5  1     1     10  (=16)????
22   801160  300  0     0     a
23   801170  300  0     0     a
24   801180  300  0     0     a
25   801190  300  0     0     a
26   8011a0  300  0     0     a
27   8011b0  2c8  2     0     8
28   8011c0  2c8  2     0     8
29   8011d0  2c8  2     0     8
30   8011e0  2c8  2     0     8
31   8011f0  2c8  2     0     8
32   801200  2c8  2     0     8
33   801210  1    0     1     2
34   801220  304  1     0     a
35   801230  304  1     0     a
36   801240  304  1     0     a
37   801250  304  1     0     a
38   801260  304  1     0     a
39   801270  307  1     3     a
40   801280  306  1     2     a
41   801290  306  1     2     a
42   8012a0  306  1     2     a
43   8012b0  306  1     2     a
44   8012c0  306  1     2     a
45   8012d0  306  1     2     a
46   8012e0  306  1     2     a
47   8012f0  306  1     2     a
48   801300  1    0     1     2
49   801310  1    0     1     2
50   801320  1    0     1     2
51   801330  c8   2     0     8
52   801340  c8   2     0     8
53   801350  300  0     0     a
54   801360  100  0     0     a
55   801370  100  0     0     a
56   801380  100  0     0     a
57   801390  100  0     0     a
58   8013a0  1    0     1     2
59   8013b0  c8   2     0     8
60   8013c0  c8   2     0     8
61   8013d0  c8   2     0     8
62   8013e0  c8   2     0     8
63   8013f0  300  0     3     a
64   801400  100  0     0     a
65   801410  100  0     0     a
66   801420  1    0     1     2
67   801430  1    0     1     2
68   801440  1    0     1     2

###  Kernel
pin  reg     val  func  pull  drv
0    801000  c0   0     0     8
1    801010  2c4  1     0     8
2    801020  c0   0     0     8
3    801030  200  0     0     2
4    801040  1    0     1     2
5    801050  1    0     1     2
6    801060  3    0     3     2
7    801070  203  0     3     2
8    801080  203  0     3     2
9    801090  203  0     3     2
10   8010a0  344  1     0     c
11   8010b0  344  1     0     c
12   8010c0  144  1     0     c
13   8010d0  144  1     0     c
14   8010e0  c5   1     1     8
15   8010f0  203  0     3     2
16   801100  203  0     3     2
17   801110  c    3     0     2
18   801120  105  1     1     a
19   801130  105  1     1     a
20   801140  107  1     3     a
21   801150  145  1     1     c
22   801160  203  0     3     2
23   801170  203  0     3     2
24   801180  203  0     3     2
25   801190  203  0     3     2
26   8011a0  200  0     0     2
27   8011b0  c8   2     0     8
28   8011c0  c8   2     0     8
29   8011d0  c8   2     0     8
30   8011e0  c8   2     0     8
31   8011f0  c8   2     0     8
32   801200  c8   2     0     8
33   801210  301  0     1     a
34   801220  304  1     0     a
35   801230  304  1     0     a
36   801240  304  1     0     a
37   801250  304  1     0     a
38   801260  304  1     0     a
39   801270  307  1     3     a
40   801280  306  1     2     a
41   801290  306  1     2     a
42   8012a0  306  1     2     a
43   8012b0  306  1     2     a
44   8012c0  306  1     2     a
45   8012d0  306  1     2     a
46   8012e0  306  1     2     a
47   8012f0  306  1     2     a
48   801300  200  0     0     2
49   801310  1    0     1     2
50   801320  1    0     1     2
51   801330  c8   2     0     8
52   801340  c8   2     0     8
53   801350  200  0     0     2
54   801360  3    0     3     2
55   801370  3    0     3     2
56   801380  3    0     3     2
57   801390  3    0     3     2
58   8013a0  3    0     3     2
59   8013b0  c8   2     0     8
60   8013c0  c8   2     0     8
61   8013d0  c8   2     0     8
62   8013e0  c8   2     0     8
63   8013f0  200  0     0     2
64   801400  3    0     3     2
65   801410  3    0     3     2
66   801420  1    0     1     2
67   801430  3    0     3     2
68   801440  203  0     3     2

GPIO value確認用script

OpenWrt Wiki にあるスクリプトからの改造。/sys/class/gpio/にあるgpiochipを GPIOCHIPS 内に記述し、それらの配下のGPIOのvalueを表示する。

#!/bin/sh
GPIOCHIPS="0 24 40 72"

for gc in $GPIOCHIPS; do
	BASE=$(cat /sys/class/gpio/gpiochip${gc}/base)
	NGPIO=$(cat /sys/class/gpio/gpiochip${gc}/ngpio)
	max=$(($BASE+$NGPIO))
	gpio=$BASE

	echo "### gpiochip${gc} ####"
	while [ $gpio -lt $max ] ; do
		echo $gpio > /sys/class/gpio/export
		[ -d /sys/class/gpio/gpio${gpio} ] && {
			echo "[GPIO${gpio}] value $(cat /sys/class/gpio/gpio${gpio}/value)"
			echo ${gpio} > /sys/class/gpio/unexport
		}
		gpio=$((gpio+1))
	done
done

使用中などでエラーを吐くピンもあるため、エラー表示が不要な場合は

./gpio.sh 2> /dev/null

などとして実行する。