Commit 9b22edd4 authored by Antti Palosaari's avatar Antti Palosaari Committed by Mauro Carvalho Chehab

V4L/DVB: af9013: optimize code size

Optimize af9013_set_coeff(). Move configuration values to own table.
Signed-off-by: default avatarAntti Palosaari <crope@iki.fi>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent d3bb73de
......@@ -220,173 +220,50 @@ static u32 af913_div(u32 a, u32 b, u32 x)
static int af9013_set_coeff(struct af9013_state *state, fe_bandwidth_t bw)
{
int ret = 0;
u8 i = 0;
int ret, i, found;
u8 buf[24];
u32 uninitialized_var(ns_coeff1_2048nu);
u32 uninitialized_var(ns_coeff1_8191nu);
u32 uninitialized_var(ns_coeff1_8192nu);
u32 uninitialized_var(ns_coeff1_8193nu);
u32 uninitialized_var(ns_coeff2_2k);
u32 uninitialized_var(ns_coeff2_8k);
deb_info("%s: adc_clock:%d bw:%d\n", __func__,
state->config.adc_clock, bw);
switch (state->config.adc_clock) {
case 28800: /* 28.800 MHz */
switch (bw) {
case BANDWIDTH_6_MHZ:
ns_coeff1_2048nu = 0x01e79e7a;
ns_coeff1_8191nu = 0x0079eb6e;
ns_coeff1_8192nu = 0x0079e79e;
ns_coeff1_8193nu = 0x0079e3cf;
ns_coeff2_2k = 0x00f3cf3d;
ns_coeff2_8k = 0x003cf3cf;
break;
case BANDWIDTH_7_MHZ:
ns_coeff1_2048nu = 0x0238e38e;
ns_coeff1_8191nu = 0x008e3d55;
ns_coeff1_8192nu = 0x008e38e4;
ns_coeff1_8193nu = 0x008e3472;
ns_coeff2_2k = 0x011c71c7;
ns_coeff2_8k = 0x00471c72;
break;
case BANDWIDTH_8_MHZ:
ns_coeff1_2048nu = 0x028a28a3;
ns_coeff1_8191nu = 0x00a28f3d;
ns_coeff1_8192nu = 0x00a28a29;
ns_coeff1_8193nu = 0x00a28514;
ns_coeff2_2k = 0x01451451;
ns_coeff2_8k = 0x00514514;
break;
default:
ret = -EINVAL;
}
break;
case 20480: /* 20.480 MHz */
switch (bw) {
case BANDWIDTH_6_MHZ:
ns_coeff1_2048nu = 0x02adb6dc;
ns_coeff1_8191nu = 0x00ab7313;
ns_coeff1_8192nu = 0x00ab6db7;
ns_coeff1_8193nu = 0x00ab685c;
ns_coeff2_2k = 0x0156db6e;
ns_coeff2_8k = 0x0055b6dc;
break;
case BANDWIDTH_7_MHZ:
ns_coeff1_2048nu = 0x03200001;
ns_coeff1_8191nu = 0x00c80640;
ns_coeff1_8192nu = 0x00c80000;
ns_coeff1_8193nu = 0x00c7f9c0;
ns_coeff2_2k = 0x01900000;
ns_coeff2_8k = 0x00640000;
break;
case BANDWIDTH_8_MHZ:
ns_coeff1_2048nu = 0x03924926;
ns_coeff1_8191nu = 0x00e4996e;
ns_coeff1_8192nu = 0x00e49249;
ns_coeff1_8193nu = 0x00e48b25;
ns_coeff2_2k = 0x01c92493;
ns_coeff2_8k = 0x00724925;
break;
default:
ret = -EINVAL;
}
break;
case 28000: /* 28.000 MHz */
switch (bw) {
case BANDWIDTH_6_MHZ:
ns_coeff1_2048nu = 0x01f58d10;
ns_coeff1_8191nu = 0x007d672f;
ns_coeff1_8192nu = 0x007d6344;
ns_coeff1_8193nu = 0x007d5f59;
ns_coeff2_2k = 0x00fac688;
ns_coeff2_8k = 0x003eb1a2;
break;
case BANDWIDTH_7_MHZ:
ns_coeff1_2048nu = 0x02492492;
ns_coeff1_8191nu = 0x00924db7;
ns_coeff1_8192nu = 0x00924925;
ns_coeff1_8193nu = 0x00924492;
ns_coeff2_2k = 0x01249249;
ns_coeff2_8k = 0x00492492;
/* lookup coeff from table */
for (i = 0, found = 0; i < ARRAY_SIZE(coeff_table); i++) {
if (coeff_table[i].adc_clock == state->config.adc_clock &&
coeff_table[i].bw == bw) {
found = 1;
break;
case BANDWIDTH_8_MHZ:
ns_coeff1_2048nu = 0x029cbc15;
ns_coeff1_8191nu = 0x00a7343f;
ns_coeff1_8192nu = 0x00a72f05;
ns_coeff1_8193nu = 0x00a729cc;
ns_coeff2_2k = 0x014e5e0a;
ns_coeff2_8k = 0x00539783;
break;
default:
ret = -EINVAL;
}
break;
case 25000: /* 25.000 MHz */
switch (bw) {
case BANDWIDTH_6_MHZ:
ns_coeff1_2048nu = 0x0231bcb5;
ns_coeff1_8191nu = 0x008c7391;
ns_coeff1_8192nu = 0x008c6f2d;
ns_coeff1_8193nu = 0x008c6aca;
ns_coeff2_2k = 0x0118de5b;
ns_coeff2_8k = 0x00463797;
break;
case BANDWIDTH_7_MHZ:
ns_coeff1_2048nu = 0x028f5c29;
ns_coeff1_8191nu = 0x00a3dc29;
ns_coeff1_8192nu = 0x00a3d70a;
ns_coeff1_8193nu = 0x00a3d1ec;
ns_coeff2_2k = 0x0147ae14;
ns_coeff2_8k = 0x0051eb85;
break;
case BANDWIDTH_8_MHZ:
ns_coeff1_2048nu = 0x02ecfb9d;
ns_coeff1_8191nu = 0x00bb44c1;
ns_coeff1_8192nu = 0x00bb3ee7;
ns_coeff1_8193nu = 0x00bb390d;
ns_coeff2_2k = 0x01767dce;
ns_coeff2_8k = 0x005d9f74;
break;
default:
ret = -EINVAL;
}
break;
default:
err("invalid xtal");
return -EINVAL;
}
if (ret) {
err("invalid bandwidth");
return ret;
if (!found) {
err("invalid bw or clock");
ret = -EINVAL;
goto error;
}
buf[i++] = (u8) ((ns_coeff1_2048nu & 0x03000000) >> 24);
buf[i++] = (u8) ((ns_coeff1_2048nu & 0x00ff0000) >> 16);
buf[i++] = (u8) ((ns_coeff1_2048nu & 0x0000ff00) >> 8);
buf[i++] = (u8) ((ns_coeff1_2048nu & 0x000000ff));
buf[i++] = (u8) ((ns_coeff2_2k & 0x01c00000) >> 22);
buf[i++] = (u8) ((ns_coeff2_2k & 0x003fc000) >> 14);
buf[i++] = (u8) ((ns_coeff2_2k & 0x00003fc0) >> 6);
buf[i++] = (u8) ((ns_coeff2_2k & 0x0000003f));
buf[i++] = (u8) ((ns_coeff1_8191nu & 0x03000000) >> 24);
buf[i++] = (u8) ((ns_coeff1_8191nu & 0x00ffc000) >> 16);
buf[i++] = (u8) ((ns_coeff1_8191nu & 0x0000ff00) >> 8);
buf[i++] = (u8) ((ns_coeff1_8191nu & 0x000000ff));
buf[i++] = (u8) ((ns_coeff1_8192nu & 0x03000000) >> 24);
buf[i++] = (u8) ((ns_coeff1_8192nu & 0x00ffc000) >> 16);
buf[i++] = (u8) ((ns_coeff1_8192nu & 0x0000ff00) >> 8);
buf[i++] = (u8) ((ns_coeff1_8192nu & 0x000000ff));
buf[i++] = (u8) ((ns_coeff1_8193nu & 0x03000000) >> 24);
buf[i++] = (u8) ((ns_coeff1_8193nu & 0x00ffc000) >> 16);
buf[i++] = (u8) ((ns_coeff1_8193nu & 0x0000ff00) >> 8);
buf[i++] = (u8) ((ns_coeff1_8193nu & 0x000000ff));
buf[i++] = (u8) ((ns_coeff2_8k & 0x01c00000) >> 22);
buf[i++] = (u8) ((ns_coeff2_8k & 0x003fc000) >> 14);
buf[i++] = (u8) ((ns_coeff2_8k & 0x00003fc0) >> 6);
buf[i++] = (u8) ((ns_coeff2_8k & 0x0000003f));
buf[0] = (u8) ((coeff_table[i].ns_coeff1_2048nu & 0x03000000) >> 24);
buf[1] = (u8) ((coeff_table[i].ns_coeff1_2048nu & 0x00ff0000) >> 16);
buf[2] = (u8) ((coeff_table[i].ns_coeff1_2048nu & 0x0000ff00) >> 8);
buf[3] = (u8) ((coeff_table[i].ns_coeff1_2048nu & 0x000000ff));
buf[4] = (u8) ((coeff_table[i].ns_coeff2_2k & 0x01c00000) >> 22);
buf[5] = (u8) ((coeff_table[i].ns_coeff2_2k & 0x003fc000) >> 14);
buf[6] = (u8) ((coeff_table[i].ns_coeff2_2k & 0x00003fc0) >> 6);
buf[7] = (u8) ((coeff_table[i].ns_coeff2_2k & 0x0000003f));
buf[8] = (u8) ((coeff_table[i].ns_coeff1_8191nu & 0x03000000) >> 24);
buf[9] = (u8) ((coeff_table[i].ns_coeff1_8191nu & 0x00ffc000) >> 16);
buf[10] = (u8) ((coeff_table[i].ns_coeff1_8191nu & 0x0000ff00) >> 8);
buf[11] = (u8) ((coeff_table[i].ns_coeff1_8191nu & 0x000000ff));
buf[12] = (u8) ((coeff_table[i].ns_coeff1_8192nu & 0x03000000) >> 24);
buf[13] = (u8) ((coeff_table[i].ns_coeff1_8192nu & 0x00ffc000) >> 16);
buf[14] = (u8) ((coeff_table[i].ns_coeff1_8192nu & 0x0000ff00) >> 8);
buf[15] = (u8) ((coeff_table[i].ns_coeff1_8192nu & 0x000000ff));
buf[16] = (u8) ((coeff_table[i].ns_coeff1_8193nu & 0x03000000) >> 24);
buf[17] = (u8) ((coeff_table[i].ns_coeff1_8193nu & 0x00ffc000) >> 16);
buf[18] = (u8) ((coeff_table[i].ns_coeff1_8193nu & 0x0000ff00) >> 8);
buf[19] = (u8) ((coeff_table[i].ns_coeff1_8193nu & 0x000000ff));
buf[20] = (u8) ((coeff_table[i].ns_coeff2_8k & 0x01c00000) >> 22);
buf[21] = (u8) ((coeff_table[i].ns_coeff2_8k & 0x003fc000) >> 14);
buf[22] = (u8) ((coeff_table[i].ns_coeff2_8k & 0x00003fc0) >> 6);
buf[23] = (u8) ((coeff_table[i].ns_coeff2_8k & 0x0000003f));
deb_info("%s: coeff:", __func__);
debug_dump(buf, sizeof(buf), deb_info);
......@@ -398,6 +275,7 @@ static int af9013_set_coeff(struct af9013_state *state, fe_bandwidth_t bw)
break;
}
error:
return ret;
}
......
......@@ -60,6 +60,49 @@ struct snr_table {
u8 snr;
};
struct coeff {
u32 adc_clock;
fe_bandwidth_t bw;
u32 ns_coeff1_2048nu;
u32 ns_coeff1_8191nu;
u32 ns_coeff1_8192nu;
u32 ns_coeff1_8193nu;
u32 ns_coeff2_2k;
u32 ns_coeff2_8k;
};
/* coeff lookup table */
static struct coeff coeff_table[] = {
/* 28.800 MHz */
{ 28800, BANDWIDTH_6_MHZ, 0x01e79e7a, 0x0079eb6e, 0x0079e79e,
0x0079e3cf, 0x00f3cf3d, 0x003cf3cf },
{ 28800, BANDWIDTH_7_MHZ, 0x0238e38e, 0x008e3d55, 0x008e38e4,
0x008e3472, 0x011c71c7, 0x00471c72 },
{ 28800, BANDWIDTH_8_MHZ, 0x028a28a3, 0x00a28f3d, 0x00a28a29,
0x00a28514, 0x01451451, 0x00514514 },
/* 20.480 MHz */
{ 20480, BANDWIDTH_6_MHZ, 0x02adb6dc, 0x00ab7313, 0x00ab6db7,
0x00ab685c, 0x0156db6e, 0x0055b6dc },
{ 20480, BANDWIDTH_7_MHZ, 0x03200001, 0x00c80640, 0x00c80000,
0x00c7f9c0, 0x01900000, 0x00640000 },
{ 20480, BANDWIDTH_8_MHZ, 0x03924926, 0x00e4996e, 0x00e49249,
0x00e48b25, 0x01c92493, 0x00724925 },
/* 28.000 MHz */
{ 28000, BANDWIDTH_6_MHZ, 0x01f58d10, 0x007d672f, 0x007d6344,
0x007d5f59, 0x00fac688, 0x003eb1a2 },
{ 28000, BANDWIDTH_7_MHZ, 0x02492492, 0x00924db7, 0x00924925,
0x00924492, 0x01249249, 0x00492492 },
{ 28000, BANDWIDTH_8_MHZ, 0x029cbc15, 0x00a7343f, 0x00a72f05,
0x00a729cc, 0x014e5e0a, 0x00539783 },
/* 25.000 MHz */
{ 25000, BANDWIDTH_6_MHZ, 0x0231bcb5, 0x008c7391, 0x008c6f2d,
0x008c6aca, 0x0118de5b, 0x00463797 },
{ 25000, BANDWIDTH_7_MHZ, 0x028f5c29, 0x00a3dc29, 0x00a3d70a,
0x00a3d1ec, 0x0147ae14, 0x0051eb85 },
{ 25000, BANDWIDTH_8_MHZ, 0x02ecfb9d, 0x00bb44c1, 0x00bb3ee7,
0x00bb390d, 0x01767dce, 0x005d9f74 },
};
/* QPSK SNR lookup table */
static struct snr_table qpsk_snr_table[] = {
{ 0x0b4771, 0 },
......
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