dvb_usb.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*
  2. * DVB USB framework
  3. *
  4. * Copyright (C) 2004-6 Patrick Boettcher <patrick.boettcher@desy.de>
  5. * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. #ifndef DVB_USB_H
  22. #define DVB_USB_H
  23. #include <linux/usb/input.h>
  24. #include <linux/firmware.h>
  25. #include <media/rc-core.h>
  26. #include "dvb_frontend.h"
  27. #include "dvb_demux.h"
  28. #include "dvb_net.h"
  29. #include "dmxdev.h"
  30. #include "dvb-usb-ids.h"
  31. /*
  32. * device file: /dev/dvb/adapter[0-1]/frontend[0-2]
  33. *
  34. * |-- device
  35. * | |-- adapter0
  36. * | | |-- frontend0
  37. * | | |-- frontend1
  38. * | | `-- frontend2
  39. * | `-- adapter1
  40. * | |-- frontend0
  41. * | |-- frontend1
  42. * | `-- frontend2
  43. *
  44. *
  45. * Commonly used variable names:
  46. * d = pointer to device (struct dvb_usb_device *)
  47. * adap = pointer to adapter (struct dvb_usb_adapter *)
  48. * fe = pointer to frontend (struct dvb_frontend *)
  49. *
  50. * Use macros defined in that file to resolve needed pointers.
  51. */
  52. /* helper macros for every DVB USB driver use */
  53. #define adap_to_d(adap) (container_of(adap, struct dvb_usb_device, \
  54. adapter[adap->id]))
  55. #define adap_to_priv(adap) (adap_to_d(adap)->priv)
  56. #define fe_to_adap(fe) ((struct dvb_usb_adapter *) ((fe)->dvb->priv))
  57. #define fe_to_d(fe) (adap_to_d(fe_to_adap(fe)))
  58. #define fe_to_priv(fe) (fe_to_d(fe)->priv)
  59. #define d_to_priv(d) (d->priv)
  60. #define dvb_usb_dbg_usb_control_msg(udev, r, t, v, i, b, l) { \
  61. char *direction; \
  62. if (t == (USB_TYPE_VENDOR | USB_DIR_OUT)) \
  63. direction = ">>>"; \
  64. else \
  65. direction = "<<<"; \
  66. dev_dbg(&udev->dev, "%s: %02x %02x %02x %02x %02x %02x %02x %02x " \
  67. "%s %*ph\n", __func__, t, r, v & 0xff, v >> 8, \
  68. i & 0xff, i >> 8, l & 0xff, l >> 8, direction, l, b); \
  69. }
  70. #define DVB_USB_STREAM_BULK(endpoint_, count_, size_) { \
  71. .type = USB_BULK, \
  72. .count = count_, \
  73. .endpoint = endpoint_, \
  74. .u = { \
  75. .bulk = { \
  76. .buffersize = size_, \
  77. } \
  78. } \
  79. }
  80. #define DVB_USB_STREAM_ISOC(endpoint_, count_, frames_, size_, interval_) { \
  81. .type = USB_ISOC, \
  82. .count = count_, \
  83. .endpoint = endpoint_, \
  84. .u = { \
  85. .isoc = { \
  86. .framesperurb = frames_, \
  87. .framesize = size_,\
  88. .interval = interval_, \
  89. } \
  90. } \
  91. }
  92. #define DVB_USB_DEVICE(vend, prod, props_, name_, rc) \
  93. .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
  94. .idVendor = (vend), \
  95. .idProduct = (prod), \
  96. .driver_info = (kernel_ulong_t) &((const struct dvb_usb_driver_info) { \
  97. .props = (props_), \
  98. .name = (name_), \
  99. .rc_map = (rc), \
  100. })
  101. struct dvb_usb_device;
  102. struct dvb_usb_adapter;
  103. /**
  104. * structure for carrying all needed data from the device driver to the general
  105. * dvb usb routines
  106. * @name: device name
  107. * @rc_map: name of rc codes table
  108. * @props: structure containing all device properties
  109. */
  110. struct dvb_usb_driver_info {
  111. const char *name;
  112. const char *rc_map;
  113. const struct dvb_usb_device_properties *props;
  114. };
  115. /**
  116. * structure for remote controller configuration
  117. * @map_name: name of rc codes table
  118. * @allowed_protos: protocol(s) supported by the driver
  119. * @change_protocol: callback to change protocol
  120. * @query: called to query an event from the device
  121. * @interval: time in ms between two queries
  122. * @driver_type: used to point if a device supports raw mode
  123. * @bulk_mode: device supports bulk mode for rc (disable polling mode)
  124. */
  125. struct dvb_usb_rc {
  126. const char *map_name;
  127. u64 allowed_protos;
  128. int (*change_protocol)(struct rc_dev *dev, u64 *rc_type);
  129. int (*query) (struct dvb_usb_device *d);
  130. unsigned int interval;
  131. const enum rc_driver_type driver_type;
  132. bool bulk_mode;
  133. };
  134. /**
  135. * usb streaming configration for adapter
  136. * @type: urb type
  137. * @count: count of used urbs
  138. * @endpoint: stream usb endpoint number
  139. */
  140. struct usb_data_stream_properties {
  141. #define USB_BULK 1
  142. #define USB_ISOC 2
  143. u8 type;
  144. u8 count;
  145. u8 endpoint;
  146. union {
  147. struct {
  148. unsigned int buffersize; /* per URB */
  149. } bulk;
  150. struct {
  151. int framesperurb;
  152. int framesize;
  153. int interval;
  154. } isoc;
  155. } u;
  156. };
  157. /**
  158. * properties of dvb usb device adapter
  159. * @caps: adapter capabilities
  160. * @pid_filter_count: pid count of adapter pid-filter
  161. * @pid_filter_ctrl: called to enable/disable pid-filter
  162. * @pid_filter: called to set/unset pid for filtering
  163. * @stream: adapter usb stream configuration
  164. */
  165. #define MAX_NO_OF_FE_PER_ADAP 3
  166. struct dvb_usb_adapter_properties {
  167. #define DVB_USB_ADAP_HAS_PID_FILTER 0x01
  168. #define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
  169. #define DVB_USB_ADAP_NEED_PID_FILTERING 0x04
  170. u8 caps;
  171. u8 pid_filter_count;
  172. int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);
  173. int (*pid_filter) (struct dvb_usb_adapter *, int, u16, int);
  174. struct usb_data_stream_properties stream;
  175. };
  176. /**
  177. * struct dvb_usb_device_properties - properties of a dvb-usb-device
  178. * @driver_name: name of the owning driver module
  179. * @owner: owner of the dvb_adapter
  180. * @adapter_nr: values from the DVB_DEFINE_MOD_OPT_ADAPTER_NR() macro
  181. * @bInterfaceNumber: usb interface number driver binds
  182. * @size_of_priv: bytes allocated for the driver private data
  183. * @generic_bulk_ctrl_endpoint: bulk control endpoint number for sent
  184. * @generic_bulk_ctrl_endpoint_response: bulk control endpoint number for
  185. * receive
  186. * @generic_bulk_ctrl_delay: delay between bulk control sent and receive message
  187. * @identify_state: called to determine the firmware state (cold or warm) and
  188. * return possible firmware file name to be loaded
  189. * @firmware: name of the firmware file to be loaded
  190. * @download_firmware: called to download the firmware
  191. * @i2c_algo: i2c_algorithm if the device has i2c-adapter
  192. * @num_adapters: dvb usb device adapter count
  193. * @get_adapter_count: called to resolve adapter count
  194. * @adapter: array of all adapter properties of device
  195. * @power_ctrl: called to enable/disable power of the device
  196. * @read_config: called to resolve device configuration
  197. * @read_mac_address: called to resolve adapter mac-address
  198. * @frontend_attach: called to attach the possible frontends
  199. * @tuner_attach: called to attach the possible tuners
  200. * @frontend_ctrl: called to power on/off active frontend
  201. * @streaming_ctrl: called to start/stop the usb streaming of adapter
  202. * @init: called after adapters are created in order to finalize device
  203. * configuration
  204. * @exit: called when driver is unloaded
  205. * @get_rc_config: called to resolve used remote controller configuration
  206. * @get_stream_config: called to resolve input and output stream configuration
  207. * of the adapter just before streaming is started. input stream is transport
  208. * stream from the demodulator and output stream is usb stream to host.
  209. */
  210. #define MAX_NO_OF_ADAPTER_PER_DEVICE 2
  211. struct dvb_usb_device_properties {
  212. const char *driver_name;
  213. struct module *owner;
  214. short *adapter_nr;
  215. u8 bInterfaceNumber;
  216. unsigned int size_of_priv;
  217. u8 generic_bulk_ctrl_endpoint;
  218. u8 generic_bulk_ctrl_endpoint_response;
  219. unsigned int generic_bulk_ctrl_delay;
  220. #define WARM 0
  221. #define COLD 1
  222. int (*identify_state) (struct dvb_usb_device *, const char **);
  223. const char *firmware;
  224. #define RECONNECTS_USB 1
  225. int (*download_firmware) (struct dvb_usb_device *,
  226. const struct firmware *);
  227. struct i2c_algorithm *i2c_algo;
  228. unsigned int num_adapters;
  229. int (*get_adapter_count) (struct dvb_usb_device *);
  230. struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
  231. int (*power_ctrl) (struct dvb_usb_device *, int);
  232. int (*read_config) (struct dvb_usb_device *d);
  233. int (*read_mac_address) (struct dvb_usb_adapter *, u8 []);
  234. int (*frontend_attach) (struct dvb_usb_adapter *);
  235. int (*tuner_attach) (struct dvb_usb_adapter *);
  236. int (*frontend_ctrl) (struct dvb_frontend *, int);
  237. int (*streaming_ctrl) (struct dvb_frontend *, int);
  238. int (*init) (struct dvb_usb_device *);
  239. void (*exit) (struct dvb_usb_device *);
  240. int (*get_rc_config) (struct dvb_usb_device *, struct dvb_usb_rc *);
  241. #define DVB_USB_FE_TS_TYPE_188 0
  242. #define DVB_USB_FE_TS_TYPE_204 1
  243. #define DVB_USB_FE_TS_TYPE_RAW 2
  244. int (*get_stream_config) (struct dvb_frontend *, u8 *,
  245. struct usb_data_stream_properties *);
  246. };
  247. /**
  248. * generic object of an usb stream
  249. * @buf_num: number of buffer allocated
  250. * @buf_size: size of each buffer in buf_list
  251. * @buf_list: array containing all allocate buffers for streaming
  252. * @dma_addr: list of dma_addr_t for each buffer in buf_list
  253. *
  254. * @urbs_initialized: number of URBs initialized
  255. * @urbs_submitted: number of URBs submitted
  256. */
  257. #define MAX_NO_URBS_FOR_DATA_STREAM 10
  258. struct usb_data_stream {
  259. struct usb_device *udev;
  260. struct usb_data_stream_properties props;
  261. #define USB_STATE_INIT 0x00
  262. #define USB_STATE_URB_BUF 0x01
  263. u8 state;
  264. void (*complete) (struct usb_data_stream *, u8 *, size_t);
  265. struct urb *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
  266. int buf_num;
  267. unsigned long buf_size;
  268. u8 *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
  269. dma_addr_t dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
  270. int urbs_initialized;
  271. int urbs_submitted;
  272. void *user_priv;
  273. };
  274. /**
  275. * dvb adapter object on dvb usb device
  276. * @props: pointer to adapter properties
  277. * @stream: adapter the usb data stream
  278. * @id: index of this adapter (starting with 0)
  279. * @ts_type: transport stream, input stream, type
  280. * @suspend_resume_active: set when there is ongoing suspend / resume
  281. * @pid_filtering: is hardware pid_filtering used or not
  282. * @feed_count: current feed count
  283. * @max_feed_count: maimum feed count device can handle
  284. * @dvb_adap: adapter dvb_adapter
  285. * @dmxdev: adapter dmxdev
  286. * @demux: adapter software demuxer
  287. * @dvb_net: adapter dvb_net interfaces
  288. * @sync_mutex: mutex used to sync control and streaming of the adapter
  289. * @fe: adapter frontends
  290. * @fe_init: rerouted frontend-init function
  291. * @fe_sleep: rerouted frontend-sleep function
  292. */
  293. struct dvb_usb_adapter {
  294. const struct dvb_usb_adapter_properties *props;
  295. struct usb_data_stream stream;
  296. u8 id;
  297. u8 ts_type;
  298. bool suspend_resume_active;
  299. bool pid_filtering;
  300. u8 feed_count;
  301. u8 max_feed_count;
  302. s8 active_fe;
  303. /* dvb */
  304. struct dvb_adapter dvb_adap;
  305. struct dmxdev dmxdev;
  306. struct dvb_demux demux;
  307. struct dvb_net dvb_net;
  308. struct mutex sync_mutex;
  309. struct dvb_frontend *fe[MAX_NO_OF_FE_PER_ADAP];
  310. int (*fe_init[MAX_NO_OF_FE_PER_ADAP]) (struct dvb_frontend *);
  311. int (*fe_sleep[MAX_NO_OF_FE_PER_ADAP]) (struct dvb_frontend *);
  312. };
  313. /**
  314. * dvb usb device object
  315. * @props: device properties
  316. * @name: device name
  317. * @rc_map: name of rc codes table
  318. * @rc_polling_active: set when RC polling is active
  319. * @udev: pointer to the device's struct usb_device
  320. * @intf: pointer to the device's usb interface
  321. * @rc: remote controller configuration
  322. * @probe_work: work to defer .probe()
  323. * @powered: indicated whether the device is power or not
  324. * @usb_mutex: mutex for usb control messages
  325. * @i2c_mutex: mutex for i2c-transfers
  326. * @i2c_adap: device's i2c-adapter
  327. * @rc_dev: rc device for the remote control
  328. * @rc_query_work: work for polling remote
  329. * @priv: private data of the actual driver (allocate by dvb usb, size defined
  330. * in size_of_priv of dvb_usb_properties).
  331. */
  332. struct dvb_usb_device {
  333. const struct dvb_usb_device_properties *props;
  334. const char *name;
  335. const char *rc_map;
  336. bool rc_polling_active;
  337. struct usb_device *udev;
  338. struct usb_interface *intf;
  339. struct dvb_usb_rc rc;
  340. struct work_struct probe_work;
  341. pid_t work_pid;
  342. int powered;
  343. /* locking */
  344. struct mutex usb_mutex;
  345. /* i2c */
  346. struct mutex i2c_mutex;
  347. struct i2c_adapter i2c_adap;
  348. struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
  349. /* remote control */
  350. struct rc_dev *rc_dev;
  351. char rc_phys[64];
  352. struct delayed_work rc_query_work;
  353. void *priv;
  354. };
  355. extern int dvb_usbv2_probe(struct usb_interface *,
  356. const struct usb_device_id *);
  357. extern void dvb_usbv2_disconnect(struct usb_interface *);
  358. extern int dvb_usbv2_suspend(struct usb_interface *, pm_message_t);
  359. extern int dvb_usbv2_resume(struct usb_interface *);
  360. extern int dvb_usbv2_reset_resume(struct usb_interface *);
  361. /* the generic read/write method for device control */
  362. extern int dvb_usbv2_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16);
  363. extern int dvb_usbv2_generic_write(struct dvb_usb_device *, u8 *, u16);
  364. #endif