162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci bttv - Bt848 frame grabber driver 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci bttv's *private* header file -- nobody other than bttv itself 762306a36Sopenharmony_ci should ever include this file. 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci (c) 2000-2002 Gerd Knorr <kraxel@bytesex.org> 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci*/ 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#ifndef _BTTVP_H_ 1462306a36Sopenharmony_ci#define _BTTVP_H_ 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#include <linux/types.h> 1762306a36Sopenharmony_ci#include <linux/wait.h> 1862306a36Sopenharmony_ci#include <linux/i2c.h> 1962306a36Sopenharmony_ci#include <linux/i2c-algo-bit.h> 2062306a36Sopenharmony_ci#include <linux/pci.h> 2162306a36Sopenharmony_ci#include <linux/input.h> 2262306a36Sopenharmony_ci#include <linux/mutex.h> 2362306a36Sopenharmony_ci#include <linux/scatterlist.h> 2462306a36Sopenharmony_ci#include <linux/device.h> 2562306a36Sopenharmony_ci#include <asm/io.h> 2662306a36Sopenharmony_ci#include <media/v4l2-common.h> 2762306a36Sopenharmony_ci#include <media/v4l2-ctrls.h> 2862306a36Sopenharmony_ci#include <media/v4l2-fh.h> 2962306a36Sopenharmony_ci#include <media/videobuf2-dma-sg.h> 3062306a36Sopenharmony_ci#include <media/tveeprom.h> 3162306a36Sopenharmony_ci#include <media/rc-core.h> 3262306a36Sopenharmony_ci#include <media/i2c/ir-kbd-i2c.h> 3362306a36Sopenharmony_ci#include <media/drv-intf/tea575x.h> 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#include "bt848.h" 3662306a36Sopenharmony_ci#include "bttv.h" 3762306a36Sopenharmony_ci#include "btcx-risc.h" 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci#ifdef __KERNEL__ 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#define FORMAT_FLAGS_DITHER 0x01 4262306a36Sopenharmony_ci#define FORMAT_FLAGS_PACKED 0x02 4362306a36Sopenharmony_ci#define FORMAT_FLAGS_PLANAR 0x04 4462306a36Sopenharmony_ci#define FORMAT_FLAGS_RAW 0x08 4562306a36Sopenharmony_ci#define FORMAT_FLAGS_CrCb 0x10 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci#define RISC_SLOT_O_VBI 4 4862306a36Sopenharmony_ci#define RISC_SLOT_O_FIELD 6 4962306a36Sopenharmony_ci#define RISC_SLOT_E_VBI 10 5062306a36Sopenharmony_ci#define RISC_SLOT_E_FIELD 12 5162306a36Sopenharmony_ci#define RISC_SLOT_LOOP 14 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#define RESOURCE_VIDEO_STREAM 2 5462306a36Sopenharmony_ci#define RESOURCE_VBI 4 5562306a36Sopenharmony_ci#define RESOURCE_VIDEO_READ 8 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci#define RAW_LINES 640 5862306a36Sopenharmony_ci#define RAW_BPL 1024 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci#define UNSET (-1U) 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci/* Min. value in VDELAY register. */ 6362306a36Sopenharmony_ci#define MIN_VDELAY 2 6462306a36Sopenharmony_ci/* Even to get Cb first, odd for Cr. */ 6562306a36Sopenharmony_ci#define MAX_HDELAY (0x3FF & -2) 6662306a36Sopenharmony_ci/* Limits scaled width, which must be a multiple of 4. */ 6762306a36Sopenharmony_ci#define MAX_HACTIVE (0x3FF & -4) 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci#define BTTV_NORMS (\ 7062306a36Sopenharmony_ci V4L2_STD_PAL | V4L2_STD_PAL_N | \ 7162306a36Sopenharmony_ci V4L2_STD_PAL_Nc | V4L2_STD_SECAM | \ 7262306a36Sopenharmony_ci V4L2_STD_NTSC | V4L2_STD_PAL_M | \ 7362306a36Sopenharmony_ci V4L2_STD_PAL_60) 7462306a36Sopenharmony_ci/* ---------------------------------------------------------- */ 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_cistruct bttv_tvnorm { 7762306a36Sopenharmony_ci int v4l2_id; 7862306a36Sopenharmony_ci char *name; 7962306a36Sopenharmony_ci u32 Fsc; 8062306a36Sopenharmony_ci u16 swidth, sheight; /* scaled standard width, height */ 8162306a36Sopenharmony_ci u16 totalwidth; 8262306a36Sopenharmony_ci u8 adelay, bdelay, iform; 8362306a36Sopenharmony_ci u32 scaledtwidth; 8462306a36Sopenharmony_ci u16 hdelayx1, hactivex1; 8562306a36Sopenharmony_ci u16 vdelay; 8662306a36Sopenharmony_ci u8 vbipack; 8762306a36Sopenharmony_ci u16 vtotal; 8862306a36Sopenharmony_ci int sram; 8962306a36Sopenharmony_ci /* ITU-R frame line number of the first VBI line we can 9062306a36Sopenharmony_ci capture, of the first and second field. The last possible line 9162306a36Sopenharmony_ci is determined by cropcap.bounds. */ 9262306a36Sopenharmony_ci u16 vbistart[2]; 9362306a36Sopenharmony_ci /* Horizontally this counts fCLKx1 samples following the leading 9462306a36Sopenharmony_ci edge of the horizontal sync pulse, vertically ITU-R frame line 9562306a36Sopenharmony_ci numbers of the first field times two (2, 4, 6, ... 524 or 624). */ 9662306a36Sopenharmony_ci struct v4l2_cropcap cropcap; 9762306a36Sopenharmony_ci}; 9862306a36Sopenharmony_ciextern const struct bttv_tvnorm bttv_tvnorms[]; 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_cistruct bttv_format { 10162306a36Sopenharmony_ci int fourcc; /* video4linux 2 */ 10262306a36Sopenharmony_ci int btformat; /* BT848_COLOR_FMT_* */ 10362306a36Sopenharmony_ci int btswap; /* BT848_COLOR_CTL_* */ 10462306a36Sopenharmony_ci int depth; /* bit/pixel */ 10562306a36Sopenharmony_ci int flags; 10662306a36Sopenharmony_ci int hshift,vshift; /* for planar modes */ 10762306a36Sopenharmony_ci}; 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_cistruct bttv_ir { 11062306a36Sopenharmony_ci struct rc_dev *dev; 11162306a36Sopenharmony_ci struct bttv *btv; 11262306a36Sopenharmony_ci struct timer_list timer; 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci char name[32]; 11562306a36Sopenharmony_ci char phys[32]; 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci /* Usual gpio signalling */ 11862306a36Sopenharmony_ci u32 mask_keycode; 11962306a36Sopenharmony_ci u32 mask_keydown; 12062306a36Sopenharmony_ci u32 mask_keyup; 12162306a36Sopenharmony_ci u32 polling; 12262306a36Sopenharmony_ci u32 last_gpio; 12362306a36Sopenharmony_ci int shift_by; 12462306a36Sopenharmony_ci int rc5_remote_gap; 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci /* RC5 gpio */ 12762306a36Sopenharmony_ci bool rc5_gpio; /* Is RC5 legacy GPIO enabled? */ 12862306a36Sopenharmony_ci u32 last_bit; /* last raw bit seen */ 12962306a36Sopenharmony_ci u32 code; /* raw code under construction */ 13062306a36Sopenharmony_ci ktime_t base_time; /* time of last seen code */ 13162306a36Sopenharmony_ci bool active; /* building raw code */ 13262306a36Sopenharmony_ci}; 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci/* ---------------------------------------------------------- */ 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_cistruct bttv_geometry { 13862306a36Sopenharmony_ci u8 vtc,crop,comb; 13962306a36Sopenharmony_ci u16 width,hscale,hdelay; 14062306a36Sopenharmony_ci u16 sheight,vscale,vdelay,vtotal; 14162306a36Sopenharmony_ci}; 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_cistruct bttv_buffer { 14462306a36Sopenharmony_ci /* common v4l buffer stuff -- must be first */ 14562306a36Sopenharmony_ci struct vb2_v4l2_buffer vbuf; 14662306a36Sopenharmony_ci struct list_head list; 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci /* bttv specific */ 14962306a36Sopenharmony_ci int btformat; 15062306a36Sopenharmony_ci int btswap; 15162306a36Sopenharmony_ci struct bttv_geometry geo; 15262306a36Sopenharmony_ci struct btcx_riscmem top; 15362306a36Sopenharmony_ci struct btcx_riscmem bottom; 15462306a36Sopenharmony_ci}; 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_cistruct bttv_buffer_set { 15762306a36Sopenharmony_ci struct bttv_buffer *top; /* top field buffer */ 15862306a36Sopenharmony_ci struct bttv_buffer *bottom; /* bottom field buffer */ 15962306a36Sopenharmony_ci unsigned int top_irq; 16062306a36Sopenharmony_ci unsigned int frame_irq; 16162306a36Sopenharmony_ci}; 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_cistruct bttv_vbi_fmt { 16462306a36Sopenharmony_ci struct v4l2_vbi_format fmt; 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci /* fmt.start[] and count[] refer to this video standard. */ 16762306a36Sopenharmony_ci const struct bttv_tvnorm *tvnorm; 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci /* Earliest possible start of video capturing with this 17062306a36Sopenharmony_ci v4l2_vbi_format, in struct bttv_crop.rect units. */ 17162306a36Sopenharmony_ci __s32 end; 17262306a36Sopenharmony_ci}; 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci/* bttv-vbi.c */ 17562306a36Sopenharmony_ciextern const struct vb2_ops bttv_vbi_qops; 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_civoid bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm); 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_cistruct bttv_crop { 18062306a36Sopenharmony_ci /* A cropping rectangle in struct bttv_tvnorm.cropcap units. */ 18162306a36Sopenharmony_ci struct v4l2_rect rect; 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ci /* Scaled image size limits with this crop rect. Divide 18462306a36Sopenharmony_ci max_height, but not min_height, by two when capturing 18562306a36Sopenharmony_ci single fields. See also bttv_crop_reset() and 18662306a36Sopenharmony_ci bttv_crop_adjust() in bttv-driver.c. */ 18762306a36Sopenharmony_ci __s32 min_scaled_width; 18862306a36Sopenharmony_ci __s32 min_scaled_height; 18962306a36Sopenharmony_ci __s32 max_scaled_width; 19062306a36Sopenharmony_ci __s32 max_scaled_height; 19162306a36Sopenharmony_ci}; 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci/* ---------------------------------------------------------- */ 19462306a36Sopenharmony_ci/* bttv-risc.c */ 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci/* risc code generators - capture */ 19762306a36Sopenharmony_ciint bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc, 19862306a36Sopenharmony_ci struct scatterlist *sglist, 19962306a36Sopenharmony_ci unsigned int offset, unsigned int bpl, 20062306a36Sopenharmony_ci unsigned int pitch, unsigned int skip_lines, 20162306a36Sopenharmony_ci unsigned int store_lines); 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci/* control dma register + risc main loop */ 20462306a36Sopenharmony_civoid bttv_set_dma(struct bttv *btv, int override); 20562306a36Sopenharmony_ciint bttv_risc_init_main(struct bttv *btv); 20662306a36Sopenharmony_ciint bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc, 20762306a36Sopenharmony_ci int irqflags); 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci/* capture buffer handling */ 21062306a36Sopenharmony_ciint bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf); 21162306a36Sopenharmony_ciint bttv_buffer_activate_video(struct bttv *btv, 21262306a36Sopenharmony_ci struct bttv_buffer_set *set); 21362306a36Sopenharmony_ciint bttv_buffer_risc_vbi(struct bttv *btv, struct bttv_buffer *buf); 21462306a36Sopenharmony_ciint bttv_buffer_activate_vbi(struct bttv *btv, 21562306a36Sopenharmony_ci struct bttv_buffer *vbi); 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci/* ---------------------------------------------------------- */ 21862306a36Sopenharmony_ci/* bttv-vbi.c */ 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ci/* 22162306a36Sopenharmony_ci * 2048 for compatibility with earlier driver versions. The driver really 22262306a36Sopenharmony_ci * stores 1024 + tvnorm->vbipack * 4 samples per line in the buffer. Note 22362306a36Sopenharmony_ci * tvnorm->vbipack is <= 0xFF (limit of VBIPACK_LO + HI is 0x1FF DWORDs) and 22462306a36Sopenharmony_ci * VBI read()s store a frame counter in the last four bytes of the VBI image. 22562306a36Sopenharmony_ci */ 22662306a36Sopenharmony_ci#define VBI_BPL 2048 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_ci#define VBI_DEFLINES 16 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ciint bttv_try_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f); 23162306a36Sopenharmony_ciint bttv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f); 23262306a36Sopenharmony_ciint bttv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f); 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_ci/* ---------------------------------------------------------- */ 23562306a36Sopenharmony_ci/* bttv-gpio.c */ 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_ciextern struct bus_type bttv_sub_bus_type; 23862306a36Sopenharmony_ciint bttv_sub_add_device(struct bttv_core *core, char *name); 23962306a36Sopenharmony_ciint bttv_sub_del_devices(struct bttv_core *core); 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ci/* ---------------------------------------------------------- */ 24262306a36Sopenharmony_ci/* bttv-input.c */ 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ciextern void init_bttv_i2c_ir(struct bttv *btv); 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ci/* ---------------------------------------------------------- */ 24762306a36Sopenharmony_ci/* bttv-i2c.c */ 24862306a36Sopenharmony_ciextern int init_bttv_i2c(struct bttv *btv); 24962306a36Sopenharmony_ciextern int fini_bttv_i2c(struct bttv *btv); 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_ci/* ---------------------------------------------------------- */ 25262306a36Sopenharmony_ci/* bttv-driver.c */ 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci/* insmod options */ 25562306a36Sopenharmony_ciextern unsigned int bttv_verbose; 25662306a36Sopenharmony_ciextern unsigned int bttv_debug; 25762306a36Sopenharmony_ciextern unsigned int bttv_gpio; 25862306a36Sopenharmony_ciint check_alloc_btres_lock(struct bttv *btv, int bit); 25962306a36Sopenharmony_civoid free_btres_lock(struct bttv *btv, int bits); 26062306a36Sopenharmony_ciextern void bttv_gpio_tracking(struct bttv *btv, char *comment); 26162306a36Sopenharmony_ci 26262306a36Sopenharmony_ci#define dprintk(fmt, ...) \ 26362306a36Sopenharmony_cido { \ 26462306a36Sopenharmony_ci if (bttv_debug >= 1) \ 26562306a36Sopenharmony_ci pr_debug(fmt, ##__VA_ARGS__); \ 26662306a36Sopenharmony_ci} while (0) 26762306a36Sopenharmony_ci#define dprintk_cont(fmt, ...) \ 26862306a36Sopenharmony_cido { \ 26962306a36Sopenharmony_ci if (bttv_debug >= 1) \ 27062306a36Sopenharmony_ci pr_cont(fmt, ##__VA_ARGS__); \ 27162306a36Sopenharmony_ci} while (0) 27262306a36Sopenharmony_ci#define d2printk(fmt, ...) \ 27362306a36Sopenharmony_cido { \ 27462306a36Sopenharmony_ci if (bttv_debug >= 2) \ 27562306a36Sopenharmony_ci printk(fmt, ##__VA_ARGS__); \ 27662306a36Sopenharmony_ci} while (0) 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci#define BTTV_MAX_FBUF 0x208000 27962306a36Sopenharmony_ci#define BTTV_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */ 28062306a36Sopenharmony_ci#define BTTV_FREE_IDLE msecs_to_jiffies(1000) /* one second */ 28162306a36Sopenharmony_ci 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_cistruct bttv_pll_info { 28462306a36Sopenharmony_ci unsigned int pll_ifreq; /* PLL input frequency */ 28562306a36Sopenharmony_ci unsigned int pll_ofreq; /* PLL output frequency */ 28662306a36Sopenharmony_ci unsigned int pll_crystal; /* Crystal used for input */ 28762306a36Sopenharmony_ci unsigned int pll_current; /* Currently programmed ofreq */ 28862306a36Sopenharmony_ci}; 28962306a36Sopenharmony_ci 29062306a36Sopenharmony_ci/* for gpio-connected remote control */ 29162306a36Sopenharmony_cistruct bttv_input { 29262306a36Sopenharmony_ci struct input_dev *dev; 29362306a36Sopenharmony_ci char name[32]; 29462306a36Sopenharmony_ci char phys[32]; 29562306a36Sopenharmony_ci u32 mask_keycode; 29662306a36Sopenharmony_ci u32 mask_keydown; 29762306a36Sopenharmony_ci}; 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_cistruct bttv_suspend_state { 30062306a36Sopenharmony_ci u32 gpio_enable; 30162306a36Sopenharmony_ci u32 gpio_data; 30262306a36Sopenharmony_ci int disabled; 30362306a36Sopenharmony_ci int loop_irq; 30462306a36Sopenharmony_ci struct bttv_buffer_set video; 30562306a36Sopenharmony_ci struct bttv_buffer *vbi; 30662306a36Sopenharmony_ci}; 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_cistruct bttv_tea575x_gpio { 30962306a36Sopenharmony_ci u8 data, clk, wren, most; 31062306a36Sopenharmony_ci}; 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_cistruct bttv { 31362306a36Sopenharmony_ci struct bttv_core c; 31462306a36Sopenharmony_ci 31562306a36Sopenharmony_ci /* pci device config */ 31662306a36Sopenharmony_ci unsigned short id; 31762306a36Sopenharmony_ci unsigned char revision; 31862306a36Sopenharmony_ci unsigned char __iomem *bt848_mmio; /* pointer to mmio */ 31962306a36Sopenharmony_ci 32062306a36Sopenharmony_ci /* card configuration info */ 32162306a36Sopenharmony_ci unsigned int cardid; /* pci subsystem id (bt878 based ones) */ 32262306a36Sopenharmony_ci unsigned int tuner_type; /* tuner chip type */ 32362306a36Sopenharmony_ci unsigned int tda9887_conf; 32462306a36Sopenharmony_ci unsigned int svhs, dig; 32562306a36Sopenharmony_ci unsigned int has_saa6588:1; 32662306a36Sopenharmony_ci struct bttv_pll_info pll; 32762306a36Sopenharmony_ci int triton1; 32862306a36Sopenharmony_ci int gpioirq; 32962306a36Sopenharmony_ci 33062306a36Sopenharmony_ci int use_i2c_hw; 33162306a36Sopenharmony_ci 33262306a36Sopenharmony_ci /* old gpio interface */ 33362306a36Sopenharmony_ci int shutdown; 33462306a36Sopenharmony_ci 33562306a36Sopenharmony_ci void (*volume_gpio)(struct bttv *btv, __u16 volume); 33662306a36Sopenharmony_ci void (*audio_mode_gpio)(struct bttv *btv, struct v4l2_tuner *tuner, int set); 33762306a36Sopenharmony_ci 33862306a36Sopenharmony_ci /* new gpio interface */ 33962306a36Sopenharmony_ci spinlock_t gpio_lock; 34062306a36Sopenharmony_ci 34162306a36Sopenharmony_ci /* i2c layer */ 34262306a36Sopenharmony_ci struct i2c_algo_bit_data i2c_algo; 34362306a36Sopenharmony_ci struct i2c_client i2c_client; 34462306a36Sopenharmony_ci int i2c_state, i2c_rc; 34562306a36Sopenharmony_ci int i2c_done; 34662306a36Sopenharmony_ci wait_queue_head_t i2c_queue; 34762306a36Sopenharmony_ci struct v4l2_subdev *sd_msp34xx; 34862306a36Sopenharmony_ci struct v4l2_subdev *sd_tvaudio; 34962306a36Sopenharmony_ci struct v4l2_subdev *sd_tda7432; 35062306a36Sopenharmony_ci 35162306a36Sopenharmony_ci /* video4linux (1) */ 35262306a36Sopenharmony_ci struct video_device video_dev; 35362306a36Sopenharmony_ci struct video_device radio_dev; 35462306a36Sopenharmony_ci struct video_device vbi_dev; 35562306a36Sopenharmony_ci 35662306a36Sopenharmony_ci /* controls */ 35762306a36Sopenharmony_ci struct v4l2_ctrl_handler ctrl_handler; 35862306a36Sopenharmony_ci struct v4l2_ctrl_handler radio_ctrl_handler; 35962306a36Sopenharmony_ci 36062306a36Sopenharmony_ci /* infrared remote */ 36162306a36Sopenharmony_ci int has_remote; 36262306a36Sopenharmony_ci struct bttv_ir *remote; 36362306a36Sopenharmony_ci 36462306a36Sopenharmony_ci /* I2C remote data */ 36562306a36Sopenharmony_ci struct IR_i2c_init_data init_data; 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_ci /* locking */ 36862306a36Sopenharmony_ci spinlock_t s_lock; 36962306a36Sopenharmony_ci struct mutex lock; 37062306a36Sopenharmony_ci int resources; 37162306a36Sopenharmony_ci 37262306a36Sopenharmony_ci /* video state */ 37362306a36Sopenharmony_ci unsigned int input; 37462306a36Sopenharmony_ci unsigned int audio_input; 37562306a36Sopenharmony_ci unsigned int mute; 37662306a36Sopenharmony_ci unsigned long tv_freq; 37762306a36Sopenharmony_ci unsigned int tvnorm; 37862306a36Sopenharmony_ci v4l2_std_id std; 37962306a36Sopenharmony_ci int hue, contrast, bright, saturation; 38062306a36Sopenharmony_ci struct v4l2_framebuffer fbuf; 38162306a36Sopenharmony_ci __u32 field_count; 38262306a36Sopenharmony_ci 38362306a36Sopenharmony_ci /* various options */ 38462306a36Sopenharmony_ci int opt_combfilter; 38562306a36Sopenharmony_ci int opt_automute; 38662306a36Sopenharmony_ci int opt_vcr_hack; 38762306a36Sopenharmony_ci int opt_uv_ratio; 38862306a36Sopenharmony_ci 38962306a36Sopenharmony_ci /* radio data/state */ 39062306a36Sopenharmony_ci int has_radio; 39162306a36Sopenharmony_ci int has_radio_tuner; 39262306a36Sopenharmony_ci int radio_user; 39362306a36Sopenharmony_ci int radio_uses_msp_demodulator; 39462306a36Sopenharmony_ci unsigned long radio_freq; 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_ci /* miro/pinnacle + Aimslab VHX 39762306a36Sopenharmony_ci philips matchbox (tea5757 radio tuner) support */ 39862306a36Sopenharmony_ci int has_tea575x; 39962306a36Sopenharmony_ci struct bttv_tea575x_gpio tea_gpio; 40062306a36Sopenharmony_ci struct snd_tea575x tea; 40162306a36Sopenharmony_ci 40262306a36Sopenharmony_ci /* ISA stuff (Terratec Active Radio Upgrade) */ 40362306a36Sopenharmony_ci int mbox_ior; 40462306a36Sopenharmony_ci int mbox_iow; 40562306a36Sopenharmony_ci int mbox_csel; 40662306a36Sopenharmony_ci 40762306a36Sopenharmony_ci /* switch status for multi-controller cards */ 40862306a36Sopenharmony_ci char sw_status[4]; 40962306a36Sopenharmony_ci 41062306a36Sopenharmony_ci /* risc memory management data 41162306a36Sopenharmony_ci - must acquire s_lock before changing these 41262306a36Sopenharmony_ci - only the irq handler is supported to touch top + bottom + vcurr */ 41362306a36Sopenharmony_ci struct btcx_riscmem main; 41462306a36Sopenharmony_ci struct list_head capture; /* video capture queue */ 41562306a36Sopenharmony_ci struct list_head vcapture; /* vbi capture queue */ 41662306a36Sopenharmony_ci struct bttv_buffer_set curr; /* active buffers */ 41762306a36Sopenharmony_ci struct bttv_buffer *cvbi; /* active vbi buffer */ 41862306a36Sopenharmony_ci int loop_irq; 41962306a36Sopenharmony_ci int new_input; 42062306a36Sopenharmony_ci 42162306a36Sopenharmony_ci unsigned long dma_on; 42262306a36Sopenharmony_ci struct timer_list timeout; 42362306a36Sopenharmony_ci struct bttv_suspend_state state; 42462306a36Sopenharmony_ci 42562306a36Sopenharmony_ci /* stats */ 42662306a36Sopenharmony_ci unsigned int errors; 42762306a36Sopenharmony_ci unsigned int framedrop; 42862306a36Sopenharmony_ci unsigned int irq_total; 42962306a36Sopenharmony_ci unsigned int irq_me; 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_ci unsigned int users; 43262306a36Sopenharmony_ci struct v4l2_fh fh; 43362306a36Sopenharmony_ci enum v4l2_buf_type type; 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ci enum v4l2_field field; 43662306a36Sopenharmony_ci int field_last; 43762306a36Sopenharmony_ci 43862306a36Sopenharmony_ci /* video capture */ 43962306a36Sopenharmony_ci struct vb2_queue capq; 44062306a36Sopenharmony_ci const struct bttv_format *fmt; 44162306a36Sopenharmony_ci int width; 44262306a36Sopenharmony_ci int height; 44362306a36Sopenharmony_ci 44462306a36Sopenharmony_ci /* vbi capture */ 44562306a36Sopenharmony_ci struct vb2_queue vbiq; 44662306a36Sopenharmony_ci struct bttv_vbi_fmt vbi_fmt; 44762306a36Sopenharmony_ci unsigned int vbi_count[2]; 44862306a36Sopenharmony_ci 44962306a36Sopenharmony_ci /* Application called VIDIOC_S_SELECTION. */ 45062306a36Sopenharmony_ci int do_crop; 45162306a36Sopenharmony_ci 45262306a36Sopenharmony_ci /* used to make dvb-bt8xx autoloadable */ 45362306a36Sopenharmony_ci struct work_struct request_module_wk; 45462306a36Sopenharmony_ci 45562306a36Sopenharmony_ci /* Default (0) and current (1) video capturing 45662306a36Sopenharmony_ci cropping parameters in bttv_tvnorm.cropcap units. Protected 45762306a36Sopenharmony_ci by bttv.lock. */ 45862306a36Sopenharmony_ci struct bttv_crop crop[2]; 45962306a36Sopenharmony_ci 46062306a36Sopenharmony_ci /* Earliest possible start of video capturing in 46162306a36Sopenharmony_ci bttv_tvnorm.cropcap line units. Set by check_alloc_btres() 46262306a36Sopenharmony_ci and free_btres(). Protected by bttv.lock. */ 46362306a36Sopenharmony_ci __s32 vbi_end; 46462306a36Sopenharmony_ci 46562306a36Sopenharmony_ci /* Latest possible end of VBI capturing (= crop[x].rect.top when 46662306a36Sopenharmony_ci VIDEO_RESOURCES are locked). Set by check_alloc_btres() 46762306a36Sopenharmony_ci and free_btres(). Protected by bttv.lock. */ 46862306a36Sopenharmony_ci __s32 crop_start; 46962306a36Sopenharmony_ci}; 47062306a36Sopenharmony_ci 47162306a36Sopenharmony_cistatic inline struct bttv *to_bttv(struct v4l2_device *v4l2_dev) 47262306a36Sopenharmony_ci{ 47362306a36Sopenharmony_ci return container_of(v4l2_dev, struct bttv, c.v4l2_dev); 47462306a36Sopenharmony_ci} 47562306a36Sopenharmony_ci 47662306a36Sopenharmony_ci/* our devices */ 47762306a36Sopenharmony_ci#define BTTV_MAX 32 47862306a36Sopenharmony_ciextern unsigned int bttv_num; 47962306a36Sopenharmony_ciextern struct bttv *bttvs[BTTV_MAX]; 48062306a36Sopenharmony_ci 48162306a36Sopenharmony_cistatic inline unsigned int bttv_muxsel(const struct bttv *btv, 48262306a36Sopenharmony_ci unsigned int input) 48362306a36Sopenharmony_ci{ 48462306a36Sopenharmony_ci return (bttv_tvcards[btv->c.type].muxsel >> (input * 2)) & 3; 48562306a36Sopenharmony_ci} 48662306a36Sopenharmony_ci 48762306a36Sopenharmony_ci#endif 48862306a36Sopenharmony_ci 48962306a36Sopenharmony_civoid init_irqreg(struct bttv *btv); 49062306a36Sopenharmony_ci 49162306a36Sopenharmony_ci#define btwrite(dat,adr) writel((dat), btv->bt848_mmio+(adr)) 49262306a36Sopenharmony_ci#define btread(adr) readl(btv->bt848_mmio+(adr)) 49362306a36Sopenharmony_ci 49462306a36Sopenharmony_ci#define btand(dat,adr) btwrite((dat) & btread(adr), adr) 49562306a36Sopenharmony_ci#define btor(dat,adr) btwrite((dat) | btread(adr), adr) 49662306a36Sopenharmony_ci#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr) 49762306a36Sopenharmony_ci 49862306a36Sopenharmony_ci#endif /* _BTTVP_H_ */ 499