public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/12] em28xx: remove unused a8293 SEC config
@ 2015-07-09  4:06 Antti Palosaari
  2015-07-09  4:06 ` [PATCH 02/12] a8293: remove legacy media attach Antti Palosaari
                   ` (10 more replies)
  0 siblings, 11 replies; 15+ messages in thread
From: Antti Palosaari @ 2015-07-09  4:06 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Devices that were using a8293 SEC are converted to I2C platform data
thus that old config structure is left unused.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/usb/em28xx/em28xx-dvb.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c b/drivers/media/usb/em28xx/em28xx-dvb.c
index a382483..357be76 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -808,10 +808,6 @@ static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
 	.gate = TDA18271_GATE_DIGITAL,
 };
 
-static const struct a8293_config em28xx_a8293_config = {
-	.i2c_addr = 0x08, /* (0x10 >> 1) */
-};
-
 static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
 	.demod_address = (0x1e >> 1),
 	.disable_i2c_gate_ctrl = 1,
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 02/12] a8293: remove legacy media attach
  2015-07-09  4:06 [PATCH 01/12] em28xx: remove unused a8293 SEC config Antti Palosaari
@ 2015-07-09  4:06 ` Antti Palosaari
  2015-07-09  4:06 ` [PATCH 03/12] a8293: use i2c_master_send / i2c_master_recv for I2C I/O Antti Palosaari
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Antti Palosaari @ 2015-07-09  4:06 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Remove legacy media attach as all users are on I2C bindings now.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/dvb-frontends/a8293.c | 63 +------------------------------------
 drivers/media/dvb-frontends/a8293.h | 18 -----------
 2 files changed, 1 insertion(+), 80 deletions(-)

diff --git a/drivers/media/dvb-frontends/a8293.c b/drivers/media/dvb-frontends/a8293.c
index 97ecbe0..522b0d1 100644
--- a/drivers/media/dvb-frontends/a8293.c
+++ b/drivers/media/dvb-frontends/a8293.c
@@ -18,7 +18,6 @@
  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "dvb_frontend.h"
 #include "a8293.h"
 
 struct a8293_priv {
@@ -105,68 +104,8 @@ err:
 	return ret;
 }
 
-static void a8293_release_sec(struct dvb_frontend *fe)
-{
-	a8293_set_voltage(fe, SEC_VOLTAGE_OFF);
-
-	kfree(fe->sec_priv);
-	fe->sec_priv = NULL;
-}
-
-struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,
-	struct i2c_adapter *i2c, const struct a8293_config *cfg)
-{
-	int ret;
-	struct a8293_priv *priv = NULL;
-	u8 buf[2];
-
-	/* allocate memory for the internal priv */
-	priv = kzalloc(sizeof(struct a8293_priv), GFP_KERNEL);
-	if (priv == NULL) {
-		ret = -ENOMEM;
-		goto err;
-	}
-
-	/* setup the priv */
-	priv->i2c = i2c;
-	priv->i2c_addr = cfg->i2c_addr;
-	fe->sec_priv = priv;
-
-	/* check if the SEC is there */
-	ret = a8293_rd(priv, buf, 2);
-	if (ret)
-		goto err;
-
-	/* ENB=0 */
-	priv->reg[0] = 0x10;
-	ret = a8293_wr(priv, &priv->reg[0], 1);
-	if (ret)
-		goto err;
-
-	/* TMODE=0, TGATE=1 */
-	priv->reg[1] = 0x82;
-	ret = a8293_wr(priv, &priv->reg[1], 1);
-	if (ret)
-		goto err;
-
-	fe->ops.release_sec = a8293_release_sec;
-
-	/* override frontend ops */
-	fe->ops.set_voltage = a8293_set_voltage;
-
-	dev_info(&priv->i2c->dev, "%s: Allegro A8293 SEC attached\n",
-			KBUILD_MODNAME);
-
-	return fe;
-err:
-	dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret);
-	kfree(priv);
-	return NULL;
-}
-EXPORT_SYMBOL(a8293_attach);
-
 static int a8293_probe(struct i2c_client *client,
-			const struct i2c_device_id *id)
+		       const struct i2c_device_id *id)
 {
 	struct a8293_priv *dev;
 	struct a8293_platform_data *pdata = client->dev.platform_data;
diff --git a/drivers/media/dvb-frontends/a8293.h b/drivers/media/dvb-frontends/a8293.h
index aff3653..aa07b68 100644
--- a/drivers/media/dvb-frontends/a8293.h
+++ b/drivers/media/dvb-frontends/a8293.h
@@ -22,7 +22,6 @@
 #define A8293_H
 
 #include "dvb_frontend.h"
-#include <linux/kconfig.h>
 
 /*
  * I2C address
@@ -37,21 +36,4 @@ struct a8293_platform_data {
 	struct dvb_frontend *dvb_frontend;
 };
 
-
-struct a8293_config {
-	u8 i2c_addr;
-};
-
-#if IS_REACHABLE(CONFIG_DVB_A8293)
-extern struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,
-	struct i2c_adapter *i2c, const struct a8293_config *cfg);
-#else
-static inline struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,
-	struct i2c_adapter *i2c, const struct a8293_config *cfg)
-{
-	printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
-	return NULL;
-}
-#endif
-
 #endif /* A8293_H */
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 03/12] a8293: use i2c_master_send / i2c_master_recv for I2C I/O
  2015-07-09  4:06 [PATCH 01/12] em28xx: remove unused a8293 SEC config Antti Palosaari
  2015-07-09  4:06 ` [PATCH 02/12] a8293: remove legacy media attach Antti Palosaari
@ 2015-07-09  4:06 ` Antti Palosaari
  2015-07-09  4:06 ` [PATCH 04/12] a8293: improve LNB register programming logic Antti Palosaari
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Antti Palosaari @ 2015-07-09  4:06 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

As driver is now proper I2C client driver, we could use correct
functions for I2C I/O. Also rename state from priv to dev. Fix
logging too.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/dvb-frontends/a8293.c | 80 +++++++++----------------------------
 1 file changed, 18 insertions(+), 62 deletions(-)

diff --git a/drivers/media/dvb-frontends/a8293.c b/drivers/media/dvb-frontends/a8293.c
index 522b0d1..d99ea4d 100644
--- a/drivers/media/dvb-frontends/a8293.c
+++ b/drivers/media/dvb-frontends/a8293.c
@@ -20,94 +20,53 @@
 
 #include "a8293.h"
 
-struct a8293_priv {
-	u8 i2c_addr;
-	struct i2c_adapter *i2c;
+struct a8293_dev {
 	struct i2c_client *client;
 	u8 reg[2];
 };
 
-static int a8293_i2c(struct a8293_priv *priv, u8 *val, int len, bool rd)
-{
-	int ret;
-	struct i2c_msg msg[1] = {
-		{
-			.addr = priv->i2c_addr,
-			.len = len,
-			.buf = val,
-		}
-	};
-
-	if (rd)
-		msg[0].flags = I2C_M_RD;
-	else
-		msg[0].flags = 0;
-
-	ret = i2c_transfer(priv->i2c, msg, 1);
-	if (ret == 1) {
-		ret = 0;
-	} else {
-		dev_warn(&priv->i2c->dev, "%s: i2c failed=%d rd=%d\n",
-				KBUILD_MODNAME, ret, rd);
-		ret = -EREMOTEIO;
-	}
-
-	return ret;
-}
-
-static int a8293_wr(struct a8293_priv *priv, u8 *val, int len)
-{
-	return a8293_i2c(priv, val, len, 0);
-}
-
-static int a8293_rd(struct a8293_priv *priv, u8 *val, int len)
-{
-	return a8293_i2c(priv, val, len, 1);
-}
-
 static int a8293_set_voltage(struct dvb_frontend *fe,
 	enum fe_sec_voltage fe_sec_voltage)
 {
-	struct a8293_priv *priv = fe->sec_priv;
+	struct a8293_dev *dev = fe->sec_priv;
+	struct i2c_client *client = dev->client;
 	int ret;
 
-	dev_dbg(&priv->i2c->dev, "%s: fe_sec_voltage=%d\n", __func__,
-			fe_sec_voltage);
+	dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage);
 
 	switch (fe_sec_voltage) {
 	case SEC_VOLTAGE_OFF:
 		/* ENB=0 */
-		priv->reg[0] = 0x10;
+		dev->reg[0] = 0x10;
 		break;
 	case SEC_VOLTAGE_13:
 		/* VSEL0=1, VSEL1=0, VSEL2=0, VSEL3=0, ENB=1*/
-		priv->reg[0] = 0x31;
+		dev->reg[0] = 0x31;
 		break;
 	case SEC_VOLTAGE_18:
 		/* VSEL0=0, VSEL1=0, VSEL2=0, VSEL3=1, ENB=1*/
-		priv->reg[0] = 0x38;
+		dev->reg[0] = 0x38;
 		break;
 	default:
 		ret = -EINVAL;
 		goto err;
 	}
 
-	ret = a8293_wr(priv, &priv->reg[0], 1);
-	if (ret)
+	ret = i2c_master_send(client, &dev->reg[0], 1);
+	if (ret < 0)
 		goto err;
 
 	usleep_range(1500, 50000);
-
-	return ret;
+	return 0;
 err:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
 static int a8293_probe(struct i2c_client *client,
 		       const struct i2c_device_id *id)
 {
-	struct a8293_priv *dev;
+	struct a8293_dev *dev;
 	struct a8293_platform_data *pdata = client->dev.platform_data;
 	struct dvb_frontend *fe = pdata->dvb_frontend;
 	int ret;
@@ -120,29 +79,26 @@ static int a8293_probe(struct i2c_client *client,
 	}
 
 	dev->client = client;
-	dev->i2c = client->adapter;
-	dev->i2c_addr = client->addr;
 
 	/* check if the SEC is there */
-	ret = a8293_rd(dev, buf, 2);
-	if (ret)
+	ret = i2c_master_recv(client, buf, 2);
+	if (ret < 0)
 		goto err_kfree;
 
 	/* ENB=0 */
 	dev->reg[0] = 0x10;
-	ret = a8293_wr(dev, &dev->reg[0], 1);
-	if (ret)
+	ret = i2c_master_send(client, &dev->reg[0], 1);
+	if (ret < 0)
 		goto err_kfree;
 
 	/* TMODE=0, TGATE=1 */
 	dev->reg[1] = 0x82;
-	ret = a8293_wr(dev, &dev->reg[1], 1);
-	if (ret)
+	ret = i2c_master_send(client, &dev->reg[1], 1);
+	if (ret < 0)
 		goto err_kfree;
 
 	/* override frontend ops */
 	fe->ops.set_voltage = a8293_set_voltage;
-
 	fe->sec_priv = dev;
 	i2c_set_clientdata(client, dev);
 
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 04/12] a8293: improve LNB register programming logic
  2015-07-09  4:06 [PATCH 01/12] em28xx: remove unused a8293 SEC config Antti Palosaari
  2015-07-09  4:06 ` [PATCH 02/12] a8293: remove legacy media attach Antti Palosaari
  2015-07-09  4:06 ` [PATCH 03/12] a8293: use i2c_master_send / i2c_master_recv for I2C I/O Antti Palosaari
@ 2015-07-09  4:06 ` Antti Palosaari
  2015-07-09  4:06 ` [PATCH 05/12] a8293: coding style issues Antti Palosaari
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Antti Palosaari @ 2015-07-09  4:06 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

On power-on LNB power supply voltage is disabled, due to that no
need to disable it during probe. Tone is supply is hard-coded as
external tone coming from the demodulator. Program both voltage
and tone on set_voltage(). Use register cache to prevent unneeded
programming.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/dvb-frontends/a8293.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/media/dvb-frontends/a8293.c b/drivers/media/dvb-frontends/a8293.c
index d99ea4d..ef2b47c 100644
--- a/drivers/media/dvb-frontends/a8293.c
+++ b/drivers/media/dvb-frontends/a8293.c
@@ -31,30 +31,42 @@ static int a8293_set_voltage(struct dvb_frontend *fe,
 	struct a8293_dev *dev = fe->sec_priv;
 	struct i2c_client *client = dev->client;
 	int ret;
+	u8 reg0, reg1;
 
 	dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage);
 
 	switch (fe_sec_voltage) {
 	case SEC_VOLTAGE_OFF:
 		/* ENB=0 */
-		dev->reg[0] = 0x10;
+		reg0 = 0x10;
 		break;
 	case SEC_VOLTAGE_13:
 		/* VSEL0=1, VSEL1=0, VSEL2=0, VSEL3=0, ENB=1*/
-		dev->reg[0] = 0x31;
+		reg0 = 0x31;
 		break;
 	case SEC_VOLTAGE_18:
 		/* VSEL0=0, VSEL1=0, VSEL2=0, VSEL3=1, ENB=1*/
-		dev->reg[0] = 0x38;
+		reg0 = 0x38;
 		break;
 	default:
 		ret = -EINVAL;
 		goto err;
 	}
+	if (reg0 != dev->reg[0]) {
+		ret = i2c_master_send(client, &reg0, 1);
+		if (ret < 0)
+			goto err;
+		dev->reg[0] = reg0;
+	}
 
-	ret = i2c_master_send(client, &dev->reg[0], 1);
-	if (ret < 0)
-		goto err;
+	/* TMODE=0, TGATE=1 */
+	reg1 = 0x82;
+	if (reg1 != dev->reg[1]) {
+		ret = i2c_master_send(client, &reg1, 1);
+		if (ret < 0)
+			goto err;
+		dev->reg[1] = reg1;
+	}
 
 	usleep_range(1500, 50000);
 	return 0;
@@ -85,18 +97,6 @@ static int a8293_probe(struct i2c_client *client,
 	if (ret < 0)
 		goto err_kfree;
 
-	/* ENB=0 */
-	dev->reg[0] = 0x10;
-	ret = i2c_master_send(client, &dev->reg[0], 1);
-	if (ret < 0)
-		goto err_kfree;
-
-	/* TMODE=0, TGATE=1 */
-	dev->reg[1] = 0x82;
-	ret = i2c_master_send(client, &dev->reg[1], 1);
-	if (ret < 0)
-		goto err_kfree;
-
 	/* override frontend ops */
 	fe->ops.set_voltage = a8293_set_voltage;
 	fe->sec_priv = dev;
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 05/12] a8293: coding style issues
  2015-07-09  4:06 [PATCH 01/12] em28xx: remove unused a8293 SEC config Antti Palosaari
                   ` (2 preceding siblings ...)
  2015-07-09  4:06 ` [PATCH 04/12] a8293: improve LNB register programming logic Antti Palosaari
@ 2015-07-09  4:06 ` Antti Palosaari
  2015-07-09  4:06 ` [PATCH 06/12] tda10071: remove legacy media attach Antti Palosaari
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Antti Palosaari @ 2015-07-09  4:06 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Remove FSF address from license. Indent parameter correctly.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/dvb-frontends/a8293.c | 6 +-----
 drivers/media/dvb-frontends/a8293.h | 4 ----
 2 files changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/media/dvb-frontends/a8293.c b/drivers/media/dvb-frontends/a8293.c
index ef2b47c..1923133 100644
--- a/drivers/media/dvb-frontends/a8293.c
+++ b/drivers/media/dvb-frontends/a8293.c
@@ -12,10 +12,6 @@
  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *    GNU General Public License for more details.
- *
- *    You should have received a copy of the GNU General Public License along
- *    with this program; if not, write to the Free Software Foundation, Inc.,
- *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include "a8293.h"
@@ -26,7 +22,7 @@ struct a8293_dev {
 };
 
 static int a8293_set_voltage(struct dvb_frontend *fe,
-	enum fe_sec_voltage fe_sec_voltage)
+			     enum fe_sec_voltage fe_sec_voltage)
 {
 	struct a8293_dev *dev = fe->sec_priv;
 	struct i2c_client *client = dev->client;
diff --git a/drivers/media/dvb-frontends/a8293.h b/drivers/media/dvb-frontends/a8293.h
index aa07b68..7b90a03 100644
--- a/drivers/media/dvb-frontends/a8293.h
+++ b/drivers/media/dvb-frontends/a8293.h
@@ -12,10 +12,6 @@
  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *    GNU General Public License for more details.
- *
- *    You should have received a copy of the GNU General Public License along
- *    with this program; if not, write to the Free Software Foundation, Inc.,
- *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifndef A8293_H
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 06/12] tda10071: remove legacy media attach
  2015-07-09  4:06 [PATCH 01/12] em28xx: remove unused a8293 SEC config Antti Palosaari
                   ` (3 preceding siblings ...)
  2015-07-09  4:06 ` [PATCH 05/12] a8293: coding style issues Antti Palosaari
@ 2015-07-09  4:06 ` Antti Palosaari
  2015-07-09  4:06 ` [PATCH 07/12] tda10071: rename device state struct to dev Antti Palosaari
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Antti Palosaari @ 2015-07-09  4:06 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

All users are now using I2C binding and old attach could be removed.
Use I2C client for proper logging at the same.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/dvb-frontends/tda10071.c      | 275 ++++++++++------------------
 drivers/media/dvb-frontends/tda10071.h      |  63 +------
 drivers/media/dvb-frontends/tda10071_priv.h |   8 +-
 3 files changed, 108 insertions(+), 238 deletions(-)

diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c
index f6dc630..cc65285 100644
--- a/drivers/media/dvb-frontends/tda10071.c
+++ b/drivers/media/dvb-frontends/tda10071.c
@@ -29,11 +29,12 @@ static struct dvb_frontend_ops tda10071_ops;
 static int tda10071_wr_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
 	int len)
 {
+	struct i2c_client *client = priv->client;
 	int ret;
 	u8 buf[MAX_XFER_SIZE];
 	struct i2c_msg msg[1] = {
 		{
-			.addr = priv->cfg.demod_i2c_addr,
+			.addr = client->addr,
 			.flags = 0,
 			.len = 1 + len,
 			.buf = buf,
@@ -41,22 +42,20 @@ static int tda10071_wr_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
 	};
 
 	if (1 + len > sizeof(buf)) {
-		dev_warn(&priv->i2c->dev,
-				"%s: i2c wr reg=%04x: len=%d is too big!\n",
-				KBUILD_MODNAME, reg, len);
+		dev_warn(&client->dev, "i2c wr reg=%04x: len=%d is too big!\n",
+				reg, len);
 		return -EINVAL;
 	}
 
 	buf[0] = reg;
 	memcpy(&buf[1], val, len);
 
-	ret = i2c_transfer(priv->i2c, msg, 1);
+	ret = i2c_transfer(client->adapter, msg, 1);
 	if (ret == 1) {
 		ret = 0;
 	} else {
-		dev_warn(&priv->i2c->dev,
-				"%s: i2c wr failed=%d reg=%02x len=%d\n",
-				KBUILD_MODNAME, ret, reg, len);
+		dev_warn(&client->dev, "i2c wr failed=%d reg=%02x len=%d\n",
+				ret, reg, len);
 		ret = -EREMOTEIO;
 	}
 	return ret;
@@ -66,16 +65,17 @@ static int tda10071_wr_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
 static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
 	int len)
 {
+	struct i2c_client *client = priv->client;
 	int ret;
 	u8 buf[MAX_XFER_SIZE];
 	struct i2c_msg msg[2] = {
 		{
-			.addr = priv->cfg.demod_i2c_addr,
+			.addr = client->addr,
 			.flags = 0,
 			.len = 1,
 			.buf = &reg,
 		}, {
-			.addr = priv->cfg.demod_i2c_addr,
+			.addr = client->addr,
 			.flags = I2C_M_RD,
 			.len = len,
 			.buf = buf,
@@ -83,20 +83,18 @@ static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
 	};
 
 	if (len > sizeof(buf)) {
-		dev_warn(&priv->i2c->dev,
-				"%s: i2c wr reg=%04x: len=%d is too big!\n",
-				KBUILD_MODNAME, reg, len);
+		dev_warn(&client->dev, "i2c wr reg=%04x: len=%d is too big!\n",
+				reg, len);
 		return -EINVAL;
 	}
 
-	ret = i2c_transfer(priv->i2c, msg, 2);
+	ret = i2c_transfer(client->adapter, msg, 2);
 	if (ret == 2) {
 		memcpy(val, buf, len);
 		ret = 0;
 	} else {
-		dev_warn(&priv->i2c->dev,
-				"%s: i2c rd failed=%d reg=%02x len=%d\n",
-				KBUILD_MODNAME, ret, reg, len);
+		dev_warn(&client->dev, "i2c rd failed=%d reg=%02x len=%d\n",
+				ret, reg, len);
 		ret = -EREMOTEIO;
 	}
 	return ret;
@@ -162,6 +160,7 @@ static int tda10071_rd_reg_mask(struct tda10071_priv *priv,
 static int tda10071_cmd_execute(struct tda10071_priv *priv,
 	struct tda10071_cmd *cmd)
 {
+	struct i2c_client *client = priv->client;
 	int ret, i;
 	u8 tmp;
 
@@ -189,7 +188,7 @@ static int tda10071_cmd_execute(struct tda10071_priv *priv,
 		usleep_range(200, 5000);
 	}
 
-	dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i);
+	dev_dbg(&client->dev, "loop=%d\n", i);
 
 	if (i == 0) {
 		ret = -ETIMEDOUT;
@@ -198,7 +197,7 @@ static int tda10071_cmd_execute(struct tda10071_priv *priv,
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
@@ -206,6 +205,7 @@ static int tda10071_set_tone(struct dvb_frontend *fe,
 	enum fe_sec_tone_mode fe_sec_tone_mode)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	struct tda10071_cmd cmd;
 	int ret;
 	u8 tone;
@@ -215,8 +215,7 @@ static int tda10071_set_tone(struct dvb_frontend *fe,
 		goto error;
 	}
 
-	dev_dbg(&priv->i2c->dev, "%s: tone_mode=%d\n", __func__,
-			fe_sec_tone_mode);
+	dev_dbg(&client->dev, "tone_mode=%d\n", fe_sec_tone_mode);
 
 	switch (fe_sec_tone_mode) {
 	case SEC_TONE_ON:
@@ -226,8 +225,7 @@ static int tda10071_set_tone(struct dvb_frontend *fe,
 		tone = 0;
 		break;
 	default:
-		dev_dbg(&priv->i2c->dev, "%s: invalid fe_sec_tone_mode\n",
-				__func__);
+		dev_dbg(&client->dev, "invalid fe_sec_tone_mode\n");
 		ret = -EINVAL;
 		goto error;
 	}
@@ -244,7 +242,7 @@ static int tda10071_set_tone(struct dvb_frontend *fe,
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
@@ -252,6 +250,7 @@ static int tda10071_set_voltage(struct dvb_frontend *fe,
 	enum fe_sec_voltage fe_sec_voltage)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	struct tda10071_cmd cmd;
 	int ret;
 	u8 voltage;
@@ -261,7 +260,7 @@ static int tda10071_set_voltage(struct dvb_frontend *fe,
 		goto error;
 	}
 
-	dev_dbg(&priv->i2c->dev, "%s: voltage=%d\n", __func__, fe_sec_voltage);
+	dev_dbg(&client->dev, "voltage=%d\n", fe_sec_voltage);
 
 	switch (fe_sec_voltage) {
 	case SEC_VOLTAGE_13:
@@ -274,8 +273,7 @@ static int tda10071_set_voltage(struct dvb_frontend *fe,
 		voltage = 0;
 		break;
 	default:
-		dev_dbg(&priv->i2c->dev, "%s: invalid fe_sec_voltage\n",
-				__func__);
+		dev_dbg(&client->dev, "invalid fe_sec_voltage\n");
 		ret = -EINVAL;
 		goto error;
 	}
@@ -290,7 +288,7 @@ static int tda10071_set_voltage(struct dvb_frontend *fe,
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
@@ -298,6 +296,7 @@ static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe,
 	struct dvb_diseqc_master_cmd *diseqc_cmd)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	struct tda10071_cmd cmd;
 	int ret, i;
 	u8 tmp;
@@ -307,8 +306,7 @@ static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe,
 		goto error;
 	}
 
-	dev_dbg(&priv->i2c->dev, "%s: msg_len=%d\n", __func__,
-			diseqc_cmd->msg_len);
+	dev_dbg(&client->dev, "msg_len=%d\n", diseqc_cmd->msg_len);
 
 	if (diseqc_cmd->msg_len < 3 || diseqc_cmd->msg_len > 6) {
 		ret = -EINVAL;
@@ -324,7 +322,7 @@ static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe,
 		usleep_range(10000, 20000);
 	}
 
-	dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i);
+	dev_dbg(&client->dev, "loop=%d\n", i);
 
 	if (i == 0) {
 		ret = -ETIMEDOUT;
@@ -350,7 +348,7 @@ static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe,
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
@@ -358,6 +356,7 @@ static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe,
 	struct dvb_diseqc_slave_reply *reply)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	struct tda10071_cmd cmd;
 	int ret, i;
 	u8 tmp;
@@ -367,7 +366,7 @@ static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe,
 		goto error;
 	}
 
-	dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
+	dev_dbg(&client->dev, "\n");
 
 	/* wait LNB RX */
 	for (i = 500, tmp = 0; i && !tmp; i--) {
@@ -378,7 +377,7 @@ static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe,
 		usleep_range(10000, 20000);
 	}
 
-	dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i);
+	dev_dbg(&client->dev, "loop=%d\n", i);
 
 	if (i == 0) {
 		ret = -ETIMEDOUT;
@@ -408,7 +407,7 @@ static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe,
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
@@ -416,6 +415,7 @@ static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
 	enum fe_sec_mini_cmd fe_sec_mini_cmd)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	struct tda10071_cmd cmd;
 	int ret, i;
 	u8 tmp, burst;
@@ -425,8 +425,7 @@ static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
 		goto error;
 	}
 
-	dev_dbg(&priv->i2c->dev, "%s: fe_sec_mini_cmd=%d\n", __func__,
-			fe_sec_mini_cmd);
+	dev_dbg(&client->dev, "fe_sec_mini_cmd=%d\n", fe_sec_mini_cmd);
 
 	switch (fe_sec_mini_cmd) {
 	case SEC_MINI_A:
@@ -436,8 +435,7 @@ static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
 		burst = 1;
 		break;
 	default:
-		dev_dbg(&priv->i2c->dev, "%s: invalid fe_sec_mini_cmd\n",
-				__func__);
+		dev_dbg(&client->dev, "invalid fe_sec_mini_cmd\n");
 		ret = -EINVAL;
 		goto error;
 	}
@@ -451,7 +449,7 @@ static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
 		usleep_range(10000, 20000);
 	}
 
-	dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i);
+	dev_dbg(&client->dev, "loop=%d\n", i);
 
 	if (i == 0) {
 		ret = -ETIMEDOUT;
@@ -472,13 +470,14 @@ static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
 static int tda10071_read_status(struct dvb_frontend *fe, enum fe_status *status)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	int ret;
 	u8 tmp;
 
@@ -505,13 +504,14 @@ static int tda10071_read_status(struct dvb_frontend *fe, enum fe_status *status)
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
 static int tda10071_read_snr(struct dvb_frontend *fe, u16 *snr)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	int ret;
 	u8 buf[2];
 
@@ -530,13 +530,14 @@ static int tda10071_read_snr(struct dvb_frontend *fe, u16 *snr)
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
 static int tda10071_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	struct tda10071_cmd cmd;
 	int ret;
 	u8 tmp;
@@ -569,13 +570,14 @@ static int tda10071_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
 static int tda10071_read_ber(struct dvb_frontend *fe, u32 *ber)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	struct tda10071_cmd cmd;
 	int ret, i, len;
 	u8 tmp, reg, buf[8];
@@ -607,8 +609,7 @@ static int tda10071_read_ber(struct dvb_frontend *fe, u32 *ber)
 		goto error;
 
 	if (priv->meas_count[i] == tmp) {
-		dev_dbg(&priv->i2c->dev, "%s: meas not ready=%02x\n", __func__,
-				tmp);
+		dev_dbg(&client->dev, "meas not ready=%02x\n", tmp);
 		*ber = priv->ber;
 		return 0;
 	} else {
@@ -637,13 +638,14 @@ static int tda10071_read_ber(struct dvb_frontend *fe, u32 *ber)
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
 static int tda10071_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	int ret = 0;
 
 	if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) {
@@ -657,24 +659,24 @@ static int tda10071_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
 static int tda10071_set_frontend(struct dvb_frontend *fe)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	struct tda10071_cmd cmd;
 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 	int ret, i;
 	u8 mode, rolloff, pilot, inversion, div;
 	enum fe_modulation modulation;
 
-	dev_dbg(&priv->i2c->dev,
-			"%s: delivery_system=%d modulation=%d frequency=%d symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n",
-			__func__, c->delivery_system, c->modulation,
-			c->frequency, c->symbol_rate, c->inversion, c->pilot,
-			c->rolloff);
+	dev_dbg(&client->dev,
+		"delivery_system=%d modulation=%d frequency=%u symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n",
+		c->delivery_system, c->modulation, c->frequency, c->symbol_rate,
+		c->inversion, c->pilot, c->rolloff);
 
 	priv->delivery_system = SYS_UNDEFINED;
 
@@ -696,7 +698,7 @@ static int tda10071_set_frontend(struct dvb_frontend *fe)
 		inversion = 3;
 		break;
 	default:
-		dev_dbg(&priv->i2c->dev, "%s: invalid inversion\n", __func__);
+		dev_dbg(&client->dev, "invalid inversion\n");
 		ret = -EINVAL;
 		goto error;
 	}
@@ -722,8 +724,7 @@ static int tda10071_set_frontend(struct dvb_frontend *fe)
 			break;
 		case ROLLOFF_AUTO:
 		default:
-			dev_dbg(&priv->i2c->dev, "%s: invalid rolloff\n",
-					__func__);
+			dev_dbg(&client->dev, "invalid rolloff\n");
 			ret = -EINVAL;
 			goto error;
 		}
@@ -739,15 +740,13 @@ static int tda10071_set_frontend(struct dvb_frontend *fe)
 			pilot = 2;
 			break;
 		default:
-			dev_dbg(&priv->i2c->dev, "%s: invalid pilot\n",
-					__func__);
+			dev_dbg(&client->dev, "invalid pilot\n");
 			ret = -EINVAL;
 			goto error;
 		}
 		break;
 	default:
-		dev_dbg(&priv->i2c->dev, "%s: invalid delivery_system\n",
-				__func__);
+		dev_dbg(&client->dev, "invalid delivery_system\n");
 		ret = -EINVAL;
 		goto error;
 	}
@@ -757,15 +756,13 @@ static int tda10071_set_frontend(struct dvb_frontend *fe)
 			modulation == TDA10071_MODCOD[i].modulation &&
 			c->fec_inner == TDA10071_MODCOD[i].fec) {
 			mode = TDA10071_MODCOD[i].val;
-			dev_dbg(&priv->i2c->dev, "%s: mode found=%02x\n",
-					__func__, mode);
+			dev_dbg(&client->dev, "mode found=%02x\n", mode);
 			break;
 		}
 	}
 
 	if (mode == 0xff) {
-		dev_dbg(&priv->i2c->dev, "%s: invalid parameter combination\n",
-				__func__);
+		dev_dbg(&client->dev, "invalid parameter combination\n");
 		ret = -EINVAL;
 		goto error;
 	}
@@ -807,13 +804,14 @@ static int tda10071_set_frontend(struct dvb_frontend *fe)
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
 static int tda10071_get_frontend(struct dvb_frontend *fe)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 	int ret, i;
 	u8 buf[5], tmp;
@@ -864,13 +862,14 @@ static int tda10071_get_frontend(struct dvb_frontend *fe)
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
 static int tda10071_init(struct dvb_frontend *fe)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	struct tda10071_cmd cmd;
 	int ret, i, len, remaining, fw_size;
 	const struct firmware *fw;
@@ -890,7 +889,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 	};
 	struct tda10071_reg_val_mask tab2[] = {
 		{ 0xf1, 0x70, 0xff },
-		{ 0x88, priv->cfg.pll_multiplier, 0x3f },
+		{ 0x88, priv->pll_multiplier, 0x3f },
 		{ 0x89, 0x00, 0x10 },
 		{ 0x89, 0x10, 0x10 },
 		{ 0xc0, 0x01, 0x01 },
@@ -955,11 +954,11 @@ static int tda10071_init(struct dvb_frontend *fe)
 		/* cold state - try to download firmware */
 
 		/* request the firmware, this will block and timeout */
-		ret = request_firmware(&fw, fw_file, priv->i2c->dev.parent);
+		ret = request_firmware(&fw, fw_file, &client->dev);
 		if (ret) {
-			dev_err(&priv->i2c->dev,
-					"%s: did not find the firmware file. (%s) Please see linux/Documentation/dvb/ for more details on firmware-problems. (%d)\n",
-					KBUILD_MODNAME, fw_file, ret);
+			dev_err(&client->dev,
+				"did not find the firmware file. (%s) Please see linux/Documentation/dvb/ for more details on firmware-problems. (%d)\n",
+				fw_file, ret);
 			goto error;
 		}
 
@@ -988,28 +987,26 @@ static int tda10071_init(struct dvb_frontend *fe)
 		if (ret)
 			goto error_release_firmware;
 
-		dev_info(&priv->i2c->dev,
-				"%s: found a '%s' in cold state, will try to load a firmware\n",
-				KBUILD_MODNAME, tda10071_ops.info.name);
-		dev_info(&priv->i2c->dev,
-				"%s: downloading firmware from file '%s'\n",
-				KBUILD_MODNAME, fw_file);
+		dev_info(&client->dev,
+			 "found a '%s' in cold state, will try to load a firmware\n",
+			 tda10071_ops.info.name);
+		dev_info(&client->dev, "downloading firmware from file '%s'\n",
+			 fw_file);
 
 		/* do not download last byte */
 		fw_size = fw->size - 1;
 
 		for (remaining = fw_size; remaining > 0;
-			remaining -= (priv->cfg.i2c_wr_max - 1)) {
+			remaining -= (priv->i2c_wr_max - 1)) {
 			len = remaining;
-			if (len > (priv->cfg.i2c_wr_max - 1))
-				len = (priv->cfg.i2c_wr_max - 1);
+			if (len > (priv->i2c_wr_max - 1))
+				len = (priv->i2c_wr_max - 1);
 
 			ret = tda10071_wr_regs(priv, 0xfa,
 				(u8 *) &fw->data[fw_size - remaining], len);
 			if (ret) {
-				dev_err(&priv->i2c->dev,
-						"%s: firmware download failed=%d\n",
-						KBUILD_MODNAME, ret);
+				dev_err(&client->dev,
+					"firmware download failed=%d\n", ret);
 				goto error_release_firmware;
 			}
 		}
@@ -1032,8 +1029,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 			goto error;
 
 		if (tmp) {
-			dev_info(&priv->i2c->dev, "%s: firmware did not run\n",
-					KBUILD_MODNAME);
+			dev_info(&client->dev, "firmware did not run\n");
 			ret = -EFAULT;
 			goto error;
 		} else {
@@ -1050,30 +1046,30 @@ static int tda10071_init(struct dvb_frontend *fe)
 		if (ret)
 			goto error;
 
-		dev_info(&priv->i2c->dev, "%s: firmware version %d.%d.%d.%d\n",
-				KBUILD_MODNAME, buf[0], buf[1], buf[2], buf[3]);
-		dev_info(&priv->i2c->dev, "%s: found a '%s' in warm state\n",
-				KBUILD_MODNAME, tda10071_ops.info.name);
+		dev_info(&client->dev, "firmware version %d.%d.%d.%d\n",
+			 buf[0], buf[1], buf[2], buf[3]);
+		dev_info(&client->dev, "found a '%s' in warm state\n",
+			 tda10071_ops.info.name);
 
 		ret = tda10071_rd_regs(priv, 0x81, buf, 2);
 		if (ret)
 			goto error;
 
 		cmd.args[0] = CMD_DEMOD_INIT;
-		cmd.args[1] = ((priv->cfg.xtal / 1000) >> 8) & 0xff;
-		cmd.args[2] = ((priv->cfg.xtal / 1000) >> 0) & 0xff;
+		cmd.args[1] = ((priv->clk / 1000) >> 8) & 0xff;
+		cmd.args[2] = ((priv->clk / 1000) >> 0) & 0xff;
 		cmd.args[3] = buf[0];
 		cmd.args[4] = buf[1];
-		cmd.args[5] = priv->cfg.pll_multiplier;
-		cmd.args[6] = priv->cfg.spec_inv;
+		cmd.args[5] = priv->pll_multiplier;
+		cmd.args[6] = priv->spec_inv;
 		cmd.args[7] = 0x00;
 		cmd.len = 8;
 		ret = tda10071_cmd_execute(priv, &cmd);
 		if (ret)
 			goto error;
 
-		if (priv->cfg.tuner_i2c_addr)
-			tmp = priv->cfg.tuner_i2c_addr;
+		if (priv->tuner_i2c_addr)
+			tmp = priv->tuner_i2c_addr;
 		else
 			tmp = 0x14;
 
@@ -1099,7 +1095,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 
 		cmd.args[0] = CMD_MPEG_CONFIG;
 		cmd.args[1] = 0;
-		cmd.args[2] = priv->cfg.ts_mode;
+		cmd.args[2] = priv->ts_mode;
 		cmd.args[3] = 0x00;
 		cmd.args[4] = 0x04;
 		cmd.args[5] = 0x00;
@@ -1142,13 +1138,14 @@ static int tda10071_init(struct dvb_frontend *fe)
 error_release_firmware:
 	release_firmware(fw);
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
 static int tda10071_sleep(struct dvb_frontend *fe)
 {
 	struct tda10071_priv *priv = fe->demodulator_priv;
+	struct i2c_client *client = priv->client;
 	struct tda10071_cmd cmd;
 	int ret, i;
 	struct tda10071_reg_val_mask tab[] = {
@@ -1186,7 +1183,7 @@ static int tda10071_sleep(struct dvb_frontend *fe)
 
 	return ret;
 error:
-	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
 
@@ -1200,71 +1197,6 @@ static int tda10071_get_tune_settings(struct dvb_frontend *fe,
 	return 0;
 }
 
-static void tda10071_release(struct dvb_frontend *fe)
-{
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	kfree(priv);
-}
-
-struct dvb_frontend *tda10071_attach(const struct tda10071_config *config,
-	struct i2c_adapter *i2c)
-{
-	int ret;
-	struct tda10071_priv *priv = NULL;
-	u8 tmp;
-
-	/* allocate memory for the internal priv */
-	priv = kzalloc(sizeof(struct tda10071_priv), GFP_KERNEL);
-	if (priv == NULL) {
-		ret = -ENOMEM;
-		goto error;
-	}
-
-	/* make sure demod i2c address is specified */
-	if (!config->demod_i2c_addr) {
-		dev_dbg(&i2c->dev, "%s: invalid demod i2c address\n", __func__);
-		ret = -EINVAL;
-		goto error;
-	}
-
-	/* make sure tuner i2c address is specified */
-	if (!config->tuner_i2c_addr) {
-		dev_dbg(&i2c->dev, "%s: invalid tuner i2c address\n", __func__);
-		ret = -EINVAL;
-		goto error;
-	}
-
-	/* setup the priv */
-	priv->i2c = i2c;
-	memcpy(&priv->cfg, config, sizeof(struct tda10071_config));
-
-	/* chip ID */
-	ret = tda10071_rd_reg(priv, 0xff, &tmp);
-	if (ret || tmp != 0x0f)
-		goto error;
-
-	/* chip type */
-	ret = tda10071_rd_reg(priv, 0xdd, &tmp);
-	if (ret || tmp != 0x00)
-		goto error;
-
-	/* chip version */
-	ret = tda10071_rd_reg(priv, 0xfe, &tmp);
-	if (ret || tmp != 0x01)
-		goto error;
-
-	/* create dvb_frontend */
-	memcpy(&priv->fe.ops, &tda10071_ops, sizeof(struct dvb_frontend_ops));
-	priv->fe.demodulator_priv = priv;
-
-	return &priv->fe;
-error:
-	dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret);
-	kfree(priv);
-	return NULL;
-}
-EXPORT_SYMBOL(tda10071_attach);
-
 static struct dvb_frontend_ops tda10071_ops = {
 	.delsys = { SYS_DVBS, SYS_DVBS2 },
 	.info = {
@@ -1289,8 +1221,6 @@ static struct dvb_frontend_ops tda10071_ops = {
 			FE_CAN_2G_MODULATION
 	},
 
-	.release = tda10071_release,
-
 	.get_tune_settings = tda10071_get_tune_settings,
 
 	.init = tda10071_init,
@@ -1337,14 +1267,12 @@ static int tda10071_probe(struct i2c_client *client,
 	}
 
 	dev->client = client;
-	dev->i2c = client->adapter;
-	dev->cfg.demod_i2c_addr = client->addr;
-	dev->cfg.i2c_wr_max = pdata->i2c_wr_max;
-	dev->cfg.ts_mode = pdata->ts_mode;
-	dev->cfg.spec_inv = pdata->spec_inv;
-	dev->cfg.xtal = pdata->clk;
-	dev->cfg.pll_multiplier = pdata->pll_multiplier;
-	dev->cfg.tuner_i2c_addr = pdata->tuner_i2c_addr;
+	dev->clk = pdata->clk;
+	dev->i2c_wr_max = pdata->i2c_wr_max;
+	dev->ts_mode = pdata->ts_mode;
+	dev->spec_inv = pdata->spec_inv;
+	dev->pll_multiplier = pdata->pll_multiplier;
+	dev->tuner_i2c_addr = pdata->tuner_i2c_addr;
 
 	/* chip ID */
 	ret = tda10071_rd_reg(dev, 0xff, &u8tmp);
@@ -1375,7 +1303,6 @@ static int tda10071_probe(struct i2c_client *client,
 
 	/* create dvb_frontend */
 	memcpy(&dev->fe.ops, &tda10071_ops, sizeof(struct dvb_frontend_ops));
-	dev->fe.ops.release = NULL;
 	dev->fe.demodulator_priv = dev;
 	i2c_set_clientdata(client, dev);
 
diff --git a/drivers/media/dvb-frontends/tda10071.h b/drivers/media/dvb-frontends/tda10071.h
index 0ffbfa5..8f18402 100644
--- a/drivers/media/dvb-frontends/tda10071.h
+++ b/drivers/media/dvb-frontends/tda10071.h
@@ -21,12 +21,11 @@
 #ifndef TDA10071_H
 #define TDA10071_H
 
-#include <linux/kconfig.h>
 #include <linux/dvb/frontend.h>
 
 /*
  * I2C address
- * 0x55,
+ * 0x05, 0x55,
  */
 
 /**
@@ -53,64 +52,4 @@ struct tda10071_platform_data {
 	struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
 };
 
-struct tda10071_config {
-	/* Demodulator I2C address.
-	 * Default: none, must set
-	 * Values: 0x55,
-	 */
-	u8 demod_i2c_addr;
-
-	/* Tuner I2C address.
-	 * Default: none, must set
-	 * Values: 0x14, 0x54, ...
-	 */
-	u8 tuner_i2c_addr;
-
-	/* Max bytes I2C provider can write at once.
-	 * Note: Buffer is taken from the stack currently!
-	 * Default: none, must set
-	 * Values:
-	 */
-	u16 i2c_wr_max;
-
-	/* TS output mode.
-	 * Default: TDA10071_TS_SERIAL
-	 * Values:
-	 */
-#define TDA10071_TS_SERIAL        0
-#define TDA10071_TS_PARALLEL      1
-	u8 ts_mode;
-
-	/* Input spectrum inversion.
-	 * Default: 0
-	 * Values: 0, 1
-	 */
-	bool spec_inv;
-
-	/* Xtal frequency Hz
-	 * Default: none, must set
-	 * Values:
-	 */
-	u32 xtal;
-
-	/* PLL multiplier.
-	 * Default: none, must set
-	 * Values:
-	 */
-	u8 pll_multiplier;
-};
-
-
-#if IS_REACHABLE(CONFIG_DVB_TDA10071)
-extern struct dvb_frontend *tda10071_attach(
-	const struct tda10071_config *config, struct i2c_adapter *i2c);
-#else
-static inline struct dvb_frontend *tda10071_attach(
-	const struct tda10071_config *config, struct i2c_adapter *i2c)
-{
-	dev_warn(&i2c->dev, "%s: driver disabled by Kconfig\n", __func__);
-	return NULL;
-}
-#endif
-
 #endif /* TDA10071_H */
diff --git a/drivers/media/dvb-frontends/tda10071_priv.h b/drivers/media/dvb-frontends/tda10071_priv.h
index 54d7c71..a6d8f8c 100644
--- a/drivers/media/dvb-frontends/tda10071_priv.h
+++ b/drivers/media/dvb-frontends/tda10071_priv.h
@@ -26,10 +26,14 @@
 #include <linux/firmware.h>
 
 struct tda10071_priv {
-	struct i2c_adapter *i2c;
 	struct dvb_frontend fe;
 	struct i2c_client *client;
-	struct tda10071_config cfg;
+	u32 clk;
+	u16 i2c_wr_max;
+	u8 ts_mode;
+	bool spec_inv;
+	u8 pll_multiplier;
+	u8 tuner_i2c_addr;
 
 	u8 meas_count[2];
 	u32 ber;
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 07/12] tda10071: rename device state struct to dev
  2015-07-09  4:06 [PATCH 01/12] em28xx: remove unused a8293 SEC config Antti Palosaari
                   ` (4 preceding siblings ...)
  2015-07-09  4:06 ` [PATCH 06/12] tda10071: remove legacy media attach Antti Palosaari
@ 2015-07-09  4:06 ` Antti Palosaari
  2015-07-09  4:06 ` [PATCH 08/12] tda10071: convert to regmap I2C API Antti Palosaari
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Antti Palosaari @ 2015-07-09  4:06 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Rename device state struct from 'priv' to 'dev'.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/dvb-frontends/tda10071.c      | 268 ++++++++++++++--------------
 drivers/media/dvb-frontends/tda10071_priv.h |   2 +-
 2 files changed, 135 insertions(+), 135 deletions(-)

diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c
index cc65285..39a4197 100644
--- a/drivers/media/dvb-frontends/tda10071.c
+++ b/drivers/media/dvb-frontends/tda10071.c
@@ -26,10 +26,10 @@
 static struct dvb_frontend_ops tda10071_ops;
 
 /* write multiple registers */
-static int tda10071_wr_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
+static int tda10071_wr_regs(struct tda10071_dev *dev, u8 reg, u8 *val,
 	int len)
 {
-	struct i2c_client *client = priv->client;
+	struct i2c_client *client = dev->client;
 	int ret;
 	u8 buf[MAX_XFER_SIZE];
 	struct i2c_msg msg[1] = {
@@ -62,10 +62,10 @@ static int tda10071_wr_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
 }
 
 /* read multiple registers */
-static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
+static int tda10071_rd_regs(struct tda10071_dev *dev, u8 reg, u8 *val,
 	int len)
 {
-	struct i2c_client *client = priv->client;
+	struct i2c_client *client = dev->client;
 	int ret;
 	u8 buf[MAX_XFER_SIZE];
 	struct i2c_msg msg[2] = {
@@ -101,19 +101,19 @@ static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
 }
 
 /* write single register */
-static int tda10071_wr_reg(struct tda10071_priv *priv, u8 reg, u8 val)
+static int tda10071_wr_reg(struct tda10071_dev *dev, u8 reg, u8 val)
 {
-	return tda10071_wr_regs(priv, reg, &val, 1);
+	return tda10071_wr_regs(dev, reg, &val, 1);
 }
 
 /* read single register */
-static int tda10071_rd_reg(struct tda10071_priv *priv, u8 reg, u8 *val)
+static int tda10071_rd_reg(struct tda10071_dev *dev, u8 reg, u8 *val)
 {
-	return tda10071_rd_regs(priv, reg, val, 1);
+	return tda10071_rd_regs(dev, reg, val, 1);
 }
 
 /* write single register with mask */
-static int tda10071_wr_reg_mask(struct tda10071_priv *priv,
+static int tda10071_wr_reg_mask(struct tda10071_dev *dev,
 				u8 reg, u8 val, u8 mask)
 {
 	int ret;
@@ -121,7 +121,7 @@ static int tda10071_wr_reg_mask(struct tda10071_priv *priv,
 
 	/* no need for read if whole reg is written */
 	if (mask != 0xff) {
-		ret = tda10071_rd_regs(priv, reg, &tmp, 1);
+		ret = tda10071_rd_regs(dev, reg, &tmp, 1);
 		if (ret)
 			return ret;
 
@@ -130,17 +130,17 @@ static int tda10071_wr_reg_mask(struct tda10071_priv *priv,
 		val |= tmp;
 	}
 
-	return tda10071_wr_regs(priv, reg, &val, 1);
+	return tda10071_wr_regs(dev, reg, &val, 1);
 }
 
 /* read single register with mask */
-static int tda10071_rd_reg_mask(struct tda10071_priv *priv,
+static int tda10071_rd_reg_mask(struct tda10071_dev *dev,
 				u8 reg, u8 *val, u8 mask)
 {
 	int ret, i;
 	u8 tmp;
 
-	ret = tda10071_rd_regs(priv, reg, &tmp, 1);
+	ret = tda10071_rd_regs(dev, reg, &tmp, 1);
 	if (ret)
 		return ret;
 
@@ -157,31 +157,31 @@ static int tda10071_rd_reg_mask(struct tda10071_priv *priv,
 }
 
 /* execute firmware command */
-static int tda10071_cmd_execute(struct tda10071_priv *priv,
+static int tda10071_cmd_execute(struct tda10071_dev *dev,
 	struct tda10071_cmd *cmd)
 {
-	struct i2c_client *client = priv->client;
+	struct i2c_client *client = dev->client;
 	int ret, i;
 	u8 tmp;
 
-	if (!priv->warm) {
+	if (!dev->warm) {
 		ret = -EFAULT;
 		goto error;
 	}
 
 	/* write cmd and args for firmware */
-	ret = tda10071_wr_regs(priv, 0x00, cmd->args, cmd->len);
+	ret = tda10071_wr_regs(dev, 0x00, cmd->args, cmd->len);
 	if (ret)
 		goto error;
 
 	/* start cmd execution */
-	ret = tda10071_wr_reg(priv, 0x1f, 1);
+	ret = tda10071_wr_reg(dev, 0x1f, 1);
 	if (ret)
 		goto error;
 
 	/* wait cmd execution terminate */
 	for (i = 1000, tmp = 1; i && tmp; i--) {
-		ret = tda10071_rd_reg(priv, 0x1f, &tmp);
+		ret = tda10071_rd_reg(dev, 0x1f, &tmp);
 		if (ret)
 			goto error;
 
@@ -204,13 +204,13 @@ error:
 static int tda10071_set_tone(struct dvb_frontend *fe,
 	enum fe_sec_tone_mode fe_sec_tone_mode)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret;
 	u8 tone;
 
-	if (!priv->warm) {
+	if (!dev->warm) {
 		ret = -EFAULT;
 		goto error;
 	}
@@ -236,7 +236,7 @@ static int tda10071_set_tone(struct dvb_frontend *fe,
 	cmd.args[3] = 0x00;
 	cmd.args[4] = tone;
 	cmd.len = 5;
-	ret = tda10071_cmd_execute(priv, &cmd);
+	ret = tda10071_cmd_execute(dev, &cmd);
 	if (ret)
 		goto error;
 
@@ -249,13 +249,13 @@ error:
 static int tda10071_set_voltage(struct dvb_frontend *fe,
 	enum fe_sec_voltage fe_sec_voltage)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret;
 	u8 voltage;
 
-	if (!priv->warm) {
+	if (!dev->warm) {
 		ret = -EFAULT;
 		goto error;
 	}
@@ -282,7 +282,7 @@ static int tda10071_set_voltage(struct dvb_frontend *fe,
 	cmd.args[1] = 0;
 	cmd.args[2] = voltage;
 	cmd.len = 3;
-	ret = tda10071_cmd_execute(priv, &cmd);
+	ret = tda10071_cmd_execute(dev, &cmd);
 	if (ret)
 		goto error;
 
@@ -295,13 +295,13 @@ error:
 static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe,
 	struct dvb_diseqc_master_cmd *diseqc_cmd)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret, i;
 	u8 tmp;
 
-	if (!priv->warm) {
+	if (!dev->warm) {
 		ret = -EFAULT;
 		goto error;
 	}
@@ -315,7 +315,7 @@ static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe,
 
 	/* wait LNB TX */
 	for (i = 500, tmp = 0; i && !tmp; i--) {
-		ret = tda10071_rd_reg_mask(priv, 0x47, &tmp, 0x01);
+		ret = tda10071_rd_reg_mask(dev, 0x47, &tmp, 0x01);
 		if (ret)
 			goto error;
 
@@ -329,7 +329,7 @@ static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe,
 		goto error;
 	}
 
-	ret = tda10071_wr_reg_mask(priv, 0x47, 0x00, 0x01);
+	ret = tda10071_wr_reg_mask(dev, 0x47, 0x00, 0x01);
 	if (ret)
 		goto error;
 
@@ -342,7 +342,7 @@ static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe,
 	cmd.args[6] = diseqc_cmd->msg_len;
 	memcpy(&cmd.args[7], diseqc_cmd->msg, diseqc_cmd->msg_len);
 	cmd.len = 7 + diseqc_cmd->msg_len;
-	ret = tda10071_cmd_execute(priv, &cmd);
+	ret = tda10071_cmd_execute(dev, &cmd);
 	if (ret)
 		goto error;
 
@@ -355,13 +355,13 @@ error:
 static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe,
 	struct dvb_diseqc_slave_reply *reply)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret, i;
 	u8 tmp;
 
-	if (!priv->warm) {
+	if (!dev->warm) {
 		ret = -EFAULT;
 		goto error;
 	}
@@ -370,7 +370,7 @@ static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe,
 
 	/* wait LNB RX */
 	for (i = 500, tmp = 0; i && !tmp; i--) {
-		ret = tda10071_rd_reg_mask(priv, 0x47, &tmp, 0x02);
+		ret = tda10071_rd_reg_mask(dev, 0x47, &tmp, 0x02);
 		if (ret)
 			goto error;
 
@@ -385,7 +385,7 @@ static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe,
 	}
 
 	/* reply len */
-	ret = tda10071_rd_reg(priv, 0x46, &tmp);
+	ret = tda10071_rd_reg(dev, 0x46, &tmp);
 	if (ret)
 		goto error;
 
@@ -397,11 +397,11 @@ static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe,
 	cmd.args[0] = CMD_LNB_UPDATE_REPLY;
 	cmd.args[1] = 0;
 	cmd.len = 2;
-	ret = tda10071_cmd_execute(priv, &cmd);
+	ret = tda10071_cmd_execute(dev, &cmd);
 	if (ret)
 		goto error;
 
-	ret = tda10071_rd_regs(priv, cmd.len, reply->msg, reply->msg_len);
+	ret = tda10071_rd_regs(dev, cmd.len, reply->msg, reply->msg_len);
 	if (ret)
 		goto error;
 
@@ -414,13 +414,13 @@ error:
 static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
 	enum fe_sec_mini_cmd fe_sec_mini_cmd)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret, i;
 	u8 tmp, burst;
 
-	if (!priv->warm) {
+	if (!dev->warm) {
 		ret = -EFAULT;
 		goto error;
 	}
@@ -442,7 +442,7 @@ static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
 
 	/* wait LNB TX */
 	for (i = 500, tmp = 0; i && !tmp; i--) {
-		ret = tda10071_rd_reg_mask(priv, 0x47, &tmp, 0x01);
+		ret = tda10071_rd_reg_mask(dev, 0x47, &tmp, 0x01);
 		if (ret)
 			goto error;
 
@@ -456,7 +456,7 @@ static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
 		goto error;
 	}
 
-	ret = tda10071_wr_reg_mask(priv, 0x47, 0x00, 0x01);
+	ret = tda10071_wr_reg_mask(dev, 0x47, 0x00, 0x01);
 	if (ret)
 		goto error;
 
@@ -464,7 +464,7 @@ static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
 	cmd.args[1] = 0;
 	cmd.args[2] = burst;
 	cmd.len = 3;
-	ret = tda10071_cmd_execute(priv, &cmd);
+	ret = tda10071_cmd_execute(dev, &cmd);
 	if (ret)
 		goto error;
 
@@ -476,19 +476,19 @@ error:
 
 static int tda10071_read_status(struct dvb_frontend *fe, enum fe_status *status)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	int ret;
 	u8 tmp;
 
 	*status = 0;
 
-	if (!priv->warm) {
+	if (!dev->warm) {
 		ret = 0;
 		goto error;
 	}
 
-	ret = tda10071_rd_reg(priv, 0x39, &tmp);
+	ret = tda10071_rd_reg(dev, 0x39, &tmp);
 	if (ret)
 		goto error;
 
@@ -500,7 +500,7 @@ static int tda10071_read_status(struct dvb_frontend *fe, enum fe_status *status)
 	if (tmp & 0x08) /* RS or BCH */
 		*status |= FE_HAS_SYNC | FE_HAS_LOCK;
 
-	priv->fe_status = *status;
+	dev->fe_status = *status;
 
 	return ret;
 error:
@@ -510,18 +510,18 @@ error:
 
 static int tda10071_read_snr(struct dvb_frontend *fe, u16 *snr)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	int ret;
 	u8 buf[2];
 
-	if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) {
+	if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
 		*snr = 0;
 		ret = 0;
 		goto error;
 	}
 
-	ret = tda10071_rd_regs(priv, 0x3a, buf, 2);
+	ret = tda10071_rd_regs(dev, 0x3a, buf, 2);
 	if (ret)
 		goto error;
 
@@ -536,13 +536,13 @@ error:
 
 static int tda10071_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret;
 	u8 tmp;
 
-	if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) {
+	if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
 		*strength = 0;
 		ret = 0;
 		goto error;
@@ -551,12 +551,12 @@ static int tda10071_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
 	cmd.args[0] = CMD_GET_AGCACC;
 	cmd.args[1] = 0;
 	cmd.len = 2;
-	ret = tda10071_cmd_execute(priv, &cmd);
+	ret = tda10071_cmd_execute(dev, &cmd);
 	if (ret)
 		goto error;
 
 	/* input power estimate dBm */
-	ret = tda10071_rd_reg(priv, 0x50, &tmp);
+	ret = tda10071_rd_reg(dev, 0x50, &tmp);
 	if (ret)
 		goto error;
 
@@ -576,19 +576,19 @@ error:
 
 static int tda10071_read_ber(struct dvb_frontend *fe, u32 *ber)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret, i, len;
 	u8 tmp, reg, buf[8];
 
-	if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) {
-		*ber = priv->ber = 0;
+	if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
+		*ber = dev->ber = 0;
 		ret = 0;
 		goto error;
 	}
 
-	switch (priv->delivery_system) {
+	switch (dev->delivery_system) {
 	case SYS_DVBS:
 		reg = 0x4c;
 		len = 8;
@@ -600,41 +600,41 @@ static int tda10071_read_ber(struct dvb_frontend *fe, u32 *ber)
 		i = 0;
 		break;
 	default:
-		*ber = priv->ber = 0;
+		*ber = dev->ber = 0;
 		return 0;
 	}
 
-	ret = tda10071_rd_reg(priv, reg, &tmp);
+	ret = tda10071_rd_reg(dev, reg, &tmp);
 	if (ret)
 		goto error;
 
-	if (priv->meas_count[i] == tmp) {
+	if (dev->meas_count[i] == tmp) {
 		dev_dbg(&client->dev, "meas not ready=%02x\n", tmp);
-		*ber = priv->ber;
+		*ber = dev->ber;
 		return 0;
 	} else {
-		priv->meas_count[i] = tmp;
+		dev->meas_count[i] = tmp;
 	}
 
 	cmd.args[0] = CMD_BER_UPDATE_COUNTERS;
 	cmd.args[1] = 0;
 	cmd.args[2] = i;
 	cmd.len = 3;
-	ret = tda10071_cmd_execute(priv, &cmd);
+	ret = tda10071_cmd_execute(dev, &cmd);
 	if (ret)
 		goto error;
 
-	ret = tda10071_rd_regs(priv, cmd.len, buf, len);
+	ret = tda10071_rd_regs(dev, cmd.len, buf, len);
 	if (ret)
 		goto error;
 
-	if (priv->delivery_system == SYS_DVBS) {
+	if (dev->delivery_system == SYS_DVBS) {
 		*ber = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
-		priv->ucb += (buf[4] << 8) | buf[5];
+		dev->ucb += (buf[4] << 8) | buf[5];
 	} else {
 		*ber = (buf[0] << 8) | buf[1];
 	}
-	priv->ber = *ber;
+	dev->ber = *ber;
 
 	return ret;
 error:
@@ -644,18 +644,18 @@ error:
 
 static int tda10071_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	int ret = 0;
 
-	if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) {
+	if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
 		*ucblocks = 0;
 		goto error;
 	}
 
 	/* UCB is updated when BER is read. Assume BER is read anyway. */
 
-	*ucblocks = priv->ucb;
+	*ucblocks = dev->ucb;
 
 	return ret;
 error:
@@ -665,8 +665,8 @@ error:
 
 static int tda10071_set_frontend(struct dvb_frontend *fe)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 	int ret, i;
@@ -678,9 +678,9 @@ static int tda10071_set_frontend(struct dvb_frontend *fe)
 		c->delivery_system, c->modulation, c->frequency, c->symbol_rate,
 		c->inversion, c->pilot, c->rolloff);
 
-	priv->delivery_system = SYS_UNDEFINED;
+	dev->delivery_system = SYS_UNDEFINED;
 
-	if (!priv->warm) {
+	if (!dev->warm) {
 		ret = -EFAULT;
 		goto error;
 	}
@@ -772,11 +772,11 @@ static int tda10071_set_frontend(struct dvb_frontend *fe)
 	else
 		div = 4;
 
-	ret = tda10071_wr_reg(priv, 0x81, div);
+	ret = tda10071_wr_reg(dev, 0x81, div);
 	if (ret)
 		goto error;
 
-	ret = tda10071_wr_reg(priv, 0xe3, div);
+	ret = tda10071_wr_reg(dev, 0xe3, div);
 	if (ret)
 		goto error;
 
@@ -796,11 +796,11 @@ static int tda10071_set_frontend(struct dvb_frontend *fe)
 	cmd.args[13] = 0x00;
 	cmd.args[14] = 0x00;
 	cmd.len = 15;
-	ret = tda10071_cmd_execute(priv, &cmd);
+	ret = tda10071_cmd_execute(dev, &cmd);
 	if (ret)
 		goto error;
 
-	priv->delivery_system = c->delivery_system;
+	dev->delivery_system = c->delivery_system;
 
 	return ret;
 error:
@@ -810,18 +810,18 @@ error:
 
 static int tda10071_get_frontend(struct dvb_frontend *fe)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 	int ret, i;
 	u8 buf[5], tmp;
 
-	if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) {
+	if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
 		ret = -EFAULT;
 		goto error;
 	}
 
-	ret = tda10071_rd_regs(priv, 0x30, buf, 5);
+	ret = tda10071_rd_regs(dev, 0x30, buf, 5);
 	if (ret)
 		goto error;
 
@@ -854,7 +854,7 @@ static int tda10071_get_frontend(struct dvb_frontend *fe)
 
 	c->frequency = (buf[2] << 16) | (buf[3] << 8) | (buf[4] << 0);
 
-	ret = tda10071_rd_regs(priv, 0x52, buf, 3);
+	ret = tda10071_rd_regs(dev, 0x52, buf, 3);
 	if (ret)
 		goto error;
 
@@ -868,8 +868,8 @@ error:
 
 static int tda10071_init(struct dvb_frontend *fe)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret, i, len, remaining, fw_size;
 	const struct firmware *fw;
@@ -889,7 +889,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 	};
 	struct tda10071_reg_val_mask tab2[] = {
 		{ 0xf1, 0x70, 0xff },
-		{ 0x88, priv->pll_multiplier, 0x3f },
+		{ 0x88, dev->pll_multiplier, 0x3f },
 		{ 0x89, 0x00, 0x10 },
 		{ 0x89, 0x10, 0x10 },
 		{ 0xc0, 0x01, 0x01 },
@@ -933,11 +933,11 @@ static int tda10071_init(struct dvb_frontend *fe)
 		{ 0xd5, 0x03, 0x03 },
 	};
 
-	if (priv->warm) {
+	if (dev->warm) {
 		/* warm state - wake up device from sleep */
 
 		for (i = 0; i < ARRAY_SIZE(tab); i++) {
-			ret = tda10071_wr_reg_mask(priv, tab[i].reg,
+			ret = tda10071_wr_reg_mask(dev, tab[i].reg,
 				tab[i].val, tab[i].mask);
 			if (ret)
 				goto error;
@@ -947,7 +947,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 		cmd.args[1] = 0;
 		cmd.args[2] = 0;
 		cmd.len = 3;
-		ret = tda10071_cmd_execute(priv, &cmd);
+		ret = tda10071_cmd_execute(dev, &cmd);
 		if (ret)
 			goto error;
 	} else {
@@ -964,26 +964,26 @@ static int tda10071_init(struct dvb_frontend *fe)
 
 		/* init */
 		for (i = 0; i < ARRAY_SIZE(tab2); i++) {
-			ret = tda10071_wr_reg_mask(priv, tab2[i].reg,
+			ret = tda10071_wr_reg_mask(dev, tab2[i].reg,
 				tab2[i].val, tab2[i].mask);
 			if (ret)
 				goto error_release_firmware;
 		}
 
 		/*  download firmware */
-		ret = tda10071_wr_reg(priv, 0xe0, 0x7f);
+		ret = tda10071_wr_reg(dev, 0xe0, 0x7f);
 		if (ret)
 			goto error_release_firmware;
 
-		ret = tda10071_wr_reg(priv, 0xf7, 0x81);
+		ret = tda10071_wr_reg(dev, 0xf7, 0x81);
 		if (ret)
 			goto error_release_firmware;
 
-		ret = tda10071_wr_reg(priv, 0xf8, 0x00);
+		ret = tda10071_wr_reg(dev, 0xf8, 0x00);
 		if (ret)
 			goto error_release_firmware;
 
-		ret = tda10071_wr_reg(priv, 0xf9, 0x00);
+		ret = tda10071_wr_reg(dev, 0xf9, 0x00);
 		if (ret)
 			goto error_release_firmware;
 
@@ -997,12 +997,12 @@ static int tda10071_init(struct dvb_frontend *fe)
 		fw_size = fw->size - 1;
 
 		for (remaining = fw_size; remaining > 0;
-			remaining -= (priv->i2c_wr_max - 1)) {
+			remaining -= (dev->i2c_wr_max - 1)) {
 			len = remaining;
-			if (len > (priv->i2c_wr_max - 1))
-				len = (priv->i2c_wr_max - 1);
+			if (len > (dev->i2c_wr_max - 1))
+				len = (dev->i2c_wr_max - 1);
 
-			ret = tda10071_wr_regs(priv, 0xfa,
+			ret = tda10071_wr_regs(dev, 0xfa,
 				(u8 *) &fw->data[fw_size - remaining], len);
 			if (ret) {
 				dev_err(&client->dev,
@@ -1012,11 +1012,11 @@ static int tda10071_init(struct dvb_frontend *fe)
 		}
 		release_firmware(fw);
 
-		ret = tda10071_wr_reg(priv, 0xf7, 0x0c);
+		ret = tda10071_wr_reg(dev, 0xf7, 0x0c);
 		if (ret)
 			goto error;
 
-		ret = tda10071_wr_reg(priv, 0xe0, 0x00);
+		ret = tda10071_wr_reg(dev, 0xe0, 0x00);
 		if (ret)
 			goto error;
 
@@ -1024,7 +1024,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 		msleep(250);
 
 		/* firmware status */
-		ret = tda10071_rd_reg(priv, 0x51, &tmp);
+		ret = tda10071_rd_reg(dev, 0x51, &tmp);
 		if (ret)
 			goto error;
 
@@ -1033,16 +1033,16 @@ static int tda10071_init(struct dvb_frontend *fe)
 			ret = -EFAULT;
 			goto error;
 		} else {
-			priv->warm = true;
+			dev->warm = true;
 		}
 
 		cmd.args[0] = CMD_GET_FW_VERSION;
 		cmd.len = 1;
-		ret = tda10071_cmd_execute(priv, &cmd);
+		ret = tda10071_cmd_execute(dev, &cmd);
 		if (ret)
 			goto error;
 
-		ret = tda10071_rd_regs(priv, cmd.len, buf, 4);
+		ret = tda10071_rd_regs(dev, cmd.len, buf, 4);
 		if (ret)
 			goto error;
 
@@ -1051,25 +1051,25 @@ static int tda10071_init(struct dvb_frontend *fe)
 		dev_info(&client->dev, "found a '%s' in warm state\n",
 			 tda10071_ops.info.name);
 
-		ret = tda10071_rd_regs(priv, 0x81, buf, 2);
+		ret = tda10071_rd_regs(dev, 0x81, buf, 2);
 		if (ret)
 			goto error;
 
 		cmd.args[0] = CMD_DEMOD_INIT;
-		cmd.args[1] = ((priv->clk / 1000) >> 8) & 0xff;
-		cmd.args[2] = ((priv->clk / 1000) >> 0) & 0xff;
+		cmd.args[1] = ((dev->clk / 1000) >> 8) & 0xff;
+		cmd.args[2] = ((dev->clk / 1000) >> 0) & 0xff;
 		cmd.args[3] = buf[0];
 		cmd.args[4] = buf[1];
-		cmd.args[5] = priv->pll_multiplier;
-		cmd.args[6] = priv->spec_inv;
+		cmd.args[5] = dev->pll_multiplier;
+		cmd.args[6] = dev->spec_inv;
 		cmd.args[7] = 0x00;
 		cmd.len = 8;
-		ret = tda10071_cmd_execute(priv, &cmd);
+		ret = tda10071_cmd_execute(dev, &cmd);
 		if (ret)
 			goto error;
 
-		if (priv->tuner_i2c_addr)
-			tmp = priv->tuner_i2c_addr;
+		if (dev->tuner_i2c_addr)
+			tmp = dev->tuner_i2c_addr;
 		else
 			tmp = 0x14;
 
@@ -1089,22 +1089,22 @@ static int tda10071_init(struct dvb_frontend *fe)
 		cmd.args[13] = 0x00;
 		cmd.args[14] = 0x00;
 		cmd.len = 15;
-		ret = tda10071_cmd_execute(priv, &cmd);
+		ret = tda10071_cmd_execute(dev, &cmd);
 		if (ret)
 			goto error;
 
 		cmd.args[0] = CMD_MPEG_CONFIG;
 		cmd.args[1] = 0;
-		cmd.args[2] = priv->ts_mode;
+		cmd.args[2] = dev->ts_mode;
 		cmd.args[3] = 0x00;
 		cmd.args[4] = 0x04;
 		cmd.args[5] = 0x00;
 		cmd.len = 6;
-		ret = tda10071_cmd_execute(priv, &cmd);
+		ret = tda10071_cmd_execute(dev, &cmd);
 		if (ret)
 			goto error;
 
-		ret = tda10071_wr_reg_mask(priv, 0xf0, 0x01, 0x01);
+		ret = tda10071_wr_reg_mask(dev, 0xf0, 0x01, 0x01);
 		if (ret)
 			goto error;
 
@@ -1120,7 +1120,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 		cmd.args[9] = 30;
 		cmd.args[10] = 30;
 		cmd.len = 11;
-		ret = tda10071_cmd_execute(priv, &cmd);
+		ret = tda10071_cmd_execute(dev, &cmd);
 		if (ret)
 			goto error;
 
@@ -1129,7 +1129,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 		cmd.args[2] = 14;
 		cmd.args[3] = 14;
 		cmd.len = 4;
-		ret = tda10071_cmd_execute(priv, &cmd);
+		ret = tda10071_cmd_execute(dev, &cmd);
 		if (ret)
 			goto error;
 	}
@@ -1144,8 +1144,8 @@ error:
 
 static int tda10071_sleep(struct dvb_frontend *fe)
 {
-	struct tda10071_priv *priv = fe->demodulator_priv;
-	struct i2c_client *client = priv->client;
+	struct tda10071_dev *dev = fe->demodulator_priv;
+	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret, i;
 	struct tda10071_reg_val_mask tab[] = {
@@ -1161,7 +1161,7 @@ static int tda10071_sleep(struct dvb_frontend *fe)
 		{ 0xce, 0x10, 0x10 },
 	};
 
-	if (!priv->warm) {
+	if (!dev->warm) {
 		ret = -EFAULT;
 		goto error;
 	}
@@ -1170,12 +1170,12 @@ static int tda10071_sleep(struct dvb_frontend *fe)
 	cmd.args[1] = 0;
 	cmd.args[2] = 1;
 	cmd.len = 3;
-	ret = tda10071_cmd_execute(priv, &cmd);
+	ret = tda10071_cmd_execute(dev, &cmd);
 	if (ret)
 		goto error;
 
 	for (i = 0; i < ARRAY_SIZE(tab); i++) {
-		ret = tda10071_wr_reg_mask(priv, tab[i].reg, tab[i].val,
+		ret = tda10071_wr_reg_mask(dev, tab[i].reg, tab[i].val,
 			tab[i].mask);
 		if (ret)
 			goto error;
@@ -1245,7 +1245,7 @@ static struct dvb_frontend_ops tda10071_ops = {
 
 static struct dvb_frontend *tda10071_get_dvb_frontend(struct i2c_client *client)
 {
-	struct tda10071_priv *dev = i2c_get_clientdata(client);
+	struct tda10071_dev *dev = i2c_get_clientdata(client);
 
 	dev_dbg(&client->dev, "\n");
 
@@ -1255,7 +1255,7 @@ static struct dvb_frontend *tda10071_get_dvb_frontend(struct i2c_client *client)
 static int tda10071_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
-	struct tda10071_priv *dev;
+	struct tda10071_dev *dev;
 	struct tda10071_platform_data *pdata = client->dev.platform_data;
 	int ret;
 	u8 u8tmp;
diff --git a/drivers/media/dvb-frontends/tda10071_priv.h b/drivers/media/dvb-frontends/tda10071_priv.h
index a6d8f8c..9800028 100644
--- a/drivers/media/dvb-frontends/tda10071_priv.h
+++ b/drivers/media/dvb-frontends/tda10071_priv.h
@@ -25,7 +25,7 @@
 #include "tda10071.h"
 #include <linux/firmware.h>
 
-struct tda10071_priv {
+struct tda10071_dev {
 	struct dvb_frontend fe;
 	struct i2c_client *client;
 	u32 clk;
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 08/12] tda10071: convert to regmap I2C API
  2015-07-09  4:06 [PATCH 01/12] em28xx: remove unused a8293 SEC config Antti Palosaari
                   ` (5 preceding siblings ...)
  2015-07-09  4:06 ` [PATCH 07/12] tda10071: rename device state struct to dev Antti Palosaari
@ 2015-07-09  4:06 ` Antti Palosaari
  2015-07-09  4:06 ` [PATCH 09/12] tda10071: use jiffies when poll firmware status Antti Palosaari
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Antti Palosaari @ 2015-07-09  4:06 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Use regmap API for I2C operations.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/dvb-frontends/Kconfig         |   1 +
 drivers/media/dvb-frontends/tda10071.c      | 263 +++++++++-------------------
 drivers/media/dvb-frontends/tda10071_priv.h |   2 +
 3 files changed, 87 insertions(+), 179 deletions(-)

diff --git a/drivers/media/dvb-frontends/Kconfig b/drivers/media/dvb-frontends/Kconfig
index 5ab90f3..e717a05 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -264,6 +264,7 @@ config DVB_MB86A16
 config DVB_TDA10071
 	tristate "NXP TDA10071"
 	depends on DVB_CORE && I2C
+	select REGMAP
 	default m if !MEDIA_SUBDRV_AUTOSELECT
 	help
 	  Say Y when you want to support this frontend.
diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c
index 39a4197..6226b57 100644
--- a/drivers/media/dvb-frontends/tda10071.c
+++ b/drivers/media/dvb-frontends/tda10071.c
@@ -20,98 +20,13 @@
 
 #include "tda10071_priv.h"
 
-/* Max transfer size done by I2C transfer functions */
-#define MAX_XFER_SIZE  64
-
 static struct dvb_frontend_ops tda10071_ops;
 
-/* write multiple registers */
-static int tda10071_wr_regs(struct tda10071_dev *dev, u8 reg, u8 *val,
-	int len)
-{
-	struct i2c_client *client = dev->client;
-	int ret;
-	u8 buf[MAX_XFER_SIZE];
-	struct i2c_msg msg[1] = {
-		{
-			.addr = client->addr,
-			.flags = 0,
-			.len = 1 + len,
-			.buf = buf,
-		}
-	};
-
-	if (1 + len > sizeof(buf)) {
-		dev_warn(&client->dev, "i2c wr reg=%04x: len=%d is too big!\n",
-				reg, len);
-		return -EINVAL;
-	}
-
-	buf[0] = reg;
-	memcpy(&buf[1], val, len);
-
-	ret = i2c_transfer(client->adapter, msg, 1);
-	if (ret == 1) {
-		ret = 0;
-	} else {
-		dev_warn(&client->dev, "i2c wr failed=%d reg=%02x len=%d\n",
-				ret, reg, len);
-		ret = -EREMOTEIO;
-	}
-	return ret;
-}
-
-/* read multiple registers */
-static int tda10071_rd_regs(struct tda10071_dev *dev, u8 reg, u8 *val,
-	int len)
-{
-	struct i2c_client *client = dev->client;
-	int ret;
-	u8 buf[MAX_XFER_SIZE];
-	struct i2c_msg msg[2] = {
-		{
-			.addr = client->addr,
-			.flags = 0,
-			.len = 1,
-			.buf = &reg,
-		}, {
-			.addr = client->addr,
-			.flags = I2C_M_RD,
-			.len = len,
-			.buf = buf,
-		}
-	};
-
-	if (len > sizeof(buf)) {
-		dev_warn(&client->dev, "i2c wr reg=%04x: len=%d is too big!\n",
-				reg, len);
-		return -EINVAL;
-	}
-
-	ret = i2c_transfer(client->adapter, msg, 2);
-	if (ret == 2) {
-		memcpy(val, buf, len);
-		ret = 0;
-	} else {
-		dev_warn(&client->dev, "i2c rd failed=%d reg=%02x len=%d\n",
-				ret, reg, len);
-		ret = -EREMOTEIO;
-	}
-	return ret;
-}
-
-/* write single register */
-static int tda10071_wr_reg(struct tda10071_dev *dev, u8 reg, u8 val)
-{
-	return tda10071_wr_regs(dev, reg, &val, 1);
-}
-
-/* read single register */
-static int tda10071_rd_reg(struct tda10071_dev *dev, u8 reg, u8 *val)
-{
-	return tda10071_rd_regs(dev, reg, val, 1);
-}
-
+/*
+ * XXX: regmap_update_bits() does not fit our needs as it does not support
+ * partially volatile registers. Also it performs register read even mask is as
+ * wide as register value.
+ */
 /* write single register with mask */
 static int tda10071_wr_reg_mask(struct tda10071_dev *dev,
 				u8 reg, u8 val, u8 mask)
@@ -121,7 +36,7 @@ static int tda10071_wr_reg_mask(struct tda10071_dev *dev,
 
 	/* no need for read if whole reg is written */
 	if (mask != 0xff) {
-		ret = tda10071_rd_regs(dev, reg, &tmp, 1);
+		ret = regmap_bulk_read(dev->regmap, reg, &tmp, 1);
 		if (ret)
 			return ret;
 
@@ -130,30 +45,7 @@ static int tda10071_wr_reg_mask(struct tda10071_dev *dev,
 		val |= tmp;
 	}
 
-	return tda10071_wr_regs(dev, reg, &val, 1);
-}
-
-/* read single register with mask */
-static int tda10071_rd_reg_mask(struct tda10071_dev *dev,
-				u8 reg, u8 *val, u8 mask)
-{
-	int ret, i;
-	u8 tmp;
-
-	ret = tda10071_rd_regs(dev, reg, &tmp, 1);
-	if (ret)
-		return ret;
-
-	tmp &= mask;
-
-	/* find position of the first bit */
-	for (i = 0; i < 8; i++) {
-		if ((mask >> i) & 0x01)
-			break;
-	}
-	*val = tmp >> i;
-
-	return 0;
+	return regmap_bulk_write(dev->regmap, reg, &val, 1);
 }
 
 /* execute firmware command */
@@ -162,7 +54,7 @@ static int tda10071_cmd_execute(struct tda10071_dev *dev,
 {
 	struct i2c_client *client = dev->client;
 	int ret, i;
-	u8 tmp;
+	unsigned int uitmp;
 
 	if (!dev->warm) {
 		ret = -EFAULT;
@@ -170,18 +62,18 @@ static int tda10071_cmd_execute(struct tda10071_dev *dev,
 	}
 
 	/* write cmd and args for firmware */
-	ret = tda10071_wr_regs(dev, 0x00, cmd->args, cmd->len);
+	ret = regmap_bulk_write(dev->regmap, 0x00, cmd->args, cmd->len);
 	if (ret)
 		goto error;
 
 	/* start cmd execution */
-	ret = tda10071_wr_reg(dev, 0x1f, 1);
+	ret = regmap_write(dev->regmap, 0x1f, 1);
 	if (ret)
 		goto error;
 
 	/* wait cmd execution terminate */
-	for (i = 1000, tmp = 1; i && tmp; i--) {
-		ret = tda10071_rd_reg(dev, 0x1f, &tmp);
+	for (i = 1000, uitmp = 1; i && uitmp; i--) {
+		ret = regmap_read(dev->regmap, 0x1f, &uitmp);
 		if (ret)
 			goto error;
 
@@ -299,7 +191,7 @@ static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe,
 	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret, i;
-	u8 tmp;
+	unsigned int uitmp;
 
 	if (!dev->warm) {
 		ret = -EFAULT;
@@ -314,11 +206,11 @@ static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe,
 	}
 
 	/* wait LNB TX */
-	for (i = 500, tmp = 0; i && !tmp; i--) {
-		ret = tda10071_rd_reg_mask(dev, 0x47, &tmp, 0x01);
+	for (i = 500, uitmp = 0; i && !uitmp; i--) {
+		ret = regmap_read(dev->regmap, 0x47, &uitmp);
 		if (ret)
 			goto error;
-
+		uitmp = (uitmp >> 0) & 1;
 		usleep_range(10000, 20000);
 	}
 
@@ -329,7 +221,7 @@ static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe,
 		goto error;
 	}
 
-	ret = tda10071_wr_reg_mask(dev, 0x47, 0x00, 0x01);
+	ret = regmap_update_bits(dev->regmap, 0x47, 0x01, 0x00);
 	if (ret)
 		goto error;
 
@@ -359,7 +251,7 @@ static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe,
 	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret, i;
-	u8 tmp;
+	unsigned int uitmp;
 
 	if (!dev->warm) {
 		ret = -EFAULT;
@@ -369,11 +261,11 @@ static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe,
 	dev_dbg(&client->dev, "\n");
 
 	/* wait LNB RX */
-	for (i = 500, tmp = 0; i && !tmp; i--) {
-		ret = tda10071_rd_reg_mask(dev, 0x47, &tmp, 0x02);
+	for (i = 500, uitmp = 0; i && !uitmp; i--) {
+		ret = regmap_read(dev->regmap, 0x47, &uitmp);
 		if (ret)
 			goto error;
-
+		uitmp = (uitmp >> 1) & 1;
 		usleep_range(10000, 20000);
 	}
 
@@ -385,11 +277,11 @@ static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe,
 	}
 
 	/* reply len */
-	ret = tda10071_rd_reg(dev, 0x46, &tmp);
+	ret = regmap_read(dev->regmap, 0x46, &uitmp);
 	if (ret)
 		goto error;
 
-	reply->msg_len = tmp & 0x1f; /* [4:0] */
+	reply->msg_len = uitmp & 0x1f; /* [4:0] */
 	if (reply->msg_len > sizeof(reply->msg))
 		reply->msg_len = sizeof(reply->msg); /* truncate API max */
 
@@ -401,7 +293,8 @@ static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe,
 	if (ret)
 		goto error;
 
-	ret = tda10071_rd_regs(dev, cmd.len, reply->msg, reply->msg_len);
+	ret = regmap_bulk_read(dev->regmap, cmd.len, reply->msg,
+			       reply->msg_len);
 	if (ret)
 		goto error;
 
@@ -418,7 +311,8 @@ static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
 	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret, i;
-	u8 tmp, burst;
+	unsigned int uitmp;
+	u8 burst;
 
 	if (!dev->warm) {
 		ret = -EFAULT;
@@ -441,11 +335,11 @@ static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
 	}
 
 	/* wait LNB TX */
-	for (i = 500, tmp = 0; i && !tmp; i--) {
-		ret = tda10071_rd_reg_mask(dev, 0x47, &tmp, 0x01);
+	for (i = 500, uitmp = 0; i && !uitmp; i--) {
+		ret = regmap_read(dev->regmap, 0x47, &uitmp);
 		if (ret)
 			goto error;
-
+		uitmp = (uitmp >> 0) & 1;
 		usleep_range(10000, 20000);
 	}
 
@@ -456,7 +350,7 @@ static int tda10071_diseqc_send_burst(struct dvb_frontend *fe,
 		goto error;
 	}
 
-	ret = tda10071_wr_reg_mask(dev, 0x47, 0x00, 0x01);
+	ret = regmap_update_bits(dev->regmap, 0x47, 0x01, 0x00);
 	if (ret)
 		goto error;
 
@@ -479,7 +373,7 @@ static int tda10071_read_status(struct dvb_frontend *fe, enum fe_status *status)
 	struct tda10071_dev *dev = fe->demodulator_priv;
 	struct i2c_client *client = dev->client;
 	int ret;
-	u8 tmp;
+	unsigned int uitmp;
 
 	*status = 0;
 
@@ -488,16 +382,16 @@ static int tda10071_read_status(struct dvb_frontend *fe, enum fe_status *status)
 		goto error;
 	}
 
-	ret = tda10071_rd_reg(dev, 0x39, &tmp);
+	ret = regmap_read(dev->regmap, 0x39, &uitmp);
 	if (ret)
 		goto error;
 
 	/* 0x39[0] tuner PLL */
-	if (tmp & 0x02) /* demod PLL */
+	if (uitmp & 0x02) /* demod PLL */
 		*status |= FE_HAS_SIGNAL | FE_HAS_CARRIER;
-	if (tmp & 0x04) /* viterbi or LDPC*/
+	if (uitmp & 0x04) /* viterbi or LDPC*/
 		*status |= FE_HAS_VITERBI;
-	if (tmp & 0x08) /* RS or BCH */
+	if (uitmp & 0x08) /* RS or BCH */
 		*status |= FE_HAS_SYNC | FE_HAS_LOCK;
 
 	dev->fe_status = *status;
@@ -521,7 +415,7 @@ static int tda10071_read_snr(struct dvb_frontend *fe, u16 *snr)
 		goto error;
 	}
 
-	ret = tda10071_rd_regs(dev, 0x3a, buf, 2);
+	ret = regmap_bulk_read(dev->regmap, 0x3a, buf, 2);
 	if (ret)
 		goto error;
 
@@ -540,7 +434,7 @@ static int tda10071_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
 	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret;
-	u8 tmp;
+	unsigned int uitmp;
 
 	if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
 		*strength = 0;
@@ -556,17 +450,17 @@ static int tda10071_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
 		goto error;
 
 	/* input power estimate dBm */
-	ret = tda10071_rd_reg(dev, 0x50, &tmp);
+	ret = regmap_read(dev->regmap, 0x50, &uitmp);
 	if (ret)
 		goto error;
 
-	if (tmp < 181)
-		tmp = 181; /* -75 dBm */
-	else if (tmp > 236)
-		tmp = 236; /* -20 dBm */
+	if (uitmp < 181)
+		uitmp = 181; /* -75 dBm */
+	else if (uitmp > 236)
+		uitmp = 236; /* -20 dBm */
 
 	/* scale value to 0x0000-0xffff */
-	*strength = (tmp-181) * 0xffff / (236-181);
+	*strength = (uitmp-181) * 0xffff / (236-181);
 
 	return ret;
 error:
@@ -580,7 +474,8 @@ static int tda10071_read_ber(struct dvb_frontend *fe, u32 *ber)
 	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret, i, len;
-	u8 tmp, reg, buf[8];
+	unsigned int uitmp;
+	u8 reg, buf[8];
 
 	if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
 		*ber = dev->ber = 0;
@@ -604,16 +499,16 @@ static int tda10071_read_ber(struct dvb_frontend *fe, u32 *ber)
 		return 0;
 	}
 
-	ret = tda10071_rd_reg(dev, reg, &tmp);
+	ret = regmap_read(dev->regmap, reg, &uitmp);
 	if (ret)
 		goto error;
 
-	if (dev->meas_count[i] == tmp) {
-		dev_dbg(&client->dev, "meas not ready=%02x\n", tmp);
+	if (dev->meas_count[i] == uitmp) {
+		dev_dbg(&client->dev, "meas not ready=%02x\n", uitmp);
 		*ber = dev->ber;
 		return 0;
 	} else {
-		dev->meas_count[i] = tmp;
+		dev->meas_count[i] = uitmp;
 	}
 
 	cmd.args[0] = CMD_BER_UPDATE_COUNTERS;
@@ -624,7 +519,7 @@ static int tda10071_read_ber(struct dvb_frontend *fe, u32 *ber)
 	if (ret)
 		goto error;
 
-	ret = tda10071_rd_regs(dev, cmd.len, buf, len);
+	ret = regmap_bulk_read(dev->regmap, cmd.len, buf, len);
 	if (ret)
 		goto error;
 
@@ -772,11 +667,11 @@ static int tda10071_set_frontend(struct dvb_frontend *fe)
 	else
 		div = 4;
 
-	ret = tda10071_wr_reg(dev, 0x81, div);
+	ret = regmap_write(dev->regmap, 0x81, div);
 	if (ret)
 		goto error;
 
-	ret = tda10071_wr_reg(dev, 0xe3, div);
+	ret = regmap_write(dev->regmap, 0xe3, div);
 	if (ret)
 		goto error;
 
@@ -821,7 +716,7 @@ static int tda10071_get_frontend(struct dvb_frontend *fe)
 		goto error;
 	}
 
-	ret = tda10071_rd_regs(dev, 0x30, buf, 5);
+	ret = regmap_bulk_read(dev->regmap, 0x30, buf, 5);
 	if (ret)
 		goto error;
 
@@ -854,7 +749,7 @@ static int tda10071_get_frontend(struct dvb_frontend *fe)
 
 	c->frequency = (buf[2] << 16) | (buf[3] << 8) | (buf[4] << 0);
 
-	ret = tda10071_rd_regs(dev, 0x52, buf, 3);
+	ret = regmap_bulk_read(dev->regmap, 0x52, buf, 3);
 	if (ret)
 		goto error;
 
@@ -872,6 +767,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 	struct i2c_client *client = dev->client;
 	struct tda10071_cmd cmd;
 	int ret, i, len, remaining, fw_size;
+	unsigned int uitmp;
 	const struct firmware *fw;
 	u8 *fw_file = TDA10071_FIRMWARE;
 	u8 tmp, buf[4];
@@ -971,19 +867,19 @@ static int tda10071_init(struct dvb_frontend *fe)
 		}
 
 		/*  download firmware */
-		ret = tda10071_wr_reg(dev, 0xe0, 0x7f);
+		ret = regmap_write(dev->regmap, 0xe0, 0x7f);
 		if (ret)
 			goto error_release_firmware;
 
-		ret = tda10071_wr_reg(dev, 0xf7, 0x81);
+		ret = regmap_write(dev->regmap, 0xf7, 0x81);
 		if (ret)
 			goto error_release_firmware;
 
-		ret = tda10071_wr_reg(dev, 0xf8, 0x00);
+		ret = regmap_write(dev->regmap, 0xf8, 0x00);
 		if (ret)
 			goto error_release_firmware;
 
-		ret = tda10071_wr_reg(dev, 0xf9, 0x00);
+		ret = regmap_write(dev->regmap, 0xf9, 0x00);
 		if (ret)
 			goto error_release_firmware;
 
@@ -1002,7 +898,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 			if (len > (dev->i2c_wr_max - 1))
 				len = (dev->i2c_wr_max - 1);
 
-			ret = tda10071_wr_regs(dev, 0xfa,
+			ret = regmap_bulk_write(dev->regmap, 0xfa,
 				(u8 *) &fw->data[fw_size - remaining], len);
 			if (ret) {
 				dev_err(&client->dev,
@@ -1012,11 +908,11 @@ static int tda10071_init(struct dvb_frontend *fe)
 		}
 		release_firmware(fw);
 
-		ret = tda10071_wr_reg(dev, 0xf7, 0x0c);
+		ret = regmap_write(dev->regmap, 0xf7, 0x0c);
 		if (ret)
 			goto error;
 
-		ret = tda10071_wr_reg(dev, 0xe0, 0x00);
+		ret = regmap_write(dev->regmap, 0xe0, 0x00);
 		if (ret)
 			goto error;
 
@@ -1024,11 +920,11 @@ static int tda10071_init(struct dvb_frontend *fe)
 		msleep(250);
 
 		/* firmware status */
-		ret = tda10071_rd_reg(dev, 0x51, &tmp);
+		ret = regmap_read(dev->regmap, 0x51, &uitmp);
 		if (ret)
 			goto error;
 
-		if (tmp) {
+		if (uitmp) {
 			dev_info(&client->dev, "firmware did not run\n");
 			ret = -EFAULT;
 			goto error;
@@ -1042,7 +938,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 		if (ret)
 			goto error;
 
-		ret = tda10071_rd_regs(dev, cmd.len, buf, 4);
+		ret = regmap_bulk_read(dev->regmap, cmd.len, buf, 4);
 		if (ret)
 			goto error;
 
@@ -1051,7 +947,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 		dev_info(&client->dev, "found a '%s' in warm state\n",
 			 tda10071_ops.info.name);
 
-		ret = tda10071_rd_regs(dev, 0x81, buf, 2);
+		ret = regmap_bulk_read(dev->regmap, 0x81, buf, 2);
 		if (ret)
 			goto error;
 
@@ -1104,7 +1000,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 		if (ret)
 			goto error;
 
-		ret = tda10071_wr_reg_mask(dev, 0xf0, 0x01, 0x01);
+		ret = regmap_update_bits(dev->regmap, 0xf0, 0x01, 0x01);
 		if (ret)
 			goto error;
 
@@ -1258,7 +1154,11 @@ static int tda10071_probe(struct i2c_client *client,
 	struct tda10071_dev *dev;
 	struct tda10071_platform_data *pdata = client->dev.platform_data;
 	int ret;
-	u8 u8tmp;
+	unsigned int uitmp;
+	static const struct regmap_config regmap_config = {
+		.reg_bits = 8,
+		.val_bits = 8,
+	};
 
 	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
 	if (!dev) {
@@ -1273,30 +1173,35 @@ static int tda10071_probe(struct i2c_client *client,
 	dev->spec_inv = pdata->spec_inv;
 	dev->pll_multiplier = pdata->pll_multiplier;
 	dev->tuner_i2c_addr = pdata->tuner_i2c_addr;
+	dev->regmap = devm_regmap_init_i2c(client, &regmap_config);
+	if (IS_ERR(dev->regmap)) {
+		ret = PTR_ERR(dev->regmap);
+		goto err_kfree;
+	}
 
 	/* chip ID */
-	ret = tda10071_rd_reg(dev, 0xff, &u8tmp);
+	ret = regmap_read(dev->regmap, 0xff, &uitmp);
 	if (ret)
 		goto err_kfree;
-	if (u8tmp != 0x0f) {
+	if (uitmp != 0x0f) {
 		ret = -ENODEV;
 		goto err_kfree;
 	}
 
 	/* chip type */
-	ret = tda10071_rd_reg(dev, 0xdd, &u8tmp);
+	ret = regmap_read(dev->regmap, 0xdd, &uitmp);
 	if (ret)
 		goto err_kfree;
-	if (u8tmp != 0x00) {
+	if (uitmp != 0x00) {
 		ret = -ENODEV;
 		goto err_kfree;
 	}
 
 	/* chip version */
-	ret = tda10071_rd_reg(dev, 0xfe, &u8tmp);
+	ret = regmap_read(dev->regmap, 0xfe, &uitmp);
 	if (ret)
 		goto err_kfree;
-	if (u8tmp != 0x01) {
+	if (uitmp != 0x01) {
 		ret = -ENODEV;
 		goto err_kfree;
 	}
diff --git a/drivers/media/dvb-frontends/tda10071_priv.h b/drivers/media/dvb-frontends/tda10071_priv.h
index 9800028..30143c8 100644
--- a/drivers/media/dvb-frontends/tda10071_priv.h
+++ b/drivers/media/dvb-frontends/tda10071_priv.h
@@ -24,10 +24,12 @@
 #include "dvb_frontend.h"
 #include "tda10071.h"
 #include <linux/firmware.h>
+#include <linux/regmap.h>
 
 struct tda10071_dev {
 	struct dvb_frontend fe;
 	struct i2c_client *client;
+	struct regmap *regmap;
 	u32 clk;
 	u16 i2c_wr_max;
 	u8 ts_mode;
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 09/12] tda10071: use jiffies when poll firmware status
  2015-07-09  4:06 [PATCH 01/12] em28xx: remove unused a8293 SEC config Antti Palosaari
                   ` (6 preceding siblings ...)
  2015-07-09  4:06 ` [PATCH 08/12] tda10071: convert to regmap I2C API Antti Palosaari
@ 2015-07-09  4:06 ` Antti Palosaari
  2015-08-11 10:20   ` Mauro Carvalho Chehab
  2015-07-09  4:06 ` [PATCH 10/12] tda10071: protect firmware command exec with mutex Antti Palosaari
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 15+ messages in thread
From: Antti Palosaari @ 2015-07-09  4:06 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Use jiffies to set timeout for firmware command status polling.
It is more elegant solution than poll X times with sleep.

