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

📄 tuner-simple.c

📁 底层驱动开发
💻 C
📖 第 1 页 / 共 2 页
字号:
{	unsigned char byte;	if (1 != i2c_master_recv(c,&byte,1))		return 0;	return byte;}static int tuner_signal(struct i2c_client *c){	return (tuner_getstatus(c) & TUNER_SIGNAL) << 13;}static int tuner_stereo(struct i2c_client *c){	int stereo, status;	struct tuner *t = i2c_get_clientdata(c);	status = tuner_getstatus (c);	switch (t->type) {        	case TUNER_PHILIPS_FM1216ME_MK3:    		case TUNER_PHILIPS_FM1236_MK3:		case TUNER_PHILIPS_FM1256_IH3:			stereo = ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3);			break;		default:			stereo = status & TUNER_STEREO;	}	return stereo;}/* ---------------------------------------------------------------------- */static void default_set_tv_freq(struct i2c_client *c, unsigned int freq){	struct tuner *t = i2c_get_clientdata(c);	u8 config;	u16 div;	struct tunertype *tun;        unsigned char buffer[4];	int rc;	tun = &tuners[t->type];	if (freq < tun->thresh1) {		config = tun->VHF_L;		tuner_dbg("tv: VHF lowrange\n");	} else if (freq < tun->thresh2) {		config = tun->VHF_H;		tuner_dbg("tv: VHF high range\n");	} else {		config = tun->UHF;		tuner_dbg("tv: UHF range\n");	}	/* tv norm specific stuff for multi-norm tuners */	switch (t->type) {	case TUNER_PHILIPS_SECAM: // FI1216MF		/* 0x01 -> ??? no change ??? */		/* 0x02 -> PAL BDGHI / SECAM L */		/* 0x04 -> ??? PAL others / SECAM others ??? */		config &= ~0x02;		if (t->std & V4L2_STD_SECAM)			config |= 0x02;		break;	case TUNER_TEMIC_4046FM5:		config &= ~0x0f;		if (t->std & V4L2_STD_PAL_BG) {			config |= TEMIC_SET_PAL_BG;		} else if (t->std & V4L2_STD_PAL_I) {			config |= TEMIC_SET_PAL_I;		} else if (t->std & V4L2_STD_PAL_DK) {			config |= TEMIC_SET_PAL_DK;		} else if (t->std & V4L2_STD_SECAM_L) {			config |= TEMIC_SET_PAL_L;		}		break;	case TUNER_PHILIPS_FQ1216ME:		config &= ~0x0f;		if (t->std & (V4L2_STD_PAL_BG|V4L2_STD_PAL_DK)) {			config |= PHILIPS_SET_PAL_BGDK;		} else if (t->std & V4L2_STD_PAL_I) {			config |= PHILIPS_SET_PAL_I;		} else if (t->std & V4L2_STD_SECAM_L) {			config |= PHILIPS_SET_PAL_L;		}		break;	case TUNER_PHILIPS_ATSC:		/* 0x00 -> ATSC antenna input 1 */		/* 0x01 -> ATSC antenna input 2 */		/* 0x02 -> NTSC antenna input 1 */		/* 0x03 -> NTSC antenna input 2 */		config &= ~0x03;		if (!(t->std & V4L2_STD_ATSC))			config |= 2;		/* FIXME: input */		break;	case TUNER_MICROTUNE_4042FI5:		/* Set the charge pump for fast tuning */		tun->config |= TUNER_CHARGE_PUMP;		break;	}	/*	 * Philips FI1216MK2 remark from specification :	 * for channel selection involving band switching, and to ensure	 * smooth tuning to the desired channel without causing	 * unnecessary charge pump action, it is recommended to consider	 * the difference between wanted channel frequency and the	 * current channel frequency.  Unnecessary charge pump action	 * will result in very low tuning voltage which may drive the	 * oscillator to extreme conditions.	 *	 * Progfou: specification says to send config data before	 * frequency in case (wanted frequency < current frequency).	 */	div=freq + tun->IFPCoff;	if (t->type == TUNER_PHILIPS_SECAM && freq < t->freq) {		buffer[0] = tun->config;		buffer[1] = config;		buffer[2] = (div>>8) & 0x7f;		buffer[3] = div      & 0xff;	} else {		buffer[0] = (div>>8) & 0x7f;		buffer[1] = div      & 0xff;		buffer[2] = tun->config;		buffer[3] = config;	}	tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",		  buffer[0],buffer[1],buffer[2],buffer[3]);        if (4 != (rc = i2c_master_send(c,buffer,4)))		tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);	if (t->type == TUNER_MICROTUNE_4042FI5) {		// FIXME - this may also work for other tuners		unsigned long timeout = jiffies + msecs_to_jiffies(1);		u8 status_byte = 0;		/* Wait until the PLL locks */		for (;;) {			if (time_after(jiffies,timeout))				return;			if (1 != (rc = i2c_master_recv(c,&status_byte,1))) {				tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc);				break;			}			if (status_byte & TUNER_PLL_LOCKED)				break;			udelay(10);		}		/* Set the charge pump for optimized phase noise figure */		tun->config &= ~TUNER_CHARGE_PUMP;		buffer[0] = (div>>8) & 0x7f;		buffer[1] = div      & 0xff;		buffer[2] = tun->config;		buffer[3] = config;		tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",		       buffer[0],buffer[1],buffer[2],buffer[3]);		if (4 != (rc = i2c_master_send(c,buffer,4)))			tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);	}}static void default_set_radio_freq(struct i2c_client *c, unsigned int freq){	struct tunertype *tun;	struct tuner *t = i2c_get_clientdata(c);        unsigned char buffer[4];	unsigned div;	int rc;	tun = &tuners[t->type];	div = (20 * freq / 16000) + (int)(20*10.7); /* IF 10.7 MHz */	buffer[2] = (tun->config & ~TUNER_RATIO_MASK) | TUNER_RATIO_SELECT_50; /* 50 kHz step */	switch (t->type) {	case TUNER_TENA_9533_DI:	case TUNER_YMEC_TVF_5533MF:		tuner_dbg ("This tuner doesn't have FM. Most cards has a TEA5767 for FM\n");		return;	case TUNER_PHILIPS_FM1216ME_MK3:	case TUNER_PHILIPS_FM1236_MK3:	case TUNER_PHILIPS_FMD1216ME_MK3:		buffer[3] = 0x19;		break;	case TUNER_PHILIPS_FM1256_IH3:		div = (20 * freq) / 16000 + (int)(33.3 * 20);  /* IF 33.3 MHz */		buffer[3] = 0x19;		break;	case TUNER_LG_PAL_FM:		buffer[3] = 0xa5;		break;	case TUNER_MICROTUNE_4049FM5:		div = (20 * freq) / 16000 + (int)(33.3 * 20); /* IF 33.3 MHz */		buffer[3] = 0xa4;		break;	default:		buffer[3] = 0xa4;		break;	}        buffer[0] = (div>>8) & 0x7f;        buffer[1] = div      & 0xff;	tuner_dbg("radio 0x%02x 0x%02x 0x%02x 0x%02x\n",	       buffer[0],buffer[1],buffer[2],buffer[3]);        if (4 != (rc = i2c_master_send(c,buffer,4)))		tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);}int default_tuner_init(struct i2c_client *c){	struct tuner *t = i2c_get_clientdata(c);	tuner_info("type set to %d (%s)\n",		   t->type, tuners[t->type].name);	strlcpy(c->name, tuners[t->type].name, sizeof(c->name));	t->tv_freq    = default_set_tv_freq;	t->radio_freq = default_set_radio_freq;	t->has_signal = tuner_signal;	t->is_stereo  = tuner_stereo;	t->standby = NULL;	return 0;}/* * Overrides for Emacs so that we follow Linus's tabbing style. * --------------------------------------------------------------------------- * Local variables: * c-basic-offset: 8 * End: */

⌨️ 快捷键说明

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