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