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

V4L/DVB (7633): au8522: consolidate mse2snr_lookup functions

consolidate au8522_qam256_mse2snr_lookup, au8522_qam64_mse2snr_lookup and
au8522_vsb_mse2snr_lookup into a single function, au8522_mse2snr_lookup.

Pass the mse2snr table into au8522_mse2snr_lookup depending on the
modulation type.
Signed-off-by: default avatarMichael Krufky <mkrufky@linuxtv.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent f01699b4
...@@ -96,11 +96,13 @@ static int au8522_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) ...@@ -96,11 +96,13 @@ static int au8522_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
return au8522_writereg(state, 0x106, 0); return au8522_writereg(state, 0x106, 0);
} }
/* VSB SNR lookup table */ struct mse2snr_tab {
static struct {
u16 val; u16 val;
u16 data; u16 data;
} vsb_mse2snr_tab[] = { };
/* VSB SNR lookup table */
static struct mse2snr_tab vsb_mse2snr_tab[] = {
{ 0, 270 }, { 0, 270 },
{ 2, 250 }, { 2, 250 },
{ 3, 240 }, { 3, 240 },
...@@ -134,10 +136,7 @@ static struct { ...@@ -134,10 +136,7 @@ static struct {
}; };
/* QAM64 SNR lookup table */ /* QAM64 SNR lookup table */
static struct { static struct mse2snr_tab qam64_mse2snr_tab[] = {
u16 val;
u16 data;
} qam64_mse2snr_tab[] = {
{ 15, 0 }, { 15, 0 },
{ 16, 290 }, { 16, 290 },
{ 17, 288 }, { 17, 288 },
...@@ -218,10 +217,7 @@ static struct { ...@@ -218,10 +217,7 @@ static struct {
}; };
/* QAM256 SNR lookup table */ /* QAM256 SNR lookup table */
static struct { static struct mse2snr_tab qam256_mse2snr_tab[] = {
u16 val;
u16 data;
} qam256_mse2snr_tab[] = {
{ 16, 0 }, { 16, 0 },
{ 17, 400 }, { 17, 400 },
{ 18, 398 }, { 18, 398 },
...@@ -288,46 +284,14 @@ static struct { ...@@ -288,46 +284,14 @@ static struct {
{ 256, 280 }, { 256, 280 },
}; };
static int au8522_vsb_mse2snr_lookup(int mse, u16 *snr) static int au8522_mse2snr_lookup(struct mse2snr_tab *tab, int sz, int mse, u16 *snr)
{
int i, ret = -EINVAL;
dprintk("%s()\n", __func__);
for (i = 0; i < ARRAY_SIZE(vsb_mse2snr_tab); i++) {
if (mse < vsb_mse2snr_tab[i].val) {
*snr = vsb_mse2snr_tab[i].data;
ret = 0;
break;
}
}
dprintk("%s() snr=%d\n", __func__, *snr);
return ret;
}
static int au8522_qam64_mse2snr_lookup(int mse, u16 *snr)
{
int i, ret = -EINVAL;
dprintk("%s()\n", __func__);
for (i = 0; i < ARRAY_SIZE(qam64_mse2snr_tab); i++) {
if (mse < qam64_mse2snr_tab[i].val) {
*snr = qam64_mse2snr_tab[i].data;
ret = 0;
break;
}
}
dprintk("%s() snr=%d\n", __func__, *snr);
return ret;
}
static int au8522_qam256_mse2snr_lookup(int mse, u16 *snr)
{ {
int i, ret = -EINVAL; int i, ret = -EINVAL;
dprintk("%s()\n", __func__); dprintk("%s()\n", __func__);
for (i = 0; i < ARRAY_SIZE(qam256_mse2snr_tab); i++) { for (i = 0; i < sz; i++) {
if (mse < qam256_mse2snr_tab[i].val) { if (mse < tab[i].val) {
*snr = qam256_mse2snr_tab[i].data; *snr = tab[i].data;
ret = 0; ret = 0;
break; break;
} }
...@@ -588,14 +552,20 @@ static int au8522_read_snr(struct dvb_frontend *fe, u16 *snr) ...@@ -588,14 +552,20 @@ static int au8522_read_snr(struct dvb_frontend *fe, u16 *snr)
dprintk("%s()\n", __func__); dprintk("%s()\n", __func__);
if (state->current_modulation == QAM_256) if (state->current_modulation == QAM_256)
ret = au8522_qam256_mse2snr_lookup( ret = au8522_mse2snr_lookup(qam256_mse2snr_tab,
au8522_readreg(state, 0x4522), snr); ARRAY_SIZE(qam256_mse2snr_tab),
au8522_readreg(state, 0x4522),
snr);
else if (state->current_modulation == QAM_64) else if (state->current_modulation == QAM_64)
ret = au8522_qam64_mse2snr_lookup( ret = au8522_mse2snr_lookup(qam64_mse2snr_tab,
au8522_readreg(state, 0x4522), snr); ARRAY_SIZE(qam64_mse2snr_tab),
au8522_readreg(state, 0x4522),
snr);
else /* VSB_8 */ else /* VSB_8 */
ret = au8522_vsb_mse2snr_lookup( ret = au8522_mse2snr_lookup(vsb_mse2snr_tab,
au8522_readreg(state, 0x4311), snr); ARRAY_SIZE(vsb_mse2snr_tab),
au8522_readreg(state, 0x4311),
snr);
return ret; return ret;
} }
......
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