diff options
author | Michael Krufky <mkrufky@linuxtv.org> | 2007-08-27 20:23:08 -0400 |
---|---|---|
committer | Michael Krufky <mkrufky@linuxtv.org> | 2007-08-27 20:23:08 -0400 |
commit | c7363325efe76153336d10dd7c7d5b82e3d72bbf (patch) | |
tree | a2589aedd78a8f2afbca48721ca60eee98b06f10 | |
parent | 918c1e336d569e3b7731fc8821cbcabebe0cd609 (diff) | |
download | mediapointer-dvb-s2-c7363325efe76153336d10dd7c7d5b82e3d72bbf.tar.gz mediapointer-dvb-s2-c7363325efe76153336d10dd7c7d5b82e3d72bbf.tar.bz2 |
mt20xx: convert from tuner sub-driver into dvb_frontend module
From: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Acked-by: Hans Verkuil <hverkuil@xs4all.nl>
Acked-by: Mike Isely <isely@pobox.com>
Acked-by: Steven Toth <stoth@hauppauge.com>
Acked-by: Patrick Boettcher <pb@linuxtv.org>
Acked-by: Jarod Wilson <jwilson@redhat.com>
Acked-by: Trent Piepho <xyzzy@speakeasy.org>
-rw-r--r-- | linux/drivers/media/video/mt20xx.c | 262 | ||||
-rw-r--r-- | linux/drivers/media/video/mt20xx.h | 27 | ||||
-rw-r--r-- | linux/drivers/media/video/tuner-core.c | 3 | ||||
-rw-r--r-- | linux/drivers/media/video/tuner-driver.h | 2 |
4 files changed, 213 insertions, 81 deletions
diff --git a/linux/drivers/media/video/mt20xx.c b/linux/drivers/media/video/mt20xx.c index f4cd2d8fa..5c6d05b07 100644 --- a/linux/drivers/media/video/mt20xx.c +++ b/linux/drivers/media/video/mt20xx.c @@ -1,17 +1,25 @@ /* - * * i2c tv tuner chip device driver * controls microtune tuners, mt2032 + mt2050 at the moment. + * + * This "mt20xx" module was split apart from the original "tuner" module. */ #include <linux/delay.h> #include <linux/i2c.h> #include "compat.h" #include <linux/videodev.h> -#include "tuner-driver.h" +#include "tuner-i2c.h" +#include "mt20xx.h" #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) #include "i2c-compat.h" #endif +static int debug = 0; +module_param(debug, int, 0644); +MODULE_PARM_DESC(debug, "enable verbose debug messages"); + +#define PREFIX "mt20xx " + /* ---------------------------------------------------------------------- */ static unsigned int optimize_vco = 1; @@ -23,9 +31,6 @@ module_param(tv_antenna, int, 0644); static unsigned int radio_antenna = 0; module_param(radio_antenna, int, 0644); -/* from tuner-core.c */ -extern int tuner_debug; - /* ---------------------------------------------------------------------- */ #define MT2032 0x04 @@ -44,19 +49,31 @@ struct microtune_priv { struct tuner_i2c_props i2c_props; unsigned int xogc; - unsigned int radio_if2; + //unsigned int radio_if2; + + u32 frequency; }; -static void microtune_release(struct tuner *t) +static int microtune_release(struct dvb_frontend *fe) { - kfree(t->priv); - t->priv = NULL; + kfree(fe->tuner_priv); + fe->tuner_priv = NULL; + + return 0; +} + +static int microtune_get_frequency(struct dvb_frontend *fe, u32 *frequency) +{ + struct microtune_priv *priv = fe->tuner_priv; + *frequency = priv->frequency; + return 0; } // IsSpurInBand()? -static int mt2032_spurcheck(struct tuner *t, +static int mt2032_spurcheck(struct dvb_frontend *fe, int f1, int f2, int spectrum_from,int spectrum_to) { + struct microtune_priv *priv = fe->tuner_priv; int n1=1,n2,f; f1=f1/1000; //scale to kHz to avoid 32bit overflows @@ -84,7 +101,7 @@ static int mt2032_spurcheck(struct tuner *t, return 1; } -static int mt2032_compute_freq(struct tuner *t, +static int mt2032_compute_freq(struct dvb_frontend *fe, unsigned int rfin, unsigned int if1, unsigned int if2, unsigned int spectrum_from, @@ -93,6 +110,7 @@ static int mt2032_compute_freq(struct tuner *t, int *ret_sel, unsigned int xogc) //all in Hz { + struct microtune_priv *priv = fe->tuner_priv; unsigned int fref,lo1,lo1n,lo1a,s,sel,lo1freq, desired_lo1, desired_lo2,lo2,lo2n,lo2a,lo2num,lo2freq; @@ -142,7 +160,7 @@ static int mt2032_compute_freq(struct tuner *t, return(-1); } - mt2032_spurcheck(t, lo1freq, desired_lo2, spectrum_from, spectrum_to); + mt2032_spurcheck(fe, lo1freq, desired_lo2, spectrum_from, spectrum_to); // should recalculate lo1 (one step up/down) // set up MT2032 register map for transfer over i2c @@ -166,9 +184,9 @@ static int mt2032_compute_freq(struct tuner *t, return 0; } -static int mt2032_check_lo_lock(struct tuner *t) +static int mt2032_check_lo_lock(struct dvb_frontend *fe) { - struct microtune_priv *priv = t->priv; + struct microtune_priv *priv = fe->tuner_priv; int try,lock=0; unsigned char buf[2]; @@ -188,9 +206,9 @@ static int mt2032_check_lo_lock(struct tuner *t) return lock; } -static int mt2032_optimize_vco(struct tuner *t,int sel,int lock) +static int mt2032_optimize_vco(struct dvb_frontend *fe,int sel,int lock) { - struct microtune_priv *priv = t->priv; + struct microtune_priv *priv = fe->tuner_priv; unsigned char buf[2]; int tad1; @@ -220,18 +238,18 @@ static int mt2032_optimize_vco(struct tuner *t,int sel,int lock) buf[0]=0x0f; buf[1]=sel; tuner_i2c_xfer_send(&priv->i2c_props,buf,2); - lock=mt2032_check_lo_lock(t); + lock=mt2032_check_lo_lock(fe); return lock; } -static void mt2032_set_if_freq(struct tuner *t, unsigned int rfin, +static void mt2032_set_if_freq(struct dvb_frontend *fe, unsigned int rfin, unsigned int if1, unsigned int if2, unsigned int from, unsigned int to) { unsigned char buf[21]; int lint_try,ret,sel,lock=0; - struct microtune_priv *priv = t->priv; + struct microtune_priv *priv = fe->tuner_priv; tuner_dbg("mt2032_set_if_freq rfin=%d if1=%d if2=%d from=%d to=%d\n", rfin,if1,if2,from,to); @@ -241,7 +259,7 @@ static void mt2032_set_if_freq(struct tuner *t, unsigned int rfin, tuner_i2c_xfer_recv(&priv->i2c_props,buf,21); buf[0]=0; - ret=mt2032_compute_freq(t,rfin,if1,if2,from,to,&buf[1],&sel,priv->xogc); + ret=mt2032_compute_freq(fe,rfin,if1,if2,from,to,&buf[1],&sel,priv->xogc); if (ret<0) return; @@ -257,10 +275,10 @@ static void mt2032_set_if_freq(struct tuner *t, unsigned int rfin, // wait for PLLs to lock (per manual), retry LINT if not. for(lint_try=0; lint_try<2; lint_try++) { - lock=mt2032_check_lo_lock(t); + lock=mt2032_check_lo_lock(fe); if(optimize_vco) - lock=mt2032_optimize_vco(t,sel,lock); + lock=mt2032_optimize_vco(fe,sel,lock); if(lock==6) break; tuner_dbg("mt2032: re-init PLLs by LINT\n"); @@ -283,12 +301,13 @@ static void mt2032_set_if_freq(struct tuner *t, unsigned int rfin, } -static void mt2032_set_tv_freq(struct tuner *t, unsigned int freq) +static int mt2032_set_tv_freq(struct dvb_frontend *fe, + struct analog_parameters *params) { int if2,from,to; // signal bandwidth and picture carrier - if (t->std & V4L2_STD_525_60) { + if (params->std & V4L2_STD_525_60) { // NTSC from = 40750*1000; to = 46750*1000; @@ -300,30 +319,72 @@ static void mt2032_set_tv_freq(struct tuner *t, unsigned int freq) if2 = 38900*1000; } - mt2032_set_if_freq(t, freq*62500 /* freq*1000*1000/16 */, + mt2032_set_if_freq(fe, params->frequency*62500, 1090*1000*1000, if2, from, to); + + return 0; } -static void mt2032_set_radio_freq(struct tuner *t, unsigned int freq) +static int mt2032_set_radio_freq(struct dvb_frontend *fe, + struct analog_parameters *params) { - struct microtune_priv *priv = t->priv; - int if2 = priv->radio_if2; + struct microtune_priv *priv = fe->tuner_priv; + int if2; + + if (params->std & V4L2_STD_525_60) { + tuner_dbg("pinnacle ntsc\n"); + if2 = 41300 * 1000; + } else { + tuner_dbg("pinnacle pal\n"); + if2 = 33300 * 1000; + } // per Manual for FM tuning: first if center freq. 1085 MHz - mt2032_set_if_freq(t, freq * 1000 / 16, - 1085*1000*1000,if2,if2,if2); + mt2032_set_if_freq(fe, params->frequency * 125 / 2, + 1085*1000*1000,if2,if2,if2); + + return 0; +} + +static int mt2032_set_params(struct dvb_frontend *fe, + struct analog_parameters *params) +{ + struct microtune_priv *priv = fe->tuner_priv; + int ret = -EINVAL; + + switch (params->mode) { + case V4L2_TUNER_RADIO: + ret = mt2032_set_radio_freq(fe, params); + priv->frequency = params->frequency * 125 / 2; + break; + case V4L2_TUNER_ANALOG_TV: + case V4L2_TUNER_DIGITAL_TV: + ret = mt2032_set_tv_freq(fe, params); + priv->frequency = params->frequency * 62500; + break; + } + + return ret; } -static struct tuner_operations mt2032_tuner_ops = { - .set_tv_freq = mt2032_set_tv_freq, - .set_radio_freq = mt2032_set_radio_freq, - .release = microtune_release, +static struct dvb_tuner_ops mt2032_tuner_ops = { +#if 0 + .info = { + .name = "MT2032", + .frequency_min = , + .frequency_max = , + .frequency_step = , + }, +#endif + .set_analog_params = mt2032_set_params, + .release = microtune_release, + .get_frequency = microtune_get_frequency, }; // Initalization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001 -static int mt2032_init(struct tuner *t) +static int mt2032_init(struct dvb_frontend *fe) { - struct microtune_priv *priv = t->priv; + struct microtune_priv *priv = fe->tuner_priv; unsigned char buf[21]; int ret,xogc,xok=0; @@ -372,14 +433,14 @@ static int mt2032_init(struct tuner *t) } while (xok != 1 ); priv->xogc=xogc; - memcpy(&t->ops, &mt2032_tuner_ops, sizeof(struct tuner_operations)); + memcpy(&fe->ops.tuner_ops, &mt2032_tuner_ops, sizeof(struct dvb_tuner_ops)); return(1); } -static void mt2050_set_antenna(struct tuner *t, unsigned char antenna) +static void mt2050_set_antenna(struct dvb_frontend *fe, unsigned char antenna) { - struct microtune_priv *priv = t->priv; + struct microtune_priv *priv = fe->tuner_priv; unsigned char buf[2]; int ret; @@ -389,9 +450,9 @@ static void mt2050_set_antenna(struct tuner *t, unsigned char antenna) tuner_dbg("mt2050: enabled antenna connector %d\n", antenna); } -static void mt2050_set_if_freq(struct tuner *t,unsigned int freq, unsigned int if2) +static void mt2050_set_if_freq(struct dvb_frontend *fe,unsigned int freq, unsigned int if2) { - struct microtune_priv *priv = t->priv; + struct microtune_priv *priv = fe->tuner_priv; unsigned int if1=1218*1000*1000; unsigned int f_lo1,f_lo2,lo1,lo2,f_lo1_modulo,f_lo2_modulo,num1,num2,div1a,div1b,div2a,div2b; int ret; @@ -423,7 +484,7 @@ static void mt2050_set_if_freq(struct tuner *t,unsigned int freq, unsigned int i div2a=(lo2/8)-1; div2b=lo2-(div2a+1)*8; - if (tuner_debug > 1) { + if (debug > 1) { tuner_dbg("lo1 lo2 = %d %d\n", lo1, lo2); tuner_dbg("num1 num2 div1a div1b div2a div2b= %x %x %x %x %x %x\n", num1,num2,div1a,div1b,div2a,div2b); @@ -439,7 +500,7 @@ static void mt2050_set_if_freq(struct tuner *t,unsigned int freq, unsigned int i buf[5]=div2a; if(num2!=0) buf[5]=buf[5]|0x40; - if (tuner_debug > 1) { + if (debug > 1) { int i; tuner_dbg("bufs is: "); for(i=0;i<6;i++) @@ -452,43 +513,86 @@ static void mt2050_set_if_freq(struct tuner *t,unsigned int freq, unsigned int i tuner_warn("i2c i/o error: rc == %d (should be 6)\n",ret); } -static void mt2050_set_tv_freq(struct tuner *t, unsigned int freq) +static int mt2050_set_tv_freq(struct dvb_frontend *fe, + struct analog_parameters *params) { unsigned int if2; - if (t->std & V4L2_STD_525_60) { + if (params->std & V4L2_STD_525_60) { // NTSC if2 = 45750*1000; } else { // PAL if2 = 38900*1000; } - if (V4L2_TUNER_DIGITAL_TV == t->mode) { + if (V4L2_TUNER_DIGITAL_TV == params->mode) { // DVB (pinnacle 300i) if2 = 36150*1000; } - mt2050_set_if_freq(t, freq*62500, if2); - mt2050_set_antenna(t, tv_antenna); + mt2050_set_if_freq(fe, params->frequency*62500, if2); + mt2050_set_antenna(fe, tv_antenna); + + return 0; +} + +static int mt2050_set_radio_freq(struct dvb_frontend *fe, + struct analog_parameters *params) +{ + struct microtune_priv *priv = fe->tuner_priv; + int if2; + + if (params->std & V4L2_STD_525_60) { + tuner_dbg("pinnacle ntsc\n"); + if2 = 41300 * 1000; + } else { + tuner_dbg("pinnacle pal\n"); + if2 = 33300 * 1000; + } + + mt2050_set_if_freq(fe, params->frequency * 125 / 2, if2); + mt2050_set_antenna(fe, radio_antenna); + + return 0; } -static void mt2050_set_radio_freq(struct tuner *t, unsigned int freq) +static int mt2050_set_params(struct dvb_frontend *fe, + struct analog_parameters *params) { - struct microtune_priv *priv = t->priv; - int if2 = priv->radio_if2; + struct microtune_priv *priv = fe->tuner_priv; + int ret = -EINVAL; - mt2050_set_if_freq(t, freq * 1000 / 16, if2); - mt2050_set_antenna(t, radio_antenna); + switch (params->mode) { + case V4L2_TUNER_RADIO: + ret = mt2050_set_radio_freq(fe, params); + priv->frequency = params->frequency * 125 / 2; + break; + case V4L2_TUNER_ANALOG_TV: + case V4L2_TUNER_DIGITAL_TV: + ret = mt2050_set_tv_freq(fe, params); + priv->frequency = params->frequency * 62500; + break; + } + + return ret; } -static struct tuner_operations mt2050_tuner_ops = { - .set_tv_freq = mt2050_set_tv_freq, - .set_radio_freq = mt2050_set_radio_freq, - .release = microtune_release, +static struct dvb_tuner_ops mt2050_tuner_ops = { +#if 0 + .info = { + .name = "MT2050", + .frequency_min = , + .frequency_max = , + .frequency_step = , + }, +#endif + .set_analog_params = mt2050_set_params, + .release = microtune_release, + .get_frequency = microtune_get_frequency, }; -static int mt2050_init(struct tuner *t) +static int mt2050_init(struct dvb_frontend *fe) { - struct microtune_priv *priv = t->priv; + struct microtune_priv *priv = fe->tuner_priv; unsigned char buf[2]; int ret; @@ -506,12 +610,14 @@ static int mt2050_init(struct tuner *t) tuner_dbg("mt2050: sro is %x\n",buf[0]); - memcpy(&t->ops, &mt2050_tuner_ops, sizeof(struct tuner_operations)); + memcpy(&fe->ops.tuner_ops, &mt2050_tuner_ops, sizeof(struct dvb_tuner_ops)); return 0; } -int microtune_init(struct tuner *t) +struct dvb_frontend *microtune_attach(struct dvb_frontend *fe, + struct i2c_adapter* i2c_adap, + u8 i2c_addr) { struct microtune_priv *priv = NULL; char *name; @@ -520,28 +626,21 @@ int microtune_init(struct tuner *t) priv = kzalloc(sizeof(struct microtune_priv), GFP_KERNEL); if (priv == NULL) - return -ENOMEM; - t->priv = priv; + return NULL; + fe->tuner_priv = priv; - priv->i2c_props.addr = t->i2c.addr; - priv->i2c_props.adap = t->i2c.adapter; + priv->i2c_props.addr = i2c_addr; + priv->i2c_props.adap = i2c_adap; - priv->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */ + //priv->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */ memset(buf,0,sizeof(buf)); - if (t->std & V4L2_STD_525_60) { - tuner_dbg("pinnacle ntsc\n"); - priv->radio_if2 = 41300 * 1000; - } else { - tuner_dbg("pinnacle pal\n"); - priv->radio_if2 = 33300 * 1000; - } name = "unknown"; tuner_i2c_xfer_send(&priv->i2c_props,buf,1); tuner_i2c_xfer_recv(&priv->i2c_props,buf,21); - if (tuner_debug) { + if (debug) { int i; tuner_dbg("MT20xx hexdump:"); for(i=0;i<21;i++) { @@ -576,10 +675,10 @@ int microtune_init(struct tuner *t) name = microtune_part[buf[0x13]]; switch (buf[0x13]) { case MT2032: - mt2032_init(t); + mt2032_init(fe); break; case MT2050: - mt2050_init(t); + mt2050_init(fe); break; default: tuner_info("microtune %s found, not (yet?) supported, sorry :-/\n", @@ -587,11 +686,18 @@ int microtune_init(struct tuner *t) return 0; } - strlcpy(t->i2c.name, name, sizeof(t->i2c.name)); + strlcpy(fe->ops.tuner_ops.info.name, name, + sizeof(fe->ops.tuner_ops.info.name)); tuner_info("microtune %s found, OK\n",name); - return 0; + return fe; } +EXPORT_SYMBOL_GPL(microtune_attach); + +MODULE_DESCRIPTION("Microtune tuner driver"); +MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer"); +MODULE_LICENSE("GPL"); + /* * Overrides for Emacs so that we follow Linus's tabbing style. * --------------------------------------------------------------------------- diff --git a/linux/drivers/media/video/mt20xx.h b/linux/drivers/media/video/mt20xx.h new file mode 100644 index 000000000..877dbef89 --- /dev/null +++ b/linux/drivers/media/video/mt20xx.h @@ -0,0 +1,27 @@ +/* + 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. +*/ + +#ifndef __MT20XX_H__ +#define __MT20XX_H__ + +#include <linux/i2c.h> +#include "dvb_frontend.h" + +extern struct dvb_frontend *microtune_attach(struct dvb_frontend *fe, + struct i2c_adapter* i2c_adap, + u8 i2c_addr); + +#endif /* __MT20XX_H__ */ diff --git a/linux/drivers/media/video/tuner-core.c b/linux/drivers/media/video/tuner-core.c index 2ce842ecf..21e54af32 100644 --- a/linux/drivers/media/video/tuner-core.c +++ b/linux/drivers/media/video/tuner-core.c @@ -23,6 +23,7 @@ #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) #include "i2c-compat.h" #endif +#include "mt20xx.h" #include "tda8290.h" #define UNSET (-1U) @@ -279,7 +280,7 @@ static void set_type(struct i2c_client *c, unsigned int type, switch (t->type) { case TUNER_MT2032: - microtune_init(t); + microtune_attach(&t->fe, t->i2c.adapter, t->i2c.addr); break; case TUNER_PHILIPS_TDA8290: { diff --git a/linux/drivers/media/video/tuner-driver.h b/linux/drivers/media/video/tuner-driver.h index 28e7c99a9..7e80154ea 100644 --- a/linux/drivers/media/video/tuner-driver.h +++ b/linux/drivers/media/video/tuner-driver.h @@ -76,8 +76,6 @@ extern int default_tuner_init(struct tuner *t); extern int tda9887_tuner_init(struct tuner *t); -extern int microtune_init(struct tuner *t); - extern int tea5761_tuner_init(struct tuner *t); extern int tea5761_autodetection(struct tuner *t); |