2002-02-13 08:59:23 +00:00
|
|
|
/*
|
|
|
|
mach64_vid - VIDIX based video driver for Mach64 and 3DRage chips
|
|
|
|
Copyrights 2002 Nick Kurshev. This file is based on sources from
|
|
|
|
GATOS (gatos.sf.net) and X11 (www.xfree86.org)
|
|
|
|
Licence: GPL
|
2002-02-25 19:26:34 +00:00
|
|
|
WARNING: THIS DRIVER IS IN BETTA STAGE
|
2002-02-13 08:59:23 +00:00
|
|
|
*/
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "../vidix.h"
|
|
|
|
#include "../fourcc.h"
|
|
|
|
#include "../../libdha/libdha.h"
|
|
|
|
#include "../../libdha/pci_ids.h"
|
|
|
|
#include "../../libdha/pci_names.h"
|
|
|
|
|
|
|
|
#include "mach64.h"
|
|
|
|
|
|
|
|
#define UNUSED(x) ((void)(x)) /**< Removes warning about unused arguments */
|
|
|
|
|
|
|
|
static void *mach64_mmio_base = 0;
|
|
|
|
static void *mach64_mem_base = 0;
|
2002-02-16 07:55:44 +00:00
|
|
|
static int32_t mach64_overlay_offset = 0;
|
2002-02-13 08:59:23 +00:00
|
|
|
static uint32_t mach64_ram_size = 0;
|
2002-02-25 19:26:34 +00:00
|
|
|
static uint32_t mach64_buffer_base[10][3];
|
|
|
|
static int num_mach64_buffers=-1;
|
2002-02-27 14:57:33 +00:00
|
|
|
static int supports_planar=0;
|
2002-02-13 08:59:23 +00:00
|
|
|
|
|
|
|
pciinfo_t pci_info;
|
|
|
|
static int probed = 0;
|
|
|
|
static int __verbose = 0;
|
2002-02-16 07:55:44 +00:00
|
|
|
|
2002-02-19 16:23:02 +00:00
|
|
|
#define VERBOSE_LEVEL 1
|
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
typedef struct bes_registers_s
|
|
|
|
{
|
|
|
|
/* base address of yuv framebuffer */
|
|
|
|
uint32_t yuv_base;
|
|
|
|
uint32_t fourcc;
|
|
|
|
/* YUV BES registers */
|
|
|
|
uint32_t reg_load_cntl;
|
|
|
|
uint32_t scale_inc;
|
|
|
|
uint32_t y_x_start;
|
|
|
|
uint32_t y_x_end;
|
|
|
|
uint32_t vid_buf_pitch;
|
|
|
|
uint32_t height_width;
|
|
|
|
|
|
|
|
uint32_t scale_cntl;
|
|
|
|
uint32_t exclusive_horz;
|
|
|
|
uint32_t auto_flip_cntl;
|
|
|
|
uint32_t filter_cntl;
|
|
|
|
uint32_t key_cntl;
|
|
|
|
uint32_t test;
|
|
|
|
/* Configurable stuff */
|
|
|
|
|
|
|
|
int brightness;
|
|
|
|
int saturation;
|
|
|
|
|
|
|
|
int ckey_on;
|
|
|
|
uint32_t graphics_key_clr;
|
|
|
|
uint32_t graphics_key_msk;
|
|
|
|
|
|
|
|
int deinterlace_on;
|
|
|
|
uint32_t deinterlace_pattern;
|
|
|
|
|
|
|
|
} bes_registers_t;
|
|
|
|
|
|
|
|
static bes_registers_t besr;
|
|
|
|
|
|
|
|
typedef struct video_registers_s
|
|
|
|
{
|
|
|
|
const char * sname;
|
|
|
|
uint32_t name;
|
|
|
|
uint32_t value;
|
|
|
|
}video_registers_t;
|
|
|
|
|
|
|
|
static bes_registers_t besr;
|
2002-02-25 14:21:26 +00:00
|
|
|
|
|
|
|
/* Graphic keys */
|
|
|
|
static vidix_grkey_t mach64_grkey;
|
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
#define DECLARE_VREG(name) { #name, name, 0 }
|
|
|
|
static video_registers_t vregs[] =
|
|
|
|
{
|
|
|
|
DECLARE_VREG(OVERLAY_SCALE_INC),
|
|
|
|
DECLARE_VREG(OVERLAY_Y_X_START),
|
|
|
|
DECLARE_VREG(OVERLAY_Y_X_END),
|
|
|
|
DECLARE_VREG(OVERLAY_SCALE_CNTL),
|
|
|
|
DECLARE_VREG(OVERLAY_EXCLUSIVE_HORZ),
|
|
|
|
DECLARE_VREG(OVERLAY_EXCLUSIVE_VERT),
|
|
|
|
DECLARE_VREG(OVERLAY_TEST),
|
|
|
|
DECLARE_VREG(SCALER_BUF_PITCH),
|
|
|
|
DECLARE_VREG(SCALER_HEIGHT_WIDTH),
|
|
|
|
DECLARE_VREG(SCALER_BUF0_OFFSET),
|
|
|
|
DECLARE_VREG(SCALER_BUF0_OFFSET_U),
|
|
|
|
DECLARE_VREG(SCALER_BUF0_OFFSET_V),
|
|
|
|
DECLARE_VREG(SCALER_BUF1_OFFSET),
|
|
|
|
DECLARE_VREG(SCALER_BUF1_OFFSET_U),
|
|
|
|
DECLARE_VREG(SCALER_BUF1_OFFSET_V),
|
|
|
|
DECLARE_VREG(SCALER_H_COEFF0),
|
|
|
|
DECLARE_VREG(SCALER_H_COEFF1),
|
|
|
|
DECLARE_VREG(SCALER_H_COEFF2),
|
|
|
|
DECLARE_VREG(SCALER_H_COEFF3),
|
|
|
|
DECLARE_VREG(SCALER_H_COEFF4),
|
|
|
|
DECLARE_VREG(SCALER_COLOUR_CNTL),
|
|
|
|
DECLARE_VREG(SCALER_THRESHOLD),
|
|
|
|
DECLARE_VREG(VIDEO_FORMAT),
|
|
|
|
DECLARE_VREG(VIDEO_CONFIG),
|
|
|
|
DECLARE_VREG(VIDEO_SYNC_TEST),
|
|
|
|
DECLARE_VREG(VIDEO_SYNC_TEST_B)
|
|
|
|
};
|
|
|
|
|
2002-02-13 08:59:23 +00:00
|
|
|
/* VIDIX exports */
|
|
|
|
|
|
|
|
/* MMIO space*/
|
|
|
|
#define GETREG(TYPE,PTR,OFFZ) (*((volatile TYPE*)((PTR)+(OFFZ))))
|
|
|
|
#define SETREG(TYPE,PTR,OFFZ,VAL) (*((volatile TYPE*)((PTR)+(OFFZ))))=VAL
|
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
#define INREG8(addr) GETREG(uint8_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2)
|
|
|
|
#define OUTREG8(addr,val) SETREG(uint8_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2,val)
|
|
|
|
#define INREG(addr) GETREG(uint32_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2)
|
|
|
|
#define OUTREG(addr,val) SETREG(uint32_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2,val)
|
2002-02-13 08:59:23 +00:00
|
|
|
|
|
|
|
#define OUTREGP(addr,val,mask) \
|
|
|
|
do { \
|
|
|
|
unsigned int _tmp = INREG(addr); \
|
|
|
|
_tmp &= (mask); \
|
|
|
|
_tmp |= (val); \
|
|
|
|
OUTREG(addr, _tmp); \
|
|
|
|
} while (0)
|
|
|
|
|
2002-02-25 14:21:26 +00:00
|
|
|
static __inline__ int ATIGetMach64LCDReg(int _Index)
|
|
|
|
{
|
|
|
|
OUTREG8(LCD_INDEX, _Index);
|
|
|
|
return INREG(LCD_DATA);
|
|
|
|
}
|
|
|
|
|
2002-02-13 08:59:23 +00:00
|
|
|
static __inline__ uint32_t INPLL(uint32_t addr)
|
|
|
|
{
|
2002-02-16 07:55:44 +00:00
|
|
|
uint32_t res;
|
|
|
|
|
|
|
|
/* write addr byte */
|
|
|
|
OUTREG8(CLOCK_CNTL + 1, (addr << 2));
|
|
|
|
/* read the register value */
|
|
|
|
res = INREG(CLOCK_CNTL + 2);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ void OUTPLL(uint32_t addr,uint32_t val)
|
|
|
|
{
|
|
|
|
/* write addr byte */
|
|
|
|
OUTREG8(CLOCK_CNTL + 1, (addr << 2) | PLL_WR_EN);
|
|
|
|
/* write the register value */
|
|
|
|
OUTREG(CLOCK_CNTL + 2, val);
|
|
|
|
OUTREG8(CLOCK_CNTL + 1, (addr << 2) & ~PLL_WR_EN);
|
2002-02-13 08:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define OUTPLLP(addr,val,mask) \
|
|
|
|
do { \
|
|
|
|
unsigned int _tmp = INPLL(addr); \
|
|
|
|
_tmp &= (mask); \
|
|
|
|
_tmp |= (val); \
|
|
|
|
OUTPLL(addr, _tmp); \
|
|
|
|
} while (0)
|
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
static void mach64_fifo_wait(unsigned n)
|
|
|
|
{
|
|
|
|
while ((INREG(FIFO_STAT) & 0xffff) > ((uint32_t)(0x8000 >> n)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mach64_wait_for_idle( void )
|
|
|
|
{
|
|
|
|
mach64_fifo_wait(16);
|
|
|
|
while ((INREG(GUI_STAT) & 1)!= 0);
|
|
|
|
}
|
|
|
|
|
2002-02-27 14:57:33 +00:00
|
|
|
static void mach64_wait_vsync( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=0; i<2000000; i++)
|
|
|
|
if( (INREG(CRTC_INT_CNTL)&CRTC_VBLANK)==0 ) break;
|
|
|
|
for(i=0; i<2000000; i++)
|
|
|
|
if( (INREG(CRTC_INT_CNTL)&CRTC_VBLANK) ) break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-02-13 08:59:23 +00:00
|
|
|
static vidix_capability_t mach64_cap =
|
|
|
|
{
|
|
|
|
"BES driver for Mach64/3DRage cards",
|
2002-02-26 22:15:08 +00:00
|
|
|
"Nick Kurshev and Michael Niedermayer",
|
2002-02-13 08:59:23 +00:00
|
|
|
TYPE_OUTPUT,
|
|
|
|
{ 0, 0, 0, 0 },
|
|
|
|
2048,
|
|
|
|
2048,
|
|
|
|
4,
|
|
|
|
4,
|
|
|
|
-1,
|
|
|
|
FLAG_UPSCALER|FLAG_DOWNSCALER,
|
|
|
|
VENDOR_ATI,
|
|
|
|
-1,
|
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
static uint32_t mach64_vid_get_dbpp( void )
|
|
|
|
{
|
|
|
|
uint32_t dbpp,retval;
|
|
|
|
dbpp = (INREG(CRTC_GEN_CNTL)>>8)& 0x7;
|
|
|
|
switch(dbpp)
|
|
|
|
{
|
|
|
|
case 1: retval = 4; break;
|
|
|
|
case 2: retval = 8; break;
|
|
|
|
case 3: retval = 15; break;
|
|
|
|
case 4: retval = 16; break;
|
|
|
|
case 5: retval = 24; break;
|
|
|
|
default: retval=32; break;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mach64_is_dbl_scan( void )
|
|
|
|
{
|
|
|
|
return INREG(CRTC_GEN_CNTL) & CRTC_DBL_SCAN_EN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mach64_is_interlace( void )
|
|
|
|
{
|
|
|
|
return INREG(CRTC_GEN_CNTL) & CRTC_INTERLACE_EN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t mach64_get_xres( void )
|
|
|
|
{
|
|
|
|
/* FIXME: currently we extract that from CRTC!!!*/
|
|
|
|
uint32_t xres,h_total;
|
|
|
|
h_total = INREG(CRTC_H_TOTAL_DISP);
|
|
|
|
xres = (h_total >> 16) & 0xffff;
|
|
|
|
return (xres + 1)*8;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t mach64_get_yres( void )
|
|
|
|
{
|
|
|
|
/* FIXME: currently we extract that from CRTC!!!*/
|
|
|
|
uint32_t yres,v_total;
|
|
|
|
v_total = INREG(CRTC_V_TOTAL_DISP);
|
|
|
|
yres = (v_total >> 16) & 0xffff;
|
|
|
|
return yres + 1;
|
|
|
|
}
|
|
|
|
|
2002-02-25 14:21:26 +00:00
|
|
|
// returns the verical stretch factor in 16.16
|
|
|
|
static int mach64_get_vert_stretch(void)
|
|
|
|
{
|
|
|
|
int lcd_index;
|
|
|
|
int lcd_gen_ctrl;
|
|
|
|
int vert_stretching;
|
|
|
|
int ext_vert_stretch;
|
|
|
|
int ret;
|
|
|
|
int yres= mach64_get_yres();
|
|
|
|
|
|
|
|
//FIXME check for mobility & co
|
|
|
|
|
|
|
|
lcd_index= INREG(LCD_INDEX);
|
|
|
|
|
|
|
|
vert_stretching= ATIGetMach64LCDReg(LCD_VERT_STRETCHING);
|
|
|
|
if(!(vert_stretching&VERT_STRETCH_EN)) ret= 1<<16;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int panel_size;
|
|
|
|
|
|
|
|
ext_vert_stretch= ATIGetMach64LCDReg(LCD_EXT_VERT_STRETCH);
|
|
|
|
panel_size= (ext_vert_stretch&VERT_PANEL_SIZE)>>11;
|
|
|
|
panel_size++;
|
|
|
|
|
|
|
|
ret= ((yres<<16) + (panel_size>>1))/panel_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
// lcd_gen_ctrl = ATIGetMach64LCDReg(LCD_GEN_CNTL);
|
|
|
|
|
|
|
|
OUTREG(LCD_INDEX, lcd_index);
|
|
|
|
|
2002-02-26 22:15:08 +00:00
|
|
|
if(__verbose>VERBOSE_LEVEL) printf("[mach64] vertical stretching factor= %d\n", ret);
|
|
|
|
|
2002-02-25 14:21:26 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
static void mach64_vid_make_default()
|
|
|
|
{
|
2002-02-26 22:15:08 +00:00
|
|
|
mach64_fifo_wait(5);
|
2002-02-20 00:19:47 +00:00
|
|
|
OUTREG(SCALER_COLOUR_CNTL,0x00101000);
|
2002-02-26 22:15:08 +00:00
|
|
|
|
|
|
|
besr.ckey_on=0;
|
|
|
|
besr.graphics_key_msk=0;
|
|
|
|
besr.graphics_key_clr=0;
|
|
|
|
|
|
|
|
OUTREG(OVERLAY_GRAPHICS_KEY_MSK, besr.graphics_key_msk);
|
|
|
|
OUTREG(OVERLAY_GRAPHICS_KEY_CLR, besr.graphics_key_clr);
|
|
|
|
OUTREG(OVERLAY_KEY_CNTL,VIDEO_KEY_FN_TRUE|GRAPHIC_KEY_FN_EQ|CMP_MIX_AND);
|
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mach64_vid_dump_regs( void )
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
printf("[mach64] *** Begin of DRIVER variables dump ***\n");
|
|
|
|
printf("[mach64] mach64_mmio_base=%p\n",mach64_mmio_base);
|
|
|
|
printf("[mach64] mach64_mem_base=%p\n",mach64_mem_base);
|
|
|
|
printf("[mach64] mach64_overlay_off=%08X\n",mach64_overlay_offset);
|
|
|
|
printf("[mach64] mach64_ram_size=%08X\n",mach64_ram_size);
|
|
|
|
printf("[mach64] video mode: %ux%u@%u\n",mach64_get_xres(),mach64_get_yres(),mach64_vid_get_dbpp());
|
|
|
|
printf("[mach64] *** Begin of OV0 registers dump ***\n");
|
|
|
|
for(i=0;i<sizeof(vregs)/sizeof(video_registers_t);i++)
|
|
|
|
{
|
|
|
|
mach64_wait_for_idle();
|
|
|
|
printf("[mach64] %s = %08X\n",vregs[i].sname,INREG(vregs[i].name));
|
|
|
|
}
|
|
|
|
printf("[mach64] *** End of OV0 registers dump ***\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-13 08:59:23 +00:00
|
|
|
unsigned int vixGetVersion(void)
|
|
|
|
{
|
|
|
|
return(VIDIX_VERSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned short ati_card_ids[] =
|
|
|
|
{
|
|
|
|
DEVICE_ATI_215CT_MACH64_CT,
|
|
|
|
DEVICE_ATI_210888CX_MACH64_CX,
|
|
|
|
DEVICE_ATI_210888ET_MACH64_ET,
|
|
|
|
DEVICE_ATI_MACH64_VT,
|
|
|
|
DEVICE_ATI_210888GX_MACH64_GX,
|
|
|
|
DEVICE_ATI_264LT_MACH64_LT,
|
|
|
|
DEVICE_ATI_264VT_MACH64_VT,
|
|
|
|
DEVICE_ATI_264VT3_MACH64_VT3,
|
|
|
|
DEVICE_ATI_264VT4_MACH64_VT4,
|
|
|
|
/**/
|
|
|
|
DEVICE_ATI_3D_RAGE_PRO,
|
|
|
|
DEVICE_ATI_3D_RAGE_PRO2,
|
|
|
|
DEVICE_ATI_3D_RAGE_PRO3,
|
|
|
|
DEVICE_ATI_3D_RAGE_PRO4,
|
|
|
|
DEVICE_ATI_RAGE_XC,
|
|
|
|
DEVICE_ATI_RAGE_XL_AGP,
|
|
|
|
DEVICE_ATI_RAGE_XC_AGP,
|
|
|
|
DEVICE_ATI_RAGE_XL,
|
|
|
|
DEVICE_ATI_3D_RAGE_PRO5,
|
|
|
|
DEVICE_ATI_3D_RAGE_PRO6,
|
|
|
|
DEVICE_ATI_RAGE_XL2,
|
|
|
|
DEVICE_ATI_RAGE_XC2,
|
|
|
|
DEVICE_ATI_3D_RAGE_I_II,
|
|
|
|
DEVICE_ATI_3D_RAGE_II,
|
|
|
|
DEVICE_ATI_3D_RAGE_IIC,
|
|
|
|
DEVICE_ATI_3D_RAGE_IIC2,
|
|
|
|
DEVICE_ATI_3D_RAGE_IIC3,
|
|
|
|
DEVICE_ATI_3D_RAGE_IIC4,
|
|
|
|
DEVICE_ATI_3D_RAGE_LT,
|
|
|
|
DEVICE_ATI_3D_RAGE_LT2,
|
|
|
|
DEVICE_ATI_3D_RAGE_LT_G,
|
|
|
|
DEVICE_ATI_3D_RAGE_LT3,
|
|
|
|
DEVICE_ATI_RAGE_MOBILITY_P_M,
|
|
|
|
DEVICE_ATI_RAGE_MOBILITY_L,
|
|
|
|
DEVICE_ATI_3D_RAGE_LT4,
|
|
|
|
DEVICE_ATI_3D_RAGE_LT5,
|
|
|
|
DEVICE_ATI_RAGE_MOBILITY_P_M2,
|
|
|
|
DEVICE_ATI_RAGE_MOBILITY_L2
|
|
|
|
};
|
|
|
|
|
|
|
|
static int find_chip(unsigned chip_id)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for(i = 0;i < sizeof(ati_card_ids)/sizeof(unsigned short);i++)
|
|
|
|
{
|
|
|
|
if(chip_id == ati_card_ids[i]) return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vixProbe(int verbose,int force)
|
|
|
|
{
|
|
|
|
pciinfo_t lst[MAX_PCI_DEVICES];
|
|
|
|
unsigned i,num_pci;
|
|
|
|
int err;
|
|
|
|
__verbose = verbose;
|
|
|
|
err = pci_scan(lst,&num_pci);
|
|
|
|
if(err)
|
|
|
|
{
|
|
|
|
printf("[mach64] Error occured during pci scan: %s\n",strerror(err));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
err = ENXIO;
|
|
|
|
for(i=0;i<num_pci;i++)
|
|
|
|
{
|
|
|
|
if(lst[i].vendor == VENDOR_ATI)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
const char *dname;
|
|
|
|
idx = find_chip(lst[i].device);
|
|
|
|
if(idx == -1 && force == PROBE_NORMAL) continue;
|
|
|
|
dname = pci_device_name(VENDOR_ATI,lst[i].device);
|
|
|
|
dname = dname ? dname : "Unknown chip";
|
|
|
|
printf("[mach64] Found chip: %s\n",dname);
|
|
|
|
if(force > PROBE_NORMAL)
|
|
|
|
{
|
|
|
|
printf("[mach64] Driver was forced. Was found %sknown chip\n",idx == -1 ? "un" : "");
|
|
|
|
if(idx == -1)
|
|
|
|
printf("[mach64] Assuming it as Mach64\n");
|
|
|
|
}
|
|
|
|
mach64_cap.device_id = lst[i].device;
|
|
|
|
err = 0;
|
|
|
|
memcpy(&pci_info,&lst[i],sizeof(pciinfo_t));
|
|
|
|
probed=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(err && verbose) printf("[mach64] Can't find chip\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
static void reset_regs( void )
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for(i=0;i<sizeof(vregs)/sizeof(video_registers_t);i++)
|
|
|
|
{
|
|
|
|
mach64_fifo_wait(2);
|
2002-02-19 16:23:02 +00:00
|
|
|
OUTREG(vregs[i].name,0);
|
2002-02-16 07:55:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-13 08:59:23 +00:00
|
|
|
int vixInit(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
if(!probed)
|
|
|
|
{
|
|
|
|
printf("[mach64] Driver was not probed but is being initializing\n");
|
|
|
|
return EINTR;
|
|
|
|
}
|
2002-02-16 07:55:44 +00:00
|
|
|
if((mach64_mmio_base = map_phys_mem(pci_info.base2,0x4000))==(void *)-1) return ENOMEM;
|
|
|
|
mach64_wait_for_idle();
|
2002-02-13 08:59:23 +00:00
|
|
|
mach64_ram_size = INREG(MEM_CNTL) & CTL_MEM_SIZEB;
|
|
|
|
if (mach64_ram_size < 8) mach64_ram_size = (mach64_ram_size + 1) * 512;
|
|
|
|
else if (mach64_ram_size < 12) mach64_ram_size = (mach64_ram_size - 3) * 1024;
|
|
|
|
else mach64_ram_size = (mach64_ram_size - 7) * 2048;
|
|
|
|
mach64_ram_size *= 0x400; /* KB -> bytes */
|
|
|
|
if((mach64_mem_base = map_phys_mem(pci_info.base0,mach64_ram_size))==(void *)-1) return ENOMEM;
|
2002-02-19 16:23:02 +00:00
|
|
|
memset(&besr,0,sizeof(bes_registers_t));
|
2002-02-13 08:59:23 +00:00
|
|
|
printf("[mach64] Video memory = %uMb\n",mach64_ram_size/0x100000);
|
|
|
|
err = mtrr_set_type(pci_info.base0,mach64_ram_size,MTRR_TYPE_WRCOMB);
|
|
|
|
if(!err) printf("[mach64] Set write-combining type of video memory\n");
|
2002-02-27 14:57:33 +00:00
|
|
|
|
|
|
|
/* check if planar formats are supported */
|
|
|
|
supports_planar=0;
|
|
|
|
mach64_wait_for_idle();
|
|
|
|
mach64_fifo_wait(2);
|
|
|
|
if(INREG(SCALER_BUF0_OFFSET_U)) supports_planar=1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OUTREG(SCALER_BUF0_OFFSET_U, -1);
|
|
|
|
|
|
|
|
mach64_wait_vsync();
|
|
|
|
mach64_wait_for_idle();
|
|
|
|
mach64_fifo_wait(2);
|
|
|
|
|
|
|
|
if(INREG(SCALER_BUF0_OFFSET_U)) supports_planar=1;
|
|
|
|
}
|
|
|
|
if(supports_planar) printf("[mach64] Planar YUV formats are supported :)\n");
|
|
|
|
else printf("[mach64] Planar YUV formats are not supported :(\n");
|
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
reset_regs();
|
2002-02-20 00:19:47 +00:00
|
|
|
mach64_vid_make_default();
|
2002-02-27 14:57:33 +00:00
|
|
|
|
2002-02-19 16:23:02 +00:00
|
|
|
if(__verbose > VERBOSE_LEVEL) mach64_vid_dump_regs();
|
2002-02-13 08:59:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vixDestroy(void)
|
|
|
|
{
|
|
|
|
unmap_phys_mem(mach64_mem_base,mach64_ram_size);
|
2002-02-16 07:55:44 +00:00
|
|
|
unmap_phys_mem(mach64_mmio_base,0x4000);
|
2002-02-13 08:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int vixGetCapability(vidix_capability_t *to)
|
|
|
|
{
|
|
|
|
memcpy(to, &mach64_cap, sizeof(vidix_capability_t));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
static unsigned mach64_query_pitch(unsigned fourcc,const vidix_yuv_t *spitch)
|
|
|
|
{
|
|
|
|
unsigned pitch,spy,spv,spu;
|
|
|
|
spy = spv = spu = 0;
|
|
|
|
switch(spitch->y)
|
|
|
|
{
|
|
|
|
case 16:
|
|
|
|
case 32:
|
|
|
|
case 64:
|
|
|
|
case 128:
|
|
|
|
case 256: spy = spitch->y; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
switch(spitch->u)
|
|
|
|
{
|
|
|
|
case 16:
|
|
|
|
case 32:
|
|
|
|
case 64:
|
|
|
|
case 128:
|
|
|
|
case 256: spu = spitch->u; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
switch(spitch->v)
|
|
|
|
{
|
|
|
|
case 16:
|
|
|
|
case 32:
|
|
|
|
case 64:
|
|
|
|
case 128:
|
|
|
|
case 256: spv = spitch->v; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
switch(fourcc)
|
|
|
|
{
|
|
|
|
/* 4:2:0 */
|
|
|
|
case IMGFMT_IYUV:
|
|
|
|
case IMGFMT_YV12:
|
|
|
|
case IMGFMT_I420:
|
|
|
|
if(spy > 16 && spu == spy/2 && spv == spy/2) pitch = spy;
|
|
|
|
else pitch = 32;
|
|
|
|
break;
|
2002-02-26 22:15:08 +00:00
|
|
|
case IMGFMT_YVU9:
|
|
|
|
if(spy > 32 && spu == spy/4 && spv == spy/4) pitch = spy;
|
|
|
|
else pitch = 64;
|
|
|
|
break;
|
2002-02-16 07:55:44 +00:00
|
|
|
default:
|
2002-02-16 08:20:24 +00:00
|
|
|
if(spy >= 16) pitch = spy;
|
|
|
|
else pitch = 16;
|
2002-02-16 07:55:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mach64_compute_framesize(vidix_playback_t *info)
|
|
|
|
{
|
|
|
|
unsigned pitch,awidth;
|
|
|
|
pitch = mach64_query_pitch(info->fourcc,&info->src.pitch);
|
|
|
|
switch(info->fourcc)
|
|
|
|
{
|
|
|
|
case IMGFMT_I420:
|
|
|
|
case IMGFMT_YV12:
|
|
|
|
case IMGFMT_IYUV:
|
|
|
|
awidth = (info->src.w + (pitch-1)) & ~(pitch-1);
|
|
|
|
info->frame_size = awidth*(info->src.h+info->src.h/2);
|
|
|
|
break;
|
2002-02-26 22:15:08 +00:00
|
|
|
case IMGFMT_YVU9:
|
|
|
|
awidth = (info->src.w + (pitch-1)) & ~(pitch-1);
|
|
|
|
info->frame_size = awidth*(info->src.h+info->src.h/8);
|
|
|
|
break;
|
|
|
|
// case IMGFMT_RGB32:
|
2002-02-16 07:55:44 +00:00
|
|
|
case IMGFMT_BGR32:
|
|
|
|
awidth = (info->src.w*4 + (pitch-1)) & ~(pitch-1);
|
|
|
|
info->frame_size = (awidth*info->src.h);
|
|
|
|
break;
|
|
|
|
/* YUY2 YVYU, RGB15, RGB16 */
|
|
|
|
default:
|
|
|
|
awidth = (info->src.w*2 + (pitch-1)) & ~(pitch-1);
|
|
|
|
info->frame_size = (awidth*info->src.h);
|
|
|
|
break;
|
|
|
|
}
|
2002-02-26 22:15:08 +00:00
|
|
|
info->frame_size+=256; // so we have some space for alignment & such
|
|
|
|
info->frame_size&=~16;
|
2002-02-16 07:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mach64_vid_stop_video( void )
|
|
|
|
{
|
|
|
|
mach64_fifo_wait(14);
|
|
|
|
OUTREG(OVERLAY_SCALE_CNTL, 0x80000000);
|
|
|
|
OUTREG(OVERLAY_EXCLUSIVE_HORZ, 0);
|
|
|
|
OUTREG(OVERLAY_EXCLUSIVE_VERT, 0);
|
|
|
|
OUTREG(SCALER_H_COEFF0, 0x00002000);
|
|
|
|
OUTREG(SCALER_H_COEFF1, 0x0D06200D);
|
|
|
|
OUTREG(SCALER_H_COEFF2, 0x0D0A1C0D);
|
|
|
|
OUTREG(SCALER_H_COEFF3, 0x0C0E1A0C);
|
|
|
|
OUTREG(SCALER_H_COEFF4, 0x0C14140C);
|
|
|
|
OUTREG(VIDEO_FORMAT, 0xB000B);
|
|
|
|
OUTREG(OVERLAY_TEST, 0x0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mach64_vid_display_video( void )
|
|
|
|
{
|
|
|
|
uint32_t vf;
|
|
|
|
mach64_fifo_wait(14);
|
|
|
|
|
|
|
|
OUTREG(OVERLAY_Y_X_START, besr.y_x_start);
|
|
|
|
OUTREG(OVERLAY_Y_X_END, besr.y_x_end);
|
|
|
|
OUTREG(OVERLAY_SCALE_INC, besr.scale_inc);
|
|
|
|
OUTREG(SCALER_BUF_PITCH, besr.vid_buf_pitch);
|
|
|
|
OUTREG(SCALER_HEIGHT_WIDTH, besr.height_width);
|
2002-02-25 19:26:34 +00:00
|
|
|
OUTREG(SCALER_BUF0_OFFSET, mach64_buffer_base[0][0]);
|
|
|
|
OUTREG(SCALER_BUF0_OFFSET_U, mach64_buffer_base[0][1]);
|
|
|
|
OUTREG(SCALER_BUF0_OFFSET_V, mach64_buffer_base[0][2]);
|
|
|
|
OUTREG(SCALER_BUF1_OFFSET, mach64_buffer_base[0][0]);
|
|
|
|
OUTREG(SCALER_BUF1_OFFSET_U, mach64_buffer_base[0][1]);
|
|
|
|
OUTREG(SCALER_BUF1_OFFSET_V, mach64_buffer_base[0][2]);
|
2002-02-27 14:57:33 +00:00
|
|
|
mach64_wait_vsync();
|
|
|
|
|
|
|
|
mach64_fifo_wait(4);
|
2002-02-19 16:23:02 +00:00
|
|
|
OUTREG(OVERLAY_SCALE_CNTL, 0xC4000003);
|
2002-02-19 20:54:58 +00:00
|
|
|
// OVERLAY_SCALE_CNTL bits & what they seem to affect
|
|
|
|
// bit 0 no effect
|
|
|
|
// bit 1 yuv2rgb coeff related
|
|
|
|
// bit 2 horizontal interpolation if 0
|
|
|
|
// bit 3 vertical interpolation if 0
|
2002-02-24 18:31:14 +00:00
|
|
|
// bit 4 chroma encoding (0-> 128=neutral / 1-> 0->neutral)
|
2002-02-19 20:54:58 +00:00
|
|
|
// bit 5-6 gamma correction
|
|
|
|
// bit 7 nothing visible if set
|
|
|
|
// bit 8-27 no effect
|
|
|
|
// bit 28-31 nothing interresting just crashed my system when i played with them :(
|
2002-02-24 18:31:14 +00:00
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
mach64_wait_for_idle();
|
|
|
|
vf = INREG(VIDEO_FORMAT);
|
2002-02-17 22:40:31 +00:00
|
|
|
|
|
|
|
// Bits 16-19 seem to select the format
|
2002-02-20 17:23:00 +00:00
|
|
|
// 0x0 dunno behaves strange
|
|
|
|
// 0x1 dunno behaves strange
|
|
|
|
// 0x2 dunno behaves strange
|
|
|
|
// 0x3 BGR15
|
|
|
|
// 0x4 BGR16
|
|
|
|
// 0x5 BGR16 (hmm, that need investigation, 2 BGR16 formats, i guess 1 will have only 5bits for green)
|
|
|
|
// 0x6 BGR32
|
|
|
|
// 0x7 BGR32 with somehow mixed even / odd pixels ?
|
|
|
|
// 0x8 YYYYUVUV
|
|
|
|
// 0x9 YVU9
|
|
|
|
// 0xA YV12
|
|
|
|
// 0xB YUY2
|
|
|
|
// 0xC UYVY
|
2002-02-24 18:31:14 +00:00
|
|
|
// 0xD UYVY (no difference is visible if i switch between C/D for every even/odd frame)
|
2002-02-20 17:23:00 +00:00
|
|
|
// 0xE dunno behaves strange
|
|
|
|
// 0xF dunno behaves strange
|
|
|
|
// Bit 28 all values are assumed to be 7 bit with chroma=64 for black (tested with YV12 & YUY2)
|
2002-02-17 22:40:31 +00:00
|
|
|
// the remaining bits seem to have no effect
|
|
|
|
|
2002-02-20 17:23:00 +00:00
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
switch(besr.fourcc)
|
|
|
|
{
|
2002-02-20 17:23:00 +00:00
|
|
|
/* BGR formats */
|
|
|
|
case IMGFMT_BGR15: OUTREG(VIDEO_FORMAT, 0x00030000); break;
|
|
|
|
case IMGFMT_BGR16: OUTREG(VIDEO_FORMAT, 0x00040000); break;
|
|
|
|
case IMGFMT_BGR32: OUTREG(VIDEO_FORMAT, 0x00060000); break;
|
2002-02-16 07:55:44 +00:00
|
|
|
/* 4:2:0 */
|
|
|
|
case IMGFMT_IYUV:
|
|
|
|
case IMGFMT_I420:
|
2002-02-20 17:23:00 +00:00
|
|
|
case IMGFMT_YV12: OUTREG(VIDEO_FORMAT, 0x000A0000); break;
|
2002-02-26 22:15:08 +00:00
|
|
|
|
|
|
|
case IMGFMT_YVU9: OUTREG(VIDEO_FORMAT, 0x00090000); break;
|
2002-02-16 07:55:44 +00:00
|
|
|
/* 4:2:2 */
|
|
|
|
case IMGFMT_YVYU:
|
2002-02-20 17:23:00 +00:00
|
|
|
case IMGFMT_UYVY: OUTREG(VIDEO_FORMAT, 0x000C0000); break;
|
2002-02-16 07:55:44 +00:00
|
|
|
case IMGFMT_YUY2:
|
2002-02-20 17:23:00 +00:00
|
|
|
default: OUTREG(VIDEO_FORMAT, 0x000B0000); break;
|
2002-02-16 07:55:44 +00:00
|
|
|
}
|
2002-02-19 16:23:02 +00:00
|
|
|
if(__verbose > VERBOSE_LEVEL) mach64_vid_dump_regs();
|
2002-02-16 07:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mach64_vid_init_video( vidix_playback_t *config )
|
|
|
|
{
|
2002-02-19 16:23:02 +00:00
|
|
|
uint32_t src_w,src_h,dest_w,dest_h,pitch,h_inc,v_inc,left,leftUV,top,ecp,y_pos;
|
2002-02-16 07:55:44 +00:00
|
|
|
int is_420,best_pitch,mpitch;
|
2002-02-25 19:26:34 +00:00
|
|
|
int src_offset_y, src_offset_u, src_offset_v;
|
|
|
|
unsigned int i;
|
2002-02-26 22:15:08 +00:00
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
mach64_vid_stop_video();
|
2002-02-25 19:26:34 +00:00
|
|
|
/* warning, if left or top are != 0 this will fail, as the framesize is too small then */
|
|
|
|
left = config->src.x;
|
|
|
|
top = config->src.y;
|
2002-02-16 07:55:44 +00:00
|
|
|
src_h = config->src.h;
|
|
|
|
src_w = config->src.w;
|
|
|
|
is_420 = 0;
|
|
|
|
if(config->fourcc == IMGFMT_YV12 ||
|
|
|
|
config->fourcc == IMGFMT_I420 ||
|
|
|
|
config->fourcc == IMGFMT_IYUV) is_420 = 1;
|
|
|
|
best_pitch = mach64_query_pitch(config->fourcc,&config->src.pitch);
|
|
|
|
mpitch = best_pitch-1;
|
|
|
|
switch(config->fourcc)
|
|
|
|
{
|
2002-02-26 22:15:08 +00:00
|
|
|
case IMGFMT_YVU9:
|
2002-02-16 07:55:44 +00:00
|
|
|
/* 4:2:0 */
|
|
|
|
case IMGFMT_IYUV:
|
|
|
|
case IMGFMT_YV12:
|
|
|
|
case IMGFMT_I420: pitch = (src_w + mpitch) & ~mpitch;
|
|
|
|
config->dest.pitch.y =
|
|
|
|
config->dest.pitch.u =
|
|
|
|
config->dest.pitch.v = best_pitch;
|
2002-02-20 17:23:00 +00:00
|
|
|
besr.vid_buf_pitch= pitch;
|
2002-02-16 07:55:44 +00:00
|
|
|
break;
|
|
|
|
/* RGB 4:4:4:4 */
|
|
|
|
case IMGFMT_RGB32:
|
|
|
|
case IMGFMT_BGR32: pitch = (src_w*4 + mpitch) & ~mpitch;
|
|
|
|
config->dest.pitch.y =
|
|
|
|
config->dest.pitch.u =
|
|
|
|
config->dest.pitch.v = best_pitch;
|
2002-02-20 17:23:00 +00:00
|
|
|
besr.vid_buf_pitch= pitch>>2;
|
2002-02-16 07:55:44 +00:00
|
|
|
break;
|
|
|
|
/* 4:2:2 */
|
|
|
|
default: /* RGB15, RGB16, YVYU, UYVY, YUY2 */
|
|
|
|
pitch = ((src_w*2) + mpitch) & ~mpitch;
|
|
|
|
config->dest.pitch.y =
|
|
|
|
config->dest.pitch.u =
|
|
|
|
config->dest.pitch.v = best_pitch;
|
2002-02-20 17:23:00 +00:00
|
|
|
besr.vid_buf_pitch= pitch>>1;
|
2002-02-16 07:55:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
dest_w = config->dest.w;
|
|
|
|
dest_h = config->dest.h;
|
|
|
|
besr.fourcc = config->fourcc;
|
|
|
|
ecp = (INPLL(PLL_VCLK_CNTL) & PLL_ECP_DIV) >> 4;
|
2002-02-25 14:21:26 +00:00
|
|
|
v_inc = src_h * mach64_get_vert_stretch();
|
|
|
|
|
|
|
|
if(mach64_is_interlace()) v_inc<<=1;
|
|
|
|
if(mach64_is_dbl_scan() ) v_inc>>=1;
|
|
|
|
v_inc>>=4; // convert 16.16 -> 20.12
|
|
|
|
v_inc/= dest_h;
|
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
h_inc = (src_w << (12+ecp)) / dest_w;
|
|
|
|
/* keep everything in 16.16 */
|
|
|
|
config->offsets[0] = 0;
|
2002-02-25 19:26:34 +00:00
|
|
|
for(i=1; i<config->num_frames; i++)
|
|
|
|
config->offsets[i] = config->offsets[i-1] + config->frame_size;
|
|
|
|
|
2002-02-26 22:15:08 +00:00
|
|
|
/*FIXME the left / top stuff is broken (= zoom a src rectangle from a larger one)
|
|
|
|
1. the framesize isnt known as the outer src rectangle dimensions arent known
|
|
|
|
2. the mach64 needs aligned addresses so it cant work anyway
|
|
|
|
-> so we could shift the outer buffer to compensate that but that would mean
|
|
|
|
alignment problems for the code which writes into it
|
|
|
|
*/
|
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
if(is_420)
|
|
|
|
{
|
2002-02-25 19:26:34 +00:00
|
|
|
config->offset.y= 0;
|
2002-02-26 22:15:08 +00:00
|
|
|
config->offset.u= (pitch*src_h + 15)&~15;
|
|
|
|
config->offset.v= (config->offset.u + (pitch*src_h>>2) + 15)&~15;
|
|
|
|
|
2002-02-25 19:26:34 +00:00
|
|
|
src_offset_y= config->offset.y + top*pitch + left;
|
|
|
|
src_offset_u= config->offset.u + (top*pitch>>2) + (left>>1);
|
|
|
|
src_offset_v= config->offset.v + (top*pitch>>2) + (left>>1);
|
2002-02-26 22:15:08 +00:00
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
if(besr.fourcc == IMGFMT_I420 || besr.fourcc == IMGFMT_IYUV)
|
|
|
|
{
|
|
|
|
uint32_t tmp;
|
|
|
|
tmp = config->offset.u;
|
|
|
|
config->offset.u = config->offset.v;
|
|
|
|
config->offset.v = tmp;
|
|
|
|
}
|
|
|
|
}
|
2002-02-26 22:15:08 +00:00
|
|
|
else if(besr.fourcc == IMGFMT_YVU9)
|
|
|
|
{
|
|
|
|
config->offset.y= 0;
|
|
|
|
config->offset.u= (pitch*src_h + 15)&~15;
|
|
|
|
config->offset.v= (config->offset.u + (pitch*src_h>>4) + 15)&~15;
|
|
|
|
|
|
|
|
src_offset_y= config->offset.y + top*pitch + left;
|
|
|
|
src_offset_u= config->offset.u + (top*pitch>>4) + (left>>1);
|
|
|
|
src_offset_v= config->offset.v + (top*pitch>>4) + (left>>1);
|
|
|
|
}
|
2002-02-25 19:26:34 +00:00
|
|
|
else if(besr.fourcc == IMGFMT_BGR32)
|
|
|
|
{
|
|
|
|
config->offset.y = config->offset.u = config->offset.v = 0;
|
2002-02-26 22:15:08 +00:00
|
|
|
src_offset_y= src_offset_u= src_offset_v= top*pitch + (left << 2);
|
2002-02-25 19:26:34 +00:00
|
|
|
}
|
2002-02-16 07:55:44 +00:00
|
|
|
else
|
|
|
|
{
|
2002-02-25 19:26:34 +00:00
|
|
|
config->offset.y = config->offset.u = config->offset.v = 0;
|
2002-02-26 22:15:08 +00:00
|
|
|
src_offset_y= src_offset_u= src_offset_v= top*pitch + (left << 1);
|
2002-02-25 19:26:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
num_mach64_buffers= config->num_frames;
|
|
|
|
for(i=0; i<config->num_frames; i++)
|
|
|
|
{
|
|
|
|
mach64_buffer_base[i][0]= (mach64_overlay_offset + config->offsets[i] + src_offset_y)&~15;
|
|
|
|
mach64_buffer_base[i][1]= (mach64_overlay_offset + config->offsets[i] + src_offset_u)&~15;
|
|
|
|
mach64_buffer_base[i][2]= (mach64_overlay_offset + config->offsets[i] + src_offset_v)&~15;
|
2002-02-16 07:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
leftUV = (left >> 17) & 15;
|
|
|
|
left = (left >> 16) & 15;
|
|
|
|
besr.scale_inc = ( h_inc << 16 ) | v_inc;
|
2002-02-19 16:23:02 +00:00
|
|
|
y_pos = config->dest.y;
|
|
|
|
if(mach64_is_dbl_scan()) y_pos*=2;
|
|
|
|
else
|
|
|
|
if(mach64_is_interlace()) y_pos/=2;
|
|
|
|
besr.y_x_start = y_pos | (config->dest.x << 16);
|
|
|
|
y_pos =config->dest.y + dest_h;
|
|
|
|
if(mach64_is_dbl_scan()) y_pos*=2;
|
|
|
|
else
|
|
|
|
if(mach64_is_interlace()) y_pos/=2;
|
|
|
|
besr.y_x_end = y_pos | ((config->dest.x + dest_w) << 16);
|
2002-02-16 07:55:44 +00:00
|
|
|
besr.height_width = ((src_w - left)<<16) | (src_h - top);
|
2002-02-20 17:23:00 +00:00
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-02-27 14:57:33 +00:00
|
|
|
static int is_supported_fourcc(uint32_t fourcc)
|
2002-02-16 07:55:44 +00:00
|
|
|
{
|
2002-02-27 14:57:33 +00:00
|
|
|
switch(fourcc)
|
|
|
|
{
|
|
|
|
case IMGFMT_YV12:
|
|
|
|
case IMGFMT_I420:
|
|
|
|
case IMGFMT_YVU9:
|
|
|
|
case IMGFMT_IYUV:
|
|
|
|
return supports_planar;
|
|
|
|
case IMGFMT_YUY2:
|
|
|
|
case IMGFMT_UYVY:
|
|
|
|
case IMGFMT_BGR15:
|
|
|
|
case IMGFMT_BGR16:
|
|
|
|
case IMGFMT_BGR32:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2002-02-16 07:55:44 +00:00
|
|
|
}
|
|
|
|
|
2002-02-13 08:59:23 +00:00
|
|
|
int vixQueryFourcc(vidix_fourcc_t *to)
|
|
|
|
{
|
2002-02-16 07:55:44 +00:00
|
|
|
if(is_supported_fourcc(to->fourcc))
|
|
|
|
{
|
|
|
|
to->depth = VID_DEPTH_1BPP | VID_DEPTH_2BPP |
|
|
|
|
VID_DEPTH_4BPP | VID_DEPTH_8BPP |
|
|
|
|
VID_DEPTH_12BPP| VID_DEPTH_15BPP|
|
|
|
|
VID_DEPTH_16BPP| VID_DEPTH_24BPP|
|
|
|
|
VID_DEPTH_32BPP;
|
2002-02-25 14:21:26 +00:00
|
|
|
to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY;
|
2002-02-16 07:55:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else to->depth = to->flags = 0;
|
2002-02-13 08:59:23 +00:00
|
|
|
return ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vixConfigPlayback(vidix_playback_t *info)
|
|
|
|
{
|
2002-02-16 07:55:44 +00:00
|
|
|
if(!is_supported_fourcc(info->fourcc)) return ENOSYS;
|
2002-02-25 19:26:34 +00:00
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
mach64_compute_framesize(info);
|
2002-02-28 16:20:58 +00:00
|
|
|
|
|
|
|
if(info->num_frames>4) info->num_frames=4;
|
|
|
|
for(;info->num_frames>0; info->num_frames--)
|
|
|
|
{
|
|
|
|
mach64_overlay_offset = mach64_ram_size - info->frame_size*info->num_frames;
|
|
|
|
mach64_overlay_offset &= 0xffff0000;
|
|
|
|
if(mach64_overlay_offset>0) break;
|
|
|
|
}
|
|
|
|
if(info->num_frames <= 0) return EINVAL;
|
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
info->dga_addr = (char *)mach64_mem_base + mach64_overlay_offset;
|
|
|
|
mach64_vid_init_video(info);
|
|
|
|
return 0;
|
2002-02-13 08:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int vixPlaybackOn(void)
|
|
|
|
{
|
2002-02-16 07:55:44 +00:00
|
|
|
mach64_vid_display_video();
|
|
|
|
return 0;
|
2002-02-13 08:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int vixPlaybackOff(void)
|
|
|
|
{
|
2002-02-16 07:55:44 +00:00
|
|
|
mach64_vid_stop_video();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-02-13 08:59:23 +00:00
|
|
|
int vixPlaybackFrameSelect(unsigned int frame)
|
|
|
|
{
|
2002-02-16 07:55:44 +00:00
|
|
|
uint32_t off[6];
|
2002-02-25 19:26:34 +00:00
|
|
|
int i;
|
|
|
|
int last_frame= (frame-1+num_mach64_buffers) % num_mach64_buffers;
|
|
|
|
//printf("Selecting frame %d\n", frame);
|
2002-02-16 07:55:44 +00:00
|
|
|
/*
|
|
|
|
buf3-5 always should point onto second buffer for better
|
|
|
|
deinterlacing and TV-in
|
|
|
|
*/
|
2002-02-25 19:26:34 +00:00
|
|
|
if(num_mach64_buffers==1) return 0;
|
|
|
|
|
|
|
|
for(i=0; i<3; i++)
|
2002-02-16 07:55:44 +00:00
|
|
|
{
|
2002-02-25 19:26:34 +00:00
|
|
|
off[i] = mach64_buffer_base[frame][i];
|
|
|
|
off[i+3]= mach64_buffer_base[last_frame][i];
|
2002-02-16 07:55:44 +00:00
|
|
|
}
|
2002-02-25 19:26:34 +00:00
|
|
|
|
2002-02-24 18:31:14 +00:00
|
|
|
#if 0 // delay routine so the individual frames can be ssen better
|
|
|
|
{
|
|
|
|
volatile int i=0;
|
|
|
|
for(i=0; i<10000000; i++);
|
|
|
|
}
|
|
|
|
#endif
|
2002-02-16 07:55:44 +00:00
|
|
|
|
|
|
|
mach64_wait_for_idle();
|
|
|
|
mach64_fifo_wait(7);
|
2002-02-24 18:31:14 +00:00
|
|
|
|
2002-02-16 07:55:44 +00:00
|
|
|
OUTREG(SCALER_BUF0_OFFSET, off[0]);
|
|
|
|
OUTREG(SCALER_BUF0_OFFSET_U, off[1]);
|
|
|
|
OUTREG(SCALER_BUF0_OFFSET_V, off[2]);
|
|
|
|
OUTREG(SCALER_BUF1_OFFSET, off[3]);
|
|
|
|
OUTREG(SCALER_BUF1_OFFSET_U, off[4]);
|
|
|
|
OUTREG(SCALER_BUF1_OFFSET_V, off[5]);
|
2002-02-25 19:26:34 +00:00
|
|
|
if(num_mach64_buffers==2) mach64_wait_vsync(); //only wait for vsync if we do double buffering
|
|
|
|
|
2002-02-19 16:23:02 +00:00
|
|
|
if(__verbose > VERBOSE_LEVEL) mach64_vid_dump_regs();
|
2002-02-16 07:55:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
vidix_video_eq_t equal =
|
|
|
|
{
|
|
|
|
VEQ_CAP_BRIGHTNESS | VEQ_CAP_SATURATION
|
|
|
|
,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
int vixPlaybackGetEq( vidix_video_eq_t * eq)
|
|
|
|
{
|
|
|
|
memcpy(eq,&equal,sizeof(vidix_video_eq_t));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vixPlaybackSetEq( const vidix_video_eq_t * eq)
|
|
|
|
{
|
|
|
|
int br,sat;
|
|
|
|
if(eq->cap & VEQ_CAP_BRIGHTNESS) equal.brightness = eq->brightness;
|
|
|
|
if(eq->cap & VEQ_CAP_CONTRAST) equal.contrast = eq->contrast;
|
|
|
|
if(eq->cap & VEQ_CAP_SATURATION) equal.saturation = eq->saturation;
|
|
|
|
if(eq->cap & VEQ_CAP_HUE) equal.hue = eq->hue;
|
|
|
|
if(eq->cap & VEQ_CAP_RGB_INTENSITY)
|
|
|
|
{
|
|
|
|
equal.red_intensity = eq->red_intensity;
|
|
|
|
equal.green_intensity = eq->green_intensity;
|
|
|
|
equal.blue_intensity = eq->blue_intensity;
|
|
|
|
}
|
|
|
|
equal.flags = eq->flags;
|
|
|
|
br = equal.brightness * 64 / 1000;
|
|
|
|
if(br < -64) br = -64; if(br > 63) br = 63;
|
|
|
|
sat = (equal.saturation + 1000) * 16 / 1000;
|
|
|
|
if(sat < 0) sat = 0; if(sat > 31) sat = 31;
|
|
|
|
OUTREG(SCALER_COLOUR_CNTL, (br & 0x7f) | (sat << 8) | (sat << 16));
|
|
|
|
return 0;
|
2002-02-13 08:59:23 +00:00
|
|
|
}
|
2002-02-25 14:21:26 +00:00
|
|
|
|
|
|
|
int vixGetGrKeys(vidix_grkey_t *grkey)
|
|
|
|
{
|
|
|
|
memcpy(grkey, &mach64_grkey, sizeof(vidix_grkey_t));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int vixSetGrKeys(const vidix_grkey_t *grkey)
|
|
|
|
{
|
|
|
|
memcpy(&mach64_grkey, grkey, sizeof(vidix_grkey_t));
|
2002-02-26 22:15:08 +00:00
|
|
|
|
|
|
|
if(mach64_grkey.ckey.op == CKEY_TRUE)
|
|
|
|
{
|
|
|
|
besr.ckey_on=1;
|
|
|
|
|
|
|
|
switch(mach64_vid_get_dbpp())
|
|
|
|
{
|
|
|
|
case 15:
|
|
|
|
besr.graphics_key_msk=0x7FFF;
|
|
|
|
besr.graphics_key_clr=
|
|
|
|
((mach64_grkey.ckey.blue &0xF8)>>3)
|
|
|
|
| ((mach64_grkey.ckey.green&0xF8)<<2)
|
|
|
|
| ((mach64_grkey.ckey.red &0xF8)<<7);
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
besr.graphics_key_msk=0xFFFF;
|
|
|
|
besr.graphics_key_clr=
|
|
|
|
((mach64_grkey.ckey.blue &0xF8)>>3)
|
|
|
|
| ((mach64_grkey.ckey.green&0xFC)<<3)
|
|
|
|
| ((mach64_grkey.ckey.red &0xF8)<<8);
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
besr.graphics_key_msk=0xFFFFFF;
|
|
|
|
besr.graphics_key_clr=
|
|
|
|
((mach64_grkey.ckey.blue &0xFF))
|
|
|
|
| ((mach64_grkey.ckey.green&0xFF)<<8)
|
|
|
|
| ((mach64_grkey.ckey.red &0xFF)<<16);
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
besr.graphics_key_msk=0xFFFFFF;
|
|
|
|
besr.graphics_key_clr=
|
|
|
|
((mach64_grkey.ckey.blue &0xFF))
|
|
|
|
| ((mach64_grkey.ckey.green&0xFF)<<8)
|
|
|
|
| ((mach64_grkey.ckey.red &0xFF)<<16);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
besr.ckey_on=0;
|
|
|
|
besr.graphics_key_msk=0;
|
|
|
|
besr.graphics_key_clr=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
besr.ckey_on=0;
|
|
|
|
besr.graphics_key_msk=0;
|
|
|
|
besr.graphics_key_clr=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mach64_fifo_wait(4);
|
|
|
|
OUTREG(OVERLAY_GRAPHICS_KEY_MSK, besr.graphics_key_msk);
|
|
|
|
OUTREG(OVERLAY_GRAPHICS_KEY_CLR, besr.graphics_key_clr);
|
|
|
|
// OUTREG(OVERLAY_VIDEO_KEY_MSK, 0);
|
|
|
|
// OUTREG(OVERLAY_VIDEO_KEY_CLR, 0);
|
|
|
|
if(besr.ckey_on)
|
|
|
|
OUTREG(OVERLAY_KEY_CNTL,VIDEO_KEY_FN_TRUE|GRAPHIC_KEY_FN_EQ|CMP_MIX_AND);
|
|
|
|
else
|
|
|
|
OUTREG(OVERLAY_KEY_CNTL,VIDEO_KEY_FN_TRUE|GRAPHIC_KEY_FN_TRUE|CMP_MIX_AND);
|
|
|
|
|
2002-02-25 14:21:26 +00:00
|
|
|
return(0);
|
|
|
|
}
|