Skip to contentSkip to conversation

gpiolib: Downgrade set_debounce() missing operation warning

PATCH In review Mark Brown 3 participants 7 messages Sep 6, 2013 – Sep 9, 2013 GPIO

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/3 gpiolib: Downgrade set_debounce() missing operation warning

From: Mark Brown <[email protected]>

It is reasonable for a driver using a GPIO to call set_debounce() on GPIOs that don't provide this support in hardware since the driver can fall back on a software debounce implementation or otherwise not depend on success so downgrade the log message for this to a debug one.

---
 drivers/gpio/gpiolib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib.c +2 -2
index b762718..374cf9e 100644
@@ -1779,8 +1779,8 @@ static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
 
 	chip = desc->chip;
 	if (!chip->set || !chip->set_debounce) {
-		pr_warn("%s: missing set() or set_debounce() operations\n",
-			__func__);
+		pr_debug("%s: missing set() or set_debounce() operations\n",
+			 __func__);
 		return -EIO;
 	}
 
Signature · 1 line
1.8.4.rc3
author
#1 lore raw

PATCH 2/3 gpiolib: Provide helper macros for logging of GPIO events

From: Mark Brown <[email protected]>

Currently many but not all GPIO log messages log the GPIO number and the formats vary. Ensure that this is done consistently by defining logging helpers which take the GPIO descriptor.

The will help people pattern matching on logs and providing the number makes the log messages that omitted it more useful.

---
 drivers/gpio/gpiolib.c | 52 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 20 deletions(-)
drivers/gpio/gpiolib.c +32 -20
index 374cf9e..e389183 100644
@@ -103,6 +103,18 @@ static int gpiod_export_link(struct device *dev, const char *name,
 static int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value);
 static void gpiod_unexport(struct gpio_desc *desc);
 
