USB host

From Openmoko

(Difference between revisions)
Jump to: navigation, search
m (Neo 1973 USB host moved to USB host: With rare exception, the contents of this page refer to all Neos, so we remove 1973. Furthermore, since the only product is Neo, there is no need to state that either.)
(Selecting USB host modes: adding qtmoko v36 node)
 
(57 intermediate revisions by 24 users not shown)
Line 1: Line 1:
== USB host ==
+
{{Languages|USB host}}
 
The mini-USB port on both the Neo 1973 and the Neo FreeRunner supports both USB host and USB device. This opens up a range of possibilities, such as adding USB cameras and USB input devices.
 
The mini-USB port on both the Neo 1973 and the Neo FreeRunner supports both USB host and USB device. This opens up a range of possibilities, such as adding USB cameras and USB input devices.
  
By default, the mini-USB port is in device mode. To tell the device that it is logically a host:
+
=== Using USB host mode ===
 +
==== Selecting USB host modes ====
 +
'''Please take into account that due to kernel changes sysfs paths can change, if you can't find a particular node, just use the “find” command'''
  
echo "host" > /sys/devices/platform/s3c2410-ohci/usb_mode
+
By default, the mini-USB port is in device mode. To tell the Neo that it is logically a host¹:
  
Instruct the device to provide 5 volts (not available on Neo 1973):
+
# echo host > [[GTA02 sysfs|/sys]]/devices/platform/s3c2410-ohci/usb_mode
  
  echo "1" > /sys/devices/platform/neo1973-pm-host.0/hostmode
+
Independent of the logical mode of the USB port, the Neo FreeRunner can provide 5 volt USB power to an attached USB device. To enable this (not available on Neo 1973):
 +
 
 +
  # echo 1 > /sys/devices/platform/neo1973-pm-host.0/hostmode
 +
 
 +
Please note, on my fairly new kernel (andy-tracking commit de8460932576502fb6bf61968a37c4d2aed2d6e2), this node is in /sys/devices/platform/s3c2440-i2c/i2c-adapter/i2c-0/0-0073/neo1973-pm-host.0/hostmode . And from 901d73fe51f33032b34b2ae5612eb863ec90532a Wed Apr 8 commit, usb_mode node is at /sys/devices/platform/s3c-ohci/usb_mode .
  
 
Note: You may want to run <code>ifconfig usb0 down</code> prior to switching to USB host mode, as the Neo's USB networking may not like having its USB port disappear. You'll probably want to ssh into your Neo over WiFi or Bluetooth before starting all of this, alternatively use an on screen keyboard.
 
Note: You may want to run <code>ifconfig usb0 down</code> prior to switching to USB host mode, as the Neo's USB networking may not like having its USB port disappear. You'll probably want to ssh into your Neo over WiFi or Bluetooth before starting all of this, alternatively use an on screen keyboard.
 +
 +
Note that in full USB host mode the FreeRunner will power the external device. To avoid draining the battery use a powered USB hub, then on the FreeRunner enable logical host mode:
 +
 +
# echo host > /sys/devices/platform/s3c2410-ohci/usb_mode
 +
 +
but NOT electrical host mode
 +
 +
# echo 0 > /sys/devices/platform/neo1973-pm-host.0/hostmode
 +
 +
Note that powered USB hubs do not send power upstream, that is, into the host. If you wish to power or charge the FreeRunner, you will need a [[Specialized USB cables|special USB cable]].
 +
 +
¹)Debian note: You'll need the ohci-hcd module:
 +
modprobe ohci-hcd
 +
 +
* NOTE: with [FSO] based distributions one should use the [[Dbus device API|dbus APIs]] and not the method stated above.
 +
 +
===== Qtmoko v36 (*) =====
 +
As of Qtmoko v36 (kernel 2.6.34-qtmoko):
 +
 +
'''To turn on power mode:'''
 +
 +
  #echo 1 > /sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio.0/reg-fixed-voltage.2/gta02-pm-usbhost.0/power_on
 +
 +
'''To switch to usb host mode:'''
 +
 +
  #echo host > /sys/devices/platform/s3c2410-ohci/usb_mode
 +
 +
'''To turn off power mode:'''
 +
 +
  #echo 0 > /sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio.0/reg-fixed-voltage.2/gta02-pm-usbhost.0/power_on
 +
 +
'''To switch to usb device mode:'''
 +
 +
  #echo device > /sys/devices/platform/s3c2410-ohci/usb_mode
 +
 +
