1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#include "cinergyT2.h"
31
32
33
34int dvb_usb_cinergyt2_debug;
35
36module_param_named(debug, dvb_usb_cinergyt2_debug, int, 0644);
37MODULE_PARM_DESC(debug, "set debugging level (1=info, xfer=2, rc=4 "
38 "(or-able)).");
39
40DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
41
42struct cinergyt2_state {
43 u8 rc_counter;
44};
45
46
47static struct dvb_usb_device *cinergyt2_usb_device;
48
49static struct dvb_usb_device_properties cinergyt2_properties;
50
51static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
52{
53 char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
54 char result[64];
55 return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
56 sizeof(result), 0);
57}
58
59static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
60{
61 char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
62 char state[3];
63 return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
64}
65
66static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
67{
68 char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
69 char state[3];
70 int ret;
71
72 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
73
74 ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
75 sizeof(state), 0);
76 if (ret < 0) {
77 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
78 "state info\n");
79 }
80
81
82 cinergyt2_usb_device = adap->dev;
83
84 return 0;
85}
86
87static struct rc_map_table rc_map_cinergyt2_table[] = {
88 { 0x0401, KEY_POWER },
89 { 0x0402, KEY_1 },
90 { 0x0403, KEY_2 },
91 { 0x0404, KEY_3 },
92 { 0x0405, KEY_4 },
93 { 0x0406, KEY_5 },
94 { 0x0407, KEY_6 },
95 { 0x0408, KEY_7 },
96 { 0x0409, KEY_8 },
97 { 0x040a, KEY_9 },
98 { 0x040c, KEY_0 },
99 { 0x040b, KEY_VIDEO },
100 { 0x040d, KEY_REFRESH },
101 { 0x040e, KEY_SELECT },
102 { 0x040f, KEY_EPG },
103 { 0x0410, KEY_UP },
104 { 0x0414, KEY_DOWN },
105 { 0x0411, KEY_LEFT },
106 { 0x0413, KEY_RIGHT },
107 { 0x0412, KEY_OK },
108 { 0x0415, KEY_TEXT },
109 { 0x0416, KEY_INFO },
110 { 0x0417, KEY_RED },
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 },
124 { 0x045c, KEY_NEXT }
125};
126
127
128#define RC_REPEAT_DELAY 3
129
130static int repeatable_keys[] = {
131 KEY_UP,
132 KEY_DOWN,
133 KEY_LEFT,
134 KEY_RIGHT,
135 KEY_VOLUMEUP,
136 KEY_VOLUMEDOWN,
137 KEY_CHANNELUP,
138 KEY_CHANNELDOWN
139};
140
141static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
142{
143 struct cinergyt2_state *st = d->priv;
144 u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
145 int i;
146
147 *state = REMOTE_NO_KEY_PRESSED;
148
149 dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
150 if (key[4] == 0xff) {
151
152 st->rc_counter++;
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",
159 *event);
160 return 0;
161 }
162 }
163 deb_rc("repeated key (non repeatable)\n");
164 }
165 return 0;
166 }
167
168
169 key[2] = ~key[1];
170 dvb_usb_nec_rc_key_to_event(d, key, event, state);
171 if (key[0] != 0) {
172 if (*event != d->last_event)
173 st->rc_counter = 0;
174
175 deb_rc("key: %*ph\n", 5, key);
176 }
177 return 0;
178}
179
180static int cinergyt2_usb_probe(struct usb_interface *intf,
181 const struct usb_device_id *id)
182{
183 return dvb_usb_device_init(intf, &cinergyt2_properties,
184 THIS_MODULE, NULL, adapter_nr);
185}
186
187
188static struct usb_device_id cinergyt2_usb_table[] = {
189 { USB_DEVICE(USB_VID_TERRATEC, 0x0038) },
190 { 0 }
191};
192
193MODULE_DEVICE_TABLE(usb, cinergyt2_usb_table);
194
195static struct dvb_usb_device_properties cinergyt2_properties = {
196 .size_of_priv = sizeof(struct cinergyt2_state),
197 .num_adapters = 1,
198 .adapter = {
199 {
200 .num_frontends = 1,
201 .fe = {{
202 .streaming_ctrl = cinergyt2_streaming_ctrl,
203 .frontend_attach = cinergyt2_frontend_attach,
204
205
206 .stream = {
207 .type = USB_BULK,
208 .count = 5,
209 .endpoint = 0x02,
210 .u = {
211 .bulk = {
212 .buffersize = 512,
213 }
214 }
215 },
216 }},
217 }
218 },
219
220 .power_ctrl = cinergyt2_power_ctrl,
221
222 .rc.legacy = {
223 .rc_interval = 50,
224 .rc_map_table = rc_map_cinergyt2_table,
225 .rc_map_size = ARRAY_SIZE(rc_map_cinergyt2_table),
226 .rc_query = cinergyt2_rc_query,
227 },
228
229 .generic_bulk_ctrl_endpoint = 1,
230
231 .num_device_descs = 1,
232 .devices = {
233 { .name = "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver",
234 .cold_ids = {NULL},
235 .warm_ids = { &cinergyt2_usb_table[0], NULL },
236 },
237 { NULL },
238 }
239};
240
241
242static struct usb_driver cinergyt2_driver = {
243 .name = "cinergyT2",
244 .probe = cinergyt2_usb_probe,
245 .disconnect = dvb_usb_device_exit,
246 .id_table = cinergyt2_usb_table
247};
248
249module_usb_driver(cinergyt2_driver);
250
251MODULE_DESCRIPTION("Terratec Cinergy T2 DVB-T driver");
252MODULE_LICENSE("GPL");
253MODULE_AUTHOR("Tomi Orava");
254