Skip to contentSkip to conversation

gpiolib: import gpio_request_array() from linux 3.7

RFC In review Antony Pavlov 3 participants 10 messages Feb 3, 2013 – Feb 6, 2013 GPIO

lore
Share & tools
lore
#0 lore raw

RFC 1/1 gpiolib: import gpio_request_array() from linux 3.7

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

---
 drivers/gpio/gpio.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/gpio.h      |   43 +++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
drivers/gpio/gpio.c +66 -0
index d37f5a0..631168d 100644
@@ -65,6 +65,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(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(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(gpio_free_array);
+
 void gpio_set_value(unsigned gpio, int value)
 {
 	struct gpio_info *gi = &gpio_desc[gpio];
include/gpio.h +43 -0

58 lines not on this page · raw message

Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw
Quoted 125 lines · Antony Pavlov

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

---
 drivers/gpio/gpio.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/gpio.h      |   43 +++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
drivers/gpio/gpio.c +66 -0
index d37f5a0..631168d 100644
@@ -65,6 +65,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(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(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(gpio_free_array);
+
 void gpio_set_value(unsigned gpio, int value)
 {
 	struct gpio_info *gi = &gpio_desc[gpio];
include/gpio.h +24 -0
index eedb980..37c151d 100644
@@ -3,6 +3,29 @@
 
 #include <asm/gpio.h>
 
+/* make these flag values available regardless of GPIO kconfig options */
+#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)
 {
@@ -12,9 +35,29 @@ static inline int gpio_request(unsigned gpio, const char *label)
 static inline void gpio_free(unsigned gpio)
 {
 }
+

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

Quoted 10 lines
include/gpio.h +10 -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;
+}

you can not do this

as if we start to use this in generic driver where gpio_direction_input/output work

we will endup with no configuration

so you need to provide working inline instead

Quoted 23 lines
include/gpio.h +9 -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.7.10.4


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

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

#2 lore raw
Quoted 138 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 125 lines · Antony Pavlov

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

---
 drivers/gpio/gpio.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/gpio.h      |   43 +++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
drivers/gpio/gpio.c +66 -0
index d37f5a0..631168d 100644
@@ -65,6 +65,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(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(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(gpio_free_array);
+
 void gpio_set_value(unsigned gpio, int value)
 {
      struct gpio_info *gi = &gpio_desc[gpio];
include/gpio.h +24 -0
index eedb980..37c151d 100644
@@ -3,6 +3,29 @@
 
 #include <asm/gpio.h>
 
+/* make these flag values available regardless of GPIO kconfig options */
+#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)
 {
@@ -12,9 +35,29 @@ static inline int gpio_request(unsigned gpio, const char *label)
 static inline void gpio_free(unsigned gpio)
 {
 }
+

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

Quoted 10 lines
include/gpio.h +10 -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;
+}

you can not do this

Quoted 4 lines

as if we start to use this in generic driver where gpio_direction_input/output work

we will endup with no configuration

But now in include/gpio.h we have this:

static inline int gpio_request(unsigned gpio, const char *label)

{
    return 0;
}

Can you explain the difference?

Quoted 24 lines

so you need to provide working inline instead

Quoted 23 lines
include/gpio.h +9 -1
+
+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;
--

1.7.10.4

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

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw
Quoted 145 lines · Antony Pavlov
Quoted 138 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 125 lines · Antony Pavlov

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

---
 drivers/gpio/gpio.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/gpio.h      |   43 +++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
drivers/gpio/gpio.c +66 -0
index d37f5a0..631168d 100644
@@ -65,6 +65,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(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(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(gpio_free_array);
+
 void gpio_set_value(unsigned gpio, int value)
 {
      struct gpio_info *gi = &gpio_desc[gpio];
include/gpio.h +24 -0
index eedb980..37c151d 100644
@@ -3,6 +3,29 @@
 
 #include <asm/gpio.h>
 
+/* make these flag values available regardless of GPIO kconfig options */
+#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)
 {
@@ -12,9 +35,29 @@ static inline int gpio_request(unsigned gpio, const char *label)
 static inline void gpio_free(unsigned gpio)
 {
 }
+

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

Quoted 10 lines
include/gpio.h +10 -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;
+}

you can not do this

Quoted 4 lines

as if we start to use this in generic driver where gpio_direction_input/output work

we will endup with no configuration

Quoted 8 lines

But now in include/gpio.h we have this:

static inline int gpio_request(unsigned gpio, const char *label)

{
    return 0;
}

Can you explain the difference?

gpio_request is not implemented without gpiolib, still you have to configure the direction and value.

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
#4 lore raw
Quoted 153 lines · Sascha Hauer
Quoted 152 lines · Antony Pavlov
Quoted 138 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 125 lines · Antony Pavlov

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

---
 drivers/gpio/gpio.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/gpio.h      |   43 +++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
drivers/gpio/gpio.c +66 -0
index d37f5a0..631168d 100644
@@ -65,6 +65,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(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(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(gpio_free_array);
+
 void gpio_set_value(unsigned gpio, int value)
 {
      struct gpio_info *gi = &gpio_desc[gpio];
include/gpio.h +24 -0
index eedb980..37c151d 100644
@@ -3,6 +3,29 @@
 
 #include <asm/gpio.h>
 
+/* make these flag values available regardless of GPIO kconfig options */
+#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)
 {
@@ -12,9 +35,29 @@ static inline int gpio_request(unsigned gpio, const char *label)
 static inline void gpio_free(unsigned gpio)
 {
 }
+

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

Quoted 10 lines
include/gpio.h +10 -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;
+}

you can not do this

Quoted 4 lines

as if we start to use this in generic driver where gpio_direction_input/output work

we will endup with no configuration

But now in include/gpio.h we have this:

static inline int gpio_request(unsigned gpio, const char *label)

{
    return 0;
}
Quoted 4 lines
Quoted 1 line

Can you explain the difference?

gpio_request is not implemented without gpiolib, still you have to configure the direction and value.

Can we use this functions only if gpiolib is enabled? Can we skip the function's definiton in the non-gpio situation?

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw
Quoted 154 lines · Antony Pavlov
Quoted 153 lines · Sascha Hauer
Quoted 152 lines · Antony Pavlov
Quoted 138 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 125 lines · Antony Pavlov

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

---
 drivers/gpio/gpio.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/gpio.h      |   43 +++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
drivers/gpio/gpio.c +66 -0
index d37f5a0..631168d 100644
@@ -65,6 +65,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(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(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(gpio_free_array);
+
 void gpio_set_value(unsigned gpio, int value)
 {
      struct gpio_info *gi = &gpio_desc[gpio];
include/gpio.h +24 -0
index eedb980..37c151d 100644
@@ -3,6 +3,29 @@
 
 #include <asm/gpio.h>
 
+/* make these flag values available regardless of GPIO kconfig options */
+#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)
 {
@@ -12,9 +35,29 @@ static inline int gpio_request(unsigned gpio, const char *label)
 static inline void gpio_free(unsigned gpio)
 {
 }
+

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

Quoted 10 lines
include/gpio.h +10 -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;
+}

you can not do this

Quoted 4 lines

as if we start to use this in generic driver where gpio_direction_input/output work

we will endup with no configuration

But now in include/gpio.h we have this:

static inline int gpio_request(unsigned gpio, const char *label)

{
    return 0;
}
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Can you explain the difference?

gpio_request is not implemented without gpiolib, still you have to configure the direction and value.

Can we use this functions only if gpiolib is enabled? Can we skip the function's definiton in the non-gpio situation?

Sounds fine. We should get rid of the !gpiolib drivers anyway, maybe this adds some motivation.

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
#6 lore raw
Quoted 157 lines · Sascha Hauer
Quoted 156 lines · Antony Pavlov
Quoted 155 lines · Sascha Hauer
Quoted 153 lines · Antony Pavlov
Quoted 138 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 125 lines · Antony Pavlov

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

---
 drivers/gpio/gpio.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/gpio.h      |   43 +++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
drivers/gpio/gpio.c +66 -0
index d37f5a0..631168d 100644
@@ -65,6 +65,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(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(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(gpio_free_array);
+
 void gpio_set_value(unsigned gpio, int value)
 {
      struct gpio_info *gi = &gpio_desc[gpio];
include/gpio.h +24 -0
index eedb980..37c151d 100644
@@ -3,6 +3,29 @@
 
 #include <asm/gpio.h>
 
+/* make these flag values available regardless of GPIO kconfig options */
+#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)
 {
@@ -12,9 +35,29 @@ static inline int gpio_request(unsigned gpio, const char *label)
 static inline void gpio_free(unsigned gpio)
 {
 }
+

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

Quoted 10 lines
include/gpio.h +10 -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;
+}

you can not do this

Quoted 4 lines

as if we start to use this in generic driver where gpio_direction_input/output work

we will endup with no configuration

But now in include/gpio.h we have this:

static inline int gpio_request(unsigned gpio, const char *label)

{
    return 0;
}

Can you explain the difference?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

gpio_request is not implemented without gpiolib, still you have to configure the direction and value.

Can we use this functions only if gpiolib is enabled? Can we skip the function's definiton in the non-gpio situation?

Sounds fine. We should get rid of the !gpiolib drivers anyway, maybe this adds some motivation.

until every driver are swith to gpiolib NACK as if we switch any generic driver to this as leds, gpio-keys, i2c-gpio etc... we break board support siliently

Best Regards,
J.

Quoted 8 lines

Sascha

Signature · 4 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

#7 lore raw
Quoted 164 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 163 lines · Sascha Hauer
Quoted 161 lines · Antony Pavlov
Quoted 153 lines · Sascha Hauer
Quoted 152 lines · Antony Pavlov
Quoted 138 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 125 lines · Antony Pavlov

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

---
 drivers/gpio/gpio.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/gpio.h      |   43 +++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
drivers/gpio/gpio.c +66 -0
index d37f5a0..631168d 100644
@@ -65,6 +65,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(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(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(gpio_free_array);
+
 void gpio_set_value(unsigned gpio, int value)
 {
      struct gpio_info *gi = &gpio_desc[gpio];
include/gpio.h +24 -0
index eedb980..37c151d 100644
@@ -3,6 +3,29 @@
 
 #include <asm/gpio.h>
 
+/* make these flag values available regardless of GPIO kconfig options */
+#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)
 {
@@ -12,9 +35,29 @@ static inline int gpio_request(unsigned gpio, const char *label)
 static inline void gpio_free(unsigned gpio)
 {
 }
+

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

Quoted 10 lines
include/gpio.h +10 -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;
+}

you can not do this

Quoted 4 lines

as if we start to use this in generic driver where gpio_direction_input/output work

we will endup with no configuration

But now in include/gpio.h we have this:

static inline int gpio_request(unsigned gpio, const char *label)

{
    return 0;
}
Quoted 4 lines
Quoted 1 line

Can you explain the difference?

gpio_request is not implemented without gpiolib, still you have to configure the direction and value.

Can we use this functions only if gpiolib is enabled? Can we skip the function's definiton in the non-gpio situation?

Quoted 6 lines
Quoted 2 lines

Sounds fine. We should get rid of the !gpiolib drivers anyway, maybe this adds some motivation.

until every driver are swith to gpiolib NACK as if we switch any generic driver to this as leds, gpio-keys, i2c-gpio etc... we break board support siliently

but leds, gpio-keys, i2c-gpio etc don't use gpio_request_one()-related functions.
If we ristrict the usage of gpio_request_one()-related functions (use it only in board code for gpiolib-enabled machines)
we can avoid mentioned problems.

Signature · 7 lines
Best regards,
  Antony Pavlov

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

ping

Quoted 182 lines · Antony Pavlov
Quoted 164 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 163 lines · Sascha Hauer
Quoted 161 lines · Antony Pavlov
Quoted 153 lines · Sascha Hauer
Quoted 152 lines · Antony Pavlov
Quoted 138 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 125 lines · Antony Pavlov

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

---
 drivers/gpio/gpio.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/gpio.h      |   43 +++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
drivers/gpio/gpio.c +66 -0
index d37f5a0..631168d 100644
@@ -65,6 +65,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(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(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(gpio_free_array);
+
 void gpio_set_value(unsigned gpio, int value)
 {
      struct gpio_info *gi = &gpio_desc[gpio];
include/gpio.h +24 -0
index eedb980..37c151d 100644
@@ -3,6 +3,29 @@
 
 #include <asm/gpio.h>
 
+/* make these flag values available regardless of GPIO kconfig options */
+#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)
 {
@@ -12,9 +35,29 @@ static inline int gpio_request(unsigned gpio, const char *label)
 static inline void gpio_free(unsigned gpio)
 {
 }
+

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

Quoted 10 lines
include/gpio.h +10 -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;
+}

you can not do this

Quoted 4 lines

as if we start to use this in generic driver where gpio_direction_input/output work

we will endup with no configuration

But now in include/gpio.h we have this:

static inline int gpio_request(unsigned gpio, const char *label)

{
    return 0;
}
Quoted 4 lines
Quoted 1 line

Can you explain the difference?

gpio_request is not implemented without gpiolib, still you have to configure the direction and value.

Can we use this functions only if gpiolib is enabled? Can we skip the function's definiton in the non-gpio situation?

Quoted 6 lines
Quoted 2 lines

Sounds fine. We should get rid of the !gpiolib drivers anyway, maybe this adds some motivation.

until every driver are swith to gpiolib NACK as if we switch any generic driver to this as leds, gpio-keys, i2c-gpio etc... we break board support siliently

but leds, gpio-keys, i2c-gpio etc don't use gpio_request_one()-related functions.
If we ristrict the usage of gpio_request_one()-related functions (use it only in board code for gpiolib-enabled machines)
we can avoid mentioned problems.

--
Best regards,
Antony Pavlov

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw
In reply to Antony Pavlov
Quoted 173 lines · Antony Pavlov
Quoted 164 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 163 lines · Sascha Hauer
Quoted 161 lines · Antony Pavlov
Quoted 153 lines · Sascha Hauer
Quoted 152 lines · Antony Pavlov
Quoted 138 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 125 lines · Antony Pavlov

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

---
 drivers/gpio/gpio.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/gpio.h      |   43 +++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
drivers/gpio/gpio.c +66 -0
index d37f5a0..631168d 100644
@@ -65,6 +65,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(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(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(gpio_free_array);
+
 void gpio_set_value(unsigned gpio, int value)
 {
      struct gpio_info *gi = &gpio_desc[gpio];
include/gpio.h +24 -0
index eedb980..37c151d 100644
@@ -3,6 +3,29 @@
 
 #include <asm/gpio.h>
 
+/* make these flag values available regardless of GPIO kconfig options */
+#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)
 {
@@ -12,9 +35,29 @@ static inline int gpio_request(unsigned gpio, const char *label)
 static inline void gpio_free(unsigned gpio)
 {
 }
+

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

Quoted 10 lines
include/gpio.h +10 -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;
+}

you can not do this

Quoted 4 lines

as if we start to use this in generic driver where gpio_direction_input/output work

we will endup with no configuration

But now in include/gpio.h we have this:

static inline int gpio_request(unsigned gpio, const char *label)

{
    return 0;
}
Quoted 4 lines
Quoted 1 line

Can you explain the difference?

gpio_request is not implemented without gpiolib, still you have to configure the direction and value.

Can we use this functions only if gpiolib is enabled? Can we skip the function's definiton in the non-gpio situation?

Quoted 6 lines
Quoted 2 lines

Sounds fine. We should get rid of the !gpiolib drivers anyway, maybe this adds some motivation.

until every driver are swith to gpiolib NACK as if we switch any generic driver to this as leds, gpio-keys, i2c-gpio etc... we break board support siliently

Quoted 5 lines

but leds, gpio-keys, i2c-gpio etc don't use gpio_request_one()-related functions.
If we ristrict the usage of gpio_request_one()-related functions (use it only in board code for gpiolib-enabled machines)
we can avoid mentioned problems.

You should probably just provide a static inline wrapper for the !gpiolib case. It's sufficiently easy to do and avoids that someone who wants to use the functions in a driver has to fixup all other gpio drivers first.

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