dvb-usb.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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/usb.h>
  13. #include <linux/firmware.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. * @download_firmware: called to download the firmware when the usb_ctrl is
  83. * DEVICE_SPECIFIC.
  84. * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
  85. so do the warm initialization right after it
  86. * @size_of_priv: how many bytes shall be allocated for the private field
  87. * of struct dvb_usb_device.
  88. *
  89. * @power_ctrl: called to enable/disable power of the device.
  90. * @streaming_crtl: called to start and stop the MPEG2-TS streaming of the
  91. * device (not URB submitting/killing).
  92. * @pid_filter_ctrl: called to en/disable the PID filter, if any.
  93. * @pid_filter: called to set/unset a PID for filtering.
  94. *
  95. * @read_mac_address: called to read the MAC address of the device.
  96. *
  97. * @frontend_attach: called to attach the possible frontends (fill fe-field
  98. * of struct dvb_usb_device).
  99. * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
  100. * pll_desc and pll_init_buf of struct dvb_usb_device).
  101. * @identify_state: called to determine the state (cold or warm), when it
  102. * is not distinguishable by the USB IDs.
  103. *
  104. * @rc_key_map: a hard-wired array of struct dvb_usb_rc_key (NULL to disable
  105. * remote control handling).
  106. * @rc_key_map_size: number of items in @rc_key_map.
  107. * @rc_query: called to query an event event.
  108. * @rc_interval: time in ms between two queries.
  109. *
  110. * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
  111. *
  112. * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
  113. * endpoint which received control messages with bulk transfers. When this
  114. * is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
  115. * helper functions.
  116. *
  117. * @urb: describes the kind of USB transfer used for MPEG2-TS-streaming.
  118. * (BULK or ISOC)
  119. *
  120. * @num_device_descs: number of struct dvb_usb_device_description in @devices
  121. * @devices: array of struct dvb_usb_device_description compatibles with these
  122. * properties.
  123. */
  124. struct dvb_usb_properties {
  125. #define DVB_USB_HAS_PID_FILTER 0x01
  126. #define DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF 0x02
  127. #define DVB_USB_NEED_PID_FILTERING 0x04
  128. #define DVB_USB_IS_AN_I2C_ADAPTER 0x08
  129. int caps;
  130. int pid_filter_count;
  131. #define DEVICE_SPECIFIC 0
  132. #define CYPRESS_AN2135 1
  133. #define CYPRESS_AN2235 2
  134. #define CYPRESS_FX2 3
  135. int usb_ctrl;
  136. const char firmware[FIRMWARE_NAME_MAX];
  137. int (*download_firmware) (struct usb_device *, const struct firmware *);
  138. int no_reconnect;
  139. int size_of_priv;
  140. int (*power_ctrl) (struct dvb_usb_device *, int);
  141. int (*streaming_ctrl) (struct dvb_usb_device *, int);
  142. int (*pid_filter_ctrl) (struct dvb_usb_device *, int);
  143. int (*pid_filter) (struct dvb_usb_device *, int, u16, int);
  144. int (*read_mac_address) (struct dvb_usb_device *, u8 []);
  145. int (*frontend_attach) (struct dvb_usb_device *);
  146. int (*tuner_attach) (struct dvb_usb_device *);
  147. int (*identify_state) (struct usb_device *, struct dvb_usb_properties *,
  148. struct dvb_usb_device_description **, int *);
  149. /* remote control properties */
  150. #define REMOTE_NO_KEY_PRESSED 0x00
  151. #define REMOTE_KEY_PRESSED 0x01
  152. #define REMOTE_KEY_REPEAT 0x02
  153. struct dvb_usb_rc_key *rc_key_map;
  154. int rc_key_map_size;
  155. int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
  156. int rc_interval;
  157. struct i2c_algorithm *i2c_algo;
  158. int generic_bulk_ctrl_endpoint;
  159. struct {
  160. #define DVB_USB_BULK 1
  161. #define DVB_USB_ISOC 2
  162. int type;
  163. int count;
  164. int endpoint;
  165. union {
  166. struct {
  167. int buffersize; /* per URB */
  168. } bulk;
  169. struct {
  170. int framesperurb;
  171. int framesize;
  172. int interval;
  173. } isoc;
  174. } u;
  175. } urb;
  176. int num_device_descs;
  177. struct dvb_usb_device_description devices[9];
  178. };
  179. /**
  180. * struct dvb_usb_device - object of a DVB USB device
  181. * @props: copy of the struct dvb_usb_properties this device belongs to.
  182. * @desc: pointer to the device's struct dvb_usb_device_description.
  183. * @state: initialization and runtime state of the device.
  184. *
  185. * @udev: pointer to the device's struct usb_device.
  186. * @urb_list: array of dynamically allocated struct urb for the MPEG2-TS-
  187. * streaming.
  188. *
  189. * @buf_num: number of buffer allocated.
  190. * @buf_size: size of each buffer in buf_list.
  191. * @buf_list: array containing all allocate buffers for streaming.
  192. * @dma_addr: list of dma_addr_t for each buffer in buf_list.
  193. *
  194. * @urbs_initialized: number of URBs initialized.
  195. * @urbs_submitted: number of URBs submitted.
  196. *
  197. * @feedcount: number of reqested feeds (used for streaming-activation)
  198. * @pid_filtering: is hardware pid_filtering used or not.
  199. *
  200. * @usb_sem: semaphore of USB control messages (reading needs two messages)
  201. * @i2c_sem: semaphore for i2c-transfers
  202. *
  203. * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
  204. * @pll_addr: I2C address of the tuner for programming
  205. * @pll_init: array containing the initialization buffer
  206. * @pll_desc: pointer to the appropriate struct dvb_pll_desc
  207. *
  208. * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or the board
  209. *
  210. * @dvb_adap: device's dvb_adapter.
  211. * @dmxdev: device's dmxdev.
  212. * @demux: device's software demuxer.
  213. * @dvb_net: device's dvb_net interfaces.
  214. * @dvb_frontend: device's frontend.
  215. * @max_feed_count: how many feeds can be handled simultaneously by this
  216. * device
  217. * @fe_sleep: rerouted frontend-sleep function.
  218. * @fe_init: rerouted frontend-init (wakeup) function.
  219. * @rc_input_dev: input device for the remote control.
  220. * @rc_query_work: struct work_struct frequent rc queries
  221. * @last_event: last triggered event
  222. * @last_state: last state (no, pressed, repeat)
  223. * @owner: owner of the dvb_adapter
  224. * @priv: private data of the actual driver (allocate by dvb-usb, size defined
  225. * in size_of_priv of dvb_usb_properties).
  226. */
  227. struct dvb_usb_device {
  228. struct dvb_usb_properties props;
  229. struct dvb_usb_device_description *desc;
  230. #define DVB_USB_STATE_INIT 0x000
  231. #define DVB_USB_STATE_URB_LIST 0x001
  232. #define DVB_USB_STATE_URB_BUF 0x002
  233. #define DVB_USB_STATE_DVB 0x004
  234. #define DVB_USB_STATE_I2C 0x008
  235. #define DVB_USB_STATE_REMOTE 0x010
  236. #define DVB_USB_STATE_URB_SUBMIT 0x020
  237. int state;
  238. /* usb */
  239. struct usb_device *udev;
  240. struct urb **urb_list;
  241. int buf_num;
  242. unsigned long buf_size;
  243. u8 **buf_list;
  244. dma_addr_t *dma_addr;
  245. int urbs_initialized;
  246. int urbs_submitted;
  247. int feedcount;
  248. int pid_filtering;
  249. /* locking */
  250. struct semaphore usb_sem;
  251. /* i2c */
  252. struct semaphore i2c_sem;
  253. struct i2c_adapter i2c_adap;
  254. /* tuner programming information */
  255. u8 pll_addr;
  256. u8 pll_init[4];
  257. struct dvb_pll_desc *pll_desc;
  258. int (*tuner_pass_ctrl)(struct dvb_frontend *, int, u8);
  259. /* dvb */
  260. struct dvb_adapter dvb_adap;
  261. struct dmxdev dmxdev;
  262. struct dvb_demux demux;
  263. struct dvb_net dvb_net;
  264. struct dvb_frontend* fe;
  265. int max_feed_count;
  266. int (*fe_sleep) (struct dvb_frontend *);
  267. int (*fe_init) (struct dvb_frontend *);
  268. /* remote control */
  269. struct input_dev *rc_input_dev;
  270. char rc_phys[64];
  271. struct work_struct rc_query_work;
  272. u32 last_event;
  273. int last_state;
  274. struct module *owner;
  275. void *priv;
  276. };
  277. extern int dvb_usb_device_init(struct usb_interface *, struct dvb_usb_properties *, struct module *, struct dvb_usb_device **);
  278. extern void dvb_usb_device_exit(struct usb_interface *);
  279. /* the generic read/write method for device control */
  280. extern int dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,int);
  281. extern int dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
  282. /* commonly used remote control parsing */
  283. extern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *, int *);
  284. /* commonly used pll init and set functions */
  285. extern int dvb_usb_pll_init_i2c(struct dvb_frontend *);
  286. extern int dvb_usb_pll_set(struct dvb_frontend *, struct dvb_frontend_parameters *, u8[]);
  287. extern int dvb_usb_pll_set_i2c(struct dvb_frontend *, struct dvb_frontend_parameters *);
  288. /* commonly used firmware download types and function */
  289. struct hexline {
  290. u8 len;
  291. u32 addr;
  292. u8 type;
  293. u8 data[255];
  294. u8 chk;
  295. };
  296. extern int dvb_usb_get_hexline(const struct firmware *, struct hexline *, int *);
  297. extern int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type);
  298. #endif