pvrusb2.rst 9.2 KB

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