From patchwork Sun Jul 14 07:10:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 3241 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 5DDB24130C for ; Sun, 14 Jul 2024 09:10:40 +0200 (CEST) Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-59c1314940csf326879a12.3 for ; Sun, 14 Jul 2024 00:10:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1720941040; cv=pass; d=google.com; s=arc-20160816; b=nNvcgeGWruPyF1tdBlqAoFtAo7VPx25Id+V9/3Iv8GRJ0MAhwc0YY52YMRrd1Zbsgq tKTRBs5gLILCT6iJfQWcKyhsq8aP0yCWr2woeX1cVusF9IqH6SzIy/vk5o+7YEW36ZXh x36mvVRMQlPZSrATgrxqWRVHRtS+3G8QFfU942/6eRgxXYC8ATUAlU1UNEMQ0dUac/pW XXxQPeC1KzbOGtiBLPTB/uSC3zLqQS4kAKNN94EUSXIPw+k2n/FW/UE2jePX1gRu6NjD UNVCZTtZZ60ire3j9VuBixdaHu3mrL9Niy73dQzVPUAffWc56KIVDOW3s0K5dESzsCYP z/xg== 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=cFUocPk8ylRLBWkTYQX6XPXsAyUQS7krMnNPFrvKdBI=; b=bO0ShoKMNf+cCfkBFU9TyrS9VkoiVaaFbLhghNL8xis+x6i2wCj+nmcTeS7JL1wWsg 2mnQ6K7zUNUF+RIdTvrh6CVl6ahFDgzhBVM0bq2uRsytGMqqLufTcpkzzMgjzqBgOyCl OYcIEmJmvTw7jMXUeXI46JLoXuRKTvuyOVBC4r2wLgo1QQcWiN38PXYoZwzbgYSjUGmz Yoyf/qkzspyhVPEEgj70UpLib8FuaUAkVJQwp7x9mwWEo/QaCUa882EpafmJZc1bo/aY d7vvRPTC8HGhMbG9fdlB6uhTR1Q+YQ5wvCIzENfuu9LoKVX0hr3CELgIobVF5Kr9kI53 LyiA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=k3UYu+Yg; 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=1720941040; x=1721545840; 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=nCBMgQtBMB7ofZOd7GPyHPCWBgwTmZ9w4ZTcgQ4l8vWrEUh/S+nwdbc+dvB/4UR9/3 BZS6eZ20n5awge1MPGCaYRL7ifzYrXHBFIcG0QV/stRQjCE4qexWZKDj+ik83+2XmawU NLbKSa6IeB9Dhiv2Za6EPfPE2pRgk6kUkyj08= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720941040; x=1721545840; 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=bQxhahpUq95SPO21YmV/ASBQ0EVzAqU3vg+ugDE4RV6SfqWqWunUqxfOufHQfofNzQ xBePrsgvyKiRZKsc8HKksTvO4vyvskHaSRUg4WdbDUfJv08GI0SqGI5AvYdsLrwKFRcE fp1qMNjJ9KdtahZvTpxK6NwH4H1n7nVEgrlpfdL9tqlFhDpOLvVPLZwr+QTefOl4c9// fkc9IVp2KQOydkJSKh6VBxhG3XlMJxomIu9Gk0hz3WqCR3+CUk/3nH54PD6g6CBAEDcw NYmKjC2mrSw3uwrY33Q34p8HQx5PNdAd6q1vCo7/uSylFIPzVboBHt87CLLgsmo4g+wp 9O6A== X-Forwarded-Encrypted: i=2; AJvYcCV+dD8JOlg2qzQzTRrzmcwiWjfLuUz8qYLV0ctTSI3T5QIXvyrL/UAOCZ+dAYScSWise7hr1WVptgKQigUaac7i4p1yiZ/v1HwKSeVPSca3wz6YEY5IXfmYO/ruow== X-Gm-Message-State: AOJu0YxXNEsqc3lXRcY/PBRpe/tLjOful5sDXyiUWiytOVKuMGKbws0U o478IfNL2JE6vvrZjFabK9gM/vQ/v2A2K4F4vZFo14rMJrjSv4GbnpYMG/L1El5IxQ== X-Google-Smtp-Source: AGHT+IFV4v8LpSoXil8v1Rl9972rQmJHqqHx/LhOjZrQs4QAzPAB1w6Ia4Czp2V1C1TsuWjUcuiKsA== X-Received: by 2002:a05:6402:5187:b0:57d:6326:c658 with SMTP id 4fb4d7f45d1cf-594b7d840admr13336477a12.0.1720941040131; Sun, 14 Jul 2024 00:10:40 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:32e:b0:58b:ce37:ebce with SMTP id 4fb4d7f45d1cf-59825c4211fls172606a12.1.-pod-prod-03-eu; Sun, 14 Jul 2024 00:10:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUXf2RBe8MBpART1rwQBNLg7Wa4oNztH5wGDcM3vUvqTjfwFWSLyRqI4wG+mjBHFhYnM5NeO0anjCtgBIcgnU4RNbnp+NFtD0Cl2BYcGLDcE2JR X-Received: by 2002:a17:906:a2d4:b0:a65:7643:3849 with SMTP id a640c23a62f3a-a780b89e7a1mr954552666b.73.1720941038561; Sun, 14 Jul 2024 00:10:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720941038; cv=none; d=google.com; s=arc-20160816; b=sYt8jPEsBIOLeB4TEE0BMw9lK9XJbIXk2CSkBxm7pf1IRrSGlopHW1HPKA4vYWvhbt A9f/AWzumBnJXuw5VNvyPUwE+lllxHmZQrzWfc+elRH1ByxAAMObUle647sOGK0Fe5Xa Ra0tyALWt8b3iESH7nEl3YpYzpHRSLoDWw9c2jkZhY37HlW37+WanfAPcucFsSAyASDz AVDarHCSILwWtvlaNSC7Sep58WTwXnK0r6pcSM6dDl32Kj6rX2SQr2C54vD9BpmePafy 9Ppb2qSuNaT6NIpuUCiIyaEiCLyISr03NvYh1tT7LYAWe4leSmV3I8DAeHmduF7UrPav johg== 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=spqgk3ArcxlpIQSA1cpOkqKMmjNKVMkFsKl/OyhXraw=; b=XyFe+q/zvhYmy/+tyDRyiZM29iI5np383EO92HFIC0A65q+CCoKpiRYSDeaLz0m3Ds I6pWt/ZRpGkqMo8aZAJq3Z49bre8PLVVV9OMlYysMavNVvhbUeK/TdtvXBO7mQbFuoS3 JlXNv1b5VQEeYTfRzVF2Z1ixyh4+RWynHw1OwXo0yQuPfcqJnuSkuzj7nxUkw6Dkv4lx OMs8ZKQFthyegl0Uoq23aL3478c2zb9GmQG38Gm4vPcHDnZ0sPl5NnMh2aFv8ZJ0IFaE Kpv7mmizrmlr3Qpb0tcmFeURUSs8FC8CcXnwDqTTbvPV/+QY8FnGIRTctZJaJTJ3wFCU WX+A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=k3UYu+Yg; 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-a79bc7cf0cdsor40915466b.16.2024.07.14.00.10.38 for (Google Transport Security); Sun, 14 Jul 2024 00:10:38 -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; AJvYcCVa1AfpcS67Fr2d9j27eR+xithYwAfjggeR4IYq7Tew4Pf7i/oEHsD/WYS0js4RUGbn1LjDIINCBUQM4f/I1EPoZRr4Io5xc78q7U2fVAdMm7Ce X-Received: by 2002:a17:906:d1c7:b0:a77:cd3c:e9b4 with SMTP id a640c23a62f3a-a780b6b389bmr1059910266b.24.1720941037784; Sun, 14 Jul 2024 00:10:37 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jul 2024 00:10:37 -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 09:10:07 +0200 Message-ID: <20240714071023.10417-9-michael@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240714071023.10417-1-michael@amarulasolutions.com> References: <20240714071023.10417-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=k3UYu+Yg; 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; }