Correct the signal strength calculation.

The current signal strength calculation does not consider the
baseband power and the compensation gain. Since the dvb callback
only takes unsigned int, the return value is always positive. The
application needs to negate the value if needed.

Test:

Set the signal generator to -30dbm, plus the cable loss and connector loss.
The result is 32dbm.

SPACECAST2# dvbsnoop -s signal -pd 9
dvbsnoop V1.4.50 -- http://dvbsnoop.sourceforge.net/
   DEMUX : /dev/dvb/adapter0/demux0
   DVR   : /dev/dvb/adapter0/dvr0
   FRONTEND: /dev/dvb/adapter0/frontend0

---------------------------------------------------------
Transponder/Frequency signal strength statistics...
Capabilities: BER: 1  SNR: 1  SIG: 1  STAT: 1  UBLK: 1
---------------------------------------------------------
cycle: 1  d_time: 0.001 s  Sig: 32  SNR: 14  BER: 0  UBLK: 0  Stat: 0x1f [SIG CARR VIT SYNC LOCK ]
cycle: 2  d_time: 0.013 s  Sig: 32  SNR: 14  BER: 0  UBLK: 0  Stat: 0x1f [SIG CARR VIT SYNC LOCK ]
cycle: 3  d_time: 0.012 s  Sig: 32  SNR: 14  BER: 0  UBLK: 0  Stat: 0x1f [SIG CARR VIT SYNC LOCK ]
cycle: 4  d_time: 0.012 s  Sig: 32  SNR: 14  BER: 0  UBLK: 0  Stat: 0x1f [SIG CARR VIT SYNC LOCK ]
cycle: 5  d_time: 0.012 s  Sig: 32  SNR: 14  BER: 0  UBLK: 0  Stat: 0x1f [SIG CARR VIT SYNC LOCK ]
cycle: 6  d_time: 0.013 s  Sig: 32  SNR: 14  BER: 0  UBLK: 0  Stat: 0x1f [SIG CARR VIT SYNC LOCK ]

Google-Bug-Id: 19432272
Change-Id: I7d5c83c1a89a1b16d57e411374d5c13bd55c0f98
diff --git a/drivers/media/dvb/frontends/dvbsky_m88rs6000.c b/drivers/media/dvb/frontends/dvbsky_m88rs6000.c
index f6c3b25..f58bcea 100644
--- a/drivers/media/dvb/frontends/dvbsky_m88rs6000.c
+++ b/drivers/media/dvb/frontends/dvbsky_m88rs6000.c
@@ -353,12 +353,36 @@
 	return 0;
 }
 
-static int m88rs6000_read_signal_strength(struct dvb_frontend *fe,
-						u16 *signal_strength)
+static int m88rs6000_tuner_get_gain(struct dvb_frontend *fe, u16 *gain)
 {
+	static u32 bb_list_dBm_negated[16][16] =
+	{
+		{5000, 4999, 4397, 4044, 3795, 3601, 3442, 3309, 3193, 3090, 2999, 2916, 2840, 2771, 2706, 2647},
+		{2590, 2538, 2488, 2441, 2397, 2354, 2314, 2275, 2238, 2203, 2169, 2136, 2104, 2074, 2044, 2016},
+		{1988, 1962, 1936, 1911, 1886, 1862, 1839, 1817, 1795, 1773, 1752, 1732, 1712, 1692, 1673, 1655},
+		{1636, 1618, 1601, 1584, 1567, 1550, 1534, 1518, 1502, 1487, 1472, 1457, 1442, 1428, 1414, 1400},
+		{1386, 1373, 1360, 1347, 1334, 1321, 1309, 1296, 1284, 1272, 1260, 1249, 1237, 1226, 1215, 1203},
+		{1193, 1182, 1171, 1161, 1150, 1140, 1130, 1120, 1110, 1100, 1090, 1081, 1071, 1062, 1052, 1043},
+		{1034, 1025, 1016, 1007,  999,  990,  982,  973,  965,  956,  948,  940,  932,  924,  916,  908},
+		{ 900,  893,  885,  877,  870,  862,  855,  848,  840,  833,  826,  819,  812,  805,  798,  791},
+		{ 784,  778,  771,  764,  758,  751,  745,  738,  732,  725,  719,  713,  706,  700,  694,  688},
+		{ 682,  676,  670,  664,  658,  652,  647,  641,  635,  629,  624,  618,  612,  607,  601,  596},
+		{ 590,  585,  580,  574,  569,  564,  558,  553,  548,  543,  538,  533,  528,  523,  518,  513},
+		{ 508,  503,  498,  493,  488,  483,  479,  474,  469,  464,  460,  455,  450,  446,  441,  437},
+		{ 432,  428,  423,  419,  414,  410,  405,  401,  397,  392,  388,  384,  379,  375,  371,  367},
+		{ 363,  358,  354,  350,  346,  342,  338,  334,  330,  326,  322,  318,  314,  310,  306,  302},
+		{ 298,  294,  290,  287,  283,  279,  275,  271,  268,  264,  260,  257,  253,  249,  246,  242},
+		{ 238,  235,  231,  227,  224,  220,  217,  213,  210,  206,  203,  199,  196,  192,  189,  186}
+	};
+
 	struct m88rs6000_state *state = fe->demodulator_priv;
+	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 
 	int val;
+	u32 bb_power = 0;
+	u32 total_gain = 8000;
+	u32 delta = 0;
+	u32 freq_MHz;
 
 	//u32  RF_GS = 290, IF_GS = 290, BB_GS = 290;
 	u32  PGA2_cri_GS = 46, PGA2_crf_GS = 290, TIA_GS = 290;
@@ -425,8 +449,44 @@
 
 	PGA2G = PGA2_cri * PGA2_cri_GS + PGA2_crf * PGA2_crf_GS;
 
-	*signal_strength = RFG + IFG - TIAG + BBG + PGA2G;
+	total_gain = RFG + IFG - TIAG + BBG + PGA2G;
 	
+	freq_MHz = (c->frequency + 500) / 1000;
+	if(freq_MHz > 1750)
+	{
+		delta = 1400;
+	}
+	else if(freq_MHz > 1350)
+	{
+		delta = 1200;
+	}
+	else
+	{
+		delta = 1300;
+	}
+
+	val = m88rs6000_tuner_readreg(state, 0x96);
+	bb_power = bb_list_dBm_negated[(val >> 4) & 0x0f][val & 0x0f];
+
+	val = total_gain + bb_power;
+	*gain = val < delta ? 0 : val - delta;
+
+	return 0;
+}
+
+
+static int m88rs6000_read_signal_strength(struct dvb_frontend *fe,
+						u16 *signal_strength)
+{
+	u16 gain = 0;
+
+	fe_status_t status;
+
+	int ret = m88rs6000_tuner_get_gain(fe, &gain);
+	if(ret) return ret;
+
+	*signal_strength = gain/100;
+
 	return 0;
 }