From patchwork Mon Feb 21 01:27:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Billy Tsai X-Patchwork-Id: 12752970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 080A1C433EF for ; Mon, 21 Feb 2022 02:10:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=GkjziwpY+nCmDvnUpz3cEtWxb2fx+8nLIH7c22mXu50=; b=jOu2f8/D0T8JXN TWsEaDozHzvNYMMtI6Ub60GL7GiQ5zxUwf46UrjTbfm1vYUIB0HpM6SXLzF33DC1Kr14x9pdUdFcZ deZo6iGVODa8bUDYXwXvRa/F4QT6BctwYjNchmltHTRmR92Krml6oFF4Cw6bjyxteQbOmgJGF5k4V izXRMQ+pM39fx2vJYlBHqagq36qKGDvLXkORsO3JJNVsnQSd9j11i7pDvU2/wV/K75/JcaetxQAXv d9KQir5hVTFmuCWEvQQTWhNq6jF0aNEKSsvrbojshkUvR17J1DNhVkEzaR/O6mEkgS6/uCOXM3Y1y 2o4aAfWIlHWo1uZggojA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nLy8F-002wdN-9S; Mon, 21 Feb 2022 02:08:56 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nLy84-002wbA-9a for linux-arm-kernel@bombadil.infradead.org; Mon, 21 Feb 2022 02:08:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To:Content-ID: Content-Description:In-Reply-To:References; bh=mzm/kWfpukJths2pn7LLE344YXf6Ex3dJSrJ+cquLKU=; b=PzosTCZkrKr3LUxvHYHCMvlxN3 GBD5V06Vp8vJg2o0B50up+ABeBqOqLZfDwHf/tnwCcpSK50ZDXH01DjiNoKJSKGDGSPciVRPFJsr7 kUuk9jioEQ9aw9M71N2eT2f3yA0ayEwNHAzDIfRDpAcY1CjIAadojGm2lXWkRrchkuP2iGWz6gUp0 CBmc3b+mJ1dHhtaVzqH4W3hSQ8udYR/GSoKJ4X+bAKZ+hczwRdKaZrZ88Vt54l0YlBHW9fDn4Skk9 +OlEADNPD9e/Acvdrvf8k87B+Wy8QAiaNPIX4HcwCYWKFbEGswq3d4xeybKxjsFYHKDBR8/88ZyxH ptFxLNuA==; Received: from twspam01.aspeedtech.com ([211.20.114.71]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nLxUZ-00BWbA-VF for linux-arm-kernel@lists.infradead.org; Mon, 21 Feb 2022 01:27:59 +0000 Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 21L1HQCl026167; Mon, 21 Feb 2022 09:17:26 +0800 (GMT-8) (envelope-from billy_tsai@aspeedtech.com) Received: from BillyTsai-pc.aspeed.com (192.168.2.149) by TWMBX02.aspeed.com (192.168.0.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 21 Feb 2022 09:26:16 +0800 From: Billy Tsai To: , , , , , , , , , CC: Konstantin Klubnichkin Subject: [PATCH v2] iio: adc: aspeed: Add divider flag to fix incorrect voltage reading. Date: Mon, 21 Feb 2022 09:27:05 +0800 Message-ID: <20220221012705.22008-1-billy_tsai@aspeedtech.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [192.168.2.149] X-ClientProxiedBy: TWMBX02.aspeed.com (192.168.0.24) To TWMBX02.aspeed.com (192.168.0.24) X-DNSRBL: X-MAIL: twspam01.aspeedtech.com 21L1HQCl026167 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220221_012756_613489_20A34CD6 X-CRM114-Status: GOOD ( 12.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The formula for the ADC sampling period in ast2400/ast2500 is: ADC clock period = PCLK * 2 * (ADC0C[31:17] + 1) * (ADC0C[9:0]) When ADC0C[9:0] is set to 0 the sampling voltage will be lower than expected, because the hardware may not have enough time to charge/discharge to a stable voltage. This patch use the flag CLK_DIVIDER_ONE_BASED which will use the raw value read from the register, with the value of zero considered invalid to conform to the corrected formula. Fixes: 573803234e72 ("iio: Aspeed ADC") Reported-by: Konstantin Klubnichkin Signed-off-by: Billy Tsai Reviewed-by: Joel Stanley --- drivers/iio/adc/aspeed_adc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/aspeed_adc.c b/drivers/iio/adc/aspeed_adc.c index a957cad1bfab..ffae64f39221 100644 --- a/drivers/iio/adc/aspeed_adc.c +++ b/drivers/iio/adc/aspeed_adc.c @@ -539,7 +539,9 @@ static int aspeed_adc_probe(struct platform_device *pdev) data->clk_scaler = devm_clk_hw_register_divider( &pdev->dev, clk_name, clk_parent_name, scaler_flags, data->base + ASPEED_REG_CLOCK_CONTROL, 0, - data->model_data->scaler_bit_width, 0, &data->clk_lock); + data->model_data->scaler_bit_width, + data->model_data->need_prescaler ? CLK_DIVIDER_ONE_BASED : 0, + &data->clk_lock); if (IS_ERR(data->clk_scaler)) return PTR_ERR(data->clk_scaler);