Re: af901x: NXP TDA18218

2010-02-26 Thread Bert Massop
Using the previous patch, the compiler will complain about a missing
file (tda18218.h). Please use this updated version of the patch, also
made by Nikola.

Have fun with it, it's working fine here!

Regards, Bert

On Wed, Feb 24, 2010 at 22:41, Bert Massop bert.mas...@gmail.com wrote:
 This is a forward of the original email from Nikola Pajkovsky. Just
 for the records, so it is on the list.

 This solves the problem of the tuner id:179 not supported error, when
 loading the AF9015 driver.

 Thank you, Nikola!

 Regards,
 Bert Massop

 -- Forwarded message --
 From: Nikola Pajkovsky npajk...@redhat.com
 Date: Wed, Feb 24, 2010 at 11:54
 Subject: Re: af901x: NXP TDA18218
 To: Antti Palosaari cr...@iki.fi
 Cc: jan.sund...@aland.net, bert.mas...@gmail.com,
 mkru...@kernellabs.com, dheitmuel...@kernellabs.com


 Hello,

    here is my solution, I can watch Vancouver right now :). I don't
 look at the patch if there is some mistake(no time watch Vancouver),
 but I will when I will have some free time.
 Attached patch apply against this souce (hg clone
 http://linuxtv.org/hg/~anttip/af9015/).

 Firmware:
 wget http://jusst.de/manu/fw/AFA/dvb-usb-af9015.fw_a-link
 sudo mv dvb-usb-af9015.fw_a-link /lib/firmware/dvb-usb-af9015.fw

 Have a nice day ;)

 On 23.2.2010 14:02, Antti Palosaari wrote:

 Hello,
 I just got info from one user about this driver, looks like Terratec have 
 driver.
 http://forum.ubuntuusers.de/topic/probleme-beim-installieren-terratec-cinergy-t/3/?highlight=terratec+cinergy+t+stick

 Antti

 Nikola Pajkovsky wrote:

 Hello,

    is any chance that will be support for TDA182118?

 Regards,




 --
 Nikola

diff -r 0f41fd7df85d linux/drivers/media/common/tuners/Kconfig
--- a/linux/drivers/media/common/tuners/Kconfig	Thu Feb 11 02:33:12 2010 +0200
+++ b/linux/drivers/media/common/tuners/Kconfig	Thu Feb 25 17:21:11 2010 +0100
@@ -179,4 +179,11 @@
 	help
 	  A driver for the silicon tuner MAX2165 from Maxim.
 
+config MEDIA_TUNER_TDA18218
+	tristate NXP TDA18218 silicon tuner
+	depends on VIDEO_MEDIA  I2C
+	default m if MEDIA_TUNER_CUSTOMISE
+	help
+	  A driver for the silicon tuner TDA18218 from NXP.
+
 endif # MEDIA_TUNER_CUSTOMISE
diff -r 0f41fd7df85d linux/drivers/media/common/tuners/Makefile
--- a/linux/drivers/media/common/tuners/Makefile	Thu Feb 11 02:33:12 2010 +0200
+++ b/linux/drivers/media/common/tuners/Makefile	Thu Feb 25 17:21:11 2010 +0100
@@ -24,6 +24,7 @@
 obj-$(CONFIG_MEDIA_TUNER_MXL5007T) += mxl5007t.o
 obj-$(CONFIG_MEDIA_TUNER_MC44S803) += mc44s803.o
 obj-$(CONFIG_MEDIA_TUNER_MAX2165) += max2165.o
+obj-$(CONFIG_MEDIA_TUNER_TDA18218) += tda18218.o
 
 EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
 EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
