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,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS autolearn=ham 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 8F1BCC4360F for ; Thu, 21 Mar 2019 13:41:39 +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 5D8D12075E for ; Thu, 21 Mar 2019 13:41:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="L3gbYfSX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D8D12075E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=st.com 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:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ZnBObkM1cuHx9XIWN4GBx5LeLhr84yIX8hU6WJSZLyM=; b=L3gbYfSXN1xRAh faSd9dX4cYNlv2iOFDQRChdDmnhdySjDktOq2t7ETNx1HDKq1FGU/d5aNEOsdVl+2BeeKnhZigo/u WeJYM3XUli5vWMgN99RAe3zbcGdL4mcqwYZb2lNwYqrRAVHchKjDNmiclzenEg2M4qqNaorx3WjyY C0aR9zH6HAoP4esAzSSA5x7mTDQ+QYzfCF6bDEWJqNyfu/ziHqEzplP1mt+IQV1lkmLd85yMfk2ML TtMJv9Fy9luY5Rx/xETr73I6h87QkyMf6tsoXT7SPuDfawuGPVQvrOalEsv5NUf67qZHhlVAfYDoR 0AxMz14BHXaGaUkFLoqw==; 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 1h6xws-0002a8-Bh; Thu, 21 Mar 2019 13:41:34 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6xwn-0002YW-JW for linux-arm-kernel@lists.infradead.org; Thu, 21 Mar 2019 13:41:31 +0000 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2LDanrX004257; Thu, 21 Mar 2019 14:41:17 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2r8qg4wqs8-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 21 Mar 2019 14:41:17 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C70B33A; Thu, 21 Mar 2019 13:41:14 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node3.st.com [10.75.127.15]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A0EAC508A; Thu, 21 Mar 2019 13:41:14 +0000 (GMT) Received: from [10.48.0.167] (10.75.127.44) by SFHDAG5NODE3.st.com (10.75.127.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 21 Mar 2019 14:41:13 +0100 Subject: Re: [PATCH 1/8] iio: adc: stm32-dfsdm: make spi_master_freq more accurate To: Jonathan Cameron References: <1551862524-25098-1-git-send-email-fabrice.gasnier@st.com> <1551862524-25098-2-git-send-email-fabrice.gasnier@st.com> <20190310100932.71fd1af1@archlinux> From: Fabrice Gasnier Message-ID: <62742e3f-3860-3020-33a0-dafc9ae66dd1@st.com> Date: Thu, 21 Mar 2019 14:41:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20190310100932.71fd1af1@archlinux> Content-Language: en-US X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG5NODE3.st.com (10.75.127.15) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-03-21_06:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190321_064129_944597_97B15654 X-CRM114-Status: GOOD ( 19.10 ) 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 3/10/19 11:09 AM, Jonathan Cameron wrote: > On Wed, 6 Mar 2019 09:55:17 +0100 > Fabrice Gasnier wrote: > >> When SPI clock isn't accurate, 'spi_master_freq' is filled in with >> expected frequency. Use computed value instead: >> - e.g. source clock / (CKOUTDIV + 1) >> Also, current divider may be set to value that makes CKOUT to exceed >> spi-max-frequency. Rather use lower value (e.g. round up divider when >> ckout isn't accurate). >> >> Signed-off-by: Fabrice Gasnier >> --- >> drivers/iio/adc/stm32-dfsdm-core.c | 9 +++++++-- >> 1 file changed, 7 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/iio/adc/stm32-dfsdm-core.c b/drivers/iio/adc/stm32-dfsdm-core.c >> index bf089f5..65b7556 100644 >> --- a/drivers/iio/adc/stm32-dfsdm-core.c >> +++ b/drivers/iio/adc/stm32-dfsdm-core.c >> @@ -243,13 +243,18 @@ 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; >> + priv->spi_clk_out_div = div_u64_rem(clk_freq, spi_freq, &rem); >> + >> + /* round up divider when clkout isn't accurate (e.g. !rem) */ >> + if (priv->spi_clk_out_div && !rem) >> + priv->spi_clk_out_div--; >> + > This comment perhaps needs adjusting because at the moment it looks > like it decrements when it is accurate. With the old code in place > in the patch it's obvious that's because you actually want one less. > > Might even be worth the dance of > > /* round up if not precise */ > if (priv->spi_clk_out_div && rem) > priv->spi_clk_out_div++; > > /* subtract one because.... */ > priv->spi_clk_out_div--; Hi Jonathan, I'll rework this patch in v2, make it easier to understand & read. In a few words: the clock output is divider = ckoutdiv + 1. ckoutdiv range can be from 1-255 to provide divider of 2-256. So I'll introduce this divider as a variable, and use it to setup spi_clk_out_div. This should address all your remarks here. Thanks for reviewing, Best Regards, Fabrice > >> if (!priv->spi_clk_out_div) { >> /* spi_clk_out_div == 0 means ckout is OFF */ >> dev_err(&pdev->dev, "spi-max-frequency not achievable\n"); >> return -EINVAL; >> } >> - priv->dfsdm.spi_master_freq = spi_freq; >> + priv->dfsdm.spi_master_freq = clk_freq / (priv->spi_clk_out_div + 1); > And we increment it again here? That needs an explanation as well. >> >> 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