GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / media / dvb / dvb-usb / dvb-usb.h
blob34f7b3ba8cc75f70607d0dc3bf4eaa287cd8ec17
1 /* dvb-usb.h is part of the DVB USB library.
3 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
6 * the headerfile, all dvb-usb-drivers have to include.
8 * TODO: clean-up the structures for unused fields and update the comments
9 */
10 #ifndef __DVB_USB_H__
11 #define __DVB_USB_H__
13 #include <linux/input.h>
14 #include <linux/usb.h>
15 #include <linux/firmware.h>
16 #include <linux/mutex.h>
17 #include <media/ir-core.h>
19 #include "dvb_frontend.h"
20 #include "dvb_demux.h"
21 #include "dvb_net.h"
22 #include "dmxdev.h"
24 #include "dvb-pll.h"
26 #include "dvb-usb-ids.h"
28 /* debug */
29 #ifdef CONFIG_DVB_USB_DEBUG
30 #define dprintk(var,level,args...) \
31 do { if ((var & level)) { printk(args); } } while (0)
33 #define debug_dump(b,l,func) {\
34 int loop_; \
35 for (loop_ = 0; loop_ < l; loop_++) func("%02x ", b[loop_]); \
36 func("\n");\
38 #define DVB_USB_DEBUG_STATUS
39 #else
40 #define dprintk(args...)
41 #define debug_dump(b,l,func)
43 #define DVB_USB_DEBUG_STATUS " (debugging is not enabled)"
45 #endif
47 /* generic log methods - taken from usb.h */
48 #ifndef DVB_USB_LOG_PREFIX
49 #define DVB_USB_LOG_PREFIX "dvb-usb (please define a log prefix)"
50 #endif
52 #undef err
53 #define err(format, arg...) printk(KERN_ERR DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
54 #undef info
55 #define info(format, arg...) printk(KERN_INFO DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
56 #undef warn
57 #define warn(format, arg...) printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
59 /**
60 * struct dvb_usb_device_description - name and its according USB IDs
61 * @name: real name of the box, regardless which DVB USB device class is in use
62 * @cold_ids: array of struct usb_device_id which describe the device in
63 * pre-firmware state
64 * @warm_ids: array of struct usb_device_id which describe the device in
65 * post-firmware state
67 * Each DVB USB device class can have one or more actual devices, this struct
68 * assigns a name to it.
70 struct dvb_usb_device_description {
71 const char *name;
73 #define DVB_USB_ID_MAX_NUM 15
74 struct usb_device_id *cold_ids[DVB_USB_ID_MAX_NUM];
75 struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM];
78 static inline u8 rc5_custom(struct ir_scancode *key)
80 return (key->scancode >> 8) & 0xff;
83 static inline u8 rc5_data(struct ir_scancode *key)
85 return key->scancode & 0xff;
88 static inline u8 rc5_scan(struct ir_scancode *key)
90 return key->scancode & 0xffff;
93 struct dvb_usb_device;
94 struct dvb_usb_adapter;
95 struct usb_data_stream;
97 /**
98 * Properties of USB streaming - TODO this structure should be somewhere else
99 * describes the kind of USB transfer used for data-streaming.
100 * (BULK or ISOC)
102 struct usb_data_stream_properties {
103 #define USB_BULK 1
104 #define USB_ISOC 2
105 int type;
106 int count;
107 int endpoint;
109 union {
110 struct {
111 int buffersize; /* per URB */
112 } bulk;
113 struct {
114 int framesperurb;
115 int framesize;
116 int interval;
117 } isoc;
118 } u;
122 * struct dvb_usb_adapter_properties - properties of a dvb-usb-adapter.
123 * A DVB-USB-Adapter is basically a dvb_adapter which is present on a USB-device.
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 * @streaming_ctrl: called to start and stop the MPEG2-TS streaming of the
128 * device (not URB submitting/killing).
129 * @pid_filter_ctrl: called to en/disable the PID filter, if any.
130 * @pid_filter: called to set/unset a PID for filtering.
131 * @frontend_attach: called to attach the possible frontends (fill fe-field
132 * of struct dvb_usb_device).
133 * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
134 * pll_desc and pll_init_buf of struct dvb_usb_device).
135 * @stream: configuration of the USB streaming
137 struct dvb_usb_adapter_properties {
138 #define DVB_USB_ADAP_HAS_PID_FILTER 0x01
139 #define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
140 #define DVB_USB_ADAP_NEED_PID_FILTERING 0x04
141 #define DVB_USB_ADAP_RECEIVES_204_BYTE_TS 0x08
142 int caps;
143 int pid_filter_count;
145 int (*streaming_ctrl) (struct dvb_usb_adapter *, int);
146 int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);
147 int (*pid_filter) (struct dvb_usb_adapter *, int, u16, int);
149 int (*frontend_attach) (struct dvb_usb_adapter *);
150 int (*tuner_attach) (struct dvb_usb_adapter *);
152 struct usb_data_stream_properties stream;
154 int size_of_priv;
156 int (*fe_ioctl_override) (struct dvb_frontend *,
157 unsigned int, void *, unsigned int);
161 * struct dvb_rc_legacy - old properties of remote controller
162 * @rc_key_map: a hard-wired array of struct ir_scancode (NULL to disable
163 * remote control handling).
164 * @rc_key_map_size: number of items in @rc_key_map.
165 * @rc_query: called to query an event event.
166 * @rc_interval: time in ms between two queries.
168 struct dvb_rc_legacy {
169 /* remote control properties */
170 #define REMOTE_NO_KEY_PRESSED 0x00
171 #define REMOTE_KEY_PRESSED 0x01
172 #define REMOTE_KEY_REPEAT 0x02
173 struct ir_scancode *rc_key_map;
174 int rc_key_map_size;
175 int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
176 int rc_interval;
180 * struct dvb_rc properties of remote controller, using rc-core
181 * @rc_codes: name of rc codes table
182 * @protocol: type of protocol(s) currently used by the driver
183 * @rc_query: called to query an event event.
184 * @rc_interval: time in ms between two queries.
185 * @rc_props: remote controller properties
186 * @bulk_mode: device supports bulk mode for RC (disable polling mode)
188 struct dvb_rc {
189 char *rc_codes;
190 u64 protocol;
191 char *module_name;
192 int (*rc_query) (struct dvb_usb_device *d);
193 int rc_interval;
194 struct ir_dev_props rc_props;
195 bool bulk_mode; /* uses bulk mode */
199 * enum dvb_usb_mode - Specifies if it is using a legacy driver or a new one
200 * based on rc-core
201 * This is initialized/used only inside dvb-usb-remote.c.
202 * It shouldn't be set by the drivers.
204 enum dvb_usb_mode {
205 DVB_RC_LEGACY,
206 DVB_RC_CORE,
210 * struct dvb_usb_device_properties - properties of a dvb-usb-device
211 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
212 * download.
213 * @firmware: name of the firmware file.
214 * @download_firmware: called to download the firmware when the usb_ctrl is
215 * DEVICE_SPECIFIC.
216 * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
217 * so do the warm initialization right after it
219 * @size_of_priv: how many bytes shall be allocated for the private field
220 * of struct dvb_usb_device.
222 * @power_ctrl: called to enable/disable power of the device.
223 * @read_mac_address: called to read the MAC address of the device.
224 * @identify_state: called to determine the state (cold or warm), when it
225 * is not distinguishable by the USB IDs.
227 * @rc: remote controller properties
229 * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
231 * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
232 * endpoint which received control messages with bulk transfers. When this
233 * is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
234 * helper functions.
236 * @generic_bulk_ctrl_endpoint_response: some DVB USB devices use a separate
237 * endpoint for responses to control messages sent with bulk transfers via
238 * the generic_bulk_ctrl_endpoint. When this is non-zero, this will be used
239 * instead of the generic_bulk_ctrl_endpoint when reading usb responses in
240 * the dvb_usb_generic_rw helper function.
242 * @num_device_descs: number of struct dvb_usb_device_description in @devices
243 * @devices: array of struct dvb_usb_device_description compatibles with these
244 * properties.
246 #define MAX_NO_OF_ADAPTER_PER_DEVICE 2
247 struct dvb_usb_device_properties {
249 #define DVB_USB_IS_AN_I2C_ADAPTER 0x01
250 int caps;
252 #define DEVICE_SPECIFIC 0
253 #define CYPRESS_AN2135 1
254 #define CYPRESS_AN2235 2
255 #define CYPRESS_FX2 3
256 int usb_ctrl;
257 int (*download_firmware) (struct usb_device *, const struct firmware *);
258 const char *firmware;
259 int no_reconnect;
261 int size_of_priv;
263 int num_adapters;
264 struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
266 int (*power_ctrl) (struct dvb_usb_device *, int);
267 int (*read_mac_address) (struct dvb_usb_device *, u8 []);
268 int (*identify_state) (struct usb_device *, struct dvb_usb_device_properties *,
269 struct dvb_usb_device_description **, int *);
271 struct {
272 enum dvb_usb_mode mode; /* Drivers shouldn't touch on it */
273 struct dvb_rc_legacy legacy;
274 struct dvb_rc core;
275 } rc;
277 struct i2c_algorithm *i2c_algo;
279 int generic_bulk_ctrl_endpoint;
280 int generic_bulk_ctrl_endpoint_response;
282 int num_device_descs;
283 struct dvb_usb_device_description devices[12];
287 * struct usb_data_stream - generic object of an USB stream
288 * @buf_num: number of buffer allocated.
289 * @buf_size: size of each buffer in buf_list.
290 * @buf_list: array containing all allocate buffers for streaming.
291 * @dma_addr: list of dma_addr_t for each buffer in buf_list.
293 * @urbs_initialized: number of URBs initialized.
294 * @urbs_submitted: number of URBs submitted.
296 #define MAX_NO_URBS_FOR_DATA_STREAM 10
297 struct usb_data_stream {
298 struct usb_device *udev;
299 struct usb_data_stream_properties props;
301 #define USB_STATE_INIT 0x00
302 #define USB_STATE_URB_BUF 0x01
303 int state;
305 void (*complete) (struct usb_data_stream *, u8 *, size_t);
307 struct urb *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
308 int buf_num;
309 unsigned long buf_size;
310 u8 *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
311 dma_addr_t dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
313 int urbs_initialized;
314 int urbs_submitted;
316 void *user_priv;
320 * struct dvb_usb_adapter - a DVB adapter on a USB device
321 * @id: index of this adapter (starting with 0).
323 * @feedcount: number of reqested feeds (used for streaming-activation)
324 * @pid_filtering: is hardware pid_filtering used or not.
326 * @pll_addr: I2C address of the tuner for programming
327 * @pll_init: array containing the initialization buffer
328 * @pll_desc: pointer to the appropriate struct dvb_pll_desc
329 * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or the board
331 * @dvb_adap: device's dvb_adapter.
332 * @dmxdev: device's dmxdev.
333 * @demux: device's software demuxer.
334 * @dvb_net: device's dvb_net interfaces.
335 * @dvb_frontend: device's frontend.
336 * @max_feed_count: how many feeds can be handled simultaneously by this
337 * device
339 * @fe_init: rerouted frontend-init (wakeup) function.
340 * @fe_sleep: rerouted frontend-sleep function.
342 * @stream: the usb data stream.
344 struct dvb_usb_adapter {
345 struct dvb_usb_device *dev;
346 struct dvb_usb_adapter_properties props;
348 #define DVB_USB_ADAP_STATE_INIT 0x000
349 #define DVB_USB_ADAP_STATE_DVB 0x001
350 int state;
352 u8 id;
354 int feedcount;
355 int pid_filtering;
357 /* dvb */
358 struct dvb_adapter dvb_adap;
359 struct dmxdev dmxdev;
360 struct dvb_demux demux;
361 struct dvb_net dvb_net;
362 struct dvb_frontend *fe;
363 int max_feed_count;
365 int (*fe_init) (struct dvb_frontend *);
366 int (*fe_sleep) (struct dvb_frontend *);
368 struct usb_data_stream stream;
370 void *priv;
374 * struct dvb_usb_device - object of a DVB USB device
375 * @props: copy of the struct dvb_usb_properties this device belongs to.
376 * @desc: pointer to the device's struct dvb_usb_device_description.
377 * @state: initialization and runtime state of the device.
379 * @powered: indicated whether the device is power or not.
380 * Powered is in/decremented for each call to modify the state.
381 * @udev: pointer to the device's struct usb_device.
383 * @usb_mutex: semaphore of USB control messages (reading needs two messages)
384 * @i2c_mutex: semaphore for i2c-transfers
386 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
388 * @rc_input_dev: input device for the remote control.
389 * @rc_query_work: struct work_struct frequent rc queries
390 * @last_event: last triggered event
391 * @last_state: last state (no, pressed, repeat)
392 * @owner: owner of the dvb_adapter
393 * @priv: private data of the actual driver (allocate by dvb-usb, size defined
394 * in size_of_priv of dvb_usb_properties).
396 struct dvb_usb_device {
397 struct dvb_usb_device_properties props;
398 struct dvb_usb_device_description *desc;
400 struct usb_device *udev;
402 #define DVB_USB_STATE_INIT 0x000
403 #define DVB_USB_STATE_I2C 0x001
404 #define DVB_USB_STATE_DVB 0x002
405 #define DVB_USB_STATE_REMOTE 0x004
406 int state;
408 int powered;
410 /* locking */
411 struct mutex usb_mutex;
413 /* i2c */
414 struct mutex i2c_mutex;
415 struct i2c_adapter i2c_adap;
417 int num_adapters_initialized;
418 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
420 /* remote control */
421 struct input_dev *rc_input_dev;
422 char rc_phys[64];
423 struct delayed_work rc_query_work;
424 u32 last_event;
425 int last_state;
427 struct module *owner;
429 void *priv;
432 extern int dvb_usb_device_init(struct usb_interface *,
433 struct dvb_usb_device_properties *,
434 struct module *, struct dvb_usb_device **,
435 short *adapter_nums);
436 extern void dvb_usb_device_exit(struct usb_interface *);
438 /* the generic read/write method for device control */
439 extern int dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,int);
440 extern int dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
442 /* commonly used remote control parsing */
443 extern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *, int *);
445 /* commonly used firmware download types and function */
446 struct hexline {
447 u8 len;
448 u32 addr;
449 u8 type;
450 u8 data[255];
451 u8 chk;
453 extern int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type);
454 extern int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx, int *pos);
457 #endif