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

2014-07-14 Thread Antti Palosaari
From: Olli Salonen olli.salo...@iki.fi

USB ID 0b48:3014.

USB interface: Cypress CY7C68013A-56LTXC
Demodulator: Silicon Labs Si2168-30
Tuner: Silicon Labs Si2158-20

Cc: Michael Krufky mkru...@linuxtv.org
Signed-off-by: Olli Salonen olli.salo...@iki.fi
Reviewed-by: Antti Palosaari cr...@iki.fi
Signed-off-by: Antti Palosaari cr...@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 

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

2014-07-14 Thread Antti Palosaari

On 07/14/2014 08:19 PM, Michael Ira Krufky wrote:

Reviewed-by: Michael Ira Krufky mkru...@linuxtv.org

I assume you'll merge this via your own branch?

...I've been traveling on  off for the past few months, but I am back
now - I'll be getting thru my pending patch queue right away


Yes, because all those remaining patches were si2168 and si2157 drivers 
(demod and tuner). I will add you Reviewed-by tag and update PULL 
request. Thanks!


regards
Antti



Cheers,

Mike

On Mon, Jul 14, 2014 at 1:08 PM, Antti Palosaari cr...@iki.fi wrote:

From: Olli Salonen olli.salo...@iki.fi

USB ID 0b48:3014.

USB interface: Cypress CY7C68013A-56LTXC
Demodulator: Silicon Labs Si2168-30
Tuner: Silicon Labs Si2158-20

Cc: Michael Krufky mkru...@linuxtv.org
Signed-off-by: Olli Salonen olli.salo...@iki.fi
Reviewed-by: Antti Palosaari cr...@iki.fi
Signed-off-by: Antti Palosaari cr...@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