All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Hilman <khilman@ti.com>
To: "DebBarma, Tarun Kanti" <tarun.kanti@ti.com>
Cc: "linux-omap@vger.kernel.org" <linux-omap@vger.kernel.org>,
	"Shilimkar, Santosh" <santosh.shilimkar@ti.com>,
	"tony@atomide.com" <tony@atomide.com>
Subject: Re: [PATCH v3 12/20] GPIO: OMAP: Use wkup_status for all SoCs
Date: Tue, 12 Jul 2011 08:30:32 -0700	[thread overview]
Message-ID: <87hb6rtt2f.fsf@ti.com> (raw)
In-Reply-To: <5A47E75E594F054BAF48C5E4FC4B92AB037BE78072@dbde02.ent.ti.com> (Tarun Kanti DebBarma's message of "Tue, 12 Jul 2011 05:34:50 +0530")

"DebBarma, Tarun Kanti" <tarun.kanti@ti.com> writes:

> Kevin,
> [...]
>> 
>> >  		set_gpio_trigger(bank, gpio, trigger);
>> >  	} else if (bank->regs->irqctrl) {
>> >  		reg += bank->regs->irqctrl;
>> > @@ -295,13 +296,7 @@ static int _set_gpio_triggering(struct gpio_bank
>> *bank, int gpio, int trigger)
>> >  		if (trigger & IRQ_TYPE_EDGE_FALLING)
>> >  			l |= 1 << (gpio << 1);
>> >
>> > -		if (trigger)
>> > -			/* Enable wake-up during idle for dynamic tick */
>> > -			__raw_writel(1 << gpio, bank->base
>> > -						+ bank->regs->wkup_set);
>> > -		else
>> > -			__raw_writel(1 << gpio, bank->base
>> > -						+ bank->regs->wkup_clear);
>> > +		MOD_REG_BIT(bank->regs->wkup_status, 1 << gpio, trigger != 0);
>> 
>> This isn't right, so I'm not sure how this is working. At this point:
>> 
>>      base = bank->base;
>>      reg = bank->base + bank->regs->edgectrl[12];
> Right so far...
>
>> 
>> but if you look at MOD_REG_BIT(), it does register access using 'base +
>> reg', but here that will be 'bank->base + bank->base + reg offset',
>> which will be doing a read/modify/write to who-knows-where.
> My understanding was MOD_REG_BIT(bank->regs->wkup_status, ...) translate to:
> bank->base + bank->regs->wkup_status, for the following reason:
>
> In the following macro, reg is equivalent to bank->regs->wkup_status.
> But this is not the case with base, which remains as bank->base.
> Please correct me.

You're right.  

This is a good example why using macros like this (with some arguments
passed and some arguments implied) leads to confusion.

> #define MOD_REG_BIT(reg, bit_mask, set) \
> do {    \
>         int l = __raw_readl(base + reg); \
>         if (set) l |= bit_mask; \
>         else l &= ~bit_mask; \
>         __raw_writel(l, base + reg); \
> } while(0)
>
>> 
>> >  		__raw_writel(l, reg);
>> 
>> Oh, now I see why it works: because you have an additional write here,
>> which isn't right either because MOD_REG_BIT() already does the read
>> *and* write.
> This should be writing to following still.
> reg = bank->base + bank->regs->edgectrl[12];

Yes, but it is a duplicate write since the MOD_REG_BIT() already does
the write.

A better solution is to just get rid of this macro and use a static inline.

The patch below does just this, and I'm including it into my
gpio-cleanup series (branch: for_3.1/gpio-cleanup-2.)  Please rebase
your updated series on that branch.

Kevin

>From 0c3da6533061f51236743ebaf4bae23561e315fe Mon Sep 17 00:00:00 2001
From: Kevin Hilman <khilman@ti.com>
Date: Tue, 12 Jul 2011 08:18:15 -0700
Subject: [PATCH] gpio/omap: replace MOD_REG_BIT macro with static inline

This macro is ugly and confusing, especially since it passes in most
arguments, but uses an implied 'base' from the caller.

Replace it with an equivalent static inline.

Signed-off-by: Kevin Hilman <khilman@ti.com>
---
 drivers/gpio/gpio-omap.c |   54 ++++++++++++++++++++++++---------------------
 1 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index 501ca3d..6d616ee 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -148,13 +148,17 @@ static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
 	return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0;
 }
 
