168 lines · c
1// SPDX-License-Identifier: GPL-2.0-only2/* Common methods for dibusb-based-receivers.3 *4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)5 *6 * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information7 */8 9#include "dibusb.h"10 11MODULE_DESCRIPTION("Common methods for DIB3000MC");12MODULE_LICENSE("GPL");13 14/* 3000MC/P stuff */15// Config Adjacent channels Perf -cal2216static struct dibx000_agc_config dib3000p_mt2060_agc_config = {17 .band_caps = BAND_VHF | BAND_UHF,18 .setup = (1 << 8) | (5 << 5) | (1 << 4) | (1 << 3) | (0 << 2) | (2 << 0),19 20 .agc1_max = 48497,21 .agc1_min = 23593,22 .agc2_max = 46531,23 .agc2_min = 24904,24 25 .agc1_pt1 = 0x65,26 .agc1_pt2 = 0x69,27 28 .agc1_slope1 = 0x51,29 .agc1_slope2 = 0x27,30 31 .agc2_pt1 = 0,32 .agc2_pt2 = 0x33,33 34 .agc2_slope1 = 0x35,35 .agc2_slope2 = 0x37,36};37 38static struct dib3000mc_config stk3000p_dib3000p_config = {39 &dib3000p_mt2060_agc_config,40 41 .max_time = 0x196,42 .ln_adc_level = 0x1cc7,43 44 .output_mpeg2_in_188_bytes = 1,45 46 .agc_command1 = 1,47 .agc_command2 = 1,48};49 50static struct dibx000_agc_config dib3000p_panasonic_agc_config = {51 .band_caps = BAND_VHF | BAND_UHF,52 .setup = (1 << 8) | (5 << 5) | (1 << 4) | (1 << 3) | (0 << 2) | (2 << 0),53 54 .agc1_max = 56361,55 .agc1_min = 22282,56 .agc2_max = 47841,57 .agc2_min = 36045,58 59 .agc1_pt1 = 0x3b,60 .agc1_pt2 = 0x6b,61 62 .agc1_slope1 = 0x55,63 .agc1_slope2 = 0x1d,64 65 .agc2_pt1 = 0,66 .agc2_pt2 = 0x0a,67 68 .agc2_slope1 = 0x95,69 .agc2_slope2 = 0x1e,70};71 72static struct dib3000mc_config mod3000p_dib3000p_config = {73 &dib3000p_panasonic_agc_config,74 75 .max_time = 0x51,76 .ln_adc_level = 0x1cc7,77 78 .output_mpeg2_in_188_bytes = 1,79 80 .agc_command1 = 1,81 .agc_command2 = 1,82};83 84int dibusb_dib3000mc_frontend_attach(struct dvb_usb_adapter *adap)85{86 if (le16_to_cpu(adap->dev->udev->descriptor.idVendor) == USB_VID_LITEON &&87 le16_to_cpu(adap->dev->udev->descriptor.idProduct) ==88 USB_PID_LITEON_DVB_T_WARM) {89 msleep(1000);90 }91 92 adap->fe_adap[0].fe = dvb_attach(dib3000mc_attach,93 &adap->dev->i2c_adap,94 DEFAULT_DIB3000P_I2C_ADDRESS,95 &mod3000p_dib3000p_config);96 if ((adap->fe_adap[0].fe) == NULL)97 adap->fe_adap[0].fe = dvb_attach(dib3000mc_attach,98 &adap->dev->i2c_adap,99 DEFAULT_DIB3000MC_I2C_ADDRESS,100 &mod3000p_dib3000p_config);101 if ((adap->fe_adap[0].fe) != NULL) {102 if (adap->priv != NULL) {103 struct dibusb_state *st = adap->priv;104 st->ops.pid_parse = dib3000mc_pid_parse;105 st->ops.pid_ctrl = dib3000mc_pid_control;106 }107 return 0;108 }109 return -ENODEV;110}111EXPORT_SYMBOL(dibusb_dib3000mc_frontend_attach);112 113static struct mt2060_config stk3000p_mt2060_config = {114 0x60115};116 117int dibusb_dib3000mc_tuner_attach(struct dvb_usb_adapter *adap)118{119 struct dibusb_state *st = adap->priv;120 u8 a,b;121 u16 if1 = 1220;122 struct i2c_adapter *tun_i2c;123 124 // First IF calibration for Liteon Sticks125 if (le16_to_cpu(adap->dev->udev->descriptor.idVendor) == USB_VID_LITEON &&126 le16_to_cpu(adap->dev->udev->descriptor.idProduct) == USB_PID_LITEON_DVB_T_WARM) {127 128 dibusb_read_eeprom_byte(adap->dev,0x7E,&a);129 dibusb_read_eeprom_byte(adap->dev,0x7F,&b);130 131 if (a == 0x00)132 if1 += b;133 else if (a == 0x80)134 if1 -= b;135 else136 warn("LITE-ON DVB-T: Strange IF1 calibration :%2X %2X\n", a, b);137 138 } else if (le16_to_cpu(adap->dev->udev->descriptor.idVendor) == USB_VID_DIBCOM &&139 le16_to_cpu(adap->dev->udev->descriptor.idProduct) == USB_PID_DIBCOM_MOD3001_WARM) {140 u8 desc;141 dibusb_read_eeprom_byte(adap->dev, 7, &desc);142 if (desc == 2) {143 a = 127;144 do {145 dibusb_read_eeprom_byte(adap->dev, a, &desc);146 a--;147 } while (a > 7 && (desc == 0xff || desc == 0x00));148 if (desc & 0x80)149 if1 -= (0xff - desc);150 else151 if1 += desc;152 }153 }154 155 tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe_adap[0].fe, 1);156 if (dvb_attach(mt2060_attach, adap->fe_adap[0].fe, tun_i2c, &stk3000p_mt2060_config, if1) == NULL) {157 /* not found - use panasonic pll parameters */158 if (dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60, tun_i2c, DVB_PLL_ENV57H1XD5) == NULL)159 return -ENOMEM;160 } else {161 st->mt2060_present = 1;162 /* set the correct parameters for the dib3000p */163 dib3000mc_set_config(adap->fe_adap[0].fe, &stk3000p_dib3000p_config);164 }165 return 0;166}167EXPORT_SYMBOL(dibusb_dib3000mc_tuner_attach);168