summaryrefslogtreecommitdiff
path: root/linux/drivers/media/dvb/dibusb/dvb-dibusb.h
blob: bac7d092175cfb2b1e7ecfe96df857e9c295fbaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 * dvb-dibusb.h
 * 
 * Copyright (C) 2004 Patrick Boettcher (patrick.boettcher@desy.de)
 * 
 *	This program is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License as
 *	published by the Free Software Foundation, version 2.
 *
 * for more information see dvb-dibusb-core.c .
 */
#ifndef __DVB_DIBUSB_H__
#define __DVB_DIBUSB_H__

#include <linux/input.h>
#include <linux/config.h>
#include <linux/usb.h>

#include "dvb_frontend.h"
#include "dvb_demux.h"
#include "dvb_net.h"
#include "dmxdev.h"

#include "dib3000.h"

/* debug */
#ifdef CONFIG_DVB_DIBCOM_DEBUG
#define dprintk(level,args...) \
	    do { if ((debug & level)) { printk(args); } } while (0)

#define debug_dump(b,l) if (debug) {\
	int i; deb_xfer("%s: %d > ",__FUNCTION__,l); \
	for (i = 0; i < l; i++) deb_xfer("%02x ", b[i]); \
	deb_xfer("\n");\
}

/* module parameters - declared in -core.c */
extern int debug;

#else
#define dprintk(args...)
#define debug_dump(b,l)
#endif

/* module parameters - declared in -core.c */
extern int pid_parse;
extern int rc_query_interval;

#define deb_info(args...) dprintk(0x01,args)
#define deb_xfer(args...) dprintk(0x02,args)
#define deb_alot(args...) dprintk(0x04,args)
#define deb_ts(args...)   dprintk(0x08,args)
#define deb_err(args...)  dprintk(0x10,args)
#define deb_rc(args...)   dprintk(0x20,args)

/* generic log methods - taken from usb.h */
#define err(format, arg...) printk(KERN_ERR "%s: " format "\n" , __FILE__ , ## arg)
#define info(format, arg...) printk(KERN_INFO "%s: " format "\n" , __FILE__ , ## arg)
#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n" , __FILE__ , ## arg)

/* Version information */
#define DRIVER_VERSION "0.1"
#define DRIVER_DESC "Driver for DiBcom based USB Budget DVB-T device"
#define DRIVER_AUTHOR "Patrick Boettcher, patrick.boettcher@desy.de"

typedef enum {
	DIBUSB1_1 = 0,
	DIBUSB2_0,
	DIBUSB1_1_AN2235,
} dibusb_type;

/* struct for holding properties of the different dibusb device models */
struct dibusb_device_parameter {
	dibusb_type type;
	const char **fw_filenames;
	const char *usb_controller;
	u16 usb_cpu_csreg;
	
	int num_urbs;
	int urb_buf_size;
	int default_size;
	int firmware_bug;

	int cmd_pipe;
	int result_pipe;
	int data_pipe;

	int (*pll_set) (struct dvb_frontend *,struct dvb_frontend_parameters *);
	unsigned char pll_addr;
	unsigned char demod_i2c_addrs[4];
};

/* 
 * for each warm/cold product id a name is stored, this is just beautification,
 * it could easily done by an PID-array, but then the real names of the devices
 * would get lost.
 */
struct dibusb_device {
	const char *name;
	u16 cold_product_id;
	u16 warm_product_id;
	struct dibusb_device_parameter *parm;
};

struct usb_dibusb {
	/* usb */
	struct usb_device * udev;

	struct dibusb_device * dibdev;

	int feedcount;
	int pid_parse;
	struct dib3000_xfer_ops xfer_ops;
	
	struct urb **urb_list;
	u8 *buffer;
	dma_addr_t dma_handle;
	
	/* I2C */
	struct i2c_adapter i2c_adap;

	/* locking */
	struct semaphore usb_sem;
	struct semaphore i2c_sem;

	/* dvb */
	int dvb_is_ready;
	struct dvb_adapter *adapter;
	struct dmxdev dmxdev;
	struct dvb_demux demux;
	struct dvb_net dvb_net;
	struct dvb_frontend* fe;

	/* remote control */
	struct input_dev rc_input_dev;
	struct work_struct rc_query_work;
	int rc_input_event;
};

/* commonly used functions in the separated files */

/* dvb-dibusb-firmware.c */
int dibusb_loadfirmware(struct usb_device *udev, struct dibusb_device *dibdev);

/* dvb-dibusb-remote.c */
int dibusb_remote_exit(struct usb_dibusb *dib);
int dibusb_remote_init(struct usb_dibusb *dib);

/* dvb-dibusb-fe-i2c.c */
int dibusb_fe_init(struct usb_dibusb* dib);
int dibusb_fe_exit(struct usb_dibusb *dib);
int dibusb_i2c_init(struct usb_dibusb *dib);
int dibusb_i2c_exit(struct usb_dibusb *dib);

/* dvb-dibusb-dvb.c */
void dibusb_urb_complete(struct urb *urb, struct pt_regs *ptregs);
int dibusb_dvb_init(struct usb_dibusb *dib);
int dibusb_dvb_exit(struct usb_dibusb *dib);

/* dvb-dibusb-usb.c */
int dibusb_readwrite_usb(struct usb_dibusb *dib, u8 *wbuf, u16 wlen, u8 *rbuf,
	u16 rlen);

int dibusb_hw_wakeup(struct usb_dibusb *dib);
int dibusb_set_streaming_mode(struct usb_dibusb *dib,u8 mode);
int dibusb_streaming(struct usb_dibusb *dib,int onoff);

int dibusb_usb_init(struct usb_dibusb *dib);
int dibusb_usb_exit(struct usb_dibusb *dib);

/* i2c and transfer stuff */
#define DIBUSB_I2C_TIMEOUT				HZ*5

/*
 * types of first byte of each buffer send to USB, applying for 
 * USB1.1 and USB2.0
 */

#define DIBUSB_REQ_START_READ			0x00
#define DIBUSB_REQ_START_DEMOD			0x01
#define DIBUSB_REQ_I2C_READ  			0x02
#define DIBUSB_REQ_I2C_WRITE 			0x03

/* prefix for reading the current RC key */
#define DIBUSB_REQ_POLL_REMOTE			0x04

#define DIBUSB_RC_NEC_EMPTY				0x00
#define DIBUSB_RC_NEC_KEY_PRESSED		0x01
#define DIBUSB_RC_NEC_KEY_REPEATED		0x02

/* 0x05 0xXX */
#define DIBUSB_REQ_SET_STREAMING_MODE	0x05

/* interrupt the internal read loop, when blocking */
#define DIBUSB_REQ_INTR_READ		   	0x06

/* IO control 
 * 0x07 <cmd 1 byte> <param 32 bytes>
 */ 
#define DIBUSB_REQ_SET_IOCTL			0x07

/* IOCTL commands */

/* change the power mode in firmware */ 
#define DIBUSB_IOCTL_CMD_POWER_MODE		0x00
#define DIBUSB_IOCTL_POWER_SLEEP			0x00
#define DIBUSB_IOCTL_POWER_WAKEUP			0x01

/* modify streaming of the FX2 */
#define DIBUSB_IOCTL_CMD_ENABLE_STREAM	0x01
#define DIBUSB_IOCTL_CMD_DISABLE_STREAM	0x02

#endif