aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/dvb-usb/anysee.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/dvb/dvb-usb/anysee.c')
-rw-r--r--drivers/media/dvb/dvb-usb/anysee.c411
1 files changed, 346 insertions, 65 deletions
diff --git a/drivers/media/dvb/dvb-usb/anysee.c b/drivers/media/dvb/dvb-usb/anysee.c
index b39f14f85e71..d66192974d68 100644
--- a/drivers/media/dvb/dvb-usb/anysee.c
+++ b/drivers/media/dvb/dvb-usb/anysee.c
@@ -41,6 +41,7 @@
41#include "stv0900.h" 41#include "stv0900.h"
42#include "stv6110.h" 42#include "stv6110.h"
43#include "isl6423.h" 43#include "isl6423.h"
44#include "cxd2820r.h"
44 45
45/* debug */ 46/* debug */
46static int dvb_usb_anysee_debug; 47static int dvb_usb_anysee_debug;
@@ -66,10 +67,12 @@ static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
66 if (mutex_lock_interruptible(&anysee_usb_mutex) < 0) 67 if (mutex_lock_interruptible(&anysee_usb_mutex) < 0)
67 return -EAGAIN; 68 return -EAGAIN;
68 69
70 deb_xfer(">>> ");
71 debug_dump(buf, slen, deb_xfer);
72
69 /* We need receive one message more after dvb_usb_generic_rw due 73 /* We need receive one message more after dvb_usb_generic_rw due
70 to weird transaction flow, which is 1 x send + 2 x receive. */ 74 to weird transaction flow, which is 1 x send + 2 x receive. */
71 ret = dvb_usb_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf), 0); 75 ret = dvb_usb_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf), 0);
72
73 if (!ret) { 76 if (!ret) {
74 /* receive 2nd answer */ 77 /* receive 2nd answer */
75 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev, 78 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
@@ -79,7 +82,10 @@ static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
79 err("%s: recv bulk message failed: %d", __func__, ret); 82 err("%s: recv bulk message failed: %d", __func__, ret);
80 else { 83 else {
81 deb_xfer("<<< "); 84 deb_xfer("<<< ");
82 debug_dump(buf, act_len, deb_xfer); 85 debug_dump(buf, rlen, deb_xfer);
86
87 if (buf[63] != 0x4f)
88 deb_info("%s: cmd failed\n", __func__);
83 } 89 }
84 } 90 }
85 91
@@ -129,6 +135,29 @@ static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
129 return anysee_write_reg(d, reg, val); 135 return anysee_write_reg(d, reg, val);
130} 136}
131 137
138/* read single register with mask */
139static int anysee_rd_reg_mask(struct dvb_usb_device *d, u16 reg, u8 *val,
140 u8 mask)
141{
142 int ret, i;
143 u8 tmp;
144
145 ret = anysee_read_reg(d, reg, &tmp);
146 if (ret)
147 return ret;
148
149 tmp &= mask;
150
151 /* find position of the first bit */
152 for (i = 0; i < 8; i++) {
153 if ((mask >> i) & 0x01)
154 break;
155 }
156 *val = tmp >> i;
157
158 return 0;
159}
160
132static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id) 161static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
133{ 162{
134 u8 buf[] = {CMD_GET_HW_INFO}; 163 u8 buf[] = {CMD_GET_HW_INFO};
@@ -156,22 +185,6 @@ static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)
156 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); 185 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
157} 186}
158 187
159static int anysee_init(struct dvb_usb_device *d)
160{
161 int ret;
162 /* LED light */
163 ret = anysee_led_ctrl(d, 0x01, 0x03);
164 if (ret)
165 return ret;
166
167 /* enable IR */
168 ret = anysee_ir_ctrl(d, 1);
169 if (ret)
170 return ret;
171
172 return 0;
173}
174
175/* I2C */ 188/* I2C */
176static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, 189static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
177 int num) 190 int num)
@@ -297,7 +310,7 @@ static struct tda10023_config anysee_tda10023_tda18212_config = {
297 .pll_m = 12, 310 .pll_m = 12,
298 .pll_p = 3, 311 .pll_p = 3,
299 .pll_n = 1, 312 .pll_n = 1,
300 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C, 313 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_B,
301 .deltaf = 0xba02, 314 .deltaf = 0xba02,
302}; 315};
303 316
@@ -309,6 +322,17 @@ static struct tda18212_config anysee_tda18212_config = {
309 .if_dvbc = 5000, 322 .if_dvbc = 5000,
310}; 323};
311 324
325static struct tda18212_config anysee_tda18212_config2 = {
326 .i2c_address = 0x60 /* (0xc0 >> 1) */,
327 .if_dvbt_6 = 3550,
328 .if_dvbt_7 = 3700,
329 .if_dvbt_8 = 4150,
330 .if_dvbt2_6 = 3250,
331 .if_dvbt2_7 = 4000,
332 .if_dvbt2_8 = 4000,
333 .if_dvbc = 5000,
334};
335
312static struct cx24116_config anysee_cx24116_config = { 336static struct cx24116_config anysee_cx24116_config = {
313 .demod_address = (0xaa >> 1), 337 .demod_address = (0xaa >> 1),
314 .mpg_clk_pos_pol = 0x00, 338 .mpg_clk_pos_pol = 0x00,
@@ -339,6 +363,11 @@ static struct isl6423_config anysee_isl6423_config = {
339 .addr = (0x10 >> 1), 363 .addr = (0x10 >> 1),
340}; 364};
341 365
366static struct cxd2820r_config anysee_cxd2820r_config = {
367 .i2c_address = 0x6d, /* (0xda >> 1) */
368 .ts_mode = 0x38,
369};
370
342/* 371/*
343 * New USB device strings: Mfr=1, Product=2, SerialNumber=0 372 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
344 * Manufacturer: AMT.CO.KR 373 * Manufacturer: AMT.CO.KR
@@ -421,6 +450,14 @@ static struct isl6423_config anysee_isl6423_config = {
421 * IOA[7] TS 1=enabled 450 * IOA[7] TS 1=enabled
422 * IOE[5] STV0903 1=enabled 451 * IOE[5] STV0903 1=enabled
423 * 452 *
453 * E7 T2C VID=1c73 PID=861f HW=20 FW=0.1 AMTCI=0.5 "anysee-E7T2C(LP)"
454 * PCB: 508T2C (rev0.3)
455 * parts: DNOQ44QCH106A(CXD2820R, TDA18212), TDA8024
456 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
457 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
458 * IOA[7] TS 1=enabled
459 * IOE[5] CXD2820R 1=enabled
460 *
424 * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)" 461 * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)"
425 * PCB: 508PTC (rev0.5) 462 * PCB: 508PTC (rev0.5)
426 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212) 463 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
@@ -437,7 +474,7 @@ static struct isl6423_config anysee_isl6423_config = {
437 * IOD[6] ZL10353 1=enabled 474 * IOD[6] ZL10353 1=enabled
438 * IOE[0] IF 0=enabled 475 * IOE[0] IF 0=enabled
439 * 476 *
440 * E7 S2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)" 477 * E7 PS2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)"
441 * PCB: 508PS2 (rev0.4) 478 * PCB: 508PS2 (rev0.4)
442 * parts: DNBU10512IST(STV0903, STV6110), ISL6423 479 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
443 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff 480 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
@@ -446,6 +483,16 @@ static struct isl6423_config anysee_isl6423_config = {
446 * IOE[5] STV0903 1=enabled 483 * IOE[5] STV0903 1=enabled
447 */ 484 */
448 485
486
487/* external I2C gate used for DNOD44CDH086A(TDA18212) tuner module */
488static int anysee_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
489{
490 struct dvb_usb_adapter *adap = fe->dvb->priv;
491
492 /* enable / disable tuner access on IOE[4] */
493 return anysee_wr_reg_mask(adap->dev, REG_IOE, (enable << 4), 0x10);
494}
495
449static int anysee_frontend_ctrl(struct dvb_frontend *fe, int onoff) 496static int anysee_frontend_ctrl(struct dvb_frontend *fe, int onoff)
450{ 497{
451 struct dvb_usb_adapter *adap = fe->dvb->priv; 498 struct dvb_usb_adapter *adap = fe->dvb->priv;
@@ -577,7 +624,8 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
577 /* detect hardware only once */ 624 /* detect hardware only once */
578 if (adap->fe_adap[0].fe == NULL) { 625 if (adap->fe_adap[0].fe == NULL) {
579 /* Check which hardware we have. 626 /* Check which hardware we have.
580 * We must do this call two times to get reliable values (hw bug). 627 * We must do this call two times to get reliable values
628 * (hw/fw bug).
581 */ 629 */
582 ret = anysee_get_hw_info(adap->dev, hw_info); 630 ret = anysee_get_hw_info(adap->dev, hw_info);
583 if (ret) 631 if (ret)
@@ -606,14 +654,14 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
606 break; 654 break;
607 655
608 /* attach demod */ 656 /* attach demod */
609 adap->fe_adap[0].fe = dvb_attach(mt352_attach, &anysee_mt352_config, 657 adap->fe_adap[0].fe = dvb_attach(mt352_attach,
610 &adap->dev->i2c_adap); 658 &anysee_mt352_config, &adap->dev->i2c_adap);
611 if (adap->fe_adap[0].fe) 659 if (adap->fe_adap[0].fe)
612 break; 660 break;
613 661
614 /* attach demod */ 662 /* attach demod */
615 adap->fe_adap[0].fe = dvb_attach(zl10353_attach, &anysee_zl10353_config, 663 adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
616 &adap->dev->i2c_adap); 664 &anysee_zl10353_config, &adap->dev->i2c_adap);
617 665
618 break; 666 break;
619 case ANYSEE_HW_507CD: /* 6 */ 667 case ANYSEE_HW_507CD: /* 6 */
@@ -665,8 +713,8 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
665 goto error; 713 goto error;
666 714
667 /* attach demod */ 715 /* attach demod */
668 adap->fe_adap[0].fe = dvb_attach(cx24116_attach, &anysee_cx24116_config, 716 adap->fe_adap[0].fe = dvb_attach(cx24116_attach,
669 &adap->dev->i2c_adap); 717 &anysee_cx24116_config, &adap->dev->i2c_adap);
670 718
671 break; 719 break;
672 case ANYSEE_HW_507FA: /* 15 */ 720 case ANYSEE_HW_507FA: /* 15 */
@@ -747,17 +795,19 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
747 } 795 }
748 } 796 }
749 797
798 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
799 if (tmp == 0xc7) {
800 if (adap->fe_adap[state->fe_id].fe)
801 adap->fe_adap[state->fe_id].fe->ops.i2c_gate_ctrl =
802 anysee_i2c_gate_ctrl;
803 }
804
750 break; 805 break;
751 case ANYSEE_HW_508TC: /* 18 */ 806 case ANYSEE_HW_508TC: /* 18 */
752 case ANYSEE_HW_508PTC: /* 21 */ 807 case ANYSEE_HW_508PTC: /* 21 */
753 /* E7 TC */ 808 /* E7 TC */
754 /* E7 PTC */ 809 /* E7 PTC */
755 810
756 /* enable transport stream on IOA[7] */
757 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);
758 if (ret)
759 goto error;
760
761 if ((state->fe_id ^ dvb_usb_anysee_delsys) == 0) { 811 if ((state->fe_id ^ dvb_usb_anysee_delsys) == 0) {
762 /* disable DVB-T demod on IOD[6] */ 812 /* disable DVB-T demod on IOD[6] */
763 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6), 813 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),
@@ -772,7 +822,8 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
772 goto error; 822 goto error;
773 823
774 /* attach demod */ 824 /* attach demod */
775 adap->fe_adap[state->fe_id].fe = dvb_attach(tda10023_attach, 825 adap->fe_adap[state->fe_id].fe =
826 dvb_attach(tda10023_attach,
776 &anysee_tda10023_tda18212_config, 827 &anysee_tda10023_tda18212_config,
777 &adap->dev->i2c_adap, 0x48); 828 &adap->dev->i2c_adap, 0x48);
778 } else { 829 } else {
@@ -789,11 +840,19 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
789 goto error; 840 goto error;
790 841
791 /* attach demod */ 842 /* attach demod */
792 adap->fe_adap[state->fe_id].fe = dvb_attach(zl10353_attach, 843 adap->fe_adap[state->fe_id].fe =
844 dvb_attach(zl10353_attach,
793 &anysee_zl10353_tda18212_config, 845 &anysee_zl10353_tda18212_config,
794 &adap->dev->i2c_adap); 846 &adap->dev->i2c_adap);
795 } 847 }
796 848
849 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
850 if (adap->fe_adap[state->fe_id].fe)
851 adap->fe_adap[state->fe_id].fe->ops.i2c_gate_ctrl =
852 anysee_i2c_gate_ctrl;
853
854 state->has_ci = true;
855
797 break; 856 break;
798 case ANYSEE_HW_508S2: /* 19 */ 857 case ANYSEE_HW_508S2: /* 19 */
799 case ANYSEE_HW_508PS2: /* 22 */ 858 case ANYSEE_HW_508PS2: /* 22 */
@@ -803,19 +862,41 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
803 if (state->fe_id) 862 if (state->fe_id)
804 break; 863 break;
805 864
806 /* enable transport stream on IOA[7] */ 865 /* enable DVB-S/S2 demod on IOE[5] */
807 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80); 866 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 5), 0x20);
808 if (ret) 867 if (ret)
809 goto error; 868 goto error;
810 869
811 /* enable DVB-S/S2 demod on IOE[5] */ 870 /* attach demod */
871 adap->fe_adap[0].fe = dvb_attach(stv0900_attach,
872 &anysee_stv0900_config, &adap->dev->i2c_adap, 0);
873
874 state->has_ci = true;
875
876 break;
877 case ANYSEE_HW_508T2C: /* 20 */
878 /* E7 T2C */
879
880 /* enable DVB-T/T2/C demod on IOE[5] */
812 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 5), 0x20); 881 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 5), 0x20);
813 if (ret) 882 if (ret)
814 goto error; 883 goto error;
815 884
816 /* attach demod */ 885 if (state->fe_id == 0) {
817 adap->fe_adap[0].fe = dvb_attach(stv0900_attach, &anysee_stv0900_config, 886 /* DVB-T/T2 */
818 &adap->dev->i2c_adap, 0); 887 adap->fe_adap[state->fe_id].fe =
888 dvb_attach(cxd2820r_attach,
889 &anysee_cxd2820r_config,
890 &adap->dev->i2c_adap, NULL);
891 } else {
892 /* DVB-C */
893 adap->fe_adap[state->fe_id].fe =
894 dvb_attach(cxd2820r_attach,
895 &anysee_cxd2820r_config,
896 &adap->dev->i2c_adap, adap->fe_adap[0].fe);
897 }
898
899 state->has_ci = true;
819 900
820 break; 901 break;
821 } 902 }
@@ -842,24 +923,26 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
842 /* E30 */ 923 /* E30 */
843 924
844 /* attach tuner */ 925 /* attach tuner */
845 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, (0xc2 >> 1), 926 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe,
846 NULL, DVB_PLL_THOMSON_DTT7579); 927 (0xc2 >> 1), NULL, DVB_PLL_THOMSON_DTT7579);
847 928
848 break; 929 break;
849 case ANYSEE_HW_507CD: /* 6 */ 930 case ANYSEE_HW_507CD: /* 6 */
850 /* E30 Plus */ 931 /* E30 Plus */
851 932
852 /* attach tuner */ 933 /* attach tuner */
853 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, (0xc2 >> 1), 934 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe,
854 &adap->dev->i2c_adap, DVB_PLL_THOMSON_DTT7579); 935 (0xc2 >> 1), &adap->dev->i2c_adap,
936 DVB_PLL_THOMSON_DTT7579);
855 937
856 break; 938 break;
857 case ANYSEE_HW_507DC: /* 10 */ 939 case ANYSEE_HW_507DC: /* 10 */
858 /* E30 C Plus */ 940 /* E30 C Plus */
859 941
860 /* attach tuner */ 942 /* attach tuner */
861 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, (0xc0 >> 1), 943 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe,
862 &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A); 944 (0xc0 >> 1), &adap->dev->i2c_adap,
945 DVB_PLL_SAMSUNG_DTOS403IH102A);
863 946
864 break; 947 break;
865 case ANYSEE_HW_507SI: /* 11 */ 948 case ANYSEE_HW_507SI: /* 11 */
@@ -877,22 +960,12 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
877 /* Try first attach TDA18212 silicon tuner on IOE[4], if that 960 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
878 * fails attach old simple PLL. */ 961 * fails attach old simple PLL. */
879 962
880 /* enable tuner on IOE[4] */
881 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
882 if (ret)
883 goto error;
884
885 /* attach tuner */ 963 /* attach tuner */
886 fe = dvb_attach(tda18212_attach, adap->fe_adap[state->fe_id].fe, 964 fe = dvb_attach(tda18212_attach, adap->fe_adap[state->fe_id].fe,
887 &adap->dev->i2c_adap, &anysee_tda18212_config); 965 &adap->dev->i2c_adap, &anysee_tda18212_config);
888 if (fe) 966 if (fe)
889 break; 967 break;
890 968
891 /* disable tuner on IOE[4] */
892 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);
893 if (ret)
894 goto error;
895
896 /* attach tuner */ 969 /* attach tuner */
897 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[state->fe_id].fe, 970 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[state->fe_id].fe,
898 (0xc0 >> 1), &adap->dev->i2c_adap, 971 (0xc0 >> 1), &adap->dev->i2c_adap,
@@ -904,11 +977,6 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
904 /* E7 TC */ 977 /* E7 TC */
905 /* E7 PTC */ 978 /* E7 PTC */
906 979
907 /* enable tuner on IOE[4] */
908 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
909 if (ret)
910 goto error;
911
912 /* attach tuner */ 980 /* attach tuner */
913 fe = dvb_attach(tda18212_attach, adap->fe_adap[state->fe_id].fe, 981 fe = dvb_attach(tda18212_attach, adap->fe_adap[state->fe_id].fe,
914 &adap->dev->i2c_adap, &anysee_tda18212_config); 982 &adap->dev->i2c_adap, &anysee_tda18212_config);
@@ -930,6 +998,15 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
930 } 998 }
931 999
932 break; 1000 break;
1001
1002 case ANYSEE_HW_508T2C: /* 20 */
1003 /* E7 T2C */
1004
1005 /* attach tuner */
1006 fe = dvb_attach(tda18212_attach, adap->fe_adap[state->fe_id].fe,
1007 &adap->dev->i2c_adap, &anysee_tda18212_config2);
1008
1009 break;
933 default: 1010 default:
934 fe = NULL; 1011 fe = NULL;
935 } 1012 }
@@ -939,7 +1016,6 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
939 else 1016 else
940 ret = -ENODEV; 1017 ret = -ENODEV;
941 1018
942error:
943 return ret; 1019 return ret;
944} 1020}
945 1021
@@ -969,6 +1045,201 @@ static int anysee_rc_query(struct dvb_usb_device *d)
969 return 0; 1045 return 0;
970} 1046}
971 1047
1048static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
1049 int addr)
1050{
1051 struct dvb_usb_device *d = ci->data;
1052 int ret;
1053 u8 buf[] = {CMD_CI, 0x02, 0x40 | addr >> 8, addr & 0xff, 0x00, 1};
1054 u8 val;
1055
1056 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
1057 if (ret)
1058 return ret;
1059
1060 return val;
1061}
1062
1063static int anysee_ci_write_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
1064 int addr, u8 val)
1065{
1066 struct dvb_usb_device *d = ci->data;
1067 int ret;
1068 u8 buf[] = {CMD_CI, 0x03, 0x40 | addr >> 8, addr & 0xff, 0x00, 1, val};
1069
1070 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
1071 if (ret)
1072 return ret;
1073
1074 return 0;
1075}
1076
1077static int anysee_ci_read_cam_control(struct dvb_ca_en50221 *ci, int slot,
1078 u8 addr)
1079{
1080 struct dvb_usb_device *d = ci->data;
1081 int ret;
1082 u8 buf[] = {CMD_CI, 0x04, 0x40, addr, 0x00, 1};
1083 u8 val;
1084
1085 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
1086 if (ret)
1087 return ret;
1088
1089 return val;
1090}
1091
1092static int anysee_ci_write_cam_control(struct dvb_ca_en50221 *ci, int slot,
1093 u8 addr, u8 val)
1094{
1095 struct dvb_usb_device *d = ci->data;
1096 int ret;
1097 u8 buf[] = {CMD_CI, 0x05, 0x40, addr, 0x00, 1, val};
1098
1099 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
1100 if (ret)
1101 return ret;
1102
1103 return 0;
1104}
1105
1106static int anysee_ci_slot_reset(struct dvb_ca_en50221 *ci, int slot)
1107{
1108 struct dvb_usb_device *d = ci->data;
1109 int ret;
1110 struct anysee_state *state = d->priv;
1111
1112 state->ci_cam_ready = jiffies + msecs_to_jiffies(1000);
1113
1114 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
1115 if (ret)
1116 return ret;
1117
1118 msleep(300);
1119
1120 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1121 if (ret)
1122 return ret;
1123
1124 return 0;
1125}
1126
1127static int anysee_ci_slot_shutdown(struct dvb_ca_en50221 *ci, int slot)
1128{
1129 struct dvb_usb_device *d = ci->data;
1130 int ret;
1131
1132 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
1133 if (ret)
1134 return ret;
1135
1136 msleep(30);
1137
1138 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1139 if (ret)
1140 return ret;
1141
1142 return 0;
1143}
1144
1145static int anysee_ci_slot_ts_enable(struct dvb_ca_en50221 *ci, int slot)
1146{
1147 struct dvb_usb_device *d = ci->data;
1148 int ret;
1149
1150 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 1), 0x02);
1151 if (ret)
1152 return ret;
1153
1154 return 0;
1155}
1156
1157static int anysee_ci_poll_slot_status(struct dvb_ca_en50221 *ci, int slot,
1158 int open)
1159{
1160 struct dvb_usb_device *d = ci->data;
1161 struct anysee_state *state = d->priv;
1162 int ret;
1163 u8 tmp;
1164
1165 ret = anysee_rd_reg_mask(d, REG_IOC, &tmp, 0x40);
1166 if (ret)
1167 return ret;
1168
1169 if (tmp == 0) {
1170 ret = DVB_CA_EN50221_POLL_CAM_PRESENT;
1171 if (time_after(jiffies, state->ci_cam_ready))
1172 ret |= DVB_CA_EN50221_POLL_CAM_READY;
1173 }
1174
1175 return ret;
1176}
1177
1178static int anysee_ci_init(struct dvb_usb_device *d)
1179{
1180 struct anysee_state *state = d->priv;
1181 int ret;
1182
1183 state->ci.owner = THIS_MODULE;
1184 state->ci.read_attribute_mem = anysee_ci_read_attribute_mem;
1185 state->ci.write_attribute_mem = anysee_ci_write_attribute_mem;
1186 state->ci.read_cam_control = anysee_ci_read_cam_control;
1187 state->ci.write_cam_control = anysee_ci_write_cam_control;
1188 state->ci.slot_reset = anysee_ci_slot_reset;
1189 state->ci.slot_shutdown = anysee_ci_slot_shutdown;
1190 state->ci.slot_ts_enable = anysee_ci_slot_ts_enable;
1191 state->ci.poll_slot_status = anysee_ci_poll_slot_status;
1192 state->ci.data = d;
1193
1194 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1195 if (ret)
1196 return ret;
1197
1198 ret = dvb_ca_en50221_init(&d->adapter[0].dvb_adap, &state->ci, 0, 1);
1199 if (ret)
1200 return ret;
1201
1202 return 0;
1203}
1204
1205static void anysee_ci_release(struct dvb_usb_device *d)
1206{
1207 struct anysee_state *state = d->priv;
1208
1209 /* detach CI */
1210 if (state->has_ci)
1211 dvb_ca_en50221_release(&state->ci);
1212
1213 return;
1214}
1215
1216static int anysee_init(struct dvb_usb_device *d)
1217{
1218 struct anysee_state *state = d->priv;
1219 int ret;
1220
1221 /* LED light */
1222 ret = anysee_led_ctrl(d, 0x01, 0x03);
1223 if (ret)
1224 return ret;
1225
1226 /* enable IR */
1227 ret = anysee_ir_ctrl(d, 1);
1228 if (ret)
1229 return ret;
1230
1231 /* attach CI */
1232 if (state->has_ci) {
1233 ret = anysee_ci_init(d);
1234 if (ret) {
1235 state->has_ci = false;
1236 return ret;
1237 }
1238 }
1239
1240 return 0;
1241}
1242
972/* DVB USB Driver stuff */ 1243/* DVB USB Driver stuff */
973static struct dvb_usb_device_properties anysee_properties; 1244static struct dvb_usb_device_properties anysee_properties;
974 1245
@@ -1010,6 +1281,16 @@ static int anysee_probe(struct usb_interface *intf,
1010 return anysee_init(d); 1281 return anysee_init(d);
1011} 1282}
1012 1283
1284static void anysee_disconnect(struct usb_interface *intf)
1285{
1286 struct dvb_usb_device *d = usb_get_intfdata(intf);
1287
1288 anysee_ci_release(d);
1289 dvb_usb_device_exit(intf);
1290
1291 return;
1292}
1293
1013static struct usb_device_id anysee_table[] = { 1294static struct usb_device_id anysee_table[] = {
1014 { USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE) }, 1295 { USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE) },
1015 { USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE) }, 1296 { USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE) },
@@ -1029,7 +1310,7 @@ static struct dvb_usb_device_properties anysee_properties = {
1029 { 1310 {
1030 .num_frontends = 2, 1311 .num_frontends = 2,
1031 .frontend_ctrl = anysee_frontend_ctrl, 1312 .frontend_ctrl = anysee_frontend_ctrl,
1032 .fe = {{ 1313 .fe = { {
1033 .streaming_ctrl = anysee_streaming_ctrl, 1314 .streaming_ctrl = anysee_streaming_ctrl,
1034 .frontend_attach = anysee_frontend_attach, 1315 .frontend_attach = anysee_frontend_attach,
1035 .tuner_attach = anysee_tuner_attach, 1316 .tuner_attach = anysee_tuner_attach,
@@ -1057,7 +1338,7 @@ static struct dvb_usb_device_properties anysee_properties = {
1057 } 1338 }
1058 } 1339 }
1059 }, 1340 },
1060 }}, 1341 } },
1061 } 1342 }
1062 }, 1343 },
1063 1344
@@ -1087,7 +1368,7 @@ static struct dvb_usb_device_properties anysee_properties = {
1087static struct usb_driver anysee_driver = { 1368static struct usb_driver anysee_driver = {
1088 .name = "dvb_usb_anysee", 1369 .name = "dvb_usb_anysee",
1089 .probe = anysee_probe, 1370 .probe = anysee_probe,
1090 .disconnect = dvb_usb_device_exit, 1371 .disconnect = anysee_disconnect,
1091 .id_table = anysee_table, 1372 .id_table = anysee_table,
1092}; 1373};
1093 1374