Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp628325ybz; Wed, 15 Apr 2020 15:27:33 -0700 (PDT) X-Google-Smtp-Source: APiQypItwnYJeVTdrXkbMMet7gF99+JBmAXy+4ufof7VuhuhUT11LQtmPo5RCLuMbVipMF3cj6l9 X-Received: by 2002:a17:906:4cd2:: with SMTP id q18mr7191428ejt.70.1586989653148; Wed, 15 Apr 2020 15:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586989653; cv=none; d=google.com; s=arc-20160816; b=gNxWrSV/lHpJHGIBdqHcnkrWOK12NKkqsZojJ3XPF7wiYBZY9vVmoEyrgnj/qM0No4 Y6BRUyTXXK3P4sWSIxuRb6EYE+TFZeFlIPKOW05emDh3x/iosKj0UPPJC2Mr6vSC3/Oh +a0FAhUhfosKAFAeHTHTrToR2HOgJx8tNe/gsCytHYGF+rTi3NXXQtX96pfgO0OPDXmG Gcrr0ZOOpL29w/enLiL2QARPjOk7FspW9mLP7O0Pb/NeGPmk8i/6K0S51+u5XXgUa2tl DblIa4YN41a7ZwEfutvZA6PwtCCW+V9PTMj/BvgX5pBio5SvzrFa0m5UwMQKt5EQ8UoQ PZ5w== 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; bh=m8uLnToVfXlcyHGRo6G4j0qrkcVKuDkwC0ZUCUaSrCE=; b=XdfNOQNSR3d4SIIWRGMMTJQQkqFIV8ano9oWBRAIKLa+L88+PhozKk7GZpbIIGKYTl ZGsA4BT0+zXrsQSh0eg32ToDMrfbZ/IaJTZcawG9XdQqvwUUCYyQQDrKI16e7AN5SlWe iVlNcouWwvEeErmPH8Bk0dhj9SocqwGneqNQMsOD2b34x6M+NLGLIs4pEv5obk2N/g4J 0R8xzHgyQFbgUZfrrZfaauJTqypE8cg/pjWGEFSwCabeMshOSb9m4kB8wZL4pQ7VVH9m sznkkI66UQO5so5yh9bbCiSPjM+8SWXso+nzSWPLTN3ZyI2QKmHibXja0AgqxwcwT8MO mdkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u21si8230828ejz.518.2020.04.15.15.27.09; Wed, 15 Apr 2020 15:27:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2635492AbgDOIFJ (ORCPT + 99 others); Wed, 15 Apr 2020 04:05:09 -0400 Received: from inva021.nxp.com ([92.121.34.21]:46866 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408047AbgDOID2 (ORCPT ); Wed, 15 Apr 2020 04:03:28 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id B19412007BC; Wed, 15 Apr 2020 10:03:08 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id A2A952007B8; Wed, 15 Apr 2020 10:03:08 +0200 (CEST) Received: from fsr-ub1664-175.ea.freescale.net (fsr-ub1664-175.ea.freescale.net [10.171.82.40]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id 11CFB202B0; Wed, 15 Apr 2020 10:03:08 +0200 (CEST) From: Abel Vesa To: Lee Jones , Shawn Guo , Peng Fan , Philipp Zabel , Stephen Boyd , Sascha Hauer , Anson Huang , Leonard Crestez , Jacky Bai Cc: NXP Linux Team , Linux Kernel Mailing List , devicetree@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Abel Vesa Subject: [PATCH v3 05/13] clk: imx: gate2: Allow single bit gating clock Date: Wed, 15 Apr 2020 11:02:45 +0300 Message-Id: <1586937773-5836-6-git-send-email-abel.vesa@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1586937773-5836-1-git-send-email-abel.vesa@nxp.com> References: <1586937773-5836-1-git-send-email-abel.vesa@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Audiomix on i.MX8MP registers two gates that share the same enable count but use the same bit to control the gate instead of two bits. By adding the flag IMX_CLK_GATE2_SINGLE_BIT we allow the gate2 to use the generic gate ops for enable, disable and is_enabled. For the disable_unused, nothing happens if this flag is specified. Signed-off-by: Abel Vesa --- drivers/clk/imx/clk-gate2.c | 31 +++++++++++++++++++++++-------- drivers/clk/imx/clk.h | 13 +++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/drivers/clk/imx/clk-gate2.c b/drivers/clk/imx/clk-gate2.c index ce0060e..b87ab3c 100644 --- a/drivers/clk/imx/clk-gate2.c +++ b/drivers/clk/imx/clk-gate2.c @@ -41,21 +41,26 @@ static int clk_gate2_enable(struct clk_hw *hw) struct clk_gate2 *gate = to_clk_gate2(hw); u32 reg; unsigned long flags; + int ret = 0; spin_lock_irqsave(gate->lock, flags); if (gate->share_count && (*gate->share_count)++ > 0) goto out; - reg = readl(gate->reg); - reg &= ~(3 << gate->bit_idx); - reg |= gate->cgr_val << gate->bit_idx; - writel(reg, gate->reg); + if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT) { + ret = clk_gate_ops.enable(hw); + } else { + reg = readl(gate->reg); + reg &= ~(3 << gate->bit_idx); + reg |= gate->cgr_val << gate->bit_idx; + writel(reg, gate->reg); + } out: spin_unlock_irqrestore(gate->lock, flags); - return 0; + return ret; } static void clk_gate2_disable(struct clk_hw *hw) @@ -73,9 +78,13 @@ static void clk_gate2_disable(struct clk_hw *hw) goto out; } - reg = readl(gate->reg); - reg &= ~(3 << gate->bit_idx); - writel(reg, gate->reg); + if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT) { + clk_gate_ops.disable(hw); + } else { + reg = readl(gate->reg); + reg &= ~(3 << gate->bit_idx); + writel(reg, gate->reg); + } out: spin_unlock_irqrestore(gate->lock, flags); @@ -95,6 +104,9 @@ static int clk_gate2_is_enabled(struct clk_hw *hw) { struct clk_gate2 *gate = to_clk_gate2(hw); + if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT) + return clk_gate_ops.is_enabled(hw); + return clk_gate2_reg_is_enabled(gate->reg, gate->bit_idx); } @@ -104,6 +116,9 @@ static void clk_gate2_disable_unused(struct clk_hw *hw) unsigned long flags; u32 reg; + if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT) + return; + spin_lock_irqsave(gate->lock, flags); if (!gate->share_count || *gate->share_count == 0) { diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index f074dd8..01ff1db 100644 --- a/drivers/clk/imx/clk.h +++ b/drivers/clk/imx/clk.h @@ -5,6 +5,8 @@ #include #include +#define IMX_CLK_GATE2_SINGLE_BIT 1 + extern spinlock_t imx_ccm_lock; void imx_check_clocks(struct clk *clks[], unsigned int count); @@ -355,6 +357,17 @@ static inline struct clk_hw *imx_clk_hw_gate2_shared2(const char *name, &imx_ccm_lock, share_count); } +static inline struct clk_hw *imx_dev_clk_hw_gate_shared(struct device *dev, + const char *name, const char *parent, + void __iomem *reg, u8 shift, + unsigned int *share_count) +{ + return clk_hw_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT | + CLK_OPS_PARENT_ENABLE, reg, shift, 0x3, + IMX_CLK_GATE2_SINGLE_BIT, + &imx_ccm_lock, share_count); +} + static inline struct clk *imx_clk_gate2_cgr(const char *name, const char *parent, void __iomem *reg, u8 shift, u8 cgr_val) { -- 2.7.4