From patchwork Sun Apr 9 19:38:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 9671723 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 B75FC600CB for ; Sun, 9 Apr 2017 19:38:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A385D26E8A for ; Sun, 9 Apr 2017 19:38:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 987D327F10; Sun, 9 Apr 2017 19:38:44 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 0D4D226E8A for ; Sun, 9 Apr 2017 19:38:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752585AbdDITim (ORCPT ); Sun, 9 Apr 2017 15:38:42 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:34744 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752552AbdDITih (ORCPT ); Sun, 9 Apr 2017 15:38:37 -0400 Received: by mail-wm0-f65.google.com with SMTP id x75so6393384wma.1 for ; Sun, 09 Apr 2017 12:38:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6gT73wNPrhOb1bQdJd37KhRkYd7gMFOIbwU9/QOCQnQ=; b=jVf3JNd84wMmOqI2TvS6FUi+1+BHVOkMcyhGbi6m4Fok7ck8uDd3ps7FRDJuZA+isK v4LYSU8NkpSSH7V4rpmuL9UfARt36gkVlZzn+O54H4YHqegx0AfmgkFPcjU0+URSCIFl +9S7lRcrbfze9dTQBEKkCHxLAWqaFdIa7V1Nv31hUiI+4HAzgeSj/r5NBgfxZfnV+k2B bpieaOoWSg1jRdfpplZTTygk0jyHTaJn9KarXF7Enrht7QjP4tbAwFWdzEM7bzC0vWgp AG0TmgdnbAuQxPWKccg/wn1mxd7nCh7Yc8G0C3Pv6oLx/H70+8MI4bWJbD7rhQRbd9uW t5Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6gT73wNPrhOb1bQdJd37KhRkYd7gMFOIbwU9/QOCQnQ=; b=SlwYGEUd57Wv0VwxuDTbST/BL1OK12i+JmdKiy0LyD812/dKnocE/FQu5aLVo+yw3g ikk1CHxL8Srvg0NLy/gOq9oWS8yQWclYLfXkqm0EbGmCW0+AF5f3LN3ns2l/dEJQ57F8 mnwj7gmyvHjpn0++yaUOWS4PgAEEfVUu2e9O2Ado3DeSr/+a8Gn42VICcqPnCtD8lJbQ hGZK2T5ZnOniK1bbDb5OHCvJ0oFVn9eToJd8/K4o1HOjl0N3cZDunsbouC4X8B1H/aRs w+aUq97urLYSKIQ+j/t4FFl+KHnMbvfzygkbvxVcAQ8+TXgVdf6Qevt4iopMim8cRL2j 5ymQ== X-Gm-Message-State: AN3rC/75yZMGWQq1kN2bH//5Pwj9C5zujN5MwnN44SoQq0fF9iqIvPEz BPtcKFZlxeE0Hg== X-Received: by 10.28.236.135 with SMTP id h7mr5632157wmi.74.1491766715635; Sun, 09 Apr 2017 12:38:35 -0700 (PDT) Received: from dvbdev.wuest.de (ip-37-24-178-151.hsi14.unitymediagroup.de. [37.24.178.151]) by smtp.gmail.com with ESMTPSA id f135sm7441407wmd.7.2017.04.09.12.38.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 09 Apr 2017 12:38:35 -0700 (PDT) From: Daniel Scheller To: aospan@netup.ru, serjk@netup.ru, mchehab@kernel.org, linux-media@vger.kernel.org Cc: rjkm@metzlerbros.de Subject: [PATCH 05/19] [media] dvb-frontends/cxd2841er: replace IFFREQ calc macros into functions Date: Sun, 9 Apr 2017 21:38:14 +0200 Message-Id: <20170409193828.18458-6-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170409193828.18458-1-d.scheller.oss@gmail.com> References: <20170409193828.18458-1-d.scheller.oss@gmail.com> 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 From: Daniel Scheller The way the MAKE_IFFREQ_CONFIG macros are written make it impossible to pass regular integers for iffreq calculation, since this will cause "SSE register return with SSE disabled" compile errors. This changes the calculation into C functions which also might help when debugging. Also, expand all passed frequencies from MHz to Hz scale. Signed-off-by: Daniel Scheller Acked-by: Abylay Ospan --- drivers/media/dvb-frontends/cxd2841er.c | 48 ++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/drivers/media/dvb-frontends/cxd2841er.c b/drivers/media/dvb-frontends/cxd2841er.c index 72a27cc..6648bd1 100644 --- a/drivers/media/dvb-frontends/cxd2841er.c +++ b/drivers/media/dvb-frontends/cxd2841er.c @@ -201,11 +201,6 @@ static const struct cxd2841er_cnr_data s2_cn_data[] = { { 0x0016, 19700 }, { 0x0015, 19900 }, { 0x0014, 20000 }, }; -#define MAKE_IFFREQ_CONFIG(iffreq) ((u32)(((iffreq)/41.0)*16777216.0 + 0.5)) -#define MAKE_IFFREQ_CONFIG_XTAL(xtal, iffreq) ((xtal == SONY_XTAL_24000) ? \ - (u32)(((iffreq)/48.0)*16777216.0 + 0.5) : \ - (u32)(((iffreq)/41.0)*16777216.0 + 0.5)) - static int cxd2841er_freeze_regs(struct cxd2841er_priv *priv); static int cxd2841er_unfreeze_regs(struct cxd2841er_priv *priv); @@ -316,6 +311,21 @@ static int cxd2841er_set_reg_bits(struct cxd2841er_priv *priv, return cxd2841er_write_reg(priv, addr, reg, data); } +static u32 cxd2841er_calc_iffreq_xtal(enum cxd2841er_xtal xtal, u32 ifhz) +{ + u64 tmp; + + tmp = (u64) ifhz * 16777216; + do_div(tmp, ((xtal == SONY_XTAL_24000) ? 48000000 : 41000000)); + + return (u32) tmp; +} + +static u32 cxd2841er_calc_iffreq(u32 ifhz) +{ + return cxd2841er_calc_iffreq_xtal(SONY_XTAL_20500, ifhz); +} + static int cxd2841er_dvbs2_set_symbol_rate(struct cxd2841er_priv *priv, u32 symbol_rate) { @@ -2228,7 +2238,7 @@ static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv, cxd2841er_write_regs(priv, I2C_SLVT, 0xA6, itbCoef8bw[priv->xtal], 14); /* */ - iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 4.80); + iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, 4800000); data[0] = (u8) ((iffreq >> 16) & 0xff); data[1] = (u8)((iffreq >> 8) & 0xff); data[2] = (u8)(iffreq & 0xff); @@ -2256,7 +2266,7 @@ static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv, cxd2841er_write_regs(priv, I2C_SLVT, 0xA6, itbCoef7bw[priv->xtal], 14); /* */ - iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 4.20); + iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, 4200000); data[0] = (u8) ((iffreq >> 16) & 0xff); data[1] = (u8)((iffreq >> 8) & 0xff); data[2] = (u8)(iffreq & 0xff); @@ -2284,7 +2294,7 @@ static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv, cxd2841er_write_regs(priv, I2C_SLVT, 0xA6, itbCoef6bw[priv->xtal], 14); /* */ - iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 3.60); + iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, 3600000); data[0] = (u8) ((iffreq >> 16) & 0xff); data[1] = (u8)((iffreq >> 8) & 0xff); data[2] = (u8)(iffreq & 0xff); @@ -2312,7 +2322,7 @@ static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv, cxd2841er_write_regs(priv, I2C_SLVT, 0xA6, itbCoef5bw[priv->xtal], 14); /* */ - iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 3.60); + iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, 3600000); data[0] = (u8) ((iffreq >> 16) & 0xff); data[1] = (u8)((iffreq >> 8) & 0xff); data[2] = (u8)(iffreq & 0xff); @@ -2340,7 +2350,7 @@ static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv, cxd2841er_write_regs(priv, I2C_SLVT, 0xA6, itbCoef17bw[priv->xtal], 14); /* */ - iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 3.50); + iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, 3500000); data[0] = (u8) ((iffreq >> 16) & 0xff); data[1] = (u8)((iffreq >> 8) & 0xff); data[2] = (u8)(iffreq & 0xff); @@ -2439,7 +2449,7 @@ static int cxd2841er_sleep_tc_to_active_t_band( cxd2841er_write_regs(priv, I2C_SLVT, 0xA6, itbCoef8bw[priv->xtal], 14); /* */ - iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 4.80); + iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, 4800000); data[0] = (u8) ((iffreq >> 16) & 0xff); data[1] = (u8)((iffreq >> 8) & 0xff); data[2] = (u8)(iffreq & 0xff); @@ -2474,7 +2484,7 @@ static int cxd2841er_sleep_tc_to_active_t_band( cxd2841er_write_regs(priv, I2C_SLVT, 0xA6, itbCoef7bw[priv->xtal], 14); /* */ - iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 4.20); + iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, 4200000); data[0] = (u8) ((iffreq >> 16) & 0xff); data[1] = (u8)((iffreq >> 8) & 0xff); data[2] = (u8)(iffreq & 0xff); @@ -2509,7 +2519,7 @@ static int cxd2841er_sleep_tc_to_active_t_band( cxd2841er_write_regs(priv, I2C_SLVT, 0xA6, itbCoef6bw[priv->xtal], 14); /* */ - iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 3.60); + iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, 3600000); data[0] = (u8) ((iffreq >> 16) & 0xff); data[1] = (u8)((iffreq >> 8) & 0xff); data[2] = (u8)(iffreq & 0xff); @@ -2544,7 +2554,7 @@ static int cxd2841er_sleep_tc_to_active_t_band( cxd2841er_write_regs(priv, I2C_SLVT, 0xA6, itbCoef5bw[priv->xtal], 14); /* */ - iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 3.60); + iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, 3600000); data[0] = (u8) ((iffreq >> 16) & 0xff); data[1] = (u8)((iffreq >> 8) & 0xff); data[2] = (u8)(iffreq & 0xff); @@ -2646,7 +2656,7 @@ static int cxd2841er_sleep_tc_to_active_i_band( 0xA6, itbCoef8bw[priv->xtal], 14); /* IF freq setting */ - iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 4.75); + iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, 4750000); data[0] = (u8) ((iffreq >> 16) & 0xff); data[1] = (u8)((iffreq >> 8) & 0xff); data[2] = (u8)(iffreq & 0xff); @@ -2675,7 +2685,7 @@ static int cxd2841er_sleep_tc_to_active_i_band( 0xA6, itbCoef7bw[priv->xtal], 14); /* IF freq setting */ - iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 4.15); + iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, 4150000); data[0] = (u8) ((iffreq >> 16) & 0xff); data[1] = (u8)((iffreq >> 8) & 0xff); data[2] = (u8)(iffreq & 0xff); @@ -2704,7 +2714,7 @@ static int cxd2841er_sleep_tc_to_active_i_band( 0xA6, itbCoef6bw[priv->xtal], 14); /* IF freq setting */ - iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 3.55); + iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, 3550000); data[0] = (u8) ((iffreq >> 16) & 0xff); data[1] = (u8)((iffreq >> 8) & 0xff); data[2] = (u8)(iffreq & 0xff); @@ -2765,13 +2775,13 @@ static int cxd2841er_sleep_tc_to_active_c_band(struct cxd2841er_priv *priv, cxd2841er_write_regs( priv, I2C_SLVT, 0xa6, bw7_8mhz_b10_a6, sizeof(bw7_8mhz_b10_a6)); - iffreq = MAKE_IFFREQ_CONFIG(4.9); + iffreq = cxd2841er_calc_iffreq(4900000); break; case 6000000: cxd2841er_write_regs( priv, I2C_SLVT, 0xa6, bw6mhz_b10_a6, sizeof(bw6mhz_b10_a6)); - iffreq = MAKE_IFFREQ_CONFIG(3.7); + iffreq = cxd2841er_calc_iffreq(3700000); break; default: dev_err(&priv->i2c->dev, "%s(): unsupported bandwidth %d\n",