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