18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci ivtv driver internal defines and structures 38c2ecf20Sopenharmony_ci Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com> 48c2ecf20Sopenharmony_ci Copyright (C) 2004 Chris Kennedy <c@groovy.org> 58c2ecf20Sopenharmony_ci Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci This program is free software; you can redistribute it and/or modify 88c2ecf20Sopenharmony_ci it under the terms of the GNU General Public License as published by 98c2ecf20Sopenharmony_ci the Free Software Foundation; either version 2 of the License, or 108c2ecf20Sopenharmony_ci (at your option) any later version. 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci This program is distributed in the hope that it will be useful, 138c2ecf20Sopenharmony_ci but WITHOUT ANY WARRANTY; without even the implied warranty of 148c2ecf20Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 158c2ecf20Sopenharmony_ci GNU General Public License for more details. 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci You should have received a copy of the GNU General Public License 188c2ecf20Sopenharmony_ci along with this program; if not, write to the Free Software 198c2ecf20Sopenharmony_ci Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 208c2ecf20Sopenharmony_ci */ 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#ifndef IVTV_DRIVER_H 238c2ecf20Sopenharmony_ci#define IVTV_DRIVER_H 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* Internal header for ivtv project: 288c2ecf20Sopenharmony_ci * Driver for the cx23415/6 chip. 298c2ecf20Sopenharmony_ci * Author: Kevin Thayer (nufan_wfk at yahoo.com) 308c2ecf20Sopenharmony_ci * License: GPL 318c2ecf20Sopenharmony_ci * 328c2ecf20Sopenharmony_ci * ----- 338c2ecf20Sopenharmony_ci * MPG600/MPG160 support by T.Adachi <tadachi@tadachi-net.com> 348c2ecf20Sopenharmony_ci * and Takeru KOMORIYA<komoriya@paken.org> 358c2ecf20Sopenharmony_ci * 368c2ecf20Sopenharmony_ci * AVerMedia M179 GPIO info by Chris Pinkham <cpinkham@bc2va.org> 378c2ecf20Sopenharmony_ci * using information provided by Jiun-Kuei Jung @ AVerMedia. 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#include <linux/module.h> 418c2ecf20Sopenharmony_ci#include <linux/init.h> 428c2ecf20Sopenharmony_ci#include <linux/delay.h> 438c2ecf20Sopenharmony_ci#include <linux/sched/signal.h> 448c2ecf20Sopenharmony_ci#include <linux/fs.h> 458c2ecf20Sopenharmony_ci#include <linux/pci.h> 468c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 478c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 488c2ecf20Sopenharmony_ci#include <linux/i2c.h> 498c2ecf20Sopenharmony_ci#include <linux/i2c-algo-bit.h> 508c2ecf20Sopenharmony_ci#include <linux/list.h> 518c2ecf20Sopenharmony_ci#include <linux/unistd.h> 528c2ecf20Sopenharmony_ci#include <linux/pagemap.h> 538c2ecf20Sopenharmony_ci#include <linux/scatterlist.h> 548c2ecf20Sopenharmony_ci#include <linux/kthread.h> 558c2ecf20Sopenharmony_ci#include <linux/mutex.h> 568c2ecf20Sopenharmony_ci#include <linux/slab.h> 578c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 588c2ecf20Sopenharmony_ci#include <asm/byteorder.h> 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#include <linux/dvb/video.h> 618c2ecf20Sopenharmony_ci#include <linux/dvb/audio.h> 628c2ecf20Sopenharmony_ci#include <media/v4l2-common.h> 638c2ecf20Sopenharmony_ci#include <media/v4l2-ioctl.h> 648c2ecf20Sopenharmony_ci#include <media/v4l2-ctrls.h> 658c2ecf20Sopenharmony_ci#include <media/v4l2-device.h> 668c2ecf20Sopenharmony_ci#include <media/v4l2-fh.h> 678c2ecf20Sopenharmony_ci#include <media/tuner.h> 688c2ecf20Sopenharmony_ci#include <media/drv-intf/cx2341x.h> 698c2ecf20Sopenharmony_ci#include <media/i2c/ir-kbd-i2c.h> 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#include <linux/ivtv.h> 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci/* Memory layout */ 748c2ecf20Sopenharmony_ci#define IVTV_ENCODER_OFFSET 0x00000000 758c2ecf20Sopenharmony_ci#define IVTV_ENCODER_SIZE 0x00800000 /* Total size is 0x01000000, but only first half is used */ 768c2ecf20Sopenharmony_ci#define IVTV_DECODER_OFFSET 0x01000000 778c2ecf20Sopenharmony_ci#define IVTV_DECODER_SIZE 0x00800000 /* Total size is 0x01000000, but only first half is used */ 788c2ecf20Sopenharmony_ci#define IVTV_REG_OFFSET 0x02000000 798c2ecf20Sopenharmony_ci#define IVTV_REG_SIZE 0x00010000 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci/* Maximum ivtv driver instances. Some people have a huge number of 828c2ecf20Sopenharmony_ci capture cards, so set this to a high value. */ 838c2ecf20Sopenharmony_ci#define IVTV_MAX_CARDS 32 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define IVTV_ENC_STREAM_TYPE_MPG 0 868c2ecf20Sopenharmony_ci#define IVTV_ENC_STREAM_TYPE_YUV 1 878c2ecf20Sopenharmony_ci#define IVTV_ENC_STREAM_TYPE_VBI 2 888c2ecf20Sopenharmony_ci#define IVTV_ENC_STREAM_TYPE_PCM 3 898c2ecf20Sopenharmony_ci#define IVTV_ENC_STREAM_TYPE_RAD 4 908c2ecf20Sopenharmony_ci#define IVTV_DEC_STREAM_TYPE_MPG 5 918c2ecf20Sopenharmony_ci#define IVTV_DEC_STREAM_TYPE_VBI 6 928c2ecf20Sopenharmony_ci#define IVTV_DEC_STREAM_TYPE_VOUT 7 938c2ecf20Sopenharmony_ci#define IVTV_DEC_STREAM_TYPE_YUV 8 948c2ecf20Sopenharmony_ci#define IVTV_MAX_STREAMS 9 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci#define IVTV_DMA_SG_OSD_ENT (2883584/PAGE_SIZE) /* sg entities */ 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci/* DMA Registers */ 998c2ecf20Sopenharmony_ci#define IVTV_REG_DMAXFER (0x0000) 1008c2ecf20Sopenharmony_ci#define IVTV_REG_DMASTATUS (0x0004) 1018c2ecf20Sopenharmony_ci#define IVTV_REG_DECDMAADDR (0x0008) 1028c2ecf20Sopenharmony_ci#define IVTV_REG_ENCDMAADDR (0x000c) 1038c2ecf20Sopenharmony_ci#define IVTV_REG_DMACONTROL (0x0010) 1048c2ecf20Sopenharmony_ci#define IVTV_REG_IRQSTATUS (0x0040) 1058c2ecf20Sopenharmony_ci#define IVTV_REG_IRQMASK (0x0048) 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci/* Setup Registers */ 1088c2ecf20Sopenharmony_ci#define IVTV_REG_ENC_SDRAM_REFRESH (0x07F8) 1098c2ecf20Sopenharmony_ci#define IVTV_REG_ENC_SDRAM_PRECHARGE (0x07FC) 1108c2ecf20Sopenharmony_ci#define IVTV_REG_DEC_SDRAM_REFRESH (0x08F8) 1118c2ecf20Sopenharmony_ci#define IVTV_REG_DEC_SDRAM_PRECHARGE (0x08FC) 1128c2ecf20Sopenharmony_ci#define IVTV_REG_VDM (0x2800) 1138c2ecf20Sopenharmony_ci#define IVTV_REG_AO (0x2D00) 1148c2ecf20Sopenharmony_ci#define IVTV_REG_BYTEFLUSH (0x2D24) 1158c2ecf20Sopenharmony_ci#define IVTV_REG_SPU (0x9050) 1168c2ecf20Sopenharmony_ci#define IVTV_REG_HW_BLOCKS (0x9054) 1178c2ecf20Sopenharmony_ci#define IVTV_REG_VPU (0x9058) 1188c2ecf20Sopenharmony_ci#define IVTV_REG_APU (0xA064) 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci/* Other registers */ 1218c2ecf20Sopenharmony_ci#define IVTV_REG_DEC_LINE_FIELD (0x28C0) 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/* debugging */ 1248c2ecf20Sopenharmony_ciextern int ivtv_debug; 1258c2ecf20Sopenharmony_ci#ifdef CONFIG_VIDEO_ADV_DEBUG 1268c2ecf20Sopenharmony_ciextern int ivtv_fw_debug; 1278c2ecf20Sopenharmony_ci#endif 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci#define IVTV_DBGFLG_WARN (1 << 0) 1308c2ecf20Sopenharmony_ci#define IVTV_DBGFLG_INFO (1 << 1) 1318c2ecf20Sopenharmony_ci#define IVTV_DBGFLG_MB (1 << 2) 1328c2ecf20Sopenharmony_ci#define IVTV_DBGFLG_IOCTL (1 << 3) 1338c2ecf20Sopenharmony_ci#define IVTV_DBGFLG_FILE (1 << 4) 1348c2ecf20Sopenharmony_ci#define IVTV_DBGFLG_DMA (1 << 5) 1358c2ecf20Sopenharmony_ci#define IVTV_DBGFLG_IRQ (1 << 6) 1368c2ecf20Sopenharmony_ci#define IVTV_DBGFLG_DEC (1 << 7) 1378c2ecf20Sopenharmony_ci#define IVTV_DBGFLG_YUV (1 << 8) 1388c2ecf20Sopenharmony_ci#define IVTV_DBGFLG_I2C (1 << 9) 1398c2ecf20Sopenharmony_ci/* Flag to turn on high volume debugging */ 1408c2ecf20Sopenharmony_ci#define IVTV_DBGFLG_HIGHVOL (1 << 10) 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci#define IVTV_DEBUG(x, type, fmt, args...) \ 1438c2ecf20Sopenharmony_ci do { \ 1448c2ecf20Sopenharmony_ci if ((x) & ivtv_debug) \ 1458c2ecf20Sopenharmony_ci v4l2_info(&itv->v4l2_dev, " " type ": " fmt , ##args); \ 1468c2ecf20Sopenharmony_ci } while (0) 1478c2ecf20Sopenharmony_ci#define IVTV_DEBUG_WARN(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_WARN, "warn", fmt , ## args) 1488c2ecf20Sopenharmony_ci#define IVTV_DEBUG_INFO(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_INFO, "info", fmt , ## args) 1498c2ecf20Sopenharmony_ci#define IVTV_DEBUG_MB(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_MB, "mb", fmt , ## args) 1508c2ecf20Sopenharmony_ci#define IVTV_DEBUG_DMA(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_DMA, "dma", fmt , ## args) 1518c2ecf20Sopenharmony_ci#define IVTV_DEBUG_IOCTL(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_IOCTL, "ioctl", fmt , ## args) 1528c2ecf20Sopenharmony_ci#define IVTV_DEBUG_FILE(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_FILE, "file", fmt , ## args) 1538c2ecf20Sopenharmony_ci#define IVTV_DEBUG_I2C(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_I2C, "i2c", fmt , ## args) 1548c2ecf20Sopenharmony_ci#define IVTV_DEBUG_IRQ(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_IRQ, "irq", fmt , ## args) 1558c2ecf20Sopenharmony_ci#define IVTV_DEBUG_DEC(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_DEC, "dec", fmt , ## args) 1568c2ecf20Sopenharmony_ci#define IVTV_DEBUG_YUV(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_YUV, "yuv", fmt , ## args) 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci#define IVTV_DEBUG_HIGH_VOL(x, type, fmt, args...) \ 1598c2ecf20Sopenharmony_ci do { \ 1608c2ecf20Sopenharmony_ci if (((x) & ivtv_debug) && (ivtv_debug & IVTV_DBGFLG_HIGHVOL)) \ 1618c2ecf20Sopenharmony_ci v4l2_info(&itv->v4l2_dev, " " type ": " fmt , ##args); \ 1628c2ecf20Sopenharmony_ci } while (0) 1638c2ecf20Sopenharmony_ci#define IVTV_DEBUG_HI_WARN(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_WARN, "warn", fmt , ## args) 1648c2ecf20Sopenharmony_ci#define IVTV_DEBUG_HI_INFO(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_INFO, "info", fmt , ## args) 1658c2ecf20Sopenharmony_ci#define IVTV_DEBUG_HI_MB(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_MB, "mb", fmt , ## args) 1668c2ecf20Sopenharmony_ci#define IVTV_DEBUG_HI_DMA(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_DMA, "dma", fmt , ## args) 1678c2ecf20Sopenharmony_ci#define IVTV_DEBUG_HI_IOCTL(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_IOCTL, "ioctl", fmt , ## args) 1688c2ecf20Sopenharmony_ci#define IVTV_DEBUG_HI_FILE(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_FILE, "file", fmt , ## args) 1698c2ecf20Sopenharmony_ci#define IVTV_DEBUG_HI_I2C(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_I2C, "i2c", fmt , ## args) 1708c2ecf20Sopenharmony_ci#define IVTV_DEBUG_HI_IRQ(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_IRQ, "irq", fmt , ## args) 1718c2ecf20Sopenharmony_ci#define IVTV_DEBUG_HI_DEC(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_DEC, "dec", fmt , ## args) 1728c2ecf20Sopenharmony_ci#define IVTV_DEBUG_HI_YUV(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_YUV, "yuv", fmt , ## args) 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci/* Standard kernel messages */ 1758c2ecf20Sopenharmony_ci#define IVTV_ERR(fmt, args...) v4l2_err(&itv->v4l2_dev, fmt , ## args) 1768c2ecf20Sopenharmony_ci#define IVTV_WARN(fmt, args...) v4l2_warn(&itv->v4l2_dev, fmt , ## args) 1778c2ecf20Sopenharmony_ci#define IVTV_INFO(fmt, args...) v4l2_info(&itv->v4l2_dev, fmt , ## args) 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci/* output modes (cx23415 only) */ 1808c2ecf20Sopenharmony_ci#define OUT_NONE 0 1818c2ecf20Sopenharmony_ci#define OUT_MPG 1 1828c2ecf20Sopenharmony_ci#define OUT_YUV 2 1838c2ecf20Sopenharmony_ci#define OUT_UDMA_YUV 3 1848c2ecf20Sopenharmony_ci#define OUT_PASSTHROUGH 4 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci#define IVTV_MAX_PGM_INDEX (400) 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci/* Default I2C SCL period in microseconds */ 1898c2ecf20Sopenharmony_ci#define IVTV_DEFAULT_I2C_CLOCK_PERIOD 20 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_cistruct ivtv_options { 1928c2ecf20Sopenharmony_ci int kilobytes[IVTV_MAX_STREAMS]; /* size in kilobytes of each stream */ 1938c2ecf20Sopenharmony_ci int cardtype; /* force card type on load */ 1948c2ecf20Sopenharmony_ci int tuner; /* set tuner on load */ 1958c2ecf20Sopenharmony_ci int radio; /* enable/disable radio */ 1968c2ecf20Sopenharmony_ci int newi2c; /* new I2C algorithm */ 1978c2ecf20Sopenharmony_ci int i2c_clock_period; /* period of SCL for I2C bus */ 1988c2ecf20Sopenharmony_ci}; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci/* ivtv-specific mailbox template */ 2018c2ecf20Sopenharmony_cistruct ivtv_mailbox { 2028c2ecf20Sopenharmony_ci u32 flags; 2038c2ecf20Sopenharmony_ci u32 cmd; 2048c2ecf20Sopenharmony_ci u32 retval; 2058c2ecf20Sopenharmony_ci u32 timeout; 2068c2ecf20Sopenharmony_ci u32 data[CX2341X_MBOX_MAX_DATA]; 2078c2ecf20Sopenharmony_ci}; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cistruct ivtv_api_cache { 2108c2ecf20Sopenharmony_ci unsigned long last_jiffies; /* when last command was issued */ 2118c2ecf20Sopenharmony_ci u32 data[CX2341X_MBOX_MAX_DATA]; /* last sent api data */ 2128c2ecf20Sopenharmony_ci}; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_cistruct ivtv_mailbox_data { 2158c2ecf20Sopenharmony_ci volatile struct ivtv_mailbox __iomem *mbox; 2168c2ecf20Sopenharmony_ci /* Bits 0-2 are for the encoder mailboxes, 0-1 are for the decoder mailboxes. 2178c2ecf20Sopenharmony_ci If the bit is set, then the corresponding mailbox is in use by the driver. */ 2188c2ecf20Sopenharmony_ci unsigned long busy; 2198c2ecf20Sopenharmony_ci u8 max_mbox; 2208c2ecf20Sopenharmony_ci}; 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci/* per-buffer bit flags */ 2238c2ecf20Sopenharmony_ci#define IVTV_F_B_NEED_BUF_SWAP (1 << 0) /* this buffer should be byte swapped */ 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci/* per-stream, s_flags */ 2268c2ecf20Sopenharmony_ci#define IVTV_F_S_DMA_PENDING 0 /* this stream has pending DMA */ 2278c2ecf20Sopenharmony_ci#define IVTV_F_S_DMA_HAS_VBI 1 /* the current DMA request also requests VBI data */ 2288c2ecf20Sopenharmony_ci#define IVTV_F_S_NEEDS_DATA 2 /* this decoding stream needs more data */ 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci#define IVTV_F_S_CLAIMED 3 /* this stream is claimed */ 2318c2ecf20Sopenharmony_ci#define IVTV_F_S_STREAMING 4 /* the fw is decoding/encoding this stream */ 2328c2ecf20Sopenharmony_ci#define IVTV_F_S_INTERNAL_USE 5 /* this stream is used internally (sliced VBI processing) */ 2338c2ecf20Sopenharmony_ci#define IVTV_F_S_PASSTHROUGH 6 /* this stream is in passthrough mode */ 2348c2ecf20Sopenharmony_ci#define IVTV_F_S_STREAMOFF 7 /* signal end of stream EOS */ 2358c2ecf20Sopenharmony_ci#define IVTV_F_S_APPL_IO 8 /* this stream is used read/written by an application */ 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci#define IVTV_F_S_PIO_PENDING 9 /* this stream has pending PIO */ 2388c2ecf20Sopenharmony_ci#define IVTV_F_S_PIO_HAS_VBI 1 /* the current PIO request also requests VBI data */ 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci/* per-ivtv, i_flags */ 2418c2ecf20Sopenharmony_ci#define IVTV_F_I_DMA 0 /* DMA in progress */ 2428c2ecf20Sopenharmony_ci#define IVTV_F_I_UDMA 1 /* UDMA in progress */ 2438c2ecf20Sopenharmony_ci#define IVTV_F_I_UDMA_PENDING 2 /* UDMA pending */ 2448c2ecf20Sopenharmony_ci#define IVTV_F_I_SPEED_CHANGE 3 /* a speed change is in progress */ 2458c2ecf20Sopenharmony_ci#define IVTV_F_I_EOS 4 /* end of encoder stream reached */ 2468c2ecf20Sopenharmony_ci#define IVTV_F_I_RADIO_USER 5 /* the radio tuner is selected */ 2478c2ecf20Sopenharmony_ci#define IVTV_F_I_DIG_RST 6 /* reset digitizer */ 2488c2ecf20Sopenharmony_ci#define IVTV_F_I_DEC_YUV 7 /* YUV instead of MPG is being decoded */ 2498c2ecf20Sopenharmony_ci#define IVTV_F_I_UPDATE_CC 9 /* CC should be updated */ 2508c2ecf20Sopenharmony_ci#define IVTV_F_I_UPDATE_WSS 10 /* WSS should be updated */ 2518c2ecf20Sopenharmony_ci#define IVTV_F_I_UPDATE_VPS 11 /* VPS should be updated */ 2528c2ecf20Sopenharmony_ci#define IVTV_F_I_DECODING_YUV 12 /* this stream is YUV frame decoding */ 2538c2ecf20Sopenharmony_ci#define IVTV_F_I_ENC_PAUSED 13 /* the encoder is paused */ 2548c2ecf20Sopenharmony_ci#define IVTV_F_I_VALID_DEC_TIMINGS 14 /* last_dec_timing is valid */ 2558c2ecf20Sopenharmony_ci#define IVTV_F_I_HAVE_WORK 15 /* used in the interrupt handler: there is work to be done */ 2568c2ecf20Sopenharmony_ci#define IVTV_F_I_WORK_HANDLER_VBI 16 /* there is work to be done for VBI */ 2578c2ecf20Sopenharmony_ci#define IVTV_F_I_WORK_HANDLER_YUV 17 /* there is work to be done for YUV */ 2588c2ecf20Sopenharmony_ci#define IVTV_F_I_WORK_HANDLER_PIO 18 /* there is work to be done for PIO */ 2598c2ecf20Sopenharmony_ci#define IVTV_F_I_PIO 19 /* PIO in progress */ 2608c2ecf20Sopenharmony_ci#define IVTV_F_I_DEC_PAUSED 20 /* the decoder is paused */ 2618c2ecf20Sopenharmony_ci#define IVTV_F_I_INITED 21 /* set after first open */ 2628c2ecf20Sopenharmony_ci#define IVTV_F_I_FAILED 22 /* set if first open failed */ 2638c2ecf20Sopenharmony_ci#define IVTV_F_I_WORK_HANDLER_PCM 23 /* there is work to be done for PCM */ 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci/* Event notifications */ 2668c2ecf20Sopenharmony_ci#define IVTV_F_I_EV_DEC_STOPPED 28 /* decoder stopped event */ 2678c2ecf20Sopenharmony_ci#define IVTV_F_I_EV_VSYNC 29 /* VSYNC event */ 2688c2ecf20Sopenharmony_ci#define IVTV_F_I_EV_VSYNC_FIELD 30 /* VSYNC event field (0 = first, 1 = second field) */ 2698c2ecf20Sopenharmony_ci#define IVTV_F_I_EV_VSYNC_ENABLED 31 /* VSYNC event enabled */ 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci/* Scatter-Gather array element, used in DMA transfers */ 2728c2ecf20Sopenharmony_cistruct ivtv_sg_element { 2738c2ecf20Sopenharmony_ci __le32 src; 2748c2ecf20Sopenharmony_ci __le32 dst; 2758c2ecf20Sopenharmony_ci __le32 size; 2768c2ecf20Sopenharmony_ci}; 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_cistruct ivtv_sg_host_element { 2798c2ecf20Sopenharmony_ci u32 src; 2808c2ecf20Sopenharmony_ci u32 dst; 2818c2ecf20Sopenharmony_ci u32 size; 2828c2ecf20Sopenharmony_ci}; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_cistruct ivtv_user_dma { 2858c2ecf20Sopenharmony_ci struct mutex lock; 2868c2ecf20Sopenharmony_ci int page_count; 2878c2ecf20Sopenharmony_ci struct page *map[IVTV_DMA_SG_OSD_ENT]; 2888c2ecf20Sopenharmony_ci /* Needed when dealing with highmem userspace buffers */ 2898c2ecf20Sopenharmony_ci struct page *bouncemap[IVTV_DMA_SG_OSD_ENT]; 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci /* Base Dev SG Array for cx23415/6 */ 2928c2ecf20Sopenharmony_ci struct ivtv_sg_element SGarray[IVTV_DMA_SG_OSD_ENT]; 2938c2ecf20Sopenharmony_ci dma_addr_t SG_handle; 2948c2ecf20Sopenharmony_ci int SG_length; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci /* SG List of Buffers */ 2978c2ecf20Sopenharmony_ci struct scatterlist SGlist[IVTV_DMA_SG_OSD_ENT]; 2988c2ecf20Sopenharmony_ci}; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_cistruct ivtv_dma_page_info { 3018c2ecf20Sopenharmony_ci unsigned long uaddr; 3028c2ecf20Sopenharmony_ci unsigned long first; 3038c2ecf20Sopenharmony_ci unsigned long last; 3048c2ecf20Sopenharmony_ci unsigned int offset; 3058c2ecf20Sopenharmony_ci unsigned int tail; 3068c2ecf20Sopenharmony_ci int page_count; 3078c2ecf20Sopenharmony_ci}; 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_cistruct ivtv_buffer { 3108c2ecf20Sopenharmony_ci struct list_head list; 3118c2ecf20Sopenharmony_ci dma_addr_t dma_handle; 3128c2ecf20Sopenharmony_ci unsigned short b_flags; 3138c2ecf20Sopenharmony_ci unsigned short dma_xfer_cnt; 3148c2ecf20Sopenharmony_ci char *buf; 3158c2ecf20Sopenharmony_ci u32 bytesused; 3168c2ecf20Sopenharmony_ci u32 readpos; 3178c2ecf20Sopenharmony_ci}; 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_cistruct ivtv_queue { 3208c2ecf20Sopenharmony_ci struct list_head list; /* the list of buffers in this queue */ 3218c2ecf20Sopenharmony_ci u32 buffers; /* number of buffers in this queue */ 3228c2ecf20Sopenharmony_ci u32 length; /* total number of bytes of available buffer space */ 3238c2ecf20Sopenharmony_ci u32 bytesused; /* total number of bytes used in this queue */ 3248c2ecf20Sopenharmony_ci}; 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_cistruct ivtv; /* forward reference */ 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_cistruct ivtv_stream { 3298c2ecf20Sopenharmony_ci /* These first four fields are always set, even if the stream 3308c2ecf20Sopenharmony_ci is not actually created. */ 3318c2ecf20Sopenharmony_ci struct video_device vdev; /* vdev.v4l2_dev is NULL if there is no device */ 3328c2ecf20Sopenharmony_ci struct ivtv *itv; /* for ease of use */ 3338c2ecf20Sopenharmony_ci const char *name; /* name of the stream */ 3348c2ecf20Sopenharmony_ci int type; /* stream type */ 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci struct v4l2_fh *fh; /* pointer to the streaming filehandle */ 3378c2ecf20Sopenharmony_ci spinlock_t qlock; /* locks access to the queues */ 3388c2ecf20Sopenharmony_ci unsigned long s_flags; /* status flags, see above */ 3398c2ecf20Sopenharmony_ci int dma; /* can be PCI_DMA_TODEVICE, PCI_DMA_FROMDEVICE or PCI_DMA_NONE */ 3408c2ecf20Sopenharmony_ci u32 pending_offset; 3418c2ecf20Sopenharmony_ci u32 pending_backup; 3428c2ecf20Sopenharmony_ci u64 pending_pts; 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci u32 dma_offset; 3458c2ecf20Sopenharmony_ci u32 dma_backup; 3468c2ecf20Sopenharmony_ci u64 dma_pts; 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci int subtype; 3498c2ecf20Sopenharmony_ci wait_queue_head_t waitq; 3508c2ecf20Sopenharmony_ci u32 dma_last_offset; 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci /* Buffer Stats */ 3538c2ecf20Sopenharmony_ci u32 buffers; 3548c2ecf20Sopenharmony_ci u32 buf_size; 3558c2ecf20Sopenharmony_ci u32 buffers_stolen; 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci /* Buffer Queues */ 3588c2ecf20Sopenharmony_ci struct ivtv_queue q_free; /* free buffers */ 3598c2ecf20Sopenharmony_ci struct ivtv_queue q_full; /* full buffers */ 3608c2ecf20Sopenharmony_ci struct ivtv_queue q_io; /* waiting for I/O */ 3618c2ecf20Sopenharmony_ci struct ivtv_queue q_dma; /* waiting for DMA */ 3628c2ecf20Sopenharmony_ci struct ivtv_queue q_predma; /* waiting for DMA */ 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci /* DMA xfer counter, buffers belonging to the same DMA 3658c2ecf20Sopenharmony_ci xfer will have the same dma_xfer_cnt. */ 3668c2ecf20Sopenharmony_ci u16 dma_xfer_cnt; 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci /* Base Dev SG Array for cx23415/6 */ 3698c2ecf20Sopenharmony_ci struct ivtv_sg_host_element *sg_pending; 3708c2ecf20Sopenharmony_ci struct ivtv_sg_host_element *sg_processing; 3718c2ecf20Sopenharmony_ci struct ivtv_sg_element *sg_dma; 3728c2ecf20Sopenharmony_ci dma_addr_t sg_handle; 3738c2ecf20Sopenharmony_ci int sg_pending_size; 3748c2ecf20Sopenharmony_ci int sg_processing_size; 3758c2ecf20Sopenharmony_ci int sg_processed; 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci /* SG List of Buffers */ 3788c2ecf20Sopenharmony_ci struct scatterlist *SGlist; 3798c2ecf20Sopenharmony_ci}; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_cistruct ivtv_open_id { 3828c2ecf20Sopenharmony_ci struct v4l2_fh fh; 3838c2ecf20Sopenharmony_ci int type; /* stream type */ 3848c2ecf20Sopenharmony_ci int yuv_frames; /* 1: started OUT_UDMA_YUV output mode */ 3858c2ecf20Sopenharmony_ci struct ivtv *itv; 3868c2ecf20Sopenharmony_ci}; 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_cistatic inline struct ivtv_open_id *fh2id(struct v4l2_fh *fh) 3898c2ecf20Sopenharmony_ci{ 3908c2ecf20Sopenharmony_ci return container_of(fh, struct ivtv_open_id, fh); 3918c2ecf20Sopenharmony_ci} 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_cistruct yuv_frame_info 3948c2ecf20Sopenharmony_ci{ 3958c2ecf20Sopenharmony_ci u32 update; 3968c2ecf20Sopenharmony_ci s32 src_x; 3978c2ecf20Sopenharmony_ci s32 src_y; 3988c2ecf20Sopenharmony_ci u32 src_w; 3998c2ecf20Sopenharmony_ci u32 src_h; 4008c2ecf20Sopenharmony_ci s32 dst_x; 4018c2ecf20Sopenharmony_ci s32 dst_y; 4028c2ecf20Sopenharmony_ci u32 dst_w; 4038c2ecf20Sopenharmony_ci u32 dst_h; 4048c2ecf20Sopenharmony_ci s32 pan_x; 4058c2ecf20Sopenharmony_ci s32 pan_y; 4068c2ecf20Sopenharmony_ci u32 vis_w; 4078c2ecf20Sopenharmony_ci u32 vis_h; 4088c2ecf20Sopenharmony_ci u32 interlaced_y; 4098c2ecf20Sopenharmony_ci u32 interlaced_uv; 4108c2ecf20Sopenharmony_ci s32 tru_x; 4118c2ecf20Sopenharmony_ci u32 tru_w; 4128c2ecf20Sopenharmony_ci u32 tru_h; 4138c2ecf20Sopenharmony_ci u32 offset_y; 4148c2ecf20Sopenharmony_ci s32 lace_mode; 4158c2ecf20Sopenharmony_ci u32 sync_field; 4168c2ecf20Sopenharmony_ci u32 delay; 4178c2ecf20Sopenharmony_ci u32 interlaced; 4188c2ecf20Sopenharmony_ci}; 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci#define IVTV_YUV_MODE_INTERLACED 0x00 4218c2ecf20Sopenharmony_ci#define IVTV_YUV_MODE_PROGRESSIVE 0x01 4228c2ecf20Sopenharmony_ci#define IVTV_YUV_MODE_AUTO 0x02 4238c2ecf20Sopenharmony_ci#define IVTV_YUV_MODE_MASK 0x03 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci#define IVTV_YUV_SYNC_EVEN 0x00 4268c2ecf20Sopenharmony_ci#define IVTV_YUV_SYNC_ODD 0x04 4278c2ecf20Sopenharmony_ci#define IVTV_YUV_SYNC_MASK 0x04 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_ci#define IVTV_YUV_BUFFERS 8 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_cistruct yuv_playback_info 4328c2ecf20Sopenharmony_ci{ 4338c2ecf20Sopenharmony_ci u32 reg_2834; 4348c2ecf20Sopenharmony_ci u32 reg_2838; 4358c2ecf20Sopenharmony_ci u32 reg_283c; 4368c2ecf20Sopenharmony_ci u32 reg_2840; 4378c2ecf20Sopenharmony_ci u32 reg_2844; 4388c2ecf20Sopenharmony_ci u32 reg_2848; 4398c2ecf20Sopenharmony_ci u32 reg_2854; 4408c2ecf20Sopenharmony_ci u32 reg_285c; 4418c2ecf20Sopenharmony_ci u32 reg_2864; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci u32 reg_2870; 4448c2ecf20Sopenharmony_ci u32 reg_2874; 4458c2ecf20Sopenharmony_ci u32 reg_2890; 4468c2ecf20Sopenharmony_ci u32 reg_2898; 4478c2ecf20Sopenharmony_ci u32 reg_289c; 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_ci u32 reg_2918; 4508c2ecf20Sopenharmony_ci u32 reg_291c; 4518c2ecf20Sopenharmony_ci u32 reg_2920; 4528c2ecf20Sopenharmony_ci u32 reg_2924; 4538c2ecf20Sopenharmony_ci u32 reg_2928; 4548c2ecf20Sopenharmony_ci u32 reg_292c; 4558c2ecf20Sopenharmony_ci u32 reg_2930; 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci u32 reg_2934; 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci u32 reg_2938; 4608c2ecf20Sopenharmony_ci u32 reg_293c; 4618c2ecf20Sopenharmony_ci u32 reg_2940; 4628c2ecf20Sopenharmony_ci u32 reg_2944; 4638c2ecf20Sopenharmony_ci u32 reg_2948; 4648c2ecf20Sopenharmony_ci u32 reg_294c; 4658c2ecf20Sopenharmony_ci u32 reg_2950; 4668c2ecf20Sopenharmony_ci u32 reg_2954; 4678c2ecf20Sopenharmony_ci u32 reg_2958; 4688c2ecf20Sopenharmony_ci u32 reg_295c; 4698c2ecf20Sopenharmony_ci u32 reg_2960; 4708c2ecf20Sopenharmony_ci u32 reg_2964; 4718c2ecf20Sopenharmony_ci u32 reg_2968; 4728c2ecf20Sopenharmony_ci u32 reg_296c; 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci u32 reg_2970; 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci int v_filter_1; 4778c2ecf20Sopenharmony_ci int v_filter_2; 4788c2ecf20Sopenharmony_ci int h_filter; 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci u8 track_osd; /* Should yuv output track the OSD size & position */ 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci u32 osd_x_offset; 4838c2ecf20Sopenharmony_ci u32 osd_y_offset; 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci u32 osd_x_pan; 4868c2ecf20Sopenharmony_ci u32 osd_y_pan; 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci u32 osd_vis_w; 4898c2ecf20Sopenharmony_ci u32 osd_vis_h; 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci u32 osd_full_w; 4928c2ecf20Sopenharmony_ci u32 osd_full_h; 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci int decode_height; 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci int lace_mode; 4978c2ecf20Sopenharmony_ci int lace_threshold; 4988c2ecf20Sopenharmony_ci int lace_sync_field; 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci atomic_t next_dma_frame; 5018c2ecf20Sopenharmony_ci atomic_t next_fill_frame; 5028c2ecf20Sopenharmony_ci 5038c2ecf20Sopenharmony_ci u32 yuv_forced_update; 5048c2ecf20Sopenharmony_ci int update_frame; 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci u8 fields_lapsed; /* Counter used when delaying a frame */ 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci struct yuv_frame_info new_frame_info[IVTV_YUV_BUFFERS]; 5098c2ecf20Sopenharmony_ci struct yuv_frame_info old_frame_info; 5108c2ecf20Sopenharmony_ci struct yuv_frame_info old_frame_info_args; 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_ci void *blanking_ptr; 5138c2ecf20Sopenharmony_ci dma_addr_t blanking_dmaptr; 5148c2ecf20Sopenharmony_ci 5158c2ecf20Sopenharmony_ci int stream_size; 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci u8 draw_frame; /* PVR350 buffer to draw into */ 5188c2ecf20Sopenharmony_ci u8 max_frames_buffered; /* Maximum number of frames to buffer */ 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci struct v4l2_rect main_rect; 5218c2ecf20Sopenharmony_ci u32 v4l2_src_w; 5228c2ecf20Sopenharmony_ci u32 v4l2_src_h; 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci u8 running; /* Have any frames been displayed */ 5258c2ecf20Sopenharmony_ci}; 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci#define IVTV_VBI_FRAMES 32 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci/* VBI data */ 5308c2ecf20Sopenharmony_cistruct vbi_cc { 5318c2ecf20Sopenharmony_ci u8 odd[2]; /* two-byte payload of odd field */ 5328c2ecf20Sopenharmony_ci u8 even[2]; /* two-byte payload of even field */; 5338c2ecf20Sopenharmony_ci}; 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_cistruct vbi_vps { 5368c2ecf20Sopenharmony_ci u8 data[5]; /* five-byte VPS payload */ 5378c2ecf20Sopenharmony_ci}; 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_cistruct vbi_info { 5408c2ecf20Sopenharmony_ci /* VBI general data, does not change during streaming */ 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci u32 raw_decoder_line_size; /* raw VBI line size from digitizer */ 5438c2ecf20Sopenharmony_ci u8 raw_decoder_sav_odd_field; /* raw VBI Start Active Video digitizer code of odd field */ 5448c2ecf20Sopenharmony_ci u8 raw_decoder_sav_even_field; /* raw VBI Start Active Video digitizer code of even field */ 5458c2ecf20Sopenharmony_ci u32 sliced_decoder_line_size; /* sliced VBI line size from digitizer */ 5468c2ecf20Sopenharmony_ci u8 sliced_decoder_sav_odd_field; /* sliced VBI Start Active Video digitizer code of odd field */ 5478c2ecf20Sopenharmony_ci u8 sliced_decoder_sav_even_field; /* sliced VBI Start Active Video digitizer code of even field */ 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci u32 start[2]; /* start of first VBI line in the odd/even fields */ 5508c2ecf20Sopenharmony_ci u32 count; /* number of VBI lines per field */ 5518c2ecf20Sopenharmony_ci u32 raw_size; /* size of raw VBI line from the digitizer */ 5528c2ecf20Sopenharmony_ci u32 sliced_size; /* size of sliced VBI line from the digitizer */ 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci u32 dec_start; /* start in decoder memory of VBI re-insertion buffers */ 5558c2ecf20Sopenharmony_ci u32 enc_start; /* start in encoder memory of VBI capture buffers */ 5568c2ecf20Sopenharmony_ci u32 enc_size; /* size of VBI capture area */ 5578c2ecf20Sopenharmony_ci int fpi; /* number of VBI frames per interrupt */ 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci struct v4l2_format in; /* current VBI capture format */ 5608c2ecf20Sopenharmony_ci struct v4l2_sliced_vbi_format *sliced_in; /* convenience pointer to sliced struct in vbi.in union */ 5618c2ecf20Sopenharmony_ci int insert_mpeg; /* if non-zero, then embed VBI data in MPEG stream */ 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci /* Raw VBI compatibility hack */ 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci u32 frame; /* frame counter hack needed for backwards compatibility 5668c2ecf20Sopenharmony_ci of old VBI software */ 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_ci /* Sliced VBI output data */ 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci struct vbi_cc cc_payload[256]; /* sliced VBI CC payload array: it is an array to 5718c2ecf20Sopenharmony_ci prevent dropping CC data if they couldn't be 5728c2ecf20Sopenharmony_ci processed fast enough */ 5738c2ecf20Sopenharmony_ci int cc_payload_idx; /* index in cc_payload */ 5748c2ecf20Sopenharmony_ci u8 cc_missing_cnt; /* counts number of frames without CC for passthrough mode */ 5758c2ecf20Sopenharmony_ci int wss_payload; /* sliced VBI WSS payload */ 5768c2ecf20Sopenharmony_ci u8 wss_missing_cnt; /* counts number of frames without WSS for passthrough mode */ 5778c2ecf20Sopenharmony_ci struct vbi_vps vps_payload; /* sliced VBI VPS payload */ 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ci /* Sliced VBI capture data */ 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci struct v4l2_sliced_vbi_data sliced_data[36]; /* sliced VBI storage for VBI encoder stream */ 5828c2ecf20Sopenharmony_ci struct v4l2_sliced_vbi_data sliced_dec_data[36];/* sliced VBI storage for VBI decoder stream */ 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci /* VBI Embedding data */ 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci /* Buffer for VBI data inserted into MPEG stream. 5878c2ecf20Sopenharmony_ci The first byte is a dummy byte that's never used. 5888c2ecf20Sopenharmony_ci The next 16 bytes contain the MPEG header for the VBI data, 5898c2ecf20Sopenharmony_ci the remainder is the actual VBI data. 5908c2ecf20Sopenharmony_ci The max size accepted by the MPEG VBI reinsertion turns out 5918c2ecf20Sopenharmony_ci to be 1552 bytes, which happens to be 4 + (1 + 42) * (2 * 18) bytes, 5928c2ecf20Sopenharmony_ci where 4 is a four byte header, 42 is the max sliced VBI payload, 1 is 5938c2ecf20Sopenharmony_ci a single line header byte and 2 * 18 is the number of VBI lines per frame. 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci However, it seems that the data must be 1K aligned, so we have to 5968c2ecf20Sopenharmony_ci pad the data until the 1 or 2 K boundary. 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ci This pointer array will allocate 2049 bytes to store each VBI frame. */ 5998c2ecf20Sopenharmony_ci u8 *sliced_mpeg_data[IVTV_VBI_FRAMES]; 6008c2ecf20Sopenharmony_ci u32 sliced_mpeg_size[IVTV_VBI_FRAMES]; 6018c2ecf20Sopenharmony_ci struct ivtv_buffer sliced_mpeg_buf; /* temporary buffer holding data from sliced_mpeg_data */ 6028c2ecf20Sopenharmony_ci u32 inserted_frame; /* index in sliced_mpeg_size of next sliced data 6038c2ecf20Sopenharmony_ci to be inserted in the MPEG stream */ 6048c2ecf20Sopenharmony_ci}; 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ci/* forward declaration of struct defined in ivtv-cards.h */ 6078c2ecf20Sopenharmony_cistruct ivtv_card; 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_ci/* Struct to hold info about ivtv cards */ 6108c2ecf20Sopenharmony_cistruct ivtv { 6118c2ecf20Sopenharmony_ci /* General fixed card data */ 6128c2ecf20Sopenharmony_ci struct pci_dev *pdev; /* PCI device */ 6138c2ecf20Sopenharmony_ci const struct ivtv_card *card; /* card information */ 6148c2ecf20Sopenharmony_ci const char *card_name; /* full name of the card */ 6158c2ecf20Sopenharmony_ci const struct ivtv_card_tuner_i2c *card_i2c; /* i2c addresses to probe for tuner */ 6168c2ecf20Sopenharmony_ci u8 has_cx23415; /* 1 if it is a cx23415 based card, 0 for cx23416 */ 6178c2ecf20Sopenharmony_ci u8 pvr150_workaround; /* 1 if the cx25840 needs to workaround a PVR150 bug */ 6188c2ecf20Sopenharmony_ci u8 nof_inputs; /* number of video inputs */ 6198c2ecf20Sopenharmony_ci u8 nof_audio_inputs; /* number of audio inputs */ 6208c2ecf20Sopenharmony_ci u32 v4l2_cap; /* V4L2 capabilities of card */ 6218c2ecf20Sopenharmony_ci u32 hw_flags; /* hardware description of the board */ 6228c2ecf20Sopenharmony_ci v4l2_std_id tuner_std; /* the norm of the card's tuner (fixed) */ 6238c2ecf20Sopenharmony_ci struct v4l2_subdev *sd_video; /* controlling video decoder subdev */ 6248c2ecf20Sopenharmony_ci struct v4l2_subdev *sd_audio; /* controlling audio subdev */ 6258c2ecf20Sopenharmony_ci struct v4l2_subdev *sd_muxer; /* controlling audio muxer subdev */ 6268c2ecf20Sopenharmony_ci resource_size_t base_addr; /* PCI resource base address */ 6278c2ecf20Sopenharmony_ci volatile void __iomem *enc_mem; /* pointer to mapped encoder memory */ 6288c2ecf20Sopenharmony_ci volatile void __iomem *dec_mem; /* pointer to mapped decoder memory */ 6298c2ecf20Sopenharmony_ci volatile void __iomem *reg_mem; /* pointer to mapped registers */ 6308c2ecf20Sopenharmony_ci struct ivtv_options options; /* user options */ 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci struct v4l2_device v4l2_dev; 6338c2ecf20Sopenharmony_ci struct cx2341x_handler cxhdl; 6348c2ecf20Sopenharmony_ci struct { 6358c2ecf20Sopenharmony_ci /* PTS/Frame count control cluster */ 6368c2ecf20Sopenharmony_ci struct v4l2_ctrl *ctrl_pts; 6378c2ecf20Sopenharmony_ci struct v4l2_ctrl *ctrl_frame; 6388c2ecf20Sopenharmony_ci }; 6398c2ecf20Sopenharmony_ci struct { 6408c2ecf20Sopenharmony_ci /* Audio Playback control cluster */ 6418c2ecf20Sopenharmony_ci struct v4l2_ctrl *ctrl_audio_playback; 6428c2ecf20Sopenharmony_ci struct v4l2_ctrl *ctrl_audio_multilingual_playback; 6438c2ecf20Sopenharmony_ci }; 6448c2ecf20Sopenharmony_ci struct v4l2_ctrl_handler hdl_gpio; 6458c2ecf20Sopenharmony_ci struct v4l2_subdev sd_gpio; /* GPIO sub-device */ 6468c2ecf20Sopenharmony_ci u16 instance; 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci /* High-level state info */ 6498c2ecf20Sopenharmony_ci unsigned long i_flags; /* global ivtv flags */ 6508c2ecf20Sopenharmony_ci u8 is_50hz; /* 1 if the current capture standard is 50 Hz */ 6518c2ecf20Sopenharmony_ci u8 is_60hz /* 1 if the current capture standard is 60 Hz */; 6528c2ecf20Sopenharmony_ci u8 is_out_50hz /* 1 if the current TV output standard is 50 Hz */; 6538c2ecf20Sopenharmony_ci u8 is_out_60hz /* 1 if the current TV output standard is 60 Hz */; 6548c2ecf20Sopenharmony_ci int output_mode; /* decoder output mode: NONE, MPG, YUV, UDMA YUV, passthrough */ 6558c2ecf20Sopenharmony_ci u32 audio_input; /* current audio input */ 6568c2ecf20Sopenharmony_ci u32 active_input; /* current video input */ 6578c2ecf20Sopenharmony_ci u32 active_output; /* current video output */ 6588c2ecf20Sopenharmony_ci v4l2_std_id std; /* current capture TV standard */ 6598c2ecf20Sopenharmony_ci v4l2_std_id std_out; /* current TV output standard */ 6608c2ecf20Sopenharmony_ci u8 audio_stereo_mode; /* decoder setting how to handle stereo MPEG audio */ 6618c2ecf20Sopenharmony_ci u8 audio_bilingual_mode; /* decoder setting how to handle bilingual MPEG audio */ 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci /* Locking */ 6648c2ecf20Sopenharmony_ci spinlock_t lock; /* lock access to this struct */ 6658c2ecf20Sopenharmony_ci struct mutex serialize_lock; /* mutex used to serialize open/close/start/stop/ioctl operations */ 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci /* Streams */ 6688c2ecf20Sopenharmony_ci int stream_buf_size[IVTV_MAX_STREAMS]; /* stream buffer size */ 6698c2ecf20Sopenharmony_ci struct ivtv_stream streams[IVTV_MAX_STREAMS]; /* stream data */ 6708c2ecf20Sopenharmony_ci atomic_t capturing; /* count number of active capture streams */ 6718c2ecf20Sopenharmony_ci atomic_t decoding; /* count number of active decoding streams */ 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_ci /* ALSA interface for PCM capture stream */ 6748c2ecf20Sopenharmony_ci struct snd_ivtv_card *alsa; 6758c2ecf20Sopenharmony_ci void (*pcm_announce_callback)(struct snd_ivtv_card *card, u8 *pcm_data, 6768c2ecf20Sopenharmony_ci size_t num_bytes); 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci /* Used for ivtv-alsa module loading */ 6798c2ecf20Sopenharmony_ci struct work_struct request_module_wk; 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_ci /* Interrupts & DMA */ 6828c2ecf20Sopenharmony_ci u32 irqmask; /* active interrupts */ 6838c2ecf20Sopenharmony_ci u32 irq_rr_idx; /* round-robin stream index */ 6848c2ecf20Sopenharmony_ci struct kthread_worker irq_worker; /* kthread worker for PIO/YUV/VBI actions */ 6858c2ecf20Sopenharmony_ci struct task_struct *irq_worker_task; /* task for irq_worker */ 6868c2ecf20Sopenharmony_ci struct kthread_work irq_work; /* kthread work entry */ 6878c2ecf20Sopenharmony_ci spinlock_t dma_reg_lock; /* lock access to DMA engine registers */ 6888c2ecf20Sopenharmony_ci int cur_dma_stream; /* index of current stream doing DMA (-1 if none) */ 6898c2ecf20Sopenharmony_ci int cur_pio_stream; /* index of current stream doing PIO (-1 if none) */ 6908c2ecf20Sopenharmony_ci u32 dma_data_req_offset; /* store offset in decoder memory of current DMA request */ 6918c2ecf20Sopenharmony_ci u32 dma_data_req_size; /* store size of current DMA request */ 6928c2ecf20Sopenharmony_ci int dma_retries; /* current DMA retry attempt */ 6938c2ecf20Sopenharmony_ci struct ivtv_user_dma udma; /* user based DMA for OSD */ 6948c2ecf20Sopenharmony_ci struct timer_list dma_timer; /* timer used to catch unfinished DMAs */ 6958c2ecf20Sopenharmony_ci u32 last_vsync_field; /* last seen vsync field */ 6968c2ecf20Sopenharmony_ci wait_queue_head_t dma_waitq; /* wake up when the current DMA is finished */ 6978c2ecf20Sopenharmony_ci wait_queue_head_t eos_waitq; /* wake up when EOS arrives */ 6988c2ecf20Sopenharmony_ci wait_queue_head_t event_waitq; /* wake up when the next decoder event arrives */ 6998c2ecf20Sopenharmony_ci wait_queue_head_t vsync_waitq; /* wake up when the next decoder vsync arrives */ 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci /* Mailbox */ 7038c2ecf20Sopenharmony_ci struct ivtv_mailbox_data enc_mbox; /* encoder mailboxes */ 7048c2ecf20Sopenharmony_ci struct ivtv_mailbox_data dec_mbox; /* decoder mailboxes */ 7058c2ecf20Sopenharmony_ci struct ivtv_api_cache api_cache[256]; /* cached API commands */ 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci /* I2C */ 7098c2ecf20Sopenharmony_ci struct i2c_adapter i2c_adap; 7108c2ecf20Sopenharmony_ci struct i2c_algo_bit_data i2c_algo; 7118c2ecf20Sopenharmony_ci struct i2c_client i2c_client; 7128c2ecf20Sopenharmony_ci int i2c_state; /* i2c bit state */ 7138c2ecf20Sopenharmony_ci struct mutex i2c_bus_lock; /* lock i2c bus */ 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci struct IR_i2c_init_data ir_i2c_init_data; 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci /* Program Index information */ 7188c2ecf20Sopenharmony_ci u32 pgm_info_offset; /* start of pgm info in encoder memory */ 7198c2ecf20Sopenharmony_ci u32 pgm_info_num; /* number of elements in the pgm cyclic buffer in encoder memory */ 7208c2ecf20Sopenharmony_ci u32 pgm_info_write_idx; /* last index written by the card that was transferred to pgm_info[] */ 7218c2ecf20Sopenharmony_ci u32 pgm_info_read_idx; /* last index in pgm_info read by the application */ 7228c2ecf20Sopenharmony_ci struct v4l2_enc_idx_entry pgm_info[IVTV_MAX_PGM_INDEX]; /* filled from the pgm cyclic buffer on the card */ 7238c2ecf20Sopenharmony_ci 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_ci /* Miscellaneous */ 7268c2ecf20Sopenharmony_ci u32 open_id; /* incremented each time an open occurs, is >= 1 */ 7278c2ecf20Sopenharmony_ci int search_pack_header; /* 1 if ivtv_copy_buf_to_user() is scanning for a pack header (0xba) */ 7288c2ecf20Sopenharmony_ci int speed; /* current playback speed setting */ 7298c2ecf20Sopenharmony_ci u8 speed_mute_audio; /* 1 if audio should be muted when fast forward */ 7308c2ecf20Sopenharmony_ci u64 mpg_data_received; /* number of bytes received from the MPEG stream */ 7318c2ecf20Sopenharmony_ci u64 vbi_data_inserted; /* number of VBI bytes inserted into the MPEG stream */ 7328c2ecf20Sopenharmony_ci u32 last_dec_timing[3]; /* cache last retrieved pts/scr/frame values */ 7338c2ecf20Sopenharmony_ci unsigned long dualwatch_jiffies;/* jiffies value of the previous dualwatch check */ 7348c2ecf20Sopenharmony_ci u32 dualwatch_stereo_mode; /* current detected dualwatch stereo mode */ 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_ci 7378c2ecf20Sopenharmony_ci /* VBI state info */ 7388c2ecf20Sopenharmony_ci struct vbi_info vbi; /* VBI-specific data */ 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci /* YUV playback */ 7428c2ecf20Sopenharmony_ci struct yuv_playback_info yuv_info; /* YUV playback data */ 7438c2ecf20Sopenharmony_ci 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_ci /* OSD support */ 7468c2ecf20Sopenharmony_ci unsigned long osd_video_pbase; 7478c2ecf20Sopenharmony_ci int osd_global_alpha_state; /* 1 = global alpha is on */ 7488c2ecf20Sopenharmony_ci int osd_local_alpha_state; /* 1 = local alpha is on */ 7498c2ecf20Sopenharmony_ci int osd_chroma_key_state; /* 1 = chroma-keying is on */ 7508c2ecf20Sopenharmony_ci u8 osd_global_alpha; /* current global alpha */ 7518c2ecf20Sopenharmony_ci u32 osd_chroma_key; /* current chroma key */ 7528c2ecf20Sopenharmony_ci struct v4l2_rect osd_rect; /* current OSD position and size */ 7538c2ecf20Sopenharmony_ci struct v4l2_rect main_rect; /* current Main window position and size */ 7548c2ecf20Sopenharmony_ci struct osd_info *osd_info; /* ivtvfb private OSD info */ 7558c2ecf20Sopenharmony_ci void (*ivtvfb_restore)(struct ivtv *itv); /* Used for a warm start */ 7568c2ecf20Sopenharmony_ci}; 7578c2ecf20Sopenharmony_ci 7588c2ecf20Sopenharmony_cistatic inline struct ivtv *to_ivtv(struct v4l2_device *v4l2_dev) 7598c2ecf20Sopenharmony_ci{ 7608c2ecf20Sopenharmony_ci return container_of(v4l2_dev, struct ivtv, v4l2_dev); 7618c2ecf20Sopenharmony_ci} 7628c2ecf20Sopenharmony_ci 7638c2ecf20Sopenharmony_ci/* ivtv extensions to be loaded */ 7648c2ecf20Sopenharmony_ciextern int (*ivtv_ext_init)(struct ivtv *); 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci/* Globals */ 7678c2ecf20Sopenharmony_ciextern int ivtv_first_minor; 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci/*==============Prototypes==================*/ 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci/* Hardware/IRQ */ 7728c2ecf20Sopenharmony_civoid ivtv_set_irq_mask(struct ivtv *itv, u32 mask); 7738c2ecf20Sopenharmony_civoid ivtv_clear_irq_mask(struct ivtv *itv, u32 mask); 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_ci/* try to set output mode, return current mode. */ 7768c2ecf20Sopenharmony_ciint ivtv_set_output_mode(struct ivtv *itv, int mode); 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci/* return current output stream based on current mode */ 7798c2ecf20Sopenharmony_cistruct ivtv_stream *ivtv_get_output_stream(struct ivtv *itv); 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_ci/* Return non-zero if a signal is pending */ 7828c2ecf20Sopenharmony_ciint ivtv_msleep_timeout(unsigned int msecs, int intr); 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_ci/* Wait on queue, returns -EINTR if interrupted */ 7858c2ecf20Sopenharmony_ciint ivtv_waitq(wait_queue_head_t *waitq); 7868c2ecf20Sopenharmony_ci 7878c2ecf20Sopenharmony_ci/* Read Hauppauge eeprom */ 7888c2ecf20Sopenharmony_cistruct tveeprom; /* forward reference */ 7898c2ecf20Sopenharmony_civoid ivtv_read_eeprom(struct ivtv *itv, struct tveeprom *tv); 7908c2ecf20Sopenharmony_ci 7918c2ecf20Sopenharmony_ci/* First-open initialization: load firmware, init cx25840, etc. */ 7928c2ecf20Sopenharmony_ciint ivtv_init_on_first_open(struct ivtv *itv); 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci/* Test if the current VBI mode is raw (1) or sliced (0) */ 7958c2ecf20Sopenharmony_cistatic inline int ivtv_raw_vbi(const struct ivtv *itv) 7968c2ecf20Sopenharmony_ci{ 7978c2ecf20Sopenharmony_ci return itv->vbi.in.type == V4L2_BUF_TYPE_VBI_CAPTURE; 7988c2ecf20Sopenharmony_ci} 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci/* This is a PCI post thing, where if the pci register is not read, then 8018c2ecf20Sopenharmony_ci the write doesn't always take effect right away. By reading back the 8028c2ecf20Sopenharmony_ci register any pending PCI writes will be performed (in order), and so 8038c2ecf20Sopenharmony_ci you can be sure that the writes are guaranteed to be done. 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci Rarely needed, only in some timing sensitive cases. 8068c2ecf20Sopenharmony_ci Apparently if this is not done some motherboards seem 8078c2ecf20Sopenharmony_ci to kill the firmware and get into the broken state until computer is 8088c2ecf20Sopenharmony_ci rebooted. */ 8098c2ecf20Sopenharmony_ci#define write_sync(val, reg) \ 8108c2ecf20Sopenharmony_ci do { writel(val, reg); readl(reg); } while (0) 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_ci#define read_reg(reg) readl(itv->reg_mem + (reg)) 8138c2ecf20Sopenharmony_ci#define write_reg(val, reg) writel(val, itv->reg_mem + (reg)) 8148c2ecf20Sopenharmony_ci#define write_reg_sync(val, reg) \ 8158c2ecf20Sopenharmony_ci do { write_reg(val, reg); read_reg(reg); } while (0) 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_ci#define read_enc(addr) readl(itv->enc_mem + (u32)(addr)) 8188c2ecf20Sopenharmony_ci#define write_enc(val, addr) writel(val, itv->enc_mem + (u32)(addr)) 8198c2ecf20Sopenharmony_ci#define write_enc_sync(val, addr) \ 8208c2ecf20Sopenharmony_ci do { write_enc(val, addr); read_enc(addr); } while (0) 8218c2ecf20Sopenharmony_ci 8228c2ecf20Sopenharmony_ci#define read_dec(addr) readl(itv->dec_mem + (u32)(addr)) 8238c2ecf20Sopenharmony_ci#define write_dec(val, addr) writel(val, itv->dec_mem + (u32)(addr)) 8248c2ecf20Sopenharmony_ci#define write_dec_sync(val, addr) \ 8258c2ecf20Sopenharmony_ci do { write_dec(val, addr); read_dec(addr); } while (0) 8268c2ecf20Sopenharmony_ci 8278c2ecf20Sopenharmony_ci/* Call the specified callback for all subdevs matching hw (if 0, then 8288c2ecf20Sopenharmony_ci match them all). Ignore any errors. */ 8298c2ecf20Sopenharmony_ci#define ivtv_call_hw(itv, hw, o, f, args...) \ 8308c2ecf20Sopenharmony_ci v4l2_device_mask_call_all(&(itv)->v4l2_dev, hw, o, f, ##args) 8318c2ecf20Sopenharmony_ci 8328c2ecf20Sopenharmony_ci#define ivtv_call_all(itv, o, f, args...) ivtv_call_hw(itv, 0, o, f , ##args) 8338c2ecf20Sopenharmony_ci 8348c2ecf20Sopenharmony_ci/* Call the specified callback for all subdevs matching hw (if 0, then 8358c2ecf20Sopenharmony_ci match them all). If the callback returns an error other than 0 or 8368c2ecf20Sopenharmony_ci -ENOIOCTLCMD, then return with that error code. */ 8378c2ecf20Sopenharmony_ci#define ivtv_call_hw_err(itv, hw, o, f, args...) \ 8388c2ecf20Sopenharmony_ci v4l2_device_mask_call_until_err(&(itv)->v4l2_dev, hw, o, f, ##args) 8398c2ecf20Sopenharmony_ci 8408c2ecf20Sopenharmony_ci#define ivtv_call_all_err(itv, o, f, args...) ivtv_call_hw_err(itv, 0, o, f , ##args) 8418c2ecf20Sopenharmony_ci 8428c2ecf20Sopenharmony_ci#endif 843