Skip to contentSkip to conversation

gpio: unify gpio direction macros names with Linux kernel

PATCH In review Antony Pavlov 4 participants 5 messages Nov 21, 2013 – Nov 22, 2013 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 gpio: unify gpio direction macros names with Linux kernel

See linux.git/include/linux/gpio.h and
linux.git/Documentation/gpio.txt for details.

---
 drivers/gpio/gpio-dw.c | 2 +-
 include/gpio.h         | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpio/gpio-dw.c +1 -1
index 6577042..e46cc8e 100644
@@ -95,7 +95,7 @@ static int dw_gpio_get_direction(struct gpio_chip *gc, unsigned offset)
 	struct dw_gpio_instance *chip = to_dw_gpio(gc);
 
 	return (readl(chip->regs + DW_GPIO_DDR) & (1 << offset)) ?
-		GPIO_DIR_OUT : GPIO_DIR_IN;
+		GPIOF_DIR_OUT : GPIOF_DIR_IN;
 }
 
 static struct gpio_ops imx_gpio_ops = {
include/gpio.h +2 -2
index 708b2aa..f33b435 100644
@@ -3,8 +3,8 @@
 
 #include <asm/gpio.h>
 
-#define GPIO_DIR_OUT	(0 << 0)
-#define GPIO_DIR_IN	(1 << 0)
+#define GPIOF_DIR_OUT	(0 << 0)
+#define GPIOF_DIR_IN	(1 << 0)
 
 #ifndef CONFIG_GPIOLIB
 static inline int gpio_request(unsigned gpio, const char *label)
Signature · 7 lines
1.8.4.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/2 gpiolib: import gpio_request_array() from linux 3.7

Also import related functions gpio_request_one() and gpio_free_array().

This commit imports code from linux 3.7 as
the more recent linux kernel versions use gpiolib descriptors, see this commit for details:

commit 372e722ea4dd4ca11c3d04845e11cbc15f32144c
Author: Alexandre Courbot <[email protected]>
Date: Sun Feb 3 01:29:29 2013 +0900

gpiolib: use descriptors internally

Make sure gpiolib works internally with descriptors and (chip, offset) pairs instead of using the global integer namespace. This prepares the ground for the removal of the global gpio_desc[] array and the introduction of the descriptor-based GPIO API.

---
 drivers/gpio/gpiolib.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/gpio.h         | 39 +++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+)
drivers/gpio/gpiolib.c +66 -0
index b7db596..8168bd3 100644
@@ -85,6 +85,72 @@ void gpio_free(unsigned gpio)
 	free(gi->label);
 }
 
