2 tda18271-fe.c - driver for the Philips / NXP TDA18271 silicon tuner
4 Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <linux/delay.h>
22 #include <linux/videodev2.h>
23 #include "tda18271-priv.h"
26 module_param_named(debug, tda18271_debug, int, 0644);
27 MODULE_PARM_DESC(debug, "set debug level "
28 "(info=1, map=2, reg=4, adv=8, cal=16 (or-able))");
30 static int tda18271_cal_on_startup;
31 module_param_named(cal, tda18271_cal_on_startup, int, 0644);
32 MODULE_PARM_DESC(cal, "perform RF tracking filter calibration on startup");
34 static DEFINE_MUTEX(tda18271_list_mutex);
35 static LIST_HEAD(hybrid_tuner_instance_list);
37 /*---------------------------------------------------------------------*/
39 static int tda18271_channel_configuration(struct dvb_frontend *fe,
40 u32 ifc, u32 freq, u32 bw, u8 std,
43 struct tda18271_priv *priv = fe->tuner_priv;
44 unsigned char *regs = priv->tda18271_regs;
47 /* update TV broadcast parameters */
50 regs[R_EP3] &= ~0x1f; /* clear std bits */
53 /* set cal mode to normal */
56 /* update IF output level & IF notch frequency */
57 regs[R_EP4] &= ~0x1c; /* clear if level bits */
61 regs[R_MPD] &= ~0x80; /* IF notch = 0 */
63 case TDA18271_DIGITAL:
64 regs[R_EP4] |= 0x04; /* IF level = 1 */
65 regs[R_MPD] |= 0x80; /* IF notch = 1 */
74 /* update RF_TOP / IF_TOP */
79 case TDA18271_DIGITAL:
83 tda18271_write_regs(fe, R_EB22, 1);
85 /* --------------------------------------------------------------- */
87 /* disable Power Level Indicator */
90 /* frequency dependent parameters */
92 tda18271_calc_ir_measure(fe, &freq);
94 tda18271_calc_bp_filter(fe, &freq);
96 tda18271_calc_rf_band(fe, &freq);
98 tda18271_calc_gain_taper(fe, &freq);
100 /* --------------------------------------------------------------- */
102 /* dual tuner and agc1 extra configuration */
104 /* main vco when Master, cal vco when slave */
105 regs[R_EB1] |= 0x04; /* FIXME: assumes master */
107 /* agc1 always active */
108 regs[R_EB1] &= ~0x02;
110 /* agc1 has priority on agc2 */
111 regs[R_EB1] &= ~0x01;
113 tda18271_write_regs(fe, R_EB1, 1);
115 /* --------------------------------------------------------------- */
119 /* FIXME: assumes master */
120 tda18271_calc_main_pll(fe, N);
121 tda18271_write_regs(fe, R_MPD, 4);
123 tda18271_write_regs(fe, R_TM, 7);
125 /* main pll charge pump source */
127 tda18271_write_regs(fe, R_EB4, 1);
131 /* normal operation for the main pll */
132 regs[R_EB4] &= ~0x20;
133 tda18271_write_regs(fe, R_EB4, 1);
140 static int tda18271_read_thermometer(struct dvb_frontend *fe)
142 struct tda18271_priv *priv = fe->tuner_priv;
143 unsigned char *regs = priv->tda18271_regs;
146 /* switch thermometer on */
148 tda18271_write_regs(fe, R_TM, 1);
150 /* read thermometer info */
151 tda18271_read_regs(fe);
153 if ((((regs[R_TM] & 0x0f) == 0x00) && ((regs[R_TM] & 0x20) == 0x20)) ||
154 (((regs[R_TM] & 0x0f) == 0x08) && ((regs[R_TM] & 0x20) == 0x00))) {
156 if ((regs[R_TM] & 0x20) == 0x20)
161 tda18271_write_regs(fe, R_TM, 1);
163 msleep(10); /* temperature sensing */
165 /* read thermometer info */
166 tda18271_read_regs(fe);
169 tm = tda18271_lookup_thermometer(fe);
171 /* switch thermometer off */
173 tda18271_write_regs(fe, R_TM, 1);
175 /* set CAL mode to normal */
176 regs[R_EP4] &= ~0x03;
177 tda18271_write_regs(fe, R_EP4, 1);
182 /* ------------------------------------------------------------------ */
184 static int tda18271c2_rf_tracking_filters_correction(struct dvb_frontend *fe,
187 struct tda18271_priv *priv = fe->tuner_priv;
188 struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state;
189 unsigned char *regs = priv->tda18271_regs;
190 int tm_current, rfcal_comp, approx, i;
191 u8 dc_over_dt, rf_tab;
194 tda18271_set_standby_mode(fe, 0, 0, 0);
196 /* read die current temperature */
197 tm_current = tda18271_read_thermometer(fe);
199 /* frequency dependent parameters */
201 tda18271_calc_rf_cal(fe, &freq);
202 rf_tab = regs[R_EB14];
204 i = tda18271_lookup_rf_band(fe, &freq, NULL);
208 if ((0 == map[i].rf3) || (freq / 1000 < map[i].rf2)) {
209 approx = map[i].rf_a1 *
210 (freq / 1000 - map[i].rf1) + map[i].rf_b1 + rf_tab;
212 approx = map[i].rf_a2 *
213 (freq / 1000 - map[i].rf2) + map[i].rf_b2 + rf_tab;
221 tda18271_lookup_map(fe, RF_CAL_DC_OVER_DT, &freq, &dc_over_dt);
223 /* calculate temperature compensation */
224 rfcal_comp = dc_over_dt * (tm_current - priv->tm_rfcal);
226 regs[R_EB14] = approx + rfcal_comp;
227 tda18271_write_regs(fe, R_EB14, 1);
232 static int tda18271_por(struct dvb_frontend *fe)
234 struct tda18271_priv *priv = fe->tuner_priv;
235 unsigned char *regs = priv->tda18271_regs;
237 /* power up detector 1 */
238 regs[R_EB12] &= ~0x20;
239 tda18271_write_regs(fe, R_EB12, 1);
241 regs[R_EB18] &= ~0x80; /* turn agc1 loop on */
242 regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */
243 tda18271_write_regs(fe, R_EB18, 1);
245 regs[R_EB21] |= 0x03; /* set agc2_gain to -6 dB */
248 tda18271_set_standby_mode(fe, 1, 0, 0);
250 /* disable 1.5 MHz low pass filter */
251 regs[R_EB23] &= ~0x04; /* forcelp_fc2_en = 0 */
252 regs[R_EB23] &= ~0x02; /* XXX: lp_fc[2] = 0 */
253 tda18271_write_regs(fe, R_EB21, 3);
258 static int tda18271_calibrate_rf(struct dvb_frontend *fe, u32 freq)
260 struct tda18271_priv *priv = fe->tuner_priv;
261 unsigned char *regs = priv->tda18271_regs;
264 /* set CAL mode to normal */
265 regs[R_EP4] &= ~0x03;
266 tda18271_write_regs(fe, R_EP4, 1);
268 /* switch off agc1 */
269 regs[R_EP3] |= 0x40; /* sm_lt = 1 */
271 regs[R_EB18] |= 0x03; /* set agc1_gain to 15 dB */
272 tda18271_write_regs(fe, R_EB18, 1);
274 /* frequency dependent parameters */
276 tda18271_calc_bp_filter(fe, &freq);
277 tda18271_calc_gain_taper(fe, &freq);
278 tda18271_calc_rf_band(fe, &freq);
279 tda18271_calc_km(fe, &freq);
281 tda18271_write_regs(fe, R_EP1, 3);
282 tda18271_write_regs(fe, R_EB13, 1);
284 /* main pll charge pump source */
286 tda18271_write_regs(fe, R_EB4, 1);
288 /* cal pll charge pump source */
290 tda18271_write_regs(fe, R_EB7, 1);
292 /* force dcdc converter to 0 V */
294 tda18271_write_regs(fe, R_EB14, 1);
296 /* disable plls lock */
297 regs[R_EB20] &= ~0x20;
298 tda18271_write_regs(fe, R_EB20, 1);
300 /* set CAL mode to RF tracking filter calibration */
302 tda18271_write_regs(fe, R_EP4, 2);
304 /* --------------------------------------------------------------- */
306 /* set the internal calibration signal */
309 tda18271_calc_main_pll(fe, N);
310 tda18271_write_regs(fe, R_MPD, 4);
312 /* downconvert internal calibration */
315 tda18271_calc_main_pll(fe, N);
316 tda18271_write_regs(fe, R_MPD, 4);
320 tda18271_write_regs(fe, R_EP2, 1);
321 tda18271_write_regs(fe, R_EP1, 1);
322 tda18271_write_regs(fe, R_EP2, 1);
323 tda18271_write_regs(fe, R_EP1, 1);
325 /* --------------------------------------------------------------- */
327 /* normal operation for the main pll */
328 regs[R_EB4] &= ~0x20;
329 tda18271_write_regs(fe, R_EB4, 1);
331 /* normal operation for the cal pll */
332 regs[R_EB7] &= ~0x20;
333 tda18271_write_regs(fe, R_EB7, 1);
335 msleep(5); /* plls locking */
337 /* launch the rf tracking filters calibration */
338 regs[R_EB20] |= 0x20;
339 tda18271_write_regs(fe, R_EB20, 1);
341 msleep(60); /* calibration */
343 /* --------------------------------------------------------------- */
345 /* set CAL mode to normal */
346 regs[R_EP4] &= ~0x03;
349 regs[R_EP3] &= ~0x40; /* sm_lt = 0 */
351 regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */
352 tda18271_write_regs(fe, R_EB18, 1);
354 tda18271_write_regs(fe, R_EP3, 2);
356 /* synchronization */
357 tda18271_write_regs(fe, R_EP1, 1);
359 /* get calibration result */
360 tda18271_read_extended(fe);
365 static int tda18271_powerscan(struct dvb_frontend *fe,
366 u32 *freq_in, u32 *freq_out)
368 struct tda18271_priv *priv = fe->tuner_priv;
369 unsigned char *regs = priv->tda18271_regs;
370 int sgn, bcal, count, wait;
377 tda18271_calc_rf_band(fe, &freq);
378 tda18271_calc_rf_cal(fe, &freq);
379 tda18271_calc_gain_taper(fe, &freq);
380 tda18271_lookup_cid_target(fe, &freq, &cid_target, &count_limit);
382 tda18271_write_regs(fe, R_EP2, 1);
383 tda18271_write_regs(fe, R_EB14, 1);
385 /* downconvert frequency */
388 tda18271_calc_main_pll(fe, freq);
389 tda18271_write_regs(fe, R_MPD, 4);
391 msleep(5); /* pll locking */
394 regs[R_EP4] &= ~0x03;
396 tda18271_write_regs(fe, R_EP4, 1);
398 /* launch power detection measurement */
399 tda18271_write_regs(fe, R_EP2, 1);
401 /* read power detection info, stored in EB10 */
402 tda18271_read_extended(fe);
404 /* algorithm initialization */
406 *freq_out = *freq_in;
411 while ((regs[R_EB10] & 0x3f) < cid_target) {
412 /* downconvert updated freq to 1 MHz */
413 freq = *freq_in + (sgn * count) + 1000000;
415 tda18271_calc_main_pll(fe, freq);
416 tda18271_write_regs(fe, R_MPD, 4);
419 msleep(5); /* pll locking */
422 udelay(100); /* pll locking */
424 /* launch power detection measurement */
425 tda18271_write_regs(fe, R_EP2, 1);
427 /* read power detection info, stored in EB10 */
428 tda18271_read_extended(fe);
432 if (count < count_limit)
443 if ((regs[R_EB10] & 0x3f) >= cid_target) {
445 *freq_out = freq - 1000000;
449 tda_cal("bcal = %d, freq_in = %d, freq_out = %d (freq = %d)\n",
450 bcal, *freq_in, *freq_out, freq);
455 static int tda18271_powerscan_init(struct dvb_frontend *fe)
457 struct tda18271_priv *priv = fe->tuner_priv;
458 unsigned char *regs = priv->tda18271_regs;
460 /* set standard to digital */
461 regs[R_EP3] &= ~0x1f; /* clear std bits */
464 /* set cal mode to normal */
465 regs[R_EP4] &= ~0x03;
467 /* update IF output level & IF notch frequency */
468 regs[R_EP4] &= ~0x1c; /* clear if level bits */
470 tda18271_write_regs(fe, R_EP3, 2);
472 regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */
473 tda18271_write_regs(fe, R_EB18, 1);
475 regs[R_EB21] &= ~0x03; /* set agc2_gain to -15 dB */
477 /* 1.5 MHz low pass filter */
478 regs[R_EB23] |= 0x04; /* forcelp_fc2_en = 1 */
479 regs[R_EB23] |= 0x02; /* lp_fc[2] = 1 */
481 tda18271_write_regs(fe, R_EB21, 3);
486 static int tda18271_rf_tracking_filters_init(struct dvb_frontend *fe, u32 freq)
488 struct tda18271_priv *priv = fe->tuner_priv;
489 struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state;
490 unsigned char *regs = priv->tda18271_regs;
500 i = tda18271_lookup_rf_band(fe, &freq, NULL);
505 rf_default[RF1] = 1000 * map[i].rf1_def;
506 rf_default[RF2] = 1000 * map[i].rf2_def;
507 rf_default[RF3] = 1000 * map[i].rf3_def;
509 for (rf = RF1; rf <= RF3; rf++) {
510 if (0 == rf_default[rf])
512 tda_cal("freq = %d, rf = %d\n", freq, rf);
514 /* look for optimized calibration frequency */
515 bcal = tda18271_powerscan(fe, &rf_default[rf], &rf_freq[rf]);
517 tda18271_calc_rf_cal(fe, &rf_freq[rf]);
518 prog_tab[rf] = regs[R_EB14];
521 prog_cal[rf] = tda18271_calibrate_rf(fe, rf_freq[rf]);
523 prog_cal[rf] = prog_tab[rf];
528 map[i].rf_b1 = prog_cal[RF1] - prog_tab[RF1];
529 map[i].rf1 = rf_freq[RF1] / 1000;
532 map[i].rf_a1 = (prog_cal[RF2] - prog_tab[RF2] -
533 prog_cal[RF1] + prog_tab[RF1]) /
534 ((rf_freq[RF2] - rf_freq[RF1]) / 1000);
535 map[i].rf2 = rf_freq[RF2] / 1000;
538 map[i].rf_a2 = (prog_cal[RF3] - prog_tab[RF3] -
539 prog_cal[RF2] + prog_tab[RF2]) /
540 ((rf_freq[RF3] - rf_freq[RF2]) / 1000);
541 map[i].rf_b2 = prog_cal[RF2] - prog_tab[RF2];
542 map[i].rf3 = rf_freq[RF3] / 1000;
552 static int tda18271_calc_rf_filter_curve(struct dvb_frontend *fe)
554 struct tda18271_priv *priv = fe->tuner_priv;
557 tda_info("tda18271: performing RF tracking filter calibration\n");
559 /* wait for die temperature stabilization */
562 tda18271_powerscan_init(fe);
564 /* rf band calibration */
565 for (i = 0; priv->rf_cal_state[i].rfmax != 0; i++)
566 tda18271_rf_tracking_filters_init(fe, 1000 *
567 priv->rf_cal_state[i].rfmax);
569 priv->tm_rfcal = tda18271_read_thermometer(fe);
574 /* ------------------------------------------------------------------ */
576 static int tda18271c2_rf_cal_init(struct dvb_frontend *fe)
578 struct tda18271_priv *priv = fe->tuner_priv;
579 unsigned char *regs = priv->tda18271_regs;
581 /* test RF_CAL_OK to see if we need init */
582 if ((regs[R_EP1] & 0x10) == 0)
583 priv->cal_initialized = false;
585 if (priv->cal_initialized)
588 tda18271_calc_rf_filter_curve(fe);
592 tda_info("tda18271: RF tracking filter calibration complete\n");
594 priv->cal_initialized = true;
599 static int tda18271c1_rf_tracking_filter_calibration(struct dvb_frontend *fe,
602 struct tda18271_priv *priv = fe->tuner_priv;
603 unsigned char *regs = priv->tda18271_regs;
606 /* calculate bp filter */
607 tda18271_calc_bp_filter(fe, &freq);
608 tda18271_write_regs(fe, R_EP1, 1);
612 tda18271_write_regs(fe, R_EB4, 1);
615 tda18271_write_regs(fe, R_EB7, 1);
618 tda18271_write_regs(fe, R_EB14, 1);
621 tda18271_write_regs(fe, R_EB20, 1);
623 /* set cal mode to RF tracking filter calibration */
626 /* calculate cal pll */
628 switch (priv->mode) {
629 case TDA18271_ANALOG:
632 case TDA18271_DIGITAL:
637 tda18271_calc_cal_pll(fe, N);
639 /* calculate main pll */
641 switch (priv->mode) {
642 case TDA18271_ANALOG:
645 case TDA18271_DIGITAL:
646 N = freq + bw / 2 + 1000000;
650 tda18271_calc_main_pll(fe, N);
652 tda18271_write_regs(fe, R_EP3, 11);
653 msleep(5); /* RF tracking filter calibration initialization */
655 /* search for K,M,CO for RF calibration */
656 tda18271_calc_km(fe, &freq);
657 tda18271_write_regs(fe, R_EB13, 1);
659 /* search for rf band */
660 tda18271_calc_rf_band(fe, &freq);
662 /* search for gain taper */
663 tda18271_calc_gain_taper(fe, &freq);
665 tda18271_write_regs(fe, R_EP2, 1);
666 tda18271_write_regs(fe, R_EP1, 1);
667 tda18271_write_regs(fe, R_EP2, 1);
668 tda18271_write_regs(fe, R_EP1, 1);
672 tda18271_write_regs(fe, R_EB4, 1);
675 tda18271_write_regs(fe, R_EB7, 1);
676 msleep(10); /* pll locking */
679 tda18271_write_regs(fe, R_EB20, 1);
680 msleep(60); /* RF tracking filter calibration completion */
682 regs[R_EP4] &= ~0x03; /* set cal mode to normal */
683 tda18271_write_regs(fe, R_EP4, 1);
685 tda18271_write_regs(fe, R_EP1, 1);
687 /* RF tracking filter correction for VHF_Low band */
688 if (0 == tda18271_calc_rf_cal(fe, &freq))
689 tda18271_write_regs(fe, R_EB14, 1);
694 /* ------------------------------------------------------------------ */
696 static int tda18271_ir_cal_init(struct dvb_frontend *fe)
698 struct tda18271_priv *priv = fe->tuner_priv;
699 unsigned char *regs = priv->tda18271_regs;
701 tda18271_read_regs(fe);
703 /* test IR_CAL_OK to see if we need init */
704 if ((regs[R_EP1] & 0x08) == 0)
705 tda18271_init_regs(fe);
710 static int tda18271_init(struct dvb_frontend *fe)
712 struct tda18271_priv *priv = fe->tuner_priv;
714 mutex_lock(&priv->lock);
717 tda18271_set_standby_mode(fe, 0, 0, 0);
720 tda18271_ir_cal_init(fe);
722 if (priv->id == TDA18271HDC2)
723 tda18271c2_rf_cal_init(fe);
725 mutex_unlock(&priv->lock);
730 static int tda18271_tune(struct dvb_frontend *fe,
731 u32 ifc, u32 freq, u32 bw, u8 std, int radio)
733 struct tda18271_priv *priv = fe->tuner_priv;
735 tda_dbg("freq = %d, ifc = %d, bw = %d, std = 0x%02x\n",
740 mutex_lock(&priv->lock);
744 tda18271c1_rf_tracking_filter_calibration(fe, freq, bw);
747 tda18271c2_rf_tracking_filters_correction(fe, freq);
750 tda18271_channel_configuration(fe, ifc, freq, bw, std, radio);
752 mutex_unlock(&priv->lock);
757 /* ------------------------------------------------------------------ */
759 static int tda18271_set_params(struct dvb_frontend *fe,
760 struct dvb_frontend_parameters *params)
762 struct tda18271_priv *priv = fe->tuner_priv;
763 struct tda18271_std_map *std_map = &priv->std;
767 u32 bw, freq = params->frequency;
769 priv->mode = TDA18271_DIGITAL;
771 if (fe->ops.info.type == FE_ATSC) {
772 switch (params->u.vsb.modulation) {
775 std = std_map->atsc_6.std_bits;
776 sgIF = std_map->atsc_6.if_freq;
780 std = std_map->qam_6.std_bits;
781 sgIF = std_map->qam_6.if_freq;
784 tda_warn("modulation not set!\n");
788 /* userspace request is already center adjusted */
789 freq += 1750000; /* Adjust to center (+1.75MHZ) */
792 } else if (fe->ops.info.type == FE_OFDM) {
793 switch (params->u.ofdm.bandwidth) {
794 case BANDWIDTH_6_MHZ:
796 std = std_map->dvbt_6.std_bits;
797 sgIF = std_map->dvbt_6.if_freq;
799 case BANDWIDTH_7_MHZ:
801 std = std_map->dvbt_7.std_bits;
802 sgIF = std_map->dvbt_7.if_freq;
804 case BANDWIDTH_8_MHZ:
806 std = std_map->dvbt_8.std_bits;
807 sgIF = std_map->dvbt_8.if_freq;
810 tda_warn("bandwidth not set!\n");
814 tda_warn("modulation type not supported!\n");
818 /* When tuning digital, the analog demod must be tri-stated */
819 if (fe->ops.analog_ops.standby)
820 fe->ops.analog_ops.standby(fe);
822 ret = tda18271_tune(fe, sgIF * 1000, freq, bw, std, 0);
827 priv->frequency = freq;
828 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ?
829 params->u.ofdm.bandwidth : 0;
834 static int tda18271_set_analog_params(struct dvb_frontend *fe,
835 struct analog_parameters *params)
837 struct tda18271_priv *priv = fe->tuner_priv;
838 struct tda18271_std_map *std_map = &priv->std;
843 u32 freq = params->frequency * 62500;
845 priv->mode = TDA18271_ANALOG;
847 if (params->mode == V4L2_TUNER_RADIO) {
850 std = std_map->fm_radio.std_bits;
851 sgIF = std_map->fm_radio.if_freq;
853 } else if (params->std & V4L2_STD_MN) {
854 std = std_map->atv_mn.std_bits;
855 sgIF = std_map->atv_mn.if_freq;
857 } else if (params->std & V4L2_STD_B) {
858 std = std_map->atv_b.std_bits;
859 sgIF = std_map->atv_b.if_freq;
861 } else if (params->std & V4L2_STD_GH) {
862 std = std_map->atv_gh.std_bits;
863 sgIF = std_map->atv_gh.if_freq;
865 } else if (params->std & V4L2_STD_PAL_I) {
866 std = std_map->atv_i.std_bits;
867 sgIF = std_map->atv_i.if_freq;
869 } else if (params->std & V4L2_STD_DK) {
870 std = std_map->atv_dk.std_bits;
871 sgIF = std_map->atv_dk.if_freq;
873 } else if (params->std & V4L2_STD_SECAM_L) {
874 std = std_map->atv_l.std_bits;
875 sgIF = std_map->atv_l.if_freq;
877 } else if (params->std & V4L2_STD_SECAM_LC) {
878 std = std_map->atv_lc.std_bits;
879 sgIF = std_map->atv_lc.if_freq;
882 std = std_map->atv_i.std_bits;
883 sgIF = std_map->atv_i.if_freq;
887 tda_dbg("setting tda18271 to system %s\n", mode);
889 ret = tda18271_tune(fe, sgIF * 1000, freq, 0, std, radio);
894 priv->frequency = freq;
900 static int tda18271_sleep(struct dvb_frontend *fe)
902 struct tda18271_priv *priv = fe->tuner_priv;
904 mutex_lock(&priv->lock);
906 /* standby mode w/ slave tuner output
907 * & loop thru & xtal oscillator on */
908 tda18271_set_standby_mode(fe, 1, 0, 0);
910 mutex_unlock(&priv->lock);
915 static int tda18271_release(struct dvb_frontend *fe)
917 struct tda18271_priv *priv = fe->tuner_priv;
919 mutex_lock(&tda18271_list_mutex);
922 hybrid_tuner_release_state(priv);
924 mutex_unlock(&tda18271_list_mutex);
926 fe->tuner_priv = NULL;
931 static int tda18271_get_frequency(struct dvb_frontend *fe, u32 *frequency)
933 struct tda18271_priv *priv = fe->tuner_priv;
934 *frequency = priv->frequency;
938 static int tda18271_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
940 struct tda18271_priv *priv = fe->tuner_priv;
941 *bandwidth = priv->bandwidth;
945 /* ------------------------------------------------------------------ */
947 #define tda18271_update_std(std_cfg, name) do { \
948 if (map->std_cfg.if_freq + map->std_cfg.std_bits > 0) { \
949 tda_dbg("Using custom std config for %s\n", name); \
950 memcpy(&std->std_cfg, &map->std_cfg, \
951 sizeof(struct tda18271_std_map_item)); \
954 #define tda18271_dump_std_item(std_cfg, name) do { \
955 tda_dbg("(%s) if freq = %d, std bits = 0x%02x\n", \
956 name, std->std_cfg.if_freq, std->std_cfg.std_bits); \
959 static int tda18271_dump_std_map(struct dvb_frontend *fe)
961 struct tda18271_priv *priv = fe->tuner_priv;
962 struct tda18271_std_map *std = &priv->std;
964 tda_dbg("========== STANDARD MAP SETTINGS ==========\n");
965 tda18271_dump_std_item(fm_radio, "fm");
966 tda18271_dump_std_item(atv_b, "pal b");
967 tda18271_dump_std_item(atv_dk, "pal dk");
968 tda18271_dump_std_item(atv_gh, "pal gh");
969 tda18271_dump_std_item(atv_i, "pal i");
970 tda18271_dump_std_item(atv_l, "pal l");
971 tda18271_dump_std_item(atv_lc, "pal l'");
972 tda18271_dump_std_item(atv_mn, "atv mn");
973 tda18271_dump_std_item(atsc_6, "atsc 6");
974 tda18271_dump_std_item(dvbt_6, "dvbt 6");
975 tda18271_dump_std_item(dvbt_7, "dvbt 7");
976 tda18271_dump_std_item(dvbt_8, "dvbt 8");
977 tda18271_dump_std_item(qam_6, "qam 6");
978 tda18271_dump_std_item(qam_8, "qam 8");
983 static int tda18271_update_std_map(struct dvb_frontend *fe,
984 struct tda18271_std_map *map)
986 struct tda18271_priv *priv = fe->tuner_priv;
987 struct tda18271_std_map *std = &priv->std;
992 tda18271_update_std(fm_radio, "fm");
993 tda18271_update_std(atv_b, "atv b");
994 tda18271_update_std(atv_dk, "atv dk");
995 tda18271_update_std(atv_gh, "atv gh");
996 tda18271_update_std(atv_i, "atv i");
997 tda18271_update_std(atv_l, "atv l");
998 tda18271_update_std(atv_lc, "atv l'");
999 tda18271_update_std(atv_mn, "atv mn");
1000 tda18271_update_std(atsc_6, "atsc 6");
1001 tda18271_update_std(dvbt_6, "dvbt 6");
1002 tda18271_update_std(dvbt_7, "dvbt 7");
1003 tda18271_update_std(dvbt_8, "dvbt 8");
1004 tda18271_update_std(qam_6, "qam 6");
1005 tda18271_update_std(qam_8, "qam 8");
1010 static int tda18271_get_id(struct dvb_frontend *fe)
1012 struct tda18271_priv *priv = fe->tuner_priv;
1013 unsigned char *regs = priv->tda18271_regs;
1017 mutex_lock(&priv->lock);
1018 tda18271_read_regs(fe);
1019 mutex_unlock(&priv->lock);
1021 switch (regs[R_ID] & 0x7f) {
1023 name = "TDA18271HD/C1";
1024 priv->id = TDA18271HDC1;
1027 name = "TDA18271HD/C2";
1028 priv->id = TDA18271HDC2;
1031 name = "Unknown device";
1036 tda_info("%s detected @ %d-%04x%s\n", name,
1037 i2c_adapter_id(priv->i2c_props.adap),
1038 priv->i2c_props.addr,
1039 (0 == ret) ? "" : ", device not supported.");
1044 static struct dvb_tuner_ops tda18271_tuner_ops = {
1046 .name = "NXP TDA18271HD",
1047 .frequency_min = 45000000,
1048 .frequency_max = 864000000,
1049 .frequency_step = 62500
1051 .init = tda18271_init,
1052 .sleep = tda18271_sleep,
1053 .set_params = tda18271_set_params,
1054 .set_analog_params = tda18271_set_analog_params,
1055 .release = tda18271_release,
1056 .get_frequency = tda18271_get_frequency,
1057 .get_bandwidth = tda18271_get_bandwidth,
1060 struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1061 struct i2c_adapter *i2c,
1062 struct tda18271_config *cfg)
1064 struct tda18271_priv *priv = NULL;
1067 mutex_lock(&tda18271_list_mutex);
1069 instance = hybrid_tuner_request_state(struct tda18271_priv, priv,
1070 hybrid_tuner_instance_list,
1071 i2c, addr, "tda18271");
1077 /* new tuner instance */
1078 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO;
1079 priv->cal_initialized = false;
1080 mutex_init(&priv->lock);
1082 fe->tuner_priv = priv;
1085 priv->small_i2c = cfg->small_i2c;
1087 if (tda18271_get_id(fe) < 0)
1090 if (tda18271_assign_map_layout(fe) < 0)
1093 mutex_lock(&priv->lock);
1094 tda18271_init_regs(fe);
1096 if ((tda18271_cal_on_startup) && (priv->id == TDA18271HDC2))
1097 tda18271c2_rf_cal_init(fe);
1099 mutex_unlock(&priv->lock);
1102 /* existing tuner instance */
1103 fe->tuner_priv = priv;
1105 /* allow dvb driver to override i2c gate setting */
1106 if ((cfg) && (cfg->gate != TDA18271_GATE_ANALOG))
1107 priv->gate = cfg->gate;
1111 /* override default std map with values in config struct */
1112 if ((cfg) && (cfg->std_map))
1113 tda18271_update_std_map(fe, cfg->std_map);
1115 mutex_unlock(&tda18271_list_mutex);
1117 memcpy(&fe->ops.tuner_ops, &tda18271_tuner_ops,
1118 sizeof(struct dvb_tuner_ops));
1120 if (tda18271_debug & DBG_MAP)
1121 tda18271_dump_std_map(fe);
1125 mutex_unlock(&tda18271_list_mutex);
1127 tda18271_release(fe);
1130 EXPORT_SYMBOL_GPL(tda18271_attach);
1131 MODULE_DESCRIPTION("NXP TDA18271HD analog / digital tuner driver");
1132 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1133 MODULE_LICENSE("GPL");
1134 MODULE_VERSION("0.2");
1137 * Overrides for Emacs so that we follow Linus's tabbing style.
1138 * ---------------------------------------------------------------------------