Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3952338imb; Wed, 6 Mar 2019 01:25:39 -0800 (PST) X-Google-Smtp-Source: APXvYqxrP6IfugnkwoExTsWYB/Givy4xhgVuYvEcuu4XYy0eTLuXxHLhibG84kjWqrUdu2pm9xt9 X-Received: by 2002:a17:902:9001:: with SMTP id a1mr5933379plp.96.1551864339264; Wed, 06 Mar 2019 01:25:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551864339; cv=none; d=google.com; s=arc-20160816; b=06AEwr+TTRTV5IQtMbVv7UEWOMfZrQSVMf+ap+d/5B7+GUR2QS3j3d7BZxYIYyFhiO ouG9NmO8XMHmUli2hp5vfHtPwM8OxdNIgKTnsBBOJpBhBTbyPfru9k4eJMuS+/7IrAe3 x2L5/Ds0ZJnNqxDPlWa97bnqzQ4hnVzvykDbrUJKibvBPtMj+WzYRpibJi9xZ4oz7MSI QLs9YZ/cmDnEsJk5JbQhWEBr/TOiuog3p09RYa7calE1pKxDQl/8HrLHrztJxJOE3Cgx /KYvBSBUIrXlq+qWrVfRs8gXOHiBq6c1fZs/QcgL55tNWMekOJOFiUW8tcyouB3GIR3v Bi9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=EwjwzvSmcnGcmwdnnABvtUoWCAAxPb/0urDH18SFcKU=; b=ymAKN2N7Xx/xanAnb6SytRKTfynlLW2GvQptW6uyR88WY5ZEVP3eFHY5qNiBzRdbc+ yA82kCUZ8VdJiKJrG7TLTNtQhV7FjYYls38nr6Y19n2niLmrVVTbXjhzskCZnAAAaYtH ZZZWBPBeH6t6ILZbn5wlubHKfmzrraxfjf2KX19uh0dW579j2Bo/VTM4bYyj2SKTH5Ff sl9lVDD6R0tPQFgLiqSb7vnIFgvMPtjnobRiBFguwMFCVhpi+ZHMMniN+pL+3yPCR3Hs DI/4Nc5iP/TlFNou6PB5PsrygRgh5pFlrW2oYcsIrQ+/eTbsoYKLWPY8zsLbUOiuhWez ToAA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d16si1001142pgv.70.2019.03.06.01.25.24; Wed, 06 Mar 2019 01:25:39 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729581AbfCFI4X (ORCPT + 99 others); Wed, 6 Mar 2019 03:56:23 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:58413 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729562AbfCFI4W (ORCPT ); Wed, 6 Mar 2019 03:56:22 -0500 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 x268p4eU001192; Wed, 6 Mar 2019 09:55:49 +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 2r0ju8yewp-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 06 Mar 2019 09:55:49 +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 585C342; Wed, 6 Mar 2019 08:55:48 +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 0EE9423F7; Wed, 6 Mar 2019 08:55:48 +0000 (GMT) Received: from localhost (10.75.127.46) by SFHDAG5NODE3.st.com (10.75.127.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 6 Mar 2019 09:55:47 +0100 From: Fabrice Gasnier To: CC: , , , , , , , , , , , Subject: [PATCH 1/8] iio: adc: stm32-dfsdm: make spi_master_freq more accurate Date: Wed, 6 Mar 2019 09:55:17 +0100 Message-ID: <1551862524-25098-2-git-send-email-fabrice.gasnier@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1551862524-25098-1-git-send-email-fabrice.gasnier@st.com> References: <1551862524-25098-1-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG7NODE3.st.com (10.75.127.21) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-06_06:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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--; + 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); if (rem) { dev_warn(&pdev->dev, "SPI clock not accurate\n"); -- 2.7.4