From patchwork Thu Jun 15 03:30:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antti Palosaari X-Patchwork-Id: 9787979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ED2FF60231 for ; Thu, 15 Jun 2017 03:32:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E411A2854A for ; Thu, 15 Jun 2017 03:32:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8F75285A8; Thu, 15 Jun 2017 03:32:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 861DA2854A for ; Thu, 15 Jun 2017 03:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752158AbdFODcF (ORCPT ); Wed, 14 Jun 2017 23:32:05 -0400 Received: from mail.kapsi.fi ([217.30.184.167]:57513 "EHLO mail.kapsi.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751869AbdFODbf (ORCPT ); Wed, 14 Jun 2017 23:31:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=xba03v5uSNWf0vsol9XSr/f1kdNYtBs1AXvZIpBYN8s=; b=PtAMfzt0MT5ZOwEwWxpFfwE31c2KPclYXaq8sa7zLTzkl2R89JmsuO56qcSbV39JthNwwCqHSubh8+0/ViNAv6EL7SkUlZCXqFyGTURjGEdfI83urnOzuAdPqx4HjvfsGTsWAlAZELeCY+j2gCIoqEKVnRzowZBWtbrhhMOdUam6W2atukEnHt9yqwcw2p8g7T6t00dr3/H0cmIZF+BN5FxiJ+wHLXQlcMblkArm9KGt7d3c7LdmFPaNg6yfBOF7pAutM9FZ5WU7Ir7rOv5It6VjsN2sMzU3m+iLV+01mNQEPKxKj6eRDpjb9ZGu38LWaNB/Or9nrwBlD3w0pyOuaQ==; Received: from dyn3-82-128-189-68.psoas.suomi.net ([82.128.189.68] helo=localhost.localdomain) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dLLVN-0001Yv-Jz; Thu, 15 Jun 2017 06:31:33 +0300 From: Antti Palosaari To: linux-media@vger.kernel.org Cc: Antti Palosaari Subject: [PATCH 04/15] af9033: use kernel 64-bit division Date: Thu, 15 Jun 2017 06:30:54 +0300 Message-Id: <20170615033105.13517-4-crope@iki.fi> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170615033105.13517-1-crope@iki.fi> References: <20170615033105.13517-1-crope@iki.fi> X-SA-Exim-Connect-IP: 82.128.189.68 X-SA-Exim-Mail-From: crope@iki.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace own binary division with 64-bit multiply and division. Signed-off-by: Antti Palosaari --- drivers/media/dvb-frontends/af9013.c | 34 +++---------------------------- 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 f644182..dd7ac0a 100644 --- a/drivers/media/dvb-frontends/af9013.c +++ b/drivers/media/dvb-frontends/af9013.c @@ -277,33 +277,6 @@ static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval) 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; @@ -638,8 +611,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; @@ -1108,11 +1081,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 31d6538..97b5b0c 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 +#include #define AF9013_FIRMWARE "dvb-fe-af9013.fw"