+/**
+ * gpio_request_one - request a single GPIO with initial configuration
+ * @gpio:	the GPIO number
+ * @flags:	GPIO configuration as specified by GPIOF_*
+ * @label:	a literal description string of this GPIO
+ */
+int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
+{
+	int err;
+
+	err = gpio_request(gpio, label);
+	if (err)
+		return err;
+
+	if (flags & GPIOF_DIR_IN)
+		err = gpio_direction_input(gpio);
+	else
+		err = gpio_direction_output(gpio,
+				(flags & GPIOF_INIT_HIGH) ? 1 : 0);
+
+	if (err)
+		goto free_gpio;
+
+	return 0;
+
+ free_gpio:
+	gpio_free(gpio);
+	return err;
+}
+EXPORT_SYMBOL_GPL(gpio_request_one);
+
+/**
+ * gpio_request_array - request multiple GPIOs in a single call
+ * @array:	array of the 'struct gpio'
+ * @num:	how many GPIOs in the array
+ */
+int gpio_request_array(const struct gpio *array, size_t num)
+{
+	int i, err;
+
+	for (i = 0; i < num; i++, array++) {
+		err = gpio_request_one(array->gpio, array->flags, array->label);
+		if (err)
+			goto err_free;
+	}
+	return 0;
+
+err_free:
+	while (i--)
+		gpio_free((--array)->gpio);
+	return err;
+}
+EXPORT_SYMBOL_GPL(gpio_request_array);
+
+/**
+ * gpio_free_array - release multiple GPIOs in a single call
+ * @array:	array of the 'struct gpio'
+ * @num:	how many GPIOs in the array
+ */
+void gpio_free_array(const struct gpio *array, size_t num)
+{
+	while (num--)
+		gpio_free((array++)->gpio);
+}
+EXPORT_SYMBOL_GPL(gpio_free_array);
+
 void gpio_set_value(unsigned gpio, int value)
 {
 	struct gpio_info *gi = gpio_to_desc(gpio);
include/gpio.h +39 -0
index f33b435..b851e85 100644
@@ -6,6 +6,25 @@
 #define GPIOF_DIR_OUT	(0 << 0)
 #define GPIOF_DIR_IN	(1 << 0)
 
+#define GPIOF_INIT_LOW	(0 << 1)
+#define GPIOF_INIT_HIGH	(1 << 1)
+
+#define GPIOF_IN		(GPIOF_DIR_IN)
+#define GPIOF_OUT_INIT_LOW	(GPIOF_DIR_OUT | GPIOF_INIT_LOW)
+#define GPIOF_OUT_INIT_HIGH	(GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
+
+/**
+ * struct gpio - a structure describing a GPIO with configuration
+ * @gpio:	the GPIO number
+ * @flags:	GPIO configuration as specified by GPIOF_*
+ * @label:	a literal description string of this GPIO
+ */
+struct gpio {
+	unsigned	gpio;
+	unsigned long	flags;
+	const char	*label;
+};
+
 #ifndef CONFIG_GPIOLIB
 static inline int gpio_request(unsigned gpio, const char *label)
 {
@@ -15,9 +34,29 @@ static inline int gpio_request(unsigned gpio, const char *label)
 static inline void gpio_free(unsigned gpio)
 {
 }
+
+static inline int gpio_request_one(unsigned gpio,
+					unsigned long flags, const char *label)
+{
+	return 0;
+}
+
+static inline int gpio_request_array(const struct gpio *array, size_t num)
+{
+	return 0;
+}
+
+static inline void gpio_free_array(const struct gpio *array, size_t num)
+{
+	/* GPIO can never have been requested */
+	WARN_ON(1);
+}
 #else
 int gpio_request(unsigned gpio, const char *label);
 void gpio_free(unsigned gpio);
+int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
+int gpio_request_array(const struct gpio *array, size_t num);
+void gpio_free_array(const struct gpio *array, size_t num);
 #endif
 
 struct gpio_chip;
Signature · 7 lines
1.8.4.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

Re: [PATCH 2/2] gpiolib: import gpio_request_array() from linux 3.7

Hi Antony,

Quoted 11 lines · Antony Pavlov

Also import related functions gpio_request_one() and gpio_free_array().

This commit imports code from linux 3.7 as
the more recent linux kernel versions use gpiolib descriptors, see this commit for details:

commit 372e722ea4dd4ca11c3d04845e11cbc15f32144c
Author: Alexandre Courbot <[email protected]>
Date: Sun Feb 3 01:29:29 2013 +0900

Quoted 8 lines

gpiolib: use descriptors internally

Make sure gpiolib works internally with descriptors and (chip, offset) pairs instead of using the global integer namespace. This prepares the ground for the removal of the global gpio_desc[] array and the introduction of the descriptor-based GPIO API.

What a pitty, we duplicated some work. I created exactly the same patch recently but haven't posted it yet, shame on me.

include/gpio.h static inline int gpio_request(unsigned gpio, const char *label) · line 48

Quoted 11 lines
include/gpio.h +11 -0
+static inline int gpio_request_one(unsigned gpio,
+					unsigned long flags, const char *label)
+{
+	return 0;
+}
+
+static inline int gpio_request_array(const struct gpio *array, size_t num)
+{
+	return 0;
+}
+

That's the only place our patches differ. In my version I return -ENOSYS since gpio_request_one() and gpio_request_array() not only request gpios but also configure them. We can't return success without configuring the gpios. I applied your version but with -ENOSYS here.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Re: [PATCH 2/2] gpiolib: import gpio_request_array() from linux 3.7

Quoted 21 lines · On Fri, 22 Nov 2013 08:20:08 +0100 Sascha Hauer <[email protected]> wrote:

Hi Antony,

Quoted 18 lines · Antony Pavlov

Also import related functions gpio_request_one() and gpio_free_array().

This commit imports code from linux 3.7 as
the more recent linux kernel versions use gpiolib descriptors, see this commit for details:

commit 372e722ea4dd4ca11c3d04845e11cbc15f32144c
Author: Alexandre Courbot <[email protected]>
Date: Sun Feb 3 01:29:29 2013 +0900

gpiolib: use descriptors internally

Make sure gpiolib works internally with descriptors and (chip, offset) pairs instead of using the global integer namespace. This prepares the ground for the removal of the global gpio_desc[] array and the introduction of the descriptor-based GPIO API.

Quoted 4 lines
Quoted 1 line

What a pitty, we duplicated some work. I created exactly the same patch recently but haven't posted it yet, shame on me.

I must say "Thanks!" to Sebastian Hesselbarth. It's him who introduced get_direction callback. His patch conflicted with patch in my local repo. So I made the decision to post my patch as soon as possible.

Quoted 29 lines

include/gpio.h static inline int gpio_request(unsigned gpio, const char *label) · line 48

Quoted 11 lines
include/gpio.h +11 -0
+static inline int gpio_request_one(unsigned gpio,
+					unsigned long flags, const char *label)
+{
+	return 0;
+}
+
+static inline int gpio_request_array(const struct gpio *array, size_t num)
+{
+	return 0;
+}
+

That's the only place our patches differ. In my version I return -ENOSYS since gpio_request_one() and gpio_request_array() not only request gpios but also configure them. We can't return success without configuring the gpios. I applied your version but with -ENOSYS here.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 7 lines
С уважением,
  Павлов Антон

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

Re: [PATCH 2/2] gpiolib: import gpio_request_array() from linux 3.7

Quoted 24 lines · Antony N. Pavlov
Quoted 21 lines · On Fri, 22 Nov 2013 08:20:08 +0100 Sascha Hauer <[email protected]> wrote:

Hi Antony,

Quoted 18 lines · Antony Pavlov

Also import related functions gpio_request_one() and gpio_free_array().

This commit imports code from linux 3.7 as
the more recent linux kernel versions use gpiolib descriptors, see this commit for details:

commit 372e722ea4dd4ca11c3d04845e11cbc15f32144c
Author: Alexandre Courbot <[email protected]>
Date: Sun Feb 3 01:29:29 2013 +0900

gpiolib: use descriptors internally

Make sure gpiolib works internally with descriptors and (chip, offset) pairs instead of using the global integer namespace. This prepares the ground for the removal of the global gpio_desc[] array and the introduction of the descriptor-based GPIO API.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

What a pitty, we duplicated some work. I created exactly the same patch recently but haven't posted it yet, shame on me.

I must say "Thanks!" to Sebastian Hesselbarth. It's him who introduced get_direction callback. His patch conflicted with patch in my local repo. So I made the decision to post my patch as soon as possible.

I added that callback because I needed it for working on Marvell Berlin support. Don't expect too fancy stuff, but as soon as I find some time to work out the Chipidea USB device driver, I'll be posting patches for Chromecast.

The get_direction callback gives valuable information for unknown HW :P

Sebastian

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox