Jump to content

Banana Pi USB OTG


pspcoelho

Recommended Posts

Hi,

 

 I've read a previous topic about it but it was a bit inconclusive. My question is simple: can the OTG port be turned on on the legacy kernel? Is it just a matter of setting up the right bits in the script.bin/fex file? Or is it missing some other stuff?

 

 Currently I can use that port on Bananian. Since this board only has 2 USB ports, it's nice to be able to use the OTG port to connect a keyboard, since the other 2 ports have HDDs connected.

 

Thanks and good work!!

Link to comment
Share on other sites

Hi again!

 

 A couple of days after I posted this question I changed the script.bin to enable the USB port. Actually, it doesn't have to be "OTG" mode, just regular USB. The 2 settings that define this must be set together:

 

  • [usbc0]

  • usb_port_type = 1 // 2=USB OTG [default], 1=USB Normal

  • usb_detect=type = 0 // 1=USB OTG [default], 0=USB Normal

 

The actual values (in the downloaded Armbian image) don't work either way since they are 1 and 1, I think.

 

Regarding vanilla kernel, is it possible to turn on this USB port? I read that this kernel uses something called Device Tree.

 

Cheers.

Link to comment
Share on other sites

USB OTG controller support is present in mainline starting with kernel version 4.3. Current armbian vanilla kernel has version 4.2.3.

You'll have to wait for new kernel release for armbian or compile 4.3 yourself, after that enabling OTG in Device Tree is relatively easy.

@Igor: I checked 4.3 source tree, for some reason OTG controller is not enabled in sun7i-a20-bananapi.dts, although it is enabled for cubietruck.

 

Edit: however, section "Planned for 4.4" on Linux mainlining effort wiki page says

AXP202/AXP209

  • USB power supply driver
  • Support for OTG vbus detection via AXP pmic
  • DTS nodes for OTG vbus support

so OTG support may depend on board specific power wirings.

Link to comment
Share on other sites

For OTG you need to go for 4.4.something. 4.3.3 have only host mode ... which is tested by me, with OTG i haven't done anything ... .try this:

apt-get install linux-image-dev-sunxi linux-dtb-dev-sunxi

... or build latest.

Link to comment
Share on other sites

Thank you....

 

ok. I haven't tried host mode yet... I have no use case so far :unsure:

 

I build the latest by using your lib last night... I will try this image today...

 

But maybe I have to wait for final release for productive use... I already tried rc5 and it was not stable...

Link to comment
Share on other sites

OTG port support was introduced not long time ago and it's currently working only on host mode. It should also in OTG but it does not.

 

In recent kernels hardware definitions are located in DTB files /boot/dtb

 

Procedure is similar to script.bin - you need to convert it to text, alter and compile back and reboot for changes.

 

... or wait a while and I'll enable it by default soon. I already did for normal bananas.

Link to comment
Share on other sites

hi all,
 I read the other topic about "Banana Pi USB OTG" in preparation of trying to enable USB OTG (device mode actually) on a Banana Pi M2 (A31s). When my Pi arrived yesterday, I performed  the following steps:
  
 I now have "uname -r" -> "4.4.1-sunxi", and "dpkg -l" lists "linux-*-next-sunxi" (*=dtb|firmware|headers|image) in version 5.01.
 I was happy to find that the g_* kernel modules were present (with the exception of g_zero), but
 
root@bananapim2:~# modprobe g_hid
 modprobe: ERROR: could not insert 'g_hid': No such device

 OK, so i checked the Device Tree file /boot/dtb/sun6i-a31s-sinovoip-bpi-m2.dtb

 To decompile it, I ran:
dtc -I dtb sun6i-a31s-sinovoip-bpi-m2.dtb -O dts -o sun6i-a31s-sinovoip-bpi-m2.dts

 When checking the DTS file, i found the musb controller, which was disabled:

usb@01c19000 {
                        compatible = "allwinner,sun6i-a31-musb";
                        reg = <0x1c19000 0x400>;
                        clocks = <0x10 0x18>;
                        resets = <0x11 0x18>;
                        interrupts = <0x0 0x47 0x4>;
                        interrupt-names = "mc";
                        phys = <0x1d 0x0>;
                        phy-names = "usb";
                        extcon = <0x1d 0x0>;
                        status = "disabled";
                };

So I changed the "disabled" into "okay" and added dr_mode="otg" to the DTS:

