maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Nokia N900 (https://talk.maemo.org/forumdisplay.php?f=44)
-   -   N900 will not allow USB OTG! (https://talk.maemo.org/showthread.php?t=31921)

egoshin 2010-05-12 15:56

Re: N900 does now allow USB hostmode!
 
Quote:

Originally Posted by javispedro (Post 654856)
I think this is the most interesting discovery so far. Now the question is: how? (and of course, what).
Should a strace of bme terminating help?

Yes, it would be great.
And I would concentrate on kernel side - going through hub and process a disk/USB stick (I assume that this stuff is more interesting for anybody).

blue_led 2010-05-12 16:58

Re: N900 will not allow USB OTG!
 
Just fact : when I play with usb port & procfs, on my n900, pc suite mode status hang-on even there is no usb charger, pc or any device connected !??

So good nwes for us ( from egoshin ) bme fault the otg usb host.
Q why I say still otg ?
A (my opinion ) : egoshin make work otg module. it is the only one activated by configs . Initial connection to pc is needed to initialize otg state machine as a peripheral then switch to host by HNP. The great discovery of egoshin is initial connection to pc. All previous attempt to activate host mode was made without this phase. Mode selection: usb device | pc suite, feat bme is a garbage bunch of software. We need to change all of this.
As i know, echo H > .... force HNP
egoshin, please, please try without " echo host > ..../mode

Quote:

So, conclusion - BME disables somehow host mechanism then it exits. Probably - to prepare a hardware charging.
i think programmers don't read all of usb specifications
charging on host mode is now accepted by ( patched ) usb 2.0 standard . because charging circuit is INDEPENDENT from usb stuff nothing prevent this on N900
we have 2 situation
1) vbus =5v ( from external source) THEN charge if is needed. IF PC don't host . IF D+/D- short then high power charge ELSE can host if wanted.
2) vbus =0 THEN IF host then BOOST

More: this settings are made on only one f.. asic
no rocket science

From ancient n900 times : ... limitation at hardware level ....
My a.. . sorry for language.

titan 2010-05-12 17:18

Re: N900 will not allow USB OTG!
 
I'm not sure whether this has been posted here already:
excerpt from drivers/usb/musb/Kconfig (it would be possible to build it with USB host only)

config USB_MUSB_HOST
depends on USB
bool "USB Host"
help
Say Y here if your system supports the USB host role.
If it has a USB "A" (rectangular), "Mini-A" (uncommon),
or "Mini-AB" connector, it supports the host role.
(With a "Mini-AB" connector, you should enable USB OTG.)

# use USB_GADGET_MUSB_HDRC not USB_MUSB_PERIPHERAL to #ifdef peripheral
# side support ... OTG needs both roles
config USB_MUSB_PERIPHERAL
depends on USB_GADGET
bool "USB Peripheral (gadget stack)"
select USB_GADGET_MUSB_HDRC
help
Say Y here if your system supports the USB peripheral role.
If it has a USB "B" (squarish), "Mini-B", or "Mini-AB"
connector, it supports the peripheral role.
(With a "Mini-AB" connector, you should enable USB OTG.)

config USB_MUSB_OTG
depends on USB && USB_GADGET && PM && EXPERIMENTAL
bool "Both host and peripheral: USB OTG (On The Go) Device"
select USB_GADGET_MUSB_HDRC
select USB_OTG
help
The most notable feature of USB OTG is support for a
"Dual-Role" device, which can act as either a device
or a host. The initial role choice can be changed
later, when two dual-role devices talk to each other.

At this writing, the OTG support in this driver is incomplete,
omitting the mandatory HNP or SRP protocols. However, some
of the cable based role switching works. (That is, grounding
the ID pin switches the controller to host mode, while leaving
it floating leaves it in peripheral mode.)

Select this if your system has a Mini-AB connector, or
to simplify certain kinds of configuration.

To implement your OTG Targeted Peripherals List (TPL), enable
USB_OTG_WHITELIST and update "drivers/usb/core/otg_whitelist.h"
to match your requirements.

endchoice

qole 2010-05-12 17:31

Re: N900 will not allow USB OTG!
 
If you disable OTG, will that break the N900's ability to charge and be a peripheral?
I don't think we really want OTG, do we? We want USB host...
If we disabled OTG, is there a way to manually switch between peripheral / PC Suite mode (USB client) and USB host?
Or do egoshin's tests (success via forcing OTG mode) suggest that OTG is our only hope?

blue_led 2010-05-12 17:31

Re: N900 will not allow USB OTG!
 
1 Attachment(s)
/* whitelist */
and about uB connector.... always chinese people made an adapter

and I present to you my spring collection

@titan
Quote:

At this writing, the OTG support in this driver is incomplete,
omitting the mandatory HNP or SRP protocols
i don't think so . srp is there even hnp ( egoshin prove this ) but routines are full of bugs and applications know nothing about otg

egoshin 2010-05-12 17:36

Re: N900 will not allow USB OTG!
 
@blue_led

1. "Initial connection to pc is needed to initialize otg state machine as a peripheral then switch to host by HNP. "

