Hi,

I've been playing with a modified version of the existing Cinergy T²
driver which has been merged to fit into current dvb-usb driver framework
like the rest of the drivers existing under the dvb-usb directory in
HG-tree. However, there are a couple of things which I have a problem
with:

1) For some reason if I define a release handler funtion for the frontend
(of type struct dvb_frontend_ops ) --> .release = cinergyt2_fe_release and
then physically remove the usb-device from the computer and re-connect
immediately after, the kernel modules ref-counter goes backwards to
unsigned 32-bit -1 (ie value is shown to be 4294967295 by the lsmod-cmd).
This seems to happen because of the dvb_frontend_detach() calls the
frontends release handler if it has been defined and immediately after it
calls symbol_put_addr(ptr).

#ifdef CONFIG_DVB_CORE_ATTACH
void dvb_frontend_detach(struct dvb_frontend* fe)
{
        void *ptr;

        if (fe->ops.release_sec) {
                fe->ops.release_sec(fe);
                symbol_put_addr(fe->ops.release_sec);
        }
        if (fe->ops.tuner_ops.release) {
                fe->ops.tuner_ops.release(fe);
                symbol_put_addr(fe->ops.tuner_ops.release);
        }
        ptr = (void*)fe->ops.release;
        if (ptr) {
                fe->ops.release(fe);
                symbol_put_addr(ptr);
        }
}
#else

If I don't define the release handler for the frontend, the modules
ref-counter stays 0 as expected.

2) Is there any chance to change the "struct dvb_usb_rc_key" defined in
dvb-usb.h as currently it contains two fields of type u8, while the
Cinergy T² device sepcs say that the device sends 32-bit remote control
codes and therefore I don't know how to get the Cinergy T² remote
controller handling to fit the current dvb-usb system ... ?
(this can be seen in the current Cinergy T² driver sources as well)

struct dvb_usb_rc_key {
        u8 custom,data;
^^^^^^^^^^^^^^^^^^^^^
        u32 event;
};

Regards,
Tomi Orava

-- 
diff -r 18f323a05fbe linux/drivers/media/dvb/dvb-usb/Kconfig
--- a/linux/drivers/media/dvb/dvb-usb/Kconfig	Mon Sep 03 16:01:51 2007 +0100
+++ b/linux/drivers/media/dvb/dvb-usb/Kconfig	Sun Sep 16 13:40:52 2007 +0300
@@ -239,3 +239,11 @@ config DVB_USB_AF9005_REMOTE
 	  Say Y here to support the default remote control decoding for the
 	  Afatech AF9005 based receiver.
 
+config 	DVB_USB_CINERGY_T2
+	tristate "Alternative driver for Terratec CinergyT2/qanu USB2 DVB-T receiver"
+	depends on DVB_USB
+	help
+	  Support for "TerraTec CinergyT2" USB2.0 Highspeed DVB Receivers
+
+	  Say Y if you own such a device and want to use it.
+
diff -r 18f323a05fbe linux/drivers/media/dvb/dvb-usb/Makefile
--- a/linux/drivers/media/dvb/dvb-usb/Makefile	Mon Sep 03 16:01:51 2007 +0100
+++ b/linux/drivers/media/dvb/dvb-usb/Makefile	Sun Sep 16 13:43:15 2007 +0300
@@ -61,4 +61,8 @@ dvb-usb-af9005-remote-objs = af9005-remo
 dvb-usb-af9005-remote-objs = af9005-remote.o
 obj-$(CONFIG_DVB_USB_AF9005_REMOTE) += dvb-usb-af9005-remote.o
 
+dvb-usb-cinergyT2-objs = cinergyT2-core.o cinergyT2-fe.o cinergyT2-remote.o
+obj-$(CONFIG_DVB_USB_CINERGY_T2) += dvb-usb-cinergyT2.o
+
+
 EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
