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