dvb-usb.h 14 KB

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