]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
V4L/DVB (6926): tda18271: consolidate table lookup functions
authorMichael Krufky <mkrufky@linuxtv.org>
Tue, 25 Dec 2007 03:39:37 +0000 (00:39 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Fri, 25 Jan 2008 21:04:25 +0000 (19:04 -0200)
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
drivers/media/dvb/frontends/tda18271-fe.c
drivers/media/dvb/frontends/tda18271-priv.h
drivers/media/dvb/frontends/tda18271-tables.c

index 4526def2d42f4af2b0f891a0c46321618b96ba70..72e256ebeb0fcbaded2e5ef4ac5f01a600b0daba 100644 (file)
@@ -360,7 +360,9 @@ static int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq)
        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);
 
@@ -378,8 +380,8 @@ static int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq)
        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)
@@ -390,7 +392,9 @@ 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;
 
@@ -399,8 +403,8 @@ static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq)
        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,
@@ -418,7 +422,7 @@ 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;
@@ -470,20 +474,20 @@ static int tda18271_tune(struct dvb_frontend *fe,
        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;
@@ -511,7 +515,7 @@ static int tda18271_tune(struct dvb_frontend *fe,
        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) {
@@ -555,7 +559,7 @@ static int tda18271_tune(struct dvb_frontend *fe,
        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;
index 7b9aa9ad53fe3703edb78e60597d59974dc47856..b08bf08aa88f64b5f7127120658cfd47c30f2f2c 100644 (file)
@@ -104,15 +104,23 @@ extern int tda18271_debug;
 
 /*---------------------------------------------------------------------*/
 
-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__ */
 
index 02b6d2cb95708d91ce4f512b2c47a7ed1986d4ba..8990bef0cf7e3669abd121690690450d23872859 100644 (file)
@@ -267,22 +267,33 @@ static struct tda18271_map tda18271_ir_measure[] = {
 
 /*---------------------------------------------------------------------*/
 
-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;
@@ -290,56 +301,65 @@ static void tda18271_lookup_pll_map(struct tda18271_pll_map *map,
        }
        *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;
 }
 
 /*