dvb-usb.h 12 KB

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