From patchwork Sun May 3 02:35:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1281817 X-Patchwork-Delegate: uboot@andestech.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=KkE877eK; 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 49F99s6B67z9sPF for ; Sun, 3 May 2020 12:37:05 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8DD0681E7A; Sun, 3 May 2020 04:36:20 +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="KkE877eK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C462D81E89; Sun, 3 May 2020 04:36:15 +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-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) (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 E45DA81E69 for ; Sun, 3 May 2020 04:36:10 +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-qt1-x842.google.com with SMTP id w29so11195804qtv.3 for ; Sat, 02 May 2020 19:36:10 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=KV+Wfmv8NzJ/8GiouN+mz/HR1iaw7p9vyCwoMp8TfOE=; b=KkE877eKDqDiFd1r+P5z5SAbvM3I3ygkyff1thWXogawaJ39zaUkKZYSPZ5eIzLxfM 308M4PLSw0NV1bdzd6iOKiHHB3Vqzlp8Fx7BKA/aWe1a4wapsIVm8ON7q7dUZMWlPA6b u7vf7QOSD6DdCW4dZerYFw+HKCxph8JzPpiJJwWO1A+UyXWkrCi+1pcSmg0RUeQEiVPG vN0I17Cl5FXZw9RlgE/NAQO7zuOoNnE7bBtw5uYhMmOPgsP7t5KnloFwmGew60fz97fh JiCk7+Dz5okfct2AAo0+gcHieY8HcCBQlZ/z4IRMMiETO3YbOeo2Suy7xtO9RrF61H3m 6r4g== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=KV+Wfmv8NzJ/8GiouN+mz/HR1iaw7p9vyCwoMp8TfOE=; b=kpSzq8G2bkxm3SLx5QTqSLHi6Sf2E+3Ge+1qmeJE+fiD4a7mgkeJpbHvqG8NOpigN9 zCNt+ULqrBwWBWsoaphHrQ8SjF8SfEeGbO1EApe9zXGHB4S+G6ZbrqrRR69jnVYSfZ6q gzZewl9FzFpGBT5P59z9G1zgrpFMlRFmQvagXUdsM/paGjDSQCAn3t6RONXRzrvriVvd eC5b51p19snKJ4ojUA2Ofkg0It9RYO6UuhmJgqooDNRcvih1id4YpiFUy1oISj6U0N9l oeJ8DhMpPQfrXuwq1J36WFL2Em00lRQ8FijRXrAiklsk0i0NF9zDIZ1qgbXwS9sLo/HB JPfQ== X-Gm-Message-State: AGi0PuZe/QaIve5Zg9xZOXdnP7StGd3/G7swLE0MuEuGq8+28LmTtY9J wk2vB83oiaW5YEmlONvIjLsDI0CmejA= X-Google-Smtp-Source: APiQypKe83IjYbD1Ucg35UHN5Vs6rr4PXppwP1ZIsFsVsjtgXzPJmyxwYqQBzEeVDo7dk3A9LEPEDw== X-Received: by 2002:aed:2213:: with SMTP id n19mr11244714qtc.246.1588473369558; Sat, 02 May 2020 19:36:09 -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 a124sm6554114qkf.93.2020.05.02.19.36.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 May 2020 19:36:09 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Rick Chen , Bin Meng , Sean Anderson , Lukasz Majewski Subject: [PATCH v9 03/21] clk: Unconditionally recursively en-/dis-able clocks Date: Sat, 2 May 2020 22:35:32 -0400 Message-Id: <20200503023550.326791-4-seanga2@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200503023550.326791-1-seanga2@gmail.com> References: <20200503023550.326791-1-seanga2@gmail.com> 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 CC: Lukasz Majewski --- Changes in v6: - Fix disable incorrectly recursing into non-clock devices Changes in v5: - Clear enable_count on request Changes in v4: - Lint Changes in v3: - New 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 71878474eb..aa8dd9d027 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -410,6 +410,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; @@ -521,7 +522,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); @@ -530,32 +530,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; @@ -581,7 +578,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); @@ -590,29 +586,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; } }