(*)source: [http://permalink.gmane.org/gmane.comp.handhelds.openmoko.community/58783]
 +
 +
==== Returning to USB device mode ====
 +
After doing whatever is needed to safely remove your device and unplugging it you can remove the provision of 5 volt power and return to device mode.
 +
 +
echo 0 > /sys/devices/platform/neo1973-pm-host.0/hostmode<BR>
 +
echo device > /sys/devices/platform/s3c2410-ohci/usb_mode
 +
 +
You can now safely restart USB networking
 +
 +
ifconfig usb0 up
 +
 +
==== USB-Mode-Script====
 +
This simple script switches between USB-Modes:
 +
 +
#!/bin/sh
 +
grep -q 'host' /sys/devices/platform/s3c2410-ohci/usb_mode
 +
if [ $? -eq 0 ]
 +
then
 +
echo 0 > /sys/devices/platform/neo1973-pm-host.0/hostmode
 +
echo device > /sys/devices/platform/s3c2410-ohci/usb_mode
 +
ifconfig usb0 up
 +
echo USB-Port is in device-mode now.
 +
else
 +
ifconfig usb0 down
 +
echo host > /sys/devices/platform/s3c2410-ohci/usb_mode
 +
echo 1 > /sys/devices/platform/neo1973-pm-host.0/hostmode
 +
lsusb
 +
echo USB-Port is in host-mode now.
 +
fi
 +
 +
See this [https://docs.openmoko.org/trac/ticket/2166 bug] for a justification for adding the lsusb hack.
 +
 +
==== USB-Mode-Script (2.6.28+ kernels) ====
 +
The paths change slightly since 2.6.28:
 +
 +
#!/bin/sh
 +
grep -q 'host' /sys/devices/platform/s3c2410-ohci/usb_mode
 +
if [ $? -eq 0 ]
 +
then
 +
echo 0 > '''/sys/class/i2c-adapter/i2c-0/0-0073'''/neo1973-pm-host.0/hostmode
 +
echo device > /sys/devices/platform/s3c2410-ohci/usb_mode
 +
ifconfig usb0 up
 +
echo USB-Port is in device-mode now.
 +
else
 +
ifconfig usb0 down
 +
echo host > /sys/devices/platform/s3c2410-ohci/usb_mode
 +
echo 1 > '''/sys/class/i2c-adapter/i2c-0/0-0073'''/neo1973-pm-host.0/hostmode
 +
lsusb
 +
echo USB-Port is in host-mode now.
 +
fi
 +
 +
Note: For me (2.6.29-rc3), it is /sys/devices/platform/s3c-ohci/usb_mode ...
 +
 +
==== USB-Mode-Script (universal for all kernels) ====
 +
#!/bin/sh
 +
 +
USB_MODE=/sys/devices/platform/s3c-ohci/usb_mode
 +
if [ ! -f ${USB_MODE} ] ; then
 +
  USB_MODE=/sys/devices/platform/s3c2410-ohci/usb_mode
 +
fi
 +
if [ ! -f ${USB_MODE} ] ; then
 +
  echo "Cannot find usb_mode sysfs node"; exit 2
 +
fi
 +
 +
POWER=/sys/devices/platform/neo1973-pm-host.0/hostmode
 +
if [ ! -f ${POWER} ] ; then
 +
  POWER=/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio/reg-fixed-voltage.2/gta02-pm-usbhost.0/power_on
 +
fi
 +
if [ ! -f ${POWER} ] ; then
 +
  POWER=/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio.0/reg-fixed-voltage.2/gta02-pm-usbhost.0/power_on
 +
fi
 +
if [ ! -f ${POWER} ] ; then
 +
  POWER=/sys/class/i2c-adapter/i2c-0/0-0073/neo1973-pm-host.0/hostmode
 +
fi
 +
if [ ! -f ${POWER} ] ; then
 +
  echo "Cannot find power hostmode sysfs node"; exit 3
 +
fi
 +
 +
echo "USB_MODE = ${USB_MODE}"
 +
echo "POWER = ${POWER}"
 +
 +
grep -q 'host' ${USB_MODE}
 +
if [ $? -eq 0 ]; then
 +
  echo 0 > ${POWER}
 +
  echo device > ${USB_MODE}
 +
  ifconfig usb0 up
 +
  echo USB-Port is in device-mode now.
 +
else
 +
  ifconfig usb0 down
 +
  echo host > ${USB_MODE}
 +
  echo 1 > ${POWER}
 +
  lsusb
 +
  echo USB-Port is in host-mode now.
 +
fi
 +
 +
==== Using a GUI ====
 +
* Using the packaged push button derived from the script above: [http://blogs.thehumanjourney.net/finds/resource/usbmode-button_0.3_armv4t.ipk Download]
 +
* [[User:Techiem2|Mark D. Montgomery II]]'s [http://techiem2.net/index.php?/archives/10-Freerunner-USB-Mode-Control-Program.html application] controls all the various modes through a GUI
 +
* Thomas Vesely's [http://projects.openmoko.org/projects/usbchmod/ project]
 +
* Using the gtk+ gui [[Framework-settings]]
 +
* Using [http://projects.openmoko.org/projects/panel-plugin openmoko-panel-plugin]
  
 
=== Providing power to connected USB devices while in host mode ===
 
=== Providing power to connected USB devices while in host mode ===
  
Normally, USB host ports provide power to any connected USB device. In the case of portable handheld devices, this power may be limited. (Usually the battery is sized to power the handheld device alone, and to maximize standby time.)
+
Normally, USB host ports provide power to any connected USB device.
  
Available power in host mode is limited to 500mA on the Neo FreeRunner, and no power is available in host mode on the Neo 1973. If your USB devices consumes less than 500mA, you may connect it directly to your Neo FreeRunner.
+
Available power in host mode is the full maximum of 500mA according to USB-specifications on the Neo FreeRunner, and no power is available in host mode on the Neo 1973. If your USB device respects USB-standards and consumes not more than 500mA, you may connect it directly to your Neo FreeRunner.
  
To power USB-host-mode on Neo 1973, or if you want to apply external power to Neo FreeRunner while in host-mode, you can provide power by using a powered USB hub (see below), or by manually injecting power into the attached USB device (and Neo FreeRunner) via a modified USB cable (Y-cable (C)jr, described further below).
+
To provide power to USB devices attached to your Neo 1973, or to provide power to your Neo FreeRunner while USB-device connected, you can provide power by using a (modified [for powering FreeRunner]) powered USB hub (see below), or by manually injecting power into the attached USB device (and Neo FreeRunner) via one of the [[specialized_USB_cables]].
  
 
=== Powered USB hubs known to work with the Neo ===
 
=== Powered USB hubs known to work with the Neo ===
  
 
(please add any known to work)
 
(please add any known to work)
 +
 +
* SIGMA Hub 300 (brandless cheap hub from Czech Makro markets) - can also charge FR, comes with 3.7A adapter
  
 
=== Providing power to run and charge the Neo while in host mode ===
 
=== Providing power to run and charge the Neo while in host mode ===
Line 32: Line 177:
 
Set to 0 (default), no power is provided at the USB port, charging is enabled, and host 15K pulldowns are removed from D+ and D-:
 
Set to 0 (default), no power is provided at the USB port, charging is enabled, and host 15K pulldowns are removed from D+ and D-:
  
echo "0" > /sys/devices/platform/neo1973-pm-host.0/hostmode
+
echo 0 > /sys/devices/platform/neo1973-pm-host.0/hostmode
  
 
Set to 1, provides up to 500mA USB power at the USB port (FreeRunner only), disables charging from USB, and applies 15K pulldowns to USB D+ and D-:
 
Set to 1, provides up to 500mA USB power at the USB port (FreeRunner only), disables charging from USB, and applies 15K pulldowns to USB D+ and D-:
  
echo "1" > /sys/devices/platform/neo1973-pm-host.0/hostmode
+
echo 1 > /sys/devices/platform/neo1973-pm-host.0/hostmode
  
Next, power must somehow be injected. An unmodified powered USB hub only provides power to the connected devices, but not to the connected host, so the only solution here is to modify a USB-hub¹) or to create a custom cable which will inject power into the host.
+
Next, power must somehow be injected. An unmodified powered USB hub only provides power to the connected devices, but not to the connected host, so the only solution here is to modify a USB-hub¹) or to create a custom cable which will inject power into the host. See [[specialized_USB_cables]] for some examples.
  
¹) often it's sufficient to short a diode in USB-hub to feed power to the host-connector too.
+
(However, as there is a wide range[http://permalink.gmane.org/gmane.comp.handhelds.openmoko.hardware/415]
 +
of USB hubs out there, one might find power (on a powered USB hub)
 +
is available already on the hub's mini USB 5 pin socket already, so not need a specialized cable after all!
 +
Check with a test meter.)
  
=== Modified USB cable to inject power while in host mode ===
+
Finally, there is the question of charge rate. The charging logic in the Neo will only charge at 100mA by default. Charging at 500mA will take place only if the charging device responds appropriatly to USB negotiation to increase power consumption. Charging at 1000mA will only take place if the Neo detects the appropriate resistor on the ID pins.
  
Three-headed cables are required if you want to power the FreeRunner / USB device whilst in host mode. For many uses the FreeRunner provides sufficient power to make such a cable unnecessary. At the moment, you'll have to manufacture this one yourself. You need to make a cable with three ends:
+
You can manually set the charge rate. See [[Forcing_fast_charge_mode]]
  
* A mini-USB type B cable for the Neo itself
+
¹) often it's sufficient to short a diode in USB-hub to feed power to the host-connector too.
* A cable of whatever type to go to your USB device.
+
# Edit 05 Oct. 2008 : Not being able to find any diode on my ([[User:Henrikz|Henrikz]]) USB Hub (Brand: Equip, Type: 4 port, aluminum) I simply connected +5V (pin 1) from one of the downstream ports to pin 1 of the upstream port.
* A cable going to a +5V +/-10%(max!) power supply with enough power for your device and to charge the Neo. This could be a wall charger or even another USB plug.
+
# Another successful mod with images of a DLINK hub (including some caveats) can be seen at [[User:Blutsauger]].
 
+
You connect the Data+ and Data- wires of the Neo and the device, and connect all of the ground wires together and all of the +5V wires together. This powers the Neo and the device, while letting the neo talk to the device.
+
You have to connect 2pcs  15kOhm resistors, one from D+ to ground, and one from D- to ground, to comply with USB-spec for hostmode, as Neo is switching off the internal resistors when you enable charging/powering over USB by asserting EN_USBHOST.
+
See schematics, LOCATION:49XX
+
 
+
Just for reference, the USB wires from left to right are:
+
*Black: Power -
+
*Green: Data -
+
*White: Data +
+
*Red: Power +
+
 
+
The Mini_USB-B connector has a fifth pin, the ID-pin.
+
This pin is supposed to be short to ground to signal Freerunner to enter hostmode. For the Y-cable and enabling external power while in hostmode, you may connect a 47kOhm resistor from ID-pin to ground. This is the same trick the OM-wallcharger uses to signal to Freerunner it can charge with 1A. Future kernels should switch to hostmode + external power when seeing this 47k resistor.
+
  
 
=== Power Concerns ===
 
=== Power Concerns ===
 
You'll need to force the Neo to go into fast charge mode, since it can't do its usual power negotiation over USB.
 
You'll need to force the Neo to go into fast charge mode, since it can't do its usual power negotiation over USB.
  
  echo -n "fast_cccv" >  /sys/devices/platform/s3c2410-i2c/i2c-adapter/i2c-0/0-0008/chgmode
+
  echo -n fast_cccv >  /sys/devices/platform/s3c2410-i2c/i2c-adapter/i2c-0/0-0008/chgmode
  
 
(Also this should be done by kernel when seeing 47K at ID-pin)
 
(Also this should be done by kernel when seeing 47K at ID-pin)
  
== DIY USB host adapter ==
+
=== Working Examples ===
 
+
Note that these instructions are provided in the hope that they are useful but without any warranty!
+
 
+
[[Image:2-usb-receptables.jpg]]
+
 
+
:#Find an old motherboard with a set of two USB receptacles as shown above.
+
:#Desolder this set of receptacles from the motherboard. This can be bit tricky but it is doable at least with a desoldering gun.
+
:#Each receptacle has four pins. Use a multimeter to verify that you have no short circuits between the pins or the shield.
+
:#Solder adjacent pins together (GND to GND, D- to D-, D+ to D+, VCC to VCC).
+
:#(Optional) Build a test cable. Cut an USB cable with A plug into half, connect it a receptacle and again measure that you have no short circuits. Then connect the test cable to PC and verify that you see
+
black GND
+
green 0V
+
white 0V
+
red +5V
+
:#Freerunner is shipped with a mini-B-to-A-plug cable. Connect this to a receptacle.
+
:#(Optional)Connect test cable to the other receptacle and verify that you see
+
black GND
+
green 0V
+
white 0V
+
red 0V
+
when freerunner acts as a device and
+
black GND
+
green 0V
+
white 0V
+
red +5V
+
when it acts as a host.
+
:#At your own risk, switch freerunner to USB host mode and connect an USB device to the other receptacle of the adapter. Here's how the setup should look like:
+
 
+
[[Image:Usb-gender-changer1.jpg]]
+
[[Image:Usb-gender-changer2.jpg]]
+
  
=== Compatibility ===
+
==== USB Keyboard ====
  
The adapter works with kingston data traveller 4G memory stick and aiptec pencam webcam. However, for some reason (probably the missing 15k resistors at D+ and D-) it did not work with any of the tested USB keyboards or mice:
+
[[Image:Usb keyboard-jej.jpg|thumb|left]]This [[Usb_keyboard|usb keyboard]] works directly under shr-testing with no changes except usb host device to host
usb 1-2: new full speed USB device using s3c2410-ohci and address 24
+
<br clear="both" />
usb 1-2: device descriptor read/64, error -62
+
Pictures [http://blogs.thehumanjourney.net/finds/entry/20080716 here]
usb 1-2: device descriptor read/64, error -62
+
usb 1-2: new full speed USB device using s3c2410-ohci and address 25
+
usb 1-2: device descriptor read/64, error -62
+
usb 1-2: device descriptor read/64, error -62
+
usb 1-2: new full speed USB device using s3c2410-ohci and address 26
+
usb 1-2: device not accepting address 26, error -62
+
usb 1-2: new full speed USB device using s3c2410-ohci and address 27
+
usb 1-2: device not accepting address 27, error -62
+
  
However, if I connect neo to small (unpowered) USB hub
+
==== Connecting a USB-Stick ====
usb 1-2: new full speed USB device using s3c2410-ohci and address 61
+
[[Image:connecting-usb-stick-1.jpg|thumb|left]]
usb 1-2: configuration #1 chosen from 1 choice
+
I found this adapter, it has 2 Type A jacks, rather cheap (about 5 &euro;).
hub 1-2:1.0: USB hub found
+
<br clear="both" />
hub 1-2:1.0: 4 ports detected
+
and connect the keyboard to the hub then it is correctly recognized:
+
usb 1-2.3: new low speed USB device using s3c2410-ohci and address 62
+
usb 1-2.3: configuration #1 chosen from 1 choice
+
input:  USB Keyboard as /devices/platform/s3c2410-ohci/usb1/1-2/1-2.3/1-2.3:1.0/input/input13
+
input: USB HID v1.10 Keyboard [  USB Keyboard] on usb-s3c24xx-2.3
+
input:  USB Keyboard as /devices/platform/s3c2410-ohci/usb1/1-2/1-2.3/1-2.3:1.1/input/input14
+
input: USB HID v1.10 Device [  USB Keyboard] on usb-s3c24xx-2.3
+
  
With the hub I can also use both keyboard and usb memory stick at the same time.
+
[[Image:connecting-usb-stick-2.jpg|thumb|left]]
 +
I borrowed the cable from a card reader, it has the same pinout like the cable that comes with the Neo.
 +
<br clear="both" />
  
=== Power consumption ===
+
[[Image:connecting-usb-stick-3.jpg|thumb|left]]
 +
With the above commands I could mount the memory stick.
 +
<br clear="both" />
  
When I unplug the USB hub (with only keyboard connected to it) the power consumption estimate at /sys/devices/platform/bq2700-battery.0/power_supply/bat/current_now decreases from 175000 to 145000 (are these microamperes?).
+
[[Image:connecting-usb-stick-4.jpg|thumb|left]]
 +
<br clear="both" />
  
 
[[Category:Neo1973 Hardware]]
 
[[Category:Neo1973 Hardware]]
 +
[[Category:Neo FreeRunner Hardware]]
 
[[Category:USB]]
 
[[Category:USB]]
 +
[[Category:Power]]

Latest revision as of 20:37, 2 December 2011

The mini-USB port on both the Neo 1973 and the Neo FreeRunner supports both USB host and USB device. This opens up a range of possibilities, such as adding USB cameras and USB input devices.

Contents

[edit] Using USB host mode

[edit] Selecting USB host modes

Please take into account that due to kernel changes sysfs paths can change, if you can't find a particular node, just use the “find” command

By default, the mini-USB port is in device mode. To tell the Neo that it is logically a host¹:

# echo host > /sys/devices/platform/s3c2410-ohci/usb_mode

Independent of the logical mode of the USB port, the Neo FreeRunner can provide 5 volt USB power to an attached USB device. To enable this (not available on Neo 1973):

# echo 1 > /sys/devices/platform/neo1973-pm-host.0/hostmode

Please note, on my fairly new kernel (andy-tracking commit de8460932576502fb6bf61968a37c4d2aed2d6e2), this node is in /sys/devices/platform/s3c2440-i2c/i2c-adapter/i2c-0/0-0073/neo1973-pm-host.0/hostmode . And from 901d73fe51f33032b34b2ae5612eb863ec90532a Wed Apr 8 commit, usb_mode node is at /sys/devices/platform/s3c-ohci/usb_mode .

Note: You may want to run ifconfig usb0 down prior to switching to USB host mode, as the Neo's USB networking may not like having its USB port disappear. You'll probably want to ssh into your Neo over WiFi or Bluetooth before starting all of this, alternatively use an on screen keyboard.

Note that in full USB host mode the FreeRunner will power the external device. To avoid draining the battery use a powered USB hub, then on the FreeRunner enable logical host mode:

# echo host > /sys/devices/platform/s3c2410-ohci/usb_mode

but NOT electrical host mode

# echo 0 > /sys/devices/platform/neo1973-pm-host.0/hostmode

Note that powered USB hubs do not send power upstream, that is, into the host. If you wish to power or charge the FreeRunner, you will need a special USB cable.

¹)Debian note: You'll need the ohci-hcd module: modprobe ohci-hcd

  • NOTE: with [FSO] based distributions one should use the dbus APIs and not the method stated above.
[edit] Qtmoko v36 (*)

As of Qtmoko v36 (kernel 2.6.34-qtmoko):

To turn on power mode:

 #echo 1 > /sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio.0/reg-fixed-voltage.2/gta02-pm-usbhost.0/power_on

To switch to usb host mode:

 #echo host > /sys/devices/platform/s3c2410-ohci/usb_mode

To turn off power mode:

 #echo 0 > /sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio.0/reg-fixed-voltage.2/gta02-pm-usbhost.0/power_on

To switch to usb device mode:

 #echo device > /sys/devices/platform/s3c2410-ohci/usb_mode

(*)source: [1]

[edit] Returning to USB device mode

After doing whatever is needed to safely remove your device and unplugging it you can remove the provision of 5 volt power and return to device mode.

echo 0 > /sys/devices/platform/neo1973-pm-host.0/hostmode
echo device > /sys/devices/platform/s3c2410-ohci/usb_mode

You can now safely restart USB networking

ifconfig usb0 up

[edit] USB-Mode-Script

This simple script switches between USB-Modes:

#!/bin/sh
grep -q 'host' /sys/devices/platform/s3c2410-ohci/usb_mode
if [ $? -eq 0 ]
then
echo 0 > /sys/devices/platform/neo1973-pm-host.0/hostmode
echo device > /sys/devices/platform/s3c2410-ohci/usb_mode
ifconfig usb0 up
echo USB-Port is in device-mode now.
else
ifconfig usb0 down
echo host > /sys/devices/platform/s3c2410-ohci/usb_mode
echo 1 > /sys/devices/platform/neo1973-pm-host.0/hostmode
lsusb
echo USB-Port is in host-mode now.
fi

See this bug for a justification for adding the lsusb hack.

[edit] USB-Mode-Script (2.6.28+ kernels)

The paths change slightly since 2.6.28:

#!/bin/sh
grep -q 'host' /sys/devices/platform/s3c2410-ohci/usb_mode
if [ $? -eq 0 ]
then
echo 0 > /sys/class/i2c-adapter/i2c-0/0-0073/neo1973-pm-host.0/hostmode 
echo device > /sys/devices/platform/s3c2410-ohci/usb_mode
ifconfig usb0 up
echo USB-Port is in device-mode now.
else
ifconfig usb0 down
echo host > /sys/devices/platform/s3c2410-ohci/usb_mode
echo 1 > /sys/class/i2c-adapter/i2c-0/0-0073/neo1973-pm-host.0/hostmode
lsusb
echo USB-Port is in host-mode now.
fi

Note: For me (2.6.29-rc3), it is /sys/devices/platform/s3c-ohci/usb_mode ...

[edit] USB-Mode-Script (universal for all kernels)

#!/bin/sh

USB_MODE=/sys/devices/platform/s3c-ohci/usb_mode
if [ ! -f ${USB_MODE} ] ; then
  USB_MODE=/sys/devices/platform/s3c2410-ohci/usb_mode
fi
if [ ! -f ${USB_MODE} ] ; then
  echo "Cannot find usb_mode sysfs node"; exit 2
fi

POWER=/sys/devices/platform/neo1973-pm-host.0/hostmode
if [ ! -f ${POWER} ] ; then
  POWER=/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio/reg-fixed-voltage.2/gta02-pm-usbhost.0/power_on
fi
if [ ! -f ${POWER} ] ; then
  POWER=/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio.0/reg-fixed-voltage.2/gta02-pm-usbhost.0/power_on
fi
if [ ! -f ${POWER} ] ; then
  POWER=/sys/class/i2c-adapter/i2c-0/0-0073/neo1973-pm-host.0/hostmode
fi
if [ ! -f ${POWER} ] ; then
  echo "Cannot find power hostmode sysfs node"; exit 3
fi

echo "USB_MODE = ${USB_MODE}"
echo "POWER = ${POWER}"

grep -q 'host' ${USB_MODE}
if [ $? -eq 0 ]; then
  echo 0 > ${POWER}
  echo device > ${USB_MODE}
  ifconfig usb0 up
  echo USB-Port is in device-mode now.
else
  ifconfig usb0 down
  echo host > ${USB_MODE}
  echo 1 > ${POWER}
  lsusb
  echo USB-Port is in host-mode now.
fi

[edit] Using a GUI

[edit] Providing power to connected USB devices while in host mode

Normally, USB host ports provide power to any connected USB device.

Available power in host mode is the full maximum of 500mA according to USB-specifications on the Neo FreeRunner, and no power is available in host mode on the Neo 1973. If your USB device respects USB-standards and consumes not more than 500mA, you may connect it directly to your Neo FreeRunner.

To provide power to USB devices attached to your Neo 1973, or to provide power to your Neo FreeRunner while USB-device connected, you can provide power by using a (modified [for powering FreeRunner]) powered USB hub (see below), or by manually injecting power into the attached USB device (and Neo FreeRunner) via one of the specialized_USB_cables.

[edit] Powered USB hubs known to work with the Neo

(please add any known to work)

  • SIGMA Hub 300 (brandless cheap hub from Czech Makro markets) - can also charge FR, comes with 3.7A adapter

[edit] Providing power to run and charge the Neo while in host mode

A slightly separate issue is power to run and charge the Neo (both types) itself. When the USB port is in device mode, the Neo FreeRunner/1973 can be powered and recharged via the USB port, but when in standard host mode, the Neo FreeRunner is set to provide power and does not charge. Fortunately, control of the direction of power (in or out) is independent of the personality of the USB port (host or device):

To recap, the direction of power can be controlled:

Set to 0 (default), no power is provided at the USB port, charging is enabled, and host 15K pulldowns are removed from D+ and D-:

echo 0 > /sys/devices/platform/neo1973-pm-host.0/hostmode

Set to 1, provides up to 500mA USB power at the USB port (FreeRunner only), disables charging from USB, and applies 15K pulldowns to USB D+ and D-:

echo 1 > /sys/devices/platform/neo1973-pm-host.0/hostmode

Next, power must somehow be injected. An unmodified powered USB hub only provides power to the connected devices, but not to the connected host, so the only solution here is to modify a USB-hub¹) or to create a custom cable which will inject power into the host. See specialized_USB_cables for some examples.

