Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7615e434 authored by Steven Toth's avatar Steven Toth Committed by Mauro Carvalho Chehab
Browse files

[media] saa7164: add various encoder message functions

parent add3f580
Loading
Loading
Loading
Loading
+662 −7
Original line number Diff line number Diff line
@@ -24,6 +24,543 @@

#include "saa7164.h"

int saa7164_api_set_encoder(struct saa7164_port *port)
{
	struct saa7164_dev *dev = port->dev;
	tmComResEncVideoBitRate_t vb;
	tmComResEncAudioBitRate_t ab;
	int ret;

	dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__, port->hwcfg.sourceid);

	ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
		EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	/* Establish video bitrates */
	vb.ucVideoBitRateMode = 0;
	vb.dwVideoBitRate = port->encoder_params.bitrate;
	vb.dwVideoBitRatePeak = vb.dwVideoBitRate;
	ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
		EU_VIDEO_BIT_RATE_CONTROL, sizeof(tmComResEncVideoBitRate_t), &vb);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	/* Establish audio bitrates */
	ab.ucAudioBitRateMode = 0;
	ab.dwAudioBitRate = 384000;
	ab.dwAudioBitRatePeak = ab.dwAudioBitRate;
	ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
		EU_AUDIO_BIT_RATE_CONTROL, sizeof(tmComResEncAudioBitRate_t), &ab);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	saa7164_api_set_aspect_ratio(port);

	return ret;
}

int saa7164_api_get_encoder(struct saa7164_port *port)
{
	struct saa7164_dev *dev = port->dev;
	tmComResEncVideoBitRate_t v;
	tmComResEncAudioBitRate_t a;
	tmComResEncVideoInputAspectRatio_t ar;
	int ret;

	dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__, port->hwcfg.sourceid);

	port->encoder_profile = 0;
	port->video_format = 0;
	port->video_resolution = 0;
	port->audio_format = 0;

	ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
		EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
		EU_VIDEO_FORMAT_CONTROL, sizeof(u8), &port->video_format);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
		EU_VIDEO_BIT_RATE_CONTROL, sizeof(v), &v);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
		EU_AUDIO_FORMAT_CONTROL, sizeof(u8), &port->audio_format);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
		EU_AUDIO_BIT_RATE_CONTROL, sizeof(a), &a);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	/* Aspect Ratio */
	ar.width = 0;
	ar.height = 0;
	ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
		EU_VIDEO_INPUT_ASPECT_CONTROL,
		sizeof(tmComResEncVideoInputAspectRatio_t), &ar);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	dprintk(DBGLVL_ENC, "encoder_profile = %d\n", port->encoder_profile);
	dprintk(DBGLVL_ENC, "video_format    = %d\n", port->video_format);
	dprintk(DBGLVL_ENC, "audio_format    = %d\n", port->audio_format);
	dprintk(DBGLVL_ENC, "video_resolution= %d\n", port->video_resolution);
	dprintk(DBGLVL_ENC, "v.ucVideoBitRateMode = %d\n", v.ucVideoBitRateMode);
	dprintk(DBGLVL_ENC, "v.dwVideoBitRate     = %d\n", v.dwVideoBitRate);
	dprintk(DBGLVL_ENC, "v.dwVideoBitRatePeak = %d\n", v.dwVideoBitRatePeak);
	dprintk(DBGLVL_ENC, "a.ucVideoBitRateMode = %d\n", a.ucAudioBitRateMode);
	dprintk(DBGLVL_ENC, "a.dwVideoBitRate     = %d\n", a.dwAudioBitRate);
	dprintk(DBGLVL_ENC, "a.dwVideoBitRatePeak = %d\n", a.dwAudioBitRatePeak);
	dprintk(DBGLVL_ENC, "aspect.width / height = %d:%d\n", ar.width, ar.height);

	return ret;
}

