Merge branch 'upstream-davem' of master.kernel.org:/pub/scm/linux/kernel/git/linville...
[GitHub/MotorolaMobilityLLC/kernel-slsi.git] / drivers / media / dvb / dvb-usb / dibusb-mb.c
CommitLineData
776338e1
JS
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
6c08d929
MK
17static 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
4d43e13f 25static int dibusb_dib3000mb_frontend_attach(struct dvb_usb_adapter *adap)
776338e1
JS
26{
27 struct dib3000_config demod_cfg;
4d43e13f 28 struct dibusb_state *st = adap->priv;
776338e1
JS
29
30 demod_cfg.demod_address = 0x8;
776338e1 31
79d3a8be
MK
32 if ((adap->fe = dvb_attach(dib3000mb_attach, &demod_cfg,
33 &adap->dev->i2c_adap, &st->ops)) == NULL)
776338e1 34 return -ENODEV;
56760f07 35
6c08d929 36 adap->fe->ops.i2c_gate_ctrl = dib3000mb_i2c_gate_ctrl;
776338e1
JS
37
38 return 0;
39}
40
4d43e13f 41static int dibusb_thomson_tuner_attach(struct dvb_usb_adapter *adap)
8945c8c3 42{
6c08d929
MK
43 struct dibusb_state *st = adap->priv;
44
45 st->tuner_addr = 0x61;
46
fbfee868 47 dvb_attach(dvb_pll_attach, adap->fe, 0x61, &adap->dev->i2c_adap,
47a9991e 48 DVB_PLL_TUA6010XS);
fbfee868
MK
49 return 0;
50}
51
52static int dibusb_panasonic_tuner_attach(struct dvb_usb_adapter *adap)
53{
6c08d929
MK
54 struct dibusb_state *st = adap->priv;
55
56 st->tuner_addr = 0x60;
57
fbfee868 58 dvb_attach(dvb_pll_attach, adap->fe, 0x60, &adap->dev->i2c_adap,
47a9991e 59 DVB_PLL_TDA665X);
8945c8c3
PB
60 return 0;
61}
62
63/* Some of the Artec 1.1 device aren't equipped with the default tuner
776338e1
JS
64 * (Thomson Cable), but with a Panasonic ENV77H11D5. This function figures
65 * this out. */
4d43e13f 66static int dibusb_tuner_probe_and_attach(struct dvb_usb_adapter *adap)
776338e1
JS
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 };
6c08d929 74 struct dibusb_state *st = adap->priv;
776338e1
JS
75
76 /* the Panasonic sits on I2C addrass 0x60, the Thomson on 0x61 */
096bb77a 77 msg[0].addr = msg[1].addr = st->tuner_addr = 0x60;
776338e1 78
6c08d929
MK
79 if (adap->fe->ops.i2c_gate_ctrl)
80 adap->fe->ops.i2c_gate_ctrl(adap->fe,1);
776338e1 81
4d43e13f 82 if (i2c_transfer(&adap->dev->i2c_adap, msg, 2) != 2) {
776338e1
JS
83 err("tuner i2c write failed.");
84 ret = -EREMOTEIO;
85 }
86
6c08d929
MK
87 if (adap->fe->ops.i2c_gate_ctrl)
88 adap->fe->ops.i2c_gate_ctrl(adap->fe,0);
776338e1
JS
89
90 if (b2[0] == 0xfe) {
1157020d 91 info("This device has the Thomson Cable onboard. Which is default.");
fbfee868 92 ret = dibusb_thomson_tuner_attach(adap);
776338e1 93 } else {
1157020d 94 info("This device has the Panasonic ENV77H11D5 onboard.");
fbfee868 95 ret = dibusb_panasonic_tuner_attach(adap);
776338e1
JS
96 }
97
98 return ret;
99}
100
101/* USB Driver stuff */
4d43e13f
PB
102static struct dvb_usb_device_properties dibusb1_1_properties;
103static struct dvb_usb_device_properties dibusb1_1_an2235_properties;
104static struct dvb_usb_device_properties dibusb2_0b_properties;
105static struct dvb_usb_device_properties artec_t1_usb2_properties;
776338e1
JS
106
107static int dibusb_probe(struct usb_interface *intf,
108 const struct usb_device_id *id)
109{
47dc3d68
PB
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 ||
f6f4b725
PB
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)
776338e1
JS
114 return 0;
115
116 return -EINVAL;
117}
118
119/* do not change the order of the ID table */
120static struct usb_device_id dibusb_dib3000mb_table [] = {
1157020d
MK
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) },
776338e1
JS
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) },
1157020d
MK
128/* 07 */ { USB_DEVICE(USB_VID_EMPIA, USB_PID_KWORLD_VSTREAM_COLD) },
129/* 08 */ { USB_DEVICE(USB_VID_EMPIA, USB_PID_KWORLD_VSTREAM_WARM) },
776338e1
JS
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) },
1157020d
MK
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) },
776338e1 144/* 23 */ { USB_DEVICE(USB_VID_ADSTECH, USB_PID_ADSTECH_USB2_COLD) },
8945c8c3
PB
145
146/* device ID with default DIBUSB2_0-firmware and with the hacked firmware */
776338e1 147/* 24 */ { USB_DEVICE(USB_VID_ADSTECH, USB_PID_ADSTECH_USB2_WARM) },
1157020d
MK
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) },
68293ddb 150
e69339d9
PB
151/* 27 */ { USB_DEVICE(USB_VID_KWORLD, USB_PID_KWORLD_VSTREAM_COLD) },
152
1157020d
MK
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) },
f6f4b725 155
1157020d
MK
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 */
68293ddb 163
1157020d 164#ifdef CONFIG_DVB_USB_DIBUSB_MB_FAULTY
f6f4b725 165/* 30 */ { USB_DEVICE(USB_VID_ANCHOR, USB_PID_ULTIMA_TVBOX_ANCHOR_COLD) },
68293ddb 166#endif
1157020d 167
776338e1
JS
168 { } /* Terminating entry */
169};
170MODULE_DEVICE_TABLE (usb, dibusb_dib3000mb_table);
171
4d43e13f
PB
172static struct dvb_usb_device_properties dibusb1_1_properties = {
173 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
776338e1
JS
174
175 .usb_ctrl = CYPRESS_AN2135,
176
177 .firmware = "dvb-usb-dibusb-5.0.0.11.fw",
178
4d43e13f
PB
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,
776338e1 184
01451e72
PB
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,
776338e1 190
01451e72 191 /* parameter for the MPEG2-data transfer */
4d43e13f
PB
192 .stream = {
193 .type = USB_BULK,
01451e72
PB
194 .count = 7,
195 .endpoint = 0x02,
196 .u = {
197 .bulk = {
198 .buffersize = 4096,
199 }
200 }
201 },
4d43e13f
PB
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,
776338e1 216
2f7f96b9 217 .num_device_descs = 9,
776338e1
JS
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 },
2f7f96b9
PB
251 { "VideoWalker DVB-T USB",
252 { &dibusb_dib3000mb_table[25], NULL },
253 { &dibusb_dib3000mb_table[26], NULL },
254 },
776338e1
JS
255 }
256};
257
4d43e13f
PB
258static struct dvb_usb_device_properties dibusb1_1_an2235_properties = {
259 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
776338e1
JS
260 .usb_ctrl = CYPRESS_AN2235,
261
262 .firmware = "dvb-usb-dibusb-an2235-01.fw",
263
4d43e13f
PB
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,
776338e1 269
01451e72
PB
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,
776338e1 275
01451e72 276 /* parameter for the MPEG2-data transfer */
4d43e13f
PB
277 .stream = {
278 .type = USB_BULK,
01451e72
PB
279 .count = 7,
280 .endpoint = 0x02,
281 .u = {
282 .bulk = {
283 .buffersize = 4096,
284 }
285 }
286 },
4d43e13f
PB
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,
776338e1 300
1157020d 301#ifdef CONFIG_DVB_USB_DIBUSB_MB_FAULTY
68293ddb
JS
302 .num_device_descs = 2,
303#else
776338e1 304 .num_device_descs = 1,
68293ddb 305#endif
776338e1
JS
306 .devices = {
307 { "Artec T1 USB1.1 TVBOX with AN2235",
776338e1 308 { &dibusb_dib3000mb_table[21], NULL },
83905b02 309 { &dibusb_dib3000mb_table[22], NULL },
776338e1 310 },
1157020d 311#ifdef CONFIG_DVB_USB_DIBUSB_MB_FAULTY
68293ddb 312 { "Artec T1 USB1.1 TVBOX with AN2235 (faulty USB IDs)",
f6f4b725 313 { &dibusb_dib3000mb_table[30], NULL },
68293ddb
JS
314 { NULL },
315 },
1157020d 316 { NULL },
68293ddb 317#endif
776338e1
JS
318 }
319};
320
4d43e13f
PB
321static struct dvb_usb_device_properties dibusb2_0b_properties = {
322 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
c251ef61 323
776338e1
JS
324 .usb_ctrl = CYPRESS_FX2,
325
8945c8c3 326 .firmware = "dvb-usb-adstech-usb2-02.fw",
776338e1 327
4d43e13f
PB
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,
776338e1 333
01451e72
PB
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 */
4d43e13f
PB
341 .stream = {
342 .type = USB_BULK,
01451e72
PB
343 .count = 7,
344 .endpoint = 0x06,
345 .u = {
346 .bulk = {
347 .buffersize = 4096,
348 }
349 }
350 },
4d43e13f
PB
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,
776338e1 364
e69339d9 365 .num_device_descs = 2,
776338e1 366 .devices = {
e69339d9 367 { "KWorld/ADSTech Instant DVB-T USB2.0",
776338e1 368 { &dibusb_dib3000mb_table[23], NULL },
8945c8c3 369 { &dibusb_dib3000mb_table[24], NULL },
776338e1 370 },
e69339d9
PB
371 { "KWorld Xpert DVB-T USB2.0",
372 { &dibusb_dib3000mb_table[27], NULL },
373 { NULL }
374 },
1157020d 375 { NULL },
776338e1
JS
376 }
377};
378
4d43e13f
PB
379static struct dvb_usb_device_properties artec_t1_usb2_properties = {
380 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
f6f4b725
PB
381
382 .usb_ctrl = CYPRESS_FX2,
383
384 .firmware = "dvb-usb-dibusb-6.0.0.8.fw",
385
4d43e13f
PB
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,
f6f4b725 391
01451e72
PB
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 */
4d43e13f
PB
398 .stream = {
399 .type = USB_BULK,
01451e72
PB
400 .count = 7,
401 .endpoint = 0x06,
402 .u = {
403 .bulk = {
404 .buffersize = 4096,
405 }
406 }
407 },
4d43e13f
PB
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,
f6f4b725
PB
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 },
1157020d 428 { NULL },
f6f4b725
PB
429 }
430};
431
776338e1 432static struct usb_driver dibusb_driver = {
63b5c1c4 433 .name = "dvb_usb_dibusb_mb",
776338e1
JS
434 .probe = dibusb_probe,
435 .disconnect = dvb_usb_device_exit,
436 .id_table = dibusb_dib3000mb_table,
437};
438
439/* module stuff */
440static 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
451static void __exit dibusb_module_exit(void)
452{
453 /* deregister this driver from the USB subsystem */
454 usb_deregister(&dibusb_driver);
455}
456
457module_init (dibusb_module_init);
458module_exit (dibusb_module_exit);
459
460MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
461MODULE_DESCRIPTION("Driver for DiBcom USB DVB-T devices (DiB3000M-B based)");
462MODULE_VERSION("1.0");
463MODULE_LICENSE("GPL");