Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp2475603img; Sun, 24 Mar 2019 09:42:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqwngp1W1f1+VbKXtkQJxhpm1Sqe88EG+zALYCVgQkXATYPJz65Yr+XX7jdMs6asGLE/1xBB X-Received: by 2002:a62:5789:: with SMTP id i9mr19265357pfj.75.1553445748372; Sun, 24 Mar 2019 09:42:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553445748; cv=none; d=google.com; s=arc-20160816; b=FCrlGj1ZMpiKK2YXm5gHKYv9XY7JjGYeoUAhXQpNtJtjrs60Oex3WiBur1yUxnh2lj 4Lgj5vUwF8JwcgY8mL8FplvDrH6i4zaMfyXysD+Gdz7BjnfWcnpxmoDOZ5riDG2IebLC nT9k8EqE2B/0z/Rq6zFe3aV1ZVzuPAtsFqaRrOlvaIG6+Mr31fq8LUDS0v6CpJxr+x0A 9bmKdAh2YKeL4uW7DYluzqN7ZALtKhJorRDJ2fade4t+bgfnNMeWCTqf2fo8gkyb4Rfr Wsd7A/6dmhbcTWrogrGqY8QoVjaK4BTWofJr3+vjPfwYdl/YjBklY9zGr/ydTSVcjQF0 vq6A== 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=T3vfXBT9Z+IOXpX9/qCXFsT5i1+L3XA13vl4LAORwOE=; b=k231baFw5zC3lZQp3Xl+glTQYZybHEml8fNwPmPvhZz3LscPdjOlTqg32TvRyEVwEw WKeHfj1IWmOgD53nwnxVp6xnGro8uVnId/91e1pmoug62+5Mqbrjp3wqxAWrRFFda8VY H/m/22K6Ul4DFLspLTF7ZR7qSlXRygz9vyK295sDBroKiC+dDNp44HYkTwEol4jQMMa7 uF5K1McaTsw8iwjuteAfnSxv/QJI3s1OJainVwoC8O65QIWnablutLnvJ0M//AKieCcD rbScb/kaRnv5j2wvM/o48XzBOsOcFLlsCoIbL2LGUuKB5sSJIFvCsq8byzQyAFGbRXHI j7SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MkcIj+tA; 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 f3si11739509pfc.158.2019.03.24.09.42.12; Sun, 24 Mar 2019 09:42:28 -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=MkcIj+tA; 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 S1727737AbfCXQlg (ORCPT + 99 others); Sun, 24 Mar 2019 12:41:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:53490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726317AbfCXQlg (ORCPT ); Sun, 24 Mar 2019 12:41:36 -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 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 Cc: , , , , , , , , , , 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 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 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");