aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb-frontends
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2013-04-28 10:47:43 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-06-08 21:03:53 -0400
commitb5e9eb6f529b5741322d1981bb176785f115d446 (patch)
tree866c5ab35db702eeb0b43e5bfca4e0b15f4eac71 /drivers/media/dvb-frontends
parent7df272563aa3ffc201ddfe2431de9bb7456e3ea6 (diff)
[media] drxk_hard: don't re-implement log10
X-Patchwork-Delegate: mchehab@redhat.com Log10 routine is already defined at dvb_math.h and provides a good enough approximation for 100 x log10(). So, instead of reinventing the wheel, use the already existing function. While here, don't use CamelCase on the function name. Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb-frontends')
-rw-r--r--drivers/media/dvb-frontends/drxk_hard.c104
1 files changed, 8 insertions, 96 deletions
diff --git a/drivers/media/dvb-frontends/drxk_hard.c b/drivers/media/dvb-frontends/drxk_hard.c
index ec24d71e153d..41b637534ed4 100644
--- a/drivers/media/dvb-frontends/drxk_hard.c
+++ b/drivers/media/dvb-frontends/drxk_hard.c
@@ -34,6 +34,7 @@
34#include "dvb_frontend.h" 34#include "dvb_frontend.h"
35#include "drxk.h" 35#include "drxk.h"
36#include "drxk_hard.h" 36#include "drxk_hard.h"
37#include "dvb_math.h"
37 38
38static int PowerDownDVBT(struct drxk_state *state, bool setPowerMode); 39static int PowerDownDVBT(struct drxk_state *state, bool setPowerMode);
39static int PowerDownQAM(struct drxk_state *state); 40static int PowerDownQAM(struct drxk_state *state);
@@ -201,98 +202,9 @@ static inline u32 Frac28a(u32 a, u32 c)
201 return Q1; 202 return Q1;
202} 203}
203 204
204static u32 Log10Times100(u32 x) 205static inline u32 log10times100(u32 value)
205{ 206{
206 static const u8 scale = 15; 207 return (100L * intlog10(value)) >> 24;
207 static const u8 indexWidth = 5;
208 u8 i = 0;
209 u32 y = 0;
210 u32 d = 0;
211 u32 k = 0;
212 u32 r = 0;
213 /*
214 log2lut[n] = (1<<scale) * 200 * log2(1.0 + ((1.0/(1<<INDEXWIDTH)) * n))
215 0 <= n < ((1<<INDEXWIDTH)+1)
216 */
217
218 static const u32 log2lut[] = {
219 0, /* 0.000000 */
220 290941, /* 290941.300628 */
221 573196, /* 573196.476418 */
222 847269, /* 847269.179851 */
223 1113620, /* 1113620.489452 */
224 1372674, /* 1372673.576986 */
225 1624818, /* 1624817.752104 */
226 1870412, /* 1870411.981536 */
227 2109788, /* 2109787.962654 */
228 2343253, /* 2343252.817465 */
229 2571091, /* 2571091.461923 */
230 2793569, /* 2793568.696416 */
231 3010931, /* 3010931.055901 */
232 3223408, /* 3223408.452106 */
233 3431216, /* 3431215.635215 */
234 3634553, /* 3634553.498355 */
235 3833610, /* 3833610.244726 */
236 4028562, /* 4028562.434393 */
237 4219576, /* 4219575.925308 */
238 4406807, /* 4406806.721144 */
239 4590402, /* 4590401.736809 */
240 4770499, /* 4770499.491025 */
241 4947231, /* 4947230.734179 */
242 5120719, /* 5120719.018555 */
243 5291081, /* 5291081.217197 */
244 5458428, /* 5458427.996830 */
245 5622864, /* 5622864.249668 */
246 5784489, /* 5784489.488298 */
247 5943398, /* 5943398.207380 */
248 6099680, /* 6099680.215452 */
249 6253421, /* 6253420.939751 */
250 6404702, /* 6404701.706649 */
251 6553600, /* 6553600.000000 */
252 };
253
254
255 if (x == 0)
256 return 0;
257
258 /* Scale x (normalize) */
259 /* computing y in log(x/y) = log(x) - log(y) */
260 if ((x & ((0xffffffff) << (scale + 1))) == 0) {
261 for (k = scale; k > 0; k--) {
262 if (x & (((u32) 1) << scale))
263 break;
264 x <<= 1;
265 }
266 } else {
267 for (k = scale; k < 31; k++) {
268 if ((x & (((u32) (-1)) << (scale + 1))) == 0)
269 break;
270 x >>= 1;
271 }
272 }
273 /*
274 Now x has binary point between bit[scale] and bit[scale-1]
275 and 1.0 <= x < 2.0 */
276
277 /* correction for divison: log(x) = log(x/y)+log(y) */
278 y = k * ((((u32) 1) << scale) * 200);
279
280 /* remove integer part */
281 x &= ((((u32) 1) << scale) - 1);
282 /* get index */
283 i = (u8) (x >> (scale - indexWidth));
284 /* compute delta (x - a) */
285 d = x & ((((u32) 1) << (scale - indexWidth)) - 1);
286 /* compute log, multiplication (d* (..)) must be within range ! */
287 y += log2lut[i] +
288 ((d * (log2lut[i + 1] - log2lut[i])) >> (scale - indexWidth));
289 /* Conver to log10() */
290 y /= 108853; /* (log2(10) << scale) */
291 r = (y >> 1);
292 /* rounding */
293 if (y & ((u32) 1))
294 r++;
295 return r;
296} 208}
297 209
298/****************************************************************************/ 210/****************************************************************************/
@@ -2530,8 +2442,8 @@ static int GetQAMSignalToNoise(struct drxk_state *state,
2530 } 2442 }
2531 2443
2532 if (qamSlErrPower > 0) { 2444 if (qamSlErrPower > 0) {
2533 qamSlMer = Log10Times100(qamSlSigPower) - 2445 qamSlMer = log10times100(qamSlSigPower) -
2534 Log10Times100((u32) qamSlErrPower); 2446 log10times100((u32) qamSlErrPower);
2535 } 2447 }
2536 *pSignalToNoise = qamSlMer; 2448 *pSignalToNoise = qamSlMer;
2537 2449
@@ -2620,12 +2532,12 @@ static int GetDVBTSignalToNoise(struct drxk_state *state,
2620 */ 2532 */
2621 2533
2622 /* log(x) x = 9bits * 9bits->18 bits */ 2534 /* log(x) x = 9bits * 9bits->18 bits */
2623 a = Log10Times100(EqRegTdTpsPwrOfs * 2535 a = log10times100(EqRegTdTpsPwrOfs *
2624 EqRegTdTpsPwrOfs); 2536 EqRegTdTpsPwrOfs);
2625 /* log(x) x = 16bits * 7bits->23 bits */ 2537 /* log(x) x = 16bits * 7bits->23 bits */
2626 b = Log10Times100(EqRegTdReqSmbCnt * tpsCnt); 2538 b = log10times100(EqRegTdReqSmbCnt * tpsCnt);
2627 /* log(x) x = (16bits + 16bits) << 15 ->32 bits */ 2539 /* log(x) x = (16bits + 16bits) << 15 ->32 bits */
2628 c = Log10Times100(SqrErrIQ); 2540 c = log10times100(SqrErrIQ);
2629 2541
2630 iMER = a + b - c; 2542 iMER = a + b - c;
2631 } 2543 }