au0828.h 7.5 KB
Newer Older
1 2 3
/*
 *  Driver for the Auvitek AU0828 USB bridge
 *
4
 *  Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 *  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; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <linux/usb.h>
#include <linux/i2c.h>
#include <linux/i2c-algo-bit.h>
25
#include <media/tveeprom.h>
26

27 28 29 30
/* Analog */
#include <linux/videodev2.h>
#include <media/videobuf-vmalloc.h>

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
/* DVB */
#include "demux.h"
#include "dmxdev.h"
#include "dvb_demux.h"
#include "dvb_frontend.h"
#include "dvb_net.h"
#include "dvbdev.h"

#include "au0828-reg.h"
#include "au0828-cards.h"

#define DRIVER_NAME "au0828"
#define URB_COUNT   16
#define URB_BUFSIZE (0xe522)

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
/* Analog constants */
#define NTSC_STD_W      720
#define NTSC_STD_H      480

#define AU0828_INTERLACED_DEFAULT       1
#define V4L2_CID_PRIVATE_SHARPNESS  (V4L2_CID_PRIVATE_BASE + 0)

/* Defination for AU0828 USB transfer */
#define AU0828_MAX_ISO_BUFS    12  /* maybe resize this value in the future */
#define AU0828_ISO_PACKETS_PER_URB      10
#define AU0828_ISO_MAX_FRAME_SIZE       (3 * 1024)
#define AU0828_ISO_BUFFER_SIZE          (AU0828_ISO_PACKETS_PER_URB * AU0828_ISO_MAX_FRAME_SIZE)

#define AU0828_MIN_BUF 4
#define AU0828_DEF_BUF 8

#define AU0828_MAX_IMAGES       10
#define AU0828_FRAME_SIZE       (1028 * 1024 * 4)
#define AU0828_URB_TIMEOUT      msecs_to_jiffies(AU0828_MAX_ISO_BUFS * AU0828_ISO_PACKETS_PER_URB)

#define AU0828_MAX_INPUT        4

enum au0828_itype {
69 70
	AU0828_VMUX_UNDEFINED = 0,
	AU0828_VMUX_COMPOSITE,
71 72 73 74 75 76 77 78 79 80 81 82 83 84
	AU0828_VMUX_SVIDEO,
	AU0828_VMUX_CABLE,
	AU0828_VMUX_TELEVISION,
	AU0828_VMUX_DVB,
	AU0828_VMUX_DEBUG
};

struct au0828_input {
	enum au0828_itype type;
	unsigned int vmux;
	unsigned int amux;
	void (*audio_setup) (void *priv, int enable);
};

85 86
struct au0828_board {
	char *name;
87 88
	unsigned int tuner_type;
	unsigned char tuner_addr;
89 90
	struct au0828_input input[AU0828_MAX_INPUT];

91 92 93 94 95 96 97 98 99 100 101 102 103 104
};

struct au0828_dvb {
	struct mutex lock;
	struct dvb_adapter adapter;
	struct dvb_frontend *frontend;
	struct dvb_demux demux;
	struct dmxdev dmxdev;
	struct dmx_frontend fe_hw;
	struct dmx_frontend fe_mem;
	struct dvb_net net;
	int feeding;
};

105 106 107 108 109 110
enum au0828_stream_state {
	STREAM_OFF,
	STREAM_INTERRUPT,
	STREAM_ON
};

111
#define AUVI_INPUT(nr) (dev->board.input[nr])
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

/* device state */
enum au0828_dev_state {
	DEV_INITIALIZED = 0x01,
	DEV_DISCONNECTED = 0x02,
	DEV_MISCONFIGURED = 0x04
};

struct au0828_fh {
	struct au0828_dev *dev;
	unsigned int  stream_on:1;	/* Locks streams */
	struct videobuf_queue        vb_vidq;
	enum v4l2_buf_type           type;
};

struct au0828_usb_isoc_ctl {
		/* max packet size of isoc transaction */
	int				max_pkt_size;

		/* number of allocated urbs */
	int				num_bufs;

		/* urb for isoc transfers */
	struct urb			**urb;

		/* transfer buffers for isoc transfer */
	char				**transfer_buffer;

		/* Last buffer command and region */
	u8				cmd;
	int				pos, size, pktsize;

		/* Last field: ODD or EVEN? */
	int				field;

		/* Stores incomplete commands */
	u32				tmp_buf;
	int				tmp_buf_len;

		/* Stores already requested buffers */
	struct au0828_buffer    	*buf;

		/* Stores the number of received fields */
	int				nfields;

