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