From patchwork Sun Jul 14 11:32:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Nazzareno Trimarchi X-Patchwork-Id: 3291 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 4CD92412C7 for ; Sun, 14 Jul 2024 13:33:17 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-59980727364sf2020530a12.3 for ; Sun, 14 Jul 2024 04:33:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1720956797; cv=pass; d=google.com; s=arc-20160816; b=HrrP93dMJb/PflVzL+XKAe0g2yJ3xM8u7pha9+oz0y4PHBPoFMHvc6rtJF7deeov95 ptn+6+WQfi2TJ2Tsxhi2QxxcyQusi/RzdIaOuegMiqeBMRJNQODUJDkVUVkh/Y/rFDuv GMC5qqensr/Xbjg3IINfmym1unF7w6jVoTyZIHg4FHrfQAiI2Blh5dtVsnvNjrUZVLts hq3p4f4AH7+QB3I7sy192WrA+7/FvQDiyvAmE7E/9YeW9EBmW8rT1f6tscFDrL/yxzbN dndH8idm1RKX97vtHBhjRJabmPpT0/7c+hEbLMjK2/dLv4ubaiHfNtu0PeW3aG+Vfq70 qM8Q== 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:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=60k/FQlEKgyC1/tqIm6PqldQOacYgyn4UB4ymJpHg7A=; fh=9kggebPEOlm+C5bHesBA30N3L2ufy82vSS9lQILRsCM=; b=lHN0aonvcTmQNjgXjmKM8jnEGdArPymEclXelghCFazdAixKMskj/FN0Qt9hzbD0CD VRzEl3S2JeEm8QHAlXe9LIe5Avf5hGnvgNL31IZgwVkE8bBQHHzIfcZZM89cRL9cqQLC jBT7FqIX46fadfeq6xdLqfFSyQ8oqkFlsppBaw3j8Sa65XEy4lJ1cwka40C0vDAIpcym RsHM+XLoV1noWuFq7wXYa+lX6fR6iYiIikDw1WC7fJ+IT00ltMT/Y7G3U1XRAvBChdzo rx+Med95yM0BiMMAurxcPyxNT36tMzFa7JC+Fbk57ZVit8BbJrx6l6Y+qV0AOb3Re+6Q Rl8A==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=KDstL7mZ; 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=1720956797; x=1721561597; 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:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=60k/FQlEKgyC1/tqIm6PqldQOacYgyn4UB4ymJpHg7A=; b=LUI+C4njqb3uHMeubWsRUX6GOWgQckE00Wk4c5r+0USUPO54paT0zfDKmvEU9b78+J Oz29aWDWMuHXAtfs8K6d13HM+w61VEsMTwzANeMnujBqffzMdHu9t35ER2f8aS+buKMA B+a9qSSnvayk20NSGzYMhidPKCMCR4FSyaizM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720956797; x=1721561597; 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 :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=60k/FQlEKgyC1/tqIm6PqldQOacYgyn4UB4ymJpHg7A=; b=DxeJftm4lZ1J2Mibd5uLvUID0meDNUXnTGBxM5wxV3yYiCwnqw5KTXhMIubxhbQOmz fsz4odWmav8lYip7olYCvzEN0cAJCH4ozM3C/nyqRfNTLlvPuM3orbnBXxtKJiePcQO+ 3+ieCR+ZmhgCBYCNsRC4nPEyerDh7DalTxoQo19iVfHw3pprGB1YiMJbUwxWhlC3VkjM 4XGUK1ee+l5hgiYHxyUUAP7CoU4khR0H9WSGhVncigEsBsR2tlTmzT1M56s1JfaWUlSt yTAhzDgbGWYmA7nzPIjV9E5Lertz/Vq4KQ6ve7gMKLXWow6z7zb0w09dUF0nnCfC7fsk PPbQ== X-Forwarded-Encrypted: i=2; AJvYcCWw3M0B0GFO4QD+KbLry6vurSk3cJziMshr/AzaUceqCgbpqCwFIo1+FYEa1MDQ2JWmrG4HvVI+WzUbR3a0na5pFGDMMglRGe7VjObGh4zC3i0mI+eq1XHxPA0s4w== X-Gm-Message-State: AOJu0Yzl++c+yJABZ5Dl8vHujxG4dKVef6N/1KIXKn5Gl+ShkcnqbRuE EdLp/QXvbZFmWusIasfq6eAN3De1aJSAn7rvHSDhz/zdB/BKGu+0TDKolNy7CbbAPw== X-Google-Smtp-Source: AGHT+IFo3T02XDVWnonpogcJ4cY6ZmIj47ambpIWQx3ouz95jexq4nou+NIqEGw6KEeaboY3hEvuvA== X-Received: by 2002:a05:6402:210e:b0:57c:74ea:8d24 with SMTP id 4fb4d7f45d1cf-594baf915e7mr12359653a12.18.1720956797055; Sun, 14 Jul 2024 04:33:17 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:c17:b0:58b:b493:fcc1 with SMTP id 4fb4d7f45d1cf-59821cb8394ls978345a12.0.-pod-prod-06-eu; Sun, 14 Jul 2024 04:33:15 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUyoXRZDuEXoOXImdby6MzDXCGkRzzw+raPKhIral1RLVwhVBTrgM1tbVdnP0Jwqe0pBaKTUL3908RxuMDahsE3XF2qrM7eHxIzJYZDiA7YiGin X-Received: by 2002:a05:6402:28af:b0:58b:9e7c:bcbf with SMTP id 4fb4d7f45d1cf-594bcab046fmr9142410a12.36.1720956795376; Sun, 14 Jul 2024 04:33:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720956795; cv=none; d=google.com; s=arc-20160816; b=R1ptepVoIMTpBRTSHsLQiSBV4yNPTnuuEyRaXYBhgDixABlYFIWxTOMh3naICBDBko tDONZGH5ysmUUQ8P2UjZOIJMofA8F9TRYdoPEwfJhaJtq7swrh14brMB079VkPYL11KK Qf3TyoEUsb5eaAqZIgR3XC17drJblqGL7ATBUE1J65NFWjWxX+9jEIsOKr+qBd5tlPgm Gj9o70kXMZ2ZJ7AAB7Df4lc/iogOAfZj9S5Tn12S52av76Movbrv+XEkAusp1sxo56ng Af6C7gV6IaAfoWtPZ9PpPVhewfLV/GMqyYURd2yFFS156Tgst09lwI48Pcmzpzsj+tva GUcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=KAkcJmy0TY38eaMN2Z+V8FYCp2Mn3ohX0YwuxdG5GUE=; fh=TtQziSequcy8tjdL1kUTzpguJ/56ANGboYYuLdQI1+w=; b=URKNKYJjriRnKA31yC4RgSHy5VM36VjSHDT6wIURoT3iAo7/sOCQWwEazgLKE5Gp5i orvN3eF3lu3RZNkCtOewLzAQHEqVsupHorvDFxpRZU5A5O5JYubDrMKxG5Cod+wRe3+b T/MGqAVzXdWPnSGsa+rDxwnyLAFAXq6H/9eP/DLxMLud+POJYMYy5NpXP9j8HkFM+twO 9olDlzzb86DK2f9OIkZM9eTIyZe0KJn6ecOj1q6fcabFoKEPaevdK42Nfa+pZaluMhKl ipqb7/1eOrvTXgbqfeLBD9Rnp6CUPpvgq8NU4CKMeOq2l5NfYrAl9R502lo85VLULtHe /MMQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=KDstL7mZ; 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 4fb4d7f45d1cf-59b2514283fsor503021a12.6.2024.07.14.04.33.15 for (Google Transport Security); Sun, 14 Jul 2024 04:33:15 -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; AJvYcCUvOEHXmUhIbtupTQgFeCXuDT6ToPtA3RPlleQjgU4XSezHis/rRP/z8SD+hyierQzUB/247q+OgerBUZjrMtG+0/JxwkzbFuWk4mG9FViOXN9R X-Received: by 2002:a05:6402:35c9:b0:59a:a8cc:23a4 with SMTP id 4fb4d7f45d1cf-59aa8cc24c7mr3628536a12.9.1720956794968; Sun, 14 Jul 2024 04:33:14 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jul 2024 04:33:14 -0700 (PDT) From: Michael Trimarchi To: Michael Trimarchi Cc: Dario Binacchi , Patrick Barsanti , linux-amarula@amarulasolutions.com Subject: [PATCH 09/25] clk: clk-uclass: Implement CLK_OPS_PARENT_ENABLE Date: Sun, 14 Jul 2024 13:32:46 +0200 Message-ID: <20240714113302.133399-9-michael@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240714113302.133399-1-michael@amarulasolutions.com> References: <20240714113302.133399-1-michael@amarulasolutions.com> 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=KDstL7mZ; 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: , There are scenario that we need to enable the new parent clock before reparent, or we need to do the same with clk_set_rate. The patch cover those scenario Signed-off-by: Michael Trimarchi --- drivers/clk/clk-uclass.c | 47 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 76f1026164..8faf5a56e1 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -583,7 +583,9 @@ static void clk_clean_rate_cache(struct clk *clk) ulong clk_set_rate(struct clk *clk, ulong rate) { const struct clk_ops *ops; + struct clk *pclk; struct clk *clkp; + ulong ret; debug("%s(clk=%p, rate=%lu)\n", __func__, clk, rate); if (!clk_valid(clk)) @@ -598,11 +600,37 @@ ulong clk_set_rate(struct clk *clk, ulong rate) /* Clean up cached rates for us and all child clocks */ clk_clean_rate_cache(clkp); - return ops->set_rate(clk, rate); + if (clk->flags & CLK_SET_RATE_UNGATE) { + ret = clk_enable(clk); + if (ret) + return ret; + } + + pclk = clk_get_parent(clk); + if (pclk) { + if (clk->flags & CLK_OPS_PARENT_ENABLE) { + ret = clk_enable(pclk); + if (ret) + goto out; + } + } + + ret = ops->set_rate(clk, rate); + + if (pclk && clk->flags & CLK_OPS_PARENT_ENABLE) + clk_disable(pclk); + +out: + if (clk->flags & CLK_SET_RATE_UNGATE) + clk_disable(clk); + + return ret; } int clk_set_parent(struct clk *clk, struct clk *parent) { + struct clk *old_parent; + const struct clk_ops *ops; int ret; @@ -614,6 +642,15 @@ int clk_set_parent(struct clk *clk, struct clk *parent) if (!ops->set_parent) return -ENOSYS; + if (clk->enable_count) + clk_enable(parent); + + old_parent = clk_get_parent(clk); + if (clk->flags & CLK_OPS_PARENT_ENABLE) { + clk_enable(old_parent); + clk_enable(parent); + } + ret = ops->set_parent(clk, parent); if (ret) return ret; @@ -621,6 +658,14 @@ int clk_set_parent(struct clk *clk, struct clk *parent) if (CONFIG_IS_ENABLED(CLK_CCF)) ret = device_reparent(clk->dev, parent->dev); + if (clk->flags & CLK_OPS_PARENT_ENABLE) { + clk_disable(parent); + clk_disable(old_parent); + } + + if (clk->enable_count) + clk_disable(old_parent); + return ret; }