From 2158e5090b5cc99ba05b43657a35d567cf077fe3 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Fri, 13 Aug 2010 03:49:24 -0300 Subject: V4L/DVB: af9013: add support for tda18218 silicon tuner Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb/frontends/af9013.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'drivers/media/dvb/frontends/af9013.c') diff --git a/drivers/media/dvb/frontends/af9013.c b/drivers/media/dvb/frontends/af9013.c index dac917f7bb7f..a780c32ebce4 100644 --- a/drivers/media/dvb/frontends/af9013.c +++ b/drivers/media/dvb/frontends/af9013.c @@ -486,6 +486,19 @@ static int af9013_set_freq_ctrl(struct af9013_state *state, fe_bandwidth_t bw) if_sample_freq = 4300000; /* 4.3 MHz */ break; } + } else if (state->config.tuner == AF9013_TUNER_TDA18218) { + switch (bw) { + case BANDWIDTH_6_MHZ: + if_sample_freq = 3000000; /* 3 MHz */ + break; + case BANDWIDTH_7_MHZ: + if_sample_freq = 3500000; /* 3.5 MHz */ + break; + case BANDWIDTH_8_MHZ: + default: + if_sample_freq = 4000000; /* 4 MHz */ + break; + } } while (if_sample_freq > (adc_freq / 2)) @@ -1393,6 +1406,7 @@ static int af9013_init(struct dvb_frontend *fe) init = tuner_init_mt2060_2; break; case AF9013_TUNER_TDA18271: + case AF9013_TUNER_TDA18218: len = ARRAY_SIZE(tuner_init_tda18271); init = tuner_init_tda18271; break; -- cgit v1.2.3 From a4f31d0da5c6807a0f5dfc7d285d8d4bdaa1e36e Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Thu, 9 Sep 2010 14:53:59 -0300 Subject: V4L/DVB: af9013: add support for MaxLinear MxL5007T tuner Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb/frontends/af9013.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/media/dvb/frontends/af9013.c') diff --git a/drivers/media/dvb/frontends/af9013.c b/drivers/media/dvb/frontends/af9013.c index a780c32ebce4..59fe5450a53e 100644 --- a/drivers/media/dvb/frontends/af9013.c +++ b/drivers/media/dvb/frontends/af9013.c @@ -1381,6 +1381,7 @@ static int af9013_init(struct dvb_frontend *fe) break; case AF9013_TUNER_MXL5005D: case AF9013_TUNER_MXL5005R: + case AF9013_TUNER_MXL5007T: len = ARRAY_SIZE(tuner_init_mxl5005); init = tuner_init_mxl5005; break; -- cgit v1.2.3 From 9b22edd4b0f3520bc1279338d52dc63e76852bef Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Sun, 12 Sep 2010 20:48:58 -0300 Subject: V4L/DVB: af9013: optimize code size Optimize af9013_set_coeff(). Move configuration values to own table. Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb/frontends/af9013.c | 194 +++++++---------------------------- 1 file changed, 36 insertions(+), 158 deletions(-) (limited to 'drivers/media/dvb/frontends/af9013.c') diff --git a/drivers/media/dvb/frontends/af9013.c b/drivers/media/dvb/frontends/af9013.c index 59fe5450a53e..25c5124bfc59 100644 --- a/drivers/media/dvb/frontends/af9013.c +++ b/drivers/media/dvb/frontends/af9013.c @@ -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; } -- cgit v1.2.3 From edb709b61abd3ba475e59d1ad81aab21ad025db6 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Wed, 6 Oct 2010 21:35:20 -0300 Subject: [media] af9013: optimize code size Precalculate coefficients register values. This reduces text size around 300 bytes. Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb/frontends/af9013.c | 37 ++++++------------------------------ 1 file changed, 6 insertions(+), 31 deletions(-) (limited to 'drivers/media/dvb/frontends/af9013.c') diff --git a/drivers/media/dvb/frontends/af9013.c b/drivers/media/dvb/frontends/af9013.c index 25c5124bfc59..6a205e68fde7 100644 --- a/drivers/media/dvb/frontends/af9013.c +++ b/drivers/media/dvb/frontends/af9013.c @@ -220,8 +220,7 @@ 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, i, found; - u8 buf[24]; + int ret, i, j, found; deb_info("%s: adc_clock:%d bw:%d\n", __func__, state->config.adc_clock, bw); @@ -240,37 +239,13 @@ static int af9013_set_coeff(struct af9013_state *state, fe_bandwidth_t bw) goto error; } - 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); + deb_info("%s: coeff: ", __func__); + debug_dump(coeff_table[i].val, sizeof(coeff_table[i].val), deb_info); /* program */ - for (i = 0; i < sizeof(buf); i++) { - ret = af9013_write_reg(state, 0xae00 + i, buf[i]); + for (j = 0; j < sizeof(coeff_table[i].val); j++) { + ret = af9013_write_reg(state, 0xae00 + j, + coeff_table[i].val[j]); if (ret) break; } -- cgit v1.2.3 From 9e35cd222bc913f34b8f69e2b41daa7aa041d79a Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Thu, 7 Oct 2010 16:34:55 -0300 Subject: [media] af9013: cache some reg values to reduce reg reads Demod + tuner specific RF AGC and IF AGC limit values are read from demod memory in every signal strength query. Cache those to reduce I2C traffic. Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb/frontends/af9013.c | 55 +++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 23 deletions(-) (limited to 'drivers/media/dvb/frontends/af9013.c') diff --git a/drivers/media/dvb/frontends/af9013.c b/drivers/media/dvb/frontends/af9013.c index 6a205e68fde7..e2a95c07bab4 100644 --- a/drivers/media/dvb/frontends/af9013.c +++ b/drivers/media/dvb/frontends/af9013.c @@ -42,6 +42,8 @@ struct af9013_state { struct af9013_config config; + /* tuner/demod RF and IF AGC limits used for signal strength calc */ + u8 signal_strength_en, rf_50, rf_80, if_50, if_80; u16 signal_strength; u32 ber; u32 ucblocks; @@ -963,45 +965,31 @@ static int af9013_update_signal_strength(struct dvb_frontend *fe) { struct af9013_state *state = fe->demodulator_priv; int ret; - u8 tmp0; - u8 rf_gain, rf_50, rf_80, if_gain, if_50, if_80; + u8 rf_gain, if_gain; int signal_strength; deb_info("%s\n", __func__); - state->signal_strength = 0; - - ret = af9013_read_reg_bits(state, 0x9bee, 0, 1, &tmp0); - if (ret) - goto error; - if (tmp0) { - ret = af9013_read_reg(state, 0x9bbd, &rf_50); - if (ret) - goto error; - ret = af9013_read_reg(state, 0x9bd0, &rf_80); - if (ret) - goto error; - ret = af9013_read_reg(state, 0x9be2, &if_50); - if (ret) - goto error; - ret = af9013_read_reg(state, 0x9be4, &if_80); - if (ret) - goto error; + if (state->signal_strength_en) { ret = af9013_read_reg(state, 0xd07c, &rf_gain); if (ret) goto error; ret = af9013_read_reg(state, 0xd07d, &if_gain); if (ret) goto error; - signal_strength = (0xffff / (9 * (rf_50 + if_50) - \ - 11 * (rf_80 + if_80))) * (10 * (rf_gain + if_gain) - \ - 11 * (rf_80 + if_80)); + signal_strength = (0xffff / \ + (9 * (state->rf_50 + state->if_50) - \ + 11 * (state->rf_80 + state->if_80))) * \ + (10 * (rf_gain + if_gain) - \ + 11 * (state->rf_80 + state->if_80)); if (signal_strength < 0) signal_strength = 0; else if (signal_strength > 0xffff) signal_strength = 0xffff; state->signal_strength = signal_strength; + } else { + state->signal_strength = 0; } error: @@ -1306,6 +1294,27 @@ static int af9013_init(struct dvb_frontend *fe) if (ret) goto error; + /* read values needed for signal strength calculation */ + ret = af9013_read_reg_bits(state, 0x9bee, 0, 1, + &state->signal_strength_en); + if (ret) + goto error; + + if (state->signal_strength_en) { + ret = af9013_read_reg(state, 0x9bbd, &state->rf_50); + if (ret) + goto error; + ret = af9013_read_reg(state, 0x9bd0, &state->rf_80); + if (ret) + goto error; + ret = af9013_read_reg(state, 0x9be2, &state->if_50); + if (ret) + goto error; + ret = af9013_read_reg(state, 0x9be4, &state->if_80); + if (ret) + goto error; + } + error: return ret; } -- cgit v1.2.3