V4L/DVB (8036): tda18271: toggle rf agc speed mode on TDA18271HD/C2 only
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / media / common / tuners / tda18271-fe.c
CommitLineData
5bea1cd3 1/*
6ca04de3 2 tda18271-fe.c - driver for the Philips / NXP TDA18271 silicon tuner
5bea1cd3 3
59067f7e 4 Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
5bea1cd3
MK
5
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.
10
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.
15
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.
19*/
20
5bea1cd3
MK
21#include <linux/delay.h>
22#include <linux/videodev2.h>
6ca04de3 23#include "tda18271-priv.h"
5bea1cd3 24
b5f3e1e1 25int tda18271_debug;
54465b08 26module_param_named(debug, tda18271_debug, int, 0644);
0e1fab90 27MODULE_PARM_DESC(debug, "set debug level "
cf04d29c 28 "(info=1, map=2, reg=4, adv=8, cal=16 (or-able))");
5bea1cd3 29
bc835d80 30static int tda18271_cal_on_startup;
0f96251e
MK
31module_param_named(cal, tda18271_cal_on_startup, int, 0644);
32MODULE_PARM_DESC(cal, "perform RF tracking filter calibration on startup");
33
a4f263b5 34static DEFINE_MUTEX(tda18271_list_mutex);
f9e315a1 35static LIST_HEAD(hybrid_tuner_instance_list);
a4f263b5 36
5bea1cd3
MK
37/*---------------------------------------------------------------------*/
38
868f5ccd
MK
39static inline int charge_pump_source(struct dvb_frontend *fe, int force)
40{
41 struct tda18271_priv *priv = fe->tuner_priv;
42 return tda18271_charge_pump_source(fe,
43 (priv->role == TDA18271_SLAVE) ?
44 TDA18271_CAL_PLL :
45 TDA18271_MAIN_PLL, force);
46}
47
44e645c2
MK
48static inline void tda18271_set_if_notch(struct dvb_frontend *fe)
49{
50 struct tda18271_priv *priv = fe->tuner_priv;
51 unsigned char *regs = priv->tda18271_regs;
52
53 switch (priv->mode) {
54 case TDA18271_ANALOG:
55 regs[R_MPD] &= ~0x80; /* IF notch = 0 */
56 break;
57 case TDA18271_DIGITAL:
58 regs[R_MPD] |= 0x80; /* IF notch = 1 */
59 break;
60 }
61}
62
255b5113 63static int tda18271_channel_configuration(struct dvb_frontend *fe,
c293d0a7
MK
64 struct tda18271_std_map_item *map,
65 u32 freq, u32 bw)
255b5113
MK
66{
67 struct tda18271_priv *priv = fe->tuner_priv;
68 unsigned char *regs = priv->tda18271_regs;
31940e39 69 int ret;
255b5113
MK
70 u32 N;
71
72 /* update TV broadcast parameters */
73
74 /* set standard */
75 regs[R_EP3] &= ~0x1f; /* clear std bits */
7f7203df 76 regs[R_EP3] |= (map->agc_mode << 3) | map->std;
255b5113 77
51858d13
MK
78 if (priv->id == TDA18271HDC2) {
79 /* set rfagc to high speed mode */
80 regs[R_EP3] &= ~0x04;
81 }
40194b2b 82
255b5113
MK
83 /* set cal mode to normal */
84 regs[R_EP4] &= ~0x03;
85
44e645c2 86 /* update IF output level */
255b5113 87 regs[R_EP4] &= ~0x1c; /* clear if level bits */
14c74b23 88 regs[R_EP4] |= (map->if_lvl << 2);
255b5113 89
c293d0a7
MK
90 /* update FM_RFn */
91 regs[R_EP4] &= ~0x80;
92 regs[R_EP4] |= map->fm_rfn << 7;
255b5113 93
c0dc0c11
MK
94 /* update rf top / if top */
95 regs[R_EB22] = 0x00;
96 regs[R_EB22] |= map->rfagc_top;
31940e39 97 ret = tda18271_write_regs(fe, R_EB22, 1);
4bd5d107 98 if (tda_fail(ret))
31940e39 99 goto fail;
255b5113
MK
100
101 /* --------------------------------------------------------------- */
102
103 /* disable Power Level Indicator */
104 regs[R_EP1] |= 0x40;
105
106 /* frequency dependent parameters */
107
108 tda18271_calc_ir_measure(fe, &freq);
109
110 tda18271_calc_bp_filter(fe, &freq);
111
112 tda18271_calc_rf_band(fe, &freq);
113
114 tda18271_calc_gain_taper(fe, &freq);
115
116 /* --------------------------------------------------------------- */
117
118 /* dual tuner and agc1 extra configuration */
119
868f5ccd
MK
120 switch (priv->role) {
121 case TDA18271_MASTER:
122 regs[R_EB1] |= 0x04; /* main vco */
123 break;
124 case TDA18271_SLAVE:
125 regs[R_EB1] &= ~0x04; /* cal vco */
126 break;
127 }
255b5113
MK
128
129 /* agc1 always active */
130 regs[R_EB1] &= ~0x02;
131
132 /* agc1 has priority on agc2 */
133 regs[R_EB1] &= ~0x01;
134
31940e39 135 ret = tda18271_write_regs(fe, R_EB1, 1);
4bd5d107 136 if (tda_fail(ret))
31940e39 137 goto fail;
255b5113
MK
138
139 /* --------------------------------------------------------------- */
140
c293d0a7 141 N = map->if_freq * 1000 + freq;
255b5113 142
868f5ccd
MK
143 switch (priv->role) {
144 case TDA18271_MASTER:
145 tda18271_calc_main_pll(fe, N);
44e645c2 146 tda18271_set_if_notch(fe);
868f5ccd
MK
147 tda18271_write_regs(fe, R_MPD, 4);
148 break;
149 case TDA18271_SLAVE:
150 tda18271_calc_cal_pll(fe, N);
151 tda18271_write_regs(fe, R_CPD, 4);
152
153 regs[R_MPD] = regs[R_CPD] & 0x7f;
44e645c2 154 tda18271_set_if_notch(fe);
868f5ccd
MK
155 tda18271_write_regs(fe, R_MPD, 1);
156 break;
157 }
255b5113 158
31940e39 159 ret = tda18271_write_regs(fe, R_TM, 7);
4bd5d107 160 if (tda_fail(ret))
31940e39 161 goto fail;
255b5113 162
868f5ccd
MK
163 /* force charge pump source */
164 charge_pump_source(fe, 1);
255b5113
MK
165
166 msleep(1);
167
868f5ccd
MK
168 /* return pll to normal operation */
169 charge_pump_source(fe, 0);
255b5113 170
40194b2b
MK
171 msleep(20);
172
51858d13
MK
173 if (priv->id == TDA18271HDC2) {
174 /* set rfagc to normal speed mode */
175 if (map->fm_rfn)
176 regs[R_EP3] &= ~0x04;
177 else
178 regs[R_EP3] |= 0x04;
179 ret = tda18271_write_regs(fe, R_EP3, 1);
180 }
31940e39
MK
181fail:
182 return ret;
255b5113
MK
183}
184
185static int tda18271_read_thermometer(struct dvb_frontend *fe)
186{
187 struct tda18271_priv *priv = fe->tuner_priv;
188 unsigned char *regs = priv->tda18271_regs;
189 int tm;
190
191 /* switch thermometer on */
192 regs[R_TM] |= 0x10;
193 tda18271_write_regs(fe, R_TM, 1);
194
195 /* read thermometer info */
196 tda18271_read_regs(fe);
197
198 if ((((regs[R_TM] & 0x0f) == 0x00) && ((regs[R_TM] & 0x20) == 0x20)) ||
199 (((regs[R_TM] & 0x0f) == 0x08) && ((regs[R_TM] & 0x20) == 0x00))) {
200
201 if ((regs[R_TM] & 0x20) == 0x20)
202 regs[R_TM] &= ~0x20;
203 else
204 regs[R_TM] |= 0x20;
205
206 tda18271_write_regs(fe, R_TM, 1);
207
208 msleep(10); /* temperature sensing */
209
210 /* read thermometer info */
211 tda18271_read_regs(fe);
212 }
213
214 tm = tda18271_lookup_thermometer(fe);
215
216 /* switch thermometer off */
217 regs[R_TM] &= ~0x10;
218 tda18271_write_regs(fe, R_TM, 1);
219
220 /* set CAL mode to normal */
221 regs[R_EP4] &= ~0x03;
222 tda18271_write_regs(fe, R_EP4, 1);
223
224 return tm;
225}
226
12afe378
MK
227/* ------------------------------------------------------------------ */
228
d1c53424
MK
229static int tda18271c2_rf_tracking_filters_correction(struct dvb_frontend *fe,
230 u32 freq)
255b5113
MK
231{
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;
20f42063 235 int tm_current, rfcal_comp, approx, i, ret;
255b5113
MK
236 u8 dc_over_dt, rf_tab;
237
238 /* power up */
20f42063 239 ret = tda18271_set_standby_mode(fe, 0, 0, 0);
4bd5d107 240 if (tda_fail(ret))
20f42063 241 goto fail;
255b5113
MK
242
243 /* read die current temperature */
244 tm_current = tda18271_read_thermometer(fe);
245
246 /* frequency dependent parameters */
247
248 tda18271_calc_rf_cal(fe, &freq);
249 rf_tab = regs[R_EB14];
250
251 i = tda18271_lookup_rf_band(fe, &freq, NULL);
4bd5d107
MK
252 if (tda_fail(i))
253 return i;
255b5113
MK
254
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;
258 } else {
259 approx = map[i].rf_a2 *
260 (freq / 1000 - map[i].rf2) + map[i].rf_b2 + rf_tab;
261 }
262
263 if (approx < 0)
264 approx = 0;
265 if (approx > 255)
266 approx = 255;
267
268 tda18271_lookup_map(fe, RF_CAL_DC_OVER_DT, &freq, &dc_over_dt);
269
270 /* calculate temperature compensation */
09f83c4f 271 rfcal_comp = dc_over_dt * (tm_current - priv->tm_rfcal);
255b5113
MK
272
273 regs[R_EB14] = approx + rfcal_comp;
20f42063
MK
274 ret = tda18271_write_regs(fe, R_EB14, 1);
275fail:
276 return ret;
255b5113
MK
277}
278
279static int tda18271_por(struct dvb_frontend *fe)
280{
281 struct tda18271_priv *priv = fe->tuner_priv;
282 unsigned char *regs = priv->tda18271_regs;
24124f78 283 int ret;
255b5113
MK
284
285 /* power up detector 1 */
286 regs[R_EB12] &= ~0x20;
24124f78 287 ret = tda18271_write_regs(fe, R_EB12, 1);
4bd5d107 288 if (tda_fail(ret))
24124f78 289 goto fail;
255b5113
MK
290
291 regs[R_EB18] &= ~0x80; /* turn agc1 loop on */
292 regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */
24124f78 293 ret = tda18271_write_regs(fe, R_EB18, 1);
4bd5d107 294 if (tda_fail(ret))
24124f78 295 goto fail;
255b5113
MK
296
297 regs[R_EB21] |= 0x03; /* set agc2_gain to -6 dB */
298
299 /* POR mode */
24124f78 300 ret = tda18271_set_standby_mode(fe, 1, 0, 0);
4bd5d107 301 if (tda_fail(ret))
24124f78 302 goto fail;
255b5113
MK
303
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 */
24124f78
MK
307 ret = tda18271_write_regs(fe, R_EB21, 3);
308fail:
309 return ret;
255b5113
MK
310}
311
312static int tda18271_calibrate_rf(struct dvb_frontend *fe, u32 freq)
313{
314 struct tda18271_priv *priv = fe->tuner_priv;
315 unsigned char *regs = priv->tda18271_regs;
316 u32 N;
317
318 /* set CAL mode to normal */
319 regs[R_EP4] &= ~0x03;
320 tda18271_write_regs(fe, R_EP4, 1);
321
322 /* switch off agc1 */
323 regs[R_EP3] |= 0x40; /* sm_lt = 1 */
324
325 regs[R_EB18] |= 0x03; /* set agc1_gain to 15 dB */
326 tda18271_write_regs(fe, R_EB18, 1);
327
328 /* frequency dependent parameters */
329
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);
334
335 tda18271_write_regs(fe, R_EP1, 3);
336 tda18271_write_regs(fe, R_EB13, 1);
337
338 /* main pll charge pump source */
4efb0ca5 339 tda18271_charge_pump_source(fe, TDA18271_MAIN_PLL, 1);
255b5113
MK
340
341 /* cal pll charge pump source */
4efb0ca5 342 tda18271_charge_pump_source(fe, TDA18271_CAL_PLL, 1);
255b5113
MK
343
344 /* force dcdc converter to 0 V */
345 regs[R_EB14] = 0x00;
346 tda18271_write_regs(fe, R_EB14, 1);
347
348 /* disable plls lock */
349 regs[R_EB20] &= ~0x20;
350 tda18271_write_regs(fe, R_EB20, 1);
351
352 /* set CAL mode to RF tracking filter calibration */
353 regs[R_EP4] |= 0x03;
354 tda18271_write_regs(fe, R_EP4, 2);
355
356 /* --------------------------------------------------------------- */
357
358 /* set the internal calibration signal */
359 N = freq;
360
ae07d042
MK
361 tda18271_calc_cal_pll(fe, N);
362 tda18271_write_regs(fe, R_CPD, 4);
255b5113
MK
363
364 /* downconvert internal calibration */
365 N += 1000000;
366
367 tda18271_calc_main_pll(fe, N);
368 tda18271_write_regs(fe, R_MPD, 4);
369
370 msleep(5);
371
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);
376
377 /* --------------------------------------------------------------- */
378
379 /* normal operation for the main pll */
4efb0ca5 380 tda18271_charge_pump_source(fe, TDA18271_MAIN_PLL, 0);
255b5113
MK
381
382 /* normal operation for the cal pll */
4efb0ca5 383 tda18271_charge_pump_source(fe, TDA18271_CAL_PLL, 0);
255b5113 384
ae07d042 385 msleep(10); /* plls locking */
255b5113
MK
386
387 /* launch the rf tracking filters calibration */
388 regs[R_EB20] |= 0x20;
389 tda18271_write_regs(fe, R_EB20, 1);
390
391 msleep(60); /* calibration */
392
393 /* --------------------------------------------------------------- */
394
395 /* set CAL mode to normal */
396 regs[R_EP4] &= ~0x03;
397
398 /* switch on agc1 */
399 regs[R_EP3] &= ~0x40; /* sm_lt = 0 */
400
401 regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */
402 tda18271_write_regs(fe, R_EB18, 1);
403
404 tda18271_write_regs(fe, R_EP3, 2);
405
406 /* synchronization */
407 tda18271_write_regs(fe, R_EP1, 1);
408
409 /* get calibration result */
410 tda18271_read_extended(fe);
411
412 return regs[R_EB14];
413}
414
415static int tda18271_powerscan(struct dvb_frontend *fe,
416 u32 *freq_in, u32 *freq_out)
417{
418 struct tda18271_priv *priv = fe->tuner_priv;
419 unsigned char *regs = priv->tda18271_regs;
24124f78 420 int sgn, bcal, count, wait, ret;
255b5113
MK
421 u8 cid_target;
422 u16 count_limit;
423 u32 freq;
424
425 freq = *freq_in;
426
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);
431
432 tda18271_write_regs(fe, R_EP2, 1);
433 tda18271_write_regs(fe, R_EB14, 1);
434
435 /* downconvert frequency */
436 freq += 1000000;
437
438 tda18271_calc_main_pll(fe, freq);
439 tda18271_write_regs(fe, R_MPD, 4);
440
441 msleep(5); /* pll locking */
442
443 /* detection mode */
444 regs[R_EP4] &= ~0x03;
445 regs[R_EP4] |= 0x01;
446 tda18271_write_regs(fe, R_EP4, 1);
447
448 /* launch power detection measurement */
449 tda18271_write_regs(fe, R_EP2, 1);
450
451 /* read power detection info, stored in EB10 */
24124f78 452 ret = tda18271_read_extended(fe);
4bd5d107 453 if (tda_fail(ret))
24124f78 454 return ret;
255b5113
MK
455
456 /* algorithm initialization */
457 sgn = 1;
458 *freq_out = *freq_in;
459 bcal = 0;
460 count = 0;
461 wait = false;
462
463 while ((regs[R_EB10] & 0x3f) < cid_target) {
464 /* downconvert updated freq to 1 MHz */
465 freq = *freq_in + (sgn * count) + 1000000;
466
467 tda18271_calc_main_pll(fe, freq);
468 tda18271_write_regs(fe, R_MPD, 4);
469
470 if (wait) {
471 msleep(5); /* pll locking */
472 wait = false;
473 } else
474 udelay(100); /* pll locking */
475
476 /* launch power detection measurement */
477 tda18271_write_regs(fe, R_EP2, 1);
478
479 /* read power detection info, stored in EB10 */
24124f78 480 ret = tda18271_read_extended(fe);
4bd5d107 481 if (tda_fail(ret))
24124f78 482 return ret;
255b5113
MK
483
484 count += 200;
485
e7809a07 486 if (count <= count_limit)
255b5113
MK
487 continue;
488
489 if (sgn <= 0)
490 break;
491
492 sgn = -1 * sgn;
493 count = 200;
494 wait = true;
495 }
496
497 if ((regs[R_EB10] & 0x3f) >= cid_target) {
498 bcal = 1;
499 *freq_out = freq - 1000000;
500 } else
501 bcal = 0;
502
cf04d29c 503 tda_cal("bcal = %d, freq_in = %d, freq_out = %d (freq = %d)\n",
255b5113
MK
504 bcal, *freq_in, *freq_out, freq);
505
506 return bcal;
507}
508
509static int tda18271_powerscan_init(struct dvb_frontend *fe)
510{
511 struct tda18271_priv *priv = fe->tuner_priv;
512 unsigned char *regs = priv->tda18271_regs;
24124f78 513 int ret;
255b5113
MK
514
515 /* set standard to digital */
516 regs[R_EP3] &= ~0x1f; /* clear std bits */
517 regs[R_EP3] |= 0x12;
518
519 /* set cal mode to normal */
520 regs[R_EP4] &= ~0x03;
521
44e645c2 522 /* update IF output level */
255b5113
MK
523 regs[R_EP4] &= ~0x1c; /* clear if level bits */
524
24124f78 525 ret = tda18271_write_regs(fe, R_EP3, 2);
4bd5d107 526 if (tda_fail(ret))
24124f78 527 goto fail;
255b5113
MK
528
529 regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */
24124f78 530 ret = tda18271_write_regs(fe, R_EB18, 1);
4bd5d107 531 if (tda_fail(ret))
24124f78 532 goto fail;
255b5113
MK
533
534 regs[R_EB21] &= ~0x03; /* set agc2_gain to -15 dB */
535
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 */
539
24124f78
MK
540 ret = tda18271_write_regs(fe, R_EB21, 3);
541fail:
542 return ret;
255b5113
MK
543}
544
545static int tda18271_rf_tracking_filters_init(struct dvb_frontend *fe, u32 freq)
546{
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;
550 int bcal, rf, i;
551#define RF1 0
552#define RF2 1
553#define RF3 2
554 u32 rf_default[3];
555 u32 rf_freq[3];
556 u8 prog_cal[3];
557 u8 prog_tab[3];
558
559 i = tda18271_lookup_rf_band(fe, &freq, NULL);
560
4bd5d107 561 if (tda_fail(i))
255b5113
MK
562 return i;
563
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;
567
568 for (rf = RF1; rf <= RF3; rf++) {
569 if (0 == rf_default[rf])
570 return 0;
cf04d29c 571 tda_cal("freq = %d, rf = %d\n", freq, rf);
255b5113
MK
572
573 /* look for optimized calibration frequency */
574 bcal = tda18271_powerscan(fe, &rf_default[rf], &rf_freq[rf]);
4bd5d107 575 if (tda_fail(bcal))
24124f78 576 return bcal;
255b5113
MK
577
578 tda18271_calc_rf_cal(fe, &rf_freq[rf]);
579 prog_tab[rf] = regs[R_EB14];
580
581 if (1 == bcal)
582 prog_cal[rf] = tda18271_calibrate_rf(fe, rf_freq[rf]);
583 else
584 prog_cal[rf] = prog_tab[rf];
585
586 switch (rf) {
587 case RF1:
588 map[i].rf_a1 = 0;
589 map[i].rf_b1 = prog_cal[RF1] - prog_tab[RF1];
590 map[i].rf1 = rf_freq[RF1] / 1000;
591 break;
592 case RF2:
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;
597 break;
598 case RF3:
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;
604 break;
605 default:
606 BUG();
607 }
608 }
609
610 return 0;
611}
612
09f83c4f 613static int tda18271_calc_rf_filter_curve(struct dvb_frontend *fe)
255b5113
MK
614{
615 struct tda18271_priv *priv = fe->tuner_priv;
616 unsigned int i;
24124f78 617 int ret;
255b5113
MK
618
619 tda_info("tda18271: performing RF tracking filter calibration\n");
620
621 /* wait for die temperature stabilization */
622 msleep(200);
623
24124f78 624 ret = tda18271_powerscan_init(fe);
4bd5d107 625 if (tda_fail(ret))
24124f78 626 goto fail;
255b5113
MK
627
628 /* rf band calibration */
c151c32f
MK
629 for (i = 0; priv->rf_cal_state[i].rfmax != 0; i++) {
630 ret =
255b5113
MK
631 tda18271_rf_tracking_filters_init(fe, 1000 *
632 priv->rf_cal_state[i].rfmax);
4bd5d107 633 if (tda_fail(ret))
c151c32f
MK
634 goto fail;
635 }
255b5113 636
09f83c4f 637 priv->tm_rfcal = tda18271_read_thermometer(fe);
24124f78
MK
638fail:
639 return ret;
255b5113
MK
640}
641
642/* ------------------------------------------------------------------ */
643
12afe378 644static int tda18271c2_rf_cal_init(struct dvb_frontend *fe)
255b5113
MK
645{
646 struct tda18271_priv *priv = fe->tuner_priv;
839c6c96 647 unsigned char *regs = priv->tda18271_regs;
24124f78 648 int ret;
839c6c96
MK
649
650 /* test RF_CAL_OK to see if we need init */
651 if ((regs[R_EP1] & 0x10) == 0)
652 priv->cal_initialized = false;
255b5113
MK
653
654 if (priv->cal_initialized)
655 return 0;
656
24124f78 657 ret = tda18271_calc_rf_filter_curve(fe);
4bd5d107 658 if (tda_fail(ret))
24124f78 659 goto fail;
255b5113 660
24124f78 661 ret = tda18271_por(fe);
4bd5d107 662 if (tda_fail(ret))
24124f78 663 goto fail;
255b5113 664
6bfa6657
MK
665 tda_info("tda18271: RF tracking filter calibration complete\n");
666
255b5113 667 priv->cal_initialized = true;
c151c32f 668 goto end;
24124f78 669fail:
c151c32f
MK
670 tda_info("tda18271: RF tracking filter calibration failed!\n");
671end:
24124f78 672 return ret;
255b5113
MK
673}
674
4d2d42bc
MK
675static int tda18271c1_rf_tracking_filter_calibration(struct dvb_frontend *fe,
676 u32 freq, u32 bw)
5bea1cd3
MK
677{
678 struct tda18271_priv *priv = fe->tuner_priv;
679 unsigned char *regs = priv->tda18271_regs;
10ed0bf4 680 int ret;
fe0bf6d7 681 u32 N = 0;
5bea1cd3 682
255b5113 683 /* calculate bp filter */
b92bf0f6 684 tda18271_calc_bp_filter(fe, &freq);
5bea1cd3
MK
685 tda18271_write_regs(fe, R_EP1, 1);
686
687 regs[R_EB4] &= 0x07;
688 regs[R_EB4] |= 0x60;
689 tda18271_write_regs(fe, R_EB4, 1);
690
691 regs[R_EB7] = 0x60;
692 tda18271_write_regs(fe, R_EB7, 1);
693
694 regs[R_EB14] = 0x00;
695 tda18271_write_regs(fe, R_EB14, 1);
696
697 regs[R_EB20] = 0xcc;
698 tda18271_write_regs(fe, R_EB20, 1);
699
255b5113 700 /* set cal mode to RF tracking filter calibration */
26501a70 701 regs[R_EP4] |= 0x03;
5bea1cd3 702
255b5113 703 /* calculate cal pll */
5bea1cd3
MK
704
705 switch (priv->mode) {
706 case TDA18271_ANALOG:
707 N = freq - 1250000;
708 break;
709 case TDA18271_DIGITAL:
710 N = freq + bw / 2;
711 break;
712 }
713
fe0bf6d7 714 tda18271_calc_cal_pll(fe, N);
5bea1cd3 715
255b5113 716 /* calculate main pll */
5bea1cd3
MK
717
718 switch (priv->mode) {
719 case TDA18271_ANALOG:
720 N = freq - 250000;
721 break;
722 case TDA18271_DIGITAL:
723 N = freq + bw / 2 + 1000000;
724 break;
725 }
726
fe0bf6d7 727 tda18271_calc_main_pll(fe, N);
5bea1cd3 728
10ed0bf4 729 ret = tda18271_write_regs(fe, R_EP3, 11);
4bd5d107 730 if (tda_fail(ret))
10ed0bf4
MK
731 return ret;
732
5bea1cd3
MK
733 msleep(5); /* RF tracking filter calibration initialization */
734
255b5113 735 /* search for K,M,CO for RF calibration */
b92bf0f6 736 tda18271_calc_km(fe, &freq);
5bea1cd3
MK
737 tda18271_write_regs(fe, R_EB13, 1);
738
255b5113 739 /* search for rf band */
b92bf0f6 740 tda18271_calc_rf_band(fe, &freq);
5bea1cd3 741
255b5113 742 /* search for gain taper */
b92bf0f6 743 tda18271_calc_gain_taper(fe, &freq);
5bea1cd3
MK
744
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);
749
750 regs[R_EB4] &= 0x07;
751 regs[R_EB4] |= 0x40;
752 tda18271_write_regs(fe, R_EB4, 1);
753
754 regs[R_EB7] = 0x40;
755 tda18271_write_regs(fe, R_EB7, 1);
4d2d42bc 756 msleep(10); /* pll locking */
5bea1cd3
MK
757
758 regs[R_EB20] = 0xec;
759 tda18271_write_regs(fe, R_EB20, 1);
760 msleep(60); /* RF tracking filter calibration completion */
761
762 regs[R_EP4] &= ~0x03; /* set cal mode to normal */
763 tda18271_write_regs(fe, R_EP4, 1);
764
765 tda18271_write_regs(fe, R_EP1, 1);
766
b92bf0f6
MK
767 /* RF tracking filter correction for VHF_Low band */
768 if (0 == tda18271_calc_rf_cal(fe, &freq))
5bea1cd3 769 tda18271_write_regs(fe, R_EB14, 1);
5bea1cd3 770
4d2d42bc
MK
771 return 0;
772}
773
d1c53424
MK
774/* ------------------------------------------------------------------ */
775
12afe378
MK
776static int tda18271_ir_cal_init(struct dvb_frontend *fe)
777{
778 struct tda18271_priv *priv = fe->tuner_priv;
779 unsigned char *regs = priv->tda18271_regs;
d35fccaf 780 int ret;
12afe378 781
d35fccaf 782 ret = tda18271_read_regs(fe);
4bd5d107 783 if (tda_fail(ret))
d35fccaf 784 goto fail;
12afe378
MK
785
786 /* test IR_CAL_OK to see if we need init */
787 if ((regs[R_EP1] & 0x08) == 0)
d35fccaf
MK
788 ret = tda18271_init_regs(fe);
789fail:
790 return ret;
12afe378
MK
791}
792
793static int tda18271_init(struct dvb_frontend *fe)
794{
795 struct tda18271_priv *priv = fe->tuner_priv;
d35fccaf 796 int ret;
12afe378
MK
797
798 mutex_lock(&priv->lock);
799
800 /* power up */
d35fccaf 801 ret = tda18271_set_standby_mode(fe, 0, 0, 0);
4bd5d107 802 if (tda_fail(ret))
d35fccaf 803 goto fail;
12afe378
MK
804
805 /* initialization */
d35fccaf 806 ret = tda18271_ir_cal_init(fe);
4bd5d107 807 if (tda_fail(ret))
d35fccaf 808 goto fail;
12afe378
MK
809
810 if (priv->id == TDA18271HDC2)
811 tda18271c2_rf_cal_init(fe);
d35fccaf 812fail:
12afe378
MK
813 mutex_unlock(&priv->lock);
814
d35fccaf 815 return ret;
12afe378
MK
816}
817
d1c53424 818static int tda18271_tune(struct dvb_frontend *fe,
c293d0a7 819 struct tda18271_std_map_item *map, u32 freq, u32 bw)
4d2d42bc
MK
820{
821 struct tda18271_priv *priv = fe->tuner_priv;
d35fccaf 822 int ret;
4d2d42bc 823
7f7203df
MK
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);
d1c53424 826
d35fccaf 827 ret = tda18271_init(fe);
4bd5d107 828 if (tda_fail(ret))
d35fccaf 829 goto fail;
4d2d42bc
MK
830
831 mutex_lock(&priv->lock);
832
ccbac9bb
MK
833 switch (priv->id) {
834 case TDA18271HDC1:
d1c53424 835 tda18271c1_rf_tracking_filter_calibration(fe, freq, bw);
ccbac9bb
MK
836 break;
837 case TDA18271HDC2:
d1c53424 838 tda18271c2_rf_tracking_filters_correction(fe, freq);
ccbac9bb
MK
839 break;
840 }
31940e39 841 ret = tda18271_channel_configuration(fe, map, freq, bw);
d1c53424
MK
842
843 mutex_unlock(&priv->lock);
d35fccaf
MK
844fail:
845 return ret;
ccbac9bb
MK
846}
847
5bea1cd3
MK
848/* ------------------------------------------------------------------ */
849
850static int tda18271_set_params(struct dvb_frontend *fe,
851 struct dvb_frontend_parameters *params)
852{
853 struct tda18271_priv *priv = fe->tuner_priv;
f21e0d7f 854 struct tda18271_std_map *std_map = &priv->std;
c293d0a7 855 struct tda18271_std_map_item *map;
ccbac9bb 856 int ret;
2ba65d51 857 u32 bw, freq = params->frequency;
5bea1cd3
MK
858
859 priv->mode = TDA18271_DIGITAL;
860
5bea1cd3
MK
861 if (fe->ops.info.type == FE_ATSC) {
862 switch (params->u.vsb.modulation) {
863 case VSB_8:
864 case VSB_16:
c293d0a7 865 map = &std_map->atsc_6;
5bea1cd3
MK
866 break;
867 case QAM_64:
868 case QAM_256:
c293d0a7 869 map = &std_map->qam_6;
5bea1cd3
MK
870 break;
871 default:
182519f4 872 tda_warn("modulation not set!\n");
5bea1cd3
MK
873 return -EINVAL;
874 }
14e3c152
MK
875#if 0
876 /* userspace request is already center adjusted */
5bea1cd3 877 freq += 1750000; /* Adjust to center (+1.75MHZ) */
14e3c152 878#endif
5bea1cd3
MK
879 bw = 6000000;
880 } else if (fe->ops.info.type == FE_OFDM) {
881 switch (params->u.ofdm.bandwidth) {
882 case BANDWIDTH_6_MHZ:
5bea1cd3 883 bw = 6000000;
c293d0a7 884 map = &std_map->dvbt_6;
5bea1cd3
MK
885 break;
886 case BANDWIDTH_7_MHZ:
5bea1cd3 887 bw = 7000000;
c293d0a7 888 map = &std_map->dvbt_7;
5bea1cd3
MK
889 break;
890 case BANDWIDTH_8_MHZ:
5bea1cd3 891 bw = 8000000;
c293d0a7 892 map = &std_map->dvbt_8;
5bea1cd3
MK
893 break;
894 default:
182519f4 895 tda_warn("bandwidth not set!\n");
5bea1cd3
MK
896 return -EINVAL;
897 }
898 } else {
182519f4 899 tda_warn("modulation type not supported!\n");
5bea1cd3
MK
900 return -EINVAL;
901 }
902
ed73683f
MK
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);
906
c293d0a7 907 ret = tda18271_tune(fe, map, freq, bw);
ccbac9bb 908
4bd5d107 909 if (tda_fail(ret))
ccbac9bb
MK
910 goto fail;
911
912 priv->frequency = freq;
913 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ?
914 params->u.ofdm.bandwidth : 0;
915fail:
916 return ret;
5bea1cd3
MK
917}
918
919static int tda18271_set_analog_params(struct dvb_frontend *fe,
920 struct analog_parameters *params)
921{
922 struct tda18271_priv *priv = fe->tuner_priv;
f21e0d7f 923 struct tda18271_std_map *std_map = &priv->std;
c293d0a7 924 struct tda18271_std_map_item *map;
5bea1cd3 925 char *mode;
c293d0a7 926 int ret;
2ba65d51 927 u32 freq = params->frequency * 62500;
5bea1cd3
MK
928
929 priv->mode = TDA18271_ANALOG;
930
c353f42f 931 if (params->mode == V4L2_TUNER_RADIO) {
c353f42f 932 freq = freq / 1000;
c293d0a7 933 map = &std_map->fm_radio;
c353f42f
MK
934 mode = "fm";
935 } else if (params->std & V4L2_STD_MN) {
c293d0a7 936 map = &std_map->atv_mn;
5bea1cd3
MK
937 mode = "MN";
938 } else if (params->std & V4L2_STD_B) {
c293d0a7 939 map = &std_map->atv_b;
5bea1cd3
MK
940 mode = "B";
941 } else if (params->std & V4L2_STD_GH) {
c293d0a7 942 map = &std_map->atv_gh;
5bea1cd3
MK
943 mode = "GH";
944 } else if (params->std & V4L2_STD_PAL_I) {
c293d0a7 945 map = &std_map->atv_i;
5bea1cd3
MK
946 mode = "I";
947 } else if (params->std & V4L2_STD_DK) {
c293d0a7 948 map = &std_map->atv_dk;
5bea1cd3
MK
949 mode = "DK";
950 } else if (params->std & V4L2_STD_SECAM_L) {
c293d0a7 951 map = &std_map->atv_l;
5bea1cd3
MK
952 mode = "L";
953 } else if (params->std & V4L2_STD_SECAM_LC) {
c293d0a7 954 map = &std_map->atv_lc;
95af8a26 955 mode = "L'";
5bea1cd3 956 } else {
c293d0a7 957 map = &std_map->atv_i;
5bea1cd3
MK
958 mode = "xx";
959 }
960
182519f4 961 tda_dbg("setting tda18271 to system %s\n", mode);
5bea1cd3 962
c293d0a7 963 ret = tda18271_tune(fe, map, freq, 0);
ccbac9bb 964
4bd5d107 965 if (tda_fail(ret))
ccbac9bb
MK
966 goto fail;
967
968 priv->frequency = freq;
969 priv->bandwidth = 0;
970fail:
971 return ret;
5bea1cd3
MK
972}
973
518d8739
MK
974static int tda18271_sleep(struct dvb_frontend *fe)
975{
976 struct tda18271_priv *priv = fe->tuner_priv;
d35fccaf 977 int ret;
518d8739
MK
978
979 mutex_lock(&priv->lock);
980
981 /* standby mode w/ slave tuner output
982 * & loop thru & xtal oscillator on */
d35fccaf 983 ret = tda18271_set_standby_mode(fe, 1, 0, 0);
518d8739
MK
984
985 mutex_unlock(&priv->lock);
986
d35fccaf 987 return ret;
518d8739
MK
988}
989
5bea1cd3
MK
990static int tda18271_release(struct dvb_frontend *fe)
991{
a4f263b5
MK
992 struct tda18271_priv *priv = fe->tuner_priv;
993
994 mutex_lock(&tda18271_list_mutex);
995
f9e315a1
MK
996 if (priv)
997 hybrid_tuner_release_state(priv);
a4f263b5 998
a4f263b5
MK
999 mutex_unlock(&tda18271_list_mutex);
1000
5bea1cd3 1001 fe->tuner_priv = NULL;
a4f263b5 1002
5bea1cd3
MK
1003 return 0;
1004}
1005
1006static int tda18271_get_frequency(struct dvb_frontend *fe, u32 *frequency)
1007{
1008 struct tda18271_priv *priv = fe->tuner_priv;
1009 *frequency = priv->frequency;
1010 return 0;
1011}
1012
1013static int tda18271_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
1014{
1015 struct tda18271_priv *priv = fe->tuner_priv;
1016 *bandwidth = priv->bandwidth;
1017 return 0;
1018}
1019
f21e0d7f
MK
1020/* ------------------------------------------------------------------ */
1021
1022#define tda18271_update_std(std_cfg, name) do { \
7f7203df 1023 if (map->std_cfg.if_freq + \
c735372f
MK
1024 map->std_cfg.agc_mode + map->std_cfg.std + \
1025 map->std_cfg.if_lvl + map->std_cfg.rfagc_top > 0) { \
f21e0d7f
MK
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)); \
1029 } } while (0)
1030
1031#define tda18271_dump_std_item(std_cfg, name) do { \
c735372f
MK
1032 tda_dbg("(%s) if_freq = %d, agc_mode = %d, std = %d, " \
1033 "if_lvl = %d, rfagc_top = 0x%02x\n", \
7f7203df 1034 name, std->std_cfg.if_freq, \
c735372f
MK
1035 std->std_cfg.agc_mode, std->std_cfg.std, \
1036 std->std_cfg.if_lvl, std->std_cfg.rfagc_top); \
f21e0d7f
MK
1037 } while (0)
1038
1039static int tda18271_dump_std_map(struct dvb_frontend *fe)
1040{
1041 struct tda18271_priv *priv = fe->tuner_priv;
1042 struct tda18271_std_map *std = &priv->std;
1043
1044 tda_dbg("========== STANDARD MAP SETTINGS ==========\n");
c735372f
MK
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'");
f21e0d7f
MK
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");
c735372f
MK
1057 tda18271_dump_std_item(qam_6, "qam 6 ");
1058 tda18271_dump_std_item(qam_8, "qam 8 ");
f21e0d7f
MK
1059
1060 return 0;
1061}
1062
1063static int tda18271_update_std_map(struct dvb_frontend *fe,
1064 struct tda18271_std_map *map)
1065{
1066 struct tda18271_priv *priv = fe->tuner_priv;
1067 struct tda18271_std_map *std = &priv->std;
1068
1069 if (!map)
1070 return -EINVAL;
1071
c353f42f 1072 tda18271_update_std(fm_radio, "fm");
f21e0d7f
MK
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");
1086
1087 return 0;
1088}
1089
49e7aaf0
MK
1090static int tda18271_get_id(struct dvb_frontend *fe)
1091{
1092 struct tda18271_priv *priv = fe->tuner_priv;
1093 unsigned char *regs = priv->tda18271_regs;
1094 char *name;
1095 int ret = 0;
1096
8d316bf5 1097 mutex_lock(&priv->lock);
49e7aaf0 1098 tda18271_read_regs(fe);
8d316bf5 1099 mutex_unlock(&priv->lock);
49e7aaf0
MK
1100
1101 switch (regs[R_ID] & 0x7f) {
1102 case 3:
1103 name = "TDA18271HD/C1";
255b5113 1104 priv->id = TDA18271HDC1;
49e7aaf0
MK
1105 break;
1106 case 4:
1107 name = "TDA18271HD/C2";
255b5113 1108 priv->id = TDA18271HDC2;
49e7aaf0
MK
1109 break;
1110 default:
1111 name = "Unknown device";
1112 ret = -EINVAL;
1113 break;
1114 }
1115
182519f4 1116 tda_info("%s detected @ %d-%04x%s\n", name,
f9e315a1
MK
1117 i2c_adapter_id(priv->i2c_props.adap),
1118 priv->i2c_props.addr,
49e7aaf0
MK
1119 (0 == ret) ? "" : ", device not supported.");
1120
1121 return ret;
1122}
1123
5bea1cd3
MK
1124static struct dvb_tuner_ops tda18271_tuner_ops = {
1125 .info = {
1126 .name = "NXP TDA18271HD",
1127 .frequency_min = 45000000,
1128 .frequency_max = 864000000,
1129 .frequency_step = 62500
1130 },
efce8410 1131 .init = tda18271_init,
518d8739 1132 .sleep = tda18271_sleep,
5bea1cd3
MK
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,
1138};
1139
1140struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
e435f95c 1141 struct i2c_adapter *i2c,
f21e0d7f 1142 struct tda18271_config *cfg)
5bea1cd3
MK
1143{
1144 struct tda18271_priv *priv = NULL;
f9e315a1 1145 int instance;
a4f263b5
MK
1146
1147 mutex_lock(&tda18271_list_mutex);
1148
f9e315a1
MK
1149 instance = hybrid_tuner_request_state(struct tda18271_priv, priv,
1150 hybrid_tuner_instance_list,
1151 i2c, addr, "tda18271");
1152 switch (instance) {
1153 case 0:
1154 goto fail;
1155 break;
1156 case 1:
1157 /* new tuner instance */
a4f263b5 1158 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO;
868f5ccd 1159 priv->role = (cfg) ? cfg->role : TDA18271_MASTER;
a4f263b5
MK
1160 priv->cal_initialized = false;
1161 mutex_init(&priv->lock);
5bea1cd3 1162
a4f263b5 1163 fe->tuner_priv = priv;
5bea1cd3 1164
5555309c
MK
1165 if (cfg)
1166 priv->small_i2c = cfg->small_i2c;
1167
4bd5d107 1168 if (tda_fail(tda18271_get_id(fe)))
a4f263b5 1169 goto fail;
49e7aaf0 1170
4bd5d107 1171 if (tda_fail(tda18271_assign_map_layout(fe)))
a4f263b5 1172 goto fail;
255b5113 1173
a4f263b5
MK
1174 mutex_lock(&priv->lock);
1175 tda18271_init_regs(fe);
0f96251e
MK
1176
1177 if ((tda18271_cal_on_startup) && (priv->id == TDA18271HDC2))
12afe378 1178 tda18271c2_rf_cal_init(fe);
0f96251e 1179
a4f263b5 1180 mutex_unlock(&priv->lock);
f9e315a1
MK
1181 break;
1182 default:
1183 /* existing tuner instance */
1184 fe->tuner_priv = priv;
1185
1186 /* allow dvb driver to override i2c gate setting */
1187 if ((cfg) && (cfg->gate != TDA18271_GATE_ANALOG))
1188 priv->gate = cfg->gate;
1189 break;
a4f263b5 1190 }
5bea1cd3 1191
f21e0d7f
MK
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);
1195
a4f263b5 1196 mutex_unlock(&tda18271_list_mutex);
8d316bf5 1197
a4f263b5
MK
1198 memcpy(&fe->ops.tuner_ops, &tda18271_tuner_ops,
1199 sizeof(struct dvb_tuner_ops));
efce8410 1200
c735372f 1201 if (tda18271_debug & (DBG_MAP | DBG_ADV))
a4f263b5 1202 tda18271_dump_std_map(fe);
8d316bf5 1203
5bea1cd3 1204 return fe;
49e7aaf0 1205fail:
a4f263b5
MK
1206 mutex_unlock(&tda18271_list_mutex);
1207
49e7aaf0
MK
1208 tda18271_release(fe);
1209 return NULL;
5bea1cd3
MK
1210}
1211EXPORT_SYMBOL_GPL(tda18271_attach);
1212MODULE_DESCRIPTION("NXP TDA18271HD analog / digital tuner driver");
1213MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1214MODULE_LICENSE("GPL");
5ec96b0c 1215MODULE_VERSION("0.3");
5bea1cd3
MK
1216
1217/*
1218 * Overrides for Emacs so that we follow Linus's tabbing style.
1219 * ---------------------------------------------------------------------------
1220 * Local variables:
1221 * c-basic-offset: 8
1222 * End:
1223 */