xref: /openbmc/linux/drivers/media/usb/em28xx/em28xx-dvb.c (revision 8c47311d34eccedb06bc60fc9435a53bd4aff392)
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 
240c0d06caSMauro Carvalho Chehab #include <linux/kernel.h>
250c0d06caSMauro Carvalho Chehab #include <linux/slab.h>
260c0d06caSMauro Carvalho Chehab #include <linux/usb.h>
270c0d06caSMauro Carvalho Chehab 
280c0d06caSMauro Carvalho Chehab #include "em28xx.h"
290c0d06caSMauro Carvalho Chehab #include <media/v4l2-common.h>
30d3829fadSDevin Heitmueller #include <dvb_demux.h>
31d3829fadSDevin Heitmueller #include <dvb_net.h>
32d3829fadSDevin Heitmueller #include <dmxdev.h>
330c0d06caSMauro Carvalho Chehab #include <media/tuner.h>
340c0d06caSMauro Carvalho Chehab #include "tuner-simple.h"
351e8f31f3SAntti Palosaari #include <linux/gpio.h>
360c0d06caSMauro Carvalho Chehab 
370c0d06caSMauro Carvalho Chehab #include "lgdt330x.h"
380c0d06caSMauro Carvalho Chehab #include "lgdt3305.h"
390c0d06caSMauro Carvalho Chehab #include "zl10353.h"
400c0d06caSMauro Carvalho Chehab #include "s5h1409.h"
41*8c47311dSAlberto Mardegan #include "mt2060.h"
420c0d06caSMauro Carvalho Chehab #include "mt352.h"
430c0d06caSMauro Carvalho Chehab #include "mt352_priv.h" /* FIXME */
440c0d06caSMauro Carvalho Chehab #include "tda1002x.h"
4538b2df95SDevin Heitmueller #include "drx39xyj/drx39xxj.h"
460c0d06caSMauro Carvalho Chehab #include "tda18271.h"
470c0d06caSMauro Carvalho Chehab #include "s921.h"
480c0d06caSMauro Carvalho Chehab #include "drxd.h"
490c0d06caSMauro Carvalho Chehab #include "cxd2820r.h"
500c0d06caSMauro Carvalho Chehab #include "tda18271c2dd.h"
510c0d06caSMauro Carvalho Chehab #include "drxk.h"
520c0d06caSMauro Carvalho Chehab #include "tda10071.h"
5302bc1f55SMauro Carvalho Chehab #include "tda18212.h"
540c0d06caSMauro Carvalho Chehab #include "a8293.h"
550c0d06caSMauro Carvalho Chehab #include "qt1010.h"
564159d01bSMauro Carvalho Chehab #include "mb86a20s.h"
57ec573362SAntti Palosaari #include "m88ds3103.h"
5883c1b6ceSAntti Palosaari #include "ts2020.h"
5919229240SAntti Palosaari #include "si2168.h"
6019229240SAntti Palosaari #include "si2157.h"
610c0d06caSMauro Carvalho Chehab 
620c0d06caSMauro Carvalho Chehab MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
630c0d06caSMauro Carvalho Chehab MODULE_LICENSE("GPL");
64d8992b09SMauro Carvalho Chehab MODULE_DESCRIPTION(DRIVER_DESC " - digital TV interface");
65d8992b09SMauro Carvalho Chehab MODULE_VERSION(EM28XX_VERSION);
66d8992b09SMauro Carvalho Chehab 
670c0d06caSMauro Carvalho Chehab static unsigned int debug;
680c0d06caSMauro Carvalho Chehab module_param(debug, int, 0644);
690c0d06caSMauro Carvalho Chehab MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
700c0d06caSMauro Carvalho Chehab 
710c0d06caSMauro Carvalho Chehab DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
720c0d06caSMauro Carvalho Chehab 
730c0d06caSMauro Carvalho Chehab #define dprintk(level, fmt, arg...) do {			\
740c0d06caSMauro Carvalho Chehab if (debug >= level)						\
750c0d06caSMauro Carvalho Chehab 	printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg);	\
760c0d06caSMauro Carvalho Chehab } while (0)
770c0d06caSMauro Carvalho Chehab 
780c0d06caSMauro Carvalho Chehab struct em28xx_dvb {
790c0d06caSMauro Carvalho Chehab 	struct dvb_frontend        *fe[2];
800c0d06caSMauro Carvalho Chehab 
810c0d06caSMauro Carvalho Chehab 	/* feed count management */
820c0d06caSMauro Carvalho Chehab 	struct mutex               lock;
830c0d06caSMauro Carvalho Chehab 	int                        nfeeds;
840c0d06caSMauro Carvalho Chehab 
850c0d06caSMauro Carvalho Chehab 	/* general boilerplate stuff */
860c0d06caSMauro Carvalho Chehab 	struct dvb_adapter         adapter;
870c0d06caSMauro Carvalho Chehab 	struct dvb_demux           demux;
880c0d06caSMauro Carvalho Chehab 	struct dmxdev              dmxdev;
890c0d06caSMauro Carvalho Chehab 	struct dmx_frontend        fe_hw;
900c0d06caSMauro Carvalho Chehab 	struct dmx_frontend        fe_mem;
910c0d06caSMauro Carvalho Chehab 	struct dvb_net             net;
920c0d06caSMauro Carvalho Chehab 
930c0d06caSMauro Carvalho Chehab 	/* Due to DRX-K - probably need changes */
940c0d06caSMauro Carvalho Chehab 	int (*gate_ctrl)(struct dvb_frontend *, int);
950c0d06caSMauro Carvalho Chehab 	struct semaphore      pll_mutex;
960c0d06caSMauro Carvalho Chehab 	bool			dont_attach_fe1;
9713a5336eSAntti Palosaari 	int			lna_gpio;
9819229240SAntti Palosaari 	struct i2c_client	*i2c_client_demod;
99eafa2ad6SAntti Palosaari 	struct i2c_client	*i2c_client_tuner;
1007098f582SAntti Palosaari 	struct i2c_client	*i2c_client_sec;
1010c0d06caSMauro Carvalho Chehab };
1020c0d06caSMauro Carvalho Chehab 
1030c0d06caSMauro Carvalho Chehab static inline void print_err_status(struct em28xx *dev,
1040c0d06caSMauro Carvalho Chehab 				    int packet, int status)
1050c0d06caSMauro Carvalho Chehab {
1060c0d06caSMauro Carvalho Chehab 	char *errmsg = "Unknown";
1070c0d06caSMauro Carvalho Chehab 
1080c0d06caSMauro Carvalho Chehab 	switch (status) {
1090c0d06caSMauro Carvalho Chehab 	case -ENOENT:
1100c0d06caSMauro Carvalho Chehab 		errmsg = "unlinked synchronuously";
1110c0d06caSMauro Carvalho Chehab 		break;
1120c0d06caSMauro Carvalho Chehab 	case -ECONNRESET:
1130c0d06caSMauro Carvalho Chehab 		errmsg = "unlinked asynchronuously";
1140c0d06caSMauro Carvalho Chehab 		break;
1150c0d06caSMauro Carvalho Chehab 	case -ENOSR:
1160c0d06caSMauro Carvalho Chehab 		errmsg = "Buffer error (overrun)";
1170c0d06caSMauro Carvalho Chehab 		break;
1180c0d06caSMauro Carvalho Chehab 	case -EPIPE:
1190c0d06caSMauro Carvalho Chehab 		errmsg = "Stalled (device not responding)";
1200c0d06caSMauro Carvalho Chehab 		break;
1210c0d06caSMauro Carvalho Chehab 	case -EOVERFLOW:
1220c0d06caSMauro Carvalho Chehab 		errmsg = "Babble (bad cable?)";
1230c0d06caSMauro Carvalho Chehab 		break;
1240c0d06caSMauro Carvalho Chehab 	case -EPROTO:
1250c0d06caSMauro Carvalho Chehab 		errmsg = "Bit-stuff error (bad cable?)";
1260c0d06caSMauro Carvalho Chehab 		break;
1270c0d06caSMauro Carvalho Chehab 	case -EILSEQ:
1280c0d06caSMauro Carvalho Chehab 		errmsg = "CRC/Timeout (could be anything)";
1290c0d06caSMauro Carvalho Chehab 		break;
1300c0d06caSMauro Carvalho Chehab 	case -ETIME:
1310c0d06caSMauro Carvalho Chehab 		errmsg = "Device does not respond";
1320c0d06caSMauro Carvalho Chehab 		break;
1330c0d06caSMauro Carvalho Chehab 	}
1340c0d06caSMauro Carvalho Chehab 	if (packet < 0) {
1350c0d06caSMauro Carvalho Chehab 		dprintk(1, "URB status %d [%s].\n", status, errmsg);
1360c0d06caSMauro Carvalho Chehab 	} else {
1370c0d06caSMauro Carvalho Chehab 		dprintk(1, "URB packet %d, status %d [%s].\n",
1380c0d06caSMauro Carvalho Chehab 			packet, status, errmsg);
1390c0d06caSMauro Carvalho Chehab 	}
1400c0d06caSMauro Carvalho Chehab }
1410c0d06caSMauro Carvalho Chehab 
142a950e4a7SFrank Schaefer static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
1430c0d06caSMauro Carvalho Chehab {
144a950e4a7SFrank Schaefer 	int xfer_bulk, num_packets, i;
1450c0d06caSMauro Carvalho Chehab 
1460c0d06caSMauro Carvalho Chehab 	if (!dev)
1470c0d06caSMauro Carvalho Chehab 		return 0;
1480c0d06caSMauro Carvalho Chehab 
1492665c299SFrank Schaefer 	if (dev->disconnected)
1500c0d06caSMauro Carvalho Chehab 		return 0;
1510c0d06caSMauro Carvalho Chehab 
1521653cb0cSFrank Schaefer 	if (urb->status < 0)
1530c0d06caSMauro Carvalho Chehab 		print_err_status(dev, -1, urb->status);
1540c0d06caSMauro Carvalho Chehab 
155a950e4a7SFrank Schaefer 	xfer_bulk = usb_pipebulk(urb->pipe);
1560c0d06caSMauro Carvalho Chehab 
157a950e4a7SFrank Schaefer 	if (xfer_bulk) /* bulk */
158a950e4a7SFrank Schaefer 		num_packets = 1;
159a950e4a7SFrank Schaefer 	else /* isoc */
160a950e4a7SFrank Schaefer 		num_packets = urb->number_of_packets;
161a950e4a7SFrank Schaefer 
162a950e4a7SFrank Schaefer 	for (i = 0; i < num_packets; i++) {
163a950e4a7SFrank Schaefer 		if (xfer_bulk) {
164a950e4a7SFrank Schaefer 			if (urb->status < 0) {
165a950e4a7SFrank Schaefer 				print_err_status(dev, i, urb->status);
166a950e4a7SFrank Schaefer 				if (urb->status != -EPROTO)
167a950e4a7SFrank Schaefer 					continue;
168a950e4a7SFrank Schaefer 			}
169ffdeca88SMauro Carvalho Chehab 			if (!urb->actual_length)
170ffdeca88SMauro Carvalho Chehab 				continue;
171a950e4a7SFrank Schaefer 			dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
172a950e4a7SFrank Schaefer 					 urb->actual_length);
173a950e4a7SFrank Schaefer 		} else {
174a950e4a7SFrank Schaefer 			if (urb->iso_frame_desc[i].status < 0) {
175a950e4a7SFrank Schaefer 				print_err_status(dev, i,
176a950e4a7SFrank Schaefer 						 urb->iso_frame_desc[i].status);
1770c0d06caSMauro Carvalho Chehab 				if (urb->iso_frame_desc[i].status != -EPROTO)
1780c0d06caSMauro Carvalho Chehab 					continue;
1790c0d06caSMauro Carvalho Chehab 			}
180ffdeca88SMauro Carvalho Chehab 			if (!urb->iso_frame_desc[i].actual_length)
181ffdeca88SMauro Carvalho Chehab 				continue;
182a950e4a7SFrank Schaefer 			dvb_dmx_swfilter(&dev->dvb->demux,
183a950e4a7SFrank Schaefer 					 urb->transfer_buffer +
1840c0d06caSMauro Carvalho Chehab 					 urb->iso_frame_desc[i].offset,
1850c0d06caSMauro Carvalho Chehab 					 urb->iso_frame_desc[i].actual_length);
1860c0d06caSMauro Carvalho Chehab 		}
187a950e4a7SFrank Schaefer 	}
1880c0d06caSMauro Carvalho Chehab 
1890c0d06caSMauro Carvalho Chehab 	return 0;
1900c0d06caSMauro Carvalho Chehab }
1910c0d06caSMauro Carvalho Chehab 
1920c0d06caSMauro Carvalho Chehab static int em28xx_start_streaming(struct em28xx_dvb *dvb)
1930c0d06caSMauro Carvalho Chehab {
1940c0d06caSMauro Carvalho Chehab 	int rc;
1953de09fbbSHans Verkuil 	struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
1963de09fbbSHans Verkuil 	struct em28xx *dev = i2c_bus->dev;
197c647a91aSFrank Schaefer 	int dvb_max_packet_size, packet_multiplier, dvb_alt;
1980c0d06caSMauro Carvalho Chehab 
199c647a91aSFrank Schaefer 	if (dev->dvb_xfer_bulk) {
200c647a91aSFrank Schaefer 		if (!dev->dvb_ep_bulk)
201c647a91aSFrank Schaefer 			return -ENODEV;
202c647a91aSFrank Schaefer 		dvb_max_packet_size = 512; /* USB 2.0 spec */
203c647a91aSFrank Schaefer 		packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
204c647a91aSFrank Schaefer 		dvb_alt = 0;
205c647a91aSFrank Schaefer 	} else { /* isoc */
206c647a91aSFrank Schaefer 		if (!dev->dvb_ep_isoc)
207c647a91aSFrank Schaefer 			return -ENODEV;
208c647a91aSFrank Schaefer 		dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
209c647a91aSFrank Schaefer 		if (dvb_max_packet_size < 0)
210c647a91aSFrank Schaefer 			return dvb_max_packet_size;
211c647a91aSFrank Schaefer 		packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
212c647a91aSFrank Schaefer 		dvb_alt = dev->dvb_alt_isoc;
213c647a91aSFrank Schaefer 	}
214c647a91aSFrank Schaefer 
215961717b4SFrank Schaefer 	usb_set_interface(dev->udev, dev->ifnum, dvb_alt);
2160c0d06caSMauro Carvalho Chehab 	rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
2170c0d06caSMauro Carvalho Chehab 	if (rc < 0)
2180c0d06caSMauro Carvalho Chehab 		return rc;
2190c0d06caSMauro Carvalho Chehab 
22052f7b00eSMauro Carvalho Chehab 	dprintk(1, "Using %d buffers each with %d x %d bytes, alternate %d\n",
2210c0d06caSMauro Carvalho Chehab 		EM28XX_DVB_NUM_BUFS,
222c647a91aSFrank Schaefer 		packet_multiplier,
22352f7b00eSMauro Carvalho Chehab 		dvb_max_packet_size, dvb_alt);
2240c0d06caSMauro Carvalho Chehab 
225c647a91aSFrank Schaefer 	return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
226c647a91aSFrank Schaefer 				    dev->dvb_xfer_bulk,
227515688a8SFrank Schaefer 				    EM28XX_DVB_NUM_BUFS,
228c647a91aSFrank Schaefer 				    dvb_max_packet_size,
229c647a91aSFrank Schaefer 				    packet_multiplier,
230a950e4a7SFrank Schaefer 				    em28xx_dvb_urb_data_copy);
2310c0d06caSMauro Carvalho Chehab }
2320c0d06caSMauro Carvalho Chehab 
2330c0d06caSMauro Carvalho Chehab static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
2340c0d06caSMauro Carvalho Chehab {
2353de09fbbSHans Verkuil 	struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
2363de09fbbSHans Verkuil 	struct em28xx *dev = i2c_bus->dev;
2370c0d06caSMauro Carvalho Chehab 
2380c0d06caSMauro Carvalho Chehab 	em28xx_stop_urbs(dev);
2390c0d06caSMauro Carvalho Chehab 
2400c0d06caSMauro Carvalho Chehab 	return 0;
2410c0d06caSMauro Carvalho Chehab }
2420c0d06caSMauro Carvalho Chehab 
2430c0d06caSMauro Carvalho Chehab static int em28xx_start_feed(struct dvb_demux_feed *feed)
2440c0d06caSMauro Carvalho Chehab {
2450c0d06caSMauro Carvalho Chehab 	struct dvb_demux *demux  = feed->demux;
2460c0d06caSMauro Carvalho Chehab 	struct em28xx_dvb *dvb = demux->priv;
2470c0d06caSMauro Carvalho Chehab 	int rc, ret;
2480c0d06caSMauro Carvalho Chehab 
2490c0d06caSMauro Carvalho Chehab 	if (!demux->dmx.frontend)
2500c0d06caSMauro Carvalho Chehab 		return -EINVAL;
2510c0d06caSMauro Carvalho Chehab 
2520c0d06caSMauro Carvalho Chehab 	mutex_lock(&dvb->lock);
2530c0d06caSMauro Carvalho Chehab 	dvb->nfeeds++;
2540c0d06caSMauro Carvalho Chehab 	rc = dvb->nfeeds;
2550c0d06caSMauro Carvalho Chehab 
2560c0d06caSMauro Carvalho Chehab 	if (dvb->nfeeds == 1) {
2570c0d06caSMauro Carvalho Chehab 		ret = em28xx_start_streaming(dvb);
2580c0d06caSMauro Carvalho Chehab 		if (ret < 0)
2590c0d06caSMauro Carvalho Chehab 			rc = ret;
2600c0d06caSMauro Carvalho Chehab 	}
2610c0d06caSMauro Carvalho Chehab 
2620c0d06caSMauro Carvalho Chehab 	mutex_unlock(&dvb->lock);
2630c0d06caSMauro Carvalho Chehab 	return rc;
2640c0d06caSMauro Carvalho Chehab }
2650c0d06caSMauro Carvalho Chehab 
2660c0d06caSMauro Carvalho Chehab static int em28xx_stop_feed(struct dvb_demux_feed *feed)
2670c0d06caSMauro Carvalho Chehab {
2680c0d06caSMauro Carvalho Chehab 	struct dvb_demux *demux  = feed->demux;
2690c0d06caSMauro Carvalho Chehab 	struct em28xx_dvb *dvb = demux->priv;
2700c0d06caSMauro Carvalho Chehab 	int err = 0;
2710c0d06caSMauro Carvalho Chehab 
2720c0d06caSMauro Carvalho Chehab 	mutex_lock(&dvb->lock);
2730c0d06caSMauro Carvalho Chehab 	dvb->nfeeds--;
2740c0d06caSMauro Carvalho Chehab 
2750c0d06caSMauro Carvalho Chehab 	if (0 == dvb->nfeeds)
2760c0d06caSMauro Carvalho Chehab 		err = em28xx_stop_streaming(dvb);
2770c0d06caSMauro Carvalho Chehab 
2780c0d06caSMauro Carvalho Chehab 	mutex_unlock(&dvb->lock);
2790c0d06caSMauro Carvalho Chehab 	return err;
2800c0d06caSMauro Carvalho Chehab }
2810c0d06caSMauro Carvalho Chehab 
2820c0d06caSMauro Carvalho Chehab 
2830c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */
2840c0d06caSMauro Carvalho Chehab static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
2850c0d06caSMauro Carvalho Chehab {
286a3b60209SMauro Carvalho Chehab 	struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
287a3b60209SMauro Carvalho Chehab 	struct em28xx *dev = i2c_bus->dev;
2880c0d06caSMauro Carvalho Chehab 
2890c0d06caSMauro Carvalho Chehab 	if (acquire)
2900c0d06caSMauro Carvalho Chehab 		return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
2910c0d06caSMauro Carvalho Chehab 	else
2920c0d06caSMauro Carvalho Chehab 		return em28xx_set_mode(dev, EM28XX_SUSPEND);
2930c0d06caSMauro Carvalho Chehab }
2940c0d06caSMauro Carvalho Chehab 
2950c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */
2960c0d06caSMauro Carvalho Chehab 
2970c0d06caSMauro Carvalho Chehab static struct lgdt330x_config em2880_lgdt3303_dev = {
2980c0d06caSMauro Carvalho Chehab 	.demod_address = 0x0e,
2990c0d06caSMauro Carvalho Chehab 	.demod_chip = LGDT3303,
3000c0d06caSMauro Carvalho Chehab };
3010c0d06caSMauro Carvalho Chehab 
3020c0d06caSMauro Carvalho Chehab static struct lgdt3305_config em2870_lgdt3304_dev = {
3030c0d06caSMauro Carvalho Chehab 	.i2c_addr           = 0x0e,
3040c0d06caSMauro Carvalho Chehab 	.demod_chip         = LGDT3304,
3050c0d06caSMauro Carvalho Chehab 	.spectral_inversion = 1,
3060c0d06caSMauro Carvalho Chehab 	.deny_i2c_rptr      = 1,
3070c0d06caSMauro Carvalho Chehab 	.mpeg_mode          = LGDT3305_MPEG_PARALLEL,
3080c0d06caSMauro Carvalho Chehab 	.tpclk_edge         = LGDT3305_TPCLK_FALLING_EDGE,
3090c0d06caSMauro Carvalho Chehab 	.tpvalid_polarity   = LGDT3305_TP_VALID_HIGH,
3100c0d06caSMauro Carvalho Chehab 	.vsb_if_khz         = 3250,
3110c0d06caSMauro Carvalho Chehab 	.qam_if_khz         = 4000,
3120c0d06caSMauro Carvalho Chehab };
3130c0d06caSMauro Carvalho Chehab 
3146dbea9f0SJean-Francois Thibert static struct lgdt3305_config em2874_lgdt3305_dev = {
3156dbea9f0SJean-Francois Thibert 	.i2c_addr           = 0x0e,
3166dbea9f0SJean-Francois Thibert 	.demod_chip         = LGDT3305,
3176dbea9f0SJean-Francois Thibert 	.spectral_inversion = 1,
3186dbea9f0SJean-Francois Thibert 	.deny_i2c_rptr      = 0,
3196dbea9f0SJean-Francois Thibert 	.mpeg_mode          = LGDT3305_MPEG_SERIAL,
3206dbea9f0SJean-Francois Thibert 	.tpclk_edge         = LGDT3305_TPCLK_FALLING_EDGE,
3216dbea9f0SJean-Francois Thibert 	.tpvalid_polarity   = LGDT3305_TP_VALID_HIGH,
3226dbea9f0SJean-Francois Thibert 	.vsb_if_khz         = 3250,
3236dbea9f0SJean-Francois Thibert 	.qam_if_khz         = 4000,
3246dbea9f0SJean-Francois Thibert };
3256dbea9f0SJean-Francois Thibert 
32602bc1f55SMauro Carvalho Chehab static struct lgdt3305_config em2874_lgdt3305_nogate_dev = {
32702bc1f55SMauro Carvalho Chehab 	.i2c_addr           = 0x0e,
32802bc1f55SMauro Carvalho Chehab 	.demod_chip         = LGDT3305,
32902bc1f55SMauro Carvalho Chehab 	.spectral_inversion = 1,
33002bc1f55SMauro Carvalho Chehab 	.deny_i2c_rptr      = 1,
33102bc1f55SMauro Carvalho Chehab 	.mpeg_mode          = LGDT3305_MPEG_SERIAL,
33202bc1f55SMauro Carvalho Chehab 	.tpclk_edge         = LGDT3305_TPCLK_FALLING_EDGE,
33302bc1f55SMauro Carvalho Chehab 	.tpvalid_polarity   = LGDT3305_TP_VALID_HIGH,
33402bc1f55SMauro Carvalho Chehab 	.vsb_if_khz         = 3600,
33502bc1f55SMauro Carvalho Chehab 	.qam_if_khz         = 3600,
33602bc1f55SMauro Carvalho Chehab };
33702bc1f55SMauro Carvalho Chehab 
3380c0d06caSMauro Carvalho Chehab static struct s921_config sharp_isdbt = {
3390c0d06caSMauro Carvalho Chehab 	.demod_address = 0x30 >> 1
3400c0d06caSMauro Carvalho Chehab };
3410c0d06caSMauro Carvalho Chehab 
3420c0d06caSMauro Carvalho Chehab static struct zl10353_config em28xx_zl10353_with_xc3028 = {
3430c0d06caSMauro Carvalho Chehab 	.demod_address = (0x1e >> 1),
3440c0d06caSMauro Carvalho Chehab 	.no_tuner = 1,
3450c0d06caSMauro Carvalho Chehab 	.parallel_ts = 1,
3460c0d06caSMauro Carvalho Chehab 	.if2 = 45600,
3470c0d06caSMauro Carvalho Chehab };
3480c0d06caSMauro Carvalho Chehab 
3490c0d06caSMauro Carvalho Chehab static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
3500c0d06caSMauro Carvalho Chehab 	.demod_address = 0x32 >> 1,
3510c0d06caSMauro Carvalho Chehab 	.output_mode   = S5H1409_PARALLEL_OUTPUT,
3520c0d06caSMauro Carvalho Chehab 	.gpio          = S5H1409_GPIO_OFF,
3530c0d06caSMauro Carvalho Chehab 	.inversion     = S5H1409_INVERSION_OFF,
3540c0d06caSMauro Carvalho Chehab 	.status_mode   = S5H1409_DEMODLOCKING,
3550c0d06caSMauro Carvalho Chehab 	.mpeg_timing   = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
3560c0d06caSMauro Carvalho Chehab };
3570c0d06caSMauro Carvalho Chehab 
3580c0d06caSMauro Carvalho Chehab static struct tda18271_std_map kworld_a340_std_map = {
3590c0d06caSMauro Carvalho Chehab 	.atsc_6   = { .if_freq = 3250, .agc_mode = 3, .std = 0,
3600c0d06caSMauro Carvalho Chehab 		      .if_lvl = 1, .rfagc_top = 0x37, },
3610c0d06caSMauro Carvalho Chehab 	.qam_6    = { .if_freq = 4000, .agc_mode = 3, .std = 1,
3620c0d06caSMauro Carvalho Chehab 		      .if_lvl = 1, .rfagc_top = 0x37, },
3630c0d06caSMauro Carvalho Chehab };
3640c0d06caSMauro Carvalho Chehab 
3650c0d06caSMauro Carvalho Chehab static struct tda18271_config kworld_a340_config = {
3660c0d06caSMauro Carvalho Chehab 	.std_map           = &kworld_a340_std_map,
3670c0d06caSMauro Carvalho Chehab };
3680c0d06caSMauro Carvalho Chehab 
3696dbea9f0SJean-Francois Thibert static struct tda18271_config kworld_ub435q_v2_config = {
3706dbea9f0SJean-Francois Thibert 	.std_map	= &kworld_a340_std_map,
3716dbea9f0SJean-Francois Thibert 	.gate		= TDA18271_GATE_DIGITAL,
3726dbea9f0SJean-Francois Thibert };
3736dbea9f0SJean-Francois Thibert 
37402bc1f55SMauro Carvalho Chehab static struct tda18212_config kworld_ub435q_v3_config = {
37502bc1f55SMauro Carvalho Chehab 	.if_atsc_vsb	= 3600,
37602bc1f55SMauro Carvalho Chehab 	.if_atsc_qam	= 3600,
37702bc1f55SMauro Carvalho Chehab };
37802bc1f55SMauro Carvalho Chehab 
3790c0d06caSMauro Carvalho Chehab static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
3800c0d06caSMauro Carvalho Chehab 	.demod_address = (0x1e >> 1),
3810c0d06caSMauro Carvalho Chehab 	.no_tuner = 1,
3820c0d06caSMauro Carvalho Chehab 	.disable_i2c_gate_ctrl = 1,
3830c0d06caSMauro Carvalho Chehab 	.parallel_ts = 1,
3840c0d06caSMauro Carvalho Chehab 	.if2 = 45600,
3850c0d06caSMauro Carvalho Chehab };
3860c0d06caSMauro Carvalho Chehab 
3870c0d06caSMauro Carvalho Chehab static struct drxd_config em28xx_drxd = {
3880c0d06caSMauro Carvalho Chehab 	.demod_address = 0x70,
3890c0d06caSMauro Carvalho Chehab 	.demod_revision = 0xa2,
3900c0d06caSMauro Carvalho Chehab 	.pll_type = DRXD_PLL_NONE,
3910c0d06caSMauro Carvalho Chehab 	.clock = 12000,
3920c0d06caSMauro Carvalho Chehab 	.insert_rs_byte = 1,
3930c0d06caSMauro Carvalho Chehab 	.IF = 42800000,
3940c0d06caSMauro Carvalho Chehab 	.disable_i2c_gate_ctrl = 1,
3950c0d06caSMauro Carvalho Chehab };
3960c0d06caSMauro Carvalho Chehab 
3970c0d06caSMauro Carvalho Chehab static struct drxk_config terratec_h5_drxk = {
3980c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
3990c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4000c0d06caSMauro Carvalho Chehab 	.no_i2c_bridge = 1,
4010c0d06caSMauro Carvalho Chehab 	.microcode_name = "dvb-usb-terratec-h5-drxk.fw",
4020c0d06caSMauro Carvalho Chehab 	.qam_demod_parameter_count = 2,
4030c0d06caSMauro Carvalho Chehab };
4040c0d06caSMauro Carvalho Chehab 
4050c0d06caSMauro Carvalho Chehab static struct drxk_config hauppauge_930c_drxk = {
4060c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4070c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4080c0d06caSMauro Carvalho Chehab 	.no_i2c_bridge = 1,
4090c0d06caSMauro Carvalho Chehab 	.microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
4100c0d06caSMauro Carvalho Chehab 	.chunk_size = 56,
4110c0d06caSMauro Carvalho Chehab 	.qam_demod_parameter_count = 2,
4120c0d06caSMauro Carvalho Chehab };
4130c0d06caSMauro Carvalho Chehab 
41489040136SMartin Blumenstingl static struct drxk_config terratec_htc_stick_drxk = {
4150c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4160c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4170c0d06caSMauro Carvalho Chehab 	.no_i2c_bridge = 1,
4180c0d06caSMauro Carvalho Chehab 	.microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
4190c0d06caSMauro Carvalho Chehab 	.chunk_size = 54,
4200c0d06caSMauro Carvalho Chehab 	.qam_demod_parameter_count = 2,
4210c0d06caSMauro Carvalho Chehab 	/* Required for the antenna_gpio to disable LNA. */
4220c0d06caSMauro Carvalho Chehab 	.antenna_dvbt = true,
4230c0d06caSMauro Carvalho Chehab 	/* The windows driver uses the same. This will disable LNA. */
4240c0d06caSMauro Carvalho Chehab 	.antenna_gpio = 0x6,
4250c0d06caSMauro Carvalho Chehab };
4260c0d06caSMauro Carvalho Chehab 
4270c0d06caSMauro Carvalho Chehab static struct drxk_config maxmedia_ub425_tc_drxk = {
4280c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4290c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4300c0d06caSMauro Carvalho Chehab 	.no_i2c_bridge = 1,
4318d100b27SAntti Palosaari 	.microcode_name = "dvb-demod-drxk-01.fw",
4328d100b27SAntti Palosaari 	.chunk_size = 62,
433de0fc463SAntti Palosaari 	.qam_demod_parameter_count = 2,
4340c0d06caSMauro Carvalho Chehab };
4350c0d06caSMauro Carvalho Chehab 
4360c0d06caSMauro Carvalho Chehab static struct drxk_config pctv_520e_drxk = {
4370c0d06caSMauro Carvalho Chehab 	.adr = 0x29,
4380c0d06caSMauro Carvalho Chehab 	.single_master = 1,
4390c0d06caSMauro Carvalho Chehab 	.microcode_name = "dvb-demod-drxk-pctv.fw",
4400c0d06caSMauro Carvalho Chehab 	.qam_demod_parameter_count = 2,
4410c0d06caSMauro Carvalho Chehab 	.chunk_size = 58,
4420c0d06caSMauro Carvalho Chehab 	.antenna_dvbt = true, /* disable LNA */
4430c0d06caSMauro Carvalho Chehab 	.antenna_gpio = (1 << 2), /* disable LNA */
4440c0d06caSMauro Carvalho Chehab };
4450c0d06caSMauro Carvalho Chehab 
4460c0d06caSMauro Carvalho Chehab static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
4470c0d06caSMauro Carvalho Chehab {
4480c0d06caSMauro Carvalho Chehab 	struct em28xx_dvb *dvb = fe->sec_priv;
4490c0d06caSMauro Carvalho Chehab 	int status;
4500c0d06caSMauro Carvalho Chehab 
4510c0d06caSMauro Carvalho Chehab 	if (!dvb)
4520c0d06caSMauro Carvalho Chehab 		return -EINVAL;
4530c0d06caSMauro Carvalho Chehab 
4540c0d06caSMauro Carvalho Chehab 	if (enable) {
4550c0d06caSMauro Carvalho Chehab 		down(&dvb->pll_mutex);
4560c0d06caSMauro Carvalho Chehab 		status = dvb->gate_ctrl(fe, 1);
4570c0d06caSMauro Carvalho Chehab 	} else {
4580c0d06caSMauro Carvalho Chehab 		status = dvb->gate_ctrl(fe, 0);
4590c0d06caSMauro Carvalho Chehab 		up(&dvb->pll_mutex);
4600c0d06caSMauro Carvalho Chehab 	}
4610c0d06caSMauro Carvalho Chehab 	return status;
4620c0d06caSMauro Carvalho Chehab }
4630c0d06caSMauro Carvalho Chehab 
4640c0d06caSMauro Carvalho Chehab static void hauppauge_hvr930c_init(struct em28xx *dev)
4650c0d06caSMauro Carvalho Chehab {
4660c0d06caSMauro Carvalho Chehab 	int i;
4670c0d06caSMauro Carvalho Chehab 
4680c0d06caSMauro Carvalho Chehab 	struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
469907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xff,	0xff,	0x65},
470907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xfb,	0xff,	0x32},
471907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xff,	0xff,	0xb8},
4720c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
4730c0d06caSMauro Carvalho Chehab 	};
4740c0d06caSMauro Carvalho Chehab 	struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
475907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x01},
476907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xaf,	0xff,	0x65},
477907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x76},
478907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x01},
479907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xcf,	0xff,	0x0b},
480907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x40},
4810c0d06caSMauro Carvalho Chehab 
482907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xcf,	0xff,	0x65},
483907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x65},
484907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xcf,	0xff,	0x0b},
485907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xef,	0xff,	0x65},
4860c0d06caSMauro Carvalho Chehab 
4870c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
4880c0d06caSMauro Carvalho Chehab 	};
4890c0d06caSMauro Carvalho Chehab 
4900c0d06caSMauro Carvalho Chehab 	struct {
4910c0d06caSMauro Carvalho Chehab 		unsigned char r[4];
4920c0d06caSMauro Carvalho Chehab 		int len;
4930c0d06caSMauro Carvalho Chehab 	} regs[] = {
4940c0d06caSMauro Carvalho Chehab 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
4950c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02 }, 2},
4960c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
4970c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
4980c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
4990c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x03, 0xa0 }, 4},
5000c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
5010c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x73, 0xaf }, 4},
5020c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x00 }, 2},
5030c0d06caSMauro Carvalho Chehab 		{{ 0x00, 0x04 }, 2},
5040c0d06caSMauro Carvalho Chehab 		{{ 0x00, 0x04, 0x00, 0x0a }, 4},
5050c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x14 }, 2},
5060c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x14, 0x00, 0x00 }, 4},
5070c0d06caSMauro Carvalho Chehab 	};
5080c0d06caSMauro Carvalho Chehab 
5090c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, hauppauge_hvr930c_init);
5100c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
5110c0d06caSMauro Carvalho Chehab 	msleep(10);
5120c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
5130c0d06caSMauro Carvalho Chehab 	msleep(10);
5140c0d06caSMauro Carvalho Chehab 
515c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
5160c0d06caSMauro Carvalho Chehab 
5170c0d06caSMauro Carvalho Chehab 	for (i = 0; i < ARRAY_SIZE(regs); i++)
518c7a45e5bSMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
5190c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, hauppauge_hvr930c_end);
5200c0d06caSMauro Carvalho Chehab 
5210c0d06caSMauro Carvalho Chehab 	msleep(100);
5220c0d06caSMauro Carvalho Chehab 
5230c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
5240c0d06caSMauro Carvalho Chehab 	msleep(30);
5250c0d06caSMauro Carvalho Chehab 
5260c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
5270c0d06caSMauro Carvalho Chehab 	msleep(10);
5280c0d06caSMauro Carvalho Chehab 
5290c0d06caSMauro Carvalho Chehab }
5300c0d06caSMauro Carvalho Chehab 
5310c0d06caSMauro Carvalho Chehab static void terratec_h5_init(struct em28xx *dev)
5320c0d06caSMauro Carvalho Chehab {
5330c0d06caSMauro Carvalho Chehab 	int i;
5340c0d06caSMauro Carvalho Chehab 	struct em28xx_reg_seq terratec_h5_init[] = {
535c074fc4cSFrank Schaefer 		{EM2820_R08_GPIO_CTRL,		0xff,	0xff,	10},
536907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	100},
537907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf2,	0xff,	50},
538907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	100},
5390c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
5400c0d06caSMauro Carvalho Chehab 	};
5410c0d06caSMauro Carvalho Chehab 	struct em28xx_reg_seq terratec_h5_end[] = {
542907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xe6,	0xff,	100},
543907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xa6,	0xff,	50},
544907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xe6,	0xff,	100},
5450c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
5460c0d06caSMauro Carvalho Chehab 	};
5470c0d06caSMauro Carvalho Chehab 	struct {
5480c0d06caSMauro Carvalho Chehab 		unsigned char r[4];
5490c0d06caSMauro Carvalho Chehab 		int len;
5500c0d06caSMauro Carvalho Chehab 	} regs[] = {
5510c0d06caSMauro Carvalho Chehab 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
5520c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02 }, 2},
5530c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
5540c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
5550c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
5560c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x03, 0xa0 }, 4},
5570c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
5580c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x73, 0xaf }, 4},
5590c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x00 }, 2},
5600c0d06caSMauro Carvalho Chehab 		{{ 0x00, 0x04 }, 2},
5610c0d06caSMauro Carvalho Chehab 		{{ 0x00, 0x04, 0x00, 0x0a }, 4},
5620c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x14 }, 2},
5630c0d06caSMauro Carvalho Chehab 		{{ 0x04, 0x14, 0x00, 0x00 }, 4},
5640c0d06caSMauro Carvalho Chehab 	};
5650c0d06caSMauro Carvalho Chehab 
5660c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, terratec_h5_init);
5670c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
5680c0d06caSMauro Carvalho Chehab 	msleep(10);
5690c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
5700c0d06caSMauro Carvalho Chehab 	msleep(10);
5710c0d06caSMauro Carvalho Chehab 
572c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
5730c0d06caSMauro Carvalho Chehab 
5740c0d06caSMauro Carvalho Chehab 	for (i = 0; i < ARRAY_SIZE(regs); i++)
575c7a45e5bSMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
5760c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, terratec_h5_end);
5770c0d06caSMauro Carvalho Chehab };
5780c0d06caSMauro Carvalho Chehab 
5790c0d06caSMauro Carvalho Chehab static void terratec_htc_stick_init(struct em28xx *dev)
5800c0d06caSMauro Carvalho Chehab {
5810c0d06caSMauro Carvalho Chehab 	int i;
5820c0d06caSMauro Carvalho Chehab 
5830c0d06caSMauro Carvalho Chehab 	/*
5840c0d06caSMauro Carvalho Chehab 	 * GPIO configuration:
5850c0d06caSMauro Carvalho Chehab 	 * 0xff: unknown (does not affect DVB-T).
5860c0d06caSMauro Carvalho Chehab 	 * 0xf6: DRX-K (demodulator).
5870c0d06caSMauro Carvalho Chehab 	 * 0xe6: unknown (does not affect DVB-T).
5880c0d06caSMauro Carvalho Chehab 	 * 0xb6: unknown (does not affect DVB-T).
5890c0d06caSMauro Carvalho Chehab 	 */
5900c0d06caSMauro Carvalho Chehab 	struct em28xx_reg_seq terratec_htc_stick_init[] = {
591c074fc4cSFrank Schaefer 		{EM2820_R08_GPIO_CTRL,		0xff,	0xff,	10},
592907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	100},
593907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xe6,	0xff,	50},
594907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	100},
5950c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
5960c0d06caSMauro Carvalho Chehab 	};
5970c0d06caSMauro Carvalho Chehab 	struct em28xx_reg_seq terratec_htc_stick_end[] = {
598907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xb6,	0xff,	100},
599907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xf6,	0xff,	50},
6000c0d06caSMauro Carvalho Chehab 		{	-1,			-1,	-1,	-1},
6010c0d06caSMauro Carvalho Chehab 	};
6020c0d06caSMauro Carvalho Chehab 
60389040136SMartin Blumenstingl 	/*
60489040136SMartin Blumenstingl 	 * Init the analog decoder (not yet supported), but
60589040136SMartin Blumenstingl 	 * it's probably still a good idea.
60689040136SMartin Blumenstingl 	 */
6070c0d06caSMauro Carvalho Chehab 	struct {
6080c0d06caSMauro Carvalho Chehab 		unsigned char r[4];
6090c0d06caSMauro Carvalho Chehab 		int len;
6100c0d06caSMauro Carvalho Chehab 	} regs[] = {
6110c0d06caSMauro Carvalho Chehab 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
6120c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02 }, 2},
6130c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
6140c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
6150c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
6160c0d06caSMauro Carvalho Chehab 	};
6170c0d06caSMauro Carvalho Chehab 
6180c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, terratec_htc_stick_init);
6190c0d06caSMauro Carvalho Chehab 
6200c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
6210c0d06caSMauro Carvalho Chehab 	msleep(10);
6220c0d06caSMauro Carvalho Chehab 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
6230c0d06caSMauro Carvalho Chehab 	msleep(10);
6240c0d06caSMauro Carvalho Chehab 
625c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
6260c0d06caSMauro Carvalho Chehab 
6270c0d06caSMauro Carvalho Chehab 	for (i = 0; i < ARRAY_SIZE(regs); i++)
628c7a45e5bSMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
6290c0d06caSMauro Carvalho Chehab 
6300c0d06caSMauro Carvalho Chehab 	em28xx_gpio_set(dev, terratec_htc_stick_end);
6310c0d06caSMauro Carvalho Chehab };
6320c0d06caSMauro Carvalho Chehab 
63389040136SMartin Blumenstingl static void terratec_htc_usb_xs_init(struct em28xx *dev)
63489040136SMartin Blumenstingl {
63589040136SMartin Blumenstingl 	int i;
63689040136SMartin Blumenstingl 
63789040136SMartin Blumenstingl 	struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
638c074fc4cSFrank Schaefer 		{EM2820_R08_GPIO_CTRL,		0xff,	0xff,	10},
639907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xb2,	0xff,	100},
640907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xb2,	0xff,	50},
641907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xb6,	0xff,	100},
64289040136SMartin Blumenstingl 		{	-1,			-1,	-1,	-1},
64389040136SMartin Blumenstingl 	};
64489040136SMartin Blumenstingl 	struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
645907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xa6,	0xff,	100},
646907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xa6,	0xff,	50},
647907d109bSFrank Schaefer 		{EM2874_R80_GPIO_P0_CTRL,	0xe6,	0xff,	100},
64889040136SMartin Blumenstingl 		{	-1,			-1,	-1,	-1},
64989040136SMartin Blumenstingl 	};
65089040136SMartin Blumenstingl 
65189040136SMartin Blumenstingl 	/*
65289040136SMartin Blumenstingl 	 * Init the analog decoder (not yet supported), but
65389040136SMartin Blumenstingl 	 * it's probably still a good idea.
65489040136SMartin Blumenstingl 	 */
65589040136SMartin Blumenstingl 	struct {
65689040136SMartin Blumenstingl 		unsigned char r[4];
65789040136SMartin Blumenstingl 		int len;
65889040136SMartin Blumenstingl 	} regs[] = {
65989040136SMartin Blumenstingl 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
66089040136SMartin Blumenstingl 		{{ 0x01, 0x02 }, 2},
66189040136SMartin Blumenstingl 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
66289040136SMartin Blumenstingl 		{{ 0x01, 0x00 }, 2},
66389040136SMartin Blumenstingl 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
66489040136SMartin Blumenstingl 		{{ 0x01, 0x00, 0x03, 0xa0 }, 4},
66589040136SMartin Blumenstingl 		{{ 0x01, 0x00 }, 2},
66689040136SMartin Blumenstingl 		{{ 0x01, 0x00, 0x73, 0xaf }, 4},
66789040136SMartin Blumenstingl 		{{ 0x04, 0x00 }, 2},
66889040136SMartin Blumenstingl 		{{ 0x00, 0x04 }, 2},
66989040136SMartin Blumenstingl 		{{ 0x00, 0x04, 0x00, 0x0a }, 4},
67089040136SMartin Blumenstingl 		{{ 0x04, 0x14 }, 2},
67189040136SMartin Blumenstingl 		{{ 0x04, 0x14, 0x00, 0x00 }, 4},
67289040136SMartin Blumenstingl 	};
67389040136SMartin Blumenstingl 
67489040136SMartin Blumenstingl 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
67589040136SMartin Blumenstingl 
67689040136SMartin Blumenstingl 	em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
67789040136SMartin Blumenstingl 
67889040136SMartin Blumenstingl 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
67989040136SMartin Blumenstingl 	msleep(10);
68089040136SMartin Blumenstingl 	em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
68189040136SMartin Blumenstingl 	msleep(10);
68289040136SMartin Blumenstingl 
683c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
68489040136SMartin Blumenstingl 
68589040136SMartin Blumenstingl 	for (i = 0; i < ARRAY_SIZE(regs); i++)
686c7a45e5bSMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
68789040136SMartin Blumenstingl 
68889040136SMartin Blumenstingl 	em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
68989040136SMartin Blumenstingl };
69089040136SMartin Blumenstingl 
6910c0d06caSMauro Carvalho Chehab static void pctv_520e_init(struct em28xx *dev)
6920c0d06caSMauro Carvalho Chehab {
6930c0d06caSMauro Carvalho Chehab 	/*
6940c0d06caSMauro Carvalho Chehab 	 * Init AVF4910B analog decoder. Looks like I2C traffic to
6950c0d06caSMauro Carvalho Chehab 	 * digital demodulator and tuner are routed via AVF4910B.
6960c0d06caSMauro Carvalho Chehab 	 */
6970c0d06caSMauro Carvalho Chehab 	int i;
6980c0d06caSMauro Carvalho Chehab 	struct {
6990c0d06caSMauro Carvalho Chehab 		unsigned char r[4];
7000c0d06caSMauro Carvalho Chehab 		int len;
7010c0d06caSMauro Carvalho Chehab 	} regs[] = {
7020c0d06caSMauro Carvalho Chehab 		{{ 0x06, 0x02, 0x00, 0x31 }, 4},
7030c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02 }, 2},
7040c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x02, 0x00, 0xc6 }, 4},
7050c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
7060c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0xff, 0xaf }, 4},
7070c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x03, 0xa0 }, 4},
7080c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00 }, 2},
7090c0d06caSMauro Carvalho Chehab 		{{ 0x01, 0x00, 0x73, 0xaf }, 4},
7100c0d06caSMauro Carvalho Chehab 	};
7110c0d06caSMauro Carvalho Chehab 
712c7a45e5bSMauro Carvalho Chehab 	dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
7130c0d06caSMauro Carvalho Chehab 
7140c0d06caSMauro Carvalho Chehab 	for (i = 0; i < ARRAY_SIZE(regs); i++)
715c7a45e5bSMauro Carvalho Chehab 		i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
7160c0d06caSMauro Carvalho Chehab };
7170c0d06caSMauro Carvalho Chehab 
71833eebec5SAntti Palosaari static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
71913a5336eSAntti Palosaari {
72033eebec5SAntti Palosaari 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
7213ec40dcfSAntti Palosaari 	struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
7223ec40dcfSAntti Palosaari 	struct em28xx *dev = i2c_bus->dev;
72313a5336eSAntti Palosaari #ifdef CONFIG_GPIOLIB
72413a5336eSAntti Palosaari 	struct em28xx_dvb *dvb = dev->dvb;
72513a5336eSAntti Palosaari 	int ret;
72613a5336eSAntti Palosaari 	unsigned long flags;
72713a5336eSAntti Palosaari 
72833eebec5SAntti Palosaari 	if (c->lna == 1)
72933eebec5SAntti Palosaari 		flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
73013a5336eSAntti Palosaari 	else
73133eebec5SAntti Palosaari 		flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
73213a5336eSAntti Palosaari 
73313a5336eSAntti Palosaari 	ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
73413a5336eSAntti Palosaari 	if (ret)
73513a5336eSAntti Palosaari 		em28xx_errdev("gpio request failed %d\n", ret);
73613a5336eSAntti Palosaari 	else
73713a5336eSAntti Palosaari 		gpio_free(dvb->lna_gpio);
73813a5336eSAntti Palosaari 
73913a5336eSAntti Palosaari 	return ret;
74013a5336eSAntti Palosaari #else
74133eebec5SAntti Palosaari 	dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
74233eebec5SAntti Palosaari 		 KBUILD_MODNAME, c->lna);
74313a5336eSAntti Palosaari 	return 0;
74413a5336eSAntti Palosaari #endif
74513a5336eSAntti Palosaari }
74613a5336eSAntti Palosaari 
747ffb9948eSAntti Palosaari static int em28xx_pctv_292e_set_lna(struct dvb_frontend *fe)
748ffb9948eSAntti Palosaari {
749ffb9948eSAntti Palosaari 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
750ffb9948eSAntti Palosaari 	struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
751ffb9948eSAntti Palosaari 	struct em28xx *dev = i2c_bus->dev;
752ffb9948eSAntti Palosaari 	u8 lna;
753ffb9948eSAntti Palosaari 
754ffb9948eSAntti Palosaari 	if (c->lna == 1)
755ffb9948eSAntti Palosaari 		lna = 0x01;
756ffb9948eSAntti Palosaari 	else
757ffb9948eSAntti Palosaari 		lna = 0x00;
758ffb9948eSAntti Palosaari 
759ffb9948eSAntti Palosaari 	return em28xx_write_reg_bits(dev, EM2874_R80_GPIO_P0_CTRL, lna, 0x01);
760ffb9948eSAntti Palosaari }
761ffb9948eSAntti Palosaari 
7620c0d06caSMauro Carvalho Chehab static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
7630c0d06caSMauro Carvalho Chehab {
7640c0d06caSMauro Carvalho Chehab 	/* Values extracted from a USB trace of the Terratec Windows driver */
7650c0d06caSMauro Carvalho Chehab 	static u8 clock_config[]   = { CLOCK_CTL,  0x38, 0x2c };
7660c0d06caSMauro Carvalho Chehab 	static u8 reset[]          = { RESET,      0x80 };
7670c0d06caSMauro Carvalho Chehab 	static u8 adc_ctl_1_cfg[]  = { ADC_CTL_1,  0x40 };
7680c0d06caSMauro Carvalho Chehab 	static u8 agc_cfg[]        = { AGC_TARGET, 0x28, 0xa0 };
7690c0d06caSMauro Carvalho Chehab 	static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
7700c0d06caSMauro Carvalho Chehab 	static u8 rs_err_cfg[]     = { RS_ERR_PER_1, 0x00, 0x4d };
7710c0d06caSMauro Carvalho Chehab 	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
7720c0d06caSMauro Carvalho Chehab 	static u8 trl_nom_cfg[]    = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
7730c0d06caSMauro Carvalho Chehab 	static u8 tps_given_cfg[]  = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
7740c0d06caSMauro Carvalho Chehab 	static u8 tuner_go[]       = { TUNER_GO, 0x01};
7750c0d06caSMauro Carvalho Chehab 
7760c0d06caSMauro Carvalho Chehab 	mt352_write(fe, clock_config,   sizeof(clock_config));
7770c0d06caSMauro Carvalho Chehab 	udelay(200);
7780c0d06caSMauro Carvalho Chehab 	mt352_write(fe, reset,          sizeof(reset));
7790c0d06caSMauro Carvalho Chehab 	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
7800c0d06caSMauro Carvalho Chehab 	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
7810c0d06caSMauro Carvalho Chehab 	mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
7820c0d06caSMauro Carvalho Chehab 	mt352_write(fe, rs_err_cfg,     sizeof(rs_err_cfg));
7830c0d06caSMauro Carvalho Chehab 	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
7840c0d06caSMauro Carvalho Chehab 	mt352_write(fe, trl_nom_cfg,    sizeof(trl_nom_cfg));
7850c0d06caSMauro Carvalho Chehab 	mt352_write(fe, tps_given_cfg,  sizeof(tps_given_cfg));
7860c0d06caSMauro Carvalho Chehab 	mt352_write(fe, tuner_go,       sizeof(tuner_go));
7870c0d06caSMauro Carvalho Chehab 	return 0;
7880c0d06caSMauro Carvalho Chehab }
7890c0d06caSMauro Carvalho Chehab 
7900c0d06caSMauro Carvalho Chehab static struct mt352_config terratec_xs_mt352_cfg = {
7910c0d06caSMauro Carvalho Chehab 	.demod_address = (0x1e >> 1),
7920c0d06caSMauro Carvalho Chehab 	.no_tuner = 1,
7930c0d06caSMauro Carvalho Chehab 	.if2 = 45600,
7940c0d06caSMauro Carvalho Chehab 	.demod_init = em28xx_mt352_terratec_xs_init,
7950c0d06caSMauro Carvalho Chehab };
7960c0d06caSMauro Carvalho Chehab 
7970c0d06caSMauro Carvalho Chehab static struct tda10023_config em28xx_tda10023_config = {
7980c0d06caSMauro Carvalho Chehab 	.demod_address = 0x0c,
7990c0d06caSMauro Carvalho Chehab 	.invert = 1,
8000c0d06caSMauro Carvalho Chehab };
8010c0d06caSMauro Carvalho Chehab 
8020c0d06caSMauro Carvalho Chehab static struct cxd2820r_config em28xx_cxd2820r_config = {
8030c0d06caSMauro Carvalho Chehab 	.i2c_address = (0xd8 >> 1),
8040c0d06caSMauro Carvalho Chehab 	.ts_mode = CXD2820R_TS_SERIAL,
8050c0d06caSMauro Carvalho Chehab };
8060c0d06caSMauro Carvalho Chehab 
8070c0d06caSMauro Carvalho Chehab static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
8080c0d06caSMauro Carvalho Chehab 	.output_opt = TDA18271_OUTPUT_LT_OFF,
8090c0d06caSMauro Carvalho Chehab 	.gate = TDA18271_GATE_DIGITAL,
8100c0d06caSMauro Carvalho Chehab };
8110c0d06caSMauro Carvalho Chehab 
8120c0d06caSMauro Carvalho Chehab static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
8130c0d06caSMauro Carvalho Chehab 	.demod_address = (0x1e >> 1),
8140c0d06caSMauro Carvalho Chehab 	.disable_i2c_gate_ctrl = 1,
8150c0d06caSMauro Carvalho Chehab 	.no_tuner = 1,
8160c0d06caSMauro Carvalho Chehab 	.parallel_ts = 1,
8170c0d06caSMauro Carvalho Chehab };
818fdf1bc9fSMauro Carvalho Chehab 
819*8c47311dSAlberto Mardegan static struct mt2060_config em28xx_mt2060_config = {
820*8c47311dSAlberto Mardegan 	.i2c_address = 0x60,
821*8c47311dSAlberto Mardegan };
822*8c47311dSAlberto Mardegan 
8230c0d06caSMauro Carvalho Chehab static struct qt1010_config em28xx_qt1010_config = {
8240c0d06caSMauro Carvalho Chehab 	.i2c_address = 0x62
8250c0d06caSMauro Carvalho Chehab };
8260c0d06caSMauro Carvalho Chehab 
8274159d01bSMauro Carvalho Chehab static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
8284159d01bSMauro Carvalho Chehab 	.demod_address = 0x10,
8294159d01bSMauro Carvalho Chehab 	.is_serial = true,
8304159d01bSMauro Carvalho Chehab };
8314159d01bSMauro Carvalho Chehab 
8324159d01bSMauro Carvalho Chehab static struct tda18271_std_map mb86a20s_tda18271_config = {
8334159d01bSMauro Carvalho Chehab 	.dvbt_6   = { .if_freq = 4000, .agc_mode = 3, .std = 4,
8344159d01bSMauro Carvalho Chehab 		      .if_lvl = 1, .rfagc_top = 0x37, },
8354159d01bSMauro Carvalho Chehab };
8364159d01bSMauro Carvalho Chehab 
8374159d01bSMauro Carvalho Chehab static struct tda18271_config c3tech_duo_tda18271_config = {
8384159d01bSMauro Carvalho Chehab 	.std_map = &mb86a20s_tda18271_config,
8394159d01bSMauro Carvalho Chehab 	.gate    = TDA18271_GATE_DIGITAL,
8404159d01bSMauro Carvalho Chehab 	.small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
8414159d01bSMauro Carvalho Chehab };
8424159d01bSMauro Carvalho Chehab 
843ec573362SAntti Palosaari static const struct m88ds3103_config pctv_461e_m88ds3103_config = {
844ec573362SAntti Palosaari 	.i2c_addr = 0x68,
845ec573362SAntti Palosaari 	.clock = 27000000,
846ec573362SAntti Palosaari 	.i2c_wr_max = 33,
847ec573362SAntti Palosaari 	.clock_out = 0,
84879d09330Snibble.max 	.ts_mode = M88DS3103_TS_PARALLEL,
84979d09330Snibble.max 	.ts_clk = 16000,
85079d09330Snibble.max 	.ts_clk_pol = 1,
851ec573362SAntti Palosaari 	.agc = 0x99,
852ec573362SAntti Palosaari };
853ec573362SAntti Palosaari 
85438b2df95SDevin Heitmueller static struct tda18271_std_map drx_j_std_map = {
85538b2df95SDevin Heitmueller 	.atsc_6   = { .if_freq = 5000, .agc_mode = 3, .std = 0, .if_lvl = 1,
85638b2df95SDevin Heitmueller 		      .rfagc_top = 0x37, },
85738b2df95SDevin Heitmueller 	.qam_6    = { .if_freq = 5380, .agc_mode = 3, .std = 3, .if_lvl = 1,
85838b2df95SDevin Heitmueller 		      .rfagc_top = 0x37, },
85938b2df95SDevin Heitmueller };
86038b2df95SDevin Heitmueller 
86138b2df95SDevin Heitmueller static struct tda18271_config pinnacle_80e_dvb_config = {
86238b2df95SDevin Heitmueller 	.std_map = &drx_j_std_map,
86338b2df95SDevin Heitmueller 	.gate    = TDA18271_GATE_DIGITAL,
86438b2df95SDevin Heitmueller 	.role    = TDA18271_MASTER,
86538b2df95SDevin Heitmueller };
86638b2df95SDevin Heitmueller 
8670c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */
8680c0d06caSMauro Carvalho Chehab 
8690c0d06caSMauro Carvalho Chehab static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
8700c0d06caSMauro Carvalho Chehab {
8710c0d06caSMauro Carvalho Chehab 	struct dvb_frontend *fe;
8720c0d06caSMauro Carvalho Chehab 	struct xc2028_config cfg;
873ee97207cSMauro Carvalho Chehab 	struct xc2028_ctrl ctl;
8740c0d06caSMauro Carvalho Chehab 
8750c0d06caSMauro Carvalho Chehab 	memset(&cfg, 0, sizeof(cfg));
876c7a45e5bSMauro Carvalho Chehab 	cfg.i2c_adap  = &dev->i2c_adap[dev->def_i2c_bus];
8770c0d06caSMauro Carvalho Chehab 	cfg.i2c_addr  = addr;
8780c0d06caSMauro Carvalho Chehab 
879ee97207cSMauro Carvalho Chehab 	memset(&ctl, 0, sizeof(ctl));
880ee97207cSMauro Carvalho Chehab 	em28xx_setup_xc3028(dev, &ctl);
881ee97207cSMauro Carvalho Chehab 	cfg.ctrl  = &ctl;
882ee97207cSMauro Carvalho Chehab 
8830c0d06caSMauro Carvalho Chehab 	if (!dev->dvb->fe[0]) {
8840c0d06caSMauro Carvalho Chehab 		em28xx_errdev("/2: dvb frontend not attached. "
8850c0d06caSMauro Carvalho Chehab 				"Can't attach xc3028\n");
8860c0d06caSMauro Carvalho Chehab 		return -EINVAL;
8870c0d06caSMauro Carvalho Chehab 	}
8880c0d06caSMauro Carvalho Chehab 
8890c0d06caSMauro Carvalho Chehab 	fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
8900c0d06caSMauro Carvalho Chehab 	if (!fe) {
8910c0d06caSMauro Carvalho Chehab 		em28xx_errdev("/2: xc3028 attach failed\n");
8920c0d06caSMauro Carvalho Chehab 		dvb_frontend_detach(dev->dvb->fe[0]);
8930c0d06caSMauro Carvalho Chehab 		dev->dvb->fe[0] = NULL;
8940c0d06caSMauro Carvalho Chehab 		return -EINVAL;
8950c0d06caSMauro Carvalho Chehab 	}
8960c0d06caSMauro Carvalho Chehab 
8970c0d06caSMauro Carvalho Chehab 	em28xx_info("%s/2: xc3028 attached\n", dev->name);
8980c0d06caSMauro Carvalho Chehab 
8990c0d06caSMauro Carvalho Chehab 	return 0;
9000c0d06caSMauro Carvalho Chehab }
9010c0d06caSMauro Carvalho Chehab 
9020c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */
9030c0d06caSMauro Carvalho Chehab 
9040c0d06caSMauro Carvalho Chehab static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
9050c0d06caSMauro Carvalho Chehab 			       struct em28xx *dev, struct device *device)
9060c0d06caSMauro Carvalho Chehab {
9070c0d06caSMauro Carvalho Chehab 	int result;
9080c0d06caSMauro Carvalho Chehab 
9090c0d06caSMauro Carvalho Chehab 	mutex_init(&dvb->lock);
9100c0d06caSMauro Carvalho Chehab 
9110c0d06caSMauro Carvalho Chehab 	/* register adapter */
9120c0d06caSMauro Carvalho Chehab 	result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
9130c0d06caSMauro Carvalho Chehab 				      adapter_nr);
9140c0d06caSMauro Carvalho Chehab 	if (result < 0) {
9150c0d06caSMauro Carvalho Chehab 		printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
9160c0d06caSMauro Carvalho Chehab 		       dev->name, result);
9170c0d06caSMauro Carvalho Chehab 		goto fail_adapter;
9180c0d06caSMauro Carvalho Chehab 	}
9190c0d06caSMauro Carvalho Chehab 
9200c0d06caSMauro Carvalho Chehab 	/* Ensure all frontends negotiate bus access */
9210c0d06caSMauro Carvalho Chehab 	dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
9220c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
9230c0d06caSMauro Carvalho Chehab 		dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
9240c0d06caSMauro Carvalho Chehab 
9253de09fbbSHans Verkuil 	dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
9260c0d06caSMauro Carvalho Chehab 
9270c0d06caSMauro Carvalho Chehab 	/* register frontend */
9280c0d06caSMauro Carvalho Chehab 	result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
9290c0d06caSMauro Carvalho Chehab 	if (result < 0) {
9300c0d06caSMauro Carvalho Chehab 		printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
9310c0d06caSMauro Carvalho Chehab 		       dev->name, result);
9320c0d06caSMauro Carvalho Chehab 		goto fail_frontend0;
9330c0d06caSMauro Carvalho Chehab 	}
9340c0d06caSMauro Carvalho Chehab 
9350c0d06caSMauro Carvalho Chehab 	/* register 2nd frontend */
9360c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1]) {
9370c0d06caSMauro Carvalho Chehab 		result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
9380c0d06caSMauro Carvalho Chehab 		if (result < 0) {
9390c0d06caSMauro Carvalho Chehab 			printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
9400c0d06caSMauro Carvalho Chehab 			       dev->name, result);
9410c0d06caSMauro Carvalho Chehab 			goto fail_frontend1;
9420c0d06caSMauro Carvalho Chehab 		}
9430c0d06caSMauro Carvalho Chehab 	}
9440c0d06caSMauro Carvalho Chehab 
9450c0d06caSMauro Carvalho Chehab 	/* register demux stuff */
9460c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.capabilities =
9470c0d06caSMauro Carvalho Chehab 		DMX_TS_FILTERING | DMX_SECTION_FILTERING |
9480c0d06caSMauro Carvalho Chehab 		DMX_MEMORY_BASED_FILTERING;
9490c0d06caSMauro Carvalho Chehab 	dvb->demux.priv       = dvb;
9500c0d06caSMauro Carvalho Chehab 	dvb->demux.filternum  = 256;
9510c0d06caSMauro Carvalho Chehab 	dvb->demux.feednum    = 256;
9520c0d06caSMauro Carvalho Chehab 	dvb->demux.start_feed = em28xx_start_feed;
9530c0d06caSMauro Carvalho Chehab 	dvb->demux.stop_feed  = em28xx_stop_feed;
9540c0d06caSMauro Carvalho Chehab 
9550c0d06caSMauro Carvalho Chehab 	result = dvb_dmx_init(&dvb->demux);
9560c0d06caSMauro Carvalho Chehab 	if (result < 0) {
9570c0d06caSMauro Carvalho Chehab 		printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
9580c0d06caSMauro Carvalho Chehab 		       dev->name, result);
9590c0d06caSMauro Carvalho Chehab 		goto fail_dmx;
9600c0d06caSMauro Carvalho Chehab 	}
9610c0d06caSMauro Carvalho Chehab 
9620c0d06caSMauro Carvalho Chehab 	dvb->dmxdev.filternum    = 256;
9630c0d06caSMauro Carvalho Chehab 	dvb->dmxdev.demux        = &dvb->demux.dmx;
9640c0d06caSMauro Carvalho Chehab 	dvb->dmxdev.capabilities = 0;
9650c0d06caSMauro Carvalho Chehab 	result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
9660c0d06caSMauro Carvalho Chehab 	if (result < 0) {
9670c0d06caSMauro Carvalho Chehab 		printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
9680c0d06caSMauro Carvalho Chehab 		       dev->name, result);
9690c0d06caSMauro Carvalho Chehab 		goto fail_dmxdev;
9700c0d06caSMauro Carvalho Chehab 	}
9710c0d06caSMauro Carvalho Chehab 
9720c0d06caSMauro Carvalho Chehab 	dvb->fe_hw.source = DMX_FRONTEND_0;
9730c0d06caSMauro Carvalho Chehab 	result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
9740c0d06caSMauro Carvalho Chehab 	if (result < 0) {
9750c0d06caSMauro Carvalho Chehab 		printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
9760c0d06caSMauro Carvalho Chehab 		       dev->name, result);
9770c0d06caSMauro Carvalho Chehab 		goto fail_fe_hw;
9780c0d06caSMauro Carvalho Chehab 	}
9790c0d06caSMauro Carvalho Chehab 
9800c0d06caSMauro Carvalho Chehab 	dvb->fe_mem.source = DMX_MEMORY_FE;
9810c0d06caSMauro Carvalho Chehab 	result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
9820c0d06caSMauro Carvalho Chehab 	if (result < 0) {
9830c0d06caSMauro Carvalho Chehab 		printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
9840c0d06caSMauro Carvalho Chehab 		       dev->name, result);
9850c0d06caSMauro Carvalho Chehab 		goto fail_fe_mem;
9860c0d06caSMauro Carvalho Chehab 	}
9870c0d06caSMauro Carvalho Chehab 
9880c0d06caSMauro Carvalho Chehab 	result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
9890c0d06caSMauro Carvalho Chehab 	if (result < 0) {
9900c0d06caSMauro Carvalho Chehab 		printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
9910c0d06caSMauro Carvalho Chehab 		       dev->name, result);
9920c0d06caSMauro Carvalho Chehab 		goto fail_fe_conn;
9930c0d06caSMauro Carvalho Chehab 	}
9940c0d06caSMauro Carvalho Chehab 
9950c0d06caSMauro Carvalho Chehab 	/* register network adapter */
9960c0d06caSMauro Carvalho Chehab 	dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
9970c0d06caSMauro Carvalho Chehab 	return 0;
9980c0d06caSMauro Carvalho Chehab 
9990c0d06caSMauro Carvalho Chehab fail_fe_conn:
10000c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
10010c0d06caSMauro Carvalho Chehab fail_fe_mem:
10020c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
10030c0d06caSMauro Carvalho Chehab fail_fe_hw:
10040c0d06caSMauro Carvalho Chehab 	dvb_dmxdev_release(&dvb->dmxdev);
10050c0d06caSMauro Carvalho Chehab fail_dmxdev:
10060c0d06caSMauro Carvalho Chehab 	dvb_dmx_release(&dvb->demux);
10070c0d06caSMauro Carvalho Chehab fail_dmx:
10080c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
10090c0d06caSMauro Carvalho Chehab 		dvb_unregister_frontend(dvb->fe[1]);
10100c0d06caSMauro Carvalho Chehab 	dvb_unregister_frontend(dvb->fe[0]);
10110c0d06caSMauro Carvalho Chehab fail_frontend1:
10120c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
10130c0d06caSMauro Carvalho Chehab 		dvb_frontend_detach(dvb->fe[1]);
10140c0d06caSMauro Carvalho Chehab fail_frontend0:
10150c0d06caSMauro Carvalho Chehab 	dvb_frontend_detach(dvb->fe[0]);
10160c0d06caSMauro Carvalho Chehab 	dvb_unregister_adapter(&dvb->adapter);
10170c0d06caSMauro Carvalho Chehab fail_adapter:
10180c0d06caSMauro Carvalho Chehab 	return result;
10190c0d06caSMauro Carvalho Chehab }
10200c0d06caSMauro Carvalho Chehab 
10210c0d06caSMauro Carvalho Chehab static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
10220c0d06caSMauro Carvalho Chehab {
10230c0d06caSMauro Carvalho Chehab 	dvb_net_release(&dvb->net);
10240c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
10250c0d06caSMauro Carvalho Chehab 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
10260c0d06caSMauro Carvalho Chehab 	dvb_dmxdev_release(&dvb->dmxdev);
10270c0d06caSMauro Carvalho Chehab 	dvb_dmx_release(&dvb->demux);
10280c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
10290c0d06caSMauro Carvalho Chehab 		dvb_unregister_frontend(dvb->fe[1]);
10300c0d06caSMauro Carvalho Chehab 	dvb_unregister_frontend(dvb->fe[0]);
10310c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1] && !dvb->dont_attach_fe1)
10320c0d06caSMauro Carvalho Chehab 		dvb_frontend_detach(dvb->fe[1]);
10330c0d06caSMauro Carvalho Chehab 	dvb_frontend_detach(dvb->fe[0]);
10340c0d06caSMauro Carvalho Chehab 	dvb_unregister_adapter(&dvb->adapter);
10350c0d06caSMauro Carvalho Chehab }
10360c0d06caSMauro Carvalho Chehab 
10370c0d06caSMauro Carvalho Chehab static int em28xx_dvb_init(struct em28xx *dev)
10380c0d06caSMauro Carvalho Chehab {
10391b07a77fSMauro Carvalho Chehab 	int result = 0;
10400c0d06caSMauro Carvalho Chehab 	struct em28xx_dvb *dvb;
10410c0d06caSMauro Carvalho Chehab 
1042822b8deaSMauro Carvalho Chehab 	if (dev->is_audio_only) {
1043822b8deaSMauro Carvalho Chehab 		/* Shouldn't initialize IR for this interface */
1044822b8deaSMauro Carvalho Chehab 		return 0;
1045822b8deaSMauro Carvalho Chehab 	}
1046822b8deaSMauro Carvalho Chehab 
10470c0d06caSMauro Carvalho Chehab 	if (!dev->board.has_dvb) {
10480c0d06caSMauro Carvalho Chehab 		/* This device does not support the extension */
10490c0d06caSMauro Carvalho Chehab 		return 0;
10500c0d06caSMauro Carvalho Chehab 	}
10510c0d06caSMauro Carvalho Chehab 
10529634614fSMauro Carvalho Chehab 	em28xx_info("Binding DVB extension\n");
10539634614fSMauro Carvalho Chehab 
10540c0d06caSMauro Carvalho Chehab 	dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
10550c0d06caSMauro Carvalho Chehab 	if (dvb == NULL) {
10560c0d06caSMauro Carvalho Chehab 		em28xx_info("em28xx_dvb: memory allocation failed\n");
10570c0d06caSMauro Carvalho Chehab 		return -ENOMEM;
10580c0d06caSMauro Carvalho Chehab 	}
10590c0d06caSMauro Carvalho Chehab 	dev->dvb = dvb;
10600c0d06caSMauro Carvalho Chehab 	dvb->fe[0] = dvb->fe[1] = NULL;
10610c0d06caSMauro Carvalho Chehab 
106227ba0dacSFrank Schaefer 	/* pre-allocate DVB usb transfer buffers */
106327ba0dacSFrank Schaefer 	if (dev->dvb_xfer_bulk) {
106427ba0dacSFrank Schaefer 		result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
106527ba0dacSFrank Schaefer 					   dev->dvb_xfer_bulk,
106627ba0dacSFrank Schaefer 					   EM28XX_DVB_NUM_BUFS,
106727ba0dacSFrank Schaefer 					   512,
106827ba0dacSFrank Schaefer 					   EM28XX_DVB_BULK_PACKET_MULTIPLIER);
106927ba0dacSFrank Schaefer 	} else {
107027ba0dacSFrank Schaefer 		result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
107127ba0dacSFrank Schaefer 					   dev->dvb_xfer_bulk,
107227ba0dacSFrank Schaefer 					   EM28XX_DVB_NUM_BUFS,
107327ba0dacSFrank Schaefer 					   dev->dvb_max_pkt_size_isoc,
107427ba0dacSFrank Schaefer 					   EM28XX_DVB_NUM_ISOC_PACKETS);
107527ba0dacSFrank Schaefer 	}
107627ba0dacSFrank Schaefer 	if (result) {
107727ba0dacSFrank Schaefer 		em28xx_errdev("em28xx_dvb: failed to pre-allocate USB transfer buffers for DVB.\n");
107827ba0dacSFrank Schaefer 		kfree(dvb);
107927ba0dacSFrank Schaefer 		dev->dvb = NULL;
108027ba0dacSFrank Schaefer 		return result;
108127ba0dacSFrank Schaefer 	}
108227ba0dacSFrank Schaefer 
10830c0d06caSMauro Carvalho Chehab 	mutex_lock(&dev->lock);
10840c0d06caSMauro Carvalho Chehab 	em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
10850c0d06caSMauro Carvalho Chehab 	/* init frontend */
10860c0d06caSMauro Carvalho Chehab 	switch (dev->model) {
10870c0d06caSMauro Carvalho Chehab 	case EM2874_BOARD_LEADERSHIP_ISDBT:
10880c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(s921_attach,
1089c7a45e5bSMauro Carvalho Chehab 				&sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
10900c0d06caSMauro Carvalho Chehab 
10910c0d06caSMauro Carvalho Chehab 		if (!dvb->fe[0]) {
10920c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
10930c0d06caSMauro Carvalho Chehab 			goto out_free;
10940c0d06caSMauro Carvalho Chehab 		}
10950c0d06caSMauro Carvalho Chehab 
10960c0d06caSMauro Carvalho Chehab 		break;
10970c0d06caSMauro Carvalho Chehab 	case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
10980c0d06caSMauro Carvalho Chehab 	case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
10990c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
11000c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
11010c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(lgdt330x_attach,
11020c0d06caSMauro Carvalho Chehab 					   &em2880_lgdt3303_dev,
1103c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
11040c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
11050c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
11060c0d06caSMauro Carvalho Chehab 			goto out_free;
11070c0d06caSMauro Carvalho Chehab 		}
11080c0d06caSMauro Carvalho Chehab 		break;
11090c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_KWORLD_DVB_310U:
11100c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(zl10353_attach,
11110c0d06caSMauro Carvalho Chehab 					   &em28xx_zl10353_with_xc3028,
1112c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
11130c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
11140c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
11150c0d06caSMauro Carvalho Chehab 			goto out_free;
11160c0d06caSMauro Carvalho Chehab 		}
11170c0d06caSMauro Carvalho Chehab 		break;
11180c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
11190c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_TERRATEC_HYBRID_XS:
11200c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_EMPIRE_DUAL_TV:
11210c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(zl10353_attach,
11220c0d06caSMauro Carvalho Chehab 					   &em28xx_zl10353_xc3028_no_i2c_gate,
1123c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
11240c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
11250c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
11260c0d06caSMauro Carvalho Chehab 			goto out_free;
11270c0d06caSMauro Carvalho Chehab 		}
11280c0d06caSMauro Carvalho Chehab 		break;
11290c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_TERRATEC_HYBRID_XS:
11300c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
11310c0d06caSMauro Carvalho Chehab 	case EM2881_BOARD_PINNACLE_HYBRID_PRO:
11320c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_DIKOM_DK300:
11330c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_KWORLD_VS_DVBT:
11340c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(zl10353_attach,
11350c0d06caSMauro Carvalho Chehab 					   &em28xx_zl10353_xc3028_no_i2c_gate,
1136c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
11370c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0] == NULL) {
11380c0d06caSMauro Carvalho Chehab 			/* This board could have either a zl10353 or a mt352.
11390c0d06caSMauro Carvalho Chehab 			   If the chip id isn't for zl10353, try mt352 */
11400c0d06caSMauro Carvalho Chehab 			dvb->fe[0] = dvb_attach(mt352_attach,
11410c0d06caSMauro Carvalho Chehab 						   &terratec_xs_mt352_cfg,
1142c7a45e5bSMauro Carvalho Chehab 						   &dev->i2c_adap[dev->def_i2c_bus]);
11430c0d06caSMauro Carvalho Chehab 		}
11440c0d06caSMauro Carvalho Chehab 
11450c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
11460c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
11470c0d06caSMauro Carvalho Chehab 			goto out_free;
11480c0d06caSMauro Carvalho Chehab 		}
11490c0d06caSMauro Carvalho Chehab 		break;
1150*8c47311dSAlberto Mardegan 	case EM2870_BOARD_TERRATEC_XS_MT2060:
1151*8c47311dSAlberto Mardegan 		dvb->fe[0] = dvb_attach(zl10353_attach,
1152*8c47311dSAlberto Mardegan 						&em28xx_zl10353_no_i2c_gate_dev,
1153*8c47311dSAlberto Mardegan 						&dev->i2c_adap[dev->def_i2c_bus]);
1154*8c47311dSAlberto Mardegan 		if (dvb->fe[0] != NULL) {
1155*8c47311dSAlberto Mardegan 			dvb_attach(mt2060_attach, dvb->fe[0],
1156*8c47311dSAlberto Mardegan 					&dev->i2c_adap[dev->def_i2c_bus],
1157*8c47311dSAlberto Mardegan 					&em28xx_mt2060_config, 1220);
1158*8c47311dSAlberto Mardegan 		}
1159*8c47311dSAlberto Mardegan 		break;
11600c0d06caSMauro Carvalho Chehab 	case EM2870_BOARD_KWORLD_355U:
11610c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(zl10353_attach,
11620c0d06caSMauro Carvalho Chehab 					   &em28xx_zl10353_no_i2c_gate_dev,
1163c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
11640c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0] != NULL)
11650c0d06caSMauro Carvalho Chehab 			dvb_attach(qt1010_attach, dvb->fe[0],
1166c7a45e5bSMauro Carvalho Chehab 				   &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
11670c0d06caSMauro Carvalho Chehab 		break;
11680c0d06caSMauro Carvalho Chehab 	case EM2883_BOARD_KWORLD_HYBRID_330U:
11690c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_EVGA_INDTUBE:
11700c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(s5h1409_attach,
11710c0d06caSMauro Carvalho Chehab 					   &em28xx_s5h1409_with_xc3028,
1172c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
11730c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
11740c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
11750c0d06caSMauro Carvalho Chehab 			goto out_free;
11760c0d06caSMauro Carvalho Chehab 		}
11770c0d06caSMauro Carvalho Chehab 		break;
11780c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_KWORLD_ATSC_315U:
11790c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(lgdt330x_attach,
11800c0d06caSMauro Carvalho Chehab 					   &em2880_lgdt3303_dev,
1181c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
11820c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0] != NULL) {
11830c0d06caSMauro Carvalho Chehab 			if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1184fdf1bc9fSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
1185fdf1bc9fSMauro Carvalho Chehab 					0x61, TUNER_THOMSON_DTT761X)) {
11860c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
11870c0d06caSMauro Carvalho Chehab 				goto out_free;
11880c0d06caSMauro Carvalho Chehab 			}
11890c0d06caSMauro Carvalho Chehab 		}
11900c0d06caSMauro Carvalho Chehab 		break;
11910c0d06caSMauro Carvalho Chehab 	case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
11920c0d06caSMauro Carvalho Chehab 	case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
11930c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
1194c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus], &dev->udev->dev);
11950c0d06caSMauro Carvalho Chehab 		if (em28xx_attach_xc3028(0x61, dev) < 0) {
11960c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
11970c0d06caSMauro Carvalho Chehab 			goto out_free;
11980c0d06caSMauro Carvalho Chehab 		}
11990c0d06caSMauro Carvalho Chehab 		break;
12000c0d06caSMauro Carvalho Chehab 	case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
12010c0d06caSMauro Carvalho Chehab 		/* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
12020c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(tda10023_attach,
12030c0d06caSMauro Carvalho Chehab 			&em28xx_tda10023_config,
1204c7a45e5bSMauro Carvalho Chehab 			&dev->i2c_adap[dev->def_i2c_bus], 0x48);
12050c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]) {
12060c0d06caSMauro Carvalho Chehab 			if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1207fdf1bc9fSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
1208fdf1bc9fSMauro Carvalho Chehab 					0x60, TUNER_PHILIPS_CU1216L)) {
12090c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
12100c0d06caSMauro Carvalho Chehab 				goto out_free;
12110c0d06caSMauro Carvalho Chehab 			}
12120c0d06caSMauro Carvalho Chehab 		}
12130c0d06caSMauro Carvalho Chehab 		break;
12140c0d06caSMauro Carvalho Chehab 	case EM2870_BOARD_KWORLD_A340:
12150c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(lgdt3305_attach,
12160c0d06caSMauro Carvalho Chehab 					   &em2870_lgdt3304_dev,
1217c7a45e5bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
12184db8954aSShuah Khan 		if (!dvb->fe[0]) {
12194db8954aSShuah Khan 			result = -EINVAL;
12204db8954aSShuah Khan 			goto out_free;
12214db8954aSShuah Khan 		}
12224db8954aSShuah Khan 		if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
12234db8954aSShuah Khan 				&dev->i2c_adap[dev->def_i2c_bus],
12244db8954aSShuah Khan 			&kworld_a340_config)) {
12254db8954aSShuah Khan 				dvb_frontend_detach(dvb->fe[0]);
12264db8954aSShuah Khan 				result = -EINVAL;
12274db8954aSShuah Khan 				goto out_free;
12284db8954aSShuah Khan 		}
12290c0d06caSMauro Carvalho Chehab 		break;
12300c0d06caSMauro Carvalho Chehab 	case EM28174_BOARD_PCTV_290E:
1231a36a66d7SAntti Palosaari 		/* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1232a36a66d7SAntti Palosaari 		dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
1233a36a66d7SAntti Palosaari 				CXD2820R_GPIO_L;
12340c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(cxd2820r_attach,
12350c0d06caSMauro Carvalho Chehab 					&em28xx_cxd2820r_config,
1236c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
123713a5336eSAntti Palosaari 					&dvb->lna_gpio);
12380c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]) {
12390c0d06caSMauro Carvalho Chehab 			/* FE 0 attach tuner */
12400c0d06caSMauro Carvalho Chehab 			if (!dvb_attach(tda18271_attach,
12410c0d06caSMauro Carvalho Chehab 					dvb->fe[0],
12420c0d06caSMauro Carvalho Chehab 					0x60,
1243c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
12440c0d06caSMauro Carvalho Chehab 					&em28xx_cxd2820r_tda18271_config)) {
12450c0d06caSMauro Carvalho Chehab 
12460c0d06caSMauro Carvalho Chehab 				dvb_frontend_detach(dvb->fe[0]);
12470c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
12480c0d06caSMauro Carvalho Chehab 				goto out_free;
12490c0d06caSMauro Carvalho Chehab 			}
12501e8f31f3SAntti Palosaari 
125113a5336eSAntti Palosaari #ifdef CONFIG_GPIOLIB
12521e8f31f3SAntti Palosaari 			/* enable LNA for DVB-T, DVB-T2 and DVB-C */
12530c42a55cSAntti Palosaari 			result = gpio_request_one(dvb->lna_gpio,
12540c42a55cSAntti Palosaari 						  GPIOF_OUT_INIT_LOW, NULL);
12551e8f31f3SAntti Palosaari 			if (result)
12560c42a55cSAntti Palosaari 				em28xx_errdev("gpio request failed %d\n",
12570c42a55cSAntti Palosaari 					      result);
12581e8f31f3SAntti Palosaari 			else
125913a5336eSAntti Palosaari 				gpio_free(dvb->lna_gpio);
12601e8f31f3SAntti Palosaari 
12611e8f31f3SAntti Palosaari 			result = 0; /* continue even set LNA fails */
126213a5336eSAntti Palosaari #endif
126313a5336eSAntti Palosaari 			dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
12640c42a55cSAntti Palosaari 		}
12650c42a55cSAntti Palosaari 
12660c0d06caSMauro Carvalho Chehab 		break;
12670c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
12680c0d06caSMauro Carvalho Chehab 	{
12690c0d06caSMauro Carvalho Chehab 		struct xc5000_config cfg;
1270fdf1bc9fSMauro Carvalho Chehab 
12710c0d06caSMauro Carvalho Chehab 		hauppauge_hvr930c_init(dev);
12720c0d06caSMauro Carvalho Chehab 
12730c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach,
1274c7a45e5bSMauro Carvalho Chehab 					&hauppauge_930c_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
12750c0d06caSMauro Carvalho Chehab 		if (!dvb->fe[0]) {
12760c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
12770c0d06caSMauro Carvalho Chehab 			goto out_free;
12780c0d06caSMauro Carvalho Chehab 		}
12790c0d06caSMauro Carvalho Chehab 		/* FIXME: do we need a pll semaphore? */
12800c0d06caSMauro Carvalho Chehab 		dvb->fe[0]->sec_priv = dvb;
12810c0d06caSMauro Carvalho Chehab 		sema_init(&dvb->pll_mutex, 1);
12820c0d06caSMauro Carvalho Chehab 		dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
12830c0d06caSMauro Carvalho Chehab 		dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
12840c0d06caSMauro Carvalho Chehab 
12850c0d06caSMauro Carvalho Chehab 		/* Attach xc5000 */
12860c0d06caSMauro Carvalho Chehab 		memset(&cfg, 0, sizeof(cfg));
12870c0d06caSMauro Carvalho Chehab 		cfg.i2c_address  = 0x61;
12880c0d06caSMauro Carvalho Chehab 		cfg.if_khz = 4000;
12890c0d06caSMauro Carvalho Chehab 
12900c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]->ops.i2c_gate_ctrl)
12910c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1292c7a45e5bSMauro Carvalho Chehab 		if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
12930c0d06caSMauro Carvalho Chehab 				&cfg)) {
12940c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
12950c0d06caSMauro Carvalho Chehab 			goto out_free;
12960c0d06caSMauro Carvalho Chehab 		}
12970c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]->ops.i2c_gate_ctrl)
12980c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
12990c0d06caSMauro Carvalho Chehab 
13000c0d06caSMauro Carvalho Chehab 		break;
13010c0d06caSMauro Carvalho Chehab 	}
13020c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_TERRATEC_H5:
13030c0d06caSMauro Carvalho Chehab 		terratec_h5_init(dev);
13040c0d06caSMauro Carvalho Chehab 
1305c7a45e5bSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
13060c0d06caSMauro Carvalho Chehab 		if (!dvb->fe[0]) {
13070c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
13080c0d06caSMauro Carvalho Chehab 			goto out_free;
13090c0d06caSMauro Carvalho Chehab 		}
13100c0d06caSMauro Carvalho Chehab 		/* FIXME: do we need a pll semaphore? */
13110c0d06caSMauro Carvalho Chehab 		dvb->fe[0]->sec_priv = dvb;
13120c0d06caSMauro Carvalho Chehab 		sema_init(&dvb->pll_mutex, 1);
13130c0d06caSMauro Carvalho Chehab 		dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
13140c0d06caSMauro Carvalho Chehab 		dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
13150c0d06caSMauro Carvalho Chehab 
13160c0d06caSMauro Carvalho Chehab 		/* Attach tda18271 to DVB-C frontend */
13170c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]->ops.i2c_gate_ctrl)
13180c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1319c7a45e5bSMauro Carvalho Chehab 		if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
13200c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
13210c0d06caSMauro Carvalho Chehab 			goto out_free;
13220c0d06caSMauro Carvalho Chehab 		}
13230c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]->ops.i2c_gate_ctrl)
13240c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
13250c0d06caSMauro Carvalho Chehab 
13260c0d06caSMauro Carvalho Chehab 		break;
13274159d01bSMauro Carvalho Chehab 	case EM2884_BOARD_C3TECH_DIGITAL_DUO:
13284159d01bSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(mb86a20s_attach,
13294159d01bSMauro Carvalho Chehab 					   &c3tech_duo_mb86a20s_config,
13304159d01bSMauro Carvalho Chehab 					   &dev->i2c_adap[dev->def_i2c_bus]);
13314159d01bSMauro Carvalho Chehab 		if (dvb->fe[0] != NULL)
13324159d01bSMauro Carvalho Chehab 			dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
13334159d01bSMauro Carvalho Chehab 				   &dev->i2c_adap[dev->def_i2c_bus],
13344159d01bSMauro Carvalho Chehab 				   &c3tech_duo_tda18271_config);
13354159d01bSMauro Carvalho Chehab 		break;
13368022f9afSAntti Palosaari 	case EM28174_BOARD_PCTV_460E: {
13378022f9afSAntti Palosaari 		struct i2c_client *client;
13388022f9afSAntti Palosaari 		struct i2c_board_info board_info;
13398022f9afSAntti Palosaari 		struct tda10071_platform_data tda10071_pdata = {};
13408022f9afSAntti Palosaari 		struct a8293_platform_data a8293_pdata = {};
13418022f9afSAntti Palosaari 
13428022f9afSAntti Palosaari 		/* attach demod + tuner combo */
13438022f9afSAntti Palosaari 		tda10071_pdata.clk = 40444000, /* 40.444 MHz */
13448022f9afSAntti Palosaari 		tda10071_pdata.i2c_wr_max = 64,
13458022f9afSAntti Palosaari 		tda10071_pdata.ts_mode = TDA10071_TS_SERIAL,
13468022f9afSAntti Palosaari 		tda10071_pdata.pll_multiplier = 20,
13478022f9afSAntti Palosaari 		tda10071_pdata.tuner_i2c_addr = 0x14,
13488022f9afSAntti Palosaari 		memset(&board_info, 0, sizeof(board_info));
13498022f9afSAntti Palosaari 		strlcpy(board_info.type, "tda10071_cx24118", I2C_NAME_SIZE);
13508022f9afSAntti Palosaari 		board_info.addr = 0x55;
13518022f9afSAntti Palosaari 		board_info.platform_data = &tda10071_pdata;
13528022f9afSAntti Palosaari 		request_module("tda10071");
13538022f9afSAntti Palosaari 		client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
13548022f9afSAntti Palosaari 		if (client == NULL || client->dev.driver == NULL) {
13558022f9afSAntti Palosaari 			result = -ENODEV;
13568022f9afSAntti Palosaari 			goto out_free;
13578022f9afSAntti Palosaari 		}
13588022f9afSAntti Palosaari 		if (!try_module_get(client->dev.driver->owner)) {
13598022f9afSAntti Palosaari 			i2c_unregister_device(client);
13608022f9afSAntti Palosaari 			result = -ENODEV;
13618022f9afSAntti Palosaari 			goto out_free;
13628022f9afSAntti Palosaari 		}
13638022f9afSAntti Palosaari 		dvb->fe[0] = tda10071_pdata.get_dvb_frontend(client);
13648022f9afSAntti Palosaari 		dvb->i2c_client_demod = client;
13650c0d06caSMauro Carvalho Chehab 
13660c0d06caSMauro Carvalho Chehab 		/* attach SEC */
13678022f9afSAntti Palosaari 		a8293_pdata.dvb_frontend = dvb->fe[0];
13688022f9afSAntti Palosaari 		memset(&board_info, 0, sizeof(board_info));
13698022f9afSAntti Palosaari 		strlcpy(board_info.type, "a8293", I2C_NAME_SIZE);
13708022f9afSAntti Palosaari 		board_info.addr = 0x08;
13718022f9afSAntti Palosaari 		board_info.platform_data = &a8293_pdata;
13728022f9afSAntti Palosaari 		request_module("a8293");
13738022f9afSAntti Palosaari 		client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
13748022f9afSAntti Palosaari 		if (client == NULL || client->dev.driver == NULL) {
13758022f9afSAntti Palosaari 			module_put(dvb->i2c_client_demod->dev.driver->owner);
13768022f9afSAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_demod);
13778022f9afSAntti Palosaari 			result = -ENODEV;
13788022f9afSAntti Palosaari 			goto out_free;
13798022f9afSAntti Palosaari 		}
13808022f9afSAntti Palosaari 		if (!try_module_get(client->dev.driver->owner)) {
13818022f9afSAntti Palosaari 			i2c_unregister_device(client);
13828022f9afSAntti Palosaari 			module_put(dvb->i2c_client_demod->dev.driver->owner);
13838022f9afSAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_demod);
13848022f9afSAntti Palosaari 			result = -ENODEV;
13858022f9afSAntti Palosaari 			goto out_free;
13868022f9afSAntti Palosaari 		}
13878022f9afSAntti Palosaari 		dvb->i2c_client_sec = client;
13880c0d06caSMauro Carvalho Chehab 		break;
13898022f9afSAntti Palosaari 	}
13907c1dfdb0SJakob Haufe 	case EM2874_BOARD_DELOCK_61959:
13910c0d06caSMauro Carvalho Chehab 	case EM2874_BOARD_MAXMEDIA_UB425_TC:
13920c0d06caSMauro Carvalho Chehab 		/* attach demodulator */
13930c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
1394c7a45e5bSMauro Carvalho Chehab 				&dev->i2c_adap[dev->def_i2c_bus]);
13950c0d06caSMauro Carvalho Chehab 
13960c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]) {
13970c0d06caSMauro Carvalho Chehab 			/* disable I2C-gate */
13980c0d06caSMauro Carvalho Chehab 			dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
13990c0d06caSMauro Carvalho Chehab 
14000c0d06caSMauro Carvalho Chehab 			/* attach tuner */
1401b6c7abb1SAntti Palosaari 			if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1402b6c7abb1SAntti Palosaari 					&dev->i2c_adap[dev->def_i2c_bus],
1403b6c7abb1SAntti Palosaari 					&em28xx_cxd2820r_tda18271_config)) {
14040c0d06caSMauro Carvalho Chehab 				dvb_frontend_detach(dvb->fe[0]);
14050c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
14060c0d06caSMauro Carvalho Chehab 				goto out_free;
14070c0d06caSMauro Carvalho Chehab 			}
14080c0d06caSMauro Carvalho Chehab 		}
14090c0d06caSMauro Carvalho Chehab 		break;
14100c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_PCTV_510E:
14110c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_PCTV_520E:
14120c0d06caSMauro Carvalho Chehab 		pctv_520e_init(dev);
14130c0d06caSMauro Carvalho Chehab 
14140c0d06caSMauro Carvalho Chehab 		/* attach demodulator */
14150c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
1416c7a45e5bSMauro Carvalho Chehab 				&dev->i2c_adap[dev->def_i2c_bus]);
14170c0d06caSMauro Carvalho Chehab 
14180c0d06caSMauro Carvalho Chehab 		if (dvb->fe[0]) {
14190c0d06caSMauro Carvalho Chehab 			/* attach tuner */
14200c0d06caSMauro Carvalho Chehab 			if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1421c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus],
14220c0d06caSMauro Carvalho Chehab 					&em28xx_cxd2820r_tda18271_config)) {
14230c0d06caSMauro Carvalho Chehab 				dvb_frontend_detach(dvb->fe[0]);
14240c0d06caSMauro Carvalho Chehab 				result = -EINVAL;
14250c0d06caSMauro Carvalho Chehab 				goto out_free;
14260c0d06caSMauro Carvalho Chehab 			}
14270c0d06caSMauro Carvalho Chehab 		}
14280c0d06caSMauro Carvalho Chehab 		break;
14291fe0fbd6SGilles Risch 	case EM2884_BOARD_ELGATO_EYETV_HYBRID_2008:
14300c0d06caSMauro Carvalho Chehab 	case EM2884_BOARD_CINERGY_HTC_STICK:
14310c0d06caSMauro Carvalho Chehab 		terratec_htc_stick_init(dev);
14320c0d06caSMauro Carvalho Chehab 
14330c0d06caSMauro Carvalho Chehab 		/* attach demodulator */
14340c0d06caSMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1435c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
14360c0d06caSMauro Carvalho Chehab 		if (!dvb->fe[0]) {
14370c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
14380c0d06caSMauro Carvalho Chehab 			goto out_free;
14390c0d06caSMauro Carvalho Chehab 		}
14400c0d06caSMauro Carvalho Chehab 
14410c0d06caSMauro Carvalho Chehab 		/* Attach the demodulator. */
14420c0d06caSMauro Carvalho Chehab 		if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1443c7a45e5bSMauro Carvalho Chehab 				&dev->i2c_adap[dev->def_i2c_bus],
14440c0d06caSMauro Carvalho Chehab 				&em28xx_cxd2820r_tda18271_config)) {
14450c0d06caSMauro Carvalho Chehab 			result = -EINVAL;
14460c0d06caSMauro Carvalho Chehab 			goto out_free;
14470c0d06caSMauro Carvalho Chehab 		}
14480c0d06caSMauro Carvalho Chehab 		break;
144989040136SMartin Blumenstingl 	case EM2884_BOARD_TERRATEC_HTC_USB_XS:
145089040136SMartin Blumenstingl 		terratec_htc_usb_xs_init(dev);
145189040136SMartin Blumenstingl 
145289040136SMartin Blumenstingl 		/* attach demodulator */
145389040136SMartin Blumenstingl 		dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1454c7a45e5bSMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
145589040136SMartin Blumenstingl 		if (!dvb->fe[0]) {
145689040136SMartin Blumenstingl 			result = -EINVAL;
145789040136SMartin Blumenstingl 			goto out_free;
145889040136SMartin Blumenstingl 		}
145989040136SMartin Blumenstingl 
146089040136SMartin Blumenstingl 		/* Attach the demodulator. */
146189040136SMartin Blumenstingl 		if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1462c7a45e5bSMauro Carvalho Chehab 				&dev->i2c_adap[dev->def_i2c_bus],
146389040136SMartin Blumenstingl 				&em28xx_cxd2820r_tda18271_config)) {
146489040136SMartin Blumenstingl 			result = -EINVAL;
146589040136SMartin Blumenstingl 			goto out_free;
146689040136SMartin Blumenstingl 		}
146789040136SMartin Blumenstingl 		break;
14686dbea9f0SJean-Francois Thibert 	case EM2874_BOARD_KWORLD_UB435Q_V2:
14696dbea9f0SJean-Francois Thibert 		dvb->fe[0] = dvb_attach(lgdt3305_attach,
14706dbea9f0SJean-Francois Thibert 					&em2874_lgdt3305_dev,
14716dbea9f0SJean-Francois Thibert 					&dev->i2c_adap[dev->def_i2c_bus]);
14726dbea9f0SJean-Francois Thibert 		if (!dvb->fe[0]) {
14736dbea9f0SJean-Francois Thibert 			result = -EINVAL;
14746dbea9f0SJean-Francois Thibert 			goto out_free;
14756dbea9f0SJean-Francois Thibert 		}
14766dbea9f0SJean-Francois Thibert 
14776dbea9f0SJean-Francois Thibert 		/* Attach the demodulator. */
14786dbea9f0SJean-Francois Thibert 		if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
14796dbea9f0SJean-Francois Thibert 				&dev->i2c_adap[dev->def_i2c_bus],
14806dbea9f0SJean-Francois Thibert 				&kworld_ub435q_v2_config)) {
14816dbea9f0SJean-Francois Thibert 			result = -EINVAL;
14826dbea9f0SJean-Francois Thibert 			goto out_free;
14836dbea9f0SJean-Francois Thibert 		}
14846dbea9f0SJean-Francois Thibert 		break;
148502bc1f55SMauro Carvalho Chehab 	case EM2874_BOARD_KWORLD_UB435Q_V3:
1486ac7a24fbSAntti Palosaari 	{
1487ac7a24fbSAntti Palosaari 		struct i2c_client *client;
1488ac7a24fbSAntti Palosaari 		struct i2c_adapter *adapter = &dev->i2c_adap[dev->def_i2c_bus];
1489ac7a24fbSAntti Palosaari 		struct i2c_board_info board_info = {
1490ac7a24fbSAntti Palosaari 			.type = "tda18212",
1491ac7a24fbSAntti Palosaari 			.addr = 0x60,
1492ac7a24fbSAntti Palosaari 			.platform_data = &kworld_ub435q_v3_config,
1493ac7a24fbSAntti Palosaari 		};
1494ac7a24fbSAntti Palosaari 
149502bc1f55SMauro Carvalho Chehab 		dvb->fe[0] = dvb_attach(lgdt3305_attach,
149602bc1f55SMauro Carvalho Chehab 					&em2874_lgdt3305_nogate_dev,
149702bc1f55SMauro Carvalho Chehab 					&dev->i2c_adap[dev->def_i2c_bus]);
149802bc1f55SMauro Carvalho Chehab 		if (!dvb->fe[0]) {
149902bc1f55SMauro Carvalho Chehab 			result = -EINVAL;
150002bc1f55SMauro Carvalho Chehab 			goto out_free;
150102bc1f55SMauro Carvalho Chehab 		}
150202bc1f55SMauro Carvalho Chehab 
1503ac7a24fbSAntti Palosaari 		/* attach tuner */
1504ac7a24fbSAntti Palosaari 		kworld_ub435q_v3_config.fe = dvb->fe[0];
1505ac7a24fbSAntti Palosaari 		request_module("tda18212");
1506ac7a24fbSAntti Palosaari 		client = i2c_new_device(adapter, &board_info);
1507ac7a24fbSAntti Palosaari 		if (client == NULL || client->dev.driver == NULL) {
1508ac7a24fbSAntti Palosaari 			dvb_frontend_detach(dvb->fe[0]);
1509ac7a24fbSAntti Palosaari 			result = -ENODEV;
151002bc1f55SMauro Carvalho Chehab 			goto out_free;
151102bc1f55SMauro Carvalho Chehab 		}
1512ac7a24fbSAntti Palosaari 
1513ac7a24fbSAntti Palosaari 		if (!try_module_get(client->dev.driver->owner)) {
1514ac7a24fbSAntti Palosaari 			i2c_unregister_device(client);
1515ac7a24fbSAntti Palosaari 			dvb_frontend_detach(dvb->fe[0]);
1516ac7a24fbSAntti Palosaari 			result = -ENODEV;
1517ac7a24fbSAntti Palosaari 			goto out_free;
1518ac7a24fbSAntti Palosaari 		}
1519ac7a24fbSAntti Palosaari 
1520ac7a24fbSAntti Palosaari 		dvb->i2c_client_tuner = client;
152102bc1f55SMauro Carvalho Chehab 		break;
1522ac7a24fbSAntti Palosaari 	}
152338b2df95SDevin Heitmueller 	case EM2874_BOARD_PCTV_HD_MINI_80E:
152438b2df95SDevin Heitmueller 		dvb->fe[0] = dvb_attach(drx39xxj_attach, &dev->i2c_adap[dev->def_i2c_bus]);
152538b2df95SDevin Heitmueller 		if (dvb->fe[0] != NULL) {
152638b2df95SDevin Heitmueller 			dvb->fe[0] = dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
152738b2df95SDevin Heitmueller 						&dev->i2c_adap[dev->def_i2c_bus],
152838b2df95SDevin Heitmueller 						&pinnacle_80e_dvb_config);
152938b2df95SDevin Heitmueller 			if (!dvb->fe[0]) {
153038b2df95SDevin Heitmueller 				result = -EINVAL;
153138b2df95SDevin Heitmueller 				goto out_free;
153238b2df95SDevin Heitmueller 			}
153338b2df95SDevin Heitmueller 		}
153438b2df95SDevin Heitmueller 		break;
153576b91be3SAntti Palosaari 	case EM28178_BOARD_PCTV_461E: {
1536425f53aaSAntti Palosaari 		struct i2c_client *client;
153776b91be3SAntti Palosaari 		struct i2c_adapter *i2c_adapter;
153876b91be3SAntti Palosaari 		struct i2c_board_info board_info;
153976b91be3SAntti Palosaari 		struct m88ds3103_platform_data m88ds3103_pdata = {};
154076b91be3SAntti Palosaari 		struct ts2020_config ts2020_config = {};
154176b91be3SAntti Palosaari 		struct a8293_platform_data a8293_pdata = {};
1542ec573362SAntti Palosaari 
1543ec573362SAntti Palosaari 		/* attach demod */
154476b91be3SAntti Palosaari 		m88ds3103_pdata.clk = 27000000;
154576b91be3SAntti Palosaari 		m88ds3103_pdata.i2c_wr_max = 33;
154676b91be3SAntti Palosaari 		m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL;
154776b91be3SAntti Palosaari 		m88ds3103_pdata.ts_clk = 16000;
154876b91be3SAntti Palosaari 		m88ds3103_pdata.ts_clk_pol = 1;
154976b91be3SAntti Palosaari 		m88ds3103_pdata.agc = 0x99;
155076b91be3SAntti Palosaari 		memset(&board_info, 0, sizeof(board_info));
155176b91be3SAntti Palosaari 		strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
155276b91be3SAntti Palosaari 		board_info.addr = 0x68;
155376b91be3SAntti Palosaari 		board_info.platform_data = &m88ds3103_pdata;
155476b91be3SAntti Palosaari 		request_module("m88ds3103");
155576b91be3SAntti Palosaari 		client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
155676b91be3SAntti Palosaari 		if (client == NULL || client->dev.driver == NULL) {
1557ec573362SAntti Palosaari 			result = -ENODEV;
1558ec573362SAntti Palosaari 			goto out_free;
1559ec573362SAntti Palosaari 		}
156076b91be3SAntti Palosaari 		if (!try_module_get(client->dev.driver->owner)) {
156176b91be3SAntti Palosaari 			i2c_unregister_device(client);
156276b91be3SAntti Palosaari 			result = -ENODEV;
156376b91be3SAntti Palosaari 			goto out_free;
156476b91be3SAntti Palosaari 		}
156576b91be3SAntti Palosaari 		dvb->fe[0] = m88ds3103_pdata.get_dvb_frontend(client);
156676b91be3SAntti Palosaari 		i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
156776b91be3SAntti Palosaari 		dvb->i2c_client_demod = client;
1568ec573362SAntti Palosaari 
1569ec573362SAntti Palosaari 		/* attach tuner */
157083c1b6ceSAntti Palosaari 		ts2020_config.fe = dvb->fe[0];
157176b91be3SAntti Palosaari 		memset(&board_info, 0, sizeof(board_info));
157276b91be3SAntti Palosaari 		strlcpy(board_info.type, "ts2022", I2C_NAME_SIZE);
157376b91be3SAntti Palosaari 		board_info.addr = 0x60;
157476b91be3SAntti Palosaari 		board_info.platform_data = &ts2020_config;
157583c1b6ceSAntti Palosaari 		request_module("ts2020");
157676b91be3SAntti Palosaari 		client = i2c_new_device(i2c_adapter, &board_info);
1577425f53aaSAntti Palosaari 		if (client == NULL || client->dev.driver == NULL) {
157876b91be3SAntti Palosaari 			module_put(dvb->i2c_client_demod->dev.driver->owner);
157976b91be3SAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_demod);
1580425f53aaSAntti Palosaari 			result = -ENODEV;
1581425f53aaSAntti Palosaari 			goto out_free;
1582425f53aaSAntti Palosaari 		}
1583425f53aaSAntti Palosaari 		if (!try_module_get(client->dev.driver->owner)) {
1584425f53aaSAntti Palosaari 			i2c_unregister_device(client);
158576b91be3SAntti Palosaari 			module_put(dvb->i2c_client_demod->dev.driver->owner);
158676b91be3SAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_demod);
1587425f53aaSAntti Palosaari 			result = -ENODEV;
1588425f53aaSAntti Palosaari 			goto out_free;
1589425f53aaSAntti Palosaari 		}
159076b91be3SAntti Palosaari 		dvb->i2c_client_tuner = client;
1591ec573362SAntti Palosaari 		/* delegate signal strength measurement to tuner */
1592ec573362SAntti Palosaari 		dvb->fe[0]->ops.read_signal_strength =
1593ec573362SAntti Palosaari 				dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1594ec573362SAntti Palosaari 
1595ec573362SAntti Palosaari 		/* attach SEC */
159676b91be3SAntti Palosaari 		a8293_pdata.dvb_frontend = dvb->fe[0];
159776b91be3SAntti Palosaari 		memset(&board_info, 0, sizeof(board_info));
159876b91be3SAntti Palosaari 		strlcpy(board_info.type, "a8293", I2C_NAME_SIZE);
159976b91be3SAntti Palosaari 		board_info.addr = 0x08;
160076b91be3SAntti Palosaari 		board_info.platform_data = &a8293_pdata;
160176b91be3SAntti Palosaari 		request_module("a8293");
160276b91be3SAntti Palosaari 		client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
160376b91be3SAntti Palosaari 		if (client == NULL || client->dev.driver == NULL) {
160476b91be3SAntti Palosaari 			module_put(dvb->i2c_client_tuner->dev.driver->owner);
160576b91be3SAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_tuner);
160676b91be3SAntti Palosaari 			module_put(dvb->i2c_client_demod->dev.driver->owner);
160776b91be3SAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_demod);
1608ec573362SAntti Palosaari 			result = -ENODEV;
1609ec573362SAntti Palosaari 			goto out_free;
1610ec573362SAntti Palosaari 		}
161176b91be3SAntti Palosaari 		if (!try_module_get(client->dev.driver->owner)) {
161276b91be3SAntti Palosaari 			i2c_unregister_device(client);
161376b91be3SAntti Palosaari 			module_put(dvb->i2c_client_tuner->dev.driver->owner);
161476b91be3SAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_tuner);
161576b91be3SAntti Palosaari 			module_put(dvb->i2c_client_demod->dev.driver->owner);
161676b91be3SAntti Palosaari 			i2c_unregister_device(dvb->i2c_client_demod);
161776b91be3SAntti Palosaari 			result = -ENODEV;
161876b91be3SAntti Palosaari 			goto out_free;
1619ec573362SAntti Palosaari 		}
162076b91be3SAntti Palosaari 		dvb->i2c_client_sec = client;
1621ec573362SAntti Palosaari 		break;
162276b91be3SAntti Palosaari 	}
162319229240SAntti Palosaari 	case EM28178_BOARD_PCTV_292E:
162419229240SAntti Palosaari 		{
162519229240SAntti Palosaari 			struct i2c_adapter *adapter;
162619229240SAntti Palosaari 			struct i2c_client *client;
162719229240SAntti Palosaari 			struct i2c_board_info info;
162819229240SAntti Palosaari 			struct si2168_config si2168_config;
162919229240SAntti Palosaari 			struct si2157_config si2157_config;
163019229240SAntti Palosaari 
163119229240SAntti Palosaari 			/* attach demod */
1632bf9025f3SOlli Salonen 			memset(&si2168_config, 0, sizeof(si2168_config));
163319229240SAntti Palosaari 			si2168_config.i2c_adapter = &adapter;
163419229240SAntti Palosaari 			si2168_config.fe = &dvb->fe[0];
16356fd2f44aSOlli Salonen 			si2168_config.ts_mode = SI2168_TS_PARALLEL;
163619229240SAntti Palosaari 			memset(&info, 0, sizeof(struct i2c_board_info));
163719229240SAntti Palosaari 			strlcpy(info.type, "si2168", I2C_NAME_SIZE);
163819229240SAntti Palosaari 			info.addr = 0x64;
163919229240SAntti Palosaari 			info.platform_data = &si2168_config;
164019229240SAntti Palosaari 			request_module(info.type);
164119229240SAntti Palosaari 			client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
164219229240SAntti Palosaari 			if (client == NULL || client->dev.driver == NULL) {
164319229240SAntti Palosaari 				result = -ENODEV;
164419229240SAntti Palosaari 				goto out_free;
164519229240SAntti Palosaari 			}
164619229240SAntti Palosaari 
164719229240SAntti Palosaari 			if (!try_module_get(client->dev.driver->owner)) {
164819229240SAntti Palosaari 				i2c_unregister_device(client);
164919229240SAntti Palosaari 				result = -ENODEV;
165019229240SAntti Palosaari 				goto out_free;
165119229240SAntti Palosaari 			}
165219229240SAntti Palosaari 
165319229240SAntti Palosaari 			dvb->i2c_client_demod = client;
165419229240SAntti Palosaari 
165519229240SAntti Palosaari 			/* attach tuner */
1656c3b513bdSMatthias Schwarzott 			memset(&si2157_config, 0, sizeof(si2157_config));
165719229240SAntti Palosaari 			si2157_config.fe = dvb->fe[0];
1658ee3c3e46SOlli Salonen 			si2157_config.if_port = 1;
165919229240SAntti Palosaari 			memset(&info, 0, sizeof(struct i2c_board_info));
166019229240SAntti Palosaari 			strlcpy(info.type, "si2157", I2C_NAME_SIZE);
166119229240SAntti Palosaari 			info.addr = 0x60;
166219229240SAntti Palosaari 			info.platform_data = &si2157_config;
166319229240SAntti Palosaari 			request_module(info.type);
166419229240SAntti Palosaari 			client = i2c_new_device(adapter, &info);
166519229240SAntti Palosaari 			if (client == NULL || client->dev.driver == NULL) {
166619229240SAntti Palosaari 				module_put(dvb->i2c_client_demod->dev.driver->owner);
166719229240SAntti Palosaari 				i2c_unregister_device(dvb->i2c_client_demod);
166819229240SAntti Palosaari 				result = -ENODEV;
166919229240SAntti Palosaari 				goto out_free;
167019229240SAntti Palosaari 			}
167119229240SAntti Palosaari 
167219229240SAntti Palosaari 			if (!try_module_get(client->dev.driver->owner)) {
167319229240SAntti Palosaari 				i2c_unregister_device(client);
167419229240SAntti Palosaari 				module_put(dvb->i2c_client_demod->dev.driver->owner);
167519229240SAntti Palosaari 				i2c_unregister_device(dvb->i2c_client_demod);
167619229240SAntti Palosaari 				result = -ENODEV;
167719229240SAntti Palosaari 				goto out_free;
167819229240SAntti Palosaari 			}
167919229240SAntti Palosaari 
168019229240SAntti Palosaari 			dvb->i2c_client_tuner = client;
1681ffb9948eSAntti Palosaari 			dvb->fe[0]->ops.set_lna = em28xx_pctv_292e_set_lna;
168219229240SAntti Palosaari 		}
168319229240SAntti Palosaari 		break;
1684fc30dd76SOlli Salonen 	case EM28178_BOARD_TERRATEC_T2_STICK_HD:
1685fc30dd76SOlli Salonen 		{
1686fc30dd76SOlli Salonen 			struct i2c_adapter *adapter;
1687fc30dd76SOlli Salonen 			struct i2c_client *client;
1688fc30dd76SOlli Salonen 			struct i2c_board_info info;
1689fc30dd76SOlli Salonen 			struct si2168_config si2168_config;
1690fc30dd76SOlli Salonen 			struct si2157_config si2157_config;
1691fc30dd76SOlli Salonen 
1692fc30dd76SOlli Salonen 			/* attach demod */
1693fc30dd76SOlli Salonen 			memset(&si2168_config, 0, sizeof(si2168_config));
1694fc30dd76SOlli Salonen 			si2168_config.i2c_adapter = &adapter;
1695fc30dd76SOlli Salonen 			si2168_config.fe = &dvb->fe[0];
1696fc30dd76SOlli Salonen 			si2168_config.ts_mode = SI2168_TS_PARALLEL;
1697fc30dd76SOlli Salonen 			memset(&info, 0, sizeof(struct i2c_board_info));
1698fc30dd76SOlli Salonen 			strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1699fc30dd76SOlli Salonen 			info.addr = 0x64;
1700fc30dd76SOlli Salonen 			info.platform_data = &si2168_config;
1701fc30dd76SOlli Salonen 			request_module(info.type);
1702fc30dd76SOlli Salonen 			client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
1703fc30dd76SOlli Salonen 			if (client == NULL || client->dev.driver == NULL) {
1704fc30dd76SOlli Salonen 				result = -ENODEV;
1705fc30dd76SOlli Salonen 				goto out_free;
1706fc30dd76SOlli Salonen 			}
1707fc30dd76SOlli Salonen 
1708fc30dd76SOlli Salonen 			if (!try_module_get(client->dev.driver->owner)) {
1709fc30dd76SOlli Salonen 				i2c_unregister_device(client);
1710fc30dd76SOlli Salonen 				result = -ENODEV;
1711fc30dd76SOlli Salonen 				goto out_free;
1712fc30dd76SOlli Salonen 			}
1713fc30dd76SOlli Salonen 
1714fc30dd76SOlli Salonen 			dvb->i2c_client_demod = client;
1715fc30dd76SOlli Salonen 
1716fc30dd76SOlli Salonen 			/* attach tuner */
1717fc30dd76SOlli Salonen 			memset(&si2157_config, 0, sizeof(si2157_config));
1718fc30dd76SOlli Salonen 			si2157_config.fe = dvb->fe[0];
1719ee3c3e46SOlli Salonen 			si2157_config.if_port = 0;
1720fc30dd76SOlli Salonen 			memset(&info, 0, sizeof(struct i2c_board_info));
1721fc30dd76SOlli Salonen 			strlcpy(info.type, "si2146", I2C_NAME_SIZE);
1722fc30dd76SOlli Salonen 			info.addr = 0x60;
1723fc30dd76SOlli Salonen 			info.platform_data = &si2157_config;
1724fc30dd76SOlli Salonen 			request_module("si2157");
1725fc30dd76SOlli Salonen 			client = i2c_new_device(adapter, &info);
1726fc30dd76SOlli Salonen 			if (client == NULL || client->dev.driver == NULL) {
1727fc30dd76SOlli Salonen 				module_put(dvb->i2c_client_demod->dev.driver->owner);
1728fc30dd76SOlli Salonen 				i2c_unregister_device(dvb->i2c_client_demod);
1729fc30dd76SOlli Salonen 				result = -ENODEV;
1730fc30dd76SOlli Salonen 				goto out_free;
1731fc30dd76SOlli Salonen 			}
1732fc30dd76SOlli Salonen 
1733fc30dd76SOlli Salonen 			if (!try_module_get(client->dev.driver->owner)) {
1734fc30dd76SOlli Salonen 				i2c_unregister_device(client);
1735fc30dd76SOlli Salonen 				module_put(dvb->i2c_client_demod->dev.driver->owner);
1736fc30dd76SOlli Salonen 				i2c_unregister_device(dvb->i2c_client_demod);
1737fc30dd76SOlli Salonen 				result = -ENODEV;
1738fc30dd76SOlli Salonen 				goto out_free;
1739fc30dd76SOlli Salonen 			}
1740fc30dd76SOlli Salonen 
1741fc30dd76SOlli Salonen 			dvb->i2c_client_tuner = client;
1742fc30dd76SOlli Salonen 		}
1743fc30dd76SOlli Salonen 		break;
17440c0d06caSMauro Carvalho Chehab 	default:
17450c0d06caSMauro Carvalho Chehab 		em28xx_errdev("/2: The frontend of your DVB/ATSC card"
17460c0d06caSMauro Carvalho Chehab 				" isn't supported yet\n");
17470c0d06caSMauro Carvalho Chehab 		break;
17480c0d06caSMauro Carvalho Chehab 	}
17490c0d06caSMauro Carvalho Chehab 	if (NULL == dvb->fe[0]) {
17500c0d06caSMauro Carvalho Chehab 		em28xx_errdev("/2: frontend initialization failed\n");
17510c0d06caSMauro Carvalho Chehab 		result = -EINVAL;
17520c0d06caSMauro Carvalho Chehab 		goto out_free;
17530c0d06caSMauro Carvalho Chehab 	}
17540c0d06caSMauro Carvalho Chehab 	/* define general-purpose callback pointer */
17550c0d06caSMauro Carvalho Chehab 	dvb->fe[0]->callback = em28xx_tuner_callback;
17560c0d06caSMauro Carvalho Chehab 	if (dvb->fe[1])
17570c0d06caSMauro Carvalho Chehab 		dvb->fe[1]->callback = em28xx_tuner_callback;
17580c0d06caSMauro Carvalho Chehab 
17590c0d06caSMauro Carvalho Chehab 	/* register everything */
17600c0d06caSMauro Carvalho Chehab 	result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
17610c0d06caSMauro Carvalho Chehab 
17620c0d06caSMauro Carvalho Chehab 	if (result < 0)
17630c0d06caSMauro Carvalho Chehab 		goto out_free;
17640c0d06caSMauro Carvalho Chehab 
17659634614fSMauro Carvalho Chehab 	em28xx_info("DVB extension successfully initialized\n");
176647677e51SMauro Carvalho Chehab 
176747677e51SMauro Carvalho Chehab 	kref_get(&dev->ref);
176847677e51SMauro Carvalho Chehab 
17690c0d06caSMauro Carvalho Chehab ret:
17700c0d06caSMauro Carvalho Chehab 	em28xx_set_mode(dev, EM28XX_SUSPEND);
17710c0d06caSMauro Carvalho Chehab 	mutex_unlock(&dev->lock);
17720c0d06caSMauro Carvalho Chehab 	return result;
17730c0d06caSMauro Carvalho Chehab 
17740c0d06caSMauro Carvalho Chehab out_free:
17750c0d06caSMauro Carvalho Chehab 	kfree(dvb);
17760c0d06caSMauro Carvalho Chehab 	dev->dvb = NULL;
17770c0d06caSMauro Carvalho Chehab 	goto ret;
17780c0d06caSMauro Carvalho Chehab }
17790c0d06caSMauro Carvalho Chehab 
17800c0d06caSMauro Carvalho Chehab static inline void prevent_sleep(struct dvb_frontend_ops *ops)
17810c0d06caSMauro Carvalho Chehab {
17820c0d06caSMauro Carvalho Chehab 	ops->set_voltage = NULL;
17830c0d06caSMauro Carvalho Chehab 	ops->sleep = NULL;
17840c0d06caSMauro Carvalho Chehab 	ops->tuner_ops.sleep = NULL;
17850c0d06caSMauro Carvalho Chehab }
17860c0d06caSMauro Carvalho Chehab 
17870c0d06caSMauro Carvalho Chehab static int em28xx_dvb_fini(struct em28xx *dev)
17880c0d06caSMauro Carvalho Chehab {
1789b45e34f2SMauro Carvalho Chehab 	struct em28xx_dvb *dvb;
1790b45e34f2SMauro Carvalho Chehab 	struct i2c_client *client;
1791b45e34f2SMauro Carvalho Chehab 
1792822b8deaSMauro Carvalho Chehab 	if (dev->is_audio_only) {
1793822b8deaSMauro Carvalho Chehab 		/* Shouldn't initialize IR for this interface */
1794822b8deaSMauro Carvalho Chehab 		return 0;
1795822b8deaSMauro Carvalho Chehab 	}
1796822b8deaSMauro Carvalho Chehab 
17970c0d06caSMauro Carvalho Chehab 	if (!dev->board.has_dvb) {
17980c0d06caSMauro Carvalho Chehab 		/* This device does not support the extension */
17990c0d06caSMauro Carvalho Chehab 		return 0;
18000c0d06caSMauro Carvalho Chehab 	}
18010c0d06caSMauro Carvalho Chehab 
1802b45e34f2SMauro Carvalho Chehab 	if (!dev->dvb)
1803b45e34f2SMauro Carvalho Chehab 		return 0;
1804b45e34f2SMauro Carvalho Chehab 
18050418ca60SRussell King 	em28xx_info("Closing DVB extension\n");
1806aa929ad7SMauro Carvalho Chehab 
1807b45e34f2SMauro Carvalho Chehab 	dvb = dev->dvb;
18080c0d06caSMauro Carvalho Chehab 
180927ba0dacSFrank Schaefer 	em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
181027ba0dacSFrank Schaefer 
18112665c299SFrank Schaefer 	if (dev->disconnected) {
18120c0d06caSMauro Carvalho Chehab 		/* We cannot tell the device to sleep
18130c0d06caSMauro Carvalho Chehab 		 * once it has been unplugged. */
1814f68e35afSShuah Khan 		if (dvb->fe[0]) {
18150c0d06caSMauro Carvalho Chehab 			prevent_sleep(&dvb->fe[0]->ops);
1816f68e35afSShuah Khan 			dvb->fe[0]->exit = DVB_FE_DEVICE_REMOVED;
1817f68e35afSShuah Khan 		}
1818f68e35afSShuah Khan 		if (dvb->fe[1]) {
18190c0d06caSMauro Carvalho Chehab 			prevent_sleep(&dvb->fe[1]->ops);
1820f68e35afSShuah Khan 			dvb->fe[1]->exit = DVB_FE_DEVICE_REMOVED;
1821f68e35afSShuah Khan 		}
18220c0d06caSMauro Carvalho Chehab 	}
18230c0d06caSMauro Carvalho Chehab 
18247098f582SAntti Palosaari 	/* remove I2C SEC */
18257098f582SAntti Palosaari 	client = dvb->i2c_client_sec;
18267098f582SAntti Palosaari 	if (client) {
18277098f582SAntti Palosaari 		module_put(client->dev.driver->owner);
18287098f582SAntti Palosaari 		i2c_unregister_device(client);
18297098f582SAntti Palosaari 	}
18307098f582SAntti Palosaari 
1831425f53aaSAntti Palosaari 	/* remove I2C tuner */
18327098f582SAntti Palosaari 	client = dvb->i2c_client_tuner;
1833425f53aaSAntti Palosaari 	if (client) {
1834425f53aaSAntti Palosaari 		module_put(client->dev.driver->owner);
1835425f53aaSAntti Palosaari 		i2c_unregister_device(client);
1836425f53aaSAntti Palosaari 	}
1837425f53aaSAntti Palosaari 
183819229240SAntti Palosaari 	/* remove I2C demod */
183919229240SAntti Palosaari 	client = dvb->i2c_client_demod;
184019229240SAntti Palosaari 	if (client) {
184119229240SAntti Palosaari 		module_put(client->dev.driver->owner);
184219229240SAntti Palosaari 		i2c_unregister_device(client);
184319229240SAntti Palosaari 	}
184419229240SAntti Palosaari 
18450c0d06caSMauro Carvalho Chehab 	em28xx_unregister_dvb(dvb);
18460c0d06caSMauro Carvalho Chehab 	kfree(dvb);
18470c0d06caSMauro Carvalho Chehab 	dev->dvb = NULL;
184847677e51SMauro Carvalho Chehab 	kref_put(&dev->ref, em28xx_free_device);
18490c0d06caSMauro Carvalho Chehab 
18500c0d06caSMauro Carvalho Chehab 	return 0;
18510c0d06caSMauro Carvalho Chehab }
18520c0d06caSMauro Carvalho Chehab 
1853ca2b46daSShuah Khan static int em28xx_dvb_suspend(struct em28xx *dev)
1854ca2b46daSShuah Khan {
1855ca2b46daSShuah Khan 	int ret = 0;
1856ca2b46daSShuah Khan 
1857ca2b46daSShuah Khan 	if (dev->is_audio_only)
1858ca2b46daSShuah Khan 		return 0;
1859ca2b46daSShuah Khan 
1860ca2b46daSShuah Khan 	if (!dev->board.has_dvb)
1861ca2b46daSShuah Khan 		return 0;
1862ca2b46daSShuah Khan 
1863a084c57fSRussell King 	em28xx_info("Suspending DVB extension\n");
1864ca2b46daSShuah Khan 	if (dev->dvb) {
1865ca2b46daSShuah Khan 		struct em28xx_dvb *dvb = dev->dvb;
1866ca2b46daSShuah Khan 
1867ca2b46daSShuah Khan 		if (dvb->fe[0]) {
1868ca2b46daSShuah Khan 			ret = dvb_frontend_suspend(dvb->fe[0]);
1869a084c57fSRussell King 			em28xx_info("fe0 suspend %d\n", ret);
1870ca2b46daSShuah Khan 		}
1871ca2b46daSShuah Khan 		if (dvb->fe[1]) {
1872ca2b46daSShuah Khan 			dvb_frontend_suspend(dvb->fe[1]);
1873a084c57fSRussell King 			em28xx_info("fe1 suspend %d\n", ret);
1874ca2b46daSShuah Khan 		}
1875ca2b46daSShuah Khan 	}
1876ca2b46daSShuah Khan 
1877ca2b46daSShuah Khan 	return 0;
1878ca2b46daSShuah Khan }
1879ca2b46daSShuah Khan 
1880ca2b46daSShuah Khan static int em28xx_dvb_resume(struct em28xx *dev)
1881ca2b46daSShuah Khan {
1882ca2b46daSShuah Khan 	int ret = 0;
1883ca2b46daSShuah Khan 
1884ca2b46daSShuah Khan 	if (dev->is_audio_only)
1885ca2b46daSShuah Khan 		return 0;
1886ca2b46daSShuah Khan 
1887ca2b46daSShuah Khan 	if (!dev->board.has_dvb)
1888ca2b46daSShuah Khan 		return 0;
1889ca2b46daSShuah Khan 
1890a084c57fSRussell King 	em28xx_info("Resuming DVB extension\n");
1891ca2b46daSShuah Khan 	if (dev->dvb) {
1892ca2b46daSShuah Khan 		struct em28xx_dvb *dvb = dev->dvb;
1893ca2b46daSShuah Khan 
1894ca2b46daSShuah Khan 		if (dvb->fe[0]) {
1895ca2b46daSShuah Khan 			ret = dvb_frontend_resume(dvb->fe[0]);
1896a084c57fSRussell King 			em28xx_info("fe0 resume %d\n", ret);
1897ca2b46daSShuah Khan 		}
1898ca2b46daSShuah Khan 
1899ca2b46daSShuah Khan 		if (dvb->fe[1]) {
1900ca2b46daSShuah Khan 			ret = dvb_frontend_resume(dvb->fe[1]);
1901a084c57fSRussell King 			em28xx_info("fe1 resume %d\n", ret);
1902ca2b46daSShuah Khan 		}
1903ca2b46daSShuah Khan 	}
1904ca2b46daSShuah Khan 
1905ca2b46daSShuah Khan 	return 0;
1906ca2b46daSShuah Khan }
1907ca2b46daSShuah Khan 
19080c0d06caSMauro Carvalho Chehab static struct em28xx_ops dvb_ops = {
19090c0d06caSMauro Carvalho Chehab 	.id   = EM28XX_DVB,
19100c0d06caSMauro Carvalho Chehab 	.name = "Em28xx dvb Extension",
19110c0d06caSMauro Carvalho Chehab 	.init = em28xx_dvb_init,
19120c0d06caSMauro Carvalho Chehab 	.fini = em28xx_dvb_fini,
1913ca2b46daSShuah Khan 	.suspend = em28xx_dvb_suspend,
1914ca2b46daSShuah Khan 	.resume = em28xx_dvb_resume,
19150c0d06caSMauro Carvalho Chehab };
19160c0d06caSMauro Carvalho Chehab 
19170c0d06caSMauro Carvalho Chehab static int __init em28xx_dvb_register(void)
19180c0d06caSMauro Carvalho Chehab {
19190c0d06caSMauro Carvalho Chehab 	return em28xx_register_extension(&dvb_ops);
19200c0d06caSMauro Carvalho Chehab }
19210c0d06caSMauro Carvalho Chehab 
19220c0d06caSMauro Carvalho Chehab static void __exit em28xx_dvb_unregister(void)
19230c0d06caSMauro Carvalho Chehab {
19240c0d06caSMauro Carvalho Chehab 	em28xx_unregister_extension(&dvb_ops);
19250c0d06caSMauro Carvalho Chehab }
19260c0d06caSMauro Carvalho Chehab 
19270c0d06caSMauro Carvalho Chehab module_init(em28xx_dvb_register);
19280c0d06caSMauro Carvalho Chehab module_exit(em28xx_dvb_unregister);
1929