diff options
author | Florian Schirmer <devnull@localhost> | 2003-01-28 21:46:44 +0000 |
---|---|---|
committer | Florian Schirmer <devnull@localhost> | 2003-01-28 21:46:44 +0000 |
commit | ee79ec2d099201f693a5fac14995c064e3a97712 (patch) | |
tree | 29362d57b092694d0aca5efdf2b08141305bb627 /linux/drivers/media/dvb/frontends/nxt6000.c | |
parent | b2ef05a28fa6389d764f88fdd64ad2f6c2952d79 (diff) | |
download | mediapointer-dvb-s2-ee79ec2d099201f693a5fac14995c064e3a97712.tar.gz mediapointer-dvb-s2-ee79ec2d099201f693a5fac14995c064e3a97712.tar.bz2 |
- More autodetect code
- Support BW 6 and 7 MHz modes
- Bugfixes
Diffstat (limited to 'linux/drivers/media/dvb/frontends/nxt6000.c')
-rw-r--r-- | linux/drivers/media/dvb/frontends/nxt6000.c | 359 |
1 files changed, 229 insertions, 130 deletions
diff --git a/linux/drivers/media/dvb/frontends/nxt6000.c b/linux/drivers/media/dvb/frontends/nxt6000.c index 5822f262d..c6b46a943 100644 --- a/linux/drivers/media/dvb/frontends/nxt6000.c +++ b/linux/drivers/media/dvb/frontends/nxt6000.c @@ -44,7 +44,7 @@ static struct dvb_frontend_info nxt6000_info = { .name = "NxtWave NXT6000", .type = FE_OFDM, - .frequency_min = 48250000, + .frequency_min = 0, .frequency_max = 863250000, .frequency_stepsize = 62500, /*.frequency_tolerance = */ /* FIXME: 12% of SR */ @@ -57,53 +57,87 @@ static struct dvb_frontend_info nxt6000_info = { FE_CAN_FEC_7_8 | FE_CAN_FEC_8_9 | FE_CAN_FEC_AUTO | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | -// FE_CAN_BANDWIDTH_AUTO | FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_HIERARCHY_AUTO, }; -static int nxt6000_writereg(struct dvb_i2c_bus *i2c, u8 reg, u8 data) +#pragma pack(1) + +struct nxt6000_config { + + u8 demod_addr; + u8 tuner_addr; + u8 tuner_type; + u8 reserved; + +}; + +#pragma pack() + +#define FE2NXT(fe) ((struct nxt6000_config *)&(fe->data)) +#define FREQ2DIV(freq) ((freq + 36166667) / 166667) + + +static int nxt6000_write(struct dvb_i2c_bus *i2c, u8 addr, u8 reg, u8 data) { u8 buf[] = {reg, data}; - struct i2c_msg msg = {addr: 0x18 >> 1, flags: 0, buf: buf, len: 2}; + struct i2c_msg msg = {addr: addr >> 1, flags: 0, buf: buf, len: 2}; int ret; if ((ret = i2c->xfer(i2c, &msg, 1)) != 1) - printk("nxt6000: nxt6000_write error (reg: 0x%02X <- data: 0x%02X)\n", reg, data); + printk("nxt6000: nxt6000_write error (addr: 0x%02X, reg: 0x%02X, data: 0x%02X, ret: %d)\n", addr, reg, data, ret); return (ret != 1) ? -EFAULT : 0; } -static u8 nxt6000_readreg(struct dvb_i2c_bus *i2c, u8 reg) +static u8 nxt6000_writereg(struct dvb_frontend *fe, u8 reg, u8 data) { - int ret; + struct nxt6000_config *nxt = FE2NXT(fe); + + return nxt6000_write(fe->i2c, nxt->demod_addr, reg, data); + +} + +static u8 nxt6000_read(struct dvb_i2c_bus *i2c, u8 addr, u8 reg) +{ + + int ret; u8 b0[] = {reg}; u8 b1[] = {0}; - struct i2c_msg msgs[] = {{addr: 0x18 >> 1, flags: 0, buf: b0, len: 1}, - {addr: 0x18 >> 1, flags: I2C_M_RD, buf: b1, len: 1}}; + struct i2c_msg msgs[] = {{addr: addr >> 1, flags: 0, buf: b0, len: 1}, + {addr: addr >> 1, flags: I2C_M_RD, buf: b1, len: 1}}; ret = i2c->xfer(i2c, msgs, 2); if (ret != 2) - printk("nxt6000: nxt6000_read error (reg: 0x%02X, ret=%d)\n", reg, ret); + printk("nxt6000: nxt6000_read error (addr: 0x%02X, reg: 0x%02X, ret: %d)\n", addr, reg, ret); return b1[0]; } -static int pll_write(struct dvb_i2c_bus *i2c, u8 addr, u8 *buf, u8 len) +static u8 nxt6000_readreg(struct dvb_frontend *fe, u8 reg) { - struct i2c_msg msg = {addr: addr >> 1, flags: 0, buf: buf, len: len}; + struct nxt6000_config *nxt = FE2NXT(fe); + + return nxt6000_read(fe->i2c, nxt->demod_addr, reg); + +} + +static int pll_write(struct dvb_i2c_bus *i2c, u8 demod_addr, u8 tuner_addr, u8 *buf, u8 len) +{ + + struct i2c_msg msg = {addr: tuner_addr >> 1, flags: 0, buf: buf, len: len}; int ret; - nxt6000_writereg(i2c, ENABLE_TUNER_IIC, 0x01); /* open i2c bus switch */ + nxt6000_write(i2c, demod_addr, ENABLE_TUNER_IIC, 0x01); /* open i2c bus switch */ ret = i2c->xfer(i2c, &msg, 1); - nxt6000_writereg(i2c, ENABLE_TUNER_IIC, 0x00); /* close i2c bus switch */ + nxt6000_write(i2c, demod_addr, ENABLE_TUNER_IIC, 0x00); /* close i2c bus switch */ if (ret != 1) printk("nxt6000: pll_write error %d\n", ret); @@ -112,12 +146,11 @@ static int pll_write(struct dvb_i2c_bus *i2c, u8 addr, u8 *buf, u8 len) } -#define FREQ2DIV(freq) ((freq + 36166667) / 166667) - -static int sp5659_set_tv_freq(struct dvb_i2c_bus *i2c, u32 freq) +static int sp5659_set_tv_freq(struct dvb_frontend *fe, u32 freq) { u8 buf[4]; + struct nxt6000_config *nxt = FE2NXT(fe); buf[0] = (FREQ2DIV(freq) >> 8) & 0x7F; buf[1] = FREQ2DIV(freq) & 0xFF; @@ -132,14 +165,15 @@ static int sp5659_set_tv_freq(struct dvb_i2c_bus *i2c, u32 freq) else return -EINVAL; - return pll_write(i2c, 0xC2, buf, 4); + return pll_write(fe->i2c, nxt->demod_addr, nxt->tuner_addr, buf, 4); } -static int alp510_set_tv_freq(struct dvb_i2c_bus *i2c, u32 freq) +static int alp510_set_tv_freq(struct dvb_frontend *fe, u32 freq) { u8 buf[4]; + struct nxt6000_config *nxt = FE2NXT(fe); buf[0] = (FREQ2DIV(freq) >> 8) & 0x7F; buf[1] = FREQ2DIV(freq) & 0xFF; @@ -169,43 +203,82 @@ static int alp510_set_tv_freq(struct dvb_i2c_bus *i2c, u32 freq) return -EINVAL; #endif - return pll_write(i2c, 0xC0, buf, 4); + return pll_write(fe->i2c, nxt->demod_addr, nxt->tuner_addr, buf, 4); } -static void nxt6000_reset(struct dvb_i2c_bus *i2c) +static void nxt6000_reset(struct dvb_frontend *fe) { u8 val; - val = nxt6000_readreg(i2c, OFDM_COR_CTL); + val = nxt6000_readreg(fe, OFDM_COR_CTL); - nxt6000_writereg(i2c, OFDM_COR_CTL, val & ~COREACT); - nxt6000_writereg(i2c, OFDM_COR_CTL, val | COREACT); + nxt6000_writereg(fe, OFDM_COR_CTL, val & ~COREACT); + nxt6000_writereg(fe, OFDM_COR_CTL, val | COREACT); } -static int nxt6000_set_guard_interval(struct dvb_i2c_bus *i2c, fe_guard_interval_t guard_interval) +static int nxt6000_set_bandwidth(struct dvb_frontend *fe, fe_bandwidth_t bandwidth) +{ + + u16 nominal_rate; + int result; + + switch(bandwidth) { + + case BANDWIDTH_6_MHZ: + + nominal_rate = 0x55B7; + + break; + + case BANDWIDTH_7_MHZ: + + nominal_rate = 0x6400; + + break; + + case BANDWIDTH_8_MHZ: + + nominal_rate = 0x7249; + + break; + + default: + + return -EINVAL; + + } + + if ((result = nxt6000_writereg(fe, OFDM_TRL_NOMINALRATE_1, nominal_rate & 0xFF)) < 0) + return result; + + return nxt6000_writereg(fe, OFDM_TRL_NOMINALRATE_2, (nominal_rate >> 8) & 0xFF); + +} + +static int nxt6000_set_guard_interval(struct dvb_frontend *fe, fe_guard_interval_t guard_interval) { switch(guard_interval) { case GUARD_INTERVAL_1_32: - return nxt6000_writereg(i2c, OFDM_COR_MODEGUARD, 0x00 | (nxt6000_readreg(i2c, OFDM_COR_MODEGUARD) & ~0x03)); + return nxt6000_writereg(fe, OFDM_COR_MODEGUARD, 0x00 | (nxt6000_readreg(fe, OFDM_COR_MODEGUARD) & ~0x03)); case GUARD_INTERVAL_1_16: - return nxt6000_writereg(i2c, OFDM_COR_MODEGUARD, 0x01 | (nxt6000_readreg(i2c, OFDM_COR_MODEGUARD) & ~0x03)); + return nxt6000_writereg(fe, OFDM_COR_MODEGUARD, 0x01 | (nxt6000_readreg(fe, OFDM_COR_MODEGUARD) & ~0x03)); case GUARD_INTERVAL_AUTO: case GUARD_INTERVAL_1_8: - return nxt6000_writereg(i2c, OFDM_COR_MODEGUARD, 0x02 | (nxt6000_readreg(i2c, OFDM_COR_MODEGUARD) & ~0x03)); + return nxt6000_writereg(fe, OFDM_COR_MODEGUARD, 0x02 | (nxt6000_readreg(fe, OFDM_COR_MODEGUARD) & ~0x03)); case GUARD_INTERVAL_1_4: - return nxt6000_writereg(i2c, OFDM_COR_MODEGUARD, 0x03 | (nxt6000_readreg(i2c, OFDM_COR_MODEGUARD) & ~0x03)); + return nxt6000_writereg(fe, OFDM_COR_MODEGUARD, 0x03 | (nxt6000_readreg(fe, OFDM_COR_MODEGUARD) & ~0x03)); default: @@ -215,18 +288,18 @@ static int nxt6000_set_guard_interval(struct dvb_i2c_bus *i2c, fe_guard_interval } -static int nxt6000_set_inversion(struct dvb_i2c_bus *i2c, fe_spectral_inversion_t inversion) +static int nxt6000_set_inversion(struct dvb_frontend *fe, fe_spectral_inversion_t inversion) { switch(inversion) { case INVERSION_OFF: - return nxt6000_writereg(i2c, OFDM_ITB_CTL, 0x00); + return nxt6000_writereg(fe, OFDM_ITB_CTL, 0x00); case INVERSION_ON: - return nxt6000_writereg(i2c, OFDM_ITB_CTL, ITBINV); + return nxt6000_writereg(fe, OFDM_ITB_CTL, ITBINV); default: @@ -236,7 +309,7 @@ static int nxt6000_set_inversion(struct dvb_i2c_bus *i2c, fe_spectral_inversion_ } -static int nxt6000_set_transmission_mode(struct dvb_i2c_bus *i2c, fe_transmit_mode_t transmission_mode) +static int nxt6000_set_transmission_mode(struct dvb_frontend *fe, fe_transmit_mode_t transmission_mode) { int result; @@ -245,18 +318,18 @@ static int nxt6000_set_transmission_mode(struct dvb_i2c_bus *i2c, fe_transmit_mo case TRANSMISSION_MODE_2K: - if ((result = nxt6000_writereg(i2c, EN_DMD_RACQ, 0x00 | (nxt6000_readreg(i2c, EN_DMD_RACQ) & ~0x03))) < 0) + if ((result = nxt6000_writereg(fe, EN_DMD_RACQ, 0x00 | (nxt6000_readreg(fe, EN_DMD_RACQ) & ~0x03))) < 0) return result; - return nxt6000_writereg(i2c, OFDM_COR_MODEGUARD, (0x00 << 2) | (nxt6000_readreg(i2c, OFDM_COR_MODEGUARD) & ~0x04)); + return nxt6000_writereg(fe, OFDM_COR_MODEGUARD, (0x00 << 2) | (nxt6000_readreg(fe, OFDM_COR_MODEGUARD) & ~0x04)); case TRANSMISSION_MODE_8K: case TRANSMISSION_MODE_AUTO: - if ((result = nxt6000_writereg(i2c, EN_DMD_RACQ, 0x02 | (nxt6000_readreg(i2c, EN_DMD_RACQ) & ~0x03))) < 0) + if ((result = nxt6000_writereg(fe, EN_DMD_RACQ, 0x02 | (nxt6000_readreg(fe, EN_DMD_RACQ) & ~0x03))) < 0) return result; - return nxt6000_writereg(i2c, OFDM_COR_MODEGUARD, (0x01 << 2) | (nxt6000_readreg(i2c, OFDM_COR_MODEGUARD) & ~0x04)); + return nxt6000_writereg(fe, OFDM_COR_MODEGUARD, (0x01 << 2) | (nxt6000_readreg(fe, OFDM_COR_MODEGUARD) & ~0x04)); default: @@ -266,58 +339,56 @@ static int nxt6000_set_transmission_mode(struct dvb_i2c_bus *i2c, fe_transmit_mo } -static void nxt6000_setup(struct dvb_i2c_bus *i2c) +static void nxt6000_setup(struct dvb_frontend *fe) { - nxt6000_writereg(i2c, RS_COR_SYNC_PARAM, SYNC_PARAM); - nxt6000_writereg(i2c, BER_CTRL, /*(1 << 2) |*/ (1 << 1) | 1); - nxt6000_writereg(i2c, VIT_COR_CTL, (1 << 7) | (1 << 1)); -// VIT_BER_TIMER_? - nxt6000_writereg(i2c, OFDM_COR_CTL, (1 << 5) | (nxt6000_readreg(i2c, OFDM_COR_CTL) & 0x0F)); - nxt6000_writereg(i2c, OFDM_COR_MODEGUARD, FORCEMODE8K | 2); -// OFDM_AGC_CTL tune zap time -// nxt6000_writereg(i2c, OFDM_AGC_CTL, ); - nxt6000_writereg(i2c, OFDM_ITB_FREQ_1, 0x06); - nxt6000_writereg(i2c, OFDM_ITB_FREQ_2, 0x31); - nxt6000_writereg(i2c, OFDM_CAS_CTL, (0x01 << 7) | (0x02 << 3) | 0x02); - nxt6000_writereg(i2c, CAS_FREQ, 0xBB); // CHECK - nxt6000_writereg(i2c, OFDM_SYR_CTL, 1 << 2); - nxt6000_writereg(i2c, OFDM_PPM_CTL_1, PPM256); - nxt6000_writereg(i2c, OFDM_TRL_NOMINALRATE_1, 0x49); // Hardcoded for 8K (fixme) - nxt6000_writereg(i2c, OFDM_TRL_NOMINALRATE_2, 0x72); // Hardcoded for 8K (fixme) - nxt6000_writereg(i2c, ANALOG_CONTROL_0, 1 << 5); - nxt6000_writereg(i2c, EN_DMD_RACQ, (1 << 7) | (3 << 4) | 2); - nxt6000_writereg(i2c, DIAG_CONFIG, TB_SET); -// nxt6000_writereg(i2c, SUB_DIAG_MODE_SEL, 0); - nxt6000_writereg(i2c, SUB_DIAG_MODE_SEL, CLKINVERSION); - nxt6000_writereg(i2c, TS_FORMAT, 0); + nxt6000_writereg(fe, RS_COR_SYNC_PARAM, SYNC_PARAM); + nxt6000_writereg(fe, BER_CTRL, /*(1 << 2) |*/ (0x01 << 1) | 0x01); + nxt6000_writereg(fe, VIT_COR_CTL, VIT_COR_RESYNC); + nxt6000_writereg(fe, OFDM_COR_CTL, (0x01 << 5) | (nxt6000_readreg(fe, OFDM_COR_CTL) & 0x0F)); + nxt6000_writereg(fe, OFDM_COR_MODEGUARD, FORCEMODE8K | 0x02); + nxt6000_writereg(fe, OFDM_AGC_CTL, AGCLAST | INITIAL_AGC_BW); // CHECKME + nxt6000_writereg(fe, OFDM_ITB_FREQ_1, 0x06); + nxt6000_writereg(fe, OFDM_ITB_FREQ_2, 0x31); + nxt6000_writereg(fe, OFDM_CAS_CTL, (0x01 << 7) | (0x02 << 3) | 0x04); + nxt6000_writereg(fe, CAS_FREQ, 0xBB); // CHECKME + nxt6000_writereg(fe, OFDM_SYR_CTL, 1 << 2); + nxt6000_writereg(fe, OFDM_PPM_CTL_1, PPM256); + nxt6000_writereg(fe, OFDM_TRL_NOMINALRATE_1, 0x49); // Hardcoded for 8MHz (fixme) + nxt6000_writereg(fe, OFDM_TRL_NOMINALRATE_2, 0x72); // Hardcoded for 8MHz (fixme) + nxt6000_writereg(fe, ANALOG_CONTROL_0, 1 << 5); + nxt6000_writereg(fe, EN_DMD_RACQ, (1 << 7) | (3 << 4) | 2); + nxt6000_writereg(fe, DIAG_CONFIG, TB_SET); +// nxt6000_writereg(fe, SUB_DIAG_MODE_SEL, 0); + nxt6000_writereg(fe, SUB_DIAG_MODE_SEL, CLKINVERSION); + nxt6000_writereg(fe, TS_FORMAT, 0); } -static void nxt6000_dump_status(struct dvb_i2c_bus *i2c) +static void nxt6000_dump_status(struct dvb_frontend *fe) { u8 val; -// printk("RS_COR_STAT: 0x%02X\n", nxt6000_readreg(i2c, RS_COR_STAT)); -// printk("VIT_SYNC_STATUS: 0x%02X\n", nxt6000_readreg(i2c, VIT_SYNC_STATUS)); -// printk("OFDM_COR_STAT: 0x%02X\n", nxt6000_readreg(i2c, OFDM_COR_STAT)); -// printk("OFDM_SYR_STAT: 0x%02X\n", nxt6000_readreg(i2c, OFDM_SYR_STAT)); -// printk("OFDM_TPS_RCVD_1: 0x%02X\n", nxt6000_readreg(i2c, OFDM_TPS_RCVD_1)); -// printk("OFDM_TPS_RCVD_2: 0x%02X\n", nxt6000_readreg(i2c, OFDM_TPS_RCVD_2)); -// printk("OFDM_TPS_RCVD_3: 0x%02X\n", nxt6000_readreg(i2c, OFDM_TPS_RCVD_3)); -// printk("OFDM_TPS_RCVD_4: 0x%02X\n", nxt6000_readreg(i2c, OFDM_TPS_RCVD_4)); -// printk("OFDM_TPS_RESERVED_1: 0x%02X\n", nxt6000_readreg(i2c, OFDM_TPS_RESERVED_1)); -// printk("OFDM_TPS_RESERVED_2: 0x%02X\n", nxt6000_readreg(i2c, OFDM_TPS_RESERVED_2)); +// printk("RS_COR_STAT: 0x%02X\n", nxt6000_readreg(fe, RS_COR_STAT)); +// printk("VIT_SYNC_STATUS: 0x%02X\n", nxt6000_readreg(fe, VIT_SYNC_STATUS)); +// printk("OFDM_COR_STAT: 0x%02X\n", nxt6000_readreg(fe, OFDM_COR_STAT)); +// printk("OFDM_SYR_STAT: 0x%02X\n", nxt6000_readreg(fe, OFDM_SYR_STAT)); +// printk("OFDM_TPS_RCVD_1: 0x%02X\n", nxt6000_readreg(fe, OFDM_TPS_RCVD_1)); +// printk("OFDM_TPS_RCVD_2: 0x%02X\n", nxt6000_readreg(fe, OFDM_TPS_RCVD_2)); +// printk("OFDM_TPS_RCVD_3: 0x%02X\n", nxt6000_readreg(fe, OFDM_TPS_RCVD_3)); +// printk("OFDM_TPS_RCVD_4: 0x%02X\n", nxt6000_readreg(fe, OFDM_TPS_RCVD_4)); +// printk("OFDM_TPS_RESERVED_1: 0x%02X\n", nxt6000_readreg(fe, OFDM_TPS_RESERVED_1)); +// printk("OFDM_TPS_RESERVED_2: 0x%02X\n", nxt6000_readreg(fe, OFDM_TPS_RESERVED_2)); printk("NXT6000 status:"); - val = nxt6000_readreg(i2c, RS_COR_STAT); + val = nxt6000_readreg(fe, RS_COR_STAT); printk(" DATA DESCR LOCK: %d,", val & 0x01); printk(" DATA SYNC LOCK: %d,", (val >> 1) & 0x01); - val = nxt6000_readreg(i2c, VIT_SYNC_STATUS); + val = nxt6000_readreg(fe, VIT_SYNC_STATUS); printk(" VITERBI LOCK: %d,", (val >> 7) & 0x01); @@ -357,14 +428,14 @@ static void nxt6000_dump_status(struct dvb_i2c_bus *i2c) } - val = nxt6000_readreg(i2c, OFDM_COR_STAT); + val = nxt6000_readreg(fe, OFDM_COR_STAT); printk(" CHCTrack: %d,", (val >> 7) & 0x01); printk(" TPSLock: %d,", (val >> 6) & 0x01); printk(" SYRLock: %d,", (val >> 5) & 0x01); printk(" AGCLock: %d,", (val >> 4) & 0x01); - switch((val >> 4) & 0x07) { + switch(val & 0x0F) { case 0x00: @@ -412,7 +483,7 @@ static void nxt6000_dump_status(struct dvb_i2c_bus *i2c) } - val = nxt6000_readreg(i2c, OFDM_SYR_STAT); + val = nxt6000_readreg(fe, OFDM_SYR_STAT); printk(" SYRLock: %d,", (val >> 4) & 0x01); printk(" SYRMode: %s,", (val >> 2) & 0x01 ? "8K" : "2K"); @@ -445,7 +516,7 @@ static void nxt6000_dump_status(struct dvb_i2c_bus *i2c) } - val = nxt6000_readreg(i2c, OFDM_TPS_RCVD_3); + val = nxt6000_readreg(fe, OFDM_TPS_RCVD_3); switch((val >> 4) & 0x07) { @@ -519,7 +590,7 @@ static void nxt6000_dump_status(struct dvb_i2c_bus *i2c) } - val = nxt6000_readreg(i2c, OFDM_TPS_RCVD_4); + val = nxt6000_readreg(fe, OFDM_TPS_RCVD_4); printk(" TPSMode: %s,", val & 0x01 ? "8K" : "2K"); @@ -552,9 +623,9 @@ static void nxt6000_dump_status(struct dvb_i2c_bus *i2c) } // Strange magic required to gain access to RF_AGC_STATUS - nxt6000_readreg(i2c, RF_AGC_VAL_1); - val = nxt6000_readreg(i2c, RF_AGC_STATUS); - val = nxt6000_readreg(i2c, RF_AGC_STATUS); + nxt6000_readreg(fe, RF_AGC_VAL_1); + val = nxt6000_readreg(fe, RF_AGC_STATUS); + val = nxt6000_readreg(fe, RF_AGC_STATUS); printk(" RF AGC LOCK: %d,", (val >> 4) & 0x01); @@ -579,25 +650,25 @@ static int nxt6000_ioctl(struct dvb_frontend *fe, unsigned int cmd, void *arg) u8 core_status; - nxt6000_dump_status(fe->i2c); + nxt6000_dump_status(fe); *status = 0; - core_status = nxt6000_readreg(fe->i2c, OFDM_COR_STAT); + core_status = nxt6000_readreg(fe, OFDM_COR_STAT); if (core_status & AGCLOCKED) *status |= FE_HAS_SIGNAL; - if (nxt6000_readreg(fe->i2c, OFDM_SYR_STAT) & GI14_SYR_LOCK) + if (nxt6000_readreg(fe, OFDM_SYR_STAT) & GI14_SYR_LOCK) *status |= FE_HAS_CARRIER; - if (nxt6000_readreg(fe->i2c, VIT_SYNC_STATUS) & VITINSYNC) + if (nxt6000_readreg(fe, VIT_SYNC_STATUS) & VITINSYNC) *status |= FE_HAS_VITERBI; - if (nxt6000_readreg(fe->i2c, RS_COR_STAT) & RSCORESTATUS) + if (nxt6000_readreg(fe, RS_COR_STAT) & RSCORESTATUS) *status |= FE_HAS_SYNC; - if (core_status & TPSLOCKED) + if ((core_status & TPSLOCKED) && (*status == (FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))) *status |= FE_HAS_LOCK; return 0; @@ -645,22 +716,51 @@ static int nxt6000_ioctl(struct dvb_frontend *fe, unsigned int cmd, void *arg) case FE_INIT: case FE_RESET: + + nxt6000_reset(fe); + nxt6000_setup(fe); - //nxt6000_setup(fe->i2c); +// alp510_set_tv_freq(fe, 177500000); // OK +// alp510_set_tv_freq(fe, 602000000); // NOK + alp510_set_tv_freq(fe, 650000000); // NOK +// alp510_set_tv_freq(fe, 658000000); // NOK + alp510_set_tv_freq(fe, 778000000); // OK + + nxt6000_set_bandwidth(fe, BANDWIDTH_8_MHZ); + nxt6000_set_guard_interval(fe, GUARD_INTERVAL_1_8); + nxt6000_set_transmission_mode(fe, TRANSMISSION_MODE_8K); +// nxt6000_set_transmission_mode(fe, TRANSMISSION_MODE_2K); + nxt6000_set_inversion(fe, INVERSION_OFF); +// nxt6000_set_inversion(fe, INVERSION_ON); + + nxt6000_reset(fe); + + nxt6000_dump_status(fe); break; - + case FE_SET_FRONTEND: { struct dvb_frontend_parameters *param = (struct dvb_frontend_parameters *)arg; + int result; - alp510_set_tv_freq(fe->i2c, param->frequency); + printk("nxt6000: params: fre=%d inv=%d\n", param->frequency, param->inversion); - nxt6000_set_guard_interval(fe->i2c, param->u.ofdm.guard_interval); - nxt6000_set_transmission_mode(fe->i2c, param->u.ofdm.transmission_mode); - nxt6000_set_inversion(fe->i2c, param->inversion); + if ((result = alp510_set_tv_freq(fe, param->frequency)) < 0) + return result; + + if ((result = nxt6000_set_bandwidth(fe, param->u.ofdm.bandwidth)) < 0) + return result; + if ((result = nxt6000_set_guard_interval(fe, param->u.ofdm.guard_interval)) < 0) + return result; + if ((result = nxt6000_set_transmission_mode(fe, param->u.ofdm.transmission_mode)) < 0) + return result; + if ((result = nxt6000_set_inversion(fe, param->inversion)) < 0) + return result; + + printk("nxt6000: param check ok\n"); - nxt6000_reset(fe->i2c); + nxt6000_reset(fe); break; } @@ -675,58 +775,57 @@ static int nxt6000_ioctl(struct dvb_frontend *fe, unsigned int cmd, void *arg) } +static u8 demod_addr_tbl[] = {0x14, 0x18, 0x24, 0x28}; + static int nxt6000_attach(struct dvb_i2c_bus *i2c) { - u8 core_rev; + u8 addr_nr; + u8 fe_count = 0; + struct nxt6000_config nxt; + u8 tuner_addr; + u8 tuner_type; printk("nxt6000: attach\n"); - if ((core_rev = nxt6000_readreg(i2c, OFDM_MSC_REV)) != NXT6000ASICDEVICE) { - - printk("nxt6000: core revision is wrong (0x%02X != 0x0B)\n", core_rev); - - return -ENODEV; - - } + for (addr_nr = 0; addr_nr < sizeof(demod_addr_tbl); addr_nr++) { - if (pll_write(i2c, 0xC0, NULL, 0) == 0) { + if (nxt6000_read(i2c, demod_addr_tbl[addr_nr], OFDM_MSC_REV) != NXT6000ASICDEVICE) + continue; + + if (pll_write(i2c, demod_addr_tbl[addr_nr], 0xC0, NULL, 0) == 0) { - printk("nxt6000: detected TI ALP510 tuner\n"); + tuner_addr = 0xC0; + tuner_type = 1; + + printk("nxt6000: detected TI ALP510 tuner at 0x%02X\n", tuner_addr); - } else if (pll_write(i2c, 0xC2, NULL, 0) == 0) { + } else if (pll_write(i2c, demod_addr_tbl[addr_nr], 0xC2, NULL, 0) == 0) { + + tuner_addr = 0xC0; + tuner_type = 2; - printk("nxt6000: detected MITEL SP5659 tuner\n"); + printk("nxt6000: detected MITEL SP5659 tuner at 0x%02X\n", tuner_addr); - } else { + } else { + + printk("nxt6000: unable to detect tuner\n"); - printk("nxt6000: unable to detect tuner\n"); + continue; + + } + + nxt.demod_addr = demod_addr_tbl[addr_nr]; + nxt.tuner_addr = tuner_addr; + nxt.tuner_type = tuner_type; + + printk("nxt6000: attached at %d:%d\n", i2c->adapter->num, i2c->id); - return -EINVAL; + dvb_register_frontend(nxt6000_ioctl, i2c, (void *)(*((u32 *)&nxt)), &nxt6000_info); } - - printk("nxt6000: attached at %d:%d\n", i2c->adapter->num, i2c->id); - nxt6000_reset(i2c); - nxt6000_setup(i2c); - -// alp510_set_tv_freq(i2c, 177500000); -// alp510_set_tv_freq(i2c, 602000000); - alp510_set_tv_freq(i2c, 650000000); // NOK -// alp510_set_tv_freq(i2c, 658000000); // OK - alp510_set_tv_freq(i2c, 778000000); // OK - nxt6000_set_guard_interval(i2c, GUARD_INTERVAL_1_8); -// nxt6000_set_transmission_mode(i2c, TRANSMISSION_MODE_8K); - nxt6000_set_transmission_mode(i2c, TRANSMISSION_MODE_2K); - nxt6000_set_inversion(i2c, INVERSION_OFF); -// nxt6000_set_inversion(i2c, INVERSION_ON); - - nxt6000_reset(i2c); - - nxt6000_dump_status(i2c); - - return dvb_register_frontend(nxt6000_ioctl, i2c, NULL, &nxt6000_info); + return (fe_count > 0) ? 0 : -ENODEV; } |