From patchwork Thu Dec 3 13:57:02 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wong X-Patchwork-Id: 64550 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nB3DvcqQ032477 for ; Thu, 3 Dec 2009 13:57:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752929AbZLCN5G (ORCPT ); Thu, 3 Dec 2009 08:57:06 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756092AbZLCN5G (ORCPT ); Thu, 3 Dec 2009 08:57:06 -0500 Received: from mail-pw0-f42.google.com ([209.85.160.42]:48921 "EHLO mail-pw0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756089AbZLCN5D (ORCPT ); Thu, 3 Dec 2009 08:57:03 -0500 Received: by pwi3 with SMTP id 3so1102374pwi.21 for ; Thu, 03 Dec 2009 05:57:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type; bh=Z9ffIQWFxUb/kVGzsrqVJ/ZqlYWvOxyWBBG6SU7pdDE=; b=JB5vZK/Qm1ZMmClldx7NW2MUyqUuBJItMXGaR88cFXvMfMt1UfQzss0ed1fPvGqtCS dlSRTNUqNuFDtddpcLmYhWlmkciVtDb71qgu/6BWKFt2G8lfE6+vQj2aS+euq0pKIvnf Op43Wdm59TDdX0LNMzq72CBCcMZ4Pe/B3CdnM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; b=hS3l11NUOMCyv/KrYw0n0s1QsmeNkreQzi2es2AFyR8nIY7uUjxMemG0ilGJaRdPzi zFJe2cIajD8XMJpBtftGkkrfb3T4OeMUq9buIpEr8ZE4gd2bD2knRq/KX1khQ/ryRYXV MHkDht26Th31ySlJG8/pbwgyt2TEZRg/Nnk1I= Received: by 10.114.189.8 with SMTP id m8mr2393823waf.180.1259848629728; Thu, 03 Dec 2009 05:57:09 -0800 (PST) Received: from ?192.168.0.3? (n219073044176.netvigator.com [219.73.44.176]) by mx.google.com with ESMTPS id 23sm1712151pzk.0.2009.12.03.05.57.05 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 03 Dec 2009 05:57:07 -0800 (PST) Message-ID: <4B17C3AE.6070207@gmail.com> Date: Thu, 03 Dec 2009 21:57:02 +0800 From: "David T. L. Wong" User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Randy Dunlap CC: linux-next@vger.kernel.org, Stephen Rothwell , LKML , linux-media@vger.kernel.org, Mauro Carvalho Chehab Subject: [PATCH] atbm8830: replace 64-bit division and floating point usage References: <20091130175346.3f3345ed.sfr@canb.auug.org.au> <4B1409D9.1050901@oracle.com> <20091202100406.e25b2322.randy.dunlap@oracle.com> In-Reply-To: <20091202100406.e25b2322.randy.dunlap@oracle.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org diff --git a/linux/drivers/media/dvb/frontends/atbm8830.c b/linux/drivers/media/dvb/frontends/atbm8830.c --- a/linux/drivers/media/dvb/frontends/atbm8830.c +++ b/linux/drivers/media/dvb/frontends/atbm8830.c @@ -19,6 +19,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include "dvb_frontend.h" #include "atbm8830.h" @@ -102,8 +103,12 @@ static int set_osc_freq(struct atbm_state *priv, u32 freq /*in kHz*/) { u32 val; + u64 t; - val = (u64)0x100000 * freq / 30400; + /* 0x100000 * freq / 30.4MHz */ + t = (u64)0x100000 * freq; + do_div(t, 30400); + val = t; atbm8830_write_reg(priv, REG_OSC_CLK, val); atbm8830_write_reg(priv, REG_OSC_CLK + 1, val >> 8); @@ -116,14 +121,18 @@ { u32 fs = priv->config->osc_clk_freq; - double t; + u64 t; u32 val; u8 dat; - t = 2 * 3.141593 * (freq - fs) / fs * (1 << 22); - val = t; + if (freq != 0) { + /* 2 * PI * (freq - fs) / fs * (2 ^ 22) */ + t = (u64) 2 * 31416 * (freq - fs); + t <<= 22; + do_div(t, fs); + do_div(t, 1000); + val = t; - if (freq != 0) { atbm8830_write_reg(priv, REG_TUNER_BASEBAND, 1); atbm8830_write_reg(priv, REG_IF_FREQ, val); atbm8830_write_reg(priv, REG_IF_FREQ+1, val >> 8);