Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4260517pxb; Tue, 31 Aug 2021 00:17:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwR+hWZs39AS1JkNJAqnrewk9xCY4LnHDBTfSj8oFIp4TNm5PxN7q1WeeJ7nHmve32tE5xn X-Received: by 2002:a02:ce37:: with SMTP id v23mr1510251jar.81.1630394247566; Tue, 31 Aug 2021 00:17:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630394247; cv=none; d=google.com; s=arc-20160816; b=vC1/Iyxm6fuOKFDd3BdkCy7Sy2dbge94IHgKLAF4OUoxGnhk3VUI3mY50c/hPIz53l xz/MboiPDfshB2Dha8/QMmqXCfIf6vF/cv4q5yOpmpVvLTlzB9b9r/8aCQOX+PdexsnU obDzLkvHmF4xvUBEmVrZ6KUnGNMqXH6bmNzhVJwwe0foNDql7OeuG5vjwSkY5zLQnqEk AdWRLBnPLdsFG8WDP3Zy7xQ8oX034oq+NBZ7KY4SLrw1GtwJNZrDqfTMJxPuqSbsFkhN JTiV23aXbJIbeLovrkTv9/t3GYMOYOEorjtUpy/bRDtUr7N9kFXW36Z8VRs1CTAVaHWn gzwA== 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:date:subject:cc:to:from; bh=aabTbT9pFxVDRKHydP7KMmpE13Xab+v7slmDnsEFVnc=; b=KnmYxn0jZfK0kiRxp5VCkUyXTnVc02IPd5LhpO3ymdi+za26ntTasLyL4lsteRgOEJ WWbuL19MZx4xwfieRkdHIfGbDg96437piakeevmcYONYcaRxns42Y1QJIUf0NxytJeK7 zir4rFZEbOM1mccAXR6SLY00k1vPFf7a+vdWv+6dsBETxs7r/aRQJD+8k1dJ5vaiLecT Hvjy1p3q384ENz8k4QGeivNZztqGy7moJxcrjaN8h9/balw0m4SMVGR0gISRM/ogBmoT 56Inr2lZ75eBGf3uyKde4AiVlGSsDxnhw1nyOXKPhpmiUojw0SLWe/WIZXFlEF+jlCBD lwEw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y15si16529845ioa.67.2021.08.31.00.17.16; Tue, 31 Aug 2021 00:17:27 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239815AbhHaHRD (ORCPT + 99 others); Tue, 31 Aug 2021 03:17:03 -0400 Received: from twspam01.aspeedtech.com ([211.20.114.71]:36745 "EHLO twspam01.aspeedtech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239758AbhHaHQx (ORCPT ); Tue, 31 Aug 2021 03:16:53 -0400 Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 17V6sc5v028274; Tue, 31 Aug 2021 14:54:38 +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; Tue, 31 Aug 2021 15:13:36 +0800 From: Billy Tsai To: , , , , , , , , , , , , , CC: Subject: [v5 11/15] iio: adc: aspeed: Fix the calculate error of clock. Date: Tue, 31 Aug 2021 15:14:54 +0800 Message-ID: <20210831071458.2334-12-billy_tsai@aspeedtech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210831071458.2334-1-billy_tsai@aspeedtech.com> References: <20210831071458.2334-1-billy_tsai@aspeedtech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 17V6sc5v028274 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ADC clock formula is ast2400/2500: ADC clock period = PCLK * 2 * (ADC0C[31:17] + 1) * (ADC0C[9:0] + 1) ast2600: ADC clock period = PCLK * 2 * (ADC0C[15:0] + 1) They all have one fixed divided 2 and the legacy driver didn't handle it. This patch register the fixed factory clock device as the parent of ADC clock scaler to fix this issue. Signed-off-by: Billy Tsai --- drivers/iio/adc/aspeed_adc.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/iio/adc/aspeed_adc.c b/drivers/iio/adc/aspeed_adc.c index 40b7ba58c1dc..349377b9fac0 100644 --- a/drivers/iio/adc/aspeed_adc.c +++ b/drivers/iio/adc/aspeed_adc.c @@ -4,6 +4,12 @@ * * Copyright (C) 2017 Google, Inc. * Copyright (C) 2021 Aspeed Technology Inc. + * + * ADC clock formula: + * Ast2400/Ast2500: + * clock period = period of PCLK * 2 * (ADC0C[31:17] + 1) * (ADC0C[9:0] + 1) + * Ast2600: + * clock period = period of PCLK * 2 * (ADC0C[15:0] + 1) */ #include @@ -85,6 +91,7 @@ struct aspeed_adc_data { struct regulator *regulator; void __iomem *base; spinlock_t clk_lock; + struct clk_hw *fixed_div_clk; struct clk_hw *clk_prescaler; struct clk_hw *clk_scaler; struct reset_control *rst; @@ -204,6 +211,13 @@ static void aspeed_adc_unregister_divider(void *data) clk_hw_unregister_divider(clk); } +static void aspeed_adc_unregister_fixed_divider(void *data) +{ + struct clk_hw *clk = data; + + clk_hw_unregister_fixed_factor(clk); +} + static void aspeed_adc_reset_assert(void *data) { struct reset_control *rst = data; @@ -328,6 +342,19 @@ static int aspeed_adc_probe(struct platform_device *pdev) spin_lock_init(&data->clk_lock); snprintf(clk_parent_name, ARRAY_SIZE(clk_parent_name), "%s", of_clk_get_parent_name(pdev->dev.of_node, 0)); + snprintf(clk_name, ARRAY_SIZE(clk_name), "%s-fixed-div", + data->model_data->model_name); + data->fixed_div_clk = clk_hw_register_fixed_factor( + &pdev->dev, clk_name, clk_parent_name, 0, 1, 2); + if (IS_ERR(data->fixed_div_clk)) + return PTR_ERR(data->fixed_div_clk); + + ret = devm_add_action_or_reset(data->dev, + aspeed_adc_unregister_fixed_divider, + data->clk_prescaler); + if (ret) + return ret; + snprintf(clk_parent_name, ARRAY_SIZE(clk_parent_name), clk_name); if (data->model_data->need_prescaler) { snprintf(clk_name, ARRAY_SIZE(clk_name), "%s-prescaler", -- 2.25.1