public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@redhat.com>
To: Srinivasa.Deevi@conexant.com, Palash.Bandyopadhyay@conexant.com,
	dheitmueller@kernellabs.com,
	Linux Media Mailing List <linux-media@vger.kernel.org>
Subject: [PATCH 08/10] V4L/DVB: tda18271: allow restricting max out to 4 bytes
Date: Tue, 28 Sep 2010 15:46:59 -0300	[thread overview]
Message-ID: <20100928154659.0e7e4147@pedra> (raw)
In-Reply-To: <cover.1285699057.git.mchehab@redhat.com>

By default, tda18271 tries to optimize I2C bus by updating all registers
at the same time. Unfortunately, some devices doesn't support it.

The current logic has a problem when small_i2c is equal to 8, since there
are some transfers using 11 + 1 bytes.

Fix the problem by enforcing the max size at the right place, and allows
reducing it to max = 3 + 1.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

diff --git a/drivers/media/common/tuners/tda18271-common.c b/drivers/media/common/tuners/tda18271-common.c
index e1f6782..195b30e 100644
--- a/drivers/media/common/tuners/tda18271-common.c
+++ b/drivers/media/common/tuners/tda18271-common.c
@@ -193,20 +193,46 @@ int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len)
 	unsigned char *regs = priv->tda18271_regs;
 	unsigned char buf[TDA18271_NUM_REGS + 1];
 	struct i2c_msg msg = { .addr = priv->i2c_props.addr, .flags = 0,
-			       .buf = buf, .len = len + 1 };
-	int i, ret;
+			       .buf = buf };
+	int i, ret = 1, max;
 
 	BUG_ON((len == 0) || (idx + len > sizeof(buf)));
 
-	buf[0] = idx;
-	for (i = 1; i <= len; i++)
-		buf[i] = regs[idx - 1 + i];
+
+	switch (priv->small_i2c) {
+	case TDA18271_03_BYTE_CHUNK_INIT:
+		max = 3;
+		break;
+	case TDA18271_08_BYTE_CHUNK_INIT:
+		max = 8;
+		break;
+	case TDA18271_16_BYTE_CHUNK_INIT:
+		max = 16;
+		break;
+	case TDA18271_39_BYTE_CHUNK_INIT:
+	default:
+		max = 39;
+	}
 
 	tda18271_i2c_gate_ctrl(fe, 1);
+	while (len) {
+		if (max > len)
+			max = len;
 
-	/* write registers */
-	ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
+		buf[0] = idx;
+		for (i = 1; i <= max; i++)
+			buf[i] = regs[idx - 1 + i];
 
+		msg.len = max + 1;
+
+		/* write registers */
+		ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
+		if (ret != 1)
+			break;
+
+		idx += max;
+		len -= max;
+	}
 	tda18271_i2c_gate_ctrl(fe, 0);
 
 	if (ret != 1)
@@ -326,24 +352,7 @@ int tda18271_init_regs(struct dvb_frontend *fe)
 	regs[R_EB22] = 0x48;
 	regs[R_EB23] = 0xb0;
 
-	switch (priv->small_i2c) {
-	case TDA18271_08_BYTE_CHUNK_INIT:
-		tda18271_write_regs(fe, 0x00, 0x08);
-		tda18271_write_regs(fe, 0x08, 0x08);
-		tda18271_write_regs(fe, 0x10, 0x08);
-		tda18271_write_regs(fe, 0x18, 0x08);
-		tda18271_write_regs(fe, 0x20, 0x07);
-		break;
-	case TDA18271_16_BYTE_CHUNK_INIT:
-		tda18271_write_regs(fe, 0x00, 0x10);
-		tda18271_write_regs(fe, 0x10, 0x10);
-		tda18271_write_regs(fe, 0x20, 0x07);
-		break;
-	case TDA18271_39_BYTE_CHUNK_INIT:
-	default:
-		tda18271_write_regs(fe, 0x00, TDA18271_NUM_REGS);
-		break;
-	}
+	tda18271_write_regs(fe, 0x00, TDA18271_NUM_REGS);
 
 	/* setup agc1 gain */
 	regs[R_EB17] = 0x00;
