From patchwork Tue Sep 3 15:30:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3373 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 242E43F1F3 for ; Tue, 3 Sep 2024 17:31:05 +0200 (CEST) Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-42bb5950d1asf61945815e9.2 for ; Tue, 03 Sep 2024 08:31:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1725377465; cv=pass; d=google.com; s=arc-20240605; b=R+4vXYQTXuGnzye0DT0UurSAiJTRgKHvLLasEf3QxIpuJ0SsJC8qYv8PXlL1F+cxoU xkfQXALzrxtX58AeJA6OYU8SNtdr4dzS4JDeezVNFjr4l1APPi6Tyl9gaJMuCLEZOZs+ TqoWMrigGe8UQ8D6ftRflQlV47X01UfVygdUciqwM2XSdX5eDV3mizLlPraz8GLtdWRA XGbQvImPp5r1X2zKPGgmbH+47yvTAtP17p+yBtxdtCsQWQf4+ylNsjOnu7M2/3bee6iA 5ukVFvdT6iE9+NNxkZp+qG+rY2CDF8DUtjhmAWMrAaXGNFoCqi0pF7KN93GyHX0kGt9R 67Jg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:message-id:date:subject:to :from:dkim-signature; bh=xblviIT/WPvwubo1pGbcNmLEU88wwTkV/I5WUrxc7pM=; fh=jPqxAwNxRTNJiiVfsaNew6JEeEc890l4hWnznnANkrI=; b=GlgNnWZ3vrtWiRr/6KYKRTkqFFQixiBK8c2a2NtZNKYRwtASO97JR4Tl9PNtmcHa8z nF+3pU9lAF8bVADqMT7HqdewSXloeRrwVn3g9zdVcJ4PsHALsrcN5rJlQLDhiipb0KQN tlmcRH97vcwHmxqZ7zmsNd6ZCw9R0DHq89DrpJKR5bG0bv/ahT0/zk8AIwJw0FY71yHc iZ0GZXwzXeXXittmp77KoFndWcyiCog99HHudSH5OvlcyREL4Y7M2v0dZRseHe8Bnj7P 6pWbfK4Dpu20x9NDzk1+p52CwvEx/pjYSa3EYfgDDtcl6xm+gBG7ysjDH7c+RY6PtvdI htiw==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Tb/srg/G"; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1725377464; x=1725982264; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:to:from:from :to:cc:subject:date:message-id:reply-to; bh=xblviIT/WPvwubo1pGbcNmLEU88wwTkV/I5WUrxc7pM=; b=D3ZWyTLtXE0SVEnAklPQGH8EYNgP3hVL65ZrSf1DYI8ZpplW6NLdhnSl6LzlU3LEog gxQUmU1PX/PTPZqQ9Mnm4CyDfqGu+sbTsIfyTfMqDcmM2I0jkDxfIL/gKOIdMsXnqXp7 QErYvyznPRN86pGNke1cyuS7zbbh1HYTJ8tac= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725377465; x=1725982265; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :message-id:date:subject:to:from:x-beenthere:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xblviIT/WPvwubo1pGbcNmLEU88wwTkV/I5WUrxc7pM=; b=PrQpA0mSjjla8OB3+7+tvpYLFc+1M3PvoAH4eripv/LJ3osiKP3wRSKuYPGce9VArz 1GEnyC+KlXlRTWcFoqaOtU6mO4oi/VVCF5zHfrqJvmrqEzN1Im7VB650Hwk/fV4QRLFC wTmhCinjXWs7WQ9TQhkSp5eJ1CRFwP5nbeL0Hgf9WzGA4aRdvoVvgIZEyK1elf0OD8ZJ s805QG8is6/rrITki0taeDBMUfJ73zUxt8PaYyntm3j32cD0D8RvAnwNJC2GuhMhsxgz KGDDy+6TFl1RR+NHHyLDmAnQo9poyqo2++FRtM1TFc7x4IXttgeiESNusHOwGGCGam1Q 2Grg== X-Forwarded-Encrypted: i=2; AJvYcCXFlXyB4nuTelqcRpCM08wNU6V0yTmmLhRdCbPKQ+F1Z3B3Ewn9nBfiQdvS5y8JEWe2IKyu/w4lcwO5jo79@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0Yx8/bZaq2KFSvBjHNrYpxU1E8+gsM+lgCEDYdIFEi4FeleIboBC XO7b7tZWjnYagfwEVkP3fKCYYlZ7pIV0dmADnubc45RIW4/rluCP73MO+B2hviulng== X-Google-Smtp-Source: AGHT+IFEYO6kMnuI80vXR1mMiF12EdAnF69cswmYmbhRDb/3/CXr5/H35LjVLbgPwA5LiZXSxISkRg== X-Received: by 2002:a05:600c:4f42:b0:426:6b14:1839 with SMTP id 5b1f17b1804b1-42bb0136dadmr169038505e9.0.1725377464540; Tue, 03 Sep 2024 08:31:04 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:3590:b0:427:9669:d780 with SMTP id 5b1f17b1804b1-42bb28398bfls1304455e9.0.-pod-prod-05-eu; Tue, 03 Sep 2024 08:31:03 -0700 (PDT) X-Received: by 2002:a05:600c:1d8b:b0:42b:892a:3296 with SMTP id 5b1f17b1804b1-42bb020d4eemr146177225e9.37.1725377462975; Tue, 03 Sep 2024 08:31:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725377462; cv=none; d=google.com; s=arc-20160816; b=uRMFwDSHoVQ8mAwvay8uYISOqeg67DlyWwumdlCLnYa0h3khbINoOOyUCSjdaSWBq0 YzswXMJQMdgVsmfw5DtQnW9RcQoiTK0nimEgFmdCmRm9bzUeFggL5m695K4VGG8WFws+ UXiIxY/mhxNAE4JnbkbXYdJ25Qd2+qRX26DQ9k+m1U2zpng7tix/bmFxJC4wsHZSfMxv EgLF0lIx6PllG4Eq249jBRPIUZlZ2LJZPftIs5LG44PMsHxMpA5D25pzTGMu5JCLknlx 8bi1Pb3Az7aikYgmfeCCR8UYzVN3SRlsGH8CSxAni+9ngEkAVY837HroIcZvBcy+E4Mp LF1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:dkim-signature; bh=/JG1v401FFHy3BRmgsxC2pPyQqhHicxf8qoeqtOnH7k=; fh=FtQepR0uNoeKT2PVdKfTKOkvEYfwbRmoVE9BmlYw3tk=; b=VS8D8TlGdot8h2vwHddYeWmkGKn+fphPnuj0Hc5ELymfVacACf7f5wbQAWg0wX9d7c 4Yen3nwSDOze3nuWJlWZaTGHmV5ViQUaZGkqCbJP3D693j5CmLrDO/OGTPKhu0VwLYbb IfdbqAeR/jsS+hjQWjcI7aopEZNgC2ezsMa6nH+kfE5GloSpS0KesTOM+w8OqJRr8A1N 1xmX9DdjyENcr+A4LbHt1CO102dbQRDtD4XhvaupDdxSbhwSUcBwqryaqWedtKk8SZFL rXv00zvJfMyohhV4dyHLzgWsfAJ2MAyYEw6126wFpnkLp8oA1qwWre9HdJ7FbVlXGhn7 rZYA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Tb/srg/G"; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 5b1f17b1804b1-42bb70b981asor4104665e9.13.2024.09.03.08.31.02 for (Google Transport Security); Tue, 03 Sep 2024 08:31:02 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a05:600c:474c:b0:429:c674:d9de with SMTP id 5b1f17b1804b1-42bb01ad776mr155656815e9.2.1725377462237; Tue, 03 Sep 2024 08:31:02 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com ([2.196.42.65]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6e273e3sm174168685e9.30.2024.09.03.08.31.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 08:31:01 -0700 (PDT) From: Dario Binacchi To: linux-amarula@amarulasolutions.com Subject: [PATCH 01/29] clk: Propagate clk_set_rate() if CLK_SET_PARENT_RATE present for gate and mux Date: Tue, 3 Sep 2024 17:30:32 +0200 Message-ID: <20240903153100.918077-1-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Tb/srg/G"; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Michael Trimarchi Gate and mux does not have .set_rate operation, but they could have CLK_SET_PARENT_RATE flag set. In that case it's usually possible to find a parent up the tree which is capable of setting the rate (div, pll, etc). Add clk_generic_set_rate to allow them to trasverse the clock tree. Signed-off-by: Michael Trimarchi --- drivers/clk/clk-gate.c | 1 + drivers/clk/clk-mux.c | 2 +- drivers/clk/clk-uclass.c | 20 ++++++++++++++++++++ drivers/clk/clk.c | 9 +++++++++ include/clk.h | 9 +++++++++ include/linux/clk-provider.h | 1 + 6 files changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c index bf1c6a93b468..bd0d3d44ac8c 100644 --- a/drivers/clk/clk-gate.c +++ b/drivers/clk/clk-gate.c @@ -115,6 +115,7 @@ const struct clk_ops clk_gate_ops = { .enable = clk_gate_enable, .disable = clk_gate_disable, .get_rate = clk_generic_get_rate, + .set_rate = clk_generic_set_rate, }; struct clk *clk_register_gate(struct device *dev, const char *name, diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c index 62477e15d27a..4feb8e8c821d 100644 --- a/drivers/clk/clk-mux.c +++ b/drivers/clk/clk-mux.c @@ -150,13 +150,13 @@ static int clk_mux_set_parent(struct clk *clk, struct clk *parent) #else writel(reg, mux->reg); #endif - return 0; } const struct clk_ops clk_mux_ops = { .get_rate = clk_generic_get_rate, .set_parent = clk_mux_set_parent, + .set_rate = clk_generic_set_rate, }; struct clk *clk_hw_register_mux_table(struct device *dev, const char *name, diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index c48a62ba099b..7d2c82e3bee4 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -515,6 +515,26 @@ ulong clk_get_parent_rate(struct clk *clk) return pclk->rate; } +ulong clk_set_parent_rate(struct clk *clk, ulong rate) +{ + const struct clk_ops *ops; + struct clk *pclk; + + debug("%s(clk=%p)\n", __func__, clk); + if (!clk_valid(clk)) + return 0; + + pclk = clk_get_parent(clk); + if (IS_ERR(pclk)) + return -ENODEV; + + ops = clk_dev_ops(pclk->dev); + if (!ops->set_rate) + return -ENOSYS; + + return clk_set_rate(pclk, rate); +} + ulong clk_round_rate(struct clk *clk, ulong rate) { const struct clk_ops *ops; diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index b8c2e8d531b9..67c6b23231ff 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -13,6 +13,7 @@ #include #include #include +#include int clk_register(struct clk *clk, const char *drv_name, const char *name, const char *parent_name) @@ -60,6 +61,14 @@ ulong clk_generic_get_rate(struct clk *clk) return clk_get_parent_rate(clk); } +ulong clk_generic_set_rate(struct clk *clk, ulong rate) +{ + if (clk->flags & CLK_SET_RATE_PARENT) + return clk_set_parent_rate(clk, rate); + + return clk_get_parent_rate(clk); +} + const char *clk_hw_get_name(const struct clk *hw) { assert(hw); diff --git a/include/clk.h b/include/clk.h index af23e4f34753..1900377eddb3 100644 --- a/include/clk.h +++ b/include/clk.h @@ -452,6 +452,15 @@ struct clk *clk_get_parent(struct clk *clk); */ ulong clk_get_parent_rate(struct clk *clk); +/** + * clk_set_parent_rate() - Set parent of current clock rate. + * @clk: A clock struct that was previously successfully requested by + * clk_request/get_by_*(). + * + * Return: clock rate in Hz, or -ve error code. + */ +ulong clk_set_parent_rate(struct clk *clk, ulong rate); + /** * clk_round_rate() - Adjust a rate to the exact rate a clock can provide * @clk: A clock struct that was previously successfully requested by diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 59f9c241b846..459fa2d15ceb 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -253,6 +253,7 @@ struct clk *clk_register_fixed_rate(struct device *dev, const char *name, const char *clk_hw_get_name(const struct clk *hw); ulong clk_generic_get_rate(struct clk *clk); +ulong clk_generic_set_rate(struct clk *clk, ulong rate); struct clk *dev_get_clk_ptr(struct udevice *dev);