All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/8] add si2165 demod driver
@ 2014-07-22 20:12 Matthias Schwarzott
  2014-07-22 20:12 ` [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165 Matthias Schwarzott
                   ` (7 more replies)
  0 siblings, 8 replies; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-22 20:12 UTC (permalink / raw)
  To: crope, m.chehab, linux-media

This series adds support for Si2165 demod.
The driver is DVB-T only for now.

Then it adds support for these devices:
* Hauppauge WinTV 930C-HD model 1113xx
* Hauppauge WinTV 930C-HD model 1114xx
* Hauppauge HVR-5500 (add DVB-T support)
* PCTV QuatroStick 521e
* PCTV QuatroStick 522e

Regards
Matthias


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

* [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165
  2014-07-22 20:12 [PATCH 0/8] add si2165 demod driver Matthias Schwarzott
@ 2014-07-22 20:12 ` Matthias Schwarzott
  2014-07-23  9:20   ` Antti Palosaari
  2014-07-22 20:12 ` [PATCH 2/8] si2165: Add demod driver for DVB-T only Matthias Schwarzott
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-22 20:12 UTC (permalink / raw)
  To: crope, m.chehab, linux-media; +Cc: Matthias Schwarzott

Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
 Documentation/dvb/get_dvb_firmware | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/Documentation/dvb/get_dvb_firmware b/Documentation/dvb/get_dvb_firmware
index d91b8be..26c623d 100755
--- a/Documentation/dvb/get_dvb_firmware
+++ b/Documentation/dvb/get_dvb_firmware
@@ -29,7 +29,7 @@ use IO::Handle;
 		"af9015", "ngene", "az6027", "lme2510_lg", "lme2510c_s7395",
 		"lme2510c_s7395_old", "drxk", "drxk_terratec_h5",
 		"drxk_hauppauge_hvr930c", "tda10071", "it9135", "drxk_pctv",
-		"drxk_terratec_htc_stick", "sms1xxx_hcw");
+		"drxk_terratec_htc_stick", "sms1xxx_hcw", "si2165");
 
 # Check args
 syntax() if (scalar(@ARGV) != 1);
@@ -783,6 +783,37 @@ sub sms1xxx_hcw {
     $allfiles;
 }
 
+sub si2165 {
+    my $sourcefile = "model_111xxx_122xxx_driver_6_0_119_31191_WHQL.zip";
+    my $url = "http://www.hauppauge.de/files/drivers/";
+    my $hash = "76633e7c76b0edee47c3ba18ded99336";
+    my $fwfile = "dvb-demod-si2165.fw";
+    my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
+
+    checkstandard();
+
+    wgetfile($sourcefile, $url . $sourcefile);
+    verify($sourcefile, $hash);
+    unzip($sourcefile, $tmpdir);
+    extract("$tmpdir/Driver10/Hcw10bda.sys", 0x80788, 0x81E08-0x80788, "$tmpdir/fw1");
+
+    delzero("$tmpdir/fw1","$tmpdir/fw1-1");
+    #verify("$tmpdir/fw1","5e0909858fdf0b5b09ad48b9fe622e70");
+
+    my $CRC="\x0A\xCC";
+    my $BLOCKS_MAIN="\x27";
+    open FW,">$fwfile";
+    print FW "\x01\x00"; # just a version id for the driver itself
+    print FW "\x9A"; # fw version
+    print FW "\x00"; # padding
+    print FW "$BLOCKS_MAIN"; # number of blocks of main part
+    print FW "\x00"; # padding
+    print FW "$CRC"; # 16bit crc value of main part
+    appendfile(FW,"$tmpdir/fw1");
+
+    "$fwfile";
+}
+
 # ---------------------------------------------------------------
 # Utilities
 
-- 
2.0.0


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

* [PATCH 2/8] si2165: Add demod driver for DVB-T only
  2014-07-22 20:12 [PATCH 0/8] add si2165 demod driver Matthias Schwarzott
  2014-07-22 20:12 ` [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165 Matthias Schwarzott
@ 2014-07-22 20:12 ` Matthias Schwarzott
  2014-07-22 20:12 ` [PATCH 3/8] cx23885: Add si2165 support for HVR-5500 Matthias Schwarzott
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-22 20:12 UTC (permalink / raw)
  To: crope, m.chehab, linux-media; +Cc: Matthias Schwarzott

DVB-T was tested  with 8MHz BW channels in germany
This driver is the simplest possible, it uses automatic mode for all
parameters (TPS).

Added spectrum inversion support.

Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
 drivers/media/dvb-frontends/Kconfig       |    9 +
 drivers/media/dvb-frontends/Makefile      |    1 +
 drivers/media/dvb-frontends/si2165.c      | 1040 +++++++++++++++++++++++++++++
 drivers/media/dvb-frontends/si2165.h      |   64 ++
 drivers/media/dvb-frontends/si2165_priv.h |   23 +
 5 files changed, 1137 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/si2165.c
 create mode 100644 drivers/media/dvb-frontends/si2165.h
 create mode 100644 drivers/media/dvb-frontends/si2165_priv.h

diff --git a/drivers/media/dvb-frontends/Kconfig b/drivers/media/dvb-frontends/Kconfig
index 78a95a6..b62fcfd 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -63,6 +63,15 @@ config DVB_TDA18271C2DD
 
 	  Say Y when you want to support this tuner.
 
+config DVB_SI2165
+	tristate "Silicon Labs si2165 based"
+	depends on DVB_CORE && I2C
+	default m if !MEDIA_SUBDRV_AUTOSELECT
+	help
+	  A DVB-C/T demodulator.
+
+	  Say Y when you want to support this frontend.
+
 comment "DVB-S (satellite) frontends"
 	depends on DVB_CORE
 
diff --git a/drivers/media/dvb-frontends/Makefile b/drivers/media/dvb-frontends/Makefile
index 655e3c8..edf103d 100644
--- a/drivers/media/dvb-frontends/Makefile
+++ b/drivers/media/dvb-frontends/Makefile
@@ -105,6 +105,7 @@ obj-$(CONFIG_DVB_STV0367) += stv0367.o
 obj-$(CONFIG_DVB_CXD2820R) += cxd2820r.o
 obj-$(CONFIG_DVB_DRXK) += drxk.o
 obj-$(CONFIG_DVB_TDA18271C2DD) += tda18271c2dd.o
+obj-$(CONFIG_DVB_SI2165) += si2165.o
 obj-$(CONFIG_DVB_A8293) += a8293.o
 obj-$(CONFIG_DVB_TDA10071) += tda10071.o
 obj-$(CONFIG_DVB_RTL2830) += rtl2830.o
diff --git a/drivers/media/dvb-frontends/si2165.c b/drivers/media/dvb-frontends/si2165.c
new file mode 100644
index 0000000..3a2d6c5
--- /dev/null
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -0,0 +1,1040 @@
+/*
+    Driver for Silicon Labs SI2165 DVB-C/-T Demodulator
+
+    Copyright (C) 2013-2014 Matthias Schwarzott <zzam@gentoo.org>
+
+    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.
+
+    References:
+    http://www.silabs.com/Support%20Documents/TechnicalDocs/Si2165-short.pdf
+*/
+
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/firmware.h>
+
+#include "dvb_frontend.h"
+#include "dvb_math.h"
+#include "si2165_priv.h"
+#include "si2165.h"
+
+/* Hauppauge WinTV-HVR-930C-HD B130 / PCTV QuatroStick 521e 1113xx
+ * uses 16 MHz xtal */
+
+/* Hauppauge WinTV-HVR-930C-HD B131 / PCTV QuatroStick 522e 1114xx
+ * uses 24 MHz clock provided by tuner */
+
+struct si2165_state {
+	struct i2c_adapter *i2c;
+
+	struct dvb_frontend frontend;
+
+	struct si2165_config config;
+
+	/* chip revision */
+	u8 revcode;
+	/* chip type */
+	u8 chip_type;
+
+	/* calculated by xtal and div settings */
+	u32 fvco_hz;
+	u32 sys_clk;
+	u32 adc_clk;
+
+	bool has_dvbc;
+	bool has_dvbt;
+	bool firmware_loaded;
+};
+
+#define DEBUG_OTHER	0x01
+#define DEBUG_I2C_WRITE	0x02
+#define DEBUG_I2C_READ	0x04
+#define DEBUG_REG_READ	0x08
+#define DEBUG_REG_WRITE	0x10
+#define DEBUG_FW_LOAD	0x20
+
+static int debug = 0x00;
+
+#define dprintk(args...) \
+	do { \
+		if (debug & DEBUG_OTHER) \
+			printk(KERN_DEBUG "si2165: " args); \
+	} while (0)
+
+#define deb_i2c_write(args...) \
+	do { \
+		if (debug & DEBUG_I2C_WRITE) \
+			printk(KERN_DEBUG "si2165: i2c write: " args); \
+	} while (0)
+
+#define deb_i2c_read(args...) \
+	do { \
+		if (debug & DEBUG_I2C_READ) \
+			printk(KERN_DEBUG "si2165: i2c read: " args); \
+	} while (0)
+
+#define deb_readreg(args...) \
+	do { \
+		if (debug & DEBUG_REG_READ) \
+			printk(KERN_DEBUG "si2165: reg read: " args); \
+	} while (0)
+
+#define deb_writereg(args...) \
+	do { \
+		if (debug & DEBUG_REG_WRITE) \
+			printk(KERN_DEBUG "si2165: reg write: " args); \
+	} while (0)
+
+#define deb_fw_load(args...) \
+	do { \
+		if (debug & DEBUG_FW_LOAD) \
+			printk(KERN_DEBUG "si2165: fw load: " args); \
+	} while (0)
+
+static int si2165_write(struct si2165_state *state, const u16 reg,
+		       const u8 *src, const int count)
+{
+	int ret;
+	struct i2c_msg msg;
+	u8 buf[2 + 4]; /* write a maximum of 4 bytes of data */
+
+	if (count + 2 > sizeof(buf)) {
+		dev_warn(&state->i2c->dev,
+			  "%s: i2c wr reg=%04x: count=%d is too big!\n",
+			  KBUILD_MODNAME, reg, count);
+		return -EINVAL;
+	}
+	buf[0] = reg >> 8;
+	buf[1] = reg & 0xff;
+	memcpy(buf + 2, src, count);
+
+	msg.addr = state->config.i2c_addr;
+	msg.flags = 0;
+	msg.buf = buf;
+	msg.len = count + 2;
+
+	if (debug & DEBUG_I2C_WRITE)
+		deb_i2c_write("reg: 0x%04x, data: %*ph\n", reg, count, src);
+
+	ret = i2c_transfer(state->i2c, &msg, 1);
+
+	if (ret != 1) {
+		dev_err(&state->i2c->dev, "%s: ret == %d\n", __func__, ret);
+		if (ret < 0)
+			return ret;
+		else
+			return -EREMOTEIO;
+	}
+
+	return 0;
+}
+
+static int si2165_read(struct si2165_state *state,
+		       const u16 reg, u8 *val, const int count)
+{
+	int ret;
+	u8 reg_buf[] = { reg >> 8, reg & 0xff };
+	struct i2c_msg msg[] = {
+		{ .addr = state->config.i2c_addr,
+		  .flags = 0, .buf = reg_buf, .len = 2 },
+		{ .addr = state->config.i2c_addr,
+		  .flags = I2C_M_RD, .buf = val, .len = count },
+	};
+
+	ret = i2c_transfer(state->i2c, msg, 2);
+
+	if (ret != 2) {
+		dev_err(&state->i2c->dev, "%s: error (addr %02x reg %04x error (ret == %i)\n",
+			__func__, state->config.i2c_addr, reg, ret);
+		if (ret < 0)
+			return ret;
+		else
+			return -EREMOTEIO;
+	}
+
+	if (debug & DEBUG_I2C_READ)
+		deb_i2c_read("reg: 0x%04x, data: %*ph\n", reg, count, val);
+
+	return 0;
+}
+
+static int si2165_readreg8(struct si2165_state *state,
+		       const u16 reg, u8 *val)
+{
+	int ret;
+
+	ret = si2165_read(state, reg, val, 1);
+	deb_readreg("R(0x%04x)=0x%02x\n", reg, *val);
+	return ret;
+}
+
+static int si2165_readreg16(struct si2165_state *state,
+		       const u16 reg, u16 *val)
+{
+	u8 buf[2];
+
+	int ret = si2165_read(state, reg, buf, 2);
+	*val = buf[0] | buf[1] << 8;
+	deb_readreg("R(0x%04x)=0x%04x\n", reg, *val);
+	return ret;
+}
+
+static int si2165_writereg8(struct si2165_state *state, const u16 reg, u8 val)
+{
+	return si2165_write(state, reg, &val, 1);
+}
+
+static int si2165_writereg16(struct si2165_state *state, const u16 reg, u16 val)
+{
+	u8 buf[2] = { val & 0xff, (val >> 8) & 0xff };
+
+	return si2165_write(state, reg, buf, 2);
+}
+
+static int si2165_writereg24(struct si2165_state *state, const u16 reg, u32 val)
+{
+	u8 buf[3] = { val & 0xff, (val >> 8) & 0xff, (val >> 16) & 0xff };
+
+	return si2165_write(state, reg, buf, 3);
+}
+
+static int si2165_writereg32(struct si2165_state *state, const u16 reg, u32 val)
+{
+	u8 buf[4] = {
+		val & 0xff,
+		(val >> 8) & 0xff,
+		(val >> 16) & 0xff,
+		(val >> 24) & 0xff
+	};
+	return si2165_write(state, reg, buf, 4);
+}
+
+static int si2165_writereg_mask8(struct si2165_state *state, const u16 reg,
+				 u8 val, u8 mask)
+{
+	int ret;
+	u8 tmp;
+
+	if (mask != 0xff) {
+		ret = si2165_readreg8(state, reg, &tmp);
+		if (ret < 0)
+			goto err;
+
+		val &= mask;
+		tmp &= ~mask;
+		val |= tmp;
+	}
+
+	ret = si2165_writereg8(state, reg, val);
+err:
+	return ret;
+}
+
+static int si2165_get_tune_settings(struct dvb_frontend *fe,
+				    struct dvb_frontend_tune_settings *s)
+{
+	s->min_delay_ms = 1000;
+	return 0;
+}
+
+static int si2165_init_pll(struct si2165_state *state)
+{
+	u32 ref_freq_Hz = state->config.ref_freq_Hz;
+	u8 divr = 1; /* 1..7 */
+	u8 divp = 1; /* only 1 or 4 */
+	u8 divn = 56; /* 1..63 */
+	u8 divm = 8;
+	u8 divl = 12;
+	u8 buf[4];
+
+	/* hardcoded values can be deleted if calculation is verified
+	 * or it yields the same values as the windows driver */
+	switch (ref_freq_Hz) {
+	case 16000000u:
+		divn = 56;
+		break;
+	case 24000000u:
+		divr = 2;
+		divp = 4;
+		divn = 19;
+		break;
+	default:
+		/* ref_freq / divr must be between 4 and 16 MHz */
+		if (ref_freq_Hz > 16000000u)
+			divr = 2;
+
+		/* now select divn and divp such that
+		 * fvco is in 1624..1824 MHz */
+		if (1624000000u * divr > ref_freq_Hz * 2u * 63u)
+			divp = 4;
+
+		/* is this already correct regarding rounding? */
+		divn = 1624000000u * divr / (ref_freq_Hz * 2u * divp);
+		break;
+	}
+
+	/* adc_clk and sys_clk depend on xtal and pll settings */
+	state->fvco_hz = ref_freq_Hz / divr
+			* 2u * divn * divp;
+	state->adc_clk = state->fvco_hz / (divm * 4u);
+	state->sys_clk = state->fvco_hz / (divl * 2u);
+
+	/* write pll registers 0x00a0..0x00a3 at once */
+	buf[0] = divl;
+	buf[1] = divm;
+	buf[2] = (divn & 0x3f) | ((divp == 1) ? 0x40 : 0x00) | 0x80;
+	buf[3] = divr;
+	return si2165_write(state, 0x00a0, buf, 4);
+}
+
+static int si2165_adjust_pll_divl(struct si2165_state *state, u8 divl)
+{
+	state->sys_clk = state->fvco_hz / (divl * 2u);
+	return si2165_writereg8(state, 0x00a0, divl); /* pll_divl */
+}
+
+static u32 si2165_get_fe_clk(struct si2165_state *state)
+{
+	/* assume Oversampling mode Ovr4 is used */
+	return state->adc_clk;
+}
+
+static bool si2165_wait_init_done(struct si2165_state *state)
+{
+	int ret = -EINVAL;
+	u8 val = 0;
+	int i;
+
+	for (i = 0; i < 3; ++i) {
+		si2165_readreg8(state, 0x0054, &val);
+		if (val == 0x01)
+			return 0;
+		usleep_range(1000, 50000);
+	}
+	dev_err(&state->i2c->dev, "%s: init_done was not set\n",
+		KBUILD_MODNAME);
+	return ret;
+}
+
+static int si2165_upload_firmware_block(struct si2165_state *state,
+	const u8 *data, u32 len, u32 *poffset, u32 block_count)
+{
+	int ret;
+	u8 buf_ctrl[4] = { 0x00, 0x00, 0x00, 0xc0 };
+	u8 wordcount;
+	u32 cur_block = 0;
+	u32 offset = poffset ? *poffset : 0;
+
+	if (len < 4)
+		return -EINVAL;
+	if (len % 4 != 0)
+		return -EINVAL;
+
+	deb_fw_load("si2165_upload_firmware_block called with len=0x%x offset=0x%x blockcount=0x%x\n",
+				len, offset, block_count);
+	while (offset+12 <= len && cur_block < block_count) {
+		deb_fw_load("si2165_upload_firmware_block in while len=0x%x offset=0x%x cur_block=0x%x blockcount=0x%x\n",
+					len, offset, cur_block, block_count);
+		wordcount = data[offset];
+		if (wordcount < 1 || data[offset+1] ||
+		    data[offset+2] || data[offset+3]) {
+			dev_warn(&state->i2c->dev,
+				 "%s: bad fw data[0..3] = %*ph\n",
+				KBUILD_MODNAME, 4, data);
+			return -EINVAL;
+		}
+
+		if (offset + 8 + wordcount * 4 > len) {
+			dev_warn(&state->i2c->dev,
+				 "%s: len is too small for block len=%d, wordcount=%d\n",
+				KBUILD_MODNAME, len, wordcount);
+			return -EINVAL;
+		}
+
+		buf_ctrl[0] = wordcount - 1;
+
+		ret = si2165_write(state, 0x0364, buf_ctrl, 4);
+		if (ret < 0)
+			goto error;
+		ret = si2165_write(state, 0x0368, data+offset+4, 4);
+		if (ret < 0)
+			goto error;
+
+		offset += 8;
+
+		while (wordcount > 0) {
+			ret = si2165_write(state, 0x36c, data+offset, 4);
+			if (ret < 0)
+				goto error;
+			wordcount--;
+			offset += 4;
+		}
+		cur_block++;
+	}
+
+	deb_fw_load("si2165_upload_firmware_block after while len=0x%x offset=0x%x cur_block=0x%x blockcount=0x%x\n",
+				len, offset, cur_block, block_count);
+
+	if (poffset)
+		*poffset = offset;
+
+	deb_fw_load("si2165_upload_firmware_block returned offset=0x%x\n",
+				offset);
+
+	return 0;
+error:
+	return ret;
+}
+
+static int si2165_upload_firmware(struct si2165_state *state)
+{
+	/* int ret; */
+	u8 val[3];
+	u16 val16;
+	int ret;
+
+	const struct firmware *fw = NULL;
+	u8 *fw_file = SI2165_FIRMWARE;
+	const u8 *data;
+	u32 len;
+	u32 offset;
+	u8 patch_version;
+	u8 block_count;
+	u16 crc_expected;
+
+	/* request the firmware, this will block and timeout */
+	ret = request_firmware(&fw, fw_file, state->i2c->dev.parent);
+	if (ret) {
+		dev_warn(&state->i2c->dev, "%s: firmare file '%s' not found\n",
+				KBUILD_MODNAME, fw_file);
+		goto error;
+	}
+
+	data = fw->data;
+	len = fw->size;
+
+	dev_info(&state->i2c->dev, "%s: downloading firmware from file '%s' size=%d\n",
+			KBUILD_MODNAME, fw_file, len);
+
+	if (len % 4 != 0) {
+		dev_warn(&state->i2c->dev, "%s: firmware size is not multiple of 4\n",
+				KBUILD_MODNAME);
+		ret = -EINVAL;
+		goto error;
+	}
+
+	/* check header (8 bytes) */
+	if (len < 8) {
+		dev_warn(&state->i2c->dev, "%s: firmware header is missing\n",
+				KBUILD_MODNAME);
+		ret = -EINVAL;
+		goto error;
+	}
+
+	if (data[0] != 1 || data[1] != 0) {
+		dev_warn(&state->i2c->dev, "%s: firmware file version is wrong\n",
+				KBUILD_MODNAME);
+		ret = -EINVAL;
+		goto error;
+	}
+
+	patch_version = data[2];
+	block_count = data[4];
+	crc_expected = data[7] << 8 | data[6];
+
+	/* start uploading fw */
+	/* boot/wdog status */
+	ret = si2165_writereg8(state, 0x0341, 0x00);
+	if (ret < 0)
+		goto error;
+	/* reset */
+	ret = si2165_writereg8(state, 0x00c0, 0x00);
+	if (ret < 0)
+		goto error;
+	/* boot/wdog status */
+	ret = si2165_readreg8(state, 0x0341, val);
+	if (ret < 0)
+		goto error;
+
+	/* enable reset on error */
+	ret = si2165_readreg8(state, 0x035c, val);
+	if (ret < 0)
+		goto error;
+	ret = si2165_readreg8(state, 0x035c, val);
+	if (ret < 0)
+		goto error;
+	ret = si2165_writereg8(state, 0x035c, 0x02);
+	if (ret < 0)
+		goto error;
+
+	/* start right after the header */
+	offset = 8;
+
+	dev_info(&state->i2c->dev, "%s: si2165_upload_firmware extracted patch_version=0x%02x, block_count=0x%02x, crc_expected=0x%04x\n",
+		KBUILD_MODNAME, patch_version, block_count, crc_expected);
+
+	ret = si2165_upload_firmware_block(state, data, len, &offset, 1);
+	if (ret < 0)
+		goto error;
+
+	ret = si2165_writereg8(state, 0x0344, patch_version);
+	if (ret < 0)
+		goto error;
+
+	/* reset crc */
+	ret = si2165_writereg8(state, 0x0379, 0x01);
+	if (ret)
+		return ret;
+
+	ret = si2165_upload_firmware_block(state, data, len,
+					   &offset, block_count);
+	if (ret < 0) {
+		dev_err(&state->i2c->dev,
+			"%s: firmare could not be uploaded\n",
+			KBUILD_MODNAME);
+		goto error;
+	}
+
+	/* read crc */
+	ret = si2165_readreg16(state, 0x037a, &val16);
+	if (ret)
+		goto error;
+
+	if (val16 != crc_expected) {
+		dev_err(&state->i2c->dev,
+			"%s: firmware crc mismatch %04x != %04x\n",
+			KBUILD_MODNAME, val16, crc_expected);
+		ret = -EINVAL;
+		goto error;
+	}
+
+	ret = si2165_upload_firmware_block(state, data, len, &offset, 5);
+	if (ret)
+		goto error;
+
+	if (len != offset) {
+		dev_err(&state->i2c->dev,
+			"%s: firmare len mismatch %04x != %04x\n",
+			KBUILD_MODNAME, len, offset);
+		ret = -EINVAL;
+		goto error;
+	}
+
+	/* reset watchdog error register */
+	ret = si2165_writereg_mask8(state, 0x0341, 0x02, 0x02);
+	if (ret < 0)
+		goto error;
+
+	/* enable reset on error */
+	ret = si2165_writereg_mask8(state, 0x035c, 0x01, 0x01);
+	if (ret < 0)
+		goto error;
+
+	dev_info(&state->i2c->dev, "%s: fw load finished\n", KBUILD_MODNAME);
+
+	ret = 0;
+	state->firmware_loaded = true;
+error:
+	if (fw) {
+		release_firmware(fw);
+		fw = NULL;
+	}
+
+	return ret;
+}
+
+static int si2165_init(struct dvb_frontend *fe)
+{
+	int ret = 0;
+	struct si2165_state *state = fe->demodulator_priv;
+	u8 val;
+	u8 patch_version = 0x00;
+
+	dprintk("%s: called\n", __func__);
+
+	/* powerup */
+	ret = si2165_writereg8(state, 0x0000, state->config.chip_mode);
+	if (ret < 0)
+		goto error;
+	/* dsp_clock_enable */
+	ret = si2165_writereg8(state, 0x0104, 0x01);
+	if (ret < 0)
+		goto error;
+	ret = si2165_readreg8(state, 0x0000, &val); /* verify chip_mode */
+	if (ret < 0)
+		goto error;
+	if (val != state->config.chip_mode) {
+		dev_err(&state->i2c->dev, "%s: could not set chip_mode\n",
+			KBUILD_MODNAME);
+		return -EINVAL;
+	}
+
+	/* agc */
+	ret = si2165_writereg8(state, 0x018b, 0x00);
+	if (ret < 0)
+		goto error;
+	ret = si2165_writereg8(state, 0x0190, 0x01);
+	if (ret < 0)
+		goto error;
+	ret = si2165_writereg8(state, 0x0170, 0x00);
+	if (ret < 0)
+		goto error;
+	ret = si2165_writereg8(state, 0x0171, 0x07);
+	if (ret < 0)
+		goto error;
+	/* rssi pad */
+	ret = si2165_writereg8(state, 0x0646, 0x00);
+	if (ret < 0)
+		goto error;
+	ret = si2165_writereg8(state, 0x0641, 0x00);
+	if (ret < 0)
+		goto error;
+
+	ret = si2165_init_pll(state);
+	if (ret < 0)
+		goto error;
+
+	/* enable chip_init */
+	ret = si2165_writereg8(state, 0x0050, 0x01);
+	if (ret < 0)
+		goto error;
+	/* set start_init */
+	ret = si2165_writereg8(state, 0x0096, 0x01);
+	if (ret < 0)
+		goto error;
+	ret = si2165_wait_init_done(state);
+	if (ret < 0)
+		goto error;
+
+	/* disable chip_init */
+	ret = si2165_writereg8(state, 0x0050, 0x00);
+	if (ret < 0)
+		goto error;
+
+	/* ber_pkt */
+	ret = si2165_writereg16(state, 0x0470 , 0x7530);
+	if (ret < 0)
+		goto error;
+
+	ret = si2165_readreg8(state, 0x0344, &patch_version);
+	if (ret < 0)
+		goto error;
+
+	ret = si2165_writereg8(state, 0x00cb, 0x00);
+	if (ret < 0)
+		goto error;
+
+	/* dsp_addr_jump */
+	ret = si2165_writereg32(state, 0x0348, 0xf4000000);
+	if (ret < 0)
+		goto error;
+	/* boot/wdog status */
+	ret = si2165_readreg8(state, 0x0341, &val);
+	if (ret < 0)
+		goto error;
+
+	if (patch_version == 0x00) {
+		ret = si2165_upload_firmware(state);
+		if (ret < 0)
+			goto error;
+	}
+
+	/* write adc values after each reset*/
+	ret = si2165_writereg8(state, 0x012a, 0x46);
+	if (ret < 0)
+		goto error;
+	ret = si2165_writereg8(state, 0x012c, 0x00);
+	if (ret < 0)
+		goto error;
+	ret = si2165_writereg8(state, 0x012e, 0x0a);
+	if (ret < 0)
+		goto error;
+	ret = si2165_writereg8(state, 0x012f, 0xff);
+	if (ret < 0)
+		goto error;
+	ret = si2165_writereg8(state, 0x0123, 0x70);
+	if (ret < 0)
+		goto error;
+
+	return 0;
+error:
+	return ret;
+}
+
+static int si2165_sleep(struct dvb_frontend *fe)
+{
+	int ret;
+	struct si2165_state *state = fe->demodulator_priv;
+
+	/* dsp clock disable */
+	ret = si2165_writereg8(state, 0x0104, 0x00);
+	if (ret < 0)
+		return ret;
+	/* chip mode */
+	ret = si2165_writereg8(state, 0x0000, SI2165_MODE_OFF);
+	if (ret < 0)
+		return ret;
+	return 0;
+}
+
+static int si2165_read_status(struct dvb_frontend *fe, fe_status_t *status)
+{
+	int ret;
+	u8 fec_lock = 0;
+	struct si2165_state *state = fe->demodulator_priv;
+
+	if (!state->has_dvbt)
+		return -EINVAL;
+
+	/* check fec_lock */
+	ret = si2165_readreg8(state, 0x4e0, &fec_lock);
+	if (ret < 0)
+		return ret;
+	*status = 0;
+	if (fec_lock & 0x01) {
+		*status |= FE_HAS_SIGNAL;
+		*status |= FE_HAS_CARRIER;
+		*status |= FE_HAS_VITERBI;
+		*status |= FE_HAS_SYNC;
+		*status |= FE_HAS_LOCK;
+	}
+
+	return 0;
+}
+
+static int si2165_set_oversamp(struct si2165_state *state, u32 dvb_rate)
+{
+	u64 oversamp;
+	u32 reg_value;
+
+	oversamp = si2165_get_fe_clk(state);
+	oversamp <<= 23;
+	do_div(oversamp, dvb_rate);
+	reg_value = oversamp & 0x3fffffff;
+
+	/* oversamp, usbdump contained 0x03100000; */
+	return si2165_writereg32(state, 0x00e4, reg_value);
+}
+
+static int si2165_set_if_freq_shift(struct si2165_state *state, u32 IF)
+{
+	u64 if_freq_shift;
+	s32 reg_value = 0;
+	u32 fe_clk = si2165_get_fe_clk(state);
+
+	if_freq_shift = IF;
+	if_freq_shift <<= 29;
+
+	do_div(if_freq_shift, fe_clk);
+	reg_value = (s32)if_freq_shift;
+
+	if (state->config.inversion)
+		reg_value = -reg_value;
+
+	reg_value = reg_value & 0x1fffffff;
+
+	/* if_freq_shift, usbdump contained 0x023ee08f; */
+	return si2165_writereg32(state, 0x00e8, reg_value);
+}
+
+static int si2165_set_parameters(struct dvb_frontend *fe)
+{
+	int ret;
+	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
+	struct si2165_state *state = fe->demodulator_priv;
+	u8 val[3];
+	u32 IF;
+	u32 dvb_rate = 0;
+	u16 bw10k;
+
+	dprintk("%s: called\n", __func__);
+
+	if (!fe->ops.tuner_ops.get_if_frequency) {
+		dev_err(&state->i2c->dev,
+			"%s: Error: get_if_frequency() not defined at tuner. Can't work without it!\n",
+			KBUILD_MODNAME);
+		return -EINVAL;
+	}
+
+	if (!state->has_dvbt)
+		return -EINVAL;
+
+	if (p->bandwidth_hz > 0) {
+		dvb_rate = p->bandwidth_hz * 8 / 7;
+		bw10k = p->bandwidth_hz / 10000;
+	} else {
+		dvb_rate = 8 * 8 / 7;
+		bw10k = 800;
+	}
+
+	/* standard = DVB-T */
+	ret = si2165_writereg8(state, 0x00ec, 0x01);
+	if (ret < 0)
+		return ret;
+	ret = si2165_adjust_pll_divl(state, 12);
+	if (ret < 0)
+		return ret;
+
+	fe->ops.tuner_ops.get_if_frequency(fe, &IF);
+	ret = si2165_set_if_freq_shift(state, IF);
+	if (ret < 0)
+		return ret;
+	ret = si2165_writereg8(state, 0x08f8, 0x00);
+	if (ret < 0)
+		return ret;
+	/* ts output config */
+	ret = si2165_writereg8(state, 0x04e4, 0x20);
+	if (ret < 0)
+		return ret;
+	ret = si2165_writereg16(state, 0x04ef, 0x00fe);
+	if (ret < 0)
+		return ret;
+	ret = si2165_writereg24(state, 0x04f4, 0x555555);
+	if (ret < 0)
+		return ret;
+	ret = si2165_writereg8(state, 0x04e5, 0x01);
+	if (ret < 0)
+		return ret;
+	/* bandwidth in 10KHz steps */
+	ret = si2165_writereg16(state, 0x0308, bw10k);
+	if (ret < 0)
+		return ret;
+	ret = si2165_set_oversamp(state, dvb_rate);
+	if (ret < 0)
+		return ret;
+	/* impulsive_noise_remover */
+	ret = si2165_writereg8(state, 0x031c, 0x01);
+	if (ret < 0)
+		return ret;
+	ret = si2165_writereg8(state, 0x00cb, 0x00);
+	if (ret < 0)
+		return ret;
+	/* agc2 */
+	ret = si2165_writereg8(state, 0x016e, 0x41);
+	if (ret < 0)
+		return ret;
+	ret = si2165_writereg8(state, 0x016c, 0x0e);
+	if (ret < 0)
+		return ret;
+	ret = si2165_writereg8(state, 0x016d, 0x10);
+	if (ret < 0)
+		return ret;
+	/* agc */
+	ret = si2165_writereg8(state, 0x015b, 0x03);
+	if (ret < 0)
+		return ret;
+	ret = si2165_writereg8(state, 0x0150, 0x78);
+	if (ret < 0)
+		return ret;
+	/* agc */
+	ret = si2165_writereg8(state, 0x01a0, 0x78);
+	if (ret < 0)
+		return ret;
+	ret = si2165_writereg8(state, 0x01c8, 0x68);
+	if (ret < 0)
+		return ret;
+	/* freq_sync_range */
+	ret = si2165_writereg16(state, 0x030c, 0x0064);
+	if (ret < 0)
+		return ret;
+	/* gp_reg0 */
+	ret = si2165_readreg8(state, 0x0387, val);
+	if (ret < 0)
+		return ret;
+	ret = si2165_writereg8(state, 0x0387, 0x00);
+	if (ret < 0)
+		return ret;
+	/* dsp_addr_jump */
+	ret = si2165_writereg32(state, 0x0348, 0xf4000000);
+	if (ret < 0)
+		return ret;
+
+	if (fe->ops.tuner_ops.set_params)
+		fe->ops.tuner_ops.set_params(fe);
+
+	/* recalc if_freq_shift if IF might has changed */
+	fe->ops.tuner_ops.get_if_frequency(fe, &IF);
+	ret = si2165_set_if_freq_shift(state, IF);
+	if (ret < 0)
+		return ret;
+
+	/* boot/wdog status */
+	ret = si2165_readreg8(state, 0x0341, val);
+	if (ret < 0)
+		return ret;
+	ret = si2165_writereg8(state, 0x0341, 0x00);
+	if (ret < 0)
+		return ret;
+	/* reset all */
+	ret = si2165_writereg8(state, 0x00c0, 0x00);
+	if (ret < 0)
+		return ret;
+	/* gp_reg0 */
+	ret = si2165_writereg32(state, 0x0384, 0x00000000);
+	if (ret < 0)
+		return ret;
+	/* start_synchro */
+	ret = si2165_writereg8(state, 0x02e0, 0x01);
+	if (ret < 0)
+		return ret;
+	/* boot/wdog status */
+	ret = si2165_readreg8(state, 0x0341, val);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static void si2165_release(struct dvb_frontend *fe)
+{
+	struct si2165_state *state = fe->demodulator_priv;
+
+	dprintk("%s: called\n", __func__);
+	kfree(state);
+}
+
+static struct dvb_frontend_ops si2165_ops = {
+	.info = {
+		.name = "Silicon Labs Si2165",
+		.caps =	FE_CAN_FEC_1_2 |
+			FE_CAN_FEC_2_3 |
+			FE_CAN_FEC_3_4 |
+			FE_CAN_FEC_5_6 |
+			FE_CAN_FEC_7_8 |
+			FE_CAN_FEC_AUTO |
+			FE_CAN_QPSK |
+			FE_CAN_QAM_16 |
+			FE_CAN_QAM_32 |
+			FE_CAN_QAM_64 |
+			FE_CAN_QAM_128 |
+			FE_CAN_QAM_256 |
+			FE_CAN_QAM_AUTO |
+			FE_CAN_TRANSMISSION_MODE_AUTO |
+			FE_CAN_GUARD_INTERVAL_AUTO |
+			FE_CAN_HIERARCHY_AUTO |
+			FE_CAN_MUTE_TS |
+			FE_CAN_TRANSMISSION_MODE_AUTO |
+			FE_CAN_RECOVER
+	},
+
+	.get_tune_settings = si2165_get_tune_settings,
+
+	.init = si2165_init,
+	.sleep = si2165_sleep,
+
+	.set_frontend      = si2165_set_parameters,
+	.read_status       = si2165_read_status,
+
+	.release = si2165_release,
+};
+
+struct dvb_frontend *si2165_attach(const struct si2165_config *config,
+				   struct i2c_adapter *i2c)
+{
+	struct si2165_state *state = NULL;
+	int n;
+	int io_ret;
+	u8 val;
+
+	if (config == NULL || i2c == NULL)
+		goto error;
+
+	/* allocate memory for the internal state */
+	state = kzalloc(sizeof(struct si2165_state), GFP_KERNEL);
+	if (state == NULL)
+		goto error;
+
+	/* setup the state */
+	state->i2c = i2c;
+	state->config = *config;
+
+	if (state->config.ref_freq_Hz < 4000000
+	    || state->config.ref_freq_Hz > 27000000) {
+		dev_err(&state->i2c->dev, "%s: ref_freq of %d Hz not supported by this driver\n",
+			 KBUILD_MODNAME, state->config.ref_freq_Hz);
+		goto error;
+	}
+
+	/* create dvb_frontend */
+	memcpy(&state->frontend.ops, &si2165_ops,
+		sizeof(struct dvb_frontend_ops));
+	state->frontend.demodulator_priv = state;
+
+	/* powerup */
+	io_ret = si2165_writereg8(state, 0x0000, state->config.chip_mode);
+	if (io_ret < 0)
+		goto error;
+
+	io_ret = si2165_readreg8(state, 0x0000, &val);
+	if (io_ret < 0)
+		goto error;
+	if (val != state->config.chip_mode)
+		goto error;
+
+	io_ret = si2165_readreg8(state, 0x0023 , &state->revcode);
+	if (io_ret < 0)
+		goto error;
+
+	io_ret = si2165_readreg8(state, 0x0118, &state->chip_type);
+	if (io_ret < 0)
+		goto error;
+
+	/* powerdown */
+	io_ret = si2165_writereg8(state, 0x0000, SI2165_MODE_OFF);
+	if (io_ret < 0)
+		goto error;
+
+	dev_info(&state->i2c->dev, "%s: hardware revision 0x%02x, chip type 0x%02x\n",
+		 KBUILD_MODNAME, state->revcode, state->chip_type);
+
+	/* It is a guess that register 0x0118 (chip type?) can be used to
+	 * differ between si2161, si2163 and si2165
+	 * Only si2165 has been tested.
+	 */
+	if (state->revcode == 0x03 && state->chip_type == 0x07) {
+		state->has_dvbt = true;
+		state->has_dvbc = true;
+	} else {
+		dev_err(&state->i2c->dev, "%s: Unsupported chip.\n",
+			KBUILD_MODNAME);
+		goto error;
+	}
+
+	n = 0;
+	if (state->has_dvbt) {
+		state->frontend.ops.delsys[n++] = SYS_DVBT;
+		strlcat(state->frontend.ops.info.name, " DVB-T",
+			sizeof(state->frontend.ops.info.name));
+	}
+	if (state->has_dvbc)
+		dev_warn(&state->i2c->dev, "%s: DVB-C is not yet supported.\n",
+		       KBUILD_MODNAME);
+
+	return &state->frontend;
+
+error:
+	kfree(state);
+	return NULL;
+}
+EXPORT_SYMBOL(si2165_attach);
+
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
+
+MODULE_DESCRIPTION("Silicon Labs Si2165 DVB-C/-T Demodulator driver");
+MODULE_AUTHOR("Matthias Schwarzott <zzam@gentoo.org>");
+MODULE_LICENSE("GPL");
+MODULE_FIRMWARE(SI2165_FIRMWARE);
diff --git a/drivers/media/dvb-frontends/si2165.h b/drivers/media/dvb-frontends/si2165.h
new file mode 100644
index 0000000..7a6b59d
--- /dev/null
+++ b/drivers/media/dvb-frontends/si2165.h
@@ -0,0 +1,64 @@
+/*
+    Driver for Silicon Labs SI2165 DVB-C/-T Demodulator
+
+    Copyright (C) 2013-2014 Matthias Schwarzott <zzam@gentoo.org>
+
+    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.
+
+    References:
+    http://www.silabs.com/Support%20Documents/TechnicalDocs/Si2165-short.pdf
+*/
+
+#ifndef _DVB_SI2165_H
+#define _DVB_SI2165_H
+
+#include <linux/dvb/frontend.h>
+
+#if IS_ENABLED(CONFIG_DVB_SI2165)
+
+enum {
+	SI2165_MODE_OFF = 0x00,
+	SI2165_MODE_PLL_EXT = 0x20,
+	SI2165_MODE_PLL_XTAL = 0x21
+};
+
+struct si2165_config {
+	/* i2c addr
+	 * possible values: 0x64,0x65,0x66,0x67 */
+	u8 i2c_addr;
+
+	/* external clock or XTAL */
+	u8 chip_mode;
+
+	/* frequency of external clock or xtal in Hz
+	 * possible values: 4000000, 16000000, 20000000, 240000000, 27000000
+	 */
+	u32 ref_freq_Hz;
+
+	/* invert the spectrum */
+	bool inversion;
+};
+
+/* Addresses: 0x64,0x65,0x66,0x67 */
+struct dvb_frontend *si2165_attach(
+	const struct si2165_config *config,
+	struct i2c_adapter *i2c);
+#else
+static inline struct dvb_frontend *si2165_attach(
+	const struct si2165_config *config,
+	struct i2c_adapter *i2c)
+{
+	pr_warn("%s: driver disabled by Kconfig\n", __func__);
+	return NULL;
+}
+#endif /* CONFIG_DVB_SI2165 */
+
+#endif /* _DVB_SI2165_H */
diff --git a/drivers/media/dvb-frontends/si2165_priv.h b/drivers/media/dvb-frontends/si2165_priv.h
new file mode 100644
index 0000000..d4cc93f
--- /dev/null
+++ b/drivers/media/dvb-frontends/si2165_priv.h
@@ -0,0 +1,23 @@
+/*
+    Driver for Silicon Labs SI2165 DVB-C/-T Demodulator
+
+    Copyright (C) 2013-2014 Matthias Schwarzott <zzam@gentoo.org>
+
+    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.
+
+*/
+
+#ifndef _DVB_SI2165_PRIV
+#define _DVB_SI2165_PRIV
+
+#define SI2165_FIRMWARE "dvb-demod-si2165.fw"
+
+#endif /* _DVB_SI2165_PRIV */
-- 
2.0.0


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

* [PATCH 3/8] cx23885: Add si2165 support for HVR-5500
  2014-07-22 20:12 [PATCH 0/8] add si2165 demod driver Matthias Schwarzott
  2014-07-22 20:12 ` [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165 Matthias Schwarzott
  2014-07-22 20:12 ` [PATCH 2/8] si2165: Add demod driver for DVB-T only Matthias Schwarzott
@ 2014-07-22 20:12 ` Matthias Schwarzott
  2014-07-22 20:12 ` [PATCH 4/8] cx231xx: prepare for i2c_client attachment Matthias Schwarzott
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-22 20:12 UTC (permalink / raw)
  To: crope, m.chehab, linux-media; +Cc: Matthias Schwarzott

The same card entry is used for HVR-4400 and HVR-5500.
Only HVR-5500 has been tested.

Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
 drivers/media/pci/cx23885/Kconfig         |  1 +
 drivers/media/pci/cx23885/cx23885-cards.c | 17 +++++++++---
 drivers/media/pci/cx23885/cx23885-dvb.c   | 43 +++++++++++++++++++++++++++----
 3 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/drivers/media/pci/cx23885/Kconfig b/drivers/media/pci/cx23885/Kconfig
index d1dcb1d..6cd1db2 100644
--- a/drivers/media/pci/cx23885/Kconfig
+++ b/drivers/media/pci/cx23885/Kconfig
@@ -31,6 +31,7 @@ config VIDEO_CX23885
 	select DVB_TDA10071 if MEDIA_SUBDRV_AUTOSELECT
 	select DVB_A8293 if MEDIA_SUBDRV_AUTOSELECT
 	select DVB_MB86A20S if MEDIA_SUBDRV_AUTOSELECT
+	select DVB_SI2165 if MEDIA_SUBDRV_AUTOSELECT
 	select MEDIA_TUNER_MT2063 if MEDIA_SUBDRV_AUTOSELECT
 	select MEDIA_TUNER_MT2131 if MEDIA_SUBDRV_AUTOSELECT
 	select MEDIA_TUNER_XC2028 if MEDIA_SUBDRV_AUTOSELECT
diff --git a/drivers/media/pci/cx23885/cx23885-cards.c b/drivers/media/pci/cx23885/cx23885-cards.c
index 9723067..e63d447 100644
--- a/drivers/media/pci/cx23885/cx23885-cards.c
+++ b/drivers/media/pci/cx23885/cx23885-cards.c
@@ -619,7 +619,12 @@ struct cx23885_board cx23885_boards[] = {
 	},
 	[CX23885_BOARD_HAUPPAUGE_HVR4400] = {
 		.name		= "Hauppauge WinTV-HVR4400",
+		.porta		= CX23885_ANALOG_VIDEO,
 		.portb		= CX23885_MPEG_DVB,
+		.portc		= CX23885_MPEG_DVB,
+		.tuner_type	= TUNER_NXP_TDA18271,
+		.tuner_addr	= 0x60, /* 0xc0 >> 1 */
+		.tuner_bus	= 1,
 	},
 	[CX23885_BOARD_AVERMEDIA_HC81R] = {
 		.name		= "AVerTV Hybrid Express Slim HC81R",
@@ -1475,13 +1480,16 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
 		break;
 	case CX23885_BOARD_HAUPPAUGE_HVR4400:
 		/* GPIO-8 tda10071 demod reset */
+		/* GPIO-9 si2165 demod reset */
 
 		/* Put the parts into reset and back */
-		cx23885_gpio_enable(dev, GPIO_8, 1);
-		cx23885_gpio_clear(dev, GPIO_8);
+		cx23885_gpio_enable(dev, GPIO_8 | GPIO_9, 1);
+
+		cx23885_gpio_clear(dev, GPIO_8 | GPIO_9);
 		mdelay(100);
-		cx23885_gpio_set(dev, GPIO_8);
+		cx23885_gpio_set(dev, GPIO_8 | GPIO_9);
 		mdelay(100);
+
 		break;
 	case CX23885_BOARD_AVERMEDIA_HC81R:
 		cx_clear(MC417_CTL, 1);
@@ -1826,6 +1834,9 @@ void cx23885_card_setup(struct cx23885_dev *dev)
 		ts1->gen_ctrl_val  = 0xc; /* Serial bus + punctured clock */
 		ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */
 		ts1->src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
+		ts2->gen_ctrl_val  = 0xc; /* Serial bus + punctured clock */
+		ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
+		ts2->src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
 		break;
 	case CX23885_BOARD_HAUPPAUGE_HVR1250:
 	case CX23885_BOARD_HAUPPAUGE_HVR1500:
diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c
index d037459..4822776 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -71,6 +71,7 @@
 #include "tda10071.h"
 #include "a8293.h"
 #include "mb86a20s.h"
+#include "si2165.h"
 
 static unsigned int debug;
 
@@ -302,6 +303,11 @@ static struct tda18271_config hauppauge_hvr1210_tuner_config = {
 	.output_opt = TDA18271_OUTPUT_LT_OFF,
 };
 
+static struct tda18271_config hauppauge_hvr4400_tuner_config = {
+	.gate    = TDA18271_GATE_DIGITAL,
+	.output_opt = TDA18271_OUTPUT_LT_OFF,
+};
+
 static struct tda18271_std_map hauppauge_hvr127x_std_map = {
 	.atsc_6   = { .if_freq = 3250, .agc_mode = 3, .std = 4,
 		      .if_lvl = 1, .rfagc_top = 0x58 },
@@ -702,6 +708,12 @@ static const struct a8293_config hauppauge_a8293_config = {
 	.i2c_addr = 0x0b,
 };
 
+static const struct si2165_config hauppauge_hvr4400_si2165_config = {
+	.i2c_addr	= 0x64,
+	.chip_mode	= SI2165_MODE_PLL_XTAL,
+	.ref_freq_Hz	= 16000000,
+};
+
 static int netup_altera_fpga_rw(void *device, int flag, int data, int read)
 {
 	struct cx23885_dev *dev = (struct cx23885_dev *)device;
@@ -1335,13 +1347,34 @@ static int dvb_register(struct cx23885_tsport *port)
 		break;
 	case CX23885_BOARD_HAUPPAUGE_HVR4400:
 		i2c_bus = &dev->i2c_bus[0];
-		fe0->dvb.frontend = dvb_attach(tda10071_attach,
+		i2c_bus2 = &dev->i2c_bus[1];
+		switch (port->nr) {
+		/* port b */
+		case 1:
+			fe0->dvb.frontend = dvb_attach(tda10071_attach,
 						&hauppauge_tda10071_config,
 						&i2c_bus->i2c_adap);
-		if (fe0->dvb.frontend != NULL) {
-			dvb_attach(a8293_attach, fe0->dvb.frontend,
-				   &i2c_bus->i2c_adap,
-				   &hauppauge_a8293_config);
+			if (fe0->dvb.frontend != NULL) {
+				if (!dvb_attach(a8293_attach, fe0->dvb.frontend,
+						&i2c_bus->i2c_adap,
+						&hauppauge_a8293_config))
+					goto frontend_detach;
+			}
+			break;
+		/* port c */
+		case 2:
+			fe0->dvb.frontend = dvb_attach(si2165_attach,
+					&hauppauge_hvr4400_si2165_config,
+					&i2c_bus->i2c_adap);
+			if (fe0->dvb.frontend != NULL) {
+				fe0->dvb.frontend->ops.i2c_gate_ctrl = 0;
+				if (!dvb_attach(tda18271_attach,
+						fe0->dvb.frontend,
+						0x60, &i2c_bus2->i2c_adap,
+					  &hauppauge_hvr4400_tuner_config))
+					goto frontend_detach;
+			}
+			break;
 		}
 		break;
 	default:
-- 
2.0.0


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

* [PATCH 4/8] cx231xx: prepare for i2c_client attachment
  2014-07-22 20:12 [PATCH 0/8] add si2165 demod driver Matthias Schwarzott
                   ` (2 preceding siblings ...)
  2014-07-22 20:12 ` [PATCH 3/8] cx23885: Add si2165 support for HVR-5500 Matthias Schwarzott
@ 2014-07-22 20:12 ` Matthias Schwarzott
  2014-07-22 20:12 ` [PATCH 5/8] cx231xx: Add digital support for [2040:b130] Hauppauge WinTV 930C-HD (model 1113xx) Matthias Schwarzott
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-22 20:12 UTC (permalink / raw)
  To: crope, m.chehab, linux-media; +Cc: Matthias Schwarzott

This is needed to support PCTV QuatroStick 522e which uses a si2157.
The si2157 driver is written using i2c_client attachment.

Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
 drivers/media/usb/cx231xx/cx231xx-dvb.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 4504bc6..5c69be7 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -67,6 +67,7 @@ struct cx231xx_dvb {
 	struct dmx_frontend fe_hw;
 	struct dmx_frontend fe_mem;
 	struct dvb_net net;
+	struct i2c_client *i2c_client_tuner;
 };
 
 static struct s5h1432_config dvico_s5h1432_config = {
@@ -549,11 +550,18 @@ fail_adapter:
 
 static void unregister_dvb(struct cx231xx_dvb *dvb)
 {
+	struct i2c_client *client;
 	dvb_net_release(&dvb->net);
 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
 	dvb_dmxdev_release(&dvb->dmxdev);
 	dvb_dmx_release(&dvb->demux);
+	client = dvb->i2c_client_tuner;
+	/* remove I2C tuner */
+	if (client) {
+		module_put(client->dev.driver->owner);
+		i2c_unregister_device(client);
+	}
 	dvb_unregister_frontend(dvb->frontend);
 	dvb_frontend_detach(dvb->frontend);
 	dvb_unregister_adapter(&dvb->adapter);
-- 
2.0.0


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

* [PATCH 5/8] cx231xx: Add digital support for [2040:b130] Hauppauge WinTV 930C-HD (model 1113xx)
  2014-07-22 20:12 [PATCH 0/8] add si2165 demod driver Matthias Schwarzott
                   ` (3 preceding siblings ...)
  2014-07-22 20:12 ` [PATCH 4/8] cx231xx: prepare for i2c_client attachment Matthias Schwarzott
@ 2014-07-22 20:12 ` Matthias Schwarzott
  2014-07-22 20:12 ` [PATCH 6/8] cx231xx: Add digital support for [2040:b131] Hauppauge WinTV 930C-HD (model 1114xx) Matthias Schwarzott
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-22 20:12 UTC (permalink / raw)
  To: crope, m.chehab, linux-media; +Cc: Matthias Schwarzott

After loading the driver the first open to dvb device node fails.

Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
 drivers/media/usb/cx231xx/Kconfig          |  1 +
 drivers/media/usb/cx231xx/cx231xx-avcore.c |  1 +
 drivers/media/usb/cx231xx/cx231xx-cards.c  | 92 ++++++++++++++++++++++++++++++
 drivers/media/usb/cx231xx/cx231xx-core.c   |  3 +
 drivers/media/usb/cx231xx/cx231xx-dvb.c    | 34 +++++++++++
 drivers/media/usb/cx231xx/cx231xx.h        |  1 +
 6 files changed, 132 insertions(+)

diff --git a/drivers/media/usb/cx231xx/Kconfig b/drivers/media/usb/cx231xx/Kconfig
index f14c5e8..036454e 100644
--- a/drivers/media/usb/cx231xx/Kconfig
+++ b/drivers/media/usb/cx231xx/Kconfig
@@ -47,6 +47,7 @@ config VIDEO_CX231XX_DVB
 	select DVB_MB86A20S if MEDIA_SUBDRV_AUTOSELECT
 	select DVB_LGDT3305 if MEDIA_SUBDRV_AUTOSELECT
 	select DVB_TDA18271C2DD if MEDIA_SUBDRV_AUTOSELECT
+	select DVB_SI2165 if MEDIA_SUBDRV_AUTOSELECT
 
 	---help---
 	  This adds support for DVB cards based on the
diff --git a/drivers/media/usb/cx231xx/cx231xx-avcore.c b/drivers/media/usb/cx231xx/cx231xx-avcore.c
index 89de00b..a428c10 100644
--- a/drivers/media/usb/cx231xx/cx231xx-avcore.c
+++ b/drivers/media/usb/cx231xx/cx231xx-avcore.c
@@ -352,6 +352,7 @@ int cx231xx_afe_update_power_control(struct cx231xx *dev,
 	case CX231XX_BOARD_CNXT_RDU_253S:
 	case CX231XX_BOARD_CNXT_VIDEO_GRABBER:
 	case CX231XX_BOARD_HAUPPAUGE_EXETER:
+	case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
 	case CX231XX_BOARD_HAUPPAUGE_USBLIVE2:
 	case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
 	case CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL:
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 2ee03e4..8b80f88 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -704,6 +704,45 @@ struct cx231xx_board cx231xx_boards[] = {
 			}
 		},
 	},
+	[CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx] = {
+		.name = "Hauppauge WinTV 930C-HD (1113xx)",
+		.tuner_type = TUNER_NXP_TDA18271,
+		.tuner_addr = 0x60,
+		.tuner_gpio = RDE250_XCV_TUNER,
+		.tuner_sif_gpio = 0x05,
+		.tuner_scl_gpio = 0x1a,
+		.tuner_sda_gpio = 0x1b,
+		.decoder = CX231XX_AVDECODER,
+		.output_mode = OUT_MODE_VIP11,
+		.demod_xfer_mode = 0,
+		.ctl_pin_status_mask = 0xFFFFFFC4,
+		.agc_analog_digital_select_gpio = 0x0c,
+		.gpio_pin_status_mask = 0x4001000,
+		.tuner_i2c_master = 1,
+		.demod_i2c_master = 2,
+		.has_dvb = 1,
+		.demod_addr = 0x0e,
+		.norm = V4L2_STD_PAL,
+
+		.input = {{
+			.type = CX231XX_VMUX_TELEVISION,
+			.vmux = CX231XX_VIN_3_1,
+			.amux = CX231XX_AMUX_VIDEO,
+			.gpio = NULL,
+		}, {
+			.type = CX231XX_VMUX_COMPOSITE1,
+			.vmux = CX231XX_VIN_2_1,
+			.amux = CX231XX_AMUX_LINE_IN,
+			.gpio = NULL,
+		}, {
+			.type = CX231XX_VMUX_SVIDEO,
+			.vmux = CX231XX_VIN_1_1 |
+				(CX231XX_VIN_1_2 << 8) |
+				CX25840_SVIDEO_ON,
+			.amux = CX231XX_AMUX_LINE_IN,
+			.gpio = NULL,
+		} },
+	},
 };
 const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
 
@@ -733,6 +772,8 @@ struct usb_device_id cx231xx_id_table[] = {
 	 .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC},
 	{USB_DEVICE(0x2040, 0xb120),
 	 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
+	{USB_DEVICE(0x2040, 0xb130),
+	 .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx},
 	{USB_DEVICE(0x2040, 0xb140),
 	 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
 	{USB_DEVICE(0x2040, 0xc200),
@@ -886,6 +927,43 @@ static void cx231xx_config_tuner(struct cx231xx *dev)
 
 }
 
+static int read_eeprom(struct cx231xx *dev, u8 *eedata, int len)
+{
+	int ret = 0;
+	u8 addr = 0xa0 >> 1;
+	u8 start_offset = 0;
+	int len_todo = len;
+	u8 *eedata_cur = eedata;
+	int i;
+	struct i2c_msg msg_write = { .addr = addr, .flags = 0,
+		.buf = &start_offset, .len = 1 };
+	struct i2c_msg msg_read = { .addr = addr, .flags = I2C_M_RD };
+
+	/* mutex_lock(&dev->i2c_lock); */
+	cx231xx_enable_i2c_port_3(dev, false);
+
+	/* start reading at offset 0 */
+	ret = i2c_transfer(&dev->i2c_bus[1].i2c_adap, &msg_write, 1);
+
+	while (len_todo > 0) {
+		msg_read.len = (len_todo > 64) ? 64 : len_todo;
+		msg_read.buf = eedata_cur;
+
+		ret = i2c_transfer(&dev->i2c_bus[1].i2c_adap, &msg_read, 1);
+
+		eedata_cur += msg_read.len;
+		len_todo -= msg_read.len;
+	}
+
+	cx231xx_enable_i2c_port_3(dev, true);
+	/* mutex_unlock(&dev->i2c_lock); */
+
+	for (i = 0; i + 15 < len; i += 16)
+		cx231xx_info("i2c eeprom %02x: %*ph\n", i, 16, &eedata[i]);
+
+	return 0;
+}
+
 void cx231xx_card_setup(struct cx231xx *dev)
 {
 
@@ -917,6 +995,20 @@ void cx231xx_card_setup(struct cx231xx *dev)
 		else
 			cx231xx_config_tuner(dev);
 	}
+
+	switch (dev->model) {
+	case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
+		{
+			struct tveeprom tvee;
+			static u8 eeprom[256];
+
+			read_eeprom(dev, eeprom, sizeof(eeprom));
+			tveeprom_hauppauge_analog(&dev->i2c_bus[1].i2c_client,
+						&tvee, eeprom + 0xc0);
+			break;
+		}
+	}
+
 }
 
 /*
diff --git a/drivers/media/usb/cx231xx/cx231xx-core.c b/drivers/media/usb/cx231xx/cx231xx-core.c
index 4ba3ce0..513194a 100644
--- a/drivers/media/usb/cx231xx/cx231xx-core.c
+++ b/drivers/media/usb/cx231xx/cx231xx-core.c
@@ -726,6 +726,7 @@ int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode)
 			errCode = cx231xx_set_agc_analog_digital_mux_select(dev, 1);
 			break;
 		case CX231XX_BOARD_HAUPPAUGE_EXETER:
+		case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
 			errCode = cx231xx_set_power_mode(dev,
 						POLARIS_AVMODE_DIGITAL);
 			break;
@@ -744,6 +745,7 @@ int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode)
 		case CX231XX_BOARD_CNXT_RDE_253S:
 		case CX231XX_BOARD_CNXT_RDU_253S:
 		case CX231XX_BOARD_HAUPPAUGE_EXETER:
+		case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
 		case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
 		case CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL:
 		case CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC:
@@ -1379,6 +1381,7 @@ int cx231xx_dev_init(struct cx231xx *dev)
 	case CX231XX_BOARD_CNXT_RDE_253S:
 	case CX231XX_BOARD_CNXT_RDU_253S:
 	case CX231XX_BOARD_HAUPPAUGE_EXETER:
+	case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
 	case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
 	case CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL:
 	case CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC:
diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 5c69be7..4ff6f7f 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -32,6 +32,7 @@
 #include "tda18271.h"
 #include "s5h1411.h"
 #include "lgdt3305.h"
+#include "si2165.h"
 #include "mb86a20s.h"
 
 MODULE_DESCRIPTION("driver for cx231xx based DVB cards");
@@ -152,6 +153,12 @@ static struct tda18271_config pv_tda18271_config = {
 	.small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
 };
 
+static const struct si2165_config hauppauge_930C_HD_1113xx_si2165_config = {
+	.i2c_addr	= 0x64,
+	.chip_mode	= SI2165_MODE_PLL_XTAL,
+	.ref_freq_Hz	= 16000000,
+};
+
 static inline void print_err_status(struct cx231xx *dev, int packet, int status)
 {
 	char *errmsg = "Unknown";
@@ -712,6 +719,33 @@ static int dvb_init(struct cx231xx *dev)
 			   &hcw_tda18271_config);
 		break;
 
+	case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
+
+		dev->dvb->frontend = dvb_attach(si2165_attach,
+			&hauppauge_930C_HD_1113xx_si2165_config,
+			&dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap
+			);
+
+		if (dev->dvb->frontend == NULL) {
+			printk(DRIVER_NAME
+			       ": Failed to attach SI2165 front end\n");
+			result = -EINVAL;
+			goto out_free;
+		}
+
+		dev->dvb->frontend->ops.i2c_gate_ctrl = 0;
+
+		/* define general-purpose callback pointer */
+		dvb->frontend->callback = cx231xx_tuner_callback;
+
+		dvb_attach(tda18271_attach, dev->dvb->frontend,
+			0x60,
+			&dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
+			&hcw_tda18271_config);
+
+		dev->cx231xx_reset_analog_tuner = NULL;
+		break;
+
 	case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
 	case CX231XX_BOARD_KWORLD_UB430_USB_HYBRID:
 
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index babca7f..a6373ba 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -73,6 +73,7 @@
 #define CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2 16
 #define CX231XX_BOARD_OTG102 17
 #define CX231XX_BOARD_KWORLD_UB445_USB_HYBRID 18
+#define CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx 19
 
 /* Limits minimum and default number of buffers */
 #define CX231XX_MIN_BUF                 4
-- 
2.0.0


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

* [PATCH 6/8] cx231xx: Add digital support for [2040:b131] Hauppauge WinTV 930C-HD (model 1114xx)
  2014-07-22 20:12 [PATCH 0/8] add si2165 demod driver Matthias Schwarzott
                   ` (4 preceding siblings ...)
  2014-07-22 20:12 ` [PATCH 5/8] cx231xx: Add digital support for [2040:b130] Hauppauge WinTV 930C-HD (model 1113xx) Matthias Schwarzott
@ 2014-07-22 20:12 ` Matthias Schwarzott
  2014-07-26 19:27   ` Mauro Carvalho Chehab
  2014-07-22 20:12 ` [PATCH 7/8] cx231xx: Add [2013:0259] PCTV QuatroStick 521e Matthias Schwarzott
  2014-07-22 20:12 ` [PATCH 8/8] cx231xx: Add [2013:025e] PCTV QuatroStick 522e Matthias Schwarzott
  7 siblings, 1 reply; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-22 20:12 UTC (permalink / raw)
  To: crope, m.chehab, linux-media; +Cc: Matthias Schwarzott

Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
 drivers/media/usb/cx231xx/Kconfig         |  1 +
 drivers/media/usb/cx231xx/cx231xx-cards.c | 42 +++++++++++++++++++++
 drivers/media/usb/cx231xx/cx231xx-dvb.c   | 63 +++++++++++++++++++++++++++++++
 drivers/media/usb/cx231xx/cx231xx.h       |  1 +
 4 files changed, 107 insertions(+)

diff --git a/drivers/media/usb/cx231xx/Kconfig b/drivers/media/usb/cx231xx/Kconfig
index 036454e..569aa29 100644
--- a/drivers/media/usb/cx231xx/Kconfig
+++ b/drivers/media/usb/cx231xx/Kconfig
@@ -48,6 +48,7 @@ config VIDEO_CX231XX_DVB
 	select DVB_LGDT3305 if MEDIA_SUBDRV_AUTOSELECT
 	select DVB_TDA18271C2DD if MEDIA_SUBDRV_AUTOSELECT
 	select DVB_SI2165 if MEDIA_SUBDRV_AUTOSELECT
+	select MEDIA_TUNER_SI2157 if MEDIA_SUBDRV_AUTOSELECT
 
 	---help---
 	  This adds support for DVB cards based on the
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 8b80f88..8857fdd 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -743,6 +743,45 @@ struct cx231xx_board cx231xx_boards[] = {
 			.gpio = NULL,
 		} },
 	},
+	[CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx] = {
+		.name = "Hauppauge WinTV 930C-HD (1114xx)",
+		.tuner_type = TUNER_ABSENT,
+		.tuner_addr = 0x60,
+		.tuner_gpio = RDE250_XCV_TUNER,
+		.tuner_sif_gpio = 0x05,
+		.tuner_scl_gpio = 0x1a,
+		.tuner_sda_gpio = 0x1b,
+		.decoder = CX231XX_AVDECODER,
+		.output_mode = OUT_MODE_VIP11,
+		.demod_xfer_mode = 0,
+		.ctl_pin_status_mask = 0xFFFFFFC4,
+		.agc_analog_digital_select_gpio = 0x0c,
+		.gpio_pin_status_mask = 0x4001000,
+		.tuner_i2c_master = 1,
+		.demod_i2c_master = 2,
+		.has_dvb = 1,
+		.demod_addr = 0x0e,
+		.norm = V4L2_STD_PAL,
+
+		.input = {{
+			.type = CX231XX_VMUX_TELEVISION,
+			.vmux = CX231XX_VIN_3_1,
+			.amux = CX231XX_AMUX_VIDEO,
+			.gpio = NULL,
+		}, {
+			.type = CX231XX_VMUX_COMPOSITE1,
+			.vmux = CX231XX_VIN_2_1,
+			.amux = CX231XX_AMUX_LINE_IN,
+			.gpio = NULL,
+		}, {
+			.type = CX231XX_VMUX_SVIDEO,
+			.vmux = CX231XX_VIN_1_1 |
+				(CX231XX_VIN_1_2 << 8) |
+				CX25840_SVIDEO_ON,
+			.amux = CX231XX_AMUX_LINE_IN,
+			.gpio = NULL,
+		} },
+	},
 };
 const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
 
@@ -774,6 +813,8 @@ struct usb_device_id cx231xx_id_table[] = {
 	 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
 	{USB_DEVICE(0x2040, 0xb130),
 	 .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx},
+	{USB_DEVICE(0x2040, 0xb131),
+	 .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx},
 	{USB_DEVICE(0x2040, 0xb140),
 	 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
 	{USB_DEVICE(0x2040, 0xc200),
@@ -998,6 +1039,7 @@ void cx231xx_card_setup(struct cx231xx *dev)
 
 	switch (dev->model) {
 	case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
+	case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx:
 		{
 			struct tveeprom tvee;
 			static u8 eeprom[256];
diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 4ff6f7f..1fa7974 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -34,6 +34,7 @@
 #include "lgdt3305.h"
 #include "si2165.h"
 #include "mb86a20s.h"
+#include "si2157.h"
 
 MODULE_DESCRIPTION("driver for cx231xx based DVB cards");
 MODULE_AUTHOR("Srinivasa Deevi <srinivasa.deevi@conexant.com>");
@@ -159,6 +160,12 @@ static const struct si2165_config hauppauge_930C_HD_1113xx_si2165_config = {
 	.ref_freq_Hz	= 16000000,
 };
 
+static const struct si2165_config pctv_quatro_stick_1114xx_si2165_config = {
+	.i2c_addr	= 0x64,
+	.chip_mode	= SI2165_MODE_PLL_EXT,
+	.ref_freq_Hz	= 24000000,
+};
+
 static inline void print_err_status(struct cx231xx *dev, int packet, int status)
 {
 	char *errmsg = "Unknown";
@@ -746,6 +753,62 @@ static int dvb_init(struct cx231xx *dev)
 		dev->cx231xx_reset_analog_tuner = NULL;
 		break;
 
+	case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx:
+	{
+		struct i2c_client *client;
+		struct i2c_board_info info;
+		struct si2157_config si2157_config;
+
+		memset(&info, 0, sizeof(struct i2c_board_info));
+
+		dev->dvb->frontend = dvb_attach(si2165_attach,
+			&pctv_quatro_stick_1114xx_si2165_config,
+			&dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap
+			);
+
+		if (dev->dvb->frontend == NULL) {
+			printk(DRIVER_NAME
+			       ": Failed to attach SI2165 front end\n");
+			result = -EINVAL;
+			goto out_free;
+		}
+
+		dev->dvb->frontend->ops.i2c_gate_ctrl = 0;
+
+		/* define general-purpose callback pointer */
+		dvb->frontend->callback = cx231xx_tuner_callback;
+
+		/* attach tuner */
+		memset(&si2157_config, 0, sizeof(si2157_config));
+		si2157_config.fe = dev->dvb->frontend;
+		si2157_config.inversion = true;
+		strlcpy(info.type, "si2157", I2C_NAME_SIZE);
+		info.addr = 0x60;
+		info.platform_data = &si2157_config;
+		request_module("si2157");
+
+		client = i2c_new_device(
+			&dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
+			&info);
+		if (client == NULL || client->dev.driver == NULL) {
+			dvb_frontend_detach(dev->dvb->frontend);
+			result = -ENODEV;
+			goto out_free;
+		}
+
+		if (!try_module_get(client->dev.driver->owner)) {
+			i2c_unregister_device(client);
+			dvb_frontend_detach(dev->dvb->frontend);
+			result = -ENODEV;
+			goto out_free;
+		}
+
+		dev->cx231xx_reset_analog_tuner = NULL;
+
+		dev->dvb->i2c_client_tuner = client;
+		break;
+	}
+
 	case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
 	case CX231XX_BOARD_KWORLD_UB430_USB_HYBRID:
 
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index a6373ba..aeb1bf4 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -74,6 +74,7 @@
 #define CX231XX_BOARD_OTG102 17
 #define CX231XX_BOARD_KWORLD_UB445_USB_HYBRID 18
 #define CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx 19
+#define CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx 20
 
 /* Limits minimum and default number of buffers */
 #define CX231XX_MIN_BUF                 4
-- 
2.0.0


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

* [PATCH 7/8] cx231xx: Add [2013:0259] PCTV QuatroStick 521e
  2014-07-22 20:12 [PATCH 0/8] add si2165 demod driver Matthias Schwarzott
                   ` (5 preceding siblings ...)
  2014-07-22 20:12 ` [PATCH 6/8] cx231xx: Add digital support for [2040:b131] Hauppauge WinTV 930C-HD (model 1114xx) Matthias Schwarzott
@ 2014-07-22 20:12 ` Matthias Schwarzott
  2014-07-22 20:12 ` [PATCH 8/8] cx231xx: Add [2013:025e] PCTV QuatroStick 522e Matthias Schwarzott
  7 siblings, 0 replies; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-22 20:12 UTC (permalink / raw)
  To: crope, m.chehab, linux-media; +Cc: Matthias Schwarzott

The hardware is identical to Hauppauge WinTV 930C-HD (model 1113xx)

Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
 drivers/media/usb/cx231xx/cx231xx-cards.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 8857fdd..0085ccd 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -705,7 +705,7 @@ struct cx231xx_board cx231xx_boards[] = {
 		},
 	},
 	[CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx] = {
-		.name = "Hauppauge WinTV 930C-HD (1113xx)",
+		.name = "Hauppauge WinTV 930C-HD (1113xx) / PCTV QuatroStick 521e",
 		.tuner_type = TUNER_NXP_TDA18271,
 		.tuner_addr = 0x60,
 		.tuner_gpio = RDE250_XCV_TUNER,
@@ -819,6 +819,9 @@ struct usb_device_id cx231xx_id_table[] = {
 	 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
 	{USB_DEVICE(0x2040, 0xc200),
 	 .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
+	/* PCTV QuatroStick 521e */
+	{USB_DEVICE(0x2013, 0x0259),
+	 .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx},
 	{USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
 	 .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
 	{USB_DEVICE(USB_VID_PIXELVIEW, 0x5014),
-- 
2.0.0


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

* [PATCH 8/8] cx231xx: Add [2013:025e] PCTV QuatroStick 522e
  2014-07-22 20:12 [PATCH 0/8] add si2165 demod driver Matthias Schwarzott
                   ` (6 preceding siblings ...)
  2014-07-22 20:12 ` [PATCH 7/8] cx231xx: Add [2013:0259] PCTV QuatroStick 521e Matthias Schwarzott
@ 2014-07-22 20:12 ` Matthias Schwarzott
  7 siblings, 0 replies; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-22 20:12 UTC (permalink / raw)
  To: crope, m.chehab, linux-media; +Cc: Matthias Schwarzott

The hardware is identical to Hauppauge WinTV 930C-HD (model 1114xx)

Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
 drivers/media/usb/cx231xx/cx231xx-cards.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 0085ccd..b2fa05d 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -744,7 +744,7 @@ struct cx231xx_board cx231xx_boards[] = {
 		} },
 	},
 	[CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx] = {
-		.name = "Hauppauge WinTV 930C-HD (1114xx)",
+		.name = "Hauppauge WinTV 930C-HD (1114xx) / PCTV QuatroStick 522e",
 		.tuner_type = TUNER_ABSENT,
 		.tuner_addr = 0x60,
 		.tuner_gpio = RDE250_XCV_TUNER,
@@ -822,6 +822,9 @@ struct usb_device_id cx231xx_id_table[] = {
 	/* PCTV QuatroStick 521e */
 	{USB_DEVICE(0x2013, 0x0259),
 	 .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx},
+	/* PCTV QuatroStick 522e */
+	{USB_DEVICE(0x2013, 0x025e),
+	 .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx},
 	{USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
 	 .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
 	{USB_DEVICE(USB_VID_PIXELVIEW, 0x5014),
-- 
2.0.0


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

* Re: [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165
  2014-07-22 20:12 ` [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165 Matthias Schwarzott
@ 2014-07-23  9:20   ` Antti Palosaari
  2014-07-23 19:03     ` Matthias Schwarzott
  0 siblings, 1 reply; 26+ messages in thread
From: Antti Palosaari @ 2014-07-23  9:20 UTC (permalink / raw)
  To: Matthias Schwarzott, m.chehab, linux-media

Moikka Matthias

On 07/22/2014 11:12 PM, Matthias Schwarzott wrote:
> Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
> ---
>   Documentation/dvb/get_dvb_firmware | 33 ++++++++++++++++++++++++++++++++-
>   1 file changed, 32 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/dvb/get_dvb_firmware b/Documentation/dvb/get_dvb_firmware
> index d91b8be..26c623d 100755
> --- a/Documentation/dvb/get_dvb_firmware
> +++ b/Documentation/dvb/get_dvb_firmware
> @@ -29,7 +29,7 @@ use IO::Handle;
>   		"af9015", "ngene", "az6027", "lme2510_lg", "lme2510c_s7395",
>   		"lme2510c_s7395_old", "drxk", "drxk_terratec_h5",
>   		"drxk_hauppauge_hvr930c", "tda10071", "it9135", "drxk_pctv",
> -		"drxk_terratec_htc_stick", "sms1xxx_hcw");
> +		"drxk_terratec_htc_stick", "sms1xxx_hcw", "si2165");
>
>   # Check args
>   syntax() if (scalar(@ARGV) != 1);
> @@ -783,6 +783,37 @@ sub sms1xxx_hcw {
>       $allfiles;
>   }
>
> +sub si2165 {
> +    my $sourcefile = "model_111xxx_122xxx_driver_6_0_119_31191_WHQL.zip";
> +    my $url = "http://www.hauppauge.de/files/drivers/";
> +    my $hash = "76633e7c76b0edee47c3ba18ded99336";
> +    my $fwfile = "dvb-demod-si2165.fw";
> +    my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
> +
> +    checkstandard();
> +
> +    wgetfile($sourcefile, $url . $sourcefile);
> +    verify($sourcefile, $hash);
> +    unzip($sourcefile, $tmpdir);
> +    extract("$tmpdir/Driver10/Hcw10bda.sys", 0x80788, 0x81E08-0x80788, "$tmpdir/fw1");
> +
> +    delzero("$tmpdir/fw1","$tmpdir/fw1-1");
> +    #verify("$tmpdir/fw1","5e0909858fdf0b5b09ad48b9fe622e70");
> +
> +    my $CRC="\x0A\xCC";
> +    my $BLOCKS_MAIN="\x27";
> +    open FW,">$fwfile";
> +    print FW "\x01\x00"; # just a version id for the driver itself
> +    print FW "\x9A"; # fw version
> +    print FW "\x00"; # padding
> +    print FW "$BLOCKS_MAIN"; # number of blocks of main part
> +    print FW "\x00"; # padding
> +    print FW "$CRC"; # 16bit crc value of main part
> +    appendfile(FW,"$tmpdir/fw1");

I have to say I little bit dislike that kind of own headers. There is no 
way to read firmware version from binary itself (very often there is)? 
Whats is benefit of telling how many blocks there is? Isn't it possible 
to detect somehow by examining firmware image itself runtime?

Anyhow, you are the author of that driver and even I don't personally 
like those, I think it is up to your decision as a author.

regards
Antti


> +
> +    "$fwfile";
> +}
> +
>   # ---------------------------------------------------------------
>   # Utilities
>
>

-- 
http://palosaari.fi/

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

* Re: [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165
  2014-07-23  9:20   ` Antti Palosaari
@ 2014-07-23 19:03     ` Matthias Schwarzott
  2014-07-23 20:10       ` Antonio Ospite
  0 siblings, 1 reply; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-23 19:03 UTC (permalink / raw)
  To: Antti Palosaari, m.chehab, linux-media

On 23.07.2014 11:20, Antti Palosaari wrote:
> Moikka Matthias
> 
Moikka Antti,

> On 07/22/2014 11:12 PM, Matthias Schwarzott wrote:
>> +
>> +    my $CRC="\x0A\xCC";
>> +    my $BLOCKS_MAIN="\x27";
>> +    open FW,">$fwfile";
>> +    print FW "\x01\x00"; # just a version id for the driver itself
>> +    print FW "\x9A"; # fw version
>> +    print FW "\x00"; # padding
>> +    print FW "$BLOCKS_MAIN"; # number of blocks of main part
>> +    print FW "\x00"; # padding
>> +    print FW "$CRC"; # 16bit crc value of main part
>> +    appendfile(FW,"$tmpdir/fw1");
> 
> I have to say I little bit dislike that kind of own headers. There is no
> way to read firmware version from binary itself (very often there is)?
> Whats is benefit of telling how many blocks there is? Isn't it possible
> to detect somehow by examining firmware image itself runtime?
> 
> Anyhow, you are the author of that driver and even I don't personally
> like those, I think it is up to your decision as a author.
> 
I thought a bit about the need for the header.
And yes, some fields I can get rid of.

firmware version:
I guess that the exact version number is not really needed - it is just
written to a seperate register - and later only read to check if
firmware was already downloaded (but for documentation it might be
interesting). I have no clue where it could be in the raw block - it
looks like it is writing to just some memory addresses.

But for the pure process it would also work to write a random number !=
0x00.

For $BLOCKS_MAIN:
The firmware is downloaded like this:
* write 1 block
* reset crc logic
* write $BLOCKS_MAIN
* read out crc and compare against $CRC in header
* write last 5 blocks

so the number of blocks in $BLOCKS_MAIN could be checked by iterating
over all blocks counting them and then substracting 6.

The crc value:
It protects the content of the file until it is in the demod - so
calculating it on my own would only check if the data is correctly
transferred from the driver into the chip.
But for this I needed to know the algorithm and which data is
checksummed exactly.

Are the different algorithms for CRC values that give 16 bit of output?

Matthias


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

* Re: [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165
  2014-07-23 19:03     ` Matthias Schwarzott
@ 2014-07-23 20:10       ` Antonio Ospite
  2014-07-29  5:37         ` Matthias Schwarzott
  0 siblings, 1 reply; 26+ messages in thread
From: Antonio Ospite @ 2014-07-23 20:10 UTC (permalink / raw)
  To: Matthias Schwarzott; +Cc: Antti Palosaari, m.chehab, linux-media

On Wed, 23 Jul 2014 21:03:14 +0200
Matthias Schwarzott <zzam@gentoo.org> wrote:

[...]
> The crc value:
> It protects the content of the file until it is in the demod - so
> calculating it on my own would only check if the data is correctly
> transferred from the driver into the chip.
> But for this I needed to know the algorithm and which data is
> checksummed exactly.
> 
> Are the different algorithms for CRC values that give 16 bit of output?
>

You could try jacksum[1] and see if any algorithm it supports
gives you the expected result, there is a handful of 16 bits ones:

  jacksum -a all -F "#ALGONAME{i} = #CHECKSUM{i}" payload.bin

Ciao,
   Antonio

[1] http://www.jonelo.de/java/jacksum/

-- 
Antonio Ospite
http://ao2.it

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?

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

* Re: [PATCH 6/8] cx231xx: Add digital support for [2040:b131] Hauppauge WinTV 930C-HD (model 1114xx)
  2014-07-22 20:12 ` [PATCH 6/8] cx231xx: Add digital support for [2040:b131] Hauppauge WinTV 930C-HD (model 1114xx) Matthias Schwarzott
@ 2014-07-26 19:27   ` Mauro Carvalho Chehab
  2014-07-27  9:32     ` Matthias Schwarzott
  0 siblings, 1 reply; 26+ messages in thread
From: Mauro Carvalho Chehab @ 2014-07-26 19:27 UTC (permalink / raw)
  To: Matthias Schwarzott; +Cc: crope, linux-media

Em Tue, 22 Jul 2014 22:12:16 +0200
Matthias Schwarzott <zzam@gentoo.org> escreveu:

> Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>

Hi Matthias,

Tried to apply your patch series, but there's something wrong on it.

See the enclosed logs. I suspect that you missed a patch adding the
proper tuner for this device.

Regards,
Mauro

[76183.104385] Linux video capture interface: v2.00
[76183.110508] cx231xx #0: New device Hauppauge Hauppauge Device @ 12 Mbps (2040:b131) with 4 interfaces
[76183.110513] cx231xx #0: registering interface 1
[76183.110602] cx231xx #0: Identified as Hauppauge WinTV 930C-HD (1114xx) / PCTV QuatroStick 522e (card=20)
[76183.211942] cx231xx #0: cx231xx_dif_set_standard: setStandard to ffffffff
[76183.220035] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)
[76183.220043] cx231xx #0: can't change interface 6 alt no. to 0 (err=-22)
[76183.228875] cx25840 0-0044: cx23102 A/V decoder found @ 0x88 (cx231xx #0)
[76183.247286] cx25840 0-0044:  Firmware download size changed to 16 bytes max length
[76185.302724] cx25840 0-0044: loaded v4l-cx231xx-avcore-01.fw firmware (16382 bytes)
[76185.336362] cx231xx #0: Changing the i2c master port to 1
[76185.368850] cx231xx #0: Changing the i2c master port to 3
[76185.368940] cx231xx #0: i2c eeprom 00: 40 20 31 b1 aa 00 00 01 10 00 50 00 30 00 ff ff
[76185.368944] cx231xx #0: i2c eeprom 10: 14 03 48 00 61 00 75 00 70 00 70 00 61 00 75 00
[76185.368946] cx231xx #0: i2c eeprom 20: 67 00 65 00 00 00 00 00 00 00 00 00 00 00 00 00
[76185.368949] cx231xx #0: i2c eeprom 30: 16 03 34 00 30 00 33 00 35 00 31 00 36 00 39 00
[76185.368951] cx231xx #0: i2c eeprom 40: 31 00 31 00 32 00 00 00 ff ff ff ff ff ff ff ff
[76185.368953] cx231xx #0: i2c eeprom 50: 22 03 48 00 61 00 75 00 70 00 70 00 61 00 75 00
[76185.368956] cx231xx #0: i2c eeprom 60: 67 00 65 00 20 00 44 00 65 00 76 00 69 00 63 00
[76185.368958] cx231xx #0: i2c eeprom 70: 65 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[76185.368960] cx231xx #0: i2c eeprom 80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[76185.368962] cx231xx #0: i2c eeprom 90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[76185.368964] cx231xx #0: i2c eeprom a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[76185.368966] cx231xx #0: i2c eeprom b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[76185.368969] cx231xx #0: i2c eeprom c0: 84 09 00 04 20 77 00 40 58 cb 83 f0 73 05 2f 00
[76185.368971] cx231xx #0: i2c eeprom d0: 84 08 00 06 3b b3 01 00 56 2a 95 72 07 70 73 09
[76185.368973] cx231xx #0: i2c eeprom e0: 2e 7f 73 0a f4 ba 72 0b 13 72 0f 05 72 10 01 72
[76185.368975] cx231xx #0: i2c eeprom f0: 11 1f 73 13 eb 79 79 ea 00 00 00 00 00 00 00 00
[76185.368981] tveeprom 1-0000: Hauppauge model 111419, rev E2I6, serial# 8637272
[76185.368984] tveeprom 1-0000: MAC address is 00:0d:fe:83:cb:58
[76185.368987] tveeprom 1-0000: tuner model is unknown (idx 186, type 4)
[76185.368991] tveeprom 1-0000: TV standards PAL(B/G) PAL(I) SECAM(L/L') PAL(D/D1/K) ATSC/DVB Digital (eeprom 0xf4)
[76185.368993] tveeprom 1-0000: audio processor is unknown (idx 47)
[76185.368995] tveeprom 1-0000: decoder processor is unknown (idx 46)
[76185.368998] tveeprom 1-0000: has no radio, has IR receiver, has no IR transmitter
[76185.370090] cx231xx #0: cx231xx #0: v4l2 driver version 0.0.2
[76185.387866] cx231xx #0: cx231xx_dif_set_standard: setStandard to ffffffff
[76185.431668] Unknown tuner type configuring SIF
[76185.432964] cx231xx #0: video_mux : 0
[76185.432972] cx231xx #0: do_mode_ctrl_overrides : 0xff
[76185.433843] cx231xx #0: do_mode_ctrl_overrides PAL
[76185.463109] cx231xx #0: cx231xx #0/0: registered device video0 [v4l2]
[76185.463321] cx231xx #0: cx231xx #0/0: registered device vbi0
[76185.463325] cx231xx #0: V4L2 device registered as video0 and vbi0
[76185.463331] cx231xx #0: EndPoint Addr 0x84, Alternate settings: 2
[76185.463334] cx231xx #0: Alternate setting 0, max size= 64
[76185.463336] cx231xx #0: Alternate setting 1, max size= 728
[76185.463359] BUG: unable to handle kernel NULL pointer dereference at           (null)
[76185.465295] IP: [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
[76185.465654] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)
[76185.465705] cx231xx #0: called cx231xx_uninit_vbi_isoc
[76185.465707] cx231xx #0: cx231xx_stop_stream():: ep_mask = 10
[76185.465872] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)
[76185.474837] PGD 21c0fa067 PUD 2182b4067 PMD 0 
[76185.476593] Oops: 0000 [#1] SMP 
[76185.478285] Modules linked in: cx25840 cx231xx(+) cx2341x tveeprom videobuf_vmalloc videobuf_core rc_core v4l2_common videodev media ip6table_filter ip6_tables bnep nouveau x86_pkg_temp_thermal coretemp i915 binfmt_misc kvm_intel kvm ttm i2c_algo_bit drm_kms_helper vfat fat drm arc4 iwldvm mac80211 snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic snd_hda_intel snd_hda_controller snd_hda_codec iwlwifi crct10dif_pclmul snd_hwdep crc32_pclmul cfg80211 snd_seq snd_seq_device snd_pcm crc32c_intel snd_timer btusb bluetooth iTCO_wdt iTCO_vendor_support mxm_wmi ghash_clmulni_intel lpc_ich i2c_i801 snd mei_me soundcore rfkill joydev serio_raw shpchp mei wmi mfd_core i2c_core video microcode r8169 mii [last unloaded: dvb_core]
[76185.487219] CPU: 0 PID: 12079 Comm: modprobe Not tainted 3.16.0-rc6+ #12
[76185.488936] Hardware name: SAMSUNG ELECTRONICS CO., LTD. 550P5C/550P7C/SAMSUNG_NP1234567890, BIOS P05ABI.016.130917.dg 09/17/2013
[76185.490710] task: ffff880211172ee0 ti: ffff88021866c000 task.ti: ffff88021866c000
[76185.492502] RIP: 0010:[<ffffffffa048dec8>]  [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
[76185.494321] RSP: 0018:ffff88021866fb50  EFLAGS: 00010246
[76185.496037] RAX: ffff88021c34fc00 RBX: ffff8800c4f70000 RCX: 0000000000000006
[76185.497781] RDX: 0000000000000004 RSI: ffff8800c4f70000 RDI: ffffffffa04a7508
[76185.499548] RBP: ffff88021866fb90 R08: 0000000000000000 R09: 00000000000011d3
[76185.501323] R10: 0000000000000000 R11: ffff88021866f85e R12: ffff88021bc20800
[76185.503119] R13: ffff88021bc27c00 R14: ffff8800c4f70168 R15: ffff8802229ca000
[76185.504934] FS:  00007f6c13b2e740(0000) GS:ffff88022f200000(0000) knlGS:0000000000000000
[76185.506662] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[76185.508406] CR2: 0000000000000000 CR3: 00000002222b8000 CR4: 00000000001407f0
[76185.510169] Stack:
[76185.511921]  ffff88020000b131 ffffffff00000004 ffff880000000001 ffff8802229ca090
[76185.513725]  ffff8802229ca000 ffffffffa04ab568 ffff88021bc27c30 ffffffffa04ab7a0
[76185.515517]  ffff88021866fbd8 ffffffff814eefcf 000000001866fbb0 ffff88021bc27c00
[76185.517248] Call Trace:
[76185.518963]  [<ffffffff814eefcf>] usb_probe_interface+0x1df/0x330
[76185.520714]  [<ffffffff8146605d>] driver_probe_device+0x12d/0x3d0
[76185.522452]  [<ffffffff814663d3>] __driver_attach+0x93/0xa0
[76185.524203]  [<ffffffff81466340>] ? __device_attach+0x40/0x40
[76185.525959]  [<ffffffff81463f03>] bus_for_each_dev+0x73/0xc0
[76185.527599]  [<ffffffff81465a5e>] driver_attach+0x1e/0x20
[76185.529240]  [<ffffffff81465640>] bus_add_driver+0x180/0x250
[76185.537278]  [<ffffffff81002144>] do_one_initcall+0xd4/0x210
[76185.538809]  [<ffffffff811b5fd4>] ? __vunmap+0x94/0x100
[76185.540330]  [<ffffffff81106767>] load_module+0x1ea7/0x24f0
[76185.541806]  [<ffffffff81102370>] ? store_uevent+0x70/0x70
[76185.543255]  [<ffffffff811f3200>] ? kernel_read+0x50/0x80
[76185.544661]  [<ffffffff81106f66>] SyS_finit_module+0xa6/0xd0
[76185.546047]  [<ffffffff816fc869>] system_call_fastpath+0x16/0x1b
[76185.547354] Code: 1d 00 00 85 ff 0f 8f 94 04 00 00 0f b6 93 bb 21 00 00 49 8b 87 68 03 00 00 48 89 de 48 c7 c7 08 75 4a a0 4c 8b 84 d0 a0 00 00 00 <49> 8b 00 4c 89 45 d0 48 8b 40 18 0f b6 40 02 0f b6 d0 66 89 93 
[76185.550208] RIP  [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
[76185.551613]  RSP <ffff88021866fb50>
[76185.553006] CR2: 0000000000000000
[76185.559997] ---[ end trace 1e58ef345d6b3f24 ]---

$ gdb drivers/media/usb/cx231xx/cx231xx.ko
GNU gdb (GDB) Fedora 7.7.1-15.fc20
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from drivers/media/usb/cx231xx/cx231xx.ko...done.
(gdb) list *cx231xx_usb_driver_init+0x1e
0x1e is in buffer_setup (drivers/media/usb/cx231xx/cx231xx-video.c:664).
659	buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
660	{
661		struct cx231xx_fh *fh = vq->priv_data;
662		struct cx231xx *dev = fh->dev;
663	
664		*size = (fh->dev->width * fh->dev->height * dev->format->depth + 7)>>3;
665		if (0 == *count)
666			*count = CX231XX_DEF_BUF;
667	
668		if (*count < CX231XX_MIN_BUF)

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

* Re: [PATCH 6/8] cx231xx: Add digital support for [2040:b131] Hauppauge WinTV 930C-HD (model 1114xx)
  2014-07-26 19:27   ` Mauro Carvalho Chehab
@ 2014-07-27  9:32     ` Matthias Schwarzott
  2014-07-27 13:44       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-27  9:32 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: crope, linux-media


Hi Mauro.

On 26.07.2014 21:27, Mauro Carvalho Chehab wrote:
> Tried to apply your patch series, but there's something wrong on it.
> 
> See the enclosed logs. I suspect that you missed a patch adding the
> proper tuner for this device.

well, tuner_type is set to TUNER_ABSENT, and for me the oops does not
happen.

> [76185.463359] BUG: unable to handle kernel NULL pointer dereference at           (null)
> [76185.465295] IP: [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
> [76185.465654] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)
> [76185.465705] cx231xx #0: called cx231xx_uninit_vbi_isoc
> [76185.465707] cx231xx #0: cx231xx_stop_stream():: ep_mask = 10
> [76185.465872] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)
> [76185.474837] PGD 21c0fa067 PUD 2182b4067 PMD 0 
> [76185.476593] Oops: 0000 [#1] SMP 
> [76185.478285] Modules linked in: cx25840 cx231xx(+) cx2341x tveeprom videobuf_vmalloc videobuf_core rc_core v4l2_common videodev media ip6table_filter ip6_tables bnep nouveau x86_pkg_temp_thermal coretemp i915 binfmt_misc kvm_intel kvm ttm i2c_algo_bit drm_kms_helper vfat fat drm arc4 iwldvm mac80211 snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic snd_hda_intel snd_hda_controller snd_hda_codec iwlwifi crct10dif_pclmul snd_hwdep crc32_pclmul cfg80211 snd_seq snd_seq_device snd_pcm crc32c_intel snd_timer btusb bluetooth iTCO_wdt iTCO_vendor_support mxm_wmi ghash_clmulni_intel lpc_ich i2c_i801 snd mei_me soundcore rfkill joydev serio_raw shpchp mei wmi mfd_core i2c_core video microcode r8169 mii [last unloaded: dvb_core]
> [76185.487219] CPU: 0 PID: 12079 Comm: modprobe Not tainted 3.16.0-rc6+ #12
> [76185.488936] Hardware name: SAMSUNG ELECTRONICS CO., LTD. 550P5C/550P7C/SAMSUNG_NP1234567890, BIOS P05ABI.016.130917.dg 09/17/2013
> [76185.490710] task: ffff880211172ee0 ti: ffff88021866c000 task.ti: ffff88021866c000
> [76185.492502] RIP: 0010:[<ffffffffa048dec8>]  [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
> [76185.494321] RSP: 0018:ffff88021866fb50  EFLAGS: 00010246
> [76185.496037] RAX: ffff88021c34fc00 RBX: ffff8800c4f70000 RCX: 0000000000000006
> [76185.497781] RDX: 0000000000000004 RSI: ffff8800c4f70000 RDI: ffffffffa04a7508
> [76185.499548] RBP: ffff88021866fb90 R08: 0000000000000000 R09: 00000000000011d3
> [76185.501323] R10: 0000000000000000 R11: ffff88021866f85e R12: ffff88021bc20800
> [76185.503119] R13: ffff88021bc27c00 R14: ffff8800c4f70168 R15: ffff8802229ca000
> [76185.504934] FS:  00007f6c13b2e740(0000) GS:ffff88022f200000(0000) knlGS:0000000000000000
> [76185.506662] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [76185.508406] CR2: 0000000000000000 CR3: 00000002222b8000 CR4: 00000000001407f0
> [76185.510169] Stack:
> [76185.511921]  ffff88020000b131 ffffffff00000004 ffff880000000001 ffff8802229ca090
> [76185.513725]  ffff8802229ca000 ffffffffa04ab568 ffff88021bc27c30 ffffffffa04ab7a0
> [76185.515517]  ffff88021866fbd8 ffffffff814eefcf 000000001866fbb0 ffff88021bc27c00
> [76185.517248] Call Trace:
> [76185.518963]  [<ffffffff814eefcf>] usb_probe_interface+0x1df/0x330
> [76185.520714]  [<ffffffff8146605d>] driver_probe_device+0x12d/0x3d0
> [76185.522452]  [<ffffffff814663d3>] __driver_attach+0x93/0xa0
> [76185.524203]  [<ffffffff81466340>] ? __device_attach+0x40/0x40
> [76185.525959]  [<ffffffff81463f03>] bus_for_each_dev+0x73/0xc0
> [76185.527599]  [<ffffffff81465a5e>] driver_attach+0x1e/0x20
> [76185.529240]  [<ffffffff81465640>] bus_add_driver+0x180/0x250
> [76185.537278]  [<ffffffff81002144>] do_one_initcall+0xd4/0x210
> [76185.538809]  [<ffffffff811b5fd4>] ? __vunmap+0x94/0x100
> [76185.540330]  [<ffffffff81106767>] load_module+0x1ea7/0x24f0
> [76185.541806]  [<ffffffff81102370>] ? store_uevent+0x70/0x70
> [76185.543255]  [<ffffffff811f3200>] ? kernel_read+0x50/0x80
> [76185.544661]  [<ffffffff81106f66>] SyS_finit_module+0xa6/0xd0
> [76185.546047]  [<ffffffff816fc869>] system_call_fastpath+0x16/0x1b
> [76185.547354] Code: 1d 00 00 85 ff 0f 8f 94 04 00 00 0f b6 93 bb 21 00 00 49 8b 87 68 03 00 00 48 89 de 48 c7 c7 08 75 4a a0 4c 8b 84 d0 a0 00 00 00 <49> 8b 00 4c 89 45 d0 48 8b 40 18 0f b6 40 02 0f b6 d0 66 89 93 
> [76185.550208] RIP  [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
> [76185.551613]  RSP <ffff88021866fb50>
> [76185.553006] CR2: 0000000000000000
> [76185.559997] ---[ end trace 1e58ef345d6b3f24 ]---
> 

Is the order of the printk messages and of the oops message fixed? Are
all messages printed before the oops also before the oops message?

It seems to oops is at cx231xx_usb_probe+0x5a8/0xb20.

> $ gdb drivers/media/usb/cx231xx/cx231xx.ko
> GNU gdb (GDB) Fedora 7.7.1-15.fc20
> Copyright (C) 2014 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[...]
> Type "apropos word" to search for commands related to "word"...
> Reading symbols from drivers/media/usb/cx231xx/cx231xx.ko...done.
> (gdb) list *cx231xx_usb_driver_init+0x1e

Could you retry this with the offset from above (0x5a8).
I normally use nm to get the base addr of the function, then add the
offset and then run "addr2line -ispf -e cx231xx.ko -a 0x....."

Regards
Matthias


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

* Re: [PATCH 6/8] cx231xx: Add digital support for [2040:b131] Hauppauge WinTV 930C-HD (model 1114xx)
  2014-07-27  9:32     ` Matthias Schwarzott
@ 2014-07-27 13:44       ` Mauro Carvalho Chehab
  2014-07-27 14:32         ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 26+ messages in thread
From: Mauro Carvalho Chehab @ 2014-07-27 13:44 UTC (permalink / raw)
  To: Matthias Schwarzott; +Cc: crope, linux-media

Em Sun, 27 Jul 2014 11:32:26 +0200
Matthias Schwarzott <zzam@gentoo.org> escreveu:

> 
> Hi Mauro.
> 
> On 26.07.2014 21:27, Mauro Carvalho Chehab wrote:
> > Tried to apply your patch series, but there's something wrong on it.
> > 
> > See the enclosed logs. I suspect that you missed a patch adding the
> > proper tuner for this device.
> 
> well, tuner_type is set to TUNER_ABSENT, and for me the oops does not
> happen.
> 
> > [76185.463359] BUG: unable to handle kernel NULL pointer dereference at           (null)
> > [76185.465295] IP: [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
> > [76185.465654] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)
> > [76185.465705] cx231xx #0: called cx231xx_uninit_vbi_isoc
> > [76185.465707] cx231xx #0: cx231xx_stop_stream():: ep_mask = 10
> > [76185.465872] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)
> > [76185.474837] PGD 21c0fa067 PUD 2182b4067 PMD 0 
> > [76185.476593] Oops: 0000 [#1] SMP 
> > [76185.478285] Modules linked in: cx25840 cx231xx(+) cx2341x tveeprom videobuf_vmalloc videobuf_core rc_core v4l2_common videodev media ip6table_filter ip6_tables bnep nouveau x86_pkg_temp_thermal coretemp i915 binfmt_misc kvm_intel kvm ttm i2c_algo_bit drm_kms_helper vfat fat drm arc4 iwldvm mac80211 snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic snd_hda_intel snd_hda_controller snd_hda_codec iwlwifi crct10dif_pclmul snd_hwdep crc32_pclmul cfg80211 snd_seq snd_seq_device snd_pcm crc32c_intel snd_timer btusb bluetooth iTCO_wdt iTCO_vendor_support mxm_wmi ghash_clmulni_intel lpc_ich i2c_i801 snd mei_me soundcore rfkill joydev serio_raw shpchp mei wmi mfd_core i2c_core video microcode r8169 mii [last unloaded: dvb_core]
> > [76185.487219] CPU: 0 PID: 12079 Comm: modprobe Not tainted 3.16.0-rc6+ #12
> > [76185.488936] Hardware name: SAMSUNG ELECTRONICS CO., LTD. 550P5C/550P7C/SAMSUNG_NP1234567890, BIOS P05ABI.016.130917.dg 09/17/2013
> > [76185.490710] task: ffff880211172ee0 ti: ffff88021866c000 task.ti: ffff88021866c000
> > [76185.492502] RIP: 0010:[<ffffffffa048dec8>]  [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
> > [76185.494321] RSP: 0018:ffff88021866fb50  EFLAGS: 00010246
> > [76185.496037] RAX: ffff88021c34fc00 RBX: ffff8800c4f70000 RCX: 0000000000000006
> > [76185.497781] RDX: 0000000000000004 RSI: ffff8800c4f70000 RDI: ffffffffa04a7508
> > [76185.499548] RBP: ffff88021866fb90 R08: 0000000000000000 R09: 00000000000011d3
> > [76185.501323] R10: 0000000000000000 R11: ffff88021866f85e R12: ffff88021bc20800
> > [76185.503119] R13: ffff88021bc27c00 R14: ffff8800c4f70168 R15: ffff8802229ca000
> > [76185.504934] FS:  00007f6c13b2e740(0000) GS:ffff88022f200000(0000) knlGS:0000000000000000
> > [76185.506662] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> > [76185.508406] CR2: 0000000000000000 CR3: 00000002222b8000 CR4: 00000000001407f0
> > [76185.510169] Stack:
> > [76185.511921]  ffff88020000b131 ffffffff00000004 ffff880000000001 ffff8802229ca090
> > [76185.513725]  ffff8802229ca000 ffffffffa04ab568 ffff88021bc27c30 ffffffffa04ab7a0
> > [76185.515517]  ffff88021866fbd8 ffffffff814eefcf 000000001866fbb0 ffff88021bc27c00
> > [76185.517248] Call Trace:
> > [76185.518963]  [<ffffffff814eefcf>] usb_probe_interface+0x1df/0x330
> > [76185.520714]  [<ffffffff8146605d>] driver_probe_device+0x12d/0x3d0
> > [76185.522452]  [<ffffffff814663d3>] __driver_attach+0x93/0xa0
> > [76185.524203]  [<ffffffff81466340>] ? __device_attach+0x40/0x40
> > [76185.525959]  [<ffffffff81463f03>] bus_for_each_dev+0x73/0xc0
> > [76185.527599]  [<ffffffff81465a5e>] driver_attach+0x1e/0x20
> > [76185.529240]  [<ffffffff81465640>] bus_add_driver+0x180/0x250
> > [76185.537278]  [<ffffffff81002144>] do_one_initcall+0xd4/0x210
> > [76185.538809]  [<ffffffff811b5fd4>] ? __vunmap+0x94/0x100
> > [76185.540330]  [<ffffffff81106767>] load_module+0x1ea7/0x24f0
> > [76185.541806]  [<ffffffff81102370>] ? store_uevent+0x70/0x70
> > [76185.543255]  [<ffffffff811f3200>] ? kernel_read+0x50/0x80
> > [76185.544661]  [<ffffffff81106f66>] SyS_finit_module+0xa6/0xd0
> > [76185.546047]  [<ffffffff816fc869>] system_call_fastpath+0x16/0x1b
> > [76185.547354] Code: 1d 00 00 85 ff 0f 8f 94 04 00 00 0f b6 93 bb 21 00 00 49 8b 87 68 03 00 00 48 89 de 48 c7 c7 08 75 4a a0 4c 8b 84 d0 a0 00 00 00 <49> 8b 00 4c 89 45 d0 48 8b 40 18 0f b6 40 02 0f b6 d0 66 89 93 
> > [76185.550208] RIP  [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
> > [76185.551613]  RSP <ffff88021866fb50>
> > [76185.553006] CR2: 0000000000000000
> > [76185.559997] ---[ end trace 1e58ef345d6b3f24 ]---
> > 
> 
> Is the order of the printk messages and of the oops message fixed? Are
> all messages printed before the oops also before the oops message?
> 
> It seems to oops is at cx231xx_usb_probe+0x5a8/0xb20.
> 
> > $ gdb drivers/media/usb/cx231xx/cx231xx.ko
> > GNU gdb (GDB) Fedora 7.7.1-15.fc20
> > Copyright (C) 2014 Free Software Foundation, Inc.
> > License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> > This is free software: you are free to change and redistribute it.
> > There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
> [...]
> > Type "apropos word" to search for commands related to "word"...
> > Reading symbols from drivers/media/usb/cx231xx/cx231xx.ko...done.
> > (gdb) list *cx231xx_usb_driver_init+0x1e
> 
> Could you retry this with the offset from above (0x5a8).

(gdb) list *cx231xx_usb_probe+0x5a8
0x4ec8 is in cx231xx_usb_probe (drivers/media/usb/cx231xx/cx231xx-cards.c:1432).
1427		uif = udev->actconfig->interface[dev->current_pcb_config.
1428					       hs_config_info[0].interface_info.
1429					       vanc_index + 1];
1430	
1431		dev->vbi_mode.end_point_addr =
1432		    uif->altsetting[0].endpoint[isoc_pipe].desc.
1433				bEndpointAddress;
1434	
1435		dev->vbi_mode.num_alt = uif->num_altsetting;
1436		cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",

> I normally use nm to get the base addr of the function, then add the
> offset and then run "addr2line -ispf -e cx231xx.ko -a 0x....."

Well, gdb is quicker, as it is just one command ;)

Regards,
Mauro

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

* Re: [PATCH 6/8] cx231xx: Add digital support for [2040:b131] Hauppauge WinTV 930C-HD (model 1114xx)
  2014-07-27 13:44       ` Mauro Carvalho Chehab
@ 2014-07-27 14:32         ` Mauro Carvalho Chehab
  2014-07-27 14:59           ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 26+ messages in thread
From: Mauro Carvalho Chehab @ 2014-07-27 14:32 UTC (permalink / raw)
  To: Matthias Schwarzott; +Cc: crope, linux-media

Em Sun, 27 Jul 2014 10:44:53 -0300
Mauro Carvalho Chehab <m.chehab@samsung.com> escreveu:

> Em Sun, 27 Jul 2014 11:32:26 +0200
> Matthias Schwarzott <zzam@gentoo.org> escreveu:
> 
> > 
> > Hi Mauro.
> > 
> > On 26.07.2014 21:27, Mauro Carvalho Chehab wrote:
> > > Tried to apply your patch series, but there's something wrong on it.
> > > 
> > > See the enclosed logs. I suspect that you missed a patch adding the
> > > proper tuner for this device.
> > 
> > well, tuner_type is set to TUNER_ABSENT, and for me the oops does not
> > happen.
> > 
> > > [76185.463359] BUG: unable to handle kernel NULL pointer dereference at           (null)
> > > [76185.465295] IP: [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
> > > [76185.465654] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)
> > > [76185.465705] cx231xx #0: called cx231xx_uninit_vbi_isoc
> > > [76185.465707] cx231xx #0: cx231xx_stop_stream():: ep_mask = 10
> > > [76185.465872] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)
> > > [76185.474837] PGD 21c0fa067 PUD 2182b4067 PMD 0 
> > > [76185.476593] Oops: 0000 [#1] SMP 
> > > [76185.478285] Modules linked in: cx25840 cx231xx(+) cx2341x tveeprom videobuf_vmalloc videobuf_core rc_core v4l2_common videodev media ip6table_filter ip6_tables bnep nouveau x86_pkg_temp_thermal coretemp i915 binfmt_misc kvm_intel kvm ttm i2c_algo_bit drm_kms_helper vfat fat drm arc4 iwldvm mac80211 snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic snd_hda_intel snd_hda_controller snd_hda_codec iwlwifi crct10dif_pclmul snd_hwdep crc32_pclmul cfg80211 snd_seq snd_seq_device snd_pcm crc32c_intel snd_timer btusb bluetooth iTCO_wdt iTCO_vendor_support mxm_wmi ghash_clmulni_intel lpc_ich i2c_i801 snd mei_me soundcore rfkill joydev serio_raw shpchp mei wmi mfd_core i2c_core video microcode r8169 mii [last unloaded: dvb_core]
> > > [76185.487219] CPU: 0 PID: 12079 Comm: modprobe Not tainted 3.16.0-rc6+ #12
> > > [76185.488936] Hardware name: SAMSUNG ELECTRONICS CO., LTD. 550P5C/550P7C/SAMSUNG_NP1234567890, BIOS P05ABI.016.130917.dg 09/17/2013
> > > [76185.490710] task: ffff880211172ee0 ti: ffff88021866c000 task.ti: ffff88021866c000
> > > [76185.492502] RIP: 0010:[<ffffffffa048dec8>]  [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
> > > [76185.494321] RSP: 0018:ffff88021866fb50  EFLAGS: 00010246
> > > [76185.496037] RAX: ffff88021c34fc00 RBX: ffff8800c4f70000 RCX: 0000000000000006
> > > [76185.497781] RDX: 0000000000000004 RSI: ffff8800c4f70000 RDI: ffffffffa04a7508
> > > [76185.499548] RBP: ffff88021866fb90 R08: 0000000000000000 R09: 00000000000011d3
> > > [76185.501323] R10: 0000000000000000 R11: ffff88021866f85e R12: ffff88021bc20800
> > > [76185.503119] R13: ffff88021bc27c00 R14: ffff8800c4f70168 R15: ffff8802229ca000
> > > [76185.504934] FS:  00007f6c13b2e740(0000) GS:ffff88022f200000(0000) knlGS:0000000000000000
> > > [76185.506662] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> > > [76185.508406] CR2: 0000000000000000 CR3: 00000002222b8000 CR4: 00000000001407f0
> > > [76185.510169] Stack:
> > > [76185.511921]  ffff88020000b131 ffffffff00000004 ffff880000000001 ffff8802229ca090
> > > [76185.513725]  ffff8802229ca000 ffffffffa04ab568 ffff88021bc27c30 ffffffffa04ab7a0
> > > [76185.515517]  ffff88021866fbd8 ffffffff814eefcf 000000001866fbb0 ffff88021bc27c00
> > > [76185.517248] Call Trace:
> > > [76185.518963]  [<ffffffff814eefcf>] usb_probe_interface+0x1df/0x330
> > > [76185.520714]  [<ffffffff8146605d>] driver_probe_device+0x12d/0x3d0
> > > [76185.522452]  [<ffffffff814663d3>] __driver_attach+0x93/0xa0
> > > [76185.524203]  [<ffffffff81466340>] ? __device_attach+0x40/0x40
> > > [76185.525959]  [<ffffffff81463f03>] bus_for_each_dev+0x73/0xc0
> > > [76185.527599]  [<ffffffff81465a5e>] driver_attach+0x1e/0x20
> > > [76185.529240]  [<ffffffff81465640>] bus_add_driver+0x180/0x250
> > > [76185.537278]  [<ffffffff81002144>] do_one_initcall+0xd4/0x210
> > > [76185.538809]  [<ffffffff811b5fd4>] ? __vunmap+0x94/0x100
> > > [76185.540330]  [<ffffffff81106767>] load_module+0x1ea7/0x24f0
> > > [76185.541806]  [<ffffffff81102370>] ? store_uevent+0x70/0x70
> > > [76185.543255]  [<ffffffff811f3200>] ? kernel_read+0x50/0x80
> > > [76185.544661]  [<ffffffff81106f66>] SyS_finit_module+0xa6/0xd0
> > > [76185.546047]  [<ffffffff816fc869>] system_call_fastpath+0x16/0x1b
> > > [76185.547354] Code: 1d 00 00 85 ff 0f 8f 94 04 00 00 0f b6 93 bb 21 00 00 49 8b 87 68 03 00 00 48 89 de 48 c7 c7 08 75 4a a0 4c 8b 84 d0 a0 00 00 00 <49> 8b 00 4c 89 45 d0 48 8b 40 18 0f b6 40 02 0f b6 d0 66 89 93 
> > > [76185.550208] RIP  [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
> > > [76185.551613]  RSP <ffff88021866fb50>
> > > [76185.553006] CR2: 0000000000000000
> > > [76185.559997] ---[ end trace 1e58ef345d6b3f24 ]---
> > > 
> > 
> > Is the order of the printk messages and of the oops message fixed? Are
> > all messages printed before the oops also before the oops message?
> > 
> > It seems to oops is at cx231xx_usb_probe+0x5a8/0xb20.
> > 
> > > $ gdb drivers/media/usb/cx231xx/cx231xx.ko
> > > GNU gdb (GDB) Fedora 7.7.1-15.fc20
> > > Copyright (C) 2014 Free Software Foundation, Inc.
> > > License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> > > This is free software: you are free to change and redistribute it.
> > > There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
> > [...]
> > > Type "apropos word" to search for commands related to "word"...
> > > Reading symbols from drivers/media/usb/cx231xx/cx231xx.ko...done.
> > > (gdb) list *cx231xx_usb_driver_init+0x1e
> > 
> > Could you retry this with the offset from above (0x5a8).
> 
> (gdb) list *cx231xx_usb_probe+0x5a8
> 0x4ec8 is in cx231xx_usb_probe (drivers/media/usb/cx231xx/cx231xx-cards.c:1432).
> 1427		uif = udev->actconfig->interface[dev->current_pcb_config.
> 1428					       hs_config_info[0].interface_info.
> 1429					       vanc_index + 1];
> 1430	
> 1431		dev->vbi_mode.end_point_addr =
> 1432		    uif->altsetting[0].endpoint[isoc_pipe].desc.
> 1433				bEndpointAddress;
> 1434	
> 1435		dev->vbi_mode.num_alt = uif->num_altsetting;
> 1436		cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
> 
> > I normally use nm to get the base addr of the function, then add the
> > offset and then run "addr2line -ispf -e cx231xx.ko -a 0x....."
> 
> Well, gdb is quicker, as it is just one command ;)

I found the issue. there are just two interfaces on this device, but 
vanc_index is equal to 4 for this PCB. So, it tries to set VBI on
interface 5, with obviously fails.

It seems that the code is identifying a wrong PCB for this device.

That's said, the probe logic is doing a crap job by allowing to go
past the array.

Regards,
Mauro

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

* Re: [PATCH 6/8] cx231xx: Add digital support for [2040:b131] Hauppauge WinTV 930C-HD (model 1114xx)
  2014-07-27 14:32         ` Mauro Carvalho Chehab
@ 2014-07-27 14:59           ` Mauro Carvalho Chehab
  2014-07-27 19:42             ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 26+ messages in thread
From: Mauro Carvalho Chehab @ 2014-07-27 14:59 UTC (permalink / raw)
  To: Matthias Schwarzott; +Cc: crope, linux-media

Em Sun, 27 Jul 2014 11:32:48 -0300
Mauro Carvalho Chehab <m.chehab@samsung.com> escreveu:

> Em Sun, 27 Jul 2014 10:44:53 -0300
> Mauro Carvalho Chehab <m.chehab@samsung.com> escreveu:
> 
> > Em Sun, 27 Jul 2014 11:32:26 +0200
> > Matthias Schwarzott <zzam@gentoo.org> escreveu:
> > 
> > > 
> > > Hi Mauro.
> > > 
> > > On 26.07.2014 21:27, Mauro Carvalho Chehab wrote:
> > > > Tried to apply your patch series, but there's something wrong on it.
> > > > 
> > > > See the enclosed logs. I suspect that you missed a patch adding the
> > > > proper tuner for this device.
> > > 
> > > well, tuner_type is set to TUNER_ABSENT, and for me the oops does not
> > > happen.
> > > 
> > > > [76185.463359] BUG: unable to handle kernel NULL pointer dereference at           (null)
> > > > [76185.465295] IP: [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
> > > > [76185.465654] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)
> > > > [76185.465705] cx231xx #0: called cx231xx_uninit_vbi_isoc
> > > > [76185.465707] cx231xx #0: cx231xx_stop_stream():: ep_mask = 10
> > > > [76185.465872] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)
> > > > [76185.474837] PGD 21c0fa067 PUD 2182b4067 PMD 0 
> > > > [76185.476593] Oops: 0000 [#1] SMP 
> > > > [76185.478285] Modules linked in: cx25840 cx231xx(+) cx2341x tveeprom videobuf_vmalloc videobuf_core rc_core v4l2_common videodev media ip6table_filter ip6_tables bnep nouveau x86_pkg_temp_thermal coretemp i915 binfmt_misc kvm_intel kvm ttm i2c_algo_bit drm_kms_helper vfat fat drm arc4 iwldvm mac80211 snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic snd_hda_intel snd_hda_controller snd_hda_codec iwlwifi crct10dif_pclmul snd_hwdep crc32_pclmul cfg80211 snd_seq snd_seq_device snd_pcm crc32c_intel snd_timer btusb bluetooth iTCO_wdt iTCO_vendor_support mxm_wmi ghash_clmulni_intel lpc_ich i2c_i801 snd mei_me soundcore rfkill joydev serio_raw shpchp mei wmi mfd_core i2c_core video microcode r8169 mii [last unloaded: dvb_core]
> > > > [76185.487219] CPU: 0 PID: 12079 Comm: modprobe Not tainted 3.16.0-rc6+ #12
> > > > [76185.488936] Hardware name: SAMSUNG ELECTRONICS CO., LTD. 550P5C/550P7C/SAMSUNG_NP1234567890, BIOS P05ABI.016.130917.dg 09/17/2013
> > > > [76185.490710] task: ffff880211172ee0 ti: ffff88021866c000 task.ti: ffff88021866c000
> > > > [76185.492502] RIP: 0010:[<ffffffffa048dec8>]  [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
> > > > [76185.494321] RSP: 0018:ffff88021866fb50  EFLAGS: 00010246
> > > > [76185.496037] RAX: ffff88021c34fc00 RBX: ffff8800c4f70000 RCX: 0000000000000006
> > > > [76185.497781] RDX: 0000000000000004 RSI: ffff8800c4f70000 RDI: ffffffffa04a7508
> > > > [76185.499548] RBP: ffff88021866fb90 R08: 0000000000000000 R09: 00000000000011d3
> > > > [76185.501323] R10: 0000000000000000 R11: ffff88021866f85e R12: ffff88021bc20800
> > > > [76185.503119] R13: ffff88021bc27c00 R14: ffff8800c4f70168 R15: ffff8802229ca000
> > > > [76185.504934] FS:  00007f6c13b2e740(0000) GS:ffff88022f200000(0000) knlGS:0000000000000000
> > > > [76185.506662] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> > > > [76185.508406] CR2: 0000000000000000 CR3: 00000002222b8000 CR4: 00000000001407f0
> > > > [76185.510169] Stack:
> > > > [76185.511921]  ffff88020000b131 ffffffff00000004 ffff880000000001 ffff8802229ca090
> > > > [76185.513725]  ffff8802229ca000 ffffffffa04ab568 ffff88021bc27c30 ffffffffa04ab7a0
> > > > [76185.515517]  ffff88021866fbd8 ffffffff814eefcf 000000001866fbb0 ffff88021bc27c00
> > > > [76185.517248] Call Trace:
> > > > [76185.518963]  [<ffffffff814eefcf>] usb_probe_interface+0x1df/0x330
> > > > [76185.520714]  [<ffffffff8146605d>] driver_probe_device+0x12d/0x3d0
> > > > [76185.522452]  [<ffffffff814663d3>] __driver_attach+0x93/0xa0
> > > > [76185.524203]  [<ffffffff81466340>] ? __device_attach+0x40/0x40
> > > > [76185.525959]  [<ffffffff81463f03>] bus_for_each_dev+0x73/0xc0
> > > > [76185.527599]  [<ffffffff81465a5e>] driver_attach+0x1e/0x20
> > > > [76185.529240]  [<ffffffff81465640>] bus_add_driver+0x180/0x250
> > > > [76185.537278]  [<ffffffff81002144>] do_one_initcall+0xd4/0x210
> > > > [76185.538809]  [<ffffffff811b5fd4>] ? __vunmap+0x94/0x100
> > > > [76185.540330]  [<ffffffff81106767>] load_module+0x1ea7/0x24f0
> > > > [76185.541806]  [<ffffffff81102370>] ? store_uevent+0x70/0x70
> > > > [76185.543255]  [<ffffffff811f3200>] ? kernel_read+0x50/0x80
> > > > [76185.544661]  [<ffffffff81106f66>] SyS_finit_module+0xa6/0xd0
> > > > [76185.546047]  [<ffffffff816fc869>] system_call_fastpath+0x16/0x1b
> > > > [76185.547354] Code: 1d 00 00 85 ff 0f 8f 94 04 00 00 0f b6 93 bb 21 00 00 49 8b 87 68 03 00 00 48 89 de 48 c7 c7 08 75 4a a0 4c 8b 84 d0 a0 00 00 00 <49> 8b 00 4c 89 45 d0 48 8b 40 18 0f b6 40 02 0f b6 d0 66 89 93 
> > > > [76185.550208] RIP  [<ffffffffa048dec8>] cx231xx_usb_probe+0x5a8/0xb20 [cx231xx]
> > > > [76185.551613]  RSP <ffff88021866fb50>
> > > > [76185.553006] CR2: 0000000000000000
> > > > [76185.559997] ---[ end trace 1e58ef345d6b3f24 ]---
> > > > 
> > > 
> > > Is the order of the printk messages and of the oops message fixed? Are
> > > all messages printed before the oops also before the oops message?
> > > 
> > > It seems to oops is at cx231xx_usb_probe+0x5a8/0xb20.
> > > 
> > > > $ gdb drivers/media/usb/cx231xx/cx231xx.ko
> > > > GNU gdb (GDB) Fedora 7.7.1-15.fc20
> > > > Copyright (C) 2014 Free Software Foundation, Inc.
> > > > License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> > > > This is free software: you are free to change and redistribute it.
> > > > There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
> > > [...]
> > > > Type "apropos word" to search for commands related to "word"...
> > > > Reading symbols from drivers/media/usb/cx231xx/cx231xx.ko...done.
> > > > (gdb) list *cx231xx_usb_driver_init+0x1e
> > > 
> > > Could you retry this with the offset from above (0x5a8).
> > 
> > (gdb) list *cx231xx_usb_probe+0x5a8
> > 0x4ec8 is in cx231xx_usb_probe (drivers/media/usb/cx231xx/cx231xx-cards.c:1432).
> > 1427		uif = udev->actconfig->interface[dev->current_pcb_config.
> > 1428					       hs_config_info[0].interface_info.
> > 1429					       vanc_index + 1];
> > 1430	
> > 1431		dev->vbi_mode.end_point_addr =
> > 1432		    uif->altsetting[0].endpoint[isoc_pipe].desc.
> > 1433				bEndpointAddress;
> > 1434	
> > 1435		dev->vbi_mode.num_alt = uif->num_altsetting;
> > 1436		cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
> > 
> > > I normally use nm to get the base addr of the function, then add the
> > > offset and then run "addr2line -ispf -e cx231xx.ko -a 0x....."
> > 
> > Well, gdb is quicker, as it is just one command ;)
> 
> I found the issue. there are just two interfaces on this device, but 

Actually there are 4 interfaces. Still, 5 is out of the array.

> vanc_index is equal to 4 for this PCB. So, it tries to set VBI on
> interface 5, with obviously fails.
> 
> It seems that the code is identifying a wrong PCB for this device.
> 
> That's said, the probe logic is doing a crap job by allowing to go
> past the array.

Just sent a patch detecting this condition and aborting the probe.
That solved the OOPS, but, of course, the device doesn't work.

See the logs.

[  326.546032] usb 3-4: new full-speed USB device number 2 using xhci_hcd
[  326.710374] usb 3-4: not running at top speed; connect to a high speed hub
[  326.713276] usb 3-4: New USB device found, idVendor=2040, idProduct=b131
[  326.713284] usb 3-4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  326.713288] usb 3-4: Product: Hauppauge Device
[  326.713291] usb 3-4: Manufacturer: Hauppauge
[  326.713294] usb 3-4: SerialNumber: 4035169112
[  326.770414] cx231xx #0: New device Hauppauge Hauppauge Device @ 12 Mbps (2040:b131) with 4 interfaces
[  326.770420] cx231xx #0: registering interface 1
[  326.770499] cx231xx #0: Identified as Hauppauge WinTV 930C-HD (1114xx) / PCTV QuatroStick 522e (card=20)
[  326.871215] cx231xx #0: cx231xx_dif_set_standard: setStandard to ffffffff
[  326.879356] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)
[  326.879363] cx231xx #0: can't change interface 6 alt no. to 0 (err=-22)
[  326.890080] cx25840 19-0044: cx23102 A/V decoder found @ 0x88 (cx231xx #0)
[  326.909307] cx25840 19-0044:  Firmware download size changed to 16 bytes max length
[  328.991008] cx25840 19-0044: loaded v4l-cx231xx-avcore-01.fw firmware (16382 bytes)
[  329.028463] cx231xx #0: Changing the i2c master port to 1
[  329.060338] cx231xx #0: Changing the i2c master port to 3
[  329.060404] cx231xx #0: i2c eeprom 00: 40 20 31 b1 aa 00 00 01 10 00 50 00 30 00 ff ff
[  329.060410] cx231xx #0: i2c eeprom 10: 14 03 48 00 61 00 75 00 70 00 70 00 61 00 75 00
[  329.060413] cx231xx #0: i2c eeprom 20: 67 00 65 00 00 00 00 00 00 00 00 00 00 00 00 00
[  329.060416] cx231xx #0: i2c eeprom 30: 16 03 34 00 30 00 33 00 35 00 31 00 36 00 39 00
[  329.060419] cx231xx #0: i2c eeprom 40: 31 00 31 00 32 00 00 00 ff ff ff ff ff ff ff ff
[  329.060423] cx231xx #0: i2c eeprom 50: 22 03 48 00 61 00 75 00 70 00 70 00 61 00 75 00
[  329.060426] cx231xx #0: i2c eeprom 60: 67 00 65 00 20 00 44 00 65 00 76 00 69 00 63 00
[  329.060429] cx231xx #0: i2c eeprom 70: 65 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[  329.060433] cx231xx #0: i2c eeprom 80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[  329.060436] cx231xx #0: i2c eeprom 90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[  329.060440] cx231xx #0: i2c eeprom a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[  329.060444] cx231xx #0: i2c eeprom b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[  329.060447] cx231xx #0: i2c eeprom c0: 84 09 00 04 20 77 00 40 58 cb 83 f0 73 05 2f 00
[  329.060450] cx231xx #0: i2c eeprom d0: 84 08 00 06 3b b3 01 00 56 2a 95 72 07 70 73 09
[  329.060453] cx231xx #0: i2c eeprom e0: 2e 7f 73 0a f4 ba 72 0b 13 72 0f 05 72 10 01 72
[  329.060457] cx231xx #0: i2c eeprom f0: 11 1f 73 13 eb 79 79 ea 00 00 00 00 00 00 00 00
[  329.060464] tveeprom 20-0000: Hauppauge model 111419, rev E2I6, serial# 8637272
[  329.060470] tveeprom 20-0000: MAC address is 00:0d:fe:83:cb:58
[  329.060474] tveeprom 20-0000: tuner model is unknown (idx 186, type 4)
[  329.060479] tveeprom 20-0000: TV standards PAL(B/G) PAL(I) SECAM(L/L') PAL(D/D1/K) ATSC/DVB Digital (eeprom 0xf4)
[  329.060483] tveeprom 20-0000: audio processor is unknown (idx 47)
[  329.060486] tveeprom 20-0000: decoder processor is unknown (idx 46)
[  329.060490] tveeprom 20-0000: has no radio, has IR receiver, has no IR transmitter
[  329.061545] cx231xx #0: cx231xx #0: v4l2 driver version 0.0.2
[  329.078247] cx231xx #0: cx231xx_dif_set_standard: setStandard to ffffffff
[  329.116882] Unknown tuner type configuring SIF
[  329.118011] cx231xx #0: video_mux : 0
[  329.118043] cx231xx #0: do_mode_ctrl_overrides : 0xff
[  329.118802] cx231xx #0: do_mode_ctrl_overrides PAL
[  329.145116] cx231xx #0: cx231xx #0/0: registered device video1 [v4l2]
[  329.145290] cx231xx #0: cx231xx #0/0: registered device vbi0
[  329.145294] cx231xx #0: V4L2 device registered as video1 and vbi0
[  329.145296] cx231xx #0: Video PCB interface #4 doesn't exist
[  329.145372] usbcore: registered new interface driver cx231xx
[  329.148408] cx231xx #0:  setPowerMode::mode = 32, No Change req.
[  329.148418] usb 3-4: selecting invalid altsetting 3
[  329.148421] cx231xx #0: cannot change alt number to 3 (error=-22)
[  329.149508] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)
[  329.149570] cx231xx #0: called cx231xx_uninit_vbi_isoc
[  329.149574] cx231xx #0: cx231xx_stop_stream():: ep_mask = 10
[  329.149721] cx231xx #0: can't change interface 5 alt no. to 0 (err=-22)



> 
> Regards,
> Mauro
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 6/8] cx231xx: Add digital support for [2040:b131] Hauppauge WinTV 930C-HD (model 1114xx)
  2014-07-27 14:59           ` Mauro Carvalho Chehab
@ 2014-07-27 19:42             ` Mauro Carvalho Chehab
  2014-07-29  5:39               ` Matthias Schwarzott
  0 siblings, 1 reply; 26+ messages in thread
From: Mauro Carvalho Chehab @ 2014-07-27 19:42 UTC (permalink / raw)
  To: Matthias Schwarzott; +Cc: crope, linux-media

Em Sun, 27 Jul 2014 11:59:11 -0300
Mauro Carvalho Chehab <m.chehab@samsung.com> escreveu:

> Em Sun, 27 Jul 2014 11:32:48 -0300
> Mauro Carvalho Chehab <m.chehab@samsung.com> escreveu:
> 
> > Em Sun, 27 Jul 2014 10:44:53 -0300
> > Mauro Carvalho Chehab <m.chehab@samsung.com> escreveu:
> > 
> > > Em Sun, 27 Jul 2014 11:32:26 +0200
> > > Matthias Schwarzott <zzam@gentoo.org> escreveu:
> > > 
> > > > 
> > > > Hi Mauro.
> > > > 
> > > > On 26.07.2014 21:27, Mauro Carvalho Chehab wrote:
> > > > > Tried to apply your patch series, but there's something wrong on it.
> > > > > 
> > > > > See the enclosed logs. I suspect that you missed a patch adding the
> > > > > proper tuner for this device.

The hole issue was due to that:
> [  326.770414] cx231xx #0: New device Hauppauge Hauppauge Device @ 12 Mbps (2040:b131) with 4 interfaces

The root cause seems to be a bad USB cable, causing errors at USB
detection.

Just send a patch series that avoids the driver to OOPS in such
case.

Regards,
Mauro

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

* Re: [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165
  2014-07-23 20:10       ` Antonio Ospite
@ 2014-07-29  5:37         ` Matthias Schwarzott
  2014-07-29  8:53           ` Antonio Ospite
  0 siblings, 1 reply; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-29  5:37 UTC (permalink / raw)
  To: Antonio Ospite; +Cc: Antti Palosaari, m.chehab, linux-media

On 23.07.2014 22:10, Antonio Ospite wrote:
> On Wed, 23 Jul 2014 21:03:14 +0200
> Matthias Schwarzott <zzam@gentoo.org> wrote:
> 
> [...]
>> The crc value:
>> It protects the content of the file until it is in the demod - so
>> calculating it on my own would only check if the data is correctly
>> transferred from the driver into the chip.
>> But for this I needed to know the algorithm and which data is
>> checksummed exactly.
>>
>> Are the different algorithms for CRC values that give 16 bit of output?
>>
> 
> You could try jacksum[1] and see if any algorithm it supports
> gives you the expected result, there is a handful of 16 bits ones:
> 
>   jacksum -a all -F "#ALGONAME{i} = #CHECKSUM{i}" payload.bin
> 
Hi Antonio,

I tried jacksum on the complete firmware and on parts - but it never
matched the results from the chip.

I now found out, that the crc register changes after every 32bit write
to the data register - the fw control registers do not affect it.

So I can try what crc results from writing 32bit portions of data.
But even that did not help in guessing the algorithm, because I do not
want to do 100s of experiments.

some of my experiments:
crc=0x0000, data=0x00000000 -> crc=0x0000
crc=0x0000, data=0x00000001 -> crc=0x1021
crc=0x0000, data=0x00000002 -> crc=0x2042
crc=0x0000, data=0x00000004 -> crc=0x4084
crc=0x0000, data=0x00000008 -> crc=0x8108
crc=0x0000, data=0x00000010 -> crc=0x1231

Is there some systematic way to get the formula?
I can write arbitrary data and check what crc it results in.

I don't know if it is worth using the crc algorithm compared to storing
the crc with the firmware, because currently it is an end to end
verification of firmware data.

Regards
Matthias


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

* Re: [PATCH 6/8] cx231xx: Add digital support for [2040:b131] Hauppauge WinTV 930C-HD (model 1114xx)
  2014-07-27 19:42             ` Mauro Carvalho Chehab
@ 2014-07-29  5:39               ` Matthias Schwarzott
  0 siblings, 0 replies; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-29  5:39 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: crope, linux-media

On 27.07.2014 21:42, Mauro Carvalho Chehab wrote:
> Em Sun, 27 Jul 2014 11:59:11 -0300
> Mauro Carvalho Chehab <m.chehab@samsung.com> escreveu:
> 
>> Em Sun, 27 Jul 2014 11:32:48 -0300
>> Mauro Carvalho Chehab <m.chehab@samsung.com> escreveu:
>>
>>> Em Sun, 27 Jul 2014 10:44:53 -0300
>>> Mauro Carvalho Chehab <m.chehab@samsung.com> escreveu:
>>>
>>>> Em Sun, 27 Jul 2014 11:32:26 +0200
>>>> Matthias Schwarzott <zzam@gentoo.org> escreveu:
>>>>
>>>>>
>>>>> Hi Mauro.
>>>>>
>>>>> On 26.07.2014 21:27, Mauro Carvalho Chehab wrote:
>>>>>> Tried to apply your patch series, but there's something wrong on it.
>>>>>>
>>>>>> See the enclosed logs. I suspect that you missed a patch adding the
>>>>>> proper tuner for this device.
> 
> The hole issue was due to that:
>> [  326.770414] cx231xx #0: New device Hauppauge Hauppauge Device @ 12 Mbps (2040:b131) with 4 interfaces
> 
> The root cause seems to be a bad USB cable, causing errors at USB
> detection.
> 
> Just send a patch series that avoids the driver to OOPS in such
> case.
> 

Ah, now I understand why this specific device did not work.
Nice errors that can be triggered by faulty hardware.

Regards
Matthias


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

* Re: [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165
  2014-07-29  5:37         ` Matthias Schwarzott
@ 2014-07-29  8:53           ` Antonio Ospite
  2014-07-29 11:34             ` Antti Palosaari
  0 siblings, 1 reply; 26+ messages in thread
From: Antonio Ospite @ 2014-07-29  8:53 UTC (permalink / raw)
  To: Matthias Schwarzott; +Cc: Antti Palosaari, m.chehab, linux-media

On Tue, 29 Jul 2014 07:37:44 +0200
Matthias Schwarzott <zzam@gentoo.org> wrote:

> On 23.07.2014 22:10, Antonio Ospite wrote:
> > On Wed, 23 Jul 2014 21:03:14 +0200
> > Matthias Schwarzott <zzam@gentoo.org> wrote:
> > 
> > [...]
> >> The crc value:
> >> It protects the content of the file until it is in the demod - so
> >> calculating it on my own would only check if the data is correctly
> >> transferred from the driver into the chip.
> >> But for this I needed to know the algorithm and which data is
> >> checksummed exactly.
> >>
> >> Are the different algorithms for CRC values that give 16 bit of output?
> >>
> > 
> > You could try jacksum[1] and see if any algorithm it supports
> > gives you the expected result, there is a handful of 16 bits ones:
> > 
> >   jacksum -a all -F "#ALGONAME{i} = #CHECKSUM{i}" payload.bin
> > 
> Hi Antonio,
> 
> I tried jacksum on the complete firmware and on parts - but it never
> matched the results from the chip.
> 
> I now found out, that the crc register changes after every 32bit write
> to the data register - the fw control registers do not affect it.
> 
> So I can try what crc results from writing 32bit portions of data.
> But even that did not help in guessing the algorithm, because I do not
> want to do 100s of experiments.
> 
> some of my experiments:
> crc=0x0000, data=0x00000000 -> crc=0x0000
> crc=0x0000, data=0x00000001 -> crc=0x1021
> crc=0x0000, data=0x00000002 -> crc=0x2042
> crc=0x0000, data=0x00000004 -> crc=0x4084
> crc=0x0000, data=0x00000008 -> crc=0x8108
> crc=0x0000, data=0x00000010 -> crc=0x1231
> 
> Is there some systematic way to get the formula?

I don't know much about crc, but the values you are getting look like
the entries in the table in lib/crc-itu-t.c so maybe compare the crc
you are getting with the ones calculated with crc_itu_t() from
include/linux/crc-itu-t.h

I just did a quick test with jacksum, the crc-itu-t parameters can
be expressed like this:

	jacksum -x -a crc:16,1021,0,false,false,0 -q 00000010

and the output is the expected 0x1231 for the 0x00000010 sequence.

[...]

Ciao,
   Antonio

-- 
Antonio Ospite
http://ao2.it

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?

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

* Re: [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165
  2014-07-29  8:53           ` Antonio Ospite
@ 2014-07-29 11:34             ` Antti Palosaari
  2014-07-29 19:22               ` Matthias Schwarzott
  0 siblings, 1 reply; 26+ messages in thread
From: Antti Palosaari @ 2014-07-29 11:34 UTC (permalink / raw)
  To: Antonio Ospite, Matthias Schwarzott; +Cc: m.chehab, linux-media



On 07/29/2014 11:53 AM, Antonio Ospite wrote:
> On Tue, 29 Jul 2014 07:37:44 +0200
> Matthias Schwarzott <zzam@gentoo.org> wrote:
>
>> On 23.07.2014 22:10, Antonio Ospite wrote:
>>> On Wed, 23 Jul 2014 21:03:14 +0200
>>> Matthias Schwarzott <zzam@gentoo.org> wrote:
>>>
>>> [...]
>>>> The crc value:
>>>> It protects the content of the file until it is in the demod - so
>>>> calculating it on my own would only check if the data is correctly
>>>> transferred from the driver into the chip.
>>>> But for this I needed to know the algorithm and which data is
>>>> checksummed exactly.
>>>>
>>>> Are the different algorithms for CRC values that give 16 bit of output?
>>>>
>>>
>>> You could try jacksum[1] and see if any algorithm it supports
>>> gives you the expected result, there is a handful of 16 bits ones:
>>>
>>>    jacksum -a all -F "#ALGONAME{i} = #CHECKSUM{i}" payload.bin
>>>
>> Hi Antonio,
>>
>> I tried jacksum on the complete firmware and on parts - but it never
>> matched the results from the chip.
>>
>> I now found out, that the crc register changes after every 32bit write
>> to the data register - the fw control registers do not affect it.
>>
>> So I can try what crc results from writing 32bit portions of data.
>> But even that did not help in guessing the algorithm, because I do not
>> want to do 100s of experiments.
>>
>> some of my experiments:
>> crc=0x0000, data=0x00000000 -> crc=0x0000
>> crc=0x0000, data=0x00000001 -> crc=0x1021
>> crc=0x0000, data=0x00000002 -> crc=0x2042
>> crc=0x0000, data=0x00000004 -> crc=0x4084
>> crc=0x0000, data=0x00000008 -> crc=0x8108
>> crc=0x0000, data=0x00000010 -> crc=0x1231
>>
>> Is there some systematic way to get the formula?
>
> I don't know much about crc, but the values you are getting look like
> the entries in the table in lib/crc-itu-t.c so maybe compare the crc
> you are getting with the ones calculated with crc_itu_t() from
> include/linux/crc-itu-t.h
>
> I just did a quick test with jacksum, the crc-itu-t parameters can
> be expressed like this:
>
> 	jacksum -x -a crc:16,1021,0,false,false,0 -q 00000010
>
> and the output is the expected 0x1231 for the 0x00000010 sequence.

maybe crc = crc + crc(val)


Antti


-- 
http://palosaari.fi/

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

* Re: [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165
  2014-07-29 11:34             ` Antti Palosaari
@ 2014-07-29 19:22               ` Matthias Schwarzott
  2014-07-29 19:45                 ` Antti Palosaari
  0 siblings, 1 reply; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-29 19:22 UTC (permalink / raw)
  To: Antti Palosaari, Antonio Ospite; +Cc: m.chehab, linux-media

On 29.07.2014 13:34, Antti Palosaari wrote:
> 
> 
> On 07/29/2014 11:53 AM, Antonio Ospite wrote:
>> On Tue, 29 Jul 2014 07:37:44 +0200
>> Matthias Schwarzott <zzam@gentoo.org> wrote:
>>
>>> On 23.07.2014 22:10, Antonio Ospite wrote:
>>>> On Wed, 23 Jul 2014 21:03:14 +0200
>>>> Matthias Schwarzott <zzam@gentoo.org> wrote:
>>>>
>>>> [...]
>>>>> The crc value:
>>>>> It protects the content of the file until it is in the demod - so
>>>>> calculating it on my own would only check if the data is correctly
>>>>> transferred from the driver into the chip.
>>>>> But for this I needed to know the algorithm and which data is
>>>>> checksummed exactly.
>>>>>
>>>>> Are the different algorithms for CRC values that give 16 bit of
>>>>> output?
>>>>>
>>>>
>>>> You could try jacksum[1] and see if any algorithm it supports
>>>> gives you the expected result, there is a handful of 16 bits ones:
>>>>
>>>>    jacksum -a all -F "#ALGONAME{i} = #CHECKSUM{i}" payload.bin
>>>>
>>> Hi Antonio,
>>>
>>> I tried jacksum on the complete firmware and on parts - but it never
>>> matched the results from the chip.
>>>
>>> I now found out, that the crc register changes after every 32bit write
>>> to the data register - the fw control registers do not affect it.
>>>
>>> So I can try what crc results from writing 32bit portions of data.
>>> But even that did not help in guessing the algorithm, because I do not
>>> want to do 100s of experiments.
>>>
>>> some of my experiments:
>>> crc=0x0000, data=0x00000000 -> crc=0x0000
>>> crc=0x0000, data=0x00000001 -> crc=0x1021
>>> crc=0x0000, data=0x00000002 -> crc=0x2042
>>> crc=0x0000, data=0x00000004 -> crc=0x4084
>>> crc=0x0000, data=0x00000008 -> crc=0x8108
>>> crc=0x0000, data=0x00000010 -> crc=0x1231
>>>
>>> Is there some systematic way to get the formula?
>>
>> I don't know much about crc, but the values you are getting look like
>> the entries in the table in lib/crc-itu-t.c so maybe compare the crc
>> you are getting with the ones calculated with crc_itu_t() from
>> include/linux/crc-itu-t.h
>>
>> I just did a quick test with jacksum, the crc-itu-t parameters can
>> be expressed like this:
>>
>>     jacksum -x -a crc:16,1021,0,false,false,0 -q 00000010
>>
>> and the output is the expected 0x1231 for the 0x00000010 sequence.
> 
> maybe crc = crc + crc(val)
> 
It worked to apply crc_itu_t to the written data in 32bit blocks,
but starting with the last byte:

			crc = crc_itu_t_byte(crc, *(data+offset+3));
			crc = crc_itu_t_byte(crc, *(data+offset+2));
			crc = crc_itu_t_byte(crc, *(data+offset+1));
			crc = crc_itu_t_byte(crc, *(data+offset+0));

It would also have worked without knowing the crc because it is only
actively read and compared in the driver - but better to know if upload
did work.

Now I am still not sure if it is worth to change the firmware file to
now have the crc explicitly.
Counting blocks is also easy todo.
But the firmware version is not inside the data I think.

So there will still remain something to be added to the raw data.

Regards
Matthias


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

* Re: [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165
  2014-07-29 19:22               ` Matthias Schwarzott
@ 2014-07-29 19:45                 ` Antti Palosaari
  2014-07-30 18:50                   ` Matthias Schwarzott
  0 siblings, 1 reply; 26+ messages in thread
From: Antti Palosaari @ 2014-07-29 19:45 UTC (permalink / raw)
  To: Matthias Schwarzott, Antonio Ospite; +Cc: m.chehab, linux-media



On 07/29/2014 10:22 PM, Matthias Schwarzott wrote:
> On 29.07.2014 13:34, Antti Palosaari wrote:
>>
>>
>> On 07/29/2014 11:53 AM, Antonio Ospite wrote:
>>> On Tue, 29 Jul 2014 07:37:44 +0200
>>> Matthias Schwarzott <zzam@gentoo.org> wrote:
>>>
>>>> On 23.07.2014 22:10, Antonio Ospite wrote:
>>>>> On Wed, 23 Jul 2014 21:03:14 +0200
>>>>> Matthias Schwarzott <zzam@gentoo.org> wrote:
>>>>>
>>>>> [...]
>>>>>> The crc value:
>>>>>> It protects the content of the file until it is in the demod - so
>>>>>> calculating it on my own would only check if the data is correctly
>>>>>> transferred from the driver into the chip.
>>>>>> But for this I needed to know the algorithm and which data is
>>>>>> checksummed exactly.
>>>>>>
>>>>>> Are the different algorithms for CRC values that give 16 bit of
>>>>>> output?
>>>>>>
>>>>>
>>>>> You could try jacksum[1] and see if any algorithm it supports
>>>>> gives you the expected result, there is a handful of 16 bits ones:
>>>>>
>>>>>     jacksum -a all -F "#ALGONAME{i} = #CHECKSUM{i}" payload.bin
>>>>>
>>>> Hi Antonio,
>>>>
>>>> I tried jacksum on the complete firmware and on parts - but it never
>>>> matched the results from the chip.
>>>>
>>>> I now found out, that the crc register changes after every 32bit write
>>>> to the data register - the fw control registers do not affect it.
>>>>
>>>> So I can try what crc results from writing 32bit portions of data.
>>>> But even that did not help in guessing the algorithm, because I do not
>>>> want to do 100s of experiments.
>>>>
>>>> some of my experiments:
>>>> crc=0x0000, data=0x00000000 -> crc=0x0000
>>>> crc=0x0000, data=0x00000001 -> crc=0x1021
>>>> crc=0x0000, data=0x00000002 -> crc=0x2042
>>>> crc=0x0000, data=0x00000004 -> crc=0x4084
>>>> crc=0x0000, data=0x00000008 -> crc=0x8108
>>>> crc=0x0000, data=0x00000010 -> crc=0x1231
>>>>
>>>> Is there some systematic way to get the formula?
>>>
>>> I don't know much about crc, but the values you are getting look like
>>> the entries in the table in lib/crc-itu-t.c so maybe compare the crc
>>> you are getting with the ones calculated with crc_itu_t() from
>>> include/linux/crc-itu-t.h
>>>
>>> I just did a quick test with jacksum, the crc-itu-t parameters can
>>> be expressed like this:
>>>
>>>      jacksum -x -a crc:16,1021,0,false,false,0 -q 00000010
>>>
>>> and the output is the expected 0x1231 for the 0x00000010 sequence.
>>
>> maybe crc = crc + crc(val)
>>
> It worked to apply crc_itu_t to the written data in 32bit blocks,
> but starting with the last byte:
>
> 			crc = crc_itu_t_byte(crc, *(data+offset+3));
> 			crc = crc_itu_t_byte(crc, *(data+offset+2));
> 			crc = crc_itu_t_byte(crc, *(data+offset+1));
> 			crc = crc_itu_t_byte(crc, *(data+offset+0));
>
> It would also have worked without knowing the crc because it is only
> actively read and compared in the driver - but better to know if upload
> did work.
>
> Now I am still not sure if it is worth to change the firmware file to
> now have the crc explicitly.
> Counting blocks is also easy todo.
> But the firmware version is not inside the data I think.
>
> So there will still remain something to be added to the raw data.

Do you need to know whole firmware version? How did you obtain it, from 
sniff? What happens if you don't tell fw version to chip at all?

Usually, almost 100%, firmware version as well all the other needed 
information, is included to firmware image itself. I don't remember many 
cases where special handling is needed. One (only one?) of such case is 
af9013, where I resolved issues by calculating fw checksum by the 
driver. IIRC chip didn't boot if there was wrong checksum for fw.

Own headers and checksums causes troubles if I someone would like to 
extract different firmwares from various windows binaries to test.

If windows driver needs to know that kind of things, those are usually 
found very near firmware image from the driver binary. Most often just 
dump 32 bytes after firmware image and it is somewhere there. Or before 
firmware image. That is because those are values are stored to same 
source code file => compiler puts that stuff ~same location.

static const unsigned char firmware[] = {
   0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,
   0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff,
};

static const unsigned int firmware_checksum = 0x01234567;
static const unsigned int firmware_version = 0x0000002b;

regards
Antti
-- 
http://palosaari.fi/

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

* Re: [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165
  2014-07-29 19:45                 ` Antti Palosaari
@ 2014-07-30 18:50                   ` Matthias Schwarzott
  2014-07-30 19:29                     ` Antti Palosaari
  0 siblings, 1 reply; 26+ messages in thread
From: Matthias Schwarzott @ 2014-07-30 18:50 UTC (permalink / raw)
  To: Antti Palosaari, Antonio Ospite; +Cc: m.chehab, linux-media

On 29.07.2014 21:45, Antti Palosaari wrote:
> 
> Do you need to know whole firmware version?
There is only 1 byte to be used and it is called patch version.
> How did you obtain it, from
> sniff?
Yes - but it also is visible in code near crc version (see below).

> What happens if you don't tell fw version to chip at all?
>
In other places it is read to verify a fw was uploaded (compare to be
not equal 0x00).
I guess the exact value is never needed (so just for information).
But I did not try it.

> Usually, almost 100%, firmware version as well all the other needed
> information, is included to firmware image itself. I don't remember many
> cases where special handling is needed. One (only one?) of such case is
> af9013, where I resolved issues by calculating fw checksum by the
> driver. IIRC chip didn't boot if there was wrong checksum for fw.

The checksum is not needed to get the device working.
The chip itself only calculates it when uploading data - and the driver
reads out the calculated checksum and compares it to the expected value.
It is only a verification of the correct upload.

> 
> Own headers and checksums causes troubles if I someone would like to
> extract different firmwares from various windows binaries to test.
> 
> If windows driver needs to know that kind of things, those are usually
> found very near firmware image from the driver binary. Most often just
> dump 32 bytes after firmware image and it is somewhere there. Or before
> firmware image. That is because those are values are stored to same
> source code file => compiler puts that stuff ~same location.
> 
I had a look at the driver - the code itself has the constants compiled
in - they are really mixed with the assembly code.

Rewritten in C it is code that has fixed values as parameters to functions.

ret = load_firmware(firmware,
  0x12, /* patch version */
  48, /* block count */
  0xaa0c /* crc */
);

I also would prefer your version with static const variables near the data.

> static const unsigned char firmware[] = {
>   0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,
>   0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff,
> };
> 
> static const unsigned int firmware_checksum = 0x01234567;
> static const unsigned int firmware_version = 0x0000002b;
> 
Regards
Matthias


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

* Re: [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165
  2014-07-30 18:50                   ` Matthias Schwarzott
@ 2014-07-30 19:29                     ` Antti Palosaari
  0 siblings, 0 replies; 26+ messages in thread
From: Antti Palosaari @ 2014-07-30 19:29 UTC (permalink / raw)
  To: Matthias Schwarzott, Antonio Ospite; +Cc: m.chehab, linux-media

All-in-all, did I understand correctly none of those header values are 
not required anymore?

hdr[0] own FW version. used by driver to print our own FW file version
hdr[1] --''--
hdr[2] vendor FW version. programmed to chip register but chip does not 
need it. read back in order to detect if FW is loaded or not
hdr[3] padding. not used
hdr[4] number of FW blocks. driver could calculate it.
hdr[5] padding. not used
hdr[6] crc. not mandatory & driver could calculate it. not 100% FW 
related, chip uses it for every write. verify xfer errors
hdr[7] --''--

regards
Antti



On 07/30/2014 09:50 PM, Matthias Schwarzott wrote:
> On 29.07.2014 21:45, Antti Palosaari wrote:
>>
>> Do you need to know whole firmware version?
> There is only 1 byte to be used and it is called patch version.
>> How did you obtain it, from
>> sniff?
> Yes - but it also is visible in code near crc version (see below).
>
>> What happens if you don't tell fw version to chip at all?
>>
> In other places it is read to verify a fw was uploaded (compare to be
> not equal 0x00).
> I guess the exact value is never needed (so just for information).
> But I did not try it.
>
>> Usually, almost 100%, firmware version as well all the other needed
>> information, is included to firmware image itself. I don't remember many
>> cases where special handling is needed. One (only one?) of such case is
>> af9013, where I resolved issues by calculating fw checksum by the
>> driver. IIRC chip didn't boot if there was wrong checksum for fw.
>
> The checksum is not needed to get the device working.
> The chip itself only calculates it when uploading data - and the driver
> reads out the calculated checksum and compares it to the expected value.
> It is only a verification of the correct upload.
>
>>
>> Own headers and checksums causes troubles if I someone would like to
>> extract different firmwares from various windows binaries to test.
>>
>> If windows driver needs to know that kind of things, those are usually
>> found very near firmware image from the driver binary. Most often just
>> dump 32 bytes after firmware image and it is somewhere there. Or before
>> firmware image. That is because those are values are stored to same
>> source code file => compiler puts that stuff ~same location.
>>
> I had a look at the driver - the code itself has the constants compiled
> in - they are really mixed with the assembly code.
>
> Rewritten in C it is code that has fixed values as parameters to functions.
>
> ret = load_firmware(firmware,
>    0x12, /* patch version */
>    48, /* block count */
>    0xaa0c /* crc */
> );
>
> I also would prefer your version with static const variables near the data.
>
>> static const unsigned char firmware[] = {
>>    0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,
>>    0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff,
>> };
>>
>> static const unsigned int firmware_checksum = 0x01234567;
>> static const unsigned int firmware_version = 0x0000002b;
>>
> Regards
> Matthias
>

-- 
http://palosaari.fi/

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

end of thread, other threads:[~2014-07-30 19:29 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-22 20:12 [PATCH 0/8] add si2165 demod driver Matthias Schwarzott
2014-07-22 20:12 ` [PATCH 1/8] get_dvb_firmware: Add firmware extractor for si2165 Matthias Schwarzott
2014-07-23  9:20   ` Antti Palosaari
2014-07-23 19:03     ` Matthias Schwarzott
2014-07-23 20:10       ` Antonio Ospite
2014-07-29  5:37         ` Matthias Schwarzott
2014-07-29  8:53           ` Antonio Ospite
2014-07-29 11:34             ` Antti Palosaari
2014-07-29 19:22               ` Matthias Schwarzott
2014-07-29 19:45                 ` Antti Palosaari
2014-07-30 18:50                   ` Matthias Schwarzott
2014-07-30 19:29                     ` Antti Palosaari
2014-07-22 20:12 ` [PATCH 2/8] si2165: Add demod driver for DVB-T only Matthias Schwarzott
2014-07-22 20:12 ` [PATCH 3/8] cx23885: Add si2165 support for HVR-5500 Matthias Schwarzott
2014-07-22 20:12 ` [PATCH 4/8] cx231xx: prepare for i2c_client attachment Matthias Schwarzott
2014-07-22 20:12 ` [PATCH 5/8] cx231xx: Add digital support for [2040:b130] Hauppauge WinTV 930C-HD (model 1113xx) Matthias Schwarzott
2014-07-22 20:12 ` [PATCH 6/8] cx231xx: Add digital support for [2040:b131] Hauppauge WinTV 930C-HD (model 1114xx) Matthias Schwarzott
2014-07-26 19:27   ` Mauro Carvalho Chehab
2014-07-27  9:32     ` Matthias Schwarzott
2014-07-27 13:44       ` Mauro Carvalho Chehab
2014-07-27 14:32         ` Mauro Carvalho Chehab
2014-07-27 14:59           ` Mauro Carvalho Chehab
2014-07-27 19:42             ` Mauro Carvalho Chehab
2014-07-29  5:39               ` Matthias Schwarzott
2014-07-22 20:12 ` [PATCH 7/8] cx231xx: Add [2013:0259] PCTV QuatroStick 521e Matthias Schwarzott
2014-07-22 20:12 ` [PATCH 8/8] cx231xx: Add [2013:025e] PCTV QuatroStick 522e Matthias Schwarzott

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.