diff --git a/drivers/media/common/tuners/tda18271.h b/drivers/media/common/tuners/tda18271.h
index d7fcc36..3abb221 100644
--- a/drivers/media/common/tuners/tda18271.h
+++ b/drivers/media/common/tuners/tda18271.h
@@ -80,8 +80,9 @@ enum tda18271_output_options {
 
 enum tda18271_small_i2c {
 	TDA18271_39_BYTE_CHUNK_INIT = 0,
-	TDA18271_16_BYTE_CHUNK_INIT = 1,
-	TDA18271_08_BYTE_CHUNK_INIT = 2,
+	TDA18271_16_BYTE_CHUNK_INIT = 16,
+	TDA18271_08_BYTE_CHUNK_INIT = 8,
+	TDA18271_03_BYTE_CHUNK_INIT = 3,
 };
 
 struct tda18271_config {
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index fa406b9..1a047c5 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -428,7 +428,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
 	{
 		struct tda18271_config cfg = {
 			.config = t->config,
-			.small_i2c = TDA18271_08_BYTE_CHUNK_INIT,
+			.small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
 		};
 
 		if (!dvb_attach(tda18271_attach, &t->fe, t->i2c->addr,
-- 
1.7.1



  parent reply	other threads:[~2010-09-28 18:54 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1285699057.git.mchehab@redhat.com>
2010-09-28 18:46 ` [PATCH 01/10] V4L/DVB: cx231xx: remove a printk warning at -avcore and at -417 Mauro Carvalho Chehab
2010-10-07 21:48   ` Mauro Carvalho Chehab
2010-10-07 22:04     ` Devin Heitmueller
2010-10-07 23:09       ` Mauro Carvalho Chehab
2010-10-08  0:31       ` Mauro Carvalho Chehab
2010-09-28 18:46 ` [PATCH 02/10] V4L/DVB: cx231xx: fix Kconfig dependencies Mauro Carvalho Chehab
2010-09-28 18:46 ` [PATCH 03/10] V4L/DVB: tda18271: Add some hint about what tda18217 reg ID returned Mauro Carvalho Chehab
2010-09-29 12:29   ` Devin Heitmueller
2010-09-30 18:57   ` Michael Krufky
2010-09-30 19:16     ` Mauro Carvalho Chehab
2010-09-30 19:27       ` Michael Krufky
2010-09-30 19:58         ` Mauro Carvalho Chehab
2010-09-30 20:26         ` Mauro Carvalho Chehab
2010-09-30 21:03           ` Michael Krufky
2010-10-01  5:47             ` Mauro Carvalho Chehab
2010-09-28 18:46 ` [PATCH 04/10] V4L/DVB: cx231xx: properly implement URB control messages log Mauro Carvalho Chehab
2010-09-28 18:46 ` [PATCH 06/10] V4L/DVB: cx231xx: better handle the master port enable command Mauro Carvalho Chehab
2010-09-28 18:46 ` [PATCH 05/10] V4L/DVB: cx231xx: properly use the right tuner i2c address Mauro Carvalho Chehab
2010-09-28 18:46 ` [PATCH 07/10] V4L/DVB: cx231xx: Only change gpio direction when needed Mauro Carvalho Chehab
2010-09-28 18:46 ` Mauro Carvalho Chehab [this message]
2010-09-29 12:29   ` [PATCH 08/10] V4L/DVB: tda18271: allow restricting max out to 4 bytes Devin Heitmueller
2010-09-30 18:52   ` Michael Krufky
2010-09-30 19:12     ` Mauro Carvalho Chehab
2010-09-30 19:18       ` Michael Krufky
2010-09-30 19:48         ` Mauro Carvalho Chehab
2010-09-30 22:00     ` Antti Palosaari
2010-09-30 22:07       ` Michael Krufky
2010-10-01  5:46         ` Mauro Carvalho Chehab
2010-09-28 18:47 ` [PATCH 09/10] V4L/DVB: tda18271: Add debug message with frequency divisor Mauro Carvalho Chehab
2010-09-29 12:30   ` Devin Heitmueller
2010-09-30 19:03   ` Michael Krufky
2010-09-30 19:16     ` Mauro Carvalho Chehab
2010-09-28 18:47 ` [PATCH 10/10] V4L/DVB: cx231xx-audio: fix some locking issues Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100928154659.0e7e4147@pedra \
    --to=mchehab@redhat.com \
    --cc=Palash.Bandyopadhyay@conexant.com \
    --cc=Srinivasa.Deevi@conexant.com \
    --cc=dheitmueller@kernellabs.com \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox