/* Driver for ST STV0299 demodulator Copyright (C) 2001-2002 Convergence Integrated Media GmbH , , Philips SU1278/SH Copyright (C) 2002 by Peter Schildmann LG TDQF-S001F Copyright (C) 2002 Felix Domke & Andreas Oberritter Support for Samsung TBMU24112IMB used on Technisat SkyStar2 rev. 2.6B Copyright (C) 2003 Vadim Catana : Support for Philips SU1278 on Technotrend hardware Copyright (C) 2004 Andrew de Quincey This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #include #include #include #include #include "dvb_frontend.h" #include "stv0299.h" #define I2C_DRIVERID_STV0299 0x77 static unsigned short ignore[] = { I2C_CLIENT_END }; static unsigned short normal_addr[] = { 0x20, 0x68, I2C_CLIENT_END }; static int attach_adapter(struct i2c_adapter *); static int detach_client(struct i2c_client *); static int dvb_command(struct i2c_client *, unsigned int, void *); //static int stv0299_status = 0; /* M=21, K=0, P=0, f_VCO = 4MHz*4*(M+1)/(K+1) = 352 MHz */ static u8 init_tab[] = { 0x01, 0x15, // M: 0x15 DIRCLK: 0 K:0 0x02, 0x30, // P: 0 SERCLK: 0 VCO:ON STDBY:0 0x03, 0x00, 0x04, 0x88, // F22FR, F22= 0x05, 0x0f, // SDAT:0 SCLT:0 I2CT:0 0x06, 0x00, // DAC mode and MSB 0x07, 0x00, // DAC LSB 0x08, 0x40, // DiSEqC 0x09, 0x00, 0x0a, 0x42, 0x0c, 0x51, // QPSK reverse:1 Nyquist:0 OP0 val:1 OP0 con:1 OP1 val:1 OP1 con:1 0x0d, 0x82, 0x0e, 0x23, 0x0f, 0x52, 0x10, 0x3d, // AGC2 0x11, 0x84, 0x12, 0xb5, // Lock detect: -64 Carrier freq detect:on 0x13, 0xb6, // alpha_car b:4 a:0 noise est:256ks derot:on 0x14, 0x93, // beat carc:0 d:0 e:0xf phase detect algo: 1 0x15, 0xc9, // lock detector threshold 0x16, 0x1d, 0x17, 0x0, 0x18, 0x14, 0x19, 0xf2, 0x1a, 0x11, 0x1b, 0x9c, 0x1c, 0x0, 0x1d, 0x0, 0x1e, 0xb, 0x22, 0x00, 0x23, 0x00, 0x24, 0xff, 0x25, 0xff, 0x26, 0xff, 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0 0x29, 0x1e, // 1/2 threshold 0x2a, 0x14, // 2/3 threshold 0x2b, 0x0f, // 3/4 threshold 0x2c, 0x09, // 5/6 threshold 0x2d, 0x05, // 7/8 threshold 0x2e, 0x01, 0x31, 0x1f, // test all FECs 0x32, 0x19, // viterbi and synchro search 0x33, 0xfc, // rs control 0x34, 0x11, // error control 0x0b, 0x00, 0x27, 0x00, 0x2f, 0x00, 0x30, 0x00, 0x35, 0x00, 0x36, 0x00, 0x37, 0x00, 0x38, 0x00, 0x39, 0x00, 0x3a, 0x00, 0x3b, 0x00, 0x3c, 0x00, 0x3d, 0x00, 0x3e, 0x00, 0x3f, 0x00, 0x40, 0x00, 0x41, 0x00, 0x42, 0x00, 0x43, 0x00, 0x44, 0x00, 0x45, 0x00, 0x46, 0x00, 0x47, 0x00, 0x48, 0x00, 0x49, 0x00, 0x4a, 0x00, 0x4b, 0x00, 0x4c, 0x00, 0x4d, 0x00, 0x4e, 0x00, 0x4f, 0x00, 0xff, 0xff }; struct stv0299_state { struct i2c_adapter* i2c; struct dvb_frontend_ops ops; const struct stv0299_config* config; struct dvb_frontend frontend; u8 initialised:1; u32 tuner_frequency; u32 symbol_rate; fe_code_rate_t fec_inner; int errmode; }; #define STATUS_BER 0 #define STATUS_UCBLOCKS 1 static int debug; static int debug_legacy_dish_switch; #define dprintk(args...) \ do { \ if (debug) printk(KERN_INFO "stv0299: " args); \ } while (0) static int stv0299_writeregI (struct stv0299_state* state, u8 reg, u8 data) { int ret; u8 buf [] = { reg, data }; struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 }; ret = i2c_transfer (state->i2c, &msg, 1); if (ret != 1) dprintk("%s: writereg error (reg == 0x%02x, val == 0x%02x, " "ret == %i)\n", __FUNCTION__, reg, data, ret); return (ret != 1) ? -EREMOTEIO : 0; } int stv0299_writereg (struct dvb_frontend* fe, u8 reg, u8 data) { struct stv0299_state* state = fe->demodulator_priv; return stv0299_writeregI(state, reg, data); } static u8 stv0299_readreg (struct stv0299_state* state, u8 reg) { int ret; u8 b0 [] = { reg }; u8 b1 [] = { 0 }; struct i2c_msg msg [] = { { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 }, { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 } }; ret = i2c_transfer (state->i2c, msg, 2); if (ret != 2) dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", __FUNCTION__, reg, ret); return b1[0]; } static int stv0299_readregs (struct stv0299_state* state, u8 reg1, u8 *b, u8 len) { int ret; struct i2c_msg msg [] = { { .addr = state->config->demod_address, .flags = 0, .buf = ®1, .len = 1 }, { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b, .len = len } }; ret = i2c_transfer (state->i2c, msg, 2); if (ret != 2) dprintk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret); return ret == 2 ? 0 : ret; } static int stv0299_pll_set(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters *params) { return stv0299_enable_plli2c(fe); } int stv0299_enable_plli2c (struct dvb_frontend* fe) { struct stv0299_state* state = fe->demodulator_priv; dprintk ("%s()\n", __FUNCTION__); return stv0299_writeregI(state, 0x05, 0xb5); /* enable i2c repeater on stv0299 */ } static int stv0299_set_FEC (struct stv0299_state* state, fe_code_rate_t fec) { dprintk ("%s(): FEC = %d\n", __FUNCTION__, fec); switch (fec) { case FEC_AUTO: { return stv0299_writeregI (state, 0x31, 0x1f); } case FEC_1_2: { return stv0299_writeregI (state, 0x31, 0x01); } case FEC_2_3: { return stv0299_writeregI (state, 0x31, 0x02); } case FEC_3_4: { return stv0299_writeregI (state, 0x31, 0x04); } case FEC_5_6: { return stv0299_writeregI (state, 0x31, 0x08); } case FEC_7_8: { return stv0299_writeregI (state, 0x31, 0x10); } default: { return -EINVAL; } } } static fe_code_rate_t stv0299_get_fec (struct stv0299_state* state) { static fe_code_rate_t fec_tab [] = { FEC_2_3, FEC_3_4, FEC_5_6, FEC_7_8, FEC_1_2 }; u8 index; dprintk ("%s\n", __FUNCTION__); index = stv0299_readreg (state, 0x1b); index &= 0x7; if (index > 4) return FEC_AUTO; return fec_tab [index]; } static int stv0299_wait_diseqc_fifo (struct stv0299_state* state, int timeout) { unsigned long start = jiffies; while (stv0299_readreg(state, 0x0a) & 1) { if (jiffies - start > timeout) { dprintk ("%s: timeout!!\n", __FUNCTION__); return -ETIMEDOUT; } msleep(10); }; return 0; } static int stv0299_wait_diseqc_idle (struct stv0299_state* state, int timeout) { unsigned long start = jiffies; while ((stv0299_readreg(state, 0x0a) & 3) != 2 ) { if (jiffies - start > timeout) { dprintk ("%s: timeout!!\n", __FUNCTION__); return -ETIMEDOUT; } msleep(10); }; return 0; } static int stv0299_set_symbolrate (struct dvb_frontend* fe, u32 srate) { // struct stv0299_state* state = fe->demodulator_priv; // u64 big = srate; u32 ratio; u32 tmp; u8 aclk = 0xb4, bclk = 0x51; dprintk ("%s()\n", __FUNCTION__); // check rate is within limits if ((srate < 1000000) || (srate > 45000000)) return -EINVAL; if (srate < 30000000) { aclk = 0xb6; bclk = 0x53; } if (srate < 14000000) { aclk = 0xb7; bclk = 0x53; } if (srate < 7000000) { aclk = 0xb7; bclk = 0x4f; } if (srate < 3000000) { aclk = 0xb7; bclk = 0x4b; } if (srate < 1500000) { aclk = 0xb7; bclk = 0x47; } tmp = srate << 4; ratio = tmp / 5500000; tmp = (tmp % 5500000) << 8; ratio = (ratio << 8) + tmp / 5500000; tmp = (tmp % 5500000) << 8; ratio = (ratio << 8) + tmp / 5500000; ratio &= 0xfffff0; stv0299_writereg(fe, 0x13, aclk); stv0299_writereg(fe, 0x14, bclk); stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff); stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff); stv0299_writereg(fe, 0x21, (ratio) & 0xff); printk(KERN_INFO "%s(): Symbol rate = %d\n", __FUNCTION__, ratio); /* // calculate value to program big = big << 20; big += (state->config->mclk-1); // round correctly do_div(big, state->config->mclk); ratio = big << 4; return state->config->set_symbol_rate(fe, srate); */ return 0; } static int stv0299_get_symbolrate (struct stv0299_state* state) { u32 Mclk = state->config->mclk / 4096L; u32 srate; s32 offset; u8 sfr[3]; s8 rtf; dprintk ("%s\n", __FUNCTION__); stv0299_readregs (state, 0x1f, sfr, 3); stv0299_readregs (state, 0x1a, &rtf, 1); srate = (sfr[0] << 8) | sfr[1]; srate *= Mclk; srate /= 16; srate += (sfr[2] >> 4) * Mclk / 256; offset = (s32) rtf * (srate / 4096L); offset /= 128; dprintk ("%s : srate = %i\n", __FUNCTION__, srate); dprintk ("%s : ofset = %i\n", __FUNCTION__, offset); srate += offset; srate += 1000; srate /= 2000; srate *= 2000; return srate; } static int stv0299_send_diseqc_msg (struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *m) { struct stv0299_state* state = fe->demodulator_priv; u8 val; int i; dprintk ("%s\n", __FUNCTION__); if (stv0299_wait_diseqc_idle (state, 100) < 0) return -ETIMEDOUT; val = stv0299_readreg (state, 0x08); if (stv0299_writeregI (state, 0x08, (val & ~0x7) | 0x6)) /* DiSEqC mode */ return -EREMOTEIO; for (i=0; imsg_len; i++) { if (stv0299_wait_diseqc_fifo (state, 100) < 0) return -ETIMEDOUT; if (stv0299_writeregI (state, 0x09, m->msg[i])) return -EREMOTEIO; } if (stv0299_wait_diseqc_idle (state, 100) < 0) return -ETIMEDOUT; return 0; } static int stv0299_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) { struct stv0299_state* state = fe->demodulator_priv; u8 val; dprintk ("%s\n", __FUNCTION__); if (stv0299_wait_diseqc_idle (state, 100) < 0) return -ETIMEDOUT; val = stv0299_readreg (state, 0x08); if (stv0299_writeregI (state, 0x08, (val & ~0x7) | 0x2)) /* burst mode */ return -EREMOTEIO; if (stv0299_writeregI (state, 0x09, burst == SEC_MINI_A ? 0x00 : 0xff)) return -EREMOTEIO; if (stv0299_wait_diseqc_idle (state, 100) < 0) return -ETIMEDOUT; if (stv0299_writeregI (state, 0x08, val)) return -EREMOTEIO; return 0; } static int stv0299_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone) { struct stv0299_state* state = fe->demodulator_priv; u8 val; dprintk ("%s()\n", __FUNCTION__); if (stv0299_wait_diseqc_idle (state, 100) < 0) return -ETIMEDOUT; val = stv0299_readreg (state, 0x08); switch (tone) { case SEC_TONE_ON: return stv0299_writeregI (state, 0x08, val | 0x3); case SEC_TONE_OFF: return stv0299_writeregI (state, 0x08, (val & ~0x3) | 0x02); default: return -EINVAL; } } static int stv0299_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage) { struct stv0299_state* state = fe->demodulator_priv; u8 reg0x08; u8 reg0x0c; dprintk("%s: %s\n", __FUNCTION__, voltage == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" : voltage == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" : "??"); reg0x08 = stv0299_readreg (state, 0x08); reg0x0c = stv0299_readreg (state, 0x0c); /** * H/V switching over OP0, OP1 and OP2 are LNB power enable bits */ reg0x0c &= 0x0f; if (voltage == SEC_VOLTAGE_OFF) { stv0299_writeregI (state, 0x0c, 0x00); /* LNB power off! */ return stv0299_writeregI (state, 0x08, 0x00); /* LNB power off! */ } stv0299_writeregI (state, 0x08, (reg0x08 & 0x3f) | (state->config->lock_output << 6)); switch (voltage) { case SEC_VOLTAGE_13: if (state->config->volt13_op0_op1 == STV0299_VOLT13_OP0) reg0x0c |= 0x10; else reg0x0c |= 0x40; return stv0299_writeregI(state, 0x0c, reg0x0c); case SEC_VOLTAGE_18: return stv0299_writeregI(state, 0x0c, reg0x0c | 0x50); default: return -EINVAL; }; } static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long cmd) { struct stv0299_state* state = fe->demodulator_priv; u8 reg0x08; u8 reg0x0c; u8 lv_mask = 0x40; u8 last = 1; int i; struct timeval nexttime; struct timeval tv[10]; reg0x08 = stv0299_readreg (state, 0x08); reg0x0c = stv0299_readreg (state, 0x0c); reg0x0c &= 0x0f; stv0299_writeregI (state, 0x08, (reg0x08 & 0x3f) | (state->config->lock_output << 6)); if (state->config->volt13_op0_op1 == STV0299_VOLT13_OP0) lv_mask = 0x10; cmd = cmd << 1; if (debug_legacy_dish_switch) printk ("%s switch command: 0x%04lx\n",__FUNCTION__, cmd); do_gettimeofday (&nexttime); if (debug_legacy_dish_switch) memcpy (&tv[0], &nexttime, sizeof (struct timeval)); stv0299_writeregI (state, 0x0c, reg0x0c | 0x50); /* set LNB to 18V */ dvb_frontend_sleep_until(&nexttime, 32000); for (i=0; i<9; i++) { if (debug_legacy_dish_switch) do_gettimeofday (&tv[i+1]); if((cmd & 0x01) != last) { /* set voltage to (last ? 13V : 18V) */ stv0299_writeregI (state, 0x0c, reg0x0c | (last ? lv_mask : 0x50)); last = (last) ? 0 : 1; } cmd = cmd >> 1; if (i != 8) dvb_frontend_sleep_until(&nexttime, 8000); } if (debug_legacy_dish_switch) { printk ("%s(%d): switch delay (should be 32k followed by all 8k\n", __FUNCTION__, fe->dvb->num); for (i = 1; i < 10; i++) printk ("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i])); } return 0; } static int stv0299_frontend_init (struct dvb_frontend* fe) { struct stv0299_state* state = fe->demodulator_priv; int i; printk(KERN_INFO "stv0299: init chip\n"); for (i=0; !(state->config->inittab[i] == 0xff && state->config->inittab[i+1] == 0xff); i+=2) stv0299_writeregI(state, state->config->inittab[i], state->config->inittab[i+1]); printk(KERN_INFO "Before pll_init()\n"); if (state->config->pll_init) { stv0299_writeregI(state, 0x05, 0xb5); /* enable i2c repeater on stv0299 */ state->config->pll_init(fe, state->i2c); stv0299_writeregI(state, 0x05, 0x35); /* disable i2c repeater on stv0299 */ } return 0; } static int stv0299_read_status(struct dvb_frontend* fe, fe_status_t* status) { struct stv0299_state* state = fe->demodulator_priv; u8 signal = 0xff - stv0299_readreg (state, 0x18); u8 sync = stv0299_readreg (state, 0x1b); dprintk ("%s : FE_READ_STATUS : VSTATUS: 0x%02x, signal: 0x%02x\n", __FUNCTION__, sync, signal); *status = 0; if (signal > 10) *status |= FE_HAS_SIGNAL; if (sync & 0x80) *status |= FE_HAS_CARRIER; if (sync & 0x10) *status |= FE_HAS_VITERBI; if (sync & 0x08) *status |= FE_HAS_SYNC; if ((sync & 0x98) == 0x98) *status |= FE_HAS_LOCK; return 0; } static int stv0299_read_ber(struct dvb_frontend* fe, u32* ber) { struct stv0299_state* state = fe->demodulator_priv; dprintk ("%s()\n", __FUNCTION__); if (state->errmode != STATUS_BER) return 0; *ber = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e); return 0; } static int stv0299_read_signal_strength(struct dvb_frontend* fe, u16* strength) { struct stv0299_state* state = fe->demodulator_priv; s32 signal = 0xffff - ((stv0299_readreg (state, 0x18) << 8) | stv0299_readreg (state, 0x19)); dprintk ("%s : FE_READ_SIGNAL_STRENGTH : AGC2I: 0x%02x%02x, signal=0x%04x\n", __FUNCTION__, stv0299_readreg (state, 0x18), stv0299_readreg (state, 0x19), (int) signal); signal = signal * 5 / 4; *strength = (signal > 0xffff) ? 0xffff : (signal < 0) ? 0 : signal; return 0; } static int stv0299_read_snr(struct dvb_frontend* fe, u16* snr) { struct stv0299_state* state = fe->demodulator_priv; dprintk ("%s()\n", __FUNCTION__); s32 xsnr = 0xffff - ((stv0299_readreg (state, 0x24) << 8) | stv0299_readreg (state, 0x25)); xsnr = 3 * (xsnr - 0xa100); *snr = (xsnr > 0xffff) ? 0xffff : (xsnr < 0) ? 0 : xsnr; return 0; } static int stv0299_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) { struct stv0299_state* state = fe->demodulator_priv; dprintk ("%s()\n", __FUNCTION__); if (state->errmode != STATUS_UCBLOCKS) *ucblocks = 0; else *ucblocks = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e); return 0; } static int stv0299_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters * p) { struct stv0299_state* state = fe->demodulator_priv; int invval = 0; // u8 ix2140_regs[4]={0,0,0xE5,0}; printk (KERN_INFO "%s : FE_SET_FRONTEND\n", __FUNCTION__); // set the inversion if (p->inversion == INVERSION_OFF) invval = 0; else if (p->inversion == INVERSION_ON) invval = 1; else { printk("stv0299 does not support auto-inversion\n"); return -EINVAL; } if (state->config->invert) invval = (~invval) & 1; stv0299_writeregI(state, 0x0c, (stv0299_readreg(state, 0x0c) & 0xfe) | invval); stv0299_writeregI(state, 0x05, 0xb5); /* enable i2c repeater on stv0299 */ state->config->pll_set(fe, state->i2c, p); stv0299_writeregI(state, 0x05, 0x35); /* disable i2c repeater on stv0299 */ stv0299_set_FEC (state, p->u.qpsk.fec_inner); stv0299_set_symbolrate (fe, p->u.qpsk.symbol_rate); /* * Set frequency ix2410_calculate_pll_lpf_cutoff(p->u.qpsk.symbol_rate, ix2140_regs); ix2410_calculate_divider_byte(freq, ix2140_regs); ix2410_calculate_vco(freq, ix2140_regs); ix2410_set_tuner_reg(client, ix2140_regs); */ stv0299_writeregI(state, 0x22, 0x00); stv0299_writeregI(state, 0x23, 0x00); stv0299_writeregI(state, 0x12, 0xb9); /* readreg (client, 0x23 ); writereg (client, 0x12, 0xb9); * Set frequency */ state->tuner_frequency = p->frequency; state->fec_inner = p->u.qpsk.fec_inner; state->symbol_rate = p->u.qpsk.symbol_rate; return 0; } static int stv0299_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters * p) { struct stv0299_state* state = fe->demodulator_priv; s32 derot_freq; int invval; dprintk ("%s()\n", __FUNCTION__); derot_freq = (s32)(s16) ((stv0299_readreg (state, 0x22) << 8) | stv0299_readreg (state, 0x23)); derot_freq *= (state->config->mclk >> 16); derot_freq += 500; derot_freq /= 1000; p->frequency += derot_freq; invval = stv0299_readreg (state, 0x0c) & 1; if (state->config->invert) invval = (~invval) & 1; p->inversion = invval ? INVERSION_ON : INVERSION_OFF; p->u.qpsk.fec_inner = stv0299_get_fec (state); p->u.qpsk.symbol_rate = stv0299_get_symbolrate (state); return 0; } static int stv0299_sleep(struct dvb_frontend* fe) { struct stv0299_state* state = fe->demodulator_priv; dprintk ("%s()\n", __FUNCTION__); stv0299_writeregI(state, 0x02, 0x80); state->initialised = 0; return 0; } static int stv0299_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings) { struct stv0299_state* state = fe->demodulator_priv; dprintk ("%s()\n", __FUNCTION__); fesettings->min_delay_ms = state->config->min_delay_ms; if (fesettings->parameters.u.qpsk.symbol_rate < 10000000) { fesettings->step_size = fesettings->parameters.u.qpsk.symbol_rate / 32000; fesettings->max_drift = 5000; } else { fesettings->step_size = fesettings->parameters.u.qpsk.symbol_rate / 16000; fesettings->max_drift = fesettings->parameters.u.qpsk.symbol_rate / 2000; } return 0; } static void stv0299_release(struct dvb_frontend* fe) { struct stv0299_state* state = fe->demodulator_priv; dprintk ("%s()\n", __FUNCTION__); kfree(state); } static struct dvb_frontend_ops stv0299_ops; struct dvb_frontend* stv0299_attach(const struct stv0299_config* config, struct i2c_adapter* i2c) { struct stv0299_state* state = NULL; int id; dprintk ("%s()\n", __FUNCTION__); /* allocate memory for the internal state */ state = kmalloc(sizeof(struct stv0299_state), GFP_KERNEL); if (state == NULL) goto error; /* setup the state */ state->config = config; state->i2c = i2c; memcpy(&state->ops, &stv0299_ops, sizeof(struct dvb_frontend_ops)); state->initialised = 0; state->tuner_frequency = 0; state->symbol_rate = 0; state->fec_inner = 9; state->errmode = STATUS_BER; /* check if the demod is there */ stv0299_writeregI(state, 0x02, 0x34); /* standby off */ msleep(200); id = stv0299_readreg(state, 0x00); /* register 0x00 contains 0xa1 for STV0299 and STV0299B */ /* register 0x00 might contain 0x80 when returning from standby */ if (id != 0xa1 && id != 0x80) goto error; else printk(KERN_INFO "Talking with demod! id = %d\n", id); /* create dvb_frontend */ state->frontend.ops = &state->ops; state->frontend.demodulator_priv = state; return &state->frontend; error: kfree(state); return NULL; } static struct dvb_frontend_ops stv0299_ops = { .info = { .name = "ST STV0299 DVB-S", .type = FE_QPSK, .frequency_min = 950000, .frequency_max = 2150000, .frequency_stepsize = 125, /* kHz for QPSK frontends */ .frequency_tolerance = 0, .symbol_rate_min = 1000000, .symbol_rate_max = 45000000, .symbol_rate_tolerance = 500, /* ppm */ .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_QPSK | FE_CAN_FEC_AUTO }, .release = stv0299_release, .init = stv0299_frontend_init, .sleep = stv0299_sleep, .set_frontend = stv0299_set_frontend, .get_frontend = stv0299_get_frontend, .get_tune_settings = stv0299_get_tune_settings, .read_status = stv0299_read_status, .read_ber = stv0299_read_ber, .read_signal_strength = stv0299_read_signal_strength, .read_snr = stv0299_read_snr, .read_ucblocks = stv0299_read_ucblocks, .diseqc_send_master_cmd = stv0299_send_diseqc_msg, .diseqc_send_burst = stv0299_send_diseqc_burst, .set_tone = stv0299_set_tone, .set_voltage = stv0299_set_voltage, .dishnetwork_send_legacy_command = stv0299_send_legacy_dish_cmd, }; const struct stv0299_config stv_config = { .demod_address = 0x68, .inittab = init_tab, .mclk = 88000000UL, .invert = 0, .skip_reinit = 0, .lock_output = STV0229_LOCKOUTPUT_1, .volt13_op0_op1 = STV0299_VOLT13_OP1, .min_delay_ms = 100, .set_symbol_rate = stv0299_set_symbolrate, .pll_set = stv0299_pll_set, }; static struct i2c_client_address_data addr_data = { .normal_i2c = normal_addr, .probe = ignore, .ignore = ignore }; static struct i2c_driver dvbt_driver = { .id = I2C_DRIVERID_STV0299, .driver = { .name = "stv0299 DVB-S demodulator", .owner = THIS_MODULE }, .attach_adapter = attach_adapter, .detach_client = detach_client, .command = dvb_command, }; static int client_attach(struct i2c_adapter *adap, int addr, int type) { char name[I2C_NAME_SIZE] = "stv0299"; struct i2c_client *new_client = NULL; struct dvb_frontend *frontend = NULL; struct dvb_adapter *dvb_adapter = NULL; printk(KERN_INFO "%s(): addr = %d, type = %d\n", __FUNCTION__, addr, type); // Create and attach the i2c client if ((new_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL)) == NULL) return -ENOMEM; memset(new_client, 0, sizeof(struct i2c_client)); memcpy(new_client->name, "stv0299", sizeof(char) * I2C_NAME_SIZE); new_client->addr = addr; new_client->adapter = adap; new_client->driver = &dvbt_driver; i2c_attach_client(new_client); // Create main struct (struct stv0299_state) and frontend frontend = stv0299_attach(&stv_config, adap); if (frontend == NULL) { printk(KERN_ERR "stv0299: The frontend driver was not found."); return -1; } printk(KERN_INFO "Before dvb_register_adapter()\n"); // Create the DVB adapter if ((dvb_adapter = kmalloc(sizeof(struct dvb_adapter), GFP_KERNEL)) == NULL) return -ENOMEM; frontend->dvb = dvb_adapter; dvb_register_adapter(frontend->dvb, name, THIS_MODULE); stv0299_frontend_init(frontend); printk(KERN_INFO "Before dvb_register_frontend()\n"); if (dvb_register_frontend(frontend->dvb, frontend)) { kfree(new_client); return -ENOMEM; } printk(KERN_INFO "Leaving client_attach()\n"); return 0; } static int attach_adapter(struct i2c_adapter *adap) { return i2c_probe(adap, &addr_data, client_attach); } static int detach_client(struct i2c_client *client) { printk(KERN_INFO "%s(): Detaching client\n", __FUNCTION__); i2c_detach_client(client); kfree(i2c_get_clientdata(client)); return 0; } static int dvb_command(struct i2c_client *client, unsigned int cmd, void *arg) { printk(KERN_INFO "Inside %s()\n", __FUNCTION__); switch (cmd) { case FE_READ_STATUS: { break; } case FE_READ_BER: { break; } case FE_READ_SIGNAL_STRENGTH: { break; } case FE_READ_SNR: { break; } case FE_READ_UNCORRECTED_BLOCKS: { break; } case FE_GET_INFO: { break; } case FE_SET_FRONTEND: { break; } default: return -1; } return 0; } static int __init stv0299_init(void) { return i2c_add_driver(&dvbt_driver); } static void __exit stv0299_exit(void) { i2c_del_driver(&dvbt_driver); } module_init(stv0299_init); module_exit(stv0299_exit); module_param(debug_legacy_dish_switch, int, 0444); MODULE_PARM_DESC(debug_legacy_dish_switch, "Enable timing analysis for Dish Network legacy switches"); module_param(debug, int, 0644); MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); MODULE_DESCRIPTION("ST STV0299 DVB Demodulator driver"); MODULE_AUTHOR("Ralph Metzler, Holger Waechtler, Peter Schildmann, Felix Domke, " "Andreas Oberritter, Andrew de Quincey, Kenneth Aafløy"); MODULE_LICENSE("GPL"); EXPORT_SYMBOL(stv0299_enable_plli2c); EXPORT_SYMBOL(stv0299_writereg); EXPORT_SYMBOL(stv0299_attach);