(However, as there is a wide range[2] of USB hubs out there, one might find power (on a powered USB hub) is available already on the hub's mini USB 5 pin socket already, so not need a specialized cable after all! Check with a test meter.)

Finally, there is the question of charge rate. The charging logic in the Neo will only charge at 100mA by default. Charging at 500mA will take place only if the charging device responds appropriatly to USB negotiation to increase power consumption. Charging at 1000mA will only take place if the Neo detects the appropriate resistor on the ID pins.

You can manually set the charge rate. See Forcing_fast_charge_mode

¹) often it's sufficient to short a diode in USB-hub to feed power to the host-connector too.

  1. Edit 05 Oct. 2008 : Not being able to find any diode on my (Henrikz) USB Hub (Brand: Equip, Type: 4 port, aluminum) I simply connected +5V (pin 1) from one of the downstream ports to pin 1 of the upstream port.
  2. Another successful mod with images of a DLINK hub (including some caveats) can be seen at User:Blutsauger.

[edit] Power Concerns

You'll need to force the Neo to go into fast charge mode, since it can't do its usual power negotiation over USB.

echo -n fast_cccv >  /sys/devices/platform/s3c2410-i2c/i2c-adapter/i2c-0/0-0008/chgmode

(Also this should be done by kernel when seeing 47K at ID-pin)

