Skip to content

Commit

Permalink
V4L/DVB (7393): tda827x: fixed support of tuners with LNA
Browse files Browse the repository at this point in the history
Tuner refactoring broke support of tuners with LNA configurations 1 and 2
for both, analog TV and DVB-T.
Additionally, this patch initializes the saa713x gpios defined by the gpiomask
at driver init to avoid undefined stated at dvb.

Signed-off-by: Hartmut Hackmann <hartmut.hackmann@t-online.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
  • Loading branch information
Hartmut Hackmann authored and Mauro Carvalho Chehab committed Apr 24, 2008
1 parent 5823b3a commit 7bff4b4
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 195 deletions.
1 change: 0 additions & 1 deletion drivers/media/dvb/frontends/tda1004x.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ struct tda1004x_config

/* slave address and configuration of the tuner */
u8 tuner_address;
u8 tuner_config;
u8 antenna_switch;

/* if the board uses another I2c Bridge (tda8290), its address */
Expand Down
163 changes: 84 additions & 79 deletions drivers/media/dvb/frontends/tda827x.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static int tda827xo_set_params(struct dvb_frontend *fe,
int i, tuner_freq, if_freq;
u32 N;

dprintk("%s:\n", __FUNCTION__);
dprintk("%s:\n", __func__);
switch (params->u.ofdm.bandwidth) {
case BANDWIDTH_6_MHZ:
if_freq = 4000000;
Expand Down Expand Up @@ -186,7 +186,7 @@ static int tda827xo_set_params(struct dvb_frontend *fe,
fe->ops.i2c_gate_ctrl(fe, 1);
if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
printk("%s: could not write to tuner at addr: 0x%02x\n",
__FUNCTION__, priv->i2c_addr << 1);
__func__, priv->i2c_addr << 1);
return -EIO;
}
msleep(500);
Expand All @@ -212,7 +212,7 @@ static int tda827xo_sleep(struct dvb_frontend *fe)
struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
.buf = buf, .len = sizeof(buf) };

dprintk("%s:\n", __FUNCTION__);
dprintk("%s:\n", __func__);
if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 1);
i2c_transfer(priv->i2c_adap, &msg, 1);
Expand Down Expand Up @@ -389,6 +389,79 @@ static struct tda827xa_data tda827xa_analog[] = {
{ .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
};

static int tda827xa_sleep(struct dvb_frontend *fe)
{
struct tda827x_priv *priv = fe->tuner_priv;
static u8 buf[] = { 0x30, 0x90 };
struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
.buf = buf, .len = sizeof(buf) };

dprintk("%s:\n", __func__);
if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 1);

i2c_transfer(priv->i2c_adap, &msg, 1);

if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 0);

if (priv->cfg && priv->cfg->sleep)
priv->cfg->sleep(fe);

return 0;
}

static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
struct analog_parameters *params)
{
struct tda827x_priv *priv = fe->tuner_priv;
unsigned char buf[] = {0x22, 0x01};
int arg;
int gp_func;
struct i2c_msg msg = { .addr = priv->cfg->switch_addr, .flags = 0,
.buf = buf, .len = sizeof(buf) };

if (NULL == priv->cfg) {
dprintk("tda827x_config not defined, cannot set LNA gain!\n");
return;
}
if (priv->cfg->config) {
if (high)
dprintk("setting LNA to high gain\n");
else
dprintk("setting LNA to low gain\n");
}
switch (priv->cfg->config) {
case 0: /* no LNA */
break;
case 1: /* switch is GPIO 0 of tda8290 */
case 2:
if (params == NULL) {
gp_func = 0;
arg = 0;
} else {
/* turn Vsync on */
gp_func = 1;
if (params->std & V4L2_STD_MN)
arg = 1;
else
arg = 0;
}
if (priv->cfg->tuner_callback)
priv->cfg->tuner_callback(priv->i2c_adap->algo_data,
gp_func, arg);
buf[1] = high ? 0 : 1;
if (priv->cfg->config == 2)
buf[1] = high ? 1 : 0;
i2c_transfer(priv->i2c_adap, &msg, 1);
break;
case 3: /* switch with GPIO of saa713x */
if (priv->cfg->tuner_callback)
priv->cfg->tuner_callback(priv->i2c_adap->algo_data, 0, high);
break;
}
}

static int tda827xa_set_params(struct dvb_frontend *fe,
struct dvb_frontend_parameters *params)
{
Expand All @@ -401,9 +474,9 @@ static int tda827xa_set_params(struct dvb_frontend *fe,
int i, tuner_freq, if_freq;
u32 N;

dprintk("%s:\n", __FUNCTION__);
if (priv->cfg && priv->cfg->lna_gain)
priv->cfg->lna_gain(fe, 1);
dprintk("%s:\n", __func__);

tda827xa_lna_gain(fe, 1, NULL);
msleep(20);

switch (params->u.ofdm.bandwidth) {
Expand Down Expand Up @@ -444,7 +517,7 @@ static int tda827xa_set_params(struct dvb_frontend *fe,
fe->ops.i2c_gate_ctrl(fe, 1);
if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
printk("%s: could not write to tuner at addr: 0x%02x\n",
__FUNCTION__, priv->i2c_addr << 1);
__func__, priv->i2c_addr << 1);
return -EIO;
}
buf[0] = 0x90;
Expand Down Expand Up @@ -474,8 +547,7 @@ static int tda827xa_set_params(struct dvb_frontend *fe,
buf[1] >>= 4;
dprintk("tda8275a AGC2 gain is: %d\n", buf[1]);
if ((buf[1]) < 2) {
if (priv->cfg && priv->cfg->lna_gain)
priv->cfg->lna_gain(fe, 0);
tda827xa_lna_gain(fe, 0, NULL);
buf[0] = 0x60;
buf[1] = 0x0c;
if (fe->ops.i2c_gate_ctrl)
Expand Down Expand Up @@ -523,73 +595,6 @@ static int tda827xa_set_params(struct dvb_frontend *fe,
return 0;
}

static int tda827xa_sleep(struct dvb_frontend *fe)
{
struct tda827x_priv *priv = fe->tuner_priv;
static u8 buf[] = { 0x30, 0x90 };
struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
.buf = buf, .len = sizeof(buf) };

dprintk("%s:\n", __FUNCTION__);
if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 1);

i2c_transfer(priv->i2c_adap, &msg, 1);

if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 0);

if (priv->cfg && priv->cfg->sleep)
priv->cfg->sleep(fe);

return 0;
}

/* ------------------------------------------------------------------ */

static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
struct analog_parameters *params)
{
struct tda827x_priv *priv = fe->tuner_priv;
unsigned char buf[] = {0x22, 0x01};
int arg;
struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
.buf = buf, .len = sizeof(buf) };

