Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] DiB0090: misc improvements

This patch adds several performance improvements and prepares the
usage of firmware-based devices.

Signed-off-by: Olivier Grenie <olivier.grenie@dibcom.fr>
Signed-off-by: Patrick Boettcher <patrick.boettcher@dibcom.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Olivier Grenie and committed by
Mauro Carvalho Chehab
28fafca7 b994d192

+1352 -341
+1321 -341
drivers/media/dvb/frontends/dib0090.c
··· 45 45 } \ 46 46 } while (0) 47 47 48 + #define CONFIG_SYS_DVBT 48 49 #define CONFIG_SYS_ISDBT 49 50 #define CONFIG_BAND_CBAND 50 51 #define CONFIG_BAND_VHF ··· 77 76 #define EN_SBD 0x44E9 78 77 #define EN_CAB 0x88E9 79 78 79 + /* Calibration defines */ 80 + #define DC_CAL 0x1 81 + #define WBD_CAL 0x2 82 + #define TEMP_CAL 0x4 83 + #define CAPTRIM_CAL 0x8 84 + 85 + #define KROSUS_PLL_LOCKED 0x800 86 + #define KROSUS 0x2 87 + 88 + /* Use those defines to identify SOC version */ 89 + #define SOC 0x02 90 + #define SOC_7090_P1G_11R1 0x82 91 + #define SOC_7090_P1G_21R1 0x8a 92 + #define SOC_8090_P1G_11R1 0x86 93 + #define SOC_8090_P1G_21R1 0x8e 94 + 95 + /* else use thos ones to check */ 96 + #define P1A_B 0x0 97 + #define P1C 0x1 98 + #define P1D_E_F 0x3 99 + #define P1G 0x7 100 + #define P1G_21R2 0xf 101 + 102 + #define MP001 0x1 /* Single 9090/8096 */ 103 + #define MP005 0x4 /* Single Sband */ 104 + #define MP008 0x6 /* Dual diversity VHF-UHF-LBAND */ 105 + #define MP009 0x7 /* Dual diversity 29098 CBAND-UHF-LBAND-SBAND */ 106 + 80 107 #define pgm_read_word(w) (*w) 81 108 82 109 struct dc_calibration; ··· 113 84 u32 max_freq; /* for every frequency less than or equal to that field: this information is correct */ 114 85 u8 switch_trim; 115 86 u8 lna_tune; 116 - u8 lna_bias; 87 + u16 lna_bias; 117 88 u16 v2i; 118 89 u16 mix; 119 90 u16 load; ··· 128 99 u8 topresc; 129 100 }; 130 101 102 + struct dib0090_identity { 103 + u8 version; 104 + u8 product; 105 + u8 p1g; 106 + u8 in_soc; 107 + }; 108 + 131 109 struct dib0090_state { 132 110 struct i2c_adapter *i2c; 133 111 struct dvb_frontend *fe; 134 112 const struct dib0090_config *config; 135 113 136 114 u8 current_band; 137 - u16 revision; 138 115 enum frontend_tune_state tune_state; 139 116 u32 current_rf; 140 117 ··· 178 143 u8 tuner_is_tuned; 179 144 u8 agc_freeze; 180 145 181 - u8 reset; 146 + struct dib0090_identity identity; 147 + 148 + u32 rf_request; 149 + u8 current_standard; 150 + 151 + u8 calibrate; 152 + u32 rest; 153 + u16 bias; 154 + s16 temperature; 155 + 156 + u8 wbd_calibration_gain; 157 + const struct dib0090_wbd_slope *current_wbd_table; 158 + u16 wbdmux; 159 + }; 160 + 161 + struct dib0090_fw_state { 162 + struct i2c_adapter *i2c; 163 + struct dvb_frontend *fe; 164 + struct dib0090_identity identity; 165 + const struct dib0090_config *config; 182 166 }; 183 167 184 168 static u16 dib0090_read_reg(struct dib0090_state *state, u8 reg) 185 169 { 186 170 u8 b[2]; 187 171 struct i2c_msg msg[2] = { 188 - {.addr = state->config->i2c_address, .flags = 0, .buf = &reg, .len = 1}, 189 - {.addr = state->config->i2c_address, .flags = I2C_M_RD, .buf = b, .len = 2}, 172 + {.addr = state->config->i2c_address,.flags = 0,.buf = &reg,.len = 1}, 173 + {.addr = state->config->i2c_address,.flags = I2C_M_RD,.buf = b,.len = 2}, 190 174 }; 191 175 if (i2c_transfer(state->i2c, msg, 2) != 2) { 192 176 printk(KERN_WARNING "DiB0090 I2C read failed\n"); ··· 217 163 static int dib0090_write_reg(struct dib0090_state *state, u32 reg, u16 val) 218 164 { 219 165 u8 b[3] = { reg & 0xff, val >> 8, val & 0xff }; 220 - struct i2c_msg msg = {.addr = state->config->i2c_address, .flags = 0, .buf = b, .len = 3 }; 166 + struct i2c_msg msg = {.addr = state->config->i2c_address,.flags = 0,.buf = b,.len = 3 }; 167 + if (i2c_transfer(state->i2c, &msg, 1) != 1) { 168 + printk(KERN_WARNING "DiB0090 I2C write failed\n"); 169 + return -EREMOTEIO; 170 + } 171 + return 0; 172 + } 173 + 174 + static u16 dib0090_fw_read_reg(struct dib0090_fw_state *state, u8 reg) 175 + { 176 + u8 b[2]; 177 + struct i2c_msg msg = {.addr = reg,.flags = I2C_M_RD,.buf = b,.len = 2 }; 178 + if (i2c_transfer(state->i2c, &msg, 1) != 1) { 179 + printk(KERN_WARNING "DiB0090 I2C read failed\n"); 180 + return 0; 181 + } 182 + return (b[0] << 8) | b[1]; 183 + } 184 + 185 + static int dib0090_fw_write_reg(struct dib0090_fw_state *state, u8 reg, u16 val) 186 + { 187 + u8 b[2] = { val >> 8, val & 0xff }; 188 + struct i2c_msg msg = {.addr = reg,.flags = 0,.buf = b,.len = 2 }; 221 189 if (i2c_transfer(state->i2c, &msg, 1) != 1) { 222 190 printk(KERN_WARNING "DiB0090 I2C write failed\n"); 223 191 return -EREMOTEIO; ··· 259 183 } while (--c); 260 184 } 261 185 262 - static u16 dib0090_identify(struct dvb_frontend *fe) 186 + static int dib0090_identify(struct dvb_frontend *fe) 263 187 { 264 188 struct dib0090_state *state = fe->tuner_priv; 265 189 u16 v; 190 + struct dib0090_identity *identity = &state->identity; 266 191 267 192 v = dib0090_read_reg(state, 0x1a); 268 193 269 - #ifdef FIRMWARE_FIREFLY 270 - /* pll is not locked locked */ 271 - if (!(v & 0x800)) 272 - dprintk("FE%d : Identification : pll is not yet locked", fe->id); 273 - #endif 194 + identity->p1g = 0; 195 + identity->in_soc = 0; 196 + 197 + dprintk("Tuner identification (Version = 0x%04x)", v); 274 198 275 199 /* without PLL lock info */ 276 - v &= 0x3ff; 277 - dprintk("P/V: %04x:", v); 200 + v &= ~KROSUS_PLL_LOCKED; 278 201 279 - if ((v >> 8) & 0xf) 280 - dprintk("FE%d : Product ID = 0x%x : KROSUS", fe->id, (v >> 8) & 0xf); 281 - else 282 - return 0xff; 202 + identity->version = v & 0xff; 203 + identity->product = (v >> 8) & 0xf; 283 204 284 - v &= 0xff; 285 - if (((v >> 5) & 0x7) == 0x1) 286 - dprintk("FE%d : MP001 : 9090/8096", fe->id); 287 - else if (((v >> 5) & 0x7) == 0x4) 288 - dprintk("FE%d : MP005 : Single Sband", fe->id); 289 - else if (((v >> 5) & 0x7) == 0x6) 290 - dprintk("FE%d : MP008 : diversity VHF-UHF-LBAND", fe->id); 291 - else if (((v >> 5) & 0x7) == 0x7) 292 - dprintk("FE%d : MP009 : diversity 29098 CBAND-UHF-LBAND-SBAND", fe->id); 293 - else 294 - return 0xff; 205 + if (identity->product != KROSUS) 206 + goto identification_error; 295 207 296 - /* revision only */ 297 - if ((v & 0x1f) == 0x3) 298 - dprintk("FE%d : P1-D/E/F detected", fe->id); 299 - else if ((v & 0x1f) == 0x1) 300 - dprintk("FE%d : P1C detected", fe->id); 301 - else if ((v & 0x1f) == 0x0) { 302 - #ifdef CONFIG_TUNER_DIB0090_P1B_SUPPORT 303 - dprintk("FE%d : P1-A/B detected: using previous driver - support will be removed soon", fe->id); 304 - dib0090_p1b_register(fe); 305 - #else 306 - dprintk("FE%d : P1-A/B detected: driver is deactivated - not available", fe->id); 307 - return 0xff; 308 - #endif 208 + if ((identity->version & 0x3) == SOC) { 209 + identity->in_soc = 1; 210 + switch (identity->version) { 211 + case SOC_8090_P1G_11R1: 212 + dprintk("SOC 8090 P1-G11R1 Has been detected"); 213 + identity->p1g = 1; 214 + break; 215 + case SOC_8090_P1G_21R1: 216 + dprintk("SOC 8090 P1-G21R1 Has been detected"); 217 + identity->p1g = 1; 218 + break; 219 + case SOC_7090_P1G_11R1: 220 + dprintk("SOC 7090 P1-G11R1 Has been detected"); 221 + identity->p1g = 1; 222 + break; 223 + case SOC_7090_P1G_21R1: 224 + dprintk("SOC 7090 P1-G21R1 Has been detected"); 225 + identity->p1g = 1; 226 + break; 227 + default: 228 + goto identification_error; 229 + } 230 + } else { 231 + switch ((identity->version >> 5) & 0x7) { 232 + case MP001: 233 + dprintk("MP001 : 9090/8096"); 234 + break; 235 + case MP005: 236 + dprintk("MP005 : Single Sband"); 237 + break; 238 + case MP008: 239 + dprintk("MP008 : diversity VHF-UHF-LBAND"); 240 + break; 241 + case MP009: 242 + dprintk("MP009 : diversity 29098 CBAND-UHF-LBAND-SBAND"); 243 + break; 244 + default: 245 + goto identification_error; 246 + } 247 + 248 + switch (identity->version & 0x1f) { 249 + case P1G_21R2: 250 + dprintk("P1G_21R2 detected"); 251 + identity->p1g = 1; 252 + break; 253 + case P1G: 254 + dprintk("P1G detected"); 255 + identity->p1g = 1; 256 + break; 257 + case P1D_E_F: 258 + dprintk("P1D/E/F detected"); 259 + break; 260 + case P1C: 261 + dprintk("P1C detected"); 262 + break; 263 + case P1A_B: 264 + dprintk("P1-A/B detected: driver is deactivated - not available"); 265 + goto identification_error; 266 + break; 267 + default: 268 + goto identification_error; 269 + } 309 270 } 310 271 311 - return v; 272 + return 0; 273 + 274 + identification_error: 275 + return -EIO; 276 + } 277 + 278 + static int dib0090_fw_identify(struct dvb_frontend *fe) 279 + { 280 + struct dib0090_fw_state *state = fe->tuner_priv; 281 + struct dib0090_identity *identity = &state->identity; 282 + 283 + u16 v = dib0090_fw_read_reg(state, 0x1a); 284 + identity->p1g = 0; 285 + identity->in_soc = 0; 286 + 287 + dprintk("FE: Tuner identification (Version = 0x%04x)", v); 288 + 289 + /* without PLL lock info */ 290 + v &= ~KROSUS_PLL_LOCKED; 291 + 292 + identity->version = v & 0xff; 293 + identity->product = (v >> 8) & 0xf; 294 + 295 + if (identity->product != KROSUS) 296 + goto identification_error; 297 + 298 + //From the SOC the version definition has changed 299 + 300 + if ((identity->version & 0x3) == SOC) { 301 + identity->in_soc = 1; 302 + switch (identity->version) { 303 + case SOC_8090_P1G_11R1: 304 + dprintk("SOC 8090 P1-G11R1 Has been detected"); 305 + identity->p1g = 1; 306 + break; 307 + case SOC_8090_P1G_21R1: 308 + dprintk("SOC 8090 P1-G21R1 Has been detected"); 309 + identity->p1g = 1; 310 + break; 311 + case SOC_7090_P1G_11R1: 312 + dprintk("SOC 7090 P1-G11R1 Has been detected"); 313 + identity->p1g = 1; 314 + break; 315 + case SOC_7090_P1G_21R1: 316 + dprintk("SOC 7090 P1-G21R1 Has been detected"); 317 + identity->p1g = 1; 318 + break; 319 + default: 320 + goto identification_error; 321 + } 322 + } else { 323 + switch ((identity->version >> 5) & 0x7) { 324 + case MP001: 325 + dprintk("MP001 : 9090/8096"); 326 + break; 327 + case MP005: 328 + dprintk("MP005 : Single Sband"); 329 + break; 330 + case MP008: 331 + dprintk("MP008 : diversity VHF-UHF-LBAND"); 332 + break; 333 + case MP009: 334 + dprintk("MP009 : diversity 29098 CBAND-UHF-LBAND-SBAND"); 335 + break; 336 + default: 337 + goto identification_error; 338 + } 339 + 340 + switch (identity->version & 0x1f) { 341 + case P1G_21R2: 342 + dprintk("P1G_21R2 detected"); 343 + identity->p1g = 1; 344 + break; 345 + case P1G: 346 + dprintk("P1G detected"); 347 + identity->p1g = 1; 348 + break; 349 + case P1D_E_F: 350 + dprintk("P1D/E/F detected"); 351 + break; 352 + case P1C: 353 + dprintk("P1C detected"); 354 + break; 355 + case P1A_B: 356 + dprintk("P1-A/B detected: driver is deactivated - not available"); 357 + goto identification_error; 358 + break; 359 + default: 360 + goto identification_error; 361 + } 362 + } 363 + 364 + return 0; 365 + 366 + identification_error: 367 + return -EIO;; 312 368 } 313 369 314 370 static void dib0090_reset_digital(struct dvb_frontend *fe, const struct dib0090_config *cfg) 315 371 { 316 372 struct dib0090_state *state = fe->tuner_priv; 373 + u16 PllCfg, i, v; 317 374 318 375 HARD_RESET(state); 319 376 320 - dib0090_write_reg(state, 0x24, EN_PLL); 377 + dib0090_write_reg(state, 0x24, EN_PLL | EN_CRYSTAL); 321 378 dib0090_write_reg(state, 0x1b, EN_DIGCLK | EN_PLL | EN_CRYSTAL); /* PLL, DIG_CLK and CRYSTAL remain */ 322 379 323 - /* adcClkOutRatio=8->7, release reset */ 324 - dib0090_write_reg(state, 0x20, ((cfg->io.adc_clock_ratio - 1) << 11) | (0 << 10) | (1 << 9) | (1 << 8) | (0 << 4) | 0); 380 + if (!cfg->in_soc) { 381 + /* adcClkOutRatio=8->7, release reset */ 382 + dib0090_write_reg(state, 0x20, ((cfg->io.adc_clock_ratio - 1) << 11) | (0 << 10) | (1 << 9) | (1 << 8) | (0 << 4) | 0); 383 + if (cfg->clkoutdrive != 0) 384 + dib0090_write_reg(state, 0x23, (0 << 15) | ((!cfg->analog_output) << 14) | (2 << 10) | (1 << 9) | (0 << 8) 385 + | (cfg->clkoutdrive << 5) | (cfg->clkouttobamse << 4) | (0 << 2) | (0)); 386 + else 387 + dib0090_write_reg(state, 0x23, (0 << 15) | ((!cfg->analog_output) << 14) | (2 << 10) | (1 << 9) | (0 << 8) 388 + | (7 << 5) | (cfg->clkouttobamse << 4) | (0 << 2) | (0)); 389 + } 390 + 391 + /* Read Pll current config * */ 392 + PllCfg = dib0090_read_reg(state, 0x21); 393 + 394 + /** Reconfigure PLL if current setting is different from default setting **/ 395 + if ((PllCfg & 0x1FFF) != ((cfg->io.pll_range << 12) | (cfg->io.pll_loopdiv << 6) | (cfg->io.pll_prediv)) && (!cfg->in_soc) 396 + && !cfg->io.pll_bypass) { 397 + 398 + /* Set Bypass mode */ 399 + PllCfg |= (1 << 15); 400 + dib0090_write_reg(state, 0x21, PllCfg); 401 + 402 + /* Set Reset Pll */ 403 + PllCfg &= ~(1 << 13); 404 + dib0090_write_reg(state, 0x21, PllCfg); 405 + 406 + /*** Set new Pll configuration in bypass and reset state ***/ 407 + PllCfg = (1 << 15) | (0 << 13) | (cfg->io.pll_range << 12) | (cfg->io.pll_loopdiv << 6) | (cfg->io.pll_prediv); 408 + dib0090_write_reg(state, 0x21, PllCfg); 409 + 410 + /* Remove Reset Pll */ 411 + PllCfg |= (1 << 13); 412 + dib0090_write_reg(state, 0x21, PllCfg); 413 + 414 + /*** Wait for PLL lock ***/ 415 + i = 100; 416 + do { 417 + v = !!(dib0090_read_reg(state, 0x1a) & 0x800); 418 + if (v) 419 + break; 420 + } while (--i); 421 + 422 + if (i == 0) { 423 + dprintk("Pll: Unable to lock Pll"); 424 + return; 425 + } 426 + 427 + /* Finally Remove Bypass mode */ 428 + PllCfg &= ~(1 << 15); 429 + dib0090_write_reg(state, 0x21, PllCfg); 430 + } 431 + 432 + if (cfg->io.pll_bypass) { 433 + PllCfg |= (cfg->io.pll_bypass << 15); 434 + dib0090_write_reg(state, 0x21, PllCfg); 435 + } 436 + } 437 + 438 + static int dib0090_fw_reset_digital(struct dvb_frontend *fe, const struct dib0090_config *cfg) 439 + { 440 + struct dib0090_fw_state *state = fe->tuner_priv; 441 + u16 PllCfg; 442 + u16 v; 443 + int i; 444 + 445 + dprintk("fw reset digital"); 446 + HARD_RESET(state); 447 + 448 + dib0090_fw_write_reg(state, 0x24, EN_PLL | EN_CRYSTAL); 449 + dib0090_fw_write_reg(state, 0x1b, EN_DIGCLK | EN_PLL | EN_CRYSTAL); /* PLL, DIG_CLK and CRYSTAL remain */ 450 + 451 + dib0090_fw_write_reg(state, 0x20, 452 + ((cfg->io.adc_clock_ratio - 1) << 11) | (0 << 10) | (1 << 9) | (1 << 8) | (cfg->data_tx_drv << 4) | cfg->ls_cfg_pad_drv); 453 + 454 + v = (0 << 15) | ((!cfg->analog_output) << 14) | (1 << 9) | (0 << 8) | (cfg->clkouttobamse << 4) | (0 << 2) | (0); 325 455 if (cfg->clkoutdrive != 0) 326 - dib0090_write_reg(state, 0x23, 327 - (0 << 15) | ((!cfg->analog_output) << 14) | (1 << 10) | (1 << 9) | (0 << 8) | (cfg->clkoutdrive << 5) | (cfg-> 328 - clkouttobamse 329 - << 4) | (0 330 - << 331 - 2) 332 - | (0)); 456 + v |= cfg->clkoutdrive << 5; 333 457 else 334 - dib0090_write_reg(state, 0x23, 335 - (0 << 15) | ((!cfg->analog_output) << 14) | (1 << 10) | (1 << 9) | (0 << 8) | (7 << 5) | (cfg-> 336 - clkouttobamse << 4) | (0 337 - << 338 - 2) 339 - | (0)); 458 + v |= 7 << 5; 340 459 341 - /* enable pll, de-activate reset, ratio: 2/1 = 60MHz */ 342 - dib0090_write_reg(state, 0x21, 343 - (cfg->io.pll_bypass << 15) | (1 << 13) | (cfg->io.pll_range << 12) | (cfg->io.pll_loopdiv << 6) | (cfg->io.pll_prediv)); 460 + v |= 2 << 10; 461 + dib0090_fw_write_reg(state, 0x23, v); 344 462 463 + /* Read Pll current config * */ 464 + PllCfg = dib0090_fw_read_reg(state, 0x21); 465 + 466 + /** Reconfigure PLL if current setting is different from default setting **/ 467 + if ((PllCfg & 0x1FFF) != ((cfg->io.pll_range << 12) | (cfg->io.pll_loopdiv << 6) | (cfg->io.pll_prediv)) && !cfg->io.pll_bypass) { 468 + 469 + /* Set Bypass mode */ 470 + PllCfg |= (1 << 15); 471 + dib0090_fw_write_reg(state, 0x21, PllCfg); 472 + 473 + /* Set Reset Pll */ 474 + PllCfg &= ~(1 << 13); 475 + dib0090_fw_write_reg(state, 0x21, PllCfg); 476 + 477 + /*** Set new Pll configuration in bypass and reset state ***/ 478 + PllCfg = (1 << 15) | (0 << 13) | (cfg->io.pll_range << 12) | (cfg->io.pll_loopdiv << 6) | (cfg->io.pll_prediv); 479 + dib0090_fw_write_reg(state, 0x21, PllCfg); 480 + 481 + /* Remove Reset Pll */ 482 + PllCfg |= (1 << 13); 483 + dib0090_fw_write_reg(state, 0x21, PllCfg); 484 + 485 + /*** Wait for PLL lock ***/ 486 + i = 100; 487 + do { 488 + v = !!(dib0090_fw_read_reg(state, 0x1a) & 0x800); 489 + if (v) 490 + break; 491 + } while (--i); 492 + 493 + if (i == 0) { 494 + dprintk("Pll: Unable to lock Pll"); 495 + return -EIO; 496 + } 497 + 498 + /* Finally Remove Bypass mode */ 499 + PllCfg &= ~(1 << 15); 500 + dib0090_fw_write_reg(state, 0x21, PllCfg); 501 + } 502 + 503 + if (cfg->io.pll_bypass) { 504 + PllCfg |= (cfg->io.pll_bypass << 15); 505 + dib0090_fw_write_reg(state, 0x21, PllCfg); 506 + } 507 + 508 + return dib0090_fw_identify(fe); 345 509 } 346 510 347 511 static int dib0090_wakeup(struct dvb_frontend *fe) ··· 589 273 struct dib0090_state *state = fe->tuner_priv; 590 274 if (state->config->sleep) 591 275 state->config->sleep(fe, 0); 276 + 277 + /* enable dataTX in case we have been restarted in the wrong moment */ 278 + dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) | (1 << 14)); 592 279 return 0; 593 280 } 594 281 ··· 611 292 else 612 293 dib0090_write_reg(state, 0x04, 1); 613 294 } 295 + 614 296 EXPORT_SYMBOL(dib0090_dcc_freq); 297 + 298 + static const u16 bb_ramp_pwm_normal_socs[] = { 299 + 550, /* max BB gain in 10th of dB */ 300 + (1 << 9) | 8, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> BB_RAMP2 */ 301 + 440, 302 + (4 << 9) | 0, /* BB_RAMP3 = 26dB */ 303 + (0 << 9) | 208, /* BB_RAMP4 */ 304 + (4 << 9) | 208, /* BB_RAMP5 = 29dB */ 305 + (0 << 9) | 440, /* BB_RAMP6 */ 306 + }; 307 + 308 + static const u16 rf_ramp_pwm_cband_7090[] = { 309 + 280, /* max RF gain in 10th of dB */ 310 + 18, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */ 311 + 504, /* ramp_max = maximum X used on the ramp */ 312 + (29 << 10) | 364, /* RF_RAMP5, LNA 1 = 8dB */ 313 + (0 << 10) | 504, /* RF_RAMP6, LNA 1 */ 314 + (60 << 10) | 228, /* RF_RAMP7, LNA 2 = 7.7dB */ 315 + (0 << 10) | 364, /* RF_RAMP8, LNA 2 */ 316 + (34 << 10) | 109, /* GAIN_4_1, LNA 3 = 6.8dB */ 317 + (0 << 10) | 228, /* GAIN_4_2, LNA 3 */ 318 + (37 << 10) | 0, /* RF_RAMP3, LNA 4 = 6.2dB */ 319 + (0 << 10) | 109, /* RF_RAMP4, LNA 4 */ 320 + }; 321 + 322 + static const u16 rf_ramp_pwm_cband_8090[] = { 323 + 345, /* max RF gain in 10th of dB */ 324 + 29, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */ 325 + 1000, /* ramp_max = maximum X used on the ramp */ 326 + (35 << 10) | 772, /* RF_RAMP3, LNA 1 = 8dB */ 327 + (0 << 10) | 1000, /* RF_RAMP4, LNA 1 */ 328 + (58 << 10) | 496, /* RF_RAMP5, LNA 2 = 9.5dB */ 329 + (0 << 10) | 772, /* RF_RAMP6, LNA 2 */ 330 + (27 << 10) | 200, /* RF_RAMP7, LNA 3 = 10.5dB */ 331 + (0 << 10) | 496, /* RF_RAMP8, LNA 3 */ 332 + (40 << 10) | 0, /* GAIN_4_1, LNA 4 = 7dB */ 333 + (0 << 10) | 200, /* GAIN_4_2, LNA 4 */ 334 + }; 335 + 336 + static const u16 rf_ramp_pwm_uhf_7090[] = { 337 + 407, /* max RF gain in 10th of dB */ 338 + 13, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */ 339 + 529, /* ramp_max = maximum X used on the ramp */ 340 + (23 << 10) | 0, /* RF_RAMP3, LNA 1 = 14.7dB */ 341 + (0 << 10) | 176, /* RF_RAMP4, LNA 1 */ 342 + (63 << 10) | 400, /* RF_RAMP5, LNA 2 = 8dB */ 343 + (0 << 10) | 529, /* RF_RAMP6, LNA 2 */ 344 + (48 << 10) | 316, /* RF_RAMP7, LNA 3 = 6.8dB */ 345 + (0 << 10) | 400, /* RF_RAMP8, LNA 3 */ 346 + (29 << 10) | 176, /* GAIN_4_1, LNA 4 = 11.5dB */ 347 + (0 << 10) | 316, /* GAIN_4_2, LNA 4 */ 348 + }; 349 + 350 + static const u16 rf_ramp_pwm_uhf_8090[] = { 351 + 388, /* max RF gain in 10th of dB */ 352 + 26, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */ 353 + 1008, /* ramp_max = maximum X used on the ramp */ 354 + (11 << 10) | 0, /* RF_RAMP3, LNA 1 = 14.7dB */ 355 + (0 << 10) | 369, /* RF_RAMP4, LNA 1 */ 356 + (41 << 10) | 809, /* RF_RAMP5, LNA 2 = 8dB */ 357 + (0 << 10) | 1008, /* RF_RAMP6, LNA 2 */ 358 + (27 << 10) | 659, /* RF_RAMP7, LNA 3 = 6dB */ 359 + (0 << 10) | 809, /* RF_RAMP8, LNA 3 */ 360 + (14 << 10) | 369, /* GAIN_4_1, LNA 4 = 11.5dB */ 361 + (0 << 10) | 659, /* GAIN_4_2, LNA 4 */ 362 + }; 615 363 616 364 static const u16 rf_ramp_pwm_cband[] = { 617 365 0, /* max RF gain in 10th of dB */ ··· 710 324 50, 50, 127, /* LNA3 : 5.0 dB */ 711 325 125, 175, 127, /* LNA4 : 12.5 dB */ 712 326 0, 0, 127, /* CBAND : 0.0 dB */ 327 + }; 328 + 329 + static const u16 rf_ramp_cband_broadmatching[] = /* for p1G only */ 330 + { 331 + 314, /* Calibrated at 200MHz order has been changed g4-g3-g2-g1 */ 332 + 84, 314, 127, /* LNA1 */ 333 + 80, 230, 255, /* LNA2 */ 334 + 80, 150, 127, /* LNA3 It was measured 12dB, do not lock if 120 */ 335 + 70, 70, 127, /* LNA4 */ 336 + 0, 0, 127, /* CBAND */ 713 337 }; 714 338 715 339 static const u16 rf_ramp_cband[] = { ··· 776 380 }; 777 381 778 382 struct slope { 779 - int16_t range; 780 - int16_t slope; 383 + s16 range; 384 + s16 slope; 781 385 }; 782 386 static u16 slopes_to_scale(const struct slope *slopes, u8 num, s16 val) 783 387 { ··· 993 597 #endif 994 598 #ifdef CONFIG_BAND_CBAND 995 599 if (state->current_band == BAND_CBAND) { 996 - dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband); 997 - dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal); 600 + if (state->identity.in_soc) { 601 + dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal_socs); 602 + if (state->identity.version == SOC_8090_P1G_11R1 || state->identity.version == SOC_8090_P1G_21R1) 603 + dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband_8090); 604 + else if (state->identity.version == SOC_7090_P1G_11R1 || state->identity.version == SOC_7090_P1G_21R1) 605 + dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband_7090); 606 + } else { 607 + dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband); 608 + dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal); 609 + } 998 610 } else 999 611 #endif 1000 612 #ifdef CONFIG_BAND_VHF 1001 613 if (state->current_band == BAND_VHF) { 1002 - dib0090_set_rframp_pwm(state, rf_ramp_pwm_vhf); 1003 - dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal); 614 + if (state->identity.in_soc) { 615 + dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal_socs); 616 + //dib0090_set_rframp_pwm(state, rf_ramp_pwm_vhf_socs); /* TODO */ 617 + } else { 618 + dib0090_set_rframp_pwm(state, rf_ramp_pwm_vhf); 619 + dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal); 620 + } 1004 621 } else 1005 622 #endif 1006 623 { 1007 - dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf); 1008 - dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal); 624 + if (state->identity.in_soc) { 625 + if (state->identity.version == SOC_8090_P1G_11R1 || state->identity.version == SOC_8090_P1G_21R1) 626 + dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf_8090); 627 + else if (state->identity.version == SOC_7090_P1G_11R1 || state->identity.version == SOC_7090_P1G_21R1) 628 + dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf_7090); 629 + dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal_socs); 630 + } else { 631 + dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf); 632 + dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal); 633 + } 1009 634 } 1010 635 1011 636 if (state->rf_ramp[0] != 0) ··· 1034 617 else 1035 618 dib0090_write_reg(state, 0x32, (0 << 11)); 1036 619 620 + dib0090_write_reg(state, 0x04, 0x01); 1037 621 dib0090_write_reg(state, 0x39, (1 << 10)); 1038 622 } 1039 623 } 624 + 1040 625 EXPORT_SYMBOL(dib0090_pwm_gain_reset); 626 + 627 + static u32 dib0090_get_slow_adc_val(struct dib0090_state *state) 628 + { 629 + u16 adc_val = dib0090_read_reg(state, 0x1d); 630 + if (state->identity.in_soc) { 631 + adc_val >>= 2; 632 + } 633 + return adc_val; 634 + } 1041 635 1042 636 int dib0090_gain_control(struct dvb_frontend *fe) 1043 637 { ··· 1071 643 } else 1072 644 #endif 1073 645 #ifdef CONFIG_BAND_VHF 1074 - if (state->current_band == BAND_VHF) { 646 + if (state->current_band == BAND_VHF && !state->identity.p1g) { 1075 647 dib0090_set_rframp(state, rf_ramp_vhf); 1076 648 dib0090_set_bbramp(state, bb_ramp_boost); 1077 649 } else 1078 650 #endif 1079 651 #ifdef CONFIG_BAND_CBAND 1080 - if (state->current_band == BAND_CBAND) { 652 + if (state->current_band == BAND_CBAND && !state->identity.p1g) { 1081 653 dib0090_set_rframp(state, rf_ramp_cband); 1082 654 dib0090_set_bbramp(state, bb_ramp_boost); 1083 655 } else 1084 656 #endif 1085 - { 657 + if ((state->current_band == BAND_CBAND || state->current_band == BAND_VHF) && state->identity.p1g) { 658 + dib0090_set_rframp(state, rf_ramp_cband_broadmatching); 659 + dib0090_set_bbramp(state, bb_ramp_boost); 660 + } else { 1086 661 dib0090_set_rframp(state, rf_ramp_uhf); 1087 662 dib0090_set_bbramp(state, bb_ramp_boost); 1088 663 } ··· 1100 669 1101 670 *tune_state = CT_AGC_STEP_0; 1102 671 } else if (!state->agc_freeze) { 1103 - s16 wbd; 672 + s16 wbd = 0, i, cnt; 1104 673 1105 674 int adc; 1106 - wbd_val = dib0090_read_reg(state, 0x1d); 675 + wbd_val = dib0090_get_slow_adc_val(state); 1107 676 1108 - /* read and calc the wbd power */ 1109 - wbd = dib0090_wbd_to_db(state, wbd_val); 677 + if (*tune_state == CT_AGC_STEP_0) 678 + cnt = 5; 679 + else 680 + cnt = 1; 681 + 682 + for (i = 0; i < cnt; i++) { 683 + wbd_val = dib0090_get_slow_adc_val(state); 684 + wbd += dib0090_wbd_to_db(state, wbd_val); 685 + } 686 + wbd /= cnt; 1110 687 wbd_error = state->wbd_target - wbd; 1111 688 1112 689 if (*tune_state == CT_AGC_STEP_0) { 1113 - if (wbd_error < 0 && state->rf_gain_limit > 0) { 690 + if (wbd_error < 0 && state->rf_gain_limit > 0 && !state->identity.p1g) { 1114 691 #ifdef CONFIG_BAND_CBAND 1115 692 /* in case of CBAND tune reduce first the lt_gain2 before adjusting the RF gain */ 1116 693 u8 ltg2 = (state->rf_lt_def >> 10) & 0x7; ··· 1139 700 adc_error = (s16) (((s32) ADC_TARGET) - adc); 1140 701 #ifdef CONFIG_STANDARD_DAB 1141 702 if (state->fe->dtv_property_cache.delivery_system == STANDARD_DAB) 1142 - adc_error += 130; 703 + adc_error -= 10; 1143 704 #endif 1144 705 #ifdef CONFIG_STANDARD_DVBT 1145 706 if (state->fe->dtv_property_cache.delivery_system == STANDARD_DVBT && 1146 - (state->fe->dtv_property_cache.modulation == QAM_64 || state->fe->dtv_property_cache.modulation == QAM_16)) 707 + (state->fe->dtv_property_cache.modulation == QAM_64 || state->fe->dtv_property_cache.modulation == QAM_16)) 1147 708 adc_error += 60; 1148 709 #endif 1149 710 #ifdef CONFIG_SYS_ISDBT 1150 711 if ((state->fe->dtv_property_cache.delivery_system == SYS_ISDBT) && (((state->fe->dtv_property_cache.layer[0].segment_count > 1151 - 0) 1152 - && 1153 - ((state->fe->dtv_property_cache.layer[0].modulation == 1154 - QAM_64) 1155 - || (state->fe->dtv_property_cache.layer[0]. 1156 - modulation == QAM_16))) 1157 - || 1158 - ((state->fe->dtv_property_cache.layer[1].segment_count > 1159 - 0) 1160 - && 1161 - ((state->fe->dtv_property_cache.layer[1].modulation == 1162 - QAM_64) 1163 - || (state->fe->dtv_property_cache.layer[1]. 1164 - modulation == QAM_16))) 1165 - || 1166 - ((state->fe->dtv_property_cache.layer[2].segment_count > 1167 - 0) 1168 - && 1169 - ((state->fe->dtv_property_cache.layer[2].modulation == 1170 - QAM_64) 1171 - || (state->fe->dtv_property_cache.layer[2]. 1172 - modulation == QAM_16))) 1173 - ) 1174 - ) 712 + 0) 713 + && 714 + ((state->fe->dtv_property_cache.layer[0].modulation == 715 + QAM_64) 716 + || (state->fe->dtv_property_cache. 717 + layer[0].modulation == QAM_16))) 718 + || 719 + ((state->fe->dtv_property_cache.layer[1].segment_count > 720 + 0) 721 + && 722 + ((state->fe->dtv_property_cache.layer[1].modulation == 723 + QAM_64) 724 + || (state->fe->dtv_property_cache. 725 + layer[1].modulation == QAM_16))) 726 + || 727 + ((state->fe->dtv_property_cache.layer[2].segment_count > 728 + 0) 729 + && 730 + ((state->fe->dtv_property_cache.layer[2].modulation == 731 + QAM_64) 732 + || (state->fe->dtv_property_cache. 733 + layer[2].modulation == QAM_16))) 734 + ) 735 + ) 1175 736 adc_error += 60; 1176 737 #endif 1177 738 ··· 1199 760 } 1200 761 #ifdef DEBUG_AGC 1201 762 dprintk 1202 - ("FE: %d, tune state %d, ADC = %3ddB (ADC err %3d) WBD %3ddB (WBD err %3d, WBD val SADC: %4d), RFGainLimit (TOP): %3d, signal: %3ddBm", 1203 - (u32) fe->id, (u32) *tune_state, (u32) adc, (u32) adc_error, (u32) wbd, (u32) wbd_error, (u32) wbd_val, 1204 - (u32) state->rf_gain_limit >> WBD_ALPHA, (s32) 200 + adc - (state->current_gain >> GAIN_ALPHA)); 763 + ("tune state %d, ADC = %3ddB (ADC err %3d) WBD %3ddB (WBD err %3d, WBD val SADC: %4d), RFGainLimit (TOP): %3d, signal: %3ddBm", 764 + (u32) * tune_state, (u32) adc, (u32) adc_error, (u32) wbd, (u32) wbd_error, (u32) wbd_val, 765 + (u32) state->rf_gain_limit >> WBD_ALPHA, (s32) 200 + adc - (state->current_gain >> GAIN_ALPHA)); 1205 766 #endif 1206 767 } 1207 768 ··· 1210 771 dib0090_gain_apply(state, adc_error, wbd_error, apply_gain_immediatly); 1211 772 return ret; 1212 773 } 774 + 1213 775 EXPORT_SYMBOL(dib0090_gain_control); 1214 776 1215 777 void dib0090_get_current_gain(struct dvb_frontend *fe, u16 * rf, u16 * bb, u16 * rf_gain_limit, u16 * rflt) ··· 1225 785 if (rflt) 1226 786 *rflt = (state->rf_lt_def >> 10) & 0x7; 1227 787 } 788 + 1228 789 EXPORT_SYMBOL(dib0090_get_current_gain); 1229 790 1230 - u16 dib0090_get_wbd_offset(struct dvb_frontend *tuner) 791 + u16 dib0090_get_wbd_offset(struct dvb_frontend *fe) 1231 792 { 1232 - struct dib0090_state *st = tuner->tuner_priv; 1233 - return st->wbd_offset; 793 + struct dib0090_state *state = fe->tuner_priv; 794 + u32 f_MHz = state->fe->dtv_property_cache.frequency / 1000000; 795 + s32 current_temp = state->temperature; 796 + s32 wbd_thot, wbd_tcold; 797 + const struct dib0090_wbd_slope *wbd = state->current_wbd_table; 798 + 799 + while (f_MHz > wbd->max_freq) 800 + wbd++; 801 + 802 + dprintk("using wbd-table-entry with max freq %d", wbd->max_freq); 803 + 804 + if (current_temp < 0) 805 + current_temp = 0; 806 + if (current_temp > 128) 807 + current_temp = 128; 808 + 809 + //What Wbd gain to apply for this range of frequency 810 + state->wbdmux &= ~(7 << 13); 811 + if (wbd->wbd_gain != 0) 812 + state->wbdmux |= (wbd->wbd_gain << 13); 813 + else 814 + state->wbdmux |= (4 << 13); // 4 is the default WBD gain 815 + 816 + dib0090_write_reg(state, 0x10, state->wbdmux); 817 + 818 + //All the curves are linear with slope*f/64+offset 819 + wbd_thot = wbd->offset_hot - (((u32) wbd->slope_hot * f_MHz) >> 6); 820 + wbd_tcold = wbd->offset_cold - (((u32) wbd->slope_cold * f_MHz) >> 6); 821 + 822 + // Iet assumes that thot-tcold = 130 equiv 128, current temperature ref is -30deg 823 + 824 + wbd_tcold += ((wbd_thot - wbd_tcold) * current_temp) >> 7; 825 + 826 + //for (offset = 0; offset < 1000; offset += 4) 827 + // dbgp("offset = %d -> %d\n", offset, dib0090_wbd_to_db(state, offset)); 828 + state->wbd_target = dib0090_wbd_to_db(state, state->wbd_offset + wbd_tcold); // get the value in dBm from the offset 829 + dprintk("wbd-target: %d dB", (u32) state->wbd_target); 830 + dprintk("wbd offset applied is %d", wbd_tcold); 831 + 832 + return state->wbd_offset + wbd_tcold; 1234 833 } 834 + 1235 835 EXPORT_SYMBOL(dib0090_get_wbd_offset); 1236 836 1237 837 static const u16 dib0090_defaults[] = { ··· 1281 801 0x99a0, 1282 802 0x6008, 1283 803 0x0000, 1284 - 0x8acb, 804 + 0x8bcb, 1285 805 0x0000, 1286 806 0x0405, 1287 807 0x0000, ··· 1309 829 1, 0x39, 1310 830 0x0000, 1311 831 1312 - 1, 0x1b, 1313 - EN_IQADC | EN_BB | EN_BIAS | EN_DIGCLK | EN_PLL | EN_CRYSTAL, 1314 832 2, 0x1e, 1315 833 0x07FF, 1316 834 0x0007, ··· 1322 844 0 1323 845 }; 1324 846 1325 - static int dib0090_reset(struct dvb_frontend *fe) 847 + static const u16 dib0090_p1g_additionnal_defaults[] = { 848 + // additionnal INITIALISATION for p1g to be written after dib0090_defaults 849 + 1, 0x05, 850 + 0xabcd, 851 + 852 + 1, 0x11, 853 + 0x00b4, 854 + 855 + 1, 0x1c, 856 + 0xfffd, 857 + 858 + 1, 0x40, 859 + 0x108, 860 + 0 861 + }; 862 + 863 + static void dib0090_set_default_config(struct dib0090_state *state, const u16 * n) 1326 864 { 1327 - struct dib0090_state *state = fe->tuner_priv; 1328 - u16 l, r, *n; 865 + u16 l, r; 1329 866 1330 - dib0090_reset_digital(fe, state->config); 1331 - state->revision = dib0090_identify(fe); 1332 - 1333 - /* Revision definition */ 1334 - if (state->revision == 0xff) 1335 - return -EINVAL; 1336 - #ifdef EFUSE 1337 - else if ((state->revision & 0x1f) >= 3) /* Update the efuse : Only available for KROSUS > P1C */ 1338 - dib0090_set_EFUSE(state); 1339 - #endif 1340 - 1341 - #ifdef CONFIG_TUNER_DIB0090_P1B_SUPPORT 1342 - if (!(state->revision & 0x1)) /* it is P1B - reset is already done */ 1343 - return 0; 1344 - #endif 1345 - 1346 - /* Upload the default values */ 1347 - n = (u16 *) dib0090_defaults; 1348 867 l = pgm_read_word(n++); 1349 868 while (l) { 1350 869 r = pgm_read_word(n++); 1351 870 do { 1352 - /* DEBUG_TUNER */ 1353 - /* dprintk("%d, %d, %d", l, r, pgm_read_word(n)); */ 1354 871 dib0090_write_reg(state, r, pgm_read_word(n++)); 1355 872 r++; 1356 873 } while (--l); 1357 874 l = pgm_read_word(n++); 1358 875 } 876 + } 877 + 878 + #define CAP_VALUE_MIN (u8) 9 879 + #define CAP_VALUE_MAX (u8) 40 880 + #define HR_MIN (u8) 25 881 + #define HR_MAX (u8) 40 882 + #define POLY_MIN (u8) 0 883 + #define POLY_MAX (u8) 8 884 + 885 + void dib0090_set_EFUSE(struct dib0090_state *state) 886 + { 887 + u8 c,h,n; 888 + u16 e2,e4; 889 + u16 cal; 890 + 891 + e2=dib0090_read_reg(state,0x26); 892 + e4=dib0090_read_reg(state,0x28); 893 + 894 + if ((state->identity.version == P1D_E_F) || // All P1F uses the internal calibration 895 + (state->identity.version == P1G) || (e2 == 0xffff)) { //W0090G11R1 and W0090G11R1-D : We will find the calibration Value of the Baseband 896 + 897 + dib0090_write_reg(state,0x22,0x10); //Start the Calib 898 + cal = (dib0090_read_reg(state,0x22)>>6) & 0x3ff; 899 + 900 + if ((cal<670) || (cal==1023)) //Cal at 800 would give too high value for the n 901 + cal=850; //Recenter the n to 32 902 + n = 165 - ((cal * 10)>>6) ; 903 + e2 = e4 = (3<<12) | (34<<6) | (n); 904 + } 905 + 906 + if (e2!=e4) { 907 + e2 &= e4; /* Remove the redundancy */ 908 + } 909 + 910 + if (e2 != 0xffff) { 911 + c = e2 & 0x3f; 912 + n = (e2 >> 12) & 0xf; 913 + h= (e2 >> 6) & 0x3f; 914 + 915 + if ((c >= CAP_VALUE_MAX) || (c <= CAP_VALUE_MIN)) 916 + c=32; 917 + if ((h >= HR_MAX) || (h <= HR_MIN)) 918 + h=34; 919 + if ((n >= POLY_MAX) || (n <= POLY_MIN)) 920 + n=3; 921 + 922 + dib0090_write_reg(state,0x13, (h << 10)) ; 923 + e2 = (n<<11) | ((h>>2)<<6) | (c); 924 + dib0090_write_reg(state,0x2, e2) ; /* Load the BB_2 */ 925 + } 926 + } 927 + 928 + static int dib0090_reset(struct dvb_frontend *fe) 929 + { 930 + struct dib0090_state *state = fe->tuner_priv; 931 + 932 + dib0090_reset_digital(fe, state->config); 933 + if (dib0090_identify(fe) < 0) 934 + return -EIO; 935 + 936 + #ifdef CONFIG_TUNER_DIB0090_P1B_SUPPORT 937 + if (!(state->identity.version & 0x1)) /* it is P1B - reset is already done */ 938 + return 0; 939 + #endif 940 + 941 + if (!state->identity.in_soc) { 942 + if ((dib0090_read_reg(state, 0x1a) >> 5) & 0x2) 943 + dib0090_write_reg(state, 0x1b, (EN_IQADC | EN_BB | EN_BIAS | EN_DIGCLK | EN_PLL | EN_CRYSTAL)); 944 + else 945 + dib0090_write_reg(state, 0x1b, (EN_DIGCLK | EN_PLL | EN_CRYSTAL)); 946 + } 947 + 948 + dib0090_set_default_config(state, dib0090_defaults); 949 + 950 + if (state->identity.in_soc) 951 + dib0090_write_reg(state, 0x18, 0x2910); /* charge pump current = 0 */ 952 + 953 + if (state->identity.p1g) 954 + dib0090_set_default_config(state, dib0090_p1g_additionnal_defaults); 955 + 956 + if (((state->identity.version & 0x1f) >= P1D_E_F) || (state->identity.in_soc)) /* Update the efuse : Only available for KROSUS > P1C and SOC as well*/ 957 + dib0090_set_EFUSE(state); 1359 958 1360 959 /* Congigure in function of the crystal */ 1361 960 if (state->config->io.clock_khz >= 24000) 1362 - l = 1; 961 + dib0090_write_reg(state, 0x14, 1); 1363 962 else 1364 - l = 2; 1365 - dib0090_write_reg(state, 0x14, l); 963 + dib0090_write_reg(state, 0x14, 2); 1366 964 dprintk("Pll lock : %d", (dib0090_read_reg(state, 0x1a) >> 11) & 0x1); 1367 965 1368 - state->reset = 3; /* enable iq-offset-calibration and wbd-calibration when tuning next time */ 966 + state->calibrate = DC_CAL | WBD_CAL | TEMP_CAL; /* enable iq-offset-calibration and wbd-calibration when tuning next time */ 1369 967 1370 968 return 0; 1371 969 } ··· 1481 927 } 1482 928 1483 929 struct dc_calibration { 1484 - uint8_t addr; 1485 - uint8_t offset; 1486 - uint8_t pga:1; 1487 - uint16_t bb1; 1488 - uint8_t i:1; 930 + u8 addr; 931 + u8 offset; 932 + u8 pga:1; 933 + u16 bb1; 934 + u8 i:1; 1489 935 }; 1490 936 1491 937 static const struct dc_calibration dc_table[] = { ··· 1495 941 /* Step 2 BB gain 1 = 26 with boost = 1 & gain 2 = 29 */ 1496 942 {0x06, 0, 0, (1 << 13) | (29 << 8) | (26 << 3), 1}, 1497 943 {0x06, 10, 0, (1 << 13) | (29 << 8) | (26 << 3), 0}, 944 + {0}, 945 + }; 946 + 947 + static const struct dc_calibration dc_p1g_table[] = { 948 + /* Step1 BB gain1= 26 with boost 1, gain 2 = 0 */ 949 + /* addr ; trim reg offset ; pga ; CTRL_BB1 value ; i or q */ 950 + {0x06, 5, 1, (1 << 13) | (0 << 8) | (15 << 3), 1}, // offset_trim2_i_chann 0 0 5 0 0 1 6 9 5 951 + {0x07, 11, 1, (1 << 13) | (0 << 8) | (15 << 3), 0}, // offset_trim2_q_chann 0 0 5 0 0 1 7 15 11 952 + /* Step 2 BB gain 1 = 26 with boost = 1 & gain 2 = 29 */ 953 + {0x06, 0, 0, (1 << 13) | (29 << 8) | (15 << 3), 1}, // offset_trim1_i_chann 0 0 5 0 0 1 6 4 0 954 + {0x06, 10, 0, (1 << 13) | (29 << 8) | (15 << 3), 0}, // offset_trim1_q_chann 0 0 5 0 0 1 6 14 10 1498 955 {0}, 1499 956 }; 1500 957 ··· 1527 962 static int dib0090_dc_offset_calibration(struct dib0090_state *state, enum frontend_tune_state *tune_state) 1528 963 { 1529 964 int ret = 0; 965 + u16 reg; 1530 966 1531 967 switch (*tune_state) { 1532 - 1533 968 case CT_TUNER_START: 1534 - /* init */ 1535 - dprintk("Internal DC calibration"); 1536 - 1537 - /* the LNA is off */ 1538 - dib0090_write_reg(state, 0x24, 0x02ed); 969 + dprintk("Start DC offset calibration"); 1539 970 1540 971 /* force vcm2 = 0.8V */ 1541 972 state->bb6 = 0; 1542 973 state->bb7 = 0x040d; 1543 974 975 + /* the LNA AND LO are off */ 976 + reg = dib0090_read_reg(state, 0x24) & 0x0ffb; /* shutdown lna and lo */ 977 + dib0090_write_reg(state, 0x24, reg); 978 + 979 + state->wbdmux = dib0090_read_reg(state, 0x10); 980 + dib0090_write_reg(state, 0x10, (state->wbdmux & ~(0xff << 3)) | (0x7 << 3) | 0x3); // connect BB, disable WDB enable* 981 + dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) & ~(1 << 14)); //Discard the DataTX 982 + 1544 983 state->dc = dc_table; 1545 984 985 + if (state->identity.p1g) 986 + state->dc = dc_p1g_table; 1546 987 *tune_state = CT_TUNER_STEP_0; 1547 988 1548 989 /* fall through */ 1549 990 1550 991 case CT_TUNER_STEP_0: 992 + dprintk("Sart/continue DC calibration for %s path", (state->dc->i == 1) ? "I" : "Q"); 1551 993 dib0090_write_reg(state, 0x01, state->dc->bb1); 1552 994 dib0090_write_reg(state, 0x07, state->bb7 | (state->dc->i << 7)); 1553 995 1554 996 state->step = 0; 1555 - 1556 997 state->min_adc_diff = 1023; 1557 - 1558 998 *tune_state = CT_TUNER_STEP_1; 1559 999 ret = 50; 1560 1000 break; 1561 1001 1562 1002 case CT_TUNER_STEP_1: 1563 1003 dib0090_set_trim(state); 1564 - 1565 1004 *tune_state = CT_TUNER_STEP_2; 1566 1005 break; 1567 1006 ··· 1576 1007 break; 1577 1008 1578 1009 case CT_TUNER_STEP_5: /* found an offset */ 1579 - dprintk("FE%d: IQC read=%d, current=%x", state->fe->id, (u32) state->adc_diff, state->step); 1010 + dprintk("adc_diff = %d, current step= %d", (u32) state->adc_diff, state->step); 1011 + if (state->step == 0 && state->adc_diff < 0) { 1012 + state->min_adc_diff = -1023; 1013 + dprintk("Change of sign of the minimum adc diff"); 1014 + } 1015 + 1016 + dprintk("adc_diff = %d, min_adc_diff = %d current_step = %d", state->adc_diff, state->min_adc_diff, state->step); 1580 1017 1581 1018 /* first turn for this frequency */ 1582 1019 if (state->step == 0) { ··· 1592 1017 state->step = 0x10; 1593 1018 } 1594 1019 1595 - state->adc_diff = ABS(state->adc_diff); 1596 - 1597 - if (state->adc_diff < state->min_adc_diff && steps(state->step) < 15) { /* stop search when the delta to 0 is increasing */ 1020 + /* Look for a change of Sign in the Adc_diff.min_adc_diff is used to STORE the setp N-1 */ 1021 + if ((state->adc_diff & 0x8000) == (state->min_adc_diff & 0x8000) && steps(state->step) < 15) { 1022 + /* stop search when the delta the sign is changing and Steps =15 and Step=0 is force for continuance */ 1598 1023 state->step++; 1599 - state->min_adc_diff = state->adc_diff; 1024 + state->min_adc_diff = state->adc_diff; //min is used as N-1 1600 1025 *tune_state = CT_TUNER_STEP_1; 1601 1026 } else { 1602 - 1603 1027 /* the minimum was what we have seen in the step before */ 1604 - state->step--; 1605 - dib0090_set_trim(state); 1028 + if (ABS(state->adc_diff) > ABS(state->min_adc_diff)) { //Come back to the previous state since the delta was better 1029 + dprintk("Since adc_diff N = %d > adc_diff step N-1 = %d, Come back one step", state->adc_diff, state->min_adc_diff); 1030 + state->step--; 1031 + } 1606 1032 1607 - dprintk("FE%d: BB Offset Cal, BBreg=%hd,Offset=%hd,Value Set=%hd", state->fe->id, state->dc->addr, state->adc_diff, 1608 - state->step); 1033 + dib0090_set_trim(state); 1034 + dprintk("BB Offset Cal, BBreg=%hd,Offset=%hd,Value Set=%hd", state->dc->addr, state->adc_diff, state->step); 1609 1035 1610 1036 state->dc++; 1611 1037 if (state->dc->addr == 0) /* done */ ··· 1618 1042 break; 1619 1043 1620 1044 case CT_TUNER_STEP_6: 1621 - dib0090_write_reg(state, 0x07, state->bb7 & ~0x0008); 1045 + dib0090_write_reg(state, 0x07, state->bb7 & ~0x0008); //Force the test bus to be off 1622 1046 dib0090_write_reg(state, 0x1f, 0x7); 1623 1047 *tune_state = CT_TUNER_START; /* reset done -> real tuning can now begin */ 1624 - state->reset &= ~0x1; 1048 + state->calibrate &= ~DC_CAL; 1625 1049 default: 1626 1050 break; 1627 1051 } ··· 1630 1054 1631 1055 static int dib0090_wbd_calibration(struct dib0090_state *state, enum frontend_tune_state *tune_state) 1632 1056 { 1057 + u8 wbd_gain; 1058 + const struct dib0090_wbd_slope *wbd = state->current_wbd_table; 1059 + 1633 1060 switch (*tune_state) { 1634 1061 case CT_TUNER_START: 1635 - /* WBD-mode=log, Bias=2, Gain=6, Testmode=1, en=1, WBDMUX=1 */ 1636 - dib0090_write_reg(state, 0x10, 0xdb09 | (1 << 10)); 1637 - dib0090_write_reg(state, 0x24, EN_UHF & 0x0fff); 1062 + while (state->current_rf / 1000 > wbd->max_freq) 1063 + wbd++; 1064 + if (wbd->wbd_gain != 0) 1065 + wbd_gain = wbd->wbd_gain; 1066 + else { 1067 + wbd_gain = 4; 1068 + #if defined(CONFIG_BAND_LBAND) || defined(CONFIG_BAND_SBAND) 1069 + if ((state->current_band == BAND_LBAND) || (state->current_band == BAND_SBAND)) 1070 + wbd_gain = 2; 1071 + #endif 1072 + } 1638 1073 1074 + if (wbd_gain == state->wbd_calibration_gain) { /* the WBD calibration has already been done */ 1075 + *tune_state = CT_TUNER_START; 1076 + state->calibrate &= ~WBD_CAL; 1077 + return 0; 1078 + } 1079 + 1080 + dib0090_write_reg(state, 0x10, 0x1b81 | (1 << 10) | (wbd_gain << 13) | (1 << 3)); // Force: WBD enable,gain to 4, mux to WBD 1081 + 1082 + dib0090_write_reg(state, 0x24, ((EN_UHF & 0x0fff) | (1 << 1))); //Discard all LNA but crystal !!! 1639 1083 *tune_state = CT_TUNER_STEP_0; 1084 + state->wbd_calibration_gain = wbd_gain; 1640 1085 return 90; /* wait for the WBDMUX to switch and for the ADC to sample */ 1641 - case CT_TUNER_STEP_0: 1642 - state->wbd_offset = dib0090_read_reg(state, 0x1d); 1643 - dprintk("WBD calibration offset = %d", state->wbd_offset); 1644 1086 1087 + case CT_TUNER_STEP_0: 1088 + state->wbd_offset = dib0090_get_slow_adc_val(state); 1089 + dprintk("WBD calibration offset = %d", state->wbd_offset); 1645 1090 *tune_state = CT_TUNER_START; /* reset done -> real tuning can now begin */ 1646 - state->reset &= ~0x2; 1091 + state->calibrate &= ~WBD_CAL; 1647 1092 break; 1093 + 1648 1094 default: 1649 1095 break; 1650 1096 } ··· 1690 1092 state->bb_1_def |= tmp; 1691 1093 1692 1094 dib0090_write_reg(state, 0x01, state->bb_1_def); /* be sure that we have the right bb-filter */ 1095 + 1096 + dib0090_write_reg(state, 0x03, 0x6008); /* = 0x6008 : vcm3_trim = 1 ; filter2_gm1_trim = 8 ; filter2_cutoff_freq = 0 */ 1097 + dib0090_write_reg(state, 0x04, 0x1); /* 0 = 1KHz ; 1 = 50Hz ; 2 = 150Hz ; 3 = 50KHz ; 4 = servo fast */ 1098 + if (state->identity.in_soc) { 1099 + dib0090_write_reg(state, 0x05, 0x9bcf); /* attenuator_ibias_tri = 2 ; input_stage_ibias_tr = 1 ; nc = 11 ; ext_gm_trim = 1 ; obuf_ibias_trim = 4 ; filter13_gm2_ibias_t = 15 */ 1100 + } else { 1101 + dib0090_write_reg(state, 0x02, (5 << 11) | (8 << 6) | (22 & 0x3f)); /* 22 = cap_value */ 1102 + dib0090_write_reg(state, 0x05, 0xabcd); /* = 0xabcd : attenuator_ibias_tri = 2 ; input_stage_ibias_tr = 2 ; nc = 11 ; ext_gm_trim = 1 ; obuf_ibias_trim = 4 ; filter13_gm2_ibias_t = 13 */ 1103 + } 1693 1104 } 1694 1105 1695 1106 static const struct dib0090_pll dib0090_pll_table[] = { ··· 1787 1180 #endif 1788 1181 }; 1789 1182 1183 + static const struct dib0090_tuning dib0090_p1g_tuning_table[] = { 1184 + //max_freq, switch_trim, lna_tune, lna_bias, v2i, mix, load, tuner_enable; 1185 + #ifdef CONFIG_BAND_CBAND 1186 + {170000, 4, 1, 0x820f, 0x300, 0x2d22, 0x82cb, EN_CAB}, // FM EN_CAB 1187 + #endif 1188 + #ifdef CONFIG_BAND_VHF 1189 + {184000, 1, 1, 15, 0x300, 0x4d12, 0xb94e, EN_VHF}, // VHF EN_VHF 1190 + {227000, 1, 3, 15, 0x300, 0x4d12, 0xb94e, EN_VHF}, // VHF EN_VHF 1191 + {380000, 1, 7, 15, 0x300, 0x4d12, 0xb94e, EN_VHF}, // VHF EN_VHF 1192 + #endif 1193 + #ifdef CONFIG_BAND_UHF 1194 + {510000, 2, 0, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF}, // UHF 1195 + {540000, 2, 1, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF}, // UHF 1196 + {600000, 2, 3, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF}, // UHF 1197 + {630000, 2, 4, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF}, // UHF 1198 + {680000, 2, 5, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF}, // UHF 1199 + {720000, 2, 6, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF}, // UHF 1200 + {900000, 2, 7, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF}, // UHF 1201 + #endif 1202 + #ifdef CONFIG_BAND_LBAND 1203 + {1500000, 4, 0, 20, 0x300, 0x1912, 0x82c9, EN_LBD}, // LBD EN_LBD 1204 + {1600000, 4, 1, 20, 0x300, 0x1912, 0x82c9, EN_LBD}, // LBD EN_LBD 1205 + {1800000, 4, 3, 20, 0x300, 0x1912, 0x82c9, EN_LBD}, // LBD EN_LBD 1206 + #endif 1207 + #ifdef CONFIG_BAND_SBAND 1208 + {2300000, 1, 4, 20, 0x300, 0x2d2A, 0x82c7, EN_SBD}, // SBD EN_SBD 1209 + {2900000, 1, 7, 20, 0x280, 0x2deb, 0x8347, EN_SBD}, // SBD EN_SBD 1210 + #endif 1211 + }; 1212 + 1213 + static const struct dib0090_pll dib0090_p1g_pll_table[] = { 1214 + #ifdef CONFIG_BAND_CBAND 1215 + {57000, 0, 11, 48, 6}, // CAB 1216 + {70000, 1, 11, 48, 6}, // CAB 1217 + {86000, 0, 10, 32, 4}, // CAB 1218 + {105000, 1, 10, 32, 4}, // FM 1219 + {115000, 0, 9, 24, 6}, // FM 1220 + {140000, 1, 9, 24, 6}, // MID FM VHF 1221 + {170000, 0, 8, 16, 4}, // MID FM VHF 1222 + #endif 1223 + #ifdef CONFIG_BAND_VHF 1224 + {200000, 1, 8, 16, 4}, // VHF 1225 + {230000, 0, 7, 12, 6}, // VHF 1226 + {280000, 1, 7, 12, 6}, // MID VHF UHF 1227 + {340000, 0, 6, 8, 4}, // MID VHF UHF 1228 + {380000, 1, 6, 8, 4}, // MID VHF UHF 1229 + {455000, 0, 5, 6, 6}, // MID VHF UHF 1230 + #endif 1231 + #ifdef CONFIG_BAND_UHF 1232 + {580000, 1, 5, 6, 6}, // UHF 1233 + {680000, 0, 4, 4, 4}, // UHF 1234 + {860000, 1, 4, 4, 4}, // UHF 1235 + #endif 1236 + #ifdef CONFIG_BAND_LBAND 1237 + {1800000, 1, 2, 2, 4}, // LBD 1238 + #endif 1239 + #ifdef CONFIG_BAND_SBAND 1240 + {2900000, 0, 1, 1, 6}, // SBD 1241 + #endif 1242 + }; 1243 + 1244 + static const struct dib0090_tuning dib0090_p1g_tuning_table_fm_vhf_on_cband[] = { 1245 + //max_freq, switch_trim, lna_tune, lna_bias, v2i, mix, load, tuner_enable; 1246 + #ifdef CONFIG_BAND_CBAND 1247 + {184000, 4, 3, 0x4187, 0x2c0, 0x2d22, 0x81cb, EN_CAB}, // FM EN_CAB // 0x8190 Good perf but higher current //0x4187 Low current 1248 + {227000, 4, 3, 0x4187, 0x2c0, 0x2d22, 0x81cb, EN_CAB}, // FM EN_CAB 1249 + {380000, 4, 3, 0x4187, 0x2c0, 0x2d22, 0x81cb, EN_CAB}, // FM EN_CAB 1250 + #endif 1251 + #ifdef CONFIG_BAND_UHF 1252 + {520000, 2, 0, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF}, // UHF 1253 + {550000, 2, 2, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF}, // UHF 1254 + {650000, 2, 3, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF}, // UHF 1255 + {750000, 2, 5, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF}, // UHF 1256 + {850000, 2, 6, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF}, // UHF 1257 + {900000, 2, 7, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF}, // UHF 1258 + #endif 1259 + #ifdef CONFIG_BAND_LBAND 1260 + {1500000, 4, 0, 20, 0x300, 0x1912, 0x82c9, EN_LBD}, // LBD EN_LBD 1261 + {1600000, 4, 1, 20, 0x300, 0x1912, 0x82c9, EN_LBD}, // LBD EN_LBD 1262 + {1800000, 4, 3, 20, 0x300, 0x1912, 0x82c9, EN_LBD}, // LBD EN_LBD 1263 + #endif 1264 + #ifdef CONFIG_BAND_SBAND 1265 + {2300000, 1, 4, 20, 0x300, 0x2d2A, 0x82c7, EN_SBD}, // SBD EN_SBD 1266 + {2900000, 1, 7, 20, 0x280, 0x2deb, 0x8347, EN_SBD}, // SBD EN_SBD 1267 + #endif 1268 + }; 1269 + 1270 + static const struct dib0090_tuning dib0090_tuning_table_cband_7090[] = { 1271 + //max_freq, switch_trim, lna_tune, lna_bias, v2i, mix, load, tuner_enable; 1272 + #ifdef CONFIG_BAND_CBAND 1273 + //{ 184000, 4, 3, 0x018F, 0x2c0, 0x2d22, 0xb9ce, EN_CAB }, // 0x81ce 0x8190 Good perf but higher current //0x4187 Low current 1274 + {300000, 4, 3, 0x018F, 0x2c0, 0x2d22, 0xb9ce, EN_CAB}, 1275 + {380000, 4, 10, 0x018F, 0x2c0, 0x2d22, 0xb9ce, EN_CAB}, //0x4187 1276 + {570000, 4, 10, 0x8190, 0x2c0, 0x2d22, 0xb9ce, EN_CAB}, 1277 + {858000, 4, 5, 0x8190, 0x2c0, 0x2d22, 0xb9ce, EN_CAB}, 1278 + #endif 1279 + }; 1280 + 1281 + static int dib0090_captrim_search(struct dib0090_state *state, enum frontend_tune_state *tune_state) 1282 + { 1283 + int ret = 0; 1284 + u16 lo4 = 0xe900; 1285 + 1286 + s16 adc_target; 1287 + u16 adc; 1288 + s8 step_sign; 1289 + u8 force_soft_search = 0; 1290 + 1291 + if (state->identity.version == SOC_8090_P1G_11R1 || state->identity.version == SOC_8090_P1G_21R1) 1292 + force_soft_search = 1; 1293 + 1294 + if (*tune_state == CT_TUNER_START) { 1295 + dprintk("Start Captrim search : %s", (force_soft_search == 1) ? "FORCE SOFT SEARCH" : "AUTO"); 1296 + dib0090_write_reg(state, 0x10, 0x2B1); 1297 + dib0090_write_reg(state, 0x1e, 0x0032); 1298 + 1299 + if (!state->tuner_is_tuned) { 1300 + /* prepare a complete captrim */ 1301 + if (!state->identity.p1g || force_soft_search) 1302 + state->step = state->captrim = state->fcaptrim = 64; 1303 + 1304 + state->current_rf = state->rf_request; 1305 + } else { /* we are already tuned to this frequency - the configuration is correct */ 1306 + if (!state->identity.p1g || force_soft_search) { 1307 + /* do a minimal captrim even if the frequency has not changed */ 1308 + state->step = 4; 1309 + state->captrim = state->fcaptrim = dib0090_read_reg(state, 0x18) & 0x7f; 1310 + } 1311 + } 1312 + state->adc_diff = 3000; // start with a unreachable high number : only set for KROSUS < P1G */ 1313 + *tune_state = CT_TUNER_STEP_0; 1314 + 1315 + } else if (*tune_state == CT_TUNER_STEP_0) { 1316 + if (state->identity.p1g && !force_soft_search) { 1317 + // 30MHz => Code 15 for the ration => 128us to lock. Giving approximately 1318 + u8 ratio = 31; // (state->config->io.clock_khz / 1024 + 1) & 0x1f; 1319 + 1320 + dib0090_write_reg(state, 0x40, (3 << 7) | (ratio << 2) | (1 << 1) | 1); 1321 + dib0090_read_reg(state, 0x40); 1322 + //dib0090_write_reg(state, 0x40, (3<<7) | ((((state->config->io.clock_khz >> 11)+1) & 0x1f)<<2) | (1<<1) | 1); 1323 + ret = 50; 1324 + } else { 1325 + state->step /= 2; 1326 + dib0090_write_reg(state, 0x18, lo4 | state->captrim); 1327 + 1328 + if (state->identity.in_soc) 1329 + ret = 25; 1330 + } 1331 + *tune_state = CT_TUNER_STEP_1; 1332 + 1333 + } else if (*tune_state == CT_TUNER_STEP_1) { 1334 + if (state->identity.p1g && !force_soft_search) { 1335 + dib0090_write_reg(state, 0x40, 0x18c | (0 << 1) | 0); 1336 + dib0090_read_reg(state, 0x40); 1337 + 1338 + state->fcaptrim = dib0090_read_reg(state, 0x18) & 0x7F; 1339 + dprintk("***Final Captrim= 0x%x", state->fcaptrim); 1340 + *tune_state = CT_TUNER_STEP_3; 1341 + 1342 + } else { 1343 + /* MERGE for all krosus before P1G */ 1344 + adc = dib0090_get_slow_adc_val(state); 1345 + dprintk("CAPTRIM=%d; ADC = %d (ADC) & %dmV", (u32) state->captrim, (u32) adc, (u32) (adc) * (u32) 1800 / (u32) 1024); 1346 + 1347 + if (state->rest == 0 || state->identity.in_soc) { /* Just for 8090P SOCS where auto captrim HW bug : TO CHECK IN ACI for SOCS !!! if 400 for 8090p SOC => tune issue !!! */ 1348 + adc_target = 200; 1349 + } else 1350 + adc_target = 400; 1351 + 1352 + if (adc >= adc_target) { 1353 + adc -= adc_target; 1354 + step_sign = -1; 1355 + } else { 1356 + adc = adc_target - adc; 1357 + step_sign = 1; 1358 + } 1359 + 1360 + if (adc < state->adc_diff) { 1361 + dprintk("CAPTRIM=%d is closer to target (%d/%d)", (u32) state->captrim, (u32) adc, (u32) state->adc_diff); 1362 + state->adc_diff = adc; 1363 + state->fcaptrim = state->captrim; 1364 + //we could break here, to save time, if we reached a close-enough value 1365 + //e.g.: if (state->adc_diff < 20) 1366 + //break; 1367 + } 1368 + 1369 + state->captrim += step_sign * state->step; 1370 + if (state->step >= 1) 1371 + *tune_state = CT_TUNER_STEP_0; 1372 + else 1373 + *tune_state = CT_TUNER_STEP_2; 1374 + 1375 + ret = 25; //LOLO changed from 15 1376 + } 1377 + } else if (*tune_state == CT_TUNER_STEP_2) { /* this step is only used by krosus < P1G */ 1378 + /*write the final cptrim config */ 1379 + dib0090_write_reg(state, 0x18, lo4 | state->fcaptrim); 1380 + 1381 + *tune_state = CT_TUNER_STEP_3; 1382 + 1383 + } else if (*tune_state == CT_TUNER_STEP_3) { 1384 + state->calibrate &= ~CAPTRIM_CAL; 1385 + *tune_state = CT_TUNER_STEP_0; 1386 + } 1387 + 1388 + return ret; 1389 + } 1390 + 1391 + static int dib0090_get_temperature(struct dib0090_state *state, enum frontend_tune_state *tune_state) 1392 + { 1393 + int ret = 15; 1394 + s16 val; 1395 + 1396 + //The assumption is that the AGC is not active 1397 + switch (*tune_state) { 1398 + case CT_TUNER_START: 1399 + state->wbdmux = dib0090_read_reg(state, 0x10); 1400 + dib0090_write_reg(state, 0x10, (state->wbdmux & ~(0xff << 3)) | (0x8 << 3)); //Move to the bias and clear the wbd enable 1401 + 1402 + state->bias = dib0090_read_reg(state, 0x13); 1403 + dib0090_write_reg(state, 0x13, state->bias | (0x3 << 8)); //Move to the Ref 1404 + 1405 + *tune_state = CT_TUNER_STEP_0; 1406 + /* wait for the WBDMUX to switch and for the ADC to sample */ 1407 + break; 1408 + 1409 + case CT_TUNER_STEP_0: 1410 + state->adc_diff = dib0090_get_slow_adc_val(state); // Get the value for the Ref 1411 + dib0090_write_reg(state, 0x13, (state->bias & ~(0x3 << 8)) | (0x2 << 8)); //Move to the Ptat 1412 + *tune_state = CT_TUNER_STEP_1; 1413 + break; 1414 + 1415 + case CT_TUNER_STEP_1: 1416 + val = dib0090_get_slow_adc_val(state); // Get the value for the Ptat 1417 + state->temperature = ((s16) ((val - state->adc_diff) * 180) >> 8) + 55; // +55 is defined as = -30deg 1418 + 1419 + dprintk("temperature: %d C", state->temperature - 30); 1420 + 1421 + *tune_state = CT_TUNER_STEP_2; 1422 + break; 1423 + 1424 + case CT_TUNER_STEP_2: 1425 + //Reload the start values. 1426 + dib0090_write_reg(state, 0x13, state->bias); 1427 + dib0090_write_reg(state, 0x10, state->wbdmux); /* write back original WBDMUX */ 1428 + 1429 + *tune_state = CT_TUNER_START; 1430 + state->calibrate &= ~TEMP_CAL; 1431 + if (state->config->analog_output == 0) 1432 + dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) | (1 << 14)); //Set the DataTX 1433 + 1434 + break; 1435 + 1436 + default: 1437 + ret = 0; 1438 + break; 1439 + } 1440 + return ret; 1441 + } 1442 + 1790 1443 #define WBD 0x781 /* 1 1 1 1 0000 0 0 1 */ 1791 1444 static int dib0090_tune(struct dvb_frontend *fe) 1792 1445 { ··· 2055 1188 const struct dib0090_pll *pll = state->current_pll_table_index; 2056 1189 enum frontend_tune_state *tune_state = &state->tune_state; 2057 1190 2058 - u32 rf; 2059 - u16 lo4 = 0xe900, lo5, lo6, Den; 1191 + u16 lo5, lo6, Den, tmp; 2060 1192 u32 FBDiv, Rest, FREF, VCOF_kHz = 0; 2061 - u16 tmp, adc; 2062 - int8_t step_sign; 2063 1193 int ret = 10; /* 1ms is the default delay most of the time */ 2064 1194 u8 c, i; 2065 1195 2066 - state->current_band = (u8) BAND_OF_FREQUENCY(fe->dtv_property_cache.frequency / 1000); 2067 - rf = fe->dtv_property_cache.frequency / 1000 + (state->current_band == 2068 - BAND_UHF ? state->config->freq_offset_khz_uhf : state->config->freq_offset_khz_vhf); 2069 - /* in any case we first need to do a reset if needed */ 2070 - if (state->reset & 0x1) 2071 - return dib0090_dc_offset_calibration(state, tune_state); 2072 - else if (state->reset & 0x2) 2073 - return dib0090_wbd_calibration(state, tune_state); 2074 - 2075 - /************************* VCO ***************************/ 1196 + /************************* VCO ***************************/ 2076 1197 /* Default values for FG */ 2077 1198 /* from these are needed : */ 2078 1199 /* Cp,HFdiv,VCOband,SD,Num,Den,FB and REFDiv */ 2079 1200 2080 - #ifdef CONFIG_SYS_ISDBT 2081 - if (state->fe->dtv_property_cache.delivery_system == SYS_ISDBT && state->fe->dtv_property_cache.isdbt_sb_mode == 1) 2082 - rf += 850; 2083 - #endif 2084 - 2085 - if (state->current_rf != rf) { 2086 - state->tuner_is_tuned = 0; 2087 - 2088 - tune = dib0090_tuning_table; 2089 - 2090 - tmp = (state->revision >> 5) & 0x7; 2091 - if (tmp == 0x4 || tmp == 0x7) { 2092 - /* CBAND tuner version for VHF */ 2093 - if (state->current_band == BAND_FM || state->current_band == BAND_VHF) { 2094 - /* Force CBAND */ 2095 - state->current_band = BAND_CBAND; 2096 - tune = dib0090_tuning_table_fm_vhf_on_cband; 2097 - } 2098 - } 2099 - 2100 - pll = dib0090_pll_table; 2101 - /* Look for the interval */ 2102 - while (rf > tune->max_freq) 2103 - tune++; 2104 - while (rf > pll->max_freq) 2105 - pll++; 2106 - state->current_tune_table_index = tune; 2107 - state->current_pll_table_index = pll; 1201 + /* in any case we first need to do a calibration if needed */ 1202 + if (*tune_state == CT_TUNER_START) { 1203 + /* deactivate DataTX before some calibrations */ 1204 + if (state->calibrate & (DC_CAL | TEMP_CAL | WBD_CAL)) 1205 + dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) & ~(1 << 14)); 1206 + else /* Activate DataTX in case a calibration has been done before */ if (state->config->analog_output == 0) 1207 + dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) | (1 << 14)); 2108 1208 } 2109 1209 1210 + if (state->calibrate & DC_CAL) 1211 + return dib0090_dc_offset_calibration(state, tune_state); 1212 + else if (state->calibrate & WBD_CAL) { 1213 + if (state->current_rf == 0) { 1214 + state->current_rf = state->fe->dtv_property_cache.frequency / 1000; 1215 + } 1216 + return dib0090_wbd_calibration(state, tune_state); 1217 + } else if (state->calibrate & TEMP_CAL) 1218 + return dib0090_get_temperature(state, tune_state); 1219 + else if (state->calibrate & CAPTRIM_CAL) 1220 + return dib0090_captrim_search(state, tune_state); 1221 + 2110 1222 if (*tune_state == CT_TUNER_START) { 1223 + /* if soc and AGC pwm control, disengage mux to be able to R/W access to 0x01 register to set the right filter (cutoff_freq_select) during the tune sequence, otherwise, SOC SERPAR error when accessing to 0x01 */ 1224 + if (state->config->use_pwm_agc && state->identity.in_soc) { 1225 + tmp = dib0090_read_reg(state, 0x39); 1226 + if ((tmp >> 10) & 0x1) 1227 + dib0090_write_reg(state, 0x39, tmp & ~(1 << 10)); // disengage mux : en_mux_bb1 = 0 1228 + } 2111 1229 2112 - if (state->tuner_is_tuned == 0) 1230 + state->current_band = (u8) BAND_OF_FREQUENCY(state->fe->dtv_property_cache.frequency / 1000); 1231 + state->rf_request = 1232 + state->fe->dtv_property_cache.frequency / 1000 + (state->current_band == 1233 + BAND_UHF ? state->config->freq_offset_khz_uhf : state->config-> 1234 + freq_offset_khz_vhf); 1235 + 1236 + /* in ISDB-T 1seg we shift tuning frequency */ 1237 + if ((state->fe->dtv_property_cache.delivery_system == SYS_ISDBT && state->fe->dtv_property_cache.isdbt_sb_mode == 1 1238 + && state->fe->dtv_property_cache.isdbt_partial_reception == 0)) { 1239 + const struct dib0090_low_if_offset_table *LUT_offset = state->config->low_if; 1240 + u8 found_offset = 0; 1241 + u32 margin_khz = 100; 1242 + 1243 + if (LUT_offset != NULL) { 1244 + while (LUT_offset->RF_freq != 0xffff) { 1245 + if (((state->rf_request > (LUT_offset->RF_freq - margin_khz)) 1246 + && (state->rf_request < (LUT_offset->RF_freq + margin_khz))) 1247 + && LUT_offset->std == state->fe->dtv_property_cache.delivery_system) { 1248 + state->rf_request += LUT_offset->offset_khz; 1249 + found_offset = 1; 1250 + break; 1251 + } 1252 + LUT_offset++; 1253 + } 1254 + } 1255 + 1256 + if (found_offset == 0) 1257 + state->rf_request += 400; 1258 + } 1259 + if (state->current_rf != state->rf_request || (state->current_standard != state->fe->dtv_property_cache.delivery_system)) { 1260 + state->tuner_is_tuned = 0; 2113 1261 state->current_rf = 0; 1262 + state->current_standard = 0; 2114 1263 2115 - if (state->current_rf != rf) { 1264 + tune = dib0090_tuning_table; 1265 + if (state->identity.p1g) 1266 + tune = dib0090_p1g_tuning_table; 2116 1267 1268 + tmp = (state->identity.version >> 5) & 0x7; 1269 + 1270 + if (state->identity.in_soc) { 1271 + if (state->config->force_cband_input) { /* Use the CBAND input for all band */ 1272 + if (state->current_band & BAND_CBAND || state->current_band & BAND_FM || state->current_band & BAND_VHF 1273 + || state->current_band & BAND_UHF) { 1274 + state->current_band = BAND_CBAND; 1275 + tune = dib0090_tuning_table_cband_7090; 1276 + } 1277 + } else { /* Use the CBAND input for all band under UHF */ 1278 + if (state->current_band & BAND_CBAND || state->current_band & BAND_FM || state->current_band & BAND_VHF) { 1279 + state->current_band = BAND_CBAND; 1280 + tune = dib0090_tuning_table_cband_7090; 1281 + } 1282 + } 1283 + } else 1284 + if (tmp == 0x4 || tmp == 0x7) { 1285 + /* CBAND tuner version for VHF */ 1286 + if (state->current_band == BAND_FM || state->current_band == BAND_CBAND || state->current_band == BAND_VHF) { 1287 + state->current_band = BAND_CBAND; /* Force CBAND */ 1288 + 1289 + tune = dib0090_tuning_table_fm_vhf_on_cband; 1290 + if (state->identity.p1g) 1291 + tune = dib0090_p1g_tuning_table_fm_vhf_on_cband; 1292 + } 1293 + } 1294 + 1295 + pll = dib0090_pll_table; 1296 + if (state->identity.p1g) 1297 + pll = dib0090_p1g_pll_table; 1298 + 1299 + /* Look for the interval */ 1300 + while (state->rf_request > tune->max_freq) 1301 + tune++; 1302 + while (state->rf_request > pll->max_freq) 1303 + pll++; 1304 + 1305 + state->current_tune_table_index = tune; 1306 + state->current_pll_table_index = pll; 1307 + 1308 + // select internal switch 2117 1309 dib0090_write_reg(state, 0x0b, 0xb800 | (tune->switch_trim)); 2118 1310 2119 - /* external loop filter, otherwise: 2120 - * lo5 = (0 << 15) | (0 << 12) | (0 << 11) | (3 << 9) | (4 << 6) | (3 << 4) | 4; 2121 - * lo6 = 0x0e34 */ 2122 - if (pll->vco_band) 2123 - lo5 = 0x049e; 2124 - else if (state->config->analog_output) 2125 - lo5 = 0x041d; 2126 - else 2127 - lo5 = 0x041c; 1311 + // Find the VCO frequency in MHz 1312 + VCOF_kHz = (pll->hfdiv * state->rf_request) * 2; 2128 1313 2129 - lo5 |= (pll->hfdiv_code << 11) | (pll->vco_band << 7); /* bit 15 is the split to the slave, we do not do it here */ 1314 + FREF = state->config->io.clock_khz; // REFDIV is 1FREF Has to be as Close as possible to 10MHz 1315 + if (state->config->fref_clock_ratio != 0) 1316 + FREF /= state->config->fref_clock_ratio; 2130 1317 2131 - if (!state->config->io.pll_int_loop_filt) 2132 - lo6 = 0xff28; 2133 - else 2134 - lo6 = (state->config->io.pll_int_loop_filt << 3); 2135 - 2136 - VCOF_kHz = (pll->hfdiv * rf) * 2; 2137 - 2138 - FREF = state->config->io.clock_khz; 2139 - 1318 + // Determine the FB divider 1319 + // The reference is 10MHz, Therefore the FBdivider is on the first digits 2140 1320 FBDiv = (VCOF_kHz / pll->topresc / FREF); 2141 - Rest = (VCOF_kHz / pll->topresc) - FBDiv * FREF; 1321 + Rest = (VCOF_kHz / pll->topresc) - FBDiv * FREF; //in kHz 2142 1322 1323 + // Avoid Spurs in the loopfilter bandwidth 2143 1324 if (Rest < LPF) 2144 1325 Rest = 0; 2145 1326 else if (Rest < 2 * LPF) ··· 2195 1280 else if (Rest > (FREF - LPF)) { 2196 1281 Rest = 0; 2197 1282 FBDiv += 1; 2198 - } else if (Rest > (FREF - 2 * LPF)) 1283 + } //Go to the next FB 1284 + else if (Rest > (FREF - 2 * LPF)) 2199 1285 Rest = FREF - 2 * LPF; 2200 1286 Rest = (Rest * 6528) / (FREF / 10); 1287 + state->rest = Rest; 1288 + 1289 + /* external loop filter, otherwise: 1290 + * lo5 = (0 << 15) | (0 << 12) | (0 << 11) | (3 << 9) | (4 << 6) | (3 << 4) | 4; 1291 + * lo6 = 0x0e34 */ 1292 + 1293 + if (Rest == 0) { 1294 + if (pll->vco_band) 1295 + lo5 = 0x049f; 1296 + //else if (state->config->analog_output) 1297 + // lo5 = 0x041f; 1298 + else 1299 + lo5 = 0x041f; 1300 + } else { 1301 + if (pll->vco_band) 1302 + lo5 = 0x049e; 1303 + else if (state->config->analog_output) 1304 + lo5 = 0x041d; 1305 + else 1306 + lo5 = 0x041c; 1307 + } 1308 + 1309 + if (state->identity.p1g) { /* Bias is done automatically in P1G */ 1310 + if (state->identity.in_soc) { 1311 + if (state->identity.version == SOC_8090_P1G_11R1) 1312 + lo5 = 0x46f; 1313 + else 1314 + lo5 = 0x42f; 1315 + } else 1316 + lo5 = 0x42c; //BIAS Lo set to 4 by default in case of the Captrim search does not take care of the VCO Bias 1317 + } 1318 + 1319 + lo5 |= (pll->hfdiv_code << 11) | (pll->vco_band << 7); /* bit 15 is the split to the slave, we do not do it here */ 1320 + 1321 + //Internal loop filter set... 1322 + if (!state->config->io.pll_int_loop_filt) { 1323 + if (state->identity.in_soc) 1324 + lo6 = 0xff98; 1325 + else if (state->identity.p1g || (Rest == 0)) 1326 + lo6 = 0xfff8; 1327 + else 1328 + lo6 = 0xff28; 1329 + } else 1330 + lo6 = (state->config->io.pll_int_loop_filt << 3); // take the loop filter value given by the layout 1331 + //dprintk("lo6 = 0x%04x", (u32)lo6); 2201 1332 2202 1333 Den = 1; 2203 1334 2204 - dprintk(" ***** ******* Rest value = %d", Rest); 2205 - 2206 1335 if (Rest > 0) { 2207 1336 if (state->config->analog_output) 2208 - lo6 |= (1 << 2) | 2; 2209 - else 2210 - lo6 |= (1 << 2) | 1; 1337 + lo6 |= (1 << 2) | 2; //SigmaDelta and Dither 1338 + else { 1339 + if (state->identity.in_soc) 1340 + lo6 |= (1 << 2) | 2; //SigmaDelta and Dither 1341 + else 1342 + lo6 |= (1 << 2) | 2; //SigmaDelta and Dither 1343 + } 2211 1344 Den = 255; 2212 1345 } 2213 - #ifdef CONFIG_BAND_SBAND 2214 - if (state->current_band == BAND_SBAND) 2215 - lo6 &= 0xfffb; 2216 - #endif 2217 - 1346 + // Now we have to define the Num and Denum 1347 + // LO1 gets the FBdiv 2218 1348 dib0090_write_reg(state, 0x15, (u16) FBDiv); 2219 - 2220 - dib0090_write_reg(state, 0x16, (Den << 8) | 1); 2221 - 1349 + // LO2 gets the REFDiv 1350 + if (state->config->fref_clock_ratio != 0) 1351 + dib0090_write_reg(state, 0x16, (Den << 8) | state->config->fref_clock_ratio); 1352 + else 1353 + dib0090_write_reg(state, 0x16, (Den << 8) | 1); 1354 + // LO3 for the Numerator 2222 1355 dib0090_write_reg(state, 0x17, (u16) Rest); 2223 - 1356 + // VCO and HF DIV 2224 1357 dib0090_write_reg(state, 0x19, lo5); 2225 - 1358 + // SIGMA Delta 2226 1359 dib0090_write_reg(state, 0x1c, lo6); 2227 1360 1361 + // Check if the 0090 is analogged configured 1362 + //Disable ADC and DigPLL =0xFF9F, 0xffbf for test purposes. 1363 + //Enable The Outputs of the BB on DATA_Tx 2228 1364 lo6 = tune->tuner_enable; 2229 1365 if (state->config->analog_output) 2230 1366 lo6 = (lo6 & 0xff9f) | 0x2; 2231 1367 2232 - dib0090_write_reg(state, 0x24, lo6 | EN_LO 2233 - #ifdef CONFIG_DIB0090_USE_PWM_AGC 2234 - | state->config->use_pwm_agc * EN_CRYSTAL 2235 - #endif 2236 - ); 1368 + dib0090_write_reg(state, 0x24, lo6 | EN_LO | state->config->use_pwm_agc * EN_CRYSTAL); 2237 1369 2238 - state->current_rf = rf; 2239 - 2240 - /* prepare a complete captrim */ 2241 - state->step = state->captrim = state->fcaptrim = 64; 2242 - 2243 - } else { /* we are already tuned to this frequency - the configuration is correct */ 2244 - 2245 - /* do a minimal captrim even if the frequency has not changed */ 2246 - state->step = 4; 2247 - state->captrim = state->fcaptrim = dib0090_read_reg(state, 0x18) & 0x7f; 2248 1370 } 2249 - state->adc_diff = 3000; 2250 1371 2251 - dib0090_write_reg(state, 0x10, 0x2B1); 2252 - 2253 - dib0090_write_reg(state, 0x1e, 0x0032); 1372 + state->current_rf = state->rf_request; 1373 + state->current_standard = state->fe->dtv_property_cache.delivery_system; 2254 1374 2255 1375 ret = 20; 2256 - *tune_state = CT_TUNER_STEP_1; 2257 - } else if (*tune_state == CT_TUNER_STEP_0) { 2258 - /* nothing */ 2259 - } else if (*tune_state == CT_TUNER_STEP_1) { 2260 - state->step /= 2; 2261 - dib0090_write_reg(state, 0x18, lo4 | state->captrim); 2262 - *tune_state = CT_TUNER_STEP_2; 2263 - } else if (*tune_state == CT_TUNER_STEP_2) { 1376 + state->calibrate = CAPTRIM_CAL; /* captrim serach now */ 1377 + } 2264 1378 2265 - adc = dib0090_read_reg(state, 0x1d); 2266 - dprintk("FE %d CAPTRIM=%d; ADC = %d (ADC) & %dmV", (u32) fe->id, (u32) state->captrim, (u32) adc, 2267 - (u32) (adc) * (u32) 1800 / (u32) 1024); 1379 + else if (*tune_state == CT_TUNER_STEP_0) { /* Warning : because of captrim cal, if you change this step, change it also in _cal.c file because it is the step following captrim cal state machine */ 1380 + const struct dib0090_wbd_slope *wbd = state->current_wbd_table; 2268 1381 2269 - if (adc >= 400) { 2270 - adc -= 400; 2271 - step_sign = -1; 2272 - } else { 2273 - adc = 400 - adc; 2274 - step_sign = 1; 2275 - } 1382 + // if(!state->identity.p1g) { 1383 + while (state->current_rf / 1000 > wbd->max_freq) 1384 + wbd++; 1385 + // } 2276 1386 2277 - if (adc < state->adc_diff) { 2278 - dprintk("FE %d CAPTRIM=%d is closer to target (%d/%d)", (u32) fe->id, (u32) state->captrim, (u32) adc, (u32) state->adc_diff); 2279 - state->adc_diff = adc; 2280 - state->fcaptrim = state->captrim; 2281 - 2282 - } 2283 - 2284 - state->captrim += step_sign * state->step; 2285 - if (state->step >= 1) 2286 - *tune_state = CT_TUNER_STEP_1; 2287 - else 2288 - *tune_state = CT_TUNER_STEP_3; 2289 - 2290 - ret = 15; 2291 - } else if (*tune_state == CT_TUNER_STEP_3) { 2292 - /*write the final cptrim config */ 2293 - dib0090_write_reg(state, 0x18, lo4 | state->fcaptrim); 2294 - 2295 - #ifdef CONFIG_TUNER_DIB0090_CAPTRIM_MEMORY 2296 - state->memory[state->memory_index].cap = state->fcaptrim; 2297 - #endif 2298 - 2299 - *tune_state = CT_TUNER_STEP_4; 2300 - } else if (*tune_state == CT_TUNER_STEP_4) { 2301 1387 dib0090_write_reg(state, 0x1e, 0x07ff); 1388 + dprintk("Final Captrim: %d", (u32) state->fcaptrim); 1389 + dprintk("HFDIV code: %d", (u32) pll->hfdiv_code); 1390 + dprintk("VCO = %d", (u32) pll->vco_band); 1391 + dprintk("VCOF in kHz: %d ((%d*%d) << 1))", (u32) ((pll->hfdiv * state->rf_request) * 2), (u32) pll->hfdiv, (u32) state->rf_request); 1392 + dprintk("REFDIV: %d, FREF: %d", (u32) 1, (u32) state->config->io.clock_khz); 1393 + dprintk("FBDIV: %d, Rest: %d", (u32) dib0090_read_reg(state, 0x15), (u32) dib0090_read_reg(state, 0x17)); 1394 + dprintk("Num: %d, Den: %d, SD: %d", (u32) dib0090_read_reg(state, 0x17), (u32) (dib0090_read_reg(state, 0x16) >> 8), 1395 + (u32) dib0090_read_reg(state, 0x1c) & 0x3); 2302 1396 2303 - dprintk("FE %d Final Captrim: %d", (u32) fe->id, (u32) state->fcaptrim); 2304 - dprintk("FE %d HFDIV code: %d", (u32) fe->id, (u32) pll->hfdiv_code); 2305 - dprintk("FE %d VCO = %d", (u32) fe->id, (u32) pll->vco_band); 2306 - dprintk("FE %d VCOF in kHz: %d ((%d*%d) << 1))", (u32) fe->id, (u32) ((pll->hfdiv * rf) * 2), (u32) pll->hfdiv, (u32) rf); 2307 - dprintk("FE %d REFDIV: %d, FREF: %d", (u32) fe->id, (u32) 1, (u32) state->config->io.clock_khz); 2308 - dprintk("FE %d FBDIV: %d, Rest: %d", (u32) fe->id, (u32) dib0090_read_reg(state, 0x15), (u32) dib0090_read_reg(state, 0x17)); 2309 - dprintk("FE %d Num: %d, Den: %d, SD: %d", (u32) fe->id, (u32) dib0090_read_reg(state, 0x17), 2310 - (u32) (dib0090_read_reg(state, 0x16) >> 8), (u32) dib0090_read_reg(state, 0x1c) & 0x3); 2311 - 1397 + #define WBD 0x781 /* 1 1 1 1 0000 0 0 1 */ 2312 1398 c = 4; 2313 - i = 3; 2314 - #if defined(CONFIG_BAND_LBAND) || defined(CONFIG_BAND_SBAND) 2315 - if ((state->current_band == BAND_LBAND) || (state->current_band == BAND_SBAND)) { 2316 - c = 2; 2317 - i = 2; 2318 - } 2319 - #endif 2320 - dib0090_write_reg(state, 0x10, (c << 13) | (i << 11) | (WBD 2321 - #ifdef CONFIG_DIB0090_USE_PWM_AGC 2322 - | (state->config->use_pwm_agc << 1) 2323 - #endif 2324 - )); 2325 - dib0090_write_reg(state, 0x09, (tune->lna_tune << 5) | (tune->lna_bias << 0)); 1399 + i = 3; //wbdmux_bias 1400 + 1401 + if (wbd->wbd_gain != 0) //&& !state->identity.p1g) 1402 + c = wbd->wbd_gain; 1403 + 1404 + //Store wideband mux register. 1405 + state->wbdmux = (c << 13) | (i << 11) | (WBD | (state->config->use_pwm_agc << 1)); 1406 + dib0090_write_reg(state, 0x10, state->wbdmux); 1407 + 1408 + if ((tune->tuner_enable == EN_CAB) && state->identity.p1g) { 1409 + dprintk("P1G : The cable band is selected and lna_tune = %d", tune->lna_tune); 1410 + dib0090_write_reg(state, 0x09, tune->lna_bias); 1411 + dib0090_write_reg(state, 0x0b, 0xb800 | (tune->lna_tune << 6) | (tune->switch_trim)); 1412 + } else 1413 + dib0090_write_reg(state, 0x09, (tune->lna_tune << 5) | tune->lna_bias); 1414 + 2326 1415 dib0090_write_reg(state, 0x0c, tune->v2i); 2327 1416 dib0090_write_reg(state, 0x0d, tune->mix); 2328 1417 dib0090_write_reg(state, 0x0e, tune->load); 1418 + *tune_state = CT_TUNER_STEP_1; 2329 1419 2330 - *tune_state = CT_TUNER_STEP_5; 2331 - } else if (*tune_state == CT_TUNER_STEP_5) { 2332 - 1420 + } else if (*tune_state == CT_TUNER_STEP_1) { 2333 1421 /* initialize the lt gain register */ 2334 1422 state->rf_lt_def = 0x7c00; 2335 - dib0090_write_reg(state, 0x0f, state->rf_lt_def); 1423 + // dib0090_write_reg(state, 0x0f, state->rf_lt_def); 2336 1424 2337 1425 dib0090_set_bandwidth(state); 2338 1426 state->tuner_is_tuned = 1; 1427 + 1428 + // if(!state->identity.p1g) 1429 + state->calibrate |= WBD_CAL; // TODO: only do the WBD calibration for new tune 1430 + // 1431 + state->calibrate |= TEMP_CAL; // Force the Temperature to be remesured at next TUNE. 2339 1432 *tune_state = CT_TUNER_STOP; 2340 1433 } else 2341 1434 ret = FE_CALLBACK_TIME_NEVER; ··· 2363 1440 2364 1441 return state->tune_state; 2365 1442 } 1443 + 2366 1444 EXPORT_SYMBOL(dib0090_get_tune_state); 2367 1445 2368 1446 int dib0090_set_tune_state(struct dvb_frontend *fe, enum frontend_tune_state tune_state) ··· 2373 1449 state->tune_state = tune_state; 2374 1450 return 0; 2375 1451 } 1452 + 2376 1453 EXPORT_SYMBOL(dib0090_set_tune_state); 2377 1454 2378 1455 static int dib0090_get_frequency(struct dvb_frontend *fe, u32 * frequency) ··· 2387 1462 static int dib0090_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *p) 2388 1463 { 2389 1464 struct dib0090_state *state = fe->tuner_priv; 2390 - uint32_t ret; 1465 + u32 ret; 2391 1466 2392 1467 state->tune_state = CT_TUNER_START; 2393 1468 ··· 2417 1492 .get_frequency = dib0090_get_frequency, 2418 1493 }; 2419 1494 1495 + static const struct dvb_tuner_ops dib0090_fw_ops = { 1496 + .info = { 1497 + .name = "DiBcom DiB0090", 1498 + .frequency_min = 45000000, 1499 + .frequency_max = 860000000, 1500 + .frequency_step = 1000, 1501 + }, 1502 + .release = dib0090_release, 1503 + 1504 + .init = NULL, 1505 + .sleep = NULL, 1506 + .set_params = NULL, 1507 + .get_frequency = NULL, 1508 + }; 1509 + 1510 + static const struct dib0090_wbd_slope dib0090_wbd_table_default[] = { 1511 + {470, 0, 250, 0, 100, 4}, 1512 + {860, 51, 866, 21, 375, 4}, 1513 + {1700, 0, 800, 0, 850, 4}, //LBAND Predefinition , to calibrate 1514 + {2900, 0, 250, 0, 100, 6}, //SBAND Predefinition , NOT tested Yet 1515 + {0xFFFF, 0, 0, 0, 0, 0}, 1516 + }; 1517 + 2420 1518 struct dvb_frontend *dib0090_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config) 2421 1519 { 2422 1520 struct dib0090_state *st = kzalloc(sizeof(struct dib0090_state), GFP_KERNEL); ··· 2450 1502 st->i2c = i2c; 2451 1503 st->fe = fe; 2452 1504 fe->tuner_priv = st; 1505 + 1506 + if (config->wbd == NULL) 1507 + st->current_wbd_table = dib0090_wbd_table_default; 1508 + else 1509 + st->current_wbd_table = config->wbd; 2453 1510 2454 1511 if (dib0090_reset(fe) != 0) 2455 1512 goto free_mem; ··· 2468 1515 fe->tuner_priv = NULL; 2469 1516 return NULL; 2470 1517 } 1518 + 2471 1519 EXPORT_SYMBOL(dib0090_register); 1520 + 1521 + struct dvb_frontend *dib0090_fw_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config) 1522 + { 1523 + struct dib0090_fw_state *st = kzalloc(sizeof(struct dib0090_fw_state), GFP_KERNEL); 1524 + if (st == NULL) 1525 + return NULL; 1526 + 1527 + st->config = config; 1528 + st->i2c = i2c; 1529 + st->fe = fe; 1530 + fe->tuner_priv = st; 1531 + 1532 + if (dib0090_fw_reset_digital(fe, st->config) != 0) 1533 + goto free_mem; 1534 + 1535 + dprintk("DiB0090 FW: successfully identified"); 1536 + memcpy(&fe->ops.tuner_ops, &dib0090_fw_ops, sizeof(struct dvb_tuner_ops)); 1537 + 1538 + return fe; 1539 + free_mem: 1540 + kfree(st); 1541 + fe->tuner_priv = NULL; 1542 + return NULL; 1543 + } 1544 + 1545 + EXPORT_SYMBOL(dib0090_fw_register); 2472 1546 2473 1547 MODULE_AUTHOR("Patrick Boettcher <pboettcher@dibcom.fr>"); 2474 1548 MODULE_AUTHOR("Olivier Grenie <olivier.grenie@dibcom.fr>");
+31
drivers/media/dvb/frontends/dib0090.h
··· 27 27 u16 pll_int_loop_filt; 28 28 }; 29 29 30 + struct dib0090_wbd_slope { 31 + u16 max_freq; /* for every frequency less than or equal to that field: this information is correct */ 32 + u16 slope_cold; 33 + u16 offset_cold; 34 + u16 slope_hot; 35 + u16 offset_hot; 36 + u8 wbd_gain; 37 + }; 38 + 39 + struct dib0090_low_if_offset_table { 40 + int std; 41 + u32 RF_freq; 42 + s32 offset_khz; 43 + }; 44 + 30 45 struct dib0090_config { 31 46 struct dib0090_io_config io; 32 47 int (*reset) (struct dvb_frontend *, int); ··· 62 47 u16 wbd_cband_offset; 63 48 u8 use_pwm_agc; 64 49 u8 clkoutdrive; 50 + 51 + u8 ls_cfg_pad_drv; 52 + u8 data_tx_drv; 53 + 54 + u8 in_soc; 55 + const struct dib0090_low_if_offset_table *low_if; 56 + u8 fref_clock_ratio; 57 + u16 force_cband_input; 58 + struct dib0090_wbd_slope *wbd; 65 59 }; 66 60 67 61 #if defined(CONFIG_DVB_TUNER_DIB0090) || (defined(CONFIG_DVB_TUNER_DIB0090_MODULE) && defined(MODULE)) 68 62 extern struct dvb_frontend *dib0090_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config); 63 + extern struct dvb_frontend *dib0090_fw_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config); 69 64 extern void dib0090_dcc_freq(struct dvb_frontend *fe, u8 fast); 70 65 extern void dib0090_pwm_gain_reset(struct dvb_frontend *fe); 71 66 extern u16 dib0090_get_wbd_offset(struct dvb_frontend *tuner); ··· 85 60 extern void dib0090_get_current_gain(struct dvb_frontend *fe, u16 * rf, u16 * bb, u16 * rf_gain_limit, u16 * rflt); 86 61 #else 87 62 static inline struct dvb_frontend *dib0090_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct dib0090_config *config) 63 + { 64 + printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 65 + return NULL; 66 + } 67 + 68 + static inline struct dvb_frontend *dib0090_fw_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct dib0090_config *config) 88 69 { 89 70 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 90 71 return NULL;