usb@01c19000 {
                        compatible = "allwinner,sun6i-a31-musb";
                        reg = <0x1c19000 0x400>;
                        clocks = <0x10 0x18>;
                        resets = <0x11 0x18>;
                        interrupts = <0x0 0x47 0x4>;
                        interrupt-names = "mc";
                        phys = <0x1d 0x0>;
                        phy-names = "usb";
                        extcon = <0x1d 0x0>;
                        dr_mode = "otg";
                        status = "okay";
                };

Then i compiled it back into the DTB file:

dtc -I dts sun6i-a31s-sinovoip-bpi-m2.dts -O dtb -o sun6i-a31s-sinovoip-bpi-m2.dtb

 After a reboot, the modprobe problem is still there. Also in dmesg, nothing shows up about musb:

root@bananapim2:/boot/dtb# dmesg | grep "usb"
[    3.203261] usbcore: registered new interface driver usbfs
[    3.203316] usbcore: registered new interface driver hub
[    3.203380] usbcore: registered new device driver usb
[    3.388457] ehci-platform 1c1a000.usb: EHCI Host Controller
[    3.388487] ehci-platform 1c1a000.usb: new USB bus registered, assigned bus number 1
[    3.388738] ehci-platform 1c1a000.usb: irq 31, io mem 0x01c1a000
[    3.404952] ehci-platform 1c1a000.usb: USB 2.0 started, EHCI 1.00
[    3.405229] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[    3.405241] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    3.405250] usb usb1: Product: EHCI Host Controller
[    3.405259] usb usb1: Manufacturer: Linux 4.4.1-sunxi ehci_hcd
[    3.405267] usb usb1: SerialNumber: 1c1a000.usb
[    3.406519] ohci-platform 1c1a400.usb: Generic Platform OHCI controller
[    3.406544] ohci-platform 1c1a400.usb: new USB bus registered, assigned bus number 2
[    3.406657] ohci-platform 1c1a400.usb: irq 32, io mem 0x01c1a400
[    3.469165] usb usb2: New USB device found, idVendor=1d6b, idProduct=0001
[    3.469177] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    3.469185] usb usb2: Product: Generic Platform OHCI controller
[    3.469194] usb usb2: Manufacturer: Linux 4.4.1-sunxi ohci_hcd
[    3.469202] usb usb2: SerialNumber: 1c1a400.usb
[    3.470269] usbcore: registered new interface driver usb-storage
[    3.506676] usbcore: registered new interface driver usbhid
[    3.506682] usbhid: USB HID core driver
[    3.724966] usb 1-1: new high-speed USB device number 2 using ehci-platform
[    3.875545] usb 1-1: New USB device found, idVendor=1a40, idProduct=0101
[    3.875558] usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[    3.875567] usb 1-1: Product: USB 2.0 Hub
[    4.174962] usb 1-1.3: new low-speed USB device number 3 using ehci-platform
[    4.314881] usb 1-1.3: New USB device found, idVendor=046a, idProduct=0011
[    4.314902] usb 1-1.3: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    4.327046] input: HID 046a:0011 as /devices/platform/soc@01c00000/1c1a000.usb/usb1/1-1/1-1.3/1-1.3:1.0/0003:046A:0011.0001/input/input0
[    4.385300] hid-generic 0003:046A:0011.0001: input,hidraw0: USB HID v1.11 Keyboard [HID 046a:0011] on usb-1c1a000.usb-1.3/input0
So is musb currently still disabled for a reason on BPi-M2 (Igor mentioned such in the other thread in March)  ? Or am I doing something wrong?
Hardware setup wise, I just connected the microUSB to my notebooks A port (power seems sufficient) using a normal cable.
 
Ah yeah, and big thanks Igor for this awesome distro and the community for bringing insight about usb OTG mode.
 
regards,
 
Paul
 
 
 
 
Link to comment
Share on other sites

It has been some time when I was playing around musb ... It works on A20, here I didn't try. Anyway try on latest kernel and try this:

modprobe sunxi

:P Thanks.

Link to comment
Share on other sites

Hi Igor,

 thanks for your lightning fast reply! by latest kernel you mean switching to the dev kernel, right? And also, the modprobe sunxi didnt throw any errors, but also no change. If the musb subsystem worked, there would be something about that in dmesg, right?

So as long as I don't get these dmesg musb messages, any later changes (like modprobing the sunxi thingy) won't bring success, if i am not mistaken with my limited linux knowledge.

I will try the dev kernels this evening.

 

