aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb
diff options
context:
space:
mode:
authorAntti Palosaari <crope@iki.fi>2012-08-12 21:27:07 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-08-13 14:58:12 -0400
commitc01a35955fc6cbf4b36fd87c4af5691a81fcda5a (patch)
treeb6c2ba06d98f226d48d7b1bcab89859c55fec7f9 /drivers/media/dvb
parentd584b8386e1dacfb153cd9962ae2a01142234750 (diff)
[media] rtl28xxu: convert to new DVB USB
Tested-by: Hin-Tak Leung <htl10@users.sourceforge.net> Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb')
-rw-r--r--drivers/media/dvb/dvb-usb-v2/Kconfig13
-rw-r--r--drivers/media/dvb/dvb-usb-v2/Makefile3
-rw-r--r--drivers/media/dvb/dvb-usb-v2/rtl28xxu.c (renamed from drivers/media/dvb/dvb-usb/rtl28xxu.c)607
-rw-r--r--drivers/media/dvb/dvb-usb-v2/rtl28xxu.h (renamed from drivers/media/dvb/dvb-usb/rtl28xxu.h)26
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig13
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile3
6 files changed, 260 insertions, 405 deletions
diff --git a/drivers/media/dvb/dvb-usb-v2/Kconfig b/drivers/media/dvb/dvb-usb-v2/Kconfig
index 14a635b97b0b..ed87935dc8d4 100644
--- a/drivers/media/dvb/dvb-usb-v2/Kconfig
+++ b/drivers/media/dvb/dvb-usb-v2/Kconfig
@@ -124,3 +124,16 @@ config DVB_USB_MXL111SF
124 help 124 help
125 Say Y here to support the MxL111SF USB2.0 DTV receiver. 125 Say Y here to support the MxL111SF USB2.0 DTV receiver.
126 126
127config DVB_USB_RTL28XXU
128 tristate "Realtek RTL28xxU DVB USB support"
129 depends on DVB_USB_V2 && EXPERIMENTAL
130 select DVB_RTL2830
131 select DVB_RTL2832
132 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE
133 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE
134 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE
135 select MEDIA_TUNER_FC0012 if !MEDIA_TUNER_CUSTOMISE
136 select MEDIA_TUNER_FC0013 if !MEDIA_TUNER_CUSTOMISE
137 help
138 Say Y here to support the Realtek RTL28xxU DVB USB receiver.
139
diff --git a/drivers/media/dvb/dvb-usb-v2/Makefile b/drivers/media/dvb/dvb-usb-v2/Makefile
index 26659bc7fa60..002e88883827 100644
--- a/drivers/media/dvb/dvb-usb-v2/Makefile
+++ b/drivers/media/dvb/dvb-usb-v2/Makefile
@@ -36,6 +36,9 @@ obj-$(CONFIG_DVB_USB_MXL111SF) += dvb-usb-mxl111sf.o
36obj-$(CONFIG_DVB_USB_MXL111SF) += mxl111sf-demod.o 36obj-$(CONFIG_DVB_USB_MXL111SF) += mxl111sf-demod.o
37obj-$(CONFIG_DVB_USB_MXL111SF) += mxl111sf-tuner.o 37obj-$(CONFIG_DVB_USB_MXL111SF) += mxl111sf-tuner.o
38 38
39dvb-usb-rtl28xxu-objs = rtl28xxu.o
40obj-$(CONFIG_DVB_USB_RTL28XXU) += dvb-usb-rtl28xxu.o
41
39ccflags-y += -I$(srctree)/drivers/media/dvb/dvb-core 42ccflags-y += -I$(srctree)/drivers/media/dvb/dvb-core
40ccflags-y += -I$(srctree)/drivers/media/dvb/frontends/ 43ccflags-y += -I$(srctree)/drivers/media/dvb/frontends/
41ccflags-y += -I$(srctree)/drivers/media/common/tuners 44ccflags-y += -I$(srctree)/drivers/media/common/tuners
diff --git a/drivers/media/dvb/dvb-usb/rtl28xxu.c b/drivers/media/dvb/dvb-usb-v2/rtl28xxu.c
index 6bd0bd792437..493d531109af 100644
--- a/drivers/media/dvb/dvb-usb/rtl28xxu.c
+++ b/drivers/media/dvb/dvb-usb-v2/rtl28xxu.c
@@ -31,10 +31,6 @@
31#include "fc0012.h" 31#include "fc0012.h"
32#include "fc0013.h" 32#include "fc0013.h"
33 33
34/* debug */
35static int dvb_usb_rtl28xxu_debug;
36module_param_named(debug, dvb_usb_rtl28xxu_debug, int, 0644);
37MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
38DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 34DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
39 35
40static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req) 36static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req)
@@ -66,8 +62,7 @@ static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req)
66 if (ret > 0) 62 if (ret > 0)
67 ret = 0; 63 ret = 0;
68 64
69 deb_dump(0, requesttype, req->value, req->index, buf, req->size, 65 deb_dump(0, requesttype, req->value, req->index, buf, req->size);
70 deb_xfer);
71 66
72 /* read request, copy returned data to return buf */ 67 /* read request, copy returned data to return buf */
73 if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN)) 68 if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN))
@@ -80,7 +75,7 @@ static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req)
80 75
81 return ret; 76 return ret;
82err: 77err:
83 deb_info("%s: failed=%d\n", __func__, ret); 78 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
84 return ret; 79 return ret;
85} 80}
86 81
@@ -291,7 +286,8 @@ static struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = {
291static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap) 286static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
292{ 287{
293 int ret; 288 int ret;
294 struct rtl28xxu_priv *priv = adap->dev->priv; 289 struct dvb_usb_device *d = adap_to_d(adap);
290 struct rtl28xxu_priv *priv = d_to_priv(d);
295 u8 buf[1]; 291 u8 buf[1];
296 struct rtl2830_config *rtl2830_config; 292 struct rtl2830_config *rtl2830_config;
297 /* open RTL2831U/RTL2830 I2C gate */ 293 /* open RTL2831U/RTL2830 I2C gate */
@@ -301,7 +297,7 @@ static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
301 /* for QT1010 tuner probe */ 297 /* for QT1010 tuner probe */
302 struct rtl28xxu_req req_qt1010 = { 0x0fc4, CMD_I2C_RD, 1, buf }; 298 struct rtl28xxu_req req_qt1010 = { 0x0fc4, CMD_I2C_RD, 1, buf };
303 299
304 deb_info("%s:\n", __func__); 300 dev_dbg(&d->udev->dev, "%s:\n", __func__);
305 301
306 /* 302 /*
307 * RTL2831U GPIOs 303 * RTL2831U GPIOs
@@ -312,12 +308,12 @@ static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
312 */ 308 */
313 309
314 /* GPIO direction */ 310 /* GPIO direction */
315 ret = rtl28xx_wr_reg(adap->dev, SYS_GPIO_DIR, 0x0a); 311 ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, 0x0a);
316 if (ret) 312 if (ret)
317 goto err; 313 goto err;
318 314
319 /* enable as output GPIO0, GPIO2, GPIO4 */ 315 /* enable as output GPIO0, GPIO2, GPIO4 */
320 ret = rtl28xx_wr_reg(adap->dev, SYS_GPIO_OUT_EN, 0x15); 316 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, 0x15);
321 if (ret) 317 if (ret)
322 goto err; 318 goto err;
323 319
@@ -330,58 +326,58 @@ static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
330 msleep(20); 326 msleep(20);
331 327
332 /* open demod I2C gate */ 328 /* open demod I2C gate */
333 ret = rtl28xxu_ctrl_msg(adap->dev, &req_gate); 329 ret = rtl28xxu_ctrl_msg(d, &req_gate);
334 if (ret) 330 if (ret)
335 goto err; 331 goto err;
336 332
337 /* check QT1010 ID(?) register; reg=0f val=2c */ 333 /* check QT1010 ID(?) register; reg=0f val=2c */
338 ret = rtl28xxu_ctrl_msg(adap->dev, &req_qt1010); 334 ret = rtl28xxu_ctrl_msg(d, &req_qt1010);
339 if (ret == 0 && buf[0] == 0x2c) { 335 if (ret == 0 && buf[0] == 0x2c) {
340 priv->tuner = TUNER_RTL2830_QT1010; 336 priv->tuner = TUNER_RTL2830_QT1010;
341 rtl2830_config = &rtl28xxu_rtl2830_qt1010_config; 337 rtl2830_config = &rtl28xxu_rtl2830_qt1010_config;
342 deb_info("%s: QT1010\n", __func__); 338 dev_dbg(&d->udev->dev, "%s: QT1010\n", __func__);
343 goto found; 339 goto found;
344 } else { 340 } else {
345 deb_info("%s: QT1010 probe failed=%d - %02x\n", 341 dev_dbg(&d->udev->dev, "%s: QT1010 probe failed=%d - %02x\n",
346 __func__, ret, buf[0]); 342 __func__, ret, buf[0]);
347 } 343 }
348 344
349 /* open demod I2C gate */ 345 /* open demod I2C gate */
350 ret = rtl28xxu_ctrl_msg(adap->dev, &req_gate); 346 ret = rtl28xxu_ctrl_msg(d, &req_gate);
351 if (ret) 347 if (ret)
352 goto err; 348 goto err;
353 349
354 /* check MT2060 ID register; reg=00 val=63 */ 350 /* check MT2060 ID register; reg=00 val=63 */
355 ret = rtl28xxu_ctrl_msg(adap->dev, &req_mt2060); 351 ret = rtl28xxu_ctrl_msg(d, &req_mt2060);
356 if (ret == 0 && buf[0] == 0x63) { 352 if (ret == 0 && buf[0] == 0x63) {
357 priv->tuner = TUNER_RTL2830_MT2060; 353 priv->tuner = TUNER_RTL2830_MT2060;
358 rtl2830_config = &rtl28xxu_rtl2830_mt2060_config; 354 rtl2830_config = &rtl28xxu_rtl2830_mt2060_config;
359 deb_info("%s: MT2060\n", __func__); 355 dev_dbg(&d->udev->dev, "%s: MT2060\n", __func__);
360 goto found; 356 goto found;
361 } else { 357 } else {
362 deb_info("%s: MT2060 probe failed=%d - %02x\n", 358 dev_dbg(&d->udev->dev, "%s: MT2060 probe failed=%d - %02x\n",
363 __func__, ret, buf[0]); 359 __func__, ret, buf[0]);
364 } 360 }
365 361
366 /* assume MXL5005S */ 362 /* assume MXL5005S */
367 ret = 0; 363 ret = 0;
368 priv->tuner = TUNER_RTL2830_MXL5005S; 364 priv->tuner = TUNER_RTL2830_MXL5005S;
369 rtl2830_config = &rtl28xxu_rtl2830_mxl5005s_config; 365 rtl2830_config = &rtl28xxu_rtl2830_mxl5005s_config;
370 deb_info("%s: MXL5005S\n", __func__); 366 dev_dbg(&d->udev->dev, "%s: MXL5005S\n", __func__);
371 goto found; 367 goto found;
372 368
373found: 369found:
374 /* attach demodulator */ 370 /* attach demodulator */
375 adap->fe_adap[0].fe = dvb_attach(rtl2830_attach, rtl2830_config, 371 adap->fe[0] = dvb_attach(rtl2830_attach, rtl2830_config,
376 &adap->dev->i2c_adap); 372 &d->i2c_adap);
377 if (adap->fe_adap[0].fe == NULL) { 373 if (adap->fe[0] == NULL) {
378 ret = -ENODEV; 374 ret = -ENODEV;
379 goto err; 375 goto err;
380 } 376 }
381 377
382 return ret; 378 return ret;
383err: 379err:
384 deb_info("%s: failed=%d\n", __func__, ret); 380 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
385 return ret; 381 return ret;
386} 382}
387 383
@@ -405,7 +401,8 @@ static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
405 int ret; 401 int ret;
406 u8 val; 402 u8 val;
407 403
408 deb_info("%s cmd=%d arg=%d\n", __func__, cmd, arg); 404 dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
405
409 switch (cmd) { 406 switch (cmd) {
410 case FC_FE_CALLBACK_VHF_ENABLE: 407 case FC_FE_CALLBACK_VHF_ENABLE:
411 /* set output values */ 408 /* set output values */
@@ -430,8 +427,7 @@ static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
430 return 0; 427 return 0;
431 428
432err: 429err:
433 err("%s: failed=%d\n", __func__, ret); 430 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
434
435 return ret; 431 return ret;
436} 432}
437 433
@@ -476,15 +472,12 @@ static int rtl2832u_frontend_callback(void *adapter_priv, int component,
476 return -EINVAL; 472 return -EINVAL;
477} 473}
478 474
479
480
481
482static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap) 475static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
483{ 476{
484 int ret; 477 int ret;
485 struct rtl28xxu_priv *priv = adap->dev->priv; 478 struct dvb_usb_device *d = adap_to_d(adap);
479 struct rtl28xxu_priv *priv = d_to_priv(d);
486 struct rtl2832_config *rtl2832_config; 480 struct rtl2832_config *rtl2832_config;
487
488 u8 buf[2], val; 481 u8 buf[2], val;
489 /* open RTL2832U/RTL2832 I2C gate */ 482 /* open RTL2832U/RTL2832 I2C gate */
490 struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"}; 483 struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"};
@@ -511,167 +504,173 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
511 /* for TDA18272 tuner probe */ 504 /* for TDA18272 tuner probe */
512 struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf}; 505 struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
513 506
514 deb_info("%s:\n", __func__); 507 dev_dbg(&d->udev->dev, "%s:\n", __func__);
515 508
516 509 ret = rtl28xx_rd_reg(d, SYS_GPIO_DIR, &val);
517 ret = rtl28xx_rd_reg(adap->dev, SYS_GPIO_DIR, &val);
518 if (ret) 510 if (ret)
519 goto err; 511 goto err;
520 512
521 val &= 0xbf; 513 val &= 0xbf;
522 514
523 ret = rtl28xx_wr_reg(adap->dev, SYS_GPIO_DIR, val); 515 ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, val);
524 if (ret) 516 if (ret)
525 goto err; 517 goto err;
526 518
527
528 /* enable as output GPIO3 and GPIO6*/ 519 /* enable as output GPIO3 and GPIO6*/
529 ret = rtl28xx_rd_reg(adap->dev, SYS_GPIO_OUT_EN, &val); 520 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_EN, &val);
530 if (ret) 521 if (ret)
531 goto err; 522 goto err;
532 523
533 val |= 0x48; 524 val |= 0x48;
534 525
535 ret = rtl28xx_wr_reg(adap->dev, SYS_GPIO_OUT_EN, val); 526 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, val);
536 if (ret) 527 if (ret)
537 goto err; 528 goto err;
538 529
539
540
541 /* 530 /*
542 * Probe used tuner. We need to know used tuner before demod attach 531 * Probe used tuner. We need to know used tuner before demod attach
543 * since there is some demod params needed to set according to tuner. 532 * since there is some demod params needed to set according to tuner.
544 */ 533 */
545 534
546 /* open demod I2C gate */ 535 /* open demod I2C gate */
547 ret = rtl28xxu_ctrl_msg(adap->dev, &req_gate_open); 536 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
548 if (ret) 537 if (ret)
549 goto err; 538 goto err;
550 539
551 priv->tuner = TUNER_NONE; 540 priv->tuner = TUNER_NONE;
552 541
553 /* check FC0012 ID register; reg=00 val=a1 */ 542 /* check FC0012 ID register; reg=00 val=a1 */
554 ret = rtl28xxu_ctrl_msg(adap->dev, &req_fc0012); 543 ret = rtl28xxu_ctrl_msg(d, &req_fc0012);
555 if (ret == 0 && buf[0] == 0xa1) { 544 if (ret == 0 && buf[0] == 0xa1) {
556 priv->tuner = TUNER_RTL2832_FC0012; 545 priv->tuner = TUNER_RTL2832_FC0012;
557 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config; 546 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
558 info("%s: FC0012 tuner found", __func__); 547 dev_info(&d->udev->dev, "%s: FC0012 tuner found",
548 KBUILD_MODNAME);
559 goto found; 549 goto found;
560 } 550 }
561 551
562 /* check FC0013 ID register; reg=00 val=a3 */ 552 /* check FC0013 ID register; reg=00 val=a3 */
563 ret = rtl28xxu_ctrl_msg(adap->dev, &req_fc0013); 553 ret = rtl28xxu_ctrl_msg(d, &req_fc0013);
564 if (ret == 0 && buf[0] == 0xa3) { 554 if (ret == 0 && buf[0] == 0xa3) {
565 priv->tuner = TUNER_RTL2832_FC0013; 555 priv->tuner = TUNER_RTL2832_FC0013;
566 rtl2832_config = &rtl28xxu_rtl2832_fc0013_config; 556 rtl2832_config = &rtl28xxu_rtl2832_fc0013_config;
567 info("%s: FC0013 tuner found", __func__); 557 dev_info(&d->udev->dev, "%s: FC0013 tuner found",
558 KBUILD_MODNAME);
568 goto found; 559 goto found;
569 } 560 }
570 561
571 /* check MT2266 ID register; reg=00 val=85 */ 562 /* check MT2266 ID register; reg=00 val=85 */
572 ret = rtl28xxu_ctrl_msg(adap->dev, &req_mt2266); 563 ret = rtl28xxu_ctrl_msg(d, &req_mt2266);
573 if (ret == 0 && buf[0] == 0x85) { 564 if (ret == 0 && buf[0] == 0x85) {
574 priv->tuner = TUNER_RTL2832_MT2266; 565 priv->tuner = TUNER_RTL2832_MT2266;
575 /* TODO implement tuner */ 566 /* TODO implement tuner */
576 info("%s: MT2266 tuner found", __func__); 567 dev_info(&d->udev->dev, "%s: MT2266 tuner found",
568 KBUILD_MODNAME);
577 goto unsupported; 569 goto unsupported;
578 } 570 }
579 571
580 /* check FC2580 ID register; reg=01 val=56 */ 572 /* check FC2580 ID register; reg=01 val=56 */
581 ret = rtl28xxu_ctrl_msg(adap->dev, &req_fc2580); 573 ret = rtl28xxu_ctrl_msg(d, &req_fc2580);
582 if (ret == 0 && buf[0] == 0x56) { 574 if (ret == 0 && buf[0] == 0x56) {
583 priv->tuner = TUNER_RTL2832_FC2580; 575 priv->tuner = TUNER_RTL2832_FC2580;
584 /* TODO implement tuner */ 576 /* TODO implement tuner */
585 info("%s: FC2580 tuner found", __func__); 577 dev_info(&d->udev->dev, "%s: FC2580 tuner found",
578 KBUILD_MODNAME);
586 goto unsupported; 579 goto unsupported;
587 } 580 }
588 581
589 /* check MT2063 ID register; reg=00 val=9e || 9c */ 582 /* check MT2063 ID register; reg=00 val=9e || 9c */
590 ret = rtl28xxu_ctrl_msg(adap->dev, &req_mt2063); 583 ret = rtl28xxu_ctrl_msg(d, &req_mt2063);
591 if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) { 584 if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) {
592 priv->tuner = TUNER_RTL2832_MT2063; 585 priv->tuner = TUNER_RTL2832_MT2063;
593 /* TODO implement tuner */ 586 /* TODO implement tuner */
594 info("%s: MT2063 tuner found", __func__); 587 dev_info(&d->udev->dev, "%s: MT2063 tuner found",
588 KBUILD_MODNAME);
595 goto unsupported; 589 goto unsupported;
596 } 590 }
597 591
598 /* check MAX3543 ID register; reg=00 val=38 */ 592 /* check MAX3543 ID register; reg=00 val=38 */
599 ret = rtl28xxu_ctrl_msg(adap->dev, &req_max3543); 593 ret = rtl28xxu_ctrl_msg(d, &req_max3543);
600 if (ret == 0 && buf[0] == 0x38) { 594 if (ret == 0 && buf[0] == 0x38) {
601 priv->tuner = TUNER_RTL2832_MAX3543; 595 priv->tuner = TUNER_RTL2832_MAX3543;
602 /* TODO implement tuner */ 596 /* TODO implement tuner */
603 info("%s: MAX3534 tuner found", __func__); 597 dev_info(&d->udev->dev, "%s: MAX3534 tuner found",
598 KBUILD_MODNAME);
604 goto unsupported; 599 goto unsupported;
605 } 600 }
606 601
607 /* check TUA9001 ID register; reg=7e val=2328 */ 602 /* check TUA9001 ID register; reg=7e val=2328 */
608 ret = rtl28xxu_ctrl_msg(adap->dev, &req_tua9001); 603 ret = rtl28xxu_ctrl_msg(d, &req_tua9001);
609 if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) { 604 if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) {
610 priv->tuner = TUNER_RTL2832_TUA9001; 605 priv->tuner = TUNER_RTL2832_TUA9001;
611 /* TODO implement tuner */ 606 /* TODO implement tuner */
612 info("%s: TUA9001 tuner found", __func__); 607 dev_info(&d->udev->dev, "%s: TUA9001 tuner found",
608 KBUILD_MODNAME);
613 goto unsupported; 609 goto unsupported;
614 } 610 }
615 611
616 /* check MXL5007R ID register; reg=d9 val=14 */ 612 /* check MXL5007R ID register; reg=d9 val=14 */
617 ret = rtl28xxu_ctrl_msg(adap->dev, &req_mxl5007t); 613 ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t);
618 if (ret == 0 && buf[0] == 0x14) { 614 if (ret == 0 && buf[0] == 0x14) {
619 priv->tuner = TUNER_RTL2832_MXL5007T; 615 priv->tuner = TUNER_RTL2832_MXL5007T;
620 /* TODO implement tuner */ 616 /* TODO implement tuner */
621 info("%s: MXL5007T tuner found", __func__); 617 dev_info(&d->udev->dev, "%s: MXL5007T tuner found",
618 KBUILD_MODNAME);
622 goto unsupported; 619 goto unsupported;
623 } 620 }
624 621
625 /* check E4000 ID register; reg=02 val=40 */ 622 /* check E4000 ID register; reg=02 val=40 */
626 ret = rtl28xxu_ctrl_msg(adap->dev, &req_e4000); 623 ret = rtl28xxu_ctrl_msg(d, &req_e4000);
627 if (ret == 0 && buf[0] == 0x40) { 624 if (ret == 0 && buf[0] == 0x40) {
628 priv->tuner = TUNER_RTL2832_E4000; 625 priv->tuner = TUNER_RTL2832_E4000;
629 /* TODO implement tuner */ 626 /* TODO implement tuner */
630 info("%s: E4000 tuner found", __func__); 627 dev_info(&d->udev->dev, "%s: E4000 tuner found",
628 KBUILD_MODNAME);
631 goto unsupported; 629 goto unsupported;
632 } 630 }
633 631
634 /* check TDA18272 ID register; reg=00 val=c760 */ 632 /* check TDA18272 ID register; reg=00 val=c760 */
635 ret = rtl28xxu_ctrl_msg(adap->dev, &req_tda18272); 633 ret = rtl28xxu_ctrl_msg(d, &req_tda18272);
636 if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) { 634 if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) {
637 priv->tuner = TUNER_RTL2832_TDA18272; 635 priv->tuner = TUNER_RTL2832_TDA18272;
638 /* TODO implement tuner */ 636 /* TODO implement tuner */
639 info("%s: TDA18272 tuner found", __func__); 637 dev_info(&d->udev->dev, "%s: TDA18272 tuner found",
638 KBUILD_MODNAME);
640 goto unsupported; 639 goto unsupported;
641 } 640 }
642 641
643unsupported: 642unsupported:
644 /* close demod I2C gate */ 643 /* close demod I2C gate */
645 ret = rtl28xxu_ctrl_msg(adap->dev, &req_gate_close); 644 ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
646 if (ret) 645 if (ret)
647 goto err; 646 goto err;
648 647
649 /* tuner not found */ 648 /* tuner not found */
650 deb_info("No compatible tuner found"); 649 dev_dbg(&d->udev->dev, "%s: No compatible tuner found\n", __func__);
651 ret = -ENODEV; 650 ret = -ENODEV;
652 return ret; 651 return ret;
653 652
654found: 653found:
655 /* close demod I2C gate */ 654 /* close demod I2C gate */
656 ret = rtl28xxu_ctrl_msg(adap->dev, &req_gate_close); 655 ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
657 if (ret) 656 if (ret)
658 goto err; 657 goto err;
659 658
660 /* attach demodulator */ 659 /* attach demodulator */
661 adap->fe_adap[0].fe = dvb_attach(rtl2832_attach, rtl2832_config, 660 adap->fe[0] = dvb_attach(rtl2832_attach, rtl2832_config,
662 &adap->dev->i2c_adap); 661 &d->i2c_adap);
663 if (adap->fe_adap[0].fe == NULL) { 662 if (adap->fe[0] == NULL) {
664 ret = -ENODEV; 663 ret = -ENODEV;
665 goto err; 664 goto err;
666 } 665 }
667 666
668 /* set fe callbacks */ 667 /* set fe callbacks */
669 adap->fe_adap[0].fe->callback = rtl2832u_frontend_callback; 668 adap->fe[0]->callback = rtl2832u_frontend_callback;
670 669
671 return ret; 670 return ret;
672 671
673err: 672err:
674 deb_info("%s: failed=%d\n", __func__, ret); 673 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
675 return ret; 674 return ret;
676} 675}
677 676
@@ -704,32 +703,34 @@ static struct mxl5005s_config rtl28xxu_mxl5005s_config = {
704static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap) 703static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap)
705{ 704{
706 int ret; 705 int ret;
707 struct rtl28xxu_priv *priv = adap->dev->priv; 706 struct dvb_usb_device *d = adap_to_d(adap);
707 struct rtl28xxu_priv *priv = d_to_priv(d);
708 struct i2c_adapter *rtl2830_tuner_i2c; 708 struct i2c_adapter *rtl2830_tuner_i2c;
709 struct dvb_frontend *fe; 709 struct dvb_frontend *fe;
710 710
711 deb_info("%s:\n", __func__); 711 dev_dbg(&d->udev->dev, "%s:\n", __func__);
712 712
713 /* use rtl2830 driver I2C adapter, for more info see rtl2830 driver */ 713 /* use rtl2830 driver I2C adapter, for more info see rtl2830 driver */
714 rtl2830_tuner_i2c = rtl2830_get_tuner_i2c_adapter(adap->fe_adap[0].fe); 714 rtl2830_tuner_i2c = rtl2830_get_tuner_i2c_adapter(adap->fe[0]);
715 715
716 switch (priv->tuner) { 716 switch (priv->tuner) {
717 case TUNER_RTL2830_QT1010: 717 case TUNER_RTL2830_QT1010:
718 fe = dvb_attach(qt1010_attach, adap->fe_adap[0].fe, 718 fe = dvb_attach(qt1010_attach, adap->fe[0],
719 rtl2830_tuner_i2c, &rtl28xxu_qt1010_config); 719 rtl2830_tuner_i2c, &rtl28xxu_qt1010_config);
720 break; 720 break;
721 case TUNER_RTL2830_MT2060: 721 case TUNER_RTL2830_MT2060:
722 fe = dvb_attach(mt2060_attach, adap->fe_adap[0].fe, 722 fe = dvb_attach(mt2060_attach, adap->fe[0],
723 rtl2830_tuner_i2c, &rtl28xxu_mt2060_config, 723 rtl2830_tuner_i2c, &rtl28xxu_mt2060_config,
724 1220); 724 1220);
725 break; 725 break;
726 case TUNER_RTL2830_MXL5005S: 726 case TUNER_RTL2830_MXL5005S:
727 fe = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe, 727 fe = dvb_attach(mxl5005s_attach, adap->fe[0],
728 rtl2830_tuner_i2c, &rtl28xxu_mxl5005s_config); 728 rtl2830_tuner_i2c, &rtl28xxu_mxl5005s_config);
729 break; 729 break;
730 default: 730 default:
731 fe = NULL; 731 fe = NULL;
732 err("unknown tuner=%d", priv->tuner); 732 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
733 priv->tuner);
733 } 734 }
734 735
735 if (fe == NULL) { 736 if (fe == NULL) {
@@ -739,40 +740,42 @@ static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap)
739 740
740 return 0; 741 return 0;
741err: 742err:
742 deb_info("%s: failed=%d\n", __func__, ret); 743 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
743 return ret; 744 return ret;
744} 745}
745 746
746static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap) 747static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
747{ 748{
748 int ret; 749 int ret;
749 struct rtl28xxu_priv *priv = adap->dev->priv; 750 struct dvb_usb_device *d = adap_to_d(adap);
751 struct rtl28xxu_priv *priv = d_to_priv(d);
750 struct dvb_frontend *fe; 752 struct dvb_frontend *fe;
751 753
752 deb_info("%s:\n", __func__); 754 dev_dbg(&d->udev->dev, "%s:\n", __func__);
753 755
754 switch (priv->tuner) { 756 switch (priv->tuner) {
755 case TUNER_RTL2832_FC0012: 757 case TUNER_RTL2832_FC0012:
756 fe = dvb_attach(fc0012_attach, adap->fe_adap[0].fe, 758 fe = dvb_attach(fc0012_attach, adap->fe[0],
757 &adap->dev->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ); 759 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
758 760
759 /* since fc0012 includs reading the signal strength delegate 761 /* since fc0012 includs reading the signal strength delegate
760 * that to the tuner driver */ 762 * that to the tuner driver */
761 adap->fe_adap[0].fe->ops.read_signal_strength = adap->fe_adap[0]. 763 adap->fe[0]->ops.read_signal_strength =
762 fe->ops.tuner_ops.get_rf_strength; 764 adap->fe[0]->ops.tuner_ops.get_rf_strength;
763 return 0; 765 return 0;
764 break; 766 break;
765 case TUNER_RTL2832_FC0013: 767 case TUNER_RTL2832_FC0013:
766 fe = dvb_attach(fc0013_attach, adap->fe_adap[0].fe, 768 fe = dvb_attach(fc0013_attach, adap->fe[0],
767 &adap->dev->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ); 769 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
768 770
769 /* fc0013 also supports signal strength reading */ 771 /* fc0013 also supports signal strength reading */
770 adap->fe_adap[0].fe->ops.read_signal_strength = adap->fe_adap[0] 772 adap->fe[0]->ops.read_signal_strength =
771 .fe->ops.tuner_ops.get_rf_strength; 773 adap->fe[0]->ops.tuner_ops.get_rf_strength;
772 return 0; 774 return 0;
773 default: 775 default:
774 fe = NULL; 776 fe = NULL;
775 err("unknown tuner=%d", priv->tuner); 777 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
778 priv->tuner);
776 } 779 }
777 780
778 if (fe == NULL) { 781 if (fe == NULL) {
@@ -782,18 +785,53 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
782 785
783 return 0; 786 return 0;
784err: 787err:
785 deb_info("%s: failed=%d\n", __func__, ret); 788 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
786 return ret; 789 return ret;
787} 790}
788 791
789static int rtl2831u_streaming_ctrl(struct dvb_usb_adapter *adap , int onoff) 792static int rtl28xxu_init(struct dvb_usb_device *d)
793{
794 int ret;
795 u8 val;
796
797 dev_dbg(&d->udev->dev, "%s:\n", __func__);
798
799 /* init USB endpoints */
800 ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val);
801 if (ret)
802 goto err;
803
804 /* enable DMA and Full Packet Mode*/
805 val |= 0x09;
806 ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val);
807 if (ret)
808 goto err;
809
810 /* set EPA maximum packet size to 0x0200 */
811 ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
812 if (ret)
813 goto err;
814
815 /* change EPA FIFO length */
816 ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
817 if (ret)
818 goto err;
819
820 return ret;
821err:
822 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
823 return ret;
824}
825
826static int rtl2831u_streaming_ctrl(struct dvb_frontend *fe , int onoff)
790{ 827{
791 int ret; 828 int ret;
792 u8 buf[2], gpio; 829 u8 buf[2], gpio;
830 struct dvb_usb_device *d = fe_to_d(fe);
793 831
794 deb_info("%s: onoff=%d\n", __func__, onoff); 832 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
795 833
796 ret = rtl28xx_rd_reg(adap->dev, SYS_GPIO_OUT_VAL, &gpio); 834 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio);
797 if (ret) 835 if (ret)
798 goto err; 836 goto err;
799 837
@@ -807,27 +845,27 @@ static int rtl2831u_streaming_ctrl(struct dvb_usb_adapter *adap , int onoff)
807 gpio &= (~0x04); /* LED off */ 845 gpio &= (~0x04); /* LED off */
808 } 846 }
809 847
810 ret = rtl28xx_wr_reg(adap->dev, SYS_GPIO_OUT_VAL, gpio); 848 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, gpio);
811 if (ret) 849 if (ret)
812 goto err; 850 goto err;
813 851
814 ret = rtl28xx_wr_regs(adap->dev, USB_EPA_CTL, buf, 2); 852 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, buf, 2);
815 if (ret) 853 if (ret)
816 goto err; 854 goto err;
817 855
818 return ret; 856 return ret;
819err: 857err:
820 deb_info("%s: failed=%d\n", __func__, ret); 858 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
821 return ret; 859 return ret;
822} 860}
823 861
824static int rtl2832u_streaming_ctrl(struct dvb_usb_adapter *adap , int onoff) 862static int rtl2832u_streaming_ctrl(struct dvb_frontend *fe , int onoff)
825{ 863{
826 int ret; 864 int ret;
827 u8 buf[2]; 865 u8 buf[2];
866 struct dvb_usb_device *d = fe_to_d(fe);
828 867
829 deb_info("%s: onoff=%d\n", __func__, onoff); 868 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
830
831 869
832 if (onoff) { 870 if (onoff) {
833 buf[0] = 0x00; 871 buf[0] = 0x00;
@@ -837,13 +875,13 @@ static int rtl2832u_streaming_ctrl(struct dvb_usb_adapter *adap , int onoff)
837 buf[1] = 0x02; /* reset EPA */ 875 buf[1] = 0x02; /* reset EPA */
838 } 876 }
839 877
840 ret = rtl28xx_wr_regs(adap->dev, USB_EPA_CTL, buf, 2); 878 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, buf, 2);
841 if (ret) 879 if (ret)
842 goto err; 880 goto err;
843 881
844 return ret; 882 return ret;
845err: 883err:
846 deb_info("%s: failed=%d\n", __func__, ret); 884 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
847 return ret; 885 return ret;
848} 886}
849 887
@@ -852,7 +890,7 @@ static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
852 int ret; 890 int ret;
853 u8 gpio, sys0; 891 u8 gpio, sys0;
854 892
855 deb_info("%s: onoff=%d\n", __func__, onoff); 893 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
856 894
857 /* demod adc */ 895 /* demod adc */
858 ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0); 896 ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0);
@@ -864,7 +902,8 @@ static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
864 if (ret) 902 if (ret)
865 goto err; 903 goto err;
866 904
867 deb_info("%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__, sys0, gpio); 905 dev_dbg(&d->udev->dev, "%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
906 sys0, gpio);
868 907
869 if (onoff) { 908 if (onoff) {
870 gpio |= 0x01; /* GPIO0 = 1 */ 909 gpio |= 0x01; /* GPIO0 = 1 */
@@ -877,7 +916,8 @@ static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
877 sys0 = sys0 & (~0xc0); 916 sys0 = sys0 & (~0xc0);
878 } 917 }
879 918
880 deb_info("%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__, sys0, gpio); 919 dev_dbg(&d->udev->dev, "%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
920 sys0, gpio);
881 921
882 /* demod adc */ 922 /* demod adc */
883 ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0); 923 ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0);
@@ -891,7 +931,7 @@ static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
891 931
892 return ret; 932 return ret;
893err: 933err:
894 deb_info("%s: failed=%d\n", __func__, ret); 934 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
895 return ret; 935 return ret;
896} 936}
897 937
@@ -900,7 +940,7 @@ static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
900 int ret; 940 int ret;
901 u8 val; 941 u8 val;
902 942
903 deb_info("%s: onoff=%d\n", __func__, onoff); 943 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
904 944
905 if (onoff) { 945 if (onoff) {
906 /* set output values */ 946 /* set output values */
@@ -1012,7 +1052,7 @@ static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
1012 1052
1013 return ret; 1053 return ret;
1014err: 1054err:
1015 deb_info("%s: failed=%d\n", __func__, ret); 1055 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
1016 return ret; 1056 return ret;
1017} 1057}
1018 1058
@@ -1085,10 +1125,21 @@ static int rtl2831u_rc_query(struct dvb_usb_device *d)
1085 1125
1086 return ret; 1126 return ret;
1087err: 1127err:
1088 deb_info("%s: failed=%d\n", __func__, ret); 1128 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
1089 return ret; 1129 return ret;
1090} 1130}
1091 1131
1132static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
1133 struct dvb_usb_rc *rc)
1134{
1135 rc->map_name = RC_MAP_EMPTY;
1136 rc->allowed_protos = RC_TYPE_NEC;
1137 rc->query = rtl2831u_rc_query;
1138 rc->interval = 400;
1139
1140 return 0;
1141}
1142
1092static int rtl2832u_rc_query(struct dvb_usb_device *d) 1143static int rtl2832u_rc_query(struct dvb_usb_device *d)
1093{ 1144{
1094 int ret, i; 1145 int ret, i;
@@ -1146,281 +1197,95 @@ static int rtl2832u_rc_query(struct dvb_usb_device *d)
1146exit: 1197exit:
1147 return ret; 1198 return ret;
1148err: 1199err:
1149 deb_info("%s: failed=%d\n", __func__, ret); 1200 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
1150 return ret; 1201 return ret;
1151} 1202}
1152 1203
1153enum rtl28xxu_usb_table_entry { 1204static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
1154 RTL2831U_0BDA_2831, 1205 struct dvb_usb_rc *rc)
1155 RTL2831U_14AA_0160, 1206{
1156 RTL2831U_14AA_0161, 1207 rc->map_name = RC_MAP_EMPTY;
1157 RTL2832U_0CCD_00A9, 1208 rc->allowed_protos = RC_TYPE_NEC;
1158 RTL2832U_1F4D_B803, 1209 rc->query = rtl2832u_rc_query;
1159 RTL2832U_0CCD_00B3, 1210 rc->interval = 400;
1160};
1161
1162static struct usb_device_id rtl28xxu_table[] = {
1163 /* RTL2831U */
1164 [RTL2831U_0BDA_2831] = {
1165 USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U)},
1166 [RTL2831U_14AA_0160] = {
1167 USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT)},
1168 [RTL2831U_14AA_0161] = {
1169 USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2)},
1170
1171 /* RTL2832U */
1172 [RTL2832U_0CCD_00A9] = {
1173 USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1)},
1174 [RTL2832U_1F4D_B803] = {
1175 USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT)},
1176 [RTL2832U_0CCD_00B3] = {
1177 USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK)},
1178 {} /* terminating entry */
1179};
1180
1181MODULE_DEVICE_TABLE(usb, rtl28xxu_table);
1182
1183static struct dvb_usb_device_properties rtl28xxu_properties[] = {
1184 {
1185 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1186
1187 .usb_ctrl = DEVICE_SPECIFIC,
1188 .no_reconnect = 1,
1189
1190 .size_of_priv = sizeof(struct rtl28xxu_priv),
1191
1192 .num_adapters = 1,
1193 .adapter = {
1194 {
1195 .num_frontends = 1,
1196 .fe = {
1197 {
1198 .frontend_attach = rtl2831u_frontend_attach,
1199 .tuner_attach = rtl2831u_tuner_attach,
1200 .streaming_ctrl = rtl2831u_streaming_ctrl,
1201 .stream = {
1202 .type = USB_BULK,
1203 .count = 6,
1204 .endpoint = 0x81,
1205 .u = {
1206 .bulk = {
1207 .buffersize = 8*512,
1208 }
1209 }
1210 }
1211 }
1212 }
1213 }
1214 },
1215 1211
1216 .power_ctrl = rtl2831u_power_ctrl, 1212 return 0;
1213}
1217 1214
1218 .rc.core = { 1215static const struct dvb_usb_device_properties rtl2831u_props = {
1219 .protocol = RC_TYPE_NEC, 1216 .driver_name = KBUILD_MODNAME,
1220 .module_name = "rtl28xxu", 1217 .owner = THIS_MODULE,
1221 .rc_query = rtl2831u_rc_query, 1218 .adapter_nr = adapter_nr,
1222 .rc_interval = 400, 1219 .size_of_priv = sizeof(struct rtl28xxu_priv),
1223 .allowed_protos = RC_TYPE_NEC, 1220
1224 .rc_codes = RC_MAP_EMPTY, 1221 .power_ctrl = rtl2831u_power_ctrl,
1222 .i2c_algo = &rtl28xxu_i2c_algo,
1223 .frontend_attach = rtl2831u_frontend_attach,
1224 .tuner_attach = rtl2831u_tuner_attach,
1225 .init = rtl28xxu_init,
1226 .get_rc_config = rtl2831u_get_rc_config,
1227 .streaming_ctrl = rtl2831u_streaming_ctrl,
1228
1229 .num_adapters = 1,
1230 .adapter = {
1231 {
1232 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
1225 }, 1233 },
1226
1227 .i2c_algo = &rtl28xxu_i2c_algo,
1228
1229 .num_device_descs = 2,
1230 .devices = {
1231 {
1232 .name = "Realtek RTL2831U reference design",
1233 .warm_ids = {
1234 &rtl28xxu_table[RTL2831U_0BDA_2831],
1235 },
1236 },
1237 {
1238 .name = "Freecom USB2.0 DVB-T",
1239 .warm_ids = {
1240 &rtl28xxu_table[RTL2831U_14AA_0160],
1241 &rtl28xxu_table[RTL2831U_14AA_0161],
1242 },
1243 },
1244 }
1245 }, 1234 },
1246 { 1235};
1247 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1248
1249 .usb_ctrl = DEVICE_SPECIFIC,
1250 .no_reconnect = 1,
1251
1252 .size_of_priv = sizeof(struct rtl28xxu_priv),
1253
1254 .num_adapters = 1,
1255 .adapter = {
1256 {
1257 .num_frontends = 1,
1258 .fe = {
1259 {
1260 .frontend_attach = rtl2832u_frontend_attach,
1261 .tuner_attach = rtl2832u_tuner_attach,
1262 .streaming_ctrl = rtl2832u_streaming_ctrl,
1263 .stream = {
1264 .type = USB_BULK,
1265 .count = 6,
1266 .endpoint = 0x81,
1267 .u = {
1268 .bulk = {
1269 .buffersize = 8*512,
1270 }
1271 }
1272 }
1273 }
1274 }
1275 }
1276 },
1277
1278 .power_ctrl = rtl2832u_power_ctrl,
1279 1236
1280 .rc.core = { 1237static const struct dvb_usb_device_properties rtl2832u_props = {
1281 .protocol = RC_TYPE_NEC, 1238 .driver_name = KBUILD_MODNAME,
1282 .module_name = "rtl28xxu", 1239 .owner = THIS_MODULE,
1283 .rc_query = rtl2832u_rc_query, 1240 .adapter_nr = adapter_nr,
1284 .rc_interval = 400, 1241 .size_of_priv = sizeof(struct rtl28xxu_priv),
1285 .allowed_protos = RC_TYPE_NEC, 1242
1286 .rc_codes = RC_MAP_EMPTY, 1243 .power_ctrl = rtl2832u_power_ctrl,
1244 .i2c_algo = &rtl28xxu_i2c_algo,
1245 .frontend_attach = rtl2832u_frontend_attach,
1246 .tuner_attach = rtl2832u_tuner_attach,
1247 .init = rtl28xxu_init,
1248 .get_rc_config = rtl2832u_get_rc_config,
1249 .streaming_ctrl = rtl2832u_streaming_ctrl,
1250
1251 .num_adapters = 1,
1252 .adapter = {
1253 {
1254 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
1287 }, 1255 },
1288
1289 .i2c_algo = &rtl28xxu_i2c_algo,
1290
1291 .num_device_descs = 3,
1292 .devices = {
1293 {
1294 .name = "Terratec Cinergy T Stick Black",
1295 .warm_ids = {
1296 &rtl28xxu_table[RTL2832U_0CCD_00A9],
1297 },
1298 },
1299 {
1300 .name = "G-Tek Electronics Group Lifeview LV5TDLX DVB-T",
1301 .warm_ids = {
1302 &rtl28xxu_table[RTL2832U_1F4D_B803],
1303 },
1304 },
1305 {
1306 .name = "NOXON DAB/DAB+ USB dongle",
1307 .warm_ids = {
1308 &rtl28xxu_table[RTL2832U_0CCD_00B3],
1309 },
1310 },
1311 }
1312 }, 1256 },
1313
1314}; 1257};
1315 1258
1316static int rtl28xxu_probe(struct usb_interface *intf, 1259static const struct usb_device_id rtl28xxu_id_table[] = {
1317 const struct usb_device_id *id) 1260 { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U,
1318{ 1261 &rtl2831u_props, "Realtek RTL2831U reference design", NULL) },
1319 int ret, i; 1262 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT,
1320 u8 val; 1263 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
1321 int properties_count = ARRAY_SIZE(rtl28xxu_properties); 1264 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2,
1322 struct dvb_usb_device *d; 1265 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
1323 struct usb_device *udev; 1266
1324 bool found; 1267 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
1325 1268 &rtl2832u_props, "Terratec Cinergy T Stick Black", NULL) },
1326 deb_info("%s: interface=%d\n", __func__, 1269 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
1327 intf->cur_altsetting->desc.bInterfaceNumber); 1270 &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
1328 1271 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
1329 if (intf->cur_altsetting->desc.bInterfaceNumber != 0) 1272 &rtl2832u_props, "NOXON DAB/DAB+ USB dongle", NULL) },
1330 return 0; 1273 { }
1331 1274};
1332 /* Dynamic USB ID support. Replaces first device ID with current one .*/ 1275MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
1333 udev = interface_to_usbdev(intf); 1276
1334 1277static struct usb_driver rtl28xxu_usb_driver = {
1335 for (i = 0, found = false; i < ARRAY_SIZE(rtl28xxu_table) - 1; i++) { 1278 .name = KBUILD_MODNAME,
1336 if (rtl28xxu_table[i].idVendor == 1279 .id_table = rtl28xxu_id_table,
1337 le16_to_cpu(udev->descriptor.idVendor) && 1280 .probe = dvb_usbv2_probe,
1338 rtl28xxu_table[i].idProduct == 1281 .disconnect = dvb_usbv2_disconnect,
1339 le16_to_cpu(udev->descriptor.idProduct)) { 1282 .suspend = dvb_usbv2_suspend,
1340 found = true; 1283 .resume = dvb_usbv2_resume,
1341 break; 1284 .no_dynamic_id = 1,
1342 } 1285 .soft_unbind = 1,
1343 }
1344
1345 if (!found) {
1346 deb_info("%s: using dynamic ID %04x:%04x\n", __func__,
1347 le16_to_cpu(udev->descriptor.idVendor),
1348 le16_to_cpu(udev->descriptor.idProduct));
1349 rtl28xxu_properties[0].devices[0].warm_ids[0]->idVendor =
1350 le16_to_cpu(udev->descriptor.idVendor);
1351 rtl28xxu_properties[0].devices[0].warm_ids[0]->idProduct =
1352 le16_to_cpu(udev->descriptor.idProduct);
1353 }
1354
1355 for (i = 0; i < properties_count; i++) {
1356 ret = dvb_usb_device_init(intf, &rtl28xxu_properties[i],
1357 THIS_MODULE, &d, adapter_nr);
1358 if (ret == 0 || ret != -ENODEV)
1359 break;
1360 }
1361
1362 if (ret)
1363 goto err;
1364
1365
1366 /* init USB endpoints */
1367 ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val);
1368 if (ret)
1369 goto err;
1370
1371 /* enable DMA and Full Packet Mode*/
1372 val |= 0x09;
1373 ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val);
1374 if (ret)
1375 goto err;
1376
1377 /* set EPA maximum packet size to 0x0200 */
1378 ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
1379 if (ret)
1380 goto err;
1381
1382 /* change EPA FIFO length */
1383 ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
1384 if (ret)
1385 goto err;
1386
1387 return ret;
1388err:
1389 deb_info("%s: failed=%d\n", __func__, ret);
1390 return ret;
1391}
1392
1393static struct usb_driver rtl28xxu_driver = {
1394 .name = "dvb_usb_rtl28xxu",
1395 .probe = rtl28xxu_probe,
1396 .disconnect = dvb_usb_device_exit,
1397 .id_table = rtl28xxu_table,
1398}; 1286};
1399 1287
1400/* module stuff */ 1288module_usb_driver(rtl28xxu_usb_driver);
1401static int __init rtl28xxu_module_init(void)
1402{
1403 int ret;
1404
1405 deb_info("%s:\n", __func__);
1406
1407 ret = usb_register(&rtl28xxu_driver);
1408 if (ret)
1409 err("usb_register failed=%d", ret);
1410
1411 return ret;
1412}
1413
1414static void __exit rtl28xxu_module_exit(void)
1415{
1416 deb_info("%s:\n", __func__);
1417
1418 /* deregister this driver from the USB subsystem */
1419 usb_deregister(&rtl28xxu_driver);
1420}
1421
1422module_init(rtl28xxu_module_init);
1423module_exit(rtl28xxu_module_exit);
1424 1289
1425MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver"); 1290MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver");
1426MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); 1291MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
diff --git a/drivers/media/dvb/dvb-usb/rtl28xxu.h b/drivers/media/dvb/dvb-usb-v2/rtl28xxu.h
index 90f3bb4f4c0e..575edbf13a92 100644
--- a/drivers/media/dvb/dvb-usb/rtl28xxu.h
+++ b/drivers/media/dvb/dvb-usb-v2/rtl28xxu.h
@@ -22,27 +22,17 @@
22#ifndef RTL28XXU_H 22#ifndef RTL28XXU_H
23#define RTL28XXU_H 23#define RTL28XXU_H
24 24
25#define DVB_USB_LOG_PREFIX "rtl28xxu" 25#include "dvb_usb.h"
26#include "dvb-usb.h"
27 26
28#define deb_info(args...) dprintk(dvb_usb_rtl28xxu_debug, 0x01, args) 27#define deb_dump(r, t, v, i, b, l) { \
29#define deb_rc(args...) dprintk(dvb_usb_rtl28xxu_debug, 0x02, args) 28 char *direction; \
30#define deb_xfer(args...) dprintk(dvb_usb_rtl28xxu_debug, 0x04, args)
31#define deb_reg(args...) dprintk(dvb_usb_rtl28xxu_debug, 0x08, args)
32#define deb_i2c(args...) dprintk(dvb_usb_rtl28xxu_debug, 0x10, args)
33#define deb_fw(args...) dprintk(dvb_usb_rtl28xxu_debug, 0x20, args)
34
35#define deb_dump(r, t, v, i, b, l, func) { \
36 int loop_; \
37 func("%02x %02x %02x %02x %02x %02x %02x %02x", \
38 t, r, v & 0xff, v >> 8, i & 0xff, i >> 8, l & 0xff, l >> 8); \
39 if (t == (USB_TYPE_VENDOR | USB_DIR_OUT)) \ 29 if (t == (USB_TYPE_VENDOR | USB_DIR_OUT)) \
40 func(" >>> "); \ 30 direction = ">>>"; \
41 else \ 31 else \
42 func(" <<< "); \ 32 direction = "<<<"; \
43 for (loop_ = 0; loop_ < l; loop_++) \ 33 dev_dbg(&d->udev->dev, "%s: %02x %02x %02x %02x %02x %02x %02x %02x " \
44 func("%02x ", b[loop_]); \ 34 "%s [%d bytes]\n", __func__, t, r, v & 0xff, v >> 8, \
45 func("\n");\ 35 i & 0xff, i >> 8, l & 0xff, l >> 8, direction, l); \
46} 36}
47 37
48/* 38/*
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index 8e13877a5c2c..ec10c0f2f554 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -319,16 +319,3 @@ config DVB_USB_IT913X
319 help 319 help
320 Say Y here to support the it913x device 320 Say Y here to support the it913x device
321 321
322config DVB_USB_RTL28XXU
323 tristate "Realtek RTL28xxU DVB USB support"
324 depends on DVB_USB && EXPERIMENTAL
325 select DVB_RTL2830
326 select DVB_RTL2832
327 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE
328 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE
329 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE
330 select MEDIA_TUNER_FC0012 if !MEDIA_TUNER_CUSTOMISE
331 select MEDIA_TUNER_FC0013 if !MEDIA_TUNER_CUSTOMISE
332 help
333 Say Y here to support the Realtek RTL28xxU DVB USB receiver.
334
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
index 859baf9c8e0c..d1912e0e1681 100644
--- a/drivers/media/dvb/dvb-usb/Makefile
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -78,9 +78,6 @@ obj-$(CONFIG_DVB_USB_TECHNISAT_USB2) += dvb-usb-technisat-usb2.o
78dvb-usb-it913x-objs := it913x.o 78dvb-usb-it913x-objs := it913x.o
79obj-$(CONFIG_DVB_USB_IT913X) += dvb-usb-it913x.o 79obj-$(CONFIG_DVB_USB_IT913X) += dvb-usb-it913x.o
80 80
81dvb-usb-rtl28xxu-objs = rtl28xxu.o
82obj-$(CONFIG_DVB_USB_RTL28XXU) += dvb-usb-rtl28xxu.o
83
84ccflags-y += -I$(srctree)/drivers/media/dvb/dvb-core 81ccflags-y += -I$(srctree)/drivers/media/dvb/dvb-core
85ccflags-y += -I$(srctree)/drivers/media/dvb/frontends/ 82ccflags-y += -I$(srctree)/drivers/media/dvb/frontends/
86# due to tuner-xc3028 83# due to tuner-xc3028