From patchwork Thu May 21 16:14:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1295331 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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=a6z3nO6h; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 49SZVh2mnFz9sRf for ; Fri, 22 May 2020 02:16:12 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9817E81E3E; Thu, 21 May 2020 18:15:37 +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="a6z3nO6h"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D42FD8185E; Thu, 21 May 2020 18:15:30 +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-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) (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 EBEB1813C6 for ; Thu, 21 May 2020 18:15:27 +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-x841.google.com with SMTP id n22so5860109qtv.12 for ; Thu, 21 May 2020 09:15:27 -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=vwWfjLE18HtJn/QIhHdsyXSBK1gvsLq7Cf0auNMoqUU=; b=a6z3nO6h7etHJ6l46lP0aKKe9Z6hePXoMAo4e9xRbUmxYMcAlIekP/g3kY7hk1d6uq W0DUvS0R3CQL7PFazIdnebO8at7hilUbVoFs5O28vGz96m1IsL6P6mir6LaBYZcqMSYV hiYS9fuTVoF0RjBNax8/QShJgr29q67QSelSQ9yczibKgYHeRjdwyjQJFz367x9g8Sza bUh1wdCfUDLVn6RTWnInpj72mk40zysZsdvueWQmpTNv7gpt9YIbPZGvnRZojCLfdUQl lsmugK0CTKvSPdzXIeYytBVeJiProE0pR7fVvIHENZUBdWcHwk4fibdjNxM87L602l3q VOMg== 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=vwWfjLE18HtJn/QIhHdsyXSBK1gvsLq7Cf0auNMoqUU=; b=WIwKuASXx7jD4UqdGknuiPLCZZigD/8WzVHsuJCVEMJHU9R2lwVnzhQyssxszznhM7 P7vwmQeLovAJflsg1NqMlC9do0/fA926FDGsi3iaIpUVDjunCT5y2s905zF5d+vqwa3O 3xLmTXT/cHTlUXP/dUCvAqmMK7hDfiwYdt5+RWqMoFdbedSIwVJyi9B4raUDMmXnKflM uaKHsRJXoyehfcyQJLUfWt3MISdEeADEhS8GIqgWDW+v9XkRv9ofrRXB71eYBqRkHVz/ odpXhYtgaRrye4WZRZxO/DrTSAjmsMDGvf2WInbms4U0uPuyxkTsMVJx1EJqq2vl5glv GuHQ== X-Gm-Message-State: AOAM532ZEBDnm3+ydYRNuPU21iFOKT8rVNQb5SYEvcwCF7r68rS1TeEW 3H9miKRi9zk8+0ZJZMBvRAob5BWhxjA= X-Google-Smtp-Source: ABdhPJxBtuoN037yX3nU6kHGprwkzfE3w3Ss5/UT8Di3/aR4A290X0UKtRqMeRYCnpAqmveoNSSOOg== X-Received: by 2002:ac8:34ec:: with SMTP id x41mr11240500qtb.238.1590077726386; Thu, 21 May 2020 09:15:26 -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 e28sm5183538qkn.17.2020.05.21.09.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 09:15:25 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Bin Meng , Rick Chen , Sean Anderson , Lukasz Majewski Subject: [PATCH v13 03/21] clk: Unconditionally recursively en-/dis-able clocks Date: Thu, 21 May 2020 12:14:45 -0400 Message-Id: <20200521161503.384823-4-seanga2@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521161503.384823-1-seanga2@gmail.com> References: <20200521161503.384823-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 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; } }