blob: 44b49db4992e2eec2bc6c12258cf5c84cca211ef [file] [log] [blame]
Johannes Stezenbach776338e2005-06-23 22:02:35 -07001/* dvb-usb.h is part of the DVB USB library.
2 *
Patrick Boettcher4d43e132006-09-30 06:53:48 -03003 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de)
Johannes Stezenbach776338e2005-06-23 22:02:35 -07004 * see dvb-usb-init.c for copyright information.
5 *
6 * the headerfile, all dvb-usb-drivers have to include.
Patrick Boettcher4d43e132006-09-30 06:53:48 -03007 *
8 * TODO: clean-up the structures for unused fields and update the comments
Johannes Stezenbach776338e2005-06-23 22:02:35 -07009 */
10#ifndef __DVB_USB_H__
11#define __DVB_USB_H__
12
Johannes Stezenbach776338e2005-06-23 22:02:35 -070013#include <linux/input.h>
Johannes Stezenbach776338e2005-06-23 22:02:35 -070014#include <linux/usb.h>
Patrick Boettcherd3707ad2006-01-09 15:25:04 -020015#include <linux/firmware.h>
Ingo Molnar3593cab2006-02-07 06:49:14 -020016#include <linux/mutex.h>
Johannes Stezenbach776338e2005-06-23 22:02:35 -070017
18#include "dvb_frontend.h"
19#include "dvb_demux.h"
20#include "dvb_net.h"
21#include "dmxdev.h"
22
23#include "dvb-pll.h"
24
25#include "dvb-usb-ids.h"
26
27/* debug */
28#ifdef CONFIG_DVB_USB_DEBUG
29#define dprintk(var,level,args...) \
30 do { if ((var & level)) { printk(args); } } while (0)
31
32#define debug_dump(b,l,func) {\
33 int loop_; \
34 for (loop_ = 0; loop_ < l; loop_++) func("%02x ", b[loop_]); \
35 func("\n");\
36}
37#define DVB_USB_DEBUG_STATUS
38#else
39#define dprintk(args...)
40#define debug_dump(b,l,func)
41
42#define DVB_USB_DEBUG_STATUS " (debugging is not enabled)"
43
44#endif
45
46/* generic log methods - taken from usb.h */
47#ifndef DVB_USB_LOG_PREFIX
48 #define DVB_USB_LOG_PREFIX "dvb-usb (please define a log prefix)"
49#endif
50
51#undef err
52#define err(format, arg...) printk(KERN_ERR DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
53#undef info
54#define info(format, arg...) printk(KERN_INFO DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
55#undef warn
56#define warn(format, arg...) printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
57
58/**
59 * struct dvb_usb_device_description - name and its according USB IDs
60 * @name: real name of the box, regardless which DVB USB device class is in use
61 * @cold_ids: array of struct usb_device_id which describe the device in
62 * pre-firmware state
63 * @warm_ids: array of struct usb_device_id which describe the device in
64 * post-firmware state
65 *
66 * Each DVB USB device class can have one or more actual devices, this struct
67 * assigns a name to it.
68 */
69struct dvb_usb_device_description {
70 const char *name;
71
72#define DVB_USB_ID_MAX_NUM 15
73 struct usb_device_id *cold_ids[DVB_USB_ID_MAX_NUM];
74 struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM];
75};
76
77/**
78 * struct dvb_usb_rc_key - a remote control key and its input-event
79 * @custom: the vendor/custom part of the key
80 * @data: the actual key part
81 * @event: the input event assigned to key identified by custom and data
82 */
83struct dvb_usb_rc_key {
84 u8 custom,data;
85 u32 event;
86};
87
88struct dvb_usb_device;
Patrick Boettcher4d43e132006-09-30 06:53:48 -030089struct dvb_usb_adapter;
90struct usb_data_stream;
Johannes Stezenbach776338e2005-06-23 22:02:35 -070091
92/**
Patrick Boettcher136cafb2006-09-19 12:51:33 -030093 * Properties of USB streaming - TODO this structure should be somewhere else
94 * describes the kind of USB transfer used for data-streaming.
Patrick Boettcher4d43e132006-09-30 06:53:48 -030095 * (BULK or ISOC)
96 */
97struct usb_data_stream_properties {
98#define USB_BULK 1
99#define USB_ISOC 2
100 int type;
101 int count;
102 int endpoint;
103
104 union {
105 struct {
106 int buffersize; /* per URB */
107 } bulk;
108 struct {
109 int framesperurb;
110 int framesize;
111 int interval;
112 } isoc;
113 } u;
114};
115
116/**
117 * struct dvb_usb_adapter_properties - properties of a dvb-usb-adapter.
118 * A DVB-USB-Adapter is basically a dvb_adapter which is present on a USB-device.
Alexey Dobriyanbe787ac2006-03-07 22:20:23 -0300119 * @caps: capabilities of the DVB USB device.
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700120 * @pid_filter_count: number of PID filter position in the optional hardware
121 * PID-filter.
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300122 * @streaming_crtl: called to start and stop the MPEG2-TS streaming of the
123 * device (not URB submitting/killing).
124 * @pid_filter_ctrl: called to en/disable the PID filter, if any.
125 * @pid_filter: called to set/unset a PID for filtering.
126 * @frontend_attach: called to attach the possible frontends (fill fe-field
127 * of struct dvb_usb_device).
128 * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
129 * pll_desc and pll_init_buf of struct dvb_usb_device).
130 * @stream: configuration of the USB streaming
131 */
132struct dvb_usb_adapter_properties {
133#define DVB_USB_ADAP_HAS_PID_FILTER 0x01
134#define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
135#define DVB_USB_ADAP_NEED_PID_FILTERING 0x04
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/**
152 * struct dvb_usb_device_properties - properties of a dvb-usb-device
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700153 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
154 * download.
155 * @firmware: name of the firmware file.
Patrick Boettcherd3707ad2006-01-09 15:25:04 -0200156 * @download_firmware: called to download the firmware when the usb_ctrl is
157 * DEVICE_SPECIFIC.
158 * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300159 * so do the warm initialization right after it
160 *
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700161 * @size_of_priv: how many bytes shall be allocated for the private field
162 * of struct dvb_usb_device.
163 *
164 * @power_ctrl: called to enable/disable power of the device.
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700165 * @read_mac_address: called to read the MAC address of the device.
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700166 * @identify_state: called to determine the state (cold or warm), when it
167 * is not distinguishable by the USB IDs.
168 *
169 * @rc_key_map: a hard-wired array of struct dvb_usb_rc_key (NULL to disable
170 * remote control handling).
171 * @rc_key_map_size: number of items in @rc_key_map.
172 * @rc_query: called to query an event event.
173 * @rc_interval: time in ms between two queries.
174 *
175 * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
176 *
177 * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
178 * endpoint which received control messages with bulk transfers. When this
179 * is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
180 * helper functions.
181 *
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700182 * @num_device_descs: number of struct dvb_usb_device_description in @devices
183 * @devices: array of struct dvb_usb_device_description compatibles with these
184 * properties.
185 */
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300186#define MAX_NO_OF_ADAPTER_PER_DEVICE 2
187struct dvb_usb_device_properties {
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700188
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300189#define DVB_USB_IS_AN_I2C_ADAPTER 0x01
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700190 int caps;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700191
Patrick Boettcherd3707ad2006-01-09 15:25:04 -0200192#define DEVICE_SPECIFIC 0
193#define CYPRESS_AN2135 1
194#define CYPRESS_AN2235 2
195#define CYPRESS_FX2 3
Patrick Boettcher136cafb2006-09-19 12:51:33 -0300196 int usb_ctrl;
197 int (*download_firmware) (struct usb_device *, const struct firmware *);
Patrick Boettcherd3707ad2006-01-09 15:25:04 -0200198 const char firmware[FIRMWARE_NAME_MAX];
Patrick Boettcher136cafb2006-09-19 12:51:33 -0300199 int no_reconnect;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700200
201 int size_of_priv;
202
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300203 int num_adapters;
204 struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700205
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300206 int (*power_ctrl) (struct dvb_usb_device *, int);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700207 int (*read_mac_address) (struct dvb_usb_device *, u8 []);
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300208 int (*identify_state) (struct usb_device *, struct dvb_usb_device_properties *,
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700209 struct dvb_usb_device_description **, int *);
210
211/* remote control properties */
212#define REMOTE_NO_KEY_PRESSED 0x00
213#define REMOTE_KEY_PRESSED 0x01
214#define REMOTE_KEY_REPEAT 0x02
Patrick Boettcher136cafb2006-09-19 12:51:33 -0300215 struct dvb_usb_rc_key *rc_key_map;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700216 int rc_key_map_size;
217 int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
218 int rc_interval;
219
220 struct i2c_algorithm *i2c_algo;
221
222 int generic_bulk_ctrl_endpoint;
223
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700224 int num_device_descs;
Patrick Boettcher2f7f96b2005-07-07 17:58:16 -0700225 struct dvb_usb_device_description devices[9];
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700226};
227
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700228/**
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300229 * struct usb_data_stream - generic object of an USB stream
Patrick Boettcher7f5fee52005-07-07 17:58:08 -0700230 * @buf_num: number of buffer allocated.
231 * @buf_size: size of each buffer in buf_list.
232 * @buf_list: array containing all allocate buffers for streaming.
233 * @dma_addr: list of dma_addr_t for each buffer in buf_list.
234 *
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700235 * @urbs_initialized: number of URBs initialized.
236 * @urbs_submitted: number of URBs submitted.
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300237 */
238#define MAX_NO_URBS_FOR_DATA_STREAM 10
239struct usb_data_stream {
Patrick Boettcher136cafb2006-09-19 12:51:33 -0300240 struct usb_device *udev;
241 struct usb_data_stream_properties props;
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300242
243#define USB_STATE_INIT 0x00
244#define USB_STATE_URB_BUF 0x01
245 int state;
246
247 void (*complete) (struct usb_data_stream *, u8 *, size_t);
248
Patrick Boettcher136cafb2006-09-19 12:51:33 -0300249 struct urb *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
250 int buf_num;
251 unsigned long buf_size;
252 u8 *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
253 dma_addr_t dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300254
255 int urbs_initialized;
256 int urbs_submitted;
257
258 void *user_priv;
259};
260
261/**
262 * struct dvb_usb_adapter - a DVB adapter on a USB device
263 * @id: index of this adapter (starting with 0).
264 *
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700265 * @feedcount: number of reqested feeds (used for streaming-activation)
266 * @pid_filtering: is hardware pid_filtering used or not.
Patrick Boettcher7f5fee52005-07-07 17:58:08 -0700267 *
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700268 * @pll_addr: I2C address of the tuner for programming
269 * @pll_init: array containing the initialization buffer
270 * @pll_desc: pointer to the appropriate struct dvb_pll_desc
Patrick Boettcher7f5fee52005-07-07 17:58:08 -0700271 * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or the board
Patrick Boettcher136cafb2006-09-19 12:51:33 -0300272 *
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700273 * @dvb_adap: device's dvb_adapter.
274 * @dmxdev: device's dmxdev.
275 * @demux: device's software demuxer.
276 * @dvb_net: device's dvb_net interfaces.
277 * @dvb_frontend: device's frontend.
278 * @max_feed_count: how many feeds can be handled simultaneously by this
279 * device
Patrick Boettcher136cafb2006-09-19 12:51:33 -0300280 *
281 * @fe_init: rerouted frontend-init (wakeup) function.
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700282 * @fe_sleep: rerouted frontend-sleep function.
Patrick Boettcher136cafb2006-09-19 12:51:33 -0300283 *
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300284 * @stream: the usb data stream.
285 */
286struct dvb_usb_adapter {
287 struct dvb_usb_device *dev;
288 struct dvb_usb_adapter_properties props;
289
290#define DVB_USB_ADAP_STATE_INIT 0x000
291#define DVB_USB_ADAP_STATE_DVB 0x001
292 int state;
293
Patrick Boettcher136cafb2006-09-19 12:51:33 -0300294 u8 id;
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300295
296 int feedcount;
297 int pid_filtering;
298
299 /* tuner programming information */
300 u8 pll_addr;
301 u8 pll_init[4];
302 struct dvb_pll_desc *pll_desc;
303 int (*tuner_pass_ctrl) (struct dvb_frontend *, int, u8);
304
305 /* dvb */
306 struct dvb_adapter dvb_adap;
307 struct dmxdev dmxdev;
308 struct dvb_demux demux;
309 struct dvb_net dvb_net;
310 struct dvb_frontend *fe;
311 int max_feed_count;
312
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300313 int (*fe_init) (struct dvb_frontend *);
Patrick Boettcher136cafb2006-09-19 12:51:33 -0300314 int (*fe_sleep) (struct dvb_frontend *);
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300315
316 struct usb_data_stream stream;
317
318 void *priv;
319};
320
321/**
322 * struct dvb_usb_device - object of a DVB USB device
323 * @props: copy of the struct dvb_usb_properties this device belongs to.
324 * @desc: pointer to the device's struct dvb_usb_device_description.
325 * @state: initialization and runtime state of the device.
326 *
327 * @udev: pointer to the device's struct usb_device.
328 *
329 * @usb_mutex: semaphore of USB control messages (reading needs two messages)
330 * @i2c_mutex: semaphore for i2c-transfers
331 *
332 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
333 *
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700334 * @rc_input_dev: input device for the remote control.
335 * @rc_query_work: struct work_struct frequent rc queries
336 * @last_event: last triggered event
337 * @last_state: last state (no, pressed, repeat)
338 * @owner: owner of the dvb_adapter
339 * @priv: private data of the actual driver (allocate by dvb-usb, size defined
340 * in size_of_priv of dvb_usb_properties).
341 */
342struct dvb_usb_device {
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300343 struct dvb_usb_device_properties props;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700344 struct dvb_usb_device_description *desc;
345
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300346 struct usb_device *udev;
347
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700348#define DVB_USB_STATE_INIT 0x000
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300349#define DVB_USB_STATE_I2C 0x001
350#define DVB_USB_STATE_DVB 0x002
351#define DVB_USB_STATE_REMOTE 0x004
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700352 int state;
353
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300354 int powered;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700355
356 /* locking */
Ingo Molnar3593cab2006-02-07 06:49:14 -0200357 struct mutex usb_mutex;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700358
359 /* i2c */
Ingo Molnar3593cab2006-02-07 06:49:14 -0200360 struct mutex i2c_mutex;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700361 struct i2c_adapter i2c_adap;
362
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300363 int num_adapters_initialized;
364 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700365
366 /* remote control */
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500367 struct input_dev *rc_input_dev;
368 char rc_phys[64];
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700369 struct work_struct rc_query_work;
370 u32 last_event;
371 int last_state;
372
373 struct module *owner;
374
375 void *priv;
376};
377
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300378extern int dvb_usb_device_init(struct usb_interface *, struct dvb_usb_device_properties *, struct module *, struct dvb_usb_device **);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700379extern void dvb_usb_device_exit(struct usb_interface *);
380
381/* the generic read/write method for device control */
382extern int dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,int);
383extern int dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
384
385/* commonly used remote control parsing */
386extern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *, int *);
387
388/* commonly used pll init and set functions */
Andrew de Quinceyee6a2cb2006-04-18 17:47:11 -0300389extern int dvb_usb_tuner_init_i2c(struct dvb_frontend *);
Andrew de Quinceybd4956b2006-04-18 21:38:49 -0300390extern int dvb_usb_tuner_calc_regs(struct dvb_frontend *, struct dvb_frontend_parameters *, u8 *buf, int buf_len);
Andrew de Quinceyee6a2cb2006-04-18 17:47:11 -0300391extern int dvb_usb_tuner_set_params_i2c(struct dvb_frontend *, struct dvb_frontend_parameters *);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700392
Patrick Boettcherd3707ad2006-01-09 15:25:04 -0200393/* commonly used firmware download types and function */
394struct hexline {
395 u8 len;
396 u32 addr;
397 u8 type;
398 u8 data[255];
399 u8 chk;
400};
Patrick Boettcherf5373782006-01-09 18:21:38 -0200401extern int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type);
Patrick Boettcher136cafb2006-09-19 12:51:33 -0300402extern int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx, int *pos);
403
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700404
405#endif