hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/media/usb/dvb-usb/cxusb.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* DVB USB compliant linux driver for Conexant USB reference design.
23 *
34 * The Conexant reference design I saw on their website was only for analogue
....@@ -11,22 +12,21 @@
1112 * design, so it can be reused for the "analogue-only" device (if it will
1213 * appear at all).
1314 *
14
- * TODO: Use the cx25840-driver for the analogue part
1515 *
1616 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@posteo.de)
1717 * Copyright (C) 2006 Michael Krufky (mkrufky@linuxtv.org)
1818 * Copyright (C) 2006, 2007 Chris Pascoe (c.pascoe@itee.uq.edu.au)
19
+ * Copyright (C) 2011, 2017 Maciej S. Szmigiero (mail@maciej.szmigiero.name)
1920 *
20
- * This program is free software; you can redistribute it and/or modify it
21
- * under the terms of the GNU General Public License as published by the Free
22
- * Software Foundation, version 2.
23
- *
24
- * see Documentation/media/dvb-drivers/dvb-usb.rst for more information
21
+ * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
2522 */
2623 #include <media/tuner.h>
27
-#include <linux/vmalloc.h>
28
-#include <linux/slab.h>
24
+#include <linux/delay.h>
25
+#include <linux/device.h>
2926 #include <linux/kernel.h>
27
+#include <linux/slab.h>
28
+#include <linux/string.h>
29
+#include <linux/vmalloc.h>
3030
3131 #include "cxusb.h"
3232
....@@ -47,17 +47,41 @@
4747 #include "si2157.h"
4848
4949 /* debug */
50
-static int dvb_usb_cxusb_debug;
50
+int dvb_usb_cxusb_debug;
5151 module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
52
-MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
52
+MODULE_PARM_DESC(debug, "set debugging level (see cxusb.h)."
53
+ DVB_USB_DEBUG_STATUS);
5354
5455 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
5556
56
-#define deb_info(args...) dprintk(dvb_usb_cxusb_debug, 0x03, args)
57
-#define deb_i2c(args...) dprintk(dvb_usb_cxusb_debug, 0x02, args)
57
+enum cxusb_table_index {
58
+ MEDION_MD95700,
59
+ DVICO_BLUEBIRD_LG064F_COLD,
60
+ DVICO_BLUEBIRD_LG064F_WARM,
61
+ DVICO_BLUEBIRD_DUAL_1_COLD,
62
+ DVICO_BLUEBIRD_DUAL_1_WARM,
63
+ DVICO_BLUEBIRD_LGZ201_COLD,
64
+ DVICO_BLUEBIRD_LGZ201_WARM,
65
+ DVICO_BLUEBIRD_TH7579_COLD,
66
+ DVICO_BLUEBIRD_TH7579_WARM,
67
+ DIGITALNOW_BLUEBIRD_DUAL_1_COLD,
68
+ DIGITALNOW_BLUEBIRD_DUAL_1_WARM,
69
+ DVICO_BLUEBIRD_DUAL_2_COLD,
70
+ DVICO_BLUEBIRD_DUAL_2_WARM,
71
+ DVICO_BLUEBIRD_DUAL_4,
72
+ DVICO_BLUEBIRD_DVB_T_NANO_2,
73
+ DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM,
74
+ AVERMEDIA_VOLAR_A868R,
75
+ DVICO_BLUEBIRD_DUAL_4_REV_2,
76
+ CONEXANT_D680_DMB,
77
+ MYGICA_D689,
78
+ NR__cxusb_table_index
79
+};
5880
59
-static int cxusb_ctrl_msg(struct dvb_usb_device *d,
60
- u8 cmd, const u8 *wbuf, int wlen, u8 *rbuf, int rlen)
81
+static struct usb_device_id cxusb_table[];
82
+
83
+int cxusb_ctrl_msg(struct dvb_usb_device *d,
84
+ u8 cmd, const u8 *wbuf, int wlen, u8 *rbuf, int rlen)
6185 {
6286 struct cxusb_state *st = d->priv;
6387 int ret;
....@@ -89,7 +113,8 @@
89113 struct cxusb_state *st = d->priv;
90114 u8 o[2], i;
91115
92
- if (st->gpio_write_state[GPIO_TUNER] == onoff)
116
+ if (st->gpio_write_state[GPIO_TUNER] == onoff &&
117
+ !st->gpio_write_refresh[GPIO_TUNER])
93118 return;
94119
95120 o[0] = GPIO_TUNER;
....@@ -97,13 +122,14 @@
97122 cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
98123
99124 if (i != 0x01)
100
- deb_info("gpio_write failed.\n");
125
+ dev_info(&d->udev->dev, "gpio_write failed.\n");
101126
102127 st->gpio_write_state[GPIO_TUNER] = onoff;
128
+ st->gpio_write_refresh[GPIO_TUNER] = false;
103129 }
104130
105131 static int cxusb_bluebird_gpio_rw(struct dvb_usb_device *d, u8 changemask,
106
- u8 newval)
132
+ u8 newval)
107133 {
108134 u8 o[2], gpio_state;
109135 int rc;
....@@ -113,7 +139,7 @@
113139
114140 rc = cxusb_ctrl_msg(d, CMD_BLUEBIRD_GPIO_RW, o, 2, &gpio_state, 1);
115141 if (rc < 0 || (gpio_state & changemask) != (newval & changemask))
116
- deb_info("bluebird_gpio_write failed.\n");
142
+ dev_info(&d->udev->dev, "bluebird_gpio_write failed.\n");
117143
118144 return rc < 0 ? rc : gpio_state;
119145 }
....@@ -131,7 +157,7 @@
131157 }
132158
133159 static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device *d,
134
- u8 addr, int onoff)
160
+ u8 addr, int onoff)
135161 {
136162 u8 o[2] = {addr, onoff};
137163 u8 i;
....@@ -141,12 +167,12 @@
141167
142168 if (rc < 0)
143169 return rc;
170
+
144171 if (i == 0x01)
145172 return 0;
146
- else {
147
- deb_info("gpio_write failed.\n");
148
- return -EIO;
149
- }
173
+
174
+ dev_info(&d->udev->dev, "gpio_write failed.\n");
175
+ return -EIO;
150176 }
151177
152178 /* I2C */
....@@ -161,7 +187,6 @@
161187 return -EAGAIN;
162188
163189 for (i = 0; i < num; i++) {
164
-
165190 if (le16_to_cpu(d->udev->descriptor.idVendor) == USB_VID_MEDION)
166191 switch (msg[i].addr) {
167192 case 0x63:
....@@ -187,13 +212,13 @@
187212 obuf[2] = msg[i].addr;
188213 if (cxusb_ctrl_msg(d, CMD_I2C_READ,
189214 obuf, 3,
190
- ibuf, 1+msg[i].len) < 0) {
215
+ ibuf, 1 + msg[i].len) < 0) {
191216 warn("i2c read failed");
192217 break;
193218 }
194219 memcpy(msg[i].buf, &ibuf[1], msg[i].len);
195
- } else if (i+1 < num && (msg[i+1].flags & I2C_M_RD) &&
196
- msg[i].addr == msg[i+1].addr) {
220
+ } else if (i + 1 < num && (msg[i + 1].flags & I2C_M_RD) &&
221
+ msg[i].addr == msg[i + 1].addr) {
197222 /* write to then read from same address */
198223 u8 obuf[MAX_XFER_SIZE], ibuf[MAX_XFER_SIZE];
199224
....@@ -210,19 +235,19 @@
210235 goto unlock;
211236 }
212237 obuf[0] = msg[i].len;
213
- obuf[1] = msg[i+1].len;
238
+ obuf[1] = msg[i + 1].len;
214239 obuf[2] = msg[i].addr;
215240 memcpy(&obuf[3], msg[i].buf, msg[i].len);
216241
217242 if (cxusb_ctrl_msg(d, CMD_I2C_READ,
218
- obuf, 3+msg[i].len,
219
- ibuf, 1+msg[i+1].len) < 0)
243
+ obuf, 3 + msg[i].len,
244
+ ibuf, 1 + msg[i + 1].len) < 0)
220245 break;
221246
222247 if (ibuf[0] != 0x08)
223
- deb_i2c("i2c read may have failed\n");
248
+ dev_info(&d->udev->dev, "i2c read may have failed\n");
224249
225
- memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);
250
+ memcpy(msg[i + 1].buf, &ibuf[1], msg[i + 1].len);
226251
227252 i++;
228253 } else {
....@@ -240,10 +265,10 @@
240265 memcpy(&obuf[2], msg[i].buf, msg[i].len);
241266
242267 if (cxusb_ctrl_msg(d, CMD_I2C_WRITE, obuf,
243
- 2+msg[i].len, &ibuf,1) < 0)
268
+ 2 + msg[i].len, &ibuf, 1) < 0)
244269 break;
245270 if (ibuf != 0x08)
246
- deb_i2c("i2c write may have failed\n");
271
+ dev_info(&d->udev->dev, "i2c write may have failed\n");
247272 }
248273 }
249274
....@@ -259,7 +284,7 @@
259284
260285 static u32 cxusb_i2c_func(struct i2c_adapter *adapter)
261286 {
262
- return I2C_FUNC_I2C;
287
+ return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
263288 }
264289
265290 static struct i2c_algorithm cxusb_i2c_algo = {
....@@ -267,29 +292,67 @@
267292 .functionality = cxusb_i2c_func,
268293 };
269294
270
-static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
295
+static int _cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
271296 {
272297 u8 b = 0;
298
+
299
+ dev_info(&d->udev->dev, "setting power %s\n", onoff ? "ON" : "OFF");
300
+
273301 if (onoff)
274302 return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
275303 else
276304 return cxusb_ctrl_msg(d, CMD_POWER_OFF, &b, 1, NULL, 0);
277305 }
278306
307
+static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
308
+{
309
+ bool is_medion = d->props.devices[0].warm_ids[0] == &cxusb_table[MEDION_MD95700];
310
+ int ret;
311
+
312
+ if (is_medion && !onoff) {
313
+ struct cxusb_medion_dev *cxdev = d->priv;
314
+
315
+ mutex_lock(&cxdev->open_lock);
316
+
317
+ if (cxdev->open_type == CXUSB_OPEN_ANALOG) {
318
+ dev_info(&d->udev->dev, "preventing DVB core from setting power OFF while we are in analog mode\n");
319
+ ret = -EBUSY;
320
+ goto ret_unlock;
321
+ }
322
+ }
323
+
324
+ ret = _cxusb_power_ctrl(d, onoff);
325
+
326
+ret_unlock:
327
+ if (is_medion && !onoff) {
328
+ struct cxusb_medion_dev *cxdev = d->priv;
329
+
330
+ mutex_unlock(&cxdev->open_lock);
331
+ }
332
+
333
+ return ret;
334
+}
335
+
279336 static int cxusb_aver_power_ctrl(struct dvb_usb_device *d, int onoff)
280337 {
281338 int ret;
339
+
282340 if (!onoff)
283341 return cxusb_ctrl_msg(d, CMD_POWER_OFF, NULL, 0, NULL, 0);
284342 if (d->state == DVB_USB_STATE_INIT &&
285343 usb_set_interface(d->udev, 0, 0) < 0)
286344 err("set interface failed");
287
- do {} while (!(ret = cxusb_ctrl_msg(d, CMD_POWER_ON, NULL, 0, NULL, 0)) &&
288
- !(ret = cxusb_ctrl_msg(d, 0x15, NULL, 0, NULL, 0)) &&
289
- !(ret = cxusb_ctrl_msg(d, 0x17, NULL, 0, NULL, 0)) && 0);
345
+ do {
346
+ /* Nothing */
347
+ } while (!(ret = cxusb_ctrl_msg(d, CMD_POWER_ON, NULL, 0, NULL, 0)) &&
348
+ !(ret = cxusb_ctrl_msg(d, 0x15, NULL, 0, NULL, 0)) &&
349
+ !(ret = cxusb_ctrl_msg(d, 0x17, NULL, 0, NULL, 0)) && 0);
350
+
290351 if (!ret) {
291
- /* FIXME: We don't know why, but we need to configure the
292
- * lgdt3303 with the register settings below on resume */
352
+ /*
353
+ * FIXME: We don't know why, but we need to configure the
354
+ * lgdt3303 with the register settings below on resume
355
+ */
293356 int i;
294357 u8 buf;
295358 static const u8 bufs[] = {
....@@ -307,7 +370,7 @@
307370 msleep(20);
308371 for (i = 0; i < ARRAY_SIZE(bufs); i += 4 / sizeof(u8)) {
309372 ret = cxusb_ctrl_msg(d, CMD_I2C_WRITE,
310
- bufs+i, 4, &buf, 1);
373
+ bufs + i, 4, &buf, 1);
311374 if (ret)
312375 break;
313376 if (buf != 0x8)
....@@ -320,6 +383,7 @@
320383 static int cxusb_bluebird_power_ctrl(struct dvb_usb_device *d, int onoff)
321384 {
322385 u8 b = 0;
386
+
323387 if (onoff)
324388 return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
325389 else
....@@ -341,6 +405,7 @@
341405 {
342406 int ret;
343407 u8 b;
408
+
344409 ret = cxusb_power_ctrl(d, onoff);
345410 if (!onoff)
346411 return ret;
....@@ -353,11 +418,26 @@
353418
354419 static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
355420 {
421
+ struct dvb_usb_device *dvbdev = adap->dev;
422
+ bool is_medion = dvbdev->props.devices[0].warm_ids[0] ==
423
+ &cxusb_table[MEDION_MD95700];
356424 u8 buf[2] = { 0x03, 0x00 };
425
+
426
+ if (is_medion && onoff) {
427
+ int ret;
428
+
429
+ ret = cxusb_medion_get(dvbdev, CXUSB_OPEN_DIGITAL);
430
+ if (ret != 0)
431
+ return ret;
432
+ }
433
+
357434 if (onoff)
358
- cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON, buf, 2, NULL, 0);
435
+ cxusb_ctrl_msg(dvbdev, CMD_STREAMING_ON, buf, 2, NULL, 0);
359436 else
360
- cxusb_ctrl_msg(adap->dev, CMD_STREAMING_OFF, NULL, 0, NULL, 0);
437
+ cxusb_ctrl_msg(dvbdev, CMD_STREAMING_OFF, NULL, 0, NULL, 0);
438
+
439
+ if (is_medion && !onoff)
440
+ cxusb_medion_put(dvbdev);
361441
362442 return 0;
363443 }
....@@ -370,26 +450,6 @@
370450 cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_OFF,
371451 NULL, 0, NULL, 0);
372452 return 0;
373
-}
374
-
375
-static int cxusb_read_status(struct dvb_frontend *fe,
376
- enum fe_status *status)
377
-{
378
- struct dvb_usb_adapter *adap = (struct dvb_usb_adapter *)fe->dvb->priv;
379
- struct cxusb_state *state = (struct cxusb_state *)adap->dev->priv;
380
- int ret;
381
-
382
- ret = state->fe_read_status(fe, status);
383
-
384
- /* it need resync slave fifo when signal change from unlock to lock.*/
385
- if ((*status & FE_HAS_LOCK) && (!state->last_lock)) {
386
- mutex_lock(&state->stream_mutex);
387
- cxusb_streaming_ctrl(adap, 1);
388
- mutex_unlock(&state->stream_mutex);
389
- }
390
-
391
- state->last_lock = (*status & FE_HAS_LOCK) ? 1 : 0;
392
- return ret;
393453 }
394454
395455 static void cxusb_d680_dmb_drain_message(struct dvb_usb_device *d)
....@@ -406,8 +466,8 @@
406466 return;
407467 while (1) {
408468 if (usb_bulk_msg(d->udev,
409
- usb_rcvbulkpipe(d->udev, ep),
410
- junk, junk_len, &rd_count, timeout) < 0)
469
+ usb_rcvbulkpipe(d->udev, ep),
470
+ junk, junk_len, &rd_count, timeout) < 0)
411471 break;
412472 if (!rd_count)
413473 break;
....@@ -429,8 +489,8 @@
429489 return;
430490 while (1) {
431491 if (usb_bulk_msg(d->udev,
432
- usb_rcvbulkpipe(d->udev, p->endpoint),
433
- junk, junk_len, &rd_count, timeout) < 0)
492
+ usb_rcvbulkpipe(d->udev, p->endpoint),
493
+ junk, junk_len, &rd_count, timeout) < 0)
434494 break;
435495 if (!rd_count)
436496 break;
....@@ -438,17 +498,18 @@
438498 kfree(junk);
439499 }
440500
441
-static int cxusb_d680_dmb_streaming_ctrl(
442
- struct dvb_usb_adapter *adap, int onoff)
501
+static int cxusb_d680_dmb_streaming_ctrl(struct dvb_usb_adapter *adap,
502
+ int onoff)
443503 {
444504 if (onoff) {
445505 u8 buf[2] = { 0x03, 0x00 };
506
+
446507 cxusb_d680_dmb_drain_video(adap->dev);
447508 return cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON,
448
- buf, sizeof(buf), NULL, 0);
509
+ buf, sizeof(buf), NULL, 0);
449510 } else {
450511 int ret = cxusb_ctrl_msg(adap->dev,
451
- CMD_STREAMING_OFF, NULL, 0, NULL, 0);
512
+ CMD_STREAMING_OFF, NULL, 0, NULL, 0);
452513 return ret;
453514 }
454515 }
....@@ -469,8 +530,12 @@
469530 static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d)
470531 {
471532 u8 ircode[4];
472
- struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
473
- .buf = ircode, .len = 4 };
533
+ struct i2c_msg msg = {
534
+ .addr = 0x6b,
535
+ .flags = I2C_M_RD,
536
+ .buf = ircode,
537
+ .len = 4
538
+ };
474539
475540 if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)
476541 return 0;
....@@ -494,13 +559,13 @@
494559 return 0;
495560 }
496561
497
-static int cxusb_dee1601_demod_init(struct dvb_frontend* fe)
562
+static int cxusb_dee1601_demod_init(struct dvb_frontend *fe)
498563 {
499
- static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x28 };
500
- static u8 reset [] = { RESET, 0x80 };
501
- static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
502
- static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0x20 };
503
- static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
564
+ static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };
565
+ static u8 reset[] = { RESET, 0x80 };
566
+ static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
567
+ static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };
568
+ static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
504569 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
505570
506571 mt352_write(fe, clock_config, sizeof(clock_config));
....@@ -515,13 +580,14 @@
515580 return 0;
516581 }
517582
518
-static int cxusb_mt352_demod_init(struct dvb_frontend* fe)
519
-{ /* used in both lgz201 and th7579 */
520
- static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x29 };
521
- static u8 reset [] = { RESET, 0x80 };
522
- static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
523
- static u8 agc_cfg [] = { AGC_TARGET, 0x24, 0x20 };
524
- static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
583
+static int cxusb_mt352_demod_init(struct dvb_frontend *fe)
584
+{
585
+ /* used in both lgz201 and th7579 */
586
+ static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x29 };
587
+ static u8 reset[] = { RESET, 0x80 };
588
+ static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
589
+ static u8 agc_cfg[] = { AGC_TARGET, 0x24, 0x20 };
590
+ static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
525591 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
526592
527593 mt352_write(fe, clock_config, sizeof(clock_config));
....@@ -631,9 +697,21 @@
631697 /* Callbacks for DVB USB */
632698 static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
633699 {
700
+ struct dvb_usb_device *dvbdev = adap->dev;
701
+ bool is_medion = dvbdev->props.devices[0].warm_ids[0] ==
702
+ &cxusb_table[MEDION_MD95700];
703
+
634704 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
635
- &adap->dev->i2c_adap, 0x61,
705
+ &dvbdev->i2c_adap, 0x61,
636706 TUNER_PHILIPS_FMD1216ME_MK3);
707
+
708
+ if (is_medion && adap->fe_adap[0].fe)
709
+ /*
710
+ * make sure that DVB core won't put to sleep (reset, really)
711
+ * tuner when we might be open in analog mode
712
+ */
713
+ adap->fe_adap[0].fe->ops.tuner_ops.sleep = NULL;
714
+
637715 return 0;
638716 }
639717
....@@ -646,7 +724,8 @@
646724
647725 static int cxusb_lgz201_tuner_attach(struct dvb_usb_adapter *adap)
648726 {
649
- dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61, NULL, DVB_PLL_LG_Z201);
727
+ dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61,
728
+ NULL, DVB_PLL_LG_Z201);
650729 return 0;
651730 }
652731
....@@ -672,16 +751,16 @@
672751
673752 switch (command) {
674753 case XC2028_TUNER_RESET:
675
- deb_info("%s: XC2028_TUNER_RESET %d\n", __func__, arg);
754
+ dev_info(&d->udev->dev, "XC2028_TUNER_RESET %d\n", arg);
676755 cxusb_bluebird_gpio_pulse(d, 0x01, 1);
677756 break;
678757 case XC2028_RESET_CLK:
679
- deb_info("%s: XC2028_RESET_CLK %d\n", __func__, arg);
758
+ dev_info(&d->udev->dev, "XC2028_RESET_CLK %d\n", arg);
680759 break;
681760 case XC2028_I2C_FLUSH:
682761 break;
683762 default:
684
- deb_info("%s: unknown command %d, arg %d\n", __func__,
763
+ dev_info(&d->udev->dev, "unknown command %d, arg %d\n",
685764 command, arg);
686765 return -EINVAL;
687766 }
....@@ -706,7 +785,7 @@
706785 adap->fe_adap[0].fe->callback = dvico_bluebird_xc2028_callback;
707786
708787 fe = dvb_attach(xc2028_attach, adap->fe_adap[0].fe, &cfg);
709
- if (fe == NULL || fe->ops.tuner_ops.set_config == NULL)
788
+ if (!fe || !fe->ops.tuner_ops.set_config)
710789 return -EIO;
711790
712791 fe->ops.tuner_ops.set_config(fe, &ctl);
....@@ -724,33 +803,120 @@
724803 static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)
725804 {
726805 struct dvb_frontend *fe;
806
+
727807 fe = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
728808 &adap->dev->i2c_adap, &d680_dmb_tuner);
729
- return (fe == NULL) ? -EIO : 0;
809
+ return (!fe) ? -EIO : 0;
730810 }
731811
732812 static int cxusb_mygica_d689_tuner_attach(struct dvb_usb_adapter *adap)
733813 {
734814 struct dvb_frontend *fe;
815
+
735816 fe = dvb_attach(max2165_attach, adap->fe_adap[0].fe,
736817 &adap->dev->i2c_adap, &mygica_d689_max2165_cfg);
737
- return (fe == NULL) ? -EIO : 0;
818
+ return (!fe) ? -EIO : 0;
819
+}
820
+
821
+static int cxusb_medion_fe_ts_bus_ctrl(struct dvb_frontend *fe, int acquire)
822
+{
823
+ struct dvb_usb_adapter *adap = fe->dvb->priv;
824
+ struct dvb_usb_device *dvbdev = adap->dev;
825
+
826
+ if (acquire)
827
+ return cxusb_medion_get(dvbdev, CXUSB_OPEN_DIGITAL);
828
+
829
+ cxusb_medion_put(dvbdev);
830
+
831
+ return 0;
832
+}
833
+
834
+static int cxusb_medion_set_mode(struct dvb_usb_device *dvbdev, bool digital)
835
+{
836
+ struct cxusb_state *st = dvbdev->priv;
837
+ int ret;
838
+ u8 b;
839
+ unsigned int i;
840
+
841
+ /*
842
+ * switching mode while doing an I2C transaction often causes
843
+ * the device to crash
844
+ */
845
+ mutex_lock(&dvbdev->i2c_mutex);
846
+
847
+ if (digital) {
848
+ ret = usb_set_interface(dvbdev->udev, 0, 6);
849
+ if (ret != 0) {
850
+ dev_err(&dvbdev->udev->dev,
851
+ "digital interface selection failed (%d)\n",
852
+ ret);
853
+ goto ret_unlock;
854
+ }
855
+ } else {
856
+ ret = usb_set_interface(dvbdev->udev, 0, 1);
857
+ if (ret != 0) {
858
+ dev_err(&dvbdev->udev->dev,
859
+ "analog interface selection failed (%d)\n",
860
+ ret);
861
+ goto ret_unlock;
862
+ }
863
+ }
864
+
865
+ /* pipes need to be cleared after setting interface */
866
+ ret = usb_clear_halt(dvbdev->udev, usb_rcvbulkpipe(dvbdev->udev, 1));
867
+ if (ret != 0)
868
+ dev_warn(&dvbdev->udev->dev,
869
+ "clear halt on IN pipe failed (%d)\n",
870
+ ret);
871
+
872
+ ret = usb_clear_halt(dvbdev->udev, usb_sndbulkpipe(dvbdev->udev, 1));
873
+ if (ret != 0)
874
+ dev_warn(&dvbdev->udev->dev,
875
+ "clear halt on OUT pipe failed (%d)\n",
876
+ ret);
877
+
878
+ ret = cxusb_ctrl_msg(dvbdev, digital ? CMD_DIGITAL : CMD_ANALOG,
879
+ NULL, 0, &b, 1);
880
+ if (ret != 0) {
881
+ dev_err(&dvbdev->udev->dev, "mode switch failed (%d)\n",
882
+ ret);
883
+ goto ret_unlock;
884
+ }
885
+
886
+ /* mode switch seems to reset GPIO states */
887
+ for (i = 0; i < ARRAY_SIZE(st->gpio_write_refresh); i++)
888
+ st->gpio_write_refresh[i] = true;
889
+
890
+ret_unlock:
891
+ mutex_unlock(&dvbdev->i2c_mutex);
892
+
893
+ return ret;
738894 }
739895
740896 static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
741897 {
742
- u8 b;
743
- if (usb_set_interface(adap->dev->udev, 0, 6) < 0)
744
- err("set interface failed");
898
+ struct dvb_usb_device *dvbdev = adap->dev;
899
+ bool is_medion = dvbdev->props.devices[0].warm_ids[0] ==
900
+ &cxusb_table[MEDION_MD95700];
745901
746
- cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, &b, 1);
902
+ if (is_medion) {
903
+ int ret;
904
+
905
+ ret = cxusb_medion_set_mode(dvbdev, true);
906
+ if (ret)
907
+ return ret;
908
+ }
747909
748910 adap->fe_adap[0].fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config,
749
- &adap->dev->i2c_adap);
750
- if ((adap->fe_adap[0].fe) != NULL)
751
- return 0;
911
+ &dvbdev->i2c_adap);
912
+ if (!adap->fe_adap[0].fe)
913
+ return -EIO;
752914
753
- return -EIO;
915
+ if (is_medion)
916
+ adap->fe_adap[0].fe->ops.ts_bus_ctrl =
917
+ cxusb_medion_fe_ts_bus_ctrl;
918
+
919
+ return 0;
754920 }
755921
756922 static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
....@@ -764,7 +930,7 @@
764930 &cxusb_lgdt3303_config,
765931 0x0e,
766932 &adap->dev->i2c_adap);
767
- if ((adap->fe_adap[0].fe) != NULL)
933
+ if (adap->fe_adap[0].fe)
768934 return 0;
769935
770936 return -EIO;
....@@ -776,7 +942,7 @@
776942 &cxusb_aver_lgdt3303_config,
777943 0x0e,
778944 &adap->dev->i2c_adap);
779
- if (adap->fe_adap[0].fe != NULL)
945
+ if (adap->fe_adap[0].fe)
780946 return 0;
781947
782948 return -EIO;
....@@ -792,7 +958,7 @@
792958
793959 adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_mt352_config,
794960 &adap->dev->i2c_adap);
795
- if ((adap->fe_adap[0].fe) != NULL)
961
+ if (adap->fe_adap[0].fe)
796962 return 0;
797963
798964 return -EIO;
....@@ -807,13 +973,13 @@
807973
808974 adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_dee1601_config,
809975 &adap->dev->i2c_adap);
810
- if ((adap->fe_adap[0].fe) != NULL)
976
+ if (adap->fe_adap[0].fe)
811977 return 0;
812978
813979 adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
814980 &cxusb_zl10353_dee1601_config,
815981 &adap->dev->i2c_adap);
816
- if ((adap->fe_adap[0].fe) != NULL)
982
+ if (adap->fe_adap[0].fe)
817983 return 0;
818984
819985 return -EIO;
....@@ -823,8 +989,12 @@
823989 {
824990 u8 ircode[4];
825991 int i;
826
- struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
827
- .buf = ircode, .len = 4 };
992
+ struct i2c_msg msg = {
993
+ .addr = 0x6b,
994
+ .flags = I2C_M_RD,
995
+ .buf = ircode,
996
+ .len = 4
997
+ };
828998
829999 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
8301000 err("set interface failed");
....@@ -840,7 +1010,7 @@
8401010 dvb_attach(zl10353_attach,
8411011 &cxusb_zl10353_xc3028_config_no_i2c_gate,
8421012 &adap->dev->i2c_adap);
843
- if ((adap->fe_adap[0].fe) == NULL)
1013
+ if (!adap->fe_adap[0].fe)
8441014 return -EIO;
8451015
8461016 /* try to determine if there is no IR decoder on the I2C bus */
....@@ -938,7 +1108,7 @@
9381108 };
9391109
9401110 struct dib0700_adapter_state {
941
- int (*set_param_save)(struct dvb_frontend *);
1111
+ int (*set_param_save)(struct dvb_frontend *fe);
9421112 struct dib7000p_ops dib7000p_ops;
9431113 };
9441114
....@@ -957,14 +1127,15 @@
9571127 return -ENODEV;
9581128
9591129 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
960
- &cxusb_dualdig4_rev2_config) < 0) {
961
- printk(KERN_WARNING "Unable to enumerate dib7000p\n");
1130
+ &cxusb_dualdig4_rev2_config) < 0) {
1131
+ pr_warn("Unable to enumerate dib7000p\n");
9621132 return -ENODEV;
9631133 }
9641134
965
- adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80,
966
- &cxusb_dualdig4_rev2_config);
967
- if (adap->fe_adap[0].fe == NULL)
1135
+ adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap,
1136
+ 0x80,
1137
+ &cxusb_dualdig4_rev2_config);
1138
+ if (!adap->fe_adap[0].fe)
9681139 return -EIO;
9691140
9701141 return 0;
....@@ -997,11 +1168,16 @@
9971168 struct dib0700_adapter_state *state = adap->priv;
9981169
9991170 u16 offset;
1000
- u8 band = BAND_OF_FREQUENCY(p->frequency/1000);
1171
+ u8 band = BAND_OF_FREQUENCY(p->frequency / 1000);
1172
+
10011173 switch (band) {
1002
- case BAND_VHF: offset = 950; break;
1174
+ case BAND_VHF:
1175
+ offset = 950;
1176
+ break;
10031177 default:
1004
- case BAND_UHF: offset = 550; break;
1178
+ case BAND_UHF:
1179
+ offset = 550;
1180
+ break;
10051181 }
10061182
10071183 state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
....@@ -1017,13 +1193,13 @@
10171193 /*
10181194 * No need to call dvb7000p_attach here, as it was called
10191195 * already, as frontend_attach method is called first, and
1020
- * tuner_attach is only called on sucess.
1196
+ * tuner_attach is only called on success.
10211197 */
10221198 tun_i2c = st->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
10231199 DIBX000_I2C_INTERFACE_TUNER, 1);
10241200
10251201 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
1026
- &dib7070p_dib0070_config) == NULL)
1202
+ &dib7070p_dib0070_config) == NULL)
10271203 return -ENODEV;
10281204
10291205 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
....@@ -1046,13 +1222,13 @@
10461222 adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
10471223 &cxusb_zl10353_xc3028_config,
10481224 &adap->dev->i2c_adap);
1049
- if ((adap->fe_adap[0].fe) != NULL)
1225
+ if (adap->fe_adap[0].fe)
10501226 return 0;
10511227
10521228 adap->fe_adap[0].fe = dvb_attach(mt352_attach,
10531229 &cxusb_mt352_xc3028_config,
10541230 &adap->dev->i2c_adap);
1055
- if ((adap->fe_adap[0].fe) != NULL)
1231
+ if (adap->fe_adap[0].fe)
10561232 return 0;
10571233
10581234 return -EIO;
....@@ -1083,11 +1259,14 @@
10831259
10841260 /* Unblock all USB pipes */
10851261 usb_clear_halt(d->udev,
1086
- usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1262
+ usb_sndbulkpipe(d->udev,
1263
+ d->props.generic_bulk_ctrl_endpoint));
10871264 usb_clear_halt(d->udev,
1088
- usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1265
+ usb_rcvbulkpipe(d->udev,
1266
+ d->props.generic_bulk_ctrl_endpoint));
10891267 usb_clear_halt(d->udev,
1090
- usb_rcvbulkpipe(d->udev, d->props.adapter[0].fe[0].stream.endpoint));
1268
+ usb_rcvbulkpipe(d->udev,
1269
+ d->props.adapter[0].fe[0].stream.endpoint));
10911270
10921271 /* Drain USB pipes to avoid hang after reboot */
10931272 for (n = 0; n < 5; n++) {
....@@ -1109,8 +1288,9 @@
11091288 msleep(100);
11101289
11111290 /* Attach frontend */
1112
- adap->fe_adap[0].fe = dvb_attach(lgs8gxx_attach, &d680_lgs8gl5_cfg, &d->i2c_adap);
1113
- if (adap->fe_adap[0].fe == NULL)
1291
+ adap->fe_adap[0].fe = dvb_attach(lgs8gxx_attach,
1292
+ &d680_lgs8gl5_cfg, &d->i2c_adap);
1293
+ if (!adap->fe_adap[0].fe)
11141294 return -EIO;
11151295
11161296 return 0;
....@@ -1140,12 +1320,14 @@
11401320
11411321 /* Unblock all USB pipes */
11421322 usb_clear_halt(d->udev,
1143
- usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1323
+ usb_sndbulkpipe(d->udev,
1324
+ d->props.generic_bulk_ctrl_endpoint));
11441325 usb_clear_halt(d->udev,
1145
- usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1326
+ usb_rcvbulkpipe(d->udev,
1327
+ d->props.generic_bulk_ctrl_endpoint));
11461328 usb_clear_halt(d->udev,
1147
- usb_rcvbulkpipe(d->udev, d->props.adapter[0].fe[0].stream.endpoint));
1148
-
1329
+ usb_rcvbulkpipe(d->udev,
1330
+ d->props.adapter[0].fe[0].stream.endpoint));
11491331
11501332 /* Reset the tuner */
11511333 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
....@@ -1160,87 +1342,11 @@
11601342 msleep(100);
11611343
11621344 /* Attach frontend */
1163
- adap->fe_adap[0].fe = dvb_attach(atbm8830_attach, &mygica_d689_atbm8830_cfg,
1164
- &d->i2c_adap);
1165
- if (adap->fe_adap[0].fe == NULL)
1345
+ adap->fe_adap[0].fe = dvb_attach(atbm8830_attach,
1346
+ &mygica_d689_atbm8830_cfg,
1347
+ &d->i2c_adap);
1348
+ if (!adap->fe_adap[0].fe)
11661349 return -EIO;
1167
-
1168
- return 0;
1169
-}
1170
-
1171
-static int cxusb_mygica_t230_frontend_attach(struct dvb_usb_adapter *adap)
1172
-{
1173
- struct dvb_usb_device *d = adap->dev;
1174
- struct cxusb_state *st = d->priv;
1175
- struct i2c_adapter *adapter;
1176
- struct i2c_client *client_demod;
1177
- struct i2c_client *client_tuner;
1178
- struct i2c_board_info info;
1179
- struct si2168_config si2168_config;
1180
- struct si2157_config si2157_config;
1181
-
1182
- /* Select required USB configuration */
1183
- if (usb_set_interface(d->udev, 0, 0) < 0)
1184
- err("set interface failed");
1185
-
1186
- /* Unblock all USB pipes */
1187
- usb_clear_halt(d->udev,
1188
- usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1189
- usb_clear_halt(d->udev,
1190
- usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1191
- usb_clear_halt(d->udev,
1192
- usb_rcvbulkpipe(d->udev, d->props.adapter[0].fe[0].stream.endpoint));
1193
-
1194
- /* attach frontend */
1195
- si2168_config.i2c_adapter = &adapter;
1196
- si2168_config.fe = &adap->fe_adap[0].fe;
1197
- si2168_config.ts_mode = SI2168_TS_PARALLEL;
1198
- si2168_config.ts_clock_inv = 1;
1199
- memset(&info, 0, sizeof(struct i2c_board_info));
1200
- strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1201
- info.addr = 0x64;
1202
- info.platform_data = &si2168_config;
1203
- request_module(info.type);
1204
- client_demod = i2c_new_device(&d->i2c_adap, &info);
1205
- if (client_demod == NULL || client_demod->dev.driver == NULL)
1206
- return -ENODEV;
1207
-
1208
- if (!try_module_get(client_demod->dev.driver->owner)) {
1209
- i2c_unregister_device(client_demod);
1210
- return -ENODEV;
1211
- }
1212
-
1213
- st->i2c_client_demod = client_demod;
1214
-
1215
- /* attach tuner */
1216
- memset(&si2157_config, 0, sizeof(si2157_config));
1217
- si2157_config.fe = adap->fe_adap[0].fe;
1218
- si2157_config.if_port = 1;
1219
- memset(&info, 0, sizeof(struct i2c_board_info));
1220
- strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1221
- info.addr = 0x60;
1222
- info.platform_data = &si2157_config;
1223
- request_module(info.type);
1224
- client_tuner = i2c_new_device(adapter, &info);
1225
- if (client_tuner == NULL || client_tuner->dev.driver == NULL) {
1226
- module_put(client_demod->dev.driver->owner);
1227
- i2c_unregister_device(client_demod);
1228
- return -ENODEV;
1229
- }
1230
- if (!try_module_get(client_tuner->dev.driver->owner)) {
1231
- i2c_unregister_device(client_tuner);
1232
- module_put(client_demod->dev.driver->owner);
1233
- i2c_unregister_device(client_demod);
1234
- return -ENODEV;
1235
- }
1236
-
1237
- st->i2c_client_tuner = client_tuner;
1238
-
1239
- /* hook fe: need to resync the slave fifo when signal locks. */
1240
- mutex_init(&st->stream_mutex);
1241
- st->last_lock = 0;
1242
- st->fe_read_status = adap->fe_adap[0].fe->ops.read_status;
1243
- adap->fe_adap[0].fe->ops.read_status = cxusb_read_status;
12441350
12451351 return 0;
12461352 }
....@@ -1252,8 +1358,8 @@
12521358 * not, and forget a match if it turns out we selected the wrong device.
12531359 */
12541360 static int bluebird_fx2_identify_state(struct usb_device *udev,
1255
- struct dvb_usb_device_properties *props,
1256
- struct dvb_usb_device_description **desc,
1361
+ const struct dvb_usb_device_properties *props,
1362
+ const struct dvb_usb_device_description **desc,
12571363 int *cold)
12581364 {
12591365 int wascold = *cold;
....@@ -1313,6 +1419,104 @@
13131419 return -EINVAL;
13141420 }
13151421
1422
+int cxusb_medion_get(struct dvb_usb_device *dvbdev,
1423
+ enum cxusb_open_type open_type)
1424
+{
1425
+ struct cxusb_medion_dev *cxdev = dvbdev->priv;
1426
+ int ret = 0;
1427
+
1428
+ mutex_lock(&cxdev->open_lock);
1429
+
1430
+ if (WARN_ON((cxdev->open_type == CXUSB_OPEN_INIT ||
1431
+ cxdev->open_type == CXUSB_OPEN_NONE) &&
1432
+ cxdev->open_ctr != 0)) {
1433
+ ret = -EINVAL;
1434
+ goto ret_unlock;
1435
+ }
1436
+
1437
+ if (cxdev->open_type == CXUSB_OPEN_INIT) {
1438
+ ret = -EAGAIN;
1439
+ goto ret_unlock;
1440
+ }
1441
+
1442
+ if (cxdev->open_ctr == 0) {
1443
+ if (cxdev->open_type != open_type) {
1444
+ dev_info(&dvbdev->udev->dev, "will acquire and switch to %s\n",
1445
+ open_type == CXUSB_OPEN_ANALOG ?
1446
+ "analog" : "digital");
1447
+
1448
+ if (open_type == CXUSB_OPEN_ANALOG) {
1449
+ ret = _cxusb_power_ctrl(dvbdev, 1);
1450
+ if (ret != 0)
1451
+ dev_warn(&dvbdev->udev->dev,
1452
+ "powerup for analog switch failed (%d)\n",
1453
+ ret);
1454
+
1455
+ ret = cxusb_medion_set_mode(dvbdev, false);
1456
+ if (ret != 0)
1457
+ goto ret_unlock;
1458
+
1459
+ ret = cxusb_medion_analog_init(dvbdev);
1460
+ if (ret != 0)
1461
+ goto ret_unlock;
1462
+ } else { /* digital */
1463
+ ret = _cxusb_power_ctrl(dvbdev, 1);
1464
+ if (ret != 0)
1465
+ dev_warn(&dvbdev->udev->dev,
1466
+ "powerup for digital switch failed (%d)\n",
1467
+ ret);
1468
+
1469
+ ret = cxusb_medion_set_mode(dvbdev, true);
1470
+ if (ret != 0)
1471
+ goto ret_unlock;
1472
+ }
1473
+
1474
+ cxdev->open_type = open_type;
1475
+ } else {
1476
+ dev_info(&dvbdev->udev->dev, "reacquired idle %s\n",
1477
+ open_type == CXUSB_OPEN_ANALOG ?
1478
+ "analog" : "digital");
1479
+ }
1480
+
1481
+ cxdev->open_ctr = 1;
1482
+ } else if (cxdev->open_type == open_type) {
1483
+ cxdev->open_ctr++;
1484
+ dev_info(&dvbdev->udev->dev, "acquired %s\n",
1485
+ open_type == CXUSB_OPEN_ANALOG ? "analog" : "digital");
1486
+ } else {
1487
+ ret = -EBUSY;
1488
+ }
1489
+
1490
+ret_unlock:
1491
+ mutex_unlock(&cxdev->open_lock);
1492
+
1493
+ return ret;
1494
+}
1495
+
1496
+void cxusb_medion_put(struct dvb_usb_device *dvbdev)
1497
+{
1498
+ struct cxusb_medion_dev *cxdev = dvbdev->priv;
1499
+
1500
+ mutex_lock(&cxdev->open_lock);
1501
+
1502
+ if (cxdev->open_type == CXUSB_OPEN_INIT) {
1503
+ WARN_ON(cxdev->open_ctr != 0);
1504
+ cxdev->open_type = CXUSB_OPEN_NONE;
1505
+ goto unlock;
1506
+ }
1507
+
1508
+ if (!WARN_ON(cxdev->open_ctr < 1)) {
1509
+ cxdev->open_ctr--;
1510
+
1511
+ dev_info(&dvbdev->udev->dev, "release %s\n",
1512
+ cxdev->open_type == CXUSB_OPEN_ANALOG ?
1513
+ "analog" : "digital");
1514
+ }
1515
+
1516
+unlock:
1517
+ mutex_unlock(&cxdev->open_lock);
1518
+}
1519
+
13161520 /* DVB USB Driver stuff */
13171521 static struct dvb_usb_device_properties cxusb_medion_properties;
13181522 static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties;
....@@ -1326,43 +1530,140 @@
13261530 static struct dvb_usb_device_properties cxusb_aver_a868r_properties;
13271531 static struct dvb_usb_device_properties cxusb_d680_dmb_properties;
13281532 static struct dvb_usb_device_properties cxusb_mygica_d689_properties;
1329
-static struct dvb_usb_device_properties cxusb_mygica_t230_properties;
1533
+
1534
+static int cxusb_medion_priv_init(struct dvb_usb_device *dvbdev)
1535
+{
1536
+ struct cxusb_medion_dev *cxdev = dvbdev->priv;
1537
+
1538
+ cxdev->dvbdev = dvbdev;
1539
+ cxdev->open_type = CXUSB_OPEN_INIT;
1540
+ mutex_init(&cxdev->open_lock);
1541
+
1542
+ return 0;
1543
+}
1544
+
1545
+static void cxusb_medion_priv_destroy(struct dvb_usb_device *dvbdev)
1546
+{
1547
+ struct cxusb_medion_dev *cxdev = dvbdev->priv;
1548
+
1549
+ mutex_destroy(&cxdev->open_lock);
1550
+}
1551
+
1552
+static bool cxusb_medion_check_altsetting(struct usb_host_interface *as)
1553
+{
1554
+ unsigned int ctr;
1555
+
1556
+ for (ctr = 0; ctr < as->desc.bNumEndpoints; ctr++) {
1557
+ if ((as->endpoint[ctr].desc.bEndpointAddress &
1558
+ USB_ENDPOINT_NUMBER_MASK) != 2)
1559
+ continue;
1560
+
1561
+ if (as->endpoint[ctr].desc.bEndpointAddress & USB_DIR_IN &&
1562
+ ((as->endpoint[ctr].desc.bmAttributes &
1563
+ USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_ISOC))
1564
+ return true;
1565
+
1566
+ break;
1567
+ }
1568
+
1569
+ return false;
1570
+}
1571
+
1572
+static bool cxusb_medion_check_intf(struct usb_interface *intf)
1573
+{
1574
+ unsigned int ctr;
1575
+
1576
+ if (intf->num_altsetting < 2) {
1577
+ dev_err(intf->usb_dev, "no alternate interface");
1578
+
1579
+ return false;
1580
+ }
1581
+
1582
+ for (ctr = 0; ctr < intf->num_altsetting; ctr++) {
1583
+ if (intf->altsetting[ctr].desc.bAlternateSetting != 1)
1584
+ continue;
1585
+
1586
+ if (cxusb_medion_check_altsetting(&intf->altsetting[ctr]))
1587
+ return true;
1588
+
1589
+ break;
1590
+ }
1591
+
1592
+ dev_err(intf->usb_dev, "no iso interface");
1593
+
1594
+ return false;
1595
+}
13301596
13311597 static int cxusb_probe(struct usb_interface *intf,
13321598 const struct usb_device_id *id)
13331599 {
1334
- if (0 == dvb_usb_device_init(intf, &cxusb_medion_properties,
1335
- THIS_MODULE, NULL, adapter_nr) ||
1336
- 0 == dvb_usb_device_init(intf, &cxusb_bluebird_lgh064f_properties,
1337
- THIS_MODULE, NULL, adapter_nr) ||
1338
- 0 == dvb_usb_device_init(intf, &cxusb_bluebird_dee1601_properties,
1339
- THIS_MODULE, NULL, adapter_nr) ||
1340
- 0 == dvb_usb_device_init(intf, &cxusb_bluebird_lgz201_properties,
1341
- THIS_MODULE, NULL, adapter_nr) ||
1342
- 0 == dvb_usb_device_init(intf, &cxusb_bluebird_dtt7579_properties,
1343
- THIS_MODULE, NULL, adapter_nr) ||
1344
- 0 == dvb_usb_device_init(intf, &cxusb_bluebird_dualdig4_properties,
1345
- THIS_MODULE, NULL, adapter_nr) ||
1346
- 0 == dvb_usb_device_init(intf, &cxusb_bluebird_nano2_properties,
1347
- THIS_MODULE, NULL, adapter_nr) ||
1348
- 0 == dvb_usb_device_init(intf,
1349
- &cxusb_bluebird_nano2_needsfirmware_properties,
1350
- THIS_MODULE, NULL, adapter_nr) ||
1351
- 0 == dvb_usb_device_init(intf, &cxusb_aver_a868r_properties,
1352
- THIS_MODULE, NULL, adapter_nr) ||
1353
- 0 == dvb_usb_device_init(intf,
1354
- &cxusb_bluebird_dualdig4_rev2_properties,
1355
- THIS_MODULE, NULL, adapter_nr) ||
1356
- 0 == dvb_usb_device_init(intf, &cxusb_d680_dmb_properties,
1357
- THIS_MODULE, NULL, adapter_nr) ||
1358
- 0 == dvb_usb_device_init(intf, &cxusb_mygica_d689_properties,
1359
- THIS_MODULE, NULL, adapter_nr) ||
1360
- 0 == dvb_usb_device_init(intf, &cxusb_mygica_t230_properties,
1361
- THIS_MODULE, NULL, adapter_nr) ||
1362
- 0)
1600
+ struct dvb_usb_device *dvbdev;
1601
+ int ret;
1602
+
1603
+ /* Medion 95700 */
1604
+ if (!dvb_usb_device_init(intf, &cxusb_medion_properties,
1605
+ THIS_MODULE, &dvbdev, adapter_nr)) {
1606
+ if (!cxusb_medion_check_intf(intf)) {
1607
+ ret = -ENODEV;
1608
+ goto ret_uninit;
1609
+ }
1610
+
1611
+ _cxusb_power_ctrl(dvbdev, 1);
1612
+ ret = cxusb_medion_set_mode(dvbdev, false);
1613
+ if (ret)
1614
+ goto ret_uninit;
1615
+
1616
+ ret = cxusb_medion_register_analog(dvbdev);
1617
+
1618
+ cxusb_medion_set_mode(dvbdev, true);
1619
+ _cxusb_power_ctrl(dvbdev, 0);
1620
+
1621
+ if (ret != 0)
1622
+ goto ret_uninit;
1623
+
1624
+ /* release device from INIT mode to normal operation */
1625
+ cxusb_medion_put(dvbdev);
1626
+
1627
+ return 0;
1628
+ } else if (!dvb_usb_device_init(intf,
1629
+ &cxusb_bluebird_lgh064f_properties,
1630
+ THIS_MODULE, NULL, adapter_nr) ||
1631
+ !dvb_usb_device_init(intf,
1632
+ &cxusb_bluebird_dee1601_properties,
1633
+ THIS_MODULE, NULL, adapter_nr) ||
1634
+ !dvb_usb_device_init(intf,
1635
+ &cxusb_bluebird_lgz201_properties,
1636
+ THIS_MODULE, NULL, adapter_nr) ||
1637
+ !dvb_usb_device_init(intf,
1638
+ &cxusb_bluebird_dtt7579_properties,
1639
+ THIS_MODULE, NULL, adapter_nr) ||
1640
+ !dvb_usb_device_init(intf,
1641
+ &cxusb_bluebird_dualdig4_properties,
1642
+ THIS_MODULE, NULL, adapter_nr) ||
1643
+ !dvb_usb_device_init(intf,
1644
+ &cxusb_bluebird_nano2_properties,
1645
+ THIS_MODULE, NULL, adapter_nr) ||
1646
+ !dvb_usb_device_init(intf,
1647
+ &cxusb_bluebird_nano2_needsfirmware_properties,
1648
+ THIS_MODULE, NULL, adapter_nr) ||
1649
+ !dvb_usb_device_init(intf, &cxusb_aver_a868r_properties,
1650
+ THIS_MODULE, NULL, adapter_nr) ||
1651
+ !dvb_usb_device_init(intf,
1652
+ &cxusb_bluebird_dualdig4_rev2_properties,
1653
+ THIS_MODULE, NULL, adapter_nr) ||
1654
+ !dvb_usb_device_init(intf, &cxusb_d680_dmb_properties,
1655
+ THIS_MODULE, NULL, adapter_nr) ||
1656
+ !dvb_usb_device_init(intf, &cxusb_mygica_d689_properties,
1657
+ THIS_MODULE, NULL, adapter_nr) ||
1658
+ 0)
13631659 return 0;
13641660
13651661 return -EINVAL;
1662
+
1663
+ret_uninit:
1664
+ dvb_usb_device_exit(intf);
1665
+
1666
+ return ret;
13661667 }
13671668
13681669 static void cxusb_disconnect(struct usb_interface *intf)
....@@ -1370,6 +1671,9 @@
13701671 struct dvb_usb_device *d = usb_get_intfdata(intf);
13711672 struct cxusb_state *st = d->priv;
13721673 struct i2c_client *client;
1674
+
1675
+ if (d->props.devices[0].warm_ids[0] == &cxusb_table[MEDION_MD95700])
1676
+ cxusb_medion_unregister_analog(d);
13731677
13741678 /* remove I2C client for tuner */
13751679 client = st->i2c_client_tuner;
....@@ -1387,31 +1691,6 @@
13871691
13881692 dvb_usb_device_exit(intf);
13891693 }
1390
-
1391
-enum cxusb_table_index {
1392
- MEDION_MD95700,
1393
- DVICO_BLUEBIRD_LG064F_COLD,
1394
- DVICO_BLUEBIRD_LG064F_WARM,
1395
- DVICO_BLUEBIRD_DUAL_1_COLD,
1396
- DVICO_BLUEBIRD_DUAL_1_WARM,
1397
- DVICO_BLUEBIRD_LGZ201_COLD,
1398
- DVICO_BLUEBIRD_LGZ201_WARM,
1399
- DVICO_BLUEBIRD_TH7579_COLD,
1400
- DVICO_BLUEBIRD_TH7579_WARM,
1401
- DIGITALNOW_BLUEBIRD_DUAL_1_COLD,
1402
- DIGITALNOW_BLUEBIRD_DUAL_1_WARM,
1403
- DVICO_BLUEBIRD_DUAL_2_COLD,
1404
- DVICO_BLUEBIRD_DUAL_2_WARM,
1405
- DVICO_BLUEBIRD_DUAL_4,
1406
- DVICO_BLUEBIRD_DVB_T_NANO_2,
1407
- DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM,
1408
- AVERMEDIA_VOLAR_A868R,
1409
- DVICO_BLUEBIRD_DUAL_4_REV_2,
1410
- CONEXANT_D680_DMB,
1411
- MYGICA_D689,
1412
- MYGICA_T230,
1413
- NR__cxusb_table_index
1414
-};
14151694
14161695 static struct usb_device_id cxusb_table[NR__cxusb_table_index + 1] = {
14171696 [MEDION_MD95700] = {
....@@ -1442,10 +1721,12 @@
14421721 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_WARM)
14431722 },
14441723 [DIGITALNOW_BLUEBIRD_DUAL_1_COLD] = {
1445
- USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD)
1724
+ USB_DEVICE(USB_VID_DVICO,
1725
+ USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD)
14461726 },
14471727 [DIGITALNOW_BLUEBIRD_DUAL_1_WARM] = {
1448
- USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM)
1728
+ USB_DEVICE(USB_VID_DVICO,
1729
+ USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM)
14491730 },
14501731 [DVICO_BLUEBIRD_DUAL_2_COLD] = {
14511732 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD)
....@@ -1460,7 +1741,8 @@
14601741 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2)
14611742 },
14621743 [DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM] = {
1463
- USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM)
1744
+ USB_DEVICE(USB_VID_DVICO,
1745
+ USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM)
14641746 },
14651747 [AVERMEDIA_VOLAR_A868R] = {
14661748 USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R)
....@@ -1474,19 +1756,18 @@
14741756 [MYGICA_D689] = {
14751757 USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_D689)
14761758 },
1477
- [MYGICA_T230] = {
1478
- USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_T230)
1479
- },
14801759 {} /* Terminating entry */
14811760 };
1482
-MODULE_DEVICE_TABLE (usb, cxusb_table);
1761
+MODULE_DEVICE_TABLE(usb, cxusb_table);
14831762
14841763 static struct dvb_usb_device_properties cxusb_medion_properties = {
14851764 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
14861765
14871766 .usb_ctrl = CYPRESS_FX2,
14881767
1489
- .size_of_priv = sizeof(struct cxusb_state),
1768
+ .size_of_priv = sizeof(struct cxusb_medion_dev),
1769
+ .priv_init = cxusb_medion_priv_init,
1770
+ .priv_destroy = cxusb_medion_priv_destroy,
14901771
14911772 .num_adapters = 1,
14921773 .adapter = {
....@@ -1507,7 +1788,7 @@
15071788 }
15081789 }
15091790 },
1510
- }},
1791
+ } },
15111792 },
15121793 },
15131794 .power_ctrl = cxusb_power_ctrl,
....@@ -1518,7 +1799,8 @@
15181799
15191800 .num_device_descs = 1,
15201801 .devices = {
1521
- { "Medion MD95700 (MDUSBTV-HYBRID)",
1802
+ {
1803
+ "Medion MD95700 (MDUSBTV-HYBRID)",
15221804 { NULL },
15231805 { &cxusb_table[MEDION_MD95700], NULL },
15241806 },
....@@ -1531,8 +1813,10 @@
15311813 .usb_ctrl = DEVICE_SPECIFIC,
15321814 .firmware = "dvb-usb-bluebird-01.fw",
15331815 .download_firmware = bluebird_patch_dvico_firmware_download,
1534
- /* use usb alt setting 0 for EP4 transfer (dvb-t),
1535
- use usb alt setting 7 for EP2 transfer (atsc) */
1816
+ /*
1817
+ * use usb alt setting 0 for EP4 transfer (dvb-t),
1818
+ * use usb alt setting 7 for EP2 transfer (atsc)
1819
+ */
15361820
15371821 .size_of_priv = sizeof(struct cxusb_state),
15381822
....@@ -1556,7 +1840,7 @@
15561840 }
15571841 }
15581842 },
1559
- }},
1843
+ } },
15601844 },
15611845 },
15621846
....@@ -1589,8 +1873,10 @@
15891873 .usb_ctrl = DEVICE_SPECIFIC,
15901874 .firmware = "dvb-usb-bluebird-01.fw",
15911875 .download_firmware = bluebird_patch_dvico_firmware_download,
1592
- /* use usb alt setting 0 for EP4 transfer (dvb-t),
1593
- use usb alt setting 7 for EP2 transfer (atsc) */
1876
+ /*
1877
+ * use usb alt setting 0 for EP4 transfer (dvb-t),
1878
+ * use usb alt setting 7 for EP2 transfer (atsc)
1879
+ */
15941880
15951881 .size_of_priv = sizeof(struct cxusb_state),
15961882
....@@ -1613,7 +1899,7 @@
16131899 }
16141900 }
16151901 },
1616
- }},
1902
+ } },
16171903 },
16181904 },
16191905
....@@ -1638,7 +1924,7 @@
16381924 { &cxusb_table[DVICO_BLUEBIRD_DUAL_1_WARM], NULL },
16391925 },
16401926 { "DigitalNow DVB-T Dual USB",
1641
- { &cxusb_table[DIGITALNOW_BLUEBIRD_DUAL_1_COLD], NULL },
1927
+ { &cxusb_table[DIGITALNOW_BLUEBIRD_DUAL_1_COLD], NULL },
16421928 { &cxusb_table[DIGITALNOW_BLUEBIRD_DUAL_1_WARM], NULL },
16431929 },
16441930 { "DViCO FusionHDTV DVB-T Dual Digital 2",
....@@ -1654,8 +1940,10 @@
16541940 .usb_ctrl = DEVICE_SPECIFIC,
16551941 .firmware = "dvb-usb-bluebird-01.fw",
16561942 .download_firmware = bluebird_patch_dvico_firmware_download,
1657
- /* use usb alt setting 0 for EP4 transfer (dvb-t),
1658
- use usb alt setting 7 for EP2 transfer (atsc) */
1943
+ /*
1944
+ * use usb alt setting 0 for EP4 transfer (dvb-t),
1945
+ * use usb alt setting 7 for EP2 transfer (atsc)
1946
+ */
16591947
16601948 .size_of_priv = sizeof(struct cxusb_state),
16611949
....@@ -1679,7 +1967,7 @@
16791967 }
16801968 }
16811969 },
1682
- }},
1970
+ } },
16831971 },
16841972 },
16851973 .power_ctrl = cxusb_bluebird_power_ctrl,
....@@ -1710,8 +1998,11 @@
17101998 .usb_ctrl = DEVICE_SPECIFIC,
17111999 .firmware = "dvb-usb-bluebird-01.fw",
17122000 .download_firmware = bluebird_patch_dvico_firmware_download,
1713
- /* use usb alt setting 0 for EP4 transfer (dvb-t),
1714
- use usb alt setting 7 for EP2 transfer (atsc) */
2001
+
2002
+ /*
2003
+ * use usb alt setting 0 for EP4 transfer (dvb-t),
2004
+ * use usb alt setting 7 for EP2 transfer (atsc)
2005
+ */
17152006
17162007 .size_of_priv = sizeof(struct cxusb_state),
17172008
....@@ -1735,7 +2026,7 @@
17352026 }
17362027 }
17372028 },
1738
- }},
2029
+ } },
17392030 },
17402031 },
17412032 .power_ctrl = cxusb_bluebird_power_ctrl,
....@@ -1787,7 +2078,7 @@
17872078 }
17882079 }
17892080 },
1790
- }},
2081
+ } },
17912082 },
17922083 },
17932084
....@@ -1841,7 +2132,7 @@
18412132 }
18422133 }
18432134 },
1844
- }},
2135
+ } },
18452136 },
18462137 },
18472138
....@@ -1868,7 +2159,8 @@
18682159 }
18692160 };
18702161
1871
-static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties = {
2162
+static struct dvb_usb_device_properties
2163
+cxusb_bluebird_nano2_needsfirmware_properties = {
18722164 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
18732165
18742166 .usb_ctrl = DEVICE_SPECIFIC,
....@@ -1897,7 +2189,7 @@
18972189 }
18982190 }
18992191 },
1900
- }},
2192
+ } },
19012193 },
19022194 },
19032195
....@@ -1916,10 +2208,11 @@
19162208 },
19172209
19182210 .num_device_descs = 1,
1919
- .devices = {
1920
- { "DViCO FusionHDTV DVB-T NANO2 w/o firmware",
2211
+ .devices = { {
2212
+ "DViCO FusionHDTV DVB-T NANO2 w/o firmware",
19212213 { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2], NULL },
1922
- { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM], NULL },
2214
+ { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM],
2215
+ NULL },
19232216 },
19242217 }
19252218 };
....@@ -1950,7 +2243,7 @@
19502243 }
19512244 }
19522245 },
1953
- }},
2246
+ } },
19542247 },
19552248 },
19562249 .power_ctrl = cxusb_aver_power_ctrl,
....@@ -1996,7 +2289,7 @@
19962289 }
19972290 }
19982291 },
1999
- }},
2292
+ } },
20002293 },
20012294 },
20022295
....@@ -2050,7 +2343,7 @@
20502343 }
20512344 }
20522345 },
2053
- }},
2346
+ } },
20542347 },
20552348 },
20562349
....@@ -2105,7 +2398,7 @@
21052398 }
21062399 }
21072400 },
2108
- }},
2401
+ } },
21092402 },
21102403 },
21112404
....@@ -2133,60 +2426,6 @@
21332426 }
21342427 };
21352428
2136
-static struct dvb_usb_device_properties cxusb_mygica_t230_properties = {
2137
- .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2138
-
2139
- .usb_ctrl = CYPRESS_FX2,
2140
-
2141
- .size_of_priv = sizeof(struct cxusb_state),
2142
-
2143
- .num_adapters = 1,
2144
- .adapter = {
2145
- {
2146
- .num_frontends = 1,
2147
- .fe = {{
2148
- .streaming_ctrl = cxusb_streaming_ctrl,
2149
- .frontend_attach = cxusb_mygica_t230_frontend_attach,
2150
-
2151
- /* parameter for the MPEG2-data transfer */
2152
- .stream = {
2153
- .type = USB_BULK,
2154
- .count = 5,
2155
- .endpoint = 0x02,
2156
- .u = {
2157
- .bulk = {
2158
- .buffersize = 8192,
2159
- }
2160
- }
2161
- },
2162
- } },
2163
- },
2164
- },
2165
-
2166
- .power_ctrl = cxusb_d680_dmb_power_ctrl,
2167
-
2168
- .i2c_algo = &cxusb_i2c_algo,
2169
-
2170
- .generic_bulk_ctrl_endpoint = 0x01,
2171
-
2172
- .rc.core = {
2173
- .rc_interval = 100,
2174
- .rc_codes = RC_MAP_D680_DMB,
2175
- .module_name = KBUILD_MODNAME,
2176
- .rc_query = cxusb_d680_dmb_rc_query,
2177
- .allowed_protos = RC_PROTO_BIT_UNKNOWN,
2178
- },
2179
-
2180
- .num_device_descs = 1,
2181
- .devices = {
2182
- {
2183
- "Mygica T230 DVB-T/T2/C",
2184
- { NULL },
2185
- { &cxusb_table[MYGICA_T230], NULL },
2186
- },
2187
- }
2188
-};
2189
-
21902429 static struct usb_driver cxusb_driver = {
21912430 .name = "dvb_usb_cxusb",
21922431 .probe = cxusb_probe,
....@@ -2199,6 +2438,6 @@
21992438 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>");
22002439 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
22012440 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
2441
+MODULE_AUTHOR("Maciej S. Szmigiero <mail@maciej.szmigiero.name>");
22022442 MODULE_DESCRIPTION("Driver for Conexant USB2.0 hybrid reference design");
2203
-MODULE_VERSION("1.0-alpha");
22042443 MODULE_LICENSE("GPL");