Skip to contentSkip to conversation

af9035: Add fc0011 tuner support

PATCH Applied Michael Büsch 2 participants 3 messages Apr 2, 2012 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 af9035: Add fc0011 tuner support

This adds Fitipower fc0011 tuner support to the af9035 driver.

---

drivers/media/dvb/dvb-usb/af9035.c +88 -0
Index: linux/drivers/media/dvb/dvb-usb/af9035.c
===================================================================
@@ -22,6 +22,7 @@
 #include "af9035.h"
 #include "af9033.h"
 #include "tua9001.h"
+#include "fc0011.h"
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 static DEFINE_MUTEX(af9035_usb_mutex);
@@ -498,6 +499,7 @@
 
 		switch (tmp) {
 		case AF9033_TUNER_TUA9001:
+		case AF9033_TUNER_FC0011:
 			af9035_af9033_config[i].spec_inv = 1;
 			break;
 		default:
@@ -542,6 +544,83 @@
 	return ret;
 }
 
+static int af9035_fc0011_tuner_callback(struct dvb_usb_device *d,
+					int cmd, int arg)
+{
+	int err;
+
+	switch (cmd) {
+	case FC0011_FE_CALLBACK_POWER:
+		/* Tuner enable */
+		err = af9035_wr_reg_mask(d, 0xd8eb, 1, 1);
+		if (err)
+			return err;
+		err = af9035_wr_reg_mask(d, 0xd8ec, 1, 1);
+		if (err)
+			return err;
+		err = af9035_wr_reg_mask(d, 0xd8ed, 1, 1);
+		if (err)
+			return err;
+		/* LED */
+		err = af9035_wr_reg_mask(d, 0xd8d0, 1, 1);
+		if (err)
+			return err;
+		err = af9035_wr_reg_mask(d, 0xd8d1, 1, 1);
+		if (err)
+			return err;
+		msleep(10);
+		break;
+	case FC0011_FE_CALLBACK_RESET:
+		err = af9035_wr_reg(d, 0xd8e9, 1);
+		if (err)
+			return err;
+		err = af9035_wr_reg(d, 0xd8e8, 1);
+		if (err)
+			return err;
+		err = af9035_wr_reg(d, 0xd8e7, 1);
+		if (err)
+			return err;
+		msleep(10);
+		err = af9035_wr_reg(d, 0xd8e7, 0);
+		if (err)
+			return err;
+		msleep(10);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int af9035_tuner_callback(struct dvb_usb_device *d, int cmd, int arg)
+{
+	switch (af9035_af9033_config[0].tuner) {
+	case AF9033_TUNER_FC0011:
+		return af9035_fc0011_tuner_callback(d, cmd, arg);
+	default:
+		break;
+	}
+
+	return -ENODEV;
+}
+
+static int af9035_frontend_callback(void *adapter_priv, int component,
+				    int cmd, int arg)
+{
+	struct i2c_adapter *adap = adapter_priv;
+	struct dvb_usb_device *d = i2c_get_adapdata(adap);
+
+	switch (component) {
+	case DVB_FRONTEND_COMPONENT_TUNER:
+		return af9035_tuner_callback(d, cmd, arg);
+	default:
+		break;
+	}
+
+	return -EINVAL;
+}
+
 static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
 {
 	int ret;
@@ -570,6 +649,7 @@
 		ret = -ENODEV;
 		goto err;
 	}
+	adap->fe_adap[0].fe->callback = af9035_frontend_callback;
 
 	return 0;
 
@@ -583,6 +663,10 @@
 	.i2c_addr = 0x60,
 };
 
+static const struct fc0011_config af9035_fc0011_config = {
+	.i2c_address = 0x60,
+};
+
 static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
 {
 	int ret;
@@ -631,6 +715,10 @@
 		fe = dvb_attach(tua9001_attach, adap->fe_adap[0].fe,
 				&adap->dev->i2c_adap, &af9035_tua9001_config);
 		break;
+	case AF9033_TUNER_FC0011:
+		fe = dvb_attach(fc0011_attach, adap->fe_adap[0].fe,
+				&adap->dev->i2c_adap, &af9035_fc0011_config);
+		break;
 	default:
 		fe = NULL;
 	}
drivers/media/dvb/frontends/af9033.c +4 -0
Index: linux/drivers/media/dvb/frontends/af9033.c
===================================================================
@@ -297,6 +297,10 @@
 		len = ARRAY_SIZE(tuner_init_tua9001);
 		init = tuner_init_tua9001;
 		break;
+	case AF9033_TUNER_FC0011:
+		len = ARRAY_SIZE(tuner_init_fc0011);
+		init = tuner_init_fc0011;
+		break;
 	default:
 		pr_debug("%s: unsupported tuner ID=%d\n", __func__,
 				state->cfg.tuner);
drivers/media/dvb/frontends/af9033_priv.h +61 -0

66 lines not on this page · raw message

drivers/media/dvb/dvb-usb/Kconfig +1 -0
Index: linux/drivers/media/dvb/dvb-usb/Kconfig
===================================================================
@@ -428,6 +428,7 @@
 	depends on DVB_USB
 	select DVB_AF9033
 	select MEDIA_TUNER_TUA9001 if !MEDIA_TUNER_CUSTOMISE
+	select MEDIA_TUNER_FC0011 if !MEDIA_TUNER_CUSTOMISE
 	help
 	  Say Y here to support the Afatech AF9035 based DVB USB receiver.
 
Signature · 3 lines
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E
#1 lore raw
Quoted 3 lines · Michael Büsch

This adds Fitipower fc0011 tuner support to the af9035 driver.

Applied, thanks!
http://git.linuxtv.org/anttip/media_tree.git/shortlog/refs/heads/af9035_experimental

And same checkpatch.pl issue here.
You can ran checkpatch like that:
git diff | ./scripts/checkpatch.pl -
git diff --cached | ./scripts/checkpatch.pl - ./scripts/checkpatch.pl --file drivers/media/dvb/dvb-usb/af9035.c

For that driver it complains you are using wrong sleep (msleep(10)). Correct sleep for that case is something like usleep_range(10000, 100000); which means as sleep at least 10ms but it does not matter if you sleep even 100ms. The wider range the better chance for Kernel to optimize power saving. There was usleep_range() already used inside that module.

regards
Antti

Signature · 1 line
http://palosaari.fi/
#2 lore raw
Quoted 14 lines · On Mon, 02 Apr 2012 20:03:08 +0300 Antti Palosaari <[email protected]> wrote:
Quoted 3 lines · Michael Büsch

This adds Fitipower fc0011 tuner support to the af9035 driver.

Applied, thanks!
http://git.linuxtv.org/anttip/media_tree.git/shortlog/refs/heads/af9035_experimental

And same checkpatch.pl issue here.
You can ran checkpatch like that:
git diff | ./scripts/checkpatch.pl -
git diff --cached | ./scripts/checkpatch.pl - ./scripts/checkpatch.pl --file drivers/media/dvb/dvb-usb/af9035.c

Quoted 6 lines

For that driver it complains you are using wrong sleep (msleep(10)). Correct sleep for that case is something like usleep_range(10000, 100000); which means as sleep at least 10ms but it does not matter if you sleep even 100ms. The wider range the better chance for Kernel to optimize power saving. There was usleep_range() already used inside that module.

Ok, the sleep warning is the only remotely sane checkpatch warning for these patches. So I will send a separate patch to convert those sleeps.

Signature · 3 lines
Greetings, Michael.

PGP encryption is encouraged / 908D8B0E