Path: blob/master/drivers/media/common/tuners/tda8290.c
15112 views
/*12i2c tv tuner chip device driver3controls the philips tda8290+75 tuner chip combo.45This program is free software; you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation; either version 2 of the License, or8(at your option) any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License16along with this program; if not, write to the Free Software17Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.1819This "tda8290" module was split apart from the original "tuner" module.20*/2122#include <linux/i2c.h>23#include <linux/slab.h>24#include <linux/delay.h>25#include <linux/videodev2.h>26#include "tuner-i2c.h"27#include "tda8290.h"28#include "tda827x.h"29#include "tda18271.h"3031static int debug;32module_param(debug, int, 0644);33MODULE_PARM_DESC(debug, "enable verbose debug messages");3435static int deemphasis_50;36module_param(deemphasis_50, int, 0644);37MODULE_PARM_DESC(deemphasis_50, "0 - 75us deemphasis; 1 - 50us deemphasis");3839/* ---------------------------------------------------------------------- */4041struct tda8290_priv {42struct tuner_i2c_props i2c_props;4344unsigned char tda8290_easy_mode;4546unsigned char tda827x_addr;4748unsigned char ver;49#define TDA8290 150#define TDA8295 251#define TDA8275 452#define TDA8275A 853#define TDA18271 165455struct tda827x_config cfg;56};5758/*---------------------------------------------------------------------*/5960static int tda8290_i2c_bridge(struct dvb_frontend *fe, int close)61{62struct tda8290_priv *priv = fe->analog_demod_priv;6364unsigned char enable[2] = { 0x21, 0xC0 };65unsigned char disable[2] = { 0x21, 0x00 };66unsigned char *msg;6768if (close) {69msg = enable;70tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);71/* let the bridge stabilize */72msleep(20);73} else {74msg = disable;75tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);76}7778return 0;79}8081static int tda8295_i2c_bridge(struct dvb_frontend *fe, int close)82{83struct tda8290_priv *priv = fe->analog_demod_priv;8485unsigned char enable[2] = { 0x45, 0xc1 };86unsigned char disable[2] = { 0x46, 0x00 };87unsigned char buf[3] = { 0x45, 0x01, 0x00 };88unsigned char *msg;8990if (close) {91msg = enable;92tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);93/* let the bridge stabilize */94msleep(20);95} else {96msg = disable;97tuner_i2c_xfer_send_recv(&priv->i2c_props, msg, 1, &msg[1], 1);9899buf[2] = msg[1];100buf[2] &= ~0x04;101tuner_i2c_xfer_send(&priv->i2c_props, buf, 3);102msleep(5);103104msg[1] |= 0x04;105tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);106}107108return 0;109}110111/*---------------------------------------------------------------------*/112113static void set_audio(struct dvb_frontend *fe,114struct analog_parameters *params)115{116struct tda8290_priv *priv = fe->analog_demod_priv;117char* mode;118119if (params->std & V4L2_STD_MN) {120priv->tda8290_easy_mode = 0x01;121mode = "MN";122} else if (params->std & V4L2_STD_B) {123priv->tda8290_easy_mode = 0x02;124mode = "B";125} else if (params->std & V4L2_STD_GH) {126priv->tda8290_easy_mode = 0x04;127mode = "GH";128} else if (params->std & V4L2_STD_PAL_I) {129priv->tda8290_easy_mode = 0x08;130mode = "I";131} else if (params->std & V4L2_STD_DK) {132priv->tda8290_easy_mode = 0x10;133mode = "DK";134} else if (params->std & V4L2_STD_SECAM_L) {135priv->tda8290_easy_mode = 0x20;136mode = "L";137} else if (params->std & V4L2_STD_SECAM_LC) {138priv->tda8290_easy_mode = 0x40;139mode = "LC";140} else {141priv->tda8290_easy_mode = 0x10;142mode = "xx";143}144145if (params->mode == V4L2_TUNER_RADIO) {146/* Set TDA8295 to FM radio; Start TDA8290 with MN values */147priv->tda8290_easy_mode = (priv->ver & TDA8295) ? 0x80 : 0x01;148tuner_dbg("setting to radio FM\n");149} else {150tuner_dbg("setting tda829x to system %s\n", mode);151}152}153154static struct {155unsigned char seq[2];156} fm_mode[] = {157{ { 0x01, 0x81} }, /* Put device into expert mode */158{ { 0x03, 0x48} }, /* Disable NOTCH and VIDEO filters */159{ { 0x04, 0x04} }, /* Disable color carrier filter (SSIF) */160{ { 0x05, 0x04} }, /* ADC headroom */161{ { 0x06, 0x10} }, /* group delay flat */162163{ { 0x07, 0x00} }, /* use the same radio DTO values as a tda8295 */164{ { 0x08, 0x00} },165{ { 0x09, 0x80} },166{ { 0x0a, 0xda} },167{ { 0x0b, 0x4b} },168{ { 0x0c, 0x68} },169170{ { 0x0d, 0x00} }, /* PLL off, no video carrier detect */171{ { 0x14, 0x00} }, /* disable auto mute if no video */172};173174static void tda8290_set_params(struct dvb_frontend *fe,175struct analog_parameters *params)176{177struct tda8290_priv *priv = fe->analog_demod_priv;178179unsigned char soft_reset[] = { 0x00, 0x00 };180unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };181unsigned char expert_mode[] = { 0x01, 0x80 };182unsigned char agc_out_on[] = { 0x02, 0x00 };183unsigned char gainset_off[] = { 0x28, 0x14 };184unsigned char if_agc_spd[] = { 0x0f, 0x88 };185unsigned char adc_head_6[] = { 0x05, 0x04 };186unsigned char adc_head_9[] = { 0x05, 0x02 };187unsigned char adc_head_12[] = { 0x05, 0x01 };188unsigned char pll_bw_nom[] = { 0x0d, 0x47 };189unsigned char pll_bw_low[] = { 0x0d, 0x27 };190unsigned char gainset_2[] = { 0x28, 0x64 };191unsigned char agc_rst_on[] = { 0x0e, 0x0b };192unsigned char agc_rst_off[] = { 0x0e, 0x09 };193unsigned char if_agc_set[] = { 0x0f, 0x81 };194unsigned char addr_adc_sat = 0x1a;195unsigned char addr_agc_stat = 0x1d;196unsigned char addr_pll_stat = 0x1b;197unsigned char adc_sat, agc_stat,198pll_stat;199int i;200201set_audio(fe, params);202203if (priv->cfg.config)204tuner_dbg("tda827xa config is 0x%02x\n", priv->cfg.config);205tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);206tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);207tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);208msleep(1);209210if (params->mode == V4L2_TUNER_RADIO) {211unsigned char deemphasis[] = { 0x13, 1 };212213/* FIXME: allow using a different deemphasis */214215if (deemphasis_50)216deemphasis[1] = 2;217218for (i = 0; i < ARRAY_SIZE(fm_mode); i++)219tuner_i2c_xfer_send(&priv->i2c_props, fm_mode[i].seq, 2);220221tuner_i2c_xfer_send(&priv->i2c_props, deemphasis, 2);222} else {223expert_mode[1] = priv->tda8290_easy_mode + 0x80;224tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);225tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);226tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);227if (priv->tda8290_easy_mode & 0x60)228tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);229else230tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);231tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);232}233234235tda8290_i2c_bridge(fe, 1);236237if (fe->ops.tuner_ops.set_analog_params)238fe->ops.tuner_ops.set_analog_params(fe, params);239240for (i = 0; i < 3; i++) {241tuner_i2c_xfer_send_recv(&priv->i2c_props,242&addr_pll_stat, 1, &pll_stat, 1);243if (pll_stat & 0x80) {244tuner_i2c_xfer_send_recv(&priv->i2c_props,245&addr_adc_sat, 1,246&adc_sat, 1);247tuner_i2c_xfer_send_recv(&priv->i2c_props,248&addr_agc_stat, 1,249&agc_stat, 1);250tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);251break;252} else {253tuner_dbg("tda8290 not locked, no signal?\n");254msleep(100);255}256}257/* adjust headroom resp. gain */258if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {259tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",260agc_stat, adc_sat, pll_stat & 0x80);261tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);262msleep(100);263tuner_i2c_xfer_send_recv(&priv->i2c_props,264&addr_agc_stat, 1, &agc_stat, 1);265tuner_i2c_xfer_send_recv(&priv->i2c_props,266&addr_pll_stat, 1, &pll_stat, 1);267if ((agc_stat > 115) || !(pll_stat & 0x80)) {268tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",269agc_stat, pll_stat & 0x80);270if (priv->cfg.agcf)271priv->cfg.agcf(fe);272msleep(100);273tuner_i2c_xfer_send_recv(&priv->i2c_props,274&addr_agc_stat, 1,275&agc_stat, 1);276tuner_i2c_xfer_send_recv(&priv->i2c_props,277&addr_pll_stat, 1,278&pll_stat, 1);279if((agc_stat > 115) || !(pll_stat & 0x80)) {280tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);281tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);282tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);283msleep(100);284}285}286}287288/* l/ l' deadlock? */289if(priv->tda8290_easy_mode & 0x60) {290tuner_i2c_xfer_send_recv(&priv->i2c_props,291&addr_adc_sat, 1,292&adc_sat, 1);293tuner_i2c_xfer_send_recv(&priv->i2c_props,294&addr_pll_stat, 1,295&pll_stat, 1);296if ((adc_sat > 20) || !(pll_stat & 0x80)) {297tuner_dbg("trying to resolve SECAM L deadlock\n");298tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);299msleep(40);300tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);301}302}303304tda8290_i2c_bridge(fe, 0);305tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);306}307308/*---------------------------------------------------------------------*/309310static void tda8295_power(struct dvb_frontend *fe, int enable)311{312struct tda8290_priv *priv = fe->analog_demod_priv;313unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */314315tuner_i2c_xfer_send_recv(&priv->i2c_props, &buf[0], 1, &buf[1], 1);316317if (enable)318buf[1] = 0x01;319else320buf[1] = 0x03;321322tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);323}324325static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)326{327struct tda8290_priv *priv = fe->analog_demod_priv;328unsigned char buf[] = { 0x01, 0x00 };329330tuner_i2c_xfer_send_recv(&priv->i2c_props, &buf[0], 1, &buf[1], 1);331332if (enable)333buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */334else335buf[1] = 0x00; /* reset active bit */336337tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);338}339340static void tda8295_set_video_std(struct dvb_frontend *fe)341{342struct tda8290_priv *priv = fe->analog_demod_priv;343unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };344345tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);346347tda8295_set_easy_mode(fe, 1);348msleep(20);349tda8295_set_easy_mode(fe, 0);350}351352/*---------------------------------------------------------------------*/353354static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)355{356struct tda8290_priv *priv = fe->analog_demod_priv;357unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */358359tuner_i2c_xfer_send_recv(&priv->i2c_props, &buf[0], 1, &buf[1], 1);360361if (enable)362buf[1] &= ~0x40;363else364buf[1] |= 0x40;365366tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);367}368369static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)370{371struct tda8290_priv *priv = fe->analog_demod_priv;372unsigned char set_gpio_cf[] = { 0x44, 0x00 };373unsigned char set_gpio_val[] = { 0x46, 0x00 };374375tuner_i2c_xfer_send_recv(&priv->i2c_props,376&set_gpio_cf[0], 1, &set_gpio_cf[1], 1);377tuner_i2c_xfer_send_recv(&priv->i2c_props,378&set_gpio_val[0], 1, &set_gpio_val[1], 1);379380set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */381382if (enable) {383set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */384set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */385}386tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);387tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);388}389390static int tda8295_has_signal(struct dvb_frontend *fe)391{392struct tda8290_priv *priv = fe->analog_demod_priv;393394unsigned char hvpll_stat = 0x26;395unsigned char ret;396397tuner_i2c_xfer_send_recv(&priv->i2c_props, &hvpll_stat, 1, &ret, 1);398return (ret & 0x01) ? 65535 : 0;399}400401/*---------------------------------------------------------------------*/402403static void tda8295_set_params(struct dvb_frontend *fe,404struct analog_parameters *params)405{406struct tda8290_priv *priv = fe->analog_demod_priv;407408unsigned char blanking_mode[] = { 0x1d, 0x00 };409410set_audio(fe, params);411412tuner_dbg("%s: freq = %d\n", __func__, params->frequency);413414tda8295_power(fe, 1);415tda8295_agc1_out(fe, 1);416417tuner_i2c_xfer_send_recv(&priv->i2c_props,418&blanking_mode[0], 1, &blanking_mode[1], 1);419420tda8295_set_video_std(fe);421422blanking_mode[1] = 0x03;423tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);424msleep(20);425426tda8295_i2c_bridge(fe, 1);427428if (fe->ops.tuner_ops.set_analog_params)429fe->ops.tuner_ops.set_analog_params(fe, params);430431if (priv->cfg.agcf)432priv->cfg.agcf(fe);433434if (tda8295_has_signal(fe))435tuner_dbg("tda8295 is locked\n");436else437tuner_dbg("tda8295 not locked, no signal?\n");438439tda8295_i2c_bridge(fe, 0);440}441442/*---------------------------------------------------------------------*/443444static int tda8290_has_signal(struct dvb_frontend *fe)445{446struct tda8290_priv *priv = fe->analog_demod_priv;447448unsigned char i2c_get_afc[1] = { 0x1B };449unsigned char afc = 0;450451tuner_i2c_xfer_send_recv(&priv->i2c_props,452i2c_get_afc, ARRAY_SIZE(i2c_get_afc), &afc, 1);453return (afc & 0x80)? 65535:0;454}455456/*---------------------------------------------------------------------*/457458static void tda8290_standby(struct dvb_frontend *fe)459{460struct tda8290_priv *priv = fe->analog_demod_priv;461462unsigned char cb1[] = { 0x30, 0xD0 };463unsigned char tda8290_standby[] = { 0x00, 0x02 };464unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };465struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};466467tda8290_i2c_bridge(fe, 1);468if (priv->ver & TDA8275A)469cb1[1] = 0x90;470i2c_transfer(priv->i2c_props.adap, &msg, 1);471tda8290_i2c_bridge(fe, 0);472tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);473tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);474}475476static void tda8295_standby(struct dvb_frontend *fe)477{478tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */479480tda8295_power(fe, 0);481}482483static void tda8290_init_if(struct dvb_frontend *fe)484{485struct tda8290_priv *priv = fe->analog_demod_priv;486487unsigned char set_VS[] = { 0x30, 0x6F };488unsigned char set_GP00_CF[] = { 0x20, 0x01 };489unsigned char set_GP01_CF[] = { 0x20, 0x0B };490491if ((priv->cfg.config == 1) || (priv->cfg.config == 2))492tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);493else494tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);495tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);496}497498static void tda8295_init_if(struct dvb_frontend *fe)499{500struct tda8290_priv *priv = fe->analog_demod_priv;501502static unsigned char set_adc_ctl[] = { 0x33, 0x14 };503static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };504static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };505static unsigned char set_pll_reg0[] = { 0x38, 0x23 };506static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };507static unsigned char set_pll_reg10[] = { 0x42, 0x61 };508static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };509510tda8295_power(fe, 1);511512tda8295_set_easy_mode(fe, 0);513tda8295_set_video_std(fe);514515tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);516tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);517tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);518tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);519tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);520tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);521tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);522523tda8295_agc1_out(fe, 0);524tda8295_agc2_out(fe, 0);525}526527static void tda8290_init_tuner(struct dvb_frontend *fe)528{529struct tda8290_priv *priv = fe->analog_demod_priv;530unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,5310x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };532unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,5330x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };534struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,535.buf=tda8275_init, .len = 14};536if (priv->ver & TDA8275A)537msg.buf = tda8275a_init;538539tda8290_i2c_bridge(fe, 1);540i2c_transfer(priv->i2c_props.adap, &msg, 1);541tda8290_i2c_bridge(fe, 0);542}543544/*---------------------------------------------------------------------*/545546static void tda829x_release(struct dvb_frontend *fe)547{548struct tda8290_priv *priv = fe->analog_demod_priv;549550/* only try to release the tuner if we've551* attached it from within this module */552if (priv->ver & (TDA18271 | TDA8275 | TDA8275A))553if (fe->ops.tuner_ops.release)554fe->ops.tuner_ops.release(fe);555556kfree(fe->analog_demod_priv);557fe->analog_demod_priv = NULL;558}559560static struct tda18271_config tda829x_tda18271_config = {561.gate = TDA18271_GATE_ANALOG,562};563564static int tda829x_find_tuner(struct dvb_frontend *fe)565{566struct tda8290_priv *priv = fe->analog_demod_priv;567struct analog_demod_ops *analog_ops = &fe->ops.analog_ops;568int i, ret, tuners_found;569u32 tuner_addrs;570u8 data;571struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };572573if (!analog_ops->i2c_gate_ctrl) {574printk(KERN_ERR "tda8290: no gate control were provided!\n");575576return -EINVAL;577}578579analog_ops->i2c_gate_ctrl(fe, 1);580581/* probe for tuner chip */582tuners_found = 0;583tuner_addrs = 0;584for (i = 0x60; i <= 0x63; i++) {585msg.addr = i;586ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);587if (ret == 1) {588tuners_found++;589tuner_addrs = (tuner_addrs << 8) + i;590}591}592/* if there is more than one tuner, we expect the right one is593behind the bridge and we choose the highest address that doesn't594give a response now595*/596597analog_ops->i2c_gate_ctrl(fe, 0);598599if (tuners_found > 1)600for (i = 0; i < tuners_found; i++) {601msg.addr = tuner_addrs & 0xff;602ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);603if (ret == 1)604tuner_addrs = tuner_addrs >> 8;605else606break;607}608609if (tuner_addrs == 0) {610tuner_addrs = 0x60;611tuner_info("could not clearly identify tuner address, "612"defaulting to %x\n", tuner_addrs);613} else {614tuner_addrs = tuner_addrs & 0xff;615tuner_info("setting tuner address to %x\n", tuner_addrs);616}617priv->tda827x_addr = tuner_addrs;618msg.addr = tuner_addrs;619620analog_ops->i2c_gate_ctrl(fe, 1);621ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);622623if (ret != 1) {624tuner_warn("tuner access failed!\n");625analog_ops->i2c_gate_ctrl(fe, 0);626return -EREMOTEIO;627}628629if ((data == 0x83) || (data == 0x84)) {630priv->ver |= TDA18271;631tda829x_tda18271_config.config = priv->cfg.config;632dvb_attach(tda18271_attach, fe, priv->tda827x_addr,633priv->i2c_props.adap, &tda829x_tda18271_config);634} else {635if ((data & 0x3c) == 0)636priv->ver |= TDA8275;637else638priv->ver |= TDA8275A;639640dvb_attach(tda827x_attach, fe, priv->tda827x_addr,641priv->i2c_props.adap, &priv->cfg);642priv->cfg.switch_addr = priv->i2c_props.addr;643}644if (fe->ops.tuner_ops.init)645fe->ops.tuner_ops.init(fe);646647if (fe->ops.tuner_ops.sleep)648fe->ops.tuner_ops.sleep(fe);649650analog_ops->i2c_gate_ctrl(fe, 0);651652return 0;653}654655static int tda8290_probe(struct tuner_i2c_props *i2c_props)656{657#define TDA8290_ID 0x89658u8 reg = 0x1f, id;659struct i2c_msg msg_read[] = {660{ .addr = i2c_props->addr, .flags = 0, .len = 1, .buf = ® },661{ .addr = i2c_props->addr, .flags = I2C_M_RD, .len = 1, .buf = &id },662};663664/* detect tda8290 */665if (i2c_transfer(i2c_props->adap, msg_read, 2) != 2) {666printk(KERN_WARNING "%s: couldn't read register 0x%02x\n",667__func__, reg);668return -ENODEV;669}670671if (id == TDA8290_ID) {672if (debug)673printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",674__func__, i2c_adapter_id(i2c_props->adap),675i2c_props->addr);676return 0;677}678return -ENODEV;679}680681static int tda8295_probe(struct tuner_i2c_props *i2c_props)682{683#define TDA8295_ID 0x8a684#define TDA8295C2_ID 0x8b685u8 reg = 0x2f, id;686struct i2c_msg msg_read[] = {687{ .addr = i2c_props->addr, .flags = 0, .len = 1, .buf = ® },688{ .addr = i2c_props->addr, .flags = I2C_M_RD, .len = 1, .buf = &id },689};690691/* detect tda8295 */692if (i2c_transfer(i2c_props->adap, msg_read, 2) != 2) {693printk(KERN_WARNING "%s: couldn't read register 0x%02x\n",694__func__, reg);695return -ENODEV;696}697698if ((id & 0xfe) == TDA8295_ID) {699if (debug)700printk(KERN_DEBUG "%s: %s detected @ %d-%04x\n",701__func__, (id == TDA8295_ID) ?702"tda8295c1" : "tda8295c2",703i2c_adapter_id(i2c_props->adap),704i2c_props->addr);705return 0;706}707708return -ENODEV;709}710711static struct analog_demod_ops tda8290_ops = {712.set_params = tda8290_set_params,713.has_signal = tda8290_has_signal,714.standby = tda8290_standby,715.release = tda829x_release,716.i2c_gate_ctrl = tda8290_i2c_bridge,717};718719static struct analog_demod_ops tda8295_ops = {720.set_params = tda8295_set_params,721.has_signal = tda8295_has_signal,722.standby = tda8295_standby,723.release = tda829x_release,724.i2c_gate_ctrl = tda8295_i2c_bridge,725};726727struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,728struct i2c_adapter *i2c_adap, u8 i2c_addr,729struct tda829x_config *cfg)730{731struct tda8290_priv *priv = NULL;732char *name;733734priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);735if (priv == NULL)736return NULL;737fe->analog_demod_priv = priv;738739priv->i2c_props.addr = i2c_addr;740priv->i2c_props.adap = i2c_adap;741priv->i2c_props.name = "tda829x";742if (cfg)743priv->cfg.config = cfg->lna_cfg;744745if (tda8290_probe(&priv->i2c_props) == 0) {746priv->ver = TDA8290;747memcpy(&fe->ops.analog_ops, &tda8290_ops,748sizeof(struct analog_demod_ops));749}750751if (tda8295_probe(&priv->i2c_props) == 0) {752priv->ver = TDA8295;753memcpy(&fe->ops.analog_ops, &tda8295_ops,754sizeof(struct analog_demod_ops));755}756757if (!(cfg) || (TDA829X_PROBE_TUNER == cfg->probe_tuner)) {758tda8295_power(fe, 1);759if (tda829x_find_tuner(fe) < 0)760goto fail;761}762763switch (priv->ver) {764case TDA8290:765name = "tda8290";766break;767case TDA8295:768name = "tda8295";769break;770case TDA8290 | TDA8275:771name = "tda8290+75";772break;773case TDA8295 | TDA8275:774name = "tda8295+75";775break;776case TDA8290 | TDA8275A:777name = "tda8290+75a";778break;779case TDA8295 | TDA8275A:780name = "tda8295+75a";781break;782case TDA8290 | TDA18271:783name = "tda8290+18271";784break;785case TDA8295 | TDA18271:786name = "tda8295+18271";787break;788default:789goto fail;790}791tuner_info("type set to %s\n", name);792793fe->ops.analog_ops.info.name = name;794795if (priv->ver & TDA8290) {796if (priv->ver & (TDA8275 | TDA8275A))797tda8290_init_tuner(fe);798tda8290_init_if(fe);799} else if (priv->ver & TDA8295)800tda8295_init_if(fe);801802return fe;803804fail:805memset(&fe->ops.analog_ops, 0, sizeof(struct analog_demod_ops));806807tda829x_release(fe);808return NULL;809}810EXPORT_SYMBOL_GPL(tda829x_attach);811812int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr)813{814struct tuner_i2c_props i2c_props = {815.adap = i2c_adap,816.addr = i2c_addr,817};818819unsigned char soft_reset[] = { 0x00, 0x00 };820unsigned char easy_mode_b[] = { 0x01, 0x02 };821unsigned char easy_mode_g[] = { 0x01, 0x04 };822unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };823unsigned char addr_dto_lsb = 0x07;824unsigned char data;825#define PROBE_BUFFER_SIZE 8826unsigned char buf[PROBE_BUFFER_SIZE];827int i;828829/* rule out tda9887, which would return the same byte repeatedly */830tuner_i2c_xfer_send_recv(&i2c_props,831soft_reset, 1, buf, PROBE_BUFFER_SIZE);832for (i = 1; i < PROBE_BUFFER_SIZE; i++) {833if (buf[i] != buf[0])834break;835}836837/* all bytes are equal, not a tda829x - probably a tda9887 */838if (i == PROBE_BUFFER_SIZE)839return -ENODEV;840841if ((tda8290_probe(&i2c_props) == 0) ||842(tda8295_probe(&i2c_props) == 0))843return 0;844845/* fall back to old probing method */846tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);847tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);848tuner_i2c_xfer_send_recv(&i2c_props, &addr_dto_lsb, 1, &data, 1);849if (data == 0) {850tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);851tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);852tuner_i2c_xfer_send_recv(&i2c_props,853&addr_dto_lsb, 1, &data, 1);854if (data == 0x7b) {855return 0;856}857}858tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);859return -ENODEV;860}861EXPORT_SYMBOL_GPL(tda829x_probe);862863MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");864MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");865MODULE_LICENSE("GPL");866867/*868* Overrides for Emacs so that we follow Linus's tabbing style.869* ---------------------------------------------------------------------------870* Local variables:871* c-basic-offset: 8872* End:873*/874875876