Not exactly. The initial connection to PC is used to avoid a problem of changing "suspend"/"resume" modes in HW and SW - the accurate procedure programming without that will take time. The HNP negotiations happens with a target device (HUB, USB stick or hard disk). If you look into /proc/driver/musb_hdrc in a mean time (after writing 'H' and while cable is connected to PC or disconnected but not connected to HUB/disk) then you can see the DEVCTL state like '9b' which means that there is not yet 'HOSTMODE' bit set. Only after you connect to hub/disk then this bit shows 1. And VBUS is needed to prevent dropping session in 1707 while you reconnect cable.

Why it is not set while connected to PC? - because HOSTREQ is activated only during transition to suspend mode but while N900 is connected to PC it is still active. And setting that bit while cable is not connected to anywhere doesn't start hostmode after subsequent connection to hub/disk.

BTW, this is only intermediate stuff - I am on crash course to find out all potential problems. The real code may use 'FORCE_HOST'. For a moment we need to find out all missed stuff.

2. Charging. I looked into debug output while connect N900 to wall charger. The last message is "musb_stop()". HW effectively is stopped.

Yes, specs allows charging while in USB working mode but that is not for high-performance charger. VBUS voltage is not enough - shortcut of D-/D+ is needed to prepare an effective charging.

So, I suspect that BME is not fixed after Nokia added 1707 and removed TWL4030 from USB path. 1707 is able to start high-speed charging without software intervention but TWL4030 is not. So, BME just prepared USB subsystem for charging while it is absent and that preparation assumes that there is TWL4030, BQXXXXX chip and it knows nothing about 1707 and it's ability for charging high-speed without software.

titan 2010-05-12 17:37

Re: N900 will not allow USB OTG!
 
we'll see. perhaps the device would not even boot?
but getting host-mode working at all would be a good start, even if conflicts with charging and other USB device functions.
I'm just rebuild a kernel...
EDIT: build fails with
drivers/usb/musb/musb_core.c: In function 'musb_charger_detect':
drivers/usb/musb/musb_core.c:244: error: 'struct musb' has no member named 'g'
drivers/usb/musb/musb_core.c:245: error: 'struct musb' has no member named 'g'
drivers/usb/musb/musb_core.c: In function 'musb_stage0_irq':
drivers/usb/musb/musb_core.c:577: warning: unused variable 'r'
drivers/usb/musb/musb_core.c: In function 'musb_connect_show':
drivers/usb/musb/musb_core.c:1983: error: 'struct musb' has no member named 'softconnect'
drivers/usb/musb/musb_core.c: In function 'musb_connect_store':
drivers/usb/musb/musb_core.c:2014: error: 'struct musb' has no member named 'softconnect'
drivers/usb/musb/musb_core.c: In function 'musb_irq_work':
drivers/usb/musb/musb_core.c:2128: warning: unused variable 'old_suspend'
drivers/usb/musb/musb_core.c: In function 'musb_init_controller':
drivers/usb/musb/musb_core.c:2465: error: 'struct musb' has no member named 'g'
drivers/usb/musb/musb_core.c:2466: error: 'struct musb' has no member named 'g'

Quote:

Originally Posted by qole (Post 655473)
If you disable OTG, will that break the N900's ability to charge and be a peripheral?
I don't think we really want OTG, do we? We want USB host...
If we disabled OTG, is there a way to manually switch between peripheral / PC Suite mode (USB client) and USB host?
Or do egoshin's tests (success via forcing OTG mode) suggest that OTG is our only hope?


blue_led 2010-05-12 17:48

Re: N900 will not allow USB OTG!
 
@ egoshin
Quote:

Why it is not set while connected to PC? - because HOSTREQ is activated only during transition to suspend mode but while N900 is connected to PC it is still active. And setting that bit while cable is not connected to anywhere doesn't start hostmode after subsequent connection to hub/disk.
Correct.
A ( time) )
A-device finishes using bus and stops all bus activity, (i.e. suspends the bus). This is pc doing someting on bus
B time )
B-device ( N900 ) detects that bus is idle for more than TB_AIDL_BDIS min and begins HNP by turning off pull-up on D+ (*) . This allows the bus to discharge to the SE0 state
so Q :WHo discharge the bus to SE0 state ?
A: the two 15k resistors on datalines but when charging is running those resistors are disabled ! right ? and for high power charger detection a source current is applied on D+ ! right ?
This curent source prevent switching to HOST by holding D+ high

isn't this a heavy & long discussed hardware limitation ?

By switching off charger & bme you allow bus discharge and reach nirvana


your procedure absolutely have sense for "manual mode" HNP
i was able to put state machine in wait to connect with ONLY a resistor of 1.5 k between vbus and D+ and a capacitor of 4.7 uF to ground but there is nobody connection capable ( for evident reason ) hnp fail. i thought to put a pic microcontroller doing hnp sequence on vbus and D+ but i have no time for that.

* If the bus was operating in HS mode, the B-device will first enter the full-speed mode

Quote:

VBUS voltage is not enough - shortcut of D-/D+ is needed to prepare an effective charging.
i discover this yesterday. i charge from office pc with an handmade a male to a female adapter with data shorted using stock data cable , bonus no viruses no mode selection.

javispedro 2010-05-12 19:09

