xref: /OK3568_Linux_fs/kernel/drivers/media/usb/dvb-usb/dvb-usb.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /* dvb-usb.h is part of the DVB USB library.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@posteo.de)
5*4882a593Smuzhiyun  * see dvb-usb-init.c for copyright information.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * the headerfile, all dvb-usb-drivers have to include.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * TODO: clean-up the structures for unused fields and update the comments
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun #ifndef __DVB_USB_H__
12*4882a593Smuzhiyun #define __DVB_USB_H__
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #include <linux/input.h>
15*4882a593Smuzhiyun #include <linux/usb.h>
16*4882a593Smuzhiyun #include <linux/firmware.h>
17*4882a593Smuzhiyun #include <linux/mutex.h>
18*4882a593Smuzhiyun #include <media/rc-core.h>
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #include <media/dvb_frontend.h>
21*4882a593Smuzhiyun #include <media/dvb_demux.h>
22*4882a593Smuzhiyun #include <media/dvb_net.h>
23*4882a593Smuzhiyun #include <media/dmxdev.h>
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #include "dvb-pll.h"
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #include <media/dvb-usb-ids.h>
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun /* debug */
30*4882a593Smuzhiyun #ifdef CONFIG_DVB_USB_DEBUG
31*4882a593Smuzhiyun #define dprintk(var,level,args...) \
32*4882a593Smuzhiyun 	    do { if ((var & level)) { printk(args); } } while (0)
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #define debug_dump(b,l,func) {\
35*4882a593Smuzhiyun 	int loop_; \
36*4882a593Smuzhiyun 	for (loop_ = 0; loop_ < l; loop_++) func("%02x ", b[loop_]); \
37*4882a593Smuzhiyun 	func("\n");\
38*4882a593Smuzhiyun }
39*4882a593Smuzhiyun #define DVB_USB_DEBUG_STATUS
40*4882a593Smuzhiyun #else
41*4882a593Smuzhiyun #define dprintk(args...)
42*4882a593Smuzhiyun #define debug_dump(b,l,func)
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun #define DVB_USB_DEBUG_STATUS " (debugging is not enabled)"
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun #endif
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /* generic log methods - taken from usb.h */
49*4882a593Smuzhiyun #ifndef DVB_USB_LOG_PREFIX
50*4882a593Smuzhiyun  #define DVB_USB_LOG_PREFIX "dvb-usb (please define a log prefix)"
51*4882a593Smuzhiyun #endif
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun #undef err
54*4882a593Smuzhiyun #define err(format, arg...)  printk(KERN_ERR     DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
55*4882a593Smuzhiyun #undef info
56*4882a593Smuzhiyun #define info(format, arg...) printk(KERN_INFO    DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
57*4882a593Smuzhiyun #undef warn
58*4882a593Smuzhiyun #define warn(format, arg...) printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /**
61*4882a593Smuzhiyun  * struct dvb_usb_device_description - name and its according USB IDs
62*4882a593Smuzhiyun  * @name: real name of the box, regardless which DVB USB device class is in use
63*4882a593Smuzhiyun  * @cold_ids: array of struct usb_device_id which describe the device in
64*4882a593Smuzhiyun  *  pre-firmware state
65*4882a593Smuzhiyun  * @warm_ids: array of struct usb_device_id which describe the device in
66*4882a593Smuzhiyun  *  post-firmware state
67*4882a593Smuzhiyun  *
68*4882a593Smuzhiyun  * Each DVB USB device class can have one or more actual devices, this struct
69*4882a593Smuzhiyun  * assigns a name to it.
70*4882a593Smuzhiyun  */
71*4882a593Smuzhiyun struct dvb_usb_device_description {
72*4882a593Smuzhiyun 	const char *name;
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun #define DVB_USB_ID_MAX_NUM 15
75*4882a593Smuzhiyun 	struct usb_device_id *cold_ids[DVB_USB_ID_MAX_NUM];
76*4882a593Smuzhiyun 	struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM];
77*4882a593Smuzhiyun };
78*4882a593Smuzhiyun 
rc5_custom(struct rc_map_table * key)79*4882a593Smuzhiyun static inline u8 rc5_custom(struct rc_map_table *key)
80*4882a593Smuzhiyun {
81*4882a593Smuzhiyun 	return (key->scancode >> 8) & 0xff;
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun 
rc5_data(struct rc_map_table * key)84*4882a593Smuzhiyun static inline u8 rc5_data(struct rc_map_table *key)
85*4882a593Smuzhiyun {
86*4882a593Smuzhiyun 	return key->scancode & 0xff;
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun 
rc5_scan(struct rc_map_table * key)89*4882a593Smuzhiyun static inline u16 rc5_scan(struct rc_map_table *key)
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun 	return key->scancode & 0xffff;
92*4882a593Smuzhiyun }
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun struct dvb_usb_device;
95*4882a593Smuzhiyun struct dvb_usb_adapter;
96*4882a593Smuzhiyun struct usb_data_stream;
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun /**
99*4882a593Smuzhiyun  * Properties of USB streaming - TODO this structure should be somewhere else
100*4882a593Smuzhiyun  * describes the kind of USB transfer used for data-streaming.
101*4882a593Smuzhiyun  *  (BULK or ISOC)
102*4882a593Smuzhiyun  */
103*4882a593Smuzhiyun struct usb_data_stream_properties {
104*4882a593Smuzhiyun #define USB_BULK  1
105*4882a593Smuzhiyun #define USB_ISOC  2
106*4882a593Smuzhiyun 	int type;
107*4882a593Smuzhiyun 	int count;
108*4882a593Smuzhiyun 	int endpoint;
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun 	union {
111*4882a593Smuzhiyun 		struct {
112*4882a593Smuzhiyun 			int buffersize; /* per URB */
113*4882a593Smuzhiyun 		} bulk;
114*4882a593Smuzhiyun 		struct {
115*4882a593Smuzhiyun 			int framesperurb;
116*4882a593Smuzhiyun 			int framesize;
117*4882a593Smuzhiyun 			int interval;
118*4882a593Smuzhiyun 		} isoc;
119*4882a593Smuzhiyun 	} u;
120*4882a593Smuzhiyun };
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun /**
123*4882a593Smuzhiyun  * struct dvb_usb_adapter_properties - properties of a dvb-usb-adapter.
124*4882a593Smuzhiyun  *    A DVB-USB-Adapter is basically a dvb_adapter which is present on a USB-device.
125*4882a593Smuzhiyun  * @caps: capabilities of the DVB USB device.
126*4882a593Smuzhiyun  * @pid_filter_count: number of PID filter position in the optional hardware
127*4882a593Smuzhiyun  *  PID-filter.
128*4882a593Smuzhiyun  * @num_frontends: number of frontends of the DVB USB adapter.
129*4882a593Smuzhiyun  * @frontend_ctrl: called to power on/off active frontend.
130*4882a593Smuzhiyun  * @streaming_ctrl: called to start and stop the MPEG2-TS streaming of the
131*4882a593Smuzhiyun  *  device (not URB submitting/killing).
132*4882a593Smuzhiyun  *  This callback will be called without data URBs being active - data URBs
133*4882a593Smuzhiyun  *  will be submitted only after streaming_ctrl(1) returns successfully and
134*4882a593Smuzhiyun  *  they will be killed before streaming_ctrl(0) gets called.
135*4882a593Smuzhiyun  * @pid_filter_ctrl: called to en/disable the PID filter, if any.
136*4882a593Smuzhiyun  * @pid_filter: called to set/unset a PID for filtering.
137*4882a593Smuzhiyun  * @frontend_attach: called to attach the possible frontends (fill fe-field
138*4882a593Smuzhiyun  *  of struct dvb_usb_device).
139*4882a593Smuzhiyun  * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
140*4882a593Smuzhiyun  *  pll_desc and pll_init_buf of struct dvb_usb_device).
141*4882a593Smuzhiyun  * @stream: configuration of the USB streaming
142*4882a593Smuzhiyun  */
143*4882a593Smuzhiyun struct dvb_usb_adapter_fe_properties {
144*4882a593Smuzhiyun #define DVB_USB_ADAP_HAS_PID_FILTER               0x01
145*4882a593Smuzhiyun #define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
146*4882a593Smuzhiyun #define DVB_USB_ADAP_NEED_PID_FILTERING           0x04
147*4882a593Smuzhiyun #define DVB_USB_ADAP_RECEIVES_204_BYTE_TS         0x08
148*4882a593Smuzhiyun #define DVB_USB_ADAP_RECEIVES_RAW_PAYLOAD         0x10
149*4882a593Smuzhiyun 	int caps;
150*4882a593Smuzhiyun 	int pid_filter_count;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	int (*streaming_ctrl)  (struct dvb_usb_adapter *, int);
153*4882a593Smuzhiyun 	int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);
154*4882a593Smuzhiyun 	int (*pid_filter)      (struct dvb_usb_adapter *, int, u16, int);
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun 	int (*frontend_attach) (struct dvb_usb_adapter *);
157*4882a593Smuzhiyun 	int (*tuner_attach)    (struct dvb_usb_adapter *);
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	struct usb_data_stream_properties stream;
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun 	int size_of_priv;
162*4882a593Smuzhiyun };
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun #define MAX_NO_OF_FE_PER_ADAP 3
165*4882a593Smuzhiyun struct dvb_usb_adapter_properties {
166*4882a593Smuzhiyun 	int size_of_priv;
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun 	int (*frontend_ctrl)   (struct dvb_frontend *, int);
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun 	int num_frontends;
171*4882a593Smuzhiyun 	struct dvb_usb_adapter_fe_properties fe[MAX_NO_OF_FE_PER_ADAP];
172*4882a593Smuzhiyun };
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun /**
175*4882a593Smuzhiyun  * struct dvb_rc_legacy - old properties of remote controller
176*4882a593Smuzhiyun  * @rc_map_table: a hard-wired array of struct rc_map_table (NULL to disable
177*4882a593Smuzhiyun  *  remote control handling).
178*4882a593Smuzhiyun  * @rc_map_size: number of items in @rc_map_table.
179*4882a593Smuzhiyun  * @rc_query: called to query an event event.
180*4882a593Smuzhiyun  * @rc_interval: time in ms between two queries.
181*4882a593Smuzhiyun  */
182*4882a593Smuzhiyun struct dvb_rc_legacy {
183*4882a593Smuzhiyun /* remote control properties */
184*4882a593Smuzhiyun #define REMOTE_NO_KEY_PRESSED      0x00
185*4882a593Smuzhiyun #define REMOTE_KEY_PRESSED         0x01
186*4882a593Smuzhiyun #define REMOTE_KEY_REPEAT          0x02
187*4882a593Smuzhiyun 	struct rc_map_table  *rc_map_table;
188*4882a593Smuzhiyun 	int rc_map_size;
189*4882a593Smuzhiyun 	int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
190*4882a593Smuzhiyun 	int rc_interval;
191*4882a593Smuzhiyun };
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun /**
194*4882a593Smuzhiyun  * struct dvb_rc properties of remote controller, using rc-core
195*4882a593Smuzhiyun  * @rc_codes: name of rc codes table
196*4882a593Smuzhiyun  * @protocol: type of protocol(s) currently used by the driver
197*4882a593Smuzhiyun  * @allowed_protos: protocol(s) supported by the driver
198*4882a593Smuzhiyun  * @driver_type: Used to point if a device supports raw mode
199*4882a593Smuzhiyun  * @change_protocol: callback to change protocol
200*4882a593Smuzhiyun  * @rc_query: called to query an event event.
201*4882a593Smuzhiyun  * @rc_interval: time in ms between two queries.
202*4882a593Smuzhiyun  * @bulk_mode: device supports bulk mode for RC (disable polling mode)
203*4882a593Smuzhiyun  */
204*4882a593Smuzhiyun struct dvb_rc {
205*4882a593Smuzhiyun 	char *rc_codes;
206*4882a593Smuzhiyun 	u64 protocol;
207*4882a593Smuzhiyun 	u64 allowed_protos;
208*4882a593Smuzhiyun 	enum rc_driver_type driver_type;
209*4882a593Smuzhiyun 	int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto);
210*4882a593Smuzhiyun 	char *module_name;
211*4882a593Smuzhiyun 	int (*rc_query) (struct dvb_usb_device *d);
212*4882a593Smuzhiyun 	int rc_interval;
213*4882a593Smuzhiyun 	bool bulk_mode;				/* uses bulk mode */
214*4882a593Smuzhiyun 	u32 scancode_mask;
215*4882a593Smuzhiyun };
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun /**
218*4882a593Smuzhiyun  * enum dvb_usb_mode - Specifies if it is using a legacy driver or a new one
219*4882a593Smuzhiyun  *		       based on rc-core
220*4882a593Smuzhiyun  * This is initialized/used only inside dvb-usb-remote.c.
221*4882a593Smuzhiyun  * It shouldn't be set by the drivers.
222*4882a593Smuzhiyun  */
223*4882a593Smuzhiyun enum dvb_usb_mode {
224*4882a593Smuzhiyun 	DVB_RC_LEGACY,
225*4882a593Smuzhiyun 	DVB_RC_CORE,
226*4882a593Smuzhiyun };
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun /**
229*4882a593Smuzhiyun  * struct dvb_usb_device_properties - properties of a dvb-usb-device
230*4882a593Smuzhiyun  * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
231*4882a593Smuzhiyun  *  download.
232*4882a593Smuzhiyun  * @firmware: name of the firmware file.
233*4882a593Smuzhiyun  * @download_firmware: called to download the firmware when the usb_ctrl is
234*4882a593Smuzhiyun  *  DEVICE_SPECIFIC.
235*4882a593Smuzhiyun  * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
236*4882a593Smuzhiyun  *  so do the warm initialization right after it
237*4882a593Smuzhiyun  *
238*4882a593Smuzhiyun  * @size_of_priv: how many bytes shall be allocated for the private field
239*4882a593Smuzhiyun  *  of struct dvb_usb_device.
240*4882a593Smuzhiyun  * @priv_init: optional callback to initialize the variable that private field
241*4882a593Smuzhiyun  * of struct dvb_usb_device has pointer to just after it had been allocated and
242*4882a593Smuzhiyun  * zeroed.
243*4882a593Smuzhiyun  * @priv_destroy: just like priv_init, only called before deallocating
244*4882a593Smuzhiyun  * the memory pointed by private field of struct dvb_usb_device.
245*4882a593Smuzhiyun  *
246*4882a593Smuzhiyun  * @power_ctrl: called to enable/disable power of the device.
247*4882a593Smuzhiyun  * @read_mac_address: called to read the MAC address of the device.
248*4882a593Smuzhiyun  * @identify_state: called to determine the state (cold or warm), when it
249*4882a593Smuzhiyun  *  is not distinguishable by the USB IDs.
250*4882a593Smuzhiyun  *
251*4882a593Smuzhiyun  * @rc: remote controller properties
252*4882a593Smuzhiyun  *
253*4882a593Smuzhiyun  * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
254*4882a593Smuzhiyun  *
255*4882a593Smuzhiyun  * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
256*4882a593Smuzhiyun  *  endpoint which received control messages with bulk transfers. When this
257*4882a593Smuzhiyun  *  is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
258*4882a593Smuzhiyun  *  helper functions.
259*4882a593Smuzhiyun  *
260*4882a593Smuzhiyun  * @generic_bulk_ctrl_endpoint_response: some DVB USB devices use a separate
261*4882a593Smuzhiyun  *  endpoint for responses to control messages sent with bulk transfers via
262*4882a593Smuzhiyun  *  the generic_bulk_ctrl_endpoint. When this is non-zero, this will be used
263*4882a593Smuzhiyun  *  instead of the generic_bulk_ctrl_endpoint when reading usb responses in
264*4882a593Smuzhiyun  *  the dvb_usb_generic_rw helper function.
265*4882a593Smuzhiyun  *
266*4882a593Smuzhiyun  * @num_device_descs: number of struct dvb_usb_device_description in @devices
267*4882a593Smuzhiyun  * @devices: array of struct dvb_usb_device_description compatibles with these
268*4882a593Smuzhiyun  *  properties.
269*4882a593Smuzhiyun  */
270*4882a593Smuzhiyun #define MAX_NO_OF_ADAPTER_PER_DEVICE 2
271*4882a593Smuzhiyun struct dvb_usb_device_properties {
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun #define DVB_USB_IS_AN_I2C_ADAPTER            0x01
274*4882a593Smuzhiyun 	int caps;
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun #define DEVICE_SPECIFIC 0
277*4882a593Smuzhiyun #define CYPRESS_AN2135  1
278*4882a593Smuzhiyun #define CYPRESS_AN2235  2
279*4882a593Smuzhiyun #define CYPRESS_FX2     3
280*4882a593Smuzhiyun 	int        usb_ctrl;
281*4882a593Smuzhiyun 	int        (*download_firmware) (struct usb_device *, const struct firmware *);
282*4882a593Smuzhiyun 	const char *firmware;
283*4882a593Smuzhiyun 	int        no_reconnect;
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun 	int size_of_priv;
286*4882a593Smuzhiyun 	int (*priv_init)(struct dvb_usb_device *);
287*4882a593Smuzhiyun 	void (*priv_destroy)(struct dvb_usb_device *);
288*4882a593Smuzhiyun 
289*4882a593Smuzhiyun 	int num_adapters;
290*4882a593Smuzhiyun 	struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun 	int (*power_ctrl)       (struct dvb_usb_device *, int);
293*4882a593Smuzhiyun 	int (*read_mac_address) (struct dvb_usb_device *, u8 []);
294*4882a593Smuzhiyun 	int (*identify_state)(struct usb_device *udev,
295*4882a593Smuzhiyun 			      const struct dvb_usb_device_properties *props,
296*4882a593Smuzhiyun 			      const struct dvb_usb_device_description **desc,
297*4882a593Smuzhiyun 			      int *cold);
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun 	struct {
300*4882a593Smuzhiyun 		enum dvb_usb_mode mode;	/* Drivers shouldn't touch on it */
301*4882a593Smuzhiyun 		struct dvb_rc_legacy legacy;
302*4882a593Smuzhiyun 		struct dvb_rc core;
303*4882a593Smuzhiyun 	} rc;
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun 	struct i2c_algorithm *i2c_algo;
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun 	int generic_bulk_ctrl_endpoint;
308*4882a593Smuzhiyun 	int generic_bulk_ctrl_endpoint_response;
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun 	int num_device_descs;
311*4882a593Smuzhiyun 	struct dvb_usb_device_description devices[12];
312*4882a593Smuzhiyun };
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun /**
315*4882a593Smuzhiyun  * struct usb_data_stream - generic object of an USB stream
316*4882a593Smuzhiyun  * @buf_num: number of buffer allocated.
317*4882a593Smuzhiyun  * @buf_size: size of each buffer in buf_list.
318*4882a593Smuzhiyun  * @buf_list: array containing all allocate buffers for streaming.
319*4882a593Smuzhiyun  * @dma_addr: list of dma_addr_t for each buffer in buf_list.
320*4882a593Smuzhiyun  *
321*4882a593Smuzhiyun  * @urbs_initialized: number of URBs initialized.
322*4882a593Smuzhiyun  * @urbs_submitted: number of URBs submitted.
323*4882a593Smuzhiyun  */
324*4882a593Smuzhiyun #define MAX_NO_URBS_FOR_DATA_STREAM 10
325*4882a593Smuzhiyun struct usb_data_stream {
326*4882a593Smuzhiyun 	struct usb_device                 *udev;
327*4882a593Smuzhiyun 	struct usb_data_stream_properties  props;
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun #define USB_STATE_INIT    0x00
330*4882a593Smuzhiyun #define USB_STATE_URB_BUF 0x01
331*4882a593Smuzhiyun 	int state;
332*4882a593Smuzhiyun 
333*4882a593Smuzhiyun 	void (*complete) (struct usb_data_stream *, u8 *, size_t);
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun 	struct urb    *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
336*4882a593Smuzhiyun 	int            buf_num;
337*4882a593Smuzhiyun 	unsigned long  buf_size;
338*4882a593Smuzhiyun 	u8            *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
339*4882a593Smuzhiyun 	dma_addr_t     dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
340*4882a593Smuzhiyun 
341*4882a593Smuzhiyun 	int urbs_initialized;
342*4882a593Smuzhiyun 	int urbs_submitted;
343*4882a593Smuzhiyun 
344*4882a593Smuzhiyun 	void *user_priv;
345*4882a593Smuzhiyun };
346*4882a593Smuzhiyun 
347*4882a593Smuzhiyun /**
348*4882a593Smuzhiyun  * struct dvb_usb_adapter - a DVB adapter on a USB device
349*4882a593Smuzhiyun  * @id: index of this adapter (starting with 0).
350*4882a593Smuzhiyun  *
351*4882a593Smuzhiyun  * @feedcount: number of requested feeds (used for streaming-activation)
352*4882a593Smuzhiyun  * @pid_filtering: is hardware pid_filtering used or not.
353*4882a593Smuzhiyun  *
354*4882a593Smuzhiyun  * @pll_addr: I2C address of the tuner for programming
355*4882a593Smuzhiyun  * @pll_init: array containing the initialization buffer
356*4882a593Smuzhiyun  * @pll_desc: pointer to the appropriate struct dvb_pll_desc
357*4882a593Smuzhiyun  * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or the board
358*4882a593Smuzhiyun  *
359*4882a593Smuzhiyun  * @dvb_adap: device's dvb_adapter.
360*4882a593Smuzhiyun  * @dmxdev: device's dmxdev.
361*4882a593Smuzhiyun  * @demux: device's software demuxer.
362*4882a593Smuzhiyun  * @dvb_net: device's dvb_net interfaces.
363*4882a593Smuzhiyun  * @dvb_frontend: device's frontend.
364*4882a593Smuzhiyun  * @max_feed_count: how many feeds can be handled simultaneously by this
365*4882a593Smuzhiyun  *  device
366*4882a593Smuzhiyun  *
367*4882a593Smuzhiyun  * @fe_init:  rerouted frontend-init (wakeup) function.
368*4882a593Smuzhiyun  * @fe_sleep: rerouted frontend-sleep function.
369*4882a593Smuzhiyun  *
370*4882a593Smuzhiyun  * @stream: the usb data stream.
371*4882a593Smuzhiyun  */
372*4882a593Smuzhiyun struct dvb_usb_fe_adapter {
373*4882a593Smuzhiyun 	struct dvb_frontend *fe;
374*4882a593Smuzhiyun 
375*4882a593Smuzhiyun 	int (*fe_init)  (struct dvb_frontend *);
376*4882a593Smuzhiyun 	int (*fe_sleep) (struct dvb_frontend *);
377*4882a593Smuzhiyun 
378*4882a593Smuzhiyun 	struct usb_data_stream stream;
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun 	int pid_filtering;
381*4882a593Smuzhiyun 	int max_feed_count;
382*4882a593Smuzhiyun 
383*4882a593Smuzhiyun 	void *priv;
384*4882a593Smuzhiyun };
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun struct dvb_usb_adapter {
387*4882a593Smuzhiyun 	struct dvb_usb_device *dev;
388*4882a593Smuzhiyun 	struct dvb_usb_adapter_properties props;
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun #define DVB_USB_ADAP_STATE_INIT 0x000
391*4882a593Smuzhiyun #define DVB_USB_ADAP_STATE_DVB  0x001
392*4882a593Smuzhiyun 	int state;
393*4882a593Smuzhiyun 
394*4882a593Smuzhiyun 	u8  id;
395*4882a593Smuzhiyun 
396*4882a593Smuzhiyun 	int feedcount;
397*4882a593Smuzhiyun 
398*4882a593Smuzhiyun 	/* dvb */
399*4882a593Smuzhiyun 	struct dvb_adapter   dvb_adap;
400*4882a593Smuzhiyun 	struct dmxdev        dmxdev;
401*4882a593Smuzhiyun 	struct dvb_demux     demux;
402*4882a593Smuzhiyun 	struct dvb_net       dvb_net;
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun 	struct dvb_usb_fe_adapter fe_adap[MAX_NO_OF_FE_PER_ADAP];
405*4882a593Smuzhiyun 	int active_fe;
406*4882a593Smuzhiyun 	int num_frontends_initialized;
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun 	void *priv;
409*4882a593Smuzhiyun };
410*4882a593Smuzhiyun 
411*4882a593Smuzhiyun /**
412*4882a593Smuzhiyun  * struct dvb_usb_device - object of a DVB USB device
413*4882a593Smuzhiyun  * @props: copy of the struct dvb_usb_properties this device belongs to.
414*4882a593Smuzhiyun  * @desc: pointer to the device's struct dvb_usb_device_description.
415*4882a593Smuzhiyun  * @state: initialization and runtime state of the device.
416*4882a593Smuzhiyun  *
417*4882a593Smuzhiyun  * @powered: indicated whether the device is power or not.
418*4882a593Smuzhiyun  *  Powered is in/decremented for each call to modify the state.
419*4882a593Smuzhiyun  * @udev: pointer to the device's struct usb_device.
420*4882a593Smuzhiyun  *
421*4882a593Smuzhiyun  * @data_mutex: mutex to protect the data structure used to store URB data
422*4882a593Smuzhiyun  * @usb_mutex: mutex of USB control messages (reading needs two messages).
423*4882a593Smuzhiyun  *	Please notice that this mutex is used internally at the generic
424*4882a593Smuzhiyun  *	URB control functions. So, drivers using dvb_usb_generic_rw() and
425*4882a593Smuzhiyun  *	derivated functions should not lock it internally.
426*4882a593Smuzhiyun  * @i2c_mutex: mutex for i2c-transfers
427*4882a593Smuzhiyun  *
428*4882a593Smuzhiyun  * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
429*4882a593Smuzhiyun  *
430*4882a593Smuzhiyun  * @rc_dev: rc device for the remote control (rc-core mode)
431*4882a593Smuzhiyun  * @input_dev: input device for the remote control (legacy mode)
432*4882a593Smuzhiyun  * @rc_query_work: struct work_struct frequent rc queries
433*4882a593Smuzhiyun  * @last_event: last triggered event
434*4882a593Smuzhiyun  * @last_state: last state (no, pressed, repeat)
435*4882a593Smuzhiyun  * @owner: owner of the dvb_adapter
436*4882a593Smuzhiyun  * @priv: private data of the actual driver (allocate by dvb-usb, size defined
437*4882a593Smuzhiyun  *  in size_of_priv of dvb_usb_properties).
438*4882a593Smuzhiyun  */
439*4882a593Smuzhiyun struct dvb_usb_device {
440*4882a593Smuzhiyun 	struct dvb_usb_device_properties props;
441*4882a593Smuzhiyun 	const struct dvb_usb_device_description *desc;
442*4882a593Smuzhiyun 
443*4882a593Smuzhiyun 	struct usb_device *udev;
444*4882a593Smuzhiyun 
445*4882a593Smuzhiyun #define DVB_USB_STATE_INIT        0x000
446*4882a593Smuzhiyun #define DVB_USB_STATE_I2C         0x001
447*4882a593Smuzhiyun #define DVB_USB_STATE_DVB         0x002
448*4882a593Smuzhiyun #define DVB_USB_STATE_REMOTE      0x004
449*4882a593Smuzhiyun 	int state;
450*4882a593Smuzhiyun 
451*4882a593Smuzhiyun 	int powered;
452*4882a593Smuzhiyun 
453*4882a593Smuzhiyun 	/* locking */
454*4882a593Smuzhiyun 	struct mutex data_mutex;
455*4882a593Smuzhiyun 	struct mutex usb_mutex;
456*4882a593Smuzhiyun 
457*4882a593Smuzhiyun 	/* i2c */
458*4882a593Smuzhiyun 	struct mutex i2c_mutex;
459*4882a593Smuzhiyun 	struct i2c_adapter i2c_adap;
460*4882a593Smuzhiyun 
461*4882a593Smuzhiyun 	int                    num_adapters_initialized;
462*4882a593Smuzhiyun 	struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
463*4882a593Smuzhiyun 
464*4882a593Smuzhiyun 	/* remote control */
465*4882a593Smuzhiyun 	struct rc_dev *rc_dev;
466*4882a593Smuzhiyun 	struct input_dev *input_dev;
467*4882a593Smuzhiyun 	char rc_phys[64];
468*4882a593Smuzhiyun 	struct delayed_work rc_query_work;
469*4882a593Smuzhiyun 	u32 last_event;
470*4882a593Smuzhiyun 	int last_state;
471*4882a593Smuzhiyun 
472*4882a593Smuzhiyun 	struct module *owner;
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun 	void *priv;
475*4882a593Smuzhiyun };
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun extern int dvb_usb_device_init(struct usb_interface *,
478*4882a593Smuzhiyun 			       const struct dvb_usb_device_properties *,
479*4882a593Smuzhiyun 			       struct module *, struct dvb_usb_device **,
480*4882a593Smuzhiyun 			       short *adapter_nums);
481*4882a593Smuzhiyun extern void dvb_usb_device_exit(struct usb_interface *);
482*4882a593Smuzhiyun 
483*4882a593Smuzhiyun /* the generic read/write method for device control */
484*4882a593Smuzhiyun extern int __must_check
485*4882a593Smuzhiyun dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16, int);
486*4882a593Smuzhiyun extern int __must_check
487*4882a593Smuzhiyun dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun /* commonly used remote control parsing */
490*4882a593Smuzhiyun extern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[5], u32 *, int *);
491*4882a593Smuzhiyun 
492*4882a593Smuzhiyun /* commonly used firmware download types and function */
493*4882a593Smuzhiyun struct hexline {
494*4882a593Smuzhiyun 	u8 len;
495*4882a593Smuzhiyun 	u32 addr;
496*4882a593Smuzhiyun 	u8 type;
497*4882a593Smuzhiyun 	u8 data[255];
498*4882a593Smuzhiyun 	u8 chk;
499*4882a593Smuzhiyun };
500*4882a593Smuzhiyun extern int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type);
501*4882a593Smuzhiyun extern int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx, int *pos);
502*4882a593Smuzhiyun 
503*4882a593Smuzhiyun 
504*4882a593Smuzhiyun #endif
505