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