Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
au0828.h
Go to the documentation of this file.
1 /*
2  * Driver for the Auvitek AU0828 USB bridge
3  *
4  * Copyright (c) 2008 Steven Toth <[email protected]>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 
22 #include <linux/usb.h>
23 #include <linux/i2c.h>
24 #include <linux/i2c-algo-bit.h>
25 #include <media/tveeprom.h>
26 
27 /* Analog */
28 #include <linux/videodev2.h>
29 #include <media/videobuf-vmalloc.h>
30 #include <media/v4l2-device.h>
31 
32 /* DVB */
33 #include "demux.h"
34 #include "dmxdev.h"
35 #include "dvb_demux.h"
36 #include "dvb_frontend.h"
37 #include "dvb_net.h"
38 #include "dvbdev.h"
39 
40 #include "au0828-reg.h"
41 #include "au0828-cards.h"
42 
43 #define DRIVER_NAME "au0828"
44 #define URB_COUNT 16
45 #define URB_BUFSIZE (0xe522)
46 
47 /* Analog constants */
48 #define NTSC_STD_W 720
49 #define NTSC_STD_H 480
50 
51 #define AU0828_INTERLACED_DEFAULT 1
52 #define V4L2_CID_PRIVATE_SHARPNESS (V4L2_CID_PRIVATE_BASE + 0)
53 
54 /* Defination for AU0828 USB transfer */
55 #define AU0828_MAX_ISO_BUFS 12 /* maybe resize this value in the future */
56 #define AU0828_ISO_PACKETS_PER_URB 128
57 
58 #define AU0828_MIN_BUF 4
59 #define AU0828_DEF_BUF 8
60 
61 #define AU0828_MAX_INPUT 4
62 
63 /* au0828 resource types (used for res_get/res_lock etc */
64 #define AU0828_RESOURCE_VIDEO 0x01
65 #define AU0828_RESOURCE_VBI 0x02
66 
75 };
76 
77 struct au0828_input {
79  unsigned int vmux;
80  unsigned int amux;
81  void (*audio_setup) (void *priv, int enable);
82 };
83 
84 struct au0828_board {
85  char *name;
86  unsigned int tuner_type;
87  unsigned char tuner_addr;
88  unsigned char i2c_clk_divider;
90 
91 };
92 
93 struct au0828_dvb {
94  struct mutex lock;
97  struct dvb_demux demux;
98  struct dmxdev dmxdev;
101  struct dvb_net net;
102  int feeding;
103 };
104 
109 };
110 
111 #define AUVI_INPUT(nr) (dev->board.input[nr])
112 
113 /* device state */
118 };
119 
120 struct au0828_fh {
121  struct au0828_dev *dev;
122  unsigned int resources;
123 
127 };
128 
130  /* max packet size of isoc transaction */
132 
133  /* number of allocated urbs */
134  int num_bufs;
135 
136  /* urb for isoc transfers */
137  struct urb **urb;
138 
139  /* transfer buffers for isoc transfer */
141 
142  /* Last buffer command and region */
144  int pos, size, pktsize;
145 
146  /* Last field: ODD or EVEN? */
147  int field;
148 
149  /* Stores incomplete commands */
152 
153  /* Stores already requested buffers */
156 
157  /* Stores the number of received fields */
158  int nfields;
159 
160  /* isoc urb callback */
161  int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb);
162 
163 };
164 
165 /* buffer for one video frame */
167  /* common v4l buffer stuff -- must be first */
169 
170  struct list_head frame;
173 };
174 
178 
180 
181  /* Counters to control buffer fill */
182  int pos;
183 };
184 
185 struct au0828_dev {
186  struct mutex mutex;
187  struct usb_device *usbdev;
188  int boardnr;
190  u8 ctrlmsg[64];
191 
192  /* I2C */
197 
198  /* Digital */
199  struct au0828_dvb dvb;
201 
202  /* Analog */
204  int users;
205  unsigned int resources; /* resources in use */
212  int width;
213  int height;
220  int type;
225  unsigned int frame_count;
229  unsigned int ctrl_input;
233 
234  struct mutex lock;
235 
236  /* Isoc control struct */
241 
242  /* usb transfer */
243  int alt; /* alternate */
244  int max_pkt_size; /* max packet size of isoc transaction */
245  int num_alt; /* Number of alternative settings */
246  unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
247  struct urb *urb[AU0828_MAX_ISO_BUFS]; /* urb for isoc transfers */
248  char *transfer_buffer[AU0828_MAX_ISO_BUFS];/* transfer buffers for isoc
249  transfer */
250 
251  /* USB / URB Related */
253  struct urb *urbs[URB_COUNT];
254 };
255 
256 /* ----------------------------------------------------------- */
257 #define au0828_read(dev, reg) au0828_readreg(dev, reg)
258 #define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value)
259 #define au0828_andor(dev, reg, mask, value) \
260  au0828_writereg(dev, reg, \
261  (au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask)))
262 
263 #define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit))
264 #define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0)
265 
266 /* ----------------------------------------------------------- */
267 /* au0828-core.c */
268 extern u32 au0828_read(struct au0828_dev *dev, u16 reg);
269 extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val);
270 extern int au0828_debug;
271 
272 /* ----------------------------------------------------------- */
273 /* au0828-cards.c */
274 extern struct au0828_board au0828_boards[];
275 extern struct usb_device_id au0828_usb_id_table[];
276 extern void au0828_gpio_setup(struct au0828_dev *dev);
277 extern int au0828_tuner_callback(void *priv, int component,
278  int command, int arg);
279 extern void au0828_card_setup(struct au0828_dev *dev);
280 
281 /* ----------------------------------------------------------- */
282 /* au0828-i2c.c */
283 extern int au0828_i2c_register(struct au0828_dev *dev);
284 extern int au0828_i2c_unregister(struct au0828_dev *dev);
285 
286 /* ----------------------------------------------------------- */
287 /* au0828-video.c */
289  struct usb_interface *interface);
292 
293 /* ----------------------------------------------------------- */
294 /* au0828-dvb.c */
295 extern int au0828_dvb_register(struct au0828_dev *dev);
296 extern void au0828_dvb_unregister(struct au0828_dev *dev);
297 
298 /* au0828-vbi.c */
299 extern struct videobuf_queue_ops au0828_vbi_qops;
300 
301 #define dprintk(level, fmt, arg...)\
302  do { if (au0828_debug & level)\
303  printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\
304  } while (0)