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

📄 saa7146_hlp.c

📁 linux-2.6.15.6
💻 C
字号:
#include <linux/kernel.h>#include <media/saa7146_vv.h>static void calculate_output_format_register(struct saa7146_dev* saa, u32 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));}static void calculate_hps_source_and_sync(struct saa7146_dev *dev, int source, int sync, u32* hps_ctrl){	*hps_ctrl &= ~(MASK_30 | MASK_31 | MASK_28);	*hps_ctrl |= (source << 30) | (sync << 28);}static void calculate_hxo_and_hyo(struct saa7146_vv *vv, u32* hps_h_scale, u32* hps_ctrl){	int hyo = 0, hxo = 0;	hyo = vv->standard->v_offset;	hxo = vv->standard->h_offset;	*hps_h_scale	&= ~(MASK_B0 | 0xf00);	*hps_h_scale	|= (hxo <<  0);	*hps_ctrl	&= ~(MASK_W0 | MASK_B2);	*hps_ctrl	|= (hyo << 12);}/* 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   changes.*//* hps_coeff used for CXY and CXUV; scale 1/1 -> scale 1/64 */static 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 */static u8 h_attenuation[] = { 1, 2, 4, 8, 2, 4, 8, 16, 0};/* calculate horizontal scale registers */static int calculate_h_scale_registers(struct saa7146_dev *dev,	int in_x, int 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 ) {		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[( (xpsc - 1) < 63 ? (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[( (xpsc - 1) < 63 ? (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;}static 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 */static u16 v_attenuation[] = { 2, 4, 8, 16, 32, 64, 128, 256, 0};/* calculate vertical scale registers */static int calculate_v_scale_registers(struct saa7146_dev *dev, enum v4l2_field field,	int in_y, int out_y, u32* hps_v_scale, u32* hps_v_gain){	int lpi = 0;	/* vertical scaling */	u32 yacm = 0, ysci = 0, yacl = 0, ypo = 0, ype = 0;	/* vertical scale & gain */	u32 dcgy = 0, cya_cyb = 0;	/* helper variables */	u32 v_atten = 0, i = 0;	/* error, if vertical zooming */	if ( in_y < out_y ) {		return -EINVAL;	}	/* linear phase interpolation may be used	   if scaling is between 1 and 1/2 (both fields used)	   or scaling is between 1/2 and 1/4 (if only one field is used) */	if (V4L2_FIELD_HAS_BOTH(field)) {		if( 2*out_y >= in_y) {			lpi = 1;		}	} else if (field == V4L2_FIELD_TOP		|| field == V4L2_FIELD_ALTERNATE		|| field == V4L2_FIELD_BOTTOM) {		if( 4*out_y >= in_y ) {			lpi = 1;		}		out_y *= 2;	}	if( 0 != lpi ) {		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 */		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[ (yacl < 63 ? yacl : 63 ) ].hps_coeff;		/* get best match in the table of attenuations for vertical scaling */		v_atten = hps_v_coeff_tab[ (yacl < 63 ? 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;}/* simple bubble-sort algorithm with duplicate elimination */static int sort_and_eliminate(u32* values, int* count){	int low = 0, high = 0, top = 0, temp = 0;	int cur = 0, next = 0;	/* sanity checks */	if( (0 > *count) || (NULL == values) ) {		return -EINVAL;	}	/* bubble sort the first 碿ount

⌨️ 快捷键说明

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