aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/frontends/tda18271-fe.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/dvb/frontends/tda18271-fe.c')
-rw-r--r--drivers/media/dvb/frontends/tda18271-fe.c418
1 files changed, 173 insertions, 245 deletions
diff --git a/drivers/media/dvb/frontends/tda18271-fe.c b/drivers/media/dvb/frontends/tda18271-fe.c
index dfe72aaec380..b262100ae897 100644
--- a/drivers/media/dvb/frontends/tda18271-fe.c
+++ b/drivers/media/dvb/frontends/tda18271-fe.c
@@ -31,30 +31,23 @@ static int tda18271_cal_on_startup;
31module_param_named(cal, tda18271_cal_on_startup, int, 0644); 31module_param_named(cal, tda18271_cal_on_startup, int, 0644);
32MODULE_PARM_DESC(cal, "perform RF tracking filter calibration on startup"); 32MODULE_PARM_DESC(cal, "perform RF tracking filter calibration on startup");
33 33
34static LIST_HEAD(tda18271_list);
35static DEFINE_MUTEX(tda18271_list_mutex); 34static DEFINE_MUTEX(tda18271_list_mutex);
35static LIST_HEAD(hybrid_tuner_instance_list);
36 36
37/*---------------------------------------------------------------------*/ 37/*---------------------------------------------------------------------*/
38 38
39static int tda18271_ir_cal_init(struct dvb_frontend *fe) 39static inline int charge_pump_source(struct dvb_frontend *fe, int force)
40{ 40{
41 struct tda18271_priv *priv = fe->tuner_priv; 41 struct tda18271_priv *priv = fe->tuner_priv;
42 unsigned char *regs = priv->tda18271_regs; 42 return tda18271_charge_pump_source(fe,
43 43 (priv->role == TDA18271_SLAVE) ?
44 tda18271_read_regs(fe); 44 TDA18271_CAL_PLL :
45 45 TDA18271_MAIN_PLL, force);
46 /* test IR_CAL_OK to see if we need init */
47 if ((regs[R_EP1] & 0x08) == 0)
48 tda18271_init_regs(fe);
49
50 return 0;
51} 46}
52 47
53/* ------------------------------------------------------------------ */
54
55static int tda18271_channel_configuration(struct dvb_frontend *fe, 48static int tda18271_channel_configuration(struct dvb_frontend *fe,
56 u32 ifc, u32 freq, u32 bw, u8 std, 49 struct tda18271_std_map_item *map,
57 int radio) 50 u32 freq, u32 bw)
58{ 51{
59 struct tda18271_priv *priv = fe->tuner_priv; 52 struct tda18271_priv *priv = fe->tuner_priv;
60 unsigned char *regs = priv->tda18271_regs; 53 unsigned char *regs = priv->tda18271_regs;
@@ -64,38 +57,34 @@ static int tda18271_channel_configuration(struct dvb_frontend *fe,
64 57
65 /* set standard */ 58 /* set standard */
66 regs[R_EP3] &= ~0x1f; /* clear std bits */ 59 regs[R_EP3] &= ~0x1f; /* clear std bits */
67 regs[R_EP3] |= std; 60 regs[R_EP3] |= (map->agc_mode << 3) | map->std;
61
62 /* set rfagc to high speed mode */
63 regs[R_EP3] &= ~0x04;
68 64
69 /* set cal mode to normal */ 65 /* set cal mode to normal */
70 regs[R_EP4] &= ~0x03; 66 regs[R_EP4] &= ~0x03;
71 67
72 /* update IF output level & IF notch frequency */ 68 /* update IF output level & IF notch frequency */
73 regs[R_EP4] &= ~0x1c; /* clear if level bits */ 69 regs[R_EP4] &= ~0x1c; /* clear if level bits */
70 regs[R_EP4] |= (map->if_lvl << 2);
74 71
75 switch (priv->mode) { 72 switch (priv->mode) {
76 case TDA18271_ANALOG: 73 case TDA18271_ANALOG:
77 regs[R_MPD] &= ~0x80; /* IF notch = 0 */ 74 regs[R_MPD] &= ~0x80; /* IF notch = 0 */
78 break; 75 break;
79 case TDA18271_DIGITAL: 76 case TDA18271_DIGITAL:
80 regs[R_EP4] |= 0x04; /* IF level = 1 */
81 regs[R_MPD] |= 0x80; /* IF notch = 1 */ 77 regs[R_MPD] |= 0x80; /* IF notch = 1 */
82 break; 78 break;
83 } 79 }
84 80
85 if (radio) 81 /* update FM_RFn */
86 regs[R_EP4] |= 0x80; 82 regs[R_EP4] &= ~0x80;
87 else 83 regs[R_EP4] |= map->fm_rfn << 7;
88 regs[R_EP4] &= ~0x80;
89 84
90 /* update RF_TOP / IF_TOP */ 85 /* update rf top / if top */
91 switch (priv->mode) { 86 regs[R_EB22] = 0x00;
92 case TDA18271_ANALOG: 87 regs[R_EB22] |= map->rfagc_top;
93 regs[R_EB22] = 0x2c;
94 break;
95 case TDA18271_DIGITAL:
96 regs[R_EB22] = 0x37;
97 break;
98 }
99 tda18271_write_regs(fe, R_EB22, 1); 88 tda18271_write_regs(fe, R_EB22, 1);
100 89
101 /* --------------------------------------------------------------- */ 90 /* --------------------------------------------------------------- */
@@ -117,8 +106,14 @@ static int tda18271_channel_configuration(struct dvb_frontend *fe,
117 106
118 /* dual tuner and agc1 extra configuration */ 107 /* dual tuner and agc1 extra configuration */
119 108
120 /* main vco when Master, cal vco when slave */ 109 switch (priv->role) {
121 regs[R_EB1] |= 0x04; /* FIXME: assumes master */ 110 case TDA18271_MASTER:
111 regs[R_EB1] |= 0x04; /* main vco */
112 break;
113 case TDA18271_SLAVE:
114 regs[R_EB1] &= ~0x04; /* cal vco */
115 break;
116 }
122 117
123 /* agc1 always active */ 118 /* agc1 always active */
124 regs[R_EB1] &= ~0x02; 119 regs[R_EB1] &= ~0x02;
@@ -130,25 +125,40 @@ static int tda18271_channel_configuration(struct dvb_frontend *fe,
130 125
131 /* --------------------------------------------------------------- */ 126 /* --------------------------------------------------------------- */
132 127
133 N = freq + ifc; 128 N = map->if_freq * 1000 + freq;
134 129
135 /* FIXME: assumes master */ 130 switch (priv->role) {
136 tda18271_calc_main_pll(fe, N); 131 case TDA18271_MASTER:
137 tda18271_write_regs(fe, R_MPD, 4); 132 tda18271_calc_main_pll(fe, N);
133 tda18271_write_regs(fe, R_MPD, 4);
134 break;
135 case TDA18271_SLAVE:
136 tda18271_calc_cal_pll(fe, N);
137 tda18271_write_regs(fe, R_CPD, 4);
138
139 regs[R_MPD] = regs[R_CPD] & 0x7f;
140 tda18271_write_regs(fe, R_MPD, 1);
141 break;
142 }
138 143
139 tda18271_write_regs(fe, R_TM, 7); 144 tda18271_write_regs(fe, R_TM, 7);
140 145
141 /* main pll charge pump source */ 146 /* force charge pump source */
142 regs[R_EB4] |= 0x20; 147 charge_pump_source(fe, 1);
143 tda18271_write_regs(fe, R_EB4, 1);
144 148
145 msleep(1); 149 msleep(1);
146 150
147 /* normal operation for the main pll */ 151 /* return pll to normal operation */
148 regs[R_EB4] &= ~0x20; 152 charge_pump_source(fe, 0);
149 tda18271_write_regs(fe, R_EB4, 1);
150 153
151 msleep(5); 154 msleep(20);
155
156 /* set rfagc to normal speed mode */
157 if (map->fm_rfn)
158 regs[R_EP3] &= ~0x04;
159 else
160 regs[R_EP3] |= 0x04;
161 tda18271_write_regs(fe, R_EP3, 1);
152 162
153 return 0; 163 return 0;
154} 164}
@@ -195,8 +205,10 @@ static int tda18271_read_thermometer(struct dvb_frontend *fe)
195 return tm; 205 return tm;
196} 206}
197 207
198static int tda18271_rf_tracking_filters_correction(struct dvb_frontend *fe, 208/* ------------------------------------------------------------------ */
199 u32 freq) 209
210static int tda18271c2_rf_tracking_filters_correction(struct dvb_frontend *fe,
211 u32 freq)
200{ 212{
201 struct tda18271_priv *priv = fe->tuner_priv; 213 struct tda18271_priv *priv = fe->tuner_priv;
202 struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state; 214 struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state;
@@ -296,12 +308,10 @@ static int tda18271_calibrate_rf(struct dvb_frontend *fe, u32 freq)
296 tda18271_write_regs(fe, R_EB13, 1); 308 tda18271_write_regs(fe, R_EB13, 1);
297 309
298 /* main pll charge pump source */ 310 /* main pll charge pump source */
299 regs[R_EB4] |= 0x20; 311 tda18271_charge_pump_source(fe, TDA18271_MAIN_PLL, 1);
300 tda18271_write_regs(fe, R_EB4, 1);
301 312
302 /* cal pll charge pump source */ 313 /* cal pll charge pump source */
303 regs[R_EB7] |= 0x20; 314 tda18271_charge_pump_source(fe, TDA18271_CAL_PLL, 1);
304 tda18271_write_regs(fe, R_EB7, 1);
305 315
306 /* force dcdc converter to 0 V */ 316 /* force dcdc converter to 0 V */
307 regs[R_EB14] = 0x00; 317 regs[R_EB14] = 0x00;
@@ -320,8 +330,8 @@ static int tda18271_calibrate_rf(struct dvb_frontend *fe, u32 freq)
320 /* set the internal calibration signal */ 330 /* set the internal calibration signal */
321 N = freq; 331 N = freq;
322 332
323 tda18271_calc_main_pll(fe, N); 333 tda18271_calc_cal_pll(fe, N);
324 tda18271_write_regs(fe, R_MPD, 4); 334 tda18271_write_regs(fe, R_CPD, 4);
325 335
326 /* downconvert internal calibration */ 336 /* downconvert internal calibration */
327 N += 1000000; 337 N += 1000000;
@@ -339,14 +349,12 @@ static int tda18271_calibrate_rf(struct dvb_frontend *fe, u32 freq)
339 /* --------------------------------------------------------------- */ 349 /* --------------------------------------------------------------- */
340 350
341 /* normal operation for the main pll */ 351 /* normal operation for the main pll */
342 regs[R_EB4] &= ~0x20; 352 tda18271_charge_pump_source(fe, TDA18271_MAIN_PLL, 0);
343 tda18271_write_regs(fe, R_EB4, 1);
344 353
345 /* normal operation for the cal pll */ 354 /* normal operation for the cal pll */
346 regs[R_EB7] &= ~0x20; 355 tda18271_charge_pump_source(fe, TDA18271_CAL_PLL, 0);
347 tda18271_write_regs(fe, R_EB7, 1);
348 356
349 msleep(5); /* plls locking */ 357 msleep(10); /* plls locking */
350 358
351 /* launch the rf tracking filters calibration */ 359 /* launch the rf tracking filters calibration */
352 regs[R_EB20] |= 0x20; 360 regs[R_EB20] |= 0x20;
@@ -443,7 +451,7 @@ static int tda18271_powerscan(struct dvb_frontend *fe,
443 451
444 count += 200; 452 count += 200;
445 453
446 if (count < count_limit) 454 if (count <= count_limit)
447 continue; 455 continue;
448 456
449 if (sgn <= 0) 457 if (sgn <= 0)
@@ -587,7 +595,7 @@ static int tda18271_calc_rf_filter_curve(struct dvb_frontend *fe)
587 595
588/* ------------------------------------------------------------------ */ 596/* ------------------------------------------------------------------ */
589 597
590static int tda18271_rf_cal_init(struct dvb_frontend *fe) 598static int tda18271c2_rf_cal_init(struct dvb_frontend *fe)
591{ 599{
592 struct tda18271_priv *priv = fe->tuner_priv; 600 struct tda18271_priv *priv = fe->tuner_priv;
593 unsigned char *regs = priv->tda18271_regs; 601 unsigned char *regs = priv->tda18271_regs;
@@ -610,63 +618,13 @@ static int tda18271_rf_cal_init(struct dvb_frontend *fe)
610 return 0; 618 return 0;
611} 619}
612 620
613static int tda18271_init(struct dvb_frontend *fe) 621static int tda18271c1_rf_tracking_filter_calibration(struct dvb_frontend *fe,
614{ 622 u32 freq, u32 bw)
615 struct tda18271_priv *priv = fe->tuner_priv;
616
617 mutex_lock(&priv->lock);
618
619 /* power up */
620 tda18271_set_standby_mode(fe, 0, 0, 0);
621
622 /* initialization */
623 tda18271_ir_cal_init(fe);
624
625 if (priv->id == TDA18271HDC2)
626 tda18271_rf_cal_init(fe);
627
628 mutex_unlock(&priv->lock);
629
630 return 0;
631}
632
633static int tda18271c2_tune(struct dvb_frontend *fe,
634 u32 ifc, u32 freq, u32 bw, u8 std, int radio)
635{
636 struct tda18271_priv *priv = fe->tuner_priv;
637
638 tda_dbg("freq = %d, ifc = %d\n", freq, ifc);
639
640 tda18271_init(fe);
641
642 mutex_lock(&priv->lock);
643
644 tda18271_rf_tracking_filters_correction(fe, freq);
645
646 tda18271_channel_configuration(fe, ifc, freq, bw, std, radio);
647
648 mutex_unlock(&priv->lock);
649
650 return 0;
651}
652
653/* ------------------------------------------------------------------ */
654
655static int tda18271c1_tune(struct dvb_frontend *fe,
656 u32 ifc, u32 freq, u32 bw, u8 std, int radio)
657{ 623{
658 struct tda18271_priv *priv = fe->tuner_priv; 624 struct tda18271_priv *priv = fe->tuner_priv;
659 unsigned char *regs = priv->tda18271_regs; 625 unsigned char *regs = priv->tda18271_regs;
660 u32 N = 0; 626 u32 N = 0;
661 627
662 tda18271_init(fe);
663
664 mutex_lock(&priv->lock);
665
666 tda_dbg("freq = %d, ifc = %d\n", freq, ifc);
667
668 /* RF tracking filter calibration */
669
670 /* calculate bp filter */ 628 /* calculate bp filter */
671 tda18271_calc_bp_filter(fe, &freq); 629 tda18271_calc_bp_filter(fe, &freq);
672 tda18271_write_regs(fe, R_EP1, 1); 630 tda18271_write_regs(fe, R_EP1, 1);
@@ -737,7 +695,7 @@ static int tda18271c1_tune(struct dvb_frontend *fe,
737 695
738 regs[R_EB7] = 0x40; 696 regs[R_EB7] = 0x40;
739 tda18271_write_regs(fe, R_EB7, 1); 697 tda18271_write_regs(fe, R_EB7, 1);
740 msleep(10); 698 msleep(10); /* pll locking */
741 699
742 regs[R_EB20] = 0xec; 700 regs[R_EB20] = 0xec;
743 tda18271_write_regs(fe, R_EB20, 1); 701 tda18271_write_regs(fe, R_EB20, 1);
@@ -752,74 +710,70 @@ static int tda18271c1_tune(struct dvb_frontend *fe,
752 if (0 == tda18271_calc_rf_cal(fe, &freq)) 710 if (0 == tda18271_calc_rf_cal(fe, &freq))
753 tda18271_write_regs(fe, R_EB14, 1); 711 tda18271_write_regs(fe, R_EB14, 1);
754 712
755 /* Channel Configuration */ 713 return 0;
714}
756 715
757 switch (priv->mode) { 716/* ------------------------------------------------------------------ */
758 case TDA18271_ANALOG:
759 regs[R_EB22] = 0x2c;
760 break;
761 case TDA18271_DIGITAL:
762 regs[R_EB22] = 0x37;
763 break;
764 }
765 tda18271_write_regs(fe, R_EB22, 1);
766 717
767 regs[R_EP1] |= 0x40; /* set dis power level on */ 718static int tda18271_ir_cal_init(struct dvb_frontend *fe)
719{
720 struct tda18271_priv *priv = fe->tuner_priv;
721 unsigned char *regs = priv->tda18271_regs;
768 722
769 /* set standard */ 723 tda18271_read_regs(fe);
770 regs[R_EP3] &= ~0x1f; /* clear std bits */
771 724
772 /* see table 22 */ 725 /* test IR_CAL_OK to see if we need init */
773 regs[R_EP3] |= std; 726 if ((regs[R_EP1] & 0x08) == 0)
727 tda18271_init_regs(fe);
774 728
775 regs[R_EP4] &= ~0x03; /* set cal mode to normal */ 729 return 0;
730}
776 731
777 regs[R_EP4] &= ~0x1c; /* clear if level bits */ 732static int tda18271_init(struct dvb_frontend *fe)
778 switch (priv->mode) { 733{
779 case TDA18271_ANALOG: 734 struct tda18271_priv *priv = fe->tuner_priv;
780 regs[R_MPD] &= ~0x80; /* IF notch = 0 */
781 break;
782 case TDA18271_DIGITAL:
783 regs[R_EP4] |= 0x04;
784 regs[R_MPD] |= 0x80;
785 break;
786 }
787 735
788 if (radio) 736 mutex_lock(&priv->lock);
789 regs[R_EP4] |= 0x80;
790 else
791 regs[R_EP4] &= ~0x80;
792 737
793 /* image rejection validity */ 738 /* power up */
794 tda18271_calc_ir_measure(fe, &freq); 739 tda18271_set_standby_mode(fe, 0, 0, 0);
795 740
796 /* calculate MAIN PLL */ 741 /* initialization */
797 N = freq + ifc; 742 tda18271_ir_cal_init(fe);
798 743
799 tda18271_calc_main_pll(fe, N); 744 if (priv->id == TDA18271HDC2)
745 tda18271c2_rf_cal_init(fe);
800 746
801 tda18271_write_regs(fe, R_TM, 15);
802 msleep(5);
803 mutex_unlock(&priv->lock); 747 mutex_unlock(&priv->lock);
804 748
805 return 0; 749 return 0;
806} 750}
807 751
808static inline int tda18271_tune(struct dvb_frontend *fe, 752static int tda18271_tune(struct dvb_frontend *fe,
809 u32 ifc, u32 freq, u32 bw, u8 std, int radio) 753 struct tda18271_std_map_item *map, u32 freq, u32 bw)
810{ 754{
811 struct tda18271_priv *priv = fe->tuner_priv; 755 struct tda18271_priv *priv = fe->tuner_priv;
812 int ret = -EINVAL; 756
757 tda_dbg("freq = %d, ifc = %d, bw = %d, agc_mode = %d, std = %d\n",
758 freq, map->if_freq, bw, map->agc_mode, map->std);
759
760 tda18271_init(fe);
761
762 mutex_lock(&priv->lock);
813 763
814 switch (priv->id) { 764 switch (priv->id) {
815 case TDA18271HDC1: 765 case TDA18271HDC1:
816 ret = tda18271c1_tune(fe, ifc, freq, bw, std, radio); 766 tda18271c1_rf_tracking_filter_calibration(fe, freq, bw);
817 break; 767 break;
818 case TDA18271HDC2: 768 case TDA18271HDC2:
819 ret = tda18271c2_tune(fe, ifc, freq, bw, std, radio); 769 tda18271c2_rf_tracking_filters_correction(fe, freq);
820 break; 770 break;
821 } 771 }
822 return ret; 772 tda18271_channel_configuration(fe, map, freq, bw);
773
774 mutex_unlock(&priv->lock);
775
776 return 0;
823} 777}
824 778
825/* ------------------------------------------------------------------ */ 779/* ------------------------------------------------------------------ */
@@ -829,9 +783,8 @@ static int tda18271_set_params(struct dvb_frontend *fe,
829{ 783{
830 struct tda18271_priv *priv = fe->tuner_priv; 784 struct tda18271_priv *priv = fe->tuner_priv;
831 struct tda18271_std_map *std_map = &priv->std; 785 struct tda18271_std_map *std_map = &priv->std;
786 struct tda18271_std_map_item *map;
832 int ret; 787 int ret;
833 u8 std;
834 u16 sgIF;
835 u32 bw, freq = params->frequency; 788 u32 bw, freq = params->frequency;
836 789
837 priv->mode = TDA18271_DIGITAL; 790 priv->mode = TDA18271_DIGITAL;
@@ -840,13 +793,11 @@ static int tda18271_set_params(struct dvb_frontend *fe,
840 switch (params->u.vsb.modulation) { 793 switch (params->u.vsb.modulation) {
841 case VSB_8: 794 case VSB_8:
842 case VSB_16: 795 case VSB_16:
843 std = std_map->atsc_6.std_bits; 796 map = &std_map->atsc_6;
844 sgIF = std_map->atsc_6.if_freq;
845 break; 797 break;
846 case QAM_64: 798 case QAM_64:
847 case QAM_256: 799 case QAM_256:
848 std = std_map->qam_6.std_bits; 800 map = &std_map->qam_6;
849 sgIF = std_map->qam_6.if_freq;
850 break; 801 break;
851 default: 802 default:
852 tda_warn("modulation not set!\n"); 803 tda_warn("modulation not set!\n");
@@ -861,18 +812,15 @@ static int tda18271_set_params(struct dvb_frontend *fe,
861 switch (params->u.ofdm.bandwidth) { 812 switch (params->u.ofdm.bandwidth) {
862 case BANDWIDTH_6_MHZ: 813 case BANDWIDTH_6_MHZ:
863 bw = 6000000; 814 bw = 6000000;
864 std = std_map->dvbt_6.std_bits; 815 map = &std_map->dvbt_6;
865 sgIF = std_map->dvbt_6.if_freq;
866 break; 816 break;
867 case BANDWIDTH_7_MHZ: 817 case BANDWIDTH_7_MHZ:
868 bw = 7000000; 818 bw = 7000000;
869 std = std_map->dvbt_7.std_bits; 819 map = &std_map->dvbt_7;
870 sgIF = std_map->dvbt_7.if_freq;
871 break; 820 break;
872 case BANDWIDTH_8_MHZ: 821 case BANDWIDTH_8_MHZ:
873 bw = 8000000; 822 bw = 8000000;
874 std = std_map->dvbt_8.std_bits; 823 map = &std_map->dvbt_8;
875 sgIF = std_map->dvbt_8.if_freq;
876 break; 824 break;
877 default: 825 default:
878 tda_warn("bandwidth not set!\n"); 826 tda_warn("bandwidth not set!\n");
@@ -887,7 +835,7 @@ static int tda18271_set_params(struct dvb_frontend *fe,
887 if (fe->ops.analog_ops.standby) 835 if (fe->ops.analog_ops.standby)
888 fe->ops.analog_ops.standby(fe); 836 fe->ops.analog_ops.standby(fe);
889 837
890 ret = tda18271_tune(fe, sgIF * 1000, freq, bw, std, 0); 838 ret = tda18271_tune(fe, map, freq, bw);
891 839
892 if (ret < 0) 840 if (ret < 0)
893 goto fail; 841 goto fail;
@@ -904,57 +852,46 @@ static int tda18271_set_analog_params(struct dvb_frontend *fe,
904{ 852{
905 struct tda18271_priv *priv = fe->tuner_priv; 853 struct tda18271_priv *priv = fe->tuner_priv;
906 struct tda18271_std_map *std_map = &priv->std; 854 struct tda18271_std_map *std_map = &priv->std;
855 struct tda18271_std_map_item *map;
907 char *mode; 856 char *mode;
908 int ret, radio = 0; 857 int ret;
909 u8 std;
910 u16 sgIF;
911 u32 freq = params->frequency * 62500; 858 u32 freq = params->frequency * 62500;
912 859
913 priv->mode = TDA18271_ANALOG; 860 priv->mode = TDA18271_ANALOG;
914 861
915 if (params->mode == V4L2_TUNER_RADIO) { 862 if (params->mode == V4L2_TUNER_RADIO) {
916 radio = 1;
917 freq = freq / 1000; 863 freq = freq / 1000;
918 std = std_map->fm_radio.std_bits; 864 map = &std_map->fm_radio;
919 sgIF = std_map->fm_radio.if_freq;
920 mode = "fm"; 865 mode = "fm";
921 } else if (params->std & V4L2_STD_MN) { 866 } else if (params->std & V4L2_STD_MN) {
922 std = std_map->atv_mn.std_bits; 867 map = &std_map->atv_mn;
923 sgIF = std_map->atv_mn.if_freq;
924 mode = "MN"; 868 mode = "MN";
925 } else if (params->std & V4L2_STD_B) { 869 } else if (params->std & V4L2_STD_B) {
926 std = std_map->atv_b.std_bits; 870 map = &std_map->atv_b;
927 sgIF = std_map->atv_b.if_freq;
928 mode = "B"; 871 mode = "B";
929 } else if (params->std & V4L2_STD_GH) { 872 } else if (params->std & V4L2_STD_GH) {
930 std = std_map->atv_gh.std_bits; 873 map = &std_map->atv_gh;
931 sgIF = std_map->atv_gh.if_freq;
932 mode = "GH"; 874 mode = "GH";
933 } else if (params->std & V4L2_STD_PAL_I) { 875 } else if (params->std & V4L2_STD_PAL_I) {
934 std = std_map->atv_i.std_bits; 876 map = &std_map->atv_i;
935 sgIF = std_map->atv_i.if_freq;
936 mode = "I"; 877 mode = "I";
937 } else if (params->std & V4L2_STD_DK) { 878 } else if (params->std & V4L2_STD_DK) {
938 std = std_map->atv_dk.std_bits; 879 map = &std_map->atv_dk;
939 sgIF = std_map->atv_dk.if_freq;
940 mode = "DK"; 880 mode = "DK";
941 } else if (params->std & V4L2_STD_SECAM_L) { 881 } else if (params->std & V4L2_STD_SECAM_L) {
942 std = std_map->atv_l.std_bits; 882 map = &std_map->atv_l;
943 sgIF = std_map->atv_l.if_freq;
944 mode = "L"; 883 mode = "L";
945 } else if (params->std & V4L2_STD_SECAM_LC) { 884 } else if (params->std & V4L2_STD_SECAM_LC) {
946 std = std_map->atv_lc.std_bits; 885 map = &std_map->atv_lc;
947 sgIF = std_map->atv_lc.if_freq;
948 mode = "L'"; 886 mode = "L'";
949 } else { 887 } else {
950 std = std_map->atv_i.std_bits; 888 map = &std_map->atv_i;
951 sgIF = std_map->atv_i.if_freq;
952 mode = "xx"; 889 mode = "xx";
953 } 890 }
954 891
955 tda_dbg("setting tda18271 to system %s\n", mode); 892 tda_dbg("setting tda18271 to system %s\n", mode);
956 893
957 ret = tda18271_tune(fe, sgIF * 1000, freq, 0, std, radio); 894 ret = tda18271_tune(fe, map, freq, 0);
958 895
959 if (ret < 0) 896 if (ret < 0)
960 goto fail; 897 goto fail;
@@ -986,16 +923,9 @@ static int tda18271_release(struct dvb_frontend *fe)
986 923
987 mutex_lock(&tda18271_list_mutex); 924 mutex_lock(&tda18271_list_mutex);
988 925
989 priv->count--; 926 if (priv)
927 hybrid_tuner_release_state(priv);
990 928
991 if (!priv->count) {
992 tda_dbg("destroying instance @ %d-%04x\n",
993 i2c_adapter_id(priv->i2c_adap),
994 priv->i2c_addr);
995 list_del(&priv->tda18271_list);
996
997 kfree(priv);
998 }
999 mutex_unlock(&tda18271_list_mutex); 929 mutex_unlock(&tda18271_list_mutex);
1000 930
1001 fe->tuner_priv = NULL; 931 fe->tuner_priv = NULL;
@@ -1020,15 +950,20 @@ static int tda18271_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
1020/* ------------------------------------------------------------------ */ 950/* ------------------------------------------------------------------ */
1021 951
1022#define tda18271_update_std(std_cfg, name) do { \ 952#define tda18271_update_std(std_cfg, name) do { \
1023 if (map->std_cfg.if_freq + map->std_cfg.std_bits > 0) { \ 953 if (map->std_cfg.if_freq + \
954 map->std_cfg.agc_mode + map->std_cfg.std + \
955 map->std_cfg.if_lvl + map->std_cfg.rfagc_top > 0) { \
1024 tda_dbg("Using custom std config for %s\n", name); \ 956 tda_dbg("Using custom std config for %s\n", name); \
1025 memcpy(&std->std_cfg, &map->std_cfg, \ 957 memcpy(&std->std_cfg, &map->std_cfg, \
1026 sizeof(struct tda18271_std_map_item)); \ 958 sizeof(struct tda18271_std_map_item)); \
1027 } } while (0) 959 } } while (0)
1028 960
1029#define tda18271_dump_std_item(std_cfg, name) do { \ 961#define tda18271_dump_std_item(std_cfg, name) do { \
1030 tda_dbg("(%s) if freq = %d, std bits = 0x%02x\n", \ 962 tda_dbg("(%s) if_freq = %d, agc_mode = %d, std = %d, " \
1031 name, std->std_cfg.if_freq, std->std_cfg.std_bits); \ 963 "if_lvl = %d, rfagc_top = 0x%02x\n", \
964 name, std->std_cfg.if_freq, \
965 std->std_cfg.agc_mode, std->std_cfg.std, \
966 std->std_cfg.if_lvl, std->std_cfg.rfagc_top); \
1032 } while (0) 967 } while (0)
1033 968
1034static int tda18271_dump_std_map(struct dvb_frontend *fe) 969static int tda18271_dump_std_map(struct dvb_frontend *fe)
@@ -1037,20 +972,20 @@ static int tda18271_dump_std_map(struct dvb_frontend *fe)
1037 struct tda18271_std_map *std = &priv->std; 972 struct tda18271_std_map *std = &priv->std;
1038 973
1039 tda_dbg("========== STANDARD MAP SETTINGS ==========\n"); 974 tda_dbg("========== STANDARD MAP SETTINGS ==========\n");
1040 tda18271_dump_std_item(fm_radio, "fm"); 975 tda18271_dump_std_item(fm_radio, " fm ");
1041 tda18271_dump_std_item(atv_b, "pal b"); 976 tda18271_dump_std_item(atv_b, "atv b ");
1042 tda18271_dump_std_item(atv_dk, "pal dk"); 977 tda18271_dump_std_item(atv_dk, "atv dk");
1043 tda18271_dump_std_item(atv_gh, "pal gh"); 978 tda18271_dump_std_item(atv_gh, "atv gh");
1044 tda18271_dump_std_item(atv_i, "pal i"); 979 tda18271_dump_std_item(atv_i, "atv i ");
1045 tda18271_dump_std_item(atv_l, "pal l"); 980 tda18271_dump_std_item(atv_l, "atv l ");
1046 tda18271_dump_std_item(atv_lc, "pal l'"); 981 tda18271_dump_std_item(atv_lc, "atv l'");
1047 tda18271_dump_std_item(atv_mn, "atv mn"); 982 tda18271_dump_std_item(atv_mn, "atv mn");
1048 tda18271_dump_std_item(atsc_6, "atsc 6"); 983 tda18271_dump_std_item(atsc_6, "atsc 6");
1049 tda18271_dump_std_item(dvbt_6, "dvbt 6"); 984 tda18271_dump_std_item(dvbt_6, "dvbt 6");
1050 tda18271_dump_std_item(dvbt_7, "dvbt 7"); 985 tda18271_dump_std_item(dvbt_7, "dvbt 7");
1051 tda18271_dump_std_item(dvbt_8, "dvbt 8"); 986 tda18271_dump_std_item(dvbt_8, "dvbt 8");
1052 tda18271_dump_std_item(qam_6, "qam 6"); 987 tda18271_dump_std_item(qam_6, "qam 6 ");
1053 tda18271_dump_std_item(qam_8, "qam 8"); 988 tda18271_dump_std_item(qam_8, "qam 8 ");
1054 989
1055 return 0; 990 return 0;
1056} 991}
@@ -1109,7 +1044,8 @@ static int tda18271_get_id(struct dvb_frontend *fe)
1109 } 1044 }
1110 1045
1111 tda_info("%s detected @ %d-%04x%s\n", name, 1046 tda_info("%s detected @ %d-%04x%s\n", name,
1112 i2c_adapter_id(priv->i2c_adap), priv->i2c_addr, 1047 i2c_adapter_id(priv->i2c_props.adap),
1048 priv->i2c_props.addr,
1113 (0 == ret) ? "" : ", device not supported."); 1049 (0 == ret) ? "" : ", device not supported.");
1114 1050
1115 return ret; 1051 return ret;
@@ -1136,45 +1072,28 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1136 struct tda18271_config *cfg) 1072 struct tda18271_config *cfg)
1137{ 1073{
1138 struct tda18271_priv *priv = NULL; 1074 struct tda18271_priv *priv = NULL;
1139 int state_found = 0; 1075 int instance;
1140 1076
1141 mutex_lock(&tda18271_list_mutex); 1077 mutex_lock(&tda18271_list_mutex);
1142 1078
1143 list_for_each_entry(priv, &tda18271_list, tda18271_list) { 1079 instance = hybrid_tuner_request_state(struct tda18271_priv, priv,
1144 if ((i2c_adapter_id(priv->i2c_adap) == i2c_adapter_id(i2c)) && 1080 hybrid_tuner_instance_list,
1145 (priv->i2c_addr == addr)) { 1081 i2c, addr, "tda18271");
1146 tda_dbg("attaching existing tuner @ %d-%04x\n", 1082 switch (instance) {
1147 i2c_adapter_id(priv->i2c_adap), 1083 case 0:
1148 priv->i2c_addr); 1084 goto fail;
1149 priv->count++; 1085 break;
1150 fe->tuner_priv = priv; 1086 case 1:
1151 state_found = 1; 1087 /* new tuner instance */
1152 /* allow dvb driver to override i2c gate setting */
1153 if ((cfg) && (cfg->gate != TDA18271_GATE_ANALOG))
1154 priv->gate = cfg->gate;
1155 break;
1156 }
1157 }
1158 if (state_found == 0) {
1159 tda_dbg("creating new tuner instance @ %d-%04x\n",
1160 i2c_adapter_id(i2c), addr);
1161
1162 priv = kzalloc(sizeof(struct tda18271_priv), GFP_KERNEL);
1163 if (priv == NULL) {
1164 mutex_unlock(&tda18271_list_mutex);
1165 return NULL;
1166 }
1167
1168 priv->i2c_addr = addr;
1169 priv->i2c_adap = i2c;
1170 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO; 1088 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO;
1089 priv->role = (cfg) ? cfg->role : TDA18271_MASTER;
1171 priv->cal_initialized = false; 1090 priv->cal_initialized = false;
1172 mutex_init(&priv->lock); 1091 mutex_init(&priv->lock);
1173 priv->count++;
1174 1092
1175 fe->tuner_priv = priv; 1093 fe->tuner_priv = priv;
1176 1094
1177 list_add_tail(&priv->tda18271_list, &tda18271_list); 1095 if (cfg)
1096 priv->small_i2c = cfg->small_i2c;
1178 1097
1179 if (tda18271_get_id(fe) < 0) 1098 if (tda18271_get_id(fe) < 0)
1180 goto fail; 1099 goto fail;
@@ -1186,9 +1105,18 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1186 tda18271_init_regs(fe); 1105 tda18271_init_regs(fe);
1187 1106
1188 if ((tda18271_cal_on_startup) && (priv->id == TDA18271HDC2)) 1107 if ((tda18271_cal_on_startup) && (priv->id == TDA18271HDC2))
1189 tda18271_rf_cal_init(fe); 1108 tda18271c2_rf_cal_init(fe);
1190 1109
1191 mutex_unlock(&priv->lock); 1110 mutex_unlock(&priv->lock);
1111 break;
1112 default:
1113 /* existing tuner instance */
1114 fe->tuner_priv = priv;
1115
1116 /* allow dvb driver to override i2c gate setting */
1117 if ((cfg) && (cfg->gate != TDA18271_GATE_ANALOG))
1118 priv->gate = cfg->gate;
1119 break;
1192 } 1120 }
1193 1121
1194 /* override default std map with values in config struct */ 1122 /* override default std map with values in config struct */
@@ -1200,7 +1128,7 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1200 memcpy(&fe->ops.tuner_ops, &tda18271_tuner_ops, 1128 memcpy(&fe->ops.tuner_ops, &tda18271_tuner_ops,
1201 sizeof(struct dvb_tuner_ops)); 1129 sizeof(struct dvb_tuner_ops));
1202 1130
1203 if (tda18271_debug & DBG_MAP) 1131 if (tda18271_debug & (DBG_MAP | DBG_ADV))
1204 tda18271_dump_std_map(fe); 1132 tda18271_dump_std_map(fe);
1205 1133
1206 return fe; 1134 return fe;
@@ -1214,7 +1142,7 @@ EXPORT_SYMBOL_GPL(tda18271_attach);
1214MODULE_DESCRIPTION("NXP TDA18271HD analog / digital tuner driver"); 1142MODULE_DESCRIPTION("NXP TDA18271HD analog / digital tuner driver");
1215MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); 1143MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1216MODULE_LICENSE("GPL"); 1144MODULE_LICENSE("GPL");
1217MODULE_VERSION("0.2"); 1145MODULE_VERSION("0.3");
1218 1146
1219/* 1147/*
1220 * Overrides for Emacs so that we follow Linus's tabbing style. 1148 * Overrides for Emacs so that we follow Linus's tabbing style.