Diff markup
1 /* DVB USB compliant Linux driver for the Twin 1 /* DVB USB compliant Linux driver for the TwinhanDTV StarBox USB2.0 DVB-S
2 * receiver. 2 * receiver.
3 * 3 *
4 * Copyright (C) 2005 Ralph Metzler <rjkm@metz 4 * Copyright (C) 2005 Ralph Metzler <rjkm@metzlerbros.de>
5 * Metzler Brothers Systeme 5 * Metzler Brothers Systementwicklung GbR
6 * 6 *
7 * Copyright (C) 2005 Patrick Boettcher <patri 7 * Copyright (C) 2005 Patrick Boettcher <patrick.boettcher@desy.de>
8 * 8 *
9 * Thanks to Twinhan who kindly provided hardw 9 * Thanks to Twinhan who kindly provided hardware and information.
10 * 10 *
11 * This program is free software; you can 11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Pub 12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation, version 2. 13 * Software Foundation, version 2.
14 * 14 *
15 * see Documentation/dvb/README.dvb-usb for mo 15 * see Documentation/dvb/README.dvb-usb for more information
16 */ 16 */
17 #include "vp702x.h" 17 #include "vp702x.h"
18 18
19 /* debug */ 19 /* debug */
20 int dvb_usb_vp702x_debug; 20 int dvb_usb_vp702x_debug;
21 module_param_named(debug,dvb_usb_vp702x_debug, 21 module_param_named(debug,dvb_usb_vp702x_debug, int, 0644);
22 MODULE_PARM_DESC(debug, "set debugging level ( 22 MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
23 23
>> 24 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
>> 25
24 struct vp702x_state { 26 struct vp702x_state {
25 int pid_filter_count; 27 int pid_filter_count;
26 int pid_filter_can_bypass; 28 int pid_filter_can_bypass;
27 u8 pid_filter_state; 29 u8 pid_filter_state;
28 }; 30 };
29 31
30 struct vp702x_device_state { 32 struct vp702x_device_state {
31 u8 power_state; 33 u8 power_state;
32 }; 34 };
33 35
34 /* check for mutex FIXME */ 36 /* check for mutex FIXME */
35 int vp702x_usb_in_op(struct dvb_usb_device *d, 37 int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen)
36 { 38 {
37 int ret = -1; 39 int ret = -1;
38 40
39 ret = usb_control_msg(d->udev, 41 ret = usb_control_msg(d->udev,
40 usb_rcvctrlpipe(d->ude 42 usb_rcvctrlpipe(d->udev,0),
41 req, 43 req,
42 USB_TYPE_VENDOR | USB_ 44 USB_TYPE_VENDOR | USB_DIR_IN,
43 value,index,b,blen, 45 value,index,b,blen,
44 2000); 46 2000);
45 47
46 if (ret < 0) { 48 if (ret < 0) {
47 warn("usb in operation failed. 49 warn("usb in operation failed. (%d)", ret);
48 ret = -EIO; 50 ret = -EIO;
49 } else 51 } else
50 ret = 0; 52 ret = 0;
51 53
52 54
53 deb_xfer("in: req. %02x, val: %04x, in 55 deb_xfer("in: req. %02x, val: %04x, ind: %04x, buffer: ",req,value,index);
54 debug_dump(b,blen,deb_xfer); 56 debug_dump(b,blen,deb_xfer);
55 57
56 return ret; 58 return ret;
57 } 59 }
58 60
59 static int vp702x_usb_out_op(struct dvb_usb_de 61 static int vp702x_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
60 u16 index, u8 *b, 62 u16 index, u8 *b, int blen)
61 { 63 {
62 int ret; 64 int ret;
63 deb_xfer("out: req. %02x, val: %04x, i 65 deb_xfer("out: req. %02x, val: %04x, ind: %04x, buffer: ",req,value,index);
64 debug_dump(b,blen,deb_xfer); 66 debug_dump(b,blen,deb_xfer);
65 67
66 if ((ret = usb_control_msg(d->udev, 68 if ((ret = usb_control_msg(d->udev,
67 usb_sndctrlpipe(d->ude 69 usb_sndctrlpipe(d->udev,0),
68 req, 70 req,
69 USB_TYPE_VENDOR | USB_ 71 USB_TYPE_VENDOR | USB_DIR_OUT,
70 value,index,b,blen, 72 value,index,b,blen,
71 2000)) != blen) { 73 2000)) != blen) {
72 warn("usb out operation failed 74 warn("usb out operation failed. (%d)",ret);
73 return -EIO; 75 return -EIO;
74 } else 76 } else
75 return 0; 77 return 0;
76 } 78 }
77 79
78 int vp702x_usb_inout_op(struct dvb_usb_device 80 int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int ilen, int msec)
79 { 81 {
80 int ret; 82 int ret;
81 83
82 if ((ret = mutex_lock_interruptible(&d 84 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
83 return ret; 85 return ret;
84 86
85 ret = vp702x_usb_out_op(d,REQUEST_OUT, 87 ret = vp702x_usb_out_op(d,REQUEST_OUT,0,0,o,olen);
86 msleep(msec); 88 msleep(msec);
87 ret = vp702x_usb_in_op(d,REQUEST_IN,0, 89 ret = vp702x_usb_in_op(d,REQUEST_IN,0,0,i,ilen);
88 90
89 mutex_unlock(&d->usb_mutex); 91 mutex_unlock(&d->usb_mutex);
90 92
91 return ret; 93 return ret;
92 } 94 }
93 95
94 static int vp702x_usb_inout_cmd(struct dvb_usb 96 static int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o,
95 int olen, u8 * 97 int olen, u8 *i, int ilen, int msec)
96 { 98 {
97 u8 bout[olen+2]; 99 u8 bout[olen+2];
98 u8 bin[ilen+1]; 100 u8 bin[ilen+1];
99 int ret = 0; 101 int ret = 0;
100 102
101 bout[0] = 0x00; 103 bout[0] = 0x00;
102 bout[1] = cmd; 104 bout[1] = cmd;
103 memcpy(&bout[2],o,olen); 105 memcpy(&bout[2],o,olen);
104 106
105 ret = vp702x_usb_inout_op(d, bout, ole 107 ret = vp702x_usb_inout_op(d, bout, olen+2, bin, ilen+1,msec);
106 108
107 if (ret == 0) 109 if (ret == 0)
108 memcpy(i,&bin[1],ilen); 110 memcpy(i,&bin[1],ilen);
109 111
110 return ret; 112 return ret;
111 } 113 }
112 114
113 static int vp702x_set_pld_mode(struct dvb_usb_ 115 static int vp702x_set_pld_mode(struct dvb_usb_adapter *adap, u8 bypass)
114 { 116 {
115 u8 buf[16] = { 0 }; 117 u8 buf[16] = { 0 };
116 return vp702x_usb_in_op(adap->dev, 0xe 118 return vp702x_usb_in_op(adap->dev, 0xe0, (bypass << 8) | 0x0e, 0, buf, 16);
117 } 119 }
118 120
119 static int vp702x_set_pld_state(struct dvb_usb 121 static int vp702x_set_pld_state(struct dvb_usb_adapter *adap, u8 state)
120 { 122 {
121 u8 buf[16] = { 0 }; 123 u8 buf[16] = { 0 };
122 return vp702x_usb_in_op(adap->dev, 0xe 124 return vp702x_usb_in_op(adap->dev, 0xe0, (state << 8) | 0x0f, 0, buf, 16);
123 } 125 }
124 126
125 static int vp702x_set_pid(struct dvb_usb_adapt 127 static int vp702x_set_pid(struct dvb_usb_adapter *adap, u16 pid, u8 id, int onoff)
126 { 128 {
127 struct vp702x_state *st = adap->priv; 129 struct vp702x_state *st = adap->priv;
128 u8 buf[16] = { 0 }; 130 u8 buf[16] = { 0 };
129 131
130 if (onoff) 132 if (onoff)
131 st->pid_filter_state |= (1 << 133 st->pid_filter_state |= (1 << id);
132 else { 134 else {
133 st->pid_filter_state &= ~(1 << 135 st->pid_filter_state &= ~(1 << id);
134 pid = 0xffff; 136 pid = 0xffff;
135 } 137 }
136 138
137 id = 0x10 + id*2; 139 id = 0x10 + id*2;
138 140
139 vp702x_set_pld_state(adap, st->pid_fil 141 vp702x_set_pld_state(adap, st->pid_filter_state);
140 vp702x_usb_in_op(adap->dev, 0xe0, (((p 142 vp702x_usb_in_op(adap->dev, 0xe0, (((pid >> 8) & 0xff) << 8) | (id), 0, buf, 16);
141 vp702x_usb_in_op(adap->dev, 0xe0, (((p 143 vp702x_usb_in_op(adap->dev, 0xe0, (((pid ) & 0xff) << 8) | (id+1), 0, buf, 16);
142 return 0; 144 return 0;
143 } 145 }
144 146
145 147
146 static int vp702x_init_pid_filter(struct dvb_u 148 static int vp702x_init_pid_filter(struct dvb_usb_adapter *adap)
147 { 149 {
148 struct vp702x_state *st = adap->priv; 150 struct vp702x_state *st = adap->priv;
149 int i; 151 int i;
150 u8 b[10] = { 0 }; 152 u8 b[10] = { 0 };
151 153
152 st->pid_filter_count = 8; 154 st->pid_filter_count = 8;
153 st->pid_filter_can_bypass = 1; 155 st->pid_filter_can_bypass = 1;
154 st->pid_filter_state = 0x00; 156 st->pid_filter_state = 0x00;
155 157
156 vp702x_set_pld_mode(adap, 1); // bypas 158 vp702x_set_pld_mode(adap, 1); // bypass
157 159
158 for (i = 0; i < st->pid_filter_count; 160 for (i = 0; i < st->pid_filter_count; i++)
159 vp702x_set_pid(adap, 0xffff, i 161 vp702x_set_pid(adap, 0xffff, i, 1);
160 162
161 vp702x_usb_in_op(adap->dev, 0xb5, 3, 0 163 vp702x_usb_in_op(adap->dev, 0xb5, 3, 0, b, 10);
162 vp702x_usb_in_op(adap->dev, 0xb5, 0, 0 164 vp702x_usb_in_op(adap->dev, 0xb5, 0, 0, b, 10);
163 vp702x_usb_in_op(adap->dev, 0xb5, 1, 0 165 vp702x_usb_in_op(adap->dev, 0xb5, 1, 0, b, 10);
164 166
165 //vp702x_set_pld_mode(d, 0); // filter 167 //vp702x_set_pld_mode(d, 0); // filter
166 return 0; 168 return 0;
167 } 169 }
168 170
169 static int vp702x_streaming_ctrl(struct dvb_us 171 static int vp702x_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
170 { 172 {
171 return 0; 173 return 0;
172 } 174 }
173 175
174 /* keys for the enclosed remote control */ 176 /* keys for the enclosed remote control */
175 static struct dvb_usb_rc_key vp702x_rc_keys[] 177 static struct dvb_usb_rc_key vp702x_rc_keys[] = {
176 { 0x00, 0x01, KEY_1 }, 178 { 0x00, 0x01, KEY_1 },
177 { 0x00, 0x02, KEY_2 }, 179 { 0x00, 0x02, KEY_2 },
178 }; 180 };
179 181
180 /* remote control stuff (does not work with my 182 /* remote control stuff (does not work with my box) */
181 static int vp702x_rc_query(struct dvb_usb_devi 183 static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
182 { 184 {
183 u8 key[10]; 185 u8 key[10];
184 int i; 186 int i;
185 187
186 /* remove the following return to enabled remo 188 /* remove the following return to enabled remote querying */
187 return 0; 189 return 0;
188 190
189 vp702x_usb_in_op(d,READ_REMOTE_REQ,0,0 191 vp702x_usb_in_op(d,READ_REMOTE_REQ,0,0,key,10);
190 192
191 deb_rc("remote query key: %x %d\n",key 193 deb_rc("remote query key: %x %d\n",key[1],key[1]);
192 194
193 if (key[1] == 0x44) { 195 if (key[1] == 0x44) {
194 *state = REMOTE_NO_KEY_PRESSED 196 *state = REMOTE_NO_KEY_PRESSED;
195 return 0; 197 return 0;
196 } 198 }
197 199
198 for (i = 0; i < ARRAY_SIZE(vp702x_rc_k 200 for (i = 0; i < ARRAY_SIZE(vp702x_rc_keys); i++)
199 if (vp702x_rc_keys[i].custom = 201 if (vp702x_rc_keys[i].custom == key[1]) {
200 *state = REMOTE_KEY_PR 202 *state = REMOTE_KEY_PRESSED;
201 *event = vp702x_rc_key 203 *event = vp702x_rc_keys[i].event;
202 break; 204 break;
203 } 205 }
204 return 0; 206 return 0;
205 } 207 }
206 208
207 209
208 static int vp702x_read_mac_addr(struct dvb_usb 210 static int vp702x_read_mac_addr(struct dvb_usb_device *d,u8 mac[6])
209 { 211 {
210 u8 i; 212 u8 i;
211 for (i = 6; i < 12; i++) 213 for (i = 6; i < 12; i++)
212 vp702x_usb_in_op(d, READ_EEPRO 214 vp702x_usb_in_op(d, READ_EEPROM_REQ, i, 1, &mac[i - 6], 1);
213 return 0; 215 return 0;
214 } 216 }
215 217
216 static int vp702x_frontend_attach(struct dvb_u 218 static int vp702x_frontend_attach(struct dvb_usb_adapter *adap)
217 { 219 {
218 u8 buf[10] = { 0 }; 220 u8 buf[10] = { 0 };
219 221
220 vp702x_usb_out_op(adap->dev, SET_TUNER 222 vp702x_usb_out_op(adap->dev, SET_TUNER_POWER_REQ, 0, 7, NULL, 0);
221 223
222 if (vp702x_usb_inout_cmd(adap->dev, GE 224 if (vp702x_usb_inout_cmd(adap->dev, GET_SYSTEM_STRING, NULL, 0, buf, 10, 10))
223 return -EIO; 225 return -EIO;
224 226
225 buf[9] = '\0'; 227 buf[9] = '\0';
226 info("system string: %s",&buf[1]); 228 info("system string: %s",&buf[1]);
227 229
228 vp702x_init_pid_filter(adap); 230 vp702x_init_pid_filter(adap);
229 231
230 adap->fe = vp702x_fe_attach(adap->dev) 232 adap->fe = vp702x_fe_attach(adap->dev);
231 vp702x_usb_out_op(adap->dev, SET_TUNER 233 vp702x_usb_out_op(adap->dev, SET_TUNER_POWER_REQ, 1, 7, NULL, 0);
232 234
233 return 0; 235 return 0;
234 } 236 }
235 237
236 static struct dvb_usb_device_properties vp702x 238 static struct dvb_usb_device_properties vp702x_properties;
237 239
238 static int vp702x_usb_probe(struct usb_interfa 240 static int vp702x_usb_probe(struct usb_interface *intf,
239 const struct usb_device_id *id 241 const struct usb_device_id *id)
240 { 242 {
241 return dvb_usb_device_init(intf,&vp702 !! 243 return dvb_usb_device_init(intf, &vp702x_properties,
>> 244 THIS_MODULE, NULL, adapter_nr);
242 } 245 }
243 246
244 static struct usb_device_id vp702x_usb_table [ 247 static struct usb_device_id vp702x_usb_table [] = {
245 { USB_DEVICE(USB_VID_VISIONPLUS, U 248 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7021_COLD) },
246 // { USB_DEVICE(USB_VID_VISIONPLUS, U 249 // { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7020_COLD) },
247 // { USB_DEVICE(USB_VID_VISIONPLUS, U 250 // { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7020_WARM) },
248 { 0 }, 251 { 0 },
249 }; 252 };
250 MODULE_DEVICE_TABLE(usb, vp702x_usb_table); 253 MODULE_DEVICE_TABLE(usb, vp702x_usb_table);
251 254
252 static struct dvb_usb_device_properties vp702x 255 static struct dvb_usb_device_properties vp702x_properties = {
253 .usb_ctrl = CYPRESS_FX2, 256 .usb_ctrl = CYPRESS_FX2,
254 .firmware = "dvb-usb-vp702x 257 .firmware = "dvb-usb-vp702x-02.fw",
255 .no_reconnect = 1, 258 .no_reconnect = 1,
256 259
257 .size_of_priv = sizeof(struct vp70 260 .size_of_priv = sizeof(struct vp702x_device_state),
258 261
259 .num_adapters = 1, 262 .num_adapters = 1,
260 .adapter = { 263 .adapter = {
261 { 264 {
262 .caps = DV 265 .caps = DVB_USB_ADAP_RECEIVES_204_BYTE_TS,
263 266
264 .streaming_ctrl = vp 267 .streaming_ctrl = vp702x_streaming_ctrl,
265 .frontend_attach = vp 268 .frontend_attach = vp702x_frontend_attach,
266 269
267 /* parameter for the M 270 /* parameter for the MPEG2-data transfer */
268 .stream = { 271 .stream = {
269 .type = USB_BU 272 .type = USB_BULK,
270 .count = 10, 273 .count = 10,
271 .endpoint = 0x 274 .endpoint = 0x02,
272 .u = { 275 .u = {
273 .bulk 276 .bulk = {
274 277 .buffersize = 4096,
275 } 278 }
276 } 279 }
277 }, 280 },
278 .size_of_priv = si 281 .size_of_priv = sizeof(struct vp702x_state),
279 } 282 }
280 }, 283 },
281 .read_mac_address = vp702x_read_mac_ad 284 .read_mac_address = vp702x_read_mac_addr,
282 285
283 .rc_key_map = vp702x_rc_keys, 286 .rc_key_map = vp702x_rc_keys,
284 .rc_key_map_size = ARRAY_SIZE(vp702x_ 287 .rc_key_map_size = ARRAY_SIZE(vp702x_rc_keys),
285 .rc_interval = 400, 288 .rc_interval = 400,
286 .rc_query = vp702x_rc_query, 289 .rc_query = vp702x_rc_query,
287 290
288 .num_device_descs = 1, 291 .num_device_descs = 1,
289 .devices = { 292 .devices = {
290 { .name = "TwinhanDTV StarBox 293 { .name = "TwinhanDTV StarBox DVB-S USB2.0 (VP7021)",
291 .cold_ids = { &vp702x_usb_ta 294 .cold_ids = { &vp702x_usb_table[0], NULL },
292 .warm_ids = { NULL }, 295 .warm_ids = { NULL },
293 }, 296 },
294 /* { .name = "TwinhanDTV StarBox 297 /* { .name = "TwinhanDTV StarBox DVB-S USB2.0 (VP7020)",
295 .cold_ids = { &vp702x_usb_ta 298 .cold_ids = { &vp702x_usb_table[2], NULL },
296 .warm_ids = { &vp702x_usb_ta 299 .warm_ids = { &vp702x_usb_table[3], NULL },
297 }, 300 },
298 */ { NULL }, 301 */ { NULL },
299 } 302 }
300 }; 303 };
301 304
302 /* usb specific object needed to register this 305 /* usb specific object needed to register this driver with the usb subsystem */
303 static struct usb_driver vp702x_usb_driver = { 306 static struct usb_driver vp702x_usb_driver = {
304 .name = "dvb_usb_vp702x", 307 .name = "dvb_usb_vp702x",
305 .probe = vp702x_usb_probe, 308 .probe = vp702x_usb_probe,
306 .disconnect = dvb_usb_device_exit, 309 .disconnect = dvb_usb_device_exit,
307 .id_table = vp702x_usb_table, 310 .id_table = vp702x_usb_table,
308 }; 311 };
309 312
310 /* module stuff */ 313 /* module stuff */
311 static int __init vp702x_usb_module_init(void) 314 static int __init vp702x_usb_module_init(void)
312 { 315 {
313 int result; 316 int result;
314 if ((result = usb_register(&vp702x_usb 317 if ((result = usb_register(&vp702x_usb_driver))) {
315 err("usb_register failed. (%d) 318 err("usb_register failed. (%d)",result);
316 return result; 319 return result;
317 } 320 }
318 321
319 return 0; 322 return 0;
320 } 323 }
321 324
322 static void __exit vp702x_usb_module_exit(void 325 static void __exit vp702x_usb_module_exit(void)
323 { 326 {
324 /* deregister this driver from the USB 327 /* deregister this driver from the USB subsystem */
325 usb_deregister(&vp702x_usb_driver); 328 usb_deregister(&vp702x_usb_driver);
326 } 329 }
327 330
328 module_init(vp702x_usb_module_init); 331 module_init(vp702x_usb_module_init);
329 module_exit(vp702x_usb_module_exit); 332 module_exit(vp702x_usb_module_exit);
330 333
331 MODULE_AUTHOR("Patrick Boettcher <patrick.boet 334 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
332 MODULE_DESCRIPTION("Driver for Twinhan StarBox 335 MODULE_DESCRIPTION("Driver for Twinhan StarBox DVB-S USB2.0 and clones");
333 MODULE_VERSION("1.0"); 336 MODULE_VERSION("1.0");
334 MODULE_LICENSE("GPL"); 337 MODULE_LICENSE("GPL");
335 338
|
This page was automatically generated by the
LXR engine.
|