-#define MOD_REG_BIT(reg, bit_mask, set)	\
-do {	\
-	int l = __raw_readl(base + reg); \
-	if (set) l |= bit_mask; \
-	else l &= ~bit_mask; \
-	__raw_writel(l, base + reg); \
-} while(0)
+static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
+{
+	int l = __raw_readl(base + reg);
+
+	if (set) 
+		l |= mask;
+	else
+		l &= ~mask;
+
+	__raw_writel(l, base + reg);
+}
 
 /**
  * _set_gpio_debounce - low level gpio debounce time
@@ -210,28 +214,28 @@ static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
 	u32 gpio_bit = 1 << gpio;
 
 	if (cpu_is_omap44xx()) {
-		MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
-			trigger & IRQ_TYPE_LEVEL_LOW);
-		MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
-			trigger & IRQ_TYPE_LEVEL_HIGH);
-		MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
-			trigger & IRQ_TYPE_EDGE_RISING);
-		MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
-			trigger & IRQ_TYPE_EDGE_FALLING);
+		_gpio_rmw(base, OMAP4_GPIO_LEVELDETECT0, gpio_bit,
+			  trigger & IRQ_TYPE_LEVEL_LOW);
+		_gpio_rmw(base, OMAP4_GPIO_LEVELDETECT1, gpio_bit,
+			  trigger & IRQ_TYPE_LEVEL_HIGH);
+		_gpio_rmw(base, OMAP4_GPIO_RISINGDETECT, gpio_bit,
+			  trigger & IRQ_TYPE_EDGE_RISING);
+		_gpio_rmw(base, OMAP4_GPIO_FALLINGDETECT, gpio_bit,
+			  trigger & IRQ_TYPE_EDGE_FALLING);
 	} else {
-		MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
-			trigger & IRQ_TYPE_LEVEL_LOW);
-		MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
-			trigger & IRQ_TYPE_LEVEL_HIGH);
-		MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
-			trigger & IRQ_TYPE_EDGE_RISING);
-		MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
-			trigger & IRQ_TYPE_EDGE_FALLING);
+		_gpio_rmw(base, OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
+			  trigger & IRQ_TYPE_LEVEL_LOW);
+		_gpio_rmw(base, OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
+			  trigger & IRQ_TYPE_LEVEL_HIGH);
+		_gpio_rmw(base, OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
+			  trigger & IRQ_TYPE_EDGE_RISING);
+		_gpio_rmw(base, OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
+			  trigger & IRQ_TYPE_EDGE_FALLING);
 	}
 	if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
 		if (cpu_is_omap44xx()) {
-			MOD_REG_BIT(OMAP4_GPIO_IRQWAKEN0, gpio_bit,
-				trigger != 0);
+			_gpio_rmw(base, OMAP4_GPIO_IRQWAKEN0, gpio_bit,
+				  trigger != 0);
 		} else {
 			/*
 			 * GPIO wakeup request can only be generated on edge
-- 
1.7.6


  reply	other threads:[~2011-07-12 15:30 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-01  9:46 [PATCH v3 00/20] GPIO: OMAP: driver cleanup and fixes Tarun Kanti DebBarma
2011-07-01  9:46 ` [PATCH v3 01/20] GPIO: OMAP: Remove dependency on gpio_bank_count Tarun Kanti DebBarma
2011-07-01  9:46 ` [PATCH v3 02/20] GPIO: OMAP2+: Use flag to identify wakeup domain Tarun Kanti DebBarma
2011-07-01  9:46 ` [PATCH v3 03/20] GPIO: OMAP: Make gpio_context part of gpio_bank structure Tarun Kanti DebBarma
2011-07-01  9:46 ` [PATCH v3 04/20] GPIO: OMAP: Fix pwrdm_post_transition call sequence Tarun Kanti DebBarma
2011-07-01  9:46 ` [PATCH v3 05/20] GPIO: OMAP: Handle save/restore ctx in GPIO driver Tarun Kanti DebBarma
2011-07-01  9:47 ` [PATCH v3 06/20] GPIO: OMAP2+: Make non-wakeup GPIO part of pdata Tarun Kanti DebBarma
2011-07-01  9:47 ` [PATCH v3 07/20] GPIO: OMAP: Avoid cpu checks during module ena/disable Tarun Kanti DebBarma
2011-07-01  9:47 ` [PATCH v3 08/20] GPIO: OMAP: Use wkup regs off/suspend support flag Tarun Kanti DebBarma
2011-07-06 19:51   ` Kevin Hilman
2011-07-07  5:06     ` DebBarma, Tarun Kanti
2011-07-01  9:47 ` [PATCH v3 09/20] GPIO: OMAP: Use level/edge detect reg offsets Tarun Kanti DebBarma
2011-07-05 23:51   ` Kevin Hilman
2011-07-06  4:15     ` DebBarma, Tarun Kanti
2011-07-06 19:57   ` Kevin Hilman
2011-07-07  4:47     ` DebBarma, Tarun Kanti
2011-07-01  9:47 ` [PATCH v3 10/20] GPIO: OMAP: Remove hardcoded offsets in ctxt save/restore Tarun Kanti DebBarma
2011-07-01  9:47 ` [PATCH v3 11/20] GPIO: OMAP: Clean set_gpio_triggering function Tarun Kanti DebBarma
2011-07-01  9:47 ` [PATCH v3 12/20] GPIO: OMAP: Use wkup_status for all SoCs Tarun Kanti DebBarma
2011-07-06  0:50   ` Kevin Hilman
2011-07-06  4:30     ` DebBarma, Tarun Kanti
2011-07-06  4:33     ` DebBarma, Tarun Kanti
2011-07-12  0:04     ` DebBarma, Tarun Kanti
2011-07-12 15:30       ` Kevin Hilman [this message]
2011-07-13  3:55         ` DebBarma, Tarun Kanti
2011-07-01  9:47 ` [PATCH v3 13/20] GPIO: OMAP: Clean omap_gpio_mod_init function Tarun Kanti DebBarma
2011-07-06 20:38   ` Kevin Hilman
2011-07-07  4:40     ` DebBarma, Tarun Kanti
2011-07-01  9:47 ` [PATCH v3 14/20] GPIO: OMAP15xx: Use pinctrl offset instead of macro Tarun Kanti DebBarma
2011-07-01  9:47 ` [PATCH v3 15/20] GPIO: OMAP: Use readl in irq_handler for all access Tarun Kanti DebBarma
2011-07-01  9:47 ` [PATCH v3 16/20] GPIO: OMAP: Remove bank->method & METHOD_* macros Tarun Kanti DebBarma
2011-07-01  9:47 ` [PATCH v3 17/20] GPIO: OMAP: Fix bankwidth for OMAP7xx MPUIO Tarun Kanti DebBarma
2011-07-01  9:47 ` [PATCH v3 18/20] GPIO: OMAP: Use PM runtime framework Tarun Kanti DebBarma
2011-07-20  6:28   ` Roger Quadros
2011-07-20  9:28     ` DebBarma, Tarun Kanti
2011-07-20  9:33       ` Roger Quadros
2011-07-20  9:46         ` DebBarma, Tarun Kanti
2011-07-01  9:47 ` [PATCH v3 19/20] GPIO: OMAP: optimize suspend and resume functions Tarun Kanti DebBarma
2011-07-06 20:54   ` Kevin Hilman
2011-07-07  4:42     ` DebBarma, Tarun Kanti
2011-07-01  9:47 ` [PATCH v3 20/20] GPIO: OMAP2+: Clean prepare_for_idle and resume_after_idle Tarun Kanti DebBarma
2011-07-05 23:46 ` [PATCH v3 00/20] GPIO: OMAP: driver cleanup and fixes Kevin Hilman
2011-07-06  4:37   ` DebBarma, Tarun Kanti
2011-07-06 21:07 ` Kevin Hilman
2011-07-07  4:16   ` DebBarma, Tarun Kanti
2011-07-12 15:22     ` Hilman, Kevin
2011-07-13  3:48       ` DebBarma, Tarun Kanti

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=87hb6rtt2f.fsf@ti.com \
    --to=khilman@ti.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=santosh.shilimkar@ti.com \
    --cc=tarun.kanti@ti.com \
    --cc=tony@atomide.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.