#include <sys/bus.h>
#include <sys/device.h>
#include <sys/select.h>
#include <sys/reboot.h>
#ifndef PCI_LATENCY_TIMER
#define PCI_LATENCY_TIMER 0x0c
#endif
#define BROOKTREE_848 1
#define BROOKTREE_848A 2
#define BROOKTREE_849A 3
#define BROOKTREE_878 4
#define BROOKTREE_879 5
typedef volatile u_int bregister_t;
#define BTBYTE(what) bregister_t what:8; int :24
#define BTWORD(what) bregister_t what:16; int: 16
#define BTLONG(what) bregister_t what:32
struct bt848_registers {
BTBYTE (dstatus);
#define BT848_DSTATUS_PRES (1<<7)
#define BT848_DSTATUS_HLOC (1<<6)
#define BT848_DSTATUS_FIELD (1<<5)
#define BT848_DSTATUS_NUML (1<<4)
#define BT848_DSTATUS_CSEL (1<<3)
#define BT848_DSTATUS_PLOCK (1<<2)
#define BT848_DSTATUS_LOF (1<<1)
#define BT848_DSTATUS_COF (1<<0)
BTBYTE (iform);
#define BT848_IFORM_MUXSEL (0x3<<5)
# define BT848_IFORM_M_MUX1 (0x03<<5)
# define BT848_IFORM_M_MUX0 (0x02<<5)
# define BT848_IFORM_M_MUX2 (0x01<<5)
# define BT848_IFORM_M_MUX3 (0x0)
# define BT848_IFORM_M_RSVD (0x00<<5)
#define BT848_IFORM_XTSEL (0x3<<3)
# define BT848_IFORM_X_AUTO (0x03<<3)
# define BT848_IFORM_X_XT1 (0x02<<3)
# define BT848_IFORM_X_XT0 (0x01<<3)
# define BT848_IFORM_X_RSVD (0x00<<3)
BTBYTE (tdec);
BTBYTE (e_crop);
BTBYTE (e_vdelay_lo);
BTBYTE (e_vactive_lo);
BTBYTE (e_delay_lo);
BTBYTE (e_hactive_lo);
BTBYTE (e_hscale_hi);
BTBYTE (e_hscale_lo);
BTBYTE (bright);
BTBYTE (e_control);
#define BT848_E_CONTROL_LNOTCH (1<<7)
#define BT848_E_CONTROL_COMP (1<<6)
#define BT848_E_CONTROL_LDEC (1<<5)
#define BT848_E_CONTROL_CBSENSE (1<<4)
#define BT848_E_CONTROL_RSVD (1<<3)
#define BT848_E_CONTROL_CON_MSB (1<<2)
#define BT848_E_CONTROL_SAT_U_MSB (1<<1)
#define BT848_E_CONTROL_SAT_V_MSB (1<<0)
BTBYTE (contrast_lo);
BTBYTE (sat_u_lo);
BTBYTE (sat_v_lo);
BTBYTE (hue);
BTBYTE (e_scloop);
#define BT848_E_SCLOOP_RSVD1 (1<<7)
#define BT848_E_SCLOOP_CAGC (1<<6)
#define BT848_E_SCLOOP_CKILL (1<<5)
#define BT848_E_SCLOOP_HFILT (0x3<<3)
# define BT848_E_SCLOOP_HFILT_ICON (0x3<<3)
# define BT848_E_SCLOOP_HFILT_QCIF (0x2<<3)
# define BT848_E_SCLOOP_HFILT_CIF (0x1<<3)
# define BT848_E_SCLOOP_HFILT_AUTO (0x0<<3)
#define BT848_E_SCLOOP_RSVD0 (0x7<<0)
int :32;
BTBYTE (oform);
BTBYTE (e_vscale_hi);
BTBYTE (e_vscale_lo);
BTBYTE (test);
int :32;
int :32;
BTLONG (adelay);
BTBYTE (bdelay);
BTBYTE (adc);
#define BT848_ADC_RESERVED (0x80)
#define BT848_ADC_SYNC_T (1<<5)
#define BT848_ADC_AGC_EN (1<<4)
#define BT848_ADC_CLK_SLEEP (1<<3)
#define BT848_ADC_Y_SLEEP (1<<2)
#define BT848_ADC_C_SLEEP (1<<1)
#define BT848_ADC_CRUSH (1<<0)
BTBYTE (e_vtc);
int :32;
int :32;
int :32;
BTLONG (sreset);
u_char filler1[0x84-0x80];
BTBYTE (tgctrl);
#define BT848_TGCTRL_TGCKI (3<<3)
#define BT848_TGCTRL_TGCKI_XTAL (0<<3)
#define BT848_TGCTRL_TGCKI_PLL (1<<3)
#define BT848_TGCTRL_TGCKI_GPCLK (2<<3)
#define BT848_TGCTRL_TGCKI_GPCLK_I (3<<3)
u_char filler[0x8c-0x88];
BTBYTE (o_crop);
BTBYTE (o_vdelay_lo);
BTBYTE (o_vactive_lo);
BTBYTE (o_delay_lo);
BTBYTE (o_hactive_lo);
BTBYTE (o_hscale_hi);
BTBYTE (o_hscale_lo);
int :32;
BTBYTE (o_control);
#define BT848_O_CONTROL_LNOTCH (1<<7)
#define BT848_O_CONTROL_COMP (1<<6)
#define BT848_O_CONTROL_LDEC (1<<5)
#define BT848_O_CONTROL_CBSENSE (1<<4)
#define BT848_O_CONTROL_RSVD (1<<3)
#define BT848_O_CONTROL_CON_MSB (1<<2)
#define BT848_O_CONTROL_SAT_U_MSB (1<<1)
#define BT848_O_CONTROL_SAT_V_MSB (1<<0)
u_char fillter4[16];
BTBYTE (o_scloop);
#define BT848_O_SCLOOP_RSVD1 (1<<7)
#define BT848_O_SCLOOP_CAGC (1<<6)
#define BT848_O_SCLOOP_CKILL (1<<5)
#define BT848_O_SCLOOP_HFILT (0x3<<3)
#define BT848_O_SCLOOP_HFILT_ICON (0x3<<3)
#define BT848_O_SCLOOP_HFILT_QCIF (0x2<<3)
#define BT848_O_SCLOOP_HFILT_CIF (0x1<<3)
#define BT848_O_SCLOOP_HFILT_AUTO (0x0<<3)
#define BT848_O_SCLOOP_RSVD0 (0x7<<0)
int :32;
int :32;
BTBYTE (o_vscale_hi);
BTBYTE (o_vscale_lo);
BTBYTE (color_fmt);
bregister_t color_ctl_swap :4;
#define BT848_COLOR_CTL_WSWAP_ODD (1<<3)
#define BT848_COLOR_CTL_WSWAP_EVEN (1<<2)
#define BT848_COLOR_CTL_BSWAP_ODD (1<<1)
#define BT848_COLOR_CTL_BSWAP_EVEN (1<<0)
bregister_t color_ctl_gamma :1;
bregister_t color_ctl_rgb_ded :1;
bregister_t color_ctl_color_bars :1;
bregister_t color_ctl_ext_frmrate :1;
#define BT848_COLOR_CTL_GAMMA (1<<4)
#define BT848_COLOR_CTL_RGB_DED (1<<5)
#define BT848_COLOR_CTL_COLOR_BARS (1<<6)
#define BT848_COLOR_CTL_EXT_FRMRATE (1<<7)
int :24;
BTBYTE (cap_ctl);
#define BT848_CAP_CTL_DITH_FRAME (1<<4)
#define BT848_CAP_CTL_VBI_ODD (1<<3)
#define BT848_CAP_CTL_VBI_EVEN (1<<2)
#define BT848_CAP_CTL_ODD (1<<1)
#define BT848_CAP_CTL_EVEN (1<<0)
BTBYTE (vbi_pack_size);
BTBYTE (vbi_pack_del);
int :32;
BTBYTE (o_vtc);
BTBYTE (pll_f_lo);
BTBYTE (pll_f_hi);
BTBYTE (pll_f_xci);
#define BT848_PLL_F_C (1<<6)
#define BT848_PLL_F_X (1<<7)
u_char filler2[0x100-0xfc];
BTLONG (int_stat);
BTLONG (int_mask);
#define BT848_INT_RISCS (0xf<<28)
#define BT848_INT_RISC_EN (1<<27)
#define BT848_INT_RACK (1<<25)
#define BT848_INT_FIELD (1<<24)
#define BT848_INT_MYSTERYBIT (1<<23)
#define BT848_INT_SCERR (1<<19)
#define BT848_INT_OCERR (1<<18)
#define BT848_INT_PABORT (1<<17)
#define BT848_INT_RIPERR (1<<16)
#define BT848_INT_PPERR (1<<15)
#define BT848_INT_FDSR (1<<14)
#define BT848_INT_FTRGT (1<<13)
#define BT848_INT_FBUS (1<<12)
#define BT848_INT_RISCI (1<<11)
#define BT848_INT_GPINT (1<<9)
#define BT848_INT_I2CDONE (1<<8)
#define BT848_INT_RSV1 (1<<7)
#define BT848_INT_RSV0 (1<<6)
#define BT848_INT_VPRES (1<<5)
#define BT848_INT_HLOCK (1<<4)
#define BT848_INT_OFLOW (1<<3)
#define BT848_INT_HSYNC (1<<2)
#define BT848_INT_VSYNC (1<<1)
#define BT848_INT_FMTCHG (1<<0)
int :32;
BTWORD (gpio_dma_ctl);
#define BT848_DMA_CTL_PL23TP4 (0<<6)
#define BT848_DMA_CTL_PL23TP8 (1<<6)
#define BT848_DMA_CTL_PL23TP16 (2<<6)
#define BT848_DMA_CTL_PL23TP32 (3<<6)
#define BT848_DMA_CTL_PL1TP4 (0<<4)
#define BT848_DMA_CTL_PL1TP8 (1<<4)
#define BT848_DMA_CTL_PL1TP16 (2<<4)
#define BT848_DMA_CTL_PL1TP32 (3<<4)
#define BT848_DMA_CTL_PKTP4 (0<<2)
#define BT848_DMA_CTL_PKTP8 (1<<2)
#define BT848_DMA_CTL_PKTP16 (2<<2)
#define BT848_DMA_CTL_PKTP32 (3<<2)
#define BT848_DMA_CTL_RISC_EN (1<<1)
#define BT848_DMA_CTL_FIFO_EN (1<<0)
BTLONG (i2c_data_ctl);
#define BT848_DATA_CTL_I2CDIV (0xf<<4)
#define BT848_DATA_CTL_I2CSYNC (1<<3)
#define BT848_DATA_CTL_I2CW3B (1<<2)
#define BT848_DATA_CTL_I2CSCL (1<<1)
#define BT848_DATA_CTL_I2CSDA (1<<0)
BTLONG (risc_strt_add);
BTLONG (gpio_out_en);
BTLONG (gpio_reg_inp);
BTLONG (risc_count);
u_char filler3[0x200-0x124];
BTLONG (gpio_data);
};
#define BKTR_DSTATUS 0x000
#define BKTR_IFORM 0x004
#define BKTR_TDEC 0x008
#define BKTR_E_CROP 0x00C
#define BKTR_O_CROP 0x08C
#define BKTR_E_VDELAY_LO 0x010
#define BKTR_O_VDELAY_LO 0x090
#define BKTR_E_VACTIVE_LO 0x014
#define BKTR_O_VACTIVE_LO 0x094
#define BKTR_E_DELAY_LO 0x018
#define BKTR_O_DELAY_LO 0x098
#define BKTR_E_HACTIVE_LO 0x01C
#define BKTR_O_HACTIVE_LO 0x09C
#define BKTR_E_HSCALE_HI 0x020
#define BKTR_O_HSCALE_HI 0x0A0
#define BKTR_E_HSCALE_LO 0x024
#define BKTR_O_HSCALE_LO 0x0A4
#define BKTR_BRIGHT 0x028
#define BKTR_E_CONTROL 0x02C
#define BKTR_O_CONTROL 0x0AC
#define BKTR_CONTRAST_LO 0x030
#define BKTR_SAT_U_LO 0x034
#define BKTR_SAT_V_LO 0x038
#define BKTR_HUE 0x03C
#define BKTR_E_SCLOOP 0x040
#define BKTR_O_SCLOOP 0x0C0
#define BKTR_OFORM 0x048
#define BKTR_E_VSCALE_HI 0x04C
#define BKTR_O_VSCALE_HI 0x0CC
#define BKTR_E_VSCALE_LO 0x050
#define BKTR_O_VSCALE_LO 0x0D0
#define BKTR_TEST 0x054
#define BKTR_ADELAY 0x060
#define BKTR_BDELAY 0x064
#define BKTR_ADC 0x068
#define BKTR_E_VTC 0x06C
#define BKTR_O_VTC 0x0EC
#define BKTR_SRESET 0x07C
#define BKTR_COLOR_FMT 0x0D4
#define BKTR_COLOR_CTL 0x0D8
#define BKTR_CAP_CTL 0x0DC
#define BKTR_VBI_PACK_SIZE 0x0E0
#define BKTR_VBI_PACK_DEL 0x0E4
#define BKTR_INT_STAT 0x100
#define BKTR_INT_MASK 0x104
#define BKTR_RISC_COUNT 0x120
#define BKTR_RISC_STRT_ADD 0x114
#define BKTR_GPIO_DMA_CTL 0x10C
#define BKTR_GPIO_OUT_EN 0x118
#define BKTR_GPIO_REG_INP 0x11C
#define BKTR_GPIO_DATA 0x200
#define BKTR_I2C_DATA_CTL 0x110
#define BKTR_TGCTRL 0x084
#define BKTR_PLL_F_LO 0x0F0
#define BKTR_PLL_F_HI 0x0F4
#define BKTR_PLL_F_XCI 0x0F8
struct TVTUNER {
int frequency;
u_char chnlset;
u_char channel;
u_char band;
u_char afc;
u_char radio_mode;
};
struct TUNER {
const char* name;
u_char type;
u_char pllControl[4];
u_int bandLimits[2];
u_char bandAddrs[4];
};
#define EEPROMBLOCKSIZE 32
struct CARDTYPE {
unsigned int card_id;
const char* name;
const struct TUNER* tuner;
u_char tuner_pllAddr;
u_char dbx;
u_char msp3400c;
u_char dpl3518a;
u_char eepromAddr;
u_char eepromSize;
u_int audiomuxs[5];
u_int gpio_mux_bits;
};
struct format_params {
int vtotal, vdelay, vactive;
int htotal, hdelay, hactive;
int scaled_hactive, scaled_htotal;
int frame_rate;
u_char adelay, bdelay;
int iform_xtsel;
int vbi_num_lines, vbi_num_samples;
};
#if defined(BKTR_USE_FREEBSD_SMBUS)
struct bktr_i2c_softc {
device_t iicbus;
device_t smbus;
};
#endif
struct bktr_softc;
u_int8_t bktr_INB(struct bktr_softc *, int);
u_int16_t bktr_INW(struct bktr_softc *, int);
u_int32_t bktr_INL(struct bktr_softc *, int);
void bktr_OUTB(struct bktr_softc *, int, u_int8_t);
void bktr_OUTW(struct bktr_softc *, int, u_int16_t);
void bktr_OUTL(struct bktr_softc *, int, u_int32_t);
#define INB(bktr,offset) bktr_INB(bktr,offset)
#define INW(bktr,offset) bktr_INW(bktr,offset)
#define INL(bktr,offset) bktr_INL(bktr,offset)
#define OUTB(bktr,offset,value) bktr_OUTB(bktr,offset,value)
#define OUTW(bktr,offset,value) bktr_OUTW(bktr,offset,value)
#define OUTL(bktr,offset,value) bktr_OUTL(bktr,offset,value)
typedef struct bktr_clip bktr_clip_t;
struct bktr_softc {
device_t bktr_dev;
bus_dma_tag_t dmat;
bus_space_tag_t memt;
bus_space_handle_t memh;
bus_size_t obmemsz;
void *ih;
bus_dmamap_t dm_prog;
bus_dmamap_t dm_oprog;
bus_dmamap_t dm_mem;
bus_dmamap_t dm_vbidata;
bus_dmamap_t dm_vbibuffer;
vaddr_t bigbuf;
vaddr_t vbidata;
vaddr_t vbibuffer;
vaddr_t dma_prog;
vaddr_t odd_dma_prog;
int alloc_pages;
int vbiinsert;
int vbistart;
int vbisize;
u_int vbi_sequence_number;
int vbi_read_blocked;
struct selinfo vbi_select;
struct proc *proc;
int signal;
int clr_on_start;
#define METEOR_SIG_MODE_MASK 0xffff0000
#define METEOR_SIG_FIELD_MODE 0x00010000
#define METEOR_SIG_FRAME_MODE 0x00000000
char dma_prog_loaded;
struct meteor_mem *mem;
u_int synch_wait;
short current;
short rows;
short cols;
int capture_area_x_offset;
int capture_area_y_offset;
int capture_area_x_size;
int capture_area_y_size;
char capture_area_enabled;
int pixfmt;
int pixfmt_compat;
u_int format;
short frames;
int frame_size;
u_int fifo_errors;
u_int dma_errors;
u_int frames_captured;
u_int even_fields_captured;
u_int odd_fields_captured;
u_int range_enable;
u_short capcontrol;
u_short bktr_cap_ctl;
volatile u_int flags;
#define METEOR_INITIALIZED 0x00000001
#define METEOR_OPEN 0x00000002
#define METEOR_MMAP 0x00000004
#define METEOR_INTR 0x00000008
#define METEOR_READ 0x00000010
#define METEOR_SINGLE 0x00000020
#define METEOR_CONTIN 0x00000040
#define METEOR_SYNCAP 0x00000080
#define METEOR_CAP_MASK 0x000000f0
#define METEOR_NTSC 0x00000100
#define METEOR_PAL 0x00000200
#define METEOR_SECAM 0x00000400
#define BROOKTREE_NTSC 0x00000100
#define BROOKTREE_PAL 0x00000200
#define BROOKTREE_SECAM 0x00000400
#define METEOR_AUTOMODE 0x00000800
#define METEOR_FORM_MASK 0x00000f00
#define METEOR_DEV0 0x00001000
#define METEOR_DEV1 0x00002000
#define METEOR_DEV2 0x00004000
#define METEOR_DEV3 0x00008000
#define METEOR_DEV_SVIDEO 0x00006000
#define METEOR_DEV_RGB 0x0000a000
#define METEOR_DEV_MASK 0x0000f000
#define METEOR_RGB16 0x00010000
#define METEOR_RGB24 0x00020000
#define METEOR_YUV_PACKED 0x00040000
#define METEOR_YUV_PLANAR 0x00080000
#define METEOR_WANT_EVEN 0x00100000
#define METEOR_WANT_ODD 0x00200000
#define METEOR_WANT_MASK 0x00300000
#define METEOR_ONLY_EVEN_FIELDS 0x01000000
#define METEOR_ONLY_ODD_FIELDS 0x02000000
#define METEOR_ONLY_FIELDS_MASK 0x03000000
#define METEOR_YUV_422 0x04000000
#define METEOR_OUTPUT_FMT_MASK 0x040f0000
#define METEOR_WANT_TS 0x08000000
#define METEOR_RGB 0x20000000
u_char tflags;
#define TUNER_INITIALIZED 0x00000001
#define TUNER_OPEN 0x00000002
u_char vbiflags;
#define VBI_INITIALIZED 0x00000001
#define VBI_OPEN 0x00000002
#define VBI_CAPTURE 0x00000004
u_short fps;
struct meteor_video video;
struct TVTUNER tuner;
struct CARDTYPE card;
u_char audio_mux_select;
u_char audio_mute_state;
u_char format_params;
u_int current_sol;
u_int current_col;
int clip_start;
int line_length;
int last_y;
int y;
int y2;
int yclip;
int yclip2;
int max_clip_node;
bktr_clip_t clip_list[100];
int reverse_mute;
int bt848_tuner;
int bt848_card;
u_int id;
#define BT848_USE_XTALS 0
#define BT848_USE_PLL 1
int xtal_pll_mode;
int remote_control;
int remote_control_addr;
char msp_version_string[9];
int msp_addr;
char dpl_version_string[9];
int dpl_addr;
int slow_msp_audio;
int msp_use_mono_source;
int audio_mux_present;
int msp_source_selected;
void *sih;
};
typedef struct bktr_softc bktr_reg_t;
typedef struct bktr_softc* bktr_ptr_t;
#define Bt848_MAX_SIGN 16
struct bt848_card_sig {
int card;
int tuner;
u_char signature[Bt848_MAX_SIGN];
};
typedef u_long ioctl_cmd_t;