Re: N900 will not allow USB OTG!
 
Quote:

Originally Posted by titan (Post 655462)
USB_GADGET_MUSB_HDRC

I was talking about this on a previous post. The OS fails to boot; I guessed because someone is modprobing some now-incompatible module, or bme doesn't find the expected sysfs nodes.

Either way, as it is now, disabling OTG does more damage than help, as some interesting pieces of code are only built if it is enabled.

imperiallight 2010-05-12 19:32

Re: N900 will not allow USB OTG!
 
wrong post - sorry

egoshin 2010-05-13 01:41

Re: N900 does now allow USB hostmode!
 
Quote:

Originally Posted by egoshin (Post 654566)
@Joerg

Again, good news - I repeated test suggested by you but replaced 'stop bme' to 'killall -SIGSTOP bme_RX-51'.



Now it works, even on stock (unmodified) kernel.

However, I doesn't work well with my USB memory stick because read returns error -32 (EPIPE). But it still exchanges some info because device "not accepting address 8" (or ever). A modified kernel is needed to find out details why it reads descriptors with EPIPE.

I researched a log and a kernel. The diagnostics shows that with VBUS=1 from BQxxxxx chip (no setup of VBUS in TWL4030) hard disk doesn't respond while N900 reads messages from it...

EDIT: USB memory stick, not hard disk.

But self-powered hub still responds.

egoshin 2010-05-13 05:37

Re: N900 will not allow USB OTG!
 
Success!

I just was able to mount USB stick via self-powered HUB and read it.

Device - /dev/sda1

Details will be later, but now - modified kernel. I am looking into right modification.

BTW, the USB stick problem with VBUS from BQxxxxx seems to be a connector problem - I was able to communicate with it too (USB stick directly connected to N900).

twoboxen 2010-05-13 13:16

Re: N900 will not allow USB OTG!
 
Quote:

Originally Posted by egoshin (Post 656408)
Success!

I just was able to mount USB stick via self-powered HUB and read it.

Device - /dev/sda1

Details will be later, but now - modified kernel. I am looking into right modification.

BTW, the USB stick problem with VBUS from BQxxxxx seems to be a connector problem - I was able to communicate with it too (USB stick directly connected to N900).

I'm sure it goes without saying... but you are the man. Well, you and all the other people who helped are the collective man. Any chance the requisite fixes can be folded into titan's kernel?

titan 2010-05-13 14:40

Re: N900 will not allow USB OTG!
 
I just got a hostmode-only kernel running!
it boots up normally, battery info and USB charging is broken (as expected)
WARNING: this is only for experienced developers! do not install as noob
http://maemory.com/N900/kernel/hostmode/
you need to replace /etc/event.d/bme with my modified file (make a backup!).
In the worst case it ends up in a reboot loop due to bme.
you could uncomment the line "cp /etc/event.replace.d/..." in the script to
restore the original at the first start. if it fails to boot you would
only need to reflash the stock kernel.

EDIT: bascially bme dies during boot but booting continues. so no workarounds for bme are needed :)

now if I only had my USB F/F adapter here...

joerg_rw 2010-05-13 14:53

Re: N900 will not allow USB OTG!
 
Quote:

Originally Posted by twoboxen (Post 656786)
I'm sure it goes without saying... but you are the man. Well, you and all the other people who helped are the collective man. Any chance the requisite fixes can be folded into titan's kernel?

Titan just booted a hostmode-only kernel this very moment.
Quote:

[2010-05-13 16:33:17] <t-tan> it continues !!!
[2010-05-13 16:33:50] <t-tan> I'm running a hostmode-only kernel
[2010-05-13 16:35:07] <DocScrutinizer> t-tan: what coninues?? the kernel booted up to full system?
[2010-05-13 16:35:18] <t-tan> yes. success!

Egoshin's method implies conecting the N900 to a PC prior to switching to hostmode, and that won't help a lot out in the field, will it?
Quote:

http://talk.maemo.org/showpost.php?p...&postcount=835
1. plug to PC, answer "PC suite"
2. echo host >/sys/devices/platform/musb_hdrc/mode
3. echo H >/proc/driver/musb_hdrc
4. /bin/sh -c 'killall -SIGSTOP bme_RX-51 && sleep 3 && /usr/local/i2cset -y -m 0x07 2 0x6b 0x01 0x05 && while sleep 28; do /usr/local/i2cset -y -m 0x80 2 0x6b 0x00 0x80; done &
5. disconnect USB from PC and connect to USB memory stick or extrnal hard disk or HUB.
6. lsusb -- or just wait
7. Look into /var/log/syslog for messages.
See 1. to 5. For the answer "PC suite" part see also http://talk.maemo.org/showthread.php...357#post635357

So we still struggle to get GENERIC hostmode, not a tricky way to put OTG statemachine into a pathological state by fiddling with VBUS timings, where it detects a drive as another OTG peer.
Quote:

[2010-05-13 14:52:07] <DocScrutinizer> let me put it this way: it's insane to trick a potentially
flawed OTG statemachine into a certain state by fiddling with VBUS timings, while
a plain vanilla generic hostmode doesn't care about VBUS at all

Stay calm and patient and wait what's going on, all the smart people know you want hostmode as soon as possible, and neither Titan nor anybody else will hesitate to ship whatever is needed to put it to work for everybody, once we figured how to implement a reliable useful thing. At the moment this is still bleeding edge R&D, and surely it's strongly discourraged for non-developers to try and put it to use, as there's no evaluation whatsoever about risks, and it's simply not yet working for the intended usecases.

cheers
jOERG

[edit] titan beat me on posting speed ;-) so please excuse if this sounds a bit weird, as I wasn't aware of his previous post when I hit the "reply" button

blue_led 2010-05-13 19:01

Re: N900 will not allow USB OTG!
 
look into /etc/bme & /etc/event.d/bme.dpkg-new
at the end of bme f* script !

description "starting bme"
author "Simo Piiroinen"

console output

start on started dsme
stop on starting shutdown

service
nice -1

env LOGGER='/usr/bin/logger -s -tBME'
env STOP_FLAG=/tmp/bme.was.stopped

env SYSFS_VBUS_PATH=/sys/class/i2c-adapter/i2c-1/1-0048/twl4030_usb/vbus
env BACKLIGHT_PATH=/sys/class/backlight/acx565akm/brightness

pre-start script
set +e
$LOGGER -pdaemon.notice 'pre-start'

EXPORT_CARDS=0

case $(cat /tmp/STATE) in
USER)
if [ -e /var/lib/ke-recv/usb_phonet_mode ]; then
modprobe g_nokia || true
initctl emit G_NOKIA_READY
else
modprobe g_file_storage luns=2 stall=0 removable || true
fi
;;
ACT_DEAD)
modprobe g_file_storage luns=2 stall=0 || true
EXPORT_CARDS=1
;;
*)
$LOGGER -pdaemon.notice 'skip modprobe g_*'
;;
esac

DISC='/dev/mmcblk0p1'
CARD='/dev/mmcblk1'

LUN0='/sys/devices/platform/musb_hdrc/gadget/gadget-lun0/file'
LUN1='/sys/devices/platform/musb_hdrc/gadget/gadget-lun1/file'

if [ $EXPORT_CARDS -eq 1 ]; then
if [ -b $DISC ]; then
echo $DISC > $LUN0 || true
fi
if [ -b $CARD ]; then
echo $CARD > $LUN1 || true
fi
fi

if ! /usr/sbin/waitfordsme ; then
$LOGGER -pdaemon.crit 'waitfordsme failed'
exit 1
fi

# check dead battery pre-charge
# (or poweroff if battery can't be charged)
if [ $(cat $SYSFS_VBUS_PATH) -eq 1 ]; then
$LOGGER -pdaemon.notice 'starting battery precharge'

# Minimize power usage during pre-charge
echo 0 > $BACKLIGHT_PATH

# Drive yellow led with device charging pattern to improve UX
# Must be done before actually running the "bme-RX-51 -b" - its slow

# Clearing LED-state to be sure
echo "disabled" > /sys/class/i2c-adapter/i2c-2/2-0032/engine1_mode
echo "disabled" > /sys/class/i2c-adapter/i2c-2/2-0032/engine2_mode
echo 0 > /sys/class/leds/lp5523:r/brightness
echo 0 > /sys/class/leds/lp5523:g/brightness
echo 0 > /sys/class/leds/lp5523:b/brightness

# Setting yellow light pattern and running it
echo "load" > /sys/class/i2c-adapter/i2c-2/2-0032/engine1_mode
echo "000001100" > /sys/class/i2c-adapter/i2c-2/2-0032/engine1_leds
echo "9d804000427f0d7f7f007f0042000000" > /sys/class/i2c-adapter/i2c-2/2-0032/engine1_load
echo "load" > /sys/class/i2c-adapter/i2c-2/2-0032/engine2_mode
echo "000000000" > /sys/class/i2c-adapter/i2c-2/2-0032/engine2_leds
echo "9d800000" > /sys/class/i2c-adapter/i2c-2/2-0032/engine2_load
echo "run" > /sys/class/i2c-adapter/i2c-2/2-0032/engine2_mode
echo "run" > /sys/class/i2c-adapter/i2c-2/2-0032/engine1_mode
echo 20 > /sys/class/leds/lp5523:r/led_current
echo 2 > /sys/class/leds/lp5523:g/led_current
echo 0 > /sys/class/leds/lp5523:b/led_current

/usr/sbin/bme_RX-51 -b
case $? in
0)
$LOGGER -pdaemon.notice 'precharge -> ok'
;;
2)
$LOGGER -pdaemon.crit 'precharge -> power off'
# power off request has been sent to dsme

# Turn off charging-LED to avoid "ghost charging" when cable removed
echo "disabled" > /sys/class/i2c-adapter/i2c-2/2-0032/engine1_mode
echo "disabled" > /sys/class/i2c-adapter/i2c-2/2-0032/engine2_mode
echo 0 > /sys/class/leds/lp5523:r/brightness
echo 0 > /sys/class/leds/lp5523:g/brightness
echo 0 > /sys/class/leds/lp5523:b/brightness

exit 1
;;
*)
$LOGGER -pdaemon.crit 'precharge -> failure'
# some mystery failure, continue startup
;;
esac
fi
end script

