summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJemma Denson <jdenson@gmail.com>2015-05-03 13:55:15 +0200
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2015-05-18 21:36:13 +0200
commitc84251bb122d6abcb0178f2c922f9ef51740e7ad (patch)
treebba0591f42d4bb0446183513242e4ac8b75fcacb /drivers
parent[media] cx24120: Fix hexdump length in writeregs (diff)
downloadlinux-c84251bb122d6abcb0178f2c922f9ef51740e7ad.tar.xz
linux-c84251bb122d6abcb0178f2c922f9ef51740e7ad.zip
[media] cx24120: Rework vco function to remove xxyyzz variable
Change calculate_vco function to send_vco to tidy up cx24120_init function. xxyyzz variable is remnants of a manual div & remainder codepath to perform a u64 rounded div; replace with kernel macro DIV_ROUND_CLOSEST_ULL Hex values provided to the message are mainly variables calculated within this function, replace with these to remove hardcoding. Signed-off-by: Jemma Denson <jdenson@gmail.com> Signed-off-by: Patrick Boettcher <patrick.boettcher@posteo.de> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/dvb-frontends/cx24120.c63
1 files changed, 29 insertions, 34 deletions
diff --git a/drivers/media/dvb-frontends/cx24120.c b/drivers/media/dvb-frontends/cx24120.c
index 74ce7a75a961..8238f80ea98e 100644
--- a/drivers/media/dvb-frontends/cx24120.c
+++ b/drivers/media/dvb-frontends/cx24120.c
@@ -1111,26 +1111,38 @@ static int cx24120_set_frontend(struct dvb_frontend *fe)
return 0;
}
-/* Calculate vco from config */
-static u64 cx24120_calculate_vco(struct cx24120_state *state)
+/* Set vco from config */
+static int cx24120_set_vco(struct cx24120_state *state)
{
- u32 vco;
- u64 inv_vco, res, xxyyzz;
+ struct cx24120_cmd cmd;
+ u32 nxtal_khz, vco;
+ u64 inv_vco;
u32 xtal_khz = state->config->xtal_khz;
- xxyyzz = 0x400000000ULL;
- vco = xtal_khz * 10 * 4;
- inv_vco = xxyyzz / vco;
- res = xxyyzz % vco;
-
- if (inv_vco > xtal_khz * 10 * 2)
- ++inv_vco;
+ nxtal_khz = xtal_khz * 4;
+ vco = nxtal_khz * 10;
+ inv_vco = DIV_ROUND_CLOSEST_ULL(0x400000000ULL, vco);
dev_dbg(&state->i2c->dev,
- "%s: xtal=%d, vco=%d, inv_vco=%lld, res=%lld\n",
- __func__, xtal_khz, vco, inv_vco, res);
+ "%s: xtal=%d, vco=%d, inv_vco=%lld\n",
+ __func__, xtal_khz, vco, inv_vco);
- return inv_vco;
+ cmd.id = CMD_VCO_SET;
+ cmd.len = 12;
+ cmd.arg[0] = (vco >> 16) & 0xff;
+ cmd.arg[1] = (vco >> 8) & 0xff;
+ cmd.arg[2] = vco & 0xff;
+ cmd.arg[3] = (inv_vco >> 8) & 0xff;
+ cmd.arg[4] = (inv_vco) & 0xff;
+ cmd.arg[5] = 0x03;
+ cmd.arg[6] = (nxtal_khz >> 8) & 0xff;
+ cmd.arg[7] = nxtal_khz & 0xff;
+ cmd.arg[8] = 0x06;
+ cmd.arg[9] = 0x03;
+ cmd.arg[10] = (xtal_khz >> 16) & 0xff;
+ cmd.arg[11] = xtal_khz & 0xff;
+
+ return cx24120_message_send(state, &cmd);
}
int cx24120_init(struct dvb_frontend *fe)
@@ -1139,7 +1151,6 @@ int cx24120_init(struct dvb_frontend *fe)
struct cx24120_state *state = fe->demodulator_priv;
struct cx24120_cmd cmd;
u8 ret, ret_EA, reg1;
- u64 inv_vco;
int reset_result;
int i;
@@ -1251,26 +1262,10 @@ int cx24120_init(struct dvb_frontend *fe)
}
/* Set VCO */
- inv_vco = cx24120_calculate_vco(state);
-
- cmd.id = CMD_VCO_SET;
- cmd.len = 12;
- cmd.arg[0] = 0x06;
- cmd.arg[1] = 0x2b;
- cmd.arg[2] = 0xd8;
- cmd.arg[3] = (inv_vco >> 8) & 0xff;
- cmd.arg[4] = (inv_vco) & 0xff;
- cmd.arg[5] = 0x03;
- cmd.arg[6] = 0x9d;
- cmd.arg[7] = 0xfc;
- cmd.arg[8] = 0x06;
- cmd.arg[9] = 0x03;
- cmd.arg[10] = 0x27;
- cmd.arg[11] = 0x7f;
-
- if (cx24120_message_send(state, &cmd)) {
+ ret = cx24120_set_vco(state);
+ if (ret != 0) {
err("Error set VCO! :(\n");
- return -EREMOTEIO;
+ return ret;
}
/* set bandwidth */