$Id: pvrusb2.html 1074 2006-04-18 06:34:42Z isely $
Mike Isely <isely at pobox dot com>
The home location for this page is here.
If you have any suggestions for improving either this web page or the driver itself, please drop me a message.
Contents
New hardware Information
Contacting People / Discussion List
Background
Download
Setup
Usage
Interactions with other drivers
FAQ
Utilities
Bugs
Change History
17-Apr-2006
VERY IMPORTANT: Hauppauge has recently respun the PVR USB2 hardware, and at the current moment though this driver works with it, support is very new and there may be some nasty bugs still lurking.
I am working to update the driver appropriately to operate the new hardware version and we're almost there. The current snapshot includes theoretically all of the changes needed to support the new device, but there still needs to be more testing here before we know it's good. There might still be some stability issues.
There are a few ways you can tell if you have the respun hardware:
Unfortunately I don't know of any way to determine the difference from looking at the retail package and of course since the official name hasn't changed, there isn't any way to specifically purchase the older device.
If you have the older device, then you're good to go with this driver and everything else on this site should apply.
If you have one of the newer devices then go on ahead and try it. Unfortunately the documentation here is not caught up yet. However the main differences for the new hardware are that (1) you really need to use a 2.6.16 or later kernel, and (2) there are three firmware files to install not too (fwextract will show you). If you try this driver with new hardware, please let me know of your success / failure.
If you wish to contact me, my e-mail address is spelled out at the top of this page.
There is also a pvrusb2 e-mail discussion list, hosted here at this site. This is a mailman-operated list, so you can subscribe, unsubscribe, access your subscription, scan archives, etc via the web. (You can also initiate a subscription by sending a message to <pvrusb2-subscribe at isely dot net>.) Any pvrusb2 relevant topic there is fair game. Posting to the pvrusb2 list is limited to just subscribers, but I encourage you to subscribe to the list.
Note also for those who use IRC, the channel #pvrusb2 has been set up on freenode. I tend to idle there (with a fairly obvious handle) when I can.
The main web page for the discussion list can be found here.
This driver is intended for the Hauppauge WinTV PVR USB2, which is a USB 2.0 hosted TV Tuner. Examples for sale can be found at pricegrabber. Please note that this driver is only for the WinTV PVR USB2, and in particular this driver is not for the seemingly similar sounding Hauppauge WinTV USB2 which is in fact a completely different and far less capable device from Hauppauge. (See here for a driver that should work with the WinTV USB2 hardware.)
This driver is very much a work in progress. Its history started with the reverse-engineering effort by Björn Danielsson whose web page can be found here. From there Aurelien Alleaume began an effort to create a video4linux compatible driver. His web page about this driver can be found here. Unfortunately it seems that Aurelien has stopped working on this driver. Repeated attempts to contact him over several months have not been successful. Thus I have for now taken Aurelien's latest snapshot and begun making changes. This page describes those efforts.
If you have trouble getting the driver to work, please read through this page again - there are a lot of details here and it's easy to miss something. Also, I've written a short FAQ covering common situations that people have found themselves in. If none of that helps, send me a message - it's entirely possible that you might have encountered something new and thus I want to hear about it so I can address the problem for everyone...
Downloads can be found here: pvrusb2-download.html
This driver only works under Linux 2.6.x. I have not made any attempt to even try it in 2.4.x and I know there are environmental differences which likely prevent it from running or even loading.
The WinTV-PVR-USB-2.0 tuner is a device containing an 8051 microcontroller and a cx23416 mpeg2 encoder, both of which must be loaded with vendor firmware before the driver will run. That firmware is not included here; you must extract it from the Windows driver package that came with your device and then place that firmware in a location where the hotplug system can find it. See the next section about firmware extraction for more information.
This driver uses a standard kernel facility for loading firmware images, and that facility requires that hotplug (or whatever might take its place in the future) be configured into your kernel and its utilities installed in order to operate correctly. Therefore, while the use of hotplug is not strictly needed (but is nice to have) for loading the pvrusb2.ko module itself, you must have hotplug installed in order for this driver to work.
The main driver module (pvrusb2.ko) specifically depends on several other kernel modules in order to function correctly. These are tveeprom.ko, tuner.ko, msp3400.ko, saa7115.ko, and possibly also (for some hardware) tda9887.ko. All (except saa7115.ko) can be built as part of the core v4l kernel implementation. Alternatively, all (except tda9887.ko) can be found as part of the ivtv driver. A snapshot from ivtv of these modules is included in this snapshot and can be built alongside everything else here. However you may elect to use later (and perhaps improved) versions from elsewhere. In fact, the included support modules are getting rather old compared to what is in the kernel tree so you're better off just using the kernel versions if you can (in fact these included modules won't even compile right now under 2.6.16). More details on this can be found further down. Regardless of the ultimate source for these drivers, they must be loaded into the kernel in order for the pvrusb2 driver to function correctly. If tveeprom.ko is not present, then pvrusb2.ko will fail to load (and probably complain about a symbol tveeprom_hauppauge_analog being undefined). But the other modules are all bound late into the driver via the kernel's I2C abstraction layer so their absence will be harder to figure out. Note that the pvrusb2 driver will attempt to autoload them all upon initialization.
Interaction with the tveeprom.ko module has recently become a lot more complicated due to apparent divergence between ivtv (0.4.0) and v4l (in kernel 2.6.14), combined with some ongoing issues that the pvrusb2 driver has had to contend with when using this module. If you think you might be having trouble with tveeprom, please read this page: pvrusb2-eeprom.html and possibly also this FAQ item pvrusb2-faq.html#Q19, which describes in great detail the sorts of things I had to watch out for when dealing with that module.
This driver has been tested against 2.6.10-ac12 and 2.6.11.7 with the "-3" v4l release applied against it. It has also been successfully tested against stock 2.6.11.10, 2.6.12.3, 2.6.13-rc6 (as of the 20050824 snapshot), 2.6.13.4, 2.6.14-rc4 (as of the 20051016 snapshot), 2.6.14.3, 2.6.15-rc2 (as of the 20051126 snapshot), and 2.6.15 (as of the 20060103 snapshot). All were tested using the kernel v4l-provided chip drivers and also with pvrusb2-supplied chip drivers. Don't count on being able to get this driver to work with anything older than 2.6.10.
Note: If your driver build fails with a complaint about being unable to find media/tveeprom.h, then your kernel sources are probably too old.
There are a couple programs in the utils subdirectory of this distribution that can perform the correct extraction of needed firmware data. Full information on firmware extraction can be found on the separate utilities page, but here's a really quick recipe:
If the above doesn't work, here a "less" quick recipe to follow:
Substitute the name of the driver package you got from Hauppauge for "driver_package.EXE" which is just a placeholder above. If you're starting from a CDROM copy of the drivers, then just copy the driver subdirectory contents into "win_driver" instead of doing the unzip step above.
You now should see two files in the current directory:
File | Size | Description |
---|---|---|
v4l-pvrusb2-29xxx-01.fw | 8192 bytes | 8051 program image |
v4l-cx2341x-enc.fw | 262144 bytes | mpeg2 encoder image |
If that didn't work, then possibly you're dealing with a later driver version that fwextract.pl doesn't know how to handle yet. Solving this requires a more complex manual extraction. See here for more info.
Note: The above two files used to be known as pvrusb2.f1 and pvrusb2.f2, respectively. Starting with the 20060318 snapshot they have been renamed (but the snapshot should also locate and use the old files if they are present).
Failing all of the above, you can still try to extract the firmware using previous methods. Information on that can be found on Björn's web page, mentioned previously. Note that you may need to rename the firmware file names in that case (see table above for clues on the correct names).
The pvrusb2 driver sources and build files can be found in the driver subdirectory of the distribution.
A set of support module sources and build files can be found in the ivtv subdirectory of the distribution. Note that these are all copies from ivtv and provided here for convenience; you do not have to use these if you have better alternatives. (Before the 20051109 snapshot, these modules were comingled with the pvrusb2 driver proper in the driver subdirectory.) Note: As of kernel 2.6.15, all of these support modules are also in the kernel and the kernel versions are more up-to-date. In fact as of 2.6.16, these modules won't even compile any longer, so I recommend you just use the kernel versions and don't bother with the ivtv subdirectory. If however you are building pvrusb2 for an older kernel version, you may still want / need to use these included support modules.Compile this driver more or less in the usual way one does to build 2.6.x kernel modules outside of the kernel source tree. Said another way, you need a kernel source tree somewhere nearby, and you need to run make in both driver and possibly also ivtv (if you need to build the included support modules - see previous paragraph) with KDIR or KREL variables set to help make find where you put that source tree. For example (starting from the root of the driver snapshot tree):
export KREL=`uname -r`
export KDIR=/lib/modules/$KREL/source
make --directory ivtv # ONLY if you need these
make --directory driver
If you set neither KDIR nor KREL, then KREL is assumed to be the output of uname -r and KDIR is assumed to be /lib/modules/$(KREL)/source (same as the example above). Since nothing else except the default KDIR value needs KREL, then you can skip setting KREL if you set KDIR. This is all explained in the comments that you can find within the Makefile itself (both in the driver and ivtv subdirectories).
Note that as of kernel 2.6.15, all support modules (including saa7115.ko which has been reconstituted there as saa711x.ko) are finally available directly in the kernel sources. Thus provided your kernel has been configured to build these modules, then you can safely skip building and installing of the ivtv part of this driver (or alternatively installing ivtv itself). As of kernel 2.6.16, the included support modules here won't even compile anymore so if you are using 2.6.16, you have no choice but to use the kernel versions anyway.
Before going on, you did extract and install the 2 required vendor firmware files, right? If not, go back and read the second paragraph of the Prerequisites section above before continuing any further.
Once you have the driver compiled, you must copy the the binary modules into your kernel's module area. The target directory is typically under /lib/modules/$(KREL). I usually use /lib/modules/$(KREL)/pvrusb2/ as the destination but the choice is up to you. Note that there are multiple modules (*.ko) to copy from both driver and ivtv (if you built the support modules there). The actual driver is pvrusb2.ko and you must copy that. The other modules from the ivtv subdirectory as mentioned earlier function in a support role; copy them as well if you want to use them. Otherwise, ensure that equivalents are available through some other means. After everything is copied, run depmod -a so that the module loader will recognize any needed dependencies.
NOTE: Some people have instead just run "make install" to let the build system copy the modules for you. This worked - up until the 20050527 snapshot. Before that point there was an explicit rule in the driver's local Makefile that did this. However I removed this rule in the (perhaps misguided) goal of simplification and outsourcing of everything to Kbuild. Now if you type "make install" you'll be running the kernel build system's "install" target - which will try to install a kernel not the modules! That of course (hopefully) fails. This problem has been fixed in the 20050605 snapshot.
A few important notes need to be said here about those "support" modules before we continue (this comes from feedback from various people trying out the driver):
find /lib/modules/$(KREL)/ -name tuner.ko -print
If you miss this detail, you may end up loading the wrong module. Do
this before you execute the depmod -a step.tveeprom: tuner = Philips FM1236 MK3 (idx = 58, type = 4)
Then you are using a type 58 tuner. This is a problem for the version
of tveeprom.ko included with the Linux kernel - it doesn't
correctly map that type to a v4l tuner definition. Thus you won't be
able to tune anything and you'll get static. The solution in this
case is to use the tveeprom.ko included in this snapshot (or
tveeprom.ko included in ivtv; they're the same).You can next execute modprobe pvrusb2 to load the driver. After this point, lsmod should show pvrusb2, tveeprom, tuner, msp3400, saa7115, and possibly tda9887 all present. This step is not strictly needed however, as hotplug (which you must have set up anyway due to firmware loading requirements) will do the needed module loading when the device appears in the system.
Plug in your WinTV-PVR-USB-2.0 device and after a few seconds the driver should be ready to go. Progress can be noticed by watching the kernel log.
Note that the level of log verbosity is controlled through a global bit mask variable whose name is debug. This mask is set initially at compile time; you might want to change it. See the module parameters list below for more information.
If the driver isn't loaded when you plug in the device, that's OK because the hotplug facility should automatically find and load for you.
There are a number of module parameters you may specify to the module when it is loaded; none however are strictly needed. Note that these parameters are also all visible at run-time by examining the directory /sys/module/pvrusb2/parameters/. Most parameters there are read-only (because they only are looked at during initialization). However the debug parameter in particular can be changed at any time simply by echoing a new value into its file name within that directory.
Note that unless otherwise pointed out, these parameters are global to all instances of the driver (i.e. if you have two PVR USB2 devices plugged in the effect is the same on both corresponding driver instances). The following parameters exist:
The pvrusb2 driver should be robust enough now that it can survive about any hardware abuse you can throw at it. There are no known situations where it should ever generate a kernel oops. You should be able to plug / unplug the hardware or insert / remove the driver (or just about any support module) to your devious heart's content and the Linux kernel should just keep merrily going on its way. (Obviously if you find out otherwise, please let me know.)
There is one potential issue however with the device itself. From experiments I have done, it seems that if the device is in the middle of transaction with the driver, that unplugging the device at that instant can leave it in a useless (maybe crashed?) state. The only recovery is to power cycle the device. I have tried numerous approaches to implementing automatic recovery in the driver, but there doesn't seem to be any strategy possible that guarantees recovery. However I did the next best thing: If the driver detects that the device might be jammed, it will log a message suggesting that the device be power cycled. The driver should come through all this just fine of course. (Update 4-Jan-2006: It has been a very long time since I've seen this problem repeat; it might have been something else long since fixed in the driver.)
This driver provides an implementation of the video4linux version 2 and version 1 driver APIs. Any v4l application which can handle an mpeg2 stream should in theory be able to use this driver. (Unfortunately there seem to be very few v4l apps which can...)
One application you can try is xawtv 4.x. Note that anything before version 4 will definitely not work with this since earlier versions did not support mpeg2 decoding. Obviously, make sure you've built xawtv with mpeg2 video and mp3 audio support configured into it.
The xawtv application seems to have a number of rough edges. I've been testing with a snapshot from February 2005 which has worked well enough for me, but there are issues. More recent snapshots - up to 20050518-16206 have a bug which completely breaks the ability to stream mpeg2 video. The maintainer has been contacted and he's committed a fix to his CVS repository. So hopefully anything after that point should work a lot better. Here is a list of known issues to watch out for when trying xawtv:
Another application that works is mplayer. There are two ways to use mplayer: You can tell mplayer it's dealing with a tv device, or just pass it /dev/video0 (or whatever the right name is on your system) as the "file" to play. The first method has not been well tested, and is strongly suspected to have problems. The second method however works well. More debugging is needed here with the first method...
Similar to mplayer, xine is reported to work provided you treat the device file as just a normal file with mpeg contents. There is a v4l mode apparently for xine (I haven't tried it), but I've heard that it is very immature and definitely does not work with this driver when run in that manner.
The MythTV application of course is the holy grail for this driver. I got sucked into this whole effort because of this desire. Several people have since tested this driver against MythTV and are reporting success.
If want to try MythTV, here are some tips:
Please contact me if you find other apps which work, and I'll list them here.
This v4l implementation should allow for multiple opens. Said another way, if you have one application reading video from /dev/video0, it should be possible to have another application still open /dev/video0 and successfully manipulate driver controls. Of course, only one application at a time can stream video. A second attempt at streaming will be greeted with an I/O error.
There is an additional interface available with this driver. In parallel with the v4l interface, you can access all driver controls via sysfs. Once the device is plugged in and the driver is loaded, try this:
# cd /sys/class/pvrusb2/sn-XXXX
where XXXX is the serial number of your device (just let tab-completion do the hard work here since unless you have multiple tuners there will only be one file there). Now use "ls" and you'll see a whole bunch of directories all starting with "ctl_". Here is what my system looks like:
londo:~# cd /sys/class/pvrusb2/sn-6829718/ londo:/sys/class/pvrusb2/sn-6829718# ls ctl_audio_bitrate ctl_resolution_ver ctl_audio_crc ctl_saturation ctl_audio_emphasis ctl_signal_present ctl_audio_layer ctl_srate ctl_audio_mode ctl_streaming_enabled ctl_balance ctl_treble ctl_bass ctl_usb_speed ctl_brightness ctl_vbr ctl_channel ctl_video_average_bitrate ctl_contrast ctl_video_peak_bitrate ctl_debug_subsys_mask ctl_video_standard ctl_debug_subsys_stream_mask ctl_video_standard_mask_active ctl_freq_table_channel ctl_video_standard_mask_available ctl_freq_table_value ctl_volume ctl_frequency debugcmd ctl_hue debuginfo ctl_input device ctl_interlace uevent ctl_mute unit_number ctl_resolution_hor v4l_minor_number londo:/sys/class/pvrusb2/sn-6829718#
(The device and driver links you see there by the way point off to other parts of sysfs where the driver's and device's lower level control files can be found.)
Note that the "XXXX" part of the path is the device's serial number. It is possible that the driver might not be able to retrieve a serial number from the device (if there were problems reading the device's PROM). In this situation, the sysfs implementation here will substitute the device's unit id using the form "unit-X" (instead of "sn-XXXX") where "X" is the letter for the unit assigned to the device instance.
Each ctl_ directory has some subset of these files:
You can read any of these files just by cat'ing it out. All are read-only except for cur_val and custom_val, most of which can be set by just writing the new value into it (a few of those controls are actually completely read-only). The incoming value must be either an integer within the legal range specified by min_val and max_val, a legal enumeration constant (for enumerated controls) or a bit mask assignment (for bit mask controls) in order for the assignment to "take". Otherwise the program doing the write should get back an EINVAL error status.
Bit mask controls have a somewhat more complex expected format in order to support the setting and clearing of individual bits within the mask. The values you write in is expected to be a set of whitespace-seprated bit masks. If just the names are used then the entire mask is set to just those bits. If however each name is prefixed with a "+" or a "-", then just those corresponding bits will be set or cleared (respectively) without affecting the other bits in the mask.
I put together this interface to make it easier to debug the driver, independent of an application like xawtv. The possibilities here are obvious. For example, it should be possible open the /dev/ entry into mplayer and then completely control everything else with this sysfs interface while mplayer is running. One could write a control program in Perl with this interface...
Please be aware that with this interface one has complete run of all the driver's controls. There are certainly combinations of settings which, uh, won't work very well. But as I said, I put this here to make it easier to debug the driver. It was either this or invent a pile of new ioctl()'s and write a test program to operate those settings (the ioctl() approach I believe is what ivtv does).
In the driver source tree, there is a file doc/controls.txt which annotates each of the controls with information about what it is expected to do, what effects may or may not happen, and whether certain settings work or not. I put this together after a day of experimentation with the device. Others may find it handy so I've made the results available..
I have several interesting thoughts towards also making a DVB interface concurrently available. This device after all deals in mpeg2 streams not video frames, so from a purist standpoint it's probably closer to DVB in behavior than v4l. The internal structure of the driver now should make this sort of stunt possible, but I need to do more research before I can determine if it is truly feasible. In the mean time, there's no DVB interface.
The IR receiver within the device is an I2C part that is understood by the lircd software package (0.7 or later). Previously Aurelien's driver hardcoded something here which made the IR receiver into another source for /dev/input, but I had stability problems with this and just decided to rip it out in favor of letting more stable external software handle this function.
You should do here precisely the same solution as that needed for ivtv. In other words, grab lircd 0.7 or later, build it, modprobe the I2C driver into the kernel and when configured with the appropriate lircd.conf (one is included with the pvrusb2 driver), it should "just work". The I2C driver should discover the internal I2C bus made available by the pvrusb2 driver, probe that bus, and attach itself when it finds the IR receiver chip it will be looking for.
I have received multiple reports that this in fact does work.
Note that if you are a Debian user, there is an lirc-modules-source package which you can in theory just install and build against your kernel tree. I and others have found that package to be broken. It won't compile cleanly. (See here for the current situation with this package.) You're probably better off just using the vanilla version from the lirc web site.
There is a frequency table implemented inside this driver. It is not available for v4l, but it can be used with the sysfs control interface. You must program it first before using it, but once programmed it becomes possible to change the channel just by, well, writing the new channel number to the driver. The table size is currently limited to channel numbers 1 through 500 (far in excess of anything anyone should need), and the channel ids must be integers not something cute like station call letters.
Note: You do not need to program this frequency table or otherwise even touch it when using this driver with any v4l application. This table is not even visible in the v4l API; it is only present here to make it easier to debug the driver using sysfs.
The frequency table must be programmed a slot at a time. You do this by first selecting the slot's id (a.k.a. the channel number) into the freq_table_channel variable through sysfs. Once selected, you can read / write the frequency (in Hz) for that slot using the freq_table_value variable through sysfs. Repeat this process for all channels to be programmed. Yes, this is just begging for a shell script to do the dirty work. Thanks to Per Christian Henden, one example of such a script exists now in the utils subdirectory (see pvrusb2-utils.html for more information about this).
Once you've programmed the desired slots in the table, just "change the channel" by writing the desired channel number to the channel variable through sysfs. That's it.
The frequency can still be set as before by writing the actual frequency to the frequency variable. If that is done, then the channel will be implicitly set to zero, which means "none". Thus the channel and frequency variables at all times stay consistent with each other and there's no loss of flexible or any implied confusion.
The frequency variable can of course be read back at any time to see what the actual frequency is, regardless of whether it was set directly or implied by a channel setting. And of course the channel variable can be read back at any time to find out what the current channel is or if it is not being used due to the frequency being directly set (in which case the value read back will be zero).
Why do this? Well it was dirt-cheap easy to implement, and it does help with debugging, though in a minor way. Besides it's cool to do. OK, OK. Enough playing and back to the real rework...
Aurelien's version of this driver implemented all chip-level functionality directly inside the pvrusb2 source code. All of these chips are accessed via an internal I2C bus, and it so happens that the Linux kernel has a fairly decent I2C abstraction layer in it. In addition, there already exist more complete and better-tested chip level drivers out there that use this I2C abstraction layer. So the first thing I did was to implement a proper I2C adapter driver within pvrusb2, and then (similar to the IR remote description earlier) I proceeded to rip out the redundant code in favor of using the better external implementations. The external chip-level drivers currently being used are:
This driver snapshot includes copies of all of the above listed chip-level drivers except tda9887, however they are just copies from version 0.4.0 of the ivtv driver (except tda9887 which is always available as part of the V4L core). They are merely included here for convenience. It is my intention to leave the corresponding source files unchanged, in order to better track the upstream source.
All of the above chip-level driver (except saa7115.ko until 2.6.15) are also available as part of the core v4l distribution. They are known to work, but old v4l implementations of tveeprom.ko do not always handle type 58 tuners (look back to the Installation section of these notes for more information on this).
Even though the PVR USB2 is a USB device while everything else driven by ivtv is a PCI device, there really is more than a passing resemblance among them. As such it's no coincidence that most of the listed chip-level drivers above also happen to come from ivtv. (In fact, the same cx23416 mpeg2 encoder - which is the heart of ivtv - is also used in this device.) If you have / need to also use ivtv, it should be possible for this driver to coexist with it. You can discard all the chip-level drivers listed earlier from this package in favor of the versions from ivtv (which likely will have additional fixes).
The X-box has an internal I2C bus, and the code that was hacked together for it makes the assumption that it is the only I2C bus that can possibly exist on an xbox. That assumption becomes false when a PVR USB2 device is introduced, unfortunately. The problem here is that the I2C driver code for the xbox tries to attach to the PVR USB2's I2C bus, causing dangling pointers in the xbox driver code and chaos ensues. If you have an xbox, I have a patch for the xbox I2C driver code that makes it play nicer (it's still a horrible hack though). I will try to get that code submitted back to the xbox author(s). In the mean time, contact me for the patch.
The v4l implementation is still undergoing development. There's a risk that a later snapshot may cause this driver to break. Indeed, it is already known that you need at least 2.6.10-3 of the v4l kernel patch for the driver to even work. There isn't anything really that can be done here yet about this problem, except to warn the reader to watch out for trouble.
I've written up a short list of common mis-steps and solutions encountered by people trying the driver. If you have any suggestions for things to add here, please let me know. Hopefully you can find your situation described here: pvrusb2-faq.html
The driver package now includes a few utilities related to operation of this device - including a new means for extracting driver firmware. There is a separate page describing all of this: pvrusb2-utils.html
This is a fairly immature driver, however it seems to have a decent history of stability now. There are currently no known issues of the "kernel oops" category. Hotplugging works pretty well, and there are people who have logged a lot of hours using this driver and the device. There are however missing features. These include:
Change history can be found here: pvrusb2-history.html
Note: If you are viewing a local sandbox copy of this page, the file pvrusb2-history.html will not exist. This file is generated from change_history.txt which you can find in the same directory.
Feel free to e-mail me (address at the top of this page) if you have any questions or just want to say hello...
Mike Isely