Lines Matching +full:switch +full:- +full:mode +full:- +full:frequency

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * mxl5007t.c - driver for the MaxLinear MxL5007T silicon tuner
11 #include "tuner-i2c.h"
21 /* ------------------------------------------------------------------------- */
51 /* ------------------------------------------------------------------------- */
76 /* ------------------------------------------------------------------------- */
121 /* ------------------------------------------------------------------------- */
137 /* ------------------------------------------------------------------------- */
155 u32 frequency; member
159 /* ------------------------------------------------------------------------- */
197 /* ------------------------------------------------------------------------- */
200 enum mxl5007t_mode mode, in mxl5007t_set_mode_bits() argument
203 switch (mode) { in mxl5007t_set_mode_bits()
205 set_reg_bits(state->tab_init, 0x06, 0x1f, 0x12); in mxl5007t_set_mode_bits()
208 set_reg_bits(state->tab_init, 0x06, 0x1f, 0x11); in mxl5007t_set_mode_bits()
211 set_reg_bits(state->tab_init, 0x06, 0x1f, 0x10); in mxl5007t_set_mode_bits()
214 set_reg_bits(state->tab_init_cable, 0x09, 0xff, 0xc1); in mxl5007t_set_mode_bits()
215 set_reg_bits(state->tab_init_cable, 0x0a, 0xff, in mxl5007t_set_mode_bits()
216 8 - if_diff_out_level); in mxl5007t_set_mode_bits()
217 set_reg_bits(state->tab_init_cable, 0x0b, 0xff, 0x17); in mxl5007t_set_mode_bits()
220 mxl_fail(-EINVAL); in mxl5007t_set_mode_bits()
230 switch (if_freq) { in mxl5007t_set_if_freq_bits()
265 mxl_fail(-EINVAL); in mxl5007t_set_if_freq_bits()
268 set_reg_bits(state->tab_init, 0x02, 0x0f, val); in mxl5007t_set_if_freq_bits()
271 set_reg_bits(state->tab_init, 0x02, 0x10, invert_if ? 0x10 : 0x00); in mxl5007t_set_if_freq_bits()
273 state->if_freq = if_freq; in mxl5007t_set_if_freq_bits()
279 switch (xtal_freq) { in mxl5007t_set_xtal_freq_bits()
282 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x00); in mxl5007t_set_xtal_freq_bits()
283 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x00); in mxl5007t_set_xtal_freq_bits()
286 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x10); in mxl5007t_set_xtal_freq_bits()
287 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x01); in mxl5007t_set_xtal_freq_bits()
290 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x20); in mxl5007t_set_xtal_freq_bits()
291 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x02); in mxl5007t_set_xtal_freq_bits()
294 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x30); in mxl5007t_set_xtal_freq_bits()
295 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x03); in mxl5007t_set_xtal_freq_bits()
298 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x40); in mxl5007t_set_xtal_freq_bits()
299 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x04); in mxl5007t_set_xtal_freq_bits()
302 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x50); in mxl5007t_set_xtal_freq_bits()
303 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x05); in mxl5007t_set_xtal_freq_bits()
306 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x60); in mxl5007t_set_xtal_freq_bits()
307 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x06); in mxl5007t_set_xtal_freq_bits()
310 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x70); in mxl5007t_set_xtal_freq_bits()
311 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x07); in mxl5007t_set_xtal_freq_bits()
314 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x80); in mxl5007t_set_xtal_freq_bits()
315 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x08); in mxl5007t_set_xtal_freq_bits()
318 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x90); in mxl5007t_set_xtal_freq_bits()
319 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x09); in mxl5007t_set_xtal_freq_bits()
322 set_reg_bits(state->tab_init, 0x03, 0xf0, 0xa0); in mxl5007t_set_xtal_freq_bits()
323 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x0a); in mxl5007t_set_xtal_freq_bits()
326 set_reg_bits(state->tab_init, 0x03, 0xf0, 0xb0); in mxl5007t_set_xtal_freq_bits()
327 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x0b); in mxl5007t_set_xtal_freq_bits()
330 set_reg_bits(state->tab_init, 0x03, 0xf0, 0xc0); in mxl5007t_set_xtal_freq_bits()
331 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x0c); in mxl5007t_set_xtal_freq_bits()
334 set_reg_bits(state->tab_init, 0x03, 0xf0, 0xd0); in mxl5007t_set_xtal_freq_bits()
335 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x0d); in mxl5007t_set_xtal_freq_bits()
338 mxl_fail(-EINVAL); in mxl5007t_set_xtal_freq_bits()
344 enum mxl5007t_mode mode) in mxl5007t_calc_init_regs() argument
346 struct mxl5007t_config *cfg = state->config; in mxl5007t_calc_init_regs()
348 memcpy(&state->tab_init, &init_tab, sizeof(init_tab)); in mxl5007t_calc_init_regs()
349 memcpy(&state->tab_init_cable, &init_tab_cable, sizeof(init_tab_cable)); in mxl5007t_calc_init_regs()
351 mxl5007t_set_mode_bits(state, mode, cfg->if_diff_out_level); in mxl5007t_calc_init_regs()
352 mxl5007t_set_if_freq_bits(state, cfg->if_freq_hz, cfg->invert_if); in mxl5007t_calc_init_regs()
353 mxl5007t_set_xtal_freq_bits(state, cfg->xtal_freq_hz); in mxl5007t_calc_init_regs()
355 set_reg_bits(state->tab_init, 0x03, 0x08, cfg->clk_out_enable << 3); in mxl5007t_calc_init_regs()
356 set_reg_bits(state->tab_init, 0x03, 0x07, cfg->clk_out_amp); in mxl5007t_calc_init_regs()
358 if (mode >= MxL_MODE_CABLE) { in mxl5007t_calc_init_regs()
359 copy_reg_bits(state->tab_init, state->tab_init_cable); in mxl5007t_calc_init_regs()
360 return state->tab_init_cable; in mxl5007t_calc_init_regs()
362 return state->tab_init; in mxl5007t_calc_init_regs()
365 /* ------------------------------------------------------------------------- */
378 switch (bw) { in mxl5007t_set_bw_bits()
390 mxl_fail(-EINVAL); in mxl5007t_set_bw_bits()
393 set_reg_bits(state->tab_rftune, 0x0c, 0x3f, val); in mxl5007t_set_bw_bits()
405 memcpy(&state->tab_rftune, &reg_pair_rftune, sizeof(reg_pair_rftune)); in mxl5007t_calc_rf_tune_regs()
409 /* Convert RF frequency into 16 bits => in mxl5007t_calc_rf_tune_regs()
419 temp -= frac_divider; in mxl5007t_calc_rf_tune_regs()
428 set_reg_bits(state->tab_rftune, 0x0d, 0xff, (u8) dig_rf_freq); in mxl5007t_calc_rf_tune_regs()
429 set_reg_bits(state->tab_rftune, 0x0e, 0xff, (u8) (dig_rf_freq >> 8)); in mxl5007t_calc_rf_tune_regs()
432 set_reg_bits(state->tab_rftune, 0x80, 0x40, 0x40); in mxl5007t_calc_rf_tune_regs()
434 return state->tab_rftune; in mxl5007t_calc_rf_tune_regs()
437 /* ------------------------------------------------------------------------- */
442 struct i2c_msg msg = { .addr = state->i2c_props.addr, .flags = 0, in mxl5007t_write_reg()
446 ret = i2c_transfer(state->i2c_props.adap, &msg, 1); in mxl5007t_write_reg()
449 return -EREMOTEIO; in mxl5007t_write_reg()
472 { .addr = state->i2c_props.addr, .flags = 0, in mxl5007t_read_reg()
474 { .addr = state->i2c_props.addr, .flags = I2C_M_RD, in mxl5007t_read_reg()
479 ret = i2c_transfer(state->i2c_props.adap, msg, 2); in mxl5007t_read_reg()
482 return -EREMOTEIO; in mxl5007t_read_reg()
491 .addr = state->i2c_props.addr, .flags = 0, in mxl5007t_soft_reset()
494 int ret = i2c_transfer(state->i2c_props.adap, &msg, 1); in mxl5007t_soft_reset()
498 return -EREMOTEIO; in mxl5007t_soft_reset()
504 enum mxl5007t_mode mode) in mxl5007t_tuner_init() argument
510 init_regs = mxl5007t_calc_init_regs(state, mode); in mxl5007t_tuner_init()
537 /* ------------------------------------------------------------------------- */
561 /* ------------------------------------------------------------------------- */
565 struct mxl5007t_state *state = fe->tuner_priv; in mxl5007t_get_status()
570 if (fe->ops.i2c_gate_ctrl) in mxl5007t_get_status()
571 fe->ops.i2c_gate_ctrl(fe, 1); in mxl5007t_get_status()
582 if (fe->ops.i2c_gate_ctrl) in mxl5007t_get_status()
583 fe->ops.i2c_gate_ctrl(fe, 0); in mxl5007t_get_status()
588 /* ------------------------------------------------------------------------- */
592 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in mxl5007t_set_params()
593 u32 delsys = c->delivery_system; in mxl5007t_set_params()
594 struct mxl5007t_state *state = fe->tuner_priv; in mxl5007t_set_params()
596 enum mxl5007t_mode mode; in mxl5007t_set_params() local
598 u32 freq = c->frequency; in mxl5007t_set_params()
600 switch (delsys) { in mxl5007t_set_params()
602 mode = MxL_MODE_ATSC; in mxl5007t_set_params()
606 mode = MxL_MODE_CABLE; in mxl5007t_set_params()
611 mode = MxL_MODE_DVBT; in mxl5007t_set_params()
612 switch (c->bandwidth_hz) { in mxl5007t_set_params()
623 return -EINVAL; in mxl5007t_set_params()
628 return -EINVAL; in mxl5007t_set_params()
631 if (fe->ops.i2c_gate_ctrl) in mxl5007t_set_params()
632 fe->ops.i2c_gate_ctrl(fe, 1); in mxl5007t_set_params()
634 mutex_lock(&state->lock); in mxl5007t_set_params()
636 ret = mxl5007t_tuner_init(state, mode); in mxl5007t_set_params()
644 state->frequency = freq; in mxl5007t_set_params()
645 state->bandwidth = c->bandwidth_hz; in mxl5007t_set_params()
647 mutex_unlock(&state->lock); in mxl5007t_set_params()
649 if (fe->ops.i2c_gate_ctrl) in mxl5007t_set_params()
650 fe->ops.i2c_gate_ctrl(fe, 0); in mxl5007t_set_params()
655 /* ------------------------------------------------------------------------- */
659 struct mxl5007t_state *state = fe->tuner_priv; in mxl5007t_init()
662 if (fe->ops.i2c_gate_ctrl) in mxl5007t_init()
663 fe->ops.i2c_gate_ctrl(fe, 1); in mxl5007t_init()
669 if (fe->ops.i2c_gate_ctrl) in mxl5007t_init()
670 fe->ops.i2c_gate_ctrl(fe, 0); in mxl5007t_init()
677 struct mxl5007t_state *state = fe->tuner_priv; in mxl5007t_sleep()
680 if (fe->ops.i2c_gate_ctrl) in mxl5007t_sleep()
681 fe->ops.i2c_gate_ctrl(fe, 1); in mxl5007t_sleep()
683 /* enter standby mode */ in mxl5007t_sleep()
689 if (fe->ops.i2c_gate_ctrl) in mxl5007t_sleep()
690 fe->ops.i2c_gate_ctrl(fe, 0); in mxl5007t_sleep()
695 /* ------------------------------------------------------------------------- */
697 static int mxl5007t_get_frequency(struct dvb_frontend *fe, u32 *frequency) in mxl5007t_get_frequency() argument
699 struct mxl5007t_state *state = fe->tuner_priv; in mxl5007t_get_frequency()
700 *frequency = state->frequency; in mxl5007t_get_frequency()
706 struct mxl5007t_state *state = fe->tuner_priv; in mxl5007t_get_bandwidth()
707 *bandwidth = state->bandwidth; in mxl5007t_get_bandwidth()
711 static int mxl5007t_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) in mxl5007t_get_if_frequency() argument
713 struct mxl5007t_state *state = fe->tuner_priv; in mxl5007t_get_if_frequency()
715 *frequency = 0; in mxl5007t_get_if_frequency()
717 switch (state->if_freq) { in mxl5007t_get_if_frequency()
719 *frequency = 4000000; in mxl5007t_get_if_frequency()
722 *frequency = 4500000; in mxl5007t_get_if_frequency()
725 *frequency = 4570000; in mxl5007t_get_if_frequency()
728 *frequency = 5000000; in mxl5007t_get_if_frequency()
731 *frequency = 5380000; in mxl5007t_get_if_frequency()
734 *frequency = 6000000; in mxl5007t_get_if_frequency()
737 *frequency = 6280000; in mxl5007t_get_if_frequency()
740 *frequency = 9191500; in mxl5007t_get_if_frequency()
743 *frequency = 35250000; in mxl5007t_get_if_frequency()
746 *frequency = 36150000; in mxl5007t_get_if_frequency()
749 *frequency = 44000000; in mxl5007t_get_if_frequency()
757 struct mxl5007t_state *state = fe->tuner_priv; in mxl5007t_release()
766 fe->tuner_priv = NULL; in mxl5007t_release()
769 /* ------------------------------------------------------------------------- */
795 switch (id) { in mxl5007t_get_chip_id()
822 state->chip_id = id; in mxl5007t_get_chip_id()
823 mxl_info("%s detected @ %d-%04x", name, in mxl5007t_get_chip_id()
824 i2c_adapter_id(state->i2c_props.adap), in mxl5007t_get_chip_id()
825 state->i2c_props.addr); in mxl5007t_get_chip_id()
828 mxl_warn("unable to identify device @ %d-%04x", in mxl5007t_get_chip_id()
829 i2c_adapter_id(state->i2c_props.adap), in mxl5007t_get_chip_id()
830 state->i2c_props.addr); in mxl5007t_get_chip_id()
832 state->chip_id = MxL_UNKNOWN_ID; in mxl5007t_get_chip_id()
847 switch (instance) { in mxl5007t_attach()
852 state->config = cfg; in mxl5007t_attach()
854 mutex_init(&state->lock); in mxl5007t_attach()
856 if (fe->ops.i2c_gate_ctrl) in mxl5007t_attach()
857 fe->ops.i2c_gate_ctrl(fe, 1); in mxl5007t_attach()
861 if (fe->ops.i2c_gate_ctrl) in mxl5007t_attach()
862 fe->ops.i2c_gate_ctrl(fe, 0); in mxl5007t_attach()
873 if (fe->ops.i2c_gate_ctrl) in mxl5007t_attach()
874 fe->ops.i2c_gate_ctrl(fe, 1); in mxl5007t_attach()
878 if (fe->ops.i2c_gate_ctrl) in mxl5007t_attach()
879 fe->ops.i2c_gate_ctrl(fe, 0); in mxl5007t_attach()
884 if (fe->ops.i2c_gate_ctrl) in mxl5007t_attach()
885 fe->ops.i2c_gate_ctrl(fe, 1); in mxl5007t_attach()
888 state->config->loop_thru_enable); in mxl5007t_attach()
890 if (fe->ops.i2c_gate_ctrl) in mxl5007t_attach()
891 fe->ops.i2c_gate_ctrl(fe, 0); in mxl5007t_attach()
896 fe->tuner_priv = state; in mxl5007t_attach()
900 memcpy(&fe->ops.tuner_ops, &mxl5007t_tuner_ops, in mxl5007t_attach()