From patchwork Wed Jun 24 10:47:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1316073 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Q07IPvLq; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49sKcG7540z9sQt for ; Wed, 24 Jun 2020 20:47:58 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C1D3082008; Wed, 24 Jun 2020 12:47:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Q07IPvLq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7772C82015; Wed, 24 Jun 2020 12:47:50 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5164C82008 for ; Wed, 24 Jun 2020 12:47:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x741.google.com with SMTP id l6so1340795qkc.6 for ; Wed, 24 Jun 2020 03:47:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3YFm4z33XKMTbEeEru0mcuGYtJ8awdP6n/lwFJg/3QI=; b=Q07IPvLqmqF4HmVyqlkOXjsja4mCIuVwcgKzbMh3/XFvxZhU7lIZMynjJXx+pJJ9f4 xcBwsxzN2haR4jNJTrcdPb1v4zt2wRkrAwz80o7rS5KytQjMWEcHyGsV1AFsa58M+Y3O +f3K1Y9zRBmcVckTwNYbSU/oQ/8pTgJjlsGmQy1YI1d9inKIvxoV17HnEdt0w0G3V3Fh 09q2irCQTG5Xbm90cv9kRiubh+NIsJYm4xkGrnz39zai7F1nPmZ9PYZf6y20VDK6riun HTxM3B9ZYjJKW9x+8HrXCpw2KHlwBcv8epNuvFDcUG1Rum8CX62vZFu8g19sbwsMfwf9 Nm2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3YFm4z33XKMTbEeEru0mcuGYtJ8awdP6n/lwFJg/3QI=; b=LiVnr8qMJYZ4p8JbugRInKIKNRF4gYgIlKcTGHwA33ZlqRsnjy8eugfzCUv85QmKEB ra7J4RA8HvZN0tJtUGwAuVqJqxWrCo83+odTwHYnuLKMjG0hVIK9z8N5Z5Z5wQq0+NM/ Dd5LRRjNIIdRmCKOvJBoiBnbbXKOldOCcEyUWaciYZFgpKfiNdrfdYRy43CCVEIqSn4C IsocU7tQ0OKzgbxJpOgJAywzYTLOP85RZ69YBwldkNLEUwKRGeFuzGYXxx8wR4ItZc8s YWA0SyAnlrwzl1IVEtUDwIxScUZQB8EyYFq/7OxNgN9QoMUhPBnWHgJJow4I/hjdRbLt SMLA== X-Gm-Message-State: AOAM532LfxQ9hZYbF1F9PoXbSm+LanSIrQ/eAHWWIZ1gbWYMrgVQEYMV wQj0EQM0JjtitMRRBeU6mfGDgvjz7xfQTA== X-Google-Smtp-Source: ABdhPJx81Ctm2r96LFfb+o/XPfdMVO0s31c6rp4MYef9Fdei9grSidNmWwh2uc8xeVbxarg5EBkezw== X-Received: by 2002:a37:418d:: with SMTP id o135mr21991881qka.244.1592995658708; Wed, 24 Jun 2020 03:47:38 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id j16sm3073704qtn.91.2020.06.24.03.47.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 03:47:37 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Lukasz Majewski , Sean Anderson Subject: [PATCH] clk: Unconditionally recursively en-/dis-able clocks Date: Wed, 24 Jun 2020 06:47:23 -0400 Message-Id: <20200624104723.364002-1-seanga2@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean For clocks not in the CCF, their parents will not have UCLASS_CLK, so we just enable them as normal. The enable count is local to the struct clk, but this will never result in the actual en-/dis-able op being called (unless the same struct clk is enabled twice). For clocks in the CCF, we always traverse up the tree when enabling. Previously, CCF clocks without id set would be skipped, stopping the traversal too early. Signed-off-by: Sean Anderson --- This patch was previously part of [1] [1] https://patchwork.ozlabs.org/project/uboot/list/?series=178480 drivers/clk/clk-uclass.c | 60 ++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 9ffc2243cb..774d6ccdf8 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -412,6 +412,7 @@ int clk_request(struct udevice *dev, struct clk *clk) ops = clk_dev_ops(dev); clk->dev = dev; + clk->enable_count = 0; if (!ops->request) return 0; @@ -523,7 +524,6 @@ int clk_set_parent(struct clk *clk, struct clk *parent) int clk_enable(struct clk *clk) { const struct clk_ops *ops; - struct clk *clkp = NULL; int ret; debug("%s(clk=%p)\n", __func__, clk); @@ -532,32 +532,29 @@ int clk_enable(struct clk *clk) ops = clk_dev_ops(clk->dev); if (CONFIG_IS_ENABLED(CLK_CCF)) { - /* Take id 0 as a non-valid clk, such as dummy */ - if (clk->id && !clk_get_by_id(clk->id, &clkp)) { - if (clkp->enable_count) { - clkp->enable_count++; - return 0; - } - if (clkp->dev->parent && - device_get_uclass_id(clkp->dev) == UCLASS_CLK) { - ret = clk_enable(dev_get_clk_ptr(clkp->dev->parent)); - if (ret) { - printf("Enable %s failed\n", - clkp->dev->parent->name); - return ret; - } + if (clk->enable_count) { + clk->enable_count++; + return 0; + } + if (clk->dev->parent && + device_get_uclass_id(clk->dev->parent) == UCLASS_CLK) { + ret = clk_enable(dev_get_clk_ptr(clk->dev->parent)); + if (ret) { + printf("Enable %s failed\n", + clk->dev->parent->name); + return ret; } } if (ops->enable) { ret = ops->enable(clk); if (ret) { - printf("Enable %s failed\n", clk->dev->name); + printf("Enable %s failed (error %d)\n", + clk->dev->name, ret); return ret; } } - if (clkp) - clkp->enable_count++; + clk->enable_count++; } else { if (!ops->enable) return -ENOSYS; @@ -583,7 +580,6 @@ int clk_enable_bulk(struct clk_bulk *bulk) int clk_disable(struct clk *clk) { const struct clk_ops *ops; - struct clk *clkp = NULL; int ret; debug("%s(clk=%p)\n", __func__, clk); @@ -592,29 +588,27 @@ int clk_disable(struct clk *clk) ops = clk_dev_ops(clk->dev); if (CONFIG_IS_ENABLED(CLK_CCF)) { - if (clk->id && !clk_get_by_id(clk->id, &clkp)) { - if (clkp->enable_count == 0) { - printf("clk %s already disabled\n", - clkp->dev->name); - return 0; - } - - if (--clkp->enable_count > 0) - return 0; + if (clk->enable_count == 0) { + printf("clk %s already disabled\n", + clk->dev->name); + return 0; } + if (--clk->enable_count > 0) + return 0; + if (ops->disable) { ret = ops->disable(clk); if (ret) return ret; } - if (clkp && clkp->dev->parent && - device_get_uclass_id(clkp->dev) == UCLASS_CLK) { - ret = clk_disable(dev_get_clk_ptr(clkp->dev->parent)); + if (clk->dev->parent && + device_get_uclass_id(clk->dev->parent) == UCLASS_CLK) { + ret = clk_disable(dev_get_clk_ptr(clk->dev->parent)); if (ret) { - printf("Disable %s failed\n", - clkp->dev->parent->name); + printf("Disable %s failed (error %d)\n", + clk->dev->parent->name, ret); return ret; } }