[edit] Working Examples

[edit] USB Keyboard

Usb keyboard-jej.jpg
This usb keyboard works directly under shr-testing with no changes except usb host device to host


Pictures here

[edit] Connecting a USB-Stick

Connecting-usb-stick-1.jpg

I found this adapter, it has 2 Type A jacks, rather cheap (about 5 €).

Connecting-usb-stick-2.jpg

I borrowed the cable from a card reader, it has the same pinout like the cable that comes with the Neo.

Connecting-usb-stick-3.jpg

With the above commands I could mount the memory stick.

Connecting-usb-stick-4.jpg


Personal tools

USB host

The mini-USB port on both the Neo 1973 and the Neo FreeRunner supports both USB host and USB device. This opens up a range of possibilities, such as adding USB cameras and USB input devices.

By default, the mini-USB port is in device mode. To tell the device that it is logically a host:

echo "host" > /sys/devices/platform/s3c2410-ohci/usb_mode

Instruct the device to provide 5 volts (not available on Neo 1973):

echo "1" > /sys/devices/platform/neo1973-pm-host.0/hostmode

Note: You may want to run ifconfig usb0 down prior to switching to USB host mode, as the Neo's USB networking may not like having its USB port disappear. You'll probably want to ssh into your Neo over WiFi or Bluetooth before starting all of this, alternatively use an on screen keyboard.

