Path: blob/master/drivers/media/video/au0828/au0828.h
17900 views
/*1* Driver for the Auvitek AU0828 USB bridge2*3* Copyright (c) 2008 Steven Toth <[email protected]>4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13*14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program; if not, write to the Free Software18* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.19*/2021#include <linux/usb.h>22#include <linux/i2c.h>23#include <linux/i2c-algo-bit.h>24#include <media/tveeprom.h>2526/* Analog */27#include <linux/videodev2.h>28#include <media/videobuf-vmalloc.h>29#include <media/v4l2-device.h>3031/* DVB */32#include "demux.h"33#include "dmxdev.h"34#include "dvb_demux.h"35#include "dvb_frontend.h"36#include "dvb_net.h"37#include "dvbdev.h"3839#include "au0828-reg.h"40#include "au0828-cards.h"4142#define DRIVER_NAME "au0828"43#define URB_COUNT 1644#define URB_BUFSIZE (0xe522)4546/* Analog constants */47#define NTSC_STD_W 72048#define NTSC_STD_H 4804950#define AU0828_INTERLACED_DEFAULT 151#define V4L2_CID_PRIVATE_SHARPNESS (V4L2_CID_PRIVATE_BASE + 0)5253/* Defination for AU0828 USB transfer */54#define AU0828_MAX_ISO_BUFS 12 /* maybe resize this value in the future */55#define AU0828_ISO_PACKETS_PER_URB 1285657#define AU0828_MIN_BUF 458#define AU0828_DEF_BUF 85960#define AU0828_MAX_INPUT 46162/* au0828 resource types (used for res_get/res_lock etc */63#define AU0828_RESOURCE_VIDEO 0x0164#define AU0828_RESOURCE_VBI 0x026566enum au0828_itype {67AU0828_VMUX_UNDEFINED = 0,68AU0828_VMUX_COMPOSITE,69AU0828_VMUX_SVIDEO,70AU0828_VMUX_CABLE,71AU0828_VMUX_TELEVISION,72AU0828_VMUX_DVB,73AU0828_VMUX_DEBUG74};7576struct au0828_input {77enum au0828_itype type;78unsigned int vmux;79unsigned int amux;80void (*audio_setup) (void *priv, int enable);81};8283struct au0828_board {84char *name;85unsigned int tuner_type;86unsigned char tuner_addr;87unsigned char i2c_clk_divider;88struct au0828_input input[AU0828_MAX_INPUT];8990};9192struct au0828_dvb {93struct mutex lock;94struct dvb_adapter adapter;95struct dvb_frontend *frontend;96struct dvb_demux demux;97struct dmxdev dmxdev;98struct dmx_frontend fe_hw;99struct dmx_frontend fe_mem;100struct dvb_net net;101int feeding;102};103104enum au0828_stream_state {105STREAM_OFF,106STREAM_INTERRUPT,107STREAM_ON108};109110#define AUVI_INPUT(nr) (dev->board.input[nr])111112/* device state */113enum au0828_dev_state {114DEV_INITIALIZED = 0x01,115DEV_DISCONNECTED = 0x02,116DEV_MISCONFIGURED = 0x04117};118119struct au0828_fh {120struct au0828_dev *dev;121unsigned int resources;122123struct videobuf_queue vb_vidq;124struct videobuf_queue vb_vbiq;125enum v4l2_buf_type type;126};127128struct au0828_usb_isoc_ctl {129/* max packet size of isoc transaction */130int max_pkt_size;131132/* number of allocated urbs */133int num_bufs;134135/* urb for isoc transfers */136struct urb **urb;137138/* transfer buffers for isoc transfer */139char **transfer_buffer;140141/* Last buffer command and region */142u8 cmd;143int pos, size, pktsize;144145/* Last field: ODD or EVEN? */146int field;147148/* Stores incomplete commands */149u32 tmp_buf;150int tmp_buf_len;151152/* Stores already requested buffers */153struct au0828_buffer *buf;154struct au0828_buffer *vbi_buf;155156/* Stores the number of received fields */157int nfields;158159/* isoc urb callback */160int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb);161162};163164/* buffer for one video frame */165struct au0828_buffer {166/* common v4l buffer stuff -- must be first */167struct videobuf_buffer vb;168169struct list_head frame;170int top_field;171int receiving;172};173174struct au0828_dmaqueue {175struct list_head active;176struct list_head queued;177178wait_queue_head_t wq;179180/* Counters to control buffer fill */181int pos;182};183184struct au0828_dev {185struct mutex mutex;186struct usb_device *usbdev;187int boardnr;188struct au0828_board board;189u8 ctrlmsg[64];190191/* I2C */192struct i2c_adapter i2c_adap;193struct i2c_algorithm i2c_algo;194struct i2c_client i2c_client;195u32 i2c_rc;196197/* Digital */198struct au0828_dvb dvb;199200/* Analog */201struct v4l2_device v4l2_dev;202int users;203unsigned int resources; /* resources in use */204struct video_device *vdev;205struct video_device *vbi_dev;206struct timer_list vid_timeout;207int vid_timeout_running;208struct timer_list vbi_timeout;209int vbi_timeout_running;210int width;211int height;212int vbi_width;213int vbi_height;214u32 vbi_read;215u32 field_size;216u32 frame_size;217u32 bytesperline;218int type;219u8 ctrl_ainput;220__u8 isoc_in_endpointaddr;221u8 isoc_init_ok;222int greenscreen_detected;223unsigned int frame_count;224int ctrl_freq;225int input_type;226unsigned int ctrl_input;227enum au0828_dev_state dev_state;228enum au0828_stream_state stream_state;229wait_queue_head_t open;230231struct mutex lock;232233/* Isoc control struct */234struct au0828_dmaqueue vidq;235struct au0828_dmaqueue vbiq;236struct au0828_usb_isoc_ctl isoc_ctl;237spinlock_t slock;238239/* usb transfer */240int alt; /* alternate */241int max_pkt_size; /* max packet size of isoc transaction */242int num_alt; /* Number of alternative settings */243unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */244struct urb *urb[AU0828_MAX_ISO_BUFS]; /* urb for isoc transfers */245char *transfer_buffer[AU0828_MAX_ISO_BUFS];/* transfer buffers for isoc246transfer */247248/* USB / URB Related */249int urb_streaming;250struct urb *urbs[URB_COUNT];251};252253/* ----------------------------------------------------------- */254#define au0828_read(dev, reg) au0828_readreg(dev, reg)255#define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value)256#define au0828_andor(dev, reg, mask, value) \257au0828_writereg(dev, reg, \258(au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask)))259260#define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit))261#define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0)262263/* ----------------------------------------------------------- */264/* au0828-core.c */265extern u32 au0828_read(struct au0828_dev *dev, u16 reg);266extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val);267extern int au0828_debug;268269/* ----------------------------------------------------------- */270/* au0828-cards.c */271extern struct au0828_board au0828_boards[];272extern struct usb_device_id au0828_usb_id_table[];273extern void au0828_gpio_setup(struct au0828_dev *dev);274extern int au0828_tuner_callback(void *priv, int component,275int command, int arg);276extern void au0828_card_setup(struct au0828_dev *dev);277278/* ----------------------------------------------------------- */279/* au0828-i2c.c */280extern int au0828_i2c_register(struct au0828_dev *dev);281extern int au0828_i2c_unregister(struct au0828_dev *dev);282283/* ----------------------------------------------------------- */284/* au0828-video.c */285int au0828_analog_register(struct au0828_dev *dev,286struct usb_interface *interface);287int au0828_analog_stream_disable(struct au0828_dev *d);288void au0828_analog_unregister(struct au0828_dev *dev);289290/* ----------------------------------------------------------- */291/* au0828-dvb.c */292extern int au0828_dvb_register(struct au0828_dev *dev);293extern void au0828_dvb_unregister(struct au0828_dev *dev);294295/* au0828-vbi.c */296extern struct videobuf_queue_ops au0828_vbi_qops;297298#define dprintk(level, fmt, arg...)\299do { if (au0828_debug & level)\300printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\301} while (0)302303304