Re: control USB Power from linux

498 views
Skip to first unread message
Message has been deleted

mahdi taheri

unread,
Sep 24, 2013, 2:01:25 AM9/24/13
to linux...@googlegroups.com, stu....@gmail.com



On Monday, September 23, 2013 10:59:34 PM UTC-7, stu....@gmail.com wrote:
I want to control the power off my Usb Device conected to cubieboard (power off - power on the device  by usb1-drv or usb2-drv  )

I googled a lot and find this article http://e2e.ti.com/support/arm/sitara_arm/f/791/t/270060.aspx
but it is not for cubie can anybody help me for this issue?

according to attached image it must be a way to control USB1-DRV from Linux.
I have checked the usb power at startup and i see the power goes on when in terminal  report [sw-ehci1]: Set USB Power ON , but i dont know how it works.

<6>hub 2-0:1.0: USB hub found
[    1.894384] hub 2-0:1.0: USB hub found
<6>hub 2-0:1.0: 1 port detected
[    1.901073] hub 2-0:1.0: 1 port detected
[sw-ehci2]: open clock
[    1.907602] [sw-ehci2]: open clock
[sw-ehci2]: Set USB Power ON
[    1.923679] [sw-ehci2]: Set USB Power ON


if any body has an idea please help.

Oliver Schinagl

unread,
Sep 23, 2013, 7:38:56 PM9/23/13
to linux...@googlegroups.com
On 24-09-13 07:59, stu....@gmail.com wrote:
> I want to control the power off my Usb Device conected to cubieboard (power off - power on the device by usb1-drv or usb2-drv )
>
>
>
> I googled a lot and find this article http://e2e.ti.com/support/arm/sitara_arm/f/791/t/270060.aspx
> but it is not for cubie can anybody help me for this issue?
> But I'm not sure it expl
> according to attached image it must be a way to control USB1-DRV from Linux.
Technically, yes; the USB power is controlled via a GPIO. With the sunxi
kernel sources, this is all handled in the driver and via the FEX file.

Mainline will have a regulator device for these purposes allowing you to
toggle it at will I suppose.

If you want to manually toggle USB power, comment out the GPIO in fex,
and write a little program that toggles the GPIO in software for you.

Oliver

Arokux X

unread,
Sep 24, 2013, 8:16:55 AM9/24/13
to linux...@googlegroups.com
Hi,


On Tue, Sep 24, 2013 at 7:59 AM, <stu....@gmail.com> wrote:
I want to control the power off my Usb Device conected to cubieboard (power off - power on the device  by usb1-drv or usb2-drv  )
what is usb1-drv and usb2-drv?



I googled a lot and find this article http://e2e.ti.com/support/arm/sitara_arm/f/791/t/270060.aspx
but it is not for cubie can anybody help me for this issue?

according to attached image it must be a way to control USB1-DRV from Linux.
I have checked the usb power at startup and i see the power goes on when in terminal  report [sw-ehci1]: Set USB Power ON , but i dont know how it works.

<6>hub 2-0:1.0: USB hub found
[    1.894384] hub 2-0:1.0: USB hub found
<6>hub 2-0:1.0: 1 port detected
[    1.901073] hub 2-0:1.0: 1 port detected
[sw-ehci2]: open clock
[    1.907602] [sw-ehci2]: open clock
[sw-ehci2]: Set USB Power ON
[    1.923679] [sw-ehci2]: Set USB Power ON
The power to USB devices is turned on by setting a certain GPIO pin (likely PH06 or PH03 - check your fex config in sections usbc) to output one. If you figure out a way how to poke at that pins from user space just set them to output 0 to switch off the power and to output 1 to turn off the power.

Now, I do not know how to poke at GPIO pins from user space, So tell me if you find out.

Thanks,
Arokux
 


if any body has an idea please help.

--
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

jons...@gmail.com

unread,
Sep 24, 2013, 8:27:31 AM9/24/13
to linux...@googlegroups.com
sysfs interface...

http://squidge.sourceforge.net/gpio/


>
> Thanks,
> Arokux
>
>>
>>
>>
>> if any body has an idea please help.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "linux-sunxi" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to linux-sunxi...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to linux-sunxi...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
Jon Smirl
jons...@gmail.com

Arokux X

unread,
Sep 24, 2013, 8:28:52 AM9/24/13
to linux...@googlegroups.com
Well yes, but will it work in sunxi-3.4?

jons...@gmail.com

unread,
Sep 24, 2013, 8:34:52 AM9/24/13
to linux...@googlegroups.com
Fix the kernel if it doesn't work. The code is very simple. 90% of it
is implemented in gpiolib and doesn't need to be written again. The
same code that makes gpio sysfs work also handles gpio support in
device trees.

Good chance of it working in the sunxi kernel and not so likely in an
Allwinner kernel. I'm not in front of a system to check it on.

mahdi taheri

unread,
Sep 25, 2013, 2:38:01 AM9/25/13
to linux...@googlegroups.com


thanks a lot 

Patrick Wood

unread,
Oct 4, 2013, 3:54:23 PM10/4/13
to linux...@googlegroups.com
sysfs gpio has worked on A10 since at least 3.4.29 (I use it for sensing a switch) and on the A20 since early in 3.4.43.  The AW 3.3.0 A20 kernel also supported it.

Pat

Vincenzo Li Vigni