Providing power to connected USB devices while in host mode

Normally, USB host ports provide power to any connected USB device. In the case of portable handheld devices, this power may be limited. (Usually the battery is sized to power the handheld device alone, and to maximize standby time.)

Available power in host mode is limited to 500mA on the Neo FreeRunner, and no power is available in host mode on the Neo 1973. If your USB devices consumes less than 500mA, you may connect it directly to your Neo FreeRunner.

To power USB-host-mode on Neo 1973, or if you want to apply external power to Neo FreeRunner while in host-mode, you can provide power by using a powered USB hub (see below), or by manually injecting power into the attached USB device (and Neo FreeRunner) via a modified USB cable (Y-cable (C)jr, described further below).

Powered USB hubs known to work with the Neo

(please add any known to work)

Providing power to run and charge the Neo while in host mode

A slightly separate issue is power to run and charge the Neo (both types) itself. When the USB port is in device mode, the Neo FreeRunner/1973 can be powered and recharged via the USB port, but when in standard host mode, the Neo FreeRunner is set to provide power and does not charge. Fortunately, control of the direction of power (in or out) is independent of the personality of the USB port (host or device):

To recap, the direction of power can be controlled:

Set to 0 (default), no power is provided at the USB port, charging is enabled, and host 15K pulldowns are removed from D+ and D-:

