aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/tuners/r820t.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2013-04-07 17:33:13 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-04-16 20:22:41 -0400
commit50786ddfa8efef696ec4f72460874f3b46dc2401 (patch)
tree05e48b2240885235c44de9ff76740b1c8f40176f /drivers/media/tuners/r820t.c
parentf8fde0e045aeac4417b09bef01b3ada74a4cbc80 (diff)
[media] r820t: Set gain mode to auto
This tuner works with 2 modes: automatic gain mode and manual gain mode. Put it into automatic mode, as we currently don't have any API for manual gain adjustment. The logic to allow setting the manual mode is there, as it is just a few extra code. This way, if/when we latter add support for setting the gain mode, the code is already there. Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com> Tested-by: Antti Palosaari <crope@iki.fi>
Diffstat (limited to 'drivers/media/tuners/r820t.c')
-rw-r--r--drivers/media/tuners/r820t.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/drivers/media/tuners/r820t.c b/drivers/media/tuners/r820t.c
index ed9cd6569548..0fa355d1737c 100644
--- a/drivers/media/tuners/r820t.c
+++ b/drivers/media/tuners/r820t.c
@@ -321,6 +321,20 @@ static int r820t_xtal_capacitor[][2] = {
321}; 321};
322 322
323/* 323/*
324 * measured with a Racal 6103E GSM test set at 928 MHz with -60 dBm
325 * input power, for raw results see:
326 * http://steve-m.de/projects/rtl-sdr/gain_measurement/r820t/
327 */
328
329static const int r820t_lna_gain_steps[] = {
330 0, 9, 13, 40, 38, 13, 31, 22, 26, 31, 26, 14, 19, 5, 35, 13
331};
332
333static const int r820t_mixer_gain_steps[] = {
334 0, 5, 10, 10, 19, 9, 10, 25, 17, 10, 8, 16, 13, 6, 3, -8
335};
336
337/*
324 * I2C read/write code and shadow registers logic 338 * I2C read/write code and shadow registers logic
325 */ 339 */
326static void shadow_store(struct r820t_priv *priv, u8 reg, const u8 *val, 340static void shadow_store(struct r820t_priv *priv, u8 reg, const u8 *val,
@@ -1094,6 +1108,78 @@ static int r820t_read_gain(struct r820t_priv *priv)
1094 return ((data[3] & 0x0f) << 1) + ((data[3] & 0xf0) >> 4); 1108 return ((data[3] & 0x0f) << 1) + ((data[3] & 0xf0) >> 4);
1095} 1109}
1096 1110
1111static int r820t_set_gain_mode(struct r820t_priv *priv,
1112 bool set_manual_gain,
1113 int gain)
1114{
1115 int rc;
1116
1117 if (set_manual_gain) {
1118 int i, total_gain = 0;
1119 uint8_t mix_index = 0, lna_index = 0;
1120 u8 data[4];
1121
1122 /* LNA auto off */
1123 rc = r820t_write_reg_mask(priv, 0x05, 0x10, 0x10);
1124 if (rc < 0)
1125 return rc;
1126
1127 /* Mixer auto off */
1128 rc = r820t_write_reg_mask(priv, 0x07, 0, 0x10);
1129 if (rc < 0)
1130 return rc;
1131
1132 rc = r820_read(priv, 0x00, data, sizeof(data));
1133 if (rc < 0)
1134 return rc;
1135
1136 /* set fixed VGA gain for now (16.3 dB) */
1137 rc = r820t_write_reg_mask(priv, 0x0c, 0x08, 0x9f);
1138 if (rc < 0)
1139 return rc;
1140
1141 for (i = 0; i < 15; i++) {
1142 if (total_gain >= gain)
1143 break;
1144
1145 total_gain += r820t_lna_gain_steps[++lna_index];
1146
1147 if (total_gain >= gain)
1148 break;
1149
1150 total_gain += r820t_mixer_gain_steps[++mix_index];
1151 }
1152
1153 /* set LNA gain */
1154 rc = r820t_write_reg_mask(priv, 0x05, lna_index, 0x0f);
1155 if (rc < 0)
1156 return rc;
1157
1158 /* set Mixer gain */
1159 rc = r820t_write_reg_mask(priv, 0x07, mix_index, 0x0f);
1160 if (rc < 0)
1161 return rc;
1162 } else {
1163 /* LNA */
1164 rc = r820t_write_reg_mask(priv, 0x05, 0, 0xef);
1165 if (rc < 0)
1166 return rc;
1167
1168 /* Mixer */
1169 rc = r820t_write_reg_mask(priv, 0x07, 0x10, 0xef);
1170 if (rc < 0)
1171 return rc;
1172
1173 /* set fixed VGA gain for now (26.5 dB) */
1174 rc = r820t_write_reg_mask(priv, 0x0c, 0x0b, 0x9f);
1175 if (rc < 0)
1176 return rc;
1177 }
1178
1179 return 0;
1180}
1181
1182
1097static int generic_set_freq(struct dvb_frontend *fe, 1183static int generic_set_freq(struct dvb_frontend *fe,
1098 u32 freq /* in HZ */, 1184 u32 freq /* in HZ */,
1099 unsigned bw, 1185 unsigned bw,
@@ -1121,6 +1207,11 @@ static int generic_set_freq(struct dvb_frontend *fe,
1121 rc = r820t_set_mux(priv, lo_freq); 1207 rc = r820t_set_mux(priv, lo_freq);
1122 if (rc < 0) 1208 if (rc < 0)
1123 goto err; 1209 goto err;
1210
1211 rc = r820t_set_gain_mode(priv, true, 0);
1212 if (rc < 0)
1213 goto err;
1214
1124 rc = r820t_set_pll(priv, lo_freq); 1215 rc = r820t_set_pll(priv, lo_freq);
1125 if (rc < 0 || !priv->has_lock) 1216 if (rc < 0 || !priv->has_lock)
1126 goto err; 1217 goto err;