blob: 49df6fbeb1ad1c9b1fc6b88992f18e5e95dfb9aa [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
Antti Palosaari7dfd1242012-05-24 20:00:28 -030063struct dvb_usb_driver_info {
Antti Palosaaric79b3392012-05-23 10:06:09 -030064 const char *name;
Antti Palosaari64921672012-05-25 10:19:03 -030065 const char *rc_map;
Antti Palosaari7dfd1242012-05-24 20:00:28 -030066 const struct dvb_usb_device_properties *props;
Antti Palosaaric79b3392012-05-23 10:06:09 -030067};
68
Antti Palosaaric79b3392012-05-23 10:06:09 -030069struct dvb_usb_device;
70struct dvb_usb_adapter;
71struct usb_data_stream;
72
73/**
74 * Properties of USB streaming - TODO this structure should be somewhere else
75 * describes the kind of USB transfer used for data-streaming.
76 * (BULK or ISOC)
77 */
78struct usb_data_stream_properties {
79#define USB_BULK 1
80#define USB_ISOC 2
81 int type;
82 int count;
83 int endpoint;
84
85 union {
86 struct {
87 int buffersize; /* per URB */
88 } bulk;
89 struct {
90 int framesperurb;
91 int framesize;
92 int interval;
93 } isoc;
94 } u;
95};
96
97/**
98 * struct dvb_usb_adapter_properties - properties of a dvb-usb-adapter.
Antti Palosaari4e60d952012-05-24 14:44:21 -030099 * A DVB-USB-Adapter is basically a dvb_adapter which is present on a
100 * USB-device.
Antti Palosaaric79b3392012-05-23 10:06:09 -0300101 * @caps: capabilities of the DVB USB device.
102 * @pid_filter_count: number of PID filter position in the optional hardware
103 * PID-filter.
104 * @num_frontends: number of frontends of the DVB USB adapter.
105 * @frontend_ctrl: called to power on/off active frontend.
106 * @streaming_ctrl: called to start and stop the MPEG2-TS streaming of the
107 * device (not URB submitting/killing).
108 * @pid_filter_ctrl: called to en/disable the PID filter, if any.
109 * @pid_filter: called to set/unset a PID for filtering.
110 * @frontend_attach: called to attach the possible frontends (fill fe-field
111 * of struct dvb_usb_device).
112 * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
113 * pll_desc and pll_init_buf of struct dvb_usb_device).
114 * @stream: configuration of the USB streaming
115 */
116struct dvb_usb_adapter_fe_properties {
117#define DVB_USB_ADAP_HAS_PID_FILTER 0x01
118#define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
119#define DVB_USB_ADAP_NEED_PID_FILTERING 0x04
120#define DVB_USB_ADAP_RECEIVES_204_BYTE_TS 0x08
121#define DVB_USB_ADAP_RECEIVES_RAW_PAYLOAD 0x10
122 int caps;
123 int pid_filter_count;
124
125 int (*streaming_ctrl) (struct dvb_usb_adapter *, int);
126 int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);
127 int (*pid_filter) (struct dvb_usb_adapter *, int, u16, int);
128
129 int (*frontend_attach) (struct dvb_usb_adapter *);
130 int (*tuner_attach) (struct dvb_usb_adapter *);
131
132 struct usb_data_stream_properties stream;
133
134 int size_of_priv;
135};
136
137#define MAX_NO_OF_FE_PER_ADAP 3
138struct dvb_usb_adapter_properties {
139 int size_of_priv;
140
141 int (*frontend_ctrl) (struct dvb_frontend *, int);
142 int (*fe_ioctl_override) (struct dvb_frontend *,
143 unsigned int, void *, unsigned int);
144
145 int num_frontends;
146 struct dvb_usb_adapter_fe_properties fe[MAX_NO_OF_FE_PER_ADAP];
147};
148
149/**
Antti Palosaaric79b3392012-05-23 10:06:09 -0300150 * struct dvb_rc properties of remote controller, using rc-core
151 * @rc_codes: name of rc codes table
152 * @protocol: type of protocol(s) currently used by the driver
153 * @allowed_protos: protocol(s) supported by the driver
154 * @driver_type: Used to point if a device supports raw mode
155 * @change_protocol: callback to change protocol
156 * @rc_query: called to query an event event.
157 * @rc_interval: time in ms between two queries.
158 * @bulk_mode: device supports bulk mode for RC (disable polling mode)
159 */
Antti Palosaari05752892012-05-26 11:43:24 -0300160struct dvb_usb_rc {
161 char *map_name;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300162 u64 allowed_protos;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300163 int (*change_protocol)(struct rc_dev *dev, u64 rc_type);
Antti Palosaari05752892012-05-26 11:43:24 -0300164 int (*query) (struct dvb_usb_device *d);
165 int interval;
166 const enum rc_driver_type driver_type;
167 bool bulk_mode;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300168};
169
170/**
Antti Palosaaric79b3392012-05-23 10:06:09 -0300171 * struct dvb_usb_device_properties - properties of a dvb-usb-device
Antti Palosaari654e62d2012-05-23 15:03:56 -0300172 * @owner: owner of the dvb_adapter
Antti Palosaaric79b3392012-05-23 10:06:09 -0300173 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
174 * download.
175 * @firmware: name of the firmware file.
176 * @download_firmware: called to download the firmware when the usb_ctrl is
177 * DEVICE_SPECIFIC.
178 * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
179 * so do the warm initialization right after it
180 *
181 * @size_of_priv: how many bytes shall be allocated for the private field
182 * of struct dvb_usb_device.
183 *
184 * @power_ctrl: called to enable/disable power of the device.
185 * @read_mac_address: called to read the MAC address of the device.
186 * @identify_state: called to determine the state (cold or warm), when it
187 * is not distinguishable by the USB IDs.
Antti Palosaaridc786932012-05-23 10:44:15 -0300188 * @init: called after adapters are created in order to finalize device
189 * configuration.
Antti Palosaaric79b3392012-05-23 10:06:09 -0300190 *
191 * @rc: remote controller properties
192 *
193 * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
194 *
195 * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
196 * endpoint which received control messages with bulk transfers. When this
197 * is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
198 * helper functions.
199 *
200 * @generic_bulk_ctrl_endpoint_response: some DVB USB devices use a separate
201 * endpoint for responses to control messages sent with bulk transfers via
202 * the generic_bulk_ctrl_endpoint. When this is non-zero, this will be used
203 * instead of the generic_bulk_ctrl_endpoint when reading usb responses in
204 * the dvb_usb_generic_rw helper function.
Antti Palosaaric79b3392012-05-23 10:06:09 -0300205 */
206#define MAX_NO_OF_ADAPTER_PER_DEVICE 2
207struct dvb_usb_device_properties {
Antti Palosaari05752892012-05-26 11:43:24 -0300208 const char *driver_name;
Antti Palosaari654e62d2012-05-23 15:03:56 -0300209 struct module *owner;
Antti Palosaari55b1f702012-05-23 16:23:44 -0300210 short *adapter_nr;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300211
212#define DVB_USB_IS_AN_I2C_ADAPTER 0x01
213 int caps;
214
215#define DEVICE_SPECIFIC 0
216#define CYPRESS_AN2135 1
217#define CYPRESS_AN2235 2
218#define CYPRESS_FX2 3
219 int usb_ctrl;
Antti Palosaari496e8272012-05-23 20:45:05 -0300220
Antti Palosaari005bc3f2012-05-25 12:28:43 -0300221 int size_of_priv;
222
223 const char *firmware;
224 int (*get_firmware_name) (struct dvb_usb_device *, const char **);
Antti Palosaari496e8272012-05-23 20:45:05 -0300225#define RECONNECTS_USB 1
Antti Palosaari4e60d952012-05-24 14:44:21 -0300226 int (*download_firmware) (struct dvb_usb_device *,
227 const struct firmware *);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300228
229 int num_adapters;
Antti Palosaari5b853002012-05-24 21:11:42 -0300230 int (*get_adapter_count) (struct dvb_usb_device *);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300231 struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
232
233 int (*power_ctrl) (struct dvb_usb_device *, int);
Antti Palosaari43402bb2012-05-24 22:18:37 -0300234 int (*read_config) (struct dvb_usb_device *d);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300235 int (*read_mac_address) (struct dvb_usb_device *, u8 []);
Antti Palosaari05752892012-05-26 11:43:24 -0300236 int (*tuner_attach) (struct dvb_frontend *);
Antti Palosaari496e8272012-05-23 20:45:05 -0300237
238#define WARM 0
239#define COLD 1
240 int (*identify_state) (struct dvb_usb_device *);
Antti Palosaaridc786932012-05-23 10:44:15 -0300241 int (*init) (struct dvb_usb_device *);
Antti Palosaari05752892012-05-26 11:43:24 -0300242 int (*get_rc_config) (struct dvb_usb_device *, struct dvb_usb_rc *);
Antti Palosaari39831f02012-05-28 21:28:01 -0300243 int (*get_usb_stream_config) (struct dvb_frontend *,
244 struct usb_data_stream_properties *);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300245
Antti Palosaaric79b3392012-05-23 10:06:09 -0300246 struct i2c_algorithm *i2c_algo;
247
248 int generic_bulk_ctrl_endpoint;
249 int generic_bulk_ctrl_endpoint_response;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300250};
251
252/**
253 * struct usb_data_stream - generic object of an USB stream
254 * @buf_num: number of buffer allocated.
255 * @buf_size: size of each buffer in buf_list.
256 * @buf_list: array containing all allocate buffers for streaming.
257 * @dma_addr: list of dma_addr_t for each buffer in buf_list.
258 *
259 * @urbs_initialized: number of URBs initialized.
260 * @urbs_submitted: number of URBs submitted.
261 */
262#define MAX_NO_URBS_FOR_DATA_STREAM 10
263struct usb_data_stream {
264 struct usb_device *udev;
265 struct usb_data_stream_properties props;
266
267#define USB_STATE_INIT 0x00
268#define USB_STATE_URB_BUF 0x01
269 int state;
270
271 void (*complete) (struct usb_data_stream *, u8 *, size_t);
272
273 struct urb *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
274 int buf_num;
275 unsigned long buf_size;
276 u8 *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
277 dma_addr_t dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
278
279 int urbs_initialized;
280 int urbs_submitted;
281
282 void *user_priv;
283};
284
285/**
286 * struct dvb_usb_adapter - a DVB adapter on a USB device
287 * @id: index of this adapter (starting with 0).
288 *
289 * @feedcount: number of reqested feeds (used for streaming-activation)
290 * @pid_filtering: is hardware pid_filtering used or not.
291 *
292 * @pll_addr: I2C address of the tuner for programming
293 * @pll_init: array containing the initialization buffer
294 * @pll_desc: pointer to the appropriate struct dvb_pll_desc
Antti Palosaari4e60d952012-05-24 14:44:21 -0300295 * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or
296 * the board
Antti Palosaaric79b3392012-05-23 10:06:09 -0300297 *
298 * @dvb_adap: device's dvb_adapter.
299 * @dmxdev: device's dmxdev.
300 * @demux: device's software demuxer.
301 * @dvb_net: device's dvb_net interfaces.
302 * @dvb_frontend: device's frontend.
303 * @max_feed_count: how many feeds can be handled simultaneously by this
304 * device
305 *
306 * @fe_init: rerouted frontend-init (wakeup) function.
307 * @fe_sleep: rerouted frontend-sleep function.
308 *
309 * @stream: the usb data stream.
310 */
311struct dvb_usb_fe_adapter {
312 struct dvb_frontend *fe;
313
314 int (*fe_init) (struct dvb_frontend *);
315 int (*fe_sleep) (struct dvb_frontend *);
316
317 struct usb_data_stream stream;
318
319 int pid_filtering;
320 int max_feed_count;
321
322 void *priv;
323};
324
325struct dvb_usb_adapter {
326 struct dvb_usb_device *dev;
327 struct dvb_usb_adapter_properties props;
328
329#define DVB_USB_ADAP_STATE_INIT 0x000
330#define DVB_USB_ADAP_STATE_DVB 0x001
331 int state;
332
333 u8 id;
334
335 int feedcount;
336
337 /* dvb */
338 struct dvb_adapter dvb_adap;
339 struct dmxdev dmxdev;
340 struct dvb_demux demux;
341 struct dvb_net dvb_net;
342
343 struct dvb_usb_fe_adapter fe_adap[MAX_NO_OF_FE_PER_ADAP];
344 int active_fe;
345 int num_frontends_initialized;
346
347 void *priv;
348};
349
350/**
351 * struct dvb_usb_device - object of a DVB USB device
352 * @props: copy of the struct dvb_usb_properties this device belongs to.
353 * @desc: pointer to the device's struct dvb_usb_device_description.
354 * @state: initialization and runtime state of the device.
355 *
356 * @powered: indicated whether the device is power or not.
357 * Powered is in/decremented for each call to modify the state.
358 * @udev: pointer to the device's struct usb_device.
359 *
360 * @usb_mutex: semaphore of USB control messages (reading needs two messages)
361 * @i2c_mutex: semaphore for i2c-transfers
362 *
363 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
364 *
365 * @rc_dev: rc device for the remote control (rc-core mode)
366 * @input_dev: input device for the remote control (legacy mode)
367 * @rc_query_work: struct work_struct frequent rc queries
368 * @last_event: last triggered event
369 * @last_state: last state (no, pressed, repeat)
Antti Palosaaric79b3392012-05-23 10:06:09 -0300370 * @priv: private data of the actual driver (allocate by dvb-usb, size defined
371 * in size_of_priv of dvb_usb_properties).
372 */
373struct dvb_usb_device {
374 struct dvb_usb_device_properties props;
Antti Palosaari7dfd1242012-05-24 20:00:28 -0300375 const char *name;
Antti Palosaari64921672012-05-25 10:19:03 -0300376 const char *rc_map;
Antti Palosaari05752892012-05-26 11:43:24 -0300377 struct dvb_usb_rc rc;
Antti Palosaaric79b3392012-05-23 10:06:09 -0300378 struct usb_device *udev;
379
380#define DVB_USB_STATE_INIT 0x000
381#define DVB_USB_STATE_I2C 0x001
382#define DVB_USB_STATE_DVB 0x002
383#define DVB_USB_STATE_REMOTE 0x004
384 int state;
385
386 int powered;
387
388 /* locking */
389 struct mutex usb_mutex;
390
391 /* i2c */
392 struct mutex i2c_mutex;
393 struct i2c_adapter i2c_adap;
394
395 int num_adapters_initialized;
396 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
397
398 /* remote control */
399 struct rc_dev *rc_dev;
400 struct input_dev *input_dev;
401 char rc_phys[64];
402 struct delayed_work rc_query_work;
403 u32 last_event;
404 int last_state;
405
Antti Palosaaric79b3392012-05-23 10:06:09 -0300406 void *priv;
407};
408
409extern int dvb_usbv2_device_init(struct usb_interface *,
Antti Palosaari55b1f702012-05-23 16:23:44 -0300410 const struct usb_device_id *);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300411extern void dvb_usbv2_device_exit(struct usb_interface *);
412
413/* the generic read/write method for device control */
Antti Palosaari4e60d952012-05-24 14:44:21 -0300414extern int dvb_usbv2_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,
415 int);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300416extern int dvb_usbv2_generic_write(struct dvb_usb_device *, u8 *, u16);
417
Antti Palosaaric79b3392012-05-23 10:06:09 -0300418/* commonly used firmware download types and function */
419struct hexline {
420 u8 len;
421 u32 addr;
422 u8 type;
423 u8 data[255];
424 u8 chk;
425};
Antti Palosaari4e60d952012-05-24 14:44:21 -0300426extern int usbv2_cypress_load_firmware(struct usb_device *udev,
427 const struct firmware *fw, int type);
428extern int dvb_usbv2_get_hexline(const struct firmware *fw, struct hexline *hx,
429 int *pos);
Antti Palosaaric79b3392012-05-23 10:06:09 -0300430
431#endif