		/* isoc urb callback */
	int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb);

};

/* buffer for one video frame */
struct au0828_buffer {
	/* common v4l buffer stuff -- must be first */
	struct videobuf_buffer vb;

	struct list_head frame;
	int top_field;
	int receiving;
};

struct au0828_dmaqueue {
	struct list_head       active;
	struct list_head       queued;

	wait_queue_head_t          wq;

	/* Counters to control buffer fill */
	int                        pos;
};

182 183 184
struct au0828_dev {
	struct mutex mutex;
	struct usb_device	*usbdev;
185 186
	int			boardnr;
	struct au0828_board	board;
187 188 189 190 191 192 193 194 195 196 197
	u8			ctrlmsg[64];

	/* I2C */
	struct i2c_adapter		i2c_adap;
	struct i2c_algo_bit_data	i2c_algo;
	struct i2c_client		i2c_client;
	u32 				i2c_rc;

	/* Digital */
	struct au0828_dvb		dvb;

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
	/* Analog */
	struct list_head au0828list;
	int users;
	unsigned int stream_on:1;	/* Locks streams */
	struct video_device *vdev;
	struct video_device *vbi_dev;
	int width;
	int height;
	u32 field_size;
	u32 frame_size;
	u32 bytesperline;
	int type;
	u8 ctrl_ainput;
	__u8 isoc_in_endpointaddr;
	u8 isoc_init_ok;
	int greenscreen_detected;
	unsigned int frame_count;
	int ctrl_freq;
	int input_type;
	unsigned int ctrl_input;
	enum au0828_dev_state dev_state;
	enum au0828_stream_state stream_state;
	wait_queue_head_t open;

	struct mutex lock;

	/* Isoc control struct */
	struct au0828_dmaqueue vidq;
	struct au0828_usb_isoc_ctl isoc_ctl;
	spinlock_t slock;

	/* usb transfer */
	int alt;		/* alternate */
	int max_pkt_size;	/* max packet size of isoc transaction */
	int num_alt;		/* Number of alternative settings */
	unsigned int *alt_max_pkt_size;	/* array of wMaxPacketSize */
	struct urb *urb[AU0828_MAX_ISO_BUFS];	/* urb for isoc transfers */
	char *transfer_buffer[AU0828_MAX_ISO_BUFS];/* transfer buffers for isoc
						   transfer */

238 239 240 241 242 243
	/* USB / URB Related */
	int		urb_streaming;
	struct urb	*urbs[URB_COUNT];
};

/* ----------------------------------------------------------- */
244 245 246 247 248 249 250 251
#define au0828_read(dev, reg) au0828_readreg(dev, reg)
#define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value)
#define au0828_andor(dev, reg, mask, value) 				\
	 au0828_writereg(dev, reg, 					\
	(au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask)))

#define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit))
#define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0)
252 253 254 255 256

/* ----------------------------------------------------------- */
/* au0828-core.c */
extern u32 au0828_read(struct au0828_dev *dev, u16 reg);
extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val);
257
extern int au0828_debug;
258 259 260 261 262 263

/* ----------------------------------------------------------- */
/* au0828-cards.c */
extern struct au0828_board au0828_boards[];
extern struct usb_device_id au0828_usb_id_table[];
extern void au0828_gpio_setup(struct au0828_dev *dev);
264 265
extern int au0828_tuner_callback(void *priv, int component,
				 int command, int arg);
266
extern void au0828_card_setup(struct au0828_dev *dev);
267 268 269 270 271 272 273 274

/* ----------------------------------------------------------- */
/* au0828-i2c.c */
extern int au0828_i2c_register(struct au0828_dev *dev);
extern int au0828_i2c_unregister(struct au0828_dev *dev);
extern void au0828_call_i2c_clients(struct au0828_dev *dev,
	unsigned int cmd, void *arg);

275 276
/* ----------------------------------------------------------- */
/* au0828-video.c */
277 278
int au0828_analog_register(struct au0828_dev *dev,
			   struct usb_interface *interface);
279 280 281
int au0828_analog_stream_disable(struct au0828_dev *d);
void au0828_analog_unregister(struct au0828_dev *dev);

282 283 284 285
/* ----------------------------------------------------------- */
/* au0828-dvb.c */
extern int au0828_dvb_register(struct au0828_dev *dev);
extern void au0828_dvb_unregister(struct au0828_dev *dev);
S
Steven Toth 已提交
286 287

#define dprintk(level, fmt, arg...)\
288
	do { if (au0828_debug & level)\
S
Steven Toth 已提交
289 290
		printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\
	} while (0)