1f22e9e71SMauro Carvalho Chehab // SPDX-License-Identifier: GPL-2.0 2f22e9e71SMauro Carvalho Chehab // 3f22e9e71SMauro Carvalho Chehab // DVB device driver for em28xx 4f22e9e71SMauro Carvalho Chehab // 5f22e9e71SMauro Carvalho Chehab // (c) 2008-2011 Mauro Carvalho Chehab <mchehab@infradead.org> 6f22e9e71SMauro Carvalho Chehab // 7f22e9e71SMauro Carvalho Chehab // (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com> 8f22e9e71SMauro Carvalho Chehab // - Fixes for the driver to properly work with HVR-950 9f22e9e71SMauro Carvalho Chehab // - Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick 10f22e9e71SMauro Carvalho Chehab // - Fixes for the driver to properly work with AMD ATI TV Wonder HD 600 11f22e9e71SMauro Carvalho Chehab // 12f22e9e71SMauro Carvalho Chehab // (c) 2008 Aidan Thornton <makosoft@googlemail.com> 13f22e9e71SMauro Carvalho Chehab // 14f22e9e71SMauro Carvalho Chehab // (c) 2012 Frank Schäfer <fschaefer.oss@googlemail.com> 15f22e9e71SMauro Carvalho Chehab // 16f22e9e71SMauro Carvalho Chehab // Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by: 17f22e9e71SMauro Carvalho Chehab // (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au> 18f22e9e71SMauro Carvalho Chehab // (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 19f22e9e71SMauro Carvalho Chehab // 20f22e9e71SMauro Carvalho Chehab // This program is free software; you can redistribute it and/or modify 21f22e9e71SMauro Carvalho Chehab // it under the terms of the GNU General Public License as published by 22f22e9e71SMauro Carvalho Chehab // the Free Software Foundation version 2 of the License. 230c0d06caSMauro Carvalho Chehab 248314d402SMauro Carvalho Chehab #include "em28xx.h" 258314d402SMauro Carvalho Chehab 260c0d06caSMauro Carvalho Chehab #include <linux/kernel.h> 270c0d06caSMauro Carvalho Chehab #include <linux/slab.h> 280c0d06caSMauro Carvalho Chehab #include <linux/usb.h> 290c0d06caSMauro Carvalho Chehab 300c0d06caSMauro Carvalho Chehab #include <media/v4l2-common.h> 31fada1935SMauro Carvalho Chehab #include <media/dvb_demux.h> 32fada1935SMauro Carvalho Chehab #include <media/dvb_net.h> 33fada1935SMauro Carvalho Chehab #include <media/dmxdev.h> 340c0d06caSMauro Carvalho Chehab #include <media/tuner.h> 350c0d06caSMauro Carvalho Chehab #include "tuner-simple.h" 361e8f31f3SAntti Palosaari #include <linux/gpio.h> 370c0d06caSMauro Carvalho Chehab 380c0d06caSMauro Carvalho Chehab #include "lgdt330x.h" 390c0d06caSMauro Carvalho Chehab #include "lgdt3305.h" 401586342eSKevin Cheng #include "lgdt3306a.h" 410c0d06caSMauro Carvalho Chehab #include "zl10353.h" 420c0d06caSMauro Carvalho Chehab #include "s5h1409.h" 438c47311dSAlberto Mardegan #include "mt2060.h" 440c0d06caSMauro Carvalho Chehab #include "mt352.h" 450c0d06caSMauro Carvalho Chehab #include "mt352_priv.h" /* FIXME */ 460c0d06caSMauro Carvalho Chehab #include "tda1002x.h" 4738b2df95SDevin Heitmueller #include "drx39xyj/drx39xxj.h" 480c0d06caSMauro Carvalho Chehab #include "tda18271.h" 490c0d06caSMauro Carvalho Chehab #include "s921.h" 500c0d06caSMauro Carvalho Chehab #include "drxd.h" 510c0d06caSMauro Carvalho Chehab #include "cxd2820r.h" 520c0d06caSMauro Carvalho Chehab #include "tda18271c2dd.h" 530c0d06caSMauro Carvalho Chehab #include "drxk.h" 540c0d06caSMauro Carvalho Chehab #include "tda10071.h" 5502bc1f55SMauro Carvalho Chehab #include "tda18212.h" 560c0d06caSMauro Carvalho Chehab #include "a8293.h" 570c0d06caSMauro Carvalho Chehab #include "qt1010.h" 584159d01bSMauro Carvalho Chehab #include "mb86a20s.h" 59ec573362SAntti Palosaari #include "m88ds3103.h" 6083c1b6ceSAntti Palosaari #include "ts2020.h" 6119229240SAntti Palosaari #include "si2168.h" 6219229240SAntti Palosaari #include "si2157.h" 63ab4d1452SSatoshi Nagahama #include "tc90522.h" 64ab4d1452SSatoshi Nagahama #include "qm1d1c0042.h" 650c0d06caSMauro Carvalho Chehab 660c0d06caSMauro Carvalho Chehab MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); 67f22e9e71SMauro Carvalho Chehab MODULE_LICENSE("GPL v2"); 68d8992b09SMauro Carvalho Chehab MODULE_DESCRIPTION(DRIVER_DESC " - digital TV interface"); 69d8992b09SMauro Carvalho Chehab MODULE_VERSION(EM28XX_VERSION); 70d8992b09SMauro Carvalho Chehab 710c0d06caSMauro Carvalho Chehab static unsigned int debug; 720c0d06caSMauro Carvalho Chehab module_param(debug, int, 0644); 730c0d06caSMauro Carvalho Chehab MODULE_PARM_DESC(debug, "enable debug messages [dvb]"); 740c0d06caSMauro Carvalho Chehab 750c0d06caSMauro Carvalho Chehab DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 760c0d06caSMauro Carvalho Chehab 770c0d06caSMauro Carvalho Chehab #define dprintk(level, fmt, arg...) do { \ 780c0d06caSMauro Carvalho Chehab if (debug >= level) \ 7929b05e22SMauro Carvalho Chehab dev_printk(KERN_DEBUG, &dev->intf->dev, \ 80ce8591ffSMauro Carvalho Chehab "dvb: " fmt, ## arg); \ 810c0d06caSMauro Carvalho Chehab } while (0) 820c0d06caSMauro Carvalho Chehab 830c0d06caSMauro Carvalho Chehab struct em28xx_dvb { 840c0d06caSMauro Carvalho Chehab struct dvb_frontend *fe[2]; 850c0d06caSMauro Carvalho Chehab 860c0d06caSMauro Carvalho Chehab /* feed count management */ 870c0d06caSMauro Carvalho Chehab struct mutex lock; 880c0d06caSMauro Carvalho Chehab int nfeeds; 890c0d06caSMauro Carvalho Chehab 900c0d06caSMauro Carvalho Chehab /* general boilerplate stuff */ 910c0d06caSMauro Carvalho Chehab struct dvb_adapter adapter; 920c0d06caSMauro Carvalho Chehab struct dvb_demux demux; 930c0d06caSMauro Carvalho Chehab struct dmxdev dmxdev; 940c0d06caSMauro Carvalho Chehab struct dmx_frontend fe_hw; 950c0d06caSMauro Carvalho Chehab struct dmx_frontend fe_mem; 960c0d06caSMauro Carvalho Chehab struct dvb_net net; 970c0d06caSMauro Carvalho Chehab 980c0d06caSMauro Carvalho Chehab /* Due to DRX-K - probably need changes */ 99fe8d54f0SMauro Carvalho Chehab int (*gate_ctrl)(struct dvb_frontend *fe, int gate); 1000c0d06caSMauro Carvalho Chehab struct semaphore pll_mutex; 1010c0d06caSMauro Carvalho Chehab bool dont_attach_fe1; 10213a5336eSAntti Palosaari int lna_gpio; 10319229240SAntti Palosaari struct i2c_client *i2c_client_demod; 104eafa2ad6SAntti Palosaari struct i2c_client *i2c_client_tuner; 1057098f582SAntti Palosaari struct i2c_client *i2c_client_sec; 1060c0d06caSMauro Carvalho Chehab }; 1070c0d06caSMauro Carvalho Chehab 1080c0d06caSMauro Carvalho Chehab static inline void print_err_status(struct em28xx *dev, 1090c0d06caSMauro Carvalho Chehab int packet, int status) 1100c0d06caSMauro Carvalho Chehab { 1110c0d06caSMauro Carvalho Chehab char *errmsg = "Unknown"; 1120c0d06caSMauro Carvalho Chehab 1130c0d06caSMauro Carvalho Chehab switch (status) { 1140c0d06caSMauro Carvalho Chehab case -ENOENT: 115b436e26eSColin Ian King errmsg = "unlinked synchronously"; 1160c0d06caSMauro Carvalho Chehab break; 1170c0d06caSMauro Carvalho Chehab case -ECONNRESET: 118b436e26eSColin Ian King errmsg = "unlinked asynchronously"; 1190c0d06caSMauro Carvalho Chehab break; 1200c0d06caSMauro Carvalho Chehab case -ENOSR: 1210c0d06caSMauro Carvalho Chehab errmsg = "Buffer error (overrun)"; 1220c0d06caSMauro Carvalho Chehab break; 1230c0d06caSMauro Carvalho Chehab case -EPIPE: 1240c0d06caSMauro Carvalho Chehab errmsg = "Stalled (device not responding)"; 1250c0d06caSMauro Carvalho Chehab break; 1260c0d06caSMauro Carvalho Chehab case -EOVERFLOW: 1270c0d06caSMauro Carvalho Chehab errmsg = "Babble (bad cable?)"; 1280c0d06caSMauro Carvalho Chehab break; 1290c0d06caSMauro Carvalho Chehab case -EPROTO: 1300c0d06caSMauro Carvalho Chehab errmsg = "Bit-stuff error (bad cable?)"; 1310c0d06caSMauro Carvalho Chehab break; 1320c0d06caSMauro Carvalho Chehab case -EILSEQ: 1330c0d06caSMauro Carvalho Chehab errmsg = "CRC/Timeout (could be anything)"; 1340c0d06caSMauro Carvalho Chehab break; 1350c0d06caSMauro Carvalho Chehab case -ETIME: 1360c0d06caSMauro Carvalho Chehab errmsg = "Device does not respond"; 1370c0d06caSMauro Carvalho Chehab break; 1380c0d06caSMauro Carvalho Chehab } 1390c0d06caSMauro Carvalho Chehab if (packet < 0) { 1400c0d06caSMauro Carvalho Chehab dprintk(1, "URB status %d [%s].\n", status, errmsg); 1410c0d06caSMauro Carvalho Chehab } else { 1420c0d06caSMauro Carvalho Chehab dprintk(1, "URB packet %d, status %d [%s].\n", 1430c0d06caSMauro Carvalho Chehab packet, status, errmsg); 1440c0d06caSMauro Carvalho Chehab } 1450c0d06caSMauro Carvalho Chehab } 1460c0d06caSMauro Carvalho Chehab 147a950e4a7SFrank Schaefer static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb) 1480c0d06caSMauro Carvalho Chehab { 149a950e4a7SFrank Schaefer int xfer_bulk, num_packets, i; 1500c0d06caSMauro Carvalho Chehab 1510c0d06caSMauro Carvalho Chehab if (!dev) 1520c0d06caSMauro Carvalho Chehab return 0; 1530c0d06caSMauro Carvalho Chehab 1542665c299SFrank Schaefer if (dev->disconnected) 1550c0d06caSMauro Carvalho Chehab return 0; 1560c0d06caSMauro Carvalho Chehab 1571653cb0cSFrank Schaefer if (urb->status < 0) 1580c0d06caSMauro Carvalho Chehab print_err_status(dev, -1, urb->status); 1590c0d06caSMauro Carvalho Chehab 160a950e4a7SFrank Schaefer xfer_bulk = usb_pipebulk(urb->pipe); 1610c0d06caSMauro Carvalho Chehab 162a950e4a7SFrank Schaefer if (xfer_bulk) /* bulk */ 163a950e4a7SFrank Schaefer num_packets = 1; 164a950e4a7SFrank Schaefer else /* isoc */ 165a950e4a7SFrank Schaefer num_packets = urb->number_of_packets; 166a950e4a7SFrank Schaefer 167a950e4a7SFrank Schaefer for (i = 0; i < num_packets; i++) { 168a950e4a7SFrank Schaefer if (xfer_bulk) { 169a950e4a7SFrank Schaefer if (urb->status < 0) { 170a950e4a7SFrank Schaefer print_err_status(dev, i, urb->status); 171a950e4a7SFrank Schaefer if (urb->status != -EPROTO) 172a950e4a7SFrank Schaefer continue; 173a950e4a7SFrank Schaefer } 174ffdeca88SMauro Carvalho Chehab if (!urb->actual_length) 175ffdeca88SMauro Carvalho Chehab continue; 176a950e4a7SFrank Schaefer dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer, 177a950e4a7SFrank Schaefer urb->actual_length); 178a950e4a7SFrank Schaefer } else { 179a950e4a7SFrank Schaefer if (urb->iso_frame_desc[i].status < 0) { 180a950e4a7SFrank Schaefer print_err_status(dev, i, 181a950e4a7SFrank Schaefer urb->iso_frame_desc[i].status); 1820c0d06caSMauro Carvalho Chehab if (urb->iso_frame_desc[i].status != -EPROTO) 1830c0d06caSMauro Carvalho Chehab continue; 1840c0d06caSMauro Carvalho Chehab } 185ffdeca88SMauro Carvalho Chehab if (!urb->iso_frame_desc[i].actual_length) 186ffdeca88SMauro Carvalho Chehab continue; 187a950e4a7SFrank Schaefer dvb_dmx_swfilter(&dev->dvb->demux, 188a950e4a7SFrank Schaefer urb->transfer_buffer + 1890c0d06caSMauro Carvalho Chehab urb->iso_frame_desc[i].offset, 1900c0d06caSMauro Carvalho Chehab urb->iso_frame_desc[i].actual_length); 1910c0d06caSMauro Carvalho Chehab } 192a950e4a7SFrank Schaefer } 1930c0d06caSMauro Carvalho Chehab 1940c0d06caSMauro Carvalho Chehab return 0; 1950c0d06caSMauro Carvalho Chehab } 1960c0d06caSMauro Carvalho Chehab 1970c0d06caSMauro Carvalho Chehab static int em28xx_start_streaming(struct em28xx_dvb *dvb) 1980c0d06caSMauro Carvalho Chehab { 1990c0d06caSMauro Carvalho Chehab int rc; 2003de09fbbSHans Verkuil struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv; 2013de09fbbSHans Verkuil struct em28xx *dev = i2c_bus->dev; 202c647a91aSFrank Schaefer int dvb_max_packet_size, packet_multiplier, dvb_alt; 2030c0d06caSMauro Carvalho Chehab 204c647a91aSFrank Schaefer if (dev->dvb_xfer_bulk) { 205c647a91aSFrank Schaefer if (!dev->dvb_ep_bulk) 206c647a91aSFrank Schaefer return -ENODEV; 207c647a91aSFrank Schaefer dvb_max_packet_size = 512; /* USB 2.0 spec */ 208c647a91aSFrank Schaefer packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER; 209c647a91aSFrank Schaefer dvb_alt = 0; 210c647a91aSFrank Schaefer } else { /* isoc */ 211c647a91aSFrank Schaefer if (!dev->dvb_ep_isoc) 212c647a91aSFrank Schaefer return -ENODEV; 213c647a91aSFrank Schaefer dvb_max_packet_size = dev->dvb_max_pkt_size_isoc; 214c647a91aSFrank Schaefer if (dvb_max_packet_size < 0) 215c647a91aSFrank Schaefer return dvb_max_packet_size; 216c647a91aSFrank Schaefer packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS; 217c647a91aSFrank Schaefer dvb_alt = dev->dvb_alt_isoc; 218c647a91aSFrank Schaefer } 219c647a91aSFrank Schaefer 2200c0d06caSMauro Carvalho Chehab rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); 2210c0d06caSMauro Carvalho Chehab if (rc < 0) 2220c0d06caSMauro Carvalho Chehab return rc; 2230c0d06caSMauro Carvalho Chehab 22452f7b00eSMauro Carvalho Chehab dprintk(1, "Using %d buffers each with %d x %d bytes, alternate %d\n", 2250c0d06caSMauro Carvalho Chehab EM28XX_DVB_NUM_BUFS, 226c647a91aSFrank Schaefer packet_multiplier, 22752f7b00eSMauro Carvalho Chehab dvb_max_packet_size, dvb_alt); 2280c0d06caSMauro Carvalho Chehab 229c647a91aSFrank Schaefer return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE, 230c647a91aSFrank Schaefer dev->dvb_xfer_bulk, 231515688a8SFrank Schaefer EM28XX_DVB_NUM_BUFS, 232c647a91aSFrank Schaefer dvb_max_packet_size, 233c647a91aSFrank Schaefer packet_multiplier, 234a950e4a7SFrank Schaefer em28xx_dvb_urb_data_copy); 2350c0d06caSMauro Carvalho Chehab } 2360c0d06caSMauro Carvalho Chehab 2370c0d06caSMauro Carvalho Chehab static int em28xx_stop_streaming(struct em28xx_dvb *dvb) 2380c0d06caSMauro Carvalho Chehab { 2393de09fbbSHans Verkuil struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv; 2403de09fbbSHans Verkuil struct em28xx *dev = i2c_bus->dev; 2410c0d06caSMauro Carvalho Chehab 2420c0d06caSMauro Carvalho Chehab em28xx_stop_urbs(dev); 2430c0d06caSMauro Carvalho Chehab 2440c0d06caSMauro Carvalho Chehab return 0; 2450c0d06caSMauro Carvalho Chehab } 2460c0d06caSMauro Carvalho Chehab 2470c0d06caSMauro Carvalho Chehab static int em28xx_start_feed(struct dvb_demux_feed *feed) 2480c0d06caSMauro Carvalho Chehab { 2490c0d06caSMauro Carvalho Chehab struct dvb_demux *demux = feed->demux; 2500c0d06caSMauro Carvalho Chehab struct em28xx_dvb *dvb = demux->priv; 2510c0d06caSMauro Carvalho Chehab int rc, ret; 2520c0d06caSMauro Carvalho Chehab 2530c0d06caSMauro Carvalho Chehab if (!demux->dmx.frontend) 2540c0d06caSMauro Carvalho Chehab return -EINVAL; 2550c0d06caSMauro Carvalho Chehab 2560c0d06caSMauro Carvalho Chehab mutex_lock(&dvb->lock); 2570c0d06caSMauro Carvalho Chehab dvb->nfeeds++; 2580c0d06caSMauro Carvalho Chehab rc = dvb->nfeeds; 2590c0d06caSMauro Carvalho Chehab 2600c0d06caSMauro Carvalho Chehab if (dvb->nfeeds == 1) { 2610c0d06caSMauro Carvalho Chehab ret = em28xx_start_streaming(dvb); 2620c0d06caSMauro Carvalho Chehab if (ret < 0) 2630c0d06caSMauro Carvalho Chehab rc = ret; 2640c0d06caSMauro Carvalho Chehab } 2650c0d06caSMauro Carvalho Chehab 2660c0d06caSMauro Carvalho Chehab mutex_unlock(&dvb->lock); 2670c0d06caSMauro Carvalho Chehab return rc; 2680c0d06caSMauro Carvalho Chehab } 2690c0d06caSMauro Carvalho Chehab 2700c0d06caSMauro Carvalho Chehab static int em28xx_stop_feed(struct dvb_demux_feed *feed) 2710c0d06caSMauro Carvalho Chehab { 2720c0d06caSMauro Carvalho Chehab struct dvb_demux *demux = feed->demux; 2730c0d06caSMauro Carvalho Chehab struct em28xx_dvb *dvb = demux->priv; 2740c0d06caSMauro Carvalho Chehab int err = 0; 2750c0d06caSMauro Carvalho Chehab 2760c0d06caSMauro Carvalho Chehab mutex_lock(&dvb->lock); 2770c0d06caSMauro Carvalho Chehab dvb->nfeeds--; 2780c0d06caSMauro Carvalho Chehab 279fe8d54f0SMauro Carvalho Chehab if (!dvb->nfeeds) 2800c0d06caSMauro Carvalho Chehab err = em28xx_stop_streaming(dvb); 2810c0d06caSMauro Carvalho Chehab 2820c0d06caSMauro Carvalho Chehab mutex_unlock(&dvb->lock); 2830c0d06caSMauro Carvalho Chehab return err; 2840c0d06caSMauro Carvalho Chehab } 2850c0d06caSMauro Carvalho Chehab 2860c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */ 2870c0d06caSMauro Carvalho Chehab static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) 2880c0d06caSMauro Carvalho Chehab { 289a3b60209SMauro Carvalho Chehab struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv; 290a3b60209SMauro Carvalho Chehab struct em28xx *dev = i2c_bus->dev; 2910c0d06caSMauro Carvalho Chehab 2920c0d06caSMauro Carvalho Chehab if (acquire) 2930c0d06caSMauro Carvalho Chehab return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); 2940c0d06caSMauro Carvalho Chehab else 2950c0d06caSMauro Carvalho Chehab return em28xx_set_mode(dev, EM28XX_SUSPEND); 2960c0d06caSMauro Carvalho Chehab } 2970c0d06caSMauro Carvalho Chehab 2980c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */ 2990c0d06caSMauro Carvalho Chehab 3000c0d06caSMauro Carvalho Chehab static struct lgdt330x_config em2880_lgdt3303_dev = { 3010c0d06caSMauro Carvalho Chehab .demod_address = 0x0e, 3020c0d06caSMauro Carvalho Chehab .demod_chip = LGDT3303, 3030c0d06caSMauro Carvalho Chehab }; 3040c0d06caSMauro Carvalho Chehab 3050c0d06caSMauro Carvalho Chehab static struct lgdt3305_config em2870_lgdt3304_dev = { 3060c0d06caSMauro Carvalho Chehab .i2c_addr = 0x0e, 3070c0d06caSMauro Carvalho Chehab .demod_chip = LGDT3304, 3080c0d06caSMauro Carvalho Chehab .spectral_inversion = 1, 3090c0d06caSMauro Carvalho Chehab .deny_i2c_rptr = 1, 3100c0d06caSMauro Carvalho Chehab .mpeg_mode = LGDT3305_MPEG_PARALLEL, 3110c0d06caSMauro Carvalho Chehab .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE, 3120c0d06caSMauro Carvalho Chehab .tpvalid_polarity = LGDT3305_TP_VALID_HIGH, 3130c0d06caSMauro Carvalho Chehab .vsb_if_khz = 3250, 3140c0d06caSMauro Carvalho Chehab .qam_if_khz = 4000, 3150c0d06caSMauro Carvalho Chehab }; 3160c0d06caSMauro Carvalho Chehab 3176dbea9f0SJean-Francois Thibert static struct lgdt3305_config em2874_lgdt3305_dev = { 3186dbea9f0SJean-Francois Thibert .i2c_addr = 0x0e, 3196dbea9f0SJean-Francois Thibert .demod_chip = LGDT3305, 3206dbea9f0SJean-Francois Thibert .spectral_inversion = 1, 3216dbea9f0SJean-Francois Thibert .deny_i2c_rptr = 0, 3226dbea9f0SJean-Francois Thibert .mpeg_mode = LGDT3305_MPEG_SERIAL, 3236dbea9f0SJean-Francois Thibert .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE, 3246dbea9f0SJean-Francois Thibert .tpvalid_polarity = LGDT3305_TP_VALID_HIGH, 3256dbea9f0SJean-Francois Thibert .vsb_if_khz = 3250, 3266dbea9f0SJean-Francois Thibert .qam_if_khz = 4000, 3276dbea9f0SJean-Francois Thibert }; 3286dbea9f0SJean-Francois Thibert 32902bc1f55SMauro Carvalho Chehab static struct lgdt3305_config em2874_lgdt3305_nogate_dev = { 33002bc1f55SMauro Carvalho Chehab .i2c_addr = 0x0e, 33102bc1f55SMauro Carvalho Chehab .demod_chip = LGDT3305, 33202bc1f55SMauro Carvalho Chehab .spectral_inversion = 1, 33302bc1f55SMauro Carvalho Chehab .deny_i2c_rptr = 1, 33402bc1f55SMauro Carvalho Chehab .mpeg_mode = LGDT3305_MPEG_SERIAL, 33502bc1f55SMauro Carvalho Chehab .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE, 33602bc1f55SMauro Carvalho Chehab .tpvalid_polarity = LGDT3305_TP_VALID_HIGH, 33702bc1f55SMauro Carvalho Chehab .vsb_if_khz = 3600, 33802bc1f55SMauro Carvalho Chehab .qam_if_khz = 3600, 33902bc1f55SMauro Carvalho Chehab }; 34002bc1f55SMauro Carvalho Chehab 3410c0d06caSMauro Carvalho Chehab static struct s921_config sharp_isdbt = { 3420c0d06caSMauro Carvalho Chehab .demod_address = 0x30 >> 1 3430c0d06caSMauro Carvalho Chehab }; 3440c0d06caSMauro Carvalho Chehab 3450c0d06caSMauro Carvalho Chehab static struct zl10353_config em28xx_zl10353_with_xc3028 = { 3460c0d06caSMauro Carvalho Chehab .demod_address = (0x1e >> 1), 3470c0d06caSMauro Carvalho Chehab .no_tuner = 1, 3480c0d06caSMauro Carvalho Chehab .parallel_ts = 1, 3490c0d06caSMauro Carvalho Chehab .if2 = 45600, 3500c0d06caSMauro Carvalho Chehab }; 3510c0d06caSMauro Carvalho Chehab 3520c0d06caSMauro Carvalho Chehab static struct s5h1409_config em28xx_s5h1409_with_xc3028 = { 3530c0d06caSMauro Carvalho Chehab .demod_address = 0x32 >> 1, 3540c0d06caSMauro Carvalho Chehab .output_mode = S5H1409_PARALLEL_OUTPUT, 3550c0d06caSMauro Carvalho Chehab .gpio = S5H1409_GPIO_OFF, 3560c0d06caSMauro Carvalho Chehab .inversion = S5H1409_INVERSION_OFF, 3570c0d06caSMauro Carvalho Chehab .status_mode = S5H1409_DEMODLOCKING, 358ad05ff09SMauro Carvalho Chehab .mpeg_timing = S5H1409_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK 3590c0d06caSMauro Carvalho Chehab }; 3600c0d06caSMauro Carvalho Chehab 3610c0d06caSMauro Carvalho Chehab static struct tda18271_std_map kworld_a340_std_map = { 3620c0d06caSMauro Carvalho Chehab .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0, 3630c0d06caSMauro Carvalho Chehab .if_lvl = 1, .rfagc_top = 0x37, }, 3640c0d06caSMauro Carvalho Chehab .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1, 3650c0d06caSMauro Carvalho Chehab .if_lvl = 1, .rfagc_top = 0x37, }, 3660c0d06caSMauro Carvalho Chehab }; 3670c0d06caSMauro Carvalho Chehab 3680c0d06caSMauro Carvalho Chehab static struct tda18271_config kworld_a340_config = { 3690c0d06caSMauro Carvalho Chehab .std_map = &kworld_a340_std_map, 3700c0d06caSMauro Carvalho Chehab }; 3710c0d06caSMauro Carvalho Chehab 3726dbea9f0SJean-Francois Thibert static struct tda18271_config kworld_ub435q_v2_config = { 3736dbea9f0SJean-Francois Thibert .std_map = &kworld_a340_std_map, 3746dbea9f0SJean-Francois Thibert .gate = TDA18271_GATE_DIGITAL, 3756dbea9f0SJean-Francois Thibert }; 3766dbea9f0SJean-Francois Thibert 37702bc1f55SMauro Carvalho Chehab static struct tda18212_config kworld_ub435q_v3_config = { 37802bc1f55SMauro Carvalho Chehab .if_atsc_vsb = 3600, 37902bc1f55SMauro Carvalho Chehab .if_atsc_qam = 3600, 38002bc1f55SMauro Carvalho Chehab }; 38102bc1f55SMauro Carvalho Chehab 3820c0d06caSMauro Carvalho Chehab static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = { 3830c0d06caSMauro Carvalho Chehab .demod_address = (0x1e >> 1), 3840c0d06caSMauro Carvalho Chehab .no_tuner = 1, 3850c0d06caSMauro Carvalho Chehab .disable_i2c_gate_ctrl = 1, 3860c0d06caSMauro Carvalho Chehab .parallel_ts = 1, 3870c0d06caSMauro Carvalho Chehab .if2 = 45600, 3880c0d06caSMauro Carvalho Chehab }; 3890c0d06caSMauro Carvalho Chehab 3900c0d06caSMauro Carvalho Chehab static struct drxd_config em28xx_drxd = { 3910c0d06caSMauro Carvalho Chehab .demod_address = 0x70, 3920c0d06caSMauro Carvalho Chehab .demod_revision = 0xa2, 3930c0d06caSMauro Carvalho Chehab .pll_type = DRXD_PLL_NONE, 3940c0d06caSMauro Carvalho Chehab .clock = 12000, 3950c0d06caSMauro Carvalho Chehab .insert_rs_byte = 1, 3960c0d06caSMauro Carvalho Chehab .IF = 42800000, 3970c0d06caSMauro Carvalho Chehab .disable_i2c_gate_ctrl = 1, 3980c0d06caSMauro Carvalho Chehab }; 3990c0d06caSMauro Carvalho Chehab 4000c0d06caSMauro Carvalho Chehab static struct drxk_config terratec_h5_drxk = { 4010c0d06caSMauro Carvalho Chehab .adr = 0x29, 4020c0d06caSMauro Carvalho Chehab .single_master = 1, 4030c0d06caSMauro Carvalho Chehab .no_i2c_bridge = 1, 4040c0d06caSMauro Carvalho Chehab .microcode_name = "dvb-usb-terratec-h5-drxk.fw", 4050c0d06caSMauro Carvalho Chehab .qam_demod_parameter_count = 2, 4060c0d06caSMauro Carvalho Chehab }; 4070c0d06caSMauro Carvalho Chehab 4080c0d06caSMauro Carvalho Chehab static struct drxk_config hauppauge_930c_drxk = { 4090c0d06caSMauro Carvalho Chehab .adr = 0x29, 4100c0d06caSMauro Carvalho Chehab .single_master = 1, 4110c0d06caSMauro Carvalho Chehab .no_i2c_bridge = 1, 4120c0d06caSMauro Carvalho Chehab .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw", 4130c0d06caSMauro Carvalho Chehab .chunk_size = 56, 4140c0d06caSMauro Carvalho Chehab .qam_demod_parameter_count = 2, 4150c0d06caSMauro Carvalho Chehab }; 4160c0d06caSMauro Carvalho Chehab 41789040136SMartin Blumenstingl static struct drxk_config terratec_htc_stick_drxk = { 4180c0d06caSMauro Carvalho Chehab .adr = 0x29, 4190c0d06caSMauro Carvalho Chehab .single_master = 1, 4200c0d06caSMauro Carvalho Chehab .no_i2c_bridge = 1, 4210c0d06caSMauro Carvalho Chehab .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw", 4220c0d06caSMauro Carvalho Chehab .chunk_size = 54, 4230c0d06caSMauro Carvalho Chehab .qam_demod_parameter_count = 2, 4240c0d06caSMauro Carvalho Chehab /* Required for the antenna_gpio to disable LNA. */ 4250c0d06caSMauro Carvalho Chehab .antenna_dvbt = true, 4260c0d06caSMauro Carvalho Chehab /* The windows driver uses the same. This will disable LNA. */ 4270c0d06caSMauro Carvalho Chehab .antenna_gpio = 0x6, 4280c0d06caSMauro Carvalho Chehab }; 4290c0d06caSMauro Carvalho Chehab 4300c0d06caSMauro Carvalho Chehab static struct drxk_config maxmedia_ub425_tc_drxk = { 4310c0d06caSMauro Carvalho Chehab .adr = 0x29, 4320c0d06caSMauro Carvalho Chehab .single_master = 1, 4330c0d06caSMauro Carvalho Chehab .no_i2c_bridge = 1, 4348d100b27SAntti Palosaari .microcode_name = "dvb-demod-drxk-01.fw", 4358d100b27SAntti Palosaari .chunk_size = 62, 436de0fc463SAntti Palosaari .qam_demod_parameter_count = 2, 4370c0d06caSMauro Carvalho Chehab }; 4380c0d06caSMauro Carvalho Chehab 4390c0d06caSMauro Carvalho Chehab static struct drxk_config pctv_520e_drxk = { 4400c0d06caSMauro Carvalho Chehab .adr = 0x29, 4410c0d06caSMauro Carvalho Chehab .single_master = 1, 4420c0d06caSMauro Carvalho Chehab .microcode_name = "dvb-demod-drxk-pctv.fw", 4430c0d06caSMauro Carvalho Chehab .qam_demod_parameter_count = 2, 4440c0d06caSMauro Carvalho Chehab .chunk_size = 58, 4450c0d06caSMauro Carvalho Chehab .antenna_dvbt = true, /* disable LNA */ 4460c0d06caSMauro Carvalho Chehab .antenna_gpio = (1 << 2), /* disable LNA */ 4470c0d06caSMauro Carvalho Chehab }; 4480c0d06caSMauro Carvalho Chehab 4490c0d06caSMauro Carvalho Chehab static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable) 4500c0d06caSMauro Carvalho Chehab { 4510c0d06caSMauro Carvalho Chehab struct em28xx_dvb *dvb = fe->sec_priv; 4520c0d06caSMauro Carvalho Chehab int status; 4530c0d06caSMauro Carvalho Chehab 4540c0d06caSMauro Carvalho Chehab if (!dvb) 4550c0d06caSMauro Carvalho Chehab return -EINVAL; 4560c0d06caSMauro Carvalho Chehab 4570c0d06caSMauro Carvalho Chehab if (enable) { 4580c0d06caSMauro Carvalho Chehab down(&dvb->pll_mutex); 4590c0d06caSMauro Carvalho Chehab status = dvb->gate_ctrl(fe, 1); 4600c0d06caSMauro Carvalho Chehab } else { 4610c0d06caSMauro Carvalho Chehab status = dvb->gate_ctrl(fe, 0); 4620c0d06caSMauro Carvalho Chehab up(&dvb->pll_mutex); 4630c0d06caSMauro Carvalho Chehab } 4640c0d06caSMauro Carvalho Chehab return status; 4650c0d06caSMauro Carvalho Chehab } 4660c0d06caSMauro Carvalho Chehab 4670c0d06caSMauro Carvalho Chehab static void hauppauge_hvr930c_init(struct em28xx *dev) 4680c0d06caSMauro Carvalho Chehab { 4690c0d06caSMauro Carvalho Chehab int i; 4700c0d06caSMauro Carvalho Chehab 4710c0d06caSMauro Carvalho Chehab struct em28xx_reg_seq hauppauge_hvr930c_init[] = { 472907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65}, 473907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32}, 474907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8}, 4750c0d06caSMauro Carvalho Chehab { -1, -1, -1, -1}, 4760c0d06caSMauro Carvalho Chehab }; 4770c0d06caSMauro Carvalho Chehab struct em28xx_reg_seq hauppauge_hvr930c_end[] = { 478907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01}, 479907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65}, 480907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76}, 481907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01}, 482907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b}, 483907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40}, 4840c0d06caSMauro Carvalho Chehab 485907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65}, 486907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65}, 487907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b}, 488907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65}, 4890c0d06caSMauro Carvalho Chehab 4900c0d06caSMauro Carvalho Chehab { -1, -1, -1, -1}, 4910c0d06caSMauro Carvalho Chehab }; 4920c0d06caSMauro Carvalho Chehab 4930c0d06caSMauro Carvalho Chehab struct { 4940c0d06caSMauro Carvalho Chehab unsigned char r[4]; 4950c0d06caSMauro Carvalho Chehab int len; 4960c0d06caSMauro Carvalho Chehab } regs[] = { 4970c0d06caSMauro Carvalho Chehab {{ 0x06, 0x02, 0x00, 0x31 }, 4}, 4980c0d06caSMauro Carvalho Chehab {{ 0x01, 0x02 }, 2}, 4990c0d06caSMauro Carvalho Chehab {{ 0x01, 0x02, 0x00, 0xc6 }, 4}, 5000c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00 }, 2}, 5010c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00, 0xff, 0xaf }, 4}, 5020c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00, 0x03, 0xa0 }, 4}, 5030c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00 }, 2}, 5040c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00, 0x73, 0xaf }, 4}, 5050c0d06caSMauro Carvalho Chehab {{ 0x04, 0x00 }, 2}, 5060c0d06caSMauro Carvalho Chehab {{ 0x00, 0x04 }, 2}, 5070c0d06caSMauro Carvalho Chehab {{ 0x00, 0x04, 0x00, 0x0a }, 4}, 5080c0d06caSMauro Carvalho Chehab {{ 0x04, 0x14 }, 2}, 5090c0d06caSMauro Carvalho Chehab {{ 0x04, 0x14, 0x00, 0x00 }, 4}, 5100c0d06caSMauro Carvalho Chehab }; 5110c0d06caSMauro Carvalho Chehab 5120c0d06caSMauro Carvalho Chehab em28xx_gpio_set(dev, hauppauge_hvr930c_init); 5130c0d06caSMauro Carvalho Chehab em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); 514fe8d54f0SMauro Carvalho Chehab usleep_range(10000, 11000); 5150c0d06caSMauro Carvalho Chehab em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44); 516fe8d54f0SMauro Carvalho Chehab usleep_range(10000, 11000); 5170c0d06caSMauro Carvalho Chehab 518c7a45e5bSMauro Carvalho Chehab dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; 5190c0d06caSMauro Carvalho Chehab 5200c0d06caSMauro Carvalho Chehab for (i = 0; i < ARRAY_SIZE(regs); i++) 521fe8d54f0SMauro Carvalho Chehab i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], 522fe8d54f0SMauro Carvalho Chehab regs[i].r, regs[i].len); 5230c0d06caSMauro Carvalho Chehab em28xx_gpio_set(dev, hauppauge_hvr930c_end); 5240c0d06caSMauro Carvalho Chehab 5250c0d06caSMauro Carvalho Chehab msleep(100); 5260c0d06caSMauro Carvalho Chehab 5270c0d06caSMauro Carvalho Chehab em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44); 5280c0d06caSMauro Carvalho Chehab msleep(30); 5290c0d06caSMauro Carvalho Chehab 5300c0d06caSMauro Carvalho Chehab em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45); 531fe8d54f0SMauro Carvalho Chehab usleep_range(10000, 11000); 5320c0d06caSMauro Carvalho Chehab } 5330c0d06caSMauro Carvalho Chehab 5340c0d06caSMauro Carvalho Chehab static void terratec_h5_init(struct em28xx *dev) 5350c0d06caSMauro Carvalho Chehab { 5360c0d06caSMauro Carvalho Chehab int i; 5370c0d06caSMauro Carvalho Chehab struct em28xx_reg_seq terratec_h5_init[] = { 538c074fc4cSFrank Schaefer {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10}, 539907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100}, 540907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50}, 541907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100}, 5420c0d06caSMauro Carvalho Chehab { -1, -1, -1, -1}, 5430c0d06caSMauro Carvalho Chehab }; 5440c0d06caSMauro Carvalho Chehab struct em28xx_reg_seq terratec_h5_end[] = { 545907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100}, 546907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50}, 547907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100}, 5480c0d06caSMauro Carvalho Chehab { -1, -1, -1, -1}, 5490c0d06caSMauro Carvalho Chehab }; 5500c0d06caSMauro Carvalho Chehab struct { 5510c0d06caSMauro Carvalho Chehab unsigned char r[4]; 5520c0d06caSMauro Carvalho Chehab int len; 5530c0d06caSMauro Carvalho Chehab } regs[] = { 5540c0d06caSMauro Carvalho Chehab {{ 0x06, 0x02, 0x00, 0x31 }, 4}, 5550c0d06caSMauro Carvalho Chehab {{ 0x01, 0x02 }, 2}, 5560c0d06caSMauro Carvalho Chehab {{ 0x01, 0x02, 0x00, 0xc6 }, 4}, 5570c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00 }, 2}, 5580c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00, 0xff, 0xaf }, 4}, 5590c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00, 0x03, 0xa0 }, 4}, 5600c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00 }, 2}, 5610c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00, 0x73, 0xaf }, 4}, 5620c0d06caSMauro Carvalho Chehab {{ 0x04, 0x00 }, 2}, 5630c0d06caSMauro Carvalho Chehab {{ 0x00, 0x04 }, 2}, 5640c0d06caSMauro Carvalho Chehab {{ 0x00, 0x04, 0x00, 0x0a }, 4}, 5650c0d06caSMauro Carvalho Chehab {{ 0x04, 0x14 }, 2}, 5660c0d06caSMauro Carvalho Chehab {{ 0x04, 0x14, 0x00, 0x00 }, 4}, 5670c0d06caSMauro Carvalho Chehab }; 5680c0d06caSMauro Carvalho Chehab 5690c0d06caSMauro Carvalho Chehab em28xx_gpio_set(dev, terratec_h5_init); 5700c0d06caSMauro Carvalho Chehab em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); 571fe8d54f0SMauro Carvalho Chehab usleep_range(10000, 11000); 5720c0d06caSMauro Carvalho Chehab em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45); 573fe8d54f0SMauro Carvalho Chehab usleep_range(10000, 11000); 5740c0d06caSMauro Carvalho Chehab 575c7a45e5bSMauro Carvalho Chehab dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; 5760c0d06caSMauro Carvalho Chehab 5770c0d06caSMauro Carvalho Chehab for (i = 0; i < ARRAY_SIZE(regs); i++) 578fe8d54f0SMauro Carvalho Chehab i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], 579fe8d54f0SMauro Carvalho Chehab regs[i].r, regs[i].len); 5800c0d06caSMauro Carvalho Chehab em28xx_gpio_set(dev, terratec_h5_end); 5810c0d06caSMauro Carvalho Chehab }; 5820c0d06caSMauro Carvalho Chehab 5830c0d06caSMauro Carvalho Chehab static void terratec_htc_stick_init(struct em28xx *dev) 5840c0d06caSMauro Carvalho Chehab { 5850c0d06caSMauro Carvalho Chehab int i; 5860c0d06caSMauro Carvalho Chehab 5870c0d06caSMauro Carvalho Chehab /* 5880c0d06caSMauro Carvalho Chehab * GPIO configuration: 5890c0d06caSMauro Carvalho Chehab * 0xff: unknown (does not affect DVB-T). 5900c0d06caSMauro Carvalho Chehab * 0xf6: DRX-K (demodulator). 5910c0d06caSMauro Carvalho Chehab * 0xe6: unknown (does not affect DVB-T). 5920c0d06caSMauro Carvalho Chehab * 0xb6: unknown (does not affect DVB-T). 5930c0d06caSMauro Carvalho Chehab */ 5940c0d06caSMauro Carvalho Chehab struct em28xx_reg_seq terratec_htc_stick_init[] = { 595c074fc4cSFrank Schaefer {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10}, 596907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100}, 597907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50}, 598907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100}, 5990c0d06caSMauro Carvalho Chehab { -1, -1, -1, -1}, 6000c0d06caSMauro Carvalho Chehab }; 6010c0d06caSMauro Carvalho Chehab struct em28xx_reg_seq terratec_htc_stick_end[] = { 602907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100}, 603907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50}, 6040c0d06caSMauro Carvalho Chehab { -1, -1, -1, -1}, 6050c0d06caSMauro Carvalho Chehab }; 6060c0d06caSMauro Carvalho Chehab 60789040136SMartin Blumenstingl /* 60889040136SMartin Blumenstingl * Init the analog decoder (not yet supported), but 60989040136SMartin Blumenstingl * it's probably still a good idea. 61089040136SMartin Blumenstingl */ 6110c0d06caSMauro Carvalho Chehab struct { 6120c0d06caSMauro Carvalho Chehab unsigned char r[4]; 6130c0d06caSMauro Carvalho Chehab int len; 6140c0d06caSMauro Carvalho Chehab } regs[] = { 6150c0d06caSMauro Carvalho Chehab {{ 0x06, 0x02, 0x00, 0x31 }, 4}, 6160c0d06caSMauro Carvalho Chehab {{ 0x01, 0x02 }, 2}, 6170c0d06caSMauro Carvalho Chehab {{ 0x01, 0x02, 0x00, 0xc6 }, 4}, 6180c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00 }, 2}, 6190c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00, 0xff, 0xaf }, 4}, 6200c0d06caSMauro Carvalho Chehab }; 6210c0d06caSMauro Carvalho Chehab 6220c0d06caSMauro Carvalho Chehab em28xx_gpio_set(dev, terratec_htc_stick_init); 6230c0d06caSMauro Carvalho Chehab 6240c0d06caSMauro Carvalho Chehab em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); 625fe8d54f0SMauro Carvalho Chehab usleep_range(10000, 11000); 6260c0d06caSMauro Carvalho Chehab em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44); 627fe8d54f0SMauro Carvalho Chehab usleep_range(10000, 11000); 6280c0d06caSMauro Carvalho Chehab 629c7a45e5bSMauro Carvalho Chehab dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; 6300c0d06caSMauro Carvalho Chehab 6310c0d06caSMauro Carvalho Chehab for (i = 0; i < ARRAY_SIZE(regs); i++) 632fe8d54f0SMauro Carvalho Chehab i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], 633fe8d54f0SMauro Carvalho Chehab regs[i].r, regs[i].len); 6340c0d06caSMauro Carvalho Chehab 6350c0d06caSMauro Carvalho Chehab em28xx_gpio_set(dev, terratec_htc_stick_end); 6360c0d06caSMauro Carvalho Chehab }; 6370c0d06caSMauro Carvalho Chehab 63889040136SMartin Blumenstingl static void terratec_htc_usb_xs_init(struct em28xx *dev) 63989040136SMartin Blumenstingl { 64089040136SMartin Blumenstingl int i; 64189040136SMartin Blumenstingl 64289040136SMartin Blumenstingl struct em28xx_reg_seq terratec_htc_usb_xs_init[] = { 643c074fc4cSFrank Schaefer {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10}, 644907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100}, 645907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50}, 646907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100}, 64789040136SMartin Blumenstingl { -1, -1, -1, -1}, 64889040136SMartin Blumenstingl }; 64989040136SMartin Blumenstingl struct em28xx_reg_seq terratec_htc_usb_xs_end[] = { 650907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100}, 651907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50}, 652907d109bSFrank Schaefer {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100}, 65389040136SMartin Blumenstingl { -1, -1, -1, -1}, 65489040136SMartin Blumenstingl }; 65589040136SMartin Blumenstingl 65689040136SMartin Blumenstingl /* 65789040136SMartin Blumenstingl * Init the analog decoder (not yet supported), but 65889040136SMartin Blumenstingl * it's probably still a good idea. 65989040136SMartin Blumenstingl */ 66089040136SMartin Blumenstingl struct { 66189040136SMartin Blumenstingl unsigned char r[4]; 66289040136SMartin Blumenstingl int len; 66389040136SMartin Blumenstingl } regs[] = { 66489040136SMartin Blumenstingl {{ 0x06, 0x02, 0x00, 0x31 }, 4}, 66589040136SMartin Blumenstingl {{ 0x01, 0x02 }, 2}, 66689040136SMartin Blumenstingl {{ 0x01, 0x02, 0x00, 0xc6 }, 4}, 66789040136SMartin Blumenstingl {{ 0x01, 0x00 }, 2}, 66889040136SMartin Blumenstingl {{ 0x01, 0x00, 0xff, 0xaf }, 4}, 66989040136SMartin Blumenstingl {{ 0x01, 0x00, 0x03, 0xa0 }, 4}, 67089040136SMartin Blumenstingl {{ 0x01, 0x00 }, 2}, 67189040136SMartin Blumenstingl {{ 0x01, 0x00, 0x73, 0xaf }, 4}, 67289040136SMartin Blumenstingl {{ 0x04, 0x00 }, 2}, 67389040136SMartin Blumenstingl {{ 0x00, 0x04 }, 2}, 67489040136SMartin Blumenstingl {{ 0x00, 0x04, 0x00, 0x0a }, 4}, 67589040136SMartin Blumenstingl {{ 0x04, 0x14 }, 2}, 67689040136SMartin Blumenstingl {{ 0x04, 0x14, 0x00, 0x00 }, 4}, 67789040136SMartin Blumenstingl }; 67889040136SMartin Blumenstingl 67989040136SMartin Blumenstingl em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); 68089040136SMartin Blumenstingl 68189040136SMartin Blumenstingl em28xx_gpio_set(dev, terratec_htc_usb_xs_init); 68289040136SMartin Blumenstingl 68389040136SMartin Blumenstingl em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); 684fe8d54f0SMauro Carvalho Chehab usleep_range(10000, 11000); 68589040136SMartin Blumenstingl em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44); 686fe8d54f0SMauro Carvalho Chehab usleep_range(10000, 11000); 68789040136SMartin Blumenstingl 688c7a45e5bSMauro Carvalho Chehab dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; 68989040136SMartin Blumenstingl 69089040136SMartin Blumenstingl for (i = 0; i < ARRAY_SIZE(regs); i++) 691fe8d54f0SMauro Carvalho Chehab i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], 692fe8d54f0SMauro Carvalho Chehab regs[i].r, regs[i].len); 69389040136SMartin Blumenstingl 69489040136SMartin Blumenstingl em28xx_gpio_set(dev, terratec_htc_usb_xs_end); 69589040136SMartin Blumenstingl }; 69689040136SMartin Blumenstingl 6970c0d06caSMauro Carvalho Chehab static void pctv_520e_init(struct em28xx *dev) 6980c0d06caSMauro Carvalho Chehab { 6990c0d06caSMauro Carvalho Chehab /* 7000c0d06caSMauro Carvalho Chehab * Init AVF4910B analog decoder. Looks like I2C traffic to 7010c0d06caSMauro Carvalho Chehab * digital demodulator and tuner are routed via AVF4910B. 7020c0d06caSMauro Carvalho Chehab */ 7030c0d06caSMauro Carvalho Chehab int i; 7040c0d06caSMauro Carvalho Chehab struct { 7050c0d06caSMauro Carvalho Chehab unsigned char r[4]; 7060c0d06caSMauro Carvalho Chehab int len; 7070c0d06caSMauro Carvalho Chehab } regs[] = { 7080c0d06caSMauro Carvalho Chehab {{ 0x06, 0x02, 0x00, 0x31 }, 4}, 7090c0d06caSMauro Carvalho Chehab {{ 0x01, 0x02 }, 2}, 7100c0d06caSMauro Carvalho Chehab {{ 0x01, 0x02, 0x00, 0xc6 }, 4}, 7110c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00 }, 2}, 7120c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00, 0xff, 0xaf }, 4}, 7130c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00, 0x03, 0xa0 }, 4}, 7140c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00 }, 2}, 7150c0d06caSMauro Carvalho Chehab {{ 0x01, 0x00, 0x73, 0xaf }, 4}, 7160c0d06caSMauro Carvalho Chehab }; 7170c0d06caSMauro Carvalho Chehab 718c7a45e5bSMauro Carvalho Chehab dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */ 7190c0d06caSMauro Carvalho Chehab 7200c0d06caSMauro Carvalho Chehab for (i = 0; i < ARRAY_SIZE(regs); i++) 721fe8d54f0SMauro Carvalho Chehab i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], 722fe8d54f0SMauro Carvalho Chehab regs[i].r, regs[i].len); 7230c0d06caSMauro Carvalho Chehab }; 7240c0d06caSMauro Carvalho Chehab 72533eebec5SAntti Palosaari static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe) 72613a5336eSAntti Palosaari { 72733eebec5SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 7283ec40dcfSAntti Palosaari struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv; 7293ec40dcfSAntti Palosaari struct em28xx *dev = i2c_bus->dev; 73013a5336eSAntti Palosaari #ifdef CONFIG_GPIOLIB 73113a5336eSAntti Palosaari struct em28xx_dvb *dvb = dev->dvb; 73213a5336eSAntti Palosaari int ret; 73313a5336eSAntti Palosaari unsigned long flags; 73413a5336eSAntti Palosaari 73533eebec5SAntti Palosaari if (c->lna == 1) 73633eebec5SAntti Palosaari flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */ 73713a5336eSAntti Palosaari else 73833eebec5SAntti Palosaari flags = GPIOF_OUT_INIT_LOW; /* disable LNA */ 73913a5336eSAntti Palosaari 74013a5336eSAntti Palosaari ret = gpio_request_one(dvb->lna_gpio, flags, NULL); 74113a5336eSAntti Palosaari if (ret) 74229b05e22SMauro Carvalho Chehab dev_err(&dev->intf->dev, "gpio request failed %d\n", ret); 74313a5336eSAntti Palosaari else 74413a5336eSAntti Palosaari gpio_free(dvb->lna_gpio); 74513a5336eSAntti Palosaari 74613a5336eSAntti Palosaari return ret; 74713a5336eSAntti Palosaari #else 74829b05e22SMauro Carvalho Chehab dev_warn(&dev->intf->dev, "%s: LNA control is disabled (lna=%u)\n", 74933eebec5SAntti Palosaari KBUILD_MODNAME, c->lna); 75013a5336eSAntti Palosaari return 0; 75113a5336eSAntti Palosaari #endif 75213a5336eSAntti Palosaari } 75313a5336eSAntti Palosaari 754ffb9948eSAntti Palosaari static int em28xx_pctv_292e_set_lna(struct dvb_frontend *fe) 755ffb9948eSAntti Palosaari { 756ffb9948eSAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 757ffb9948eSAntti Palosaari struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv; 758ffb9948eSAntti Palosaari struct em28xx *dev = i2c_bus->dev; 759ffb9948eSAntti Palosaari u8 lna; 760ffb9948eSAntti Palosaari 761ffb9948eSAntti Palosaari if (c->lna == 1) 762ffb9948eSAntti Palosaari lna = 0x01; 763ffb9948eSAntti Palosaari else 764ffb9948eSAntti Palosaari lna = 0x00; 765ffb9948eSAntti Palosaari 766ffb9948eSAntti Palosaari return em28xx_write_reg_bits(dev, EM2874_R80_GPIO_P0_CTRL, lna, 0x01); 767ffb9948eSAntti Palosaari } 768ffb9948eSAntti Palosaari 7690c0d06caSMauro Carvalho Chehab static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe) 7700c0d06caSMauro Carvalho Chehab { 7710c0d06caSMauro Carvalho Chehab /* Values extracted from a USB trace of the Terratec Windows driver */ 7720c0d06caSMauro Carvalho Chehab static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c }; 7730c0d06caSMauro Carvalho Chehab static u8 reset[] = { RESET, 0x80 }; 7740c0d06caSMauro Carvalho Chehab static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 }; 7750c0d06caSMauro Carvalho Chehab static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 }; 7760c0d06caSMauro Carvalho Chehab static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 }; 7770c0d06caSMauro Carvalho Chehab static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d }; 7780c0d06caSMauro Carvalho Chehab static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 }; 7790c0d06caSMauro Carvalho Chehab static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 }; 7800c0d06caSMauro Carvalho Chehab static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 }; 7810c0d06caSMauro Carvalho Chehab static u8 tuner_go[] = { TUNER_GO, 0x01}; 7820c0d06caSMauro Carvalho Chehab 7830c0d06caSMauro Carvalho Chehab mt352_write(fe, clock_config, sizeof(clock_config)); 784fe8d54f0SMauro Carvalho Chehab usleep_range(200, 250); 7850c0d06caSMauro Carvalho Chehab mt352_write(fe, reset, sizeof(reset)); 7860c0d06caSMauro Carvalho Chehab mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg)); 7870c0d06caSMauro Carvalho Chehab mt352_write(fe, agc_cfg, sizeof(agc_cfg)); 7880c0d06caSMauro Carvalho Chehab mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg)); 7890c0d06caSMauro Carvalho Chehab mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg)); 7900c0d06caSMauro Carvalho Chehab mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg)); 7910c0d06caSMauro Carvalho Chehab mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg)); 7920c0d06caSMauro Carvalho Chehab mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg)); 7930c0d06caSMauro Carvalho Chehab mt352_write(fe, tuner_go, sizeof(tuner_go)); 7940c0d06caSMauro Carvalho Chehab return 0; 7950c0d06caSMauro Carvalho Chehab } 7960c0d06caSMauro Carvalho Chehab 797ab4d1452SSatoshi Nagahama static void px_bcud_init(struct em28xx *dev) 798ab4d1452SSatoshi Nagahama { 799ab4d1452SSatoshi Nagahama int i; 800ab4d1452SSatoshi Nagahama struct { 801ab4d1452SSatoshi Nagahama unsigned char r[4]; 802ab4d1452SSatoshi Nagahama int len; 803ab4d1452SSatoshi Nagahama } regs1[] = { 804ab4d1452SSatoshi Nagahama {{ 0x0e, 0x77 }, 2}, 805ab4d1452SSatoshi Nagahama {{ 0x0f, 0x77 }, 2}, 806ab4d1452SSatoshi Nagahama {{ 0x03, 0x90 }, 2}, 807ab4d1452SSatoshi Nagahama }, regs2[] = { 808ab4d1452SSatoshi Nagahama {{ 0x07, 0x01 }, 2}, 809ab4d1452SSatoshi Nagahama {{ 0x08, 0x10 }, 2}, 810ab4d1452SSatoshi Nagahama {{ 0x13, 0x00 }, 2}, 811ab4d1452SSatoshi Nagahama {{ 0x17, 0x00 }, 2}, 812ab4d1452SSatoshi Nagahama {{ 0x03, 0x01 }, 2}, 813ab4d1452SSatoshi Nagahama {{ 0x10, 0xb1 }, 2}, 814ab4d1452SSatoshi Nagahama {{ 0x11, 0x40 }, 2}, 815ab4d1452SSatoshi Nagahama {{ 0x85, 0x7a }, 2}, 816ab4d1452SSatoshi Nagahama {{ 0x87, 0x04 }, 2}, 817ab4d1452SSatoshi Nagahama }; 818ab4d1452SSatoshi Nagahama static struct em28xx_reg_seq gpio[] = { 819ab4d1452SSatoshi Nagahama {EM28XX_R06_I2C_CLK, 0x40, 0xff, 300}, 820ab4d1452SSatoshi Nagahama {EM2874_R80_GPIO_P0_CTRL, 0xfd, 0xff, 60}, 821ab4d1452SSatoshi Nagahama {EM28XX_R15_RGAIN, 0x20, 0xff, 0}, 822ab4d1452SSatoshi Nagahama {EM28XX_R16_GGAIN, 0x20, 0xff, 0}, 823ab4d1452SSatoshi Nagahama {EM28XX_R17_BGAIN, 0x20, 0xff, 0}, 824ab4d1452SSatoshi Nagahama {EM28XX_R18_ROFFSET, 0x00, 0xff, 0}, 825ab4d1452SSatoshi Nagahama {EM28XX_R19_GOFFSET, 0x00, 0xff, 0}, 826ab4d1452SSatoshi Nagahama {EM28XX_R1A_BOFFSET, 0x00, 0xff, 0}, 827ab4d1452SSatoshi Nagahama {EM28XX_R23_UOFFSET, 0x00, 0xff, 0}, 828ab4d1452SSatoshi Nagahama {EM28XX_R24_VOFFSET, 0x00, 0xff, 0}, 829ab4d1452SSatoshi Nagahama {EM28XX_R26_COMPR, 0x00, 0xff, 0}, 830ab4d1452SSatoshi Nagahama {0x13, 0x08, 0xff, 0}, 831ab4d1452SSatoshi Nagahama {EM28XX_R12_VINENABLE, 0x27, 0xff, 0}, 832ab4d1452SSatoshi Nagahama {EM28XX_R0C_USBSUSP, 0x10, 0xff, 0}, 833ab4d1452SSatoshi Nagahama {EM28XX_R27_OUTFMT, 0x00, 0xff, 0}, 834ab4d1452SSatoshi Nagahama {EM28XX_R10_VINMODE, 0x00, 0xff, 0}, 835ab4d1452SSatoshi Nagahama {EM28XX_R11_VINCTRL, 0x11, 0xff, 0}, 836ab4d1452SSatoshi Nagahama {EM2874_R50_IR_CONFIG, 0x01, 0xff, 0}, 837ab4d1452SSatoshi Nagahama {EM2874_R5F_TS_ENABLE, 0x80, 0xff, 0}, 838ab4d1452SSatoshi Nagahama {EM28XX_R06_I2C_CLK, 0x46, 0xff, 0}, 839ab4d1452SSatoshi Nagahama }; 840ab4d1452SSatoshi Nagahama em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x46); 841ab4d1452SSatoshi Nagahama /* sleeping ISDB-T */ 842ab4d1452SSatoshi Nagahama dev->dvb->i2c_client_demod->addr = 0x14; 843ab4d1452SSatoshi Nagahama for (i = 0; i < ARRAY_SIZE(regs1); i++) 844fe8d54f0SMauro Carvalho Chehab i2c_master_send(dev->dvb->i2c_client_demod, 845fe8d54f0SMauro Carvalho Chehab regs1[i].r, regs1[i].len); 846ab4d1452SSatoshi Nagahama /* sleeping ISDB-S */ 847ab4d1452SSatoshi Nagahama dev->dvb->i2c_client_demod->addr = 0x15; 848ab4d1452SSatoshi Nagahama for (i = 0; i < ARRAY_SIZE(regs2); i++) 849ab4d1452SSatoshi Nagahama i2c_master_send(dev->dvb->i2c_client_demod, regs2[i].r, 850ab4d1452SSatoshi Nagahama regs2[i].len); 851ab4d1452SSatoshi Nagahama for (i = 0; i < ARRAY_SIZE(gpio); i++) { 852ab4d1452SSatoshi Nagahama em28xx_write_reg_bits(dev, gpio[i].reg, gpio[i].val, 853ab4d1452SSatoshi Nagahama gpio[i].mask); 854ab4d1452SSatoshi Nagahama if (gpio[i].sleep > 0) 855ab4d1452SSatoshi Nagahama msleep(gpio[i].sleep); 856ab4d1452SSatoshi Nagahama } 857ab4d1452SSatoshi Nagahama }; 858ab4d1452SSatoshi Nagahama 8590c0d06caSMauro Carvalho Chehab static struct mt352_config terratec_xs_mt352_cfg = { 8600c0d06caSMauro Carvalho Chehab .demod_address = (0x1e >> 1), 8610c0d06caSMauro Carvalho Chehab .no_tuner = 1, 8620c0d06caSMauro Carvalho Chehab .if2 = 45600, 8630c0d06caSMauro Carvalho Chehab .demod_init = em28xx_mt352_terratec_xs_init, 8640c0d06caSMauro Carvalho Chehab }; 8650c0d06caSMauro Carvalho Chehab 8660c0d06caSMauro Carvalho Chehab static struct tda10023_config em28xx_tda10023_config = { 8670c0d06caSMauro Carvalho Chehab .demod_address = 0x0c, 8680c0d06caSMauro Carvalho Chehab .invert = 1, 8690c0d06caSMauro Carvalho Chehab }; 8700c0d06caSMauro Carvalho Chehab 8710c0d06caSMauro Carvalho Chehab static struct cxd2820r_config em28xx_cxd2820r_config = { 8720c0d06caSMauro Carvalho Chehab .i2c_address = (0xd8 >> 1), 8730c0d06caSMauro Carvalho Chehab .ts_mode = CXD2820R_TS_SERIAL, 8740c0d06caSMauro Carvalho Chehab }; 8750c0d06caSMauro Carvalho Chehab 8760c0d06caSMauro Carvalho Chehab static struct tda18271_config em28xx_cxd2820r_tda18271_config = { 8770c0d06caSMauro Carvalho Chehab .output_opt = TDA18271_OUTPUT_LT_OFF, 8780c0d06caSMauro Carvalho Chehab .gate = TDA18271_GATE_DIGITAL, 8790c0d06caSMauro Carvalho Chehab }; 8800c0d06caSMauro Carvalho Chehab 8810c0d06caSMauro Carvalho Chehab static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = { 8820c0d06caSMauro Carvalho Chehab .demod_address = (0x1e >> 1), 8830c0d06caSMauro Carvalho Chehab .disable_i2c_gate_ctrl = 1, 8840c0d06caSMauro Carvalho Chehab .no_tuner = 1, 8850c0d06caSMauro Carvalho Chehab .parallel_ts = 1, 8860c0d06caSMauro Carvalho Chehab }; 887fdf1bc9fSMauro Carvalho Chehab 8888c47311dSAlberto Mardegan static struct mt2060_config em28xx_mt2060_config = { 8898c47311dSAlberto Mardegan .i2c_address = 0x60, 8908c47311dSAlberto Mardegan }; 8918c47311dSAlberto Mardegan 8920c0d06caSMauro Carvalho Chehab static struct qt1010_config em28xx_qt1010_config = { 8930c0d06caSMauro Carvalho Chehab .i2c_address = 0x62 8940c0d06caSMauro Carvalho Chehab }; 8950c0d06caSMauro Carvalho Chehab 8964159d01bSMauro Carvalho Chehab static const struct mb86a20s_config c3tech_duo_mb86a20s_config = { 8974159d01bSMauro Carvalho Chehab .demod_address = 0x10, 8984159d01bSMauro Carvalho Chehab .is_serial = true, 8994159d01bSMauro Carvalho Chehab }; 9004159d01bSMauro Carvalho Chehab 9014159d01bSMauro Carvalho Chehab static struct tda18271_std_map mb86a20s_tda18271_config = { 9024159d01bSMauro Carvalho Chehab .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4, 9034159d01bSMauro Carvalho Chehab .if_lvl = 1, .rfagc_top = 0x37, }, 9044159d01bSMauro Carvalho Chehab }; 9054159d01bSMauro Carvalho Chehab 9064159d01bSMauro Carvalho Chehab static struct tda18271_config c3tech_duo_tda18271_config = { 9074159d01bSMauro Carvalho Chehab .std_map = &mb86a20s_tda18271_config, 9084159d01bSMauro Carvalho Chehab .gate = TDA18271_GATE_DIGITAL, 9094159d01bSMauro Carvalho Chehab .small_i2c = TDA18271_03_BYTE_CHUNK_INIT, 9104159d01bSMauro Carvalho Chehab }; 9114159d01bSMauro Carvalho Chehab 91238b2df95SDevin Heitmueller static struct tda18271_std_map drx_j_std_map = { 91338b2df95SDevin Heitmueller .atsc_6 = { .if_freq = 5000, .agc_mode = 3, .std = 0, .if_lvl = 1, 91438b2df95SDevin Heitmueller .rfagc_top = 0x37, }, 91538b2df95SDevin Heitmueller .qam_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3, .if_lvl = 1, 91638b2df95SDevin Heitmueller .rfagc_top = 0x37, }, 91738b2df95SDevin Heitmueller }; 91838b2df95SDevin Heitmueller 91938b2df95SDevin Heitmueller static struct tda18271_config pinnacle_80e_dvb_config = { 92038b2df95SDevin Heitmueller .std_map = &drx_j_std_map, 92138b2df95SDevin Heitmueller .gate = TDA18271_GATE_DIGITAL, 92238b2df95SDevin Heitmueller .role = TDA18271_MASTER, 92338b2df95SDevin Heitmueller }; 92438b2df95SDevin Heitmueller 9251586342eSKevin Cheng static struct lgdt3306a_config hauppauge_01595_lgdt3306a_config = { 9261586342eSKevin Cheng .qam_if_khz = 4000, 9271586342eSKevin Cheng .vsb_if_khz = 3250, 9281586342eSKevin Cheng .spectral_inversion = 0, 9291586342eSKevin Cheng .deny_i2c_rptr = 0, 9301586342eSKevin Cheng .mpeg_mode = LGDT3306A_MPEG_SERIAL, 9311586342eSKevin Cheng .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE, 9321586342eSKevin Cheng .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH, 9331586342eSKevin Cheng .xtalMHz = 25, 9341586342eSKevin Cheng }; 9351586342eSKevin Cheng 9360c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */ 9370c0d06caSMauro Carvalho Chehab 938f410b409SArnd Bergmann static noinline_for_stack int em28xx_attach_xc3028(u8 addr, struct em28xx *dev) 9390c0d06caSMauro Carvalho Chehab { 9400c0d06caSMauro Carvalho Chehab struct dvb_frontend *fe; 9410c0d06caSMauro Carvalho Chehab struct xc2028_config cfg; 942ee97207cSMauro Carvalho Chehab struct xc2028_ctrl ctl; 9430c0d06caSMauro Carvalho Chehab 9440c0d06caSMauro Carvalho Chehab memset(&cfg, 0, sizeof(cfg)); 945c7a45e5bSMauro Carvalho Chehab cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus]; 9460c0d06caSMauro Carvalho Chehab cfg.i2c_addr = addr; 9470c0d06caSMauro Carvalho Chehab 948ee97207cSMauro Carvalho Chehab memset(&ctl, 0, sizeof(ctl)); 949ee97207cSMauro Carvalho Chehab em28xx_setup_xc3028(dev, &ctl); 950ee97207cSMauro Carvalho Chehab cfg.ctrl = &ctl; 951ee97207cSMauro Carvalho Chehab 9520c0d06caSMauro Carvalho Chehab if (!dev->dvb->fe[0]) { 95329b05e22SMauro Carvalho Chehab dev_err(&dev->intf->dev, 954ce8591ffSMauro Carvalho Chehab "dvb frontend not attached. Can't attach xc3028\n"); 9550c0d06caSMauro Carvalho Chehab return -EINVAL; 9560c0d06caSMauro Carvalho Chehab } 9570c0d06caSMauro Carvalho Chehab 9580c0d06caSMauro Carvalho Chehab fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg); 9590c0d06caSMauro Carvalho Chehab if (!fe) { 96029b05e22SMauro Carvalho Chehab dev_err(&dev->intf->dev, "xc3028 attach failed\n"); 9610c0d06caSMauro Carvalho Chehab dvb_frontend_detach(dev->dvb->fe[0]); 9620c0d06caSMauro Carvalho Chehab dev->dvb->fe[0] = NULL; 9630c0d06caSMauro Carvalho Chehab return -EINVAL; 9640c0d06caSMauro Carvalho Chehab } 9650c0d06caSMauro Carvalho Chehab 96629b05e22SMauro Carvalho Chehab dev_info(&dev->intf->dev, "xc3028 attached\n"); 9670c0d06caSMauro Carvalho Chehab 9680c0d06caSMauro Carvalho Chehab return 0; 9690c0d06caSMauro Carvalho Chehab } 9700c0d06caSMauro Carvalho Chehab 9710c0d06caSMauro Carvalho Chehab /* ------------------------------------------------------------------ */ 9720c0d06caSMauro Carvalho Chehab 9730c0d06caSMauro Carvalho Chehab static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module, 9740c0d06caSMauro Carvalho Chehab struct em28xx *dev, struct device *device) 9750c0d06caSMauro Carvalho Chehab { 9760c0d06caSMauro Carvalho Chehab int result; 977e9ef88bdSMauro Carvalho Chehab bool create_rf_connector = false; 9780c0d06caSMauro Carvalho Chehab 9790c0d06caSMauro Carvalho Chehab mutex_init(&dvb->lock); 9800c0d06caSMauro Carvalho Chehab 9810c0d06caSMauro Carvalho Chehab /* register adapter */ 982ce8591ffSMauro Carvalho Chehab result = dvb_register_adapter(&dvb->adapter, 98329b05e22SMauro Carvalho Chehab dev_name(&dev->intf->dev), module, 984ce8591ffSMauro Carvalho Chehab device, adapter_nr); 9850c0d06caSMauro Carvalho Chehab if (result < 0) { 98629b05e22SMauro Carvalho Chehab dev_warn(&dev->intf->dev, 987ce8591ffSMauro Carvalho Chehab "dvb_register_adapter failed (errno = %d)\n", 9882a96f60eSMauro Carvalho Chehab result); 9890c0d06caSMauro Carvalho Chehab goto fail_adapter; 9900c0d06caSMauro Carvalho Chehab } 99137ecc7b1SMauro Carvalho Chehab #ifdef CONFIG_MEDIA_CONTROLLER_DVB 99237ecc7b1SMauro Carvalho Chehab dvb->adapter.mdev = dev->media_dev; 99337ecc7b1SMauro Carvalho Chehab #endif 9940c0d06caSMauro Carvalho Chehab 9950c0d06caSMauro Carvalho Chehab /* Ensure all frontends negotiate bus access */ 9960c0d06caSMauro Carvalho Chehab dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl; 9970c0d06caSMauro Carvalho Chehab if (dvb->fe[1]) 9980c0d06caSMauro Carvalho Chehab dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl; 9990c0d06caSMauro Carvalho Chehab 10003de09fbbSHans Verkuil dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus]; 10010c0d06caSMauro Carvalho Chehab 10020c0d06caSMauro Carvalho Chehab /* register frontend */ 10030c0d06caSMauro Carvalho Chehab result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]); 10040c0d06caSMauro Carvalho Chehab if (result < 0) { 100529b05e22SMauro Carvalho Chehab dev_warn(&dev->intf->dev, 1006ce8591ffSMauro Carvalho Chehab "dvb_register_frontend failed (errno = %d)\n", 10072a96f60eSMauro Carvalho Chehab result); 10080c0d06caSMauro Carvalho Chehab goto fail_frontend0; 10090c0d06caSMauro Carvalho Chehab } 10100c0d06caSMauro Carvalho Chehab 10110c0d06caSMauro Carvalho Chehab /* register 2nd frontend */ 10120c0d06caSMauro Carvalho Chehab if (dvb->fe[1]) { 10130c0d06caSMauro Carvalho Chehab result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]); 10140c0d06caSMauro Carvalho Chehab if (result < 0) { 101529b05e22SMauro Carvalho Chehab dev_warn(&dev->intf->dev, 1016ce8591ffSMauro Carvalho Chehab "2nd dvb_register_frontend failed (errno = %d)\n", 10172a96f60eSMauro Carvalho Chehab result); 10180c0d06caSMauro Carvalho Chehab goto fail_frontend1; 10190c0d06caSMauro Carvalho Chehab } 10200c0d06caSMauro Carvalho Chehab } 10210c0d06caSMauro Carvalho Chehab 10220c0d06caSMauro Carvalho Chehab /* register demux stuff */ 10230c0d06caSMauro Carvalho Chehab dvb->demux.dmx.capabilities = 10240c0d06caSMauro Carvalho Chehab DMX_TS_FILTERING | DMX_SECTION_FILTERING | 10250c0d06caSMauro Carvalho Chehab DMX_MEMORY_BASED_FILTERING; 10260c0d06caSMauro Carvalho Chehab dvb->demux.priv = dvb; 10270c0d06caSMauro Carvalho Chehab dvb->demux.filternum = 256; 10280c0d06caSMauro Carvalho Chehab dvb->demux.feednum = 256; 10290c0d06caSMauro Carvalho Chehab dvb->demux.start_feed = em28xx_start_feed; 10300c0d06caSMauro Carvalho Chehab dvb->demux.stop_feed = em28xx_stop_feed; 10310c0d06caSMauro Carvalho Chehab 10320c0d06caSMauro Carvalho Chehab result = dvb_dmx_init(&dvb->demux); 10330c0d06caSMauro Carvalho Chehab if (result < 0) { 103429b05e22SMauro Carvalho Chehab dev_warn(&dev->intf->dev, 1035ce8591ffSMauro Carvalho Chehab "dvb_dmx_init failed (errno = %d)\n", 1036ce8591ffSMauro Carvalho Chehab result); 10370c0d06caSMauro Carvalho Chehab goto fail_dmx; 10380c0d06caSMauro Carvalho Chehab } 10390c0d06caSMauro Carvalho Chehab 10400c0d06caSMauro Carvalho Chehab dvb->dmxdev.filternum = 256; 10410c0d06caSMauro Carvalho Chehab dvb->dmxdev.demux = &dvb->demux.dmx; 10420c0d06caSMauro Carvalho Chehab dvb->dmxdev.capabilities = 0; 10430c0d06caSMauro Carvalho Chehab result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); 10440c0d06caSMauro Carvalho Chehab if (result < 0) { 104529b05e22SMauro Carvalho Chehab dev_warn(&dev->intf->dev, 1046ce8591ffSMauro Carvalho Chehab "dvb_dmxdev_init failed (errno = %d)\n", 1047ce8591ffSMauro Carvalho Chehab result); 10480c0d06caSMauro Carvalho Chehab goto fail_dmxdev; 10490c0d06caSMauro Carvalho Chehab } 10500c0d06caSMauro Carvalho Chehab 10510c0d06caSMauro Carvalho Chehab dvb->fe_hw.source = DMX_FRONTEND_0; 10520c0d06caSMauro Carvalho Chehab result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); 10530c0d06caSMauro Carvalho Chehab if (result < 0) { 105429b05e22SMauro Carvalho Chehab dev_warn(&dev->intf->dev, 1055ce8591ffSMauro Carvalho Chehab "add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", 10562a96f60eSMauro Carvalho Chehab result); 10570c0d06caSMauro Carvalho Chehab goto fail_fe_hw; 10580c0d06caSMauro Carvalho Chehab } 10590c0d06caSMauro Carvalho Chehab 10600c0d06caSMauro Carvalho Chehab dvb->fe_mem.source = DMX_MEMORY_FE; 10610c0d06caSMauro Carvalho Chehab result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); 10620c0d06caSMauro Carvalho Chehab if (result < 0) { 106329b05e22SMauro Carvalho Chehab dev_warn(&dev->intf->dev, 1064ce8591ffSMauro Carvalho Chehab "add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", 10652a96f60eSMauro Carvalho Chehab result); 10660c0d06caSMauro Carvalho Chehab goto fail_fe_mem; 10670c0d06caSMauro Carvalho Chehab } 10680c0d06caSMauro Carvalho Chehab 10690c0d06caSMauro Carvalho Chehab result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); 10700c0d06caSMauro Carvalho Chehab if (result < 0) { 107129b05e22SMauro Carvalho Chehab dev_warn(&dev->intf->dev, 1072ce8591ffSMauro Carvalho Chehab "connect_frontend failed (errno = %d)\n", 1073ce8591ffSMauro Carvalho Chehab result); 10740c0d06caSMauro Carvalho Chehab goto fail_fe_conn; 10750c0d06caSMauro Carvalho Chehab } 10760c0d06caSMauro Carvalho Chehab 10770c0d06caSMauro Carvalho Chehab /* register network adapter */ 10780c0d06caSMauro Carvalho Chehab dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); 107937ecc7b1SMauro Carvalho Chehab 1080e9ef88bdSMauro Carvalho Chehab /* If the analog part won't create RF connectors, DVB will do it */ 1081fe8d54f0SMauro Carvalho Chehab if (!dev->has_video || dev->tuner_type == TUNER_ABSENT) 1082e9ef88bdSMauro Carvalho Chehab create_rf_connector = true; 1083e9ef88bdSMauro Carvalho Chehab 1084e9ef88bdSMauro Carvalho Chehab result = dvb_create_media_graph(&dvb->adapter, create_rf_connector); 108537ecc7b1SMauro Carvalho Chehab if (result < 0) 108637ecc7b1SMauro Carvalho Chehab goto fail_create_graph; 108737ecc7b1SMauro Carvalho Chehab 10880c0d06caSMauro Carvalho Chehab return 0; 10890c0d06caSMauro Carvalho Chehab 109037ecc7b1SMauro Carvalho Chehab fail_create_graph: 109137ecc7b1SMauro Carvalho Chehab dvb_net_release(&dvb->net); 10920c0d06caSMauro Carvalho Chehab fail_fe_conn: 10930c0d06caSMauro Carvalho Chehab dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); 10940c0d06caSMauro Carvalho Chehab fail_fe_mem: 10950c0d06caSMauro Carvalho Chehab dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); 10960c0d06caSMauro Carvalho Chehab fail_fe_hw: 10970c0d06caSMauro Carvalho Chehab dvb_dmxdev_release(&dvb->dmxdev); 10980c0d06caSMauro Carvalho Chehab fail_dmxdev: 10990c0d06caSMauro Carvalho Chehab dvb_dmx_release(&dvb->demux); 11000c0d06caSMauro Carvalho Chehab fail_dmx: 11010c0d06caSMauro Carvalho Chehab if (dvb->fe[1]) 11020c0d06caSMauro Carvalho Chehab dvb_unregister_frontend(dvb->fe[1]); 11030c0d06caSMauro Carvalho Chehab dvb_unregister_frontend(dvb->fe[0]); 11040c0d06caSMauro Carvalho Chehab fail_frontend1: 11050c0d06caSMauro Carvalho Chehab if (dvb->fe[1]) 11060c0d06caSMauro Carvalho Chehab dvb_frontend_detach(dvb->fe[1]); 11070c0d06caSMauro Carvalho Chehab fail_frontend0: 11080c0d06caSMauro Carvalho Chehab dvb_frontend_detach(dvb->fe[0]); 11090c0d06caSMauro Carvalho Chehab dvb_unregister_adapter(&dvb->adapter); 11100c0d06caSMauro Carvalho Chehab fail_adapter: 11110c0d06caSMauro Carvalho Chehab return result; 11120c0d06caSMauro Carvalho Chehab } 11130c0d06caSMauro Carvalho Chehab 11140c0d06caSMauro Carvalho Chehab static void em28xx_unregister_dvb(struct em28xx_dvb *dvb) 11150c0d06caSMauro Carvalho Chehab { 11160c0d06caSMauro Carvalho Chehab dvb_net_release(&dvb->net); 11170c0d06caSMauro Carvalho Chehab dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); 11180c0d06caSMauro Carvalho Chehab dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); 11190c0d06caSMauro Carvalho Chehab dvb_dmxdev_release(&dvb->dmxdev); 11200c0d06caSMauro Carvalho Chehab dvb_dmx_release(&dvb->demux); 11210c0d06caSMauro Carvalho Chehab if (dvb->fe[1]) 11220c0d06caSMauro Carvalho Chehab dvb_unregister_frontend(dvb->fe[1]); 11230c0d06caSMauro Carvalho Chehab dvb_unregister_frontend(dvb->fe[0]); 11240c0d06caSMauro Carvalho Chehab if (dvb->fe[1] && !dvb->dont_attach_fe1) 11250c0d06caSMauro Carvalho Chehab dvb_frontend_detach(dvb->fe[1]); 11260c0d06caSMauro Carvalho Chehab dvb_frontend_detach(dvb->fe[0]); 11270c0d06caSMauro Carvalho Chehab dvb_unregister_adapter(&dvb->adapter); 11280c0d06caSMauro Carvalho Chehab } 11290c0d06caSMauro Carvalho Chehab 1130ad32495bSMauro Carvalho Chehab static int em28174_dvb_init_pctv_460e(struct em28xx *dev) 1131f410b409SArnd Bergmann { 1132f410b409SArnd Bergmann struct em28xx_dvb *dvb = dev->dvb; 1133f410b409SArnd Bergmann struct tda10071_platform_data tda10071_pdata = {}; 1134f410b409SArnd Bergmann struct a8293_platform_data a8293_pdata = {}; 1135f410b409SArnd Bergmann 1136f410b409SArnd Bergmann /* attach demod + tuner combo */ 1137ad32495bSMauro Carvalho Chehab tda10071_pdata.clk = 40444000; /* 40.444 MHz */ 1138ad32495bSMauro Carvalho Chehab tda10071_pdata.i2c_wr_max = 64; 1139ad32495bSMauro Carvalho Chehab tda10071_pdata.ts_mode = TDA10071_TS_SERIAL; 1140ad32495bSMauro Carvalho Chehab tda10071_pdata.pll_multiplier = 20; 1141ad32495bSMauro Carvalho Chehab tda10071_pdata.tuner_i2c_addr = 0x14; 1142ad32495bSMauro Carvalho Chehab 1143ad32495bSMauro Carvalho Chehab dvb->i2c_client_demod = dvb_module_probe("tda10071", "tda10071_cx24118", 1144ad32495bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 1145ad32495bSMauro Carvalho Chehab 0x55, &tda10071_pdata); 1146ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_demod) 1147ad32495bSMauro Carvalho Chehab return -ENODEV; 1148ad32495bSMauro Carvalho Chehab 1149ad32495bSMauro Carvalho Chehab dvb->fe[0] = tda10071_pdata.get_dvb_frontend(dvb->i2c_client_demod); 1150f410b409SArnd Bergmann 1151f410b409SArnd Bergmann /* attach SEC */ 1152f410b409SArnd Bergmann a8293_pdata.dvb_frontend = dvb->fe[0]; 1153ad32495bSMauro Carvalho Chehab 1154ad32495bSMauro Carvalho Chehab dvb->i2c_client_sec = dvb_module_probe("a8293", NULL, 1155ad32495bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 1156ad32495bSMauro Carvalho Chehab 0x08, &a8293_pdata); 1157ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_sec) { 1158ad32495bSMauro Carvalho Chehab dvb_module_release(dvb->i2c_client_demod); 1159ad32495bSMauro Carvalho Chehab return -ENODEV; 1160f410b409SArnd Bergmann } 1161f410b409SArnd Bergmann 1162ad32495bSMauro Carvalho Chehab return 0; 1163ad32495bSMauro Carvalho Chehab } 1164ad32495bSMauro Carvalho Chehab 1165ad32495bSMauro Carvalho Chehab static int em28178_dvb_init_pctv_461e(struct em28xx *dev) 1166f410b409SArnd Bergmann { 1167f410b409SArnd Bergmann struct em28xx_dvb *dvb = dev->dvb; 1168f410b409SArnd Bergmann struct i2c_adapter *i2c_adapter; 1169f410b409SArnd Bergmann struct m88ds3103_platform_data m88ds3103_pdata = {}; 1170f410b409SArnd Bergmann struct ts2020_config ts2020_config = {}; 1171f410b409SArnd Bergmann struct a8293_platform_data a8293_pdata = {}; 1172f410b409SArnd Bergmann 1173f410b409SArnd Bergmann /* attach demod */ 1174f410b409SArnd Bergmann m88ds3103_pdata.clk = 27000000; 1175f410b409SArnd Bergmann m88ds3103_pdata.i2c_wr_max = 33; 1176f410b409SArnd Bergmann m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL; 1177f410b409SArnd Bergmann m88ds3103_pdata.ts_clk = 16000; 1178f410b409SArnd Bergmann m88ds3103_pdata.ts_clk_pol = 1; 1179f410b409SArnd Bergmann m88ds3103_pdata.agc = 0x99; 1180ad32495bSMauro Carvalho Chehab 1181ad32495bSMauro Carvalho Chehab dvb->i2c_client_demod = dvb_module_probe("m88ds3103", NULL, 1182ad32495bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 1183ad32495bSMauro Carvalho Chehab 0x68, &m88ds3103_pdata); 1184ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_demod) 1185ad32495bSMauro Carvalho Chehab return -ENODEV; 1186ad32495bSMauro Carvalho Chehab 1187ad32495bSMauro Carvalho Chehab dvb->fe[0] = m88ds3103_pdata.get_dvb_frontend(dvb->i2c_client_demod); 1188ad32495bSMauro Carvalho Chehab i2c_adapter = m88ds3103_pdata.get_i2c_adapter(dvb->i2c_client_demod); 1189f410b409SArnd Bergmann 1190f410b409SArnd Bergmann /* attach tuner */ 1191f410b409SArnd Bergmann ts2020_config.fe = dvb->fe[0]; 1192ad32495bSMauro Carvalho Chehab 1193ad32495bSMauro Carvalho Chehab dvb->i2c_client_tuner = dvb_module_probe("ts2020", "ts2022", 1194ad32495bSMauro Carvalho Chehab i2c_adapter, 1195ad32495bSMauro Carvalho Chehab 0x60, &ts2020_config); 1196ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_tuner) { 1197ad32495bSMauro Carvalho Chehab dvb_module_release(dvb->i2c_client_demod); 1198ad32495bSMauro Carvalho Chehab return -ENODEV; 1199f410b409SArnd Bergmann } 1200ad32495bSMauro Carvalho Chehab 1201f410b409SArnd Bergmann /* delegate signal strength measurement to tuner */ 1202f410b409SArnd Bergmann dvb->fe[0]->ops.read_signal_strength = 1203f410b409SArnd Bergmann dvb->fe[0]->ops.tuner_ops.get_rf_strength; 1204f410b409SArnd Bergmann 1205f410b409SArnd Bergmann /* attach SEC */ 1206f410b409SArnd Bergmann a8293_pdata.dvb_frontend = dvb->fe[0]; 1207ad32495bSMauro Carvalho Chehab dvb->i2c_client_sec = dvb_module_probe("a8293", NULL, 1208ad32495bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 1209ad32495bSMauro Carvalho Chehab 0x08, &a8293_pdata); 1210ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_sec) { 1211ad32495bSMauro Carvalho Chehab dvb_module_release(dvb->i2c_client_tuner); 1212ad32495bSMauro Carvalho Chehab dvb_module_release(dvb->i2c_client_demod); 1213ad32495bSMauro Carvalho Chehab return -ENODEV; 1214f410b409SArnd Bergmann } 1215f410b409SArnd Bergmann 1216ad32495bSMauro Carvalho Chehab return 0; 1217ad32495bSMauro Carvalho Chehab } 1218ad32495bSMauro Carvalho Chehab 1219ad32495bSMauro Carvalho Chehab static int em28178_dvb_init_pctv_292e(struct em28xx *dev) 1220f410b409SArnd Bergmann { 1221f410b409SArnd Bergmann struct em28xx_dvb *dvb = dev->dvb; 1222f410b409SArnd Bergmann struct i2c_adapter *adapter; 1223ad32495bSMauro Carvalho Chehab struct si2168_config si2168_config = {}; 1224ad32495bSMauro Carvalho Chehab struct si2157_config si2157_config = {}; 1225f410b409SArnd Bergmann 1226f410b409SArnd Bergmann /* attach demod */ 1227f410b409SArnd Bergmann si2168_config.i2c_adapter = &adapter; 1228f410b409SArnd Bergmann si2168_config.fe = &dvb->fe[0]; 1229f410b409SArnd Bergmann si2168_config.ts_mode = SI2168_TS_PARALLEL; 1230*309d4c4cSBrad Love si2168_config.spectral_inversion = true; 1231f410b409SArnd Bergmann 1232ad32495bSMauro Carvalho Chehab dvb->i2c_client_demod = dvb_module_probe("si2168", NULL, 1233ad32495bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 1234ad32495bSMauro Carvalho Chehab 0x64, &si2168_config); 1235ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_demod) 1236ad32495bSMauro Carvalho Chehab return -ENODEV; 1237f410b409SArnd Bergmann 1238f410b409SArnd Bergmann /* attach tuner */ 1239f410b409SArnd Bergmann si2157_config.fe = dvb->fe[0]; 1240f410b409SArnd Bergmann si2157_config.if_port = 1; 1241f410b409SArnd Bergmann #ifdef CONFIG_MEDIA_CONTROLLER_DVB 1242f410b409SArnd Bergmann si2157_config.mdev = dev->media_dev; 1243f410b409SArnd Bergmann #endif 1244ad32495bSMauro Carvalho Chehab dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL, 1245ad32495bSMauro Carvalho Chehab adapter, 1246ad32495bSMauro Carvalho Chehab 0x60, &si2157_config); 1247ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_tuner) { 1248ad32495bSMauro Carvalho Chehab dvb_module_release(dvb->i2c_client_demod); 1249ad32495bSMauro Carvalho Chehab return -ENODEV; 1250f410b409SArnd Bergmann } 1251f410b409SArnd Bergmann dvb->fe[0]->ops.set_lna = em28xx_pctv_292e_set_lna; 1252ad32495bSMauro Carvalho Chehab 1253ad32495bSMauro Carvalho Chehab return 0; 1254f410b409SArnd Bergmann } 1255f410b409SArnd Bergmann 1256ad32495bSMauro Carvalho Chehab static int em28178_dvb_init_terratec_t2_stick_hd(struct em28xx *dev) 1257f410b409SArnd Bergmann { 1258f410b409SArnd Bergmann struct em28xx_dvb *dvb = dev->dvb; 1259f410b409SArnd Bergmann struct i2c_adapter *adapter; 1260ad32495bSMauro Carvalho Chehab struct si2168_config si2168_config = {}; 1261ad32495bSMauro Carvalho Chehab struct si2157_config si2157_config = {}; 1262f410b409SArnd Bergmann 1263f410b409SArnd Bergmann /* attach demod */ 1264f410b409SArnd Bergmann si2168_config.i2c_adapter = &adapter; 1265f410b409SArnd Bergmann si2168_config.fe = &dvb->fe[0]; 1266f410b409SArnd Bergmann si2168_config.ts_mode = SI2168_TS_PARALLEL; 1267f410b409SArnd Bergmann 1268ad32495bSMauro Carvalho Chehab dvb->i2c_client_demod = dvb_module_probe("si2168", NULL, 1269ad32495bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 1270ad32495bSMauro Carvalho Chehab 0x64, &si2168_config); 1271ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_demod) 1272ad32495bSMauro Carvalho Chehab return -ENODEV; 1273f410b409SArnd Bergmann 1274f410b409SArnd Bergmann /* attach tuner */ 1275f410b409SArnd Bergmann memset(&si2157_config, 0, sizeof(si2157_config)); 1276f410b409SArnd Bergmann si2157_config.fe = dvb->fe[0]; 1277f410b409SArnd Bergmann si2157_config.if_port = 0; 1278f410b409SArnd Bergmann #ifdef CONFIG_MEDIA_CONTROLLER_DVB 1279f410b409SArnd Bergmann si2157_config.mdev = dev->media_dev; 1280f410b409SArnd Bergmann #endif 1281ad32495bSMauro Carvalho Chehab dvb->i2c_client_tuner = dvb_module_probe("si2157", "si2146", 1282ad32495bSMauro Carvalho Chehab adapter, 1283ad32495bSMauro Carvalho Chehab 0x60, &si2157_config); 1284ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_tuner) { 1285ad32495bSMauro Carvalho Chehab dvb_module_release(dvb->i2c_client_demod); 1286ad32495bSMauro Carvalho Chehab return -ENODEV; 1287f410b409SArnd Bergmann } 1288f410b409SArnd Bergmann 1289ad32495bSMauro Carvalho Chehab return 0; 1290f410b409SArnd Bergmann } 1291f410b409SArnd Bergmann 1292ad32495bSMauro Carvalho Chehab static int em28178_dvb_init_plex_px_bcud(struct em28xx *dev) 1293f410b409SArnd Bergmann { 1294f410b409SArnd Bergmann struct em28xx_dvb *dvb = dev->dvb; 1295ad32495bSMauro Carvalho Chehab struct tc90522_config tc90522_config = {}; 1296ad32495bSMauro Carvalho Chehab struct qm1d1c0042_config qm1d1c0042_config = {}; 1297f410b409SArnd Bergmann 1298f410b409SArnd Bergmann /* attach demod */ 1299ad32495bSMauro Carvalho Chehab dvb->i2c_client_demod = dvb_module_probe("tc90522", "tc90522sat", 1300ad32495bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 1301ad32495bSMauro Carvalho Chehab 0x15, &tc90522_config); 1302ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_demod) 1303ad32495bSMauro Carvalho Chehab return -ENODEV; 1304f410b409SArnd Bergmann 1305f410b409SArnd Bergmann /* attach tuner */ 1306f410b409SArnd Bergmann qm1d1c0042_config.fe = tc90522_config.fe; 1307f410b409SArnd Bergmann qm1d1c0042_config.lpf = 1; 1308ad32495bSMauro Carvalho Chehab 1309ad32495bSMauro Carvalho Chehab dvb->i2c_client_tuner = dvb_module_probe("qm1d1c0042", NULL, 1310ad32495bSMauro Carvalho Chehab tc90522_config.tuner_i2c, 1311ad32495bSMauro Carvalho Chehab 0x61, &qm1d1c0042_config); 1312ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_tuner) { 1313ad32495bSMauro Carvalho Chehab dvb_module_release(dvb->i2c_client_demod); 1314ad32495bSMauro Carvalho Chehab return -ENODEV; 1315f410b409SArnd Bergmann } 1316f410b409SArnd Bergmann 1317ad32495bSMauro Carvalho Chehab dvb->fe[0] = tc90522_config.fe; 1318ad32495bSMauro Carvalho Chehab px_bcud_init(dev); 1319ad32495bSMauro Carvalho Chehab 1320ad32495bSMauro Carvalho Chehab return 0; 1321ad32495bSMauro Carvalho Chehab } 1322ad32495bSMauro Carvalho Chehab 1323ad32495bSMauro Carvalho Chehab static int em28174_dvb_init_hauppauge_wintv_dualhd_dvb(struct em28xx *dev) 1324f410b409SArnd Bergmann { 1325f410b409SArnd Bergmann struct em28xx_dvb *dvb = dev->dvb; 1326f410b409SArnd Bergmann struct i2c_adapter *adapter; 1327ad32495bSMauro Carvalho Chehab struct si2168_config si2168_config = {}; 1328ad32495bSMauro Carvalho Chehab struct si2157_config si2157_config = {}; 1329ad32495bSMauro Carvalho Chehab unsigned char addr; 1330f410b409SArnd Bergmann 1331f410b409SArnd Bergmann /* attach demod */ 1332f410b409SArnd Bergmann si2168_config.i2c_adapter = &adapter; 1333f410b409SArnd Bergmann si2168_config.fe = &dvb->fe[0]; 1334f410b409SArnd Bergmann si2168_config.ts_mode = SI2168_TS_SERIAL; 1335*309d4c4cSBrad Love si2168_config.spectral_inversion = true; 1336ad32495bSMauro Carvalho Chehab addr = (dev->ts == PRIMARY_TS) ? 0x64 : 0x67; 1337f410b409SArnd Bergmann 1338ad32495bSMauro Carvalho Chehab dvb->i2c_client_demod = dvb_module_probe("si2168", NULL, 1339ad32495bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 1340ad32495bSMauro Carvalho Chehab addr, &si2168_config); 1341ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_demod) 1342ad32495bSMauro Carvalho Chehab return -ENODEV; 1343f410b409SArnd Bergmann 1344f410b409SArnd Bergmann /* attach tuner */ 1345f410b409SArnd Bergmann memset(&si2157_config, 0, sizeof(si2157_config)); 1346f410b409SArnd Bergmann si2157_config.fe = dvb->fe[0]; 1347f410b409SArnd Bergmann si2157_config.if_port = 1; 1348f410b409SArnd Bergmann #ifdef CONFIG_MEDIA_CONTROLLER_DVB 1349f410b409SArnd Bergmann si2157_config.mdev = dev->media_dev; 1350f410b409SArnd Bergmann #endif 1351ad32495bSMauro Carvalho Chehab addr = (dev->ts == PRIMARY_TS) ? 0x60 : 0x63; 1352ad32495bSMauro Carvalho Chehab 1353ad32495bSMauro Carvalho Chehab dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL, 1354ad32495bSMauro Carvalho Chehab adapter, 1355ad32495bSMauro Carvalho Chehab addr, &si2157_config); 1356ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_tuner) { 1357ad32495bSMauro Carvalho Chehab dvb_module_release(dvb->i2c_client_demod); 1358ad32495bSMauro Carvalho Chehab return -ENODEV; 1359f410b409SArnd Bergmann } 1360f410b409SArnd Bergmann 1361ad32495bSMauro Carvalho Chehab return 0; 1362f410b409SArnd Bergmann } 1363f410b409SArnd Bergmann 1364f410b409SArnd Bergmann static int em28174_dvb_init_hauppauge_wintv_dualhd_01595(struct em28xx *dev) 1365f410b409SArnd Bergmann { 1366f410b409SArnd Bergmann struct em28xx_dvb *dvb = dev->dvb; 1367f410b409SArnd Bergmann struct i2c_adapter *adapter; 1368ad32495bSMauro Carvalho Chehab struct lgdt3306a_config lgdt3306a_config = {}; 1369f410b409SArnd Bergmann struct si2157_config si2157_config = {}; 1370ad32495bSMauro Carvalho Chehab unsigned char addr; 1371f410b409SArnd Bergmann 1372f410b409SArnd Bergmann /* attach demod */ 1373f410b409SArnd Bergmann lgdt3306a_config = hauppauge_01595_lgdt3306a_config; 1374f410b409SArnd Bergmann lgdt3306a_config.fe = &dvb->fe[0]; 1375f410b409SArnd Bergmann lgdt3306a_config.i2c_adapter = &adapter; 1376ad32495bSMauro Carvalho Chehab addr = (dev->ts == PRIMARY_TS) ? 0x59 : 0x0e; 1377f410b409SArnd Bergmann 1378ad32495bSMauro Carvalho Chehab dvb->i2c_client_demod = dvb_module_probe("lgdt3306a", NULL, 1379ad32495bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 1380ad32495bSMauro Carvalho Chehab addr, &lgdt3306a_config); 1381ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_demod) 1382ad32495bSMauro Carvalho Chehab return -ENODEV; 1383f410b409SArnd Bergmann 1384f410b409SArnd Bergmann /* attach tuner */ 1385f410b409SArnd Bergmann si2157_config.fe = dvb->fe[0]; 1386f410b409SArnd Bergmann si2157_config.if_port = 1; 1387f410b409SArnd Bergmann si2157_config.inversion = 1; 1388f410b409SArnd Bergmann #ifdef CONFIG_MEDIA_CONTROLLER_DVB 1389f410b409SArnd Bergmann si2157_config.mdev = dev->media_dev; 1390f410b409SArnd Bergmann #endif 1391ad32495bSMauro Carvalho Chehab addr = (dev->ts == PRIMARY_TS) ? 0x60 : 0x62; 1392f410b409SArnd Bergmann 1393ad32495bSMauro Carvalho Chehab dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL, 1394ad32495bSMauro Carvalho Chehab adapter, 1395ad32495bSMauro Carvalho Chehab 0x60, &si2157_config); 1396ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_tuner) { 1397ad32495bSMauro Carvalho Chehab dvb_module_release(dvb->i2c_client_demod); 1398ad32495bSMauro Carvalho Chehab return -ENODEV; 1399f410b409SArnd Bergmann } 1400f410b409SArnd Bergmann 1401ad32495bSMauro Carvalho Chehab return 0; 1402f410b409SArnd Bergmann } 1403ad32495bSMauro Carvalho Chehab 14040c0d06caSMauro Carvalho Chehab static int em28xx_dvb_init(struct em28xx *dev) 14050c0d06caSMauro Carvalho Chehab { 1406be7fd3c3SBrad Love int result = 0, dvb_alt = 0; 14070c0d06caSMauro Carvalho Chehab struct em28xx_dvb *dvb; 1408be7fd3c3SBrad Love struct usb_device *udev; 14090c0d06caSMauro Carvalho Chehab 1410822b8deaSMauro Carvalho Chehab if (dev->is_audio_only) { 1411822b8deaSMauro Carvalho Chehab /* Shouldn't initialize IR for this interface */ 1412822b8deaSMauro Carvalho Chehab return 0; 1413822b8deaSMauro Carvalho Chehab } 1414822b8deaSMauro Carvalho Chehab 14150c0d06caSMauro Carvalho Chehab if (!dev->board.has_dvb) { 14160c0d06caSMauro Carvalho Chehab /* This device does not support the extension */ 14170c0d06caSMauro Carvalho Chehab return 0; 14180c0d06caSMauro Carvalho Chehab } 14190c0d06caSMauro Carvalho Chehab 142029b05e22SMauro Carvalho Chehab dev_info(&dev->intf->dev, "Binding DVB extension\n"); 14219634614fSMauro Carvalho Chehab 1422fe8d54f0SMauro Carvalho Chehab dvb = kzalloc(sizeof(*dvb), GFP_KERNEL); 14238314d402SMauro Carvalho Chehab if (!dvb) 14240c0d06caSMauro Carvalho Chehab return -ENOMEM; 14258314d402SMauro Carvalho Chehab 14260c0d06caSMauro Carvalho Chehab dev->dvb = dvb; 1427fe8d54f0SMauro Carvalho Chehab dvb->fe[0] = NULL; 1428fe8d54f0SMauro Carvalho Chehab dvb->fe[1] = NULL; 14290c0d06caSMauro Carvalho Chehab 143027ba0dacSFrank Schaefer /* pre-allocate DVB usb transfer buffers */ 143127ba0dacSFrank Schaefer if (dev->dvb_xfer_bulk) { 143227ba0dacSFrank Schaefer result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE, 143327ba0dacSFrank Schaefer dev->dvb_xfer_bulk, 143427ba0dacSFrank Schaefer EM28XX_DVB_NUM_BUFS, 143527ba0dacSFrank Schaefer 512, 143627ba0dacSFrank Schaefer EM28XX_DVB_BULK_PACKET_MULTIPLIER); 143727ba0dacSFrank Schaefer } else { 143827ba0dacSFrank Schaefer result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE, 143927ba0dacSFrank Schaefer dev->dvb_xfer_bulk, 144027ba0dacSFrank Schaefer EM28XX_DVB_NUM_BUFS, 144127ba0dacSFrank Schaefer dev->dvb_max_pkt_size_isoc, 144227ba0dacSFrank Schaefer EM28XX_DVB_NUM_ISOC_PACKETS); 144327ba0dacSFrank Schaefer } 144427ba0dacSFrank Schaefer if (result) { 144529b05e22SMauro Carvalho Chehab dev_err(&dev->intf->dev, 1446ce8591ffSMauro Carvalho Chehab "failed to pre-allocate USB transfer buffers for DVB.\n"); 144727ba0dacSFrank Schaefer kfree(dvb); 144827ba0dacSFrank Schaefer dev->dvb = NULL; 144927ba0dacSFrank Schaefer return result; 145027ba0dacSFrank Schaefer } 145127ba0dacSFrank Schaefer 14520c0d06caSMauro Carvalho Chehab mutex_lock(&dev->lock); 14530c0d06caSMauro Carvalho Chehab em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); 14540c0d06caSMauro Carvalho Chehab /* init frontend */ 14550c0d06caSMauro Carvalho Chehab switch (dev->model) { 14560c0d06caSMauro Carvalho Chehab case EM2874_BOARD_LEADERSHIP_ISDBT: 14570c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(s921_attach, 1458fe8d54f0SMauro Carvalho Chehab &sharp_isdbt, 1459fe8d54f0SMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 14600c0d06caSMauro Carvalho Chehab 14610c0d06caSMauro Carvalho Chehab if (!dvb->fe[0]) { 14620c0d06caSMauro Carvalho Chehab result = -EINVAL; 14630c0d06caSMauro Carvalho Chehab goto out_free; 14640c0d06caSMauro Carvalho Chehab } 14650c0d06caSMauro Carvalho Chehab 14660c0d06caSMauro Carvalho Chehab break; 14670c0d06caSMauro Carvalho Chehab case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850: 14680c0d06caSMauro Carvalho Chehab case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950: 14690c0d06caSMauro Carvalho Chehab case EM2880_BOARD_PINNACLE_PCTV_HD_PRO: 14700c0d06caSMauro Carvalho Chehab case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600: 14710c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(lgdt330x_attach, 14720c0d06caSMauro Carvalho Chehab &em2880_lgdt3303_dev, 1473c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 14740c0d06caSMauro Carvalho Chehab if (em28xx_attach_xc3028(0x61, dev) < 0) { 14750c0d06caSMauro Carvalho Chehab result = -EINVAL; 14760c0d06caSMauro Carvalho Chehab goto out_free; 14770c0d06caSMauro Carvalho Chehab } 14780c0d06caSMauro Carvalho Chehab break; 14790c0d06caSMauro Carvalho Chehab case EM2880_BOARD_KWORLD_DVB_310U: 14800c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(zl10353_attach, 14810c0d06caSMauro Carvalho Chehab &em28xx_zl10353_with_xc3028, 1482c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 14830c0d06caSMauro Carvalho Chehab if (em28xx_attach_xc3028(0x61, dev) < 0) { 14840c0d06caSMauro Carvalho Chehab result = -EINVAL; 14850c0d06caSMauro Carvalho Chehab goto out_free; 14860c0d06caSMauro Carvalho Chehab } 14870c0d06caSMauro Carvalho Chehab break; 14880c0d06caSMauro Carvalho Chehab case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: 14890c0d06caSMauro Carvalho Chehab case EM2882_BOARD_TERRATEC_HYBRID_XS: 14900c0d06caSMauro Carvalho Chehab case EM2880_BOARD_EMPIRE_DUAL_TV: 14910c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(zl10353_attach, 14920c0d06caSMauro Carvalho Chehab &em28xx_zl10353_xc3028_no_i2c_gate, 1493c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 14940c0d06caSMauro Carvalho Chehab if (em28xx_attach_xc3028(0x61, dev) < 0) { 14950c0d06caSMauro Carvalho Chehab result = -EINVAL; 14960c0d06caSMauro Carvalho Chehab goto out_free; 14970c0d06caSMauro Carvalho Chehab } 14980c0d06caSMauro Carvalho Chehab break; 14990c0d06caSMauro Carvalho Chehab case EM2880_BOARD_TERRATEC_HYBRID_XS: 15000c0d06caSMauro Carvalho Chehab case EM2880_BOARD_TERRATEC_HYBRID_XS_FR: 15010c0d06caSMauro Carvalho Chehab case EM2881_BOARD_PINNACLE_HYBRID_PRO: 15020c0d06caSMauro Carvalho Chehab case EM2882_BOARD_DIKOM_DK300: 15030c0d06caSMauro Carvalho Chehab case EM2882_BOARD_KWORLD_VS_DVBT: 1504fe8d54f0SMauro Carvalho Chehab /* 1505fe8d54f0SMauro Carvalho Chehab * Those boards could have either a zl10353 or a mt352. 1506fe8d54f0SMauro Carvalho Chehab * If the chip id isn't for zl10353, try mt352. 1507fe8d54f0SMauro Carvalho Chehab */ 15080c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(zl10353_attach, 15090c0d06caSMauro Carvalho Chehab &em28xx_zl10353_xc3028_no_i2c_gate, 1510c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 1511fe8d54f0SMauro Carvalho Chehab if (!dvb->fe[0]) 15120c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(mt352_attach, 15130c0d06caSMauro Carvalho Chehab &terratec_xs_mt352_cfg, 1514c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 15150c0d06caSMauro Carvalho Chehab 15160c0d06caSMauro Carvalho Chehab if (em28xx_attach_xc3028(0x61, dev) < 0) { 15170c0d06caSMauro Carvalho Chehab result = -EINVAL; 15180c0d06caSMauro Carvalho Chehab goto out_free; 15190c0d06caSMauro Carvalho Chehab } 15200c0d06caSMauro Carvalho Chehab break; 15218c47311dSAlberto Mardegan case EM2870_BOARD_TERRATEC_XS_MT2060: 15228c47311dSAlberto Mardegan dvb->fe[0] = dvb_attach(zl10353_attach, 15238c47311dSAlberto Mardegan &em28xx_zl10353_no_i2c_gate_dev, 15248c47311dSAlberto Mardegan &dev->i2c_adap[dev->def_i2c_bus]); 1525fe8d54f0SMauro Carvalho Chehab if (dvb->fe[0]) { 15268c47311dSAlberto Mardegan dvb_attach(mt2060_attach, dvb->fe[0], 15278c47311dSAlberto Mardegan &dev->i2c_adap[dev->def_i2c_bus], 15288c47311dSAlberto Mardegan &em28xx_mt2060_config, 1220); 15298c47311dSAlberto Mardegan } 15308c47311dSAlberto Mardegan break; 15310c0d06caSMauro Carvalho Chehab case EM2870_BOARD_KWORLD_355U: 15320c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(zl10353_attach, 15330c0d06caSMauro Carvalho Chehab &em28xx_zl10353_no_i2c_gate_dev, 1534c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 1535fe8d54f0SMauro Carvalho Chehab if (dvb->fe[0]) 15360c0d06caSMauro Carvalho Chehab dvb_attach(qt1010_attach, dvb->fe[0], 1537fe8d54f0SMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 1538fe8d54f0SMauro Carvalho Chehab &em28xx_qt1010_config); 15390c0d06caSMauro Carvalho Chehab break; 15400c0d06caSMauro Carvalho Chehab case EM2883_BOARD_KWORLD_HYBRID_330U: 15410c0d06caSMauro Carvalho Chehab case EM2882_BOARD_EVGA_INDTUBE: 15420c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(s5h1409_attach, 15430c0d06caSMauro Carvalho Chehab &em28xx_s5h1409_with_xc3028, 1544c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 15450c0d06caSMauro Carvalho Chehab if (em28xx_attach_xc3028(0x61, dev) < 0) { 15460c0d06caSMauro Carvalho Chehab result = -EINVAL; 15470c0d06caSMauro Carvalho Chehab goto out_free; 15480c0d06caSMauro Carvalho Chehab } 15490c0d06caSMauro Carvalho Chehab break; 15500c0d06caSMauro Carvalho Chehab case EM2882_BOARD_KWORLD_ATSC_315U: 15510c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(lgdt330x_attach, 15520c0d06caSMauro Carvalho Chehab &em2880_lgdt3303_dev, 1553c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 1554fe8d54f0SMauro Carvalho Chehab if (dvb->fe[0]) { 15550c0d06caSMauro Carvalho Chehab if (!dvb_attach(simple_tuner_attach, dvb->fe[0], 1556fdf1bc9fSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 1557fdf1bc9fSMauro Carvalho Chehab 0x61, TUNER_THOMSON_DTT761X)) { 15580c0d06caSMauro Carvalho Chehab result = -EINVAL; 15590c0d06caSMauro Carvalho Chehab goto out_free; 15600c0d06caSMauro Carvalho Chehab } 15610c0d06caSMauro Carvalho Chehab } 15620c0d06caSMauro Carvalho Chehab break; 15630c0d06caSMauro Carvalho Chehab case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2: 15640c0d06caSMauro Carvalho Chehab case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E: 15650c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL, 156629b05e22SMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 156729b05e22SMauro Carvalho Chehab &dev->intf->dev); 15680c0d06caSMauro Carvalho Chehab if (em28xx_attach_xc3028(0x61, dev) < 0) { 15690c0d06caSMauro Carvalho Chehab result = -EINVAL; 15700c0d06caSMauro Carvalho Chehab goto out_free; 15710c0d06caSMauro Carvalho Chehab } 15720c0d06caSMauro Carvalho Chehab break; 15730c0d06caSMauro Carvalho Chehab case EM2870_BOARD_REDDO_DVB_C_USB_BOX: 15740c0d06caSMauro Carvalho Chehab /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */ 15750c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(tda10023_attach, 15760c0d06caSMauro Carvalho Chehab &em28xx_tda10023_config, 1577fe8d54f0SMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 1578fe8d54f0SMauro Carvalho Chehab 0x48); 15790c0d06caSMauro Carvalho Chehab if (dvb->fe[0]) { 15800c0d06caSMauro Carvalho Chehab if (!dvb_attach(simple_tuner_attach, dvb->fe[0], 1581fdf1bc9fSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 1582fdf1bc9fSMauro Carvalho Chehab 0x60, TUNER_PHILIPS_CU1216L)) { 15830c0d06caSMauro Carvalho Chehab result = -EINVAL; 15840c0d06caSMauro Carvalho Chehab goto out_free; 15850c0d06caSMauro Carvalho Chehab } 15860c0d06caSMauro Carvalho Chehab } 15870c0d06caSMauro Carvalho Chehab break; 15880c0d06caSMauro Carvalho Chehab case EM2870_BOARD_KWORLD_A340: 15890c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(lgdt3305_attach, 15900c0d06caSMauro Carvalho Chehab &em2870_lgdt3304_dev, 1591c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 15924db8954aSShuah Khan if (!dvb->fe[0]) { 15934db8954aSShuah Khan result = -EINVAL; 15944db8954aSShuah Khan goto out_free; 15954db8954aSShuah Khan } 15964db8954aSShuah Khan if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60, 15974db8954aSShuah Khan &dev->i2c_adap[dev->def_i2c_bus], 15984db8954aSShuah Khan &kworld_a340_config)) { 15994db8954aSShuah Khan dvb_frontend_detach(dvb->fe[0]); 16004db8954aSShuah Khan result = -EINVAL; 16014db8954aSShuah Khan goto out_free; 16024db8954aSShuah Khan } 16030c0d06caSMauro Carvalho Chehab break; 16040c0d06caSMauro Carvalho Chehab case EM28174_BOARD_PCTV_290E: 1605a36a66d7SAntti Palosaari /* set default GPIO0 for LNA, used if GPIOLIB is undefined */ 1606a36a66d7SAntti Palosaari dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O | 1607a36a66d7SAntti Palosaari CXD2820R_GPIO_L; 16080c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(cxd2820r_attach, 16090c0d06caSMauro Carvalho Chehab &em28xx_cxd2820r_config, 1610c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 161113a5336eSAntti Palosaari &dvb->lna_gpio); 16120c0d06caSMauro Carvalho Chehab if (dvb->fe[0]) { 16130c0d06caSMauro Carvalho Chehab /* FE 0 attach tuner */ 16140c0d06caSMauro Carvalho Chehab if (!dvb_attach(tda18271_attach, 16150c0d06caSMauro Carvalho Chehab dvb->fe[0], 16160c0d06caSMauro Carvalho Chehab 0x60, 1617c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 16180c0d06caSMauro Carvalho Chehab &em28xx_cxd2820r_tda18271_config)) { 16190c0d06caSMauro Carvalho Chehab dvb_frontend_detach(dvb->fe[0]); 16200c0d06caSMauro Carvalho Chehab result = -EINVAL; 16210c0d06caSMauro Carvalho Chehab goto out_free; 16220c0d06caSMauro Carvalho Chehab } 16231e8f31f3SAntti Palosaari 162413a5336eSAntti Palosaari #ifdef CONFIG_GPIOLIB 16251e8f31f3SAntti Palosaari /* enable LNA for DVB-T, DVB-T2 and DVB-C */ 16260c42a55cSAntti Palosaari result = gpio_request_one(dvb->lna_gpio, 16270c42a55cSAntti Palosaari GPIOF_OUT_INIT_LOW, NULL); 16281e8f31f3SAntti Palosaari if (result) 162929b05e22SMauro Carvalho Chehab dev_err(&dev->intf->dev, 1630ce8591ffSMauro Carvalho Chehab "gpio request failed %d\n", 16310c42a55cSAntti Palosaari result); 16321e8f31f3SAntti Palosaari else 163313a5336eSAntti Palosaari gpio_free(dvb->lna_gpio); 16341e8f31f3SAntti Palosaari 16351e8f31f3SAntti Palosaari result = 0; /* continue even set LNA fails */ 163613a5336eSAntti Palosaari #endif 163713a5336eSAntti Palosaari dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna; 16380c42a55cSAntti Palosaari } 16390c42a55cSAntti Palosaari 16400c0d06caSMauro Carvalho Chehab break; 16410c0d06caSMauro Carvalho Chehab case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C: 16420c0d06caSMauro Carvalho Chehab { 1643ad32495bSMauro Carvalho Chehab struct xc5000_config cfg = {}; 1644fdf1bc9fSMauro Carvalho Chehab 16450c0d06caSMauro Carvalho Chehab hauppauge_hvr930c_init(dev); 16460c0d06caSMauro Carvalho Chehab 16470c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(drxk_attach, 1648fe8d54f0SMauro Carvalho Chehab &hauppauge_930c_drxk, 1649fe8d54f0SMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 16500c0d06caSMauro Carvalho Chehab if (!dvb->fe[0]) { 16510c0d06caSMauro Carvalho Chehab result = -EINVAL; 16520c0d06caSMauro Carvalho Chehab goto out_free; 16530c0d06caSMauro Carvalho Chehab } 16540c0d06caSMauro Carvalho Chehab /* FIXME: do we need a pll semaphore? */ 16550c0d06caSMauro Carvalho Chehab dvb->fe[0]->sec_priv = dvb; 16560c0d06caSMauro Carvalho Chehab sema_init(&dvb->pll_mutex, 1); 16570c0d06caSMauro Carvalho Chehab dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl; 16580c0d06caSMauro Carvalho Chehab dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl; 16590c0d06caSMauro Carvalho Chehab 16600c0d06caSMauro Carvalho Chehab /* Attach xc5000 */ 16610c0d06caSMauro Carvalho Chehab cfg.i2c_address = 0x61; 16620c0d06caSMauro Carvalho Chehab cfg.if_khz = 4000; 16630c0d06caSMauro Carvalho Chehab 16640c0d06caSMauro Carvalho Chehab if (dvb->fe[0]->ops.i2c_gate_ctrl) 16650c0d06caSMauro Carvalho Chehab dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1); 1666fe8d54f0SMauro Carvalho Chehab if (!dvb_attach(xc5000_attach, dvb->fe[0], 1667fe8d54f0SMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], &cfg)) { 16680c0d06caSMauro Carvalho Chehab result = -EINVAL; 16690c0d06caSMauro Carvalho Chehab goto out_free; 16700c0d06caSMauro Carvalho Chehab } 16710c0d06caSMauro Carvalho Chehab if (dvb->fe[0]->ops.i2c_gate_ctrl) 16720c0d06caSMauro Carvalho Chehab dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0); 16730c0d06caSMauro Carvalho Chehab 16740c0d06caSMauro Carvalho Chehab break; 16750c0d06caSMauro Carvalho Chehab } 16760c0d06caSMauro Carvalho Chehab case EM2884_BOARD_TERRATEC_H5: 16770c0d06caSMauro Carvalho Chehab terratec_h5_init(dev); 16780c0d06caSMauro Carvalho Chehab 1679fe8d54f0SMauro Carvalho Chehab dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, 1680fe8d54f0SMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 16810c0d06caSMauro Carvalho Chehab if (!dvb->fe[0]) { 16820c0d06caSMauro Carvalho Chehab result = -EINVAL; 16830c0d06caSMauro Carvalho Chehab goto out_free; 16840c0d06caSMauro Carvalho Chehab } 16850c0d06caSMauro Carvalho Chehab /* FIXME: do we need a pll semaphore? */ 16860c0d06caSMauro Carvalho Chehab dvb->fe[0]->sec_priv = dvb; 16870c0d06caSMauro Carvalho Chehab sema_init(&dvb->pll_mutex, 1); 16880c0d06caSMauro Carvalho Chehab dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl; 16890c0d06caSMauro Carvalho Chehab dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl; 16900c0d06caSMauro Carvalho Chehab 16910c0d06caSMauro Carvalho Chehab /* Attach tda18271 to DVB-C frontend */ 16920c0d06caSMauro Carvalho Chehab if (dvb->fe[0]->ops.i2c_gate_ctrl) 16930c0d06caSMauro Carvalho Chehab dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1); 1694fe8d54f0SMauro Carvalho Chehab if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], 1695fe8d54f0SMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 0x60)) { 16960c0d06caSMauro Carvalho Chehab result = -EINVAL; 16970c0d06caSMauro Carvalho Chehab goto out_free; 16980c0d06caSMauro Carvalho Chehab } 16990c0d06caSMauro Carvalho Chehab if (dvb->fe[0]->ops.i2c_gate_ctrl) 17000c0d06caSMauro Carvalho Chehab dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0); 17010c0d06caSMauro Carvalho Chehab 17020c0d06caSMauro Carvalho Chehab break; 17034159d01bSMauro Carvalho Chehab case EM2884_BOARD_C3TECH_DIGITAL_DUO: 17044159d01bSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(mb86a20s_attach, 17054159d01bSMauro Carvalho Chehab &c3tech_duo_mb86a20s_config, 17064159d01bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 1707fe8d54f0SMauro Carvalho Chehab if (dvb->fe[0]) 17084159d01bSMauro Carvalho Chehab dvb_attach(tda18271_attach, dvb->fe[0], 0x60, 17094159d01bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 17104159d01bSMauro Carvalho Chehab &c3tech_duo_tda18271_config); 17114159d01bSMauro Carvalho Chehab break; 1712f410b409SArnd Bergmann case EM28174_BOARD_PCTV_460E: 1713f410b409SArnd Bergmann result = em28174_dvb_init_pctv_460e(dev); 1714f410b409SArnd Bergmann if (result) 17158022f9afSAntti Palosaari goto out_free; 17160c0d06caSMauro Carvalho Chehab break; 17177c1dfdb0SJakob Haufe case EM2874_BOARD_DELOCK_61959: 17180c0d06caSMauro Carvalho Chehab case EM2874_BOARD_MAXMEDIA_UB425_TC: 17190c0d06caSMauro Carvalho Chehab /* attach demodulator */ 17200c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk, 1721c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 17220c0d06caSMauro Carvalho Chehab 17230c0d06caSMauro Carvalho Chehab if (dvb->fe[0]) { 17240c0d06caSMauro Carvalho Chehab /* disable I2C-gate */ 17250c0d06caSMauro Carvalho Chehab dvb->fe[0]->ops.i2c_gate_ctrl = NULL; 17260c0d06caSMauro Carvalho Chehab 17270c0d06caSMauro Carvalho Chehab /* attach tuner */ 1728b6c7abb1SAntti Palosaari if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60, 1729b6c7abb1SAntti Palosaari &dev->i2c_adap[dev->def_i2c_bus], 1730b6c7abb1SAntti Palosaari &em28xx_cxd2820r_tda18271_config)) { 17310c0d06caSMauro Carvalho Chehab dvb_frontend_detach(dvb->fe[0]); 17320c0d06caSMauro Carvalho Chehab result = -EINVAL; 17330c0d06caSMauro Carvalho Chehab goto out_free; 17340c0d06caSMauro Carvalho Chehab } 17350c0d06caSMauro Carvalho Chehab } 17360c0d06caSMauro Carvalho Chehab break; 17370c0d06caSMauro Carvalho Chehab case EM2884_BOARD_PCTV_510E: 17380c0d06caSMauro Carvalho Chehab case EM2884_BOARD_PCTV_520E: 17390c0d06caSMauro Carvalho Chehab pctv_520e_init(dev); 17400c0d06caSMauro Carvalho Chehab 17410c0d06caSMauro Carvalho Chehab /* attach demodulator */ 17420c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk, 1743c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 17440c0d06caSMauro Carvalho Chehab 17450c0d06caSMauro Carvalho Chehab if (dvb->fe[0]) { 17460c0d06caSMauro Carvalho Chehab /* attach tuner */ 17470c0d06caSMauro Carvalho Chehab if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60, 1748c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 17490c0d06caSMauro Carvalho Chehab &em28xx_cxd2820r_tda18271_config)) { 17500c0d06caSMauro Carvalho Chehab dvb_frontend_detach(dvb->fe[0]); 17510c0d06caSMauro Carvalho Chehab result = -EINVAL; 17520c0d06caSMauro Carvalho Chehab goto out_free; 17530c0d06caSMauro Carvalho Chehab } 17540c0d06caSMauro Carvalho Chehab } 17550c0d06caSMauro Carvalho Chehab break; 17561fe0fbd6SGilles Risch case EM2884_BOARD_ELGATO_EYETV_HYBRID_2008: 17570c0d06caSMauro Carvalho Chehab case EM2884_BOARD_CINERGY_HTC_STICK: 1758d6a64327SMauro Carvalho Chehab case EM2884_BOARD_TERRATEC_H6: 17590c0d06caSMauro Carvalho Chehab terratec_htc_stick_init(dev); 17600c0d06caSMauro Carvalho Chehab 17610c0d06caSMauro Carvalho Chehab /* attach demodulator */ 17620c0d06caSMauro Carvalho Chehab dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk, 1763c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 17640c0d06caSMauro Carvalho Chehab if (!dvb->fe[0]) { 17650c0d06caSMauro Carvalho Chehab result = -EINVAL; 17660c0d06caSMauro Carvalho Chehab goto out_free; 17670c0d06caSMauro Carvalho Chehab } 17680c0d06caSMauro Carvalho Chehab 17690c0d06caSMauro Carvalho Chehab /* Attach the demodulator. */ 17700c0d06caSMauro Carvalho Chehab if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60, 1771c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 17720c0d06caSMauro Carvalho Chehab &em28xx_cxd2820r_tda18271_config)) { 17730c0d06caSMauro Carvalho Chehab result = -EINVAL; 17740c0d06caSMauro Carvalho Chehab goto out_free; 17750c0d06caSMauro Carvalho Chehab } 17760c0d06caSMauro Carvalho Chehab break; 177789040136SMartin Blumenstingl case EM2884_BOARD_TERRATEC_HTC_USB_XS: 177889040136SMartin Blumenstingl terratec_htc_usb_xs_init(dev); 177989040136SMartin Blumenstingl 178089040136SMartin Blumenstingl /* attach demodulator */ 178189040136SMartin Blumenstingl dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk, 1782c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 178389040136SMartin Blumenstingl if (!dvb->fe[0]) { 178489040136SMartin Blumenstingl result = -EINVAL; 178589040136SMartin Blumenstingl goto out_free; 178689040136SMartin Blumenstingl } 178789040136SMartin Blumenstingl 178889040136SMartin Blumenstingl /* Attach the demodulator. */ 178989040136SMartin Blumenstingl if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60, 1790c7a45e5bSMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus], 179189040136SMartin Blumenstingl &em28xx_cxd2820r_tda18271_config)) { 179289040136SMartin Blumenstingl result = -EINVAL; 179389040136SMartin Blumenstingl goto out_free; 179489040136SMartin Blumenstingl } 179589040136SMartin Blumenstingl break; 17966dbea9f0SJean-Francois Thibert case EM2874_BOARD_KWORLD_UB435Q_V2: 17976dbea9f0SJean-Francois Thibert dvb->fe[0] = dvb_attach(lgdt3305_attach, 17986dbea9f0SJean-Francois Thibert &em2874_lgdt3305_dev, 17996dbea9f0SJean-Francois Thibert &dev->i2c_adap[dev->def_i2c_bus]); 18006dbea9f0SJean-Francois Thibert if (!dvb->fe[0]) { 18016dbea9f0SJean-Francois Thibert result = -EINVAL; 18026dbea9f0SJean-Francois Thibert goto out_free; 18036dbea9f0SJean-Francois Thibert } 18046dbea9f0SJean-Francois Thibert 18056dbea9f0SJean-Francois Thibert /* Attach the demodulator. */ 18066dbea9f0SJean-Francois Thibert if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60, 18076dbea9f0SJean-Francois Thibert &dev->i2c_adap[dev->def_i2c_bus], 18086dbea9f0SJean-Francois Thibert &kworld_ub435q_v2_config)) { 18096dbea9f0SJean-Francois Thibert result = -EINVAL; 18106dbea9f0SJean-Francois Thibert goto out_free; 18116dbea9f0SJean-Francois Thibert } 18126dbea9f0SJean-Francois Thibert break; 181302bc1f55SMauro Carvalho Chehab case EM2874_BOARD_KWORLD_UB435Q_V3: 1814ac7a24fbSAntti Palosaari { 1815ac7a24fbSAntti Palosaari struct i2c_adapter *adapter = &dev->i2c_adap[dev->def_i2c_bus]; 1816ac7a24fbSAntti Palosaari 181702bc1f55SMauro Carvalho Chehab dvb->fe[0] = dvb_attach(lgdt3305_attach, 181802bc1f55SMauro Carvalho Chehab &em2874_lgdt3305_nogate_dev, 181902bc1f55SMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 182002bc1f55SMauro Carvalho Chehab if (!dvb->fe[0]) { 182102bc1f55SMauro Carvalho Chehab result = -EINVAL; 182202bc1f55SMauro Carvalho Chehab goto out_free; 182302bc1f55SMauro Carvalho Chehab } 182402bc1f55SMauro Carvalho Chehab 1825ac7a24fbSAntti Palosaari /* attach tuner */ 1826ac7a24fbSAntti Palosaari kworld_ub435q_v3_config.fe = dvb->fe[0]; 1827ad32495bSMauro Carvalho Chehab 1828ad32495bSMauro Carvalho Chehab dvb->i2c_client_tuner = dvb_module_probe("tda18212", NULL, 1829fe8d54f0SMauro Carvalho Chehab adapter, 0x60, 1830ad32495bSMauro Carvalho Chehab &kworld_ub435q_v3_config); 1831ad32495bSMauro Carvalho Chehab if (!dvb->i2c_client_tuner) { 1832ac7a24fbSAntti Palosaari dvb_frontend_detach(dvb->fe[0]); 1833ac7a24fbSAntti Palosaari result = -ENODEV; 183402bc1f55SMauro Carvalho Chehab goto out_free; 183502bc1f55SMauro Carvalho Chehab } 183602bc1f55SMauro Carvalho Chehab break; 1837ac7a24fbSAntti Palosaari } 183838b2df95SDevin Heitmueller case EM2874_BOARD_PCTV_HD_MINI_80E: 1839fe8d54f0SMauro Carvalho Chehab dvb->fe[0] = dvb_attach(drx39xxj_attach, 1840fe8d54f0SMauro Carvalho Chehab &dev->i2c_adap[dev->def_i2c_bus]); 1841fe8d54f0SMauro Carvalho Chehab if (dvb->fe[0]) { 1842fe8d54f0SMauro Carvalho Chehab dvb->fe[0] = dvb_attach(tda18271_attach, dvb->fe[0], 1843fe8d54f0SMauro Carvalho Chehab 0x60, 184438b2df95SDevin Heitmueller &dev->i2c_adap[dev->def_i2c_bus], 184538b2df95SDevin Heitmueller &pinnacle_80e_dvb_config); 184638b2df95SDevin Heitmueller if (!dvb->fe[0]) { 184738b2df95SDevin Heitmueller result = -EINVAL; 184838b2df95SDevin Heitmueller goto out_free; 184938b2df95SDevin Heitmueller } 185038b2df95SDevin Heitmueller } 185138b2df95SDevin Heitmueller break; 1852f410b409SArnd Bergmann case EM28178_BOARD_PCTV_461E: 1853f410b409SArnd Bergmann result = em28178_dvb_init_pctv_461e(dev); 1854f410b409SArnd Bergmann if (result) 1855ec573362SAntti Palosaari goto out_free; 1856ec573362SAntti Palosaari break; 185719229240SAntti Palosaari case EM28178_BOARD_PCTV_292E: 1858f410b409SArnd Bergmann result = em28178_dvb_init_pctv_292e(dev); 1859f410b409SArnd Bergmann if (result) 186019229240SAntti Palosaari goto out_free; 186119229240SAntti Palosaari break; 1862fc30dd76SOlli Salonen case EM28178_BOARD_TERRATEC_T2_STICK_HD: 1863f410b409SArnd Bergmann result = em28178_dvb_init_terratec_t2_stick_hd(dev); 1864f410b409SArnd Bergmann if (result) 1865fc30dd76SOlli Salonen goto out_free; 1866fc30dd76SOlli Salonen break; 1867ab4d1452SSatoshi Nagahama case EM28178_BOARD_PLEX_PX_BCUD: 1868f410b409SArnd Bergmann result = em28178_dvb_init_plex_px_bcud(dev); 1869f410b409SArnd Bergmann if (result) 1870ab4d1452SSatoshi Nagahama goto out_free; 1871ab4d1452SSatoshi Nagahama break; 187211a2a949SOlli Salonen case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB: 1873f410b409SArnd Bergmann result = em28174_dvb_init_hauppauge_wintv_dualhd_dvb(dev); 1874f410b409SArnd Bergmann if (result) 187511a2a949SOlli Salonen goto out_free; 187611a2a949SOlli Salonen break; 18771586342eSKevin Cheng case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595: 1878f410b409SArnd Bergmann result = em28174_dvb_init_hauppauge_wintv_dualhd_01595(dev); 1879f410b409SArnd Bergmann if (result) 18801586342eSKevin Cheng goto out_free; 18811586342eSKevin Cheng break; 18820c0d06caSMauro Carvalho Chehab default: 188329b05e22SMauro Carvalho Chehab dev_err(&dev->intf->dev, 1884ce8591ffSMauro Carvalho Chehab "The frontend of your DVB/ATSC card isn't supported yet\n"); 18850c0d06caSMauro Carvalho Chehab break; 18860c0d06caSMauro Carvalho Chehab } 1887fe8d54f0SMauro Carvalho Chehab if (!dvb->fe[0]) { 188829b05e22SMauro Carvalho Chehab dev_err(&dev->intf->dev, "frontend initialization failed\n"); 18890c0d06caSMauro Carvalho Chehab result = -EINVAL; 18900c0d06caSMauro Carvalho Chehab goto out_free; 18910c0d06caSMauro Carvalho Chehab } 18920c0d06caSMauro Carvalho Chehab /* define general-purpose callback pointer */ 18930c0d06caSMauro Carvalho Chehab dvb->fe[0]->callback = em28xx_tuner_callback; 18940c0d06caSMauro Carvalho Chehab if (dvb->fe[1]) 18950c0d06caSMauro Carvalho Chehab dvb->fe[1]->callback = em28xx_tuner_callback; 18960c0d06caSMauro Carvalho Chehab 18970c0d06caSMauro Carvalho Chehab /* register everything */ 189829b05e22SMauro Carvalho Chehab result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->intf->dev); 18990c0d06caSMauro Carvalho Chehab 19000c0d06caSMauro Carvalho Chehab if (result < 0) 19010c0d06caSMauro Carvalho Chehab goto out_free; 19020c0d06caSMauro Carvalho Chehab 1903be7fd3c3SBrad Love if (dev->dvb_xfer_bulk) { 1904be7fd3c3SBrad Love dvb_alt = 0; 1905be7fd3c3SBrad Love } else { /* isoc */ 1906be7fd3c3SBrad Love dvb_alt = dev->dvb_alt_isoc; 1907be7fd3c3SBrad Love } 1908be7fd3c3SBrad Love 1909be7fd3c3SBrad Love udev = interface_to_usbdev(dev->intf); 1910be7fd3c3SBrad Love usb_set_interface(udev, dev->ifnum, dvb_alt); 191129b05e22SMauro Carvalho Chehab dev_info(&dev->intf->dev, "DVB extension successfully initialized\n"); 191247677e51SMauro Carvalho Chehab 191347677e51SMauro Carvalho Chehab kref_get(&dev->ref); 191447677e51SMauro Carvalho Chehab 19150c0d06caSMauro Carvalho Chehab ret: 19160c0d06caSMauro Carvalho Chehab em28xx_set_mode(dev, EM28XX_SUSPEND); 19170c0d06caSMauro Carvalho Chehab mutex_unlock(&dev->lock); 19180c0d06caSMauro Carvalho Chehab return result; 19190c0d06caSMauro Carvalho Chehab 19200c0d06caSMauro Carvalho Chehab out_free: 19210c0d06caSMauro Carvalho Chehab kfree(dvb); 19220c0d06caSMauro Carvalho Chehab dev->dvb = NULL; 19230c0d06caSMauro Carvalho Chehab goto ret; 19240c0d06caSMauro Carvalho Chehab } 19250c0d06caSMauro Carvalho Chehab 19260c0d06caSMauro Carvalho Chehab static inline void prevent_sleep(struct dvb_frontend_ops *ops) 19270c0d06caSMauro Carvalho Chehab { 19280c0d06caSMauro Carvalho Chehab ops->set_voltage = NULL; 19290c0d06caSMauro Carvalho Chehab ops->sleep = NULL; 19300c0d06caSMauro Carvalho Chehab ops->tuner_ops.sleep = NULL; 19310c0d06caSMauro Carvalho Chehab } 19320c0d06caSMauro Carvalho Chehab 19330c0d06caSMauro Carvalho Chehab static int em28xx_dvb_fini(struct em28xx *dev) 19340c0d06caSMauro Carvalho Chehab { 1935b45e34f2SMauro Carvalho Chehab struct em28xx_dvb *dvb; 1936b45e34f2SMauro Carvalho Chehab 1937822b8deaSMauro Carvalho Chehab if (dev->is_audio_only) { 1938822b8deaSMauro Carvalho Chehab /* Shouldn't initialize IR for this interface */ 1939822b8deaSMauro Carvalho Chehab return 0; 1940822b8deaSMauro Carvalho Chehab } 1941822b8deaSMauro Carvalho Chehab 19420c0d06caSMauro Carvalho Chehab if (!dev->board.has_dvb) { 19430c0d06caSMauro Carvalho Chehab /* This device does not support the extension */ 19440c0d06caSMauro Carvalho Chehab return 0; 19450c0d06caSMauro Carvalho Chehab } 19460c0d06caSMauro Carvalho Chehab 1947b45e34f2SMauro Carvalho Chehab if (!dev->dvb) 1948b45e34f2SMauro Carvalho Chehab return 0; 1949b45e34f2SMauro Carvalho Chehab 195029b05e22SMauro Carvalho Chehab dev_info(&dev->intf->dev, "Closing DVB extension\n"); 1951aa929ad7SMauro Carvalho Chehab 1952b45e34f2SMauro Carvalho Chehab dvb = dev->dvb; 19530c0d06caSMauro Carvalho Chehab 195427ba0dacSFrank Schaefer em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE); 195527ba0dacSFrank Schaefer 19562665c299SFrank Schaefer if (dev->disconnected) { 1957fe8d54f0SMauro Carvalho Chehab /* 1958fe8d54f0SMauro Carvalho Chehab * We cannot tell the device to sleep 1959fe8d54f0SMauro Carvalho Chehab * once it has been unplugged. 1960fe8d54f0SMauro Carvalho Chehab */ 1961f68e35afSShuah Khan if (dvb->fe[0]) { 19620c0d06caSMauro Carvalho Chehab prevent_sleep(&dvb->fe[0]->ops); 1963f68e35afSShuah Khan dvb->fe[0]->exit = DVB_FE_DEVICE_REMOVED; 1964f68e35afSShuah Khan } 1965f68e35afSShuah Khan if (dvb->fe[1]) { 19660c0d06caSMauro Carvalho Chehab prevent_sleep(&dvb->fe[1]->ops); 1967f68e35afSShuah Khan dvb->fe[1]->exit = DVB_FE_DEVICE_REMOVED; 1968f68e35afSShuah Khan } 19690c0d06caSMauro Carvalho Chehab } 19700c0d06caSMauro Carvalho Chehab 1971910b0797SMatthias Schwarzott em28xx_unregister_dvb(dvb); 1972910b0797SMatthias Schwarzott 1973ad32495bSMauro Carvalho Chehab /* release I2C module bindings */ 1974ad32495bSMauro Carvalho Chehab dvb_module_release(dvb->i2c_client_sec); 1975ad32495bSMauro Carvalho Chehab dvb_module_release(dvb->i2c_client_tuner); 1976ad32495bSMauro Carvalho Chehab dvb_module_release(dvb->i2c_client_demod); 197719229240SAntti Palosaari 19780c0d06caSMauro Carvalho Chehab kfree(dvb); 19790c0d06caSMauro Carvalho Chehab dev->dvb = NULL; 198047677e51SMauro Carvalho Chehab kref_put(&dev->ref, em28xx_free_device); 19810c0d06caSMauro Carvalho Chehab 19820c0d06caSMauro Carvalho Chehab return 0; 19830c0d06caSMauro Carvalho Chehab } 19840c0d06caSMauro Carvalho Chehab 1985ca2b46daSShuah Khan static int em28xx_dvb_suspend(struct em28xx *dev) 1986ca2b46daSShuah Khan { 1987ca2b46daSShuah Khan int ret = 0; 1988ca2b46daSShuah Khan 1989ca2b46daSShuah Khan if (dev->is_audio_only) 1990ca2b46daSShuah Khan return 0; 1991ca2b46daSShuah Khan 1992ca2b46daSShuah Khan if (!dev->board.has_dvb) 1993ca2b46daSShuah Khan return 0; 1994ca2b46daSShuah Khan 199529b05e22SMauro Carvalho Chehab dev_info(&dev->intf->dev, "Suspending DVB extension\n"); 1996ca2b46daSShuah Khan if (dev->dvb) { 1997ca2b46daSShuah Khan struct em28xx_dvb *dvb = dev->dvb; 1998ca2b46daSShuah Khan 1999ca2b46daSShuah Khan if (dvb->fe[0]) { 2000ca2b46daSShuah Khan ret = dvb_frontend_suspend(dvb->fe[0]); 200129b05e22SMauro Carvalho Chehab dev_info(&dev->intf->dev, "fe0 suspend %d\n", ret); 2002ca2b46daSShuah Khan } 2003ca2b46daSShuah Khan if (dvb->fe[1]) { 2004ca2b46daSShuah Khan dvb_frontend_suspend(dvb->fe[1]); 200529b05e22SMauro Carvalho Chehab dev_info(&dev->intf->dev, "fe1 suspend %d\n", ret); 2006ca2b46daSShuah Khan } 2007ca2b46daSShuah Khan } 2008ca2b46daSShuah Khan 2009ca2b46daSShuah Khan return 0; 2010ca2b46daSShuah Khan } 2011ca2b46daSShuah Khan 2012ca2b46daSShuah Khan static int em28xx_dvb_resume(struct em28xx *dev) 2013ca2b46daSShuah Khan { 2014ca2b46daSShuah Khan int ret = 0; 2015ca2b46daSShuah Khan 2016ca2b46daSShuah Khan if (dev->is_audio_only) 2017ca2b46daSShuah Khan return 0; 2018ca2b46daSShuah Khan 2019ca2b46daSShuah Khan if (!dev->board.has_dvb) 2020ca2b46daSShuah Khan return 0; 2021ca2b46daSShuah Khan 202229b05e22SMauro Carvalho Chehab dev_info(&dev->intf->dev, "Resuming DVB extension\n"); 2023ca2b46daSShuah Khan if (dev->dvb) { 2024ca2b46daSShuah Khan struct em28xx_dvb *dvb = dev->dvb; 2025ca2b46daSShuah Khan 2026ca2b46daSShuah Khan if (dvb->fe[0]) { 2027ca2b46daSShuah Khan ret = dvb_frontend_resume(dvb->fe[0]); 202829b05e22SMauro Carvalho Chehab dev_info(&dev->intf->dev, "fe0 resume %d\n", ret); 2029ca2b46daSShuah Khan } 2030ca2b46daSShuah Khan 2031ca2b46daSShuah Khan if (dvb->fe[1]) { 2032ca2b46daSShuah Khan ret = dvb_frontend_resume(dvb->fe[1]); 203329b05e22SMauro Carvalho Chehab dev_info(&dev->intf->dev, "fe1 resume %d\n", ret); 2034ca2b46daSShuah Khan } 2035ca2b46daSShuah Khan } 2036ca2b46daSShuah Khan 2037ca2b46daSShuah Khan return 0; 2038ca2b46daSShuah Khan } 2039ca2b46daSShuah Khan 20400c0d06caSMauro Carvalho Chehab static struct em28xx_ops dvb_ops = { 20410c0d06caSMauro Carvalho Chehab .id = EM28XX_DVB, 20420c0d06caSMauro Carvalho Chehab .name = "Em28xx dvb Extension", 20430c0d06caSMauro Carvalho Chehab .init = em28xx_dvb_init, 20440c0d06caSMauro Carvalho Chehab .fini = em28xx_dvb_fini, 2045ca2b46daSShuah Khan .suspend = em28xx_dvb_suspend, 2046ca2b46daSShuah Khan .resume = em28xx_dvb_resume, 20470c0d06caSMauro Carvalho Chehab }; 20480c0d06caSMauro Carvalho Chehab 20490c0d06caSMauro Carvalho Chehab static int __init em28xx_dvb_register(void) 20500c0d06caSMauro Carvalho Chehab { 20510c0d06caSMauro Carvalho Chehab return em28xx_register_extension(&dvb_ops); 20520c0d06caSMauro Carvalho Chehab } 20530c0d06caSMauro Carvalho Chehab 20540c0d06caSMauro Carvalho Chehab static void __exit em28xx_dvb_unregister(void) 20550c0d06caSMauro Carvalho Chehab { 20560c0d06caSMauro Carvalho Chehab em28xx_unregister_extension(&dvb_ops); 20570c0d06caSMauro Carvalho Chehab } 20580c0d06caSMauro Carvalho Chehab 20590c0d06caSMauro Carvalho Chehab module_init(em28xx_dvb_register); 20600c0d06caSMauro Carvalho Chehab module_exit(em28xx_dvb_unregister); 2061