int saa7164_api_set_aspect_ratio(struct saa7164_port *port)
{
	struct saa7164_dev *dev = port->dev;
	tmComResEncVideoInputAspectRatio_t ar;
	int ret;

	dprintk(DBGLVL_ENC, "%s(%d)\n", __func__,
		port->encoder_params.ctl_aspect);

	switch (port->encoder_params.ctl_aspect) {
	case V4L2_MPEG_VIDEO_ASPECT_1x1:
		ar.width = 1;
		ar.height = 1;
		break;
	case V4L2_MPEG_VIDEO_ASPECT_4x3:
		ar.width = 4;
		ar.height = 3;
		break;
	case V4L2_MPEG_VIDEO_ASPECT_16x9:
		ar.width = 16;
		ar.height = 9;
		break;
	case V4L2_MPEG_VIDEO_ASPECT_221x100:
		ar.width = 221;
		ar.height = 100;
		break;
	default:
		BUG();
	}

	dprintk(DBGLVL_ENC, "%s(%d) now %d:%d\n", __func__,
		port->encoder_params.ctl_aspect,
		ar.width, ar.height);

	/* Aspect Ratio */
	ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
		EU_VIDEO_INPUT_ASPECT_CONTROL,
		sizeof(tmComResEncVideoInputAspectRatio_t), &ar);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	return ret;
}

int saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl)
{
	struct saa7164_dev *dev = port->dev;
	int ret;
	u16 val;

	if (ctl == PU_BRIGHTNESS_CONTROL)
		val = port->ctl_brightness;
	else
	if (ctl == PU_CONTRAST_CONTROL)
		val = port->ctl_contrast;
	else
	if (ctl == PU_HUE_CONTROL)
		val = port->ctl_hue;
	else
	if (ctl == PU_SATURATION_CONTROL)
		val = port->ctl_saturation;
	else
	if (ctl == PU_SHARPNESS_CONTROL)
		val = port->ctl_sharpness;
	else
		return -EINVAL;

	dprintk(DBGLVL_ENC, "%s() unitid=0x%x ctl=%d, val=%d\n",
		__func__, port->encunit.vsourceid, ctl, val);

	ret = saa7164_cmd_send(port->dev, port->encunit.vsourceid, SET_CUR,
		ctl, sizeof(u16), &val);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	return ret;
}

int saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl)
{
	struct saa7164_dev *dev = port->dev;
	int ret;
	u16 val;

	ret = saa7164_cmd_send(port->dev, port->encunit.vsourceid, GET_CUR,
		ctl, sizeof(u16), &val);
	if (ret != SAA_OK) {
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
		return ret;
	}

	dprintk(DBGLVL_ENC, "%s() ctl=%d, val=%d\n",
		__func__, ctl, val);

	if (ctl == PU_BRIGHTNESS_CONTROL)
		port->ctl_brightness = val;
	else
	if (ctl == PU_CONTRAST_CONTROL)
		port->ctl_contrast = val;
	else
	if (ctl == PU_HUE_CONTROL)
		port->ctl_hue = val;
	else
	if (ctl == PU_SATURATION_CONTROL)
		port->ctl_saturation = val;
	else
	if (ctl == PU_SHARPNESS_CONTROL)
		port->ctl_sharpness = val;

	return ret;
}

int saa7164_api_set_videomux(struct saa7164_port *port)
{
	struct saa7164_dev *dev = port->dev;
	u8 inputs[] = { 1, 2, 2, 2, 5, 5, 5 };
	int ret;

	dprintk(DBGLVL_ENC, "%s() v_mux=%d a_mux=%d\n",
		__func__, port->mux_input, inputs[ port->mux_input - 1 ]);

	/* Audio Mute */
	ret = saa7164_api_audio_mute(port, 1);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	/* Video Mux */
	ret = saa7164_cmd_send(port->dev, port->vidproc.sourceid, SET_CUR,
		SU_INPUT_SELECT_CONTROL, sizeof(u8), &port->mux_input);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
	/* Audio Mux */
	ret = saa7164_cmd_send(port->dev, port->audfeat.sourceid, SET_CUR,
		SU_INPUT_SELECT_CONTROL, sizeof(u8), &inputs[ port->mux_input - 1 ]);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
	/* Audio UnMute */
	ret = saa7164_api_audio_mute(port, 0);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	return ret;
}

