Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2572495pxb; Tue, 24 Aug 2021 02:17:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSsYvXivcd4Nge8hdwBDaULsqE4rLQOtodPXybm+x9s45+CcbNy1jgtM1zBvswqlqSe1ju X-Received: by 2002:a17:906:bb03:: with SMTP id jz3mr41406899ejb.79.1629796651694; Tue, 24 Aug 2021 02:17:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629796651; cv=none; d=google.com; s=arc-20160816; b=I7ZZT6NdQnv7WU8bB3hJuwf3Vkc621rLelFGVH6qFX1YFGIRmilboIHFmvjEvrD5wl BytavO0wnPNDP/UsY0IYgudwvIfCzAmqkQwr/CRfV3LLqxIxI8sG2qvAZYz/D/0T3C6m SDHMN1ZcuVS0RYim9xBFR5wc7JtCdWJdyiDXDUskY4MWngimwzIVqhY+sR3HeAUhgHEn e9BmTxpQlVRu3oU1TC2oehXL/AW3NkWJznujRI98GIPzF7wpudItwOXaUfEUfQ030Oan zV9+hnxInXJ7YIBpEt7A1y2XJ8vTXDPi+UvApUBEkzlDP1Q7AXZ0GU17ULa2MFIc1p/y FQRw== 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=kmWxzrmH8m2sc5j47JvrXaT1iqRaEHAnjR9AITfD3Jg=; b=oNzWAAqwvdRJOzjYA0soyzdiExeuXOuT9b0tidnMm0RWY9/hoT5GEhercx5tjiv/E8 Np9nylfmBRXOuV0bZ6uXMpHSLU93KVdXQGSUeo8Zo/EyPz8wHEA6Ryi6Q87a/YTNRli1 MOZ1Wq6HT/7wygh6vRzb23mZ+ezuKzrQIA2kpLB9uHhFrHuiX+le0+2YkSp7EnujHqwM 9OUSGfwQ0x4SFhp2F63EAsd9M1p4x/mF2B0ncNZGHydRDLEoL4OQqlI1uCigldrHtY/i YRQKdarQyhAYIt7zWf7oKWSRutbnxGQmoJTkP1UMfDUB9NO8xD4/6Khixw6hMEHN8k2g /0Rw== 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 x5si17659229ejc.347.2021.08.24.02.17.03; Tue, 24 Aug 2021 02:17:31 -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 S235695AbhHXJP5 (ORCPT + 99 others); Tue, 24 Aug 2021 05:15:57 -0400 Received: from twspam01.aspeedtech.com ([211.20.114.71]:20697 "EHLO twspam01.aspeedtech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235060AbhHXJPs (ORCPT ); Tue, 24 Aug 2021 05:15:48 -0400 Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 17O8rGxk098402; Tue, 24 Aug 2021 16:53:16 +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, 24 Aug 2021 17:11:49 +0800 From: Billy Tsai To: , , , , , , , , , , , , , CC: Subject: [RESEND v4 11/15] iio: adc: aspeed: Fix the calculate error of clock. Date: Tue, 24 Aug 2021 17:12:39 +0800 Message-ID: <20210824091243.9393-12-billy_tsai@aspeedtech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824091243.9393-1-billy_tsai@aspeedtech.com> References: <20210824091243.9393-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 17O8rGxk098402 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The adc clcok 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 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/iio/adc/aspeed_adc.c b/drivers/iio/adc/aspeed_adc.c index ea3e9a52fcc9..8fe7da1a651f 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 @@ -77,6 +83,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; @@ -196,6 +203,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; @@ -312,6 +326,18 @@ static int aspeed_adc_probe(struct platform_device *pdev) /* Register ADC clock prescaler with source specified by device tree. */ spin_lock_init(&data->clk_lock); snprintf(clk_parent_name, 32, of_clk_get_parent_name(pdev->dev.of_node, 0)); + snprintf(clk_name, 32, "%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, 32, clk_name); if (data->model_data->need_prescaler) { snprintf(clk_name, 32, "%s-prescaler", data->model_data->model_name); -- 2.25.1