blob: f7849f852e9d100af2ff9ef08ce6bfa12648fa1a [file] [log] [blame]
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001/*
2 ivtv driver internal defines and structures
3 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
4 Copyright (C) 2004 Chris Kennedy <c@groovy.org>
5 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#ifndef IVTV_DRIVER_H
23#define IVTV_DRIVER_H
24
25/* Internal header for ivtv project:
26 * Driver for the cx23415/6 chip.
27 * Author: Kevin Thayer (nufan_wfk at yahoo.com)
28 * License: GPL
29 * http://www.ivtvdriver.org
30 *
31 * -----
32 * MPG600/MPG160 support by T.Adachi <tadachi@tadachi-net.com>
33 * and Takeru KOMORIYA<komoriya@paken.org>
34 *
35 * AVerMedia M179 GPIO info by Chris Pinkham <cpinkham@bc2va.org>
36 * using information provided by Jiun-Kuei Jung @ AVerMedia.
37 */
38
39#include <linux/version.h>
40#include <linux/module.h>
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030041#include <linux/init.h>
42#include <linux/delay.h>
43#include <linux/sched.h>
44#include <linux/fs.h>
45#include <linux/pci.h>
46#include <linux/interrupt.h>
47#include <linux/spinlock.h>
48#include <linux/i2c.h>
49#include <linux/i2c-algo-bit.h>
50#include <linux/list.h>
51#include <linux/unistd.h>
52#include <linux/byteorder/swab.h>
53#include <linux/pagemap.h>
54#include <linux/workqueue.h>
55#include <linux/mutex.h>
56#include <asm/uaccess.h>
57#include <asm/system.h>
58
59#include <linux/dvb/video.h>
60#include <linux/dvb/audio.h>
61#include <media/v4l2-common.h>
62#include <media/tuner.h>
63#include <media/cx2341x.h>
64
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030065#include <media/ivtv.h>
66
Hans Verkuil37297802007-09-11 11:59:15 -030067
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030068#define IVTV_ENCODER_OFFSET 0x00000000
69#define IVTV_ENCODER_SIZE 0x00800000 /* Last half isn't needed 0x01000000 */
70
71#define IVTV_DECODER_OFFSET 0x01000000
72#define IVTV_DECODER_SIZE 0x00800000 /* Last half isn't needed 0x01000000 */
73
74#define IVTV_REG_OFFSET 0x02000000
75#define IVTV_REG_SIZE 0x00010000
76
Hans Verkuil32db7752007-07-20 09:29:43 -030077/* Maximum ivtv driver instances. Some people have a huge number of
78 capture cards, so set this to a high value. */
79#define IVTV_MAX_CARDS 32
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030080
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030081#define IVTV_ENC_STREAM_TYPE_MPG 0
82#define IVTV_ENC_STREAM_TYPE_YUV 1
83#define IVTV_ENC_STREAM_TYPE_VBI 2
84#define IVTV_ENC_STREAM_TYPE_PCM 3
85#define IVTV_ENC_STREAM_TYPE_RAD 4
86#define IVTV_DEC_STREAM_TYPE_MPG 5
87#define IVTV_DEC_STREAM_TYPE_VBI 6
88#define IVTV_DEC_STREAM_TYPE_VOUT 7
89#define IVTV_DEC_STREAM_TYPE_YUV 8
90#define IVTV_MAX_STREAMS 9
91
92#define IVTV_V4L2_DEC_MPG_OFFSET 16 /* offset from 0 to register decoder mpg v4l2 minors on */
93#define IVTV_V4L2_ENC_PCM_OFFSET 24 /* offset from 0 to register pcm v4l2 minors on */
94#define IVTV_V4L2_ENC_YUV_OFFSET 32 /* offset from 0 to register yuv v4l2 minors on */
95#define IVTV_V4L2_DEC_YUV_OFFSET 48 /* offset from 0 to register decoder yuv v4l2 minors on */
96#define IVTV_V4L2_DEC_VBI_OFFSET 8 /* offset from 0 to register decoder vbi input v4l2 minors on */
97#define IVTV_V4L2_DEC_VOUT_OFFSET 16 /* offset from 0 to register vbi output v4l2 minors on */
98
99#define IVTV_ENC_MEM_START 0x00000000
100#define IVTV_DEC_MEM_START 0x01000000
101
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300102/* Decoder Buffer hardware size on Chip */
103#define IVTV_DEC_MAX_BUF 0x00100000 /* max bytes in decoder buffer */
104#define IVTV_DEC_MIN_BUF 0x00010000 /* min bytes in dec buffer */
105
106/* ======================================================================== */
107/* ========================== START USER SETTABLE DMA VARIABLES =========== */
108/* ======================================================================== */
109
110#define IVTV_DMA_SG_OSD_ENT (2883584/PAGE_SIZE) /* sg entities */
111
112/* DMA Buffers, Default size in MB allocated */
113#define IVTV_DEFAULT_ENC_MPG_BUFFERS 4
114#define IVTV_DEFAULT_ENC_YUV_BUFFERS 2
115#define IVTV_DEFAULT_ENC_VBI_BUFFERS 1
Hans Verkuil313e91e2007-08-19 05:32:33 -0300116/* Exception: size in kB for this stream (MB is overkill) */
117#define IVTV_DEFAULT_ENC_PCM_BUFFERS 320
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300118#define IVTV_DEFAULT_DEC_MPG_BUFFERS 1
119#define IVTV_DEFAULT_DEC_YUV_BUFFERS 1
Hans Verkuil313e91e2007-08-19 05:32:33 -0300120/* Exception: size in kB for this stream (MB is way overkill) */
121#define IVTV_DEFAULT_DEC_VBI_BUFFERS 64
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300122
123/* ======================================================================== */
124/* ========================== END USER SETTABLE DMA VARIABLES ============= */
125/* ======================================================================== */
126
127/* Decoder Status Register */
128#define IVTV_DMA_ERR_LIST 0x00000010
129#define IVTV_DMA_ERR_WRITE 0x00000008
130#define IVTV_DMA_ERR_READ 0x00000004
131#define IVTV_DMA_SUCCESS_WRITE 0x00000002
132#define IVTV_DMA_SUCCESS_READ 0x00000001
133#define IVTV_DMA_READ_ERR (IVTV_DMA_ERR_LIST | IVTV_DMA_ERR_READ)
134#define IVTV_DMA_WRITE_ERR (IVTV_DMA_ERR_LIST | IVTV_DMA_ERR_WRITE)
135#define IVTV_DMA_ERR (IVTV_DMA_ERR_LIST | IVTV_DMA_ERR_WRITE | IVTV_DMA_ERR_READ)
136
137/* DMA Registers */
138#define IVTV_REG_DMAXFER (0x0000)
139#define IVTV_REG_DMASTATUS (0x0004)
140#define IVTV_REG_DECDMAADDR (0x0008)
141#define IVTV_REG_ENCDMAADDR (0x000c)
142#define IVTV_REG_DMACONTROL (0x0010)
143#define IVTV_REG_IRQSTATUS (0x0040)
144#define IVTV_REG_IRQMASK (0x0048)
145
146/* Setup Registers */
147#define IVTV_REG_ENC_SDRAM_REFRESH (0x07F8)
148#define IVTV_REG_ENC_SDRAM_PRECHARGE (0x07FC)
149#define IVTV_REG_DEC_SDRAM_REFRESH (0x08F8)
150#define IVTV_REG_DEC_SDRAM_PRECHARGE (0x08FC)
151#define IVTV_REG_VDM (0x2800)
152#define IVTV_REG_AO (0x2D00)
153#define IVTV_REG_BYTEFLUSH (0x2D24)
154#define IVTV_REG_SPU (0x9050)
155#define IVTV_REG_HW_BLOCKS (0x9054)
156#define IVTV_REG_VPU (0x9058)
157#define IVTV_REG_APU (0xA064)
158
159#define IVTV_IRQ_ENC_START_CAP (0x1 << 31)
160#define IVTV_IRQ_ENC_EOS (0x1 << 30)
161#define IVTV_IRQ_ENC_VBI_CAP (0x1 << 29)
162#define IVTV_IRQ_ENC_VIM_RST (0x1 << 28)
163#define IVTV_IRQ_ENC_DMA_COMPLETE (0x1 << 27)
Hans Verkuildc02d502007-05-19 14:07:16 -0300164#define IVTV_IRQ_ENC_PIO_COMPLETE (0x1 << 25)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300165#define IVTV_IRQ_DEC_AUD_MODE_CHG (0x1 << 24)
166#define IVTV_IRQ_DEC_DATA_REQ (0x1 << 22)
167#define IVTV_IRQ_DEC_DMA_COMPLETE (0x1 << 20)
168#define IVTV_IRQ_DEC_VBI_RE_INSERT (0x1 << 19)
169#define IVTV_IRQ_DMA_ERR (0x1 << 18)
170#define IVTV_IRQ_DMA_WRITE (0x1 << 17)
171#define IVTV_IRQ_DMA_READ (0x1 << 16)
172#define IVTV_IRQ_DEC_VSYNC (0x1 << 10)
173
174/* IRQ Masks */
Hans Verkuildc02d502007-05-19 14:07:16 -0300175#define IVTV_IRQ_MASK_INIT (IVTV_IRQ_DMA_ERR|IVTV_IRQ_ENC_DMA_COMPLETE|\
176 IVTV_IRQ_DMA_READ|IVTV_IRQ_ENC_PIO_COMPLETE)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300177
178#define IVTV_IRQ_MASK_CAPTURE (IVTV_IRQ_ENC_START_CAP | IVTV_IRQ_ENC_EOS)
179#define IVTV_IRQ_MASK_DECODE (IVTV_IRQ_DEC_DATA_REQ|IVTV_IRQ_DEC_AUD_MODE_CHG)
180
181/* i2c stuff */
182#define I2C_CLIENTS_MAX 16
183
184/* debugging */
185
Hans Verkuil1aa32c22007-08-19 06:08:58 -0300186#define IVTV_DBGFLG_WARN (1 << 0)
187#define IVTV_DBGFLG_INFO (1 << 1)
188#define IVTV_DBGFLG_MB (1 << 2)
189#define IVTV_DBGFLG_IOCTL (1 << 3)
190#define IVTV_DBGFLG_FILE (1 << 4)
191#define IVTV_DBGFLG_DMA (1 << 5)
192#define IVTV_DBGFLG_IRQ (1 << 6)
193#define IVTV_DBGFLG_DEC (1 << 7)
194#define IVTV_DBGFLG_YUV (1 << 8)
195#define IVTV_DBGFLG_I2C (1 << 9)
Hans Verkuilbd58df62007-07-10 17:47:07 -0300196/* Flag to turn on high volume debugging */
Hans Verkuil1aa32c22007-08-19 06:08:58 -0300197#define IVTV_DBGFLG_HIGHVOL (1 << 10)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300198
199/* NOTE: extra space before comma in 'itv->num , ## args' is required for
200 gcc-2.95, otherwise it won't compile. */
201#define IVTV_DEBUG(x, type, fmt, args...) \
202 do { \
203 if ((x) & ivtv_debug) \
204 printk(KERN_INFO "ivtv%d " type ": " fmt, itv->num , ## args); \
205 } while (0)
Hans Verkuil1aa32c22007-08-19 06:08:58 -0300206#define IVTV_DEBUG_WARN(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_WARN, "warn", fmt , ## args)
207#define IVTV_DEBUG_INFO(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_INFO, "info", fmt , ## args)
208#define IVTV_DEBUG_MB(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_MB, "mb", fmt , ## args)
209#define IVTV_DEBUG_DMA(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_DMA, "dma", fmt , ## args)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300210#define IVTV_DEBUG_IOCTL(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_IOCTL, "ioctl", fmt , ## args)
Hans Verkuil1aa32c22007-08-19 06:08:58 -0300211#define IVTV_DEBUG_FILE(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_FILE, "file", fmt , ## args)
212#define IVTV_DEBUG_I2C(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_I2C, "i2c", fmt , ## args)
213#define IVTV_DEBUG_IRQ(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_IRQ, "irq", fmt , ## args)
214#define IVTV_DEBUG_DEC(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_DEC, "dec", fmt , ## args)
215#define IVTV_DEBUG_YUV(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_YUV, "yuv", fmt , ## args)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300216
Hans Verkuilbd58df62007-07-10 17:47:07 -0300217#define IVTV_DEBUG_HIGH_VOL(x, type, fmt, args...) \
218 do { \
219 if (((x) & ivtv_debug) && (ivtv_debug & IVTV_DBGFLG_HIGHVOL)) \
220 printk(KERN_INFO "ivtv%d " type ": " fmt, itv->num , ## args); \
221 } while (0)
Hans Verkuil1aa32c22007-08-19 06:08:58 -0300222#define IVTV_DEBUG_HI_WARN(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_WARN, "warn", fmt , ## args)
223#define IVTV_DEBUG_HI_INFO(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_INFO, "info", fmt , ## args)
224#define IVTV_DEBUG_HI_MB(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_MB, "mb", fmt , ## args)
225#define IVTV_DEBUG_HI_DMA(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_DMA, "dma", fmt , ## args)
Hans Verkuilbd58df62007-07-10 17:47:07 -0300226#define IVTV_DEBUG_HI_IOCTL(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_IOCTL, "ioctl", fmt , ## args)
Hans Verkuil1aa32c22007-08-19 06:08:58 -0300227#define IVTV_DEBUG_HI_FILE(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_FILE, "file", fmt , ## args)
228#define IVTV_DEBUG_HI_I2C(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_I2C, "i2c", fmt , ## args)
229#define IVTV_DEBUG_HI_IRQ(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_IRQ, "irq", fmt , ## args)
230#define IVTV_DEBUG_HI_DEC(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_DEC, "dec", fmt , ## args)
231#define IVTV_DEBUG_HI_YUV(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_YUV, "yuv", fmt , ## args)
Hans Verkuilbd58df62007-07-10 17:47:07 -0300232
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300233/* Standard kernel messages */
234#define IVTV_ERR(fmt, args...) printk(KERN_ERR "ivtv%d: " fmt, itv->num , ## args)
235#define IVTV_WARN(fmt, args...) printk(KERN_WARNING "ivtv%d: " fmt, itv->num , ## args)
236#define IVTV_INFO(fmt, args...) printk(KERN_INFO "ivtv%d: " fmt, itv->num , ## args)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300237
238/* Values for IVTV_API_DEC_PLAYBACK_SPEED mpeg_frame_type_mask parameter: */
239#define MPEG_FRAME_TYPE_IFRAME 1
240#define MPEG_FRAME_TYPE_IFRAME_PFRAME 3
241#define MPEG_FRAME_TYPE_ALL 7
242
243/* output modes (cx23415 only) */
244#define OUT_NONE 0
245#define OUT_MPG 1
246#define OUT_YUV 2
247#define OUT_UDMA_YUV 3
248#define OUT_PASSTHROUGH 4
249
250#define IVTV_MAX_PGM_INDEX (400)
251
252extern int ivtv_debug;
253
254
255struct ivtv_options {
Hans Verkuil313e91e2007-08-19 05:32:33 -0300256 int kilobytes[IVTV_MAX_STREAMS]; /* Size in kilobytes of each stream */
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300257 int cardtype; /* force card type on load */
258 int tuner; /* set tuner on load */
259 int radio; /* enable/disable radio */
260 int newi2c; /* New I2C algorithm */
261};
262
263#define IVTV_MBOX_DMA_START 6
264#define IVTV_MBOX_DMA_END 8
265#define IVTV_MBOX_DMA 9
266#define IVTV_MBOX_FIELD_DISPLAYED 8
267
268/* ivtv-specific mailbox template */
269struct ivtv_mailbox {
270 u32 flags;
271 u32 cmd;
272 u32 retval;
273 u32 timeout;
274 u32 data[CX2341X_MBOX_MAX_DATA];
275};
276
277struct ivtv_api_cache {
278 unsigned long last_jiffies; /* when last command was issued */
279 u32 data[CX2341X_MBOX_MAX_DATA]; /* last sent api data */
280};
281
282struct ivtv_mailbox_data {
283 volatile struct ivtv_mailbox __iomem *mbox;
284 /* Bits 0-2 are for the encoder mailboxes, 0-1 are for the decoder mailboxes.
285 If the bit is set, then the corresponding mailbox is in use by the driver. */
286 unsigned long busy;
287 u8 max_mbox;
288};
289
290/* per-buffer bit flags */
Hans Verkuilf4071b82007-07-28 12:07:12 -0300291#define IVTV_F_B_NEED_BUF_SWAP (1 << 0) /* this buffer should be byte swapped */
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300292
293/* per-stream, s_flags */
294#define IVTV_F_S_DMA_PENDING 0 /* this stream has pending DMA */
295#define IVTV_F_S_DMA_HAS_VBI 1 /* the current DMA request also requests VBI data */
296#define IVTV_F_S_NEEDS_DATA 2 /* this decoding stream needs more data */
297
298#define IVTV_F_S_CLAIMED 3 /* this stream is claimed */
299#define IVTV_F_S_STREAMING 4 /* the fw is decoding/encoding this stream */
300#define IVTV_F_S_INTERNAL_USE 5 /* this stream is used internally (sliced VBI processing) */
301#define IVTV_F_S_PASSTHROUGH 6 /* this stream is in passthrough mode */
302#define IVTV_F_S_STREAMOFF 7 /* signal end of stream EOS */
303#define IVTV_F_S_APPL_IO 8 /* this stream is used read/written by an application */
304
Hans Verkuildc02d502007-05-19 14:07:16 -0300305#define IVTV_F_S_PIO_PENDING 9 /* this stream has pending PIO */
306#define IVTV_F_S_PIO_HAS_VBI 1 /* the current PIO request also requests VBI data */
307
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300308/* per-ivtv, i_flags */
Hans Verkuil1e13f9e2007-03-10 06:52:02 -0300309#define IVTV_F_I_DMA 0 /* DMA in progress */
310#define IVTV_F_I_UDMA 1 /* UDMA in progress */
311#define IVTV_F_I_UDMA_PENDING 2 /* UDMA pending */
312#define IVTV_F_I_SPEED_CHANGE 3 /* A speed change is in progress */
313#define IVTV_F_I_EOS 4 /* End of encoder stream reached */
314#define IVTV_F_I_RADIO_USER 5 /* The radio tuner is selected */
315#define IVTV_F_I_DIG_RST 6 /* Reset digitizer */
316#define IVTV_F_I_DEC_YUV 7 /* YUV instead of MPG is being decoded */
Hans Verkuil1e13f9e2007-03-10 06:52:02 -0300317#define IVTV_F_I_UPDATE_CC 9 /* CC should be updated */
318#define IVTV_F_I_UPDATE_WSS 10 /* WSS should be updated */
319#define IVTV_F_I_UPDATE_VPS 11 /* VPS should be updated */
320#define IVTV_F_I_DECODING_YUV 12 /* this stream is YUV frame decoding */
321#define IVTV_F_I_ENC_PAUSED 13 /* the encoder is paused */
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300322#define IVTV_F_I_VALID_DEC_TIMINGS 14 /* last_dec_timing is valid */
Hans Verkuildc02d502007-05-19 14:07:16 -0300323#define IVTV_F_I_HAVE_WORK 15 /* Used in the interrupt handler: there is work to be done */
324#define IVTV_F_I_WORK_HANDLER_VBI 16 /* there is work to be done for VBI */
325#define IVTV_F_I_WORK_HANDLER_YUV 17 /* there is work to be done for YUV */
326#define IVTV_F_I_WORK_HANDLER_PIO 18 /* there is work to be done for PIO */
327#define IVTV_F_I_PIO 19 /* PIO in progress */
Hans Verkuilac425142007-07-22 08:46:38 -0300328#define IVTV_F_I_DEC_PAUSED 20 /* the decoder is paused */
Hans Verkuilc976bc82007-07-22 12:52:40 -0300329#define IVTV_F_I_INITED 21 /* set after first open */
330#define IVTV_F_I_FAILED 22 /* set if first open failed */
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300331
332/* Event notifications */
Hans Verkuil1e13f9e2007-03-10 06:52:02 -0300333#define IVTV_F_I_EV_DEC_STOPPED 28 /* decoder stopped event */
334#define IVTV_F_I_EV_VSYNC 29 /* VSYNC event */
335#define IVTV_F_I_EV_VSYNC_FIELD 30 /* VSYNC event field (0 = first, 1 = second field) */
336#define IVTV_F_I_EV_VSYNC_ENABLED 31 /* VSYNC event enabled */
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300337
338/* Scatter-Gather array element, used in DMA transfers */
Hans Verkuil37093b12007-07-28 19:45:50 -0300339struct ivtv_sg_element {
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300340 u32 src;
341 u32 dst;
342 u32 size;
343};
344
345struct ivtv_user_dma {
346 struct mutex lock;
347 int page_count;
348 struct page *map[IVTV_DMA_SG_OSD_ENT];
Hans Verkuil0989fd2c2007-08-19 12:25:39 -0300349 /* Needed when dealing with highmem userspace buffers */
350 struct page *bouncemap[IVTV_DMA_SG_OSD_ENT];
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300351
352 /* Base Dev SG Array for cx23415/6 */
Hans Verkuil37093b12007-07-28 19:45:50 -0300353 struct ivtv_sg_element SGarray[IVTV_DMA_SG_OSD_ENT];
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300354 dma_addr_t SG_handle;
355 int SG_length;
356
357 /* SG List of Buffers */
358 struct scatterlist SGlist[IVTV_DMA_SG_OSD_ENT];
359};
360
361struct ivtv_dma_page_info {
362 unsigned long uaddr;
363 unsigned long first;
364 unsigned long last;
365 unsigned int offset;
366 unsigned int tail;
367 int page_count;
368};
369
370struct ivtv_buffer {
371 struct list_head list;
372 dma_addr_t dma_handle;
Hans Verkuilf4071b82007-07-28 12:07:12 -0300373 unsigned short b_flags;
374 unsigned short dma_xfer_cnt;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300375 char *buf;
376
377 u32 bytesused;
378 u32 readpos;
379};
380
381struct ivtv_queue {
382 struct list_head list;
383 u32 buffers;
384 u32 length;
385 u32 bytesused;
386};
387
388struct ivtv; /* forward reference */
389
390struct ivtv_stream {
391 /* These first four fields are always set, even if the stream
392 is not actually created. */
393 struct video_device *v4l2dev; /* NULL when stream not created */
394 struct ivtv *itv; /* for ease of use */
395 const char *name; /* name of the stream */
396 int type; /* stream type */
397
398 u32 id;
399 spinlock_t qlock; /* locks access to the queues */
400 unsigned long s_flags; /* status flags, see above */
401 int dma; /* can be PCI_DMA_TODEVICE,
402 PCI_DMA_FROMDEVICE or
403 PCI_DMA_NONE */
Hans Verkuil37093b12007-07-28 19:45:50 -0300404 u32 pending_offset;
405 u32 pending_backup;
406 u64 pending_pts;
407
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300408 u32 dma_offset;
409 u32 dma_backup;
410 u64 dma_pts;
411
412 int subtype;
413 wait_queue_head_t waitq;
414 u32 dma_last_offset;
415
416 /* Buffer Stats */
417 u32 buffers;
418 u32 buf_size;
419 u32 buffers_stolen;
420
421 /* Buffer Queues */
422 struct ivtv_queue q_free; /* free buffers */
423 struct ivtv_queue q_full; /* full buffers */
424 struct ivtv_queue q_io; /* waiting for I/O */
425 struct ivtv_queue q_dma; /* waiting for DMA */
426 struct ivtv_queue q_predma; /* waiting for DMA */
427
Hans Verkuilf4071b82007-07-28 12:07:12 -0300428 /* DMA xfer counter, buffers belonging to the same DMA
429 xfer will have the same dma_xfer_cnt. */
430 u16 dma_xfer_cnt;
431
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300432 /* Base Dev SG Array for cx23415/6 */
Hans Verkuil37093b12007-07-28 19:45:50 -0300433 struct ivtv_sg_element *sg_pending;
434 struct ivtv_sg_element *sg_processing;
435 struct ivtv_sg_element *sg_dma;
436 dma_addr_t sg_handle;
437 int sg_pending_size;
438 int sg_processing_size;
439 int sg_processed;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300440
441 /* SG List of Buffers */
442 struct scatterlist *SGlist;
443};
444
445struct ivtv_open_id {
446 u32 open_id;
447 int type;
Hans Verkuilad8ff0f2007-08-20 16:01:58 -0300448 int yuv_frames;
Hans Verkuild46c17d2007-03-10 17:59:15 -0300449 enum v4l2_priority prio;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300450 struct ivtv *itv;
451};
452
453#define IVTV_YUV_UPDATE_HORIZONTAL 0x01
454#define IVTV_YUV_UPDATE_VERTICAL 0x02
455
456struct yuv_frame_info
457{
458 u32 update;
459 int src_x;
460 int src_y;
461 unsigned int src_w;
462 unsigned int src_h;
463 int dst_x;
464 int dst_y;
465 unsigned int dst_w;
466 unsigned int dst_h;
467 int pan_x;
468 int pan_y;
469 u32 vis_w;
470 u32 vis_h;
471 u32 interlaced_y;
472 u32 interlaced_uv;
473 int tru_x;
474 u32 tru_w;
475 u32 tru_h;
476 u32 offset_y;
Ian Armstrongbfd7bea2007-08-03 10:01:39 -0300477 int lace_mode;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300478};
479
480#define IVTV_YUV_MODE_INTERLACED 0x00
481#define IVTV_YUV_MODE_PROGRESSIVE 0x01
482#define IVTV_YUV_MODE_AUTO 0x02
483#define IVTV_YUV_MODE_MASK 0x03
484
485#define IVTV_YUV_SYNC_EVEN 0x00
486#define IVTV_YUV_SYNC_ODD 0x04
487#define IVTV_YUV_SYNC_MASK 0x04
488
489struct yuv_playback_info
490{
491 u32 reg_2834;
492 u32 reg_2838;
493 u32 reg_283c;
494 u32 reg_2840;
495 u32 reg_2844;
496 u32 reg_2848;
497 u32 reg_2854;
498 u32 reg_285c;
499 u32 reg_2864;
500
501 u32 reg_2870;
502 u32 reg_2874;
503 u32 reg_2890;
504 u32 reg_2898;
505 u32 reg_289c;
506
507 u32 reg_2918;
508 u32 reg_291c;
509 u32 reg_2920;
510 u32 reg_2924;
511 u32 reg_2928;
512 u32 reg_292c;
513 u32 reg_2930;
514
515 u32 reg_2934;
516
517 u32 reg_2938;
518 u32 reg_293c;
519 u32 reg_2940;
520 u32 reg_2944;
521 u32 reg_2948;
522 u32 reg_294c;
523 u32 reg_2950;
524 u32 reg_2954;
525 u32 reg_2958;
526 u32 reg_295c;
527 u32 reg_2960;
528 u32 reg_2964;
529 u32 reg_2968;
530 u32 reg_296c;
531
532 u32 reg_2970;
533
534 int v_filter_1;
535 int v_filter_2;
536 int h_filter;
537
538 u32 osd_x_offset;
539 u32 osd_y_offset;
540
541 u32 osd_x_pan;
542 u32 osd_y_pan;
543
544 u32 osd_vis_w;
545 u32 osd_vis_h;
546
547 int decode_height;
548
549 int frame_interlaced;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300550
551 int lace_mode;
552 int lace_threshold;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300553 int lace_sync_field;
554
555 atomic_t next_dma_frame;
556 atomic_t next_fill_frame;
557
558 u32 yuv_forced_update;
559 int update_frame;
Ian Armstrongbfd7bea2007-08-03 10:01:39 -0300560
561 int sync_field[4]; /* Field to sync on */
562 int field_delay[4]; /* Flag to extend duration of previous frame */
563 u8 fields_lapsed; /* Counter used when delaying a frame */
564
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300565 struct yuv_frame_info new_frame_info[4];
566 struct yuv_frame_info old_frame_info;
567 struct yuv_frame_info old_frame_info_args;
568
569 void *blanking_ptr;
570 dma_addr_t blanking_dmaptr;
571};
572
573#define IVTV_VBI_FRAMES 32
574
575/* VBI data */
576struct vbi_info {
577 u32 dec_start;
578 u32 enc_start, enc_size;
579 int fpi;
580 u32 frame;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300581 u8 cc_data_odd[256];
582 u8 cc_data_even[256];
583 int cc_pos;
584 u8 cc_no_update;
585 u8 vps[5];
586 u8 vps_found;
587 int wss;
588 u8 wss_found;
589 u8 wss_no_update;
590 u32 raw_decoder_line_size;
591 u8 raw_decoder_sav_odd_field;
592 u8 raw_decoder_sav_even_field;
593 u32 sliced_decoder_line_size;
594 u8 sliced_decoder_sav_odd_field;
595 u8 sliced_decoder_sav_even_field;
596 struct v4l2_format in;
597 /* convenience pointer to sliced struct in vbi_in union */
598 struct v4l2_sliced_vbi_format *sliced_in;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300599 int insert_mpeg;
600
601 /* Buffer for the maximum of 2 * 18 * packet_size sliced VBI lines.
602 One for /dev/vbi0 and one for /dev/vbi8 */
603 struct v4l2_sliced_vbi_data sliced_data[36];
604 struct v4l2_sliced_vbi_data sliced_dec_data[36];
605
606 /* Buffer for VBI data inserted into MPEG stream.
607 The first byte is a dummy byte that's never used.
608 The next 16 bytes contain the MPEG header for the VBI data,
609 the remainder is the actual VBI data.
610 The max size accepted by the MPEG VBI reinsertion turns out
611 to be 1552 bytes, which happens to be 4 + (1 + 42) * (2 * 18) bytes,
612 where 4 is a four byte header, 42 is the max sliced VBI payload, 1 is
613 a single line header byte and 2 * 18 is the number of VBI lines per frame.
614
615 However, it seems that the data must be 1K aligned, so we have to
616 pad the data until the 1 or 2 K boundary.
617
618 This pointer array will allocate 2049 bytes to store each VBI frame. */
619 u8 *sliced_mpeg_data[IVTV_VBI_FRAMES];
620 u32 sliced_mpeg_size[IVTV_VBI_FRAMES];
621 struct ivtv_buffer sliced_mpeg_buf;
622 u32 inserted_frame;
623
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300624 u32 start[2], count;
625 u32 raw_size;
626 u32 sliced_size;
627};
628
629/* forward declaration of struct defined in ivtv-cards.h */
630struct ivtv_card;
631
632/* Struct to hold info about ivtv cards */
633struct ivtv {
634 int num; /* board number, -1 during init! */
635 char name[8]; /* board name for printk and interrupts (e.g. 'ivtv0') */
636 struct pci_dev *dev; /* PCI device */
637 const struct ivtv_card *card; /* card information */
638 const char *card_name; /* full name of the card */
639 u8 has_cx23415; /* 1 if it is a cx23415 based card, 0 for cx23416 */
640 u8 is_50hz;
641 u8 is_60hz;
642 u8 is_out_50hz;
643 u8 is_out_60hz;
644 u8 pvr150_workaround; /* 1 if the cx25840 needs to workaround a PVR150 bug */
645 u8 nof_inputs; /* number of video inputs */
646 u8 nof_audio_inputs; /* number of audio inputs */
647 u32 v4l2_cap; /* V4L2 capabilities of card */
648 u32 hw_flags; /* Hardware description of the board */
Hans Verkuil37297802007-09-11 11:59:15 -0300649 int tunerid; /* Userspace tuner ID for experimental Xceive tuner support */
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300650
651 /* controlling Video decoder function */
652 int (*video_dec_func)(struct ivtv *, unsigned int, void *);
653
654 struct ivtv_options options; /* User options */
655 int stream_buf_size[IVTV_MAX_STREAMS]; /* Stream buffer size */
656 struct ivtv_stream streams[IVTV_MAX_STREAMS]; /* Stream data */
657 int speed;
658 u8 speed_mute_audio;
659 unsigned long i_flags; /* global ivtv flags */
660 atomic_t capturing; /* count number of active capture streams */
661 atomic_t decoding; /* count number of active decoding streams */
662 u32 irq_rr_idx; /* Round-robin stream index */
663 int cur_dma_stream; /* index of stream doing DMA */
Hans Verkuildc02d502007-05-19 14:07:16 -0300664 int cur_pio_stream; /* index of stream doing PIO */
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300665 u32 dma_data_req_offset;
666 u32 dma_data_req_size;
Hans Verkuil37093b12007-07-28 19:45:50 -0300667 int dma_retries;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300668 int output_mode; /* NONE, MPG, YUV, UDMA YUV, passthrough */
669 spinlock_t lock; /* lock access to this struct */
670 int search_pack_header;
671
672 spinlock_t dma_reg_lock; /* lock access to DMA engine registers */
Hans Verkuilf8859692007-07-10 14:58:33 -0300673 struct mutex serialize_lock; /* lock used to serialize starting streams */
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300674
675 /* User based DMA for OSD */
676 struct ivtv_user_dma udma;
677
678 int open_id; /* incremented each time an open occurs, used as unique ID.
679 starts at 1, so 0 can be used as uninitialized value
680 in the stream->id. */
681
682 u32 base_addr;
683 u32 irqmask;
Hans Verkuil1e13f9e2007-03-10 06:52:02 -0300684
Hans Verkuild46c17d2007-03-10 17:59:15 -0300685 struct v4l2_prio_state prio;
Hans Verkuil1e13f9e2007-03-10 06:52:02 -0300686 struct workqueue_struct *irq_work_queues;
687 struct work_struct irq_work_queue;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300688 struct timer_list dma_timer; /* Timer used to catch unfinished DMAs */
689
690 struct vbi_info vbi;
691
692 struct ivtv_mailbox_data enc_mbox;
693 struct ivtv_mailbox_data dec_mbox;
694 struct ivtv_api_cache api_cache[256]; /* Cached API Commands */
695
696 u8 card_rev;
697 volatile void __iomem *enc_mem, *dec_mem, *reg_mem;
698
699 u32 pgm_info_offset;
700 u32 pgm_info_num;
701 u32 pgm_info_write_idx;
702 u32 pgm_info_read_idx;
703 struct v4l2_enc_idx_entry pgm_info[IVTV_MAX_PGM_INDEX];
704
705 u64 mpg_data_received;
706 u64 vbi_data_inserted;
707
708 wait_queue_head_t cap_w;
709 /* when the next decoder event arrives this queue is woken up */
710 wait_queue_head_t event_waitq;
711 /* when the next decoder vsync arrives this queue is woken up */
712 wait_queue_head_t vsync_waitq;
713 /* when the current DMA is finished this queue is woken up */
714 wait_queue_head_t dma_waitq;
715
716 /* OSD support */
717 unsigned long osd_video_pbase;
718 int osd_global_alpha_state; /* 0=off : 1=on */
719 int osd_local_alpha_state; /* 0=off : 1=on */
720 int osd_color_key_state; /* 0=off : 1=on */
721 u8 osd_global_alpha; /* Current global alpha */
722 u32 osd_color_key; /* Current color key */
723 u32 osd_pixelformat; /* Current pixel format */
724 struct v4l2_rect osd_rect; /* Current OSD position and size */
725 struct v4l2_rect main_rect; /* Current Main window position and size */
726
727 u32 last_dec_timing[3]; /* Store last retrieved pts/scr/frame values */
728
729 /* i2c */
730 struct i2c_adapter i2c_adap;
731 struct i2c_algo_bit_data i2c_algo;
732 struct i2c_client i2c_client;
733 struct mutex i2c_bus_lock;
734 int i2c_state;
735 struct i2c_client *i2c_clients[I2C_CLIENTS_MAX];
736
737 /* v4l2 and User settings */
738
739 /* codec settings */
740 struct cx2341x_mpeg_params params;
741 u32 audio_input;
742 u32 active_input;
743 u32 active_output;
744 v4l2_std_id std;
745 v4l2_std_id std_out;
746 v4l2_std_id tuner_std; /* The norm of the tuner (fixed) */
747 u8 audio_stereo_mode;
748 u8 audio_bilingual_mode;
749
750 /* dualwatch */
751 unsigned long dualwatch_jiffies;
752 u16 dualwatch_stereo_mode;
753
754 /* Digitizer type */
755 int digitizer; /* 0x00EF = saa7114 0x00FO = saa7115 0x0106 = mic */
756
757 u32 lastVsyncFrame;
758
759 struct yuv_playback_info yuv_info;
760 struct osd_info *osd_info;
761};
762
763/* Globals */
764extern struct ivtv *ivtv_cards[];
765extern int ivtv_cards_active;
766extern int ivtv_first_minor;
767extern spinlock_t ivtv_cards_lock;
768
769/*==============Prototypes==================*/
770
771/* Hardware/IRQ */
772void ivtv_set_irq_mask(struct ivtv *itv, u32 mask);
773void ivtv_clear_irq_mask(struct ivtv *itv, u32 mask);
774
775/* try to set output mode, return current mode. */
776int ivtv_set_output_mode(struct ivtv *itv, int mode);
777
778/* return current output stream based on current mode */
779struct ivtv_stream *ivtv_get_output_stream(struct ivtv *itv);
780
781/* Return non-zero if a signal is pending */
Mauro Carvalho Chehab201700d2007-07-19 11:21:04 -0300782int ivtv_msleep_timeout(unsigned int msecs, int intr);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300783
784/* Wait on queue, returns -EINTR if interrupted */
785int ivtv_waitq(wait_queue_head_t *waitq);
786
787/* Read Hauppauge eeprom */
788struct tveeprom; /* forward reference */
789void ivtv_read_eeprom(struct ivtv *itv, struct tveeprom *tv);
790
Hans Verkuilc976bc82007-07-22 12:52:40 -0300791/* First-open initialization: load firmware, init cx25840, etc. */
792int ivtv_init_on_first_open(struct ivtv *itv);
793
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300794/* This is a PCI post thing, where if the pci register is not read, then
795 the write doesn't always take effect right away. By reading back the
796 register any pending PCI writes will be performed (in order), and so
797 you can be sure that the writes are guaranteed to be done.
798
799 Rarely needed, only in some timing sensitive cases.
800 Apparently if this is not done some motherboards seem
801 to kill the firmware and get into the broken state until computer is
802 rebooted. */
803#define write_sync(val, reg) \
804 do { writel(val, reg); readl(reg); } while (0)
805
806#define read_reg(reg) readl(itv->reg_mem + (reg))
807#define write_reg(val, reg) writel(val, itv->reg_mem + (reg))
808#define write_reg_sync(val, reg) \
809 do { write_reg(val, reg); read_reg(reg); } while (0)
810
811#define read_enc(addr) readl(itv->enc_mem + (u32)(addr))
812#define write_enc(val, addr) writel(val, itv->enc_mem + (u32)(addr))
813#define write_enc_sync(val, addr) \
814 do { write_enc(val, addr); read_enc(addr); } while (0)
815
816#define read_dec(addr) readl(itv->dec_mem + (u32)(addr))
817#define write_dec(val, addr) writel(val, itv->dec_mem + (u32)(addr))
818#define write_dec_sync(val, addr) \
819 do { write_dec(val, addr); read_dec(addr); } while (0)
820
Hans Verkuil612570f2007-08-23 05:42:59 -0300821#endif