int saa7164_api_audio_mute(struct saa7164_port *port, int mute)
{
	struct saa7164_dev *dev = port->dev;
	u8 v = mute;
	int ret;

	dprintk(DBGLVL_API, "%s(%d)\n", __func__, mute);

	ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
		MUTE_CONTROL, sizeof(u8), &v);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	return ret;
}

/* 0 = silence, 0xff = full */
int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level)
{
	struct saa7164_dev *dev = port->dev;
	s16 v, min, max;
	int ret;

	dprintk(DBGLVL_API, "%s(%d)\n", __func__, level);

	/* Obtain the min/max ranges */
	ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_MIN,
		VOLUME_CONTROL, sizeof(u16), &min);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_MAX,
		VOLUME_CONTROL, sizeof(u16), &max);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_CUR,
		( 0x01 << 8) | VOLUME_CONTROL, sizeof(u16), &v);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__, level, min, max, v);

	v = level;
	if (v < min)
		v = min;
	if (v > max)
		v = max;

	/* Left */
	ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
		( 0x01 << 8 ) | VOLUME_CONTROL, sizeof(s16), &v);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	/* Right */
	ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
		( 0x02 << 8 ) | VOLUME_CONTROL, sizeof(s16), &v);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_CUR,
		( 0x01 << 8) | VOLUME_CONTROL, sizeof(u16), &v);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__, level, min, max, v);

	return ret;
}

int saa7164_api_set_audio_std(struct saa7164_port *port)
{
	struct saa7164_dev *dev = port->dev;
	tmComResAudioDefaults_t lvl;
	tmComResTunerStandard_t tvaudio;
	int ret;

	dprintk(DBGLVL_API, "%s()\n", __func__);

	/* Establish default levels */
	lvl.ucDecoderLevel = TMHW_LEV_ADJ_DECLEV_DEFAULT;
	lvl.ucDecoderFM_Level = TMHW_LEV_ADJ_DECLEV_DEFAULT;
	lvl.ucMonoLevel = TMHW_LEV_ADJ_MONOLEV_DEFAULT;
	lvl.ucNICAM_Level = TMHW_LEV_ADJ_NICLEV_DEFAULT;
	lvl.ucSAP_Level = TMHW_LEV_ADJ_SAPLEV_DEFAULT;
	lvl.ucADC_Level = TMHW_LEV_ADJ_ADCLEV_DEFAULT;
	ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
		AUDIO_DEFAULT_CONTROL, sizeof(tmComResAudioDefaults_t), &lvl);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	/* Manually select the appropriate TV audio standard */
	if (port->encodernorm.id & V4L2_STD_NTSC) {
		tvaudio.std = TU_STANDARD_NTSC_M;
		tvaudio.country = 1;
	} else {
		tvaudio.std = TU_STANDARD_PAL_I;
		tvaudio.country = 44;
	}

	ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR,
		TU_STANDARD_CONTROL, sizeof(tvaudio), &tvaudio);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() TU_STANDARD_CONTROL error, ret = 0x%x\n", __func__, ret);
	return ret;
}

int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect)
{
	struct saa7164_dev *dev = port->dev;
	tmComResTunerStandardAuto_t p;
	int ret;

	dprintk(DBGLVL_API, "%s(%d)\n", __func__, autodetect);

	/* Disable TV Audio autodetect if not already set (buggy) */
	if (autodetect)
		p.mode = TU_STANDARD_AUTO;
	else
		p.mode = TU_STANDARD_MANUAL;
	ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR,
		TU_STANDARD_AUTO_CONTROL, sizeof(p), &p);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() TU_STANDARD_AUTO_CONTROL error, ret = 0x%x\n", __func__, ret);

	return ret;
}

