linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: s.hauer@pengutronix.de (Sascha Hauer)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 23/33] ARM i.MX: Add common clock support for 2bit gate
Date: Wed, 25 Apr 2012 17:28:13 +0200	[thread overview]
Message-ID: <1335367703-19929-24-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1335367703-19929-1-git-send-email-s.hauer@pengutronix.de>

This gate consists of two bits:

0b00: clk disabled
0b01: clk enabled in run mode and disabled in sleep mode
0b11: clk enabled

Currently only disabled and enabled are supported. As it's unlikely
that we find something like this in another SoC create a i.MX specific
clk helper for this.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/Makefile    |    2 +-
 arch/arm/mach-imx/clk-gate2.c |  115 +++++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-imx/clk.h       |   12 +++++
 3 files changed, 128 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-imx/clk-gate2.c

diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index 66bc6be..1b3f2ae 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -11,7 +11,7 @@ obj-$(CONFIG_SOC_IMX35) += mm-imx3.o cpu-imx35.o clock-imx35.o ehci-imx35.o pm-i
 
 obj-$(CONFIG_SOC_IMX5) += cpu-imx5.o mm-imx5.o clock-mx51-mx53.o ehci-imx5.o pm-imx5.o cpu_op-mx51.o
 
-obj-$(CONFIG_COMMON_CLK) += clk-pllv1.o clk-pllv2.o clk-pllv3.o
+obj-$(CONFIG_COMMON_CLK) += clk-pllv1.o clk-pllv2.o clk-pllv3.o clk-gate2.o
 
 # Support for CMOS sensor interface
 obj-$(CONFIG_MX1_VIDEO) += mx1-camera-fiq.o mx1-camera-fiq-ksym.o
