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

📄 xc5000.c

📁 trident tm5600的linux驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
}static int xc_tune_channel(struct xc5000_priv *priv, u32 freq_hz){	int found = 0;	dprintk(1, "%s(%u)\n", __func__, freq_hz);	if (xc_set_RF_frequency(priv, freq_hz) != XC_RESULT_SUCCESS)		return 0;	if (WaitForLock(priv) == 1)		found = 1;	return found;}static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val){	u8 buf[2] = { reg >> 8, reg & 0xff };	u8 bval[2] = { 0, 0 };	struct i2c_msg msg[2] = {		{ .addr = priv->i2c_props.addr,			.flags = 0, .buf = &buf[0], .len = 2 },		{ .addr = priv->i2c_props.addr,			.flags = I2C_M_RD, .buf = &bval[0], .len = 2 },	};	if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {		printk(KERN_WARNING "xc5000: I2C read failed\n");		return -EREMOTEIO;	}	*val = (bval[0] << 8) | bval[1];	return 0;}static int xc5000_writeregs(struct xc5000_priv *priv, u8 *buf, u8 len){	struct i2c_msg msg = { .addr = priv->i2c_props.addr,		.flags = 0, .buf = buf, .len = len };	if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {		printk(KERN_ERR "xc5000: I2C write failed (len=%i)\n",			(int)len);		return -EREMOTEIO;	}	return 0;}static int xc5000_readregs(struct xc5000_priv *priv, u8 *buf, u8 len){	struct i2c_msg msg = { .addr = priv->i2c_props.addr,		.flags = I2C_M_RD, .buf = buf, .len = len };	if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {		printk(KERN_ERR "xc5000 I2C read failed (len=%i)\n", (int)len);		return -EREMOTEIO;	}	return 0;}static int xc5000_fwupload(struct dvb_frontend *fe){	struct xc5000_priv *priv = fe->tuner_priv;	const struct firmware *fw;	int ret;	/* request the firmware, this will block and timeout */	printk(KERN_INFO "xc5000: waiting for firmware upload (%s)...\n",		XC5000_DEFAULT_FIRMWARE);	ret = request_firmware(&fw, XC5000_DEFAULT_FIRMWARE,		&priv->i2c_props.adap->dev);	if (ret) {		printk(KERN_ERR "xc5000: Upload failed. (file not found?)\n");		ret = XC_RESULT_RESET_FAILURE;		goto out;	} else {		printk(KERN_INFO "xc5000: firmware read %Zu bytes.\n",		       fw->size);		ret = XC_RESULT_SUCCESS;	}	if (fw->size != XC5000_DEFAULT_FIRMWARE_SIZE) {		printk(KERN_ERR "xc5000: firmware incorrect size\n");		ret = XC_RESULT_RESET_FAILURE;	} else {		printk(KERN_INFO "xc5000: firmware upload\n");		ret = xc_load_i2c_sequence(fe,  fw->data);	}out:	release_firmware(fw);	return ret;}static void xc_debug_dump(struct xc5000_priv *priv){	u16 adc_envelope;	u32 freq_error_hz = 0;	u16 lock_status;	u32 hsync_freq_hz = 0;	u16 frame_lines;	u16 quality;	u8 hw_majorversion = 0, hw_minorversion = 0;	u8 fw_majorversion = 0, fw_minorversion = 0;	/* Wait for stats to stabilize.	 * Frame Lines needs two frame times after initial lock	 * before it is valid.	 */	xc_wait(100);	xc_get_ADC_Envelope(priv,  &adc_envelope);	dprintk(1, "*** ADC envelope (0-1023) = %d\n", adc_envelope);	xc_get_frequency_error(priv, &freq_error_hz);	dprintk(1, "*** Frequency error = %d Hz\n", freq_error_hz);	xc_get_lock_status(priv,  &lock_status);	dprintk(1, "*** Lock status (0-Wait, 1-Locked, 2-No-signal) = %d\n",		lock_status);	xc_get_version(priv,  &hw_majorversion, &hw_minorversion,		&fw_majorversion, &fw_minorversion);	dprintk(1, "*** HW: V%02x.%02x, FW: V%02x.%02x\n",		hw_majorversion, hw_minorversion,		fw_majorversion, fw_minorversion);	xc_get_hsync_freq(priv,  &hsync_freq_hz);	dprintk(1, "*** Horizontal sync frequency = %d Hz\n", hsync_freq_hz);	xc_get_frame_lines(priv,  &frame_lines);	dprintk(1, "*** Frame lines = %d\n", frame_lines);	xc_get_quality(priv,  &quality);	dprintk(1, "*** Quality (0:<8dB, 7:>56dB) = %d\n", quality);}static int xc5000_set_params(struct dvb_frontend *fe,	struct dvb_frontend_parameters *params){	struct xc5000_priv *priv = fe->tuner_priv;	int ret;	dprintk(1, "%s() frequency=%d (Hz)\n", __func__, params->frequency);	switch (params->u.vsb.modulation) {	case VSB_8:	case VSB_16:		dprintk(1, "%s() VSB modulation\n", __func__);		priv->rf_mode = XC_RF_MODE_AIR;		priv->freq_hz = params->frequency - 1750000;		priv->bandwidth = BANDWIDTH_6_MHZ;		priv->video_standard = DTV6;		break;	case QAM_64:	case QAM_256:	case QAM_AUTO:		dprintk(1, "%s() QAM modulation\n", __func__);		priv->rf_mode = XC_RF_MODE_CABLE;		priv->freq_hz = params->frequency - 1750000;		priv->bandwidth = BANDWIDTH_6_MHZ;		priv->video_standard = DTV6;		break;	default:		return -EINVAL;	}	dprintk(1, "%s() frequency=%d (compensated)\n",		__func__, priv->freq_hz);	ret = xc_SetSignalSource(priv, priv->rf_mode);	if (ret != XC_RESULT_SUCCESS) {		printk(KERN_ERR			"xc5000: xc_SetSignalSource(%d) failed\n",			priv->rf_mode);		return -EREMOTEIO;	}	ret = xc_SetTVStandard(priv,		XC5000_Standard[priv->video_standard].VideoMode,		XC5000_Standard[priv->video_standard].AudioMode);	if (ret != XC_RESULT_SUCCESS) {		printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n");		return -EREMOTEIO;	}	ret = xc_set_IF_frequency(priv, priv->if_khz);	if (ret != XC_RESULT_SUCCESS) {		printk(KERN_ERR "xc5000: xc_Set_IF_frequency(%d) failed\n",		       priv->if_khz);		return -EIO;	}	xc_tune_channel(priv, priv->freq_hz);	if (debug)		xc_debug_dump(priv);	return 0;}static int xc5000_is_firmware_loaded(struct dvb_frontend *fe){	struct xc5000_priv *priv = fe->tuner_priv;	int ret;	u16 id;	ret = xc5000_readreg(priv, XREG_PRODUCT_ID, &id);	if (ret == XC_RESULT_SUCCESS) {		if (id == XC_PRODUCT_ID_FW_NOT_LOADED)			ret = XC_RESULT_RESET_FAILURE;		else			ret = XC_RESULT_SUCCESS;	}	dprintk(1, "%s() returns %s id = 0x%x\n", __func__,		ret == XC_RESULT_SUCCESS ? "True" : "False", id);	return ret;}static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe);static int xc5000_set_analog_params(struct dvb_frontend *fe,	struct analog_parameters *params){	struct xc5000_priv *priv = fe->tuner_priv;	int ret;	if (xc5000_is_firmware_loaded(fe) != XC_RESULT_SUCCESS)		xc_load_fw_and_init_tuner(fe);	dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n",		__func__, params->frequency);	priv->rf_mode = XC_RF_MODE_CABLE; /* Fix me: it could be air. */	/* params->frequency is in units of 62.5khz */	priv->freq_hz = params->frequency * 62500;	/* FIX ME: Some video standards may have several possible audio		   standards. We simply default to one of them here.	 */	if (params->std & V4L2_STD_MN) {		/* default to BTSC audio standard */		priv->video_standard = MN_NTSC_PAL_BTSC;		goto tune_channel;	}	if (params->std & V4L2_STD_PAL_BG) {		/* default to NICAM audio standard */		priv->video_standard = BG_PAL_NICAM;		goto tune_channel;	}	if (params->std & V4L2_STD_PAL_I) {		/* default to NICAM audio standard */		priv->video_standard = I_PAL_NICAM;		goto tune_channel;	}	if (params->std & V4L2_STD_PAL_DK) {		/* default to NICAM audio standard */		priv->video_standard = DK_PAL_NICAM;		goto tune_channel;	}	if (params->std & V4L2_STD_SECAM_DK) {		/* default to A2 DK1 audio standard */		priv->video_standard = DK_SECAM_A2DK1;		goto tune_channel;	}	if (params->std & V4L2_STD_SECAM_L) {		priv->video_standard = L_SECAM_NICAM;		goto tune_channel;	}	if (params->std & V4L2_STD_SECAM_LC) {		priv->video_standard = LC_SECAM_NICAM;		goto tune_channel;	}tune_channel:	ret = xc_SetSignalSource(priv, priv->rf_mode);	if (ret != XC_RESULT_SUCCESS) {		printk(KERN_ERR			"xc5000: xc_SetSignalSource(%d) failed\n",			priv->rf_mode);		return -EREMOTEIO;	}	ret = xc_SetTVStandard(priv,		XC5000_Standard[priv->video_standard].VideoMode,		XC5000_Standard[priv->video_standard].AudioMode);	if (ret != XC_RESULT_SUCCESS) {		printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n");		return -EREMOTEIO;	}	xc_tune_channel(priv, priv->freq_hz);	if (debug)		xc_debug_dump(priv);	return 0;}static int xc5000_get_frequency(struct dvb_frontend *fe, u32 *freq){	struct xc5000_priv *priv = fe->tuner_priv;	dprintk(1, "%s()\n", __func__);	*freq = priv->freq_hz;	return 0;}static int xc5000_get_bandwidth(struct dvb_frontend *fe, u32 *bw){	struct xc5000_priv *priv = fe->tuner_priv;	dprintk(1, "%s()\n", __func__);	*bw = priv->bandwidth;	return 0;}static int xc5000_get_status(struct dvb_frontend *fe, u32 *status){	struct xc5000_priv *priv = fe->tuner_priv;	u16 lock_status = 0;	xc_get_lock_status(priv, &lock_status);	dprintk(1, "%s() lock_status = 0x%08x\n", __func__, lock_status);	*status = lock_status;	return 0;}static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe){	struct xc5000_priv *priv = fe->tuner_priv;	int ret = 0;	if (xc5000_is_firmware_loaded(fe) != XC_RESULT_SUCCESS) {		ret = xc5000_fwupload(fe);		if (ret != XC_RESULT_SUCCESS)			return ret;	}	/* Start the tuner self-calibration process */	ret |= xc_initialize(priv);	/* Wait for calibration to complete.	 * We could continue but XC5000 will clock stretch subsequent	 * I2C transactions until calibration is complete.  This way we	 * don't have to rely on clock stretching working.	 */	xc_wait(100);	/* Default to "CABLE" mode */	ret |= xc_write_reg(priv, XREG_SIGNALSOURCE, XC_RF_MODE_CABLE);	return ret;}static int xc5000_sleep(struct dvb_frontend *fe){	struct xc5000_priv *priv = fe->tuner_priv;	int ret;	dprintk(1, "%s()\n", __func__);	/* On Pinnacle PCTV HD 800i, the tuner cannot be reinitialized	 * once shutdown without reloading the driver. Maybe I am not	 * doing something right.	 *	 */	ret = xc_shutdown(priv);	if (ret != XC_RESULT_SUCCESS) {		printk(KERN_ERR			"xc5000: %s() unable to shutdown tuner\n",			__func__);		return -EREMOTEIO;	} else		return XC_RESULT_SUCCESS;}static int xc5000_init(struct dvb_frontend *fe){	struct xc5000_priv *priv = fe->tuner_priv;	dprintk(1, "%s()\n", __func__);	if (xc_load_fw_and_init_tuner(fe) != XC_RESULT_SUCCESS) {		printk(KERN_ERR "xc5000: Unable to initialise tuner\n");		return -EREMOTEIO;	}	if (debug)		xc_debug_dump(priv);	return 0;}static int xc5000_release(struct dvb_frontend *fe){	struct xc5000_priv *priv = fe->tuner_priv;	dprintk(1, "%s()\n", __func__);	mutex_lock(&xc5000_list_mutex);	if (priv)		hybrid_tuner_release_state(priv);	mutex_unlock(&xc5000_list_mutex);	fe->tuner_priv = NULL;	return 0;}static const struct dvb_tuner_ops xc5000_tuner_ops = {	.info = {		.name           = "Xceive XC5000",		.frequency_min  =    1000000,		.frequency_max  = 1023000000,		.frequency_step =      50000,	},	.release	   = xc5000_release,	.init		   = xc5000_init,	.sleep		   = xc5000_sleep,	.set_params	   = xc5000_set_params,	.set_analog_params = xc5000_set_analog_params,	.get_frequency	   = xc5000_get_frequency,	.get_bandwidth	   = xc5000_get_bandwidth,	.get_status	   = xc5000_get_status};struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,				   struct i2c_adapter *i2c,				   struct xc5000_config *cfg){	struct xc5000_priv *priv = NULL;	int instance;	u16 id = 0;	dprintk(1, "%s(%d-%04x)\n", __func__,		i2c ? i2c_adapter_id(i2c) : -1,		cfg ? cfg->i2c_address : -1);	mutex_lock(&xc5000_list_mutex);	instance = hybrid_tuner_request_state(struct xc5000_priv, priv,					      hybrid_tuner_instance_list,					      i2c, cfg->i2c_address, "xc5000");	switch (instance) {	case 0:		goto fail;		break;	case 1:		/* new tuner instance */		priv->bandwidth = BANDWIDTH_6_MHZ;		priv->if_khz = cfg->if_khz;		fe->tuner_priv = priv;		break;	default:		/* existing tuner instance */		fe->tuner_priv = priv;		break;	}	/* Check if firmware has been loaded. It is possible that another	   instance of the driver has loaded the firmware.	 */	if (xc5000_readreg(priv, XREG_PRODUCT_ID, &id) != 0)		goto fail;	switch (id) {	case XC_PRODUCT_ID_FW_LOADED:		printk(KERN_INFO			"xc5000: Successfully identified at address 0x%02x\n",			cfg->i2c_address);		printk(KERN_INFO			"xc5000: Firmware has been loaded previously\n");		break;	case XC_PRODUCT_ID_FW_NOT_LOADED:		printk(KERN_INFO			"xc5000: Successfully identified at address 0x%02x\n",			cfg->i2c_address);		printk(KERN_INFO			"xc5000: Firmware has not been loaded previously\n");		break;	default:		printk(KERN_ERR			"xc5000: Device not found at addr 0x%02x (0x%x)\n",			cfg->i2c_address, id);		goto fail;	}	mutex_unlock(&xc5000_list_mutex);	memcpy(&fe->ops.tuner_ops, &xc5000_tuner_ops,		sizeof(struct dvb_tuner_ops));	if (xc5000_load_fw_on_attach)		xc5000_init(fe);	return fe;fail:	mutex_unlock(&xc5000_list_mutex);	xc5000_release(fe);	return NULL;}EXPORT_SYMBOL(xc5000_attach);MODULE_AUTHOR("Steven Toth");MODULE_DESCRIPTION("Xceive xc5000 silicon tuner driver");MODULE_LICENSE("GPL");

⌨️ 快捷键说明

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