Path: blob/master/drivers/media/video/cx23885/cx23885-dvb.c
17728 views
/*1* Driver for the Conexant CX23885 PCIe bridge2*3* Copyright (c) 2006 Steven Toth <[email protected]>4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13*14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program; if not, write to the Free Software18* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.19*/2021#include <linux/module.h>22#include <linux/init.h>23#include <linux/device.h>24#include <linux/fs.h>25#include <linux/kthread.h>26#include <linux/file.h>27#include <linux/suspend.h>2829#include "cx23885.h"30#include <media/v4l2-common.h>3132#include "dvb_ca_en50221.h"33#include "s5h1409.h"34#include "s5h1411.h"35#include "mt2131.h"36#include "tda8290.h"37#include "tda18271.h"38#include "lgdt330x.h"39#include "xc5000.h"40#include "max2165.h"41#include "tda10048.h"42#include "tuner-xc2028.h"43#include "tuner-simple.h"44#include "dib7000p.h"45#include "dibx000_common.h"46#include "zl10353.h"47#include "stv0900.h"48#include "stv0900_reg.h"49#include "stv6110.h"50#include "lnbh24.h"51#include "cx24116.h"52#include "cimax2.h"53#include "lgs8gxx.h"54#include "netup-eeprom.h"55#include "netup-init.h"56#include "lgdt3305.h"57#include "atbm8830.h"58#include "ds3000.h"59#include "cx23885-f300.h"60#include "altera-ci.h"61#include "stv0367.h"6263static unsigned int debug;6465#define dprintk(level, fmt, arg...)\66do { if (debug >= level)\67printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\68} while (0)6970/* ------------------------------------------------------------------ */7172static unsigned int alt_tuner;73module_param(alt_tuner, int, 0644);74MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");7576DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);7778/* ------------------------------------------------------------------ */7980static int dvb_buf_setup(struct videobuf_queue *q,81unsigned int *count, unsigned int *size)82{83struct cx23885_tsport *port = q->priv_data;8485port->ts_packet_size = 188 * 4;86port->ts_packet_count = 32;8788*size = port->ts_packet_size * port->ts_packet_count;89*count = 32;90return 0;91}9293static int dvb_buf_prepare(struct videobuf_queue *q,94struct videobuf_buffer *vb, enum v4l2_field field)95{96struct cx23885_tsport *port = q->priv_data;97return cx23885_buf_prepare(q, port, (struct cx23885_buffer *)vb, field);98}99100static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)101{102struct cx23885_tsport *port = q->priv_data;103cx23885_buf_queue(port, (struct cx23885_buffer *)vb);104}105106static void dvb_buf_release(struct videobuf_queue *q,107struct videobuf_buffer *vb)108{109cx23885_free_buffer(q, (struct cx23885_buffer *)vb);110}111112static void cx23885_dvb_gate_ctrl(struct cx23885_tsport *port, int open)113{114struct videobuf_dvb_frontends *f;115struct videobuf_dvb_frontend *fe;116117f = &port->frontends;118119if (f->gate <= 1) /* undefined or fe0 */120fe = videobuf_dvb_get_frontend(f, 1);121else122fe = videobuf_dvb_get_frontend(f, f->gate);123124if (fe && fe->dvb.frontend && fe->dvb.frontend->ops.i2c_gate_ctrl)125fe->dvb.frontend->ops.i2c_gate_ctrl(fe->dvb.frontend, open);126}127128static struct videobuf_queue_ops dvb_qops = {129.buf_setup = dvb_buf_setup,130.buf_prepare = dvb_buf_prepare,131.buf_queue = dvb_buf_queue,132.buf_release = dvb_buf_release,133};134135static struct s5h1409_config hauppauge_generic_config = {136.demod_address = 0x32 >> 1,137.output_mode = S5H1409_SERIAL_OUTPUT,138.gpio = S5H1409_GPIO_ON,139.qam_if = 44000,140.inversion = S5H1409_INVERSION_OFF,141.status_mode = S5H1409_DEMODLOCKING,142.mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,143};144145static struct tda10048_config hauppauge_hvr1200_config = {146.demod_address = 0x10 >> 1,147.output_mode = TDA10048_SERIAL_OUTPUT,148.fwbulkwritelen = TDA10048_BULKWRITE_200,149.inversion = TDA10048_INVERSION_ON,150.dtv6_if_freq_khz = TDA10048_IF_3300,151.dtv7_if_freq_khz = TDA10048_IF_3800,152.dtv8_if_freq_khz = TDA10048_IF_4300,153.clk_freq_khz = TDA10048_CLK_16000,154};155156static struct tda10048_config hauppauge_hvr1210_config = {157.demod_address = 0x10 >> 1,158.output_mode = TDA10048_SERIAL_OUTPUT,159.fwbulkwritelen = TDA10048_BULKWRITE_200,160.inversion = TDA10048_INVERSION_ON,161.dtv6_if_freq_khz = TDA10048_IF_3300,162.dtv7_if_freq_khz = TDA10048_IF_3500,163.dtv8_if_freq_khz = TDA10048_IF_4000,164.clk_freq_khz = TDA10048_CLK_16000,165};166167static struct s5h1409_config hauppauge_ezqam_config = {168.demod_address = 0x32 >> 1,169.output_mode = S5H1409_SERIAL_OUTPUT,170.gpio = S5H1409_GPIO_OFF,171.qam_if = 4000,172.inversion = S5H1409_INVERSION_ON,173.status_mode = S5H1409_DEMODLOCKING,174.mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,175};176177static struct s5h1409_config hauppauge_hvr1800lp_config = {178.demod_address = 0x32 >> 1,179.output_mode = S5H1409_SERIAL_OUTPUT,180.gpio = S5H1409_GPIO_OFF,181.qam_if = 44000,182.inversion = S5H1409_INVERSION_OFF,183.status_mode = S5H1409_DEMODLOCKING,184.mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,185};186187static struct s5h1409_config hauppauge_hvr1500_config = {188.demod_address = 0x32 >> 1,189.output_mode = S5H1409_SERIAL_OUTPUT,190.gpio = S5H1409_GPIO_OFF,191.inversion = S5H1409_INVERSION_OFF,192.status_mode = S5H1409_DEMODLOCKING,193.mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,194};195196static struct mt2131_config hauppauge_generic_tunerconfig = {1970x61198};199200static struct lgdt330x_config fusionhdtv_5_express = {201.demod_address = 0x0e,202.demod_chip = LGDT3303,203.serial_mpeg = 0x40,204};205206static struct s5h1409_config hauppauge_hvr1500q_config = {207.demod_address = 0x32 >> 1,208.output_mode = S5H1409_SERIAL_OUTPUT,209.gpio = S5H1409_GPIO_ON,210.qam_if = 44000,211.inversion = S5H1409_INVERSION_OFF,212.status_mode = S5H1409_DEMODLOCKING,213.mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,214};215216static struct s5h1409_config dvico_s5h1409_config = {217.demod_address = 0x32 >> 1,218.output_mode = S5H1409_SERIAL_OUTPUT,219.gpio = S5H1409_GPIO_ON,220.qam_if = 44000,221.inversion = S5H1409_INVERSION_OFF,222.status_mode = S5H1409_DEMODLOCKING,223.mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,224};225226static struct s5h1411_config dvico_s5h1411_config = {227.output_mode = S5H1411_SERIAL_OUTPUT,228.gpio = S5H1411_GPIO_ON,229.qam_if = S5H1411_IF_44000,230.vsb_if = S5H1411_IF_44000,231.inversion = S5H1411_INVERSION_OFF,232.status_mode = S5H1411_DEMODLOCKING,233.mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,234};235236static struct s5h1411_config hcw_s5h1411_config = {237.output_mode = S5H1411_SERIAL_OUTPUT,238.gpio = S5H1411_GPIO_OFF,239.vsb_if = S5H1411_IF_44000,240.qam_if = S5H1411_IF_4000,241.inversion = S5H1411_INVERSION_ON,242.status_mode = S5H1411_DEMODLOCKING,243.mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,244};245246static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {247.i2c_address = 0x61,248.if_khz = 5380,249};250251static struct xc5000_config dvico_xc5000_tunerconfig = {252.i2c_address = 0x64,253.if_khz = 5380,254};255256static struct tda829x_config tda829x_no_probe = {257.probe_tuner = TDA829X_DONT_PROBE,258};259260static struct tda18271_std_map hauppauge_tda18271_std_map = {261.atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,262.if_lvl = 6, .rfagc_top = 0x37 },263.qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,264.if_lvl = 6, .rfagc_top = 0x37 },265};266267static struct tda18271_std_map hauppauge_hvr1200_tda18271_std_map = {268.dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,269.if_lvl = 1, .rfagc_top = 0x37, },270.dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5,271.if_lvl = 1, .rfagc_top = 0x37, },272.dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6,273.if_lvl = 1, .rfagc_top = 0x37, },274};275276static struct tda18271_config hauppauge_tda18271_config = {277.std_map = &hauppauge_tda18271_std_map,278.gate = TDA18271_GATE_ANALOG,279.output_opt = TDA18271_OUTPUT_LT_OFF,280};281282static struct tda18271_config hauppauge_hvr1200_tuner_config = {283.std_map = &hauppauge_hvr1200_tda18271_std_map,284.gate = TDA18271_GATE_ANALOG,285.output_opt = TDA18271_OUTPUT_LT_OFF,286};287288static struct tda18271_config hauppauge_hvr1210_tuner_config = {289.gate = TDA18271_GATE_DIGITAL,290.output_opt = TDA18271_OUTPUT_LT_OFF,291};292293static struct tda18271_std_map hauppauge_hvr127x_std_map = {294.atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,295.if_lvl = 1, .rfagc_top = 0x58 },296.qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,297.if_lvl = 1, .rfagc_top = 0x58 },298};299300static struct tda18271_config hauppauge_hvr127x_config = {301.std_map = &hauppauge_hvr127x_std_map,302.output_opt = TDA18271_OUTPUT_LT_OFF,303};304305static struct lgdt3305_config hauppauge_lgdt3305_config = {306.i2c_addr = 0x0e,307.mpeg_mode = LGDT3305_MPEG_SERIAL,308.tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,309.tpvalid_polarity = LGDT3305_TP_VALID_HIGH,310.deny_i2c_rptr = 1,311.spectral_inversion = 1,312.qam_if_khz = 4000,313.vsb_if_khz = 3250,314};315316static struct dibx000_agc_config xc3028_agc_config = {317BAND_VHF | BAND_UHF, /* band_caps */318319/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,320* P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,321* P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,322* P_agc_nb_est=2, P_agc_write=0323*/324(0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |325(3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */326327712, /* inv_gain */32821, /* time_stabiliz */3293300, /* alpha_level */331118, /* thlock */3323330, /* wbd_inv */3342867, /* wbd_ref */3350, /* wbd_sel */3362, /* wbd_alpha */3373380, /* agc1_max */3390, /* agc1_min */34039718, /* agc2_max */3419930, /* agc2_min */3420, /* agc1_pt1 */3430, /* agc1_pt2 */3440, /* agc1_pt3 */3450, /* agc1_slope1 */3460, /* agc1_slope2 */3470, /* agc2_pt1 */348128, /* agc2_pt2 */34929, /* agc2_slope1 */35029, /* agc2_slope2 */35135217, /* alpha_mant */35327, /* alpha_exp */35423, /* beta_mant */35551, /* beta_exp */3563571, /* perform_agc_softsplit */358};359360/* PLL Configuration for COFDM BW_MHz = 8.000000361* With external clock = 30.000000 */362static struct dibx000_bandwidth_config xc3028_bw_config = {36360000, /* internal */36430000, /* sampling */3651, /* pll_cfg: prediv */3668, /* pll_cfg: ratio */3673, /* pll_cfg: range */3681, /* pll_cfg: reset */3690, /* pll_cfg: bypass */3700, /* misc: refdiv */3710, /* misc: bypclk_div */3721, /* misc: IO_CLK_en_core */3731, /* misc: ADClkSrc */3740, /* misc: modulo */375(3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */376(1 << 25) | 5816102, /* ifreq = 5.200000 MHz */37720452225, /* timf */37830000000 /* xtal_hz */379};380381static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {382.output_mpeg2_in_188_bytes = 1,383.hostbus_diversity = 1,384.tuner_is_baseband = 0,385.update_lna = NULL,386387.agc_config_count = 1,388.agc = &xc3028_agc_config,389.bw = &xc3028_bw_config,390391.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,392.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,393.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,394395.pwm_freq_div = 0,396.agc_control = NULL,397.spur_protect = 0,398399.output_mode = OUTMODE_MPEG2_SERIAL,400};401402static struct zl10353_config dvico_fusionhdtv_xc3028 = {403.demod_address = 0x0f,404.if2 = 45600,405.no_tuner = 1,406.disable_i2c_gate_ctrl = 1,407};408409static struct stv0900_reg stv0900_ts_regs[] = {410{ R0900_TSGENERAL, 0x00 },411{ R0900_P1_TSSPEED, 0x40 },412{ R0900_P2_TSSPEED, 0x40 },413{ R0900_P1_TSCFGM, 0xc0 },414{ R0900_P2_TSCFGM, 0xc0 },415{ R0900_P1_TSCFGH, 0xe0 },416{ R0900_P2_TSCFGH, 0xe0 },417{ R0900_P1_TSCFGL, 0x20 },418{ R0900_P2_TSCFGL, 0x20 },419{ 0xffff, 0xff }, /* terminate */420};421422static struct stv0900_config netup_stv0900_config = {423.demod_address = 0x68,424.demod_mode = 1, /* dual */425.xtal = 8000000,426.clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */427.diseqc_mode = 2,/* 2/3 PWM */428.ts_config_regs = stv0900_ts_regs,429.tun1_maddress = 0,/* 0x60 */430.tun2_maddress = 3,/* 0x63 */431.tun1_adc = 1,/* 1 Vpp */432.tun2_adc = 1,/* 1 Vpp */433};434435static struct stv6110_config netup_stv6110_tunerconfig_a = {436.i2c_address = 0x60,437.mclk = 16000000,438.clk_div = 1,439.gain = 8, /* +16 dB - maximum gain */440};441442static struct stv6110_config netup_stv6110_tunerconfig_b = {443.i2c_address = 0x63,444.mclk = 16000000,445.clk_div = 1,446.gain = 8, /* +16 dB - maximum gain */447};448449static struct cx24116_config tbs_cx24116_config = {450.demod_address = 0x55,451};452453static struct ds3000_config tevii_ds3000_config = {454.demod_address = 0x68,455};456457static struct cx24116_config dvbworld_cx24116_config = {458.demod_address = 0x05,459};460461static struct lgs8gxx_config mygica_x8506_lgs8gl5_config = {462.prod = LGS8GXX_PROD_LGS8GL5,463.demod_address = 0x19,464.serial_ts = 0,465.ts_clk_pol = 1,466.ts_clk_gated = 1,467.if_clk_freq = 30400, /* 30.4 MHz */468.if_freq = 5380, /* 5.38 MHz */469.if_neg_center = 1,470.ext_adc = 0,471.adc_signed = 0,472.if_neg_edge = 0,473};474475static struct xc5000_config mygica_x8506_xc5000_config = {476.i2c_address = 0x61,477.if_khz = 5380,478};479480static int cx23885_dvb_set_frontend(struct dvb_frontend *fe,481struct dvb_frontend_parameters *param)482{483struct cx23885_tsport *port = fe->dvb->priv;484struct cx23885_dev *dev = port->dev;485486switch (dev->board) {487case CX23885_BOARD_HAUPPAUGE_HVR1275:488switch (param->u.vsb.modulation) {489case VSB_8:490cx23885_gpio_clear(dev, GPIO_5);491break;492case QAM_64:493case QAM_256:494default:495cx23885_gpio_set(dev, GPIO_5);496break;497}498break;499case CX23885_BOARD_MYGICA_X8506:500case CX23885_BOARD_MAGICPRO_PROHDTVE2:501/* Select Digital TV */502cx23885_gpio_set(dev, GPIO_0);503break;504}505return 0;506}507508static int cx23885_dvb_fe_ioctl_override(struct dvb_frontend *fe,509unsigned int cmd, void *parg,510unsigned int stage)511{512int err = 0;513514switch (stage) {515case DVB_FE_IOCTL_PRE:516517switch (cmd) {518case FE_SET_FRONTEND:519err = cx23885_dvb_set_frontend(fe,520(struct dvb_frontend_parameters *) parg);521break;522}523break;524525case DVB_FE_IOCTL_POST:526/* no post-ioctl handling required */527break;528}529return err;530};531532533static struct lgs8gxx_config magicpro_prohdtve2_lgs8g75_config = {534.prod = LGS8GXX_PROD_LGS8G75,535.demod_address = 0x19,536.serial_ts = 0,537.ts_clk_pol = 1,538.ts_clk_gated = 1,539.if_clk_freq = 30400, /* 30.4 MHz */540.if_freq = 6500, /* 6.50 MHz */541.if_neg_center = 1,542.ext_adc = 0,543.adc_signed = 1,544.adc_vpp = 2, /* 1.6 Vpp */545.if_neg_edge = 1,546};547548static struct xc5000_config magicpro_prohdtve2_xc5000_config = {549.i2c_address = 0x61,550.if_khz = 6500,551};552553static struct atbm8830_config mygica_x8558pro_atbm8830_cfg1 = {554.prod = ATBM8830_PROD_8830,555.demod_address = 0x44,556.serial_ts = 0,557.ts_sampling_edge = 1,558.ts_clk_gated = 0,559.osc_clk_freq = 30400, /* in kHz */560.if_freq = 0, /* zero IF */561.zif_swap_iq = 1,562.agc_min = 0x2E,563.agc_max = 0xFF,564.agc_hold_loop = 0,565};566567static struct max2165_config mygic_x8558pro_max2165_cfg1 = {568.i2c_address = 0x60,569.osc_clk = 20570};571572static struct atbm8830_config mygica_x8558pro_atbm8830_cfg2 = {573.prod = ATBM8830_PROD_8830,574.demod_address = 0x44,575.serial_ts = 1,576.ts_sampling_edge = 1,577.ts_clk_gated = 0,578.osc_clk_freq = 30400, /* in kHz */579.if_freq = 0, /* zero IF */580.zif_swap_iq = 1,581.agc_min = 0x2E,582.agc_max = 0xFF,583.agc_hold_loop = 0,584};585586static struct max2165_config mygic_x8558pro_max2165_cfg2 = {587.i2c_address = 0x60,588.osc_clk = 20589};590static struct stv0367_config netup_stv0367_config[] = {591{592.demod_address = 0x1c,593.xtal = 27000000,594.if_khz = 4500,595.if_iq_mode = 0,596.ts_mode = 1,597.clk_pol = 0,598}, {599.demod_address = 0x1d,600.xtal = 27000000,601.if_khz = 4500,602.if_iq_mode = 0,603.ts_mode = 1,604.clk_pol = 0,605},606};607608static struct xc5000_config netup_xc5000_config[] = {609{610.i2c_address = 0x61,611.if_khz = 4500,612}, {613.i2c_address = 0x64,614.if_khz = 4500,615},616};617618int netup_altera_fpga_rw(void *device, int flag, int data, int read)619{620struct cx23885_dev *dev = (struct cx23885_dev *)device;621unsigned long timeout = jiffies + msecs_to_jiffies(1);622uint32_t mem = 0;623624mem = cx_read(MC417_RWD);625if (read)626cx_set(MC417_OEN, ALT_DATA);627else {628cx_clear(MC417_OEN, ALT_DATA);/* D0-D7 out */629mem &= ~ALT_DATA;630mem |= (data & ALT_DATA);631}632633if (flag)634mem |= ALT_AD_RG;635else636mem &= ~ALT_AD_RG;637638mem &= ~ALT_CS;639if (read)640mem = (mem & ~ALT_RD) | ALT_WR;641else642mem = (mem & ~ALT_WR) | ALT_RD;643644cx_write(MC417_RWD, mem); /* start RW cycle */645646for (;;) {647mem = cx_read(MC417_RWD);648if ((mem & ALT_RDY) == 0)649break;650if (time_after(jiffies, timeout))651break;652udelay(1);653}654655cx_set(MC417_RWD, ALT_RD | ALT_WR | ALT_CS);656if (read)657return mem & ALT_DATA;658659return 0;660};661662static int dvb_register(struct cx23885_tsport *port)663{664struct cx23885_dev *dev = port->dev;665struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL;666struct videobuf_dvb_frontend *fe0, *fe1 = NULL;667int mfe_shared = 0; /* bus not shared by default */668int ret;669670/* Get the first frontend */671fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);672if (!fe0)673return -EINVAL;674675/* init struct videobuf_dvb */676fe0->dvb.name = dev->name;677678/* multi-frontend gate control is undefined or defaults to fe0 */679port->frontends.gate = 0;680681/* Sets the gate control callback to be used by i2c command calls */682port->gate_ctrl = cx23885_dvb_gate_ctrl;683684/* init frontend */685switch (dev->board) {686case CX23885_BOARD_HAUPPAUGE_HVR1250:687i2c_bus = &dev->i2c_bus[0];688fe0->dvb.frontend = dvb_attach(s5h1409_attach,689&hauppauge_generic_config,690&i2c_bus->i2c_adap);691if (fe0->dvb.frontend != NULL) {692dvb_attach(mt2131_attach, fe0->dvb.frontend,693&i2c_bus->i2c_adap,694&hauppauge_generic_tunerconfig, 0);695}696break;697case CX23885_BOARD_HAUPPAUGE_HVR1270:698case CX23885_BOARD_HAUPPAUGE_HVR1275:699i2c_bus = &dev->i2c_bus[0];700fe0->dvb.frontend = dvb_attach(lgdt3305_attach,701&hauppauge_lgdt3305_config,702&i2c_bus->i2c_adap);703if (fe0->dvb.frontend != NULL) {704dvb_attach(tda18271_attach, fe0->dvb.frontend,7050x60, &dev->i2c_bus[1].i2c_adap,706&hauppauge_hvr127x_config);707}708break;709case CX23885_BOARD_HAUPPAUGE_HVR1255:710i2c_bus = &dev->i2c_bus[0];711fe0->dvb.frontend = dvb_attach(s5h1411_attach,712&hcw_s5h1411_config,713&i2c_bus->i2c_adap);714if (fe0->dvb.frontend != NULL) {715dvb_attach(tda18271_attach, fe0->dvb.frontend,7160x60, &dev->i2c_bus[1].i2c_adap,717&hauppauge_tda18271_config);718}719break;720case CX23885_BOARD_HAUPPAUGE_HVR1800:721i2c_bus = &dev->i2c_bus[0];722switch (alt_tuner) {723case 1:724fe0->dvb.frontend =725dvb_attach(s5h1409_attach,726&hauppauge_ezqam_config,727&i2c_bus->i2c_adap);728if (fe0->dvb.frontend != NULL) {729dvb_attach(tda829x_attach, fe0->dvb.frontend,730&dev->i2c_bus[1].i2c_adap, 0x42,731&tda829x_no_probe);732dvb_attach(tda18271_attach, fe0->dvb.frontend,7330x60, &dev->i2c_bus[1].i2c_adap,734&hauppauge_tda18271_config);735}736break;737case 0:738default:739fe0->dvb.frontend =740dvb_attach(s5h1409_attach,741&hauppauge_generic_config,742&i2c_bus->i2c_adap);743if (fe0->dvb.frontend != NULL)744dvb_attach(mt2131_attach, fe0->dvb.frontend,745&i2c_bus->i2c_adap,746&hauppauge_generic_tunerconfig, 0);747break;748}749break;750case CX23885_BOARD_HAUPPAUGE_HVR1800lp:751i2c_bus = &dev->i2c_bus[0];752fe0->dvb.frontend = dvb_attach(s5h1409_attach,753&hauppauge_hvr1800lp_config,754&i2c_bus->i2c_adap);755if (fe0->dvb.frontend != NULL) {756dvb_attach(mt2131_attach, fe0->dvb.frontend,757&i2c_bus->i2c_adap,758&hauppauge_generic_tunerconfig, 0);759}760break;761case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:762i2c_bus = &dev->i2c_bus[0];763fe0->dvb.frontend = dvb_attach(lgdt330x_attach,764&fusionhdtv_5_express,765&i2c_bus->i2c_adap);766if (fe0->dvb.frontend != NULL) {767dvb_attach(simple_tuner_attach, fe0->dvb.frontend,768&i2c_bus->i2c_adap, 0x61,769TUNER_LG_TDVS_H06XF);770}771break;772case CX23885_BOARD_HAUPPAUGE_HVR1500Q:773i2c_bus = &dev->i2c_bus[1];774fe0->dvb.frontend = dvb_attach(s5h1409_attach,775&hauppauge_hvr1500q_config,776&dev->i2c_bus[0].i2c_adap);777if (fe0->dvb.frontend != NULL)778dvb_attach(xc5000_attach, fe0->dvb.frontend,779&i2c_bus->i2c_adap,780&hauppauge_hvr1500q_tunerconfig);781break;782case CX23885_BOARD_HAUPPAUGE_HVR1500:783i2c_bus = &dev->i2c_bus[1];784fe0->dvb.frontend = dvb_attach(s5h1409_attach,785&hauppauge_hvr1500_config,786&dev->i2c_bus[0].i2c_adap);787if (fe0->dvb.frontend != NULL) {788struct dvb_frontend *fe;789struct xc2028_config cfg = {790.i2c_adap = &i2c_bus->i2c_adap,791.i2c_addr = 0x61,792};793static struct xc2028_ctrl ctl = {794.fname = XC2028_DEFAULT_FIRMWARE,795.max_len = 64,796.demod = XC3028_FE_OREN538,797};798799fe = dvb_attach(xc2028_attach,800fe0->dvb.frontend, &cfg);801if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)802fe->ops.tuner_ops.set_config(fe, &ctl);803}804break;805case CX23885_BOARD_HAUPPAUGE_HVR1200:806case CX23885_BOARD_HAUPPAUGE_HVR1700:807i2c_bus = &dev->i2c_bus[0];808fe0->dvb.frontend = dvb_attach(tda10048_attach,809&hauppauge_hvr1200_config,810&i2c_bus->i2c_adap);811if (fe0->dvb.frontend != NULL) {812dvb_attach(tda829x_attach, fe0->dvb.frontend,813&dev->i2c_bus[1].i2c_adap, 0x42,814&tda829x_no_probe);815dvb_attach(tda18271_attach, fe0->dvb.frontend,8160x60, &dev->i2c_bus[1].i2c_adap,817&hauppauge_hvr1200_tuner_config);818}819break;820case CX23885_BOARD_HAUPPAUGE_HVR1210:821i2c_bus = &dev->i2c_bus[0];822fe0->dvb.frontend = dvb_attach(tda10048_attach,823&hauppauge_hvr1210_config,824&i2c_bus->i2c_adap);825if (fe0->dvb.frontend != NULL) {826dvb_attach(tda18271_attach, fe0->dvb.frontend,8270x60, &dev->i2c_bus[1].i2c_adap,828&hauppauge_hvr1210_tuner_config);829}830break;831case CX23885_BOARD_HAUPPAUGE_HVR1400:832i2c_bus = &dev->i2c_bus[0];833fe0->dvb.frontend = dvb_attach(dib7000p_attach,834&i2c_bus->i2c_adap,8350x12, &hauppauge_hvr1400_dib7000_config);836if (fe0->dvb.frontend != NULL) {837struct dvb_frontend *fe;838struct xc2028_config cfg = {839.i2c_adap = &dev->i2c_bus[1].i2c_adap,840.i2c_addr = 0x64,841};842static struct xc2028_ctrl ctl = {843.fname = XC3028L_DEFAULT_FIRMWARE,844.max_len = 64,845.demod = 5000,846/* This is true for all demods with847v36 firmware? */848.type = XC2028_D2633,849};850851fe = dvb_attach(xc2028_attach,852fe0->dvb.frontend, &cfg);853if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)854fe->ops.tuner_ops.set_config(fe, &ctl);855}856break;857case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:858i2c_bus = &dev->i2c_bus[port->nr - 1];859860fe0->dvb.frontend = dvb_attach(s5h1409_attach,861&dvico_s5h1409_config,862&i2c_bus->i2c_adap);863if (fe0->dvb.frontend == NULL)864fe0->dvb.frontend = dvb_attach(s5h1411_attach,865&dvico_s5h1411_config,866&i2c_bus->i2c_adap);867if (fe0->dvb.frontend != NULL)868dvb_attach(xc5000_attach, fe0->dvb.frontend,869&i2c_bus->i2c_adap,870&dvico_xc5000_tunerconfig);871break;872case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {873i2c_bus = &dev->i2c_bus[port->nr - 1];874875fe0->dvb.frontend = dvb_attach(zl10353_attach,876&dvico_fusionhdtv_xc3028,877&i2c_bus->i2c_adap);878if (fe0->dvb.frontend != NULL) {879struct dvb_frontend *fe;880struct xc2028_config cfg = {881.i2c_adap = &i2c_bus->i2c_adap,882.i2c_addr = 0x61,883};884static struct xc2028_ctrl ctl = {885.fname = XC2028_DEFAULT_FIRMWARE,886.max_len = 64,887.demod = XC3028_FE_ZARLINK456,888};889890fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,891&cfg);892if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)893fe->ops.tuner_ops.set_config(fe, &ctl);894}895break;896}897case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:898case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:899case CX23885_BOARD_COMPRO_VIDEOMATE_E800:900i2c_bus = &dev->i2c_bus[0];901902fe0->dvb.frontend = dvb_attach(zl10353_attach,903&dvico_fusionhdtv_xc3028,904&i2c_bus->i2c_adap);905if (fe0->dvb.frontend != NULL) {906struct dvb_frontend *fe;907struct xc2028_config cfg = {908.i2c_adap = &dev->i2c_bus[1].i2c_adap,909.i2c_addr = 0x61,910};911static struct xc2028_ctrl ctl = {912.fname = XC2028_DEFAULT_FIRMWARE,913.max_len = 64,914.demod = XC3028_FE_ZARLINK456,915};916917fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,918&cfg);919if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)920fe->ops.tuner_ops.set_config(fe, &ctl);921}922break;923case CX23885_BOARD_TBS_6920:924i2c_bus = &dev->i2c_bus[1];925926fe0->dvb.frontend = dvb_attach(cx24116_attach,927&tbs_cx24116_config,928&i2c_bus->i2c_adap);929if (fe0->dvb.frontend != NULL)930fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;931932break;933case CX23885_BOARD_TEVII_S470:934i2c_bus = &dev->i2c_bus[1];935936fe0->dvb.frontend = dvb_attach(ds3000_attach,937&tevii_ds3000_config,938&i2c_bus->i2c_adap);939if (fe0->dvb.frontend != NULL)940fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;941942break;943case CX23885_BOARD_DVBWORLD_2005:944i2c_bus = &dev->i2c_bus[1];945946fe0->dvb.frontend = dvb_attach(cx24116_attach,947&dvbworld_cx24116_config,948&i2c_bus->i2c_adap);949break;950case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:951i2c_bus = &dev->i2c_bus[0];952switch (port->nr) {953/* port B */954case 1:955fe0->dvb.frontend = dvb_attach(stv0900_attach,956&netup_stv0900_config,957&i2c_bus->i2c_adap, 0);958if (fe0->dvb.frontend != NULL) {959if (dvb_attach(stv6110_attach,960fe0->dvb.frontend,961&netup_stv6110_tunerconfig_a,962&i2c_bus->i2c_adap)) {963if (!dvb_attach(lnbh24_attach,964fe0->dvb.frontend,965&i2c_bus->i2c_adap,966LNBH24_PCL | LNBH24_TTX,967LNBH24_TEN, 0x09))968printk(KERN_ERR969"No LNBH24 found!\n");970971}972}973break;974/* port C */975case 2:976fe0->dvb.frontend = dvb_attach(stv0900_attach,977&netup_stv0900_config,978&i2c_bus->i2c_adap, 1);979if (fe0->dvb.frontend != NULL) {980if (dvb_attach(stv6110_attach,981fe0->dvb.frontend,982&netup_stv6110_tunerconfig_b,983&i2c_bus->i2c_adap)) {984if (!dvb_attach(lnbh24_attach,985fe0->dvb.frontend,986&i2c_bus->i2c_adap,987LNBH24_PCL | LNBH24_TTX,988LNBH24_TEN, 0x0a))989printk(KERN_ERR990"No LNBH24 found!\n");991992}993}994break;995}996break;997case CX23885_BOARD_MYGICA_X8506:998i2c_bus = &dev->i2c_bus[0];999i2c_bus2 = &dev->i2c_bus[1];1000fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,1001&mygica_x8506_lgs8gl5_config,1002&i2c_bus->i2c_adap);1003if (fe0->dvb.frontend != NULL) {1004dvb_attach(xc5000_attach,1005fe0->dvb.frontend,1006&i2c_bus2->i2c_adap,1007&mygica_x8506_xc5000_config);1008}1009break;1010case CX23885_BOARD_MAGICPRO_PROHDTVE2:1011i2c_bus = &dev->i2c_bus[0];1012i2c_bus2 = &dev->i2c_bus[1];1013fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,1014&magicpro_prohdtve2_lgs8g75_config,1015&i2c_bus->i2c_adap);1016if (fe0->dvb.frontend != NULL) {1017dvb_attach(xc5000_attach,1018fe0->dvb.frontend,1019&i2c_bus2->i2c_adap,1020&magicpro_prohdtve2_xc5000_config);1021}1022break;1023case CX23885_BOARD_HAUPPAUGE_HVR1850:1024case CX23885_BOARD_HAUPPAUGE_HVR1290:1025i2c_bus = &dev->i2c_bus[0];1026fe0->dvb.frontend = dvb_attach(s5h1411_attach,1027&hcw_s5h1411_config,1028&i2c_bus->i2c_adap);1029if (fe0->dvb.frontend != NULL)1030dvb_attach(tda18271_attach, fe0->dvb.frontend,10310x60, &dev->i2c_bus[0].i2c_adap,1032&hauppauge_tda18271_config);1033break;1034case CX23885_BOARD_MYGICA_X8558PRO:1035switch (port->nr) {1036/* port B */1037case 1:1038i2c_bus = &dev->i2c_bus[0];1039fe0->dvb.frontend = dvb_attach(atbm8830_attach,1040&mygica_x8558pro_atbm8830_cfg1,1041&i2c_bus->i2c_adap);1042if (fe0->dvb.frontend != NULL) {1043dvb_attach(max2165_attach,1044fe0->dvb.frontend,1045&i2c_bus->i2c_adap,1046&mygic_x8558pro_max2165_cfg1);1047}1048break;1049/* port C */1050case 2:1051i2c_bus = &dev->i2c_bus[1];1052fe0->dvb.frontend = dvb_attach(atbm8830_attach,1053&mygica_x8558pro_atbm8830_cfg2,1054&i2c_bus->i2c_adap);1055if (fe0->dvb.frontend != NULL) {1056dvb_attach(max2165_attach,1057fe0->dvb.frontend,1058&i2c_bus->i2c_adap,1059&mygic_x8558pro_max2165_cfg2);1060}1061break;1062}1063break;1064case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:1065i2c_bus = &dev->i2c_bus[0];1066mfe_shared = 1;/* MFE */1067port->frontends.gate = 0;/* not clear for me yet */1068/* ports B, C */1069/* MFE frontend 1 DVB-T */1070fe0->dvb.frontend = dvb_attach(stv0367ter_attach,1071&netup_stv0367_config[port->nr - 1],1072&i2c_bus->i2c_adap);1073if (fe0->dvb.frontend != NULL) {1074if (NULL == dvb_attach(xc5000_attach,1075fe0->dvb.frontend,1076&i2c_bus->i2c_adap,1077&netup_xc5000_config[port->nr - 1]))1078goto frontend_detach;1079/* load xc5000 firmware */1080fe0->dvb.frontend->ops.tuner_ops.init(fe0->dvb.frontend);1081}1082/* MFE frontend 2 */1083fe1 = videobuf_dvb_get_frontend(&port->frontends, 2);1084if (fe1 == NULL)1085goto frontend_detach;1086/* DVB-C init */1087fe1->dvb.frontend = dvb_attach(stv0367cab_attach,1088&netup_stv0367_config[port->nr - 1],1089&i2c_bus->i2c_adap);1090if (fe1->dvb.frontend != NULL) {1091fe1->dvb.frontend->id = 1;1092if (NULL == dvb_attach(xc5000_attach,1093fe1->dvb.frontend,1094&i2c_bus->i2c_adap,1095&netup_xc5000_config[port->nr - 1]))1096goto frontend_detach;1097}1098break;1099default:1100printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "1101" isn't supported yet\n",1102dev->name);1103break;1104}11051106if ((NULL == fe0->dvb.frontend) || (fe1 && NULL == fe1->dvb.frontend)) {1107printk(KERN_ERR "%s: frontend initialization failed\n",1108dev->name);1109goto frontend_detach;1110}11111112/* define general-purpose callback pointer */1113fe0->dvb.frontend->callback = cx23885_tuner_callback;1114if (fe1)1115fe1->dvb.frontend->callback = cx23885_tuner_callback;1116#if 01117/* Ensure all frontends negotiate bus access */1118fe0->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;1119if (fe1)1120fe1->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;1121#endif11221123/* Put the analog decoder in standby to keep it quiet */1124call_all(dev, core, s_power, 0);11251126if (fe0->dvb.frontend->ops.analog_ops.standby)1127fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);11281129/* register everything */1130ret = videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port,1131&dev->pci->dev, adapter_nr, mfe_shared,1132cx23885_dvb_fe_ioctl_override);1133if (ret)1134goto frontend_detach;11351136/* init CI & MAC */1137switch (dev->board) {1138case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {1139static struct netup_card_info cinfo;11401141netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);1142memcpy(port->frontends.adapter.proposed_mac,1143cinfo.port[port->nr - 1].mac, 6);1144printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC=%pM\n",1145port->nr, port->frontends.adapter.proposed_mac);11461147netup_ci_init(port);1148break;1149}1150case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: {1151struct altera_ci_config netup_ci_cfg = {1152.dev = dev,/* magic number to identify*/1153.adapter = &port->frontends.adapter,/* for CI */1154.demux = &fe0->dvb.demux,/* for hw pid filter */1155.fpga_rw = netup_altera_fpga_rw,1156};11571158altera_ci_init(&netup_ci_cfg, port->nr);1159break;1160}1161case CX23885_BOARD_TEVII_S470: {1162u8 eeprom[256]; /* 24C02 i2c eeprom */11631164if (port->nr != 1)1165break;11661167/* Read entire EEPROM */1168dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;1169tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom));1170printk(KERN_INFO "TeVii S470 MAC= %pM\n", eeprom + 0xa0);1171memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6);1172break;1173}1174}11751176return ret;11771178frontend_detach:1179port->gate_ctrl = NULL;1180videobuf_dvb_dealloc_frontends(&port->frontends);1181return -EINVAL;1182}11831184int cx23885_dvb_register(struct cx23885_tsport *port)1185{11861187struct videobuf_dvb_frontend *fe0;1188struct cx23885_dev *dev = port->dev;1189int err, i;11901191/* Here we need to allocate the correct number of frontends,1192* as reflected in the cards struct. The reality is that currently1193* no cx23885 boards support this - yet. But, if we don't modify this1194* code then the second frontend would never be allocated (later)1195* and fail with error before the attach in dvb_register().1196* Without these changes we risk an OOPS later. The changes here1197* are for safety, and should provide a good foundation for the1198* future addition of any multi-frontend cx23885 based boards.1199*/1200printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,1201port->num_frontends);12021203for (i = 1; i <= port->num_frontends; i++) {1204if (videobuf_dvb_alloc_frontend(1205&port->frontends, i) == NULL) {1206printk(KERN_ERR "%s() failed to alloc\n", __func__);1207return -ENOMEM;1208}12091210fe0 = videobuf_dvb_get_frontend(&port->frontends, i);1211if (!fe0)1212err = -EINVAL;12131214dprintk(1, "%s\n", __func__);1215dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",1216dev->board,1217dev->name,1218dev->pci_bus,1219dev->pci_slot);12201221err = -ENODEV;12221223/* dvb stuff */1224/* We have to init the queue for each frontend on a port. */1225printk(KERN_INFO "%s: cx23885 based dvb card\n", dev->name);1226videobuf_queue_sg_init(&fe0->dvb.dvbq, &dvb_qops,1227&dev->pci->dev, &port->slock,1228V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,1229sizeof(struct cx23885_buffer), port, NULL);1230}1231err = dvb_register(port);1232if (err != 0)1233printk(KERN_ERR "%s() dvb_register failed err = %d\n",1234__func__, err);12351236return err;1237}12381239int cx23885_dvb_unregister(struct cx23885_tsport *port)1240{1241struct videobuf_dvb_frontend *fe0;12421243/* FIXME: in an error condition where the we have1244* an expected number of frontends (attach problem)1245* then this might not clean up correctly, if 11246* is invalid.1247* This comment only applies to future boards IF they1248* implement MFE support.1249*/1250fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);1251if (fe0->dvb.frontend)1252videobuf_dvb_unregister_bus(&port->frontends);12531254switch (port->dev->board) {1255case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:1256netup_ci_exit(port);1257break;1258case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:1259altera_ci_release(port->dev, port->nr);1260break;1261}12621263port->gate_ctrl = NULL;12641265return 0;1266}1267126812691270