Regards,

 

Paul

 

Link to comment
Share on other sites

Hi, I will now try to switch to the debug kernel manually using apt-get. To do so, i will first remove "linux-*-next-sunxi" (*=dtb|firmware|headers|image) :

sudo apt-get remove linux-dtb-next-sunxi linux-firmware-next-sunxi linux-headers-next-sunxi linux-image-next-sunxi 

linux-jessie-root-next-bananapim2 (root tweaks) has no dev counterpart in the repo (only linux-jessie-root-bananapim2 without any tags). Both have latest version 5.00, so which one shall i choose? The existing next one or the one without a declarator (linux-jessie-root-bananapim2)?

 

and then i will install the dev counterparts:

sudo apt-get install linux-dtb-dev-sunxi linux-firmware-dev-sunxi linux-headers-dev-sunxi linux-image-dev-sunxi 

As the repo also includes a custom uboot for dev, i will install it too (but theres nothing to uninstall as the uboot package is not installed atm):

sudo apt-get install linux-u-boot-bananapim2-dev

Then I will reboot and hopefully still have a working system, but switched to dev kernel, right?

And the selection of the root fs tweaks package does not even matter maybe because of the same version?

 

Regards,

 

Paul

Link to comment
Share on other sites

hmm, your installer does not list the banana pi m2. so i'll have to switch manually?

does that happen by me uninstalling the old packages and installing the dev one?

 

You mean upgrade installer?  upgrade.armbian.com ?

 

I was referring to build own image or at least kernel from sources, starting from here:

https://github.com/igorpecovnik/lib

 

If you stick to latest dev, you have best chances around a31 chip.

Link to comment
Share on other sites

Hi there,

 I sent the M2 back and got me a bananaPRO, hoping it would work out of the box with the vanilla kernel. Problem is, it does not work.

I am on 4.4.3-sunxi now, and by default, the DR_MODE was "host". In this setting i get musb logs in dmesg. BUT if i change it to "otg", theres no more musb logs in dmesg AND modprobe g_hid still fails with the error device not found.

There should be musb logs in dmesg regardless of the DR_MODE, right?

 

Can you give me some more advice? Shall i switch to dev? Or try the legacy version?

 

Regards,

 

Paul

Link to comment
Share on other sites

Okay, so i wanted to try the dev and legacy kernels. Is it possible the dev kernel for bananaPi is also not supported by the installer?

So to check them out i need to remove and add the packages as mentioned before manually?

 

Regards,

 

Paul

 

EDIT: I tried switching to DEV, and its also not working there (4.5.0-rc3). No dmesg musb logs at all (and no ethernet for some reason). So next step would be trying the legacy kernel.

Link to comment
Share on other sites

Hi Erpomata,

Up. Now with kernel 4.7.3

 

I have found solution to use USB OTG on Lime2 (A20) boards last tested on Kernel 4.5 but should work on 4.7 as well.

Unfortunately, I could not set and use it in OTG mode even all say it should work.

 

On the other hand USB hangs was encountered by me - see here and here.

That is why I have decided to use only USB Hosts with adding of USB Hub (incl. USB to Ethernet adapter in it).

 

I need to use WiFi, GPS, Ethernet and Flash USB adapters and dongles (some of them optionally) which is possible thanks to 1A power feature of USB1 port on Lime2.

 

Any way I am interested in using of USB OTG port (because of no extra power consumption) in otg or at least in host mode but without described hangs.

 

Best regards

Chris

 

Link to comment
Share on other sites

Hi to All,

Hi Erpomata,

 

I have found solution to use USB OTG on Lime2 (A20) boards last tested on Kernel 4.5 but should work on 4.7 as well.

It is proved to work on Kernel 4.7.6 and can be tested without Kernel build using following procedure:

cp /boot/dtb/sun7i-a20-olinuxino-lime2-emmc.dtb .
dtc -I dtb -O dts -o sun7i-a20-olinuxino-lime2-emmc.dts sun7i-a20-olinuxino-lime2-emmc.dtb
nano sun7i-a20-olinuxino-lime2-emmc.dts