unread,
Mar 31, 2014, 12:48:06 PM3/31/14
to linux...@googlegroups.com
Hello people,
I've disabled these lines in script.bin:
usb_drv_vbus_gpio = port:PH06<1><0><default><0>
usb_drv_vbus_gpio = port:PH03<1><0><default><0>
in order to use them as standard GPIO, enabling to switch on and off the usb port.

The results is that I receive a super-kernel-panic at boot:

<6>ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    2.156913] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
<6>ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    2.168608] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
WRN:L104(drivers/usb/host/sw_hci_sunxi.c):[    2.178486] WRN:L104(drivers/usb/host/sw_hci_sunxi.c):ERR: get usbc1(usbc1) id failed
ERR: get usbc1(usbc1) id failed
WRN:L430(drivers/usb/host/sw_hci_sunxi.c):[    2.192860] WRN:L430(drivers/usb/host/sw_hci_sunxi.c):ERR: gpio_request failed
ERR: gpio_request failed
WRN:L816(drivers/usb/host/sw_hci_sunxi.c):[    2.206014] WRN:L816(drivers/usb/host/sw_hci_sunxi.c):ERR: alloc_pin failed
ERR: alloc_pin failed
WRN:L104(drivers/usb/host/sw_hci_sunxi.c):[    2.218657] WRN:L104(drivers/usb/host/sw_hci_sunxi.c):ERR: get usbc1(usbc1) id failed
ERR: get usbc1(usbc1) id failed
WRN:L430(drivers/usb/host/sw_hci_sunxi.c):[    2.233026] WRN:L430(drivers/usb/host/sw_hci_sunxi.c):ERR: gpio_request failed
ERR: gpio_request failed
WRN:L816(drivers/usb/host/sw_hci_sunxi.c):[    2.246177] WRN:L816(drivers/usb/host/sw_hci_sunxi.c):ERR: alloc_pin failed
ERR: alloc_pin failed
WRN:L104(drivers/usb/host/sw_hci_sunxi.c):[    2.258821] WRN:L104(drivers/usb/host/sw_hci_sunxi.c):ERR: get usbc2(usbc2) id failed
ERR: get usbc2(usbc2) id failed
WRN:L430(drivers/usb/host/sw_hci_sunxi.c):[    2.273189] WRN:L430(drivers/usb/host/sw_hci_sunxi.c):ERR: gpio_request failed
ERR: gpio_request failed
WRN:L816(drivers/usb/host/sw_hci_sunxi.c):[    2.286342] WRN:L816(drivers/usb/host/sw_hci_sunxi.c):ERR: alloc_pin failed
ERR: alloc_pin failed
WRN:L104(drivers/usb/host/sw_hci_sunxi.c):[    2.298985] WRN:L104(drivers/usb/host/sw_hci_sunxi.c):ERR: get usbc2(usbc2) id failed
ERR: get usbc2(usbc2) id failed
WRN:L430(drivers/usb/host/sw_hci_sunxi.c):[    2.313354] WRN:L430(drivers/usb/host/sw_hci_sunxi.c):ERR: gpio_request failed
ERR: gpio_request failed
WRN:L816(drivers/usb/host/sw_hci_sunxi.c):[    2.326507] WRN:L816(drivers/usb/host/sw_hci_sunxi.c):ERR: alloc_pin failed
ERR: alloc_pin failed
<1>Unable to handle kernel NULL pointer dereference at virtual address 00000000
[    2.342599] Unable to handle kernel NULL pointer dereference at virtual address 00000000
<1>pgd = c0004000
[    2.352363] pgd = c0004000
<1>[00000000] *pgd=00000000[    2.357427] [00000000] *pgd=00000000

It does look clear that the kernel tries to take control of the gpio used to switch on the TCS9708 IC (which powers the USB as you can see from Cubiebooard schematic) but it fails.
I'm thinking I should edit something in kernel sources, but I'd like to ask you if I'm doing somehow wrong and/or there are other ways,
Thanks in advance.

Vincenzo

Vincenzo Li Vigni

unread,
Apr 1, 2014, 4:56:25 AM4/1/14
to linux...@googlegroups.com, stu....@gmail.com
OK. It did work in this (ugly) way:

USB1 USB2
ON ON ./devmem2 0x1c2090c w 0x180078
ON OFF ./devmem2 0x1c2090c w 0x180038
OFF ON ./devmem2 0x1c2090c w 0x180070
OFF OFF ./devmem2 0x1c2090c w 0x180030

USB1 is (for me) the upper usb port. 0x1c2090c is the memory address of Port H Data register and the last argument is the word to write in that register. You can get devmem2 (direct access to memory using /dev/mem) on the web or attached here (binary compiled for A10 here: https://dl.dropboxusercontent.com/u/848639/keep/devmem2).
NOTE that this works on the Cubieboard (A10) only, since it provides an electronic switch on both usb ports. Maybe you can use a similar approach on other boards with similar switches on board.
Hope it helps,

Vincenzo
devmem2.c

Linus Ivanov

unread,
Nov 4, 2015, 1:11:45 PM11/4/15
to linux-sunxi, stu....@gmail.com
Usb power can be controlled by corresponding gpio.
There is sunxi-pio utility from sunxi-tools.

For example
To power off usb port:
./sunxi-pio -m PH6'<default><default<default><0>'
To power it up again:
./sunxi-pio -m PH6'<default><default<default><1>'

To find gpio port used to control usb power, see usb_drv_vbus_gpio in your fex.


вторник, 1 апреля 2014 г., 11:56:25 UTC+3 пользователь Vincenzo Li Vigni написал:
Reply all
Reply to author
Forward
0 new messages