Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1436635imm; Thu, 4 Oct 2018 13:39:50 -0700 (PDT) X-Google-Smtp-Source: ACcGV63/U+EOpEX+QPRw+GqFCPHZjUk42RqHwwmr145juzYlbNsJLRgmyr53GHkbTqMBJ0FF00N2 X-Received: by 2002:a63:5f05:: with SMTP id t5-v6mr7070930pgb.352.1538685589981; Thu, 04 Oct 2018 13:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538685589; cv=none; d=google.com; s=arc-20160816; b=nUIG4uPVQBpwJlJT47fCVApjFIaD3zeKsOmiA3rv55EJYKJtj1JjtTvrKVqF1RhZC/ vXAeOmtwrm1guMP5LtdulB+7FrzcQWt4gy7mEv7J2Z1cgGXs2+WMV6EXeLXuu+4ZEIpj ur43xqTX6hih1jkDp35Ijx5nNVcNHjQj4Q9+Kwt7l+vRqs7NwSQaAuF+9ORlmzi40fDD sRcOtBqPHqKC3UgZ2H46KTxqtKf5SUIcH2J2Gt5DZkk//T2XImiPF013hoZbiY/W8zsh 6bm3jAz5xzgrbXhVOLuisS63zIoqAWVs7dX8clW8geMDovTp9VZuGehfBt+ivMHGCC4m KvUA== 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=hxKaBbQP9Ohf6unfmS5C4E5JDsTkQe6IxUA7qgDVBQc=; b=GPUh0KA5oNN2FSgkZVGZ6W2fj34AH0Hj88bGQdJVga37zKYlXwQlVK6tcAUyleHf4c 6GPdJP5+W67zG39WC5NsWjnBjf65uYl9MAsgYnSmn44U6sPRm5sFKT6HavAzyguRRsL6 TyOCXzAArN5AHO8upq5CY+jUggi82wqCSVoHLWbDWvZe+//kx6V6pCu3Qie914H+MKJB mN7kg2LCQ0BkJT0p+FA+a8RnRS2hZcqeKLfdNvrz2bAYNGCWfH7p1riLnfjnRDkR4EVk vwFZ3CZj4rYbTT7NvELd3g/9u8TcRCSozuBGv7dPEEjcGHjc5oEWIUnaTDhjTlzpVUcE SDqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=AU1VWG6c; 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 j24-v6si5433156pff.42.2018.10.04.13.39.34; Thu, 04 Oct 2018 13:39:49 -0700 (PDT) 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=AU1VWG6c; 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 S1727758AbeJEDd3 (ORCPT + 99 others); Thu, 4 Oct 2018 23:33:29 -0400 Received: from mail.andi.de1.cc ([85.214.239.24]:33926 "EHLO h2641619.stratoserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727354AbeJEDd3 (ORCPT ); Thu, 4 Oct 2018 23:33:29 -0400 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=hxKaBbQP9Ohf6unfmS5C4E5JDsTkQe6IxUA7qgDVBQc=; b=AU1VWG6c6U0Tcj29nA5TnaB9i yf4HzBgo0h+2bKYXNSnhpf3lj0a4NtcoVGVBrXWLH8DxemA4oiPT7q6XF0laRSRMGb1kzKABT2+Cs wtSGEbhs1MhP7951I3K/trG7ArKgYwTwPOrx0xCH/q3WxJPjzObu7tT1f2JRQWgWU6ZMc=; Received: from p200300ccfbcbd5001a3da2fffebfd33a.dip0.t-ipconnect.de ([2003:cc:fbcb:d500: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 1g8AOA-0007GZ-C4; Thu, 04 Oct 2018 22:38:26 +0200 Received: from andi by aktux with local (Exim 4.89) (envelope-from ) id 1g8AOA-0005mB-1h; Thu, 04 Oct 2018 22:38:26 +0200 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 1/2] clk: ti: add a usecount for autoidle Date: Thu, 4 Oct 2018 22:38:16 +0200 Message-Id: <20181004203817.22101-2-andreas@kemnade.info> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181004203817.22101-1-andreas@kemnade.info> References: <20181004203817.22101-1-andreas@kemnade.info> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We have the scenario that first autoidle is disabled for all clocks, then it is disabled for selected ones and then enabled for all. So we should have some counting here, also according to the comment in _setup_iclk_autoidle() Signed-off-by: Andreas Kemnade --- drivers/clk/ti/autoidle.c | 32 ++++++++++++++++++++++++-------- include/linux/clk/ti.h | 1 + 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/drivers/clk/ti/autoidle.c b/drivers/clk/ti/autoidle.c index 7bb9afbe4058..bb6cff168e73 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 mutex for handling autoidle + * of all clocks + */ +static DEFINE_MUTEX(autoidle_mutex); + /** * omap2_clk_deny_idle - disable autoidle on an OMAP clock * @clk: struct clk * to disable autoidle for @@ -48,8 +56,13 @@ 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) { + mutex_lock(&autoidle_mutex); + c->autoidle_count--; + if (c->autoidle_count == -1) + c->ops->deny_idle(c); + mutex_unlock(&autoidle_mutex); + } return 0; } @@ -64,8 +77,13 @@ 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) { + mutex_lock(&autoidle_mutex); + c->autoidle_count++; + if (c->autoidle_count == 0) + c->ops->allow_idle(c); + mutex_unlock(&autoidle_mutex); + } return 0; } @@ -201,8 +219,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 +240,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 a8faa38b1ed6..c460355419c0 100644 --- a/include/linux/clk/ti.h +++ b/include/linux/clk/ti.h @@ -159,6 +159,7 @@ struct clk_hw_omap { const char *clkdm_name; struct clockdomain *clkdm; const struct clk_hw_omap_ops *ops; + int autoidle_count; }; /* -- 2.11.0