2 * TerraTec Cinergy T2/qanu USB2 DVB-T adapter.
4 * Copyright (C) 2007 Tomi Orava (tomimo@ncircle.nullnet.fi)
6 * Based on the dvb-usb-framework code and the
7 * original Terratec Cinergy T2 driver by:
9 * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and
10 * Holger Waechtler <holger@qanu.de>
12 * Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include "cinergyT2.h"
34 int dvb_usb_cinergyt2_debug
;
36 module_param_named(debug
, dvb_usb_cinergyt2_debug
, int, 0644);
37 MODULE_PARM_DESC(debug
, "set debugging level (1=info, xfer=2, rc=4 "
40 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
42 struct cinergyt2_state
{
46 /* We are missing a release hook with usb_device data */
47 static struct dvb_usb_device
*cinergyt2_usb_device
;
49 static struct dvb_usb_device_properties cinergyt2_properties
;
51 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter
*adap
, int enable
)
53 char buf
[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER
, enable
? 1 : 0 };
55 return dvb_usb_generic_rw(adap
->dev
, buf
, sizeof(buf
), result
,
59 static int cinergyt2_power_ctrl(struct dvb_usb_device
*d
, int enable
)
61 char buf
[] = { CINERGYT2_EP1_SLEEP_MODE
, enable
? 0 : 1 };
63 return dvb_usb_generic_rw(d
, buf
, sizeof(buf
), state
, sizeof(state
), 0);
66 static int cinergyt2_frontend_attach(struct dvb_usb_adapter
*adap
)
68 char query
[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION
};
72 adap
->fe_adap
[0].fe
= cinergyt2_fe_attach(adap
->dev
);
74 ret
= dvb_usb_generic_rw(adap
->dev
, query
, sizeof(query
), state
,
77 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
81 /* Copy this pointer as we are gonna need it in the release phase */
82 cinergyt2_usb_device
= adap
->dev
;
87 static struct rc_map_table rc_map_cinergyt2_table
[] = {
88 { 0x0401, KEY_POWER
},
99 { 0x040b, KEY_VIDEO
},
100 { 0x040d, KEY_REFRESH
},
101 { 0x040e, KEY_SELECT
},
104 { 0x0414, KEY_DOWN
},
105 { 0x0411, KEY_LEFT
},
106 { 0x0413, KEY_RIGHT
},
108 { 0x0415, KEY_TEXT
},
109 { 0x0416, KEY_INFO
},
111 { 0x0418, KEY_GREEN
},
112 { 0x0419, KEY_YELLOW
},
113 { 0x041a, KEY_BLUE
},
114 { 0x041c, KEY_VOLUMEUP
},
115 { 0x041e, KEY_VOLUMEDOWN
},
116 { 0x041d, KEY_MUTE
},
117 { 0x041b, KEY_CHANNELUP
},
118 { 0x041f, KEY_CHANNELDOWN
},
119 { 0x0440, KEY_PAUSE
},
120 { 0x044c, KEY_PLAY
},
121 { 0x0458, KEY_RECORD
},
122 { 0x0454, KEY_PREVIOUS
},
123 { 0x0448, KEY_STOP
},
127 /* Number of keypresses to ignore before detect repeating */
128 #define RC_REPEAT_DELAY 3
130 static int repeatable_keys
[] = {
141 static int cinergyt2_rc_query(struct dvb_usb_device
*d
, u32
*event
, int *state
)
143 struct cinergyt2_state
*st
= d
->priv
;
144 u8 key
[5] = {0, 0, 0, 0, 0}, cmd
= CINERGYT2_EP1_GET_RC_EVENTS
;
147 *state
= REMOTE_NO_KEY_PRESSED
;
149 dvb_usb_generic_rw(d
, &cmd
, 1, key
, sizeof(key
), 0);
150 if (key
[4] == 0xff) {
153 if (st
->rc_counter
> RC_REPEAT_DELAY
) {
154 for (i
= 0; i
< ARRAY_SIZE(repeatable_keys
); i
++) {
155 if (d
->last_event
== repeatable_keys
[i
]) {
156 *state
= REMOTE_KEY_REPEAT
;
157 *event
= d
->last_event
;
158 deb_rc("repeat key, event %x\n",
163 deb_rc("repeated key (non repeatable)\n");
168 /* hack to pass checksum on the custom field */
170 dvb_usb_nec_rc_key_to_event(d
, key
, event
, state
);
172 if (*event
!= d
->last_event
)
175 deb_rc("key: %*ph\n", 5, key
);
180 static int cinergyt2_usb_probe(struct usb_interface
*intf
,
181 const struct usb_device_id
*id
)
183 return dvb_usb_device_init(intf
, &cinergyt2_properties
,
184 THIS_MODULE
, NULL
, adapter_nr
);
188 static struct usb_device_id cinergyt2_usb_table
[] = {
189 { USB_DEVICE(USB_VID_TERRATEC
, 0x0038) },
193 MODULE_DEVICE_TABLE(usb
, cinergyt2_usb_table
);
195 static struct dvb_usb_device_properties cinergyt2_properties
= {
196 .size_of_priv
= sizeof(struct cinergyt2_state
),
202 .streaming_ctrl
= cinergyt2_streaming_ctrl
,
203 .frontend_attach
= cinergyt2_frontend_attach
,
205 /* parameter for the MPEG2-data transfer */
220 .power_ctrl
= cinergyt2_power_ctrl
,
224 .rc_map_table
= rc_map_cinergyt2_table
,
225 .rc_map_size
= ARRAY_SIZE(rc_map_cinergyt2_table
),
226 .rc_query
= cinergyt2_rc_query
,
229 .generic_bulk_ctrl_endpoint
= 1,
231 .num_device_descs
= 1,
233 { .name
= "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver",
235 .warm_ids
= { &cinergyt2_usb_table
[0], NULL
},
242 static struct usb_driver cinergyt2_driver
= {
244 .probe
= cinergyt2_usb_probe
,
245 .disconnect
= dvb_usb_device_exit
,
246 .id_table
= cinergyt2_usb_table
249 module_usb_driver(cinergyt2_driver
);
251 MODULE_DESCRIPTION("Terratec Cinergy T2 DVB-T driver");
252 MODULE_LICENSE("GPL");
253 MODULE_AUTHOR("Tomi Orava");