V4L/DVB (5955): Add support for DiB7070-based devices
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / media / dvb / dvb-usb / dib0700_devices.c
CommitLineData
b7f54910
PB
1/* 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 *
b6884a17 7 * Copyright (C) 2005-7 DiBcom, SA
b7f54910
PB
8 */
9#include "dib0700.h"
10
11#include "dib3000mc.h"
91bb9be6 12#include "dib7000m.h"
a75763ff 13#include "dib7000p.h"
b7f54910 14#include "mt2060.h"
54d75eba 15#include "mt2266.h"
01373a5c 16#include "dib0070.h"
b7f54910 17
7fb3fc0c
PB
18static int force_lna_activation;
19module_param(force_lna_activation, int, 0644);
20MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplifyer(s) (LNA), "
21 "if applicable for the device (default: 0=automatic/off).");
22
01373a5c
PB
23struct dib0700_adapter_state {
24 int (*set_param_save) (struct dvb_frontend *, struct dvb_frontend_parameters *);
25};
26
27/* Hauppauge Nova-T 500 (aka Bristol)
b7f54910
PB
28 * has a LNA on GPIO0 which is enabled by setting 1 */
29static struct mt2060_config bristol_mt2060_config[2] = {
30 {
31 .i2c_address = 0x60,
303cbeaa 32 .clock_out = 3,
b7f54910
PB
33 }, {
34 .i2c_address = 0x61,
35 }
36};
37
38static struct dibx000_agc_config bristol_dib3000p_mt2060_agc_config = {
39 .band_caps = BAND_VHF | BAND_UHF,
01b4bf31 40 .setup = (1 << 8) | (5 << 5) | (0 << 4) | (0 << 3) | (0 << 2) | (2 << 0),
b7f54910 41
6958effe
PB
42 .agc1_max = 42598,
43 .agc1_min = 17694,
44 .agc2_max = 45875,
45 .agc2_min = 0,
b7f54910 46
6958effe
PB
47 .agc1_pt1 = 0,
48 .agc1_pt2 = 59,
b7f54910 49
6958effe
PB
50 .agc1_slope1 = 0,
51 .agc1_slope2 = 69,
b7f54910
PB
52
53 .agc2_pt1 = 0,
6958effe 54 .agc2_pt2 = 59,
b7f54910 55
6958effe
PB
56 .agc2_slope1 = 111,
57 .agc2_slope2 = 28,
b7f54910
PB
58};
59
60static struct dib3000mc_config bristol_dib3000mc_config[2] = {
61 { .agc = &bristol_dib3000p_mt2060_agc_config,
62 .max_time = 0x196,
63 .ln_adc_level = 0x1cc7,
64 .output_mpeg2_in_188_bytes = 1,
65 },
66 { .agc = &bristol_dib3000p_mt2060_agc_config,
67 .max_time = 0x196,
68 .ln_adc_level = 0x1cc7,
69 .output_mpeg2_in_188_bytes = 1,
70 }
71};
72
73static int bristol_frontend_attach(struct dvb_usb_adapter *adap)
74{
6958effe 75 struct dib0700_state *st = adap->dev->priv;
b7f54910
PB
76 if (adap->id == 0) {
77 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(10);
78 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); msleep(10);
79 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10);
80 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(10);
81
7fb3fc0c
PB
82 if (force_lna_activation)
83 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
84 else
85 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 0);
6958effe 86
b7f54910
PB
87 if (dib3000mc_i2c_enumeration(&adap->dev->i2c_adap, 2, DEFAULT_DIB3000P_I2C_ADDRESS, bristol_dib3000mc_config) != 0) {
88 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(10);
89 return -ENODEV;
90 }
91 }
6958effe
PB
92 st->mt2060_if1[adap->id] = 1220;
93 return (adap->fe = dvb_attach(dib3000mc_attach, &adap->dev->i2c_adap,
94 (10 + adap->id) << 1, &bristol_dib3000mc_config[adap->id])) == NULL ? -ENODEV : 0;
b7f54910
PB
95}
96
97static int bristol_tuner_attach(struct dvb_usb_adapter *adap)
98{
99 struct dib0700_state *st = adap->dev->priv;
100 struct i2c_adapter *tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe, 1);
6958effe
PB
101 return dvb_attach(mt2060_attach,adap->fe, tun_i2c, &bristol_mt2060_config[adap->id],
102 st->mt2060_if1[adap->id]) == NULL ? -ENODEV : 0;
b7f54910
PB
103}
104
01373a5c 105/* STK7700D: Pinnacle/Terratec/Hauppauge Dual DVB-T Diversity */
54d75eba 106
b6884a17
PB
107/* MT226x */
108static struct dibx000_agc_config stk7700d_7000p_mt2266_agc_config[2] = {
109 {
110 BAND_UHF, // band_caps
111
112 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1, P_agc_inv_pwm1=1, P_agc_inv_pwm2=1,
113 * 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 */
114 (0 << 15) | (0 << 14) | (1 << 11) | (1 << 10) | (1 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0), // setup
115
116 1130, // inv_gain
117 21, // time_stabiliz
118
119 0, // alpha_level
120 118, // thlock
121
122 0, // wbd_inv
123 3530, // wbd_ref
124 1, // wbd_sel
125 0, // wbd_alpha
126
127 65535, // agc1_max
128 33770, // agc1_min
129 65535, // agc2_max
130 23592, // agc2_min
131
132 0, // agc1_pt1
133 62, // agc1_pt2
134 255, // agc1_pt3
135 64, // agc1_slope1
136 64, // agc1_slope2
137 132, // agc2_pt1
138 192, // agc2_pt2
139 80, // agc2_slope1
140 80, // agc2_slope2
141
142 17, // alpha_mant
143 27, // alpha_exp
144 23, // beta_mant
145 51, // beta_exp
146
147 1, // perform_agc_softsplit
148 }, {
149 BAND_VHF | BAND_LBAND, // band_caps
150
151 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1, P_agc_inv_pwm1=1, P_agc_inv_pwm2=1,
152 * 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 */
153 (0 << 15) | (0 << 14) | (1 << 11) | (1 << 10) | (1 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), // setup
154
155 2372, // inv_gain
156 21, // time_stabiliz
157
158 0, // alpha_level
159 118, // thlock
160
161 0, // wbd_inv
162 3530, // wbd_ref
163 1, // wbd_sel
164 0, // wbd_alpha
165
166 65535, // agc1_max
167 0, // agc1_min
168 65535, // agc2_max
169 23592, // agc2_min
170
171 0, // agc1_pt1
172 128, // agc1_pt2
173 128, // agc1_pt3
174 128, // agc1_slope1
175 0, // agc1_slope2
176 128, // agc2_pt1
177 253, // agc2_pt2
178 81, // agc2_slope1
179 0, // agc2_slope2
180
181 17, // alpha_mant
182 27, // alpha_exp
183 23, // beta_mant
184 51, // beta_exp
185
186 1, // perform_agc_softsplit
187 }
54d75eba
OD
188};
189
190static struct dibx000_bandwidth_config stk7700d_mt2266_pll_config = {
191 60000, 30000, // internal, sampling
192 1, 8, 3, 1, 0, // pll_cfg: prediv, ratio, range, reset, bypass
193 0, 0, 1, 1, 2, // misc: refdiv, bypclk_div, IO_CLK_en_core, ADClkSrc, modulo
194 (3 << 14) | (1 << 12) | (524 << 0), // sad_cfg: refsel, sel, freq_15k
195 0, // ifreq
196 20452225, // timf
197};
198
199static struct dib7000p_config stk7700d_dib7000p_mt2266_config[] = {
200 { .output_mpeg2_in_188_bytes = 1,
201 .hostbus_diversity = 1,
202 .tuner_is_baseband = 1,
203
b6884a17
PB
204 .agc_config_count = 2,
205 .agc = stk7700d_7000p_mt2266_agc_config,
54d75eba
OD
206 .bw = &stk7700d_mt2266_pll_config,
207
b6884a17
PB
208 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
209 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
210 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
54d75eba
OD
211 },
212 { .output_mpeg2_in_188_bytes = 1,
213 .hostbus_diversity = 1,
214 .tuner_is_baseband = 1,
215
b6884a17
PB
216 .agc_config_count = 2,
217 .agc = stk7700d_7000p_mt2266_agc_config,
54d75eba
OD
218 .bw = &stk7700d_mt2266_pll_config,
219
b6884a17
PB
220 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
221 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
222 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
54d75eba
OD
223 }
224};
225
226static struct mt2266_config stk7700d_mt2266_config[2] = {
227 { .i2c_address = 0x60
228 },
229 { .i2c_address = 0x60
230 }
231};
232
233static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap)
234{
235 if (adap->id == 0) {
236 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
237 msleep(10);
238 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
239 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
240 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
241 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
242 msleep(10);
243 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
244 msleep(10);
245 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
246 dib7000p_i2c_enumeration(&adap->dev->i2c_adap,2,18,stk7700d_dib7000p_mt2266_config);
247 }
248
249 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,0x80+(adap->id << 1),
250 &stk7700d_dib7000p_mt2266_config[adap->id]);
251
252 return adap->fe == NULL ? -ENODEV : 0;
253}
254
255static int stk7700d_tuner_attach(struct dvb_usb_adapter *adap)
256{
257 struct i2c_adapter *tun_i2c;
258 tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
259 return dvb_attach(mt2266_attach, adap->fe, tun_i2c,
260 &stk7700d_mt2266_config[adap->id]) == NULL ? -ENODEV : 0;;
261}
262
263#define DEFAULT_RC_INTERVAL 150
264
265static u8 rc_request[] = { REQUEST_POLL_RC, 0 };
266
b6884a17 267static int stk7700d_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
54d75eba
OD
268{
269 u8 key[4];
270 int i;
271 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
272 struct dib0700_state *st = d->priv;
273 *event = 0;
274 *state = REMOTE_NO_KEY_PRESSED;
275 i=dib0700_ctrl_rd(d,rc_request,2,key,4);
276 if (i<=0) {
277 err("stk7700d:RC Query Failed\n");
278 return 0;
279 }
280 if (key[0]==0 && key[1]==0 && key[2]==0 && key[3]==0) return 0;
281 if (key[1]!=st->rc_toggle) {
282 for (i=0;i<d->props.rc_key_map_size; i++) {
283 if (keymap[i].custom == key[2] && keymap[i].data == key[3]) {
284 *event = keymap[i].event;
285 *state = REMOTE_KEY_PRESSED;
286 st->rc_toggle=key[1];
287 return 0;
288 }
289 }
290 err("stk7700d:Unknown remote controller key : %2X %2X\n",(int)key[2],(int)key[3]);
291 }
292 return 0;
293}
294
295#define KEY_MAP_SIZE (25+48)
296
b6884a17 297static struct dvb_usb_rc_key stk7700d_rc_keys[] = {
54d75eba
OD
298 /* Key codes for the tiny Pinnacle remote*/
299 { 0x07, 0x00, KEY_MUTE },
300 { 0x07, 0x01, KEY_MENU }, // Pinnacle logo
301 { 0x07, 0x39, KEY_POWER },
302 { 0x07, 0x03, KEY_VOLUMEUP },
303 { 0x07, 0x09, KEY_VOLUMEDOWN },
304 { 0x07, 0x06, KEY_CHANNELUP },
305 { 0x07, 0x0c, KEY_CHANNELDOWN },
306 { 0x07, 0x0f, KEY_1 },
307 { 0x07, 0x15, KEY_2 },
308 { 0x07, 0x10, KEY_3 },
309 { 0x07, 0x18, KEY_4 },
310 { 0x07, 0x1b, KEY_5 },
311 { 0x07, 0x1e, KEY_6 },
312 { 0x07, 0x11, KEY_7 },
313 { 0x07, 0x21, KEY_8 },
314 { 0x07, 0x12, KEY_9 },
315 { 0x07, 0x27, KEY_0 },
316 { 0x07, 0x24, KEY_SCREEN }, // 'Square' key
317 { 0x07, 0x2a, KEY_TEXT }, // 'T' key
318 { 0x07, 0x2d, KEY_REWIND },
319 { 0x07, 0x30, KEY_PLAY },
320 { 0x07, 0x33, KEY_FASTFORWARD },
321 { 0x07, 0x36, KEY_RECORD },
322 { 0x07, 0x3c, KEY_STOP },
323 { 0x07, 0x3f, KEY_CANCEL }, // '?' key
324 /* Key codes for the Terratec Cinergy DT XS Diversity, similar to cinergyT2.c */
325 { 0xeb, 0x01, KEY_POWER },
326 { 0xeb, 0x02, KEY_1 },
327 { 0xeb, 0x03, KEY_2 },
328 { 0xeb, 0x04, KEY_3 },
329 { 0xeb, 0x05, KEY_4 },
330 { 0xeb, 0x06, KEY_5 },
331 { 0xeb, 0x07, KEY_6 },
332 { 0xeb, 0x08, KEY_7 },
333 { 0xeb, 0x09, KEY_8 },
334 { 0xeb, 0x0a, KEY_9 },
335 { 0xeb, 0x0b, KEY_VIDEO },
336 { 0xeb, 0x0c, KEY_0 },
337 { 0xeb, 0x0d, KEY_REFRESH },
338 { 0xeb, 0x0f, KEY_EPG },
339 { 0xeb, 0x10, KEY_UP },
340 { 0xeb, 0x11, KEY_LEFT },
341 { 0xeb, 0x12, KEY_OK },
342 { 0xeb, 0x13, KEY_RIGHT },
343 { 0xeb, 0x14, KEY_DOWN },
344 { 0xeb, 0x16, KEY_INFO },
345 { 0xeb, 0x17, KEY_RED },
346 { 0xeb, 0x18, KEY_GREEN },
347 { 0xeb, 0x19, KEY_YELLOW },
348 { 0xeb, 0x1a, KEY_BLUE },
349 { 0xeb, 0x1b, KEY_CHANNELUP },
350 { 0xeb, 0x1c, KEY_VOLUMEUP },
351 { 0xeb, 0x1d, KEY_MUTE },
352 { 0xeb, 0x1e, KEY_VOLUMEDOWN },
353 { 0xeb, 0x1f, KEY_CHANNELDOWN },
354 { 0xeb, 0x40, KEY_PAUSE },
355 { 0xeb, 0x41, KEY_HOME },
356 { 0xeb, 0x42, KEY_MENU }, /* DVD Menu */
357 { 0xeb, 0x43, KEY_SUBTITLE },
358 { 0xeb, 0x44, KEY_TEXT }, /* Teletext */
359 { 0xeb, 0x45, KEY_DELETE },
360 { 0xeb, 0x46, KEY_TV },
361 { 0xeb, 0x47, KEY_DVD },
362 { 0xeb, 0x48, KEY_STOP },
363 { 0xeb, 0x49, KEY_VIDEO },
364 { 0xeb, 0x4a, KEY_AUDIO }, /* Music */
365 { 0xeb, 0x4b, KEY_SCREEN }, /* Pic */
366 { 0xeb, 0x4c, KEY_PLAY },
367 { 0xeb, 0x4d, KEY_BACK },
368 { 0xeb, 0x4e, KEY_REWIND },
369 { 0xeb, 0x4f, KEY_FASTFORWARD },
370 { 0xeb, 0x54, KEY_PREVIOUS },
371 { 0xeb, 0x58, KEY_RECORD },
372 { 0xeb, 0x5c, KEY_NEXT }
373 };
374
b7f54910 375/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */
a75763ff 376static struct dibx000_agc_config stk7700p_7000m_mt2060_agc_config = {
69ea31e7
PB
377 BAND_UHF | BAND_VHF, // band_caps
378
379 /* 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,
380 * 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 */
381 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), // setup
382
383 712, // inv_gain
384 41, // time_stabiliz
385
386 0, // alpha_level
387 118, // thlock
388
389 0, // wbd_inv
390 4095, // wbd_ref
391 0, // wbd_sel
392 0, // wbd_alpha
393
394 42598, // agc1_max
395 17694, // agc1_min
396 45875, // agc2_max
397 2621, // agc2_min
398 0, // agc1_pt1
399 76, // agc1_pt2
400 139, // agc1_pt3
401 52, // agc1_slope1
402 59, // agc1_slope2
403 107, // agc2_pt1
404 172, // agc2_pt2
405 57, // agc2_slope1
406 70, // agc2_slope2
407
408 21, // alpha_mant
409 25, // alpha_exp
410 28, // beta_mant
411 48, // beta_exp
412
413 1, // perform_agc_softsplit
414 { 0, // split_min
415 107, // split_max
416 51800, // global_split_min
417 24700 // global_split_max
418 },
419};
420
a75763ff
PB
421static struct dibx000_agc_config stk7700p_7000p_mt2060_agc_config = {
422 BAND_UHF | BAND_VHF,
423
424 /* 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,
425 * 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 */
426 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), // setup
427
428 712, // inv_gain
429 41, // time_stabiliz
430
431 0, // alpha_level
432 118, // thlock
433
434 0, // wbd_inv
435 4095, // wbd_ref
436 0, // wbd_sel
437 0, // wbd_alpha
438
439 42598, // agc1_max
440 16384, // agc1_min
441 42598, // agc2_max
442 0, // agc2_min
443
444 0, // agc1_pt1
445 137, // agc1_pt2
446 255, // agc1_pt3
447
448 0, // agc1_slope1
449 255, // agc1_slope2
450
451 0, // agc2_pt1
452 0, // agc2_pt2
453
454 0, // agc2_slope1
455 41, // agc2_slope2
456
457 15, // alpha_mant
458 25, // alpha_exp
459
460 28, // beta_mant
461 48, // beta_exp
462
463 0, // perform_agc_softsplit
464};
465
466static struct dibx000_bandwidth_config stk7700p_pll_config = {
69ea31e7
PB
467 60000, 30000, // internal, sampling
468 1, 8, 3, 1, 0, // pll_cfg: prediv, ratio, range, reset, bypass
469 0, 0, 1, 1, 0, // misc: refdiv, bypclk_div, IO_CLK_en_core, ADClkSrc, modulo
470 (3 << 14) | (1 << 12) | (524 << 0), // sad_cfg: refsel, sel, freq_15k
471 60258167, // ifreq
472 20452225, // timf
473};
474
475static struct dib7000m_config stk7700p_dib7000m_config = {
476 .dvbt_mode = 1,
477 .output_mpeg2_in_188_bytes = 1,
478 .quartz_direct = 1,
479
480 .agc_config_count = 1,
a75763ff
PB
481 .agc = &stk7700p_7000m_mt2060_agc_config,
482 .bw = &stk7700p_pll_config,
483
484 .gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
485 .gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
486 .gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
487};
488
489static struct dib7000p_config stk7700p_dib7000p_config = {
490 .output_mpeg2_in_188_bytes = 1,
491
b6884a17 492 .agc_config_count = 1,
a75763ff
PB
493 .agc = &stk7700p_7000p_mt2060_agc_config,
494 .bw = &stk7700p_pll_config,
69ea31e7
PB
495
496 .gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
497 .gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
498 .gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
b7f54910
PB
499};
500
501static int stk7700p_frontend_attach(struct dvb_usb_adapter *adap)
502{
69ea31e7 503 struct dib0700_state *st = adap->dev->priv;
b7f54910 504 /* unless there is no real power management in DVB - we leave the device on GPIO6 */
a75763ff
PB
505
506 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
507 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(50);
508
69ea31e7 509 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); msleep(10);
a75763ff
PB
510 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
511
b7f54910 512 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10);
a75763ff
PB
513 dib0700_ctrl_clock(adap->dev, 72, 1);
514 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(100);
515
516 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
b7f54910 517
69ea31e7 518 st->mt2060_if1[0] = 1220;
a75763ff
PB
519
520 if (dib7000pc_detection(&adap->dev->i2c_adap)) {
521 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000p_config);
522 st->is_dib7000pc = 1;
523 } else
524 adap->fe = dvb_attach(dib7000m_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000m_config);
525
526 return adap->fe == NULL ? -ENODEV : 0;
b7f54910
PB
527}
528
69ea31e7
PB
529static struct mt2060_config stk7700p_mt2060_config = {
530 0x60
531};
532
b7f54910
PB
533static int stk7700p_tuner_attach(struct dvb_usb_adapter *adap)
534{
69ea31e7 535 struct dib0700_state *st = adap->dev->priv;
a75763ff
PB
536 struct i2c_adapter *tun_i2c;
537
538 if (st->is_dib7000pc)
539 tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
540 else
541 tun_i2c = dib7000m_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
542
543 return dvb_attach(mt2060_attach, adap->fe, tun_i2c, &stk7700p_mt2060_config,
69ea31e7 544 st->mt2060_if1[0]) == NULL ? -ENODEV : 0;
b7f54910
PB
545}
546
01373a5c
PB
547/* DIB7070 generic */
548static struct dibx000_agc_config dib7070_agc_config = {
549 BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
550 /* 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,
551 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
552 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0), // setup
553
554 600, // inv_gain
555 10, // time_stabiliz
556
557 0, // alpha_level
558 118, // thlock
559
560 0, // wbd_inv
561 3530, // wbd_ref
562 1, // wbd_sel
563 5, // wbd_alpha
564
565 65535, // agc1_max
566 0, // agc1_min
567
568 65535, // agc2_max
569 0, // agc2_min
570
571 0, // agc1_pt1
572 40, // agc1_pt2
573 183, // agc1_pt3
574 206, // agc1_slope1
575 255, // agc1_slope2
576 72, // agc2_pt1
577 152, // agc2_pt2
578 88, // agc2_slope1
579 90, // agc2_slope2
580
581 17, // alpha_mant
582 27, // alpha_exp
583 23, // beta_mant
584 51, // beta_exp
585
586 0, // perform_agc_softsplit
587};
588
589static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
590{
591 return dib7000p_set_gpio(fe, 8, 0, !onoff);
592}
593
594static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
595{
596 return dib7000p_set_gpio(fe, 9, 0, onoff);
597}
598
599static struct dib0070_config dib7070p_dib0070_config[2] = {
600 {
601 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
602 .reset = dib7070_tuner_reset,
603 .sleep = dib7070_tuner_sleep,
604 .clock_khz = 12000,
605 .clock_pad_drive = 4
606 }, {
607 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
608 .reset = dib7070_tuner_reset,
609 .sleep = dib7070_tuner_sleep,
610 .clock_khz = 12000,
611
612 }
613};
614
615static int dib7070_set_param_override(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)
616{
617 struct dvb_usb_adapter *adap = fe->dvb->priv;
618 struct dib0700_adapter_state *state = adap->priv;
619
620 u16 offset;
621 u8 band = BAND_OF_FREQUENCY(fep->frequency/1000);
622 switch (band) {
623 case BAND_VHF: offset = 950; break;
624 case BAND_UHF:
625 default: offset = 550; break;
626 }
627 deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe));
628 dib7000p_set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
629 return state->set_param_save(fe, fep);
630}
631
632static int dib7070p_tuner_attach(struct dvb_usb_adapter *adap)
633{
634 struct dib0700_adapter_state *st = adap->priv;
635 struct i2c_adapter *tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
636
637 if (adap->id == 0) {
638 if (dvb_attach(dib0070_attach, adap->fe, tun_i2c, &dib7070p_dib0070_config[0]) == NULL)
639 return -ENODEV;
640 } else {
641 if (dvb_attach(dib0070_attach, adap->fe, tun_i2c, &dib7070p_dib0070_config[1]) == NULL)
642 return -ENODEV;
643 }
644
645 st->set_param_save = adap->fe->ops.tuner_ops.set_params;
646 adap->fe->ops.tuner_ops.set_params = dib7070_set_param_override;
647 return 0;
648}
649
650static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
651 60000, 15000, // internal, sampling
652 1, 20, 3, 1, 0, // pll_cfg: prediv, ratio, range, reset, bypass
653 0, 0, 1, 1, 2, // misc: refdiv, bypclk_div, IO_CLK_en_core, ADClkSrc, modulo
654 (3 << 14) | (1 << 12) | (524 << 0), // sad_cfg: refsel, sel, freq_15k
655 (0 << 25) | 0, // ifreq = 0.000000 MHz
656 20452225, // timf
657 12000000, // xtal_hz
658};
659
660static struct dib7000p_config dib7070p_dib7000p_config = {
661 .output_mpeg2_in_188_bytes = 1,
662
663 .agc_config_count = 1,
664 .agc = &dib7070_agc_config,
665 .bw = &dib7070_bw_config_12_mhz,
666
667 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
668 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
669 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
670
671 .hostbus_diversity = 1,
672};
673
674/* STK7070P */
675static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap)
676{
677 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
678 msleep(10);
679 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
680 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
681 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
682 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
683
684 dib0700_ctrl_clock(adap->dev, 72, 1);
685
686 msleep(10);
687 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
688 msleep(10);
689 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
690
691 dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, &dib7070p_dib7000p_config);
692
693 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &dib7070p_dib7000p_config);
694 return adap->fe == NULL ? -ENODEV : 0;
695}
696
697/* STK7070PD */
698static struct dib7000p_config stk7070pd_dib7000p_config[2] = {
699 {
700 .output_mpeg2_in_188_bytes = 1,
701
702 .agc_config_count = 1,
703 .agc = &dib7070_agc_config,
704 .bw = &dib7070_bw_config_12_mhz,
705
706 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
707 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
708 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
709
710 .hostbus_diversity = 1,
711 }, {
712 .output_mpeg2_in_188_bytes = 1,
713
714 .agc_config_count = 1,
715 .agc = &dib7070_agc_config,
716 .bw = &dib7070_bw_config_12_mhz,
717
718 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
719 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
720 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
721
722 .hostbus_diversity = 1,
723 }
724};
725
726static int stk7070pd_frontend_attach0(struct dvb_usb_adapter *adap)
727{
728 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
729 msleep(10);
730 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
731 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
732 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
733 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
734
735 dib0700_ctrl_clock(adap->dev, 72, 1);
736
737 msleep(10);
738 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
739 msleep(10);
740 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
741
742 dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 2, 18, stk7070pd_dib7000p_config);
743
744 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &stk7070pd_dib7000p_config[0]);
745 return adap->fe == NULL ? -ENODEV : 0;
746}
747
748static int stk7070pd_frontend_attach1(struct dvb_usb_adapter *adap)
749{
750 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x82, &stk7070pd_dib7000p_config[1]);
751 return adap->fe == NULL ? -ENODEV : 0;
752}
753
754/* DVB-USB and USB stuff follows */
b7f54910 755struct usb_device_id dib0700_usb_id_table[] = {
01373a5c 756/* 0 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) },
49a1376c
TK
757 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P_PC) },
758
b7f54910 759 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500) },
d535cfa7 760 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_2) },
b7f54910 761 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK) },
01373a5c 762/* 5 */ { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR) },
49a1376c 763 { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_VIDEOMATE_U500) },
0ce215e1 764 { USB_DEVICE(USB_VID_UNIWILL, USB_PID_UNIWILL_STK7700P) },
8637a875 765 { USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_STK7700P) },
f9aeba45 766 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_2) },
01373a5c 767/* 10 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_2) },
54d75eba
OD
768 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV2000E) },
769 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY) },
770 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK) },
b6884a17 771 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700D) },
01373a5c
PB
772/* 15 */{ USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7070P) },
773 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV_DVB_T_FLASH) },
774 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7070PD) },
775 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T) },
776 { 0 } /* Terminating entry */
b7f54910
PB
777};
778MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
779
780#define DIB0700_DEFAULT_DEVICE_PROPERTIES \
781 .caps = DVB_USB_IS_AN_I2C_ADAPTER, \
782 .usb_ctrl = DEVICE_SPECIFIC, \
01373a5c 783 .firmware = "dvb-usb-dib0700-03-pre1.fw", \
b7f54910 784 .download_firmware = dib0700_download_firmware, \
6958effe 785 .no_reconnect = 1, \
b7f54910 786 .size_of_priv = sizeof(struct dib0700_state), \
6958effe
PB
787 .i2c_algo = &dib0700_i2c_algo, \
788 .identify_state = dib0700_identify_state
b7f54910
PB
789
790#define DIB0700_DEFAULT_STREAMING_CONFIG(ep) \
791 .streaming_ctrl = dib0700_streaming_ctrl, \
792 .stream = { \
793 .type = USB_BULK, \
794 .count = 4, \
795 .endpoint = ep, \
796 .u = { \
797 .bulk = { \
798 .buffersize = 39480, \
799 } \
800 } \
801 }
802
803struct dvb_usb_device_properties dib0700_devices[] = {
804 {
805 DIB0700_DEFAULT_DEVICE_PROPERTIES,
806
807 .num_adapters = 1,
808 .adapter = {
809 {
810 .frontend_attach = stk7700p_frontend_attach,
811 .tuner_attach = stk7700p_tuner_attach,
812
813 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
814 },
815 },
816
8637a875 817 .num_device_descs = 6,
b7f54910
PB
818 .devices = {
819 { "DiBcom STK7700P reference design",
49a1376c 820 { &dib0700_usb_id_table[0], &dib0700_usb_id_table[1] },
b7f54910
PB
821 { NULL },
822 },
823 { "Hauppauge Nova-T Stick",
f9aeba45 824 { &dib0700_usb_id_table[4], &dib0700_usb_id_table[9], NULL },
b7f54910
PB
825 { NULL },
826 },
827 { "AVerMedia AVerTV DVB-T Volar",
ced8feca 828 { &dib0700_usb_id_table[5], &dib0700_usb_id_table[10] },
b7f54910
PB
829 { NULL },
830 },
49a1376c
TK
831 { "Compro Videomate U500",
832 { &dib0700_usb_id_table[6], NULL },
833 { NULL },
0ce215e1
HS
834 },
835 { "Uniwill STK7700P based (Hama and others)",
836 { &dib0700_usb_id_table[7], NULL },
837 { NULL },
8637a875
MK
838 },
839 { "Leadtek Winfast DTV Dongle (STK7700P based)",
840 { &dib0700_usb_id_table[8], NULL },
841 { NULL },
49a1376c 842 }
b7f54910
PB
843 }
844 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
845
846 .num_adapters = 2,
847 .adapter = {
848 {
849 .frontend_attach = bristol_frontend_attach,
850 .tuner_attach = bristol_tuner_attach,
851
852 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
853 }, {
854 .frontend_attach = bristol_frontend_attach,
855 .tuner_attach = bristol_tuner_attach,
856
857 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
858 }
859 },
860
861 .num_device_descs = 1,
862 .devices = {
863 { "Hauppauge Nova-T 500 Dual DVB-T",
49a1376c 864 { &dib0700_usb_id_table[2], &dib0700_usb_id_table[3], NULL },
b7f54910
PB
865 { NULL },
866 },
867 }
54d75eba
OD
868 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
869
870 .num_adapters = 2,
871 .adapter = {
872 {
873 .frontend_attach = stk7700d_frontend_attach,
874 .tuner_attach = stk7700d_tuner_attach,
875
876 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
877 }, {
878 .frontend_attach = stk7700d_frontend_attach,
879 .tuner_attach = stk7700d_tuner_attach,
880
881 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
882 }
883 },
884
b6884a17 885 .num_device_descs = 4,
54d75eba
OD
886 .devices = {
887 { "Pinnacle PCTV 2000e",
888 { &dib0700_usb_id_table[11], NULL },
889 { NULL },
890 },
891 { "Terratec Cinergy DT XS Diversity",
892 { &dib0700_usb_id_table[12], NULL },
893 { NULL },
894 },
01373a5c 895 { "Haupauge Nova-TD Stick/Elgato Eye-TV Diversity",
54d75eba
OD
896 { &dib0700_usb_id_table[13], NULL },
897 { NULL },
898 },
01373a5c 899 { "DiBcom STK7700D reference design",
b6884a17
PB
900 { &dib0700_usb_id_table[14], NULL },
901 { NULL },
902 },
54d75eba
OD
903 },
904 .rc_interval = DEFAULT_RC_INTERVAL,
905 .rc_key_map = stk7700d_rc_keys,
906 .rc_key_map_size = KEY_MAP_SIZE,
907 .rc_query = stk7700d_rc_query
01373a5c
PB
908
909 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
910
911 .num_adapters = 1,
912 .adapter = {
913 {
914 .frontend_attach = stk7070p_frontend_attach,
915 .tuner_attach = dib7070p_tuner_attach,
916
917 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
918
919 .size_of_priv = sizeof(struct dib0700_adapter_state),
920 },
921 },
922
923 .num_device_descs = 2,
924 .devices = {
925 { "DiBcom STK7070P reference design",
926 { &dib0700_usb_id_table[15], NULL },
927 { NULL },
928 },
929 { "Pinnacle PCTV DVB-T Flash Stick",
930 { &dib0700_usb_id_table[16], NULL },
931 { NULL },
932 },
933 }
934 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
935
936 .num_adapters = 2,
937 .adapter = {
938 {
939 .frontend_attach = stk7070pd_frontend_attach0,
940 .tuner_attach = dib7070p_tuner_attach,
941
942 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
943
944 .size_of_priv = sizeof(struct dib0700_adapter_state),
945 }, {
946 .frontend_attach = stk7070pd_frontend_attach1,
947 .tuner_attach = dib7070p_tuner_attach,
948
949 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
950
951 .size_of_priv = sizeof(struct dib0700_adapter_state),
952 }
953 },
954
955 .num_device_descs = 2,
956 .devices = {
957 { "DiBcom STK7070PD reference design",
958 { &dib0700_usb_id_table[17], NULL },
959 { NULL },
960 },
961 { "Pinnacle PCTV Dual DVB-T Diversity Stick",
962 { &dib0700_usb_id_table[18], NULL },
963 { NULL },
964 },
965 }
966 },
b7f54910
PB
967};
968
969int dib0700_device_count = ARRAY_SIZE(dib0700_devices);