linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: tony@atomide.com (Tony Lindgren)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 02/12] omap: GPIO module enable/disable
Date: Mon, 16 Nov 2009 15:26:58 -0800	[thread overview]
Message-ID: <20091116232658.24892.92547.stgit@localhost> (raw)
In-Reply-To: <20091116232435.24892.81547.stgit@localhost>

From: Charulatha V <charu@ti.com>

This patch disables a GPIO module when all pins of a GPIO
module are inactive (clock gating forced at module level) and
enables the module when any gpio in the module is requested.

The module is enabled only when "mod_usage" indicates that no GPIO
in that  module is currently active and the GPIO being requested
is the 1st one to be active in that module.

Each module would be disabled in omap_gpio_free() API when all
GPIOs in a particular module becomes inactive. The module is
re-enabled in omap_gpio_request() API when a GPIO is requested
from the module that was previously disabled.

Since individual GPIO's bookkeeping is added in this patch
via "mod_usage", the same is used in omap_set_gpio_debounce()
& omap_set_gpio_debounce_time() APIs to ensure that the gpio being
used is actually "requested" prior to being used (Nishant Menon's
<nm at ti.comSuggestion)

GPIO module level details are specific to hardware and hence
introducing this patch in low level layer (plat-omap/gpio.c)

Signed-off-by: Charulatha V <charu@ti.com>
Acked-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 arch/arm/plat-omap/gpio.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/arch/arm/plat-omap/gpio.c b/arch/arm/plat-omap/gpio.c
index b71052c..ce4f0cd 100644
--- a/arch/arm/plat-omap/gpio.c
+++ b/arch/arm/plat-omap/gpio.c
@@ -195,6 +195,7 @@ struct gpio_bank {
 	spinlock_t lock;
 	struct gpio_chip chip;
 	struct clk *dbck;
+	u32 mod_usage;
 };
 
 #define METHOD_MPUIO		0
@@ -628,6 +629,10 @@ void omap_set_gpio_debounce(int gpio, int enable)
 #else
 	reg += OMAP24XX_GPIO_DEBOUNCE_EN;
 #endif
+	if (!(bank->mod_usage & l)) {
+		printk(KERN_ERR "GPIO %d not requested\n", gpio);
+		return;
+	}
 
 	spin_lock_irqsave(&bank->lock, flags);
 	val = __raw_readl(reg);
@@ -663,6 +668,11 @@ void omap_set_gpio_debounce_time(int gpio, int enc_time)
 	bank = get_gpio_bank(gpio);
 	reg = bank->base;
 
+	if (!bank->mod_usage) {
+		printk(KERN_ERR "GPIO not requested\n");
+		return;
+	}
+
 	enc_time &= 0xff;
 #ifdef CONFIG_ARCH_OMAP4
 	reg += OMAP4_GPIO_DEBOUNCINGTIME;
@@ -1144,6 +1154,16 @@ static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
 		__raw_writel(__raw_readl(reg) | (1 << offset), reg);
 	}
 #endif
+	if (!cpu_class_is_omap1()) {
+		if (!bank->mod_usage) {
+			u32 ctrl;
+			ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
+			ctrl &= 0xFFFFFFFE;
+			/* Module is enabled, clocks are not gated */
+			__raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
+		}
+		bank->mod_usage |= 1 << offset;
+	}
 	spin_unlock_irqrestore(&bank->lock, flags);
 
 	return 0;
@@ -1170,6 +1190,16 @@ static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
 		__raw_writel(1 << offset, reg);
 	}
 #endif
+	if (!cpu_class_is_omap1()) {
+		bank->mod_usage &= ~(1 << offset);
+		if (!bank->mod_usage) {
+			u32 ctrl;
+			ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
+			/* Module is disabled, clocks are gated */
+			ctrl |= 1;
+			__raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
+		}
+	}
 	_reset_gpio(bank, bank->chip.base + offset);
 	spin_unlock_irqrestore(&bank->lock, flags);
 }
@@ -1749,6 +1779,8 @@ static int __init _omap_gpio_init(void)
 			gpio_count = 32;
 		}
 #endif
+
+		bank->mod_usage = 0;
 		/* REVISIT eventually switch from OMAP-specific gpio structs
 		 * over to the generic ones
 		 */

  parent reply	other threads:[~2009-11-16 23:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-16 23:26 [PATCH 00/12] Mostly board updates for 2.6.33 merge window Tony Lindgren
2009-11-16 23:26 ` [PATCH 01/12] omap: Cleanup the coding style in id.c Tony Lindgren
2009-11-16 23:26 ` Tony Lindgren [this message]
2009-11-16 23:27 ` [PATCH 03/12] omap3: defconfigs: remove SYSFS_DEPRECATED flag Tony Lindgren
2009-11-16 23:27 ` [PATCH 04/12] omap3: Update 3430SDP defconfig Tony Lindgren
2009-11-16 23:27 ` [PATCH 05/12] omap3evm: Add board revision function Tony Lindgren
2009-11-17  3:56   ` Hiremath, Vaibhav
2009-11-18 22:47     ` [PATCH 05/12] omap3evm: Add board revision function, v2 Tony Lindgren
2009-11-16 23:27 ` [PATCH 06/12] omap3evm: ehci: Update EHCI support on OMAP3EVM (Rev >= E) Tony Lindgren
2009-11-16 23:27 ` [PATCH 07/12] omap3evm: Initialize vmmc and vmmc_aux regulators Tony Lindgren
2009-11-16 23:28 ` [PATCH 08/12] omap3evm: MIgrate to smsc911x ethernet driver Tony Lindgren
2009-11-16 23:28 ` [PATCH 09/12] omap3: zoom: split board file for software reuse Tony Lindgren
2009-11-16 23:40   ` [PATCH] omap: Fix keymap for zoom2 according to matrix keypad framwork Tony Lindgren
2009-11-16 23:28 ` [PATCH 10/12] omap3: zoom: rename zoom2 name to generic zoom Tony Lindgren
2009-11-16 23:28 ` [PATCH 11/12] omap3: zoom: Drop i2c-1 speed to 2400 Tony Lindgren
2009-11-16 23:37 ` [PATCH 12/12] omap3: zoom: Introduce zoom3 board support Tony Lindgren
2009-11-17  0:02 ` [PATCH 13/12] omap: zoom3: defconfig creation Tony Lindgren
2009-11-17  0:03 ` [PATCH 14/12] omap: zoom2: update defconfig for LL_DEBUG_NONE Tony Lindgren

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=20091116232658.24892.92547.stgit@localhost \
    --to=tony@atomide.com \
    --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).