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