int saa7164_api_get_videomux(struct saa7164_port *port)
{
	struct saa7164_dev *dev = port->dev;
	int ret;

	ret = saa7164_cmd_send(port->dev, port->vidproc.sourceid, GET_CUR,
		SU_INPUT_SELECT_CONTROL, sizeof(u8), &port->mux_input);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);

	dprintk(DBGLVL_ENC, "%s() v_mux=%d\n",
		__func__, port->mux_input);

	return ret;
}

int saa7164_api_set_dif(struct saa7164_port *port, u8 reg, u8 val)
{
	struct saa7164_dev *dev = port->dev;

	u16 len = 0;
	u8 buf[256];
	int ret;
	u8 mas;

	dprintk(DBGLVL_API, "%s()\n", __func__);

	if (port->nr == 0)
		mas = 0xd0;
	else
		mas = 0xe0;

	memset(buf, 0, sizeof(buf));

	buf[0x00] = 0x04;
	buf[0x01] = 0x00;
	buf[0x02] = 0x00;
	buf[0x03] = 0x00;

	buf[0x04] = 0x04;
	buf[0x05] = 0x00;
	buf[0x06] = 0x00;
	buf[0x07] = 0x00;

	buf[0x08] = reg;
	buf[0x09] = 0x26;
	buf[0x0a] = mas;
	buf[0x0b] = 0xb0;

	buf[0x0c] = val;
	buf[0x0d] = 0x00;
	buf[0x0e] = 0x00;
	buf[0x0f] = 0x00;

	ret = saa7164_cmd_send(dev, port->ifunit.unitid, GET_LEN,
		EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len);
	if (ret != SAA_OK) {
		printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret);
		return -EIO;
	}

	ret = saa7164_cmd_send(dev, port->ifunit.unitid, SET_CUR,
		EXU_REGISTER_ACCESS_CONTROL, len, &buf);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret);

	//saa7164_dumphex16(dev, buf, 16);

	return ret == SAA_OK ? 0 : -EIO;
}

/* Disable the IF block AGC controls */
int saa7164_api_configure_dif(struct saa7164_port *port, u32 std)
{
	struct saa7164_dev *dev = port->dev;
	int ret = 0;
	u8 agc_disable;

	dprintk(DBGLVL_API, "%s(%p, 0x%x)\n", __func__, port, std);

	if (std & V4L2_STD_NTSC) {
		dprintk(DBGLVL_API, " NTSC\n");
		saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
		agc_disable = 0;
	} else if (std & V4L2_STD_PAL_I) {
		dprintk(DBGLVL_API, " PAL-I\n");
		saa7164_api_set_dif(port, 0x00, 0x08); /* Video Standard */
		agc_disable = 0;
	} else if (std & V4L2_STD_PAL_M) {
		dprintk(DBGLVL_API, " PAL-M\n");
		saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
		agc_disable = 0;
	} else if (std & V4L2_STD_PAL_N) {
		dprintk(DBGLVL_API, " PAL-N\n");
		saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
		agc_disable = 0;
	} else if (std & V4L2_STD_PAL_Nc) {
		dprintk(DBGLVL_API, " PAL-Nc\n");
		saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
		agc_disable = 0;
	} else if (std & V4L2_STD_PAL_B) {
		dprintk(DBGLVL_API, " PAL-B\n");
		saa7164_api_set_dif(port, 0x00, 0x02); /* Video Standard */
		agc_disable = 0;
	} else if (std & V4L2_STD_PAL_DK) {
		dprintk(DBGLVL_API, " PAL-DK\n");
		saa7164_api_set_dif(port, 0x00, 0x10); /* Video Standard */
		agc_disable = 0;
	} else if (std & V4L2_STD_SECAM_L) {
		dprintk(DBGLVL_API, " SECAM-L\n");
		saa7164_api_set_dif(port, 0x00, 0x20); /* Video Standard */
		agc_disable = 0;
	} else {
		/* Unknown standard, assume DTV */
		dprintk(DBGLVL_API, " Unknown (assuming DTV)\n");
		saa7164_api_set_dif(port, 0x00, 0x80); /* Undefined Video Standard */
		agc_disable = 1;
	}

	saa7164_api_set_dif(port, 0x48, 0xa0); /* AGC Functions 1 */
	saa7164_api_set_dif(port, 0xc0, agc_disable); /* AGC Output Disable */
	saa7164_api_set_dif(port, 0x7c, 0x04); /* CVBS EQ */
	saa7164_api_set_dif(port, 0x04, 0x01); /* Active */
	msleep(100);
	saa7164_api_set_dif(port, 0x04, 0x00); /* Active (again) */
	msleep(100);

	return ret;
}

