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