Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1299263imu; Wed, 16 Jan 2019 16:42:08 -0800 (PST) X-Google-Smtp-Source: ALg8bN71+01nsGL/C4Vcp0fCKK+sItTtuj6/8OkW1YpJoPLe9BpKLvSYsj4s6sqItT6FUUZaULLM X-Received: by 2002:a62:1a91:: with SMTP id a139mr13181708pfa.64.1547685728750; Wed, 16 Jan 2019 16:42:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547685728; cv=none; d=google.com; s=arc-20160816; b=oucRM+jgkEtygR4WXdjGJR6GNLMC+xsYKA99tT9mIY9Gy3WapAYZKrxhbBbiOCLZhc Tynb+BDMqYO32i+9ELREzzJx4WH2cqr7Q2zgPOn45LQA1iLM65TBe6ZtWzgk/UGUFbWz 6dwFflAnDPL+DsoK3GqQiOJnwURjeB99G/Z9skPWsx2V/arA6wkj9Gb/hJSH/f5s0Gc4 afNhONYD9jZPc5axpBmpZhAYcoN4SEJLKhl1igxVZTZKMDVU/yPGZkkKHOqv83fBkZXf /itcJiZLzGXCHajTEacS+UbBm1WZ7KojxZaCmWmk1JuoADSZP1ctJwSkdX3GwiJMROja X6NQ== 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=0HrSc9TjfAApcBtB66m46jVWZ+gQ86n9XEvM/jcR5Bk=; b=EwCvMQuCyHhuu19YyatXO/MGVhvF8eq5vH2iy8/frfd+ejFh8bzJSCcQ0AXwQWz04L C+AQAW/B5WfGrikqor+qUv4YNwjwgFH2m7uJiDuwkfI4zB905e3Mz7Tk3h7ebzyHHX/Z 73LqqiCGfQ9u4Dzh3cl/BS6WuTHcS97OzW6TvuSDa3+AmHkx8iUscZj+Wvadg6Ea4z45 t+Vfk7jh42Wpb9ya8bZHAOVtPm+yW3+HHb3Wyae9LyMhJlxtwK7oNncER7ZYOR4SfD5Z AMBr3vVMOSnqjyAnZFkxgC3YkUpPC/K8+Y4P4ac57ZOUixGfk+raJVtkTuUIwEHAL5ST JHEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=bTuW51YH; 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 c10si8064881pla.173.2019.01.16.16.41.50; Wed, 16 Jan 2019 16:42:08 -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=bTuW51YH; 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 S1732756AbfAPWEq (ORCPT + 99 others); Wed, 16 Jan 2019 17:04:46 -0500 Received: from mail.andi.de1.cc ([85.214.239.24]:55766 "EHLO h2641619.stratoserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732006AbfAPWEl (ORCPT ); Wed, 16 Jan 2019 17:04:41 -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=0HrSc9TjfAApcBtB66m46jVWZ+gQ86n9XEvM/jcR5Bk=; b=bTuW51YHeG3ZfthC3Xnt+y6B4 +tYZrqsMd3hhPpoNkTVJoY5YyyRedscK07fii2Bc4/BZaJvqVan4/egVWU4jJmyvBWyyYavyVEU4y 5gKG0jAUgimTJLNcms2VlI/db6GOypMoZ30aDQjkznsIKpWYziBr1d0sRV7Rw3nN6e/JY=; Received: from p200300ccfbcc8e001a3da2fffebfd33a.dip0.t-ipconnect.de ([2003:cc:fbcc:8e00: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 1gjtIW-0006la-Vm; Wed, 16 Jan 2019 23:04:33 +0100 Received: from andi by aktux with local (Exim 4.89) (envelope-from ) id 1gjtIW-0002PR-DT; Wed, 16 Jan 2019 23:04:32 +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 v3 1/3] clk: ti: add a usecount for autoidle Date: Wed, 16 Jan 2019 23:04:27 +0100 Message-Id: <20190116220429.9136-2-andreas@kemnade.info> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190116220429.9136-1-andreas@kemnade.info> References: <20190116220429.9136-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 --- Change since v2: - rebase on top of clk: ti: get rid of CLK_IS_BASIC Changes since v1: - use spinlocks instead of mutexes - invert logic drivers/clk/ti/autoidle.c | 32 ++++++++++++++++++++++++++++---- include/linux/clk/ti.h | 1 + 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/clk/ti/autoidle.c b/drivers/clk/ti/autoidle.c index a129b4b36ea3..964e97b5478a 100644 --- a/drivers/clk/ti/autoidle.c +++ b/drivers/clk/ti/autoidle.c @@ -36,17 +36,41 @@ struct clk_ti_autoidle { static LIST_HEAD(autoidle_clks); +/* + * 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); + static int _omap2_clk_deny_idle(struct clk_hw_omap *clk) { - if (clk->ops && clk->ops->deny_idle) - clk->ops->deny_idle(clk); + if (clk->ops && clk->ops->deny_idle) { + unsigned long irqflags; + + spin_lock_irqsave(&autoidle_spinlock, irqflags); + clk->autoidle_count++; + if (clk->autoidle_count == 1) + clk->ops->deny_idle(clk); + + spin_unlock_irqrestore(&autoidle_spinlock, irqflags); + } return 0; } static int _omap2_clk_allow_idle(struct clk_hw_omap *clk) { - if (clk->ops && clk->ops->allow_idle) - clk->ops->allow_idle(clk); + if (clk->ops && clk->ops->allow_idle) { + unsigned long irqflags; + + spin_lock_irqsave(&autoidle_spinlock, irqflags); + clk->autoidle_count--; + if (clk->autoidle_count == 0) + clk->ops->allow_idle(clk); + + spin_unlock_irqrestore(&autoidle_spinlock, irqflags); + } return 0; } 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