Path: blob/master/drivers/media/dvb/dvb-usb/cinergyT2-core.c
15112 views
/*1* TerraTec Cinergy T2/qanu USB2 DVB-T adapter.2*3* Copyright (C) 2007 Tomi Orava ([email protected])4*5* Based on the dvb-usb-framework code and the6* original Terratec Cinergy T2 driver by:7*8* Copyright (C) 2004 Daniel Mack <[email protected]> and9* Holger Waechtler <[email protected]>10*11* Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf12*13* This program is free software; you can redistribute it and/or modify14* it under the terms of the GNU General Public License as published by15* the Free Software Foundation; either version 2 of the License, or16* (at your option) any later version.17*18* This program is distributed in the hope that it will be useful,19* but WITHOUT ANY WARRANTY; without even the implied warranty of20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the21* GNU General Public License for more details.22*23* You should have received a copy of the GNU General Public License24* along with this program; if not, write to the Free Software25* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.26*27*/2829#include "cinergyT2.h"303132/* debug */33int dvb_usb_cinergyt2_debug;3435module_param_named(debug, dvb_usb_cinergyt2_debug, int, 0644);36MODULE_PARM_DESC(debug, "set debugging level (1=info, xfer=2, rc=4 "37"(or-able)).");3839DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);4041struct cinergyt2_state {42u8 rc_counter;43};4445/* We are missing a release hook with usb_device data */46static struct dvb_usb_device *cinergyt2_usb_device;4748static struct dvb_usb_device_properties cinergyt2_properties;4950static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)51{52char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };53char result[64];54return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,55sizeof(result), 0);56}5758static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)59{60char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };61char state[3];62return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);63}6465static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)66{67char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };68char state[3];69int ret;7071adap->fe = cinergyt2_fe_attach(adap->dev);7273ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,74sizeof(state), 0);75if (ret < 0) {76deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "77"state info\n");78}7980/* Copy this pointer as we are gonna need it in the release phase */81cinergyt2_usb_device = adap->dev;8283return 0;84}8586static struct rc_map_table rc_map_cinergyt2_table[] = {87{ 0x0401, KEY_POWER },88{ 0x0402, KEY_1 },89{ 0x0403, KEY_2 },90{ 0x0404, KEY_3 },91{ 0x0405, KEY_4 },92{ 0x0406, KEY_5 },93{ 0x0407, KEY_6 },94{ 0x0408, KEY_7 },95{ 0x0409, KEY_8 },96{ 0x040a, KEY_9 },97{ 0x040c, KEY_0 },98{ 0x040b, KEY_VIDEO },99{ 0x040d, KEY_REFRESH },100{ 0x040e, KEY_SELECT },101{ 0x040f, KEY_EPG },102{ 0x0410, KEY_UP },103{ 0x0414, KEY_DOWN },104{ 0x0411, KEY_LEFT },105{ 0x0413, KEY_RIGHT },106{ 0x0412, KEY_OK },107{ 0x0415, KEY_TEXT },108{ 0x0416, KEY_INFO },109{ 0x0417, KEY_RED },110{ 0x0418, KEY_GREEN },111{ 0x0419, KEY_YELLOW },112{ 0x041a, KEY_BLUE },113{ 0x041c, KEY_VOLUMEUP },114{ 0x041e, KEY_VOLUMEDOWN },115{ 0x041d, KEY_MUTE },116{ 0x041b, KEY_CHANNELUP },117{ 0x041f, KEY_CHANNELDOWN },118{ 0x0440, KEY_PAUSE },119{ 0x044c, KEY_PLAY },120{ 0x0458, KEY_RECORD },121{ 0x0454, KEY_PREVIOUS },122{ 0x0448, KEY_STOP },123{ 0x045c, KEY_NEXT }124};125126/* Number of keypresses to ignore before detect repeating */127#define RC_REPEAT_DELAY 3128129static int repeatable_keys[] = {130KEY_UP,131KEY_DOWN,132KEY_LEFT,133KEY_RIGHT,134KEY_VOLUMEUP,135KEY_VOLUMEDOWN,136KEY_CHANNELUP,137KEY_CHANNELDOWN138};139140static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)141{142struct cinergyt2_state *st = d->priv;143u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;144int i;145146*state = REMOTE_NO_KEY_PRESSED;147148dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);149if (key[4] == 0xff) {150/* key repeat */151st->rc_counter++;152if (st->rc_counter > RC_REPEAT_DELAY) {153for (i = 0; i < ARRAY_SIZE(repeatable_keys); i++) {154if (d->last_event == repeatable_keys[i]) {155*state = REMOTE_KEY_REPEAT;156*event = d->last_event;157deb_rc("repeat key, event %x\n",158*event);159return 0;160}161}162deb_rc("repeated key (non repeatable)\n");163}164return 0;165}166167/* hack to pass checksum on the custom field */168key[2] = ~key[1];169dvb_usb_nec_rc_key_to_event(d, key, event, state);170if (key[0] != 0) {171if (*event != d->last_event)172st->rc_counter = 0;173174deb_rc("key: %x %x %x %x %x\n",175key[0], key[1], key[2], key[3], key[4]);176}177return 0;178}179180static int cinergyt2_usb_probe(struct usb_interface *intf,181const struct usb_device_id *id)182{183return dvb_usb_device_init(intf, &cinergyt2_properties,184THIS_MODULE, NULL, adapter_nr);185}186187188static struct usb_device_id cinergyt2_usb_table[] = {189{ USB_DEVICE(USB_VID_TERRATEC, 0x0038) },190{ 0 }191};192193MODULE_DEVICE_TABLE(usb, cinergyt2_usb_table);194195static struct dvb_usb_device_properties cinergyt2_properties = {196.size_of_priv = sizeof(struct cinergyt2_state),197.num_adapters = 1,198.adapter = {199{200.streaming_ctrl = cinergyt2_streaming_ctrl,201.frontend_attach = cinergyt2_frontend_attach,202203/* parameter for the MPEG2-data transfer */204.stream = {205.type = USB_BULK,206.count = 5,207.endpoint = 0x02,208.u = {209.bulk = {210.buffersize = 512,211}212}213},214}215},216217.power_ctrl = cinergyt2_power_ctrl,218219.rc.legacy = {220.rc_interval = 50,221.rc_map_table = rc_map_cinergyt2_table,222.rc_map_size = ARRAY_SIZE(rc_map_cinergyt2_table),223.rc_query = cinergyt2_rc_query,224},225226.generic_bulk_ctrl_endpoint = 1,227228.num_device_descs = 1,229.devices = {230{ .name = "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver",231.cold_ids = {NULL},232.warm_ids = { &cinergyt2_usb_table[0], NULL },233},234{ NULL },235}236};237238239static struct usb_driver cinergyt2_driver = {240.name = "cinergyT2",241.probe = cinergyt2_usb_probe,242.disconnect = dvb_usb_device_exit,243.id_table = cinergyt2_usb_table244};245246static int __init cinergyt2_usb_init(void)247{248int err;249250err = usb_register(&cinergyt2_driver);251if (err) {252err("usb_register() failed! (err %i)\n", err);253return err;254}255return 0;256}257258static void __exit cinergyt2_usb_exit(void)259{260usb_deregister(&cinergyt2_driver);261}262263module_init(cinergyt2_usb_init);264module_exit(cinergyt2_usb_exit);265266MODULE_DESCRIPTION("Terratec Cinergy T2 DVB-T driver");267MODULE_LICENSE("GPL");268MODULE_AUTHOR("Tomi Orava");269270271