From patchwork Sun Jul 14 11:32:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 3283 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 06E1940F88 for ; Sun, 14 Jul 2024 13:33:07 +0200 (CEST) Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-58bd8406816sf3378024a12.0 for ; Sun, 14 Jul 2024 04:33:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1720956786; cv=pass; d=google.com; s=arc-20160816; b=ENfPQcAW6+H8qf4jj1m/qaCPKa7E0y5FJzWg6kgHmwOQhBoZ7Ae3XDE7Mhg9IXCA7P Pfj1N+3w4QVLWWybPnRGzWIsa/kph7yZ4bx1hrsCs3pComCwkmEEUjgJOe9Ityn5nU5e aT2OPzllYu8UudGsGvNEhPtSxWI9/4LxUgrizyh+WOaUidVeWYbZmVYDe/93cI63CY+Q 3/rVtDTuqmst2uEXfBq9151SE1Cz5tb34HMl4TWv+TdS4NQi27ZSfEU3a3UgzcCQLkKm t5RrGb2EFPogrfxNgs4PnXr0MYwPqKFu38VP7Po8HNxkY9B8tpg9A6mnZscid6NQKbf2 jIAA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:message-id:date:subject:cc:to :from:dkim-signature; bh=jIs6Vq7SG1FP+1F7Pt9VcFBRZE72WyIUwXFlmh/9ESc=; fh=UJVNwS57L/Pa78A3Dim3yYrDzu8bbNKj7XZWsRzGXKQ=; b=zBh7S18htpYtZT2YiOJVhEJkUV+VftPq1qCXooQ4zE3c0JiVpQFGimsQqbBnDQB5Eb tdW0d3mOwzSFi+IV71UsZu9n9QwAo0VpKp0Jig6EdVsnYhD0l/09f2aK3VJbRDTjALPb 0tkmwH+ehGVlqNT7V775/rbHvqppiHGxMMOJfW8mqMecuSR43JLEjZR/ivsani8w59uo kzyVCLp217fjUuXoloZ/v81O0RJ4CsuSQC0FaZSrbCc/SMve7DMrZTy/M3q8eYsWQp2Q yz1Sxo2frQzWxAlyah9KM+UeEEIOLh+i2mrjsz+Td1/HrgzuCwzXnTfz67B97t+1JjT5 Nesw==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ApuTeLq7; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@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=1720956786; x=1721561586; 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:cc:to:from :from:to:cc:subject:date:message-id:reply-to; bh=jIs6Vq7SG1FP+1F7Pt9VcFBRZE72WyIUwXFlmh/9ESc=; b=A9HIEhEpHr2psZdG6vfrk3DVPnpGwVM0aPlLaQvxSzA0MchP80RT+HZKKqX81DEJn5 taiP0cO+rkzuVrXWtUDeYjsKjSkSjSrIBsG10bjOqOt2yhmtWHWvVf5aE+Itlmg/iSGc xE33DuMIxBvpV5UIFl5Hg5FqW9ly0o8g+IP5c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720956786; x=1721561586; 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:cc:to:from:x-beenthere:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jIs6Vq7SG1FP+1F7Pt9VcFBRZE72WyIUwXFlmh/9ESc=; b=aubCYRB431ShaqK9qANclCMQxs+E6rWMx/wR4KK35anTML3o/8p9sS34ZVeAkb5rcX zusHBijgp+pgY7PfFn8ipa/290OxgcDFk1IyH0yzXLyL++ARBkJL8MvnZoZj0cFv2WNk PgpOXhEgBxxw0wbHWdM68iJNSos9PESveinTQhK7vmQqVWfYpw3lCBlvhzWQofPeihkH 0VeZFbPNglo4FT6aW60UfcICcS+eCpb0sGSzz5FE/V6j9eeiT51kFJu0gIB9M8M7QKiG +CxD1y7GmJuqwrmatMzjKPqV+UoCMlm/dFvvqfM9V7oRcOiixegW9lLc4CVbLgtOuuWg KClA== X-Forwarded-Encrypted: i=2; AJvYcCVe5xNXWotmQfGfNLTTbPqpG9kBS8Di+REa47R1vSFIaVmGgf/BG04PtlrepCKWjiXrO+8/7V1jeF0vFXzc0wROmq0r/h1xqmXPpHqAWhjH2FEJX+Nwo7Kw6CUfSw== X-Gm-Message-State: AOJu0YxvbkYufrSY7ueNDOhqbGT4Y57PEqCOI4V5Ym3Y7+OqBya3KpMF 9CqbfWGVQ/PaJOIpqV1ROvszWcrvIf9/BWEL6wAQcV4A+2K93MGn/m0I8UMr8pJUPw== X-Google-Smtp-Source: AGHT+IE5NEW6MNn51FUYPBPVBChydJUCZp4eVZZvaQL8wBMLvMv5GhYL/z3yI+MuO0+q/RusRJwQWw== X-Received: by 2002:a05:6402:40d2:b0:58a:d4f4:e866 with SMTP id 4fb4d7f45d1cf-594b9b06ceemr13449481a12.6.1720956786543; Sun, 14 Jul 2024 04:33:06 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:aa7:cc91:0:b0:58c:3dc1:35d4 with SMTP id 4fb4d7f45d1cf-59821cb697bls1645767a12.0.-pod-prod-01-eu; Sun, 14 Jul 2024 04:33:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV1mjg9ibRgDN+Bj4zsHvgosZhmDJEFaPVrnO6pNr68/plSHzAcZ8AldtgEkKpOAgHaOzxEWUxAV4hULYmo8sBUcKoC+O0m5upHEseo4Phyd0Mj X-Received: by 2002:a17:907:e92:b0:a6f:b715:6cd9 with SMTP id a640c23a62f3a-a780b884b45mr1394068466b.56.1720956784869; Sun, 14 Jul 2024 04:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720956784; cv=none; d=google.com; s=arc-20160816; b=wxGoknexIzlfoBe64icxJAuXypJeez825x9Kqw+Z/6e75JaWWXjGEZ+tuZV4hhR2jG yIT1X8nb5WjTVBDIBZJxn20xMSLlPVPv+VS/yGl/dQyKg603wd7wc7x9Q0YwW5CKXhja sYL9aLpjHnVjezRhhM8AslPl974a0/wW80FKt66ZdavW18CqsAMkFV+C+0ILt+aaywhv 7nXwWrS+yAHKEVzbR3Yi3ahd24BskxSJYgeBYf9SiS5NwdmRZl7kjFqq5Va+eNKwp1sw apw6mts6PrZYHMrK89oTRm8yQX+KgTx8/fcWSIDYVADofcErpPGM7luXwLqR7Vc1CWR0 ZztA== 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:cc :to:from:dkim-signature; bh=mLFlSS3LOz2z5PbDNHqhhOO8pKuSllLzwO6lu7HBbUw=; fh=WxCKNUkkWKNUa+2BkypJtBadT4H4CtN3rLUpdILDz0s=; b=fjB7KEkrFKrDkwIweUxivBUfuQCC2MhriRFfkhOxmVYeAvl6e/ZBr8XtBNbtPEzLPQ Z8RZLBis4URzdh29GkE4isFaqi/8zgD7EELJ6TxwG3umSp457zi01RaU82afwwnIxWok w0NTzBG7A1qyHeQ/cDSu/RW3y+MwiFNewY0MSW3mHkgxm07xBjGmiXYhhYmfPl/Hyuzf sSOjTVZx/rnHmi+BVZFMp86NBH35oPd82CRE1waD6kLCT7o0eOO8rvB7uOgveBta29Jr h04V3mCyWdDSoY68saapeqGjfJtF/cm1HrN4xQ6kaBtccEdZ5wHq9mqMkDkNs82V1wuf JMsg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ApuTeLq7; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@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 a640c23a62f3a-a79bc5f7d31sor65496566b.0.2024.07.14.04.33.04 for (Google Transport Security); Sun, 14 Jul 2024 04:33:04 -0700 (PDT) Received-SPF: pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Forwarded-Encrypted: i=1; AJvYcCXQi02cWrvsmez9YpC2yBz4q84Tpuzbs/nOo44bPXLxSBL6GvcqnlNc6JycN5PDJ+loCFhQ/rtCE8Fbfmu0IZGXiMZoXN6266R8/Ho3yJ6lvUdQ X-Received: by 2002:a05:6402:1ac4:b0:58d:703b:c1d5 with SMTP id 4fb4d7f45d1cf-594bbe2ba6bmr9480345a12.38.1720956784284; Sun, 14 Jul 2024 04:33:04 -0700 (PDT) Received: from panicking.. (mob-5-91-58-211.net.vodafone.it. [5.91.58.211]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-59b25528dc1sm1929469a12.52.2024.07.14.04.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jul 2024 04:33:04 -0700 (PDT) From: Michael Trimarchi To: Michael Trimarchi Cc: Dario Binacchi , Patrick Barsanti , linux-amarula@amarulasolutions.com Subject: [PATCH 01/25] clk: Propagate clk_set_rate() if CLK_SET_PARENT_RATE present for gate and mux Date: Sun, 14 Jul 2024 13:32:38 +0200 Message-ID: <20240714113302.133399-1-michael@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ApuTeLq7; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@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: , 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. Cc: Sam Protsenko 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 bf1c6a93b4..bd0d3d44ac 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 62477e15d2..4feb8e8c82 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 4c832f1a53..d768e5ad2e 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -516,6 +516,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 b8c2e8d531..67c6b23231 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 af23e4f347..1900377edd 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 59f9c241b8..459fa2d15c 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);