brintos

brintos / linux-shallow public Read only

0
0
Text · 57.6 KiB · 6de8a02 Raw
2010 lines · c
1// SPDX-License-Identifier: GPL-2.0-or-later2/*3 *4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]5 *6 *  Extended 3 / 2005 by Hartmut Hackmann to support various7 *  cards with the tda10046 DVB-T channel decoder8 */9 10#include "saa7134.h"11#include "saa7134-reg.h"12 13#include <linux/init.h>14#include <linux/list.h>15#include <linux/module.h>16#include <linux/kernel.h>17#include <linux/delay.h>18#include <linux/kthread.h>19#include <linux/suspend.h>20 21#include <media/v4l2-common.h>22#include "dvb-pll.h"23#include <media/dvb_frontend.h>24 25#include "mt352.h"26#include "mt352_priv.h" /* FIXME */27#include "tda1004x.h"28#include "nxt200x.h"29#include "xc2028.h"30#include "xc5000.h"31 32#include "tda10086.h"33#include "tda826x.h"34#include "tda827x.h"35#include "isl6421.h"36#include "isl6405.h"37#include "lnbp21.h"38#include "tuner-simple.h"39#include "tda10048.h"40#include "tda18271.h"41#include "lgdt3305.h"42#include "tda8290.h"43#include "mb86a20s.h"44#include "lgs8gxx.h"45 46#include "zl10353.h"47#include "qt1010.h"48 49#include "zl10036.h"50#include "zl10039.h"51#include "mt312.h"52#include "s5h1411.h"53 54MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");55MODULE_DESCRIPTION("DVB/ATSC Support for saa7134 based TV cards");56MODULE_LICENSE("GPL");57 58static unsigned int antenna_pwr;59 60module_param(antenna_pwr, int, 0444);61MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");62 63static int use_frontend;64module_param(use_frontend, int, 0644);65MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");66 67DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);68 69/* ------------------------------------------------------------------70 * mt352 based DVB-T cards71 */72 73static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)74{75	u32 ok;76 77	if (!on) {78		saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 26));79		saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));80		return 0;81	}82 83	saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 26));84	saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 26));85	udelay(10);86 87	saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 28));88	saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));89	udelay(10);90	saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 28));91	udelay(10);92	ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);93	pr_debug("%s %s\n", __func__, ok ? "on" : "off");94 95	if (!ok)96		saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 26));97	return ok;98}99 100static int mt352_pinnacle_init(struct dvb_frontend* fe)101{102	static u8 clock_config []  = { CLOCK_CTL,  0x3d, 0x28 };103	static u8 reset []         = { RESET,      0x80 };104	static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };105	static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0xa0 };106	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };107	static u8 fsm_ctl_cfg[]    = { 0x7b,       0x04 };108	static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x0f };109	static u8 scan_ctl_cfg []  = { SCAN_CTL,   0x0d };110	static u8 irq_cfg []       = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };111 112	pr_debug("%s called\n", __func__);113 114	mt352_write(fe, clock_config,   sizeof(clock_config));115	udelay(200);116	mt352_write(fe, reset,          sizeof(reset));117	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));118	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));119	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));120	mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));121 122	mt352_write(fe, fsm_ctl_cfg,    sizeof(fsm_ctl_cfg));123	mt352_write(fe, scan_ctl_cfg,   sizeof(scan_ctl_cfg));124	mt352_write(fe, irq_cfg,        sizeof(irq_cfg));125 126	return 0;127}128 129static int mt352_aver777_init(struct dvb_frontend* fe)130{131	static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x2d };132	static u8 reset []         = { RESET,      0x80 };133	static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };134	static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0xa0 };135	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };136 137	mt352_write(fe, clock_config,   sizeof(clock_config));138	udelay(200);139	mt352_write(fe, reset,          sizeof(reset));140	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));141	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));142	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));143 144	return 0;145}146 147static int mt352_avermedia_xc3028_init(struct dvb_frontend *fe)148{149	static u8 clock_config []  = { CLOCK_CTL, 0x38, 0x2d };150	static u8 reset []         = { RESET, 0x80 };151	static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };152	static u8 agc_cfg []       = { AGC_TARGET, 0xe };153	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };154 155	mt352_write(fe, clock_config,   sizeof(clock_config));156	udelay(200);157	mt352_write(fe, reset,          sizeof(reset));158	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));159	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));160	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));161	return 0;162}163 164static int mt352_pinnacle_tuner_set_params(struct dvb_frontend *fe)165{166	struct dtv_frontend_properties *c = &fe->dtv_property_cache;167	u8 off[] = { 0x00, 0xf1};168	u8 on[]  = { 0x00, 0x71};169	struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};170 171	struct saa7134_dev *dev = fe->dvb->priv;172	struct v4l2_frequency f;173 174	/* set frequency (mt2050) */175	f.tuner     = 0;176	f.type      = V4L2_TUNER_DIGITAL_TV;177	f.frequency = c->frequency / 1000 * 16 / 1000;178	if (fe->ops.i2c_gate_ctrl)179		fe->ops.i2c_gate_ctrl(fe, 1);180	i2c_transfer(&dev->i2c_adap, &msg, 1);181	saa_call_all(dev, tuner, s_frequency, &f);182	msg.buf = on;183	if (fe->ops.i2c_gate_ctrl)184		fe->ops.i2c_gate_ctrl(fe, 1);185	i2c_transfer(&dev->i2c_adap, &msg, 1);186 187	pinnacle_antenna_pwr(dev, antenna_pwr);188 189	/* mt352 setup */190	return mt352_pinnacle_init(fe);191}192 193static struct mt352_config pinnacle_300i = {194	.demod_address = 0x3c >> 1,195	.adc_clock     = 20333,196	.if2           = 36150,197	.no_tuner      = 1,198	.demod_init    = mt352_pinnacle_init,199};200 201static struct mt352_config avermedia_777 = {202	.demod_address = 0xf,203	.demod_init    = mt352_aver777_init,204};205 206static struct mt352_config avermedia_xc3028_mt352_dev = {207	.demod_address   = (0x1e >> 1),208	.no_tuner        = 1,209	.demod_init      = mt352_avermedia_xc3028_init,210};211 212static struct tda18271_std_map mb86a20s_tda18271_std_map = {213	.dvbt_6   = { .if_freq = 3300, .agc_mode = 3, .std = 4,214		      .if_lvl = 7, .rfagc_top = 0x37, },215};216 217static struct tda18271_config kworld_tda18271_config = {218	.std_map = &mb86a20s_tda18271_std_map,219	.gate    = TDA18271_GATE_DIGITAL,220	.config  = 3,	/* Use tuner callback for AGC */221 222};223 224static const struct mb86a20s_config kworld_mb86a20s_config = {225	.demod_address = 0x10,226};227 228static int kworld_sbtvd_gate_ctrl(struct dvb_frontend* fe, int enable)229{230	struct saa7134_dev *dev = fe->dvb->priv;231 232	unsigned char initmsg[] = {0x45, 0x97};233	unsigned char msg_enable[] = {0x45, 0xc1};234	unsigned char msg_disable[] = {0x45, 0x81};235	struct i2c_msg msg = {.addr = 0x4b, .flags = 0, .buf = initmsg, .len = 2};236 237	if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {238		pr_warn("could not access the I2C gate\n");239		return -EIO;240	}241	if (enable)242		msg.buf = msg_enable;243	else244		msg.buf = msg_disable;245	if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {246		pr_warn("could not access the I2C gate\n");247		return -EIO;248	}249	msleep(20);250	return 0;251}252 253/* ==================================================================254 * tda1004x based DVB-T cards, helper functions255 */256 257static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,258					   const struct firmware **fw, char *name)259{260	struct saa7134_dev *dev = fe->dvb->priv;261	return request_firmware(fw, name, &dev->pci->dev);262}263 264/* ------------------------------------------------------------------265 * these tuners are tu1216, td1316(a)266 */267 268static int philips_tda6651_pll_set(struct dvb_frontend *fe)269{270	struct dtv_frontend_properties *c = &fe->dtv_property_cache;271	struct saa7134_dev *dev = fe->dvb->priv;272	struct tda1004x_state *state = fe->demodulator_priv;273	u8 addr = state->config->tuner_address;274	u8 tuner_buf[4];275	struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =276			sizeof(tuner_buf) };277	int tuner_frequency = 0;278	u8 band, cp, filter;279 280	/* determine charge pump */281	tuner_frequency = c->frequency + 36166000;282	if (tuner_frequency < 87000000)283		return -EINVAL;284	else if (tuner_frequency < 130000000)285		cp = 3;286	else if (tuner_frequency < 160000000)287		cp = 5;288	else if (tuner_frequency < 200000000)289		cp = 6;290	else if (tuner_frequency < 290000000)291		cp = 3;292	else if (tuner_frequency < 420000000)293		cp = 5;294	else if (tuner_frequency < 480000000)295		cp = 6;296	else if (tuner_frequency < 620000000)297		cp = 3;298	else if (tuner_frequency < 830000000)299		cp = 5;300	else if (tuner_frequency < 895000000)301		cp = 7;302	else303		return -EINVAL;304 305	/* determine band */306	if (c->frequency < 49000000)307		return -EINVAL;308	else if (c->frequency < 161000000)309		band = 1;310	else if (c->frequency < 444000000)311		band = 2;312	else if (c->frequency < 861000000)313		band = 4;314	else315		return -EINVAL;316 317	/* setup PLL filter */318	switch (c->bandwidth_hz) {319	case 6000000:320		filter = 0;321		break;322 323	case 7000000:324		filter = 0;325		break;326 327	case 8000000:328		filter = 1;329		break;330 331	default:332		return -EINVAL;333	}334 335	/* calculate divisor336	 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)337	 */338	tuner_frequency = (((c->frequency / 1000) * 6) + 217496) / 1000;339 340	/* setup tuner buffer */341	tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;342	tuner_buf[1] = tuner_frequency & 0xff;343	tuner_buf[2] = 0xca;344	tuner_buf[3] = (cp << 5) | (filter << 3) | band;345 346	if (fe->ops.i2c_gate_ctrl)347		fe->ops.i2c_gate_ctrl(fe, 1);348	if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {349		pr_warn("could not write to tuner at addr: 0x%02x\n",350			addr << 1);351		return -EIO;352	}353	msleep(1);354	return 0;355}356 357static int philips_tu1216_init(struct dvb_frontend *fe)358{359	struct saa7134_dev *dev = fe->dvb->priv;360	struct tda1004x_state *state = fe->demodulator_priv;361	u8 addr = state->config->tuner_address;362	static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };363	struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };364 365	/* setup PLL configuration */366	if (fe->ops.i2c_gate_ctrl)367		fe->ops.i2c_gate_ctrl(fe, 1);368	if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)369		return -EIO;370	msleep(1);371 372	return 0;373}374 375/* ------------------------------------------------------------------ */376 377static struct tda1004x_config philips_tu1216_60_config = {378	.demod_address = 0x8,379	.invert        = 1,380	.invert_oclk   = 0,381	.xtal_freq     = TDA10046_XTAL_4M,382	.agc_config    = TDA10046_AGC_DEFAULT,383	.if_freq       = TDA10046_FREQ_3617,384	.tuner_address = 0x60,385	.request_firmware = philips_tda1004x_request_firmware386};387 388static struct tda1004x_config philips_tu1216_61_config = {389 390	.demod_address = 0x8,391	.invert        = 1,392	.invert_oclk   = 0,393	.xtal_freq     = TDA10046_XTAL_4M,394	.agc_config    = TDA10046_AGC_DEFAULT,395	.if_freq       = TDA10046_FREQ_3617,396	.tuner_address = 0x61,397	.request_firmware = philips_tda1004x_request_firmware398};399 400/* ------------------------------------------------------------------ */401 402static int philips_td1316_tuner_init(struct dvb_frontend *fe)403{404	struct saa7134_dev *dev = fe->dvb->priv;405	struct tda1004x_state *state = fe->demodulator_priv;406	u8 addr = state->config->tuner_address;407	static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };408	struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };409 410	/* setup PLL configuration */411	if (fe->ops.i2c_gate_ctrl)412		fe->ops.i2c_gate_ctrl(fe, 1);413	if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)414		return -EIO;415	return 0;416}417 418static int philips_td1316_tuner_set_params(struct dvb_frontend *fe)419{420	return philips_tda6651_pll_set(fe);421}422 423static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)424{425	struct saa7134_dev *dev = fe->dvb->priv;426	struct tda1004x_state *state = fe->demodulator_priv;427	u8 addr = state->config->tuner_address;428	static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };429	struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };430 431	/* switch the tuner to analog mode */432	if (fe->ops.i2c_gate_ctrl)433		fe->ops.i2c_gate_ctrl(fe, 1);434	if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)435		return -EIO;436	return 0;437}438 439/* ------------------------------------------------------------------ */440 441static int philips_europa_tuner_init(struct dvb_frontend *fe)442{443	struct saa7134_dev *dev = fe->dvb->priv;444	static u8 msg[] = { 0x00, 0x40};445	struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };446 447 448	if (philips_td1316_tuner_init(fe))449		return -EIO;450	msleep(1);451	if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)452		return -EIO;453 454	return 0;455}456 457static int philips_europa_tuner_sleep(struct dvb_frontend *fe)458{459	struct saa7134_dev *dev = fe->dvb->priv;460 461	static u8 msg[] = { 0x00, 0x14 };462	struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };463 464	if (philips_td1316_tuner_sleep(fe))465		return -EIO;466 467	/* switch the board to analog mode */468	if (fe->ops.i2c_gate_ctrl)469		fe->ops.i2c_gate_ctrl(fe, 1);470	if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)471		return -EIO;472 473	return 0;474}475 476static int philips_europa_demod_sleep(struct dvb_frontend *fe)477{478	struct saa7134_dev *dev = fe->dvb->priv;479 480	if (dev->original_demod_sleep)481		dev->original_demod_sleep(fe);482	fe->ops.i2c_gate_ctrl(fe, 1);483	return 0;484}485 486static struct tda1004x_config philips_europa_config = {487 488	.demod_address = 0x8,489	.invert        = 0,490	.invert_oclk   = 0,491	.xtal_freq     = TDA10046_XTAL_4M,492	.agc_config    = TDA10046_AGC_IFO_AUTO_POS,493	.if_freq       = TDA10046_FREQ_052,494	.tuner_address = 0x61,495	.request_firmware = philips_tda1004x_request_firmware496};497 498static struct tda1004x_config medion_cardbus = {499	.demod_address = 0x08,500	.invert        = 1,501	.invert_oclk   = 0,502	.xtal_freq     = TDA10046_XTAL_16M,503	.agc_config    = TDA10046_AGC_IFO_AUTO_NEG,504	.if_freq       = TDA10046_FREQ_3613,505	.tuner_address = 0x61,506	.request_firmware = philips_tda1004x_request_firmware507};508 509static struct tda1004x_config technotrend_budget_t3000_config = {510	.demod_address = 0x8,511	.invert        = 1,512	.invert_oclk   = 0,513	.xtal_freq     = TDA10046_XTAL_4M,514	.agc_config    = TDA10046_AGC_DEFAULT,515	.if_freq       = TDA10046_FREQ_3617,516	.tuner_address = 0x63,517	.request_firmware = philips_tda1004x_request_firmware518};519 520/* ------------------------------------------------------------------521 * tda 1004x based cards with philips silicon tuner522 */523 524static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)525{526	struct tda1004x_state *state = fe->demodulator_priv;527 528	u8 addr = state->config->i2c_gate;529	static u8 tda8290_close[] = { 0x21, 0xc0};530	static u8 tda8290_open[]  = { 0x21, 0x80};531	struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};532	if (enable) {533		tda8290_msg.buf = tda8290_close;534	} else {535		tda8290_msg.buf = tda8290_open;536	}537	if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {538		pr_warn("could not access tda8290 I2C gate\n");539		return -EIO;540	}541	msleep(20);542	return 0;543}544 545static int philips_tda827x_tuner_init(struct dvb_frontend *fe)546{547	struct saa7134_dev *dev = fe->dvb->priv;548	struct tda1004x_state *state = fe->demodulator_priv;549 550	switch (state->config->antenna_switch) {551	case 0:552		break;553	case 1:554		pr_debug("setting GPIO21 to 0 (TV antenna?)\n");555		saa7134_set_gpio(dev, 21, 0);556		break;557	case 2:558		pr_debug("setting GPIO21 to 1 (Radio antenna?)\n");559		saa7134_set_gpio(dev, 21, 1);560		break;561	}562	return 0;563}564 565static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)566{567	struct saa7134_dev *dev = fe->dvb->priv;568	struct tda1004x_state *state = fe->demodulator_priv;569 570	switch (state->config->antenna_switch) {571	case 0:572		break;573	case 1:574		pr_debug("setting GPIO21 to 1 (Radio antenna?)\n");575		saa7134_set_gpio(dev, 21, 1);576		break;577	case 2:578		pr_debug("setting GPIO21 to 0 (TV antenna?)\n");579		saa7134_set_gpio(dev, 21, 0);580		break;581	}582	return 0;583}584 585static int configure_tda827x_fe(struct saa7134_dev *dev,586				struct tda1004x_config *cdec_conf,587				struct tda827x_config *tuner_conf)588{589	struct vb2_dvb_frontend *fe0;590 591	/* Get the first frontend */592	fe0 = vb2_dvb_get_frontend(&dev->frontends, 1);593 594	if (!fe0)595		return -EINVAL;596 597	fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);598	if (fe0->dvb.frontend) {599		if (cdec_conf->i2c_gate)600			fe0->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;601		if (dvb_attach(tda827x_attach, fe0->dvb.frontend,602			       cdec_conf->tuner_address,603			       &dev->i2c_adap, tuner_conf))604			return 0;605 606		pr_warn("no tda827x tuner found at addr: %02x\n",607				cdec_conf->tuner_address);608	}609	return -EINVAL;610}611 612/* ------------------------------------------------------------------ */613 614static struct tda827x_config tda827x_cfg_0 = {615	.init = philips_tda827x_tuner_init,616	.sleep = philips_tda827x_tuner_sleep,617	.config = 0,618	.switch_addr = 0619};620 621static struct tda827x_config tda827x_cfg_1 = {622	.init = philips_tda827x_tuner_init,623	.sleep = philips_tda827x_tuner_sleep,624	.config = 1,625	.switch_addr = 0x4b626};627 628static struct tda827x_config tda827x_cfg_2 = {629	.init = philips_tda827x_tuner_init,630	.sleep = philips_tda827x_tuner_sleep,631	.config = 2,632	.switch_addr = 0x4b633};634 635static struct tda827x_config tda827x_cfg_2_sw42 = {636	.init = philips_tda827x_tuner_init,637	.sleep = philips_tda827x_tuner_sleep,638	.config = 2,639	.switch_addr = 0x42640};641 642/* ------------------------------------------------------------------ */643 644static struct tda1004x_config tda827x_lifeview_config = {645	.demod_address = 0x08,646	.invert        = 1,647	.invert_oclk   = 0,648	.xtal_freq     = TDA10046_XTAL_16M,649	.agc_config    = TDA10046_AGC_TDA827X,650	.gpio_config   = TDA10046_GP11_I,651	.if_freq       = TDA10046_FREQ_045,652	.tuner_address = 0x60,653	.request_firmware = philips_tda1004x_request_firmware654};655 656static struct tda1004x_config philips_tiger_config = {657	.demod_address = 0x08,658	.invert        = 1,659	.invert_oclk   = 0,660	.xtal_freq     = TDA10046_XTAL_16M,661	.agc_config    = TDA10046_AGC_TDA827X,662	.gpio_config   = TDA10046_GP11_I,663	.if_freq       = TDA10046_FREQ_045,664	.i2c_gate      = 0x4b,665	.tuner_address = 0x61,666	.antenna_switch= 1,667	.request_firmware = philips_tda1004x_request_firmware668};669 670static struct tda1004x_config cinergy_ht_config = {671	.demod_address = 0x08,672	.invert        = 1,673	.invert_oclk   = 0,674	.xtal_freq     = TDA10046_XTAL_16M,675	.agc_config    = TDA10046_AGC_TDA827X,676	.gpio_config   = TDA10046_GP01_I,677	.if_freq       = TDA10046_FREQ_045,678	.i2c_gate      = 0x4b,679	.tuner_address = 0x61,680	.request_firmware = philips_tda1004x_request_firmware681};682 683static struct tda1004x_config cinergy_ht_pci_config = {684	.demod_address = 0x08,685	.invert        = 1,686	.invert_oclk   = 0,687	.xtal_freq     = TDA10046_XTAL_16M,688	.agc_config    = TDA10046_AGC_TDA827X,689	.gpio_config   = TDA10046_GP01_I,690	.if_freq       = TDA10046_FREQ_045,691	.i2c_gate      = 0x4b,692	.tuner_address = 0x60,693	.request_firmware = philips_tda1004x_request_firmware694};695 696static struct tda1004x_config philips_tiger_s_config = {697	.demod_address = 0x08,698	.invert        = 1,699	.invert_oclk   = 0,700	.xtal_freq     = TDA10046_XTAL_16M,701	.agc_config    = TDA10046_AGC_TDA827X,702	.gpio_config   = TDA10046_GP01_I,703	.if_freq       = TDA10046_FREQ_045,704	.i2c_gate      = 0x4b,705	.tuner_address = 0x61,706	.antenna_switch= 1,707	.request_firmware = philips_tda1004x_request_firmware708};709 710static struct tda1004x_config pinnacle_pctv_310i_config = {711	.demod_address = 0x08,712	.invert        = 1,713	.invert_oclk   = 0,714	.xtal_freq     = TDA10046_XTAL_16M,715	.agc_config    = TDA10046_AGC_TDA827X,716	.gpio_config   = TDA10046_GP11_I,717	.if_freq       = TDA10046_FREQ_045,718	.i2c_gate      = 0x4b,719	.tuner_address = 0x61,720	.request_firmware = philips_tda1004x_request_firmware721};722 723static struct tda1004x_config hauppauge_hvr_1110_config = {724	.demod_address = 0x08,725	.invert        = 1,726	.invert_oclk   = 0,727	.xtal_freq     = TDA10046_XTAL_16M,728	.agc_config    = TDA10046_AGC_TDA827X,729	.gpio_config   = TDA10046_GP11_I,730	.if_freq       = TDA10046_FREQ_045,731	.i2c_gate      = 0x4b,732	.tuner_address = 0x61,733	.request_firmware = philips_tda1004x_request_firmware734};735 736static struct tda1004x_config asus_p7131_dual_config = {737	.demod_address = 0x08,738	.invert        = 1,739	.invert_oclk   = 0,740	.xtal_freq     = TDA10046_XTAL_16M,741	.agc_config    = TDA10046_AGC_TDA827X,742	.gpio_config   = TDA10046_GP11_I,743	.if_freq       = TDA10046_FREQ_045,744	.i2c_gate      = 0x4b,745	.tuner_address = 0x61,746	.antenna_switch= 2,747	.request_firmware = philips_tda1004x_request_firmware748};749 750static struct tda1004x_config lifeview_trio_config = {751	.demod_address = 0x09,752	.invert        = 1,753	.invert_oclk   = 0,754	.xtal_freq     = TDA10046_XTAL_16M,755	.agc_config    = TDA10046_AGC_TDA827X,756	.gpio_config   = TDA10046_GP00_I,757	.if_freq       = TDA10046_FREQ_045,758	.tuner_address = 0x60,759	.request_firmware = philips_tda1004x_request_firmware760};761 762static struct tda1004x_config tevion_dvbt220rf_config = {763	.demod_address = 0x08,764	.invert        = 1,765	.invert_oclk   = 0,766	.xtal_freq     = TDA10046_XTAL_16M,767	.agc_config    = TDA10046_AGC_TDA827X,768	.gpio_config   = TDA10046_GP11_I,769	.if_freq       = TDA10046_FREQ_045,770	.tuner_address = 0x60,771	.request_firmware = philips_tda1004x_request_firmware772};773 774static struct tda1004x_config md8800_dvbt_config = {775	.demod_address = 0x08,776	.invert        = 1,777	.invert_oclk   = 0,778	.xtal_freq     = TDA10046_XTAL_16M,779	.agc_config    = TDA10046_AGC_TDA827X,780	.gpio_config   = TDA10046_GP01_I,781	.if_freq       = TDA10046_FREQ_045,782	.i2c_gate      = 0x4b,783	.tuner_address = 0x60,784	.request_firmware = philips_tda1004x_request_firmware785};786 787static struct tda1004x_config asus_p7131_4871_config = {788	.demod_address = 0x08,789	.invert        = 1,790	.invert_oclk   = 0,791	.xtal_freq     = TDA10046_XTAL_16M,792	.agc_config    = TDA10046_AGC_TDA827X,793	.gpio_config   = TDA10046_GP01_I,794	.if_freq       = TDA10046_FREQ_045,795	.i2c_gate      = 0x4b,796	.tuner_address = 0x61,797	.antenna_switch= 2,798	.request_firmware = philips_tda1004x_request_firmware799};800 801static struct tda1004x_config asus_p7131_hybrid_lna_config = {802	.demod_address = 0x08,803	.invert        = 1,804	.invert_oclk   = 0,805	.xtal_freq     = TDA10046_XTAL_16M,806	.agc_config    = TDA10046_AGC_TDA827X,807	.gpio_config   = TDA10046_GP11_I,808	.if_freq       = TDA10046_FREQ_045,809	.i2c_gate      = 0x4b,810	.tuner_address = 0x61,811	.antenna_switch= 2,812	.request_firmware = philips_tda1004x_request_firmware813};814 815static struct tda1004x_config kworld_dvb_t_210_config = {816	.demod_address = 0x08,817	.invert        = 1,818	.invert_oclk   = 0,819	.xtal_freq     = TDA10046_XTAL_16M,820	.agc_config    = TDA10046_AGC_TDA827X,821	.gpio_config   = TDA10046_GP11_I,822	.if_freq       = TDA10046_FREQ_045,823	.i2c_gate      = 0x4b,824	.tuner_address = 0x61,825	.antenna_switch= 1,826	.request_firmware = philips_tda1004x_request_firmware827};828 829static struct tda1004x_config avermedia_super_007_config = {830	.demod_address = 0x08,831	.invert        = 1,832	.invert_oclk   = 0,833	.xtal_freq     = TDA10046_XTAL_16M,834	.agc_config    = TDA10046_AGC_TDA827X,835	.gpio_config   = TDA10046_GP01_I,836	.if_freq       = TDA10046_FREQ_045,837	.i2c_gate      = 0x4b,838	.tuner_address = 0x60,839	.antenna_switch= 1,840	.request_firmware = philips_tda1004x_request_firmware841};842 843static struct tda1004x_config twinhan_dtv_dvb_3056_config = {844	.demod_address = 0x08,845	.invert        = 1,846	.invert_oclk   = 0,847	.xtal_freq     = TDA10046_XTAL_16M,848	.agc_config    = TDA10046_AGC_TDA827X,849	.gpio_config   = TDA10046_GP01_I,850	.if_freq       = TDA10046_FREQ_045,851	.i2c_gate      = 0x42,852	.tuner_address = 0x61,853	.antenna_switch = 1,854	.request_firmware = philips_tda1004x_request_firmware855};856 857static struct tda1004x_config asus_tiger_3in1_config = {858	.demod_address = 0x0b,859	.invert        = 1,860	.invert_oclk   = 0,861	.xtal_freq     = TDA10046_XTAL_16M,862	.agc_config    = TDA10046_AGC_TDA827X,863	.gpio_config   = TDA10046_GP11_I,864	.if_freq       = TDA10046_FREQ_045,865	.i2c_gate      = 0x4b,866	.tuner_address = 0x61,867	.antenna_switch = 1,868	.request_firmware = philips_tda1004x_request_firmware869};870 871static struct tda1004x_config asus_ps3_100_config = {872	.demod_address = 0x0b,873	.invert        = 1,874	.invert_oclk   = 0,875	.xtal_freq     = TDA10046_XTAL_16M,876	.agc_config    = TDA10046_AGC_TDA827X,877	.gpio_config   = TDA10046_GP11_I,878	.if_freq       = TDA10046_FREQ_045,879	.i2c_gate      = 0x4b,880	.tuner_address = 0x61,881	.antenna_switch = 1,882	.request_firmware = philips_tda1004x_request_firmware883};884 885/* ------------------------------------------------------------------886 * special case: this card uses saa713x GPIO22 for the mode switch887 */888 889static int ads_duo_tuner_init(struct dvb_frontend *fe)890{891	struct saa7134_dev *dev = fe->dvb->priv;892	philips_tda827x_tuner_init(fe);893	/* route TDA8275a AGC input to the channel decoder */894	saa7134_set_gpio(dev, 22, 1);895	return 0;896}897 898static int ads_duo_tuner_sleep(struct dvb_frontend *fe)899{900	struct saa7134_dev *dev = fe->dvb->priv;901	/* route TDA8275a AGC input to the analog IF chip*/902	saa7134_set_gpio(dev, 22, 0);903	philips_tda827x_tuner_sleep(fe);904	return 0;905}906 907static struct tda827x_config ads_duo_cfg = {908	.init = ads_duo_tuner_init,909	.sleep = ads_duo_tuner_sleep,910	.config = 0911};912 913static struct tda1004x_config ads_tech_duo_config = {914	.demod_address = 0x08,915	.invert        = 1,916	.invert_oclk   = 0,917	.xtal_freq     = TDA10046_XTAL_16M,918	.agc_config    = TDA10046_AGC_TDA827X,919	.gpio_config   = TDA10046_GP00_I,920	.if_freq       = TDA10046_FREQ_045,921	.tuner_address = 0x61,922	.request_firmware = philips_tda1004x_request_firmware923};924 925static struct zl10353_config behold_h6_config = {926	.demod_address = 0x1e>>1,927	.no_tuner      = 1,928	.parallel_ts   = 1,929	.disable_i2c_gate_ctrl = 1,930};931 932static struct xc5000_config behold_x7_tunerconfig = {933	.i2c_address      = 0xc2>>1,934	.if_khz           = 4560,935	.radio_input      = XC5000_RADIO_FM1,936};937 938static struct zl10353_config behold_x7_config = {939	.demod_address = 0x1e>>1,940	.if2           = 45600,941	.no_tuner      = 1,942	.parallel_ts   = 1,943	.disable_i2c_gate_ctrl = 1,944};945 946static struct zl10353_config videomate_t750_zl10353_config = {947	.demod_address         = 0x0f,948	.no_tuner              = 1,949	.parallel_ts           = 1,950	.disable_i2c_gate_ctrl = 1,951};952 953static struct qt1010_config videomate_t750_qt1010_config = {954	.i2c_address = 0x62955};956 957 958/* ==================================================================959 * tda10086 based DVB-S cards, helper functions960 */961 962static struct tda10086_config flydvbs = {963	.demod_address = 0x0e,964	.invert = 0,965	.diseqc_tone = 0,966	.xtal_freq = TDA10086_XTAL_16M,967};968 969static struct tda10086_config sd1878_4m = {970	.demod_address = 0x0e,971	.invert = 0,972	.diseqc_tone = 0,973	.xtal_freq = TDA10086_XTAL_4M,974};975 976/* ------------------------------------------------------------------977 * special case: lnb supply is connected to the gated i2c978 */979 980static int md8800_set_voltage(struct dvb_frontend *fe,981			      enum fe_sec_voltage voltage)982{983	int res = -EIO;984	struct saa7134_dev *dev = fe->dvb->priv;985	if (fe->ops.i2c_gate_ctrl) {986		fe->ops.i2c_gate_ctrl(fe, 1);987		if (dev->original_set_voltage)988			res = dev->original_set_voltage(fe, voltage);989		fe->ops.i2c_gate_ctrl(fe, 0);990	}991	return res;992};993 994static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)995{996	int res = -EIO;997	struct saa7134_dev *dev = fe->dvb->priv;998	if (fe->ops.i2c_gate_ctrl) {999		fe->ops.i2c_gate_ctrl(fe, 1);1000		if (dev->original_set_high_voltage)1001			res = dev->original_set_high_voltage(fe, arg);1002		fe->ops.i2c_gate_ctrl(fe, 0);1003	}1004	return res;1005};1006 1007static int md8800_set_voltage2(struct dvb_frontend *fe,1008			       enum fe_sec_voltage voltage)1009{1010	struct saa7134_dev *dev = fe->dvb->priv;1011	u8 wbuf[2] = { 0x1f, 00 };1012	u8 rbuf;1013	struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },1014				 { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };1015 1016	if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)1017		return -EIO;1018	/* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */1019	if (voltage == SEC_VOLTAGE_18)1020		wbuf[1] = rbuf | 0x10;1021	else1022		wbuf[1] = rbuf & 0xef;1023	msg[0].len = 2;1024	if (i2c_transfer(&dev->i2c_adap, msg, 1) != 1)1025		return -EIO;1026 1027	return 0;1028}1029 1030static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)1031{1032	pr_warn("%s: sorry can't set high LNB supply voltage from here\n",1033		__func__);1034	return -EIO;1035}1036 1037/* ==================================================================1038 * nxt200x based ATSC cards, helper functions1039 */1040 1041static const struct nxt200x_config avertvhda180 = {1042	.demod_address    = 0x0a,1043};1044 1045static const struct nxt200x_config kworldatsc110 = {1046	.demod_address    = 0x0a,1047};1048 1049/* ------------------------------------------------------------------ */1050 1051static struct mt312_config avertv_a700_mt312 = {1052	.demod_address = 0x0e,1053	.voltage_inverted = 1,1054};1055 1056static struct zl10036_config avertv_a700_tuner = {1057	.tuner_address = 0x60,1058};1059 1060static struct mt312_config zl10313_compro_s350_config = {1061	.demod_address = 0x0e,1062};1063 1064static struct mt312_config zl10313_avermedia_a706_config = {1065	.demod_address = 0x0e,1066};1067 1068static struct lgdt3305_config hcw_lgdt3305_config = {1069	.i2c_addr           = 0x0e,1070	.mpeg_mode          = LGDT3305_MPEG_SERIAL,1071	.tpclk_edge         = LGDT3305_TPCLK_RISING_EDGE,1072	.tpvalid_polarity   = LGDT3305_TP_VALID_HIGH,1073	.deny_i2c_rptr      = 1,1074	.spectral_inversion = 1,1075	.qam_if_khz         = 4000,1076	.vsb_if_khz         = 3250,1077};1078 1079static struct tda10048_config hcw_tda10048_config = {1080	.demod_address    = 0x10 >> 1,1081	.output_mode      = TDA10048_SERIAL_OUTPUT,1082	.fwbulkwritelen   = TDA10048_BULKWRITE_200,1083	.inversion        = TDA10048_INVERSION_ON,1084	.dtv6_if_freq_khz = TDA10048_IF_3300,1085	.dtv7_if_freq_khz = TDA10048_IF_3500,1086	.dtv8_if_freq_khz = TDA10048_IF_4000,1087	.clk_freq_khz     = TDA10048_CLK_16000,1088	.disable_gate_access = 1,1089};1090 1091static struct tda18271_std_map hauppauge_tda18271_std_map = {1092	.atsc_6   = { .if_freq = 3250, .agc_mode = 3, .std = 4,1093		      .if_lvl = 1, .rfagc_top = 0x58, },1094	.qam_6    = { .if_freq = 4000, .agc_mode = 3, .std = 5,1095		      .if_lvl = 1, .rfagc_top = 0x58, },1096};1097 1098static struct tda18271_config hcw_tda18271_config = {1099	.std_map = &hauppauge_tda18271_std_map,1100	.gate    = TDA18271_GATE_ANALOG,1101	.config  = 3,1102	.output_opt = TDA18271_OUTPUT_LT_OFF,1103};1104 1105static struct tda829x_config tda829x_no_probe = {1106	.probe_tuner = TDA829X_DONT_PROBE,1107};1108 1109static struct tda10048_config zolid_tda10048_config = {1110	.demod_address    = 0x10 >> 1,1111	.output_mode      = TDA10048_PARALLEL_OUTPUT,1112	.fwbulkwritelen   = TDA10048_BULKWRITE_200,1113	.inversion        = TDA10048_INVERSION_ON,1114	.dtv6_if_freq_khz = TDA10048_IF_3300,1115	.dtv7_if_freq_khz = TDA10048_IF_3500,1116	.dtv8_if_freq_khz = TDA10048_IF_4000,1117	.clk_freq_khz     = TDA10048_CLK_16000,1118	.disable_gate_access = 1,1119};1120 1121static struct tda18271_config zolid_tda18271_config = {1122	.gate    = TDA18271_GATE_ANALOG,1123};1124 1125static struct tda10048_config dtv1000s_tda10048_config = {1126	.demod_address    = 0x10 >> 1,1127	.output_mode      = TDA10048_PARALLEL_OUTPUT,1128	.fwbulkwritelen   = TDA10048_BULKWRITE_200,1129	.inversion        = TDA10048_INVERSION_ON,1130	.dtv6_if_freq_khz = TDA10048_IF_3300,1131	.dtv7_if_freq_khz = TDA10048_IF_3800,1132	.dtv8_if_freq_khz = TDA10048_IF_4300,1133	.clk_freq_khz     = TDA10048_CLK_16000,1134	.disable_gate_access = 1,1135};1136 1137static struct tda18271_std_map dtv1000s_tda18271_std_map = {1138	.dvbt_6   = { .if_freq = 3300, .agc_mode = 3, .std = 4,1139		      .if_lvl = 1, .rfagc_top = 0x37, },1140	.dvbt_7   = { .if_freq = 3800, .agc_mode = 3, .std = 5,1141		      .if_lvl = 1, .rfagc_top = 0x37, },1142	.dvbt_8   = { .if_freq = 4300, .agc_mode = 3, .std = 6,1143		      .if_lvl = 1, .rfagc_top = 0x37, },1144};1145 1146static struct tda18271_config dtv1000s_tda18271_config = {1147	.std_map = &dtv1000s_tda18271_std_map,1148	.gate    = TDA18271_GATE_ANALOG,1149};1150 1151static struct lgs8gxx_config prohdtv_pro2_lgs8g75_config = {1152	.prod = LGS8GXX_PROD_LGS8G75,1153	.demod_address = 0x1d,1154	.serial_ts = 0,1155	.ts_clk_pol = 1,1156	.ts_clk_gated = 0,1157	.if_clk_freq = 30400, /* 30.4 MHz */1158	.if_freq = 4000, /* 4.00 MHz */1159	.if_neg_center = 0,1160	.ext_adc = 0,1161	.adc_signed = 1,1162	.adc_vpp = 3, /* 2.0 Vpp */1163	.if_neg_edge = 1,1164};1165 1166static struct tda18271_config prohdtv_pro2_tda18271_config = {1167	.gate = TDA18271_GATE_ANALOG,1168	.output_opt = TDA18271_OUTPUT_LT_OFF,1169};1170 1171static struct tda18271_std_map kworld_tda18271_std_map = {1172	.atsc_6   = { .if_freq = 3250, .agc_mode = 3, .std = 3,1173		      .if_lvl = 6, .rfagc_top = 0x37 },1174	.qam_6    = { .if_freq = 4000, .agc_mode = 3, .std = 0,1175		      .if_lvl = 6, .rfagc_top = 0x37 },1176};1177 1178static struct tda18271_config kworld_pc150u_tda18271_config = {1179	.std_map = &kworld_tda18271_std_map,1180	.gate    = TDA18271_GATE_ANALOG,1181	.output_opt = TDA18271_OUTPUT_LT_OFF,1182	.config  = 3,	/* Use tuner callback for AGC */1183	.rf_cal_on_startup = 11184};1185 1186static struct s5h1411_config kworld_s5h1411_config = {1187	.output_mode   = S5H1411_PARALLEL_OUTPUT,1188	.gpio          = S5H1411_GPIO_OFF,1189	.qam_if        = S5H1411_IF_4000,1190	.vsb_if        = S5H1411_IF_3250,1191	.inversion     = S5H1411_INVERSION_ON,1192	.status_mode   = S5H1411_DEMODLOCKING,1193	.mpeg_timing   =1194		S5H1411_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK,1195};1196 1197static struct tda18271_config hdtv200h_tda18271_config = {1198	.gate    = TDA18271_GATE_ANALOG,1199	.config  = 3	/* Use tuner callback for AGC */1200};1201 1202static struct s5h1411_config hdtv200h_s5h1411_config = {1203	.output_mode   = S5H1411_PARALLEL_OUTPUT,1204	.gpio          = S5H1411_GPIO_OFF,1205	.qam_if        = S5H1411_IF_4000,1206	.vsb_if        = S5H1411_IF_3250,1207	.inversion     = S5H1411_INVERSION_ON,1208	.status_mode   = S5H1411_DEMODLOCKING,1209	.mpeg_timing   =1210		S5H1411_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK,1211};1212 1213 1214/* ==================================================================1215 * Core code1216 */1217 1218static int dvb_init(struct saa7134_dev *dev)1219{1220	int ret;1221	int attach_xc3028 = 0;1222	struct vb2_dvb_frontend *fe0;1223	struct vb2_queue *q;1224 1225	/* FIXME: add support for multi-frontend */1226	mutex_init(&dev->frontends.lock);1227	INIT_LIST_HEAD(&dev->frontends.felist);1228 1229	pr_info("%s() allocating 1 frontend\n", __func__);1230	fe0 = vb2_dvb_alloc_frontend(&dev->frontends, 1);1231	if (!fe0) {1232		pr_err("%s() failed to alloc\n", __func__);1233		return -ENOMEM;1234	}1235 1236	/* init struct vb2_dvb */1237	dev->ts.nr_bufs    = 32;1238	dev->ts.nr_packets = 32*4;1239	fe0->dvb.name = dev->name;1240	q = &fe0->dvb.dvbq;1241	q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;1242	q->io_modes = VB2_MMAP | VB2_READ;1243	q->drv_priv = &dev->ts_q;1244	q->ops = &saa7134_ts_qops;1245	q->mem_ops = &vb2_dma_sg_memops;1246	q->buf_struct_size = sizeof(struct saa7134_buf);1247	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;1248	q->lock = &dev->lock;1249	q->dev = &dev->pci->dev;1250	ret = vb2_queue_init(q);1251	if (ret) {1252		vb2_dvb_dealloc_frontends(&dev->frontends);1253		return ret;1254	}1255 1256	switch (dev->board) {1257	case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:1258		pr_debug("pinnacle 300i dvb setup\n");1259		fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,1260					       &dev->i2c_adap);1261		if (fe0->dvb.frontend) {1262			fe0->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;1263		}1264		break;1265	case SAA7134_BOARD_AVERMEDIA_777:1266	case SAA7134_BOARD_AVERMEDIA_A16AR:1267		pr_debug("avertv 777 dvb setup\n");1268		fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,1269					       &dev->i2c_adap);1270		if (fe0->dvb.frontend) {1271			dvb_attach(simple_tuner_attach, fe0->dvb.frontend,1272				   &dev->i2c_adap, 0x61,1273				   TUNER_PHILIPS_TD1316);1274		}1275		break;1276	case SAA7134_BOARD_AVERMEDIA_A16D:1277		pr_debug("AverMedia A16D dvb setup\n");1278		fe0->dvb.frontend = dvb_attach(mt352_attach,1279						&avermedia_xc3028_mt352_dev,1280						&dev->i2c_adap);1281		attach_xc3028 = 1;1282		break;1283	case SAA7134_BOARD_MD7134:1284		fe0->dvb.frontend = dvb_attach(tda10046_attach,1285					       &medion_cardbus,1286					       &dev->i2c_adap);1287		if (fe0->dvb.frontend) {1288			/*1289			 * The TV tuner on this board is actually NOT1290			 * behind the demod i2c gate.1291			 * However, the demod EEPROM is indeed there and it1292			 * conflicts with the SAA7134 chip config EEPROM1293			 * if the i2c gate is open (since they have same1294			 * bus addresses) resulting in card PCI SVID / SSID1295			 * being garbage after a reboot from time to time.1296			 *1297			 * Let's just leave the gate permanently closed -1298			 * saa7134_i2c_eeprom_md7134_gate() will close it for1299			 * us at probe time if it was open for some reason.1300			 */1301			fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;1302			dvb_attach(simple_tuner_attach, fe0->dvb.frontend,1303				   &dev->i2c_adap, medion_cardbus.tuner_address,1304				   TUNER_PHILIPS_FMD1216ME_MK3);1305		}1306		break;1307	case SAA7134_BOARD_PHILIPS_TOUGH:1308		fe0->dvb.frontend = dvb_attach(tda10046_attach,1309					       &philips_tu1216_60_config,1310					       &dev->i2c_adap);1311		if (fe0->dvb.frontend) {1312			fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;1313			fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;1314		}1315		break;1316	case SAA7134_BOARD_FLYDVBTDUO:1317	case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:1318		if (configure_tda827x_fe(dev, &tda827x_lifeview_config,1319					 &tda827x_cfg_0) < 0)1320			goto detach_frontend;1321		break;1322	case SAA7134_BOARD_PHILIPS_EUROPA:1323	case SAA7134_BOARD_VIDEOMATE_DVBT_300:1324	case SAA7134_BOARD_ASUS_EUROPA_HYBRID:1325		fe0->dvb.frontend = dvb_attach(tda10046_attach,1326					       &philips_europa_config,1327					       &dev->i2c_adap);1328		if (fe0->dvb.frontend) {1329			dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;1330			fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;1331			fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;1332			fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;1333			fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;1334		}1335		break;1336	case SAA7134_BOARD_TECHNOTREND_BUDGET_T3000:1337		fe0->dvb.frontend = dvb_attach(tda10046_attach,1338					       &technotrend_budget_t3000_config,1339					       &dev->i2c_adap);1340		if (fe0->dvb.frontend) {1341			dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;1342			fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;1343			fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;1344			fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;1345			fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;1346		}1347		break;1348	case SAA7134_BOARD_VIDEOMATE_DVBT_200:1349		fe0->dvb.frontend = dvb_attach(tda10046_attach,1350					       &philips_tu1216_61_config,1351					       &dev->i2c_adap);1352		if (fe0->dvb.frontend) {1353			fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;1354			fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;1355		}1356		break;1357	case SAA7134_BOARD_KWORLD_DVBT_210:1358		if (configure_tda827x_fe(dev, &kworld_dvb_t_210_config,1359					 &tda827x_cfg_2) < 0)1360			goto detach_frontend;1361		break;1362	case SAA7134_BOARD_HAUPPAUGE_HVR1120:1363		fe0->dvb.frontend = dvb_attach(tda10048_attach,1364					       &hcw_tda10048_config,1365					       &dev->i2c_adap);1366		if (fe0->dvb.frontend != NULL) {1367			dvb_attach(tda829x_attach, fe0->dvb.frontend,1368				   &dev->i2c_adap, 0x4b,1369				   &tda829x_no_probe);1370			dvb_attach(tda18271_attach, fe0->dvb.frontend,1371				   0x60, &dev->i2c_adap,1372				   &hcw_tda18271_config);1373		}1374		break;1375	case SAA7134_BOARD_PHILIPS_TIGER:1376		if (configure_tda827x_fe(dev, &philips_tiger_config,1377					 &tda827x_cfg_0) < 0)1378			goto detach_frontend;1379		break;1380	case SAA7134_BOARD_PINNACLE_PCTV_310i:1381		if (configure_tda827x_fe(dev, &pinnacle_pctv_310i_config,1382					 &tda827x_cfg_1) < 0)1383			goto detach_frontend;1384		break;1385	case SAA7134_BOARD_HAUPPAUGE_HVR1110:1386		if (configure_tda827x_fe(dev, &hauppauge_hvr_1110_config,1387					 &tda827x_cfg_1) < 0)1388			goto detach_frontend;1389		break;1390	case SAA7134_BOARD_HAUPPAUGE_HVR1150:1391		fe0->dvb.frontend = dvb_attach(lgdt3305_attach,1392					       &hcw_lgdt3305_config,1393					       &dev->i2c_adap);1394		if (fe0->dvb.frontend) {1395			dvb_attach(tda829x_attach, fe0->dvb.frontend,1396				   &dev->i2c_adap, 0x4b,1397				   &tda829x_no_probe);1398			dvb_attach(tda18271_attach, fe0->dvb.frontend,1399				   0x60, &dev->i2c_adap,1400				   &hcw_tda18271_config);1401		}1402		break;1403	case SAA7134_BOARD_ASUSTeK_P7131_DUAL:1404		if (configure_tda827x_fe(dev, &asus_p7131_dual_config,1405					 &tda827x_cfg_0) < 0)1406			goto detach_frontend;1407		break;1408	case SAA7134_BOARD_FLYDVBT_LR301:1409		if (configure_tda827x_fe(dev, &tda827x_lifeview_config,1410					 &tda827x_cfg_0) < 0)1411			goto detach_frontend;1412		break;1413	case SAA7134_BOARD_FLYDVB_TRIO:1414		if (!use_frontend) {	/* terrestrial */1415			if (configure_tda827x_fe(dev, &lifeview_trio_config,1416						 &tda827x_cfg_0) < 0)1417				goto detach_frontend;1418		} else {		/* satellite */1419			fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);1420			if (fe0->dvb.frontend) {1421				if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63,1422									&dev->i2c_adap, 0) == NULL) {1423					pr_warn("%s: Lifeview Trio, No tda826x found!\n",1424						__func__);1425					goto detach_frontend;1426				}1427				if (dvb_attach(isl6421_attach, fe0->dvb.frontend,1428					       &dev->i2c_adap,1429					       0x08, 0, 0, false) == NULL) {1430					pr_warn("%s: Lifeview Trio, No ISL6421 found!\n",1431						__func__);1432					goto detach_frontend;1433				}1434			}1435		}1436		break;1437	case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:1438	case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:1439		fe0->dvb.frontend = dvb_attach(tda10046_attach,1440					       &ads_tech_duo_config,1441					       &dev->i2c_adap);1442		if (fe0->dvb.frontend) {1443			if (dvb_attach(tda827x_attach,fe0->dvb.frontend,1444				   ads_tech_duo_config.tuner_address, &dev->i2c_adap,1445								&ads_duo_cfg) == NULL) {1446				pr_warn("no tda827x tuner found at addr: %02x\n",1447					ads_tech_duo_config.tuner_address);1448				goto detach_frontend;1449			}1450		} else1451			pr_warn("failed to attach tda10046\n");1452		break;1453	case SAA7134_BOARD_TEVION_DVBT_220RF:1454		if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,1455					 &tda827x_cfg_0) < 0)1456			goto detach_frontend;1457		break;1458	case SAA7134_BOARD_MEDION_MD8800_QUADRO:1459		if (!use_frontend) {     /* terrestrial */1460			if (configure_tda827x_fe(dev, &md8800_dvbt_config,1461						 &tda827x_cfg_0) < 0)1462				goto detach_frontend;1463		} else {        /* satellite */1464			fe0->dvb.frontend = dvb_attach(tda10086_attach,1465							&flydvbs, &dev->i2c_adap);1466			if (fe0->dvb.frontend) {1467				struct dvb_frontend *fe = fe0->dvb.frontend;1468				u8 dev_id = dev->eedata[2];1469				u8 data = 0xc4;1470				struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};1471 1472				if (dvb_attach(tda826x_attach, fe0->dvb.frontend,1473						0x60, &dev->i2c_adap, 0) == NULL) {1474					pr_warn("%s: Medion Quadro, no tda826x found !\n",1475						__func__);1476					goto detach_frontend;1477				}1478				if (dev_id != 0x08) {1479					/* we need to open the i2c gate (we know it exists) */1480					fe->ops.i2c_gate_ctrl(fe, 1);1481					if (dvb_attach(isl6405_attach, fe,1482							&dev->i2c_adap, 0x08, 0, 0) == NULL) {1483						pr_warn("%s: Medion Quadro, no ISL6405 found !\n",1484							__func__);1485						goto detach_frontend;1486					}1487					if (dev_id == 0x07) {1488						/* fire up the 2nd section of the LNB supply since1489						   we can't do this from the other section */1490						msg.buf = &data;1491						i2c_transfer(&dev->i2c_adap, &msg, 1);1492					}1493					fe->ops.i2c_gate_ctrl(fe, 0);1494					dev->original_set_voltage = fe->ops.set_voltage;1495					fe->ops.set_voltage = md8800_set_voltage;1496					dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;1497					fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;1498				} else {1499					fe->ops.set_voltage = md8800_set_voltage2;1500					fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;1501				}1502			}1503		}1504		break;1505	case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:1506		fe0->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,1507					       &dev->i2c_adap);1508		if (fe0->dvb.frontend)1509			dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x61,1510				   NULL, DVB_PLL_TDHU2);1511		break;1512	case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:1513	case SAA7134_BOARD_KWORLD_ATSC110:1514		fe0->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,1515					       &dev->i2c_adap);1516		if (fe0->dvb.frontend)1517			dvb_attach(simple_tuner_attach, fe0->dvb.frontend,1518				   &dev->i2c_adap, 0x61,1519				   TUNER_PHILIPS_TUV1236D);1520		break;1521	case SAA7134_BOARD_KWORLD_PC150U:1522		saa7134_set_gpio(dev, 18, 1); /* Switch to digital mode */1523		saa7134_tuner_callback(dev, 0,1524				       TDA18271_CALLBACK_CMD_AGC_ENABLE, 1);1525		fe0->dvb.frontend = dvb_attach(s5h1411_attach,1526					       &kworld_s5h1411_config,1527					       &dev->i2c_adap);1528		if (fe0->dvb.frontend != NULL) {1529			dvb_attach(tda829x_attach, fe0->dvb.frontend,1530				   &dev->i2c_adap, 0x4b,1531				   &tda829x_no_probe);1532			dvb_attach(tda18271_attach, fe0->dvb.frontend,1533				   0x60, &dev->i2c_adap,1534				   &kworld_pc150u_tda18271_config);1535		}1536		break;1537	case SAA7134_BOARD_FLYDVBS_LR300:1538		fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,1539					       &dev->i2c_adap);1540		if (fe0->dvb.frontend) {1541			if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,1542				       &dev->i2c_adap, 0) == NULL) {1543				pr_warn("%s: No tda826x found!\n", __func__);1544				goto detach_frontend;1545			}1546			if (dvb_attach(isl6421_attach, fe0->dvb.frontend,1547				       &dev->i2c_adap,1548				       0x08, 0, 0, false) == NULL) {1549				pr_warn("%s: No ISL6421 found!\n", __func__);1550				goto detach_frontend;1551			}1552		}1553		break;1554	case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:1555		fe0->dvb.frontend = dvb_attach(tda10046_attach,1556					       &medion_cardbus,1557					       &dev->i2c_adap);1558		if (fe0->dvb.frontend) {1559			dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;1560			fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;1561 1562			dvb_attach(simple_tuner_attach, fe0->dvb.frontend,1563				   &dev->i2c_adap, medion_cardbus.tuner_address,1564				   TUNER_PHILIPS_FMD1216ME_MK3);1565		}1566		break;1567	case SAA7134_BOARD_VIDEOMATE_DVBT_200A:1568		fe0->dvb.frontend = dvb_attach(tda10046_attach,1569				&philips_europa_config,1570				&dev->i2c_adap);1571		if (fe0->dvb.frontend) {1572			fe0->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;1573			fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;1574		}1575		break;1576	case SAA7134_BOARD_CINERGY_HT_PCMCIA:1577		if (configure_tda827x_fe(dev, &cinergy_ht_config,1578					 &tda827x_cfg_0) < 0)1579			goto detach_frontend;1580		break;1581	case SAA7134_BOARD_CINERGY_HT_PCI:1582		if (configure_tda827x_fe(dev, &cinergy_ht_pci_config,1583					 &tda827x_cfg_0) < 0)1584			goto detach_frontend;1585		break;1586	case SAA7134_BOARD_PHILIPS_TIGER_S:1587		if (configure_tda827x_fe(dev, &philips_tiger_s_config,1588					 &tda827x_cfg_2) < 0)1589			goto detach_frontend;1590		break;1591	case SAA7134_BOARD_ASUS_P7131_4871:1592		if (configure_tda827x_fe(dev, &asus_p7131_4871_config,1593					 &tda827x_cfg_2) < 0)1594			goto detach_frontend;1595		break;1596	case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:1597		if (configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config,1598					 &tda827x_cfg_2) < 0)1599			goto detach_frontend;1600		break;1601	case SAA7134_BOARD_AVERMEDIA_SUPER_007:1602		if (configure_tda827x_fe(dev, &avermedia_super_007_config,1603					 &tda827x_cfg_0) < 0)1604			goto detach_frontend;1605		break;1606	case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:1607		if (configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config,1608					 &tda827x_cfg_2_sw42) < 0)1609			goto detach_frontend;1610		break;1611	case SAA7134_BOARD_PHILIPS_SNAKE:1612		fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,1613						&dev->i2c_adap);1614		if (fe0->dvb.frontend) {1615			if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,1616					&dev->i2c_adap, 0) == NULL) {1617				pr_warn("%s: No tda826x found!\n", __func__);1618				goto detach_frontend;1619			}1620			if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,1621					&dev->i2c_adap, 0, 0) == NULL) {1622				pr_warn("%s: No lnbp21 found!\n", __func__);1623				goto detach_frontend;1624			}1625		}1626		break;1627	case SAA7134_BOARD_CREATIX_CTX953:1628		if (configure_tda827x_fe(dev, &md8800_dvbt_config,1629					 &tda827x_cfg_0) < 0)1630			goto detach_frontend;1631		break;1632	case SAA7134_BOARD_MSI_TVANYWHERE_AD11:1633		if (configure_tda827x_fe(dev, &philips_tiger_s_config,1634					 &tda827x_cfg_2) < 0)1635			goto detach_frontend;1636		break;1637	case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:1638		pr_debug("AverMedia E506R dvb setup\n");1639		saa7134_set_gpio(dev, 25, 0);1640		msleep(10);1641		saa7134_set_gpio(dev, 25, 1);1642		fe0->dvb.frontend = dvb_attach(mt352_attach,1643						&avermedia_xc3028_mt352_dev,1644						&dev->i2c_adap);1645		attach_xc3028 = 1;1646		break;1647	case SAA7134_BOARD_MD7134_BRIDGE_2:1648		fe0->dvb.frontend = dvb_attach(tda10086_attach,1649						&sd1878_4m, &dev->i2c_adap);1650		if (fe0->dvb.frontend) {1651			struct dvb_frontend *fe;1652			if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,1653				  &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) {1654				pr_warn("%s: MD7134 DVB-S, no SD1878 found !\n",1655					__func__);1656				goto detach_frontend;1657			}1658			/* we need to open the i2c gate (we know it exists) */1659			fe = fe0->dvb.frontend;1660			fe->ops.i2c_gate_ctrl(fe, 1);1661			if (dvb_attach(isl6405_attach, fe,1662					&dev->i2c_adap, 0x08, 0, 0) == NULL) {1663				pr_warn("%s: MD7134 DVB-S, no ISL6405 found !\n",1664					__func__);1665				goto detach_frontend;1666			}1667			fe->ops.i2c_gate_ctrl(fe, 0);1668			dev->original_set_voltage = fe->ops.set_voltage;1669			fe->ops.set_voltage = md8800_set_voltage;1670			dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;1671			fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;1672		}1673		break;1674	case SAA7134_BOARD_AVERMEDIA_M103:1675		saa7134_set_gpio(dev, 25, 0);1676		msleep(10);1677		saa7134_set_gpio(dev, 25, 1);1678		fe0->dvb.frontend = dvb_attach(mt352_attach,1679						&avermedia_xc3028_mt352_dev,1680						&dev->i2c_adap);1681		attach_xc3028 = 1;1682		break;1683	case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:1684		if (!use_frontend) {     /* terrestrial */1685			if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,1686							&tda827x_cfg_2) < 0)1687				goto detach_frontend;1688		} else {		/* satellite */1689			fe0->dvb.frontend = dvb_attach(tda10086_attach,1690						&flydvbs, &dev->i2c_adap);1691			if (fe0->dvb.frontend) {1692				if (dvb_attach(tda826x_attach,1693						fe0->dvb.frontend, 0x60,1694						&dev->i2c_adap, 0) == NULL) {1695					pr_warn("%s: Asus Tiger 3in1, no tda826x found!\n",1696						__func__);1697					goto detach_frontend;1698				}1699				if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,1700						&dev->i2c_adap, 0, 0) == NULL) {1701					pr_warn("%s: Asus Tiger 3in1, no lnbp21 found!\n",1702						__func__);1703					goto detach_frontend;1704			       }1705		       }1706	       }1707	       break;1708	case SAA7134_BOARD_ASUSTeK_PS3_100:1709		if (!use_frontend) {     /* terrestrial */1710			if (configure_tda827x_fe(dev, &asus_ps3_100_config,1711						 &tda827x_cfg_2) < 0)1712				goto detach_frontend;1713	       } else {                /* satellite */1714			fe0->dvb.frontend = dvb_attach(tda10086_attach,1715						       &flydvbs, &dev->i2c_adap);1716			if (fe0->dvb.frontend) {1717				if (dvb_attach(tda826x_attach,1718					       fe0->dvb.frontend, 0x60,1719					       &dev->i2c_adap, 0) == NULL) {1720					pr_warn("%s: Asus My Cinema PS3-100, no tda826x found!\n",1721						__func__);1722					goto detach_frontend;1723				}1724				if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,1725					       &dev->i2c_adap, 0, 0) == NULL) {1726					pr_warn("%s: Asus My Cinema PS3-100, no lnbp21 found!\n",1727						__func__);1728					goto detach_frontend;1729				}1730			}1731		}1732		break;1733	case SAA7134_BOARD_ASUSTeK_TIGER:1734		if (configure_tda827x_fe(dev, &philips_tiger_config,1735					 &tda827x_cfg_0) < 0)1736			goto detach_frontend;1737		break;1738	case SAA7134_BOARD_BEHOLD_H6:1739		fe0->dvb.frontend = dvb_attach(zl10353_attach,1740						&behold_h6_config,1741						&dev->i2c_adap);1742		if (fe0->dvb.frontend) {1743			dvb_attach(simple_tuner_attach, fe0->dvb.frontend,1744				   &dev->i2c_adap, 0x61,1745				   TUNER_PHILIPS_FMD1216MEX_MK3);1746		}1747		break;1748	case SAA7134_BOARD_BEHOLD_X7:1749		fe0->dvb.frontend = dvb_attach(zl10353_attach,1750						&behold_x7_config,1751						&dev->i2c_adap);1752		if (fe0->dvb.frontend) {1753			dvb_attach(xc5000_attach, fe0->dvb.frontend,1754				   &dev->i2c_adap, &behold_x7_tunerconfig);1755		}1756		break;1757	case SAA7134_BOARD_BEHOLD_H7:1758		fe0->dvb.frontend = dvb_attach(zl10353_attach,1759						&behold_x7_config,1760						&dev->i2c_adap);1761		if (fe0->dvb.frontend) {1762			dvb_attach(xc5000_attach, fe0->dvb.frontend,1763				   &dev->i2c_adap, &behold_x7_tunerconfig);1764		}1765		break;1766	case SAA7134_BOARD_AVERMEDIA_A700_PRO:1767	case SAA7134_BOARD_AVERMEDIA_A700_HYBRID:1768		/* Zarlink ZL10313 */1769		fe0->dvb.frontend = dvb_attach(mt312_attach,1770			&avertv_a700_mt312, &dev->i2c_adap);1771		if (fe0->dvb.frontend) {1772			if (dvb_attach(zl10036_attach, fe0->dvb.frontend,1773					&avertv_a700_tuner, &dev->i2c_adap) == NULL) {1774				pr_warn("%s: No zl10036 found!\n",1775					__func__);1776			}1777		}1778		break;1779	case SAA7134_BOARD_VIDEOMATE_S350:1780		fe0->dvb.frontend = dvb_attach(mt312_attach,1781				&zl10313_compro_s350_config, &dev->i2c_adap);1782		if (fe0->dvb.frontend)1783			if (dvb_attach(zl10039_attach, fe0->dvb.frontend,1784					0x60, &dev->i2c_adap) == NULL)1785				pr_warn("%s: No zl10039 found!\n",1786					__func__);1787 1788		break;1789	case SAA7134_BOARD_VIDEOMATE_T750:1790		fe0->dvb.frontend = dvb_attach(zl10353_attach,1791						&videomate_t750_zl10353_config,1792						&dev->i2c_adap);1793		if (fe0->dvb.frontend != NULL) {1794			if (dvb_attach(qt1010_attach,1795					fe0->dvb.frontend,1796					&dev->i2c_adap,1797					&videomate_t750_qt1010_config) == NULL)1798				pr_warn("error attaching QT1010\n");1799		}1800		break;1801	case SAA7134_BOARD_ZOLID_HYBRID_PCI:1802		fe0->dvb.frontend = dvb_attach(tda10048_attach,1803					       &zolid_tda10048_config,1804					       &dev->i2c_adap);1805		if (fe0->dvb.frontend != NULL) {1806			dvb_attach(tda829x_attach, fe0->dvb.frontend,1807				   &dev->i2c_adap, 0x4b,1808				   &tda829x_no_probe);1809			dvb_attach(tda18271_attach, fe0->dvb.frontend,1810				   0x60, &dev->i2c_adap,1811				   &zolid_tda18271_config);1812		}1813		break;1814	case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:1815		fe0->dvb.frontend = dvb_attach(tda10048_attach,1816					       &dtv1000s_tda10048_config,1817					       &dev->i2c_adap);1818		if (fe0->dvb.frontend != NULL) {1819			dvb_attach(tda829x_attach, fe0->dvb.frontend,1820				   &dev->i2c_adap, 0x4b,1821				   &tda829x_no_probe);1822			dvb_attach(tda18271_attach, fe0->dvb.frontend,1823				   0x60, &dev->i2c_adap,1824				   &dtv1000s_tda18271_config);1825		}1826		break;1827	case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG:1828		/* Switch to digital mode */1829		saa7134_tuner_callback(dev, 0,1830				       TDA18271_CALLBACK_CMD_AGC_ENABLE, 1);1831		fe0->dvb.frontend = dvb_attach(mb86a20s_attach,1832					       &kworld_mb86a20s_config,1833					       &dev->i2c_adap);1834		if (fe0->dvb.frontend != NULL) {1835			dvb_attach(tda829x_attach, fe0->dvb.frontend,1836				   &dev->i2c_adap, 0x4b,1837				   &tda829x_no_probe);1838			fe0->dvb.frontend->ops.i2c_gate_ctrl = kworld_sbtvd_gate_ctrl;1839			dvb_attach(tda18271_attach, fe0->dvb.frontend,1840				   0x60, &dev->i2c_adap,1841				   &kworld_tda18271_config);1842		}1843 1844		/* mb86a20s need to use the I2C gateway */1845		break;1846	case SAA7134_BOARD_MAGICPRO_PROHDTV_PRO2:1847		fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,1848					       &prohdtv_pro2_lgs8g75_config,1849					       &dev->i2c_adap);1850		if (fe0->dvb.frontend != NULL) {1851			dvb_attach(tda829x_attach, fe0->dvb.frontend,1852				   &dev->i2c_adap, 0x4b,1853				   &tda829x_no_probe);1854			dvb_attach(tda18271_attach, fe0->dvb.frontend,1855				   0x60, &dev->i2c_adap,1856				   &prohdtv_pro2_tda18271_config);1857		}1858		break;1859	case SAA7134_BOARD_AVERMEDIA_A706:1860		/* Enable all DVB-S devices now */1861		/* CE5039 DVB-S tuner SLEEP pin low */1862		saa7134_set_gpio(dev, 23, 0);1863		/* CE6313 DVB-S demod SLEEP pin low */1864		saa7134_set_gpio(dev, 9, 0);1865		/* CE6313 DVB-S demod RESET# pin high */1866		saa7134_set_gpio(dev, 25, 1);1867		msleep(1);1868		fe0->dvb.frontend = dvb_attach(mt312_attach,1869				&zl10313_avermedia_a706_config, &dev->i2c_adap);1870		if (fe0->dvb.frontend) {1871			fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;1872			if (dvb_attach(zl10039_attach, fe0->dvb.frontend,1873					0x60, &dev->i2c_adap) == NULL)1874				pr_warn("%s: No zl10039 found!\n",1875					__func__);1876		}1877		break;1878	case SAA7134_BOARD_LEADTEK_WINFAST_HDTV200_H:1879		fe0->dvb.frontend = dvb_attach(s5h1411_attach,1880					       &hdtv200h_s5h1411_config,1881					       &dev->i2c_adap);1882		if (fe0->dvb.frontend) {1883			dvb_attach(tda829x_attach, fe0->dvb.frontend,1884				   &dev->i2c_adap, 0x4b,1885				   &tda829x_no_probe);1886			dvb_attach(tda18271_attach, fe0->dvb.frontend,1887				   0x60, &dev->i2c_adap,1888				   &hdtv200h_tda18271_config);1889		}1890		break;1891	default:1892		pr_warn("Huh? unknown DVB card?\n");1893		break;1894	}1895 1896	if (attach_xc3028) {1897		struct dvb_frontend *fe;1898		struct xc2028_config cfg = {1899			.i2c_adap  = &dev->i2c_adap,1900			.i2c_addr  = 0x61,1901		};1902 1903		if (!fe0->dvb.frontend)1904			goto detach_frontend;1905 1906		fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);1907		if (!fe) {1908			pr_err("%s/2: xc3028 attach failed\n",1909			       dev->name);1910			goto detach_frontend;1911		}1912	}1913 1914	if (NULL == fe0->dvb.frontend) {1915		pr_err("%s/dvb: frontend initialization failed\n", dev->name);1916		goto detach_frontend;1917	}1918	/* define general-purpose callback pointer */1919	fe0->dvb.frontend->callback = saa7134_tuner_callback;1920 1921	/* register everything else */1922#ifndef CONFIG_MEDIA_CONTROLLER_DVB1923	ret = vb2_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,1924				   &dev->pci->dev, NULL,1925				   adapter_nr, 0);1926#else1927	ret = vb2_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,1928				   &dev->pci->dev, dev->media_dev,1929				   adapter_nr, 0);1930#endif1931 1932	/* this sequence is necessary to make the tda1004x load its firmware1933	 * and to enter analog mode of hybrid boards1934	 */1935	if (!ret) {1936		if (fe0->dvb.frontend->ops.init)1937			fe0->dvb.frontend->ops.init(fe0->dvb.frontend);1938		if (fe0->dvb.frontend->ops.sleep)1939			fe0->dvb.frontend->ops.sleep(fe0->dvb.frontend);1940		if (fe0->dvb.frontend->ops.tuner_ops.sleep)1941			fe0->dvb.frontend->ops.tuner_ops.sleep(fe0->dvb.frontend);1942	}1943	return ret;1944 1945detach_frontend:1946	vb2_dvb_dealloc_frontends(&dev->frontends);1947	vb2_queue_release(&fe0->dvb.dvbq);1948	return -EINVAL;1949}1950 1951static int dvb_fini(struct saa7134_dev *dev)1952{1953	struct vb2_dvb_frontend *fe0;1954 1955	/* Get the first frontend */1956	fe0 = vb2_dvb_get_frontend(&dev->frontends, 1);1957	if (!fe0)1958		return -EINVAL;1959 1960	/* FIXME: I suspect that this code is bogus, since the entry for1961	   Pinnacle 300I DVB-T PAL already defines the proper init to allow1962	   the detection of mt2032 (TDA9887_PORT2_INACTIVE)1963	 */1964	if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {1965		struct v4l2_priv_tun_config tda9887_cfg;1966		static int on  = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;1967 1968		tda9887_cfg.tuner = TUNER_TDA9887;1969		tda9887_cfg.priv  = &on;1970 1971		/* otherwise we don't detect the tuner on next insmod */1972		saa_call_all(dev, tuner, s_config, &tda9887_cfg);1973	} else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {1974		if ((dev->eedata[2] == 0x07) && use_frontend) {1975			/* turn off the 2nd lnb supply */1976			u8 data = 0x80;1977			struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};1978			struct dvb_frontend *fe;1979			fe = fe0->dvb.frontend;1980			if (fe->ops.i2c_gate_ctrl) {1981				fe->ops.i2c_gate_ctrl(fe, 1);1982				i2c_transfer(&dev->i2c_adap, &msg, 1);1983				fe->ops.i2c_gate_ctrl(fe, 0);1984			}1985		}1986	}1987	vb2_dvb_unregister_bus(&dev->frontends);1988	vb2_queue_release(&fe0->dvb.dvbq);1989	return 0;1990}1991 1992static struct saa7134_mpeg_ops dvb_ops = {1993	.type          = SAA7134_MPEG_DVB,1994	.init          = dvb_init,1995	.fini          = dvb_fini,1996};1997 1998static int __init dvb_register(void)1999{2000	return saa7134_ts_register(&dvb_ops);2001}2002 2003static void __exit dvb_unregister(void)2004{2005	saa7134_ts_unregister(&dvb_ops);2006}2007 2008module_init(dvb_register);2009module_exit(dvb_unregister);2010