/* Ensure the dif is in the correct state for the operating mode
 * (analog / dtv). We only configure the diff through the analog encoder
 * so when we're in digital mode we need to find the appropriate encoder
 * and use it to configure the DIF.
 */
int saa7164_api_initialize_dif(struct saa7164_port *port)
{
	struct saa7164_dev *dev = port->dev;
	struct saa7164_port *p = 0;
	int ret = -EINVAL;
	u32 std = 0;

	if (port->type == SAA7164_MPEG_ENCODER) {
		/* Pick any analog standard to init the diff.
		 * we'll come back during encoder_init'
		 * and set the correct standard if requried.
		 */
		std = V4L2_STD_NTSC;
	} else
	if (port->type == SAA7164_MPEG_DVB) {
		if (port->nr == SAA7164_PORT_TS1)
			p = &dev->ports[ SAA7164_PORT_ENC1 ];
		else
			p = &dev->ports[ SAA7164_PORT_ENC2 ];
	} else
		BUG();

	if (p)
		ret = saa7164_api_configure_dif(p, std);

	return ret;
}

int saa7164_api_transition_port(struct saa7164_port *port, u8 mode)
{
	int ret;
@@ -96,9 +633,43 @@ int saa7164_api_configure_port_mpeg2ts(struct saa7164_dev *dev,
	return 0;
}

int saa7164_api_configure_port_mpeg2ps(struct saa7164_dev *dev,
	struct saa7164_port *port,
	tmComResPSFormatDescrHeader_t *fmt)
{
	dprintk(DBGLVL_API, "    bFormatIndex = 0x%x\n", fmt->bFormatIndex);
	dprintk(DBGLVL_API, "    wPacketLength= 0x%x\n", fmt->wPacketLength);
	dprintk(DBGLVL_API, "    wPackLength=   0x%x\n", fmt->wPackLength);
	dprintk(DBGLVL_API, "    bPackDataType= 0x%x\n", fmt->bPackDataType);

	/* Cache the hardware configuration in the port */
	/* TODO: CHECK THIS in the port config */
	port->bufcounter = port->hwcfg.BARLocation;
	port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32));
	port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32));
	port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32));
	port->bufptr32l = port->hwcfg.BARLocation +
		(4 * sizeof(u32)) +
		(sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32);
	port->bufptr32h = port->hwcfg.BARLocation +
		(4 * sizeof(u32)) +
		(sizeof(u32) * port->hwcfg.buffercount);
	port->bufptr64 = port->hwcfg.BARLocation +
		(4 * sizeof(u32)) +
		(sizeof(u32) * port->hwcfg.buffercount);
	dprintk(DBGLVL_API, "   = port->hwcfg.BARLocation = 0x%x\n",
		port->hwcfg.BARLocation);

	dprintk(DBGLVL_API, "   = VS_FORMAT_MPEGPS (becomes dev->enc[%d])\n",
		port->nr);

	return 0;
}

