Skip to contentSkip to conversation

GPIO Module is reset during initialization

PATCH In review [email protected] 4 participants 9 messages Oct 23, 2009 – Oct 26, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 GPIO Module is reset during initialization

From: Charulatha V <[email protected]>

During initialization, GPIO module is reset using soft reset bit of SYSCONFIG register

---
 arch/arm/plat-omap/gpio.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
arch/arm/plat-omap/gpio.c +11 -1
index 2304a5d..4579650 100644
@@ -21,6 +21,7 @@
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <linux/io.h>
+#include <linux/delay.h>
 
 #include <mach/hardware.h>
 #include <asm/irq.h>
@@ -1670,7 +1671,7 @@ static int __init _omap_gpio_init(void)
 	}
 #endif
 	for (i = 0; i < gpio_bank_count; i++) {
-		int j, gpio_count = 16;
+		int j, gpio_count = 16, attempt = 0;
 
 		bank = &gpio_bank[i];
 		spin_lock_init(&bank->lock);
@@ -1698,6 +1699,15 @@ static int __init _omap_gpio_init(void)
 			static const u32 non_wakeup_gpios[] = {
 				0xe203ffc0, 0x08700040
 			};
+
+		/* Software Reset of GPIO module */
+		__raw_writel(0x0002, bank->base	+ OMAP24XX_GPIO_SYSCONFIG);
+		while (((__raw_readl(bank->base + OMAP24XX_GPIO_SYSSTATUS)
+					& 0x1) == 0) && attempt < 5) {
+			udelay(1);
+			attempt++;
+		}
+
 		if (cpu_is_omap44xx()) {
 			__raw_writel(0xffffffff, bank->base +
 						OMAP4_GPIO_IRQSTATUSCLR0);
Signature · 1 line
1.6.0.4
#1 lore raw
Quoted 23 lines · On Fri, Oct 23, 2009 at 09:25:29PM +0530, [email protected] wrote:

From: Charulatha V <[email protected]>

During initialization, GPIO module is reset using soft reset bit of SYSCONFIG register

---
 arch/arm/plat-omap/gpio.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
arch/arm/plat-omap/gpio.c +1 -0
index 2304a5d..4579650 100644
@@ -21,6 +21,7 @@
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <linux/io.h>
+#include <linux/delay.h>
 
 #include <mach/hardware.h>
 #include <asm/irq.h>

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1674

Quoted 5 lines
arch/arm/plat-omap/gpio.c +1 -1
@@ -1670,7 +1671,7 @@ static int __init _omap_gpio_init(void)
 	}
 #endif
 	for (i = 0; i < gpio_bank_count; i++) {
-		int j, gpio_count = 16;
+		int j, gpio_count = 16, attempt = 0;

decrementing is better, so:

attempt = 1000

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1706

Quoted 12 lines
arch/arm/plat-omap/gpio.c +5 -0
 		bank = &gpio_bank[i];
 		spin_lock_init(&bank->lock);
@@ -1698,6 +1699,15 @@ static int __init _omap_gpio_init(void)
 			static const u32 non_wakeup_gpios[] = {
 				0xe203ffc0, 0x08700040
 			};
+
+		/* Software Reset of GPIO module */
+		__raw_writel(0x0002, bank->base	+ OMAP24XX_GPIO_SYSCONFIG);
+		while (((__raw_readl(bank->base + OMAP24XX_GPIO_SYSSTATUS)
+					& 0x1) == 0) && attempt < 5) {

&& attemp)

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1707

Quoted 1 line
arch/arm/plat-omap/gpio.c +1 -0
+			udelay(1);

i guess cpu_relax() is better here.

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1708

Quoted 1 line
arch/arm/plat-omap/gpio.c +1 -0
+			attempt++;

attempt--;

Signature · 1 line
balbi
#2 lore raw

Felipe Balbi had written, on 10/23/2009 05:56 PM, the following:

Quoted 32 lines · On Fri, Oct 23, 2009 at 09:25:29PM +0530, [email protected] wrote:
Quoted 23 lines

From: Charulatha V <[email protected]>

During initialization, GPIO module is reset using soft reset bit of SYSCONFIG register

---
 arch/arm/plat-omap/gpio.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
arch/arm/plat-omap/gpio.c +1 -0
index 2304a5d..4579650 100644
@@ -21,6 +21,7 @@
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <linux/io.h>
+#include <linux/delay.h>
 
 #include <mach/hardware.h>
 #include <asm/irq.h>

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1674

Quoted 5 lines
arch/arm/plat-omap/gpio.c +1 -1
@@ -1670,7 +1671,7 @@ static int __init _omap_gpio_init(void)
 	}
 #endif
 	for (i = 0; i < gpio_bank_count; i++) {
-		int j, gpio_count = 16;
+		int j, gpio_count = 16, attempt = 0;

decrementing is better, so:

Quoted 1 line

attempt = 1000

please move attempt out of here to the {} for 3430.. Warning for OMAP1.

Quoted 16 lines

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1706

Quoted 13 lines
arch/arm/plat-omap/gpio.c +5 -0
 		bank = &gpio_bank[i];
 		spin_lock_init(&bank->lock);
@@ -1698,6 +1699,15 @@ static int __init _omap_gpio_init(void)
 			static const u32 non_wakeup_gpios[] = {
 				0xe203ffc0, 0x08700040
 			};
+
+		/* Software Reset of GPIO module */
+		__raw_writel(0x0002, bank->base	+ OMAP24XX_GPIO_SYSCONFIG);
+		while (((__raw_readl(bank->base + OMAP24XX_GPIO_SYSSTATUS)
+					& 0x1) == 0) && attempt < 5) {

&& attemp)

Quoted 8 lines

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1707

Quoted 1 line
arch/arm/plat-omap/gpio.c +1 -0
+			udelay(1);

i guess cpu_relax() is better here.

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1708

Quoted 1 line
arch/arm/plat-omap/gpio.c +1 -0
+			attempt++;

attempt--;

cant we improve this code as following:

{
	u8 attempts = 25;
	/* Software Reset of GPIO module */
	__raw_writel(0x0002, bank->base
				+ OMAP24XX_GPIO_SYSCONFIG);
	/* wait for reset to be done */	
	while (((__raw_readl(bank->base	+
			OMAP24XX_GPIO_SYSSTATUS) & 0x1)	== 0)
			&& attempts) {
		cpu_relax();
		if (attempts % 5)
			udelay(1);
		attempts--;
	}

allows the kernel to do somethin else while we also ensure we have a 5 usec guarenteed delay before giving up..

Signature · 2 lines
Regards,
Nishanth Menon
#3 lore raw
Quoted 32 lines

Felipe Balbi had written, on 10/23/2009 05:56 PM, the following:

Quoted 31 lines · On Fri, Oct 23, 2009 at 09:25:29PM +0530, [email protected] wrote:
Quoted 23 lines

From: Charulatha V <[email protected]>

During initialization, GPIO module is reset using soft reset bit of SYSCONFIG register

---
 arch/arm/plat-omap/gpio.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
arch/arm/plat-omap/gpio.c +1 -0
index 2304a5d..4579650 100644
@@ -21,6 +21,7 @@
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <linux/io.h>
+#include <linux/delay.h>
 
 #include <mach/hardware.h>
 #include <asm/irq.h>

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1674

Quoted 5 lines
arch/arm/plat-omap/gpio.c +1 -1
@@ -1670,7 +1671,7 @@ static int __init _omap_gpio_init(void)
     }
 #endif
     for (i = 0; i < gpio_bank_count; i++) {
-            int j, gpio_count = 16;
+            int j, gpio_count = 16, attempt = 0;

decrementing is better, so:

Okay

Quoted 3 lines
Quoted 2 lines

attempt = 1000

please move attempt out of here to the {} for 3430.. Warning for OMAP1.

Okay

Quoted 16 lines
Quoted 16 lines

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1706

Quoted 13 lines
arch/arm/plat-omap/gpio.c +5 -0
             bank = &gpio_bank[i];
             spin_lock_init(&bank->lock);
@@ -1698,6 +1699,15 @@ static int __init _omap_gpio_init(void)
                     static const u32 non_wakeup_gpios[] = {
                             0xe203ffc0, 0x08700040
                     };
+
+            /* Software Reset of GPIO module */
+            __raw_writel(0x0002, bank->base + OMAP24XX_GPIO_SYSCONFIG);
+            while (((__raw_readl(bank->base + OMAP24XX_GPIO_SYSSTATUS)
+                                    & 0x1) == 0) && attempt < 5) {

&& attemp)

Quoted 3 lines
Quoted 3 lines

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1707

Quoted 1 line
arch/arm/plat-omap/gpio.c +1 -0
+                    udelay(1);

i guess cpu_relax() is better here.

I guess cpu_relax is not required because this part of code is called only from board file during boot-up. Hence this would be the only code to be executed.

Quoted 21 lines
Quoted 6 lines

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1711

Quoted 5 lines
arch/arm/plat-omap/gpio.c +1 -0
+                    attempt++;
 
 attempt--;
 

cant we improve this code as following:

{
       u8 attempts = 25;
       /* Software Reset of GPIO module */
       __raw_writel(0x0002, bank->base
                               + OMAP24XX_GPIO_SYSCONFIG);
       /* wait for reset to be done */
       while (((__raw_readl(bank->base +
                       OMAP24XX_GPIO_SYSSTATUS) & 0x1) == 0)
                       && attempts) {
               cpu_relax();
               if (attempts % 5)
                       udelay(1);
               attempts--;
       }
Quoted 2 lines

allows the kernel to do somethin else while we also ensure we have a 5 usec guarenteed delay before giving up..

Doesn't modulo operation cost more in terms of performance? Any specific reason for specific 5 microseconds?

#4 lore raw
Quoted 87 lines

From: Varadarajan, Charu Latha
Sent: Monday, October 26, 2009 4:26 AM
To: Menon, Nishanth; [email protected]

Quoted 32 lines

Felipe Balbi had written, on 10/23/2009 05:56 PM, the following:

Quoted 31 lines · On Fri, Oct 23, 2009 at 09:25:29PM +0530, [email protected] wrote:
Quoted 23 lines

From: Charulatha V <[email protected]>

During initialization, GPIO module is reset using soft reset bit of SYSCONFIG register

---
 arch/arm/plat-omap/gpio.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
arch/arm/plat-omap/gpio.c +1 -0
index 2304a5d..4579650 100644
@@ -21,6 +21,7 @@
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <linux/io.h>
+#include <linux/delay.h>
 
 #include <mach/hardware.h>
 #include <asm/irq.h>

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1674

Quoted 5 lines
arch/arm/plat-omap/gpio.c +1 -1
@@ -1670,7 +1671,7 @@ static int __init _omap_gpio_init(void)
     }
 #endif
     for (i = 0; i < gpio_bank_count; i++) {
-            int j, gpio_count = 16;
+            int j, gpio_count = 16, attempt = 0;

decrementing is better, so:

Okay

Quoted 3 lines
Quoted 2 lines

attempt = 1000

please move attempt out of here to the {} for 3430.. Warning for OMAP1.

Okay

Quoted 11 lines
Quoted 11 lines

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1704

Quoted 11 lines
arch/arm/plat-omap/gpio.c +3 -0
             bank = &gpio_bank[i];
             spin_lock_init(&bank->lock);
@@ -1698,6 +1699,15 @@ static int __init _omap_gpio_init(void)
                     static const u32 non_wakeup_gpios[] = {
                             0xe203ffc0, 0x08700040
                     };
+
+            /* Software Reset of GPIO module */
+            __raw_writel(0x0002, bank->base +

OMAP24XX_GPIO_SYSCONFIG);

Quoted 1 line
Quoted 1 line

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1705

Quoted 1 line
arch/arm/plat-omap/gpio.c +1 -0
+            while (((__raw_readl(bank->base +

OMAP24XX_GPIO_SYSSTATUS)

Quoted 7 lines
Quoted 7 lines

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1706

Quoted 1 line
arch/arm/plat-omap/gpio.c +1 -0
+                                    & 0x1) == 0) && attempt < 5) {

&& attemp)

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1707

Quoted 1 line
arch/arm/plat-omap/gpio.c +1 -0
+                    udelay(1);

i guess cpu_relax() is better here.

I guess cpu_relax is not required because this part of code is called only from
board file during boot-up. Hence this would be the only code to be executed.

Quoted 21 lines
Quoted 6 lines

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1711

Quoted 5 lines
arch/arm/plat-omap/gpio.c +1 -0
+                    attempt++;
 
 attempt--;
 

cant we improve this code as following:

{
       u8 attempts = 25;
       /* Software Reset of GPIO module */
       __raw_writel(0x0002, bank->base
                               + OMAP24XX_GPIO_SYSCONFIG);
       /* wait for reset to be done */
       while (((__raw_readl(bank->base +
                       OMAP24XX_GPIO_SYSSTATUS) & 0x1) == 0)
                       && attempts) {
               cpu_relax();
               if (attempts % 5)
                       udelay(1);
               attempts--;
       }
Quoted 4 lines
Quoted 2 lines

allows the kernel to do somethin else while we also ensure we have a 5 usec guarenteed delay before giving up..

Doesn't modulo operation cost more in terms of performance? Any specific reason for specific 5 microseconds?

You could replace it with >> operator if you like and use 2^x multiples.. I am just sticking 5 us there based on your original code.. so the same logic over here I suppose.. unless I missed something?

Regards,
Nishanth Menon

#5 lore raw

-----snippet----

Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines

&& attemp)

Quoted 1 line

+ udelay(1);

i guess cpu_relax() is better here.

I guess cpu_relax is not required because this part of code is called only from
board file during boot-up. Hence this would be the only code to be executed.

What is your opinion on this?

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 6 lines
Quoted 5 lines

+ attempt++;

attempt--;

cant we improve this code as following:

{
       u8 attempts = 25;
       /* Software Reset of GPIO module */
       __raw_writel(0x0002, bank->base
                               + OMAP24XX_GPIO_SYSCONFIG);
       /* wait for reset to be done */
       while (((__raw_readl(bank->base +
                       OMAP24XX_GPIO_SYSSTATUS) & 0x1) == 0)
                       && attempts) {
               cpu_relax();
               if (attempts % 5)
                       udelay(1);
               attempts--;
       }
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

allows the kernel to do somethin else while we also ensure we have a 5 usec guarenteed delay before giving up..

Doesn't modulo operation cost more in terms of performance? Any specific reason for specific 5 microseconds?

You could replace it with >> operator if you like and use 2^x multiples.. I am just sticking 5 us there based on your original code.. so the same logic over here I suppose.. unless I missed something?

I was using attempts as 5, as my intension was to attempt only 5 times and not in terms of usec as I could not find any details in any document for maximum time for the bit to get set/reset. According to your code, it would attempt to read the register 25 times with a delay of 5 microseconds min during worst case scenario.

#6 lore raw
Quoted 13 lines

-----Original Message-----
From: Varadarajan, Charu Latha
Sent: Monday, October 26, 2009 5:52 AM
To: Menon, Nishanth; [email protected]
Cc: [email protected]
Subject: RE: [PATCH] [OMAP] GPIO Module is reset during initialization

-----snippet----

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

&& attemp)

Quoted 1 line

+ udelay(1);

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line

i guess cpu_relax() is better here.

I guess cpu_relax is not required because this part of code is called

only

Quoted 3 lines
Quoted 3 lines

from
board file during boot-up. Hence this would be the only code to be executed.

What is your opinion on this?

Cpu_relax is still the better way of doing it.

Quoted 29 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 6 lines
Quoted 5 lines

+ attempt++;

attempt--;

cant we improve this code as following:

{
       u8 attempts = 25;
       /* Software Reset of GPIO module */
       __raw_writel(0x0002, bank->base
                               + OMAP24XX_GPIO_SYSCONFIG);
       /* wait for reset to be done */
       while (((__raw_readl(bank->base +
                       OMAP24XX_GPIO_SYSSTATUS) & 0x1) == 0)
                       && attempts) {
               cpu_relax();
               if (attempts % 5)
                       udelay(1);
               attempts--;
       }
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

allows the kernel to do somethin else while we also ensure we have a 5 usec guarenteed delay before giving up..

Doesn't modulo operation cost more in terms of performance? Any

specific

Quoted 4 lines
Quoted 1 line

reason for specific 5 microseconds?

You could replace it with >> operator if you like and use 2^x multiples.. I am just sticking 5 us there based on your original code.. so the same logic over here I suppose.. unless I missed something?

Quoted 8 lines

I was using attempts as 5, as my intension was to attempt only 5 times and not
in terms of usec as I could not find any details in any document for maximum
time for the bit to get set/reset. According to your code, it would attempt to read
the register 25 times with a delay of 5 microseconds min during worst case scenario.

Please find the h/w timeout value and resubmit the patch..

Regards,
Nishanth Menon

#7 lore raw

----------------snippet---------------------

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line

i guess cpu_relax() is better here.

I guess cpu_relax is not required because this part of code is called

only

Quoted 3 lines
Quoted 3 lines

from
board file during boot-up. Hence this would be the only code to be executed.

What is your opinion on this?

Cpu_relax is still the better way of doing it.

Please clarify why.

Quoted 16 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

allows the kernel to do somethin else while we also ensure we have a 5 usec guarenteed delay before giving up..

Doesn't modulo operation cost more in terms of performance? Any

specific

Quoted 4 lines
Quoted 1 line

reason for specific 5 microseconds?

You could replace it with >> operator if you like and use 2^x multiples.. I am just sticking 5 us there based on your original code.. so the same logic over here I suppose.. unless I missed something?

Quoted 8 lines

I was using attempts as 5, as my intension was to attempt only 5 times and not
in terms of usec as I could not find any details in any document for maximum
time for the bit to get set/reset. According to your code, it would attempt to read
the register 25 times with a delay of 5 microseconds min during worst case scenario.

Quoted 1 line

Please find the h/w timeout value and resubmit the patch..

As of now, I do not have any information on these details. Please share any details if you can.

#8 lore raw
In reply to [email protected]
Quoted 34 lines · [email protected] writes:

From: Charulatha V <[email protected]>

During initialization, GPIO module is reset using soft reset bit of SYSCONFIG register

---
 arch/arm/plat-omap/gpio.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
arch/arm/plat-omap/gpio.c +2 -1
index 2304a5d..4579650 100644
@@ -21,6 +21,7 @@
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <linux/io.h>
+#include <linux/delay.h>
 
 #include <mach/hardware.h>
 #include <asm/irq.h>
@@ -1670,7 +1671,7 @@ static int __init _omap_gpio_init(void)
 	}
 #endif
 	for (i = 0; i < gpio_bank_count; i++) {
-		int j, gpio_count = 16;
+		int j, gpio_count = 16, attempt = 0;
 
 		bank = &gpio_bank[i];
 		spin_lock_init(&bank->lock);
@@ -1698,6 +1699,15 @@ static int __init _omap_gpio_init(void)
 			static const u32 non_wakeup_gpios[] = {
 				0xe203ffc0, 0x08700040

arch/arm/plat-omap/gpio.c static int __init _omap_gpio_init(void) · line 1710

Quoted 10 lines
arch/arm/plat-omap/gpio.c +9 -0
 			};
+
+		/* Software Reset of GPIO module */
+		__raw_writel(0x0002, bank->base	+ OMAP24XX_GPIO_SYSCONFIG);
+		while (((__raw_readl(bank->base + OMAP24XX_GPIO_SYSSTATUS)
+					& 0x1) == 0) && attempt < 5) {
+			udelay(1);
+			attempt++;
+		}
+

NAK. Would rather see an omap_hwmod added for GPIO, in which case we get the reset for free.

Kevin