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
13 #include <linux/input.h>
14 #include <linux/usb.h>
15 #include <linux/firmware.h>
16 #include <linux/mutex.h>
18 #include "dvb_frontend.h"
19 #include "dvb_demux.h"
25 #include "dvb-usb-ids.h"
28 #ifdef CONFIG_DVB_USB_DEBUG
29 #define dprintk(var,level,args...) \
30 do { if ((var & level)) { printk(args); } } while (0)
32 #define debug_dump(b,l,func) {\
34 for (loop_ = 0; loop_ < l; loop_++) func("%02x ", b[loop_]); \
37 #define DVB_USB_DEBUG_STATUS
39 #define dprintk(args...)
40 #define debug_dump(b,l,func)
42 #define DVB_USB_DEBUG_STATUS " (debugging is not enabled)"
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)"
52 #define err(format, arg...) printk(KERN_ERR DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
54 #define info(format, arg...) printk(KERN_INFO DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
56 #define warn(format, arg...) printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
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
63 * @warm_ids: array of struct usb_device_id which describe the device in
66 * Each DVB USB device class can have one or more actual devices, this struct
67 * assigns a name to it.
69 struct dvb_usb_device_description {
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];
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
83 struct dvb_usb_rc_key {
88 struct dvb_usb_device;
89 struct dvb_usb_adapter;
90 struct usb_data_stream;
93 * Properties of USB streaming - TODO this structure does not belong here actually
94 * describes the kind of USB transfer used for MPEG2-TS-streaming.
97 struct usb_data_stream_properties {
106 int buffersize; /* per URB */
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.
119 * @caps: capabilities of the DVB USB device.
120 * @pid_filter_count: number of PID filter position in the optional hardware
122 * @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
132 struct 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
137 int pid_filter_count;
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);
143 int (*frontend_attach) (struct dvb_usb_adapter *);
144 int (*tuner_attach) (struct dvb_usb_adapter *);
146 struct usb_data_stream_properties stream;
152 * struct dvb_usb_device_properties - properties of a dvb-usb-device
153 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
155 * @firmware: name of the firmware file.
156 * @download_firmware: called to download the firmware when the usb_ctrl is
158 * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
159 * so do the warm initialization right after it
161 * @size_of_priv: how many bytes shall be allocated for the private field
162 * of struct dvb_usb_device.
164 * @power_ctrl: called to enable/disable power of the device.
165 * @read_mac_address: called to read the MAC address of the device.
166 * @identify_state: called to determine the state (cold or warm), when it
167 * is not distinguishable by the USB IDs.
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.
175 * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
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-
182 * @num_device_descs: number of struct dvb_usb_device_description in @devices
183 * @devices: array of struct dvb_usb_device_description compatibles with these
186 #define MAX_NO_OF_ADAPTER_PER_DEVICE 2
187 struct dvb_usb_device_properties {
189 #define DVB_USB_IS_AN_I2C_ADAPTER 0x01
192 #define DEVICE_SPECIFIC 0
193 #define CYPRESS_AN2135 1
194 #define CYPRESS_AN2235 2
195 #define CYPRESS_FX2 3
197 const char firmware[FIRMWARE_NAME_MAX];
198 int (*download_firmware) (struct usb_device *, const struct firmware *);
204 struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
206 int (*power_ctrl) (struct dvb_usb_device *, int);
207 int (*read_mac_address) (struct dvb_usb_device *, u8 []);
208 int (*identify_state) (struct usb_device *, struct dvb_usb_device_properties *,
209 struct dvb_usb_device_description **, int *);
211 /* remote control properties */
212 #define REMOTE_NO_KEY_PRESSED 0x00
213 #define REMOTE_KEY_PRESSED 0x01
214 #define REMOTE_KEY_REPEAT 0x02
215 struct dvb_usb_rc_key *rc_key_map;
217 int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
220 struct i2c_algorithm *i2c_algo;
222 int generic_bulk_ctrl_endpoint;
224 int num_device_descs;
225 struct dvb_usb_device_description devices[9];
229 * struct usb_data_stream - generic object of an USB stream
230 * @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.
235 * @urbs_initialized: number of URBs initialized.
236 * @urbs_submitted: number of URBs submitted.
238 * TODO put this in the correct place.
240 #define MAX_NO_URBS_FOR_DATA_STREAM 10
241 struct usb_data_stream {
242 struct usb_device *udev;
243 struct usb_data_stream_properties props;
245 #define USB_STATE_INIT 0x00
246 #define USB_STATE_URB_BUF 0x01
249 void (*complete) (struct usb_data_stream *, u8 *, size_t);
251 struct urb *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
254 unsigned long buf_size;
255 u8 *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
256 dma_addr_t dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
258 int urbs_initialized;
265 * struct dvb_usb_adapter - a DVB adapter on a USB device
266 * @id: index of this adapter (starting with 0).
268 * @feedcount: number of reqested feeds (used for streaming-activation)
269 * @pid_filtering: is hardware pid_filtering used or not.
271 * @pll_addr: I2C address of the tuner for programming
272 * @pll_init: array containing the initialization buffer
273 * @pll_desc: pointer to the appropriate struct dvb_pll_desc
275 * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or the board
276 * @dvb_adap: device's dvb_adapter.
277 * @dmxdev: device's dmxdev.
278 * @demux: device's software demuxer.
279 * @dvb_net: device's dvb_net interfaces.
280 * @dvb_frontend: device's frontend.
281 * @max_feed_count: how many feeds can be handled simultaneously by this
283 * @fe_sleep: rerouted frontend-sleep function.
284 * @fe_init: rerouted frontend-init (wakeup) function.
285 * @stream: the usb data stream.
287 struct dvb_usb_adapter {
288 struct dvb_usb_device *dev;
289 struct dvb_usb_adapter_properties props;
291 #define DVB_USB_ADAP_STATE_INIT 0x000
292 #define DVB_USB_ADAP_STATE_DVB 0x001
300 /* tuner programming information */
303 struct dvb_pll_desc *pll_desc;
304 int (*tuner_pass_ctrl) (struct dvb_frontend *, int, u8);
307 struct dvb_adapter dvb_adap;
308 struct dmxdev dmxdev;
309 struct dvb_demux demux;
310 struct dvb_net dvb_net;
311 struct dvb_frontend *fe;
314 int (*fe_sleep) (struct dvb_frontend *);
315 int (*fe_init) (struct dvb_frontend *);
317 struct usb_data_stream stream;
323 * struct dvb_usb_device - object of a DVB USB device
324 * @props: copy of the struct dvb_usb_properties this device belongs to.
325 * @desc: pointer to the device's struct dvb_usb_device_description.
326 * @state: initialization and runtime state of the device.
328 * @udev: pointer to the device's struct usb_device.
330 * @usb_mutex: semaphore of USB control messages (reading needs two messages)
331 * @i2c_mutex: semaphore for i2c-transfers
333 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
335 * @rc_input_dev: input device for the remote control.
336 * @rc_query_work: struct work_struct frequent rc queries
337 * @last_event: last triggered event
338 * @last_state: last state (no, pressed, repeat)
339 * @owner: owner of the dvb_adapter
340 * @priv: private data of the actual driver (allocate by dvb-usb, size defined
341 * in size_of_priv of dvb_usb_properties).
343 struct dvb_usb_device {
344 struct dvb_usb_device_properties props;
345 struct dvb_usb_device_description *desc;
347 struct usb_device *udev;
349 #define DVB_USB_STATE_INIT 0x000
350 #define DVB_USB_STATE_I2C 0x001
351 #define DVB_USB_STATE_DVB 0x002
352 #define DVB_USB_STATE_REMOTE 0x004
358 struct mutex usb_mutex;
361 struct mutex i2c_mutex;
362 struct i2c_adapter i2c_adap;
364 int num_adapters_initialized;
365 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
368 struct input_dev *rc_input_dev;
370 struct work_struct rc_query_work;
374 struct module *owner;
379 extern int dvb_usb_device_init(struct usb_interface *, struct dvb_usb_device_properties *, struct module *, struct dvb_usb_device **);
380 extern void dvb_usb_device_exit(struct usb_interface *);
382 /* the generic read/write method for device control */
383 extern int dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,int);
384 extern int dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
386 /* commonly used remote control parsing */
387 extern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *, int *);
389 /* commonly used pll init and set functions */
390 extern int dvb_usb_tuner_init_i2c(struct dvb_frontend *);
391 extern int dvb_usb_tuner_calc_regs(struct dvb_frontend *, struct dvb_frontend_parameters *, u8 *buf, int buf_len);
392 extern int dvb_usb_tuner_set_params_i2c(struct dvb_frontend *, struct dvb_frontend_parameters *);
394 /* commonly used firmware download types and function */
402 extern int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type);