pepe2k / u-boot_mod

U-Boot 1.1.4 modification for routers
GNU General Public License v2.0
1.08k stars 533 forks source link

gpio differences compared to orig u-boot #210

Closed psyborg55 closed 2 years ago

psyborg55 commented 6 years ago

Hi

i notice some differences in gpio directions/values when loaded original tp-link u-boot. can this cause any problems? tl-mr22u is in question.

TP-LINK U-Boot:


gpiochip0: GPIOs 0-31, parent: platform/ath79-gpio, ath79-gpio:
 gpio-0   (                    |sysfs               ) in  lo    
 gpio-1   (                    |sysfs               ) in  lo    
 gpio-2   (                    |sysfs               ) out lo    
 gpio-3   (                    |sysfs               ) out hi    
 gpio-4   (                    |sysfs               ) out hi    
 gpio-5   (                    |sysfs               ) out hi    
 gpio-6   (                    |sysfs               ) out lo    
 gpio-7   (                    |sysfs               ) out lo    
 gpio-8   (                    |sysfs               ) in  lo    
 gpio-9   (                    |sysfs               ) in  lo    
 gpio-10  (                    |sysfs               ) out hi    
 gpio-11  (                    |USB power           ) out hi    
 gpio-12  (                    |reset               ) in  lo    
 gpio-13  (                    |tp-link:blue:system ) out hi    
 gpio-14  (                    |sw1                 ) in  lo    
 gpio-15  (                    |sysfs               ) out hi    
 gpio-16  (                    |sw2                 ) in  hi    
 gpio-17  (                    |sysfs               ) out hi    
 gpio-18  (                    |sysfs               ) out lo    
 gpio-19  (                    |sysfs               ) out lo    
 gpio-21  (                    |sysfs               ) out lo    
 gpio-22  (                    |sysfs               ) out lo    
 gpio-23  (                    |sysfs               ) out hi    
 gpio-24  (                    |sysfs               ) out lo    
 gpio-25  (                    |sysfs               ) out lo    
 gpio-26  (                    |sysfs               ) out lo    
 gpio-27  (                    |sysfs               ) out lo    
 gpio-28  (                    |sysfs               ) out lo    
 gpio-29  (                    |sysfs               ) out lo    
 gpio-30  (                    |sysfs               ) out lo    
 gpio-31  (                    |sysfs               ) out lo    

gpiochip1: GPIOs 494-511, parent: platform/qca953x_wmac, ath9k-phy0:
 gpio-494 (                    |sysfs               ) out lo    
 gpio-495 (                    |ath9k-phy0          ) in  lo    
 gpio-496 (                    |sysfs               ) in  lo    
 gpio-497 (                    |sysfs               ) in  lo    
 gpio-498 (                    |sysfs               ) in  hi    
 gpio-499 (                    |sysfs               ) in  hi    
 gpio-500 (                    |sysfs               ) in  hi    
 gpio-501 (                    |sysfs               ) in  hi    
 gpio-502 (                    |sysfs               ) in  hi    
 gpio-503 (                    |sysfs               ) in  hi    
 gpio-504 (                    |sysfs               ) in  hi    
 gpio-505 (                    |sysfs               ) in  hi    
 gpio-506 (                    |sysfs               ) in  hi    
 gpio-507 (                    |sysfs               ) in  hi    
 gpio-508 (                    |sysfs               ) in  hi    
 gpio-509 (                    |sysfs               ) in  hi    
 gpio-510 (                    |sysfs               ) out hi    
 gpio-511 (                    |sysfs               ) in  hi  

modified U-Boot:

gpiochip0: GPIOs 0-31, parent: platform/ath79-gpio, ath79-gpio:
 gpio-0   (                    |sysfs               ) in  lo    
 gpio-1   (                    |sysfs               ) in  lo    
 gpio-2   (                    |sysfs               ) out lo    
 gpio-3   (                    |sysfs               ) in  lo    
 gpio-4   (                    |sysfs               ) out hi    
 gpio-5   (                    |sysfs               ) out hi    
 gpio-6   (                    |sysfs               ) out lo    
 gpio-7   (                    |sysfs               ) out lo    
 gpio-8   (                    |sysfs               ) in  lo    
 gpio-9   (                    |sysfs               ) in  lo    
 gpio-10  (                    |sysfs               ) out hi    
 gpio-11  (                    |USB power           ) out hi    
 gpio-12  (                    |reset               ) in  lo    
 gpio-13  (                    |tp-link:blue:system ) out hi    
 gpio-14  (                    |sw1                 ) in  lo    
 gpio-15  (                    |sysfs               ) in  lo    
 gpio-16  (                    |sw2                 ) in  hi    
 gpio-17  (                    |sysfs               ) out hi    
 gpio-18  (                    |sysfs               ) out lo    
 gpio-19  (                    |sysfs               ) out lo    
 gpio-21  (                    |sysfs               ) out lo    
 gpio-22  (                    |sysfs               ) out lo    
 gpio-23  (                    |sysfs               ) out hi    
 gpio-24  (                    |sysfs               ) out lo    
 gpio-25  (                    |sysfs               ) out lo    
 gpio-26  (                    |sysfs               ) out lo    
 gpio-27  (                    |sysfs               ) out lo    
 gpio-28  (                    |sysfs               ) out lo    
 gpio-29  (                    |sysfs               ) out lo    
 gpio-30  (                    |sysfs               ) out lo    
 gpio-31  (                    |sysfs               ) out lo    

gpiochip1: GPIOs 494-511, parent: platform/qca953x_wmac, ath9k-phy0:
 gpio-494 (                    |sysfs               ) out lo    
 gpio-495 (                    |ath9k-phy0          ) in  lo    
 gpio-496 (                    |sysfs               ) in  lo    
 gpio-497 (                    |sysfs               ) in  lo    
 gpio-498 (                    |sysfs               ) in  hi    
 gpio-499 (                    |sysfs               ) in  hi    
 gpio-500 (                    |sysfs               ) in  hi    
 gpio-501 (                    |sysfs               ) in  hi    
 gpio-502 (                    |sysfs               ) in  hi    
 gpio-503 (                    |sysfs               ) in  hi    
 gpio-504 (                    |sysfs               ) in  hi    
 gpio-505 (                    |sysfs               ) in  hi    
 gpio-506 (                    |sysfs               ) in  hi    
 gpio-507 (                    |sysfs               ) in  hi    
 gpio-508 (                    |sysfs               ) in  hi    
 gpio-509 (                    |sysfs               ) in  hi    
 gpio-510 (                    |sysfs               ) out hi    
 gpio-511 (                    |sysfs               ) in  hi 

i am not sure where does it take gpio23 value from?

also after exporting 494-511 pins and trying to cat debug file i get this for every gpio read attempt:

