diff options
Diffstat (limited to 'drivers/media/dvb-frontends/dib0070.c')
| -rw-r--r-- | drivers/media/dvb-frontends/dib0070.c | 575 |
1 files changed, 287 insertions, 288 deletions
diff --git a/drivers/media/dvb-frontends/dib0070.c b/drivers/media/dvb-frontends/dib0070.c index 3b024bfe980a..0b8fb5dd1889 100644 --- a/drivers/media/dvb-frontends/dib0070.c +++ b/drivers/media/dvb-frontends/dib0070.c | |||
| @@ -58,10 +58,10 @@ struct dib0070_state { | |||
| 58 | u16 wbd_ff_offset; | 58 | u16 wbd_ff_offset; |
| 59 | u8 revision; | 59 | u8 revision; |
| 60 | 60 | ||
| 61 | enum frontend_tune_state tune_state; | 61 | enum frontend_tune_state tune_state; |
| 62 | u32 current_rf; | 62 | u32 current_rf; |
| 63 | 63 | ||
| 64 | /* for the captrim binary search */ | 64 | /* for the captrim binary search */ |
| 65 | s8 step; | 65 | s8 step; |
| 66 | u16 adc_diff; | 66 | u16 adc_diff; |
| 67 | 67 | ||
| @@ -72,7 +72,7 @@ struct dib0070_state { | |||
| 72 | const struct dib0070_tuning *current_tune_table_index; | 72 | const struct dib0070_tuning *current_tune_table_index; |
| 73 | const struct dib0070_lna_match *lna_match; | 73 | const struct dib0070_lna_match *lna_match; |
| 74 | 74 | ||
| 75 | u8 wbd_gain_current; | 75 | u8 wbd_gain_current; |
| 76 | u16 wbd_offset_3_3[2]; | 76 | u16 wbd_offset_3_3[2]; |
| 77 | 77 | ||
| 78 | /* for the I2C transfer */ | 78 | /* for the I2C transfer */ |
| @@ -151,31 +151,31 @@ static int dib0070_write_reg(struct dib0070_state *state, u8 reg, u16 val) | |||
| 151 | } while (0) | 151 | } while (0) |
| 152 | 152 | ||
| 153 | static int dib0070_set_bandwidth(struct dvb_frontend *fe) | 153 | static int dib0070_set_bandwidth(struct dvb_frontend *fe) |
| 154 | { | 154 | { |
| 155 | struct dib0070_state *state = fe->tuner_priv; | 155 | struct dib0070_state *state = fe->tuner_priv; |
| 156 | u16 tmp = dib0070_read_reg(state, 0x02) & 0x3fff; | 156 | u16 tmp = dib0070_read_reg(state, 0x02) & 0x3fff; |
| 157 | 157 | ||
| 158 | if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 7000) | 158 | if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 7000) |
| 159 | tmp |= (0 << 14); | 159 | tmp |= (0 << 14); |
| 160 | else if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 6000) | 160 | else if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 6000) |
| 161 | tmp |= (1 << 14); | 161 | tmp |= (1 << 14); |
| 162 | else if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 5000) | 162 | else if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 5000) |
| 163 | tmp |= (2 << 14); | 163 | tmp |= (2 << 14); |
| 164 | else | 164 | else |
| 165 | tmp |= (3 << 14); | 165 | tmp |= (3 << 14); |
| 166 | 166 | ||
| 167 | dib0070_write_reg(state, 0x02, tmp); | 167 | dib0070_write_reg(state, 0x02, tmp); |
| 168 | 168 | ||
| 169 | /* sharpen the BB filter in ISDB-T to have higher immunity to adjacent channels */ | 169 | /* sharpen the BB filter in ISDB-T to have higher immunity to adjacent channels */ |
| 170 | if (state->fe->dtv_property_cache.delivery_system == SYS_ISDBT) { | 170 | if (state->fe->dtv_property_cache.delivery_system == SYS_ISDBT) { |
| 171 | u16 value = dib0070_read_reg(state, 0x17); | 171 | u16 value = dib0070_read_reg(state, 0x17); |
| 172 | 172 | ||
| 173 | dib0070_write_reg(state, 0x17, value & 0xfffc); | 173 | dib0070_write_reg(state, 0x17, value & 0xfffc); |
| 174 | tmp = dib0070_read_reg(state, 0x01) & 0x01ff; | 174 | tmp = dib0070_read_reg(state, 0x01) & 0x01ff; |
| 175 | dib0070_write_reg(state, 0x01, tmp | (60 << 9)); | 175 | dib0070_write_reg(state, 0x01, tmp | (60 << 9)); |
| 176 | 176 | ||
| 177 | dib0070_write_reg(state, 0x17, value); | 177 | dib0070_write_reg(state, 0x17, value); |
| 178 | } | 178 | } |
| 179 | return 0; | 179 | return 0; |
| 180 | } | 180 | } |
| 181 | 181 | ||
| @@ -186,7 +186,6 @@ static int dib0070_captrim(struct dib0070_state *state, enum frontend_tune_state | |||
| 186 | int ret = 0; | 186 | int ret = 0; |
| 187 | 187 | ||
| 188 | if (*tune_state == CT_TUNER_STEP_0) { | 188 | if (*tune_state == CT_TUNER_STEP_0) { |
| 189 | |||
| 190 | dib0070_write_reg(state, 0x0f, 0xed10); | 189 | dib0070_write_reg(state, 0x0f, 0xed10); |
| 191 | dib0070_write_reg(state, 0x17, 0x0034); | 190 | dib0070_write_reg(state, 0x17, 0x0034); |
| 192 | 191 | ||
| @@ -195,7 +194,7 @@ static int dib0070_captrim(struct dib0070_state *state, enum frontend_tune_state | |||
| 195 | state->adc_diff = 3000; | 194 | state->adc_diff = 3000; |
| 196 | ret = 20; | 195 | ret = 20; |
| 197 | 196 | ||
| 198 | *tune_state = CT_TUNER_STEP_1; | 197 | *tune_state = CT_TUNER_STEP_1; |
| 199 | } else if (*tune_state == CT_TUNER_STEP_1) { | 198 | } else if (*tune_state == CT_TUNER_STEP_1) { |
| 200 | state->step /= 2; | 199 | state->step /= 2; |
| 201 | dib0070_write_reg(state, 0x14, state->lo4 | state->captrim); | 200 | dib0070_write_reg(state, 0x14, state->lo4 | state->captrim); |
| @@ -220,9 +219,6 @@ static int dib0070_captrim(struct dib0070_state *state, enum frontend_tune_state | |||
| 220 | dprintk("CAPTRIM=%hd is closer to target (%hd/%hd)", state->captrim, adc, state->adc_diff); | 219 | dprintk("CAPTRIM=%hd is closer to target (%hd/%hd)", state->captrim, adc, state->adc_diff); |
| 221 | state->adc_diff = adc; | 220 | state->adc_diff = adc; |
| 222 | state->fcaptrim = state->captrim; | 221 | state->fcaptrim = state->captrim; |
| 223 | |||
| 224 | |||
| 225 | |||
| 226 | } | 222 | } |
| 227 | state->captrim += (step_sign * state->step); | 223 | state->captrim += (step_sign * state->step); |
| 228 | 224 | ||
| @@ -243,7 +239,8 @@ static int dib0070_captrim(struct dib0070_state *state, enum frontend_tune_state | |||
| 243 | static int dib0070_set_ctrl_lo5(struct dvb_frontend *fe, u8 vco_bias_trim, u8 hf_div_trim, u8 cp_current, u8 third_order_filt) | 239 | static int dib0070_set_ctrl_lo5(struct dvb_frontend *fe, u8 vco_bias_trim, u8 hf_div_trim, u8 cp_current, u8 third_order_filt) |
| 244 | { | 240 | { |
| 245 | struct dib0070_state *state = fe->tuner_priv; | 241 | struct dib0070_state *state = fe->tuner_priv; |
| 246 | u16 lo5 = (third_order_filt << 14) | (0 << 13) | (1 << 12) | (3 << 9) | (cp_current << 6) | (hf_div_trim << 3) | (vco_bias_trim << 0); | 242 | u16 lo5 = (third_order_filt << 14) | (0 << 13) | (1 << 12) | (3 << 9) | (cp_current << 6) | (hf_div_trim << 3) | (vco_bias_trim << 0); |
| 243 | |||
| 247 | dprintk("CTRL_LO5: 0x%x", lo5); | 244 | dprintk("CTRL_LO5: 0x%x", lo5); |
| 248 | return dib0070_write_reg(state, 0x15, lo5); | 245 | return dib0070_write_reg(state, 0x15, lo5); |
| 249 | } | 246 | } |
| @@ -257,281 +254,282 @@ void dib0070_ctrl_agc_filter(struct dvb_frontend *fe, u8 open) | |||
| 257 | dib0070_write_reg(state, 0x1a, 0x0000); | 254 | dib0070_write_reg(state, 0x1a, 0x0000); |
| 258 | } else { | 255 | } else { |
| 259 | dib0070_write_reg(state, 0x1b, 0x4112); | 256 | dib0070_write_reg(state, 0x1b, 0x4112); |
| 260 | if (state->cfg->vga_filter != 0) { | 257 | if (state->cfg->vga_filter != 0) { |
| 261 | dib0070_write_reg(state, 0x1a, state->cfg->vga_filter); | 258 | dib0070_write_reg(state, 0x1a, state->cfg->vga_filter); |
| 262 | dprintk("vga filter register is set to %x", state->cfg->vga_filter); | 259 | dprintk("vga filter register is set to %x", state->cfg->vga_filter); |
| 263 | } else | 260 | } else |
| 264 | dib0070_write_reg(state, 0x1a, 0x0009); | 261 | dib0070_write_reg(state, 0x1a, 0x0009); |
| 265 | } | 262 | } |
| 266 | } | 263 | } |
| 267 | 264 | ||
| 268 | EXPORT_SYMBOL(dib0070_ctrl_agc_filter); | 265 | EXPORT_SYMBOL(dib0070_ctrl_agc_filter); |
| 269 | struct dib0070_tuning { | 266 | struct dib0070_tuning { |
| 270 | u32 max_freq; /* for every frequency less than or equal to that field: this information is correct */ | 267 | u32 max_freq; /* for every frequency less than or equal to that field: this information is correct */ |
| 271 | u8 switch_trim; | 268 | u8 switch_trim; |
| 272 | u8 vco_band; | 269 | u8 vco_band; |
| 273 | u8 hfdiv; | 270 | u8 hfdiv; |
| 274 | u8 vco_multi; | 271 | u8 vco_multi; |
| 275 | u8 presc; | 272 | u8 presc; |
| 276 | u8 wbdmux; | 273 | u8 wbdmux; |
| 277 | u16 tuner_enable; | 274 | u16 tuner_enable; |
| 278 | }; | 275 | }; |
| 279 | 276 | ||
| 280 | struct dib0070_lna_match { | 277 | struct dib0070_lna_match { |
| 281 | u32 max_freq; /* for every frequency less than or equal to that field: this information is correct */ | 278 | u32 max_freq; /* for every frequency less than or equal to that field: this information is correct */ |
| 282 | u8 lna_band; | 279 | u8 lna_band; |
| 283 | }; | 280 | }; |
| 284 | 281 | ||
| 285 | static const struct dib0070_tuning dib0070s_tuning_table[] = { | 282 | static const struct dib0070_tuning dib0070s_tuning_table[] = { |
| 286 | { 570000, 2, 1, 3, 6, 6, 2, 0x4000 | 0x0800 }, /* UHF */ | 283 | { 570000, 2, 1, 3, 6, 6, 2, 0x4000 | 0x0800 }, /* UHF */ |
| 287 | { 700000, 2, 0, 2, 4, 2, 2, 0x4000 | 0x0800 }, | 284 | { 700000, 2, 0, 2, 4, 2, 2, 0x4000 | 0x0800 }, |
| 288 | { 863999, 2, 1, 2, 4, 2, 2, 0x4000 | 0x0800 }, | 285 | { 863999, 2, 1, 2, 4, 2, 2, 0x4000 | 0x0800 }, |
| 289 | { 1500000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 }, /* LBAND */ | 286 | { 1500000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 }, /* LBAND */ |
| 290 | { 1600000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 }, | 287 | { 1600000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 }, |
| 291 | { 2000000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 }, | 288 | { 2000000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 }, |
| 292 | { 0xffffffff, 0, 0, 8, 1, 2, 1, 0x8000 | 0x1000 }, /* SBAND */ | 289 | { 0xffffffff, 0, 0, 8, 1, 2, 1, 0x8000 | 0x1000 }, /* SBAND */ |
| 293 | }; | 290 | }; |
| 294 | 291 | ||
| 295 | static const struct dib0070_tuning dib0070_tuning_table[] = { | 292 | static const struct dib0070_tuning dib0070_tuning_table[] = { |
| 296 | { 115000, 1, 0, 7, 24, 2, 1, 0x8000 | 0x1000 }, /* FM below 92MHz cannot be tuned */ | 293 | { 115000, 1, 0, 7, 24, 2, 1, 0x8000 | 0x1000 }, /* FM below 92MHz cannot be tuned */ |
| 297 | { 179500, 1, 0, 3, 16, 2, 1, 0x8000 | 0x1000 }, /* VHF */ | 294 | { 179500, 1, 0, 3, 16, 2, 1, 0x8000 | 0x1000 }, /* VHF */ |
| 298 | { 189999, 1, 1, 3, 16, 2, 1, 0x8000 | 0x1000 }, | 295 | { 189999, 1, 1, 3, 16, 2, 1, 0x8000 | 0x1000 }, |
| 299 | { 250000, 1, 0, 6, 12, 2, 1, 0x8000 | 0x1000 }, | 296 | { 250000, 1, 0, 6, 12, 2, 1, 0x8000 | 0x1000 }, |
| 300 | { 569999, 2, 1, 5, 6, 2, 2, 0x4000 | 0x0800 }, /* UHF */ | 297 | { 569999, 2, 1, 5, 6, 2, 2, 0x4000 | 0x0800 }, /* UHF */ |
| 301 | { 699999, 2, 0, 1, 4, 2, 2, 0x4000 | 0x0800 }, | 298 | { 699999, 2, 0, 1, 4, 2, 2, 0x4000 | 0x0800 }, |
| 302 | { 863999, 2, 1, 1, 4, 2, 2, 0x4000 | 0x0800 }, | 299 | { 863999, 2, 1, 1, 4, 2, 2, 0x4000 | 0x0800 }, |
| 303 | { 0xffffffff, 0, 1, 0, 2, 2, 4, 0x2000 | 0x0400 }, /* LBAND or everything higher than UHF */ | 300 | { 0xffffffff, 0, 1, 0, 2, 2, 4, 0x2000 | 0x0400 }, /* LBAND or everything higher than UHF */ |
| 304 | }; | 301 | }; |
| 305 | 302 | ||
| 306 | static const struct dib0070_lna_match dib0070_lna_flip_chip[] = { | 303 | static const struct dib0070_lna_match dib0070_lna_flip_chip[] = { |
| 307 | { 180000, 0 }, /* VHF */ | 304 | { 180000, 0 }, /* VHF */ |
| 308 | { 188000, 1 }, | 305 | { 188000, 1 }, |
| 309 | { 196400, 2 }, | 306 | { 196400, 2 }, |
| 310 | { 250000, 3 }, | 307 | { 250000, 3 }, |
| 311 | { 550000, 0 }, /* UHF */ | 308 | { 550000, 0 }, /* UHF */ |
| 312 | { 590000, 1 }, | 309 | { 590000, 1 }, |
| 313 | { 666000, 3 }, | 310 | { 666000, 3 }, |
| 314 | { 864000, 5 }, | 311 | { 864000, 5 }, |
| 315 | { 1500000, 0 }, /* LBAND or everything higher than UHF */ | 312 | { 1500000, 0 }, /* LBAND or everything higher than UHF */ |
| 316 | { 1600000, 1 }, | 313 | { 1600000, 1 }, |
| 317 | { 2000000, 3 }, | 314 | { 2000000, 3 }, |
| 318 | { 0xffffffff, 7 }, | 315 | { 0xffffffff, 7 }, |
| 319 | }; | 316 | }; |
| 320 | 317 | ||
| 321 | static const struct dib0070_lna_match dib0070_lna[] = { | 318 | static const struct dib0070_lna_match dib0070_lna[] = { |
| 322 | { 180000, 0 }, /* VHF */ | 319 | { 180000, 0 }, /* VHF */ |
| 323 | { 188000, 1 }, | 320 | { 188000, 1 }, |
| 324 | { 196400, 2 }, | 321 | { 196400, 2 }, |
| 325 | { 250000, 3 }, | 322 | { 250000, 3 }, |
| 326 | { 550000, 2 }, /* UHF */ | 323 | { 550000, 2 }, /* UHF */ |
| 327 | { 650000, 3 }, | 324 | { 650000, 3 }, |
| 328 | { 750000, 5 }, | 325 | { 750000, 5 }, |
| 329 | { 850000, 6 }, | 326 | { 850000, 6 }, |
| 330 | { 864000, 7 }, | 327 | { 864000, 7 }, |
| 331 | { 1500000, 0 }, /* LBAND or everything higher than UHF */ | 328 | { 1500000, 0 }, /* LBAND or everything higher than UHF */ |
| 332 | { 1600000, 1 }, | 329 | { 1600000, 1 }, |
| 333 | { 2000000, 3 }, | 330 | { 2000000, 3 }, |
| 334 | { 0xffffffff, 7 }, | 331 | { 0xffffffff, 7 }, |
| 335 | }; | 332 | }; |
| 336 | 333 | ||
| 337 | #define LPF 100 | 334 | #define LPF 100 |
| 338 | static int dib0070_tune_digital(struct dvb_frontend *fe) | 335 | static int dib0070_tune_digital(struct dvb_frontend *fe) |
| 339 | { | 336 | { |
| 340 | struct dib0070_state *state = fe->tuner_priv; | 337 | struct dib0070_state *state = fe->tuner_priv; |
| 341 | 338 | ||
| 342 | const struct dib0070_tuning *tune; | 339 | const struct dib0070_tuning *tune; |
| 343 | const struct dib0070_lna_match *lna_match; | 340 | const struct dib0070_lna_match *lna_match; |
| 344 | 341 | ||
| 345 | enum frontend_tune_state *tune_state = &state->tune_state; | 342 | enum frontend_tune_state *tune_state = &state->tune_state; |
| 346 | int ret = 10; /* 1ms is the default delay most of the time */ | 343 | int ret = 10; /* 1ms is the default delay most of the time */ |
| 347 | 344 | ||
| 348 | u8 band = (u8)BAND_OF_FREQUENCY(fe->dtv_property_cache.frequency/1000); | 345 | u8 band = (u8)BAND_OF_FREQUENCY(fe->dtv_property_cache.frequency/1000); |
| 349 | u32 freq = fe->dtv_property_cache.frequency/1000 + (band == BAND_VHF ? state->cfg->freq_offset_khz_vhf : state->cfg->freq_offset_khz_uhf); | 346 | u32 freq = fe->dtv_property_cache.frequency/1000 + (band == BAND_VHF ? state->cfg->freq_offset_khz_vhf : state->cfg->freq_offset_khz_uhf); |
| 350 | 347 | ||
| 351 | #ifdef CONFIG_SYS_ISDBT | 348 | #ifdef CONFIG_SYS_ISDBT |
| 352 | if (state->fe->dtv_property_cache.delivery_system == SYS_ISDBT && state->fe->dtv_property_cache.isdbt_sb_mode == 1) | 349 | if (state->fe->dtv_property_cache.delivery_system == SYS_ISDBT && state->fe->dtv_property_cache.isdbt_sb_mode == 1) |
| 353 | if (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) | 350 | if (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) |
| 354 | && (state->fe->dtv_property_cache.isdbt_sb_segment_idx == ((state->fe->dtv_property_cache.isdbt_sb_segment_count / 2) + 1))) | 351 | && (state->fe->dtv_property_cache.isdbt_sb_segment_idx == ((state->fe->dtv_property_cache.isdbt_sb_segment_count / 2) + 1))) |
| 355 | || (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) == 0) | 352 | || (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) == 0) |
| 356 | && (state->fe->dtv_property_cache.isdbt_sb_segment_idx == (state->fe->dtv_property_cache.isdbt_sb_segment_count / 2))) | 353 | && (state->fe->dtv_property_cache.isdbt_sb_segment_idx == (state->fe->dtv_property_cache.isdbt_sb_segment_count / 2))) |
| 357 | || (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) == 0) | 354 | || (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) == 0) |
| 358 | && (state->fe->dtv_property_cache.isdbt_sb_segment_idx == ((state->fe->dtv_property_cache.isdbt_sb_segment_count / 2) + 1)))) | 355 | && (state->fe->dtv_property_cache.isdbt_sb_segment_idx == ((state->fe->dtv_property_cache.isdbt_sb_segment_count / 2) + 1)))) |
| 359 | freq += 850; | 356 | freq += 850; |
| 360 | #endif | 357 | #endif |
| 361 | if (state->current_rf != freq) { | ||
| 362 | |||
| 363 | switch (state->revision) { | ||
| 364 | case DIB0070S_P1A: | ||
| 365 | tune = dib0070s_tuning_table; | ||
| 366 | lna_match = dib0070_lna; | ||
| 367 | break; | ||
| 368 | default: | ||
| 369 | tune = dib0070_tuning_table; | ||
| 370 | if (state->cfg->flip_chip) | ||
| 371 | lna_match = dib0070_lna_flip_chip; | ||
| 372 | else | ||
| 373 | lna_match = dib0070_lna; | ||
| 374 | break; | ||
| 375 | } | ||
| 376 | while (freq > tune->max_freq) /* find the right one */ | ||
| 377 | tune++; | ||
| 378 | while (freq > lna_match->max_freq) /* find the right one */ | ||
| 379 | lna_match++; | ||
| 380 | |||
| 381 | state->current_tune_table_index = tune; | ||
| 382 | state->lna_match = lna_match; | ||
| 383 | } | ||
| 384 | |||
| 385 | if (*tune_state == CT_TUNER_START) { | ||
| 386 | dprintk("Tuning for Band: %hd (%d kHz)", band, freq); | ||
| 387 | if (state->current_rf != freq) { | 358 | if (state->current_rf != freq) { |
| 388 | u8 REFDIV; | ||
| 389 | u32 FBDiv, Rest, FREF, VCOF_kHz; | ||
| 390 | u8 Den; | ||
| 391 | |||
| 392 | state->current_rf = freq; | ||
| 393 | state->lo4 = (state->current_tune_table_index->vco_band << 11) | (state->current_tune_table_index->hfdiv << 7); | ||
| 394 | |||
| 395 | |||
| 396 | dib0070_write_reg(state, 0x17, 0x30); | ||
| 397 | |||
| 398 | |||
| 399 | VCOF_kHz = state->current_tune_table_index->vco_multi * freq * 2; | ||
| 400 | |||
| 401 | switch (band) { | ||
| 402 | case BAND_VHF: | ||
| 403 | REFDIV = (u8) ((state->cfg->clock_khz + 9999) / 10000); | ||
| 404 | break; | ||
| 405 | case BAND_FM: | ||
| 406 | REFDIV = (u8) ((state->cfg->clock_khz) / 1000); | ||
| 407 | break; | ||
| 408 | default: | ||
| 409 | REFDIV = (u8) (state->cfg->clock_khz / 10000); | ||
| 410 | break; | ||
| 411 | } | ||
| 412 | FREF = state->cfg->clock_khz / REFDIV; | ||
| 413 | |||
| 414 | |||
| 415 | 359 | ||
| 416 | switch (state->revision) { | 360 | switch (state->revision) { |
| 417 | case DIB0070S_P1A: | 361 | case DIB0070S_P1A: |
| 418 | FBDiv = (VCOF_kHz / state->current_tune_table_index->presc / FREF); | 362 | tune = dib0070s_tuning_table; |
| 419 | Rest = (VCOF_kHz / state->current_tune_table_index->presc) - FBDiv * FREF; | 363 | lna_match = dib0070_lna; |
| 420 | break; | 364 | break; |
| 421 | |||
| 422 | case DIB0070_P1G: | ||
| 423 | case DIB0070_P1F: | ||
| 424 | default: | 365 | default: |
| 425 | FBDiv = (freq / (FREF / 2)); | 366 | tune = dib0070_tuning_table; |
| 426 | Rest = 2 * freq - FBDiv * FREF; | 367 | if (state->cfg->flip_chip) |
| 427 | break; | 368 | lna_match = dib0070_lna_flip_chip; |
| 428 | } | 369 | else |
| 429 | 370 | lna_match = dib0070_lna; | |
| 430 | if (Rest < LPF) | 371 | break; |
| 431 | Rest = 0; | ||
| 432 | else if (Rest < 2 * LPF) | ||
| 433 | Rest = 2 * LPF; | ||
| 434 | else if (Rest > (FREF - LPF)) { | ||
| 435 | Rest = 0; | ||
| 436 | FBDiv += 1; | ||
| 437 | } else if (Rest > (FREF - 2 * LPF)) | ||
| 438 | Rest = FREF - 2 * LPF; | ||
| 439 | Rest = (Rest * 6528) / (FREF / 10); | ||
| 440 | |||
| 441 | Den = 1; | ||
| 442 | if (Rest > 0) { | ||
| 443 | state->lo4 |= (1 << 14) | (1 << 12); | ||
| 444 | Den = 255; | ||
| 445 | } | 372 | } |
| 373 | while (freq > tune->max_freq) /* find the right one */ | ||
| 374 | tune++; | ||
| 375 | while (freq > lna_match->max_freq) /* find the right one */ | ||
| 376 | lna_match++; | ||
| 446 | 377 | ||
| 378 | state->current_tune_table_index = tune; | ||
| 379 | state->lna_match = lna_match; | ||
| 380 | } | ||
| 447 | 381 | ||
| 448 | dib0070_write_reg(state, 0x11, (u16)FBDiv); | 382 | if (*tune_state == CT_TUNER_START) { |
| 449 | dib0070_write_reg(state, 0x12, (Den << 8) | REFDIV); | 383 | dprintk("Tuning for Band: %hd (%d kHz)", band, freq); |
| 450 | dib0070_write_reg(state, 0x13, (u16) Rest); | 384 | if (state->current_rf != freq) { |
| 451 | 385 | u8 REFDIV; | |
| 452 | if (state->revision == DIB0070S_P1A) { | 386 | u32 FBDiv, Rest, FREF, VCOF_kHz; |
| 453 | 387 | u8 Den; | |
| 454 | if (band == BAND_SBAND) { | 388 | |
| 455 | dib0070_set_ctrl_lo5(fe, 2, 4, 3, 0); | 389 | state->current_rf = freq; |
| 456 | dib0070_write_reg(state, 0x1d, 0xFFFF); | 390 | state->lo4 = (state->current_tune_table_index->vco_band << 11) | (state->current_tune_table_index->hfdiv << 7); |
| 457 | } else | 391 | |
| 458 | dib0070_set_ctrl_lo5(fe, 5, 4, 3, 1); | 392 | |
| 393 | dib0070_write_reg(state, 0x17, 0x30); | ||
| 394 | |||
| 395 | |||
| 396 | VCOF_kHz = state->current_tune_table_index->vco_multi * freq * 2; | ||
| 397 | |||
| 398 | switch (band) { | ||
| 399 | case BAND_VHF: | ||
| 400 | REFDIV = (u8) ((state->cfg->clock_khz + 9999) / 10000); | ||
| 401 | break; | ||
| 402 | case BAND_FM: | ||
| 403 | REFDIV = (u8) ((state->cfg->clock_khz) / 1000); | ||
| 404 | break; | ||
| 405 | default: | ||
| 406 | REFDIV = (u8) (state->cfg->clock_khz / 10000); | ||
| 407 | break; | ||
| 408 | } | ||
| 409 | FREF = state->cfg->clock_khz / REFDIV; | ||
| 410 | |||
| 411 | |||
| 412 | |||
| 413 | switch (state->revision) { | ||
| 414 | case DIB0070S_P1A: | ||
| 415 | FBDiv = (VCOF_kHz / state->current_tune_table_index->presc / FREF); | ||
| 416 | Rest = (VCOF_kHz / state->current_tune_table_index->presc) - FBDiv * FREF; | ||
| 417 | break; | ||
| 418 | |||
| 419 | case DIB0070_P1G: | ||
| 420 | case DIB0070_P1F: | ||
| 421 | default: | ||
| 422 | FBDiv = (freq / (FREF / 2)); | ||
| 423 | Rest = 2 * freq - FBDiv * FREF; | ||
| 424 | break; | ||
| 425 | } | ||
| 426 | |||
| 427 | if (Rest < LPF) | ||
| 428 | Rest = 0; | ||
| 429 | else if (Rest < 2 * LPF) | ||
| 430 | Rest = 2 * LPF; | ||
| 431 | else if (Rest > (FREF - LPF)) { | ||
| 432 | Rest = 0; | ||
| 433 | FBDiv += 1; | ||
| 434 | } else if (Rest > (FREF - 2 * LPF)) | ||
| 435 | Rest = FREF - 2 * LPF; | ||
| 436 | Rest = (Rest * 6528) / (FREF / 10); | ||
| 437 | |||
| 438 | Den = 1; | ||
| 439 | if (Rest > 0) { | ||
| 440 | state->lo4 |= (1 << 14) | (1 << 12); | ||
| 441 | Den = 255; | ||
| 442 | } | ||
| 443 | |||
| 444 | |||
| 445 | dib0070_write_reg(state, 0x11, (u16)FBDiv); | ||
| 446 | dib0070_write_reg(state, 0x12, (Den << 8) | REFDIV); | ||
| 447 | dib0070_write_reg(state, 0x13, (u16) Rest); | ||
| 448 | |||
| 449 | if (state->revision == DIB0070S_P1A) { | ||
| 450 | |||
| 451 | if (band == BAND_SBAND) { | ||
| 452 | dib0070_set_ctrl_lo5(fe, 2, 4, 3, 0); | ||
| 453 | dib0070_write_reg(state, 0x1d, 0xFFFF); | ||
| 454 | } else | ||
| 455 | dib0070_set_ctrl_lo5(fe, 5, 4, 3, 1); | ||
| 456 | } | ||
| 457 | |||
| 458 | dib0070_write_reg(state, 0x20, | ||
| 459 | 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001 | state->current_tune_table_index->tuner_enable); | ||
| 460 | |||
| 461 | dprintk("REFDIV: %hd, FREF: %d", REFDIV, FREF); | ||
| 462 | dprintk("FBDIV: %d, Rest: %d", FBDiv, Rest); | ||
| 463 | dprintk("Num: %hd, Den: %hd, SD: %hd", (u16) Rest, Den, (state->lo4 >> 12) & 0x1); | ||
| 464 | dprintk("HFDIV code: %hd", state->current_tune_table_index->hfdiv); | ||
| 465 | dprintk("VCO = %hd", state->current_tune_table_index->vco_band); | ||
| 466 | dprintk("VCOF: ((%hd*%d) << 1))", state->current_tune_table_index->vco_multi, freq); | ||
| 467 | |||
| 468 | *tune_state = CT_TUNER_STEP_0; | ||
| 469 | } else { /* we are already tuned to this frequency - the configuration is correct */ | ||
| 470 | ret = 50; /* wakeup time */ | ||
| 471 | *tune_state = CT_TUNER_STEP_5; | ||
| 459 | } | 472 | } |
| 473 | } else if ((*tune_state > CT_TUNER_START) && (*tune_state < CT_TUNER_STEP_4)) { | ||
| 460 | 474 | ||
| 461 | dib0070_write_reg(state, 0x20, | 475 | ret = dib0070_captrim(state, tune_state); |
| 462 | 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001 | state->current_tune_table_index->tuner_enable); | ||
| 463 | |||
| 464 | dprintk("REFDIV: %hd, FREF: %d", REFDIV, FREF); | ||
| 465 | dprintk("FBDIV: %d, Rest: %d", FBDiv, Rest); | ||
| 466 | dprintk("Num: %hd, Den: %hd, SD: %hd", (u16) Rest, Den, (state->lo4 >> 12) & 0x1); | ||
| 467 | dprintk("HFDIV code: %hd", state->current_tune_table_index->hfdiv); | ||
| 468 | dprintk("VCO = %hd", state->current_tune_table_index->vco_band); | ||
| 469 | dprintk("VCOF: ((%hd*%d) << 1))", state->current_tune_table_index->vco_multi, freq); | ||
| 470 | |||
| 471 | *tune_state = CT_TUNER_STEP_0; | ||
| 472 | } else { /* we are already tuned to this frequency - the configuration is correct */ | ||
| 473 | ret = 50; /* wakeup time */ | ||
| 474 | *tune_state = CT_TUNER_STEP_5; | ||
| 475 | } | ||
| 476 | } else if ((*tune_state > CT_TUNER_START) && (*tune_state < CT_TUNER_STEP_4)) { | ||
| 477 | |||
| 478 | ret = dib0070_captrim(state, tune_state); | ||
| 479 | 476 | ||
| 480 | } else if (*tune_state == CT_TUNER_STEP_4) { | 477 | } else if (*tune_state == CT_TUNER_STEP_4) { |
| 481 | const struct dib0070_wbd_gain_cfg *tmp = state->cfg->wbd_gain; | 478 | const struct dib0070_wbd_gain_cfg *tmp = state->cfg->wbd_gain; |
| 482 | if (tmp != NULL) { | 479 | if (tmp != NULL) { |
| 483 | while (freq/1000 > tmp->freq) /* find the right one */ | 480 | while (freq/1000 > tmp->freq) /* find the right one */ |
| 484 | tmp++; | 481 | tmp++; |
| 485 | dib0070_write_reg(state, 0x0f, | ||
| 486 | (0 << 15) | (1 << 14) | (3 << 12) | ||
| 487 | | (tmp->wbd_gain_val << 9) | (0 << 8) | (1 << 7) | ||
| 488 | | (state->current_tune_table_index->wbdmux << 0)); | ||
| 489 | state->wbd_gain_current = tmp->wbd_gain_val; | ||
| 490 | } else { | ||
| 491 | dib0070_write_reg(state, 0x0f, | 482 | dib0070_write_reg(state, 0x0f, |
| 492 | (0 << 15) | (1 << 14) | (3 << 12) | (6 << 9) | (0 << 8) | (1 << 7) | (state->current_tune_table_index-> | 483 | (0 << 15) | (1 << 14) | (3 << 12) |
| 493 | wbdmux << 0)); | 484 | | (tmp->wbd_gain_val << 9) | (0 << 8) | (1 << 7) |
| 494 | state->wbd_gain_current = 6; | 485 | | (state->current_tune_table_index->wbdmux << 0)); |
| 495 | } | 486 | state->wbd_gain_current = tmp->wbd_gain_val; |
| 487 | } else { | ||
| 488 | dib0070_write_reg(state, 0x0f, | ||
| 489 | (0 << 15) | (1 << 14) | (3 << 12) | ||
| 490 | | (6 << 9) | (0 << 8) | (1 << 7) | ||
| 491 | | (state->current_tune_table_index->wbdmux << 0)); | ||
| 492 | state->wbd_gain_current = 6; | ||
| 493 | } | ||
| 496 | 494 | ||
| 497 | dib0070_write_reg(state, 0x06, 0x3fff); | 495 | dib0070_write_reg(state, 0x06, 0x3fff); |
| 498 | dib0070_write_reg(state, 0x07, | 496 | dib0070_write_reg(state, 0x07, |
| 499 | (state->current_tune_table_index->switch_trim << 11) | (7 << 8) | (state->lna_match->lna_band << 3) | (3 << 0)); | 497 | (state->current_tune_table_index->switch_trim << 11) | (7 << 8) | (state->lna_match->lna_band << 3) | (3 << 0)); |
| 500 | dib0070_write_reg(state, 0x08, (state->lna_match->lna_band << 10) | (3 << 7) | (127)); | 498 | dib0070_write_reg(state, 0x08, (state->lna_match->lna_band << 10) | (3 << 7) | (127)); |
| 501 | dib0070_write_reg(state, 0x0d, 0x0d80); | 499 | dib0070_write_reg(state, 0x0d, 0x0d80); |
| 502 | 500 | ||
| 503 | 501 | ||
| 504 | dib0070_write_reg(state, 0x18, 0x07ff); | 502 | dib0070_write_reg(state, 0x18, 0x07ff); |
| 505 | dib0070_write_reg(state, 0x17, 0x0033); | 503 | dib0070_write_reg(state, 0x17, 0x0033); |
| 506 | 504 | ||
| 507 | 505 | ||
| 508 | *tune_state = CT_TUNER_STEP_5; | 506 | *tune_state = CT_TUNER_STEP_5; |
| 509 | } else if (*tune_state == CT_TUNER_STEP_5) { | 507 | } else if (*tune_state == CT_TUNER_STEP_5) { |
| 510 | dib0070_set_bandwidth(fe); | 508 | dib0070_set_bandwidth(fe); |
| 511 | *tune_state = CT_TUNER_STOP; | 509 | *tune_state = CT_TUNER_STOP; |
| 512 | } else { | 510 | } else { |
| 513 | ret = FE_CALLBACK_TIME_NEVER; /* tuner finished, time to call again infinite */ | 511 | ret = FE_CALLBACK_TIME_NEVER; /* tuner finished, time to call again infinite */ |
| 514 | } | 512 | } |
| 515 | return ret; | 513 | return ret; |
| 516 | } | 514 | } |
| 517 | 515 | ||
| 518 | 516 | ||
| 519 | static int dib0070_tune(struct dvb_frontend *fe) | 517 | static int dib0070_tune(struct dvb_frontend *fe) |
| 520 | { | 518 | { |
| 521 | struct dib0070_state *state = fe->tuner_priv; | 519 | struct dib0070_state *state = fe->tuner_priv; |
| 522 | uint32_t ret; | 520 | uint32_t ret; |
| 523 | 521 | ||
| 524 | state->tune_state = CT_TUNER_START; | 522 | state->tune_state = CT_TUNER_START; |
| 525 | 523 | ||
| 526 | do { | 524 | do { |
| 527 | ret = dib0070_tune_digital(fe); | 525 | ret = dib0070_tune_digital(fe); |
| 528 | if (ret != FE_CALLBACK_TIME_NEVER) | 526 | if (ret != FE_CALLBACK_TIME_NEVER) |
| 529 | msleep(ret/10); | 527 | msleep(ret/10); |
| 530 | else | 528 | else |
| 531 | break; | 529 | break; |
| 532 | } while (state->tune_state != CT_TUNER_STOP); | 530 | } while (state->tune_state != CT_TUNER_STOP); |
| 533 | 531 | ||
| 534 | return 0; | 532 | return 0; |
| 535 | } | 533 | } |
| 536 | 534 | ||
| 537 | static int dib0070_wakeup(struct dvb_frontend *fe) | 535 | static int dib0070_wakeup(struct dvb_frontend *fe) |
| @@ -610,48 +608,48 @@ static const u16 dib0070_p1f_defaults[] = | |||
| 610 | 608 | ||
| 611 | static u16 dib0070_read_wbd_offset(struct dib0070_state *state, u8 gain) | 609 | static u16 dib0070_read_wbd_offset(struct dib0070_state *state, u8 gain) |
| 612 | { | 610 | { |
| 613 | u16 tuner_en = dib0070_read_reg(state, 0x20); | 611 | u16 tuner_en = dib0070_read_reg(state, 0x20); |
| 614 | u16 offset; | 612 | u16 offset; |
| 615 | 613 | ||
| 616 | dib0070_write_reg(state, 0x18, 0x07ff); | 614 | dib0070_write_reg(state, 0x18, 0x07ff); |
| 617 | dib0070_write_reg(state, 0x20, 0x0800 | 0x4000 | 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001); | 615 | dib0070_write_reg(state, 0x20, 0x0800 | 0x4000 | 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001); |
| 618 | dib0070_write_reg(state, 0x0f, (1 << 14) | (2 << 12) | (gain << 9) | (1 << 8) | (1 << 7) | (0 << 0)); | 616 | dib0070_write_reg(state, 0x0f, (1 << 14) | (2 << 12) | (gain << 9) | (1 << 8) | (1 << 7) | (0 << 0)); |
| 619 | msleep(9); | 617 | msleep(9); |
| 620 | offset = dib0070_read_reg(state, 0x19); | 618 | offset = dib0070_read_reg(state, 0x19); |
| 621 | dib0070_write_reg(state, 0x20, tuner_en); | 619 | dib0070_write_reg(state, 0x20, tuner_en); |
| 622 | return offset; | 620 | return offset; |
| 623 | } | 621 | } |
| 624 | 622 | ||
| 625 | static void dib0070_wbd_offset_calibration(struct dib0070_state *state) | 623 | static void dib0070_wbd_offset_calibration(struct dib0070_state *state) |
| 626 | { | 624 | { |
| 627 | u8 gain; | 625 | u8 gain; |
| 628 | for (gain = 6; gain < 8; gain++) { | 626 | for (gain = 6; gain < 8; gain++) { |
| 629 | state->wbd_offset_3_3[gain - 6] = ((dib0070_read_wbd_offset(state, gain) * 8 * 18 / 33 + 1) / 2); | 627 | state->wbd_offset_3_3[gain - 6] = ((dib0070_read_wbd_offset(state, gain) * 8 * 18 / 33 + 1) / 2); |
| 630 | dprintk("Gain: %d, WBDOffset (3.3V) = %hd", gain, state->wbd_offset_3_3[gain-6]); | 628 | dprintk("Gain: %d, WBDOffset (3.3V) = %hd", gain, state->wbd_offset_3_3[gain-6]); |
| 631 | } | 629 | } |
| 632 | } | 630 | } |
| 633 | 631 | ||
| 634 | u16 dib0070_wbd_offset(struct dvb_frontend *fe) | 632 | u16 dib0070_wbd_offset(struct dvb_frontend *fe) |
| 635 | { | 633 | { |
| 636 | struct dib0070_state *state = fe->tuner_priv; | 634 | struct dib0070_state *state = fe->tuner_priv; |
| 637 | const struct dib0070_wbd_gain_cfg *tmp = state->cfg->wbd_gain; | 635 | const struct dib0070_wbd_gain_cfg *tmp = state->cfg->wbd_gain; |
| 638 | u32 freq = fe->dtv_property_cache.frequency/1000; | 636 | u32 freq = fe->dtv_property_cache.frequency/1000; |
| 639 | 637 | ||
| 640 | if (tmp != NULL) { | 638 | if (tmp != NULL) { |
| 641 | while (freq/1000 > tmp->freq) /* find the right one */ | 639 | while (freq/1000 > tmp->freq) /* find the right one */ |
| 642 | tmp++; | 640 | tmp++; |
| 643 | state->wbd_gain_current = tmp->wbd_gain_val; | 641 | state->wbd_gain_current = tmp->wbd_gain_val; |
| 644 | } else | 642 | } else |
| 645 | state->wbd_gain_current = 6; | 643 | state->wbd_gain_current = 6; |
| 646 | 644 | ||
| 647 | return state->wbd_offset_3_3[state->wbd_gain_current - 6]; | 645 | return state->wbd_offset_3_3[state->wbd_gain_current - 6]; |
| 648 | } | 646 | } |
| 649 | EXPORT_SYMBOL(dib0070_wbd_offset); | 647 | EXPORT_SYMBOL(dib0070_wbd_offset); |
| 650 | 648 | ||
| 651 | #define pgm_read_word(w) (*w) | 649 | #define pgm_read_word(w) (*w) |
| 652 | static int dib0070_reset(struct dvb_frontend *fe) | 650 | static int dib0070_reset(struct dvb_frontend *fe) |
| 653 | { | 651 | { |
| 654 | struct dib0070_state *state = fe->tuner_priv; | 652 | struct dib0070_state *state = fe->tuner_priv; |
| 655 | u16 l, r, *n; | 653 | u16 l, r, *n; |
| 656 | 654 | ||
| 657 | HARD_RESET(state); | 655 | HARD_RESET(state); |
| @@ -664,7 +662,7 @@ static int dib0070_reset(struct dvb_frontend *fe) | |||
| 664 | #else | 662 | #else |
| 665 | #warning forcing SBAND | 663 | #warning forcing SBAND |
| 666 | #endif | 664 | #endif |
| 667 | state->revision = DIB0070S_P1A; | 665 | state->revision = DIB0070S_P1A; |
| 668 | 666 | ||
| 669 | /* P1F or not */ | 667 | /* P1F or not */ |
| 670 | dprintk("Revision: %x", state->revision); | 668 | dprintk("Revision: %x", state->revision); |
| @@ -703,24 +701,25 @@ static int dib0070_reset(struct dvb_frontend *fe) | |||
| 703 | dib0070_write_reg(state, 0x02, r | (1 << 5)); | 701 | dib0070_write_reg(state, 0x02, r | (1 << 5)); |
| 704 | } | 702 | } |
| 705 | 703 | ||
| 706 | if (state->revision == DIB0070S_P1A) | 704 | if (state->revision == DIB0070S_P1A) |
| 707 | dib0070_set_ctrl_lo5(fe, 2, 4, 3, 0); | 705 | dib0070_set_ctrl_lo5(fe, 2, 4, 3, 0); |
| 708 | else | 706 | else |
| 709 | dib0070_set_ctrl_lo5(fe, 5, 4, state->cfg->charge_pump, state->cfg->enable_third_order_filter); | 707 | dib0070_set_ctrl_lo5(fe, 5, 4, state->cfg->charge_pump, |
| 708 | state->cfg->enable_third_order_filter); | ||
| 710 | 709 | ||
| 711 | dib0070_write_reg(state, 0x01, (54 << 9) | 0xc8); | 710 | dib0070_write_reg(state, 0x01, (54 << 9) | 0xc8); |
| 712 | 711 | ||
| 713 | dib0070_wbd_offset_calibration(state); | 712 | dib0070_wbd_offset_calibration(state); |
| 714 | 713 | ||
| 715 | return 0; | 714 | return 0; |
| 716 | } | 715 | } |
| 717 | 716 | ||
| 718 | static int dib0070_get_frequency(struct dvb_frontend *fe, u32 *frequency) | 717 | static int dib0070_get_frequency(struct dvb_frontend *fe, u32 *frequency) |
| 719 | { | 718 | { |
| 720 | struct dib0070_state *state = fe->tuner_priv; | 719 | struct dib0070_state *state = fe->tuner_priv; |
| 721 | 720 | ||
| 722 | *frequency = 1000 * state->current_rf; | 721 | *frequency = 1000 * state->current_rf; |
| 723 | return 0; | 722 | return 0; |
| 724 | } | 723 | } |
| 725 | 724 | ||
| 726 | static int dib0070_release(struct dvb_frontend *fe) | 725 | static int dib0070_release(struct dvb_frontend *fe) |
