Skip to contentSkip to conversation

Updates for tea5761 (take #2)

PATCH In review Eduardo Valentin 2 participants 8 messages Jun 9, 2008 – Jun 10, 2008 Media (V4L/DVB)

lore
Share & tools
lore
#1 lore raw

PATCH 1/3 tea5761: Add init and sleep callbacks on tea5761 tuner

In reply to Eduardo Valentin

From: Eduardo Valentin <[email protected]>

Add init and sleep callbacks on tea5761 tuner

---
 drivers/media/common/tuners/tea5761.c |   44 +++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)
drivers/media/common/tuners/tea5761.c +44 -0
index b93cdef..8e86cb2 100644
@@ -175,6 +175,48 @@ static int set_radio_freq(struct dvb_frontend *fe,
 	return 0;
 }
 
+static int tea5761_init(struct dvb_frontend *fe)
+{
+	struct tea5761_priv *priv = fe->tuner_priv;
+	unsigned char buffer[] = {0, 0, 0, 0, 0, 0, 0 };
+	int rc;
+
+	tuner_dbg("Power up radio\n");
+
+	buffer[3] = TEA5761_TNCTRL_PUPD_0;
+
+	if (debug)
+		tea5761_status_dump(buffer);
+
+	rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, ARRAY_SIZE(buffer));
+	if (rc != ARRAY_SIZE(buffer))
+		tuner_warn("i2c i/o error: rc == %d (should be %d)\n", rc,
+				ARRAY_SIZE(buffer));
+
+	return 0;
+}
+
+static int tea5761_sleep(struct dvb_frontend *fe)
+{
+	struct tea5761_priv *priv = fe->tuner_priv;
+	unsigned char buffer[] = {0, 0, 0, 0, 0, 0, 0 };
+	int rc;
+
+	tuner_dbg("Power down radio\n");
+
+	buffer[3] &= ~TEA5761_TNCTRL_PUPD_0;
+
+	if (debug)
+		tea5761_status_dump(buffer);
+
+	rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, ARRAY_SIZE(buffer));
+	if (rc != ARRAY_SIZE(buffer))
+		tuner_warn("i2c i/o error: rc == %d (should be %d)\n", rc,
+				ARRAY_SIZE(buffer));
+
+	return 0;
+}
+
 static int tea5761_read_status(struct dvb_frontend *fe, char *buffer)
 {
 	struct tea5761_priv *priv = fe->tuner_priv;
@@ -287,6 +329,8 @@ static struct dvb_tuner_ops tea5761_tuner_ops = {
 	.get_frequency     = tea5761_get_frequency,
 	.get_status        = tea5761_get_status,
 	.get_rf_strength   = tea5761_get_rf_strength,
+	.init              = tea5761_init,
+	.sleep             = tea5761_sleep,
 };
 
 struct dvb_frontend *tea5761_attach(struct dvb_frontend *fe,
Signature · 1 line
1.5.6.rc0.84.g06f60.dirty
#0 lore raw

cover Updates for tea5761 (take #2)

From: Eduardo Valentin <[email protected]>

Hi guys,

Following recommendation from v4l people, I'm sending this update to our tea5761 driver.

They already had a tuner for this device which communicates through i2c.

I needed to update it because there were some register mis-utilization.

Here is a series which updates their tuner and our driver.

After acks and merging here in linux-omap I'll send it to v4l again.

Cheers,

Eduardo Valentin (3):
tea5761: Add init and sleep callbacks on tea5761 tuner tea5761 tuner: fix registers utilization
radio-tea5761: Update driver

 drivers/media/common/tuners/tea5761.c |   55 +++-
 drivers/media/radio/Kconfig           |    1 +
 drivers/media/radio/Makefile          |    2 +
 drivers/media/radio/radio-tea5761.c   |  564 ++++++++++++++++-----------------
 4 files changed, 330 insertions(+), 292 deletions(-)
#2 lore raw

PATCH 2/3 tea5761 tuner: fix registers utilization

In reply to Eduardo Valentin

From: Eduardo Valentin <[email protected]>

Fix registers utilization.
tnctrl register was supposed to be used but it was right shifted. frqset also was being configured using incorrect equation.

---
 drivers/media/common/tuners/tea5761.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
drivers/media/common/tuners/tea5761.c +7 -4
index 8e86cb2..b3d4786 100644
@@ -101,6 +101,8 @@ struct tea5761_priv {
 
 	/* All zero = no test mode */
 
+#define TEA5761_TESTREG_TRIGFR		0x08
+
 /* MANID - Read: bytes 12 and 13 */
 
 	/* First byte - should be 0x10 */
@@ -147,20 +149,21 @@ static int set_radio_freq(struct dvb_frontend *fe,
 
 	if (params->mode == T_STANDBY) {
 		tuner_dbg("TEA5761 set to standby mode\n");
-		buffer[5] |= TEA5761_TNCTRL_MU;
+		buffer[4] |= TEA5761_TNCTRL_MU;
 	} else {
-		buffer[4] |= TEA5761_TNCTRL_PUPD_0;
+		buffer[3] |= TEA5761_TNCTRL_PUPD_0;
 	}
 
+	buffer[5] = TEA5761_TESTREG_TRIGFR;
 
 	if (params->audmode == V4L2_TUNER_MODE_MONO) {
 		tuner_dbg("TEA5761 set to mono\n");
-		buffer[5] |= TEA5761_TNCTRL_MST;
+		buffer[4] |= TEA5761_TNCTRL_MST;
 	} else {
 		tuner_dbg("TEA5761 set to stereo\n");
 	}
 
-	div = (1000 * (frq * 4 / 16 + 700 + 225) ) >> 15;
+	div = (frq * 125 / 2 - 225000) >> 13;
 	buffer[1] = (div >> 8) & 0x3f;
 	buffer[2] = div & 0xff;
 
Signature · 1 line
1.5.6.rc0.84.g06f60.dirty
#3 lore raw

PATCH 3/3 radio-tea5761: Update driver

From: Eduardo Valentin <[email protected]>

This patch updates this driver by changing the way it accesses the device. There is the tuner API which already has an implementation for tea5761.

This patch changes the driver to use tuner API.

It also changes the way ioctls are handled. This way it is more easy to deal with v4l2 and v4l calls.

Some cleans are also done.

---
 drivers/media/radio/Kconfig         |    1 +
 drivers/media/radio/Makefile        |    2 +
 drivers/media/radio/radio-tea5761.c |  564 +++++++++++++++++------------------
 3 files changed, 279 insertions(+), 288 deletions(-)
drivers/media/radio/Kconfig +1 -0
index de6ca27..b45f834 100644
@@ -341,6 +341,7 @@ config RADIO_ZOLTRIX_PORT
 
 config RADIO_TEA5761
 	tristate "Philips Semiconductors TEA5761 I2C FM Radio"
+	depends on MEDIA_TUNER_TEA5761
 	help
 	  Choose Y here if you have one of these AM/FM radio cards.
 
drivers/media/radio/Makefile +2 -0
index f5bffcc..a843007 100644
@@ -25,3 +25,5 @@ obj-$(CONFIG_USB_DSBR) += dsbr100.o
 obj-$(CONFIG_USB_SI470X) += radio-si470x.o
 
 EXTRA_CFLAGS += -Isound
+EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/
+EXTRA_CFLAGS += -Idrivers/media/common/tuners/
drivers/media/radio/radio-tea5761.c +276 -288

682 lines not on this page · raw message

Signature · 1 line
1.5.6.rc0.84.g06f60.dirty
#4 lore raw

Re: [PATCH 3/3] radio-tea5761: Update driver

Quoted 15 lines · Eduardo Valentin
drivers/media/radio/radio-tea5761.c +6 -8
+static void tea5761_set_audout_mode(struct tea5761_device *tea, int audmode)
 {
-	struct tea5761_regs *r = &tea->regs;
-
-	if (!(r->tnctrl & TEA5761_TNCTRL_PUPD0)) {
-		r->tnctrl &= ~(TEA5761_TNCTRL_AFM | TEA5761_TNCTRL_MU |
-			       TEA5761_TNCTRL_HLSI);
-		r->testreg |= TEA5761_TESTREG_TRIGFR;
-		r->tnctrl |= TEA5761_TNCTRL_PUPD0;
-		return tea5761_write_regs(tea);
+	struct dvb_frontend *fe = &tea->fe;
+	struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
+	struct analog_parameters params = {
+		.mode		= V4L2_TUNER_RADIO,
+		.frequency	= tea->freq,

drivers/media/radio/radio-tea5761.c static struct tea5761_device tea5761; · line 125

Quoted 10 lines
drivers/media/radio/radio-tea5761.c +9 -0
+		.audmode	= audmode,
+	};
+
+	if (NULL == fe_tuner_ops->set_analog_params) {
+		dev_warn(tea->dev,
+			"Tuner frontend module has no way to set frequency\n");
+		return;
 	}
+	if (!fe_tuner_ops->set_analog_params(fe, &params))
+		tea->audmode = audmode;

instead of both ifs, how about:

	if (fe_tuner_ops->set_analog_params) {
		tea->audmode =
		fe_tuner_ops->set_analog_params(fe, &params) ?
			audmode : 0;
	}
Quoted 9 lines

}

drivers/media/radio/radio-tea5761.c +7 -0
+static void tea5761_mute(struct tea5761_device *tea, int on)
+{
+	struct dvb_frontend *fe = &tea->fe;
+	struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
+	struct analog_parameters params = {
+		.mode		= on ? T_STANDBY : V4L2_TUNER_RADIO,
+		.frequency	= tea->freq,

drivers/media/radio/radio-tea5761.c static struct tea5761_device tea5761; · line 149

Quoted 10 lines
drivers/media/radio/radio-tea5761.c +9 -0
+		.audmode	= tea->audmode,
+	};
+
+	if (NULL == fe_tuner_ops->set_analog_params) {
+		dev_warn(tea->dev,
+			"Tuner frontend module has no way to set frequency\n");
+		return;
 	}
+	if (!fe_tuner_ops->set_analog_params(fe, &params))
+		tea->mute = on;

samething here.

Quoted 15 lines

}

static int tea5761_i2c_driver_probe(struct i2c_client *client,

drivers/media/radio/radio-tea5761.c +7 -1
@@ -422,12 +407,24 @@ static int tea5761_i2c_driver_probe(struct i2c_client *client,
 
 	mutex_init(&tea->mutex);
 
-	tea->i2c_dev = client;
+	/* Tuner attach */
+	if (!dvb_attach(tea5761_attach, &tea->fe, client->adapter,
+			client->addr)) {
+		dev_err(&client->dev, "Could not attach tuner\n");
+		err = -ENODEV;
+		goto exit;
+	}

drivers/media/radio/radio-tea5761.c static int tea5761_i2c_driver_probe(struct i2c_client *client, · line 426

Quoted 10 lines
drivers/media/radio/radio-tea5761.c +6 -0
+
+	/* initialize and power off the chip */
+	tea5761_power_up(tea);
+	tea5761_set_audout_mode(tea, V4L2_TUNER_MODE_STEREO);
+	tea5761_mute(tea, 0);
+	tea5761_power_down(tea);
 
 	/* V4L initialization */
 	video_dev = video_device_alloc();
 	if (video_dev == NULL) {
	if (!video_dev)
Quoted 35 lines
drivers/media/radio/radio-tea5761.c +4 -14
-		dev_err(&client->dev, "couldn't allocate memory\n");
+		dev_err(&client->dev, "Could not allocate memory\n");
 		err = -ENOMEM;
 		goto exit;
 	}
@@ -436,25 +433,15 @@ static int tea5761_i2c_driver_probe(struct i2c_client *client,
 	*video_dev = tea5761_video_device;
 	video_dev->dev = &client->dev;
 	i2c_set_clientdata(client, video_dev);
-
-	/* initialize and power off the chip */
-	tea5761_read_regs(tea);
-	tea5761_set_audout_mode(tea, V4L2_TUNER_MODE_STEREO);
-	tea5761_mute(tea, 0);
-	tea5761_power_down(tea);
-
-	tea5761.video_dev = video_dev;
-	tea5761.i2c_dev = client;
+	tea->video_dev = video_dev;
+	tea->dev = &client->dev;
 
 	err = video_register_device(video_dev, VFL_TYPE_RADIO, radio_nr);
 	if (err) {
-		dev_err(&client->dev, "couldn't register video device\n");
+		dev_err(&client->dev, "Could not register video device\n");
 		goto err_video_alloc;
 	}
 
-	dev_info(&client->dev, "tea5761 (version %d) detected\n",
-		(tea->regs.manid >> 12) & 0xf);
-
 	return 0;
 
 err_video_alloc:

drivers/media/radio/radio-tea5761.c static int __init tea5761_init(void) · line 485

Quoted 8 lines
drivers/media/radio/radio-tea5761.c +2 -1
@@ -492,7 +479,8 @@ static int __init tea5761_init(void)
 {
 	int res;
 
-	if ((res = i2c_add_driver(&tea5761_driver))) {
+	res = i2c_add_driver(&tea5761_driver);
+	if (res) {
 		printk(KERN_ERR DRIVER_NAME ": driver registration failed\n");
 		return res;

not needed, return i2c_add_driver(&tea5761_driver); is enough as i2c subsystem already prints out error messages in case of failed probe.

Quoted 1 line
(quoted diff) +0 -0
 	}
Signature · 5 lines
Best Regards,

Felipe Balbi
[email protected]
http://blog.felipebalbi.com
#5 lore raw

Re: [PATCH 3/3] radio-tea5761: Update driver

Hi Balbi,

Quoted 29 lines · Felipe Balbi
Quoted 15 lines · Eduardo Valentin
drivers/media/radio/radio-tea5761.c +6 -8
+static void tea5761_set_audout_mode(struct tea5761_device *tea, int audmode)
 {
-     struct tea5761_regs *r = &tea->regs;
-
-     if (!(r->tnctrl & TEA5761_TNCTRL_PUPD0)) {
-             r->tnctrl &= ~(TEA5761_TNCTRL_AFM | TEA5761_TNCTRL_MU |
-                            TEA5761_TNCTRL_HLSI);
-             r->testreg |= TEA5761_TESTREG_TRIGFR;
-             r->tnctrl |= TEA5761_TNCTRL_PUPD0;
-             return tea5761_write_regs(tea);
+     struct dvb_frontend *fe = &tea->fe;
+     struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
+     struct analog_parameters params = {
+             .mode           = V4L2_TUNER_RADIO,
+             .frequency      = tea->freq,

drivers/media/radio/radio-tea5761.c static struct tea5761_device tea5761; · line 125

Quoted 10 lines
drivers/media/radio/radio-tea5761.c +9 -0
+             .audmode        = audmode,
+     };
+
+     if (NULL == fe_tuner_ops->set_analog_params) {
+             dev_warn(tea->dev,
+                     "Tuner frontend module has no way to set frequency\n");
+             return;
      }
+     if (!fe_tuner_ops->set_analog_params(fe, &params))
+             tea->audmode = audmode;

instead of both ifs, how about:

Quoted 6 lines
       if (fe_tuner_ops->set_analog_params) {
               tea->audmode =
               fe_tuner_ops->set_analog_params(fe, &params) ?
                       audmode : 0;
       }
Quoted 1 line

}

I don't know. I personally do not like "silent fail" style. The way you proposed it will say nothing if set_anolog_params is not set. And that is a very important part of this code.

Quoted 12 lines
Quoted 12 lines
drivers/media/radio/radio-tea5761.c +11 -0
+static void tea5761_mute(struct tea5761_device *tea, int on)
+{
+     struct dvb_frontend *fe = &tea->fe;
+     struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
+     struct analog_parameters params = {
+             .mode           = on ? T_STANDBY : V4L2_TUNER_RADIO,
+             .frequency      = tea->freq,
+             .audmode        = tea->audmode,
+     };
+
+     if (NULL == fe_tuner_ops->set_analog_params) {
Quoted 8 lines

drivers/media/radio/radio-tea5761.c static struct tea5761_device tea5761; · line 149

Quoted 6 lines
drivers/media/radio/radio-tea5761.c +5 -0
+             dev_warn(tea->dev,
+                     "Tuner frontend module has no way to set frequency\n");
+             return;
      }
+     if (!fe_tuner_ops->set_analog_params(fe, &params))
+             tea->mute = on;

samething here.

same here.

Quoted 67 lines
Quoted 16 lines

}

static int tea5761_i2c_driver_probe(struct i2c_client *client,

drivers/media/radio/radio-tea5761.c +7 -1
@@ -422,12 +407,24 @@ static int tea5761_i2c_driver_probe(struct i2c_client *client,
 
      mutex_init(&tea->mutex);
 
-     tea->i2c_dev = client;
+     /* Tuner attach */
+     if (!dvb_attach(tea5761_attach, &tea->fe, client->adapter,
+                     client->addr)) {
+             dev_err(&client->dev, "Could not attach tuner\n");
+             err = -ENODEV;
+             goto exit;
+     }

drivers/media/radio/radio-tea5761.c static int tea5761_i2c_driver_probe(struct i2c_client *client, · line 426

Quoted 10 lines
drivers/media/radio/radio-tea5761.c +6 -0
+
+     /* initialize and power off the chip */
+     tea5761_power_up(tea);
+     tea5761_set_audout_mode(tea, V4L2_TUNER_MODE_STEREO);
+     tea5761_mute(tea, 0);
+     tea5761_power_down(tea);
 
      /* V4L initialization */
      video_dev = video_device_alloc();
      if (video_dev == NULL) {
       if (!video_dev)
Quoted 38 lines
drivers/media/radio/radio-tea5761.c +4 -14
-             dev_err(&client->dev, "couldn't allocate memory\n");
+             dev_err(&client->dev, "Could not allocate memory\n");
              err = -ENOMEM;
              goto exit;
      }
@@ -436,25 +433,15 @@ static int tea5761_i2c_driver_probe(struct i2c_client *client,
      *video_dev = tea5761_video_device;
      video_dev->dev = &client->dev;
      i2c_set_clientdata(client, video_dev);
-
-     /* initialize and power off the chip */
-     tea5761_read_regs(tea);
-     tea5761_set_audout_mode(tea, V4L2_TUNER_MODE_STEREO);
-     tea5761_mute(tea, 0);
-     tea5761_power_down(tea);
-
-     tea5761.video_dev = video_dev;
-     tea5761.i2c_dev = client;
+     tea->video_dev = video_dev;
+     tea->dev = &client->dev;
 
      err = video_register_device(video_dev, VFL_TYPE_RADIO, radio_nr);
      if (err) {
-             dev_err(&client->dev, "couldn't register video device\n");
+             dev_err(&client->dev, "Could not register video device\n");
              goto err_video_alloc;
      }
 
-     dev_info(&client->dev, "tea5761 (version %d) detected\n",
-             (tea->regs.manid >> 12) & 0xf);
-
      return 0;
 
 err_video_alloc:
@@ -492,7 +479,8 @@ static int __init tea5761_init(void)
 {
      int res;
 
Quoted 8 lines

drivers/media/radio/radio-tea5761.c static int __init tea5761_init(void) · line 485

Quoted 5 lines
drivers/media/radio/radio-tea5761.c +2 -1
-     if ((res = i2c_add_driver(&tea5761_driver))) {
+     res = i2c_add_driver(&tea5761_driver);
+     if (res) {
              printk(KERN_ERR DRIVER_NAME ": driver registration failed\n");
              return res;

not needed, return i2c_add_driver(&tea5761_driver); is enough as i2c subsystem already prints out error messages in case of failed probe.

If I understood correctly what you said, the same comment I said before also applies here.
Eventhough it prints that the probe
failed, this way I sent it says: The probe failed and "The driver registration failed". More easy
to debug the code when in a error situation.

Quoted 10 lines

Review static int __init tea5761_init(void) · line 486

Quoted 2 lines
(quoted diff) +0 -0
      }

--
Best Regards,

Felipe Balbi
[email protected]
http://blog.felipebalbi.com

Signature · 1 line
Eduardo Bezerra Valentin
#6 lore raw

Re: [PATCH 3/3] radio-tea5761: Update driver

Quoted 6 lines · Eduardo Valentin

If I understood correctly what you said, the same comment I said before also applies here.
Eventhough it prints that the probe
failed, this way I sent it says: The probe failed and "The driver registration failed". More easy
to debug the code when in a error situation.

But if probe fails, driver registration failed. The same comment Jean Delvare gave me when I was sending some isp1301 patches upstream, so later on, when this driver goes to mailine, it'll probably, if Jean happens to see this one, get commented on this point as well.

If you look at drivers/i2c/chips/*.c you'll see that only in two cases they are printing error if i2c_add_driver() fails and those are really necessary cases (check those drivers).

But anyway, if you think it's really necessary.

Signature · 5 lines
Best Regards,

Felipe Balbi
[email protected]
http://blog.felipebalbi.com
#7 lore raw

Re: [PATCH 3/3] radio-tea5761: Update driver

Hi Balbi,

Quoted 13 lines · Felipe Balbi
Quoted 6 lines · Eduardo Valentin

If I understood correctly what you said, the same comment I said before also applies here.
Eventhough it prints that the probe
failed, this way I sent it says: The probe failed and "The driver registration failed". More easy
to debug the code when in a error situation.

But if probe fails, driver registration failed. The same comment Jean Delvare gave me when I was sending some isp1301 patches upstream, so later on, when this driver goes to mailine, it'll probably, if Jean happens to see this one, get commented on this point as well.

Quoted 6 lines

If you look at drivers/i2c/chips/*.c you'll see that only in two cases they are printing error if i2c_add_driver() fails and those are really necessary cases (check those drivers).

But anyway, if you think it's really necessary.

Ok. I've just resent the whole series with this message removed. :)

Quoted 7 lines

--
Best Regards,

Felipe Balbi
[email protected]
http://blog.felipebalbi.com

Signature · 1 line
Eduardo Bezerra Valentin