Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2994725pxv; Sun, 27 Jun 2021 15:41:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzus70Q9QPc/uXldoA5aJrd9umBZOYhqmrtbBUC9KbDw+w3dqlIXHxtwqEn8t91jYfLBj10 X-Received: by 2002:a05:6e02:1c2f:: with SMTP id m15mr17287159ilh.304.1624833663218; Sun, 27 Jun 2021 15:41:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624833663; cv=none; d=google.com; s=arc-20160816; b=uYBVwtSyhSTX6gZpjKyQDiiVcn41ie3Nxo1Jk5Fh4TJxqB+r6oS7kPlqFfI44bD+Gg 0WpThpCwqn6c8E+f3qLJ1TLaIB/pOEcB7kULCiVD3a8pjuf9BQtDe8vwgI7jwrhJUQ05 WpZKnAdVXBYdTM53mB6Aj3CXX5E8NXfM3SkhPvzAeEOKXVNKMsiwhctZJpUHPwOSHHW2 C3r7wYg7e5GYNNYYQaooFlL5femdOd1dc0a/rxJE2aV25BgY2RJjMg0lObUtTk0juRSD 5JiAJAp/HmHM/dklz+/V3GMy5iY/6DhX7vIkxOP5W8CX0xN9VBsRnysR7qPEh2uMVdsN Zl+g== 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 :dkim-signature; bh=PGONBXxvlhJmqdlV0gc3mwlikq8hNJaflhau0UlR32c=; b=i8szL49CjqN9Q8br7+e0CeYayGKufbyJrXkbbPfZ2ICCcp8mx2nOe1MRVK8KRO8np7 pkOBZ6ldA12RTSIKx2zp+neM1U8agO6w1n7YEWs8iEOGQHftvQPj3NxE2jtIWfyPfpP2 6JRoGosyvImZfl1xqxKHYXvbkUJJpD9tUr+dZMi4mxcwoBsWtdf3R/AS5u6yPRMDyHOG 6/Vbag/g4etnkLEhpqb5egh5StZIHMyoil15ujXrJ05IEk57mBtibaDt68t30SRptu5y D7GFHkQt9vhOvLtSLYFldR/Z8pGcmfTELq3k5TRQVCgPRiUgk270TN/iT06JDuhgRAJf lHkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20161025 header.b=tZrzV+ig; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a12si5960261ion.18.2021.06.27.15.40.50; Sun, 27 Jun 2021 15:41:03 -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; dkim=pass header.i=@googlemail.com header.s=20161025 header.b=tZrzV+ig; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231864AbhF0Wmq (ORCPT + 99 others); Sun, 27 Jun 2021 18:42:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231818AbhF0Wmp (ORCPT ); Sun, 27 Jun 2021 18:42:45 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DFFFC061766; Sun, 27 Jun 2021 15:40:20 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id q14so22642267eds.5; Sun, 27 Jun 2021 15:40:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PGONBXxvlhJmqdlV0gc3mwlikq8hNJaflhau0UlR32c=; b=tZrzV+ig6jKUQBbzQWnL09J6iWbBXMV6GCuURJsqjq/LgXjRJkkGGoivmqEqqOLnUG IdxSmPH8hvG/bHKoVrNBur1zg80tQ7vjBWb6tMpa6SjEt9BZsvIUP817R3FwS7R+3s1+ efcA74IJEoL8Ld52nywX7Afxkdba3Tk+pqimGw6MYVudeiVpq75O3xpinBAd3irc4eQL jOI+NEfYN2iZW8DaFj5s6MYteT2hLpptvQ5wKKNC6SDux7rNsfsxxeeQ4BZp+5Agh3qH l2qyTIMuXAyB+Z1Fq7eZtWJ+xwDcfGqrKGIRl+DesRHahvXHsr5ToMK3F3VfG4OHsNur zl5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PGONBXxvlhJmqdlV0gc3mwlikq8hNJaflhau0UlR32c=; b=cqO2mG25LrX/TH6iBPZmu/abJCDX+hKCUpXgNMR9Qa0HSmXgYLAhjyv2vDZbTLrPRm 4+EkqJhKaIzCbooSxNSlosZ0zCZkdmO3CvVpdsHf5sbuY9eIqk6EynhW3K2jbFPTCJAn LN3nG7j1H1vjVeqVqdpAXlIAQLa8u8mERFb6nnwM44mf9gXP2Y5kB3epIZfUmFAPW9ed 8nUZ2GOHcSpdLksY84m78qmm2Dpq3P7uS4s97RFQFmux9mFe5fgjb5zB8QlAQTTQkhW6 fekgzGEif5spXLlSV7qWwVP4uWOC5kL8PtJoHMFbRvplEzng+DbW3hldsHoVStvIggfM kOZw== X-Gm-Message-State: AOAM531BErNlw27zJ8TCXh2kEULK2rXAhbyZIVt3oDfIlvoEeKLKk+0P c6+jI0kjg85spl1t7g1lfa0dmKRVVYM= X-Received: by 2002:a05:6402:1103:: with SMTP id u3mr29293230edv.342.1624833618675; Sun, 27 Jun 2021 15:40:18 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a01-0c23-bd64-8b00-f22f-74ff-fe21-0725.c23.pool.telefonica.de. [2a01:c23:bd64:8b00:f22f:74ff:fe21:725]) by smtp.googlemail.com with ESMTPSA id jz27sm6048861ejc.33.2021.06.27.15.40.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Jun 2021 15:40:18 -0700 (PDT) From: Martin Blumenstingl To: mturquette@baylibre.com, sboyd@kernel.org, linux-clk@vger.kernel.org Cc: narmstrong@baylibre.com, jbrunet@baylibre.com, khilman@baylibre.com, linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Martin Blumenstingl Subject: [PATCH v3 1/3] clk: divider: Add re-usable determine_rate implementations Date: Mon, 28 Jun 2021 00:39:57 +0200 Message-Id: <20210627223959.188139-2-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210627223959.188139-1-martin.blumenstingl@googlemail.com> References: <20210627223959.188139-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These are useful when running on 32-bit systems to increase the upper supported frequency limit. clk_ops.round_rate returns a signed long which limits the maximum rate on 32-bit systems to 2^31 (or approx. 2.14GHz). clk_ops.determine_rate internally uses an unsigned long so the maximum rate on 32-bit systems is 2^32 or approx. 4.29GHz. To avoid code-duplication switch over divider_{ro_,}round_rate_parent to use the new divider_{ro_,}determine_rate functions. Reviewed-by: Jerome Brunet Signed-off-by: Martin Blumenstingl --- drivers/clk/clk-divider.c | 75 +++++++++++++++++++++++++++++------- include/linux/clk-provider.h | 6 +++ 2 files changed, 67 insertions(+), 14 deletions(-) diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index 344997203f0e..87ba4966b0e8 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -343,16 +343,63 @@ static int clk_divider_bestdiv(struct clk_hw *hw, struct clk_hw *parent, return bestdiv; } +int divider_determine_rate(struct clk_hw *hw, struct clk_rate_request *req, + const struct clk_div_table *table, u8 width, + unsigned long flags) +{ + int div; + + div = clk_divider_bestdiv(hw, req->best_parent_hw, req->rate, + &req->best_parent_rate, table, width, flags); + + req->rate = DIV_ROUND_UP_ULL((u64)req->best_parent_rate, div); + + return 0; +} +EXPORT_SYMBOL_GPL(divider_determine_rate); + +int divider_ro_determine_rate(struct clk_hw *hw, struct clk_rate_request *req, + const struct clk_div_table *table, u8 width, + unsigned long flags, unsigned int val) +{ + int div; + + div = _get_div(table, val, flags, width); + + /* Even a read-only clock can propagate a rate change */ + if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) { + if (!req->best_parent_hw) + return -EINVAL; + + req->best_parent_rate = clk_hw_round_rate(req->best_parent_hw, + req->rate * div); + } + + req->rate = DIV_ROUND_UP_ULL((u64)req->best_parent_rate, div); + + return 0; +} +EXPORT_SYMBOL_GPL(divider_ro_determine_rate); + long divider_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent, unsigned long rate, unsigned long *prate, const struct clk_div_table *table, u8 width, unsigned long flags) { - int div; + struct clk_rate_request req = { + .rate = rate, + .best_parent_rate = *prate, + .best_parent_hw = parent, + }; + int ret; - div = clk_divider_bestdiv(hw, parent, rate, prate, table, width, flags); + ret = divider_determine_rate(hw, &req, table, width, flags); + if (ret) + return ret; - return DIV_ROUND_UP_ULL((u64)*prate, div); + *prate = req.best_parent_rate; + + return req.rate; } EXPORT_SYMBOL_GPL(divider_round_rate_parent); @@ -361,23 +408,23 @@ long divider_ro_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent, const struct clk_div_table *table, u8 width, unsigned long flags, unsigned int val) { - int div; - - div = _get_div(table, val, flags, width); + struct clk_rate_request req = { + .rate = rate, + .best_parent_rate = *prate, + .best_parent_hw = parent, + }; + int ret; - /* Even a read-only clock can propagate a rate change */ - if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) { - if (!parent) - return -EINVAL; + ret = divider_ro_determine_rate(hw, &req, table, width, flags, val); + if (ret) + return ret; - *prate = clk_hw_round_rate(parent, rate * div); - } + *prate = req.best_parent_rate; - return DIV_ROUND_UP_ULL((u64)*prate, div); + return req.rate; } EXPORT_SYMBOL_GPL(divider_ro_round_rate_parent); - static long clk_divider_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 162a2e5546a3..d83b829305c0 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -629,6 +629,12 @@ long divider_ro_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent, unsigned long rate, unsigned long *prate, const struct clk_div_table *table, u8 width, unsigned long flags, unsigned int val); +int divider_determine_rate(struct clk_hw *hw, struct clk_rate_request *req, + const struct clk_div_table *table, u8 width, + unsigned long flags); +int divider_ro_determine_rate(struct clk_hw *hw, struct clk_rate_request *req, + const struct clk_div_table *table, u8 width, + unsigned long flags, unsigned int val); int divider_get_val(unsigned long rate, unsigned long parent_rate, const struct clk_div_table *table, u8 width, unsigned long flags); -- 2.32.0