tda9887.c
来自「trident tm5600的linux驱动」· C语言 代码 · 共 718 行 · 第 1/2 页
C
718 行
tuner_info(" C0-4 top adjustment : %s dB\n", adjust[buf[2] & 0x1f]); tuner_info(" C5-6 de-emphasis : %s\n", deemph[(buf[2] & 0x60) >> 5]); tuner_info(" C7 audio gain : %s\n", (buf[2] & 0x80) ? "-6" : "0"); tuner_info("write: byte E 0x%02x\n", buf[3]); tuner_info(" E0-1 sound carrier : %s\n", carrier[(buf[3] & 0x03)]); tuner_info(" E6 l pll gating : %s\n", (buf[3] & 0x40) ? "36" : "13"); if (buf[1] & 0x08) { /* radio */ tuner_info(" E2-4 video if : %s\n", rif[(buf[3] & 0x0c) >> 2]); tuner_info(" E7 vif agc output : %s\n", (buf[3] & 0x80) ? ((buf[3] & 0x10) ? "fm-agc radio" : "sif-agc radio") : "fm radio carrier afc"); } else { /* video */ tuner_info(" E2-4 video if : %s\n", vif[(buf[3] & 0x1c) >> 2]); tuner_info(" E5 tuner gain : %s\n", (buf[3] & 0x80) ? ((buf[3] & 0x20) ? "external" : "normal") : ((buf[3] & 0x20) ? "minimum" : "normal")); tuner_info(" E7 vif agc output : %s\n", (buf[3] & 0x80) ? ((buf[3] & 0x20) ? "pin3 port, pin22 vif agc out" : "pin22 port, pin3 vif acg ext in") : "pin3+pin22 port"); } tuner_info("--\n");}/* ---------------------------------------------------------------------- */static int tda9887_set_tvnorm(struct dvb_frontend *fe){ struct tda9887_priv *priv = fe->analog_demod_priv; struct tvnorm *norm = NULL; char *buf = priv->data; int i; if (priv->mode == V4L2_TUNER_RADIO) { if (priv->audmode == V4L2_TUNER_MODE_MONO) norm = &radio_mono; else norm = &radio_stereo; } else { for (i = 0; i < ARRAY_SIZE(tvnorms); i++) { if (tvnorms[i].std & priv->std) { norm = tvnorms+i; break; } } } if (NULL == norm) { tuner_dbg("Unsupported tvnorm entry - audio muted\n"); return -1; } tuner_dbg("configure for: %s\n", norm->name); buf[1] = norm->b; buf[2] = norm->c; buf[3] = norm->e; return 0;}static unsigned int port1 = UNSET;static unsigned int port2 = UNSET;static unsigned int qss = UNSET;static unsigned int adjust = UNSET;module_param(port1, int, 0644);module_param(port2, int, 0644);module_param(qss, int, 0644);module_param(adjust, int, 0644);static int tda9887_set_insmod(struct dvb_frontend *fe){ struct tda9887_priv *priv = fe->analog_demod_priv; char *buf = priv->data; if (UNSET != port1) { if (port1) buf[1] |= cOutputPort1Inactive; else buf[1] &= ~cOutputPort1Inactive; } if (UNSET != port2) { if (port2) buf[1] |= cOutputPort2Inactive; else buf[1] &= ~cOutputPort2Inactive; } if (UNSET != qss) { if (qss) buf[1] |= cQSS; else buf[1] &= ~cQSS; } if (adjust >= 0x00 && adjust < 0x20) { buf[2] &= ~cTopMask; buf[2] |= adjust; } return 0;}static int tda9887_do_config(struct dvb_frontend *fe){ struct tda9887_priv *priv = fe->analog_demod_priv; char *buf = priv->data; if (priv->config & TDA9887_PORT1_ACTIVE) buf[1] &= ~cOutputPort1Inactive; if (priv->config & TDA9887_PORT1_INACTIVE) buf[1] |= cOutputPort1Inactive; if (priv->config & TDA9887_PORT2_ACTIVE) buf[1] &= ~cOutputPort2Inactive; if (priv->config & TDA9887_PORT2_INACTIVE) buf[1] |= cOutputPort2Inactive; if (priv->config & TDA9887_QSS) buf[1] |= cQSS; if (priv->config & TDA9887_INTERCARRIER) buf[1] &= ~cQSS; if (priv->config & TDA9887_AUTOMUTE) buf[1] |= cAutoMuteFmActive; if (priv->config & TDA9887_DEEMPHASIS_MASK) { buf[2] &= ~0x60; switch (priv->config & TDA9887_DEEMPHASIS_MASK) { case TDA9887_DEEMPHASIS_NONE: buf[2] |= cDeemphasisOFF; break; case TDA9887_DEEMPHASIS_50: buf[2] |= cDeemphasisON | cDeemphasis50; break; case TDA9887_DEEMPHASIS_75: buf[2] |= cDeemphasisON | cDeemphasis75; break; } } if (priv->config & TDA9887_TOP_SET) { buf[2] &= ~cTopMask; buf[2] |= (priv->config >> 8) & cTopMask; } if ((priv->config & TDA9887_INTERCARRIER_NTSC) && (priv->std & V4L2_STD_NTSC)) buf[1] &= ~cQSS; if (priv->config & TDA9887_GATING_18) buf[3] &= ~cGating_36; if (priv->mode == V4L2_TUNER_RADIO) { if (priv->config & TDA9887_RIF_41_3) { buf[3] &= ~cVideoIFMask; buf[3] |= cRadioIF_41_30; } if (priv->config & TDA9887_GAIN_NORMAL) buf[3] &= ~cTunerGainLow; } return 0;}/* ---------------------------------------------------------------------- */static int tda9887_status(struct dvb_frontend *fe){ struct tda9887_priv *priv = fe->analog_demod_priv; unsigned char buf[1]; int rc; memset(buf,0,sizeof(buf)); if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,buf,1))) tuner_info("i2c i/o error: rc == %d (should be 1)\n", rc); dump_read_message(fe, buf); return 0;}static void tda9887_configure(struct dvb_frontend *fe){ struct tda9887_priv *priv = fe->analog_demod_priv; int rc; memset(priv->data,0,sizeof(priv->data)); tda9887_set_tvnorm(fe); /* A note on the port settings: These settings tend to depend on the specifics of the board. By default they are set to inactive (bit value 1) by this driver, overwriting any changes made by the tvnorm. This means that it is the responsibility of the module using the tda9887 to set these values in case of changes in the tvnorm. In many cases port 2 should be made active (0) when selecting SECAM-L, and port 2 should remain inactive (1) for SECAM-L'. For the other standards the tda9887 application note says that the ports should be set to active (0), but, again, that may differ depending on the precise hardware configuration. */ priv->data[1] |= cOutputPort1Inactive; priv->data[1] |= cOutputPort2Inactive; tda9887_do_config(fe); tda9887_set_insmod(fe); if (priv->mode == T_STANDBY) priv->data[1] |= cForcedMuteAudioON; tuner_dbg("writing: b=0x%02x c=0x%02x e=0x%02x\n", priv->data[1], priv->data[2], priv->data[3]); if (debug > 1) dump_write_message(fe, priv->data); if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,priv->data,4))) tuner_info("i2c i/o error: rc == %d (should be 4)\n", rc); if (debug > 2) { msleep_interruptible(1000); tda9887_status(fe); }}/* ---------------------------------------------------------------------- */static void tda9887_tuner_status(struct dvb_frontend *fe){ struct tda9887_priv *priv = fe->analog_demod_priv; tuner_info("Data bytes: b=0x%02x c=0x%02x e=0x%02x\n", priv->data[1], priv->data[2], priv->data[3]);}static int tda9887_get_afc(struct dvb_frontend *fe){ struct tda9887_priv *priv = fe->analog_demod_priv; static int AFC_BITS_2_kHz[] = { -12500, -37500, -62500, -97500, -112500, -137500, -162500, -187500, 187500, 162500, 137500, 112500, 97500 , 62500, 37500 , 12500 }; int afc=0; __u8 reg = 0; if (1 == tuner_i2c_xfer_recv(&priv->i2c_props,®,1)) afc = AFC_BITS_2_kHz[(reg>>1)&0x0f]; return afc;}static void tda9887_standby(struct dvb_frontend *fe){ struct tda9887_priv *priv = fe->analog_demod_priv; priv->mode = T_STANDBY; tda9887_configure(fe);}static void tda9887_set_params(struct dvb_frontend *fe, struct analog_parameters *params){ struct tda9887_priv *priv = fe->analog_demod_priv; priv->mode = params->mode; priv->audmode = params->audmode; priv->std = params->std; tda9887_configure(fe);}static int tda9887_set_config(struct dvb_frontend *fe, void *priv_cfg){ struct tda9887_priv *priv = fe->analog_demod_priv; priv->config = *(unsigned int *)priv_cfg; tda9887_configure(fe); return 0;}static void tda9887_release(struct dvb_frontend *fe){ struct tda9887_priv *priv = fe->analog_demod_priv; mutex_lock(&tda9887_list_mutex); if (priv) hybrid_tuner_release_state(priv); mutex_unlock(&tda9887_list_mutex); fe->analog_demod_priv = NULL;}static struct analog_demod_ops tda9887_ops = { .info = { .name = "tda9887", }, .set_params = tda9887_set_params, .standby = tda9887_standby, .tuner_status = tda9887_tuner_status, .get_afc = tda9887_get_afc, .release = tda9887_release, .set_config = tda9887_set_config,};struct dvb_frontend *tda9887_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c_adap, u8 i2c_addr){ struct tda9887_priv *priv = NULL; int instance; mutex_lock(&tda9887_list_mutex); instance = hybrid_tuner_request_state(struct tda9887_priv, priv, hybrid_tuner_instance_list, i2c_adap, i2c_addr, "tda9887"); switch (instance) { case 0: mutex_unlock(&tda9887_list_mutex); return NULL; case 1: fe->analog_demod_priv = priv; priv->mode = T_STANDBY; tuner_info("tda988[5/6/7] found\n"); break; default: fe->analog_demod_priv = priv; break; } mutex_unlock(&tda9887_list_mutex); memcpy(&fe->ops.analog_ops, &tda9887_ops, sizeof(struct analog_demod_ops)); return fe;}EXPORT_SYMBOL_GPL(tda9887_attach);MODULE_LICENSE("GPL");/* * Overrides for Emacs so that we follow Linus's tabbing style. * --------------------------------------------------------------------------- * Local variables: * c-basic-offset: 8 * End: */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?