echo "0" > /sys/devices/platform/neo1973-pm-host.0/hostmode

Set to 1, provides up to 500mA USB power at the USB port (FreeRunner only), disables charging from USB, and applies 15K pulldowns to USB D+ and D-:

echo "1" > /sys/devices/platform/neo1973-pm-host.0/hostmode

Next, power must somehow be injected. An unmodified powered USB hub only provides power to the connected devices, but not to the connected host, so the only solution here is to modify a USB-hub¹) or to create a custom cable which will inject power into the host.

¹) often it's sufficient to short a diode in USB-hub to feed power to the host-connector too.

Modified USB cable to inject power while in host mode

Three-headed cables are required if you want to power the FreeRunner / USB device whilst in host mode. For many uses the FreeRunner provides sufficient power to make such a cable unnecessary. At the moment, you'll have to manufacture this one yourself. You need to make a cable with three ends:

  • A mini-USB type B cable for the Neo itself
  • A cable of whatever type to go to your USB device.
  • A cable going to a +5V +/-10%(max!) power supply with enough power for your device and to charge the Neo. This could be a wall charger or even another USB plug.

You connect the Data+ and Data- wires of the Neo and the device, and connect all of the ground wires together and all of the +5V wires together. This powers the Neo and the device, while letting the neo talk to the device. You have to connect 2pcs 15kOhm resistors, one from D+ to ground, and one from D- to ground, to comply with USB-spec for hostmode, as Neo is switching off the internal resistors when you enable charging/powering over USB by asserting EN_USBHOST. See schematics, LOCATION:49XX

