4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
10 * for more information see dvb-dibusb-core.c .
12 #ifndef __DVB_DIBUSB_H__
13 #define __DVB_DIBUSB_H__
15 #include <linux/input.h>
16 #include <linux/config.h>
17 #include <linux/usb.h>
19 #include "dvb_frontend.h"
20 #include "dvb_demux.h"
28 #ifdef CONFIG_DVB_DIBCOM_DEBUG
29 #define dprintk(level,args...) \
30 do { if ((dvb_dibusb_debug & level)) { printk(args); } } while (0)
32 #define debug_dump(b,l) {\
34 for (i = 0; i < l; i++) deb_xfer("%02x ", b[i]); \
39 #define dprintk(args...)
40 #define debug_dump(b,l)
43 extern int dvb_dibusb_debug
;
45 /* Version information */
46 #define DRIVER_VERSION "0.3"
47 #define DRIVER_DESC "DiBcom based USB Budget DVB-T device"
48 #define DRIVER_AUTHOR "Patrick Boettcher, patrick.boettcher@desy.de"
50 #define deb_info(args...) dprintk(0x01,args)
51 #define deb_xfer(args...) dprintk(0x02,args)
52 #define deb_alot(args...) dprintk(0x04,args)
53 #define deb_ts(args...) dprintk(0x08,args)
54 #define deb_err(args...) dprintk(0x10,args)
55 #define deb_rc(args...) dprintk(0x20,args)
57 /* generic log methods - taken from usb.h */
59 #define err(format, arg...) printk(KERN_ERR "dvb-dibusb: " format "\n" , ## arg)
61 #define info(format, arg...) printk(KERN_INFO "dvb-dibusb: " format "\n" , ## arg)
63 #define warn(format, arg...) printk(KERN_WARNING "dvb-dibusb: " format "\n" , ## arg)
65 struct dibusb_usb_controller
{
66 const char *name
; /* name of the usb controller */
67 u16 cpu_cs_register
; /* needs to be restarted, when the firmware has been downloaded. */
81 DIBUSB_TUNER_CABLE_THOMSON
= 0,
82 DIBUSB_TUNER_COFDM_PANASONIC_ENV57H1XD5
,
83 DIBUSB_TUNER_CABLE_LG_TDTP_E102P
,
84 DIBUSB_TUNER_COFDM_PANASONIC_ENV77H11D5
,
92 } dibusb_demodulator_t
;
96 DIBUSB_RC_NEC_PROTOCOL
,
97 DIBUSB_RC_HAUPPAUGE_PROTO
,
100 struct dibusb_tuner
{
103 u8 pll_addr
; /* tuner i2c address */
105 extern struct dibusb_tuner dibusb_tuner
[];
107 #define DIBUSB_POSSIBLE_I2C_ADDR_NUM 4
108 struct dibusb_demod
{
109 dibusb_demodulator_t id
;
111 int pid_filter_count
; /* counter of the internal pid_filter */
112 u8 i2c_addrs
[DIBUSB_POSSIBLE_I2C_ADDR_NUM
]; /* list of possible i2c addresses of the demod */
115 #define DIBUSB_MAX_TUNER_NUM 2
116 struct dibusb_device_class
{
119 const struct dibusb_usb_controller
*usb_ctrl
; /* usb controller */
120 const char *firmware
; /* valid firmware filenames */
122 int pipe_cmd
; /* command pipe (read/write) */
123 int pipe_data
; /* data pipe */
125 int urb_count
; /* number of data URBs to be submitted */
126 int urb_buffer_size
; /* the size of the buffer for each URB */
128 dibusb_remote_t remote_type
; /* does this device have a ir-receiver */
130 struct dibusb_demod
*demod
; /* which demodulator is mount */
131 struct dibusb_tuner
*tuner
; /* which tuner can be found here */
134 #define DIBUSB_ID_MAX_NUM 15
135 struct dibusb_usb_device
{
136 const char *name
; /* real name of the box */
137 struct dibusb_device_class
*dev_cl
; /* which dibusb_device_class is this device part of */
139 struct usb_device_id
*cold_ids
[DIBUSB_ID_MAX_NUM
]; /* list of USB ids when this device is at pre firmware state */
140 struct usb_device_id
*warm_ids
[DIBUSB_ID_MAX_NUM
]; /* list of USB ids when this device is at post firmware state */
143 /* a PID for the pid_filter list, when in use */
153 struct usb_device
* udev
;
155 struct dibusb_usb_device
* dibdev
;
157 #define DIBUSB_STATE_INIT 0x000
158 #define DIBUSB_STATE_URB_LIST 0x001
159 #define DIBUSB_STATE_URB_BUF 0x002
160 #define DIBUSB_STATE_URB_INIT 0x004
161 #define DIBUSB_STATE_DVB 0x008
162 #define DIBUSB_STATE_I2C 0x010
163 #define DIBUSB_STATE_REMOTE 0x020
164 #define DIBUSB_STATE_URB_SUBMIT 0x040
168 struct dib_fe_xfer_ops xfer_ops
;
170 struct dibusb_tuner
*tuner
;
172 struct urb
**urb_list
;
174 dma_addr_t dma_handle
;
177 struct i2c_adapter i2c_adap
;
180 struct semaphore usb_sem
;
181 struct semaphore i2c_sem
;
184 struct dvb_adapter adapter
;
185 struct dmxdev dmxdev
;
186 struct dvb_demux demux
;
187 struct dvb_net dvb_net
;
188 struct dvb_frontend
* fe
;
190 int (*fe_sleep
) (struct dvb_frontend
*);
191 int (*fe_init
) (struct dvb_frontend
*);
194 struct input_dev rc_input_dev
;
195 struct work_struct rc_query_work
;
197 int last_state
; /* for Hauppauge RC protocol */
198 int repeat_key_count
;
199 int rc_key_repeat_count
; /* module parameter */
201 /* module parameters */
203 int rc_query_interval
;
206 /* commonly used functions in the separated files */
208 /* dvb-dibusb-firmware.c */
209 int dibusb_loadfirmware(struct usb_device
*udev
, struct dibusb_usb_device
*dibdev
);
211 /* dvb-dibusb-remote.c */
212 int dibusb_remote_exit(struct usb_dibusb
*dib
);
213 int dibusb_remote_init(struct usb_dibusb
*dib
);
215 /* dvb-dibusb-fe-i2c.c */
216 int dibusb_fe_init(struct usb_dibusb
* dib
);
217 int dibusb_fe_exit(struct usb_dibusb
*dib
);
218 int dibusb_i2c_init(struct usb_dibusb
*dib
);
219 int dibusb_i2c_exit(struct usb_dibusb
*dib
);
221 /* dvb-dibusb-dvb.c */
222 void dibusb_urb_complete(struct urb
*urb
, struct pt_regs
*ptregs
);
223 int dibusb_dvb_init(struct usb_dibusb
*dib
);
224 int dibusb_dvb_exit(struct usb_dibusb
*dib
);
226 /* dvb-dibusb-usb.c */
227 int dibusb_readwrite_usb(struct usb_dibusb
*dib
, u8
*wbuf
, u16 wlen
, u8
*rbuf
,
229 int dibusb_write_usb(struct usb_dibusb
*dib
, u8
*buf
, u16 len
);
231 int dibusb_hw_wakeup(struct dvb_frontend
*);
232 int dibusb_hw_sleep(struct dvb_frontend
*);
233 int dibusb_set_streaming_mode(struct usb_dibusb
*,u8
);
234 int dibusb_streaming(struct usb_dibusb
*,int);
236 int dibusb_urb_init(struct usb_dibusb
*);
237 int dibusb_urb_exit(struct usb_dibusb
*);
239 /* dvb-fe-dtt200u.c */
240 struct dvb_frontend
* dtt200u_fe_attach(struct usb_dibusb
*,struct dib_fe_xfer_ops
*);
242 /* i2c and transfer stuff */
243 #define DIBUSB_I2C_TIMEOUT 5000
246 * protocol of all dibusb related devices
250 * bulk msg to/from endpoint 0x01
253 * request_byte parameter_bytes
256 #define DIBUSB_REQ_START_READ 0x00
257 #define DIBUSB_REQ_START_DEMOD 0x01
261 * bulk write: 0x02 ((7bit i2c_addr << 1) & 0x01) register_bytes length_word
262 * bulk read: byte_buffer (length_word bytes)
264 #define DIBUSB_REQ_I2C_READ 0x02
268 * bulk write: 0x03 (7bit i2c_addr << 1) register_bytes value_bytes
270 #define DIBUSB_REQ_I2C_WRITE 0x03
273 * polling the value of the remote control
275 * bulk read: byte_buffer (5 bytes)
277 * first byte of byte_buffer shows the status (0x00, 0x01, 0x02)
279 #define DIBUSB_REQ_POLL_REMOTE 0x04
281 #define DIBUSB_RC_NEC_EMPTY 0x00
282 #define DIBUSB_RC_NEC_KEY_PRESSED 0x01
283 #define DIBUSB_RC_NEC_KEY_REPEATED 0x02
285 /* additional status values for Hauppauge Remote Control Protocol */
286 #define DIBUSB_RC_HAUPPAUGE_KEY_PRESSED 0x01
287 #define DIBUSB_RC_HAUPPAUGE_KEY_EMPTY 0x03
290 * bulk write: 0x05 mode_byte
292 * mode_byte is mostly 0x00
294 #define DIBUSB_REQ_SET_STREAMING_MODE 0x05
296 /* interrupt the internal read loop, when blocking */
297 #define DIBUSB_REQ_INTR_READ 0x06
300 * 0x07 cmd_byte param_bytes
302 * param_bytes can be up to 32 bytes
304 * cmd_byte function parameter name
309 * 0x01 enable streaming
310 * 0x02 disable streaming
314 #define DIBUSB_REQ_SET_IOCTL 0x07
318 /* change the power mode in firmware */
319 #define DIBUSB_IOCTL_CMD_POWER_MODE 0x00
320 #define DIBUSB_IOCTL_POWER_SLEEP 0x00
321 #define DIBUSB_IOCTL_POWER_WAKEUP 0x01
323 /* modify streaming of the FX2 */
324 #define DIBUSB_IOCTL_CMD_ENABLE_STREAM 0x01
325 #define DIBUSB_IOCTL_CMD_DISABLE_STREAM 0x02