Path: blob/master/drivers/media/video/bt8xx/bttvp.h
10785 views
/*12bttv - Bt848 frame grabber driver34bttv's *private* header file -- nobody other than bttv itself5should ever include this file.67(c) 2000-2002 Gerd Knorr <[email protected]>89This program is free software; you can redistribute it and/or modify10it under the terms of the GNU General Public License as published by11the Free Software Foundation; either version 2 of the License, or12(at your option) any later version.1314This program is distributed in the hope that it will be useful,15but WITHOUT ANY WARRANTY; without even the implied warranty of16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17GNU General Public License for more details.1819You should have received a copy of the GNU General Public License20along with this program; if not, write to the Free Software21Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.22*/2324#ifndef _BTTVP_H_25#define _BTTVP_H_2627#include <linux/version.h>28#define BTTV_VERSION_CODE KERNEL_VERSION(0,9,18)2930#include <linux/types.h>31#include <linux/wait.h>32#include <linux/i2c.h>33#include <linux/i2c-algo-bit.h>34#include <linux/pci.h>35#include <linux/input.h>36#include <linux/mutex.h>37#include <linux/scatterlist.h>38#include <asm/io.h>39#include <media/v4l2-common.h>40#include <linux/device.h>41#include <media/videobuf-dma-sg.h>42#include <media/tveeprom.h>43#include <media/rc-core.h>44#include <media/ir-kbd-i2c.h>4546#include "bt848.h"47#include "bttv.h"48#include "btcx-risc.h"4950#ifdef __KERNEL__5152#define FORMAT_FLAGS_DITHER 0x0153#define FORMAT_FLAGS_PACKED 0x0254#define FORMAT_FLAGS_PLANAR 0x0455#define FORMAT_FLAGS_RAW 0x0856#define FORMAT_FLAGS_CrCb 0x105758#define RISC_SLOT_O_VBI 459#define RISC_SLOT_O_FIELD 660#define RISC_SLOT_E_VBI 1061#define RISC_SLOT_E_FIELD 1262#define RISC_SLOT_LOOP 146364#define RESOURCE_OVERLAY 165#define RESOURCE_VIDEO_STREAM 266#define RESOURCE_VBI 467#define RESOURCE_VIDEO_READ 86869#define RAW_LINES 64070#define RAW_BPL 10247172#define UNSET (-1U)7374/* Min. value in VDELAY register. */75#define MIN_VDELAY 276/* Even to get Cb first, odd for Cr. */77#define MAX_HDELAY (0x3FF & -2)78/* Limits scaled width, which must be a multiple of 4. */79#define MAX_HACTIVE (0x3FF & -4)8081#define BTTV_NORMS (\82V4L2_STD_PAL | V4L2_STD_PAL_N | \83V4L2_STD_PAL_Nc | V4L2_STD_SECAM | \84V4L2_STD_NTSC | V4L2_STD_PAL_M | \85V4L2_STD_PAL_60)86/* ---------------------------------------------------------- */8788struct bttv_tvnorm {89int v4l2_id;90char *name;91u32 Fsc;92u16 swidth, sheight; /* scaled standard width, height */93u16 totalwidth;94u8 adelay, bdelay, iform;95u32 scaledtwidth;96u16 hdelayx1, hactivex1;97u16 vdelay;98u8 vbipack;99u16 vtotal;100int sram;101/* ITU-R frame line number of the first VBI line we can102capture, of the first and second field. The last possible line103is determined by cropcap.bounds. */104u16 vbistart[2];105/* Horizontally this counts fCLKx1 samples following the leading106edge of the horizontal sync pulse, vertically ITU-R frame line107numbers of the first field times two (2, 4, 6, ... 524 or 624). */108struct v4l2_cropcap cropcap;109};110extern const struct bttv_tvnorm bttv_tvnorms[];111112struct bttv_format {113char *name;114int fourcc; /* video4linux 2 */115int btformat; /* BT848_COLOR_FMT_* */116int btswap; /* BT848_COLOR_CTL_* */117int depth; /* bit/pixel */118int flags;119int hshift,vshift; /* for planar modes */120};121122struct bttv_ir {123struct rc_dev *dev;124struct timer_list timer;125126char name[32];127char phys[32];128129/* Usual gpio signalling */130u32 mask_keycode;131u32 mask_keydown;132u32 mask_keyup;133u32 polling;134u32 last_gpio;135int shift_by;136int start; // What should RC5_START() be137int addr; // What RC5_ADDR() should be.138int rc5_remote_gap;139140/* RC5 gpio */141bool rc5_gpio; /* Is RC5 legacy GPIO enabled? */142u32 last_bit; /* last raw bit seen */143u32 code; /* raw code under construction */144struct timeval base_time; /* time of last seen code */145bool active; /* building raw code */146};147148149/* ---------------------------------------------------------- */150151struct bttv_geometry {152u8 vtc,crop,comb;153u16 width,hscale,hdelay;154u16 sheight,vscale,vdelay,vtotal;155};156157struct bttv_buffer {158/* common v4l buffer stuff -- must be first */159struct videobuf_buffer vb;160161/* bttv specific */162const struct bttv_format *fmt;163unsigned int tvnorm;164int btformat;165int btswap;166struct bttv_geometry geo;167struct btcx_riscmem top;168struct btcx_riscmem bottom;169struct v4l2_rect crop;170unsigned int vbi_skip[2];171unsigned int vbi_count[2];172};173174struct bttv_buffer_set {175struct bttv_buffer *top; /* top field buffer */176struct bttv_buffer *bottom; /* bottom field buffer */177unsigned int top_irq;178unsigned int frame_irq;179};180181struct bttv_overlay {182unsigned int tvnorm;183struct v4l2_rect w;184enum v4l2_field field;185struct v4l2_clip *clips;186int nclips;187int setup_ok;188};189190struct bttv_vbi_fmt {191struct v4l2_vbi_format fmt;192193/* fmt.start[] and count[] refer to this video standard. */194const struct bttv_tvnorm *tvnorm;195196/* Earliest possible start of video capturing with this197v4l2_vbi_format, in struct bttv_crop.rect units. */198__s32 end;199};200201/* bttv-vbi.c */202void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm);203204struct bttv_crop {205/* A cropping rectangle in struct bttv_tvnorm.cropcap units. */206struct v4l2_rect rect;207208/* Scaled image size limits with this crop rect. Divide209max_height, but not min_height, by two when capturing210single fields. See also bttv_crop_reset() and211bttv_crop_adjust() in bttv-driver.c. */212__s32 min_scaled_width;213__s32 min_scaled_height;214__s32 max_scaled_width;215__s32 max_scaled_height;216};217218struct bttv_fh {219struct bttv *btv;220int resources;221#ifdef VIDIOC_G_PRIORITY222enum v4l2_priority prio;223#endif224enum v4l2_buf_type type;225226/* video capture */227struct videobuf_queue cap;228const struct bttv_format *fmt;229int width;230int height;231232/* video overlay */233const struct bttv_format *ovfmt;234struct bttv_overlay ov;235236/* Application called VIDIOC_S_CROP. */237int do_crop;238239/* vbi capture */240struct videobuf_queue vbi;241/* Current VBI capture window as seen through this fh (cannot242be global for compatibility with earlier drivers). Protected243by struct bttv.lock and struct bttv_fh.vbi.lock. */244struct bttv_vbi_fmt vbi_fmt;245};246247/* ---------------------------------------------------------- */248/* bttv-risc.c */249250/* risc code generators - capture */251int bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,252struct scatterlist *sglist,253unsigned int offset, unsigned int bpl,254unsigned int pitch, unsigned int skip_lines,255unsigned int store_lines);256257/* control dma register + risc main loop */258void bttv_set_dma(struct bttv *btv, int override);259int bttv_risc_init_main(struct bttv *btv);260int bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,261int irqflags);262263/* capture buffer handling */264int bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf);265int bttv_buffer_activate_video(struct bttv *btv,266struct bttv_buffer_set *set);267int bttv_buffer_activate_vbi(struct bttv *btv,268struct bttv_buffer *vbi);269void bttv_dma_free(struct videobuf_queue *q, struct bttv *btv,270struct bttv_buffer *buf);271272/* overlay handling */273int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,274const struct bttv_format *fmt,275struct bttv_buffer *buf);276277278/* ---------------------------------------------------------- */279/* bttv-vbi.c */280281int bttv_try_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);282int bttv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);283int bttv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);284285extern struct videobuf_queue_ops bttv_vbi_qops;286287/* ---------------------------------------------------------- */288/* bttv-gpio.c */289290extern struct bus_type bttv_sub_bus_type;291int bttv_sub_add_device(struct bttv_core *core, char *name);292int bttv_sub_del_devices(struct bttv_core *core);293294/* ---------------------------------------------------------- */295/* bttv-cards.c */296297extern int no_overlay;298299/* ---------------------------------------------------------- */300/* bttv-input.c */301302extern void init_bttv_i2c_ir(struct bttv *btv);303extern int fini_bttv_i2c(struct bttv *btv);304305/* ---------------------------------------------------------- */306/* bttv-driver.c */307308/* insmod options */309extern unsigned int bttv_verbose;310extern unsigned int bttv_debug;311extern unsigned int bttv_gpio;312extern void bttv_gpio_tracking(struct bttv *btv, char *comment);313extern int init_bttv_i2c(struct bttv *btv);314315#define bttv_printk if (bttv_verbose) printk316#define dprintk if (bttv_debug >= 1) printk317#define d2printk if (bttv_debug >= 2) printk318319#define BTTV_MAX_FBUF 0x208000320#define BTTV_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */321#define BTTV_FREE_IDLE msecs_to_jiffies(1000) /* one second */322323324struct bttv_pll_info {325unsigned int pll_ifreq; /* PLL input frequency */326unsigned int pll_ofreq; /* PLL output frequency */327unsigned int pll_crystal; /* Crystal used for input */328unsigned int pll_current; /* Currently programmed ofreq */329};330331/* for gpio-connected remote control */332struct bttv_input {333struct input_dev *dev;334char name[32];335char phys[32];336u32 mask_keycode;337u32 mask_keydown;338};339340struct bttv_suspend_state {341u32 gpio_enable;342u32 gpio_data;343int disabled;344int loop_irq;345struct bttv_buffer_set video;346struct bttv_buffer *vbi;347};348349struct bttv {350struct bttv_core c;351352/* pci device config */353unsigned short id;354unsigned char revision;355unsigned char __iomem *bt848_mmio; /* pointer to mmio */356357/* card configuration info */358unsigned int cardid; /* pci subsystem id (bt878 based ones) */359unsigned int tuner_type; /* tuner chip type */360unsigned int tda9887_conf;361unsigned int svhs, dig;362unsigned int has_saa6588:1;363struct bttv_pll_info pll;364int triton1;365int gpioirq;366367int use_i2c_hw;368369/* old gpio interface */370int shutdown;371372void (*volume_gpio)(struct bttv *btv, __u16 volume);373void (*audio_mode_gpio)(struct bttv *btv, struct v4l2_tuner *tuner, int set);374375/* new gpio interface */376spinlock_t gpio_lock;377378/* i2c layer */379struct i2c_algo_bit_data i2c_algo;380struct i2c_client i2c_client;381int i2c_state, i2c_rc;382int i2c_done;383wait_queue_head_t i2c_queue;384struct v4l2_subdev *sd_msp34xx;385struct v4l2_subdev *sd_tvaudio;386387/* video4linux (1) */388struct video_device *video_dev;389struct video_device *radio_dev;390struct video_device *vbi_dev;391392/* infrared remote */393int has_remote;394struct bttv_ir *remote;395396/* I2C remote data */397struct IR_i2c_init_data init_data;398399/* locking */400spinlock_t s_lock;401struct mutex lock;402int resources;403#ifdef VIDIOC_G_PRIORITY404struct v4l2_prio_state prio;405#endif406407/* video state */408unsigned int input;409unsigned int audio;410unsigned int mute;411unsigned long freq;412unsigned int tvnorm;413int hue, contrast, bright, saturation;414struct v4l2_framebuffer fbuf;415unsigned int field_count;416417/* various options */418int opt_combfilter;419int opt_lumafilter;420int opt_automute;421int opt_chroma_agc;422int opt_adc_crush;423int opt_vcr_hack;424int opt_whitecrush_upper;425int opt_whitecrush_lower;426int opt_uv_ratio;427int opt_full_luma_range;428int opt_coring;429430/* radio data/state */431int has_radio;432int radio_user;433434/* miro/pinnacle + Aimslab VHX435philips matchbox (tea5757 radio tuner) support */436int has_matchbox;437int mbox_we;438int mbox_data;439int mbox_clk;440int mbox_most;441int mbox_mask;442443/* ISA stuff (Terratec Active Radio Upgrade) */444int mbox_ior;445int mbox_iow;446int mbox_csel;447448/* risc memory management data449- must acquire s_lock before changing these450- only the irq handler is supported to touch top + bottom + vcurr */451struct btcx_riscmem main;452struct bttv_buffer *screen; /* overlay */453struct list_head capture; /* video capture queue */454struct list_head vcapture; /* vbi capture queue */455struct bttv_buffer_set curr; /* active buffers */456struct bttv_buffer *cvbi; /* active vbi buffer */457int loop_irq;458int new_input;459460unsigned long cap_ctl;461unsigned long dma_on;462struct timer_list timeout;463struct bttv_suspend_state state;464465/* stats */466unsigned int errors;467unsigned int framedrop;468unsigned int irq_total;469unsigned int irq_me;470471unsigned int users;472struct bttv_fh init;473474/* used to make dvb-bt8xx autoloadable */475struct work_struct request_module_wk;476477/* Default (0) and current (1) video capturing and overlay478cropping parameters in bttv_tvnorm.cropcap units. Protected479by bttv.lock. */480struct bttv_crop crop[2];481482/* Earliest possible start of video capturing in483bttv_tvnorm.cropcap line units. Set by check_alloc_btres()484and free_btres(). Protected by bttv.lock. */485__s32 vbi_end;486487/* Latest possible end of VBI capturing (= crop[x].rect.top when488VIDEO_RESOURCES are locked). Set by check_alloc_btres()489and free_btres(). Protected by bttv.lock. */490__s32 crop_start;491};492493static inline struct bttv *to_bttv(struct v4l2_device *v4l2_dev)494{495return container_of(v4l2_dev, struct bttv, c.v4l2_dev);496}497498/* our devices */499#define BTTV_MAX 32500extern unsigned int bttv_num;501extern struct bttv *bttvs[BTTV_MAX];502503static inline unsigned int bttv_muxsel(const struct bttv *btv,504unsigned int input)505{506return (bttv_tvcards[btv->c.type].muxsel >> (input * 2)) & 3;507}508509#endif510511#define btwrite(dat,adr) writel((dat), btv->bt848_mmio+(adr))512#define btread(adr) readl(btv->bt848_mmio+(adr))513514#define btand(dat,adr) btwrite((dat) & btread(adr), adr)515#define btor(dat,adr) btwrite((dat) | btread(adr), adr)516#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)517518#endif /* _BTTVP_H_ */519520/*521* Local variables:522* c-basic-offset: 8523* End:524*/525526527