blob: fe305f4430ead592f862572121b3361d837e455f [file] [log] [blame]
Patrick Boettcherb7f54912006-09-19 12:51:37 -03001/* Linux driver for devices based on the DiBcom DiB0700 USB bridge
2 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation, version 2.
6 *
7 * Copyright (C) 2005-6 DiBcom, SA
8 */
9#include "dib0700.h"
10
11#include "dib3000mc.h"
Patrick Boettcher91bb9be2006-12-02 21:15:51 -020012#include "dib7000m.h"
Patrick Boettchera75763f2006-10-18 08:34:16 -030013#include "dib7000p.h"
Patrick Boettcherb7f54912006-09-19 12:51:37 -030014#include "mt2060.h"
15
Patrick Boettcher7fb3fc02006-09-20 04:37:18 -030016static int force_lna_activation;
17module_param(force_lna_activation, int, 0644);
18MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplifyer(s) (LNA), "
19 "if applicable for the device (default: 0=automatic/off).");
20
Patrick Boettcherb7f54912006-09-19 12:51:37 -030021/* Hauppauge Nova-T 500
22 * has a LNA on GPIO0 which is enabled by setting 1 */
23static struct mt2060_config bristol_mt2060_config[2] = {
24 {
25 .i2c_address = 0x60,
Patrick Boettcher303cbea2006-09-19 12:51:56 -030026 .clock_out = 3,
Patrick Boettcherb7f54912006-09-19 12:51:37 -030027 }, {
28 .i2c_address = 0x61,
29 }
30};
31
32static struct dibx000_agc_config bristol_dib3000p_mt2060_agc_config = {
33 .band_caps = BAND_VHF | BAND_UHF,
Patrick Boettcher01b4bf32006-09-19 12:51:53 -030034 .setup = (1 << 8) | (5 << 5) | (0 << 4) | (0 << 3) | (0 << 2) | (2 << 0),
Patrick Boettcherb7f54912006-09-19 12:51:37 -030035
Patrick Boettcher6958eff2006-09-19 12:51:40 -030036 .agc1_max = 42598,
37 .agc1_min = 17694,
38 .agc2_max = 45875,
39 .agc2_min = 0,
Patrick Boettcherb7f54912006-09-19 12:51:37 -030040
Patrick Boettcher6958eff2006-09-19 12:51:40 -030041 .agc1_pt1 = 0,
42 .agc1_pt2 = 59,
Patrick Boettcherb7f54912006-09-19 12:51:37 -030043
Patrick Boettcher6958eff2006-09-19 12:51:40 -030044 .agc1_slope1 = 0,
45 .agc1_slope2 = 69,
Patrick Boettcherb7f54912006-09-19 12:51:37 -030046
47 .agc2_pt1 = 0,
Patrick Boettcher6958eff2006-09-19 12:51:40 -030048 .agc2_pt2 = 59,
Patrick Boettcherb7f54912006-09-19 12:51:37 -030049
Patrick Boettcher6958eff2006-09-19 12:51:40 -030050 .agc2_slope1 = 111,
51 .agc2_slope2 = 28,
Patrick Boettcherb7f54912006-09-19 12:51:37 -030052};
53
54static struct dib3000mc_config bristol_dib3000mc_config[2] = {
55 { .agc = &bristol_dib3000p_mt2060_agc_config,
56 .max_time = 0x196,
57 .ln_adc_level = 0x1cc7,
58 .output_mpeg2_in_188_bytes = 1,
59 },
60 { .agc = &bristol_dib3000p_mt2060_agc_config,
61 .max_time = 0x196,
62 .ln_adc_level = 0x1cc7,
63 .output_mpeg2_in_188_bytes = 1,
64 }
65};
66
67static int bristol_frontend_attach(struct dvb_usb_adapter *adap)
68{
Patrick Boettcher6958eff2006-09-19 12:51:40 -030069 struct dib0700_state *st = adap->dev->priv;
Patrick Boettcherb7f54912006-09-19 12:51:37 -030070 if (adap->id == 0) {
71 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(10);
72 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); msleep(10);
73 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10);
74 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(10);
75
Patrick Boettcher7fb3fc02006-09-20 04:37:18 -030076 if (force_lna_activation)
77 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
78 else
79 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 0);
Patrick Boettcher6958eff2006-09-19 12:51:40 -030080
Patrick Boettcherb7f54912006-09-19 12:51:37 -030081 if (dib3000mc_i2c_enumeration(&adap->dev->i2c_adap, 2, DEFAULT_DIB3000P_I2C_ADDRESS, bristol_dib3000mc_config) != 0) {
82 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(10);
83 return -ENODEV;
84 }
85 }
Patrick Boettcher6958eff2006-09-19 12:51:40 -030086 st->mt2060_if1[adap->id] = 1220;
87 return (adap->fe = dvb_attach(dib3000mc_attach, &adap->dev->i2c_adap,
88 (10 + adap->id) << 1, &bristol_dib3000mc_config[adap->id])) == NULL ? -ENODEV : 0;
Patrick Boettcherb7f54912006-09-19 12:51:37 -030089}
90
91static int bristol_tuner_attach(struct dvb_usb_adapter *adap)
92{
93 struct dib0700_state *st = adap->dev->priv;
94 struct i2c_adapter *tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe, 1);
Patrick Boettcher6958eff2006-09-19 12:51:40 -030095 return dvb_attach(mt2060_attach,adap->fe, tun_i2c, &bristol_mt2060_config[adap->id],
96 st->mt2060_if1[adap->id]) == NULL ? -ENODEV : 0;
Patrick Boettcherb7f54912006-09-19 12:51:37 -030097}
98
99/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */
Patrick Boettchera75763f2006-10-18 08:34:16 -0300100static struct dibx000_agc_config stk7700p_7000m_mt2060_agc_config = {
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300101 BAND_UHF | BAND_VHF, // band_caps
102
103 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5, P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
104 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=2, P_agc_write=0 */
105 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), // setup
106
107 712, // inv_gain
108 41, // time_stabiliz
109
110 0, // alpha_level
111 118, // thlock
112
113 0, // wbd_inv
114 4095, // wbd_ref
115 0, // wbd_sel
116 0, // wbd_alpha
117
118 42598, // agc1_max
119 17694, // agc1_min
120 45875, // agc2_max
121 2621, // agc2_min
122 0, // agc1_pt1
123 76, // agc1_pt2
124 139, // agc1_pt3
125 52, // agc1_slope1
126 59, // agc1_slope2
127 107, // agc2_pt1
128 172, // agc2_pt2
129 57, // agc2_slope1
130 70, // agc2_slope2
131
132 21, // alpha_mant
133 25, // alpha_exp
134 28, // beta_mant
135 48, // beta_exp
136
137 1, // perform_agc_softsplit
138 { 0, // split_min
139 107, // split_max
140 51800, // global_split_min
141 24700 // global_split_max
142 },
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300143};
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300144
Patrick Boettchera75763f2006-10-18 08:34:16 -0300145static struct dibx000_agc_config stk7700p_7000p_mt2060_agc_config = {
146 BAND_UHF | BAND_VHF,
147
148 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5, P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
149 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=2, P_agc_write=0 */
150 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), // setup
151
152 712, // inv_gain
153 41, // time_stabiliz
154
155 0, // alpha_level
156 118, // thlock
157
158 0, // wbd_inv
159 4095, // wbd_ref
160 0, // wbd_sel
161 0, // wbd_alpha
162
163 42598, // agc1_max
164 16384, // agc1_min
165 42598, // agc2_max
166 0, // agc2_min
167
168 0, // agc1_pt1
169 137, // agc1_pt2
170 255, // agc1_pt3
171
172 0, // agc1_slope1
173 255, // agc1_slope2
174
175 0, // agc2_pt1
176 0, // agc2_pt2
177
178 0, // agc2_slope1
179 41, // agc2_slope2
180
181 15, // alpha_mant
182 25, // alpha_exp
183
184 28, // beta_mant
185 48, // beta_exp
186
187 0, // perform_agc_softsplit
188};
189
190static struct dibx000_bandwidth_config stk7700p_pll_config = {
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300191 60000, 30000, // internal, sampling
192 1, 8, 3, 1, 0, // pll_cfg: prediv, ratio, range, reset, bypass
193 0, 0, 1, 1, 0, // misc: refdiv, bypclk_div, IO_CLK_en_core, ADClkSrc, modulo
194 (3 << 14) | (1 << 12) | (524 << 0), // sad_cfg: refsel, sel, freq_15k
195 60258167, // ifreq
196 20452225, // timf
197};
198
199static struct dib7000m_config stk7700p_dib7000m_config = {
200 .dvbt_mode = 1,
201 .output_mpeg2_in_188_bytes = 1,
202 .quartz_direct = 1,
203
204 .agc_config_count = 1,
Patrick Boettchera75763f2006-10-18 08:34:16 -0300205 .agc = &stk7700p_7000m_mt2060_agc_config,
206 .bw = &stk7700p_pll_config,
207
208 .gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
209 .gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
210 .gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
211};
212
213static struct dib7000p_config stk7700p_dib7000p_config = {
214 .output_mpeg2_in_188_bytes = 1,
215
216 .agc = &stk7700p_7000p_mt2060_agc_config,
217 .bw = &stk7700p_pll_config,
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300218
219 .gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
220 .gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
221 .gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
222};
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300223
224static int stk7700p_frontend_attach(struct dvb_usb_adapter *adap)
225{
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300226 struct dib0700_state *st = adap->dev->priv;
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300227 /* unless there is no real power management in DVB - we leave the device on GPIO6 */
Patrick Boettchera75763f2006-10-18 08:34:16 -0300228
229 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
230 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(50);
231
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300232 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); msleep(10);
Patrick Boettchera75763f2006-10-18 08:34:16 -0300233 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
234
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300235 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10);
Patrick Boettchera75763f2006-10-18 08:34:16 -0300236 dib0700_ctrl_clock(adap->dev, 72, 1);
237 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(100);
238
239 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300240
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300241 st->mt2060_if1[0] = 1220;
Patrick Boettchera75763f2006-10-18 08:34:16 -0300242
243 if (dib7000pc_detection(&adap->dev->i2c_adap)) {
244 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000p_config);
245 st->is_dib7000pc = 1;
246 } else
247 adap->fe = dvb_attach(dib7000m_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000m_config);
248
249 return adap->fe == NULL ? -ENODEV : 0;
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300250}
251
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300252static struct mt2060_config stk7700p_mt2060_config = {
253 0x60
254};
255
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300256static int stk7700p_tuner_attach(struct dvb_usb_adapter *adap)
257{
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300258 struct dib0700_state *st = adap->dev->priv;
Patrick Boettchera75763f2006-10-18 08:34:16 -0300259 struct i2c_adapter *tun_i2c;
260
261 if (st->is_dib7000pc)
262 tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
263 else
264 tun_i2c = dib7000m_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
265
266 return dvb_attach(mt2060_attach, adap->fe, tun_i2c, &stk7700p_mt2060_config,
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300267 st->mt2060_if1[0]) == NULL ? -ENODEV : 0;
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300268}
269
270struct usb_device_id dib0700_usb_id_table[] = {
271 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) },
Tomi Koivulahti49a13762006-10-19 07:27:19 -0300272 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P_PC) },
273
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300274 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500) },
Patrick Boettcherd535cfa2006-09-19 12:51:49 -0300275 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_2) },
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300276 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK) },
277 { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR) },
Tomi Koivulahti49a13762006-10-19 07:27:19 -0300278 { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_VIDEOMATE_U500) },
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300279 { } /* Terminating entry */
280};
281MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
282
283#define DIB0700_DEFAULT_DEVICE_PROPERTIES \
284 .caps = DVB_USB_IS_AN_I2C_ADAPTER, \
285 .usb_ctrl = DEVICE_SPECIFIC, \
286 .firmware = "dvb-usb-dib0700-01.fw", \
287 .download_firmware = dib0700_download_firmware, \
Patrick Boettcher6958eff2006-09-19 12:51:40 -0300288 .no_reconnect = 1, \
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300289 .size_of_priv = sizeof(struct dib0700_state), \
Patrick Boettcher6958eff2006-09-19 12:51:40 -0300290 .i2c_algo = &dib0700_i2c_algo, \
291 .identify_state = dib0700_identify_state
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300292
293#define DIB0700_DEFAULT_STREAMING_CONFIG(ep) \
294 .streaming_ctrl = dib0700_streaming_ctrl, \
295 .stream = { \
296 .type = USB_BULK, \
297 .count = 4, \
298 .endpoint = ep, \
299 .u = { \
300 .bulk = { \
301 .buffersize = 39480, \
302 } \
303 } \
304 }
305
306struct dvb_usb_device_properties dib0700_devices[] = {
307 {
308 DIB0700_DEFAULT_DEVICE_PROPERTIES,
309
310 .num_adapters = 1,
311 .adapter = {
312 {
313 .frontend_attach = stk7700p_frontend_attach,
314 .tuner_attach = stk7700p_tuner_attach,
315
316 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
317 },
318 },
319
Tomi Koivulahti49a13762006-10-19 07:27:19 -0300320 .num_device_descs = 4,
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300321 .devices = {
322 { "DiBcom STK7700P reference design",
Tomi Koivulahti49a13762006-10-19 07:27:19 -0300323 { &dib0700_usb_id_table[0], &dib0700_usb_id_table[1] },
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300324 { NULL },
325 },
326 { "Hauppauge Nova-T Stick",
Patrick Boettcherd535cfa2006-09-19 12:51:49 -0300327 { &dib0700_usb_id_table[4], NULL },
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300328 { NULL },
329 },
Tomi Koivulahti49a13762006-10-19 07:27:19 -0300330 { "AVerMedia AVerTV DVB-T Volar",
331 { &dib0700_usb_id_table[5], NULL },
332 { NULL },
333 },
334 { "Compro Videomate U500",
335 { &dib0700_usb_id_table[6], NULL },
336 { NULL },
337 }
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300338 }
339 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
340
341 .num_adapters = 2,
342 .adapter = {
343 {
344 .frontend_attach = bristol_frontend_attach,
345 .tuner_attach = bristol_tuner_attach,
346
347 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
348 }, {
349 .frontend_attach = bristol_frontend_attach,
350 .tuner_attach = bristol_tuner_attach,
351
352 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
353 }
354 },
355
356 .num_device_descs = 1,
357 .devices = {
358 { "Hauppauge Nova-T 500 Dual DVB-T",
Tomi Koivulahti49a13762006-10-19 07:27:19 -0300359 { &dib0700_usb_id_table[2], &dib0700_usb_id_table[3], NULL },
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300360 { NULL },
361 },
362 }
363 }
364};
365
366int dib0700_device_count = ARRAY_SIZE(dib0700_devices);