int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
{
	struct saa7164_port *port = 0;
	struct saa7164_port *tsport = 0;
	struct saa7164_port *encport = 0;
	u32 idx, next_offset;
	int i;
	tmComResDescrHeader_t *hdr, *t;
@@ -108,6 +679,11 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
	tmComResTunerDescrHeader_t *tunerunithdr;
	tmComResDMATermDescrHeader_t *vcoutputtermhdr;
	tmComResTSFormatDescrHeader_t *tsfmt;
	tmComResPSFormatDescrHeader_t *psfmt;
	tmComResSelDescrHeader_t *psel;
	tmComResProcDescrHeader_t *pdh;
	tmComResAFeatureDescrHeader_t *afd;
	tmComResEncoderDescrHeader_t *edh;
	u32 currpath = 0;

	dprintk(DBGLVL_API,
@@ -244,17 +820,25 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
					tsfmt =
					(tmComResTSFormatDescrHeader_t *)t;
					if (currpath == 1)
						port = &dev->ts1;
						tsport = &dev->ports[ SAA7164_PORT_TS1 ];
					else
						port = &dev->ts2;
					memcpy(&port->hwcfg, vcoutputtermhdr,
						tsport = &dev->ports[ SAA7164_PORT_TS2 ];
					memcpy(&tsport->hwcfg, vcoutputtermhdr,
						sizeof(*vcoutputtermhdr));
					saa7164_api_configure_port_mpeg2ts(dev,
						port, tsfmt);
						tsport, tsfmt);
					break;
				case VS_FORMAT_MPEG2PS:
					dprintk(DBGLVL_API,
						"   = VS_FORMAT_MPEG2PS\n");
					psfmt =
					(tmComResPSFormatDescrHeader_t *)t;
					if (currpath == 1)
						encport = &dev->ports[ SAA7164_PORT_ENC1 ];
					else
						encport = &dev->ports[ SAA7164_PORT_ENC2 ];
					memcpy(&encport->hwcfg, vcoutputtermhdr,
						sizeof(*vcoutputtermhdr));
					saa7164_api_configure_port_mpeg2ps(dev,
						encport, psfmt);
					break;
				case VS_FORMAT_VBI:
					dprintk(DBGLVL_API,
@@ -297,18 +881,80 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
				tunerunithdr->controlsize);
			dprintk(DBGLVL_API, "  controls = 0x%x\n",
				tunerunithdr->controls);

			if (tunerunithdr->unitid == tunerunithdr->iunit) {
				if (currpath == 1)
					encport = &dev->ports[ SAA7164_PORT_ENC1 ];
				else
					encport = &dev->ports[ SAA7164_PORT_ENC2 ];
				memcpy(&encport->tunerunit, tunerunithdr,
					sizeof(tmComResTunerDescrHeader_t));
				dprintk(DBGLVL_API, "  (becomes dev->enc[%d] tuner)\n", encport->nr);
			}
			break;
		case VC_SELECTOR_UNIT:
			psel = (tmComResSelDescrHeader_t *)(buf + idx);
			dprintk(DBGLVL_API, " VC_SELECTOR_UNIT\n");
			dprintk(DBGLVL_API, "  unitid = 0x%x\n",
				psel->unitid);
			dprintk(DBGLVL_API, "  nrinpins = 0x%x\n",
				psel->nrinpins);
			dprintk(DBGLVL_API, "  sourceid = 0x%x\n",
				psel->sourceid);
			break;
		case VC_PROCESSING_UNIT:
			pdh = (tmComResProcDescrHeader_t *)(buf + idx);
			dprintk(DBGLVL_API, " VC_PROCESSING_UNIT\n");
			dprintk(DBGLVL_API, "  unitid = 0x%x\n",
				pdh->unitid);
			dprintk(DBGLVL_API, "  sourceid = 0x%x\n",
				pdh->sourceid);
			dprintk(DBGLVL_API, "  controlsize = 0x%x\n",
				pdh->controlsize);
			if (pdh->controlsize == 0x04) {
				if (currpath == 1)
					encport = &dev->ports[ SAA7164_PORT_ENC1 ];
				else
					encport = &dev->ports[ SAA7164_PORT_ENC2 ];
				memcpy(&encport->vidproc, pdh,
					sizeof(tmComResProcDescrHeader_t));
				dprintk(DBGLVL_API, "  (becomes dev->enc[%d])\n", encport->nr);
			}
			break;
		case FEATURE_UNIT:
			afd = (tmComResAFeatureDescrHeader_t *)(buf + idx);
			dprintk(DBGLVL_API, " FEATURE_UNIT\n");
			dprintk(DBGLVL_API, "  unitid = 0x%x\n",
				afd->unitid);
			dprintk(DBGLVL_API, "  sourceid = 0x%x\n",
				afd->sourceid);
			dprintk(DBGLVL_API, "  controlsize = 0x%x\n",
				afd->controlsize);
			if (currpath == 1)
				encport = &dev->ports[ SAA7164_PORT_ENC1 ];
			else
				encport = &dev->ports[ SAA7164_PORT_ENC2 ];
			memcpy(&encport->audfeat, afd,
				sizeof(tmComResAFeatureDescrHeader_t));
			dprintk(DBGLVL_API, "  (becomes dev->enc[%d])\n", encport->nr);
			break;
		case ENCODER_UNIT:
			edh = (tmComResEncoderDescrHeader_t *)(buf + idx);
			dprintk(DBGLVL_API, " ENCODER_UNIT\n");
			dprintk(DBGLVL_API, "  subtype = 0x%x\n", edh->subtype);
			dprintk(DBGLVL_API, "  unitid = 0x%x\n", edh->unitid);
			dprintk(DBGLVL_API, "  vsourceid = 0x%x\n", edh->vsourceid);
			dprintk(DBGLVL_API, "  asourceid = 0x%x\n", edh->asourceid);
			dprintk(DBGLVL_API, "  iunit = 0x%x\n", edh->iunit);
			if (edh->iunit == edh->unitid) {
				if (currpath == 1)
					encport = &dev->ports[ SAA7164_PORT_ENC1 ];
				else
					encport = &dev->ports[ SAA7164_PORT_ENC2 ];
				memcpy(&encport->encunit, edh,
					sizeof(tmComResEncoderDescrHeader_t));
				dprintk(DBGLVL_API, "  (becomes dev->enc[%d])\n", encport->nr);
			}
			break;
		case EXTENSION_UNIT:
			dprintk(DBGLVL_API, " EXTENSION_UNIT\n");
@@ -364,6 +1010,15 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
				exthdr->numgpiogroups);
			dprintk(DBGLVL_API, "  controlsize = 0x%x\n",
				exthdr->controlsize);
			if (exthdr->devicetype & 0x80) {
				if (currpath == 1)
					encport = &dev->ports[ SAA7164_PORT_ENC1 ];
				else
					encport = &dev->ports[ SAA7164_PORT_ENC2 ];
				memcpy(&encport->ifunit, exthdr,
					sizeof(tmComResExtDevDescrHeader_t));
				dprintk(DBGLVL_API, "  (becomes dev->enc[%d])\n", encport->nr);
			}
			break;
		case PVC_INFRARED_UNIT:
			dprintk(DBGLVL_API, " PVC_INFRARED_UNIT\n");
+38 −0
Original line number Diff line number Diff line
@@ -265,3 +265,41 @@ int saa7164_buffer_cfg_port(struct saa7164_port *port)
	return 0;
}

