From patchwork Wed Feb 21 18:22:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 204352 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1217086dyc; Wed, 21 Feb 2024 10:23:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVvbxPWql4PwdwYc1FMpCTEidDv0JMqmGRPUvNgjo6LCZSyWgiKdvoJKe33KV7V9OrTH4CD28ui3GX2hJF5CZgMo9Petw== X-Google-Smtp-Source: AGHT+IH7++V57Rqr3UZHaXMHch/tzxIzqTpA67K/f1t3rP7hSLyvRrq4lGasUGyS3VkN3QOTkYlK X-Received: by 2002:a05:620a:1135:b0:787:3ac2:15ab with SMTP id p21-20020a05620a113500b007873ac215abmr19363409qkk.37.1708539790666; Wed, 21 Feb 2024 10:23:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708539790; cv=pass; d=google.com; s=arc-20160816; b=0T+HBuQdN+OV9mKFjSJ5zU1z1MYH8PiFIsNDIwrzsJ8Mr5/al+wbCXazuqB7pscJyw 5ExclTEi0pOF/Siy9KSX8OAxyD56rBx13lI0WN7WO9dybfTzg9foLVVHkGFwWfjLQsp+ vNgSoXO7lTCMVa3CBNEALJoCiCeq2I+1FGXxqp5iT6R4EULNlzdaH4CZ2lKGf4hKFJSc 0UZGTjREY4FVaCeogkdkI+jQwam6q88L/hib0K6nNheDhSI1WMfkSVggljfApY+EyiL2 /rMAyK9RS2ST4/tokiPfW/fpcNg9HFVYlU7p+5kg+9YIuQ27uWDiK89zuDgDHIj1OlhA EQ1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=4q8B4FHnqm+Q9SZFv8e202u5pyLWu9j+3pZ0RNxIqVE=; fh=x5R05joZrGxebVEAaczvDRwH1m7BAJpjuUh/Gh1YI/Y=; b=owPtQx9Kxzy0u54II+xAuGhNRzkm6ms+AYFDs5eZ3Z/WcgjK6dc/hQPPWY1LpH7fHU soxjq2vGvPMUtR5PBH5Na1mz5Gah4U4DqyH9reuPQbDOwXcVNAyP86TkGR+p+EP6vv3O 0XQDSDbiuiq6sdQ6Op8RI6HeXJuMtVzaQtXqsl3rLquuRlK/G2baXqkSb3z7BFlzZPCd qUQJ/pfWbzCPik/KOWhjU97F06HoUYnVIW/gI4eM55H6iLLjTqHr1R0RxZrrsAXVBOxV 5pAkoE2Hr/n2SX/7KNNnR4km/iQ1cLOnmo6Zprov+C3E7vwVHIUo1vxukcTtoO1qXHQn GWHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ChqVUceC; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-75268-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75268-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f5-20020a05620a20c500b0078786192e61si1703524qka.501.2024.02.21.10.23.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 10:23:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75268-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ChqVUceC; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-75268-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75268-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 71D301C23C72 for ; Wed, 21 Feb 2024 18:23:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80C3A86120; Wed, 21 Feb 2024 18:22:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ChqVUceC" Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D79E37FBD5; Wed, 21 Feb 2024 18:22:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708539737; cv=none; b=GwEhAvcUF2ggrpLBIYUtd4vtHNnbiXjR/ewYenRlth8aZXKJ9AHeZF7Vr7g0iVZ5sUz0nuPyBtBUFhsoZvH7MNWmrAEN6B1wToL6vmdJeBI1OA1iWxjMLOHm4AAbudO1lCWuYZPfp1noX4wCIdO2uQkXs/8lphGMRqWmhlWG32I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708539737; c=relaxed/simple; bh=RFY7ut+rYoNyROemcFQ4SPLXjLR+Hh3fj3dk+W3dUTY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UIrbOV1hE60lf79rP9jgheZCVRYpAnSfb1QvjvBLEyIBnH9TVGjz/c02eJyFU7URFKAXZE/qo6wVHoPAGuTSoNsn4wZtCtFo5sVCXm6zgZ2x0y/epK9K6A6QqgllZNC6d0ncANFHhEbIuhIJ9p6oM4vtiJgRvADAk6E6bInjcXw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ChqVUceC; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 3CF8B1C000B; Wed, 21 Feb 2024 18:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708539733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4q8B4FHnqm+Q9SZFv8e202u5pyLWu9j+3pZ0RNxIqVE=; b=ChqVUceCPkJTlZw8xSx2cVMM27qR9bmOYfIwNpzLYx/+AogIhe+3hXEJbS0j4sKsZbHHlp bcq8/zQVK7/akstNq074hnOEjBW85+8feh0zJHPWCMIAWetYICRvltgMW5ciHXx8gk9/Uh c6g7zNLsLJ/T2OLV26sV31PkGBTKWGqaP77eTPmNgd4kiMWKZanjJe1RfyT9+c5+02LUmA sr0LCfMZEcr8viAkmjKttUS74svJcyCLXNfc9F6WJlCvw7LEBIut2YbdZRMG7CAfZRPeIw eousLVtd0Mp6jWKlAq5kZYB52z2LqUb9Vf6KIr4c+D2fahK12rMFBGP5t2wExQ== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 21 Feb 2024 19:22:09 +0100 Subject: [PATCH v7 01/14] clk: fixed-factor: add optional accuracy support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240221-mbly-clk-v7-1-31d4ce3630c3@bootlin.com> References: <20240221-mbly-clk-v7-0-31d4ce3630c3@bootlin.com> In-Reply-To: <20240221-mbly-clk-v7-0-31d4ce3630c3@bootlin.com> To: Gregory CLEMENT , Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Thomas Bogendoerfer , Linus Walleij , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Philipp Zabel Cc: Vladimir Kondratiev , linux-mips@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Tawfik Bayouk , linux-gpio@vger.kernel.org, =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.13.0 X-GND-Sasl: theo.lebrun@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791533819440356752 X-GMAIL-MSGID: 1791533819440356752 Fixed factor clock reports the parent clock accuracy. Add flags and acc fields to `struct clk_fixed_factor` to support setting a fixed accuracy. The default if no flag is set is not changed: use the parent clock accuracy. Signed-off-by: Théo Lebrun --- drivers/clk/clk-fixed-factor.c | 28 +++++++++++++++++++++------- include/linux/clk-provider.h | 12 +++++++++++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c index b3e66202b942..bc2644a9bd7d 100644 --- a/drivers/clk/clk-fixed-factor.c +++ b/drivers/clk/clk-fixed-factor.c @@ -57,10 +57,22 @@ static int clk_factor_set_rate(struct clk_hw *hw, unsigned long rate, return 0; } +static unsigned long clk_factor_recalc_accuracy(struct clk_hw *hw, + unsigned long parent_accuracy) +{ + struct clk_fixed_factor *fix = to_clk_fixed_factor(hw); + + if (fix->flags & CLK_FIXED_FACTOR_FIXED_ACCURACY) + return fix->acc; + + return parent_accuracy; +} + const struct clk_ops clk_fixed_factor_ops = { .round_rate = clk_factor_round_rate, .set_rate = clk_factor_set_rate, .recalc_rate = clk_factor_recalc_rate, + .recalc_accuracy = clk_factor_recalc_accuracy, }; EXPORT_SYMBOL_GPL(clk_fixed_factor_ops); @@ -81,7 +93,7 @@ __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np, const char *name, const char *parent_name, const struct clk_hw *parent_hw, int index, unsigned long flags, unsigned int mult, unsigned int div, - bool devm) + unsigned long acc, unsigned int fixflags, bool devm) { struct clk_fixed_factor *fix; struct clk_init_data init = { }; @@ -105,6 +117,8 @@ __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np, fix->mult = mult; fix->div = div; fix->hw.init = &init; + fix->acc = acc; + fix->flags = fixflags; init.name = name; init.ops = &clk_fixed_factor_ops; @@ -152,7 +166,7 @@ struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev, unsigned int mult, unsigned int div) { return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, NULL, index, - flags, mult, div, true); + flags, mult, div, 0, 0, true); } EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_index); @@ -174,7 +188,7 @@ struct clk_hw *devm_clk_hw_register_fixed_factor_parent_hw(struct device *dev, unsigned long flags, unsigned int mult, unsigned int div) { return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, parent_hw, - -1, flags, mult, div, true); + -1, flags, mult, div, 0, 0, true); } EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_parent_hw); @@ -184,7 +198,7 @@ struct clk_hw *clk_hw_register_fixed_factor_parent_hw(struct device *dev, { return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, parent_hw, -1, flags, mult, div, - false); + 0, 0, false); } EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor_parent_hw); @@ -193,7 +207,7 @@ struct clk_hw *clk_hw_register_fixed_factor(struct device *dev, unsigned int mult, unsigned int div) { return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, NULL, -1, - flags, mult, div, false); + flags, mult, div, 0, 0, false); } EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor); @@ -240,7 +254,7 @@ struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev, unsigned int mult, unsigned int div) { return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, NULL, -1, - flags, mult, div, true); + flags, mult, div, 0, 0, true); } EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor); @@ -267,7 +281,7 @@ static struct clk_hw *_of_fixed_factor_clk_setup(struct device_node *node) of_property_read_string(node, "clock-output-names", &clk_name); hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, NULL, 0, - 0, mult, div, false); + 0, mult, div, 0, 0, false); if (IS_ERR(hw)) { /* * Clear OF_POPULATED flag so that clock registration can be diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 1293c38ddb7f..7ddc952c8c67 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -1084,18 +1084,28 @@ void of_fixed_factor_clk_setup(struct device_node *node); * @hw: handle between common and hardware-specific interfaces * @mult: multiplier * @div: divider + * @acc: fixed accuracy in ppb + * @flags: behavior modifying flags * * Clock with a fixed multiplier and divider. The output frequency is the * parent clock rate divided by div and multiplied by mult. - * Implements .recalc_rate, .set_rate and .round_rate + * Implements .recalc_rate, .set_rate, .round_rate and .recalc_accuracy + * + * Flags: + * * CLK_FIXED_FACTOR_FIXED_ACCURACY - Use the value in @acc instead of the + * parent clk accuracy. */ struct clk_fixed_factor { struct clk_hw hw; unsigned int mult; unsigned int div; + unsigned long acc; + unsigned int flags; }; +#define CLK_FIXED_FACTOR_FIXED_ACCURACY BIT(0) + #define to_clk_fixed_factor(_hw) container_of(_hw, struct clk_fixed_factor, hw) extern const struct clk_ops clk_fixed_factor_ops;