Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2336774imu; Sat, 10 Nov 2018 12:32:25 -0800 (PST) X-Google-Smtp-Source: AJdET5cWRS7grs0pb06DBjl47Nhf0ek4iBGjEzULBE6beNweDfqnhiF8xwBy0FittA9BrwLWAQQs X-Received: by 2002:a17:902:824:: with SMTP id 33-v6mr7586238plk.107.1541881944996; Sat, 10 Nov 2018 12:32:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541881944; cv=none; d=google.com; s=arc-20160816; b=SBtP09hTwULMBo9xwJY+G17ozDB41MJEBP1TSsUt91If/pGYRLBb3gjr+3fG0gBAtY XCArj5EFFOUVRV2P+pUmqDBaZOfwEU9m3sVnZVK9xfYm8pCOWrzbjxiAOir5iPzvBAw0 dbARGQPIK9hpnxfdjlvo/RPkckXdP42dcxO9kRFulTRHVQcR6Fs6ytOVe12kKhpzWJ0P hZghyoT9fyMl6glfrpFH1AqYTYmJFDKxQ4B2BHQTqhnhjeRSHVXVa1QFVQMxm/V3f5PB /lhzr68H1EKLBFYMq2APGEuE9G9SxGc8MIJBqximc+YxHdWv1voNM/u81bcdFrjXIt2Z Rw5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Wf/u8C0XrToxFFyDJHcHwb5Q4HKFOYNOE9vQVibkCE0=; b=GVVwUBCjTmzpicZ5vOk/28Vo9rjZXuL1qWjF2xp+0CWKNKI1Ni7Z0P5tK6fEAjqUXv eyMTLLABkg6aMkJ6xUaj1PSVKrS1W/nSsdBXYfr6R2WC8I0YitMQry6urMs8EfaU7uO8 UdNTet+0XcbomTOGyL1xz+m/KVqYnpJGnyQqefp+0ciIcquAcfls6DBkHK25X+P2md77 E0y2O+XbiIvLVYECjlYRZm6oWADPmf95vyHTL9ifvzVpvzsTC4+Xs6dxM0/FG+uYsg11 yJ3ypJIE64i3Sb0FFm6TADF3d7atiZ9yBEFOMiwjxHff7kr41hu3I6jJCBR+aQI0f8Ek udsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=aUnKtmTF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q23-v6si11905538pll.178.2018.11.10.12.32.09; Sat, 10 Nov 2018 12:32:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=aUnKtmTF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726898AbeKKGRy (ORCPT + 99 others); Sun, 11 Nov 2018 01:17:54 -0500 Received: from mail.andi.de1.cc ([85.214.239.24]:55174 "EHLO h2641619.stratoserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725870AbeKKGRw (ORCPT ); Sun, 11 Nov 2018 01:17:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kemnade.info; s=20180802; h=References:In-Reply-To:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Wf/u8C0XrToxFFyDJHcHwb5Q4HKFOYNOE9vQVibkCE0=; b=aUnKtmTFxtHvV2fn4h6KxQGkG svdITzofToM7T0gTNPFiCYjORzReq/q3AUUw5/LvGEmLTkNYrw2UQANBaBzc2oTrWs7E9LeIy4Esv YWmayvdNviUHkjyy/pJ7w+qVUEyQkTMvSejoIYPFea7Yv+9EQRLzdCfRGujZR3n6KBTQk=; Received: from p200300ccfbcefb001a3da2fffebfd33a.dip0.t-ipconnect.de ([2003:cc:fbce:fb00:1a3d:a2ff:febf:d33a] helo=aktux) by h2641619.stratoserver.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLZuj-0000Au-Bf; Sat, 10 Nov 2018 21:31:29 +0100 Received: from andi by aktux with local (Exim 4.89) (envelope-from ) id 1gLZuj-0003Tp-1E; Sat, 10 Nov 2018 21:31:29 +0100 From: Andreas Kemnade To: t-kristo@ti.com, mturquette@baylibre.com, sboyd@kernel.org, linux-omap@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, bcousson@baylibre.com, paul@pwsan.com, tony@atomide.com, letux-kernel@openphoenux.org Cc: Andreas Kemnade Subject: [PATCH v2 1/3] clk: ti: add a usecount for autoidle Date: Sat, 10 Nov 2018 21:31:13 +0100 Message-Id: <20181110203115.13335-2-andreas@kemnade.info> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181110203115.13335-1-andreas@kemnade.info> References: <20181110203115.13335-1-andreas@kemnade.info> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Multiple users might deny autoidle on a clock. So we should have some counting here, also according to the comment in _setup_iclk_autoidle(). Also setting autoidle regs is not atomic, so there is another reason for locking. Signed-off-by: Andreas Kemnade --- Changes since v1: - use spinlocks instead of mutexes - invert logic --- drivers/clk/ti/autoidle.c | 36 ++++++++++++++++++++++++++++-------- include/linux/clk/ti.h | 1 + 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/clk/ti/autoidle.c b/drivers/clk/ti/autoidle.c index 7bb9afbe4058..161f67850393 100644 --- a/drivers/clk/ti/autoidle.c +++ b/drivers/clk/ti/autoidle.c @@ -37,6 +37,14 @@ struct clk_ti_autoidle { static LIST_HEAD(autoidle_clks); static LIST_HEAD(clk_hw_omap_clocks); +/* + * we have some non-atomic read/write + * operations behind it, so lets + * take one lock for handling autoidle + * of all clocks + */ +static DEFINE_SPINLOCK(autoidle_spinlock); + /** * omap2_clk_deny_idle - disable autoidle on an OMAP clock * @clk: struct clk * to disable autoidle for @@ -48,8 +56,15 @@ int omap2_clk_deny_idle(struct clk *clk) struct clk_hw_omap *c; c = to_clk_hw_omap(__clk_get_hw(clk)); - if (c->ops && c->ops->deny_idle) - c->ops->deny_idle(c); + if (c->ops && c->ops->deny_idle) { + unsigned long irqflags; + + spin_lock_irqsave(&autoidle_spinlock, irqflags); + c->autoidle_count++; + if (c->autoidle_count == 1) + c->ops->deny_idle(c); + spin_unlock_irqrestore(&autoidle_spinlock, irqflags); + } return 0; } @@ -64,8 +79,15 @@ int omap2_clk_allow_idle(struct clk *clk) struct clk_hw_omap *c; c = to_clk_hw_omap(__clk_get_hw(clk)); - if (c->ops && c->ops->allow_idle) - c->ops->allow_idle(c); + if (c->ops && c->ops->allow_idle) { + unsigned long irqflags; + + spin_lock_irqsave(&autoidle_spinlock, irqflags); + c->autoidle_count--; + if (c->autoidle_count == 0) + c->ops->allow_idle(c); + spin_unlock_irqrestore(&autoidle_spinlock, irqflags); + } return 0; } @@ -201,8 +223,7 @@ int omap2_clk_enable_autoidle_all(void) struct clk_hw_omap *c; list_for_each_entry(c, &clk_hw_omap_clocks, node) - if (c->ops && c->ops->allow_idle) - c->ops->allow_idle(c); + omap2_clk_allow_idle(c->hw.clk); _clk_generic_allow_autoidle_all(); @@ -223,8 +244,7 @@ int omap2_clk_disable_autoidle_all(void) struct clk_hw_omap *c; list_for_each_entry(c, &clk_hw_omap_clocks, node) - if (c->ops && c->ops->deny_idle) - c->ops->deny_idle(c); + omap2_clk_deny_idle(c->hw.clk); _clk_generic_deny_autoidle_all(); diff --git a/include/linux/clk/ti.h b/include/linux/clk/ti.h index eacc5df57b99..78872efc7be0 100644 --- a/include/linux/clk/ti.h +++ b/include/linux/clk/ti.h @@ -160,6 +160,7 @@ struct clk_hw_omap { struct clockdomain *clkdm; const struct clk_hw_omap_ops *ops; u32 context; + int autoidle_count; }; /* -- 2.11.0