All of lore.kernel.org
 help / color / mirror / Atom feed
From: Antti Palosaari <crope@iki.fi>
To: linux-media@vger.kernel.org
Cc: Antti Palosaari <crope@iki.fi>
Subject: [PATCH 17/37] it913x: re-implement sleep
Date: Thu,  4 Sep 2014 05:36:25 +0300	[thread overview]
Message-ID: <1409798205-25645-17-git-send-email-crope@iki.fi> (raw)
In-Reply-To: <1409798205-25645-1-git-send-email-crope@iki.fi>

Re-implement sleep. Based USB sniffs taken from the latest Hauppauge
windows driver version 07/10/2014, 14.6.23.32191.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/tuners/it913x.c         | 76 +++++++++++++++++++++++++++--------
 drivers/media/tuners/it913x.h         | 10 ++++-
 drivers/media/tuners/it913x_priv.h    | 27 -------------
 drivers/media/usb/dvb-usb-v2/af9035.c | 14 +++++++
 4 files changed, 83 insertions(+), 44 deletions(-)

diff --git a/drivers/media/tuners/it913x.c b/drivers/media/tuners/it913x.c
index f3e212c..11d391a 100644
--- a/drivers/media/tuners/it913x.c
+++ b/drivers/media/tuners/it913x.c
@@ -26,7 +26,8 @@ struct it913x_dev {
 	struct i2c_client *client;
 	struct regmap *regmap;
 	struct dvb_frontend *fe;
-	u8 chip_ver;
+	u8 chip_ver:2;
+	u8 role:2;
 	u8 firmware_ver;
 	u16 tun_xtal;
 	u8 tun_fdiv;
@@ -122,6 +123,62 @@ static int it913x_init(struct dvb_frontend *fe)
 	return regmap_write(dev->regmap, 0x80ed81, val);
 }
 
+static int it913x_sleep(struct dvb_frontend *fe)
+{
+	struct it913x_dev *dev = fe->tuner_priv;
+	int ret, len;
+
+	dev_dbg(&dev->client->dev, "role=%u\n", dev->role);
+
+	ret  = regmap_bulk_write(dev->regmap, 0x80ec40, "\x00", 1);
+	if (ret)
+		goto err;
+
+	/*
+	 * Writing '0x00' to master tuner register '0x80ec08' causes slave tuner
+	 * communication lost. Due to that, we cannot put master full sleep.
+	 */
+	if (dev->role == IT913X_ROLE_DUAL_MASTER)
+		len = 4;
+	else
+		len = 15;
+
+	dev_dbg(&dev->client->dev, "role=%u len=%d\n", dev->role, len);
+
+	ret = regmap_bulk_write(dev->regmap, 0x80ec02,
+			"\x3f\x1f\x3f\x3e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+			len);
+	if (ret)
+		goto err;
+
+	ret = regmap_bulk_write(dev->regmap, 0x80ec12, "\x00\x00\x00\x00", 4);
+	if (ret)
+		goto err;
+
+	ret = regmap_bulk_write(dev->regmap, 0x80ec17,
+			"\x00\x00\x00\x00\x00\x00\x00\x00\x00", 9);
+	if (ret)
+		goto err;
+
+	ret = regmap_bulk_write(dev->regmap, 0x80ec22,
+			"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 10);
+	if (ret)
+		goto err;
+
+	ret = regmap_bulk_write(dev->regmap, 0x80ec20, "\x00", 1);
+	if (ret)
+		goto err;
+
+	ret = regmap_bulk_write(dev->regmap, 0x80ec3f, "\x01", 1);
+	if (ret)
+		goto err;
+
+	return 0;
+err:
+	dev_dbg(&dev->client->dev, "failed %d\n", ret);
+	return ret;
+}
+
 static int it9137_set_params(struct dvb_frontend *fe)
 {
 	struct it913x_dev *dev = fe->tuner_priv;
@@ -274,20 +331,6 @@ static int it9137_set_params(struct dvb_frontend *fe)
 	return (ret < 0) ? -ENODEV : 0;
 }
 
-/* Power sequence */
-/* Power Up	Tuner on -> Frontend suspend off -> Tuner clk on */
-/* Power Down	Frontend suspend on -> Tuner clk off -> Tuner off */
-
-static int it913x_sleep(struct dvb_frontend *fe)
-{
-	struct it913x_dev *dev = fe->tuner_priv;
-
-	if (dev->chip_ver == 0x01)
-		return it913x_script_loader(dev, it9135ax_tuner_off);
-	else
-		return it913x_script_loader(dev, it9137_tuner_off);
-}
-
 static const struct dvb_tuner_ops it913x_tuner_ops = {
 	.info = {
 		.name           = "ITE Tech IT913X",
@@ -323,6 +366,7 @@ static int it913x_probe(struct i2c_client *client,
 	dev->client = client;
 	dev->fe = cfg->fe;
 	dev->chip_ver = cfg->chip_ver;
+	dev->role = cfg->role;
 	dev->firmware_ver = 1;
 	dev->regmap = regmap_init_i2c(client, &regmap_config);
 	if (IS_ERR(dev->regmap)) {
@@ -349,7 +393,7 @@ static int it913x_probe(struct i2c_client *client,
 
 	dev_info(&dev->client->dev, "ITE IT913X %s successfully attached\n",
 			chip_ver_str);
-	dev_dbg(&dev->client->dev, "chip_ver=%02x\n", dev->chip_ver);
+	dev_dbg(&dev->client->dev, "chip_ver=%u role=%u\n", dev->chip_ver, dev->role);
 	return 0;
 
 err_regmap_exit:
diff --git a/drivers/media/tuners/it913x.h b/drivers/media/tuners/it913x.h
index 9789c4d..33de53d 100644
--- a/drivers/media/tuners/it913x.h
+++ b/drivers/media/tuners/it913x.h
@@ -40,7 +40,15 @@ struct it913x_config {
 	 * 1 = IT9135 AX
 	 * 2 = IT9135 BX
 	 */
-	u8 chip_ver:2;
+	unsigned int chip_ver:2;
+
+	/*
+	 * tuner role
+	 */
+#define IT913X_ROLE_SINGLE         0
+#define IT913X_ROLE_DUAL_MASTER    1
+#define IT913X_ROLE_DUAL_SLAVE     2
+	unsigned int role:2;
 };
 
 #endif
diff --git a/drivers/media/tuners/it913x_priv.h b/drivers/media/tuners/it913x_priv.h
index 3ed2d3c..41f9b2a 100644
--- a/drivers/media/tuners/it913x_priv.h
+++ b/drivers/media/tuners/it913x_priv.h
@@ -33,33 +33,6 @@ struct it913xset {	u32 address;
 			u8 count;
 };
 
-/* Tuner setting scripts for IT9135 AX */
-static struct it913xset it9135ax_tuner_off[] = {
-	{0x80ec40, {0x00}, 0x01}, /* Power Down Tuner */
-	{0x80ec02, {0x3f}, 0x01},
-	{0x80ec03, {0x1f}, 0x01},
-	{0x80ec04, {0x3f}, 0x01},
-	{0x80ec05, {0x3f}, 0x01},
-	{0x80ec3f, {0x01}, 0x01},
-	{0x000000, {0x00}, 0x00}, /* Terminating Entry */
-};
-
-/* Tuner setting scripts (still keeping it9137) */
-static struct it913xset it9137_tuner_off[] = {
-	{0x80ec40, {0x00}, 0x01}, /* Power Down Tuner */
-	{0x80ec02, {0x3f, 0x1f, 0x3f, 0x3f}, 0x04},
-	{0x80ec06, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-				0x00, 0x00, 0x00, 0x00}, 0x0c},
-	{0x80ec12, {0x00, 0x00, 0x00, 0x00}, 0x04},
-	{0x80ec17, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-				0x00}, 0x09},
-	{0x80ec22, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-				0x00, 0x00}, 0x0a},
-	{0x80ec20, {0x00}, 0x01},
-	{0x80ec3f, {0x01}, 0x01},
-	{0x000000, {0x00}, 0x00}, /* Terminating Entry */
-};
-
 static struct it913xset set_it9135_template[] = {
 	{0x80ee06, {0x00}, 0x01},
 	{0x80ec56, {0x00}, 0x01},
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c
index 1a5b600..533c96e 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -1324,6 +1324,13 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
 			.chip_ver = 1,
 		};
 
+		if (state->dual_mode) {
+			if (adap->id == 0)
+				it913x_config.role = IT913X_ROLE_DUAL_MASTER;
+			else
+				it913x_config.role = IT913X_ROLE_DUAL_SLAVE;
+		}
+
 		ret = af9035_add_i2c_dev(d, "it913x",
 				state->af9033_config[adap->id].i2c_addr,
 				&it913x_config);
@@ -1342,6 +1349,13 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
 			.chip_ver = 2,
 		};
 
+		if (state->dual_mode) {
+			if (adap->id == 0)
+				it913x_config.role = IT913X_ROLE_DUAL_MASTER;
+			else
+				it913x_config.role = IT913X_ROLE_DUAL_SLAVE;
+		}
+
 		ret = af9035_add_i2c_dev(d, "it913x",
 				state->af9033_config[adap->id].i2c_addr,
 				&it913x_config);
-- 
http://palosaari.fi/


  parent reply	other threads:[~2014-09-04  2:37 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-04  2:36 [PATCH 01/37] af9033: provide dyn0_clk clock source Antti Palosaari
2014-09-04  2:36 ` [PATCH 02/37] af9035: enable AF9033 demod clock source for IT9135 Antti Palosaari
2014-09-04  2:36 ` [PATCH 03/37] it913x: fix tuner sleep power leak Antti Palosaari
2014-09-04  2:36 ` [PATCH 04/37] it913x: avoid division by zero on error case Antti Palosaari
2014-09-04  2:36 ` [PATCH 05/37] it913x: fix IT9135 AX sleep Antti Palosaari
2014-09-04  2:36 ` [PATCH 06/37] af9035: remove AVerMedia eeprom override Antti Palosaari
2014-09-04  2:36 ` [PATCH 07/37] af9035: make checkpatch.pl happy Antti Palosaari
2014-09-04  2:36 ` [PATCH 08/37] af9033: " Antti Palosaari
2014-09-04  2:36 ` [PATCH 09/37] it913x: " Antti Palosaari
2014-09-04  2:36 ` [PATCH 10/37] it913x: rename tuner_it913x => it913x Antti Palosaari
2014-09-04  2:36 ` [PATCH 11/37] af9035: do not attach IT9135 tuner Antti Palosaari
2014-09-04  2:36 ` [PATCH 12/37] it913x: convert to I2C driver Antti Palosaari
2014-09-04  2:36 ` [PATCH 13/37] af9035: use I2C it913x tuner driver Antti Palosaari
2014-09-04  2:36 ` [PATCH 14/37] it913x: change reg read/write routines more common Antti Palosaari
2014-09-04  2:36 ` [PATCH 15/37] it913x: rename 'state' to 'dev' Antti Palosaari
2014-09-04  2:36 ` [PATCH 16/37] it913x: convert to RegMap API Antti Palosaari
2014-09-04  2:36 ` Antti Palosaari [this message]
2014-09-04  2:36 ` [PATCH 18/37] it913x: remove dead code Antti Palosaari
2014-09-04  2:36 ` [PATCH 19/37] it913x: get rid of script loader and and private header file Antti Palosaari
2014-09-04  2:36 ` [PATCH 20/37] it913x: refactor code largely Antti Palosaari
2014-09-04  2:36 ` [PATCH 21/37] it913x: replace udelay polling with jiffies Antti Palosaari
2014-09-04  2:36 ` [PATCH 22/37] af9033: fix firmware version logging Antti Palosaari
2014-09-04  2:36 ` [PATCH 23/37] af9033: rename 'state' to 'dev' Antti Palosaari
2014-09-04  2:36 ` [PATCH 24/37] af9033: convert to I2C client Antti Palosaari
2014-09-04  2:36 ` [PATCH 25/37] af9033: clean up logging Antti Palosaari
2014-09-04  2:36 ` [PATCH 26/37] af9035: few small I2C master xfer changes Antti Palosaari
2014-09-04  2:36 ` [PATCH 27/37] af9033: remove I2C addr from config Antti Palosaari
2014-09-04  2:36 ` [PATCH 28/37] af9035: replace PCTV device model numbers with name Antti Palosaari
2014-09-04  2:36 ` [PATCH 29/37] MAINTAINERS: IT913X driver filenames Antti Palosaari
2014-09-04  2:36 ` [PATCH 30/37] af9033: implement DVBv5 statistic for signal strength Antti Palosaari
2014-09-04  2:36 ` [PATCH 31/37] af9033: implement DVBv5 statistic for CNR Antti Palosaari
2014-09-04  2:36 ` [PATCH 32/37] af9033: wrap DVBv3 read SNR to DVBv5 CNR Antti Palosaari
2014-09-04  2:36 ` [PATCH 33/37] af9033: implement DVBv5 stat block counters Antti Palosaari
2014-09-04  2:36 ` [PATCH 34/37] af9033: implement DVBv5 post-Viterbi BER Antti Palosaari
2014-09-04  2:36 ` [PATCH 35/37] af9033: wrap DVBv3 UCB to DVBv5 UCB stats Antti Palosaari
2014-09-04  2:36 ` [PATCH 36/37] af9033: wrap DVBv3 BER to DVBv5 BER Antti Palosaari
2014-09-04  2:36 ` [PATCH 37/37] af9033: remove all DVBv3 stat calculation logic Antti Palosaari

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=1409798205-25645-17-git-send-email-crope@iki.fi \
    --to=crope@iki.fi \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.