blob: 6392fd3d416478f3c44c3ff9853b373debd5d120 [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), \
Antti Palosaariacaec142012-06-12 01:34:22 -030035 .driver_info = (kernel_ulong_t) &((const struct dvb_usb_driver_info) { \
Antti Palosaari0359b5f2012-06-04 20:12:55 -030036 .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 Palosaari30249852012-05-29 16:12:17 -0300103 struct usb_data_stream_properties stream;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300104};
105
106/**
Antti Palosaaric79b3392012-05-23 10:06:09 -0300107 * struct dvb_rc properties of remote controller, using rc-core
108 * @rc_codes: name of rc codes table
109 * @protocol: type of protocol(s) currently used by the driver
110 * @allowed_protos: protocol(s) supported by the driver
111 * @driver_type: Used to point if a device supports raw mode
112 * @change_protocol: callback to change protocol
113 * @rc_query: called to query an event event.
114 * @rc_interval: time in ms between two queries.
115 * @bulk_mode: device supports bulk mode for RC (disable polling mode)
116 */
Antti Palosaari05752892012-05-26 11:43:24 -0300117struct dvb_usb_rc {
118 char *map_name;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300119 u64 allowed_protos;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300120 int (*change_protocol)(struct rc_dev *dev, u64 rc_type);
Antti Palosaari05752892012-05-26 11:43:24 -0300121 int (*query) (struct dvb_usb_device *d);
122 int interval;
123 const enum rc_driver_type driver_type;
124 bool bulk_mode;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300125};
126
127/**
Antti Palosaaric79b3392012-05-23 10:06:09 -0300128 * struct dvb_usb_device_properties - properties of a dvb-usb-device
Antti Palosaari654e62d2012-05-23 15:03:56 -0300129 * @owner: owner of the dvb_adapter
Antti Palosaaric79b3392012-05-23 10:06:09 -0300130 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
131 * download.
132 * @firmware: name of the firmware file.
133 * @download_firmware: called to download the firmware when the usb_ctrl is
134 * DEVICE_SPECIFIC.
135 * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
136 * so do the warm initialization right after it
137 *
138 * @size_of_priv: how many bytes shall be allocated for the private field
139 * of struct dvb_usb_device.
140 *
141 * @power_ctrl: called to enable/disable power of the device.
142 * @read_mac_address: called to read the MAC address of the device.
143 * @identify_state: called to determine the state (cold or warm), when it
144 * is not distinguishable by the USB IDs.
Antti Palosaaridc786932012-05-23 10:44:15 -0300145 * @init: called after adapters are created in order to finalize device
146 * configuration.
Antti Palosaaric79b3392012-05-23 10:06:09 -0300147 *
148 * @rc: remote controller properties
149 *
150 * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
151 *
152 * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
153 * endpoint which received control messages with bulk transfers. When this
154 * is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
155 * helper functions.
156 *
157 * @generic_bulk_ctrl_endpoint_response: some DVB USB devices use a separate
158 * endpoint for responses to control messages sent with bulk transfers via
159 * the generic_bulk_ctrl_endpoint. When this is non-zero, this will be used
160 * instead of the generic_bulk_ctrl_endpoint when reading usb responses in
161 * the dvb_usb_generic_rw helper function.
Antti Palosaaric79b3392012-05-23 10:06:09 -0300162 */
163#define MAX_NO_OF_ADAPTER_PER_DEVICE 2
164struct dvb_usb_device_properties {
Antti Palosaari05752892012-05-26 11:43:24 -0300165 const char *driver_name;
Antti Palosaari654e62d2012-05-23 15:03:56 -0300166 struct module *owner;
Antti Palosaari55b1f702012-05-23 16:23:44 -0300167 short *adapter_nr;
Antti Palosaari36764032012-06-07 17:34:41 -0300168 u8 bInterfaceNumber;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300169
Antti Palosaari005bc3f2012-05-25 12:28:43 -0300170 int size_of_priv;
171
172 const char *firmware;
173 int (*get_firmware_name) (struct dvb_usb_device *, const char **);
Antti Palosaari496e8272012-05-23 20:45:05 -0300174#define RECONNECTS_USB 1
Antti Palosaari4e60d952012-05-24 14:44:21 -0300175 int (*download_firmware) (struct dvb_usb_device *,
176 const struct firmware *);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300177
178 int num_adapters;
Antti Palosaari5b853002012-05-24 21:11:42 -0300179 int (*get_adapter_count) (struct dvb_usb_device *);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300180 struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
181
182 int (*power_ctrl) (struct dvb_usb_device *, int);
Antti Palosaari43402bb2012-05-24 22:18:37 -0300183 int (*read_config) (struct dvb_usb_device *d);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300184 int (*read_mac_address) (struct dvb_usb_device *, u8 []);
Antti Palosaari2d2b37c72012-06-12 01:05:20 -0300185 int (*frontend_attach) (struct dvb_usb_adapter *);
186 int (*tuner_attach) (struct dvb_usb_adapter *);
187 int (*frontend_ctrl) (struct dvb_frontend *, int);
188 int (*streaming_ctrl) (struct dvb_usb_adapter *, int);
Antti Palosaari6dca4ea2012-06-15 02:10:50 -0300189 int (*fe_ioctl_override) (struct dvb_frontend *,
190 unsigned int, void *, unsigned int);
Antti Palosaari496e8272012-05-23 20:45:05 -0300191
192#define WARM 0
193#define COLD 1
194 int (*identify_state) (struct dvb_usb_device *);
Antti Palosaaridc786932012-05-23 10:44:15 -0300195 int (*init) (struct dvb_usb_device *);
Antti Palosaari5b6a63c2012-06-10 00:46:22 -0300196 void (*disconnect) (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;
Antti Palosaarif093c382012-06-12 16:25:01 -0300272 const struct dvb_usb_adapter_properties *props;
Antti Palosaarie46c5b662012-05-29 18:05:40 -0300273 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;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300291};
292
293/**
294 * struct dvb_usb_device - object of a DVB USB device
295 * @props: copy of the struct dvb_usb_properties this device belongs to.
296 * @desc: pointer to the device's struct dvb_usb_device_description.
297 * @state: initialization and runtime state of the device.
298 *
299 * @powered: indicated whether the device is power or not.
300 * Powered is in/decremented for each call to modify the state.
301 * @udev: pointer to the device's struct usb_device.
302 *
303 * @usb_mutex: semaphore of USB control messages (reading needs two messages)
304 * @i2c_mutex: semaphore for i2c-transfers
305 *
306 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
307 *
308 * @rc_dev: rc device for the remote control (rc-core mode)
309 * @input_dev: input device for the remote control (legacy mode)
310 * @rc_query_work: struct work_struct frequent rc queries
311 * @last_event: last triggered event
312 * @last_state: last state (no, pressed, repeat)
Antti Palosaaric79b3392012-05-23 10:06:09 -0300313 * @priv: private data of the actual driver (allocate by dvb-usb, size defined
314 * in size_of_priv of dvb_usb_properties).
315 */
316struct dvb_usb_device {
Antti Palosaarif093c382012-06-12 16:25:01 -0300317 const struct dvb_usb_device_properties *props;
Antti Palosaari7dfd1242012-05-24 20:00:28 -0300318 const char *name;
Antti Palosaari64921672012-05-25 10:19:03 -0300319 const char *rc_map;
Antti Palosaari05752892012-05-26 11:43:24 -0300320 struct dvb_usb_rc rc;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300321 struct usb_device *udev;
Antti Palosaari4f208d42012-06-06 00:05:06 -0300322 struct work_struct probe_work;
Antti Palosaari3238aaf2012-06-09 21:11:28 -0300323 pid_t work_pid;
Antti Palosaari4f208d42012-06-06 00:05:06 -0300324 struct usb_interface *intf;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300325 int powered;
326
327 /* locking */
328 struct mutex usb_mutex;
329
330 /* i2c */
331 struct mutex i2c_mutex;
332 struct i2c_adapter i2c_adap;
333
Antti Palosaarie80e9af2012-06-04 22:18:34 -0300334 int num_adapters_initialized;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300335 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
336
337 /* remote control */
338 struct rc_dev *rc_dev;
339 struct input_dev *input_dev;
340 char rc_phys[64];
341 struct delayed_work rc_query_work;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300342
Antti Palosaaric79b3392012-05-23 10:06:09 -0300343 void *priv;
344};
345
Antti Palosaari6b8c8c42012-06-07 16:23:40 -0300346extern int dvb_usbv2_probe(struct usb_interface *,
Antti Palosaari55b1f702012-05-23 16:23:44 -0300347 const struct usb_device_id *);
Antti Palosaari6b8c8c42012-06-07 16:23:40 -0300348extern void dvb_usbv2_disconnect(struct usb_interface *);
Antti Palosaarief81e9e2012-06-11 17:47:04 -0300349extern int dvb_usbv2_suspend(struct usb_interface *, pm_message_t);
350extern int dvb_usbv2_resume(struct usb_interface *);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300351
352/* the generic read/write method for device control */
Antti Palosaari4e60d952012-05-24 14:44:21 -0300353extern int dvb_usbv2_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,
354 int);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300355extern int dvb_usbv2_generic_write(struct dvb_usb_device *, u8 *, u16);
356
Antti Palosaaric79b3392012-05-23 10:06:09 -0300357#endif