diff options
Diffstat (limited to 'drivers/media/dvb/frontends')
22 files changed, 714 insertions, 245 deletions
diff --git a/drivers/media/dvb/frontends/af9013.h b/drivers/media/dvb/frontends/af9013.h index 28b90c91c766..e90fa92b1c1d 100644 --- a/drivers/media/dvb/frontends/af9013.h +++ b/drivers/media/dvb/frontends/af9013.h | |||
@@ -44,6 +44,7 @@ enum af9013_tuner { | |||
44 | AF9013_TUNER_MT2060_2 = 147, /* Microtune */ | 44 | AF9013_TUNER_MT2060_2 = 147, /* Microtune */ |
45 | AF9013_TUNER_TDA18271 = 156, /* NXP */ | 45 | AF9013_TUNER_TDA18271 = 156, /* NXP */ |
46 | AF9013_TUNER_QT1010A = 162, /* Quantek */ | 46 | AF9013_TUNER_QT1010A = 162, /* Quantek */ |
47 | AF9013_TUNER_TDA18218 = 179, /* NXP */ | ||
47 | }; | 48 | }; |
48 | 49 | ||
49 | /* AF9013/5 GPIOs (mostly guessed) | 50 | /* AF9013/5 GPIOs (mostly guessed) |
diff --git a/drivers/media/dvb/frontends/atbm8830.c b/drivers/media/dvb/frontends/atbm8830.c index 59881a5944eb..43aac2f85c2e 100644 --- a/drivers/media/dvb/frontends/atbm8830.c +++ b/drivers/media/dvb/frontends/atbm8830.c | |||
@@ -170,6 +170,19 @@ static int is_locked(struct atbm_state *priv, u8 *locked) | |||
170 | return 0; | 170 | return 0; |
171 | } | 171 | } |
172 | 172 | ||
173 | static int set_agc_config(struct atbm_state *priv, | ||
174 | u8 min, u8 max, u8 hold_loop) | ||
175 | { | ||
176 | /* no effect if both min and max are zero */ | ||
177 | if (!min && !max) | ||
178 | return 0; | ||
179 | |||
180 | atbm8830_write_reg(priv, REG_AGC_MIN, min); | ||
181 | atbm8830_write_reg(priv, REG_AGC_MAX, max); | ||
182 | atbm8830_write_reg(priv, REG_AGC_HOLD_LOOP, hold_loop); | ||
183 | |||
184 | return 0; | ||
185 | } | ||
173 | 186 | ||
174 | static int set_static_channel_mode(struct atbm_state *priv) | 187 | static int set_static_channel_mode(struct atbm_state *priv) |
175 | { | 188 | { |
@@ -227,6 +240,9 @@ static int atbm8830_init(struct dvb_frontend *fe) | |||
227 | /*Set IF frequency*/ | 240 | /*Set IF frequency*/ |
228 | set_if_freq(priv, cfg->if_freq); | 241 | set_if_freq(priv, cfg->if_freq); |
229 | 242 | ||
243 | /*Set AGC Config*/ | ||
244 | set_agc_config(priv, cfg->agc_min, cfg->agc_max, | ||
245 | cfg->agc_hold_loop); | ||
230 | 246 | ||
231 | /*Set static channel mode*/ | 247 | /*Set static channel mode*/ |
232 | set_static_channel_mode(priv); | 248 | set_static_channel_mode(priv); |
diff --git a/drivers/media/dvb/frontends/dib0090.c b/drivers/media/dvb/frontends/dib0090.c index 614552709a6f..7eac178f57b2 100644 --- a/drivers/media/dvb/frontends/dib0090.c +++ b/drivers/media/dvb/frontends/dib0090.c | |||
@@ -283,7 +283,7 @@ static int dib0090_sleep(struct dvb_frontend *fe) | |||
283 | return 0; | 283 | return 0; |
284 | } | 284 | } |
285 | 285 | ||
286 | extern void dib0090_dcc_freq(struct dvb_frontend *fe, u8 fast) | 286 | void dib0090_dcc_freq(struct dvb_frontend *fe, u8 fast) |
287 | { | 287 | { |
288 | struct dib0090_state *state = fe->tuner_priv; | 288 | struct dib0090_state *state = fe->tuner_priv; |
289 | if (fast) | 289 | if (fast) |
diff --git a/drivers/media/dvb/frontends/dib8000.c b/drivers/media/dvb/frontends/dib8000.c index 6f6fa29d9ea4..2aa97dd6a8af 100644 --- a/drivers/media/dvb/frontends/dib8000.c +++ b/drivers/media/dvb/frontends/dib8000.c | |||
@@ -1999,6 +1999,8 @@ static int dib8000_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_par | |||
1999 | struct dib8000_state *state = fe->demodulator_priv; | 1999 | struct dib8000_state *state = fe->demodulator_priv; |
2000 | int time, ret; | 2000 | int time, ret; |
2001 | 2001 | ||
2002 | fe->dtv_property_cache.delivery_system = SYS_ISDBT; | ||
2003 | |||
2002 | dib8000_set_output_mode(state, OUTMODE_HIGH_Z); | 2004 | dib8000_set_output_mode(state, OUTMODE_HIGH_Z); |
2003 | 2005 | ||
2004 | if (fe->ops.tuner_ops.set_params) | 2006 | if (fe->ops.tuner_ops.set_params) |
diff --git a/drivers/media/dvb/frontends/dibx000_common.c b/drivers/media/dvb/frontends/dibx000_common.c index e6f3d73db9d3..980e02f1575e 100644 --- a/drivers/media/dvb/frontends/dibx000_common.c +++ b/drivers/media/dvb/frontends/dibx000_common.c | |||
@@ -174,7 +174,7 @@ void dibx000_exit_i2c_master(struct dibx000_i2c_master *mst) | |||
174 | EXPORT_SYMBOL(dibx000_exit_i2c_master); | 174 | EXPORT_SYMBOL(dibx000_exit_i2c_master); |
175 | 175 | ||
176 | 176 | ||
177 | u32 systime() | 177 | u32 systime(void) |
178 | { | 178 | { |
179 | struct timespec t; | 179 | struct timespec t; |
180 | 180 | ||
diff --git a/drivers/media/dvb/frontends/lnbp21.c b/drivers/media/dvb/frontends/lnbp21.c index b181bf023ada..13437259eeac 100644 --- a/drivers/media/dvb/frontends/lnbp21.c +++ b/drivers/media/dvb/frontends/lnbp21.c | |||
@@ -158,7 +158,8 @@ static struct dvb_frontend *lnbx2x_attach(struct dvb_frontend *fe, | |||
158 | /* override frontend ops */ | 158 | /* override frontend ops */ |
159 | fe->ops.set_voltage = lnbp21_set_voltage; | 159 | fe->ops.set_voltage = lnbp21_set_voltage; |
160 | fe->ops.enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage; | 160 | fe->ops.enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage; |
161 | fe->ops.set_tone = lnbp21_set_tone; | 161 | if (!(override_clear & LNBH24_TEN)) /*22kHz logic controlled by demod*/ |
162 | fe->ops.set_tone = lnbp21_set_tone; | ||
162 | printk(KERN_INFO "LNBx2x attached on addr=%x\n", lnbp21->i2c_addr); | 163 | printk(KERN_INFO "LNBx2x attached on addr=%x\n", lnbp21->i2c_addr); |
163 | 164 | ||
164 | return fe; | 165 | return fe; |
diff --git a/drivers/media/dvb/frontends/si21xx.c b/drivers/media/dvb/frontends/si21xx.c index 9552a22ccffb..d21a327db629 100644 --- a/drivers/media/dvb/frontends/si21xx.c +++ b/drivers/media/dvb/frontends/si21xx.c | |||
@@ -97,8 +97,6 @@ | |||
97 | #define LNB_SUPPLY_CTRL_REG_4 0xce | 97 | #define LNB_SUPPLY_CTRL_REG_4 0xce |
98 | #define LNB_SUPPLY_STATUS_REG 0xcf | 98 | #define LNB_SUPPLY_STATUS_REG 0xcf |
99 | 99 | ||
100 | #define FALSE 0 | ||
101 | #define TRUE 1 | ||
102 | #define FAIL -1 | 100 | #define FAIL -1 |
103 | #define PASS 0 | 101 | #define PASS 0 |
104 | 102 | ||
@@ -718,7 +716,7 @@ static int si21xx_set_frontend(struct dvb_frontend *fe, | |||
718 | int fine_tune_freq; | 716 | int fine_tune_freq; |
719 | unsigned char sample_rate = 0; | 717 | unsigned char sample_rate = 0; |
720 | /* boolean */ | 718 | /* boolean */ |
721 | unsigned int inband_interferer_ind; | 719 | bool inband_interferer_ind; |
722 | 720 | ||
723 | /* INTERMEDIATE VALUES */ | 721 | /* INTERMEDIATE VALUES */ |
724 | int icoarse_tune_freq; /* MHz */ | 722 | int icoarse_tune_freq; /* MHz */ |
@@ -728,15 +726,8 @@ static int si21xx_set_frontend(struct dvb_frontend *fe, | |||
728 | unsigned int x1; | 726 | unsigned int x1; |
729 | unsigned int x2; | 727 | unsigned int x2; |
730 | int i; | 728 | int i; |
731 | unsigned int inband_interferer_div2[ALLOWABLE_FS_COUNT] = { | 729 | bool inband_interferer_div2[ALLOWABLE_FS_COUNT]; |
732 | FALSE, FALSE, FALSE, FALSE, FALSE, | 730 | bool inband_interferer_div4[ALLOWABLE_FS_COUNT]; |
733 | FALSE, FALSE, FALSE, FALSE, FALSE | ||
734 | }; | ||
735 | unsigned int inband_interferer_div4[ALLOWABLE_FS_COUNT] = { | ||
736 | FALSE, FALSE, FALSE, FALSE, FALSE, | ||
737 | FALSE, FALSE, FALSE, FALSE, FALSE | ||
738 | }; | ||
739 | |||
740 | int status; | 731 | int status; |
741 | 732 | ||
742 | /* allowable sample rates for ADC in MHz */ | 733 | /* allowable sample rates for ADC in MHz */ |
@@ -762,7 +753,7 @@ static int si21xx_set_frontend(struct dvb_frontend *fe, | |||
762 | } | 753 | } |
763 | 754 | ||
764 | for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) | 755 | for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) |
765 | inband_interferer_div2[i] = inband_interferer_div4[i] = FALSE; | 756 | inband_interferer_div2[i] = inband_interferer_div4[i] = false; |
766 | 757 | ||
767 | if_limit_high = -700000; | 758 | if_limit_high = -700000; |
768 | if_limit_low = -100000; | 759 | if_limit_low = -100000; |
@@ -798,7 +789,7 @@ static int si21xx_set_frontend(struct dvb_frontend *fe, | |||
798 | 789 | ||
799 | if (((band_low < x1) && (x1 < band_high)) || | 790 | if (((band_low < x1) && (x1 < band_high)) || |
800 | ((band_low < x2) && (x2 < band_high))) | 791 | ((band_low < x2) && (x2 < band_high))) |
801 | inband_interferer_div4[i] = TRUE; | 792 | inband_interferer_div4[i] = true; |
802 | 793 | ||
803 | } | 794 | } |
804 | 795 | ||
@@ -811,25 +802,28 @@ static int si21xx_set_frontend(struct dvb_frontend *fe, | |||
811 | 802 | ||
812 | if (((band_low < x1) && (x1 < band_high)) || | 803 | if (((band_low < x1) && (x1 < band_high)) || |
813 | ((band_low < x2) && (x2 < band_high))) | 804 | ((band_low < x2) && (x2 < band_high))) |
814 | inband_interferer_div2[i] = TRUE; | 805 | inband_interferer_div2[i] = true; |
815 | } | 806 | } |
816 | 807 | ||
817 | inband_interferer_ind = TRUE; | 808 | inband_interferer_ind = true; |
818 | for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) | 809 | for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) { |
819 | inband_interferer_ind &= inband_interferer_div2[i] | | 810 | if (inband_interferer_div2[i] || inband_interferer_div4[i]) { |
820 | inband_interferer_div4[i]; | 811 | inband_interferer_ind = false; |
812 | break; | ||
813 | } | ||
814 | } | ||
821 | 815 | ||
822 | if (inband_interferer_ind) { | 816 | if (inband_interferer_ind) { |
823 | for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) { | 817 | for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) { |
824 | if (inband_interferer_div2[i] == FALSE) { | 818 | if (!inband_interferer_div2[i]) { |
825 | sample_rate = (u8) afs[i]; | 819 | sample_rate = (u8) afs[i]; |
826 | break; | 820 | break; |
827 | } | 821 | } |
828 | } | 822 | } |
829 | } else { | 823 | } else { |
830 | for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) { | 824 | for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) { |
831 | if ((inband_interferer_div2[i] | | 825 | if ((inband_interferer_div2[i] || |
832 | inband_interferer_div4[i]) == FALSE) { | 826 | !inband_interferer_div4[i])) { |
833 | sample_rate = (u8) afs[i]; | 827 | sample_rate = (u8) afs[i]; |
834 | break; | 828 | break; |
835 | } | 829 | } |
diff --git a/drivers/media/dvb/frontends/stv0900.h b/drivers/media/dvb/frontends/stv0900.h index 29c3fa85c227..e3e35d1ce838 100644 --- a/drivers/media/dvb/frontends/stv0900.h +++ b/drivers/media/dvb/frontends/stv0900.h | |||
@@ -49,6 +49,8 @@ struct stv0900_config { | |||
49 | u8 tun2_maddress; | 49 | u8 tun2_maddress; |
50 | u8 tun1_adc;/* 1 for stv6110, 2 for stb6100 */ | 50 | u8 tun1_adc;/* 1 for stv6110, 2 for stb6100 */ |
51 | u8 tun2_adc; | 51 | u8 tun2_adc; |
52 | u8 tun1_type;/* for now 3 for stb6100 auto, else - software */ | ||
53 | u8 tun2_type; | ||
52 | /* Set device param to start dma */ | 54 | /* Set device param to start dma */ |
53 | int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured); | 55 | int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured); |
54 | }; | 56 | }; |
diff --git a/drivers/media/dvb/frontends/stv0900_core.c b/drivers/media/dvb/frontends/stv0900_core.c index 8762c86044a5..01f8f1f802fd 100644 --- a/drivers/media/dvb/frontends/stv0900_core.c +++ b/drivers/media/dvb/frontends/stv0900_core.c | |||
@@ -177,7 +177,7 @@ u8 stv0900_read_reg(struct stv0900_internal *intp, u16 reg) | |||
177 | return buf; | 177 | return buf; |
178 | } | 178 | } |
179 | 179 | ||
180 | void extract_mask_pos(u32 label, u8 *mask, u8 *pos) | 180 | static void extract_mask_pos(u32 label, u8 *mask, u8 *pos) |
181 | { | 181 | { |
182 | u8 position = 0, i = 0; | 182 | u8 position = 0, i = 0; |
183 | 183 | ||
@@ -218,7 +218,7 @@ u8 stv0900_get_bits(struct stv0900_internal *intp, u32 label) | |||
218 | return val; | 218 | return val; |
219 | } | 219 | } |
220 | 220 | ||
221 | enum fe_stv0900_error stv0900_initialize(struct stv0900_internal *intp) | 221 | static enum fe_stv0900_error stv0900_initialize(struct stv0900_internal *intp) |
222 | { | 222 | { |
223 | s32 i; | 223 | s32 i; |
224 | 224 | ||
@@ -282,7 +282,7 @@ enum fe_stv0900_error stv0900_initialize(struct stv0900_internal *intp) | |||
282 | return STV0900_NO_ERROR; | 282 | return STV0900_NO_ERROR; |
283 | } | 283 | } |
284 | 284 | ||
285 | u32 stv0900_get_mclk_freq(struct stv0900_internal *intp, u32 ext_clk) | 285 | static u32 stv0900_get_mclk_freq(struct stv0900_internal *intp, u32 ext_clk) |
286 | { | 286 | { |
287 | u32 mclk = 90000000, div = 0, ad_div = 0; | 287 | u32 mclk = 90000000, div = 0, ad_div = 0; |
288 | 288 | ||
@@ -296,7 +296,7 @@ u32 stv0900_get_mclk_freq(struct stv0900_internal *intp, u32 ext_clk) | |||
296 | return mclk; | 296 | return mclk; |
297 | } | 297 | } |
298 | 298 | ||
299 | enum fe_stv0900_error stv0900_set_mclk(struct stv0900_internal *intp, u32 mclk) | 299 | static enum fe_stv0900_error stv0900_set_mclk(struct stv0900_internal *intp, u32 mclk) |
300 | { | 300 | { |
301 | u32 m_div, clk_sel; | 301 | u32 m_div, clk_sel; |
302 | 302 | ||
@@ -334,7 +334,7 @@ enum fe_stv0900_error stv0900_set_mclk(struct stv0900_internal *intp, u32 mclk) | |||
334 | return STV0900_NO_ERROR; | 334 | return STV0900_NO_ERROR; |
335 | } | 335 | } |
336 | 336 | ||
337 | u32 stv0900_get_err_count(struct stv0900_internal *intp, int cntr, | 337 | static u32 stv0900_get_err_count(struct stv0900_internal *intp, int cntr, |
338 | enum fe_stv0900_demod_num demod) | 338 | enum fe_stv0900_demod_num demod) |
339 | { | 339 | { |
340 | u32 lsb, msb, hsb, err_val; | 340 | u32 lsb, msb, hsb, err_val; |
@@ -567,6 +567,46 @@ void stv0900_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth) | |||
567 | } | 567 | } |
568 | } | 568 | } |
569 | 569 | ||
570 | u32 stv0900_get_freq_auto(struct stv0900_internal *intp, int demod) | ||
571 | { | ||
572 | u32 freq, round; | ||
573 | /* Formulat : | ||
574 | Tuner_Frequency(MHz) = Regs / 64 | ||
575 | Tuner_granularity(MHz) = Regs / 2048 | ||
576 | real_Tuner_Frequency = Tuner_Frequency(MHz) - Tuner_granularity(MHz) | ||
577 | */ | ||
578 | freq = (stv0900_get_bits(intp, TUN_RFFREQ2) << 10) + | ||
579 | (stv0900_get_bits(intp, TUN_RFFREQ1) << 2) + | ||
580 | stv0900_get_bits(intp, TUN_RFFREQ0); | ||
581 | |||
582 | freq = (freq * 1000) / 64; | ||
583 | |||
584 | round = (stv0900_get_bits(intp, TUN_RFRESTE1) >> 2) + | ||
585 | stv0900_get_bits(intp, TUN_RFRESTE0); | ||
586 | |||
587 | round = (round * 1000) / 2048; | ||
588 | |||
589 | return freq + round; | ||
590 | } | ||
591 | |||
592 | void stv0900_set_tuner_auto(struct stv0900_internal *intp, u32 Frequency, | ||
593 | u32 Bandwidth, int demod) | ||
594 | { | ||
595 | u32 tunerFrequency; | ||
596 | /* Formulat: | ||
597 | Tuner_frequency_reg= Frequency(MHz)*64 | ||
598 | */ | ||
599 | tunerFrequency = (Frequency * 64) / 1000; | ||
600 | |||
601 | stv0900_write_bits(intp, TUN_RFFREQ2, (tunerFrequency >> 10)); | ||
602 | stv0900_write_bits(intp, TUN_RFFREQ1, (tunerFrequency >> 2) & 0xff); | ||
603 | stv0900_write_bits(intp, TUN_RFFREQ0, (tunerFrequency & 0x03)); | ||
604 | /* Low Pass Filter = BW /2 (MHz)*/ | ||
605 | stv0900_write_bits(intp, TUN_BW, Bandwidth / 2000000); | ||
606 | /* Tuner Write trig */ | ||
607 | stv0900_write_reg(intp, TNRLD, 1); | ||
608 | } | ||
609 | |||
570 | static s32 stv0900_get_rf_level(struct stv0900_internal *intp, | 610 | static s32 stv0900_get_rf_level(struct stv0900_internal *intp, |
571 | const struct stv0900_table *lookup, | 611 | const struct stv0900_table *lookup, |
572 | enum fe_stv0900_demod_num demod) | 612 | enum fe_stv0900_demod_num demod) |
@@ -1329,7 +1369,6 @@ static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe, | |||
1329 | enum fe_stv0900_error error = STV0900_NO_ERROR; | 1369 | enum fe_stv0900_error error = STV0900_NO_ERROR; |
1330 | enum fe_stv0900_error demodError = STV0900_NO_ERROR; | 1370 | enum fe_stv0900_error demodError = STV0900_NO_ERROR; |
1331 | struct stv0900_internal *intp = NULL; | 1371 | struct stv0900_internal *intp = NULL; |
1332 | |||
1333 | int selosci, i; | 1372 | int selosci, i; |
1334 | 1373 | ||
1335 | struct stv0900_inode *temp_int = find_inode(state->i2c_adap, | 1374 | struct stv0900_inode *temp_int = find_inode(state->i2c_adap, |
@@ -1345,7 +1384,14 @@ static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe, | |||
1345 | } else { | 1384 | } else { |
1346 | state->internal = kmalloc(sizeof(struct stv0900_internal), | 1385 | state->internal = kmalloc(sizeof(struct stv0900_internal), |
1347 | GFP_KERNEL); | 1386 | GFP_KERNEL); |
1387 | if (state->internal == NULL) | ||
1388 | return STV0900_INVALID_HANDLE; | ||
1348 | temp_int = append_internal(state->internal); | 1389 | temp_int = append_internal(state->internal); |
1390 | if (temp_int == NULL) { | ||
1391 | kfree(state->internal); | ||
1392 | state->internal = NULL; | ||
1393 | return STV0900_INVALID_HANDLE; | ||
1394 | } | ||
1349 | state->internal->dmds_used = 1; | 1395 | state->internal->dmds_used = 1; |
1350 | state->internal->i2c_adap = state->i2c_adap; | 1396 | state->internal->i2c_adap = state->i2c_adap; |
1351 | state->internal->i2c_addr = state->config->demod_address; | 1397 | state->internal->i2c_addr = state->config->demod_address; |
@@ -1371,11 +1417,6 @@ static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe, | |||
1371 | return error; | 1417 | return error; |
1372 | } | 1418 | } |
1373 | 1419 | ||
1374 | if (state->internal == NULL) { | ||
1375 | error = STV0900_INVALID_HANDLE; | ||
1376 | return error; | ||
1377 | } | ||
1378 | |||
1379 | intp = state->internal; | 1420 | intp = state->internal; |
1380 | 1421 | ||
1381 | intp->demod_mode = p_init->demod_mode; | 1422 | intp->demod_mode = p_init->demod_mode; |
@@ -1404,6 +1445,27 @@ static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe, | |||
1404 | stv0900_write_bits(intp, F0900_P1_RST_HWARE, 0); | 1445 | stv0900_write_bits(intp, F0900_P1_RST_HWARE, 0); |
1405 | } | 1446 | } |
1406 | 1447 | ||
1448 | intp->tuner_type[0] = p_init->tuner1_type; | ||
1449 | intp->tuner_type[1] = p_init->tuner2_type; | ||
1450 | /* tuner init */ | ||
1451 | switch (p_init->tuner1_type) { | ||
1452 | case 3: /*FE_AUTO_STB6100:*/ | ||
1453 | stv0900_write_reg(intp, R0900_P1_TNRCFG, 0x3c); | ||
1454 | stv0900_write_reg(intp, R0900_P1_TNRCFG2, 0x86); | ||
1455 | stv0900_write_reg(intp, R0900_P1_TNRCFG3, 0x18); | ||
1456 | stv0900_write_reg(intp, R0900_P1_TNRXTAL, 27); /* 27MHz */ | ||
1457 | stv0900_write_reg(intp, R0900_P1_TNRSTEPS, 0x05); | ||
1458 | stv0900_write_reg(intp, R0900_P1_TNRGAIN, 0x17); | ||
1459 | stv0900_write_reg(intp, R0900_P1_TNRADJ, 0x1f); | ||
1460 | stv0900_write_reg(intp, R0900_P1_TNRCTL2, 0x0); | ||
1461 | stv0900_write_bits(intp, F0900_P1_TUN_TYPE, 3); | ||
1462 | break; | ||
1463 | /* case FE_SW_TUNER: */ | ||
1464 | default: | ||
1465 | stv0900_write_bits(intp, F0900_P1_TUN_TYPE, 6); | ||
1466 | break; | ||
1467 | } | ||
1468 | |||
1407 | stv0900_write_bits(intp, F0900_P1_TUN_MADDRESS, p_init->tun1_maddress); | 1469 | stv0900_write_bits(intp, F0900_P1_TUN_MADDRESS, p_init->tun1_maddress); |
1408 | switch (p_init->tuner1_adc) { | 1470 | switch (p_init->tuner1_adc) { |
1409 | case 1: | 1471 | case 1: |
@@ -1413,6 +1475,27 @@ static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe, | |||
1413 | break; | 1475 | break; |
1414 | } | 1476 | } |
1415 | 1477 | ||
1478 | stv0900_write_reg(intp, R0900_P1_TNRLD, 1); /* hw tuner */ | ||
1479 | |||
1480 | /* tuner init */ | ||
1481 | switch (p_init->tuner2_type) { | ||
1482 | case 3: /*FE_AUTO_STB6100:*/ | ||
1483 | stv0900_write_reg(intp, R0900_P2_TNRCFG, 0x3c); | ||
1484 | stv0900_write_reg(intp, R0900_P2_TNRCFG2, 0x86); | ||
1485 | stv0900_write_reg(intp, R0900_P2_TNRCFG3, 0x18); | ||
1486 | stv0900_write_reg(intp, R0900_P2_TNRXTAL, 27); /* 27MHz */ | ||
1487 | stv0900_write_reg(intp, R0900_P2_TNRSTEPS, 0x05); | ||
1488 | stv0900_write_reg(intp, R0900_P2_TNRGAIN, 0x17); | ||
1489 | stv0900_write_reg(intp, R0900_P2_TNRADJ, 0x1f); | ||
1490 | stv0900_write_reg(intp, R0900_P2_TNRCTL2, 0x0); | ||
1491 | stv0900_write_bits(intp, F0900_P2_TUN_TYPE, 3); | ||
1492 | break; | ||
1493 | /* case FE_SW_TUNER: */ | ||
1494 | default: | ||
1495 | stv0900_write_bits(intp, F0900_P2_TUN_TYPE, 6); | ||
1496 | break; | ||
1497 | } | ||
1498 | |||
1416 | stv0900_write_bits(intp, F0900_P2_TUN_MADDRESS, p_init->tun2_maddress); | 1499 | stv0900_write_bits(intp, F0900_P2_TUN_MADDRESS, p_init->tun2_maddress); |
1417 | switch (p_init->tuner2_adc) { | 1500 | switch (p_init->tuner2_adc) { |
1418 | case 1: | 1501 | case 1: |
@@ -1422,6 +1505,8 @@ static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe, | |||
1422 | break; | 1505 | break; |
1423 | } | 1506 | } |
1424 | 1507 | ||
1508 | stv0900_write_reg(intp, R0900_P2_TNRLD, 1); /* hw tuner */ | ||
1509 | |||
1425 | stv0900_write_bits(intp, F0900_P1_TUN_IQSWAP, p_init->tun1_iq_inv); | 1510 | stv0900_write_bits(intp, F0900_P1_TUN_IQSWAP, p_init->tun1_iq_inv); |
1426 | stv0900_write_bits(intp, F0900_P2_TUN_IQSWAP, p_init->tun2_iq_inv); | 1511 | stv0900_write_bits(intp, F0900_P2_TUN_IQSWAP, p_init->tun2_iq_inv); |
1427 | stv0900_set_mclk(intp, 135000000); | 1512 | stv0900_set_mclk(intp, 135000000); |
@@ -1824,10 +1909,12 @@ struct dvb_frontend *stv0900_attach(const struct stv0900_config *config, | |||
1824 | init_params.tun1_maddress = config->tun1_maddress; | 1909 | init_params.tun1_maddress = config->tun1_maddress; |
1825 | init_params.tun1_iq_inv = STV0900_IQ_NORMAL; | 1910 | init_params.tun1_iq_inv = STV0900_IQ_NORMAL; |
1826 | init_params.tuner1_adc = config->tun1_adc; | 1911 | init_params.tuner1_adc = config->tun1_adc; |
1912 | init_params.tuner1_type = config->tun1_type; | ||
1827 | init_params.path2_ts_clock = config->path2_mode; | 1913 | init_params.path2_ts_clock = config->path2_mode; |
1828 | init_params.ts_config = config->ts_config_regs; | 1914 | init_params.ts_config = config->ts_config_regs; |
1829 | init_params.tun2_maddress = config->tun2_maddress; | 1915 | init_params.tun2_maddress = config->tun2_maddress; |
1830 | init_params.tuner2_adc = config->tun2_adc; | 1916 | init_params.tuner2_adc = config->tun2_adc; |
1917 | init_params.tuner2_type = config->tun2_type; | ||
1831 | init_params.tun2_iq_inv = STV0900_IQ_SWAPPED; | 1918 | init_params.tun2_iq_inv = STV0900_IQ_SWAPPED; |
1832 | 1919 | ||
1833 | err_stv0900 = stv0900_init_internal(&state->frontend, | 1920 | err_stv0900 = stv0900_init_internal(&state->frontend, |
diff --git a/drivers/media/dvb/frontends/stv0900_priv.h b/drivers/media/dvb/frontends/stv0900_priv.h index d8ba8a984abe..b62b0f0a4fef 100644 --- a/drivers/media/dvb/frontends/stv0900_priv.h +++ b/drivers/media/dvb/frontends/stv0900_priv.h | |||
@@ -247,6 +247,7 @@ struct stv0900_init_params{ | |||
247 | 247 | ||
248 | u8 tun1_maddress; | 248 | u8 tun1_maddress; |
249 | int tuner1_adc; | 249 | int tuner1_adc; |
250 | int tuner1_type; | ||
250 | 251 | ||
251 | /* IQ from the tuner1 to the demod */ | 252 | /* IQ from the tuner1 to the demod */ |
252 | enum stv0900_iq_inversion tun1_iq_inv; | 253 | enum stv0900_iq_inversion tun1_iq_inv; |
@@ -254,6 +255,7 @@ struct stv0900_init_params{ | |||
254 | 255 | ||
255 | u8 tun2_maddress; | 256 | u8 tun2_maddress; |
256 | int tuner2_adc; | 257 | int tuner2_adc; |
258 | int tuner2_type; | ||
257 | 259 | ||
258 | /* IQ from the tuner2 to the demod */ | 260 | /* IQ from the tuner2 to the demod */ |
259 | enum stv0900_iq_inversion tun2_iq_inv; | 261 | enum stv0900_iq_inversion tun2_iq_inv; |
@@ -309,6 +311,8 @@ struct stv0900_internal{ | |||
309 | s32 bw[2]; | 311 | s32 bw[2]; |
310 | s32 symbol_rate[2]; | 312 | s32 symbol_rate[2]; |
311 | s32 srch_range[2]; | 313 | s32 srch_range[2]; |
314 | /* for software/auto tuner */ | ||
315 | int tuner_type[2]; | ||
312 | 316 | ||
313 | /* algorithm for search Blind, Cold or Warm*/ | 317 | /* algorithm for search Blind, Cold or Warm*/ |
314 | enum fe_stv0900_search_algo srch_algo[2]; | 318 | enum fe_stv0900_search_algo srch_algo[2]; |
@@ -394,4 +398,11 @@ extern enum | |||
394 | fe_stv0900_tracking_standard stv0900_get_standard(struct dvb_frontend *fe, | 398 | fe_stv0900_tracking_standard stv0900_get_standard(struct dvb_frontend *fe, |
395 | enum fe_stv0900_demod_num demod); | 399 | enum fe_stv0900_demod_num demod); |
396 | 400 | ||
401 | extern u32 | ||
402 | stv0900_get_freq_auto(struct stv0900_internal *intp, int demod); | ||
403 | |||
404 | extern void | ||
405 | stv0900_set_tuner_auto(struct stv0900_internal *intp, u32 Frequency, | ||
406 | u32 Bandwidth, int demod); | ||
407 | |||
397 | #endif | 408 | #endif |
diff --git a/drivers/media/dvb/frontends/stv0900_reg.h b/drivers/media/dvb/frontends/stv0900_reg.h index 7b8edf192e97..731afe93a823 100644 --- a/drivers/media/dvb/frontends/stv0900_reg.h +++ b/drivers/media/dvb/frontends/stv0900_reg.h | |||
@@ -3174,17 +3174,21 @@ extern s32 shiftx(s32 x, int demod, s32 shift); | |||
3174 | #define R0900_P1_TNRRF1 0xf4e9 | 3174 | #define R0900_P1_TNRRF1 0xf4e9 |
3175 | #define TNRRF1 REGx(R0900_P1_TNRRF1) | 3175 | #define TNRRF1 REGx(R0900_P1_TNRRF1) |
3176 | #define F0900_P1_TUN_RFFREQ2 0xf4e900ff | 3176 | #define F0900_P1_TUN_RFFREQ2 0xf4e900ff |
3177 | #define TUN_RFFREQ2 FLDx(F0900_P1_TUN_RFFREQ2) | ||
3177 | 3178 | ||
3178 | /*P1_TNRRF0*/ | 3179 | /*P1_TNRRF0*/ |
3179 | #define R0900_P1_TNRRF0 0xf4ea | 3180 | #define R0900_P1_TNRRF0 0xf4ea |
3180 | #define TNRRF0 REGx(R0900_P1_TNRRF0) | 3181 | #define TNRRF0 REGx(R0900_P1_TNRRF0) |
3181 | #define F0900_P1_TUN_RFFREQ1 0xf4ea00ff | 3182 | #define F0900_P1_TUN_RFFREQ1 0xf4ea00ff |
3183 | #define TUN_RFFREQ1 FLDx(F0900_P1_TUN_RFFREQ1) | ||
3182 | 3184 | ||
3183 | /*P1_TNRBW*/ | 3185 | /*P1_TNRBW*/ |
3184 | #define R0900_P1_TNRBW 0xf4eb | 3186 | #define R0900_P1_TNRBW 0xf4eb |
3185 | #define TNRBW REGx(R0900_P1_TNRBW) | 3187 | #define TNRBW REGx(R0900_P1_TNRBW) |
3186 | #define F0900_P1_TUN_RFFREQ0 0xf4eb00c0 | 3188 | #define F0900_P1_TUN_RFFREQ0 0xf4eb00c0 |
3189 | #define TUN_RFFREQ0 FLDx(F0900_P1_TUN_RFFREQ0) | ||
3187 | #define F0900_P1_TUN_BW 0xf4eb003f | 3190 | #define F0900_P1_TUN_BW 0xf4eb003f |
3191 | #define TUN_BW FLDx(F0900_P1_TUN_BW) | ||
3188 | 3192 | ||
3189 | /*P1_TNRADJ*/ | 3193 | /*P1_TNRADJ*/ |
3190 | #define R0900_P1_TNRADJ 0xf4ec | 3194 | #define R0900_P1_TNRADJ 0xf4ec |
@@ -3234,11 +3238,13 @@ extern s32 shiftx(s32 x, int demod, s32 shift); | |||
3234 | #define F0900_P1_TUN_I2CLOCKED 0xf4f60010 | 3238 | #define F0900_P1_TUN_I2CLOCKED 0xf4f60010 |
3235 | #define F0900_P1_TUN_PROGDONE 0xf4f6000c | 3239 | #define F0900_P1_TUN_PROGDONE 0xf4f6000c |
3236 | #define F0900_P1_TUN_RFRESTE1 0xf4f60003 | 3240 | #define F0900_P1_TUN_RFRESTE1 0xf4f60003 |
3241 | #define TUN_RFRESTE1 FLDx(F0900_P1_TUN_RFRESTE1) | ||
3237 | 3242 | ||
3238 | /*P1_TNRRESTE*/ | 3243 | /*P1_TNRRESTE*/ |
3239 | #define R0900_P1_TNRRESTE 0xf4f7 | 3244 | #define R0900_P1_TNRRESTE 0xf4f7 |
3240 | #define TNRRESTE REGx(R0900_P1_TNRRESTE) | 3245 | #define TNRRESTE REGx(R0900_P1_TNRRESTE) |
3241 | #define F0900_P1_TUN_RFRESTE0 0xf4f700ff | 3246 | #define F0900_P1_TUN_RFRESTE0 0xf4f700ff |
3247 | #define TUN_RFRESTE0 FLDx(F0900_P1_TUN_RFRESTE0) | ||
3242 | 3248 | ||
3243 | /*P1_SMAPCOEF7*/ | 3249 | /*P1_SMAPCOEF7*/ |
3244 | #define R0900_P1_SMAPCOEF7 0xf500 | 3250 | #define R0900_P1_SMAPCOEF7 0xf500 |
diff --git a/drivers/media/dvb/frontends/stv0900_sw.c b/drivers/media/dvb/frontends/stv0900_sw.c index b8da87fa637f..ba0709b2d433 100644 --- a/drivers/media/dvb/frontends/stv0900_sw.c +++ b/drivers/media/dvb/frontends/stv0900_sw.c | |||
@@ -193,7 +193,7 @@ static int stv0900_search_carr_sw_loop(struct stv0900_internal *intp, | |||
193 | return lock; | 193 | return lock; |
194 | } | 194 | } |
195 | 195 | ||
196 | int stv0900_sw_algo(struct stv0900_internal *intp, | 196 | static int stv0900_sw_algo(struct stv0900_internal *intp, |
197 | enum fe_stv0900_demod_num demod) | 197 | enum fe_stv0900_demod_num demod) |
198 | { | 198 | { |
199 | int lock = FALSE, | 199 | int lock = FALSE, |
@@ -606,7 +606,12 @@ static int stv0900_get_demod_cold_lock(struct dvb_frontend *fe, | |||
606 | tuner_freq -= (current_step * currier_step); | 606 | tuner_freq -= (current_step * currier_step); |
607 | 607 | ||
608 | if (intp->chip_id <= 0x20) { | 608 | if (intp->chip_id <= 0x20) { |
609 | stv0900_set_tuner(fe, tuner_freq, intp->bw[d]); | 609 | if (intp->tuner_type[d] == 3) |
610 | stv0900_set_tuner_auto(intp, tuner_freq, | ||
611 | intp->bw[d], demod); | ||
612 | else | ||
613 | stv0900_set_tuner(fe, tuner_freq, intp->bw[d]); | ||
614 | |||
610 | stv0900_write_reg(intp, DMDISTATE, 0x1c); | 615 | stv0900_write_reg(intp, DMDISTATE, 0x1c); |
611 | stv0900_write_reg(intp, CFRINIT1, 0); | 616 | stv0900_write_reg(intp, CFRINIT1, 0); |
612 | stv0900_write_reg(intp, CFRINIT0, 0); | 617 | stv0900_write_reg(intp, CFRINIT0, 0); |
@@ -790,7 +795,7 @@ static enum fe_stv0900_fec stv0900_get_vit_fec(struct stv0900_internal *intp, | |||
790 | return prate; | 795 | return prate; |
791 | } | 796 | } |
792 | 797 | ||
793 | void stv0900_set_dvbs1_track_car_loop(struct stv0900_internal *intp, | 798 | static void stv0900_set_dvbs1_track_car_loop(struct stv0900_internal *intp, |
794 | enum fe_stv0900_demod_num demod, | 799 | enum fe_stv0900_demod_num demod, |
795 | u32 srate) | 800 | u32 srate) |
796 | { | 801 | { |
@@ -976,8 +981,16 @@ static void stv0900_track_optimization(struct dvb_frontend *fe) | |||
976 | intp->rolloff) + 10000000; | 981 | intp->rolloff) + 10000000; |
977 | 982 | ||
978 | if ((intp->chip_id >= 0x20) || (blind_tun_sw == 1)) { | 983 | if ((intp->chip_id >= 0x20) || (blind_tun_sw == 1)) { |
979 | if (intp->srch_algo[demod] != STV0900_WARM_START) | 984 | if (intp->srch_algo[demod] != STV0900_WARM_START) { |
980 | stv0900_set_bandwidth(fe, intp->bw[demod]); | 985 | if (intp->tuner_type[demod] == 3) |
986 | stv0900_set_tuner_auto(intp, | ||
987 | intp->freq[demod], | ||
988 | intp->bw[demod], | ||
989 | demod); | ||
990 | else | ||
991 | stv0900_set_bandwidth(fe, | ||
992 | intp->bw[demod]); | ||
993 | } | ||
981 | } | 994 | } |
982 | 995 | ||
983 | if ((intp->srch_algo[demod] == STV0900_BLIND_SEARCH) || | 996 | if ((intp->srch_algo[demod] == STV0900_BLIND_SEARCH) || |
@@ -1202,7 +1215,11 @@ fe_stv0900_signal_type stv0900_get_signal_params(struct dvb_frontend *fe) | |||
1202 | } | 1215 | } |
1203 | 1216 | ||
1204 | result->standard = stv0900_get_standard(fe, d); | 1217 | result->standard = stv0900_get_standard(fe, d); |
1205 | result->frequency = stv0900_get_tuner_freq(fe); | 1218 | if (intp->tuner_type[demod] == 3) |
1219 | result->frequency = stv0900_get_freq_auto(intp, d); | ||
1220 | else | ||
1221 | result->frequency = stv0900_get_tuner_freq(fe); | ||
1222 | |||
1206 | offsetFreq = stv0900_get_carr_freq(intp, intp->mclk, d) / 1000; | 1223 | offsetFreq = stv0900_get_carr_freq(intp, intp->mclk, d) / 1000; |
1207 | result->frequency += offsetFreq; | 1224 | result->frequency += offsetFreq; |
1208 | result->symbol_rate = stv0900_get_symbol_rate(intp, intp->mclk, d); | 1225 | result->symbol_rate = stv0900_get_symbol_rate(intp, intp->mclk, d); |
@@ -1213,6 +1230,9 @@ fe_stv0900_signal_type stv0900_get_signal_params(struct dvb_frontend *fe) | |||
1213 | result->pilot = stv0900_get_bits(intp, DEMOD_TYPE) & 0x01; | 1230 | result->pilot = stv0900_get_bits(intp, DEMOD_TYPE) & 0x01; |
1214 | result->frame_len = ((u32)stv0900_get_bits(intp, DEMOD_TYPE)) >> 1; | 1231 | result->frame_len = ((u32)stv0900_get_bits(intp, DEMOD_TYPE)) >> 1; |
1215 | result->rolloff = stv0900_get_bits(intp, ROLLOFF_STATUS); | 1232 | result->rolloff = stv0900_get_bits(intp, ROLLOFF_STATUS); |
1233 | |||
1234 | dprintk("%s: modcode=0x%x \n", __func__, result->modcode); | ||
1235 | |||
1216 | switch (result->standard) { | 1236 | switch (result->standard) { |
1217 | case STV0900_DVBS2_STANDARD: | 1237 | case STV0900_DVBS2_STANDARD: |
1218 | result->spectrum = stv0900_get_bits(intp, SPECINV_DEMOD); | 1238 | result->spectrum = stv0900_get_bits(intp, SPECINV_DEMOD); |
@@ -1239,7 +1259,11 @@ fe_stv0900_signal_type stv0900_get_signal_params(struct dvb_frontend *fe) | |||
1239 | if ((intp->srch_algo[d] == STV0900_BLIND_SEARCH) || | 1259 | if ((intp->srch_algo[d] == STV0900_BLIND_SEARCH) || |
1240 | (intp->symbol_rate[d] < 10000000)) { | 1260 | (intp->symbol_rate[d] < 10000000)) { |
1241 | offsetFreq = result->frequency - intp->freq[d]; | 1261 | offsetFreq = result->frequency - intp->freq[d]; |
1242 | intp->freq[d] = stv0900_get_tuner_freq(fe); | 1262 | if (intp->tuner_type[demod] == 3) |
1263 | intp->freq[d] = stv0900_get_freq_auto(intp, d); | ||
1264 | else | ||
1265 | intp->freq[d] = stv0900_get_tuner_freq(fe); | ||
1266 | |||
1243 | if (ABS(offsetFreq) <= ((intp->srch_range[d] / 2000) + 500)) | 1267 | if (ABS(offsetFreq) <= ((intp->srch_range[d] / 2000) + 500)) |
1244 | range = STV0900_RANGEOK; | 1268 | range = STV0900_RANGEOK; |
1245 | else if (ABS(offsetFreq) <= | 1269 | else if (ABS(offsetFreq) <= |
@@ -1481,7 +1505,12 @@ static u32 stv0900_search_srate_coarse(struct dvb_frontend *fe) | |||
1481 | else | 1505 | else |
1482 | tuner_freq -= (current_step * currier_step); | 1506 | tuner_freq -= (current_step * currier_step); |
1483 | 1507 | ||
1484 | stv0900_set_tuner(fe, tuner_freq, intp->bw[demod]); | 1508 | if (intp->tuner_type[demod] == 3) |
1509 | stv0900_set_tuner_auto(intp, tuner_freq, | ||
1510 | intp->bw[demod], demod); | ||
1511 | else | ||
1512 | stv0900_set_tuner(fe, tuner_freq, | ||
1513 | intp->bw[demod]); | ||
1485 | } | 1514 | } |
1486 | } | 1515 | } |
1487 | 1516 | ||
@@ -1608,7 +1637,8 @@ static int stv0900_blind_search_algo(struct dvb_frontend *fe) | |||
1608 | 1637 | ||
1609 | agc2_int = stv0900_blind_check_agc2_min_level(intp, demod); | 1638 | agc2_int = stv0900_blind_check_agc2_min_level(intp, demod); |
1610 | 1639 | ||
1611 | if (agc2_int > STV0900_BLIND_SEARCH_AGC2_TH) | 1640 | dprintk("%s agc2_int=%d agc2_th=%d \n", __func__, agc2_int, agc2_th); |
1641 | if (agc2_int > agc2_th) | ||
1612 | return FALSE; | 1642 | return FALSE; |
1613 | 1643 | ||
1614 | if (intp->chip_id == 0x10) | 1644 | if (intp->chip_id == 0x10) |
@@ -1875,7 +1905,11 @@ enum fe_stv0900_signal_type stv0900_algo(struct dvb_frontend *fe) | |||
1875 | 1905 | ||
1876 | } | 1906 | } |
1877 | 1907 | ||
1878 | stv0900_set_tuner(fe, intp->freq[demod], intp->bw[demod]); | 1908 | if (intp->tuner_type[demod] == 3) |
1909 | stv0900_set_tuner_auto(intp, intp->freq[demod], | ||
1910 | intp->bw[demod], demod); | ||
1911 | else | ||
1912 | stv0900_set_tuner(fe, intp->freq[demod], intp->bw[demod]); | ||
1879 | 1913 | ||
1880 | agc1_power = MAKEWORD(stv0900_get_bits(intp, AGCIQ_VALUE1), | 1914 | agc1_power = MAKEWORD(stv0900_get_bits(intp, AGCIQ_VALUE1), |
1881 | stv0900_get_bits(intp, AGCIQ_VALUE0)); | 1915 | stv0900_get_bits(intp, AGCIQ_VALUE0)); |
diff --git a/drivers/media/dvb/frontends/stv090x.c b/drivers/media/dvb/frontends/stv090x.c index 1573466a5c74..c52c3357dc54 100644 --- a/drivers/media/dvb/frontends/stv090x.c +++ b/drivers/media/dvb/frontends/stv090x.c | |||
@@ -37,7 +37,82 @@ | |||
37 | static unsigned int verbose; | 37 | static unsigned int verbose; |
38 | module_param(verbose, int, 0644); | 38 | module_param(verbose, int, 0644); |
39 | 39 | ||
40 | struct mutex demod_lock; | 40 | /* internal params node */ |
41 | struct stv090x_dev { | ||
42 | /* pointer for internal params, one for each pair of demods */ | ||
43 | struct stv090x_internal *internal; | ||
44 | struct stv090x_dev *next_dev; | ||
45 | }; | ||
46 | |||
47 | /* first internal params */ | ||
48 | static struct stv090x_dev *stv090x_first_dev; | ||
49 | |||
50 | /* find chip by i2c adapter and i2c address */ | ||
51 | static struct stv090x_dev *find_dev(struct i2c_adapter *i2c_adap, | ||
52 | u8 i2c_addr) | ||
53 | { | ||
54 | struct stv090x_dev *temp_dev = stv090x_first_dev; | ||
55 | |||
56 | /* | ||
57 | Search of the last stv0900 chip or | ||
58 | find it by i2c adapter and i2c address */ | ||
59 | while ((temp_dev != NULL) && | ||
60 | ((temp_dev->internal->i2c_adap != i2c_adap) || | ||
61 | (temp_dev->internal->i2c_addr != i2c_addr))) { | ||
62 | |||
63 | temp_dev = temp_dev->next_dev; | ||
64 | } | ||
65 | |||
66 | return temp_dev; | ||
67 | } | ||
68 | |||
69 | /* deallocating chip */ | ||
70 | static void remove_dev(struct stv090x_internal *internal) | ||
71 | { | ||
72 | struct stv090x_dev *prev_dev = stv090x_first_dev; | ||
73 | struct stv090x_dev *del_dev = find_dev(internal->i2c_adap, | ||
74 | internal->i2c_addr); | ||
75 | |||
76 | if (del_dev != NULL) { | ||
77 | if (del_dev == stv090x_first_dev) { | ||
78 | stv090x_first_dev = del_dev->next_dev; | ||
79 | } else { | ||
80 | while (prev_dev->next_dev != del_dev) | ||
81 | prev_dev = prev_dev->next_dev; | ||
82 | |||
83 | prev_dev->next_dev = del_dev->next_dev; | ||
84 | } | ||
85 | |||
86 | kfree(del_dev); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | /* allocating new chip */ | ||
91 | static struct stv090x_dev *append_internal(struct stv090x_internal *internal) | ||
92 | { | ||
93 | struct stv090x_dev *new_dev; | ||
94 | struct stv090x_dev *temp_dev; | ||
95 | |||
96 | new_dev = kmalloc(sizeof(struct stv090x_dev), GFP_KERNEL); | ||
97 | if (new_dev != NULL) { | ||
98 | new_dev->internal = internal; | ||
99 | new_dev->next_dev = NULL; | ||
100 | |||
101 | /* append to list */ | ||
102 | if (stv090x_first_dev == NULL) { | ||
103 | stv090x_first_dev = new_dev; | ||
104 | } else { | ||
105 | temp_dev = stv090x_first_dev; | ||
106 | while (temp_dev->next_dev != NULL) | ||
107 | temp_dev = temp_dev->next_dev; | ||
108 | |||
109 | temp_dev->next_dev = new_dev; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | return new_dev; | ||
114 | } | ||
115 | |||
41 | 116 | ||
42 | /* DVBS1 and DSS C/N Lookup table */ | 117 | /* DVBS1 and DSS C/N Lookup table */ |
43 | static const struct stv090x_tab stv090x_s1cn_tab[] = { | 118 | static const struct stv090x_tab stv090x_s1cn_tab[] = { |
@@ -683,6 +758,9 @@ static int stv090x_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) | |||
683 | struct stv090x_state *state = fe->demodulator_priv; | 758 | struct stv090x_state *state = fe->demodulator_priv; |
684 | u32 reg; | 759 | u32 reg; |
685 | 760 | ||
761 | if (enable) | ||
762 | mutex_lock(&state->internal->tuner_lock); | ||
763 | |||
686 | reg = STV090x_READ_DEMOD(state, I2CRPT); | 764 | reg = STV090x_READ_DEMOD(state, I2CRPT); |
687 | if (enable) { | 765 | if (enable) { |
688 | dprintk(FE_DEBUG, 1, "Enable Gate"); | 766 | dprintk(FE_DEBUG, 1, "Enable Gate"); |
@@ -696,9 +774,14 @@ static int stv090x_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) | |||
696 | if ((STV090x_WRITE_DEMOD(state, I2CRPT, reg)) < 0) | 774 | if ((STV090x_WRITE_DEMOD(state, I2CRPT, reg)) < 0) |
697 | goto err; | 775 | goto err; |
698 | } | 776 | } |
777 | |||
778 | if (!enable) | ||
779 | mutex_unlock(&state->internal->tuner_lock); | ||
780 | |||
699 | return 0; | 781 | return 0; |
700 | err: | 782 | err: |
701 | dprintk(FE_ERROR, 1, "I/O error"); | 783 | dprintk(FE_ERROR, 1, "I/O error"); |
784 | mutex_unlock(&state->internal->tuner_lock); | ||
702 | return -1; | 785 | return -1; |
703 | } | 786 | } |
704 | 787 | ||
@@ -755,13 +838,13 @@ static int stv090x_set_srate(struct stv090x_state *state, u32 srate) | |||
755 | 838 | ||
756 | if (srate > 60000000) { | 839 | if (srate > 60000000) { |
757 | sym = (srate << 4); /* SR * 2^16 / master_clk */ | 840 | sym = (srate << 4); /* SR * 2^16 / master_clk */ |
758 | sym /= (state->mclk >> 12); | 841 | sym /= (state->internal->mclk >> 12); |
759 | } else if (srate > 6000000) { | 842 | } else if (srate > 6000000) { |
760 | sym = (srate << 6); | 843 | sym = (srate << 6); |
761 | sym /= (state->mclk >> 10); | 844 | sym /= (state->internal->mclk >> 10); |
762 | } else { | 845 | } else { |
763 | sym = (srate << 9); | 846 | sym = (srate << 9); |
764 | sym /= (state->mclk >> 7); | 847 | sym /= (state->internal->mclk >> 7); |
765 | } | 848 | } |
766 | 849 | ||
767 | if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0x7f) < 0) /* MSB */ | 850 | if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0x7f) < 0) /* MSB */ |
@@ -782,13 +865,13 @@ static int stv090x_set_max_srate(struct stv090x_state *state, u32 clk, u32 srate | |||
782 | srate = 105 * (srate / 100); | 865 | srate = 105 * (srate / 100); |
783 | if (srate > 60000000) { | 866 | if (srate > 60000000) { |
784 | sym = (srate << 4); /* SR * 2^16 / master_clk */ | 867 | sym = (srate << 4); /* SR * 2^16 / master_clk */ |
785 | sym /= (state->mclk >> 12); | 868 | sym /= (state->internal->mclk >> 12); |
786 | } else if (srate > 6000000) { | 869 | } else if (srate > 6000000) { |
787 | sym = (srate << 6); | 870 | sym = (srate << 6); |
788 | sym /= (state->mclk >> 10); | 871 | sym /= (state->internal->mclk >> 10); |
789 | } else { | 872 | } else { |
790 | sym = (srate << 9); | 873 | sym = (srate << 9); |
791 | sym /= (state->mclk >> 7); | 874 | sym /= (state->internal->mclk >> 7); |
792 | } | 875 | } |
793 | 876 | ||
794 | if (sym < 0x7fff) { | 877 | if (sym < 0x7fff) { |
@@ -816,13 +899,13 @@ static int stv090x_set_min_srate(struct stv090x_state *state, u32 clk, u32 srate | |||
816 | srate = 95 * (srate / 100); | 899 | srate = 95 * (srate / 100); |
817 | if (srate > 60000000) { | 900 | if (srate > 60000000) { |
818 | sym = (srate << 4); /* SR * 2^16 / master_clk */ | 901 | sym = (srate << 4); /* SR * 2^16 / master_clk */ |
819 | sym /= (state->mclk >> 12); | 902 | sym /= (state->internal->mclk >> 12); |
820 | } else if (srate > 6000000) { | 903 | } else if (srate > 6000000) { |
821 | sym = (srate << 6); | 904 | sym = (srate << 6); |
822 | sym /= (state->mclk >> 10); | 905 | sym /= (state->internal->mclk >> 10); |
823 | } else { | 906 | } else { |
824 | sym = (srate << 9); | 907 | sym = (srate << 9); |
825 | sym /= (state->mclk >> 7); | 908 | sym /= (state->internal->mclk >> 7); |
826 | } | 909 | } |
827 | 910 | ||
828 | if (STV090x_WRITE_DEMOD(state, SFRLOW1, ((sym >> 8) & 0x7f)) < 0) /* MSB */ | 911 | if (STV090x_WRITE_DEMOD(state, SFRLOW1, ((sym >> 8) & 0x7f)) < 0) /* MSB */ |
@@ -1103,21 +1186,21 @@ static int stv090x_vitclk_ctl(struct stv090x_state *state, int enable) | |||
1103 | 1186 | ||
1104 | switch (state->demod) { | 1187 | switch (state->demod) { |
1105 | case STV090x_DEMODULATOR_0: | 1188 | case STV090x_DEMODULATOR_0: |
1106 | mutex_lock(&demod_lock); | 1189 | mutex_lock(&state->internal->demod_lock); |
1107 | reg = stv090x_read_reg(state, STV090x_STOPCLK2); | 1190 | reg = stv090x_read_reg(state, STV090x_STOPCLK2); |
1108 | STV090x_SETFIELD(reg, STOP_CLKVIT1_FIELD, enable); | 1191 | STV090x_SETFIELD(reg, STOP_CLKVIT1_FIELD, enable); |
1109 | if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) | 1192 | if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) |
1110 | goto err; | 1193 | goto err; |
1111 | mutex_unlock(&demod_lock); | 1194 | mutex_unlock(&state->internal->demod_lock); |
1112 | break; | 1195 | break; |
1113 | 1196 | ||
1114 | case STV090x_DEMODULATOR_1: | 1197 | case STV090x_DEMODULATOR_1: |
1115 | mutex_lock(&demod_lock); | 1198 | mutex_lock(&state->internal->demod_lock); |
1116 | reg = stv090x_read_reg(state, STV090x_STOPCLK2); | 1199 | reg = stv090x_read_reg(state, STV090x_STOPCLK2); |
1117 | STV090x_SETFIELD(reg, STOP_CLKVIT2_FIELD, enable); | 1200 | STV090x_SETFIELD(reg, STOP_CLKVIT2_FIELD, enable); |
1118 | if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) | 1201 | if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) |
1119 | goto err; | 1202 | goto err; |
1120 | mutex_unlock(&demod_lock); | 1203 | mutex_unlock(&state->internal->demod_lock); |
1121 | break; | 1204 | break; |
1122 | 1205 | ||
1123 | default: | 1206 | default: |
@@ -1126,14 +1209,14 @@ static int stv090x_vitclk_ctl(struct stv090x_state *state, int enable) | |||
1126 | } | 1209 | } |
1127 | return 0; | 1210 | return 0; |
1128 | err: | 1211 | err: |
1129 | mutex_unlock(&demod_lock); | 1212 | mutex_unlock(&state->internal->demod_lock); |
1130 | dprintk(FE_ERROR, 1, "I/O error"); | 1213 | dprintk(FE_ERROR, 1, "I/O error"); |
1131 | return -1; | 1214 | return -1; |
1132 | } | 1215 | } |
1133 | 1216 | ||
1134 | static int stv090x_dvbs_track_crl(struct stv090x_state *state) | 1217 | static int stv090x_dvbs_track_crl(struct stv090x_state *state) |
1135 | { | 1218 | { |
1136 | if (state->dev_ver >= 0x30) { | 1219 | if (state->internal->dev_ver >= 0x30) { |
1137 | /* Set ACLC BCLC optimised value vs SR */ | 1220 | /* Set ACLC BCLC optimised value vs SR */ |
1138 | if (state->srate >= 15000000) { | 1221 | if (state->srate >= 15000000) { |
1139 | if (STV090x_WRITE_DEMOD(state, ACLC, 0x2b) < 0) | 1222 | if (STV090x_WRITE_DEMOD(state, ACLC, 0x2b) < 0) |
@@ -1215,7 +1298,7 @@ static int stv090x_delivery_search(struct stv090x_state *state) | |||
1215 | if (STV090x_WRITE_DEMOD(state, BCLC, 0x09) < 0) | 1298 | if (STV090x_WRITE_DEMOD(state, BCLC, 0x09) < 0) |
1216 | goto err; | 1299 | goto err; |
1217 | 1300 | ||
1218 | if (state->dev_ver <= 0x20) { | 1301 | if (state->internal->dev_ver <= 0x20) { |
1219 | /* enable S2 carrier loop */ | 1302 | /* enable S2 carrier loop */ |
1220 | if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0) | 1303 | if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0) |
1221 | goto err; | 1304 | goto err; |
@@ -1246,6 +1329,10 @@ static int stv090x_delivery_search(struct stv090x_state *state) | |||
1246 | default: | 1329 | default: |
1247 | /* enable DVB-S2 and DVB-S2 in Auto MODE */ | 1330 | /* enable DVB-S2 and DVB-S2 in Auto MODE */ |
1248 | reg = STV090x_READ_DEMOD(state, DMDCFGMD); | 1331 | reg = STV090x_READ_DEMOD(state, DMDCFGMD); |
1332 | STV090x_SETFIELD_Px(reg, DVBS1_ENABLE_FIELD, 0); | ||
1333 | STV090x_SETFIELD_Px(reg, DVBS2_ENABLE_FIELD, 0); | ||
1334 | if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) | ||
1335 | goto err; | ||
1249 | STV090x_SETFIELD_Px(reg, DVBS1_ENABLE_FIELD, 1); | 1336 | STV090x_SETFIELD_Px(reg, DVBS1_ENABLE_FIELD, 1); |
1250 | STV090x_SETFIELD_Px(reg, DVBS2_ENABLE_FIELD, 1); | 1337 | STV090x_SETFIELD_Px(reg, DVBS2_ENABLE_FIELD, 1); |
1251 | if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) | 1338 | if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) |
@@ -1257,7 +1344,7 @@ static int stv090x_delivery_search(struct stv090x_state *state) | |||
1257 | if (stv090x_dvbs_track_crl(state) < 0) | 1344 | if (stv090x_dvbs_track_crl(state) < 0) |
1258 | goto err; | 1345 | goto err; |
1259 | 1346 | ||
1260 | if (state->dev_ver <= 0x20) { | 1347 | if (state->internal->dev_ver <= 0x20) { |
1261 | /* enable S2 carrier loop */ | 1348 | /* enable S2 carrier loop */ |
1262 | if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0) | 1349 | if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0) |
1263 | goto err; | 1350 | goto err; |
@@ -1304,7 +1391,7 @@ static int stv090x_start_search(struct stv090x_state *state) | |||
1304 | if (STV090x_WRITE_DEMOD(state, DMDISTATE, reg) < 0) | 1391 | if (STV090x_WRITE_DEMOD(state, DMDISTATE, reg) < 0) |
1305 | goto err; | 1392 | goto err; |
1306 | 1393 | ||
1307 | if (state->dev_ver <= 0x20) { | 1394 | if (state->internal->dev_ver <= 0x20) { |
1308 | if (state->srate <= 5000000) { | 1395 | if (state->srate <= 5000000) { |
1309 | if (STV090x_WRITE_DEMOD(state, CARCFG, 0x44) < 0) | 1396 | if (STV090x_WRITE_DEMOD(state, CARCFG, 0x44) < 0) |
1310 | goto err; | 1397 | goto err; |
@@ -1348,7 +1435,7 @@ static int stv090x_start_search(struct stv090x_state *state) | |||
1348 | * CFR max = +1MHz | 1435 | * CFR max = +1MHz |
1349 | */ | 1436 | */ |
1350 | freq_abs = 1000 << 16; | 1437 | freq_abs = 1000 << 16; |
1351 | freq_abs /= (state->mclk / 1000); | 1438 | freq_abs /= (state->internal->mclk / 1000); |
1352 | freq = (s16) freq_abs; | 1439 | freq = (s16) freq_abs; |
1353 | } else { | 1440 | } else { |
1354 | /* COLD Start | 1441 | /* COLD Start |
@@ -1358,7 +1445,7 @@ static int stv090x_start_search(struct stv090x_state *state) | |||
1358 | */ | 1445 | */ |
1359 | freq_abs = (state->search_range / 2000) + 600; | 1446 | freq_abs = (state->search_range / 2000) + 600; |
1360 | freq_abs = freq_abs << 16; | 1447 | freq_abs = freq_abs << 16; |
1361 | freq_abs /= (state->mclk / 1000); | 1448 | freq_abs /= (state->internal->mclk / 1000); |
1362 | freq = (s16) freq_abs; | 1449 | freq = (s16) freq_abs; |
1363 | } | 1450 | } |
1364 | 1451 | ||
@@ -1381,7 +1468,7 @@ static int stv090x_start_search(struct stv090x_state *state) | |||
1381 | if (STV090x_WRITE_DEMOD(state, CFRINIT0, 0) < 0) | 1468 | if (STV090x_WRITE_DEMOD(state, CFRINIT0, 0) < 0) |
1382 | goto err; | 1469 | goto err; |
1383 | 1470 | ||
1384 | if (state->dev_ver >= 0x20) { | 1471 | if (state->internal->dev_ver >= 0x20) { |
1385 | if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0) | 1472 | if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0) |
1386 | goto err; | 1473 | goto err; |
1387 | if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) | 1474 | if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) |
@@ -1418,10 +1505,10 @@ static int stv090x_start_search(struct stv090x_state *state) | |||
1418 | if (STV090x_WRITE_DEMOD(state, RTC, 0x88) < 0) | 1505 | if (STV090x_WRITE_DEMOD(state, RTC, 0x88) < 0) |
1419 | goto err; | 1506 | goto err; |
1420 | 1507 | ||
1421 | if (state->dev_ver >= 0x20) { | 1508 | if (state->internal->dev_ver >= 0x20) { |
1422 | /*Frequency offset detector setting*/ | 1509 | /*Frequency offset detector setting*/ |
1423 | if (state->srate < 2000000) { | 1510 | if (state->srate < 2000000) { |
1424 | if (state->dev_ver <= 0x20) { | 1511 | if (state->internal->dev_ver <= 0x20) { |
1425 | /* Cut 2 */ | 1512 | /* Cut 2 */ |
1426 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x39) < 0) | 1513 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x39) < 0) |
1427 | goto err; | 1514 | goto err; |
@@ -1512,7 +1599,7 @@ static int stv090x_get_agc2_min_level(struct stv090x_state *state) | |||
1512 | steps = 1; | 1599 | steps = 1; |
1513 | 1600 | ||
1514 | dir = 1; | 1601 | dir = 1; |
1515 | freq_step = (1000000 * 256) / (state->mclk / 256); | 1602 | freq_step = (1000000 * 256) / (state->internal->mclk / 256); |
1516 | freq_init = 0; | 1603 | freq_init = 0; |
1517 | 1604 | ||
1518 | for (i = 0; i < steps; i++) { | 1605 | for (i = 0; i < steps; i++) { |
@@ -1583,7 +1670,7 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state) | |||
1583 | u32 srate_coarse = 0, agc2 = 0, car_step = 1200, reg; | 1670 | u32 srate_coarse = 0, agc2 = 0, car_step = 1200, reg; |
1584 | u32 agc2th; | 1671 | u32 agc2th; |
1585 | 1672 | ||
1586 | if (state->dev_ver >= 0x30) | 1673 | if (state->internal->dev_ver >= 0x30) |
1587 | agc2th = 0x2e00; | 1674 | agc2th = 0x2e00; |
1588 | else | 1675 | else |
1589 | agc2th = 0x1f00; | 1676 | agc2th = 0x1f00; |
@@ -1619,13 +1706,13 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state) | |||
1619 | if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x50) < 0) | 1706 | if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x50) < 0) |
1620 | goto err; | 1707 | goto err; |
1621 | 1708 | ||
1622 | if (state->dev_ver >= 0x30) { | 1709 | if (state->internal->dev_ver >= 0x30) { |
1623 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x99) < 0) | 1710 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x99) < 0) |
1624 | goto err; | 1711 | goto err; |
1625 | if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x98) < 0) | 1712 | if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x98) < 0) |
1626 | goto err; | 1713 | goto err; |
1627 | 1714 | ||
1628 | } else if (state->dev_ver >= 0x20) { | 1715 | } else if (state->internal->dev_ver >= 0x20) { |
1629 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x6a) < 0) | 1716 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x6a) < 0) |
1630 | goto err; | 1717 | goto err; |
1631 | if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x95) < 0) | 1718 | if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x95) < 0) |
@@ -1677,7 +1764,7 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state) | |||
1677 | STV090x_READ_DEMOD(state, AGC2I0); | 1764 | STV090x_READ_DEMOD(state, AGC2I0); |
1678 | } | 1765 | } |
1679 | agc2 /= 10; | 1766 | agc2 /= 10; |
1680 | srate_coarse = stv090x_get_srate(state, state->mclk); | 1767 | srate_coarse = stv090x_get_srate(state, state->internal->mclk); |
1681 | cur_step++; | 1768 | cur_step++; |
1682 | dir *= -1; | 1769 | dir *= -1; |
1683 | if ((tmg_cpt >= 5) && (agc2 < agc2th) && | 1770 | if ((tmg_cpt >= 5) && (agc2 < agc2th) && |
@@ -1695,12 +1782,12 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state) | |||
1695 | 1782 | ||
1696 | if (state->config->tuner_set_frequency) { | 1783 | if (state->config->tuner_set_frequency) { |
1697 | if (state->config->tuner_set_frequency(fe, freq) < 0) | 1784 | if (state->config->tuner_set_frequency(fe, freq) < 0) |
1698 | goto err; | 1785 | goto err_gateoff; |
1699 | } | 1786 | } |
1700 | 1787 | ||
1701 | if (state->config->tuner_set_bandwidth) { | 1788 | if (state->config->tuner_set_bandwidth) { |
1702 | if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) | 1789 | if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) |
1703 | goto err; | 1790 | goto err_gateoff; |
1704 | } | 1791 | } |
1705 | 1792 | ||
1706 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) | 1793 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) |
@@ -1713,7 +1800,7 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state) | |||
1713 | 1800 | ||
1714 | if (state->config->tuner_get_status) { | 1801 | if (state->config->tuner_get_status) { |
1715 | if (state->config->tuner_get_status(fe, ®) < 0) | 1802 | if (state->config->tuner_get_status(fe, ®) < 0) |
1716 | goto err; | 1803 | goto err_gateoff; |
1717 | } | 1804 | } |
1718 | 1805 | ||
1719 | if (reg) | 1806 | if (reg) |
@@ -1729,9 +1816,12 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state) | |||
1729 | if (!tmg_lock) | 1816 | if (!tmg_lock) |
1730 | srate_coarse = 0; | 1817 | srate_coarse = 0; |
1731 | else | 1818 | else |
1732 | srate_coarse = stv090x_get_srate(state, state->mclk); | 1819 | srate_coarse = stv090x_get_srate(state, state->internal->mclk); |
1733 | 1820 | ||
1734 | return srate_coarse; | 1821 | return srate_coarse; |
1822 | |||
1823 | err_gateoff: | ||
1824 | stv090x_i2c_gate_ctrl(fe, 0); | ||
1735 | err: | 1825 | err: |
1736 | dprintk(FE_ERROR, 1, "I/O error"); | 1826 | dprintk(FE_ERROR, 1, "I/O error"); |
1737 | return -1; | 1827 | return -1; |
@@ -1741,7 +1831,7 @@ static u32 stv090x_srate_srch_fine(struct stv090x_state *state) | |||
1741 | { | 1831 | { |
1742 | u32 srate_coarse, freq_coarse, sym, reg; | 1832 | u32 srate_coarse, freq_coarse, sym, reg; |
1743 | 1833 | ||
1744 | srate_coarse = stv090x_get_srate(state, state->mclk); | 1834 | srate_coarse = stv090x_get_srate(state, state->internal->mclk); |
1745 | freq_coarse = STV090x_READ_DEMOD(state, CFR2) << 8; | 1835 | freq_coarse = STV090x_READ_DEMOD(state, CFR2) << 8; |
1746 | freq_coarse |= STV090x_READ_DEMOD(state, CFR1); | 1836 | freq_coarse |= STV090x_READ_DEMOD(state, CFR1); |
1747 | sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */ | 1837 | sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */ |
@@ -1767,10 +1857,10 @@ static u32 stv090x_srate_srch_fine(struct stv090x_state *state) | |||
1767 | if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) | 1857 | if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) |
1768 | goto err; | 1858 | goto err; |
1769 | 1859 | ||
1770 | if (state->dev_ver >= 0x30) { | 1860 | if (state->internal->dev_ver >= 0x30) { |
1771 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x79) < 0) | 1861 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x79) < 0) |
1772 | goto err; | 1862 | goto err; |
1773 | } else if (state->dev_ver >= 0x20) { | 1863 | } else if (state->internal->dev_ver >= 0x20) { |
1774 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) | 1864 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) |
1775 | goto err; | 1865 | goto err; |
1776 | } | 1866 | } |
@@ -1778,20 +1868,20 @@ static u32 stv090x_srate_srch_fine(struct stv090x_state *state) | |||
1778 | if (srate_coarse > 3000000) { | 1868 | if (srate_coarse > 3000000) { |
1779 | sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */ | 1869 | sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */ |
1780 | sym = (sym / 1000) * 65536; | 1870 | sym = (sym / 1000) * 65536; |
1781 | sym /= (state->mclk / 1000); | 1871 | sym /= (state->internal->mclk / 1000); |
1782 | if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) | 1872 | if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) |
1783 | goto err; | 1873 | goto err; |
1784 | if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) | 1874 | if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) |
1785 | goto err; | 1875 | goto err; |
1786 | sym = 10 * (srate_coarse / 13); /* SFRLOW = SFR - 30% */ | 1876 | sym = 10 * (srate_coarse / 13); /* SFRLOW = SFR - 30% */ |
1787 | sym = (sym / 1000) * 65536; | 1877 | sym = (sym / 1000) * 65536; |
1788 | sym /= (state->mclk / 1000); | 1878 | sym /= (state->internal->mclk / 1000); |
1789 | if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0) | 1879 | if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0) |
1790 | goto err; | 1880 | goto err; |
1791 | if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0) | 1881 | if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0) |
1792 | goto err; | 1882 | goto err; |
1793 | sym = (srate_coarse / 1000) * 65536; | 1883 | sym = (srate_coarse / 1000) * 65536; |
1794 | sym /= (state->mclk / 1000); | 1884 | sym /= (state->internal->mclk / 1000); |
1795 | if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0) | 1885 | if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0) |
1796 | goto err; | 1886 | goto err; |
1797 | if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0) | 1887 | if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0) |
@@ -1799,20 +1889,20 @@ static u32 stv090x_srate_srch_fine(struct stv090x_state *state) | |||
1799 | } else { | 1889 | } else { |
1800 | sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */ | 1890 | sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */ |
1801 | sym = (sym / 100) * 65536; | 1891 | sym = (sym / 100) * 65536; |
1802 | sym /= (state->mclk / 100); | 1892 | sym /= (state->internal->mclk / 100); |
1803 | if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) | 1893 | if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) |
1804 | goto err; | 1894 | goto err; |
1805 | if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) | 1895 | if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) |
1806 | goto err; | 1896 | goto err; |
1807 | sym = 10 * (srate_coarse / 14); /* SFRLOW = SFR - 30% */ | 1897 | sym = 10 * (srate_coarse / 14); /* SFRLOW = SFR - 30% */ |
1808 | sym = (sym / 100) * 65536; | 1898 | sym = (sym / 100) * 65536; |
1809 | sym /= (state->mclk / 100); | 1899 | sym /= (state->internal->mclk / 100); |
1810 | if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0) | 1900 | if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0) |
1811 | goto err; | 1901 | goto err; |
1812 | if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0) | 1902 | if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0) |
1813 | goto err; | 1903 | goto err; |
1814 | sym = (srate_coarse / 100) * 65536; | 1904 | sym = (srate_coarse / 100) * 65536; |
1815 | sym /= (state->mclk / 100); | 1905 | sym /= (state->internal->mclk / 100); |
1816 | if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0) | 1906 | if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0) |
1817 | goto err; | 1907 | goto err; |
1818 | if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0) | 1908 | if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0) |
@@ -1874,18 +1964,19 @@ static int stv090x_blind_search(struct stv090x_state *state) | |||
1874 | u32 agc2, reg, srate_coarse; | 1964 | u32 agc2, reg, srate_coarse; |
1875 | s32 cpt_fail, agc2_ovflw, i; | 1965 | s32 cpt_fail, agc2_ovflw, i; |
1876 | u8 k_ref, k_max, k_min; | 1966 | u8 k_ref, k_max, k_min; |
1877 | int coarse_fail, lock; | 1967 | int coarse_fail = 0; |
1968 | int lock; | ||
1878 | 1969 | ||
1879 | k_max = 110; | 1970 | k_max = 110; |
1880 | k_min = 10; | 1971 | k_min = 10; |
1881 | 1972 | ||
1882 | agc2 = stv090x_get_agc2_min_level(state); | 1973 | agc2 = stv090x_get_agc2_min_level(state); |
1883 | 1974 | ||
1884 | if (agc2 > STV090x_SEARCH_AGC2_TH(state->dev_ver)) { | 1975 | if (agc2 > STV090x_SEARCH_AGC2_TH(state->internal->dev_ver)) { |
1885 | lock = 0; | 1976 | lock = 0; |
1886 | } else { | 1977 | } else { |
1887 | 1978 | ||
1888 | if (state->dev_ver <= 0x20) { | 1979 | if (state->internal->dev_ver <= 0x20) { |
1889 | if (STV090x_WRITE_DEMOD(state, CARCFG, 0xc4) < 0) | 1980 | if (STV090x_WRITE_DEMOD(state, CARCFG, 0xc4) < 0) |
1890 | goto err; | 1981 | goto err; |
1891 | } else { | 1982 | } else { |
@@ -1897,7 +1988,7 @@ static int stv090x_blind_search(struct stv090x_state *state) | |||
1897 | if (STV090x_WRITE_DEMOD(state, RTCS2, 0x44) < 0) | 1988 | if (STV090x_WRITE_DEMOD(state, RTCS2, 0x44) < 0) |
1898 | goto err; | 1989 | goto err; |
1899 | 1990 | ||
1900 | if (state->dev_ver >= 0x20) { | 1991 | if (state->internal->dev_ver >= 0x20) { |
1901 | if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0) | 1992 | if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0) |
1902 | goto err; | 1993 | goto err; |
1903 | if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) | 1994 | if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) |
@@ -1956,7 +2047,7 @@ static int stv090x_chk_tmg(struct stv090x_state *state) | |||
1956 | u32 reg; | 2047 | u32 reg; |
1957 | s32 tmg_cpt = 0, i; | 2048 | s32 tmg_cpt = 0, i; |
1958 | u8 freq, tmg_thh, tmg_thl; | 2049 | u8 freq, tmg_thh, tmg_thl; |
1959 | int tmg_lock; | 2050 | int tmg_lock = 0; |
1960 | 2051 | ||
1961 | freq = STV090x_READ_DEMOD(state, CARFREQ); | 2052 | freq = STV090x_READ_DEMOD(state, CARFREQ); |
1962 | tmg_thh = STV090x_READ_DEMOD(state, TMGTHRISE); | 2053 | tmg_thh = STV090x_READ_DEMOD(state, TMGTHRISE); |
@@ -2080,12 +2171,12 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd) | |||
2080 | 2171 | ||
2081 | if (state->config->tuner_set_frequency) { | 2172 | if (state->config->tuner_set_frequency) { |
2082 | if (state->config->tuner_set_frequency(fe, freq) < 0) | 2173 | if (state->config->tuner_set_frequency(fe, freq) < 0) |
2083 | goto err; | 2174 | goto err_gateoff; |
2084 | } | 2175 | } |
2085 | 2176 | ||
2086 | if (state->config->tuner_set_bandwidth) { | 2177 | if (state->config->tuner_set_bandwidth) { |
2087 | if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) | 2178 | if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) |
2088 | goto err; | 2179 | goto err_gateoff; |
2089 | } | 2180 | } |
2090 | 2181 | ||
2091 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) | 2182 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) |
@@ -2098,7 +2189,7 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd) | |||
2098 | 2189 | ||
2099 | if (state->config->tuner_get_status) { | 2190 | if (state->config->tuner_get_status) { |
2100 | if (state->config->tuner_get_status(fe, ®) < 0) | 2191 | if (state->config->tuner_get_status(fe, ®) < 0) |
2101 | goto err; | 2192 | goto err_gateoff; |
2102 | } | 2193 | } |
2103 | 2194 | ||
2104 | if (reg) | 2195 | if (reg) |
@@ -2129,6 +2220,8 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd) | |||
2129 | 2220 | ||
2130 | return lock; | 2221 | return lock; |
2131 | 2222 | ||
2223 | err_gateoff: | ||
2224 | stv090x_i2c_gate_ctrl(fe, 0); | ||
2132 | err: | 2225 | err: |
2133 | dprintk(FE_ERROR, 1, "I/O error"); | 2226 | dprintk(FE_ERROR, 1, "I/O error"); |
2134 | return -1; | 2227 | return -1; |
@@ -2142,13 +2235,13 @@ static int stv090x_get_loop_params(struct stv090x_state *state, s32 *freq_inc, s | |||
2142 | car_max = state->search_range / 1000; | 2235 | car_max = state->search_range / 1000; |
2143 | car_max += car_max / 10; | 2236 | car_max += car_max / 10; |
2144 | car_max = 65536 * (car_max / 2); | 2237 | car_max = 65536 * (car_max / 2); |
2145 | car_max /= (state->mclk / 1000); | 2238 | car_max /= (state->internal->mclk / 1000); |
2146 | 2239 | ||
2147 | if (car_max > 0x4000) | 2240 | if (car_max > 0x4000) |
2148 | car_max = 0x4000 ; /* maxcarrier should be<= +-1/4 Mclk */ | 2241 | car_max = 0x4000 ; /* maxcarrier should be<= +-1/4 Mclk */ |
2149 | 2242 | ||
2150 | inc = srate; | 2243 | inc = srate; |
2151 | inc /= state->mclk / 1000; | 2244 | inc /= state->internal->mclk / 1000; |
2152 | inc *= 256; | 2245 | inc *= 256; |
2153 | inc *= 256; | 2246 | inc *= 256; |
2154 | inc /= 1000; | 2247 | inc /= 1000; |
@@ -2209,7 +2302,7 @@ static int stv090x_chk_signal(struct stv090x_state *state) | |||
2209 | 2302 | ||
2210 | car_max += (car_max / 10); /* 10% margin */ | 2303 | car_max += (car_max / 10); /* 10% margin */ |
2211 | car_max = (65536 * car_max / 2); | 2304 | car_max = (65536 * car_max / 2); |
2212 | car_max /= state->mclk / 1000; | 2305 | car_max /= state->internal->mclk / 1000; |
2213 | 2306 | ||
2214 | if (car_max > 0x4000) | 2307 | if (car_max > 0x4000) |
2215 | car_max = 0x4000; | 2308 | car_max = 0x4000; |
@@ -2234,7 +2327,7 @@ static int stv090x_search_car_loop(struct stv090x_state *state, s32 inc, s32 tim | |||
2234 | car_max = state->search_range / 1000; | 2327 | car_max = state->search_range / 1000; |
2235 | car_max += (car_max / 10); | 2328 | car_max += (car_max / 10); |
2236 | car_max = (65536 * car_max / 2); | 2329 | car_max = (65536 * car_max / 2); |
2237 | car_max /= (state->mclk / 1000); | 2330 | car_max /= (state->internal->mclk / 1000); |
2238 | if (car_max > 0x4000) | 2331 | if (car_max > 0x4000) |
2239 | car_max = 0x4000; | 2332 | car_max = 0x4000; |
2240 | 2333 | ||
@@ -2304,7 +2397,7 @@ static int stv090x_sw_algo(struct stv090x_state *state) | |||
2304 | case STV090x_SEARCH_DVBS1: | 2397 | case STV090x_SEARCH_DVBS1: |
2305 | case STV090x_SEARCH_DSS: | 2398 | case STV090x_SEARCH_DSS: |
2306 | /* accelerate the frequency detector */ | 2399 | /* accelerate the frequency detector */ |
2307 | if (state->dev_ver >= 0x20) { | 2400 | if (state->internal->dev_ver >= 0x20) { |
2308 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3B) < 0) | 2401 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3B) < 0) |
2309 | goto err; | 2402 | goto err; |
2310 | } | 2403 | } |
@@ -2315,7 +2408,7 @@ static int stv090x_sw_algo(struct stv090x_state *state) | |||
2315 | break; | 2408 | break; |
2316 | 2409 | ||
2317 | case STV090x_SEARCH_DVBS2: | 2410 | case STV090x_SEARCH_DVBS2: |
2318 | if (state->dev_ver >= 0x20) { | 2411 | if (state->internal->dev_ver >= 0x20) { |
2319 | if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) | 2412 | if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) |
2320 | goto err; | 2413 | goto err; |
2321 | } | 2414 | } |
@@ -2328,7 +2421,7 @@ static int stv090x_sw_algo(struct stv090x_state *state) | |||
2328 | case STV090x_SEARCH_AUTO: | 2421 | case STV090x_SEARCH_AUTO: |
2329 | default: | 2422 | default: |
2330 | /* accelerate the frequency detector */ | 2423 | /* accelerate the frequency detector */ |
2331 | if (state->dev_ver >= 0x20) { | 2424 | if (state->internal->dev_ver >= 0x20) { |
2332 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3b) < 0) | 2425 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3b) < 0) |
2333 | goto err; | 2426 | goto err; |
2334 | if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) | 2427 | if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) |
@@ -2350,7 +2443,7 @@ static int stv090x_sw_algo(struct stv090x_state *state) | |||
2350 | /*run the SW search 2 times maximum*/ | 2443 | /*run the SW search 2 times maximum*/ |
2351 | if (lock || no_signal || (trials == 2)) { | 2444 | if (lock || no_signal || (trials == 2)) { |
2352 | /*Check if the demod is not losing lock in DVBS2*/ | 2445 | /*Check if the demod is not losing lock in DVBS2*/ |
2353 | if (state->dev_ver >= 0x20) { | 2446 | if (state->internal->dev_ver >= 0x20) { |
2354 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) | 2447 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) |
2355 | goto err; | 2448 | goto err; |
2356 | if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0) | 2449 | if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0) |
@@ -2372,7 +2465,7 @@ static int stv090x_sw_algo(struct stv090x_state *state) | |||
2372 | /*FALSE lock, The demod is loosing lock */ | 2465 | /*FALSE lock, The demod is loosing lock */ |
2373 | lock = 0; | 2466 | lock = 0; |
2374 | if (trials < 2) { | 2467 | if (trials < 2) { |
2375 | if (state->dev_ver >= 0x20) { | 2468 | if (state->internal->dev_ver >= 0x20) { |
2376 | if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) | 2469 | if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) |
2377 | goto err; | 2470 | goto err; |
2378 | } | 2471 | } |
@@ -2422,11 +2515,11 @@ static s32 stv090x_get_car_freq(struct stv090x_state *state, u32 mclk) | |||
2422 | derot |= STV090x_READ_DEMOD(state, CFR0); | 2515 | derot |= STV090x_READ_DEMOD(state, CFR0); |
2423 | 2516 | ||
2424 | derot = comp2(derot, 24); | 2517 | derot = comp2(derot, 24); |
2425 | int_1 = state->mclk >> 12; | 2518 | int_1 = mclk >> 12; |
2426 | int_2 = derot >> 12; | 2519 | int_2 = derot >> 12; |
2427 | 2520 | ||
2428 | /* carrier_frequency = MasterClock * Reg / 2^24 */ | 2521 | /* carrier_frequency = MasterClock * Reg / 2^24 */ |
2429 | tmp_1 = state->mclk % 0x1000; | 2522 | tmp_1 = mclk % 0x1000; |
2430 | tmp_2 = derot % 0x1000; | 2523 | tmp_2 = derot % 0x1000; |
2431 | 2524 | ||
2432 | derot = (int_1 * int_2) + | 2525 | derot = (int_1 * int_2) + |
@@ -2502,13 +2595,13 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st | |||
2502 | 2595 | ||
2503 | if (state->config->tuner_get_frequency) { | 2596 | if (state->config->tuner_get_frequency) { |
2504 | if (state->config->tuner_get_frequency(fe, &state->frequency) < 0) | 2597 | if (state->config->tuner_get_frequency(fe, &state->frequency) < 0) |
2505 | goto err; | 2598 | goto err_gateoff; |
2506 | } | 2599 | } |
2507 | 2600 | ||
2508 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) | 2601 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) |
2509 | goto err; | 2602 | goto err; |
2510 | 2603 | ||
2511 | offst_freq = stv090x_get_car_freq(state, state->mclk) / 1000; | 2604 | offst_freq = stv090x_get_car_freq(state, state->internal->mclk) / 1000; |
2512 | state->frequency += offst_freq; | 2605 | state->frequency += offst_freq; |
2513 | 2606 | ||
2514 | if (stv090x_get_viterbi(state) < 0) | 2607 | if (stv090x_get_viterbi(state) < 0) |
@@ -2530,7 +2623,7 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st | |||
2530 | 2623 | ||
2531 | if (state->config->tuner_get_frequency) { | 2624 | if (state->config->tuner_get_frequency) { |
2532 | if (state->config->tuner_get_frequency(fe, &state->frequency) < 0) | 2625 | if (state->config->tuner_get_frequency(fe, &state->frequency) < 0) |
2533 | goto err; | 2626 | goto err_gateoff; |
2534 | } | 2627 | } |
2535 | 2628 | ||
2536 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) | 2629 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) |
@@ -2550,6 +2643,9 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st | |||
2550 | } | 2643 | } |
2551 | 2644 | ||
2552 | return STV090x_OUTOFRANGE; | 2645 | return STV090x_OUTOFRANGE; |
2646 | |||
2647 | err_gateoff: | ||
2648 | stv090x_i2c_gate_ctrl(fe, 0); | ||
2553 | err: | 2649 | err: |
2554 | dprintk(FE_ERROR, 1, "I/O error"); | 2650 | dprintk(FE_ERROR, 1, "I/O error"); |
2555 | return -1; | 2651 | return -1; |
@@ -2579,7 +2675,7 @@ static u8 stv090x_optimize_carloop(struct stv090x_state *state, enum stv090x_mod | |||
2579 | s32 i; | 2675 | s32 i; |
2580 | struct stv090x_long_frame_crloop *car_loop, *car_loop_qpsk_low, *car_loop_apsk_low; | 2676 | struct stv090x_long_frame_crloop *car_loop, *car_loop_qpsk_low, *car_loop_apsk_low; |
2581 | 2677 | ||
2582 | if (state->dev_ver == 0x20) { | 2678 | if (state->internal->dev_ver == 0x20) { |
2583 | car_loop = stv090x_s2_crl_cut20; | 2679 | car_loop = stv090x_s2_crl_cut20; |
2584 | car_loop_qpsk_low = stv090x_s2_lowqpsk_crl_cut20; | 2680 | car_loop_qpsk_low = stv090x_s2_lowqpsk_crl_cut20; |
2585 | car_loop_apsk_low = stv090x_s2_apsk_crl_cut20; | 2681 | car_loop_apsk_low = stv090x_s2_apsk_crl_cut20; |
@@ -2700,7 +2796,7 @@ static u8 stv090x_optimize_carloop_short(struct stv090x_state *state) | |||
2700 | break; | 2796 | break; |
2701 | } | 2797 | } |
2702 | 2798 | ||
2703 | if (state->dev_ver >= 0x30) { | 2799 | if (state->internal->dev_ver >= 0x30) { |
2704 | /* Cut 3.0 and up */ | 2800 | /* Cut 3.0 and up */ |
2705 | short_crl = stv090x_s2_short_crl_cut30; | 2801 | short_crl = stv090x_s2_short_crl_cut30; |
2706 | } else { | 2802 | } else { |
@@ -2732,7 +2828,7 @@ static int stv090x_optimize_track(struct stv090x_state *state) | |||
2732 | s32 srate, pilots, aclc, f_1, f_0, i = 0, blind_tune = 0; | 2828 | s32 srate, pilots, aclc, f_1, f_0, i = 0, blind_tune = 0; |
2733 | u32 reg; | 2829 | u32 reg; |
2734 | 2830 | ||
2735 | srate = stv090x_get_srate(state, state->mclk); | 2831 | srate = stv090x_get_srate(state, state->internal->mclk); |
2736 | srate += stv090x_get_tmgoffst(state, srate); | 2832 | srate += stv090x_get_tmgoffst(state, srate); |
2737 | 2833 | ||
2738 | switch (state->delsys) { | 2834 | switch (state->delsys) { |
@@ -2751,7 +2847,7 @@ static int stv090x_optimize_track(struct stv090x_state *state) | |||
2751 | if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) | 2847 | if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) |
2752 | goto err; | 2848 | goto err; |
2753 | 2849 | ||
2754 | if (state->dev_ver >= 0x30) { | 2850 | if (state->internal->dev_ver >= 0x30) { |
2755 | if (stv090x_get_viterbi(state) < 0) | 2851 | if (stv090x_get_viterbi(state) < 0) |
2756 | goto err; | 2852 | goto err; |
2757 | 2853 | ||
@@ -2868,7 +2964,7 @@ static int stv090x_optimize_track(struct stv090x_state *state) | |||
2868 | goto err; | 2964 | goto err; |
2869 | } | 2965 | } |
2870 | 2966 | ||
2871 | if (state->dev_ver >= 0x20) { | 2967 | if (state->internal->dev_ver >= 0x20) { |
2872 | if ((state->search_mode == STV090x_SEARCH_DVBS1) || | 2968 | if ((state->search_mode == STV090x_SEARCH_DVBS1) || |
2873 | (state->search_mode == STV090x_SEARCH_DSS) || | 2969 | (state->search_mode == STV090x_SEARCH_DSS) || |
2874 | (state->search_mode == STV090x_SEARCH_AUTO)) { | 2970 | (state->search_mode == STV090x_SEARCH_AUTO)) { |
@@ -2890,7 +2986,8 @@ static int stv090x_optimize_track(struct stv090x_state *state) | |||
2890 | if (STV090x_WRITE_DEMOD(state, SFRLOW1, 0x80) < 0) | 2986 | if (STV090x_WRITE_DEMOD(state, SFRLOW1, 0x80) < 0) |
2891 | goto err; | 2987 | goto err; |
2892 | 2988 | ||
2893 | if ((state->dev_ver >= 0x20) || (blind_tune == 1) || (state->srate < 10000000)) { | 2989 | if ((state->internal->dev_ver >= 0x20) || (blind_tune == 1) || |
2990 | (state->srate < 10000000)) { | ||
2894 | /* update initial carrier freq with the found freq offset */ | 2991 | /* update initial carrier freq with the found freq offset */ |
2895 | if (STV090x_WRITE_DEMOD(state, CFRINIT1, f_1) < 0) | 2992 | if (STV090x_WRITE_DEMOD(state, CFRINIT1, f_1) < 0) |
2896 | goto err; | 2993 | goto err; |
@@ -2898,7 +2995,7 @@ static int stv090x_optimize_track(struct stv090x_state *state) | |||
2898 | goto err; | 2995 | goto err; |
2899 | state->tuner_bw = stv090x_car_width(srate, state->rolloff) + 10000000; | 2996 | state->tuner_bw = stv090x_car_width(srate, state->rolloff) + 10000000; |
2900 | 2997 | ||
2901 | if ((state->dev_ver >= 0x20) || (blind_tune == 1)) { | 2998 | if ((state->internal->dev_ver >= 0x20) || (blind_tune == 1)) { |
2902 | 2999 | ||
2903 | if (state->algo != STV090x_WARM_SEARCH) { | 3000 | if (state->algo != STV090x_WARM_SEARCH) { |
2904 | 3001 | ||
@@ -2907,7 +3004,7 @@ static int stv090x_optimize_track(struct stv090x_state *state) | |||
2907 | 3004 | ||
2908 | if (state->config->tuner_set_bandwidth) { | 3005 | if (state->config->tuner_set_bandwidth) { |
2909 | if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) | 3006 | if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) |
2910 | goto err; | 3007 | goto err_gateoff; |
2911 | } | 3008 | } |
2912 | 3009 | ||
2913 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) | 3010 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) |
@@ -2950,7 +3047,7 @@ static int stv090x_optimize_track(struct stv090x_state *state) | |||
2950 | 3047 | ||
2951 | } | 3048 | } |
2952 | 3049 | ||
2953 | if (state->dev_ver >= 0x20) { | 3050 | if (state->internal->dev_ver >= 0x20) { |
2954 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) | 3051 | if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) |
2955 | goto err; | 3052 | goto err; |
2956 | } | 3053 | } |
@@ -2959,6 +3056,9 @@ static int stv090x_optimize_track(struct stv090x_state *state) | |||
2959 | stv090x_set_vit_thtracq(state); | 3056 | stv090x_set_vit_thtracq(state); |
2960 | 3057 | ||
2961 | return 0; | 3058 | return 0; |
3059 | |||
3060 | err_gateoff: | ||
3061 | stv090x_i2c_gate_ctrl(fe, 0); | ||
2962 | err: | 3062 | err: |
2963 | dprintk(FE_ERROR, 1, "I/O error"); | 3063 | dprintk(FE_ERROR, 1, "I/O error"); |
2964 | return -1; | 3064 | return -1; |
@@ -3026,7 +3126,7 @@ static int stv090x_set_s2rolloff(struct stv090x_state *state) | |||
3026 | { | 3126 | { |
3027 | u32 reg; | 3127 | u32 reg; |
3028 | 3128 | ||
3029 | if (state->dev_ver <= 0x20) { | 3129 | if (state->internal->dev_ver <= 0x20) { |
3030 | /* rolloff to auto mode if DVBS2 */ | 3130 | /* rolloff to auto mode if DVBS2 */ |
3031 | reg = STV090x_READ_DEMOD(state, DEMOD); | 3131 | reg = STV090x_READ_DEMOD(state, DEMOD); |
3032 | STV090x_SETFIELD_Px(reg, MANUAL_SXROLLOFF_FIELD, 0x00); | 3132 | STV090x_SETFIELD_Px(reg, MANUAL_SXROLLOFF_FIELD, 0x00); |
@@ -3062,7 +3162,7 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state) | |||
3062 | if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5c) < 0) /* Demod stop */ | 3162 | if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5c) < 0) /* Demod stop */ |
3063 | goto err; | 3163 | goto err; |
3064 | 3164 | ||
3065 | if (state->dev_ver >= 0x20) { | 3165 | if (state->internal->dev_ver >= 0x20) { |
3066 | if (state->srate > 5000000) { | 3166 | if (state->srate > 5000000) { |
3067 | if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0) | 3167 | if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0) |
3068 | goto err; | 3168 | goto err; |
@@ -3102,7 +3202,7 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state) | |||
3102 | if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) | 3202 | if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) |
3103 | goto err; | 3203 | goto err; |
3104 | 3204 | ||
3105 | if (state->dev_ver >= 0x20) { | 3205 | if (state->internal->dev_ver >= 0x20) { |
3106 | if (STV090x_WRITE_DEMOD(state, KREFTMG, 0x5a) < 0) | 3206 | if (STV090x_WRITE_DEMOD(state, KREFTMG, 0x5a) < 0) |
3107 | goto err; | 3207 | goto err; |
3108 | if (state->algo == STV090x_COLD_SEARCH) | 3208 | if (state->algo == STV090x_COLD_SEARCH) |
@@ -3120,9 +3220,11 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state) | |||
3120 | if (stv090x_set_srate(state, state->srate) < 0) | 3220 | if (stv090x_set_srate(state, state->srate) < 0) |
3121 | goto err; | 3221 | goto err; |
3122 | 3222 | ||
3123 | if (stv090x_set_max_srate(state, state->mclk, state->srate) < 0) | 3223 | if (stv090x_set_max_srate(state, state->internal->mclk, |
3224 | state->srate) < 0) | ||
3124 | goto err; | 3225 | goto err; |
3125 | if (stv090x_set_min_srate(state, state->mclk, state->srate) < 0) | 3226 | if (stv090x_set_min_srate(state, state->internal->mclk, |
3227 | state->srate) < 0) | ||
3126 | goto err; | 3228 | goto err; |
3127 | 3229 | ||
3128 | if (state->srate >= 10000000) | 3230 | if (state->srate >= 10000000) |
@@ -3136,18 +3238,21 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state) | |||
3136 | goto err; | 3238 | goto err; |
3137 | 3239 | ||
3138 | if (state->config->tuner_set_bbgain) { | 3240 | if (state->config->tuner_set_bbgain) { |
3139 | if (state->config->tuner_set_bbgain(fe, 10) < 0) /* 10dB */ | 3241 | reg = state->config->tuner_bbgain; |
3140 | goto err; | 3242 | if (reg == 0) |
3243 | reg = 10; /* default: 10dB */ | ||
3244 | if (state->config->tuner_set_bbgain(fe, reg) < 0) | ||
3245 | goto err_gateoff; | ||
3141 | } | 3246 | } |
3142 | 3247 | ||
3143 | if (state->config->tuner_set_frequency) { | 3248 | if (state->config->tuner_set_frequency) { |
3144 | if (state->config->tuner_set_frequency(fe, state->frequency) < 0) | 3249 | if (state->config->tuner_set_frequency(fe, state->frequency) < 0) |
3145 | goto err; | 3250 | goto err_gateoff; |
3146 | } | 3251 | } |
3147 | 3252 | ||
3148 | if (state->config->tuner_set_bandwidth) { | 3253 | if (state->config->tuner_set_bandwidth) { |
3149 | if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) | 3254 | if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) |
3150 | goto err; | 3255 | goto err_gateoff; |
3151 | } | 3256 | } |
3152 | 3257 | ||
3153 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) | 3258 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) |
@@ -3155,21 +3260,21 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state) | |||
3155 | 3260 | ||
3156 | msleep(50); | 3261 | msleep(50); |
3157 | 3262 | ||
3158 | if (stv090x_i2c_gate_ctrl(fe, 1) < 0) | ||
3159 | goto err; | ||
3160 | |||
3161 | if (state->config->tuner_get_status) { | 3263 | if (state->config->tuner_get_status) { |
3264 | if (stv090x_i2c_gate_ctrl(fe, 1) < 0) | ||
3265 | goto err; | ||
3162 | if (state->config->tuner_get_status(fe, ®) < 0) | 3266 | if (state->config->tuner_get_status(fe, ®) < 0) |
3267 | goto err_gateoff; | ||
3268 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) | ||
3163 | goto err; | 3269 | goto err; |
3164 | } | ||
3165 | 3270 | ||
3166 | if (reg) | 3271 | if (reg) |
3167 | dprintk(FE_DEBUG, 1, "Tuner phase locked"); | 3272 | dprintk(FE_DEBUG, 1, "Tuner phase locked"); |
3168 | else | 3273 | else { |
3169 | dprintk(FE_DEBUG, 1, "Tuner unlocked"); | 3274 | dprintk(FE_DEBUG, 1, "Tuner unlocked"); |
3170 | 3275 | return STV090x_NOCARRIER; | |
3171 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) | 3276 | } |
3172 | goto err; | 3277 | } |
3173 | 3278 | ||
3174 | msleep(10); | 3279 | msleep(10); |
3175 | agc1_power = MAKEWORD16(STV090x_READ_DEMOD(state, AGCIQIN1), | 3280 | agc1_power = MAKEWORD16(STV090x_READ_DEMOD(state, AGCIQIN1), |
@@ -3194,7 +3299,7 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state) | |||
3194 | reg = STV090x_READ_DEMOD(state, DEMOD); | 3299 | reg = STV090x_READ_DEMOD(state, DEMOD); |
3195 | STV090x_SETFIELD_Px(reg, SPECINV_CONTROL_FIELD, state->inversion); | 3300 | STV090x_SETFIELD_Px(reg, SPECINV_CONTROL_FIELD, state->inversion); |
3196 | 3301 | ||
3197 | if (state->dev_ver <= 0x20) { | 3302 | if (state->internal->dev_ver <= 0x20) { |
3198 | /* rolloff to auto mode if DVBS2 */ | 3303 | /* rolloff to auto mode if DVBS2 */ |
3199 | STV090x_SETFIELD_Px(reg, MANUAL_SXROLLOFF_FIELD, 1); | 3304 | STV090x_SETFIELD_Px(reg, MANUAL_SXROLLOFF_FIELD, 1); |
3200 | } else { | 3305 | } else { |
@@ -3238,7 +3343,7 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state) | |||
3238 | if ((lock) && (signal_state == STV090x_RANGEOK)) { /* signal within Range */ | 3343 | if ((lock) && (signal_state == STV090x_RANGEOK)) { /* signal within Range */ |
3239 | stv090x_optimize_track(state); | 3344 | stv090x_optimize_track(state); |
3240 | 3345 | ||
3241 | if (state->dev_ver >= 0x20) { | 3346 | if (state->internal->dev_ver >= 0x20) { |
3242 | /* >= Cut 2.0 :release TS reset after | 3347 | /* >= Cut 2.0 :release TS reset after |
3243 | * demod lock and optimized Tracking | 3348 | * demod lock and optimized Tracking |
3244 | */ | 3349 | */ |
@@ -3293,6 +3398,8 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state) | |||
3293 | } | 3398 | } |
3294 | return signal_state; | 3399 | return signal_state; |
3295 | 3400 | ||
3401 | err_gateoff: | ||
3402 | stv090x_i2c_gate_ctrl(fe, 0); | ||
3296 | err: | 3403 | err: |
3297 | dprintk(FE_ERROR, 1, "I/O error"); | 3404 | dprintk(FE_ERROR, 1, "I/O error"); |
3298 | return -1; | 3405 | return -1; |
@@ -3303,6 +3410,9 @@ static enum dvbfe_search stv090x_search(struct dvb_frontend *fe, struct dvb_fron | |||
3303 | struct stv090x_state *state = fe->demodulator_priv; | 3410 | struct stv090x_state *state = fe->demodulator_priv; |
3304 | struct dtv_frontend_properties *props = &fe->dtv_property_cache; | 3411 | struct dtv_frontend_properties *props = &fe->dtv_property_cache; |
3305 | 3412 | ||
3413 | if (p->frequency == 0) | ||
3414 | return DVBFE_ALGO_SEARCH_INVALID; | ||
3415 | |||
3306 | state->delsys = props->delivery_system; | 3416 | state->delsys = props->delivery_system; |
3307 | state->frequency = p->frequency; | 3417 | state->frequency = p->frequency; |
3308 | state->srate = p->u.qpsk.symbol_rate; | 3418 | state->srate = p->u.qpsk.symbol_rate; |
@@ -3353,7 +3463,8 @@ static int stv090x_read_status(struct dvb_frontend *fe, enum fe_status *status) | |||
3353 | if (STV090x_GETFIELD_Px(reg, PKTDELIN_LOCK_FIELD)) { | 3463 | if (STV090x_GETFIELD_Px(reg, PKTDELIN_LOCK_FIELD)) { |
3354 | reg = STV090x_READ_DEMOD(state, TSSTATUS); | 3464 | reg = STV090x_READ_DEMOD(state, TSSTATUS); |
3355 | if (STV090x_GETFIELD_Px(reg, TSFIFO_LINEOK_FIELD)) { | 3465 | if (STV090x_GETFIELD_Px(reg, TSFIFO_LINEOK_FIELD)) { |
3356 | *status = FE_HAS_CARRIER | | 3466 | *status = FE_HAS_SIGNAL | |
3467 | FE_HAS_CARRIER | | ||
3357 | FE_HAS_VITERBI | | 3468 | FE_HAS_VITERBI | |
3358 | FE_HAS_SYNC | | 3469 | FE_HAS_SYNC | |
3359 | FE_HAS_LOCK; | 3470 | FE_HAS_LOCK; |
@@ -3370,7 +3481,11 @@ static int stv090x_read_status(struct dvb_frontend *fe, enum fe_status *status) | |||
3370 | if (STV090x_GETFIELD_Px(reg, LOCKEDVIT_FIELD)) { | 3481 | if (STV090x_GETFIELD_Px(reg, LOCKEDVIT_FIELD)) { |
3371 | reg = STV090x_READ_DEMOD(state, TSSTATUS); | 3482 | reg = STV090x_READ_DEMOD(state, TSSTATUS); |
3372 | if (STV090x_GETFIELD_Px(reg, TSFIFO_LINEOK_FIELD)) { | 3483 | if (STV090x_GETFIELD_Px(reg, TSFIFO_LINEOK_FIELD)) { |
3373 | *status = FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; | 3484 | *status = FE_HAS_SIGNAL | |
3485 | FE_HAS_CARRIER | | ||
3486 | FE_HAS_VITERBI | | ||
3487 | FE_HAS_SYNC | | ||
3488 | FE_HAS_LOCK; | ||
3374 | } | 3489 | } |
3375 | } | 3490 | } |
3376 | } | 3491 | } |
@@ -3770,6 +3885,15 @@ static void stv090x_release(struct dvb_frontend *fe) | |||
3770 | { | 3885 | { |
3771 | struct stv090x_state *state = fe->demodulator_priv; | 3886 | struct stv090x_state *state = fe->demodulator_priv; |
3772 | 3887 | ||
3888 | state->internal->num_used--; | ||
3889 | if (state->internal->num_used <= 0) { | ||
3890 | |||
3891 | dprintk(FE_ERROR, 1, "Actually removing"); | ||
3892 | |||
3893 | remove_dev(state->internal); | ||
3894 | kfree(state->internal); | ||
3895 | } | ||
3896 | |||
3773 | kfree(state); | 3897 | kfree(state); |
3774 | } | 3898 | } |
3775 | 3899 | ||
@@ -3901,10 +4025,10 @@ static int stv090x_set_mclk(struct stv090x_state *state, u32 mclk, u32 clk) | |||
3901 | if (stv090x_write_reg(state, STV090x_NCOARSE, reg) < 0) | 4025 | if (stv090x_write_reg(state, STV090x_NCOARSE, reg) < 0) |
3902 | goto err; | 4026 | goto err; |
3903 | 4027 | ||
3904 | state->mclk = stv090x_get_mclk(state); | 4028 | state->internal->mclk = stv090x_get_mclk(state); |
3905 | 4029 | ||
3906 | /*Set the DiseqC frequency to 22KHz */ | 4030 | /*Set the DiseqC frequency to 22KHz */ |
3907 | div = state->mclk / 704000; | 4031 | div = state->internal->mclk / 704000; |
3908 | if (STV090x_WRITE_DEMOD(state, F22TX, div) < 0) | 4032 | if (STV090x_WRITE_DEMOD(state, F22TX, div) < 0) |
3909 | goto err; | 4033 | goto err; |
3910 | if (STV090x_WRITE_DEMOD(state, F22RX, div) < 0) | 4034 | if (STV090x_WRITE_DEMOD(state, F22RX, div) < 0) |
@@ -3920,7 +4044,7 @@ static int stv090x_set_tspath(struct stv090x_state *state) | |||
3920 | { | 4044 | { |
3921 | u32 reg; | 4045 | u32 reg; |
3922 | 4046 | ||
3923 | if (state->dev_ver >= 0x20) { | 4047 | if (state->internal->dev_ver >= 0x20) { |
3924 | switch (state->config->ts1_mode) { | 4048 | switch (state->config->ts1_mode) { |
3925 | case STV090x_TSMODE_PARALLEL_PUNCTURED: | 4049 | case STV090x_TSMODE_PARALLEL_PUNCTURED: |
3926 | case STV090x_TSMODE_DVBCI: | 4050 | case STV090x_TSMODE_DVBCI: |
@@ -4092,6 +4216,71 @@ static int stv090x_set_tspath(struct stv090x_state *state) | |||
4092 | default: | 4216 | default: |
4093 | break; | 4217 | break; |
4094 | } | 4218 | } |
4219 | |||
4220 | if (state->config->ts1_clk > 0) { | ||
4221 | u32 speed; | ||
4222 | |||
4223 | switch (state->config->ts1_mode) { | ||
4224 | case STV090x_TSMODE_PARALLEL_PUNCTURED: | ||
4225 | case STV090x_TSMODE_DVBCI: | ||
4226 | default: | ||
4227 | speed = state->internal->mclk / | ||
4228 | (state->config->ts1_clk / 4); | ||
4229 | if (speed < 0x08) | ||
4230 | speed = 0x08; | ||
4231 | if (speed > 0xFF) | ||
4232 | speed = 0xFF; | ||
4233 | break; | ||
4234 | case STV090x_TSMODE_SERIAL_PUNCTURED: | ||
4235 | case STV090x_TSMODE_SERIAL_CONTINUOUS: | ||
4236 | speed = state->internal->mclk / | ||
4237 | (state->config->ts1_clk / 32); | ||
4238 | if (speed < 0x20) | ||
4239 | speed = 0x20; | ||
4240 | if (speed > 0xFF) | ||
4241 | speed = 0xFF; | ||
4242 | break; | ||
4243 | } | ||
4244 | reg = stv090x_read_reg(state, STV090x_P1_TSCFGM); | ||
4245 | STV090x_SETFIELD_Px(reg, TSFIFO_MANSPEED_FIELD, 3); | ||
4246 | if (stv090x_write_reg(state, STV090x_P1_TSCFGM, reg) < 0) | ||
4247 | goto err; | ||
4248 | if (stv090x_write_reg(state, STV090x_P1_TSSPEED, speed) < 0) | ||
4249 | goto err; | ||
4250 | } | ||
4251 | |||
4252 | if (state->config->ts2_clk > 0) { | ||
4253 | u32 speed; | ||
4254 | |||
4255 | switch (state->config->ts2_mode) { | ||
4256 | case STV090x_TSMODE_PARALLEL_PUNCTURED: | ||
4257 | case STV090x_TSMODE_DVBCI: | ||
4258 | default: | ||
4259 | speed = state->internal->mclk / | ||
4260 | (state->config->ts2_clk / 4); | ||
4261 | if (speed < 0x08) | ||
4262 | speed = 0x08; | ||
4263 | if (speed > 0xFF) | ||
4264 | speed = 0xFF; | ||
4265 | break; | ||
4266 | case STV090x_TSMODE_SERIAL_PUNCTURED: | ||
4267 | case STV090x_TSMODE_SERIAL_CONTINUOUS: | ||
4268 | speed = state->internal->mclk / | ||
4269 | (state->config->ts2_clk / 32); | ||
4270 | if (speed < 0x20) | ||
4271 | speed = 0x20; | ||
4272 | if (speed > 0xFF) | ||
4273 | speed = 0xFF; | ||
4274 | break; | ||
4275 | } | ||
4276 | reg = stv090x_read_reg(state, STV090x_P2_TSCFGM); | ||
4277 | STV090x_SETFIELD_Px(reg, TSFIFO_MANSPEED_FIELD, 3); | ||
4278 | if (stv090x_write_reg(state, STV090x_P2_TSCFGM, reg) < 0) | ||
4279 | goto err; | ||
4280 | if (stv090x_write_reg(state, STV090x_P2_TSSPEED, speed) < 0) | ||
4281 | goto err; | ||
4282 | } | ||
4283 | |||
4095 | reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); | 4284 | reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); |
4096 | STV090x_SETFIELD_Px(reg, RST_HWARE_FIELD, 0x01); | 4285 | STV090x_SETFIELD_Px(reg, RST_HWARE_FIELD, 0x01); |
4097 | if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) | 4286 | if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) |
@@ -4120,6 +4309,15 @@ static int stv090x_init(struct dvb_frontend *fe) | |||
4120 | const struct stv090x_config *config = state->config; | 4309 | const struct stv090x_config *config = state->config; |
4121 | u32 reg; | 4310 | u32 reg; |
4122 | 4311 | ||
4312 | if (state->internal->mclk == 0) { | ||
4313 | stv090x_set_mclk(state, 135000000, config->xtal); /* 135 Mhz */ | ||
4314 | msleep(5); | ||
4315 | if (stv090x_write_reg(state, STV090x_SYNTCTRL, | ||
4316 | 0x20 | config->clk_mode) < 0) | ||
4317 | goto err; | ||
4318 | stv090x_get_mclk(state); | ||
4319 | } | ||
4320 | |||
4123 | if (stv090x_wakeup(fe) < 0) { | 4321 | if (stv090x_wakeup(fe) < 0) { |
4124 | dprintk(FE_ERROR, 1, "Error waking device"); | 4322 | dprintk(FE_ERROR, 1, "Error waking device"); |
4125 | goto err; | 4323 | goto err; |
@@ -4142,12 +4340,12 @@ static int stv090x_init(struct dvb_frontend *fe) | |||
4142 | 4340 | ||
4143 | if (config->tuner_set_mode) { | 4341 | if (config->tuner_set_mode) { |
4144 | if (config->tuner_set_mode(fe, TUNER_WAKE) < 0) | 4342 | if (config->tuner_set_mode(fe, TUNER_WAKE) < 0) |
4145 | goto err; | 4343 | goto err_gateoff; |
4146 | } | 4344 | } |
4147 | 4345 | ||
4148 | if (config->tuner_init) { | 4346 | if (config->tuner_init) { |
4149 | if (config->tuner_init(fe) < 0) | 4347 | if (config->tuner_init(fe) < 0) |
4150 | goto err; | 4348 | goto err_gateoff; |
4151 | } | 4349 | } |
4152 | 4350 | ||
4153 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) | 4351 | if (stv090x_i2c_gate_ctrl(fe, 0) < 0) |
@@ -4157,6 +4355,9 @@ static int stv090x_init(struct dvb_frontend *fe) | |||
4157 | goto err; | 4355 | goto err; |
4158 | 4356 | ||
4159 | return 0; | 4357 | return 0; |
4358 | |||
4359 | err_gateoff: | ||
4360 | stv090x_i2c_gate_ctrl(fe, 0); | ||
4160 | err: | 4361 | err: |
4161 | dprintk(FE_ERROR, 1, "I/O error"); | 4362 | dprintk(FE_ERROR, 1, "I/O error"); |
4162 | return -1; | 4363 | return -1; |
@@ -4188,16 +4389,26 @@ static int stv090x_setup(struct dvb_frontend *fe) | |||
4188 | } | 4389 | } |
4189 | 4390 | ||
4190 | /* STV090x init */ | 4391 | /* STV090x init */ |
4191 | if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5c) < 0) /* Stop Demod */ | 4392 | |
4393 | /* Stop Demod */ | ||
4394 | if (stv090x_write_reg(state, STV090x_P1_DMDISTATE, 0x5c) < 0) | ||
4395 | goto err; | ||
4396 | if (stv090x_write_reg(state, STV090x_P2_DMDISTATE, 0x5c) < 0) | ||
4192 | goto err; | 4397 | goto err; |
4193 | 4398 | ||
4194 | msleep(5); | 4399 | msleep(5); |
4195 | 4400 | ||
4196 | if (STV090x_WRITE_DEMOD(state, TNRCFG, 0x6c) < 0) /* check register ! (No Tuner Mode) */ | 4401 | /* Set No Tuner Mode */ |
4402 | if (stv090x_write_reg(state, STV090x_P1_TNRCFG, 0x6c) < 0) | ||
4403 | goto err; | ||
4404 | if (stv090x_write_reg(state, STV090x_P2_TNRCFG, 0x6c) < 0) | ||
4197 | goto err; | 4405 | goto err; |
4198 | 4406 | ||
4407 | /* I2C repeater OFF */ | ||
4199 | STV090x_SETFIELD_Px(reg, ENARPT_LEVEL_FIELD, config->repeater_level); | 4408 | STV090x_SETFIELD_Px(reg, ENARPT_LEVEL_FIELD, config->repeater_level); |
4200 | if (STV090x_WRITE_DEMOD(state, I2CRPT, reg) < 0) /* repeater OFF */ | 4409 | if (stv090x_write_reg(state, STV090x_P1_I2CRPT, reg) < 0) |
4410 | goto err; | ||
4411 | if (stv090x_write_reg(state, STV090x_P2_I2CRPT, reg) < 0) | ||
4201 | goto err; | 4412 | goto err; |
4202 | 4413 | ||
4203 | if (stv090x_write_reg(state, STV090x_NCOARSE, 0x13) < 0) /* set PLL divider */ | 4414 | if (stv090x_write_reg(state, STV090x_NCOARSE, 0x13) < 0) /* set PLL divider */ |
@@ -4216,8 +4427,8 @@ static int stv090x_setup(struct dvb_frontend *fe) | |||
4216 | goto err; | 4427 | goto err; |
4217 | } | 4428 | } |
4218 | 4429 | ||
4219 | state->dev_ver = stv090x_read_reg(state, STV090x_MID); | 4430 | state->internal->dev_ver = stv090x_read_reg(state, STV090x_MID); |
4220 | if (state->dev_ver >= 0x20) { | 4431 | if (state->internal->dev_ver >= 0x20) { |
4221 | if (stv090x_write_reg(state, STV090x_TSGENERAL, 0x0c) < 0) | 4432 | if (stv090x_write_reg(state, STV090x_TSGENERAL, 0x0c) < 0) |
4222 | goto err; | 4433 | goto err; |
4223 | 4434 | ||
@@ -4228,27 +4439,35 @@ static int stv090x_setup(struct dvb_frontend *fe) | |||
4228 | goto err; | 4439 | goto err; |
4229 | } | 4440 | } |
4230 | 4441 | ||
4231 | } else if (state->dev_ver < 0x20) { | 4442 | } else if (state->internal->dev_ver < 0x20) { |
4232 | dprintk(FE_ERROR, 1, "ERROR: Unsupported Cut: 0x%02x!", | 4443 | dprintk(FE_ERROR, 1, "ERROR: Unsupported Cut: 0x%02x!", |
4233 | state->dev_ver); | 4444 | state->internal->dev_ver); |
4234 | 4445 | ||
4235 | goto err; | 4446 | goto err; |
4236 | } else if (state->dev_ver > 0x30) { | 4447 | } else if (state->internal->dev_ver > 0x30) { |
4237 | /* we shouldn't bail out from here */ | 4448 | /* we shouldn't bail out from here */ |
4238 | dprintk(FE_ERROR, 1, "INFO: Cut: 0x%02x probably incomplete support!", | 4449 | dprintk(FE_ERROR, 1, "INFO: Cut: 0x%02x probably incomplete support!", |
4239 | state->dev_ver); | 4450 | state->internal->dev_ver); |
4240 | } | 4451 | } |
4241 | 4452 | ||
4242 | if (stv090x_write_reg(state, STV090x_TSTRES0, 0x80) < 0) | 4453 | /* ADC1 range */ |
4454 | reg = stv090x_read_reg(state, STV090x_TSTTNR1); | ||
4455 | STV090x_SETFIELD(reg, ADC1_INMODE_FIELD, | ||
4456 | (config->adc1_range == STV090x_ADC_1Vpp) ? 0 : 1); | ||
4457 | if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0) | ||
4243 | goto err; | 4458 | goto err; |
4244 | if (stv090x_write_reg(state, STV090x_TSTRES0, 0x00) < 0) | 4459 | |
4460 | /* ADC2 range */ | ||
4461 | reg = stv090x_read_reg(state, STV090x_TSTTNR3); | ||
4462 | STV090x_SETFIELD(reg, ADC2_INMODE_FIELD, | ||
4463 | (config->adc2_range == STV090x_ADC_1Vpp) ? 0 : 1); | ||
4464 | if (stv090x_write_reg(state, STV090x_TSTTNR3, reg) < 0) | ||
4245 | goto err; | 4465 | goto err; |
4246 | 4466 | ||
4247 | stv090x_set_mclk(state, 135000000, config->xtal); /* 135 Mhz */ | 4467 | if (stv090x_write_reg(state, STV090x_TSTRES0, 0x80) < 0) |
4248 | msleep(5); | 4468 | goto err; |
4249 | if (stv090x_write_reg(state, STV090x_SYNTCTRL, 0x20 | config->clk_mode) < 0) | 4469 | if (stv090x_write_reg(state, STV090x_TSTRES0, 0x00) < 0) |
4250 | goto err; | 4470 | goto err; |
4251 | stv090x_get_mclk(state); | ||
4252 | 4471 | ||
4253 | return 0; | 4472 | return 0; |
4254 | err: | 4473 | err: |
@@ -4299,6 +4518,7 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config, | |||
4299 | enum stv090x_demodulator demod) | 4518 | enum stv090x_demodulator demod) |
4300 | { | 4519 | { |
4301 | struct stv090x_state *state = NULL; | 4520 | struct stv090x_state *state = NULL; |
4521 | struct stv090x_dev *temp_int; | ||
4302 | 4522 | ||
4303 | state = kzalloc(sizeof (struct stv090x_state), GFP_KERNEL); | 4523 | state = kzalloc(sizeof (struct stv090x_state), GFP_KERNEL); |
4304 | if (state == NULL) | 4524 | if (state == NULL) |
@@ -4314,8 +4534,32 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config, | |||
4314 | state->device = config->device; | 4534 | state->device = config->device; |
4315 | state->rolloff = STV090x_RO_35; /* default */ | 4535 | state->rolloff = STV090x_RO_35; /* default */ |
4316 | 4536 | ||
4317 | if (state->demod == STV090x_DEMODULATOR_0) | 4537 | temp_int = find_dev(state->i2c, |
4318 | mutex_init(&demod_lock); | 4538 | state->config->address); |
4539 | |||
4540 | if ((temp_int != NULL) && (state->demod_mode == STV090x_DUAL)) { | ||
4541 | state->internal = temp_int->internal; | ||
4542 | state->internal->num_used++; | ||
4543 | dprintk(FE_INFO, 1, "Found Internal Structure!"); | ||
4544 | dprintk(FE_ERROR, 1, "Attaching %s demodulator(%d) Cut=0x%02x", | ||
4545 | state->device == STV0900 ? "STV0900" : "STV0903", | ||
4546 | demod, | ||
4547 | state->internal->dev_ver); | ||
4548 | return &state->frontend; | ||
4549 | } else { | ||
4550 | state->internal = kmalloc(sizeof(struct stv090x_internal), | ||
4551 | GFP_KERNEL); | ||
4552 | temp_int = append_internal(state->internal); | ||
4553 | state->internal->num_used = 1; | ||
4554 | state->internal->mclk = 0; | ||
4555 | state->internal->dev_ver = 0; | ||
4556 | state->internal->i2c_adap = state->i2c; | ||
4557 | state->internal->i2c_addr = state->config->address; | ||
4558 | dprintk(FE_INFO, 1, "Create New Internal Structure!"); | ||
4559 | } | ||
4560 | |||
4561 | mutex_init(&state->internal->demod_lock); | ||
4562 | mutex_init(&state->internal->tuner_lock); | ||
4319 | 4563 | ||
4320 | if (stv090x_sleep(&state->frontend) < 0) { | 4564 | if (stv090x_sleep(&state->frontend) < 0) { |
4321 | dprintk(FE_ERROR, 1, "Error putting device to sleep"); | 4565 | dprintk(FE_ERROR, 1, "Error putting device to sleep"); |
@@ -4331,10 +4575,10 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config, | |||
4331 | goto error; | 4575 | goto error; |
4332 | } | 4576 | } |
4333 | 4577 | ||
4334 | dprintk(FE_ERROR, 1, "Attaching %s demodulator(%d) Cut=0x%02x\n", | 4578 | dprintk(FE_ERROR, 1, "Attaching %s demodulator(%d) Cut=0x%02x", |
4335 | state->device == STV0900 ? "STV0900" : "STV0903", | 4579 | state->device == STV0900 ? "STV0900" : "STV0903", |
4336 | demod, | 4580 | demod, |
4337 | state->dev_ver); | 4581 | state->internal->dev_ver); |
4338 | 4582 | ||
4339 | return &state->frontend; | 4583 | return &state->frontend; |
4340 | 4584 | ||
diff --git a/drivers/media/dvb/frontends/stv090x.h b/drivers/media/dvb/frontends/stv090x.h index b133807663ea..30f01a6902ac 100644 --- a/drivers/media/dvb/frontends/stv090x.h +++ b/drivers/media/dvb/frontends/stv090x.h | |||
@@ -60,6 +60,11 @@ enum stv090x_i2crpt { | |||
60 | STV090x_RPTLEVEL_2 = 7, | 60 | STV090x_RPTLEVEL_2 = 7, |
61 | }; | 61 | }; |
62 | 62 | ||
63 | enum stv090x_adc_range { | ||
64 | STV090x_ADC_2Vpp = 0, | ||
65 | STV090x_ADC_1Vpp = 1 | ||
66 | }; | ||
67 | |||
63 | struct stv090x_config { | 68 | struct stv090x_config { |
64 | enum stv090x_device device; | 69 | enum stv090x_device device; |
65 | enum stv090x_mode demod_mode; | 70 | enum stv090x_mode demod_mode; |
@@ -68,13 +73,17 @@ struct stv090x_config { | |||
68 | u32 xtal; /* default: 8000000 */ | 73 | u32 xtal; /* default: 8000000 */ |
69 | u8 address; /* default: 0x68 */ | 74 | u8 address; /* default: 0x68 */ |
70 | 75 | ||
71 | u32 ref_clk; /* default: 16000000 FIXME to tuner config */ | ||
72 | |||
73 | u8 ts1_mode; | 76 | u8 ts1_mode; |
74 | u8 ts2_mode; | 77 | u8 ts2_mode; |
78 | u32 ts1_clk; | ||
79 | u32 ts2_clk; | ||
75 | 80 | ||
76 | enum stv090x_i2crpt repeater_level; | 81 | enum stv090x_i2crpt repeater_level; |
77 | 82 | ||
83 | u8 tuner_bbgain; /* default: 10db */ | ||
84 | enum stv090x_adc_range adc1_range; /* default: 2Vpp */ | ||
85 | enum stv090x_adc_range adc2_range; /* default: 2Vpp */ | ||
86 | |||
78 | bool diseqc_envelope_mode; | 87 | bool diseqc_envelope_mode; |
79 | 88 | ||
80 | int (*tuner_init) (struct dvb_frontend *fe); | 89 | int (*tuner_init) (struct dvb_frontend *fe); |
diff --git a/drivers/media/dvb/frontends/stv090x_priv.h b/drivers/media/dvb/frontends/stv090x_priv.h index 5921a8d6c89f..5b780c80d496 100644 --- a/drivers/media/dvb/frontends/stv090x_priv.h +++ b/drivers/media/dvb/frontends/stv090x_priv.h | |||
@@ -230,11 +230,23 @@ struct stv090x_tab { | |||
230 | s32 read; | 230 | s32 read; |
231 | }; | 231 | }; |
232 | 232 | ||
233 | struct stv090x_internal { | ||
234 | struct i2c_adapter *i2c_adap; | ||
235 | u8 i2c_addr; | ||
236 | |||
237 | struct mutex demod_lock; /* Lock access to shared register */ | ||
238 | struct mutex tuner_lock; /* Lock access to tuners */ | ||
239 | s32 mclk; /* Masterclock Divider factor */ | ||
240 | u32 dev_ver; | ||
241 | |||
242 | int num_used; | ||
243 | }; | ||
244 | |||
233 | struct stv090x_state { | 245 | struct stv090x_state { |
234 | enum stv090x_device device; | 246 | enum stv090x_device device; |
235 | enum stv090x_demodulator demod; | 247 | enum stv090x_demodulator demod; |
236 | enum stv090x_mode demod_mode; | 248 | enum stv090x_mode demod_mode; |
237 | u32 dev_ver; | 249 | struct stv090x_internal *internal; |
238 | 250 | ||
239 | struct i2c_adapter *i2c; | 251 | struct i2c_adapter *i2c; |
240 | const struct stv090x_config *config; | 252 | const struct stv090x_config *config; |
@@ -256,11 +268,8 @@ struct stv090x_state { | |||
256 | u32 frequency; | 268 | u32 frequency; |
257 | u32 srate; | 269 | u32 srate; |
258 | 270 | ||
259 | s32 mclk; /* Masterclock Divider factor */ | ||
260 | s32 tuner_bw; | 271 | s32 tuner_bw; |
261 | 272 | ||
262 | u32 tuner_refclk; | ||
263 | |||
264 | s32 search_range; | 273 | s32 search_range; |
265 | 274 | ||
266 | s32 DemodTimeout; | 275 | s32 DemodTimeout; |
diff --git a/drivers/media/dvb/frontends/stv6110x.c b/drivers/media/dvb/frontends/stv6110x.c index bcfcb652464c..f931ed07e92d 100644 --- a/drivers/media/dvb/frontends/stv6110x.c +++ b/drivers/media/dvb/frontends/stv6110x.c | |||
@@ -35,8 +35,6 @@ static unsigned int verbose; | |||
35 | module_param(verbose, int, 0644); | 35 | module_param(verbose, int, 0644); |
36 | MODULE_PARM_DESC(verbose, "Set Verbosity level"); | 36 | MODULE_PARM_DESC(verbose, "Set Verbosity level"); |
37 | 37 | ||
38 | static u8 stv6110x_regs[] = {0x07, 0x11, 0xdc, 0x85, 0x17, 0x01, 0xe6, 0x1e}; | ||
39 | |||
40 | static int stv6110x_read_reg(struct stv6110x_state *stv6110x, u8 reg, u8 *data) | 38 | static int stv6110x_read_reg(struct stv6110x_state *stv6110x, u8 reg, u8 *data) |
41 | { | 39 | { |
42 | int ret; | 40 | int ret; |
@@ -58,12 +56,23 @@ static int stv6110x_read_reg(struct stv6110x_state *stv6110x, u8 reg, u8 *data) | |||
58 | return 0; | 56 | return 0; |
59 | } | 57 | } |
60 | 58 | ||
61 | static int stv6110x_write_reg(struct stv6110x_state *stv6110x, u8 reg, u8 data) | 59 | static int stv6110x_write_regs(struct stv6110x_state *stv6110x, int start, u8 data[], int len) |
62 | { | 60 | { |
63 | int ret; | 61 | int ret; |
64 | const struct stv6110x_config *config = stv6110x->config; | 62 | const struct stv6110x_config *config = stv6110x->config; |
65 | u8 buf[] = { reg, data }; | 63 | u8 buf[len + 1]; |
66 | struct i2c_msg msg = { .addr = config->addr, .flags = 0, . buf = buf, .len = 2 }; | 64 | struct i2c_msg msg = { |
65 | .addr = config->addr, | ||
66 | .flags = 0, | ||
67 | .buf = buf, | ||
68 | .len = len + 1 | ||
69 | }; | ||
70 | |||
71 | if (start + len > 8) | ||
72 | return -EINVAL; | ||
73 | |||
74 | buf[0] = start; | ||
75 | memcpy(&buf[1], data, len); | ||
67 | 76 | ||
68 | ret = i2c_transfer(stv6110x->i2c, &msg, 1); | 77 | ret = i2c_transfer(stv6110x->i2c, &msg, 1); |
69 | if (ret != 1) { | 78 | if (ret != 1) { |
@@ -74,18 +83,21 @@ static int stv6110x_write_reg(struct stv6110x_state *stv6110x, u8 reg, u8 data) | |||
74 | return 0; | 83 | return 0; |
75 | } | 84 | } |
76 | 85 | ||
86 | static int stv6110x_write_reg(struct stv6110x_state *stv6110x, u8 reg, u8 data) | ||
87 | { | ||
88 | return stv6110x_write_regs(stv6110x, reg, &data, 1); | ||
89 | } | ||
90 | |||
77 | static int stv6110x_init(struct dvb_frontend *fe) | 91 | static int stv6110x_init(struct dvb_frontend *fe) |
78 | { | 92 | { |
79 | struct stv6110x_state *stv6110x = fe->tuner_priv; | 93 | struct stv6110x_state *stv6110x = fe->tuner_priv; |
80 | int ret; | 94 | int ret; |
81 | u8 i; | ||
82 | 95 | ||
83 | for (i = 0; i < ARRAY_SIZE(stv6110x_regs); i++) { | 96 | ret = stv6110x_write_regs(stv6110x, 0, stv6110x->regs, |
84 | ret = stv6110x_write_reg(stv6110x, i, stv6110x_regs[i]); | 97 | ARRAY_SIZE(stv6110x->regs)); |
85 | if (ret < 0) { | 98 | if (ret < 0) { |
86 | dprintk(FE_ERROR, 1, "Initialization failed"); | 99 | dprintk(FE_ERROR, 1, "Initialization failed"); |
87 | return -1; | 100 | return -1; |
88 | } | ||
89 | } | 101 | } |
90 | 102 | ||
91 | return 0; | 103 | return 0; |
@@ -98,23 +110,23 @@ static int stv6110x_set_frequency(struct dvb_frontend *fe, u32 frequency) | |||
98 | s32 pVal, pCalc, rDivOpt = 0, pCalcOpt = 1000; | 110 | s32 pVal, pCalc, rDivOpt = 0, pCalcOpt = 1000; |
99 | u8 i; | 111 | u8 i; |
100 | 112 | ||
101 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_K, (REFCLOCK_MHz - 16)); | 113 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_K, (REFCLOCK_MHz - 16)); |
102 | 114 | ||
103 | if (frequency <= 1023000) { | 115 | if (frequency <= 1023000) { |
104 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_DIV4SEL, 1); | 116 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 1); |
105 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_PRESC32_ON, 0); | 117 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 0); |
106 | pVal = 40; | 118 | pVal = 40; |
107 | } else if (frequency <= 1300000) { | 119 | } else if (frequency <= 1300000) { |
108 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_DIV4SEL, 1); | 120 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 1); |
109 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_PRESC32_ON, 1); | 121 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 1); |
110 | pVal = 40; | 122 | pVal = 40; |
111 | } else if (frequency <= 2046000) { | 123 | } else if (frequency <= 2046000) { |
112 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_DIV4SEL, 0); | 124 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 0); |
113 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_PRESC32_ON, 0); | 125 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 0); |
114 | pVal = 20; | 126 | pVal = 20; |
115 | } else { | 127 | } else { |
116 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_DIV4SEL, 0); | 128 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 0); |
117 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_PRESC32_ON, 1); | 129 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 1); |
118 | pVal = 20; | 130 | pVal = 20; |
119 | } | 131 | } |
120 | 132 | ||
@@ -130,21 +142,21 @@ static int stv6110x_set_frequency(struct dvb_frontend *fe, u32 frequency) | |||
130 | divider = (frequency * R_DIV(rDivOpt) * pVal) / REFCLOCK_kHz; | 142 | divider = (frequency * R_DIV(rDivOpt) * pVal) / REFCLOCK_kHz; |
131 | divider = (divider + 5) / 10; | 143 | divider = (divider + 5) / 10; |
132 | 144 | ||
133 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_R_DIV, rDivOpt); | 145 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_R_DIV, rDivOpt); |
134 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_N_DIV_11_8, MSB(divider)); | 146 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_N_DIV_11_8, MSB(divider)); |
135 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG0], TNG0_N_DIV_7_0, LSB(divider)); | 147 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG0], TNG0_N_DIV_7_0, LSB(divider)); |
136 | 148 | ||
137 | /* VCO Auto calibration */ | 149 | /* VCO Auto calibration */ |
138 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_STAT1], STAT1_CALVCO_STRT, 1); | 150 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_STAT1], STAT1_CALVCO_STRT, 1); |
139 | 151 | ||
140 | stv6110x_write_reg(stv6110x, STV6110x_CTRL1, stv6110x_regs[STV6110x_CTRL1]); | 152 | stv6110x_write_reg(stv6110x, STV6110x_CTRL1, stv6110x->regs[STV6110x_CTRL1]); |
141 | stv6110x_write_reg(stv6110x, STV6110x_TNG1, stv6110x_regs[STV6110x_TNG1]); | 153 | stv6110x_write_reg(stv6110x, STV6110x_TNG1, stv6110x->regs[STV6110x_TNG1]); |
142 | stv6110x_write_reg(stv6110x, STV6110x_TNG0, stv6110x_regs[STV6110x_TNG0]); | 154 | stv6110x_write_reg(stv6110x, STV6110x_TNG0, stv6110x->regs[STV6110x_TNG0]); |
143 | stv6110x_write_reg(stv6110x, STV6110x_STAT1, stv6110x_regs[STV6110x_STAT1]); | 155 | stv6110x_write_reg(stv6110x, STV6110x_STAT1, stv6110x->regs[STV6110x_STAT1]); |
144 | 156 | ||
145 | for (i = 0; i < TRIALS; i++) { | 157 | for (i = 0; i < TRIALS; i++) { |
146 | stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x_regs[STV6110x_STAT1]); | 158 | stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x->regs[STV6110x_STAT1]); |
147 | if (!STV6110x_GETFIELD(STAT1_CALVCO_STRT, stv6110x_regs[STV6110x_STAT1])) | 159 | if (!STV6110x_GETFIELD(STAT1_CALVCO_STRT, stv6110x->regs[STV6110x_STAT1])) |
148 | break; | 160 | break; |
149 | msleep(1); | 161 | msleep(1); |
150 | } | 162 | } |
@@ -156,14 +168,14 @@ static int stv6110x_get_frequency(struct dvb_frontend *fe, u32 *frequency) | |||
156 | { | 168 | { |
157 | struct stv6110x_state *stv6110x = fe->tuner_priv; | 169 | struct stv6110x_state *stv6110x = fe->tuner_priv; |
158 | 170 | ||
159 | stv6110x_read_reg(stv6110x, STV6110x_TNG1, &stv6110x_regs[STV6110x_TNG1]); | 171 | stv6110x_read_reg(stv6110x, STV6110x_TNG1, &stv6110x->regs[STV6110x_TNG1]); |
160 | stv6110x_read_reg(stv6110x, STV6110x_TNG0, &stv6110x_regs[STV6110x_TNG0]); | 172 | stv6110x_read_reg(stv6110x, STV6110x_TNG0, &stv6110x->regs[STV6110x_TNG0]); |
161 | 173 | ||
162 | *frequency = (MAKEWORD16(STV6110x_GETFIELD(TNG1_N_DIV_11_8, stv6110x_regs[STV6110x_TNG1]), | 174 | *frequency = (MAKEWORD16(STV6110x_GETFIELD(TNG1_N_DIV_11_8, stv6110x->regs[STV6110x_TNG1]), |
163 | STV6110x_GETFIELD(TNG0_N_DIV_7_0, stv6110x_regs[STV6110x_TNG0]))) * REFCLOCK_kHz; | 175 | STV6110x_GETFIELD(TNG0_N_DIV_7_0, stv6110x->regs[STV6110x_TNG0]))) * REFCLOCK_kHz; |
164 | 176 | ||
165 | *frequency /= (1 << (STV6110x_GETFIELD(TNG1_R_DIV, stv6110x_regs[STV6110x_TNG1]) + | 177 | *frequency /= (1 << (STV6110x_GETFIELD(TNG1_R_DIV, stv6110x->regs[STV6110x_TNG1]) + |
166 | STV6110x_GETFIELD(TNG1_DIV4SEL, stv6110x_regs[STV6110x_TNG1]))); | 178 | STV6110x_GETFIELD(TNG1_DIV4SEL, stv6110x->regs[STV6110x_TNG1]))); |
167 | 179 | ||
168 | *frequency >>= 2; | 180 | *frequency >>= 2; |
169 | 181 | ||
@@ -179,27 +191,27 @@ static int stv6110x_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth) | |||
179 | halfbw = bandwidth >> 1; | 191 | halfbw = bandwidth >> 1; |
180 | 192 | ||
181 | if (halfbw > 36000000) | 193 | if (halfbw > 36000000) |
182 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL3], CTRL3_CF, 31); /* LPF */ | 194 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_CF, 31); /* LPF */ |
183 | else if (halfbw < 5000000) | 195 | else if (halfbw < 5000000) |
184 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL3], CTRL3_CF, 0); /* LPF */ | 196 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_CF, 0); /* LPF */ |
185 | else | 197 | else |
186 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL3], CTRL3_CF, ((halfbw / 1000000) - 5)); /* LPF */ | 198 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_CF, ((halfbw / 1000000) - 5)); /* LPF */ |
187 | 199 | ||
188 | 200 | ||
189 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL3], CTRL3_RCCLK_OFF, 0x0); /* cal. clk activated */ | 201 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_RCCLK_OFF, 0x0); /* cal. clk activated */ |
190 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_STAT1], STAT1_CALRC_STRT, 0x1); /* LPF auto cal */ | 202 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_STAT1], STAT1_CALRC_STRT, 0x1); /* LPF auto cal */ |
191 | 203 | ||
192 | stv6110x_write_reg(stv6110x, STV6110x_CTRL3, stv6110x_regs[STV6110x_CTRL3]); | 204 | stv6110x_write_reg(stv6110x, STV6110x_CTRL3, stv6110x->regs[STV6110x_CTRL3]); |
193 | stv6110x_write_reg(stv6110x, STV6110x_STAT1, stv6110x_regs[STV6110x_STAT1]); | 205 | stv6110x_write_reg(stv6110x, STV6110x_STAT1, stv6110x->regs[STV6110x_STAT1]); |
194 | 206 | ||
195 | for (i = 0; i < TRIALS; i++) { | 207 | for (i = 0; i < TRIALS; i++) { |
196 | stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x_regs[STV6110x_STAT1]); | 208 | stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x->regs[STV6110x_STAT1]); |
197 | if (!STV6110x_GETFIELD(STAT1_CALRC_STRT, stv6110x_regs[STV6110x_STAT1])) | 209 | if (!STV6110x_GETFIELD(STAT1_CALRC_STRT, stv6110x->regs[STV6110x_STAT1])) |
198 | break; | 210 | break; |
199 | msleep(1); | 211 | msleep(1); |
200 | } | 212 | } |
201 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL3], CTRL3_RCCLK_OFF, 0x1); /* cal. done */ | 213 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_RCCLK_OFF, 0x1); /* cal. done */ |
202 | stv6110x_write_reg(stv6110x, STV6110x_CTRL3, stv6110x_regs[STV6110x_CTRL3]); | 214 | stv6110x_write_reg(stv6110x, STV6110x_CTRL3, stv6110x->regs[STV6110x_CTRL3]); |
203 | 215 | ||
204 | return 0; | 216 | return 0; |
205 | } | 217 | } |
@@ -208,8 +220,8 @@ static int stv6110x_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth) | |||
208 | { | 220 | { |
209 | struct stv6110x_state *stv6110x = fe->tuner_priv; | 221 | struct stv6110x_state *stv6110x = fe->tuner_priv; |
210 | 222 | ||
211 | stv6110x_read_reg(stv6110x, STV6110x_CTRL3, &stv6110x_regs[STV6110x_CTRL3]); | 223 | stv6110x_read_reg(stv6110x, STV6110x_CTRL3, &stv6110x->regs[STV6110x_CTRL3]); |
212 | *bandwidth = (STV6110x_GETFIELD(CTRL3_CF, stv6110x_regs[STV6110x_CTRL3]) + 5) * 2000000; | 224 | *bandwidth = (STV6110x_GETFIELD(CTRL3_CF, stv6110x->regs[STV6110x_CTRL3]) + 5) * 2000000; |
213 | 225 | ||
214 | return 0; | 226 | return 0; |
215 | } | 227 | } |
@@ -222,20 +234,20 @@ static int stv6110x_set_refclock(struct dvb_frontend *fe, u32 refclock) | |||
222 | switch (refclock) { | 234 | switch (refclock) { |
223 | default: | 235 | default: |
224 | case 1: | 236 | case 1: |
225 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL2], CTRL2_CO_DIV, 0); | 237 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 0); |
226 | break; | 238 | break; |
227 | case 2: | 239 | case 2: |
228 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL2], CTRL2_CO_DIV, 1); | 240 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 1); |
229 | break; | 241 | break; |
230 | case 4: | 242 | case 4: |
231 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL2], CTRL2_CO_DIV, 2); | 243 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 2); |
232 | break; | 244 | break; |
233 | case 8: | 245 | case 8: |
234 | case 0: | 246 | case 0: |
235 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL2], CTRL2_CO_DIV, 3); | 247 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 3); |
236 | break; | 248 | break; |
237 | } | 249 | } |
238 | stv6110x_write_reg(stv6110x, STV6110x_CTRL2, stv6110x_regs[STV6110x_CTRL2]); | 250 | stv6110x_write_reg(stv6110x, STV6110x_CTRL2, stv6110x->regs[STV6110x_CTRL2]); |
239 | 251 | ||
240 | return 0; | 252 | return 0; |
241 | } | 253 | } |
@@ -244,8 +256,8 @@ static int stv6110x_get_bbgain(struct dvb_frontend *fe, u32 *gain) | |||
244 | { | 256 | { |
245 | struct stv6110x_state *stv6110x = fe->tuner_priv; | 257 | struct stv6110x_state *stv6110x = fe->tuner_priv; |
246 | 258 | ||
247 | stv6110x_read_reg(stv6110x, STV6110x_CTRL2, &stv6110x_regs[STV6110x_CTRL2]); | 259 | stv6110x_read_reg(stv6110x, STV6110x_CTRL2, &stv6110x->regs[STV6110x_CTRL2]); |
248 | *gain = 2 * STV6110x_GETFIELD(CTRL2_BBGAIN, stv6110x_regs[STV6110x_CTRL2]); | 260 | *gain = 2 * STV6110x_GETFIELD(CTRL2_BBGAIN, stv6110x->regs[STV6110x_CTRL2]); |
249 | 261 | ||
250 | return 0; | 262 | return 0; |
251 | } | 263 | } |
@@ -254,8 +266,8 @@ static int stv6110x_set_bbgain(struct dvb_frontend *fe, u32 gain) | |||
254 | { | 266 | { |
255 | struct stv6110x_state *stv6110x = fe->tuner_priv; | 267 | struct stv6110x_state *stv6110x = fe->tuner_priv; |
256 | 268 | ||
257 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL2], CTRL2_BBGAIN, gain / 2); | 269 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_BBGAIN, gain / 2); |
258 | stv6110x_write_reg(stv6110x, STV6110x_CTRL2, stv6110x_regs[STV6110x_CTRL2]); | 270 | stv6110x_write_reg(stv6110x, STV6110x_CTRL2, stv6110x->regs[STV6110x_CTRL2]); |
259 | 271 | ||
260 | return 0; | 272 | return 0; |
261 | } | 273 | } |
@@ -267,19 +279,19 @@ static int stv6110x_set_mode(struct dvb_frontend *fe, enum tuner_mode mode) | |||
267 | 279 | ||
268 | switch (mode) { | 280 | switch (mode) { |
269 | case TUNER_SLEEP: | 281 | case TUNER_SLEEP: |
270 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_SYN, 0); | 282 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_SYN, 0); |
271 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_RX, 0); | 283 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_RX, 0); |
272 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_LPT, 0); | 284 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_LPT, 0); |
273 | break; | 285 | break; |
274 | 286 | ||
275 | case TUNER_WAKE: | 287 | case TUNER_WAKE: |
276 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_SYN, 1); | 288 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_SYN, 1); |
277 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_RX, 1); | 289 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_RX, 1); |
278 | STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_LPT, 1); | 290 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_LPT, 1); |
279 | break; | 291 | break; |
280 | } | 292 | } |
281 | 293 | ||
282 | ret = stv6110x_write_reg(stv6110x, STV6110x_CTRL1, stv6110x_regs[STV6110x_CTRL1]); | 294 | ret = stv6110x_write_reg(stv6110x, STV6110x_CTRL1, stv6110x->regs[STV6110x_CTRL1]); |
283 | if (ret < 0) { | 295 | if (ret < 0) { |
284 | dprintk(FE_ERROR, 1, "I/O Error"); | 296 | dprintk(FE_ERROR, 1, "I/O Error"); |
285 | return -EIO; | 297 | return -EIO; |
@@ -297,9 +309,9 @@ static int stv6110x_get_status(struct dvb_frontend *fe, u32 *status) | |||
297 | { | 309 | { |
298 | struct stv6110x_state *stv6110x = fe->tuner_priv; | 310 | struct stv6110x_state *stv6110x = fe->tuner_priv; |
299 | 311 | ||
300 | stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x_regs[STV6110x_STAT1]); | 312 | stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x->regs[STV6110x_STAT1]); |
301 | 313 | ||
302 | if (STV6110x_GETFIELD(STAT1_LOCK, stv6110x_regs[STV6110x_STAT1])) | 314 | if (STV6110x_GETFIELD(STAT1_LOCK, stv6110x->regs[STV6110x_STAT1])) |
303 | *status = TUNER_PHASELOCKED; | 315 | *status = TUNER_PHASELOCKED; |
304 | else | 316 | else |
305 | *status = 0; | 317 | *status = 0; |
@@ -349,6 +361,8 @@ struct stv6110x_devctl *stv6110x_attach(struct dvb_frontend *fe, | |||
349 | struct i2c_adapter *i2c) | 361 | struct i2c_adapter *i2c) |
350 | { | 362 | { |
351 | struct stv6110x_state *stv6110x; | 363 | struct stv6110x_state *stv6110x; |
364 | u8 default_regs[] = {0x07, 0x11, 0xdc, 0x85, 0x17, 0x01, 0xe6, 0x1e}; | ||
365 | int ret; | ||
352 | 366 | ||
353 | stv6110x = kzalloc(sizeof (struct stv6110x_state), GFP_KERNEL); | 367 | stv6110x = kzalloc(sizeof (struct stv6110x_state), GFP_KERNEL); |
354 | if (stv6110x == NULL) | 368 | if (stv6110x == NULL) |
@@ -357,6 +371,44 @@ struct stv6110x_devctl *stv6110x_attach(struct dvb_frontend *fe, | |||
357 | stv6110x->i2c = i2c; | 371 | stv6110x->i2c = i2c; |
358 | stv6110x->config = config; | 372 | stv6110x->config = config; |
359 | stv6110x->devctl = &stv6110x_ctl; | 373 | stv6110x->devctl = &stv6110x_ctl; |
374 | memcpy(stv6110x->regs, default_regs, 8); | ||
375 | |||
376 | /* setup divider */ | ||
377 | switch (stv6110x->config->clk_div) { | ||
378 | default: | ||
379 | case 1: | ||
380 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 0); | ||
381 | break; | ||
382 | case 2: | ||
383 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 1); | ||
384 | break; | ||
385 | case 4: | ||
386 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 2); | ||
387 | break; | ||
388 | case 8: | ||
389 | case 0: | ||
390 | STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 3); | ||
391 | break; | ||
392 | } | ||
393 | |||
394 | if (fe->ops.i2c_gate_ctrl) { | ||
395 | ret = fe->ops.i2c_gate_ctrl(fe, 1); | ||
396 | if (ret < 0) | ||
397 | goto error; | ||
398 | } | ||
399 | |||
400 | ret = stv6110x_write_regs(stv6110x, 0, stv6110x->regs, | ||
401 | ARRAY_SIZE(stv6110x->regs)); | ||
402 | if (ret < 0) { | ||
403 | dprintk(FE_ERROR, 1, "Initialization failed"); | ||
404 | goto error; | ||
405 | } | ||
406 | |||
407 | if (fe->ops.i2c_gate_ctrl) { | ||
408 | ret = fe->ops.i2c_gate_ctrl(fe, 0); | ||
409 | if (ret < 0) | ||
410 | goto error; | ||
411 | } | ||
360 | 412 | ||
361 | fe->tuner_priv = stv6110x; | 413 | fe->tuner_priv = stv6110x; |
362 | fe->ops.tuner_ops = stv6110x_ops; | 414 | fe->ops.tuner_ops = stv6110x_ops; |
diff --git a/drivers/media/dvb/frontends/stv6110x.h b/drivers/media/dvb/frontends/stv6110x.h index a38257080e01..2429ae6d7847 100644 --- a/drivers/media/dvb/frontends/stv6110x.h +++ b/drivers/media/dvb/frontends/stv6110x.h | |||
@@ -26,6 +26,7 @@ | |||
26 | struct stv6110x_config { | 26 | struct stv6110x_config { |
27 | u8 addr; | 27 | u8 addr; |
28 | u32 refclk; | 28 | u32 refclk; |
29 | u8 clk_div; /* divisor value for the output clock */ | ||
29 | }; | 30 | }; |
30 | 31 | ||
31 | enum tuner_mode { | 32 | enum tuner_mode { |
diff --git a/drivers/media/dvb/frontends/stv6110x_priv.h b/drivers/media/dvb/frontends/stv6110x_priv.h index 7260da633d49..0ec936a660a7 100644 --- a/drivers/media/dvb/frontends/stv6110x_priv.h +++ b/drivers/media/dvb/frontends/stv6110x_priv.h | |||
@@ -68,6 +68,7 @@ | |||
68 | struct stv6110x_state { | 68 | struct stv6110x_state { |
69 | struct i2c_adapter *i2c; | 69 | struct i2c_adapter *i2c; |
70 | const struct stv6110x_config *config; | 70 | const struct stv6110x_config *config; |
71 | u8 regs[8]; | ||
71 | 72 | ||
72 | struct stv6110x_devctl *devctl; | 73 | struct stv6110x_devctl *devctl; |
73 | }; | 74 | }; |
diff --git a/drivers/media/dvb/frontends/tda665x.c b/drivers/media/dvb/frontends/tda665x.c index 87d52739c828..c44fefe92d97 100644 --- a/drivers/media/dvb/frontends/tda665x.c +++ b/drivers/media/dvb/frontends/tda665x.c | |||
@@ -133,7 +133,7 @@ static int tda665x_set_state(struct dvb_frontend *fe, | |||
133 | frequency += config->ref_divider >> 1; | 133 | frequency += config->ref_divider >> 1; |
134 | frequency /= config->ref_divider; | 134 | frequency /= config->ref_divider; |
135 | 135 | ||
136 | buf[0] = (u8) (frequency & 0x7f00) >> 8; | 136 | buf[0] = (u8) ((frequency & 0x7f00) >> 8); |
137 | buf[1] = (u8) (frequency & 0x00ff) >> 0; | 137 | buf[1] = (u8) (frequency & 0x00ff) >> 0; |
138 | buf[2] = 0x80 | 0x40 | 0x02; | 138 | buf[2] = 0x80 | 0x40 | 0x02; |
139 | buf[3] = 0x00; | 139 | buf[3] = 0x00; |
diff --git a/drivers/media/dvb/frontends/tda8261.c b/drivers/media/dvb/frontends/tda8261.c index 320c3c36d8b2..614afcec05f1 100644 --- a/drivers/media/dvb/frontends/tda8261.c +++ b/drivers/media/dvb/frontends/tda8261.c | |||
@@ -39,7 +39,7 @@ static int tda8261_read(struct tda8261_state *state, u8 *buf) | |||
39 | { | 39 | { |
40 | const struct tda8261_config *config = state->config; | 40 | const struct tda8261_config *config = state->config; |
41 | int err = 0; | 41 | int err = 0; |
42 | struct i2c_msg msg = { .addr = config->addr, .flags = I2C_M_RD,.buf = buf, .len = 2 }; | 42 | struct i2c_msg msg = { .addr = config->addr, .flags = I2C_M_RD,.buf = buf, .len = 1 }; |
43 | 43 | ||
44 | if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) | 44 | if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) |
45 | printk("%s: read error, err=%d\n", __func__, err); | 45 | printk("%s: read error, err=%d\n", __func__, err); |
diff --git a/drivers/media/dvb/frontends/zl10036.c b/drivers/media/dvb/frontends/zl10036.c index 4e814ff22b23..34c5de491d2b 100644 --- a/drivers/media/dvb/frontends/zl10036.c +++ b/drivers/media/dvb/frontends/zl10036.c | |||
@@ -411,7 +411,7 @@ static int zl10036_init_regs(struct zl10036_state *state) | |||
411 | state->bf = 0xff; | 411 | state->bf = 0xff; |
412 | 412 | ||
413 | if (!state->config->rf_loop_enable) | 413 | if (!state->config->rf_loop_enable) |
414 | zl10036_init_tab[1][2] |= 0x01; | 414 | zl10036_init_tab[1][0] |= 0x01; |
415 | 415 | ||
416 | deb_info("%s\n", __func__); | 416 | deb_info("%s\n", __func__); |
417 | 417 | ||
diff --git a/drivers/media/dvb/frontends/zl10039.c b/drivers/media/dvb/frontends/zl10039.c index 11b29cb883e6..c085e58a94bf 100644 --- a/drivers/media/dvb/frontends/zl10039.c +++ b/drivers/media/dvb/frontends/zl10039.c | |||
@@ -287,7 +287,6 @@ struct dvb_frontend *zl10039_attach(struct dvb_frontend *fe, | |||
287 | break; | 287 | break; |
288 | default: | 288 | default: |
289 | dprintk("Chip ID=%x does not match a known type\n", state->id); | 289 | dprintk("Chip ID=%x does not match a known type\n", state->id); |
290 | break; | ||
291 | goto error; | 290 | goto error; |
292 | } | 291 | } |
293 | 292 | ||