From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FE1EC43381 for ; Sun, 24 Mar 2019 16:41:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F1F122087E for ; Sun, 24 Mar 2019 16:41:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="snQe/lzy"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="MkcIj+tA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F1F122087E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GME0/i1iO7Pr5ehaKLLUwKbizWXD1S8WM744JJx9M7E=; b=snQe/lzySNp739 9du7RN3frKRWL44BB26kLimYhCMDtBd+O0SVi869w9TBe4YDQ4x0mKmk59Qpnh0wQd8jujJRzdBN9 JuWKa98RRYPjyaPUd8eDUtXkL0tpzioalLIuoj0BvAvKr56cL4KagF4EG95ubAwHm9sjGIlVHZUDr fXXm2LocWyRNKam789N72NH/OCYWDbUGXs5pxwnqubX0F6ASWBnIsGBsqvX+Z9D72M7rPD3mxQ8dS Sr7pltNaSEK1wYhkU/Snzhb7qWEshHAgUmZHkrRHeW64/p0rIgKL/e3Ov+hAUPzIJVdU+bTy8npJ/ m7Xth9o5gDSJIW35QeOg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h86Bm-0006wj-L1; Sun, 24 Mar 2019 16:41:38 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h86Bj-0006wP-Cl for linux-arm-kernel@lists.infradead.org; Sun, 24 Mar 2019 16:41:36 +0000 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6792C20823; Sun, 24 Mar 2019 16:41:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553445694; bh=Kv3TDuW80B8AVSdOkjAs1pOmjBnZIjLUbrZAG19GBqo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MkcIj+tA2fUQWmo+xVVBd91U20HuKFFG8MyIBo3XYus+QiEam1sKH0P5AR1YQg8tb HHgDuVStn6j5H/zGcMa65Orce6byjBg2YQYSIVGbR+oY2nFwhnO7AUyM+DvO20HOYs BEb8+rrVWecJyxLkpmsTu+i+9CJOcdlRuabQ8hM0= Date: Sun, 24 Mar 2019 16:41:29 +0000 From: Jonathan Cameron To: Fabrice Gasnier Subject: Re: [PATCH v2 1/8] iio: adc: stm32-dfsdm: make spi_master_freq more accurate Message-ID: <20190324164129.620bf216@archlinux> In-Reply-To: <1553186849-6261-2-git-send-email-fabrice.gasnier@st.com> References: <1553186849-6261-1-git-send-email-fabrice.gasnier@st.com> <1553186849-6261-2-git-send-email-fabrice.gasnier@st.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190324_094135_469101_967CF628 X-CRM114-Status: GOOD ( 18.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lars@metafoo.de, olivier.moysan@st.com, alexandre.torgue@st.com, linux-iio@vger.kernel.org, pmeerw@pmeerw.net, arnaud.pouliquen@st.com, linux-kernel@vger.kernel.org, mcoquelin.stm32@gmail.com, knaack.h@gmx.de, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 21 Mar 2019 17:47:22 +0100 Fabrice Gasnier wrote: > Current ckout divider may be set to a value that makes ckout to exceed > spi-max-frequency. Rather use lower value (e.g. round up divider when > ckout isn't accurate). > > Also when the SPI clock isn't accurate, 'spi_master_freq' is filled in > with expected frequency. Use computed value instead to be more accurate: > - e.g. source clock / (CKOUTDIV + 1) > > Enforce checks on the divider: ckoutdiv range can be from 1-255 to provide > divider of 2-256. > > Signed-off-by: Fabrice Gasnier Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > Changes in v2: > - rework the way to determine ckoutdiv bitfield: deal with divider directly > to explicitly handle the rounding, the range constraints of 2-256 and the > divider = ckoutdiv + 1. > --- > drivers/iio/adc/stm32-dfsdm-core.c | 17 ++++++++++++----- > 1 file changed, 12 insertions(+), 5 deletions(-) > > diff --git a/drivers/iio/adc/stm32-dfsdm-core.c b/drivers/iio/adc/stm32-dfsdm-core.c > index bf089f5..472b809 100644 > --- a/drivers/iio/adc/stm32-dfsdm-core.c > +++ b/drivers/iio/adc/stm32-dfsdm-core.c > @@ -199,7 +199,7 @@ static int stm32_dfsdm_parse_of(struct platform_device *pdev, > { > struct device_node *node = pdev->dev.of_node; > struct resource *res; > - unsigned long clk_freq; > + unsigned long clk_freq, divider; > unsigned int spi_freq, rem; > int ret; > > @@ -243,13 +243,20 @@ static int stm32_dfsdm_parse_of(struct platform_device *pdev, > return 0; > } > > - priv->spi_clk_out_div = div_u64_rem(clk_freq, spi_freq, &rem) - 1; > - if (!priv->spi_clk_out_div) { > - /* spi_clk_out_div == 0 means ckout is OFF */ > + divider = div_u64_rem(clk_freq, spi_freq, &rem); > + /* Round up divider when ckout isn't precise, not to exceed spi_freq */ > + if (rem) > + divider++; > + > + /* programmable divider is in range of [2:256] */ > + if (divider < 2 || divider > 256) { > dev_err(&pdev->dev, "spi-max-frequency not achievable\n"); > return -EINVAL; > } > - priv->dfsdm.spi_master_freq = spi_freq; > + > + /* SPI clock output divider is: divider = CKOUTDIV + 1 */ > + priv->spi_clk_out_div = divider - 1; > + priv->dfsdm.spi_master_freq = clk_freq / (priv->spi_clk_out_div + 1); > > if (rem) { > dev_warn(&pdev->dev, "SPI clock not accurate\n"); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel