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