From patchwork Sun Jul 14 10:53:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 3258 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 9BA6940F59 for ; Sun, 14 Jul 2024 12:53:33 +0200 (CEST) Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2eebdfcb63esf35279331fa.2 for ; Sun, 14 Jul 2024 03:53:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1720954413; cv=pass; d=google.com; s=arc-20160816; b=DO13Oatl6qHnqQCDpskQGYyzm7dSOy9WeW7PWEDMFugzu25mrxLaB0nhaTN3fu9Eo+ MSyTeyRgH5w+cG0sAyYiAFLf81EhczRkXxrMvo87QUBbVQ2pmDvYoh00yt6iyM9ZJ18N iUT6So222XwKmTiLFCvcrOAmE8kX0C21XcjL6klioXbRIcD7/Oa7gmfDqduuir7Uoodj nan5urbmBZahMIrQi7EsPFrJqV05YO2hDdTA6/Ne3YK0WS48U5YE7VbwHkTkN6RFNy86 CXZe0+cXD4wlv8Fu0Dm2/H1SkBxbi26frppPjP51bjegrdY3lkVxq0xH6TK2gDMhLwm5 dfrQ== 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=wSWnQ5f4NjP5J36hXqes4BHEO/Eaj8SJyNmfh/wPJO0=; b=oDjEQKTVu/HW3XDo8RWqCUAxcwS5kdz/bvsAdYVvNBxDeFXwgF528UN+FYhg7LohSW Sux166FhvVmLoeLxHtuYCE9rSZbi2hsqPvYrv6rA0eOk+BgBUaI87VO1ZQKZCLG0+aAl 8XpkbLTRY6ZYYT4URqEb08jU2Fcgbc1A8hnryoN33YDOaaehQC39kp9JCm/JlZAk1K5b ZEIs53SurDt1yNJnCDzyuYQDtwUb8Et98xIDx0zsGSEohegqhqMxjypfY3nzVZQ7U4og rGVYWdU9OfL3T1AGHJjPe8deLD1O3NcWebfO2C8rv/BMdBm1/Yuhap76vZWm/Smpma8U QnIA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=IPMJReQA; 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=1720954413; x=1721559213; 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=gQcgaV8CbXe8eOziL0nB6LfQRYcVJ8zoN8j8SQJWNNhBHlp5lmC8IOvsZPvKWA2zkz Qq8pxhS38KWr8HbZK/yemtvdhgwXfGb4EhBvoghv++kqZ8/kHKe3ZvEGzuUKimu+s1OJ S3QNM8UnwlVOWxFzx+mles8jZ8n9xCGzZF9B8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720954413; x=1721559213; 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=ZBVtQYeUZHT6mjDNy8O780Xf+mdpAoHGmvGnd9K7uNO1P57THM+OY/GhM3mTWzHS4P gqBFz4HgqaNVZ7FSoyTCf9PhegzUYU14DBC1j0WLXK+u/tVPmL2B/pnbbMhadnRzLUZl lqjNs19U5L2qjJC8rMvh7Ogbuapk6+nYl6yTy8L4Ltdbm4fcnYmjRZZud4dn1PIG5Dhn nTHD2oPTiVzNmbUmprnM41VknXeKAnpkv2ZnMBtqqa2R4mevc0YLKcBMWjAVJj39q7aA gn33+kNdwJm/8w6LgdExPk4+WrTpt7ebZCA1H+fB0gyc5AbqqBba1i6t4MaIyGRnRq5K MqLw== X-Forwarded-Encrypted: i=2; AJvYcCUoprK6gEVa0aVajQzwdc37Aw6MHbD+b3KKUx17olCxPRb3YRYXRa/iRgXzNSh5NhGL0DEjomKgZDtzoQRNsglm2dn8F/eFbtjMT95t9mBGQmQ11MF5eWiO3ujxzA== X-Gm-Message-State: AOJu0YxVakg9lxsGiBjbwPz0HUxM7BfU5uG6KYr4ZjkdTVuJ7PVnnSM7 LlfecOYDCfQL3GDb3kBHewcJjLe6MJ/QlQOH4t9jKS693M5wMy2qELTHsmVM0VHeLA== X-Google-Smtp-Source: AGHT+IGxyLwCa++TzdAVYG2wJfpbmcvg4jdWfGr0ZC74fBG/lks6vyfBw4wDvbKvOo/wgdeuWMmROg== X-Received: by 2002:a2e:bc21:0:b0:2ee:8a6d:8683 with SMTP id 38308e7fff4ca-2eeb31027a1mr139033581fa.24.1720954412762; Sun, 14 Jul 2024 03:53:32 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:aa7:cc91:0:b0:585:2014:4d17 with SMTP id 4fb4d7f45d1cf-59821dad88cls1720880a12.0.-pod-prod-09-eu; Sun, 14 Jul 2024 03:53:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUvobz0UXRoGih8Ptj8XQ+STKgGJfl2yGyC54PxgaViI2+4kLpsCTyIz+FThd/T1wVspmnE6gQxnXmIP6Y0FhHnMUrG2Rtyg8E9mJSqnYV7n8Sb X-Received: by 2002:a17:906:395b:b0:a74:84e8:9994 with SMTP id a640c23a62f3a-a780b7053e5mr1140972466b.45.1720954410813; Sun, 14 Jul 2024 03:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720954410; cv=none; d=google.com; s=arc-20160816; b=Vh/WdMQJqv8KyqNAb+02MeGGRrFFFl5nmW4769MlLBR/GvkXOnhci42WJqRarl97aV zvKrj0p9BKPQG9PgVWl+ROtIDF/oBmYWObNmS+PKwoc2L+EXGT6FQbW7Jd7Sa/qlrkAY 8EC+Q4114SYAasStSvtJwVcHVG8earQpOKzkkzYrRHuch4RLtyaGJc3KNckT6VZCuT2X 16XC9vt/QKzwgLnoAddBV1KX1GCmmV7+6rBQZfnQDO+m8Sh2abJ1Fvf6tZ7hj1yblb2d WSkiUv4vW53djD800dULq+NdyYwGvf2YxLbl5ZesS+t843wfA3nTTSG9r4csOQnbusiz UJMQ== 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=Akzlz2NtI8tE7tt+FatfotIMRIGAofFr0iud+8iYfn4=; b=ZaeiRnxBPXNGw6XdgO/Ck4oxhhEAZ+e9vNZzOP1JXWsE6iOL8bv6iA8BG8Jivqcy7J NbHTrYnWOOUtKfkRxBrd1duv4SVWkD9oodrdAihEwIo65rbIxdPckVWuk8tmt86ciIYh roMuen+OBs5N7zEgNxuz8mVV/371mWBGtbsGkL2L9ncsvPisrUwdiEmzk90cz5qPSxDS VsBU1MXyvNSsy+FbTgXQD2IwWsMR/eUdR3CC43Vcjbw+nXV694pdO7kjVNcWtufSUhjS LnA97vDIlm4UWJ24OFEjlpv0nxGBm4W8qZ/IvBB8v+kHuHDYk+flf2PV2sI2suC5zA5Z 4umA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=IPMJReQA; 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-a79bc7ff35bsor36928266b.10.2024.07.14.03.53.30 for (Google Transport Security); Sun, 14 Jul 2024 03:53:30 -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; AJvYcCUnN4iMS986fSdrZDa7Oo5YQwE2MqdkRmHHIUsbYHxf6HmTy/PFlGcITXowSACUISMvFN1YaYDHvHQrcl8vm2sEbi1aFIUl3fQkU+4dx9y9J/ij X-Received: by 2002:a17:906:b319:b0:a77:da14:8403 with SMTP id a640c23a62f3a-a780b68a4cfmr1140636166b.2.1720954410226; Sun, 14 Jul 2024 03:53:30 -0700 (PDT) Received: from panicking.. (mob-5-91-58-211.net.vodafone.it. [5.91.58.211]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc5a36c7sm119966166b.7.2024.07.14.03.53.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jul 2024 03:53:29 -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 12:53:04 +0200 Message-ID: <20240714105328.35825-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=IPMJReQA; 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);