Re: [patch/rfc 1/4] GPIO implementation framework

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: eric miao
Date: Tuesday, November 13, 2007 - 6:04 pm

Subject: [PATCH] move per GPIO "is_out" to "struct gpio_desc"

---
 include/asm-generic/gpio.h |    4 +---
 lib/gpiolib.c              |   18 +++++++++++-------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 783adcf..da67038 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -27,6 +27,7 @@ struct gpio_chip;

 struct gpio_desc {
 	struct gpio_chip *chip;
+	unsigned is_out:1;
 };

 /**
@@ -47,8 +48,6 @@ struct gpio_desc {
  *	(base + ngpio - 1).
  * @can_sleep: flag must be set iff get()/set() methods sleep, as they
  *	must while accessing GPIO expander chips over I2C or SPI
- * @is_out: bit array where bit N is true iff GPIO with offset N has been
- *	 called successfully to configure this as an output
  *
  * A gpio_chip can help platforms abstract various sources of GPIOs so
  * they can all be accessed through a common programing interface.
@@ -78,7 +77,6 @@ struct gpio_chip {
 	unsigned		can_sleep:1;

 	/* other fields are modified by the gpio library only */
-	DECLARE_BITMAP(is_out, ARCH_GPIOS_PER_CHIP);
 	DECLARE_BITMAP(requested, ARCH_GPIOS_PER_CHIP);

 #ifdef CONFIG_DEBUG_FS
diff --git a/lib/gpiolib.c b/lib/gpiolib.c
index 57e0d10..a089597 100644
--- a/lib/gpiolib.c
+++ b/lib/gpiolib.c
@@ -217,11 +217,14 @@ int gpio_direction_input(unsigned gpio)
 {
 	unsigned long		flags;
 	struct gpio_chip	*chip;
+	struct gpio_desc	*desc;
 	int			status = -EINVAL;

 	spin_lock_irqsave(&gpio_lock, flags);

-	chip = gpio_to_chip(gpio);
+	desc = &gpio_desc[gpio];
+	chip = desc->chip;
+
 	if (!chip || !chip->get || !chip->direction_input)
 		goto fail;

@@ -238,8 +241,7 @@ int gpio_direction_input(unsigned gpio)
 	might_sleep_if(extra_checks && chip->can_sleep);

 	status = chip->direction_input(chip, gpio);
-	if (status == 0)
-		clear_bit(gpio, chip->is_out);
+	desc->is_out = 0;
 	return status;
 fail:
 	spin_unlock_irqrestore(&gpio_lock, flags);
@@ -251,11 +253,14 @@ int gpio_direction_output(unsigned gpio, int value)
 {
 	unsigned long		flags;
 	struct gpio_chip	*chip;
+	struct gpio_desc	*desc;
 	int			status = -EINVAL;

 	spin_lock_irqsave(&gpio_lock, flags);

-	chip = gpio_to_chip(gpio);
+	desc = &gpio_desc[gpio];
+	chip = desc->chip;
+
 	if (!chip || !chip->get || !chip->direction_output)
 		goto fail;
 	
@@ -272,8 +277,7 @@ int gpio_direction_output(unsigned gpio, int value)
 	might_sleep_if(extra_checks && chip->can_sleep);

 	status = chip->direction_output(chip, gpio, value);
-	if (status == 0)
-		set_bit(gpio, chip->is_out);
+	desc->is_out = 1;
 	return status;
 fail:
 	spin_unlock_irqrestore(&gpio_lock, flags);
@@ -402,7 +406,7 @@ static void gpiolib_dbg_show(struct seq_file *s,
struct gpio_chip *chip)
 			continue;

 		gpio = chip->base + i;
-		is_out = test_bit(i, chip->is_out);
+		is_out = gpio_desc[gpio].is_out;

 		seq_printf(s, " gpio-%-3d (%-12s) %s %s",
 			gpio, chip->requested_str[i],
-- 
1.5.2.5.GIT
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch/rfc 1/4] GPIO implementation framework, David Brownell, (Mon Oct 29, 6:51 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Mon Nov 5, 2:05 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Mon Nov 12, 7:28 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Tue Nov 13, 12:06 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Tue Nov 13, 5:57 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Tue Nov 13, 6:00 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Tue Nov 13, 6:02 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Tue Nov 13, 6:03 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Tue Nov 13, 6:04 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Tue Nov 13, 6:04 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Tue Nov 13, 8:25 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Tue Nov 13, 8:28 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Tue Nov 13, 8:30 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Tue Nov 13, 8:53 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Tue Nov 13, 9:18 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Tue Nov 13, 9:36 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Tue Nov 13, 11:37 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Tue Nov 13, 11:40 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Tue Nov 13, 11:46 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Tue Nov 13, 11:51 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Wed Nov 14, 12:08 am)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Wed Nov 14, 12:19 am)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Wed Nov 14, 12:36 am)
Re: [patch/rfc 1/4] GPIO implementation framework, Jean Delvare, (Sat Nov 17, 3:38 am)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Sat Nov 17, 10:36 am)
Re: [patch/rfc 1/4] GPIO implementation framework, Jean Delvare, (Tue Nov 20, 8:20 am)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Mon Nov 26, 6:46 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Tue Nov 27, 3:58 am)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Tue Nov 27, 10:26 am)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Tue Nov 27, 12:03 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, David Brownell, (Tue Nov 27, 12:29 pm)
[patch/rfc 2.6.24-rc3-mm] gpiolib grows a gpio_desc, David Brownell, (Tue Nov 27, 8:15 pm)
Re: [patch/rfc 1/4] GPIO implementation framework, eric miao, (Tue Nov 27, 10:11 pm)
Re: [patch/rfc 2.6.24-rc3-mm] gpiolib grows a gpio_desc, David Brownell, (Wed Nov 28, 2:53 am)