/*
* TerraTec Cinergy T�/qanu USB2 DVB-T adapter.
*
* Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and
* Holger Waechtler <holger@qanu.de>
*
* 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 <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/usb.h>
#include <linux/pci.h>
#include <linux/input.h>
#include <linux/dvb/frontend.h>
#include <linux/mutex.h>
#include "dmxdev.h"
#include "dvb_demux.h"
#include "dvb_net.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
#define DRIVER_NAME "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver"
static int debug;
module_param_named(debug, debug, int, 0644);
MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
#define dprintk(level, args...) \
do { \
if ((debug & level)) { \
printk("%s: %s(): ", KBUILD_MODNAME, \
__FUNCTION__); \
printk(args); } \
} while (0)
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
};
struct dvbt_set_parameters_msg {
uint8_t cmd;
uint32_t freq;
uint8_t bandwidth;
uint16_t tps;
uint8_t flags;
} __attribute__((packed));
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));
static struct dvb_frontend_info cinergyt2_fe_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
};
struct cinergyt2 {
struct dvb_demux demux;
struct usb_device *udev;
struct mutex sem;
struct dvb_adapter adapter;
struct dvb_device *fedev;
struct dmxdev dmxdev;
struct dvb_net dvbnet;
int streaming;
int sleeping;
struct dvbt_set_parameters_msg param;
struct dvbt_get_status_msg status;
struct delayed_work query_work;
wait_queue_head_t poll_wq;
int pending_fe_events;
int disconnect_pending;
atomic_t inuse;
void *streambuf;
dma_addr_t streambuf_dmahandle;
struct urb *stream_urb [STREAM_URB_COUNT];
#ifdef ENABLE_RC
struct input_dev *rc_input_dev;
char phys[64];
struct delayed_work rc_query_work;
int rc_input_event;
u32 rc_last_code;
unsigned long last_event_jiffies;
#endif
};
enum {
CINERGYT2_RC_EVENT_TYPE_NONE = 0x00,
CINERGYT2_RC_EVENT_TYPE_NEC = 0x01,
CINERGYT2_RC_EVENT_TYPE_RC5 = 0x02
};
struct cinergyt2_rc_event {
char type;
uint32_t value;
} __attribute__((packed));
static const uint32_t 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