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