Shorten timeout to 30ms as all commands seems to be executed under
10ms.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/dvb-frontends/tda10071.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c
index 6226b57..c1507cc 100644
--- a/drivers/media/dvb-frontends/tda10071.c
+++ b/drivers/media/dvb-frontends/tda10071.c
@@ -53,8 +53,9 @@ static int tda10071_cmd_execute(struct tda10071_dev *dev,
 	struct tda10071_cmd *cmd)
 {
 	struct i2c_client *client = dev->client;
-	int ret, i;
+	int ret;
 	unsigned int uitmp;
+	unsigned long timeout;
 
 	if (!dev->warm) {
 		ret = -EFAULT;
@@ -72,17 +73,19 @@ static int tda10071_cmd_execute(struct tda10071_dev *dev,
 		goto error;
 
 	/* wait cmd execution terminate */
-	for (i = 1000, uitmp = 1; i && uitmp; i--) {
+	#define CMD_EXECUTE_TIMEOUT 30
+	timeout = jiffies + msecs_to_jiffies(CMD_EXECUTE_TIMEOUT);
+	for (uitmp = 1; !time_after(jiffies, timeout) && uitmp;) {
 		ret = regmap_read(dev->regmap, 0x1f, &uitmp);
 		if (ret)
 			goto error;
-
-		usleep_range(200, 5000);
 	}
 
-	dev_dbg(&client->dev, "loop=%d\n", i);
+	dev_dbg(&client->dev, "cmd execution took %u ms\n",
+		jiffies_to_msecs(jiffies) -
+		(jiffies_to_msecs(timeout) - CMD_EXECUTE_TIMEOUT));
 
-	if (i == 0) {
+	if (uitmp) {
 		ret = -ETIMEDOUT;
 		goto error;
 	}
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 10/12] tda10071: protect firmware command exec with mutex
  2015-07-09  4:06 [PATCH 01/12] em28xx: remove unused a8293 SEC config Antti Palosaari
                   ` (7 preceding siblings ...)
  2015-07-09  4:06 ` [PATCH 09/12] tda10071: use jiffies when poll firmware status Antti Palosaari
@ 2015-07-09  4:06 ` Antti Palosaari
  2015-07-09  4:06 ` [PATCH 11/12] tda10071: do not get_frontend() when not ready Antti Palosaari
  2015-07-09  4:06 ` [PATCH 12/12] tda10071: implement DVBv5 statistics Antti Palosaari
  10 siblings, 0 replies; 15+ messages in thread
From: Antti Palosaari @ 2015-07-09  4:06 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

There should be clearly some lock in order to make sure firmware
command in execution is not disturbed by another command. It has
worked as callbacks are serialized somehow pretty well and command
execution happens usually without any delays.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/dvb-frontends/tda10071.c      | 12 +++++++++---
 drivers/media/dvb-frontends/tda10071_priv.h |  1 +
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c
index c1507cc..c8feb58 100644
--- a/drivers/media/dvb-frontends/tda10071.c
+++ b/drivers/media/dvb-frontends/tda10071.c
@@ -62,15 +62,17 @@ static int tda10071_cmd_execute(struct tda10071_dev *dev,
 		goto error;
 	}
 
+	mutex_lock(&dev->cmd_execute_mutex);
+
 	/* write cmd and args for firmware */
 	ret = regmap_bulk_write(dev->regmap, 0x00, cmd->args, cmd->len);
 	if (ret)
-		goto error;
+		goto error_mutex_unlock;
 
 	/* start cmd execution */
 	ret = regmap_write(dev->regmap, 0x1f, 1);
 	if (ret)
-		goto error;
+		goto error_mutex_unlock;
 
 	/* wait cmd execution terminate */
 	#define CMD_EXECUTE_TIMEOUT 30
@@ -78,8 +80,9 @@ static int tda10071_cmd_execute(struct tda10071_dev *dev,
 	for (uitmp = 1; !time_after(jiffies, timeout) && uitmp;) {
 		ret = regmap_read(dev->regmap, 0x1f, &uitmp);
 		if (ret)
-			goto error;
+			goto error_mutex_unlock;
 	}
+	mutex_unlock(&dev->cmd_execute_mutex);
 
 	dev_dbg(&client->dev, "cmd execution took %u ms\n",
 		jiffies_to_msecs(jiffies) -
@@ -91,6 +94,8 @@ static int tda10071_cmd_execute(struct tda10071_dev *dev,
 	}
 
 	return ret;
+error_mutex_unlock:
+	mutex_unlock(&dev->cmd_execute_mutex);
 error:
 	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
@@ -1170,6 +1175,7 @@ static int tda10071_probe(struct i2c_client *client,
 	}
 
 	dev->client = client;
+	mutex_init(&dev->cmd_execute_mutex);
 	dev->clk = pdata->clk;
 	dev->i2c_wr_max = pdata->i2c_wr_max;
 	dev->ts_mode = pdata->ts_mode;
diff --git a/drivers/media/dvb-frontends/tda10071_priv.h b/drivers/media/dvb-frontends/tda10071_priv.h
index 30143c8..cf5b433 100644
--- a/drivers/media/dvb-frontends/tda10071_priv.h
+++ b/drivers/media/dvb-frontends/tda10071_priv.h
@@ -30,6 +30,7 @@ struct tda10071_dev {
 	struct dvb_frontend fe;
 	struct i2c_client *client;
 	struct regmap *regmap;
+	struct mutex cmd_execute_mutex;
 	u32 clk;
 	u16 i2c_wr_max;
 	u8 ts_mode;
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 11/12] tda10071: do not get_frontend() when not ready
  2015-07-09  4:06 [PATCH 01/12] em28xx: remove unused a8293 SEC config Antti Palosaari
                   ` (8 preceding siblings ...)
  2015-07-09  4:06 ` [PATCH 10/12] tda10071: protect firmware command exec with mutex Antti Palosaari
@ 2015-07-09  4:06 ` Antti Palosaari
  2015-07-09  4:06 ` [PATCH 12/12] tda10071: implement DVBv5 statistics Antti Palosaari
  10 siblings, 0 replies; 15+ messages in thread
From: Antti Palosaari @ 2015-07-09  4:06 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

This is a bit hack, but returning error when driver is not tuned yet
causes DVBv5 zap stop polling DVBv5 statistics. Thus return 0 even
callback is called during invalid device state.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/dvb-frontends/tda10071.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c
index c8feb58..c661b74 100644
--- a/drivers/media/dvb-frontends/tda10071.c
+++ b/drivers/media/dvb-frontends/tda10071.c
@@ -720,7 +720,7 @@ static int tda10071_get_frontend(struct dvb_frontend *fe)
 	u8 buf[5], tmp;
 
 	if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
-		ret = -EFAULT;
+		ret = 0;
 		goto error;
 	}
 
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 12/12] tda10071: implement DVBv5 statistics
  2015-07-09  4:06 [PATCH 01/12] em28xx: remove unused a8293 SEC config Antti Palosaari
                   ` (9 preceding siblings ...)
  2015-07-09  4:06 ` [PATCH 11/12] tda10071: do not get_frontend() when not ready Antti Palosaari
@ 2015-07-09  4:06 ` Antti Palosaari
  10 siblings, 0 replies; 15+ messages in thread
From: Antti Palosaari @ 2015-07-09  4:06 UTC (permalink / raw)
  To: linux-media; +Cc: Antti Palosaari

Implement DVBv5 CNR, signal strength, BER and block errors.

Wrap legacy DVBv3 statistics to DVBv5 internally.

Signed-off-by: Antti Palosaari <crope@iki.fi>
---
 drivers/media/dvb-frontends/tda10071.c      | 258 ++++++++++++++--------------
 drivers/media/dvb-frontends/tda10071_priv.h |   7 +-
 2 files changed, 135 insertions(+), 130 deletions(-)

diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c
index c661b74..9f930cf 100644
--- a/drivers/media/dvb-frontends/tda10071.c
+++ b/drivers/media/dvb-frontends/tda10071.c
@@ -380,8 +380,11 @@ static int tda10071_read_status(struct dvb_frontend *fe, enum fe_status *status)
 {
 	struct tda10071_dev *dev = fe->demodulator_priv;
 	struct i2c_client *client = dev->client;
+	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+	struct tda10071_cmd cmd;
 	int ret;
 	unsigned int uitmp;
+	u8 buf[8];
 
 	*status = 0;
 
@@ -404,71 +407,105 @@ static int tda10071_read_status(struct dvb_frontend *fe, enum fe_status *status)
 
 	dev->fe_status = *status;
 
-	return ret;
-error:
-	dev_dbg(&client->dev, "failed=%d\n", ret);
-	return ret;
-}
+	/* signal strength */
+	if (dev->fe_status & FE_HAS_SIGNAL) {
+		cmd.args[0] = CMD_GET_AGCACC;
+		cmd.args[1] = 0;
+		cmd.len = 2;
+		ret = tda10071_cmd_execute(dev, &cmd);
+		if (ret)
+			goto error;
 
-static int tda10071_read_snr(struct dvb_frontend *fe, u16 *snr)
-{
-	struct tda10071_dev *dev = fe->demodulator_priv;
-	struct i2c_client *client = dev->client;
-	int ret;
-	u8 buf[2];
+		/* input power estimate dBm */
+		ret = regmap_read(dev->regmap, 0x50, &uitmp);
+		if (ret)
+			goto error;
 
-	if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
-		*snr = 0;
-		ret = 0;
-		goto error;
+		c->strength.stat[0].scale = FE_SCALE_DECIBEL;
+		c->strength.stat[0].svalue = (int) (uitmp - 256) * 1000;
+	} else {
+		c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
 	}
 
-	ret = regmap_bulk_read(dev->regmap, 0x3a, buf, 2);
-	if (ret)
-		goto error;
+	/* CNR */
+	if (dev->fe_status & FE_HAS_VITERBI) {
+		/* Es/No */
+		ret = regmap_bulk_read(dev->regmap, 0x3a, buf, 2);
+		if (ret)
+			goto error;
 
-	/* Es/No dBx10 */
-	*snr = buf[0] << 8 | buf[1];
+		c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
+		c->cnr.stat[0].svalue = (buf[0] << 8 | buf[1] << 0) * 100;
+	} else {
+		c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	}
 
-	return ret;
-error:
-	dev_dbg(&client->dev, "failed=%d\n", ret);
-	return ret;
-}
+	/* UCB/PER/BER */
+	if (dev->fe_status & FE_HAS_LOCK) {
+		/* TODO: report total bits/packets */
+		u8 delivery_system, reg, len;
 
-static int tda10071_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
-{
-	struct tda10071_dev *dev = fe->demodulator_priv;
-	struct i2c_client *client = dev->client;
-	struct tda10071_cmd cmd;
-	int ret;
-	unsigned int uitmp;
+		switch (dev->delivery_system) {
+		case SYS_DVBS:
+			reg = 0x4c;
+			len = 8;
+			delivery_system = 1;
+			break;
+		case SYS_DVBS2:
+			reg = 0x4d;
+			len = 4;
+			delivery_system = 0;
+			break;
+		default:
+			ret = -EINVAL;
+			goto error;
+		}
 
-	if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
-		*strength = 0;
-		ret = 0;
-		goto error;
-	}
+		ret = regmap_read(dev->regmap, reg, &uitmp);
+		if (ret)
+			goto error;
 
-	cmd.args[0] = CMD_GET_AGCACC;
-	cmd.args[1] = 0;
-	cmd.len = 2;
-	ret = tda10071_cmd_execute(dev, &cmd);
-	if (ret)
-		goto error;
+		if (dev->meas_count == uitmp) {
+			dev_dbg(&client->dev, "meas not ready=%02x\n", uitmp);
+			ret = 0;
+			goto error;
+		} else {
+			dev->meas_count = uitmp;
+		}
 
-	/* input power estimate dBm */
-	ret = regmap_read(dev->regmap, 0x50, &uitmp);
-	if (ret)
-		goto error;
+		cmd.args[0] = CMD_BER_UPDATE_COUNTERS;
+		cmd.args[1] = 0;
+		cmd.args[2] = delivery_system;
+		cmd.len = 3;
+		ret = tda10071_cmd_execute(dev, &cmd);
+		if (ret)
+			goto error;
 
-	if (uitmp < 181)
-		uitmp = 181; /* -75 dBm */
-	else if (uitmp > 236)
-		uitmp = 236; /* -20 dBm */
+		ret = regmap_bulk_read(dev->regmap, cmd.len, buf, len);
+		if (ret)
+			goto error;
 
-	/* scale value to 0x0000-0xffff */
-	*strength = (uitmp-181) * 0xffff / (236-181);
+		if (dev->delivery_system == SYS_DVBS) {
+			dev->dvbv3_ber = buf[0] << 24 | buf[1] << 16 |
+					 buf[2] << 8 | buf[3] << 0;
+			dev->post_bit_error += buf[0] << 24 | buf[1] << 16 |
+					       buf[2] << 8 | buf[3] << 0;
+			c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
+			c->post_bit_error.stat[0].uvalue = dev->post_bit_error;
+			dev->block_error += buf[4] << 8 | buf[5] << 0;
+			c->block_error.stat[0].scale = FE_SCALE_COUNTER;
+			c->block_error.stat[0].uvalue = dev->block_error;
+		} else {
+			dev->dvbv3_ber = buf[0] << 8 | buf[1] << 0;
+			dev->post_bit_error += buf[0] << 8 | buf[1] << 0;
+			c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
+			c->post_bit_error.stat[0].uvalue = dev->post_bit_error;
+			c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		}
+	} else {
+		c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+		c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	}
 
 	return ret;
 error:
@@ -476,94 +513,50 @@ error:
 	return ret;
 }
 
-static int tda10071_read_ber(struct dvb_frontend *fe, u32 *ber)
+static int tda10071_read_snr(struct dvb_frontend *fe, u16 *snr)
 {
-	struct tda10071_dev *dev = fe->demodulator_priv;
-	struct i2c_client *client = dev->client;
-	struct tda10071_cmd cmd;
-	int ret, i, len;
-	unsigned int uitmp;
-	u8 reg, buf[8];
-
-	if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
-		*ber = dev->ber = 0;
-		ret = 0;
-		goto error;
-	}
+	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 
-	switch (dev->delivery_system) {
-	case SYS_DVBS:
-		reg = 0x4c;
-		len = 8;
-		i = 1;
-		break;
-	case SYS_DVBS2:
-		reg = 0x4d;
-		len = 4;
-		i = 0;
-		break;
-	default:
-		*ber = dev->ber = 0;
-		return 0;
-	}
+	if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL)
+		*snr = div_s64(c->cnr.stat[0].svalue, 100);
+	else
+		*snr = 0;
+	return 0;
+}
 
-	ret = regmap_read(dev->regmap, reg, &uitmp);
-	if (ret)
-		goto error;
+static int tda10071_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
+{
+	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+	unsigned int uitmp;
 
-	if (dev->meas_count[i] == uitmp) {
-		dev_dbg(&client->dev, "meas not ready=%02x\n", uitmp);
-		*ber = dev->ber;
-		return 0;
+	if (c->strength.stat[0].scale == FE_SCALE_DECIBEL) {
+		uitmp = c->strength.stat[0].svalue / 1000 + 256;
+		uitmp = clamp(uitmp, 181U, 236U); /* -75dBm - -20dBm */
+		/* scale value to 0x0000-0xffff */
+		*strength = (uitmp-181) * 0xffff / (236-181);
 	} else {
-		dev->meas_count[i] = uitmp;
+		*strength = 0;
 	}
+	return 0;
+}
 
-	cmd.args[0] = CMD_BER_UPDATE_COUNTERS;
-	cmd.args[1] = 0;
-	cmd.args[2] = i;
-	cmd.len = 3;
-	ret = tda10071_cmd_execute(dev, &cmd);
-	if (ret)
-		goto error;
-
-	ret = regmap_bulk_read(dev->regmap, cmd.len, buf, len);
-	if (ret)
-		goto error;
-
-	if (dev->delivery_system == SYS_DVBS) {
-		*ber = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
-		dev->ucb += (buf[4] << 8) | buf[5];
-	} else {
-		*ber = (buf[0] << 8) | buf[1];
-	}
-	dev->ber = *ber;
+static int tda10071_read_ber(struct dvb_frontend *fe, u32 *ber)
+{
+	struct tda10071_dev *dev = fe->demodulator_priv;
 
-	return ret;
-error:
-	dev_dbg(&client->dev, "failed=%d\n", ret);
-	return ret;
+	*ber = dev->dvbv3_ber;
+	return 0;
 }
 
 static int tda10071_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
 {
-	struct tda10071_dev *dev = fe->demodulator_priv;
-	struct i2c_client *client = dev->client;
-	int ret = 0;
+	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 
-	if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
+	if (c->block_error.stat[0].scale == FE_SCALE_COUNTER)
+		*ucblocks = c->block_error.stat[0].uvalue;
+	else
 		*ucblocks = 0;
-		goto error;
-	}
-
-	/* UCB is updated when BER is read. Assume BER is read anyway. */
-
-	*ucblocks = dev->ucb;
-
-	return ret;
-error:
-	dev_dbg(&client->dev, "failed=%d\n", ret);
-	return ret;
+	return 0;
 }
 
 static int tda10071_set_frontend(struct dvb_frontend *fe)
@@ -773,6 +766,7 @@ static int tda10071_init(struct dvb_frontend *fe)
 {
 	struct tda10071_dev *dev = fe->demodulator_priv;
 	struct i2c_client *client = dev->client;
+	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 	struct tda10071_cmd cmd;
 	int ret, i, len, remaining, fw_size;
 	unsigned int uitmp;
@@ -1038,6 +1032,16 @@ static int tda10071_init(struct dvb_frontend *fe)
 			goto error;
 	}
 
+	/* init stats here in order signal app which stats are supported */
+	c->strength.len = 1;
+	c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	c->cnr.len = 1;
+	c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	c->post_bit_error.len = 1;
+	c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+	c->block_error.len = 1;
+	c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+
 	return ret;
 error_release_firmware:
 	release_firmware(fw);
diff --git a/drivers/media/dvb-frontends/tda10071_priv.h b/drivers/media/dvb-frontends/tda10071_priv.h
index cf5b433..b9c3601 100644
--- a/drivers/media/dvb-frontends/tda10071_priv.h
+++ b/drivers/media/dvb-frontends/tda10071_priv.h
@@ -38,12 +38,13 @@ struct tda10071_dev {
 	u8 pll_multiplier;
 	u8 tuner_i2c_addr;
 
-	u8 meas_count[2];
-	u32 ber;
-	u32 ucb;
+	u8 meas_count;
+	u32 dvbv3_ber;
 	enum fe_status fe_status;
 	enum fe_delivery_system delivery_system;
 	bool warm; /* FW running */
+	u64 post_bit_error;
+	u64 block_error;
 };
 
 static struct tda10071_modcod {
-- 
http://palosaari.fi/


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH 09/12] tda10071: use jiffies when poll firmware status
  2015-07-09  4:06 ` [PATCH 09/12] tda10071: use jiffies when poll firmware status Antti Palosaari
@ 2015-08-11 10:20   ` Mauro Carvalho Chehab
  2015-08-11 15:18     ` Antti Palosaari
  0 siblings, 1 reply; 15+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-11 10:20 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: linux-media

Em Thu,  9 Jul 2015 07:06:29 +0300
Antti Palosaari <crope@iki.fi> escreveu:

> Use jiffies to set timeout for firmware command status polling.
> It is more elegant solution than poll X times with sleep.
> 
> Shorten timeout to 30ms as all commands seems to be executed under
> 10ms.
> 
> Signed-off-by: Antti Palosaari <crope@iki.fi>
> ---
>  drivers/media/dvb-frontends/tda10071.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c
> index 6226b57..c1507cc 100644
> --- a/drivers/media/dvb-frontends/tda10071.c
> +++ b/drivers/media/dvb-frontends/tda10071.c
> @@ -53,8 +53,9 @@ static int tda10071_cmd_execute(struct tda10071_dev *dev,
>  	struct tda10071_cmd *cmd)
>  {
>  	struct i2c_client *client = dev->client;
> -	int ret, i;
> +	int ret;
>  	unsigned int uitmp;
> +	unsigned long timeout;
>  
>  	if (!dev->warm) {
>  		ret = -EFAULT;
> @@ -72,17 +73,19 @@ static int tda10071_cmd_execute(struct tda10071_dev *dev,
>  		goto error;
>  
>  	/* wait cmd execution terminate */
> -	for (i = 1000, uitmp = 1; i && uitmp; i--) {
> +	#define CMD_EXECUTE_TIMEOUT 30
> +	timeout = jiffies + msecs_to_jiffies(CMD_EXECUTE_TIMEOUT);
> +	for (uitmp = 1; !time_after(jiffies, timeout) && uitmp;) {
>  		ret = regmap_read(dev->regmap, 0x1f, &uitmp);
>  		if (ret)
>  			goto error;
> -
> -		usleep_range(200, 5000);

Hmm... removing the usleep() doesn't sound a good idea. You'll be
flooding the I2C bus with read commands and spending CPU cycles
for 30ms spending more power than the previous code. That doesn't
sound more "elegant solution than poll X times with sleep" for me.

So, I would keep the usleep_range() here and add a better
comment on the patch description.

I'll skip this patch from the git pull request, as, from your description,
this is just a cleanup patch. So, it shouldn't affect the other patches
at the series.


>  	}
>  
> -	dev_dbg(&client->dev, "loop=%d\n", i);
> +	dev_dbg(&client->dev, "cmd execution took %u ms\n",
> +		jiffies_to_msecs(jiffies) -
> +		(jiffies_to_msecs(timeout) - CMD_EXECUTE_TIMEOUT));
>  
> -	if (i == 0) {
> +	if (uitmp) {
>  		ret = -ETIMEDOUT;
>  		goto error;
>  	}

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 09/12] tda10071: use jiffies when poll firmware status
  2015-08-11 10:20   ` Mauro Carvalho Chehab
@ 2015-08-11 15:18     ` Antti Palosaari
  2015-08-11 15:50       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 15+ messages in thread
From: Antti Palosaari @ 2015-08-11 15:18 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: linux-media

On 08/11/2015 01:20 PM, Mauro Carvalho Chehab wrote:
> Em Thu,  9 Jul 2015 07:06:29 +0300
> Antti Palosaari <crope@iki.fi> escreveu:
>
>> Use jiffies to set timeout for firmware command status polling.
>> It is more elegant solution than poll X times with sleep.

>>   	/* wait cmd execution terminate */
>> -	for (i = 1000, uitmp = 1; i && uitmp; i--) {
>> +	#define CMD_EXECUTE_TIMEOUT 30
>> +	timeout = jiffies + msecs_to_jiffies(CMD_EXECUTE_TIMEOUT);
>> +	for (uitmp = 1; !time_after(jiffies, timeout) && uitmp;) {
>>   		ret = regmap_read(dev->regmap, 0x1f, &uitmp);
>>   		if (ret)
>>   			goto error;
>> -
>> -		usleep_range(200, 5000);
>
> Hmm... removing the usleep() doesn't sound a good idea. You'll be
> flooding the I2C bus with read commands and spending CPU cycles
> for 30ms spending more power than the previous code. That doesn't
> sound more "elegant solution than poll X times with sleep" for me.
>
> So, I would keep the usleep_range() here and add a better
> comment on the patch description.

First of all, polling firmware ready status is very common for chips 
having firmware. And there is 2 ways to implement it:
1) poll N times in a loop using X sleep, timeout = N * X
2) poll in a loop using jiffies as a timeout

IMHO 2 is more elegant solution and I have started using it recently.

What you now propose is add some throttle in order to slow down polling 
interval to reduce I2C I/O. Yes sure less I/O is better, but downside is 
that it makes some unneeded extra delay to code path. Usually these sort 
firmware ready polling ends rather quickly, in a loop or two.

Sure it eats some extra CPU cycles, but I think extra control messages 
are about nothing compared to I/O used for data streaming.

Which kind of throttle delay you think is suitable for polling command 
status over I2C bus?

regards
Antti

-- 
http://palosaari.fi/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 09/12] tda10071: use jiffies when poll firmware status
  2015-08-11 15:18     ` Antti Palosaari
@ 2015-08-11 15:50       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 15+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-11 15:50 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: linux-media

Em Tue, 11 Aug 2015 18:18:39 +0300
Antti Palosaari <crope@iki.fi> escreveu:

> On 08/11/2015 01:20 PM, Mauro Carvalho Chehab wrote:
> > Em Thu,  9 Jul 2015 07:06:29 +0300
> > Antti Palosaari <crope@iki.fi> escreveu:
> >
> >> Use jiffies to set timeout for firmware command status polling.
> >> It is more elegant solution than poll X times with sleep.
> 
> >>   	/* wait cmd execution terminate */
> >> -	for (i = 1000, uitmp = 1; i && uitmp; i--) {
> >> +	#define CMD_EXECUTE_TIMEOUT 30
> >> +	timeout = jiffies + msecs_to_jiffies(CMD_EXECUTE_TIMEOUT);
> >> +	for (uitmp = 1; !time_after(jiffies, timeout) && uitmp;) {
> >>   		ret = regmap_read(dev->regmap, 0x1f, &uitmp);
> >>   		if (ret)
> >>   			goto error;
> >> -
> >> -		usleep_range(200, 5000);
> >
> > Hmm... removing the usleep() doesn't sound a good idea. You'll be
> > flooding the I2C bus with read commands and spending CPU cycles
> > for 30ms spending more power than the previous code. That doesn't
> > sound more "elegant solution than poll X times with sleep" for me.
> >
> > So, I would keep the usleep_range() here and add a better
> > comment on the patch description.
> 
> First of all, polling firmware ready status is very common for chips 
> having firmware. And there is 2 ways to implement it:
> 1) poll N times in a loop using X sleep, timeout = N * X
> 2) poll in a loop using jiffies as a timeout
> 
> IMHO 2 is more elegant solution and I have started using it recently.

Yes, (2) is more elegant.

> What you now propose is add some throttle in order to slow down polling 
> interval to reduce I2C I/O. Yes sure less I/O is better, but downside is 
> that it makes some unneeded extra delay to code path. Usually these sort 
> firmware ready polling ends rather quickly, in a loop or two.

If only few interactions is needed, then OK. Please add a comment then,
explaining that.
> 
> Sure it eats some extra CPU cycles, but I think extra control messages 
> are about nothing compared to I/O used for data streaming.
> 
> Which kind of throttle delay you think is suitable for polling command 
> status over I2C bus?
> 
> regards
> Antti
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2015-08-11 15:50 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-09  4:06 [PATCH 01/12] em28xx: remove unused a8293 SEC config Antti Palosaari
2015-07-09  4:06 ` [PATCH 02/12] a8293: remove legacy media attach Antti Palosaari
2015-07-09  4:06 ` [PATCH 03/12] a8293: use i2c_master_send / i2c_master_recv for I2C I/O Antti Palosaari
2015-07-09  4:06 ` [PATCH 04/12] a8293: improve LNB register programming logic Antti Palosaari
2015-07-09  4:06 ` [PATCH 05/12] a8293: coding style issues Antti Palosaari
2015-07-09  4:06 ` [PATCH 06/12] tda10071: remove legacy media attach Antti Palosaari
2015-07-09  4:06 ` [PATCH 07/12] tda10071: rename device state struct to dev Antti Palosaari
2015-07-09  4:06 ` [PATCH 08/12] tda10071: convert to regmap I2C API Antti Palosaari
2015-07-09  4:06 ` [PATCH 09/12] tda10071: use jiffies when poll firmware status Antti Palosaari
2015-08-11 10:20   ` Mauro Carvalho Chehab
2015-08-11 15:18     ` Antti Palosaari
2015-08-11 15:50       ` Mauro Carvalho Chehab
2015-07-09  4:06 ` [PATCH 10/12] tda10071: protect firmware command exec with mutex Antti Palosaari
2015-07-09  4:06 ` [PATCH 11/12] tda10071: do not get_frontend() when not ready Antti Palosaari
2015-07-09  4:06 ` [PATCH 12/12] tda10071: implement DVBv5 statistics Antti Palosaari

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox