[PATCH 2/3] af9035: Add possibility to define which I2C adapter to use

2014-09-21 Thread Olli Salonen
Some I2C tuner drivers require that the I2C device of the tuner is added to the 
I2C adapter of the demodulator (Si2168+Si2157 for example). Add possibility to 
tell af9035_add_i2c_dev which I2C adapter should be used.

Cc: cr...@iki.fi
Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/usb/dvb-usb-v2/af9035.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c 
b/drivers/media/usb/dvb-usb-v2/af9035.c
index 440ecb4..c50d27d 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -194,12 +194,11 @@ static int af9035_wr_reg_mask(struct dvb_usb_device *d, 
u32 reg, u8 val,
 }
 
 static int af9035_add_i2c_dev(struct dvb_usb_device *d, char *type, u8 addr,
-   void *platform_data)
+   void *platform_data, struct i2c_adapter *adapter)
 {
int ret, num;
struct state *state = d_to_priv(d);
struct i2c_client *client;
-   struct i2c_adapter *adapter = d-i2c_adap;
struct i2c_board_info board_info = {
.addr = addr,
.platform_data = platform_data,
@@ -1091,7 +1090,7 @@ static int af9035_frontend_attach(struct dvb_usb_adapter 
*adap)
state-af9033_config[adap-id].fe = adap-fe[0];
state-af9033_config[adap-id].ops = state-ops;
ret = af9035_add_i2c_dev(d, af9033, state-af9033_i2c_addr[adap-id],
-   state-af9033_config[adap-id]);
+   state-af9033_config[adap-id], d-i2c_adap);
if (ret)
goto err;
 
@@ -1382,7 +1381,7 @@ static int af9035_tuner_attach(struct dvb_usb_adapter 
*adap)
 
ret = af9035_add_i2c_dev(d, it913x,
state-af9033_i2c_addr[adap-id]  1,
-   it913x_config);
+   it913x_config, d-i2c_adap);
if (ret)
goto err;
 
@@ -1407,7 +1406,7 @@ static int af9035_tuner_attach(struct dvb_usb_adapter 
*adap)
 
ret = af9035_add_i2c_dev(d, it913x,
state-af9033_i2c_addr[adap-id]  1,
-   it913x_config);
+   it913x_config, d-i2c_adap);
if (ret)
goto err;
 
-- 
1.9.1

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


[PATCH 3/3] af9035: Add support for IT930x USB bridge

2014-09-21 Thread Olli Salonen
Add support for IT930x USB bridge and IT9303 reference design.

It is a DVB-T/T2/C tuner with the following components:
- IT9303 USB bridge
- Si2168-B40 demodulator
- Si2147-A30 tuner

The IT9303 requires firmware that can be downloaded here:
http://trsqr.net/olli/linux/firmwares/it930x/

The Si2168-B40 requires firmware, but the one that is used by PCTV 292e can be 
used.
http://palosaari.fi/linux/v4l-dvb/firmware/Si2168/Si2168-B40/

The Si2147-A30 tuner does not require firmware loading.

Cc: cr...@iki.fi
Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-core/dvb-usb-ids.h  |   1 +
 drivers/media/usb/dvb-usb-v2/af9035.c | 324 --
 drivers/media/usb/dvb-usb-v2/af9035.h |   6 +
 3 files changed, 314 insertions(+), 17 deletions(-)

diff --git a/drivers/media/dvb-core/dvb-usb-ids.h 
b/drivers/media/dvb-core/dvb-usb-ids.h
index d484a51..e07a84e 100644
--- a/drivers/media/dvb-core/dvb-usb-ids.h
+++ b/drivers/media/dvb-core/dvb-usb-ids.h
@@ -144,6 +144,7 @@
 #define USB_PID_ITETECH_IT9135 0x9135
 #define USB_PID_ITETECH_IT9135_90050x9005
 #define USB_PID_ITETECH_IT9135_90060x9006
+#define USB_PID_ITETECH_IT9303 0x9306
 #define USB_PID_KWORLD_399U0xe399
 #define USB_PID_KWORLD_399U_2  0xe400
 #define USB_PID_KWORLD_395U0xe396
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c 
b/drivers/media/usb/dvb-usb-v2/af9035.c
index c50d27d..00758c8 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -290,7 +290,7 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
return -EAGAIN;
 
/*
-* I2C sub header is 5 bytes long. Meaning of those bytes are:
+* AF9035 I2C sub header is 5 bytes long. Meaning of those bytes are:
 * 0: data len
 * 1: I2C addr  1
 * 2: reg addr len
@@ -317,6 +317,12 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
 * bus. I2C subsystem does not allow register multiple devices to same
 * bus, having same slave address. Due to that we reuse demod address,
 * shifted by one bit, on that case.
+*
+* For IT930x we use a different command and the sub header is
+* different as well:
+* 0: data len
+* 1: I2C bus (0x03 seems to be only value used)
+* 2: I2C addr  1
 */
 #define AF9035_IS_I2C_XFER_WRITE_READ(_msg, _num) \
