From patchwork Sun Jul 14 07:09:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 3233 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 9823440F59 for ; Sun, 14 Jul 2024 09:10:29 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-57851ae6090sf3203633a12.3 for ; Sun, 14 Jul 2024 00:10:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1720941029; cv=pass; d=google.com; s=arc-20160816; b=j4Wrpu4azccgcFD5epTQyYYtaqDoTqOnWl9GpG7ZSCj8kyoNMDnP+j6S7XyYSXfvHw sJOVXUHHvUPHMZQjRCKtzaOvkm33esuyQjxB4xW0aA8UlymafvuS5jFP5CRwbitcRjK6 RGqtkAXXqmVPZjsel0wU5f0CG4k5/auC337J98UvjBo7QWOhgpcEQJSMj/WyTuml6ME4 3h7L4oumZjVAjubPdVxR0tUJy9y2kx75ybjumqDkk1awMnjQD6twY+rRsQiQEodX9Pga KCcQIfKzRaI45PVy+3kXj4V+kcUf7+G0UNHfR8rjtcvs6TUVcx6eQnPon4OhJ/yjFrny PwdQ== 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=YqNG1tBisBysDcce+YjATakUIo4qzDBrh+6kVxpi+3E=; b=clauItbEwShYqQL6m94R0TMK59DdI3QbFr2arps8adviWLZ80SFXlfY9lWiQWvZAlz JaFg58eBshoC3jAcRXGSEfLCxg68HqFr5FGKWQsd3qRwawJiFTaNL7c2QvkP79KO1pbO rrA+LyC6ojOjYGDyx6A+SEQ0QQdXwMbqBm0Ro6JZWC5F3gYYUVSgIq1wMyp0yNQE5WZP Y2Z8t1zwXVag5n0nCRfEgVBrV3h3FguW21YcUUY/Ttg1qd2oWVQms0FkA30R5UCVSBrn lOj9JB3U+203VQN4x7ZncWhms8U92IHsATQCNLWqOzKUr3GslBBxx1U7GfPDcLpdD9md P8dw==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=HUDi5hJ8; 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=1720941029; x=1721545829; 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=TUKaFwn2lQJDG0/4bRDxCG+flzEzj7u5Isrt5TmWofOceue6c2GqxVnJZ7BAN7FZy9 lyd5GoG4OpUisW8uxyBPtH/sIPn6GdoTOrGKwXqkYedy9f1d2ZSlgkXRigX9O7Fdbp6g AaDrkwLtajusXWrngHABNx1lx1g71CUCdy8Tg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720941029; x=1721545829; 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=OO8S6qgisFsnF7klm0xxi1Gg89ypdbs54kzjoWsaj1ACo4WwaXPMI15O7mjoIcgnU4 yfsJJMC9Ow+2GytcSVka4mUin+oJCZ77LBh2ZbYdajnrIOV7wQv7C4k5weccdnfTjoSj Kn2L7SwJ4Y77EVykIbpOzoVIvoe88oNUjDJgvvgCWGzsF8lrxaTbp+z8HlwNUCucz4Ke 7lY98KH8Vb+rjrZwXS49hUGrN3laEz2Y6/+SB9pHBUKC4U9PfW7MUNTQniQt9y+Kvi1u ZlomT9CbBPBSDrbp5OYwDj/TNNmvewZTHzyjduhdiGFicHOL2IRJ3+d+9Jc4Ky6l4XRo D7Zg== X-Forwarded-Encrypted: i=2; AJvYcCX45vXI5PbbbFNwwy53SZiHEjiyAY4zOZf5oldBBMFsPC6MfJZBssuScoxdMZibXiMlss9U72XeT/FjFwF+HRUuCIBfOPVYjRxny5gVG3pjUQ7s3/rjuFLFaOmsow== X-Gm-Message-State: AOJu0YxFSpTBvJnB0eAipuXrLOYfSRNEyFdkDgv6QaAPqRlz/sh2PrCd ihZO5ci21/gFZSoqtbhX7/fZqxKgw/NXWdz14wQSCaB+fGRhjn3EaTwKSvK0IsvjFabv96RDew= = X-Google-Smtp-Source: AGHT+IEu/LO6318LXbJ+C7G7TPEt4Mu2RCzX4oAYJrgJUIS2EFIgfWEhMrUMiT48TQpRCA6rQQFngw== X-Received: by 2002:aa7:da54:0:b0:57d:ef3:c3b7 with SMTP id 4fb4d7f45d1cf-594bbe2ba17mr9474903a12.36.1720941028732; Sun, 14 Jul 2024 00:10:28 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:aa7:cc91:0:b0:58c:3dc1:35d4 with SMTP id 4fb4d7f45d1cf-59821cb697bls1605454a12.0.-pod-prod-01-eu; Sun, 14 Jul 2024 00:10:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWiDz5cv+LHgsCzagJkOREF2cKuEuH/w8+i8kgn0BomWOIm5g09h9m+FPyjwXMOdggi62Nm7gHBXLZcjZMtKASYwM3YaUETj5Dum7HMM+2JlsMe X-Received: by 2002:a17:907:7e83:b0:a72:80b8:ba64 with SMTP id a640c23a62f3a-a780b6b20b0mr1190636966b.25.1720941026849; Sun, 14 Jul 2024 00:10:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720941026; cv=none; d=google.com; s=arc-20160816; b=HLqwxCrweMTIL9VjaVsyEmpHdQNxY9wKT+AlFgZTxfTAvidSkgPAHAIknQ1msi64HD BIOMmyxn/wqFFgCGpk6vrx8yiPUyuDvu976HSG9ruPKWGvIssII8BXvB5agHjKuSmmV0 F4a8j98AE03f4Dk1ZGpU1O/9kKR6Y9OnnjmfY6KFrXki6zuvzlh+Fma+Fgh84JTPQxlW zMRJdPzVv2DL8Vo0t6IcyBRABzWR3hJ1OhBdIuxZ/xTETyC2UR67xbDggbihZLPLcmjH HHa/90tpaR0qoNQE/foicgizxGBs6GJ3PQvX3KMyML147L2qDyPCYQjUkOcgu+nyNmv8 lC7g== 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=nQEn8a+3c9EWRp/tFwgeplNZ21kduKtST31RkxU0yqk=; b=xwQL3/TjGOV5LH/ZBN/BeGpaKMQfKx/Iom1zemmqQSmgtDCpJZZWCm6chHzuxdQIEw NyO4faAwcRD7O5M+y3Gnaf8YgYES+clPz33EjIxgZrr0eVRgtmNt6NmTn+kOOJu0GLap J2WTWvg4DJVTf+kPvj2JE7cKaiClcPFIDrBxdx9c4DKUbhH9UAuclw9hBmWPNbJF1HWf F2wYp49vo8AMnongtUpfglaaeN8KGBilQ5f1oUog16x1MXggKAJOme4Nt1lmJ6tU2eYQ 13w/IK6otiY/Mk8Vy0DSSjWX889o18j6UsnjfQCU5fC7zAGWWsPoBgop0pSk5b2kdI/B 0Q2Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=HUDi5hJ8; 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-a79bc95978asor42300166b.16.2024.07.14.00.10.26 for (Google Transport Security); Sun, 14 Jul 2024 00:10:26 -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; AJvYcCW+LL6GgDj60WM++hi63R0z1PiAj65jg1qYJqcgYYnDuWEYlwWeap+Xsn0SmPK8IUtiNUW1mcM07mvEU0fM9LR9pS+e1hfgqsywuVADmjNYgIw/ X-Received: by 2002:a17:906:3e47:b0:a72:76c8:ef68 with SMTP id a640c23a62f3a-a780b89f574mr903311566b.69.1720941026233; Sun, 14 Jul 2024 00:10:26 -0700 (PDT) Received: from panicking.. (93-35-128-17.ip55.fastwebnet.it. [93.35.128.17]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc820d52sm104950266b.214.2024.07.14.00.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jul 2024 00:10:25 -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 09:09:59 +0200 Message-ID: <20240714071023.10417-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=HUDi5hJ8; 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);