タグ: fixed-regulator

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
などが例らしい(?)。
広告

WR8750N fixed-regulatorメモ

WR8750N/WR9500N/WG600HPではいくつかGPIOをHIGHで出さなければ機能しないデバイスがあり、それらについてfixed-regulatorのDeviceTree binding (compatible = "regulator-fixed") を使用する場合の挙動確認用メモ。

USB-Vbus
ath79内の他のdtsでは問題無いようではあるものの、Aterm 3機種ではブート中に無効化されてしまった。こうなると、USBポートにDC 5V電源が供給されずデバイスが使用できない。
ノード内に regulator-always-on; を付加した場合は無効化されず有効なまま。

無効化される場合のログ

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
DRAM Test ..... PASS
Timer test .... PASS
FLASH CHKSUM .. PASS
LAN Test ..... 
LoopBack count 0 .. 
phy0.1: "Atheros/AR8327(SW)"
phy0.0: "Atheros/AR8327(phy)"
active ch:0
active ch:1
phy0.1: "Atheros/AR8327(SW)"
phy0.0: "Atheros/AR8327(phy)"
active ch:0
PASS
Package TYPE = 0x01
post success

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 = 3442316
start memory load ... 
memory load complete
  begin  : 0x80060000
  length : 3442292
  startup: 0x80060000