Change and remove to fit following:

 

 

                usb@01c13000 {
                        compatible = "allwinner,sun4i-a10-musb";
                        reg = <0x1c13000 0x400>;
                        clocks = <0x4 0x0>;
                        interrupts = <0x0 0x26 0x4>;
                        interrupt-names = "mc";
                        phys = <0x26 0x0>;
                        phy-names = "usb";
                        extcon = <0x26 0x0>;
                        allwinner,sram = <0x27 0x1>;
                        status = "okay";
                        dr_mode = "host";
                        linux,phandle = <0x5f>;
                        phandle = <0x5f>;
                };

                phy@01c13400 {
                        #phy-cells = <0x1>;
                        compatible = "allwinner,sun7i-a20-usb-phy";
                        reg = <0x1c13400 0x10 0x1c14800 0x4 0x1c1c800 0x4>;
                        reg-names = "phy_ctrl", "pmu1", "pmu2";
                        clocks = <0x28 0x8>;
                        clock-names = "usb_phy";
                        resets = <0x28 0x0 0x28 0x1 0x28 0x2>;
                        reset-names = "usb0_reset", "usb1_reset", "usb2_reset";
                        status = "okay";
                        usb0_vbus-supply = <0x2b>;
                        usb1_vbus-supply = <0x2c>;
                        usb2_vbus-supply = <0x2d>;
                        linux,phandle = <0x26>;
                        phandle = <0x26>;
                };

 

 

where the original staff is:

 

 

                usb@01c13000 {
                        compatible = "allwinner,sun4i-a10-musb";
                        reg = <0x1c13000 0x400>;
                        clocks = <0x4 0x0>;
                        interrupts = <0x0 0x26 0x4>;
                        interrupt-names = "mc";
                        phys = <0x26 0x0>;
                        phy-names = "usb";
                        extcon = <0x26 0x0>;
                        allwinner,sram = <0x27 0x1>;
                        status = "okay";
                        dr_mode = "otg";
                        linux,phandle = <0x5f>;
                        phandle = <0x5f>;
                };

                phy@01c13400 {
                        #phy-cells = <0x1>;
                        compatible = "allwinner,sun7i-a20-usb-phy";
                        reg = <0x1c13400 0x10 0x1c14800 0x4 0x1c1c800 0x4>;
                        reg-names = "phy_ctrl", "pmu1", "pmu2";
                        clocks = <0x28 0x8>;
                        clock-names = "usb_phy";
                        resets = <0x28 0x0 0x28 0x1 0x28 0x2>;
                        reset-names = "usb0_reset", "usb1_reset", "usb2_reset";
                        status = "okay";
                        pinctrl-names = "default";
                        pinctrl-0 = <0x29 0x2a>;
                        usb0_id_det-gpio = <0x21 0x7 0x4 0x0>;
                        usb0_vbus_det-gpio = <0x21 0x7 0x5 0x0>;
                        usb0_vbus-supply = <0x2b>;
                        usb1_vbus-supply = <0x2c>;
                        usb2_vbus-supply = <0x2d>;
                        linux,phandle = <0x26>;
                        phandle = <0x26>;
                };

 

 

and the difference is:

root@egpr:~# diff sun7i-a20-olinuxino-lime2-emmc.dts.orig sun7i-a20-olinuxino-lime2-emmc.dts
830c830
<                       dr_mode = "otg";
---
>                       dr_mode = "host";
845,848d844
<                       pinctrl-names = "default";
<                       pinctrl-0 = <0x29 0x2a>;
<                       usb0_id_det-gpio = <0x21 0x7 0x4 0x0>;
<                       usb0_vbus_det-gpio = <0x21 0x7 0x5 0x0>;

Re-compile device tree, copy it back to /boot/dtb/ and reboot

dtc -I dts -O dtb -o sun7i-a20-olinuxino-lime2-emmc.dtb sun7i-a20-olinuxino-lime2-emmc.dts
cp sun7i-a20-olinuxino-lime2-emmc.dtb /boot/dtb/
reboot

USB device can be connected to OTG port via USB OTG cable and registered in the system.

You will see musb massages at 'dmesg' and corresponding Bus Device in 'lsusb' printout.

 

The procedure can be applied for other boards using corresponding DT file.

Some of the staff may differ from Lime2-eMMC one above.

 

Best regards

Chris

Link to comment
Share on other sites

Hello to all,
i tried to do what you have recommended, but on my lamobo r1 did not work.
Also the only usb port (not OTG) available has been disabled

This is the error that I noticed when starting:

[    3.741379] sun4i-usb-phy 1c13400.phy: usb0_id_det missing or invalid
 

 