diff -r 0f41fd7df85d linux/drivers/media/common/tuners/tda18218.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +
+++ b/linux/drivers/media/common/tuners/tda18218.c	Thu Feb 25 17:21:11 2010 +0100
@@ -0,0 +1,471 @@
+/*
+ *  Driver for NXP TDA18218 silicon tuner
+ *
+ *  Copyright (C) 2010 Lauris Ding ld...@gmx.de
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#include tda18218.h
+#include compat.h
+#include tda18218_priv.h
+
+static int tda18218_write_reg(struct dvb_frontend *fe, u8 reg, u8 val)
+{
+	struct tda18218_priv *priv = fe-tuner_priv;
+	u8 buf[2] = { reg, val };
+	struct i2c_msg msg = { .addr = priv-cfg-i2c_address, .flags = 0,
+			   .buf = buf, .len = 2 };
+	int ret;
+
+	if (fe-ops.i2c_gate_ctrl)
+		fe-ops.i2c_gate_ctrl(fe, 1);
+	/* write register */
+	ret = i2c_transfer(priv-i2c, msg, 1);
+	if (fe-ops.i2c_gate_ctrl)
+		fe-ops.i2c_gate_ctrl(fe, 0);
+
+	if (ret != 1)
+		printk(KERN_WARNING I2C write failed ret: %d reg: %02x\n, ret, reg);
+
+	return (ret == 1 ? 0 : ret);
+}
+
+static int tda18218_write_regs(struct dvb_frontend *fe, u8 reg,
+	u8 *val, u8 len)
+{
+	struct tda18218_priv *priv = fe-tuner_priv;
+	u8 buf[1+len];
+	struct i2c_msg msg = {
+		.addr = priv-cfg-i2c_address,
+		.flags = 0,
+		.len = sizeof(buf),
+		.buf = buf };
+		
+	int ret;
+
+	buf[0] = reg;
+	memcpy(buf[1], val, len);
+	
+	if (fe-ops.i2c_gate_ctrl)
+		fe-ops.i2c_gate_ctrl(fe, 1);
+	ret = i2c_transfer(priv-i2c, msg, 1);
+	if (fe-ops.i2c_gate_ctrl)
+		fe-ops.i2c_gate_ctrl(fe, 1);
+
+	if (ret != 1)
+		printk(KERN_WARNING I2C write failed ret: %d reg: %02x len: %d\n, ret, reg, len

Fwd: af901x: NXP TDA18218

2010-02-24 Thread Bert Massop
This is a forward of the original email from Nikola Pajkovsky. Just
for the records, so it is on the list.

This solves the problem of the tuner id:179 not supported error, when
loading the AF9015 driver.

Thank you, Nikola!

Regards,
Bert Massop

-- Forwarded message --
From: Nikola Pajkovsky npajk...@redhat.com
Date: Wed, Feb 24, 2010 at 11:54
Subject: Re: af901x: NXP TDA18218
To: Antti Palosaari cr...@iki.fi
Cc: jan.sund...@aland.net, bert.mas...@gmail.com,
mkru...@kernellabs.com, dheitmuel...@kernellabs.com


Hello,

   here is my solution, I can watch Vancouver right now :). I don't
look at the patch if there is some mistake(no time watch Vancouver),
but I will when I will have some free time.
Attached patch apply against this souce (hg clone
http://linuxtv.org/hg/~anttip/af9015/).

Firmware:
wget http://jusst.de/manu/fw/AFA/dvb-usb-af9015.fw_a-link
sudo mv dvb-usb-af9015.fw_a-link /lib/firmware/dvb-usb-af9015.fw

Have a nice day ;)

On 23.2.2010 14:02, Antti Palosaari wrote:

 Hello,
 I just got info from one user about this driver, looks like Terratec have 
 driver.
 http://forum.ubuntuusers.de/topic/probleme-beim-installieren-terratec-cinergy-t/3/?highlight=terratec+cinergy+t+stick

 Antti

 Nikola Pajkovsky wrote:

 Hello,

    is any chance that will be support for TDA182118?

 Regards,




--
Nikola
diff -r 0f41fd7df85d linux/drivers/media/common/tuners/Kconfig
--- a/linux/drivers/media/common/tuners/Kconfig	Thu Feb 11 02:33:12 2010 +0200
+++ b/linux/drivers/media/common/tuners/Kconfig	Wed Feb 24 11:47:14 2010 +0100
@@ -179,4 +179,11 @@
 	help
 	  A driver for the silicon tuner MAX2165 from Maxim.
 
+config MEDIA_TUNER_TDA18218
+	tristate NXP TDA18218 silicon tuner
+	depends on VIDEO_MEDIA  I2C
+	default m if MEDIA_TUNER_CUSTOMISE
+	help
+	  A driver for the silicon tuner TDA18218 from NXP.
+
 endif # MEDIA_TUNER_CUSTOMISE
diff -r 0f41fd7df85d linux/drivers/media/common/tuners/Makefile
--- a/linux/drivers/media/common/tuners/Makefile	Thu Feb 11 02:33:12 2010 +0200
+++ b/linux/drivers/media/common/tuners/Makefile	Wed Feb 24 11:47:14 2010 +0100
@@ -24,6 +24,7 @@
 obj-$(CONFIG_MEDIA_TUNER_MXL5007T) += mxl5007t.o
 obj-$(CONFIG_MEDIA_TUNER_MC44S803) += mc44s803.o
 obj-$(CONFIG_MEDIA_TUNER_MAX2165) += max2165.o
+obj-$(CONFIG_MEDIA_TUNER_TDA18218) += tda18218.o
 
 EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
 EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
diff -r 0f41fd7df85d linux/drivers/media/dvb/dvb-usb/af9015.c
--- a/linux/drivers/media/dvb/dvb-usb/af9015.c	Thu Feb 11 02:33:12 2010 +0200
+++ b/linux/drivers/media/dvb/dvb-usb/af9015.c	Wed Feb 24 11:47:14 2010 +0100
@@ -20,11 +20,7 @@
  *Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  */
-#if LINUX_VERSION_CODE = KERNEL_VERSION(2, 6, 25)
 
-#include linux/hash.h
-
-#endif
 #include af9015.h
 #include af9013.h
 #include mt2060.h
@@ -32,6 +28,7 @@
 #include tda18271.h
 #include mxl5005s.h
 #include mc44s803.h
+#include tda18218.h
 
 static int dvb_usb_af9015_debug;
 module_param_named(debug, dvb_usb_af9015_debug, int, 0644);
@@ -273,7 +270,8 @@
 
 	while (i  num) {
 		if (msg[i].addr == af9015_af9013_config[0].demod_address ||
-		msg[i].addr == af9015_af9013_config[1].demod_address) {
+		msg[i].addr == af9015_af9013_config[1].demod_address  ||
+		msg[i].addr == 0x3a) {
 			addr = msg[i].buf[0]  8;
 			addr += msg[i].buf[1];
 			mbox = msg[i].buf[2];
@@ -286,7 +284,8 @@
 
 		if (num  i + 1  (msg[i+1].flags  I2C_M_RD)) {
 			if (msg[i].addr ==
-af9015_af9013_config[0].demod_address)
+af9015_af9013_config[0].demod_address ||
+			msg[i].addr == 0x3a)
 req.cmd = READ_MEMORY;
 			else
 req.cmd = READ_I2C;
@@ -301,7 +300,8 @@
 		} else if (msg[i].flags  I2C_M_RD) {
 			ret = -EINVAL;
 			if (msg[i].addr ==
-af9015_af9013_config[0].demod_address)
+af9015_af9013_config[0].demod_address ||
+			msg[i].addr == 0x3a)
 goto error;
 			else
 req.cmd = READ_I2C;
@@ -315,7 +315,8 @@
 			i += 1;
 		} else {
 			if (msg[i].addr ==
-af9015_af9013_config[0].demod_address)
+af9015_af9013_config[0].demod_address ||
+			msg[i].addr == 0x3a)
 req.cmd = WRITE_MEMORY;
 			else
 req.cmd = WRITE_I2C;
@@ -560,24 +561,11 @@
 	return ret;
 }
 
-#if LINUX_VERSION_CODE  KERNEL_VERSION(2, 6, 25)
+/* dump eeprom */
 static int af9015_eeprom_dump(struct dvb_usb_device *d)
-#else
-/* hash (and dump) eeprom */
-static int af9015_eeprom_hash(struct usb_device *udev)
-#endif
 {
-#if LINUX_VERSION_CODE  KERNEL_VERSION(2, 6, 25)
 	u8 reg, val;
-#else
-	static const unsigned int eeprom_size = 256;
-	unsigned int reg;
-	int ret;
-	u8 val, *eeprom;
-	struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, val};
-#endif
 
-#if LINUX_VERSION_CODE  KERNEL_VERSION(2, 6, 25)
 	for (reg = 0; ; reg++) {
 		if (reg % 16 == 0) {
 			if (reg)
@@ -590,43 +578,9 @@
 			deb_info(KERN_CONT  --);
 		if (reg == 0xff)
 			break;
-#else
-	eeprom = kmalloc(eeprom_size, GFP_KERNEL);
-	if (eeprom == NULL