diff --git a/arch/arm/mach-imx/clk-gate2.c b/arch/arm/mach-imx/clk-gate2.c
new file mode 100644
index 0000000..3e4713c8
--- /dev/null
+++ b/arch/arm/mach-imx/clk-gate2.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
+ * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Gated clock implementation
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/io.h>
+#include <linux/err.h>
+#include <linux/string.h>
+
+/**
+ * DOC: basic gatable clock which can gate and ungate it's ouput
+ *
+ * Traits of this clock:
+ * prepare - clk_(un)prepare only ensures parent is (un)prepared
+ * enable - clk_enable and clk_disable are functional & control gating
+ * rate - inherits rate from parent.  No clk_set_rate support
+ * parent - fixed parent.  No clk_set_parent support
+ */
+
+#define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
+
+static int clk_gate2_enable(struct clk_hw *hw)
+{
+	struct clk_gate *gate = to_clk_gate(hw);
+	u32 reg;
+	unsigned long flags = 0;
+
+	if (gate->lock)
+		spin_lock_irqsave(gate->lock, flags);
+
+	reg = readl(gate->reg);
+	reg |= 3 << gate->bit_idx;
+	writel(reg, gate->reg);
+
+	if (gate->lock)
+		spin_unlock_irqrestore(gate->lock, flags);
+
+	return 0;
+}
+
+static void clk_gate2_disable(struct clk_hw *hw)
+{
+	struct clk_gate *gate = to_clk_gate(hw);
+	u32 reg;
+	unsigned long flags = 0;
+
+	if (gate->lock)
+		spin_lock_irqsave(gate->lock, flags);
+
+	reg = readl(gate->reg);
+	reg &= ~(3 << gate->bit_idx);
+	writel(reg, gate->reg);
+
+	if (gate->lock)
+		spin_unlock_irqrestore(gate->lock, flags);
+}
+
+static int clk_gate2_is_enabled(struct clk_hw *hw)
+{
+	u32 reg;
+	struct clk_gate *gate = to_clk_gate(hw);
+
+	reg = readl(gate->reg);
+
+	if (((reg >> gate->bit_idx) & 3) == 3)
+		return 1;
+
+	return 0;
+}
+
+static struct clk_ops clk_gate2_ops = {
+	.enable = clk_gate2_enable,
+	.disable = clk_gate2_disable,
+	.is_enabled = clk_gate2_is_enabled,
+};
+
+struct clk *clk_register_gate2(struct device *dev, const char *name,
+		const char *parent_name, unsigned long flags,
+		void __iomem *reg, u8 bit_idx,
+		u8 clk_gate2_flags, spinlock_t *lock)
+{
+	struct clk_gate *gate;
+	struct clk *clk;
+
+	gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
+	if (!gate) {
+		pr_err("%s: could not allocate gated clk\n", __func__);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	/* struct clk_gate assignments */
+	gate->reg = reg;
+	gate->bit_idx = bit_idx;
+	gate->flags = clk_gate2_flags;
+	gate->lock = lock;
+
+	clk = clk_register(dev, name,
+			&clk_gate2_ops, &gate->hw,
+			(parent_name ? &parent_name : NULL),
+			(parent_name ? 1 : 0),
+			flags);
+	if (IS_ERR(clk))
+		kfree(clk);
+
+	return clk;
+}
diff --git a/arch/arm/mach-imx/clk.h b/arch/arm/mach-imx/clk.h
index 331316d..5f6e435 100644
--- a/arch/arm/mach-imx/clk.h
+++ b/arch/arm/mach-imx/clk.h
@@ -24,6 +24,18 @@ struct clk *imx_clk_pllv3(enum imx_pllv3_type type, const char *name,
 		const char *parent_name, void __iomem *base, u32 gate_mask,
 		u32 div_mask);
 
+struct clk *clk_register_gate2(struct device *dev, const char *name,
+		const char *parent_name, unsigned long flags,
+		void __iomem *reg, u8 bit_idx,
+		u8 clk_gate_flags, spinlock_t *lock);
+
+static inline struct clk *imx_clk_gate2(const char *name, const char *parent,
+		void __iomem *reg, u8 shift)
+{
+	return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg,
+			shift, 0, &imx_ccm_lock);
+}
+
 static inline struct clk *imx_clk_fixed(const char *name, int rate)
 {
 	return clk_register_fixed_rate(NULL, name, NULL, CLK_IS_ROOT, rate);
-- 
1.7.10

  parent reply	other threads:[~2012-04-25 15:28 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-25 15:27 [PATCH v2] Convert i.MX architecture to generic clock framework Sascha Hauer
2012-04-25 15:27 ` [PATCH 01/33] dmaengine i.MX SDMA: do not depend on grouped clocks Sascha Hauer
2012-04-25 15:27 ` [PATCH 02/33] spi i.MX: " Sascha Hauer
2012-04-25 15:27 ` [PATCH 03/33] video imxfb: " Sascha Hauer
2012-04-25 15:27 ` [PATCH 04/33] net fec: " Sascha Hauer
2012-04-25 15:27 ` [PATCH 05/33] mmc mxcmmc: " Sascha Hauer
2012-04-25 15:27 ` [PATCH 06/33] mmc sdhc i.MX: " Sascha Hauer
2012-04-25 15:27 ` [PATCH 07/33] serial " Sascha Hauer
2012-04-25 15:27 ` [PATCH 08/33] mtd mxc_nand: prepare/unprepare clock Sascha Hauer
2012-04-25 15:27 ` [PATCH 09/33] USB ehci mxc: " Sascha Hauer
2012-04-25 15:28 ` [PATCH 10/33] USB ehci mxc: sanitize clock handling Sascha Hauer
2012-04-25 15:28 ` [PATCH 11/33] w1 i.MX: prepare/unprepare clock Sascha Hauer
2012-04-25 15:28 ` [PATCH 12/33] watchdog imx2: prepare clk before enabling it Sascha Hauer
2012-04-25 15:28 ` [PATCH 13/33] media mx3 camera: " Sascha Hauer
2012-04-25 15:28 ` [PATCH 14/33] dmaengine i.MX ipu: clk_prepare/unprepare clock Sascha Hauer
2012-04-25 15:28 ` [PATCH 15/33] rtc: imx dryice: Add missing clk_prepare Sascha Hauer
2012-04-25 15:28 ` [PATCH 16/33] ARM i.MX5: prepare gpc_dvfs_clk Sascha Hauer
2012-04-25 15:28 ` [PATCH 17/33] ARM i.MX timer: request correct clock Sascha Hauer
2012-04-25 15:28 ` [PATCH 18/33] ARM i.MX3: Make ccm base address a variable Sascha Hauer
2012-04-25 15:28 ` [PATCH 19/33] ARM i.MX: prepare for common clock framework Sascha Hauer
2012-04-27  6:40   ` Shawn Guo
2012-04-27  7:16     ` Sascha Hauer
2012-04-27  7:55       ` Shawn Guo
2012-04-27  8:09         ` Sascha Hauer
2012-04-25 15:28 ` [PATCH 20/33] ARM i.MX: Add common clock support for pllv1 Sascha Hauer
2012-04-25 15:28 ` [PATCH 21/33] ARM i.MX: Add common clock support for pllv2 Sascha Hauer
2012-04-25 15:28 ` [PATCH 22/33] ARM: imx: add common clock support for pllv3 Sascha Hauer
2012-04-27  6:21   ` Shawn Guo
2012-04-27  6:32     ` Sascha Hauer
2012-04-27  6:45       ` Shawn Guo
2012-04-25 15:28 ` Sascha Hauer [this message]
2012-04-25 15:28 ` [PATCH 24/33] ARM: imx: add common clock support for pfd Sascha Hauer
2012-04-25 15:28 ` [PATCH 25/33] ARM: imx: add common clock support for clk busy Sascha Hauer
2012-04-25 15:28 ` [PATCH 26/33] ARM i.MX25: implement clocks using common clock framework Sascha Hauer
2012-04-25 15:28 ` [PATCH 27/33] ARM i.MX1: " Sascha Hauer
2012-04-25 15:28 ` [PATCH 28/33] ARM i.MX21: " Sascha Hauer
2012-04-25 15:28 ` [PATCH 29/33] ARM i.MX27: " Sascha Hauer
2012-04-25 15:28 ` [PATCH 30/33] ARM i.MX31: " Sascha Hauer
2012-04-25 15:28 ` [PATCH 31/33] ARM i.MX5: " Sascha Hauer
2012-04-26 12:48   ` Heiko Stübner
2012-04-26 13:02     ` Sascha Hauer
2012-04-26 14:21       ` Heiko Stübner
2012-05-03  3:21   ` Shawn Guo
2012-05-03  6:35     ` Sascha Hauer
2012-04-25 15:28 ` [PATCH 32/33] ARM i.MX35: " Sascha Hauer
2012-04-25 15:28 ` [PATCH 33/33] ARM: i.MX6: " Sascha Hauer
2012-04-26  2:48   ` Richard Zhao
2012-04-26  6:41     ` Sascha Hauer
2012-04-26  6:57       ` Richard Zhao
2012-04-26  7:14         ` Sascha Hauer
2012-04-26  8:04           ` Sascha Hauer
2012-04-26  9:27             ` Richard Zhao
2012-04-26  7:58         ` Shawn Guo
2012-04-26  9:30           ` Richard Zhao
2012-04-26  7:42       ` Shawn Guo
2012-04-26  9:37         ` Richard Zhao
2012-04-26 14:06 ` [PATCH v2] Convert i.MX architecture to generic " Dirk Behme
2012-04-26 14:25   ` Sascha Hauer
2012-04-27  2:28   ` Shawn Guo
2012-04-27  6:32     ` Dirk Behme

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1335367703-19929-24-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).