diff -r 18f323a05fbe linux/drivers/media/dvb/dvb-usb/cinergyT2-core.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linux/drivers/media/dvb/dvb-usb/cinergyT2-core.c	Thu Sep 20 11:02:14 2007 +0300
@@ -0,0 +1,264 @@
+/*
+ * TerraTec Cinergy T�/qanu USB2 DVB-T adapter.
+ *
+ * Copyright (C) 2004 Daniel Mack <[EMAIL PROTECTED]> and
+ *		    Holger Waechtler <[EMAIL PROTECTED]>
+ *
+ *  Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include "cinergyT2.h"
+
+
+// #ifdef CONFIG_DVB_CINERGYT2_TUNING
+// 	#define STREAM_URB_COUNT (CONFIG_DVB_CINERGYT2_STREAM_URB_COUNT)
+// 	#define STREAM_BUF_SIZE (CONFIG_DVB_CINERGYT2_STREAM_BUF_SIZE)
+// 	#define QUERY_INTERVAL (CONFIG_DVB_CINERGYT2_QUERY_INTERVAL)
+// 	#ifdef CONFIG_DVB_CINERGYT2_ENABLE_RC_INPUT_DEVICE
+// 		#define RC_QUERY_INTERVAL (CONFIG_DVB_CINERGYT2_RC_QUERY_INTERVAL)
+// 		// #define ENABLE_RC (1)
+// 	#endif
+// #else
+// 	#define STREAM_URB_COUNT (32)
+// 	#define STREAM_BUF_SIZE (512)	/* bytes */
+// 	// #define ENABLE_RC (1)
+// 	#define RC_QUERY_INTERVAL (50)	/* milliseconds */
+// 	#define QUERY_INTERVAL (333)	/* milliseconds */
+// #endif
+
+/* debug */
+int dvb_usb_cinergyt2_debug;
+module_param_named(debug,dvb_usb_cinergyt2_debug, int, 0644);
+MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able)).");
+
+struct cinergyt2_rc_event {
+	char type;
+	uint32_t value;
+} __attribute__((packed));
+
+
+int cinergyt2_command(struct dvb_usb_device *d,
+			      char *send_buf, int send_buf_len,
+			      char *recv_buf, int recv_buf_len, int msec)
+{
+	int actual_len;
+	char dummy;
+	int ret;
+	msec=msec;
+
+	if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
+		return ret;
+
+	ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev, 1),
+	 		   send_buf, send_buf_len, &actual_len, 1000);
+	if (ret) {
+		err("usb_bulk_msg (send) failed, err %i\n", ret);
+		mutex_unlock(&d->usb_mutex);
+		return (-EIO);
+	}
+
+	if (!recv_buf)
+		recv_buf = &dummy;
+
+	ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev, 1),
+			   recv_buf, recv_buf_len, &actual_len, 1000);
+
+	if (ret) {
+		err("usb_bulk_msg (read) failed, err %i\n", ret);
+		mutex_unlock(&d->usb_mutex);
+		return (-EIO);
+	}
+
+	mutex_unlock(&d->usb_mutex);
+	return actual_len;
+}
+
+static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
+{
+	char buf [] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
+	return cinergyt2_command(adap->dev, buf, sizeof(buf), NULL, 0, 30);
+}
+
+static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
+{
+	char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
+	char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
+	char state[3];
+	int ret;
+
+#if 0
+	ret = cinergyt2_command(d, query, sizeof(query), state, sizeof(state), 0);
+	if (ret < 0) {
+		info("cinergyt2_power_ctrl() Failed to retrieve sleep state info\n");
+		return ret;
+	}
+
+	if (enable == state[2]) {
+		printk(KERN_INFO "cinergyt2_power_ctrl() Already in correct power state=%d\n", enable);
+		return 0;
+	}
+#endif
+	info("cinergyt2_power_ctrl() setting power=%d\n", enable);
+	return cinergyt2_command(d, buf, sizeof(buf), NULL, 0, 0);
+}
+
+static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
+{
+	adap->fe = cinergyt2_fe_attach(adap->dev);
+	return 0;
+}
+
+
+
+static struct dvb_usb_device_properties cinergyt2_properties;
+
+static int cinergyt2_usb_probe(struct usb_interface *intf,
+                const struct usb_device_id *id)
+{
+        return dvb_usb_device_init(intf,&cinergyt2_properties,THIS_MODULE,NULL);
+}
+
+
+static struct usb_device_id cinergyt2_usb_table [] = {
+	{ USB_DEVICE(USB_VID_TERRATEC, 0x0038) },
+	{ 0 }
+};
+
+MODULE_DEVICE_TABLE(usb, cinergyt2_usb_table);
+
+
+static struct dvb_usb_device_properties cinergyt2_properties = {
+	// .usb_ctrl = CYPRESS_FX2,
+	// .firmware = "dvb-usb-vp7045-01.fw",
+
+	.num_adapters = 1,
+	.adapter = {
+		{
+			.streaming_ctrl   = cinergyt2_streaming_ctrl,
+			.frontend_attach  = cinergyt2_frontend_attach,
+
+			/* parameter for the MPEG2-data transfer */
+			.stream = {
+				.type = USB_BULK,
+				.count = 7,
+				.endpoint = 0x02,
+				.u = {
+					.bulk = {
+						.buffersize = 512,
+					}
+				}
+			},
+		}
+	},
+
+	.power_ctrl       = cinergyt2_power_ctrl,
+
+	.rc_interval      = 0,
+	.rc_key_map       = cinergyt2_rc_keys,
+	.rc_key_map_size  = 0,
+	.rc_query         = 0,
+	// .rc_query         = cinergyt2_rc_query,
+
+        .generic_bulk_ctrl_endpoint = 0x01,
+
+	.num_device_descs = 1,
+	.devices = {
+		{ .name = "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver",
+		  .cold_ids = {NULL},
+		  .warm_ids = { &cinergyt2_usb_table[0], NULL },
+		},
+		{ NULL },
+	}
+};
+
+
+static struct usb_driver cinergyt2_driver = {
+#if LINUX_VERSION_CODE <=  KERNEL_VERSION(2,6,15)
+	.owner	= THIS_MODULE,
+#endif
+	.name		= "cinergyT2",
+	.probe		= cinergyt2_usb_probe,
+	.disconnect	= dvb_usb_device_exit,
+	.id_table	= cinergyt2_usb_table
+};
+
+static int __init cinergyt2_usb_init(void)
+{
+	int err;
+
+	if (0) {
+		err("Cinergy Remote Control was enabled!\n");
+		cinergyt2_properties.rc_key_map_size = cinergyt2_rc_keys_size;
+		cinergyt2_properties.rc_key_map = cinergyt2_rc_keys;
+		cinergyt2_properties.rc_interval = 300;
+		cinergyt2_properties.rc_query = cinergyt2_rc_query;
+	} else {
+		cinergyt2_properties.rc_query = NULL;
+		cinergyt2_properties.rc_interval = 0;
+		err("Cinergy Remote Control was not enabled!\n");
+	}
+
+	err("Cinergy Remote Control table size=%d\n", cinergyt2_rc_keys_size);
+
+	if ((err = usb_register(&cinergyt2_driver))) {
+		err("usb_register() failed! (err %i)\n", err);
+		return err;
+	}
+	return 0;
+}
+
+static void __exit cinergyt2_usb_exit(void)
+{
+	usb_deregister(&cinergyt2_driver);
+}
+
+module_init (cinergyt2_usb_init);
+module_exit (cinergyt2_usb_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Holger Waechtler, Daniel Mack");
+
+int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
+{
+	char buf[1] = { CINERGYT2_EP1_GET_RC_EVENTS };
+	struct cinergyt2_rc_event rc_events[12];
+	int len, i;
+
+
+	*state = REMOTE_NO_KEY_PRESSED;
+
+
+	len = cinergyt2_command(d, buf, sizeof(buf),
+				(char *)rc_events, sizeof(rc_events), 30);
+	if (len < 0) {
+		printk(KERN_INFO "Failed to read RC event data!\n");
+		return 0;
+	}
+
+	if (len==0)
+		return 0;
+
+	info("Read %d rc events data!\n", len);
+	// info("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]);
+
+	for (i = 0; i < (len / sizeof(rc_events[0])); i++) {
+		deb_info("rc_events[%d].value = %x (converted=%x), type=%x\n",
+			i, rc_events[i].value, le32_to_cpu(rc_events[i].value), rc_events[i].type);
+	}
+	return 0;
+}
diff -r 18f323a05fbe linux/drivers/media/dvb/dvb-usb/cinergyT2-fe.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linux/drivers/media/dvb/dvb-usb/cinergyT2-fe.c	Sun Sep 16 13:37:30 2007 +0300
@@ -0,0 +1,337 @@
+/*
+ * TerraTec Cinergy T�/qanu USB2 DVB-T adapter.
+ *
+ * Copyright (C) 2004 Daniel Mack <[EMAIL PROTECTED]> and
+ *		    Holger Waechtler <[EMAIL PROTECTED]>
+ *
+ *  Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include "cinergyT2.h"
+
+
+/**
+ *  convert linux-dvb frontend parameter set into TPS.
+ *  See ETSI ETS-300744, section 4.6.2, table 9 for details.
+ *
+ *  This function is probably reusable and may better get placed in a support
+ *  library.
+ *
+ *  We replace errornous fields by default TPS fields (the ones with value 0).
+ */
+static uint16_t compute_tps (struct dvb_frontend_parameters *p)
+{
+	struct dvb_ofdm_parameters *op = &p->u.ofdm;
+	uint16_t tps = 0;
+
+	// deb_info("compute_tps() Called\n");
+
+	switch (op->code_rate_HP) {
+		case FEC_2_3:
+			tps |= (1 << 7);
+			break;
+		case FEC_3_4:
+			tps |= (2 << 7);
+			break;
+		case FEC_5_6:
+			tps |= (3 << 7);
+			break;
+		case FEC_7_8:
+			tps |= (4 << 7);
+			break;
+		case FEC_1_2:
+		case FEC_AUTO:
+		default:
+			/* tps |= (0 << 7) */;
+	}
+
+	switch (op->code_rate_LP) {
+		case FEC_2_3:
+			tps |= (1 << 4);
+			break;
+		case FEC_3_4:
+			tps |= (2 << 4);
+			break;
+		case FEC_5_6:
+			tps |= (3 << 4);
+			break;
+		case FEC_7_8:
+			tps |= (4 << 4);
+			break;
+		case FEC_1_2:
+		case FEC_AUTO:
+		default:
+			/* tps |= (0 << 4) */;
+	}
+
+	switch (op->constellation) {
+		case QAM_16:
+			tps |= (1 << 13);
+			break;
+		case QAM_64:
+			tps |= (2 << 13);
+			break;
+		case QPSK:
+		default:
+			/* tps |= (0 << 13) */;
+	}
+
+	switch (op->transmission_mode) {
+		case TRANSMISSION_MODE_8K:
+			tps |= (1 << 0);
+			break;
+		case TRANSMISSION_MODE_2K:
+		default:
+			/* tps |= (0 << 0) */;
+	}
+
+	switch (op->guard_interval) {
+		case GUARD_INTERVAL_1_16:
+			tps |= (1 << 2);
+			break;
+		case GUARD_INTERVAL_1_8:
+			tps |= (2 << 2);
+			break;
+		case GUARD_INTERVAL_1_4:
+			tps |= (3 << 2);
+			break;
+		case GUARD_INTERVAL_1_32:
+		default:
+			/* tps |= (0 << 2) */;
+	}
+
+	switch (op->hierarchy_information) {
+		case HIERARCHY_1:
+			tps |= (1 << 10);
+			break;
+		case HIERARCHY_2:
+			tps |= (2 << 10);
+			break;
+		case HIERARCHY_4:
+			tps |= (3 << 10);
+			break;
+		case HIERARCHY_NONE:
+		default:
+			/* tps |= (0 << 10) */;
+	}
+
+	return tps;
+}
+
+
+
+struct cinergyt2_fe_state {
+	struct dvb_frontend fe;
+	struct dvb_usb_device *d;
+};
+
+static int cinergyt2_fe_read_status(struct dvb_frontend* fe, fe_status_t *status)
+{
+	struct cinergyt2_fe_state *state = fe->demodulator_priv;
+	struct dvbt_get_status_msg result;
+	char cmd [] = { CINERGYT2_EP1_GET_TUNER_STATUS };
+	int ret;
+
+	ret = cinergyt2_command(state->d, cmd, sizeof(cmd), (char *)&result,
+			sizeof(result), 30);
+	if (ret < 0) {
+		return ret;
+	}
+	*status = 0;
+
+	if (0xffff - le16_to_cpu(result.gain) > 30)
+		*status |= FE_HAS_SIGNAL;
+	if (result.lock_bits & (1 << 6))
+		*status |= FE_HAS_LOCK;
+	if (result.lock_bits & (1 << 5))
+		*status |= FE_HAS_SYNC;
+	if (result.lock_bits & (1 << 4))
+		*status |= FE_HAS_CARRIER;
+	if (result.lock_bits & (1 << 1))
+		*status |= FE_HAS_VITERBI;
+
+	if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
+			(FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
+		*status &= ~FE_HAS_LOCK;
+
+	return 0;
+}
+
+static int cinergyt2_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
+{
+	struct cinergyt2_fe_state *state = fe->demodulator_priv;
+	struct dvbt_get_status_msg status;
+	char cmd [] = { CINERGYT2_EP1_GET_TUNER_STATUS };
+	int ret;
+
+	ret = cinergyt2_command(state->d, cmd, sizeof(cmd), (char *)&status, sizeof(status), 30);
+	if (ret < 0) {
+		return ret;
+	}
+	*ber = le32_to_cpu(status.viterbi_error_rate);
+	return 0;
+}
+
+static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
+{
+	struct cinergyt2_fe_state *state = fe->demodulator_priv;
+	struct dvbt_get_status_msg status;
+	char cmd [] = { CINERGYT2_EP1_GET_TUNER_STATUS };
+	int ret;
+
+	ret = cinergyt2_command(state->d, cmd, sizeof(cmd), (char *)&status, sizeof(status), 30);
+	if (ret < 0) {
+		err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n", ret);
+		return ret;
+	}
+ 	*unc = le32_to_cpu(status.uncorrected_block_count);
+	return 0;
+}
+
+static int cinergyt2_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
+{
+	struct cinergyt2_fe_state *state = fe->demodulator_priv;
+	struct dvbt_get_status_msg status;
+	char cmd [] = { CINERGYT2_EP1_GET_TUNER_STATUS };
+	int ret;
+
+	ret = cinergyt2_command(state->d, cmd, sizeof(cmd), (char *)&status, sizeof(status), 30);
+	if (ret < 0) {
+		err("cinergyt2_fe_read_signal_strength() Failed! (Error=%d)\n", ret);
+		return ret;
+	}
+	*strength = (0xffff - le16_to_cpu(status.gain));
+	return 0;
+}
+
+static int cinergyt2_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
+{
+	struct cinergyt2_fe_state *state = fe->demodulator_priv;
+	struct dvbt_get_status_msg status;
+	char cmd [] = { CINERGYT2_EP1_GET_TUNER_STATUS };
+	int ret;
+
+	ret = cinergyt2_command(state->d, cmd, sizeof(cmd), (char *)&status, sizeof(status), 30);
+	if (ret < 0) {
+		err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
+		return ret;
+	}
+	*snr = (status.snr << 8) | status.snr;
+	return 0;
+}
+
+static int cinergyt2_fe_init(struct dvb_frontend* fe)
+{
+	return 0;
+}
+
+static int cinergyt2_fe_sleep(struct dvb_frontend* fe)
+{
+	deb_info("cinergyt2_fe_sleep() Called\n");
+	return 0;
+}
+
+static int cinergyt2_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
+{
+	tune->min_delay_ms = 800;
+	return 0;
+}
+
+static int cinergyt2_fe_set_frontend(struct dvb_frontend* fe,
+				  struct dvb_frontend_parameters *fep)
+{
+	struct cinergyt2_fe_state *state = fe->demodulator_priv;
+	struct dvbt_set_parameters_msg param;
+	int err;
+
+	param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
+	param.tps = cpu_to_le16(compute_tps(fep));
+	param.freq = cpu_to_le32(fep->frequency / 1000);
+	param.bandwidth = 8 - fep->u.ofdm.bandwidth - BANDWIDTH_8_MHZ;
+
+	err = cinergyt2_command(state->d,
+			(char *)&param, sizeof(param),
+			NULL, 0, 30);
+	if (err < 0) {
+		err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
+	}
+
+	return (err < 0) ? err : 0;
+}
+
+static int cinergyt2_fe_get_frontend(struct dvb_frontend* fe,
+				  struct dvb_frontend_parameters *fep)
+{
+	return 0;
+}
+
+static void cinergyt2_fe_release(struct dvb_frontend* fe)
+{
+	struct cinergyt2_fe_state *state = fe->demodulator_priv;
+	if (state != NULL)
+		kfree(state);
+}
+
+static struct dvb_frontend_ops cinergyt2_fe_ops;
+
+struct dvb_frontend * cinergyt2_fe_attach(struct dvb_usb_device *d)
+{
+	struct cinergyt2_fe_state *s = kzalloc(sizeof(struct cinergyt2_fe_state), GFP_KERNEL);
+	if (s == NULL)
+		goto error;
+
+	s->d = d;
+	memcpy(&s->fe.ops, &cinergyt2_fe_ops, sizeof(struct dvb_frontend_ops));
+	s->fe.demodulator_priv = s;
+
+	return &s->fe;
+error:
+	return NULL;
+}
+
+
+static struct dvb_frontend_ops cinergyt2_fe_ops = {
+	.info = {
+		.name			= DRIVER_NAME,
+		.type			= FE_OFDM,
+		.frequency_min		= 174000000,
+		.frequency_max		= 862000000,
+		.frequency_stepsize	= 166667,
+		.caps = FE_CAN_INVERSION_AUTO | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
+			FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
+			FE_CAN_FEC_AUTO |
+			FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
+			FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
+			FE_CAN_HIERARCHY_AUTO | FE_CAN_RECOVER | FE_CAN_MUTE_TS
+	},
+
+	.release		= cinergyt2_fe_release,
+
+	.init			= cinergyt2_fe_init,
+	.sleep			= cinergyt2_fe_sleep,
+
+	.set_frontend		= cinergyt2_fe_set_frontend,
+	.get_frontend		= cinergyt2_fe_get_frontend,
+	.get_tune_settings	= cinergyt2_fe_get_tune_settings,
+
+	.read_status		= cinergyt2_fe_read_status,
+	.read_ber		= cinergyt2_fe_read_ber,
+	.read_signal_strength	= cinergyt2_fe_read_signal_strength,
+	.read_snr		= cinergyt2_fe_read_snr,
+	.read_ucblocks		= cinergyt2_fe_read_unc_blocks,
+};
diff -r 18f323a05fbe linux/drivers/media/dvb/dvb-usb/cinergyT2-remote.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linux/drivers/media/dvb/dvb-usb/cinergyT2-remote.c	Sun Sep 16 13:37:30 2007 +0300
@@ -0,0 +1,300 @@
+/*
+ * TerraTec Cinergy T�/qanu USB2 DVB-T adapter.
+ *
+ * Copyright (C) 2004 Daniel Mack <[EMAIL PROTECTED]> and
+ *		    Holger Waechtler <[EMAIL PROTECTED]>
+ *
+ *  Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include "cinergyT2.h"
+
+
+// struct cinergyt2_rc_event {
+// 	char type;
+// 	uint32_t value;
+// } __attribute__((packed));
+//
+
+enum {
+	CINERGYT2_RC_EVENT_TYPE_NONE = 0x00,
+	CINERGYT2_RC_EVENT_TYPE_NEC  = 0x01,
+	CINERGYT2_RC_EVENT_TYPE_RC5  = 0x02
+};
+
+struct dvb_usb_rc_key cinergyt2_rc_keys[] = {
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xfe01eb04,	KEY_POWER },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xfd02eb04,	KEY_1 },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xfc03eb04,	KEY_2 },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xfb04eb04,	KEY_3 },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xfa05eb04,	KEY_4 },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xf906eb04,	KEY_5 },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xf807eb04,	KEY_6 },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xf708eb04,	KEY_7 },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xf609eb04,	KEY_8 },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xf50aeb04,	KEY_9 },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xf30ceb04,	KEY_0 },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xf40beb04,	KEY_VIDEO },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xf20deb04,	KEY_REFRESH },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xf10eeb04,	KEY_SELECT },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xf00feb04,	KEY_EPG },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xef10eb04,	KEY_UP },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xeb14eb04,	KEY_DOWN },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xee11eb04,	KEY_LEFT },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xec13eb04,	KEY_RIGHT },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xed12eb04,	KEY_OK },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xea15eb04,	KEY_TEXT },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xe916eb04,	KEY_INFO },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xe817eb04,	KEY_RED },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xe718eb04,	KEY_GREEN },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xe619eb04,	KEY_YELLOW },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xe51aeb04,	KEY_BLUE },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xe31ceb04,	KEY_VOLUMEUP },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xe11eeb04,	KEY_VOLUMEDOWN },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xe21deb04,	KEY_MUTE },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xe41beb04,	KEY_CHANNELUP },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xe01feb04,	KEY_CHANNELDOWN },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xbf40eb04,	KEY_PAUSE },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xb34ceb04,	KEY_PLAY },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xa758eb04,	KEY_RECORD },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xab54eb04,	KEY_PREVIOUS },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xb748eb04,	KEY_STOP },
+	{ CINERGYT2_RC_EVENT_TYPE_NEC,	0xa35ceb04,	KEY_NEXT }
+};
+
+#if 0
+int cinergyt2_rc_keys_size(void) {
+	return (sizeof(cinergyt2_rc_keys));
+}
+#endif
+
+int cinergyt2_rc_keys_size = ARRAY_SIZE(cinergyt2_rc_keys);
+
+#if 0
+int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
+{
+	char buf[1] = { CINERGYT2_EP1_GET_RC_EVENTS };
+	struct cinergyt2_rc_event rc_events[12];
+	int len, i;
+
+
+	*state = REMOTE_NO_KEY_PRESSED;
+
+
+	len = cinergyt2_command(d, buf, sizeof(buf),
+				(char *)rc_events, sizeof(rc_events), 30);
+	if (len < 0) {
+		printk(KERN_INFO "Failed to read RC event data!\n");
+		return len;
+	}
+
+	if (len==0)
+		return 0;
+
+	info("Read %d rc events data!\n", len);
+	// info("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]);
+
+	for (i = 0; i < (len / sizeof(cinergyt2_rc_keys[0])); i++) {
+		deb_info("rc_events[%d].value = %x (converted=%x), type=%x\n",
+			i, rc_events[i].value, le32_to_cpu(rc_events[i].value), rc_events[i].type);
+	}
+
+
+#if 0
+	u8 key;
+	int i;
+	vp7045_usb_op(d,RC_VAL_READ,NULL,0,&key,1,20);
+
+	deb_rc("remote query key: %x %d\n",key,key);
+
+	if (key == 0x44) {
+		*state = REMOTE_NO_KEY_PRESSED;
+		return 0;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(vp7045_rc_keys); i++)
+		if (vp7045_rc_keys[i].data == key) {
+			*state = REMOTE_KEY_PRESSED;
+			*event = vp7045_rc_keys[i].event;
+			break;
+		}
+	return 0;
+#endif
+
+#if 0
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
+	struct cinergyt2 *cinergyt2 = data;
+#else
+	struct cinergyt2 *cinergyt2 =
+		container_of(work, struct cinergyt2, rc_query_work.work);
+#endif
+	struct cinergyt2_rc_event rc_events[12];
+	int n, len, i;
+
+	if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->mutex))
+		return;
+
+	len = cinergyt2_command(cinergyt2, buf, sizeof(buf),
+				(char *) rc_events, sizeof(rc_events));
+	if (len < 0)
+		goto out;
+	if (len == 0) {
+		if (time_after(jiffies, cinergyt2->last_event_jiffies +
+			       msecs_to_jiffies(150))) {
+			/* stop key repeat */
+			if (cinergyt2->rc_input_event != KEY_MAX) {
+				dprintk(1, "rc_input_event=%d Up\n", cinergyt2->rc_input_event);
+				input_report_key(cinergyt2->rc_input_dev,
+						 cinergyt2->rc_input_event, 0);
+				input_sync(cinergyt2->rc_input_dev);
+				cinergyt2->rc_input_event = KEY_MAX;
+			}
+			cinergyt2->rc_last_code = ~0;
+		}
+		goto out;
+	}
+	cinergyt2->last_event_jiffies = jiffies;
+
+	for (n = 0; n < (len / sizeof(rc_events[0])); n++) {
+		dprintk(1, "rc_events[%d].value = %x, type=%x\n",
+			n, le32_to_cpu(rc_events[n].value), rc_events[n].type);
+
+		if (rc_events[n].type == CINERGYT2_RC_EVENT_TYPE_NEC &&
+		    rc_events[n].value == ~0) {
+			/* keyrepeat bit -> just repeat last rc_input_event */
+		} else {
+			cinergyt2->rc_input_event = KEY_MAX;
+			for (i = 0; i < ARRAY_SIZE(rc_keys); i += 3) {
+				if (rc_keys[i + 0] == rc_events[n].type &&
+				    rc_keys[i + 1] == le32_to_cpu(rc_events[n].value)) {
+					cinergyt2->rc_input_event = rc_keys[i + 2];
+					break;
+				}
+			}
+		}
+
+		if (cinergyt2->rc_input_event != KEY_MAX) {
+			if (rc_events[n].value == cinergyt2->rc_last_code &&
+			    cinergyt2->rc_last_code != ~0) {
+				/* emit a key-up so the double event is recognized */
+				dprintk(1, "rc_input_event=%d UP\n", cinergyt2->rc_input_event);
+				input_report_key(cinergyt2->rc_input_dev,
+						 cinergyt2->rc_input_event, 0);
+			}
+			dprintk(1, "rc_input_event=%d\n", cinergyt2->rc_input_event);
+			input_report_key(cinergyt2->rc_input_dev,
+					 cinergyt2->rc_input_event, 1);
+			input_sync(cinergyt2->rc_input_dev);
+			cinergyt2->rc_last_code = rc_events[n].value;
+		}
+	}
+
+out:
+	schedule_delayed_work(&cinergyt2->rc_query_work,
+			      msecs_to_jiffies(RC_QUERY_INTERVAL));
+
+	mutex_unlock(&cinergyt2->mutex);
+#endif
+	return 0;
+}
+#endif
+
+#if 0
+static int cinergyt2_register_rc(struct cinergyt2 *cinergyt2)
+{
+	struct input_dev *input_dev;
+	int i;
+	int err;
+
+	input_dev = input_allocate_device();
+	if (!input_dev)
+		return -ENOMEM;
+
+	usb_make_path(cinergyt2->udev, cinergyt2->phys, sizeof(cinergyt2->phys));
+	strlcat(cinergyt2->phys, "/input0", sizeof(cinergyt2->phys));
+	cinergyt2->rc_input_event = KEY_MAX;
+	cinergyt2->rc_last_code = ~0;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
+	INIT_WORK(&cinergyt2->rc_query_work, cinergyt2_query_rc, cinergyt2);
+#else
+	INIT_DELAYED_WORK(&cinergyt2->rc_query_work, cinergyt2_query_rc);
+#endif
+
+	input_dev->name = DRIVER_NAME " remote control";
+	input_dev->phys = cinergyt2->phys;
+	input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
+	for (i = 0; i < ARRAY_SIZE(rc_keys); i += 3)
+		set_bit(rc_keys[i + 2], input_dev->keybit);
+	input_dev->keycodesize = 0;
+	input_dev->keycodemax = 0;
+	input_dev->id.bustype = BUS_USB;
+	input_dev->id.vendor = cinergyt2->udev->descriptor.idVendor;
+	input_dev->id.product = cinergyt2->udev->descriptor.idProduct;
+	input_dev->id.version = 1;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
+	input_dev->cdev.dev = &cinergyt2->udev->dev;
+#else
+	input_dev->dev = &cinergyt2->udev->dev;
+#endif
+
+	err = input_register_device(input_dev);
+	if (err) {
+		input_free_device(input_dev);
+		return err;
+	}
+
+	cinergyt2->rc_input_dev = input_dev;
+	schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2);
+	return 0;
+}
+#endif
+
+// static void cinergyt2_unregister_rc(struct cinergyt2 *cinergyt2)
+// {
+//	cancel_delayed_work(&cinergyt2->rc_query_work);
+//	input_unregister_device(cinergyt2->rc_input_dev);
+// }
+
+// static inline void cinergyt2_suspend_rc(struct cinergyt2 *cinergyt2)
+// {
+//	cancel_delayed_work(&cinergyt2->rc_query_work);
+// }
+
+// static inline void cinergyt2_resume_rc(struct cinergyt2 *cinergyt2)
+// {
+//	schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2);
+// }
+
+
+
+// EXPORT_SYMBOL(cinergyt2_rc_keys);
+// EXPORT_SYMBOL(cinergyt2_rc_query);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 18f323a05fbe linux/drivers/media/dvb/dvb-usb/cinergyT2.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linux/drivers/media/dvb/dvb-usb/cinergyT2.h	Sun Sep 16 13:37:25 2007 +0300
@@ -0,0 +1,65 @@
+
+#ifndef _DVB_USB_CINERGYT2_H_
+#define _DVB_USB_CINERGYT2_H_
+
+#define DVB_USB_LOG_PREFIX "cinergyT2"
+#define CONFIG_DVB_USB_DEBUG 1
+#include "dvb-usb.h"
+
+#define DRIVER_NAME "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver"
+
+extern int dvb_usb_cinergyt2_debug;
+#define deb_info(args...) dprintk(dvb_usb_cinergyt2_debug,0x01,args)
+#define deb_xfer(args...) dprintk(dvb_usb_cinergyt2_debug,0x02,args)
+#define deb_rc(args...)   dprintk(dvb_usb_cinergyt2_debug,0x04,args)
+
+
+enum cinergyt2_ep1_cmd {
+	CINERGYT2_EP1_PID_TABLE_RESET		= 0x01,
+	CINERGYT2_EP1_PID_SETUP			= 0x02,
+	CINERGYT2_EP1_CONTROL_STREAM_TRANSFER	= 0x03,
+	CINERGYT2_EP1_SET_TUNER_PARAMETERS	= 0x04,
+	CINERGYT2_EP1_GET_TUNER_STATUS		= 0x05,
+	CINERGYT2_EP1_START_SCAN		= 0x06,
+	CINERGYT2_EP1_CONTINUE_SCAN		= 0x07,
+	CINERGYT2_EP1_GET_RC_EVENTS		= 0x08,
+	CINERGYT2_EP1_SLEEP_MODE		= 0x09,
+	CINERGYT2_EP1_GET_FIRMWARE_VERSION	= 0x0A
+};
+
+
+struct dvbt_get_status_msg {
+	uint32_t freq;
+	uint8_t bandwidth;
+	uint16_t tps;
+	uint8_t flags;
+	uint16_t gain;
+	uint8_t snr;
+	uint32_t viterbi_error_rate;
+	uint32_t rs_error_rate;
+	uint32_t uncorrected_block_count;
+	uint8_t lock_bits;
+	uint8_t prev_lock_bits;
+} __attribute__((packed));
+
+
+struct dvbt_set_parameters_msg {
+	uint8_t cmd;
+	uint32_t freq;
+	uint8_t bandwidth;
+	uint16_t tps;
+	uint8_t flags;
+} __attribute__((packed));
+
+
+extern struct dvb_usb_rc_key cinergyt2_rc_keys[];
+extern int cinergyt2_rc_keys_size;
+
+
+extern struct dvb_frontend * cinergyt2_fe_attach(struct dvb_usb_device *d);
+extern int cinergyt2_command(struct dvb_usb_device *d, char *send_buf, int send_buf_len, char *recv_buf, int recv_buf_len, int msec);
+extern int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state);
+
+
+
+#endif /* _DVB_USB_CINERGYT2_H_ */
_______________________________________________
linux-dvb mailing list
linux-dvb@linuxtv.org
http://www.linuxtv.org/cgi-bin/mailman/listinfo/linux-dvb

Reply via email to