Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp262018pxb; Wed, 22 Sep 2021 01:20:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzA277hcHq6gKM4pn82EgXQBZLS6BAsCpB/dhrHmrRy082E0opTtqpwiGa5UFUrTOTmtppB X-Received: by 2002:a17:906:2bc7:: with SMTP id n7mr38649983ejg.238.1632298808877; Wed, 22 Sep 2021 01:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632298808; cv=none; d=google.com; s=arc-20160816; b=DSosF7+ndk6dBBOtP30eXLd01fyvyEr8AcODMksz3geCjJb9U50zKC/Io9KceksKyf rn4GS1sgvxqsV7CZRD1UzNuava8bHo4jjliKtJEk1thyC+WrKhZ/U7JciAR98/da2E64 mQBbF5MmNNz3xIdtpfaN/YYzMFbIvMk8kX+KC2zVzUcInvvr24LMkIiTZzAJLWBNXd0U dletXLQu6RY+4ltB6gp8Q+bbofK2bv0nhAB3ybw26J3h/cXRwKa0qBD067IX77Qc4sEl 0xSiEM5/NqH+I6zcMCSfvoVXO8zp9r+09H2lfsc53qKnwwdXnwGAxjy4DpgHjnkRYLRB 4d2Q== 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=pA/5AtQInJyeurr9C+fpayS5jjbU2vsVxo0hkXoB2zs=; b=bOkJHTtUnMRDz45PQfejZ4mqn1Qeb9Sio47aU63SEWWCcVgl27n/TNfIdTMoR50rne JjcJZOET92j2m1OBCZxVZ8K5TubrEJojaJyNvPNuVTDOMoJG2XV/nvozL8pxTxvGzOf2 BnWPokrosELV8Bj4KhTPtQNyTfpLzJwYUI/MOmx/5uXqeNakIpxtpcPJYfFn4uFFzlUR p9YiaBc+nwT1lfyns4lUWhXOq92ONA35tjE7Re2He7sbbaqRIZ7ghNCHEpcTIMRZ9fQE WehrddB4kHY2tW98OBzUVI20d9dlgfFNOUPLhrLb8JHXl1XxxHsUAongAk8j89tCZOQK Kn3w== 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 s2si1783136edy.454.2021.09.22.01.19.45; Wed, 22 Sep 2021 01:20:08 -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 S233867AbhIVISv (ORCPT + 99 others); Wed, 22 Sep 2021 04:18:51 -0400 Received: from twspam01.aspeedtech.com ([211.20.114.71]:14032 "EHLO twspam01.aspeedtech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233770AbhIVISq (ORCPT ); Wed, 22 Sep 2021 04:18:46 -0400 Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 18M7scjK099787; Wed, 22 Sep 2021 15: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; Wed, 22 Sep 2021 16:14:56 +0800 From: Billy Tsai To: , , , , , , , , , , , , , CC: Subject: [v7 07/11] iio: adc: aspeed: Fix the calculate error of clock. Date: Wed, 22 Sep 2021 16:15:16 +0800 Message-ID: <20210922081520.30580-8-billy_tsai@aspeedtech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210922081520.30580-1-billy_tsai@aspeedtech.com> References: <20210922081520.30580-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 18M7scjK099787 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 3ec4e1a2ddd3..a24be2a4f69c 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; @@ -197,6 +204,13 @@ static const struct iio_info aspeed_adc_iio_info = { .debugfs_reg_access = aspeed_adc_reg_access, }; +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; @@ -321,6 +335,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->fixed_div_clk); + 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