These are the changes

		usb@01c13000 {
			compatible = "allwinner,sun4i-a10-musb";
			reg = <0x1c13000 0x400>;
			clocks = <0x4 0x0>;
			interrupts = <0x0 0x26 0x4>;
			interrupt-names = "mc";
			phys = <0x29 0x0>;
			phy-names = "usb";
			extcon = <0x29 0x0>;
			allwinner,sram = <0x2a 0x1>;
			status = "okay";
			dr_mode = "host";
			linux,phandle = <0x63>;
			phandle = <0x63>;
		};

		phy@01c13400 {
			#phy-cells = <0x1>;
			compatible = "allwinner,sun7i-a20-usb-phy";
			reg = <0x1c13400 0x10 0x1c14800 0x4 0x1c1c800 0x4>;
			reg-names = "phy_ctrl", "pmu1", "pmu2";
			clocks = <0x2b 0x8>;
			clock-names = "usb_phy";
			resets = <0x2b 0x0 0x2b 0x1 0x2b 0x2>;
			reset-names = "usb0_reset", "usb1_reset", "usb2_reset";
			status = "okay";
			usb0_vbus_power-supply = <0x2d>;
			usb0_vbus-supply = <0x2e>;
			usb1_vbus-supply = <0x2f>;
			usb2_vbus-supply = <0x30>;
			linux,phandle = <0x29>;
			phandle = <0x29>;
		};

Diff

diff sun7i-a20-lamobo-r1.dts sun7i-a20-lamobo-r1.dts.orig 
819c819
< 			dr_mode = "host";
---
> 			dr_mode = "otg";
833a834,836
> 			pinctrl-names = "default";
> 			pinctrl-0 = <0x2c>;
> 			usb0_id_det-gpio = <0x25 0x7 0x4 0x0>;

thank you so much

 

 

Link to comment
Share on other sites

Hi Erpomata,

Hello to all,
i tried to do what you have recommended, but on my lamobo r1 did not work.
Also the only usb port (not OTG) available has been disabled

As I can see USB Host ports for Lamobo r1 are disabled by default and have to be enabled.
Search for 'echiX' and 'ochiX' where X can be 0 or 1 and change status to 'okay'
 

This is the error that I noticed when starting:
[    3.741379] sun4i-usb-phy 1c13400.phy: usb0_id_det missing or invalid

This error mean that 'usb0_id_det' is somewhere in dtb 1c13400.phy node.
Try to search for and remove it from final dts file.

You may also remove from 'pio' node whole section for 'usb0_id_detect_pin'.
 

These are the changes

		usb@01c13000 {
			compatible = "allwinner,sun4i-a10-musb";
			reg = <0x1c13000 0x400>;
			clocks = <0x4 0x0>;
			interrupts = <0x0 0x26 0x4>;
			interrupt-names = "mc";
			phys = <0x29 0x0>;
			phy-names = "usb";
			extcon = <0x29 0x0>;
			allwinner,sram = <0x2a 0x1>;
			status = "okay";
			dr_mode = "host";
			linux,phandle = <0x63>;
			phandle = <0x63>;
		};

		phy@01c13400 {
			#phy-cells = <0x1>;
			compatible = "allwinner,sun7i-a20-usb-phy";
			reg = <0x1c13400 0x10 0x1c14800 0x4 0x1c1c800 0x4>;
			reg-names = "phy_ctrl", "pmu1", "pmu2";
			clocks = <0x2b 0x8>;
			clock-names = "usb_phy";
			resets = <0x2b 0x0 0x2b 0x1 0x2b 0x2>;
			reset-names = "usb0_reset", "usb1_reset", "usb2_reset";
			status = "okay";
			usb0_vbus_power-supply = <0x2d>;
			usb0_vbus-supply = <0x2e>;
			usb1_vbus-supply = <0x2f>;
			usb2_vbus-supply = <0x30>;
			linux,phandle = <0x29>;
			phandle = <0x29>;
		};
Diff
diff sun7i-a20-lamobo-r1.dts sun7i-a20-lamobo-r1.dts.orig 
819c819
< 			dr_mode = "host";
---
> 			dr_mode = "otg";
833a834,836
> 			pinctrl-names = "default";
> 			pinctrl-0 = <0x2c>;
> 			usb0_id_det-gpio = <0x25 0x7 0x4 0x0>;

thank you so much

 

 
'usb0_vbus_power-supply ...' is missing in my configuration but maybe it is not wrong.
 
And finally be sure you compile final dts file and overwrite with produced dtb one the file in /boot/dtb/.
 
Best regards
Chris

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines