Jump to content

Control USB-OTG Power On/Off On Orange Pi One - Armbian Buster


Fionn

Recommended Posts

Armbianmonitor:

Hi all, 

 

I am hoping there is a straight forward solution to this;

 

I've read this thread on turning on and off the usb OTG using GPIO commands:

The concept is really clever and I was hoping to use it as part of my Octoprint 3D printing setup so that I can turn off printer when not in use. The only catch is that the method requires modifying the ./bin/orangepione.bin file which isn't present on my version of Armbian (Buster).

 

TL;DR according to the post I need to

1. convert ./bin/orangepione.bin to FEX, 

2.  edit the file by adding "usb_drv_vbus_gpio = port:PL02<1><0><default><0>",

3. convert it back to bin,

4. use the commands "echo 0 > /sys/class/gpio/gpio354/value" or "echo 1 > /sys/class/gpio/gpio354/value" to turn off/on the pin and thus usb.

 

Is there an equivalent file where I could modify the line "usb_drv_vbus_gpio =" which would allow me to control pin PL2?

 

Alternatively is it possible to control pin PL2 using the WiringOP? I am currently using it to control a relay however while looking into it I could not find any reference to PL2.

 

I'm fairly new to Linux and Armbian so any guidance at all would be very much appreciated.  

 

image.png.8803dff54aaaeb9a7df72e21d2a318c9.png

Link to comment
Share on other sites

  • Fionn changed the title to Control USB-OTG Power On/Off On Orange Pi One - Armbian Buster

Okay so I've made some progress but have hit a wall. 

 

I can access the gpio pins using sysfm, I was having a lot of permission issues due to the ">" symbol in the standard commands, e.g 

echo 354 > /sys/class/gpio/export

 

To excecute these commands I had to rewrite them as: 

 echo "354" | sudo tee /sys/class/gpio/export

or 

sudo sh -c 'echo "354" > /sys/class/gpio/export'


The issue I am having now is that I cannot export or control gpio-354 (PL2) in order to turn on and off the usb-otg port.  Anytime I attempt to I get the error 

Quote

 /sys/class/gpio/export: Device or resource busy

 

I can confirm this to be true as after running

sudo cat /sys/kernel/debug/gpio

I get 
 

Quote

gpiochip0: GPIOs 0-223, parent: platform/1c20800.pinctrl, 1c20800.pinctrl:
 gpio-15  (                    |orangepi:red:status   ) out lo
 gpio-166 (                    |cd                             ) in  lo ACTIVE LOW
 gpio-204 (                    |usb0_id_det              ) in  lo IRQ

gpiochip1: GPIOs 352-383, parent: platform/1f02c00.pinctrl, 1f02c00.pinctrl:
 gpio-354 (                    |usb0-vbus                ) out hi
 gpio-355 (                    |sw4                          ) in  hi IRQ ACTIVE LOW
 gpio-358 (                    |vdd-cpux                  ) out hi
 gpio-362 (                    |orangepi:green:pwr  ) out hi
 

 

My issue is that I do not know how override that control. I have changed the device tree (dtb) files multiple times changing the dr_mode from "otg" to "host" . Doing this successfully changes the gpio-354 output from lo to hi but I cannot change it without recompiling. 

 

                usb@1c19000 {
                        compatible = "allwinner,sun8i-h3-musb";
                        reg = < 0x1c19000 0x400 >;
                        clocks = < 0x03 0x20 >;
                        resets = < 0x03 0x11 >;
                        interrupts = < 0x00 0x47 0x04 >;
                        interrupt-names = "mc";
                        phys = < 0x0e 0x00 >;
                        phy-names = "usb";
                        extcon = < 0x0e 0x00 >;
                        dr_mode = "host";
                        status = "okay";
                        phandle = < 0x47 >;
                };

                phy@1c19400 {
                        compatible = "allwinner,sun8i-h3-usb-phy";
                        reg = < 0x1c19400 0x2c 0x1c1a800 0x04 0x1c1b800 0x04 0x1c$
                        reg-names = "phy_ctrl\0pmu0\0pmu1\0pmu2\0pmu3";
                        clocks = < 0x03 0x58 0x03 0x59 0x03 0x5a 0x03 0x5b >;
                        clock-names = "usb0_phy\0usb1_phy\0usb2_phy\0usb3_phy";
                        resets = < 0x03 0x00 0x03 0x01 0x03 0x02 0x03 0x03 >;
                        reset-names = "usb0_reset\0usb1_reset\0usb2_reset\0usb3_r$
                        status = "okay";
                        #phy-cells = < 0x01 >;
                        usb0_id_det-gpios = < 0x0c 0x06 0x0c 0x00 >;
                        usb0_vbus-supply = < 0x0f >;
                        phandle = < 0x0e >;
                };

 

Link to comment
Share on other sites

Digging a little bit more I've found this patch which was done to allow you to control pin PL2: 

https://github.com/armbian/build/commit/fb0d3c6ea4b06df236d198af825d31a073dd2b81

it seems to be for the orangepi PC but I assume there is a similar functionality for the orange pi one. or if not how could it be created?

 

secondly I've found this: 

https://github.com/ARM-software/u-boot/blob/master/arch/arm/dts/sun8i-h3-orangepi-one.dts

which contains

image.png.7ffd7fe6de57cea3e53820d83becf56f.png 

I could be wrong but I believe this is sets PL2 high. 

 

on the equivalent dts file on my computer I don't have that exact line however I do have: 

image.png.a20eaebf20af3fe0b3a069e126239604.png

Which I suspect is the same thing,  just in a different version, I am going to try and play around with this to see if it can be changed. What I'm unsure of is the second link above uses several includes at the start:

Quote

 

#include "sun8i-h3.dtsi"

#include "sunxi-common-regulators.dtsi"

#include <dt-bindings/gpio/gpio.h>

#include <dt-bindings/input/input.h>

 

Which I believe allows the user to write <&r_pio 0 2 GPIO_ACTIVE_HIGH> but I'm unsure.

 

If anyone has any experience in these it would be hugely appreciated, are there any resources for learning this type of thing? Very much new to this whole space. 

Link to comment
Share on other sites

GOT IT!!!!!! :D

 

Okay so reading this forum gave me the idea: 

 

The GPIO's under the control of the USB0-vbus which was blocking me from making any changes were listed in the dtb under: 

Quote

        usb0-vbus {
                compatible = "regulator-fixed";
                regulator-name = "usb0-vbus";
                regulator-min-microvolt = < 0x4c4b40 >;
                regulator-max-microvolt = < 0x4c4b40 >;
                enable-active-high;
                gpio = < 0x3b 0x00 0x02 0x00 >;
                status = "okay";
                phandle = < 0x0f >;
        };

 

A USB has 4 connections: 

"5v",

"Data -",

"data +",

"ground" 

 

As we know that PL2 (aka 354) is the power provided the gpio's listed above are in the same order the 1st one much be PL2. So I changed 

gpio = < 0x3b 0x00 0x02 0x00 >;  to 

gpio = < 0x00 0x02 0x00 >;

and then recompiled (use armbian-config >system >dtc to modify the dtb, it makes like 100x easier). Now by default the USB-OTG is off and using "lsusb"  shows no device, but when i run: 

echo "354" | sudo tee /sys/class/gpio/export

echo "out" | sudo tee /sys/class/gpio/gpio354/direction

echo "1" | sudo tee /sys/class/gpio/gpio354/value


It turns on! and I can turn it off again by running: 

echo "0" | sudo tee /sys/class/gpio/gpio354/value


I'm delighted and this is working really well without any issues.  The only thing I would like to do is to change the access so it doesn't require sudo to run the gpio commands if anyone knows how to do that please let me know. Alternatively I would love to use wiringOP to control the usb-otg but I'm not sure if it can, I might give it a try  anyway.

Link to comment
Share on other sites

I'll give the TL;DR version: 

1. sudo apt update && sudo apt upgrade

2. sudo armbian-config 

3. Scroll to  "system" then "Dtc" (as per attached image)

4.  search for: "usb@1c19000" (use ctrl+w for speed)

5. change dr_mode to "host and status to "okay" as below

                usb@1c19000 {
                        compatible = "allwinner,sun8i-h3-musb";
                        reg = < 0x1c19000 0x400 >;
                        clocks = < 0x03 0x20 >;
                        resets = < 0x03 0x11 >;
                        interrupts = < 0x00 0x47 0x04 >;
                        interrupt-names = "mc";
                        phys = < 0x0e 0x00 >;
                        phy-names = "usb";
                        extcon = < 0x0e 0x00 >;
                        dr_mode = "host";
                        status = "okay";
                        phandle = < 0x47 >;
                };

6. search for "usb0-vbus"

7. Change gpio to < 0x00 0x02 0x00 >; as below 

        usb0-vbus {
                compatible = "regulator-fixed";
                regulator-name = "usb0-vbus";
                regulator-min-microvolt = < 0x4c4b40 >;
                regulator-max-microvolt = < 0x4c4b40 >;
                enable-active-high;
                gpio = < 0x00 0x02 0x00 >;
                status = "okay";
                phandle = < 0x0f >;
        };

8. Save, exit and recompile

9. run lsusb and the otg device will not be listed 

10.  echo "354" | sudo tee /sys/class/gpio/export    #makes pin PL2 controllable

11. echo "out" | sudo tee /sys/class/gpio/gpio354/direction   #sets pin as an output 

12. echo "1" | sudo tee /sys/class/gpio/gpio354/value  #turns on the usb

13. run lsusb and otg device should be listed :D.

14.  echo "0" | sudo tee /sys/class/gpio/gpio354/value  #turns off the usb

15. you will need to run steps 10 and 11 each time the OPi one boots.

 

And there you have it!

image.png

Link to comment
Share on other sites

  • Werner featured this topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines