diff options
author | Antti Palosaari <crope@iki.fi> | 2017-06-10 21:12:14 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2017-06-20 10:17:15 -0300 |
commit | 903b0e58d890ab9052eef1dbbddcac0f357410b8 (patch) | |
tree | c68bab7b79965832f1d2a53d11c61f877808427d /drivers/media | |
parent | 82d1ce3eba6952929efa770e693d3be6e55bd7ab (diff) |
[media] af9013: use kernel 64-bit division
Replace own binary division with 64-bit multiply and division.
Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/dvb-frontends/af9013.c | 34 | ||||
-rw-r--r-- | drivers/media/dvb-frontends/af9013_priv.h | 1 |
2 files changed, 4 insertions, 31 deletions
diff --git a/drivers/media/dvb-frontends/af9013.c b/drivers/media/dvb-frontends/af9013.c index a10c7165075c..a6c53bb298ce 100644 --- a/drivers/media/dvb-frontends/af9013.c +++ b/drivers/media/dvb-frontends/af9013.c @@ -277,33 +277,6 @@ err: return ret; } -static u32 af9013_div(struct af9013_state *state, u32 a, u32 b, u32 x) -{ - u32 r = 0, c = 0, i; - - dev_dbg(&state->client->dev, "%s: a=%d b=%d x=%d\n", __func__, a, b, x); - - if (a > b) { - c = a / b; - a = a - c * b; - } - - for (i = 0; i < x; i++) { - if (a >= b) { - r += 1; - a -= b; - } - a <<= 1; - r <<= 1; - } - r = (c << (u32)x) + r; - - dev_dbg(&state->client->dev, "%s: a=%d b=%d x=%d r=%d r=%x\n", - __func__, a, b, x, r, r); - - return r; -} - static int af9013_power_ctrl(struct af9013_state *state, u8 onoff) { int ret, i; @@ -641,8 +614,8 @@ static int af9013_set_frontend(struct dvb_frontend *fe) spec_inv = !state->spec_inv; } - freq_cw = af9013_div(state, sampling_freq, state->clk, - 23); + freq_cw = DIV_ROUND_CLOSEST_ULL((u64)sampling_freq * 0x800000, + state->clk); if (spec_inv) freq_cw = 0x800000 - freq_cw; @@ -1111,11 +1084,10 @@ static int af9013_init(struct dvb_frontend *fe) return -EINVAL; } - adc_cw = af9013_div(state, state->clk, 1000000ul, 19); + adc_cw = div_u64((u64)state->clk * 0x80000, 1000000); buf[0] = (adc_cw >> 0) & 0xff; buf[1] = (adc_cw >> 8) & 0xff; buf[2] = (adc_cw >> 16) & 0xff; - ret = af9013_wr_regs(state, 0xd180, buf, 3); if (ret) goto err; diff --git a/drivers/media/dvb-frontends/af9013_priv.h b/drivers/media/dvb-frontends/af9013_priv.h index 31d6538abfae..97b5b0c0fe77 100644 --- a/drivers/media/dvb-frontends/af9013_priv.h +++ b/drivers/media/dvb-frontends/af9013_priv.h @@ -24,6 +24,7 @@ #include "dvb_frontend.h" #include "af9013.h" #include <linux/firmware.h> +#include <linux/math64.h> #define AF9013_FIRMWARE "dvb-fe-af9013.fw" |