struct saa7164_user_buffer *saa7164_buffer_alloc_user(struct saa7164_dev *dev, u32 len)
{
	struct saa7164_user_buffer *buf;

	buf = kzalloc(sizeof(struct saa7164_user_buffer), GFP_KERNEL);
	if (buf == 0)
		return 0;

	buf->data = kzalloc(len, GFP_KERNEL);

	if (buf->data == 0) {
		kfree(buf);
		return 0;
	}

	buf->actual_size = len;
	buf->pos = 0;

	dprintk(DBGLVL_BUF, "%s()   allocated user buffer @ 0x%p\n",
		__func__, buf);

	return buf;
}

void saa7164_buffer_dealloc_user(struct saa7164_user_buffer *buf)
{
	if (!buf)
		return;

	if (buf->data) {
		kfree(buf->data);
		buf->data = 0;
	}

	if (buf)
		kfree(buf);
}
+14 −0
Original line number Diff line number Diff line
@@ -55,6 +55,8 @@ struct saa7164_board saa7164_boards[] = {
		.name		= "Hauppauge WinTV-HVR2200",
		.porta		= SAA7164_MPEG_DVB,
		.portb		= SAA7164_MPEG_DVB,
		.portc		= SAA7164_MPEG_ENCODER,
		.portd		= SAA7164_MPEG_ENCODER,
		.chiprev	= SAA7164_CHIP_REV3,
		.unit		= {{
			.id		= 0x1d,
@@ -97,6 +99,8 @@ struct saa7164_board saa7164_boards[] = {
		.name		= "Hauppauge WinTV-HVR2200",
		.porta		= SAA7164_MPEG_DVB,
		.portb		= SAA7164_MPEG_DVB,
		.portc		= SAA7164_MPEG_ENCODER,
		.portd		= SAA7164_MPEG_ENCODER,
		.chiprev	= SAA7164_CHIP_REV2,
		.unit		= {{
			.id		= 0x06,
@@ -139,6 +143,8 @@ struct saa7164_board saa7164_boards[] = {
		.name		= "Hauppauge WinTV-HVR2200",
		.porta		= SAA7164_MPEG_DVB,
		.portb		= SAA7164_MPEG_DVB,
		.portc		= SAA7164_MPEG_ENCODER,
		.portd		= SAA7164_MPEG_ENCODER,
		.chiprev	= SAA7164_CHIP_REV2,
		.unit		= {{
			.id		= 0x1d,
@@ -195,6 +201,10 @@ struct saa7164_board saa7164_boards[] = {
		.name		= "Hauppauge WinTV-HVR2250",
		.porta		= SAA7164_MPEG_DVB,
		.portb		= SAA7164_MPEG_DVB,
		.portc		= SAA7164_MPEG_ENCODER,
		.portd		= SAA7164_MPEG_ENCODER,
		.portc		= SAA7164_MPEG_ENCODER,
		.portd		= SAA7164_MPEG_ENCODER,
		.chiprev	= SAA7164_CHIP_REV3,
		.unit		= {{
			.id		= 0x22,
@@ -251,6 +261,8 @@ struct saa7164_board saa7164_boards[] = {
		.name		= "Hauppauge WinTV-HVR2250",
		.porta		= SAA7164_MPEG_DVB,
		.portb		= SAA7164_MPEG_DVB,
		.portc		= SAA7164_MPEG_ENCODER,
		.portd		= SAA7164_MPEG_ENCODER,
		.chiprev	= SAA7164_CHIP_REV3,
		.unit		= {{
			.id		= 0x28,
@@ -307,6 +319,8 @@ struct saa7164_board saa7164_boards[] = {
		.name		= "Hauppauge WinTV-HVR2250",
		.porta		= SAA7164_MPEG_DVB,
		.portb		= SAA7164_MPEG_DVB,
		.portc		= SAA7164_MPEG_ENCODER,
		.portd		= SAA7164_MPEG_ENCODER,
		.chiprev	= SAA7164_CHIP_REV3,
		.unit		= {{
			.id		= 0x26,
+142 −25

File changed.

Preview size limit exceeded, changes collapsed.

+1371 −0

File changed.

Preview size limit exceeded, changes collapsed.

Loading