script
set +e
$LOGGER -pdaemon.notice 'start'
exec /usr/sbin/bme_RX-51
end script

# create flag file if bme is stopped on purpose (via upstart)
pre-stop script
set +e
$LOGGER -pdaemon.notice 'pre-stop'
touch $STOP_FLAG
end script

# reboot the device if flag file is not present (bme crashed)
post-stop script
set +e
$LOGGER -pdaemon.notice 'post-stop'
if [ -e $STOP_FLAG ]; then
rm $STOP_FLAG
else
$LOGGER -pdaemon.crit "crash detected -> rebooting"
/usr/sbin/dsmetool --reboot
fi

end script

MohammadAG 2010-05-13 23:41

Re: N900 will not allow USB OTG!
 
Quote:

Originally Posted by blue_led (Post 657290)
look into /etc/bme & /etc/event.d/bme.dpkg-new
at the end of bme f* script !

# reboot the device if flag file is not present (bme crashed)
post-stop script
set +e
$LOGGER -pdaemon.notice 'post-stop'
if [ -e $STOP_FLAG ]; then
rm $STOP_FLAG
else
$LOGGER -pdaemon.crit "crash detected -> rebooting"
/usr/sbin/dsmetool --reboot
fi

end script
[/COLOR][/I]

Mentioned that on #maemo over the IRC, no idea if joerg_rw checked it out or not

6sicSIX 2010-05-13 23:52

Re: N900 will not allow USB OTG!
 
Thanks all of you! I have no idea what anyone is talking about, but it looks like some real progress is being made :)

joerg_rw 2010-05-13 23:58

Re: N900 will not allow USB OTG!
 
Quote:

Originally Posted by MohammadAG (Post 657682)
Mentioned that on #maemo over the IRC, no idea if joerg_rw checked it out or not

I looked into that by going over the results of 'grep bme /etc', so I was of course aware of that. Why do you think I suggested 'stop bme', and why I suggested to Titan (and others) to remove bme references in init.d/upstart-event scripts?
It's pretty clear bme needs to be started first, if it wants to tear down the device. So if we don't start it in init/upstart it probably won't reboot the kernel.

I'm a little unsure though about that (from top):
[2010-05-13 16:25:28] <DocScrutinizer> t-tan: [2010-05-13 00:41:14] <DocScrutinizer> PP:hald-runer PID:821 hald-addon-usb-cable: listening on /sys/devices/platform/musb_hdrc/usb1/../mode

I.E. we don't know what relies on a working BME and in which way.

There's one thing we can be sure though: battery will not explode or otherwise be killed when there's no bme. The bq24150 will wake up to sane safe defaults like max USB current 100mA, max battery charge voltage 3.7V, and it should start charging with these parameters, for at least 32min ("recover from flat battery" scheme). With a little luck (and support from a correctly configured 1707 PHY chip) the bq24150 will detect a dedicated charger (D+/- short) and crank up max USB current to 500mA. But no matter if it starts charging, and at which rate - it never will overcharge the battery unless there's a bme forcing it to do that. So removing / replacing bme is as safe as any other software project, you can do nasty things if you *want*, but they won't happen by accident. A failing or nonexistent bme will NOT cause any hazard.

/j

egoshin 2010-05-14 05:27

Re: N900 will not allow USB OTG!
 
2 Attachment(s)
Quote:

Originally Posted by egoshin (Post 656408)
Success!

I just was able to mount USB stick via self-powered HUB and read it.

Device - /dev/sda1

Details will be later, but now - modified kernel. I am looking into right modification.

If you want repeat a test, some detailed explanation is here:

A. You need a modified kernel build from 2.6.28-20100903+0m5. A default kernel configuration arch/arm/configs/rx51_defconfig should be modified:

1 - remove CONFIG_USB_OTG_WHITELIST and CONFIG_USB_OTG_BLACKLIST_HUB options.

2 - Apply an attached patch (u.txt) to kernel sources.

3 - Build a kernel.

B. Boot a kernel

C. Connect to PC and answer "PC Suite" to mode question.

D. echo host >/sys/devices/platform/musb_hdrc/mode
You should see in /var/log/syslog a message "twl4030_set_host() after 4030 OTG_CTRL=0x26" - the '2' is a significant.

E. echo H >/proc/driver/musb_hdrc

F. reattach USB cable from PC to self powered USB hub with memory stick or to external hard disk.

E. Look into /var/log/syslog - You can see a lot of messages and two are most valuable - "Initializing USB Mass Storage driver" and "
USB Mass Storage support registered". And in between you may see "scsi0 : SCSI emulation for USB Mass Storage devices".

F. After some time the scanning finishes and you may execute

mount /dev/sda1 /mnt

(check /dev/sda1 first!)

Viola!

If somebody could repeat it - it would be a very good information, I worries about some HW differences or wrong setup of D+/D-.

I also attach a copy of my log for reference (a lot of debug output here).

Note: ke_recv has some problem with storage recognition and it is a reason why a manual mount is needed. Don't forget to unmount before cable detachment. Or just switch N900 OFF.

joerg_rw 2010-05-14 12:56

slightly off topic - make N900 charge without bme
 
