dvb-usb.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /* dvb-usb.h is part of the DVB USB library.
  2. *
  3. * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
  4. * see dvb-usb-init.c for copyright information.
  5. *
  6. * the headerfile, all dvb-usb-drivers have to include.
  7. */
  8. #ifndef __DVB_USB_H__
  9. #define __DVB_USB_H__
  10. #include <linux/config.h>
  11. #include <linux/input.h>
  12. #include <linux/module.h>
  13. #include <linux/usb.h>
  14. #include "dvb_frontend.h"
  15. #include "dvb_demux.h"
  16. #include "dvb_net.h"
  17. #include "dmxdev.h"
  18. #include "dvb-pll.h"
  19. #include "dvb-usb-ids.h"
  20. /* debug */
  21. #ifdef CONFIG_DVB_USB_DEBUG
  22. #define dprintk(var,level,args...) \
  23. do { if ((var & level)) { printk(args); } } while (0)
  24. #define debug_dump(b,l,func) {\
  25. int loop_; \
  26. for (loop_ = 0; loop_ < l; loop_++) func("%02x ", b[loop_]); \
  27. func("\n");\
  28. }
  29. #define DVB_USB_DEBUG_STATUS
  30. #else
  31. #define dprintk(args...)
  32. #define debug_dump(b,l,func)
  33. #define DVB_USB_DEBUG_STATUS " (debugging is not enabled)"
  34. #endif
  35. /* generic log methods - taken from usb.h */
  36. #ifndef DVB_USB_LOG_PREFIX
  37. #define DVB_USB_LOG_PREFIX "dvb-usb (please define a log prefix)"
  38. #endif
  39. #undef err
  40. #define err(format, arg...) printk(KERN_ERR DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
  41. #undef info
  42. #define info(format, arg...) printk(KERN_INFO DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
  43. #undef warn
  44. #define warn(format, arg...) printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
  45. /**
  46. * struct dvb_usb_device_description - name and its according USB IDs
  47. * @name: real name of the box, regardless which DVB USB device class is in use
  48. * @cold_ids: array of struct usb_device_id which describe the device in
  49. * pre-firmware state
  50. * @warm_ids: array of struct usb_device_id which describe the device in
  51. * post-firmware state
  52. *
  53. * Each DVB USB device class can have one or more actual devices, this struct
  54. * assigns a name to it.
  55. */
  56. struct dvb_usb_device_description {
  57. const char *name;
  58. #define DVB_USB_ID_MAX_NUM 15
  59. struct usb_device_id *cold_ids[DVB_USB_ID_MAX_NUM];
  60. struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM];
  61. };
  62. /**
  63. * struct dvb_usb_rc_key - a remote control key and its input-event
  64. * @custom: the vendor/custom part of the key
  65. * @data: the actual key part
  66. * @event: the input event assigned to key identified by custom and data
  67. */
  68. struct dvb_usb_rc_key {
  69. u8 custom,data;
  70. u32 event;
  71. };
  72. struct dvb_usb_device;
  73. /**
  74. * struct dvb_usb_properties - properties of a dvb-usb-device
  75. * @caps: capabilites of the DVB USB device.
  76. * @pid_filter_count: number of PID filter position in the optional hardware
  77. * PID-filter.
  78. *
  79. * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
  80. * download.
  81. * @firmware: name of the firmware file.
  82. *
  83. * @size_of_priv: how many bytes shall be allocated for the private field
  84. * of struct dvb_usb_device.
  85. *
  86. * @power_ctrl: called to enable/disable power of the device.
  87. * @streaming_crtl: called to start and stop the MPEG2-TS streaming of the
  88. * device (not URB submitting/killing).
  89. * @pid_filter_ctrl: called to en/disable the PID filter, if any.
  90. * @pid_filter: called to set/unset a PID for filtering.
  91. *
  92. * @read_mac_address: called to read the MAC address of the device.
  93. *
  94. * @frontend_attach: called to attach the possible frontends (fill fe-field
  95. * of struct dvb_usb_device).
  96. * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
  97. * pll_desc and pll_init_buf of struct dvb_usb_device).
  98. * @identify_state: called to determine the state (cold or warm), when it
  99. * is not distinguishable by the USB IDs.
  100. *
  101. * @rc_key_map: a hard-wired array of struct dvb_usb_rc_key (NULL to disable
  102. * remote control handling).
  103. * @rc_key_map_size: number of items in @rc_key_map.
  104. * @rc_query: called to query an event event.
  105. * @rc_interval: time in ms between two queries.
  106. *
  107. * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
  108. *
  109. * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
  110. * endpoint which received control messages with bulk transfers. When this
  111. * is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
  112. * helper functions.
  113. *
  114. * @urb: describes the kind of USB transfer used for MPEG2-TS-streaming.
  115. * (BULK or ISOC)
  116. *
  117. * @num_device_descs: number of struct dvb_usb_device_description in @devices
  118. * @devices: array of struct dvb_usb_device_description compatibles with these
  119. * properties.
  120. */
  121. struct dvb_usb_properties {
  122. #define DVB_USB_HAS_PID_FILTER 0x01
  123. #define DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF 0x02
  124. #define DVB_USB_NEED_PID_FILTERING 0x04
  125. #define DVB_USB_IS_AN_I2C_ADAPTER 0x08
  126. int caps;
  127. int pid_filter_count;
  128. #define CYPRESS_AN2135 0
  129. #define CYPRESS_AN2235 1
  130. #define CYPRESS_FX2 2
  131. int usb_ctrl;
  132. const char *firmware;
  133. int size_of_priv;
  134. int (*power_ctrl) (struct dvb_usb_device *, int);
  135. int (*streaming_ctrl) (struct dvb_usb_device *, int);
  136. int (*pid_filter_ctrl) (struct dvb_usb_device *, int);
  137. int (*pid_filter) (struct dvb_usb_device *, int, u16, int);
  138. int (*read_mac_address) (struct dvb_usb_device *, u8 []);
  139. int (*frontend_attach) (struct dvb_usb_device *);
  140. int (*tuner_attach) (struct dvb_usb_device *);
  141. int (*identify_state) (struct usb_device *, struct dvb_usb_properties *,
  142. struct dvb_usb_device_description **, int *);
  143. /* remote control properties */
  144. #define REMOTE_NO_KEY_PRESSED 0x00
  145. #define REMOTE_KEY_PRESSED 0x01
  146. #define REMOTE_KEY_REPEAT 0x02
  147. struct dvb_usb_rc_key *rc_key_map;
  148. int rc_key_map_size;
  149. int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
  150. int rc_interval;
  151. struct i2c_algorithm *i2c_algo;
  152. int generic_bulk_ctrl_endpoint;
  153. struct {
  154. #define DVB_USB_BULK 1
  155. #define DVB_USB_ISOC 2
  156. int type;
  157. int count;
  158. int endpoint;
  159. union {
  160. struct {
  161. int buffersize; /* per URB */
  162. } bulk;
  163. struct {
  164. int framesperurb;
  165. int framesize;
  166. int interval;
  167. } isoc;
  168. } u;
  169. } urb;
  170. int num_device_descs;
  171. struct dvb_usb_device_description devices[9];
  172. };
  173. /**
  174. * struct dvb_usb_device - object of a DVB USB device
  175. * @props: copy of the struct dvb_usb_properties this device belongs to.
  176. * @desc: pointer to the device's struct dvb_usb_device_description.
  177. * @state: initialization and runtime state of the device.
  178. *
  179. * @udev: pointer to the device's struct usb_device.
  180. * @urb_list: array of dynamically allocated struct urb for the MPEG2-TS-
  181. * streaming.
  182. *
  183. * @buf_num: number of buffer allocated.
  184. * @buf_size: size of each buffer in buf_list.
  185. * @buf_list: array containing all allocate buffers for streaming.
  186. * @dma_addr: list of dma_addr_t for each buffer in buf_list.
  187. *
  188. * @urbs_initialized: number of URBs initialized.
  189. * @urbs_submitted: number of URBs submitted.
  190. *
  191. * @feedcount: number of reqested feeds (used for streaming-activation)
  192. * @pid_filtering: is hardware pid_filtering used or not.
  193. *
  194. * @usb_sem: semaphore of USB control messages (reading needs two messages)
  195. * @i2c_sem: semaphore for i2c-transfers
  196. *
  197. * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
  198. * @pll_addr: I2C address of the tuner for programming
  199. * @pll_init: array containing the initialization buffer
  200. * @pll_desc: pointer to the appropriate struct dvb_pll_desc
  201. *
  202. * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or the board
  203. *
  204. * @dvb_adap: device's dvb_adapter.
  205. * @dmxdev: device's dmxdev.
  206. * @demux: device's software demuxer.
  207. * @dvb_net: device's dvb_net interfaces.
  208. * @dvb_frontend: device's frontend.
  209. * @max_feed_count: how many feeds can be handled simultaneously by this
  210. * device
  211. * @fe_sleep: rerouted frontend-sleep function.
  212. * @fe_init: rerouted frontend-init (wakeup) function.
  213. * @rc_input_dev: input device for the remote control.
  214. * @rc_query_work: struct work_struct frequent rc queries
  215. * @last_event: last triggered event
  216. * @last_state: last state (no, pressed, repeat)
  217. * @owner: owner of the dvb_adapter
  218. * @priv: private data of the actual driver (allocate by dvb-usb, size defined
  219. * in size_of_priv of dvb_usb_properties).
  220. */
  221. struct dvb_usb_device {
  222. struct dvb_usb_properties props;
  223. struct dvb_usb_device_description *desc;
  224. #define DVB_USB_STATE_INIT 0x000
  225. #define DVB_USB_STATE_URB_LIST 0x001
  226. #define DVB_USB_STATE_URB_BUF 0x002
  227. #define DVB_USB_STATE_DVB 0x004
  228. #define DVB_USB_STATE_I2C 0x008
  229. #define DVB_USB_STATE_REMOTE 0x010
  230. #define DVB_USB_STATE_URB_SUBMIT 0x020
  231. int state;
  232. /* usb */
  233. struct usb_device *udev;
  234. struct urb **urb_list;
  235. int buf_num;
  236. unsigned long buf_size;
  237. u8 **buf_list;
  238. dma_addr_t *dma_addr;
  239. int urbs_initialized;
  240. int urbs_submitted;
  241. int feedcount;
  242. int pid_filtering;
  243. /* locking */
  244. struct semaphore usb_sem;
  245. /* i2c */
  246. struct semaphore i2c_sem;
  247. struct i2c_adapter i2c_adap;
  248. /* tuner programming information */
  249. u8 pll_addr;
  250. u8 pll_init[4];
  251. struct dvb_pll_desc *pll_desc;
  252. int (*tuner_pass_ctrl)(struct dvb_frontend *, int, u8);
  253. /* dvb */
  254. struct dvb_adapter dvb_adap;
  255. struct dmxdev dmxdev;
  256. struct dvb_demux demux;
  257. struct dvb_net dvb_net;
  258. struct dvb_frontend* fe;
  259. int max_feed_count;
  260. int (*fe_sleep) (struct dvb_frontend *);
  261. int (*fe_init) (struct dvb_frontend *);
  262. /* remote control */
  263. struct input_dev rc_input_dev;
  264. struct work_struct rc_query_work;
  265. u32 last_event;
  266. int last_state;
  267. struct module *owner;
  268. void *priv;
  269. };
  270. extern int dvb_usb_device_init(struct usb_interface *, struct dvb_usb_properties *, struct module *, struct dvb_usb_device **);
  271. extern void dvb_usb_device_exit(struct usb_interface *);
  272. /* the generic read/write method for device control */
  273. extern int dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,int);
  274. extern int dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
  275. /* commonly used remote control parsing */
  276. extern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *, int *);
  277. /* commonly used pll init and set functions */
  278. extern int dvb_usb_pll_init_i2c(struct dvb_frontend *);
  279. extern int dvb_usb_pll_set(struct dvb_frontend *, struct dvb_frontend_parameters *, u8[]);
  280. extern int dvb_usb_pll_set_i2c(struct dvb_frontend *, struct dvb_frontend_parameters *);
  281. #endif