u8 d, pd;
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_MD1] = 0x7f & (div >> 16);
regs[R_MD2] = 0xff & (div >> 8);
regs[R_MD3] = 0xff & div;
-
- return 0;
+fail:
+ return ret;
}
static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq)
u8 d, pd;
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_CD1] = 0x7f & (div >> 16);
regs[R_CD2] = 0xff & (div >> 8);
regs[R_CD3] = 0xff & div;
-
- return 0;
+fail:
+ return ret;
}
static int tda18271_tune(struct dvb_frontend *fe,
/* RF tracking filter calibration */
/* 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] |= val;
msleep(5); /* RF tracking filter calibration initialization */
/* 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] |= val;
tda18271_write_regs(fe, R_EB13, 1);
/* 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] |= (val << 5);
/* 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] |= val;
tda18271_write_regs(fe, R_EP1, 1);
/* 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 */
if (val != 0) {
regs[R_EP4] &= ~0x80; /* turn this bit on only for fm */
/* 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] |= val;
/*---------------------------------------------------------------------*/
-extern void tda18271_lookup_cal_pll(u32 *freq, u8 *post_div, u8 *div);
-extern void tda18271_lookup_main_pll(u32 *freq, u8 *post_div, u8 *div);
-
-extern void tda18271_lookup_bp_filter(u32 *freq, u8 *val);
-extern void tda18271_lookup_km(u32 *freq, u8 *val);
-extern void tda18271_lookup_rf_band(u32 *freq, u8 *val);
-extern void tda18271_lookup_gain_taper(u32 *freq, u8 *val);
-extern void tda18271_lookup_rf_cal(u32 *freq, u8 *val);
-extern void tda18271_lookup_ir_measure(u32 *freq, u8 *val);
+enum tda18271_map_type {
+ /* tda18271_pll_map */
+ MAIN_PLL,
+ CAL_PLL,
+ /* tda18271_map */
+ RF_CAL,
+ RF_CAL_KMCO,
+ BP_FILTER,
+ 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__ */
/*---------------------------------------------------------------------*/
-static void tda18271_lookup_map(struct tda18271_map *map,
- u32 *freq, u8 *val)
+int tda18271_lookup_pll_map(enum tda18271_map_type map_type,
+ u32 *freq, u8 *post_div, u8 *div)
{
- int i = 0;
- while ((map[i].rfmax * 1000) < *freq) {
- if (map[i + 1].rfmax == 0)
- break;
- i++;
+ struct tda18271_pll_map *map = NULL;
+ unsigned int i = 0;
+ char *map_name;
+
+ 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) {
if (map[i + 1].lomax == 0)
break;
}
*post_div = map[i].pd;
*div = map[i].d;
-}
-
-/*---------------------------------------------------------------------*/
-void tda18271_lookup_cal_pll(u32 *freq, u8 *post_div, u8 *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);
-}
+ dbg_map("%s: post div = 0x%02x, div = 0x%02x\n",
+ map_name, *post_div, *div);
-void tda18271_lookup_main_pll(u32 *freq, u8 *post_div, u8 *div)
-{
- tda18271_lookup_pll_map(tda18271_main_pll, freq, post_div, div);
- dbg_map("post div = 0x%02x, div = 0x%02x\n", *post_div, *div);
+ return 0;
}
-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);
- dbg_map("0x%02x\n", *val);
-}
+ struct tda18271_map *map = NULL;
+ unsigned int i = 0;
+ char *map_name;
-void tda18271_lookup_km(u32 *freq, u8 *val)
-{
- tda18271_lookup_map(tda18271_km, freq, val);
- dbg_map("0x%02x\n", *val);
-}
+ switch (map_type) {
+ case BP_FILTER:
+ map = tda18271_bp_filter;
+ 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)
-{
- tda18271_lookup_map(tda18271_rf_band, freq, val);
- dbg_map("0x%02x\n", *val);
-}
+ if (!map) {
+ dbg_info("%s map is not set!\n", map_name);
+ return -EINVAL;
+ }
-void tda18271_lookup_gain_taper(u32 *freq, u8 *val)
-{
- tda18271_lookup_map(tda18271_gain_taper, freq, val);
- dbg_map("0x%02x\n", *val);
-}
+ while ((map[i].rfmax * 1000) < *freq) {
+ if (map[i + 1].rfmax == 0)
+ break;
+ i++;
+ }
+ *val = map[i].val;
-void tda18271_lookup_rf_cal(u32 *freq, u8 *val)
-{
- tda18271_lookup_map(tda18271_rf_cal, freq, val);
- dbg_map("0x%02x\n", *val);
-}
+ dbg_map("%s: 0x%02x\n", map_name, *val);
-void tda18271_lookup_ir_measure(u32 *freq, u8 *val)
-{
- tda18271_lookup_map(tda18271_ir_measure, freq, val);
- dbg_map("0x%02x\n", *val);
+ return 0;
}
/*