Wednesday, April 16, 2008

The TURBO button

Did more work on my HVR-950 code tonight. Because of some broken patches I received from Mauro, I couldn't focus on figuring out why switching between digital and analog mode doesn't work. So instead I looked at why firmware loading took forever.

The Xceive 3028 is a programmable digital tuner, and one of the things you have to do is load microcode into the device. For some reason, it was taking 13 seconds to load the firmware, which is only about 60 KB. Bear in mind that this is a tuner chip that normally transfers data at around 19 Mb/s.

I thought perhaps there was some limitation on the speed of the i2c bus in the em28xx bridge, or perhaps there was some magic register you had to set to change the bus speed. In the end, the answer was MUCH simpler:

From: Devin Heitmueller

- Remove sleep in i2c message routine which slows down i2c by a factor
10x. Load time for BASE firmware went from 13s to .973s

Signed-off-by: Devin Heitmueller

diff -ur a/v4l/em28xx-core.c b/v4l/em28xx-core.c
--- a/v4l/em28xx-core.c 2008-04-16 00:34:32.000000000 -0400
+++ b/v4l/em28xx-core.c 2008-04-17 01:48:04.000000000 -0400
@@ -153,7 +153,6 @@
ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), req,
0x0000, reg, bufs, len, HZ);
- msleep(5); /* FIXME: magic number */
return ret;

Yup, somebody stuck a 5 millisecond sleep into a low level function that sends commands onto the USB bus. While .005 seconds doesn't sound like much, try doing that around 2600 times, and you magically end up with around 13 seconds...