Jump to content
  • 0

Reboot devices connected to OTG by cutting power to OTG?


MarshallMCH
 Share

Question

I'm powering a small PCB via the OTG port on my OPI PC Plus, however sometimes I need to be able to reboot the device.  It is possible to cut power to the OTG port momentarily to force a reboot?  I've seen mention of PL2 GPIO, but it is unclear to me how this should be setup.  I've also looked at uhubctl, but that didn't work.  Thoughts? 

Link to comment
Share on other sites

16 answers to this question

Recommended Posts

Donate and support the project!

  • 0
32 minutes ago, MarshallMCH said:

I'm not familiar with devmem2.

"devmem2" is a small piece of code used to access kernel memory directly from userspace. You can find a copy of it here : https://bootlin.com/pub/mirror/devmem2.c

Compile it (using "gcc -o devmem2 devmem2.c" ) and give first a try by reading the PL_DAT register which is at the 0x01F02C10 address :

./devmem2 1F02C10 h

Then, since PL2 is the third bit of that PL_DAT register, you can write into it, this bring the PL2 to HIGH :

./devmem2 1F02C10 h 0004

EDIT : Almost forgot, if it is already HIGH during reading, then to bring it LOW by writing 0000 instead of 0004.

Link to comment
Share on other sites

  • 0

Hi Martin, here's what I see when running those commands:

 

root@device:~# ./devmem2 1F02C10 h
/dev/mem opened.
Memory mapped at address 0xb6f52000.
Value at address 0x1 (0xb6f52001): 0x61A

root@device:~# ./devmem2 1F02C10 h 0000
/dev/mem opened.
Memory mapped at address 0xb6f2b000.
Value at address 0x1 (0xb6f2b001): 0x61A
Written 0x0; readback 0x0

root@device:~# ./devmem2 1F02C10 h 0004
/dev/mem opened.
Memory mapped at address 0xb6fce000.
Value at address 0x1 (0xb6fce001): 0x0
Written 0x4; readback 0x4

However, I do not see my PCB turn off after running those commands. 

Link to comment
Share on other sites

  • 0
23 minutes ago, MarshallMCH said:

Hi Martin, here's what I see when running those commands:

Ok ! I figured out : my bad, it needs HEX prefix "0x" :

./devmem2 0x1F02C10 h

This should probably read 0x0480 or 0x0484 ...

Then, let's do the opposite level, if 0x0480, then write 0x0484, or the reverse :

./devmem2 0x1F02C10 h 0x0484

 

Link to comment
Share on other sites

  • 0
9 minutes ago, MarshallMCH said:

Hm, after I run:

What was the value returned by the reading ?

 

9 minutes ago, MarshallMCH said:

My board freezes,

Strange, with my board, it didn't freeze, and I was even able to toggle green power led by toggling its PL10 bit between 0x0080 and 0x0480 ...

 

Link to comment
Share on other sites

  • 0

Hi Martin, it does not hang, but still does not turn off the OTG port, unfortunately:

 

root@device:~# ./devmem2 0x1F02C10 h
/dev/mem opened.
Memory mapped at address 0xb6f70000.
Value at address 0x1F02C10 (0xb6f70c10): 0x784

root@device:~# ./devmem2 0x1F02C10 h 0x0780
/dev/mem opened.
Memory mapped at address 0xb6fb7000.
Value at address 0x1F02C10 (0xb6fb7c10): 0x784
Written 0x780; readback 0x780

root@device:~# ./devmem2 0x1F02C10 h 0x0784
/dev/mem opened.
Memory mapped at address 0xb6f02000.
Value at address 0x1F02C10 (0xb6f02c10): 0x780
Written 0x784; readback 0x784

 

Link to comment
Share on other sites

  • 0
6 minutes ago, MarshallMCH said:

but still does not turn off the OTG port, unfortunately

Can you provide output of "cat /sys/kernel/debug/gpio" ?

And maybe also output "./devmem2 0x1F02C04 w" ...

 

When you say OTG port, you are talking about MicroUSB, right ?

If not and you mean normal USB, then it is USB1-DRVVBUS that you need to switch, therefore PL3 instead of PL2, which mean the toggling value would be 0x780 and 0x788 ...

Link to comment
Share on other sites

  • 0

Here are the outputs:

 

cat /sys/kernel/debug/gpio
GPIOs 0-383, platform/sunxi-pinctrl, sunxi-pinctrl:
 gpio-15  (red_led             ) out lo
 gpio-16  (?                   ) out hi
 gpio-166 (cd                  ) in  hi
 gpio-354 (?                   ) out lo
 gpio-362 (green_led           ) out hi
./devmem2 0x1F02C04 w
/dev/mem opened.
Memory mapped at address 0xb6f1c000.
Illegal data type '▒'.

Yes, I am talking about the MicroUSB port.  Thanks!

Link to comment
Share on other sites

  • 0
12 minutes ago, MarshallMCH said:

gpio-354 (? ) out lo

Which kernel/image are you using ?

Because the output should be :

gpio-354 (                    |usb0-vbus           ) out lo

Could you reboot your OS and do again the "cat /sys/kernel/debug/gpio" right after login to see if gpio-354 is still shown the way you provided ?

 

You can also try with Armbian Mainline-DEV 5.1.y image, it is what I'm using ...

 

Link to comment
Share on other sites

  • 0

Here is the output of uname -a

Linux 3.4.113-sun8i #10 SMP PREEMPT Thu Feb 23 19:55:00 CET 2017 armv7l GNU/Linux

Here's the output after a fresh reboot:

 

cat /sys/kernel/debug/gpio
GPIOs 0-383, platform/sunxi-pinctrl, sunxi-pinctrl:
 gpio-15  (red_led             ) out lo
 gpio-16  (?                   ) out hi
 gpio-166 (cd                  ) in  hi
 gpio-354 (?                   ) out hi
 gpio-362 (green_led           ) out hi

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...