GPIO Module disable when all pins are inactive
Subsystems (2)
PATCH v2 1/1 GPIO Module disable when all pins are inactive
From: Charulatha V <[email protected]>
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 introduced automatically in this patch(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 <[email protected]> Suggestion)
Higher layer keeps track of GPIOs individually. This patch introduces bookkeeping information, modulewise in lower layer since disabling clock is done at module level. GPIO module level details are specific to hardware and introducing APIs in higher level layer to handle them might not be correct. Hence GPIO module level information (mod_usage) has to be handled only in low-level layer.
--- arch/arm/plat-omap/gpio.c | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-)
arch/arm/plat-omap/gpio.c +35 -0
@@ -199,6 +199,7 @@ struct gpio_bank {struct gpio_chip chip;struct clk *dbck;u32 dbck_enable_mask; +u32 mod_usage; };#define METHOD_MPUIO 0
@@ -691,6 +692,12 @@ void omap_set_gpio_debounce(int gpio, int enable) reg +=OMAP24XX_GPIO_DEBOUNCE_EN ;#endif +if ((cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) + && (!(bank->mod_usage & l))) { +printk (KERN_ERR "GPIO not requested\n" ); +return ; + } +spin_lock_irqsave (&bank->lock, flags); val =__raw_readl (reg);
@@ -726,6 +733,12 @@ void omap_set_gpio_debounce_time(int gpio, int enc_time) bank =get_gpio_bank (gpio); reg = bank->base; +if ((cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) + && (!bank->mod_usage)) { +printk (KERN_ERR "GPIO not requested\n" ); +return ; + } + enc_time &=0xff ;#ifdef CONFIG_ARCH_OMAP4 reg +=OMAP4_GPIO_DEBOUNCINGTIME ;
@@ -1219,6 +1232,16 @@ static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) __raw_writel(__raw_readl(reg) | (1 << offset), reg); }#endif +if (cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) { +u32 ctrl; +if (!bank->mod_usage) { + ctrl =__raw_readl (bank->base +OMAP24XX_GPIO_CTRL ); +/* Module is enabled, clocks are not gated */ + ctrl &=0xFFFFFFFE ; +__raw_writel (ctrl, bank->base +OMAP24XX_GPIO_CTRL ); + } + bank->mod_usage |=1 << offset; + }spin_unlock_irqrestore (&bank->lock, flags);return 0 ;
@@ -1245,6 +1268,16 @@ static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) __raw_writel(1 << offset, reg); }#endif +if (cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) { +u32 ctrl; + bank->mod_usage &= ~(1 << offset); +if (!bank->mod_usage) { + 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); }
@@ -1879,6 +1912,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 */
Signature · 1 line
1.6.0.4
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of [email protected]
Sent: Monday, November 09, 2009 7:56 PM
To: [email protected]
Cc: Varadarajan, Charu Latha
Subject: [PATCH V2] [OMAP] GPIO Module disable when all pins are inactiveFrom: Charulatha V <[email protected]>
Quoted 7 lines
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_usageindicates that no GPIO in that module is currently active and the GPIO being requested is the 1st one to be active in that module.
[sp] This para reads quite confusing. The subject talks of disable
but this para indicates process for 'enable'.
Quoted 9 lines
Each module would be disabled in
omap_gpio_free()API when all GPIOs in a particular module becomes inactive. The module is re-enabled inomap_gpio_request()API when a GPIO is requested from the module that was previously disabled.Since individual GPIO's bookkeeping is introduced automatically in this
patch(mod_usage), the same is used inomap_set_gpio_debounce()
[sp] Is book-keeping 'automatically introduced' or added in this
patch?
Quoted 11 lines
&
omap_set_gpio_debounce_time()APIs to ensure that the gpio being used is actually "requested" prior to being used (Nishant Menon's <[email protected]> Suggestion)Higher layer keeps track of GPIOs individually. This patch introduces bookkeeping information, modulewise in lower layer since disabling clock is done at module level. GPIO module level details are specific to hardware and introducing APIs in higher level layer to handle them might not be correct. Hence GPIO module level information (
mod_usage) has to be handled only in low-level layer.
[sp] Again the description seems to be quite confusing between the
higher layer and lower layer contexts.
Quoted 20 lines
Signed-off-by Charulatha V <[email protected]>Acked-by Nishanth Menon <[email protected]>--- arch/arm/plat-omap/gpio.c | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-)arch/arm/plat-omap/gpio.c +1
-0@@ -199,6 +199,7 @@ struct gpio_bank {struct gpio_chip chip;struct clk *dbck;u32 dbck_enable_mask; +u32 mod_usage; };#define METHOD_MPUIO 0
arch/arm/plat-omap/gpio.c void omap_set_gpio_debounce(int gpio, int enable) · line 697
Quoted 6 lines
arch/arm/plat-omap/gpio.c +2
-0@@ -691,6 +692,12 @@ void omap_set_gpio_debounce(int gpio, int enable) reg +=OMAP24XX_GPIO_DEBOUNCE_EN ;#endif +if ((cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) + && (!(bank->mod_usage & l))) {
[sp] Is the AND operation really needed?
Quoted 23 lines
arch/arm/plat-omap/gpio.c +10
-0+printk (KERN_ERR "GPIO not requested\n" ); +return ; + } +spin_lock_irqsave (&bank->lock, flags); val =__raw_readl (reg);@@ -726,6 +733,12 @@ void omap_set_gpio_debounce_time(int gpio, int enc_time) bank =get_gpio_bank (gpio); reg = bank->base; +if ((cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) + && (!bank->mod_usage)) { +printk (KERN_ERR "GPIO not requested\n" ); +return ; + } + enc_time &=0xff ;#ifdef
CONFIG_ARCH_OMAP4arch/arm/plat-omap/gpio.c +0
-0reg +=OMAP4_GPIO_DEBOUNCINGTIME ;
arch/arm/plat-omap/gpio.c static int omap_gpio_request(struct · line 1238
Quoted 7 lines
arch/arm/plat-omap/gpio.c +2
-0@@ -1219,6 +1232,16 @@ static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) __raw_writel(__raw_readl(reg) | (1 << offset), reg); }#endif +if (cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) { +u32 ctrl;
[sp] This should move into next "if" where it is used.
Quoted 54 lines
arch/arm/plat-omap/gpio.c +5
-0+if (!bank->mod_usage) { + ctrl =__raw_readl (bank->base +OMAP24XX_GPIO_CTRL ); +/* Module is enabled, clocks are not gated */ + ctrl &=0xFFFFFFFE ; + __raw_writel(ctrl, bank->base +
OMAP24XX_GPIO_CTRL);arch/arm/plat-omap/gpio.c +11
-0+ } + bank->mod_usage |=1 << offset; + }spin_unlock_irqrestore (&bank->lock, flags);return 0 ;@@ -1245,6 +1268,16 @@ static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) __raw_writel(1 << offset, reg); }#endif +if (cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) { +u32 ctrl; + bank->mod_usage &= ~(1 << offset); +if (!bank->mod_usage) { + ctrl =__raw_readl (bank->base +OMAP24XX_GPIO_CTRL ); +/* Module is disabled, clocks are gated */ + ctrl |=1 ; + __raw_writel(ctrl, bank->base +
OMAP24XX_GPIO_CTRL);arch/arm/plat-omap/gpio.c +4
-0+ } + }_reset_gpio (bank, bank->chip.base + offset);spin_unlock_irqrestore (&bank->lock, flags); }@@ -1879,6 +1912,8 @@ static int __init _omap_gpio_init(void) gpio_count = 32; }#endif + + bank->mod_usage =0 ;/* REVISIT eventually switch from OMAP-specific gpio structs
arch/arm/plat-omap/gpio.c +0
-0* over to the generic ones */ Signature · 7 lines
1.6.0.4 -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines
Quoted 11 lines
Subject: [PATCH V2] [OMAP] GPIO Module disable when all pins are inactive
From: Charulatha V <[email protected]>
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.
Quoted 6 lines
Quoted 3 lines
The module is enabled only when
mod_usageindicates that no GPIO in that module is currently active and the GPIO being requested is the 1st one to be active in that module.[sp] This para reads quite confusing. The subject talks of disable
but this para indicates process for 'enable'.
Shall change the subject to "GPIO module enable/disable".
Quoted 8 lines
Quoted 8 lines
Each module would be disabled in
omap_gpio_free()API when all GPIOs in a particular module becomes inactive. The module is re-enabled inomap_gpio_request()API when a GPIO is requested from the module that was previously disabled.
Quoted 6 lines
Quoted 2 lines
Since individual GPIO's bookkeeping is introduced automatically in this
patch(mod_usage), the same is used in
omap_set_gpio_debounce()[sp] Is book-keeping 'automatically introduced' or added in this
patch?
The intention of the patch is not to introduce bookkeeping. But the implementation has brought in bookkeeping concept modulewise. I shall change it to "added" instead of "automatically introduced".
Quoted 13 lines
Quoted 5 lines
&
omap_set_gpio_debounce_time()APIs to ensure that the gpio being used is actually "requested" prior to being used (Nishant Menon's <[email protected]> Suggestion)Quoted 7 lines
Higher layer keeps track of GPIOs individually. This patch introduces bookkeeping information, modulewise in lower layer since disabling clock is done at module level. GPIO module level details are specific to hardware and introducing APIs in higher level layer to handle them might not be correct. Hence GPIO module level information (
mod_usage) has to be handled only in low-level layer.
Quoted 2 lines
[sp] Again the description seems to be quite confusing between the
higher layer and lower layer contexts.
I shall remove the above para and keep it as:
GPIO module level details are specific to hardware and hence introducing this patch in low level layer (plat-omap/gpio.c).
Quoted 22 lines
arch/arm/plat-omap/gpio.c void omap_set_gpio_debounce(int gpio,
Quoted 21 lines
Signed-off-by Charulatha V <[email protected]>Acked-by Nishanth Menon <[email protected]>--- arch/arm/plat-omap/gpio.c | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-)arch/arm/plat-omap/gpio.c +1
-0@@ -199,6 +199,7 @@ struct gpio_bank {struct gpio_chip chip;struct clk *dbck;u32 dbck_enable_mask; +u32 mod_usage; };#define METHOD_MPUIO 0@@ -691,6 +692,12 @@ void omap_set_gpio_debounce(int gpio,int enable)
Quoted 7 lines
arch/arm/plat-omap/gpio.c void omap_set_gpio_debounce(int gpio, int enable) · line 696
Quoted 6 lines
arch/arm/plat-omap/gpio.c +2
-0reg +=OMAP24XX_GPIO_DEBOUNCE_EN ;#endif +if ((cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) + && (!(bank->mod_usage & l))) {[sp] Is the AND operation really needed?
Yes, inorder to check if this GPIO was "requested" before calling omap_set_gpio_debounce
Quoted 5 lines
Quoted 5 lines
arch/arm/plat-omap/gpio.c +4
-0+printk (KERN_ERR "GPIO not requested\n" ); +return ; + } +
<Snip>
Quoted 11 lines
arch/arm/plat-omap/gpio.c static int omap_gpio_request(struct · line 1238
Quoted 9 lines
arch/arm/plat-omap/gpio.c +2
-0reg +=OMAP4_GPIO_DEBOUNCINGTIME ;@@ -1219,6 +1232,16 @@ static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) __raw_writel(__raw_readl(reg) | (1 << offset), reg); }#endif +if (cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) { +u32 ctrl;[sp] This should move into next "if" where it is used.
Ok.
Quoted 3 lines
Quoted 3 lines
arch/arm/plat-omap/gpio.c +2
-0+if (!bank->mod_usage) { + ctrl = __raw_readl(bank->base +
<Snip>
Quoted 63 lines · * [email protected] <[email protected]> [091109 06:25]:
From: Charulatha V <[email protected]>
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_usageindicates 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 inomap_gpio_request()API when a GPIO is requested from the module that was previously disabled.Since individual GPIO's bookkeeping is introduced automatically in this
patch(mod_usage), the same is used inomap_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 <[email protected]> Suggestion)Higher layer keeps track of GPIOs individually. This patch introduces bookkeeping information, modulewise in lower layer since disabling clock is done at module level. GPIO module level details are specific to hardware and introducing APIs in higher level layer to handle them might not be correct. Hence GPIO module level information (
mod_usage) has to be handled only in low-level layer.Signed-off-by Charulatha V <[email protected]>Acked-by Nishanth Menon <[email protected]>--- arch/arm/plat-omap/gpio.c | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-)arch/arm/plat-omap/gpio.c +7
-0@@ -199,6 +199,7 @@ struct gpio_bank {struct gpio_chip chip;struct clk *dbck;u32 dbck_enable_mask; +u32 mod_usage; };#define METHOD_MPUIO 0@@ -691,6 +692,12 @@ void omap_set_gpio_debounce(int gpio, int enable) reg +=OMAP24XX_GPIO_DEBOUNCE_EN ;#endif +if ((cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) + && (!(bank->mod_usage & l))) { +printk (KERN_ERR "GPIO not requested\n" ); +return ; + } +spin_lock_irqsave (&bank->lock, flags); val =__raw_readl (reg);@@ -726,6 +733,12 @@ void omap_set_gpio_debounce_time(int gpio, int enc_time) bank =get_gpio_bank (gpio); reg = bank->base;
arch/arm/plat-omap/gpio.c void omap_set_gpio_debounce_time(int gpio, int enc_time) · line 744
Quoted 10 lines
arch/arm/plat-omap/gpio.c +6
-0+if ((cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) + && (!bank->mod_usage)) { +printk (KERN_ERR "GPIO not requested\n" ); +return ; + } + enc_time &=0xff ;#ifdef CONFIG_ARCH_OMAP4 reg +=OMAP4_GPIO_DEBOUNCINGTIME ;
Please just use:
if (!cpu_class_is_omap1()) {
...
}Quoted 7 lines
arch/arm/plat-omap/gpio.c +3
-0@@ -1219,6 +1232,16 @@ static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) __raw_writel(__raw_readl(reg) | (1 << offset), reg); }#endif +if (cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) { +u32 ctrl; +if (!bank->mod_usage) {
arch/arm/plat-omap/gpio.c static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) · line 1247
Quoted 10 lines
arch/arm/plat-omap/gpio.c +7
-0+ ctrl =__raw_readl (bank->base +OMAP24XX_GPIO_CTRL ); +/* Module is enabled, clocks are not gated */ + ctrl &=0xFFFFFFFE ; +__raw_writel (ctrl, bank->base +OMAP24XX_GPIO_CTRL ); + } + bank->mod_usage |=1 << offset; + }spin_unlock_irqrestore (&bank->lock, flags);return 0 ;
Here too.
Quoted 7 lines
arch/arm/plat-omap/gpio.c +3
-0@@ -1245,6 +1268,16 @@ static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) __raw_writel(1 << offset, reg); }#endif +if (cpu_is_omap24xx () ||cpu_is_omap34xx () ||cpu_is_omap44xx ()) { +u32 ctrl; + bank->mod_usage &= ~(1 << offset);
arch/arm/plat-omap/gpio.c static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) · line 1283
Quoted 10 lines
arch/arm/plat-omap/gpio.c +7
-0+if (!bank->mod_usage) { + 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); }
Here too.
Quoted 16 lines
arch/arm/plat-omap/gpio.c +2
-0@@ -1879,6 +1912,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 */ Signature · 6 lines
1.6.0.4 -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html