blob: e67333b4a72689c710ae8afebe6e3dddd8897a68 [file] [log] [blame]
Antti Palosaaric79b3392012-05-23 10:06:09 -03001/* 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
13#include <linux/input.h>
14#include <linux/usb.h>
15#include <linux/firmware.h>
16#include <linux/mutex.h>
17#include <media/rc-core.h>
18
19#include "dvb_frontend.h"
20#include "dvb_demux.h"
21#include "dvb_net.h"
22#include "dmxdev.h"
Antti Palosaaric79b3392012-05-23 10:06:09 -030023#include "dvb-usb-ids.h"
24
Antti Palosaari7dfd1242012-05-24 20:00:28 -030025struct dvb_usb_driver_info {
Antti Palosaaric79b3392012-05-23 10:06:09 -030026 const char *name;
Antti Palosaari64921672012-05-25 10:19:03 -030027 const char *rc_map;
Antti Palosaari7dfd1242012-05-24 20:00:28 -030028 const struct dvb_usb_device_properties *props;
Antti Palosaaric79b3392012-05-23 10:06:09 -030029};
30
Antti Palosaari0359b5f2012-06-04 20:12:55 -030031#define DVB_USB_DEVICE(vend, prod, props_, name_, rc) \
32 .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
33 .idVendor = (vend), \
34 .idProduct = (prod), \
35 .driver_info = (kernel_ulong_t) &((struct dvb_usb_driver_info) { \
36 .props = (props_), \
37 .name = (name_), \
38 .rc_map = (rc), \
39 })
40
Antti Palosaaric79b3392012-05-23 10:06:09 -030041struct dvb_usb_device;
42struct dvb_usb_adapter;
43struct usb_data_stream;
44
45/**
46 * Properties of USB streaming - TODO this structure should be somewhere else
47 * describes the kind of USB transfer used for data-streaming.
48 * (BULK or ISOC)
49 */
50struct usb_data_stream_properties {
51#define USB_BULK 1
52#define USB_ISOC 2
53 int type;
54 int count;
55 int endpoint;
56
57 union {
58 struct {
59 int buffersize; /* per URB */
60 } bulk;
61 struct {
62 int framesperurb;
63 int framesize;
64 int interval;
65 } isoc;
66 } u;
67};
68
69/**
70 * struct dvb_usb_adapter_properties - properties of a dvb-usb-adapter.
Antti Palosaari4e60d952012-05-24 14:44:21 -030071 * A DVB-USB-Adapter is basically a dvb_adapter which is present on a
72 * USB-device.
Antti Palosaaric79b3392012-05-23 10:06:09 -030073 * @caps: capabilities of the DVB USB device.
74 * @pid_filter_count: number of PID filter position in the optional hardware
75 * PID-filter.
76 * @num_frontends: number of frontends of the DVB USB adapter.
77 * @frontend_ctrl: called to power on/off active frontend.
78 * @streaming_ctrl: called to start and stop the MPEG2-TS streaming of the
79 * device (not URB submitting/killing).
80 * @pid_filter_ctrl: called to en/disable the PID filter, if any.
81 * @pid_filter: called to set/unset a PID for filtering.
82 * @frontend_attach: called to attach the possible frontends (fill fe-field
83 * of struct dvb_usb_device).
84 * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
85 * pll_desc and pll_init_buf of struct dvb_usb_device).
86 * @stream: configuration of the USB streaming
87 */
Antti Palosaaric79b3392012-05-23 10:06:09 -030088
89#define MAX_NO_OF_FE_PER_ADAP 3
90struct dvb_usb_adapter_properties {
Antti Palosaarie46c5b662012-05-29 18:05:40 -030091#define DVB_USB_ADAP_HAS_PID_FILTER 0x01
92#define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
93#define DVB_USB_ADAP_NEED_PID_FILTERING 0x04
94#define DVB_USB_ADAP_RECEIVES_204_BYTE_TS 0x08
95#define DVB_USB_ADAP_RECEIVES_RAW_PAYLOAD 0x10
96 int caps;
Antti Palosaaric79b3392012-05-23 10:06:09 -030097 int size_of_priv;
98
Antti Palosaarie46c5b662012-05-29 18:05:40 -030099 int pid_filter_count;
100 int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);
101 int (*pid_filter) (struct dvb_usb_adapter *, int, u16, int);
102
Antti Palosaarifec88df2012-05-29 20:30:05 -0300103 int (*frontend_attach) (struct dvb_usb_adapter *);
104 int (*tuner_attach) (struct dvb_usb_adapter *);
105 int (*frontend_ctrl) (struct dvb_frontend *, int);
106 int (*streaming_ctrl) (struct dvb_usb_adapter *, int);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300107 int (*fe_ioctl_override) (struct dvb_frontend *,
Antti Palosaarifec88df2012-05-29 20:30:05 -0300108 unsigned int, void *, unsigned int);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300109
Antti Palosaari30249852012-05-29 16:12:17 -0300110 struct usb_data_stream_properties stream;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300111};
112
113/**
Antti Palosaaric79b3392012-05-23 10:06:09 -0300114 * struct dvb_rc properties of remote controller, using rc-core
115 * @rc_codes: name of rc codes table
116 * @protocol: type of protocol(s) currently used by the driver
117 * @allowed_protos: protocol(s) supported by the driver
118 * @driver_type: Used to point if a device supports raw mode
119 * @change_protocol: callback to change protocol
120 * @rc_query: called to query an event event.
121 * @rc_interval: time in ms between two queries.
122 * @bulk_mode: device supports bulk mode for RC (disable polling mode)
123 */
Antti Palosaari05752892012-05-26 11:43:24 -0300124struct dvb_usb_rc {
125 char *map_name;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300126 u64 allowed_protos;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300127 int (*change_protocol)(struct rc_dev *dev, u64 rc_type);
Antti Palosaari05752892012-05-26 11:43:24 -0300128 int (*query) (struct dvb_usb_device *d);
129 int interval;
130 const enum rc_driver_type driver_type;
131 bool bulk_mode;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300132};
133
134/**
Antti Palosaaric79b3392012-05-23 10:06:09 -0300135 * struct dvb_usb_device_properties - properties of a dvb-usb-device
Antti Palosaari654e62d2012-05-23 15:03:56 -0300136 * @owner: owner of the dvb_adapter
Antti Palosaaric79b3392012-05-23 10:06:09 -0300137 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
138 * download.
139 * @firmware: name of the firmware file.
140 * @download_firmware: called to download the firmware when the usb_ctrl is
141 * DEVICE_SPECIFIC.
142 * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
143 * so do the warm initialization right after it
144 *
145 * @size_of_priv: how many bytes shall be allocated for the private field
146 * of struct dvb_usb_device.
147 *
148 * @power_ctrl: called to enable/disable power of the device.
149 * @read_mac_address: called to read the MAC address of the device.
150 * @identify_state: called to determine the state (cold or warm), when it
151 * is not distinguishable by the USB IDs.
Antti Palosaaridc786932012-05-23 10:44:15 -0300152 * @init: called after adapters are created in order to finalize device
153 * configuration.
Antti Palosaaric79b3392012-05-23 10:06:09 -0300154 *
155 * @rc: remote controller properties
156 *
157 * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
158 *
159 * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
160 * endpoint which received control messages with bulk transfers. When this
161 * is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
162 * helper functions.
163 *
164 * @generic_bulk_ctrl_endpoint_response: some DVB USB devices use a separate
165 * endpoint for responses to control messages sent with bulk transfers via
166 * the generic_bulk_ctrl_endpoint. When this is non-zero, this will be used
167 * instead of the generic_bulk_ctrl_endpoint when reading usb responses in
168 * the dvb_usb_generic_rw helper function.
Antti Palosaaric79b3392012-05-23 10:06:09 -0300169 */
170#define MAX_NO_OF_ADAPTER_PER_DEVICE 2
171struct dvb_usb_device_properties {
Antti Palosaari05752892012-05-26 11:43:24 -0300172 const char *driver_name;
Antti Palosaari654e62d2012-05-23 15:03:56 -0300173 struct module *owner;
Antti Palosaari55b1f702012-05-23 16:23:44 -0300174 short *adapter_nr;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300175
Antti Palosaari005bc3f2012-05-25 12:28:43 -0300176 int size_of_priv;
177
178 const char *firmware;
179 int (*get_firmware_name) (struct dvb_usb_device *, const char **);
Antti Palosaari496e8272012-05-23 20:45:05 -0300180#define RECONNECTS_USB 1
Antti Palosaari4e60d952012-05-24 14:44:21 -0300181 int (*download_firmware) (struct dvb_usb_device *,
182 const struct firmware *);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300183
184 int num_adapters;
Antti Palosaari5b853002012-05-24 21:11:42 -0300185 int (*get_adapter_count) (struct dvb_usb_device *);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300186 struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
187
188 int (*power_ctrl) (struct dvb_usb_device *, int);
Antti Palosaari43402bb2012-05-24 22:18:37 -0300189 int (*read_config) (struct dvb_usb_device *d);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300190 int (*read_mac_address) (struct dvb_usb_device *, u8 []);
Antti Palosaari05752892012-05-26 11:43:24 -0300191 int (*tuner_attach) (struct dvb_frontend *);
Antti Palosaari496e8272012-05-23 20:45:05 -0300192
193#define WARM 0
194#define COLD 1
195 int (*identify_state) (struct dvb_usb_device *);
Antti Palosaaridc786932012-05-23 10:44:15 -0300196 int (*init) (struct dvb_usb_device *);
Antti Palosaari05752892012-05-26 11:43:24 -0300197 int (*get_rc_config) (struct dvb_usb_device *, struct dvb_usb_rc *);
Antti Palosaari39831f02012-05-28 21:28:01 -0300198 int (*get_usb_stream_config) (struct dvb_frontend *,
199 struct usb_data_stream_properties *);
Antti Palosaarib6ecf8b2012-05-29 12:17:20 -0300200 int (*get_ts_config) (struct dvb_frontend *, unsigned int *);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300201
Antti Palosaaric79b3392012-05-23 10:06:09 -0300202 struct i2c_algorithm *i2c_algo;
203
204 int generic_bulk_ctrl_endpoint;
205 int generic_bulk_ctrl_endpoint_response;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300206};
207
208/**
209 * struct usb_data_stream - generic object of an USB stream
210 * @buf_num: number of buffer allocated.
211 * @buf_size: size of each buffer in buf_list.
212 * @buf_list: array containing all allocate buffers for streaming.
213 * @dma_addr: list of dma_addr_t for each buffer in buf_list.
214 *
215 * @urbs_initialized: number of URBs initialized.
216 * @urbs_submitted: number of URBs submitted.
217 */
218#define MAX_NO_URBS_FOR_DATA_STREAM 10
219struct usb_data_stream {
220 struct usb_device *udev;
221 struct usb_data_stream_properties props;
222
223#define USB_STATE_INIT 0x00
224#define USB_STATE_URB_BUF 0x01
225 int state;
226
227 void (*complete) (struct usb_data_stream *, u8 *, size_t);
228
229 struct urb *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
230 int buf_num;
231 unsigned long buf_size;
232 u8 *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
233 dma_addr_t dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
234
235 int urbs_initialized;
236 int urbs_submitted;
237
238 void *user_priv;
239};
240
241/**
242 * struct dvb_usb_adapter - a DVB adapter on a USB device
243 * @id: index of this adapter (starting with 0).
244 *
245 * @feedcount: number of reqested feeds (used for streaming-activation)
246 * @pid_filtering: is hardware pid_filtering used or not.
247 *
248 * @pll_addr: I2C address of the tuner for programming
249 * @pll_init: array containing the initialization buffer
250 * @pll_desc: pointer to the appropriate struct dvb_pll_desc
Antti Palosaari4e60d952012-05-24 14:44:21 -0300251 * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or
252 * the board
Antti Palosaaric79b3392012-05-23 10:06:09 -0300253 *
254 * @dvb_adap: device's dvb_adapter.
255 * @dmxdev: device's dmxdev.
256 * @demux: device's software demuxer.
257 * @dvb_net: device's dvb_net interfaces.
258 * @dvb_frontend: device's frontend.
259 * @max_feed_count: how many feeds can be handled simultaneously by this
260 * device
261 *
262 * @fe_init: rerouted frontend-init (wakeup) function.
263 * @fe_sleep: rerouted frontend-sleep function.
264 *
265 * @stream: the usb data stream.
266 */
Antti Palosaaric79b3392012-05-23 10:06:09 -0300267struct dvb_usb_adapter {
Antti Palosaaric79b3392012-05-23 10:06:09 -0300268#define DVB_USB_ADAP_STATE_INIT 0x000
269#define DVB_USB_ADAP_STATE_DVB 0x001
270 int state;
Antti Palosaarie46c5b662012-05-29 18:05:40 -0300271 struct dvb_usb_device *dev;
272 struct dvb_usb_adapter_properties props;
273 struct usb_data_stream stream;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300274 u8 id;
275
Antti Palosaarie46c5b662012-05-29 18:05:40 -0300276 int pid_filtering;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300277 int feedcount;
Antti Palosaarie46c5b662012-05-29 18:05:40 -0300278 int max_feed_count;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300279
280 /* dvb */
281 struct dvb_adapter dvb_adap;
282 struct dmxdev dmxdev;
283 struct dvb_demux demux;
284 struct dvb_net dvb_net;
285
Antti Palosaari20bb9cc2012-05-29 22:20:24 -0300286 struct dvb_frontend *fe[MAX_NO_OF_FE_PER_ADAP];
287 int (*fe_init[MAX_NO_OF_FE_PER_ADAP]) (struct dvb_frontend *);
288 int (*fe_sleep[MAX_NO_OF_FE_PER_ADAP]) (struct dvb_frontend *);
289
Antti Palosaaric79b3392012-05-23 10:06:09 -0300290 int active_fe;
291 int num_frontends_initialized;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300292};
293
294/**
295 * struct dvb_usb_device - object of a DVB USB device
296 * @props: copy of the struct dvb_usb_properties this device belongs to.
297 * @desc: pointer to the device's struct dvb_usb_device_description.
298 * @state: initialization and runtime state of the device.
299 *
300 * @powered: indicated whether the device is power or not.
301 * Powered is in/decremented for each call to modify the state.
302 * @udev: pointer to the device's struct usb_device.
303 *
304 * @usb_mutex: semaphore of USB control messages (reading needs two messages)
305 * @i2c_mutex: semaphore for i2c-transfers
306 *
307 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
308 *
309 * @rc_dev: rc device for the remote control (rc-core mode)
310 * @input_dev: input device for the remote control (legacy mode)
311 * @rc_query_work: struct work_struct frequent rc queries
312 * @last_event: last triggered event
313 * @last_state: last state (no, pressed, repeat)
Antti Palosaaric79b3392012-05-23 10:06:09 -0300314 * @priv: private data of the actual driver (allocate by dvb-usb, size defined
315 * in size_of_priv of dvb_usb_properties).
316 */
317struct dvb_usb_device {
318 struct dvb_usb_device_properties props;
Antti Palosaari7dfd1242012-05-24 20:00:28 -0300319 const char *name;
Antti Palosaari64921672012-05-25 10:19:03 -0300320 const char *rc_map;
Antti Palosaari05752892012-05-26 11:43:24 -0300321 struct dvb_usb_rc rc;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300322 struct usb_device *udev;
Antti Palosaari4f208d42012-06-06 00:05:06 -0300323 struct work_struct probe_work;
324 struct usb_interface *intf;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300325
326#define DVB_USB_STATE_INIT 0x000
327#define DVB_USB_STATE_I2C 0x001
328#define DVB_USB_STATE_DVB 0x002
329#define DVB_USB_STATE_REMOTE 0x004
330 int state;
331
332 int powered;
333
334 /* locking */
335 struct mutex usb_mutex;
336
337 /* i2c */
338 struct mutex i2c_mutex;
339 struct i2c_adapter i2c_adap;
340
Antti Palosaarie80e9af2012-06-04 22:18:34 -0300341 int num_adapters_initialized;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300342 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
343
344 /* remote control */
345 struct rc_dev *rc_dev;
346 struct input_dev *input_dev;
347 char rc_phys[64];
348 struct delayed_work rc_query_work;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300349
Antti Palosaaric79b3392012-05-23 10:06:09 -0300350 void *priv;
351};
352
Antti Palosaari6b8c8c42012-06-07 16:23:40 -0300353extern int dvb_usbv2_probe(struct usb_interface *,
Antti Palosaari55b1f702012-05-23 16:23:44 -0300354 const struct usb_device_id *);
Antti Palosaari6b8c8c42012-06-07 16:23:40 -0300355extern void dvb_usbv2_disconnect(struct usb_interface *);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300356
357/* the generic read/write method for device control */
Antti Palosaari4e60d952012-05-24 14:44:21 -0300358extern int dvb_usbv2_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,
359 int);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300360extern int dvb_usbv2_generic_write(struct dvb_usb_device *, u8 *, u16);
361
Antti Palosaaric79b3392012-05-23 10:06:09 -0300362#endif