Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2625282pxb; Sun, 8 Nov 2020 07:20:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJylL3VV4n/ObbPoI4eN4dqk1pyeJGdABUcSFn8NkD7p8DUTfyXqFb0sbcz5lrDlY+LZPhFq X-Received: by 2002:aa7:c44d:: with SMTP id n13mr11651000edr.138.1604848823056; Sun, 08 Nov 2020 07:20:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604848823; cv=none; d=google.com; s=arc-20160816; b=gv789DyOnvJYynsBawk7/kymbiIBFpRqApEhKI9vI3FIehXd5NGFQIleJPRYgt89Gw oht8HvhKK72ZQpYaSAfpRxC/wr05r9lif2z4QXZChplZNSkx2BTbKvHqWNxu3fY6Nfdx 6Bm140y5aLAdOs77WTg7Zf3xGgUNSV9B42OLgUbUd1FWtxOcta6DTWPron+3A4utns5z tp3/Sr19m6ysye/5Bot0GnwLQwuKcPFrebzEqBgj0qIQNzGwkIyIPdX9q3SMauCC7Oy+ zn/efT2NyRoDSA1Py6cJXK46N9Y3Z9TgPGXnhyUL4N7DV6BX2Vee+NYBTNQn5c4KljgF Dg8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=v+kTI5FvTTmEvWVT+vNXNzUGVXMm6Jy0NhYfbIaHXzc=; b=as8QPfFs2KEekgi0r6dyAYDYT35aOyKyQZIzKHcDmPDU4+OdTtBbuW91yw74dkYk4o TnKOjTO5CO+qGCN9gF9wM8YyJ9BNj+ELsC/xugikSd+Oafi0I7LZ8n5wreBqNquYKwyO EAVrjYPafAXdFF7ra2Rfl0nBZgXNJ6hUQa68L/d4Iy1YqIdUGrmiXp1LH9EEwZpxWtEV t2SnE9Baxl02Ab1n4OyaU7e/sNpKrzyDV75BN+DGFpSpBSzWwFrwr7DvQ3lq0EXlo7da sLQKt+Tco5tM00IeCWnU01Oqeu0qsRBqjg/+VPQ5pFP+XuVTjzprDTcuyznh0DFnE88w jK1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=q9I7aJ5F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id f1si5296064eja.366.2020.11.08.07.19.59; Sun, 08 Nov 2020 07:20:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=q9I7aJ5F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728191AbgKHPSf (ORCPT + 99 others); Sun, 8 Nov 2020 10:18:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:48898 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727844AbgKHPSe (ORCPT ); Sun, 8 Nov 2020 10:18:34 -0500 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (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 0BECD206B2; Sun, 8 Nov 2020 15:18:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604848714; bh=0CKqtqq+aeOYU19z0fE06Ud/SoL1fEHH0qhlYS0YDvA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=q9I7aJ5FbsgvzNIO+z+3NEbam63dMAi7KBjxsSj5vfVcm4uc9lcktJmnH7JHQ9noV q7Pip2DbokpPTkthZV87efexmfNYuhUWO2FYwR/Y2ZTu3Qj7d+rZ6NirYkDD7QQOAd 6mnaOyVj4H/j+8PnbUxlJUOd0TwdrqqiOykqmhCU= Date: Sun, 8 Nov 2020 15:18:35 +0000 From: Jonathan Cameron To: Fabrice Gasnier Cc: , , , , , Subject: Re: [PATCH] iio: adc: stm32-adc: adapt clock duty cycle for proper operation Message-ID: <20201108151835.5d78ebca@archlinux> In-Reply-To: <1604681846-31234-1-git-send-email-fabrice.gasnier@st.com> References: <1604681846-31234-1-git-send-email-fabrice.gasnier@st.com> X-Mailer: Claws Mail 3.17.7 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 6 Nov 2020 17:57:26 +0100 Fabrice Gasnier wrote: > For proper operation, STM32 ADC should be used with a clock duty cycle > of 50%, in the range of 49% to 51%. Depending on the clock tree, divider > can be used in case clock duty cycle is out of this range. > In case clk_get_scaled_duty_cycle() returns an error, kindly apply a > divider by default (don't make the probe fail). > > Signed-off-by: Fabrice Gasnier Hi Fabrice, This sounds like it's a fix for a situation in which the device is not currently working? If so, please let me know a fixes tag. Thanks, Jonathan > --- > drivers/iio/adc/stm32-adc-core.c | 21 ++++++++++++++++++++- > 1 file changed, 20 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c > index cd870c0..d64a9e8 100644 > --- a/drivers/iio/adc/stm32-adc-core.c > +++ b/drivers/iio/adc/stm32-adc-core.c > @@ -202,7 +202,7 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev, > { > u32 ckmode, presc, val; > unsigned long rate; > - int i, div; > + int i, div, duty; > > /* stm32h7 bus clock is common for all ADC instances (mandatory) */ > if (!priv->bclk) { > @@ -226,6 +226,11 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev, > return -EINVAL; > } > > + /* If duty is an error, kindly use at least /2 divider */ > + duty = clk_get_scaled_duty_cycle(priv->aclk, 100); > + if (duty < 0) > + dev_warn(&pdev->dev, "adc clock duty: %d\n", duty); > + > for (i = 0; i < ARRAY_SIZE(stm32h7_adc_ckmodes_spec); i++) { > ckmode = stm32h7_adc_ckmodes_spec[i].ckmode; > presc = stm32h7_adc_ckmodes_spec[i].presc; > @@ -234,6 +239,13 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev, > if (ckmode) > continue; > > + /* > + * For proper operation, clock duty cycle range is 49% > + * to 51%. Apply at least /2 prescaler otherwise. > + */ > + if (div == 1 && (duty < 49 || duty > 51)) > + continue; > + > if ((rate / div) <= priv->max_clk_rate) > goto out; > } > @@ -246,6 +258,10 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev, > return -EINVAL; > } > > + duty = clk_get_scaled_duty_cycle(priv->bclk, 100); > + if (duty < 0) > + dev_warn(&pdev->dev, "bus clock duty: %d\n", duty); > + > for (i = 0; i < ARRAY_SIZE(stm32h7_adc_ckmodes_spec); i++) { > ckmode = stm32h7_adc_ckmodes_spec[i].ckmode; > presc = stm32h7_adc_ckmodes_spec[i].presc; > @@ -254,6 +270,9 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev, > if (!ckmode) > continue; > > + if (div == 1 && (duty < 49 || duty > 51)) > + continue; > + > if ((rate / div) <= priv->max_clk_rate) > goto out; > }