162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ciThe pvrusb2 driver 462306a36Sopenharmony_ci================== 562306a36Sopenharmony_ci 662306a36Sopenharmony_ciAuthor: Mike Isely <isely@pobox.com> 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciBackground 962306a36Sopenharmony_ci---------- 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciThis driver is intended for the "Hauppauge WinTV PVR USB 2.0", which 1262306a36Sopenharmony_ciis a USB 2.0 hosted TV Tuner. This driver is a work in progress. 1362306a36Sopenharmony_ciIts history started with the reverse-engineering effort by Björn 1462306a36Sopenharmony_ciDanielsson <pvrusb2@dax.nu> whose web page can be found here: 1562306a36Sopenharmony_cihttp://pvrusb2.dax.nu/ 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ciFrom there Aurelien Alleaume <slts@free.fr> began an effort to 1862306a36Sopenharmony_cicreate a video4linux compatible driver. I began with Aurelien's 1962306a36Sopenharmony_cilast known snapshot and evolved the driver to the state it is in 2062306a36Sopenharmony_cihere. 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciMore information on this driver can be found at: 2362306a36Sopenharmony_cihttps://www.isely.net/pvrusb2.html 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciThis driver has a strong separation of layers. They are very 2762306a36Sopenharmony_ciroughly: 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci1. Low level wire-protocol implementation with the device. 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci2. I2C adaptor implementation and corresponding I2C client drivers 3262306a36Sopenharmony_ci implemented elsewhere in V4L. 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci3. High level hardware driver implementation which coordinates all 3562306a36Sopenharmony_ci activities that ensure correct operation of the device. 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci4. A "context" layer which manages instancing of driver, setup, 3862306a36Sopenharmony_ci tear-down, arbitration, and interaction with high level 3962306a36Sopenharmony_ci interfaces appropriately as devices are hotplugged in the 4062306a36Sopenharmony_ci system. 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci5. High level interfaces which glue the driver to various published 4362306a36Sopenharmony_ci Linux APIs (V4L, sysfs, maybe DVB in the future). 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ciThe most important shearing layer is between the top 2 layers. A 4662306a36Sopenharmony_cilot of work went into the driver to ensure that any kind of 4762306a36Sopenharmony_ciconceivable API can be laid on top of the core driver. (Yes, the 4862306a36Sopenharmony_cidriver internally leverages V4L to do its work but that really has 4962306a36Sopenharmony_cinothing to do with the API published by the driver to the outside 5062306a36Sopenharmony_ciworld.) The architecture allows for different APIs to 5162306a36Sopenharmony_cisimultaneously access the driver. I have a strong sense of fairness 5262306a36Sopenharmony_ciabout APIs and also feel that it is a good design principle to keep 5362306a36Sopenharmony_ciimplementation and interface isolated from each other. Thus while 5462306a36Sopenharmony_ciright now the V4L high level interface is the most complete, the 5562306a36Sopenharmony_cisysfs high level interface will work equally well for similar 5662306a36Sopenharmony_cifunctions, and there's no reason I see right now why it shouldn't be 5762306a36Sopenharmony_cipossible to produce a DVB high level interface that can sit right 5862306a36Sopenharmony_cialongside V4L. 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ciBuilding 6162306a36Sopenharmony_ci-------- 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ciTo build these modules essentially amounts to just running "Make", 6462306a36Sopenharmony_cibut you need the kernel source tree nearby and you will likely also 6562306a36Sopenharmony_ciwant to set a few controlling environment variables first in order 6662306a36Sopenharmony_cito link things up with that source tree. Please see the Makefile 6762306a36Sopenharmony_cihere for comments that explain how to do that. 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ciSource file list / functional overview 7062306a36Sopenharmony_ci-------------------------------------- 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci(Note: The term "module" used below generally refers to loosely 7362306a36Sopenharmony_cidefined functional units within the pvrusb2 driver and bears no 7462306a36Sopenharmony_cirelation to the Linux kernel's concept of a loadable module.) 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_cipvrusb2-audio.[ch] - This is glue logic that resides between this 7762306a36Sopenharmony_ci driver and the msp3400.ko I2C client driver (which is found 7862306a36Sopenharmony_ci elsewhere in V4L). 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_cipvrusb2-context.[ch] - This module implements the context for an 8162306a36Sopenharmony_ci instance of the driver. Everything else eventually ties back to 8262306a36Sopenharmony_ci or is otherwise instanced within the data structures implemented 8362306a36Sopenharmony_ci here. Hotplugging is ultimately coordinated here. All high level 8462306a36Sopenharmony_ci interfaces tie into the driver through this module. This module 8562306a36Sopenharmony_ci helps arbitrate each interface's access to the actual driver core, 8662306a36Sopenharmony_ci and is designed to allow concurrent access through multiple 8762306a36Sopenharmony_ci instances of multiple interfaces (thus you can for example change 8862306a36Sopenharmony_ci the tuner's frequency through sysfs while simultaneously streaming 8962306a36Sopenharmony_ci video through V4L out to an instance of mplayer). 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_cipvrusb2-debug.h - This header defines a printk() wrapper and a mask 9262306a36Sopenharmony_ci of debugging bit definitions for the various kinds of debug 9362306a36Sopenharmony_ci messages that can be enabled within the driver. 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_cipvrusb2-debugifc.[ch] - This module implements a crude command line 9662306a36Sopenharmony_ci oriented debug interface into the driver. Aside from being part 9762306a36Sopenharmony_ci of the process for implementing manual firmware extraction (see 9862306a36Sopenharmony_ci the pvrusb2 web site mentioned earlier), probably I'm the only one 9962306a36Sopenharmony_ci who has ever used this. It is mainly a debugging aid. 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_cipvrusb2-eeprom.[ch] - This is glue logic that resides between this 10262306a36Sopenharmony_ci driver the tveeprom.ko module, which is itself implemented 10362306a36Sopenharmony_ci elsewhere in V4L. 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_cipvrusb2-encoder.[ch] - This module implements all protocol needed to 10662306a36Sopenharmony_ci interact with the Conexant mpeg2 encoder chip within the pvrusb2 10762306a36Sopenharmony_ci device. It is a crude echo of corresponding logic in ivtv, 10862306a36Sopenharmony_ci however the design goals (strict isolation) and physical layer 10962306a36Sopenharmony_ci (proxy through USB instead of PCI) are enough different that this 11062306a36Sopenharmony_ci implementation had to be completely different. 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_cipvrusb2-hdw-internal.h - This header defines the core data structure 11362306a36Sopenharmony_ci in the driver used to track ALL internal state related to control 11462306a36Sopenharmony_ci of the hardware. Nobody outside of the core hardware-handling 11562306a36Sopenharmony_ci modules should have any business using this header. All external 11662306a36Sopenharmony_ci access to the driver should be through one of the high level 11762306a36Sopenharmony_ci interfaces (e.g. V4L, sysfs, etc), and in fact even those high 11862306a36Sopenharmony_ci level interfaces are restricted to the API defined in 11962306a36Sopenharmony_ci pvrusb2-hdw.h and NOT this header. 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_cipvrusb2-hdw.h - This header defines the full internal API for 12262306a36Sopenharmony_ci controlling the hardware. High level interfaces (e.g. V4L, sysfs) 12362306a36Sopenharmony_ci will work through here. 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_cipvrusb2-hdw.c - This module implements all the various bits of logic 12662306a36Sopenharmony_ci that handle overall control of a specific pvrusb2 device. 12762306a36Sopenharmony_ci (Policy, instantiation, and arbitration of pvrusb2 devices fall 12862306a36Sopenharmony_ci within the jurisdiction of pvrusb-context not here). 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_cipvrusb2-i2c-chips-\*.c - These modules implement the glue logic to 13162306a36Sopenharmony_ci tie together and configure various I2C modules as they attach to 13262306a36Sopenharmony_ci the I2C bus. There are two versions of this file. The "v4l2" 13362306a36Sopenharmony_ci version is intended to be used in-tree alongside V4L, where we 13462306a36Sopenharmony_ci implement just the logic that makes sense for a pure V4L 13562306a36Sopenharmony_ci environment. The "all" version is intended for use outside of 13662306a36Sopenharmony_ci V4L, where we might encounter other possibly "challenging" modules 13762306a36Sopenharmony_ci from ivtv or older kernel snapshots (or even the support modules 13862306a36Sopenharmony_ci in the standalone snapshot). 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_cipvrusb2-i2c-cmd-v4l1.[ch] - This module implements generic V4L1 14162306a36Sopenharmony_ci compatible commands to the I2C modules. It is here where state 14262306a36Sopenharmony_ci changes inside the pvrusb2 driver are translated into V4L1 14362306a36Sopenharmony_ci commands that are in turn send to the various I2C modules. 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_cipvrusb2-i2c-cmd-v4l2.[ch] - This module implements generic V4L2 14662306a36Sopenharmony_ci compatible commands to the I2C modules. It is here where state 14762306a36Sopenharmony_ci changes inside the pvrusb2 driver are translated into V4L2 14862306a36Sopenharmony_ci commands that are in turn send to the various I2C modules. 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_cipvrusb2-i2c-core.[ch] - This module provides an implementation of a 15162306a36Sopenharmony_ci kernel-friendly I2C adaptor driver, through which other external 15262306a36Sopenharmony_ci I2C client drivers (e.g. msp3400, tuner, lirc) may connect and 15362306a36Sopenharmony_ci operate corresponding chips within the pvrusb2 device. It is 15462306a36Sopenharmony_ci through here that other V4L modules can reach into this driver to 15562306a36Sopenharmony_ci operate specific pieces (and those modules are in turn driven by 15662306a36Sopenharmony_ci glue logic which is coordinated by pvrusb2-hdw, doled out by 15762306a36Sopenharmony_ci pvrusb2-context, and then ultimately made available to users 15862306a36Sopenharmony_ci through one of the high level interfaces). 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_cipvrusb2-io.[ch] - This module implements a very low level ring of 16162306a36Sopenharmony_ci transfer buffers, required in order to stream data from the 16262306a36Sopenharmony_ci device. This module is *very* low level. It only operates the 16362306a36Sopenharmony_ci buffers and makes no attempt to define any policy or mechanism for 16462306a36Sopenharmony_ci how such buffers might be used. 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_cipvrusb2-ioread.[ch] - This module layers on top of pvrusb2-io.[ch] 16762306a36Sopenharmony_ci to provide a streaming API usable by a read() system call style of 16862306a36Sopenharmony_ci I/O. Right now this is the only layer on top of pvrusb2-io.[ch], 16962306a36Sopenharmony_ci however the underlying architecture here was intended to allow for 17062306a36Sopenharmony_ci other styles of I/O to be implemented with additional modules, like 17162306a36Sopenharmony_ci mmap()'ed buffers or something even more exotic. 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_cipvrusb2-main.c - This is the top level of the driver. Module level 17462306a36Sopenharmony_ci and USB core entry points are here. This is our "main". 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_cipvrusb2-sysfs.[ch] - This is the high level interface which ties the 17762306a36Sopenharmony_ci pvrusb2 driver into sysfs. Through this interface you can do 17862306a36Sopenharmony_ci everything with the driver except actually stream data. 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_cipvrusb2-tuner.[ch] - This is glue logic that resides between this 18162306a36Sopenharmony_ci driver and the tuner.ko I2C client driver (which is found 18262306a36Sopenharmony_ci elsewhere in V4L). 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_cipvrusb2-util.h - This header defines some common macros used 18562306a36Sopenharmony_ci throughout the driver. These macros are not really specific to 18662306a36Sopenharmony_ci the driver, but they had to go somewhere. 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_cipvrusb2-v4l2.[ch] - This is the high level interface which ties the 18962306a36Sopenharmony_ci pvrusb2 driver into video4linux. It is through here that V4L 19062306a36Sopenharmony_ci applications can open and operate the driver in the usual V4L 19162306a36Sopenharmony_ci ways. Note that **ALL** V4L functionality is published only 19262306a36Sopenharmony_ci through here and nowhere else. 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_cipvrusb2-video-\*.[ch] - This is glue logic that resides between this 19562306a36Sopenharmony_ci driver and the saa711x.ko I2C client driver (which is found 19662306a36Sopenharmony_ci elsewhere in V4L). Note that saa711x.ko used to be known as 19762306a36Sopenharmony_ci saa7115.ko in ivtv. There are two versions of this; one is 19862306a36Sopenharmony_ci selected depending on the particular saa711[5x].ko that is found. 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_cipvrusb2.h - This header contains compile time tunable parameters 20162306a36Sopenharmony_ci (and at the moment the driver has very little that needs to be 20262306a36Sopenharmony_ci tuned). 203