[media] dvb_usb_v2: refactor dvb_usbv2_generic_rw()
[linux-2.6-block.git] / drivers / media / dvb / dvb-usb / dvb_usb.h
CommitLineData
c79b339f
AP
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
831511bd 13#include <linux/usb/input.h>
c79b339f 14#include <linux/firmware.h>
c79b339f
AP
15#include <media/rc-core.h>
16
17#include "dvb_frontend.h"
18#include "dvb_demux.h"
19#include "dvb_net.h"
20#include "dmxdev.h"
c79b339f
AP
21#include "dvb-usb-ids.h"
22
f89f9ff8 23/* helper macros for every DVB USB driver use */
ec0dd2f2
AP
24#define adap_to_d(adap) (container_of(adap, struct dvb_usb_device, \
25 adapter[adap->id]))
f89f9ff8
AP
26#define adap_to_priv(adap) (adap_to_d(adap)->priv)
27#define fe_to_adap(fe) ((struct dvb_usb_adapter *) ((fe)->dvb->priv))
28#define fe_to_d(fe) (adap_to_d(fe_to_adap(fe)))
29#define fe_to_priv(fe) (fe_to_d(fe)->priv)
30#define d_to_priv(d) (d->priv)
31
12077a3a
AP
32#define DVB_USB_STREAM_BULK(endpoint_, count_, size_) { \
33 .type = USB_BULK, \
34 .count = count_, \
35 .endpoint = endpoint_, \
36 .u = { \
37 .bulk = { \
38 .buffersize = size_, \
39 } \
40 } \
41}
42
43#define DVB_USB_STREAM_ISOC(endpoint_, count_, frames_, size_, interval_) { \
44 .type = USB_ISOC, \
45 .count = count_, \
46 .endpoint = endpoint_, \
47 .u = { \
48 .isoc = { \
49 .framesperurb = frames_, \
50 .framesize = size_,\
51 .interval = interval_, \
52 } \
53 } \
54}
c79b339f 55
0359b5fa
AP
56#define DVB_USB_DEVICE(vend, prod, props_, name_, rc) \
57 .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
58 .idVendor = (vend), \
59 .idProduct = (prod), \
acaec14f 60 .driver_info = (kernel_ulong_t) &((const struct dvb_usb_driver_info) { \
0359b5fa
AP
61 .props = (props_), \
62 .name = (name_), \
63 .rc_map = (rc), \
64 })
65
831511bd
AP
66struct dvb_usb_device;
67struct dvb_usb_adapter;
68
12077a3a
AP
69struct dvb_usb_driver_info {
70 const char *name;
71 const char *rc_map;
72 const struct dvb_usb_device_properties *props;
73};
74
831511bd
AP
75/**
76 * struct dvb_rc properties of remote controller, using rc-core
77 * @rc_codes: name of rc codes table
78 * @protocol: type of protocol(s) currently used by the driver
79 * @allowed_protos: protocol(s) supported by the driver
80 * @driver_type: Used to point if a device supports raw mode
81 * @change_protocol: callback to change protocol
82 * @rc_query: called to query an event event.
83 * @rc_interval: time in ms between two queries.
84 * @bulk_mode: device supports bulk mode for RC (disable polling mode)
85 */
86struct dvb_usb_rc {
87 char *map_name;
88 u64 allowed_protos;
89 int (*change_protocol)(struct rc_dev *dev, u64 rc_type);
90 int (*query) (struct dvb_usb_device *d);
91 unsigned int interval;
92 const enum rc_driver_type driver_type;
93 bool bulk_mode;
94};
c79b339f
AP
95
96/**
97 * Properties of USB streaming - TODO this structure should be somewhere else
98 * describes the kind of USB transfer used for data-streaming.
99 * (BULK or ISOC)
100 */
101struct usb_data_stream_properties {
102#define USB_BULK 1
103#define USB_ISOC 2
831511bd
AP
104 u8 type;
105 u8 count;
106 u8 endpoint;
c79b339f
AP
107
108 union {
109 struct {
831511bd 110 unsigned int buffersize; /* per URB */
c79b339f
AP
111 } bulk;
112 struct {
113 int framesperurb;
114 int framesize;
115 int interval;
116 } isoc;
117 } u;
118};
119
120/**
121 * struct dvb_usb_adapter_properties - properties of a dvb-usb-adapter.
4e60d951
AP
122 * A DVB-USB-Adapter is basically a dvb_adapter which is present on a
123 * USB-device.
c79b339f
AP
124 * @caps: capabilities of the DVB USB device.
125 * @pid_filter_count: number of PID filter position in the optional hardware
126 * PID-filter.
127 * @num_frontends: number of frontends of the DVB USB adapter.
128 * @frontend_ctrl: called to power on/off active frontend.
129 * @streaming_ctrl: called to start and stop the MPEG2-TS streaming of the
130 * device (not URB submitting/killing).
131 * @pid_filter_ctrl: called to en/disable the PID filter, if any.
132 * @pid_filter: called to set/unset a PID for filtering.
133 * @frontend_attach: called to attach the possible frontends (fill fe-field
134 * of struct dvb_usb_device).
135 * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
136 * pll_desc and pll_init_buf of struct dvb_usb_device).
137 * @stream: configuration of the USB streaming
138 */
c79b339f
AP
139
140#define MAX_NO_OF_FE_PER_ADAP 3
141struct dvb_usb_adapter_properties {
e46c5b66
AP
142#define DVB_USB_ADAP_HAS_PID_FILTER 0x01
143#define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
144#define DVB_USB_ADAP_NEED_PID_FILTERING 0x04
831511bd 145 u8 caps;
c79b339f 146
831511bd 147 u8 pid_filter_count;
e46c5b66
AP
148 int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);
149 int (*pid_filter) (struct dvb_usb_adapter *, int, u16, int);
150
3024985d 151 struct usb_data_stream_properties stream;
c79b339f
AP
152};
153
c79b339f
AP
154/**
155 * struct dvb_usb_device_properties - properties of a dvb-usb-device
654e62dc 156 * @owner: owner of the dvb_adapter
c79b339f
AP
157 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
158 * download.
159 * @firmware: name of the firmware file.
160 * @download_firmware: called to download the firmware when the usb_ctrl is
161 * DEVICE_SPECIFIC.
162 * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
163 * so do the warm initialization right after it
164 *
165 * @size_of_priv: how many bytes shall be allocated for the private field
166 * of struct dvb_usb_device.
167 *
168 * @power_ctrl: called to enable/disable power of the device.
169 * @read_mac_address: called to read the MAC address of the device.
170 * @identify_state: called to determine the state (cold or warm), when it
171 * is not distinguishable by the USB IDs.
dc786937
AP
172 * @init: called after adapters are created in order to finalize device
173 * configuration.
c79b339f
AP
174 *
175 * @rc: remote controller properties
176 *
177 * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
178 *
179 * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
180 * endpoint which received control messages with bulk transfers. When this
181 * is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
182 * helper functions.
183 *
184 * @generic_bulk_ctrl_endpoint_response: some DVB USB devices use a separate
185 * endpoint for responses to control messages sent with bulk transfers via
186 * the generic_bulk_ctrl_endpoint. When this is non-zero, this will be used
187 * instead of the generic_bulk_ctrl_endpoint when reading usb responses in
188 * the dvb_usb_generic_rw helper function.
c79b339f
AP
189 */
190#define MAX_NO_OF_ADAPTER_PER_DEVICE 2
191struct dvb_usb_device_properties {
05752890 192 const char *driver_name;
654e62dc 193 struct module *owner;
55b1f704 194 short *adapter_nr;
831511bd 195
36764037 196 u8 bInterfaceNumber;
831511bd
AP
197 unsigned int size_of_priv;
198 u8 generic_bulk_ctrl_endpoint;
199 u8 generic_bulk_ctrl_endpoint_response;
1162c7b3 200 unsigned int generic_bulk_ctrl_delay;
005bc3fc 201
a0921af7
AP
202#define WARM 0
203#define COLD 1
204 int (*identify_state) (struct dvb_usb_device *, const char **);
005bc3fc 205 const char *firmware;
a0921af7 206#define RECONNECTS_USB 1
4e60d951
AP
207 int (*download_firmware) (struct dvb_usb_device *,
208 const struct firmware *);
c79b339f 209
831511bd 210 struct i2c_algorithm *i2c_algo;
c79b339f 211
831511bd
AP
212 unsigned int num_adapters;
213 struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
214 int (*get_adapter_count) (struct dvb_usb_device *);
215 int (*power_ctrl) (struct dvb_usb_device *, int);
43402bbd 216 int (*read_config) (struct dvb_usb_device *d);
ddee5694 217 int (*read_mac_address) (struct dvb_usb_adapter *, u8 []);
2d2b37c7
AP
218 int (*frontend_attach) (struct dvb_usb_adapter *);
219 int (*tuner_attach) (struct dvb_usb_adapter *);
220 int (*frontend_ctrl) (struct dvb_frontend *, int);
221 int (*streaming_ctrl) (struct dvb_usb_adapter *, int);
6dca4ea3
AP
222 int (*fe_ioctl_override) (struct dvb_frontend *,
223 unsigned int, void *, unsigned int);
dc786937 224 int (*init) (struct dvb_usb_device *);
831511bd 225 void (*exit) (struct dvb_usb_device *);
05752890 226 int (*get_rc_config) (struct dvb_usb_device *, struct dvb_usb_rc *);
b905a2a1
AP
227#define DVB_USB_FE_TS_TYPE_188 0
228#define DVB_USB_FE_TS_TYPE_204 1
229#define DVB_USB_FE_TS_TYPE_RAW 2
230 int (*get_stream_config) (struct dvb_frontend *, u8 *,
39831f09 231 struct usb_data_stream_properties *);
c79b339f
AP
232};
233
234/**
235 * struct usb_data_stream - generic object of an USB stream
236 * @buf_num: number of buffer allocated.
237 * @buf_size: size of each buffer in buf_list.
238 * @buf_list: array containing all allocate buffers for streaming.
239 * @dma_addr: list of dma_addr_t for each buffer in buf_list.
240 *
241 * @urbs_initialized: number of URBs initialized.
242 * @urbs_submitted: number of URBs submitted.
243 */
244#define MAX_NO_URBS_FOR_DATA_STREAM 10
245struct usb_data_stream {
831511bd
AP
246 struct usb_device *udev;
247 struct usb_data_stream_properties props;
c79b339f
AP
248
249#define USB_STATE_INIT 0x00
250#define USB_STATE_URB_BUF 0x01
831511bd 251 u8 state;
c79b339f
AP
252
253 void (*complete) (struct usb_data_stream *, u8 *, size_t);
254
255 struct urb *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
256 int buf_num;
257 unsigned long buf_size;
258 u8 *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
259 dma_addr_t dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
260
261 int urbs_initialized;
262 int urbs_submitted;
263
264 void *user_priv;
265};
266
267/**
268 * struct dvb_usb_adapter - a DVB adapter on a USB device
269 * @id: index of this adapter (starting with 0).
270 *
271 * @feedcount: number of reqested feeds (used for streaming-activation)
272 * @pid_filtering: is hardware pid_filtering used or not.
273 *
274 * @pll_addr: I2C address of the tuner for programming
275 * @pll_init: array containing the initialization buffer
276 * @pll_desc: pointer to the appropriate struct dvb_pll_desc
4e60d951
AP
277 * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or
278 * the board
c79b339f
AP
279 *
280 * @dvb_adap: device's dvb_adapter.
281 * @dmxdev: device's dmxdev.
282 * @demux: device's software demuxer.
283 * @dvb_net: device's dvb_net interfaces.
284 * @dvb_frontend: device's frontend.
285 * @max_feed_count: how many feeds can be handled simultaneously by this
286 * device
287 *
288 * @fe_init: rerouted frontend-init (wakeup) function.
289 * @fe_sleep: rerouted frontend-sleep function.
290 *
291 * @stream: the usb data stream.
292 */
c79b339f 293struct dvb_usb_adapter {
f093c388 294 const struct dvb_usb_adapter_properties *props;
e46c5b66 295 struct usb_data_stream stream;
831511bd 296 u8 id;
b905a2a1 297 u8 ts_type;
831511bd
AP
298 bool pid_filtering;
299 u8 feed_count;
300 u8 max_feed_count;
301 s8 active_fe;
191f79a4 302
c79b339f
AP
303 /* dvb */
304 struct dvb_adapter dvb_adap;
305 struct dmxdev dmxdev;
306 struct dvb_demux demux;
307 struct dvb_net dvb_net;
831511bd 308 struct mutex sync_mutex;
c79b339f 309
20bb9cc4
AP
310 struct dvb_frontend *fe[MAX_NO_OF_FE_PER_ADAP];
311 int (*fe_init[MAX_NO_OF_FE_PER_ADAP]) (struct dvb_frontend *);
312 int (*fe_sleep[MAX_NO_OF_FE_PER_ADAP]) (struct dvb_frontend *);
c79b339f
AP
313};
314
315/**
316 * struct dvb_usb_device - object of a DVB USB device
317 * @props: copy of the struct dvb_usb_properties this device belongs to.
318 * @desc: pointer to the device's struct dvb_usb_device_description.
319 * @state: initialization and runtime state of the device.
320 *
321 * @powered: indicated whether the device is power or not.
322 * Powered is in/decremented for each call to modify the state.
323 * @udev: pointer to the device's struct usb_device.
324 *
325 * @usb_mutex: semaphore of USB control messages (reading needs two messages)
326 * @i2c_mutex: semaphore for i2c-transfers
327 *
328 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
329 *
330 * @rc_dev: rc device for the remote control (rc-core mode)
331 * @input_dev: input device for the remote control (legacy mode)
332 * @rc_query_work: struct work_struct frequent rc queries
333 * @last_event: last triggered event
334 * @last_state: last state (no, pressed, repeat)
c79b339f
AP
335 * @priv: private data of the actual driver (allocate by dvb-usb, size defined
336 * in size_of_priv of dvb_usb_properties).
337 */
338struct dvb_usb_device {
f093c388 339 const struct dvb_usb_device_properties *props;
7dfd1242 340 const char *name;
64921670 341 const char *rc_map;
831511bd 342
c79b339f 343 struct usb_device *udev;
831511bd
AP
344 struct usb_interface *intf;
345 struct dvb_usb_rc rc;
4f208d4e 346 struct work_struct probe_work;
3238aafb 347 pid_t work_pid;
c79b339f
AP
348 int powered;
349
350 /* locking */
351 struct mutex usb_mutex;
352
353 /* i2c */
354 struct mutex i2c_mutex;
355 struct i2c_adapter i2c_adap;
356
c79b339f
AP
357 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
358
359 /* remote control */
360 struct rc_dev *rc_dev;
361 struct input_dev *input_dev;
362 char rc_phys[64];
363 struct delayed_work rc_query_work;
c79b339f 364
c79b339f
AP
365 void *priv;
366};
367
6b8c8c40 368extern int dvb_usbv2_probe(struct usb_interface *,
55b1f704 369 const struct usb_device_id *);
6b8c8c40 370extern void dvb_usbv2_disconnect(struct usb_interface *);
ef81e9eb
AP
371extern int dvb_usbv2_suspend(struct usb_interface *, pm_message_t);
372extern int dvb_usbv2_resume(struct usb_interface *);
c79b339f
AP
373
374/* the generic read/write method for device control */
1162c7b3 375extern int dvb_usbv2_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16);
c79b339f
AP
376extern int dvb_usbv2_generic_write(struct dvb_usb_device *, u8 *, u16);
377
c79b339f 378#endif