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 (info=1, map=2, reg=4 (or-able))");
29 /*---------------------------------------------------------------------*/
31 static int tda18271_init(struct dvb_frontend *fe)
33 struct tda18271_priv *priv = fe->tuner_priv;
34 unsigned char *regs = priv->tda18271_regs;
36 tda18271_read_regs(fe);
38 /* test IR_CAL_OK to see if we need init */
39 if ((regs[R_EP1] & 0x08) == 0)
40 tda18271_init_regs(fe);
45 /* ------------------------------------------------------------------ */
47 static int tda18271_channel_configuration(struct dvb_frontend *fe,
48 u32 ifc, u32 freq, u32 bw, u8 std)
50 struct tda18271_priv *priv = fe->tuner_priv;
51 unsigned char *regs = priv->tda18271_regs;
54 /* update TV broadcast parameters */
57 regs[R_EP3] &= ~0x1f; /* clear std bits */
60 /* set cal mode to normal */
63 /* update IF output level & IF notch frequency */
64 regs[R_EP4] &= ~0x1c; /* clear if level bits */
68 regs[R_MPD] &= ~0x80; /* IF notch = 0 */
70 case TDA18271_DIGITAL:
71 regs[R_EP4] |= 0x04; /* IF level = 1 */
72 regs[R_MPD] |= 0x80; /* IF notch = 1 */
75 regs[R_EP4] &= ~0x80; /* FM_RFn: turn this bit on only for fm radio */
77 /* update RF_TOP / IF_TOP */
82 case TDA18271_DIGITAL:
86 tda18271_write_regs(fe, R_EB22, 1);
88 /* --------------------------------------------------------------- */
90 /* disable Power Level Indicator */
93 /* frequency dependent parameters */
95 tda18271_calc_ir_measure(fe, &freq);
97 tda18271_calc_bp_filter(fe, &freq);
99 tda18271_calc_rf_band(fe, &freq);
101 tda18271_calc_gain_taper(fe, &freq);
103 /* --------------------------------------------------------------- */
105 /* dual tuner and agc1 extra configuration */
107 /* main vco when Master, cal vco when slave */
108 regs[R_EB1] |= 0x04; /* FIXME: assumes master */
110 /* agc1 always active */
111 regs[R_EB1] &= ~0x02;
113 /* agc1 has priority on agc2 */
114 regs[R_EB1] &= ~0x01;
116 tda18271_write_regs(fe, R_EB1, 1);
118 /* --------------------------------------------------------------- */
122 /* FIXME: assumes master */
123 tda18271_calc_main_pll(fe, N);
124 tda18271_write_regs(fe, R_MPD, 4);
126 tda18271_write_regs(fe, R_TM, 7);
128 /* main pll charge pump source */
130 tda18271_write_regs(fe, R_EB4, 1);
134 /* normal operation for the main pll */
135 regs[R_EB4] &= ~0x20;
136 tda18271_write_regs(fe, R_EB4, 1);
143 static int tda18271_read_thermometer(struct dvb_frontend *fe)
145 struct tda18271_priv *priv = fe->tuner_priv;
146 unsigned char *regs = priv->tda18271_regs;
149 /* switch thermometer on */
151 tda18271_write_regs(fe, R_TM, 1);
153 /* read thermometer info */
154 tda18271_read_regs(fe);
156 if ((((regs[R_TM] & 0x0f) == 0x00) && ((regs[R_TM] & 0x20) == 0x20)) ||
157 (((regs[R_TM] & 0x0f) == 0x08) && ((regs[R_TM] & 0x20) == 0x00))) {
159 if ((regs[R_TM] & 0x20) == 0x20)
164 tda18271_write_regs(fe, R_TM, 1);
166 msleep(10); /* temperature sensing */
168 /* read thermometer info */
169 tda18271_read_regs(fe);
172 tm = tda18271_lookup_thermometer(fe);
174 /* switch thermometer off */
176 tda18271_write_regs(fe, R_TM, 1);
178 /* set CAL mode to normal */
179 regs[R_EP4] &= ~0x03;
180 tda18271_write_regs(fe, R_EP4, 1);
185 static int tda18271_rf_tracking_filters_correction(struct dvb_frontend *fe,
186 u32 freq, int tm_rfcal)
188 struct tda18271_priv *priv = fe->tuner_priv;
189 struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state;
190 unsigned char *regs = priv->tda18271_regs;
191 int tm_current, rfcal_comp, approx, i;
192 u8 dc_over_dt, rf_tab;
195 regs[R_EP3] &= ~0xe0; /* sm = 0, sm_lt = 0, sm_xt = 0 */
196 tda18271_write_regs(fe, R_EP3, 1);
198 /* read die current temperature */
199 tm_current = tda18271_read_thermometer(fe);
201 /* frequency dependent parameters */
203 tda18271_calc_rf_cal(fe, &freq);
204 rf_tab = regs[R_EB14];
206 i = tda18271_lookup_rf_band(fe, &freq, NULL);
210 if ((0 == map[i].rf3) || (freq / 1000 < map[i].rf2)) {
211 approx = map[i].rf_a1 *
212 (freq / 1000 - map[i].rf1) + map[i].rf_b1 + rf_tab;
214 approx = map[i].rf_a2 *
215 (freq / 1000 - map[i].rf2) + map[i].rf_b2 + rf_tab;
223 tda18271_lookup_map(fe, RF_CAL_DC_OVER_DT, &freq, &dc_over_dt);
225 /* calculate temperature compensation */
226 rfcal_comp = dc_over_dt * (tm_current - tm_rfcal);
228 regs[R_EB14] = approx + rfcal_comp;
229 tda18271_write_regs(fe, R_EB14, 1);
234 static int tda18271_por(struct dvb_frontend *fe)
236 struct tda18271_priv *priv = fe->tuner_priv;
237 unsigned char *regs = priv->tda18271_regs;
239 /* power up detector 1 */
240 regs[R_EB12] &= ~0x20;
241 tda18271_write_regs(fe, R_EB12, 1);
243 regs[R_EB18] &= ~0x80; /* turn agc1 loop on */
244 regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */
245 tda18271_write_regs(fe, R_EB18, 1);
247 regs[R_EB21] |= 0x03; /* set agc2_gain to -6 dB */
250 regs[R_EP3] &= ~0xe0; /* clear sm, sm_lt, sm_xt */
251 regs[R_EP3] |= 0x80; /* sm = 1, sm_lt = 0, sm_xt = 0 */
252 tda18271_write_regs(fe, R_EP3, 1);
254 /* disable 1.5 MHz low pass filter */
255 regs[R_EB23] &= ~0x04; /* forcelp_fc2_en = 0 */
256 regs[R_EB23] &= ~0x02; /* XXX: lp_fc[2] = 0 */
257 tda18271_write_regs(fe, R_EB21, 3);
262 static int tda18271_calibrate_rf(struct dvb_frontend *fe, u32 freq)
264 struct tda18271_priv *priv = fe->tuner_priv;
265 unsigned char *regs = priv->tda18271_regs;
268 /* set CAL mode to normal */
269 regs[R_EP4] &= ~0x03;
270 tda18271_write_regs(fe, R_EP4, 1);
272 /* switch off agc1 */
273 regs[R_EP3] |= 0x40; /* sm_lt = 1 */
275 regs[R_EB18] |= 0x03; /* set agc1_gain to 15 dB */
276 tda18271_write_regs(fe, R_EB18, 1);
278 /* frequency dependent parameters */
280 tda18271_calc_bp_filter(fe, &freq);
281 tda18271_calc_gain_taper(fe, &freq);
282 tda18271_calc_rf_band(fe, &freq);
283 tda18271_calc_km(fe, &freq);
285 tda18271_write_regs(fe, R_EP1, 3);
286 tda18271_write_regs(fe, R_EB13, 1);
288 /* main pll charge pump source */
290 tda18271_write_regs(fe, R_EB4, 1);
292 /* cal pll charge pump source */
294 tda18271_write_regs(fe, R_EB7, 1);
296 /* force dcdc converter to 0 V */
298 tda18271_write_regs(fe, R_EB14, 1);
300 /* disable plls lock */
301 regs[R_EB20] &= ~0x20;
302 tda18271_write_regs(fe, R_EB20, 1);
304 /* set CAL mode to RF tracking filter calibration */
306 tda18271_write_regs(fe, R_EP4, 2);
308 /* --------------------------------------------------------------- */
310 /* set the internal calibration signal */
313 tda18271_calc_main_pll(fe, N);
314 tda18271_write_regs(fe, R_MPD, 4);
316 /* downconvert internal calibration */
319 tda18271_calc_main_pll(fe, N);
320 tda18271_write_regs(fe, R_MPD, 4);
324 tda18271_write_regs(fe, R_EP2, 1);
325 tda18271_write_regs(fe, R_EP1, 1);
326 tda18271_write_regs(fe, R_EP2, 1);
327 tda18271_write_regs(fe, R_EP1, 1);
329 /* --------------------------------------------------------------- */
331 /* normal operation for the main pll */
332 regs[R_EB4] &= ~0x20;
333 tda18271_write_regs(fe, R_EB4, 1);
335 /* normal operation for the cal pll */
336 regs[R_EB7] &= ~0x20;
337 tda18271_write_regs(fe, R_EB7, 1);
339 msleep(5); /* plls locking */
341 /* launch the rf tracking filters calibration */
342 regs[R_EB20] |= 0x20;
343 tda18271_write_regs(fe, R_EB20, 1);
345 msleep(60); /* calibration */
347 /* --------------------------------------------------------------- */
349 /* set CAL mode to normal */
350 regs[R_EP4] &= ~0x03;
353 regs[R_EP3] &= ~0x40; /* sm_lt = 0 */
355 regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */
356 tda18271_write_regs(fe, R_EB18, 1);
358 tda18271_write_regs(fe, R_EP3, 2);
360 /* synchronization */
361 tda18271_write_regs(fe, R_EP1, 1);
363 /* get calibration result */
364 tda18271_read_extended(fe);
369 static int tda18271_powerscan(struct dvb_frontend *fe,
370 u32 *freq_in, u32 *freq_out)
372 struct tda18271_priv *priv = fe->tuner_priv;
373 unsigned char *regs = priv->tda18271_regs;
374 int sgn, bcal, count, wait;
381 tda18271_calc_rf_band(fe, &freq);
382 tda18271_calc_rf_cal(fe, &freq);
383 tda18271_calc_gain_taper(fe, &freq);
384 tda18271_lookup_cid_target(fe, &freq, &cid_target, &count_limit);
386 tda18271_write_regs(fe, R_EP2, 1);
387 tda18271_write_regs(fe, R_EB14, 1);
389 /* downconvert frequency */
392 tda18271_calc_main_pll(fe, freq);
393 tda18271_write_regs(fe, R_MPD, 4);
395 msleep(5); /* pll locking */
398 regs[R_EP4] &= ~0x03;
400 tda18271_write_regs(fe, R_EP4, 1);
402 /* launch power detection measurement */
403 tda18271_write_regs(fe, R_EP2, 1);
405 /* read power detection info, stored in EB10 */
406 tda18271_read_extended(fe);
408 /* algorithm initialization */
410 *freq_out = *freq_in;
415 while ((regs[R_EB10] & 0x3f) < cid_target) {
416 /* downconvert updated freq to 1 MHz */
417 freq = *freq_in + (sgn * count) + 1000000;
419 tda18271_calc_main_pll(fe, freq);
420 tda18271_write_regs(fe, R_MPD, 4);
423 msleep(5); /* pll locking */
426 udelay(100); /* pll locking */
428 /* launch power detection measurement */
429 tda18271_write_regs(fe, R_EP2, 1);
431 /* read power detection info, stored in EB10 */
432 tda18271_read_extended(fe);
436 if (count < count_limit)
447 if ((regs[R_EB10] & 0x3f) >= cid_target) {
449 *freq_out = freq - 1000000;
453 tda_dbg("bcal = %d, freq_in = %d, freq_out = %d (freq = %d)\n",
454 bcal, *freq_in, *freq_out, freq);
459 static int tda18271_powerscan_init(struct dvb_frontend *fe)
461 struct tda18271_priv *priv = fe->tuner_priv;
462 unsigned char *regs = priv->tda18271_regs;
464 /* set standard to digital */
465 regs[R_EP3] &= ~0x1f; /* clear std bits */
468 /* set cal mode to normal */
469 regs[R_EP4] &= ~0x03;
471 /* update IF output level & IF notch frequency */
472 regs[R_EP4] &= ~0x1c; /* clear if level bits */
474 tda18271_write_regs(fe, R_EP3, 2);
476 regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */
477 tda18271_write_regs(fe, R_EB18, 1);
479 regs[R_EB21] &= ~0x03; /* set agc2_gain to -15 dB */
481 /* 1.5 MHz low pass filter */
482 regs[R_EB23] |= 0x04; /* forcelp_fc2_en = 1 */
483 regs[R_EB23] |= 0x02; /* lp_fc[2] = 1 */
485 tda18271_write_regs(fe, R_EB21, 3);
490 static int tda18271_rf_tracking_filters_init(struct dvb_frontend *fe, u32 freq)
492 struct tda18271_priv *priv = fe->tuner_priv;
493 struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state;
494 unsigned char *regs = priv->tda18271_regs;
504 i = tda18271_lookup_rf_band(fe, &freq, NULL);
509 rf_default[RF1] = 1000 * map[i].rf1_def;
510 rf_default[RF2] = 1000 * map[i].rf2_def;
511 rf_default[RF3] = 1000 * map[i].rf3_def;
513 for (rf = RF1; rf <= RF3; rf++) {
514 if (0 == rf_default[rf])
516 tda_dbg("freq = %d, rf = %d\n", freq, rf);
518 /* look for optimized calibration frequency */
519 bcal = tda18271_powerscan(fe, &rf_default[rf], &rf_freq[rf]);
521 tda18271_calc_rf_cal(fe, &rf_freq[rf]);
522 prog_tab[rf] = regs[R_EB14];
525 prog_cal[rf] = tda18271_calibrate_rf(fe, rf_freq[rf]);
527 prog_cal[rf] = prog_tab[rf];
532 map[i].rf_b1 = prog_cal[RF1] - prog_tab[RF1];
533 map[i].rf1 = rf_freq[RF1] / 1000;
536 map[i].rf_a1 = (prog_cal[RF2] - prog_tab[RF2] -
537 prog_cal[RF1] + prog_tab[RF1]) /
538 ((rf_freq[RF2] - rf_freq[RF1]) / 1000);
539 map[i].rf2 = rf_freq[RF2] / 1000;
542 map[i].rf_a2 = (prog_cal[RF3] - prog_tab[RF3] -
543 prog_cal[RF2] + prog_tab[RF2]) /
544 ((rf_freq[RF3] - rf_freq[RF2]) / 1000);
545 map[i].rf_b2 = prog_cal[RF2] - prog_tab[RF2];
546 map[i].rf3 = rf_freq[RF3] / 1000;
556 static int tda18271_calc_rf_filter_curve(struct dvb_frontend *fe,
559 struct tda18271_priv *priv = fe->tuner_priv;
562 tda_info("tda18271: performing RF tracking filter calibration\n");
564 /* wait for die temperature stabilization */
567 tda18271_powerscan_init(fe);
569 /* rf band calibration */
570 for (i = 0; priv->rf_cal_state[i].rfmax != 0; i++)
571 tda18271_rf_tracking_filters_init(fe, 1000 *
572 priv->rf_cal_state[i].rfmax);
574 *tm_rfcal = tda18271_read_thermometer(fe);
579 /* ------------------------------------------------------------------ */
581 static int tda18271_init_cal(struct dvb_frontend *fe, int *tm)
583 struct tda18271_priv *priv = fe->tuner_priv;
585 if (priv->cal_initialized)
591 tda18271_calc_rf_filter_curve(fe, tm);
595 priv->cal_initialized = true;
600 static int tda18271c2_tune(struct dvb_frontend *fe,
601 u32 ifc, u32 freq, u32 bw, u8 std)
605 tda_dbg("freq = %d, ifc = %d\n", freq, ifc);
607 tda18271_init_cal(fe, &tm);
609 tda18271_rf_tracking_filters_correction(fe, freq, tm);
611 tda18271_channel_configuration(fe, ifc, freq, bw, std);
616 /* ------------------------------------------------------------------ */
618 static int tda18271c1_tune(struct dvb_frontend *fe,
619 u32 ifc, u32 freq, u32 bw, u8 std)
621 struct tda18271_priv *priv = fe->tuner_priv;
622 unsigned char *regs = priv->tda18271_regs;
627 tda_dbg("freq = %d, ifc = %d\n", freq, ifc);
629 /* RF tracking filter calibration */
631 /* calculate bp filter */
632 tda18271_calc_bp_filter(fe, &freq);
633 tda18271_write_regs(fe, R_EP1, 1);
637 tda18271_write_regs(fe, R_EB4, 1);
640 tda18271_write_regs(fe, R_EB7, 1);
643 tda18271_write_regs(fe, R_EB14, 1);
646 tda18271_write_regs(fe, R_EB20, 1);
648 /* set cal mode to RF tracking filter calibration */
651 /* calculate cal pll */
653 switch (priv->mode) {
654 case TDA18271_ANALOG:
657 case TDA18271_DIGITAL:
662 tda18271_calc_cal_pll(fe, N);
664 /* calculate main pll */
666 switch (priv->mode) {
667 case TDA18271_ANALOG:
670 case TDA18271_DIGITAL:
671 N = freq + bw / 2 + 1000000;
675 tda18271_calc_main_pll(fe, N);
677 tda18271_write_regs(fe, R_EP3, 11);
678 msleep(5); /* RF tracking filter calibration initialization */
680 /* search for K,M,CO for RF calibration */
681 tda18271_calc_km(fe, &freq);
682 tda18271_write_regs(fe, R_EB13, 1);
684 /* search for rf band */
685 tda18271_calc_rf_band(fe, &freq);
687 /* search for gain taper */
688 tda18271_calc_gain_taper(fe, &freq);
690 tda18271_write_regs(fe, R_EP2, 1);
691 tda18271_write_regs(fe, R_EP1, 1);
692 tda18271_write_regs(fe, R_EP2, 1);
693 tda18271_write_regs(fe, R_EP1, 1);
697 tda18271_write_regs(fe, R_EB4, 1);
700 tda18271_write_regs(fe, R_EB7, 1);
704 tda18271_write_regs(fe, R_EB20, 1);
705 msleep(60); /* RF tracking filter calibration completion */
707 regs[R_EP4] &= ~0x03; /* set cal mode to normal */
708 tda18271_write_regs(fe, R_EP4, 1);
710 tda18271_write_regs(fe, R_EP1, 1);
712 /* RF tracking filter correction for VHF_Low band */
713 if (0 == tda18271_calc_rf_cal(fe, &freq))
714 tda18271_write_regs(fe, R_EB14, 1);
716 /* Channel Configuration */
718 switch (priv->mode) {
719 case TDA18271_ANALOG:
722 case TDA18271_DIGITAL:
726 tda18271_write_regs(fe, R_EB22, 1);
728 regs[R_EP1] |= 0x40; /* set dis power level on */
731 regs[R_EP3] &= ~0x1f; /* clear std bits */
736 regs[R_EP4] &= ~0x03; /* set cal mode to normal */
738 regs[R_EP4] &= ~0x1c; /* clear if level bits */
739 switch (priv->mode) {
740 case TDA18271_ANALOG:
741 regs[R_MPD] &= ~0x80; /* IF notch = 0 */
743 case TDA18271_DIGITAL:
749 regs[R_EP4] &= ~0x80; /* turn this bit on only for fm */
751 /* image rejection validity */
752 tda18271_calc_ir_measure(fe, &freq);
754 /* calculate MAIN PLL */
757 tda18271_calc_main_pll(fe, N);
759 tda18271_write_regs(fe, R_TM, 15);
765 /* ------------------------------------------------------------------ */
767 static int tda18271_set_params(struct dvb_frontend *fe,
768 struct dvb_frontend_parameters *params)
770 struct tda18271_priv *priv = fe->tuner_priv;
771 struct tda18271_std_map *std_map = &priv->std;
774 u32 bw, freq = params->frequency;
778 priv->mode = TDA18271_DIGITAL;
781 if (fe->ops.info.type == FE_ATSC) {
782 switch (params->u.vsb.modulation) {
785 std = std_map->atsc_6.std_bits;
786 sgIF = std_map->atsc_6.if_freq;
790 std = std_map->qam_6.std_bits;
791 sgIF = std_map->qam_6.if_freq;
794 tda_warn("modulation not set!\n");
798 /* userspace request is already center adjusted */
799 freq += 1750000; /* Adjust to center (+1.75MHZ) */
802 } else if (fe->ops.info.type == FE_OFDM) {
803 switch (params->u.ofdm.bandwidth) {
804 case BANDWIDTH_6_MHZ:
806 std = std_map->dvbt_6.std_bits;
807 sgIF = std_map->dvbt_6.if_freq;
809 case BANDWIDTH_7_MHZ:
811 std = std_map->dvbt_7.std_bits;
812 sgIF = std_map->dvbt_7.if_freq;
814 case BANDWIDTH_8_MHZ:
816 std = std_map->dvbt_8.std_bits;
817 sgIF = std_map->dvbt_8.if_freq;
820 tda_warn("bandwidth not set!\n");
824 tda_warn("modulation type not supported!\n");
828 return priv->tune(fe, sgIF * 1000, freq, bw, std);
831 static int tda18271_set_analog_params(struct dvb_frontend *fe,
832 struct analog_parameters *params)
834 struct tda18271_priv *priv = fe->tuner_priv;
835 struct tda18271_std_map *std_map = &priv->std;
839 u32 freq = params->frequency * 62500;
843 priv->mode = TDA18271_ANALOG;
845 if (params->std & V4L2_STD_MN) {
846 std = std_map->atv_mn.std_bits;
847 sgIF = std_map->atv_mn.if_freq;
849 } else if (params->std & V4L2_STD_B) {
850 std = std_map->atv_b.std_bits;
851 sgIF = std_map->atv_b.if_freq;
853 } else if (params->std & V4L2_STD_GH) {
854 std = std_map->atv_gh.std_bits;
855 sgIF = std_map->atv_gh.if_freq;
857 } else if (params->std & V4L2_STD_PAL_I) {
858 std = std_map->atv_i.std_bits;
859 sgIF = std_map->atv_i.if_freq;
861 } else if (params->std & V4L2_STD_DK) {
862 std = std_map->atv_dk.std_bits;
863 sgIF = std_map->atv_dk.if_freq;
865 } else if (params->std & V4L2_STD_SECAM_L) {
866 std = std_map->atv_l.std_bits;
867 sgIF = std_map->atv_l.if_freq;
869 } else if (params->std & V4L2_STD_SECAM_LC) {
870 std = std_map->atv_lc.std_bits;
871 sgIF = std_map->atv_lc.if_freq;
874 std = std_map->atv_i.std_bits;
875 sgIF = std_map->atv_i.if_freq;
879 tda_dbg("setting tda18271 to system %s\n", mode);
881 return priv->tune(fe, sgIF * 1000, freq, 0, std);
884 static int tda18271_release(struct dvb_frontend *fe)
886 kfree(fe->tuner_priv);
887 fe->tuner_priv = NULL;
891 static int tda18271_get_frequency(struct dvb_frontend *fe, u32 *frequency)
893 struct tda18271_priv *priv = fe->tuner_priv;
894 *frequency = priv->frequency;
898 static int tda18271_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
900 struct tda18271_priv *priv = fe->tuner_priv;
901 *bandwidth = priv->bandwidth;
905 /* ------------------------------------------------------------------ */
907 #define tda18271_update_std(std_cfg, name) do { \
908 if (map->std_cfg.if_freq + map->std_cfg.std_bits > 0) { \
909 tda_dbg("Using custom std config for %s\n", name); \
910 memcpy(&std->std_cfg, &map->std_cfg, \
911 sizeof(struct tda18271_std_map_item)); \
914 #define tda18271_dump_std_item(std_cfg, name) do { \
915 tda_dbg("(%s) if freq = %d, std bits = 0x%02x\n", \
916 name, std->std_cfg.if_freq, std->std_cfg.std_bits); \
919 static int tda18271_dump_std_map(struct dvb_frontend *fe)
921 struct tda18271_priv *priv = fe->tuner_priv;
922 struct tda18271_std_map *std = &priv->std;
924 tda_dbg("========== STANDARD MAP SETTINGS ==========\n");
925 tda18271_dump_std_item(atv_b, "pal b");
926 tda18271_dump_std_item(atv_dk, "pal dk");
927 tda18271_dump_std_item(atv_gh, "pal gh");
928 tda18271_dump_std_item(atv_i, "pal i");
929 tda18271_dump_std_item(atv_l, "pal l");
930 tda18271_dump_std_item(atv_lc, "pal l'");
931 tda18271_dump_std_item(atv_mn, "atv mn");
932 tda18271_dump_std_item(atsc_6, "atsc 6");
933 tda18271_dump_std_item(dvbt_6, "dvbt 6");
934 tda18271_dump_std_item(dvbt_7, "dvbt 7");
935 tda18271_dump_std_item(dvbt_8, "dvbt 8");
936 tda18271_dump_std_item(qam_6, "qam 6");
937 tda18271_dump_std_item(qam_8, "qam 8");
942 static int tda18271_update_std_map(struct dvb_frontend *fe,
943 struct tda18271_std_map *map)
945 struct tda18271_priv *priv = fe->tuner_priv;
946 struct tda18271_std_map *std = &priv->std;
951 tda18271_update_std(atv_b, "atv b");
952 tda18271_update_std(atv_dk, "atv dk");
953 tda18271_update_std(atv_gh, "atv gh");
954 tda18271_update_std(atv_i, "atv i");
955 tda18271_update_std(atv_l, "atv l");
956 tda18271_update_std(atv_lc, "atv l'");
957 tda18271_update_std(atv_mn, "atv mn");
958 tda18271_update_std(atsc_6, "atsc 6");
959 tda18271_update_std(dvbt_6, "dvbt 6");
960 tda18271_update_std(dvbt_7, "dvbt 7");
961 tda18271_update_std(dvbt_8, "dvbt 8");
962 tda18271_update_std(qam_6, "qam 6");
963 tda18271_update_std(qam_8, "qam 8");
968 static int tda18271_get_id(struct dvb_frontend *fe)
970 struct tda18271_priv *priv = fe->tuner_priv;
971 unsigned char *regs = priv->tda18271_regs;
975 tda18271_read_regs(fe);
977 switch (regs[R_ID] & 0x7f) {
979 name = "TDA18271HD/C1";
980 priv->id = TDA18271HDC1;
981 priv->tune = tda18271c1_tune;
984 name = "TDA18271HD/C2";
985 priv->id = TDA18271HDC2;
986 priv->tune = tda18271c2_tune;
989 name = "Unknown device";
994 tda_info("%s detected @ %d-%04x%s\n", name,
995 i2c_adapter_id(priv->i2c_adap), priv->i2c_addr,
996 (0 == ret) ? "" : ", device not supported.");
1001 static struct dvb_tuner_ops tda18271_tuner_ops = {
1003 .name = "NXP TDA18271HD",
1004 .frequency_min = 45000000,
1005 .frequency_max = 864000000,
1006 .frequency_step = 62500
1008 .init = tda18271_init,
1009 .set_params = tda18271_set_params,
1010 .set_analog_params = tda18271_set_analog_params,
1011 .release = tda18271_release,
1012 .get_frequency = tda18271_get_frequency,
1013 .get_bandwidth = tda18271_get_bandwidth,
1016 struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1017 struct i2c_adapter *i2c,
1018 struct tda18271_config *cfg)
1020 struct tda18271_priv *priv = NULL;
1022 priv = kzalloc(sizeof(struct tda18271_priv), GFP_KERNEL);
1026 priv->i2c_addr = addr;
1027 priv->i2c_adap = i2c;
1028 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO;
1029 priv->cal_initialized = false;
1031 fe->tuner_priv = priv;
1033 if (tda18271_get_id(fe) < 0)
1036 if (tda18271_assign_map_layout(fe) < 0)
1039 memcpy(&fe->ops.tuner_ops, &tda18271_tuner_ops,
1040 sizeof(struct dvb_tuner_ops));
1042 /* override default std map with values in config struct */
1043 if ((cfg) && (cfg->std_map))
1044 tda18271_update_std_map(fe, cfg->std_map);
1046 if (tda18271_debug & DBG_MAP)
1047 tda18271_dump_std_map(fe);
1049 tda18271_init_regs(fe);
1053 tda18271_release(fe);
1056 EXPORT_SYMBOL_GPL(tda18271_attach);
1057 MODULE_DESCRIPTION("NXP TDA18271HD analog / digital tuner driver");
1058 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1059 MODULE_LICENSE("GPL");
1060 MODULE_VERSION("0.2");
1063 * Overrides for Emacs so that we follow Linus's tabbing style.
1064 * ---------------------------------------------------------------------------