first draft for putting bq24150 into fastcharge mode at a reasonable charge end voltage, and keep it in charge mode until battery is full:

Code:

i2cset -y -m 0x77 2 0x6b 0x04 0xc9;
# next register 0x03 is device ID, always 4b and r/o; so we skip to 0x04
i2cset -y -m 0xff 2 0x6b 0x02 0x8c;
# 0x8c = 3v5 + .640 + .040 + .020 = 4V200, BE CAREFUL and DON'T CHANGE
# unless you know what you're doing. 4V2 is ABS MAX!
i2cset -y -m 0xff 2 0x6b 0x01 0xc8;
i2cset -y -m 0xc0 2 0x6b 0x00 0x00;

# tickle watchdog, while status indicates 'charging from wallcharger'
while [ $(i2cget -y 2 0x6b 0x00) = 0x90 ] ; do
  sleep 28;
  # reset watchdog timer:
  i2cset -y -m 0x80 2 0x6b 0x00 0x80;
done
echo "charging finished, status(reg0)=$(i2cget -y 2 0x6b 0x00)"

above code not yet tested, but should result in

Code:

Nokia-N900-02-8:~# ~user/i2c/i2cdump -y -r 0-4 2 0x6b
No size specified (using byte-data access)
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 90 c8 8c 4b c9                                    ???K?

which is what bme sets bq24150 to, during normal charge process

Usual disclaimer: this is addressed to developers only, who exactly understand the above code. ENDUSERS STAY AWAY


cheers
jOERG

cb22 2010-05-14 13:09

Re: slightly off topic - make N900 charge without bme
 
According to the wiki, the reason given for BME being closed source is:
Quote:

bme - Battery Management Entity: Security. A misuse of the could lead to serious battery damages that could result in liabilities for Nokia. hald-addon-bme is a related package, also closed.
Maybe a well written comment on the existing open source request for it (https://bugs.maemo.org/show_bug.cgi?id=9314) with info about what's been happening in this thread could help.

Failing that, maybe they would be so kind as to let a few people (egoshin / joerg / etc) have access to the code under an NDA...

joerg_rw 2010-05-14 13:20

Re: N900 will not allow USB OTG!
 
sorry for the edits in post 2 above (charging), but while testing I found the registers need another sequence to be set correctly.
anyway now it is at least tested and working for what can be told by watching your shell

/j

javispedro 2010-05-14 14:02

Re: N900 will not allow USB OTG!
 
Quote:

Originally Posted by egoshin (Post 657866)
...

So basically there's NO changes other than enabling the charge pump? Dang it, so my supposed self-powered hub is a not as selfpowered as I though...

egoshin 2010-05-14 16:24

Re: N900 will not allow USB OTG!
 
Quote:

Originally Posted by javispedro (Post 658368)
So basically there's NO changes other than enabling the charge pump? Dang it, so my supposed self-powered hub is a not as selfpowered as I though...

Yet another changes to avoid whitelist and blacklist problems.

EDIT: I do not enable charge pump, it is impossible (read joerg). But to work as HOST some VBUS voltage is needed (read blue_led) and TWL4030 is an obvious candidate. I don't know - is it possible to use VBUS from 1707 chip (a real USB PHY) because checking it requires too much change in code - driver actively works with 1707 registers and intermixing both is difficult to predict.

And of course - the procedure... it is not suitable for normal use because it requires PC initially. I am working on that stuff right now, and first - try to use FORCE_HOST. However, it is not simple as a success experiment, it doesn't see anything at all, so I am looking into code and acquiring logic.

BTW, if joerg is successfull in setting VBUS charge voltage and workaround BME intervention it could be a solution for non-selfpowered hubs/HDs. I did an experiment with his command (first version) and it seems it works, at least until DSME shutdowns N900. I stopped do it for now because fast shutdown does too much confusion in results and I can't go far enough until mounting USB stick.

egoshin 2010-05-14 16:39

Re: slightly off topic - make N900 charge without bme
 
Quote:

Originally Posted by joerg_rw (Post 658278)
first draft for putting bq24150 into fastcharge mode at a reasonable charge end voltage, and keep it in charge mode until battery is full:

Joerg, double check - is this code a replacement of BME which is supposed to be stopped by earlier published script?

javispedro 2010-05-14 17:41

Re: N900 will not allow USB OTG!
 
Quote:

Originally Posted by egoshin (Post 658557)
EDIT: I do not enable charge pump, it is impossible (read joerg). But to work as HOST some VBUS voltage is needed (read blue_led)

That's my issue here, I though you don't need vbus at all for certain devices. In fact I'm not still sure about this. I know that the driver as is disables the PHY when gaia's vbus sense is not asserted -- you must have seen this.
And of course without the (even if it's broken) pump and without a host connection it's surely not asserted. Pumping even a measly 3,0 V might mean that the useless-for-charger-detection vbus sense in gaia gets asserted, and the PHY turns on.

(Of course the less changes to the driver the better)

Quote:

Originally Posted by egoshin (Post 658557)
And of course - the procedure... it is not suitable for normal use because it requires PC initially. I am working on that stuff right now, and first - try to use FORCE_HOST. However, it is not simple as a success experiment, it doesn't see anything at all, so I am looking into code and acquiring logic.

You mention that you need to select PC Suite mode. Does it work with USB STorage Mode? If it works only with PC Suite mode, I think it might have to do with g_mass_storage (weird suspicion). rmmod it and modprobe g_zero before switching to host.

Quote:

Originally Posted by egoshin (Post 658557)
BTW, if joerg is successfull in setting VBUS charge voltage and workaround BME intervention it could be a solution for non-selfpowered hubs/HDs. I did an experiment with his command (first version) and it seems it works, at least until DSME shutdowns N900.

DSME reboots can be entirely disabled via a /etc file. The issue iirc is the rest of watchdogs, and even those can be disabled by a r&d flag.

titan 2010-05-15 15:30

Re: N900 will not allow USB OTG!
 
An updated version of the kernel with egoshin's patches and
CONFIG_USB_GPIO_VBUS=m
CONFIG_USB_GADGET_DEBUG=y
is now available.

Quote:

Originally Posted by titan (Post 654575)
I have build a special version of the power-user kernel with USB debugging and verbose enumeration enabled, and the USB blacklist+whitelist disabled.
Modules for all common USB device classes are already included (for USB/IP).
I hope it can help you to get USB hostmode working on the N900.

download and install in this order
http://maemory.com/N900/kernel/testi...mo28_armel.deb
http://maemory.com/N900/kernel/testi...mo28_armel.deb
http://maemory.com/N900/kernel/testi...mo28_armel.deb
the kernel configuration is http://maemory.com/N900/kernel/testi...ower_defconfig

good luck!


hcm 2010-05-15 17:37

Re: N900 will not allow USB OTG!
 
hi guys!

I've been following you on this thread for quite some time, and recently also in the chatroom. I'm really impressed by your work so far! Keep it going :)

I would like to join you in testing, I have a rather good knowledge of linux and also some hardware-level-experience of USB. But I'd still like some advice:
  • What would you recommend for checking the device health during testing, i.e. battery voltage/current(in/out)/temperature, VBUS level, etc. What are some interesting procfs/sysfs files to monitor?
  • Are there any important I2C registers to monitor? From the bq24150 (0x6b) or other I2C devices?
  • To which degree is debugfs and usbmon working in titans new kernel? Any (special) setup needed? (except mounting debugfs and modprobing usbmon)
  • Are there datasheets for the TWL4030 and the 1707 (could only find one for TPS65950 which is apparently similar (?) to the TWL)
  • And finally: do you know a (working) way to save/restore the whole filesystem in case anything goes wrong? :rolleyes:

I think that's it for now… Would be great if you could give me some hints :)
Btw, it's not important if charging doesn't work, I have a desktop charger.

titan 2010-05-15 18:23

Re: N900 will not allow USB OTG!
 
1) modprobe bq27x00_battery and check /sys/class/power_supply/bq27200-0
3) both are compiled in
ls /sys/kernel/debug/usbmon/
0s 0u 1s 1t 1u
5) always backup and be prepared to reflash :)

