[PATCH v3 1/2] si2168: Set TS clock mode and frequency

2018-05-12 Thread Thomas Hollstegge
Some devices require a higher TS clock frequency to demodulate some
muxes. This adds two optional parameters to control the TS clock
frequency mode as well as the frequency.

Signed-off-by: Thomas Hollstegge <thomas.hollste...@gmail.com>
---
 drivers/media/dvb-frontends/si2168.c  | 20 +++-
 drivers/media/dvb-frontends/si2168.h  |  8 
 drivers/media/dvb-frontends/si2168_priv.h |  2 ++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/si2168.c 
b/drivers/media/dvb-frontends/si2168.c
index 324493e..b05e677 100644
--- a/drivers/media/dvb-frontends/si2168.c
+++ b/drivers/media/dvb-frontends/si2168.c
@@ -92,13 +92,15 @@ static int si2168_ts_bus_ctrl(struct dvb_frontend *fe, int 
acquire)
dev_dbg(>dev, "%s acquire: %d\n", __func__, acquire);
 
/* set TS_MODE property */
-   memcpy(cmd.args, "\x14\x00\x01\x10\x10\x00", 6);
+   memcpy(cmd.args, "\x14\x00\x01\x10\x00\x00", 6);
if (acquire)
cmd.args[4] |= dev->ts_mode;
else
cmd.args[4] |= SI2168_TS_TRISTATE;
if (dev->ts_clock_gapped)
cmd.args[4] |= 0x40;
+   cmd.args[4] |= (dev->ts_clock_mode & 0x03) << 4;
+
cmd.wlen = 6;
cmd.rlen = 4;
ret = si2168_cmd_execute(client, );
@@ -398,6 +400,18 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
if (ret)
goto err;
 
