V4L/DVB (5784): Dibusb-mb: fix tuner autodetection regression
[linux-2.6] / drivers / media / dvb / dvb-usb / dibusb-mb.c
1 /* DVB USB compliant linux driver for mobile DVB-T USB devices based on
2  * reference designs made by DiBcom (http://www.dibcom.fr/) (DiB3000M-B)
3  *
4  * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
5  *
6  * based on GPL code from DiBcom, which has
7  * Copyright (C) 2004 Amaury Demol for DiBcom (ademol@dibcom.fr)
8  *
9  *      This program is free software; you can redistribute it and/or modify it
10  *      under the terms of the GNU General Public License as published by the Free
11  *      Software Foundation, version 2.
12  *
13  * see Documentation/dvb/README.dvb-usb for more information
14  */
15 #include "dibusb.h"
16
17 static int dib3000mb_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
18 {
19         struct dvb_usb_adapter *adap = fe->dvb->priv;
20         struct dibusb_state *st = adap->priv;
21
22         return st->ops.tuner_pass_ctrl(fe, enable, st->tuner_addr);
23 }
24
25 static int dibusb_dib3000mb_frontend_attach(struct dvb_usb_adapter *adap)
26 {
27         struct dib3000_config demod_cfg;
28         struct dibusb_state *st = adap->priv;
29
30         demod_cfg.demod_address = 0x8;
31
32         if ((adap->fe = dvb_attach(dib3000mb_attach, &demod_cfg,
33                                    &adap->dev->i2c_adap, &st->ops)) == NULL)
34                 return -ENODEV;
35
36         adap->fe->ops.i2c_gate_ctrl = dib3000mb_i2c_gate_ctrl;
37
38         return 0;
39 }
40
41 static int dibusb_thomson_tuner_attach(struct dvb_usb_adapter *adap)
42 {
43         struct dibusb_state *st = adap->priv;
44
45         st->tuner_addr = 0x61;
46
47         dvb_attach(dvb_pll_attach, adap->fe, 0x61, &adap->dev->i2c_adap,
48                    DVB_PLL_TUA6010XS);
49         return 0;
50 }
51
52 static int dibusb_panasonic_tuner_attach(struct dvb_usb_adapter *adap)
53 {
54         struct dibusb_state *st = adap->priv;
55
56         st->tuner_addr = 0x60;
57
58         dvb_attach(dvb_pll_attach, adap->fe, 0x60, &adap->dev->i2c_adap,
59                    DVB_PLL_TDA665X);
60         return 0;
61 }
62
63 /* Some of the Artec 1.1 device aren't equipped with the default tuner
64  * (Thomson Cable), but with a Panasonic ENV77H11D5.  This function figures
65  * this out. */
66 static int dibusb_tuner_probe_and_attach(struct dvb_usb_adapter *adap)
67 {
68         u8 b[2] = { 0,0 }, b2[1];
69         int ret = 0;
70         struct i2c_msg msg[2] = {
71                 { .flags = 0,        .buf = b,  .len = 2 },
72                 { .flags = I2C_M_RD, .buf = b2, .len = 1 },
73         };
74         struct dibusb_state *st = adap->priv;
75
76         /* the Panasonic sits on I2C addrass 0x60, the Thomson on 0x61 */
77         msg[0].addr = msg[1].addr = st->tuner_addr = 0x60;
78
79         if (adap->fe->ops.i2c_gate_ctrl)
80                 adap->fe->ops.i2c_gate_ctrl(adap->fe,1);
81
82         if (i2c_transfer(&adap->dev->i2c_adap, msg, 2) != 2) {
83                 err("tuner i2c write failed.");
84                 ret = -EREMOTEIO;
85         }
86
87         if (adap->fe->ops.i2c_gate_ctrl)
88                 adap->fe->ops.i2c_gate_ctrl(adap->fe,0);
89
90         if (b2[0] == 0xfe) {
91                 info("This device has the Thomson Cable onboard. Which is default.");
92                 ret = dibusb_thomson_tuner_attach(adap);
93         } else {
94                 info("This device has the Panasonic ENV77H11D5 onboard.");
95                 ret = dibusb_panasonic_tuner_attach(adap);
96         }
97
98         return ret;
99 }
100
101 /* USB Driver stuff */
102 static struct dvb_usb_device_properties dibusb1_1_properties;
103 static struct dvb_usb_device_properties dibusb1_1_an2235_properties;
104 static struct dvb_usb_device_properties dibusb2_0b_properties;
105 static struct dvb_usb_device_properties artec_t1_usb2_properties;
106
107 static int dibusb_probe(struct usb_interface *intf,
108                 const struct usb_device_id *id)
109 {
110         if (dvb_usb_device_init(intf,&dibusb1_1_properties,THIS_MODULE,NULL) == 0 ||
111                 dvb_usb_device_init(intf,&dibusb1_1_an2235_properties,THIS_MODULE,NULL) == 0 ||
112                 dvb_usb_device_init(intf,&dibusb2_0b_properties,THIS_MODULE,NULL) == 0 ||
113                 dvb_usb_device_init(intf,&artec_t1_usb2_properties,THIS_MODULE,NULL) == 0)
114                 return 0;
115
116         return -EINVAL;
117 }
118
119 /* do not change the order of the ID table */
120 static struct usb_device_id dibusb_dib3000mb_table [] = {
121 /* 00 */        { USB_DEVICE(USB_VID_WIDEVIEW,          USB_PID_AVERMEDIA_DVBT_USB_COLD) },
122 /* 01 */        { USB_DEVICE(USB_VID_WIDEVIEW,          USB_PID_AVERMEDIA_DVBT_USB_WARM) },
123 /* 02 */        { USB_DEVICE(USB_VID_COMPRO,            USB_PID_COMPRO_DVBU2000_COLD) },
124 /* 03 */        { USB_DEVICE(USB_VID_COMPRO,            USB_PID_COMPRO_DVBU2000_WARM) },
125 /* 04 */        { USB_DEVICE(USB_VID_COMPRO_UNK,        USB_PID_COMPRO_DVBU2000_UNK_COLD) },
126 /* 05 */        { USB_DEVICE(USB_VID_DIBCOM,            USB_PID_DIBCOM_MOD3000_COLD) },
127 /* 06 */        { USB_DEVICE(USB_VID_DIBCOM,            USB_PID_DIBCOM_MOD3000_WARM) },
128 /* 07 */        { USB_DEVICE(USB_VID_EMPIA,             USB_PID_KWORLD_VSTREAM_COLD) },
129 /* 08 */        { USB_DEVICE(USB_VID_EMPIA,             USB_PID_KWORLD_VSTREAM_WARM) },
130 /* 09 */        { USB_DEVICE(USB_VID_GRANDTEC,          USB_PID_GRANDTEC_DVBT_USB_COLD) },
131 /* 10 */        { USB_DEVICE(USB_VID_GRANDTEC,          USB_PID_GRANDTEC_DVBT_USB_WARM) },
132 /* 11 */        { USB_DEVICE(USB_VID_GRANDTEC,          USB_PID_DIBCOM_MOD3000_COLD) },
133 /* 12 */        { USB_DEVICE(USB_VID_GRANDTEC,          USB_PID_DIBCOM_MOD3000_WARM) },
134 /* 13 */        { USB_DEVICE(USB_VID_HYPER_PALTEK,      USB_PID_UNK_HYPER_PALTEK_COLD) },
135 /* 14 */        { USB_DEVICE(USB_VID_HYPER_PALTEK,      USB_PID_UNK_HYPER_PALTEK_WARM) },
136 /* 15 */        { USB_DEVICE(USB_VID_VISIONPLUS,        USB_PID_TWINHAN_VP7041_COLD) },
137 /* 16 */        { USB_DEVICE(USB_VID_VISIONPLUS,        USB_PID_TWINHAN_VP7041_WARM) },
138 /* 17 */        { USB_DEVICE(USB_VID_TWINHAN,           USB_PID_TWINHAN_VP7041_COLD) },
139 /* 18 */        { USB_DEVICE(USB_VID_TWINHAN,           USB_PID_TWINHAN_VP7041_WARM) },
140 /* 19 */        { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_COLD) },
141 /* 20 */        { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_WARM) },
142 /* 21 */        { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_AN2235_COLD) },
143 /* 22 */        { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_AN2235_WARM) },
144 /* 23 */        { USB_DEVICE(USB_VID_ADSTECH,           USB_PID_ADSTECH_USB2_COLD) },
145
146 /* device ID with default DIBUSB2_0-firmware and with the hacked firmware */
147 /* 24 */        { USB_DEVICE(USB_VID_ADSTECH,           USB_PID_ADSTECH_USB2_WARM) },
148 /* 25 */        { USB_DEVICE(USB_VID_KYE,               USB_PID_KYE_DVB_T_COLD) },
149 /* 26 */        { USB_DEVICE(USB_VID_KYE,               USB_PID_KYE_DVB_T_WARM) },
150
151 /* 27 */        { USB_DEVICE(USB_VID_KWORLD,            USB_PID_KWORLD_VSTREAM_COLD) },
152
153 /* 28 */        { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_USB2_COLD) },
154 /* 29 */        { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_USB2_WARM) },
155
156 /*
157  * XXX: As Artec just 'forgot' to program the EEPROM on some Artec T1 devices
158  *      we don't catch these faulty IDs (namely 'Cypress FX1 USB controller') that
159  *      have been left on the device. If you don't have such a device but an Artec
160  *      device that's supposed to work with this driver but is not detected by it,
161  *      free to enable CONFIG_DVB_USB_DIBUSB_MB_FAULTY via your kernel config.
162  */
163
164 #ifdef CONFIG_DVB_USB_DIBUSB_MB_FAULTY
165 /* 30 */        { USB_DEVICE(USB_VID_ANCHOR,            USB_PID_ULTIMA_TVBOX_ANCHOR_COLD) },
166 #endif
167
168                         { }             /* Terminating entry */
169 };
170 MODULE_DEVICE_TABLE (usb, dibusb_dib3000mb_table);
171
172 static struct dvb_usb_device_properties dibusb1_1_properties = {
173         .caps =  DVB_USB_IS_AN_I2C_ADAPTER,
174
175         .usb_ctrl = CYPRESS_AN2135,
176
177         .firmware = "dvb-usb-dibusb-5.0.0.11.fw",
178
179         .num_adapters = 1,
180         .adapter = {
181                 {
182                         .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
183                         .pid_filter_count = 16,
184
185                         .streaming_ctrl   = dibusb_streaming_ctrl,
186                         .pid_filter       = dibusb_pid_filter,
187                         .pid_filter_ctrl  = dibusb_pid_filter_ctrl,
188                         .frontend_attach  = dibusb_dib3000mb_frontend_attach,
189                         .tuner_attach     = dibusb_tuner_probe_and_attach,
190
191                         /* parameter for the MPEG2-data transfer */
192                         .stream = {
193                                 .type = USB_BULK,
194                                 .count = 7,
195                                 .endpoint = 0x02,
196                                 .u = {
197                                         .bulk = {
198                                                 .buffersize = 4096,
199                                         }
200                                 }
201                         },
202                         .size_of_priv     = sizeof(struct dibusb_state),
203                 }
204         },
205
206         .power_ctrl       = dibusb_power_ctrl,
207
208         .rc_interval      = DEFAULT_RC_INTERVAL,
209         .rc_key_map       = dibusb_rc_keys,
210         .rc_key_map_size  = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
211         .rc_query         = dibusb_rc_query,
212
213         .i2c_algo         = &dibusb_i2c_algo,
214
215         .generic_bulk_ctrl_endpoint = 0x01,
216
217         .num_device_descs = 9,
218         .devices = {
219                 {       "AVerMedia AverTV DVBT USB1.1",
220                         { &dibusb_dib3000mb_table[0],  NULL },
221                         { &dibusb_dib3000mb_table[1],  NULL },
222                 },
223                 {       "Compro Videomate DVB-U2000 - DVB-T USB1.1 (please confirm to linux-dvb)",
224                         { &dibusb_dib3000mb_table[2], &dibusb_dib3000mb_table[4], NULL},
225                         { &dibusb_dib3000mb_table[3], NULL },
226                 },
227                 {       "DiBcom USB1.1 DVB-T reference design (MOD3000)",
228                         { &dibusb_dib3000mb_table[5],  NULL },
229                         { &dibusb_dib3000mb_table[6],  NULL },
230                 },
231                 {       "KWorld V-Stream XPERT DTV - DVB-T USB1.1",
232                         { &dibusb_dib3000mb_table[7], NULL },
233                         { &dibusb_dib3000mb_table[8], NULL },
234                 },
235                 {       "Grandtec USB1.1 DVB-T",
236                         { &dibusb_dib3000mb_table[9],  &dibusb_dib3000mb_table[11], NULL },
237                         { &dibusb_dib3000mb_table[10], &dibusb_dib3000mb_table[12], NULL },
238                 },
239                 {       "Unkown USB1.1 DVB-T device ???? please report the name to the author",
240                         { &dibusb_dib3000mb_table[13], NULL },
241                         { &dibusb_dib3000mb_table[14], NULL },
242                 },
243                 {       "TwinhanDTV USB-Ter USB1.1 / Magic Box I / HAMA USB1.1 DVB-T device",
244                         { &dibusb_dib3000mb_table[15], &dibusb_dib3000mb_table[17], NULL},
245                         { &dibusb_dib3000mb_table[16], &dibusb_dib3000mb_table[18], NULL},
246                 },
247                 {       "Artec T1 USB1.1 TVBOX with AN2135",
248                         { &dibusb_dib3000mb_table[19], NULL },
249                         { &dibusb_dib3000mb_table[20], NULL },
250                 },
251                 {       "VideoWalker DVB-T USB",
252                         { &dibusb_dib3000mb_table[25], NULL },
253                         { &dibusb_dib3000mb_table[26], NULL },
254                 },
255         }
256 };
257
258 static struct dvb_usb_device_properties dibusb1_1_an2235_properties = {
259         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
260         .usb_ctrl = CYPRESS_AN2235,
261
262         .firmware = "dvb-usb-dibusb-an2235-01.fw",
263
264         .num_adapters = 1,
265         .adapter = {
266                 {
267                         .caps = DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_ADAP_HAS_PID_FILTER,
268                         .pid_filter_count = 16,
269
270                         .streaming_ctrl   = dibusb_streaming_ctrl,
271                         .pid_filter       = dibusb_pid_filter,
272                         .pid_filter_ctrl  = dibusb_pid_filter_ctrl,
273                         .frontend_attach  = dibusb_dib3000mb_frontend_attach,
274                         .tuner_attach     = dibusb_tuner_probe_and_attach,
275
276                         /* parameter for the MPEG2-data transfer */
277                         .stream = {
278                                 .type = USB_BULK,
279                                 .count = 7,
280                                 .endpoint = 0x02,
281                                 .u = {
282                                         .bulk = {
283                                                 .buffersize = 4096,
284                                         }
285                                 }
286                         },
287                         .size_of_priv     = sizeof(struct dibusb_state),
288                 },
289         },
290         .power_ctrl       = dibusb_power_ctrl,
291
292         .rc_interval      = DEFAULT_RC_INTERVAL,
293         .rc_key_map       = dibusb_rc_keys,
294         .rc_key_map_size  = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
295         .rc_query         = dibusb_rc_query,
296
297         .i2c_algo         = &dibusb_i2c_algo,
298
299         .generic_bulk_ctrl_endpoint = 0x01,
300
301 #ifdef CONFIG_DVB_USB_DIBUSB_MB_FAULTY
302         .num_device_descs = 2,
303 #else
304         .num_device_descs = 1,
305 #endif
306         .devices = {
307                 {       "Artec T1 USB1.1 TVBOX with AN2235",
308                         { &dibusb_dib3000mb_table[21], NULL },
309                         { &dibusb_dib3000mb_table[22], NULL },
310                 },
311 #ifdef CONFIG_DVB_USB_DIBUSB_MB_FAULTY
312                 {       "Artec T1 USB1.1 TVBOX with AN2235 (faulty USB IDs)",
313                         { &dibusb_dib3000mb_table[30], NULL },
314                         { NULL },
315                 },
316                 { NULL },
317 #endif
318         }
319 };
320
321 static struct dvb_usb_device_properties dibusb2_0b_properties = {
322         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
323
324         .usb_ctrl = CYPRESS_FX2,
325
326         .firmware = "dvb-usb-adstech-usb2-02.fw",
327
328         .num_adapters = 1,
329         .adapter = {
330                 {
331                         .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
332                         .pid_filter_count = 16,
333
334                         .streaming_ctrl   = dibusb2_0_streaming_ctrl,
335                         .pid_filter       = dibusb_pid_filter,
336                         .pid_filter_ctrl  = dibusb_pid_filter_ctrl,
337                         .frontend_attach  = dibusb_dib3000mb_frontend_attach,
338                         .tuner_attach     = dibusb_thomson_tuner_attach,
339
340                         /* parameter for the MPEG2-data transfer */
341                         .stream = {
342                                 .type = USB_BULK,
343                                 .count = 7,
344                                 .endpoint = 0x06,
345                                 .u = {
346                                         .bulk = {
347                                                 .buffersize = 4096,
348                                         }
349                                 }
350                         },
351                         .size_of_priv     = sizeof(struct dibusb_state),
352                 }
353         },
354         .power_ctrl       = dibusb2_0_power_ctrl,
355
356         .rc_interval      = DEFAULT_RC_INTERVAL,
357         .rc_key_map       = dibusb_rc_keys,
358         .rc_key_map_size  = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
359         .rc_query         = dibusb_rc_query,
360
361         .i2c_algo         = &dibusb_i2c_algo,
362
363         .generic_bulk_ctrl_endpoint = 0x01,
364
365         .num_device_descs = 2,
366         .devices = {
367                 {       "KWorld/ADSTech Instant DVB-T USB2.0",
368                         { &dibusb_dib3000mb_table[23], NULL },
369                         { &dibusb_dib3000mb_table[24], NULL },
370                 },
371                 {       "KWorld Xpert DVB-T USB2.0",
372                         { &dibusb_dib3000mb_table[27], NULL },
373                         { NULL }
374                 },
375                 { NULL },
376         }
377 };
378
379 static struct dvb_usb_device_properties artec_t1_usb2_properties = {
380         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
381
382         .usb_ctrl = CYPRESS_FX2,
383
384         .firmware = "dvb-usb-dibusb-6.0.0.8.fw",
385
386         .num_adapters = 1,
387         .adapter = {
388                 {
389                         .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
390                         .pid_filter_count = 16,
391
392                         .streaming_ctrl   = dibusb2_0_streaming_ctrl,
393                         .pid_filter       = dibusb_pid_filter,
394                         .pid_filter_ctrl  = dibusb_pid_filter_ctrl,
395                         .frontend_attach  = dibusb_dib3000mb_frontend_attach,
396                         .tuner_attach     = dibusb_tuner_probe_and_attach,
397                         /* parameter for the MPEG2-data transfer */
398                         .stream = {
399                                 .type = USB_BULK,
400                                 .count = 7,
401                                 .endpoint = 0x06,
402                                 .u = {
403                                         .bulk = {
404                                                 .buffersize = 4096,
405                                         }
406                                 }
407                         },
408                         .size_of_priv     = sizeof(struct dibusb_state),
409                 }
410         },
411         .power_ctrl       = dibusb2_0_power_ctrl,
412
413         .rc_interval      = DEFAULT_RC_INTERVAL,
414         .rc_key_map       = dibusb_rc_keys,
415         .rc_key_map_size  = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
416         .rc_query         = dibusb_rc_query,
417
418         .i2c_algo         = &dibusb_i2c_algo,
419
420         .generic_bulk_ctrl_endpoint = 0x01,
421
422         .num_device_descs = 1,
423         .devices = {
424                 {       "Artec T1 USB2.0",
425                         { &dibusb_dib3000mb_table[28], NULL },
426                         { &dibusb_dib3000mb_table[29], NULL },
427                 },
428                 { NULL },
429         }
430 };
431
432 static struct usb_driver dibusb_driver = {
433         .name           = "dvb_usb_dibusb_mb",
434         .probe          = dibusb_probe,
435         .disconnect = dvb_usb_device_exit,
436         .id_table       = dibusb_dib3000mb_table,
437 };
438
439 /* module stuff */
440 static int __init dibusb_module_init(void)
441 {
442         int result;
443         if ((result = usb_register(&dibusb_driver))) {
444                 err("usb_register failed. Error number %d",result);
445                 return result;
446         }
447
448         return 0;
449 }
450
451 static void __exit dibusb_module_exit(void)
452 {
453         /* deregister this driver from the USB subsystem */
454         usb_deregister(&dibusb_driver);
455 }
456
457 module_init (dibusb_module_init);
458 module_exit (dibusb_module_exit);
459
460 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
461 MODULE_DESCRIPTION("Driver for DiBcom USB DVB-T devices (DiB3000M-B based)");
462 MODULE_VERSION("1.0");
463 MODULE_LICENSE("GPL");