Quote:

Originally Posted by hcm (Post 659843)
  • What would you recommend for checking the device health during testing, i.e. battery voltage/current(in/out)/temperature, VBUS level, etc. What are some interesting procfs/sysfs files to monitor?
  • Are there any important I2C registers to monitor? From the bq24150 (0x6b) or other I2C devices?
  • To which degree is debugfs and usbmon working in titans new kernel? Any (special) setup needed? (except mounting debugfs and modprobing usbmon)
  • Are there datasheets for the TWL4030 and the 1707 (could only find one for TPS65950 which is apparently similar (?) to the TWL)
  • And finally: do you know a (working) way to save/restore the whole filesystem in case anything goes wrong? :rolleyes:


SpeedEvil 2010-05-15 21:14

Re: N900 will not allow USB OTG!
 
Quote:

Originally Posted by titan (Post 659887)
1) modprobe bq27x00_battery and check /sys/class/power_supply/bq27200-0
3) both are compiled in
ls /sys/kernel/debug/usbmon/
0s 0u 1s 1t 1u
5) always backup and be prepared to reflash :)

One caveat.
the current exposed by the bq27200 needs multiplied by (20/3.57)mA to get a current.

It's a raw value from the chip.
the '20' is arguable - but is at least more or less reasonable.
This is as the chip really reads out in units of 3.57uV, and the resistor the battery current is applied across is 20mR in the datasheet recommendation.

titan 2010-05-16 22:50

Re: N900 will not allow USB OTG!
 
FYI:
echo 5 > /sys/module/musb_hdrc/parameters/debug
enables USB debugging in dmesg!
it contains very interesting information incl. line numbers

javispedro 2010-05-17 00:41

Re: N900 will not allow USB OTG!
 
Using egoshin's idea, I got a DisplayLink device working:

http://depot.javispedro.com/nit/usb/displaylink.jpg

This is the same USB monitor shown at the DisplayLink homepage, connected to a N900, in dual screen "clone" mode (more accurately x11vnc, vnc2dl and libdlo, all on the N900). vnc2dl seems to have a 1280x1024 forced resolution.

