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 "Driver for 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 */
58 #define err(format, arg...) printk(KERN_ERR "%s: " format "\n" , __FILE__ , ## arg)
59 #define info(format, arg...) printk(KERN_INFO "%s: " format "\n" , __FILE__ , ## arg)
60 #define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n" , __FILE__ , ## arg)
62 struct dibusb_usb_controller {
63 const char *name; /* name of the usb controller */
64 u16 cpu_cs_register; /* needs to be restarted, when the firmware has been downloaded. */
75 DIBUSB_TUNER_CABLE_THOMSON = 0,
76 DIBUSB_TUNER_COFDM_PANASONIC_ENV57H1XD5,
77 DIBUSB_TUNER_CABLE_LG_TDTP_E102P,
78 DIBUSB_TUNER_COFDM_PANASONIC_ENV77H11D5,
85 } dibusb_demodulator_t;
89 DIBUSB_RC_NEC_PROTOCOL = 1,
95 u8 pll_addr; /* tuner i2c address */
97 extern struct dibusb_tuner dibusb_tuner[];
99 #define DIBUSB_POSSIBLE_I2C_ADDR_NUM 4
100 struct dibusb_demod {
101 dibusb_demodulator_t id;
103 int pid_filter_count; /* counter of the internal pid_filter */
104 u8 i2c_addrs[DIBUSB_POSSIBLE_I2C_ADDR_NUM]; /* list of possible i2c addresses of the demod */
107 #define DIBUSB_MAX_TUNER_NUM 2
108 struct dibusb_device_class {
111 const struct dibusb_usb_controller *usb_ctrl; /* usb controller */
112 const char *firmware; /* valid firmware filenames */
114 int pipe_cmd; /* command pipe (read/write) */
115 int pipe_data; /* data pipe */
117 int urb_count; /* number of data URBs to be submitted */
118 int urb_buffer_size; /* the size of the buffer for each URB */
120 dibusb_remote_t remote_type; /* does this device have a ir-receiver */
122 struct dibusb_demod *demod; /* which demodulator is mount */
123 struct dibusb_tuner *tuner; /* which tuner can be found here */
126 #define DIBUSB_ID_MAX_NUM 15
127 struct dibusb_usb_device {
128 const char *name; /* real name of the box */
129 struct dibusb_device_class *dev_cl; /* which dibusb_device_class is this device part of */
131 struct usb_device_id *cold_ids[DIBUSB_ID_MAX_NUM]; /* list of USB ids when this device is at pre firmware state */
132 struct usb_device_id *warm_ids[DIBUSB_ID_MAX_NUM]; /* list of USB ids when this device is at post firmware state */
135 /* a PID for the pid_filter list, when in use */
145 struct usb_device * udev;
147 struct dibusb_usb_device * dibdev;
149 #define DIBUSB_STATE_INIT 0x000
150 #define DIBUSB_STATE_URB_LIST 0x001
151 #define DIBUSB_STATE_URB_BUF 0x002
152 #define DIBUSB_STATE_URB_SUBMIT 0x004
153 #define DIBUSB_STATE_DVB 0x008
154 #define DIBUSB_STATE_I2C 0x010
155 #define DIBUSB_STATE_REMOTE 0x020
156 #define DIBUSB_STATE_PIDLIST 0x040
160 struct dib_fe_xfer_ops xfer_ops;
162 struct dibusb_tuner *tuner;
164 struct urb **urb_list;
166 dma_addr_t dma_handle;
169 struct i2c_adapter i2c_adap;
172 struct semaphore usb_sem;
173 struct semaphore i2c_sem;
176 spinlock_t pid_list_lock;
177 struct dibusb_pid *pid_list;
180 struct dvb_adapter *adapter;
181 struct dmxdev dmxdev;
182 struct dvb_demux demux;
183 struct dvb_net dvb_net;
184 struct dvb_frontend* fe;
186 int (*fe_sleep) (struct dvb_frontend *);
187 int (*fe_init) (struct dvb_frontend *);
190 struct input_dev rc_input_dev;
191 struct work_struct rc_query_work;
194 /* module parameters */
196 int rc_query_interval;
199 /* commonly used functions in the separated files */
201 /* dvb-dibusb-firmware.c */
202 int dibusb_loadfirmware(struct usb_device *udev, struct dibusb_usb_device *dibdev);
204 /* dvb-dibusb-remote.c */
205 int dibusb_remote_exit(struct usb_dibusb *dib);
206 int dibusb_remote_init(struct usb_dibusb *dib);
208 /* dvb-dibusb-fe-i2c.c */
209 int dibusb_i2c_msg(struct usb_dibusb *dib, u8 addr,
210 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen);
211 int dibusb_fe_init(struct usb_dibusb* dib);
212 int dibusb_fe_exit(struct usb_dibusb *dib);
213 int dibusb_i2c_init(struct usb_dibusb *dib);
214 int dibusb_i2c_exit(struct usb_dibusb *dib);
216 /* dvb-dibusb-dvb.c */
217 void dibusb_urb_complete(struct urb *urb, struct pt_regs *ptregs);
218 int dibusb_dvb_init(struct usb_dibusb *dib);
219 int dibusb_dvb_exit(struct usb_dibusb *dib);
221 /* dvb-dibusb-usb.c */
222 int dibusb_readwrite_usb(struct usb_dibusb *dib, u8 *wbuf, u16 wlen, u8 *rbuf,
225 int dibusb_hw_wakeup(struct dvb_frontend *);
226 int dibusb_hw_sleep(struct dvb_frontend *);
227 int dibusb_set_streaming_mode(struct usb_dibusb *,u8);
228 int dibusb_streaming(struct usb_dibusb *,int);
230 int dibusb_urb_init(struct usb_dibusb *);
231 int dibusb_urb_exit(struct usb_dibusb *);
233 /* dvb-dibusb-pid.c */
234 int dibusb_pid_list_init(struct usb_dibusb *dib);
235 void dibusb_pid_list_exit(struct usb_dibusb *dib);
236 int dibusb_ctrl_pid(struct usb_dibusb *dib, struct dvb_demux_feed *dvbdmxfeed , int onoff);
238 /* i2c and transfer stuff */
239 #define DIBUSB_I2C_TIMEOUT HZ*5
242 * protocol of all dibusb related devices
246 * bulk msg to/from endpoint 0x01
249 * request_byte parameter_bytes
252 #define DIBUSB_REQ_START_READ 0x00
253 #define DIBUSB_REQ_START_DEMOD 0x01
257 * bulk write: 0x02 ((7bit i2c_addr << 1) & 0x01) register_bytes length_word
258 * bulk read: byte_buffer (length_word bytes)
260 #define DIBUSB_REQ_I2C_READ 0x02
264 * bulk write: 0x03 (7bit i2c_addr << 1) register_bytes value_bytes
266 #define DIBUSB_REQ_I2C_WRITE 0x03
269 * polling the value of the remote control
271 * bulk read: byte_buffer (5 bytes)
273 * first byte of byte_buffer shows the status (0x00, 0x01, 0x02)
275 #define DIBUSB_REQ_POLL_REMOTE 0x04
277 #define DIBUSB_RC_NEC_EMPTY 0x00
278 #define DIBUSB_RC_NEC_KEY_PRESSED 0x01
279 #define DIBUSB_RC_NEC_KEY_REPEATED 0x02
282 * bulk write: 0x05 mode_byte
284 * mode_byte is mostly 0x00
286 #define DIBUSB_REQ_SET_STREAMING_MODE 0x05
288 /* interrupt the internal read loop, when blocking */
289 #define DIBUSB_REQ_INTR_READ 0x06
292 * 0x07 cmd_byte param_bytes
294 * param_bytes can be up to 32 bytes
296 * cmd_byte function parameter name
301 * 0x01 enable streaming
302 * 0x02 disable streaming
306 #define DIBUSB_REQ_SET_IOCTL 0x07
310 /* change the power mode in firmware */
311 #define DIBUSB_IOCTL_CMD_POWER_MODE 0x00
312 #define DIBUSB_IOCTL_POWER_SLEEP 0x00
313 #define DIBUSB_IOCTL_POWER_WAKEUP 0x01
315 /* modify streaming of the FX2 */
316 #define DIBUSB_IOCTL_CMD_ENABLE_STREAM 0x01
317 #define DIBUSB_IOCTL_CMD_DISABLE_STREAM 0x02