xref: /OK3568_Linux_fs/kernel/Documentation/driver-api/media/drivers/pvrusb2.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593SmuzhiyunThe pvrusb2 driver
4*4882a593Smuzhiyun==================
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunAuthor: Mike Isely <isely@pobox.com>
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunBackground
9*4882a593Smuzhiyun----------
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunThis driver is intended for the "Hauppauge WinTV PVR USB 2.0", which
12*4882a593Smuzhiyunis a USB 2.0 hosted TV Tuner.  This driver is a work in progress.
13*4882a593SmuzhiyunIts history started with the reverse-engineering effort by Björn
14*4882a593SmuzhiyunDanielsson <pvrusb2@dax.nu> whose web page can be found here:
15*4882a593Smuzhiyunhttp://pvrusb2.dax.nu/
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunFrom there Aurelien Alleaume <slts@free.fr> began an effort to
18*4882a593Smuzhiyuncreate a video4linux compatible driver.  I began with Aurelien's
19*4882a593Smuzhiyunlast known snapshot and evolved the driver to the state it is in
20*4882a593Smuzhiyunhere.
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunMore information on this driver can be found at:
23*4882a593Smuzhiyunhttps://www.isely.net/pvrusb2.html
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunThis driver has a strong separation of layers.  They are very
27*4882a593Smuzhiyunroughly:
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun1. Low level wire-protocol implementation with the device.
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun2. I2C adaptor implementation and corresponding I2C client drivers
32*4882a593Smuzhiyun   implemented elsewhere in V4L.
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun3. High level hardware driver implementation which coordinates all
35*4882a593Smuzhiyun   activities that ensure correct operation of the device.
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun4. A "context" layer which manages instancing of driver, setup,
38*4882a593Smuzhiyun   tear-down, arbitration, and interaction with high level
39*4882a593Smuzhiyun   interfaces appropriately as devices are hotplugged in the
40*4882a593Smuzhiyun   system.
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun5. High level interfaces which glue the driver to various published
43*4882a593Smuzhiyun   Linux APIs (V4L, sysfs, maybe DVB in the future).
44*4882a593Smuzhiyun
45*4882a593SmuzhiyunThe most important shearing layer is between the top 2 layers.  A
46*4882a593Smuzhiyunlot of work went into the driver to ensure that any kind of
47*4882a593Smuzhiyunconceivable API can be laid on top of the core driver.  (Yes, the
48*4882a593Smuzhiyundriver internally leverages V4L to do its work but that really has
49*4882a593Smuzhiyunnothing to do with the API published by the driver to the outside
50*4882a593Smuzhiyunworld.)  The architecture allows for different APIs to
51*4882a593Smuzhiyunsimultaneously access the driver.  I have a strong sense of fairness
52*4882a593Smuzhiyunabout APIs and also feel that it is a good design principle to keep
53*4882a593Smuzhiyunimplementation and interface isolated from each other.  Thus while
54*4882a593Smuzhiyunright now the V4L high level interface is the most complete, the
55*4882a593Smuzhiyunsysfs high level interface will work equally well for similar
56*4882a593Smuzhiyunfunctions, and there's no reason I see right now why it shouldn't be
57*4882a593Smuzhiyunpossible to produce a DVB high level interface that can sit right
58*4882a593Smuzhiyunalongside V4L.
59*4882a593Smuzhiyun
60*4882a593SmuzhiyunBuilding
61*4882a593Smuzhiyun--------
62*4882a593Smuzhiyun
63*4882a593SmuzhiyunTo build these modules essentially amounts to just running "Make",
64*4882a593Smuzhiyunbut you need the kernel source tree nearby and you will likely also
65*4882a593Smuzhiyunwant to set a few controlling environment variables first in order
66*4882a593Smuzhiyunto link things up with that source tree.  Please see the Makefile
67*4882a593Smuzhiyunhere for comments that explain how to do that.
68*4882a593Smuzhiyun
69*4882a593SmuzhiyunSource file list / functional overview
70*4882a593Smuzhiyun--------------------------------------
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun(Note: The term "module" used below generally refers to loosely
73*4882a593Smuzhiyundefined functional units within the pvrusb2 driver and bears no
74*4882a593Smuzhiyunrelation to the Linux kernel's concept of a loadable module.)
75*4882a593Smuzhiyun
76*4882a593Smuzhiyunpvrusb2-audio.[ch] - This is glue logic that resides between this
77*4882a593Smuzhiyun    driver and the msp3400.ko I2C client driver (which is found
78*4882a593Smuzhiyun    elsewhere in V4L).
79*4882a593Smuzhiyun
80*4882a593Smuzhiyunpvrusb2-context.[ch] - This module implements the context for an
81*4882a593Smuzhiyun    instance of the driver.  Everything else eventually ties back to
82*4882a593Smuzhiyun    or is otherwise instanced within the data structures implemented
83*4882a593Smuzhiyun    here.  Hotplugging is ultimately coordinated here.  All high level
84*4882a593Smuzhiyun    interfaces tie into the driver through this module.  This module
85*4882a593Smuzhiyun    helps arbitrate each interface's access to the actual driver core,
86*4882a593Smuzhiyun    and is designed to allow concurrent access through multiple
87*4882a593Smuzhiyun    instances of multiple interfaces (thus you can for example change
88*4882a593Smuzhiyun    the tuner's frequency through sysfs while simultaneously streaming
89*4882a593Smuzhiyun    video through V4L out to an instance of mplayer).
90*4882a593Smuzhiyun
91*4882a593Smuzhiyunpvrusb2-debug.h - This header defines a printk() wrapper and a mask
92*4882a593Smuzhiyun    of debugging bit definitions for the various kinds of debug
93*4882a593Smuzhiyun    messages that can be enabled within the driver.
94*4882a593Smuzhiyun
95*4882a593Smuzhiyunpvrusb2-debugifc.[ch] - This module implements a crude command line
96*4882a593Smuzhiyun    oriented debug interface into the driver.  Aside from being part
97*4882a593Smuzhiyun    of the process for implementing manual firmware extraction (see
98*4882a593Smuzhiyun    the pvrusb2 web site mentioned earlier), probably I'm the only one
99*4882a593Smuzhiyun    who has ever used this.  It is mainly a debugging aid.
100*4882a593Smuzhiyun
101*4882a593Smuzhiyunpvrusb2-eeprom.[ch] - This is glue logic that resides between this
102*4882a593Smuzhiyun    driver the tveeprom.ko module, which is itself implemented
103*4882a593Smuzhiyun    elsewhere in V4L.
104*4882a593Smuzhiyun
105*4882a593Smuzhiyunpvrusb2-encoder.[ch] - This module implements all protocol needed to
106*4882a593Smuzhiyun    interact with the Conexant mpeg2 encoder chip within the pvrusb2
107*4882a593Smuzhiyun    device.  It is a crude echo of corresponding logic in ivtv,
108*4882a593Smuzhiyun    however the design goals (strict isolation) and physical layer
109*4882a593Smuzhiyun    (proxy through USB instead of PCI) are enough different that this
110*4882a593Smuzhiyun    implementation had to be completely different.
111*4882a593Smuzhiyun
112*4882a593Smuzhiyunpvrusb2-hdw-internal.h - This header defines the core data structure
113*4882a593Smuzhiyun    in the driver used to track ALL internal state related to control
114*4882a593Smuzhiyun    of the hardware.  Nobody outside of the core hardware-handling
115*4882a593Smuzhiyun    modules should have any business using this header.  All external
116*4882a593Smuzhiyun    access to the driver should be through one of the high level
117*4882a593Smuzhiyun    interfaces (e.g. V4L, sysfs, etc), and in fact even those high
118*4882a593Smuzhiyun    level interfaces are restricted to the API defined in
119*4882a593Smuzhiyun    pvrusb2-hdw.h and NOT this header.
120*4882a593Smuzhiyun
121*4882a593Smuzhiyunpvrusb2-hdw.h - This header defines the full internal API for
122*4882a593Smuzhiyun    controlling the hardware.  High level interfaces (e.g. V4L, sysfs)
123*4882a593Smuzhiyun    will work through here.
124*4882a593Smuzhiyun
125*4882a593Smuzhiyunpvrusb2-hdw.c - This module implements all the various bits of logic
126*4882a593Smuzhiyun    that handle overall control of a specific pvrusb2 device.
127*4882a593Smuzhiyun    (Policy, instantiation, and arbitration of pvrusb2 devices fall
128*4882a593Smuzhiyun    within the jurisdiction of pvrusb-context not here).
129*4882a593Smuzhiyun
130*4882a593Smuzhiyunpvrusb2-i2c-chips-\*.c - These modules implement the glue logic to
131*4882a593Smuzhiyun    tie together and configure various I2C modules as they attach to
132*4882a593Smuzhiyun    the I2C bus.  There are two versions of this file.  The "v4l2"
133*4882a593Smuzhiyun    version is intended to be used in-tree alongside V4L, where we
134*4882a593Smuzhiyun    implement just the logic that makes sense for a pure V4L
135*4882a593Smuzhiyun    environment.  The "all" version is intended for use outside of
136*4882a593Smuzhiyun    V4L, where we might encounter other possibly "challenging" modules
137*4882a593Smuzhiyun    from ivtv or older kernel snapshots (or even the support modules
138*4882a593Smuzhiyun    in the standalone snapshot).
139*4882a593Smuzhiyun
140*4882a593Smuzhiyunpvrusb2-i2c-cmd-v4l1.[ch] - This module implements generic V4L1
141*4882a593Smuzhiyun    compatible commands to the I2C modules.  It is here where state
142*4882a593Smuzhiyun    changes inside the pvrusb2 driver are translated into V4L1
143*4882a593Smuzhiyun    commands that are in turn send to the various I2C modules.
144*4882a593Smuzhiyun
145*4882a593Smuzhiyunpvrusb2-i2c-cmd-v4l2.[ch] - This module implements generic V4L2
146*4882a593Smuzhiyun    compatible commands to the I2C modules.  It is here where state
147*4882a593Smuzhiyun    changes inside the pvrusb2 driver are translated into V4L2
148*4882a593Smuzhiyun    commands that are in turn send to the various I2C modules.
149*4882a593Smuzhiyun
150*4882a593Smuzhiyunpvrusb2-i2c-core.[ch] - This module provides an implementation of a
151*4882a593Smuzhiyun    kernel-friendly I2C adaptor driver, through which other external
152*4882a593Smuzhiyun    I2C client drivers (e.g. msp3400, tuner, lirc) may connect and
153*4882a593Smuzhiyun    operate corresponding chips within the pvrusb2 device.  It is
154*4882a593Smuzhiyun    through here that other V4L modules can reach into this driver to
155*4882a593Smuzhiyun    operate specific pieces (and those modules are in turn driven by
156*4882a593Smuzhiyun    glue logic which is coordinated by pvrusb2-hdw, doled out by
157*4882a593Smuzhiyun    pvrusb2-context, and then ultimately made available to users
158*4882a593Smuzhiyun    through one of the high level interfaces).
159*4882a593Smuzhiyun
160*4882a593Smuzhiyunpvrusb2-io.[ch] - This module implements a very low level ring of
161*4882a593Smuzhiyun    transfer buffers, required in order to stream data from the
162*4882a593Smuzhiyun    device.  This module is *very* low level.  It only operates the
163*4882a593Smuzhiyun    buffers and makes no attempt to define any policy or mechanism for
164*4882a593Smuzhiyun    how such buffers might be used.
165*4882a593Smuzhiyun
166*4882a593Smuzhiyunpvrusb2-ioread.[ch] - This module layers on top of pvrusb2-io.[ch]
167*4882a593Smuzhiyun    to provide a streaming API usable by a read() system call style of
168*4882a593Smuzhiyun    I/O.  Right now this is the only layer on top of pvrusb2-io.[ch],
169*4882a593Smuzhiyun    however the underlying architecture here was intended to allow for
170*4882a593Smuzhiyun    other styles of I/O to be implemented with additional modules, like
171*4882a593Smuzhiyun    mmap()'ed buffers or something even more exotic.
172*4882a593Smuzhiyun
173*4882a593Smuzhiyunpvrusb2-main.c - This is the top level of the driver.  Module level
174*4882a593Smuzhiyun    and USB core entry points are here.  This is our "main".
175*4882a593Smuzhiyun
176*4882a593Smuzhiyunpvrusb2-sysfs.[ch] - This is the high level interface which ties the
177*4882a593Smuzhiyun    pvrusb2 driver into sysfs.  Through this interface you can do
178*4882a593Smuzhiyun    everything with the driver except actually stream data.
179*4882a593Smuzhiyun
180*4882a593Smuzhiyunpvrusb2-tuner.[ch] - This is glue logic that resides between this
181*4882a593Smuzhiyun    driver and the tuner.ko I2C client driver (which is found
182*4882a593Smuzhiyun    elsewhere in V4L).
183*4882a593Smuzhiyun
184*4882a593Smuzhiyunpvrusb2-util.h - This header defines some common macros used
185*4882a593Smuzhiyun    throughout the driver.  These macros are not really specific to
186*4882a593Smuzhiyun    the driver, but they had to go somewhere.
187*4882a593Smuzhiyun
188*4882a593Smuzhiyunpvrusb2-v4l2.[ch] - This is the high level interface which ties the
189*4882a593Smuzhiyun    pvrusb2 driver into video4linux.  It is through here that V4L
190*4882a593Smuzhiyun    applications can open and operate the driver in the usual V4L
191*4882a593Smuzhiyun    ways.  Note that **ALL** V4L functionality is published only
192*4882a593Smuzhiyun    through here and nowhere else.
193*4882a593Smuzhiyun
194*4882a593Smuzhiyunpvrusb2-video-\*.[ch] - This is glue logic that resides between this
195*4882a593Smuzhiyun    driver and the saa711x.ko I2C client driver (which is found
196*4882a593Smuzhiyun    elsewhere in V4L).  Note that saa711x.ko used to be known as
197*4882a593Smuzhiyun    saa7115.ko in ivtv.  There are two versions of this; one is
198*4882a593Smuzhiyun    selected depending on the particular saa711[5x].ko that is found.
199*4882a593Smuzhiyun
200*4882a593Smuzhiyunpvrusb2.h - This header contains compile time tunable parameters
201*4882a593Smuzhiyun    (and at the moment the driver has very little that needs to be
202*4882a593Smuzhiyun    tuned).
203