if (NULL == priv->cfg) {
dprintk("tda827x_config not defined, cannot set LNA gain!\n");
return;
}

if (priv->cfg->config) {
if (high)
dprintk("setting LNA to high gain\n");
else
dprintk("setting LNA to low gain\n");
}
switch (*priv->cfg->config) {
case 0: /* no LNA */
break;
case 1: /* switch is GPIO 0 of tda8290 */
case 2:
/* turn Vsync on */
if (params->std & V4L2_STD_MN)
arg = 1;
else
arg = 0;
if (priv->cfg->tuner_callback)
priv->cfg->tuner_callback(priv, 1, arg);
buf[1] = high ? 0 : 1;
if (*priv->cfg->config == 2)
buf[1] = high ? 1 : 0;
i2c_transfer(priv->i2c_adap, &msg, 1);
break;
case 3: /* switch with GPIO of saa713x */
if (priv->cfg->tuner_callback)
priv->cfg->tuner_callback(priv, 0, high);
break;
}
}

static int tda827xa_set_analog_params(struct dvb_frontend *fe,
struct analog_parameters *params)
Expand Down Expand Up @@ -724,7 +729,7 @@ static int tda827x_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
static int tda827x_init(struct dvb_frontend *fe)
{
struct tda827x_priv *priv = fe->tuner_priv;
dprintk("%s:\n", __FUNCTION__);
dprintk("%s:\n", __func__);
if (priv->cfg && priv->cfg->init)
priv->cfg->init(fe);

Expand Down Expand Up @@ -792,7 +797,7 @@ static int tda827x_probe_version(struct dvb_frontend *fe)
fe->ops.i2c_gate_ctrl(fe, 1);
if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
printk("%s: could not read from tuner at addr: 0x%02x\n",
__FUNCTION__, msg.addr << 1);
__func__, msg.addr << 1);
return -EIO;
}
if ((data & 0x3c) == 0) {
Expand All @@ -816,7 +821,7 @@ struct dvb_frontend *tda827x_attach(struct dvb_frontend *fe, int addr,
{
struct tda827x_priv *priv = NULL;

dprintk("%s:\n", __FUNCTION__);
dprintk("%s:\n", __func__);
priv = kzalloc(sizeof(struct tda827x_priv), GFP_KERNEL);
if (priv == NULL)
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions drivers/media/dvb/frontends/tda827x.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
struct tda827x_config
{
/* saa7134 - provided callbacks */
void (*lna_gain) (struct dvb_frontend *fe, int high);
int (*init) (struct dvb_frontend *fe);
int (*sleep) (struct dvb_frontend *fe);

/* interface to tda829x driver */
unsigned int *config;
unsigned int config;
int switch_addr;
int (*tuner_callback) (void *dev, int command, int arg);

void (*agcf)(struct dvb_frontend *fe);
Expand Down
13 changes: 7 additions & 6 deletions drivers/media/video/saa7134/saa7134-cards.c
Original file line number Diff line number Diff line change
Expand Up @@ -5260,12 +5260,13 @@ int saa7134_tuner_callback(void *priv, int command, int arg)
{
struct i2c_algo_bit_data *i2c_algo = priv;
struct saa7134_dev *dev = i2c_algo->data;

switch (dev->tuner_type) {
case TUNER_PHILIPS_TDA8290:
return saa7134_tda8290_callback(dev, command, arg);
case TUNER_XC2028:
return saa7134_xc2028_callback(dev, command, arg);
if (dev != NULL) {
switch (dev->tuner_type) {
case TUNER_PHILIPS_TDA8290:
return saa7134_tda8290_callback(dev, command, arg);
case TUNER_XC2028:
return saa7134_xc2028_callback(dev, command, arg);
}
}
return -EINVAL;
}
Expand Down
6 changes: 6 additions & 0 deletions drivers/media/video/saa7134/saa7134-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
struct saa7134_dev *dev;
struct saa7134_mpeg_ops *mops;
int err;
int mask;

dev = kzalloc(sizeof(*dev),GFP_KERNEL);
if (NULL == dev)
Expand Down Expand Up @@ -1061,6 +1062,11 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
if (TUNER_ABSENT != dev->tuner_type)
saa7134_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL);

if (card(dev).gpiomask != 0) {
mask = card(dev).gpiomask;
saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, mask, mask);
saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, mask, 0);
}
return 0;

fail4:
Expand Down
Loading

0 comments on commit 7bff4b4

Please sign in to comment.