Path: blob/master/drivers/media/video/cx88/cx88-dvb.c
17681 views
/*1*2* device driver for Conexant 2388x based TV cards3* MPEG Transport Stream (DVB) routines4*5* (c) 2004, 2005 Chris Pascoe <[email protected]>6* (c) 2004 Gerd Knorr <[email protected]> [SuSE Labs]7*8* This program is free software; you can redistribute it and/or modify9* it under the terms of the GNU General Public License as published by10* the Free Software Foundation; either version 2 of the License, or11* (at your option) any later version.12*13* This program is distributed in the hope that it will be useful,14* but WITHOUT ANY WARRANTY; without even the implied warranty of15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16* GNU General Public License for more details.17*18* You should have received a copy of the GNU General Public License19* along with this program; if not, write to the Free Software20* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.21*/2223#include <linux/module.h>24#include <linux/init.h>25#include <linux/device.h>26#include <linux/fs.h>27#include <linux/kthread.h>28#include <linux/file.h>29#include <linux/suspend.h>3031#include "cx88.h"32#include "dvb-pll.h"33#include <media/v4l2-common.h>3435#include "mt352.h"36#include "mt352_priv.h"37#include "cx88-vp3054-i2c.h"38#include "zl10353.h"39#include "cx22702.h"40#include "or51132.h"41#include "lgdt330x.h"42#include "s5h1409.h"43#include "xc5000.h"44#include "nxt200x.h"45#include "cx24123.h"46#include "isl6421.h"47#include "tuner-simple.h"48#include "tda9887.h"49#include "s5h1411.h"50#include "stv0299.h"51#include "z0194a.h"52#include "stv0288.h"53#include "stb6000.h"54#include "cx24116.h"55#include "stv0900.h"56#include "stb6100.h"57#include "stb6100_proc.h"58#include "mb86a16.h"59#include "ds3000.h"6061MODULE_DESCRIPTION("driver for cx2388x based DVB cards");62MODULE_AUTHOR("Chris Pascoe <[email protected]>");63MODULE_AUTHOR("Gerd Knorr <[email protected]> [SuSE Labs]");64MODULE_LICENSE("GPL");6566static unsigned int debug;67module_param(debug, int, 0644);68MODULE_PARM_DESC(debug,"enable debug messages [dvb]");6970static unsigned int dvb_buf_tscnt = 32;71module_param(dvb_buf_tscnt, int, 0644);72MODULE_PARM_DESC(dvb_buf_tscnt, "DVB Buffer TS count [dvb]");7374DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);7576#define dprintk(level,fmt, arg...) if (debug >= level) \77printk(KERN_DEBUG "%s/2-dvb: " fmt, core->name, ## arg)7879/* ------------------------------------------------------------------ */8081static int dvb_buf_setup(struct videobuf_queue *q,82unsigned int *count, unsigned int *size)83{84struct cx8802_dev *dev = q->priv_data;8586dev->ts_packet_size = 188 * 4;87dev->ts_packet_count = dvb_buf_tscnt;8889*size = dev->ts_packet_size * dev->ts_packet_count;90*count = dvb_buf_tscnt;91return 0;92}9394static int dvb_buf_prepare(struct videobuf_queue *q,95struct videobuf_buffer *vb, enum v4l2_field field)96{97struct cx8802_dev *dev = q->priv_data;98return cx8802_buf_prepare(q, dev, (struct cx88_buffer*)vb,field);99}100101static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)102{103struct cx8802_dev *dev = q->priv_data;104cx8802_buf_queue(dev, (struct cx88_buffer*)vb);105}106107static void dvb_buf_release(struct videobuf_queue *q,108struct videobuf_buffer *vb)109{110cx88_free_buffer(q, (struct cx88_buffer*)vb);111}112113static const struct videobuf_queue_ops dvb_qops = {114.buf_setup = dvb_buf_setup,115.buf_prepare = dvb_buf_prepare,116.buf_queue = dvb_buf_queue,117.buf_release = dvb_buf_release,118};119120/* ------------------------------------------------------------------ */121122static int cx88_dvb_bus_ctrl(struct dvb_frontend* fe, int acquire)123{124struct cx8802_dev *dev= fe->dvb->priv;125struct cx8802_driver *drv = NULL;126int ret = 0;127int fe_id;128129fe_id = videobuf_dvb_find_frontend(&dev->frontends, fe);130if (!fe_id) {131printk(KERN_ERR "%s() No frontend found\n", __func__);132return -EINVAL;133}134135mutex_lock(&dev->core->lock);136drv = cx8802_get_driver(dev, CX88_MPEG_DVB);137if (drv) {138if (acquire){139dev->frontends.active_fe_id = fe_id;140ret = drv->request_acquire(drv);141} else {142ret = drv->request_release(drv);143dev->frontends.active_fe_id = 0;144}145}146mutex_unlock(&dev->core->lock);147148return ret;149}150151static void cx88_dvb_gate_ctrl(struct cx88_core *core, int open)152{153struct videobuf_dvb_frontends *f;154struct videobuf_dvb_frontend *fe;155156if (!core->dvbdev)157return;158159f = &core->dvbdev->frontends;160161if (!f)162return;163164if (f->gate <= 1) /* undefined or fe0 */165fe = videobuf_dvb_get_frontend(f, 1);166else167fe = videobuf_dvb_get_frontend(f, f->gate);168169if (fe && fe->dvb.frontend && fe->dvb.frontend->ops.i2c_gate_ctrl)170fe->dvb.frontend->ops.i2c_gate_ctrl(fe->dvb.frontend, open);171}172173/* ------------------------------------------------------------------ */174175static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)176{177static const u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 };178static const u8 reset [] = { RESET, 0x80 };179static const u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };180static const u8 agc_cfg [] = { AGC_TARGET, 0x24, 0x20 };181static const u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };182static const u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };183184mt352_write(fe, clock_config, sizeof(clock_config));185udelay(200);186mt352_write(fe, reset, sizeof(reset));187mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));188189mt352_write(fe, agc_cfg, sizeof(agc_cfg));190mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));191mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));192return 0;193}194195static int dvico_dual_demod_init(struct dvb_frontend *fe)196{197static const u8 clock_config [] = { CLOCK_CTL, 0x38, 0x38 };198static const u8 reset [] = { RESET, 0x80 };199static const u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };200static const u8 agc_cfg [] = { AGC_TARGET, 0x28, 0x20 };201static const u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };202static const u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };203204mt352_write(fe, clock_config, sizeof(clock_config));205udelay(200);206mt352_write(fe, reset, sizeof(reset));207mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));208209mt352_write(fe, agc_cfg, sizeof(agc_cfg));210mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));211mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));212213return 0;214}215216static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)217{218static const u8 clock_config [] = { 0x89, 0x38, 0x39 };219static const u8 reset [] = { 0x50, 0x80 };220static const u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };221static const u8 agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,2220x00, 0xFF, 0x00, 0x40, 0x40 };223static const u8 dntv_extra[] = { 0xB5, 0x7A };224static const u8 capt_range_cfg[] = { 0x75, 0x32 };225226mt352_write(fe, clock_config, sizeof(clock_config));227udelay(2000);228mt352_write(fe, reset, sizeof(reset));229mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));230231mt352_write(fe, agc_cfg, sizeof(agc_cfg));232udelay(2000);233mt352_write(fe, dntv_extra, sizeof(dntv_extra));234mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));235236return 0;237}238239static const struct mt352_config dvico_fusionhdtv = {240.demod_address = 0x0f,241.demod_init = dvico_fusionhdtv_demod_init,242};243244static const struct mt352_config dntv_live_dvbt_config = {245.demod_address = 0x0f,246.demod_init = dntv_live_dvbt_demod_init,247};248249static const struct mt352_config dvico_fusionhdtv_dual = {250.demod_address = 0x0f,251.demod_init = dvico_dual_demod_init,252};253254static const struct zl10353_config cx88_terratec_cinergy_ht_pci_mkii_config = {255.demod_address = (0x1e >> 1),256.no_tuner = 1,257.if2 = 45600,258};259260static struct mb86a16_config twinhan_vp1027 = {261.demod_address = 0x08,262};263264#if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE))265static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe)266{267static const u8 clock_config [] = { 0x89, 0x38, 0x38 };268static const u8 reset [] = { 0x50, 0x80 };269static const u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };270static const u8 agc_cfg [] = { 0x67, 0x10, 0x20, 0x00, 0xFF, 0xFF,2710x00, 0xFF, 0x00, 0x40, 0x40 };272static const u8 dntv_extra[] = { 0xB5, 0x7A };273static const u8 capt_range_cfg[] = { 0x75, 0x32 };274275mt352_write(fe, clock_config, sizeof(clock_config));276udelay(2000);277mt352_write(fe, reset, sizeof(reset));278mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));279280mt352_write(fe, agc_cfg, sizeof(agc_cfg));281udelay(2000);282mt352_write(fe, dntv_extra, sizeof(dntv_extra));283mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));284285return 0;286}287288static const struct mt352_config dntv_live_dvbt_pro_config = {289.demod_address = 0x0f,290.no_tuner = 1,291.demod_init = dntv_live_dvbt_pro_demod_init,292};293#endif294295static const struct zl10353_config dvico_fusionhdtv_hybrid = {296.demod_address = 0x0f,297.no_tuner = 1,298};299300static const struct zl10353_config dvico_fusionhdtv_xc3028 = {301.demod_address = 0x0f,302.if2 = 45600,303.no_tuner = 1,304};305306static const struct mt352_config dvico_fusionhdtv_mt352_xc3028 = {307.demod_address = 0x0f,308.if2 = 4560,309.no_tuner = 1,310.demod_init = dvico_fusionhdtv_demod_init,311};312313static const struct zl10353_config dvico_fusionhdtv_plus_v1_1 = {314.demod_address = 0x0f,315};316317static const struct cx22702_config connexant_refboard_config = {318.demod_address = 0x43,319.output_mode = CX22702_SERIAL_OUTPUT,320};321322static const struct cx22702_config hauppauge_hvr_config = {323.demod_address = 0x63,324.output_mode = CX22702_SERIAL_OUTPUT,325};326327static int or51132_set_ts_param(struct dvb_frontend* fe, int is_punctured)328{329struct cx8802_dev *dev= fe->dvb->priv;330dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;331return 0;332}333334static const struct or51132_config pchdtv_hd3000 = {335.demod_address = 0x15,336.set_ts_params = or51132_set_ts_param,337};338339static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index)340{341struct cx8802_dev *dev= fe->dvb->priv;342struct cx88_core *core = dev->core;343344dprintk(1, "%s: index = %d\n", __func__, index);345if (index == 0)346cx_clear(MO_GP0_IO, 8);347else348cx_set(MO_GP0_IO, 8);349return 0;350}351352static int lgdt330x_set_ts_param(struct dvb_frontend* fe, int is_punctured)353{354struct cx8802_dev *dev= fe->dvb->priv;355if (is_punctured)356dev->ts_gen_cntrl |= 0x04;357else358dev->ts_gen_cntrl &= ~0x04;359return 0;360}361362static struct lgdt330x_config fusionhdtv_3_gold = {363.demod_address = 0x0e,364.demod_chip = LGDT3302,365.serial_mpeg = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */366.set_ts_params = lgdt330x_set_ts_param,367};368369static const struct lgdt330x_config fusionhdtv_5_gold = {370.demod_address = 0x0e,371.demod_chip = LGDT3303,372.serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */373.set_ts_params = lgdt330x_set_ts_param,374};375376static const struct lgdt330x_config pchdtv_hd5500 = {377.demod_address = 0x59,378.demod_chip = LGDT3303,379.serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */380.set_ts_params = lgdt330x_set_ts_param,381};382383static int nxt200x_set_ts_param(struct dvb_frontend* fe, int is_punctured)384{385struct cx8802_dev *dev= fe->dvb->priv;386dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;387return 0;388}389390static const struct nxt200x_config ati_hdtvwonder = {391.demod_address = 0x0a,392.set_ts_params = nxt200x_set_ts_param,393};394395static int cx24123_set_ts_param(struct dvb_frontend* fe,396int is_punctured)397{398struct cx8802_dev *dev= fe->dvb->priv;399dev->ts_gen_cntrl = 0x02;400return 0;401}402403static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe,404fe_sec_voltage_t voltage)405{406struct cx8802_dev *dev= fe->dvb->priv;407struct cx88_core *core = dev->core;408409if (voltage == SEC_VOLTAGE_OFF)410cx_write(MO_GP0_IO, 0x000006fb);411else412cx_write(MO_GP0_IO, 0x000006f9);413414if (core->prev_set_voltage)415return core->prev_set_voltage(fe, voltage);416return 0;417}418419static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,420fe_sec_voltage_t voltage)421{422struct cx8802_dev *dev= fe->dvb->priv;423struct cx88_core *core = dev->core;424425if (voltage == SEC_VOLTAGE_OFF) {426dprintk(1,"LNB Voltage OFF\n");427cx_write(MO_GP0_IO, 0x0000efff);428}429430if (core->prev_set_voltage)431return core->prev_set_voltage(fe, voltage);432return 0;433}434435static int tevii_dvbs_set_voltage(struct dvb_frontend *fe,436fe_sec_voltage_t voltage)437{438struct cx8802_dev *dev= fe->dvb->priv;439struct cx88_core *core = dev->core;440441cx_set(MO_GP0_IO, 0x6040);442switch (voltage) {443case SEC_VOLTAGE_13:444cx_clear(MO_GP0_IO, 0x20);445break;446case SEC_VOLTAGE_18:447cx_set(MO_GP0_IO, 0x20);448break;449case SEC_VOLTAGE_OFF:450cx_clear(MO_GP0_IO, 0x20);451break;452}453454if (core->prev_set_voltage)455return core->prev_set_voltage(fe, voltage);456return 0;457}458459static int vp1027_set_voltage(struct dvb_frontend *fe,460fe_sec_voltage_t voltage)461{462struct cx8802_dev *dev = fe->dvb->priv;463struct cx88_core *core = dev->core;464465switch (voltage) {466case SEC_VOLTAGE_13:467dprintk(1, "LNB SEC Voltage=13\n");468cx_write(MO_GP0_IO, 0x00001220);469break;470case SEC_VOLTAGE_18:471dprintk(1, "LNB SEC Voltage=18\n");472cx_write(MO_GP0_IO, 0x00001222);473break;474case SEC_VOLTAGE_OFF:475dprintk(1, "LNB Voltage OFF\n");476cx_write(MO_GP0_IO, 0x00001230);477break;478}479480if (core->prev_set_voltage)481return core->prev_set_voltage(fe, voltage);482return 0;483}484485static const struct cx24123_config geniatech_dvbs_config = {486.demod_address = 0x55,487.set_ts_params = cx24123_set_ts_param,488};489490static const struct cx24123_config hauppauge_novas_config = {491.demod_address = 0x55,492.set_ts_params = cx24123_set_ts_param,493};494495static const struct cx24123_config kworld_dvbs_100_config = {496.demod_address = 0x15,497.set_ts_params = cx24123_set_ts_param,498.lnb_polarity = 1,499};500501static const struct s5h1409_config pinnacle_pctv_hd_800i_config = {502.demod_address = 0x32 >> 1,503.output_mode = S5H1409_PARALLEL_OUTPUT,504.gpio = S5H1409_GPIO_ON,505.qam_if = 44000,506.inversion = S5H1409_INVERSION_OFF,507.status_mode = S5H1409_DEMODLOCKING,508.mpeg_timing = S5H1409_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK,509};510511static const struct s5h1409_config dvico_hdtv5_pci_nano_config = {512.demod_address = 0x32 >> 1,513.output_mode = S5H1409_SERIAL_OUTPUT,514.gpio = S5H1409_GPIO_OFF,515.inversion = S5H1409_INVERSION_OFF,516.status_mode = S5H1409_DEMODLOCKING,517.mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,518};519520static const struct s5h1409_config kworld_atsc_120_config = {521.demod_address = 0x32 >> 1,522.output_mode = S5H1409_SERIAL_OUTPUT,523.gpio = S5H1409_GPIO_OFF,524.inversion = S5H1409_INVERSION_OFF,525.status_mode = S5H1409_DEMODLOCKING,526.mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,527};528529static const struct xc5000_config pinnacle_pctv_hd_800i_tuner_config = {530.i2c_address = 0x64,531.if_khz = 5380,532};533534static const struct zl10353_config cx88_pinnacle_hybrid_pctv = {535.demod_address = (0x1e >> 1),536.no_tuner = 1,537.if2 = 45600,538};539540static const struct zl10353_config cx88_geniatech_x8000_mt = {541.demod_address = (0x1e >> 1),542.no_tuner = 1,543.disable_i2c_gate_ctrl = 1,544};545546static const struct s5h1411_config dvico_fusionhdtv7_config = {547.output_mode = S5H1411_SERIAL_OUTPUT,548.gpio = S5H1411_GPIO_ON,549.mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,550.qam_if = S5H1411_IF_44000,551.vsb_if = S5H1411_IF_44000,552.inversion = S5H1411_INVERSION_OFF,553.status_mode = S5H1411_DEMODLOCKING554};555556static const struct xc5000_config dvico_fusionhdtv7_tuner_config = {557.i2c_address = 0xc2 >> 1,558.if_khz = 5380,559};560561static int attach_xc3028(u8 addr, struct cx8802_dev *dev)562{563struct dvb_frontend *fe;564struct videobuf_dvb_frontend *fe0 = NULL;565struct xc2028_ctrl ctl;566struct xc2028_config cfg = {567.i2c_adap = &dev->core->i2c_adap,568.i2c_addr = addr,569.ctrl = &ctl,570};571572/* Get the first frontend */573fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);574if (!fe0)575return -EINVAL;576577if (!fe0->dvb.frontend) {578printk(KERN_ERR "%s/2: dvb frontend not attached. "579"Can't attach xc3028\n",580dev->core->name);581return -EINVAL;582}583584/*585* Some xc3028 devices may be hidden by an I2C gate. This is known586* to happen with some s5h1409-based devices.587* Now that I2C gate is open, sets up xc3028 configuration588*/589cx88_setup_xc3028(dev->core, &ctl);590591fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);592if (!fe) {593printk(KERN_ERR "%s/2: xc3028 attach failed\n",594dev->core->name);595dvb_frontend_detach(fe0->dvb.frontend);596dvb_unregister_frontend(fe0->dvb.frontend);597fe0->dvb.frontend = NULL;598return -EINVAL;599}600601printk(KERN_INFO "%s/2: xc3028 attached\n",602dev->core->name);603604return 0;605}606607static int cx24116_set_ts_param(struct dvb_frontend *fe,608int is_punctured)609{610struct cx8802_dev *dev = fe->dvb->priv;611dev->ts_gen_cntrl = 0x2;612613return 0;614}615616static int stv0900_set_ts_param(struct dvb_frontend *fe,617int is_punctured)618{619struct cx8802_dev *dev = fe->dvb->priv;620dev->ts_gen_cntrl = 0;621622return 0;623}624625static int cx24116_reset_device(struct dvb_frontend *fe)626{627struct cx8802_dev *dev = fe->dvb->priv;628struct cx88_core *core = dev->core;629630/* Reset the part */631/* Put the cx24116 into reset */632cx_write(MO_SRST_IO, 0);633msleep(10);634/* Take the cx24116 out of reset */635cx_write(MO_SRST_IO, 1);636msleep(10);637638return 0;639}640641static const struct cx24116_config hauppauge_hvr4000_config = {642.demod_address = 0x05,643.set_ts_params = cx24116_set_ts_param,644.reset_device = cx24116_reset_device,645};646647static const struct cx24116_config tevii_s460_config = {648.demod_address = 0x55,649.set_ts_params = cx24116_set_ts_param,650.reset_device = cx24116_reset_device,651};652653static int ds3000_set_ts_param(struct dvb_frontend *fe,654int is_punctured)655{656struct cx8802_dev *dev = fe->dvb->priv;657dev->ts_gen_cntrl = 4;658659return 0;660}661662static struct ds3000_config tevii_ds3000_config = {663.demod_address = 0x68,664.set_ts_params = ds3000_set_ts_param,665};666667static const struct stv0900_config prof_7301_stv0900_config = {668.demod_address = 0x6a,669/* demod_mode = 0,*/670.xtal = 27000000,671.clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */672.diseqc_mode = 2,/* 2/3 PWM */673.tun1_maddress = 0,/* 0x60 */674.tun1_adc = 0,/* 2 Vpp */675.path1_mode = 3,676.set_ts_params = stv0900_set_ts_param,677};678679static const struct stb6100_config prof_7301_stb6100_config = {680.tuner_address = 0x60,681.refclock = 27000000,682};683684static const struct stv0299_config tevii_tuner_sharp_config = {685.demod_address = 0x68,686.inittab = sharp_z0194a_inittab,687.mclk = 88000000UL,688.invert = 1,689.skip_reinit = 0,690.lock_output = 1,691.volt13_op0_op1 = STV0299_VOLT13_OP1,692.min_delay_ms = 100,693.set_symbol_rate = sharp_z0194a_set_symbol_rate,694.set_ts_params = cx24116_set_ts_param,695};696697static const struct stv0288_config tevii_tuner_earda_config = {698.demod_address = 0x68,699.min_delay_ms = 100,700.set_ts_params = cx24116_set_ts_param,701};702703static int cx8802_alloc_frontends(struct cx8802_dev *dev)704{705struct cx88_core *core = dev->core;706struct videobuf_dvb_frontend *fe = NULL;707int i;708709mutex_init(&dev->frontends.lock);710INIT_LIST_HEAD(&dev->frontends.felist);711712if (!core->board.num_frontends)713return -ENODEV;714715printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,716core->board.num_frontends);717for (i = 1; i <= core->board.num_frontends; i++) {718fe = videobuf_dvb_alloc_frontend(&dev->frontends, i);719if (!fe) {720printk(KERN_ERR "%s() failed to alloc\n", __func__);721videobuf_dvb_dealloc_frontends(&dev->frontends);722return -ENOMEM;723}724}725return 0;726}727728729730static const u8 samsung_smt_7020_inittab[] = {7310x01, 0x15,7320x02, 0x00,7330x03, 0x00,7340x04, 0x7D,7350x05, 0x0F,7360x06, 0x02,7370x07, 0x00,7380x08, 0x60,7397400x0A, 0xC2,7410x0B, 0x00,7420x0C, 0x01,7430x0D, 0x81,7440x0E, 0x44,7450x0F, 0x09,7460x10, 0x3C,7470x11, 0x84,7480x12, 0xDA,7490x13, 0x99,7500x14, 0x8D,7510x15, 0xCE,7520x16, 0xE8,7530x17, 0x43,7540x18, 0x1C,7550x19, 0x1B,7560x1A, 0x1D,7577580x1C, 0x12,7590x1D, 0x00,7600x1E, 0x00,7610x1F, 0x00,7620x20, 0x00,7630x21, 0x00,7640x22, 0x00,7650x23, 0x00,7667670x28, 0x02,7680x29, 0x28,7690x2A, 0x14,7700x2B, 0x0F,7710x2C, 0x09,7720x2D, 0x05,7737740x31, 0x1F,7750x32, 0x19,7760x33, 0xFC,7770x34, 0x13,7780xff, 0xff,779};780781782static int samsung_smt_7020_tuner_set_params(struct dvb_frontend *fe,783struct dvb_frontend_parameters *params)784{785struct cx8802_dev *dev = fe->dvb->priv;786u8 buf[4];787u32 div;788struct i2c_msg msg = {789.addr = 0x61,790.flags = 0,791.buf = buf,792.len = sizeof(buf) };793794div = params->frequency / 125;795796buf[0] = (div >> 8) & 0x7f;797buf[1] = div & 0xff;798buf[2] = 0x84; /* 0xC4 */799buf[3] = 0x00;800801if (params->frequency < 1500000)802buf[3] |= 0x10;803804if (fe->ops.i2c_gate_ctrl)805fe->ops.i2c_gate_ctrl(fe, 1);806807if (i2c_transfer(&dev->core->i2c_adap, &msg, 1) != 1)808return -EIO;809810return 0;811}812813static int samsung_smt_7020_set_tone(struct dvb_frontend *fe,814fe_sec_tone_mode_t tone)815{816struct cx8802_dev *dev = fe->dvb->priv;817struct cx88_core *core = dev->core;818819cx_set(MO_GP0_IO, 0x0800);820821switch (tone) {822case SEC_TONE_ON:823cx_set(MO_GP0_IO, 0x08);824break;825case SEC_TONE_OFF:826cx_clear(MO_GP0_IO, 0x08);827break;828default:829return -EINVAL;830}831832return 0;833}834835static int samsung_smt_7020_set_voltage(struct dvb_frontend *fe,836fe_sec_voltage_t voltage)837{838struct cx8802_dev *dev = fe->dvb->priv;839struct cx88_core *core = dev->core;840841u8 data;842struct i2c_msg msg = {843.addr = 8,844.flags = 0,845.buf = &data,846.len = sizeof(data) };847848cx_set(MO_GP0_IO, 0x8000);849850switch (voltage) {851case SEC_VOLTAGE_OFF:852break;853case SEC_VOLTAGE_13:854data = ISL6421_EN1 | ISL6421_LLC1;855cx_clear(MO_GP0_IO, 0x80);856break;857case SEC_VOLTAGE_18:858data = ISL6421_EN1 | ISL6421_LLC1 | ISL6421_VSEL1;859cx_clear(MO_GP0_IO, 0x80);860break;861default:862return -EINVAL;863};864865return (i2c_transfer(&dev->core->i2c_adap, &msg, 1) == 1) ? 0 : -EIO;866}867868static int samsung_smt_7020_stv0299_set_symbol_rate(struct dvb_frontend *fe,869u32 srate, u32 ratio)870{871u8 aclk = 0;872u8 bclk = 0;873874if (srate < 1500000) {875aclk = 0xb7;876bclk = 0x47;877} else if (srate < 3000000) {878aclk = 0xb7;879bclk = 0x4b;880} else if (srate < 7000000) {881aclk = 0xb7;882bclk = 0x4f;883} else if (srate < 14000000) {884aclk = 0xb7;885bclk = 0x53;886} else if (srate < 30000000) {887aclk = 0xb6;888bclk = 0x53;889} else if (srate < 45000000) {890aclk = 0xb4;891bclk = 0x51;892}893894stv0299_writereg(fe, 0x13, aclk);895stv0299_writereg(fe, 0x14, bclk);896stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);897stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);898stv0299_writereg(fe, 0x21, ratio & 0xf0);899900return 0;901}902903904static const struct stv0299_config samsung_stv0299_config = {905.demod_address = 0x68,906.inittab = samsung_smt_7020_inittab,907.mclk = 88000000UL,908.invert = 0,909.skip_reinit = 0,910.lock_output = STV0299_LOCKOUTPUT_LK,911.volt13_op0_op1 = STV0299_VOLT13_OP1,912.min_delay_ms = 100,913.set_symbol_rate = samsung_smt_7020_stv0299_set_symbol_rate,914};915916static int dvb_register(struct cx8802_dev *dev)917{918struct cx88_core *core = dev->core;919struct videobuf_dvb_frontend *fe0, *fe1 = NULL;920int mfe_shared = 0; /* bus not shared by default */921922if (0 != core->i2c_rc) {923printk(KERN_ERR "%s/2: no i2c-bus available, cannot attach dvb drivers\n", core->name);924goto frontend_detach;925}926927/* Get the first frontend */928fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);929if (!fe0)930goto frontend_detach;931932/* multi-frontend gate control is undefined or defaults to fe0 */933dev->frontends.gate = 0;934935/* Sets the gate control callback to be used by i2c command calls */936core->gate_ctrl = cx88_dvb_gate_ctrl;937938/* init frontend(s) */939switch (core->boardnr) {940case CX88_BOARD_HAUPPAUGE_DVB_T1:941fe0->dvb.frontend = dvb_attach(cx22702_attach,942&connexant_refboard_config,943&core->i2c_adap);944if (fe0->dvb.frontend != NULL) {945if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,9460x61, &core->i2c_adap,947DVB_PLL_THOMSON_DTT759X))948goto frontend_detach;949}950break;951case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:952case CX88_BOARD_CONEXANT_DVB_T1:953case CX88_BOARD_KWORLD_DVB_T_CX22702:954case CX88_BOARD_WINFAST_DTV1000:955fe0->dvb.frontend = dvb_attach(cx22702_attach,956&connexant_refboard_config,957&core->i2c_adap);958if (fe0->dvb.frontend != NULL) {959if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,9600x60, &core->i2c_adap,961DVB_PLL_THOMSON_DTT7579))962goto frontend_detach;963}964break;965case CX88_BOARD_WINFAST_DTV2000H:966case CX88_BOARD_WINFAST_DTV2000H_J:967case CX88_BOARD_HAUPPAUGE_HVR1100:968case CX88_BOARD_HAUPPAUGE_HVR1100LP:969case CX88_BOARD_HAUPPAUGE_HVR1300:970fe0->dvb.frontend = dvb_attach(cx22702_attach,971&hauppauge_hvr_config,972&core->i2c_adap);973if (fe0->dvb.frontend != NULL) {974if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,975&core->i2c_adap, 0x61,976TUNER_PHILIPS_FMD1216ME_MK3))977goto frontend_detach;978}979break;980case CX88_BOARD_HAUPPAUGE_HVR3000:981/* MFE frontend 1 */982mfe_shared = 1;983dev->frontends.gate = 2;984/* DVB-S init */985fe0->dvb.frontend = dvb_attach(cx24123_attach,986&hauppauge_novas_config,987&dev->core->i2c_adap);988if (fe0->dvb.frontend) {989if (!dvb_attach(isl6421_attach,990fe0->dvb.frontend,991&dev->core->i2c_adap,9920x08, ISL6421_DCL, 0x00))993goto frontend_detach;994}995/* MFE frontend 2 */996fe1 = videobuf_dvb_get_frontend(&dev->frontends, 2);997if (!fe1)998goto frontend_detach;999/* DVB-T init */1000fe1->dvb.frontend = dvb_attach(cx22702_attach,1001&hauppauge_hvr_config,1002&dev->core->i2c_adap);1003if (fe1->dvb.frontend) {1004fe1->dvb.frontend->id = 1;1005if (!dvb_attach(simple_tuner_attach,1006fe1->dvb.frontend,1007&dev->core->i2c_adap,10080x61, TUNER_PHILIPS_FMD1216ME_MK3))1009goto frontend_detach;1010}1011break;1012case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:1013fe0->dvb.frontend = dvb_attach(mt352_attach,1014&dvico_fusionhdtv,1015&core->i2c_adap);1016if (fe0->dvb.frontend != NULL) {1017if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,10180x60, NULL, DVB_PLL_THOMSON_DTT7579))1019goto frontend_detach;1020break;1021}1022/* ZL10353 replaces MT352 on later cards */1023fe0->dvb.frontend = dvb_attach(zl10353_attach,1024&dvico_fusionhdtv_plus_v1_1,1025&core->i2c_adap);1026if (fe0->dvb.frontend != NULL) {1027if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,10280x60, NULL, DVB_PLL_THOMSON_DTT7579))1029goto frontend_detach;1030}1031break;1032case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:1033/* The tin box says DEE1601, but it seems to be DTT75791034* compatible, with a slightly different MT352 AGC gain. */1035fe0->dvb.frontend = dvb_attach(mt352_attach,1036&dvico_fusionhdtv_dual,1037&core->i2c_adap);1038if (fe0->dvb.frontend != NULL) {1039if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,10400x61, NULL, DVB_PLL_THOMSON_DTT7579))1041goto frontend_detach;1042break;1043}1044/* ZL10353 replaces MT352 on later cards */1045fe0->dvb.frontend = dvb_attach(zl10353_attach,1046&dvico_fusionhdtv_plus_v1_1,1047&core->i2c_adap);1048if (fe0->dvb.frontend != NULL) {1049if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,10500x61, NULL, DVB_PLL_THOMSON_DTT7579))1051goto frontend_detach;1052}1053break;1054case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:1055fe0->dvb.frontend = dvb_attach(mt352_attach,1056&dvico_fusionhdtv,1057&core->i2c_adap);1058if (fe0->dvb.frontend != NULL) {1059if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,10600x61, NULL, DVB_PLL_LG_Z201))1061goto frontend_detach;1062}1063break;1064case CX88_BOARD_KWORLD_DVB_T:1065case CX88_BOARD_DNTV_LIVE_DVB_T:1066case CX88_BOARD_ADSTECH_DVB_T_PCI:1067fe0->dvb.frontend = dvb_attach(mt352_attach,1068&dntv_live_dvbt_config,1069&core->i2c_adap);1070if (fe0->dvb.frontend != NULL) {1071if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,10720x61, NULL, DVB_PLL_UNKNOWN_1))1073goto frontend_detach;1074}1075break;1076case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:1077#if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE))1078/* MT352 is on a secondary I2C bus made from some GPIO lines */1079fe0->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config,1080&dev->vp3054->adap);1081if (fe0->dvb.frontend != NULL) {1082if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,1083&core->i2c_adap, 0x61,1084TUNER_PHILIPS_FMD1216ME_MK3))1085goto frontend_detach;1086}1087#else1088printk(KERN_ERR "%s/2: built without vp3054 support\n",1089core->name);1090#endif1091break;1092case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID:1093fe0->dvb.frontend = dvb_attach(zl10353_attach,1094&dvico_fusionhdtv_hybrid,1095&core->i2c_adap);1096if (fe0->dvb.frontend != NULL) {1097if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,1098&core->i2c_adap, 0x61,1099TUNER_THOMSON_FE6600))1100goto frontend_detach;1101}1102break;1103case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:1104fe0->dvb.frontend = dvb_attach(zl10353_attach,1105&dvico_fusionhdtv_xc3028,1106&core->i2c_adap);1107if (fe0->dvb.frontend == NULL)1108fe0->dvb.frontend = dvb_attach(mt352_attach,1109&dvico_fusionhdtv_mt352_xc3028,1110&core->i2c_adap);1111/*1112* On this board, the demod provides the I2C bus pullup.1113* We must not permit gate_ctrl to be performed, or1114* the xc3028 cannot communicate on the bus.1115*/1116if (fe0->dvb.frontend)1117fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;1118if (attach_xc3028(0x61, dev) < 0)1119goto frontend_detach;1120break;1121case CX88_BOARD_PCHDTV_HD3000:1122fe0->dvb.frontend = dvb_attach(or51132_attach, &pchdtv_hd3000,1123&core->i2c_adap);1124if (fe0->dvb.frontend != NULL) {1125if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,1126&core->i2c_adap, 0x61,1127TUNER_THOMSON_DTT761X))1128goto frontend_detach;1129}1130break;1131case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:1132dev->ts_gen_cntrl = 0x08;11331134/* Do a hardware reset of chip before using it. */1135cx_clear(MO_GP0_IO, 1);1136mdelay(100);1137cx_set(MO_GP0_IO, 1);1138mdelay(200);11391140/* Select RF connector callback */1141fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set;1142fe0->dvb.frontend = dvb_attach(lgdt330x_attach,1143&fusionhdtv_3_gold,1144&core->i2c_adap);1145if (fe0->dvb.frontend != NULL) {1146if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,1147&core->i2c_adap, 0x61,1148TUNER_MICROTUNE_4042FI5))1149goto frontend_detach;1150}1151break;1152case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:1153dev->ts_gen_cntrl = 0x08;11541155/* Do a hardware reset of chip before using it. */1156cx_clear(MO_GP0_IO, 1);1157mdelay(100);1158cx_set(MO_GP0_IO, 9);1159mdelay(200);1160fe0->dvb.frontend = dvb_attach(lgdt330x_attach,1161&fusionhdtv_3_gold,1162&core->i2c_adap);1163if (fe0->dvb.frontend != NULL) {1164if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,1165&core->i2c_adap, 0x61,1166TUNER_THOMSON_DTT761X))1167goto frontend_detach;1168}1169break;1170case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:1171dev->ts_gen_cntrl = 0x08;11721173/* Do a hardware reset of chip before using it. */1174cx_clear(MO_GP0_IO, 1);1175mdelay(100);1176cx_set(MO_GP0_IO, 1);1177mdelay(200);1178fe0->dvb.frontend = dvb_attach(lgdt330x_attach,1179&fusionhdtv_5_gold,1180&core->i2c_adap);1181if (fe0->dvb.frontend != NULL) {1182if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,1183&core->i2c_adap, 0x61,1184TUNER_LG_TDVS_H06XF))1185goto frontend_detach;1186if (!dvb_attach(tda9887_attach, fe0->dvb.frontend,1187&core->i2c_adap, 0x43))1188goto frontend_detach;1189}1190break;1191case CX88_BOARD_PCHDTV_HD5500:1192dev->ts_gen_cntrl = 0x08;11931194/* Do a hardware reset of chip before using it. */1195cx_clear(MO_GP0_IO, 1);1196mdelay(100);1197cx_set(MO_GP0_IO, 1);1198mdelay(200);1199fe0->dvb.frontend = dvb_attach(lgdt330x_attach,1200&pchdtv_hd5500,1201&core->i2c_adap);1202if (fe0->dvb.frontend != NULL) {1203if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,1204&core->i2c_adap, 0x61,1205TUNER_LG_TDVS_H06XF))1206goto frontend_detach;1207if (!dvb_attach(tda9887_attach, fe0->dvb.frontend,1208&core->i2c_adap, 0x43))1209goto frontend_detach;1210}1211break;1212case CX88_BOARD_ATI_HDTVWONDER:1213fe0->dvb.frontend = dvb_attach(nxt200x_attach,1214&ati_hdtvwonder,1215&core->i2c_adap);1216if (fe0->dvb.frontend != NULL) {1217if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,1218&core->i2c_adap, 0x61,1219TUNER_PHILIPS_TUV1236D))1220goto frontend_detach;1221}1222break;1223case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:1224case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:1225fe0->dvb.frontend = dvb_attach(cx24123_attach,1226&hauppauge_novas_config,1227&core->i2c_adap);1228if (fe0->dvb.frontend) {1229if (!dvb_attach(isl6421_attach, fe0->dvb.frontend,1230&core->i2c_adap, 0x08, ISL6421_DCL, 0x00))1231goto frontend_detach;1232}1233break;1234case CX88_BOARD_KWORLD_DVBS_100:1235fe0->dvb.frontend = dvb_attach(cx24123_attach,1236&kworld_dvbs_100_config,1237&core->i2c_adap);1238if (fe0->dvb.frontend) {1239core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;1240fe0->dvb.frontend->ops.set_voltage = kworld_dvbs_100_set_voltage;1241}1242break;1243case CX88_BOARD_GENIATECH_DVBS:1244fe0->dvb.frontend = dvb_attach(cx24123_attach,1245&geniatech_dvbs_config,1246&core->i2c_adap);1247if (fe0->dvb.frontend) {1248core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;1249fe0->dvb.frontend->ops.set_voltage = geniatech_dvbs_set_voltage;1250}1251break;1252case CX88_BOARD_PINNACLE_PCTV_HD_800i:1253fe0->dvb.frontend = dvb_attach(s5h1409_attach,1254&pinnacle_pctv_hd_800i_config,1255&core->i2c_adap);1256if (fe0->dvb.frontend != NULL) {1257if (!dvb_attach(xc5000_attach, fe0->dvb.frontend,1258&core->i2c_adap,1259&pinnacle_pctv_hd_800i_tuner_config))1260goto frontend_detach;1261}1262break;1263case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:1264fe0->dvb.frontend = dvb_attach(s5h1409_attach,1265&dvico_hdtv5_pci_nano_config,1266&core->i2c_adap);1267if (fe0->dvb.frontend != NULL) {1268struct dvb_frontend *fe;1269struct xc2028_config cfg = {1270.i2c_adap = &core->i2c_adap,1271.i2c_addr = 0x61,1272};1273static struct xc2028_ctrl ctl = {1274.fname = XC2028_DEFAULT_FIRMWARE,1275.max_len = 64,1276.scode_table = XC3028_FE_OREN538,1277};12781279fe = dvb_attach(xc2028_attach,1280fe0->dvb.frontend, &cfg);1281if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)1282fe->ops.tuner_ops.set_config(fe, &ctl);1283}1284break;1285case CX88_BOARD_PINNACLE_HYBRID_PCTV:1286case CX88_BOARD_WINFAST_DTV1800H:1287fe0->dvb.frontend = dvb_attach(zl10353_attach,1288&cx88_pinnacle_hybrid_pctv,1289&core->i2c_adap);1290if (fe0->dvb.frontend) {1291fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;1292if (attach_xc3028(0x61, dev) < 0)1293goto frontend_detach;1294}1295break;1296case CX88_BOARD_GENIATECH_X8000_MT:1297dev->ts_gen_cntrl = 0x00;12981299fe0->dvb.frontend = dvb_attach(zl10353_attach,1300&cx88_geniatech_x8000_mt,1301&core->i2c_adap);1302if (attach_xc3028(0x61, dev) < 0)1303goto frontend_detach;1304break;1305case CX88_BOARD_KWORLD_ATSC_120:1306fe0->dvb.frontend = dvb_attach(s5h1409_attach,1307&kworld_atsc_120_config,1308&core->i2c_adap);1309if (attach_xc3028(0x61, dev) < 0)1310goto frontend_detach;1311break;1312case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD:1313fe0->dvb.frontend = dvb_attach(s5h1411_attach,1314&dvico_fusionhdtv7_config,1315&core->i2c_adap);1316if (fe0->dvb.frontend != NULL) {1317if (!dvb_attach(xc5000_attach, fe0->dvb.frontend,1318&core->i2c_adap,1319&dvico_fusionhdtv7_tuner_config))1320goto frontend_detach;1321}1322break;1323case CX88_BOARD_HAUPPAUGE_HVR4000:1324/* MFE frontend 1 */1325mfe_shared = 1;1326dev->frontends.gate = 2;1327/* DVB-S/S2 Init */1328fe0->dvb.frontend = dvb_attach(cx24116_attach,1329&hauppauge_hvr4000_config,1330&dev->core->i2c_adap);1331if (fe0->dvb.frontend) {1332if (!dvb_attach(isl6421_attach,1333fe0->dvb.frontend,1334&dev->core->i2c_adap,13350x08, ISL6421_DCL, 0x00))1336goto frontend_detach;1337}1338/* MFE frontend 2 */1339fe1 = videobuf_dvb_get_frontend(&dev->frontends, 2);1340if (!fe1)1341goto frontend_detach;1342/* DVB-T Init */1343fe1->dvb.frontend = dvb_attach(cx22702_attach,1344&hauppauge_hvr_config,1345&dev->core->i2c_adap);1346if (fe1->dvb.frontend) {1347fe1->dvb.frontend->id = 1;1348if (!dvb_attach(simple_tuner_attach,1349fe1->dvb.frontend,1350&dev->core->i2c_adap,13510x61, TUNER_PHILIPS_FMD1216ME_MK3))1352goto frontend_detach;1353}1354break;1355case CX88_BOARD_HAUPPAUGE_HVR4000LITE:1356fe0->dvb.frontend = dvb_attach(cx24116_attach,1357&hauppauge_hvr4000_config,1358&dev->core->i2c_adap);1359if (fe0->dvb.frontend) {1360if (!dvb_attach(isl6421_attach,1361fe0->dvb.frontend,1362&dev->core->i2c_adap,13630x08, ISL6421_DCL, 0x00))1364goto frontend_detach;1365}1366break;1367case CX88_BOARD_PROF_6200:1368case CX88_BOARD_TBS_8910:1369case CX88_BOARD_TEVII_S420:1370fe0->dvb.frontend = dvb_attach(stv0299_attach,1371&tevii_tuner_sharp_config,1372&core->i2c_adap);1373if (fe0->dvb.frontend != NULL) {1374if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,1375&core->i2c_adap, DVB_PLL_OPERA1))1376goto frontend_detach;1377core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;1378fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;13791380} else {1381fe0->dvb.frontend = dvb_attach(stv0288_attach,1382&tevii_tuner_earda_config,1383&core->i2c_adap);1384if (fe0->dvb.frontend != NULL) {1385if (!dvb_attach(stb6000_attach, fe0->dvb.frontend, 0x61,1386&core->i2c_adap))1387goto frontend_detach;1388core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;1389fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;1390}1391}1392break;1393case CX88_BOARD_TEVII_S460:1394fe0->dvb.frontend = dvb_attach(cx24116_attach,1395&tevii_s460_config,1396&core->i2c_adap);1397if (fe0->dvb.frontend != NULL)1398fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;1399break;1400case CX88_BOARD_TEVII_S464:1401fe0->dvb.frontend = dvb_attach(ds3000_attach,1402&tevii_ds3000_config,1403&core->i2c_adap);1404if (fe0->dvb.frontend != NULL)1405fe0->dvb.frontend->ops.set_voltage =1406tevii_dvbs_set_voltage;1407break;1408case CX88_BOARD_OMICOM_SS4_PCI:1409case CX88_BOARD_TBS_8920:1410case CX88_BOARD_PROF_7300:1411case CX88_BOARD_SATTRADE_ST4200:1412fe0->dvb.frontend = dvb_attach(cx24116_attach,1413&hauppauge_hvr4000_config,1414&core->i2c_adap);1415if (fe0->dvb.frontend != NULL)1416fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;1417break;1418case CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII:1419fe0->dvb.frontend = dvb_attach(zl10353_attach,1420&cx88_terratec_cinergy_ht_pci_mkii_config,1421&core->i2c_adap);1422if (fe0->dvb.frontend) {1423fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;1424if (attach_xc3028(0x61, dev) < 0)1425goto frontend_detach;1426}1427break;1428case CX88_BOARD_PROF_7301:{1429struct dvb_tuner_ops *tuner_ops = NULL;14301431fe0->dvb.frontend = dvb_attach(stv0900_attach,1432&prof_7301_stv0900_config,1433&core->i2c_adap, 0);1434if (fe0->dvb.frontend != NULL) {1435if (!dvb_attach(stb6100_attach, fe0->dvb.frontend,1436&prof_7301_stb6100_config,1437&core->i2c_adap))1438goto frontend_detach;14391440tuner_ops = &fe0->dvb.frontend->ops.tuner_ops;1441tuner_ops->set_frequency = stb6100_set_freq;1442tuner_ops->get_frequency = stb6100_get_freq;1443tuner_ops->set_bandwidth = stb6100_set_bandw;1444tuner_ops->get_bandwidth = stb6100_get_bandw;14451446core->prev_set_voltage =1447fe0->dvb.frontend->ops.set_voltage;1448fe0->dvb.frontend->ops.set_voltage =1449tevii_dvbs_set_voltage;1450}1451break;1452}1453case CX88_BOARD_SAMSUNG_SMT_7020:1454dev->ts_gen_cntrl = 0x08;14551456cx_set(MO_GP0_IO, 0x0101);14571458cx_clear(MO_GP0_IO, 0x01);1459mdelay(100);1460cx_set(MO_GP0_IO, 0x01);1461mdelay(200);14621463fe0->dvb.frontend = dvb_attach(stv0299_attach,1464&samsung_stv0299_config,1465&dev->core->i2c_adap);1466if (fe0->dvb.frontend) {1467fe0->dvb.frontend->ops.tuner_ops.set_params =1468samsung_smt_7020_tuner_set_params;1469fe0->dvb.frontend->tuner_priv =1470&dev->core->i2c_adap;1471fe0->dvb.frontend->ops.set_voltage =1472samsung_smt_7020_set_voltage;1473fe0->dvb.frontend->ops.set_tone =1474samsung_smt_7020_set_tone;1475}14761477break;1478case CX88_BOARD_TWINHAN_VP1027_DVBS:1479dev->ts_gen_cntrl = 0x00;1480fe0->dvb.frontend = dvb_attach(mb86a16_attach,1481&twinhan_vp1027,1482&core->i2c_adap);1483if (fe0->dvb.frontend) {1484core->prev_set_voltage =1485fe0->dvb.frontend->ops.set_voltage;1486fe0->dvb.frontend->ops.set_voltage =1487vp1027_set_voltage;1488}1489break;14901491default:1492printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",1493core->name);1494break;1495}14961497if ( (NULL == fe0->dvb.frontend) || (fe1 && NULL == fe1->dvb.frontend) ) {1498printk(KERN_ERR1499"%s/2: frontend initialization failed\n",1500core->name);1501goto frontend_detach;1502}1503/* define general-purpose callback pointer */1504fe0->dvb.frontend->callback = cx88_tuner_callback;15051506/* Ensure all frontends negotiate bus access */1507fe0->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;1508if (fe1)1509fe1->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;15101511/* Put the analog decoder in standby to keep it quiet */1512call_all(core, core, s_power, 0);15131514/* register everything */1515return videobuf_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,1516&dev->pci->dev, adapter_nr, mfe_shared, NULL);15171518frontend_detach:1519core->gate_ctrl = NULL;1520videobuf_dvb_dealloc_frontends(&dev->frontends);1521return -EINVAL;1522}15231524/* ----------------------------------------------------------- */15251526/* CX8802 MPEG -> mini driver - We have been given the hardware */1527static int cx8802_dvb_advise_acquire(struct cx8802_driver *drv)1528{1529struct cx88_core *core = drv->core;1530int err = 0;1531dprintk( 1, "%s\n", __func__);15321533switch (core->boardnr) {1534case CX88_BOARD_HAUPPAUGE_HVR1300:1535/* We arrive here with either the cx23416 or the cx227021536* on the bus. Take the bus from the cx23416 and enable the1537* cx22702 demod1538*/1539/* Toggle reset on cx22702 leaving i2c active */1540cx_set(MO_GP0_IO, 0x00000080);1541udelay(1000);1542cx_clear(MO_GP0_IO, 0x00000080);1543udelay(50);1544cx_set(MO_GP0_IO, 0x00000080);1545udelay(1000);1546/* enable the cx22702 pins */1547cx_clear(MO_GP0_IO, 0x00000004);1548udelay(1000);1549break;15501551case CX88_BOARD_HAUPPAUGE_HVR3000:1552case CX88_BOARD_HAUPPAUGE_HVR4000:1553/* Toggle reset on cx22702 leaving i2c active */1554cx_set(MO_GP0_IO, 0x00000080);1555udelay(1000);1556cx_clear(MO_GP0_IO, 0x00000080);1557udelay(50);1558cx_set(MO_GP0_IO, 0x00000080);1559udelay(1000);1560switch (core->dvbdev->frontends.active_fe_id) {1561case 1: /* DVB-S/S2 Enabled */1562/* tri-state the cx22702 pins */1563cx_set(MO_GP0_IO, 0x00000004);1564/* Take the cx24116/cx24123 out of reset */1565cx_write(MO_SRST_IO, 1);1566core->dvbdev->ts_gen_cntrl = 0x02; /* Parallel IO */1567break;1568case 2: /* DVB-T Enabled */1569/* Put the cx24116/cx24123 into reset */1570cx_write(MO_SRST_IO, 0);1571/* enable the cx22702 pins */1572cx_clear(MO_GP0_IO, 0x00000004);1573core->dvbdev->ts_gen_cntrl = 0x0c; /* Serial IO */1574break;1575}1576udelay(1000);1577break;15781579default:1580err = -ENODEV;1581}1582return err;1583}15841585/* CX8802 MPEG -> mini driver - We no longer have the hardware */1586static int cx8802_dvb_advise_release(struct cx8802_driver *drv)1587{1588struct cx88_core *core = drv->core;1589int err = 0;1590dprintk( 1, "%s\n", __func__);15911592switch (core->boardnr) {1593case CX88_BOARD_HAUPPAUGE_HVR1300:1594/* Do Nothing, leave the cx22702 on the bus. */1595break;1596case CX88_BOARD_HAUPPAUGE_HVR3000:1597case CX88_BOARD_HAUPPAUGE_HVR4000:1598break;1599default:1600err = -ENODEV;1601}1602return err;1603}16041605static int cx8802_dvb_probe(struct cx8802_driver *drv)1606{1607struct cx88_core *core = drv->core;1608struct cx8802_dev *dev = drv->core->dvbdev;1609int err;1610struct videobuf_dvb_frontend *fe;1611int i;16121613dprintk( 1, "%s\n", __func__);1614dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",1615core->boardnr,1616core->name,1617core->pci_bus,1618core->pci_slot);16191620err = -ENODEV;1621if (!(core->board.mpeg & CX88_MPEG_DVB))1622goto fail_core;16231624/* If vp3054 isn't enabled, a stub will just return 0 */1625err = vp3054_i2c_probe(dev);1626if (0 != err)1627goto fail_core;16281629/* dvb stuff */1630printk(KERN_INFO "%s/2: cx2388x based DVB/ATSC card\n", core->name);1631dev->ts_gen_cntrl = 0x0c;16321633err = cx8802_alloc_frontends(dev);1634if (err)1635goto fail_core;16361637err = -ENODEV;1638for (i = 1; i <= core->board.num_frontends; i++) {1639fe = videobuf_dvb_get_frontend(&core->dvbdev->frontends, i);1640if (fe == NULL) {1641printk(KERN_ERR "%s() failed to get frontend(%d)\n",1642__func__, i);1643goto fail_probe;1644}1645videobuf_queue_sg_init(&fe->dvb.dvbq, &dvb_qops,1646&dev->pci->dev, &dev->slock,1647V4L2_BUF_TYPE_VIDEO_CAPTURE,1648V4L2_FIELD_TOP,1649sizeof(struct cx88_buffer),1650dev, NULL);1651/* init struct videobuf_dvb */1652fe->dvb.name = dev->core->name;1653}16541655err = dvb_register(dev);1656if (err)1657/* frontends/adapter de-allocated in dvb_register */1658printk(KERN_ERR "%s/2: dvb_register failed (err = %d)\n",1659core->name, err);1660return err;1661fail_probe:1662videobuf_dvb_dealloc_frontends(&core->dvbdev->frontends);1663fail_core:1664return err;1665}16661667static int cx8802_dvb_remove(struct cx8802_driver *drv)1668{1669struct cx88_core *core = drv->core;1670struct cx8802_dev *dev = drv->core->dvbdev;16711672dprintk( 1, "%s\n", __func__);16731674videobuf_dvb_unregister_bus(&dev->frontends);16751676vp3054_i2c_remove(dev);16771678core->gate_ctrl = NULL;16791680return 0;1681}16821683static struct cx8802_driver cx8802_dvb_driver = {1684.type_id = CX88_MPEG_DVB,1685.hw_access = CX8802_DRVCTL_SHARED,1686.probe = cx8802_dvb_probe,1687.remove = cx8802_dvb_remove,1688.advise_acquire = cx8802_dvb_advise_acquire,1689.advise_release = cx8802_dvb_advise_release,1690};16911692static int __init dvb_init(void)1693{1694printk(KERN_INFO "cx88/2: cx2388x dvb driver version %d.%d.%d loaded\n",1695(CX88_VERSION_CODE >> 16) & 0xff,1696(CX88_VERSION_CODE >> 8) & 0xff,1697CX88_VERSION_CODE & 0xff);1698#ifdef SNAPSHOT1699printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",1700SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);1701#endif1702return cx8802_register_driver(&cx8802_dvb_driver);1703}17041705static void __exit dvb_fini(void)1706{1707cx8802_unregister_driver(&cx8802_dvb_driver);1708}17091710module_init(dvb_init);1711module_exit(dvb_fini);17121713/*1714* Local variables:1715* c-basic-offset: 81716* compile-command: "make DVB=1"1717* End:1718*/171917201721