22 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/string.h>
33 #define dprintk(arg...)\
226 static int au8522_mse2snr_lookup(
struct mse2snr_tab *tab,
int sz,
int mse,
232 for (i = 0; i < sz; i++) {
233 if (mse < tab[i].
val) {
239 dprintk(
"%s() snr=%d\n", __func__, *snr);
269 dprintk(
"%s() IF Frequency not supported\n", __func__);
272 dprintk(
"%s() %s MHz\n", __func__, ifmhz);
318 } QAM64_mod_tab[] = {
397 } QAM256_mod_tab[] = {
472 static int au8522_enable_modulation(
struct dvb_frontend *fe,
478 dprintk(
"%s(0x%08x)\n", __func__, m);
482 dprintk(
"%s() VSB_8\n", __func__);
486 VSB_mod_tab[i].
data);
487 au8522_set_if(fe, state->
config->vsb_if);
490 dprintk(
"%s() QAM 64\n", __func__);
491 for (i = 0; i <
ARRAY_SIZE(QAM64_mod_tab); i++)
493 QAM64_mod_tab[i].reg,
494 QAM64_mod_tab[i].data);
495 au8522_set_if(fe, state->
config->qam_if);
498 dprintk(
"%s() QAM 256\n", __func__);
499 for (i = 0; i <
ARRAY_SIZE(QAM256_mod_tab); i++)
501 QAM256_mod_tab[i].reg,
502 QAM256_mod_tab[i].data);
503 au8522_set_if(fe, state->
config->qam_if);
506 dprintk(
"%s() Invalid modulation\n", __func__);
528 if (fe->
ops.tuner_ops.set_params) {
529 if (fe->
ops.i2c_gate_ctrl)
530 fe->
ops.i2c_gate_ctrl(fe, 1);
531 ret = fe->
ops.tuner_ops.set_params(fe);
532 if (fe->
ops.i2c_gate_ctrl)
533 fe->
ops.i2c_gate_ctrl(fe, 0);
558 dprintk(
"%s() Checking VSB_8\n", __func__);
560 if ((reg & 0x03) == 0x03)
563 dprintk(
"%s() Checking QAM\n", __func__);
571 switch (state->
config->status_mode) {
573 dprintk(
"%s() DEMODLOCKING\n", __func__);
579 dprintk(
"%s() TUNERLOCKING\n", __func__);
580 if (fe->
ops.tuner_ops.get_status) {
581 if (fe->
ops.i2c_gate_ctrl)
582 fe->
ops.i2c_gate_ctrl(fe, 1);
584 fe->
ops.tuner_ops.get_status(fe, &tuner_status);
586 if (fe->
ops.i2c_gate_ctrl)
587 fe->
ops.i2c_gate_ctrl(fe, 0);
602 dprintk(
"%s() status 0x%08x\n", __func__, *status);
607 static int au8522_led_status(
struct au8522_state *state,
const u16 *snr)
632 (((strong < *snr) ? (*snr - strong) : (strong - *snr)) <= 10))
648 ret = au8522_mse2snr_lookup(qam256_mse2snr_tab,
653 ret = au8522_mse2snr_lookup(qam64_mse2snr_tab,
658 ret = au8522_mse2snr_lookup(vsb_mse2snr_tab,
663 if (state->
config->led_cfg)
664 au8522_led_status(state, snr);
669 static int au8522_read_signal_strength(
struct dvb_frontend *fe,
670 u16 *signal_strength)
681 int ret = au8522_read_snr(fe, &snr);
683 *signal_strength = 0;
691 tmp = (snr * ((1 << 24) / 10));
695 if (tmp >= 8960 * 0x10000)
696 *signal_strength = 0xffff;
698 *signal_strength = tmp / 8960;
704 static int au8522_read_ucblocks(
struct dvb_frontend *fe,
u32 *ucblocks)
718 return au8522_read_ucblocks(fe, ber);
732 static int au8522_get_tune_settings(
struct dvb_frontend *fe,
758 dprintk(
"%s state allocation failed\n", __func__);
762 dprintk(
"%s using new instance\n", __func__);
766 dprintk(
"%s using existing instance\n", __func__);
802 .name =
"Auvitek AU8522 QAM/8VSB Frontend",
803 .frequency_min = 54000000,
804 .frequency_max = 858000000,
805 .frequency_stepsize = 62500,
812 .set_frontend = au8522_set_frontend,
813 .get_frontend = au8522_get_frontend,
814 .get_tune_settings = au8522_get_tune_settings,
815 .read_status = au8522_read_status,
816 .read_ber = au8522_read_ber,
817 .read_signal_strength = au8522_read_signal_strength,
818 .read_snr = au8522_read_snr,
819 .read_ucblocks = au8522_read_ucblocks,
820 .release = au8522_release,