aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/dvb-usb/cinergyT2-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/dvb/dvb-usb/cinergyT2-core.c')
-rw-r--r--drivers/media/dvb/dvb-usb/cinergyT2-core.c230
1 files changed, 230 insertions, 0 deletions
diff --git a/drivers/media/dvb/dvb-usb/cinergyT2-core.c b/drivers/media/dvb/dvb-usb/cinergyT2-core.c
new file mode 100644
index 00000000000..25863033c48
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/cinergyT2-core.c
@@ -0,0 +1,230 @@
1/*
2 * TerraTec Cinergy T2/qanu USB2 DVB-T adapter.
3 *
4 * Copyright (C) 2007 Tomi Orava (tomimo@ncircle.nullnet.fi)
5 *
6 * Based on the dvb-usb-framework code and the
7 * original Terratec Cinergy T2 driver by:
8 *
9 * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and
10 * Holger Waechtler <holger@qanu.de>
11 *
12 * Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
13 *
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.
18 *
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.
23 *
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.
27 *
28 */
29
30#include "cinergyT2.h"
31
32
33/* debug */
34int dvb_usb_cinergyt2_debug;
35int disable_remote;
36
37module_param_named(debug, dvb_usb_cinergyt2_debug, int, 0644);
38MODULE_PARM_DESC(debug, "set debugging level (1=info, xfer=2, rc=4 "
39 "(or-able)).");
40
41DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
42
43
44/* We are missing a release hook with usb_device data */
45struct dvb_usb_device *cinergyt2_usb_device;
46
47static struct dvb_usb_device_properties cinergyt2_properties;
48
49static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
50{
51 char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
52 char result[64];
53 return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
54 sizeof(result), 0);
55}
56
57static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
58{
59 char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
60 char state[3];
61 return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
62}
63
64static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
65{
66 char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
67 char state[3];
68 int ret;
69
70 adap->fe = cinergyt2_fe_attach(adap->dev);
71
72 ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
73 sizeof(state), 0);
74 if (ret < 0) {
75 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
76 "state info\n");
77 }
78
79 /* Copy this pointer as we are gonna need it in the release phase */
80 cinergyt2_usb_device = adap->dev;
81
82 return 0;
83}
84
85static struct dvb_usb_rc_key cinergyt2_rc_keys[] = {
86 { 0x04, 0x01, KEY_POWER },
87 { 0x04, 0x02, KEY_1 },
88 { 0x04, 0x03, KEY_2 },
89 { 0x04, 0x04, KEY_3 },
90 { 0x04, 0x05, KEY_4 },
91 { 0x04, 0x06, KEY_5 },
92 { 0x04, 0x07, KEY_6 },
93 { 0x04, 0x08, KEY_7 },
94 { 0x04, 0x09, KEY_8 },
95 { 0x04, 0x0a, KEY_9 },
96 { 0x04, 0x0c, KEY_0 },
97 { 0x04, 0x0b, KEY_VIDEO },
98 { 0x04, 0x0d, KEY_REFRESH },
99 { 0x04, 0x0e, KEY_SELECT },
100 { 0x04, 0x0f, KEY_EPG },
101 { 0x04, 0x10, KEY_UP },
102 { 0x04, 0x14, KEY_DOWN },
103 { 0x04, 0x11, KEY_LEFT },
104 { 0x04, 0x13, KEY_RIGHT },
105 { 0x04, 0x12, KEY_OK },
106 { 0x04, 0x15, KEY_TEXT },
107 { 0x04, 0x16, KEY_INFO },
108 { 0x04, 0x17, KEY_RED },
109 { 0x04, 0x18, KEY_GREEN },
110 { 0x04, 0x19, KEY_YELLOW },
111 { 0x04, 0x1a, KEY_BLUE },
112 { 0x04, 0x1c, KEY_VOLUMEUP },
113 { 0x04, 0x1e, KEY_VOLUMEDOWN },
114 { 0x04, 0x1d, KEY_MUTE },
115 { 0x04, 0x1b, KEY_CHANNELUP },
116 { 0x04, 0x1f, KEY_CHANNELDOWN },
117 { 0x04, 0x40, KEY_PAUSE },
118 { 0x04, 0x4c, KEY_PLAY },
119 { 0x04, 0x58, KEY_RECORD },
120 { 0x04, 0x54, KEY_PREVIOUS },
121 { 0x04, 0x48, KEY_STOP },
122 { 0x04, 0x5c, KEY_NEXT }
123};
124
125static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
126{
127 u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
128 *state = REMOTE_NO_KEY_PRESSED;
129
130 dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
131 if (key[4] == 0xff)
132 return 0;
133
134 /* hack to pass checksum on the custom field (is set to 0xeb) */
135 key[2] = ~0x04;
136 dvb_usb_nec_rc_key_to_event(d, key, event, state);
137 if (key[0] != 0)
138 deb_info("key: %x %x %x %x %x\n",
139 key[0], key[1], key[2], key[3], key[4]);
140
141 return 0;
142}
143
144static int cinergyt2_usb_probe(struct usb_interface *intf,
145 const struct usb_device_id *id)
146{
147 return dvb_usb_device_init(intf, &cinergyt2_properties,
148 THIS_MODULE, NULL, adapter_nr);
149}
150
151
152static struct usb_device_id cinergyt2_usb_table[] = {
153 { USB_DEVICE(USB_VID_TERRATEC, 0x0038) },
154 { 0 }
155};
156
157MODULE_DEVICE_TABLE(usb, cinergyt2_usb_table);
158
159static struct dvb_usb_device_properties cinergyt2_properties = {
160
161 .num_adapters = 1,
162 .adapter = {
163 {
164 .streaming_ctrl = cinergyt2_streaming_ctrl,
165 .frontend_attach = cinergyt2_frontend_attach,
166
167 /* parameter for the MPEG2-data transfer */
168 .stream = {
169 .type = USB_BULK,
170 .count = 5,
171 .endpoint = 0x02,
172 .u = {
173 .bulk = {
174 .buffersize = 512,
175 }
176 }
177 },
178 }
179 },
180
181 .power_ctrl = cinergyt2_power_ctrl,
182
183 .rc_interval = 50,
184 .rc_key_map = cinergyt2_rc_keys,
185 .rc_key_map_size = ARRAY_SIZE(cinergyt2_rc_keys),
186 .rc_query = cinergyt2_rc_query,
187
188 .generic_bulk_ctrl_endpoint = 1,
189
190 .num_device_descs = 1,
191 .devices = {
192 { .name = "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver",
193 .cold_ids = {NULL},
194 .warm_ids = { &cinergyt2_usb_table[0], NULL },
195 },
196 { NULL },
197 }
198};
199
200
201static struct usb_driver cinergyt2_driver = {
202 .name = "cinergyT2",
203 .probe = cinergyt2_usb_probe,
204 .disconnect = dvb_usb_device_exit,
205 .id_table = cinergyt2_usb_table
206};
207
208static int __init cinergyt2_usb_init(void)
209{
210 int err;
211
212 err = usb_register(&cinergyt2_driver);
213 if (err) {
214 err("usb_register() failed! (err %i)\n", err);
215 return err;
216 }
217 return 0;
218}
219
220static void __exit cinergyt2_usb_exit(void)
221{
222 usb_deregister(&cinergyt2_driver);
223}
224
225module_init(cinergyt2_usb_init);
226module_exit(cinergyt2_usb_exit);
227
228MODULE_DESCRIPTION("Terratec Cinergy T2 DVB-T driver");
229MODULE_LICENSE("GPL");
230MODULE_AUTHOR("Tomi Orava");