* [PATCH] gpio: sim: implement the dbg_show() callback
@ 2023-11-30 10:40 Bartosz Golaszewski
2023-11-30 13:37 ` Andy Shevchenko
0 siblings, 1 reply; 4+ messages in thread
From: Bartosz Golaszewski @ 2023-11-30 10:40 UTC (permalink / raw)
To: Linus Walleij, Andy Shevchenko, Kent Gibson
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Provide a custom implementation of the dbg_show() callback that prints
all requested lines together with their label, direction, value and
bias. This improves the code coverage of GPIOLIB.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/gpio-sim.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 1928209491e1..f60b0988c4db 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -28,6 +28,7 @@
#include <linux/notifier.h>
#include <linux/platform_device.h>
#include <linux/property.h>
+#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/string_helpers.h>
@@ -224,6 +225,29 @@ static void gpio_sim_free(struct gpio_chip *gc, unsigned int offset)
}
}
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+static void gpio_sim_dbg_show(struct seq_file *seq, struct gpio_chip *gc)
+{
+ struct gpio_sim_chip *chip = gpiochip_get_data(gc);
+ const char *label;
+ int i;
+
+ guard(mutex)(&chip->lock);
+
+ for_each_requested_gpio(gc, i, label)
+ seq_printf(seq, " gpio-%-3d (%s) %s,%s\n",
+ gc->base + i,
+ label,
+ test_bit(i, chip->direction_map) ? "input" :
+ test_bit(i, chip->value_map) ? "output-high" :
+ "output-low",
+ test_bit(i, chip->pull_map) ? "pull-up" :
+ "pull-down");
+}
+#else
+#define gpio_sim_dbg_show NULL
+#endif /* CONFIG_DEBUG_FS */
+
static ssize_t gpio_sim_sysfs_val_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -460,6 +484,7 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev)
gc->to_irq = gpio_sim_to_irq;
gc->request = gpio_sim_request;
gc->free = gpio_sim_free;
+ gc->dbg_show = gpio_sim_dbg_show;
gc->can_sleep = true;
ret = devm_gpiochip_add_data(dev, gc, chip);
--
2.40.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] gpio: sim: implement the dbg_show() callback
2023-11-30 10:40 [PATCH] gpio: sim: implement the dbg_show() callback Bartosz Golaszewski
@ 2023-11-30 13:37 ` Andy Shevchenko
2023-11-30 13:39 ` Andy Shevchenko
2023-11-30 14:08 ` Bartosz Golaszewski
0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2023-11-30 13:37 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Kent Gibson, linux-gpio, linux-kernel,
Bartosz Golaszewski
On Thu, Nov 30, 2023 at 11:40:23AM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> Provide a custom implementation of the dbg_show() callback that prints
> all requested lines together with their label, direction, value and
> bias. This improves the code coverage of GPIOLIB.
...
> +#else
> +#define gpio_sim_dbg_show NULL
> +#endif /* CONFIG_DEBUG_FS */
I;m wondering if you can use PTR_IF() instead of this ugly ifdeffery.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpio: sim: implement the dbg_show() callback
2023-11-30 13:37 ` Andy Shevchenko
@ 2023-11-30 13:39 ` Andy Shevchenko
2023-11-30 14:08 ` Bartosz Golaszewski
1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2023-11-30 13:39 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Kent Gibson, linux-gpio, linux-kernel,
Bartosz Golaszewski
On Thu, Nov 30, 2023 at 03:37:48PM +0200, Andy Shevchenko wrote:
> On Thu, Nov 30, 2023 at 11:40:23AM +0100, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
...
> > +#else
> > +#define gpio_sim_dbg_show NULL
> > +#endif /* CONFIG_DEBUG_FS */
>
> I;m wondering if you can use PTR_IF() instead of this ugly ifdeffery.
If brave enough, you can even propose a new macro like
#define debugfs_ptr(ptr) ...
(see pm_sleep_ptr() / pm_ptr() as examples).
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpio: sim: implement the dbg_show() callback
2023-11-30 13:37 ` Andy Shevchenko
2023-11-30 13:39 ` Andy Shevchenko
@ 2023-11-30 14:08 ` Bartosz Golaszewski
1 sibling, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2023-11-30 14:08 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Linus Walleij, Kent Gibson, linux-gpio, linux-kernel,
Bartosz Golaszewski
On Thu, Nov 30, 2023 at 2:37 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Thu, Nov 30, 2023 at 11:40:23AM +0100, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >
> > Provide a custom implementation of the dbg_show() callback that prints
> > all requested lines together with their label, direction, value and
> > bias. This improves the code coverage of GPIOLIB.
>
> ...
>
> > +#else
> > +#define gpio_sim_dbg_show NULL
> > +#endif /* CONFIG_DEBUG_FS */
>
> I;m wondering if you can use PTR_IF() instead of this ugly ifdeffery.
>
I wasn't aware of this. Thanks for bringing it to my attention, I'll use it.
Bart
> --
> With Best Regards,
> Andy Shevchenko
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-30 14:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-30 10:40 [PATCH] gpio: sim: implement the dbg_show() callback Bartosz Golaszewski
2023-11-30 13:37 ` Andy Shevchenko
2023-11-30 13:39 ` Andy Shevchenko
2023-11-30 14:08 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).