(_num == 2  !(_msg[0].flags  I2C_M_RD)  (_msg[1].flags  I2C_M_RD))
@@ -348,13 +354,24 @@ static int af9035_i2c_master_xfer(struct i2c_adapter 
*adap,
struct usb_req req = { CMD_I2C_RD, 0, 5 + msg[0].len,
buf, msg[1].len, msg[1].buf };
 
+   if (state-chip_type == 0x9306) {
+   req.cmd = CMD_GENERIC_I2C_RD;
+   req.wlen = 3 + msg[0].len;
+   }
req.mbox |= ((msg[0].addr  0x80)3);
+
buf[0] = msg[1].len;
-   buf[1] = msg[0].addr  1;
-   buf[2] = 0x00; /* reg addr len */
-   buf[3] = 0x00; /* reg addr MSB */
-   buf[4] = 0x00; /* reg addr LSB */
-   memcpy(buf[5], msg[0].buf, msg[0].len);
+   if (state-chip_type == 0x9306) {
+   buf[1] = 0x03; /* I2C bus */
+   buf[2] = msg[0].addr  1;
+   memcpy(buf[3], msg[0].buf, msg[0].len);
+   } else {
+   buf[1] = msg[0].addr  1;
+   buf[2] = 0x00; /* reg addr len */
+   buf[3] = 0x00; /* reg addr MSB */
+   buf[4] = 0x00; /* reg addr LSB */
+   memcpy(buf[5], msg[0].buf, msg[0].len);
+   }
ret = af9035_ctrl_msg(d, req);
}
} else if (AF9035_IS_I2C_XFER_WRITE(msg, num)) {
@@ -380,13 +397,24 @@ static int af9035_i2c_master_xfer(struct i2c_adapter 
*adap,
struct usb_req req = { CMD_I2C_WR, 0, 5 + msg[0].len,
buf, 0, NULL };
 
+   if (state-chip_type == 0x9306) {
+   req.cmd = CMD_GENERIC_I2C_WR;
+   req.wlen = 3 + msg[0].len;
+   }
+
req.mbox |= ((msg[0].addr  0x80)3);
buf[0] = msg[0].len;
-   buf[1] = msg[0].addr  1;
-   buf[2] = 0x00; /* reg addr len */
-   buf[3] = 0x00; /* reg addr MSB */
-   buf[4] = 0x00

[PATCH] si2157: Add support for Si2147-A30 tuner

2014-09-11 Thread Olli Salonen
This patch adds support for Si2147-A30 tuner. Fairly trivial, no firmware 
needed for this tuner. However, command 14 00 02 07 01 00 seems to be 
mandatory. On Si2157 and Si2158 the value 0x0100 is the default value, so this 
patch does not impact the existing tuners/devices. On Si2147 the default is 
0x and I can't get a lock with that value.

While here, fix the return length of the previous set command to 4 bytes.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/tuners/si2157.c  | 13 +++--
 drivers/media/tuners/si2157.h  |  2 +-
 drivers/media/tuners/si2157_priv.h |  2 +-
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
index 5901484..cf97142 100644
--- a/drivers/media/tuners/si2157.c
+++ b/drivers/media/tuners/si2157.c
@@ -1,5 +1,5 @@
 /*
- * Silicon Labs Si2157/2158 silicon tuner driver
+ * Silicon Labs Si2147/2157/2158 silicon tuner driver
  *
  * Copyright (C) 2014 Antti Palosaari cr...@iki.fi
  *
@@ -113,12 +113,14 @@ static int si2157_init(struct dvb_frontend *fe)
 
#define SI2158_A20 ('A'  24 | 58  16 | '2'  8 | '0'  0)
#define SI2157_A30 ('A'  24 | 57  16 | '3'  8 | '0'  0)
+   #define SI2147_A30 ('A'  24 | 47  16 | '3'  8 | '0'  0)
 
switch (chip_id) {
case SI2158_A20:
fw_file = SI2158_A20_FIRMWARE;
break;
case SI2157_A30:
+   case SI2147_A30:
goto skip_fw_download;
break;
default:
@@ -265,7 +267,14 @@ static int si2157_set_params(struct dvb_frontend *fe)
if (s-inversion)
cmd.args[5] = 0x01;
cmd.wlen = 6;
-   cmd.rlen = 1;
+   cmd.rlen = 4;
+   ret = si2157_cmd_execute(s, cmd);
+   if (ret)
+   goto err;
+
+   memcpy(cmd.args, \x14\x00\x02\x07\x01\x00, 6);
+   cmd.wlen = 6;
+   cmd.rlen = 4;
ret = si2157_cmd_execute(s, cmd);
if (ret)
goto err;
diff --git a/drivers/media/tuners/si2157.h b/drivers/media/tuners/si2157.h
index 6da4d5d..d3b19ca 100644
--- a/drivers/media/tuners/si2157.h
+++ b/drivers/media/tuners/si2157.h
@@ -1,5 +1,5 @@
 /*
- * Silicon Labs Si2157/2158 silicon tuner driver
+ * Silicon Labs Si2147/2157/2158 silicon tuner driver
  *
  * Copyright (C) 2014 Antti Palosaari cr...@iki.fi
  *
diff --git a/drivers/media/tuners/si2157_priv.h 
b/drivers/media/tuners/si2157_priv.h
index 4080a57..e71ffaf 100644
--- a/drivers/media/tuners/si2157_priv.h
+++ b/drivers/media/tuners/si2157_priv.h
@@ -1,5 +1,5 @@
 /*
- * Silicon Labs Si2157/2158 silicon tuner driver
+ * Silicon Labs Si2147/2157/2158 silicon tuner driver
  *
  * Copyright (C) 2014 Antti Palosaari cr...@iki.fi
  *
-- 
1.9.1

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


Re: [PATCH 3/3] si2168: avoid firmware loading if it has been loaded previously

2014-09-06 Thread Olli Salonen
Moro Antti,

Tried removing the command 85 after resume, but the result is that the
demod doesn't lock after sleep. Curiously this only impacts HD or
DVB-T2 channels. DVB-T SD channels are fine even after resume.

Log of the testing here:
http://paste.ubuntu.com/8271949/

Same thing happens after applying the si2157: sleep hack patch: my
TT CT2-4400 does not lock on the second tune, ie. after sleep.

Log of the testing of that patch is here:
http://paste.ubuntu.com/8271869/

Cheers,
-olli

On 5 September 2014 21:54, Olli Salonen olli.salo...@iki.fi wrote:
 Moro,

 I'll test it once more when testing the si2157 sleep hack you
 posted. Though I remember that the command 85 seemed to be the magic
 trick that finally made it work - I agree it sounds a bit strange
 considering it's run later on anyway. The proprietary driver seems to
 do a command 85 after wake up, but of course that's not a guarantee of
 anything.

 My sniff using the proprietary driver is here:
 http://trsqr.net/olli/ct2-4400/ct2-4400-wakeup-tune-sleep.txt

 Cheers,
 -olli

 On 5 September 2014 11:36, Antti Palosaari cr...@iki.fi wrote:
 Moikka
 Did you really need command 85 here? It will be given later in any case. For
 my Si2168 B40 there was no need for it.

 regards
 Antti

 On 08/25/2014 09:07 PM, Olli Salonen wrote:

 Add a variable to keep track if firmware is loaded or not and skip parts
 of the
 initialization if fw is already loaded. Resume from sleep with a different
 command compared to initial power up and run command 85 after resume
 command.
 This behaviour is observed when using manufacturer provided binary-only
 si2168
 driver for TechnoTrend CT2-4400.

 Signed-off-by: Olli Salonen olli.salo...@iki.fi
 ---
   drivers/media/dvb-frontends/si2168.c  | 31
 ---
   drivers/media/dvb-frontends/si2168_priv.h |  1 +
   2 files changed, 29 insertions(+), 3 deletions(-)

 diff --git a/drivers/media/dvb-frontends/si2168.c
 b/drivers/media/dvb-frontends/si2168.c
 index 55a4212..a0797fd 100644
 --- a/drivers/media/dvb-frontends/si2168.c
 +++ b/drivers/media/dvb-frontends/si2168.c
 @@ -363,6 +363,7 @@ static int si2168_init(struct dvb_frontend *fe)

 dev_dbg(s-client-dev, \n);

 +   /* initialize */
 memcpy(cmd.args,
 \xc0\x12\x00\x0c\x00\x0d\x16\x00\x00\x00\x00\x00\x00, 13);
 cmd.wlen = 13;
 cmd.rlen = 0;
 @@ -370,6 +371,26 @@ static int si2168_init(struct dvb_frontend *fe)
 if (ret)
 goto err;

 +   if (s-fw_loaded) {
 +   /* resume */
 +   memcpy(cmd.args, \xc0\x06\x08\x0f\x00\x20\x21\x01, 8);
 +   cmd.wlen = 8;
 +   cmd.rlen = 1;
 +   ret = si2168_cmd_execute(s, cmd);
 +   if (ret)
 +   goto err;
 +
 +   memcpy(cmd.args, \x85, 1);
 +   cmd.wlen = 1;
 +   cmd.rlen = 1;
 +   ret = si2168_cmd_execute(s, cmd);
 +   if (ret)
 +   goto err;
 +
 +   goto warm;
 +   }
 +
 +   /* power up */
 memcpy(cmd.args, \xc0\x06\x01\x0f\x00\x20\x20\x01, 8);
 cmd.wlen = 8;
 cmd.rlen = 1;
 @@ -466,9 +487,6 @@ static int si2168_init(struct dvb_frontend *fe)
 if (ret)
 goto err;

 -   dev_info(s-client-dev, found a '%s' in warm state\n,
 -   si2168_ops.info.name);
 -
 /* set ts mode */
 memcpy(cmd.args, \x14\x00\x01\x10\x10\x00, 6);
 cmd.args[4] |= s-ts_mode;
 @@ -478,6 +496,12 @@ static int si2168_init(struct dvb_frontend *fe)
 if (ret)
 goto err;

 +   s-fw_loaded = true;
 +
 +warm:
 +   dev_info(s-client-dev, found a '%s' in warm state\n,
 +   si2168_ops.info.name);
 +
 s-active = true;

 return 0;
 @@ -645,6 +669,7 @@ static int si2168_probe(struct i2c_client *client,
 *config-i2c_adapter = s-adapter;
 *config-fe = s-fe;
 s-ts_mode = config-ts_mode;
 +   s-fw_loaded = false;

 i2c_set_clientdata(client, s);

 diff --git a/drivers/media/dvb-frontends/si2168_priv.h
 b/drivers/media/dvb-frontends/si2168_priv.h
 index 0f83284..e13983e 100644
 --- a/drivers/media/dvb-frontends/si2168_priv.h
 +++ b/drivers/media/dvb-frontends/si2168_priv.h
 @@ -36,6 +36,7 @@ struct si2168 {
 fe_delivery_system_t delivery_system;
 fe_status_t fe_status;
 bool active;
 +   bool fw_loaded;
 u8 ts_mode;
   };



 --
 http://palosaari.fi/
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/3] si2168: avoid firmware loading if it has been loaded previously

2014-09-05 Thread Olli Salonen
Moro,

I'll test it once more when testing the si2157 sleep hack you
posted. Though I remember that the command 85 seemed to be the magic
trick that finally made it work - I agree it sounds a bit strange
considering it's run later on anyway. The proprietary driver seems to
do a command 85 after wake up, but of course that's not a guarantee of
anything.

My sniff using the proprietary driver is here:
http://trsqr.net/olli/ct2-4400/ct2-4400-wakeup-tune-sleep.txt

Cheers,
-olli

On 5 September 2014 11:36, Antti Palosaari cr...@iki.fi wrote:
 Moikka
 Did you really need command 85 here? It will be given later in any case. For
 my Si2168 B40 there was no need for it.

 regards
 Antti

 On 08/25/2014 09:07 PM, Olli Salonen wrote:

 Add a variable to keep track if firmware is loaded or not and skip parts
 of the
 initialization if fw is already loaded. Resume from sleep with a different
 command compared to initial power up and run command 85 after resume
 command.
 This behaviour is observed when using manufacturer provided binary-only
 si2168
 driver for TechnoTrend CT2-4400.

 Signed-off-by: Olli Salonen olli.salo...@iki.fi
 ---
   drivers/media/dvb-frontends/si2168.c  | 31
 ---
   drivers/media/dvb-frontends/si2168_priv.h |  1 +
   2 files changed, 29 insertions(+), 3 deletions(-)

 diff --git a/drivers/media/dvb-frontends/si2168.c
 b/drivers/media/dvb-frontends/si2168.c
 index 55a4212..a0797fd 100644
 --- a/drivers/media/dvb-frontends/si2168.c
 +++ b/drivers/media/dvb-frontends/si2168.c
 @@ -363,6 +363,7 @@ static int si2168_init(struct dvb_frontend *fe)

 dev_dbg(s-client-dev, \n);

 +   /* initialize */
 memcpy(cmd.args,
 \xc0\x12\x00\x0c\x00\x0d\x16\x00\x00\x00\x00\x00\x00, 13);
 cmd.wlen = 13;
 cmd.rlen = 0;
 @@ -370,6 +371,26 @@ static int si2168_init(struct dvb_frontend *fe)
 if (ret)
 goto err;

 +   if (s-fw_loaded) {
 +   /* resume */
 +   memcpy(cmd.args, \xc0\x06\x08\x0f\x00\x20\x21\x01, 8);
 +   cmd.wlen = 8;
 +   cmd.rlen = 1;
 +   ret = si2168_cmd_execute(s, cmd);
 +   if (ret)
 +   goto err;
 +
 +   memcpy(cmd.args, \x85, 1);
 +   cmd.wlen = 1;
 +   cmd.rlen = 1;
 +   ret = si2168_cmd_execute(s, cmd);
 +   if (ret)
 +   goto err;
 +
 +   goto warm;
 +   }
 +
 +   /* power up */
 memcpy(cmd.args, \xc0\x06\x01\x0f\x00\x20\x20\x01, 8);
 cmd.wlen = 8;
 cmd.rlen = 1;
 @@ -466,9 +487,6 @@ static int si2168_init(struct dvb_frontend *fe)
 if (ret)
 goto err;

 -   dev_info(s-client-dev, found a '%s' in warm state\n,
 -   si2168_ops.info.name);
 -
 /* set ts mode */
 memcpy(cmd.args, \x14\x00\x01\x10\x10\x00, 6);
 cmd.args[4] |= s-ts_mode;
 @@ -478,6 +496,12 @@ static int si2168_init(struct dvb_frontend *fe)
 if (ret)
 goto err;

 +   s-fw_loaded = true;
 +
 +warm:
 +   dev_info(s-client-dev, found a '%s' in warm state\n,
 +   si2168_ops.info.name);
 +
 s-active = true;

 return 0;
 @@ -645,6 +669,7 @@ static int si2168_probe(struct i2c_client *client,
 *config-i2c_adapter = s-adapter;
 *config-fe = s-fe;
 s-ts_mode = config-ts_mode;
 +   s-fw_loaded = false;

 i2c_set_clientdata(client, s);

 diff --git a/drivers/media/dvb-frontends/si2168_priv.h
 b/drivers/media/dvb-frontends/si2168_priv.h
 index 0f83284..e13983e 100644
 --- a/drivers/media/dvb-frontends/si2168_priv.h
 +++ b/drivers/media/dvb-frontends/si2168_priv.h
 @@ -36,6 +36,7 @@ struct si2168 {
 fe_delivery_system_t delivery_system;
 fe_status_t fe_status;
 bool active;
 +   bool fw_loaded;
 u8 ts_mode;
   };



 --
 http://palosaari.fi/
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] si2157: avoid firmware loading if it has been loaded previously

2014-08-25 Thread Olli Salonen
Add a variable into state to keep track if firmware has been loaded or not. 
Skip firmware loading in case it is already loaded (resume from sleep).

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/tuners/si2157.c  | 11 +--
 drivers/media/tuners/si2157_priv.h |  1 +
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
index c84f7b8..5901484 100644
--- a/drivers/media/tuners/si2157.c
+++ b/drivers/media/tuners/si2157.c
@@ -89,7 +89,10 @@ static int si2157_init(struct dvb_frontend *fe)
 
dev_dbg(s-client-dev, \n);
 
-   /* configure? */
+   if (s-fw_loaded)
+   goto warm;
+
+   /* power up */
memcpy(cmd.args, 
\xc0\x00\x0c\x00\x00\x01\x01\x01\x01\x01\x01\x02\x00\x00\x01, 15);
cmd.wlen = 15;
cmd.rlen = 1;
@@ -176,9 +179,12 @@ skip_fw_download:
if (ret)
goto err;
 
-   s-active = true;
+   s-fw_loaded = true;
 
+warm:
+   s-active = true;
return 0;
+
 err:
if (fw)
release_firmware(fw);
@@ -320,6 +326,7 @@ static int si2157_probe(struct i2c_client *client,
s-client = client;
s-fe = cfg-fe;
s-inversion = cfg-inversion;
+   s-fw_loaded = false;
mutex_init(s-i2c_mutex);
 
/* check if the tuner is there */
diff --git a/drivers/media/tuners/si2157_priv.h 
b/drivers/media/tuners/si2157_priv.h
index 3ddab5e..4080a57 100644
--- a/drivers/media/tuners/si2157_priv.h
+++ b/drivers/media/tuners/si2157_priv.h
@@ -26,6 +26,7 @@ struct si2157 {
struct i2c_client *client;
struct dvb_frontend *fe;
bool active;
+   bool fw_loaded;
bool inversion;
 };
 
-- 
1.9.1

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


[PATCH 1/3] si2157: change command for sleep

2014-08-25 Thread Olli Salonen
Instead of sending command 13 to the tuner, send command 16 when sleeping. This 
behaviour is observed when using manufacturer provided binary-only Linux driver 
for TechnoTrend CT2-4400 (Windows driver does not do power management).

The issue with command 13 is that firmware loading is necessary after that. 
This is not an issue with tuners that do not require firmware, but resuming 
from sleep on an Si2158 takes noticeable time as firmware is loaded on resume.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/tuners/si2157.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
index efb5cce..c84f7b8 100644
--- a/drivers/media/tuners/si2157.c
+++ b/drivers/media/tuners/si2157.c
@@ -197,9 +197,10 @@ static int si2157_sleep(struct dvb_frontend *fe)
 
s-active = false;
 
-   memcpy(cmd.args, \x13, 1);
-   cmd.wlen = 1;
-   cmd.rlen = 0;
+   /* standby */
+   memcpy(cmd.args, \x16\x00, 2);
+   cmd.wlen = 2;
+   cmd.rlen = 1;
ret = si2157_cmd_execute(s, cmd);
if (ret)
goto err;
-- 
1.9.1

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


[PATCH 3/3] si2168: avoid firmware loading if it has been loaded previously

2014-08-25 Thread Olli Salonen
Add a variable to keep track if firmware is loaded or not and skip parts of the 
initialization if fw is already loaded. Resume from sleep with a different 
command compared to initial power up and run command 85 after resume command. 
This behaviour is observed when using manufacturer provided binary-only si2168 
driver for TechnoTrend CT2-4400.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-frontends/si2168.c  | 31 ---
 drivers/media/dvb-frontends/si2168_priv.h |  1 +
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2168.c 
b/drivers/media/dvb-frontends/si2168.c
index 55a4212..a0797fd 100644
--- a/drivers/media/dvb-frontends/si2168.c
+++ b/drivers/media/dvb-frontends/si2168.c
@@ -363,6 +363,7 @@ static int si2168_init(struct dvb_frontend *fe)
 
dev_dbg(s-client-dev, \n);
 
+   /* initialize */
memcpy(cmd.args, 
\xc0\x12\x00\x0c\x00\x0d\x16\x00\x00\x00\x00\x00\x00, 13);
cmd.wlen = 13;
cmd.rlen = 0;
@@ -370,6 +371,26 @@ static int si2168_init(struct dvb_frontend *fe)
if (ret)
goto err;
 
+   if (s-fw_loaded) {
+   /* resume */
+   memcpy(cmd.args, \xc0\x06\x08\x0f\x00\x20\x21\x01, 8);
+   cmd.wlen = 8;
+   cmd.rlen = 1;
+   ret = si2168_cmd_execute(s, cmd);
+   if (ret)
+   goto err;
+
+   memcpy(cmd.args, \x85, 1);
+   cmd.wlen = 1;
+   cmd.rlen = 1;
+   ret = si2168_cmd_execute(s, cmd);
+   if (ret)
+   goto err;
+
+   goto warm;
+   }
+
+   /* power up */
memcpy(cmd.args, \xc0\x06\x01\x0f\x00\x20\x20\x01, 8);
cmd.wlen = 8;
cmd.rlen = 1;
@@ -466,9 +487,6 @@ static int si2168_init(struct dvb_frontend *fe)
if (ret)
goto err;
 
-   dev_info(s-client-dev, found a '%s' in warm state\n,
-   si2168_ops.info.name);
-
/* set ts mode */
memcpy(cmd.args, \x14\x00\x01\x10\x10\x00, 6);
cmd.args[4] |= s-ts_mode;
@@ -478,6 +496,12 @@ static int si2168_init(struct dvb_frontend *fe)
if (ret)
goto err;
 
+   s-fw_loaded = true;
+
+warm:
+   dev_info(s-client-dev, found a '%s' in warm state\n,
+   si2168_ops.info.name);
+
s-active = true;
 
return 0;
@@ -645,6 +669,7 @@ static int si2168_probe(struct i2c_client *client,
*config-i2c_adapter = s-adapter;
*config-fe = s-fe;
s-ts_mode = config-ts_mode;
+   s-fw_loaded = false;
 
i2c_set_clientdata(client, s);
 
diff --git a/drivers/media/dvb-frontends/si2168_priv.h 
b/drivers/media/dvb-frontends/si2168_priv.h
index 0f83284..e13983e 100644
--- a/drivers/media/dvb-frontends/si2168_priv.h
+++ b/drivers/media/dvb-frontends/si2168_priv.h
@@ -36,6 +36,7 @@ struct si2168 {
fe_delivery_system_t delivery_system;
fe_status_t fe_status;
bool active;
+   bool fw_loaded;
u8 ts_mode;
 };
 
-- 
1.9.1

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


[PATCH] MAINTAINERS: add sp2 entry

2014-08-22 Thread Olli Salonen
Add a maintainer for the new CIMaX SP2 driver.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 MAINTAINERS |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4cdf24c..6139b66 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8451,6 +8451,14 @@ F:   include/sound/dmaengine_pcm.h
 F: sound/core/pcm_dmaengine.c
 F: sound/soc/soc-generic-dmaengine-pcm.c
 
+SP2 MEDIA DRIVER
+M: Olli Salonen olli.salo...@iki.fi
+L: linux-media@vger.kernel.org
+W: http://linuxtv.org/
+Q: http://patchwork.linuxtv.org/project/linux-media/list/
+S: Maintained
+F: drivers/media/dvb-frontends/sp2*
+
 SPARC + UltraSPARC (sparc/sparc64)
 M: David S. Miller da...@davemloft.net
 L: sparcli...@vger.kernel.org
-- 
1.7.0.4

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


[PATCHv2] cxusb: Add read_mac_address for TT CT2-4400 and CT2-4650

2014-08-21 Thread Olli Salonen
Read MAC address from the EEPROM. This version two corrects a flaw in the 
result code returning that did exist in the first version.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/usb/dvb-usb/cxusb.c | 35 +++
 1 file changed, 35 insertions(+)

diff --git a/drivers/media/usb/dvb-usb/cxusb.c 
b/drivers/media/usb/dvb-usb/cxusb.c
index c3a44c7..f631955 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -673,6 +673,39 @@ static struct rc_map_table rc_map_d680_dmb_table[] = {
{ 0x0025, KEY_POWER },
 };
 
+static int cxusb_tt_ct2_4400_read_mac_address(struct dvb_usb_device *d, u8 
mac[6])
+{
+   u8 wbuf[2];
+   u8 rbuf[6];
+   int ret;
+   struct i2c_msg msg[] = {
+   {
+   .addr = 0x51,
+   .flags = 0,
+   .buf = wbuf,
+   .len = 2,
+   }, {
+   .addr = 0x51,
+   .flags = I2C_M_RD,
+   .buf = rbuf,
+   .len = 6,
+   }
+   };
+
+   wbuf[0] = 0x1e;
+   wbuf[1] = 0x00;
+   ret = cxusb_i2c_xfer(d-i2c_adap, msg, 2);
+
+   if (ret == 2) {
+   memcpy(mac, rbuf, 6);
+   return 0;
+   } else {
+   if (ret  0)
+   return ret;
+   return -EIO;
+   }
+}
+
 static int cxusb_tt_ct2_4650_ci_ctrl(void *priv, u8 read, int addr,
u8 data, int *mem)
 {
@@ -2315,6 +2348,8 @@ static struct dvb_usb_device_properties 
cxusb_tt_ct2_4400_properties = {
.size_of_priv = sizeof(struct cxusb_state),
 
.num_adapters = 1,
+   .read_mac_address = cxusb_tt_ct2_4400_read_mac_address,
+
.adapter = {
{
.num_frontends = 1,
-- 
1.9.1

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


[PATCH] si2157: Add support for delivery system SYS_ATSC

2014-08-16 Thread Olli Salonen
Set the property for delivery system also in case of SYS_ATSC. This 
behaviour is observed in the sniffs taken with Hauppauge HVR-955Q 
Windows driver.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/tuners/si2157.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
index 6c53edb..3b86d59 100644
--- a/drivers/media/tuners/si2157.c
+++ b/drivers/media/tuners/si2157.c
@@ -239,6 +239,9 @@ static int si2157_set_params(struct dvb_frontend *fe)
bandwidth = 0x0f;
 
switch (c-delivery_system) {
+   case SYS_ATSC:
+   delivery_system = 0x00;
+   break;
case SYS_DVBT:
case SYS_DVBT2: /* it seems DVB-T and DVB-T2 both are 0x20 here */
delivery_system = 0x20;
-- 
1.9.1

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


Re: [PATCH 2/6] em28xx: add ts mode setting for PCTV 461e

2014-08-13 Thread Olli Salonen
Indeed, the patch is correct, but the description should say:

em28xx: add ts mode setting for PCTV 292e
TS mode must be set in the existing PCTV 292e driver.

Thanks for your reviews!

On 13 August 2014 02:23, Antti Palosaari cr...@iki.fi wrote:
 Acked-by: Antti Palosaari cr...@iki.fi
 Reviewed-by: Antti Palosaari cr...@iki.fi

 PCTV 461e is satellite receiver whilst that one should be PCTV 292e. I will
 fix the type, no new patch needed.

 Antti


 On 08/11/2014 10:58 PM, Olli Salonen wrote:

 TS mode must be set in the existing PCTV 461e driver.

 Signed-off-by: Olli Salonen olli.salo...@iki.fi
 ---
   drivers/media/usb/em28xx/em28xx-dvb.c | 1 +
   1 file changed, 1 insertion(+)

 diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c
 b/drivers/media/usb/em28xx/em28xx-dvb.c
 index d8e9760..0645793 100644
 --- a/drivers/media/usb/em28xx/em28xx-dvb.c
 +++ b/drivers/media/usb/em28xx/em28xx-dvb.c
 @@ -1535,6 +1535,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
 /* attach demod */
 si2168_config.i2c_adapter = adapter;
 si2168_config.fe = dvb-fe[0];
 +   si2168_config.ts_mode = SI2168_TS_PARALLEL;
 memset(info, 0, sizeof(struct i2c_board_info));
 strlcpy(info.type, si2168, I2C_NAME_SIZE);
 info.addr = 0x64;


 --
 http://palosaari.fi/
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/6] em28xx: add ts mode setting for PCTV 461e

2014-08-11 Thread Olli Salonen
TS mode must be set in the existing PCTV 461e driver.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/usb/em28xx/em28xx-dvb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c 
b/drivers/media/usb/em28xx/em28xx-dvb.c
index d8e9760..0645793 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -1535,6 +1535,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
/* attach demod */
si2168_config.i2c_adapter = adapter;
si2168_config.fe = dvb-fe[0];
+   si2168_config.ts_mode = SI2168_TS_PARALLEL;
memset(info, 0, sizeof(struct i2c_board_info));
strlcpy(info.type, si2168, I2C_NAME_SIZE);
info.addr = 0x64;
-- 
1.9.1

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


[PATCH 5/6] cx23855: add frontend set voltage function into state

2014-08-11 Thread Olli Salonen
Setting the LNB voltage requires setting some GPIOs on the cx23885 with some 
boards before calling the actual set_voltage function in the demod driver. Add 
a function pointer into state for that case.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/pci/cx23885/cx23885.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/pci/cx23885/cx23885.h 
b/drivers/media/pci/cx23885/cx23885.h
index 1040b3e..e60ff7f 100644
--- a/drivers/media/pci/cx23885/cx23885.h
+++ b/drivers/media/pci/cx23885/cx23885.h
@@ -330,6 +330,8 @@ struct cx23885_tsport {
struct i2c_client *i2c_client_tuner;
 
int (*set_frontend)(struct dvb_frontend *fe);
+   int (*fe_set_voltage)(struct dvb_frontend *fe,
+   fe_sec_voltage_t voltage);
 };
 
 struct cx23885_kernel_ir {
-- 
1.9.1

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


[PATCH 1/6] si2168: add ts_mode setting and move to si2168_init

2014-08-11 Thread Olli Salonen
Luis Alves submitted a TS mode patch to si2168 earlier, but the patch was 
rejected due to a small issue. Here is a working version. Also, setting of TS 
mode is moved from si2168_set_frontend to si2168_init.

This patch adds the TS mode as a config option for the si2168 demod:
- ts_mode added to config struct.
- Possible (interesting) values are
   * Parallel mode = 0x06
   * Serial mode = 0x03

Currently the modules using this demod only use parallel mode. Patches for 
these modules later in this patch series.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-frontends/si2168.c  | 17 ++---
 drivers/media/dvb-frontends/si2168.h  |  6 ++
 drivers/media/dvb-frontends/si2168_priv.h |  1 +
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2168.c 
b/drivers/media/dvb-frontends/si2168.c
index 8f81d97..0eb0e4e 100644
--- a/drivers/media/dvb-frontends/si2168.c
+++ b/drivers/media/dvb-frontends/si2168.c
@@ -297,13 +297,6 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
if (ret)
goto err;
 
-   memcpy(cmd.args, \x14\x00\x01\x10\x16\x00, 6);
-   cmd.wlen = 6;
-   cmd.rlen = 4;
-   ret = si2168_cmd_execute(s, cmd);
-   if (ret)
-   goto err;
-
memcpy(cmd.args, \x14\x00\x09\x10\xe3\x18, 6);
cmd.wlen = 6;
cmd.rlen = 4;
@@ -465,6 +458,15 @@ static int si2168_init(struct dvb_frontend *fe)
dev_info(s-client-dev, %s: found a '%s' in warm state\n,
KBUILD_MODNAME, si2168_ops.info.name);
 
+   /* set ts mode */
+   memcpy(cmd.args, \x14\x00\x01\x10\x10\x00, 6);
+   cmd.args[4] |= s-ts_mode;
+   cmd.wlen = 6;
+   cmd.rlen = 4;
+   ret = si2168_cmd_execute(s, cmd);
+   if (ret)
+   goto err;
+
s-active = true;
 
return 0;
@@ -633,6 +635,7 @@ static int si2168_probe(struct i2c_client *client,
 
*config-i2c_adapter = s-adapter;
*config-fe = s-fe;
+   s-ts_mode = config-ts_mode;
 
i2c_set_clientdata(client, s);
 
diff --git a/drivers/media/dvb-frontends/si2168.h 
b/drivers/media/dvb-frontends/si2168.h
index 3c5b5ab..e086d67 100644
--- a/drivers/media/dvb-frontends/si2168.h
+++ b/drivers/media/dvb-frontends/si2168.h
@@ -34,6 +34,12 @@ struct si2168_config {
 * returned by driver
 */
struct i2c_adapter **i2c_adapter;
+
+   /* TS mode */
+   u8 ts_mode;
 };
 
+#define SI2168_TS_PARALLEL 0x06
+#define SI2168_TS_SERIAL   0x03
+
 #endif
diff --git a/drivers/media/dvb-frontends/si2168_priv.h 
b/drivers/media/dvb-frontends/si2168_priv.h
index ebbf502..0f83284 100644
--- a/drivers/media/dvb-frontends/si2168_priv.h
+++ b/drivers/media/dvb-frontends/si2168_priv.h
@@ -36,6 +36,7 @@ struct si2168 {
fe_delivery_system_t delivery_system;
fe_status_t fe_status;
bool active;
+   u8 ts_mode;
 };
 
 /* firmare command struct */
-- 
1.9.1

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


[PATCH 3/6] cxusb: add ts mode setting for TechnoTrend CT2-4400

2014-08-11 Thread Olli Salonen
TS mode must be set in the existing TechnoTrend CT2-4400 driver.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/usb/dvb-usb/cxusb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/usb/dvb-usb/cxusb.c 
b/drivers/media/usb/dvb-usb/cxusb.c
index 16bc579..87842e9 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -1369,6 +1369,7 @@ static int cxusb_tt_ct2_4400_attach(struct 
dvb_usb_adapter *adap)
/* attach frontend */
si2168_config.i2c_adapter = adapter;
si2168_config.fe = adap-fe_adap[0].fe;
+   si2168_config.ts_mode = SI2168_TS_PARALLEL;
memset(info, 0, sizeof(struct i2c_board_info));
strlcpy(info.type, si2168, I2C_NAME_SIZE);
info.addr = 0x64;
-- 
1.9.1

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


[PATCH 4/6] cx23885: add i2c client handling into dvb_unregister and state

2014-08-11 Thread Olli Salonen
Prepare cx23885 driver for handling I2C client that is needed for certain 
demodulators and tuners (for example Si2168 and Si2157). I2C client for tuner 
and demod stored in state and unregistering of the I2C devices added into 
dvb_unregister.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/pci/cx23885/cx23885-dvb.c | 16 
 drivers/media/pci/cx23885/cx23885.h |  3 +++
 2 files changed, 19 insertions(+)

diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c 
b/drivers/media/pci/cx23885/cx23885-dvb.c
index 968fecc..2608155 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -1643,6 +1643,7 @@ int cx23885_dvb_register(struct cx23885_tsport *port)
 int cx23885_dvb_unregister(struct cx23885_tsport *port)
 {
struct videobuf_dvb_frontend *fe0;
+   struct i2c_client *client;
 
/* FIXME: in an error condition where the we have
 * an expected number of frontends (attach problem)
@@ -1651,6 +1652,21 @@ int cx23885_dvb_unregister(struct cx23885_tsport *port)
 * This comment only applies to future boards IF they
 * implement MFE support.
 */
+
+   /* remove I2C client for tuner */
+   client = port-i2c_client_tuner;
+   if (client) {
+   module_put(client-dev.driver-owner);
+   i2c_unregister_device(client);
+   }
+
+   /* remove I2C client for demodulator */
+   client = port-i2c_client_demod;
+   if (client) {
+   module_put(client-dev.driver-owner);
+   i2c_unregister_device(client);
+   }
+
fe0 = videobuf_dvb_get_frontend(port-frontends, 1);
if (fe0  fe0-dvb.frontend)
videobuf_dvb_unregister_bus(port-frontends);
diff --git a/drivers/media/pci/cx23885/cx23885.h 
b/drivers/media/pci/cx23885/cx23885.h
index 0e086c0..1040b3e 100644
--- a/drivers/media/pci/cx23885/cx23885.h
+++ b/drivers/media/pci/cx23885/cx23885.h
@@ -326,6 +326,9 @@ struct cx23885_tsport {
/* Workaround for a temp dvb_frontend that the tuner can attached to */
struct dvb_frontend analog_fe;
 
+   struct i2c_client *i2c_client_demod;
+   struct i2c_client *i2c_client_tuner;
+
int (*set_frontend)(struct dvb_frontend *fe);
 };
 
-- 
1.9.1

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


[PATCH 6/6] cx23855: add support for DVBSky T9580 DVB-C/T2/S2 tuner

2014-08-11 Thread Olli Salonen
DVBSky T9580 is a dual tuner card with one DVB-T2/C tuner and one DVB-S2 tuner. 
It contains the following components:

- PCIe bridge: Conexant CX23885
- Demod for terrestrial/cable: Silicon Labs Si2168-A30
- Tuner for terrestrial/cable: Silicon Labs Si2158-A20
- Demod for sat: Montage DS3103
- Tuner for sat: Montage TS2022

This patch depends on Max Nibble's patch for m88ds3103 (see patchwork 25312: 
https://patchwork.linuxtv.org/patch/25312/ ).

3 firmwares are needed:
- Si2168-A30 demod and Si2158-A20 tuner: same as TechnoTrend CT2-4400, 
https://www.mail-archive.com/linux-media@vger.kernel.org/msg76944.html
- Montage DS3103 demod: same as PCTV 461e, Antti has it on his LinuxTV project 
page: http://palosaari.fi/linux/v4l-dvb/firmware/M88DS3103/

IR receiver is not supported.

Values in cx23885_gpio_setup, cx23885_card_setup and dvbsky_t9580_set_voltage 
as well as the EEPROM read function are taken from the manufacturer provided 
semi-open source driver. The drivers in question are Linux GPL'd media tree 
drivers for cx23885 modified by Max Nibble (nibble@gmail.com) with 
proprietary tuner/demod drivers. Max is aware of this patch and has approved my 
use of the values in this patch.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/pci/cx23885/Kconfig |   4 +
 drivers/media/pci/cx23885/cx23885-cards.c |  26 +
 drivers/media/pci/cx23885/cx23885-dvb.c   | 160 ++
 drivers/media/pci/cx23885/cx23885.h   |   1 +
 4 files changed, 191 insertions(+)

diff --git a/drivers/media/pci/cx23885/Kconfig 
b/drivers/media/pci/cx23885/Kconfig
index e12c006..413587e 100644
--- a/drivers/media/pci/cx23885/Kconfig
+++ b/drivers/media/pci/cx23885/Kconfig
@@ -32,12 +32,16 @@ config VIDEO_CX23885
select DVB_A8293 if MEDIA_SUBDRV_AUTOSELECT
select DVB_MB86A20S if MEDIA_SUBDRV_AUTOSELECT
select DVB_SI2165 if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_SI2168 if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_M88DS3103 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
select MEDIA_TUNER_TDA8290 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_TDA18271 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT
+   select MEDIA_TUNER_SI2157 if MEDIA_SUBDRV_AUTOSELECT
+   select MEDIA_TUNER_M88TS2022 if MEDIA_SUBDRV_AUTOSELECT
select DVB_TUNER_DIB0070 if MEDIA_SUBDRV_AUTOSELECT
---help---
  This is a video4linux driver for Conexant 23885 based
diff --git a/drivers/media/pci/cx23885/cx23885-cards.c 
b/drivers/media/pci/cx23885/cx23885-cards.c
index c2b6080..c1b02bb 100644
--- a/drivers/media/pci/cx23885/cx23885-cards.c
+++ b/drivers/media/pci/cx23885/cx23885-cards.c
@@ -679,6 +679,11 @@ struct cx23885_board cx23885_boards[] = {
.amux   = CX25840_AUDIO7,
} },
},
+   [CX23885_BOARD_DVBSKY_T9580] = {
+   .name   = DVBSky T9580,
+   .portb  = CX23885_MPEG_DVB,
+   .portc  = CX23885_MPEG_DVB,
+   },
 };
 const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
 
@@ -934,6 +939,10 @@ struct cx23885_subid cx23885_subids[] = {
.subvendor = 0x18ac,
.subdevice = 0xdb98,
.card  = CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP2,
+   }, {
+   .subvendor = 0x4254,
+   .subdevice = 0x9580,
+   .card  = CX23885_BOARD_DVBSKY_T9580,
},
 };
 const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
@@ -1528,6 +1537,14 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
cx_set(GP0_IO, 0x00040004);
mdelay(60);
break;
+   case CX23885_BOARD_DVBSKY_T9580:
+   /* enable GPIO3-18 pins */
+   cx_write(MC417_CTL, 0x0037);
+   cx23885_gpio_enable(dev, GPIO_2 | GPIO_11, 1);
+   cx23885_gpio_clear(dev, GPIO_2 | GPIO_11);
+   mdelay(100);
+   cx23885_gpio_set(dev, GPIO_2 | GPIO_11);
+   break;
}
 }
 
@@ -1851,6 +1868,14 @@ void cx23885_card_setup(struct cx23885_dev *dev)
ts2-ts_clk_en_val = 0x1; /* Enable TS_CLK */
ts2-src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
break;
+   case CX23885_BOARD_DVBSKY_T9580:
+   ts1-gen_ctrl_val  = 0x5; /* Parallel */
+   ts1-ts_clk_en_val = 0x1; /* Enable TS_CLK */
+   ts1-src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
+   ts2-gen_ctrl_val  = 0x8; /* Serial bus */
+   ts2-ts_clk_en_val = 0x1; /* Enable TS_CLK */
+   ts2-src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
+   break;
case

[PATCH 4/4] cxusb: Add read_mac_address for TT CT2-4400 and CT2-4650

2014-08-08 Thread Olli Salonen
Read MAC address from the EEPROM.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/usb/dvb-usb/cxusb.c | 37 +
 1 file changed, 37 insertions(+)

diff --git a/drivers/media/usb/dvb-usb/cxusb.c 
b/drivers/media/usb/dvb-usb/cxusb.c
index c3a44c7..6abfd6b 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -673,6 +673,41 @@ static struct rc_map_table rc_map_d680_dmb_table[] = {
{ 0x0025, KEY_POWER },
 };
 
+static int cxusb_tt_ct2_4400_read_mac_address(struct dvb_usb_device *d, u8 
mac[6])
+{
+   u8 wbuf[2];
+   u8 rbuf[6];
+   int ret;
+   struct i2c_msg msg[] = {
+   {
+   .addr = 0x51,
+   .flags = 0,
+   .buf = wbuf,
+   .len = 2,
+   }, {
+   .addr = 0x51,
+   .flags = I2C_M_RD,
+   .buf = rbuf,
+   .len = 6,
+   }
+   };
+
+   wbuf[0] = 0x1e;
+   wbuf[1] = 0x00;
+   ret = cxusb_i2c_xfer(d-i2c_adap, msg, 2);
+
+   if (ret == 2) {
+   memcpy(mac, rbuf, 6);
+   return 0;
+   } else {
+   if (ret  0)
+   return ret;
+   else
+   return -EIO;
+   }
+   }
+}
+
 static int cxusb_tt_ct2_4650_ci_ctrl(void *priv, u8 read, int addr,
u8 data, int *mem)
 {
@@ -2315,6 +2350,8 @@ static struct dvb_usb_device_properties 
cxusb_tt_ct2_4400_properties = {
.size_of_priv = sizeof(struct cxusb_state),
 
.num_adapters = 1,
+   .read_mac_address = cxusb_tt_ct2_4400_read_mac_address,
+
.adapter = {
{
.num_frontends = 1,
-- 
1.9.1

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


[PATCHv2 1/4] sp2: Add I2C driver for CIMaX SP2 common interface module

2014-08-08 Thread Olli Salonen
Driver for the CIMaX SP2 common interface chip. It is very much based on
the existing cimax2 driver for cx23885, but should be more reusable. The
product has been sold with name Atmel T90FJR as well and the data sheets
for that chip seem to be publicly available.

It seems that the USB device that I have and the cx23885 based devices will
need to interact differently with the chip for the CAM operations. Thus
there is one callback function that is passed on to the sp2 driver
(see function sp2_ci_op_cam for that one).

IRQ functionality is not included currently (not needed by USB devices
and I don't have a PCIe device for development).

This is the second version of the patch series after review by Antti
Palosaari.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-frontends/Kconfig|   7 +
 drivers/media/dvb-frontends/Makefile   |   1 +
 drivers/media/dvb-frontends/sp2.c  | 441 +
 drivers/media/dvb-frontends/sp2.h  |  53 
 drivers/media/dvb-frontends/sp2_priv.h |  50 
 5 files changed, 552 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/sp2.c
 create mode 100644 drivers/media/dvb-frontends/sp2.h
 create mode 100644 drivers/media/dvb-frontends/sp2_priv.h

diff --git a/drivers/media/dvb-frontends/Kconfig 
b/drivers/media/dvb-frontends/Kconfig
index fe0ddcc..c38c936 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -720,6 +720,13 @@ config DVB_A8293
depends on DVB_CORE  I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
 
+config DVB_SP2
+   tristate CIMaX SP2
+   depends on DVB_CORE  I2C
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ CIMaX SP2/SP2HF Common Interface module.
+
 config DVB_LGS8GL5
tristate Silicon Legend LGS-8GL5 demodulator (OFDM)
depends on DVB_CORE  I2C
diff --git a/drivers/media/dvb-frontends/Makefile 
b/drivers/media/dvb-frontends/Makefile
index edf103d..3498b95 100644
--- a/drivers/media/dvb-frontends/Makefile
+++ b/drivers/media/dvb-frontends/Makefile
@@ -107,6 +107,7 @@ 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_SP2) += sp2.o
 obj-$(CONFIG_DVB_TDA10071) += tda10071.o
 obj-$(CONFIG_DVB_RTL2830) += rtl2830.o
 obj-$(CONFIG_DVB_RTL2832) += rtl2832.o
diff --git a/drivers/media/dvb-frontends/sp2.c 
b/drivers/media/dvb-frontends/sp2.c
new file mode 100644
index 000..9b684d5
--- /dev/null
+++ b/drivers/media/dvb-frontends/sp2.c
@@ -0,0 +1,441 @@
+/*
+ * CIMaX SP2/SP2HF (Atmel T90FJR) CI driver
+ *
+ * Copyright (C) 2014 Olli Salonen olli.salo...@iki.fi
+ *
+ * Heavily based on CIMax2(R) SP2 driver in conjunction with NetUp Dual
+ * DVB-S2 CI card (cimax2) with following copyrights:
+ *
+ *  Copyright (C) 2009 NetUP Inc.
+ *  Copyright (C) 2009 Igor M. Liplianin liplia...@netup.ru
+ *  Copyright (C) 2009 Abylay Ospan aos...@netup.ru
+ *
+ *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.
+ */
+
+#include sp2_priv.h
+
+static int sp2_read_i2c(struct sp2 *s, u8 reg, u8 *buf, int len)
+{
+   int ret;
+   struct i2c_client *client = s-client;
+   struct i2c_adapter *adap = client-adapter;
+   struct i2c_msg msg[] = {
+   {
+   .addr = client-addr,
+   .flags = 0,
+   .buf = reg,
+   .len = 1
+   }, {
+   .addr = client-addr,
+   .flags  = I2C_M_RD,
+   .buf = buf,
+   .len = len
+   }
+   };
+
+   ret = i2c_transfer(adap, msg, 2);
+
+   if (ret != 2) {
+   dev_err(client-dev, i2c read error, reg = 0x%02x, status = 
%d\n,
+   reg, ret);
+   if (ret  0)
+   return ret;
+   else
+   return -EIO;
+   }
+
+   dev_dbg(s-client-dev, addr=0x%04x, reg = 0x%02x, data = %02x\n,
+   client-addr, reg, buf[0]);
+
+   return 0;
+}
+
+static int sp2_write_i2c(struct sp2 *s, u8 reg, u8 *buf, int len)
+{
+   int ret;
+   u8 buffer[35];
+   struct i2c_client *client = s-client;
+   struct i2c_adapter *adap = client-adapter;
+   struct i2c_msg msg = {
+   .addr = client-addr,
+   .flags = 0,
+   .buf = buffer[0

[PATCHv2 3/4] cxusb: Add support for TechnoTrend TT-connect CT2-4650 CI

2014-08-08 Thread Olli Salonen
TechnoTrend TT-connect CT2-4650 CI (0b48:3012) is an USB DVB-T2/C tuner with
the following components:

 USB interface: Cypress CY7C68013A-56LTXC
 Demodulator: Silicon Labs Si2168-A20
 Tuner: Silicon Labs Si2158-A20
 CI chip: CIMaX SP2HF

The firmware for the tuner is the same as for TechnoTrend TT-TVStick CT2-4400.
See https://www.mail-archive.com/linux-media@vger.kernel.org/msg76944.html

The demodulator needs a firmware that can be extracted from the Windows 
drivers. 
File ttConnect4650_64.sys should be extracted from 
http://www.tt-downloads.de/bda-treiber_4.1.0.4.zip (MD5 sum below).

3464bfc37a47b4032568718bacba23fb  ttConnect4650_64.sys

Then the firmware can be extracted:
dd if=ttConnect4650_64.sys ibs=1 skip=273376 count=6424 
of=dvb-demod-si2168-a20-01.fw

The SP2 CI module requires a definition of a function cxusb_tt_ct2_4650_ci_ctrl
that is passed on to the SP2 driver and called back for CAM operations.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/usb/dvb-usb/Kconfig |  2 +-
 drivers/media/usb/dvb-usb/cxusb.c | 92 ++-
 drivers/media/usb/dvb-usb/cxusb.h |  4 ++
 3 files changed, 96 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/Kconfig 
b/drivers/media/usb/dvb-usb/Kconfig
index 10aef21..41d3eb9 100644
--- a/drivers/media/usb/dvb-usb/Kconfig
+++ b/drivers/media/usb/dvb-usb/Kconfig
@@ -130,7 +130,7 @@ config DVB_USB_CXUSB
 
  Medion MD95700 hybrid USB2.0 device.
  DViCO FusionHDTV (Bluebird) USB2.0 devices
- TechnoTrend TVStick CT2-4400
+ TechnoTrend TVStick CT2-4400 and CT2-4650 CI devices
 
 config DVB_USB_M920X
tristate Uli m920x DVB-T USB2.0 support
diff --git a/drivers/media/usb/dvb-usb/cxusb.c 
b/drivers/media/usb/dvb-usb/cxusb.c
index 16bc579..c3a44c7 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -44,6 +44,7 @@
 #include atbm8830.h
 #include si2168.h
 #include si2157.h
+#include sp2.h
 
 /* Max transfer size done by I2C transfer functions */
 #define MAX_XFER_SIZE  80
@@ -672,6 +673,37 @@ static struct rc_map_table rc_map_d680_dmb_table[] = {
{ 0x0025, KEY_POWER },
 };
 
+static int cxusb_tt_ct2_4650_ci_ctrl(void *priv, u8 read, int addr,
+   u8 data, int *mem)
+{
+   struct dvb_usb_device *d = priv;
+   u8 wbuf[3];
+   u8 rbuf[2];
+   int ret;
+
+   wbuf[0] = (addr  8)  0xff;
+   wbuf[1] = addr  0xff;
+
+   if (read) {
+   ret = cxusb_ctrl_msg(d, CMD_SP2_CI_READ, wbuf, 2, rbuf, 2);
+   } else {
+   wbuf[2] = data;
+   ret = cxusb_ctrl_msg(d, CMD_SP2_CI_WRITE, wbuf, 3, rbuf, 1);
+   }
+
+   if (ret)
+   goto err;
+
+   if (read)
+   *mem = rbuf[1];
+
+   return 0;
+err:
+   deb_info(%s: ci usb write returned %d\n, __func__, ret);
+   return ret;
+
+}
+
 static int cxusb_dee1601_demod_init(struct dvb_frontend* fe)
 {
static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x28 };
@@ -1350,9 +1382,12 @@ static int cxusb_tt_ct2_4400_attach(struct 
dvb_usb_adapter *adap)
struct i2c_adapter *adapter;
struct i2c_client *client_demod;
struct i2c_client *client_tuner;
+   struct i2c_client *client_ci;
struct i2c_board_info info;
struct si2168_config si2168_config;
struct si2157_config si2157_config;
+   struct sp2_config sp2_config;
+   u8 o[2], i;
 
/* reset the tuner */
if (cxusb_tt_ct2_4400_gpio_tuner(d, 0)  0) {
@@ -1408,6 +1443,48 @@ static int cxusb_tt_ct2_4400_attach(struct 
dvb_usb_adapter *adap)
 
st-i2c_client_tuner = client_tuner;
 
+   /* initialize CI */
+   if (d-udev-descriptor.idProduct ==
+   USB_PID_TECHNOTREND_CONNECT_CT2_4650_CI) {
+
+   memcpy(o, \xc0\x01, 2);
+   cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, i, 1);
+   msleep(100);
+
+   memcpy(o, \xc0\x00, 2);
+   cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, i, 1);
+   msleep(100);
+
+   memset(sp2_config, 0, sizeof(sp2_config));
+   sp2_config.dvb_adap = adap-dvb_adap;
+   sp2_config.priv = d;
+   sp2_config.ci_control = cxusb_tt_ct2_4650_ci_ctrl;
+   memset(info, 0, sizeof(struct i2c_board_info));
+   strlcpy(info.type, sp2, I2C_NAME_SIZE);
+   info.addr = 0x40;
+   info.platform_data = sp2_config;
+   request_module(info.type);
+   client_ci = i2c_new_device(d-i2c_adap, info);
+   if (client_ci == NULL || client_ci-dev.driver == NULL) {
+   module_put(client_tuner-dev.driver-owner);
+   i2c_unregister_device(client_tuner);
+   module_put(client_demod-dev.driver-owner);
+   i2c_unregister_device(client_demod

[PATCHv2 2/4] Add USB ID for TechnoTrend TT-connect CT2-4650 CI

2014-08-08 Thread Olli Salonen
Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-core/dvb-usb-ids.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/dvb-core/dvb-usb-ids.h 
b/drivers/media/dvb-core/dvb-usb-ids.h
index 5135a09..b7a9b98 100644
--- a/drivers/media/dvb-core/dvb-usb-ids.h
+++ b/drivers/media/dvb-core/dvb-usb-ids.h
@@ -244,6 +244,7 @@
 #define USB_PID_TECHNOTREND_CONNECT_S2400   0x3006
 #define USB_PID_TECHNOTREND_CONNECT_S2400_8KEEPROM 0x3009
 #define USB_PID_TECHNOTREND_CONNECT_CT3650 0x300d
+#define USB_PID_TECHNOTREND_CONNECT_CT2_4650_CI0x3012
 #define USB_PID_TECHNOTREND_TVSTICK_CT2_4400   0x3014
 #define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY   0x005a
 #define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY_2 0x0081
-- 
1.9.1

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


Re: [PATCH 1/3] sp2: Add I2C driver for CIMaX SP2 common interface module

2014-08-07 Thread Olli Salonen
Thank you Antti for the review. I'll submit another version of the
patch in the coming days.

Cheers,
-olli

On 7 August 2014 19:28, Antti Palosaari cr...@iki.fi wrote:
 Reviewed-by: Antti Palosaari cr...@iki.fi

 None of those findings are critical. However I hope you double check and fix
 if there is any relevant enough.

 regards
 Antti

 --
 http://palosaari.fi/
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/4] support for DVBSky dvb-s2 usb: add dvb-usb-v2 driver for DVBSky dvb-s2 box

2014-08-07 Thread Olli Salonen
Hi Max,

nibble.max nibble.max at gmail.com writes:
 diff --git a/drivers/media/usb/dvb-usb-v2/Kconfig
b/drivers/media/usb/dvb-usb-v2/Kconfig
 index 66645b0..8107c8d 100644
 --- a/drivers/media/usb/dvb-usb-v2/Kconfig
 +++ b/drivers/media/usb/dvb-usb-v2/Kconfig
  at  at  -141,3 +141,9  at  at  config DVB_USB_RTL28XXU
   help
 Say Y here to support the Realtek RTL28xxU DVB USB receiver.
 
 +config DVB_USB_DVBSKY
 + tristate DVBSky USB support
 + depends on DVB_USB_V2
 + select DVB_M88DS3103 if MEDIA_SUBDRV_AUTOSELECT
 + help
 +   Say Y here to support the USB receivers from DVBSky.

Shouldn't the MEDIA_TUNER_M88TS2022 also be selected in Kconfig?

Cheers,
-olli



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


[PATCH 3/3] cxusb: Add support for TechnoTrend TT-connect CT2-4650 CI

2014-08-06 Thread Olli Salonen
TechnoTrend TT-connect CT2-4650 CI is an USB DVB-T2/C tuner with the
following components:

 USB interface: Cypress CY7C68013A-56LTXC
 Demodulator: Silicon Labs Si2168-A20
 Tuner: Silicon Labs Si2158-A20
 CI chip: CIMaX SP2HF

The firmware for the tuner is the same as for TechnoTrend TT-TVStick CT2-4400. 
See
https://www.mail-archive.com/linux-media@vger.kernel.org/msg76944.html

The demodulator needs a firmware that can be extracted from the Windows drivers.
File ttConnect4650_64.sys should be extracted from
http://www.tt-downloads.de/bda-treiber_4.1.0.4.zip (MD5 sum below).

3464bfc37a47b4032568718bacba23fb  ttConnect4650_64.sys

Then the firmware can be extracted:
dd if=ttConnect4650_64.sys ibs=1 skip=273376 count=6424 
of=dvb-demod-si2168-a20-01.fw

The SP2 CI module requires a definition of a function cxusb_tt_ct2_4650_ci_ctrl 
that
is passed on to the SP2 driver and called back for CAM operations.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/usb/dvb-usb/Kconfig |  1 +
 drivers/media/usb/dvb-usb/cxusb.c | 92 ++-
 drivers/media/usb/dvb-usb/cxusb.h |  4 ++
 3 files changed, 96 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/dvb-usb/Kconfig 
b/drivers/media/usb/dvb-usb/Kconfig
index 10aef21..87deb55 100644
--- a/drivers/media/usb/dvb-usb/Kconfig
+++ b/drivers/media/usb/dvb-usb/Kconfig
@@ -118,6 +118,7 @@ config DVB_USB_CXUSB
select DVB_ATBM8830 if MEDIA_SUBDRV_AUTOSELECT
select DVB_LGS8GXX if MEDIA_SUBDRV_AUTOSELECT
select DVB_SI2168 if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_SP2 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_SIMPLE if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_XC2028 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_MXL5005S if MEDIA_SUBDRV_AUTOSELECT
diff --git a/drivers/media/usb/dvb-usb/cxusb.c 
b/drivers/media/usb/dvb-usb/cxusb.c
index 16bc579..499d76d 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -44,6 +44,7 @@
 #include atbm8830.h
 #include si2168.h
 #include si2157.h
+#include sp2.h
 
 /* Max transfer size done by I2C transfer functions */
 #define MAX_XFER_SIZE  80
@@ -672,6 +673,37 @@ static struct rc_map_table rc_map_d680_dmb_table[] = {
{ 0x0025, KEY_POWER },
 };
 
+static int cxusb_tt_ct2_4650_ci_ctrl(void *priv, u8 read, int addr,
+   u8 data, int *mem)
+{
+   struct dvb_usb_device *d = priv;
+   u8 wbuf[3];
+   u8 rbuf[2];
+   int ret;
+
+   wbuf[0] = (addr  8)  0xff;
+   wbuf[1] = addr  0xff;
+
+   if (read) {
+   ret = cxusb_ctrl_msg(d, CMD_SP2_CI_READ, wbuf, 2, rbuf, 2);
+   } else {
+   wbuf[2] = data;
+   ret = cxusb_ctrl_msg(d, CMD_SP2_CI_WRITE, wbuf, 3, rbuf, 1);
+   }
+
+   if (ret)
+   goto err;
+
+   if (read)
+   *mem = rbuf[1];
+
+   return 0;
+err:
+   deb_info(%s: ci usb write returned %d\n, __func__, ret);
+   return ret;
+
+}
+
 static int cxusb_dee1601_demod_init(struct dvb_frontend* fe)
 {
static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x28 };
@@ -1350,9 +1382,12 @@ static int cxusb_tt_ct2_4400_attach(struct 
dvb_usb_adapter *adap)
struct i2c_adapter *adapter;
struct i2c_client *client_demod;
struct i2c_client *client_tuner;
+   struct i2c_client *client_ci;
struct i2c_board_info info;
struct si2168_config si2168_config;
struct si2157_config si2157_config;
+   struct sp2_config sp2_config;
+   u8 o[2], i;
 
/* reset the tuner */
if (cxusb_tt_ct2_4400_gpio_tuner(d, 0)  0) {
@@ -1408,6 +1443,48 @@ static int cxusb_tt_ct2_4400_attach(struct 
dvb_usb_adapter *adap)
 
st-i2c_client_tuner = client_tuner;
 
+   /* initialize CI */
+   if (d-udev-descriptor.idProduct ==
+   USB_PID_TECHNOTREND_CONNECT_CT2_4650_CI) {
+
+   memcpy(o, \xc0\x01, 2);
+   cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, i, 1);
+   msleep(100);
+
+   memcpy(o, \xc0\x00, 2);
+   cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, i, 1);
+   msleep(100);
+
+   memset(sp2_config, 0, sizeof(sp2_config));
+   sp2_config.dvb_adap = adap-dvb_adap;
+   sp2_config.priv = d;
+   sp2_config.ci_control = cxusb_tt_ct2_4650_ci_ctrl;
+   memset(info, 0, sizeof(struct i2c_board_info));
+   strlcpy(info.type, sp2, I2C_NAME_SIZE);
+   info.addr = 0x40;
+   info.platform_data = sp2_config;
+   request_module(info.type);
+   client_ci = i2c_new_device(d-i2c_adap, info);
+   if (client_ci == NULL || client_ci-dev.driver == NULL) {
+   module_put(client_tuner-dev.driver-owner);
+   i2c_unregister_device(client_tuner);
+   module_put

[PATCH 2/3] Add USB ID for TechnoTrend TT-connect CT2-4650 CI

2014-08-06 Thread Olli Salonen
Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-core/dvb-usb-ids.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/dvb-core/dvb-usb-ids.h 
b/drivers/media/dvb-core/dvb-usb-ids.h
index 5135a09..b7a9b98 100644
--- a/drivers/media/dvb-core/dvb-usb-ids.h
+++ b/drivers/media/dvb-core/dvb-usb-ids.h
@@ -244,6 +244,7 @@
 #define USB_PID_TECHNOTREND_CONNECT_S2400   0x3006
 #define USB_PID_TECHNOTREND_CONNECT_S2400_8KEEPROM 0x3009
 #define USB_PID_TECHNOTREND_CONNECT_CT3650 0x300d
+#define USB_PID_TECHNOTREND_CONNECT_CT2_4650_CI0x3012
 #define USB_PID_TECHNOTREND_TVSTICK_CT2_4400   0x3014
 #define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY   0x005a
 #define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY_2 0x0081
-- 
1.9.1

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


[PATCH 1/3] sp2: Add I2C driver for CIMaX SP2 common interface module

2014-08-06 Thread Olli Salonen
Driver for the CIMaX SP2 common interface chip. It is very much based on
the existing cimax2 driver for cx23885, but should be more reusable. The
product has been sold with name Atmel T90FJR as well and the data sheets
for that chip seem to be publicly available.

It seems that the USB device that I have and the cx23885 based devices will
need to interact differently with the chip for the CAM operations. Thus
there is one callback function that is passed on to the sp2 driver
(see function sp2_ci_op_cam for that one).

IRQ functionality is not included currently (not needed by USB devices
and I don't have a PCIe device for development).

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-frontends/Makefile   |   1 +
 drivers/media/dvb-frontends/sp2.c  | 411 +
 drivers/media/dvb-frontends/sp2.h  |  54 +
 drivers/media/dvb-frontends/sp2_priv.h |  49 
 4 files changed, 515 insertions(+)
 create mode 100644 drivers/media/dvb-frontends/sp2.c
 create mode 100644 drivers/media/dvb-frontends/sp2.h
 create mode 100644 drivers/media/dvb-frontends/sp2_priv.h

diff --git a/drivers/media/dvb-frontends/Makefile 
b/drivers/media/dvb-frontends/Makefile
index edf103d..3498b95 100644
--- a/drivers/media/dvb-frontends/Makefile
+++ b/drivers/media/dvb-frontends/Makefile
@@ -107,6 +107,7 @@ 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_SP2) += sp2.o
 obj-$(CONFIG_DVB_TDA10071) += tda10071.o
 obj-$(CONFIG_DVB_RTL2830) += rtl2830.o
 obj-$(CONFIG_DVB_RTL2832) += rtl2832.o
diff --git a/drivers/media/dvb-frontends/sp2.c 
b/drivers/media/dvb-frontends/sp2.c
new file mode 100644
index 000..c1b4d7e
--- /dev/null
+++ b/drivers/media/dvb-frontends/sp2.c
@@ -0,0 +1,411 @@
+/*
+ * CIMaX SP2/SP2HF (Atmel T90FJR) CI driver
+ *
+ * Copyright (C) 2014 Olli Salonen olli.salo...@iki.fi
+ *
+ * Heavily based on CIMax2(R) SP2 driver in conjunction with NetUp Dual
+ * DVB-S2 CI card (cimax2) with following copyrights:
+ *
+ *  Copyright (C) 2009 NetUP Inc.
+ *  Copyright (C) 2009 Igor M. Liplianin liplia...@netup.ru
+ *  Copyright (C) 2009 Abylay Ospan aos...@netup.ru
+ *
+ *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.
+ */
+
+#include sp2_priv.h
+
+static int sp2_read_i2c(struct sp2 *s, u8 reg, u8 *buf, int len)
+{
+   int ret;
+   struct i2c_client *client = s-client;
+   struct i2c_adapter *adap = client-adapter;
+   struct i2c_msg msg[] = {
+   {
+   .addr = client-addr,
+   .flags = 0,
+   .buf = reg,
+   .len = 1
+   }, {
+   .addr = client-addr,
+   .flags  = I2C_M_RD,
+   .buf = buf,
+   .len = len
+   }
+   };
+
+   ret = i2c_transfer(adap, msg, 2);
+
+   if (ret != 2) {
+   dev_err(client-dev, i2c read error, reg = 0x%02x, status = 
%d\n,
+   reg, ret);
+   return -1;
+   }
+
+   dev_dbg(s-client-dev, addr=0x%04x, reg = 0x%02x, data = %02x\n,
+   client-addr, reg, buf[0]);
+
+   return 0;
+}
+
+static int sp2_write_i2c(struct sp2 *s, u8 reg, u8 *buf, int len)
+{
+   int ret;
+   u8 buffer[35];
+   struct i2c_client *client = s-client;
+   struct i2c_adapter *adap = client-adapter;
+   struct i2c_msg msg = {
+   .addr = client-addr,
+   .flags = 0,
+   .buf = buffer[0],
+   .len = len + 1
+   };
+
+   if ((len + 1)  sizeof(buffer)) {
+   dev_err(client-dev, i2c wr reg=%02x: len=%d is too big!\n,
+   reg, len);
+   return -EINVAL;
+   }
+
+   buffer[0] = reg;
+   memcpy(buffer[1], buf, len);
+
+   ret = i2c_transfer(adap, msg, 1);
+
+   if (ret != 1) {
+   dev_err(client-dev, i2c write error, reg = 0x%02x, status = 
%d\n,
+   reg, ret);
+   return -1;
+   }
+
+   return 0;
+}
+
+static int sp2_ci_op_cam(struct dvb_ca_en50221 *en50221, int slot, u8 acs,
+   u8 read, int addr, u8 data)
+{
+   struct sp2 *s = en50221-data;
+   u8 store;
+   int mem, ret;
+   int (*ci_op_cam)(void*, u8, int, u8, int*) = s-ci_control

[PATCH] sp2: Add SP2 entry to Kconfig

2014-08-06 Thread Olli Salonen
Option DVB_SP2 must be in Kconfig as well. This patch should be applied 
together with patch 25206 that was submitted earlier today.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-frontends/Kconfig | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/media/dvb-frontends/Kconfig 
b/drivers/media/dvb-frontends/Kconfig
index fe0ddcc..c38c936 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -720,6 +720,13 @@ config DVB_A8293
depends on DVB_CORE  I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
 
+config DVB_SP2
+   tristate CIMaX SP2
+   depends on DVB_CORE  I2C
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ CIMaX SP2/SP2HF Common Interface module.
+
 config DVB_LGS8GL5
tristate Silicon Legend LGS-8GL5 demodulator (OFDM)
depends on DVB_CORE  I2C
-- 
1.9.1

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


[PATCH] si2168: clean logging

2014-08-05 Thread Olli Salonen
Same thing for si2168 as Antti did earlier for tda18212:

There is no need to print module name nor function name as those
are done by kernel logging system when dev_xxx logging is used and
driver is proper I2C driver.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-frontends/si2168.c | 70 +---
 1 file changed, 33 insertions(+), 37 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2168.c 
b/drivers/media/dvb-frontends/si2168.c
index 8f81d97..59a4218 100644
--- a/drivers/media/dvb-frontends/si2168.c
+++ b/drivers/media/dvb-frontends/si2168.c
@@ -55,8 +55,7 @@ static int si2168_cmd_execute(struct si2168 *s, struct 
si2168_cmd *cmd)
break;
}
 
-   dev_dbg(s-client-dev, %s: cmd execution took %d ms\n,
-   __func__,
+   dev_dbg(s-client-dev, cmd execution took %d ms\n,
jiffies_to_msecs(jiffies) -
(jiffies_to_msecs(timeout) - TIMEOUT));
 
@@ -75,7 +74,7 @@ err_mutex_unlock:
 
return 0;
 err:
-   dev_dbg(s-client-dev, %s: failed=%d\n, __func__, ret);
+   dev_dbg(s-client-dev, failed=%d\n, ret);
return ret;
 }
 
@@ -150,12 +149,12 @@ static int si2168_read_status(struct dvb_frontend *fe, 
fe_status_t *status)
c-cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
}
 
-   dev_dbg(s-client-dev, %s: status=%02x args=%*ph\n,
-   __func__, *status, cmd.rlen, cmd.args);
+   dev_dbg(s-client-dev, status=%02x args=%*ph\n,
+   *status, cmd.rlen, cmd.args);
 
return 0;
 err:
-   dev_dbg(s-client-dev, %s: failed=%d\n, __func__, ret);
+   dev_dbg(s-client-dev, failed=%d\n, ret);
return ret;
 }
 
@@ -168,8 +167,8 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
u8 bandwidth, delivery_system;
 
dev_dbg(s-client-dev,
-   %s: delivery_system=%u modulation=%u frequency=%u 
bandwidth_hz=%u symbol_rate=%u inversion=%u\n,
-   __func__, c-delivery_system, c-modulation,
+   delivery_system=%u modulation=%u frequency=%u 
bandwidth_hz=%u symbol_rate=%u inversion=%u\n,
+   c-delivery_system, c-modulation,
c-frequency, c-bandwidth_hz, c-symbol_rate,
c-inversion);
 
@@ -343,7 +342,7 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
 
return 0;
 err:
-   dev_dbg(s-client-dev, %s: failed=%d\n, __func__, ret);
+   dev_dbg(s-client-dev, failed=%d\n, ret);
return ret;
 }
 
@@ -357,7 +356,7 @@ static int si2168_init(struct dvb_frontend *fe)
struct si2168_cmd cmd;
unsigned int chip_id;
 
-   dev_dbg(s-client-dev, %s:\n, __func__);
+   dev_dbg(s-client-dev, \n);
 
memcpy(cmd.args, 
\xc0\x12\x00\x0c\x00\x0d\x16\x00\x00\x00\x00\x00\x00, 13);
cmd.wlen = 13;
@@ -400,16 +399,16 @@ static int si2168_init(struct dvb_frontend *fe)
break;
default:
dev_err(s-client-dev,
-   %s: unkown chip version Si21%d-%c%c%c\n,
-   KBUILD_MODNAME, cmd.args[2], cmd.args[1],
+   unknown chip version Si21%d-%c%c%c\n,
+   cmd.args[2], cmd.args[1],
cmd.args[3], cmd.args[4]);
ret = -EINVAL;
goto err;
}
 
/* cold state - try to download firmware */
-   dev_info(s-client-dev, %s: found a '%s' in cold state\n,
-   KBUILD_MODNAME, si2168_ops.info.name);
+   dev_info(s-client-dev, found a '%s' in cold state\n,
+   si2168_ops.info.name);
 
/* request the firmware, this will block and timeout */
ret = request_firmware(fw, fw_file, s-client-dev);
@@ -422,18 +421,18 @@ static int si2168_init(struct dvb_frontend *fe)
 
if (ret == 0) {
dev_notice(s-client-dev,
-   %s: please install firmware file 
'%s'\n,
-   KBUILD_MODNAME, SI2168_B40_FIRMWARE);
+   please install firmware file '%s'\n,
+   SI2168_B40_FIRMWARE);
} else {
dev_err(s-client-dev,
-   %s: firmware file '%s' not found\n,
-   KBUILD_MODNAME, fw_file);
+   firmware file '%s' not found\n,
+   fw_file);
goto err;
}
}
 
-   dev_info(s-client-dev, %s: downloading firmware from file '%s'\n,
-   KBUILD_MODNAME, fw_file);
+   dev_info(s-client-dev

[PATCH] si2157: clean logging

2014-08-05 Thread Olli Salonen
Same thing for si2157 as Antti did earlier for tda18212:

There is no need to print module name nor function name as those
are done by kernel logging system when dev_xxx logging is used and
driver is proper I2C driver.

While here, fix a typo (unknown) in si2157_init.

Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/tuners/si2157.c | 52 +--
 1 file changed, 25 insertions(+), 27 deletions(-)

diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
index 6c53edb..2281b7d 100644
--- a/drivers/media/tuners/si2157.c
+++ b/drivers/media/tuners/si2157.c
@@ -55,8 +55,7 @@ static int si2157_cmd_execute(struct si2157 *s, struct 
si2157_cmd *cmd)
break;
}
 
-   dev_dbg(s-client-dev, %s: cmd execution took %d ms\n,
-   __func__,
+   dev_dbg(s-client-dev, cmd execution took %d ms\n,
jiffies_to_msecs(jiffies) -
(jiffies_to_msecs(timeout) - TIMEOUT));
 
@@ -75,7 +74,7 @@ err_mutex_unlock:
 
return 0;
 err:
-   dev_dbg(s-client-dev, %s: failed=%d\n, __func__, ret);
+   dev_dbg(s-client-dev, failed=%d\n, ret);
return ret;
 }
 
@@ -88,7 +87,7 @@ static int si2157_init(struct dvb_frontend *fe)
u8 *fw_file;
unsigned int chip_id;
 
-   dev_dbg(s-client-dev, %s:\n, __func__);
+   dev_dbg(s-client-dev, \n);
 
/* configure? */
memcpy(cmd.args, 
\xc0\x00\x0c\x00\x00\x01\x01\x01\x01\x01\x01\x02\x00\x00\x01, 15);
@@ -121,35 +120,35 @@ static int si2157_init(struct dvb_frontend *fe)
break;
default:
dev_err(s-client-dev,
-   %s: unkown chip version Si21%d-%c%c%c\n,
-   KBUILD_MODNAME, cmd.args[2], cmd.args[1],
+   unknown chip version Si21%d-%c%c%c\n,
+   cmd.args[2], cmd.args[1],
cmd.args[3], cmd.args[4]);
ret = -EINVAL;
goto err;
}
 
/* cold state - try to download firmware */
-   dev_info(s-client-dev, %s: found a '%s' in cold state\n,
-   KBUILD_MODNAME, si2157_ops.info.name);
+   dev_info(s-client-dev, found a '%s' in cold state\n,
+   si2157_ops.info.name);
 
/* request the firmware, this will block and timeout */
ret = request_firmware(fw, fw_file, s-client-dev);
if (ret) {
-   dev_err(s-client-dev, %s: firmware file '%s' not found\n,
-   KBUILD_MODNAME, fw_file);
+   dev_err(s-client-dev, firmware file '%s' not found\n,
+   fw_file);
goto err;
}
 
/* firmware should be n chunks of 17 bytes */
if (fw-size % 17 != 0) {
-   dev_err(s-client-dev, %s: firmware file '%s' is invalid\n,
-   KBUILD_MODNAME, fw_file);
+   dev_err(s-client-dev, firmware file '%s' is invalid\n,
+   fw_file);
ret = -EINVAL;
goto err;
}
 
-   dev_info(s-client-dev, %s: downloading firmware from file '%s'\n,
-   KBUILD_MODNAME, fw_file);
+   dev_info(s-client-dev, downloading firmware from file '%s'\n,
+   fw_file);
 
for (remaining = fw-size; remaining  0; remaining -= 17) {
len = fw-data[fw-size - remaining];
@@ -159,8 +158,8 @@ static int si2157_init(struct dvb_frontend *fe)
ret = si2157_cmd_execute(s, cmd);
if (ret) {
dev_err(s-client-dev,
-   %s: firmware download failed=%d\n,
-   KBUILD_MODNAME, ret);
+   firmware download failed=%d\n,
+   ret);
goto err;
}
}
@@ -184,7 +183,7 @@ err:
if (fw)
release_firmware(fw);
 
-   dev_dbg(s-client-dev, %s: failed=%d\n, __func__, ret);
+   dev_dbg(s-client-dev, failed=%d\n, ret);
return ret;
 }
 
@@ -194,7 +193,7 @@ static int si2157_sleep(struct dvb_frontend *fe)
int ret;
struct si2157_cmd cmd;
 
-   dev_dbg(s-client-dev, %s:\n, __func__);
+   dev_dbg(s-client-dev, \n);
 
s-active = false;
 
@@ -207,7 +206,7 @@ static int si2157_sleep(struct dvb_frontend *fe)
 
return 0;
 err:
-   dev_dbg(s-client-dev, %s: failed=%d\n, __func__, ret);
+   dev_dbg(s-client-dev, failed=%d\n, ret);
return ret;
 }
 
@@ -220,8 +219,8 @@ static int si2157_set_params(struct dvb_frontend *fe)
u8 bandwidth, delivery_system;
 
dev_dbg(s-client-dev,
-   %s

cxusb: How to add CI support?

2014-07-23 Thread Olli Salonen
Hi everyone,

I'm in need of advice when it comes to the implementation of the
drivers. I recently added support for TechnoTrend CT2-4400 DVB-T2
tuner into the dvb-usb-cxusb module. Now I have gotten another
TechnoTrend device CT2-4650 and it seems this is more or less the same
device as CT2-4400 but with an added CI slot. The CI is realized using
a CIMaX SP2HF chip.

There seems to be support already for the said CIMaX chip, but only in
combination with cx23885 (drivers/media/pci/cx23885/
cimax2.c). This cannot be reused directly in my case. When I look at
the other dvb-usb devices that have CI slot the support for CI has
been implemented directly in the code of the USB device (for example,
pctv452e or az6027).

Of course, an easy way to do it is to reuse a lot of code from the
existing cimax2 and add it in the cxusb. However, I'm not sure if
that's an ok approach. As I'm relatively new to linux kernel coding,
I'd like to ask your recommendation for implementing the CI support
here before the endeavour. Thanks!

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


[PATCH] si2168: improve scanning performance by setting property 0301 with a value from Windows driver.

2014-07-17 Thread Olli Salonen
Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-frontends/si2168.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/media/dvb-frontends/si2168.c 
b/drivers/media/dvb-frontends/si2168.c
index 0422925..56811e1 100644
--- a/drivers/media/dvb-frontends/si2168.c
+++ b/drivers/media/dvb-frontends/si2168.c
@@ -313,6 +313,13 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
if (ret)
goto err;
 
+   memcpy(cmd.args, \x14\x00\x01\x03\x0c\x00, 6);
+   cmd.wlen = 6;
+   cmd.rlen = 4;
+   ret = si2168_cmd_execute(s, cmd);
+   if (ret)
+   goto err;
+
memcpy(cmd.args, \x85, 1);
cmd.wlen = 1;
cmd.rlen = 1;
-- 
1.9.1

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


[PATCH] si2157: Use name si2157_ops instead of si2157_tuner_ops (harmonize with si2168)

2014-07-17 Thread Olli Salonen
Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/tuners/si2157.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
index 329004f..4730f69 100644
--- a/drivers/media/tuners/si2157.c
+++ b/drivers/media/tuners/si2157.c
@@ -277,7 +277,7 @@ err:
return ret;
 }
 
-static const struct dvb_tuner_ops si2157_tuner_ops = {
+static const struct dvb_tuner_ops si2157_ops = {
.info = {
.name   = Silicon Labs Si2157/Si2158,
.frequency_min  = 11000,
@@ -317,7 +317,7 @@ static int si2157_probe(struct i2c_client *client,
goto err;
 
fe-tuner_priv = s;
-   memcpy(fe-ops.tuner_ops, si2157_tuner_ops,
+   memcpy(fe-ops.tuner_ops, si2157_ops,
sizeof(struct dvb_tuner_ops));
 
i2c_set_clientdata(client, s);
-- 
1.9.1

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


[PATCH 0/6] [0b48:3014] TechnoTrend TVStick CT2-4400

2014-07-13 Thread Olli Salonen
TechnoTrend TVStick CT2-4400 is a USB 2.0 DVB C/T/T2 tuner with the
following components.

USB bridge: Cypress FX2
Demodulator: Silicon Labs Si2168-A30
Tuner: Silicon Labs Si2158-A20

Both the demodulator and the tuner need a firmware. These can be
extracted from TT drivers.

Download: http://www.tt-downloads.de/bda-treiber_4.2.0.0.zip

Extract firmware from file ttTVStick4400_64.sys in the zip (MD5 sum below):
0276023ce027bab05c2e7053033e2182  ttTVStick4400_64.sys

dd if=ttTVStick4400_64.sys ibs=1 skip=211216 count=17576 
of=dvb-demod-si2168-30-01.fw
dd if=ttTVStick4400_64.sys ibs=1 skip=200816 count=3944 
of=dvb-tuner-si2158-20-01.fw

Olli Salonen (6):
  si2168: Small typo fix (SI2157 - SI2168)
  si2168: Add handling for different chip revisions and firmwares
  si2157: Move chip initialization to si2157_init
  si2157: Add support for Si2158 chip
  si2157: Set delivery system and bandwidth before tuning
  cxusb: TechnoTrend CT2-4400 USB DVB-T2/C tuner support

 drivers/media/dvb-core/dvb-usb-ids.h  |   1 +
 drivers/media/dvb-frontends/si2168.c  |  34 +-
 drivers/media/dvb-frontends/si2168_priv.h |   8 +-
 drivers/media/tuners/si2157.c | 161 +++--
 drivers/media/tuners/si2157.h |   2 +-
 drivers/media/tuners/si2157_priv.h|   5 +-
 drivers/media/usb/dvb-usb/Kconfig |   3 +
 drivers/media/usb/dvb-usb/cxusb.c | 191 +-
 drivers/media/usb/dvb-usb/cxusb.h |   2 +
 9 files changed, 357 insertions(+), 50 deletions(-)

-- 
1.9.1

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


[PATCH 2/6] si2168: Add handling for different chip revisions and firmwares

2014-07-13 Thread Olli Salonen
Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-frontends/si2168.c  | 34 ++-
 drivers/media/dvb-frontends/si2168_priv.h |  4 +++-
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2168.c 
b/drivers/media/dvb-frontends/si2168.c
index bae7771..268fce3 100644
--- a/drivers/media/dvb-frontends/si2168.c
+++ b/drivers/media/dvb-frontends/si2168.c
@@ -333,7 +333,7 @@ static int si2168_init(struct dvb_frontend *fe)
struct si2168 *s = fe-demodulator_priv;
int ret, len, remaining;
const struct firmware *fw = NULL;
-   u8 *fw_file = SI2168_FIRMWARE;
+   u8 *fw_file;
const unsigned int i2c_wr_max = 8;
struct si2168_cmd cmd;
 
@@ -353,6 +353,7 @@ static int si2168_init(struct dvb_frontend *fe)
if (ret)
goto err;
 
+   /* query chip revision */
memcpy(cmd.args, \x02, 1);
cmd.wlen = 1;
cmd.rlen = 13;
@@ -360,6 +361,20 @@ static int si2168_init(struct dvb_frontend *fe)
if (ret)
goto err;
 
+   if (((cmd.args[1]  0x0f) == 2)  (cmd.args[3] == '4') 
+   (cmd.args[4] == '0'))
+   fw_file = SI2168_B40_FIRMWARE;
+   else if (((cmd.args[1]  0x0f) == 1)  (cmd.args[3] == '3') 
+   (cmd.args[4] == '0'))
+   fw_file = SI2168_A30_FIRMWARE;
+   else {
+   dev_err(s-client-dev,
+   %s: no firmware file for Si2168-%c%c 
defined\n,
+   KBUILD_MODNAME, cmd.args[3], cmd.args[4]);
+   ret = -EINVAL;
+   goto err;
+   }
+
/* cold state - try to download firmware */
dev_info(s-client-dev, %s: found a '%s' in cold state\n,
KBUILD_MODNAME, si2168_ops.info.name);
@@ -367,9 +382,18 @@ static int si2168_init(struct dvb_frontend *fe)
/* request the firmware, this will block and timeout */
ret = request_firmware(fw, fw_file, s-client-dev);
if (ret) {
-   dev_err(s-client-dev, %s: firmare file '%s' not found\n,
-   KBUILD_MODNAME, fw_file);
-   goto err;
+   /* fallback mechanism to handle old name for
+  SI2168_B40_FIRMWARE */
+   if (((cmd.args[1]  0x0f) == 2)  (cmd.args[3] == '4') 
+   (cmd.args[4] == '0')) {
+   fw_file = SI2168_B40_FIRMWARE_FALLBACK;
+   ret = request_firmware(fw, fw_file, s-client-dev);
+   }
+   if (ret) {
+   dev_err(s-client-dev, %s: firmware file '%s' not 
found\n,
+   KBUILD_MODNAME, fw_file);
+   goto err;
+   }
}
 
dev_info(s-client-dev, %s: downloading firmware from file '%s'\n,
@@ -629,4 +653,4 @@ module_i2c_driver(si2168_driver);
 MODULE_AUTHOR(Antti Palosaari cr...@iki.fi);
 MODULE_DESCRIPTION(Silicon Labs Si2168 DVB-T/T2/C demodulator driver);
 MODULE_LICENSE(GPL);
-MODULE_FIRMWARE(SI2168_FIRMWARE);
+MODULE_FIRMWARE(SI2168_B40_FIRMWARE);
diff --git a/drivers/media/dvb-frontends/si2168_priv.h 
b/drivers/media/dvb-frontends/si2168_priv.h
index 97f9d87..bebb68a 100644
--- a/drivers/media/dvb-frontends/si2168_priv.h
+++ b/drivers/media/dvb-frontends/si2168_priv.h
@@ -22,7 +22,9 @@
 #include linux/firmware.h
 #include linux/i2c-mux.h
 
-#define SI2168_FIRMWARE dvb-demod-si2168-02.fw
+#define SI2168_A30_FIRMWARE dvb-demod-si2168-a30-01.fw
+#define SI2168_B40_FIRMWARE dvb-demod-si2168-b40-01.fw
+#define SI2168_B40_FIRMWARE_FALLBACK dvb-demod-si2168-02.fw
 
 /* state struct */
 struct si2168 {
-- 
1.9.1

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


[PATCH 1/6] si2168: Small typo fix (SI2157 - SI2168)

2014-07-13 Thread Olli Salonen
Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-frontends/si2168_priv.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2168_priv.h 
b/drivers/media/dvb-frontends/si2168_priv.h
index 53f7f06..97f9d87 100644
--- a/drivers/media/dvb-frontends/si2168_priv.h
+++ b/drivers/media/dvb-frontends/si2168_priv.h
@@ -36,9 +36,9 @@ struct si2168 {
 };
 
 /* firmare command struct */
-#define SI2157_ARGLEN  30
+#define SI2168_ARGLEN  30
 struct si2168_cmd {
-   u8 args[SI2157_ARGLEN];
+   u8 args[SI2168_ARGLEN];
unsigned wlen;
unsigned rlen;
 };
-- 
1.9.1

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


[PATCH 4/6] si2157: Add support for Si2158 chip

2014-07-13 Thread Olli Salonen
Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/tuners/si2157.c  | 73 +++---
 drivers/media/tuners/si2157.h  |  2 +-
 drivers/media/tuners/si2157_priv.h |  5 ++-
 3 files changed, 73 insertions(+), 7 deletions(-)

diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
index a92570f9..58c5ef5 100644
--- a/drivers/media/tuners/si2157.c
+++ b/drivers/media/tuners/si2157.c
@@ -1,5 +1,5 @@
 /*
- * Silicon Labs Si2157 silicon tuner driver
+ * Silicon Labs Si2157/2158 silicon tuner driver
  *
  * Copyright (C) 2014 Antti Palosaari cr...@iki.fi
  *
@@ -16,6 +16,8 @@
 
 #include si2157_priv.h
 
+static const struct dvb_tuner_ops si2157_ops;
+
 /* execute firmware command */
 static int si2157_cmd_execute(struct si2157 *s, struct si2157_cmd *cmd)
 {
@@ -80,8 +82,11 @@ err:
 static int si2157_init(struct dvb_frontend *fe)
 {
struct si2157 *s = fe-tuner_priv;
-   int ret;
+   int ret, remaining;
struct si2157_cmd cmd;
+   u8 chip, len = 0;
+   const struct firmware *fw = NULL;
+   u8 *fw_file;
 
dev_dbg(s-client-dev, %s:\n, __func__);
 
@@ -101,6 +106,64 @@ static int si2157_init(struct dvb_frontend *fe)
if (ret)
goto err;
 
+   chip = cmd.args[2]; /* 57 for Si2157, 58 for Si2158 */
+
+   /* Si2158 requires firmware download */
+   if (chip == 58) {
+   if (((cmd.args[1]  0x0f) == 1)  (cmd.args[3] == '2') 
+   (cmd.args[4] == '0'))
+   fw_file = SI2158_A20_FIRMWARE;
+   else {
+   dev_err(s-client-dev,
+   %s: no firmware file for Si%d-%c%c 
defined\n,
+   KBUILD_MODNAME, chip, cmd.args[3], 
cmd.args[4]);
+   ret = -EINVAL;
+   goto err;
+   }
+
+   /* cold state - try to download firmware */
+   dev_info(s-client-dev, %s: found a '%s' in cold state\n,
+   KBUILD_MODNAME, si2157_ops.info.name);
+
+   /* request the firmware, this will block and timeout */
+   ret = request_firmware(fw, fw_file, s-client-dev);
+   if (ret) {
+   dev_err(s-client-dev, %s: firmware file '%s' not 
found\n,
+   KBUILD_MODNAME, fw_file);
+   goto err;
+   }
+
+   dev_info(s-client-dev, %s: downloading firmware from file 
'%s'\n,
+   KBUILD_MODNAME, fw_file);
+
+   /* firmware should be n chunks of 17 bytes */
+   if (fw-size % 17 != 0) {
+   dev_err(s-client-dev, %s: firmware file '%s' is 
invalid\n,
+   KBUILD_MODNAME, fw_file);
+   ret = -EINVAL;
+   goto err;
+   }
+
+   for (remaining = fw-size; remaining  0; remaining -= 17) {
+   memcpy(len, fw-data[fw-size - remaining], 1);
+   memcpy(cmd.args, fw-data[(fw-size - remaining) + 1],
+   len);
+   cmd.wlen = len;
+   cmd.rlen = 1;
+   ret = si2157_cmd_execute(s, cmd);
+   if (ret) {
+   dev_err(s-client-dev,
+   %s: firmware download 
failed=%d\n,
+   KBUILD_MODNAME, ret);
+   goto err;
+   }
+   }
+
+   release_firmware(fw);
+   fw = NULL;
+
+   }
+
/* reboot the tuner with new firmware? */
memcpy(cmd.args, \x01\x01, 2);
cmd.wlen = 2;
@@ -177,7 +240,7 @@ err:
 
 static const struct dvb_tuner_ops si2157_tuner_ops = {
.info = {
-   .name   = Silicon Labs Si2157,
+   .name   = Silicon Labs Si2157/Si2158,
.frequency_min  = 11000,
.frequency_max  = 86200,
},
@@ -221,7 +284,7 @@ static int si2157_probe(struct i2c_client *client,
i2c_set_clientdata(client, s);
 
dev_info(s-client-dev,
-   %s: Silicon Labs Si2157 successfully attached\n,
+   %s: Silicon Labs Si2157/Si2158 successfully 
attached\n,
KBUILD_MODNAME);
return 0;
 err:
@@ -263,6 +326,6 @@ static struct i2c_driver si2157_driver = {
 
 module_i2c_driver(si2157_driver);
 
-MODULE_DESCRIPTION(Silicon Labs Si2157 silicon tuner driver);
+MODULE_DESCRIPTION(Silicon Labs Si2157/Si2158 silicon tuner driver);
 MODULE_AUTHOR(Antti Palosaari cr...@iki.fi);
 MODULE_LICENSE(GPL);
diff --git a/drivers/media/tuners/si2157.h b/drivers/media/tuners/si2157.h
index f469a09

[PATCH 3/6] si2157: Move chip initialization to si2157_init

2014-07-13 Thread Olli Salonen
Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/tuners/si2157.c | 71 ++-
 1 file changed, 30 insertions(+), 41 deletions(-)

diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
index a4908ee..a92570f9 100644
--- a/drivers/media/tuners/si2157.c
+++ b/drivers/media/tuners/si2157.c
@@ -80,12 +80,41 @@ err:
 static int si2157_init(struct dvb_frontend *fe)
 {
struct si2157 *s = fe-tuner_priv;
+   int ret;
+   struct si2157_cmd cmd;
 
dev_dbg(s-client-dev, %s:\n, __func__);
 
+   /* configure? */
+   memcpy(cmd.args, 
\xc0\x00\x0c\x00\x00\x01\x01\x01\x01\x01\x01\x02\x00\x00\x01, 15);
+   cmd.wlen = 15;
+   cmd.rlen = 1;
+   ret = si2157_cmd_execute(s, cmd);
+   if (ret)
+   goto err;
+
+   /* query chip revision */
+   memcpy(cmd.args, \x02, 1);
+   cmd.wlen = 1;
+   cmd.rlen = 13;
+   ret = si2157_cmd_execute(s, cmd);
+   if (ret)
+   goto err;
+
+   /* reboot the tuner with new firmware? */
+   memcpy(cmd.args, \x01\x01, 2);
+   cmd.wlen = 2;
+   cmd.rlen = 1;
+   ret = si2157_cmd_execute(s, cmd);
+   if (ret)
+   goto err;
+
s-active = true;
 
return 0;
+err:
+   dev_dbg(s-client-dev, %s: failed=%d\n, __func__, ret);
+   return ret;
 }
 
 static int si2157_sleep(struct dvb_frontend *fe)
@@ -128,48 +157,8 @@ static int si2157_set_params(struct dvb_frontend *fe)
goto err;
}
 
-   /* configure? */
-   cmd.args[0] = 0xc0;
-   cmd.args[1] = 0x00;
-   cmd.args[2] = 0x0c;
-   cmd.args[3] = 0x00;
-   cmd.args[4] = 0x00;
-   cmd.args[5] = 0x01;
-   cmd.args[6] = 0x01;
-   cmd.args[7] = 0x01;
-   cmd.args[8] = 0x01;
-   cmd.args[9] = 0x01;
-   cmd.args[10] = 0x01;
-   cmd.args[11] = 0x02;
-   cmd.args[12] = 0x00;
-   cmd.args[13] = 0x00;
-   cmd.args[14] = 0x01;
-   cmd.wlen = 15;
-   cmd.rlen = 1;
-   ret = si2157_cmd_execute(s, cmd);
-   if (ret)
-   goto err;
-
-   cmd.args[0] = 0x02;
-   cmd.wlen = 1;
-   cmd.rlen = 13;
-   ret = si2157_cmd_execute(s, cmd);
-   if (ret)
-   goto err;
-
-   cmd.args[0] = 0x01;
-   cmd.args[1] = 0x01;
-   cmd.wlen = 2;
-   cmd.rlen = 1;
-   ret = si2157_cmd_execute(s, cmd);
-   if (ret)
-   goto err;
-
/* set frequency */
-   cmd.args[0] = 0x41;
-   cmd.args[1] = 0x00;
-   cmd.args[2] = 0x00;
-   cmd.args[3] = 0x00;
+   memcpy(cmd.args, \x41\x00\x00\x00\x00\x00\x00\x00, 8);
cmd.args[4] = (c-frequency   0)  0xff;
cmd.args[5] = (c-frequency   8)  0xff;
cmd.args[6] = (c-frequency  16)  0xff;
-- 
1.9.1

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


[PATCH 5/6] si2157: Set delivery system and bandwidth before tuning

2014-07-13 Thread Olli Salonen
Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/tuners/si2157.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
index 58c5ef5..b656f9b 100644
--- a/drivers/media/tuners/si2157.c
+++ b/drivers/media/tuners/si2157.c
@@ -209,6 +209,7 @@ static int si2157_set_params(struct dvb_frontend *fe)
struct dtv_frontend_properties *c = fe-dtv_property_cache;
int ret;
struct si2157_cmd cmd;
+   u8 bandwidth, delivery_system;
 
dev_dbg(s-client-dev,
%s: delivery_system=%d frequency=%u bandwidth_hz=%u\n,
@@ -220,6 +221,36 @@ static int si2157_set_params(struct dvb_frontend *fe)
goto err;
}
 
+   if (c-bandwidth_hz = 600)
+   bandwidth = 0x06;
+   else if (c-bandwidth_hz = 700)
+   bandwidth = 0x07;
+   else if (c-bandwidth_hz = 800)
+   bandwidth = 0x08;
+   else
+   bandwidth = 0x0f;
+
+   switch (c-delivery_system) {
+   case SYS_DVBT:
+   case SYS_DVBT2: /* it seems DVB-T and DVB-T2 both are 0x20 here */
+   delivery_system = 0x20;
+   break;
+   case SYS_DVBC_ANNEX_A:
+   delivery_system = 0x30;
+   break;
+   default:
+   ret = -EINVAL;
+   goto err;
+   }
+
+   memcpy(cmd.args, \x14\x00\x03\x07\x00\x00, 6);
+   cmd.args[4] = delivery_system | bandwidth;
+   cmd.wlen = 6;
+   cmd.rlen = 1;
+   ret = si2157_cmd_execute(s, cmd);
+   if (ret)
+   goto err;
+
/* set frequency */
memcpy(cmd.args, \x41\x00\x00\x00\x00\x00\x00\x00, 8);
cmd.args[4] = (c-frequency   0)  0xff;
-- 
1.9.1

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


[PATCH 6/6] cxusb: TechnoTrend CT2-4400 USB DVB-T2/C tuner support

2014-07-13 Thread Olli Salonen
Signed-off-by: Olli Salonen olli.salo...@iki.fi
---
 drivers/media/dvb-core/dvb-usb-ids.h |   1 +
 drivers/media/usb/dvb-usb/Kconfig|   3 +
 drivers/media/usb/dvb-usb/cxusb.c| 191 ++-
 drivers/media/usb/dvb-usb/cxusb.h|   2 +
 4 files changed, 196 insertions(+), 1 deletion(-)

diff --git a/drivers/media/dvb-core/dvb-usb-ids.h 
b/drivers/media/dvb-core/dvb-usb-ids.h
index 11d2bea..f8e3150 100644
--- a/drivers/media/dvb-core/dvb-usb-ids.h
+++ b/drivers/media/dvb-core/dvb-usb-ids.h
@@ -244,6 +244,7 @@
 #define USB_PID_TECHNOTREND_CONNECT_S2400   0x3006
 #define USB_PID_TECHNOTREND_CONNECT_S2400_8KEEPROM 0x3009
 #define USB_PID_TECHNOTREND_CONNECT_CT3650 0x300d
+#define USB_PID_TECHNOTREND_TVSTICK_CT2_4400   0x3014
 #define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY   0x005a
 #define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY_2 0x0081
 #define USB_PID_TERRATEC_CINERGY_HT_USB_XE 0x0058
diff --git a/drivers/media/usb/dvb-usb/Kconfig 
b/drivers/media/usb/dvb-usb/Kconfig
index c5d9566..10aef21 100644
--- a/drivers/media/usb/dvb-usb/Kconfig
+++ b/drivers/media/usb/dvb-usb/Kconfig
@@ -117,10 +117,12 @@ config DVB_USB_CXUSB
select DVB_TUNER_DIB0070 if MEDIA_SUBDRV_AUTOSELECT
select DVB_ATBM8830 if MEDIA_SUBDRV_AUTOSELECT
select DVB_LGS8GXX if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_SI2168 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_SIMPLE if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_XC2028 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_MXL5005S if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_MAX2165 if MEDIA_SUBDRV_AUTOSELECT
+   select MEDIA_TUNER_SI2157 if MEDIA_SUBDRV_AUTOSELECT
help
  Say Y here to support the Conexant USB2.0 hybrid reference design.
  Currently, only DVB and ATSC modes are supported, analog mode
@@ -128,6 +130,7 @@ config DVB_USB_CXUSB
 
  Medion MD95700 hybrid USB2.0 device.
  DViCO FusionHDTV (Bluebird) USB2.0 devices
+ TechnoTrend TVStick CT2-4400
 
 config DVB_USB_M920X
tristate Uli m920x DVB-T USB2.0 support
diff --git a/drivers/media/usb/dvb-usb/cxusb.c 
b/drivers/media/usb/dvb-usb/cxusb.c
index a1c641e..ad20c39 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -42,6 +42,8 @@
 #include dib0070.h
 #include lgs8gxx.h
 #include atbm8830.h
+#include si2168.h
+#include si2157.h
 
 /* Max transfer size done by I2C transfer functions */
 #define MAX_XFER_SIZE  64
@@ -144,6 +146,22 @@ static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device 
*d,
}
 }
 
+static int cxusb_tt_ct2_4400_gpio_tuner(struct dvb_usb_device *d, int onoff)
+{
+   u8 o[2], i;
+   int rc;
+
+   o[0] = 0x83;
+   o[1] = onoff;
+   rc = cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, i, 1);
+
+   if (rc) {
+   deb_info(gpio_write failed.\n);
+   return -EIO;
+   }
+   return 0;
+}
+
 /* I2C */
 static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  int num)
@@ -505,6 +523,30 @@ static int cxusb_d680_dmb_rc_query(struct dvb_usb_device 
*d, u32 *event,
return 0;
 }
 
+static int cxusb_tt_ct2_4400_rc_query(struct dvb_usb_device *d)
+{
+   u8 i[2];
+   int ret;
+   u32 cmd, keycode;
+   u8 rc5_cmd, rc5_addr, rc5_toggle;
+
+   ret = cxusb_ctrl_msg(d, 0x10, NULL, 0, i, 2);
+   if (ret)
+   return ret;
+
+   cmd = (i[0]  8) | i[1];
+
+   if (cmd != 0x) {
+   rc5_cmd = cmd  0x3F; /* bits 1-6 for command */
+   rc5_addr = (cmd  0x07C0)  6; /* bits 7-11 for address */
+   rc5_toggle = (cmd  0x0800)  11; /* bit 12 for toggle */
+   keycode = (rc5_addr  8) | rc5_cmd;
+   rc_keydown(d-rc_dev, keycode, rc5_toggle);
+   }
+
+   return 0;
+}
+
 static struct rc_map_table rc_map_dvico_mce_table[] = {
{ 0xfe02, KEY_TV },
{ 0xfe0e, KEY_MP3 },
@@ -1286,6 +1328,73 @@ static int cxusb_mygica_d689_frontend_attach(struct 
dvb_usb_adapter *adap)
return 0;
 }
 
+static int cxusb_tt_ct2_4400_attach(struct dvb_usb_adapter *adap)
+{
+   struct dvb_usb_device *d = adap-dev;
+   struct cxusb_state *st = d-priv;
+   struct i2c_adapter *adapter;
+   struct i2c_client *client_demod;
+   struct i2c_client *client_tuner;
+   struct i2c_board_info info;
+   struct si2168_config si2168_config;
+   struct si2157_config si2157_config;
+
+   /* reset the tuner */
+   if (cxusb_tt_ct2_4400_gpio_tuner(d, 0)  0) {
+   err(clear tuner gpio failed);
+   return -EIO;
+   }
+   msleep(100);
+   if (cxusb_tt_ct2_4400_gpio_tuner(d, 1)  0) {
+   err(set tuner gpio failed);
+   return -EIO;
+   }
+   msleep(100);
+
+   /* attach frontend */
+   si2168_config.i2c_adapter

<    1   2   3