[  330.384059] ------------[ cut here ]------------
[  330.388854] WARNING: CPU: 0 PID: 1374 at backports-2017-11-01/drivers/net/wireless/ath/ath9k/hw.c:2856 0x80d83430 [ath9k_hw@80d80000+0x56820]
[  330.401963] Modules linked in: ath9k ath9k_htc ath9k_common rt2800usb rt2800lib ath9k_hw ath rt2x00usb rt2x00lib mac80211 iptable_nat iptable_mangle iptable_filter ipt_REJECT ipt_MASQUERADE ip_tables cfg80211 xt_time xt_tcpudp xt_state xt_nat xt_multiport xt_mark xt_mac xt_limit xt_conntrack xt_comment xt_TCPMSS xt_REDIRECT xt_LOG x_tables nf_reject_ipv4 nf_nat_redirect nf_nat_masquerade_ipv4 nf_conntrack_ipv4 nf_nat_ipv4 nf_nat nf_log_ipv4 nf_log_common nf_defrag_ipv4 nf_conntrack_rtcache nf_conntrack crc_itu_t crc_ccitt compat ledtrig_usbport ehci_platform ehci_hcd gpio_button_hotplug usbcore nls_base usb_common
[  330.458617] CPU: 0 PID: 1374 Comm: cat Tainted: G        W       4.9.111 #0
[  330.465799] Stack : 803e7672 0000003f 00000000 00000001 00000000 00000000 00000000 00000000
[  330.474507]         00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[  330.483217]         00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[  330.491917]         00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[  330.500618]         00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[  330.509318]         ...
[  330.511854] Call Trace:
[  330.514203] [<8006ac4c>] 0x8006ac4c
[  330.517809] [<8006ac4c>] 0x8006ac4c
[  330.521423] [<8007fa5c>] 0x8007fa5c
[  330.525036] [<80d83430>] 0x80d83430 [ath9k_hw@80d80000+0x56820]
[  330.531182] [<8007faf8>] 0x8007faf8
[  330.534791] [<8012dea4>] 0x8012dea4
[  330.538409] [<80d83430>] 0x80d83430 [ath9k_hw@80d80000+0x56820]
[  330.544546] [<801db898>] 0x801db898
[  330.548172] [<8012d9e4>] 0x8012d9e4
[  330.551792] [<80184900>] 0x80184900
[  330.555400] [<8018495c>] 0x8018495c
[  330.559031] [<8010c6d4>] 0x8010c6d4
[  330.562656] [<801c47c0>] 0x801c47c0
[  330.566270] [<801c6a80>] 0x801c6a80
[  330.569895] [<8010c750>] 0x8010c750
[  330.573518] [<801359c8>] 0x801359c8
[  330.577155] [<801356d0>] 0x801356d0
[  330.580786] [<80136640>] 0x80136640
[  330.584404] [<8013584c>] 0x8013584c
[  330.588009] [<80070ed0>] 0x80070ed0
[  330.591638] [<8010cd0c>] 0x8010cd0c
[  330.595240] [<80127e24>] 0x80127e24
[  330.598863] [<8010d820>] 0x8010d820
[  330.602472] [<8006f2ec>] 0x8006f2ec
[  330.606080] [<8010ae7c>] 0x8010ae7c
[  330.609697] 
[  330.611241] ---[ end trace c3af2e896cbe096e ]---

for reference modified U-Boot barrier breaker image:

GPIOs 0-17, ath79:
 gpio-0   (sysfs               ) in  lo
 gpio-1   (sysfs               ) in  lo
 gpio-2   (sysfs               ) in  lo
 gpio-3   (sysfs               ) in  lo
 gpio-4   (sysfs               ) in  hi
 gpio-5   (sysfs               ) in  hi
 gpio-6   (sysfs               ) in  lo
 gpio-7   (sysfs               ) in  lo
 gpio-8   (sysfs               ) in  lo
 gpio-9   (sysfs               ) in  lo
 gpio-10  (sysfs               ) in  hi
 gpio-11  (USB power           ) out hi
 gpio-12  (reset               ) in  lo
 gpio-13  (tp-link:blue:system ) out hi
 gpio-14  (sw1                 ) in  lo
 gpio-15  (sysfs               ) in  lo
 gpio-16  (sw2                 ) in  hi
 gpio-17  (sysfs               ) in  hi

TP_Link U-boot barrier breaker:

GPIOs 0-17, ath79:
 gpio-0   (sysfs               ) in  lo
 gpio-1   (sysfs               ) in  lo
 gpio-2   (sysfs               ) in  lo
 gpio-3   (sysfs               ) in  hi
 gpio-4   (sysfs               ) in  hi
 gpio-5   (sysfs               ) in  hi
 gpio-6   (sysfs               ) in  lo
 gpio-7   (sysfs               ) in  lo
 gpio-8   (sysfs               ) in  lo
 gpio-9   (sysfs               ) in  lo
 gpio-10  (sysfs               ) in  hi
 gpio-11  (USB power           ) out hi
 gpio-12  (reset               ) in  lo
 gpio-13  (tp-link:blue:system ) out hi
 gpio-14  (sw1                 ) in  lo
 gpio-15  (sysfs               ) in  hi
 gpio-16  (sw2                 ) in  hi
 gpio-17  (sysfs               ) in  hi
pepe2k commented 6 years ago

Hi @psyborg55,

First of all:

also after exporting 494-511 pins and trying to cat debug file i get this for every gpio read attempt:

I fail to see how this is related to U-Boot?

Also, are you aware that ath9k GPIOs == SOC GPIOs in case of your hardware? There are no other (controlled by radio) I/O lines in QCA953x. It's just another way to drive the same I/O lines, using two different drivers (ath79-gpio vs. ath9k).

Back to your question...

i notice some differences in gpio directions/values when loaded original tp-link u-boot. can this cause any problems? tl-mr22u is in question.

From what I can see, GPIO15 and GPIO3 have different directions (they are set to output in TP-Link original U-Boot and left as floating/input in u-boot_mod).

I don't setup/touch GPIOs which aren't used/connected to anything useful - in this case they are left in default state which is (usually) floating/input.

As I don't have access to your board, it's up to you to look at the PCB, find and measure these GPIOs to check where they are connected to and whether we should change their direction[/value] in code. TP-Link's code is kinda messy, so I wouldn't be surprised that they changed direction[/value] of these GPIOs by mistake but I'm not entirely sure here.

I briefly looked at this picture from OpenWrt Wiki and I would say that GPIO15 is left unconnected (I believe it's pulled low internally as it's used for XTAL value selection) but GPIO3 seems to be connected somewhere: tl-mr22u_pcb_top

PS. OpenWrt ath79 target isn't ready (yet) for production use - please, report your ath9k GPIO related problem in https://bugs.openwrt.org

Cheers, Piotr

psyborg55 commented 6 years ago

It's just another way to drive the same I/O lines, using two different drivers (ath79-gpio vs. ath9k).

I'm aware of that. Is ath9k gpio driver upstreamed into kernel maybe?

GPIO3 seems to be connected somewhere:

I'll check that. Meanwhile I found by extracting original firmware there is an ipad_charge binary in /usr/sbin directory. Quick lookup on google reveals that ipad needs charging current of 2.1A. Maybe some gpio passes more current to USB port when toggled?

jack338c commented 3 years ago

hi gpio-11 USB power of mr22u may not work ,I tried echo 0 >/sys/class/gpio/gpio11/value to turn off usb power,but it dosen't work. please help thanks

psyborg55 commented 2 years ago

there is no way to turn off usb power on this device. it might be possible to rewire EN pin of TPS2553 power switch to a free GPIO but that requires opening device and soldering.

but GPIO3 seems to be connected somewhere:

gpios 0-3 are pulled out to unpopulated header probably used for jtag

recently i had dismantled device to replace dying battery and upgraded memory to 64MB while at it. also fixed the the SPI chip mess and replaced dead pullup/pulldown resistors on its pins.

then the device booted with gpio3 and gpio4 low, tried changing direction/value but it worked only for gpio4

this is current gpio debug output:

gpiochip0: GPIOs 0-31, parent: platform/ath79-gpio, ath79-gpio:
 gpio-0   (                    |sysfs               ) in  lo
 gpio-1   (                    |sysfs               ) in  lo
 gpio-2   (                    |sysfs               ) out lo
 gpio-3   (                    |sysfs               ) in  lo
 gpio-4   (                    |sysfs               ) out hi
 gpio-5   (                    |sysfs               ) out hi
 gpio-6   (                    |sysfs               ) out lo
 gpio-7   (                    |sysfs               ) out lo
 gpio-8   (                    |sysfs               ) in  lo
 gpio-9   (                    |sysfs               ) in  lo
 gpio-10  (                    |sysfs               ) out hi
 gpio-11  (                    |sysfs               ) in  lo
 gpio-12  (                    |reset               ) in  lo
 gpio-13  (                    |tp-link:blue:system ) out hi
 gpio-14  (                    |sw1                 ) in  hi
 gpio-15  (                    |sysfs               ) in  lo
 gpio-16  (                    |sw2                 ) in  hi
 gpio-17  (                    |sysfs               ) out hi

not sure if it matters but gpio4 (and gpio17) is also connected to holtek MCU. for what purpose i have no idea. besides the smart power path design flaw, everything else works pretty stable so i guess small gpio differences are not relevant

jack338c commented 2 years ago

@psyborg55 thank you for your reminder