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 inline int charge_pump_source(struct dvb_frontend
*fe
, int force
)
41 struct tda18271_priv
*priv
= fe
->tuner_priv
;
42 return tda18271_charge_pump_source(fe
,
43 (priv
->role
== TDA18271_SLAVE
) ?
45 TDA18271_MAIN_PLL
, force
);
48 static inline void tda18271_set_if_notch(struct dvb_frontend
*fe
)
50 struct tda18271_priv
*priv
= fe
->tuner_priv
;
51 unsigned char *regs
= priv
->tda18271_regs
;
55 regs
[R_MPD
] &= ~0x80; /* IF notch = 0 */
57 case TDA18271_DIGITAL
:
58 regs
[R_MPD
] |= 0x80; /* IF notch = 1 */
63 static int tda18271_channel_configuration(struct dvb_frontend
*fe
,
64 struct tda18271_std_map_item
*map
,
67 struct tda18271_priv
*priv
= fe
->tuner_priv
;
68 unsigned char *regs
= priv
->tda18271_regs
;
72 /* update TV broadcast parameters */
75 regs
[R_EP3
] &= ~0x1f; /* clear std bits */
76 regs
[R_EP3
] |= (map
->agc_mode
<< 3) | map
->std
;
78 if (priv
->id
== TDA18271HDC2
) {
79 /* set rfagc to high speed mode */
83 /* set cal mode to normal */
86 /* update IF output level */
87 regs
[R_EP4
] &= ~0x1c; /* clear if level bits */
88 regs
[R_EP4
] |= (map
->if_lvl
<< 2);
92 regs
[R_EP4
] |= map
->fm_rfn
<< 7;
94 /* update rf top / if top */
96 regs
[R_EB22
] |= map
->rfagc_top
;
97 ret
= tda18271_write_regs(fe
, R_EB22
, 1);
101 /* --------------------------------------------------------------- */
103 /* disable Power Level Indicator */
106 /* frequency dependent parameters */
108 tda18271_calc_ir_measure(fe
, &freq
);
110 tda18271_calc_bp_filter(fe
, &freq
);
112 tda18271_calc_rf_band(fe
, &freq
);
114 tda18271_calc_gain_taper(fe
, &freq
);
116 /* --------------------------------------------------------------- */
118 /* dual tuner and agc1 extra configuration */
120 switch (priv
->role
) {
121 case TDA18271_MASTER
:
122 regs
[R_EB1
] |= 0x04; /* main vco */
125 regs
[R_EB1
] &= ~0x04; /* cal vco */
129 /* agc1 always active */
130 regs
[R_EB1
] &= ~0x02;
132 /* agc1 has priority on agc2 */
133 regs
[R_EB1
] &= ~0x01;
135 ret
= tda18271_write_regs(fe
, R_EB1
, 1);
139 /* --------------------------------------------------------------- */
141 N
= map
->if_freq
* 1000 + freq
;
143 switch (priv
->role
) {
144 case TDA18271_MASTER
:
145 tda18271_calc_main_pll(fe
, N
);
146 tda18271_set_if_notch(fe
);
147 tda18271_write_regs(fe
, R_MPD
, 4);
150 tda18271_calc_cal_pll(fe
, N
);
151 tda18271_write_regs(fe
, R_CPD
, 4);
153 regs
[R_MPD
] = regs
[R_CPD
] & 0x7f;
154 tda18271_set_if_notch(fe
);
155 tda18271_write_regs(fe
, R_MPD
, 1);
159 ret
= tda18271_write_regs(fe
, R_TM
, 7);
163 /* force charge pump source */
164 charge_pump_source(fe
, 1);
168 /* return pll to normal operation */
169 charge_pump_source(fe
, 0);
173 if (priv
->id
== TDA18271HDC2
) {
174 /* set rfagc to normal speed mode */
176 regs
[R_EP3
] &= ~0x04;
179 ret
= tda18271_write_regs(fe
, R_EP3
, 1);
185 static int tda18271_read_thermometer(struct dvb_frontend
*fe
)
187 struct tda18271_priv
*priv
= fe
->tuner_priv
;
188 unsigned char *regs
= priv
->tda18271_regs
;
191 /* switch thermometer on */
193 tda18271_write_regs(fe
, R_TM
, 1);
195 /* read thermometer info */
196 tda18271_read_regs(fe
);
198 if ((((regs
[R_TM
] & 0x0f) == 0x00) && ((regs
[R_TM
] & 0x20) == 0x20)) ||
199 (((regs
[R_TM
] & 0x0f) == 0x08) && ((regs
[R_TM
] & 0x20) == 0x00))) {
201 if ((regs
[R_TM
] & 0x20) == 0x20)
206 tda18271_write_regs(fe
, R_TM
, 1);
208 msleep(10); /* temperature sensing */
210 /* read thermometer info */
211 tda18271_read_regs(fe
);
214 tm
= tda18271_lookup_thermometer(fe
);
216 /* switch thermometer off */
218 tda18271_write_regs(fe
, R_TM
, 1);
220 /* set CAL mode to normal */
221 regs
[R_EP4
] &= ~0x03;
222 tda18271_write_regs(fe
, R_EP4
, 1);
227 /* ------------------------------------------------------------------ */
229 static int tda18271c2_rf_tracking_filters_correction(struct dvb_frontend
*fe
,
232 struct tda18271_priv
*priv
= fe
->tuner_priv
;
233 struct tda18271_rf_tracking_filter_cal
*map
= priv
->rf_cal_state
;
234 unsigned char *regs
= priv
->tda18271_regs
;
235 int tm_current
, rfcal_comp
, approx
, i
, ret
;
236 u8 dc_over_dt
, rf_tab
;
239 ret
= tda18271_set_standby_mode(fe
, 0, 0, 0);
243 /* read die current temperature */
244 tm_current
= tda18271_read_thermometer(fe
);
246 /* frequency dependent parameters */
248 tda18271_calc_rf_cal(fe
, &freq
);
249 rf_tab
= regs
[R_EB14
];
251 i
= tda18271_lookup_rf_band(fe
, &freq
, NULL
);
255 if ((0 == map
[i
].rf3
) || (freq
/ 1000 < map
[i
].rf2
)) {
256 approx
= map
[i
].rf_a1
*
257 (freq
/ 1000 - map
[i
].rf1
) + map
[i
].rf_b1
+ rf_tab
;
259 approx
= map
[i
].rf_a2
*
260 (freq
/ 1000 - map
[i
].rf2
) + map
[i
].rf_b2
+ rf_tab
;
268 tda18271_lookup_map(fe
, RF_CAL_DC_OVER_DT
, &freq
, &dc_over_dt
);
270 /* calculate temperature compensation */
271 rfcal_comp
= dc_over_dt
* (tm_current
- priv
->tm_rfcal
);
273 regs
[R_EB14
] = approx
+ rfcal_comp
;
274 ret
= tda18271_write_regs(fe
, R_EB14
, 1);
279 static int tda18271_por(struct dvb_frontend
*fe
)
281 struct tda18271_priv
*priv
= fe
->tuner_priv
;
282 unsigned char *regs
= priv
->tda18271_regs
;
285 /* power up detector 1 */
286 regs
[R_EB12
] &= ~0x20;
287 ret
= tda18271_write_regs(fe
, R_EB12
, 1);
291 regs
[R_EB18
] &= ~0x80; /* turn agc1 loop on */
292 regs
[R_EB18
] &= ~0x03; /* set agc1_gain to 6 dB */
293 ret
= tda18271_write_regs(fe
, R_EB18
, 1);
297 regs
[R_EB21
] |= 0x03; /* set agc2_gain to -6 dB */
300 ret
= tda18271_set_standby_mode(fe
, 1, 0, 0);
304 /* disable 1.5 MHz low pass filter */
305 regs
[R_EB23
] &= ~0x04; /* forcelp_fc2_en = 0 */
306 regs
[R_EB23
] &= ~0x02; /* XXX: lp_fc[2] = 0 */
307 ret
= tda18271_write_regs(fe
, R_EB21
, 3);
312 static int tda18271_calibrate_rf(struct dvb_frontend
*fe
, u32 freq
)
314 struct tda18271_priv
*priv
= fe
->tuner_priv
;
315 unsigned char *regs
= priv
->tda18271_regs
;
318 /* set CAL mode to normal */
319 regs
[R_EP4
] &= ~0x03;
320 tda18271_write_regs(fe
, R_EP4
, 1);
322 /* switch off agc1 */
323 regs
[R_EP3
] |= 0x40; /* sm_lt = 1 */
325 regs
[R_EB18
] |= 0x03; /* set agc1_gain to 15 dB */
326 tda18271_write_regs(fe
, R_EB18
, 1);
328 /* frequency dependent parameters */
330 tda18271_calc_bp_filter(fe
, &freq
);
331 tda18271_calc_gain_taper(fe
, &freq
);
332 tda18271_calc_rf_band(fe
, &freq
);
333 tda18271_calc_km(fe
, &freq
);
335 tda18271_write_regs(fe
, R_EP1
, 3);
336 tda18271_write_regs(fe
, R_EB13
, 1);
338 /* main pll charge pump source */
339 tda18271_charge_pump_source(fe
, TDA18271_MAIN_PLL
, 1);
341 /* cal pll charge pump source */
342 tda18271_charge_pump_source(fe
, TDA18271_CAL_PLL
, 1);
344 /* force dcdc converter to 0 V */
346 tda18271_write_regs(fe
, R_EB14
, 1);
348 /* disable plls lock */
349 regs
[R_EB20
] &= ~0x20;
350 tda18271_write_regs(fe
, R_EB20
, 1);
352 /* set CAL mode to RF tracking filter calibration */
354 tda18271_write_regs(fe
, R_EP4
, 2);
356 /* --------------------------------------------------------------- */
358 /* set the internal calibration signal */
361 tda18271_calc_cal_pll(fe
, N
);
362 tda18271_write_regs(fe
, R_CPD
, 4);
364 /* downconvert internal calibration */
367 tda18271_calc_main_pll(fe
, N
);
368 tda18271_write_regs(fe
, R_MPD
, 4);
372 tda18271_write_regs(fe
, R_EP2
, 1);
373 tda18271_write_regs(fe
, R_EP1
, 1);
374 tda18271_write_regs(fe
, R_EP2
, 1);
375 tda18271_write_regs(fe
, R_EP1
, 1);
377 /* --------------------------------------------------------------- */
379 /* normal operation for the main pll */
380 tda18271_charge_pump_source(fe
, TDA18271_MAIN_PLL
, 0);
382 /* normal operation for the cal pll */
383 tda18271_charge_pump_source(fe
, TDA18271_CAL_PLL
, 0);
385 msleep(10); /* plls locking */
387 /* launch the rf tracking filters calibration */
388 regs
[R_EB20
] |= 0x20;
389 tda18271_write_regs(fe
, R_EB20
, 1);
391 msleep(60); /* calibration */
393 /* --------------------------------------------------------------- */
395 /* set CAL mode to normal */
396 regs
[R_EP4
] &= ~0x03;
399 regs
[R_EP3
] &= ~0x40; /* sm_lt = 0 */
401 regs
[R_EB18
] &= ~0x03; /* set agc1_gain to 6 dB */
402 tda18271_write_regs(fe
, R_EB18
, 1);
404 tda18271_write_regs(fe
, R_EP3
, 2);
406 /* synchronization */
407 tda18271_write_regs(fe
, R_EP1
, 1);
409 /* get calibration result */
410 tda18271_read_extended(fe
);
415 static int tda18271_powerscan(struct dvb_frontend
*fe
,
416 u32
*freq_in
, u32
*freq_out
)
418 struct tda18271_priv
*priv
= fe
->tuner_priv
;
419 unsigned char *regs
= priv
->tda18271_regs
;
420 int sgn
, bcal
, count
, wait
, ret
;
427 tda18271_calc_rf_band(fe
, &freq
);
428 tda18271_calc_rf_cal(fe
, &freq
);
429 tda18271_calc_gain_taper(fe
, &freq
);
430 tda18271_lookup_cid_target(fe
, &freq
, &cid_target
, &count_limit
);
432 tda18271_write_regs(fe
, R_EP2
, 1);
433 tda18271_write_regs(fe
, R_EB14
, 1);
435 /* downconvert frequency */
438 tda18271_calc_main_pll(fe
, freq
);
439 tda18271_write_regs(fe
, R_MPD
, 4);
441 msleep(5); /* pll locking */
444 regs
[R_EP4
] &= ~0x03;
446 tda18271_write_regs(fe
, R_EP4
, 1);
448 /* launch power detection measurement */
449 tda18271_write_regs(fe
, R_EP2
, 1);
451 /* read power detection info, stored in EB10 */
452 ret
= tda18271_read_extended(fe
);
456 /* algorithm initialization */
458 *freq_out
= *freq_in
;
463 while ((regs
[R_EB10
] & 0x3f) < cid_target
) {
464 /* downconvert updated freq to 1 MHz */
465 freq
= *freq_in
+ (sgn
* count
) + 1000000;
467 tda18271_calc_main_pll(fe
, freq
);
468 tda18271_write_regs(fe
, R_MPD
, 4);
471 msleep(5); /* pll locking */
474 udelay(100); /* pll locking */
476 /* launch power detection measurement */
477 tda18271_write_regs(fe
, R_EP2
, 1);
479 /* read power detection info, stored in EB10 */
480 ret
= tda18271_read_extended(fe
);
486 if (count
<= count_limit
)
497 if ((regs
[R_EB10
] & 0x3f) >= cid_target
) {
499 *freq_out
= freq
- 1000000;
503 tda_cal("bcal = %d, freq_in = %d, freq_out = %d (freq = %d)\n",
504 bcal
, *freq_in
, *freq_out
, freq
);
509 static int tda18271_powerscan_init(struct dvb_frontend
*fe
)
511 struct tda18271_priv
*priv
= fe
->tuner_priv
;
512 unsigned char *regs
= priv
->tda18271_regs
;
515 /* set standard to digital */
516 regs
[R_EP3
] &= ~0x1f; /* clear std bits */
519 /* set cal mode to normal */
520 regs
[R_EP4
] &= ~0x03;
522 /* update IF output level */
523 regs
[R_EP4
] &= ~0x1c; /* clear if level bits */
525 ret
= tda18271_write_regs(fe
, R_EP3
, 2);
529 regs
[R_EB18
] &= ~0x03; /* set agc1_gain to 6 dB */
530 ret
= tda18271_write_regs(fe
, R_EB18
, 1);
534 regs
[R_EB21
] &= ~0x03; /* set agc2_gain to -15 dB */
536 /* 1.5 MHz low pass filter */
537 regs
[R_EB23
] |= 0x04; /* forcelp_fc2_en = 1 */
538 regs
[R_EB23
] |= 0x02; /* lp_fc[2] = 1 */
540 ret
= tda18271_write_regs(fe
, R_EB21
, 3);
545 static int tda18271_rf_tracking_filters_init(struct dvb_frontend
*fe
, u32 freq
)
547 struct tda18271_priv
*priv
= fe
->tuner_priv
;
548 struct tda18271_rf_tracking_filter_cal
*map
= priv
->rf_cal_state
;
549 unsigned char *regs
= priv
->tda18271_regs
;
559 i
= tda18271_lookup_rf_band(fe
, &freq
, NULL
);
564 rf_default
[RF1
] = 1000 * map
[i
].rf1_def
;
565 rf_default
[RF2
] = 1000 * map
[i
].rf2_def
;
566 rf_default
[RF3
] = 1000 * map
[i
].rf3_def
;
568 for (rf
= RF1
; rf
<= RF3
; rf
++) {
569 if (0 == rf_default
[rf
])
571 tda_cal("freq = %d, rf = %d\n", freq
, rf
);
573 /* look for optimized calibration frequency */
574 bcal
= tda18271_powerscan(fe
, &rf_default
[rf
], &rf_freq
[rf
]);
578 tda18271_calc_rf_cal(fe
, &rf_freq
[rf
]);
579 prog_tab
[rf
] = regs
[R_EB14
];
582 prog_cal
[rf
] = tda18271_calibrate_rf(fe
, rf_freq
[rf
]);
584 prog_cal
[rf
] = prog_tab
[rf
];
589 map
[i
].rf_b1
= prog_cal
[RF1
] - prog_tab
[RF1
];
590 map
[i
].rf1
= rf_freq
[RF1
] / 1000;
593 map
[i
].rf_a1
= (prog_cal
[RF2
] - prog_tab
[RF2
] -
594 prog_cal
[RF1
] + prog_tab
[RF1
]) /
595 ((rf_freq
[RF2
] - rf_freq
[RF1
]) / 1000);
596 map
[i
].rf2
= rf_freq
[RF2
] / 1000;
599 map
[i
].rf_a2
= (prog_cal
[RF3
] - prog_tab
[RF3
] -
600 prog_cal
[RF2
] + prog_tab
[RF2
]) /
601 ((rf_freq
[RF3
] - rf_freq
[RF2
]) / 1000);
602 map
[i
].rf_b2
= prog_cal
[RF2
] - prog_tab
[RF2
];
603 map
[i
].rf3
= rf_freq
[RF3
] / 1000;
613 static int tda18271_calc_rf_filter_curve(struct dvb_frontend
*fe
)
615 struct tda18271_priv
*priv
= fe
->tuner_priv
;
619 tda_info("tda18271: performing RF tracking filter calibration\n");
621 /* wait for die temperature stabilization */
624 ret
= tda18271_powerscan_init(fe
);
628 /* rf band calibration */
629 for (i
= 0; priv
->rf_cal_state
[i
].rfmax
!= 0; i
++) {
631 tda18271_rf_tracking_filters_init(fe
, 1000 *
632 priv
->rf_cal_state
[i
].rfmax
);
637 priv
->tm_rfcal
= tda18271_read_thermometer(fe
);
642 /* ------------------------------------------------------------------ */
644 static int tda18271c2_rf_cal_init(struct dvb_frontend
*fe
)
646 struct tda18271_priv
*priv
= fe
->tuner_priv
;
647 unsigned char *regs
= priv
->tda18271_regs
;
650 /* test RF_CAL_OK to see if we need init */
651 if ((regs
[R_EP1
] & 0x10) == 0)
652 priv
->cal_initialized
= false;
654 if (priv
->cal_initialized
)
657 ret
= tda18271_calc_rf_filter_curve(fe
);
661 ret
= tda18271_por(fe
);
665 tda_info("tda18271: RF tracking filter calibration complete\n");
667 priv
->cal_initialized
= true;
670 tda_info("tda18271: RF tracking filter calibration failed!\n");
675 static int tda18271c1_rf_tracking_filter_calibration(struct dvb_frontend
*fe
,
678 struct tda18271_priv
*priv
= fe
->tuner_priv
;
679 unsigned char *regs
= priv
->tda18271_regs
;
683 /* calculate bp filter */
684 tda18271_calc_bp_filter(fe
, &freq
);
685 tda18271_write_regs(fe
, R_EP1
, 1);
689 tda18271_write_regs(fe
, R_EB4
, 1);
692 tda18271_write_regs(fe
, R_EB7
, 1);
695 tda18271_write_regs(fe
, R_EB14
, 1);
698 tda18271_write_regs(fe
, R_EB20
, 1);
700 /* set cal mode to RF tracking filter calibration */
703 /* calculate cal pll */
705 switch (priv
->mode
) {
706 case TDA18271_ANALOG
:
709 case TDA18271_DIGITAL
:
714 tda18271_calc_cal_pll(fe
, N
);
716 /* calculate main pll */
718 switch (priv
->mode
) {
719 case TDA18271_ANALOG
:
722 case TDA18271_DIGITAL
:
723 N
= freq
+ bw
/ 2 + 1000000;
727 tda18271_calc_main_pll(fe
, N
);
729 ret
= tda18271_write_regs(fe
, R_EP3
, 11);
733 msleep(5); /* RF tracking filter calibration initialization */
735 /* search for K,M,CO for RF calibration */
736 tda18271_calc_km(fe
, &freq
);
737 tda18271_write_regs(fe
, R_EB13
, 1);
739 /* search for rf band */
740 tda18271_calc_rf_band(fe
, &freq
);
742 /* search for gain taper */
743 tda18271_calc_gain_taper(fe
, &freq
);
745 tda18271_write_regs(fe
, R_EP2
, 1);
746 tda18271_write_regs(fe
, R_EP1
, 1);
747 tda18271_write_regs(fe
, R_EP2
, 1);
748 tda18271_write_regs(fe
, R_EP1
, 1);
752 tda18271_write_regs(fe
, R_EB4
, 1);
755 tda18271_write_regs(fe
, R_EB7
, 1);
756 msleep(10); /* pll locking */
759 tda18271_write_regs(fe
, R_EB20
, 1);
760 msleep(60); /* RF tracking filter calibration completion */
762 regs
[R_EP4
] &= ~0x03; /* set cal mode to normal */
763 tda18271_write_regs(fe
, R_EP4
, 1);
765 tda18271_write_regs(fe
, R_EP1
, 1);
767 /* RF tracking filter correction for VHF_Low band */
768 if (0 == tda18271_calc_rf_cal(fe
, &freq
))
769 tda18271_write_regs(fe
, R_EB14
, 1);
774 /* ------------------------------------------------------------------ */
776 static int tda18271_ir_cal_init(struct dvb_frontend
*fe
)
778 struct tda18271_priv
*priv
= fe
->tuner_priv
;
779 unsigned char *regs
= priv
->tda18271_regs
;
782 ret
= tda18271_read_regs(fe
);
786 /* test IR_CAL_OK to see if we need init */
787 if ((regs
[R_EP1
] & 0x08) == 0)
788 ret
= tda18271_init_regs(fe
);
793 static int tda18271_init(struct dvb_frontend
*fe
)
795 struct tda18271_priv
*priv
= fe
->tuner_priv
;
798 mutex_lock(&priv
->lock
);
801 ret
= tda18271_set_standby_mode(fe
, 0, 0, 0);
806 ret
= tda18271_ir_cal_init(fe
);
810 if (priv
->id
== TDA18271HDC2
)
811 tda18271c2_rf_cal_init(fe
);
813 mutex_unlock(&priv
->lock
);
818 static int tda18271_tune(struct dvb_frontend
*fe
,
819 struct tda18271_std_map_item
*map
, u32 freq
, u32 bw
)
821 struct tda18271_priv
*priv
= fe
->tuner_priv
;
824 tda_dbg("freq = %d, ifc = %d, bw = %d, agc_mode = %d, std = %d\n",
825 freq
, map
->if_freq
, bw
, map
->agc_mode
, map
->std
);
827 ret
= tda18271_init(fe
);
831 mutex_lock(&priv
->lock
);
835 tda18271c1_rf_tracking_filter_calibration(fe
, freq
, bw
);
838 tda18271c2_rf_tracking_filters_correction(fe
, freq
);
841 ret
= tda18271_channel_configuration(fe
, map
, freq
, bw
);
843 mutex_unlock(&priv
->lock
);
848 /* ------------------------------------------------------------------ */
850 static int tda18271_set_params(struct dvb_frontend
*fe
,
851 struct dvb_frontend_parameters
*params
)
853 struct tda18271_priv
*priv
= fe
->tuner_priv
;
854 struct tda18271_std_map
*std_map
= &priv
->std
;
855 struct tda18271_std_map_item
*map
;
857 u32 bw
, freq
= params
->frequency
;
859 priv
->mode
= TDA18271_DIGITAL
;
861 if (fe
->ops
.info
.type
== FE_ATSC
) {
862 switch (params
->u
.vsb
.modulation
) {
865 map
= &std_map
->atsc_6
;
869 map
= &std_map
->qam_6
;
872 tda_warn("modulation not set!\n");
876 /* userspace request is already center adjusted */
877 freq
+= 1750000; /* Adjust to center (+1.75MHZ) */
880 } else if (fe
->ops
.info
.type
== FE_OFDM
) {
881 switch (params
->u
.ofdm
.bandwidth
) {
882 case BANDWIDTH_6_MHZ
:
884 map
= &std_map
->dvbt_6
;
886 case BANDWIDTH_7_MHZ
:
888 map
= &std_map
->dvbt_7
;
890 case BANDWIDTH_8_MHZ
:
892 map
= &std_map
->dvbt_8
;
895 tda_warn("bandwidth not set!\n");
899 tda_warn("modulation type not supported!\n");
903 /* When tuning digital, the analog demod must be tri-stated */
904 if (fe
->ops
.analog_ops
.standby
)
905 fe
->ops
.analog_ops
.standby(fe
);
907 ret
= tda18271_tune(fe
, map
, freq
, bw
);
912 priv
->frequency
= freq
;
913 priv
->bandwidth
= (fe
->ops
.info
.type
== FE_OFDM
) ?
914 params
->u
.ofdm
.bandwidth
: 0;
919 static int tda18271_set_analog_params(struct dvb_frontend
*fe
,
920 struct analog_parameters
*params
)
922 struct tda18271_priv
*priv
= fe
->tuner_priv
;
923 struct tda18271_std_map
*std_map
= &priv
->std
;
924 struct tda18271_std_map_item
*map
;
927 u32 freq
= params
->frequency
* 62500;
929 priv
->mode
= TDA18271_ANALOG
;
931 if (params
->mode
== V4L2_TUNER_RADIO
) {
933 map
= &std_map
->fm_radio
;
935 } else if (params
->std
& V4L2_STD_MN
) {
936 map
= &std_map
->atv_mn
;
938 } else if (params
->std
& V4L2_STD_B
) {
939 map
= &std_map
->atv_b
;
941 } else if (params
->std
& V4L2_STD_GH
) {
942 map
= &std_map
->atv_gh
;
944 } else if (params
->std
& V4L2_STD_PAL_I
) {
945 map
= &std_map
->atv_i
;
947 } else if (params
->std
& V4L2_STD_DK
) {
948 map
= &std_map
->atv_dk
;
950 } else if (params
->std
& V4L2_STD_SECAM_L
) {
951 map
= &std_map
->atv_l
;
953 } else if (params
->std
& V4L2_STD_SECAM_LC
) {
954 map
= &std_map
->atv_lc
;
957 map
= &std_map
->atv_i
;
961 tda_dbg("setting tda18271 to system %s\n", mode
);
963 ret
= tda18271_tune(fe
, map
, freq
, 0);
968 priv
->frequency
= freq
;
974 static int tda18271_sleep(struct dvb_frontend
*fe
)
976 struct tda18271_priv
*priv
= fe
->tuner_priv
;
979 mutex_lock(&priv
->lock
);
981 /* standby mode w/ slave tuner output
982 * & loop thru & xtal oscillator on */
983 ret
= tda18271_set_standby_mode(fe
, 1, 0, 0);
985 mutex_unlock(&priv
->lock
);
990 static int tda18271_release(struct dvb_frontend
*fe
)
992 struct tda18271_priv
*priv
= fe
->tuner_priv
;
994 mutex_lock(&tda18271_list_mutex
);
997 hybrid_tuner_release_state(priv
);
999 mutex_unlock(&tda18271_list_mutex
);
1001 fe
->tuner_priv
= NULL
;
1006 static int tda18271_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
1008 struct tda18271_priv
*priv
= fe
->tuner_priv
;
1009 *frequency
= priv
->frequency
;
1013 static int tda18271_get_bandwidth(struct dvb_frontend
*fe
, u32
*bandwidth
)
1015 struct tda18271_priv
*priv
= fe
->tuner_priv
;
1016 *bandwidth
= priv
->bandwidth
;
1020 /* ------------------------------------------------------------------ */
1022 #define tda18271_update_std(std_cfg, name) do { \
1023 if (map->std_cfg.if_freq + \
1024 map->std_cfg.agc_mode + map->std_cfg.std + \
1025 map->std_cfg.if_lvl + map->std_cfg.rfagc_top > 0) { \
1026 tda_dbg("Using custom std config for %s\n", name); \
1027 memcpy(&std->std_cfg, &map->std_cfg, \
1028 sizeof(struct tda18271_std_map_item)); \
1031 #define tda18271_dump_std_item(std_cfg, name) do { \
1032 tda_dbg("(%s) if_freq = %d, agc_mode = %d, std = %d, " \
1033 "if_lvl = %d, rfagc_top = 0x%02x\n", \
1034 name, std->std_cfg.if_freq, \
1035 std->std_cfg.agc_mode, std->std_cfg.std, \
1036 std->std_cfg.if_lvl, std->std_cfg.rfagc_top); \
1039 static int tda18271_dump_std_map(struct dvb_frontend
*fe
)
1041 struct tda18271_priv
*priv
= fe
->tuner_priv
;
1042 struct tda18271_std_map
*std
= &priv
->std
;
1044 tda_dbg("========== STANDARD MAP SETTINGS ==========\n");
1045 tda18271_dump_std_item(fm_radio
, " fm ");
1046 tda18271_dump_std_item(atv_b
, "atv b ");
1047 tda18271_dump_std_item(atv_dk
, "atv dk");
1048 tda18271_dump_std_item(atv_gh
, "atv gh");
1049 tda18271_dump_std_item(atv_i
, "atv i ");
1050 tda18271_dump_std_item(atv_l
, "atv l ");
1051 tda18271_dump_std_item(atv_lc
, "atv l'");
1052 tda18271_dump_std_item(atv_mn
, "atv mn");
1053 tda18271_dump_std_item(atsc_6
, "atsc 6");
1054 tda18271_dump_std_item(dvbt_6
, "dvbt 6");
1055 tda18271_dump_std_item(dvbt_7
, "dvbt 7");
1056 tda18271_dump_std_item(dvbt_8
, "dvbt 8");
1057 tda18271_dump_std_item(qam_6
, "qam 6 ");
1058 tda18271_dump_std_item(qam_8
, "qam 8 ");
1063 static int tda18271_update_std_map(struct dvb_frontend
*fe
,
1064 struct tda18271_std_map
*map
)
1066 struct tda18271_priv
*priv
= fe
->tuner_priv
;
1067 struct tda18271_std_map
*std
= &priv
->std
;
1072 tda18271_update_std(fm_radio
, "fm");
1073 tda18271_update_std(atv_b
, "atv b");
1074 tda18271_update_std(atv_dk
, "atv dk");
1075 tda18271_update_std(atv_gh
, "atv gh");
1076 tda18271_update_std(atv_i
, "atv i");
1077 tda18271_update_std(atv_l
, "atv l");
1078 tda18271_update_std(atv_lc
, "atv l'");
1079 tda18271_update_std(atv_mn
, "atv mn");
1080 tda18271_update_std(atsc_6
, "atsc 6");
1081 tda18271_update_std(dvbt_6
, "dvbt 6");
1082 tda18271_update_std(dvbt_7
, "dvbt 7");
1083 tda18271_update_std(dvbt_8
, "dvbt 8");
1084 tda18271_update_std(qam_6
, "qam 6");
1085 tda18271_update_std(qam_8
, "qam 8");
1090 static int tda18271_get_id(struct dvb_frontend
*fe
)
1092 struct tda18271_priv
*priv
= fe
->tuner_priv
;
1093 unsigned char *regs
= priv
->tda18271_regs
;
1097 mutex_lock(&priv
->lock
);
1098 tda18271_read_regs(fe
);
1099 mutex_unlock(&priv
->lock
);
1101 switch (regs
[R_ID
] & 0x7f) {
1103 name
= "TDA18271HD/C1";
1104 priv
->id
= TDA18271HDC1
;
1107 name
= "TDA18271HD/C2";
1108 priv
->id
= TDA18271HDC2
;
1111 name
= "Unknown device";
1116 tda_info("%s detected @ %d-%04x%s\n", name
,
1117 i2c_adapter_id(priv
->i2c_props
.adap
),
1118 priv
->i2c_props
.addr
,
1119 (0 == ret
) ? "" : ", device not supported.");
1124 static struct dvb_tuner_ops tda18271_tuner_ops
= {
1126 .name
= "NXP TDA18271HD",
1127 .frequency_min
= 45000000,
1128 .frequency_max
= 864000000,
1129 .frequency_step
= 62500
1131 .init
= tda18271_init
,
1132 .sleep
= tda18271_sleep
,
1133 .set_params
= tda18271_set_params
,
1134 .set_analog_params
= tda18271_set_analog_params
,
1135 .release
= tda18271_release
,
1136 .get_frequency
= tda18271_get_frequency
,
1137 .get_bandwidth
= tda18271_get_bandwidth
,
1140 struct dvb_frontend
*tda18271_attach(struct dvb_frontend
*fe
, u8 addr
,
1141 struct i2c_adapter
*i2c
,
1142 struct tda18271_config
*cfg
)
1144 struct tda18271_priv
*priv
= NULL
;
1147 mutex_lock(&tda18271_list_mutex
);
1149 instance
= hybrid_tuner_request_state(struct tda18271_priv
, priv
,
1150 hybrid_tuner_instance_list
,
1151 i2c
, addr
, "tda18271");
1157 /* new tuner instance */
1158 priv
->gate
= (cfg
) ? cfg
->gate
: TDA18271_GATE_AUTO
;
1159 priv
->role
= (cfg
) ? cfg
->role
: TDA18271_MASTER
;
1160 priv
->cal_initialized
= false;
1161 mutex_init(&priv
->lock
);
1163 fe
->tuner_priv
= priv
;
1166 priv
->small_i2c
= cfg
->small_i2c
;
1168 if (tda_fail(tda18271_get_id(fe
)))
1171 if (tda_fail(tda18271_assign_map_layout(fe
)))
1174 mutex_lock(&priv
->lock
);
1175 tda18271_init_regs(fe
);
1177 if ((tda18271_cal_on_startup
) && (priv
->id
== TDA18271HDC2
))
1178 tda18271c2_rf_cal_init(fe
);
1180 mutex_unlock(&priv
->lock
);
1183 /* existing tuner instance */
1184 fe
->tuner_priv
= priv
;
1186 /* allow dvb driver to override i2c gate setting */
1187 if ((cfg
) && (cfg
->gate
!= TDA18271_GATE_ANALOG
))
1188 priv
->gate
= cfg
->gate
;
1192 /* override default std map with values in config struct */
1193 if ((cfg
) && (cfg
->std_map
))
1194 tda18271_update_std_map(fe
, cfg
->std_map
);
1196 mutex_unlock(&tda18271_list_mutex
);
1198 memcpy(&fe
->ops
.tuner_ops
, &tda18271_tuner_ops
,
1199 sizeof(struct dvb_tuner_ops
));
1201 if (tda18271_debug
& (DBG_MAP
| DBG_ADV
))
1202 tda18271_dump_std_map(fe
);
1206 mutex_unlock(&tda18271_list_mutex
);
1208 tda18271_release(fe
);
1211 EXPORT_SYMBOL_GPL(tda18271_attach
);
1212 MODULE_DESCRIPTION("NXP TDA18271HD analog / digital tuner driver");
1213 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1214 MODULE_LICENSE("GPL");
1215 MODULE_VERSION("0.3");
1218 * Overrides for Emacs so that we follow Linus's tabbing style.
1219 * ---------------------------------------------------------------------------