boot
begin  : 0x80060000
length : 3442292
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.101 (musashino205@Taiha.Net) (gcc version 7.4.0 (OpenWrt GCC 7.4.0 r0+9362-3cf839bf27)) #0 Sun Feb 17 11:18:45 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 0x8045d72c 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: 117812K/131072K available (3467K kernel code, 136K rwdata, 472K rodata, 7372K init, 195K bss, 13260K 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.092710] Calibrating delay loop... 278.93 BogoMIPS (lpj=1394688)
[    0.237626] pid_max: default: 32768 minimum: 301
[    0.293067] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.372218] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.461311] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.579001] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.651956] pinctrl core: initialized pinctrl subsystem
[    0.715407] NET: Registered protocol family 16
[    0.769307] Can't analyze schedule() prologue at 803beb1c
[    0.836254] PCI host bridge /ahb/apb/pcie-controller@180c0000 ranges:
[    0.913369]  MEM 0x0000000010000000..0x0000000013ffffff
[    0.975830]   IO 0x0000000000000000..0x0000000000000000
[    1.059606] PCI host bridge to bus 0000:00
[    1.108577] pci_bus 0000:00: root bus resource [mem 0x10000000-0x13ffffff]
[    1.190796] pci_bus 0000:00: root bus resource [io  0x0000]
[    1.257459] pci_bus 0000:00: root bus resource [??? 0x00000000 flags 0x0]
[    1.338683] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.433994] pci 0000:00:00.0: BAR 0: assigned [mem 0x10000000-0x1001ffff 64bit]
[    1.521455] pci 0000:00:00.0: BAR 6: assigned [mem 0x10020000-0x1002ffff pref]
[    1.608447] clocksource: Switched to clocksource MIPS
[    1.670048] NET: Registered protocol family 2
[    1.722993] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[    1.806319] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    1.882308] TCP: Hash tables configured (established 1024 bind 1024)
[    1.958477] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    2.028229] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    2.103447] NET: Registered protocol family 1
[    2.300316] Crashlog allocated RAM at address 0x3f00000
[    2.364123] workingset: timestamp_bits=30 max_order=15 bucket_order=0
[    2.446224] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    2.515993] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    2.706900] io scheduler noop registered
[    2.753847] io scheduler deadline registered (default)
[    2.815602] ar7200-usb-phy usb-phy: phy reset is missing
[    2.881456] pinctrl-single 1804002c.pinmux: 544 pins at pa b804002c size 68
[    2.965880] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    3.042684] console [ttyS0] disabled
[    3.085437] 18020000.uart: ttyS0 at MMIO 0x18020000 (irq = 8, base_baud = 2500000) is a 16550A
[    3.188462] console [ttyS0] enabled
[    3.188462] console [ttyS0] enabled
[    3.271732] bootconsole [early0] disabled
[    3.271732] bootconsole [early0] disabled
[    3.373903] m25p80 spi0.0: mx25l6405d (8192 Kbytes)
[    3.432289] 4 fixed-partitions partitions found on MTD device spi0.0
[    3.508338] Creating 4 MTD partitions on "spi0.0":
[    3.565649] 0x000000000000-0x000000020000 : "u-boot"
[    3.625861] 0x000000020000-0x000000030000 : "config"
[    3.686072] 0x000000030000-0x000000040000 : "art"
[    3.743173] 0x000000040000-0x000000800000 : "firmware"
[    3.814900] libphy: Fixed MDIO Bus: probed
[    4.198841] libphy: ag71xx_mdio: probed
[    4.269237] switch0: Atheros AR8327 rev. 2 switch registered on mdio-bus.0
[    5.339625] ag71xx 19000000.eth: connected to PHY at mdio-bus.0:00 [uid=004dd033, driver=Atheros AR8216/AR8236/AR8316]
[    5.468299] eth0: Atheros AG71xx at 0xb9000000, irq 4, mode:RGMII
[    5.543245] NET: Registered protocol family 10
[    5.600101] Segment Routing with IPv6
[    5.644025] NET: Registered protocol family 17
[    5.697555] 8021q: 802.1Q VLAN Support v1.8
[    5.750794] usb_vbus: disabling
[    5.823669] Freeing unused kernel memory: 7372K
[    5.877886] This architecture does not have kernel memory protection.
[    5.968851] init: Console is alive
[    6.009792] init: - watchdog -
[    6.068664] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    6.160539] usbcore: registered new interface driver usbfs
[    6.226283] usbcore: registered new interface driver hub
[    6.289932] usbcore: registered new device driver usb
[    6.356625] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    6.436541] ehci-platform: EHCI generic platform driver
[    6.499101] random: fast init done
[    6.540019] ehci-platform 1b000000.usb: EHCI Host Controller
[    6.607799] ehci-platform 1b000000.usb: new USB bus registered, assigned bus number 1
[    6.701547] ehci-platform 1b000000.usb: irq 3, io mem 0x1b000000
[    6.798491] ehci-platform 1b000000.usb: USB 2.0 started, EHCI 1.00
[    6.873338] hub 1-0:1.0: USB hub found
[    6.918714] hub 1-0:1.0: 1 port detected
[    6.967320] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    7.064183] init: - preinit -
[    7.322505] random: jshn: uninitialized urandom read (4 bytes read)
[    7.397627] usb 1-1: new high-speed USB device number 2 using ehci-platform
[    7.571547] random: jshn: uninitialized urandom read (4 bytes read)
[    7.759977] random: procd: uninitialized urandom read (4 bytes read)
[    7.836445] hub 1-1:1.0: USB hub found
[    7.928501] hub 1-1:1.0: 4 ports detected
[    8.377822] urandom_read: 4 callbacks suppressed
[    8.377831] random: jshn: uninitialized urandom read (4 bytes read)
[    9.265951] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[    9.335906] 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.449722] eth0: link up (1000Mbps/Full duplex)
[   10.506481] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   10.586000] IPv6: ADDRCONF(NETDEV_CHANGE): eth0.1: link becomes ready
[   12.652859] eth0: link down
[   12.705540] procd: - early -
[   12.740359] procd: - watchdog -
[   13.324256] procd: - watchdog -
[   13.362195] procd: - ubus -
[   13.402672] random: ubusd: uninitialized urandom read (4 bytes read)
[   13.479944] random: ubusd: uninitialized urandom read (4 bytes read)
[   13.557503] procd: - init -
Please press Enter to activate this console.
[   13.784410] kmodloader: loading kernel modules from /etc/modules.d/*
[   13.864552] ip6_tables: (C) 2000-2006 Netfilter Core Team
[   13.940076] Loading modules backported from Linux version v4.19.7-0-g61c68f2a2af0
[   14.029655] Backport generated by backports.git v4.19.7-1-0-g148b072d
[   14.109759] ip_tables: (C) 2000-2006 Netfilter Core Team
[   14.182075] nf_conntrack version 0.5.0 (2048 buckets, 8192 max)
[   14.311244] xt_time: kernel timezone is -0000
[   14.419646] PPP generic driver version 2.4.2
[   14.473306] NET: Registered protocol family 24
[   14.586672] ieee80211 phy0: Atheros AR9340 Rev:1 mem=0xb8100000, irq=11
[   14.669780] ath9k 0000:00:00.0: Direct firmware load for ath9k-eeprom-pci-0000:00:00.0.bin failed with error -2
[   14.790514] ath9k 0000:00:00.0: Falling back to user helper
[   15.283757] ieee80211 phy1: Atheros AR9300 Rev:3 mem=0xb0000000, irq=13
[   15.468860] kmodloader: done loading kernel modules from /etc/modules.d/*
[   27.496202] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[   27.738887] br-lan: port 1(eth0.1) entered blocking state
[   27.803513] br-lan: port 1(eth0.1) entered disabled state
[   27.868396] device eth0.1 entered promiscuous mode
[   27.925703] device eth0 entered promiscuous mode
[   28.309978] IPv6: ADDRCONF(NETDEV_UP): br-lan: link is not ready
[   28.490322] IPv6: ADDRCONF(NETDEV_UP): eth0.2: link is not ready
[   28.609772] eth0: link up (1000Mbps/Full duplex)
[   28.858530] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   29.364321] br-lan: port 1(eth0.1) entered blocking state
[   29.428925] br-lan: port 1(eth0.1) entered forwarding state
[   29.496037] IPv6: ADDRCONF(NETDEV_CHANGE): eth0.2: link becomes ready
[   30.938550] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready
[  125.446530] random: crng init done