diff options
author | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-01-07 06:28:29 -0200 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-01-07 06:28:29 -0200 |
commit | 74ce6b7b0556581a03c969a92a04445076b7426f (patch) | |
tree | fa6cdfc22270e8c6abb8624ee7e7ecb8fac60d7d /linux/drivers | |
parent | df0b4ca7281eb52502a930f064748b7668875d64 (diff) | |
parent | ef15cd3c577cdc80d27bbd6ee72c2a9c991cd270 (diff) | |
download | mediapointer-dvb-s2-74ce6b7b0556581a03c969a92a04445076b7426f.tar.gz mediapointer-dvb-s2-74ce6b7b0556581a03c969a92a04445076b7426f.tar.bz2 |
merge: http://linuxtv.org/hg/~mkrufky/tda18271
From: Mauro Carvalho Chehab <mchehab@infradead.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'linux/drivers')
-rw-r--r-- | linux/drivers/media/dvb/frontends/tda18271-fe.c | 101 | ||||
-rw-r--r-- | linux/drivers/media/dvb/frontends/tda18271-priv.h | 14 |
2 files changed, 91 insertions, 24 deletions
diff --git a/linux/drivers/media/dvb/frontends/tda18271-fe.c b/linux/drivers/media/dvb/frontends/tda18271-fe.c index a6e40e969..26352716a 100644 --- a/linux/drivers/media/dvb/frontends/tda18271-fe.c +++ b/linux/drivers/media/dvb/frontends/tda18271-fe.c @@ -30,7 +30,7 @@ MODULE_PARM_DESC(debug, "set debug level " /*---------------------------------------------------------------------*/ -static int tda18271_init(struct dvb_frontend *fe) +static int tda18271_ir_cal_init(struct dvb_frontend *fe) { struct tda18271_priv *priv = fe->tuner_priv; unsigned char *regs = priv->tda18271_regs; @@ -204,7 +204,7 @@ static int tda18271_read_thermometer(struct dvb_frontend *fe) } static int tda18271_rf_tracking_filters_correction(struct dvb_frontend *fe, - u32 freq, int tm_rfcal) + u32 freq) { struct tda18271_priv *priv = fe->tuner_priv; struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state; @@ -244,7 +244,7 @@ static int tda18271_rf_tracking_filters_correction(struct dvb_frontend *fe, tda18271_lookup_map(fe, RF_CAL_DC_OVER_DT, &freq, &dc_over_dt); /* calculate temperature compensation */ - rfcal_comp = dc_over_dt * (tm_current - tm_rfcal); + rfcal_comp = dc_over_dt * (tm_current - priv->tm_rfcal); regs[R_EB14] = approx + rfcal_comp; tda18271_write_regs(fe, R_EB14, 1); @@ -578,8 +578,7 @@ static int tda18271_rf_tracking_filters_init(struct dvb_frontend *fe, u32 freq) return 0; } -static int tda18271_calc_rf_filter_curve(struct dvb_frontend *fe, - int *tm_rfcal) +static int tda18271_calc_rf_filter_curve(struct dvb_frontend *fe) { struct tda18271_priv *priv = fe->tuner_priv; unsigned int i; @@ -596,24 +595,21 @@ static int tda18271_calc_rf_filter_curve(struct dvb_frontend *fe, tda18271_rf_tracking_filters_init(fe, 1000 * priv->rf_cal_state[i].rfmax); - *tm_rfcal = tda18271_read_thermometer(fe); + priv->tm_rfcal = tda18271_read_thermometer(fe); return 0; } /* ------------------------------------------------------------------ */ -static int tda18271_init_cal(struct dvb_frontend *fe, int *tm) +static int tda18271_rf_cal_init(struct dvb_frontend *fe) { struct tda18271_priv *priv = fe->tuner_priv; if (priv->cal_initialized) return 0; - /* initialization */ - tda18271_init(fe); - - tda18271_calc_rf_filter_curve(fe, tm); + tda18271_calc_rf_filter_curve(fe); tda18271_por(fe); @@ -622,19 +618,40 @@ static int tda18271_init_cal(struct dvb_frontend *fe, int *tm) return 0; } +static int tda18271_init(struct dvb_frontend *fe) +{ + struct tda18271_priv *priv = fe->tuner_priv; + + mutex_lock(&priv->lock); + + /* initialization */ + tda18271_ir_cal_init(fe); + + if (priv->id == TDA18271HDC2) + tda18271_rf_cal_init(fe); + + mutex_unlock(&priv->lock); + + return 0; +} + static int tda18271c2_tune(struct dvb_frontend *fe, u32 ifc, u32 freq, u32 bw, u8 std) { - int tm = 0; + struct tda18271_priv *priv = fe->tuner_priv; tda_dbg("freq = %d, ifc = %d\n", freq, ifc); - tda18271_init_cal(fe, &tm); + tda18271_init(fe); + + mutex_lock(&priv->lock); - tda18271_rf_tracking_filters_correction(fe, freq, tm); + tda18271_rf_tracking_filters_correction(fe, freq); tda18271_channel_configuration(fe, ifc, freq, bw, std); + mutex_unlock(&priv->lock); + return 0; } @@ -648,6 +665,8 @@ static int tda18271c1_tune(struct dvb_frontend *fe, u32 N = 0; tda18271_init(fe); + + mutex_lock(&priv->lock); #if 0 /* FIXME: FM Radio support */ if (t->mode == V4L2_TUNER_RADIO) @@ -788,10 +807,28 @@ static int tda18271c1_tune(struct dvb_frontend *fe, tda18271_write_regs(fe, R_TM, 15); msleep(5); + mutex_unlock(&priv->lock); return 0; } +static inline int tda18271_tune(struct dvb_frontend *fe, + u32 ifc, u32 freq, u32 bw, u8 std) +{ + struct tda18271_priv *priv = fe->tuner_priv; + int ret = -EINVAL; + + switch (priv->id) { + case TDA18271HDC1: + ret = tda18271c1_tune(fe, ifc, freq, bw, std); + break; + case TDA18271HDC2: + ret = tda18271c2_tune(fe, ifc, freq, bw, std); + break; + } + return ret; +} + /* ------------------------------------------------------------------ */ static int tda18271_set_params(struct dvb_frontend *fe, @@ -799,12 +836,11 @@ static int tda18271_set_params(struct dvb_frontend *fe, { struct tda18271_priv *priv = fe->tuner_priv; struct tda18271_std_map *std_map = &priv->std; + int ret; u8 std; u16 sgIF; u32 bw, freq = params->frequency; - BUG_ON(!priv->tune); - priv->mode = TDA18271_DIGITAL; /* see table 22 */ @@ -855,7 +891,16 @@ static int tda18271_set_params(struct dvb_frontend *fe, return -EINVAL; } - return priv->tune(fe, sgIF * 1000, freq, bw, std); + ret = tda18271_tune(fe, sgIF * 1000, freq, bw, std); + + if (ret < 0) + goto fail; + + priv->frequency = freq; + priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? + params->u.ofdm.bandwidth : 0; +fail: + return ret; } static int tda18271_set_analog_params(struct dvb_frontend *fe, @@ -864,12 +909,11 @@ static int tda18271_set_analog_params(struct dvb_frontend *fe, struct tda18271_priv *priv = fe->tuner_priv; struct tda18271_std_map *std_map = &priv->std; char *mode; + int ret; u8 std; u16 sgIF; u32 freq = params->frequency * 62500; - BUG_ON(!priv->tune); - priv->mode = TDA18271_ANALOG; if (params->std & V4L2_STD_MN) { @@ -912,7 +956,15 @@ static int tda18271_set_analog_params(struct dvb_frontend *fe, #endif tda_dbg("setting tda18271 to system %s\n", mode); - return priv->tune(fe, sgIF * 1000, freq, 0, std); + ret = tda18271_tune(fe, sgIF * 1000, freq, 0, std); + + if (ret < 0) + goto fail; + + priv->frequency = freq; + priv->bandwidth = 0; +fail: + return ret; } static int tda18271_release(struct dvb_frontend *fe) @@ -1012,18 +1064,18 @@ static int tda18271_get_id(struct dvb_frontend *fe) char *name; int ret = 0; + mutex_lock(&priv->lock); tda18271_read_regs(fe); + mutex_unlock(&priv->lock); switch (regs[R_ID] & 0x7f) { case 3: name = "TDA18271HD/C1"; priv->id = TDA18271HDC1; - priv->tune = tda18271c1_tune; break; case 4: name = "TDA18271HD/C2"; priv->id = TDA18271HDC2; - priv->tune = tda18271c2_tune; break; default: name = "Unknown device"; @@ -1067,6 +1119,7 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr, priv->i2c_adap = i2c; priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO; priv->cal_initialized = false; + mutex_init(&priv->lock); fe->tuner_priv = priv; @@ -1086,8 +1139,12 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr, if (tda18271_debug & DBG_MAP) tda18271_dump_std_map(fe); + mutex_lock(&priv->lock); + tda18271_init_regs(fe); + mutex_unlock(&priv->lock); + return fe; fail: tda18271_release(fe); diff --git a/linux/drivers/media/dvb/frontends/tda18271-priv.h b/linux/drivers/media/dvb/frontends/tda18271-priv.h index 6e04258ca..5eaa0462b 100644 --- a/linux/drivers/media/dvb/frontends/tda18271-priv.h +++ b/linux/drivers/media/dvb/frontends/tda18271-priv.h @@ -23,6 +23,12 @@ #include <linux/kernel.h> #include <linux/types.h> +#include "compat.h" +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) +#include <linux/mutex.h> +#else +#include <asm/semaphore.h> +#endif #include "tda18271.h" #define R_ID 0x00 /* ID byte */ @@ -105,14 +111,18 @@ struct tda18271_priv { enum tda18271_i2c_gate gate; enum tda18271_ver id; + unsigned int tm_rfcal; unsigned int cal_initialized:1; struct tda18271_map_layout *maps; struct tda18271_std_map std; struct tda18271_rf_tracking_filter_cal rf_cal_state[8]; - int (*tune) (struct dvb_frontend *fe, - u32 ifc, u32 freq, u32 bw, u8 std); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) + struct mutex lock; +#else + struct semaphore lock; +#endif u32 frequency; u32 bandwidth; |