+   /* set TS frequency */
+   if (dev->ts_clock_freq) {
+   memcpy(cmd.args, "\x14\x00\x0d\x10", 4);
+   cmd.args[4] = ((dev->ts_clock_freq / 1) >> 0) & 0xff;
+   cmd.args[5] = ((dev->ts_clock_freq / 1) >> 8) & 0xff;
+   cmd.wlen = 6;
+   cmd.rlen = 4;
+   ret = si2168_cmd_execute(client, );
+   if (ret)
+   goto err;
+   }
+
memcpy(cmd.args, "\x14\x00\x08\x10\xd7\x05", 6);
cmd.args[5] |= dev->ts_clock_inv ? 0x00 : 0x10;
cmd.wlen = 6;
@@ -806,6 +820,10 @@ static int si2168_probe(struct i2c_client *client,
dev->ts_mode = config->ts_mode;
dev->ts_clock_inv = config->ts_clock_inv;
dev->ts_clock_gapped = config->ts_clock_gapped;
+   dev->ts_clock_mode = config->ts_clock_mode;
+   if (dev->ts_clock_mode == 0)
+   dev->ts_clock_mode = SI2168_TS_CLOCK_MODE_AUTO_ADAPT;
+   dev->ts_clock_freq = config->ts_clock_freq;
dev->spectral_inversion = config->spectral_inversion;
 
dev_info(>dev, "Silicon Labs Si2168-%c%d%d successfully 
identified\n",
diff --git a/drivers/media/dvb-frontends/si2168.h 
b/drivers/media/dvb-frontends/si2168.h
index d519edd..3f52ee8 100644
--- a/drivers/media/dvb-frontends/si2168.h
+++ b/drivers/media/dvb-frontends/si2168.h
@@ -47,6 +47,14 @@ struct si2168_config {
/* TS clock gapped */
bool ts_clock_gapped;
 
+   /* TS clock mode */
+#define SI2168_TS_CLOCK_MODE_AUTO_ADAPT0x01
+#define SI2168_TS_CLOCK_MODE_MANUAL0x02
+   u8 ts_clock_mode;
+
+   /* TS clock frequency (for manual mode) */
+   u32 ts_clock_freq;
+
/* Inverted spectrum */
bool spectral_inversion;
 };
diff --git a/drivers/media/dvb-frontends/si2168_priv.h 
b/drivers/media/dvb-frontends/si2168_priv.h
index 2d362e1..8173d6c 100644
--- a/drivers/media/dvb-frontends/si2168_priv.h
+++ b/drivers/media/dvb-frontends/si2168_priv.h
@@ -48,6 +48,8 @@ struct si2168_dev {
u8 ts_mode;
bool ts_clock_inv;
bool ts_clock_gapped;
+   u8 ts_clock_mode;
+   u32 ts_clock_freq;
bool spectral_inversion;
 };
 
-- 
2.7.4



[PATCH v3 2/2] dvbsky: Add support for MyGica T230C v2

2018-05-12 Thread Thomas Hollstegge
Support for newer revisions of the MyGica T230C, shipping with a
different USB pid. Although sometimes referred to as T230C2, the device
is sold under its original name T230C.

Besides a slightly different PCB layout and some different minor
components, it utilizes the same bridge, demodulator and tuner as the
older revision. However, it requires a fixed TS clock frequency of 10
MHz to tune to some muxes.

Tested with various DVB-T2 HEVC and DVB-C channels.

Signed-off-by: Thomas Hollstegge <thomas.hollste...@gmail.com>
Cc: Stefan Brüns <stefan.bru...@rwth-aachen.de>
---
 drivers/media/usb/dvb-usb-v2/dvbsky.c | 90 +++
 include/media/dvb-usb-ids.h   |  1 +
 2 files changed, 91 insertions(+)

diff --git a/drivers/media/usb/dvb-usb-v2/dvbsky.c 
b/drivers/media/usb/dvb-usb-v2/dvbsky.c
index 1aa88d9..a6d3c08 100644
--- a/drivers/media/usb/dvb-usb-v2/dvbsky.c
+++ b/drivers/media/usb/dvb-usb-v2/dvbsky.c
@@ -581,6 +581,66 @@ static int dvbsky_mygica_t230c_attach(struct 
dvb_usb_adapter *adap)
return 0;
 }
 
+static int dvbsky_mygica_t230c_v2_attach(struct dvb_usb_adapter *adap)
+{
+   struct dvbsky_state *state = adap_to_priv(adap);
+   struct dvb_usb_device *d = adap_to_d(adap);
+   struct i2c_adapter *i2c_adapter;
+   struct i2c_client *client_demod, *client_tuner;
+   struct i2c_board_info info;
+   struct si2168_config si2168_config;
+   struct si2157_config si2157_config;
+
+   /* attach demod */
+   memset(_config, 0, sizeof(si2168_config));
+   si2168_config.i2c_adapter = _adapter;
+   si2168_config.fe = >fe[0];
+   si2168_config.ts_mode = SI2168_TS_PARALLEL;
+   si2168_config.ts_clock_inv = 1;
+   si2168_config.ts_clock_mode = SI2168_TS_CLOCK_MODE_MANUAL;
+   si2168_config.ts_clock_freq = 1000;
+   memset(, 0, sizeof(struct i2c_board_info));
+   strlcpy(info.type, "si2168", sizeof(info.type));
+   info.addr = 0x64;
+   info.platform_data = _config;
+
+   request_module("si2168");
+   client_demod = i2c_new_device(>i2c_adap, );
+   if (!client_demod || !client_demod->dev.driver)
+   goto fail_demod_device;
+   if (!try_module_get(client_demod->dev.driver->owner))
+   goto fail_demod_module;
+
+   /* attach tuner */
+   memset(_config, 0, sizeof(si2157_config));
+   si2157_config.fe = adap->fe[0];
+   si2157_config.if_port = 0;
+   memset(, 0, sizeof(struct i2c_board_info));
+   strlcpy(info.type, "si2141", sizeof(info.type));
+   info.addr = 0x60;
+   info.platform_data = _config;
+
+   request_module("si2157");
+   client_tuner = i2c_new_device(i2c_adapter, );
+   if (!client_tuner || !client_tuner->dev.driver)
+   goto fail_tuner_device;
+   if (!try_module_get(client_tuner->dev.driver->owner))
+   goto fail_tuner_module;
+
+   state->i2c_client_demod = client_demod;
+   state->i2c_client_tuner = client_tuner;
+   return 0;
+
+fail_tuner_module:
+   i2c_unregister_device(client_tuner);
+fail_tuner_device:
+   module_put(client_demod->dev.driver->owner);
+fail_demod_module:
+   i2c_unregister_device(client_demod);
+fail_demod_device:
+   return -ENODEV;
+}
+
 
 static int dvbsky_identify_state(struct dvb_usb_device *d, const char **name)
 {
@@ -758,6 +818,33 @@ static struct dvb_usb_device_properties mygica_t230c_props 
= {
}
 };
 
+static struct dvb_usb_device_properties mygica_t230c_v2_props = {
+   .driver_name = KBUILD_MODNAME,
+   .owner = THIS_MODULE,
+   .adapter_nr = adapter_nr,
+   .size_of_priv = sizeof(struct dvbsky_state),
+
+   .generic_bulk_ctrl_endpoint = 0x01,
+   .generic_bulk_ctrl_endpoint_response = 0x81,
+   .generic_bulk_ctrl_delay = DVBSKY_MSG_DELAY,
+
+   .i2c_algo = _i2c_algo,
+   .frontend_attach  = dvbsky_mygica_t230c_v2_attach,
+   .init = dvbsky_init,
+   .get_rc_config= dvbsky_get_rc_config,
+   .streaming_ctrl   = dvbsky_streaming_ctrl,
+   .identify_state   = dvbsky_identify_state,
+   .exit = dvbsky_exit,
+
+   .num_adapters = 1,
+   .adapter = {
+   {
+   .stream = DVB_USB_STREAM_BULK(0x82, 8, 4096),
+   }
+   }
+};
+
+
 static const struct usb_device_id dvbsky_id_table[] = {
{ DVB_USB_DEVICE(0x0572, 0x6831,
_s960_props, "DVBSky S960/S860", RC_MAP_DVBSKY) },
@@ -793,6 +880,9 @@ static const struct usb_device_id dvbsky_id_table[] = {
{ DVB_USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_T230C,
_t230c_props, "MyGica Mini DVB-T2 USB Stick T230C",
RC_MAP_TOTAL_MEDIA_IN_HAND_02) },
+   { DVB_USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_T230C_V2,
+   

[PATCH v3 0/2] media: dvbsky: Add support for MyGica T230C v2

2018-05-12 Thread Thomas Hollstegge
Add support for newer revisions of the USB DVB-C/DVB-T/DVB-T2 stick MyGica
T230C, sometimes referred to as MyGica T230C2. The device needs a fixed TS
clock frequency of 10MHz to be able to demod some channels. This is done by
adding two new optional configuration options for the Si2168 demod
(ts_clock_mode and ts_clock_freq).

Although there is a third TS clock mode available (AUTO_FIXED = 0x00), I chose
not to implement it yet as I don't have a device that uses this mode.

Tested with all available DVB-T2 HEVC and DVB-C muxes in my region (Germany).

Patch v3 notes: Fixed issue with other Si2168 devices. Tested with MyGica T230,
T230C and T230C v2.

Thomas Hollstegge (2):
  si2168: Set TS clock mode and frequency
  dvbsky: Add support for MyGica T230C v2

 drivers/media/dvb-frontends/si2168.c  | 20 ++-
 drivers/media/dvb-frontends/si2168.h  |  8 +++
 drivers/media/dvb-frontends/si2168_priv.h |  2 +
 drivers/media/usb/dvb-usb-v2/dvbsky.c | 90 +++
 include/media/dvb-usb-ids.h   |  1 +
 5 files changed, 120 insertions(+), 1 deletion(-)

-- 
2.7.4



[PATCH v2 1/2] si2168: Set TS clock mode and frequency

2018-05-06 Thread Thomas Hollstegge
Some devices require a higher TS clock frequency to demodulate some
muxes. This adds two optional parameters to control the TS clock
frequency mode as well as the frequency.

Signed-off-by: Thomas Hollstegge <thomas.hollste...@gmail.com>
---
 drivers/media/dvb-frontends/si2168.c  | 20 +++-
 drivers/media/dvb-frontends/si2168.h  |  8 
 drivers/media/dvb-frontends/si2168_priv.h |  2 ++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/si2168.c 
b/drivers/media/dvb-frontends/si2168.c
index 324493e..80740db 100644
--- a/drivers/media/dvb-frontends/si2168.c
+++ b/drivers/media/dvb-frontends/si2168.c
@@ -92,13 +92,15 @@ static int si2168_ts_bus_ctrl(struct dvb_frontend *fe, int 
acquire)
dev_dbg(>dev, "%s acquire: %d\n", __func__, acquire);
 
/* set TS_MODE property */
-   memcpy(cmd.args, "\x14\x00\x01\x10\x10\x00", 6);
+   memcpy(cmd.args, "\x14\x00\x01\x10\x00\x00", 6);
if (acquire)
cmd.args[4] |= dev->ts_mode;
else
cmd.args[4] |= SI2168_TS_TRISTATE;
if (dev->ts_clock_gapped)
cmd.args[4] |= 0x40;
+   cmd.args[4] |= (dev->ts_clock_mode & 0x03) << 4;
+
cmd.wlen = 6;
cmd.rlen = 4;
ret = si2168_cmd_execute(client, );
@@ -398,6 +400,18 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
if (ret)
goto err;
 
+   /* set TS frequency */
+   if (dev->ts_clock_freq) {
+   memcpy(cmd.args, "\x14\x00\x0d\x10", 4);
+   cmd.args[4] = ((dev->ts_clock_freq / 1) >> 0) & 0xff;
+   cmd.args[5] = ((dev->ts_clock_freq / 1) >> 8) & 0xff;
+   cmd.wlen = 6;
+   cmd.rlen = 4;
+   ret = si2168_cmd_execute(client, );
+   if (ret)
+   goto err;
+   }
+
memcpy(cmd.args, "\x14\x00\x08\x10\xd7\x05", 6);
cmd.args[5] |= dev->ts_clock_inv ? 0x00 : 0x10;
cmd.wlen = 6;
@@ -806,6 +820,10 @@ static int si2168_probe(struct i2c_client *client,
dev->ts_mode = config->ts_mode;
dev->ts_clock_inv = config->ts_clock_inv;
dev->ts_clock_gapped = config->ts_clock_gapped;
+   dev->ts_clock_mode = config->ts_clock_mode;
+   if (!dev->ts_clock_mode)
+   dev->ts_clock_mode = SI2168_TS_CLOCK_MODE_AUTO_ADAPT;
+   dev->ts_clock_freq = config->ts_clock_freq;
dev->spectral_inversion = config->spectral_inversion;
 
dev_info(>dev, "Silicon Labs Si2168-%c%d%d successfully 
identified\n",
diff --git a/drivers/media/dvb-frontends/si2168.h 
b/drivers/media/dvb-frontends/si2168.h
index d519edd..3f52ee8 100644
--- a/drivers/media/dvb-frontends/si2168.h
+++ b/drivers/media/dvb-frontends/si2168.h
@@ -47,6 +47,14 @@ struct si2168_config {
/* TS clock gapped */
bool ts_clock_gapped;
 
+   /* TS clock mode */
+#define SI2168_TS_CLOCK_MODE_AUTO_ADAPT0x01
+#define SI2168_TS_CLOCK_MODE_MANUAL0x02
+   u8 ts_clock_mode;
+
+   /* TS clock frequency (for manual mode) */
+   u32 ts_clock_freq;
+
/* Inverted spectrum */
bool spectral_inversion;
 };
diff --git a/drivers/media/dvb-frontends/si2168_priv.h 
b/drivers/media/dvb-frontends/si2168_priv.h
index 2d362e1..8173d6c 100644
--- a/drivers/media/dvb-frontends/si2168_priv.h
+++ b/drivers/media/dvb-frontends/si2168_priv.h
@@ -48,6 +48,8 @@ struct si2168_dev {
u8 ts_mode;
bool ts_clock_inv;
bool ts_clock_gapped;
+   u8 ts_clock_mode;
+   u32 ts_clock_freq;
bool spectral_inversion;
 };
 
-- 
2.7.4



[PATCH v2 2/2] dvbsky: Add support for MyGica T230C v2

2018-05-06 Thread Thomas Hollstegge
Support for newer revisions of the MyGica T230C, shipping with a
different USB pid. Although sometimes referred to as T230C2, the device
is sold under its original name T230C.

Besides a slightly different PCB layout and some different minor
components, it utilizes the same bridge, demodulator and tuner as the
older revision. However, it requires a fixed TS clock frequency of 10
MHz to tune to some muxes.

Tested with various DVB-T2 HEVC and DVB-C channels.

Signed-off-by: Thomas Hollstegge <thomas.hollste...@gmail.com>
Cc: Stefan Brüns <stefan.bru...@rwth-aachen.de>
---
 drivers/media/usb/dvb-usb-v2/dvbsky.c | 90 +++
 include/media/dvb-usb-ids.h   |  1 +
 2 files changed, 91 insertions(+)

diff --git a/drivers/media/usb/dvb-usb-v2/dvbsky.c 
b/drivers/media/usb/dvb-usb-v2/dvbsky.c
index e28bd88..4a4c6ae 100644
--- a/drivers/media/usb/dvb-usb-v2/dvbsky.c
+++ b/drivers/media/usb/dvb-usb-v2/dvbsky.c
@@ -583,6 +583,66 @@ static int dvbsky_mygica_t230c_attach(struct 
dvb_usb_adapter *adap)
return 0;
 }
 
+static int dvbsky_mygica_t230c_v2_attach(struct dvb_usb_adapter *adap)
+{
+   struct dvbsky_state *state = adap_to_priv(adap);
+   struct dvb_usb_device *d = adap_to_d(adap);
+   struct i2c_adapter *i2c_adapter;
+   struct i2c_client *client_demod, *client_tuner;
+   struct i2c_board_info info;
+   struct si2168_config si2168_config;
+   struct si2157_config si2157_config;
+
+   /* attach demod */
+   memset(_config, 0, sizeof(si2168_config));
+   si2168_config.i2c_adapter = _adapter;
+   si2168_config.fe = >fe[0];
+   si2168_config.ts_mode = SI2168_TS_PARALLEL;
+   si2168_config.ts_clock_inv = 1;
+   si2168_config.ts_clock_mode = SI2168_TS_CLOCK_MODE_MANUAL;
+   si2168_config.ts_clock_freq = 1000;
+   memset(, 0, sizeof(struct i2c_board_info));
+   strlcpy(info.type, "si2168", sizeof(info.type));
+   info.addr = 0x64;
+   info.platform_data = _config;
+
+   request_module("si2168");
+   client_demod = i2c_new_device(>i2c_adap, );
+   if (!client_demod || !client_demod->dev.driver)
+   goto fail_demod_device;
+   if (!try_module_get(client_demod->dev.driver->owner))
+   goto fail_demod_module;
+
+   /* attach tuner */
+   memset(_config, 0, sizeof(si2157_config));
+   si2157_config.fe = adap->fe[0];
+   si2157_config.if_port = 0;
+   memset(, 0, sizeof(struct i2c_board_info));
+   strlcpy(info.type, "si2141", sizeof(info.type));
+   info.addr = 0x60;
+   info.platform_data = _config;
+
+   request_module("si2157");
+   client_tuner = i2c_new_device(i2c_adapter, );
+   if (!client_tuner || !client_tuner->dev.driver)
+   goto fail_tuner_device;
+   if (!try_module_get(client_tuner->dev.driver->owner))
+   goto fail_tuner_module;
+
+   state->i2c_client_demod = client_demod;
+   state->i2c_client_tuner = client_tuner;
+   return 0;
+
+fail_tuner_module:
+   i2c_unregister_device(client_tuner);
+fail_tuner_device:
+   module_put(client_demod->dev.driver->owner);
+fail_demod_module:
+   i2c_unregister_device(client_demod);
+fail_demod_device:
+   return -ENODEV;
+}
+
 
 static int dvbsky_identify_state(struct dvb_usb_device *d, const char **name)
 {
@@ -762,6 +822,33 @@ static struct dvb_usb_device_properties mygica_t230c_props 
= {
}
 };
 
+static struct dvb_usb_device_properties mygica_t230c_v2_props = {
+   .driver_name = KBUILD_MODNAME,
+   .owner = THIS_MODULE,
+   .adapter_nr = adapter_nr,
+   .size_of_priv = sizeof(struct dvbsky_state),
+
+   .generic_bulk_ctrl_endpoint = 0x01,
+   .generic_bulk_ctrl_endpoint_response = 0x81,
+   .generic_bulk_ctrl_delay = DVBSKY_MSG_DELAY,
+
+   .i2c_algo = _i2c_algo,
+   .frontend_attach  = dvbsky_mygica_t230c_v2_attach,
+   .init = dvbsky_init,
+   .get_rc_config= dvbsky_get_rc_config,
+   .streaming_ctrl   = dvbsky_streaming_ctrl,
+   .identify_state   = dvbsky_identify_state,
+   .exit = dvbsky_exit,
+
+   .num_adapters = 1,
+   .adapter = {
+   {
+   .stream = DVB_USB_STREAM_BULK(0x82, 8, 4096),
+   }
+   }
+};
+
+
 static const struct usb_device_id dvbsky_id_table[] = {
{ DVB_USB_DEVICE(0x0572, 0x6831,
_s960_props, "DVBSky S960/S860", RC_MAP_DVBSKY) },
@@ -797,6 +884,9 @@ static const struct usb_device_id dvbsky_id_table[] = {
{ DVB_USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_T230C,
_t230c_props, "MyGica Mini DVB-T2 USB Stick T230C",
RC_MAP_TOTAL_MEDIA_IN_HAND_02) },
+   { DVB_USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_T230C_V2,
+   

[PATCH v2 0/2] media: dvbsky: Add support for MyGica T230C v2

2018-05-06 Thread Thomas Hollstegge
Add support for newer revisions of the USB DVB-C/DVB-T/DVB-T2 stick MyGica
T230C, sometimes referred to as MyGica T230C2. The device needs a fixed TS
clock frequency of 10MHz to be able to demod some channels. This is done by
adding two new optional configuration options for the Si2168 demod
(ts_clock_mode and ts_clock_freq).

Although there is a third TS clock mode available (AUTO_FIXED = 0x00), I chose
not to implement it yet as I don't have a device that uses this mode.

Tested with all available DVB-T2 HEVC and DVB-C muxes in my region (Germany).

Patch v2 notes: rebased against https://git.linuxtv.org/media_tree.git/

Thomas Hollstegge (2):
  si2168: Set TS clock mode and frequency
  dvbsky: Add support for MyGica T230C v2

 drivers/media/dvb-frontends/si2168.c  | 20 ++-
 drivers/media/dvb-frontends/si2168.h  |  8 +++
 drivers/media/dvb-frontends/si2168_priv.h |  2 +
 drivers/media/usb/dvb-usb-v2/dvbsky.c | 90 +++
 include/media/dvb-usb-ids.h   |  1 +
 5 files changed, 120 insertions(+), 1 deletion(-)

-- 
2.7.4



[PATCH 2/2] dvbsky: Add support for MyGica T230C v2

2018-05-05 Thread Thomas Hollstegge
Support for newer revisions of the MyGica T230C, shipping with a
different USB pid. Although sometimes referred to as T230C2, the device
is sold under its original name T230C.

Besides a slightly different PCB layout and some different minor
components, it utilizes the same bridge, demodulator and tuner as the
older revision. However, it requires a fixed TS clock frequency of 10
MHz to tune to some muxes.

Tested with various DVB-T2 HEVC and DVB-C channels.

Signed-off-by: Thomas Hollstegge <thomas.hollste...@gmail.com>
Cc: Stefan Brüns <stefan.bru...@rwth-aachen.de>
---
 drivers/media/usb/dvb-usb-v2/dvbsky.c | 90 +++
 include/media/dvb-usb-ids.h   |  1 +
 2 files changed, 91 insertions(+)

diff --git a/drivers/media/usb/dvb-usb-v2/dvbsky.c 
b/drivers/media/usb/dvb-usb-v2/dvbsky.c
index 43eb828..49db69f 100644
--- a/drivers/media/usb/dvb-usb-v2/dvbsky.c
+++ b/drivers/media/usb/dvb-usb-v2/dvbsky.c
@@ -719,6 +719,66 @@ static int dvbsky_mygica_t230c_attach(struct 
dvb_usb_adapter *adap)
return -ENODEV;
 }
 
+static int dvbsky_mygica_t230c_v2_attach(struct dvb_usb_adapter *adap)
+{
+   struct dvbsky_state *state = adap_to_priv(adap);
+   struct dvb_usb_device *d = adap_to_d(adap);
+   struct i2c_adapter *i2c_adapter;
+   struct i2c_client *client_demod, *client_tuner;
+   struct i2c_board_info info;
+   struct si2168_config si2168_config;
+   struct si2157_config si2157_config;
+
+   /* attach demod */
+   memset(_config, 0, sizeof(si2168_config));
+   si2168_config.i2c_adapter = _adapter;
+   si2168_config.fe = >fe[0];
+   si2168_config.ts_mode = SI2168_TS_PARALLEL;
+   si2168_config.ts_clock_inv = 1;
+   si2168_config.ts_clock_mode = SI2168_TS_CLOCK_MODE_MANUAL;
+   si2168_config.ts_clock_freq = 1000;
+   memset(, 0, sizeof(struct i2c_board_info));
+   strlcpy(info.type, "si2168", sizeof(info.type));
+   info.addr = 0x64;
+   info.platform_data = _config;
+
+   request_module("si2168");
+   client_demod = i2c_new_device(>i2c_adap, );
+   if (!client_demod || !client_demod->dev.driver)
+   goto fail_demod_device;
+   if (!try_module_get(client_demod->dev.driver->owner))
+   goto fail_demod_module;
+
+   /* attach tuner */
+   memset(_config, 0, sizeof(si2157_config));
+   si2157_config.fe = adap->fe[0];
+   si2157_config.if_port = 0;
+   memset(, 0, sizeof(struct i2c_board_info));
+   strlcpy(info.type, "si2141", sizeof(info.type));
+   info.addr = 0x60;
+   info.platform_data = _config;
+
+   request_module("si2157");
+   client_tuner = i2c_new_device(i2c_adapter, );
+   if (!client_tuner || !client_tuner->dev.driver)
+   goto fail_tuner_device;
+   if (!try_module_get(client_tuner->dev.driver->owner))
+   goto fail_tuner_module;
+
+   state->i2c_client_demod = client_demod;
+   state->i2c_client_tuner = client_tuner;
+   return 0;
+
+fail_tuner_module:
+   i2c_unregister_device(client_tuner);
+fail_tuner_device:
+   module_put(client_demod->dev.driver->owner);
+fail_demod_module:
+   i2c_unregister_device(client_demod);
+fail_demod_device:
+   return -ENODEV;
+}
+
 
 static int dvbsky_identify_state(struct dvb_usb_device *d, const char **name)
 {
@@ -911,6 +971,33 @@ static struct dvb_usb_device_properties mygica_t230c_props 
= {
}
 };
 
+static struct dvb_usb_device_properties mygica_t230c_v2_props = {
+   .driver_name = KBUILD_MODNAME,
+   .owner = THIS_MODULE,
+   .adapter_nr = adapter_nr,
+   .size_of_priv = sizeof(struct dvbsky_state),
+
+   .generic_bulk_ctrl_endpoint = 0x01,
+   .generic_bulk_ctrl_endpoint_response = 0x81,
+   .generic_bulk_ctrl_delay = DVBSKY_MSG_DELAY,
+
+   .i2c_algo = _i2c_algo,
+   .frontend_attach  = dvbsky_mygica_t230c_v2_attach,
+   .init = dvbsky_init,
+   .get_rc_config= dvbsky_get_rc_config,
+   .streaming_ctrl   = dvbsky_streaming_ctrl,
+   .identify_state   = dvbsky_identify_state,
+   .exit = dvbsky_exit,
+
+   .num_adapters = 1,
+   .adapter = {
+   {
+   .stream = DVB_USB_STREAM_BULK(0x82, 8, 4096),
+   }
+   }
+};
+
+
 static const struct usb_device_id dvbsky_id_table[] = {
{ DVB_USB_DEVICE(0x0572, 0x6831,
_s960_props, "DVBSky S960/S860", RC_MAP_DVBSKY) },
@@ -946,6 +1033,9 @@ static const struct usb_device_id dvbsky_id_table[] = {
{ DVB_USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_T230C,
_t230c_props, "MyGica Mini DVB-T2 USB Stick T230C",
RC_MAP_TOTAL_MEDIA_IN_HAND_02) },
+   { DVB_USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_T230C_V2,
+   

[PATCH 0/2] dvbsky: Add support for MyGica T230C v2

2018-05-05 Thread Thomas Hollstegge
Add support for newer revisions of the USB DVB-C/DVB-T/DVB-T2 stick MyGica
T230C, sometimes referred to as MyGica T230C2. The device needs a fixed TS
clock frequency of 10MHz to be able to demod some channels. This is done by
adding two new optional configuration options for the Si2168 demod
(ts_clock_mode and ts_clock_freq).

Although there is a third TS clock mode available (AUTO_FIXED = 0x00), I chose
not to implement it yet as I don't have a device that uses this mode.

Tested with all available DVB-T2 HEVC and DVB-C muxes in my region (Germany).

Thomas Hollstegge (2):
  si2168: Set TS clock mode and frequency
  dvbsky: Add support for MyGica T230C v2

 drivers/media/dvb-frontends/si2168.c  | 20 ++-
 drivers/media/dvb-frontends/si2168.h  |  8 +++
 drivers/media/dvb-frontends/si2168_priv.h |  2 +
 drivers/media/usb/dvb-usb-v2/dvbsky.c | 90 +++
 include/media/dvb-usb-ids.h   |  1 +
 5 files changed, 120 insertions(+), 1 deletion(-)

-- 
2.7.4



[PATCH 1/2] si2168: Set TS clock mode and frequency

2018-05-05 Thread Thomas Hollstegge
Some devices require a higher TS clock frequency to demodulate some
muxes. This adds two optional parameters to control the TS clock
frequency mode as well as the frequency.

Signed-off-by: Thomas Hollstegge <thomas.hollste...@gmail.com>
---
 drivers/media/dvb-frontends/si2168.c  | 20 +++-
 drivers/media/dvb-frontends/si2168.h  |  8 
 drivers/media/dvb-frontends/si2168_priv.h |  2 ++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/si2168.c 
b/drivers/media/dvb-frontends/si2168.c
index 324493e..80740db 100644
--- a/drivers/media/dvb-frontends/si2168.c
+++ b/drivers/media/dvb-frontends/si2168.c
@@ -92,13 +92,15 @@ static int si2168_ts_bus_ctrl(struct dvb_frontend *fe, int 
acquire)
dev_dbg(>dev, "%s acquire: %d\n", __func__, acquire);
 
/* set TS_MODE property */
-   memcpy(cmd.args, "\x14\x00\x01\x10\x10\x00", 6);
+   memcpy(cmd.args, "\x14\x00\x01\x10\x00\x00", 6);
if (acquire)
cmd.args[4] |= dev->ts_mode;
else
cmd.args[4] |= SI2168_TS_TRISTATE;
if (dev->ts_clock_gapped)
cmd.args[4] |= 0x40;
+   cmd.args[4] |= (dev->ts_clock_mode & 0x03) << 4;
+
cmd.wlen = 6;
cmd.rlen = 4;
ret = si2168_cmd_execute(client, );
@@ -398,6 +400,18 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
if (ret)
goto err;
 
+   /* set TS frequency */
+   if (dev->ts_clock_freq) {
+   memcpy(cmd.args, "\x14\x00\x0d\x10", 4);
+   cmd.args[4] = ((dev->ts_clock_freq / 1) >> 0) & 0xff;
+   cmd.args[5] = ((dev->ts_clock_freq / 1) >> 8) & 0xff;
+   cmd.wlen = 6;
+   cmd.rlen = 4;
+   ret = si2168_cmd_execute(client, );
+   if (ret)
+   goto err;
+   }
+
memcpy(cmd.args, "\x14\x00\x08\x10\xd7\x05", 6);
cmd.args[5] |= dev->ts_clock_inv ? 0x00 : 0x10;
cmd.wlen = 6;
@@ -806,6 +820,10 @@ static int si2168_probe(struct i2c_client *client,
dev->ts_mode = config->ts_mode;
dev->ts_clock_inv = config->ts_clock_inv;
dev->ts_clock_gapped = config->ts_clock_gapped;
+   dev->ts_clock_mode = config->ts_clock_mode;
+   if (!dev->ts_clock_mode)
+   dev->ts_clock_mode = SI2168_TS_CLOCK_MODE_AUTO_ADAPT;
+   dev->ts_clock_freq = config->ts_clock_freq;
dev->spectral_inversion = config->spectral_inversion;
 
dev_info(>dev, "Silicon Labs Si2168-%c%d%d successfully 
identified\n",
diff --git a/drivers/media/dvb-frontends/si2168.h 
b/drivers/media/dvb-frontends/si2168.h
index d519edd..3f52ee8 100644
--- a/drivers/media/dvb-frontends/si2168.h
+++ b/drivers/media/dvb-frontends/si2168.h
@@ -47,6 +47,14 @@ struct si2168_config {
/* TS clock gapped */
bool ts_clock_gapped;
 
+   /* TS clock mode */
+#define SI2168_TS_CLOCK_MODE_AUTO_ADAPT0x01
+#define SI2168_TS_CLOCK_MODE_MANUAL0x02
+   u8 ts_clock_mode;
+
+   /* TS clock frequency (for manual mode) */
+   u32 ts_clock_freq;
+
/* Inverted spectrum */
bool spectral_inversion;
 };
diff --git a/drivers/media/dvb-frontends/si2168_priv.h 
b/drivers/media/dvb-frontends/si2168_priv.h
index 2d362e1..8173d6c 100644
--- a/drivers/media/dvb-frontends/si2168_priv.h
+++ b/drivers/media/dvb-frontends/si2168_priv.h
@@ -48,6 +48,8 @@ struct si2168_dev {
u8 ts_mode;
bool ts_clock_inv;
bool ts_clock_gapped;
+   u8 ts_clock_mode;
+   u32 ts_clock_freq;
bool spectral_inversion;
 };
 
-- 
2.7.4



[PATCH v2] [media] em28xx: support for Sundtek MediaTV Digital Home

2017-05-05 Thread Thomas Hollstegge
Sundtek MediaTV Digital Home is a rebranded MaxMedia UB425-TC with the
following components:

USB bridge: Empia EM2874B
Demodulator: Micronas DRX 3913KA2
Tuner: NXP TDA18271HDC2

Signed-off-by: Thomas Hollstegge <thomas.hollste...@gmail.com>
---
Changes in v2:
  - Make the patch apply against linux-media master

 drivers/media/usb/em28xx/em28xx-cards.c | 15 +++
 drivers/media/usb/em28xx/em28xx-dvb.c   |  1 +
 drivers/media/usb/em28xx/em28xx.h   |  1 +
 3 files changed, 17 insertions(+)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index a12b599..adb5db2 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -415,6 +415,7 @@ static struct em28xx_reg_seq hauppauge_930c_digital[] = {
 
 /* 1b80:e425 MaxMedia UB425-TC
  * 1b80:e1cc Delock 61959
+ * eb1a:51b2 Sundtek MediaTV Digital Home
  * GPIO_6 - demod reset, 0=active
  * GPIO_7 - LED, 0=active
  */
@@ -2405,6 +2406,18 @@ struct em28xx_board em28xx_boards[] = {
.ir_codes  = RC_MAP_HAUPPAUGE,
.leds  = hauppauge_dualhd_leds,
},
+   /* eb1a:51b2 Sundtek MediaTV Digital Home
+* Empia EM2874B + Micronas DRX 3913KA2 + NXP TDA18271HDC2 */
+   [EM2874_BOARD_SUNDTEK_MEDIATV_DIGITAL_HOME] = {
+   .name  = "Sundtek MediaTV Digital Home",
+   .tuner_type= TUNER_ABSENT,
+   .tuner_gpio= maxmedia_ub425_tc,
+   .has_dvb   = 1,
+   .ir_codes  = RC_MAP_REDDO,
+   .def_i2c_bus   = 1,
+   .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
+   EM28XX_I2C_FREQ_400_KHZ,
+   },
 };
 EXPORT_SYMBOL_GPL(em28xx_boards);
 
@@ -2602,6 +2615,8 @@ struct usb_device_id em28xx_id_table[] = {
.driver_info = EM28178_BOARD_PLEX_PX_BCUD },
{ USB_DEVICE(0xeb1a, 0x5051), /* Ion Video 2 PC MKII / Startech 
svid2usb23 / Raygo R12-41373 */
.driver_info = EM2860_BOARD_TVP5150_REFERENCE_DESIGN },
+   { USB_DEVICE(0xeb1a, 0x51b2),
+   .driver_info = 
EM2874_BOARD_SUNDTEK_MEDIATV_DIGITAL_HOME },
{ },
 };
 MODULE_DEVICE_TABLE(usb, em28xx_id_table);
diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c 
b/drivers/media/usb/em28xx/em28xx-dvb.c
index 82edd37..e7fa25d 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -1482,6 +1482,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
break;
}
case EM2874_BOARD_DELOCK_61959:
+   case EM2874_BOARD_SUNDTEK_MEDIATV_DIGITAL_HOME:
case EM2874_BOARD_MAXMEDIA_UB425_TC:
/* attach demodulator */
dvb->fe[0] = dvb_attach(drxk_attach, _ub425_tc_drxk,
diff --git a/drivers/media/usb/em28xx/em28xx.h 
b/drivers/media/usb/em28xx/em28xx.h
index e8d97d5..226c2b6 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -148,6 +148,7 @@
 #define EM28178_BOARD_PLEX_PX_BCUD98
 #define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB  99
 #define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595 100
+#define EM2874_BOARD_SUNDTEK_MEDIATV_DIGITAL_HOME 101
 
 /* Limits minimum and default number of buffers */
 #define EM28XX_MIN_BUF 4
-- 
2.7.4



Re: [PATCH] [media] em28xx: support for Sundtek MediaTV Digital Home

2017-05-05 Thread Thomas Hollstegge
Hi Markus,

Markus Rechberger  schrieb am Sat, 06. May 00:33:
> We had different HW designs based on Empia until 2012 using this USB
> ID it will not work with many units out there, also with different
> standby behaviours, chipsets etc.

Well, after this patch there's one more device that works with an
open-source driver, which I consider a good thing. What about
open-sourcing support for the other devices you're talking about?

> If you want to get a device with kernel support I recommend buying a
> different one and let that one go back to our community (since our
> tuners and support are still quite popular).

Thanks, but I'd rather stick with the device I have than spending more
money to have a device that only works with a closed-source driver.

Anyway, I just saw that the patch doesn't apply cleanly against
linux-media master. I'll submit a new version of the patch in a
minute.

Cheers
Thomas


Re: [PATCH] [media] em28xx: support for Sundtek MediaTV Digital Home

2017-05-05 Thread Thomas Hollstegge
Hi Markus,

Markus Rechberger <mrechber...@gmail.com> schrieb am Fri, 05. May 08:06:
> On Fri, May 5, 2017 at 6:21 AM, Thomas Hollstegge
> <thomas.hollste...@gmail.com> wrote:
> > Sundtek MediaTV Digital Home is a rebranded MaxMedia UB425-TC with the
> > following components:
> >
> > USB bridge: Empia EM2874B
> > Demodulator: Micronas DRX 3913KA2
> > Tuner: NXP TDA18271HDC2
> >
> 
> Not that it matters a lot anymore for those units however the USB ID
> is allocated for multiple different units, this patch will break some
> of them.

I searched the kernel sources for USB IDs but didn't find any mention.
So what exactly will break with this commit? Is there a better way to
detect different devices besides USB IDs?

> If you want to use that use the unit with this driver you're on your
> own and have to assign it via sysfs and usb/bind.

I did, and it works fine. However, it would be nice if the driver
supported the devices directly.

> It was a joint project many years ago before we also started to design
> and manufacture our own units.

Interesting, thanks for sharing this insight!

Cheers
Thomas


[PATCH] [media] em28xx: support for Sundtek MediaTV Digital Home

2017-05-04 Thread Thomas Hollstegge
Sundtek MediaTV Digital Home is a rebranded MaxMedia UB425-TC with the
following components:

USB bridge: Empia EM2874B
Demodulator: Micronas DRX 3913KA2
Tuner: NXP TDA18271HDC2

Signed-off-by: Thomas Hollstegge <thomas.hollste...@gmail.com>
---
 drivers/media/usb/em28xx/em28xx-cards.c | 15 +++
 drivers/media/usb/em28xx/em28xx-dvb.c   |  1 +
 drivers/media/usb/em28xx/em28xx.h   |  1 +
 3 files changed, 17 insertions(+)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index 5f90d08..4effbda 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -415,6 +415,7 @@ static struct em28xx_reg_seq hauppauge_930c_digital[] = {
 
 /* 1b80:e425 MaxMedia UB425-TC
  * 1b80:e1cc Delock 61959
+ * eb1a:51b2 Sundtek MediaTV Digital Home
  * GPIO_6 - demod reset, 0=active
  * GPIO_7 - LED, 0=active
  */
@@ -2405,6 +2406,18 @@ struct em28xx_board em28xx_boards[] = {
.ir_codes  = RC_MAP_HAUPPAUGE,
.leds  = hauppauge_dualhd_leds,
},
+   /* eb1a:51b2 Sundtek MediaTV Digital Home
+* Empia EM2874B + Micronas DRX 3913KA2 + NXP TDA18271HDC2 */
+   [EM2874_BOARD_SUNDTEK_MEDIATV_DIGITAL_HOME] = {
+   .name  = "Sundtek MediaTV Digital Home",
+   .tuner_type= TUNER_ABSENT,
+   .tuner_gpio= maxmedia_ub425_tc,
+   .has_dvb   = 1,
+   .ir_codes  = RC_MAP_REDDO,
+   .def_i2c_bus   = 1,
+   .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
+   EM28XX_I2C_FREQ_400_KHZ,
+   },
 };
 EXPORT_SYMBOL_GPL(em28xx_boards);
 
@@ -2600,6 +2613,8 @@ struct usb_device_id em28xx_id_table[] = {
.driver_info = EM28178_BOARD_TERRATEC_T2_STICK_HD },
{ USB_DEVICE(0x3275, 0x0085),
.driver_info = EM28178_BOARD_PLEX_PX_BCUD },
+   { USB_DEVICE(0xeb1a, 0x51b2),
+   .driver_info = 
EM2874_BOARD_SUNDTEK_MEDIATV_DIGITAL_HOME },
{ },
 };
 MODULE_DEVICE_TABLE(usb, em28xx_id_table);
diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c 
b/drivers/media/usb/em28xx/em28xx-dvb.c
index 82edd37..e7fa25d 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -1482,6 +1482,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
break;
}
case EM2874_BOARD_DELOCK_61959:
+   case EM2874_BOARD_SUNDTEK_MEDIATV_DIGITAL_HOME:
case EM2874_BOARD_MAXMEDIA_UB425_TC:
/* attach demodulator */
dvb->fe[0] = dvb_attach(drxk_attach, _ub425_tc_drxk,
diff --git a/drivers/media/usb/em28xx/em28xx.h 
b/drivers/media/usb/em28xx/em28xx.h
index e9f3799..72f1468 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -148,6 +148,7 @@
 #define EM28178_BOARD_PLEX_PX_BCUD98
 #define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB  99
 #define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595 100
+#define EM2874_BOARD_SUNDTEK_MEDIATV_DIGITAL_HOME 101
 
 /* Limits minimum and default number of buffers */
 #define EM28XX_MIN_BUF 4
-- 
2.7.4