⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saa7146.c

📁 linux数字电视播放器,比先的版本高一些.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    the api- and os-independet parts of the saa7146 device driver        Copyright (C) 1998,1999 Michael Hunold <michael@mihu.de>    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include "saa7146_defs.h"#define TRUNC(val,max) ((val) < (max) ? (val) : (max))#ifdef __COMPILE_SAA7146__struct saa7146_modes_constants modes_constants[] = {	{ V_OFFSET_PAL,		V_FIELD_PAL,	V_ACTIVE_LINES_PAL,	  H_OFFSET_PAL,		H_PIXELS_PAL,	H_PIXELS_PAL+1,	  V_ACTIVE_LINES_PAL,	1024 },	/* PAL values */	{ V_OFFSET_NTSC,	V_FIELD_NTSC,	V_ACTIVE_LINES_NTSC,	  H_OFFSET_NTSC,	H_PIXELS_NTSC,  H_PIXELS_NTSC+1,	  V_ACTIVE_LINES_NTSC,	1024 },	/* NTSC values */	{ 0,0,0,0,0,0,0,0 }, /* secam values */	{ 0,288,576, 	  0,188*4,188*4+1,	  288,188*4 } /* TS values */};/* -----------------------------------------------------------------------------------------   helper functions for the calculation of the horizontal- and vertical scaling	registers,   clip-format-register etc ...   these functions take pointers to the (most-likely read-out original-values) and manipulate   them according to the requested new scaling parameters.   ----------------------------------------------------------------------------------------- *//* hps_coeff used for CXY and CXUV; scale 1/1 -> scale 1/64 */struct {	u16 hps_coeff;	u16 weight_sum;} hps_h_coeff_tab [] = { 	{0x00,   2}, {0x02,   4}, {0x00,   4}, {0x06,   8}, {0x02,   8},	{0x08,   8}, {0x00,   8}, {0x1E,  16}, {0x0E,   8}, {0x26,   8},	{0x06,   8}, {0x42,   8}, {0x02,   8}, {0x80,   8}, {0x00,   8},	{0xFE,  16}, {0xFE,   8}, {0x7E,   8}, {0x7E,   8}, {0x3E,   8},	{0x3E,   8}, {0x1E,   8}, {0x1E,   8}, {0x0E,   8}, {0x0E,   8},	{0x06,   8}, {0x06,   8}, {0x02,   8}, {0x02,   8}, {0x00,   8},	{0x00,   8}, {0xFE,  16}, {0xFE,   8}, {0xFE,   8}, {0xFE,   8},	{0xFE,   8}, {0xFE,   8}, {0xFE,   8}, {0xFE,   8}, {0xFE,   8},	{0xFE,   8}, {0xFE,   8}, {0xFE,   8}, {0xFE,   8}, {0xFE,   8},	{0xFE,   8}, {0xFE,   8}, {0xFE,   8}, {0xFE,   8}, {0x7E,   8},	{0x7E,   8}, {0x3E,   8}, {0x3E,   8}, {0x1E,   8}, {0x1E,   8},	{0x0E,   8}, {0x0E,   8}, {0x06,   8}, {0x06,   8}, {0x02,   8},	{0x02,   8}, {0x00,   8}, {0x00,   8}, {0xFE,  16}};/* table of attenuation values for horizontal scaling */u8 h_attenuation[] = { 1, 2, 4, 8, 2, 4, 8, 16, 0};int calculate_h_scale_registers(struct saa7146* saa, u32 in_x, u32 out_x, int flip_lr, u32* hps_ctrl, u32* hps_v_gain, u32* hps_h_prescale, u32* hps_h_scale){	/* horizontal prescaler */	u32 dcgx = 0, xpsc = 0, xacm = 0, cxy = 0, cxuv = 0;	/* horizontal scaler */	u32 xim = 0, xp = 0, xsci =0;	/* vertical scale & gain */	u32 pfuv = 0;		/* helper variables */	u32 h_atten = 0, i = 0;	if ( 0 == out_x ) {		printk("saa7146: ==> calculate_h_scale_registers: invalid value (=0).\n");		return -EINVAL;	}		/* mask out vanity-bit */	*hps_ctrl &= ~MASK_29;			/* calculate prescale-(xspc)-value:	[n   .. 1/2) : 1				    		[1/2 .. 1/3) : 2				    		[1/3 .. 1/4) : 3						... 			*/	if (in_x > out_x) {		xpsc = in_x / out_x;	} else {		/* zooming */		xpsc = 1;							}		/* if flip_lr-bit is set, number of pixels after horizontal prescaling must be < 384 */	if ( 0 != flip_lr ) {		/* set vanity bit */		*hps_ctrl |= MASK_29;			while (in_x / xpsc >= 384 )			xpsc++;	}	/* if zooming is wanted, number of pixels after horizontal prescaling must be < 768 */	else {		while ( in_x / xpsc >= 768 )			xpsc++;	}		/* maximum prescale is 64 (p.69) */	if ( xpsc > 64 )		xpsc = 64;	/* keep xacm clear*/	xacm = 0;		/* set horizontal filter parameters (CXY = CXUV) */	cxy = hps_h_coeff_tab[TRUNC(xpsc - 1, 63)].hps_coeff;	cxuv = cxy;		/* calculate and set horizontal fine scale (xsci) */		/* bypass the horizontal scaler ? */	if ( (in_x == out_x) && ( 1 == xpsc ) )		xsci = 0x400;	else			xsci = ( (1024 * in_x) / (out_x * xpsc) ) + xpsc;	/* set start phase for horizontal fine scale (xp) to 0 */		xp = 0;		/* set xim, if we bypass the horizontal scaler */	if ( 0x400 == xsci )		xim = 1;	else		xim = 0;			/* if the prescaler is bypassed, enable horizontal accumulation mode (xacm)	   and clear dcgx */	if( 1 == xpsc ) {		xacm = 1;		dcgx = 0;	} else {		xacm = 0;		/* get best match in the table of attenuations for horizontal scaling */		h_atten = hps_h_coeff_tab[TRUNC(xpsc - 1, 63)].weight_sum;			for (i = 0; h_attenuation[i] != 0; i++) {			if (h_attenuation[i] >= h_atten)				break;		}			dcgx = i;	}	/* the horizontal scaling increment controls the UV filter to reduce the bandwith to	   improve the display quality, so set it ... */	if ( xsci == 0x400)		pfuv = 0x00;	else if ( xsci < 0x600)		pfuv = 0x01;	else if ( xsci < 0x680)		pfuv = 0x11;	else if ( xsci < 0x700)		pfuv = 0x22;	else		pfuv = 0x33;		*hps_v_gain  &= MASK_W0|MASK_B2;	*hps_v_gain  |= (pfuv << 24);		*hps_h_scale 	&= ~(MASK_W1 | 0xf000);	*hps_h_scale	|= (xim << 31) | (xp << 24) | (xsci << 12);	*hps_h_prescale	|= (dcgx << 27) | ((xpsc-1) << 18) | (xacm << 17) | (cxy << 8) | (cxuv << 0);	return 0;}struct {	u16 hps_coeff;	u16 weight_sum;} hps_v_coeff_tab [] = { 	{0x0100,   2},  {0x0102,   4},  {0x0300,   4},  {0x0106,   8},	{0x0502,   8},  {0x0708,   8},  {0x0F00,   8},  {0x011E,  16},	{0x110E,  16},  {0x1926,  16},  {0x3906,  16},  {0x3D42,  16},	{0x7D02,  16},  {0x7F80,  16},  {0xFF00,  16},  {0x01FE,  32},	{0x01FE,  32},  {0x817E,  32},  {0x817E,  32},  {0xC13E,  32},	{0xC13E,  32},  {0xE11E,  32},  {0xE11E,  32},  {0xF10E,  32},	{0xF10E,  32},  {0xF906,  32},  {0xF906,  32},  {0xFD02,  32},	{0xFD02,  32},  {0xFF00,  32},  {0xFF00,  32},  {0x01FE,  64},	{0x01FE,  64},  {0x01FE,  64},  {0x01FE,  64},  {0x01FE,  64},	{0x01FE,  64},  {0x01FE,  64},  {0x01FE,  64},  {0x01FE,  64},	{0x01FE,  64},  {0x01FE,  64},  {0x01FE,  64},  {0x01FE,  64},	{0x01FE,  64},  {0x01FE,  64},  {0x01FE,  64},  {0x01FE,  64},	{0x01FE,  64},  {0x817E,  64},  {0x817E,  64},  {0xC13E,  64},	{0xC13E,  64},  {0xE11E,  64},  {0xE11E,  64},  {0xF10E,  64},	{0xF10E,  64},  {0xF906,  64},  {0xF906,  64},  {0xFD02,  64},	{0xFD02,  64},  {0xFF00,  64},  {0xFF00,  64},  {0x01FE, 128}};/* table of attenuation values for vertical scaling */u16 v_attenuation[] = { 2, 4, 8, 16, 32, 64, 128, 256, 0};int calculate_v_scale_registers(struct saa7146* saa, u32 in_y, u32 out_y, u32* hps_v_scale, u32* hps_v_gain){	u32 yacm = 0, ysci = 0, yacl = 0, ypo = 0, ype = 0;	/* vertical scaling */	u32 dcgy = 0, cya_cyb = 0;				/* vertical scale & gain */					u32 v_atten = 0, i = 0;					/* helper variables */	/* error, if vertical zooming */	if ( in_y < out_y ) {		printk("saa7146: ==> calculate_v_scale_registers: we cannot do vertical zooming.\n");		return -EINVAL;	}	/* linear phase interpolation may be used if scaling is between 1 and 1/2	   or scaling is between 1/2 and 1/4 (if interlace is set; see below) */	if( ((2*out_y) >= in_y) || (((4*out_y) >= in_y) && saa->interlace != 0)) {		/* convention: if scaling is between 1/2 and 1/4 we only use		   the even lines, the odd lines get discarded (see function move_to)		   if interlace is set */		if( saa->interlace != 0 && (out_y*4) >= in_y && (out_y*2) <= in_y) 			out_y *= 2;		yacm = 0;		yacl = 0;		cya_cyb = 0x00ff;				/* calculate scaling increment */		if ( in_y > out_y )			ysci = ((1024 * in_y) / (out_y + 1)) - 1024;		else			ysci = 0;		dcgy = 0;		/* calculate ype and ypo */                if (saa->interlace !=0) {                                         /* Special case for interlaced input */                    /* See Philips SAA7146A Product Spec (page 75):       */                    /* "For interlaced input, ype and ypo is defiend as   */                    /* YPeven= 3/2 x YPodd (line 1 = odd)"                */                    /*                                                    */                    /* It looks like the spec is wrong!                   */                    /* The  ad hoc values below works fine for a target   */                    /* window height of 480 (vertical scale = 1/1) NTSC.  */                    /* PLI: December 27, 2000.                            */                    ypo=64;                    ype=0;                 } else {                    ype = ysci / 16;                    ypo = ype + (ysci / 64);                }	}	else {		yacm = 1;			/* calculate scaling increment */		ysci = (((10 * 1024 * (in_y - out_y - 1)) / in_y) + 9) / 10;		/* calculate ype and ypo */		ypo = ype = ((ysci + 15) / 16);		/* the sequence length interval (yacl) has to be set according		   to the prescale value, e.g.	[n   .. 1/2) : 0		   				[1/2 .. 1/3) : 1						[1/3 .. 1/4) : 2						... */		if ( ysci < 512) {			yacl = 0;		}		else {			yacl = ( ysci / (1024 - ysci) );		}		/* get filter coefficients for cya, cyb from table hps_v_coeff_tab */			cya_cyb = hps_v_coeff_tab[TRUNC(yacl, 63)].hps_coeff;		/* get best match in the table of attenuations for vertical scaling */		v_atten = hps_v_coeff_tab[TRUNC(yacl, 63)].weight_sum;		for (i = 0; v_attenuation[i] != 0; i++) {			if (v_attenuation[i] >= v_atten)				break;		}			dcgy = i;	}	/* ypo and ype swapped in spec ? */	*hps_v_scale	|= (yacm << 31) | (ysci << 21) | (yacl << 15) | (ypo << 8 ) | (ype << 1);	*hps_v_gain	&= ~(MASK_W0|MASK_B2);	*hps_v_gain	|= (dcgy << 16) | (cya_cyb << 0);	return 0;}void calculate_hxo_hyo_and_sources(struct saa7146* saa, int port_sel, int sync_sel, u32* hps_h_scale, u32* hps_ctrl){	u32 hyo = 0, hxo = 0;		hyo = modes_constants[saa->mode].v_offset;	hxo = modes_constants[saa->mode].h_offset;					*hps_h_scale	&= ~(MASK_B0 | 0xf00);	*hps_ctrl	&= ~(MASK_W0 | MASK_B2 | MASK_30 | MASK_31 | MASK_28);	*hps_h_scale	|= (hxo <<  0);	*hps_ctrl	|= (hyo << 12);	*hps_ctrl	|= ( port_sel == 0 ? 0x0 : MASK_30);	*hps_ctrl	|= ( sync_sel == 0 ? 0x0 : MASK_28);}void calculate_output_format_register(struct saa7146* saa, u16 palette, u32* clip_format){	/* clear out the necessary bits */	*clip_format &= 0x0000ffff;		/* set these bits new */	*clip_format |=  (( ((palette&0xf00)>>8) << 30) | ((palette&0x00f) << 24) | (((palette&0x0f0)>>4) << 16));}void calculate_bcs_ctrl_register(struct saa7146 *saa, u32 brightness, u32 contrast, u32 colour, u32 *bcs_ctrl){	*bcs_ctrl = ((brightness << 24) | (contrast << 16) | (colour <<  0));}int calculate_video_dma1_grab(struct saa7146* saa, int frame, struct saa7146_video_dma* vdma1) {	int depth = 0;		switch(saa->grab_format[frame]) {		case YUV422_COMPOSED:		case RGB15_COMPOSED:		case RGB16_COMPOSED:			depth = 2;			break;		case RGB24_COMPOSED:			depth = 3;			break;		default:			depth = 4;			break;	}	vdma1->pitch		= saa->grab_width[frame]*depth*2;	vdma1->base_even	= 0;	vdma1->base_odd		= vdma1->base_even + (vdma1->pitch/2);	vdma1->prot_addr	= (saa->grab_width[frame]*saa->grab_height[frame]*depth)-1;	vdma1->num_line_byte	= ((modes_constants[saa->mode].v_field<<16) + modes_constants[saa->mode].h_pixels);	vdma1->base_page	= virt_to_bus(saa->page_table[frame]) | ME1;	/* convention: if scaling is between 1/2 and 1/4 we only use	   the even lines, the odd lines get discarded (see vertical scaling) */	if( saa->interlace != 0 && saa->grab_height[frame]*4 >= modes_constants[saa->mode].v_calc && saa->grab_height[frame]*2 <= modes_constants[saa->mode].v_calc) {		vdma1->base_odd = vdma1->prot_addr;		vdma1->pitch /= 2;	}	return 0;}/* ---------------------------------------------*//* position of overlay-window			*//* ---------------------------------------------*/		/* calculate the new memory offsets for a desired position */int move_to(struct saa7146* saa, int w_x, int w_y, int w_height, int b_width, int b_depth, int b_bpl, u32 base, int td_flip){		struct	saa7146_video_dma	vdma1;	if( w_y < 0 || w_height <= 0 || b_depth <= 0 || b_bpl <= 0 || base == 0 ) {		printk("saa7146: ==> calculate_video_dma1_overlay: illegal values: y: %d  h: %d  d: %d  b: %d  base: %d\n",w_y ,w_height,b_depth,b_bpl,base);		return -EINVAL;	}		/* calculate memory offsets for picture, look if we shall top-down-flip */	vdma1.pitch	= 2*b_bpl;	if ( 0 == td_flip ) {		vdma1.prot_addr = (u32)base + ((w_height+w_y+1)*b_width*(b_depth/4));				vdma1.base_even = (u32)base + (w_y * (vdma1.pitch/2)) + (w_x * (b_depth / 8)); 		vdma1.base_odd  = vdma1.base_even + (vdma1.pitch / 2);	}	else {		vdma1.prot_addr = (u32)base + (w_y * (vdma1.pitch/2));		vdma1.base_even = (u32)base + ((w_y+w_height) * (vdma1.pitch/2)) + (w_x * (b_depth / 8)); 		vdma1.base_odd  = vdma1.base_even + (vdma1.pitch / 2);		vdma1.pitch    *= -1;	}		/* convention: if scaling is between 1/2 and 1/4 we only use	   the even lines, the odd lines get discarded (see vertical scaling) */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -