dvb_usb.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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/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_STREAM_BULK(endpoint_, count_, size_) { \
  61. .type = USB_BULK, \
  62. .count = count_, \
  63. .endpoint = endpoint_, \
  64. .u = { \
  65. .bulk = { \
  66. .buffersize = size_, \
  67. } \
  68. } \
  69. }
  70. #define DVB_USB_STREAM_ISOC(endpoint_, count_, frames_, size_, interval_) { \
  71. .type = USB_ISOC, \
  72. .count = count_, \
  73. .endpoint = endpoint_, \
  74. .u = { \
  75. .isoc = { \
  76. .framesperurb = frames_, \
  77. .framesize = size_,\
  78. .interval = interval_, \
  79. } \
  80. } \
  81. }
  82. #define DVB_USB_DEVICE(vend, prod, props_, name_, rc) \
  83. .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
  84. .idVendor = (vend), \
  85. .idProduct = (prod), \
  86. .driver_info = (kernel_ulong_t) &((const struct dvb_usb_driver_info) { \
  87. .props = (props_), \
  88. .name = (name_), \
  89. .rc_map = (rc), \
  90. })
  91. struct dvb_usb_device;
  92. struct dvb_usb_adapter;
  93. /**
  94. * structure for carrying all needed data from the device driver to the general
  95. * dvb usb routines
  96. * @name: device name
  97. * @rc_map: name of rc codes table
  98. * @props: structure containing all device properties
  99. */
  100. struct dvb_usb_driver_info {
  101. const char *name;
  102. const char *rc_map;
  103. const struct dvb_usb_device_properties *props;
  104. };
  105. /**
  106. * structure for remote controller configuration
  107. * @map_name: name of rc codes table
  108. * @allowed_protos: protocol(s) supported by the driver
  109. * @change_protocol: callback to change protocol
  110. * @query: called to query an event from the device
  111. * @interval: time in ms between two queries
  112. * @driver_type: used to point if a device supports raw mode
  113. * @bulk_mode: device supports bulk mode for rc (disable polling mode)
  114. */
  115. struct dvb_usb_rc {
  116. const char *map_name;
  117. u64 allowed_protos;
  118. int (*change_protocol)(struct rc_dev *dev, u64 rc_type);
  119. int (*query) (struct dvb_usb_device *d);
  120. unsigned int interval;
  121. const enum rc_driver_type driver_type;
  122. bool bulk_mode;
  123. };
  124. /**
  125. * usb streaming configration for adapter
  126. * @type: urb type
  127. * @count: count of used urbs
  128. * @endpoint: stream usb endpoint number
  129. */
  130. struct usb_data_stream_properties {
  131. #define USB_BULK 1
  132. #define USB_ISOC 2
  133. u8 type;
  134. u8 count;
  135. u8 endpoint;
  136. union {
  137. struct {
  138. unsigned int buffersize; /* per URB */
  139. } bulk;
  140. struct {
  141. int framesperurb;
  142. int framesize;
  143. int interval;
  144. } isoc;
  145. } u;
  146. };
  147. /**
  148. * properties of dvb usb device adapter
  149. * @caps: adapter capabilities
  150. * @pid_filter_count: pid count of adapter pid-filter
  151. * @pid_filter_ctrl: called to enable/disable pid-filter
  152. * @pid_filter: called to set/unset pid for filtering
  153. * @stream: adapter usb stream configuration
  154. */
  155. #define MAX_NO_OF_FE_PER_ADAP 3
  156. struct dvb_usb_adapter_properties {
  157. #define DVB_USB_ADAP_HAS_PID_FILTER 0x01
  158. #define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
  159. #define DVB_USB_ADAP_NEED_PID_FILTERING 0x04
  160. u8 caps;
  161. u8 pid_filter_count;
  162. int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);
  163. int (*pid_filter) (struct dvb_usb_adapter *, int, u16, int);
  164. struct usb_data_stream_properties stream;
  165. };
  166. /**
  167. * struct dvb_usb_device_properties - properties of a dvb-usb-device
  168. * @driver_name: name of the owning driver module
  169. * @owner: owner of the dvb_adapter
  170. * @adapter_nr: values from the DVB_DEFINE_MOD_OPT_ADAPTER_NR() macro
  171. * @bInterfaceNumber: usb interface number driver binds
  172. * @size_of_priv: bytes allocated for the driver private data
  173. * @generic_bulk_ctrl_endpoint: bulk control endpoint number for sent
  174. * @generic_bulk_ctrl_endpoint_response: bulk control endpoint number for
  175. * receive
  176. * @generic_bulk_ctrl_delay: delay between bulk control sent and receive message
  177. * @identify_state: called to determine the firmware state (cold or warm) and
  178. * return possible firmware file name to be loaded
  179. * @firmware: name of the firmware file to be loaded
  180. * @download_firmware: called to download the firmware
  181. * @i2c_algo: i2c_algorithm if the device has i2c-adapter
  182. * @num_adapters: dvb usb device adapter count
  183. * @get_adapter_count: called to resolve adapter count
  184. * @adapter: array of all adapter properties of device
  185. * @power_ctrl: called to enable/disable power of the device
  186. * @read_config: called to resolve device configuration
  187. * @read_mac_address: called to resolve adapter mac-address
  188. * @frontend_attach: called to attach the possible frontends
  189. * @tuner_attach: called to attach the possible tuners
  190. * @frontend_ctrl: called to power on/off active frontend
  191. * @streaming_ctrl: called to start/stop the usb streaming of adapter
  192. * @fe_ioctl_override: frontend ioctl override. avoid using that is possible
  193. * @init: called after adapters are created in order to finalize device
  194. * configuration
  195. * @exit: called when driver is unloaded
  196. * @get_rc_config: called to resolve used remote controller configuration
  197. * @get_stream_config: called to resolve input and output stream configuration
  198. * of the adapter just before streaming is started. input stream is transport
  199. * stream from the demodulator and output stream is usb stream to host.
  200. */
  201. #define MAX_NO_OF_ADAPTER_PER_DEVICE 2
  202. struct dvb_usb_device_properties {
  203. const char *driver_name;
  204. struct module *owner;
  205. short *adapter_nr;
  206. u8 bInterfaceNumber;
  207. unsigned int size_of_priv;
  208. u8 generic_bulk_ctrl_endpoint;
  209. u8 generic_bulk_ctrl_endpoint_response;
  210. unsigned int generic_bulk_ctrl_delay;
  211. #define WARM 0
  212. #define COLD 1
  213. int (*identify_state) (struct dvb_usb_device *, const char **);
  214. const char *firmware;
  215. #define RECONNECTS_USB 1
  216. int (*download_firmware) (struct dvb_usb_device *,
  217. const struct firmware *);
  218. struct i2c_algorithm *i2c_algo;
  219. unsigned int num_adapters;
  220. int (*get_adapter_count) (struct dvb_usb_device *);
  221. struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
  222. int (*power_ctrl) (struct dvb_usb_device *, int);
  223. int (*read_config) (struct dvb_usb_device *d);
  224. int (*read_mac_address) (struct dvb_usb_adapter *, u8 []);
  225. int (*frontend_attach) (struct dvb_usb_adapter *);
  226. int (*tuner_attach) (struct dvb_usb_adapter *);
  227. int (*frontend_ctrl) (struct dvb_frontend *, int);
  228. int (*streaming_ctrl) (struct dvb_frontend *, int);
  229. int (*fe_ioctl_override) (struct dvb_frontend *,
  230. unsigned int, void *, unsigned int);
  231. int (*init) (struct dvb_usb_device *);
  232. void (*exit) (struct dvb_usb_device *);
  233. int (*get_rc_config) (struct dvb_usb_device *, struct dvb_usb_rc *);
  234. #define DVB_USB_FE_TS_TYPE_188 0
  235. #define DVB_USB_FE_TS_TYPE_204 1
  236. #define DVB_USB_FE_TS_TYPE_RAW 2
  237. int (*get_stream_config) (struct dvb_frontend *, u8 *,
  238. struct usb_data_stream_properties *);
  239. };
  240. /**
  241. * generic object of an usb stream
  242. * @buf_num: number of buffer allocated
  243. * @buf_size: size of each buffer in buf_list
  244. * @buf_list: array containing all allocate buffers for streaming
  245. * @dma_addr: list of dma_addr_t for each buffer in buf_list
  246. *
  247. * @urbs_initialized: number of URBs initialized
  248. * @urbs_submitted: number of URBs submitted
  249. */
  250. #define MAX_NO_URBS_FOR_DATA_STREAM 10
  251. struct usb_data_stream {
  252. struct usb_device *udev;
  253. struct usb_data_stream_properties props;
  254. #define USB_STATE_INIT 0x00
  255. #define USB_STATE_URB_BUF 0x01
  256. u8 state;
  257. void (*complete) (struct usb_data_stream *, u8 *, size_t);
  258. struct urb *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
  259. int buf_num;
  260. unsigned long buf_size;
  261. u8 *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
  262. dma_addr_t dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
  263. int urbs_initialized;
  264. int urbs_submitted;
  265. void *user_priv;
  266. };
  267. /**
  268. * dvb adapter object on dvb usb device
  269. * @props: pointer to adapter properties
  270. * @stream: adapter the usb data stream
  271. * @id: index of this adapter (starting with 0)
  272. * @ts_type: transport stream, input stream, type
  273. * @pid_filtering: is hardware pid_filtering used or not
  274. * @feed_count: current feed count
  275. * @max_feed_count: maimum feed count device can handle
  276. * @dvb_adap: adapter dvb_adapter
  277. * @dmxdev: adapter dmxdev
  278. * @demux: adapter software demuxer
  279. * @dvb_net: adapter dvb_net interfaces
  280. * @sync_mutex: mutex used to sync control and streaming of the adapter
  281. * @fe: adapter frontends
  282. * @fe_init: rerouted frontend-init function
  283. * @fe_sleep: rerouted frontend-sleep function
  284. */
  285. struct dvb_usb_adapter {
  286. const struct dvb_usb_adapter_properties *props;
  287. struct usb_data_stream stream;
  288. u8 id;
  289. u8 ts_type;
  290. bool pid_filtering;
  291. u8 feed_count;
  292. u8 max_feed_count;
  293. s8 active_fe;
  294. /* dvb */
  295. struct dvb_adapter dvb_adap;
  296. struct dmxdev dmxdev;
  297. struct dvb_demux demux;
  298. struct dvb_net dvb_net;
  299. struct mutex sync_mutex;
  300. struct dvb_frontend *fe[MAX_NO_OF_FE_PER_ADAP];
  301. int (*fe_init[MAX_NO_OF_FE_PER_ADAP]) (struct dvb_frontend *);
  302. int (*fe_sleep[MAX_NO_OF_FE_PER_ADAP]) (struct dvb_frontend *);
  303. };
  304. /**
  305. * dvb usb device object
  306. * @props: device properties
  307. * @name: device name
  308. * @rc_map: name of rc codes table
  309. * @udev: pointer to the device's struct usb_device
  310. * @intf: pointer to the device's usb interface
  311. * @rc: remote controller configuration
  312. * @probe_work: work to defer .probe()
  313. * @powered: indicated whether the device is power or not
  314. * @usb_mutex: mutex for usb control messages
  315. * @i2c_mutex: mutex for i2c-transfers
  316. * @i2c_adap: device's i2c-adapter
  317. * @rc_dev: rc device for the remote control
  318. * @rc_query_work: work for polling remote
  319. * @priv: private data of the actual driver (allocate by dvb usb, size defined
  320. * in size_of_priv of dvb_usb_properties).
  321. */
  322. struct dvb_usb_device {
  323. const struct dvb_usb_device_properties *props;
  324. const char *name;
  325. const char *rc_map;
  326. struct usb_device *udev;
  327. struct usb_interface *intf;
  328. struct dvb_usb_rc rc;
  329. struct work_struct probe_work;
  330. pid_t work_pid;
  331. int powered;
  332. /* locking */
  333. struct mutex usb_mutex;
  334. /* i2c */
  335. struct mutex i2c_mutex;
  336. struct i2c_adapter i2c_adap;
  337. struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
  338. /* remote control */
  339. struct rc_dev *rc_dev;
  340. char rc_phys[64];
  341. struct delayed_work rc_query_work;
  342. void *priv;
  343. };
  344. extern int dvb_usbv2_probe(struct usb_interface *,
  345. const struct usb_device_id *);
  346. extern void dvb_usbv2_disconnect(struct usb_interface *);
  347. extern int dvb_usbv2_suspend(struct usb_interface *, pm_message_t);
  348. extern int dvb_usbv2_resume(struct usb_interface *);
  349. /* the generic read/write method for device control */
  350. extern int dvb_usbv2_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16);
  351. extern int dvb_usbv2_generic_write(struct dvb_usb_device *, u8 *, u16);
  352. #endif