blob: 1fb017ecee74a18cf92c498abb7066d37dfe5d83 [file] [log] [blame]
Michael Krufky4c66c922011-08-29 00:05:35 -03001/*
2 * Copyright (C) 2010 Michael Krufky (mkrufky@kernellabs.com)
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation, version 2.
7 *
8 * see Documentation/dvb/README.dvb-usb for more information
9 */
10
11#include <linux/vmalloc.h>
12#include <linux/i2c.h>
13
14#include "mxl111sf.h"
15#include "mxl111sf-reg.h"
16#include "mxl111sf-phy.h"
17#include "mxl111sf-i2c.h"
18#include "mxl111sf-gpio.h"
19
Michael Krufky4f984802011-10-15 23:10:15 +010020#include "mxl111sf-demod.h"
Michael Krufky4c66c922011-08-29 00:05:35 -030021#include "mxl111sf-tuner.h"
22
23#include "lgdt3305.h"
Michael Krufky31136212012-01-29 15:53:55 -030024#include "lg2160.h"
Michael Krufky4c66c922011-08-29 00:05:35 -030025
26int dvb_usb_mxl111sf_debug;
27module_param_named(debug, dvb_usb_mxl111sf_debug, int, 0644);
28MODULE_PARM_DESC(debug, "set debugging level "
29 "(1=info, 2=xfer, 4=i2c, 8=reg, 16=adv (or-able)).");
30
31int dvb_usb_mxl111sf_isoc;
32module_param_named(isoc, dvb_usb_mxl111sf_isoc, int, 0644);
33MODULE_PARM_DESC(isoc, "enable usb isoc xfer (0=bulk, 1=isoc).");
34
Michael Krufky31136212012-01-29 15:53:55 -030035int dvb_usb_mxl111sf_spi;
36module_param_named(spi, dvb_usb_mxl111sf_spi, int, 0644);
37MODULE_PARM_DESC(spi, "use spi rather than tp for data xfer (0=tp, 1=spi).");
38
Michael Krufky4c66c922011-08-29 00:05:35 -030039#define ANT_PATH_AUTO 0
40#define ANT_PATH_EXTERNAL 1
41#define ANT_PATH_INTERNAL 2
42
43int dvb_usb_mxl111sf_rfswitch =
44#if 0
45 ANT_PATH_AUTO;
46#else
47 ANT_PATH_EXTERNAL;
48#endif
49
50module_param_named(rfswitch, dvb_usb_mxl111sf_rfswitch, int, 0644);
51MODULE_PARM_DESC(rfswitch, "force rf switch position (0=auto, 1=ext, 2=int).");
52
53DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
54
Antti Palosaari85722112012-06-26 00:17:04 -030055#define deb_info pr_debug
56#define deb_reg pr_debug
57#define deb_adv pr_debug
58#define err pr_err
59#define info pr_info
Michael Krufky4c66c922011-08-29 00:05:35 -030060
61int mxl111sf_ctrl_msg(struct dvb_usb_device *d,
62 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
63{
64 int wo = (rbuf == NULL || rlen == 0); /* write-only */
65 int ret;
66 u8 sndbuf[1+wlen];
67
68 deb_adv("%s(wlen = %d, rlen = %d)\n", __func__, wlen, rlen);
69
70 memset(sndbuf, 0, 1+wlen);
71
72 sndbuf[0] = cmd;
73 memcpy(&sndbuf[1], wbuf, wlen);
74
Antti Palosaari85722112012-06-26 00:17:04 -030075 ret = (wo) ? dvb_usbv2_generic_write(d, sndbuf, 1+wlen) :
76 dvb_usbv2_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen);
Michael Krufky4c66c922011-08-29 00:05:35 -030077 mxl_fail(ret);
78
79 return ret;
80}
81
82/* ------------------------------------------------------------------------ */
83
84#define MXL_CMD_REG_READ 0xaa
85#define MXL_CMD_REG_WRITE 0x55
86
87int mxl111sf_read_reg(struct mxl111sf_state *state, u8 addr, u8 *data)
88{
89 u8 buf[2];
90 int ret;
91
92 ret = mxl111sf_ctrl_msg(state->d, MXL_CMD_REG_READ, &addr, 1, buf, 2);
93 if (mxl_fail(ret)) {
94 mxl_debug("error reading reg: 0x%02x", addr);
95 goto fail;
96 }
97
98 if (buf[0] == addr)
99 *data = buf[1];
100 else {
101 err("invalid response reading reg: 0x%02x != 0x%02x, 0x%02x",
102 addr, buf[0], buf[1]);
103 ret = -EINVAL;
104 }
105
106 deb_reg("R: (0x%02x, 0x%02x)\n", addr, *data);
107fail:
108 return ret;
109}
110
111int mxl111sf_write_reg(struct mxl111sf_state *state, u8 addr, u8 data)
112{
113 u8 buf[] = { addr, data };
114 int ret;
115
116 deb_reg("W: (0x%02x, 0x%02x)\n", addr, data);
117
118 ret = mxl111sf_ctrl_msg(state->d, MXL_CMD_REG_WRITE, buf, 2, NULL, 0);
119 if (mxl_fail(ret))
120 err("error writing reg: 0x%02x, val: 0x%02x", addr, data);
121 return ret;
122}
123
124/* ------------------------------------------------------------------------ */
125
126int mxl111sf_write_reg_mask(struct mxl111sf_state *state,
127 u8 addr, u8 mask, u8 data)
128{
129 int ret;
130 u8 val;
131
132 if (mask != 0xff) {
133 ret = mxl111sf_read_reg(state, addr, &val);
134#if 1
135 /* dont know why this usually errors out on the first try */
136 if (mxl_fail(ret))
137 err("error writing addr: 0x%02x, mask: 0x%02x, "
138 "data: 0x%02x, retrying...", addr, mask, data);
139
140 ret = mxl111sf_read_reg(state, addr, &val);
141#endif
142 if (mxl_fail(ret))
143 goto fail;
144 }
145 val &= ~mask;
146 val |= data;
147
148 ret = mxl111sf_write_reg(state, addr, val);
149 mxl_fail(ret);
150fail:
151 return ret;
152}
153
154/* ------------------------------------------------------------------------ */
155
156int mxl111sf_ctrl_program_regs(struct mxl111sf_state *state,
157 struct mxl111sf_reg_ctrl_info *ctrl_reg_info)
158{
159 int i, ret = 0;
160
161 for (i = 0; ctrl_reg_info[i].addr |
162 ctrl_reg_info[i].mask |
163 ctrl_reg_info[i].data; i++) {
164
165 ret = mxl111sf_write_reg_mask(state,
166 ctrl_reg_info[i].addr,
167 ctrl_reg_info[i].mask,
168 ctrl_reg_info[i].data);
169 if (mxl_fail(ret)) {
170 err("failed on reg #%d (0x%02x)", i,
171 ctrl_reg_info[i].addr);
172 break;
173 }
174 }
175 return ret;
176}
177
178/* ------------------------------------------------------------------------ */
179
180static int mxl1x1sf_get_chip_info(struct mxl111sf_state *state)
181{
182 int ret;
183 u8 id, ver;
184 char *mxl_chip, *mxl_rev;
185
186 if ((state->chip_id) && (state->chip_ver))
187 return 0;
188
189 ret = mxl111sf_read_reg(state, CHIP_ID_REG, &id);
190 if (mxl_fail(ret))
191 goto fail;
192 state->chip_id = id;
193
194 ret = mxl111sf_read_reg(state, TOP_CHIP_REV_ID_REG, &ver);
195 if (mxl_fail(ret))
196 goto fail;
197 state->chip_ver = ver;
198
199 switch (id) {
200 case 0x61:
201 mxl_chip = "MxL101SF";
202 break;
203 case 0x63:
204 mxl_chip = "MxL111SF";
205 break;
206 default:
207 mxl_chip = "UNKNOWN MxL1X1";
208 break;
209 }
210 switch (ver) {
211 case 0x36:
212 state->chip_rev = MXL111SF_V6;
213 mxl_rev = "v6";
214 break;
215 case 0x08:
216 state->chip_rev = MXL111SF_V8_100;
217 mxl_rev = "v8_100";
218 break;
219 case 0x18:
220 state->chip_rev = MXL111SF_V8_200;
221 mxl_rev = "v8_200";
222 break;
223 default:
224 state->chip_rev = 0;
225 mxl_rev = "UNKNOWN REVISION";
226 break;
227 }
228 info("%s detected, %s (0x%x)", mxl_chip, mxl_rev, ver);
229fail:
230 return ret;
231}
232
233#define get_chip_info(state) \
234({ \
235 int ___ret; \
236 ___ret = mxl1x1sf_get_chip_info(state); \
237 if (mxl_fail(___ret)) { \
238 mxl_debug("failed to get chip info" \
239 " on first probe attempt"); \
240 ___ret = mxl1x1sf_get_chip_info(state); \
241 if (mxl_fail(___ret)) \
242 err("failed to get chip info during probe"); \
243 else \
244 mxl_debug("probe needed a retry " \
245 "in order to succeed."); \
246 } \
247 ___ret; \
248})
249
250/* ------------------------------------------------------------------------ */
Antti Palosaari85722112012-06-26 00:17:04 -0300251#if 0
Michael Krufky4c66c922011-08-29 00:05:35 -0300252static int mxl111sf_power_ctrl(struct dvb_usb_device *d, int onoff)
253{
254 /* power control depends on which adapter is being woken:
255 * save this for init, instead, via mxl111sf_adap_fe_init */
256 return 0;
257}
Antti Palosaari85722112012-06-26 00:17:04 -0300258#endif
Michael Krufky4c66c922011-08-29 00:05:35 -0300259
260static int mxl111sf_adap_fe_init(struct dvb_frontend *fe)
261{
Antti Palosaari85722112012-06-26 00:17:04 -0300262 struct dvb_usb_device *d = fe_to_d(fe);
263 struct mxl111sf_state *state = fe_to_priv(fe);
264 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe->id];
Michael Krufky4c66c922011-08-29 00:05:35 -0300265 int err;
266
267 /* exit if we didnt initialize the driver yet */
268 if (!state->chip_id) {
269 mxl_debug("driver not yet initialized, exit.");
270 goto fail;
271 }
272
273 deb_info("%s()\n", __func__);
274
275 mutex_lock(&state->fe_lock);
276
277 state->alt_mode = adap_state->alt_mode;
278
Antti Palosaari85722112012-06-26 00:17:04 -0300279 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
Michael Krufky4c66c922011-08-29 00:05:35 -0300280 err("set interface failed");
281
282 err = mxl1x1sf_soft_reset(state);
283 mxl_fail(err);
284 err = mxl111sf_init_tuner_demod(state);
285 mxl_fail(err);
286 err = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
287
288 mxl_fail(err);
289 mxl111sf_enable_usb_output(state);
290 mxl_fail(err);
291 mxl1x1sf_top_master_ctrl(state, 1);
292 mxl_fail(err);
293
294 if ((MXL111SF_GPIO_MOD_DVBT != adap_state->gpio_mode) &&
295 (state->chip_rev > MXL111SF_V6)) {
296 mxl111sf_config_pin_mux_modes(state,
297 PIN_MUX_TS_SPI_IN_MODE_1);
298 mxl_fail(err);
299 }
300 err = mxl111sf_init_port_expander(state);
301 if (!mxl_fail(err)) {
302 state->gpio_mode = adap_state->gpio_mode;
303 err = mxl111sf_gpio_mode_switch(state, state->gpio_mode);
304 mxl_fail(err);
305#if 0
306 err = fe->ops.init(fe);
307#endif
308 msleep(100); /* add short delay after enabling
309 * the demod before touching it */
310 }
311
312 return (adap_state->fe_init) ? adap_state->fe_init(fe) : 0;
313fail:
314 return -ENODEV;
315}
316
317static int mxl111sf_adap_fe_sleep(struct dvb_frontend *fe)
318{
Antti Palosaari85722112012-06-26 00:17:04 -0300319 struct mxl111sf_state *state = fe_to_priv(fe);
320 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe->id];
Michael Krufky4c66c922011-08-29 00:05:35 -0300321 int err;
322
323 /* exit if we didnt initialize the driver yet */
324 if (!state->chip_id) {
325 mxl_debug("driver not yet initialized, exit.");
326 goto fail;
327 }
328
329 deb_info("%s()\n", __func__);
330
331 err = (adap_state->fe_sleep) ? adap_state->fe_sleep(fe) : 0;
332
333 mutex_unlock(&state->fe_lock);
334
335 return err;
336fail:
337 return -ENODEV;
338}
339
340
Antti Palosaari85722112012-06-26 00:17:04 -0300341static int mxl111sf_ep6_streaming_ctrl(struct dvb_frontend *fe, int onoff)
Michael Krufky4c66c922011-08-29 00:05:35 -0300342{
Antti Palosaari85722112012-06-26 00:17:04 -0300343 struct mxl111sf_state *state = fe_to_priv(fe);
344 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe->id];
Michael Krufky4c66c922011-08-29 00:05:35 -0300345 int ret = 0;
Michael Krufky4c66c922011-08-29 00:05:35 -0300346
347 deb_info("%s(%d)\n", __func__, onoff);
348
349 if (onoff) {
350 ret = mxl111sf_enable_usb_output(state);
351 mxl_fail(ret);
352 ret = mxl111sf_config_mpeg_in(state, 1, 1,
353 adap_state->ep6_clockphase,
354 0, 0);
355 mxl_fail(ret);
Michael Krufky3be5bb72012-03-18 14:35:57 -0300356#if 0
Michael Krufky4c66c922011-08-29 00:05:35 -0300357 } else {
358 ret = mxl111sf_disable_656_port(state);
359 mxl_fail(ret);
Michael Krufky3be5bb72012-03-18 14:35:57 -0300360#endif
Michael Krufky4c66c922011-08-29 00:05:35 -0300361 }
362
Michael Krufky4c66c922011-08-29 00:05:35 -0300363 return ret;
364}
365
Antti Palosaari85722112012-06-26 00:17:04 -0300366static int mxl111sf_ep5_streaming_ctrl(struct dvb_frontend *fe, int onoff)
Michael Krufky31136212012-01-29 15:53:55 -0300367{
Antti Palosaari85722112012-06-26 00:17:04 -0300368 struct mxl111sf_state *state = fe_to_priv(fe);
Michael Krufky31136212012-01-29 15:53:55 -0300369 int ret = 0;
370
371 deb_info("%s(%d)\n", __func__, onoff);
372
373 if (onoff) {
374 ret = mxl111sf_enable_usb_output(state);
375 mxl_fail(ret);
376
377 ret = mxl111sf_init_i2s_port(state, 200);
378 mxl_fail(ret);
379 ret = mxl111sf_config_i2s(state, 0, 15);
380 mxl_fail(ret);
381 } else {
382 ret = mxl111sf_disable_i2s_port(state);
383 mxl_fail(ret);
384 }
385 if (state->chip_rev > MXL111SF_V6)
386 ret = mxl111sf_config_spi(state, onoff);
387 mxl_fail(ret);
388
389 return ret;
390}
391
Antti Palosaari85722112012-06-26 00:17:04 -0300392static int mxl111sf_ep4_streaming_ctrl(struct dvb_frontend *fe, int onoff)
Michael Krufky4f984802011-10-15 23:10:15 +0100393{
Antti Palosaari85722112012-06-26 00:17:04 -0300394 struct mxl111sf_state *state = fe_to_priv(fe);
Michael Krufky4f984802011-10-15 23:10:15 +0100395 int ret = 0;
396
397 deb_info("%s(%d)\n", __func__, onoff);
398
399 if (onoff) {
400 ret = mxl111sf_enable_usb_output(state);
401 mxl_fail(ret);
402 }
403
404 return ret;
405}
406
Michael Krufky4c66c922011-08-29 00:05:35 -0300407/* ------------------------------------------------------------------------ */
408
409static struct lgdt3305_config hauppauge_lgdt3305_config = {
410 .i2c_addr = 0xb2 >> 1,
411 .mpeg_mode = LGDT3305_MPEG_SERIAL,
412 .tpclk_edge = LGDT3305_TPCLK_RISING_EDGE,
413 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
414 .deny_i2c_rptr = 1,
415 .spectral_inversion = 0,
416 .qam_if_khz = 6000,
417 .vsb_if_khz = 6000,
418};
419
Antti Palosaari85722112012-06-26 00:17:04 -0300420static int mxl111sf_lgdt3305_frontend_attach(struct dvb_usb_adapter *adap, u8 fe_id)
Michael Krufky4c66c922011-08-29 00:05:35 -0300421{
Antti Palosaari85722112012-06-26 00:17:04 -0300422 struct dvb_usb_device *d = adap_to_d(adap);
423 struct mxl111sf_state *state = d_to_priv(d);
424 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
Michael Krufky4c66c922011-08-29 00:05:35 -0300425 int ret;
426
427 deb_adv("%s()\n", __func__);
428
429 /* save a pointer to the dvb_usb_device in device state */
430 state->d = d;
431 adap_state->alt_mode = (dvb_usb_mxl111sf_isoc) ? 2 : 1;
432 state->alt_mode = adap_state->alt_mode;
433
Antti Palosaari85722112012-06-26 00:17:04 -0300434 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
Michael Krufky4c66c922011-08-29 00:05:35 -0300435 err("set interface failed");
436
437 state->gpio_mode = MXL111SF_GPIO_MOD_ATSC;
438 adap_state->gpio_mode = state->gpio_mode;
439 adap_state->device_mode = MXL_TUNER_MODE;
440 adap_state->ep6_clockphase = 1;
441
442 ret = mxl1x1sf_soft_reset(state);
443 if (mxl_fail(ret))
444 goto fail;
445 ret = mxl111sf_init_tuner_demod(state);
446 if (mxl_fail(ret))
447 goto fail;
448
449 ret = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
450 if (mxl_fail(ret))
451 goto fail;
452
453 ret = mxl111sf_enable_usb_output(state);
454 if (mxl_fail(ret))
455 goto fail;
456 ret = mxl1x1sf_top_master_ctrl(state, 1);
457 if (mxl_fail(ret))
458 goto fail;
459
460 ret = mxl111sf_init_port_expander(state);
461 if (mxl_fail(ret))
462 goto fail;
463 ret = mxl111sf_gpio_mode_switch(state, state->gpio_mode);
464 if (mxl_fail(ret))
465 goto fail;
466
Antti Palosaari85722112012-06-26 00:17:04 -0300467 adap->fe[fe_id] = dvb_attach(lgdt3305_attach,
Michael Krufky4c66c922011-08-29 00:05:35 -0300468 &hauppauge_lgdt3305_config,
Antti Palosaari85722112012-06-26 00:17:04 -0300469 &d->i2c_adap);
470 if (adap->fe[fe_id]) {
471 state->num_frontends++;
472 adap_state->fe_init = adap->fe[fe_id]->ops.init;
473 adap->fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
474 adap_state->fe_sleep = adap->fe[fe_id]->ops.sleep;
475 adap->fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
Michael Krufky4c66c922011-08-29 00:05:35 -0300476 return 0;
477 }
478 ret = -EIO;
479fail:
480 return ret;
481}
482
Michael Krufky31136212012-01-29 15:53:55 -0300483static struct lg2160_config hauppauge_lg2160_config = {
484 .lg_chip = LG2160,
485 .i2c_addr = 0x1c >> 1,
486 .deny_i2c_rptr = 1,
487 .spectral_inversion = 0,
488 .if_khz = 6000,
489};
490
Antti Palosaari85722112012-06-26 00:17:04 -0300491static int mxl111sf_lg2160_frontend_attach(struct dvb_usb_adapter *adap, u8 fe_id)
Michael Krufky31136212012-01-29 15:53:55 -0300492{
Antti Palosaari85722112012-06-26 00:17:04 -0300493 struct dvb_usb_device *d = adap_to_d(adap);
494 struct mxl111sf_state *state = d_to_priv(d);
495 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
Michael Krufky31136212012-01-29 15:53:55 -0300496 int ret;
497
498 deb_adv("%s()\n", __func__);
499
500 /* save a pointer to the dvb_usb_device in device state */
501 state->d = d;
502 adap_state->alt_mode = (dvb_usb_mxl111sf_isoc) ? 2 : 1;
503 state->alt_mode = adap_state->alt_mode;
504
Antti Palosaari85722112012-06-26 00:17:04 -0300505 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
Michael Krufky31136212012-01-29 15:53:55 -0300506 err("set interface failed");
507
508 state->gpio_mode = MXL111SF_GPIO_MOD_MH;
509 adap_state->gpio_mode = state->gpio_mode;
510 adap_state->device_mode = MXL_TUNER_MODE;
511 adap_state->ep6_clockphase = 1;
512
513 ret = mxl1x1sf_soft_reset(state);
514 if (mxl_fail(ret))
515 goto fail;
516 ret = mxl111sf_init_tuner_demod(state);
517 if (mxl_fail(ret))
518 goto fail;
519
520 ret = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
521 if (mxl_fail(ret))
522 goto fail;
523
524 ret = mxl111sf_enable_usb_output(state);
525 if (mxl_fail(ret))
526 goto fail;
527 ret = mxl1x1sf_top_master_ctrl(state, 1);
528 if (mxl_fail(ret))
529 goto fail;
530
531 ret = mxl111sf_init_port_expander(state);
532 if (mxl_fail(ret))
533 goto fail;
534 ret = mxl111sf_gpio_mode_switch(state, state->gpio_mode);
535 if (mxl_fail(ret))
536 goto fail;
537
538 ret = get_chip_info(state);
539 if (mxl_fail(ret))
540 goto fail;
541
Antti Palosaari85722112012-06-26 00:17:04 -0300542 adap->fe[fe_id] = dvb_attach(lg2160_attach,
Michael Krufky31136212012-01-29 15:53:55 -0300543 &hauppauge_lg2160_config,
Antti Palosaari85722112012-06-26 00:17:04 -0300544 &d->i2c_adap);
545 if (adap->fe[fe_id]) {
546 state->num_frontends++;
547 adap_state->fe_init = adap->fe[fe_id]->ops.init;
548 adap->fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
549 adap_state->fe_sleep = adap->fe[fe_id]->ops.sleep;
550 adap->fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
Michael Krufky31136212012-01-29 15:53:55 -0300551 return 0;
552 }
553 ret = -EIO;
554fail:
555 return ret;
556}
557
558static struct lg2160_config hauppauge_lg2161_1019_config = {
559 .lg_chip = LG2161_1019,
560 .i2c_addr = 0x1c >> 1,
561 .deny_i2c_rptr = 1,
562 .spectral_inversion = 0,
563 .if_khz = 6000,
564 .output_if = 2, /* LG2161_OIF_SPI_MAS */
565};
566
567static struct lg2160_config hauppauge_lg2161_1040_config = {
568 .lg_chip = LG2161_1040,
569 .i2c_addr = 0x1c >> 1,
570 .deny_i2c_rptr = 1,
571 .spectral_inversion = 0,
572 .if_khz = 6000,
573 .output_if = 4, /* LG2161_OIF_SPI_MAS */
574};
575
Antti Palosaari85722112012-06-26 00:17:04 -0300576static int mxl111sf_lg2161_frontend_attach(struct dvb_usb_adapter *adap, u8 fe_id)
Michael Krufky31136212012-01-29 15:53:55 -0300577{
Antti Palosaari85722112012-06-26 00:17:04 -0300578 struct dvb_usb_device *d = adap_to_d(adap);
579 struct mxl111sf_state *state = d_to_priv(d);
580 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
Michael Krufky31136212012-01-29 15:53:55 -0300581 int ret;
582
583 deb_adv("%s()\n", __func__);
584
585 /* save a pointer to the dvb_usb_device in device state */
586 state->d = d;
587 adap_state->alt_mode = (dvb_usb_mxl111sf_isoc) ? 2 : 1;
588 state->alt_mode = adap_state->alt_mode;
589
Antti Palosaari85722112012-06-26 00:17:04 -0300590 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
Michael Krufky31136212012-01-29 15:53:55 -0300591 err("set interface failed");
592
593 state->gpio_mode = MXL111SF_GPIO_MOD_MH;
594 adap_state->gpio_mode = state->gpio_mode;
595 adap_state->device_mode = MXL_TUNER_MODE;
596 adap_state->ep6_clockphase = 1;
597
598 ret = mxl1x1sf_soft_reset(state);
599 if (mxl_fail(ret))
600 goto fail;
601 ret = mxl111sf_init_tuner_demod(state);
602 if (mxl_fail(ret))
603 goto fail;
604
605 ret = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
606 if (mxl_fail(ret))
607 goto fail;
608
609 ret = mxl111sf_enable_usb_output(state);
610 if (mxl_fail(ret))
611 goto fail;
612 ret = mxl1x1sf_top_master_ctrl(state, 1);
613 if (mxl_fail(ret))
614 goto fail;
615
616 ret = mxl111sf_init_port_expander(state);
617 if (mxl_fail(ret))
618 goto fail;
619 ret = mxl111sf_gpio_mode_switch(state, state->gpio_mode);
620 if (mxl_fail(ret))
621 goto fail;
622
623 ret = get_chip_info(state);
624 if (mxl_fail(ret))
625 goto fail;
626
Antti Palosaari85722112012-06-26 00:17:04 -0300627 adap->fe[fe_id] = dvb_attach(lg2160_attach,
Michael Krufky31136212012-01-29 15:53:55 -0300628 (MXL111SF_V8_200 == state->chip_rev) ?
629 &hauppauge_lg2161_1040_config :
630 &hauppauge_lg2161_1019_config,
Antti Palosaari85722112012-06-26 00:17:04 -0300631 &d->i2c_adap);
632 if (adap->fe[fe_id]) {
633 state->num_frontends++;
634 adap_state->fe_init = adap->fe[fe_id]->ops.init;
635 adap->fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
636 adap_state->fe_sleep = adap->fe[fe_id]->ops.sleep;
637 adap->fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
Michael Krufky31136212012-01-29 15:53:55 -0300638 return 0;
639 }
640 ret = -EIO;
641fail:
642 return ret;
643}
644
645static struct lg2160_config hauppauge_lg2161_1019_ep6_config = {
646 .lg_chip = LG2161_1019,
647 .i2c_addr = 0x1c >> 1,
648 .deny_i2c_rptr = 1,
649 .spectral_inversion = 0,
650 .if_khz = 6000,
651 .output_if = 1, /* LG2161_OIF_SERIAL_TS */
652};
653
654static struct lg2160_config hauppauge_lg2161_1040_ep6_config = {
655 .lg_chip = LG2161_1040,
656 .i2c_addr = 0x1c >> 1,
657 .deny_i2c_rptr = 1,
658 .spectral_inversion = 0,
659 .if_khz = 6000,
660 .output_if = 7, /* LG2161_OIF_SERIAL_TS */
661};
662
Antti Palosaari85722112012-06-26 00:17:04 -0300663static int mxl111sf_lg2161_ep6_frontend_attach(struct dvb_usb_adapter *adap, u8 fe_id)
Michael Krufky31136212012-01-29 15:53:55 -0300664{
Antti Palosaari85722112012-06-26 00:17:04 -0300665 struct dvb_usb_device *d = adap_to_d(adap);
666 struct mxl111sf_state *state = d_to_priv(d);
667 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
Michael Krufky31136212012-01-29 15:53:55 -0300668 int ret;
669
670 deb_adv("%s()\n", __func__);
671
672 /* save a pointer to the dvb_usb_device in device state */
673 state->d = d;
674 adap_state->alt_mode = (dvb_usb_mxl111sf_isoc) ? 2 : 1;
675 state->alt_mode = adap_state->alt_mode;
676
Antti Palosaari85722112012-06-26 00:17:04 -0300677 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
Michael Krufky31136212012-01-29 15:53:55 -0300678 err("set interface failed");
679
680 state->gpio_mode = MXL111SF_GPIO_MOD_MH;
681 adap_state->gpio_mode = state->gpio_mode;
682 adap_state->device_mode = MXL_TUNER_MODE;
683 adap_state->ep6_clockphase = 0;
684
685 ret = mxl1x1sf_soft_reset(state);
686 if (mxl_fail(ret))
687 goto fail;
688 ret = mxl111sf_init_tuner_demod(state);
689 if (mxl_fail(ret))
690 goto fail;
691
692 ret = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
693 if (mxl_fail(ret))
694 goto fail;
695
696 ret = mxl111sf_enable_usb_output(state);
697 if (mxl_fail(ret))
698 goto fail;
699 ret = mxl1x1sf_top_master_ctrl(state, 1);
700 if (mxl_fail(ret))
701 goto fail;
702
703 ret = mxl111sf_init_port_expander(state);
704 if (mxl_fail(ret))
705 goto fail;
706 ret = mxl111sf_gpio_mode_switch(state, state->gpio_mode);
707 if (mxl_fail(ret))
708 goto fail;
709
710 ret = get_chip_info(state);
711 if (mxl_fail(ret))
712 goto fail;
713
Antti Palosaari85722112012-06-26 00:17:04 -0300714 adap->fe[fe_id] = dvb_attach(lg2160_attach,
Michael Krufky31136212012-01-29 15:53:55 -0300715 (MXL111SF_V8_200 == state->chip_rev) ?
716 &hauppauge_lg2161_1040_ep6_config :
717 &hauppauge_lg2161_1019_ep6_config,
Antti Palosaari85722112012-06-26 00:17:04 -0300718 &d->i2c_adap);
719 if (adap->fe[fe_id]) {
720 state->num_frontends++;
721 adap_state->fe_init = adap->fe[fe_id]->ops.init;
722 adap->fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
723 adap_state->fe_sleep = adap->fe[fe_id]->ops.sleep;
724 adap->fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
Michael Krufky31136212012-01-29 15:53:55 -0300725 return 0;
726 }
727 ret = -EIO;
728fail:
729 return ret;
730}
731
Michael Krufky4f984802011-10-15 23:10:15 +0100732static struct mxl111sf_demod_config mxl_demod_config = {
733 .read_reg = mxl111sf_read_reg,
734 .write_reg = mxl111sf_write_reg,
735 .program_regs = mxl111sf_ctrl_program_regs,
736};
737
Antti Palosaari85722112012-06-26 00:17:04 -0300738static int mxl111sf_attach_demod(struct dvb_usb_adapter *adap, u8 fe_id)
Michael Krufky4f984802011-10-15 23:10:15 +0100739{
Antti Palosaari85722112012-06-26 00:17:04 -0300740 struct dvb_usb_device *d = adap_to_d(adap);
741 struct mxl111sf_state *state = d_to_priv(d);
742 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
Michael Krufky4f984802011-10-15 23:10:15 +0100743 int ret;
744
745 deb_adv("%s()\n", __func__);
746
747 /* save a pointer to the dvb_usb_device in device state */
748 state->d = d;
749 adap_state->alt_mode = (dvb_usb_mxl111sf_isoc) ? 1 : 2;
750 state->alt_mode = adap_state->alt_mode;
751
Antti Palosaari85722112012-06-26 00:17:04 -0300752 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
Michael Krufky4f984802011-10-15 23:10:15 +0100753 err("set interface failed");
754
755 state->gpio_mode = MXL111SF_GPIO_MOD_DVBT;
756 adap_state->gpio_mode = state->gpio_mode;
757 adap_state->device_mode = MXL_SOC_MODE;
758 adap_state->ep6_clockphase = 1;
759
760 ret = mxl1x1sf_soft_reset(state);
761 if (mxl_fail(ret))
762 goto fail;
763 ret = mxl111sf_init_tuner_demod(state);
764 if (mxl_fail(ret))
765 goto fail;
766
767 ret = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
768 if (mxl_fail(ret))
769 goto fail;
770
771 ret = mxl111sf_enable_usb_output(state);
772 if (mxl_fail(ret))
773 goto fail;
774 ret = mxl1x1sf_top_master_ctrl(state, 1);
775 if (mxl_fail(ret))
776 goto fail;
777
778 /* dont care if this fails */
779 mxl111sf_init_port_expander(state);
780
Antti Palosaari85722112012-06-26 00:17:04 -0300781 adap->fe[fe_id] = dvb_attach(mxl111sf_demod_attach, state,
Michael Krufky4f984802011-10-15 23:10:15 +0100782 &mxl_demod_config);
Antti Palosaari85722112012-06-26 00:17:04 -0300783 if (adap->fe[fe_id]) {
784 state->num_frontends++;
785 adap_state->fe_init = adap->fe[fe_id]->ops.init;
786 adap->fe[fe_id]->ops.init = mxl111sf_adap_fe_init;
787 adap_state->fe_sleep = adap->fe[fe_id]->ops.sleep;
788 adap->fe[fe_id]->ops.sleep = mxl111sf_adap_fe_sleep;
Michael Krufky4f984802011-10-15 23:10:15 +0100789 return 0;
790 }
791 ret = -EIO;
792fail:
793 return ret;
794}
795
Michael Krufky4c66c922011-08-29 00:05:35 -0300796static inline int mxl111sf_set_ant_path(struct mxl111sf_state *state,
797 int antpath)
798{
799 return mxl111sf_idac_config(state, 1, 1,
800 (antpath == ANT_PATH_INTERNAL) ?
801 0x3f : 0x00, 0);
802}
803
804#define DbgAntHunt(x, pwr0, pwr1, pwr2, pwr3) \
805 err("%s(%d) FINAL input set to %s rxPwr:%d|%d|%d|%d\n", \
806 __func__, __LINE__, \
807 (ANT_PATH_EXTERNAL == x) ? "EXTERNAL" : "INTERNAL", \
808 pwr0, pwr1, pwr2, pwr3)
809
810#define ANT_HUNT_SLEEP 90
811#define ANT_EXT_TWEAK 0
812
813static int mxl111sf_ant_hunt(struct dvb_frontend *fe)
814{
Antti Palosaari85722112012-06-26 00:17:04 -0300815 struct mxl111sf_state *state = fe_to_priv(fe);
Michael Krufky4c66c922011-08-29 00:05:35 -0300816 int antctrl = dvb_usb_mxl111sf_rfswitch;
817
818 u16 rxPwrA, rxPwr0, rxPwr1, rxPwr2;
819
820 /* FIXME: must force EXTERNAL for QAM - done elsewhere */
821 mxl111sf_set_ant_path(state, antctrl == ANT_PATH_AUTO ?
822 ANT_PATH_EXTERNAL : antctrl);
823
824 if (antctrl == ANT_PATH_AUTO) {
825#if 0
826 msleep(ANT_HUNT_SLEEP);
827#endif
828 fe->ops.tuner_ops.get_rf_strength(fe, &rxPwrA);
829
830 mxl111sf_set_ant_path(state, ANT_PATH_EXTERNAL);
831 msleep(ANT_HUNT_SLEEP);
832 fe->ops.tuner_ops.get_rf_strength(fe, &rxPwr0);
833
834 mxl111sf_set_ant_path(state, ANT_PATH_EXTERNAL);
835 msleep(ANT_HUNT_SLEEP);
836 fe->ops.tuner_ops.get_rf_strength(fe, &rxPwr1);
837
838 mxl111sf_set_ant_path(state, ANT_PATH_INTERNAL);
839 msleep(ANT_HUNT_SLEEP);
840 fe->ops.tuner_ops.get_rf_strength(fe, &rxPwr2);
841
842 if (rxPwr1+ANT_EXT_TWEAK >= rxPwr2) {
843 /* return with EXTERNAL enabled */
844 mxl111sf_set_ant_path(state, ANT_PATH_EXTERNAL);
845 DbgAntHunt(ANT_PATH_EXTERNAL, rxPwrA,
846 rxPwr0, rxPwr1, rxPwr2);
847 } else {
848 /* return with INTERNAL enabled */
849 DbgAntHunt(ANT_PATH_INTERNAL, rxPwrA,
850 rxPwr0, rxPwr1, rxPwr2);
851 }
852 }
853 return 0;
854}
855
856static struct mxl111sf_tuner_config mxl_tuner_config = {
857 .if_freq = MXL_IF_6_0, /* applies to external IF output, only */
858 .invert_spectrum = 0,
859 .read_reg = mxl111sf_read_reg,
860 .write_reg = mxl111sf_write_reg,
861 .program_regs = mxl111sf_ctrl_program_regs,
862 .top_master_ctrl = mxl1x1sf_top_master_ctrl,
863 .ant_hunt = mxl111sf_ant_hunt,
864};
865
866static int mxl111sf_attach_tuner(struct dvb_usb_adapter *adap)
867{
Antti Palosaari85722112012-06-26 00:17:04 -0300868 struct mxl111sf_state *state = adap_to_priv(adap);
869 int i;
Michael Krufky4c66c922011-08-29 00:05:35 -0300870
871 deb_adv("%s()\n", __func__);
872
Antti Palosaari85722112012-06-26 00:17:04 -0300873 for (i = 0; i < state->num_frontends; i++) {
874 if (dvb_attach(mxl111sf_tuner_attach, adap->fe[i], state,
875 &mxl_tuner_config) == NULL)
876 return -EIO;
877 }
Michael Krufky4c66c922011-08-29 00:05:35 -0300878
Antti Palosaari85722112012-06-26 00:17:04 -0300879 return 0;
Michael Krufky4c66c922011-08-29 00:05:35 -0300880}
881
882static int mxl111sf_fe_ioctl_override(struct dvb_frontend *fe,
883 unsigned int cmd, void *parg,
884 unsigned int stage)
885{
886 int err = 0;
887
888 switch (stage) {
889 case DVB_FE_IOCTL_PRE:
890
891 switch (cmd) {
892 case FE_READ_SIGNAL_STRENGTH:
893 err = fe->ops.tuner_ops.get_rf_strength(fe, parg);
894 /* If no error occurs, prevent dvb-core from handling
895 * this IOCTL, otherwise return the error */
896 if (0 == err)
897 err = 1;
898 break;
899 }
900 break;
901
902 case DVB_FE_IOCTL_POST:
903 /* no post-ioctl handling required */
904 break;
905 }
906 return err;
907};
908
909static u32 mxl111sf_i2c_func(struct i2c_adapter *adapter)
910{
911 return I2C_FUNC_I2C;
912}
913
914struct i2c_algorithm mxl111sf_i2c_algo = {
915 .master_xfer = mxl111sf_i2c_xfer,
916 .functionality = mxl111sf_i2c_func,
917#ifdef NEED_ALGO_CONTROL
918 .algo_control = dummy_algo_control,
919#endif
920};
921
Antti Palosaari85722112012-06-26 00:17:04 -0300922static int mxl111sf_init(struct dvb_usb_device *d)
Michael Krufky4c66c922011-08-29 00:05:35 -0300923{
Antti Palosaari85722112012-06-26 00:17:04 -0300924 struct mxl111sf_state *state = d_to_priv(d);
925 int ret;
926 static u8 eeprom[256];
927 struct i2c_client c;
Michael Krufky4c66c922011-08-29 00:05:35 -0300928
Antti Palosaari85722112012-06-26 00:17:04 -0300929 ret = get_chip_info(state);
930 if (mxl_fail(ret))
931 err("failed to get chip info during probe");
Michael Krufky4c66c922011-08-29 00:05:35 -0300932
Antti Palosaari85722112012-06-26 00:17:04 -0300933 mutex_init(&state->fe_lock);
Michael Krufky4c66c922011-08-29 00:05:35 -0300934
Antti Palosaari85722112012-06-26 00:17:04 -0300935 if (state->chip_rev > MXL111SF_V6)
936 mxl111sf_config_pin_mux_modes(state, PIN_MUX_TS_SPI_IN_MODE_1);
Michael Krufky4c66c922011-08-29 00:05:35 -0300937
Antti Palosaari85722112012-06-26 00:17:04 -0300938 c.adapter = &d->i2c_adap;
939 c.addr = 0xa0 >> 1;
Michael Krufky4c66c922011-08-29 00:05:35 -0300940
Antti Palosaari85722112012-06-26 00:17:04 -0300941 ret = tveeprom_read(&c, eeprom, sizeof(eeprom));
942 if (mxl_fail(ret))
Michael Krufky4c66c922011-08-29 00:05:35 -0300943 return 0;
Antti Palosaari85722112012-06-26 00:17:04 -0300944 tveeprom_hauppauge_analog(&c, &state->tv, (0x84 == eeprom[0xa0]) ?
945 eeprom + 0xa0 : eeprom + 0x80);
946#if 0
947 switch (state->tv.model) {
948 case 117001:
949 case 126001:
950 case 138001:
951 break;
952 default:
953 printk(KERN_WARNING "%s: warning: "
954 "unknown hauppauge model #%d\n",
955 __func__, state->tv.model);
Michael Krufky4c66c922011-08-29 00:05:35 -0300956 }
Antti Palosaari85722112012-06-26 00:17:04 -0300957#endif
958 return 0;
Michael Krufky4c66c922011-08-29 00:05:35 -0300959}
960
Antti Palosaari85722112012-06-26 00:17:04 -0300961static int mxl111sf_frontend_attach_dvbt(struct dvb_usb_adapter *adap)
962{
963 return mxl111sf_attach_demod(adap, 0);
964}
Michael Krufky4c66c922011-08-29 00:05:35 -0300965
Antti Palosaari85722112012-06-26 00:17:04 -0300966static int mxl111sf_frontend_attach_atsc(struct dvb_usb_adapter *adap)
967{
968 return mxl111sf_lgdt3305_frontend_attach(adap, 0);
969}
Michael Krufky4c66c922011-08-29 00:05:35 -0300970
Antti Palosaari85722112012-06-26 00:17:04 -0300971static int mxl111sf_frontend_attach_mh(struct dvb_usb_adapter *adap)
972{
973 return mxl111sf_lg2160_frontend_attach(adap, 0);
974}
Michael Krufky4f984802011-10-15 23:10:15 +0100975
Antti Palosaari85722112012-06-26 00:17:04 -0300976static int mxl111sf_frontend_attach_atsc_mh(struct dvb_usb_adapter *adap)
977{
978 int ret;
979 deb_info("%s\n", __func__);
Michael Krufky4f984802011-10-15 23:10:15 +0100980
Antti Palosaari85722112012-06-26 00:17:04 -0300981 ret = mxl111sf_lgdt3305_frontend_attach(adap, 0);
982 if (ret < 0)
983 return ret;
Michael Krufky31136212012-01-29 15:53:55 -0300984
Antti Palosaari85722112012-06-26 00:17:04 -0300985 ret = mxl111sf_attach_demod(adap, 1);
986 if (ret < 0)
987 return ret;
Michael Krufky31136212012-01-29 15:53:55 -0300988
Antti Palosaari85722112012-06-26 00:17:04 -0300989 ret = mxl111sf_lg2160_frontend_attach(adap, 2);
990 if (ret < 0)
991 return ret;
Michael Krufky4c66c922011-08-29 00:05:35 -0300992
Antti Palosaari85722112012-06-26 00:17:04 -0300993 return ret;
994}
Michael Krufky4c66c922011-08-29 00:05:35 -0300995
Antti Palosaari85722112012-06-26 00:17:04 -0300996static int mxl111sf_frontend_attach_mercury(struct dvb_usb_adapter *adap)
997{
998 int ret;
999 deb_info("%s\n", __func__);
Michael Krufky4c66c922011-08-29 00:05:35 -03001000
Antti Palosaari85722112012-06-26 00:17:04 -03001001 ret = mxl111sf_lgdt3305_frontend_attach(adap, 0);
1002 if (ret < 0)
1003 return ret;
1004
1005 ret = mxl111sf_attach_demod(adap, 1);
1006 if (ret < 0)
1007 return ret;
1008
1009 ret = mxl111sf_lg2161_ep6_frontend_attach(adap, 2);
1010 if (ret < 0)
1011 return ret;
1012
1013 return ret;
1014}
1015
1016static int mxl111sf_frontend_attach_mercury_mh(struct dvb_usb_adapter *adap)
1017{
1018 int ret;
1019 deb_info("%s\n", __func__);
1020
1021 ret = mxl111sf_attach_demod(adap, 0);
1022 if (ret < 0)
1023 return ret;
1024
1025 if (dvb_usb_mxl111sf_spi)
1026 ret = mxl111sf_lg2161_frontend_attach(adap, 1);
1027 else
1028 ret = mxl111sf_lg2161_ep6_frontend_attach(adap, 1);
1029
1030 return ret;
1031}
1032
1033static void mxl111sf_stream_config_bulk(struct usb_data_stream_properties *stream, u8 endpoint)
1034{
1035 deb_info("%s: endpoint=%d size=8192\n", __func__, endpoint);
1036 stream->type = USB_BULK;
1037 stream->count = 5;
1038 stream->endpoint = endpoint;
1039 stream->u.bulk.buffersize = 8192;
1040}
1041
1042static void mxl111sf_stream_config_isoc(struct usb_data_stream_properties *stream,
1043 u8 endpoint, int framesperurb, int framesize)
1044{
1045 deb_info("%s: endpoint=%d size=%d\n", __func__, endpoint,
1046 framesperurb * framesize);
1047 stream->type = USB_ISOC;
1048 stream->count = 5;
1049 stream->endpoint = endpoint;
1050 stream->u.isoc.framesperurb = framesperurb;
1051 stream->u.isoc.framesize = framesize;
1052 stream->u.isoc.interval = 1;
1053}
1054
1055/* DVB USB Driver stuff */
1056
1057/* dvbt mxl111sf
1058 * bulk EP4/BULK/5/8192
1059 * isoc EP4/ISOC/5/96/564
1060 */
1061static int mxl111sf_get_stream_config_dvbt(struct dvb_frontend *fe,
1062 u8 *ts_type, struct usb_data_stream_properties *stream)
1063{
1064 deb_info("%s: fe=%d\n", __func__, fe->id);
1065
1066 *ts_type = DVB_USB_FE_TS_TYPE_188;
1067 if (dvb_usb_mxl111sf_isoc)
1068 mxl111sf_stream_config_isoc(stream, 4, 96, 564);
1069 else
1070 mxl111sf_stream_config_bulk(stream, 4);
1071 return 0;
1072}
1073
1074static struct dvb_usb_device_properties mxl111sf_props_dvbt = {
1075 .driver_name = KBUILD_MODNAME,
1076 .owner = THIS_MODULE,
1077 .adapter_nr = adapter_nr,
1078 .size_of_priv = sizeof(struct mxl111sf_state),
1079
1080 .generic_bulk_ctrl_endpoint = 0x02,
1081 .generic_bulk_ctrl_endpoint_response = 0x81,
1082
1083 .i2c_algo = &mxl111sf_i2c_algo,
1084 .frontend_attach = mxl111sf_frontend_attach_dvbt,
1085 .tuner_attach = mxl111sf_attach_tuner,
1086 .init = mxl111sf_init,
1087 .streaming_ctrl = mxl111sf_ep4_streaming_ctrl,
1088 .get_stream_config = mxl111sf_get_stream_config_dvbt,
1089 .fe_ioctl_override = mxl111sf_fe_ioctl_override,
Michael Krufky4c66c922011-08-29 00:05:35 -03001090
1091 .num_adapters = 1,
1092 .adapter = {
1093 {
Antti Palosaari85722112012-06-26 00:17:04 -03001094 .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
1095 }
Michael Krufky4f984802011-10-15 23:10:15 +01001096 }
1097};
1098
Antti Palosaari85722112012-06-26 00:17:04 -03001099/* atsc lgdt3305
1100 * bulk EP6/BULK/5/8192
1101 * isoc EP6/ISOC/5/24/3072
1102 */
1103static int mxl111sf_get_stream_config_atsc(struct dvb_frontend *fe,
1104 u8 *ts_type, struct usb_data_stream_properties *stream)
1105{
1106 deb_info("%s: fe=%d\n", __func__, fe->id);
1107
1108 *ts_type = DVB_USB_FE_TS_TYPE_188;
1109 if (dvb_usb_mxl111sf_isoc)
1110 mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
1111 else
1112 mxl111sf_stream_config_bulk(stream, 6);
1113 return 0;
1114}
1115
1116static struct dvb_usb_device_properties mxl111sf_props_atsc = {
1117 .driver_name = KBUILD_MODNAME,
1118 .owner = THIS_MODULE,
1119 .adapter_nr = adapter_nr,
1120 .size_of_priv = sizeof(struct mxl111sf_state),
1121
1122 .generic_bulk_ctrl_endpoint = 0x02,
1123 .generic_bulk_ctrl_endpoint_response = 0x81,
1124
1125 .i2c_algo = &mxl111sf_i2c_algo,
1126 .frontend_attach = mxl111sf_frontend_attach_atsc,
1127 .tuner_attach = mxl111sf_attach_tuner,
1128 .init = mxl111sf_init,
1129 .streaming_ctrl = mxl111sf_ep6_streaming_ctrl,
1130 .get_stream_config = mxl111sf_get_stream_config_atsc,
1131 .fe_ioctl_override = mxl111sf_fe_ioctl_override,
Michael Krufky4f984802011-10-15 23:10:15 +01001132
1133 .num_adapters = 1,
1134 .adapter = {
1135 {
Antti Palosaari85722112012-06-26 00:17:04 -03001136 .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
1137 }
Michael Krufky4f984802011-10-15 23:10:15 +01001138 }
1139};
1140
Antti Palosaari85722112012-06-26 00:17:04 -03001141/* mh lg2160
1142 * bulk EP5/BULK/5/8192/RAW
1143 * isoc EP5/ISOC/5/96/200/RAW
1144 */
1145static int mxl111sf_get_stream_config_mh(struct dvb_frontend *fe,
1146 u8 *ts_type, struct usb_data_stream_properties *stream)
1147{
1148 deb_info("%s: fe=%d\n", __func__, fe->id);
1149
1150 *ts_type = DVB_USB_FE_TS_TYPE_RAW;
1151 if (dvb_usb_mxl111sf_isoc)
1152 mxl111sf_stream_config_isoc(stream, 5, 96, 200);
1153 else
1154 mxl111sf_stream_config_bulk(stream, 5);
1155 return 0;
1156}
1157
1158static struct dvb_usb_device_properties mxl111sf_props_mh = {
1159 .driver_name = KBUILD_MODNAME,
1160 .owner = THIS_MODULE,
1161 .adapter_nr = adapter_nr,
1162 .size_of_priv = sizeof(struct mxl111sf_state),
1163
1164 .generic_bulk_ctrl_endpoint = 0x02,
1165 .generic_bulk_ctrl_endpoint_response = 0x81,
1166
1167 .i2c_algo = &mxl111sf_i2c_algo,
1168 .frontend_attach = mxl111sf_frontend_attach_mh,
1169 .tuner_attach = mxl111sf_attach_tuner,
1170 .init = mxl111sf_init,
1171 .streaming_ctrl = mxl111sf_ep5_streaming_ctrl,
1172 .get_stream_config = mxl111sf_get_stream_config_mh,
1173 .fe_ioctl_override = mxl111sf_fe_ioctl_override,
Michael Krufky4f984802011-10-15 23:10:15 +01001174
1175 .num_adapters = 1,
1176 .adapter = {
1177 {
Antti Palosaari85722112012-06-26 00:17:04 -03001178 .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
1179 }
Michael Krufky31136212012-01-29 15:53:55 -03001180 }
1181};
1182
Antti Palosaari85722112012-06-26 00:17:04 -03001183/* atsc mh lgdt3305 mxl111sf lg2160
1184 * bulk EP6/BULK/5/8192 EP4/BULK/5/8192 EP5/BULK/5/8192/RAW
1185 * isoc EP6/ISOC/5/24/3072 EP4/ISOC/5/96/564 EP5/ISOC/5/96/200/RAW
1186 */
1187static int mxl111sf_get_stream_config_atsc_mh(struct dvb_frontend *fe,
1188 u8 *ts_type, struct usb_data_stream_properties *stream)
1189{
1190 deb_info("%s: fe=%d\n", __func__, fe->id);
1191
1192 if (fe->id == 0) {
1193 *ts_type = DVB_USB_FE_TS_TYPE_188;
1194 if (dvb_usb_mxl111sf_isoc)
1195 mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
1196 else
1197 mxl111sf_stream_config_bulk(stream, 6);
1198 } else if (fe->id == 1) {
1199 *ts_type = DVB_USB_FE_TS_TYPE_188;
1200 if (dvb_usb_mxl111sf_isoc)
1201 mxl111sf_stream_config_isoc(stream, 4, 96, 564);
1202 else
1203 mxl111sf_stream_config_bulk(stream, 4);
1204 } else if (fe->id == 2) {
1205 *ts_type = DVB_USB_FE_TS_TYPE_RAW;
1206 if (dvb_usb_mxl111sf_isoc)
1207 mxl111sf_stream_config_isoc(stream, 5, 96, 200);
1208 else
1209 mxl111sf_stream_config_bulk(stream, 5);
1210 }
1211 return 0;
1212}
1213
1214static int mxl111sf_streaming_ctrl_atsc_mh(struct dvb_frontend *fe, int onoff)
1215{
1216 deb_info("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
1217
1218 if (fe->id == 0)
1219 return mxl111sf_ep6_streaming_ctrl(fe, onoff);
1220 else if (fe->id == 1)
1221 return mxl111sf_ep4_streaming_ctrl(fe, onoff);
1222 else if (fe->id == 2)
1223 return mxl111sf_ep5_streaming_ctrl(fe, onoff);
1224 return 0;
1225}
1226
1227static struct dvb_usb_device_properties mxl111sf_props_atsc_mh = {
1228 .driver_name = KBUILD_MODNAME,
1229 .owner = THIS_MODULE,
1230 .adapter_nr = adapter_nr,
1231 .size_of_priv = sizeof(struct mxl111sf_state),
1232
1233 .generic_bulk_ctrl_endpoint = 0x02,
1234 .generic_bulk_ctrl_endpoint_response = 0x81,
1235
1236 .i2c_algo = &mxl111sf_i2c_algo,
1237 .frontend_attach = mxl111sf_frontend_attach_atsc_mh,
1238 .tuner_attach = mxl111sf_attach_tuner,
1239 .init = mxl111sf_init,
1240 .streaming_ctrl = mxl111sf_streaming_ctrl_atsc_mh,
1241 .get_stream_config = mxl111sf_get_stream_config_atsc_mh,
1242 .fe_ioctl_override = mxl111sf_fe_ioctl_override,
Michael Krufky31136212012-01-29 15:53:55 -03001243
1244 .num_adapters = 1,
1245 .adapter = {
1246 {
Antti Palosaari85722112012-06-26 00:17:04 -03001247 .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
1248 }
Michael Krufky31136212012-01-29 15:53:55 -03001249 }
1250};
1251
Antti Palosaari85722112012-06-26 00:17:04 -03001252/* mercury lgdt3305 mxl111sf lg2161
1253 * tp bulk EP6/BULK/5/8192 EP4/BULK/5/8192 EP6/BULK/5/8192/RAW
1254 * tp isoc EP6/ISOC/5/24/3072 EP4/ISOC/5/96/564 EP6/ISOC/5/24/3072/RAW
1255 * spi bulk EP6/BULK/5/8192 EP4/BULK/5/8192 EP5/BULK/5/8192/RAW
1256 * spi isoc EP6/ISOC/5/24/3072 EP4/ISOC/5/96/564 EP5/ISOC/5/96/200/RAW
1257 */
1258static int mxl111sf_get_stream_config_mercury(struct dvb_frontend *fe,
1259 u8 *ts_type, struct usb_data_stream_properties *stream)
1260{
1261 deb_info("%s: fe=%d\n", __func__, fe->id);
1262
1263 if (fe->id == 0) {
1264 *ts_type = DVB_USB_FE_TS_TYPE_188;
1265 if (dvb_usb_mxl111sf_isoc)
1266 mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
1267 else
1268 mxl111sf_stream_config_bulk(stream, 6);
1269 } else if (fe->id == 1) {
1270 *ts_type = DVB_USB_FE_TS_TYPE_188;
1271 if (dvb_usb_mxl111sf_isoc)
1272 mxl111sf_stream_config_isoc(stream, 4, 96, 564);
1273 else
1274 mxl111sf_stream_config_bulk(stream, 4);
1275 } else if (fe->id == 2 && dvb_usb_mxl111sf_spi) {
1276 *ts_type = DVB_USB_FE_TS_TYPE_RAW;
1277 if (dvb_usb_mxl111sf_isoc)
1278 mxl111sf_stream_config_isoc(stream, 5, 96, 200);
1279 else
1280 mxl111sf_stream_config_bulk(stream, 5);
1281 } else if (fe->id == 2 && !dvb_usb_mxl111sf_spi) {
1282 *ts_type = DVB_USB_FE_TS_TYPE_RAW;
1283 if (dvb_usb_mxl111sf_isoc)
1284 mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
1285 else
1286 mxl111sf_stream_config_bulk(stream, 6);
1287 }
1288 return 0;
1289}
1290
1291static int mxl111sf_streaming_ctrl_mercury(struct dvb_frontend *fe, int onoff)
1292{
1293 deb_info("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
1294
1295 if (fe->id == 0)
1296 return mxl111sf_ep6_streaming_ctrl(fe, onoff);
1297 else if (fe->id == 1)
1298 return mxl111sf_ep4_streaming_ctrl(fe, onoff);
1299 else if (fe->id == 2 && dvb_usb_mxl111sf_spi)
1300 return mxl111sf_ep5_streaming_ctrl(fe, onoff);
1301 else if (fe->id == 2 && !dvb_usb_mxl111sf_spi)
1302 return mxl111sf_ep6_streaming_ctrl(fe, onoff);
1303 return 0;
1304}
1305
1306static struct dvb_usb_device_properties mxl111sf_props_mercury = {
1307 .driver_name = KBUILD_MODNAME,
1308 .owner = THIS_MODULE,
1309 .adapter_nr = adapter_nr,
1310 .size_of_priv = sizeof(struct mxl111sf_state),
1311
1312 .generic_bulk_ctrl_endpoint = 0x02,
1313 .generic_bulk_ctrl_endpoint_response = 0x81,
1314
1315 .i2c_algo = &mxl111sf_i2c_algo,
1316 .frontend_attach = mxl111sf_frontend_attach_mercury,
1317 .tuner_attach = mxl111sf_attach_tuner,
1318 .init = mxl111sf_init,
1319 .streaming_ctrl = mxl111sf_streaming_ctrl_mercury,
1320 .get_stream_config = mxl111sf_get_stream_config_mercury,
1321 .fe_ioctl_override = mxl111sf_fe_ioctl_override,
Michael Krufky31136212012-01-29 15:53:55 -03001322
1323 .num_adapters = 1,
1324 .adapter = {
1325 {
Antti Palosaari85722112012-06-26 00:17:04 -03001326 .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
1327 }
Michael Krufky31136212012-01-29 15:53:55 -03001328 }
1329};
1330
Antti Palosaari85722112012-06-26 00:17:04 -03001331/* mercury mh mxl111sf lg2161
1332 * tp bulk EP4/BULK/5/8192 EP6/BULK/5/8192/RAW
1333 * tp isoc EP4/ISOC/5/96/564 EP6/ISOC/5/24/3072/RAW
1334 * spi bulk EP4/BULK/5/8192 EP5/BULK/5/8192/RAW
1335 * spi isoc EP4/ISOC/5/96/564 EP5/ISOC/5/96/200/RAW
1336 */
1337static int mxl111sf_get_stream_config_mercury_mh(struct dvb_frontend *fe,
1338 u8 *ts_type, struct usb_data_stream_properties *stream)
1339{
1340 deb_info("%s: fe=%d\n", __func__, fe->id);
1341
1342 if (fe->id == 0) {
1343 *ts_type = DVB_USB_FE_TS_TYPE_188;
1344 if (dvb_usb_mxl111sf_isoc)
1345 mxl111sf_stream_config_isoc(stream, 4, 96, 564);
1346 else
1347 mxl111sf_stream_config_bulk(stream, 4);
1348 } else if (fe->id == 1 && dvb_usb_mxl111sf_spi) {
1349 *ts_type = DVB_USB_FE_TS_TYPE_RAW;
1350 if (dvb_usb_mxl111sf_isoc)
1351 mxl111sf_stream_config_isoc(stream, 5, 96, 200);
1352 else
1353 mxl111sf_stream_config_bulk(stream, 5);
1354 } else if (fe->id == 1 && !dvb_usb_mxl111sf_spi) {
1355 *ts_type = DVB_USB_FE_TS_TYPE_RAW;
1356 if (dvb_usb_mxl111sf_isoc)
1357 mxl111sf_stream_config_isoc(stream, 6, 24, 3072);
1358 else
1359 mxl111sf_stream_config_bulk(stream, 6);
1360 }
1361 return 0;
1362}
1363
1364static int mxl111sf_streaming_ctrl_mercury_mh(struct dvb_frontend *fe, int onoff)
1365{
1366 deb_info("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
1367
1368 if (fe->id == 0)
1369 return mxl111sf_ep4_streaming_ctrl(fe, onoff);
1370 else if (fe->id == 1 && dvb_usb_mxl111sf_spi)
1371 return mxl111sf_ep5_streaming_ctrl(fe, onoff);
1372 else if (fe->id == 1 && !dvb_usb_mxl111sf_spi)
1373 return mxl111sf_ep6_streaming_ctrl(fe, onoff);
1374 return 0;
1375}
1376
1377static struct dvb_usb_device_properties mxl111sf_props_mercury_mh = {
1378 .driver_name = KBUILD_MODNAME,
1379 .owner = THIS_MODULE,
1380 .adapter_nr = adapter_nr,
1381 .size_of_priv = sizeof(struct mxl111sf_state),
1382
1383 .generic_bulk_ctrl_endpoint = 0x02,
1384 .generic_bulk_ctrl_endpoint_response = 0x81,
1385
1386 .i2c_algo = &mxl111sf_i2c_algo,
1387 .frontend_attach = mxl111sf_frontend_attach_mercury_mh,
1388 .tuner_attach = mxl111sf_attach_tuner,
1389 .init = mxl111sf_init,
1390 .streaming_ctrl = mxl111sf_streaming_ctrl_mercury_mh,
1391 .get_stream_config = mxl111sf_get_stream_config_mercury_mh,
1392 .fe_ioctl_override = mxl111sf_fe_ioctl_override,
Michael Krufky31136212012-01-29 15:53:55 -03001393
1394 .num_adapters = 1,
1395 .adapter = {
1396 {
Antti Palosaari85722112012-06-26 00:17:04 -03001397 .stream = DVB_USB_STREAM_ISOC(6, 5, 24, 3072, 1),
1398 }
Michael Krufky31136212012-01-29 15:53:55 -03001399 }
1400};
1401
Antti Palosaari85722112012-06-26 00:17:04 -03001402static const struct usb_device_id mxl111sf_id_table[] = {
1403 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc600, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
1404 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc601, &mxl111sf_props_atsc, "Hauppauge 126xxx ATSC", NULL) },
1405 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc602, &mxl111sf_props_mh, "HCW 126xxx", NULL) },
1406 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc603, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
1407 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc604, &mxl111sf_props_dvbt, "Hauppauge 126xxx DVBT", NULL) },
1408 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc609, &mxl111sf_props_atsc, "Hauppauge 126xxx ATSC", NULL) },
1409 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc60a, &mxl111sf_props_mh, "HCW 126xxx", NULL) },
1410 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc60b, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
1411 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc60c, &mxl111sf_props_dvbt, "Hauppauge 126xxx DVBT", NULL) },
1412 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc653, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
1413 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc65b, &mxl111sf_props_atsc_mh, "Hauppauge 126xxx ATSC+", NULL) },
1414 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb700, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
1415 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb701, &mxl111sf_props_atsc, "Hauppauge 126xxx ATSC", NULL) },
1416 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb702, &mxl111sf_props_mh, "HCW 117xxx", NULL) },
1417 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb703, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
1418 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb704, &mxl111sf_props_dvbt, "Hauppauge 117xxx DVBT", NULL) },
1419 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb753, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
1420 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb763, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
1421 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb764, &mxl111sf_props_dvbt, "Hauppauge 117xxx DVBT", NULL) },
1422 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd853, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
1423 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd854, &mxl111sf_props_dvbt, "Hauppauge 138xxx DVBT", NULL) },
1424 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd863, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
1425 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd864, &mxl111sf_props_dvbt, "Hauppauge 138xxx DVBT", NULL) },
1426 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8d3, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
1427 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8d4, &mxl111sf_props_dvbt, "Hauppauge 138xxx DVBT", NULL) },
1428 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8e3, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
1429 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8e4, &mxl111sf_props_dvbt, "Hauppauge 138xxx DVBT", NULL) },
1430 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xd8ff, &mxl111sf_props_mercury, "Hauppauge Mercury", NULL) },
1431 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc612, &mxl111sf_props_mercury_mh, "Hauppauge 126xxx", NULL) },
1432 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc613, &mxl111sf_props_mercury, "Hauppauge WinTV-Aero-M", NULL) },
1433 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc61a, &mxl111sf_props_mercury_mh, "Hauppauge 126xxx", NULL) },
1434 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xc61b, &mxl111sf_props_mercury, "Hauppauge WinTV-Aero-M", NULL) },
1435 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb757, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
1436 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xb767, &mxl111sf_props_atsc_mh, "Hauppauge 117xxx ATSC+", NULL) },
1437 { }
1438};
1439MODULE_DEVICE_TABLE(usb, mxl111sf_id_table);
Michael Krufky31136212012-01-29 15:53:55 -03001440
Antti Palosaari85722112012-06-26 00:17:04 -03001441static struct usb_driver mxl111sf_usb_driver = {
1442 .name = KBUILD_MODNAME,
1443 .id_table = mxl111sf_id_table,
1444 .probe = dvb_usbv2_probe,
1445 .disconnect = dvb_usbv2_disconnect,
1446 .suspend = dvb_usbv2_suspend,
1447 .resume = dvb_usbv2_resume,
1448 .no_dynamic_id = 1,
1449 .soft_unbind = 1,
Michael Krufky31136212012-01-29 15:53:55 -03001450};
1451
Antti Palosaari85722112012-06-26 00:17:04 -03001452module_usb_driver(mxl111sf_usb_driver);
Michael Krufky4c66c922011-08-29 00:05:35 -03001453
1454MODULE_AUTHOR("Michael Krufky <mkrufky@kernellabs.com>");
1455MODULE_DESCRIPTION("Driver for MaxLinear MxL111SF");
1456MODULE_VERSION("1.0");
1457MODULE_LICENSE("GPL");
1458
1459/*
1460 * Local variables:
1461 * c-basic-offset: 8
1462 * End:
1463 */