From patchwork Wed Aug 5 15:11:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 1341260 X-Patchwork-Delegate: eugen.hristev@microchip.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=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=lPcRqyMV; 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 4BMFVb4Vn7z9sPC for ; Thu, 6 Aug 2020 01:12:55 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 314D582193; Wed, 5 Aug 2020 17:12:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.b="lPcRqyMV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CD33082193; Wed, 5 Aug 2020 17:12:24 +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,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from esa2.microchip.iphmx.com (esa2.microchip.iphmx.com [68.232.149.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0625E82176 for ; Wed, 5 Aug 2020 17:12:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=Claudiu.Beznea@microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1596640340; x=1628176340; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=uFLkWsTZiR7u0p+EXeKJnztA3ftZ0h6He4d/VIAf1G8=; b=lPcRqyMVvEVXV9GUd+aVCECfvGZ9I3gI1BwOEKz/nZlT+uKUSyo45dUg dXJRNyN8FkcN9aFNqeMSnLUrLYfjK0ANOMcDo2JF4J2HRqALI1uqFs9MS Kb7Dld1nBdh2JR1xWQOBR3YcPtK5jlOGivgCaw2drxTWpXJbcHhcs5UZ0 UeTGr3EN6UUMFDFsdSdS0YnU/hb+sV6UpKpRw22khpcjSLNRmX1gaffQk LDNMQLrnBHbIGdQT7i6w7R3Ppx8n0FNYrrw0X3JlZaTWqUnxkA6HfpiRU ixoyRdxmG4xMNwcj969q7RlXJ7rtbYYJUjH9U5KrPWoO4T7KYhlzKlq9e Q==; IronPort-SDR: TjH8DFYvus9iy/pm9/n0h7igmurVXciHyCjM+UgdluulWE83K1PdwRE/F/lAZtQLCXqlGkdKOS xUwyOMFNZmYJBvRU8zAMZuJM02Ah8u3z8uJmB6CDX7quDOLe3oBk7ygBtBNiPlkDNac7JnCNQA NJ2V8jlcivC2/wZ8dX3Uq0ZBhdpb306LwGmQKXsrgUEIyUFvsB8D9ifZEiG+4gD/YlUhENW550 y5p6EV4scZvwDciYJev/b4605Gk9D+vB5WtMV1LSeeel/N1rbE3gxOsFoYIRqww1qqY1ttOesu EPY= X-IronPort-AV: E=Sophos;i="5.75,438,1589266800"; d="scan'208";a="84521106" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 05 Aug 2020 08:12:18 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 5 Aug 2020 08:12:14 -0700 Received: from m18063-ThinkPad-T460p.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.1979.3 via Frontend Transport; Wed, 5 Aug 2020 08:12:12 -0700 From: Claudiu Beznea To: , CC: , Claudiu Beznea Subject: [PATCH v2 04/21] clk: do not disable clock if it is critical Date: Wed, 5 Aug 2020 18:11:48 +0300 Message-ID: <1596640325-20014-5-git-send-email-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1596640325-20014-1-git-send-email-claudiu.beznea@microchip.com> References: <1596640325-20014-1-git-send-email-claudiu.beznea@microchip.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.3 at phobos.denx.de X-Virus-Status: Clean Do not disable clock if it is a critical one. Signed-off-by: Claudiu Beznea Reviewed-by: Simon Glass Reviewed-by: Simon Glass --- drivers/clk/clk-uclass.c | 3 +++ test/dm/clk_ccf.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 5e0c8419d65b..b8538f342a0c 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -606,6 +606,9 @@ int clk_disable(struct clk *clk) if (CONFIG_IS_ENABLED(CLK_CCF)) { if (clk->id && !clk_get_by_id(clk->id, &clkp)) { + if (clkp->flags & CLK_IS_CRITICAL) + return 0; + if (clkp->enable_count == 0) { printf("clk %s already disabled\n", clkp->dev->name); diff --git a/test/dm/clk_ccf.c b/test/dm/clk_ccf.c index b039cc5f8d8f..592509ff7c9d 100644 --- a/test/dm/clk_ccf.c +++ b/test/dm/clk_ccf.c @@ -24,7 +24,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) int ret; #if CONFIG_IS_ENABLED(CLK_CCF) const char *clkname; - int clkid; + int clkid, i; #endif /* Get the device using the clk device */ @@ -118,6 +118,36 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) pclk = clk_get_parent(clk); ut_assertok_ptr(pclk); ut_asserteq_str(clkname, pclk->dev->name); + + /* Test disabling critical clock. */ + ret = clk_get_by_id(SANDBOX_CLK_I2C_ROOT, &clk); + ut_assertok(ret); + ut_asserteq_str("i2c_root", clk->dev->name); + + /* Disable it, if any. */ + ret = sandbox_clk_enable_count(clk); + for (i = 0; i < ret; i++) { + ret = clk_disable(clk); + ut_assertok(ret); + } + + ret = sandbox_clk_enable_count(clk); + ut_asserteq(ret, 0); + + clk->flags = CLK_IS_CRITICAL; + ret = clk_enable(clk); + ut_assertok(ret); + + ret = clk_disable(clk); + ut_assertok(ret); + ret = sandbox_clk_enable_count(clk); + ut_asserteq(ret, 1); + clk->flags &= ~CLK_IS_CRITICAL; + + ret = clk_disable(clk); + ut_assertok(ret); + ret = sandbox_clk_enable_count(clk); + ut_asserteq(ret, 0); #endif return 1;