2 * mxl5007t.c - driver for the MaxLinear MxL5007T silicon tuner
4 * Copyright (C) 2008 Michael Krufky <mkrufky@linuxtv.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <linux/i2c.h>
22 #include <linux/types.h>
23 #include <linux/videodev2.h>
24 #include "tuner-i2c.h"
27 static DEFINE_MUTEX(mxl5007t_list_mutex);
28 static LIST_HEAD(hybrid_tuner_instance_list);
30 static int mxl5007t_debug;
31 module_param_named(debug, mxl5007t_debug, int, 0644);
32 MODULE_PARM_DESC(debug, "set debug level");
34 /* ------------------------------------------------------------------------- */
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", \
64 /* ------------------------------------------------------------------------- */
69 MxL_MODE_OTA_DVBT_ATSC = 0,
70 MxL_MODE_OTA_NTSC_PAL_GH = 1,
71 MxL_MODE_OTA_PAL_IB = 2,
72 MxL_MODE_OTA_PAL_D_SECAM_KL = 3,
73 MxL_MODE_OTA_ISDBT = 4,
74 MxL_MODE_CABLE_DIGITAL = 0x10,
75 MxL_MODE_CABLE_NTSC_PAL_GH = 0x11,
76 MxL_MODE_CABLE_PAL_IB = 0x12,
77 MxL_MODE_CABLE_PAL_D_SECAM_KL = 0x13,
78 MxL_MODE_CABLE_SCTE40 = 0x14,
81 enum mxl5007t_chip_version {
82 MxL_UNKNOWN_ID = 0x00,
83 MxL_5007_V1_F1 = 0x11,
84 MxL_5007_V1_F2 = 0x12,
85 MxL_5007_V2_100_F1 = 0x21,
86 MxL_5007_V2_100_F2 = 0x22,
87 MxL_5007_V2_200_F1 = 0x23,
88 MxL_5007_V2_200_F2 = 0x24,
96 /* ------------------------------------------------------------------------- */
98 static struct reg_pair_t init_tab[] = {
99 { 0x0b, 0x44 }, /* XTAL */
100 { 0x0c, 0x60 }, /* IF */
101 { 0x10, 0x00 }, /* MISC */
102 { 0x12, 0xca }, /* IDAC */
103 { 0x16, 0x90 }, /* MODE */
104 { 0x32, 0x38 }, /* MODE Analog/Digital */
105 { 0xd8, 0x18 }, /* CLK_OUT_ENABLE */
106 { 0x2c, 0x34 }, /* OVERRIDE */
107 { 0x4d, 0x40 }, /* OVERRIDE */
108 { 0x7f, 0x02 }, /* OVERRIDE */
109 { 0x9a, 0x52 }, /* OVERRIDE */
110 { 0x48, 0x5a }, /* OVERRIDE */
111 { 0x76, 0x1a }, /* OVERRIDE */
112 { 0x6a, 0x48 }, /* OVERRIDE */
113 { 0x64, 0x28 }, /* OVERRIDE */
114 { 0x66, 0xe6 }, /* OVERRIDE */
115 { 0x35, 0x0e }, /* OVERRIDE */
116 { 0x7e, 0x01 }, /* OVERRIDE */
117 { 0x83, 0x00 }, /* OVERRIDE */
118 { 0x04, 0x0b }, /* OVERRIDE */
119 { 0x05, 0x01 }, /* TOP_MASTER_ENABLE */
123 static struct reg_pair_t init_tab_cable[] = {
124 { 0x0b, 0x44 }, /* XTAL */
125 { 0x0c, 0x60 }, /* IF */
126 { 0x10, 0x00 }, /* MISC */
127 { 0x12, 0xca }, /* IDAC */
128 { 0x16, 0x90 }, /* MODE */
129 { 0x32, 0x38 }, /* MODE A/D */
130 { 0x71, 0x3f }, /* TOP1 */
131 { 0x72, 0x3f }, /* TOP2 */
132 { 0x74, 0x3f }, /* TOP3 */
133 { 0xd8, 0x18 }, /* CLK_OUT_ENABLE */
134 { 0x2c, 0x34 }, /* OVERRIDE */
135 { 0x4d, 0x40 }, /* OVERRIDE */
136 { 0x7f, 0x02 }, /* OVERRIDE */
137 { 0x9a, 0x52 }, /* OVERRIDE */
138 { 0x48, 0x5a }, /* OVERRIDE */
139 { 0x76, 0x1a }, /* OVERRIDE */
140 { 0x6a, 0x48 }, /* OVERRIDE */
141 { 0x64, 0x28 }, /* OVERRIDE */
142 { 0x66, 0xe6 }, /* OVERRIDE */
143 { 0x35, 0x0e }, /* OVERRIDE */
144 { 0x7e, 0x01 }, /* OVERRIDE */
145 { 0x04, 0x0b }, /* OVERRIDE */
146 { 0x68, 0xb4 }, /* OVERRIDE */
147 { 0x36, 0x00 }, /* OVERRIDE */
148 { 0x05, 0x01 }, /* TOP_MASTER_ENABLE */
152 /* ------------------------------------------------------------------------- */
154 static struct reg_pair_t reg_pair_rftune[] = {
155 { 0x11, 0x00 }, /* abort tune */
159 { 0x11, 0x02 }, /* start tune */
163 /* ------------------------------------------------------------------------- */
165 struct mxl5007t_state {
166 struct list_head hybrid_tuner_instance_list;
167 struct tuner_i2c_props i2c_props;
171 struct mxl5007t_config *config;
173 enum mxl5007t_chip_version chip_id;
175 struct reg_pair_t tab_init[ARRAY_SIZE(init_tab)];
176 struct reg_pair_t tab_init_cable[ARRAY_SIZE(init_tab_cable)];
177 struct reg_pair_t tab_rftune[ARRAY_SIZE(reg_pair_rftune)];
183 /* ------------------------------------------------------------------------- */
185 /* called by _init and _rftun to manipulate the register arrays */
187 static void set_reg_bits(struct reg_pair_t *reg_pair, u8 reg, u8 mask, u8 val)
191 while (reg_pair[i].reg || reg_pair[i].val) {
192 if (reg_pair[i].reg == reg) {
193 reg_pair[i].val &= ~mask;
194 reg_pair[i].val |= val;
202 static void copy_reg_bits(struct reg_pair_t *reg_pair1,
203 struct reg_pair_t *reg_pair2)
209 while (reg_pair1[i].reg || reg_pair1[i].val) {
210 while (reg_pair2[j].reg || reg_pair2[j].reg) {
211 if (reg_pair1[i].reg != reg_pair2[j].reg) {
215 reg_pair2[j].val = reg_pair1[i].val;
223 /* ------------------------------------------------------------------------- */
225 static void mxl5007t_set_mode_bits(struct mxl5007t_state *state,
226 enum mxl5007t_mode mode,
227 s32 if_diff_out_level)
230 case MxL_MODE_OTA_DVBT_ATSC:
231 set_reg_bits(state->tab_init, 0x32, 0x0f, 0x06);
232 set_reg_bits(state->tab_init, 0x35, 0xff, 0x0e);
234 case MxL_MODE_OTA_ISDBT:
235 set_reg_bits(state->tab_init, 0x32, 0x0f, 0x06);
236 set_reg_bits(state->tab_init, 0x35, 0xff, 0x12);
238 case MxL_MODE_OTA_NTSC_PAL_GH:
239 set_reg_bits(state->tab_init, 0x16, 0x70, 0x00);
240 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
242 case MxL_MODE_OTA_PAL_IB:
243 set_reg_bits(state->tab_init, 0x16, 0x70, 0x10);
244 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
246 case MxL_MODE_OTA_PAL_D_SECAM_KL:
247 set_reg_bits(state->tab_init, 0x16, 0x70, 0x20);
248 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
250 case MxL_MODE_CABLE_DIGITAL:
251 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
252 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
253 8 - if_diff_out_level);
254 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
256 case MxL_MODE_CABLE_NTSC_PAL_GH:
257 set_reg_bits(state->tab_init, 0x16, 0x70, 0x00);
258 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
259 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
260 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
261 8 - if_diff_out_level);
262 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
264 case MxL_MODE_CABLE_PAL_IB:
265 set_reg_bits(state->tab_init, 0x16, 0x70, 0x10);
266 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
267 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
268 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
269 8 - if_diff_out_level);
270 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
272 case MxL_MODE_CABLE_PAL_D_SECAM_KL:
273 set_reg_bits(state->tab_init, 0x16, 0x70, 0x20);
274 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
275 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
276 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
277 8 - if_diff_out_level);
278 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
280 case MxL_MODE_CABLE_SCTE40:
281 set_reg_bits(state->tab_init_cable, 0x36, 0xff, 0x08);
282 set_reg_bits(state->tab_init_cable, 0x68, 0xff, 0xbc);
283 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
284 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
285 8 - if_diff_out_level);
286 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
294 static void mxl5007t_set_if_freq_bits(struct mxl5007t_state *state,
295 enum mxl5007t_if_freq if_freq,
307 case MxL_IF_4_57_MHZ:
313 case MxL_IF_5_38_MHZ:
319 case MxL_IF_6_28_MHZ:
322 case MxL_IF_9_1915_MHZ:
325 case MxL_IF_35_25_MHZ:
328 case MxL_IF_36_15_MHZ:
338 set_reg_bits(state->tab_init, 0x0c, 0xf0, val);
340 /* set inverted IF or normal IF */
341 set_reg_bits(state->tab_init, 0x0c, 0x08, invert_if ? 0x08 : 0x00);
346 static void mxl5007t_set_xtal_freq_bits(struct mxl5007t_state *state,
347 enum mxl5007t_xtal_freq xtal_freq)
352 case MxL_XTAL_16_MHZ:
353 val = 0x00; /* select xtal freq & Ref Freq */
355 case MxL_XTAL_20_MHZ:
358 case MxL_XTAL_20_25_MHZ:
361 case MxL_XTAL_20_48_MHZ:
364 case MxL_XTAL_24_MHZ:
367 case MxL_XTAL_25_MHZ:
370 case MxL_XTAL_25_14_MHZ:
373 case MxL_XTAL_27_MHZ:
376 case MxL_XTAL_28_8_MHZ:
379 case MxL_XTAL_32_MHZ:
382 case MxL_XTAL_40_MHZ:
385 case MxL_XTAL_44_MHZ:
388 case MxL_XTAL_48_MHZ:
391 case MxL_XTAL_49_3811_MHZ:
398 set_reg_bits(state->tab_init, 0x0b, 0xff, val);
403 static struct reg_pair_t *mxl5007t_calc_init_regs(struct mxl5007t_state *state,
404 enum mxl5007t_mode mode)
406 struct mxl5007t_config *cfg = state->config;
408 memcpy(&state->tab_init, &init_tab, sizeof(init_tab));
409 memcpy(&state->tab_init_cable, &init_tab_cable, sizeof(init_tab_cable));
411 mxl5007t_set_mode_bits(state, mode, cfg->if_diff_out_level);
412 mxl5007t_set_if_freq_bits(state, cfg->if_freq_hz, cfg->invert_if);
413 mxl5007t_set_xtal_freq_bits(state, cfg->xtal_freq_hz);
415 set_reg_bits(state->tab_init, 0x10, 0x40, cfg->loop_thru_enable << 6);
417 set_reg_bits(state->tab_init, 0xd8, 0x08, cfg->clk_out_enable << 3);
419 set_reg_bits(state->tab_init, 0x10, 0x07, cfg->clk_out_amp);
421 /* set IDAC to automatic mode control by AGC */
422 set_reg_bits(state->tab_init, 0x12, 0x80, 0x00);
424 if (mode >= MxL_MODE_CABLE_DIGITAL) {
425 copy_reg_bits(state->tab_init, state->tab_init_cable);
426 return state->tab_init_cable;
428 return state->tab_init;
431 /* ------------------------------------------------------------------------- */
433 enum mxl5007t_bw_mhz {
439 static void mxl5007t_set_bw_bits(struct mxl5007t_state *state,
440 enum mxl5007t_bw_mhz bw)
446 val = 0x15; /* set DIG_MODEINDEX, DIG_MODEINDEX_A,
447 * and DIG_MODEINDEX_CSF */
459 set_reg_bits(state->tab_rftune, 0x13, 0x3f, val);
465 reg_pair_t *mxl5007t_calc_rf_tune_regs(struct mxl5007t_state *state,
466 u32 rf_freq, enum mxl5007t_bw_mhz bw)
470 u32 frac_divider = 1000000;
473 memcpy(&state->tab_rftune, ®_pair_rftune, sizeof(reg_pair_rftune));
475 mxl5007t_set_bw_bits(state, bw);
477 /* Convert RF frequency into 16 bits =>
478 * 10 bit integer (MHz) + 6 bit fraction */
479 dig_rf_freq = rf_freq / MHz;
481 temp = rf_freq % MHz;
483 for (i = 0; i < 6; i++) {
486 if (temp > frac_divider) {
487 temp -= frac_divider;
492 /* add to have shift center point by 7.8124 kHz */
496 set_reg_bits(state->tab_rftune, 0x14, 0xff, (u8)dig_rf_freq);
497 set_reg_bits(state->tab_rftune, 0x15, 0xff, (u8)(dig_rf_freq >> 8));
499 return state->tab_rftune;
502 /* ------------------------------------------------------------------------- */
504 static int mxl5007t_write_reg(struct mxl5007t_state *state, u8 reg, u8 val)
506 u8 buf[] = { reg, val };
507 struct i2c_msg msg = { .addr = state->i2c_props.addr, .flags = 0,
508 .buf = buf, .len = 2 };
511 ret = i2c_transfer(state->i2c_props.adap, &msg, 1);
519 static int mxl5007t_write_regs(struct mxl5007t_state *state,
520 struct reg_pair_t *reg_pair)
525 while ((ret == 0) && (reg_pair[i].reg || reg_pair[i].val)) {
526 ret = mxl5007t_write_reg(state,
527 reg_pair[i].reg, reg_pair[i].val);
533 static int mxl5007t_read_reg(struct mxl5007t_state *state, u8 reg, u8 *val)
535 struct i2c_msg msg[] = {
536 { .addr = state->i2c_props.addr, .flags = 0,
537 .buf = ®, .len = 1 },
538 { .addr = state->i2c_props.addr, .flags = I2C_M_RD,
539 .buf = val, .len = 1 },
543 ret = i2c_transfer(state->i2c_props.adap, msg, 2);
551 static int mxl5007t_soft_reset(struct mxl5007t_state *state)
554 struct i2c_msg msg = { .addr = state->i2c_props.addr, .flags = 0,
555 .buf = &d, .len = 1 };
557 int ret = i2c_transfer(state->i2c_props.adap, &msg, 1);
566 static int mxl5007t_tuner_init(struct mxl5007t_state *state,
567 enum mxl5007t_mode mode)
569 struct reg_pair_t *init_regs;
572 ret = mxl5007t_soft_reset(state);
576 /* calculate initialization reg array */
577 init_regs = mxl5007t_calc_init_regs(state, mode);
579 ret = mxl5007t_write_regs(state, init_regs);
584 ret = mxl5007t_write_reg(state, 0x2c, 0x35);
590 static int mxl5007t_tuner_rf_tune(struct mxl5007t_state *state, u32 rf_freq_hz,
591 enum mxl5007t_bw_mhz bw)
593 struct reg_pair_t *rf_tune_regs;
596 /* calculate channel change reg array */
597 rf_tune_regs = mxl5007t_calc_rf_tune_regs(state, rf_freq_hz, bw);
599 ret = mxl5007t_write_regs(state, rf_tune_regs);
607 /* ------------------------------------------------------------------------- */
609 static int mxl5007t_synth_lock_status(struct mxl5007t_state *state,
610 int *rf_locked, int *ref_locked)
618 ret = mxl5007t_read_reg(state, 0xcf, &d);
622 if ((d & 0x0c) == 0x0c)
625 if ((d & 0x03) == 0x03)
631 static int mxl5007t_check_rf_input_power(struct mxl5007t_state *state,
637 ret = mxl5007t_read_reg(state, 0xb7, &d1);
641 ret = mxl5007t_read_reg(state, 0xbf, &d2);
649 *rf_input_level = (s32)(d1 + d2 - 113);
654 /* ------------------------------------------------------------------------- */
656 static int mxl5007t_get_status(struct dvb_frontend *fe, u32 *status)
658 struct mxl5007t_state *state = fe->tuner_priv;
659 int rf_locked, ref_locked;
663 if (fe->ops.i2c_gate_ctrl)
664 fe->ops.i2c_gate_ctrl(fe, 1);
666 ret = mxl5007t_synth_lock_status(state, &rf_locked, &ref_locked);
669 mxl_debug("%s%s", rf_locked ? "rf locked " : "",
670 ref_locked ? "ref locked" : "");
672 ret = mxl5007t_check_rf_input_power(state, &rf_input_level);
675 mxl_debug("rf input power: %d", rf_input_level);
677 if (fe->ops.i2c_gate_ctrl)
678 fe->ops.i2c_gate_ctrl(fe, 0);
683 /* ------------------------------------------------------------------------- */
685 static int mxl5007t_set_params(struct dvb_frontend *fe,
686 struct dvb_frontend_parameters *params)
688 struct mxl5007t_state *state = fe->tuner_priv;
689 enum mxl5007t_bw_mhz bw;
690 enum mxl5007t_mode mode;
692 u32 freq = params->frequency;
694 if (fe->ops.info.type == FE_ATSC) {
695 switch (params->u.vsb.modulation) {
698 mode = MxL_MODE_OTA_DVBT_ATSC;
702 mode = MxL_MODE_CABLE_DIGITAL;
705 mxl_err("modulation not set!");
709 } else if (fe->ops.info.type == FE_OFDM) {
710 switch (params->u.ofdm.bandwidth) {
711 case BANDWIDTH_6_MHZ:
714 case BANDWIDTH_7_MHZ:
717 case BANDWIDTH_8_MHZ:
721 mxl_err("bandwidth not set!");
724 mode = MxL_MODE_OTA_DVBT_ATSC;
726 mxl_err("modulation type not supported!");
730 if (fe->ops.i2c_gate_ctrl)
731 fe->ops.i2c_gate_ctrl(fe, 1);
733 mutex_lock(&state->lock);
735 ret = mxl5007t_tuner_init(state, mode);
739 ret = mxl5007t_tuner_rf_tune(state, freq, bw);
743 state->frequency = freq;
744 state->bandwidth = (fe->ops.info.type == FE_OFDM) ?
745 params->u.ofdm.bandwidth : 0;
747 mutex_unlock(&state->lock);
749 if (fe->ops.i2c_gate_ctrl)
750 fe->ops.i2c_gate_ctrl(fe, 0);
755 static int mxl5007t_set_analog_params(struct dvb_frontend *fe,
756 struct analog_parameters *params)
758 struct mxl5007t_state *state = fe->tuner_priv;
759 enum mxl5007t_bw_mhz bw = 0; /* FIXME */
760 enum mxl5007t_mode cbl_mode;
761 enum mxl5007t_mode ota_mode;
764 u32 freq = params->frequency * 62500;
767 if (params->std & V4L2_STD_MN) {
768 cbl_mode = MxL_MODE_CABLE_NTSC_PAL_GH;
769 ota_mode = MxL_MODE_OTA_NTSC_PAL_GH;
771 } else if (params->std & V4L2_STD_B) {
772 cbl_mode = MxL_MODE_CABLE_PAL_IB;
773 ota_mode = MxL_MODE_OTA_PAL_IB;
775 } else if (params->std & V4L2_STD_GH) {
776 cbl_mode = MxL_MODE_CABLE_NTSC_PAL_GH;
777 ota_mode = MxL_MODE_OTA_NTSC_PAL_GH;
779 } else if (params->std & V4L2_STD_PAL_I) {
780 cbl_mode = MxL_MODE_CABLE_PAL_IB;
781 ota_mode = MxL_MODE_OTA_PAL_IB;
783 } else if (params->std & V4L2_STD_DK) {
784 cbl_mode = MxL_MODE_CABLE_PAL_D_SECAM_KL;
785 ota_mode = MxL_MODE_OTA_PAL_D_SECAM_KL;
787 } else if (params->std & V4L2_STD_SECAM_L) {
788 cbl_mode = MxL_MODE_CABLE_PAL_D_SECAM_KL;
789 ota_mode = MxL_MODE_OTA_PAL_D_SECAM_KL;
791 } else if (params->std & V4L2_STD_SECAM_LC) {
792 cbl_mode = MxL_MODE_CABLE_PAL_D_SECAM_KL;
793 ota_mode = MxL_MODE_OTA_PAL_D_SECAM_KL;
798 cbl_mode = MxL_MODE_CABLE_NTSC_PAL_GH;
799 ota_mode = MxL_MODE_OTA_NTSC_PAL_GH;
801 mxl_debug("setting mxl5007 to system %s", mode_name);
803 if (fe->ops.i2c_gate_ctrl)
804 fe->ops.i2c_gate_ctrl(fe, 1);
806 mutex_lock(&state->lock);
808 ret = mxl5007t_tuner_init(state, cable ? cbl_mode : ota_mode);
812 ret = mxl5007t_tuner_rf_tune(state, freq, bw);
816 state->frequency = freq;
817 state->bandwidth = 0;
819 mutex_unlock(&state->lock);
821 if (fe->ops.i2c_gate_ctrl)
822 fe->ops.i2c_gate_ctrl(fe, 0);
827 /* ------------------------------------------------------------------------- */
829 static int mxl5007t_init(struct dvb_frontend *fe)
831 struct mxl5007t_state *state = fe->tuner_priv;
835 if (fe->ops.i2c_gate_ctrl)
836 fe->ops.i2c_gate_ctrl(fe, 1);
838 ret = mxl5007t_read_reg(state, 0x05, &d);
842 ret = mxl5007t_write_reg(state, 0x05, d | 0x01);
845 if (fe->ops.i2c_gate_ctrl)
846 fe->ops.i2c_gate_ctrl(fe, 0);
851 static int mxl5007t_sleep(struct dvb_frontend *fe)
853 struct mxl5007t_state *state = fe->tuner_priv;
857 if (fe->ops.i2c_gate_ctrl)
858 fe->ops.i2c_gate_ctrl(fe, 1);
860 ret = mxl5007t_read_reg(state, 0x05, &d);
864 ret = mxl5007t_write_reg(state, 0x05, d & ~0x01);
867 if (fe->ops.i2c_gate_ctrl)
868 fe->ops.i2c_gate_ctrl(fe, 0);
873 /* ------------------------------------------------------------------------- */
875 static int mxl5007t_get_frequency(struct dvb_frontend *fe, u32 *frequency)
877 struct mxl5007t_state *state = fe->tuner_priv;
878 *frequency = state->frequency;
882 static int mxl5007t_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
884 struct mxl5007t_state *state = fe->tuner_priv;
885 *bandwidth = state->bandwidth;
889 static int mxl5007t_release(struct dvb_frontend *fe)
891 struct mxl5007t_state *state = fe->tuner_priv;
893 mutex_lock(&mxl5007t_list_mutex);
896 hybrid_tuner_release_state(state);
898 mutex_unlock(&mxl5007t_list_mutex);
900 fe->tuner_priv = NULL;
905 /* ------------------------------------------------------------------------- */
907 static struct dvb_tuner_ops mxl5007t_tuner_ops = {
909 .name = "MaxLinear MxL5007T",
911 .init = mxl5007t_init,
912 .sleep = mxl5007t_sleep,
913 .set_params = mxl5007t_set_params,
914 .set_analog_params = mxl5007t_set_analog_params,
915 .get_status = mxl5007t_get_status,
916 .get_frequency = mxl5007t_get_frequency,
917 .get_bandwidth = mxl5007t_get_bandwidth,
918 .release = mxl5007t_release,
921 static int mxl5007t_get_chip_id(struct mxl5007t_state *state)
927 ret = mxl5007t_read_reg(state, 0xd3, &id);
933 name = "MxL5007.v1.f1";
936 name = "MxL5007.v1.f2";
938 case MxL_5007_V2_100_F1:
939 name = "MxL5007.v2.100.f1";
941 case MxL_5007_V2_100_F2:
942 name = "MxL5007.v2.100.f2";
944 case MxL_5007_V2_200_F1:
945 name = "MxL5007.v2.200.f1";
947 case MxL_5007_V2_200_F2:
948 name = "MxL5007.v2.200.f2";
955 mxl_info("%s detected @ %d-%04x", name,
956 i2c_adapter_id(state->i2c_props.adap),
957 state->i2c_props.addr);
960 mxl_warn("unable to identify device @ %d-%04x",
961 i2c_adapter_id(state->i2c_props.adap),
962 state->i2c_props.addr);
964 state->chip_id = MxL_UNKNOWN_ID;
968 struct dvb_frontend *mxl5007t_attach(struct dvb_frontend *fe,
969 struct i2c_adapter *i2c, u8 addr,
970 struct mxl5007t_config *cfg)
972 struct mxl5007t_state *state = NULL;
975 mutex_lock(&mxl5007t_list_mutex);
976 instance = hybrid_tuner_request_state(struct mxl5007t_state, state,
977 hybrid_tuner_instance_list,
978 i2c, addr, "mxl5007");
983 /* new tuner instance */
986 mutex_init(&state->lock);
988 if (fe->ops.i2c_gate_ctrl)
989 fe->ops.i2c_gate_ctrl(fe, 1);
991 ret = mxl5007t_get_chip_id(state);
993 if (fe->ops.i2c_gate_ctrl)
994 fe->ops.i2c_gate_ctrl(fe, 0);
996 /* check return value of mxl5007t_get_chip_id */
1001 /* existing tuner instance */
1004 fe->tuner_priv = state;
1005 mutex_unlock(&mxl5007t_list_mutex);
1007 memcpy(&fe->ops.tuner_ops, &mxl5007t_tuner_ops,
1008 sizeof(struct dvb_tuner_ops));
1012 mutex_unlock(&mxl5007t_list_mutex);
1014 mxl5007t_release(fe);
1017 EXPORT_SYMBOL_GPL(mxl5007t_attach);
1018 MODULE_DESCRIPTION("MaxLinear MxL5007T Silicon IC tuner driver");
1019 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1020 MODULE_LICENSE("GPL");
1021 MODULE_VERSION("0.1");
1024 * Overrides for Emacs so that we follow Linus's tabbing style.
1025 * ---------------------------------------------------------------------------