28 #include <asm/div64.h>
70 (
u8) ((value & 0x300) >> 8));
97 err(
"invalid pos in read word agc");
132 static int af9005_get_post_vit_err_cw_count(
struct dvb_frontend *fe,
133 u32 * post_err_count,
155 deb_info(
"rsd counter not ready\n");
171 loc_abort_count = ((
u16) temp1 << 8) +
temp0;
189 err_count = ((
u32) temp2 << 16) + ((
u32) temp1 << 8) +
temp0;
190 *post_err_count = err_count - (
u32) loc_abort_count *8 * 8;
203 cw_count = ((
u32) temp1 << 8) +
temp0;
205 err(
"wrong RSD packet count");
208 deb_info(
"POST abort count %d err count %d rsd packets %d\n",
209 loc_abort_count, err_count, cw_count);
210 *post_cw_count = cw_count - (
u32) loc_abort_count;
211 *abort_count = loc_abort_count;
216 static int af9005_get_post_vit_ber(
struct dvb_frontend *fe,
217 u32 * post_err_count,
u32 * post_cw_count,
220 u32 loc_cw_count = 0, loc_err_count;
221 u16 loc_abort_count = 0;
225 af9005_get_post_vit_err_cw_count(fe, &loc_err_count, &loc_cw_count,
229 *post_err_count = loc_err_count;
230 *post_cw_count = loc_cw_count * 204 * 8;
231 *abort_count = loc_abort_count;
236 static int af9005_get_pre_vit_err_bit_count(
struct dvb_frontend *fe,
252 deb_info(
"viterbi counter not ready\n");
270 *pre_err_count = ((
u32) temp2 << 16) + ((
u32) temp1 << 8) +
temp0;
282 super_frame_count = ((
u32) temp1 << 8) +
temp0;
283 if (super_frame_count == 0) {
298 }
else if (temp == 1) {
302 err(
"Invalid fft mode");
324 err(
"invalid modulation mode");
327 *pre_bit_count = super_frame_count * 68 * 4 * x *
bits;
328 deb_info(
"PRE err count %d frame count %d bit count %d\n",
329 *pre_err_count, super_frame_count, *pre_bit_count);
333 static int af9005_reset_pre_viterbi(
struct dvb_frontend *fe)
357 static int af9005_reset_post_viterbi(
struct dvb_frontend *fe)
382 static int af9005_get_statistic(
struct dvb_frontend *fe)
385 int ret, fecavailable;
386 u64 numerator, denominator;
389 ret = af9005_is_fecmon_available(fe, &fecavailable);
400 af9005_reset_pre_viterbi(fe);
408 state->
ber =
do_div(numerator, denominator);
410 state->
ber = 0xffffffff;
418 ret = af9005_reset_post_viterbi(fe);
426 static int af9005_fe_refresh_state(
struct dvb_frontend *fe)
433 if (af9005_get_statistic(fe))
434 err(
"get_statistic_failed");
446 if (fe->
ops.tuner_ops.release ==
NULL)
482 if (temp != state->
strong) {
483 deb_info(
"adjust for strong signal %d\n", temp);
492 if (fe->
ops.tuner_ops.release ==
NULL)
494 af9005_fe_refresh_state(fe);
502 if (fe->
ops.tuner_ops.release ==
NULL)
504 af9005_fe_refresh_state(fe);
509 static int af9005_fe_read_signal_strength(
struct dvb_frontend *fe,
516 if (fe->
ops.tuner_ops.release ==
NULL)
530 *strength = (512 - rf_gain - if_gain) << 7;
546 u32 NS_coeff1_2048Nu;
547 u32 NS_coeff1_8191Nu;
548 u32 NS_coeff1_8192Nu;
549 u32 NS_coeff1_8193Nu;
555 NS_coeff1_2048Nu = 0x2ADB6DC;
556 NS_coeff1_8191Nu = 0xAB7313;
557 NS_coeff1_8192Nu = 0xAB6DB7;
558 NS_coeff1_8193Nu = 0xAB685C;
559 NS_coeff2_2k = 0x156DB6E;
560 NS_coeff2_8k = 0x55B6DC;
564 NS_coeff1_2048Nu = 0x3200001;
565 NS_coeff1_8191Nu = 0xC80640;
566 NS_coeff1_8192Nu = 0xC80000;
567 NS_coeff1_8193Nu = 0xC7F9C0;
568 NS_coeff2_2k = 0x1900000;
569 NS_coeff2_8k = 0x640000;
573 NS_coeff1_2048Nu = 0x3924926;
574 NS_coeff1_8191Nu = 0xE4996E;
575 NS_coeff1_8192Nu = 0xE49249;
576 NS_coeff1_8193Nu = 0xE48B25;
577 NS_coeff2_2k = 0x1C92493;
578 NS_coeff2_8k = 0x724925;
581 err(
"Invalid bandwidth %d.", bw);
589 temp0 = (
u8) (NS_coeff1_2048Nu & 0x000000FF);
590 temp1 = (
u8) ((NS_coeff1_2048Nu & 0x0000FF00) >> 8);
591 temp2 = (
u8) ((NS_coeff1_2048Nu & 0x00FF0000) >> 16);
592 temp3 = (
u8) ((NS_coeff1_2048Nu & 0x03000000) >> 24);
624 temp0 = (
u8) ((NS_coeff2_2k & 0x0000003F));
625 temp1 = (
u8) ((NS_coeff2_2k & 0x00003FC0) >> 6);
626 temp2 = (
u8) ((NS_coeff2_2k & 0x003FC000) >> 14);
627 temp3 = (
u8) ((NS_coeff2_2k & 0x01C00000) >> 22);
655 temp0 = (
u8) ((NS_coeff1_8191Nu & 0x000000FF));
656 temp1 = (
u8) ((NS_coeff1_8191Nu & 0x0000FF00) >> 8);
657 temp2 = (
u8) ((NS_coeff1_8191Nu & 0x00FFC000) >> 16);
658 temp3 = (
u8) ((NS_coeff1_8191Nu & 0x03000000) >> 24);
686 temp0 = (
u8) (NS_coeff1_8192Nu & 0x000000FF);
687 temp1 = (
u8) ((NS_coeff1_8192Nu & 0x0000FF00) >> 8);
688 temp2 = (
u8) ((NS_coeff1_8192Nu & 0x00FFC000) >> 16);
689 temp3 = (
u8) ((NS_coeff1_8192Nu & 0x03000000) >> 24);
717 temp0 = (
u8) ((NS_coeff1_8193Nu & 0x000000FF));
718 temp1 = (
u8) ((NS_coeff1_8193Nu & 0x0000FF00) >> 8);
719 temp2 = (
u8) ((NS_coeff1_8193Nu & 0x00FFC000) >> 16);
720 temp3 = (
u8) ((NS_coeff1_8193Nu & 0x03000000) >> 24);
748 temp0 = (
u8) ((NS_coeff2_8k & 0x0000003F));
749 temp1 = (
u8) ((NS_coeff2_8k & 0x00003FC0) >> 6);
750 temp2 = (
u8) ((NS_coeff2_8k & 0x003FC000) >> 14);
751 temp3 = (
u8) ((NS_coeff2_8k & 0x01C00000) >> 22);
790 err(
"Invalid bandwidth %d.", bw);
797 static int af9005_fe_power(
struct dvb_frontend *fe,
int on)
802 deb_info(
"power %s tuner\n", on ?
"on" :
"off");
819 int ret,
i, scriptlen;
820 u8 temp, temp0 = 0, temp1 = 0, temp2 = 0;
836 for (i = 0; i < 150; i++) {
899 deb_info(
"set dca upper & lower chip\n");
912 deb_info(
"set 2wire master clock to 0x14 (for 60KHz)\n");
918 deb_info(
"clear dca enable chip\n");
933 ret = af9005_fe_program_cfoe(state->
d, 6000000);
937 deb_info(
"set read-update bit for modulation\n");
948 deb_info(
"set read-update bit 1 for DCA modulation\n");
967 deb_info(
"set api_retrain_never_freeze\n");
974 for (i = 0; i < scriptlen; i++) {
1000 ((
u32) temp2 << 16) + ((
u32) temp1 << 8) + (
u32) temp0;
1008 af9005_read_word_agc(state->
d,
1017 af9005_read_word_agc(state->
d,
1026 af9005_read_word_agc(state->
d, 0xA60E, 0xA60A, 4, 2,
1033 af9005_read_word_agc(state->
d, 0xA60E, 0xA60B, 6, 2,
1039 if (fe->
ops.tuner_ops.release ==
NULL) {
1043 err(
"Impossible to read EEPROM\n");
1046 deb_info(
"Tuner id %d, board id %d\n", buf[0], buf[1]);
1052 err(
"Impossible to read EEPROM\n");
1055 if1 = (
u16) (buf[0] << 8) + buf[1];
1057 &af9005_mt2060_config, if1) ==
NULL) {
1058 deb_info(
"MT2060 attach failed\n");
1065 &af9005_qt1010_config) ==
NULL) {
1066 deb_info(
"QT1010 attach failed\n");
1071 err(
"Unsupported tuner type %d", buf[0]);
1074 ret = fe->
ops.tuner_ops.init(fe);
1085 return af9005_fe_power(fe, 0);
1088 static int af9005_ts_bus_ctrl(
struct dvb_frontend *fe,
int acquire)
1103 static int af9005_fe_set_frontend(
struct dvb_frontend *fe)
1112 if (fe->
ops.tuner_ops.release ==
NULL) {
1113 err(
"Tuner not attached");
1128 deb_info(
"set FCW to default value\n");
1143 deb_info(
"restore original TOPs\n");
1145 af9005_write_word_agc(state->
d,
1152 af9005_write_word_agc(state->
d,
1159 af9005_write_word_agc(state->
d, 0xA60E, 0xA60A, 4, 2,
1164 af9005_write_word_agc(state->
d, 0xA60E, 0xA60B, 6, 2,
1179 deb_info(
"clear easy mode flag\n");
1185 deb_info(
"set unplug threshold to original value\n");
1193 ret = fe->
ops.tuner_ops.set_params(fe);
1205 deb_info(
"clear retrain and freeze flag\n");
1214 af9005_reset_pre_viterbi(fe);
1215 af9005_reset_post_viterbi(fe);
1229 static int af9005_fe_get_frontend(
struct dvb_frontend *fe)
1243 deb_info(
"===== fe_get_frontend_legacy = =============\n");
1294 deb_info(
"PRIORITY %s\n", temp ?
"high" :
"low");
1443 deb_info(
"attaching frontend af9005\n");
1460 .name =
"AF9005 USB DVB-T",
1461 .frequency_min = 44250000,
1462 .frequency_max = 867250000,
1463 .frequency_stepsize = 250000,
1473 .release = af9005_fe_release,
1475 .init = af9005_fe_init,
1476 .sleep = af9005_fe_sleep,
1477 .ts_bus_ctrl = af9005_ts_bus_ctrl,
1479 .set_frontend = af9005_fe_set_frontend,
1480 .get_frontend = af9005_fe_get_frontend,
1482 .read_status = af9005_fe_read_status,
1483 .read_ber = af9005_fe_read_ber,
1484 .read_signal_strength = af9005_fe_read_signal_strength,
1485 .read_snr = af9005_fe_read_snr,
1486 .read_ucblocks = af9005_fe_read_unc_blocks,