Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1595927pxb; Mon, 13 Sep 2021 00:55:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6ohS3tklDtVNwQvT7W/JtpJnWKDNja4e/BihkbR0Gm4E28B8p+2tH3TgiKvDojmM2XIvU X-Received: by 2002:a05:6e02:ef4:: with SMTP id j20mr7387872ilk.294.1631519719041; Mon, 13 Sep 2021 00:55:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631519719; cv=none; d=google.com; s=arc-20160816; b=io3olI4UeePXXDDyICydJFmvSaX4T5bEGpWLqPoEb56zxHuDsU81WtR4FMTg0Q9ErZ r81GuZ9g5ryk692m4pC3MVoHyjnM93YMezqyInl8F4rs0gmUUlh3+pmsr04rFaxnYhoF ELedwlTbpNI4mOBOhVO6LKS1bOs13hLZvaxKh2acBUjZzXccXISv/Tj4QZrDGJYKd108 MmTvLWIYE4GPFelDLS4ipU2HaMNz2ZC3u20dLOv+GX5Un0z8hzlF/uDLjdokJoorg54B nij4nRLdUOSdT/aFT2mHKZH1OVQS5VAh+XkXn8xviTRaO3P/jTlbOvAKf5r1szenpwUg SlpQ== 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=FjvecZm7kbZskuhHIsAe1ePmASxrCeLqua/lI+lxF+E=; b=JKms1o84nV00Pgb0XVjMVyE9LL/dZVURrsZMBW4JJ+TmXzVFVwC+FLmx45KuDIGL3k c5pPpmTRloZLDWi6fHHme8cODIjfitNQIDajzcoJig04k7en4JTN6DX1566u/lPtry6b 9A4Td/zRhQ6r5dW9OyXs7Jk+Ym1FVRMJoJJCUGZSgdQcHgArE8+ms3kN7nsimCldgrMc EXU7pOBcQnFC27rQ7Zf18qqa7EHw6NDkMAIwRwUOVzn2uPRDizPLkloGU5bcu5kGg5mD E8Lx4rFedM+k1RCmJk6V/Ed4byPCZHz4onDlp5d+Ahc2mNgbMAeZG/+RFSYp66lFEnqX xTuw== 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 y12si5873431ilh.146.2021.09.13.00.55.08; Mon, 13 Sep 2021 00:55:19 -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 S237992AbhIMHz3 (ORCPT + 99 others); Mon, 13 Sep 2021 03:55:29 -0400 Received: from twspam01.aspeedtech.com ([211.20.114.71]:18183 "EHLO twspam01.aspeedtech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237692AbhIMHz1 (ORCPT ); Mon, 13 Sep 2021 03:55:27 -0400 Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 18D7VMo9004722; Mon, 13 Sep 2021 15:31:22 +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, 13 Sep 2021 15:51:07 +0800 From: Billy Tsai To: , , , , , , , , , , , , , CC: Subject: [v6 07/11] iio: adc: aspeed: Fix the calculate error of clock. Date: Mon, 13 Sep 2021 15:53:33 +0800 Message-ID: <20210913075337.19991-8-billy_tsai@aspeedtech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210913075337.19991-1-billy_tsai@aspeedtech.com> References: <20210913075337.19991-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 18D7VMo9004722 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..262b5f80c728 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->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