diff options
author | Andreas Oberritter <devnull@localhost> | 2004-06-23 12:30:39 +0000 |
---|---|---|
committer | Andreas Oberritter <devnull@localhost> | 2004-06-23 12:30:39 +0000 |
commit | 0e796b2ee04bd1acbdc5150e7c939cc349aa23d5 (patch) | |
tree | ce1a44f367543bcc2a927295c7543fcf20d650d3 /linux/drivers | |
parent | 0bf6ad26278afdb8ee4b2876c79f1a31936ea158 (diff) | |
download | mediapointer-dvb-s2-0e796b2ee04bd1acbdc5150e7c939cc349aa23d5.tar.gz mediapointer-dvb-s2-0e796b2ee04bd1acbdc5150e7c939cc349aa23d5.tar.bz2 |
merged fixes from cvs.tuxbox.org (1.53->1.56)
Diffstat (limited to 'linux/drivers')
-rw-r--r-- | linux/drivers/media/dvb/frontends/at76c651.c | 282 |
1 files changed, 127 insertions, 155 deletions
diff --git a/linux/drivers/media/dvb/frontends/at76c651.c b/linux/drivers/media/dvb/frontends/at76c651.c index 51c9654e9..237773b8d 100644 --- a/linux/drivers/media/dvb/frontends/at76c651.c +++ b/linux/drivers/media/dvb/frontends/at76c651.c @@ -1,10 +1,10 @@ /* * at76c651.c * - * Atmel DVB-C Frontend Driver (at76c651/dat7021) + * Atmel DVB-C Frontend Driver (at76c651/tua6010xs) * * Copyright (C) 2001 fnbrd <fnbrd@gmx.de> - * & 2002 Andreas Oberritter <obi@linuxtv.org> + * & 2002-2004 Andreas Oberritter <obi@linuxtv.org> * & 2003 Wolfram Joost <dbox2@frokaschwei.de> * * This program is free software; you can redistribute it and/or modify @@ -21,6 +21,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * + * AT76C651 + * http://www.nalanda.nitc.ac.in/industry/datasheets/atmel/acrobat/doc1293.pdf + * http://www.atmel.com/atmel/acrobat/doc1320.pdf + * + * TUA6010XS + * http://www.infineon.com/cgi/ecrm.dll/ecrm/scripts/public_download.jsp?oid=19512 */ #include <linux/init.h> @@ -37,27 +43,15 @@ #include "dvb_i2c.h" #include "dvb_functions.h" -static int debug = 0; +static int debug; #define dprintk if (debug) printk //FIXME: Move to i2c-id.h #define I2C_DRIVERID_DVBFE_AT76C651 I2C_DRIVERID_EXP0 -/* - * DAT7021 - * ------- - * Input Frequency Range (RF): 48.25 MHz to 863.25 MHz - * Band Width: 8 MHz - * Level Input (Range for Digital Signals): -61 dBm to -41 dBm - * Output Frequency (IF): 36 MHz - * - * (see http://www.atmel.com/atmel/acrobat/doc1320.pdf) - */ - static struct dvb_frontend_info at76c651_info = { - - .name = "Atmel AT76C651(B) with DAT7021", + .name = "Atmel AT76C651B with TUA6010XS", .type = FE_QAM, .frequency_min = 48250000, .frequency_max = 863250000, @@ -101,7 +95,8 @@ static int at76c651_writereg(struct i2c_adapter *i2c, u8 reg, u8 data) { int ret; u8 buf[] = { reg, data }; - struct i2c_msg msg = { .addr = 0x1a >> 1, .flags = 0, .buf = buf, .len = 2 }; + struct i2c_msg msg = + { .addr = 0x1a >> 1, .flags = 0, .buf = buf, .len = 2 }; ret = i2c_transfer(i2c, &msg, 1); @@ -118,17 +113,18 @@ static int at76c651_writereg(struct i2c_adapter *i2c, u8 reg, u8 data) static u8 at76c651_readreg(struct i2c_adapter *i2c, u8 reg) { int ret; - u8 b0[] = { reg }; - u8 b1[] = { 0 }; - struct i2c_msg msg[] = { {.addr = 0x1a >> 1, .flags = 0, .buf = b0, .len = 1}, - {.addr = 0x1a >> 1, .flags = I2C_M_RD, .buf = b1, .len = 1} }; + u8 val; + struct i2c_msg msg[] = { + { .addr = 0x1a >> 1, .flags = 0, .buf = ®, .len = 1 }, + { .addr = 0x1a >> 1, .flags = I2C_M_RD, .buf = &val, .len = 1 } + }; ret = i2c_transfer(i2c, msg, 2); if (ret != 2) dprintk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret); - return b1[0]; + return val; } static int at76c651_reset(struct i2c_adapter *i2c) @@ -136,9 +132,9 @@ static int at76c651_reset(struct i2c_adapter *i2c) return at76c651_writereg(i2c, 0x07, 0x01); } -static int at76c651_disable_interrupts(struct i2c_adapter *i2c) +static void at76c651_disable_interrupts(struct i2c_adapter *i2c) { - return at76c651_writereg(i2c, 0x0b, 0x00); + at76c651_writereg(i2c, 0x0b, 0x00); } static int at76c651_set_auto_config(struct at76c651_state *state) @@ -184,87 +180,74 @@ static int at76c651_set_auto_config(struct at76c651_state *state) return 0; } -static int at76c651_set_bbfreq(struct i2c_adapter *i2c) +static void at76c651_set_bbfreq(struct i2c_adapter *i2c) { at76c651_writereg(i2c, 0x04, 0x3f); at76c651_writereg(i2c, 0x05, 0xee); - return 0; } -static int at76c651_switch_tuner_i2c(struct i2c_adapter *i2c, u8 enable) -{ - if (enable) - return at76c651_writereg(i2c, 0x0c, 0xc2 | 0x01); - else - return at76c651_writereg(i2c, 0x0c, 0xc2); -} - -static int dat7021_write(struct i2c_adapter *i2c, u32 tw) +static int at76c651_pll_write(struct i2c_adapter *i2c, u8 *buf, size_t len) { int ret; struct i2c_msg msg = - { .addr = 0xc2 >> 1, .flags = 0, .buf = (u8 *) & tw, .len = sizeof (tw) }; - -#ifdef __LITTLE_ENDIAN - tw = __cpu_to_be32(tw); -#endif + { .addr = 0xc2 >> 1, .flags = 0, .buf = buf, .len = len }; - at76c651_switch_tuner_i2c(i2c, 1); + at76c651_writereg(i2c, 0x0c, 0xc3); ret = i2c_transfer(i2c, &msg, 1); - at76c651_switch_tuner_i2c(i2c, 0); - - if (ret != 4) - return -EFAULT; + at76c651_writereg(i2c, 0x0c, 0xc2); - at76c651_reset(i2c); + if (ret < 0) + return ret; + else if (ret != 1) + return -EREMOTEIO; return 0; } -static int dat7021_set_tv_freq(struct i2c_adapter *i2c, u32 freq) +static int tua6010_setfreq(struct i2c_adapter *i2c, u32 freq) { - u32 dw; + u32 div; + u8 buf[4]; + u8 vu, p2, p1, p0; - freq /= 1000; - - if ((freq < 48250) || (freq > 863250)) + if ((freq < 50000000) || (freq > 900000000)) return -EINVAL; - /* - * formula: dw=0x17e28e06+(freq-346000UL)/8000UL*0x800000 - * or: dw=0x4E28E06+(freq-42000) / 125 * 0x20000 - */ + div = (freq + 36125000) / 62500; - dw = (freq - 42000) * 4096; - dw = dw / 125; - dw = dw * 32; - - if (freq > 394000) - dw += 0x4E28E85; + if (freq > 400000000) + vu = 1, p2 = 1, p1 = 0, p0 = 1; + else if (freq > 140000000) + vu = 0, p2 = 1, p1 = 1, p0 = 0; else - dw += 0x4E28E06; + vu = 0, p2 = 0, p1 = 1, p0 = 1; + + buf[0] = (div >> 8) & 0x7f; + buf[1] = (div >> 0) & 0xff; + buf[2] = 0x8e; + buf[3] = (vu << 7) | (p2 << 2) | (p1 << 1) | p0; - return dat7021_write(i2c, dw); + return at76c651_pll_write(i2c, buf, 4); } -static int at76c651_set_symbolrate(struct i2c_adapter *i2c, u32 symbolrate) +static int at76c651_set_symbol_rate(struct i2c_adapter *i2c, u32 symbol_rate) { u8 exponent; u32 mantissa; - if (symbolrate > 9360000) + if (symbol_rate > 9360000) return -EINVAL; /* * FREF = 57800 kHz - * exponent = 10 + floor ( log2 ( symbolrate / FREF ) ) - * mantissa = ( symbolrate / FREF) * ( 1 << ( 30 - exponent ) ) + * exponent = 10 + floor (log2(symbol_rate / FREF)) + * mantissa = (symbol_rate / FREF) * (1 << (30 - exponent)) */ - exponent = __ilog2((symbolrate << 4) / 903125); - mantissa = ((symbolrate / 3125) * (1 << (24 - exponent))) / 289; + exponent = __ilog2((symbol_rate << 4) / 903125); + mantissa = ((symbol_rate / 3125) * (1 << (24 - exponent))) / 289; at76c651_writereg(i2c, 0x00, mantissa >> 13); at76c651_writereg(i2c, 0x01, mantissa >> 5); @@ -340,21 +323,25 @@ static int at76c651_set_parameters(struct at76c651_state *state, struct dvb_frontend_parameters *p) { struct i2c_adapter *i2c = state->i2c; + int ret; - dat7021_set_tv_freq(i2c, p->frequency); - at76c651_set_symbolrate(i2c, p->u.qam.symbol_rate); - at76c651_set_inversion(i2c, p->inversion); - at76c651_set_auto_config(state); - at76c651_reset(i2c); - - return 0; + if ((ret = tua6010_setfreq(i2c, p->frequency))) + return ret; + + if ((ret = at76c651_set_symbol_rate(i2c, p->u.qam.symbol_rate))) + return ret; + + if ((ret = at76c651_set_inversion(i2c, p->inversion))) + return ret; + + return at76c651_set_auto_config(state); } static int at76c651_set_defaults(struct at76c651_state *state) { struct i2c_adapter *i2c = state->i2c; - at76c651_set_symbolrate(i2c, 6900000); + at76c651_set_symbol_rate(i2c, 6900000); at76c651_set_qam(state, QAM_64); at76c651_set_bbfreq(i2c); at76c651_set_auto_config(state); @@ -369,70 +356,59 @@ static int at76c651_ioctl(struct dvb_frontend *fe, unsigned int cmd, void *arg) switch (cmd) { case FE_GET_INFO: - memcpy(arg, &at76c651_info, sizeof (struct dvb_frontend_info)); + memcpy(arg, &at76c651_info, sizeof(struct dvb_frontend_info)); break; case FE_READ_STATUS: - { - - fe_status_t *status = (fe_status_t *) arg; - u8 sync; - - /* - * Bits: FEC, CAR, EQU, TIM, AGC2, AGC1, ADC, PLL (PLL=0) - */ - sync = at76c651_readreg(i2c, 0x80); - - *status = 0; - - if (sync & (0x04 | 0x10)) /* AGC1 || TIM */ - *status |= FE_HAS_SIGNAL; - - if (sync & 0x10) /* TIM */ - *status |= FE_HAS_CARRIER; - - if (sync & 0x80) /* FEC */ - *status |= FE_HAS_VITERBI; - - if (sync & 0x40) /* CAR */ - *status |= FE_HAS_SYNC; - - if ((sync & 0xF0) == 0xF0) /* TIM && EQU && CAR && FEC */ - *status |= FE_HAS_LOCK; - - break; - - } + { + fe_status_t *status = arg; + u8 sync; + + /* + * Bits: FEC, CAR, EQU, TIM, AGC2, AGC1, ADC, PLL (PLL=0) + */ + sync = at76c651_readreg(i2c, 0x80); + + *status = 0; + + if (sync & (0x04 | 0x10)) /* AGC1 || TIM */ + *status |= FE_HAS_SIGNAL; + if (sync & 0x10) /* TIM */ + *status |= FE_HAS_CARRIER; + if (sync & 0x80) /* FEC */ + *status |= FE_HAS_VITERBI; + if (sync & 0x40) /* CAR */ + *status |= FE_HAS_SYNC; + if ((sync & 0xF0) == 0xF0) /* TIM && EQU && CAR && FEC */ + *status |= FE_HAS_LOCK; + break; + } case FE_READ_BER: - { - u32 *ber = (u32 *) arg; - - *ber = (at76c651_readreg(i2c, 0x81) & 0x0F) << 16; - *ber |= at76c651_readreg(i2c, 0x82) << 8; - *ber |= at76c651_readreg(i2c, 0x83); - *ber *= 10; - - break; - } + { + u32 *ber = arg; + *ber = (at76c651_readreg(i2c, 0x81) & 0x0F) << 16; + *ber |= at76c651_readreg(i2c, 0x82) << 8; + *ber |= at76c651_readreg(i2c, 0x83); + *ber *= 10; + break; + } case FE_READ_SIGNAL_STRENGTH: - { - u8 gain = ~at76c651_readreg(i2c, 0x91); - - *(u16 *) arg = (gain << 8) | gain; - break; - } + { + u8 gain = ~at76c651_readreg(i2c, 0x91); + *(u16 *)arg = (gain << 8) | gain; + break; + } case FE_READ_SNR: - *(u16 *) arg = - 0xFFFF - + *(u16 *)arg = 0xFFFF - ((at76c651_readreg(i2c, 0x8F) << 8) | at76c651_readreg(i2c, 0x90)); break; case FE_READ_UNCORRECTED_BLOCKS: - *(u32 *) arg = at76c651_readreg(i2c, 0x82); + *(u32 *)arg = at76c651_readreg(i2c, 0x82); break; case FE_SET_FRONTEND: @@ -449,14 +425,12 @@ static int at76c651_ioctl(struct dvb_frontend *fe, unsigned int cmd, void *arg) case FE_GET_TUNE_SETTINGS: { - struct dvb_frontend_tune_settings* fesettings = - (struct dvb_frontend_tune_settings*) arg; - + struct dvb_frontend_tune_settings *fesettings = arg; fesettings->min_delay_ms = 50; fesettings->step_size = 0; fesettings->max_drift = 0; - return 0; - } + break; + } default: return -ENOIOCTLCMD; @@ -473,28 +447,28 @@ static int attach_adapter(struct i2c_adapter *adapter) struct i2c_client *client; int ret; - if (NULL == (state = kmalloc(sizeof(struct at76c651_state), GFP_KERNEL))) + if (at76c651_readreg(adapter, 0x0E) != 0x65) + return -ENODEV; + + if (!(state = kmalloc(sizeof(struct at76c651_state), GFP_KERNEL))) return -ENOMEM; state->i2c = adapter; state->revision = at76c651_readreg(adapter, 0x0F) & 0xFE; - if (state->revision == 0x10) { - dprintk("AT76C651A found\n"); - strcpy(at76c651_info.name, "Atmel AT76C651A with DAT7021"); - } else { - dprintk("AT76C651B found\n"); - strcpy(at76c651_info.name, "Atmel AT76C651B with DAT7021"); - } - - if (at76c651_readreg(adapter, 0x0E) != 0x65 || - state->revision != 0x10) { - dprintk("no AT76C651(B) found\n"); + switch (state->revision) { + case 0x10: + at76c651_info.name[14] = 'A'; + break; + case 0x11: + at76c651_info.name[14] = 'B'; + break; + default: kfree(state); return -ENODEV; } - if (NULL == (client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) { + if (!(client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) { kfree(state); return -ENOMEM; } @@ -526,27 +500,24 @@ static int attach_adapter(struct i2c_adapter *adapter) static int detach_client(struct i2c_client *client) { - struct at76c651_state *state = (struct at76c651_state*)i2c_get_clientdata(client); - - dprintk ("%s\n", __FUNCTION__); + struct at76c651_state *state = i2c_get_clientdata(client); dvb_unregister_frontend_new(at76c651_ioctl, state->dvb); i2c_detach_client(client); BUG_ON(state->dvb); kfree(client); kfree(state); + return 0; } -static int command (struct i2c_client *client, unsigned int cmd, void *arg) +static int command(struct i2c_client *client, unsigned int cmd, void *arg) { - struct at76c651_state *state = (struct at76c651_state*)i2c_get_clientdata(client); - - dprintk ("%s\n", __FUNCTION__); + struct at76c651_state *state = i2c_get_clientdata(client); switch (cmd) { case FE_REGISTER: - state->dvb = (struct dvb_adapter*)arg; + state->dvb = arg; break; case FE_UNREGISTER: state->dvb = NULL; @@ -554,6 +525,7 @@ static int command (struct i2c_client *client, unsigned int cmd, void *arg) default: return -EOPNOTSUPP; } + return 0; } @@ -586,8 +558,8 @@ static void __exit at76c651_exit(void) module_init(at76c651_init); module_exit(at76c651_exit); +module_param(debug, int, 0444); -MODULE_DESCRIPTION("at76c651/dat7021 dvb-c frontend driver"); +MODULE_DESCRIPTION("at76c651/tua6010xs dvb-c frontend driver"); MODULE_AUTHOR("Andreas Oberritter <obi@linuxtv.org>"); MODULE_LICENSE("GPL"); -MODULE_PARM(debug, "i"); |