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