21 #include <linux/i2c.h>
22 #include <linux/types.h>
23 #include <linux/videodev2.h>
28 static LIST_HEAD(hybrid_tuner_instance_list);
30 static int mxl5007t_debug;
36 #define mxl_printk(kern, fmt, arg...) \
37 printk(kern "%s: " fmt "\n", __func__, ##arg)
39 #define mxl_err(fmt, arg...) \
40 mxl_printk(KERN_ERR, "%d: " fmt, __LINE__, ##arg)
42 #define mxl_warn(fmt, arg...) \
43 mxl_printk(KERN_WARNING, fmt, ##arg)
45 #define mxl_info(fmt, arg...) \
46 mxl_printk(KERN_INFO, fmt, ##arg)
48 #define mxl_debug(fmt, arg...) \
51 mxl_printk(KERN_DEBUG, fmt, ##arg); \
54 #define mxl_fail(ret) \
59 mxl_printk(KERN_ERR, "error %d on line %d", \
138 static struct reg_pair_t reg_pair_rftune[] = {
182 while (reg_pair[i].reg || reg_pair[i].val) {
183 if (reg_pair[i].reg == reg) {
184 reg_pair[
i].
val &= ~mask;
193 static void copy_reg_bits(
struct reg_pair_t *reg_pair1,
200 while (reg_pair1[i].
reg || reg_pair1[i].
val) {
201 while (reg_pair2[j].
reg || reg_pair2[j].val) {
202 if (reg_pair1[i].
reg != reg_pair2[j].
reg) {
206 reg_pair2[
j].
val = reg_pair1[
i].
val;
218 s32 if_diff_out_level)
233 8 - if_diff_out_level);
242 static void mxl5007t_set_if_freq_bits(
struct mxl5007t_state *state,
296 static void mxl5007t_set_xtal_freq_bits(
struct mxl5007t_state *state,
427 u32 frac_divider = 1000000;
432 mxl5007t_set_bw_bits(state, bw);
436 dig_rf_freq = rf_freq /
MHz;
438 temp = rf_freq %
MHz;
440 for (i = 0; i < 6; i++) {
443 if (temp > frac_divider) {
444 temp -= frac_divider;
456 if (rf_freq >= 333000000)
468 .buf =
buf, .len = 2 };
485 while ((ret == 0) && (reg_pair[i].reg || reg_pair[i].val)) {
486 ret = mxl5007t_write_reg(state,
487 reg_pair[i].reg, reg_pair[i].val);
495 u8 buf[2] = { 0xfb, reg };
498 .buf =
buf, .len = 2 },
500 .buf =
val, .len = 1 },
534 ret = mxl5007t_soft_reset(state);
539 init_regs = mxl5007t_calc_init_regs(state, mode);
541 ret = mxl5007t_write_regs(state, init_regs);
556 rf_tune_regs = mxl5007t_calc_rf_tune_regs(state, rf_freq_hz, bw);
558 ret = mxl5007t_write_regs(state, rf_tune_regs);
568 static int mxl5007t_synth_lock_status(
struct mxl5007t_state *state,
569 int *rf_locked,
int *ref_locked)
577 ret = mxl5007t_read_reg(state, 0xd8, &d);
581 if ((d & 0x0c) == 0x0c)
584 if ((d & 0x03) == 0x03)
595 int rf_locked, ref_locked,
ret;
599 if (fe->
ops.i2c_gate_ctrl)
600 fe->
ops.i2c_gate_ctrl(fe, 1);
602 ret = mxl5007t_synth_lock_status(state, &rf_locked, &ref_locked);
605 mxl_debug(
"%s%s", rf_locked ?
"rf locked " :
"",
606 ref_locked ?
"ref locked" :
"");
608 if ((rf_locked) || (ref_locked))
611 if (fe->
ops.i2c_gate_ctrl)
612 fe->
ops.i2c_gate_ctrl(fe, 0);
656 mxl_err(
"modulation type not supported!");
660 if (fe->
ops.i2c_gate_ctrl)
661 fe->
ops.i2c_gate_ctrl(fe, 1);
665 ret = mxl5007t_tuner_init(state, mode);
669 ret = mxl5007t_tuner_rf_tune(state, freq, bw);
678 if (fe->
ops.i2c_gate_ctrl)
679 fe->
ops.i2c_gate_ctrl(fe, 0);
691 if (fe->
ops.i2c_gate_ctrl)
692 fe->
ops.i2c_gate_ctrl(fe, 1);
695 ret = mxl5007t_write_reg(state, 0x01, 0x01);
698 if (fe->
ops.i2c_gate_ctrl)
699 fe->
ops.i2c_gate_ctrl(fe, 0);
709 if (fe->
ops.i2c_gate_ctrl)
710 fe->
ops.i2c_gate_ctrl(fe, 1);
713 ret = mxl5007t_write_reg(state, 0x01, 0x00);
715 ret = mxl5007t_write_reg(state, 0x0f, 0x00);
718 if (fe->
ops.i2c_gate_ctrl)
719 fe->
ops.i2c_gate_ctrl(fe, 0);
748 *frequency = 4000000;
751 *frequency = 4500000;
754 *frequency = 4570000;
757 *frequency = 5000000;
760 *frequency = 5380000;
763 *frequency = 6000000;
766 *frequency = 6280000;
769 *frequency = 9191500;
772 *frequency = 35250000;
775 *frequency = 36150000;
778 *frequency = 44000000;
804 .name =
"MaxLinear MxL5007T",
806 .init = mxl5007t_init,
807 .sleep = mxl5007t_sleep,
808 .set_params = mxl5007t_set_params,
809 .get_status = mxl5007t_get_status,
810 .get_frequency = mxl5007t_get_frequency,
811 .get_bandwidth = mxl5007t_get_bandwidth,
812 .release = mxl5007t_release,
813 .get_if_frequency = mxl5007t_get_if_frequency,
822 ret = mxl5007t_read_reg(state, 0xd9, &
id);
828 name =
"MxL5007.v1.f1";
831 name =
"MxL5007.v1.f2";
834 name =
"MxL5007.v2.100.f1";
837 name =
"MxL5007.v2.100.f2";
840 name =
"MxL5007.v2.200.f1";
843 name =
"MxL5007.v2.200.f2";
846 name =
"MxL5007T.v4";
854 mxl_info(
"%s detected @ %d-%04x", name,
859 mxl_warn(
"unable to identify device @ %d-%04x",
877 i2c, addr,
"mxl5007t");
887 if (fe->
ops.i2c_gate_ctrl)
888 fe->
ops.i2c_gate_ctrl(fe, 1);
890 ret = mxl5007t_get_chip_id(state);
892 if (fe->
ops.i2c_gate_ctrl)
893 fe->
ops.i2c_gate_ctrl(fe, 0);
906 memcpy(&fe->
ops.tuner_ops, &mxl5007t_tuner_ops,
913 mxl5007t_release(fe);