Just for reference, the USB wires from left to right are:

  • Black: Power -
  • Green: Data -
  • White: Data +
  • Red: Power +

The Mini_USB-B connector has a fifth pin, the ID-pin. This pin is supposed to be short to ground to signal Freerunner to enter hostmode. For the Y-cable and enabling external power while in hostmode, you may connect a 47kOhm resistor from ID-pin to ground. This is the same trick the OM-wallcharger uses to signal to Freerunner it can charge with 1A. Future kernels should switch to hostmode + external power when seeing this 47k resistor.

Power Concerns

You'll need to force the Neo to go into fast charge mode, since it can't do its usual power negotiation over USB.

echo -n "fast_cccv" >  /sys/devices/platform/s3c2410-i2c/i2c-adapter/i2c-0/0-0008/chgmode

(Also this should be done by kernel when seeing 47K at ID-pin)

DIY USB host adapter

Note that these instructions are provided in the hope that they are useful but without any warranty!

2-usb-receptables.jpg

  1. Find an old motherboard with a set of two USB receptacles as shown above.
  2. Desolder this set of receptacles from the motherboard. This can be bit tricky but it is doable at least with a desoldering gun.
  3. Each receptacle has four pins. Use a multimeter to verify that you have no short circuits between the pins or the shield.
  4. Solder adjacent pins together (GND to GND, D- to D-, D+ to D+, VCC to VCC).
  5. (Optional) Build a test cable. Cut an USB cable with A plug into half, connect it a receptacle and again measure that you have no short circuits. Then connect the test cable to PC and verify that you see
