bttvp.h revision ae50f0f83efce31c8d485b5de131a4fd3f13e24b
11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    bttv - Bt848 frame grabber driver
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    bttv's *private* header file  --  nobody other than bttv itself
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    should ever include this file.
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    (c) 2000-2002 Gerd Knorr <kraxel@bytesex.org>
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    This program is free software; you can redistribute it and/or modify
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    it under the terms of the GNU General Public License as published by
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    the Free Software Foundation; either version 2 of the License, or
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    (at your option) any later version.
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    This program is distributed in the hope that it will be useful,
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    but WITHOUT ANY WARRANTY; without even the implied warranty of
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    GNU General Public License for more details.
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    You should have received a copy of the GNU General Public License
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    along with this program; if not, write to the Free Software
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds*/
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef _BTTVP_H_
261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define _BTTVP_H_
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/types.h>
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/wait.h>
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/i2c.h>
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/i2c-algo-bit.h>
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/pci.h>
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/input.h>
34bd5f0ac930168899003952110c45d110958a5c55Ingo Molnar#include <linux/mutex.h>
3587ae9afdcada236d0a1b38ce2c465a65916961dcAdrian Bunk#include <linux/scatterlist.h>
3601df530c2791610727e345b3dd97ef75943c7320Hans Verkuil#include <linux/device.h>
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/io.h>
3818f3fa1e2eab297a2f7ec704385fa0ecfda0de55Mauro Carvalho Chehab#include <media/v4l2-common.h>
3901df530c2791610727e345b3dd97ef75943c7320Hans Verkuil#include <media/v4l2-ctrls.h>
40ae50f0f83efce31c8d485b5de131a4fd3f13e24bHans Verkuil#include <media/v4l2-fh.h>
41c1accaa21bdef38ec0f36eaaf7ce3384fff9d0c5Mauro Carvalho Chehab#include <media/videobuf-dma-sg.h>
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <media/tveeprom.h>
436bda96447cef24fbf97a798b1ea664224d5fdc25Mauro Carvalho Chehab#include <media/rc-core.h>
44c0c46826274a4da5d9e312d7cfd4ca0806c0a358Mauro Carvalho Chehab#include <media/ir-kbd-i2c.h>
45674434c691e10015660022fc00b04985a23ef87bMauro Carvalho Chehab
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "bt848.h"
471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "bttv.h"
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "btcx-risc.h"
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef __KERNEL__
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FORMAT_FLAGS_DITHER       0x01
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FORMAT_FLAGS_PACKED       0x02
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FORMAT_FLAGS_PLANAR       0x04
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FORMAT_FLAGS_RAW          0x08
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FORMAT_FLAGS_CrCb         0x10
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define RISC_SLOT_O_VBI        4
591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define RISC_SLOT_O_FIELD      6
601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define RISC_SLOT_E_VBI       10
611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define RISC_SLOT_E_FIELD     12
621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define RISC_SLOT_LOOP        14
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define RESOURCE_OVERLAY       1
65e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek#define RESOURCE_VIDEO_STREAM  2
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define RESOURCE_VBI           4
67e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek#define RESOURCE_VIDEO_READ    8
681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define RAW_LINES            640
701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define RAW_BPL             1024
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define UNSET (-1U)
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
74e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek/* Min. value in VDELAY register. */
75e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek#define MIN_VDELAY 2
76e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek/* Even to get Cb first, odd for Cr. */
77e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek#define MAX_HDELAY (0x3FF & -2)
78e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek/* Limits scaled width, which must be a multiple of 4. */
79e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek#define MAX_HACTIVE (0x3FF & -4)
80e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek
81402aa76aa5e57801b4db5ccf8c7beea9f580bb1bDouglas Schilling Landgraf#define BTTV_NORMS    (\
82402aa76aa5e57801b4db5ccf8c7beea9f580bb1bDouglas Schilling Landgraf		V4L2_STD_PAL    | V4L2_STD_PAL_N | \
83402aa76aa5e57801b4db5ccf8c7beea9f580bb1bDouglas Schilling Landgraf		V4L2_STD_PAL_Nc | V4L2_STD_SECAM | \
84402aa76aa5e57801b4db5ccf8c7beea9f580bb1bDouglas Schilling Landgraf		V4L2_STD_NTSC   | V4L2_STD_PAL_M | \
85402aa76aa5e57801b4db5ccf8c7beea9f580bb1bDouglas Schilling Landgraf		V4L2_STD_PAL_60)
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* ---------------------------------------------------------- */
871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct bttv_tvnorm {
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int   v4l2_id;
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	char  *name;
914ac97914c6c35f6bf132071c718e034d0846b9f5Mauro Carvalho Chehab	u32   Fsc;
924ac97914c6c35f6bf132071c718e034d0846b9f5Mauro Carvalho Chehab	u16   swidth, sheight; /* scaled standard width, height */
931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u16   totalwidth;
941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u8    adelay, bdelay, iform;
951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32   scaledtwidth;
961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u16   hdelayx1, hactivex1;
971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u16   vdelay;
984ac97914c6c35f6bf132071c718e034d0846b9f5Mauro Carvalho Chehab	u8    vbipack;
991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u16   vtotal;
1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int   sram;
10167f1570a0659abba5efbf55cc986187af61bdd52Michael H. Schimek	/* ITU-R frame line number of the first VBI line we can
102e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   capture, of the first and second field. The last possible line
103e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   is determined by cropcap.bounds. */
10467f1570a0659abba5efbf55cc986187af61bdd52Michael H. Schimek	u16   vbistart[2];
105e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	/* Horizontally this counts fCLKx1 samples following the leading
106e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   edge of the horizontal sync pulse, vertically ITU-R frame line
107e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   numbers of the first field times two (2, 4, 6, ... 524 or 624). */
108e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	struct v4l2_cropcap cropcap;
1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern const struct bttv_tvnorm bttv_tvnorms[];
1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct bttv_format {
1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	char *name;
1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int  fourcc;          /* video4linux 2      */
1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int  btformat;        /* BT848_COLOR_FMT_*  */
1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int  btswap;          /* BT848_COLOR_CTL_*  */
1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int  depth;           /* bit/pixel          */
1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int  flags;
1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int  hshift,vshift;   /* for planar modes   */
1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
122edb4c25ca3a7997660500692eca3510eac9726e5David Härdemanstruct bttv_ir {
123a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	struct rc_dev           *dev;
1243938e0cfeb812e7b66f4e1cb6e34eb2e6864c6a2David Härdeman	struct timer_list       timer;
125a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab
126a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	char                    name[32];
127a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	char                    phys[32];
128edb4c25ca3a7997660500692eca3510eac9726e5David Härdeman
129a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	/* Usual gpio signalling */
130a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	u32                     mask_keycode;
131a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	u32                     mask_keydown;
132a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	u32                     mask_keyup;
133a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	u32                     polling;
134a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	u32                     last_gpio;
135a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	int                     shift_by;
136a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	int                     start; // What should RC5_START() be
137a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	int                     addr; // What RC5_ADDR() should be.
138a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	int                     rc5_remote_gap;
139a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab
140a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab	/* RC5 gpio */
141b7c7a4bed8d695933ae172031556de9de30ae598Mauro Carvalho Chehab	bool			rc5_gpio;   /* Is RC5 legacy GPIO enabled? */
142edb4c25ca3a7997660500692eca3510eac9726e5David Härdeman	u32                     last_bit;   /* last raw bit seen */
143edb4c25ca3a7997660500692eca3510eac9726e5David Härdeman	u32                     code;       /* raw code under construction */
144edb4c25ca3a7997660500692eca3510eac9726e5David Härdeman	struct timeval          base_time;  /* time of last seen code */
145edb4c25ca3a7997660500692eca3510eac9726e5David Härdeman	bool                    active;     /* building raw code */
146a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab};
147a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab
148a6e3b81f6198654207c4e972e7ed91931e53e93cMauro Carvalho Chehab
1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* ---------------------------------------------------------- */
1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct bttv_geometry {
1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u8  vtc,crop,comb;
1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u16 width,hscale,hdelay;
1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u16 sheight,vscale,vdelay,vtotal;
1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct bttv_buffer {
1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* common v4l buffer stuff -- must be first */
1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct videobuf_buffer     vb;
1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* bttv specific */
1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	const struct bttv_format   *fmt;
1634ef2ccc2611456667ea78c6f418ce87e1fa9fac5Trent Piepho	unsigned int               tvnorm;
1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int                        btformat;
1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int                        btswap;
1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv_geometry       geo;
1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct btcx_riscmem        top;
1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct btcx_riscmem        bottom;
169e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	struct v4l2_rect           crop;
170e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	unsigned int               vbi_skip[2];
171e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	unsigned int               vbi_count[2];
1721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct bttv_buffer_set {
1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv_buffer     *top;       /* top field buffer    */
1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv_buffer     *bottom;    /* bottom field buffer */
1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int           top_irq;
1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int           frame_irq;
1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct bttv_overlay {
1824ef2ccc2611456667ea78c6f418ce87e1fa9fac5Trent Piepho	unsigned int           tvnorm;
1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct v4l2_rect       w;
1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	enum v4l2_field        field;
1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct v4l2_clip       *clips;
1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int                    nclips;
1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int                    setup_ok;
1881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
1891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
190e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimekstruct bttv_vbi_fmt {
191e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	struct v4l2_vbi_format fmt;
192e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek
193e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	/* fmt.start[] and count[] refer to this video standard. */
194e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	const struct bttv_tvnorm *tvnorm;
195e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek
196e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	/* Earliest possible start of video capturing with this
197e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   v4l2_vbi_format, in struct bttv_crop.rect units. */
198e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	__s32                  end;
199e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek};
200e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek
201e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek/* bttv-vbi.c */
2024ef2ccc2611456667ea78c6f418ce87e1fa9fac5Trent Piephovoid bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm);
203e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek
204e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimekstruct bttv_crop {
205e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	/* A cropping rectangle in struct bttv_tvnorm.cropcap units. */
206e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	struct v4l2_rect       rect;
207e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek
208e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	/* Scaled image size limits with this crop rect. Divide
209e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   max_height, but not min_height, by two when capturing
210e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   single fields. See also bttv_crop_reset() and
211e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   bttv_crop_adjust() in bttv-driver.c. */
212e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	__s32                  min_scaled_width;
213e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	__s32                  min_scaled_height;
214e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	__s32                  max_scaled_width;
215e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	__s32                  max_scaled_height;
216e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek};
217e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek
2181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct bttv_fh {
219ae50f0f83efce31c8d485b5de131a4fd3f13e24bHans Verkuil	/* This must be the first field in this struct */
220ae50f0f83efce31c8d485b5de131a4fd3f13e24bHans Verkuil	struct v4l2_fh		 fh;
221ae50f0f83efce31c8d485b5de131a4fd3f13e24bHans Verkuil
2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv              *btv;
2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int resources;
2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef VIDIOC_G_PRIORITY
2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	enum v4l2_priority       prio;
2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	enum v4l2_buf_type       type;
2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* video capture */
2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct videobuf_queue    cap;
2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	const struct bttv_format *fmt;
2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int                      width;
2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int                      height;
2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
235e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	/* video overlay */
2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	const struct bttv_format *ovfmt;
2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv_overlay      ov;
2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
239e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	/* Application called VIDIOC_S_CROP. */
240e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	int                      do_crop;
241e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek
242e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	/* vbi capture */
2431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct videobuf_queue    vbi;
244e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	/* Current VBI capture window as seen through this fh (cannot
245e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   be global for compatibility with earlier drivers). Protected
246e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   by struct bttv.lock and struct bttv_fh.vbi.lock. */
247e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	struct bttv_vbi_fmt      vbi_fmt;
2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* ---------------------------------------------------------- */
2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* bttv-risc.c                                                */
2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* risc code generators - capture */
2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
2551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		     struct scatterlist *sglist,
2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		     unsigned int offset, unsigned int bpl,
257e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek		     unsigned int pitch, unsigned int skip_lines,
258e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek		     unsigned int store_lines);
2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* control dma register + risc main loop */
2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid bttv_set_dma(struct bttv *btv, int override);
2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint bttv_risc_init_main(struct bttv *btv);
2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		   int irqflags);
2651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* capture buffer handling */
2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf);
2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint bttv_buffer_activate_video(struct bttv *btv,
2691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			       struct bttv_buffer_set *set);
2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint bttv_buffer_activate_vbi(struct bttv *btv,
2711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			     struct bttv_buffer *vbi);
272c7b0ac0546985fc6361a8d92cf808d46da797677Mauro Carvalho Chehabvoid bttv_dma_free(struct videobuf_queue *q, struct bttv *btv,
273c7b0ac0546985fc6361a8d92cf808d46da797677Mauro Carvalho Chehab		   struct bttv_buffer *buf);
2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* overlay handling */
2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
2771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		      const struct bttv_format *fmt,
2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		      struct bttv_buffer *buf);
2791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* ---------------------------------------------------------- */
2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* bttv-vbi.c                                                 */
2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
28478b526a43561d7e5e702ba27948e422dfbc4bea1Hans Verkuilint bttv_try_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
28578b526a43561d7e5e702ba27948e422dfbc4bea1Hans Verkuilint bttv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
28678b526a43561d7e5e702ba27948e422dfbc4bea1Hans Verkuilint bttv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern struct videobuf_queue_ops bttv_vbi_qops;
2891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* ---------------------------------------------------------- */
2911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* bttv-gpio.c */
2921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern struct bus_type bttv_sub_bus_type;
2941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint bttv_sub_add_device(struct bttv_core *core, char *name);
2951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint bttv_sub_del_devices(struct bttv_core *core);
2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* ---------------------------------------------------------- */
298c6eb8eafdba4ad18b4520a0d28a38bc9e61883eaHans Verkuil/* bttv-cards.c                                               */
299c6eb8eafdba4ad18b4520a0d28a38bc9e61883eaHans Verkuil
300c6eb8eafdba4ad18b4520a0d28a38bc9e61883eaHans Verkuilextern int no_overlay;
301c6eb8eafdba4ad18b4520a0d28a38bc9e61883eaHans Verkuil
302c6eb8eafdba4ad18b4520a0d28a38bc9e61883eaHans Verkuil/* ---------------------------------------------------------- */
303c0c46826274a4da5d9e312d7cfd4ca0806c0a358Mauro Carvalho Chehab/* bttv-input.c                                               */
304c0c46826274a4da5d9e312d7cfd4ca0806c0a358Mauro Carvalho Chehab
305c0c46826274a4da5d9e312d7cfd4ca0806c0a358Mauro Carvalho Chehabextern void init_bttv_i2c_ir(struct bttv *btv);
306c0c46826274a4da5d9e312d7cfd4ca0806c0a358Mauro Carvalho Chehabextern int fini_bttv_i2c(struct bttv *btv);
307c0c46826274a4da5d9e312d7cfd4ca0806c0a358Mauro Carvalho Chehab
308c0c46826274a4da5d9e312d7cfd4ca0806c0a358Mauro Carvalho Chehab/* ---------------------------------------------------------- */
3091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* bttv-driver.c                                              */
3101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* insmod options */
3121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern unsigned int bttv_verbose;
3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern unsigned int bttv_debug;
3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern unsigned int bttv_gpio;
3151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void bttv_gpio_tracking(struct bttv *btv, char *comment);
3161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int init_bttv_i2c(struct bttv *btv);
3171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3188af443e581ab57a6a38f595eb40be3514ea55195Joe Perches#define dprintk(fmt, ...)			\
3198af443e581ab57a6a38f595eb40be3514ea55195Joe Perchesdo {						\
3208af443e581ab57a6a38f595eb40be3514ea55195Joe Perches	if (bttv_debug >= 1)			\
3218af443e581ab57a6a38f595eb40be3514ea55195Joe Perches		pr_debug(fmt, ##__VA_ARGS__);	\
3228af443e581ab57a6a38f595eb40be3514ea55195Joe Perches} while (0)
3238af443e581ab57a6a38f595eb40be3514ea55195Joe Perches#define dprintk_cont(fmt, ...)			\
3248af443e581ab57a6a38f595eb40be3514ea55195Joe Perchesdo {						\
3258af443e581ab57a6a38f595eb40be3514ea55195Joe Perches	if (bttv_debug >= 1)			\
3268af443e581ab57a6a38f595eb40be3514ea55195Joe Perches		pr_cont(fmt, ##__VA_ARGS__);	\
3278af443e581ab57a6a38f595eb40be3514ea55195Joe Perches} while (0)
3288af443e581ab57a6a38f595eb40be3514ea55195Joe Perches#define d2printk(fmt, ...)			\
3298af443e581ab57a6a38f595eb40be3514ea55195Joe Perchesdo {						\
3308af443e581ab57a6a38f595eb40be3514ea55195Joe Perches	if (bttv_debug >= 2)			\
3318af443e581ab57a6a38f595eb40be3514ea55195Joe Perches		printk(fmt, ##__VA_ARGS__);	\
3328af443e581ab57a6a38f595eb40be3514ea55195Joe Perches} while (0)
3331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define BTTV_MAX_FBUF   0x208000
335fe06fe0a4d0f781f8ae0570e4d7e517a81878c1dMauro Carvalho Chehab#define BTTV_TIMEOUT    msecs_to_jiffies(500)    /* 0.5 seconds */
336fe06fe0a4d0f781f8ae0570e4d7e517a81878c1dMauro Carvalho Chehab#define BTTV_FREE_IDLE  msecs_to_jiffies(1000)   /* one second */
3371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct bttv_pll_info {
3401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int pll_ifreq;    /* PLL input frequency        */
3411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int pll_ofreq;    /* PLL output frequency       */
3421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int pll_crystal;  /* Crystal used for input     */
3431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int pll_current;  /* Currently programmed ofreq */
3441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
3451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* for gpio-connected remote control */
3471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct bttv_input {
348b7df3910c1298fee8ed7b9dfd2da74b85df5539cDmitry Torokhov	struct input_dev      *dev;
3491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	char                  name[32];
3501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	char                  phys[32];
3511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32                   mask_keycode;
3521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32                   mask_keydown;
3531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
3541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct bttv_suspend_state {
3561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32  gpio_enable;
3571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32  gpio_data;
3581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int  disabled;
3591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int  loop_irq;
3601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv_buffer_set video;
3611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv_buffer     *vbi;
3621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
3631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct bttv {
3651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv_core c;
3661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* pci device config */
3681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned short id;
3691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned char revision;
3701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned char __iomem *bt848_mmio;   /* pointer to mmio */
3711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* card configuration info */
3731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int cardid;   /* pci subsystem id (bt878 based ones) */
3744ac97914c6c35f6bf132071c718e034d0846b9f5Mauro Carvalho Chehab	unsigned int tuner_type;  /* tuner chip type */
37539e8f40da20a803a17e16304e73fd31050b1871cHans Verkuil	unsigned int tda9887_conf;
3765221e21e5ecd3aebd2e8e3234bd18883ce720945Trent Piepho	unsigned int svhs, dig;
377859f0277a6c3ba59b0a5a1eb183f8f6ce661a95dHans Verkuil	unsigned int has_saa6588:1;
3781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv_pll_info pll;
3791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int triton1;
3801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int gpioirq;
3814abdfed5676e5ef7f2461bb76f5929068a9cc9cfRicardo Cerqueira
3821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int use_i2c_hw;
3831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* old gpio interface */
3851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int shutdown;
3864b9b936f278163614543d66f8e8c93d5484dd148Nickolay V. Shmyrev
3874b9b936f278163614543d66f8e8c93d5484dd148Nickolay V. Shmyrev	void (*volume_gpio)(struct bttv *btv, __u16 volume);
3884b9b936f278163614543d66f8e8c93d5484dd148Nickolay V. Shmyrev	void (*audio_mode_gpio)(struct bttv *btv, struct v4l2_tuner *tuner, int set);
3894b9b936f278163614543d66f8e8c93d5484dd148Nickolay V. Shmyrev
3901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* new gpio interface */
3911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	spinlock_t gpio_lock;
3921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* i2c layer */
3941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct i2c_algo_bit_data   i2c_algo;
3951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct i2c_client          i2c_client;
3961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int                        i2c_state, i2c_rc;
3971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int                        i2c_done;
3981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	wait_queue_head_t          i2c_queue;
399859f0277a6c3ba59b0a5a1eb183f8f6ce661a95dHans Verkuil	struct v4l2_subdev 	  *sd_msp34xx;
400859f0277a6c3ba59b0a5a1eb183f8f6ce661a95dHans Verkuil	struct v4l2_subdev 	  *sd_tvaudio;
40101df530c2791610727e345b3dd97ef75943c7320Hans Verkuil	struct v4l2_subdev	  *sd_tda7432;
4021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* video4linux (1) */
4041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct video_device *video_dev;
4051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct video_device *radio_dev;
4061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct video_device *vbi_dev;
4071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
40801df530c2791610727e345b3dd97ef75943c7320Hans Verkuil	/* controls */
40901df530c2791610727e345b3dd97ef75943c7320Hans Verkuil	struct v4l2_ctrl_handler   ctrl_handler;
41001df530c2791610727e345b3dd97ef75943c7320Hans Verkuil	struct v4l2_ctrl_handler   radio_ctrl_handler;
41101df530c2791610727e345b3dd97ef75943c7320Hans Verkuil
4121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* infrared remote */
4131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int has_remote;
414edb4c25ca3a7997660500692eca3510eac9726e5David Härdeman	struct bttv_ir *remote;
4151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
416c0c46826274a4da5d9e312d7cfd4ca0806c0a358Mauro Carvalho Chehab	/* I2C remote data */
417c0c46826274a4da5d9e312d7cfd4ca0806c0a358Mauro Carvalho Chehab	struct IR_i2c_init_data    init_data;
418c0c46826274a4da5d9e312d7cfd4ca0806c0a358Mauro Carvalho Chehab
4191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* locking */
4201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	spinlock_t s_lock;
421bd5f0ac930168899003952110c45d110958a5c55Ingo Molnar	struct mutex lock;
4221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int resources;
4231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef VIDIOC_G_PRIORITY
4241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct v4l2_prio_state prio;
4251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
4261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* video state */
4281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int input;
4291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int audio;
4308bf2f8e747700419cc5bbc56c4496774eb8f2f1fHans Verkuil	unsigned int mute;
43176ea992a036c4a5d3bc606a79ef775dd32fd3daaHans Verkuil	unsigned long tv_freq;
4324ef2ccc2611456667ea78c6f418ce87e1fa9fac5Trent Piepho	unsigned int tvnorm;
4334ef2ccc2611456667ea78c6f418ce87e1fa9fac5Trent Piepho	int hue, contrast, bright, saturation;
4341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct v4l2_framebuffer fbuf;
4351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int field_count;
4361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* various options */
4381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int opt_combfilter;
4391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int opt_automute;
4401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int opt_vcr_hack;
441060d3027f26aab9adeac8ff6d1184bca67c7d174Mauro Carvalho Chehab	int opt_uv_ratio;
4421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* radio data/state */
4441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int has_radio;
4451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int radio_user;
4467025e521b1b068af8a47a7625335a605bbd4d7eaHans de Goede	int radio_uses_msp_demodulator;
44776ea992a036c4a5d3bc606a79ef775dd32fd3daaHans Verkuil	unsigned long radio_freq;
4481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* miro/pinnacle + Aimslab VHX
4501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	   philips matchbox (tea5757 radio tuner) support */
4511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int has_matchbox;
4521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int mbox_we;
4531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int mbox_data;
4541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int mbox_clk;
4551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int mbox_most;
4561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int mbox_mask;
4571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* ISA stuff (Terratec Active Radio Upgrade) */
4591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int mbox_ior;
4601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int mbox_iow;
4611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int mbox_csel;
4621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* risc memory management data
4640418726bb5c7b5a70c7e7e82e860d5979d0c78cfAdrian Bunk	   - must acquire s_lock before changing these
4651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	   - only the irq handler is supported to touch top + bottom + vcurr */
4661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct btcx_riscmem     main;
4671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv_buffer      *screen;    /* overlay             */
4681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct list_head        capture;    /* video capture queue */
4691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct list_head        vcapture;   /* vbi capture queue   */
4701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv_buffer_set  curr;       /* active buffers      */
4711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv_buffer      *cvbi;      /* active vbi buffer   */
4721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int                     loop_irq;
4731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int                     new_input;
4741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned long cap_ctl;
4761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned long dma_on;
4771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct timer_list timeout;
4781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv_suspend_state state;
4791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* stats */
4811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int errors;
4821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int framedrop;
4831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int irq_total;
4841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int irq_me;
4851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int users;
4871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct bttv_fh init;
488e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek
489f992a497c71981e215b1415759fc13593ed2919fJarod Wilson	/* used to make dvb-bt8xx autoloadable */
490f992a497c71981e215b1415759fc13593ed2919fJarod Wilson	struct work_struct request_module_wk;
491f992a497c71981e215b1415759fc13593ed2919fJarod Wilson
492e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	/* Default (0) and current (1) video capturing and overlay
493e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   cropping parameters in bttv_tvnorm.cropcap units. Protected
494e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   by bttv.lock. */
495e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	struct bttv_crop crop[2];
496e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek
497e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	/* Earliest possible start of video capturing in
498e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   bttv_tvnorm.cropcap line units. Set by check_alloc_btres()
499e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   and free_btres(). Protected by bttv.lock. */
500e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	__s32			vbi_end;
501e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek
502e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	/* Latest possible end of VBI capturing (= crop[x].rect.top when
503e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   VIDEO_RESOURCES are locked). Set by check_alloc_btres()
504e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	   and free_btres(). Protected by bttv.lock. */
505e5bd0260e7d3d806e66c12859f50733dca43bbcfMichael Schimek	__s32			crop_start;
5061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
5072d03e289ea4b13d78ce55f1ea0b0d45b8f1b34c3Mauro Carvalho Chehab
50874fc7bd9cec0ccdbea23659208492ec7ffc58297Hans Verkuilstatic inline struct bttv *to_bttv(struct v4l2_device *v4l2_dev)
50974fc7bd9cec0ccdbea23659208492ec7ffc58297Hans Verkuil{
51074fc7bd9cec0ccdbea23659208492ec7ffc58297Hans Verkuil	return container_of(v4l2_dev, struct bttv, c.v4l2_dev);
51174fc7bd9cec0ccdbea23659208492ec7ffc58297Hans Verkuil}
51274fc7bd9cec0ccdbea23659208492ec7ffc58297Hans Verkuil
5132d03e289ea4b13d78ce55f1ea0b0d45b8f1b34c3Mauro Carvalho Chehab/* our devices */
5142499abe710a86084eee1c0d5662ebd43c261350dAlan McIvor#define BTTV_MAX 32
5152d03e289ea4b13d78ce55f1ea0b0d45b8f1b34c3Mauro Carvalho Chehabextern unsigned int bttv_num;
5164b10d3b626922ffa2387905a230b12450281a12dTrent Piephoextern struct bttv *bttvs[BTTV_MAX];
5171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
5186f98700a5bb8d218162b04db1b8a3921a0dcc7ceTrent Piephostatic inline unsigned int bttv_muxsel(const struct bttv *btv,
5196f98700a5bb8d218162b04db1b8a3921a0dcc7ceTrent Piepho				       unsigned int input)
5206f98700a5bb8d218162b04db1b8a3921a0dcc7ceTrent Piepho{
5216f98700a5bb8d218162b04db1b8a3921a0dcc7ceTrent Piepho	return (bttv_tvcards[btv->c.type].muxsel >> (input * 2)) & 3;
5226f98700a5bb8d218162b04db1b8a3921a0dcc7ceTrent Piepho}
5236f98700a5bb8d218162b04db1b8a3921a0dcc7ceTrent Piepho
5241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
5251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
5261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define btwrite(dat,adr)    writel((dat), btv->bt848_mmio+(adr))
5271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define btread(adr)         readl(btv->bt848_mmio+(adr))
5281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
5291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define btand(dat,adr)      btwrite((dat) & btread(adr), adr)
5301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define btor(dat,adr)       btwrite((dat) | btread(adr), adr)
5311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
5321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
5331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* _BTTVP_H_ */
5341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
5351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
5361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Local variables:
5371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * c-basic-offset: 8
5381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * End:
5391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
540