Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp2066800pxb; Sun, 5 Sep 2021 07:49:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5bLFaGJxunqYcjphmFj55TPMeJKDSKnWST00oLeMuUj6xmQ1ojsIt/xKd+iKitRpcXzre X-Received: by 2002:a17:906:350d:: with SMTP id r13mr9103713eja.408.1630853371140; Sun, 05 Sep 2021 07:49:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630853371; cv=none; d=google.com; s=arc-20160816; b=zFJkP5rXQASU6SgWUuMXETJkg7IRdvFBqixLJt7AVQV0e+yWQfC/1O32KxRzbHzCU/ tkEEgtnWPkvs8r94wzRpwk49b5em3+q3ocySNb63hEKHT3DxB4GwPQHKqj1LTuV72QvE AxeeOMzJcch6p4/KxN29sAorJaMk6/x0nJsJoZYeWkxc2Yiv013ATCaqg0DOzFB9/K/o eYbRRkttcMyfLY3qgE/aOkbVaNXbCDEhWil+63sue51FUifTyL/gi0iKwW1cdxIiugDf EjsyHAAJQqQ//iVY7cAjx8YJuN5MKTTPjX/JPUnlESSn5j2+0ubQ4WHzmYDEKLG3vbMx AVJw== 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:subject:cc:to:from:date; bh=c1W6xt3bBig1nLC7lsdwdnPZ3LytQY/riDjOkxQIELg=; b=Tx3Zllu1IoHNiyaIf+Axs/V7asAIIDJJxpacsnwHauiWjdBOHckzXGmYYOGHp7KsU/ y3GwHinS7uFloAClhG/tJLgRjyPvuaXRgk9dGHPTsk68zxkev9ct4pULGhY8jmVoNhdO SdIsVlA6CHA8UQE1ty2KIq3GjSNZ0IZE7H5abuI5r3trrAP1dvGGcNUdV5M8sQko0RdE W091uAnY2kLuYj8aSE7bqycOhiiooD7vN5zWHMGYfj8gvY82XVu8Itt8cRGX01OKWK9V kiDAofy615rV1p4ICrwCc4J4nZRFLmPfI9dCSqJwfZjBt2IYJPsRclaqvE2Mi2Y0Q91k fVbg== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si5426061ejc.100.2021.09.05.07.49.07; Sun, 05 Sep 2021 07:49: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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235218AbhIEOpX (ORCPT + 99 others); Sun, 5 Sep 2021 10:45:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:55682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232764AbhIEOpX (ORCPT ); Sun, 5 Sep 2021 10:45:23 -0400 Received: from jic23-huawei (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D3BBA60E8B; Sun, 5 Sep 2021 14:44:14 +0000 (UTC) Date: Sun, 5 Sep 2021 15:47:36 +0100 From: Jonathan Cameron To: Billy Tsai Cc: , , , , , , , , , , , , , Subject: Re: [v5 11/15] iio: adc: aspeed: Fix the calculate error of clock. Message-ID: <20210905154737.6c41bae0@jic23-huawei> In-Reply-To: <20210831071458.2334-12-billy_tsai@aspeedtech.com> References: <20210831071458.2334-1-billy_tsai@aspeedtech.com> <20210831071458.2334-12-billy_tsai@aspeedtech.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 31 Aug 2021 15:14:54 +0800 Billy Tsai wrote: > 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); Obvious follow on from Philipp's review - there is a devm_ version of this as well which you can use rather than rolling a custom version. As a side note, I'm fairly sure you could refactor all those devm_clk_hw functions to use devm_add_action_or_reset() internally and simplify that code nicely. A recent series did the same for all the similar functions in IIO. > + 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",