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