1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun //
3*4882a593Smuzhiyun // DVB device driver for em28xx
4*4882a593Smuzhiyun //
5*4882a593Smuzhiyun // (c) 2008-2011 Mauro Carvalho Chehab <mchehab@kernel.org>
6*4882a593Smuzhiyun //
7*4882a593Smuzhiyun // (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
8*4882a593Smuzhiyun // - Fixes for the driver to properly work with HVR-950
9*4882a593Smuzhiyun // - Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick
10*4882a593Smuzhiyun // - Fixes for the driver to properly work with AMD ATI TV Wonder HD 600
11*4882a593Smuzhiyun //
12*4882a593Smuzhiyun // (c) 2008 Aidan Thornton <makosoft@googlemail.com>
13*4882a593Smuzhiyun //
14*4882a593Smuzhiyun // (c) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
15*4882a593Smuzhiyun //
16*4882a593Smuzhiyun // Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
17*4882a593Smuzhiyun // (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
18*4882a593Smuzhiyun // (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
19*4882a593Smuzhiyun //
20*4882a593Smuzhiyun // This program is free software; you can redistribute it and/or modify
21*4882a593Smuzhiyun // it under the terms of the GNU General Public License as published by
22*4882a593Smuzhiyun // the Free Software Foundation version 2 of the License.
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #include "em28xx.h"
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun #include <linux/kernel.h>
27*4882a593Smuzhiyun #include <linux/slab.h>
28*4882a593Smuzhiyun #include <linux/usb.h>
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #include <media/v4l2-common.h>
31*4882a593Smuzhiyun #include <media/dvb_demux.h>
32*4882a593Smuzhiyun #include <media/dvb_net.h>
33*4882a593Smuzhiyun #include <media/dmxdev.h>
34*4882a593Smuzhiyun #include <media/tuner.h>
35*4882a593Smuzhiyun #include "tuner-simple.h"
36*4882a593Smuzhiyun #include <linux/gpio.h>
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun #include "lgdt330x.h"
39*4882a593Smuzhiyun #include "lgdt3305.h"
40*4882a593Smuzhiyun #include "lgdt3306a.h"
41*4882a593Smuzhiyun #include "zl10353.h"
42*4882a593Smuzhiyun #include "s5h1409.h"
43*4882a593Smuzhiyun #include "mt2060.h"
44*4882a593Smuzhiyun #include "mt352.h"
45*4882a593Smuzhiyun #include "mt352_priv.h" /* FIXME */
46*4882a593Smuzhiyun #include "tda1002x.h"
47*4882a593Smuzhiyun #include "drx39xyj/drx39xxj.h"
48*4882a593Smuzhiyun #include "tda18271.h"
49*4882a593Smuzhiyun #include "s921.h"
50*4882a593Smuzhiyun #include "drxd.h"
51*4882a593Smuzhiyun #include "cxd2820r.h"
52*4882a593Smuzhiyun #include "tda18271c2dd.h"
53*4882a593Smuzhiyun #include "drxk.h"
54*4882a593Smuzhiyun #include "tda10071.h"
55*4882a593Smuzhiyun #include "tda18212.h"
56*4882a593Smuzhiyun #include "a8293.h"
57*4882a593Smuzhiyun #include "qt1010.h"
58*4882a593Smuzhiyun #include "mb86a20s.h"
59*4882a593Smuzhiyun #include "m88ds3103.h"
60*4882a593Smuzhiyun #include "ts2020.h"
61*4882a593Smuzhiyun #include "si2168.h"
62*4882a593Smuzhiyun #include "si2157.h"
63*4882a593Smuzhiyun #include "tc90522.h"
64*4882a593Smuzhiyun #include "qm1d1c0042.h"
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@kernel.org>");
67*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
68*4882a593Smuzhiyun MODULE_DESCRIPTION(DRIVER_DESC " - digital TV interface");
69*4882a593Smuzhiyun MODULE_VERSION(EM28XX_VERSION);
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun static unsigned int debug;
72*4882a593Smuzhiyun module_param(debug, int, 0644);
73*4882a593Smuzhiyun MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun #define dprintk(level, fmt, arg...) do { \
78*4882a593Smuzhiyun if (debug >= level) \
79*4882a593Smuzhiyun dev_printk(KERN_DEBUG, &dev->intf->dev, \
80*4882a593Smuzhiyun "dvb: " fmt, ## arg); \
81*4882a593Smuzhiyun } while (0)
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun struct em28xx_dvb {
84*4882a593Smuzhiyun struct dvb_frontend *fe[2];
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun /* feed count management */
87*4882a593Smuzhiyun struct mutex lock;
88*4882a593Smuzhiyun int nfeeds;
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun /* general boilerplate stuff */
91*4882a593Smuzhiyun struct dvb_adapter adapter;
92*4882a593Smuzhiyun struct dvb_demux demux;
93*4882a593Smuzhiyun struct dmxdev dmxdev;
94*4882a593Smuzhiyun struct dmx_frontend fe_hw;
95*4882a593Smuzhiyun struct dmx_frontend fe_mem;
96*4882a593Smuzhiyun struct dvb_net net;
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun /* Due to DRX-K - probably need changes */
99*4882a593Smuzhiyun int (*gate_ctrl)(struct dvb_frontend *fe, int gate);
100*4882a593Smuzhiyun struct semaphore pll_mutex;
101*4882a593Smuzhiyun bool dont_attach_fe1;
102*4882a593Smuzhiyun int lna_gpio;
103*4882a593Smuzhiyun struct i2c_client *i2c_client_demod;
104*4882a593Smuzhiyun struct i2c_client *i2c_client_tuner;
105*4882a593Smuzhiyun struct i2c_client *i2c_client_sec;
106*4882a593Smuzhiyun };
107*4882a593Smuzhiyun
print_err_status(struct em28xx * dev,int packet,int status)108*4882a593Smuzhiyun static inline void print_err_status(struct em28xx *dev,
109*4882a593Smuzhiyun int packet, int status)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun char *errmsg = "Unknown";
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun switch (status) {
114*4882a593Smuzhiyun case -ENOENT:
115*4882a593Smuzhiyun errmsg = "unlinked synchronously";
116*4882a593Smuzhiyun break;
117*4882a593Smuzhiyun case -ECONNRESET:
118*4882a593Smuzhiyun errmsg = "unlinked asynchronously";
119*4882a593Smuzhiyun break;
120*4882a593Smuzhiyun case -ENOSR:
121*4882a593Smuzhiyun errmsg = "Buffer error (overrun)";
122*4882a593Smuzhiyun break;
123*4882a593Smuzhiyun case -EPIPE:
124*4882a593Smuzhiyun errmsg = "Stalled (device not responding)";
125*4882a593Smuzhiyun break;
126*4882a593Smuzhiyun case -EOVERFLOW:
127*4882a593Smuzhiyun errmsg = "Babble (bad cable?)";
128*4882a593Smuzhiyun break;
129*4882a593Smuzhiyun case -EPROTO:
130*4882a593Smuzhiyun errmsg = "Bit-stuff error (bad cable?)";
131*4882a593Smuzhiyun break;
132*4882a593Smuzhiyun case -EILSEQ:
133*4882a593Smuzhiyun errmsg = "CRC/Timeout (could be anything)";
134*4882a593Smuzhiyun break;
135*4882a593Smuzhiyun case -ETIME:
136*4882a593Smuzhiyun errmsg = "Device does not respond";
137*4882a593Smuzhiyun break;
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun if (packet < 0) {
140*4882a593Smuzhiyun dprintk(1, "URB status %d [%s].\n", status, errmsg);
141*4882a593Smuzhiyun } else {
142*4882a593Smuzhiyun dprintk(1, "URB packet %d, status %d [%s].\n",
143*4882a593Smuzhiyun packet, status, errmsg);
144*4882a593Smuzhiyun }
145*4882a593Smuzhiyun }
146*4882a593Smuzhiyun
em28xx_dvb_urb_data_copy(struct em28xx * dev,struct urb * urb)147*4882a593Smuzhiyun static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
148*4882a593Smuzhiyun {
149*4882a593Smuzhiyun int xfer_bulk, num_packets, i;
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun if (!dev)
152*4882a593Smuzhiyun return 0;
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun if (dev->disconnected)
155*4882a593Smuzhiyun return 0;
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun if (urb->status < 0)
158*4882a593Smuzhiyun print_err_status(dev, -1, urb->status);
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun xfer_bulk = usb_pipebulk(urb->pipe);
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun if (xfer_bulk) /* bulk */
163*4882a593Smuzhiyun num_packets = 1;
164*4882a593Smuzhiyun else /* isoc */
165*4882a593Smuzhiyun num_packets = urb->number_of_packets;
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun for (i = 0; i < num_packets; i++) {
168*4882a593Smuzhiyun if (xfer_bulk) {
169*4882a593Smuzhiyun if (urb->status < 0) {
170*4882a593Smuzhiyun print_err_status(dev, i, urb->status);
171*4882a593Smuzhiyun if (urb->status != -EPROTO)
172*4882a593Smuzhiyun continue;
173*4882a593Smuzhiyun }
174*4882a593Smuzhiyun if (!urb->actual_length)
175*4882a593Smuzhiyun continue;
176*4882a593Smuzhiyun dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
177*4882a593Smuzhiyun urb->actual_length);
178*4882a593Smuzhiyun } else {
179*4882a593Smuzhiyun if (urb->iso_frame_desc[i].status < 0) {
180*4882a593Smuzhiyun print_err_status(dev, i,
181*4882a593Smuzhiyun urb->iso_frame_desc[i].status);
182*4882a593Smuzhiyun if (urb->iso_frame_desc[i].status != -EPROTO)
183*4882a593Smuzhiyun continue;
184*4882a593Smuzhiyun }
185*4882a593Smuzhiyun if (!urb->iso_frame_desc[i].actual_length)
186*4882a593Smuzhiyun continue;
187*4882a593Smuzhiyun dvb_dmx_swfilter(&dev->dvb->demux,
188*4882a593Smuzhiyun urb->transfer_buffer +
189*4882a593Smuzhiyun urb->iso_frame_desc[i].offset,
190*4882a593Smuzhiyun urb->iso_frame_desc[i].actual_length);
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun }
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun return 0;
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun
em28xx_start_streaming(struct em28xx_dvb * dvb)197*4882a593Smuzhiyun static int em28xx_start_streaming(struct em28xx_dvb *dvb)
198*4882a593Smuzhiyun {
199*4882a593Smuzhiyun int rc;
200*4882a593Smuzhiyun struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
201*4882a593Smuzhiyun struct em28xx *dev = i2c_bus->dev;
202*4882a593Smuzhiyun struct usb_device *udev = interface_to_usbdev(dev->intf);
203*4882a593Smuzhiyun int dvb_max_packet_size, packet_multiplier, dvb_alt;
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun if (dev->dvb_xfer_bulk) {
206*4882a593Smuzhiyun if (!dev->dvb_ep_bulk)
207*4882a593Smuzhiyun return -ENODEV;
208*4882a593Smuzhiyun dvb_max_packet_size = 512; /* USB 2.0 spec */
209*4882a593Smuzhiyun packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
210*4882a593Smuzhiyun dvb_alt = 0;
211*4882a593Smuzhiyun } else { /* isoc */
212*4882a593Smuzhiyun if (!dev->dvb_ep_isoc)
213*4882a593Smuzhiyun return -ENODEV;
214*4882a593Smuzhiyun dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
215*4882a593Smuzhiyun if (dvb_max_packet_size < 0)
216*4882a593Smuzhiyun return dvb_max_packet_size;
217*4882a593Smuzhiyun packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
218*4882a593Smuzhiyun dvb_alt = dev->dvb_alt_isoc;
219*4882a593Smuzhiyun }
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun if (!dev->board.has_dual_ts)
222*4882a593Smuzhiyun usb_set_interface(udev, dev->ifnum, dvb_alt);
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
225*4882a593Smuzhiyun if (rc < 0)
226*4882a593Smuzhiyun return rc;
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun dprintk(1, "Using %d buffers each with %d x %d bytes, alternate %d\n",
229*4882a593Smuzhiyun EM28XX_DVB_NUM_BUFS,
230*4882a593Smuzhiyun packet_multiplier,
231*4882a593Smuzhiyun dvb_max_packet_size, dvb_alt);
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
234*4882a593Smuzhiyun dev->dvb_xfer_bulk,
235*4882a593Smuzhiyun EM28XX_DVB_NUM_BUFS,
236*4882a593Smuzhiyun dvb_max_packet_size,
237*4882a593Smuzhiyun packet_multiplier,
238*4882a593Smuzhiyun em28xx_dvb_urb_data_copy);
239*4882a593Smuzhiyun }
240*4882a593Smuzhiyun
em28xx_stop_streaming(struct em28xx_dvb * dvb)241*4882a593Smuzhiyun static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
242*4882a593Smuzhiyun {
243*4882a593Smuzhiyun struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
244*4882a593Smuzhiyun struct em28xx *dev = i2c_bus->dev;
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun em28xx_stop_urbs(dev);
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun return 0;
249*4882a593Smuzhiyun }
250*4882a593Smuzhiyun
em28xx_start_feed(struct dvb_demux_feed * feed)251*4882a593Smuzhiyun static int em28xx_start_feed(struct dvb_demux_feed *feed)
252*4882a593Smuzhiyun {
253*4882a593Smuzhiyun struct dvb_demux *demux = feed->demux;
254*4882a593Smuzhiyun struct em28xx_dvb *dvb = demux->priv;
255*4882a593Smuzhiyun int rc, ret;
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun if (!demux->dmx.frontend)
258*4882a593Smuzhiyun return -EINVAL;
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun mutex_lock(&dvb->lock);
261*4882a593Smuzhiyun dvb->nfeeds++;
262*4882a593Smuzhiyun rc = dvb->nfeeds;
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun if (dvb->nfeeds == 1) {
265*4882a593Smuzhiyun ret = em28xx_start_streaming(dvb);
266*4882a593Smuzhiyun if (ret < 0)
267*4882a593Smuzhiyun rc = ret;
268*4882a593Smuzhiyun }
269*4882a593Smuzhiyun
270*4882a593Smuzhiyun mutex_unlock(&dvb->lock);
271*4882a593Smuzhiyun return rc;
272*4882a593Smuzhiyun }
273*4882a593Smuzhiyun
em28xx_stop_feed(struct dvb_demux_feed * feed)274*4882a593Smuzhiyun static int em28xx_stop_feed(struct dvb_demux_feed *feed)
275*4882a593Smuzhiyun {
276*4882a593Smuzhiyun struct dvb_demux *demux = feed->demux;
277*4882a593Smuzhiyun struct em28xx_dvb *dvb = demux->priv;
278*4882a593Smuzhiyun int err = 0;
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun mutex_lock(&dvb->lock);
281*4882a593Smuzhiyun dvb->nfeeds--;
282*4882a593Smuzhiyun
283*4882a593Smuzhiyun if (!dvb->nfeeds)
284*4882a593Smuzhiyun err = em28xx_stop_streaming(dvb);
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun mutex_unlock(&dvb->lock);
287*4882a593Smuzhiyun return err;
288*4882a593Smuzhiyun }
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun /* ------------------------------------------------------------------ */
em28xx_dvb_bus_ctrl(struct dvb_frontend * fe,int acquire)291*4882a593Smuzhiyun static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
292*4882a593Smuzhiyun {
293*4882a593Smuzhiyun struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
294*4882a593Smuzhiyun struct em28xx *dev = i2c_bus->dev;
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun if (acquire)
297*4882a593Smuzhiyun return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
298*4882a593Smuzhiyun else
299*4882a593Smuzhiyun return em28xx_set_mode(dev, EM28XX_SUSPEND);
300*4882a593Smuzhiyun }
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun /* ------------------------------------------------------------------ */
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun static struct lgdt330x_config em2880_lgdt3303_dev = {
305*4882a593Smuzhiyun .demod_chip = LGDT3303,
306*4882a593Smuzhiyun };
307*4882a593Smuzhiyun
308*4882a593Smuzhiyun static struct lgdt3305_config em2870_lgdt3304_dev = {
309*4882a593Smuzhiyun .i2c_addr = 0x0e,
310*4882a593Smuzhiyun .demod_chip = LGDT3304,
311*4882a593Smuzhiyun .spectral_inversion = 1,
312*4882a593Smuzhiyun .deny_i2c_rptr = 1,
313*4882a593Smuzhiyun .mpeg_mode = LGDT3305_MPEG_PARALLEL,
314*4882a593Smuzhiyun .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
315*4882a593Smuzhiyun .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
316*4882a593Smuzhiyun .vsb_if_khz = 3250,
317*4882a593Smuzhiyun .qam_if_khz = 4000,
318*4882a593Smuzhiyun };
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun static struct lgdt3305_config em2874_lgdt3305_dev = {
321*4882a593Smuzhiyun .i2c_addr = 0x0e,
322*4882a593Smuzhiyun .demod_chip = LGDT3305,
323*4882a593Smuzhiyun .spectral_inversion = 1,
324*4882a593Smuzhiyun .deny_i2c_rptr = 0,
325*4882a593Smuzhiyun .mpeg_mode = LGDT3305_MPEG_SERIAL,
326*4882a593Smuzhiyun .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
327*4882a593Smuzhiyun .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
328*4882a593Smuzhiyun .vsb_if_khz = 3250,
329*4882a593Smuzhiyun .qam_if_khz = 4000,
330*4882a593Smuzhiyun };
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun static struct lgdt3305_config em2874_lgdt3305_nogate_dev = {
333*4882a593Smuzhiyun .i2c_addr = 0x0e,
334*4882a593Smuzhiyun .demod_chip = LGDT3305,
335*4882a593Smuzhiyun .spectral_inversion = 1,
336*4882a593Smuzhiyun .deny_i2c_rptr = 1,
337*4882a593Smuzhiyun .mpeg_mode = LGDT3305_MPEG_SERIAL,
338*4882a593Smuzhiyun .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
339*4882a593Smuzhiyun .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
340*4882a593Smuzhiyun .vsb_if_khz = 3600,
341*4882a593Smuzhiyun .qam_if_khz = 3600,
342*4882a593Smuzhiyun };
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun static struct s921_config sharp_isdbt = {
345*4882a593Smuzhiyun .demod_address = 0x30 >> 1
346*4882a593Smuzhiyun };
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun static struct zl10353_config em28xx_zl10353_with_xc3028 = {
349*4882a593Smuzhiyun .demod_address = (0x1e >> 1),
350*4882a593Smuzhiyun .no_tuner = 1,
351*4882a593Smuzhiyun .parallel_ts = 1,
352*4882a593Smuzhiyun .if2 = 45600,
353*4882a593Smuzhiyun };
354*4882a593Smuzhiyun
355*4882a593Smuzhiyun static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
356*4882a593Smuzhiyun .demod_address = 0x32 >> 1,
357*4882a593Smuzhiyun .output_mode = S5H1409_PARALLEL_OUTPUT,
358*4882a593Smuzhiyun .gpio = S5H1409_GPIO_OFF,
359*4882a593Smuzhiyun .inversion = S5H1409_INVERSION_OFF,
360*4882a593Smuzhiyun .status_mode = S5H1409_DEMODLOCKING,
361*4882a593Smuzhiyun .mpeg_timing = S5H1409_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK
362*4882a593Smuzhiyun };
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun static struct tda18271_std_map kworld_a340_std_map = {
365*4882a593Smuzhiyun .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
366*4882a593Smuzhiyun .if_lvl = 1, .rfagc_top = 0x37, },
367*4882a593Smuzhiyun .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
368*4882a593Smuzhiyun .if_lvl = 1, .rfagc_top = 0x37, },
369*4882a593Smuzhiyun };
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun static struct tda18271_config kworld_a340_config = {
372*4882a593Smuzhiyun .std_map = &kworld_a340_std_map,
373*4882a593Smuzhiyun };
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun static struct tda18271_config kworld_ub435q_v2_config = {
376*4882a593Smuzhiyun .std_map = &kworld_a340_std_map,
377*4882a593Smuzhiyun .gate = TDA18271_GATE_DIGITAL,
378*4882a593Smuzhiyun };
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun static struct tda18212_config kworld_ub435q_v3_config = {
381*4882a593Smuzhiyun .if_atsc_vsb = 3600,
382*4882a593Smuzhiyun .if_atsc_qam = 3600,
383*4882a593Smuzhiyun };
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
386*4882a593Smuzhiyun .demod_address = (0x1e >> 1),
387*4882a593Smuzhiyun .no_tuner = 1,
388*4882a593Smuzhiyun .disable_i2c_gate_ctrl = 1,
389*4882a593Smuzhiyun .parallel_ts = 1,
390*4882a593Smuzhiyun .if2 = 45600,
391*4882a593Smuzhiyun };
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun static struct drxd_config em28xx_drxd = {
394*4882a593Smuzhiyun .demod_address = 0x70,
395*4882a593Smuzhiyun .demod_revision = 0xa2,
396*4882a593Smuzhiyun .pll_type = DRXD_PLL_NONE,
397*4882a593Smuzhiyun .clock = 12000,
398*4882a593Smuzhiyun .insert_rs_byte = 1,
399*4882a593Smuzhiyun .IF = 42800000,
400*4882a593Smuzhiyun .disable_i2c_gate_ctrl = 1,
401*4882a593Smuzhiyun };
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun static struct drxk_config terratec_h5_drxk = {
404*4882a593Smuzhiyun .adr = 0x29,
405*4882a593Smuzhiyun .single_master = 1,
406*4882a593Smuzhiyun .no_i2c_bridge = 1,
407*4882a593Smuzhiyun .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
408*4882a593Smuzhiyun .qam_demod_parameter_count = 2,
409*4882a593Smuzhiyun };
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun static struct drxk_config hauppauge_930c_drxk = {
412*4882a593Smuzhiyun .adr = 0x29,
413*4882a593Smuzhiyun .single_master = 1,
414*4882a593Smuzhiyun .no_i2c_bridge = 1,
415*4882a593Smuzhiyun .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
416*4882a593Smuzhiyun .chunk_size = 56,
417*4882a593Smuzhiyun .qam_demod_parameter_count = 2,
418*4882a593Smuzhiyun };
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun static struct drxk_config terratec_htc_stick_drxk = {
421*4882a593Smuzhiyun .adr = 0x29,
422*4882a593Smuzhiyun .single_master = 1,
423*4882a593Smuzhiyun .no_i2c_bridge = 1,
424*4882a593Smuzhiyun .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
425*4882a593Smuzhiyun .chunk_size = 54,
426*4882a593Smuzhiyun .qam_demod_parameter_count = 2,
427*4882a593Smuzhiyun /* Required for the antenna_gpio to disable LNA. */
428*4882a593Smuzhiyun .antenna_dvbt = true,
429*4882a593Smuzhiyun /* The windows driver uses the same. This will disable LNA. */
430*4882a593Smuzhiyun .antenna_gpio = 0x6,
431*4882a593Smuzhiyun };
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun static struct drxk_config maxmedia_ub425_tc_drxk = {
434*4882a593Smuzhiyun .adr = 0x29,
435*4882a593Smuzhiyun .single_master = 1,
436*4882a593Smuzhiyun .no_i2c_bridge = 1,
437*4882a593Smuzhiyun .microcode_name = "dvb-demod-drxk-01.fw",
438*4882a593Smuzhiyun .chunk_size = 62,
439*4882a593Smuzhiyun .qam_demod_parameter_count = 2,
440*4882a593Smuzhiyun };
441*4882a593Smuzhiyun
442*4882a593Smuzhiyun static struct drxk_config pctv_520e_drxk = {
443*4882a593Smuzhiyun .adr = 0x29,
444*4882a593Smuzhiyun .single_master = 1,
445*4882a593Smuzhiyun .microcode_name = "dvb-demod-drxk-pctv.fw",
446*4882a593Smuzhiyun .qam_demod_parameter_count = 2,
447*4882a593Smuzhiyun .chunk_size = 58,
448*4882a593Smuzhiyun .antenna_dvbt = true, /* disable LNA */
449*4882a593Smuzhiyun .antenna_gpio = (1 << 2), /* disable LNA */
450*4882a593Smuzhiyun };
451*4882a593Smuzhiyun
drxk_gate_ctrl(struct dvb_frontend * fe,int enable)452*4882a593Smuzhiyun static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
453*4882a593Smuzhiyun {
454*4882a593Smuzhiyun struct em28xx_dvb *dvb = fe->sec_priv;
455*4882a593Smuzhiyun int status;
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun if (!dvb)
458*4882a593Smuzhiyun return -EINVAL;
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun if (enable) {
461*4882a593Smuzhiyun down(&dvb->pll_mutex);
462*4882a593Smuzhiyun status = dvb->gate_ctrl(fe, 1);
463*4882a593Smuzhiyun } else {
464*4882a593Smuzhiyun status = dvb->gate_ctrl(fe, 0);
465*4882a593Smuzhiyun up(&dvb->pll_mutex);
466*4882a593Smuzhiyun }
467*4882a593Smuzhiyun return status;
468*4882a593Smuzhiyun }
469*4882a593Smuzhiyun
hauppauge_hvr930c_init(struct em28xx * dev)470*4882a593Smuzhiyun static void hauppauge_hvr930c_init(struct em28xx *dev)
471*4882a593Smuzhiyun {
472*4882a593Smuzhiyun int i;
473*4882a593Smuzhiyun
474*4882a593Smuzhiyun static const struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
475*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
476*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
477*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
478*4882a593Smuzhiyun { -1, -1, -1, -1},
479*4882a593Smuzhiyun };
480*4882a593Smuzhiyun static const struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
481*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
482*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
483*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
484*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
485*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
486*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
487*4882a593Smuzhiyun
488*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
489*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
490*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
491*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun { -1, -1, -1, -1},
494*4882a593Smuzhiyun };
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun static const struct {
497*4882a593Smuzhiyun unsigned char r[4];
498*4882a593Smuzhiyun int len;
499*4882a593Smuzhiyun } regs[] = {
500*4882a593Smuzhiyun {{ 0x06, 0x02, 0x00, 0x31 }, 4},
501*4882a593Smuzhiyun {{ 0x01, 0x02 }, 2},
502*4882a593Smuzhiyun {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
503*4882a593Smuzhiyun {{ 0x01, 0x00 }, 2},
504*4882a593Smuzhiyun {{ 0x01, 0x00, 0xff, 0xaf }, 4},
505*4882a593Smuzhiyun {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
506*4882a593Smuzhiyun {{ 0x01, 0x00 }, 2},
507*4882a593Smuzhiyun {{ 0x01, 0x00, 0x73, 0xaf }, 4},
508*4882a593Smuzhiyun {{ 0x04, 0x00 }, 2},
509*4882a593Smuzhiyun {{ 0x00, 0x04 }, 2},
510*4882a593Smuzhiyun {{ 0x00, 0x04, 0x00, 0x0a }, 4},
511*4882a593Smuzhiyun {{ 0x04, 0x14 }, 2},
512*4882a593Smuzhiyun {{ 0x04, 0x14, 0x00, 0x00 }, 4},
513*4882a593Smuzhiyun };
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun em28xx_gpio_set(dev, hauppauge_hvr930c_init);
516*4882a593Smuzhiyun em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
517*4882a593Smuzhiyun usleep_range(10000, 11000);
518*4882a593Smuzhiyun em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
519*4882a593Smuzhiyun usleep_range(10000, 11000);
520*4882a593Smuzhiyun
521*4882a593Smuzhiyun dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
522*4882a593Smuzhiyun
523*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(regs); i++)
524*4882a593Smuzhiyun i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
525*4882a593Smuzhiyun regs[i].r, regs[i].len);
526*4882a593Smuzhiyun em28xx_gpio_set(dev, hauppauge_hvr930c_end);
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun msleep(100);
529*4882a593Smuzhiyun
530*4882a593Smuzhiyun em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
531*4882a593Smuzhiyun msleep(30);
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
534*4882a593Smuzhiyun usleep_range(10000, 11000);
535*4882a593Smuzhiyun }
536*4882a593Smuzhiyun
terratec_h5_init(struct em28xx * dev)537*4882a593Smuzhiyun static void terratec_h5_init(struct em28xx *dev)
538*4882a593Smuzhiyun {
539*4882a593Smuzhiyun int i;
540*4882a593Smuzhiyun static const struct em28xx_reg_seq terratec_h5_init[] = {
541*4882a593Smuzhiyun {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
542*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
543*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
544*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
545*4882a593Smuzhiyun { -1, -1, -1, -1},
546*4882a593Smuzhiyun };
547*4882a593Smuzhiyun static const struct em28xx_reg_seq terratec_h5_end[] = {
548*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
549*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
550*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
551*4882a593Smuzhiyun { -1, -1, -1, -1},
552*4882a593Smuzhiyun };
553*4882a593Smuzhiyun static const struct {
554*4882a593Smuzhiyun unsigned char r[4];
555*4882a593Smuzhiyun int len;
556*4882a593Smuzhiyun } regs[] = {
557*4882a593Smuzhiyun {{ 0x06, 0x02, 0x00, 0x31 }, 4},
558*4882a593Smuzhiyun {{ 0x01, 0x02 }, 2},
559*4882a593Smuzhiyun {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
560*4882a593Smuzhiyun {{ 0x01, 0x00 }, 2},
561*4882a593Smuzhiyun {{ 0x01, 0x00, 0xff, 0xaf }, 4},
562*4882a593Smuzhiyun {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
563*4882a593Smuzhiyun {{ 0x01, 0x00 }, 2},
564*4882a593Smuzhiyun {{ 0x01, 0x00, 0x73, 0xaf }, 4},
565*4882a593Smuzhiyun {{ 0x04, 0x00 }, 2},
566*4882a593Smuzhiyun {{ 0x00, 0x04 }, 2},
567*4882a593Smuzhiyun {{ 0x00, 0x04, 0x00, 0x0a }, 4},
568*4882a593Smuzhiyun {{ 0x04, 0x14 }, 2},
569*4882a593Smuzhiyun {{ 0x04, 0x14, 0x00, 0x00 }, 4},
570*4882a593Smuzhiyun };
571*4882a593Smuzhiyun
572*4882a593Smuzhiyun em28xx_gpio_set(dev, terratec_h5_init);
573*4882a593Smuzhiyun em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
574*4882a593Smuzhiyun usleep_range(10000, 11000);
575*4882a593Smuzhiyun em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
576*4882a593Smuzhiyun usleep_range(10000, 11000);
577*4882a593Smuzhiyun
578*4882a593Smuzhiyun dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
579*4882a593Smuzhiyun
580*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(regs); i++)
581*4882a593Smuzhiyun i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
582*4882a593Smuzhiyun regs[i].r, regs[i].len);
583*4882a593Smuzhiyun em28xx_gpio_set(dev, terratec_h5_end);
584*4882a593Smuzhiyun };
585*4882a593Smuzhiyun
terratec_htc_stick_init(struct em28xx * dev)586*4882a593Smuzhiyun static void terratec_htc_stick_init(struct em28xx *dev)
587*4882a593Smuzhiyun {
588*4882a593Smuzhiyun int i;
589*4882a593Smuzhiyun
590*4882a593Smuzhiyun /*
591*4882a593Smuzhiyun * GPIO configuration:
592*4882a593Smuzhiyun * 0xff: unknown (does not affect DVB-T).
593*4882a593Smuzhiyun * 0xf6: DRX-K (demodulator).
594*4882a593Smuzhiyun * 0xe6: unknown (does not affect DVB-T).
595*4882a593Smuzhiyun * 0xb6: unknown (does not affect DVB-T).
596*4882a593Smuzhiyun */
597*4882a593Smuzhiyun static const struct em28xx_reg_seq terratec_htc_stick_init[] = {
598*4882a593Smuzhiyun {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
599*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
600*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
601*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
602*4882a593Smuzhiyun { -1, -1, -1, -1},
603*4882a593Smuzhiyun };
604*4882a593Smuzhiyun static const struct em28xx_reg_seq terratec_htc_stick_end[] = {
605*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
606*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
607*4882a593Smuzhiyun { -1, -1, -1, -1},
608*4882a593Smuzhiyun };
609*4882a593Smuzhiyun
610*4882a593Smuzhiyun /*
611*4882a593Smuzhiyun * Init the analog decoder (not yet supported), but
612*4882a593Smuzhiyun * it's probably still a good idea.
613*4882a593Smuzhiyun */
614*4882a593Smuzhiyun static const struct {
615*4882a593Smuzhiyun unsigned char r[4];
616*4882a593Smuzhiyun int len;
617*4882a593Smuzhiyun } regs[] = {
618*4882a593Smuzhiyun {{ 0x06, 0x02, 0x00, 0x31 }, 4},
619*4882a593Smuzhiyun {{ 0x01, 0x02 }, 2},
620*4882a593Smuzhiyun {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
621*4882a593Smuzhiyun {{ 0x01, 0x00 }, 2},
622*4882a593Smuzhiyun {{ 0x01, 0x00, 0xff, 0xaf }, 4},
623*4882a593Smuzhiyun };
624*4882a593Smuzhiyun
625*4882a593Smuzhiyun em28xx_gpio_set(dev, terratec_htc_stick_init);
626*4882a593Smuzhiyun
627*4882a593Smuzhiyun em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
628*4882a593Smuzhiyun usleep_range(10000, 11000);
629*4882a593Smuzhiyun em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
630*4882a593Smuzhiyun usleep_range(10000, 11000);
631*4882a593Smuzhiyun
632*4882a593Smuzhiyun dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
633*4882a593Smuzhiyun
634*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(regs); i++)
635*4882a593Smuzhiyun i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
636*4882a593Smuzhiyun regs[i].r, regs[i].len);
637*4882a593Smuzhiyun
638*4882a593Smuzhiyun em28xx_gpio_set(dev, terratec_htc_stick_end);
639*4882a593Smuzhiyun };
640*4882a593Smuzhiyun
terratec_htc_usb_xs_init(struct em28xx * dev)641*4882a593Smuzhiyun static void terratec_htc_usb_xs_init(struct em28xx *dev)
642*4882a593Smuzhiyun {
643*4882a593Smuzhiyun int i;
644*4882a593Smuzhiyun
645*4882a593Smuzhiyun static const struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
646*4882a593Smuzhiyun {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
647*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
648*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
649*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
650*4882a593Smuzhiyun { -1, -1, -1, -1},
651*4882a593Smuzhiyun };
652*4882a593Smuzhiyun static const struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
653*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
654*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
655*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
656*4882a593Smuzhiyun { -1, -1, -1, -1},
657*4882a593Smuzhiyun };
658*4882a593Smuzhiyun
659*4882a593Smuzhiyun /*
660*4882a593Smuzhiyun * Init the analog decoder (not yet supported), but
661*4882a593Smuzhiyun * it's probably still a good idea.
662*4882a593Smuzhiyun */
663*4882a593Smuzhiyun static const struct {
664*4882a593Smuzhiyun unsigned char r[4];
665*4882a593Smuzhiyun int len;
666*4882a593Smuzhiyun } regs[] = {
667*4882a593Smuzhiyun {{ 0x06, 0x02, 0x00, 0x31 }, 4},
668*4882a593Smuzhiyun {{ 0x01, 0x02 }, 2},
669*4882a593Smuzhiyun {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
670*4882a593Smuzhiyun {{ 0x01, 0x00 }, 2},
671*4882a593Smuzhiyun {{ 0x01, 0x00, 0xff, 0xaf }, 4},
672*4882a593Smuzhiyun {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
673*4882a593Smuzhiyun {{ 0x01, 0x00 }, 2},
674*4882a593Smuzhiyun {{ 0x01, 0x00, 0x73, 0xaf }, 4},
675*4882a593Smuzhiyun {{ 0x04, 0x00 }, 2},
676*4882a593Smuzhiyun {{ 0x00, 0x04 }, 2},
677*4882a593Smuzhiyun {{ 0x00, 0x04, 0x00, 0x0a }, 4},
678*4882a593Smuzhiyun {{ 0x04, 0x14 }, 2},
679*4882a593Smuzhiyun {{ 0x04, 0x14, 0x00, 0x00 }, 4},
680*4882a593Smuzhiyun };
681*4882a593Smuzhiyun
682*4882a593Smuzhiyun em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
683*4882a593Smuzhiyun
684*4882a593Smuzhiyun em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
685*4882a593Smuzhiyun
686*4882a593Smuzhiyun em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
687*4882a593Smuzhiyun usleep_range(10000, 11000);
688*4882a593Smuzhiyun em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
689*4882a593Smuzhiyun usleep_range(10000, 11000);
690*4882a593Smuzhiyun
691*4882a593Smuzhiyun dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
692*4882a593Smuzhiyun
693*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(regs); i++)
694*4882a593Smuzhiyun i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
695*4882a593Smuzhiyun regs[i].r, regs[i].len);
696*4882a593Smuzhiyun
697*4882a593Smuzhiyun em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
698*4882a593Smuzhiyun };
699*4882a593Smuzhiyun
pctv_520e_init(struct em28xx * dev)700*4882a593Smuzhiyun static void pctv_520e_init(struct em28xx *dev)
701*4882a593Smuzhiyun {
702*4882a593Smuzhiyun /*
703*4882a593Smuzhiyun * Init AVF4910B analog decoder. Looks like I2C traffic to
704*4882a593Smuzhiyun * digital demodulator and tuner are routed via AVF4910B.
705*4882a593Smuzhiyun */
706*4882a593Smuzhiyun int i;
707*4882a593Smuzhiyun static const struct {
708*4882a593Smuzhiyun unsigned char r[4];
709*4882a593Smuzhiyun int len;
710*4882a593Smuzhiyun } regs[] = {
711*4882a593Smuzhiyun {{ 0x06, 0x02, 0x00, 0x31 }, 4},
712*4882a593Smuzhiyun {{ 0x01, 0x02 }, 2},
713*4882a593Smuzhiyun {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
714*4882a593Smuzhiyun {{ 0x01, 0x00 }, 2},
715*4882a593Smuzhiyun {{ 0x01, 0x00, 0xff, 0xaf }, 4},
716*4882a593Smuzhiyun {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
717*4882a593Smuzhiyun {{ 0x01, 0x00 }, 2},
718*4882a593Smuzhiyun {{ 0x01, 0x00, 0x73, 0xaf }, 4},
719*4882a593Smuzhiyun };
720*4882a593Smuzhiyun
721*4882a593Smuzhiyun dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
722*4882a593Smuzhiyun
723*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(regs); i++)
724*4882a593Smuzhiyun i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
725*4882a593Smuzhiyun regs[i].r, regs[i].len);
726*4882a593Smuzhiyun };
727*4882a593Smuzhiyun
em28xx_pctv_290e_set_lna(struct dvb_frontend * fe)728*4882a593Smuzhiyun static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
729*4882a593Smuzhiyun {
730*4882a593Smuzhiyun struct dtv_frontend_properties *c = &fe->dtv_property_cache;
731*4882a593Smuzhiyun struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
732*4882a593Smuzhiyun struct em28xx *dev = i2c_bus->dev;
733*4882a593Smuzhiyun #ifdef CONFIG_GPIOLIB
734*4882a593Smuzhiyun struct em28xx_dvb *dvb = dev->dvb;
735*4882a593Smuzhiyun int ret;
736*4882a593Smuzhiyun unsigned long flags;
737*4882a593Smuzhiyun
738*4882a593Smuzhiyun if (c->lna == 1)
739*4882a593Smuzhiyun flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
740*4882a593Smuzhiyun else
741*4882a593Smuzhiyun flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
742*4882a593Smuzhiyun
743*4882a593Smuzhiyun ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
744*4882a593Smuzhiyun if (ret)
745*4882a593Smuzhiyun dev_err(&dev->intf->dev, "gpio request failed %d\n", ret);
746*4882a593Smuzhiyun else
747*4882a593Smuzhiyun gpio_free(dvb->lna_gpio);
748*4882a593Smuzhiyun
749*4882a593Smuzhiyun return ret;
750*4882a593Smuzhiyun #else
751*4882a593Smuzhiyun dev_warn(&dev->intf->dev, "%s: LNA control is disabled (lna=%u)\n",
752*4882a593Smuzhiyun KBUILD_MODNAME, c->lna);
753*4882a593Smuzhiyun return 0;
754*4882a593Smuzhiyun #endif
755*4882a593Smuzhiyun }
756*4882a593Smuzhiyun
em28xx_pctv_292e_set_lna(struct dvb_frontend * fe)757*4882a593Smuzhiyun static int em28xx_pctv_292e_set_lna(struct dvb_frontend *fe)
758*4882a593Smuzhiyun {
759*4882a593Smuzhiyun struct dtv_frontend_properties *c = &fe->dtv_property_cache;
760*4882a593Smuzhiyun struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
761*4882a593Smuzhiyun struct em28xx *dev = i2c_bus->dev;
762*4882a593Smuzhiyun u8 lna;
763*4882a593Smuzhiyun
764*4882a593Smuzhiyun if (c->lna == 1)
765*4882a593Smuzhiyun lna = 0x01;
766*4882a593Smuzhiyun else
767*4882a593Smuzhiyun lna = 0x00;
768*4882a593Smuzhiyun
769*4882a593Smuzhiyun return em28xx_write_reg_bits(dev, EM2874_R80_GPIO_P0_CTRL, lna, 0x01);
770*4882a593Smuzhiyun }
771*4882a593Smuzhiyun
em28xx_mt352_terratec_xs_init(struct dvb_frontend * fe)772*4882a593Smuzhiyun static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
773*4882a593Smuzhiyun {
774*4882a593Smuzhiyun /* Values extracted from a USB trace of the Terratec Windows driver */
775*4882a593Smuzhiyun static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
776*4882a593Smuzhiyun static u8 reset[] = { RESET, 0x80 };
777*4882a593Smuzhiyun static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
778*4882a593Smuzhiyun static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
779*4882a593Smuzhiyun static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
780*4882a593Smuzhiyun static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
781*4882a593Smuzhiyun static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
782*4882a593Smuzhiyun static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
783*4882a593Smuzhiyun static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
784*4882a593Smuzhiyun static u8 tuner_go[] = { TUNER_GO, 0x01};
785*4882a593Smuzhiyun
786*4882a593Smuzhiyun mt352_write(fe, clock_config, sizeof(clock_config));
787*4882a593Smuzhiyun usleep_range(200, 250);
788*4882a593Smuzhiyun mt352_write(fe, reset, sizeof(reset));
789*4882a593Smuzhiyun mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
790*4882a593Smuzhiyun mt352_write(fe, agc_cfg, sizeof(agc_cfg));
791*4882a593Smuzhiyun mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
792*4882a593Smuzhiyun mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
793*4882a593Smuzhiyun mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
794*4882a593Smuzhiyun mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
795*4882a593Smuzhiyun mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
796*4882a593Smuzhiyun mt352_write(fe, tuner_go, sizeof(tuner_go));
797*4882a593Smuzhiyun return 0;
798*4882a593Smuzhiyun }
799*4882a593Smuzhiyun
px_bcud_init(struct em28xx * dev)800*4882a593Smuzhiyun static void px_bcud_init(struct em28xx *dev)
801*4882a593Smuzhiyun {
802*4882a593Smuzhiyun int i;
803*4882a593Smuzhiyun static const struct {
804*4882a593Smuzhiyun unsigned char r[4];
805*4882a593Smuzhiyun int len;
806*4882a593Smuzhiyun } regs1[] = {
807*4882a593Smuzhiyun {{ 0x0e, 0x77 }, 2},
808*4882a593Smuzhiyun {{ 0x0f, 0x77 }, 2},
809*4882a593Smuzhiyun {{ 0x03, 0x90 }, 2},
810*4882a593Smuzhiyun }, regs2[] = {
811*4882a593Smuzhiyun {{ 0x07, 0x01 }, 2},
812*4882a593Smuzhiyun {{ 0x08, 0x10 }, 2},
813*4882a593Smuzhiyun {{ 0x13, 0x00 }, 2},
814*4882a593Smuzhiyun {{ 0x17, 0x00 }, 2},
815*4882a593Smuzhiyun {{ 0x03, 0x01 }, 2},
816*4882a593Smuzhiyun {{ 0x10, 0xb1 }, 2},
817*4882a593Smuzhiyun {{ 0x11, 0x40 }, 2},
818*4882a593Smuzhiyun {{ 0x85, 0x7a }, 2},
819*4882a593Smuzhiyun {{ 0x87, 0x04 }, 2},
820*4882a593Smuzhiyun };
821*4882a593Smuzhiyun static const struct em28xx_reg_seq gpio[] = {
822*4882a593Smuzhiyun {EM28XX_R06_I2C_CLK, 0x40, 0xff, 300},
823*4882a593Smuzhiyun {EM2874_R80_GPIO_P0_CTRL, 0xfd, 0xff, 60},
824*4882a593Smuzhiyun {EM28XX_R15_RGAIN, 0x20, 0xff, 0},
825*4882a593Smuzhiyun {EM28XX_R16_GGAIN, 0x20, 0xff, 0},
826*4882a593Smuzhiyun {EM28XX_R17_BGAIN, 0x20, 0xff, 0},
827*4882a593Smuzhiyun {EM28XX_R18_ROFFSET, 0x00, 0xff, 0},
828*4882a593Smuzhiyun {EM28XX_R19_GOFFSET, 0x00, 0xff, 0},
829*4882a593Smuzhiyun {EM28XX_R1A_BOFFSET, 0x00, 0xff, 0},
830*4882a593Smuzhiyun {EM28XX_R23_UOFFSET, 0x00, 0xff, 0},
831*4882a593Smuzhiyun {EM28XX_R24_VOFFSET, 0x00, 0xff, 0},
832*4882a593Smuzhiyun {EM28XX_R26_COMPR, 0x00, 0xff, 0},
833*4882a593Smuzhiyun {0x13, 0x08, 0xff, 0},
834*4882a593Smuzhiyun {EM28XX_R12_VINENABLE, 0x27, 0xff, 0},
835*4882a593Smuzhiyun {EM28XX_R0C_USBSUSP, 0x10, 0xff, 0},
836*4882a593Smuzhiyun {EM28XX_R27_OUTFMT, 0x00, 0xff, 0},
837*4882a593Smuzhiyun {EM28XX_R10_VINMODE, 0x00, 0xff, 0},
838*4882a593Smuzhiyun {EM28XX_R11_VINCTRL, 0x11, 0xff, 0},
839*4882a593Smuzhiyun {EM2874_R50_IR_CONFIG, 0x01, 0xff, 0},
840*4882a593Smuzhiyun {EM2874_R5F_TS_ENABLE, 0x80, 0xff, 0},
841*4882a593Smuzhiyun {EM28XX_R06_I2C_CLK, 0x46, 0xff, 0},
842*4882a593Smuzhiyun };
843*4882a593Smuzhiyun em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x46);
844*4882a593Smuzhiyun /* sleeping ISDB-T */
845*4882a593Smuzhiyun dev->dvb->i2c_client_demod->addr = 0x14;
846*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(regs1); i++)
847*4882a593Smuzhiyun i2c_master_send(dev->dvb->i2c_client_demod,
848*4882a593Smuzhiyun regs1[i].r, regs1[i].len);
849*4882a593Smuzhiyun /* sleeping ISDB-S */
850*4882a593Smuzhiyun dev->dvb->i2c_client_demod->addr = 0x15;
851*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(regs2); i++)
852*4882a593Smuzhiyun i2c_master_send(dev->dvb->i2c_client_demod, regs2[i].r,
853*4882a593Smuzhiyun regs2[i].len);
854*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(gpio); i++) {
855*4882a593Smuzhiyun em28xx_write_reg_bits(dev, gpio[i].reg, gpio[i].val,
856*4882a593Smuzhiyun gpio[i].mask);
857*4882a593Smuzhiyun if (gpio[i].sleep > 0)
858*4882a593Smuzhiyun msleep(gpio[i].sleep);
859*4882a593Smuzhiyun }
860*4882a593Smuzhiyun };
861*4882a593Smuzhiyun
862*4882a593Smuzhiyun static struct mt352_config terratec_xs_mt352_cfg = {
863*4882a593Smuzhiyun .demod_address = (0x1e >> 1),
864*4882a593Smuzhiyun .no_tuner = 1,
865*4882a593Smuzhiyun .if2 = 45600,
866*4882a593Smuzhiyun .demod_init = em28xx_mt352_terratec_xs_init,
867*4882a593Smuzhiyun };
868*4882a593Smuzhiyun
869*4882a593Smuzhiyun static struct tda10023_config em28xx_tda10023_config = {
870*4882a593Smuzhiyun .demod_address = 0x0c,
871*4882a593Smuzhiyun .invert = 1,
872*4882a593Smuzhiyun };
873*4882a593Smuzhiyun
874*4882a593Smuzhiyun static struct cxd2820r_config em28xx_cxd2820r_config = {
875*4882a593Smuzhiyun .i2c_address = (0xd8 >> 1),
876*4882a593Smuzhiyun .ts_mode = CXD2820R_TS_SERIAL,
877*4882a593Smuzhiyun };
878*4882a593Smuzhiyun
879*4882a593Smuzhiyun static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
880*4882a593Smuzhiyun .output_opt = TDA18271_OUTPUT_LT_OFF,
881*4882a593Smuzhiyun .gate = TDA18271_GATE_DIGITAL,
882*4882a593Smuzhiyun };
883*4882a593Smuzhiyun
884*4882a593Smuzhiyun static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
885*4882a593Smuzhiyun .demod_address = (0x1e >> 1),
886*4882a593Smuzhiyun .disable_i2c_gate_ctrl = 1,
887*4882a593Smuzhiyun .no_tuner = 1,
888*4882a593Smuzhiyun .parallel_ts = 1,
889*4882a593Smuzhiyun };
890*4882a593Smuzhiyun
891*4882a593Smuzhiyun static struct mt2060_config em28xx_mt2060_config = {
892*4882a593Smuzhiyun .i2c_address = 0x60,
893*4882a593Smuzhiyun };
894*4882a593Smuzhiyun
895*4882a593Smuzhiyun static struct qt1010_config em28xx_qt1010_config = {
896*4882a593Smuzhiyun .i2c_address = 0x62
897*4882a593Smuzhiyun };
898*4882a593Smuzhiyun
899*4882a593Smuzhiyun static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
900*4882a593Smuzhiyun .demod_address = 0x10,
901*4882a593Smuzhiyun .is_serial = true,
902*4882a593Smuzhiyun };
903*4882a593Smuzhiyun
904*4882a593Smuzhiyun static struct tda18271_std_map mb86a20s_tda18271_config = {
905*4882a593Smuzhiyun .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
906*4882a593Smuzhiyun .if_lvl = 1, .rfagc_top = 0x37, },
907*4882a593Smuzhiyun };
908*4882a593Smuzhiyun
909*4882a593Smuzhiyun static struct tda18271_config c3tech_duo_tda18271_config = {
910*4882a593Smuzhiyun .std_map = &mb86a20s_tda18271_config,
911*4882a593Smuzhiyun .gate = TDA18271_GATE_DIGITAL,
912*4882a593Smuzhiyun .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
913*4882a593Smuzhiyun };
914*4882a593Smuzhiyun
915*4882a593Smuzhiyun static struct tda18271_std_map drx_j_std_map = {
916*4882a593Smuzhiyun .atsc_6 = { .if_freq = 5000, .agc_mode = 3, .std = 0, .if_lvl = 1,
917*4882a593Smuzhiyun .rfagc_top = 0x37, },
918*4882a593Smuzhiyun .qam_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3, .if_lvl = 1,
919*4882a593Smuzhiyun .rfagc_top = 0x37, },
920*4882a593Smuzhiyun };
921*4882a593Smuzhiyun
922*4882a593Smuzhiyun static struct tda18271_config pinnacle_80e_dvb_config = {
923*4882a593Smuzhiyun .std_map = &drx_j_std_map,
924*4882a593Smuzhiyun .gate = TDA18271_GATE_DIGITAL,
925*4882a593Smuzhiyun .role = TDA18271_MASTER,
926*4882a593Smuzhiyun };
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun static struct lgdt3306a_config hauppauge_01595_lgdt3306a_config = {
929*4882a593Smuzhiyun .qam_if_khz = 4000,
930*4882a593Smuzhiyun .vsb_if_khz = 3250,
931*4882a593Smuzhiyun .spectral_inversion = 0,
932*4882a593Smuzhiyun .deny_i2c_rptr = 0,
933*4882a593Smuzhiyun .mpeg_mode = LGDT3306A_MPEG_SERIAL,
934*4882a593Smuzhiyun .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
935*4882a593Smuzhiyun .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
936*4882a593Smuzhiyun .xtalMHz = 25,
937*4882a593Smuzhiyun };
938*4882a593Smuzhiyun
939*4882a593Smuzhiyun /* ------------------------------------------------------------------ */
940*4882a593Smuzhiyun
em28xx_attach_xc3028(u8 addr,struct em28xx * dev)941*4882a593Smuzhiyun static noinline_for_stack int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
942*4882a593Smuzhiyun {
943*4882a593Smuzhiyun struct dvb_frontend *fe;
944*4882a593Smuzhiyun struct xc2028_config cfg;
945*4882a593Smuzhiyun struct xc2028_ctrl ctl;
946*4882a593Smuzhiyun
947*4882a593Smuzhiyun memset(&cfg, 0, sizeof(cfg));
948*4882a593Smuzhiyun cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
949*4882a593Smuzhiyun cfg.i2c_addr = addr;
950*4882a593Smuzhiyun
951*4882a593Smuzhiyun memset(&ctl, 0, sizeof(ctl));
952*4882a593Smuzhiyun em28xx_setup_xc3028(dev, &ctl);
953*4882a593Smuzhiyun cfg.ctrl = &ctl;
954*4882a593Smuzhiyun
955*4882a593Smuzhiyun if (!dev->dvb->fe[0]) {
956*4882a593Smuzhiyun dev_err(&dev->intf->dev,
957*4882a593Smuzhiyun "dvb frontend not attached. Can't attach xc3028\n");
958*4882a593Smuzhiyun return -EINVAL;
959*4882a593Smuzhiyun }
960*4882a593Smuzhiyun
961*4882a593Smuzhiyun fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
962*4882a593Smuzhiyun if (!fe) {
963*4882a593Smuzhiyun dev_err(&dev->intf->dev, "xc3028 attach failed\n");
964*4882a593Smuzhiyun dvb_frontend_detach(dev->dvb->fe[0]);
965*4882a593Smuzhiyun dev->dvb->fe[0] = NULL;
966*4882a593Smuzhiyun return -EINVAL;
967*4882a593Smuzhiyun }
968*4882a593Smuzhiyun
969*4882a593Smuzhiyun dev_info(&dev->intf->dev, "xc3028 attached\n");
970*4882a593Smuzhiyun
971*4882a593Smuzhiyun return 0;
972*4882a593Smuzhiyun }
973*4882a593Smuzhiyun
974*4882a593Smuzhiyun /* ------------------------------------------------------------------ */
975*4882a593Smuzhiyun
em28xx_register_dvb(struct em28xx_dvb * dvb,struct module * module,struct em28xx * dev,struct device * device)976*4882a593Smuzhiyun static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
977*4882a593Smuzhiyun struct em28xx *dev, struct device *device)
978*4882a593Smuzhiyun {
979*4882a593Smuzhiyun int result;
980*4882a593Smuzhiyun bool create_rf_connector = false;
981*4882a593Smuzhiyun
982*4882a593Smuzhiyun mutex_init(&dvb->lock);
983*4882a593Smuzhiyun
984*4882a593Smuzhiyun /* register adapter */
985*4882a593Smuzhiyun result = dvb_register_adapter(&dvb->adapter,
986*4882a593Smuzhiyun dev_name(&dev->intf->dev), module,
987*4882a593Smuzhiyun device, adapter_nr);
988*4882a593Smuzhiyun if (result < 0) {
989*4882a593Smuzhiyun dev_warn(&dev->intf->dev,
990*4882a593Smuzhiyun "dvb_register_adapter failed (errno = %d)\n",
991*4882a593Smuzhiyun result);
992*4882a593Smuzhiyun goto fail_adapter;
993*4882a593Smuzhiyun }
994*4882a593Smuzhiyun #ifdef CONFIG_MEDIA_CONTROLLER_DVB
995*4882a593Smuzhiyun dvb->adapter.mdev = dev->media_dev;
996*4882a593Smuzhiyun #endif
997*4882a593Smuzhiyun
998*4882a593Smuzhiyun /* Ensure all frontends negotiate bus access */
999*4882a593Smuzhiyun dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
1000*4882a593Smuzhiyun if (dvb->fe[1])
1001*4882a593Smuzhiyun dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
1002*4882a593Smuzhiyun
1003*4882a593Smuzhiyun dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
1004*4882a593Smuzhiyun
1005*4882a593Smuzhiyun /* register frontend */
1006*4882a593Smuzhiyun result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
1007*4882a593Smuzhiyun if (result < 0) {
1008*4882a593Smuzhiyun dev_warn(&dev->intf->dev,
1009*4882a593Smuzhiyun "dvb_register_frontend failed (errno = %d)\n",
1010*4882a593Smuzhiyun result);
1011*4882a593Smuzhiyun goto fail_frontend0;
1012*4882a593Smuzhiyun }
1013*4882a593Smuzhiyun
1014*4882a593Smuzhiyun /* register 2nd frontend */
1015*4882a593Smuzhiyun if (dvb->fe[1]) {
1016*4882a593Smuzhiyun result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
1017*4882a593Smuzhiyun if (result < 0) {
1018*4882a593Smuzhiyun dev_warn(&dev->intf->dev,
1019*4882a593Smuzhiyun "2nd dvb_register_frontend failed (errno = %d)\n",
1020*4882a593Smuzhiyun result);
1021*4882a593Smuzhiyun goto fail_frontend1;
1022*4882a593Smuzhiyun }
1023*4882a593Smuzhiyun }
1024*4882a593Smuzhiyun
1025*4882a593Smuzhiyun /* register demux stuff */
1026*4882a593Smuzhiyun dvb->demux.dmx.capabilities =
1027*4882a593Smuzhiyun DMX_TS_FILTERING | DMX_SECTION_FILTERING |
1028*4882a593Smuzhiyun DMX_MEMORY_BASED_FILTERING;
1029*4882a593Smuzhiyun dvb->demux.priv = dvb;
1030*4882a593Smuzhiyun dvb->demux.filternum = 256;
1031*4882a593Smuzhiyun dvb->demux.feednum = 256;
1032*4882a593Smuzhiyun dvb->demux.start_feed = em28xx_start_feed;
1033*4882a593Smuzhiyun dvb->demux.stop_feed = em28xx_stop_feed;
1034*4882a593Smuzhiyun
1035*4882a593Smuzhiyun result = dvb_dmx_init(&dvb->demux);
1036*4882a593Smuzhiyun if (result < 0) {
1037*4882a593Smuzhiyun dev_warn(&dev->intf->dev,
1038*4882a593Smuzhiyun "dvb_dmx_init failed (errno = %d)\n",
1039*4882a593Smuzhiyun result);
1040*4882a593Smuzhiyun goto fail_dmx;
1041*4882a593Smuzhiyun }
1042*4882a593Smuzhiyun
1043*4882a593Smuzhiyun dvb->dmxdev.filternum = 256;
1044*4882a593Smuzhiyun dvb->dmxdev.demux = &dvb->demux.dmx;
1045*4882a593Smuzhiyun dvb->dmxdev.capabilities = 0;
1046*4882a593Smuzhiyun result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
1047*4882a593Smuzhiyun if (result < 0) {
1048*4882a593Smuzhiyun dev_warn(&dev->intf->dev,
1049*4882a593Smuzhiyun "dvb_dmxdev_init failed (errno = %d)\n",
1050*4882a593Smuzhiyun result);
1051*4882a593Smuzhiyun goto fail_dmxdev;
1052*4882a593Smuzhiyun }
1053*4882a593Smuzhiyun
1054*4882a593Smuzhiyun dvb->fe_hw.source = DMX_FRONTEND_0;
1055*4882a593Smuzhiyun result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1056*4882a593Smuzhiyun if (result < 0) {
1057*4882a593Smuzhiyun dev_warn(&dev->intf->dev,
1058*4882a593Smuzhiyun "add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
1059*4882a593Smuzhiyun result);
1060*4882a593Smuzhiyun goto fail_fe_hw;
1061*4882a593Smuzhiyun }
1062*4882a593Smuzhiyun
1063*4882a593Smuzhiyun dvb->fe_mem.source = DMX_MEMORY_FE;
1064*4882a593Smuzhiyun result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
1065*4882a593Smuzhiyun if (result < 0) {
1066*4882a593Smuzhiyun dev_warn(&dev->intf->dev,
1067*4882a593Smuzhiyun "add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
1068*4882a593Smuzhiyun result);
1069*4882a593Smuzhiyun goto fail_fe_mem;
1070*4882a593Smuzhiyun }
1071*4882a593Smuzhiyun
1072*4882a593Smuzhiyun result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1073*4882a593Smuzhiyun if (result < 0) {
1074*4882a593Smuzhiyun dev_warn(&dev->intf->dev,
1075*4882a593Smuzhiyun "connect_frontend failed (errno = %d)\n",
1076*4882a593Smuzhiyun result);
1077*4882a593Smuzhiyun goto fail_fe_conn;
1078*4882a593Smuzhiyun }
1079*4882a593Smuzhiyun
1080*4882a593Smuzhiyun /* register network adapter */
1081*4882a593Smuzhiyun dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
1082*4882a593Smuzhiyun
1083*4882a593Smuzhiyun /* If the analog part won't create RF connectors, DVB will do it */
1084*4882a593Smuzhiyun if (!dev->has_video || dev->tuner_type == TUNER_ABSENT)
1085*4882a593Smuzhiyun create_rf_connector = true;
1086*4882a593Smuzhiyun
1087*4882a593Smuzhiyun result = dvb_create_media_graph(&dvb->adapter, create_rf_connector);
1088*4882a593Smuzhiyun if (result < 0)
1089*4882a593Smuzhiyun goto fail_create_graph;
1090*4882a593Smuzhiyun
1091*4882a593Smuzhiyun return 0;
1092*4882a593Smuzhiyun
1093*4882a593Smuzhiyun fail_create_graph:
1094*4882a593Smuzhiyun dvb_net_release(&dvb->net);
1095*4882a593Smuzhiyun fail_fe_conn:
1096*4882a593Smuzhiyun dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
1097*4882a593Smuzhiyun fail_fe_mem:
1098*4882a593Smuzhiyun dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1099*4882a593Smuzhiyun fail_fe_hw:
1100*4882a593Smuzhiyun dvb_dmxdev_release(&dvb->dmxdev);
1101*4882a593Smuzhiyun fail_dmxdev:
1102*4882a593Smuzhiyun dvb_dmx_release(&dvb->demux);
1103*4882a593Smuzhiyun fail_dmx:
1104*4882a593Smuzhiyun if (dvb->fe[1])
1105*4882a593Smuzhiyun dvb_unregister_frontend(dvb->fe[1]);
1106*4882a593Smuzhiyun dvb_unregister_frontend(dvb->fe[0]);
1107*4882a593Smuzhiyun fail_frontend1:
1108*4882a593Smuzhiyun if (dvb->fe[1])
1109*4882a593Smuzhiyun dvb_frontend_detach(dvb->fe[1]);
1110*4882a593Smuzhiyun fail_frontend0:
1111*4882a593Smuzhiyun dvb_frontend_detach(dvb->fe[0]);
1112*4882a593Smuzhiyun dvb_unregister_adapter(&dvb->adapter);
1113*4882a593Smuzhiyun fail_adapter:
1114*4882a593Smuzhiyun return result;
1115*4882a593Smuzhiyun }
1116*4882a593Smuzhiyun
em28xx_unregister_dvb(struct em28xx_dvb * dvb)1117*4882a593Smuzhiyun static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
1118*4882a593Smuzhiyun {
1119*4882a593Smuzhiyun dvb_net_release(&dvb->net);
1120*4882a593Smuzhiyun dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
1121*4882a593Smuzhiyun dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1122*4882a593Smuzhiyun dvb_dmxdev_release(&dvb->dmxdev);
1123*4882a593Smuzhiyun dvb_dmx_release(&dvb->demux);
1124*4882a593Smuzhiyun if (dvb->fe[1])
1125*4882a593Smuzhiyun dvb_unregister_frontend(dvb->fe[1]);
1126*4882a593Smuzhiyun dvb_unregister_frontend(dvb->fe[0]);
1127*4882a593Smuzhiyun if (dvb->fe[1] && !dvb->dont_attach_fe1)
1128*4882a593Smuzhiyun dvb_frontend_detach(dvb->fe[1]);
1129*4882a593Smuzhiyun dvb_frontend_detach(dvb->fe[0]);
1130*4882a593Smuzhiyun dvb_unregister_adapter(&dvb->adapter);
1131*4882a593Smuzhiyun }
1132*4882a593Smuzhiyun
em28174_dvb_init_pctv_460e(struct em28xx * dev)1133*4882a593Smuzhiyun static int em28174_dvb_init_pctv_460e(struct em28xx *dev)
1134*4882a593Smuzhiyun {
1135*4882a593Smuzhiyun struct em28xx_dvb *dvb = dev->dvb;
1136*4882a593Smuzhiyun struct tda10071_platform_data tda10071_pdata = {};
1137*4882a593Smuzhiyun struct a8293_platform_data a8293_pdata = {};
1138*4882a593Smuzhiyun
1139*4882a593Smuzhiyun /* attach demod + tuner combo */
1140*4882a593Smuzhiyun tda10071_pdata.clk = 40444000; /* 40.444 MHz */
1141*4882a593Smuzhiyun tda10071_pdata.i2c_wr_max = 64;
1142*4882a593Smuzhiyun tda10071_pdata.ts_mode = TDA10071_TS_SERIAL;
1143*4882a593Smuzhiyun tda10071_pdata.pll_multiplier = 20;
1144*4882a593Smuzhiyun tda10071_pdata.tuner_i2c_addr = 0x14;
1145*4882a593Smuzhiyun
1146*4882a593Smuzhiyun dvb->i2c_client_demod = dvb_module_probe("tda10071", "tda10071_cx24118",
1147*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1148*4882a593Smuzhiyun 0x55, &tda10071_pdata);
1149*4882a593Smuzhiyun if (!dvb->i2c_client_demod)
1150*4882a593Smuzhiyun return -ENODEV;
1151*4882a593Smuzhiyun
1152*4882a593Smuzhiyun dvb->fe[0] = tda10071_pdata.get_dvb_frontend(dvb->i2c_client_demod);
1153*4882a593Smuzhiyun
1154*4882a593Smuzhiyun /* attach SEC */
1155*4882a593Smuzhiyun a8293_pdata.dvb_frontend = dvb->fe[0];
1156*4882a593Smuzhiyun
1157*4882a593Smuzhiyun dvb->i2c_client_sec = dvb_module_probe("a8293", NULL,
1158*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1159*4882a593Smuzhiyun 0x08, &a8293_pdata);
1160*4882a593Smuzhiyun if (!dvb->i2c_client_sec) {
1161*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_demod);
1162*4882a593Smuzhiyun return -ENODEV;
1163*4882a593Smuzhiyun }
1164*4882a593Smuzhiyun
1165*4882a593Smuzhiyun return 0;
1166*4882a593Smuzhiyun }
1167*4882a593Smuzhiyun
em28178_dvb_init_pctv_461e(struct em28xx * dev)1168*4882a593Smuzhiyun static int em28178_dvb_init_pctv_461e(struct em28xx *dev)
1169*4882a593Smuzhiyun {
1170*4882a593Smuzhiyun struct em28xx_dvb *dvb = dev->dvb;
1171*4882a593Smuzhiyun struct i2c_adapter *i2c_adapter;
1172*4882a593Smuzhiyun struct m88ds3103_platform_data m88ds3103_pdata = {};
1173*4882a593Smuzhiyun struct ts2020_config ts2020_config = {};
1174*4882a593Smuzhiyun struct a8293_platform_data a8293_pdata = {};
1175*4882a593Smuzhiyun
1176*4882a593Smuzhiyun /* attach demod */
1177*4882a593Smuzhiyun m88ds3103_pdata.clk = 27000000;
1178*4882a593Smuzhiyun m88ds3103_pdata.i2c_wr_max = 33;
1179*4882a593Smuzhiyun m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL;
1180*4882a593Smuzhiyun m88ds3103_pdata.ts_clk = 16000;
1181*4882a593Smuzhiyun m88ds3103_pdata.ts_clk_pol = 1;
1182*4882a593Smuzhiyun m88ds3103_pdata.agc = 0x99;
1183*4882a593Smuzhiyun
1184*4882a593Smuzhiyun dvb->i2c_client_demod = dvb_module_probe("m88ds3103", NULL,
1185*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1186*4882a593Smuzhiyun 0x68, &m88ds3103_pdata);
1187*4882a593Smuzhiyun if (!dvb->i2c_client_demod)
1188*4882a593Smuzhiyun return -ENODEV;
1189*4882a593Smuzhiyun
1190*4882a593Smuzhiyun dvb->fe[0] = m88ds3103_pdata.get_dvb_frontend(dvb->i2c_client_demod);
1191*4882a593Smuzhiyun i2c_adapter = m88ds3103_pdata.get_i2c_adapter(dvb->i2c_client_demod);
1192*4882a593Smuzhiyun
1193*4882a593Smuzhiyun /* attach tuner */
1194*4882a593Smuzhiyun ts2020_config.fe = dvb->fe[0];
1195*4882a593Smuzhiyun
1196*4882a593Smuzhiyun dvb->i2c_client_tuner = dvb_module_probe("ts2020", "ts2022",
1197*4882a593Smuzhiyun i2c_adapter,
1198*4882a593Smuzhiyun 0x60, &ts2020_config);
1199*4882a593Smuzhiyun if (!dvb->i2c_client_tuner) {
1200*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_demod);
1201*4882a593Smuzhiyun return -ENODEV;
1202*4882a593Smuzhiyun }
1203*4882a593Smuzhiyun
1204*4882a593Smuzhiyun /* delegate signal strength measurement to tuner */
1205*4882a593Smuzhiyun dvb->fe[0]->ops.read_signal_strength =
1206*4882a593Smuzhiyun dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1207*4882a593Smuzhiyun
1208*4882a593Smuzhiyun /* attach SEC */
1209*4882a593Smuzhiyun a8293_pdata.dvb_frontend = dvb->fe[0];
1210*4882a593Smuzhiyun dvb->i2c_client_sec = dvb_module_probe("a8293", NULL,
1211*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1212*4882a593Smuzhiyun 0x08, &a8293_pdata);
1213*4882a593Smuzhiyun if (!dvb->i2c_client_sec) {
1214*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_tuner);
1215*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_demod);
1216*4882a593Smuzhiyun return -ENODEV;
1217*4882a593Smuzhiyun }
1218*4882a593Smuzhiyun
1219*4882a593Smuzhiyun return 0;
1220*4882a593Smuzhiyun }
1221*4882a593Smuzhiyun
em28178_dvb_init_pctv_461e_v2(struct em28xx * dev)1222*4882a593Smuzhiyun static int em28178_dvb_init_pctv_461e_v2(struct em28xx *dev)
1223*4882a593Smuzhiyun {
1224*4882a593Smuzhiyun struct em28xx_dvb *dvb = dev->dvb;
1225*4882a593Smuzhiyun struct i2c_adapter *i2c_adapter;
1226*4882a593Smuzhiyun struct m88ds3103_platform_data m88ds3103_pdata = {};
1227*4882a593Smuzhiyun struct ts2020_config ts2020_config = {};
1228*4882a593Smuzhiyun struct a8293_platform_data a8293_pdata = {};
1229*4882a593Smuzhiyun
1230*4882a593Smuzhiyun /* attach demod */
1231*4882a593Smuzhiyun m88ds3103_pdata.clk = 27000000;
1232*4882a593Smuzhiyun m88ds3103_pdata.i2c_wr_max = 33;
1233*4882a593Smuzhiyun m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL;
1234*4882a593Smuzhiyun m88ds3103_pdata.ts_clk = 16000;
1235*4882a593Smuzhiyun m88ds3103_pdata.ts_clk_pol = 0;
1236*4882a593Smuzhiyun m88ds3103_pdata.agc = 0x99;
1237*4882a593Smuzhiyun m88ds3103_pdata.agc_inv = 0;
1238*4882a593Smuzhiyun m88ds3103_pdata.spec_inv = 0;
1239*4882a593Smuzhiyun dvb->i2c_client_demod = dvb_module_probe("m88ds3103", "m88ds3103b",
1240*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1241*4882a593Smuzhiyun 0x6a, &m88ds3103_pdata);
1242*4882a593Smuzhiyun
1243*4882a593Smuzhiyun if (!dvb->i2c_client_demod)
1244*4882a593Smuzhiyun return -ENODEV;
1245*4882a593Smuzhiyun
1246*4882a593Smuzhiyun dvb->fe[0] = m88ds3103_pdata.get_dvb_frontend(dvb->i2c_client_demod);
1247*4882a593Smuzhiyun i2c_adapter = m88ds3103_pdata.get_i2c_adapter(dvb->i2c_client_demod);
1248*4882a593Smuzhiyun
1249*4882a593Smuzhiyun /* attach tuner */
1250*4882a593Smuzhiyun ts2020_config.fe = dvb->fe[0];
1251*4882a593Smuzhiyun dvb->i2c_client_tuner = dvb_module_probe("ts2020", "ts2022",
1252*4882a593Smuzhiyun i2c_adapter,
1253*4882a593Smuzhiyun 0x60, &ts2020_config);
1254*4882a593Smuzhiyun if (!dvb->i2c_client_tuner) {
1255*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_demod);
1256*4882a593Smuzhiyun return -ENODEV;
1257*4882a593Smuzhiyun }
1258*4882a593Smuzhiyun
1259*4882a593Smuzhiyun /* delegate signal strength measurement to tuner */
1260*4882a593Smuzhiyun dvb->fe[0]->ops.read_signal_strength =
1261*4882a593Smuzhiyun dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1262*4882a593Smuzhiyun
1263*4882a593Smuzhiyun /* attach SEC */
1264*4882a593Smuzhiyun a8293_pdata.dvb_frontend = dvb->fe[0];
1265*4882a593Smuzhiyun dvb->i2c_client_sec = dvb_module_probe("a8293", NULL,
1266*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1267*4882a593Smuzhiyun 0x08, &a8293_pdata);
1268*4882a593Smuzhiyun if (!dvb->i2c_client_sec) {
1269*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_tuner);
1270*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_demod);
1271*4882a593Smuzhiyun return -ENODEV;
1272*4882a593Smuzhiyun }
1273*4882a593Smuzhiyun
1274*4882a593Smuzhiyun return 0;
1275*4882a593Smuzhiyun }
1276*4882a593Smuzhiyun
em28178_dvb_init_pctv_292e(struct em28xx * dev)1277*4882a593Smuzhiyun static int em28178_dvb_init_pctv_292e(struct em28xx *dev)
1278*4882a593Smuzhiyun {
1279*4882a593Smuzhiyun struct em28xx_dvb *dvb = dev->dvb;
1280*4882a593Smuzhiyun struct i2c_adapter *adapter;
1281*4882a593Smuzhiyun struct si2168_config si2168_config = {};
1282*4882a593Smuzhiyun struct si2157_config si2157_config = {};
1283*4882a593Smuzhiyun
1284*4882a593Smuzhiyun /* attach demod */
1285*4882a593Smuzhiyun si2168_config.i2c_adapter = &adapter;
1286*4882a593Smuzhiyun si2168_config.fe = &dvb->fe[0];
1287*4882a593Smuzhiyun si2168_config.ts_mode = SI2168_TS_PARALLEL;
1288*4882a593Smuzhiyun si2168_config.spectral_inversion = true;
1289*4882a593Smuzhiyun
1290*4882a593Smuzhiyun dvb->i2c_client_demod = dvb_module_probe("si2168", NULL,
1291*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1292*4882a593Smuzhiyun 0x64, &si2168_config);
1293*4882a593Smuzhiyun if (!dvb->i2c_client_demod)
1294*4882a593Smuzhiyun return -ENODEV;
1295*4882a593Smuzhiyun
1296*4882a593Smuzhiyun /* attach tuner */
1297*4882a593Smuzhiyun si2157_config.fe = dvb->fe[0];
1298*4882a593Smuzhiyun si2157_config.if_port = 1;
1299*4882a593Smuzhiyun #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1300*4882a593Smuzhiyun si2157_config.mdev = dev->media_dev;
1301*4882a593Smuzhiyun #endif
1302*4882a593Smuzhiyun dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL,
1303*4882a593Smuzhiyun adapter,
1304*4882a593Smuzhiyun 0x60, &si2157_config);
1305*4882a593Smuzhiyun if (!dvb->i2c_client_tuner) {
1306*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_demod);
1307*4882a593Smuzhiyun return -ENODEV;
1308*4882a593Smuzhiyun }
1309*4882a593Smuzhiyun dvb->fe[0]->ops.set_lna = em28xx_pctv_292e_set_lna;
1310*4882a593Smuzhiyun
1311*4882a593Smuzhiyun return 0;
1312*4882a593Smuzhiyun }
1313*4882a593Smuzhiyun
em28178_dvb_init_terratec_t2_stick_hd(struct em28xx * dev)1314*4882a593Smuzhiyun static int em28178_dvb_init_terratec_t2_stick_hd(struct em28xx *dev)
1315*4882a593Smuzhiyun {
1316*4882a593Smuzhiyun struct em28xx_dvb *dvb = dev->dvb;
1317*4882a593Smuzhiyun struct i2c_adapter *adapter;
1318*4882a593Smuzhiyun struct si2168_config si2168_config = {};
1319*4882a593Smuzhiyun struct si2157_config si2157_config = {};
1320*4882a593Smuzhiyun
1321*4882a593Smuzhiyun /* attach demod */
1322*4882a593Smuzhiyun si2168_config.i2c_adapter = &adapter;
1323*4882a593Smuzhiyun si2168_config.fe = &dvb->fe[0];
1324*4882a593Smuzhiyun si2168_config.ts_mode = SI2168_TS_PARALLEL;
1325*4882a593Smuzhiyun
1326*4882a593Smuzhiyun dvb->i2c_client_demod = dvb_module_probe("si2168", NULL,
1327*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1328*4882a593Smuzhiyun 0x64, &si2168_config);
1329*4882a593Smuzhiyun if (!dvb->i2c_client_demod)
1330*4882a593Smuzhiyun return -ENODEV;
1331*4882a593Smuzhiyun
1332*4882a593Smuzhiyun /* attach tuner */
1333*4882a593Smuzhiyun memset(&si2157_config, 0, sizeof(si2157_config));
1334*4882a593Smuzhiyun si2157_config.fe = dvb->fe[0];
1335*4882a593Smuzhiyun si2157_config.if_port = 0;
1336*4882a593Smuzhiyun #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1337*4882a593Smuzhiyun si2157_config.mdev = dev->media_dev;
1338*4882a593Smuzhiyun #endif
1339*4882a593Smuzhiyun dvb->i2c_client_tuner = dvb_module_probe("si2157", "si2146",
1340*4882a593Smuzhiyun adapter,
1341*4882a593Smuzhiyun 0x60, &si2157_config);
1342*4882a593Smuzhiyun if (!dvb->i2c_client_tuner) {
1343*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_demod);
1344*4882a593Smuzhiyun return -ENODEV;
1345*4882a593Smuzhiyun }
1346*4882a593Smuzhiyun
1347*4882a593Smuzhiyun return 0;
1348*4882a593Smuzhiyun }
1349*4882a593Smuzhiyun
em28178_dvb_init_plex_px_bcud(struct em28xx * dev)1350*4882a593Smuzhiyun static int em28178_dvb_init_plex_px_bcud(struct em28xx *dev)
1351*4882a593Smuzhiyun {
1352*4882a593Smuzhiyun struct em28xx_dvb *dvb = dev->dvb;
1353*4882a593Smuzhiyun struct tc90522_config tc90522_config = {};
1354*4882a593Smuzhiyun struct qm1d1c0042_config qm1d1c0042_config = {};
1355*4882a593Smuzhiyun
1356*4882a593Smuzhiyun /* attach demod */
1357*4882a593Smuzhiyun dvb->i2c_client_demod = dvb_module_probe("tc90522", "tc90522sat",
1358*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1359*4882a593Smuzhiyun 0x15, &tc90522_config);
1360*4882a593Smuzhiyun if (!dvb->i2c_client_demod)
1361*4882a593Smuzhiyun return -ENODEV;
1362*4882a593Smuzhiyun
1363*4882a593Smuzhiyun /* attach tuner */
1364*4882a593Smuzhiyun qm1d1c0042_config.fe = tc90522_config.fe;
1365*4882a593Smuzhiyun qm1d1c0042_config.lpf = 1;
1366*4882a593Smuzhiyun
1367*4882a593Smuzhiyun dvb->i2c_client_tuner = dvb_module_probe("qm1d1c0042", NULL,
1368*4882a593Smuzhiyun tc90522_config.tuner_i2c,
1369*4882a593Smuzhiyun 0x61, &qm1d1c0042_config);
1370*4882a593Smuzhiyun if (!dvb->i2c_client_tuner) {
1371*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_demod);
1372*4882a593Smuzhiyun return -ENODEV;
1373*4882a593Smuzhiyun }
1374*4882a593Smuzhiyun
1375*4882a593Smuzhiyun dvb->fe[0] = tc90522_config.fe;
1376*4882a593Smuzhiyun px_bcud_init(dev);
1377*4882a593Smuzhiyun
1378*4882a593Smuzhiyun return 0;
1379*4882a593Smuzhiyun }
1380*4882a593Smuzhiyun
em28174_dvb_init_hauppauge_wintv_dualhd_dvb(struct em28xx * dev)1381*4882a593Smuzhiyun static int em28174_dvb_init_hauppauge_wintv_dualhd_dvb(struct em28xx *dev)
1382*4882a593Smuzhiyun {
1383*4882a593Smuzhiyun struct em28xx_dvb *dvb = dev->dvb;
1384*4882a593Smuzhiyun struct i2c_adapter *adapter;
1385*4882a593Smuzhiyun struct si2168_config si2168_config = {};
1386*4882a593Smuzhiyun struct si2157_config si2157_config = {};
1387*4882a593Smuzhiyun unsigned char addr;
1388*4882a593Smuzhiyun
1389*4882a593Smuzhiyun /* attach demod */
1390*4882a593Smuzhiyun si2168_config.i2c_adapter = &adapter;
1391*4882a593Smuzhiyun si2168_config.fe = &dvb->fe[0];
1392*4882a593Smuzhiyun si2168_config.ts_mode = SI2168_TS_SERIAL;
1393*4882a593Smuzhiyun si2168_config.spectral_inversion = true;
1394*4882a593Smuzhiyun addr = (dev->ts == PRIMARY_TS) ? 0x64 : 0x67;
1395*4882a593Smuzhiyun
1396*4882a593Smuzhiyun dvb->i2c_client_demod = dvb_module_probe("si2168", NULL,
1397*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1398*4882a593Smuzhiyun addr, &si2168_config);
1399*4882a593Smuzhiyun if (!dvb->i2c_client_demod)
1400*4882a593Smuzhiyun return -ENODEV;
1401*4882a593Smuzhiyun
1402*4882a593Smuzhiyun /* attach tuner */
1403*4882a593Smuzhiyun memset(&si2157_config, 0, sizeof(si2157_config));
1404*4882a593Smuzhiyun si2157_config.fe = dvb->fe[0];
1405*4882a593Smuzhiyun si2157_config.if_port = 1;
1406*4882a593Smuzhiyun #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1407*4882a593Smuzhiyun si2157_config.mdev = dev->media_dev;
1408*4882a593Smuzhiyun #endif
1409*4882a593Smuzhiyun addr = (dev->ts == PRIMARY_TS) ? 0x60 : 0x63;
1410*4882a593Smuzhiyun
1411*4882a593Smuzhiyun dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL,
1412*4882a593Smuzhiyun adapter,
1413*4882a593Smuzhiyun addr, &si2157_config);
1414*4882a593Smuzhiyun if (!dvb->i2c_client_tuner) {
1415*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_demod);
1416*4882a593Smuzhiyun return -ENODEV;
1417*4882a593Smuzhiyun }
1418*4882a593Smuzhiyun
1419*4882a593Smuzhiyun return 0;
1420*4882a593Smuzhiyun }
1421*4882a593Smuzhiyun
em28174_dvb_init_hauppauge_wintv_dualhd_01595(struct em28xx * dev)1422*4882a593Smuzhiyun static int em28174_dvb_init_hauppauge_wintv_dualhd_01595(struct em28xx *dev)
1423*4882a593Smuzhiyun {
1424*4882a593Smuzhiyun struct em28xx_dvb *dvb = dev->dvb;
1425*4882a593Smuzhiyun struct i2c_adapter *adapter;
1426*4882a593Smuzhiyun struct lgdt3306a_config lgdt3306a_config = {};
1427*4882a593Smuzhiyun struct si2157_config si2157_config = {};
1428*4882a593Smuzhiyun unsigned char addr;
1429*4882a593Smuzhiyun
1430*4882a593Smuzhiyun /* attach demod */
1431*4882a593Smuzhiyun lgdt3306a_config = hauppauge_01595_lgdt3306a_config;
1432*4882a593Smuzhiyun lgdt3306a_config.fe = &dvb->fe[0];
1433*4882a593Smuzhiyun lgdt3306a_config.i2c_adapter = &adapter;
1434*4882a593Smuzhiyun addr = (dev->ts == PRIMARY_TS) ? 0x59 : 0x0e;
1435*4882a593Smuzhiyun
1436*4882a593Smuzhiyun dvb->i2c_client_demod = dvb_module_probe("lgdt3306a", NULL,
1437*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1438*4882a593Smuzhiyun addr, &lgdt3306a_config);
1439*4882a593Smuzhiyun if (!dvb->i2c_client_demod)
1440*4882a593Smuzhiyun return -ENODEV;
1441*4882a593Smuzhiyun
1442*4882a593Smuzhiyun /* attach tuner */
1443*4882a593Smuzhiyun si2157_config.fe = dvb->fe[0];
1444*4882a593Smuzhiyun si2157_config.if_port = 1;
1445*4882a593Smuzhiyun si2157_config.inversion = 1;
1446*4882a593Smuzhiyun #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1447*4882a593Smuzhiyun si2157_config.mdev = dev->media_dev;
1448*4882a593Smuzhiyun #endif
1449*4882a593Smuzhiyun addr = (dev->ts == PRIMARY_TS) ? 0x60 : 0x62;
1450*4882a593Smuzhiyun
1451*4882a593Smuzhiyun dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL,
1452*4882a593Smuzhiyun adapter,
1453*4882a593Smuzhiyun addr, &si2157_config);
1454*4882a593Smuzhiyun if (!dvb->i2c_client_tuner) {
1455*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_demod);
1456*4882a593Smuzhiyun return -ENODEV;
1457*4882a593Smuzhiyun }
1458*4882a593Smuzhiyun
1459*4882a593Smuzhiyun return 0;
1460*4882a593Smuzhiyun }
1461*4882a593Smuzhiyun
em28xx_dvb_init(struct em28xx * dev)1462*4882a593Smuzhiyun static int em28xx_dvb_init(struct em28xx *dev)
1463*4882a593Smuzhiyun {
1464*4882a593Smuzhiyun int result = 0, dvb_alt = 0;
1465*4882a593Smuzhiyun struct em28xx_dvb *dvb;
1466*4882a593Smuzhiyun struct usb_device *udev;
1467*4882a593Smuzhiyun
1468*4882a593Smuzhiyun if (dev->is_audio_only) {
1469*4882a593Smuzhiyun /* Shouldn't initialize IR for this interface */
1470*4882a593Smuzhiyun return 0;
1471*4882a593Smuzhiyun }
1472*4882a593Smuzhiyun
1473*4882a593Smuzhiyun if (!dev->board.has_dvb) {
1474*4882a593Smuzhiyun /* This device does not support the extension */
1475*4882a593Smuzhiyun return 0;
1476*4882a593Smuzhiyun }
1477*4882a593Smuzhiyun
1478*4882a593Smuzhiyun dev_info(&dev->intf->dev, "Binding DVB extension\n");
1479*4882a593Smuzhiyun
1480*4882a593Smuzhiyun dvb = kzalloc(sizeof(*dvb), GFP_KERNEL);
1481*4882a593Smuzhiyun if (!dvb)
1482*4882a593Smuzhiyun return -ENOMEM;
1483*4882a593Smuzhiyun
1484*4882a593Smuzhiyun dev->dvb = dvb;
1485*4882a593Smuzhiyun dvb->fe[0] = NULL;
1486*4882a593Smuzhiyun dvb->fe[1] = NULL;
1487*4882a593Smuzhiyun
1488*4882a593Smuzhiyun /* pre-allocate DVB usb transfer buffers */
1489*4882a593Smuzhiyun if (dev->dvb_xfer_bulk) {
1490*4882a593Smuzhiyun result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
1491*4882a593Smuzhiyun dev->dvb_xfer_bulk,
1492*4882a593Smuzhiyun EM28XX_DVB_NUM_BUFS,
1493*4882a593Smuzhiyun 512,
1494*4882a593Smuzhiyun EM28XX_DVB_BULK_PACKET_MULTIPLIER);
1495*4882a593Smuzhiyun } else {
1496*4882a593Smuzhiyun result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
1497*4882a593Smuzhiyun dev->dvb_xfer_bulk,
1498*4882a593Smuzhiyun EM28XX_DVB_NUM_BUFS,
1499*4882a593Smuzhiyun dev->dvb_max_pkt_size_isoc,
1500*4882a593Smuzhiyun EM28XX_DVB_NUM_ISOC_PACKETS);
1501*4882a593Smuzhiyun }
1502*4882a593Smuzhiyun if (result) {
1503*4882a593Smuzhiyun dev_err(&dev->intf->dev,
1504*4882a593Smuzhiyun "failed to pre-allocate USB transfer buffers for DVB.\n");
1505*4882a593Smuzhiyun kfree(dvb);
1506*4882a593Smuzhiyun dev->dvb = NULL;
1507*4882a593Smuzhiyun return result;
1508*4882a593Smuzhiyun }
1509*4882a593Smuzhiyun
1510*4882a593Smuzhiyun mutex_lock(&dev->lock);
1511*4882a593Smuzhiyun em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
1512*4882a593Smuzhiyun /* init frontend */
1513*4882a593Smuzhiyun switch (dev->model) {
1514*4882a593Smuzhiyun case EM2874_BOARD_LEADERSHIP_ISDBT:
1515*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(s921_attach,
1516*4882a593Smuzhiyun &sharp_isdbt,
1517*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1518*4882a593Smuzhiyun
1519*4882a593Smuzhiyun if (!dvb->fe[0]) {
1520*4882a593Smuzhiyun result = -EINVAL;
1521*4882a593Smuzhiyun goto out_free;
1522*4882a593Smuzhiyun }
1523*4882a593Smuzhiyun
1524*4882a593Smuzhiyun break;
1525*4882a593Smuzhiyun case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
1526*4882a593Smuzhiyun case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
1527*4882a593Smuzhiyun case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
1528*4882a593Smuzhiyun case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
1529*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(lgdt330x_attach,
1530*4882a593Smuzhiyun &em2880_lgdt3303_dev,
1531*4882a593Smuzhiyun 0x0e,
1532*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1533*4882a593Smuzhiyun if (em28xx_attach_xc3028(0x61, dev) < 0) {
1534*4882a593Smuzhiyun result = -EINVAL;
1535*4882a593Smuzhiyun goto out_free;
1536*4882a593Smuzhiyun }
1537*4882a593Smuzhiyun break;
1538*4882a593Smuzhiyun case EM2880_BOARD_KWORLD_DVB_310U:
1539*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(zl10353_attach,
1540*4882a593Smuzhiyun &em28xx_zl10353_with_xc3028,
1541*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1542*4882a593Smuzhiyun if (em28xx_attach_xc3028(0x61, dev) < 0) {
1543*4882a593Smuzhiyun result = -EINVAL;
1544*4882a593Smuzhiyun goto out_free;
1545*4882a593Smuzhiyun }
1546*4882a593Smuzhiyun break;
1547*4882a593Smuzhiyun case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
1548*4882a593Smuzhiyun case EM2882_BOARD_TERRATEC_HYBRID_XS:
1549*4882a593Smuzhiyun case EM2880_BOARD_EMPIRE_DUAL_TV:
1550*4882a593Smuzhiyun case EM2882_BOARD_ZOLID_HYBRID_TV_STICK:
1551*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(zl10353_attach,
1552*4882a593Smuzhiyun &em28xx_zl10353_xc3028_no_i2c_gate,
1553*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1554*4882a593Smuzhiyun if (em28xx_attach_xc3028(0x61, dev) < 0) {
1555*4882a593Smuzhiyun result = -EINVAL;
1556*4882a593Smuzhiyun goto out_free;
1557*4882a593Smuzhiyun }
1558*4882a593Smuzhiyun break;
1559*4882a593Smuzhiyun case EM2880_BOARD_TERRATEC_HYBRID_XS:
1560*4882a593Smuzhiyun case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
1561*4882a593Smuzhiyun case EM2881_BOARD_PINNACLE_HYBRID_PRO:
1562*4882a593Smuzhiyun case EM2882_BOARD_DIKOM_DK300:
1563*4882a593Smuzhiyun case EM2882_BOARD_KWORLD_VS_DVBT:
1564*4882a593Smuzhiyun /*
1565*4882a593Smuzhiyun * Those boards could have either a zl10353 or a mt352.
1566*4882a593Smuzhiyun * If the chip id isn't for zl10353, try mt352.
1567*4882a593Smuzhiyun */
1568*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(zl10353_attach,
1569*4882a593Smuzhiyun &em28xx_zl10353_xc3028_no_i2c_gate,
1570*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1571*4882a593Smuzhiyun if (!dvb->fe[0])
1572*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(mt352_attach,
1573*4882a593Smuzhiyun &terratec_xs_mt352_cfg,
1574*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1575*4882a593Smuzhiyun
1576*4882a593Smuzhiyun if (em28xx_attach_xc3028(0x61, dev) < 0) {
1577*4882a593Smuzhiyun result = -EINVAL;
1578*4882a593Smuzhiyun goto out_free;
1579*4882a593Smuzhiyun }
1580*4882a593Smuzhiyun break;
1581*4882a593Smuzhiyun case EM2870_BOARD_TERRATEC_XS_MT2060:
1582*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(zl10353_attach,
1583*4882a593Smuzhiyun &em28xx_zl10353_no_i2c_gate_dev,
1584*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1585*4882a593Smuzhiyun if (dvb->fe[0]) {
1586*4882a593Smuzhiyun dvb_attach(mt2060_attach, dvb->fe[0],
1587*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1588*4882a593Smuzhiyun &em28xx_mt2060_config, 1220);
1589*4882a593Smuzhiyun }
1590*4882a593Smuzhiyun break;
1591*4882a593Smuzhiyun case EM2870_BOARD_KWORLD_355U:
1592*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(zl10353_attach,
1593*4882a593Smuzhiyun &em28xx_zl10353_no_i2c_gate_dev,
1594*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1595*4882a593Smuzhiyun if (dvb->fe[0])
1596*4882a593Smuzhiyun dvb_attach(qt1010_attach, dvb->fe[0],
1597*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1598*4882a593Smuzhiyun &em28xx_qt1010_config);
1599*4882a593Smuzhiyun break;
1600*4882a593Smuzhiyun case EM2883_BOARD_KWORLD_HYBRID_330U:
1601*4882a593Smuzhiyun case EM2882_BOARD_EVGA_INDTUBE:
1602*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(s5h1409_attach,
1603*4882a593Smuzhiyun &em28xx_s5h1409_with_xc3028,
1604*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1605*4882a593Smuzhiyun if (em28xx_attach_xc3028(0x61, dev) < 0) {
1606*4882a593Smuzhiyun result = -EINVAL;
1607*4882a593Smuzhiyun goto out_free;
1608*4882a593Smuzhiyun }
1609*4882a593Smuzhiyun break;
1610*4882a593Smuzhiyun case EM2882_BOARD_KWORLD_ATSC_315U:
1611*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(lgdt330x_attach,
1612*4882a593Smuzhiyun &em2880_lgdt3303_dev,
1613*4882a593Smuzhiyun 0x0e,
1614*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1615*4882a593Smuzhiyun if (dvb->fe[0]) {
1616*4882a593Smuzhiyun if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1617*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1618*4882a593Smuzhiyun 0x61, TUNER_THOMSON_DTT761X)) {
1619*4882a593Smuzhiyun result = -EINVAL;
1620*4882a593Smuzhiyun goto out_free;
1621*4882a593Smuzhiyun }
1622*4882a593Smuzhiyun }
1623*4882a593Smuzhiyun break;
1624*4882a593Smuzhiyun case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
1625*4882a593Smuzhiyun case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
1626*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
1627*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1628*4882a593Smuzhiyun &dev->intf->dev);
1629*4882a593Smuzhiyun if (em28xx_attach_xc3028(0x61, dev) < 0) {
1630*4882a593Smuzhiyun result = -EINVAL;
1631*4882a593Smuzhiyun goto out_free;
1632*4882a593Smuzhiyun }
1633*4882a593Smuzhiyun break;
1634*4882a593Smuzhiyun case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
1635*4882a593Smuzhiyun /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
1636*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(tda10023_attach,
1637*4882a593Smuzhiyun &em28xx_tda10023_config,
1638*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1639*4882a593Smuzhiyun 0x48);
1640*4882a593Smuzhiyun if (dvb->fe[0]) {
1641*4882a593Smuzhiyun if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1642*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1643*4882a593Smuzhiyun 0x60, TUNER_PHILIPS_CU1216L)) {
1644*4882a593Smuzhiyun result = -EINVAL;
1645*4882a593Smuzhiyun goto out_free;
1646*4882a593Smuzhiyun }
1647*4882a593Smuzhiyun }
1648*4882a593Smuzhiyun break;
1649*4882a593Smuzhiyun case EM2870_BOARD_KWORLD_A340:
1650*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(lgdt3305_attach,
1651*4882a593Smuzhiyun &em2870_lgdt3304_dev,
1652*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1653*4882a593Smuzhiyun if (!dvb->fe[0]) {
1654*4882a593Smuzhiyun result = -EINVAL;
1655*4882a593Smuzhiyun goto out_free;
1656*4882a593Smuzhiyun }
1657*4882a593Smuzhiyun if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1658*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1659*4882a593Smuzhiyun &kworld_a340_config)) {
1660*4882a593Smuzhiyun dvb_frontend_detach(dvb->fe[0]);
1661*4882a593Smuzhiyun result = -EINVAL;
1662*4882a593Smuzhiyun goto out_free;
1663*4882a593Smuzhiyun }
1664*4882a593Smuzhiyun break;
1665*4882a593Smuzhiyun case EM28174_BOARD_PCTV_290E:
1666*4882a593Smuzhiyun /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1667*4882a593Smuzhiyun dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
1668*4882a593Smuzhiyun CXD2820R_GPIO_L;
1669*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(cxd2820r_attach,
1670*4882a593Smuzhiyun &em28xx_cxd2820r_config,
1671*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1672*4882a593Smuzhiyun &dvb->lna_gpio);
1673*4882a593Smuzhiyun if (dvb->fe[0]) {
1674*4882a593Smuzhiyun /* FE 0 attach tuner */
1675*4882a593Smuzhiyun if (!dvb_attach(tda18271_attach,
1676*4882a593Smuzhiyun dvb->fe[0],
1677*4882a593Smuzhiyun 0x60,
1678*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1679*4882a593Smuzhiyun &em28xx_cxd2820r_tda18271_config)) {
1680*4882a593Smuzhiyun dvb_frontend_detach(dvb->fe[0]);
1681*4882a593Smuzhiyun result = -EINVAL;
1682*4882a593Smuzhiyun goto out_free;
1683*4882a593Smuzhiyun }
1684*4882a593Smuzhiyun
1685*4882a593Smuzhiyun #ifdef CONFIG_GPIOLIB
1686*4882a593Smuzhiyun /* enable LNA for DVB-T, DVB-T2 and DVB-C */
1687*4882a593Smuzhiyun result = gpio_request_one(dvb->lna_gpio,
1688*4882a593Smuzhiyun GPIOF_OUT_INIT_LOW, NULL);
1689*4882a593Smuzhiyun if (result)
1690*4882a593Smuzhiyun dev_err(&dev->intf->dev,
1691*4882a593Smuzhiyun "gpio request failed %d\n",
1692*4882a593Smuzhiyun result);
1693*4882a593Smuzhiyun else
1694*4882a593Smuzhiyun gpio_free(dvb->lna_gpio);
1695*4882a593Smuzhiyun
1696*4882a593Smuzhiyun result = 0; /* continue even set LNA fails */
1697*4882a593Smuzhiyun #endif
1698*4882a593Smuzhiyun dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
1699*4882a593Smuzhiyun }
1700*4882a593Smuzhiyun
1701*4882a593Smuzhiyun break;
1702*4882a593Smuzhiyun case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
1703*4882a593Smuzhiyun {
1704*4882a593Smuzhiyun struct xc5000_config cfg = {};
1705*4882a593Smuzhiyun
1706*4882a593Smuzhiyun hauppauge_hvr930c_init(dev);
1707*4882a593Smuzhiyun
1708*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(drxk_attach,
1709*4882a593Smuzhiyun &hauppauge_930c_drxk,
1710*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1711*4882a593Smuzhiyun if (!dvb->fe[0]) {
1712*4882a593Smuzhiyun result = -EINVAL;
1713*4882a593Smuzhiyun goto out_free;
1714*4882a593Smuzhiyun }
1715*4882a593Smuzhiyun /* FIXME: do we need a pll semaphore? */
1716*4882a593Smuzhiyun dvb->fe[0]->sec_priv = dvb;
1717*4882a593Smuzhiyun sema_init(&dvb->pll_mutex, 1);
1718*4882a593Smuzhiyun dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1719*4882a593Smuzhiyun dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1720*4882a593Smuzhiyun
1721*4882a593Smuzhiyun /* Attach xc5000 */
1722*4882a593Smuzhiyun cfg.i2c_address = 0x61;
1723*4882a593Smuzhiyun cfg.if_khz = 4000;
1724*4882a593Smuzhiyun
1725*4882a593Smuzhiyun if (dvb->fe[0]->ops.i2c_gate_ctrl)
1726*4882a593Smuzhiyun dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1727*4882a593Smuzhiyun if (!dvb_attach(xc5000_attach, dvb->fe[0],
1728*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus], &cfg)) {
1729*4882a593Smuzhiyun result = -EINVAL;
1730*4882a593Smuzhiyun goto out_free;
1731*4882a593Smuzhiyun }
1732*4882a593Smuzhiyun if (dvb->fe[0]->ops.i2c_gate_ctrl)
1733*4882a593Smuzhiyun dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1734*4882a593Smuzhiyun
1735*4882a593Smuzhiyun break;
1736*4882a593Smuzhiyun }
1737*4882a593Smuzhiyun case EM2884_BOARD_TERRATEC_H5:
1738*4882a593Smuzhiyun terratec_h5_init(dev);
1739*4882a593Smuzhiyun
1740*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk,
1741*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1742*4882a593Smuzhiyun if (!dvb->fe[0]) {
1743*4882a593Smuzhiyun result = -EINVAL;
1744*4882a593Smuzhiyun goto out_free;
1745*4882a593Smuzhiyun }
1746*4882a593Smuzhiyun /* FIXME: do we need a pll semaphore? */
1747*4882a593Smuzhiyun dvb->fe[0]->sec_priv = dvb;
1748*4882a593Smuzhiyun sema_init(&dvb->pll_mutex, 1);
1749*4882a593Smuzhiyun dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1750*4882a593Smuzhiyun dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1751*4882a593Smuzhiyun
1752*4882a593Smuzhiyun /* Attach tda18271 to DVB-C frontend */
1753*4882a593Smuzhiyun if (dvb->fe[0]->ops.i2c_gate_ctrl)
1754*4882a593Smuzhiyun dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1755*4882a593Smuzhiyun if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0],
1756*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
1757*4882a593Smuzhiyun result = -EINVAL;
1758*4882a593Smuzhiyun goto out_free;
1759*4882a593Smuzhiyun }
1760*4882a593Smuzhiyun if (dvb->fe[0]->ops.i2c_gate_ctrl)
1761*4882a593Smuzhiyun dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1762*4882a593Smuzhiyun
1763*4882a593Smuzhiyun break;
1764*4882a593Smuzhiyun case EM2884_BOARD_C3TECH_DIGITAL_DUO:
1765*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(mb86a20s_attach,
1766*4882a593Smuzhiyun &c3tech_duo_mb86a20s_config,
1767*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1768*4882a593Smuzhiyun if (dvb->fe[0])
1769*4882a593Smuzhiyun dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1770*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1771*4882a593Smuzhiyun &c3tech_duo_tda18271_config);
1772*4882a593Smuzhiyun break;
1773*4882a593Smuzhiyun case EM28174_BOARD_PCTV_460E:
1774*4882a593Smuzhiyun result = em28174_dvb_init_pctv_460e(dev);
1775*4882a593Smuzhiyun if (result)
1776*4882a593Smuzhiyun goto out_free;
1777*4882a593Smuzhiyun break;
1778*4882a593Smuzhiyun case EM2874_BOARD_DELOCK_61959:
1779*4882a593Smuzhiyun case EM2874_BOARD_MAXMEDIA_UB425_TC:
1780*4882a593Smuzhiyun /* attach demodulator */
1781*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
1782*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1783*4882a593Smuzhiyun
1784*4882a593Smuzhiyun if (dvb->fe[0]) {
1785*4882a593Smuzhiyun /* disable I2C-gate */
1786*4882a593Smuzhiyun dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1787*4882a593Smuzhiyun
1788*4882a593Smuzhiyun /* attach tuner */
1789*4882a593Smuzhiyun if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1790*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1791*4882a593Smuzhiyun &em28xx_cxd2820r_tda18271_config)) {
1792*4882a593Smuzhiyun dvb_frontend_detach(dvb->fe[0]);
1793*4882a593Smuzhiyun result = -EINVAL;
1794*4882a593Smuzhiyun goto out_free;
1795*4882a593Smuzhiyun }
1796*4882a593Smuzhiyun }
1797*4882a593Smuzhiyun break;
1798*4882a593Smuzhiyun case EM2884_BOARD_PCTV_510E:
1799*4882a593Smuzhiyun case EM2884_BOARD_PCTV_520E:
1800*4882a593Smuzhiyun pctv_520e_init(dev);
1801*4882a593Smuzhiyun
1802*4882a593Smuzhiyun /* attach demodulator */
1803*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
1804*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1805*4882a593Smuzhiyun
1806*4882a593Smuzhiyun if (dvb->fe[0]) {
1807*4882a593Smuzhiyun /* attach tuner */
1808*4882a593Smuzhiyun if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1809*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1810*4882a593Smuzhiyun &em28xx_cxd2820r_tda18271_config)) {
1811*4882a593Smuzhiyun dvb_frontend_detach(dvb->fe[0]);
1812*4882a593Smuzhiyun result = -EINVAL;
1813*4882a593Smuzhiyun goto out_free;
1814*4882a593Smuzhiyun }
1815*4882a593Smuzhiyun }
1816*4882a593Smuzhiyun break;
1817*4882a593Smuzhiyun case EM2884_BOARD_ELGATO_EYETV_HYBRID_2008:
1818*4882a593Smuzhiyun case EM2884_BOARD_CINERGY_HTC_STICK:
1819*4882a593Smuzhiyun case EM2884_BOARD_TERRATEC_H6:
1820*4882a593Smuzhiyun terratec_htc_stick_init(dev);
1821*4882a593Smuzhiyun
1822*4882a593Smuzhiyun /* attach demodulator */
1823*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1824*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1825*4882a593Smuzhiyun if (!dvb->fe[0]) {
1826*4882a593Smuzhiyun result = -EINVAL;
1827*4882a593Smuzhiyun goto out_free;
1828*4882a593Smuzhiyun }
1829*4882a593Smuzhiyun
1830*4882a593Smuzhiyun /* Attach the demodulator. */
1831*4882a593Smuzhiyun if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1832*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1833*4882a593Smuzhiyun &em28xx_cxd2820r_tda18271_config)) {
1834*4882a593Smuzhiyun result = -EINVAL;
1835*4882a593Smuzhiyun goto out_free;
1836*4882a593Smuzhiyun }
1837*4882a593Smuzhiyun break;
1838*4882a593Smuzhiyun case EM2884_BOARD_TERRATEC_HTC_USB_XS:
1839*4882a593Smuzhiyun terratec_htc_usb_xs_init(dev);
1840*4882a593Smuzhiyun
1841*4882a593Smuzhiyun /* attach demodulator */
1842*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1843*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1844*4882a593Smuzhiyun if (!dvb->fe[0]) {
1845*4882a593Smuzhiyun result = -EINVAL;
1846*4882a593Smuzhiyun goto out_free;
1847*4882a593Smuzhiyun }
1848*4882a593Smuzhiyun
1849*4882a593Smuzhiyun /* Attach the demodulator. */
1850*4882a593Smuzhiyun if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1851*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1852*4882a593Smuzhiyun &em28xx_cxd2820r_tda18271_config)) {
1853*4882a593Smuzhiyun result = -EINVAL;
1854*4882a593Smuzhiyun goto out_free;
1855*4882a593Smuzhiyun }
1856*4882a593Smuzhiyun break;
1857*4882a593Smuzhiyun case EM2874_BOARD_KWORLD_UB435Q_V2:
1858*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(lgdt3305_attach,
1859*4882a593Smuzhiyun &em2874_lgdt3305_dev,
1860*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1861*4882a593Smuzhiyun if (!dvb->fe[0]) {
1862*4882a593Smuzhiyun result = -EINVAL;
1863*4882a593Smuzhiyun goto out_free;
1864*4882a593Smuzhiyun }
1865*4882a593Smuzhiyun
1866*4882a593Smuzhiyun /* Attach the demodulator. */
1867*4882a593Smuzhiyun if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1868*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1869*4882a593Smuzhiyun &kworld_ub435q_v2_config)) {
1870*4882a593Smuzhiyun result = -EINVAL;
1871*4882a593Smuzhiyun goto out_free;
1872*4882a593Smuzhiyun }
1873*4882a593Smuzhiyun break;
1874*4882a593Smuzhiyun case EM2874_BOARD_KWORLD_UB435Q_V3:
1875*4882a593Smuzhiyun {
1876*4882a593Smuzhiyun struct i2c_adapter *adapter = &dev->i2c_adap[dev->def_i2c_bus];
1877*4882a593Smuzhiyun
1878*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(lgdt3305_attach,
1879*4882a593Smuzhiyun &em2874_lgdt3305_nogate_dev,
1880*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1881*4882a593Smuzhiyun if (!dvb->fe[0]) {
1882*4882a593Smuzhiyun result = -EINVAL;
1883*4882a593Smuzhiyun goto out_free;
1884*4882a593Smuzhiyun }
1885*4882a593Smuzhiyun
1886*4882a593Smuzhiyun /* attach tuner */
1887*4882a593Smuzhiyun kworld_ub435q_v3_config.fe = dvb->fe[0];
1888*4882a593Smuzhiyun
1889*4882a593Smuzhiyun dvb->i2c_client_tuner = dvb_module_probe("tda18212", NULL,
1890*4882a593Smuzhiyun adapter, 0x60,
1891*4882a593Smuzhiyun &kworld_ub435q_v3_config);
1892*4882a593Smuzhiyun if (!dvb->i2c_client_tuner) {
1893*4882a593Smuzhiyun dvb_frontend_detach(dvb->fe[0]);
1894*4882a593Smuzhiyun result = -ENODEV;
1895*4882a593Smuzhiyun goto out_free;
1896*4882a593Smuzhiyun }
1897*4882a593Smuzhiyun break;
1898*4882a593Smuzhiyun }
1899*4882a593Smuzhiyun case EM2874_BOARD_PCTV_HD_MINI_80E:
1900*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(drx39xxj_attach,
1901*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus]);
1902*4882a593Smuzhiyun if (dvb->fe[0]) {
1903*4882a593Smuzhiyun dvb->fe[0] = dvb_attach(tda18271_attach, dvb->fe[0],
1904*4882a593Smuzhiyun 0x60,
1905*4882a593Smuzhiyun &dev->i2c_adap[dev->def_i2c_bus],
1906*4882a593Smuzhiyun &pinnacle_80e_dvb_config);
1907*4882a593Smuzhiyun if (!dvb->fe[0]) {
1908*4882a593Smuzhiyun result = -EINVAL;
1909*4882a593Smuzhiyun goto out_free;
1910*4882a593Smuzhiyun }
1911*4882a593Smuzhiyun }
1912*4882a593Smuzhiyun break;
1913*4882a593Smuzhiyun case EM28178_BOARD_PCTV_461E:
1914*4882a593Smuzhiyun result = em28178_dvb_init_pctv_461e(dev);
1915*4882a593Smuzhiyun if (result)
1916*4882a593Smuzhiyun goto out_free;
1917*4882a593Smuzhiyun break;
1918*4882a593Smuzhiyun case EM28178_BOARD_PCTV_461E_V2:
1919*4882a593Smuzhiyun result = em28178_dvb_init_pctv_461e_v2(dev);
1920*4882a593Smuzhiyun if (result)
1921*4882a593Smuzhiyun goto out_free;
1922*4882a593Smuzhiyun break;
1923*4882a593Smuzhiyun case EM28178_BOARD_PCTV_292E:
1924*4882a593Smuzhiyun result = em28178_dvb_init_pctv_292e(dev);
1925*4882a593Smuzhiyun if (result)
1926*4882a593Smuzhiyun goto out_free;
1927*4882a593Smuzhiyun break;
1928*4882a593Smuzhiyun case EM28178_BOARD_TERRATEC_T2_STICK_HD:
1929*4882a593Smuzhiyun result = em28178_dvb_init_terratec_t2_stick_hd(dev);
1930*4882a593Smuzhiyun if (result)
1931*4882a593Smuzhiyun goto out_free;
1932*4882a593Smuzhiyun break;
1933*4882a593Smuzhiyun case EM28178_BOARD_PLEX_PX_BCUD:
1934*4882a593Smuzhiyun result = em28178_dvb_init_plex_px_bcud(dev);
1935*4882a593Smuzhiyun if (result)
1936*4882a593Smuzhiyun goto out_free;
1937*4882a593Smuzhiyun break;
1938*4882a593Smuzhiyun case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB:
1939*4882a593Smuzhiyun result = em28174_dvb_init_hauppauge_wintv_dualhd_dvb(dev);
1940*4882a593Smuzhiyun if (result)
1941*4882a593Smuzhiyun goto out_free;
1942*4882a593Smuzhiyun break;
1943*4882a593Smuzhiyun case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595:
1944*4882a593Smuzhiyun result = em28174_dvb_init_hauppauge_wintv_dualhd_01595(dev);
1945*4882a593Smuzhiyun if (result)
1946*4882a593Smuzhiyun goto out_free;
1947*4882a593Smuzhiyun break;
1948*4882a593Smuzhiyun default:
1949*4882a593Smuzhiyun dev_err(&dev->intf->dev,
1950*4882a593Smuzhiyun "The frontend of your DVB/ATSC card isn't supported yet\n");
1951*4882a593Smuzhiyun break;
1952*4882a593Smuzhiyun }
1953*4882a593Smuzhiyun if (!dvb->fe[0]) {
1954*4882a593Smuzhiyun dev_err(&dev->intf->dev, "frontend initialization failed\n");
1955*4882a593Smuzhiyun result = -EINVAL;
1956*4882a593Smuzhiyun goto out_free;
1957*4882a593Smuzhiyun }
1958*4882a593Smuzhiyun /* define general-purpose callback pointer */
1959*4882a593Smuzhiyun dvb->fe[0]->callback = em28xx_tuner_callback;
1960*4882a593Smuzhiyun if (dvb->fe[1])
1961*4882a593Smuzhiyun dvb->fe[1]->callback = em28xx_tuner_callback;
1962*4882a593Smuzhiyun
1963*4882a593Smuzhiyun /* register everything */
1964*4882a593Smuzhiyun result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->intf->dev);
1965*4882a593Smuzhiyun
1966*4882a593Smuzhiyun if (result < 0)
1967*4882a593Smuzhiyun goto out_free;
1968*4882a593Smuzhiyun
1969*4882a593Smuzhiyun if (dev->dvb_xfer_bulk) {
1970*4882a593Smuzhiyun dvb_alt = 0;
1971*4882a593Smuzhiyun } else { /* isoc */
1972*4882a593Smuzhiyun dvb_alt = dev->dvb_alt_isoc;
1973*4882a593Smuzhiyun }
1974*4882a593Smuzhiyun
1975*4882a593Smuzhiyun udev = interface_to_usbdev(dev->intf);
1976*4882a593Smuzhiyun usb_set_interface(udev, dev->ifnum, dvb_alt);
1977*4882a593Smuzhiyun dev_info(&dev->intf->dev, "DVB extension successfully initialized\n");
1978*4882a593Smuzhiyun
1979*4882a593Smuzhiyun kref_get(&dev->ref);
1980*4882a593Smuzhiyun
1981*4882a593Smuzhiyun ret:
1982*4882a593Smuzhiyun em28xx_set_mode(dev, EM28XX_SUSPEND);
1983*4882a593Smuzhiyun mutex_unlock(&dev->lock);
1984*4882a593Smuzhiyun return result;
1985*4882a593Smuzhiyun
1986*4882a593Smuzhiyun out_free:
1987*4882a593Smuzhiyun em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
1988*4882a593Smuzhiyun kfree(dvb);
1989*4882a593Smuzhiyun dev->dvb = NULL;
1990*4882a593Smuzhiyun goto ret;
1991*4882a593Smuzhiyun }
1992*4882a593Smuzhiyun
prevent_sleep(struct dvb_frontend_ops * ops)1993*4882a593Smuzhiyun static inline void prevent_sleep(struct dvb_frontend_ops *ops)
1994*4882a593Smuzhiyun {
1995*4882a593Smuzhiyun ops->set_voltage = NULL;
1996*4882a593Smuzhiyun ops->sleep = NULL;
1997*4882a593Smuzhiyun ops->tuner_ops.sleep = NULL;
1998*4882a593Smuzhiyun }
1999*4882a593Smuzhiyun
em28xx_dvb_fini(struct em28xx * dev)2000*4882a593Smuzhiyun static int em28xx_dvb_fini(struct em28xx *dev)
2001*4882a593Smuzhiyun {
2002*4882a593Smuzhiyun struct em28xx_dvb *dvb;
2003*4882a593Smuzhiyun
2004*4882a593Smuzhiyun if (dev->is_audio_only) {
2005*4882a593Smuzhiyun /* Shouldn't initialize IR for this interface */
2006*4882a593Smuzhiyun return 0;
2007*4882a593Smuzhiyun }
2008*4882a593Smuzhiyun
2009*4882a593Smuzhiyun if (!dev->board.has_dvb) {
2010*4882a593Smuzhiyun /* This device does not support the extension */
2011*4882a593Smuzhiyun return 0;
2012*4882a593Smuzhiyun }
2013*4882a593Smuzhiyun
2014*4882a593Smuzhiyun if (!dev->dvb)
2015*4882a593Smuzhiyun return 0;
2016*4882a593Smuzhiyun
2017*4882a593Smuzhiyun dev_info(&dev->intf->dev, "Closing DVB extension\n");
2018*4882a593Smuzhiyun
2019*4882a593Smuzhiyun dvb = dev->dvb;
2020*4882a593Smuzhiyun
2021*4882a593Smuzhiyun em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
2022*4882a593Smuzhiyun
2023*4882a593Smuzhiyun if (dev->disconnected) {
2024*4882a593Smuzhiyun /*
2025*4882a593Smuzhiyun * We cannot tell the device to sleep
2026*4882a593Smuzhiyun * once it has been unplugged.
2027*4882a593Smuzhiyun */
2028*4882a593Smuzhiyun if (dvb->fe[0]) {
2029*4882a593Smuzhiyun prevent_sleep(&dvb->fe[0]->ops);
2030*4882a593Smuzhiyun dvb->fe[0]->exit = DVB_FE_DEVICE_REMOVED;
2031*4882a593Smuzhiyun }
2032*4882a593Smuzhiyun if (dvb->fe[1]) {
2033*4882a593Smuzhiyun prevent_sleep(&dvb->fe[1]->ops);
2034*4882a593Smuzhiyun dvb->fe[1]->exit = DVB_FE_DEVICE_REMOVED;
2035*4882a593Smuzhiyun }
2036*4882a593Smuzhiyun }
2037*4882a593Smuzhiyun
2038*4882a593Smuzhiyun em28xx_unregister_dvb(dvb);
2039*4882a593Smuzhiyun
2040*4882a593Smuzhiyun /* release I2C module bindings */
2041*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_sec);
2042*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_tuner);
2043*4882a593Smuzhiyun dvb_module_release(dvb->i2c_client_demod);
2044*4882a593Smuzhiyun
2045*4882a593Smuzhiyun kfree(dvb);
2046*4882a593Smuzhiyun dev->dvb = NULL;
2047*4882a593Smuzhiyun kref_put(&dev->ref, em28xx_free_device);
2048*4882a593Smuzhiyun
2049*4882a593Smuzhiyun return 0;
2050*4882a593Smuzhiyun }
2051*4882a593Smuzhiyun
em28xx_dvb_suspend(struct em28xx * dev)2052*4882a593Smuzhiyun static int em28xx_dvb_suspend(struct em28xx *dev)
2053*4882a593Smuzhiyun {
2054*4882a593Smuzhiyun int ret = 0;
2055*4882a593Smuzhiyun
2056*4882a593Smuzhiyun if (dev->is_audio_only)
2057*4882a593Smuzhiyun return 0;
2058*4882a593Smuzhiyun
2059*4882a593Smuzhiyun if (!dev->board.has_dvb)
2060*4882a593Smuzhiyun return 0;
2061*4882a593Smuzhiyun
2062*4882a593Smuzhiyun dev_info(&dev->intf->dev, "Suspending DVB extension\n");
2063*4882a593Smuzhiyun if (dev->dvb) {
2064*4882a593Smuzhiyun struct em28xx_dvb *dvb = dev->dvb;
2065*4882a593Smuzhiyun
2066*4882a593Smuzhiyun if (dvb->fe[0]) {
2067*4882a593Smuzhiyun ret = dvb_frontend_suspend(dvb->fe[0]);
2068*4882a593Smuzhiyun dev_info(&dev->intf->dev, "fe0 suspend %d\n", ret);
2069*4882a593Smuzhiyun }
2070*4882a593Smuzhiyun if (dvb->fe[1]) {
2071*4882a593Smuzhiyun dvb_frontend_suspend(dvb->fe[1]);
2072*4882a593Smuzhiyun dev_info(&dev->intf->dev, "fe1 suspend %d\n", ret);
2073*4882a593Smuzhiyun }
2074*4882a593Smuzhiyun }
2075*4882a593Smuzhiyun
2076*4882a593Smuzhiyun return 0;
2077*4882a593Smuzhiyun }
2078*4882a593Smuzhiyun
em28xx_dvb_resume(struct em28xx * dev)2079*4882a593Smuzhiyun static int em28xx_dvb_resume(struct em28xx *dev)
2080*4882a593Smuzhiyun {
2081*4882a593Smuzhiyun int ret = 0;
2082*4882a593Smuzhiyun
2083*4882a593Smuzhiyun if (dev->is_audio_only)
2084*4882a593Smuzhiyun return 0;
2085*4882a593Smuzhiyun
2086*4882a593Smuzhiyun if (!dev->board.has_dvb)
2087*4882a593Smuzhiyun return 0;
2088*4882a593Smuzhiyun
2089*4882a593Smuzhiyun dev_info(&dev->intf->dev, "Resuming DVB extension\n");
2090*4882a593Smuzhiyun if (dev->dvb) {
2091*4882a593Smuzhiyun struct em28xx_dvb *dvb = dev->dvb;
2092*4882a593Smuzhiyun
2093*4882a593Smuzhiyun if (dvb->fe[0]) {
2094*4882a593Smuzhiyun ret = dvb_frontend_resume(dvb->fe[0]);
2095*4882a593Smuzhiyun dev_info(&dev->intf->dev, "fe0 resume %d\n", ret);
2096*4882a593Smuzhiyun }
2097*4882a593Smuzhiyun
2098*4882a593Smuzhiyun if (dvb->fe[1]) {
2099*4882a593Smuzhiyun ret = dvb_frontend_resume(dvb->fe[1]);
2100*4882a593Smuzhiyun dev_info(&dev->intf->dev, "fe1 resume %d\n", ret);
2101*4882a593Smuzhiyun }
2102*4882a593Smuzhiyun }
2103*4882a593Smuzhiyun
2104*4882a593Smuzhiyun return 0;
2105*4882a593Smuzhiyun }
2106*4882a593Smuzhiyun
2107*4882a593Smuzhiyun static struct em28xx_ops dvb_ops = {
2108*4882a593Smuzhiyun .id = EM28XX_DVB,
2109*4882a593Smuzhiyun .name = "Em28xx dvb Extension",
2110*4882a593Smuzhiyun .init = em28xx_dvb_init,
2111*4882a593Smuzhiyun .fini = em28xx_dvb_fini,
2112*4882a593Smuzhiyun .suspend = em28xx_dvb_suspend,
2113*4882a593Smuzhiyun .resume = em28xx_dvb_resume,
2114*4882a593Smuzhiyun };
2115*4882a593Smuzhiyun
em28xx_dvb_register(void)2116*4882a593Smuzhiyun static int __init em28xx_dvb_register(void)
2117*4882a593Smuzhiyun {
2118*4882a593Smuzhiyun return em28xx_register_extension(&dvb_ops);
2119*4882a593Smuzhiyun }
2120*4882a593Smuzhiyun
em28xx_dvb_unregister(void)2121*4882a593Smuzhiyun static void __exit em28xx_dvb_unregister(void)
2122*4882a593Smuzhiyun {
2123*4882a593Smuzhiyun em28xx_unregister_extension(&dvb_ops);
2124*4882a593Smuzhiyun }
2125*4882a593Smuzhiyun
2126*4882a593Smuzhiyun module_init(em28xx_dvb_register);
2127*4882a593Smuzhiyun module_exit(em28xx_dvb_unregister);
2128