X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=drivers%2Fmedia%2Fdvb%2Ffrontends%2Fnxt200x.c;h=84b62881cea7f81b459924b5b1646d2c07b246a0;hb=ec637e3ffb6b978143652477c7c5f96c9519b691;hp=1d729be9b75c6f0891fca6f49bbee73b6456f6ec;hpb=04a45929e7f00ed4fc7b1d375397f808c8a5d0eb;p=firefly-linux-kernel-4.4.55.git diff --git a/drivers/media/dvb/frontends/nxt200x.c b/drivers/media/dvb/frontends/nxt200x.c index 1d729be9b75c..84b62881cea7 100644 --- a/drivers/media/dvb/frontends/nxt200x.c +++ b/drivers/media/dvb/frontends/nxt200x.c @@ -44,6 +44,8 @@ #include #include #include +#include +#include #include "dvb_frontend.h" #include "dvb-pll.h" @@ -239,26 +241,16 @@ static int nxt200x_readreg_multibyte (struct nxt200x_state* state, u8 reg, u8* d buf = 0x80; nxt200x_writebytes(state, 0x21, &buf, 1); - /* read status */ - nxt200x_readbytes(state, 0x21, &buf, 1); - - if (buf == 0) - { - /* read the actual data */ - for(i = 0; i < len; i++) { - nxt200x_readbytes(state, 0x36 + i, &data[i], 1); - } - return 0; + /* read the actual data */ + for(i = 0; i < len; i++) { + nxt200x_readbytes(state, 0x36 + i, &data[i], 1); } + return 0; break; default: return -EINVAL; break; } - - printk(KERN_WARNING "nxt200x: Error reading multireg register 0x%02X\n",reg); - - return 0; } static void nxt200x_microcontroller_stop (struct nxt200x_state* state) @@ -342,50 +334,56 @@ static int nxt200x_writetuner (struct nxt200x_state* state, u8* data) dprintk("Tuner Bytes: %02X %02X %02X %02X\n", data[0], data[1], data[2], data[3]); - /* if pll is a Philips TUV1236D then write directly to tuner */ - if (strcmp(state->config->pll_desc->name, "Philips TUV1236D") == 0) { - if (i2c_writebytes(state, state->config->pll_address, data, 4)) - printk(KERN_WARNING "nxt200x: error writing to tuner\n"); - /* wait until we have a lock */ - while (count < 20) { - i2c_readbytes(state, state->config->pll_address, &buf, 1); - if (buf & 0x40) - return 0; - msleep(100); - count++; - } - printk("nxt200x: timeout waiting for tuner lock\n"); - return 0; - } else { - /* set the i2c transfer speed to the tuner */ - buf = 0x03; - nxt200x_writebytes(state, 0x20, &buf, 1); - - /* setup to transfer 4 bytes via i2c */ - buf = 0x04; - nxt200x_writebytes(state, 0x34, &buf, 1); - - /* write actual tuner bytes */ - nxt200x_writebytes(state, 0x36, data, 4); - - /* set tuner i2c address */ - buf = state->config->pll_address; - nxt200x_writebytes(state, 0x35, &buf, 1); - - /* write UC Opmode to begin transfer */ - buf = 0x80; - nxt200x_writebytes(state, 0x21, &buf, 1); - - while (count < 20) { - nxt200x_readbytes(state, 0x21, &buf, 1); - if ((buf & 0x80)== 0x00) - return 0; - msleep(100); - count++; - } - printk("nxt200x: timeout error writing tuner\n"); - return 0; + /* if NXT2004, write directly to tuner. if NXT2002, write through NXT chip. + * direct write is required for Philips TUV1236D and ALPS TDHU2 */ + switch (state->demod_chip) { + case NXT2004: + if (i2c_writebytes(state, state->config->pll_address, data, 4)) + printk(KERN_WARNING "nxt200x: error writing to tuner\n"); + /* wait until we have a lock */ + while (count < 20) { + i2c_readbytes(state, state->config->pll_address, &buf, 1); + if (buf & 0x40) + return 0; + msleep(100); + count++; + } + printk("nxt2004: timeout waiting for tuner lock\n"); + break; + case NXT2002: + /* set the i2c transfer speed to the tuner */ + buf = 0x03; + nxt200x_writebytes(state, 0x20, &buf, 1); + + /* setup to transfer 4 bytes via i2c */ + buf = 0x04; + nxt200x_writebytes(state, 0x34, &buf, 1); + + /* write actual tuner bytes */ + nxt200x_writebytes(state, 0x36, data, 4); + + /* set tuner i2c address */ + buf = state->config->pll_address; + nxt200x_writebytes(state, 0x35, &buf, 1); + + /* write UC Opmode to begin transfer */ + buf = 0x80; + nxt200x_writebytes(state, 0x21, &buf, 1); + + while (count < 20) { + nxt200x_readbytes(state, 0x21, &buf, 1); + if ((buf & 0x80)== 0x00) + return 0; + msleep(100); + count++; + } + printk("nxt2002: timeout error writing tuner\n"); + break; + default: + return -EINVAL; + break; } + return 0; } static void nxt200x_agc_reset(struct nxt200x_state* state) @@ -557,14 +555,21 @@ static int nxt200x_setup_frontend_parameters (struct dvb_frontend* fe, case QAM_256: /* Set punctured clock for QAM */ /* This is just a guess since I am unable to test it */ - state->config->set_ts_params(fe, 1); + if (state->config->set_ts_params) + state->config->set_ts_params(fe, 1); - /* set to use cable input */ - buf[3] |= 0x08; + /* set input */ + if (state->config->set_pll_input) + state->config->set_pll_input(buf, 1); break; case VSB_8: /* Set non-punctured clock for VSB */ - state->config->set_ts_params(fe, 0); + if (state->config->set_ts_params) + state->config->set_ts_params(fe, 0); + + /* set input */ + if (state->config->set_pll_input) + state->config->set_pll_input(buf, 0); break; default: return -EINVAL; @@ -1157,8 +1162,7 @@ struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* config, return &state->frontend; error: - if (state) - kfree(state); + kfree(state); printk("Unknown/Unsupported NXT chip: %02X %02X %02X %02X %02X\n", buf[0], buf[1], buf[2], buf[3], buf[4]); return NULL;