xref: /openbmc/linux/drivers/media/usb/em28xx/em28xx-dvb.c (revision 910b0797fa9e8af09c44a3fa36cb310ba7a7218d)
10c0d06caSMauro Carvalho Chehab /*
20c0d06caSMauro Carvalho Chehab  DVB device driver for em28xx
30c0d06caSMauro Carvalho Chehab 
40c0d06caSMauro Carvalho Chehab  (c) 2008-2011 Mauro Carvalho Chehab <mchehab@infradead.org>
50c0d06caSMauro Carvalho Chehab 
60c0d06caSMauro Carvalho Chehab  (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
70c0d06caSMauro Carvalho Chehab 	- Fixes for the driver to properly work with HVR-950
80c0d06caSMauro Carvalho Chehab 	- Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick
90c0d06caSMauro Carvalho Chehab 	- Fixes for the driver to properly work with AMD ATI TV Wonder HD 600
100c0d06caSMauro Carvalho Chehab 
110c0d06caSMauro Carvalho Chehab  (c) 2008 Aidan Thornton <makosoft@googlemail.com>
120c0d06caSMauro Carvalho Chehab 
13a950e4a7SFrank Schaefer  (c) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
14a950e4a7SFrank Schaefer 
150c0d06caSMauro Carvalho Chehab  Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
160c0d06caSMauro Carvalho Chehab 	(c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
170c0d06caSMauro Carvalho Chehab 	(c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
180c0d06caSMauro Carvalho Chehab 
190c0d06caSMauro Carvalho Chehab  This program is free software; you can redistribute it and/or modify
200c0d06caSMauro Carvalho Chehab  it under the terms of the GNU General Public License as published by
210c0d06caSMauro Carvalho Chehab  the Free Software Foundation; either version 2 of the License.
220c0d06caSMauro Carvalho Chehab  */
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>
31d3829fadSDevin Heitmueller #include <dvb_demux.h>
32d3829fadSDevin Heitmueller #include <dvb_net.h>
33d3829fadSDevin Heitmueller #include <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"
650c0d06caSMauro Carvalho Chehab 
660c0d06caSMauro Carvalho Chehab MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
670c0d06caSMauro Carvalho Chehab MODULE_LICENSE("GPL");
68d8992b09SMauro Carvalho Chehab MODULE_DESCRIPTION(DRIVER_DESC " - digital TV interface");
69d8992b09SMauro Carvalho Chehab MODULE_VERSION(EM28XX_VERSION);
70d8992b09SMauro Carvalho Chehab 
710c0d06caSMauro Carvalho Chehab static unsigned int debug;
720c0d06caSMauro Carvalho Chehab module_param(debug, int, 0644);
730c0d06caSMauro Carvalho Chehab MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
740c0d06caSMauro Carvalho Chehab 
750c0d06caSMauro Carvalho Chehab DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
760c0d06caSMauro Carvalho Chehab 
770c0d06caSMauro Carvalho Chehab #define dprintk(level, fmt, arg...) do {				\
780c0d06caSMauro Carvalho Chehab 	if (debug >= level)						\
7929b05e22SMauro Carvalho Chehab 		dev_printk(KERN_DEBUG, &dev->intf->dev,			\
80ce8591ffSMauro Carvalho Chehab 			   "dvb: " fmt, ## arg);			\
810c0d06caSMauro Carvalho Chehab } while (0)
820c0d06caSMauro Carvalho Chehab 
830c0d06caSMauro Carvalho Chehab struct em28xx_dvb {
840c0d06caSMauro Carvalho Chehab 	struct dvb_frontend        *fe[2];
850c0d06caSMauro Carvalho Chehab 
860c0d06caSMauro Carvalho Chehab 	/* feed count management */
870c0d06caSMauro Carvalho Chehab 	struct mutex               lock;
880c0d06caSMauro Carvalho Chehab 	int                        nfeeds;
890c0d06caSMauro Carvalho Chehab 
900c0d06caSMauro Carvalho Chehab 	/* general boilerplate stuff */
910c0d06caSMauro Carvalho Chehab 	struct dvb_adapter         adapter;
920c0d06caSMauro Carvalho Chehab 	struct dvb_demux           demux;
930c0d06caSMauro Carvalho Chehab 	struct dmxdev              dmxdev;
940c0d06caSMauro Carvalho Chehab 	struct dmx_frontend        fe_hw;
950c0d06caSMauro Carvalho Chehab 	struct dmx_frontend        fe_mem;
960c0d06caSMauro Carvalho Chehab 	struct dvb_net             net;
970c0d06caSMauro Carvalho Chehab 
980c0d06caSMauro Carvalho Chehab 	/* Due to DRX-K - probably need changes */
990c0d06caSMauro Carvalho Chehab 	int (*gate_ctrl)(struct dvb_frontend *, int);
1000c0d06caSMauro Carvalho Chehab 	struct semaphore      pll_mutex;
1010c0d06caSMauro Carvalho Chehab 	bool			dont_attach_fe1;
10213a5336eSAntti Palosaari 	int			lna_gpio;
10319229240SAntti Palosaari 	struct i2c_client	*i2c_client_demod;
104eafa2ad6SAntti Palosaari 	struct i2c_client	*i2c_client_tuner;
1057098f582SAntti Palosaari 	struct i2c_client	*i2c_client_sec;
1060c0d06caSMauro Carvalho Chehab };
1070c0d06caSMauro Carvalho Chehab 
1080c0d06caSMauro Carvalho Chehab static inline void print_err_status(struct em28xx *dev,
1090c0d06caSMauro Carvalho Chehab 				    int packet, int status)
1100c0d06caSMauro Carvalho Chehab {
1110c0d06caSMauro Carvalho Chehab 	char *errmsg = "Unknown";
1120c0d06caSMauro Carvalho Chehab 
1130c0d06caSMauro Carvalho Chehab 	switch (status) {
1140c0d06caSMauro Carvalho Chehab 	case -ENOENT:
115b436e26eSColin Ian King 		errmsg = "unlinked synchronously";
1160c0d06caSMauro Carvalho Chehab 		break;
1170c0d06caSMauro Carvalho Chehab 	case -ECONNRESET:
118b436e26eSColin Ian King 		errmsg = "unlinked asynchronously";
1190c0d06caSMauro Carvalho Chehab 		break;
1200c0d06caSMauro Carvalho Chehab 	case -ENOSR:
1210c0d06caSMauro Carvalho Chehab 		errmsg = "Buffer error (overrun)";
1220c0d06caSMauro Carvalho Chehab 		break;
1230c0d06caSMauro Carvalho Chehab 	case -EPIPE:
1240c0d06caSMauro Carvalho Chehab 		errmsg = "Stalled (device not responding)";
1250c0d06caSMauro Carvalho Chehab 		break;
1260c0d06caSMauro Carvalho Chehab 	case -EOVERFLOW:
1270c0d06caSMauro Carvalho Chehab 		errmsg = "Babble (bad cable?)";
1280c0d06caSMauro Carvalho Chehab 		break;
1290c0d06caSMauro Carvalho Chehab 	case -EPROTO:
1300c0d06caSMauro Carvalho Chehab 		errmsg = "Bit-stuff error (bad cable?)";
1310c0d06caSMauro Carvalho Chehab 		break;
1320c0d06caSMauro Carvalho Chehab 	case -EILSEQ:
1330c0d06caSMauro Carvalho Chehab 		errmsg = "CRC/Timeout (could be anything)";
1340c0d06caSMauro Carvalho Chehab 		break;
1350c0d06caSMauro Carvalho Chehab 	case -ETIME:
1360c0d06caSMauro Carvalho Chehab 		errmsg = "Device does not respond";
1370c0d06caSMauro Carvalho Chehab 		break;
1380c0d06caSMauro Carvalho Chehab 	}
1390c0d06caSMauro Carvalho Chehab 	if (packet < 0) {
1400c0d06caSMauro Carvalho Chehab 		dprintk(1, "URB status %d [%s].\n", status, errmsg);
1410c0d06caSMauro Carvalho Chehab 	} else {
1420c0d06caSMauro Carvalho Chehab 		dprintk(1, "URB packet %d, status %d [%s].\n",
1430c0d06caSMauro Carvalho Chehab 			packet, status, errmsg);
1440c0d06caSMauro Carvalho Chehab 	}
1450c0d06caSMauro Carvalho Chehab }
1460c0d06caSMauro Carvalho Chehab 
147a950e4a7SFrank Schaefer static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
1480c0d06caSMauro Carvalho Chehab {
149a950e4a7SFrank Schaefer 	int xfer_bulk, num_packets, i;
1500c0d06caSMauro Carvalho Chehab 
1510c0d06caSMauro Carvalho Chehab 	if (!dev)
1520c0d06caSMauro Carvalho Chehab 		return 0;
1530c0d06caSMauro Carvalho Chehab 
1542665c299SFrank Schaefer 	if (dev->disconnected)
1550c0d06caSMauro Carvalho Chehab 		return 0;
1560c0d06caSMauro Carvalho Chehab 
1571653cb0cSFrank Schaefer 	if (urb->status < 0)
1580c0d06caSMauro Carvalho Chehab 		print_err_status(dev, -1, urb->status);
1590c0d06caSMauro Carvalho Chehab 
160a950e4a7SFrank Schaefer 	xfer_bulk = usb_pipebulk(urb->pipe);
1610c0d06caSMauro Carvalho Chehab 
162a950e4a7SFrank Schaefer 	if (xfer_bulk) /* bulk */
163a950e4a7SFrank Schaefer 		num_packets = 1;
164a950e4a7SFrank Schaefer 	else /* isoc */
165a950e4a7SFrank Schaefer 		num_packets = urb->number_of_packets;
166a950e4a7SFrank Schaefer 
167a950e4a7SFrank Schaefer 	for (i = 0; i < num_packets; i++) {
168a950e4a7SFrank Schaefer 		if (xfer_bulk) {
169a950e4a7SFrank Schaefer 			if (urb->status < 0) {
170a950e4a7SFrank Schaefer 				print_err_status(dev, i, urb->status);
171a950e4a7SFrank Schaefer 				if (urb->status != -EPROTO)
172a950e4a7SFrank Schaefer 					continue;
173a950e4a7SFrank Schaefer 			}
174ffdeca88SMauro Carvalho Chehab 			if (!urb->actual_length)
175ffdeca88SMauro Carvalho Chehab 				continue;
176a950e4a7SFrank Schaefer 			dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
177a950e4a7SFrank Schaefer 					 urb->actual_length);
178a950e4a7SFrank Schaefer 		} else {
179a950e4a7SFrank Schaefer 			if (urb->iso_frame_desc[i].status < 0) {
180a950e4a7SFrank Schaefer 				print_err_status(dev, i,
181a950e4a7SFrank Schaefer 						 urb->iso_frame_desc[i].status);
1820c0d06caSMauro Carvalho Chehab 				if (urb->iso_frame_desc[i].status != -EPROTO)
1830c0d06caSMauro Carvalho Chehab 					continue;
1840c0d06caSMauro Carvalho Chehab 			}
185ffdeca88SMauro Carvalho Chehab 			if (!urb->iso_frame_desc[i].actual_length)
186ffdeca88SMauro Carvalho Chehab 				continue;
187a950e4a7SFrank Schaefer 			dvb_dmx_swfilter(&dev->dvb->demux,
188a950e4a7SFrank Schaefer 					 urb->transfer_buffer +
1890c0d06caSMauro Carvalho Chehab 					 urb->iso_frame_desc[i].offset,
1900c0d06caSMauro Carvalho Chehab 					 urb->iso_frame_desc[i].actual_length);
1910c0d06caSMauro Carvalho Chehab 		}
192a950e4a7SFrank Schaefer 	}
1930c0d06caSMauro Carvalho Chehab 
1940c0d06caSMauro Carvalho Chehab 	return 0;
1950c0d06caSMauro Carvalho Chehab }
1960c0d06caSMauro Carvalho Chehab 
1970c0d06caSMauro Carvalho Chehab static int em28xx_start_streaming(struct em28xx_dvb *dvb)
1980c0d06caSMauro Carvalho Chehab {
1990c0d06caSMauro Carvalho Chehab 	int rc;
2003de09fbbSHans Verkuil 	struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
2013de09fbbSHans Verkuil 	struct em28xx *dev = i2c_bus->dev;
202c6d48134SMauro Carvalho Chehab 	struct usb_device *udev = interface_to_usbdev(dev->intf);
203c647a91aSFrank Schaefer 	int dvb_max_packet_size, packet_multiplier, dvb_alt;
2040c0d06caSMauro Carvalho Chehab 
205c647a91aSFrank Schaefer 	if (dev->dvb_xfer_bulk) {
206c647a91aSFrank Schaefer 		if (!dev->dvb_ep_bulk)
207c647a91aSFrank Schaefer 			return -ENODEV;
208c647a91aSFrank Schaefer 		dvb_max_packet_size = 512; /* USB 2.0 spec */
209c647a91aSFrank Schaefer 		packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
210c647a91aSFrank Schaefer 		dvb_alt = 0;
211c647a91aSFrank Schaefer 	} else { /* isoc */
212c647a91aSFrank Schaefer 		if (!dev->dvb_ep_isoc)
213c647a91aSFrank Schaefer 			return -ENODEV;
214c647a91aSFrank Schaefer 		dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
215c647a91aSFrank Schaefer 		if (dvb_max_packet_size < 0)
216c647a91aSFrank Schaefer 			return dvb_max_packet_size;
217c647a91aSFrank Schaefer 		packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
218c647a91aSFrank Schaefer 		dvb_alt = dev->dvb_alt_isoc;
219c647a91aSFrank Schaefer 	}
220c647a91aSFrank Schaefer 
221c6d48134SMauro Carvalho Chehab 	usb_set_interface(udev, dev->ifnum, dvb_alt);
2220c0d06caSMauro Carvalho Chehab 	rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
2230c0d06caSMauro Carvalho Chehab 	if (rc < 0)
2240c0d06caSMauro Carvalho Chehab 		return rc;
2250c0d06caSMauro Carvalho Chehab 
22652f7b00eSMauro Carvalho Chehab 	dprintk(1, "Using %d buffers each with %d x %d bytes, alternate %d\n",
2270c0d06caSMauro Carvalho Chehab 		EM28XX_DVB_NUM_BUFS,
228c647a91aSFrank Schaefer 		packet_multiplier,
22952f7b00eSMauro Carvalho Chehab 		dvb_max_packet_size, dvb_alt);
2300c0d06caSMauro Carvalho Chehab 
231c647a91aSFrank Schaefer 	return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
232c647a91aSFrank Schaefer 				    dev->dvb_xfer_bulk,
233515688a8SFrank Schaefer 				    EM28XX_DVB_NUM_BUFS,
234c647a91aSFrank Schaefer 				    dvb_max_packet_size,
235c647a91aSFrank Schaefer 				    packet_multiplier,
236a950e4a7SFrank Schaefer 				    em28xx_dvb_urb_data_copy);
2370c0d06caSMauro Carvalho Chehab }
2380c0d06caSMauro Carvalho Chehab 
2390c0d06caSMauro Carvalho Chehab static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
2400c0d06caSMauro Carvalho Chehab {
2413de09fbbSHans Verkuil 	struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
2423de09fbbSHans Verkuil 	struct em28xx *dev = i2c_bus->dev;
2430c0d06caSMauro Carvalho Chehab 
2440c0d06caSMauro Carvalho Chehab 	em28xx_stop_urbs(dev);
2450c0d06caSMauro Carvalho Chehab 
2460c0d06caSMauro Carvalho Chehab 	return 0;
2470c0d06caSMauro Carvalho Chehab }
2480c0d06caSMauro Carvalho Chehab 
2490c0d06caSMauro Carvalho Chehab static int em28xx_start_feed(struct dvb_demux_feed *feed)
2500c0d06caSMauro Carvalho Chehab {
2510c0d06caSMauro Carvalho Chehab 	struct dvb_demux *demux  = feed->demux;
2520c0d06caSMauro Carvalho Chehab 	struct em28xx_dvb *dvb = demux->priv;
2530c0d06caSMauro Carvalho Chehab 	int rc, ret;
2540c0d06caSMauro Carvalho Chehab 
2550c0d06caSMauro Carvalho Chehab 	if (!demux->dmx.frontend)
2560c0d06caSMauro Carvalho Chehab 		return -EINVAL;
2570c0d06caSMauro Carvalho Chehab 
2580c0d06caSMauro Carvalho Chehab 	mutex_lock(&dvb->lock);
2590c0d06caSMauro Carvalho Chehab 	dvb->nfeeds++;
2600c0d06caSMauro Carvalho Chehab 	rc = dvb->nfeeds;
2610c0d06caSMauro Carvalho Chehab 
2620c0d06caSMauro Carvalho Chehab 	if (dvb->nfeeds == 1) {
2630c0d06caSMauro Carvalho Chehab 		ret = em28xx_start_streaming(dvb);
2640c0d06caSMauro Carvalho Chehab 		if (ret < 0)
2650c0d06caSMauro Carvalho Chehab 			rc = ret;
2660c0d06caSMauro Carvalho Chehab 	}
2670c0d06caSMauro Carvalho Chehab 
2680c0d06caSMauro Carvalho Chehab 	mutex_unlock(&dvb->lock);
2690c0d06caSMauro Carvalho Chehab 	return rc;
2700c0d06caSMauro Carvalho Chehab }
2710c0d06caSMauro Carvalho Chehab 
2720c0d06caSMauro Carvalho Chehab static int em28xx_stop_feed(struct dvb_demux_feed *feed)
2730c0d06caSMauro Carvalho Chehab {
2740c0d06caSMauro Carvalho Chehab 	struct dvb_demux *demux  = feed->demux;
2750c0d06caSMauro Carvalho Chehab 	struct em28xx_dvb *dvb = demux->priv;
2760c0d06caSMauro Carvalho Chehab 	int err = 0;
2770c0d06caSMauro Carvalho Chehab 
2780c0d06caSMauro Carvalho Chehab 	mutex_lock(&dvb->lock);
2790c0d06caSMauro Carvalho Chehab 	dvb->nfeeds--;
2800c0d06caSMauro Carvalho Chehab 
2810c0d06caSMauro Carvalho Chehab 	if (0 == dvb->nfeeds)
2820c0d06caSMauro Carvalho Chehab 		err = em28xx_stop_streaming(dvb);
2830c0d06caSMauro Carvalho Chehab 
2840c0d06caSMauro Carvalho Chehab 	mutex_unlock(&dvb->lock);
2850c0d06caSMauro Carvalho Chehab 	return err;
2860c0d06caSMauro Carvalho Chehab }
2870c0d06caSMauro Carvalho Chehab 
2880c0d06caSMauro Carvalho Chehab 
2890c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */
2900c0d06caSMauro Carvalho Chehab static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
2910c0d06caSMauro Carvalho Chehab {
292a3b60209SMauro Carvalho Chehab 	struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
293a3b60209SMauro Carvalho Chehab 	struct em28xx *dev = i2c_bus->dev;
2940c0d06caSMauro Carvalho Chehab 
2950c0d06caSMauro Carvalho Chehab 	if (acquire)
2960c0d06caSMauro Carvalho Chehab 		return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
2970c0d06caSMauro Carvalho Chehab 	else
2980c0d06caSMauro Carvalho Chehab 		return em28xx_set_mode(dev, EM28XX_SUSPEND);
2990c0d06caSMauro Carvalho Chehab }
3000c0d06caSMauro Carvalho Chehab 
3010c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */
3020c0d06caSMauro Carvalho Chehab 
3030c0d06caSMauro Carvalho Chehab static struct lgdt330x_config em2880_lgdt3303_dev = {
3040c0d06caSMauro Carvalho Chehab 	.demod_address = 0x0e,
3050c0d06caSMauro Carvalho Chehab 	.demod_chip = LGDT3303,
3060c0d06caSMauro Carvalho Chehab };
3070c0d06caSMauro Carvalho Chehab 
3080c0d06caSMauro Carvalho Chehab static struct lgdt3305_config em2870_lgdt3304_dev = {
3090c0d06caSMauro Carvalho Chehab 	.i2c_addr           = 0x0e,
3100c0d06caSMauro Carvalho Chehab 	.demod_chip         = LGDT3304,
3110c0d06caSMauro Carvalho Chehab 	.spectral_inversion = 1,
3120c0d06caSMauro Carvalho Chehab 	.deny_i2c_rptr      = 1,
3130c0d06caSMauro Carvalho Chehab 	.mpeg_mode          = LGDT3305_MPEG_PARALLEL,
3140c0d06caSMauro Carvalho Chehab 	.tpclk_edge         = LGDT3305_TPCLK_FALLING_EDGE,
3150c0d06caSMauro Carvalho Chehab 	.tpvalid_polarity   = LGDT3305_TP_VALID_HIGH,
3160c0d06caSMauro Carvalho Chehab 	.vsb_if_khz         = 3250,
3170c0d06caSMauro Carvalho Chehab 	.qam_if_khz         = 4000,
3180c0d06caSMauro Carvalho Chehab };
3190c0d06caSMauro Carvalho Chehab 
3206dbea9f0SJean-Francois Thibert static struct lgdt3305_config em2874_lgdt3305_dev = {
3216dbea9f0SJean-Francois Thibert 	.i2c_addr           = 0x0e,
3226dbea9f0SJean-Francois Thibert 	.demod_chip         = LGDT3305,
3236dbea9f0SJean-Francois Thibert 	.spectral_inversion = 1,
3246dbea9f0SJean-Francois Thibert 	.deny_i2c_rptr      = 0,
3256dbea9f0SJean-Francois Thibert 	.mpeg_mode          = LGDT3305_MPEG_SERIAL,
3266dbea9f0SJean-Francois Thibert 	.tpclk_edge         = LGDT3305_TPCLK_FALLING_EDGE,
3276dbea9f0SJean-Francois Thibert 	.tpvalid_polarity   = LGDT3305_TP_VALID_HIGH,
3286dbea9f0SJean-Francois Thibert 	.vsb_if_khz         = 3250,
3296dbea9f0SJean-Francois Thibert 	.qam_if_khz         = 4000,
3306dbea9f0SJean-Francois Thibert };
3316dbea9f0SJean-Francois Thibert 
33202bc1f55SMauro Carvalho Chehab static struct lgdt3305_config em2874_lgdt3305_nogate_dev = {
33302bc1f55SMauro Carvalho Chehab 	.i2c_addr           = 0x0e,
33402bc1f55SMauro Carvalho Chehab 	.demod_chip         = LGDT3305,
33502bc1f55SMauro Carvalho Chehab 	.spectral_inversion = 1,
33602bc1f55SMauro Carvalho Chehab 	.deny_i2c_rptr      = 1,
33702bc1f55SMauro Carvalho Chehab 	.mpeg_mode          = LGDT3305_MPEG_SERIAL,
33802bc1f55SMauro Carvalho Chehab 	.tpclk_edge         = LGDT3305_TPCLK_FALLING_EDGE,
33902bc1f55SMauro Carvalho Chehab 	.tpvalid_polarity   = LGDT3305_TP_VALID_HIGH,
34002bc1f55SMauro Carvalho Chehab 	.vsb_if_khz         = 3600,
34102bc1f55SMauro Carvalho Chehab 	.qam_if_khz         = 3600,
34202bc1f55SMauro Carvalho Chehab };
34302bc1f55SMauro Carvalho Chehab 
3440c0d06caSMauro Carvalho Chehab static struct s921_config sharp_isdbt = {
3450c0d06caSMauro Carvalho Chehab 	.demod_address = 0x30 >> 1
3460c0d06caSMauro Carvalho Chehab };
3470c0d06caSMauro Carvalho Chehab 
3480c0d06caSMauro Carvalho Chehab static struct zl10353_config em28xx_zl10353_with_xc3028 = {
3490c0d06caSMauro Carvalho Chehab 	.demod_address = (0x1e >> 1),
3500c0d06caSMauro Carvalho Chehab 	.no_tuner = 1,
3510c0d06caSMauro Carvalho Chehab 	.parallel_ts = 1,
3520c0d06caSMauro Carvalho Chehab 	.if2 = 45600,
3530c0d06caSMauro Carvalho Chehab };
3540c0d06caSMauro Carvalho Chehab 
3550c0d06caSMauro Carvalho Chehab static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
3560c0d06caSMauro Carvalho Chehab 	.demod_address = 0x32 >> 1,
3570c0d06caSMauro Carvalho Chehab 	.output_mode   = S5H1409_PARALLEL_OUTPUT,
3580c0d06caSMauro Carvalho Chehab 	.gpio          = S5H1409_GPIO_OFF,
3590c0d06caSMauro Carvalho Chehab 	.inversion     = S5H1409_INVERSION_OFF,
3600c0d06caSMauro Carvalho Chehab 	.status_mode   = S5H1409_DEMODLOCKING,
3610c0d06caSMauro Carvalho Chehab 	.mpeg_timing   = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
3620c0d06caSMauro Carvalho Chehab };
3630c0d06caSMauro Carvalho Chehab 
3640c0d06caSMauro Carvalho Chehab static struct tda18271_std_map kworld_a340_std_map = {
3650c0d06caSMauro Carvalho Chehab 	.atsc_6   = { .if_freq = 3250, .agc_mode = 3, .std = 0,
3660c0d06caSMauro Carvalho Chehab 		      .if_lvl = 1, .rfagc_top = 0x37, },
3670c0d06caSMauro Carvalho Chehab 	.qam_6    = { .if_freq = 4000, .agc_mode = 3, .std = 1,
3680c0d06caSMauro Carvalho Chehab 		      .if_lvl = 1, .rfagc_top = 0x37, },
3690c0d06caSMauro Carvalho Chehab };
3700c0d06caSMauro Carvalho Chehab 
3710c0d06caSMauro Carvalho Chehab static struct tda18271_config kworld_a340_config = {
3720c0d06caSMauro Carvalho Chehab 	.std_map           = &kworld_a340_std_map,
3730c0d06caSMauro Carvalho Chehab };
3740c0d06caSMauro Carvalho Chehab 
3756dbea9f0SJean-Francois Thibert static struct tda18271_config kworld_ub435q_v2_config = {
3766dbea9f0SJean-Francois Thibert 	.std_map	= &kworld_a340_std_map,
3776dbea9f0SJean-Francois Thibert 	.gate		= TDA18271_GATE_DIGITAL,
3786dbea9f0SJean-Francois Thibert };
3796dbea9f0SJean-Francois Thibert 
38002bc1f55SMauro Carvalho Chehab static struct tda18212_config kworld_ub435q_v3_config = {
38102bc1f55SMauro Carvalho Chehab 	.if_atsc_vsb	= 3600,
38202bc1f55SMauro Carvalho Chehab 	.if_atsc_qam	= 3600,
38302bc1f55SMauro Carvalho Chehab };
38402bc1f55SMauro Carvalho Chehab 
3850c0d06caSMauro Carvalho Chehab static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
3860c0d06caSMauro Carvalho Chehab 	.demod_address = (0x1e >> 1),
3870c0d06caSMauro Carvalho Chehab 	.no_tuner = 1,
3880c0d06caSMauro Carvalho Chehab 	.disable_i2c_gate_ctrl = 1,
3890c0d06caSMauro Carvalho Chehab 	.parallel_ts = 1,
3900c0d06caSMauro Carvalho Chehab 	.if2 = 45600,
3910c0d06caSMauro Carvalho Chehab };
3920c0d06caSMauro Carvalho Chehab 
3930c0d06caSMauro Carvalho Chehab static struct drxd_config em28xx_drxd = {
3940c0d06caSMauro Carvalho Chehab 	.demod_address = 0x70,
3950c0d06caSMauro Carvalho Chehab 	.demod_revision = 0xa2,
3960c0d06caSMauro Carvalho Chehab 	.pll_type = DRXD_PLL_NONE,
3970c0d06caSMauro Carvalho Chehab 	.clock = 12000,
3980c0d06caSMauro Carvalho Chehab 	.insert_rs_byte = 1,
3990c0d06caSMauro Carvalho Chehab 	.IF = 42800000,
4000c0d06caSMauro Carvalho Chehab 	.disable_i2c_gate_ctrl = 1,
4010c0d06caSMauro Carvalho Chehab };
4020c0d06caSMauro Carvalho Chehab 
4030c0d06caSMauro Carvalho Chehab static struct drxk_config terratec_h5_drxk = {
4040c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4050c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4060c0d06caSMauro Carvalho Chehab 	.no_i2c_bridge = 1,
4070c0d06caSMauro Carvalho Chehab 	.microcode_name = "dvb-usb-terratec-h5-drxk.fw",
4080c0d06caSMauro Carvalho Chehab 	.qam_demod_parameter_count = 2,
4090c0d06caSMauro Carvalho Chehab };
4100c0d06caSMauro Carvalho Chehab 
4110c0d06caSMauro Carvalho Chehab static struct drxk_config hauppauge_930c_drxk = {
4120c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4130c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4140c0d06caSMauro Carvalho Chehab 	.no_i2c_bridge = 1,
4150c0d06caSMauro Carvalho Chehab 	.microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
4160c0d06caSMauro Carvalho Chehab 	.chunk_size = 56,
4170c0d06caSMauro Carvalho Chehab 	.qam_demod_parameter_count = 2,
4180c0d06caSMauro Carvalho Chehab };
4190c0d06caSMauro Carvalho Chehab 
42089040136SMartin Blumenstingl static struct drxk_config terratec_htc_stick_drxk = {
4210c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4220c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4230c0d06caSMauro Carvalho Chehab 	.no_i2c_bridge = 1,
4240c0d06caSMauro Carvalho Chehab 	.microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
4250c0d06caSMauro Carvalho Chehab 	.chunk_size = 54,
4260c0d06caSMauro Carvalho Chehab 	.qam_demod_parameter_count = 2,
4270c0d06caSMauro Carvalho Chehab 	/* Required for the antenna_gpio to disable LNA. */
4280c0d06caSMauro Carvalho Chehab 	.antenna_dvbt = true,
4290c0d06caSMauro Carvalho Chehab 	/* The windows driver uses the same. This will disable LNA. */
4300c0d06caSMauro Carvalho Chehab 	.antenna_gpio = 0x6,
4310c0d06caSMauro Carvalho Chehab };
4320c0d06caSMauro Carvalho Chehab 
4330c0d06caSMauro Carvalho Chehab static struct drxk_config maxmedia_ub425_tc_drxk = {
4340c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4350c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4360c0d06caSMauro Carvalho Chehab 	.no_i2c_bridge = 1,
4378d100b27SAntti Palosaari 	.microcode_name = "dvb-demod-drxk-01.fw",
4388d100b27SAntti Palosaari 	.chunk_size = 62,
439de0fc463SAntti Palosaari 	.qam_demod_parameter_count = 2,
4400c0d06caSMauro Carvalho Chehab };
4410c0d06caSMauro Carvalho Chehab 
4420c0d06caSMauro Carvalho Chehab static struct drxk_config pctv_520e_drxk = {
4430c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4440c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4450c0d06caSMauro Carvalho Chehab 	.microcode_name = "dvb-demod-drxk-pctv.fw",
4460c0d06caSMauro Carvalho Chehab 	.qam_demod_parameter_count = 2,
4470c0d06caSMauro Carvalho Chehab 	.chunk_size = 58,
4480c0d06caSMauro Carvalho Chehab 	.antenna_dvbt = true, /* disable LNA */
4490c0d06caSMauro Carvalho Chehab 	.antenna_gpio = (1 << 2), /* disable LNA */
4500c0d06caSMauro Carvalho Chehab };
4510c0d06caSMauro Carvalho Chehab 
4520c0d06caSMauro Carvalho Chehab static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
4530c0d06caSMauro Carvalho Chehab {
4540c0d06caSMauro Carvalho Chehab 	struct em28xx_dvb *dvb = fe->sec_priv;
4550c0d06caSMauro Carvalho Chehab 	int status;
4560c0d06caSMauro Carvalho Chehab 
4570c0d06caSMauro Carvalho Chehab 	if (!dvb)
4580c0d06caSMauro Carvalho Chehab 		return -EINVAL;
4590c0d06caSMauro Carvalho Chehab 
4600c0d06caSMauro Carvalho Chehab 	if (enable) {
4610c0d06caSMauro Carvalho Chehab 		down(&dvb->pll_mutex);
4620c0d06caSMauro Carvalho Chehab 		status = dvb->gate_ctrl(fe, 1);
4630c0d06caSMauro Carvalho Chehab 	} else {
4640c0d06caSMauro Carvalho Chehab 		status = dvb->gate_ctrl(fe, 0);
4650c0d06caSMauro Carvalho Chehab 		up(&dvb->pll_mutex);
4660c0d06caSMauro Carvalho Chehab 	}
4670c0d06caSMauro Carvalho Chehab 	return status;
4680c0d06caSMauro Carvalho Chehab }
4690c0d06caSMauro Carvalho Chehab 
4700c0d06caSMauro Carvalho Chehab static void hauppauge_hvr930c_init(struct em28xx *dev)
4710c0d06caSMauro Carvalho Chehab {
4720c0d06caSMauro Carvalho Chehab 	int i;
4730c0d06caSMauro Carvalho Chehab 
4740c0d06caSMauro Carvalho Chehab 	struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
475907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xff,	0xff,	0x65},
476907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xfb,	0xff,	0x32},
477907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xff,	0xff,	0xb8},
4780c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
4790c0d06caSMauro Carvalho Chehab 	};
4800c0d06caSMauro Carvalho Chehab 	struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
481907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x01},
482907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xaf,	0xff,	0x65},
483907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x76},
484907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x01},
485907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xcf,	0xff,	0x0b},
486907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x40},
4870c0d06caSMauro Carvalho Chehab 
488907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xcf,	0xff,	0x65},
489907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x65},
490907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xcf,	0xff,	0x0b},
491907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x65},
4920c0d06caSMauro Carvalho Chehab 
4930c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
4940c0d06caSMauro Carvalho Chehab 	};
4950c0d06caSMauro Carvalho Chehab 
4960c0d06caSMauro Carvalho Chehab 	struct {
4970c0d06caSMauro Carvalho Chehab 		unsigned char r[4];
4980c0d06caSMauro Carvalho Chehab 		int len;
4990c0d06caSMauro Carvalho Chehab 	} regs[] = {
5000c0d06caSMauro Carvalho Chehab 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
5010c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02 }, 2},
5020c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
5030c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
5040c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
5050c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x03, 0xa0 }, 4},
5060c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
5070c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x73, 0xaf }, 4},
5080c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x00 }, 2},
5090c0d06caSMauro Carvalho Chehab 		{{ 0x00, 0x04 }, 2},
5100c0d06caSMauro Carvalho Chehab 		{{ 0x00, 0x04, 0x00, 0x0a }, 4},
5110c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x14 }, 2},
5120c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x14, 0x00, 0x00 }, 4},
5130c0d06caSMauro Carvalho Chehab 	};
5140c0d06caSMauro Carvalho Chehab 
5150c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, hauppauge_hvr930c_init);
5160c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
5170c0d06caSMauro Carvalho Chehab 	msleep(10);
5180c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
5190c0d06caSMauro Carvalho Chehab 	msleep(10);
5200c0d06caSMauro Carvalho Chehab 
521c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
5220c0d06caSMauro Carvalho Chehab 
5230c0d06caSMauro Carvalho Chehab 	for (i = 0; i < ARRAY_SIZE(regs); i++)
524c7a45e5bSMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
5250c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, hauppauge_hvr930c_end);
5260c0d06caSMauro Carvalho Chehab 
5270c0d06caSMauro Carvalho Chehab 	msleep(100);
5280c0d06caSMauro Carvalho Chehab 
5290c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
5300c0d06caSMauro Carvalho Chehab 	msleep(30);
5310c0d06caSMauro Carvalho Chehab 
5320c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
5330c0d06caSMauro Carvalho Chehab 	msleep(10);
5340c0d06caSMauro Carvalho Chehab 
5350c0d06caSMauro Carvalho Chehab }
5360c0d06caSMauro Carvalho Chehab 
5370c0d06caSMauro Carvalho Chehab static void terratec_h5_init(struct em28xx *dev)
5380c0d06caSMauro Carvalho Chehab {
5390c0d06caSMauro Carvalho Chehab 	int i;
5400c0d06caSMauro Carvalho Chehab 	struct em28xx_reg_seq terratec_h5_init[] = {
541c074fc4cSFrank Schaefer 		{EM2820_R08_GPIO_CTRL,		0xff,	0xff,	10},
542907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	100},
543907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf2,	0xff,	50},
544907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	100},
5450c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
5460c0d06caSMauro Carvalho Chehab 	};
5470c0d06caSMauro Carvalho Chehab 	struct em28xx_reg_seq terratec_h5_end[] = {
548907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xe6,	0xff,	100},
549907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xa6,	0xff,	50},
550907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xe6,	0xff,	100},
5510c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
5520c0d06caSMauro Carvalho Chehab 	};
5530c0d06caSMauro Carvalho Chehab 	struct {
5540c0d06caSMauro Carvalho Chehab 		unsigned char r[4];
5550c0d06caSMauro Carvalho Chehab 		int len;
5560c0d06caSMauro Carvalho Chehab 	} regs[] = {
5570c0d06caSMauro Carvalho Chehab 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
5580c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02 }, 2},
5590c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
5600c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
5610c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
5620c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x03, 0xa0 }, 4},
5630c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
5640c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x73, 0xaf }, 4},
5650c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x00 }, 2},
5660c0d06caSMauro Carvalho Chehab 		{{ 0x00, 0x04 }, 2},
5670c0d06caSMauro Carvalho Chehab 		{{ 0x00, 0x04, 0x00, 0x0a }, 4},
5680c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x14 }, 2},
5690c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x14, 0x00, 0x00 }, 4},
5700c0d06caSMauro Carvalho Chehab 	};
5710c0d06caSMauro Carvalho Chehab 
5720c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, terratec_h5_init);
5730c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
5740c0d06caSMauro Carvalho Chehab 	msleep(10);
5750c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
5760c0d06caSMauro Carvalho Chehab 	msleep(10);
5770c0d06caSMauro Carvalho Chehab 
578c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
5790c0d06caSMauro Carvalho Chehab 
5800c0d06caSMauro Carvalho Chehab 	for (i = 0; i < ARRAY_SIZE(regs); i++)
581c7a45e5bSMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
5820c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, terratec_h5_end);
5830c0d06caSMauro Carvalho Chehab };
5840c0d06caSMauro Carvalho Chehab 
5850c0d06caSMauro Carvalho Chehab static void terratec_htc_stick_init(struct em28xx *dev)
5860c0d06caSMauro Carvalho Chehab {
5870c0d06caSMauro Carvalho Chehab 	int i;
5880c0d06caSMauro Carvalho Chehab 
5890c0d06caSMauro Carvalho Chehab 	/*
5900c0d06caSMauro Carvalho Chehab 	 * GPIO configuration:
5910c0d06caSMauro Carvalho Chehab 	 * 0xff: unknown (does not affect DVB-T).
5920c0d06caSMauro Carvalho Chehab 	 * 0xf6: DRX-K (demodulator).
5930c0d06caSMauro Carvalho Chehab 	 * 0xe6: unknown (does not affect DVB-T).
5940c0d06caSMauro Carvalho Chehab 	 * 0xb6: unknown (does not affect DVB-T).
5950c0d06caSMauro Carvalho Chehab 	 */
5960c0d06caSMauro Carvalho Chehab 	struct em28xx_reg_seq terratec_htc_stick_init[] = {
597c074fc4cSFrank Schaefer 		{EM2820_R08_GPIO_CTRL,		0xff,	0xff,	10},
598907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	100},
599907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xe6,	0xff,	50},
600907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	100},
6010c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
6020c0d06caSMauro Carvalho Chehab 	};
6030c0d06caSMauro Carvalho Chehab 	struct em28xx_reg_seq terratec_htc_stick_end[] = {
604907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xb6,	0xff,	100},
605907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	50},
6060c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
6070c0d06caSMauro Carvalho Chehab 	};
6080c0d06caSMauro Carvalho Chehab 
60989040136SMartin Blumenstingl 	/*
61089040136SMartin Blumenstingl 	 * Init the analog decoder (not yet supported), but
61189040136SMartin Blumenstingl 	 * it's probably still a good idea.
61289040136SMartin Blumenstingl 	 */
6130c0d06caSMauro Carvalho Chehab 	struct {
6140c0d06caSMauro Carvalho Chehab 		unsigned char r[4];
6150c0d06caSMauro Carvalho Chehab 		int len;
6160c0d06caSMauro Carvalho Chehab 	} regs[] = {
6170c0d06caSMauro Carvalho Chehab 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
6180c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02 }, 2},
6190c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
6200c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
6210c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
6220c0d06caSMauro Carvalho Chehab 	};
6230c0d06caSMauro Carvalho Chehab 
6240c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, terratec_htc_stick_init);
6250c0d06caSMauro Carvalho Chehab 
6260c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
6270c0d06caSMauro Carvalho Chehab 	msleep(10);
6280c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
6290c0d06caSMauro Carvalho Chehab 	msleep(10);
6300c0d06caSMauro Carvalho Chehab 
631c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
6320c0d06caSMauro Carvalho Chehab 
6330c0d06caSMauro Carvalho Chehab 	for (i = 0; i < ARRAY_SIZE(regs); i++)
634c7a45e5bSMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
6350c0d06caSMauro Carvalho Chehab 
6360c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, terratec_htc_stick_end);
6370c0d06caSMauro Carvalho Chehab };
6380c0d06caSMauro Carvalho Chehab 
63989040136SMartin Blumenstingl static void terratec_htc_usb_xs_init(struct em28xx *dev)
64089040136SMartin Blumenstingl {
64189040136SMartin Blumenstingl 	int i;
64289040136SMartin Blumenstingl 
64389040136SMartin Blumenstingl 	struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
644c074fc4cSFrank Schaefer 		{EM2820_R08_GPIO_CTRL,		0xff,	0xff,	10},
645907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xb2,	0xff,	100},
646907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xb2,	0xff,	50},
647907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xb6,	0xff,	100},
64889040136SMartin Blumenstingl 		{	-1,			-1,	-1,	-1},
64989040136SMartin Blumenstingl 	};
65089040136SMartin Blumenstingl 	struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
651907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xa6,	0xff,	100},
652907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xa6,	0xff,	50},
653907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xe6,	0xff,	100},
65489040136SMartin Blumenstingl 		{	-1,			-1,	-1,	-1},
65589040136SMartin Blumenstingl 	};
65689040136SMartin Blumenstingl 
65789040136SMartin Blumenstingl 	/*
65889040136SMartin Blumenstingl 	 * Init the analog decoder (not yet supported), but
65989040136SMartin Blumenstingl 	 * it's probably still a good idea.
66089040136SMartin Blumenstingl 	 */
66189040136SMartin Blumenstingl 	struct {
66289040136SMartin Blumenstingl 		unsigned char r[4];
66389040136SMartin Blumenstingl 		int len;
66489040136SMartin Blumenstingl 	} regs[] = {
66589040136SMartin Blumenstingl 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
66689040136SMartin Blumenstingl 		{{ 0x01, 0x02 }, 2},
66789040136SMartin Blumenstingl 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
66889040136SMartin Blumenstingl 		{{ 0x01, 0x00 }, 2},
66989040136SMartin Blumenstingl 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
67089040136SMartin Blumenstingl 		{{ 0x01, 0x00, 0x03, 0xa0 }, 4},
67189040136SMartin Blumenstingl 		{{ 0x01, 0x00 }, 2},
67289040136SMartin Blumenstingl 		{{ 0x01, 0x00, 0x73, 0xaf }, 4},
67389040136SMartin Blumenstingl 		{{ 0x04, 0x00 }, 2},
67489040136SMartin Blumenstingl 		{{ 0x00, 0x04 }, 2},
67589040136SMartin Blumenstingl 		{{ 0x00, 0x04, 0x00, 0x0a }, 4},
67689040136SMartin Blumenstingl 		{{ 0x04, 0x14 }, 2},
67789040136SMartin Blumenstingl 		{{ 0x04, 0x14, 0x00, 0x00 }, 4},
67889040136SMartin Blumenstingl 	};
67989040136SMartin Blumenstingl 
68089040136SMartin Blumenstingl 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
68189040136SMartin Blumenstingl 
68289040136SMartin Blumenstingl 	em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
68389040136SMartin Blumenstingl 
68489040136SMartin Blumenstingl 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
68589040136SMartin Blumenstingl 	msleep(10);
68689040136SMartin Blumenstingl 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
68789040136SMartin Blumenstingl 	msleep(10);
68889040136SMartin Blumenstingl 
689c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
69089040136SMartin Blumenstingl 
69189040136SMartin Blumenstingl 	for (i = 0; i < ARRAY_SIZE(regs); i++)
692c7a45e5bSMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
69389040136SMartin Blumenstingl 
69489040136SMartin Blumenstingl 	em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
69589040136SMartin Blumenstingl };
69689040136SMartin Blumenstingl 
6970c0d06caSMauro Carvalho Chehab static void pctv_520e_init(struct em28xx *dev)
6980c0d06caSMauro Carvalho Chehab {
6990c0d06caSMauro Carvalho Chehab 	/*
7000c0d06caSMauro Carvalho Chehab 	 * Init AVF4910B analog decoder. Looks like I2C traffic to
7010c0d06caSMauro Carvalho Chehab 	 * digital demodulator and tuner are routed via AVF4910B.
7020c0d06caSMauro Carvalho Chehab 	 */
7030c0d06caSMauro Carvalho Chehab 	int i;
7040c0d06caSMauro Carvalho Chehab 	struct {
7050c0d06caSMauro Carvalho Chehab 		unsigned char r[4];
7060c0d06caSMauro Carvalho Chehab 		int len;
7070c0d06caSMauro Carvalho Chehab 	} regs[] = {
7080c0d06caSMauro Carvalho Chehab 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
7090c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02 }, 2},
7100c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
7110c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
7120c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
7130c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x03, 0xa0 }, 4},
7140c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
7150c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x73, 0xaf }, 4},
7160c0d06caSMauro Carvalho Chehab 	};
7170c0d06caSMauro Carvalho Chehab 
718c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
7190c0d06caSMauro Carvalho Chehab 
7200c0d06caSMauro Carvalho Chehab 	for (i = 0; i < ARRAY_SIZE(regs); i++)
721c7a45e5bSMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
7220c0d06caSMauro Carvalho Chehab };
7230c0d06caSMauro Carvalho Chehab 
72433eebec5SAntti Palosaari static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
72513a5336eSAntti Palosaari {
72633eebec5SAntti Palosaari 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
7273ec40dcfSAntti Palosaari 	struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
7283ec40dcfSAntti Palosaari 	struct em28xx *dev = i2c_bus->dev;
72913a5336eSAntti Palosaari #ifdef CONFIG_GPIOLIB
73013a5336eSAntti Palosaari 	struct em28xx_dvb *dvb = dev->dvb;
73113a5336eSAntti Palosaari 	int ret;
73213a5336eSAntti Palosaari 	unsigned long flags;
73313a5336eSAntti Palosaari 
73433eebec5SAntti Palosaari 	if (c->lna == 1)
73533eebec5SAntti Palosaari 		flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
73613a5336eSAntti Palosaari 	else
73733eebec5SAntti Palosaari 		flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
73813a5336eSAntti Palosaari 
73913a5336eSAntti Palosaari 	ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
74013a5336eSAntti Palosaari 	if (ret)
74129b05e22SMauro Carvalho Chehab 		dev_err(&dev->intf->dev, "gpio request failed %d\n", ret);
74213a5336eSAntti Palosaari 	else
74313a5336eSAntti Palosaari 		gpio_free(dvb->lna_gpio);
74413a5336eSAntti Palosaari 
74513a5336eSAntti Palosaari 	return ret;
74613a5336eSAntti Palosaari #else
74729b05e22SMauro Carvalho Chehab 	dev_warn(&dev->intf->dev, "%s: LNA control is disabled (lna=%u)\n",
74833eebec5SAntti Palosaari 		 KBUILD_MODNAME, c->lna);
74913a5336eSAntti Palosaari 	return 0;
75013a5336eSAntti Palosaari #endif
75113a5336eSAntti Palosaari }
75213a5336eSAntti Palosaari 
753ffb9948eSAntti Palosaari static int em28xx_pctv_292e_set_lna(struct dvb_frontend *fe)
754ffb9948eSAntti Palosaari {
755ffb9948eSAntti Palosaari 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
756ffb9948eSAntti Palosaari 	struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
757ffb9948eSAntti Palosaari 	struct em28xx *dev = i2c_bus->dev;
758ffb9948eSAntti Palosaari 	u8 lna;
759ffb9948eSAntti Palosaari 
760ffb9948eSAntti Palosaari 	if (c->lna == 1)
761ffb9948eSAntti Palosaari 		lna = 0x01;
762ffb9948eSAntti Palosaari 	else
763ffb9948eSAntti Palosaari 		lna = 0x00;
764ffb9948eSAntti Palosaari 
765ffb9948eSAntti Palosaari 	return em28xx_write_reg_bits(dev, EM2874_R80_GPIO_P0_CTRL, lna, 0x01);
766ffb9948eSAntti Palosaari }
767ffb9948eSAntti Palosaari 
7680c0d06caSMauro Carvalho Chehab static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
7690c0d06caSMauro Carvalho Chehab {
7700c0d06caSMauro Carvalho Chehab 	/* Values extracted from a USB trace of the Terratec Windows driver */
7710c0d06caSMauro Carvalho Chehab 	static u8 clock_config[]   = { CLOCK_CTL,  0x38, 0x2c };
7720c0d06caSMauro Carvalho Chehab 	static u8 reset[]          = { RESET,      0x80 };
7730c0d06caSMauro Carvalho Chehab 	static u8 adc_ctl_1_cfg[]  = { ADC_CTL_1,  0x40 };
7740c0d06caSMauro Carvalho Chehab 	static u8 agc_cfg[]        = { AGC_TARGET, 0x28, 0xa0 };
7750c0d06caSMauro Carvalho Chehab 	static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
7760c0d06caSMauro Carvalho Chehab 	static u8 rs_err_cfg[]     = { RS_ERR_PER_1, 0x00, 0x4d };
7770c0d06caSMauro Carvalho Chehab 	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
7780c0d06caSMauro Carvalho Chehab 	static u8 trl_nom_cfg[]    = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
7790c0d06caSMauro Carvalho Chehab 	static u8 tps_given_cfg[]  = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
7800c0d06caSMauro Carvalho Chehab 	static u8 tuner_go[]       = { TUNER_GO, 0x01};
7810c0d06caSMauro Carvalho Chehab 
7820c0d06caSMauro Carvalho Chehab 	mt352_write(fe, clock_config,   sizeof(clock_config));
7830c0d06caSMauro Carvalho Chehab 	udelay(200);
7840c0d06caSMauro Carvalho Chehab 	mt352_write(fe, reset,          sizeof(reset));
7850c0d06caSMauro Carvalho Chehab 	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
7860c0d06caSMauro Carvalho Chehab 	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
7870c0d06caSMauro Carvalho Chehab 	mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
7880c0d06caSMauro Carvalho Chehab 	mt352_write(fe, rs_err_cfg,     sizeof(rs_err_cfg));
7890c0d06caSMauro Carvalho Chehab 	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
7900c0d06caSMauro Carvalho Chehab 	mt352_write(fe, trl_nom_cfg,    sizeof(trl_nom_cfg));
7910c0d06caSMauro Carvalho Chehab 	mt352_write(fe, tps_given_cfg,  sizeof(tps_given_cfg));
7920c0d06caSMauro Carvalho Chehab 	mt352_write(fe, tuner_go,       sizeof(tuner_go));
7930c0d06caSMauro Carvalho Chehab 	return 0;
7940c0d06caSMauro Carvalho Chehab }
7950c0d06caSMauro Carvalho Chehab 
796ab4d1452SSatoshi Nagahama static void px_bcud_init(struct em28xx *dev)
797ab4d1452SSatoshi Nagahama {
798ab4d1452SSatoshi Nagahama 	int i;
799ab4d1452SSatoshi Nagahama 	struct {
800ab4d1452SSatoshi Nagahama 		unsigned char r[4];
801ab4d1452SSatoshi Nagahama 		int len;
802ab4d1452SSatoshi Nagahama 	} regs1[] = {
803ab4d1452SSatoshi Nagahama 		{{ 0x0e, 0x77 }, 2},
804ab4d1452SSatoshi Nagahama 		{{ 0x0f, 0x77 }, 2},
805ab4d1452SSatoshi Nagahama 		{{ 0x03, 0x90 }, 2},
806ab4d1452SSatoshi Nagahama 	}, regs2[] = {
807ab4d1452SSatoshi Nagahama 		{{ 0x07, 0x01 }, 2},
808ab4d1452SSatoshi Nagahama 		{{ 0x08, 0x10 }, 2},
809ab4d1452SSatoshi Nagahama 		{{ 0x13, 0x00 }, 2},
810ab4d1452SSatoshi Nagahama 		{{ 0x17, 0x00 }, 2},
811ab4d1452SSatoshi Nagahama 		{{ 0x03, 0x01 }, 2},
812ab4d1452SSatoshi Nagahama 		{{ 0x10, 0xb1 }, 2},
813ab4d1452SSatoshi Nagahama 		{{ 0x11, 0x40 }, 2},
814ab4d1452SSatoshi Nagahama 		{{ 0x85, 0x7a }, 2},
815ab4d1452SSatoshi Nagahama 		{{ 0x87, 0x04 }, 2},
816ab4d1452SSatoshi Nagahama 	};
817ab4d1452SSatoshi Nagahama 	static struct em28xx_reg_seq gpio[] = {
818ab4d1452SSatoshi Nagahama 		{EM28XX_R06_I2C_CLK,		0x40,	0xff,	300},
819ab4d1452SSatoshi Nagahama 		{EM2874_R80_GPIO_P0_CTRL,	0xfd,	0xff,	60},
820ab4d1452SSatoshi Nagahama 		{EM28XX_R15_RGAIN,		0x20,	0xff,	0},
821ab4d1452SSatoshi Nagahama 		{EM28XX_R16_GGAIN,		0x20,	0xff,	0},
822ab4d1452SSatoshi Nagahama 		{EM28XX_R17_BGAIN,		0x20,	0xff,	0},
823ab4d1452SSatoshi Nagahama 		{EM28XX_R18_ROFFSET,		0x00,	0xff,	0},
824ab4d1452SSatoshi Nagahama 		{EM28XX_R19_GOFFSET,		0x00,	0xff,	0},
825ab4d1452SSatoshi Nagahama 		{EM28XX_R1A_BOFFSET,		0x00,	0xff,	0},
826ab4d1452SSatoshi Nagahama 		{EM28XX_R23_UOFFSET,		0x00,	0xff,	0},
827ab4d1452SSatoshi Nagahama 		{EM28XX_R24_VOFFSET,		0x00,	0xff,	0},
828ab4d1452SSatoshi Nagahama 		{EM28XX_R26_COMPR,		0x00,	0xff,	0},
829ab4d1452SSatoshi Nagahama 		{0x13,				0x08,	0xff,	0},
830ab4d1452SSatoshi Nagahama 		{EM28XX_R12_VINENABLE,		0x27,	0xff,	0},
831ab4d1452SSatoshi Nagahama 		{EM28XX_R0C_USBSUSP,		0x10,	0xff,	0},
832ab4d1452SSatoshi Nagahama 		{EM28XX_R27_OUTFMT,		0x00,	0xff,	0},
833ab4d1452SSatoshi Nagahama 		{EM28XX_R10_VINMODE,		0x00,	0xff,	0},
834ab4d1452SSatoshi Nagahama 		{EM28XX_R11_VINCTRL,		0x11,	0xff,	0},
835ab4d1452SSatoshi Nagahama 		{EM2874_R50_IR_CONFIG,		0x01,	0xff,	0},
836ab4d1452SSatoshi Nagahama 		{EM2874_R5F_TS_ENABLE,		0x80,	0xff,	0},
837ab4d1452SSatoshi Nagahama 		{EM28XX_R06_I2C_CLK,		0x46,	0xff,	0},
838ab4d1452SSatoshi Nagahama 	};
839ab4d1452SSatoshi Nagahama 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x46);
840ab4d1452SSatoshi Nagahama 	/* sleeping ISDB-T */
841ab4d1452SSatoshi Nagahama 	dev->dvb->i2c_client_demod->addr = 0x14;
842ab4d1452SSatoshi Nagahama 	for (i = 0; i < ARRAY_SIZE(regs1); i++)
843ab4d1452SSatoshi Nagahama 		i2c_master_send(dev->dvb->i2c_client_demod, regs1[i].r,
844ab4d1452SSatoshi Nagahama 				regs1[i].len);
845ab4d1452SSatoshi Nagahama 	/* sleeping ISDB-S */
846ab4d1452SSatoshi Nagahama 	dev->dvb->i2c_client_demod->addr = 0x15;
847ab4d1452SSatoshi Nagahama 	for (i = 0; i < ARRAY_SIZE(regs2); i++)
848ab4d1452SSatoshi Nagahama 		i2c_master_send(dev->dvb->i2c_client_demod, regs2[i].r,
849ab4d1452SSatoshi Nagahama 				regs2[i].len);
850ab4d1452SSatoshi Nagahama 	for (i = 0; i < ARRAY_SIZE(gpio); i++) {
851ab4d1452SSatoshi Nagahama 		em28xx_write_reg_bits(dev, gpio[i].reg, gpio[i].val,
852ab4d1452SSatoshi Nagahama 				      gpio[i].mask);
853ab4d1452SSatoshi Nagahama 		if (gpio[i].sleep > 0)
854ab4d1452SSatoshi Nagahama 			msleep(gpio[i].sleep);
855ab4d1452SSatoshi Nagahama 	}
856ab4d1452SSatoshi Nagahama };
857ab4d1452SSatoshi Nagahama 
8580c0d06caSMauro Carvalho Chehab static struct mt352_config terratec_xs_mt352_cfg = {
8590c0d06caSMauro Carvalho Chehab 	.demod_address = (0x1e >> 1),
8600c0d06caSMauro Carvalho Chehab 	.no_tuner = 1,
8610c0d06caSMauro Carvalho Chehab 	.if2 = 45600,
8620c0d06caSMauro Carvalho Chehab 	.demod_init = em28xx_mt352_terratec_xs_init,
8630c0d06caSMauro Carvalho Chehab };
8640c0d06caSMauro Carvalho Chehab 
8650c0d06caSMauro Carvalho Chehab static struct tda10023_config em28xx_tda10023_config = {
8660c0d06caSMauro Carvalho Chehab 	.demod_address = 0x0c,
8670c0d06caSMauro Carvalho Chehab 	.invert = 1,
8680c0d06caSMauro Carvalho Chehab };
8690c0d06caSMauro Carvalho Chehab 
8700c0d06caSMauro Carvalho Chehab static struct cxd2820r_config em28xx_cxd2820r_config = {
8710c0d06caSMauro Carvalho Chehab 	.i2c_address = (0xd8 >> 1),
8720c0d06caSMauro Carvalho Chehab 	.ts_mode = CXD2820R_TS_SERIAL,
8730c0d06caSMauro Carvalho Chehab };
8740c0d06caSMauro Carvalho Chehab 
8750c0d06caSMauro Carvalho Chehab static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
8760c0d06caSMauro Carvalho Chehab 	.output_opt = TDA18271_OUTPUT_LT_OFF,
8770c0d06caSMauro Carvalho Chehab 	.gate = TDA18271_GATE_DIGITAL,
8780c0d06caSMauro Carvalho Chehab };
8790c0d06caSMauro Carvalho Chehab 
8800c0d06caSMauro Carvalho Chehab static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
8810c0d06caSMauro Carvalho Chehab 	.demod_address = (0x1e >> 1),
8820c0d06caSMauro Carvalho Chehab 	.disable_i2c_gate_ctrl = 1,
8830c0d06caSMauro Carvalho Chehab 	.no_tuner = 1,
8840c0d06caSMauro Carvalho Chehab 	.parallel_ts = 1,
8850c0d06caSMauro Carvalho Chehab };
886fdf1bc9fSMauro Carvalho Chehab 
8878c47311dSAlberto Mardegan static struct mt2060_config em28xx_mt2060_config = {
8888c47311dSAlberto Mardegan 	.i2c_address = 0x60,
8898c47311dSAlberto Mardegan };
8908c47311dSAlberto Mardegan 
8910c0d06caSMauro Carvalho Chehab static struct qt1010_config em28xx_qt1010_config = {
8920c0d06caSMauro Carvalho Chehab 	.i2c_address = 0x62
8930c0d06caSMauro Carvalho Chehab };
8940c0d06caSMauro Carvalho Chehab 
8954159d01bSMauro Carvalho Chehab static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
8964159d01bSMauro Carvalho Chehab 	.demod_address = 0x10,
8974159d01bSMauro Carvalho Chehab 	.is_serial = true,
8984159d01bSMauro Carvalho Chehab };
8994159d01bSMauro Carvalho Chehab 
9004159d01bSMauro Carvalho Chehab static struct tda18271_std_map mb86a20s_tda18271_config = {
9014159d01bSMauro Carvalho Chehab 	.dvbt_6   = { .if_freq = 4000, .agc_mode = 3, .std = 4,
9024159d01bSMauro Carvalho Chehab 		      .if_lvl = 1, .rfagc_top = 0x37, },
9034159d01bSMauro Carvalho Chehab };
9044159d01bSMauro Carvalho Chehab 
9054159d01bSMauro Carvalho Chehab static struct tda18271_config c3tech_duo_tda18271_config = {
9064159d01bSMauro Carvalho Chehab 	.std_map = &mb86a20s_tda18271_config,
9074159d01bSMauro Carvalho Chehab 	.gate    = TDA18271_GATE_DIGITAL,
9084159d01bSMauro Carvalho Chehab 	.small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
9094159d01bSMauro Carvalho Chehab };
9104159d01bSMauro Carvalho Chehab 
91138b2df95SDevin Heitmueller static struct tda18271_std_map drx_j_std_map = {
91238b2df95SDevin Heitmueller 	.atsc_6   = { .if_freq = 5000, .agc_mode = 3, .std = 0, .if_lvl = 1,
91338b2df95SDevin Heitmueller 		      .rfagc_top = 0x37, },
91438b2df95SDevin Heitmueller 	.qam_6    = { .if_freq = 5380, .agc_mode = 3, .std = 3, .if_lvl = 1,
91538b2df95SDevin Heitmueller 		      .rfagc_top = 0x37, },
91638b2df95SDevin Heitmueller };
91738b2df95SDevin Heitmueller 
91838b2df95SDevin Heitmueller static struct tda18271_config pinnacle_80e_dvb_config = {
91938b2df95SDevin Heitmueller 	.std_map = &drx_j_std_map,
92038b2df95SDevin Heitmueller 	.gate    = TDA18271_GATE_DIGITAL,
92138b2df95SDevin Heitmueller 	.role    = TDA18271_MASTER,
92238b2df95SDevin Heitmueller };
92338b2df95SDevin Heitmueller 
9241586342eSKevin Cheng static struct lgdt3306a_config hauppauge_01595_lgdt3306a_config = {
9251586342eSKevin Cheng 	.qam_if_khz         = 4000,
9261586342eSKevin Cheng 	.vsb_if_khz         = 3250,
9271586342eSKevin Cheng 	.spectral_inversion = 0,
9281586342eSKevin Cheng 	.deny_i2c_rptr      = 0,
9291586342eSKevin Cheng 	.mpeg_mode          = LGDT3306A_MPEG_SERIAL,
9301586342eSKevin Cheng 	.tpclk_edge         = LGDT3306A_TPCLK_RISING_EDGE,
9311586342eSKevin Cheng 	.tpvalid_polarity   = LGDT3306A_TP_VALID_HIGH,
9321586342eSKevin Cheng 	.xtalMHz            = 25,
9331586342eSKevin Cheng };
9341586342eSKevin Cheng 
9350c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */
9360c0d06caSMauro Carvalho Chehab 
9370c0d06caSMauro Carvalho Chehab static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
9380c0d06caSMauro Carvalho Chehab {
9390c0d06caSMauro Carvalho Chehab 	struct dvb_frontend *fe;
9400c0d06caSMauro Carvalho Chehab 	struct xc2028_config cfg;
941ee97207cSMauro Carvalho Chehab 	struct xc2028_ctrl ctl;
9420c0d06caSMauro Carvalho Chehab 
9430c0d06caSMauro Carvalho Chehab 	memset(&cfg, 0, sizeof(cfg));
944c7a45e5bSMauro Carvalho Chehab 	cfg.i2c_adap  = &dev->i2c_adap[dev->def_i2c_bus];
9450c0d06caSMauro Carvalho Chehab 	cfg.i2c_addr  = addr;
9460c0d06caSMauro Carvalho Chehab 
947ee97207cSMauro Carvalho Chehab 	memset(&ctl, 0, sizeof(ctl));
948ee97207cSMauro Carvalho Chehab 	em28xx_setup_xc3028(dev, &ctl);
949ee97207cSMauro Carvalho Chehab 	cfg.ctrl  = &ctl;
950ee97207cSMauro Carvalho Chehab 
9510c0d06caSMauro Carvalho Chehab 	if (!dev->dvb->fe[0]) {
95229b05e22SMauro Carvalho Chehab 		dev_err(&dev->intf->dev,
953ce8591ffSMauro Carvalho Chehab 			"dvb frontend not attached. Can't attach xc3028\n");
9540c0d06caSMauro Carvalho Chehab 		return -EINVAL;
9550c0d06caSMauro Carvalho Chehab 	}
9560c0d06caSMauro Carvalho Chehab 
9570c0d06caSMauro Carvalho Chehab 	fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
9580c0d06caSMauro Carvalho Chehab 	if (!fe) {
95929b05e22SMauro Carvalho Chehab 		dev_err(&dev->intf->dev, "xc3028 attach failed\n");
9600c0d06caSMauro Carvalho Chehab 		dvb_frontend_detach(dev->dvb->fe[0]);
9610c0d06caSMauro Carvalho Chehab 		dev->dvb->fe[0] = NULL;
9620c0d06caSMauro Carvalho Chehab 		return -EINVAL;
9630c0d06caSMauro Carvalho Chehab 	}
9640c0d06caSMauro Carvalho Chehab 
96529b05e22SMauro Carvalho Chehab 	dev_info(&dev->intf->dev, "xc3028 attached\n");
9660c0d06caSMauro Carvalho Chehab 
9670c0d06caSMauro Carvalho Chehab 	return 0;
9680c0d06caSMauro Carvalho Chehab }
9690c0d06caSMauro Carvalho Chehab 
9700c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */
9710c0d06caSMauro Carvalho Chehab 
9720c0d06caSMauro Carvalho Chehab static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
9730c0d06caSMauro Carvalho Chehab 			       struct em28xx *dev, struct device *device)
9740c0d06caSMauro Carvalho Chehab {
9750c0d06caSMauro Carvalho Chehab 	int result;
976e9ef88bdSMauro Carvalho Chehab 	bool create_rf_connector = false;
9770c0d06caSMauro Carvalho Chehab 
9780c0d06caSMauro Carvalho Chehab 	mutex_init(&dvb->lock);
9790c0d06caSMauro Carvalho Chehab 
9800c0d06caSMauro Carvalho Chehab 	/* register adapter */
981ce8591ffSMauro Carvalho Chehab 	result = dvb_register_adapter(&dvb->adapter,
98229b05e22SMauro Carvalho Chehab 				      dev_name(&dev->intf->dev), module,
983ce8591ffSMauro Carvalho Chehab 				      device, adapter_nr);
9840c0d06caSMauro Carvalho Chehab 	if (result < 0) {
98529b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
986ce8591ffSMauro Carvalho Chehab 			 "dvb_register_adapter failed (errno = %d)\n",
9872a96f60eSMauro Carvalho Chehab 			 result);
9880c0d06caSMauro Carvalho Chehab 		goto fail_adapter;
9890c0d06caSMauro Carvalho Chehab 	}
99037ecc7b1SMauro Carvalho Chehab #ifdef CONFIG_MEDIA_CONTROLLER_DVB
99137ecc7b1SMauro Carvalho Chehab 	dvb->adapter.mdev = dev->media_dev;
99237ecc7b1SMauro Carvalho Chehab #endif
9930c0d06caSMauro Carvalho Chehab 
9940c0d06caSMauro Carvalho Chehab 	/* Ensure all frontends negotiate bus access */
9950c0d06caSMauro Carvalho Chehab 	dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
9960c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
9970c0d06caSMauro Carvalho Chehab 		dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
9980c0d06caSMauro Carvalho Chehab 
9993de09fbbSHans Verkuil 	dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
10000c0d06caSMauro Carvalho Chehab 
10010c0d06caSMauro Carvalho Chehab 	/* register frontend */
10020c0d06caSMauro Carvalho Chehab 	result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
10030c0d06caSMauro Carvalho Chehab 	if (result < 0) {
100429b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
1005ce8591ffSMauro Carvalho Chehab 			 "dvb_register_frontend failed (errno = %d)\n",
10062a96f60eSMauro Carvalho Chehab 			 result);
10070c0d06caSMauro Carvalho Chehab 		goto fail_frontend0;
10080c0d06caSMauro Carvalho Chehab 	}
10090c0d06caSMauro Carvalho Chehab 
10100c0d06caSMauro Carvalho Chehab 	/* register 2nd frontend */
10110c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1]) {
10120c0d06caSMauro Carvalho Chehab 		result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
10130c0d06caSMauro Carvalho Chehab 		if (result < 0) {
101429b05e22SMauro Carvalho Chehab 			dev_warn(&dev->intf->dev,
1015ce8591ffSMauro Carvalho Chehab 				 "2nd dvb_register_frontend failed (errno = %d)\n",
10162a96f60eSMauro Carvalho Chehab 				 result);
10170c0d06caSMauro Carvalho Chehab 			goto fail_frontend1;
10180c0d06caSMauro Carvalho Chehab 		}
10190c0d06caSMauro Carvalho Chehab 	}
10200c0d06caSMauro Carvalho Chehab 
10210c0d06caSMauro Carvalho Chehab 	/* register demux stuff */
10220c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.capabilities =
10230c0d06caSMauro Carvalho Chehab 		DMX_TS_FILTERING | DMX_SECTION_FILTERING |
10240c0d06caSMauro Carvalho Chehab 		DMX_MEMORY_BASED_FILTERING;
10250c0d06caSMauro Carvalho Chehab 	dvb->demux.priv       = dvb;
10260c0d06caSMauro Carvalho Chehab 	dvb->demux.filternum  = 256;
10270c0d06caSMauro Carvalho Chehab 	dvb->demux.feednum    = 256;
10280c0d06caSMauro Carvalho Chehab 	dvb->demux.start_feed = em28xx_start_feed;
10290c0d06caSMauro Carvalho Chehab 	dvb->demux.stop_feed  = em28xx_stop_feed;
10300c0d06caSMauro Carvalho Chehab 
10310c0d06caSMauro Carvalho Chehab 	result = dvb_dmx_init(&dvb->demux);
10320c0d06caSMauro Carvalho Chehab 	if (result < 0) {
103329b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
1034ce8591ffSMauro Carvalho Chehab 			 "dvb_dmx_init failed (errno = %d)\n",
1035ce8591ffSMauro Carvalho Chehab 			 result);
10360c0d06caSMauro Carvalho Chehab 		goto fail_dmx;
10370c0d06caSMauro Carvalho Chehab 	}
10380c0d06caSMauro Carvalho Chehab 
10390c0d06caSMauro Carvalho Chehab 	dvb->dmxdev.filternum    = 256;
10400c0d06caSMauro Carvalho Chehab 	dvb->dmxdev.demux        = &dvb->demux.dmx;
10410c0d06caSMauro Carvalho Chehab 	dvb->dmxdev.capabilities = 0;
10420c0d06caSMauro Carvalho Chehab 	result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
10430c0d06caSMauro Carvalho Chehab 	if (result < 0) {
104429b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
1045ce8591ffSMauro Carvalho Chehab 			 "dvb_dmxdev_init failed (errno = %d)\n",
1046ce8591ffSMauro Carvalho Chehab 			 result);
10470c0d06caSMauro Carvalho Chehab 		goto fail_dmxdev;
10480c0d06caSMauro Carvalho Chehab 	}
10490c0d06caSMauro Carvalho Chehab 
10500c0d06caSMauro Carvalho Chehab 	dvb->fe_hw.source = DMX_FRONTEND_0;
10510c0d06caSMauro Carvalho Chehab 	result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
10520c0d06caSMauro Carvalho Chehab 	if (result < 0) {
105329b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
1054ce8591ffSMauro Carvalho Chehab 			 "add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
10552a96f60eSMauro Carvalho Chehab 			 result);
10560c0d06caSMauro Carvalho Chehab 		goto fail_fe_hw;
10570c0d06caSMauro Carvalho Chehab 	}
10580c0d06caSMauro Carvalho Chehab 
10590c0d06caSMauro Carvalho Chehab 	dvb->fe_mem.source = DMX_MEMORY_FE;
10600c0d06caSMauro Carvalho Chehab 	result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
10610c0d06caSMauro Carvalho Chehab 	if (result < 0) {
106229b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
1063ce8591ffSMauro Carvalho Chehab 			 "add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
10642a96f60eSMauro Carvalho Chehab 			 result);
10650c0d06caSMauro Carvalho Chehab 		goto fail_fe_mem;
10660c0d06caSMauro Carvalho Chehab 	}
10670c0d06caSMauro Carvalho Chehab 
10680c0d06caSMauro Carvalho Chehab 	result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
10690c0d06caSMauro Carvalho Chehab 	if (result < 0) {
107029b05e22SMauro Carvalho Chehab 		dev_warn(&dev->intf->dev,
1071ce8591ffSMauro Carvalho Chehab 			 "connect_frontend failed (errno = %d)\n",
1072ce8591ffSMauro Carvalho Chehab 			 result);
10730c0d06caSMauro Carvalho Chehab 		goto fail_fe_conn;
10740c0d06caSMauro Carvalho Chehab 	}
10750c0d06caSMauro Carvalho Chehab 
10760c0d06caSMauro Carvalho Chehab 	/* register network adapter */
10770c0d06caSMauro Carvalho Chehab 	dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
107837ecc7b1SMauro Carvalho Chehab 
1079e9ef88bdSMauro Carvalho Chehab 	/* If the analog part won't create RF connectors, DVB will do it */
1080e9ef88bdSMauro Carvalho Chehab 	if (!dev->has_video || (dev->tuner_type == TUNER_ABSENT))
1081e9ef88bdSMauro Carvalho Chehab 		create_rf_connector = true;
1082e9ef88bdSMauro Carvalho Chehab 
1083e9ef88bdSMauro Carvalho Chehab 	result = dvb_create_media_graph(&dvb->adapter, create_rf_connector);
108437ecc7b1SMauro Carvalho Chehab 	if (result < 0)
108537ecc7b1SMauro Carvalho Chehab 		goto fail_create_graph;
108637ecc7b1SMauro Carvalho Chehab 
10870c0d06caSMauro Carvalho Chehab 	return 0;
10880c0d06caSMauro Carvalho Chehab 
108937ecc7b1SMauro Carvalho Chehab fail_create_graph:
109037ecc7b1SMauro Carvalho Chehab 	dvb_net_release(&dvb->net);
10910c0d06caSMauro Carvalho Chehab fail_fe_conn:
10920c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
10930c0d06caSMauro Carvalho Chehab fail_fe_mem:
10940c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
10950c0d06caSMauro Carvalho Chehab fail_fe_hw:
10960c0d06caSMauro Carvalho Chehab 	dvb_dmxdev_release(&dvb->dmxdev);
10970c0d06caSMauro Carvalho Chehab fail_dmxdev:
10980c0d06caSMauro Carvalho Chehab 	dvb_dmx_release(&dvb->demux);
10990c0d06caSMauro Carvalho Chehab fail_dmx:
11000c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
11010c0d06caSMauro Carvalho Chehab 		dvb_unregister_frontend(dvb->fe[1]);
11020c0d06caSMauro Carvalho Chehab 	dvb_unregister_frontend(dvb->fe[0]);
11030c0d06caSMauro Carvalho Chehab fail_frontend1:
11040c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
11050c0d06caSMauro Carvalho Chehab 		dvb_frontend_detach(dvb->fe[1]);
11060c0d06caSMauro Carvalho Chehab fail_frontend0:
11070c0d06caSMauro Carvalho Chehab 	dvb_frontend_detach(dvb->fe[0]);
11080c0d06caSMauro Carvalho Chehab 	dvb_unregister_adapter(&dvb->adapter);
11090c0d06caSMauro Carvalho Chehab fail_adapter:
11100c0d06caSMauro Carvalho Chehab 	return result;
11110c0d06caSMauro Carvalho Chehab }
11120c0d06caSMauro Carvalho Chehab 
11130c0d06caSMauro Carvalho Chehab static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
11140c0d06caSMauro Carvalho Chehab {
11150c0d06caSMauro Carvalho Chehab 	dvb_net_release(&dvb->net);
11160c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
11170c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
11180c0d06caSMauro Carvalho Chehab 	dvb_dmxdev_release(&dvb->dmxdev);
11190c0d06caSMauro Carvalho Chehab 	dvb_dmx_release(&dvb->demux);
11200c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
11210c0d06caSMauro Carvalho Chehab 		dvb_unregister_frontend(dvb->fe[1]);
11220c0d06caSMauro Carvalho Chehab 	dvb_unregister_frontend(dvb->fe[0]);
11230c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1] && !dvb->dont_attach_fe1)
11240c0d06caSMauro Carvalho Chehab 		dvb_frontend_detach(dvb->fe[1]);
11250c0d06caSMauro Carvalho Chehab 	dvb_frontend_detach(dvb->fe[0]);
11260c0d06caSMauro Carvalho Chehab 	dvb_unregister_adapter(&dvb->adapter);
11270c0d06caSMauro Carvalho Chehab }
11280c0d06caSMauro Carvalho Chehab 
11290c0d06caSMauro Carvalho Chehab static int em28xx_dvb_init(struct em28xx *dev)
11300c0d06caSMauro Carvalho Chehab {
11311b07a77fSMauro Carvalho Chehab 	int result = 0;
11320c0d06caSMauro Carvalho Chehab 	struct em28xx_dvb *dvb;
11330c0d06caSMauro Carvalho Chehab 
1134822b8deaSMauro Carvalho Chehab 	if (dev->is_audio_only) {
1135822b8deaSMauro Carvalho Chehab 		/* Shouldn't initialize IR for this interface */
1136822b8deaSMauro Carvalho Chehab 		return 0;
1137822b8deaSMauro Carvalho Chehab 	}
1138822b8deaSMauro Carvalho Chehab 
11390c0d06caSMauro Carvalho Chehab 	if (!dev->board.has_dvb) {
11400c0d06caSMauro Carvalho Chehab 		/* This device does not support the extension */
11410c0d06caSMauro Carvalho Chehab 		return 0;
11420c0d06caSMauro Carvalho Chehab 	}
11430c0d06caSMauro Carvalho Chehab 
114429b05e22SMauro Carvalho Chehab 	dev_info(&dev->intf->dev, "Binding DVB extension\n");
11459634614fSMauro Carvalho Chehab 
11460c0d06caSMauro Carvalho Chehab 	dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
11478314d402SMauro Carvalho Chehab 	if (!dvb)
11480c0d06caSMauro Carvalho Chehab 		return -ENOMEM;
11498314d402SMauro Carvalho Chehab 
11500c0d06caSMauro Carvalho Chehab 	dev->dvb = dvb;
11510c0d06caSMauro Carvalho Chehab 	dvb->fe[0] = dvb->fe[1] = NULL;
11520c0d06caSMauro Carvalho Chehab 
115327ba0dacSFrank Schaefer 	/* pre-allocate DVB usb transfer buffers */
115427ba0dacSFrank Schaefer 	if (dev->dvb_xfer_bulk) {
115527ba0dacSFrank Schaefer 		result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
115627ba0dacSFrank Schaefer 					   dev->dvb_xfer_bulk,
115727ba0dacSFrank Schaefer 					   EM28XX_DVB_NUM_BUFS,
115827ba0dacSFrank Schaefer 					   512,
115927ba0dacSFrank Schaefer 					   EM28XX_DVB_BULK_PACKET_MULTIPLIER);
116027ba0dacSFrank Schaefer 	} else {
116127ba0dacSFrank Schaefer 		result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
116227ba0dacSFrank Schaefer 					   dev->dvb_xfer_bulk,
116327ba0dacSFrank Schaefer 					   EM28XX_DVB_NUM_BUFS,
116427ba0dacSFrank Schaefer 					   dev->dvb_max_pkt_size_isoc,
116527ba0dacSFrank Schaefer 					   EM28XX_DVB_NUM_ISOC_PACKETS);
116627ba0dacSFrank Schaefer 	}
116727ba0dacSFrank Schaefer 	if (result) {
116829b05e22SMauro Carvalho Chehab 		dev_err(&dev->intf->dev,
1169ce8591ffSMauro Carvalho Chehab 			"failed to pre-allocate USB transfer buffers for DVB.\n");
117027ba0dacSFrank Schaefer 		kfree(dvb);
117127ba0dacSFrank Schaefer 		dev->dvb = NULL;
117227ba0dacSFrank Schaefer 		return result;
117327ba0dacSFrank Schaefer 	}
117427ba0dacSFrank Schaefer 
11750c0d06caSMauro Carvalho Chehab 	mutex_lock(&dev->lock);
11760c0d06caSMauro Carvalho Chehab 	em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
11770c0d06caSMauro Carvalho Chehab 	/* init frontend */
11780c0d06caSMauro Carvalho Chehab 	switch (dev->model) {
11790c0d06caSMauro Carvalho Chehab 	case EM2874_BOARD_LEADERSHIP_ISDBT:
11800c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(s921_attach,
1181c7a45e5bSMauro Carvalho Chehab 				&sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
11820c0d06caSMauro Carvalho Chehab 
11830c0d06caSMauro Carvalho Chehab 		if (!dvb->fe[0]) {
11840c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
11850c0d06caSMauro Carvalho Chehab 			goto out_free;
11860c0d06caSMauro Carvalho Chehab 		}
11870c0d06caSMauro Carvalho Chehab 
11880c0d06caSMauro Carvalho Chehab 		break;
11890c0d06caSMauro Carvalho Chehab 	case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
11900c0d06caSMauro Carvalho Chehab 	case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
11910c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
11920c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
11930c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(lgdt330x_attach,
11940c0d06caSMauro Carvalho Chehab 					   &em2880_lgdt3303_dev,
1195c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
11960c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
11970c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
11980c0d06caSMauro Carvalho Chehab 			goto out_free;
11990c0d06caSMauro Carvalho Chehab 		}
12000c0d06caSMauro Carvalho Chehab 		break;
12010c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_KWORLD_DVB_310U:
12020c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(zl10353_attach,
12030c0d06caSMauro Carvalho Chehab 					   &em28xx_zl10353_with_xc3028,
1204c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
12050c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
12060c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
12070c0d06caSMauro Carvalho Chehab 			goto out_free;
12080c0d06caSMauro Carvalho Chehab 		}
12090c0d06caSMauro Carvalho Chehab 		break;
12100c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
12110c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_TERRATEC_HYBRID_XS:
12120c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_EMPIRE_DUAL_TV:
12130c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(zl10353_attach,
12140c0d06caSMauro Carvalho Chehab 					   &em28xx_zl10353_xc3028_no_i2c_gate,
1215c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
12160c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
12170c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
12180c0d06caSMauro Carvalho Chehab 			goto out_free;
12190c0d06caSMauro Carvalho Chehab 		}
12200c0d06caSMauro Carvalho Chehab 		break;
12210c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_TERRATEC_HYBRID_XS:
12220c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
12230c0d06caSMauro Carvalho Chehab 	case EM2881_BOARD_PINNACLE_HYBRID_PRO:
12240c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_DIKOM_DK300:
12250c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_KWORLD_VS_DVBT:
12260c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(zl10353_attach,
12270c0d06caSMauro Carvalho Chehab 					   &em28xx_zl10353_xc3028_no_i2c_gate,
1228c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
12290c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0] == NULL) {
12300c0d06caSMauro Carvalho Chehab 			/* This board could have either a zl10353 or a mt352.
12310c0d06caSMauro Carvalho Chehab 			   If the chip id isn't for zl10353, try mt352 */
12320c0d06caSMauro Carvalho Chehab 			dvb->fe[0] = dvb_attach(mt352_attach,
12330c0d06caSMauro Carvalho Chehab 						   &terratec_xs_mt352_cfg,
1234c7a45e5bSMauro Carvalho Chehab 						   &dev->i2c_adap[dev->def_i2c_bus]);
12350c0d06caSMauro Carvalho Chehab 		}
12360c0d06caSMauro Carvalho Chehab 
12370c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
12380c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
12390c0d06caSMauro Carvalho Chehab 			goto out_free;
12400c0d06caSMauro Carvalho Chehab 		}
12410c0d06caSMauro Carvalho Chehab 		break;
12428c47311dSAlberto Mardegan 	case EM2870_BOARD_TERRATEC_XS_MT2060:
12438c47311dSAlberto Mardegan 		dvb->fe[0] = dvb_attach(zl10353_attach,
12448c47311dSAlberto Mardegan 						&em28xx_zl10353_no_i2c_gate_dev,
12458c47311dSAlberto Mardegan 						&dev->i2c_adap[dev->def_i2c_bus]);
12468c47311dSAlberto Mardegan 		if (dvb->fe[0] != NULL) {
12478c47311dSAlberto Mardegan 			dvb_attach(mt2060_attach, dvb->fe[0],
12488c47311dSAlberto Mardegan 					&dev->i2c_adap[dev->def_i2c_bus],
12498c47311dSAlberto Mardegan 					&em28xx_mt2060_config, 1220);
12508c47311dSAlberto Mardegan 		}
12518c47311dSAlberto Mardegan 		break;
12520c0d06caSMauro Carvalho Chehab 	case EM2870_BOARD_KWORLD_355U:
12530c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(zl10353_attach,
12540c0d06caSMauro Carvalho Chehab 					   &em28xx_zl10353_no_i2c_gate_dev,
1255c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
12560c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0] != NULL)
12570c0d06caSMauro Carvalho Chehab 			dvb_attach(qt1010_attach, dvb->fe[0],
1258c7a45e5bSMauro Carvalho Chehab 				   &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
12590c0d06caSMauro Carvalho Chehab 		break;
12600c0d06caSMauro Carvalho Chehab 	case EM2883_BOARD_KWORLD_HYBRID_330U:
12610c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_EVGA_INDTUBE:
12620c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(s5h1409_attach,
12630c0d06caSMauro Carvalho Chehab 					   &em28xx_s5h1409_with_xc3028,
1264c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
12650c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
12660c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
12670c0d06caSMauro Carvalho Chehab 			goto out_free;
12680c0d06caSMauro Carvalho Chehab 		}
12690c0d06caSMauro Carvalho Chehab 		break;
12700c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_KWORLD_ATSC_315U:
12710c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(lgdt330x_attach,
12720c0d06caSMauro Carvalho Chehab 					   &em2880_lgdt3303_dev,
1273c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
12740c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0] != NULL) {
12750c0d06caSMauro Carvalho Chehab 			if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1276fdf1bc9fSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
1277fdf1bc9fSMauro Carvalho Chehab 					0x61, TUNER_THOMSON_DTT761X)) {
12780c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
12790c0d06caSMauro Carvalho Chehab 				goto out_free;
12800c0d06caSMauro Carvalho Chehab 			}
12810c0d06caSMauro Carvalho Chehab 		}
12820c0d06caSMauro Carvalho Chehab 		break;
12830c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
12840c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
12850c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
128629b05e22SMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
128729b05e22SMauro Carvalho Chehab 					&dev->intf->dev);
12880c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
12890c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
12900c0d06caSMauro Carvalho Chehab 			goto out_free;
12910c0d06caSMauro Carvalho Chehab 		}
12920c0d06caSMauro Carvalho Chehab 		break;
12930c0d06caSMauro Carvalho Chehab 	case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
12940c0d06caSMauro Carvalho Chehab 		/* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
12950c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(tda10023_attach,
12960c0d06caSMauro Carvalho Chehab 			&em28xx_tda10023_config,
1297c7a45e5bSMauro Carvalho Chehab 			&dev->i2c_adap[dev->def_i2c_bus], 0x48);
12980c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]) {
12990c0d06caSMauro Carvalho Chehab 			if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1300fdf1bc9fSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
1301fdf1bc9fSMauro Carvalho Chehab 					0x60, TUNER_PHILIPS_CU1216L)) {
13020c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
13030c0d06caSMauro Carvalho Chehab 				goto out_free;
13040c0d06caSMauro Carvalho Chehab 			}
13050c0d06caSMauro Carvalho Chehab 		}
13060c0d06caSMauro Carvalho Chehab 		break;
13070c0d06caSMauro Carvalho Chehab 	case EM2870_BOARD_KWORLD_A340:
13080c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(lgdt3305_attach,
13090c0d06caSMauro Carvalho Chehab 					   &em2870_lgdt3304_dev,
1310c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
13114db8954aSShuah Khan 		if (!dvb->fe[0]) {
13124db8954aSShuah Khan 			result = -EINVAL;
13134db8954aSShuah Khan 			goto out_free;
13144db8954aSShuah Khan 		}
13154db8954aSShuah Khan 		if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
13164db8954aSShuah Khan 				&dev->i2c_adap[dev->def_i2c_bus],
13174db8954aSShuah Khan 			&kworld_a340_config)) {
13184db8954aSShuah Khan 				dvb_frontend_detach(dvb->fe[0]);
13194db8954aSShuah Khan 				result = -EINVAL;
13204db8954aSShuah Khan 				goto out_free;
13214db8954aSShuah Khan 		}
13220c0d06caSMauro Carvalho Chehab 		break;
13230c0d06caSMauro Carvalho Chehab 	case EM28174_BOARD_PCTV_290E:
1324a36a66d7SAntti Palosaari 		/* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1325a36a66d7SAntti Palosaari 		dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
1326a36a66d7SAntti Palosaari 				CXD2820R_GPIO_L;
13270c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(cxd2820r_attach,
13280c0d06caSMauro Carvalho Chehab 					&em28xx_cxd2820r_config,
1329c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
133013a5336eSAntti Palosaari 					&dvb->lna_gpio);
13310c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]) {
13320c0d06caSMauro Carvalho Chehab 			/* FE 0 attach tuner */
13330c0d06caSMauro Carvalho Chehab 			if (!dvb_attach(tda18271_attach,
13340c0d06caSMauro Carvalho Chehab 					dvb->fe[0],
13350c0d06caSMauro Carvalho Chehab 					0x60,
1336c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
13370c0d06caSMauro Carvalho Chehab 					&em28xx_cxd2820r_tda18271_config)) {
13380c0d06caSMauro Carvalho Chehab 
13390c0d06caSMauro Carvalho Chehab 				dvb_frontend_detach(dvb->fe[0]);
13400c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
13410c0d06caSMauro Carvalho Chehab 				goto out_free;
13420c0d06caSMauro Carvalho Chehab 			}
13431e8f31f3SAntti Palosaari 
134413a5336eSAntti Palosaari #ifdef CONFIG_GPIOLIB
13451e8f31f3SAntti Palosaari 			/* enable LNA for DVB-T, DVB-T2 and DVB-C */
13460c42a55cSAntti Palosaari 			result = gpio_request_one(dvb->lna_gpio,
13470c42a55cSAntti Palosaari 						  GPIOF_OUT_INIT_LOW, NULL);
13481e8f31f3SAntti Palosaari 			if (result)
134929b05e22SMauro Carvalho Chehab 				dev_err(&dev->intf->dev,
1350ce8591ffSMauro Carvalho Chehab 					"gpio request failed %d\n",
13510c42a55cSAntti Palosaari 					result);
13521e8f31f3SAntti Palosaari 			else
135313a5336eSAntti Palosaari 				gpio_free(dvb->lna_gpio);
13541e8f31f3SAntti Palosaari 
13551e8f31f3SAntti Palosaari 			result = 0; /* continue even set LNA fails */
135613a5336eSAntti Palosaari #endif
135713a5336eSAntti Palosaari 			dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
13580c42a55cSAntti Palosaari 		}
13590c42a55cSAntti Palosaari 
13600c0d06caSMauro Carvalho Chehab 		break;
13610c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
13620c0d06caSMauro Carvalho Chehab 	{
13630c0d06caSMauro Carvalho Chehab 		struct xc5000_config cfg;
1364fdf1bc9fSMauro Carvalho Chehab 
13650c0d06caSMauro Carvalho Chehab 		hauppauge_hvr930c_init(dev);
13660c0d06caSMauro Carvalho Chehab 
13670c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach,
1368c7a45e5bSMauro Carvalho Chehab 					&hauppauge_930c_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
13690c0d06caSMauro Carvalho Chehab 		if (!dvb->fe[0]) {
13700c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
13710c0d06caSMauro Carvalho Chehab 			goto out_free;
13720c0d06caSMauro Carvalho Chehab 		}
13730c0d06caSMauro Carvalho Chehab 		/* FIXME: do we need a pll semaphore? */
13740c0d06caSMauro Carvalho Chehab 		dvb->fe[0]->sec_priv = dvb;
13750c0d06caSMauro Carvalho Chehab 		sema_init(&dvb->pll_mutex, 1);
13760c0d06caSMauro Carvalho Chehab 		dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
13770c0d06caSMauro Carvalho Chehab 		dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
13780c0d06caSMauro Carvalho Chehab 
13790c0d06caSMauro Carvalho Chehab 		/* Attach xc5000 */
13800c0d06caSMauro Carvalho Chehab 		memset(&cfg, 0, sizeof(cfg));
13810c0d06caSMauro Carvalho Chehab 		cfg.i2c_address  = 0x61;
13820c0d06caSMauro Carvalho Chehab 		cfg.if_khz = 4000;
13830c0d06caSMauro Carvalho Chehab 
13840c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]->ops.i2c_gate_ctrl)
13850c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1386c7a45e5bSMauro Carvalho Chehab 		if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
13870c0d06caSMauro Carvalho Chehab 				&cfg)) {
13880c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
13890c0d06caSMauro Carvalho Chehab 			goto out_free;
13900c0d06caSMauro Carvalho Chehab 		}
13910c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]->ops.i2c_gate_ctrl)
13920c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
13930c0d06caSMauro Carvalho Chehab 
13940c0d06caSMauro Carvalho Chehab 		break;
13950c0d06caSMauro Carvalho Chehab 	}
13960c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_TERRATEC_H5:
13970c0d06caSMauro Carvalho Chehab 		terratec_h5_init(dev);
13980c0d06caSMauro Carvalho Chehab 
1399c7a45e5bSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
14000c0d06caSMauro Carvalho Chehab 		if (!dvb->fe[0]) {
14010c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
14020c0d06caSMauro Carvalho Chehab 			goto out_free;
14030c0d06caSMauro Carvalho Chehab 		}
14040c0d06caSMauro Carvalho Chehab 		/* FIXME: do we need a pll semaphore? */
14050c0d06caSMauro Carvalho Chehab 		dvb->fe[0]->sec_priv = dvb;
14060c0d06caSMauro Carvalho Chehab 		sema_init(&dvb->pll_mutex, 1);
14070c0d06caSMauro Carvalho Chehab 		dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
14080c0d06caSMauro Carvalho Chehab 		dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
14090c0d06caSMauro Carvalho Chehab 
14100c0d06caSMauro Carvalho Chehab 		/* Attach tda18271 to DVB-C frontend */
14110c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]->ops.i2c_gate_ctrl)
14120c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1413c7a45e5bSMauro Carvalho Chehab 		if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
14140c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
14150c0d06caSMauro Carvalho Chehab 			goto out_free;
14160c0d06caSMauro Carvalho Chehab 		}
14170c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]->ops.i2c_gate_ctrl)
14180c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
14190c0d06caSMauro Carvalho Chehab 
14200c0d06caSMauro Carvalho Chehab 		break;
14214159d01bSMauro Carvalho Chehab 	case EM2884_BOARD_C3TECH_DIGITAL_DUO:
14224159d01bSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(mb86a20s_attach,
14234159d01bSMauro Carvalho Chehab 					   &c3tech_duo_mb86a20s_config,
14244159d01bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
14254159d01bSMauro Carvalho Chehab 		if (dvb->fe[0] != NULL)
14264159d01bSMauro Carvalho Chehab 			dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
14274159d01bSMauro Carvalho Chehab 				   &dev->i2c_adap[dev->def_i2c_bus],
14284159d01bSMauro Carvalho Chehab 				   &c3tech_duo_tda18271_config);
14294159d01bSMauro Carvalho Chehab 		break;
14308022f9afSAntti Palosaari 	case EM28174_BOARD_PCTV_460E: {
14318022f9afSAntti Palosaari 		struct i2c_client *client;
14328022f9afSAntti Palosaari 		struct i2c_board_info board_info;
14338022f9afSAntti Palosaari 		struct tda10071_platform_data tda10071_pdata = {};
14348022f9afSAntti Palosaari 		struct a8293_platform_data a8293_pdata = {};
14358022f9afSAntti Palosaari 
14368022f9afSAntti Palosaari 		/* attach demod + tuner combo */
14378022f9afSAntti Palosaari 		tda10071_pdata.clk = 40444000, /* 40.444 MHz */
14388022f9afSAntti Palosaari 		tda10071_pdata.i2c_wr_max = 64,
14398022f9afSAntti Palosaari 		tda10071_pdata.ts_mode = TDA10071_TS_SERIAL,
14408022f9afSAntti Palosaari 		tda10071_pdata.pll_multiplier = 20,
14418022f9afSAntti Palosaari 		tda10071_pdata.tuner_i2c_addr = 0x14,
14428022f9afSAntti Palosaari 		memset(&board_info, 0, sizeof(board_info));
14438022f9afSAntti Palosaari 		strlcpy(board_info.type, "tda10071_cx24118", I2C_NAME_SIZE);
14448022f9afSAntti Palosaari 		board_info.addr = 0x55;
14458022f9afSAntti Palosaari 		board_info.platform_data = &tda10071_pdata;
14468022f9afSAntti Palosaari 		request_module("tda10071");
14478022f9afSAntti Palosaari 		client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
14488022f9afSAntti Palosaari 		if (client == NULL || client->dev.driver == NULL) {
14498022f9afSAntti Palosaari 			result = -ENODEV;
14508022f9afSAntti Palosaari 			goto out_free;
14518022f9afSAntti Palosaari 		}
14528022f9afSAntti Palosaari 		if (!try_module_get(client->dev.driver->owner)) {
14538022f9afSAntti Palosaari 			i2c_unregister_device(client);
14548022f9afSAntti Palosaari 			result = -ENODEV;
14558022f9afSAntti Palosaari 			goto out_free;
14568022f9afSAntti Palosaari 		}
14578022f9afSAntti Palosaari 		dvb->fe[0] = tda10071_pdata.get_dvb_frontend(client);
14588022f9afSAntti Palosaari 		dvb->i2c_client_demod = client;
14590c0d06caSMauro Carvalho Chehab 
14600c0d06caSMauro Carvalho Chehab 		/* attach SEC */
14618022f9afSAntti Palosaari 		a8293_pdata.dvb_frontend = dvb->fe[0];
14628022f9afSAntti Palosaari 		memset(&board_info, 0, sizeof(board_info));
14638022f9afSAntti Palosaari 		strlcpy(board_info.type, "a8293", I2C_NAME_SIZE);
14648022f9afSAntti Palosaari 		board_info.addr = 0x08;
14658022f9afSAntti Palosaari 		board_info.platform_data = &a8293_pdata;
14668022f9afSAntti Palosaari 		request_module("a8293");
14678022f9afSAntti Palosaari 		client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
14688022f9afSAntti Palosaari 		if (client == NULL || client->dev.driver == NULL) {
14698022f9afSAntti Palosaari 			module_put(dvb->i2c_client_demod->dev.driver->owner);
14708022f9afSAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_demod);
14718022f9afSAntti Palosaari 			result = -ENODEV;
14728022f9afSAntti Palosaari 			goto out_free;
14738022f9afSAntti Palosaari 		}
14748022f9afSAntti Palosaari 		if (!try_module_get(client->dev.driver->owner)) {
14758022f9afSAntti Palosaari 			i2c_unregister_device(client);
14768022f9afSAntti Palosaari 			module_put(dvb->i2c_client_demod->dev.driver->owner);
14778022f9afSAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_demod);
14788022f9afSAntti Palosaari 			result = -ENODEV;
14798022f9afSAntti Palosaari 			goto out_free;
14808022f9afSAntti Palosaari 		}
14818022f9afSAntti Palosaari 		dvb->i2c_client_sec = client;
14820c0d06caSMauro Carvalho Chehab 		break;
14838022f9afSAntti Palosaari 	}
14847c1dfdb0SJakob Haufe 	case EM2874_BOARD_DELOCK_61959:
14850c0d06caSMauro Carvalho Chehab 	case EM2874_BOARD_MAXMEDIA_UB425_TC:
14860c0d06caSMauro Carvalho Chehab 		/* attach demodulator */
14870c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
1488c7a45e5bSMauro Carvalho Chehab 				&dev->i2c_adap[dev->def_i2c_bus]);
14890c0d06caSMauro Carvalho Chehab 
14900c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]) {
14910c0d06caSMauro Carvalho Chehab 			/* disable I2C-gate */
14920c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
14930c0d06caSMauro Carvalho Chehab 
14940c0d06caSMauro Carvalho Chehab 			/* attach tuner */
1495b6c7abb1SAntti Palosaari 			if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1496b6c7abb1SAntti Palosaari 					&dev->i2c_adap[dev->def_i2c_bus],
1497b6c7abb1SAntti Palosaari 					&em28xx_cxd2820r_tda18271_config)) {
14980c0d06caSMauro Carvalho Chehab 				dvb_frontend_detach(dvb->fe[0]);
14990c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
15000c0d06caSMauro Carvalho Chehab 				goto out_free;
15010c0d06caSMauro Carvalho Chehab 			}
15020c0d06caSMauro Carvalho Chehab 		}
15030c0d06caSMauro Carvalho Chehab 		break;
15040c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_PCTV_510E:
15050c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_PCTV_520E:
15060c0d06caSMauro Carvalho Chehab 		pctv_520e_init(dev);
15070c0d06caSMauro Carvalho Chehab 
15080c0d06caSMauro Carvalho Chehab 		/* attach demodulator */
15090c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
1510c7a45e5bSMauro Carvalho Chehab 				&dev->i2c_adap[dev->def_i2c_bus]);
15110c0d06caSMauro Carvalho Chehab 
15120c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]) {
15130c0d06caSMauro Carvalho Chehab 			/* attach tuner */
15140c0d06caSMauro Carvalho Chehab 			if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1515c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
15160c0d06caSMauro Carvalho Chehab 					&em28xx_cxd2820r_tda18271_config)) {
15170c0d06caSMauro Carvalho Chehab 				dvb_frontend_detach(dvb->fe[0]);
15180c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
15190c0d06caSMauro Carvalho Chehab 				goto out_free;
15200c0d06caSMauro Carvalho Chehab 			}
15210c0d06caSMauro Carvalho Chehab 		}
15220c0d06caSMauro Carvalho Chehab 		break;
15231fe0fbd6SGilles Risch 	case EM2884_BOARD_ELGATO_EYETV_HYBRID_2008:
15240c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_CINERGY_HTC_STICK:
1525d6a64327SMauro Carvalho Chehab 	case EM2884_BOARD_TERRATEC_H6:
15260c0d06caSMauro Carvalho Chehab 		terratec_htc_stick_init(dev);
15270c0d06caSMauro Carvalho Chehab 
15280c0d06caSMauro Carvalho Chehab 		/* attach demodulator */
15290c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1530c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
15310c0d06caSMauro Carvalho Chehab 		if (!dvb->fe[0]) {
15320c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
15330c0d06caSMauro Carvalho Chehab 			goto out_free;
15340c0d06caSMauro Carvalho Chehab 		}
15350c0d06caSMauro Carvalho Chehab 
15360c0d06caSMauro Carvalho Chehab 		/* Attach the demodulator. */
15370c0d06caSMauro Carvalho Chehab 		if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1538c7a45e5bSMauro Carvalho Chehab 				&dev->i2c_adap[dev->def_i2c_bus],
15390c0d06caSMauro Carvalho Chehab 				&em28xx_cxd2820r_tda18271_config)) {
15400c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
15410c0d06caSMauro Carvalho Chehab 			goto out_free;
15420c0d06caSMauro Carvalho Chehab 		}
15430c0d06caSMauro Carvalho Chehab 		break;
154489040136SMartin Blumenstingl 	case EM2884_BOARD_TERRATEC_HTC_USB_XS:
154589040136SMartin Blumenstingl 		terratec_htc_usb_xs_init(dev);
154689040136SMartin Blumenstingl 
154789040136SMartin Blumenstingl 		/* attach demodulator */
154889040136SMartin Blumenstingl 		dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1549c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
155089040136SMartin Blumenstingl 		if (!dvb->fe[0]) {
155189040136SMartin Blumenstingl 			result = -EINVAL;
155289040136SMartin Blumenstingl 			goto out_free;
155389040136SMartin Blumenstingl 		}
155489040136SMartin Blumenstingl 
155589040136SMartin Blumenstingl 		/* Attach the demodulator. */
155689040136SMartin Blumenstingl 		if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1557c7a45e5bSMauro Carvalho Chehab 				&dev->i2c_adap[dev->def_i2c_bus],
155889040136SMartin Blumenstingl 				&em28xx_cxd2820r_tda18271_config)) {
155989040136SMartin Blumenstingl 			result = -EINVAL;
156089040136SMartin Blumenstingl 			goto out_free;
156189040136SMartin Blumenstingl 		}
156289040136SMartin Blumenstingl 		break;
15636dbea9f0SJean-Francois Thibert 	case EM2874_BOARD_KWORLD_UB435Q_V2:
15646dbea9f0SJean-Francois Thibert 		dvb->fe[0] = dvb_attach(lgdt3305_attach,
15656dbea9f0SJean-Francois Thibert 					&em2874_lgdt3305_dev,
15666dbea9f0SJean-Francois Thibert 					&dev->i2c_adap[dev->def_i2c_bus]);
15676dbea9f0SJean-Francois Thibert 		if (!dvb->fe[0]) {
15686dbea9f0SJean-Francois Thibert 			result = -EINVAL;
15696dbea9f0SJean-Francois Thibert 			goto out_free;
15706dbea9f0SJean-Francois Thibert 		}
15716dbea9f0SJean-Francois Thibert 
15726dbea9f0SJean-Francois Thibert 		/* Attach the demodulator. */
15736dbea9f0SJean-Francois Thibert 		if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
15746dbea9f0SJean-Francois Thibert 				&dev->i2c_adap[dev->def_i2c_bus],
15756dbea9f0SJean-Francois Thibert 				&kworld_ub435q_v2_config)) {
15766dbea9f0SJean-Francois Thibert 			result = -EINVAL;
15776dbea9f0SJean-Francois Thibert 			goto out_free;
15786dbea9f0SJean-Francois Thibert 		}
15796dbea9f0SJean-Francois Thibert 		break;
158002bc1f55SMauro Carvalho Chehab 	case EM2874_BOARD_KWORLD_UB435Q_V3:
1581ac7a24fbSAntti Palosaari 	{
1582ac7a24fbSAntti Palosaari 		struct i2c_client *client;
1583ac7a24fbSAntti Palosaari 		struct i2c_adapter *adapter = &dev->i2c_adap[dev->def_i2c_bus];
1584ac7a24fbSAntti Palosaari 		struct i2c_board_info board_info = {
1585ac7a24fbSAntti Palosaari 			.type = "tda18212",
1586ac7a24fbSAntti Palosaari 			.addr = 0x60,
1587ac7a24fbSAntti Palosaari 			.platform_data = &kworld_ub435q_v3_config,
1588ac7a24fbSAntti Palosaari 		};
1589ac7a24fbSAntti Palosaari 
159002bc1f55SMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(lgdt3305_attach,
159102bc1f55SMauro Carvalho Chehab 					&em2874_lgdt3305_nogate_dev,
159202bc1f55SMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
159302bc1f55SMauro Carvalho Chehab 		if (!dvb->fe[0]) {
159402bc1f55SMauro Carvalho Chehab 			result = -EINVAL;
159502bc1f55SMauro Carvalho Chehab 			goto out_free;
159602bc1f55SMauro Carvalho Chehab 		}
159702bc1f55SMauro Carvalho Chehab 
1598ac7a24fbSAntti Palosaari 		/* attach tuner */
1599ac7a24fbSAntti Palosaari 		kworld_ub435q_v3_config.fe = dvb->fe[0];
1600ac7a24fbSAntti Palosaari 		request_module("tda18212");
1601ac7a24fbSAntti Palosaari 		client = i2c_new_device(adapter, &board_info);
1602ac7a24fbSAntti Palosaari 		if (client == NULL || client->dev.driver == NULL) {
1603ac7a24fbSAntti Palosaari 			dvb_frontend_detach(dvb->fe[0]);
1604ac7a24fbSAntti Palosaari 			result = -ENODEV;
160502bc1f55SMauro Carvalho Chehab 			goto out_free;
160602bc1f55SMauro Carvalho Chehab 		}
1607ac7a24fbSAntti Palosaari 
1608ac7a24fbSAntti Palosaari 		if (!try_module_get(client->dev.driver->owner)) {
1609ac7a24fbSAntti Palosaari 			i2c_unregister_device(client);
1610ac7a24fbSAntti Palosaari 			dvb_frontend_detach(dvb->fe[0]);
1611ac7a24fbSAntti Palosaari 			result = -ENODEV;
1612ac7a24fbSAntti Palosaari 			goto out_free;
1613ac7a24fbSAntti Palosaari 		}
1614ac7a24fbSAntti Palosaari 
1615ac7a24fbSAntti Palosaari 		dvb->i2c_client_tuner = client;
161602bc1f55SMauro Carvalho Chehab 		break;
1617ac7a24fbSAntti Palosaari 	}
161838b2df95SDevin Heitmueller 	case EM2874_BOARD_PCTV_HD_MINI_80E:
161938b2df95SDevin Heitmueller 		dvb->fe[0] = dvb_attach(drx39xxj_attach, &dev->i2c_adap[dev->def_i2c_bus]);
162038b2df95SDevin Heitmueller 		if (dvb->fe[0] != NULL) {
162138b2df95SDevin Heitmueller 			dvb->fe[0] = dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
162238b2df95SDevin Heitmueller 						&dev->i2c_adap[dev->def_i2c_bus],
162338b2df95SDevin Heitmueller 						&pinnacle_80e_dvb_config);
162438b2df95SDevin Heitmueller 			if (!dvb->fe[0]) {
162538b2df95SDevin Heitmueller 				result = -EINVAL;
162638b2df95SDevin Heitmueller 				goto out_free;
162738b2df95SDevin Heitmueller 			}
162838b2df95SDevin Heitmueller 		}
162938b2df95SDevin Heitmueller 		break;
163076b91be3SAntti Palosaari 	case EM28178_BOARD_PCTV_461E: {
1631425f53aaSAntti Palosaari 		struct i2c_client *client;
163276b91be3SAntti Palosaari 		struct i2c_adapter *i2c_adapter;
163376b91be3SAntti Palosaari 		struct i2c_board_info board_info;
163476b91be3SAntti Palosaari 		struct m88ds3103_platform_data m88ds3103_pdata = {};
163576b91be3SAntti Palosaari 		struct ts2020_config ts2020_config = {};
163676b91be3SAntti Palosaari 		struct a8293_platform_data a8293_pdata = {};
1637ec573362SAntti Palosaari 
1638ec573362SAntti Palosaari 		/* attach demod */
163976b91be3SAntti Palosaari 		m88ds3103_pdata.clk = 27000000;
164076b91be3SAntti Palosaari 		m88ds3103_pdata.i2c_wr_max = 33;
164176b91be3SAntti Palosaari 		m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL;
164276b91be3SAntti Palosaari 		m88ds3103_pdata.ts_clk = 16000;
164376b91be3SAntti Palosaari 		m88ds3103_pdata.ts_clk_pol = 1;
164476b91be3SAntti Palosaari 		m88ds3103_pdata.agc = 0x99;
164576b91be3SAntti Palosaari 		memset(&board_info, 0, sizeof(board_info));
164676b91be3SAntti Palosaari 		strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
164776b91be3SAntti Palosaari 		board_info.addr = 0x68;
164876b91be3SAntti Palosaari 		board_info.platform_data = &m88ds3103_pdata;
164976b91be3SAntti Palosaari 		request_module("m88ds3103");
165076b91be3SAntti Palosaari 		client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
165176b91be3SAntti Palosaari 		if (client == NULL || client->dev.driver == NULL) {
1652ec573362SAntti Palosaari 			result = -ENODEV;
1653ec573362SAntti Palosaari 			goto out_free;
1654ec573362SAntti Palosaari 		}
165576b91be3SAntti Palosaari 		if (!try_module_get(client->dev.driver->owner)) {
165676b91be3SAntti Palosaari 			i2c_unregister_device(client);
165776b91be3SAntti Palosaari 			result = -ENODEV;
165876b91be3SAntti Palosaari 			goto out_free;
165976b91be3SAntti Palosaari 		}
166076b91be3SAntti Palosaari 		dvb->fe[0] = m88ds3103_pdata.get_dvb_frontend(client);
166176b91be3SAntti Palosaari 		i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
166276b91be3SAntti Palosaari 		dvb->i2c_client_demod = client;
1663ec573362SAntti Palosaari 
1664ec573362SAntti Palosaari 		/* attach tuner */
166583c1b6ceSAntti Palosaari 		ts2020_config.fe = dvb->fe[0];
166676b91be3SAntti Palosaari 		memset(&board_info, 0, sizeof(board_info));
166776b91be3SAntti Palosaari 		strlcpy(board_info.type, "ts2022", I2C_NAME_SIZE);
166876b91be3SAntti Palosaari 		board_info.addr = 0x60;
166976b91be3SAntti Palosaari 		board_info.platform_data = &ts2020_config;
167083c1b6ceSAntti Palosaari 		request_module("ts2020");
167176b91be3SAntti Palosaari 		client = i2c_new_device(i2c_adapter, &board_info);
1672425f53aaSAntti Palosaari 		if (client == NULL || client->dev.driver == NULL) {
167376b91be3SAntti Palosaari 			module_put(dvb->i2c_client_demod->dev.driver->owner);
167476b91be3SAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_demod);
1675425f53aaSAntti Palosaari 			result = -ENODEV;
1676425f53aaSAntti Palosaari 			goto out_free;
1677425f53aaSAntti Palosaari 		}
1678425f53aaSAntti Palosaari 		if (!try_module_get(client->dev.driver->owner)) {
1679425f53aaSAntti Palosaari 			i2c_unregister_device(client);
168076b91be3SAntti Palosaari 			module_put(dvb->i2c_client_demod->dev.driver->owner);
168176b91be3SAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_demod);
1682425f53aaSAntti Palosaari 			result = -ENODEV;
1683425f53aaSAntti Palosaari 			goto out_free;
1684425f53aaSAntti Palosaari 		}
168576b91be3SAntti Palosaari 		dvb->i2c_client_tuner = client;
1686ec573362SAntti Palosaari 		/* delegate signal strength measurement to tuner */
1687ec573362SAntti Palosaari 		dvb->fe[0]->ops.read_signal_strength =
1688ec573362SAntti Palosaari 				dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1689ec573362SAntti Palosaari 
1690ec573362SAntti Palosaari 		/* attach SEC */
169176b91be3SAntti Palosaari 		a8293_pdata.dvb_frontend = dvb->fe[0];
169276b91be3SAntti Palosaari 		memset(&board_info, 0, sizeof(board_info));
169376b91be3SAntti Palosaari 		strlcpy(board_info.type, "a8293", I2C_NAME_SIZE);
169476b91be3SAntti Palosaari 		board_info.addr = 0x08;
169576b91be3SAntti Palosaari 		board_info.platform_data = &a8293_pdata;
169676b91be3SAntti Palosaari 		request_module("a8293");
169776b91be3SAntti Palosaari 		client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
169876b91be3SAntti Palosaari 		if (client == NULL || client->dev.driver == NULL) {
169976b91be3SAntti Palosaari 			module_put(dvb->i2c_client_tuner->dev.driver->owner);
170076b91be3SAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_tuner);
170176b91be3SAntti Palosaari 			module_put(dvb->i2c_client_demod->dev.driver->owner);
170276b91be3SAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_demod);
1703ec573362SAntti Palosaari 			result = -ENODEV;
1704ec573362SAntti Palosaari 			goto out_free;
1705ec573362SAntti Palosaari 		}
170676b91be3SAntti Palosaari 		if (!try_module_get(client->dev.driver->owner)) {
170776b91be3SAntti Palosaari 			i2c_unregister_device(client);
170876b91be3SAntti Palosaari 			module_put(dvb->i2c_client_tuner->dev.driver->owner);
170976b91be3SAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_tuner);
171076b91be3SAntti Palosaari 			module_put(dvb->i2c_client_demod->dev.driver->owner);
171176b91be3SAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_demod);
171276b91be3SAntti Palosaari 			result = -ENODEV;
171376b91be3SAntti Palosaari 			goto out_free;
1714ec573362SAntti Palosaari 		}
171576b91be3SAntti Palosaari 		dvb->i2c_client_sec = client;
1716ec573362SAntti Palosaari 		break;
171776b91be3SAntti Palosaari 	}
171819229240SAntti Palosaari 	case EM28178_BOARD_PCTV_292E:
171919229240SAntti Palosaari 		{
172019229240SAntti Palosaari 			struct i2c_adapter *adapter;
172119229240SAntti Palosaari 			struct i2c_client *client;
172219229240SAntti Palosaari 			struct i2c_board_info info;
172319229240SAntti Palosaari 			struct si2168_config si2168_config;
172419229240SAntti Palosaari 			struct si2157_config si2157_config;
172519229240SAntti Palosaari 
172619229240SAntti Palosaari 			/* attach demod */
1727bf9025f3SOlli Salonen 			memset(&si2168_config, 0, sizeof(si2168_config));
172819229240SAntti Palosaari 			si2168_config.i2c_adapter = &adapter;
172919229240SAntti Palosaari 			si2168_config.fe = &dvb->fe[0];
17306fd2f44aSOlli Salonen 			si2168_config.ts_mode = SI2168_TS_PARALLEL;
173119229240SAntti Palosaari 			memset(&info, 0, sizeof(struct i2c_board_info));
173219229240SAntti Palosaari 			strlcpy(info.type, "si2168", I2C_NAME_SIZE);
173319229240SAntti Palosaari 			info.addr = 0x64;
173419229240SAntti Palosaari 			info.platform_data = &si2168_config;
173519229240SAntti Palosaari 			request_module(info.type);
173619229240SAntti Palosaari 			client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
173719229240SAntti Palosaari 			if (client == NULL || client->dev.driver == NULL) {
173819229240SAntti Palosaari 				result = -ENODEV;
173919229240SAntti Palosaari 				goto out_free;
174019229240SAntti Palosaari 			}
174119229240SAntti Palosaari 
174219229240SAntti Palosaari 			if (!try_module_get(client->dev.driver->owner)) {
174319229240SAntti Palosaari 				i2c_unregister_device(client);
174419229240SAntti Palosaari 				result = -ENODEV;
174519229240SAntti Palosaari 				goto out_free;
174619229240SAntti Palosaari 			}
174719229240SAntti Palosaari 
174819229240SAntti Palosaari 			dvb->i2c_client_demod = client;
174919229240SAntti Palosaari 
175019229240SAntti Palosaari 			/* attach tuner */
1751c3b513bdSMatthias Schwarzott 			memset(&si2157_config, 0, sizeof(si2157_config));
175219229240SAntti Palosaari 			si2157_config.fe = dvb->fe[0];
1753ee3c3e46SOlli Salonen 			si2157_config.if_port = 1;
1754133bc4e4SMauro Carvalho Chehab #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1755133bc4e4SMauro Carvalho Chehab 			si2157_config.mdev = dev->media_dev;
1756133bc4e4SMauro Carvalho Chehab #endif
175719229240SAntti Palosaari 			memset(&info, 0, sizeof(struct i2c_board_info));
175819229240SAntti Palosaari 			strlcpy(info.type, "si2157", I2C_NAME_SIZE);
175919229240SAntti Palosaari 			info.addr = 0x60;
176019229240SAntti Palosaari 			info.platform_data = &si2157_config;
176119229240SAntti Palosaari 			request_module(info.type);
176219229240SAntti Palosaari 			client = i2c_new_device(adapter, &info);
176319229240SAntti Palosaari 			if (client == NULL || client->dev.driver == NULL) {
176419229240SAntti Palosaari 				module_put(dvb->i2c_client_demod->dev.driver->owner);
176519229240SAntti Palosaari 				i2c_unregister_device(dvb->i2c_client_demod);
176619229240SAntti Palosaari 				result = -ENODEV;
176719229240SAntti Palosaari 				goto out_free;
176819229240SAntti Palosaari 			}
176919229240SAntti Palosaari 
177019229240SAntti Palosaari 			if (!try_module_get(client->dev.driver->owner)) {
177119229240SAntti Palosaari 				i2c_unregister_device(client);
177219229240SAntti Palosaari 				module_put(dvb->i2c_client_demod->dev.driver->owner);
177319229240SAntti Palosaari 				i2c_unregister_device(dvb->i2c_client_demod);
177419229240SAntti Palosaari 				result = -ENODEV;
177519229240SAntti Palosaari 				goto out_free;
177619229240SAntti Palosaari 			}
177719229240SAntti Palosaari 
177819229240SAntti Palosaari 			dvb->i2c_client_tuner = client;
1779ffb9948eSAntti Palosaari 			dvb->fe[0]->ops.set_lna = em28xx_pctv_292e_set_lna;
178019229240SAntti Palosaari 		}
178119229240SAntti Palosaari 		break;
1782fc30dd76SOlli Salonen 	case EM28178_BOARD_TERRATEC_T2_STICK_HD:
1783fc30dd76SOlli Salonen 		{
1784fc30dd76SOlli Salonen 			struct i2c_adapter *adapter;
1785fc30dd76SOlli Salonen 			struct i2c_client *client;
1786fc30dd76SOlli Salonen 			struct i2c_board_info info;
1787fc30dd76SOlli Salonen 			struct si2168_config si2168_config;
1788fc30dd76SOlli Salonen 			struct si2157_config si2157_config;
1789fc30dd76SOlli Salonen 
1790fc30dd76SOlli Salonen 			/* attach demod */
1791fc30dd76SOlli Salonen 			memset(&si2168_config, 0, sizeof(si2168_config));
1792fc30dd76SOlli Salonen 			si2168_config.i2c_adapter = &adapter;
1793fc30dd76SOlli Salonen 			si2168_config.fe = &dvb->fe[0];
1794fc30dd76SOlli Salonen 			si2168_config.ts_mode = SI2168_TS_PARALLEL;
1795fc30dd76SOlli Salonen 			memset(&info, 0, sizeof(struct i2c_board_info));
1796fc30dd76SOlli Salonen 			strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1797fc30dd76SOlli Salonen 			info.addr = 0x64;
1798fc30dd76SOlli Salonen 			info.platform_data = &si2168_config;
1799fc30dd76SOlli Salonen 			request_module(info.type);
1800fc30dd76SOlli Salonen 			client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
1801fc30dd76SOlli Salonen 			if (client == NULL || client->dev.driver == NULL) {
1802fc30dd76SOlli Salonen 				result = -ENODEV;
1803fc30dd76SOlli Salonen 				goto out_free;
1804fc30dd76SOlli Salonen 			}
1805fc30dd76SOlli Salonen 
1806fc30dd76SOlli Salonen 			if (!try_module_get(client->dev.driver->owner)) {
1807fc30dd76SOlli Salonen 				i2c_unregister_device(client);
1808fc30dd76SOlli Salonen 				result = -ENODEV;
1809fc30dd76SOlli Salonen 				goto out_free;
1810fc30dd76SOlli Salonen 			}
1811fc30dd76SOlli Salonen 
1812fc30dd76SOlli Salonen 			dvb->i2c_client_demod = client;
1813fc30dd76SOlli Salonen 
1814fc30dd76SOlli Salonen 			/* attach tuner */
1815fc30dd76SOlli Salonen 			memset(&si2157_config, 0, sizeof(si2157_config));
1816fc30dd76SOlli Salonen 			si2157_config.fe = dvb->fe[0];
1817ee3c3e46SOlli Salonen 			si2157_config.if_port = 0;
1818133bc4e4SMauro Carvalho Chehab #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1819133bc4e4SMauro Carvalho Chehab 			si2157_config.mdev = dev->media_dev;
1820133bc4e4SMauro Carvalho Chehab #endif
1821fc30dd76SOlli Salonen 			memset(&info, 0, sizeof(struct i2c_board_info));
1822fc30dd76SOlli Salonen 			strlcpy(info.type, "si2146", I2C_NAME_SIZE);
1823fc30dd76SOlli Salonen 			info.addr = 0x60;
1824fc30dd76SOlli Salonen 			info.platform_data = &si2157_config;
1825fc30dd76SOlli Salonen 			request_module("si2157");
1826fc30dd76SOlli Salonen 			client = i2c_new_device(adapter, &info);
1827fc30dd76SOlli Salonen 			if (client == NULL || client->dev.driver == NULL) {
1828fc30dd76SOlli Salonen 				module_put(dvb->i2c_client_demod->dev.driver->owner);
1829fc30dd76SOlli Salonen 				i2c_unregister_device(dvb->i2c_client_demod);
1830fc30dd76SOlli Salonen 				result = -ENODEV;
1831fc30dd76SOlli Salonen 				goto out_free;
1832fc30dd76SOlli Salonen 			}
1833fc30dd76SOlli Salonen 
1834fc30dd76SOlli Salonen 			if (!try_module_get(client->dev.driver->owner)) {
1835fc30dd76SOlli Salonen 				i2c_unregister_device(client);
1836fc30dd76SOlli Salonen 				module_put(dvb->i2c_client_demod->dev.driver->owner);
1837fc30dd76SOlli Salonen 				i2c_unregister_device(dvb->i2c_client_demod);
1838fc30dd76SOlli Salonen 				result = -ENODEV;
1839fc30dd76SOlli Salonen 				goto out_free;
1840fc30dd76SOlli Salonen 			}
1841fc30dd76SOlli Salonen 
1842fc30dd76SOlli Salonen 			dvb->i2c_client_tuner = client;
1843fc30dd76SOlli Salonen 		}
1844fc30dd76SOlli Salonen 		break;
1845ab4d1452SSatoshi Nagahama 
1846ab4d1452SSatoshi Nagahama 	case EM28178_BOARD_PLEX_PX_BCUD:
1847ab4d1452SSatoshi Nagahama 		{
1848ab4d1452SSatoshi Nagahama 			struct i2c_client *client;
1849ab4d1452SSatoshi Nagahama 			struct i2c_board_info info;
1850ab4d1452SSatoshi Nagahama 			struct tc90522_config tc90522_config;
1851ab4d1452SSatoshi Nagahama 			struct qm1d1c0042_config qm1d1c0042_config;
1852ab4d1452SSatoshi Nagahama 
1853ab4d1452SSatoshi Nagahama 			/* attach demod */
1854ab4d1452SSatoshi Nagahama 			memset(&tc90522_config, 0, sizeof(tc90522_config));
1855ab4d1452SSatoshi Nagahama 			memset(&info, 0, sizeof(struct i2c_board_info));
1856ab4d1452SSatoshi Nagahama 			strlcpy(info.type, "tc90522sat", I2C_NAME_SIZE);
1857ab4d1452SSatoshi Nagahama 			info.addr = 0x15;
1858ab4d1452SSatoshi Nagahama 			info.platform_data = &tc90522_config;
1859ab4d1452SSatoshi Nagahama 			request_module("tc90522");
1860ab4d1452SSatoshi Nagahama 			client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
1861ab4d1452SSatoshi Nagahama 			if (client == NULL || client->dev.driver == NULL) {
1862ab4d1452SSatoshi Nagahama 				result = -ENODEV;
1863ab4d1452SSatoshi Nagahama 				goto out_free;
1864ab4d1452SSatoshi Nagahama 			}
1865ab4d1452SSatoshi Nagahama 			dvb->i2c_client_demod = client;
1866ab4d1452SSatoshi Nagahama 			if (!try_module_get(client->dev.driver->owner)) {
1867ab4d1452SSatoshi Nagahama 				i2c_unregister_device(client);
1868ab4d1452SSatoshi Nagahama 				result = -ENODEV;
1869ab4d1452SSatoshi Nagahama 				goto out_free;
1870ab4d1452SSatoshi Nagahama 			}
1871ab4d1452SSatoshi Nagahama 
1872ab4d1452SSatoshi Nagahama 			/* attach tuner */
1873ab4d1452SSatoshi Nagahama 			memset(&qm1d1c0042_config, 0,
1874ab4d1452SSatoshi Nagahama 			       sizeof(qm1d1c0042_config));
1875ab4d1452SSatoshi Nagahama 			qm1d1c0042_config.fe = tc90522_config.fe;
1876ab4d1452SSatoshi Nagahama 			qm1d1c0042_config.lpf = 1;
1877ab4d1452SSatoshi Nagahama 			memset(&info, 0, sizeof(struct i2c_board_info));
1878ab4d1452SSatoshi Nagahama 			strlcpy(info.type, "qm1d1c0042", I2C_NAME_SIZE);
1879ab4d1452SSatoshi Nagahama 			info.addr = 0x61;
1880ab4d1452SSatoshi Nagahama 			info.platform_data = &qm1d1c0042_config;
1881ab4d1452SSatoshi Nagahama 			request_module(info.type);
1882ab4d1452SSatoshi Nagahama 			client = i2c_new_device(tc90522_config.tuner_i2c,
1883ab4d1452SSatoshi Nagahama 						&info);
1884ab4d1452SSatoshi Nagahama 			if (client == NULL || client->dev.driver == NULL) {
1885ab4d1452SSatoshi Nagahama 				module_put(dvb->i2c_client_demod->dev.driver->owner);
1886ab4d1452SSatoshi Nagahama 				i2c_unregister_device(dvb->i2c_client_demod);
1887ab4d1452SSatoshi Nagahama 				result = -ENODEV;
1888ab4d1452SSatoshi Nagahama 				goto out_free;
1889ab4d1452SSatoshi Nagahama 			}
1890ab4d1452SSatoshi Nagahama 			dvb->i2c_client_tuner = client;
1891ab4d1452SSatoshi Nagahama 			if (!try_module_get(client->dev.driver->owner)) {
1892ab4d1452SSatoshi Nagahama 				i2c_unregister_device(client);
1893ab4d1452SSatoshi Nagahama 				module_put(dvb->i2c_client_demod->dev.driver->owner);
1894ab4d1452SSatoshi Nagahama 				i2c_unregister_device(dvb->i2c_client_demod);
1895ab4d1452SSatoshi Nagahama 				result = -ENODEV;
1896ab4d1452SSatoshi Nagahama 				goto out_free;
1897ab4d1452SSatoshi Nagahama 			}
1898ab4d1452SSatoshi Nagahama 			dvb->fe[0] = tc90522_config.fe;
1899ab4d1452SSatoshi Nagahama 			px_bcud_init(dev);
1900ab4d1452SSatoshi Nagahama 		}
1901ab4d1452SSatoshi Nagahama 		break;
190211a2a949SOlli Salonen 	case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB:
190311a2a949SOlli Salonen 		{
190411a2a949SOlli Salonen 			struct i2c_adapter *adapter;
190511a2a949SOlli Salonen 			struct i2c_client *client;
190611a2a949SOlli Salonen 			struct i2c_board_info info;
190711a2a949SOlli Salonen 			struct si2168_config si2168_config;
190811a2a949SOlli Salonen 			struct si2157_config si2157_config;
190911a2a949SOlli Salonen 
191011a2a949SOlli Salonen 			/* attach demod */
191111a2a949SOlli Salonen 			memset(&si2168_config, 0, sizeof(si2168_config));
191211a2a949SOlli Salonen 			si2168_config.i2c_adapter = &adapter;
191311a2a949SOlli Salonen 			si2168_config.fe = &dvb->fe[0];
191411a2a949SOlli Salonen 			si2168_config.ts_mode = SI2168_TS_SERIAL;
191511a2a949SOlli Salonen 			memset(&info, 0, sizeof(struct i2c_board_info));
191611a2a949SOlli Salonen 			strlcpy(info.type, "si2168", I2C_NAME_SIZE);
191711a2a949SOlli Salonen 			info.addr = 0x64;
191811a2a949SOlli Salonen 			info.platform_data = &si2168_config;
191911a2a949SOlli Salonen 			request_module(info.type);
192011a2a949SOlli Salonen 			client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
192111a2a949SOlli Salonen 			if (client == NULL || client->dev.driver == NULL) {
192211a2a949SOlli Salonen 				result = -ENODEV;
192311a2a949SOlli Salonen 				goto out_free;
192411a2a949SOlli Salonen 			}
192511a2a949SOlli Salonen 
192611a2a949SOlli Salonen 			if (!try_module_get(client->dev.driver->owner)) {
192711a2a949SOlli Salonen 				i2c_unregister_device(client);
192811a2a949SOlli Salonen 				result = -ENODEV;
192911a2a949SOlli Salonen 				goto out_free;
193011a2a949SOlli Salonen 			}
193111a2a949SOlli Salonen 
193211a2a949SOlli Salonen 			dvb->i2c_client_demod = client;
193311a2a949SOlli Salonen 
193411a2a949SOlli Salonen 			/* attach tuner */
193511a2a949SOlli Salonen 			memset(&si2157_config, 0, sizeof(si2157_config));
193611a2a949SOlli Salonen 			si2157_config.fe = dvb->fe[0];
193711a2a949SOlli Salonen 			si2157_config.if_port = 1;
193811a2a949SOlli Salonen #ifdef CONFIG_MEDIA_CONTROLLER_DVB
193911a2a949SOlli Salonen 			si2157_config.mdev = dev->media_dev;
194011a2a949SOlli Salonen #endif
194111a2a949SOlli Salonen 			memset(&info, 0, sizeof(struct i2c_board_info));
194211a2a949SOlli Salonen 			strlcpy(info.type, "si2157", I2C_NAME_SIZE);
194311a2a949SOlli Salonen 			info.addr = 0x60;
194411a2a949SOlli Salonen 			info.platform_data = &si2157_config;
194511a2a949SOlli Salonen 			request_module(info.type);
194611a2a949SOlli Salonen 			client = i2c_new_device(adapter, &info);
194711a2a949SOlli Salonen 			if (client == NULL || client->dev.driver == NULL) {
194811a2a949SOlli Salonen 				module_put(dvb->i2c_client_demod->dev.driver->owner);
194911a2a949SOlli Salonen 				i2c_unregister_device(dvb->i2c_client_demod);
195011a2a949SOlli Salonen 				result = -ENODEV;
195111a2a949SOlli Salonen 				goto out_free;
195211a2a949SOlli Salonen 			}
195311a2a949SOlli Salonen 
195411a2a949SOlli Salonen 			if (!try_module_get(client->dev.driver->owner)) {
195511a2a949SOlli Salonen 				i2c_unregister_device(client);
195611a2a949SOlli Salonen 				module_put(dvb->i2c_client_demod->dev.driver->owner);
195711a2a949SOlli Salonen 				i2c_unregister_device(dvb->i2c_client_demod);
195811a2a949SOlli Salonen 				result = -ENODEV;
195911a2a949SOlli Salonen 				goto out_free;
196011a2a949SOlli Salonen 			}
196111a2a949SOlli Salonen 
196211a2a949SOlli Salonen 			dvb->i2c_client_tuner = client;
196311a2a949SOlli Salonen 
196411a2a949SOlli Salonen 		}
196511a2a949SOlli Salonen 		break;
19661586342eSKevin Cheng 	case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595:
19671586342eSKevin Cheng 		{
19681586342eSKevin Cheng 			struct i2c_adapter *adapter;
19691586342eSKevin Cheng 			struct i2c_client *client;
19701586342eSKevin Cheng 			struct i2c_board_info info = {};
19711586342eSKevin Cheng 			struct lgdt3306a_config lgdt3306a_config;
19721586342eSKevin Cheng 			struct si2157_config si2157_config = {};
19731586342eSKevin Cheng 
19741586342eSKevin Cheng 			/* attach demod */
19751586342eSKevin Cheng 			lgdt3306a_config = hauppauge_01595_lgdt3306a_config;
19761586342eSKevin Cheng 			lgdt3306a_config.fe = &dvb->fe[0];
19771586342eSKevin Cheng 			lgdt3306a_config.i2c_adapter = &adapter;
19781586342eSKevin Cheng 			strlcpy(info.type, "lgdt3306a", sizeof(info.type));
19791586342eSKevin Cheng 			info.addr = 0x59;
19801586342eSKevin Cheng 			info.platform_data = &lgdt3306a_config;
19811586342eSKevin Cheng 			request_module(info.type);
19821586342eSKevin Cheng 			client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus],
19831586342eSKevin Cheng 					&info);
19841586342eSKevin Cheng 			if (client == NULL || client->dev.driver == NULL) {
19851586342eSKevin Cheng 				result = -ENODEV;
19861586342eSKevin Cheng 				goto out_free;
19871586342eSKevin Cheng 			}
19881586342eSKevin Cheng 
19891586342eSKevin Cheng 			if (!try_module_get(client->dev.driver->owner)) {
19901586342eSKevin Cheng 				i2c_unregister_device(client);
19911586342eSKevin Cheng 				result = -ENODEV;
19921586342eSKevin Cheng 				goto out_free;
19931586342eSKevin Cheng 			}
19941586342eSKevin Cheng 
19951586342eSKevin Cheng 			dvb->i2c_client_demod = client;
19961586342eSKevin Cheng 
19971586342eSKevin Cheng 			/* attach tuner */
19981586342eSKevin Cheng 			si2157_config.fe = dvb->fe[0];
19991586342eSKevin Cheng 			si2157_config.if_port = 1;
20001586342eSKevin Cheng 			si2157_config.inversion = 1;
20011586342eSKevin Cheng #ifdef CONFIG_MEDIA_CONTROLLER_DVB
20021586342eSKevin Cheng 			si2157_config.mdev = dev->media_dev;
20031586342eSKevin Cheng #endif
20041586342eSKevin Cheng 			memset(&info, 0, sizeof(struct i2c_board_info));
20051586342eSKevin Cheng 			strlcpy(info.type, "si2157", sizeof(info.type));
20061586342eSKevin Cheng 			info.addr = 0x60;
20071586342eSKevin Cheng 			info.platform_data = &si2157_config;
20081586342eSKevin Cheng 			request_module(info.type);
20091586342eSKevin Cheng 
20101586342eSKevin Cheng 			client = i2c_new_device(adapter, &info);
20111586342eSKevin Cheng 			if (client == NULL || client->dev.driver == NULL) {
20121586342eSKevin Cheng 				module_put(dvb->i2c_client_demod->dev.driver->owner);
20131586342eSKevin Cheng 				i2c_unregister_device(dvb->i2c_client_demod);
20141586342eSKevin Cheng 				result = -ENODEV;
20151586342eSKevin Cheng 				goto out_free;
20161586342eSKevin Cheng 			}
20171586342eSKevin Cheng 			if (!try_module_get(client->dev.driver->owner)) {
20181586342eSKevin Cheng 				i2c_unregister_device(client);
20191586342eSKevin Cheng 				module_put(dvb->i2c_client_demod->dev.driver->owner);
20201586342eSKevin Cheng 				i2c_unregister_device(dvb->i2c_client_demod);
20211586342eSKevin Cheng 				result = -ENODEV;
20221586342eSKevin Cheng 				goto out_free;
20231586342eSKevin Cheng 			}
20241586342eSKevin Cheng 
20251586342eSKevin Cheng 			dvb->i2c_client_tuner = client;
20261586342eSKevin Cheng 		}
20271586342eSKevin Cheng 		break;
20280c0d06caSMauro Carvalho Chehab 	default:
202929b05e22SMauro Carvalho Chehab 		dev_err(&dev->intf->dev,
2030ce8591ffSMauro Carvalho Chehab 			"The frontend of your DVB/ATSC card isn't supported yet\n");
20310c0d06caSMauro Carvalho Chehab 		break;
20320c0d06caSMauro Carvalho Chehab 	}
20330c0d06caSMauro Carvalho Chehab 	if (NULL == dvb->fe[0]) {
203429b05e22SMauro Carvalho Chehab 		dev_err(&dev->intf->dev, "frontend initialization failed\n");
20350c0d06caSMauro Carvalho Chehab 		result = -EINVAL;
20360c0d06caSMauro Carvalho Chehab 		goto out_free;
20370c0d06caSMauro Carvalho Chehab 	}
20380c0d06caSMauro Carvalho Chehab 	/* define general-purpose callback pointer */
20390c0d06caSMauro Carvalho Chehab 	dvb->fe[0]->callback = em28xx_tuner_callback;
20400c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
20410c0d06caSMauro Carvalho Chehab 		dvb->fe[1]->callback = em28xx_tuner_callback;
20420c0d06caSMauro Carvalho Chehab 
20430c0d06caSMauro Carvalho Chehab 	/* register everything */
204429b05e22SMauro Carvalho Chehab 	result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->intf->dev);
20450c0d06caSMauro Carvalho Chehab 
20460c0d06caSMauro Carvalho Chehab 	if (result < 0)
20470c0d06caSMauro Carvalho Chehab 		goto out_free;
20480c0d06caSMauro Carvalho Chehab 
204929b05e22SMauro Carvalho Chehab 	dev_info(&dev->intf->dev, "DVB extension successfully initialized\n");
205047677e51SMauro Carvalho Chehab 
205147677e51SMauro Carvalho Chehab 	kref_get(&dev->ref);
205247677e51SMauro Carvalho Chehab 
20530c0d06caSMauro Carvalho Chehab ret:
20540c0d06caSMauro Carvalho Chehab 	em28xx_set_mode(dev, EM28XX_SUSPEND);
20550c0d06caSMauro Carvalho Chehab 	mutex_unlock(&dev->lock);
20560c0d06caSMauro Carvalho Chehab 	return result;
20570c0d06caSMauro Carvalho Chehab 
20580c0d06caSMauro Carvalho Chehab out_free:
20590c0d06caSMauro Carvalho Chehab 	kfree(dvb);
20600c0d06caSMauro Carvalho Chehab 	dev->dvb = NULL;
20610c0d06caSMauro Carvalho Chehab 	goto ret;
20620c0d06caSMauro Carvalho Chehab }
20630c0d06caSMauro Carvalho Chehab 
20640c0d06caSMauro Carvalho Chehab static inline void prevent_sleep(struct dvb_frontend_ops *ops)
20650c0d06caSMauro Carvalho Chehab {
20660c0d06caSMauro Carvalho Chehab 	ops->set_voltage = NULL;
20670c0d06caSMauro Carvalho Chehab 	ops->sleep = NULL;
20680c0d06caSMauro Carvalho Chehab 	ops->tuner_ops.sleep = NULL;
20690c0d06caSMauro Carvalho Chehab }
20700c0d06caSMauro Carvalho Chehab 
20710c0d06caSMauro Carvalho Chehab static int em28xx_dvb_fini(struct em28xx *dev)
20720c0d06caSMauro Carvalho Chehab {
2073b45e34f2SMauro Carvalho Chehab 	struct em28xx_dvb *dvb;
2074b45e34f2SMauro Carvalho Chehab 	struct i2c_client *client;
2075b45e34f2SMauro Carvalho Chehab 
2076822b8deaSMauro Carvalho Chehab 	if (dev->is_audio_only) {
2077822b8deaSMauro Carvalho Chehab 		/* Shouldn't initialize IR for this interface */
2078822b8deaSMauro Carvalho Chehab 		return 0;
2079822b8deaSMauro Carvalho Chehab 	}
2080822b8deaSMauro Carvalho Chehab 
20810c0d06caSMauro Carvalho Chehab 	if (!dev->board.has_dvb) {
20820c0d06caSMauro Carvalho Chehab 		/* This device does not support the extension */
20830c0d06caSMauro Carvalho Chehab 		return 0;
20840c0d06caSMauro Carvalho Chehab 	}
20850c0d06caSMauro Carvalho Chehab 
2086b45e34f2SMauro Carvalho Chehab 	if (!dev->dvb)
2087b45e34f2SMauro Carvalho Chehab 		return 0;
2088b45e34f2SMauro Carvalho Chehab 
208929b05e22SMauro Carvalho Chehab 	dev_info(&dev->intf->dev, "Closing DVB extension\n");
2090aa929ad7SMauro Carvalho Chehab 
2091b45e34f2SMauro Carvalho Chehab 	dvb = dev->dvb;
20920c0d06caSMauro Carvalho Chehab 
209327ba0dacSFrank Schaefer 	em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
209427ba0dacSFrank Schaefer 
20952665c299SFrank Schaefer 	if (dev->disconnected) {
20960c0d06caSMauro Carvalho Chehab 		/* We cannot tell the device to sleep
20970c0d06caSMauro Carvalho Chehab 		 * once it has been unplugged. */
2098f68e35afSShuah Khan 		if (dvb->fe[0]) {
20990c0d06caSMauro Carvalho Chehab 			prevent_sleep(&dvb->fe[0]->ops);
2100f68e35afSShuah Khan 			dvb->fe[0]->exit = DVB_FE_DEVICE_REMOVED;
2101f68e35afSShuah Khan 		}
2102f68e35afSShuah Khan 		if (dvb->fe[1]) {
21030c0d06caSMauro Carvalho Chehab 			prevent_sleep(&dvb->fe[1]->ops);
2104f68e35afSShuah Khan 			dvb->fe[1]->exit = DVB_FE_DEVICE_REMOVED;
2105f68e35afSShuah Khan 		}
21060c0d06caSMauro Carvalho Chehab 	}
21070c0d06caSMauro Carvalho Chehab 
2108*910b0797SMatthias Schwarzott 	em28xx_unregister_dvb(dvb);
2109*910b0797SMatthias Schwarzott 
21107098f582SAntti Palosaari 	/* remove I2C SEC */
21117098f582SAntti Palosaari 	client = dvb->i2c_client_sec;
21127098f582SAntti Palosaari 	if (client) {
21137098f582SAntti Palosaari 		module_put(client->dev.driver->owner);
21147098f582SAntti Palosaari 		i2c_unregister_device(client);
21157098f582SAntti Palosaari 	}
21167098f582SAntti Palosaari 
2117425f53aaSAntti Palosaari 	/* remove I2C tuner */
21187098f582SAntti Palosaari 	client = dvb->i2c_client_tuner;
2119425f53aaSAntti Palosaari 	if (client) {
2120425f53aaSAntti Palosaari 		module_put(client->dev.driver->owner);
2121425f53aaSAntti Palosaari 		i2c_unregister_device(client);
2122425f53aaSAntti Palosaari 	}
2123425f53aaSAntti Palosaari 
212419229240SAntti Palosaari 	/* remove I2C demod */
212519229240SAntti Palosaari 	client = dvb->i2c_client_demod;
212619229240SAntti Palosaari 	if (client) {
212719229240SAntti Palosaari 		module_put(client->dev.driver->owner);
212819229240SAntti Palosaari 		i2c_unregister_device(client);
212919229240SAntti Palosaari 	}
213019229240SAntti Palosaari 
21310c0d06caSMauro Carvalho Chehab 	kfree(dvb);
21320c0d06caSMauro Carvalho Chehab 	dev->dvb = NULL;
213347677e51SMauro Carvalho Chehab 	kref_put(&dev->ref, em28xx_free_device);
21340c0d06caSMauro Carvalho Chehab 
21350c0d06caSMauro Carvalho Chehab 	return 0;
21360c0d06caSMauro Carvalho Chehab }
21370c0d06caSMauro Carvalho Chehab 
2138ca2b46daSShuah Khan static int em28xx_dvb_suspend(struct em28xx *dev)
2139ca2b46daSShuah Khan {
2140ca2b46daSShuah Khan 	int ret = 0;
2141ca2b46daSShuah Khan 
2142ca2b46daSShuah Khan 	if (dev->is_audio_only)
2143ca2b46daSShuah Khan 		return 0;
2144ca2b46daSShuah Khan 
2145ca2b46daSShuah Khan 	if (!dev->board.has_dvb)
2146ca2b46daSShuah Khan 		return 0;
2147ca2b46daSShuah Khan 
214829b05e22SMauro Carvalho Chehab 	dev_info(&dev->intf->dev, "Suspending DVB extension\n");
2149ca2b46daSShuah Khan 	if (dev->dvb) {
2150ca2b46daSShuah Khan 		struct em28xx_dvb *dvb = dev->dvb;
2151ca2b46daSShuah Khan 
2152ca2b46daSShuah Khan 		if (dvb->fe[0]) {
2153ca2b46daSShuah Khan 			ret = dvb_frontend_suspend(dvb->fe[0]);
215429b05e22SMauro Carvalho Chehab 			dev_info(&dev->intf->dev, "fe0 suspend %d\n", ret);
2155ca2b46daSShuah Khan 		}
2156ca2b46daSShuah Khan 		if (dvb->fe[1]) {
2157ca2b46daSShuah Khan 			dvb_frontend_suspend(dvb->fe[1]);
215829b05e22SMauro Carvalho Chehab 			dev_info(&dev->intf->dev, "fe1 suspend %d\n", ret);
2159ca2b46daSShuah Khan 		}
2160ca2b46daSShuah Khan 	}
2161ca2b46daSShuah Khan 
2162ca2b46daSShuah Khan 	return 0;
2163ca2b46daSShuah Khan }
2164ca2b46daSShuah Khan 
2165ca2b46daSShuah Khan static int em28xx_dvb_resume(struct em28xx *dev)
2166ca2b46daSShuah Khan {
2167ca2b46daSShuah Khan 	int ret = 0;
2168ca2b46daSShuah Khan 
2169ca2b46daSShuah Khan 	if (dev->is_audio_only)
2170ca2b46daSShuah Khan 		return 0;
2171ca2b46daSShuah Khan 
2172ca2b46daSShuah Khan 	if (!dev->board.has_dvb)
2173ca2b46daSShuah Khan 		return 0;
2174ca2b46daSShuah Khan 
217529b05e22SMauro Carvalho Chehab 	dev_info(&dev->intf->dev, "Resuming DVB extension\n");
2176ca2b46daSShuah Khan 	if (dev->dvb) {
2177ca2b46daSShuah Khan 		struct em28xx_dvb *dvb = dev->dvb;
2178ca2b46daSShuah Khan 
2179ca2b46daSShuah Khan 		if (dvb->fe[0]) {
2180ca2b46daSShuah Khan 			ret = dvb_frontend_resume(dvb->fe[0]);
218129b05e22SMauro Carvalho Chehab 			dev_info(&dev->intf->dev, "fe0 resume %d\n", ret);
2182ca2b46daSShuah Khan 		}
2183ca2b46daSShuah Khan 
2184ca2b46daSShuah Khan 		if (dvb->fe[1]) {
2185ca2b46daSShuah Khan 			ret = dvb_frontend_resume(dvb->fe[1]);
218629b05e22SMauro Carvalho Chehab 			dev_info(&dev->intf->dev, "fe1 resume %d\n", ret);
2187ca2b46daSShuah Khan 		}
2188ca2b46daSShuah Khan 	}
2189ca2b46daSShuah Khan 
2190ca2b46daSShuah Khan 	return 0;
2191ca2b46daSShuah Khan }
2192ca2b46daSShuah Khan 
21930c0d06caSMauro Carvalho Chehab static struct em28xx_ops dvb_ops = {
21940c0d06caSMauro Carvalho Chehab 	.id   = EM28XX_DVB,
21950c0d06caSMauro Carvalho Chehab 	.name = "Em28xx dvb Extension",
21960c0d06caSMauro Carvalho Chehab 	.init = em28xx_dvb_init,
21970c0d06caSMauro Carvalho Chehab 	.fini = em28xx_dvb_fini,
2198ca2b46daSShuah Khan 	.suspend = em28xx_dvb_suspend,
2199ca2b46daSShuah Khan 	.resume = em28xx_dvb_resume,
22000c0d06caSMauro Carvalho Chehab };
22010c0d06caSMauro Carvalho Chehab 
22020c0d06caSMauro Carvalho Chehab static int __init em28xx_dvb_register(void)
22030c0d06caSMauro Carvalho Chehab {
22040c0d06caSMauro Carvalho Chehab 	return em28xx_register_extension(&dvb_ops);
22050c0d06caSMauro Carvalho Chehab }
22060c0d06caSMauro Carvalho Chehab 
22070c0d06caSMauro Carvalho Chehab static void __exit em28xx_dvb_unregister(void)
22080c0d06caSMauro Carvalho Chehab {
22090c0d06caSMauro Carvalho Chehab 	em28xx_unregister_extension(&dvb_ops);
22100c0d06caSMauro Carvalho Chehab }
22110c0d06caSMauro Carvalho Chehab 
22120c0d06caSMauro Carvalho Chehab module_init(em28xx_dvb_register);
22130c0d06caSMauro Carvalho Chehab module_exit(em28xx_dvb_unregister);
2214