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