Basically the requirement of connecting the N900 to a host previously is the key. If you play your cards well you don't even need to patch the kernel (Y-cable, or fully self powered bug, etc.).
I initially though that this requirement came from a g_mass_storage bug that seemingly also happens on the beagleboard, but I was wrong.

Seemingly, DocScrutinizer is right: for some reason after repeating egoshin's steps the N900 seems incapable of closing any USB session, and thus after you unplug it from the host it still believes it's plugged into it, keeping everything powered on. This tricks the driver's OTG state machine into some weirdo state where something starts moving :).

Also, with this method you cannot unplug the hub from the N900, as per the above the N900 will keep on thinking it's still connected to it, thus causing mayhem on the kernel.

qole 2010-05-17 06:28

Re: N900 will not allow USB OTG!
 
apparently superheroes can be on multiple teams at the same time. :)

Keep up the good work guys!

titan 2010-05-17 17:24

Re: N900 will not allow USB OTG!
 
I cannot replicate this. btw, it is /proc/driver/musb_hdrc

Quote:

Originally Posted by egoshin (Post 657866)
If you want repeat a test, some detailed explanation is here:
C. Connect to PC and answer "PC Suite" to mode question.

D. echo host >/sys/devices/platform/musb_hdrc/mode
You should see in /var/log/syslog a message "twl4030_set_host() after 4030 OTG_CTRL=0x26" - the '2' is a significant.

E. echo H >/proc/drivers/musb_hdrc

F. reattach USB cable from PC to self powered USB hub with memory stick or to external hard disk.

E. Look into /var/log/syslog - You can see a lot of messages and two are most valuable - "Initializing USB Mass Storage driver" and "
USB Mass Storage support registered". And in between you may see "scsi0 : SCSI emulation for USB Mass Storage devices".


javispedro 2010-05-17 17:37

Re: N900 will not allow USB OTG!
 
Quote:

Originally Posted by qole (Post 661857)
apparently superheroes can be on multiple teams at the same time. :)

Hah, not really a superhero as I discarded all what I was doing to test egoshin's method, which is the first time I've ever seen it moving.

Btw, you might need the patches after all -- seems I had some previous leftover on my N900 (be careful as some settings survive rebooting and reflashing, forcing you to remove the battery).

egoshin 2010-05-17 17:52

Re: N900 will not allow USB OTG!
 
Quote:

Originally Posted by titan (Post 662763)
I cannot replicate this. btw, it is /proc/driver/musb_hdrc

Interesting. Sometime I can't do it too but I blamed it to some leftovers and repeat it after removing battery.

But there is still a possibility that some process like BME or DSME intervenes and creates a problem.

BTW, did you see in log a message "twl4030_set_host() after 4030 OTG_CTRL=0x26"?

egoshin 2010-05-17 17:59

Re: N900 will not allow USB OTG!
 
Quote:

Originally Posted by javispedro (Post 661612)
Using egoshin's idea, I got a DisplayLink device working:

http://depot.javispedro.com/nit/usb/displaylink.jpg

This is the same USB monitor shown at the DisplayLink homepage, connected to a N900, in dual screen "clone" mode (more accurately x11vnc, vnc2dl and libdlo, all on the N900). vnc2dl seems to have a 1280x1024 forced resolution.

Basically the requirement of connecting the N900 to a host previously is the key. If you play your cards well you don't even need to patch the kernel (Y-cable, or fully self powered bug, etc.).
I initially though that this requirement came from a g_mass_storage bug that seemingly also happens on the beagleboard, but I was wrong.

Seemingly, DocScrutinizer is right: for some reason after repeating egoshin's steps the N900 seems incapable of closing any USB session, and thus after you unplug it from the host it still believes it's plugged into it, keeping everything powered on. This tricks the driver's OTG state machine into some weirdo state where something starts moving :).

Also, with this method you cannot unplug the hub from the N900, as per the above the N900 will keep on thinking it's still connected to it, thus causing mayhem on the kernel.

To return back from host mode state to normal just do:

echo peripheral >/sys/devices/platform/musb_hdrc/mode

It will cancel VBUS and it immediately stops a session.

BUT! It doesn't do the right stuff about DISK - you should unmount it first, especially if it is not ISO9660 format but some Linux file system.

javispedro 2010-05-17 18:03

Re: N900 will not allow USB OTG!
 
Quote:

Originally Posted by egoshin (Post 662823)
To return back from host mode state to normal just do:

echo peripheral >/sys/devices/platform/musb_hdrc/mode

It will cancel VBUS and it immediately stops a session.

I couldn't -- as I've noticed though my twl3040 was possibly in some random state -- I wasn't using your kernel.

hcm 2010-05-17 18:15

Re: N900 will not allow USB OTG!
 
fyi, just found a comparison chart of USB PHY:
http://www.ebv.com/fileadmin/product...sceivers_1.pdf

and checked out the isp1704a because of its similarity to the 1707:
http://www.stericsson.com/product/222222.jsp

It is 100% pin-compatible to the chip in the N900-schematic (which only misses ID and PSW, in comparison to isp1704a, but ID should be present somehow, considering its an OTG chip…)

happy reading :)


All times are GMT. The time now is 15:09.

vBulletin® Version 3.8.8