Commit 2f27dfc9 authored by Michael Krufky's avatar Michael Krufky Committed by Mauro Carvalho Chehab

V4L/DVB (6926): tda18271: consolidate table lookup functions

Signed-off-by: default avatarMichael Krufky <mkrufky@linuxtv.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent d3714210
...@@ -360,7 +360,9 @@ static int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq) ...@@ -360,7 +360,9 @@ static int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq)
u8 d, pd; u8 d, pd;
u32 div; u32 div;
tda18271_lookup_main_pll(&freq, &pd, &d); int ret = tda18271_lookup_pll_map(MAIN_PLL, &freq, &pd, &d);
if (ret < 0)
goto fail;
regs[R_MPD] = (0x77 & pd); regs[R_MPD] = (0x77 & pd);
...@@ -378,8 +380,8 @@ static int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq) ...@@ -378,8 +380,8 @@ static int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq)
regs[R_MD1] = 0x7f & (div >> 16); regs[R_MD1] = 0x7f & (div >> 16);
regs[R_MD2] = 0xff & (div >> 8); regs[R_MD2] = 0xff & (div >> 8);
regs[R_MD3] = 0xff & div; regs[R_MD3] = 0xff & div;
fail:
return 0; return ret;
} }
static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq) static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq)
...@@ -390,7 +392,9 @@ static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq) ...@@ -390,7 +392,9 @@ static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq)
u8 d, pd; u8 d, pd;
u32 div; u32 div;
tda18271_lookup_cal_pll(&freq, &pd, &d); int ret = tda18271_lookup_pll_map(CAL_PLL, &freq, &pd, &d);
if (ret < 0)
goto fail;
regs[R_CPD] = pd; regs[R_CPD] = pd;
...@@ -399,8 +403,8 @@ static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq) ...@@ -399,8 +403,8 @@ static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq)
regs[R_CD1] = 0x7f & (div >> 16); regs[R_CD1] = 0x7f & (div >> 16);
regs[R_CD2] = 0xff & (div >> 8); regs[R_CD2] = 0xff & (div >> 8);
regs[R_CD3] = 0xff & div; regs[R_CD3] = 0xff & div;
fail:
return 0; return ret;
} }
static int tda18271_tune(struct dvb_frontend *fe, static int tda18271_tune(struct dvb_frontend *fe,
...@@ -418,7 +422,7 @@ static int tda18271_tune(struct dvb_frontend *fe, ...@@ -418,7 +422,7 @@ static int tda18271_tune(struct dvb_frontend *fe,
/* RF tracking filter calibration */ /* RF tracking filter calibration */
/* calculate BP_Filter */ /* calculate BP_Filter */
tda18271_lookup_bp_filter(&freq, &val); tda18271_lookup_map(BP_FILTER, &freq, &val);
regs[R_EP1] &= ~0x07; /* clear bp filter bits */ regs[R_EP1] &= ~0x07; /* clear bp filter bits */
regs[R_EP1] |= val; regs[R_EP1] |= val;
...@@ -470,20 +474,20 @@ static int tda18271_tune(struct dvb_frontend *fe, ...@@ -470,20 +474,20 @@ static int tda18271_tune(struct dvb_frontend *fe,
msleep(5); /* RF tracking filter calibration initialization */ msleep(5); /* RF tracking filter calibration initialization */
/* search for K,M,CO for RF Calibration */ /* search for K,M,CO for RF Calibration */
tda18271_lookup_km(&freq, &val); tda18271_lookup_map(RF_CAL_KMCO, &freq, &val);
regs[R_EB13] &= 0x83; regs[R_EB13] &= 0x83;
regs[R_EB13] |= val; regs[R_EB13] |= val;
tda18271_write_regs(fe, R_EB13, 1); tda18271_write_regs(fe, R_EB13, 1);
/* search for RF_BAND */ /* search for RF_BAND */
tda18271_lookup_rf_band(&freq, &val); tda18271_lookup_map(RF_BAND, &freq, &val);
regs[R_EP2] &= ~0xe0; /* clear rf band bits */ regs[R_EP2] &= ~0xe0; /* clear rf band bits */
regs[R_EP2] |= (val << 5); regs[R_EP2] |= (val << 5);
/* search for Gain_Taper */ /* search for Gain_Taper */
tda18271_lookup_gain_taper(&freq, &val); tda18271_lookup_map(GAIN_TAPER, &freq, &val);
regs[R_EP2] &= ~0x1f; /* clear gain taper bits */ regs[R_EP2] &= ~0x1f; /* clear gain taper bits */
regs[R_EP2] |= val; regs[R_EP2] |= val;
...@@ -511,7 +515,7 @@ static int tda18271_tune(struct dvb_frontend *fe, ...@@ -511,7 +515,7 @@ static int tda18271_tune(struct dvb_frontend *fe,
tda18271_write_regs(fe, R_EP1, 1); tda18271_write_regs(fe, R_EP1, 1);
/* RF tracking filer correction for VHF_Low band */ /* RF tracking filer correction for VHF_Low band */
tda18271_lookup_rf_cal(&freq, &val); tda18271_lookup_map(RF_CAL, &freq, &val);
/* VHF_Low band only */ /* VHF_Low band only */
if (val != 0) { if (val != 0) {
...@@ -555,7 +559,7 @@ static int tda18271_tune(struct dvb_frontend *fe, ...@@ -555,7 +559,7 @@ static int tda18271_tune(struct dvb_frontend *fe,
regs[R_EP4] &= ~0x80; /* turn this bit on only for fm */ regs[R_EP4] &= ~0x80; /* turn this bit on only for fm */
/* image rejection validity EP5[2:0] */ /* image rejection validity EP5[2:0] */
tda18271_lookup_ir_measure(&freq, &val); tda18271_lookup_map(IR_MEASURE, &freq, &val);
regs[R_EP5] &= ~0x07; regs[R_EP5] &= ~0x07;
regs[R_EP5] |= val; regs[R_EP5] |= val;
......
...@@ -104,15 +104,23 @@ extern int tda18271_debug; ...@@ -104,15 +104,23 @@ extern int tda18271_debug;
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
extern void tda18271_lookup_cal_pll(u32 *freq, u8 *post_div, u8 *div); enum tda18271_map_type {
extern void tda18271_lookup_main_pll(u32 *freq, u8 *post_div, u8 *div); /* tda18271_pll_map */
MAIN_PLL,
extern void tda18271_lookup_bp_filter(u32 *freq, u8 *val); CAL_PLL,
extern void tda18271_lookup_km(u32 *freq, u8 *val); /* tda18271_map */
extern void tda18271_lookup_rf_band(u32 *freq, u8 *val); RF_CAL,
extern void tda18271_lookup_gain_taper(u32 *freq, u8 *val); RF_CAL_KMCO,
extern void tda18271_lookup_rf_cal(u32 *freq, u8 *val); BP_FILTER,
extern void tda18271_lookup_ir_measure(u32 *freq, u8 *val); RF_BAND,
GAIN_TAPER,
IR_MEASURE,
};
extern int tda18271_lookup_pll_map(enum tda18271_map_type map_type,
u32 *freq, u8 *post_div, u8 *div);
extern int tda18271_lookup_map(enum tda18271_map_type map_type,
u32 *freq, u8 *val);
#endif /* __TDA18271_PRIV_H__ */ #endif /* __TDA18271_PRIV_H__ */
......
...@@ -267,22 +267,33 @@ static struct tda18271_map tda18271_ir_measure[] = { ...@@ -267,22 +267,33 @@ static struct tda18271_map tda18271_ir_measure[] = {
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
static void tda18271_lookup_map(struct tda18271_map *map, int tda18271_lookup_pll_map(enum tda18271_map_type map_type,
u32 *freq, u8 *val) u32 *freq, u8 *post_div, u8 *div)
{ {
int i = 0; struct tda18271_pll_map *map = NULL;
while ((map[i].rfmax * 1000) < *freq) { unsigned int i = 0;
if (map[i + 1].rfmax == 0) char *map_name;
break;
i++; switch (map_type) {
case MAIN_PLL:
map = tda18271_main_pll;
map_name = "main_pll";
break;
case CAL_PLL:
map = tda18271_cal_pll;
map_name = "cal_pll";
break;
default:
/* we should never get here */
map_name = "undefined";
break;
}
if (!map) {
dbg_info("%s map is not set!\n", map_name);
return -EINVAL;
} }
*val = map[i].val;
}
static void tda18271_lookup_pll_map(struct tda18271_pll_map *map,
u32 *freq, u8 *post_div, u8 *div)
{
int i = 0;
while ((map[i].lomax * 1000) < *freq) { while ((map[i].lomax * 1000) < *freq) {
if (map[i + 1].lomax == 0) if (map[i + 1].lomax == 0)
break; break;
...@@ -290,56 +301,65 @@ static void tda18271_lookup_pll_map(struct tda18271_pll_map *map, ...@@ -290,56 +301,65 @@ static void tda18271_lookup_pll_map(struct tda18271_pll_map *map,
} }
*post_div = map[i].pd; *post_div = map[i].pd;
*div = map[i].d; *div = map[i].d;
}
/*---------------------------------------------------------------------*/
void tda18271_lookup_cal_pll(u32 *freq, u8 *post_div, u8 *div) dbg_map("%s: post div = 0x%02x, div = 0x%02x\n",
{ map_name, *post_div, *div);
tda18271_lookup_pll_map(tda18271_cal_pll, freq, post_div, div);
dbg_map("post div = 0x%02x, div = 0x%02x\n", *post_div, *div);
}
void tda18271_lookup_main_pll(u32 *freq, u8 *post_div, u8 *div) return 0;
{
tda18271_lookup_pll_map(tda18271_main_pll, freq, post_div, div);
dbg_map("post div = 0x%02x, div = 0x%02x\n", *post_div, *div);
} }
void tda18271_lookup_bp_filter(u32 *freq, u8 *val) int tda18271_lookup_map(enum tda18271_map_type map_type, u32 *freq, u8 *val)
{ {
tda18271_lookup_map(tda18271_bp_filter, freq, val); struct tda18271_map *map = NULL;
dbg_map("0x%02x\n", *val); unsigned int i = 0;
} char *map_name;
void tda18271_lookup_km(u32 *freq, u8 *val) switch (map_type) {
{ case BP_FILTER:
tda18271_lookup_map(tda18271_km, freq, val); map = tda18271_bp_filter;
dbg_map("0x%02x\n", *val); map_name = "bp_filter";
} break;
case RF_CAL_KMCO:
map = tda18271_km;
map_name = "km";
break;
case RF_BAND:
map = tda18271_rf_band;
map_name = "rf_band";
break;
case GAIN_TAPER:
map = tda18271_gain_taper;
map_name = "gain_taper";
break;
case RF_CAL:
map = tda18271_rf_cal;
map_name = "rf_cal";
break;
case IR_MEASURE:
map = tda18271_ir_measure;
map_name = "ir_measure";
break;
default:
/* we should never get here */
map_name = "undefined";
break;
}
void tda18271_lookup_rf_band(u32 *freq, u8 *val) if (!map) {
{ dbg_info("%s map is not set!\n", map_name);
tda18271_lookup_map(tda18271_rf_band, freq, val); return -EINVAL;
dbg_map("0x%02x\n", *val); }
}
void tda18271_lookup_gain_taper(u32 *freq, u8 *val) while ((map[i].rfmax * 1000) < *freq) {
{ if (map[i + 1].rfmax == 0)
tda18271_lookup_map(tda18271_gain_taper, freq, val); break;
dbg_map("0x%02x\n", *val); i++;
} }
*val = map[i].val;
void tda18271_lookup_rf_cal(u32 *freq, u8 *val) dbg_map("%s: 0x%02x\n", map_name, *val);
{
tda18271_lookup_map(tda18271_rf_cal, freq, val);
dbg_map("0x%02x\n", *val);
}
void tda18271_lookup_ir_measure(u32 *freq, u8 *val) return 0;
{
tda18271_lookup_map(tda18271_ir_measure, freq, val);
dbg_map("0x%02x\n", *val);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment