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