aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorReinhard Nissl <rnissl@gmx.de>2008-01-21 14:43:18 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2008-12-29 14:53:21 -0500
commit27713c8ba45e807c64c53a8a865adbe3a73f3b2d (patch)
tree95e2dd39fcd800f3c842ff93de511be1906148e1 /drivers/media
parent561374113e6dbd717ac4a578d99834219de9d3c1 (diff)
V4L/DVB (9449): Code Simplification: use do_div() instead
Signed-off-by: Reinhard Nissl <rnissl@gmx.de> Signed-off-by: Manu Abraham <manu@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/dvb/frontends/stb0899_algo.c69
1 files changed, 34 insertions, 35 deletions
diff --git a/drivers/media/dvb/frontends/stb0899_algo.c b/drivers/media/dvb/frontends/stb0899_algo.c
index 2d2b87cf6d00..f1432cb29262 100644
--- a/drivers/media/dvb/frontends/stb0899_algo.c
+++ b/drivers/media/dvb/frontends/stb0899_algo.c
@@ -23,27 +23,12 @@
23#include "stb0899_priv.h" 23#include "stb0899_priv.h"
24#include "stb0899_reg.h" 24#include "stb0899_reg.h"
25 25
26/* 26inline u32 stb0899_do_div(u64 n, u32 d)
27 * BinaryFloatDiv
28 * float division with integer
29 */
30static long BinaryFloatDiv(long n1, long n2, int precision)
31{ 27{
32 int i = 0; 28 /* wrap do_div() for ease of use */
33 long result = 0;
34 29
35 while (i <= precision) { 30 do_div(n, d);
36 if (n1 < n2) { 31 return n;
37 result *= 2;
38 n1 *= 2;
39 } else {
40 result = result * 2 + 1;
41 n1 = (n1 - n2) * 2;
42 }
43 i++;
44 }
45
46 return result;
47} 32}
48 33
49/* 34/*
@@ -52,15 +37,15 @@ static long BinaryFloatDiv(long n1, long n2, int precision)
52 */ 37 */
53static u32 stb0899_calc_srate(u32 master_clk, u8 *sfr) 38static u32 stb0899_calc_srate(u32 master_clk, u8 *sfr)
54{ 39{
55 u32 tmp, tmp2, mclk; 40 u64 tmp;
56 41
57 mclk = master_clk / 4096L; /* MasterClock * 10 / 2^20 */ 42 /* srate = (SFR * master_clk) >> 20 */
58 tmp = (((u32) sfr[0] << 12) + ((u32) sfr[1] << 4)) / 16;
59 43
60 tmp *= mclk; 44 /* sfr is of size 20 bit, stored with an offset of 4 bit */
61 tmp /= 16; 45 tmp = (((u32)sfr[0]) << 16) | (((u32)sfr[1]) << 8) | sfr[2];
62 tmp2 = ((u32) sfr[2] * mclk) / 256; 46 tmp &= ~0xf;
63 tmp += tmp2; 47 tmp *= master_clk;
48 tmp >>= 24;
64 49
65 return tmp; 50 return tmp;
66} 51}
@@ -72,7 +57,7 @@ static u32 stb0899_calc_srate(u32 master_clk, u8 *sfr)
72u32 stb0899_get_srate(struct stb0899_state *state) 57u32 stb0899_get_srate(struct stb0899_state *state)
73{ 58{
74 struct stb0899_internal *internal = &state->internal; 59 struct stb0899_internal *internal = &state->internal;
75 u8 sfr[4]; 60 u8 sfr[3];
76 61
77 stb0899_read_regs(state, STB0899_SFRH, sfr, 3); 62 stb0899_read_regs(state, STB0899_SFRH, sfr, 3);
78 63
@@ -101,16 +86,30 @@ static u32 stb0899_set_srate(struct stb0899_state *state, u32 master_clk, u32 sr
101 */ 86 */
102// srate_up += (srate_up * 3) / 100; 87// srate_up += (srate_up * 3) / 100;
103 88
104 tmp = BinaryFloatDiv(srate, master_clk, 20); 89 /*
105// tmp_up = BinaryFloatDiv(srate_up, master_clk, 20); 90 * srate = (SFR * master_clk) >> 20
91 * <=>
92 * SFR = srate << 20 / master_clk
93 *
94 * rounded:
95 * SFR = (srate << 21 + master_clk) / (2 * master_clk)
96 *
97 * stored as 20 bit number with an offset of 4 bit:
98 * sfr = SFR << 4;
99 */
100// tmp_up = stb0899_do_div((((u64)srate_up) << 21) + master_clk, 2 * master_clk);
101// tmp_up <<= 4;
102
103 tmp = stb0899_do_div((((u64)srate) << 21) + master_clk, 2 * master_clk);
104 tmp <<= 4;
106 105
107// sfr_up[0] = (tmp_up >> 12) & 0xff; 106// sfr_up[0] = tmp_up >> 16;
108// sfr_up[1] = (tmp_up >> 4) & 0xff; 107// sfr_up[1] = tmp_up >> 8;
109// sfr_up[2] = tmp_up & 0x0f; 108// sfr_up[2] = tmp_up;
110 109
111 sfr[0] = (tmp >> 12) & 0xff; 110 sfr[0] = tmp >> 16;
112 sfr[1] = (tmp >> 4) & 0xff; 111 sfr[1] = tmp >> 8;
113 sfr[2] = (tmp << 4) & 0xf0; 112 sfr[2] = tmp;
114 113
115// stb0899_write_regs(state, STB0899_SFRUPH, sfr_up, 3); 114// stb0899_write_regs(state, STB0899_SFRUPH, sfr_up, 3);
116 stb0899_write_regs(state, STB0899_SFRH, sfr, 3); 115 stb0899_write_regs(state, STB0899_SFRH, sfr, 3);