Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp200079imc; Sun, 10 Mar 2019 03:10:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxofS+dILdRQOy5scebW98Zs/vTWZzBzth/PH4nK+c8ybGa74ea3gytqMw+xHOQnbYAyr8S X-Received: by 2002:a17:902:1101:: with SMTP id d1mr27416752pla.19.1552212613627; Sun, 10 Mar 2019 03:10:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552212613; cv=none; d=google.com; s=arc-20160816; b=hxXuxTYSGd3x4Ws4maP2hOY0v4wV2OLWVAZuxjtolLQvndSKxWiagW2soM9PEH5jzh 4SrvDtKL+bKMmA2wB13KAFeF1FvQ8AmLeXoPOnykVvtTXAFbg6DP+qVvjNiONnAigcq4 70PDhoK+m6khBl5fl0GXa5rKYpPxNc1G8OvpkPMFS6UM6LOu73d83NndBqrkShx6veij +0Tmdsf8LCNdEHGSr0Gu9J6NkMdjjYJpbtVDXsX36xL7k7kuHYx8UsNaSJHR/C3yKire 1nimu78hEyrKNFGJw5DDCi3CKLsqkn3hng0lUp0GEuzLxPPqcwMLRP5AsJ+NSOE9hUna GRqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=j0qYxWeDZSr54ggPKzXxcsdJ/qhEm3Y4HEzIhYfaarI=; b=sTmiacckwPf/l1My+166gbMgUyjpOC+csYETF2zAOTHEzaGosjW8pmYhid8inBu+3z oOXpRMjXo79cir2+UHfmGdhI/1/JmqCu6oXakr9M2XZ1RjCgKbbQaEtgnpiNHE3B1Reb dNLj+NixcdFyl63oEPiQCo4Df7Xo9VyOrRY/vVqS8s4CY8hJhVv0o8+Zl8g4tsw02SYn bk8kSOtuBnRfVASCPTN5JvDLAMpcudVOsr6Z63H56OPbevXpjTx1w0jednZ+Bm8hckBJ ab3c7oirBTObZNwC5ssOxs4+nIAedcw6yFZH8Cg/VjG94w/iNSk1kucBAO0a2fn2NXey etsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bUjZyLI9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o32si2766837pld.163.2019.03.10.03.09.58; Sun, 10 Mar 2019 03:10:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bUjZyLI9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726443AbfCJKJj (ORCPT + 99 others); Sun, 10 Mar 2019 06:09:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:37474 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725840AbfCJKJj (ORCPT ); Sun, 10 Mar 2019 06:09:39 -0400 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 6C1E0207E0; Sun, 10 Mar 2019 10:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552212578; bh=eCdM6jdCcVcbvvmuBC3cUHjyHNsrk1CsMDk6B8cH+m4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=bUjZyLI9/UjPtzh7AJlzyoKnDouerg8cohIY9E9kDufMJcxWFARPpDUDXkI5QY6JG otKFVId4TFjkDdjoMARVU5AFGb57h32MSrRwoUcEYCoY32aH5Kc9I6kdFLwi3JSVJT o2MD56vhZZOwhhtKyGksK3/1qW0qiJeTsLMXBpcg= Date: Sun, 10 Mar 2019 10:09:32 +0000 From: Jonathan Cameron To: Fabrice Gasnier Cc: , , , , , , , , , , Subject: Re: [PATCH 1/8] iio: adc: stm32-dfsdm: make spi_master_freq more accurate Message-ID: <20190310100932.71fd1af1@archlinux> In-Reply-To: <1551862524-25098-2-git-send-email-fabrice.gasnier@st.com> References: <1551862524-25098-1-git-send-email-fabrice.gasnier@st.com> <1551862524-25098-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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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--; > 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");