+#define gpiod_emerg(desc, fmt, ...)			           \
+	pr_emerg("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
+#define gpiod_crit(desc, fmt, ...)			           \
+	pr_crit("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
+#define gpiod_err(desc, fmt, ...)				   \
+	pr_err("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
+#define gpiod_warn(desc, fmt, ...)				   \
+	pr_warn("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
+#define gpiod_info(desc, fmt, ...)				   \
+	pr_info("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
+#define gpiod_dbg(desc, fmt, ...)				   \
+	pr_debug("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
 
 static inline void desc_set_label(struct gpio_desc *d, const char *label)
 {
@@ -1636,8 +1648,9 @@ static int gpiod_direction_input(struct gpio_desc *desc)
 
 	chip = desc->chip;
 	if (!chip->get || !chip->direction_input) {
-		pr_warn("%s: missing get() or direction_input() operations\n",
-			__func__);
+		gpiod_warn(desc,
+			"%s: missing get() or direction_input() operations\n",
+			 __func__);
 		return -EIO;
 	}
 
@@ -1657,8 +1670,7 @@ static int gpiod_direction_input(struct gpio_desc *desc)
 	if (status) {
 		status = chip->request(chip, offset);
 		if (status < 0) {
-			pr_debug("GPIO-%d: chip request fail, %d\n",
-				desc_to_gpio(desc), status);
+			gpiod_dbg(desc, "chip request fail, %d\n", status);
 			/* and it's not available to anyone else ...
 			 * gpio_request() is the fully clean solution.
 			 */
@@ -1676,8 +1688,7 @@ lose:
 fail:
 	spin_unlock_irqrestore(&gpio_lock, flags);
 	if (status)
-		pr_debug("%s: gpio-%d status %d\n", __func__,
-			 desc_to_gpio(desc), status);
+		gpiod_dbg(desc, "%s status %d\n", __func__, status);
 	return status;
 }
 
@@ -1709,8 +1720,9 @@ static int gpiod_direction_output(struct gpio_desc *desc, int value)
 
 	chip = desc->chip;
 	if (!chip->set || !chip->direction_output) {
-		pr_warn("%s: missing set() or direction_output() operations\n",
-			__func__);
+		gpiod_warn(desc,
+		       "%s: missing set() or direction_output() operations\n",
+		       __func__);
 		return -EIO;
 	}
 
@@ -1730,8 +1742,7 @@ static int gpiod_direction_output(struct gpio_desc *desc, int value)
 	if (status) {
 		status = chip->request(chip, offset);
 		if (status < 0) {
-			pr_debug("GPIO-%d: chip request fail, %d\n",
-				desc_to_gpio(desc), status);
+			gpiod_dbg(desc, "chip request fail, %d\n", status);
 			/* and it's not available to anyone else ...
 			 * gpio_request() is the fully clean solution.
 			 */
@@ -1749,8 +1760,7 @@ lose:
 fail:
 	spin_unlock_irqrestore(&gpio_lock, flags);
 	if (status)
-		pr_debug("%s: gpio-%d status %d\n", __func__,
-			 desc_to_gpio(desc), status);
+		gpiod_dbg(desc, "%s: gpio status %d\n", __func__, status);
 	return status;
 }
 
@@ -1779,8 +1789,9 @@ static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
 
 	chip = desc->chip;
 	if (!chip->set || !chip->set_debounce) {
-		pr_debug("%s: missing set() or set_debounce() operations\n",
-			 __func__);
+		gpiod_dbg(desc,
+			  "%s: missing set() or set_debounce() operations\n",
+			  __func__);
 		return -EIO;
 	}
 
@@ -1802,8 +1813,7 @@ static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
 fail:
 	spin_unlock_irqrestore(&gpio_lock, flags);
 	if (status)
-		pr_debug("%s: gpio-%d status %d\n", __func__,
-			 desc_to_gpio(desc), status);
+		gpiod_dbg(desc, "%s: status %d\n", __func__, status);
 
 	return status;
 }
@@ -1891,8 +1901,9 @@ static void _gpio_set_open_drain_value(struct gpio_desc *desc, int value)
 	}
 	trace_gpio_direction(desc_to_gpio(desc), value, err);
 	if (err < 0)
-		pr_err("%s: Error in set_value for open drain gpio%d err %d\n",
-					__func__, desc_to_gpio(desc), err);
+		gpiod_err(desc,
+			  "%s: Error in set_value for open drain err %d\n",
+			  __func__, err);
 }
 
 /*
@@ -1918,8 +1929,9 @@ static void _gpio_set_open_source_value(struct gpio_desc *desc, int value)
 	}
 	trace_gpio_direction(desc_to_gpio(desc), !value, err);
 	if (err < 0)
-		pr_err("%s: Error in set_value for open source gpio%d err %d\n",
-					__func__, desc_to_gpio(desc), err);
+		gpiod_err(desc,
+			  "%s: Error in set_value for open source err %d\n",
+			  __func__, err);
 }
 
 /**
Signature · 1 line
1.8.4.rc3
Acked-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] gpiolib: Provide helper macros for logging of GPIO events

Quoted 8 lines · Mark Brown

From: Mark Brown <[email protected]>

Currently many but not all GPIO log messages log the GPIO number and the formats vary. Ensure that this is done consistently by defining logging helpers which take the GPIO descriptor.

The will help people pattern matching on logs and providing the number makes the log messages that omitted it more useful.

I like the idea of having log helpers, but we are trying to deprecate the representation of GPIO as integers. Well, for now this is indeed the only way to use them, so what I am saying might only apply when the gpiod RFC patches are refined and merged, but how about thinking of another way to represent them, e.g. by GPIO chip name/GPIO index wrt. their chip? The representation needs to be compact, which is another challenge.

Note that this is not a comment against this patch (which definitely improves the situation), just some thinking about a problem we will likely face later.

Quoted 146 lines
---
 drivers/gpio/gpiolib.c | 52 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 20 deletions(-)
drivers/gpio/gpiolib.c +32 -21
index 374cf9e..e389183 100644
@@ -103,6 +103,18 @@ static int gpiod_export_link(struct device *dev, const char *name,
 static int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value);
 static void gpiod_unexport(struct gpio_desc *desc);
 
+#define gpiod_emerg(desc, fmt, ...)                               \
+       pr_emerg("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
+#define gpiod_crit(desc, fmt, ...)                                \
+       pr_crit("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
+#define gpiod_err(desc, fmt, ...)                                 \
+       pr_err("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
+#define gpiod_warn(desc, fmt, ...)                                \
+       pr_warn("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
+#define gpiod_info(desc, fmt, ...)                                \
+       pr_info("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
+#define gpiod_dbg(desc, fmt, ...)                                 \
+       pr_debug("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
 
 static inline void desc_set_label(struct gpio_desc *d, const char *label)
 {
@@ -1636,8 +1648,9 @@ static int gpiod_direction_input(struct gpio_desc *desc)
 
        chip = desc->chip;
        if (!chip->get || !chip->direction_input) {
-               pr_warn("%s: missing get() or direction_input() operations\n",
-                       __func__);
+               gpiod_warn(desc,
+                       "%s: missing get() or direction_input() operations\n",
+                        __func__);
                return -EIO;
        }
 
@@ -1657,8 +1670,7 @@ static int gpiod_direction_input(struct gpio_desc *desc)
        if (status) {
                status = chip->request(chip, offset);
                if (status < 0) {
-                       pr_debug("GPIO-%d: chip request fail, %d\n",
-                               desc_to_gpio(desc), status);
+                       gpiod_dbg(desc, "chip request fail, %d\n", status);
                        /* and it's not available to anyone else ...
                         * gpio_request() is the fully clean solution.
                         */
@@ -1676,8 +1688,7 @@ lose:
 fail:
        spin_unlock_irqrestore(&gpio_lock, flags);
        if (status)
-               pr_debug("%s: gpio-%d status %d\n", __func__,
-                        desc_to_gpio(desc), status);
+               gpiod_dbg(desc, "%s status %d\n", __func__, status);
        return status;
 }
 
@@ -1709,8 +1720,9 @@ static int gpiod_direction_output(struct gpio_desc *desc, int value)
 
        chip = desc->chip;
        if (!chip->set || !chip->direction_output) {
-               pr_warn("%s: missing set() or direction_output() operations\n",
-                       __func__);
+               gpiod_warn(desc,
+                      "%s: missing set() or direction_output() operations\n",
+                      __func__);
                return -EIO;
        }
 
@@ -1730,8 +1742,7 @@ static int gpiod_direction_output(struct gpio_desc *desc, int value)
        if (status) {
                status = chip->request(chip, offset);
                if (status < 0) {
-                       pr_debug("GPIO-%d: chip request fail, %d\n",
-                               desc_to_gpio(desc), status);
+                       gpiod_dbg(desc, "chip request fail, %d\n", status);
                        /* and it's not available to anyone else ...
                         * gpio_request() is the fully clean solution.
                         */
@@ -1749,8 +1760,7 @@ lose:
 fail:
        spin_unlock_irqrestore(&gpio_lock, flags);
        if (status)
-               pr_debug("%s: gpio-%d status %d\n", __func__,
-                        desc_to_gpio(desc), status);
+               gpiod_dbg(desc, "%s: gpio status %d\n", __func__, status);
        return status;
 }
 
@@ -1779,8 +1789,9 @@ static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
 
        chip = desc->chip;
        if (!chip->set || !chip->set_debounce) {
-               pr_debug("%s: missing set() or set_debounce() operations\n",
-                        __func__);
+               gpiod_dbg(desc,
+                         "%s: missing set() or set_debounce() operations\n",
+                         __func__);
                return -EIO;
        }
 
@@ -1802,8 +1813,7 @@ static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
 fail:
        spin_unlock_irqrestore(&gpio_lock, flags);
        if (status)
-               pr_debug("%s: gpio-%d status %d\n", __func__,
-                        desc_to_gpio(desc), status);
+               gpiod_dbg(desc, "%s: status %d\n", __func__, status);
 
        return status;
 }
@@ -1891,8 +1901,9 @@ static void _gpio_set_open_drain_value(struct gpio_desc *desc, int value)
        }
        trace_gpio_direction(desc_to_gpio(desc), value, err);
        if (err < 0)
-               pr_err("%s: Error in set_value for open drain gpio%d err %d\n",
-                                       __func__, desc_to_gpio(desc), err);
+               gpiod_err(desc,
+                         "%s: Error in set_value for open drain err %d\n",
+                         __func__, err);
 }
 
 /*
@@ -1918,8 +1929,9 @@ static void _gpio_set_open_source_value(struct gpio_desc *desc, int value)
        }
        trace_gpio_direction(desc_to_gpio(desc), !value, err);
        if (err < 0)
-               pr_err("%s: Error in set_value for open source gpio%d err %d\n",
-                                       __func__, desc_to_gpio(desc), err);
+               gpiod_err(desc,
+                         "%s: Error in set_value for open source err %d\n",
+                         __func__, err);
 }
 
 /**
--

1.8.4.rc3

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#3 lore raw

Re: [PATCH 2/3] gpiolib: Provide helper macros for logging of GPIO events

Quoted 7 lines · Alexandre Courbot

I like the idea of having log helpers, but we are trying to deprecate the representation of GPIO as integers. Well, for now this is indeed the only way to use them, so what I am saying might only apply when the gpiod RFC patches are refined and merged, but how about thinking of another way to represent them, e.g. by GPIO chip name/GPIO index wrt. their chip? The representation needs to be compact, which is another challenge.

dev_name() plus label perhaps? Some of the labels do tend to get a bit long but if they're used this way it'd probably encourage brevity.

author
#4 lore raw

PATCH 3/3 gpiolib: Include GPIO label in log messages for GPIOs

In reply to Mark Brown

From: Mark Brown <[email protected]>

Provide the human readable label for the GPIO as well as the number when we are recording it in order to improve the readability of log messages.

---
 drivers/gpio/gpiolib.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/gpio/gpiolib.c +21 -0
index e389183..a3a41bc 100644
@@ -103,6 +103,26 @@ static int gpiod_export_link(struct device *dev, const char *name,
 static int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value);
 static void gpiod_unexport(struct gpio_desc *desc);
 
+#ifdef CONFIG_DEBUG_FS
+#define gpiod_emerg(desc, fmt, ...)			                \
+	pr_emerg("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label, \
+                 ##__VA_ARGS__)
+#define gpiod_crit(desc, fmt, ...)			                \
+	pr_crit("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label,  \
+                 ##__VA_ARGS__)
+#define gpiod_err(desc, fmt, ...)				        \
+	pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label,   \
+                 ##__VA_ARGS__)
+#define gpiod_warn(desc, fmt, ...)				        \
+	pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label,  \
+                 ##__VA_ARGS__)
+#define gpiod_info(desc, fmt, ...)				        \
+	pr_info("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label,  \
+                ##__VA_ARGS__)
+#define gpiod_dbg(desc, fmt, ...)				   \
+	pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label, \
+                 ##__VA_ARGS__)
+#else
 #define gpiod_emerg(desc, fmt, ...)			           \
 	pr_emerg("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
 #define gpiod_crit(desc, fmt, ...)			           \
@@ -115,6 +135,7 @@ static void gpiod_unexport(struct gpio_desc *desc);
 	pr_info("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
 #define gpiod_dbg(desc, fmt, ...)				   \
 	pr_debug("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__)
+#endif
 
 static inline void desc_set_label(struct gpio_desc *d, const char *label)
 {
Signature · 1 line
1.8.4.rc3
#5 lore raw
In reply to Mark Brown

drivers/gpio/gpiolib.c static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) · line 1783

Quoted 9 lines · Mark Brown

+++ b/drivers/gpio/gpiolib.c

drivers/gpio/gpiolib.c +2 -2
@@ -1779,8 +1779,8 @@ static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
 
        chip = desc->chip;
        if (!chip->set || !chip->set_debounce) {
-               pr_warn("%s: missing set() or set_debounce() operations\n",
-                       __func__);
+               pr_debug("%s: missing set() or set_debounce() operations\n",
+                        __func__);

A patch like this is already upstream, but thanks anyway!

Yours,
Linus Walleij

author
#6 lore raw
Quoted 1 line · Linus Walleij

A patch like this is already upstream, but thanks anyway!

Hrm, it hadn't found its way into -next on Friday but I see it's there now.