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