[media] dvb_usb_v2: implement .get_adapter_count()
[deliverable/linux.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
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"
23
24#include "dvb-pll.h"
25
26#include "dvb-usb-ids.h"
27
28/* debug */
29#ifdef CONFIG_DVB_USB_DEBUG
4e60d951
AP
30#define dprintk(var, level, args...) \
31 do { if ((var & level)) { printk(args); } } while (0)
c79b339f 32
4e60d951 33#define debug_dump(b, l, func) {\
c79b339f 34 int loop_; \
4e60d951
AP
35 for (loop_ = 0; loop_ < l; loop_++) \
36 func("%02x ", b[loop_]); \
c79b339f
AP
37 func("\n");\
38}
39#define DVB_USB_DEBUG_STATUS
40#else
41#define dprintk(args...)
4e60d951 42#define debug_dump(b, l, func)
c79b339f
AP
43
44#define DVB_USB_DEBUG_STATUS " (debugging is not enabled)"
45
46#endif
47
48/* generic log methods - taken from usb.h */
49#ifndef DVB_USB_LOG_PREFIX
50 #define DVB_USB_LOG_PREFIX "dvb-usb (please define a log prefix)"
51#endif
52
53#undef err
4e60d951
AP
54#define err(format, arg...) \
55 printk(KERN_ERR DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
c79b339f 56#undef info
4e60d951
AP
57#define info(format, arg...) \
58 printk(KERN_INFO DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
c79b339f 59#undef warn
4e60d951
AP
60#define warn(format, arg...) \
61 printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
c79b339f 62
7dfd1242 63struct dvb_usb_driver_info {
c79b339f 64 const char *name;
7dfd1242 65 const struct dvb_usb_device_properties *props;
c79b339f
AP
66};
67
68static inline u8 rc5_custom(struct rc_map_table *key)
69{
70 return (key->scancode >> 8) & 0xff;
71}
72
73static inline u8 rc5_data(struct rc_map_table *key)
74{
75 return key->scancode & 0xff;
76}
77
78static inline u16 rc5_scan(struct rc_map_table *key)
79{
80 return key->scancode & 0xffff;
81}
82
83struct dvb_usb_device;
84struct dvb_usb_adapter;
85struct usb_data_stream;
86
87/**
88 * Properties of USB streaming - TODO this structure should be somewhere else
89 * describes the kind of USB transfer used for data-streaming.
90 * (BULK or ISOC)
91 */
92struct usb_data_stream_properties {
93#define USB_BULK 1
94#define USB_ISOC 2
95 int type;
96 int count;
97 int endpoint;
98
99 union {
100 struct {
101 int buffersize; /* per URB */
102 } bulk;
103 struct {
104 int framesperurb;
105 int framesize;
106 int interval;
107 } isoc;
108 } u;
109};
110
111/**
112 * struct dvb_usb_adapter_properties - properties of a dvb-usb-adapter.
4e60d951
AP
113 * A DVB-USB-Adapter is basically a dvb_adapter which is present on a
114 * USB-device.
c79b339f
AP
115 * @caps: capabilities of the DVB USB device.
116 * @pid_filter_count: number of PID filter position in the optional hardware
117 * PID-filter.
118 * @num_frontends: number of frontends of the DVB USB adapter.
119 * @frontend_ctrl: called to power on/off active frontend.
120 * @streaming_ctrl: called to start and stop the MPEG2-TS streaming of the
121 * device (not URB submitting/killing).
122 * @pid_filter_ctrl: called to en/disable the PID filter, if any.
123 * @pid_filter: called to set/unset a PID for filtering.
124 * @frontend_attach: called to attach the possible frontends (fill fe-field
125 * of struct dvb_usb_device).
126 * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
127 * pll_desc and pll_init_buf of struct dvb_usb_device).
128 * @stream: configuration of the USB streaming
129 */
130struct dvb_usb_adapter_fe_properties {
131#define DVB_USB_ADAP_HAS_PID_FILTER 0x01
132#define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
133#define DVB_USB_ADAP_NEED_PID_FILTERING 0x04
134#define DVB_USB_ADAP_RECEIVES_204_BYTE_TS 0x08
135#define DVB_USB_ADAP_RECEIVES_RAW_PAYLOAD 0x10
136 int caps;
137 int pid_filter_count;
138
139 int (*streaming_ctrl) (struct dvb_usb_adapter *, int);
140 int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);
141 int (*pid_filter) (struct dvb_usb_adapter *, int, u16, int);
142
143 int (*frontend_attach) (struct dvb_usb_adapter *);
144 int (*tuner_attach) (struct dvb_usb_adapter *);
145
146 struct usb_data_stream_properties stream;
147
148 int size_of_priv;
149};
150
151#define MAX_NO_OF_FE_PER_ADAP 3
152struct dvb_usb_adapter_properties {
153 int size_of_priv;
154
155 int (*frontend_ctrl) (struct dvb_frontend *, int);
156 int (*fe_ioctl_override) (struct dvb_frontend *,
157 unsigned int, void *, unsigned int);
158
159 int num_frontends;
160 struct dvb_usb_adapter_fe_properties fe[MAX_NO_OF_FE_PER_ADAP];
161};
162
163/**
164 * struct dvb_rc_legacy - old properties of remote controller
165 * @rc_map_table: a hard-wired array of struct rc_map_table (NULL to disable
166 * remote control handling).
167 * @rc_map_size: number of items in @rc_map_table.
168 * @rc_query: called to query an event event.
169 * @rc_interval: time in ms between two queries.
170 */
171struct dvb_rc_legacy {
172/* remote control properties */
173#define REMOTE_NO_KEY_PRESSED 0x00
174#define REMOTE_KEY_PRESSED 0x01
175#define REMOTE_KEY_REPEAT 0x02
176 struct rc_map_table *rc_map_table;
177 int rc_map_size;
178 int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
179 int rc_interval;
180};
181
182/**
183 * struct dvb_rc properties of remote controller, using rc-core
184 * @rc_codes: name of rc codes table
185 * @protocol: type of protocol(s) currently used by the driver
186 * @allowed_protos: protocol(s) supported by the driver
187 * @driver_type: Used to point if a device supports raw mode
188 * @change_protocol: callback to change protocol
189 * @rc_query: called to query an event event.
190 * @rc_interval: time in ms between two queries.
191 * @bulk_mode: device supports bulk mode for RC (disable polling mode)
192 */
193struct dvb_rc {
194 char *rc_codes;
195 u64 protocol;
196 u64 allowed_protos;
197 enum rc_driver_type driver_type;
198 int (*change_protocol)(struct rc_dev *dev, u64 rc_type);
199 char *module_name;
200 int (*rc_query) (struct dvb_usb_device *d);
201 int rc_interval;
202 bool bulk_mode; /* uses bulk mode */
203};
204
205/**
206 * enum dvb_usb_mode - Specifies if it is using a legacy driver or a new one
207 * based on rc-core
208 * This is initialized/used only inside dvb-usb-remote.c.
209 * It shouldn't be set by the drivers.
210 */
211enum dvb_usb_mode {
212 DVB_RC_LEGACY,
213 DVB_RC_CORE,
214};
215
216/**
217 * struct dvb_usb_device_properties - properties of a dvb-usb-device
654e62dc 218 * @owner: owner of the dvb_adapter
c79b339f
AP
219 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
220 * download.
221 * @firmware: name of the firmware file.
222 * @download_firmware: called to download the firmware when the usb_ctrl is
223 * DEVICE_SPECIFIC.
224 * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
225 * so do the warm initialization right after it
226 *
227 * @size_of_priv: how many bytes shall be allocated for the private field
228 * of struct dvb_usb_device.
229 *
230 * @power_ctrl: called to enable/disable power of the device.
231 * @read_mac_address: called to read the MAC address of the device.
232 * @identify_state: called to determine the state (cold or warm), when it
233 * is not distinguishable by the USB IDs.
dc786937
AP
234 * @init: called after adapters are created in order to finalize device
235 * configuration.
c79b339f
AP
236 *
237 * @rc: remote controller properties
238 *
239 * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
240 *
241 * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
242 * endpoint which received control messages with bulk transfers. When this
243 * is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
244 * helper functions.
245 *
246 * @generic_bulk_ctrl_endpoint_response: some DVB USB devices use a separate
247 * endpoint for responses to control messages sent with bulk transfers via
248 * the generic_bulk_ctrl_endpoint. When this is non-zero, this will be used
249 * instead of the generic_bulk_ctrl_endpoint when reading usb responses in
250 * the dvb_usb_generic_rw helper function.
c79b339f
AP
251 */
252#define MAX_NO_OF_ADAPTER_PER_DEVICE 2
253struct dvb_usb_device_properties {
654e62dc 254 struct module *owner;
55b1f704 255 short *adapter_nr;
c79b339f
AP
256
257#define DVB_USB_IS_AN_I2C_ADAPTER 0x01
258 int caps;
259
260#define DEVICE_SPECIFIC 0
261#define CYPRESS_AN2135 1
262#define CYPRESS_AN2235 2
263#define CYPRESS_FX2 3
264 int usb_ctrl;
496e8278
AP
265
266#define RECONNECTS_USB 1
4e60d951
AP
267 int (*download_firmware) (struct dvb_usb_device *,
268 const struct firmware *);
8b9dff58 269 int (*get_firmware_name) (struct dvb_usb_device *, const char **);
c79b339f
AP
270
271 int size_of_priv;
272
273 int num_adapters;
5b853004 274 int (*get_adapter_count) (struct dvb_usb_device *);
c79b339f
AP
275 struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
276
277 int (*power_ctrl) (struct dvb_usb_device *, int);
278 int (*read_mac_address) (struct dvb_usb_device *, u8 []);
496e8278
AP
279
280#define WARM 0
281#define COLD 1
282 int (*identify_state) (struct dvb_usb_device *);
dc786937 283 int (*init) (struct dvb_usb_device *);
c79b339f
AP
284
285 struct {
286 enum dvb_usb_mode mode; /* Drivers shouldn't touch on it */
287 struct dvb_rc_legacy legacy;
288 struct dvb_rc core;
289 } rc;
290
291 struct i2c_algorithm *i2c_algo;
292
293 int generic_bulk_ctrl_endpoint;
294 int generic_bulk_ctrl_endpoint_response;
c79b339f
AP
295};
296
297/**
298 * struct usb_data_stream - generic object of an USB stream
299 * @buf_num: number of buffer allocated.
300 * @buf_size: size of each buffer in buf_list.
301 * @buf_list: array containing all allocate buffers for streaming.
302 * @dma_addr: list of dma_addr_t for each buffer in buf_list.
303 *
304 * @urbs_initialized: number of URBs initialized.
305 * @urbs_submitted: number of URBs submitted.
306 */
307#define MAX_NO_URBS_FOR_DATA_STREAM 10
308struct usb_data_stream {
309 struct usb_device *udev;
310 struct usb_data_stream_properties props;
311
312#define USB_STATE_INIT 0x00
313#define USB_STATE_URB_BUF 0x01
314 int state;
315
316 void (*complete) (struct usb_data_stream *, u8 *, size_t);
317
318 struct urb *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
319 int buf_num;
320 unsigned long buf_size;
321 u8 *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
322 dma_addr_t dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
323
324 int urbs_initialized;
325 int urbs_submitted;
326
327 void *user_priv;
328};
329
330/**
331 * struct dvb_usb_adapter - a DVB adapter on a USB device
332 * @id: index of this adapter (starting with 0).
333 *
334 * @feedcount: number of reqested feeds (used for streaming-activation)
335 * @pid_filtering: is hardware pid_filtering used or not.
336 *
337 * @pll_addr: I2C address of the tuner for programming
338 * @pll_init: array containing the initialization buffer
339 * @pll_desc: pointer to the appropriate struct dvb_pll_desc
4e60d951
AP
340 * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or
341 * the board
c79b339f
AP
342 *
343 * @dvb_adap: device's dvb_adapter.
344 * @dmxdev: device's dmxdev.
345 * @demux: device's software demuxer.
346 * @dvb_net: device's dvb_net interfaces.
347 * @dvb_frontend: device's frontend.
348 * @max_feed_count: how many feeds can be handled simultaneously by this
349 * device
350 *
351 * @fe_init: rerouted frontend-init (wakeup) function.
352 * @fe_sleep: rerouted frontend-sleep function.
353 *
354 * @stream: the usb data stream.
355 */
356struct dvb_usb_fe_adapter {
357 struct dvb_frontend *fe;
358
359 int (*fe_init) (struct dvb_frontend *);
360 int (*fe_sleep) (struct dvb_frontend *);
361
362 struct usb_data_stream stream;
363
364 int pid_filtering;
365 int max_feed_count;
366
367 void *priv;
368};
369
370struct dvb_usb_adapter {
371 struct dvb_usb_device *dev;
372 struct dvb_usb_adapter_properties props;
373
374#define DVB_USB_ADAP_STATE_INIT 0x000
375#define DVB_USB_ADAP_STATE_DVB 0x001
376 int state;
377
378 u8 id;
379
380 int feedcount;
381
382 /* dvb */
383 struct dvb_adapter dvb_adap;
384 struct dmxdev dmxdev;
385 struct dvb_demux demux;
386 struct dvb_net dvb_net;
387
388 struct dvb_usb_fe_adapter fe_adap[MAX_NO_OF_FE_PER_ADAP];
389 int active_fe;
390 int num_frontends_initialized;
391
392 void *priv;
393};
394
395/**
396 * struct dvb_usb_device - object of a DVB USB device
397 * @props: copy of the struct dvb_usb_properties this device belongs to.
398 * @desc: pointer to the device's struct dvb_usb_device_description.
399 * @state: initialization and runtime state of the device.
400 *
401 * @powered: indicated whether the device is power or not.
402 * Powered is in/decremented for each call to modify the state.
403 * @udev: pointer to the device's struct usb_device.
404 *
405 * @usb_mutex: semaphore of USB control messages (reading needs two messages)
406 * @i2c_mutex: semaphore for i2c-transfers
407 *
408 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
409 *
410 * @rc_dev: rc device for the remote control (rc-core mode)
411 * @input_dev: input device for the remote control (legacy mode)
412 * @rc_query_work: struct work_struct frequent rc queries
413 * @last_event: last triggered event
414 * @last_state: last state (no, pressed, repeat)
c79b339f
AP
415 * @priv: private data of the actual driver (allocate by dvb-usb, size defined
416 * in size_of_priv of dvb_usb_properties).
417 */
418struct dvb_usb_device {
419 struct dvb_usb_device_properties props;
7dfd1242 420 const char *name;
c79b339f
AP
421
422 struct usb_device *udev;
423
424#define DVB_USB_STATE_INIT 0x000
425#define DVB_USB_STATE_I2C 0x001
426#define DVB_USB_STATE_DVB 0x002
427#define DVB_USB_STATE_REMOTE 0x004
428 int state;
429
430 int powered;
431
432 /* locking */
433 struct mutex usb_mutex;
434
435 /* i2c */
436 struct mutex i2c_mutex;
437 struct i2c_adapter i2c_adap;
438
439 int num_adapters_initialized;
440 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
441
442 /* remote control */
443 struct rc_dev *rc_dev;
444 struct input_dev *input_dev;
445 char rc_phys[64];
446 struct delayed_work rc_query_work;
447 u32 last_event;
448 int last_state;
449
c79b339f
AP
450 void *priv;
451};
452
453extern int dvb_usbv2_device_init(struct usb_interface *,
55b1f704 454 const struct usb_device_id *);
c79b339f
AP
455extern void dvb_usbv2_device_exit(struct usb_interface *);
456
457/* the generic read/write method for device control */
4e60d951
AP
458extern int dvb_usbv2_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,
459 int);
c79b339f
AP
460extern int dvb_usbv2_generic_write(struct dvb_usb_device *, u8 *, u16);
461
462/* commonly used remote control parsing */
4e60d951
AP
463extern int dvb_usbv2_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *,
464 int *);
c79b339f
AP
465
466/* commonly used firmware download types and function */
467struct hexline {
468 u8 len;
469 u32 addr;
470 u8 type;
471 u8 data[255];
472 u8 chk;
473};
4e60d951
AP
474extern int usbv2_cypress_load_firmware(struct usb_device *udev,
475 const struct firmware *fw, int type);
476extern int dvb_usbv2_get_hexline(const struct firmware *fw, struct hexline *hx,
477 int *pos);
c79b339f
AP
478
479#endif
This page took 0.041999 seconds and 5 git commands to generate.