xref: /openbmc/linux/drivers/media/usb/em28xx/em28xx-dvb.c (revision 0ae10a7dc8992ee682ff0b1752ff7c83d472eef1)
1f22e9e71SMauro Carvalho Chehab // SPDX-License-Identifier: GPL-2.0
2f22e9e71SMauro Carvalho Chehab //
3f22e9e71SMauro Carvalho Chehab // DVB device driver for em28xx
4f22e9e71SMauro Carvalho Chehab //
532590819SMauro Carvalho Chehab // (c) 2008-2011 Mauro Carvalho Chehab <mchehab@kernel.org>
6f22e9e71SMauro Carvalho Chehab //
7f22e9e71SMauro Carvalho Chehab // (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
8f22e9e71SMauro Carvalho Chehab //	- Fixes for the driver to properly work with HVR-950
9f22e9e71SMauro Carvalho Chehab //	- Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick
10f22e9e71SMauro Carvalho Chehab //	- Fixes for the driver to properly work with AMD ATI TV Wonder HD 600
11f22e9e71SMauro Carvalho Chehab //
12f22e9e71SMauro Carvalho Chehab // (c) 2008 Aidan Thornton <makosoft@googlemail.com>
13f22e9e71SMauro Carvalho Chehab //
14f22e9e71SMauro Carvalho Chehab // (c) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
15f22e9e71SMauro Carvalho Chehab //
16f22e9e71SMauro Carvalho Chehab // Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
17f22e9e71SMauro Carvalho Chehab //	(c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
18f22e9e71SMauro Carvalho Chehab //	(c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
19f22e9e71SMauro Carvalho Chehab //
20f22e9e71SMauro Carvalho Chehab // This program is free software; you can redistribute it and/or modify
21f22e9e71SMauro Carvalho Chehab // it under the terms of the GNU General Public License as published by
22f22e9e71SMauro Carvalho Chehab // the Free Software Foundation version 2 of the License.
230c0d06caSMauro Carvalho Chehab 
248314d402SMauro Carvalho Chehab #include "em28xx.h"
258314d402SMauro Carvalho Chehab 
260c0d06caSMauro Carvalho Chehab #include <linux/kernel.h>
270c0d06caSMauro Carvalho Chehab #include <linux/slab.h>
280c0d06caSMauro Carvalho Chehab #include <linux/usb.h>
290c0d06caSMauro Carvalho Chehab 
300c0d06caSMauro Carvalho Chehab #include <media/v4l2-common.h>
31fada1935SMauro Carvalho Chehab #include <media/dvb_demux.h>
32fada1935SMauro Carvalho Chehab #include <media/dvb_net.h>
33fada1935SMauro Carvalho Chehab #include <media/dmxdev.h>
340c0d06caSMauro Carvalho Chehab #include <media/tuner.h>
350c0d06caSMauro Carvalho Chehab #include "tuner-simple.h"
361e8f31f3SAntti Palosaari #include <linux/gpio.h>
370c0d06caSMauro Carvalho Chehab 
380c0d06caSMauro Carvalho Chehab #include "lgdt330x.h"
390c0d06caSMauro Carvalho Chehab #include "lgdt3305.h"
401586342eSKevin Cheng #include "lgdt3306a.h"
410c0d06caSMauro Carvalho Chehab #include "zl10353.h"
420c0d06caSMauro Carvalho Chehab #include "s5h1409.h"
438c47311dSAlberto Mardegan #include "mt2060.h"
440c0d06caSMauro Carvalho Chehab #include "mt352.h"
450c0d06caSMauro Carvalho Chehab #include "mt352_priv.h" /* FIXME */
460c0d06caSMauro Carvalho Chehab #include "tda1002x.h"
4738b2df95SDevin Heitmueller #include "drx39xyj/drx39xxj.h"
480c0d06caSMauro Carvalho Chehab #include "tda18271.h"
490c0d06caSMauro Carvalho Chehab #include "s921.h"
500c0d06caSMauro Carvalho Chehab #include "drxd.h"
510c0d06caSMauro Carvalho Chehab #include "cxd2820r.h"
520c0d06caSMauro Carvalho Chehab #include "tda18271c2dd.h"
530c0d06caSMauro Carvalho Chehab #include "drxk.h"
540c0d06caSMauro Carvalho Chehab #include "tda10071.h"
5502bc1f55SMauro Carvalho Chehab #include "tda18212.h"
560c0d06caSMauro Carvalho Chehab #include "a8293.h"
570c0d06caSMauro Carvalho Chehab #include "qt1010.h"
584159d01bSMauro Carvalho Chehab #include "mb86a20s.h"
59ec573362SAntti Palosaari #include "m88ds3103.h"
6083c1b6ceSAntti Palosaari #include "ts2020.h"
6119229240SAntti Palosaari #include "si2168.h"
6219229240SAntti Palosaari #include "si2157.h"
63ab4d1452SSatoshi Nagahama #include "tc90522.h"
64ab4d1452SSatoshi Nagahama #include "qm1d1c0042.h"
652e74a01fSBrad Love #include "mxl692.h"
660c0d06caSMauro Carvalho Chehab 
6732590819SMauro Carvalho Chehab MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@kernel.org>");
68f22e9e71SMauro Carvalho Chehab MODULE_LICENSE("GPL v2");
69d8992b09SMauro Carvalho Chehab MODULE_DESCRIPTION(DRIVER_DESC " - digital TV interface");
70d8992b09SMauro Carvalho Chehab MODULE_VERSION(EM28XX_VERSION);
71d8992b09SMauro Carvalho Chehab 
720c0d06caSMauro Carvalho Chehab static unsigned int debug;
730c0d06caSMauro Carvalho Chehab module_param(debug, int, 0644);
740c0d06caSMauro Carvalho Chehab MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
750c0d06caSMauro Carvalho Chehab 
760c0d06caSMauro Carvalho Chehab DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
770c0d06caSMauro Carvalho Chehab 
780c0d06caSMauro Carvalho Chehab #define dprintk(level, fmt, arg...) do {				\
790c0d06caSMauro Carvalho Chehab 	if (debug >= level)						\
8029b05e22SMauro Carvalho Chehab 		dev_printk(KERN_DEBUG, &dev->intf->dev,			\
81ce8591ffSMauro Carvalho Chehab 			   "dvb: " fmt, ## arg);			\
820c0d06caSMauro Carvalho Chehab } while (0)
830c0d06caSMauro Carvalho Chehab 
840c0d06caSMauro Carvalho Chehab struct em28xx_dvb {
850c0d06caSMauro Carvalho Chehab 	struct dvb_frontend        *fe[2];
860c0d06caSMauro Carvalho Chehab 
870c0d06caSMauro Carvalho Chehab 	/* feed count management */
880c0d06caSMauro Carvalho Chehab 	struct mutex               lock;
890c0d06caSMauro Carvalho Chehab 	int                        nfeeds;
900c0d06caSMauro Carvalho Chehab 
910c0d06caSMauro Carvalho Chehab 	/* general boilerplate stuff */
920c0d06caSMauro Carvalho Chehab 	struct dvb_adapter         adapter;
930c0d06caSMauro Carvalho Chehab 	struct dvb_demux           demux;
940c0d06caSMauro Carvalho Chehab 	struct dmxdev              dmxdev;
950c0d06caSMauro Carvalho Chehab 	struct dmx_frontend        fe_hw;
960c0d06caSMauro Carvalho Chehab 	struct dmx_frontend        fe_mem;
970c0d06caSMauro Carvalho Chehab 	struct dvb_net             net;
980c0d06caSMauro Carvalho Chehab 
990c0d06caSMauro Carvalho Chehab 	/* Due to DRX-K - probably need changes */
100fe8d54f0SMauro Carvalho Chehab 	int (*gate_ctrl)(struct dvb_frontend *fe, int gate);
1010c0d06caSMauro Carvalho Chehab 	struct semaphore      pll_mutex;
1020c0d06caSMauro Carvalho Chehab 	bool			dont_attach_fe1;
10313a5336eSAntti Palosaari 	int			lna_gpio;
10419229240SAntti Palosaari 	struct i2c_client	*i2c_client_demod;
105eafa2ad6SAntti Palosaari 	struct i2c_client	*i2c_client_tuner;
1067098f582SAntti Palosaari 	struct i2c_client	*i2c_client_sec;
1070c0d06caSMauro Carvalho Chehab };
1080c0d06caSMauro Carvalho Chehab 
1090c0d06caSMauro Carvalho Chehab static inline void print_err_status(struct em28xx *dev,
1100c0d06caSMauro Carvalho Chehab 				    int packet, int status)
1110c0d06caSMauro Carvalho Chehab {
1120c0d06caSMauro Carvalho Chehab 	char *errmsg = "Unknown";
1130c0d06caSMauro Carvalho Chehab 
1140c0d06caSMauro Carvalho Chehab 	switch (status) {
1150c0d06caSMauro Carvalho Chehab 	case -ENOENT:
116b436e26eSColin Ian King 		errmsg = "unlinked synchronously";
1170c0d06caSMauro Carvalho Chehab 		break;
1180c0d06caSMauro Carvalho Chehab 	case -ECONNRESET:
119b436e26eSColin Ian King 		errmsg = "unlinked asynchronously";
1200c0d06caSMauro Carvalho Chehab 		break;
1210c0d06caSMauro Carvalho Chehab 	case -ENOSR:
1220c0d06caSMauro Carvalho Chehab 		errmsg = "Buffer error (overrun)";
1230c0d06caSMauro Carvalho Chehab 		break;
1240c0d06caSMauro Carvalho Chehab 	case -EPIPE:
1250c0d06caSMauro Carvalho Chehab 		errmsg = "Stalled (device not responding)";
1260c0d06caSMauro Carvalho Chehab 		break;
1270c0d06caSMauro Carvalho Chehab 	case -EOVERFLOW:
1280c0d06caSMauro Carvalho Chehab 		errmsg = "Babble (bad cable?)";
1290c0d06caSMauro Carvalho Chehab 		break;
1300c0d06caSMauro Carvalho Chehab 	case -EPROTO:
1310c0d06caSMauro Carvalho Chehab 		errmsg = "Bit-stuff error (bad cable?)";
1320c0d06caSMauro Carvalho Chehab 		break;
1330c0d06caSMauro Carvalho Chehab 	case -EILSEQ:
1340c0d06caSMauro Carvalho Chehab 		errmsg = "CRC/Timeout (could be anything)";
1350c0d06caSMauro Carvalho Chehab 		break;
1360c0d06caSMauro Carvalho Chehab 	case -ETIME:
1370c0d06caSMauro Carvalho Chehab 		errmsg = "Device does not respond";
1380c0d06caSMauro Carvalho Chehab 		break;
1390c0d06caSMauro Carvalho Chehab 	}
1400c0d06caSMauro Carvalho Chehab 	if (packet < 0) {
1410c0d06caSMauro Carvalho Chehab 		dprintk(1, "URB status %d [%s].\n", status, errmsg);
1420c0d06caSMauro Carvalho Chehab 	} else {
1430c0d06caSMauro Carvalho Chehab 		dprintk(1, "URB packet %d, status %d [%s].\n",
1440c0d06caSMauro Carvalho Chehab 			packet, status, errmsg);
1450c0d06caSMauro Carvalho Chehab 	}
1460c0d06caSMauro Carvalho Chehab }
1470c0d06caSMauro Carvalho Chehab 
148a950e4a7SFrank Schaefer static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
1490c0d06caSMauro Carvalho Chehab {
150a950e4a7SFrank Schaefer 	int xfer_bulk, num_packets, i;
1510c0d06caSMauro Carvalho Chehab 
1520c0d06caSMauro Carvalho Chehab 	if (!dev)
1530c0d06caSMauro Carvalho Chehab 		return 0;
1540c0d06caSMauro Carvalho Chehab 
1552665c299SFrank Schaefer 	if (dev->disconnected)
1560c0d06caSMauro Carvalho Chehab 		return 0;
1570c0d06caSMauro Carvalho Chehab 
1581653cb0cSFrank Schaefer 	if (urb->status < 0)
1590c0d06caSMauro Carvalho Chehab 		print_err_status(dev, -1, urb->status);
1600c0d06caSMauro Carvalho Chehab 
161a950e4a7SFrank Schaefer 	xfer_bulk = usb_pipebulk(urb->pipe);
1620c0d06caSMauro Carvalho Chehab 
163a950e4a7SFrank Schaefer 	if (xfer_bulk) /* bulk */
164a950e4a7SFrank Schaefer 		num_packets = 1;
165a950e4a7SFrank Schaefer 	else /* isoc */
166a950e4a7SFrank Schaefer 		num_packets = urb->number_of_packets;
167a950e4a7SFrank Schaefer 
168a950e4a7SFrank Schaefer 	for (i = 0; i < num_packets; i++) {
169a950e4a7SFrank Schaefer 		if (xfer_bulk) {
170a950e4a7SFrank Schaefer 			if (urb->status < 0) {
171a950e4a7SFrank Schaefer 				print_err_status(dev, i, urb->status);
172a950e4a7SFrank Schaefer 				if (urb->status != -EPROTO)
173a950e4a7SFrank Schaefer 					continue;
174a950e4a7SFrank Schaefer 			}
175ffdeca88SMauro Carvalho Chehab 			if (!urb->actual_length)
176ffdeca88SMauro Carvalho Chehab 				continue;
177a950e4a7SFrank Schaefer 			dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
178a950e4a7SFrank Schaefer 					 urb->actual_length);
179a950e4a7SFrank Schaefer 		} else {
180a950e4a7SFrank Schaefer 			if (urb->iso_frame_desc[i].status < 0) {
181a950e4a7SFrank Schaefer 				print_err_status(dev, i,
182a950e4a7SFrank Schaefer 						 urb->iso_frame_desc[i].status);
1830c0d06caSMauro Carvalho Chehab 				if (urb->iso_frame_desc[i].status != -EPROTO)
1840c0d06caSMauro Carvalho Chehab 					continue;
1850c0d06caSMauro Carvalho Chehab 			}
186ffdeca88SMauro Carvalho Chehab 			if (!urb->iso_frame_desc[i].actual_length)
187ffdeca88SMauro Carvalho Chehab 				continue;
188a950e4a7SFrank Schaefer 			dvb_dmx_swfilter(&dev->dvb->demux,
189a950e4a7SFrank Schaefer 					 urb->transfer_buffer +
1900c0d06caSMauro Carvalho Chehab 					 urb->iso_frame_desc[i].offset,
1910c0d06caSMauro Carvalho Chehab 					 urb->iso_frame_desc[i].actual_length);
1920c0d06caSMauro Carvalho Chehab 		}
193a950e4a7SFrank Schaefer 	}
1940c0d06caSMauro Carvalho Chehab 
1950c0d06caSMauro Carvalho Chehab 	return 0;
1960c0d06caSMauro Carvalho Chehab }
1970c0d06caSMauro Carvalho Chehab 
1980c0d06caSMauro Carvalho Chehab static int em28xx_start_streaming(struct em28xx_dvb *dvb)
1990c0d06caSMauro Carvalho Chehab {
2000c0d06caSMauro Carvalho Chehab 	int rc;
2013de09fbbSHans Verkuil 	struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
2023de09fbbSHans Verkuil 	struct em28xx *dev = i2c_bus->dev;
203509f8965SMauro Carvalho Chehab 	struct usb_device *udev = interface_to_usbdev(dev->intf);
204c647a91aSFrank Schaefer 	int dvb_max_packet_size, packet_multiplier, dvb_alt;
2050c0d06caSMauro Carvalho Chehab 
206c647a91aSFrank Schaefer 	if (dev->dvb_xfer_bulk) {
207c647a91aSFrank Schaefer 		if (!dev->dvb_ep_bulk)
208c647a91aSFrank Schaefer 			return -ENODEV;
209c647a91aSFrank Schaefer 		dvb_max_packet_size = 512; /* USB 2.0 spec */
210c647a91aSFrank Schaefer 		packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
211c647a91aSFrank Schaefer 		dvb_alt = 0;
212c647a91aSFrank Schaefer 	} else { /* isoc */
213c647a91aSFrank Schaefer 		if (!dev->dvb_ep_isoc)
214c647a91aSFrank Schaefer 			return -ENODEV;
215c647a91aSFrank Schaefer 		dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
216c647a91aSFrank Schaefer 		if (dvb_max_packet_size < 0)
217c647a91aSFrank Schaefer 			return dvb_max_packet_size;
218c647a91aSFrank Schaefer 		packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
219c647a91aSFrank Schaefer 		dvb_alt = dev->dvb_alt_isoc;
220c647a91aSFrank Schaefer 	}
221c647a91aSFrank Schaefer 
222a7853c25SBrad Love 	if (!dev->board.has_dual_ts)
223509f8965SMauro Carvalho Chehab 		usb_set_interface(udev, dev->ifnum, dvb_alt);
224a7853c25SBrad Love 
2250c0d06caSMauro Carvalho Chehab 	rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
2260c0d06caSMauro Carvalho Chehab 	if (rc < 0)
2270c0d06caSMauro Carvalho Chehab 		return rc;
2280c0d06caSMauro Carvalho Chehab 
22952f7b00eSMauro Carvalho Chehab 	dprintk(1, "Using %d buffers each with %d x %d bytes, alternate %d\n",
2300c0d06caSMauro Carvalho Chehab 		EM28XX_DVB_NUM_BUFS,
231c647a91aSFrank Schaefer 		packet_multiplier,
23252f7b00eSMauro Carvalho Chehab 		dvb_max_packet_size, dvb_alt);
2330c0d06caSMauro Carvalho Chehab 
234c647a91aSFrank Schaefer 	return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
235c647a91aSFrank Schaefer 				    dev->dvb_xfer_bulk,
236515688a8SFrank Schaefer 				    EM28XX_DVB_NUM_BUFS,
237c647a91aSFrank Schaefer 				    dvb_max_packet_size,
238c647a91aSFrank Schaefer 				    packet_multiplier,
239a950e4a7SFrank Schaefer 				    em28xx_dvb_urb_data_copy);
2400c0d06caSMauro Carvalho Chehab }
2410c0d06caSMauro Carvalho Chehab 
2420c0d06caSMauro Carvalho Chehab static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
2430c0d06caSMauro Carvalho Chehab {
2443de09fbbSHans Verkuil 	struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
2453de09fbbSHans Verkuil 	struct em28xx *dev = i2c_bus->dev;
2460c0d06caSMauro Carvalho Chehab 
2470c0d06caSMauro Carvalho Chehab 	em28xx_stop_urbs(dev);
2480c0d06caSMauro Carvalho Chehab 
2490c0d06caSMauro Carvalho Chehab 	return 0;
2500c0d06caSMauro Carvalho Chehab }
2510c0d06caSMauro Carvalho Chehab 
2520c0d06caSMauro Carvalho Chehab static int em28xx_start_feed(struct dvb_demux_feed *feed)
2530c0d06caSMauro Carvalho Chehab {
2540c0d06caSMauro Carvalho Chehab 	struct dvb_demux *demux  = feed->demux;
2550c0d06caSMauro Carvalho Chehab 	struct em28xx_dvb *dvb = demux->priv;
2560c0d06caSMauro Carvalho Chehab 	int rc, ret;
2570c0d06caSMauro Carvalho Chehab 
2580c0d06caSMauro Carvalho Chehab 	if (!demux->dmx.frontend)
2590c0d06caSMauro Carvalho Chehab 		return -EINVAL;
2600c0d06caSMauro Carvalho Chehab 
2610c0d06caSMauro Carvalho Chehab 	mutex_lock(&dvb->lock);
2620c0d06caSMauro Carvalho Chehab 	dvb->nfeeds++;
2630c0d06caSMauro Carvalho Chehab 	rc = dvb->nfeeds;
2640c0d06caSMauro Carvalho Chehab 
2650c0d06caSMauro Carvalho Chehab 	if (dvb->nfeeds == 1) {
2660c0d06caSMauro Carvalho Chehab 		ret = em28xx_start_streaming(dvb);
2670c0d06caSMauro Carvalho Chehab 		if (ret < 0)
2680c0d06caSMauro Carvalho Chehab 			rc = ret;
2690c0d06caSMauro Carvalho Chehab 	}
2700c0d06caSMauro Carvalho Chehab 
2710c0d06caSMauro Carvalho Chehab 	mutex_unlock(&dvb->lock);
2720c0d06caSMauro Carvalho Chehab 	return rc;
2730c0d06caSMauro Carvalho Chehab }
2740c0d06caSMauro Carvalho Chehab 
2750c0d06caSMauro Carvalho Chehab static int em28xx_stop_feed(struct dvb_demux_feed *feed)
2760c0d06caSMauro Carvalho Chehab {
2770c0d06caSMauro Carvalho Chehab 	struct dvb_demux *demux  = feed->demux;
2780c0d06caSMauro Carvalho Chehab 	struct em28xx_dvb *dvb = demux->priv;
2790c0d06caSMauro Carvalho Chehab 	int err = 0;
2800c0d06caSMauro Carvalho Chehab 
2810c0d06caSMauro Carvalho Chehab 	mutex_lock(&dvb->lock);
2820c0d06caSMauro Carvalho Chehab 	dvb->nfeeds--;
2830c0d06caSMauro Carvalho Chehab 
284fe8d54f0SMauro Carvalho Chehab 	if (!dvb->nfeeds)
2850c0d06caSMauro Carvalho Chehab 		err = em28xx_stop_streaming(dvb);
2860c0d06caSMauro Carvalho Chehab 
2870c0d06caSMauro Carvalho Chehab 	mutex_unlock(&dvb->lock);
2880c0d06caSMauro Carvalho Chehab 	return err;
2890c0d06caSMauro Carvalho Chehab }
2900c0d06caSMauro Carvalho Chehab 
2910c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */
2920c0d06caSMauro Carvalho Chehab static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
2930c0d06caSMauro Carvalho Chehab {
294a3b60209SMauro Carvalho Chehab 	struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
295a3b60209SMauro Carvalho Chehab 	struct em28xx *dev = i2c_bus->dev;
2960c0d06caSMauro Carvalho Chehab 
2970c0d06caSMauro Carvalho Chehab 	if (acquire)
2980c0d06caSMauro Carvalho Chehab 		return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
2990c0d06caSMauro Carvalho Chehab 	else
3000c0d06caSMauro Carvalho Chehab 		return em28xx_set_mode(dev, EM28XX_SUSPEND);
3010c0d06caSMauro Carvalho Chehab }
3020c0d06caSMauro Carvalho Chehab 
3030c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */
3040c0d06caSMauro Carvalho Chehab 
3050c0d06caSMauro Carvalho Chehab static struct lgdt330x_config em2880_lgdt3303_dev = {
3060c0d06caSMauro Carvalho Chehab 	.demod_chip = LGDT3303,
3070c0d06caSMauro Carvalho Chehab };
3080c0d06caSMauro Carvalho Chehab 
3090c0d06caSMauro Carvalho Chehab static struct lgdt3305_config em2870_lgdt3304_dev = {
3100c0d06caSMauro Carvalho Chehab 	.i2c_addr           = 0x0e,
3110c0d06caSMauro Carvalho Chehab 	.demod_chip         = LGDT3304,
3120c0d06caSMauro Carvalho Chehab 	.spectral_inversion = 1,
3130c0d06caSMauro Carvalho Chehab 	.deny_i2c_rptr      = 1,
3140c0d06caSMauro Carvalho Chehab 	.mpeg_mode          = LGDT3305_MPEG_PARALLEL,
3150c0d06caSMauro Carvalho Chehab 	.tpclk_edge         = LGDT3305_TPCLK_FALLING_EDGE,
3160c0d06caSMauro Carvalho Chehab 	.tpvalid_polarity   = LGDT3305_TP_VALID_HIGH,
3170c0d06caSMauro Carvalho Chehab 	.vsb_if_khz         = 3250,
3180c0d06caSMauro Carvalho Chehab 	.qam_if_khz         = 4000,
3190c0d06caSMauro Carvalho Chehab };
3200c0d06caSMauro Carvalho Chehab 
3216dbea9f0SJean-Francois Thibert static struct lgdt3305_config em2874_lgdt3305_dev = {
3226dbea9f0SJean-Francois Thibert 	.i2c_addr           = 0x0e,
3236dbea9f0SJean-Francois Thibert 	.demod_chip         = LGDT3305,
3246dbea9f0SJean-Francois Thibert 	.spectral_inversion = 1,
3256dbea9f0SJean-Francois Thibert 	.deny_i2c_rptr      = 0,
3266dbea9f0SJean-Francois Thibert 	.mpeg_mode          = LGDT3305_MPEG_SERIAL,
3276dbea9f0SJean-Francois Thibert 	.tpclk_edge         = LGDT3305_TPCLK_FALLING_EDGE,
3286dbea9f0SJean-Francois Thibert 	.tpvalid_polarity   = LGDT3305_TP_VALID_HIGH,
3296dbea9f0SJean-Francois Thibert 	.vsb_if_khz         = 3250,
3306dbea9f0SJean-Francois Thibert 	.qam_if_khz         = 4000,
3316dbea9f0SJean-Francois Thibert };
3326dbea9f0SJean-Francois Thibert 
33302bc1f55SMauro Carvalho Chehab static struct lgdt3305_config em2874_lgdt3305_nogate_dev = {
33402bc1f55SMauro Carvalho Chehab 	.i2c_addr           = 0x0e,
33502bc1f55SMauro Carvalho Chehab 	.demod_chip         = LGDT3305,
33602bc1f55SMauro Carvalho Chehab 	.spectral_inversion = 1,
33702bc1f55SMauro Carvalho Chehab 	.deny_i2c_rptr      = 1,
33802bc1f55SMauro Carvalho Chehab 	.mpeg_mode          = LGDT3305_MPEG_SERIAL,
33902bc1f55SMauro Carvalho Chehab 	.tpclk_edge         = LGDT3305_TPCLK_FALLING_EDGE,
34002bc1f55SMauro Carvalho Chehab 	.tpvalid_polarity   = LGDT3305_TP_VALID_HIGH,
34102bc1f55SMauro Carvalho Chehab 	.vsb_if_khz         = 3600,
34202bc1f55SMauro Carvalho Chehab 	.qam_if_khz         = 3600,
34302bc1f55SMauro Carvalho Chehab };
34402bc1f55SMauro Carvalho Chehab 
3450c0d06caSMauro Carvalho Chehab static struct s921_config sharp_isdbt = {
3460c0d06caSMauro Carvalho Chehab 	.demod_address = 0x30 >> 1
3470c0d06caSMauro Carvalho Chehab };
3480c0d06caSMauro Carvalho Chehab 
3490c0d06caSMauro Carvalho Chehab static struct zl10353_config em28xx_zl10353_with_xc3028 = {
3500c0d06caSMauro Carvalho Chehab 	.demod_address = (0x1e >> 1),
3510c0d06caSMauro Carvalho Chehab 	.no_tuner = 1,
3520c0d06caSMauro Carvalho Chehab 	.parallel_ts = 1,
3530c0d06caSMauro Carvalho Chehab 	.if2 = 45600,
3540c0d06caSMauro Carvalho Chehab };
3550c0d06caSMauro Carvalho Chehab 
3560c0d06caSMauro Carvalho Chehab static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
3570c0d06caSMauro Carvalho Chehab 	.demod_address = 0x32 >> 1,
3580c0d06caSMauro Carvalho Chehab 	.output_mode   = S5H1409_PARALLEL_OUTPUT,
3590c0d06caSMauro Carvalho Chehab 	.gpio          = S5H1409_GPIO_OFF,
3600c0d06caSMauro Carvalho Chehab 	.inversion     = S5H1409_INVERSION_OFF,
3610c0d06caSMauro Carvalho Chehab 	.status_mode   = S5H1409_DEMODLOCKING,
362ad05ff09SMauro Carvalho Chehab 	.mpeg_timing   = S5H1409_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK
3630c0d06caSMauro Carvalho Chehab };
3640c0d06caSMauro Carvalho Chehab 
3650c0d06caSMauro Carvalho Chehab static struct tda18271_std_map kworld_a340_std_map = {
3660c0d06caSMauro Carvalho Chehab 	.atsc_6   = { .if_freq = 3250, .agc_mode = 3, .std = 0,
3670c0d06caSMauro Carvalho Chehab 		      .if_lvl = 1, .rfagc_top = 0x37, },
3680c0d06caSMauro Carvalho Chehab 	.qam_6    = { .if_freq = 4000, .agc_mode = 3, .std = 1,
3690c0d06caSMauro Carvalho Chehab 		      .if_lvl = 1, .rfagc_top = 0x37, },
3700c0d06caSMauro Carvalho Chehab };
3710c0d06caSMauro Carvalho Chehab 
3720c0d06caSMauro Carvalho Chehab static struct tda18271_config kworld_a340_config = {
3730c0d06caSMauro Carvalho Chehab 	.std_map           = &kworld_a340_std_map,
3740c0d06caSMauro Carvalho Chehab };
3750c0d06caSMauro Carvalho Chehab 
3766dbea9f0SJean-Francois Thibert static struct tda18271_config kworld_ub435q_v2_config = {
3776dbea9f0SJean-Francois Thibert 	.std_map	= &kworld_a340_std_map,
3786dbea9f0SJean-Francois Thibert 	.gate		= TDA18271_GATE_DIGITAL,
3796dbea9f0SJean-Francois Thibert };
3806dbea9f0SJean-Francois Thibert 
38102bc1f55SMauro Carvalho Chehab static struct tda18212_config kworld_ub435q_v3_config = {
38202bc1f55SMauro Carvalho Chehab 	.if_atsc_vsb	= 3600,
38302bc1f55SMauro Carvalho Chehab 	.if_atsc_qam	= 3600,
38402bc1f55SMauro Carvalho Chehab };
38502bc1f55SMauro Carvalho Chehab 
3860c0d06caSMauro Carvalho Chehab static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
3870c0d06caSMauro Carvalho Chehab 	.demod_address = (0x1e >> 1),
3880c0d06caSMauro Carvalho Chehab 	.no_tuner = 1,
3890c0d06caSMauro Carvalho Chehab 	.disable_i2c_gate_ctrl = 1,
3900c0d06caSMauro Carvalho Chehab 	.parallel_ts = 1,
3910c0d06caSMauro Carvalho Chehab 	.if2 = 45600,
3920c0d06caSMauro Carvalho Chehab };
3930c0d06caSMauro Carvalho Chehab 
3940c0d06caSMauro Carvalho Chehab static struct drxd_config em28xx_drxd = {
3950c0d06caSMauro Carvalho Chehab 	.demod_address = 0x70,
3960c0d06caSMauro Carvalho Chehab 	.demod_revision = 0xa2,
3970c0d06caSMauro Carvalho Chehab 	.pll_type = DRXD_PLL_NONE,
3980c0d06caSMauro Carvalho Chehab 	.clock = 12000,
3990c0d06caSMauro Carvalho Chehab 	.insert_rs_byte = 1,
4000c0d06caSMauro Carvalho Chehab 	.IF = 42800000,
4010c0d06caSMauro Carvalho Chehab 	.disable_i2c_gate_ctrl = 1,
4020c0d06caSMauro Carvalho Chehab };
4030c0d06caSMauro Carvalho Chehab 
4040c0d06caSMauro Carvalho Chehab static struct drxk_config terratec_h5_drxk = {
4050c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4060c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4070c0d06caSMauro Carvalho Chehab 	.no_i2c_bridge = 1,
4080c0d06caSMauro Carvalho Chehab 	.microcode_name = "dvb-usb-terratec-h5-drxk.fw",
4090c0d06caSMauro Carvalho Chehab 	.qam_demod_parameter_count = 2,
4100c0d06caSMauro Carvalho Chehab };
4110c0d06caSMauro Carvalho Chehab 
4120c0d06caSMauro Carvalho Chehab static struct drxk_config hauppauge_930c_drxk = {
4130c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4140c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4150c0d06caSMauro Carvalho Chehab 	.no_i2c_bridge = 1,
4160c0d06caSMauro Carvalho Chehab 	.microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
4170c0d06caSMauro Carvalho Chehab 	.chunk_size = 56,
4180c0d06caSMauro Carvalho Chehab 	.qam_demod_parameter_count = 2,
4190c0d06caSMauro Carvalho Chehab };
4200c0d06caSMauro Carvalho Chehab 
42189040136SMartin Blumenstingl static struct drxk_config terratec_htc_stick_drxk = {
4220c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4230c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4240c0d06caSMauro Carvalho Chehab 	.no_i2c_bridge = 1,
4250c0d06caSMauro Carvalho Chehab 	.microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
4260c0d06caSMauro Carvalho Chehab 	.chunk_size = 54,
4270c0d06caSMauro Carvalho Chehab 	.qam_demod_parameter_count = 2,
4280c0d06caSMauro Carvalho Chehab 	/* Required for the antenna_gpio to disable LNA. */
4290c0d06caSMauro Carvalho Chehab 	.antenna_dvbt = true,
4300c0d06caSMauro Carvalho Chehab 	/* The windows driver uses the same. This will disable LNA. */
4310c0d06caSMauro Carvalho Chehab 	.antenna_gpio = 0x6,
4320c0d06caSMauro Carvalho Chehab };
4330c0d06caSMauro Carvalho Chehab 
4340c0d06caSMauro Carvalho Chehab static struct drxk_config maxmedia_ub425_tc_drxk = {
4350c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4360c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4370c0d06caSMauro Carvalho Chehab 	.no_i2c_bridge = 1,
4388d100b27SAntti Palosaari 	.microcode_name = "dvb-demod-drxk-01.fw",
4398d100b27SAntti Palosaari 	.chunk_size = 62,
440de0fc463SAntti Palosaari 	.qam_demod_parameter_count = 2,
4410c0d06caSMauro Carvalho Chehab };
4420c0d06caSMauro Carvalho Chehab 
4430c0d06caSMauro Carvalho Chehab static struct drxk_config pctv_520e_drxk = {
4440c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4450c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4460c0d06caSMauro Carvalho Chehab 	.microcode_name = "dvb-demod-drxk-pctv.fw",
4470c0d06caSMauro Carvalho Chehab 	.qam_demod_parameter_count = 2,
4480c0d06caSMauro Carvalho Chehab 	.chunk_size = 58,
4490c0d06caSMauro Carvalho Chehab 	.antenna_dvbt = true, /* disable LNA */
4500c0d06caSMauro Carvalho Chehab 	.antenna_gpio = (1 << 2), /* disable LNA */
4510c0d06caSMauro Carvalho Chehab };
4520c0d06caSMauro Carvalho Chehab 
4530c0d06caSMauro Carvalho Chehab static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
4540c0d06caSMauro Carvalho Chehab {
4550c0d06caSMauro Carvalho Chehab 	struct em28xx_dvb *dvb = fe->sec_priv;
4560c0d06caSMauro Carvalho Chehab 	int status;
4570c0d06caSMauro Carvalho Chehab 
4580c0d06caSMauro Carvalho Chehab 	if (!dvb)
4590c0d06caSMauro Carvalho Chehab 		return -EINVAL;
4600c0d06caSMauro Carvalho Chehab 
4610c0d06caSMauro Carvalho Chehab 	if (enable) {
4620c0d06caSMauro Carvalho Chehab 		down(&dvb->pll_mutex);
4630c0d06caSMauro Carvalho Chehab 		status = dvb->gate_ctrl(fe, 1);
4640c0d06caSMauro Carvalho Chehab 	} else {
4650c0d06caSMauro Carvalho Chehab 		status = dvb->gate_ctrl(fe, 0);
4660c0d06caSMauro Carvalho Chehab 		up(&dvb->pll_mutex);
4670c0d06caSMauro Carvalho Chehab 	}
4680c0d06caSMauro Carvalho Chehab 	return status;
4690c0d06caSMauro Carvalho Chehab }
4700c0d06caSMauro Carvalho Chehab 
4710c0d06caSMauro Carvalho Chehab static void hauppauge_hvr930c_init(struct em28xx *dev)
4720c0d06caSMauro Carvalho Chehab {
4730c0d06caSMauro Carvalho Chehab 	int i;
4740c0d06caSMauro Carvalho Chehab 
475ba0c8e6eSColin Ian King 	static const struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
476907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xff,	0xff,	0x65},
477907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xfb,	0xff,	0x32},
478907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xff,	0xff,	0xb8},
4790c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
4800c0d06caSMauro Carvalho Chehab 	};
481ba0c8e6eSColin Ian King 	static const struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
482907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x01},
483907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xaf,	0xff,	0x65},
484907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x76},
485907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x01},
486907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xcf,	0xff,	0x0b},
487907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x40},
4880c0d06caSMauro Carvalho Chehab 
489907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xcf,	0xff,	0x65},
490907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x65},
491907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xcf,	0xff,	0x0b},
492907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x65},
4930c0d06caSMauro Carvalho Chehab 
4940c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
4950c0d06caSMauro Carvalho Chehab 	};
4960c0d06caSMauro Carvalho Chehab 
497ba0c8e6eSColin Ian King 	static const struct {
4980c0d06caSMauro Carvalho Chehab 		unsigned char r[4];
4990c0d06caSMauro Carvalho Chehab 		int len;
5000c0d06caSMauro Carvalho Chehab 	} regs[] = {
5010c0d06caSMauro Carvalho Chehab 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
5020c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02 }, 2},
5030c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
5040c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
5050c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
5060c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x03, 0xa0 }, 4},
5070c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
5080c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x73, 0xaf }, 4},
5090c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x00 }, 2},
5100c0d06caSMauro Carvalho Chehab 		{{ 0x00, 0x04 }, 2},
5110c0d06caSMauro Carvalho Chehab 		{{ 0x00, 0x04, 0x00, 0x0a }, 4},
5120c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x14 }, 2},
5130c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x14, 0x00, 0x00 }, 4},
5140c0d06caSMauro Carvalho Chehab 	};
5150c0d06caSMauro Carvalho Chehab 
5160c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, hauppauge_hvr930c_init);
5170c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
518fe8d54f0SMauro Carvalho Chehab 	usleep_range(10000, 11000);
5190c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
520fe8d54f0SMauro Carvalho Chehab 	usleep_range(10000, 11000);
5210c0d06caSMauro Carvalho Chehab 
522c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
5230c0d06caSMauro Carvalho Chehab 
5240c0d06caSMauro Carvalho Chehab 	for (i = 0; i < ARRAY_SIZE(regs); i++)
525fe8d54f0SMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
526fe8d54f0SMauro Carvalho Chehab 				regs[i].r, regs[i].len);
5270c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, hauppauge_hvr930c_end);
5280c0d06caSMauro Carvalho Chehab 
5290c0d06caSMauro Carvalho Chehab 	msleep(100);
5300c0d06caSMauro Carvalho Chehab 
5310c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
5320c0d06caSMauro Carvalho Chehab 	msleep(30);
5330c0d06caSMauro Carvalho Chehab 
5340c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
535fe8d54f0SMauro Carvalho Chehab 	usleep_range(10000, 11000);
5360c0d06caSMauro Carvalho Chehab }
5370c0d06caSMauro Carvalho Chehab 
5380c0d06caSMauro Carvalho Chehab static void terratec_h5_init(struct em28xx *dev)
5390c0d06caSMauro Carvalho Chehab {
5400c0d06caSMauro Carvalho Chehab 	int i;
541ba0c8e6eSColin Ian King 	static const struct em28xx_reg_seq terratec_h5_init[] = {
542c074fc4cSFrank Schaefer 		{EM2820_R08_GPIO_CTRL,		0xff,	0xff,	10},
543907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	100},
544907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf2,	0xff,	50},
545907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	100},
5460c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
5470c0d06caSMauro Carvalho Chehab 	};
548ba0c8e6eSColin Ian King 	static const struct em28xx_reg_seq terratec_h5_end[] = {
549907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xe6,	0xff,	100},
550907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xa6,	0xff,	50},
551907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xe6,	0xff,	100},
5520c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
5530c0d06caSMauro Carvalho Chehab 	};
554ba0c8e6eSColin Ian King 	static const struct {
5550c0d06caSMauro Carvalho Chehab 		unsigned char r[4];
5560c0d06caSMauro Carvalho Chehab 		int len;
5570c0d06caSMauro Carvalho Chehab 	} regs[] = {
5580c0d06caSMauro Carvalho Chehab 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
5590c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02 }, 2},
5600c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
5610c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
5620c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
5630c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x03, 0xa0 }, 4},
5640c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
5650c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x73, 0xaf }, 4},
5660c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x00 }, 2},
5670c0d06caSMauro Carvalho Chehab 		{{ 0x00, 0x04 }, 2},
5680c0d06caSMauro Carvalho Chehab 		{{ 0x00, 0x04, 0x00, 0x0a }, 4},
5690c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x14 }, 2},
5700c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x14, 0x00, 0x00 }, 4},
5710c0d06caSMauro Carvalho Chehab 	};
5720c0d06caSMauro Carvalho Chehab 
5730c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, terratec_h5_init);
5740c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
575fe8d54f0SMauro Carvalho Chehab 	usleep_range(10000, 11000);
5760c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
577fe8d54f0SMauro Carvalho Chehab 	usleep_range(10000, 11000);
5780c0d06caSMauro Carvalho Chehab 
579c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
5800c0d06caSMauro Carvalho Chehab 
5810c0d06caSMauro Carvalho Chehab 	for (i = 0; i < ARRAY_SIZE(regs); i++)
582fe8d54f0SMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
583fe8d54f0SMauro Carvalho Chehab 				regs[i].r, regs[i].len);
5840c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, terratec_h5_end);
5850c0d06caSMauro Carvalho Chehab };
5860c0d06caSMauro Carvalho Chehab 
5870c0d06caSMauro Carvalho Chehab static void terratec_htc_stick_init(struct em28xx *dev)
5880c0d06caSMauro Carvalho Chehab {
5890c0d06caSMauro Carvalho Chehab 	int i;
5900c0d06caSMauro Carvalho Chehab 
5910c0d06caSMauro Carvalho Chehab 	/*
5920c0d06caSMauro Carvalho Chehab 	 * GPIO configuration:
5930c0d06caSMauro Carvalho Chehab 	 * 0xff: unknown (does not affect DVB-T).
5940c0d06caSMauro Carvalho Chehab 	 * 0xf6: DRX-K (demodulator).
5950c0d06caSMauro Carvalho Chehab 	 * 0xe6: unknown (does not affect DVB-T).
5960c0d06caSMauro Carvalho Chehab 	 * 0xb6: unknown (does not affect DVB-T).
5970c0d06caSMauro Carvalho Chehab 	 */
598ba0c8e6eSColin Ian King 	static const struct em28xx_reg_seq terratec_htc_stick_init[] = {
599c074fc4cSFrank Schaefer 		{EM2820_R08_GPIO_CTRL,		0xff,	0xff,	10},
600907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	100},
601907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xe6,	0xff,	50},
602907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	100},
6030c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
6040c0d06caSMauro Carvalho Chehab 	};
605ba0c8e6eSColin Ian King 	static const struct em28xx_reg_seq terratec_htc_stick_end[] = {
606907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xb6,	0xff,	100},
607907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	50},
6080c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
6090c0d06caSMauro Carvalho Chehab 	};
6100c0d06caSMauro Carvalho Chehab 
61189040136SMartin Blumenstingl 	/*
61289040136SMartin Blumenstingl 	 * Init the analog decoder (not yet supported), but
61389040136SMartin Blumenstingl 	 * it's probably still a good idea.
61489040136SMartin Blumenstingl 	 */
615ba0c8e6eSColin Ian King 	static const struct {
6160c0d06caSMauro Carvalho Chehab 		unsigned char r[4];
6170c0d06caSMauro Carvalho Chehab 		int len;
6180c0d06caSMauro Carvalho Chehab 	} regs[] = {
6190c0d06caSMauro Carvalho Chehab 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
6200c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02 }, 2},
6210c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
6220c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
6230c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
6240c0d06caSMauro Carvalho Chehab 	};
6250c0d06caSMauro Carvalho Chehab 
6260c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, terratec_htc_stick_init);
6270c0d06caSMauro Carvalho Chehab 
6280c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
629fe8d54f0SMauro Carvalho Chehab 	usleep_range(10000, 11000);
6300c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
631fe8d54f0SMauro Carvalho Chehab 	usleep_range(10000, 11000);
6320c0d06caSMauro Carvalho Chehab 
633c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
6340c0d06caSMauro Carvalho Chehab 
6350c0d06caSMauro Carvalho Chehab 	for (i = 0; i < ARRAY_SIZE(regs); i++)
636fe8d54f0SMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
637fe8d54f0SMauro Carvalho Chehab 				regs[i].r, regs[i].len);
6380c0d06caSMauro Carvalho Chehab 
6390c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, terratec_htc_stick_end);
6400c0d06caSMauro Carvalho Chehab };
6410c0d06caSMauro Carvalho Chehab 
64289040136SMartin Blumenstingl static void terratec_htc_usb_xs_init(struct em28xx *dev)
64389040136SMartin Blumenstingl {
64489040136SMartin Blumenstingl 	int i;
64589040136SMartin Blumenstingl 
646ba0c8e6eSColin Ian King 	static const struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
647c074fc4cSFrank Schaefer 		{EM2820_R08_GPIO_CTRL,		0xff,	0xff,	10},
648907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xb2,	0xff,	100},
649907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xb2,	0xff,	50},
650907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xb6,	0xff,	100},
65189040136SMartin Blumenstingl 		{	-1,			-1,	-1,	-1},
65289040136SMartin Blumenstingl 	};
653ba0c8e6eSColin Ian King 	static const struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
654907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xa6,	0xff,	100},
655907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xa6,	0xff,	50},
656907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xe6,	0xff,	100},
65789040136SMartin Blumenstingl 		{	-1,			-1,	-1,	-1},
65889040136SMartin Blumenstingl 	};
65989040136SMartin Blumenstingl 
66089040136SMartin Blumenstingl 	/*
66189040136SMartin Blumenstingl 	 * Init the analog decoder (not yet supported), but
66289040136SMartin Blumenstingl 	 * it's probably still a good idea.
66389040136SMartin Blumenstingl 	 */
664ba0c8e6eSColin Ian King 	static const struct {
66589040136SMartin Blumenstingl 		unsigned char r[4];
66689040136SMartin Blumenstingl 		int len;
66789040136SMartin Blumenstingl 	} regs[] = {
66889040136SMartin Blumenstingl 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
66989040136SMartin Blumenstingl 		{{ 0x01, 0x02 }, 2},
67089040136SMartin Blumenstingl 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
67189040136SMartin Blumenstingl 		{{ 0x01, 0x00 }, 2},
67289040136SMartin Blumenstingl 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
67389040136SMartin Blumenstingl 		{{ 0x01, 0x00, 0x03, 0xa0 }, 4},
67489040136SMartin Blumenstingl 		{{ 0x01, 0x00 }, 2},
67589040136SMartin Blumenstingl 		{{ 0x01, 0x00, 0x73, 0xaf }, 4},
67689040136SMartin Blumenstingl 		{{ 0x04, 0x00 }, 2},
67789040136SMartin Blumenstingl 		{{ 0x00, 0x04 }, 2},
67889040136SMartin Blumenstingl 		{{ 0x00, 0x04, 0x00, 0x0a }, 4},
67989040136SMartin Blumenstingl 		{{ 0x04, 0x14 }, 2},
68089040136SMartin Blumenstingl 		{{ 0x04, 0x14, 0x00, 0x00 }, 4},
68189040136SMartin Blumenstingl 	};
68289040136SMartin Blumenstingl 
68389040136SMartin Blumenstingl 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
68489040136SMartin Blumenstingl 
68589040136SMartin Blumenstingl 	em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
68689040136SMartin Blumenstingl 
68789040136SMartin Blumenstingl 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
688fe8d54f0SMauro Carvalho Chehab 	usleep_range(10000, 11000);
68989040136SMartin Blumenstingl 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
690fe8d54f0SMauro Carvalho Chehab 	usleep_range(10000, 11000);
69189040136SMartin Blumenstingl 
692c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
69389040136SMartin Blumenstingl 
69489040136SMartin Blumenstingl 	for (i = 0; i < ARRAY_SIZE(regs); i++)
695fe8d54f0SMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
696fe8d54f0SMauro Carvalho Chehab 				regs[i].r, regs[i].len);
69789040136SMartin Blumenstingl 
69889040136SMartin Blumenstingl 	em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
69989040136SMartin Blumenstingl };
70089040136SMartin Blumenstingl 
7010c0d06caSMauro Carvalho Chehab static void pctv_520e_init(struct em28xx *dev)
7020c0d06caSMauro Carvalho Chehab {
7030c0d06caSMauro Carvalho Chehab 	/*
7040c0d06caSMauro Carvalho Chehab 	 * Init AVF4910B analog decoder. Looks like I2C traffic to
7050c0d06caSMauro Carvalho Chehab 	 * digital demodulator and tuner are routed via AVF4910B.
7060c0d06caSMauro Carvalho Chehab 	 */
7070c0d06caSMauro Carvalho Chehab 	int i;
708ba0c8e6eSColin Ian King 	static const struct {
7090c0d06caSMauro Carvalho Chehab 		unsigned char r[4];
7100c0d06caSMauro Carvalho Chehab 		int len;
7110c0d06caSMauro Carvalho Chehab 	} regs[] = {
7120c0d06caSMauro Carvalho Chehab 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
7130c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02 }, 2},
7140c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
7150c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
7160c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
7170c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x03, 0xa0 }, 4},
7180c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
7190c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x73, 0xaf }, 4},
7200c0d06caSMauro Carvalho Chehab 	};
7210c0d06caSMauro Carvalho Chehab 
722c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
7230c0d06caSMauro Carvalho Chehab 
7240c0d06caSMauro Carvalho Chehab 	for (i = 0; i < ARRAY_SIZE(regs); i++)
725fe8d54f0SMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
726fe8d54f0SMauro Carvalho Chehab 				regs[i].r, regs[i].len);
7270c0d06caSMauro Carvalho Chehab };
7280c0d06caSMauro Carvalho Chehab 
72933eebec5SAntti Palosaari static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
73013a5336eSAntti Palosaari {
73133eebec5SAntti Palosaari 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
7323ec40dcfSAntti Palosaari 	struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
7333ec40dcfSAntti Palosaari 	struct em28xx *dev = i2c_bus->dev;
73413a5336eSAntti Palosaari #ifdef CONFIG_GPIOLIB
73513a5336eSAntti Palosaari 	struct em28xx_dvb *dvb = dev->dvb;
73613a5336eSAntti Palosaari 	int ret;
73713a5336eSAntti Palosaari 	unsigned long flags;
73813a5336eSAntti Palosaari 
73933eebec5SAntti Palosaari 	if (c->lna == 1)
74033eebec5SAntti Palosaari 		flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
74113a5336eSAntti Palosaari 	else
74233eebec5SAntti Palosaari 		flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
74313a5336eSAntti Palosaari 
74413a5336eSAntti Palosaari 	ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
74513a5336eSAntti Palosaari 	if (ret)
74629b05e22SMauro Carvalho Chehab 		dev_err(&dev->intf->dev, "gpio request failed %d\n", ret);
74713a5336eSAntti Palosaari 	else
74813a5336eSAntti Palosaari 		gpio_free(dvb->lna_gpio);
74913a5336eSAntti Palosaari 
75013a5336eSAntti Palosaari 	return ret;
75113a5336eSAntti Palosaari #else
75229b05e22SMauro Carvalho Chehab 	dev_warn(&dev->intf->dev, "%s: LNA control is disabled (lna=%u)\n",
75333eebec5SAntti Palosaari 		 KBUILD_MODNAME, c->lna);
75413a5336eSAntti Palosaari 	return 0;
75513a5336eSAntti Palosaari #endif
75613a5336eSAntti Palosaari }
75713a5336eSAntti Palosaari 
758ffb9948eSAntti Palosaari static int em28xx_pctv_292e_set_lna(struct dvb_frontend *fe)
759ffb9948eSAntti Palosaari {
760ffb9948eSAntti Palosaari 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
761ffb9948eSAntti Palosaari 	struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
762ffb9948eSAntti Palosaari 	struct em28xx *dev = i2c_bus->dev;
763ffb9948eSAntti Palosaari 	u8 lna;
764ffb9948eSAntti Palosaari 
765ffb9948eSAntti Palosaari 	if (c->lna == 1)
766ffb9948eSAntti Palosaari 		lna = 0x01;
767ffb9948eSAntti Palosaari 	else
768ffb9948eSAntti Palosaari 		lna = 0x00;
769ffb9948eSAntti Palosaari 
770ffb9948eSAntti Palosaari 	return em28xx_write_reg_bits(dev, EM2874_R80_GPIO_P0_CTRL, lna, 0x01);
771ffb9948eSAntti Palosaari }
772ffb9948eSAntti Palosaari 
7730c0d06caSMauro Carvalho Chehab static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
7740c0d06caSMauro Carvalho Chehab {
7750c0d06caSMauro Carvalho Chehab 	/* Values extracted from a USB trace of the Terratec Windows driver */
7760c0d06caSMauro Carvalho Chehab 	static u8 clock_config[]   = { CLOCK_CTL,  0x38, 0x2c };
7770c0d06caSMauro Carvalho Chehab 	static u8 reset[]          = { RESET,      0x80 };
7780c0d06caSMauro Carvalho Chehab 	static u8 adc_ctl_1_cfg[]  = { ADC_CTL_1,  0x40 };
7790c0d06caSMauro Carvalho Chehab 	static u8 agc_cfg[]        = { AGC_TARGET, 0x28, 0xa0 };
7800c0d06caSMauro Carvalho Chehab 	static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
7810c0d06caSMauro Carvalho Chehab 	static u8 rs_err_cfg[]     = { RS_ERR_PER_1, 0x00, 0x4d };
7820c0d06caSMauro Carvalho Chehab 	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
7830c0d06caSMauro Carvalho Chehab 	static u8 trl_nom_cfg[]    = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
7840c0d06caSMauro Carvalho Chehab 	static u8 tps_given_cfg[]  = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
7850c0d06caSMauro Carvalho Chehab 	static u8 tuner_go[]       = { TUNER_GO, 0x01};
7860c0d06caSMauro Carvalho Chehab 
7870c0d06caSMauro Carvalho Chehab 	mt352_write(fe, clock_config,   sizeof(clock_config));
788fe8d54f0SMauro Carvalho Chehab 	usleep_range(200, 250);
7890c0d06caSMauro Carvalho Chehab 	mt352_write(fe, reset,          sizeof(reset));
7900c0d06caSMauro Carvalho Chehab 	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
7910c0d06caSMauro Carvalho Chehab 	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
7920c0d06caSMauro Carvalho Chehab 	mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
7930c0d06caSMauro Carvalho Chehab 	mt352_write(fe, rs_err_cfg,     sizeof(rs_err_cfg));
7940c0d06caSMauro Carvalho Chehab 	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
7950c0d06caSMauro Carvalho Chehab 	mt352_write(fe, trl_nom_cfg,    sizeof(trl_nom_cfg));
7960c0d06caSMauro Carvalho Chehab 	mt352_write(fe, tps_given_cfg,  sizeof(tps_given_cfg));
7970c0d06caSMauro Carvalho Chehab 	mt352_write(fe, tuner_go,       sizeof(tuner_go));
7980c0d06caSMauro Carvalho Chehab 	return 0;
7990c0d06caSMauro Carvalho Chehab }
8000c0d06caSMauro Carvalho Chehab 
801ab4d1452SSatoshi Nagahama static void px_bcud_init(struct em28xx *dev)
802ab4d1452SSatoshi Nagahama {
803ab4d1452SSatoshi Nagahama 	int i;
804ba0c8e6eSColin Ian King 	static const struct {
805ab4d1452SSatoshi Nagahama 		unsigned char r[4];
806ab4d1452SSatoshi Nagahama 		int len;
807ab4d1452SSatoshi Nagahama 	} regs1[] = {
808ab4d1452SSatoshi Nagahama 		{{ 0x0e, 0x77 }, 2},
809ab4d1452SSatoshi Nagahama 		{{ 0x0f, 0x77 }, 2},
810ab4d1452SSatoshi Nagahama 		{{ 0x03, 0x90 }, 2},
811ab4d1452SSatoshi Nagahama 	}, regs2[] = {
812ab4d1452SSatoshi Nagahama 		{{ 0x07, 0x01 }, 2},
813ab4d1452SSatoshi Nagahama 		{{ 0x08, 0x10 }, 2},
814ab4d1452SSatoshi Nagahama 		{{ 0x13, 0x00 }, 2},
815ab4d1452SSatoshi Nagahama 		{{ 0x17, 0x00 }, 2},
816ab4d1452SSatoshi Nagahama 		{{ 0x03, 0x01 }, 2},
817ab4d1452SSatoshi Nagahama 		{{ 0x10, 0xb1 }, 2},
818ab4d1452SSatoshi Nagahama 		{{ 0x11, 0x40 }, 2},
819ab4d1452SSatoshi Nagahama 		{{ 0x85, 0x7a }, 2},
820ab4d1452SSatoshi Nagahama 		{{ 0x87, 0x04 }, 2},
821ab4d1452SSatoshi Nagahama 	};
822ba0c8e6eSColin Ian King 	static const struct em28xx_reg_seq gpio[] = {
823ab4d1452SSatoshi Nagahama 		{EM28XX_R06_I2C_CLK,		0x40,	0xff,	300},
824ab4d1452SSatoshi Nagahama 		{EM2874_R80_GPIO_P0_CTRL,	0xfd,	0xff,	60},
825ab4d1452SSatoshi Nagahama 		{EM28XX_R15_RGAIN,		0x20,	0xff,	0},
826ab4d1452SSatoshi Nagahama 		{EM28XX_R16_GGAIN,		0x20,	0xff,	0},
827ab4d1452SSatoshi Nagahama 		{EM28XX_R17_BGAIN,		0x20,	0xff,	0},
828ab4d1452SSatoshi Nagahama 		{EM28XX_R18_ROFFSET,		0x00,	0xff,	0},
829ab4d1452SSatoshi Nagahama 		{EM28XX_R19_GOFFSET,		0x00,	0xff,	0},
830ab4d1452SSatoshi Nagahama 		{EM28XX_R1A_BOFFSET,		0x00,	0xff,	0},
831ab4d1452SSatoshi Nagahama 		{EM28XX_R23_UOFFSET,		0x00,	0xff,	0},
832ab4d1452SSatoshi Nagahama 		{EM28XX_R24_VOFFSET,		0x00,	0xff,	0},
833ab4d1452SSatoshi Nagahama 		{EM28XX_R26_COMPR,		0x00,	0xff,	0},
834ab4d1452SSatoshi Nagahama 		{0x13,				0x08,	0xff,	0},
835ab4d1452SSatoshi Nagahama 		{EM28XX_R12_VINENABLE,		0x27,	0xff,	0},
836ab4d1452SSatoshi Nagahama 		{EM28XX_R0C_USBSUSP,		0x10,	0xff,	0},
837ab4d1452SSatoshi Nagahama 		{EM28XX_R27_OUTFMT,		0x00,	0xff,	0},
838ab4d1452SSatoshi Nagahama 		{EM28XX_R10_VINMODE,		0x00,	0xff,	0},
839ab4d1452SSatoshi Nagahama 		{EM28XX_R11_VINCTRL,		0x11,	0xff,	0},
840ab4d1452SSatoshi Nagahama 		{EM2874_R50_IR_CONFIG,		0x01,	0xff,	0},
841ab4d1452SSatoshi Nagahama 		{EM2874_R5F_TS_ENABLE,		0x80,	0xff,	0},
842ab4d1452SSatoshi Nagahama 		{EM28XX_R06_I2C_CLK,		0x46,	0xff,	0},
843ab4d1452SSatoshi Nagahama 	};
844ab4d1452SSatoshi Nagahama 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x46);
845ab4d1452SSatoshi Nagahama 	/* sleeping ISDB-T */
846ab4d1452SSatoshi Nagahama 	dev->dvb->i2c_client_demod->addr = 0x14;
847ab4d1452SSatoshi Nagahama 	for (i = 0; i < ARRAY_SIZE(regs1); i++)
848fe8d54f0SMauro Carvalho Chehab 		i2c_master_send(dev->dvb->i2c_client_demod,
849fe8d54f0SMauro Carvalho Chehab 				regs1[i].r, regs1[i].len);
850ab4d1452SSatoshi Nagahama 	/* sleeping ISDB-S */
851ab4d1452SSatoshi Nagahama 	dev->dvb->i2c_client_demod->addr = 0x15;
852ab4d1452SSatoshi Nagahama 	for (i = 0; i < ARRAY_SIZE(regs2); i++)
853ab4d1452SSatoshi Nagahama 		i2c_master_send(dev->dvb->i2c_client_demod, regs2[i].r,
854ab4d1452SSatoshi Nagahama 				regs2[i].len);
855ab4d1452SSatoshi Nagahama 	for (i = 0; i < ARRAY_SIZE(gpio); i++) {
856ab4d1452SSatoshi Nagahama 		em28xx_write_reg_bits(dev, gpio[i].reg, gpio[i].val,
857ab4d1452SSatoshi Nagahama 				      gpio[i].mask);
858ab4d1452SSatoshi Nagahama 		if (gpio[i].sleep > 0)
859ab4d1452SSatoshi Nagahama 			msleep(gpio[i].sleep);
860ab4d1452SSatoshi Nagahama 	}
861ab4d1452SSatoshi Nagahama };
862ab4d1452SSatoshi Nagahama 
8630c0d06caSMauro Carvalho Chehab static struct mt352_config terratec_xs_mt352_cfg = {
8640c0d06caSMauro Carvalho Chehab 	.demod_address = (0x1e >> 1),
8650c0d06caSMauro Carvalho Chehab 	.no_tuner = 1,
8660c0d06caSMauro Carvalho Chehab 	.if2 = 45600,
8670c0d06caSMauro Carvalho Chehab 	.demod_init = em28xx_mt352_terratec_xs_init,
8680c0d06caSMauro Carvalho Chehab };
8690c0d06caSMauro Carvalho Chehab 
8700c0d06caSMauro Carvalho Chehab static struct tda10023_config em28xx_tda10023_config = {
8710c0d06caSMauro Carvalho Chehab 	.demod_address = 0x0c,
8720c0d06caSMauro Carvalho Chehab 	.invert = 1,
8730c0d06caSMauro Carvalho Chehab };
8740c0d06caSMauro Carvalho Chehab 
8750c0d06caSMauro Carvalho Chehab static struct cxd2820r_config em28xx_cxd2820r_config = {
8760c0d06caSMauro Carvalho Chehab 	.i2c_address = (0xd8 >> 1),
8770c0d06caSMauro Carvalho Chehab 	.ts_mode = CXD2820R_TS_SERIAL,
8780c0d06caSMauro Carvalho Chehab };
8790c0d06caSMauro Carvalho Chehab 
8800c0d06caSMauro Carvalho Chehab static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
8810c0d06caSMauro Carvalho Chehab 	.output_opt = TDA18271_OUTPUT_LT_OFF,
8820c0d06caSMauro Carvalho Chehab 	.gate = TDA18271_GATE_DIGITAL,
8830c0d06caSMauro Carvalho Chehab };
8840c0d06caSMauro Carvalho Chehab 
8850c0d06caSMauro Carvalho Chehab static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
8860c0d06caSMauro Carvalho Chehab 	.demod_address = (0x1e >> 1),
8870c0d06caSMauro Carvalho Chehab 	.disable_i2c_gate_ctrl = 1,
8880c0d06caSMauro Carvalho Chehab 	.no_tuner = 1,
8890c0d06caSMauro Carvalho Chehab 	.parallel_ts = 1,
8900c0d06caSMauro Carvalho Chehab };
891fdf1bc9fSMauro Carvalho Chehab 
8928c47311dSAlberto Mardegan static struct mt2060_config em28xx_mt2060_config = {
8938c47311dSAlberto Mardegan 	.i2c_address = 0x60,
8948c47311dSAlberto Mardegan };
8958c47311dSAlberto Mardegan 
8960c0d06caSMauro Carvalho Chehab static struct qt1010_config em28xx_qt1010_config = {
8970c0d06caSMauro Carvalho Chehab 	.i2c_address = 0x62
8980c0d06caSMauro Carvalho Chehab };
8990c0d06caSMauro Carvalho Chehab 
9004159d01bSMauro Carvalho Chehab static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
9014159d01bSMauro Carvalho Chehab 	.demod_address = 0x10,
9024159d01bSMauro Carvalho Chehab 	.is_serial = true,
9034159d01bSMauro Carvalho Chehab };
9044159d01bSMauro Carvalho Chehab 
9054159d01bSMauro Carvalho Chehab static struct tda18271_std_map mb86a20s_tda18271_config = {
9064159d01bSMauro Carvalho Chehab 	.dvbt_6   = { .if_freq = 4000, .agc_mode = 3, .std = 4,
9074159d01bSMauro Carvalho Chehab 		      .if_lvl = 1, .rfagc_top = 0x37, },
9084159d01bSMauro Carvalho Chehab };
9094159d01bSMauro Carvalho Chehab 
9104159d01bSMauro Carvalho Chehab static struct tda18271_config c3tech_duo_tda18271_config = {
9114159d01bSMauro Carvalho Chehab 	.std_map = &mb86a20s_tda18271_config,
9124159d01bSMauro Carvalho Chehab 	.gate    = TDA18271_GATE_DIGITAL,
9134159d01bSMauro Carvalho Chehab 	.small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
9144159d01bSMauro Carvalho Chehab };
9154159d01bSMauro Carvalho Chehab 
91638b2df95SDevin Heitmueller static struct tda18271_std_map drx_j_std_map = {
91738b2df95SDevin Heitmueller 	.atsc_6   = { .if_freq = 5000, .agc_mode = 3, .std = 0, .if_lvl = 1,
91838b2df95SDevin Heitmueller 		      .rfagc_top = 0x37, },
91938b2df95SDevin Heitmueller 	.qam_6    = { .if_freq = 5380, .agc_mode = 3, .std = 3, .if_lvl = 1,
92038b2df95SDevin Heitmueller 		      .rfagc_top = 0x37, },
92138b2df95SDevin Heitmueller };
92238b2df95SDevin Heitmueller 
92338b2df95SDevin Heitmueller static struct tda18271_config pinnacle_80e_dvb_config = {
92438b2df95SDevin Heitmueller 	.std_map = &drx_j_std_map,
92538b2df95SDevin Heitmueller 	.gate    = TDA18271_GATE_DIGITAL,
92638b2df95SDevin Heitmueller 	.role    = TDA18271_MASTER,
92738b2df95SDevin Heitmueller };
92838b2df95SDevin Heitmueller 
9291586342eSKevin Cheng static struct lgdt3306a_config hauppauge_01595_lgdt3306a_config = {
9301586342eSKevin Cheng 	.qam_if_khz         = 4000,
9311586342eSKevin Cheng 	.vsb_if_khz         = 3250,
9321586342eSKevin Cheng 	.spectral_inversion = 0,
9331586342eSKevin Cheng 	.deny_i2c_rptr      = 0,
9341586342eSKevin Cheng 	.mpeg_mode          = LGDT3306A_MPEG_SERIAL,
9351586342eSKevin Cheng 	.tpclk_edge         = LGDT3306A_TPCLK_RISING_EDGE,
9361586342eSKevin Cheng 	.tpvalid_polarity   = LGDT3306A_TP_VALID_HIGH,
9371586342eSKevin Cheng 	.xtalMHz            = 25,
9381586342eSKevin Cheng };
9391586342eSKevin Cheng 
9400c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */
9410c0d06caSMauro Carvalho Chehab 
942f410b409SArnd Bergmann static noinline_for_stack int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
9430c0d06caSMauro Carvalho Chehab {
9440c0d06caSMauro Carvalho Chehab 	struct dvb_frontend *fe;
9450c0d06caSMauro Carvalho Chehab 	struct xc2028_config cfg;
946ee97207cSMauro Carvalho Chehab 	struct xc2028_ctrl ctl;
9470c0d06caSMauro Carvalho Chehab 
9480c0d06caSMauro Carvalho Chehab 	memset(&cfg, 0, sizeof(cfg));
949c7a45e5bSMauro Carvalho Chehab 	cfg.i2c_adap  = &dev->i2c_adap[dev->def_i2c_bus];
9500c0d06caSMauro Carvalho Chehab 	cfg.i2c_addr  = addr;
9510c0d06caSMauro Carvalho Chehab 
952ee97207cSMauro Carvalho Chehab 	memset(&ctl, 0, sizeof(ctl));
953ee97207cSMauro Carvalho Chehab 	em28xx_setup_xc3028(dev, &ctl);
954ee97207cSMauro Carvalho Chehab 	cfg.ctrl  = &ctl;
955ee97207cSMauro Carvalho Chehab 
9560c0d06caSMauro Carvalho Chehab 	if (!dev->dvb->fe[0]) {
95729b05e22SMauro Carvalho Chehab 		dev_err(&dev->intf->dev,
958ce8591ffSMauro Carvalho Chehab 			"dvb frontend not attached. Can't attach xc3028\n");
9590c0d06caSMauro Carvalho Chehab 		return -EINVAL;
9600c0d06caSMauro Carvalho Chehab 	}
9610c0d06caSMauro Carvalho Chehab 
9620c0d06caSMauro Carvalho Chehab 	fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
9630c0d06caSMauro Carvalho Chehab 	if (!fe) {
96429b05e22SMauro Carvalho Chehab 		dev_err(&dev->intf->dev, "xc3028 attach failed\n");
9650c0d06caSMauro Carvalho Chehab 		dvb_frontend_detach(dev->dvb->fe[0]);
9660c0d06caSMauro Carvalho Chehab 		dev->dvb->fe[0] = NULL;
9670c0d06caSMauro Carvalho Chehab 		return -EINVAL;
9680c0d06caSMauro Carvalho Chehab 	}
9690c0d06caSMauro Carvalho Chehab 
97029b05e22SMauro Carvalho Chehab 	dev_info(&dev->intf->dev, "xc3028 attached\n");
9710c0d06caSMauro Carvalho Chehab 
9720c0d06caSMauro Carvalho Chehab 	return 0;
9730c0d06caSMauro Carvalho Chehab }
9740c0d06caSMauro Carvalho Chehab 
9750c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */
9760c0d06caSMauro Carvalho Chehab 
9770c0d06caSMauro Carvalho Chehab static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
9780c0d06caSMauro Carvalho Chehab 			       struct em28xx *dev, struct device *device)
9790c0d06caSMauro Carvalho Chehab {
9800c0d06caSMauro Carvalho Chehab 	int result;
981e9ef88bdSMauro Carvalho Chehab 	bool create_rf_connector = false;
9820c0d06caSMauro Carvalho Chehab 
9830c0d06caSMauro Carvalho Chehab 	mutex_init(&dvb->lock);
9840c0d06caSMauro Carvalho Chehab 
9850c0d06caSMauro Carvalho Chehab 	/* register adapter */
986ce8591ffSMauro Carvalho Chehab 	result = dvb_register_adapter(&dvb->adapter,
98729b05e22SMauro Carvalho Chehab 				      dev_name(&dev->intf->dev), module,
988ce8591ffSMauro Carvalho Chehab 				      device, adapter_nr);
9890c0d06caSMauro Carvalho Chehab 	if (result < 0) {
99029b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
991ce8591ffSMauro Carvalho Chehab 			 "dvb_register_adapter failed (errno = %d)\n",
9922a96f60eSMauro Carvalho Chehab 			 result);
9930c0d06caSMauro Carvalho Chehab 		goto fail_adapter;
9940c0d06caSMauro Carvalho Chehab 	}
99537ecc7b1SMauro Carvalho Chehab #ifdef CONFIG_MEDIA_CONTROLLER_DVB
99637ecc7b1SMauro Carvalho Chehab 	dvb->adapter.mdev = dev->media_dev;
99737ecc7b1SMauro Carvalho Chehab #endif
9980c0d06caSMauro Carvalho Chehab 
9990c0d06caSMauro Carvalho Chehab 	/* Ensure all frontends negotiate bus access */
10000c0d06caSMauro Carvalho Chehab 	dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
10010c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
10020c0d06caSMauro Carvalho Chehab 		dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
10030c0d06caSMauro Carvalho Chehab 
10043de09fbbSHans Verkuil 	dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
10050c0d06caSMauro Carvalho Chehab 
10060c0d06caSMauro Carvalho Chehab 	/* register frontend */
10070c0d06caSMauro Carvalho Chehab 	result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
10080c0d06caSMauro Carvalho Chehab 	if (result < 0) {
100929b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
1010ce8591ffSMauro Carvalho Chehab 			 "dvb_register_frontend failed (errno = %d)\n",
10112a96f60eSMauro Carvalho Chehab 			 result);
10120c0d06caSMauro Carvalho Chehab 		goto fail_frontend0;
10130c0d06caSMauro Carvalho Chehab 	}
10140c0d06caSMauro Carvalho Chehab 
10150c0d06caSMauro Carvalho Chehab 	/* register 2nd frontend */
10160c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1]) {
10170c0d06caSMauro Carvalho Chehab 		result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
10180c0d06caSMauro Carvalho Chehab 		if (result < 0) {
101929b05e22SMauro Carvalho Chehab 			dev_warn(&dev->intf->dev,
1020ce8591ffSMauro Carvalho Chehab 				 "2nd dvb_register_frontend failed (errno = %d)\n",
10212a96f60eSMauro Carvalho Chehab 				 result);
10220c0d06caSMauro Carvalho Chehab 			goto fail_frontend1;
10230c0d06caSMauro Carvalho Chehab 		}
10240c0d06caSMauro Carvalho Chehab 	}
10250c0d06caSMauro Carvalho Chehab 
10260c0d06caSMauro Carvalho Chehab 	/* register demux stuff */
10270c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.capabilities =
10280c0d06caSMauro Carvalho Chehab 		DMX_TS_FILTERING | DMX_SECTION_FILTERING |
10290c0d06caSMauro Carvalho Chehab 		DMX_MEMORY_BASED_FILTERING;
10300c0d06caSMauro Carvalho Chehab 	dvb->demux.priv       = dvb;
10310c0d06caSMauro Carvalho Chehab 	dvb->demux.filternum  = 256;
10320c0d06caSMauro Carvalho Chehab 	dvb->demux.feednum    = 256;
10330c0d06caSMauro Carvalho Chehab 	dvb->demux.start_feed = em28xx_start_feed;
10340c0d06caSMauro Carvalho Chehab 	dvb->demux.stop_feed  = em28xx_stop_feed;
10350c0d06caSMauro Carvalho Chehab 
10360c0d06caSMauro Carvalho Chehab 	result = dvb_dmx_init(&dvb->demux);
10370c0d06caSMauro Carvalho Chehab 	if (result < 0) {
103829b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
1039ce8591ffSMauro Carvalho Chehab 			 "dvb_dmx_init failed (errno = %d)\n",
1040ce8591ffSMauro Carvalho Chehab 			 result);
10410c0d06caSMauro Carvalho Chehab 		goto fail_dmx;
10420c0d06caSMauro Carvalho Chehab 	}
10430c0d06caSMauro Carvalho Chehab 
10440c0d06caSMauro Carvalho Chehab 	dvb->dmxdev.filternum    = 256;
10450c0d06caSMauro Carvalho Chehab 	dvb->dmxdev.demux        = &dvb->demux.dmx;
10460c0d06caSMauro Carvalho Chehab 	dvb->dmxdev.capabilities = 0;
10470c0d06caSMauro Carvalho Chehab 	result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
10480c0d06caSMauro Carvalho Chehab 	if (result < 0) {
104929b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
1050ce8591ffSMauro Carvalho Chehab 			 "dvb_dmxdev_init failed (errno = %d)\n",
1051ce8591ffSMauro Carvalho Chehab 			 result);
10520c0d06caSMauro Carvalho Chehab 		goto fail_dmxdev;
10530c0d06caSMauro Carvalho Chehab 	}
10540c0d06caSMauro Carvalho Chehab 
10550c0d06caSMauro Carvalho Chehab 	dvb->fe_hw.source = DMX_FRONTEND_0;
10560c0d06caSMauro Carvalho Chehab 	result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
10570c0d06caSMauro Carvalho Chehab 	if (result < 0) {
105829b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
1059ce8591ffSMauro Carvalho Chehab 			 "add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
10602a96f60eSMauro Carvalho Chehab 			 result);
10610c0d06caSMauro Carvalho Chehab 		goto fail_fe_hw;
10620c0d06caSMauro Carvalho Chehab 	}
10630c0d06caSMauro Carvalho Chehab 
10640c0d06caSMauro Carvalho Chehab 	dvb->fe_mem.source = DMX_MEMORY_FE;
10650c0d06caSMauro Carvalho Chehab 	result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
10660c0d06caSMauro Carvalho Chehab 	if (result < 0) {
106729b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
1068ce8591ffSMauro Carvalho Chehab 			 "add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
10692a96f60eSMauro Carvalho Chehab 			 result);
10700c0d06caSMauro Carvalho Chehab 		goto fail_fe_mem;
10710c0d06caSMauro Carvalho Chehab 	}
10720c0d06caSMauro Carvalho Chehab 
10730c0d06caSMauro Carvalho Chehab 	result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
10740c0d06caSMauro Carvalho Chehab 	if (result < 0) {
107529b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
1076ce8591ffSMauro Carvalho Chehab 			 "connect_frontend failed (errno = %d)\n",
1077ce8591ffSMauro Carvalho Chehab 			 result);
10780c0d06caSMauro Carvalho Chehab 		goto fail_fe_conn;
10790c0d06caSMauro Carvalho Chehab 	}
10800c0d06caSMauro Carvalho Chehab 
10810c0d06caSMauro Carvalho Chehab 	/* register network adapter */
10820c0d06caSMauro Carvalho Chehab 	dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
108337ecc7b1SMauro Carvalho Chehab 
1084e9ef88bdSMauro Carvalho Chehab 	/* If the analog part won't create RF connectors, DVB will do it */
1085fe8d54f0SMauro Carvalho Chehab 	if (!dev->has_video || dev->tuner_type == TUNER_ABSENT)
1086e9ef88bdSMauro Carvalho Chehab 		create_rf_connector = true;
1087e9ef88bdSMauro Carvalho Chehab 
1088e9ef88bdSMauro Carvalho Chehab 	result = dvb_create_media_graph(&dvb->adapter, create_rf_connector);
108937ecc7b1SMauro Carvalho Chehab 	if (result < 0)
109037ecc7b1SMauro Carvalho Chehab 		goto fail_create_graph;
109137ecc7b1SMauro Carvalho Chehab 
10920c0d06caSMauro Carvalho Chehab 	return 0;
10930c0d06caSMauro Carvalho Chehab 
109437ecc7b1SMauro Carvalho Chehab fail_create_graph:
109537ecc7b1SMauro Carvalho Chehab 	dvb_net_release(&dvb->net);
10960c0d06caSMauro Carvalho Chehab fail_fe_conn:
10970c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
10980c0d06caSMauro Carvalho Chehab fail_fe_mem:
10990c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
11000c0d06caSMauro Carvalho Chehab fail_fe_hw:
11010c0d06caSMauro Carvalho Chehab 	dvb_dmxdev_release(&dvb->dmxdev);
11020c0d06caSMauro Carvalho Chehab fail_dmxdev:
11030c0d06caSMauro Carvalho Chehab 	dvb_dmx_release(&dvb->demux);
11040c0d06caSMauro Carvalho Chehab fail_dmx:
11050c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
11060c0d06caSMauro Carvalho Chehab 		dvb_unregister_frontend(dvb->fe[1]);
11070c0d06caSMauro Carvalho Chehab 	dvb_unregister_frontend(dvb->fe[0]);
11080c0d06caSMauro Carvalho Chehab fail_frontend1:
11090c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
11100c0d06caSMauro Carvalho Chehab 		dvb_frontend_detach(dvb->fe[1]);
11110c0d06caSMauro Carvalho Chehab fail_frontend0:
11120c0d06caSMauro Carvalho Chehab 	dvb_frontend_detach(dvb->fe[0]);
11130c0d06caSMauro Carvalho Chehab 	dvb_unregister_adapter(&dvb->adapter);
11140c0d06caSMauro Carvalho Chehab fail_adapter:
11150c0d06caSMauro Carvalho Chehab 	return result;
11160c0d06caSMauro Carvalho Chehab }
11170c0d06caSMauro Carvalho Chehab 
11180c0d06caSMauro Carvalho Chehab static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
11190c0d06caSMauro Carvalho Chehab {
11200c0d06caSMauro Carvalho Chehab 	dvb_net_release(&dvb->net);
11210c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
11220c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
11230c0d06caSMauro Carvalho Chehab 	dvb_dmxdev_release(&dvb->dmxdev);
11240c0d06caSMauro Carvalho Chehab 	dvb_dmx_release(&dvb->demux);
11250c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
11260c0d06caSMauro Carvalho Chehab 		dvb_unregister_frontend(dvb->fe[1]);
11270c0d06caSMauro Carvalho Chehab 	dvb_unregister_frontend(dvb->fe[0]);
11280c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1] && !dvb->dont_attach_fe1)
11290c0d06caSMauro Carvalho Chehab 		dvb_frontend_detach(dvb->fe[1]);
11300c0d06caSMauro Carvalho Chehab 	dvb_frontend_detach(dvb->fe[0]);
11310c0d06caSMauro Carvalho Chehab 	dvb_unregister_adapter(&dvb->adapter);
11320c0d06caSMauro Carvalho Chehab }
11330c0d06caSMauro Carvalho Chehab 
1134ad32495bSMauro Carvalho Chehab static int em28174_dvb_init_pctv_460e(struct em28xx *dev)
1135f410b409SArnd Bergmann {
1136f410b409SArnd Bergmann 	struct em28xx_dvb *dvb = dev->dvb;
1137f410b409SArnd Bergmann 	struct tda10071_platform_data tda10071_pdata = {};
1138f410b409SArnd Bergmann 	struct a8293_platform_data a8293_pdata = {};
1139f410b409SArnd Bergmann 
1140f410b409SArnd Bergmann 	/* attach demod + tuner combo */
1141ad32495bSMauro Carvalho Chehab 	tda10071_pdata.clk = 40444000; /* 40.444 MHz */
1142ad32495bSMauro Carvalho Chehab 	tda10071_pdata.i2c_wr_max = 64;
1143ad32495bSMauro Carvalho Chehab 	tda10071_pdata.ts_mode = TDA10071_TS_SERIAL;
1144ad32495bSMauro Carvalho Chehab 	tda10071_pdata.pll_multiplier = 20;
1145ad32495bSMauro Carvalho Chehab 	tda10071_pdata.tuner_i2c_addr = 0x14;
1146ad32495bSMauro Carvalho Chehab 
1147ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_demod = dvb_module_probe("tda10071", "tda10071_cx24118",
1148ad32495bSMauro Carvalho Chehab 						 &dev->i2c_adap[dev->def_i2c_bus],
1149ad32495bSMauro Carvalho Chehab 						 0x55, &tda10071_pdata);
1150ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_demod)
1151ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1152ad32495bSMauro Carvalho Chehab 
1153ad32495bSMauro Carvalho Chehab 	dvb->fe[0] = tda10071_pdata.get_dvb_frontend(dvb->i2c_client_demod);
1154f410b409SArnd Bergmann 
1155f410b409SArnd Bergmann 	/* attach SEC */
1156f410b409SArnd Bergmann 	a8293_pdata.dvb_frontend = dvb->fe[0];
1157ad32495bSMauro Carvalho Chehab 
1158ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_sec = dvb_module_probe("a8293", NULL,
1159ad32495bSMauro Carvalho Chehab 					       &dev->i2c_adap[dev->def_i2c_bus],
1160ad32495bSMauro Carvalho Chehab 					       0x08, &a8293_pdata);
1161ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_sec) {
1162ad32495bSMauro Carvalho Chehab 		dvb_module_release(dvb->i2c_client_demod);
1163ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1164f410b409SArnd Bergmann 	}
1165f410b409SArnd Bergmann 
1166ad32495bSMauro Carvalho Chehab 	return 0;
1167ad32495bSMauro Carvalho Chehab }
1168ad32495bSMauro Carvalho Chehab 
1169ad32495bSMauro Carvalho Chehab static int em28178_dvb_init_pctv_461e(struct em28xx *dev)
1170f410b409SArnd Bergmann {
1171f410b409SArnd Bergmann 	struct em28xx_dvb *dvb = dev->dvb;
1172f410b409SArnd Bergmann 	struct i2c_adapter *i2c_adapter;
1173f410b409SArnd Bergmann 	struct m88ds3103_platform_data m88ds3103_pdata = {};
1174f410b409SArnd Bergmann 	struct ts2020_config ts2020_config = {};
1175f410b409SArnd Bergmann 	struct a8293_platform_data a8293_pdata = {};
1176f410b409SArnd Bergmann 
1177f410b409SArnd Bergmann 	/* attach demod */
1178f410b409SArnd Bergmann 	m88ds3103_pdata.clk = 27000000;
1179f410b409SArnd Bergmann 	m88ds3103_pdata.i2c_wr_max = 33;
1180f410b409SArnd Bergmann 	m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL;
1181f410b409SArnd Bergmann 	m88ds3103_pdata.ts_clk = 16000;
1182f410b409SArnd Bergmann 	m88ds3103_pdata.ts_clk_pol = 1;
1183f410b409SArnd Bergmann 	m88ds3103_pdata.agc = 0x99;
1184ad32495bSMauro Carvalho Chehab 
1185ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_demod = dvb_module_probe("m88ds3103", NULL,
1186ad32495bSMauro Carvalho Chehab 						 &dev->i2c_adap[dev->def_i2c_bus],
1187ad32495bSMauro Carvalho Chehab 						 0x68, &m88ds3103_pdata);
1188ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_demod)
1189ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1190ad32495bSMauro Carvalho Chehab 
1191ad32495bSMauro Carvalho Chehab 	dvb->fe[0] = m88ds3103_pdata.get_dvb_frontend(dvb->i2c_client_demod);
1192ad32495bSMauro Carvalho Chehab 	i2c_adapter = m88ds3103_pdata.get_i2c_adapter(dvb->i2c_client_demod);
1193f410b409SArnd Bergmann 
1194f410b409SArnd Bergmann 	/* attach tuner */
1195f410b409SArnd Bergmann 	ts2020_config.fe = dvb->fe[0];
1196ad32495bSMauro Carvalho Chehab 
1197ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_tuner = dvb_module_probe("ts2020", "ts2022",
1198ad32495bSMauro Carvalho Chehab 						 i2c_adapter,
1199ad32495bSMauro Carvalho Chehab 						 0x60, &ts2020_config);
1200ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_tuner) {
1201ad32495bSMauro Carvalho Chehab 		dvb_module_release(dvb->i2c_client_demod);
1202ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1203f410b409SArnd Bergmann 	}
1204ad32495bSMauro Carvalho Chehab 
1205f410b409SArnd Bergmann 	/* delegate signal strength measurement to tuner */
1206f410b409SArnd Bergmann 	dvb->fe[0]->ops.read_signal_strength =
1207f410b409SArnd Bergmann 			dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1208f410b409SArnd Bergmann 
1209f410b409SArnd Bergmann 	/* attach SEC */
1210f410b409SArnd Bergmann 	a8293_pdata.dvb_frontend = dvb->fe[0];
1211ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_sec = dvb_module_probe("a8293", NULL,
1212ad32495bSMauro Carvalho Chehab 					       &dev->i2c_adap[dev->def_i2c_bus],
1213ad32495bSMauro Carvalho Chehab 					       0x08, &a8293_pdata);
1214ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_sec) {
1215ad32495bSMauro Carvalho Chehab 		dvb_module_release(dvb->i2c_client_tuner);
1216ad32495bSMauro Carvalho Chehab 		dvb_module_release(dvb->i2c_client_demod);
1217ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1218f410b409SArnd Bergmann 	}
1219f410b409SArnd Bergmann 
1220ad32495bSMauro Carvalho Chehab 	return 0;
1221ad32495bSMauro Carvalho Chehab }
1222ad32495bSMauro Carvalho Chehab 
1223985b0edeSBrad Love static int em28178_dvb_init_pctv_461e_v2(struct em28xx *dev)
1224985b0edeSBrad Love {
1225985b0edeSBrad Love 	struct em28xx_dvb *dvb = dev->dvb;
1226985b0edeSBrad Love 	struct i2c_adapter *i2c_adapter;
1227985b0edeSBrad Love 	struct m88ds3103_platform_data m88ds3103_pdata = {};
1228985b0edeSBrad Love 	struct ts2020_config ts2020_config = {};
1229985b0edeSBrad Love 	struct a8293_platform_data a8293_pdata = {};
1230985b0edeSBrad Love 
1231985b0edeSBrad Love 	/* attach demod */
1232985b0edeSBrad Love 	m88ds3103_pdata.clk = 27000000;
1233985b0edeSBrad Love 	m88ds3103_pdata.i2c_wr_max = 33;
1234985b0edeSBrad Love 	m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL;
1235985b0edeSBrad Love 	m88ds3103_pdata.ts_clk = 16000;
1236985b0edeSBrad Love 	m88ds3103_pdata.ts_clk_pol = 0;
1237985b0edeSBrad Love 	m88ds3103_pdata.agc = 0x99;
1238985b0edeSBrad Love 	m88ds3103_pdata.agc_inv = 0;
1239985b0edeSBrad Love 	m88ds3103_pdata.spec_inv = 0;
1240985b0edeSBrad Love 	dvb->i2c_client_demod = dvb_module_probe("m88ds3103", "m88ds3103b",
1241985b0edeSBrad Love 						 &dev->i2c_adap[dev->def_i2c_bus],
1242985b0edeSBrad Love 						 0x6a, &m88ds3103_pdata);
1243985b0edeSBrad Love 
1244985b0edeSBrad Love 	if (!dvb->i2c_client_demod)
1245985b0edeSBrad Love 		return -ENODEV;
1246985b0edeSBrad Love 
1247985b0edeSBrad Love 	dvb->fe[0] = m88ds3103_pdata.get_dvb_frontend(dvb->i2c_client_demod);
1248985b0edeSBrad Love 	i2c_adapter = m88ds3103_pdata.get_i2c_adapter(dvb->i2c_client_demod);
1249985b0edeSBrad Love 
1250985b0edeSBrad Love 	/* attach tuner */
1251985b0edeSBrad Love 	ts2020_config.fe = dvb->fe[0];
1252985b0edeSBrad Love 	dvb->i2c_client_tuner = dvb_module_probe("ts2020", "ts2022",
1253985b0edeSBrad Love 						 i2c_adapter,
1254985b0edeSBrad Love 						 0x60, &ts2020_config);
1255985b0edeSBrad Love 	if (!dvb->i2c_client_tuner) {
1256985b0edeSBrad Love 		dvb_module_release(dvb->i2c_client_demod);
1257985b0edeSBrad Love 		return -ENODEV;
1258985b0edeSBrad Love 	}
1259985b0edeSBrad Love 
1260985b0edeSBrad Love 	/* delegate signal strength measurement to tuner */
1261985b0edeSBrad Love 	dvb->fe[0]->ops.read_signal_strength =
1262985b0edeSBrad Love 			dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1263985b0edeSBrad Love 
1264985b0edeSBrad Love 	/* attach SEC */
1265985b0edeSBrad Love 	a8293_pdata.dvb_frontend = dvb->fe[0];
1266985b0edeSBrad Love 	dvb->i2c_client_sec = dvb_module_probe("a8293", NULL,
1267985b0edeSBrad Love 					       &dev->i2c_adap[dev->def_i2c_bus],
1268985b0edeSBrad Love 					       0x08, &a8293_pdata);
1269985b0edeSBrad Love 	if (!dvb->i2c_client_sec) {
1270985b0edeSBrad Love 		dvb_module_release(dvb->i2c_client_tuner);
1271985b0edeSBrad Love 		dvb_module_release(dvb->i2c_client_demod);
1272985b0edeSBrad Love 		return -ENODEV;
1273985b0edeSBrad Love 	}
1274985b0edeSBrad Love 
1275985b0edeSBrad Love 	return 0;
1276985b0edeSBrad Love }
1277985b0edeSBrad Love 
1278ad32495bSMauro Carvalho Chehab static int em28178_dvb_init_pctv_292e(struct em28xx *dev)
1279f410b409SArnd Bergmann {
1280f410b409SArnd Bergmann 	struct em28xx_dvb *dvb = dev->dvb;
1281f410b409SArnd Bergmann 	struct i2c_adapter *adapter;
1282ad32495bSMauro Carvalho Chehab 	struct si2168_config si2168_config = {};
1283ad32495bSMauro Carvalho Chehab 	struct si2157_config si2157_config = {};
1284f410b409SArnd Bergmann 
1285f410b409SArnd Bergmann 	/* attach demod */
1286f410b409SArnd Bergmann 	si2168_config.i2c_adapter = &adapter;
1287f410b409SArnd Bergmann 	si2168_config.fe = &dvb->fe[0];
1288f410b409SArnd Bergmann 	si2168_config.ts_mode = SI2168_TS_PARALLEL;
1289309d4c4cSBrad Love 	si2168_config.spectral_inversion = true;
1290f410b409SArnd Bergmann 
1291ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_demod = dvb_module_probe("si2168", NULL,
1292ad32495bSMauro Carvalho Chehab 						 &dev->i2c_adap[dev->def_i2c_bus],
1293ad32495bSMauro Carvalho Chehab 						 0x64, &si2168_config);
1294ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_demod)
1295ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1296f410b409SArnd Bergmann 
1297f410b409SArnd Bergmann 	/* attach tuner */
1298f410b409SArnd Bergmann 	si2157_config.fe = dvb->fe[0];
1299f410b409SArnd Bergmann 	si2157_config.if_port = 1;
1300f410b409SArnd Bergmann #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1301f410b409SArnd Bergmann 	si2157_config.mdev = dev->media_dev;
1302f410b409SArnd Bergmann #endif
1303ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL,
1304ad32495bSMauro Carvalho Chehab 						 adapter,
1305ad32495bSMauro Carvalho Chehab 						 0x60, &si2157_config);
1306ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_tuner) {
1307ad32495bSMauro Carvalho Chehab 		dvb_module_release(dvb->i2c_client_demod);
1308ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1309f410b409SArnd Bergmann 	}
1310f410b409SArnd Bergmann 	dvb->fe[0]->ops.set_lna = em28xx_pctv_292e_set_lna;
1311ad32495bSMauro Carvalho Chehab 
1312ad32495bSMauro Carvalho Chehab 	return 0;
1313f410b409SArnd Bergmann }
1314f410b409SArnd Bergmann 
1315ad32495bSMauro Carvalho Chehab static int em28178_dvb_init_terratec_t2_stick_hd(struct em28xx *dev)
1316f410b409SArnd Bergmann {
1317f410b409SArnd Bergmann 	struct em28xx_dvb *dvb = dev->dvb;
1318f410b409SArnd Bergmann 	struct i2c_adapter *adapter;
1319ad32495bSMauro Carvalho Chehab 	struct si2168_config si2168_config = {};
1320ad32495bSMauro Carvalho Chehab 	struct si2157_config si2157_config = {};
1321f410b409SArnd Bergmann 
1322f410b409SArnd Bergmann 	/* attach demod */
1323f410b409SArnd Bergmann 	si2168_config.i2c_adapter = &adapter;
1324f410b409SArnd Bergmann 	si2168_config.fe = &dvb->fe[0];
1325f410b409SArnd Bergmann 	si2168_config.ts_mode = SI2168_TS_PARALLEL;
1326f410b409SArnd Bergmann 
1327ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_demod = dvb_module_probe("si2168", NULL,
1328ad32495bSMauro Carvalho Chehab 						 &dev->i2c_adap[dev->def_i2c_bus],
1329ad32495bSMauro Carvalho Chehab 						 0x64, &si2168_config);
1330ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_demod)
1331ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1332f410b409SArnd Bergmann 
1333f410b409SArnd Bergmann 	/* attach tuner */
1334f410b409SArnd Bergmann 	memset(&si2157_config, 0, sizeof(si2157_config));
1335f410b409SArnd Bergmann 	si2157_config.fe = dvb->fe[0];
1336f410b409SArnd Bergmann 	si2157_config.if_port = 0;
1337f410b409SArnd Bergmann #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1338f410b409SArnd Bergmann 	si2157_config.mdev = dev->media_dev;
1339f410b409SArnd Bergmann #endif
1340ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_tuner = dvb_module_probe("si2157", "si2146",
1341ad32495bSMauro Carvalho Chehab 						 adapter,
1342ad32495bSMauro Carvalho Chehab 						 0x60, &si2157_config);
1343ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_tuner) {
1344ad32495bSMauro Carvalho Chehab 		dvb_module_release(dvb->i2c_client_demod);
1345ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1346f410b409SArnd Bergmann 	}
1347f410b409SArnd Bergmann 
1348ad32495bSMauro Carvalho Chehab 	return 0;
1349f410b409SArnd Bergmann }
1350f410b409SArnd Bergmann 
1351ad32495bSMauro Carvalho Chehab static int em28178_dvb_init_plex_px_bcud(struct em28xx *dev)
1352f410b409SArnd Bergmann {
1353f410b409SArnd Bergmann 	struct em28xx_dvb *dvb = dev->dvb;
1354ad32495bSMauro Carvalho Chehab 	struct tc90522_config tc90522_config = {};
1355ad32495bSMauro Carvalho Chehab 	struct qm1d1c0042_config qm1d1c0042_config = {};
1356f410b409SArnd Bergmann 
1357f410b409SArnd Bergmann 	/* attach demod */
1358ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_demod = dvb_module_probe("tc90522", "tc90522sat",
1359ad32495bSMauro Carvalho Chehab 						 &dev->i2c_adap[dev->def_i2c_bus],
1360ad32495bSMauro Carvalho Chehab 						 0x15, &tc90522_config);
1361ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_demod)
1362ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1363f410b409SArnd Bergmann 
1364f410b409SArnd Bergmann 	/* attach tuner */
1365f410b409SArnd Bergmann 	qm1d1c0042_config.fe = tc90522_config.fe;
1366f410b409SArnd Bergmann 	qm1d1c0042_config.lpf = 1;
1367ad32495bSMauro Carvalho Chehab 
1368ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_tuner = dvb_module_probe("qm1d1c0042", NULL,
1369ad32495bSMauro Carvalho Chehab 						 tc90522_config.tuner_i2c,
1370ad32495bSMauro Carvalho Chehab 						 0x61, &qm1d1c0042_config);
1371ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_tuner) {
1372ad32495bSMauro Carvalho Chehab 		dvb_module_release(dvb->i2c_client_demod);
1373ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1374f410b409SArnd Bergmann 	}
1375f410b409SArnd Bergmann 
1376ad32495bSMauro Carvalho Chehab 	dvb->fe[0] = tc90522_config.fe;
1377ad32495bSMauro Carvalho Chehab 	px_bcud_init(dev);
1378ad32495bSMauro Carvalho Chehab 
1379ad32495bSMauro Carvalho Chehab 	return 0;
1380ad32495bSMauro Carvalho Chehab }
1381ad32495bSMauro Carvalho Chehab 
1382ad32495bSMauro Carvalho Chehab static int em28174_dvb_init_hauppauge_wintv_dualhd_dvb(struct em28xx *dev)
1383f410b409SArnd Bergmann {
1384f410b409SArnd Bergmann 	struct em28xx_dvb *dvb = dev->dvb;
1385f410b409SArnd Bergmann 	struct i2c_adapter *adapter;
1386ad32495bSMauro Carvalho Chehab 	struct si2168_config si2168_config = {};
1387ad32495bSMauro Carvalho Chehab 	struct si2157_config si2157_config = {};
1388ad32495bSMauro Carvalho Chehab 	unsigned char addr;
1389f410b409SArnd Bergmann 
1390f410b409SArnd Bergmann 	/* attach demod */
1391f410b409SArnd Bergmann 	si2168_config.i2c_adapter = &adapter;
1392f410b409SArnd Bergmann 	si2168_config.fe = &dvb->fe[0];
1393f410b409SArnd Bergmann 	si2168_config.ts_mode = SI2168_TS_SERIAL;
1394309d4c4cSBrad Love 	si2168_config.spectral_inversion = true;
1395ad32495bSMauro Carvalho Chehab 	addr = (dev->ts == PRIMARY_TS) ? 0x64 : 0x67;
1396f410b409SArnd Bergmann 
1397ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_demod = dvb_module_probe("si2168", NULL,
1398ad32495bSMauro Carvalho Chehab 						 &dev->i2c_adap[dev->def_i2c_bus],
1399ad32495bSMauro Carvalho Chehab 						 addr, &si2168_config);
1400ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_demod)
1401ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1402f410b409SArnd Bergmann 
1403f410b409SArnd Bergmann 	/* attach tuner */
1404f410b409SArnd Bergmann 	memset(&si2157_config, 0, sizeof(si2157_config));
1405f410b409SArnd Bergmann 	si2157_config.fe = dvb->fe[0];
1406f410b409SArnd Bergmann 	si2157_config.if_port = 1;
1407f410b409SArnd Bergmann #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1408f410b409SArnd Bergmann 	si2157_config.mdev = dev->media_dev;
1409f410b409SArnd Bergmann #endif
1410ad32495bSMauro Carvalho Chehab 	addr = (dev->ts == PRIMARY_TS) ? 0x60 : 0x63;
1411ad32495bSMauro Carvalho Chehab 
1412ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL,
1413ad32495bSMauro Carvalho Chehab 						 adapter,
1414ad32495bSMauro Carvalho Chehab 						 addr, &si2157_config);
1415ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_tuner) {
1416ad32495bSMauro Carvalho Chehab 		dvb_module_release(dvb->i2c_client_demod);
1417ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1418f410b409SArnd Bergmann 	}
1419f410b409SArnd Bergmann 
1420ad32495bSMauro Carvalho Chehab 	return 0;
1421f410b409SArnd Bergmann }
1422f410b409SArnd Bergmann 
1423f410b409SArnd Bergmann static int em28174_dvb_init_hauppauge_wintv_dualhd_01595(struct em28xx *dev)
1424f410b409SArnd Bergmann {
1425f410b409SArnd Bergmann 	struct em28xx_dvb *dvb = dev->dvb;
1426f410b409SArnd Bergmann 	struct i2c_adapter *adapter;
1427ad32495bSMauro Carvalho Chehab 	struct lgdt3306a_config lgdt3306a_config =  {};
1428f410b409SArnd Bergmann 	struct si2157_config si2157_config = {};
1429ad32495bSMauro Carvalho Chehab 	unsigned char addr;
1430f410b409SArnd Bergmann 
1431f410b409SArnd Bergmann 	/* attach demod */
1432f410b409SArnd Bergmann 	lgdt3306a_config = hauppauge_01595_lgdt3306a_config;
1433f410b409SArnd Bergmann 	lgdt3306a_config.fe = &dvb->fe[0];
1434f410b409SArnd Bergmann 	lgdt3306a_config.i2c_adapter = &adapter;
1435ad32495bSMauro Carvalho Chehab 	addr = (dev->ts == PRIMARY_TS) ? 0x59 : 0x0e;
1436f410b409SArnd Bergmann 
1437ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_demod = dvb_module_probe("lgdt3306a", NULL,
1438ad32495bSMauro Carvalho Chehab 						 &dev->i2c_adap[dev->def_i2c_bus],
1439ad32495bSMauro Carvalho Chehab 						 addr, &lgdt3306a_config);
1440ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_demod)
1441ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1442f410b409SArnd Bergmann 
1443f410b409SArnd Bergmann 	/* attach tuner */
1444f410b409SArnd Bergmann 	si2157_config.fe = dvb->fe[0];
1445f410b409SArnd Bergmann 	si2157_config.if_port = 1;
1446f410b409SArnd Bergmann 	si2157_config.inversion = 1;
1447f410b409SArnd Bergmann #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1448f410b409SArnd Bergmann 	si2157_config.mdev = dev->media_dev;
1449f410b409SArnd Bergmann #endif
1450ad32495bSMauro Carvalho Chehab 	addr = (dev->ts == PRIMARY_TS) ? 0x60 : 0x62;
1451f410b409SArnd Bergmann 
1452ad32495bSMauro Carvalho Chehab 	dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL,
1453ad32495bSMauro Carvalho Chehab 						 adapter,
145401affb00SBrad Love 						 addr, &si2157_config);
1455ad32495bSMauro Carvalho Chehab 	if (!dvb->i2c_client_tuner) {
1456ad32495bSMauro Carvalho Chehab 		dvb_module_release(dvb->i2c_client_demod);
1457ad32495bSMauro Carvalho Chehab 		return -ENODEV;
1458f410b409SArnd Bergmann 	}
1459f410b409SArnd Bergmann 
1460ad32495bSMauro Carvalho Chehab 	return 0;
1461f410b409SArnd Bergmann }
1462ad32495bSMauro Carvalho Chehab 
14632e74a01fSBrad Love static int em2874_dvb_init_hauppauge_usb_quadhd(struct em28xx *dev)
14642e74a01fSBrad Love {
14652e74a01fSBrad Love 	struct em28xx_dvb *dvb = dev->dvb;
14662e74a01fSBrad Love 	struct mxl692_config mxl692_config = {};
14672e74a01fSBrad Love 	unsigned char addr;
14682e74a01fSBrad Love 
14692e74a01fSBrad Love 	/* attach demod/tuner combo */
14702e74a01fSBrad Love 	mxl692_config.id = (dev->ts == PRIMARY_TS) ? 0 : 1;
14712e74a01fSBrad Love 	mxl692_config.fe = &dvb->fe[0];
14722e74a01fSBrad Love 	addr = (dev->ts == PRIMARY_TS) ? 0x60 : 0x63;
14732e74a01fSBrad Love 
14742e74a01fSBrad Love 	dvb->i2c_client_demod = dvb_module_probe("mxl692", NULL,
14752e74a01fSBrad Love 						 &dev->i2c_adap[dev->def_i2c_bus],
14762e74a01fSBrad Love 						 addr, &mxl692_config);
14772e74a01fSBrad Love 	if (!dvb->i2c_client_demod)
14782e74a01fSBrad Love 		return -ENODEV;
14792e74a01fSBrad Love 
14802e74a01fSBrad Love 	return 0;
14812e74a01fSBrad Love }
14822e74a01fSBrad Love 
14830c0d06caSMauro Carvalho Chehab static int em28xx_dvb_init(struct em28xx *dev)
14840c0d06caSMauro Carvalho Chehab {
1485be7fd3c3SBrad Love 	int result = 0, dvb_alt = 0;
14860c0d06caSMauro Carvalho Chehab 	struct em28xx_dvb *dvb;
1487be7fd3c3SBrad Love 	struct usb_device *udev;
14880c0d06caSMauro Carvalho Chehab 
1489822b8deaSMauro Carvalho Chehab 	if (dev->is_audio_only) {
1490822b8deaSMauro Carvalho Chehab 		/* Shouldn't initialize IR for this interface */
1491822b8deaSMauro Carvalho Chehab 		return 0;
1492822b8deaSMauro Carvalho Chehab 	}
1493822b8deaSMauro Carvalho Chehab 
14940c0d06caSMauro Carvalho Chehab 	if (!dev->board.has_dvb) {
14950c0d06caSMauro Carvalho Chehab 		/* This device does not support the extension */
14960c0d06caSMauro Carvalho Chehab 		return 0;
14970c0d06caSMauro Carvalho Chehab 	}
14980c0d06caSMauro Carvalho Chehab 
149929b05e22SMauro Carvalho Chehab 	dev_info(&dev->intf->dev, "Binding DVB extension\n");
15009634614fSMauro Carvalho Chehab 
1501fe8d54f0SMauro Carvalho Chehab 	dvb = kzalloc(sizeof(*dvb), GFP_KERNEL);
15028314d402SMauro Carvalho Chehab 	if (!dvb)
15030c0d06caSMauro Carvalho Chehab 		return -ENOMEM;
15048314d402SMauro Carvalho Chehab 
15050c0d06caSMauro Carvalho Chehab 	dev->dvb = dvb;
1506fe8d54f0SMauro Carvalho Chehab 	dvb->fe[0] = NULL;
1507fe8d54f0SMauro Carvalho Chehab 	dvb->fe[1] = NULL;
15080c0d06caSMauro Carvalho Chehab 
150927ba0dacSFrank Schaefer 	/* pre-allocate DVB usb transfer buffers */
151027ba0dacSFrank Schaefer 	if (dev->dvb_xfer_bulk) {
151127ba0dacSFrank Schaefer 		result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
151227ba0dacSFrank Schaefer 					   dev->dvb_xfer_bulk,
151327ba0dacSFrank Schaefer 					   EM28XX_DVB_NUM_BUFS,
151427ba0dacSFrank Schaefer 					   512,
151527ba0dacSFrank Schaefer 					   EM28XX_DVB_BULK_PACKET_MULTIPLIER);
151627ba0dacSFrank Schaefer 	} else {
151727ba0dacSFrank Schaefer 		result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
151827ba0dacSFrank Schaefer 					   dev->dvb_xfer_bulk,
151927ba0dacSFrank Schaefer 					   EM28XX_DVB_NUM_BUFS,
152027ba0dacSFrank Schaefer 					   dev->dvb_max_pkt_size_isoc,
152127ba0dacSFrank Schaefer 					   EM28XX_DVB_NUM_ISOC_PACKETS);
152227ba0dacSFrank Schaefer 	}
152327ba0dacSFrank Schaefer 	if (result) {
152429b05e22SMauro Carvalho Chehab 		dev_err(&dev->intf->dev,
1525ce8591ffSMauro Carvalho Chehab 			"failed to pre-allocate USB transfer buffers for DVB.\n");
152627ba0dacSFrank Schaefer 		kfree(dvb);
152727ba0dacSFrank Schaefer 		dev->dvb = NULL;
152827ba0dacSFrank Schaefer 		return result;
152927ba0dacSFrank Schaefer 	}
153027ba0dacSFrank Schaefer 
15310c0d06caSMauro Carvalho Chehab 	mutex_lock(&dev->lock);
15320c0d06caSMauro Carvalho Chehab 	em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
15330c0d06caSMauro Carvalho Chehab 	/* init frontend */
15340c0d06caSMauro Carvalho Chehab 	switch (dev->model) {
15350c0d06caSMauro Carvalho Chehab 	case EM2874_BOARD_LEADERSHIP_ISDBT:
15360c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(s921_attach,
1537fe8d54f0SMauro Carvalho Chehab 					&sharp_isdbt,
1538fe8d54f0SMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
15390c0d06caSMauro Carvalho Chehab 
15400c0d06caSMauro Carvalho Chehab 		if (!dvb->fe[0]) {
15410c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
15420c0d06caSMauro Carvalho Chehab 			goto out_free;
15430c0d06caSMauro Carvalho Chehab 		}
15440c0d06caSMauro Carvalho Chehab 
15450c0d06caSMauro Carvalho Chehab 		break;
15460c0d06caSMauro Carvalho Chehab 	case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
15470c0d06caSMauro Carvalho Chehab 	case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
15480c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
15490c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
15500c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(lgdt330x_attach,
15510c0d06caSMauro Carvalho Chehab 					&em2880_lgdt3303_dev,
155223ba635dSMauro Carvalho Chehab 					0x0e,
1553c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
15540c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
15550c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
15560c0d06caSMauro Carvalho Chehab 			goto out_free;
15570c0d06caSMauro Carvalho Chehab 		}
15580c0d06caSMauro Carvalho Chehab 		break;
15590c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_KWORLD_DVB_310U:
15600c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(zl10353_attach,
15610c0d06caSMauro Carvalho Chehab 					&em28xx_zl10353_with_xc3028,
1562c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
15630c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
15640c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
15650c0d06caSMauro Carvalho Chehab 			goto out_free;
15660c0d06caSMauro Carvalho Chehab 		}
15670c0d06caSMauro Carvalho Chehab 		break;
15680c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
15690c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_TERRATEC_HYBRID_XS:
15700c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_EMPIRE_DUAL_TV:
1571acf43845SMarcel Stork 	case EM2882_BOARD_ZOLID_HYBRID_TV_STICK:
15720c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(zl10353_attach,
15730c0d06caSMauro Carvalho Chehab 					&em28xx_zl10353_xc3028_no_i2c_gate,
1574c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
15750c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
15760c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
15770c0d06caSMauro Carvalho Chehab 			goto out_free;
15780c0d06caSMauro Carvalho Chehab 		}
15790c0d06caSMauro Carvalho Chehab 		break;
15800c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_TERRATEC_HYBRID_XS:
15810c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
15820c0d06caSMauro Carvalho Chehab 	case EM2881_BOARD_PINNACLE_HYBRID_PRO:
15830c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_DIKOM_DK300:
15840c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_KWORLD_VS_DVBT:
1585fe8d54f0SMauro Carvalho Chehab 		/*
1586fe8d54f0SMauro Carvalho Chehab 		 * Those boards could have either a zl10353 or a mt352.
1587fe8d54f0SMauro Carvalho Chehab 		 * If the chip id isn't for zl10353, try mt352.
1588fe8d54f0SMauro Carvalho Chehab 		 */
15890c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(zl10353_attach,
15900c0d06caSMauro Carvalho Chehab 					&em28xx_zl10353_xc3028_no_i2c_gate,
1591c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
1592fe8d54f0SMauro Carvalho Chehab 		if (!dvb->fe[0])
15930c0d06caSMauro Carvalho Chehab 			dvb->fe[0] = dvb_attach(mt352_attach,
15940c0d06caSMauro Carvalho Chehab 						&terratec_xs_mt352_cfg,
1595c7a45e5bSMauro Carvalho Chehab 						&dev->i2c_adap[dev->def_i2c_bus]);
15960c0d06caSMauro Carvalho Chehab 
15970c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
15980c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
15990c0d06caSMauro Carvalho Chehab 			goto out_free;
16000c0d06caSMauro Carvalho Chehab 		}
16010c0d06caSMauro Carvalho Chehab 		break;
16028c47311dSAlberto Mardegan 	case EM2870_BOARD_TERRATEC_XS_MT2060:
16038c47311dSAlberto Mardegan 		dvb->fe[0] = dvb_attach(zl10353_attach,
16048c47311dSAlberto Mardegan 					&em28xx_zl10353_no_i2c_gate_dev,
16058c47311dSAlberto Mardegan 					&dev->i2c_adap[dev->def_i2c_bus]);
1606fe8d54f0SMauro Carvalho Chehab 		if (dvb->fe[0]) {
16078c47311dSAlberto Mardegan 			dvb_attach(mt2060_attach, dvb->fe[0],
16088c47311dSAlberto Mardegan 				   &dev->i2c_adap[dev->def_i2c_bus],
16098c47311dSAlberto Mardegan 				   &em28xx_mt2060_config, 1220);
16108c47311dSAlberto Mardegan 		}
16118c47311dSAlberto Mardegan 		break;
16120c0d06caSMauro Carvalho Chehab 	case EM2870_BOARD_KWORLD_355U:
16130c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(zl10353_attach,
16140c0d06caSMauro Carvalho Chehab 					&em28xx_zl10353_no_i2c_gate_dev,
1615c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
1616fe8d54f0SMauro Carvalho Chehab 		if (dvb->fe[0])
16170c0d06caSMauro Carvalho Chehab 			dvb_attach(qt1010_attach, dvb->fe[0],
1618fe8d54f0SMauro Carvalho Chehab 				   &dev->i2c_adap[dev->def_i2c_bus],
1619fe8d54f0SMauro Carvalho Chehab 				   &em28xx_qt1010_config);
16200c0d06caSMauro Carvalho Chehab 		break;
16210c0d06caSMauro Carvalho Chehab 	case EM2883_BOARD_KWORLD_HYBRID_330U:
16220c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_EVGA_INDTUBE:
16230c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(s5h1409_attach,
16240c0d06caSMauro Carvalho Chehab 					&em28xx_s5h1409_with_xc3028,
1625c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
16260c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
16270c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
16280c0d06caSMauro Carvalho Chehab 			goto out_free;
16290c0d06caSMauro Carvalho Chehab 		}
16300c0d06caSMauro Carvalho Chehab 		break;
16310c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_KWORLD_ATSC_315U:
16320c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(lgdt330x_attach,
16330c0d06caSMauro Carvalho Chehab 					&em2880_lgdt3303_dev,
163423ba635dSMauro Carvalho Chehab 					0x0e,
1635c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
1636fe8d54f0SMauro Carvalho Chehab 		if (dvb->fe[0]) {
16370c0d06caSMauro Carvalho Chehab 			if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1638fdf1bc9fSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
1639fdf1bc9fSMauro Carvalho Chehab 					0x61, TUNER_THOMSON_DTT761X)) {
16400c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
16410c0d06caSMauro Carvalho Chehab 				goto out_free;
16420c0d06caSMauro Carvalho Chehab 			}
16430c0d06caSMauro Carvalho Chehab 		}
16440c0d06caSMauro Carvalho Chehab 		break;
16450c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
16460c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
16470c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
164829b05e22SMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
164929b05e22SMauro Carvalho Chehab 					&dev->intf->dev);
16500c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
16510c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
16520c0d06caSMauro Carvalho Chehab 			goto out_free;
16530c0d06caSMauro Carvalho Chehab 		}
16540c0d06caSMauro Carvalho Chehab 		break;
16550c0d06caSMauro Carvalho Chehab 	case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
16560c0d06caSMauro Carvalho Chehab 		/* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
16570c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(tda10023_attach,
16580c0d06caSMauro Carvalho Chehab 					&em28xx_tda10023_config,
1659fe8d54f0SMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
1660fe8d54f0SMauro Carvalho Chehab 					0x48);
16610c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]) {
16620c0d06caSMauro Carvalho Chehab 			if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1663fdf1bc9fSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
1664fdf1bc9fSMauro Carvalho Chehab 					0x60, TUNER_PHILIPS_CU1216L)) {
16650c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
16660c0d06caSMauro Carvalho Chehab 				goto out_free;
16670c0d06caSMauro Carvalho Chehab 			}
16680c0d06caSMauro Carvalho Chehab 		}
16690c0d06caSMauro Carvalho Chehab 		break;
16700c0d06caSMauro Carvalho Chehab 	case EM2870_BOARD_KWORLD_A340:
16710c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(lgdt3305_attach,
16720c0d06caSMauro Carvalho Chehab 					&em2870_lgdt3304_dev,
1673c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
16744db8954aSShuah Khan 		if (!dvb->fe[0]) {
16754db8954aSShuah Khan 			result = -EINVAL;
16764db8954aSShuah Khan 			goto out_free;
16774db8954aSShuah Khan 		}
16784db8954aSShuah Khan 		if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
16794db8954aSShuah Khan 				&dev->i2c_adap[dev->def_i2c_bus],
16804db8954aSShuah Khan 				&kworld_a340_config)) {
16814db8954aSShuah Khan 			dvb_frontend_detach(dvb->fe[0]);
16824db8954aSShuah Khan 			result = -EINVAL;
16834db8954aSShuah Khan 			goto out_free;
16844db8954aSShuah Khan 		}
16850c0d06caSMauro Carvalho Chehab 		break;
16860c0d06caSMauro Carvalho Chehab 	case EM28174_BOARD_PCTV_290E:
1687a36a66d7SAntti Palosaari 		/* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1688a36a66d7SAntti Palosaari 		dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
1689a36a66d7SAntti Palosaari 				CXD2820R_GPIO_L;
16900c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(cxd2820r_attach,
16910c0d06caSMauro Carvalho Chehab 					&em28xx_cxd2820r_config,
1692c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
169313a5336eSAntti Palosaari 					&dvb->lna_gpio);
16940c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]) {
16950c0d06caSMauro Carvalho Chehab 			/* FE 0 attach tuner */
16960c0d06caSMauro Carvalho Chehab 			if (!dvb_attach(tda18271_attach,
16970c0d06caSMauro Carvalho Chehab 					dvb->fe[0],
16980c0d06caSMauro Carvalho Chehab 					0x60,
1699c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
17000c0d06caSMauro Carvalho Chehab 					&em28xx_cxd2820r_tda18271_config)) {
17010c0d06caSMauro Carvalho Chehab 				dvb_frontend_detach(dvb->fe[0]);
17020c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
17030c0d06caSMauro Carvalho Chehab 				goto out_free;
17040c0d06caSMauro Carvalho Chehab 			}
17051e8f31f3SAntti Palosaari 
170613a5336eSAntti Palosaari #ifdef CONFIG_GPIOLIB
17071e8f31f3SAntti Palosaari 			/* enable LNA for DVB-T, DVB-T2 and DVB-C */
17080c42a55cSAntti Palosaari 			result = gpio_request_one(dvb->lna_gpio,
17090c42a55cSAntti Palosaari 						  GPIOF_OUT_INIT_LOW, NULL);
17101e8f31f3SAntti Palosaari 			if (result)
171129b05e22SMauro Carvalho Chehab 				dev_err(&dev->intf->dev,
1712ce8591ffSMauro Carvalho Chehab 					"gpio request failed %d\n",
17130c42a55cSAntti Palosaari 					result);
17141e8f31f3SAntti Palosaari 			else
171513a5336eSAntti Palosaari 				gpio_free(dvb->lna_gpio);
17161e8f31f3SAntti Palosaari 
17171e8f31f3SAntti Palosaari 			result = 0; /* continue even set LNA fails */
171813a5336eSAntti Palosaari #endif
171913a5336eSAntti Palosaari 			dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
17200c42a55cSAntti Palosaari 		}
17210c42a55cSAntti Palosaari 
17220c0d06caSMauro Carvalho Chehab 		break;
17230c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
17240c0d06caSMauro Carvalho Chehab 	{
1725ad32495bSMauro Carvalho Chehab 		struct xc5000_config cfg = {};
1726fdf1bc9fSMauro Carvalho Chehab 
17270c0d06caSMauro Carvalho Chehab 		hauppauge_hvr930c_init(dev);
17280c0d06caSMauro Carvalho Chehab 
17290c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach,
1730fe8d54f0SMauro Carvalho Chehab 					&hauppauge_930c_drxk,
1731fe8d54f0SMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
17320c0d06caSMauro Carvalho Chehab 		if (!dvb->fe[0]) {
17330c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
17340c0d06caSMauro Carvalho Chehab 			goto out_free;
17350c0d06caSMauro Carvalho Chehab 		}
17360c0d06caSMauro Carvalho Chehab 		/* FIXME: do we need a pll semaphore? */
17370c0d06caSMauro Carvalho Chehab 		dvb->fe[0]->sec_priv = dvb;
17380c0d06caSMauro Carvalho Chehab 		sema_init(&dvb->pll_mutex, 1);
17390c0d06caSMauro Carvalho Chehab 		dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
17400c0d06caSMauro Carvalho Chehab 		dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
17410c0d06caSMauro Carvalho Chehab 
17420c0d06caSMauro Carvalho Chehab 		/* Attach xc5000 */
17430c0d06caSMauro Carvalho Chehab 		cfg.i2c_address  = 0x61;
17440c0d06caSMauro Carvalho Chehab 		cfg.if_khz = 4000;
17450c0d06caSMauro Carvalho Chehab 
17460c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]->ops.i2c_gate_ctrl)
17470c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1748fe8d54f0SMauro Carvalho Chehab 		if (!dvb_attach(xc5000_attach, dvb->fe[0],
1749fe8d54f0SMauro Carvalho Chehab 				&dev->i2c_adap[dev->def_i2c_bus], &cfg)) {
17500c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
17510c0d06caSMauro Carvalho Chehab 			goto out_free;
17520c0d06caSMauro Carvalho Chehab 		}
17530c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]->ops.i2c_gate_ctrl)
17540c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
17550c0d06caSMauro Carvalho Chehab 
17560c0d06caSMauro Carvalho Chehab 		break;
17570c0d06caSMauro Carvalho Chehab 	}
17580c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_TERRATEC_H5:
17590c0d06caSMauro Carvalho Chehab 		terratec_h5_init(dev);
17600c0d06caSMauro Carvalho Chehab 
1761fe8d54f0SMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk,
1762fe8d54f0SMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
17630c0d06caSMauro Carvalho Chehab 		if (!dvb->fe[0]) {
17640c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
17650c0d06caSMauro Carvalho Chehab 			goto out_free;
17660c0d06caSMauro Carvalho Chehab 		}
17670c0d06caSMauro Carvalho Chehab 		/* FIXME: do we need a pll semaphore? */
17680c0d06caSMauro Carvalho Chehab 		dvb->fe[0]->sec_priv = dvb;
17690c0d06caSMauro Carvalho Chehab 		sema_init(&dvb->pll_mutex, 1);
17700c0d06caSMauro Carvalho Chehab 		dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
17710c0d06caSMauro Carvalho Chehab 		dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
17720c0d06caSMauro Carvalho Chehab 
17730c0d06caSMauro Carvalho Chehab 		/* Attach tda18271 to DVB-C frontend */
17740c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]->ops.i2c_gate_ctrl)
17750c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1776fe8d54f0SMauro Carvalho Chehab 		if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0],
1777fe8d54f0SMauro Carvalho Chehab 				&dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
17780c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
17790c0d06caSMauro Carvalho Chehab 			goto out_free;
17800c0d06caSMauro Carvalho Chehab 		}
17810c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]->ops.i2c_gate_ctrl)
17820c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
17830c0d06caSMauro Carvalho Chehab 
17840c0d06caSMauro Carvalho Chehab 		break;
17854159d01bSMauro Carvalho Chehab 	case EM2884_BOARD_C3TECH_DIGITAL_DUO:
17864159d01bSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(mb86a20s_attach,
17874159d01bSMauro Carvalho Chehab 					&c3tech_duo_mb86a20s_config,
17884159d01bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
1789fe8d54f0SMauro Carvalho Chehab 		if (dvb->fe[0])
17904159d01bSMauro Carvalho Chehab 			dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
17914159d01bSMauro Carvalho Chehab 				   &dev->i2c_adap[dev->def_i2c_bus],
17924159d01bSMauro Carvalho Chehab 				   &c3tech_duo_tda18271_config);
17934159d01bSMauro Carvalho Chehab 		break;
1794f410b409SArnd Bergmann 	case EM28174_BOARD_PCTV_460E:
1795f410b409SArnd Bergmann 		result = em28174_dvb_init_pctv_460e(dev);
1796f410b409SArnd Bergmann 		if (result)
17978022f9afSAntti Palosaari 			goto out_free;
17980c0d06caSMauro Carvalho Chehab 		break;
17997c1dfdb0SJakob Haufe 	case EM2874_BOARD_DELOCK_61959:
18000c0d06caSMauro Carvalho Chehab 	case EM2874_BOARD_MAXMEDIA_UB425_TC:
18010c0d06caSMauro Carvalho Chehab 		/* attach demodulator */
18020c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
1803c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
18040c0d06caSMauro Carvalho Chehab 
18050c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]) {
18060c0d06caSMauro Carvalho Chehab 			/* disable I2C-gate */
18070c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
18080c0d06caSMauro Carvalho Chehab 
18090c0d06caSMauro Carvalho Chehab 			/* attach tuner */
1810b6c7abb1SAntti Palosaari 			if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1811b6c7abb1SAntti Palosaari 					&dev->i2c_adap[dev->def_i2c_bus],
1812b6c7abb1SAntti Palosaari 					&em28xx_cxd2820r_tda18271_config)) {
18130c0d06caSMauro Carvalho Chehab 				dvb_frontend_detach(dvb->fe[0]);
18140c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
18150c0d06caSMauro Carvalho Chehab 				goto out_free;
18160c0d06caSMauro Carvalho Chehab 			}
18170c0d06caSMauro Carvalho Chehab 		}
18180c0d06caSMauro Carvalho Chehab 		break;
18190c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_PCTV_510E:
18200c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_PCTV_520E:
18210c0d06caSMauro Carvalho Chehab 		pctv_520e_init(dev);
18220c0d06caSMauro Carvalho Chehab 
18230c0d06caSMauro Carvalho Chehab 		/* attach demodulator */
18240c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
1825c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
18260c0d06caSMauro Carvalho Chehab 
18270c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]) {
18280c0d06caSMauro Carvalho Chehab 			/* attach tuner */
18290c0d06caSMauro Carvalho Chehab 			if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1830c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
18310c0d06caSMauro Carvalho Chehab 					&em28xx_cxd2820r_tda18271_config)) {
18320c0d06caSMauro Carvalho Chehab 				dvb_frontend_detach(dvb->fe[0]);
18330c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
18340c0d06caSMauro Carvalho Chehab 				goto out_free;
18350c0d06caSMauro Carvalho Chehab 			}
18360c0d06caSMauro Carvalho Chehab 		}
18370c0d06caSMauro Carvalho Chehab 		break;
18381fe0fbd6SGilles Risch 	case EM2884_BOARD_ELGATO_EYETV_HYBRID_2008:
18390c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_CINERGY_HTC_STICK:
1840d6a64327SMauro Carvalho Chehab 	case EM2884_BOARD_TERRATEC_H6:
18410c0d06caSMauro Carvalho Chehab 		terratec_htc_stick_init(dev);
18420c0d06caSMauro Carvalho Chehab 
18430c0d06caSMauro Carvalho Chehab 		/* attach demodulator */
18440c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1845c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
18460c0d06caSMauro Carvalho Chehab 		if (!dvb->fe[0]) {
18470c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
18480c0d06caSMauro Carvalho Chehab 			goto out_free;
18490c0d06caSMauro Carvalho Chehab 		}
18500c0d06caSMauro Carvalho Chehab 
18510c0d06caSMauro Carvalho Chehab 		/* Attach the demodulator. */
18520c0d06caSMauro Carvalho Chehab 		if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1853c7a45e5bSMauro Carvalho Chehab 				&dev->i2c_adap[dev->def_i2c_bus],
18540c0d06caSMauro Carvalho Chehab 				&em28xx_cxd2820r_tda18271_config)) {
18550c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
18560c0d06caSMauro Carvalho Chehab 			goto out_free;
18570c0d06caSMauro Carvalho Chehab 		}
18580c0d06caSMauro Carvalho Chehab 		break;
185989040136SMartin Blumenstingl 	case EM2884_BOARD_TERRATEC_HTC_USB_XS:
186089040136SMartin Blumenstingl 		terratec_htc_usb_xs_init(dev);
186189040136SMartin Blumenstingl 
186289040136SMartin Blumenstingl 		/* attach demodulator */
186389040136SMartin Blumenstingl 		dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1864c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
186589040136SMartin Blumenstingl 		if (!dvb->fe[0]) {
186689040136SMartin Blumenstingl 			result = -EINVAL;
186789040136SMartin Blumenstingl 			goto out_free;
186889040136SMartin Blumenstingl 		}
186989040136SMartin Blumenstingl 
187089040136SMartin Blumenstingl 		/* Attach the demodulator. */
187189040136SMartin Blumenstingl 		if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1872c7a45e5bSMauro Carvalho Chehab 				&dev->i2c_adap[dev->def_i2c_bus],
187389040136SMartin Blumenstingl 				&em28xx_cxd2820r_tda18271_config)) {
187489040136SMartin Blumenstingl 			result = -EINVAL;
187589040136SMartin Blumenstingl 			goto out_free;
187689040136SMartin Blumenstingl 		}
187789040136SMartin Blumenstingl 		break;
18786dbea9f0SJean-Francois Thibert 	case EM2874_BOARD_KWORLD_UB435Q_V2:
18796dbea9f0SJean-Francois Thibert 		dvb->fe[0] = dvb_attach(lgdt3305_attach,
18806dbea9f0SJean-Francois Thibert 					&em2874_lgdt3305_dev,
18816dbea9f0SJean-Francois Thibert 					&dev->i2c_adap[dev->def_i2c_bus]);
18826dbea9f0SJean-Francois Thibert 		if (!dvb->fe[0]) {
18836dbea9f0SJean-Francois Thibert 			result = -EINVAL;
18846dbea9f0SJean-Francois Thibert 			goto out_free;
18856dbea9f0SJean-Francois Thibert 		}
18866dbea9f0SJean-Francois Thibert 
18876dbea9f0SJean-Francois Thibert 		/* Attach the demodulator. */
18886dbea9f0SJean-Francois Thibert 		if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
18896dbea9f0SJean-Francois Thibert 				&dev->i2c_adap[dev->def_i2c_bus],
18906dbea9f0SJean-Francois Thibert 				&kworld_ub435q_v2_config)) {
18916dbea9f0SJean-Francois Thibert 			result = -EINVAL;
18926dbea9f0SJean-Francois Thibert 			goto out_free;
18936dbea9f0SJean-Francois Thibert 		}
18946dbea9f0SJean-Francois Thibert 		break;
189502bc1f55SMauro Carvalho Chehab 	case EM2874_BOARD_KWORLD_UB435Q_V3:
1896ac7a24fbSAntti Palosaari 	{
1897ac7a24fbSAntti Palosaari 		struct i2c_adapter *adapter = &dev->i2c_adap[dev->def_i2c_bus];
1898ac7a24fbSAntti Palosaari 
189902bc1f55SMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(lgdt3305_attach,
190002bc1f55SMauro Carvalho Chehab 					&em2874_lgdt3305_nogate_dev,
190102bc1f55SMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
190202bc1f55SMauro Carvalho Chehab 		if (!dvb->fe[0]) {
190302bc1f55SMauro Carvalho Chehab 			result = -EINVAL;
190402bc1f55SMauro Carvalho Chehab 			goto out_free;
190502bc1f55SMauro Carvalho Chehab 		}
190602bc1f55SMauro Carvalho Chehab 
1907ac7a24fbSAntti Palosaari 		/* attach tuner */
1908ac7a24fbSAntti Palosaari 		kworld_ub435q_v3_config.fe = dvb->fe[0];
1909ad32495bSMauro Carvalho Chehab 
1910ad32495bSMauro Carvalho Chehab 		dvb->i2c_client_tuner = dvb_module_probe("tda18212", NULL,
1911fe8d54f0SMauro Carvalho Chehab 							 adapter, 0x60,
1912ad32495bSMauro Carvalho Chehab 							 &kworld_ub435q_v3_config);
1913ad32495bSMauro Carvalho Chehab 		if (!dvb->i2c_client_tuner) {
1914ac7a24fbSAntti Palosaari 			dvb_frontend_detach(dvb->fe[0]);
1915ac7a24fbSAntti Palosaari 			result = -ENODEV;
191602bc1f55SMauro Carvalho Chehab 			goto out_free;
191702bc1f55SMauro Carvalho Chehab 		}
191802bc1f55SMauro Carvalho Chehab 		break;
1919ac7a24fbSAntti Palosaari 	}
192038b2df95SDevin Heitmueller 	case EM2874_BOARD_PCTV_HD_MINI_80E:
1921fe8d54f0SMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drx39xxj_attach,
1922fe8d54f0SMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
1923fe8d54f0SMauro Carvalho Chehab 		if (dvb->fe[0]) {
1924fe8d54f0SMauro Carvalho Chehab 			dvb->fe[0] = dvb_attach(tda18271_attach, dvb->fe[0],
1925fe8d54f0SMauro Carvalho Chehab 						0x60,
192638b2df95SDevin Heitmueller 						&dev->i2c_adap[dev->def_i2c_bus],
192738b2df95SDevin Heitmueller 						&pinnacle_80e_dvb_config);
192838b2df95SDevin Heitmueller 			if (!dvb->fe[0]) {
192938b2df95SDevin Heitmueller 				result = -EINVAL;
193038b2df95SDevin Heitmueller 				goto out_free;
193138b2df95SDevin Heitmueller 			}
193238b2df95SDevin Heitmueller 		}
193338b2df95SDevin Heitmueller 		break;
1934f410b409SArnd Bergmann 	case EM28178_BOARD_PCTV_461E:
1935f410b409SArnd Bergmann 		result = em28178_dvb_init_pctv_461e(dev);
1936f410b409SArnd Bergmann 		if (result)
1937ec573362SAntti Palosaari 			goto out_free;
1938ec573362SAntti Palosaari 		break;
1939985b0edeSBrad Love 	case EM28178_BOARD_PCTV_461E_V2:
1940985b0edeSBrad Love 		result = em28178_dvb_init_pctv_461e_v2(dev);
1941985b0edeSBrad Love 		if (result)
1942985b0edeSBrad Love 			goto out_free;
1943985b0edeSBrad Love 		break;
194419229240SAntti Palosaari 	case EM28178_BOARD_PCTV_292E:
1945f410b409SArnd Bergmann 		result = em28178_dvb_init_pctv_292e(dev);
1946f410b409SArnd Bergmann 		if (result)
194719229240SAntti Palosaari 			goto out_free;
194819229240SAntti Palosaari 		break;
1949fc30dd76SOlli Salonen 	case EM28178_BOARD_TERRATEC_T2_STICK_HD:
1950f410b409SArnd Bergmann 		result = em28178_dvb_init_terratec_t2_stick_hd(dev);
1951f410b409SArnd Bergmann 		if (result)
1952fc30dd76SOlli Salonen 			goto out_free;
1953fc30dd76SOlli Salonen 		break;
1954ab4d1452SSatoshi Nagahama 	case EM28178_BOARD_PLEX_PX_BCUD:
1955f410b409SArnd Bergmann 		result = em28178_dvb_init_plex_px_bcud(dev);
1956f410b409SArnd Bergmann 		if (result)
1957ab4d1452SSatoshi Nagahama 			goto out_free;
1958ab4d1452SSatoshi Nagahama 		break;
195911a2a949SOlli Salonen 	case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB:
1960f410b409SArnd Bergmann 		result = em28174_dvb_init_hauppauge_wintv_dualhd_dvb(dev);
1961f410b409SArnd Bergmann 		if (result)
196211a2a949SOlli Salonen 			goto out_free;
196311a2a949SOlli Salonen 		break;
19641586342eSKevin Cheng 	case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595:
1965f410b409SArnd Bergmann 		result = em28174_dvb_init_hauppauge_wintv_dualhd_01595(dev);
1966f410b409SArnd Bergmann 		if (result)
19671586342eSKevin Cheng 			goto out_free;
19681586342eSKevin Cheng 		break;
19692e74a01fSBrad Love 	case EM2874_BOARD_HAUPPAUGE_USB_QUADHD:
19702e74a01fSBrad Love 		result = em2874_dvb_init_hauppauge_usb_quadhd(dev);
19712e74a01fSBrad Love 		if (result)
19722e74a01fSBrad Love 			goto out_free;
19732e74a01fSBrad Love 		break;
19740c0d06caSMauro Carvalho Chehab 	default:
197529b05e22SMauro Carvalho Chehab 		dev_err(&dev->intf->dev,
1976ce8591ffSMauro Carvalho Chehab 			"The frontend of your DVB/ATSC card isn't supported yet\n");
19770c0d06caSMauro Carvalho Chehab 		break;
19780c0d06caSMauro Carvalho Chehab 	}
1979fe8d54f0SMauro Carvalho Chehab 	if (!dvb->fe[0]) {
198029b05e22SMauro Carvalho Chehab 		dev_err(&dev->intf->dev, "frontend initialization failed\n");
19810c0d06caSMauro Carvalho Chehab 		result = -EINVAL;
19820c0d06caSMauro Carvalho Chehab 		goto out_free;
19830c0d06caSMauro Carvalho Chehab 	}
19840c0d06caSMauro Carvalho Chehab 	/* define general-purpose callback pointer */
19850c0d06caSMauro Carvalho Chehab 	dvb->fe[0]->callback = em28xx_tuner_callback;
19860c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
19870c0d06caSMauro Carvalho Chehab 		dvb->fe[1]->callback = em28xx_tuner_callback;
19880c0d06caSMauro Carvalho Chehab 
19890c0d06caSMauro Carvalho Chehab 	/* register everything */
199029b05e22SMauro Carvalho Chehab 	result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->intf->dev);
19910c0d06caSMauro Carvalho Chehab 
19920c0d06caSMauro Carvalho Chehab 	if (result < 0)
19930c0d06caSMauro Carvalho Chehab 		goto out_free;
19940c0d06caSMauro Carvalho Chehab 
1995be7fd3c3SBrad Love 	if (dev->dvb_xfer_bulk) {
1996be7fd3c3SBrad Love 		dvb_alt = 0;
1997be7fd3c3SBrad Love 	} else { /* isoc */
1998be7fd3c3SBrad Love 		dvb_alt = dev->dvb_alt_isoc;
1999be7fd3c3SBrad Love 	}
2000be7fd3c3SBrad Love 
2001be7fd3c3SBrad Love 	udev = interface_to_usbdev(dev->intf);
2002be7fd3c3SBrad Love 	usb_set_interface(udev, dev->ifnum, dvb_alt);
200329b05e22SMauro Carvalho Chehab 	dev_info(&dev->intf->dev, "DVB extension successfully initialized\n");
200447677e51SMauro Carvalho Chehab 
200547677e51SMauro Carvalho Chehab 	kref_get(&dev->ref);
200647677e51SMauro Carvalho Chehab 
20070c0d06caSMauro Carvalho Chehab ret:
20080c0d06caSMauro Carvalho Chehab 	em28xx_set_mode(dev, EM28XX_SUSPEND);
20090c0d06caSMauro Carvalho Chehab 	mutex_unlock(&dev->lock);
20100c0d06caSMauro Carvalho Chehab 	return result;
20110c0d06caSMauro Carvalho Chehab 
20120c0d06caSMauro Carvalho Chehab out_free:
2013*0ae10a7dSMuhammad Usama Anjum 	em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
20140c0d06caSMauro Carvalho Chehab 	kfree(dvb);
20150c0d06caSMauro Carvalho Chehab 	dev->dvb = NULL;
20160c0d06caSMauro Carvalho Chehab 	goto ret;
20170c0d06caSMauro Carvalho Chehab }
20180c0d06caSMauro Carvalho Chehab 
20190c0d06caSMauro Carvalho Chehab static inline void prevent_sleep(struct dvb_frontend_ops *ops)
20200c0d06caSMauro Carvalho Chehab {
20210c0d06caSMauro Carvalho Chehab 	ops->set_voltage = NULL;
20220c0d06caSMauro Carvalho Chehab 	ops->sleep = NULL;
20230c0d06caSMauro Carvalho Chehab 	ops->tuner_ops.sleep = NULL;
20240c0d06caSMauro Carvalho Chehab }
20250c0d06caSMauro Carvalho Chehab 
20260c0d06caSMauro Carvalho Chehab static int em28xx_dvb_fini(struct em28xx *dev)
20270c0d06caSMauro Carvalho Chehab {
2028b45e34f2SMauro Carvalho Chehab 	struct em28xx_dvb *dvb;
2029b45e34f2SMauro Carvalho Chehab 
2030822b8deaSMauro Carvalho Chehab 	if (dev->is_audio_only) {
2031822b8deaSMauro Carvalho Chehab 		/* Shouldn't initialize IR for this interface */
2032822b8deaSMauro Carvalho Chehab 		return 0;
2033822b8deaSMauro Carvalho Chehab 	}
2034822b8deaSMauro Carvalho Chehab 
20350c0d06caSMauro Carvalho Chehab 	if (!dev->board.has_dvb) {
20360c0d06caSMauro Carvalho Chehab 		/* This device does not support the extension */
20370c0d06caSMauro Carvalho Chehab 		return 0;
20380c0d06caSMauro Carvalho Chehab 	}
20390c0d06caSMauro Carvalho Chehab 
2040b45e34f2SMauro Carvalho Chehab 	if (!dev->dvb)
2041b45e34f2SMauro Carvalho Chehab 		return 0;
2042b45e34f2SMauro Carvalho Chehab 
204329b05e22SMauro Carvalho Chehab 	dev_info(&dev->intf->dev, "Closing DVB extension\n");
2044aa929ad7SMauro Carvalho Chehab 
2045b45e34f2SMauro Carvalho Chehab 	dvb = dev->dvb;
20460c0d06caSMauro Carvalho Chehab 
204727ba0dacSFrank Schaefer 	em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
204827ba0dacSFrank Schaefer 
20492665c299SFrank Schaefer 	if (dev->disconnected) {
2050fe8d54f0SMauro Carvalho Chehab 		/*
2051fe8d54f0SMauro Carvalho Chehab 		 * We cannot tell the device to sleep
2052fe8d54f0SMauro Carvalho Chehab 		 * once it has been unplugged.
2053fe8d54f0SMauro Carvalho Chehab 		 */
2054f68e35afSShuah Khan 		if (dvb->fe[0]) {
20550c0d06caSMauro Carvalho Chehab 			prevent_sleep(&dvb->fe[0]->ops);
2056f68e35afSShuah Khan 			dvb->fe[0]->exit = DVB_FE_DEVICE_REMOVED;
2057f68e35afSShuah Khan 		}
2058f68e35afSShuah Khan 		if (dvb->fe[1]) {
20590c0d06caSMauro Carvalho Chehab 			prevent_sleep(&dvb->fe[1]->ops);
2060f68e35afSShuah Khan 			dvb->fe[1]->exit = DVB_FE_DEVICE_REMOVED;
2061f68e35afSShuah Khan 		}
20620c0d06caSMauro Carvalho Chehab 	}
20630c0d06caSMauro Carvalho Chehab 
2064910b0797SMatthias Schwarzott 	em28xx_unregister_dvb(dvb);
2065910b0797SMatthias Schwarzott 
2066ad32495bSMauro Carvalho Chehab 	/* release I2C module bindings */
2067ad32495bSMauro Carvalho Chehab 	dvb_module_release(dvb->i2c_client_sec);
2068ad32495bSMauro Carvalho Chehab 	dvb_module_release(dvb->i2c_client_tuner);
2069ad32495bSMauro Carvalho Chehab 	dvb_module_release(dvb->i2c_client_demod);
207019229240SAntti Palosaari 
20710c0d06caSMauro Carvalho Chehab 	kfree(dvb);
20720c0d06caSMauro Carvalho Chehab 	dev->dvb = NULL;
207347677e51SMauro Carvalho Chehab 	kref_put(&dev->ref, em28xx_free_device);
20740c0d06caSMauro Carvalho Chehab 
20750c0d06caSMauro Carvalho Chehab 	return 0;
20760c0d06caSMauro Carvalho Chehab }
20770c0d06caSMauro Carvalho Chehab 
2078ca2b46daSShuah Khan static int em28xx_dvb_suspend(struct em28xx *dev)
2079ca2b46daSShuah Khan {
2080ca2b46daSShuah Khan 	int ret = 0;
2081ca2b46daSShuah Khan 
2082ca2b46daSShuah Khan 	if (dev->is_audio_only)
2083ca2b46daSShuah Khan 		return 0;
2084ca2b46daSShuah Khan 
2085ca2b46daSShuah Khan 	if (!dev->board.has_dvb)
2086ca2b46daSShuah Khan 		return 0;
2087ca2b46daSShuah Khan 
208829b05e22SMauro Carvalho Chehab 	dev_info(&dev->intf->dev, "Suspending DVB extension\n");
2089ca2b46daSShuah Khan 	if (dev->dvb) {
2090ca2b46daSShuah Khan 		struct em28xx_dvb *dvb = dev->dvb;
2091ca2b46daSShuah Khan 
2092ca2b46daSShuah Khan 		if (dvb->fe[0]) {
2093ca2b46daSShuah Khan 			ret = dvb_frontend_suspend(dvb->fe[0]);
209429b05e22SMauro Carvalho Chehab 			dev_info(&dev->intf->dev, "fe0 suspend %d\n", ret);
2095ca2b46daSShuah Khan 		}
2096ca2b46daSShuah Khan 		if (dvb->fe[1]) {
2097ca2b46daSShuah Khan 			dvb_frontend_suspend(dvb->fe[1]);
209829b05e22SMauro Carvalho Chehab 			dev_info(&dev->intf->dev, "fe1 suspend %d\n", ret);
2099ca2b46daSShuah Khan 		}
2100ca2b46daSShuah Khan 	}
2101ca2b46daSShuah Khan 
2102ca2b46daSShuah Khan 	return 0;
2103ca2b46daSShuah Khan }
2104ca2b46daSShuah Khan 
2105ca2b46daSShuah Khan static int em28xx_dvb_resume(struct em28xx *dev)
2106ca2b46daSShuah Khan {
2107ca2b46daSShuah Khan 	int ret = 0;
2108ca2b46daSShuah Khan 
2109ca2b46daSShuah Khan 	if (dev->is_audio_only)
2110ca2b46daSShuah Khan 		return 0;
2111ca2b46daSShuah Khan 
2112ca2b46daSShuah Khan 	if (!dev->board.has_dvb)
2113ca2b46daSShuah Khan 		return 0;
2114ca2b46daSShuah Khan 
211529b05e22SMauro Carvalho Chehab 	dev_info(&dev->intf->dev, "Resuming DVB extension\n");
2116ca2b46daSShuah Khan 	if (dev->dvb) {
2117ca2b46daSShuah Khan 		struct em28xx_dvb *dvb = dev->dvb;
2118ca2b46daSShuah Khan 
2119ca2b46daSShuah Khan 		if (dvb->fe[0]) {
2120ca2b46daSShuah Khan 			ret = dvb_frontend_resume(dvb->fe[0]);
212129b05e22SMauro Carvalho Chehab 			dev_info(&dev->intf->dev, "fe0 resume %d\n", ret);
2122ca2b46daSShuah Khan 		}
2123ca2b46daSShuah Khan 
2124ca2b46daSShuah Khan 		if (dvb->fe[1]) {
2125ca2b46daSShuah Khan 			ret = dvb_frontend_resume(dvb->fe[1]);
212629b05e22SMauro Carvalho Chehab 			dev_info(&dev->intf->dev, "fe1 resume %d\n", ret);
2127ca2b46daSShuah Khan 		}
2128ca2b46daSShuah Khan 	}
2129ca2b46daSShuah Khan 
2130ca2b46daSShuah Khan 	return 0;
2131ca2b46daSShuah Khan }
2132ca2b46daSShuah Khan 
21330c0d06caSMauro Carvalho Chehab static struct em28xx_ops dvb_ops = {
21340c0d06caSMauro Carvalho Chehab 	.id   = EM28XX_DVB,
21350c0d06caSMauro Carvalho Chehab 	.name = "Em28xx dvb Extension",
21360c0d06caSMauro Carvalho Chehab 	.init = em28xx_dvb_init,
21370c0d06caSMauro Carvalho Chehab 	.fini = em28xx_dvb_fini,
2138ca2b46daSShuah Khan 	.suspend = em28xx_dvb_suspend,
2139ca2b46daSShuah Khan 	.resume = em28xx_dvb_resume,
21400c0d06caSMauro Carvalho Chehab };
21410c0d06caSMauro Carvalho Chehab 
21420c0d06caSMauro Carvalho Chehab static int __init em28xx_dvb_register(void)
21430c0d06caSMauro Carvalho Chehab {
21440c0d06caSMauro Carvalho Chehab 	return em28xx_register_extension(&dvb_ops);
21450c0d06caSMauro Carvalho Chehab }
21460c0d06caSMauro Carvalho Chehab 
21470c0d06caSMauro Carvalho Chehab static void __exit em28xx_dvb_unregister(void)
21480c0d06caSMauro Carvalho Chehab {
21490c0d06caSMauro Carvalho Chehab 	em28xx_unregister_extension(&dvb_ops);
21500c0d06caSMauro Carvalho Chehab }
21510c0d06caSMauro Carvalho Chehab 
21520c0d06caSMauro Carvalho Chehab module_init(em28xx_dvb_register);
21530c0d06caSMauro Carvalho Chehab module_exit(em28xx_dvb_unregister);
2154