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

V4L/DVB (6727): tda18271: convert table lookup loops to functions

Signed-off-by: default avatarMichael Krufky <mkrufky@linuxtv.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent aaeccba6
...@@ -25,22 +25,10 @@ ...@@ -25,22 +25,10 @@
#include "tda18271.h" #include "tda18271.h"
#include "tda18271-priv.h" #include "tda18271-priv.h"
static int tda18271_debug; int tda18271_debug;
module_param_named(debug, tda18271_debug, int, 0644); module_param_named(debug, tda18271_debug, int, 0644);
MODULE_PARM_DESC(debug, "set debug level (info=1, map=2, reg=4 (or-able))"); MODULE_PARM_DESC(debug, "set debug level (info=1, map=2, reg=4 (or-able))");
#define dprintk(level, fmt, arg...) do {\
if (tda18271_debug & level) \
printk(KERN_DEBUG "%s: " fmt, __FUNCTION__, ##arg); } while (0)
#define DBG_INFO 1
#define DBG_MAP 2
#define DBG_REG 4
#define dbg_info(fmt, arg...) dprintk(DBG_INFO, fmt, ##arg)
#define dbg_map(fmt, arg...) dprintk(DBG_MAP, fmt, ##arg)
#define dbg_reg(fmt, arg...) dprintk(DBG_REG, fmt, ##arg)
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
#define TDA18271_ANALOG 0 #define TDA18271_ANALOG 0
...@@ -365,7 +353,7 @@ static int tda18271_tune(struct dvb_frontend *fe, ...@@ -365,7 +353,7 @@ static int tda18271_tune(struct dvb_frontend *fe,
struct tda18271_priv *priv = fe->tuner_priv; struct tda18271_priv *priv = fe->tuner_priv;
unsigned char *regs = priv->tda18271_regs; unsigned char *regs = priv->tda18271_regs;
u32 div, N = 0; u32 div, N = 0;
int i; u8 d, pd, val;
tda18271_init(fe); tda18271_init(fe);
...@@ -374,16 +362,10 @@ static int tda18271_tune(struct dvb_frontend *fe, ...@@ -374,16 +362,10 @@ static int tda18271_tune(struct dvb_frontend *fe,
/* RF tracking filter calibration */ /* RF tracking filter calibration */
/* calculate BP_Filter */ /* calculate BP_Filter */
i = 0; tda18271_calc_bp_filter(&freq, &val);
while ((tda18271_bp_filter[i].rfmax * 1000) < freq) {
if (tda18271_bp_filter[i + 1].rfmax == 0)
break;
i++;
}
dbg_map("bp filter = 0x%x, i = %d\n", tda18271_bp_filter[i].val, i);
regs[R_EP1] &= ~0x07; /* clear bp filter bits */ regs[R_EP1] &= ~0x07; /* clear bp filter bits */
regs[R_EP1] |= tda18271_bp_filter[i].val; regs[R_EP1] |= val;
tda18271_write_regs(fe, R_EP1, 1); tda18271_write_regs(fe, R_EP1, 1);
regs[R_EB4] &= 0x07; regs[R_EB4] &= 0x07;
...@@ -413,18 +395,11 @@ static int tda18271_tune(struct dvb_frontend *fe, ...@@ -413,18 +395,11 @@ static int tda18271_tune(struct dvb_frontend *fe,
break; break;
} }
i = 0; tda18271_calc_cal_pll(&N, &pd, &d);
while ((tda18271_cal_pll[i].lomax * 1000) < N) {
if (tda18271_cal_pll[i + 1].lomax == 0)
break;
i++;
}
dbg_map("cal pll, pd = 0x%x, d = 0x%x, i = %d\n",
tda18271_cal_pll[i].pd, tda18271_cal_pll[i].d, i);
regs[R_CPD] = tda18271_cal_pll[i].pd; regs[R_CPD] = pd;
div = ((tda18271_cal_pll[i].d * (N / 1000)) << 7) / 125; div = ((d * (N / 1000)) << 7) / 125;
regs[R_CD1] = 0xff & (div >> 16); regs[R_CD1] = 0xff & (div >> 16);
regs[R_CD2] = 0xff & (div >> 8); regs[R_CD2] = 0xff & (div >> 8);
regs[R_CD3] = 0xff & div; regs[R_CD3] = 0xff & div;
...@@ -440,16 +415,9 @@ static int tda18271_tune(struct dvb_frontend *fe, ...@@ -440,16 +415,9 @@ static int tda18271_tune(struct dvb_frontend *fe,
break; break;
} }
i = 0; tda18271_calc_main_pll(&N, &pd, &d);
while ((tda18271_main_pll[i].lomax * 1000) < N) {
if (tda18271_main_pll[i + 1].lomax == 0)
break;
i++;
}
dbg_map("main pll, pd = 0x%x, d = 0x%x, i = %d\n",
tda18271_main_pll[i].pd, tda18271_main_pll[i].d, i);
regs[R_MPD] = (0x7f & tda18271_main_pll[i].pd); regs[R_MPD] = (0x7f & pd);
switch (priv->mode) { switch (priv->mode) {
case TDA18271_ANALOG: case TDA18271_ANALOG:
...@@ -460,7 +428,7 @@ static int tda18271_tune(struct dvb_frontend *fe, ...@@ -460,7 +428,7 @@ static int tda18271_tune(struct dvb_frontend *fe,
break; break;
} }
div = ((tda18271_main_pll[i].d * (N / 1000)) << 7) / 125; div = ((d * (N / 1000)) << 7) / 125;
regs[R_MD1] = 0xff & (div >> 16); regs[R_MD1] = 0xff & (div >> 16);
regs[R_MD2] = 0xff & (div >> 8); regs[R_MD2] = 0xff & (div >> 8);
regs[R_MD3] = 0xff & div; regs[R_MD3] = 0xff & div;
...@@ -469,42 +437,23 @@ static int tda18271_tune(struct dvb_frontend *fe, ...@@ -469,42 +437,23 @@ 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 */
i = 0; tda18271_calc_km(&freq, &val);
while ((tda18271_km[i].rfmax * 1000) < freq) {
if (tda18271_km[i + 1].rfmax == 0)
break;
i++;
}
dbg_map("km = 0x%x, i = %d\n", tda18271_km[i].val, i);
regs[R_EB13] &= 0x83; regs[R_EB13] &= 0x83;
regs[R_EB13] |= tda18271_km[i].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 */
i = 0; tda18271_calc_rf_band(&freq, &val);
while ((tda18271_rf_band[i].rfmax * 1000) < freq) {
if (tda18271_rf_band[i + 1].rfmax == 0)
break;
i++;
}
dbg_map("rf band = 0x%x, i = %d\n", tda18271_rf_band[i].val, i);
regs[R_EP2] &= ~0xe0; /* clear rf band bits */ regs[R_EP2] &= ~0xe0; /* clear rf band bits */
regs[R_EP2] |= (tda18271_rf_band[i].val << 5); regs[R_EP2] |= (val << 5);
/* search for Gain_Taper */ /* search for Gain_Taper */
i = 0; tda18271_calc_gain_taper(&freq, &val);
while ((tda18271_gain_taper[i].rfmax * 1000) < freq) {
if (tda18271_gain_taper[i + 1].rfmax == 0)
break;
i++;
}
dbg_map("gain taper = 0x%x, i = %d\n",
tda18271_gain_taper[i].val, i);
regs[R_EP2] &= ~0x1f; /* clear gain taper bits */ regs[R_EP2] &= ~0x1f; /* clear gain taper bits */
regs[R_EP2] |= tda18271_gain_taper[i].val; regs[R_EP2] |= val;
tda18271_write_regs(fe, R_EP2, 1); tda18271_write_regs(fe, R_EP2, 1);
tda18271_write_regs(fe, R_EP1, 1); tda18271_write_regs(fe, R_EP1, 1);
...@@ -529,17 +478,11 @@ static int tda18271_tune(struct dvb_frontend *fe, ...@@ -529,17 +478,11 @@ 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 */
i = 0; tda18271_calc_rf_cal(&freq, &val);
while ((tda18271_rf_cal[i].rfmax * 1000) < freq) {
if (tda18271_rf_cal[i].rfmax == 0)
break;
i++;
}
dbg_map("rf cal = 0x%x, i = %d\n", tda18271_rf_cal[i].val, i);
/* VHF_Low band only */ /* VHF_Low band only */
if (tda18271_rf_cal[i].rfmax != 0) { if (val != 0) {
regs[R_EB14] = tda18271_rf_cal[i].val; regs[R_EB14] = val;
tda18271_write_regs(fe, R_EB14, 1); tda18271_write_regs(fe, R_EB14, 1);
} }
...@@ -579,29 +522,17 @@ static int tda18271_tune(struct dvb_frontend *fe, ...@@ -579,29 +522,17 @@ 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] */
i = 0; tda18271_calc_ir_measure(&freq, &val);
while ((tda18271_ir_measure[i].rfmax * 1000) < freq) {
if (tda18271_ir_measure[i].rfmax == 0)
break;
i++;
}
dbg_map("ir measure, i = %d\n", i);
regs[R_EP5] &= ~0x07; regs[R_EP5] &= ~0x07;
regs[R_EP5] |= tda18271_ir_measure[i].val; regs[R_EP5] |= val;
/* calculate MAIN PLL */ /* calculate MAIN PLL */
N = freq + ifc; N = freq + ifc;
i = 0; tda18271_calc_main_pll(&N, &pd, &d);
while ((tda18271_main_pll[i].lomax * 1000) < N) {
if (tda18271_main_pll[i + 1].lomax == 0)
break;
i++;
}
dbg_map("main pll, pd = 0x%x, d = 0x%x, i = %d\n",
tda18271_main_pll[i].pd, tda18271_main_pll[i].d, i);
regs[R_MPD] = (0x7f & tda18271_main_pll[i].pd); regs[R_MPD] = (0x7f & pd);
switch (priv->mode) { switch (priv->mode) {
case TDA18271_ANALOG: case TDA18271_ANALOG:
regs[R_MPD] &= ~0x08; regs[R_MPD] &= ~0x08;
...@@ -611,7 +542,7 @@ static int tda18271_tune(struct dvb_frontend *fe, ...@@ -611,7 +542,7 @@ static int tda18271_tune(struct dvb_frontend *fe,
break; break;
} }
div = ((tda18271_main_pll[i].d * (N / 1000)) << 7) / 125; div = ((d * (N / 1000)) << 7) / 125;
regs[R_MD1] = 0xff & (div >> 16); regs[R_MD1] = 0xff & (div >> 16);
regs[R_MD2] = 0xff & (div >> 8); regs[R_MD2] = 0xff & (div >> 8);
regs[R_MD3] = 0xff & div; regs[R_MD3] = 0xff & div;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#ifndef __TDA18271_PRIV_H__ #ifndef __TDA18271_PRIV_H__
#define __TDA18271_PRIV_H__ #define __TDA18271_PRIV_H__
#include <linux/kernel.h>
#include <linux/types.h> #include <linux/types.h>
#define R_ID 0x00 /* ID byte */ #define R_ID 0x00 /* ID byte */
...@@ -65,26 +66,31 @@ ...@@ -65,26 +66,31 @@
#define TDA18271_NUM_REGS 39 #define TDA18271_NUM_REGS 39
struct tda18271_pll_map { extern int tda18271_debug;
u32 lomax;
u8 pd; /* post div */ #define dprintk(level, fmt, arg...) do {\
u8 d; /* div */ if (tda18271_debug & level) \
}; printk(KERN_DEBUG "%s: " fmt, __FUNCTION__, ##arg); } while (0)
extern struct tda18271_pll_map tda18271_main_pll[]; #define DBG_INFO 1
extern struct tda18271_pll_map tda18271_cal_pll[]; #define DBG_MAP 2
#define DBG_REG 4
struct tda18271_map {
u32 rfmax; #define dbg_info(fmt, arg...) dprintk(DBG_INFO, fmt, ##arg)
u8 val; #define dbg_map(fmt, arg...) dprintk(DBG_MAP, fmt, ##arg)
}; #define dbg_reg(fmt, arg...) dprintk(DBG_REG, fmt, ##arg)
extern struct tda18271_map tda18271_bp_filter[]; /*---------------------------------------------------------------------*/
extern struct tda18271_map tda18271_km[];
extern struct tda18271_map tda18271_rf_band[]; extern void tda18271_calc_cal_pll(u32 *freq, u8 *post_div, u8 *div);
extern struct tda18271_map tda18271_gain_taper[]; extern void tda18271_calc_main_pll(u32 *freq, u8 *post_div, u8 *div);
extern struct tda18271_map tda18271_rf_cal[];
extern struct tda18271_map tda18271_ir_measure[]; extern void tda18271_calc_bp_filter(u32 *freq, u8 *val);
extern void tda18271_calc_km(u32 *freq, u8 *val);
extern void tda18271_calc_rf_band(u32 *freq, u8 *val);
extern void tda18271_calc_gain_taper(u32 *freq, u8 *val);
extern void tda18271_calc_rf_cal(u32 *freq, u8 *val);
extern void tda18271_calc_ir_measure(u32 *freq, u8 *val);
#endif /* __TDA18271_PRIV_H__ */ #endif /* __TDA18271_PRIV_H__ */
......
...@@ -20,7 +20,20 @@ ...@@ -20,7 +20,20 @@
#include "tda18271-priv.h" #include "tda18271-priv.h"
struct tda18271_pll_map tda18271_main_pll[] = { struct tda18271_pll_map {
u32 lomax;
u8 pd; /* post div */
u8 d; /* div */
};
struct tda18271_map {
u32 rfmax;
u8 val;
};
/*---------------------------------------------------------------------*/
static struct tda18271_pll_map tda18271_main_pll[] = {
{ .lomax = 32000, .pd = 0x5f, .d = 0xf0 }, { .lomax = 32000, .pd = 0x5f, .d = 0xf0 },
{ .lomax = 35000, .pd = 0x5e, .d = 0xe0 }, { .lomax = 35000, .pd = 0x5e, .d = 0xe0 },
{ .lomax = 37000, .pd = 0x5d, .d = 0xd0 }, { .lomax = 37000, .pd = 0x5d, .d = 0xd0 },
...@@ -64,7 +77,7 @@ struct tda18271_pll_map tda18271_main_pll[] = { ...@@ -64,7 +77,7 @@ struct tda18271_pll_map tda18271_main_pll[] = {
{ .lomax = 0, .pd = 0x00, .d = 0x00 }, /* end */ { .lomax = 0, .pd = 0x00, .d = 0x00 }, /* end */
}; };
struct tda18271_pll_map tda18271_cal_pll[] = { static struct tda18271_pll_map tda18271_cal_pll[] = {
{ .lomax = 33000, .pd = 0xdd, .d = 0xd0 }, { .lomax = 33000, .pd = 0xdd, .d = 0xd0 },
{ .lomax = 36000, .pd = 0xdc, .d = 0xc0 }, { .lomax = 36000, .pd = 0xdc, .d = 0xc0 },
{ .lomax = 40000, .pd = 0xdb, .d = 0xb0 }, { .lomax = 40000, .pd = 0xdb, .d = 0xb0 },
...@@ -103,7 +116,7 @@ struct tda18271_pll_map tda18271_cal_pll[] = { ...@@ -103,7 +116,7 @@ struct tda18271_pll_map tda18271_cal_pll[] = {
{ .lomax = 0, .pd = 0x00, .d = 0x00 }, /* end */ { .lomax = 0, .pd = 0x00, .d = 0x00 }, /* end */
}; };
struct tda18271_map tda18271_bp_filter[] = { static struct tda18271_map tda18271_bp_filter[] = {
{ .rfmax = 62000, .val = 0x00 }, { .rfmax = 62000, .val = 0x00 },
{ .rfmax = 84000, .val = 0x01 }, { .rfmax = 84000, .val = 0x01 },
{ .rfmax = 100000, .val = 0x02 }, { .rfmax = 100000, .val = 0x02 },
...@@ -114,7 +127,7 @@ struct tda18271_map tda18271_bp_filter[] = { ...@@ -114,7 +127,7 @@ struct tda18271_map tda18271_bp_filter[] = {
{ .rfmax = 0, .val = 0x00 }, /* end */ { .rfmax = 0, .val = 0x00 }, /* end */
}; };
struct tda18271_map tda18271_km[] = { static struct tda18271_map tda18271_km[] = {
{ .rfmax = 61100, .val = 0x74 }, { .rfmax = 61100, .val = 0x74 },
{ .rfmax = 350000, .val = 0x40 }, { .rfmax = 350000, .val = 0x40 },
{ .rfmax = 720000, .val = 0x30 }, { .rfmax = 720000, .val = 0x30 },
...@@ -122,7 +135,7 @@ struct tda18271_map tda18271_km[] = { ...@@ -122,7 +135,7 @@ struct tda18271_map tda18271_km[] = {
{ .rfmax = 0, .val = 0x00 }, /* end */ { .rfmax = 0, .val = 0x00 }, /* end */
}; };
struct tda18271_map tda18271_rf_band[] = { static struct tda18271_map tda18271_rf_band[] = {
{ .rfmax = 47900, .val = 0x00 }, { .rfmax = 47900, .val = 0x00 },
{ .rfmax = 61100, .val = 0x01 }, { .rfmax = 61100, .val = 0x01 },
/* { .rfmax = 152600, .val = 0x02 }, */ /* { .rfmax = 152600, .val = 0x02 }, */
...@@ -134,7 +147,7 @@ struct tda18271_map tda18271_rf_band[] = { ...@@ -134,7 +147,7 @@ struct tda18271_map tda18271_rf_band[] = {
{ .rfmax = 0, .val = 0x00 }, /* end */ { .rfmax = 0, .val = 0x00 }, /* end */
}; };
struct tda18271_map tda18271_gain_taper[] = { static struct tda18271_map tda18271_gain_taper[] = {
{ .rfmax = 45400, .val = 0x1f }, { .rfmax = 45400, .val = 0x1f },
{ .rfmax = 45800, .val = 0x1e }, { .rfmax = 45800, .val = 0x1e },
{ .rfmax = 46200, .val = 0x1d }, { .rfmax = 46200, .val = 0x1d },
...@@ -223,7 +236,7 @@ struct tda18271_map tda18271_gain_taper[] = { ...@@ -223,7 +236,7 @@ struct tda18271_map tda18271_gain_taper[] = {
{ .rfmax = 0, .val = 0x00 }, /* end */ { .rfmax = 0, .val = 0x00 }, /* end */
}; };
struct tda18271_map tda18271_rf_cal[] = { static struct tda18271_map tda18271_rf_cal[] = {
{ .rfmax = 41000, .val = 0x1e }, { .rfmax = 41000, .val = 0x1e },
{ .rfmax = 43000, .val = 0x30 }, { .rfmax = 43000, .val = 0x30 },
{ .rfmax = 45000, .val = 0x43 }, { .rfmax = 45000, .val = 0x43 },
...@@ -244,7 +257,7 @@ struct tda18271_map tda18271_rf_cal[] = { ...@@ -244,7 +257,7 @@ struct tda18271_map tda18271_rf_cal[] = {
{ .rfmax = 0, .val = 0x00 }, /* end */ { .rfmax = 0, .val = 0x00 }, /* end */
}; };
struct tda18271_map tda18271_ir_measure[] = { static struct tda18271_map tda18271_ir_measure[] = {
{ .rfmax = 30000, .val = 4}, { .rfmax = 30000, .val = 4},
{ .rfmax = 200000, .val = 5}, { .rfmax = 200000, .val = 5},
{ .rfmax = 600000, .val = 6}, { .rfmax = 600000, .val = 6},
...@@ -252,6 +265,83 @@ struct tda18271_map tda18271_ir_measure[] = { ...@@ -252,6 +265,83 @@ struct tda18271_map tda18271_ir_measure[] = {
{ .rfmax = 0, .val = 0}, /* end */ { .rfmax = 0, .val = 0}, /* end */
}; };
/*---------------------------------------------------------------------*/
static void tda18271_lookup_map(struct tda18271_map *map,
u32 *freq, u8 *val)
{
int i = 0;
while ((map[i].rfmax * 1000) < *freq) {
if (map[i + 1].rfmax == 0)
break;
i++;
}
*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;
i++;
}
*post_div = map[i].pd;
*div = map[i].d;
}
/*---------------------------------------------------------------------*/
void tda18271_calc_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);
}
void tda18271_calc_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);
}
void tda18271_calc_bp_filter(u32 *freq, u8 *val)
{
tda18271_lookup_map(tda18271_bp_filter, freq, val);
dbg_map("0x%02x\n", *val);
}
void tda18271_calc_km(u32 *freq, u8 *val)
{
tda18271_lookup_map(tda18271_km, freq, val);
dbg_map("0x%02x\n", *val);
}
void tda18271_calc_rf_band(u32 *freq, u8 *val)
{
tda18271_lookup_map(tda18271_rf_band, freq, val);
dbg_map("0x%02x\n", *val);
}
void tda18271_calc_gain_taper(u32 *freq, u8 *val)
{
tda18271_lookup_map(tda18271_gain_taper, freq, val);
dbg_map("0x%02x\n", *val);
}
void tda18271_calc_rf_cal(u32 *freq, u8 *val)
{
tda18271_lookup_map(tda18271_rf_cal, freq, val);
dbg_map("0x%02x\n", *val);
}
void tda18271_calc_ir_measure(u32 *freq, u8 *val)
{
tda18271_lookup_map(tda18271_ir_measure, freq, val);
dbg_map("0x%02x\n", *val);
}
/* /*
* Overrides for Emacs so that we follow Linus's tabbing style. * Overrides for Emacs so that we follow Linus's tabbing style.
* --------------------------------------------------------------------------- * ---------------------------------------------------------------------------
......
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