1577a7ad3SMauro Carvalho Chehab.. SPDX-License-Identifier: GPL-2.0 2577a7ad3SMauro Carvalho Chehab 3577a7ad3SMauro Carvalho ChehabThe pvrusb2 driver 4577a7ad3SMauro Carvalho Chehab================== 5577a7ad3SMauro Carvalho Chehab 6577a7ad3SMauro Carvalho ChehabAuthor: Mike Isely <isely@pobox.com> 7577a7ad3SMauro Carvalho Chehab 8577a7ad3SMauro Carvalho ChehabBackground 9577a7ad3SMauro Carvalho Chehab---------- 10577a7ad3SMauro Carvalho Chehab 11577a7ad3SMauro Carvalho ChehabThis driver is intended for the "Hauppauge WinTV PVR USB 2.0", which 12577a7ad3SMauro Carvalho Chehabis a USB 2.0 hosted TV Tuner. This driver is a work in progress. 13577a7ad3SMauro Carvalho ChehabIts history started with the reverse-engineering effort by Björn 14577a7ad3SMauro Carvalho ChehabDanielsson <pvrusb2@dax.nu> whose web page can be found here: 15577a7ad3SMauro Carvalho Chehabhttp://pvrusb2.dax.nu/ 16577a7ad3SMauro Carvalho Chehab 17577a7ad3SMauro Carvalho ChehabFrom there Aurelien Alleaume <slts@free.fr> began an effort to 18577a7ad3SMauro Carvalho Chehabcreate a video4linux compatible driver. I began with Aurelien's 19577a7ad3SMauro Carvalho Chehablast known snapshot and evolved the driver to the state it is in 20577a7ad3SMauro Carvalho Chehabhere. 21577a7ad3SMauro Carvalho Chehab 22577a7ad3SMauro Carvalho ChehabMore information on this driver can be found at: 23*467bd18dSAlexander A. Klimovhttps://www.isely.net/pvrusb2.html 24577a7ad3SMauro Carvalho Chehab 25577a7ad3SMauro Carvalho Chehab 26577a7ad3SMauro Carvalho ChehabThis driver has a strong separation of layers. They are very 27577a7ad3SMauro Carvalho Chehabroughly: 28577a7ad3SMauro Carvalho Chehab 29577a7ad3SMauro Carvalho Chehab1. Low level wire-protocol implementation with the device. 30577a7ad3SMauro Carvalho Chehab 31577a7ad3SMauro Carvalho Chehab2. I2C adaptor implementation and corresponding I2C client drivers 32577a7ad3SMauro Carvalho Chehab implemented elsewhere in V4L. 33577a7ad3SMauro Carvalho Chehab 34577a7ad3SMauro Carvalho Chehab3. High level hardware driver implementation which coordinates all 35577a7ad3SMauro Carvalho Chehab activities that ensure correct operation of the device. 36577a7ad3SMauro Carvalho Chehab 37577a7ad3SMauro Carvalho Chehab4. A "context" layer which manages instancing of driver, setup, 38577a7ad3SMauro Carvalho Chehab tear-down, arbitration, and interaction with high level 39577a7ad3SMauro Carvalho Chehab interfaces appropriately as devices are hotplugged in the 40577a7ad3SMauro Carvalho Chehab system. 41577a7ad3SMauro Carvalho Chehab 42577a7ad3SMauro Carvalho Chehab5. High level interfaces which glue the driver to various published 43577a7ad3SMauro Carvalho Chehab Linux APIs (V4L, sysfs, maybe DVB in the future). 44577a7ad3SMauro Carvalho Chehab 45577a7ad3SMauro Carvalho ChehabThe most important shearing layer is between the top 2 layers. A 46577a7ad3SMauro Carvalho Chehablot of work went into the driver to ensure that any kind of 47577a7ad3SMauro Carvalho Chehabconceivable API can be laid on top of the core driver. (Yes, the 48577a7ad3SMauro Carvalho Chehabdriver internally leverages V4L to do its work but that really has 49577a7ad3SMauro Carvalho Chehabnothing to do with the API published by the driver to the outside 50577a7ad3SMauro Carvalho Chehabworld.) The architecture allows for different APIs to 51577a7ad3SMauro Carvalho Chehabsimultaneously access the driver. I have a strong sense of fairness 52577a7ad3SMauro Carvalho Chehababout APIs and also feel that it is a good design principle to keep 53577a7ad3SMauro Carvalho Chehabimplementation and interface isolated from each other. Thus while 54577a7ad3SMauro Carvalho Chehabright now the V4L high level interface is the most complete, the 55577a7ad3SMauro Carvalho Chehabsysfs high level interface will work equally well for similar 56577a7ad3SMauro Carvalho Chehabfunctions, and there's no reason I see right now why it shouldn't be 57577a7ad3SMauro Carvalho Chehabpossible to produce a DVB high level interface that can sit right 58577a7ad3SMauro Carvalho Chehabalongside V4L. 59577a7ad3SMauro Carvalho Chehab 60577a7ad3SMauro Carvalho ChehabBuilding 61577a7ad3SMauro Carvalho Chehab-------- 62577a7ad3SMauro Carvalho Chehab 63577a7ad3SMauro Carvalho ChehabTo build these modules essentially amounts to just running "Make", 64577a7ad3SMauro Carvalho Chehabbut you need the kernel source tree nearby and you will likely also 65577a7ad3SMauro Carvalho Chehabwant to set a few controlling environment variables first in order 66577a7ad3SMauro Carvalho Chehabto link things up with that source tree. Please see the Makefile 67577a7ad3SMauro Carvalho Chehabhere for comments that explain how to do that. 68577a7ad3SMauro Carvalho Chehab 69577a7ad3SMauro Carvalho ChehabSource file list / functional overview 70577a7ad3SMauro Carvalho Chehab-------------------------------------- 71577a7ad3SMauro Carvalho Chehab 72577a7ad3SMauro Carvalho Chehab(Note: The term "module" used below generally refers to loosely 73577a7ad3SMauro Carvalho Chehabdefined functional units within the pvrusb2 driver and bears no 74577a7ad3SMauro Carvalho Chehabrelation to the Linux kernel's concept of a loadable module.) 75577a7ad3SMauro Carvalho Chehab 76577a7ad3SMauro Carvalho Chehabpvrusb2-audio.[ch] - This is glue logic that resides between this 77577a7ad3SMauro Carvalho Chehab driver and the msp3400.ko I2C client driver (which is found 78577a7ad3SMauro Carvalho Chehab elsewhere in V4L). 79577a7ad3SMauro Carvalho Chehab 80577a7ad3SMauro Carvalho Chehabpvrusb2-context.[ch] - This module implements the context for an 81577a7ad3SMauro Carvalho Chehab instance of the driver. Everything else eventually ties back to 82577a7ad3SMauro Carvalho Chehab or is otherwise instanced within the data structures implemented 83577a7ad3SMauro Carvalho Chehab here. Hotplugging is ultimately coordinated here. All high level 84577a7ad3SMauro Carvalho Chehab interfaces tie into the driver through this module. This module 85577a7ad3SMauro Carvalho Chehab helps arbitrate each interface's access to the actual driver core, 86577a7ad3SMauro Carvalho Chehab and is designed to allow concurrent access through multiple 87577a7ad3SMauro Carvalho Chehab instances of multiple interfaces (thus you can for example change 88577a7ad3SMauro Carvalho Chehab the tuner's frequency through sysfs while simultaneously streaming 89577a7ad3SMauro Carvalho Chehab video through V4L out to an instance of mplayer). 90577a7ad3SMauro Carvalho Chehab 91577a7ad3SMauro Carvalho Chehabpvrusb2-debug.h - This header defines a printk() wrapper and a mask 92577a7ad3SMauro Carvalho Chehab of debugging bit definitions for the various kinds of debug 93577a7ad3SMauro Carvalho Chehab messages that can be enabled within the driver. 94577a7ad3SMauro Carvalho Chehab 95577a7ad3SMauro Carvalho Chehabpvrusb2-debugifc.[ch] - This module implements a crude command line 96577a7ad3SMauro Carvalho Chehab oriented debug interface into the driver. Aside from being part 97577a7ad3SMauro Carvalho Chehab of the process for implementing manual firmware extraction (see 98577a7ad3SMauro Carvalho Chehab the pvrusb2 web site mentioned earlier), probably I'm the only one 99577a7ad3SMauro Carvalho Chehab who has ever used this. It is mainly a debugging aid. 100577a7ad3SMauro Carvalho Chehab 101577a7ad3SMauro Carvalho Chehabpvrusb2-eeprom.[ch] - This is glue logic that resides between this 102577a7ad3SMauro Carvalho Chehab driver the tveeprom.ko module, which is itself implemented 103577a7ad3SMauro Carvalho Chehab elsewhere in V4L. 104577a7ad3SMauro Carvalho Chehab 105577a7ad3SMauro Carvalho Chehabpvrusb2-encoder.[ch] - This module implements all protocol needed to 106577a7ad3SMauro Carvalho Chehab interact with the Conexant mpeg2 encoder chip within the pvrusb2 107577a7ad3SMauro Carvalho Chehab device. It is a crude echo of corresponding logic in ivtv, 108577a7ad3SMauro Carvalho Chehab however the design goals (strict isolation) and physical layer 109577a7ad3SMauro Carvalho Chehab (proxy through USB instead of PCI) are enough different that this 110577a7ad3SMauro Carvalho Chehab implementation had to be completely different. 111577a7ad3SMauro Carvalho Chehab 112577a7ad3SMauro Carvalho Chehabpvrusb2-hdw-internal.h - This header defines the core data structure 113577a7ad3SMauro Carvalho Chehab in the driver used to track ALL internal state related to control 114577a7ad3SMauro Carvalho Chehab of the hardware. Nobody outside of the core hardware-handling 115577a7ad3SMauro Carvalho Chehab modules should have any business using this header. All external 116577a7ad3SMauro Carvalho Chehab access to the driver should be through one of the high level 117577a7ad3SMauro Carvalho Chehab interfaces (e.g. V4L, sysfs, etc), and in fact even those high 118577a7ad3SMauro Carvalho Chehab level interfaces are restricted to the API defined in 119577a7ad3SMauro Carvalho Chehab pvrusb2-hdw.h and NOT this header. 120577a7ad3SMauro Carvalho Chehab 121577a7ad3SMauro Carvalho Chehabpvrusb2-hdw.h - This header defines the full internal API for 122577a7ad3SMauro Carvalho Chehab controlling the hardware. High level interfaces (e.g. V4L, sysfs) 123577a7ad3SMauro Carvalho Chehab will work through here. 124577a7ad3SMauro Carvalho Chehab 125577a7ad3SMauro Carvalho Chehabpvrusb2-hdw.c - This module implements all the various bits of logic 126577a7ad3SMauro Carvalho Chehab that handle overall control of a specific pvrusb2 device. 127577a7ad3SMauro Carvalho Chehab (Policy, instantiation, and arbitration of pvrusb2 devices fall 128577a7ad3SMauro Carvalho Chehab within the jurisdiction of pvrusb-context not here). 129577a7ad3SMauro Carvalho Chehab 130577a7ad3SMauro Carvalho Chehabpvrusb2-i2c-chips-\*.c - These modules implement the glue logic to 131577a7ad3SMauro Carvalho Chehab tie together and configure various I2C modules as they attach to 132577a7ad3SMauro Carvalho Chehab the I2C bus. There are two versions of this file. The "v4l2" 133577a7ad3SMauro Carvalho Chehab version is intended to be used in-tree alongside V4L, where we 134577a7ad3SMauro Carvalho Chehab implement just the logic that makes sense for a pure V4L 135577a7ad3SMauro Carvalho Chehab environment. The "all" version is intended for use outside of 136577a7ad3SMauro Carvalho Chehab V4L, where we might encounter other possibly "challenging" modules 137577a7ad3SMauro Carvalho Chehab from ivtv or older kernel snapshots (or even the support modules 138577a7ad3SMauro Carvalho Chehab in the standalone snapshot). 139577a7ad3SMauro Carvalho Chehab 140577a7ad3SMauro Carvalho Chehabpvrusb2-i2c-cmd-v4l1.[ch] - This module implements generic V4L1 141577a7ad3SMauro Carvalho Chehab compatible commands to the I2C modules. It is here where state 142577a7ad3SMauro Carvalho Chehab changes inside the pvrusb2 driver are translated into V4L1 143577a7ad3SMauro Carvalho Chehab commands that are in turn send to the various I2C modules. 144577a7ad3SMauro Carvalho Chehab 145577a7ad3SMauro Carvalho Chehabpvrusb2-i2c-cmd-v4l2.[ch] - This module implements generic V4L2 146577a7ad3SMauro Carvalho Chehab compatible commands to the I2C modules. It is here where state 147577a7ad3SMauro Carvalho Chehab changes inside the pvrusb2 driver are translated into V4L2 148577a7ad3SMauro Carvalho Chehab commands that are in turn send to the various I2C modules. 149577a7ad3SMauro Carvalho Chehab 150577a7ad3SMauro Carvalho Chehabpvrusb2-i2c-core.[ch] - This module provides an implementation of a 151577a7ad3SMauro Carvalho Chehab kernel-friendly I2C adaptor driver, through which other external 152577a7ad3SMauro Carvalho Chehab I2C client drivers (e.g. msp3400, tuner, lirc) may connect and 153577a7ad3SMauro Carvalho Chehab operate corresponding chips within the pvrusb2 device. It is 154577a7ad3SMauro Carvalho Chehab through here that other V4L modules can reach into this driver to 155577a7ad3SMauro Carvalho Chehab operate specific pieces (and those modules are in turn driven by 156577a7ad3SMauro Carvalho Chehab glue logic which is coordinated by pvrusb2-hdw, doled out by 157577a7ad3SMauro Carvalho Chehab pvrusb2-context, and then ultimately made available to users 158577a7ad3SMauro Carvalho Chehab through one of the high level interfaces). 159577a7ad3SMauro Carvalho Chehab 160577a7ad3SMauro Carvalho Chehabpvrusb2-io.[ch] - This module implements a very low level ring of 161577a7ad3SMauro Carvalho Chehab transfer buffers, required in order to stream data from the 162577a7ad3SMauro Carvalho Chehab device. This module is *very* low level. It only operates the 163577a7ad3SMauro Carvalho Chehab buffers and makes no attempt to define any policy or mechanism for 164577a7ad3SMauro Carvalho Chehab how such buffers might be used. 165577a7ad3SMauro Carvalho Chehab 166577a7ad3SMauro Carvalho Chehabpvrusb2-ioread.[ch] - This module layers on top of pvrusb2-io.[ch] 167577a7ad3SMauro Carvalho Chehab to provide a streaming API usable by a read() system call style of 168577a7ad3SMauro Carvalho Chehab I/O. Right now this is the only layer on top of pvrusb2-io.[ch], 169577a7ad3SMauro Carvalho Chehab however the underlying architecture here was intended to allow for 170577a7ad3SMauro Carvalho Chehab other styles of I/O to be implemented with additional modules, like 171577a7ad3SMauro Carvalho Chehab mmap()'ed buffers or something even more exotic. 172577a7ad3SMauro Carvalho Chehab 173577a7ad3SMauro Carvalho Chehabpvrusb2-main.c - This is the top level of the driver. Module level 174577a7ad3SMauro Carvalho Chehab and USB core entry points are here. This is our "main". 175577a7ad3SMauro Carvalho Chehab 176577a7ad3SMauro Carvalho Chehabpvrusb2-sysfs.[ch] - This is the high level interface which ties the 177577a7ad3SMauro Carvalho Chehab pvrusb2 driver into sysfs. Through this interface you can do 178577a7ad3SMauro Carvalho Chehab everything with the driver except actually stream data. 179577a7ad3SMauro Carvalho Chehab 180577a7ad3SMauro Carvalho Chehabpvrusb2-tuner.[ch] - This is glue logic that resides between this 181577a7ad3SMauro Carvalho Chehab driver and the tuner.ko I2C client driver (which is found 182577a7ad3SMauro Carvalho Chehab elsewhere in V4L). 183577a7ad3SMauro Carvalho Chehab 184577a7ad3SMauro Carvalho Chehabpvrusb2-util.h - This header defines some common macros used 185577a7ad3SMauro Carvalho Chehab throughout the driver. These macros are not really specific to 186577a7ad3SMauro Carvalho Chehab the driver, but they had to go somewhere. 187577a7ad3SMauro Carvalho Chehab 188577a7ad3SMauro Carvalho Chehabpvrusb2-v4l2.[ch] - This is the high level interface which ties the 189577a7ad3SMauro Carvalho Chehab pvrusb2 driver into video4linux. It is through here that V4L 190577a7ad3SMauro Carvalho Chehab applications can open and operate the driver in the usual V4L 191577a7ad3SMauro Carvalho Chehab ways. Note that **ALL** V4L functionality is published only 192577a7ad3SMauro Carvalho Chehab through here and nowhere else. 193577a7ad3SMauro Carvalho Chehab 194577a7ad3SMauro Carvalho Chehabpvrusb2-video-\*.[ch] - This is glue logic that resides between this 195577a7ad3SMauro Carvalho Chehab driver and the saa711x.ko I2C client driver (which is found 196577a7ad3SMauro Carvalho Chehab elsewhere in V4L). Note that saa711x.ko used to be known as 197577a7ad3SMauro Carvalho Chehab saa7115.ko in ivtv. There are two versions of this; one is 198577a7ad3SMauro Carvalho Chehab selected depending on the particular saa711[5x].ko that is found. 199577a7ad3SMauro Carvalho Chehab 200577a7ad3SMauro Carvalho Chehabpvrusb2.h - This header contains compile time tunable parameters 201577a7ad3SMauro Carvalho Chehab (and at the moment the driver has very little that needs to be 202577a7ad3SMauro Carvalho Chehab tuned). 203