V4L/DVB (3893): Convert calls from _pllbuf() to _calc_reg()
[linux-2.6/mini2440.git] / drivers / media / dvb / dvb-usb / dvb-usb.h
blob4cf9f89c51bf91c48f1faebee796d9a2839e0932
1 /* dvb-usb.h is part of the DVB USB library.
3 * Copyright (C) 2004-5 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.
7 */
8 #ifndef __DVB_USB_H__
9 #define __DVB_USB_H__
11 #include <linux/config.h>
12 #include <linux/input.h>
13 #include <linux/usb.h>
14 #include <linux/firmware.h>
15 #include <linux/mutex.h>
17 #include "dvb_frontend.h"
18 #include "dvb_demux.h"
19 #include "dvb_net.h"
20 #include "dmxdev.h"
22 #include "dvb-pll.h"
24 #include "dvb-usb-ids.h"
26 /* debug */
27 #ifdef CONFIG_DVB_USB_DEBUG
28 #define dprintk(var,level,args...) \
29 do { if ((var & level)) { printk(args); } } while (0)
31 #define debug_dump(b,l,func) {\
32 int loop_; \
33 for (loop_ = 0; loop_ < l; loop_++) func("%02x ", b[loop_]); \
34 func("\n");\
36 #define DVB_USB_DEBUG_STATUS
37 #else
38 #define dprintk(args...)
39 #define debug_dump(b,l,func)
41 #define DVB_USB_DEBUG_STATUS " (debugging is not enabled)"
43 #endif
45 /* generic log methods - taken from usb.h */
46 #ifndef DVB_USB_LOG_PREFIX
47 #define DVB_USB_LOG_PREFIX "dvb-usb (please define a log prefix)"
48 #endif
50 #undef err
51 #define err(format, arg...) printk(KERN_ERR DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
52 #undef info
53 #define info(format, arg...) printk(KERN_INFO DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
54 #undef warn
55 #define warn(format, arg...) printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
57 /**
58 * struct dvb_usb_device_description - name and its according USB IDs
59 * @name: real name of the box, regardless which DVB USB device class is in use
60 * @cold_ids: array of struct usb_device_id which describe the device in
61 * pre-firmware state
62 * @warm_ids: array of struct usb_device_id which describe the device in
63 * post-firmware state
65 * Each DVB USB device class can have one or more actual devices, this struct
66 * assigns a name to it.
68 struct dvb_usb_device_description {
69 const char *name;
71 #define DVB_USB_ID_MAX_NUM 15
72 struct usb_device_id *cold_ids[DVB_USB_ID_MAX_NUM];
73 struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM];
76 /**
77 * struct dvb_usb_rc_key - a remote control key and its input-event
78 * @custom: the vendor/custom part of the key
79 * @data: the actual key part
80 * @event: the input event assigned to key identified by custom and data
82 struct dvb_usb_rc_key {
83 u8 custom,data;
84 u32 event;
87 struct dvb_usb_device;
89 /**
90 * struct dvb_usb_properties - properties of a dvb-usb-device
91 * @caps: capabilities of the DVB USB device.
92 * @pid_filter_count: number of PID filter position in the optional hardware
93 * PID-filter.
95 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
96 * download.
97 * @firmware: name of the firmware file.
98 * @download_firmware: called to download the firmware when the usb_ctrl is
99 * DEVICE_SPECIFIC.
100 * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
101 so do the warm initialization right after it
103 * @size_of_priv: how many bytes shall be allocated for the private field
104 * of struct dvb_usb_device.
106 * @power_ctrl: called to enable/disable power of the device.
107 * @streaming_crtl: called to start and stop the MPEG2-TS streaming of the
108 * device (not URB submitting/killing).
109 * @pid_filter_ctrl: called to en/disable the PID filter, if any.
110 * @pid_filter: called to set/unset a PID for filtering.
112 * @read_mac_address: called to read the MAC address of the device.
114 * @frontend_attach: called to attach the possible frontends (fill fe-field
115 * of struct dvb_usb_device).
116 * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
117 * pll_desc and pll_init_buf of struct dvb_usb_device).
118 * @identify_state: called to determine the state (cold or warm), when it
119 * is not distinguishable by the USB IDs.
121 * @rc_key_map: a hard-wired array of struct dvb_usb_rc_key (NULL to disable
122 * remote control handling).
123 * @rc_key_map_size: number of items in @rc_key_map.
124 * @rc_query: called to query an event event.
125 * @rc_interval: time in ms between two queries.
127 * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
129 * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
130 * endpoint which received control messages with bulk transfers. When this
131 * is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
132 * helper functions.
134 * @urb: describes the kind of USB transfer used for MPEG2-TS-streaming.
135 * (BULK or ISOC)
137 * @num_device_descs: number of struct dvb_usb_device_description in @devices
138 * @devices: array of struct dvb_usb_device_description compatibles with these
139 * properties.
141 struct dvb_usb_properties {
143 #define DVB_USB_HAS_PID_FILTER 0x01
144 #define DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF 0x02
145 #define DVB_USB_NEED_PID_FILTERING 0x04
146 #define DVB_USB_IS_AN_I2C_ADAPTER 0x08
147 int caps;
148 int pid_filter_count;
150 #define DEVICE_SPECIFIC 0
151 #define CYPRESS_AN2135 1
152 #define CYPRESS_AN2235 2
153 #define CYPRESS_FX2 3
154 int usb_ctrl;
155 const char firmware[FIRMWARE_NAME_MAX];
156 int (*download_firmware) (struct usb_device *, const struct firmware *);
157 int no_reconnect;
159 int size_of_priv;
161 int (*power_ctrl) (struct dvb_usb_device *, int);
162 int (*streaming_ctrl) (struct dvb_usb_device *, int);
163 int (*pid_filter_ctrl) (struct dvb_usb_device *, int);
164 int (*pid_filter) (struct dvb_usb_device *, int, u16, int);
166 int (*read_mac_address) (struct dvb_usb_device *, u8 []);
167 int (*frontend_attach) (struct dvb_usb_device *);
168 int (*tuner_attach) (struct dvb_usb_device *);
170 int (*identify_state) (struct usb_device *, struct dvb_usb_properties *,
171 struct dvb_usb_device_description **, int *);
173 /* remote control properties */
174 #define REMOTE_NO_KEY_PRESSED 0x00
175 #define REMOTE_KEY_PRESSED 0x01
176 #define REMOTE_KEY_REPEAT 0x02
177 struct dvb_usb_rc_key *rc_key_map;
178 int rc_key_map_size;
179 int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
180 int rc_interval;
182 struct i2c_algorithm *i2c_algo;
184 int generic_bulk_ctrl_endpoint;
186 struct {
187 #define DVB_USB_BULK 1
188 #define DVB_USB_ISOC 2
189 int type;
190 int count;
191 int endpoint;
193 union {
194 struct {
195 int buffersize; /* per URB */
196 } bulk;
197 struct {
198 int framesperurb;
199 int framesize;
200 int interval;
201 } isoc;
202 } u;
203 } urb;
205 int num_device_descs;
206 struct dvb_usb_device_description devices[9];
211 * struct dvb_usb_device - object of a DVB USB device
212 * @props: copy of the struct dvb_usb_properties this device belongs to.
213 * @desc: pointer to the device's struct dvb_usb_device_description.
214 * @state: initialization and runtime state of the device.
216 * @udev: pointer to the device's struct usb_device.
217 * @urb_list: array of dynamically allocated struct urb for the MPEG2-TS-
218 * streaming.
220 * @buf_num: number of buffer allocated.
221 * @buf_size: size of each buffer in buf_list.
222 * @buf_list: array containing all allocate buffers for streaming.
223 * @dma_addr: list of dma_addr_t for each buffer in buf_list.
225 * @urbs_initialized: number of URBs initialized.
226 * @urbs_submitted: number of URBs submitted.
228 * @feedcount: number of reqested feeds (used for streaming-activation)
229 * @pid_filtering: is hardware pid_filtering used or not.
231 * @usb_mutex: semaphore of USB control messages (reading needs two messages)
232 * @i2c_mutex: semaphore for i2c-transfers
234 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
235 * @pll_addr: I2C address of the tuner for programming
236 * @pll_init: array containing the initialization buffer
237 * @pll_desc: pointer to the appropriate struct dvb_pll_desc
239 * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or the board
241 * @dvb_adap: device's dvb_adapter.
242 * @dmxdev: device's dmxdev.
243 * @demux: device's software demuxer.
244 * @dvb_net: device's dvb_net interfaces.
245 * @dvb_frontend: device's frontend.
246 * @max_feed_count: how many feeds can be handled simultaneously by this
247 * device
248 * @fe_sleep: rerouted frontend-sleep function.
249 * @fe_init: rerouted frontend-init (wakeup) function.
250 * @rc_input_dev: input device for the remote control.
251 * @rc_query_work: struct work_struct frequent rc queries
252 * @last_event: last triggered event
253 * @last_state: last state (no, pressed, repeat)
254 * @owner: owner of the dvb_adapter
255 * @priv: private data of the actual driver (allocate by dvb-usb, size defined
256 * in size_of_priv of dvb_usb_properties).
258 struct dvb_usb_device {
259 struct dvb_usb_properties props;
260 struct dvb_usb_device_description *desc;
262 #define DVB_USB_STATE_INIT 0x000
263 #define DVB_USB_STATE_URB_LIST 0x001
264 #define DVB_USB_STATE_URB_BUF 0x002
265 #define DVB_USB_STATE_DVB 0x004
266 #define DVB_USB_STATE_I2C 0x008
267 #define DVB_USB_STATE_REMOTE 0x010
268 #define DVB_USB_STATE_URB_SUBMIT 0x020
269 int state;
271 /* usb */
272 struct usb_device *udev;
273 struct urb **urb_list;
275 int buf_num;
276 unsigned long buf_size;
277 u8 **buf_list;
278 dma_addr_t *dma_addr;
280 int urbs_initialized;
281 int urbs_submitted;
283 int feedcount;
284 int pid_filtering;
286 /* locking */
287 struct mutex usb_mutex;
289 /* i2c */
290 struct mutex i2c_mutex;
291 struct i2c_adapter i2c_adap;
293 /* tuner programming information */
294 u8 pll_addr;
295 u8 pll_init[4];
296 struct dvb_pll_desc *pll_desc;
297 int (*tuner_pass_ctrl)(struct dvb_frontend *, int, u8);
299 /* dvb */
300 struct dvb_adapter dvb_adap;
301 struct dmxdev dmxdev;
302 struct dvb_demux demux;
303 struct dvb_net dvb_net;
304 struct dvb_frontend* fe;
305 int max_feed_count;
307 int (*fe_sleep) (struct dvb_frontend *);
308 int (*fe_init) (struct dvb_frontend *);
310 /* remote control */
311 struct input_dev *rc_input_dev;
312 char rc_phys[64];
313 struct work_struct rc_query_work;
314 u32 last_event;
315 int last_state;
317 struct module *owner;
319 void *priv;
322 extern int dvb_usb_device_init(struct usb_interface *, struct dvb_usb_properties *, struct module *, struct dvb_usb_device **);
323 extern void dvb_usb_device_exit(struct usb_interface *);
325 /* the generic read/write method for device control */
326 extern int dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,int);
327 extern int dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
329 /* commonly used remote control parsing */
330 extern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *, int *);
332 /* commonly used pll init and set functions */
333 extern int dvb_usb_tuner_init_i2c(struct dvb_frontend *);
334 extern int dvb_usb_tuner_calc_regs(struct dvb_frontend *, struct dvb_frontend_parameters *, u8 *buf, int buf_len);
335 extern int dvb_usb_tuner_set_params_i2c(struct dvb_frontend *, struct dvb_frontend_parameters *);
337 /* commonly used firmware download types and function */
338 struct hexline {
339 u8 len;
340 u32 addr;
341 u8 type;
342 u8 data[255];
343 u8 chk;
345 extern int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type);
347 #endif