blob: 04b66f6e659fa4bd9f9d851e53da164fa3649f66 [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 *
Patrick Boettcherb6884a12007-07-27 10:08:51 -03007 * Copyright (C) 2005-7 DiBcom, SA
Patrick Boettcherb7f54912006-09-19 12:51:37 -03008 */
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"
Olivier DANET54d75eb2007-07-25 14:42:54 -030015#include "mt2266.h"
Patrick Boettcherb7f54912006-09-19 12:51:37 -030016
Patrick Boettcher7fb3fc02006-09-20 04:37:18 -030017static int force_lna_activation;
18module_param(force_lna_activation, int, 0644);
19MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplifyer(s) (LNA), "
20 "if applicable for the device (default: 0=automatic/off).");
21
Patrick Boettcherb7f54912006-09-19 12:51:37 -030022/* Hauppauge Nova-T 500
23 * has a LNA on GPIO0 which is enabled by setting 1 */
24static struct mt2060_config bristol_mt2060_config[2] = {
25 {
26 .i2c_address = 0x60,
Patrick Boettcher303cbea2006-09-19 12:51:56 -030027 .clock_out = 3,
Patrick Boettcherb7f54912006-09-19 12:51:37 -030028 }, {
29 .i2c_address = 0x61,
30 }
31};
32
33static struct dibx000_agc_config bristol_dib3000p_mt2060_agc_config = {
34 .band_caps = BAND_VHF | BAND_UHF,
Patrick Boettcher01b4bf32006-09-19 12:51:53 -030035 .setup = (1 << 8) | (5 << 5) | (0 << 4) | (0 << 3) | (0 << 2) | (2 << 0),
Patrick Boettcherb7f54912006-09-19 12:51:37 -030036
Patrick Boettcher6958eff2006-09-19 12:51:40 -030037 .agc1_max = 42598,
38 .agc1_min = 17694,
39 .agc2_max = 45875,
40 .agc2_min = 0,
Patrick Boettcherb7f54912006-09-19 12:51:37 -030041
Patrick Boettcher6958eff2006-09-19 12:51:40 -030042 .agc1_pt1 = 0,
43 .agc1_pt2 = 59,
Patrick Boettcherb7f54912006-09-19 12:51:37 -030044
Patrick Boettcher6958eff2006-09-19 12:51:40 -030045 .agc1_slope1 = 0,
46 .agc1_slope2 = 69,
Patrick Boettcherb7f54912006-09-19 12:51:37 -030047
48 .agc2_pt1 = 0,
Patrick Boettcher6958eff2006-09-19 12:51:40 -030049 .agc2_pt2 = 59,
Patrick Boettcherb7f54912006-09-19 12:51:37 -030050
Patrick Boettcher6958eff2006-09-19 12:51:40 -030051 .agc2_slope1 = 111,
52 .agc2_slope2 = 28,
Patrick Boettcherb7f54912006-09-19 12:51:37 -030053};
54
55static struct dib3000mc_config bristol_dib3000mc_config[2] = {
56 { .agc = &bristol_dib3000p_mt2060_agc_config,
57 .max_time = 0x196,
58 .ln_adc_level = 0x1cc7,
59 .output_mpeg2_in_188_bytes = 1,
60 },
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};
67
68static int bristol_frontend_attach(struct dvb_usb_adapter *adap)
69{
Patrick Boettcher6958eff2006-09-19 12:51:40 -030070 struct dib0700_state *st = adap->dev->priv;
Patrick Boettcherb7f54912006-09-19 12:51:37 -030071 if (adap->id == 0) {
72 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(10);
73 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); msleep(10);
74 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10);
75 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(10);
76
Patrick Boettcher7fb3fc02006-09-20 04:37:18 -030077 if (force_lna_activation)
78 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
79 else
80 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 0);
Patrick Boettcher6958eff2006-09-19 12:51:40 -030081
Patrick Boettcherb7f54912006-09-19 12:51:37 -030082 if (dib3000mc_i2c_enumeration(&adap->dev->i2c_adap, 2, DEFAULT_DIB3000P_I2C_ADDRESS, bristol_dib3000mc_config) != 0) {
83 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(10);
84 return -ENODEV;
85 }
86 }
Patrick Boettcher6958eff2006-09-19 12:51:40 -030087 st->mt2060_if1[adap->id] = 1220;
88 return (adap->fe = dvb_attach(dib3000mc_attach, &adap->dev->i2c_adap,
89 (10 + adap->id) << 1, &bristol_dib3000mc_config[adap->id])) == NULL ? -ENODEV : 0;
Patrick Boettcherb7f54912006-09-19 12:51:37 -030090}
91
92static int bristol_tuner_attach(struct dvb_usb_adapter *adap)
93{
94 struct dib0700_state *st = adap->dev->priv;
95 struct i2c_adapter *tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe, 1);
Patrick Boettcher6958eff2006-09-19 12:51:40 -030096 return dvb_attach(mt2060_attach,adap->fe, tun_i2c, &bristol_mt2060_config[adap->id],
97 st->mt2060_if1[adap->id]) == NULL ? -ENODEV : 0;
Patrick Boettcherb7f54912006-09-19 12:51:37 -030098}
99
Olivier DANET54d75eb2007-07-25 14:42:54 -0300100/* STK7700D: Pinnacle Dual DVB-T Diversity */
101
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300102/* MT226x */
103static struct dibx000_agc_config stk7700d_7000p_mt2266_agc_config[2] = {
104 {
105 BAND_UHF, // band_caps
Olivier DANET54d75eb2007-07-25 14:42:54 -0300106
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300107 /* 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,
108 * 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 */
109 (0 << 15) | (0 << 14) | (1 << 11) | (1 << 10) | (1 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0), // setup
Olivier DANET54d75eb2007-07-25 14:42:54 -0300110
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300111 1130, // inv_gain
112 21, // time_stabiliz
Olivier DANET54d75eb2007-07-25 14:42:54 -0300113
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300114 0, // alpha_level
115 118, // thlock
Olivier DANET54d75eb2007-07-25 14:42:54 -0300116
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300117 0, // wbd_inv
118 3530, // wbd_ref
119 1, // wbd_sel
120 0, // wbd_alpha
Olivier DANET54d75eb2007-07-25 14:42:54 -0300121
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300122 65535, // agc1_max
123 33770, // agc1_min
124 65535, // agc2_max
125 23592, // agc2_min
Olivier DANET54d75eb2007-07-25 14:42:54 -0300126
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300127 0, // agc1_pt1
128 62, // agc1_pt2
129 255, // agc1_pt3
130 64, // agc1_slope1
131 64, // agc1_slope2
132 132, // agc2_pt1
133 192, // agc2_pt2
134 80, // agc2_slope1
135 80, // agc2_slope2
136
137 17, // alpha_mant
138 27, // alpha_exp
139 23, // beta_mant
140 51, // beta_exp
141
142 1, // perform_agc_softsplit
143 }, {
144 BAND_VHF | BAND_LBAND, // band_caps
145
146 /* 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,
147 * 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 */
148 (0 << 15) | (0 << 14) | (1 << 11) | (1 << 10) | (1 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), // setup
149
150 2372, // inv_gain
151 21, // time_stabiliz
152
153 0, // alpha_level
154 118, // thlock
155
156 0, // wbd_inv
157 3530, // wbd_ref
158 1, // wbd_sel
159 0, // wbd_alpha
160
161 65535, // agc1_max
162 0, // agc1_min
163 65535, // agc2_max
164 23592, // agc2_min
165
166 0, // agc1_pt1
167 128, // agc1_pt2
168 128, // agc1_pt3
169 128, // agc1_slope1
170 0, // agc1_slope2
171 128, // agc2_pt1
172 253, // agc2_pt2
173 81, // agc2_slope1
174 0, // agc2_slope2
175
176 17, // alpha_mant
177 27, // alpha_exp
178 23, // beta_mant
179 51, // beta_exp
180
181 1, // perform_agc_softsplit
182 }
Olivier DANET54d75eb2007-07-25 14:42:54 -0300183};
184
185static struct dibx000_bandwidth_config stk7700d_mt2266_pll_config = {
186 60000, 30000, // internal, sampling
187 1, 8, 3, 1, 0, // pll_cfg: prediv, ratio, range, reset, bypass
188 0, 0, 1, 1, 2, // misc: refdiv, bypclk_div, IO_CLK_en_core, ADClkSrc, modulo
189 (3 << 14) | (1 << 12) | (524 << 0), // sad_cfg: refsel, sel, freq_15k
190 0, // ifreq
191 20452225, // timf
192};
193
194static struct dib7000p_config stk7700d_dib7000p_mt2266_config[] = {
195 { .output_mpeg2_in_188_bytes = 1,
196 .hostbus_diversity = 1,
197 .tuner_is_baseband = 1,
198
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300199 .agc_config_count = 2,
200 .agc = stk7700d_7000p_mt2266_agc_config,
Olivier DANET54d75eb2007-07-25 14:42:54 -0300201 .bw = &stk7700d_mt2266_pll_config,
202
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300203 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
204 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
205 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
Olivier DANET54d75eb2007-07-25 14:42:54 -0300206 },
207 { .output_mpeg2_in_188_bytes = 1,
208 .hostbus_diversity = 1,
209 .tuner_is_baseband = 1,
210
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300211 .agc_config_count = 2,
212 .agc = stk7700d_7000p_mt2266_agc_config,
Olivier DANET54d75eb2007-07-25 14:42:54 -0300213 .bw = &stk7700d_mt2266_pll_config,
214
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300215 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
216 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
217 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
Olivier DANET54d75eb2007-07-25 14:42:54 -0300218 }
219};
220
221static struct mt2266_config stk7700d_mt2266_config[2] = {
222 { .i2c_address = 0x60
223 },
224 { .i2c_address = 0x60
225 }
226};
227
228static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap)
229{
230 if (adap->id == 0) {
231 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
232 msleep(10);
233 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
234 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
235 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
236 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
237 msleep(10);
238 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
239 msleep(10);
240 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
241 dib7000p_i2c_enumeration(&adap->dev->i2c_adap,2,18,stk7700d_dib7000p_mt2266_config);
242 }
243
244 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,0x80+(adap->id << 1),
245 &stk7700d_dib7000p_mt2266_config[adap->id]);
246
247 return adap->fe == NULL ? -ENODEV : 0;
248}
249
250static int stk7700d_tuner_attach(struct dvb_usb_adapter *adap)
251{
252 struct i2c_adapter *tun_i2c;
253 tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
254 return dvb_attach(mt2266_attach, adap->fe, tun_i2c,
255 &stk7700d_mt2266_config[adap->id]) == NULL ? -ENODEV : 0;;
256}
257
258#define DEFAULT_RC_INTERVAL 150
259
260static u8 rc_request[] = { REQUEST_POLL_RC, 0 };
261
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300262static int stk7700d_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
Olivier DANET54d75eb2007-07-25 14:42:54 -0300263{
264 u8 key[4];
265 int i;
266 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
267 struct dib0700_state *st = d->priv;
268 *event = 0;
269 *state = REMOTE_NO_KEY_PRESSED;
270 i=dib0700_ctrl_rd(d,rc_request,2,key,4);
271 if (i<=0) {
272 err("stk7700d:RC Query Failed\n");
273 return 0;
274 }
275 if (key[0]==0 && key[1]==0 && key[2]==0 && key[3]==0) return 0;
276 if (key[1]!=st->rc_toggle) {
277 for (i=0;i<d->props.rc_key_map_size; i++) {
278 if (keymap[i].custom == key[2] && keymap[i].data == key[3]) {
279 *event = keymap[i].event;
280 *state = REMOTE_KEY_PRESSED;
281 st->rc_toggle=key[1];
282 return 0;
283 }
284 }
285 err("stk7700d:Unknown remote controller key : %2X %2X\n",(int)key[2],(int)key[3]);
286 }
287 return 0;
288}
289
290#define KEY_MAP_SIZE (25+48)
291
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300292static struct dvb_usb_rc_key stk7700d_rc_keys[] = {
Olivier DANET54d75eb2007-07-25 14:42:54 -0300293 /* Key codes for the tiny Pinnacle remote*/
294 { 0x07, 0x00, KEY_MUTE },
295 { 0x07, 0x01, KEY_MENU }, // Pinnacle logo
296 { 0x07, 0x39, KEY_POWER },
297 { 0x07, 0x03, KEY_VOLUMEUP },
298 { 0x07, 0x09, KEY_VOLUMEDOWN },
299 { 0x07, 0x06, KEY_CHANNELUP },
300 { 0x07, 0x0c, KEY_CHANNELDOWN },
301 { 0x07, 0x0f, KEY_1 },
302 { 0x07, 0x15, KEY_2 },
303 { 0x07, 0x10, KEY_3 },
304 { 0x07, 0x18, KEY_4 },
305 { 0x07, 0x1b, KEY_5 },
306 { 0x07, 0x1e, KEY_6 },
307 { 0x07, 0x11, KEY_7 },
308 { 0x07, 0x21, KEY_8 },
309 { 0x07, 0x12, KEY_9 },
310 { 0x07, 0x27, KEY_0 },
311 { 0x07, 0x24, KEY_SCREEN }, // 'Square' key
312 { 0x07, 0x2a, KEY_TEXT }, // 'T' key
313 { 0x07, 0x2d, KEY_REWIND },
314 { 0x07, 0x30, KEY_PLAY },
315 { 0x07, 0x33, KEY_FASTFORWARD },
316 { 0x07, 0x36, KEY_RECORD },
317 { 0x07, 0x3c, KEY_STOP },
318 { 0x07, 0x3f, KEY_CANCEL }, // '?' key
319 /* Key codes for the Terratec Cinergy DT XS Diversity, similar to cinergyT2.c */
320 { 0xeb, 0x01, KEY_POWER },
321 { 0xeb, 0x02, KEY_1 },
322 { 0xeb, 0x03, KEY_2 },
323 { 0xeb, 0x04, KEY_3 },
324 { 0xeb, 0x05, KEY_4 },
325 { 0xeb, 0x06, KEY_5 },
326 { 0xeb, 0x07, KEY_6 },
327 { 0xeb, 0x08, KEY_7 },
328 { 0xeb, 0x09, KEY_8 },
329 { 0xeb, 0x0a, KEY_9 },
330 { 0xeb, 0x0b, KEY_VIDEO },
331 { 0xeb, 0x0c, KEY_0 },
332 { 0xeb, 0x0d, KEY_REFRESH },
333 { 0xeb, 0x0f, KEY_EPG },
334 { 0xeb, 0x10, KEY_UP },
335 { 0xeb, 0x11, KEY_LEFT },
336 { 0xeb, 0x12, KEY_OK },
337 { 0xeb, 0x13, KEY_RIGHT },
338 { 0xeb, 0x14, KEY_DOWN },
339 { 0xeb, 0x16, KEY_INFO },
340 { 0xeb, 0x17, KEY_RED },
341 { 0xeb, 0x18, KEY_GREEN },
342 { 0xeb, 0x19, KEY_YELLOW },
343 { 0xeb, 0x1a, KEY_BLUE },
344 { 0xeb, 0x1b, KEY_CHANNELUP },
345 { 0xeb, 0x1c, KEY_VOLUMEUP },
346 { 0xeb, 0x1d, KEY_MUTE },
347 { 0xeb, 0x1e, KEY_VOLUMEDOWN },
348 { 0xeb, 0x1f, KEY_CHANNELDOWN },
349 { 0xeb, 0x40, KEY_PAUSE },
350 { 0xeb, 0x41, KEY_HOME },
351 { 0xeb, 0x42, KEY_MENU }, /* DVD Menu */
352 { 0xeb, 0x43, KEY_SUBTITLE },
353 { 0xeb, 0x44, KEY_TEXT }, /* Teletext */
354 { 0xeb, 0x45, KEY_DELETE },
355 { 0xeb, 0x46, KEY_TV },
356 { 0xeb, 0x47, KEY_DVD },
357 { 0xeb, 0x48, KEY_STOP },
358 { 0xeb, 0x49, KEY_VIDEO },
359 { 0xeb, 0x4a, KEY_AUDIO }, /* Music */
360 { 0xeb, 0x4b, KEY_SCREEN }, /* Pic */
361 { 0xeb, 0x4c, KEY_PLAY },
362 { 0xeb, 0x4d, KEY_BACK },
363 { 0xeb, 0x4e, KEY_REWIND },
364 { 0xeb, 0x4f, KEY_FASTFORWARD },
365 { 0xeb, 0x54, KEY_PREVIOUS },
366 { 0xeb, 0x58, KEY_RECORD },
367 { 0xeb, 0x5c, KEY_NEXT }
368 };
369
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300370/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */
Patrick Boettchera75763f2006-10-18 08:34:16 -0300371static struct dibx000_agc_config stk7700p_7000m_mt2060_agc_config = {
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300372 BAND_UHF | BAND_VHF, // band_caps
373
374 /* 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,
375 * 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 */
376 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), // setup
377
378 712, // inv_gain
379 41, // time_stabiliz
380
381 0, // alpha_level
382 118, // thlock
383
384 0, // wbd_inv
385 4095, // wbd_ref
386 0, // wbd_sel
387 0, // wbd_alpha
388
389 42598, // agc1_max
390 17694, // agc1_min
391 45875, // agc2_max
392 2621, // agc2_min
393 0, // agc1_pt1
394 76, // agc1_pt2
395 139, // agc1_pt3
396 52, // agc1_slope1
397 59, // agc1_slope2
398 107, // agc2_pt1
399 172, // agc2_pt2
400 57, // agc2_slope1
401 70, // agc2_slope2
402
403 21, // alpha_mant
404 25, // alpha_exp
405 28, // beta_mant
406 48, // beta_exp
407
408 1, // perform_agc_softsplit
409 { 0, // split_min
410 107, // split_max
411 51800, // global_split_min
412 24700 // global_split_max
413 },
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300414};
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300415
Patrick Boettchera75763f2006-10-18 08:34:16 -0300416static struct dibx000_agc_config stk7700p_7000p_mt2060_agc_config = {
417 BAND_UHF | BAND_VHF,
418
419 /* 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,
420 * 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 */
421 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), // setup
422
423 712, // inv_gain
424 41, // time_stabiliz
425
426 0, // alpha_level
427 118, // thlock
428
429 0, // wbd_inv
430 4095, // wbd_ref
431 0, // wbd_sel
432 0, // wbd_alpha
433
434 42598, // agc1_max
435 16384, // agc1_min
436 42598, // agc2_max
437 0, // agc2_min
438
439 0, // agc1_pt1
440 137, // agc1_pt2
441 255, // agc1_pt3
442
443 0, // agc1_slope1
444 255, // agc1_slope2
445
446 0, // agc2_pt1
447 0, // agc2_pt2
448
449 0, // agc2_slope1
450 41, // agc2_slope2
451
452 15, // alpha_mant
453 25, // alpha_exp
454
455 28, // beta_mant
456 48, // beta_exp
457
458 0, // perform_agc_softsplit
459};
460
461static struct dibx000_bandwidth_config stk7700p_pll_config = {
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300462 60000, 30000, // internal, sampling
463 1, 8, 3, 1, 0, // pll_cfg: prediv, ratio, range, reset, bypass
464 0, 0, 1, 1, 0, // misc: refdiv, bypclk_div, IO_CLK_en_core, ADClkSrc, modulo
465 (3 << 14) | (1 << 12) | (524 << 0), // sad_cfg: refsel, sel, freq_15k
466 60258167, // ifreq
467 20452225, // timf
468};
469
470static struct dib7000m_config stk7700p_dib7000m_config = {
471 .dvbt_mode = 1,
472 .output_mpeg2_in_188_bytes = 1,
473 .quartz_direct = 1,
474
475 .agc_config_count = 1,
Patrick Boettchera75763f2006-10-18 08:34:16 -0300476 .agc = &stk7700p_7000m_mt2060_agc_config,
477 .bw = &stk7700p_pll_config,
478
479 .gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
480 .gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
481 .gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
482};
483
484static struct dib7000p_config stk7700p_dib7000p_config = {
485 .output_mpeg2_in_188_bytes = 1,
486
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300487 .agc_config_count = 1,
Patrick Boettchera75763f2006-10-18 08:34:16 -0300488 .agc = &stk7700p_7000p_mt2060_agc_config,
489 .bw = &stk7700p_pll_config,
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300490
491 .gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
492 .gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
493 .gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
494};
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300495
496static int stk7700p_frontend_attach(struct dvb_usb_adapter *adap)
497{
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300498 struct dib0700_state *st = adap->dev->priv;
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300499 /* unless there is no real power management in DVB - we leave the device on GPIO6 */
Patrick Boettchera75763f2006-10-18 08:34:16 -0300500
501 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
502 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(50);
503
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300504 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); msleep(10);
Patrick Boettchera75763f2006-10-18 08:34:16 -0300505 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
506
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300507 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10);
Patrick Boettchera75763f2006-10-18 08:34:16 -0300508 dib0700_ctrl_clock(adap->dev, 72, 1);
509 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(100);
510
511 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300512
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300513 st->mt2060_if1[0] = 1220;
Patrick Boettchera75763f2006-10-18 08:34:16 -0300514
515 if (dib7000pc_detection(&adap->dev->i2c_adap)) {
516 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000p_config);
517 st->is_dib7000pc = 1;
518 } else
519 adap->fe = dvb_attach(dib7000m_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000m_config);
520
521 return adap->fe == NULL ? -ENODEV : 0;
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300522}
523
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300524static struct mt2060_config stk7700p_mt2060_config = {
525 0x60
526};
527
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300528static int stk7700p_tuner_attach(struct dvb_usb_adapter *adap)
529{
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300530 struct dib0700_state *st = adap->dev->priv;
Patrick Boettchera75763f2006-10-18 08:34:16 -0300531 struct i2c_adapter *tun_i2c;
532
533 if (st->is_dib7000pc)
534 tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
535 else
536 tun_i2c = dib7000m_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
537
538 return dvb_attach(mt2060_attach, adap->fe, tun_i2c, &stk7700p_mt2060_config,
Patrick Boettcher69ea31e2006-10-17 18:28:14 -0300539 st->mt2060_if1[0]) == NULL ? -ENODEV : 0;
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300540}
541
542struct usb_device_id dib0700_usb_id_table[] = {
543 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) },
Tomi Koivulahti49a13762006-10-19 07:27:19 -0300544 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P_PC) },
545
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300546 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500) },
Patrick Boettcherd535cfa2006-09-19 12:51:49 -0300547 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_2) },
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300548 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK) },
549 { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR) },
Tomi Koivulahti49a13762006-10-19 07:27:19 -0300550 { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_VIDEOMATE_U500) },
Henning Schroeer0ce215e2006-10-19 07:58:22 -0300551 { USB_DEVICE(USB_VID_UNIWILL, USB_PID_UNIWILL_STK7700P) },
Michael Krufky8637a872006-11-08 16:47:32 -0300552 { USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_STK7700P) },
Stefan Trabyf9aeba42006-11-12 13:02:51 -0300553 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_2) },
Jose Carlos Garcia Sogoced8fec2006-11-14 05:01:47 -0300554 { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_2) },
Olivier DANET54d75eb2007-07-25 14:42:54 -0300555 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV2000E) },
556 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY) },
557 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK) },
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300558 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700D) },
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300559 { } /* Terminating entry */
560};
561MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
562
563#define DIB0700_DEFAULT_DEVICE_PROPERTIES \
564 .caps = DVB_USB_IS_AN_I2C_ADAPTER, \
565 .usb_ctrl = DEVICE_SPECIFIC, \
566 .firmware = "dvb-usb-dib0700-01.fw", \
567 .download_firmware = dib0700_download_firmware, \
Patrick Boettcher6958eff2006-09-19 12:51:40 -0300568 .no_reconnect = 1, \
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300569 .size_of_priv = sizeof(struct dib0700_state), \
Patrick Boettcher6958eff2006-09-19 12:51:40 -0300570 .i2c_algo = &dib0700_i2c_algo, \
571 .identify_state = dib0700_identify_state
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300572
573#define DIB0700_DEFAULT_STREAMING_CONFIG(ep) \
574 .streaming_ctrl = dib0700_streaming_ctrl, \
575 .stream = { \
576 .type = USB_BULK, \
577 .count = 4, \
578 .endpoint = ep, \
579 .u = { \
580 .bulk = { \
581 .buffersize = 39480, \
582 } \
583 } \
584 }
585
586struct dvb_usb_device_properties dib0700_devices[] = {
587 {
588 DIB0700_DEFAULT_DEVICE_PROPERTIES,
589
590 .num_adapters = 1,
591 .adapter = {
592 {
593 .frontend_attach = stk7700p_frontend_attach,
594 .tuner_attach = stk7700p_tuner_attach,
595
596 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
597 },
598 },
599
Michael Krufky8637a872006-11-08 16:47:32 -0300600 .num_device_descs = 6,
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300601 .devices = {
602 { "DiBcom STK7700P reference design",
Tomi Koivulahti49a13762006-10-19 07:27:19 -0300603 { &dib0700_usb_id_table[0], &dib0700_usb_id_table[1] },
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300604 { NULL },
605 },
606 { "Hauppauge Nova-T Stick",
Stefan Trabyf9aeba42006-11-12 13:02:51 -0300607 { &dib0700_usb_id_table[4], &dib0700_usb_id_table[9], NULL },
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300608 { NULL },
609 },
Tomi Koivulahti49a13762006-10-19 07:27:19 -0300610 { "AVerMedia AVerTV DVB-T Volar",
Jose Carlos Garcia Sogoced8fec2006-11-14 05:01:47 -0300611 { &dib0700_usb_id_table[5], &dib0700_usb_id_table[10] },
Tomi Koivulahti49a13762006-10-19 07:27:19 -0300612 { NULL },
613 },
614 { "Compro Videomate U500",
615 { &dib0700_usb_id_table[6], NULL },
616 { NULL },
Henning Schroeer0ce215e2006-10-19 07:58:22 -0300617 },
618 { "Uniwill STK7700P based (Hama and others)",
619 { &dib0700_usb_id_table[7], NULL },
620 { NULL },
Michael Krufky8637a872006-11-08 16:47:32 -0300621 },
622 { "Leadtek Winfast DTV Dongle (STK7700P based)",
623 { &dib0700_usb_id_table[8], NULL },
624 { NULL },
Tomi Koivulahti49a13762006-10-19 07:27:19 -0300625 }
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300626 }
627 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
628
629 .num_adapters = 2,
630 .adapter = {
631 {
632 .frontend_attach = bristol_frontend_attach,
633 .tuner_attach = bristol_tuner_attach,
634
635 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
636 }, {
637 .frontend_attach = bristol_frontend_attach,
638 .tuner_attach = bristol_tuner_attach,
639
640 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
641 }
642 },
643
644 .num_device_descs = 1,
645 .devices = {
646 { "Hauppauge Nova-T 500 Dual DVB-T",
Tomi Koivulahti49a13762006-10-19 07:27:19 -0300647 { &dib0700_usb_id_table[2], &dib0700_usb_id_table[3], NULL },
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300648 { NULL },
649 },
650 }
Olivier DANET54d75eb2007-07-25 14:42:54 -0300651 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
652
653 .num_adapters = 2,
654 .adapter = {
655 {
656 .frontend_attach = stk7700d_frontend_attach,
657 .tuner_attach = stk7700d_tuner_attach,
658
659 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
660 }, {
661 .frontend_attach = stk7700d_frontend_attach,
662 .tuner_attach = stk7700d_tuner_attach,
663
664 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
665 }
666 },
667
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300668 .num_device_descs = 4,
Olivier DANET54d75eb2007-07-25 14:42:54 -0300669 .devices = {
670 { "Pinnacle PCTV 2000e",
671 { &dib0700_usb_id_table[11], NULL },
672 { NULL },
673 },
674 { "Terratec Cinergy DT XS Diversity",
675 { &dib0700_usb_id_table[12], NULL },
676 { NULL },
677 },
678 { "Haupauge Nova-TD Stick",
679 { &dib0700_usb_id_table[13], NULL },
680 { NULL },
681 },
Patrick Boettcherb6884a12007-07-27 10:08:51 -0300682 { "DiBcom STK7700D",
683 { &dib0700_usb_id_table[14], NULL },
684 { NULL },
685 },
Olivier DANET54d75eb2007-07-25 14:42:54 -0300686 },
687 .rc_interval = DEFAULT_RC_INTERVAL,
688 .rc_key_map = stk7700d_rc_keys,
689 .rc_key_map_size = KEY_MAP_SIZE,
690 .rc_query = stk7700d_rc_query
Patrick Boettcherb7f54912006-09-19 12:51:37 -0300691 }
692};
693
694int dib0700_device_count = ARRAY_SIZE(dib0700_devices);