From add17e2e692db3dde258c0fb519d58b55cc460f9 Mon Sep 17 00:00:00 2001 From: Michael Krufky Date: Sat, 5 Jan 2008 18:00:09 -0500 Subject: tda18271: clean up calibration initialization procedures From: Michael Krufky Always initialize registers during attach. Perform IR Calibration during init if needed. Perform RF Calibration during init if needed for C2, only. Signed-off-by: Michael Krufky --- linux/drivers/media/dvb/frontends/tda18271-fe.c | 37 ++++++++++++++--------- linux/drivers/media/dvb/frontends/tda18271-priv.h | 1 + 2 files changed, 23 insertions(+), 15 deletions(-) (limited to 'linux') diff --git a/linux/drivers/media/dvb/frontends/tda18271-fe.c b/linux/drivers/media/dvb/frontends/tda18271-fe.c index a6e40e969..7c70ac681 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,16 +618,27 @@ 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; + + /* initialization */ + tda18271_ir_cal_init(fe); + + if (priv->id == TDA18271HDC2) + tda18271_rf_cal_init(fe); + + return 0; +} + static int tda18271c2_tune(struct dvb_frontend *fe, u32 ifc, u32 freq, u32 bw, u8 std) { - int tm = 0; - tda_dbg("freq = %d, ifc = %d\n", freq, ifc); - tda18271_init_cal(fe, &tm); + tda18271_init(fe); - tda18271_rf_tracking_filters_correction(fe, freq, tm); + tda18271_rf_tracking_filters_correction(fe, freq); tda18271_channel_configuration(fe, ifc, freq, bw, std); diff --git a/linux/drivers/media/dvb/frontends/tda18271-priv.h b/linux/drivers/media/dvb/frontends/tda18271-priv.h index 6e04258ca..7b06e0599 100644 --- a/linux/drivers/media/dvb/frontends/tda18271-priv.h +++ b/linux/drivers/media/dvb/frontends/tda18271-priv.h @@ -105,6 +105,7 @@ 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; -- cgit v1.2.3 From 407b62c662853ae567acabbecf5712d00f5b8fd2 Mon Sep 17 00:00:00 2001 From: Michael Krufky Date: Sat, 5 Jan 2008 22:55:21 -0500 Subject: tda18271: store frequency and bandwidth after successful tune From: Michael Krufky Store last tuned frequency & bandwidth after successful tune. Clean up tune functions -- remove pointer to tune function in state structure, instead call tune function based on priv->id. Signed-off-by: Michael Krufky --- linux/drivers/media/dvb/frontends/tda18271-fe.c | 46 +++++++++++++++++++---- linux/drivers/media/dvb/frontends/tda18271-priv.h | 3 -- 2 files changed, 38 insertions(+), 11 deletions(-) (limited to 'linux') diff --git a/linux/drivers/media/dvb/frontends/tda18271-fe.c b/linux/drivers/media/dvb/frontends/tda18271-fe.c index 7c70ac681..3af6ddb1b 100644 --- a/linux/drivers/media/dvb/frontends/tda18271-fe.c +++ b/linux/drivers/media/dvb/frontends/tda18271-fe.c @@ -799,6 +799,23 @@ static int tda18271c1_tune(struct dvb_frontend *fe, 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, @@ -806,12 +823,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 */ @@ -862,7 +878,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, @@ -871,12 +896,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) { @@ -919,7 +943,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) @@ -1025,12 +1057,10 @@ static int tda18271_get_id(struct dvb_frontend *fe) 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"; diff --git a/linux/drivers/media/dvb/frontends/tda18271-priv.h b/linux/drivers/media/dvb/frontends/tda18271-priv.h index 7b06e0599..b4d1ab770 100644 --- a/linux/drivers/media/dvb/frontends/tda18271-priv.h +++ b/linux/drivers/media/dvb/frontends/tda18271-priv.h @@ -112,9 +112,6 @@ struct tda18271_priv { 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); - u32 frequency; u32 bandwidth; }; -- cgit v1.2.3 From ef15cd3c577cdc80d27bbd6ee72c2a9c991cd270 Mon Sep 17 00:00:00 2001 From: Michael Krufky Date: Sun, 6 Jan 2008 13:31:35 -0500 Subject: tda18271: use a mutex to protect state in critical sections From: Michael Krufky Signed-off-by: Michael Krufky --- linux/drivers/media/dvb/frontends/tda18271-fe.c | 20 ++++++++++++++++++++ linux/drivers/media/dvb/frontends/tda18271-priv.h | 12 ++++++++++++ 2 files changed, 32 insertions(+) (limited to 'linux') diff --git a/linux/drivers/media/dvb/frontends/tda18271-fe.c b/linux/drivers/media/dvb/frontends/tda18271-fe.c index 3af6ddb1b..26352716a 100644 --- a/linux/drivers/media/dvb/frontends/tda18271-fe.c +++ b/linux/drivers/media/dvb/frontends/tda18271-fe.c @@ -622,26 +622,36 @@ 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) { + struct tda18271_priv *priv = fe->tuner_priv; + tda_dbg("freq = %d, ifc = %d\n", freq, ifc); tda18271_init(fe); + mutex_lock(&priv->lock); + tda18271_rf_tracking_filters_correction(fe, freq); tda18271_channel_configuration(fe, ifc, freq, bw, std); + mutex_unlock(&priv->lock); + return 0; } @@ -655,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) @@ -795,6 +807,7 @@ static int tda18271c1_tune(struct dvb_frontend *fe, tda18271_write_regs(fe, R_TM, 15); msleep(5); + mutex_unlock(&priv->lock); return 0; } @@ -1051,7 +1064,9 @@ 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: @@ -1104,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; @@ -1123,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 b4d1ab770..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 #include +#include "compat.h" +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) +#include +#else +#include +#endif #include "tda18271.h" #define R_ID 0x00 /* ID byte */ @@ -112,6 +118,12 @@ struct tda18271_priv { struct tda18271_std_map std; struct tda18271_rf_tracking_filter_cal rf_cal_state[8]; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) + struct mutex lock; +#else + struct semaphore lock; +#endif + u32 frequency; u32 bandwidth; }; -- cgit v1.2.3