black GND
green 0V
white 0V
red +5V
  1. Freerunner is shipped with a mini-B-to-A-plug cable. Connect this to a receptacle.
  2. (Optional)Connect test cable to the other receptacle and verify that you see
black GND
green 0V
white 0V
red 0V

when freerunner acts as a device and

black GND
green 0V
white 0V
red +5V

when it acts as a host.

  1. At your own risk, switch freerunner to USB host mode and connect an USB device to the other receptacle of the adapter. Here's how the setup should look like:

Usb-gender-changer1.jpg Usb-gender-changer2.jpg

Compatibility

The adapter works with kingston data traveller 4G memory stick and aiptec pencam webcam. However, for some reason (probably the missing 15k resistors at D+ and D-) it did not work with any of the tested USB keyboards or mice:

usb 1-2: new full speed USB device using s3c2410-ohci and address 24
usb 1-2: device descriptor read/64, error -62
usb 1-2: device descriptor read/64, error -62
usb 1-2: new full speed USB device using s3c2410-ohci and address 25
usb 1-2: device descriptor read/64, error -62
usb 1-2: device descriptor read/64, error -62
usb 1-2: new full speed USB device using s3c2410-ohci and address 26
usb 1-2: device not accepting address 26, error -62
usb 1-2: new full speed USB device using s3c2410-ohci and address 27
usb 1-2: device not accepting address 27, error -62

However, if I connect neo to small (unpowered) USB hub

usb 1-2: new full speed USB device using s3c2410-ohci and address 61
usb 1-2: configuration #1 chosen from 1 choice
hub 1-2:1.0: USB hub found
hub 1-2:1.0: 4 ports detected

and connect the keyboard to the hub then it is correctly recognized:

usb 1-2.3: new low speed USB device using s3c2410-ohci and address 62
usb 1-2.3: configuration #1 chosen from 1 choice
input:   USB Keyboard as /devices/platform/s3c2410-ohci/usb1/1-2/1-2.3/1-2.3:1.0/input/input13
input: USB HID v1.10 Keyboard [  USB Keyboard] on usb-s3c24xx-2.3
input:   USB Keyboard as /devices/platform/s3c2410-ohci/usb1/1-2/1-2.3/1-2.3:1.1/input/input14
input: USB HID v1.10 Device [  USB Keyboard] on usb-s3c24xx-2.3

With the hub I can also use both keyboard and usb memory stick at the same time.

Power consumption

When I unplug the USB hub (with only keyboard connected to it) the power consumption estimate at /sys/devices/platform/bq2700-battery.0/power_supply/bat/current_now decreases from 175000 to 145000 (are these microamperes?).