From patchwork Sun Jul 14 10:53:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 3266 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 6217640F59 for ; Sun, 14 Jul 2024 12:53:46 +0200 (CEST) Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2ee9f58c858sf33846971fa.3 for ; Sun, 14 Jul 2024 03:53:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1720954426; cv=pass; d=google.com; s=arc-20160816; b=oBslAFKGUjTWOLTPIOMVBR9fvXXjJZPD98v0gLAoN+E+RYm0hj3xqCSmH4BIECHaSO 7HzblieNTKiGzk6pHF3sHU/5G2CVeUV7qbfcAJlqDu3bAtYy9wMe/HPLyTM9NwBsiWQ6 VIDBqbkn8XxZujJjOWMgqHuRdI3gfN76hbM+WVWCpfFA+03WLAB0TUV6nEMYRfWAeLhE u+808ThjlCiNT1tsUz9YAo5Qwps5bxOUSK9amlJwda7yAjIUyqaa+If2vkA/sNt3pt2x Xmxaz1pSkAw7gfxMNPvOUXHGV35qgUOec+A1U7kPz4viBV2bgiT8cRt10xM1paZvTEz8 SYVQ== 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=L3PsDzFvl/z0yOmu0tJ6Kvoqqz2BEw5PLEttWud+RZI=; b=IfZ6WRUbbXsuwDPQ77w1Gl+p1Hp+41VvVssARwBCZW5XgILpj2y/NDN5PifOosZLhE upU/bt6wqGR1AxpO/9yQXWCYsiB+k03csUd440fAJUfJoVOBNgkiffskYM1pnTG5HiC6 g+aNCtHOHvTn6bPtpyuxP1OE5VDwaJlkFaH9cf4EJL4SfAj/OLP9nSaWRgG0b1K9oFVn NvF3f63OO7ihZzXFJrpdu+2M8vXkuLDJ6Dl+29rTfKIGTLJRtFeooZwP29ZeOvR8xDp2 eJCeSGqTGl6t1X5raLmPkFWr+Rye5JRYZp5O2pc4yusXu0oe5dMqLoV1u+qSPMK6Qi1Z yBKw==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=TbpRIymn; 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=1720954426; x=1721559226; 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=ganeVQAwpyOTIL7Krk0uE8fKOjeGLwaR7FwxmEqmg/3hCUvkKOZAP+6EcIeSFPfQYF WN1YCtfGI2N1lbj8Q5u++KxL42ho8jTZcy8oHw+oX0lQUdh7kVdYT6BvQc9feOg7DZrx y1MHk4bqWtywP0kiN2vZ5IrYj2TXYBzXKjxzE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720954426; x=1721559226; 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=cCbwBw/jpfnN+IQN1BqcXg045b//bSNx4spP4jKDBwP7rDYaz1X2G3+TG3uZer0/46 mxYlp1Lk1aFeaiKhdMBlinK+dt/hgpgBf8NQ0p1cFlLjh+lza7UtEtpc0kybJrR/2Apx V5ENM3MXgvwkKRiBoo+DQOtMxlbmL5b9+RJwBp0esvM91M0ZxGXPkHRWNZGwOaoOcO0o tIkf7vbiL/eeIx+Z82hDry8oZkHxRHEhmPgOXeAyAvwt+X/0jQOi9zPWdNlzj26tEptR kW3Rqa0O5nU07qXyBcRe6V1hYOTp8TX95QXu+pjaPg1zoraxWVAiQEqkDPhLvYBT+zAz McOw== X-Forwarded-Encrypted: i=2; AJvYcCUBSQ651gVk3FAy6riD+pTOzzgQ3ctxcOEXVWPUj96Zr0FSyj/y8hIwUpTsj+iGkMQD4ww2pf1DVYS85BFnFGOCPf3KpLtXWmp7iDBioG2M7rtleDqw6Nl0EtqtNA== X-Gm-Message-State: AOJu0Yxeh866/y8LNXT9wfpndqWDq5l04j82PPjfnx7CKc6zGPZj0alG v5LvnbDLWUQqXgWnuaxyHeoAi26i7mJWBLqbYpk2vpkzKhvhrUkYoM8NmWTRQAKarqT+f35G0Q= = X-Google-Smtp-Source: AGHT+IH9jwRNNp/JTgX8wCas03/4xmju66mfAZlWfJDMmF69QOi5GUcYxim064Uku9dVlZ87tIOmFQ== X-Received: by 2002:a05:6512:2247:b0:52c:dec1:4578 with SMTP id 2adb3069b0e04-52eb99d3d82mr9936706e87.60.1720954425850; Sun, 14 Jul 2024 03:53:45 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:ac2:561b:0:b0:52c:e3d2:83c3 with SMTP id 2adb3069b0e04-52ec4093c35ls1738339e87.0.-pod-prod-07-eu; Sun, 14 Jul 2024 03:53:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVruDfYq9rfbmtzx2ykYph5hQ8GhRufqZ4kTLQEdYKKsawwm7g5rK4C9zt/kg+7HMueoLwCCoWUELFq9bWJtK8A2fimTADkeHVOC0FbdNMq77kX X-Received: by 2002:a05:6512:3b82:b0:52c:dc0b:42cf with SMTP id 2adb3069b0e04-52eb998fcdcmr10571220e87.9.1720954423823; Sun, 14 Jul 2024 03:53:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720954423; cv=none; d=google.com; s=arc-20160816; b=dZZLPWH/9MU2cA3nVkh759y6YHYJCFGJRXmmOWvwggxS+y92jnmStshB4f96LYMHeP VuCsaDRe8HbXZB8rTpcckih/CrDzxUCI8V2CASN0B91OAfykaz+UFmfOgA4x37n3p9AK vmwl/g8AuxO8fEkQfyeKkw6gPbmIe6GY13PG8SLYhTrDS8U01cb9u4yCQlAmHRaQE+J6 oUrIuoWJPnSCmc2HTm9sb+BKlQzzaZo/A+soUgFp2+cdKQvswNJRNyYBhAh0XXI++8bB YDm1fHQgy+c8e9sH0ccWpaFZ0FfKzYBlMTtr6Fb7/vU+gzKVRoV8APhS/tm1no+RHspO NVZA== 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=9fWjDrfvSYrK1UQ4g7mm/lg9f4gqFF2m1f9zJYoVFAw=; b=iY679BnENU8Pek5ocz+yEmRUWgL2pj9tv7ak6EaC+q5dd7GvXYeUW+zeH9pZUpaaNQ wgB4ASlhKhZS6Fem60j8Etg7a6GQ8AesOAclxNNKR3JcDT32/8Q+kqoZkXNnNqIu8Cju Ef3dzEOtjUr7/67OW567rU+s+KlefjXgyvaxNOJtQqpEoP+cnR3wBDFniL3D8FtA9AK6 IQNJhh11Bp+aTKrBR23VjHScyU9WO0G0Ru9pme2Jf5/dXQSXskN6rn9MhY2ZTeVlyVeG cTYr+l2+O8hsCFnVrYiQ/71OtiEyU7SI7QRpk67NrwjrcJGnWE7HaIQlmmn3+hSOH/DL tZMw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=TbpRIymn; 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-a79bc5b7df6sor39721166b.10.2024.07.14.03.53.43 for (Google Transport Security); Sun, 14 Jul 2024 03:53:43 -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; AJvYcCX8hofXrwvmiICcSgg1QKtpMLPaL3nEjZsaV9EBUwJRSH9niWp15jmKVBhTAKeJB7cRWjDyXovJQsDXvHiahBBWNc/5GpPx4bTiOJQuFeimYyRt X-Received: by 2002:a17:906:724b:b0:a72:8c15:c73e with SMTP id a640c23a62f3a-a780b88607fmr1028700266b.55.1720954423349; Sun, 14 Jul 2024 03:53:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jul 2024 03:53:42 -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 12:53:12 +0200 Message-ID: <20240714105328.35825-9-michael@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240714105328.35825-1-michael@amarulasolutions.com> References: <20240714105328.35825-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=TbpRIymn; 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; }