* [PATCH 2/5] gpio: mockup: remove unused field
2023-09-07 14:52 [PATCH 1/5] gpio: mockup: fix kerneldoc Bartosz Golaszewski
@ 2023-09-07 14:52 ` Bartosz Golaszewski
2023-09-07 14:52 ` [PATCH 3/5] gpio: mockup: deprecate the old testing module Bartosz Golaszewski
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2023-09-07 14:52 UTC (permalink / raw)
To: Linus Walleij, Andy Shevchenko, Kent Gibson
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
The desc assigned to debugfs private structure is unused so remove it.
Fixes: 9202ba2397d1 ("gpio: mockup: implement event injecting over debugfs")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/gpio-mockup.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index 17d4d48524b7..ff1a263f1b05 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -58,7 +58,6 @@ struct gpio_mockup_chip {
struct gpio_mockup_dbgfs_private {
struct gpio_mockup_chip *chip;
- struct gpio_desc *desc;
unsigned int offset;
};
@@ -369,7 +368,6 @@ static void gpio_mockup_debugfs_setup(struct device *dev,
priv->chip = chip;
priv->offset = i;
- priv->desc = gpiochip_get_desc(gc, i);
debugfs_create_file(name, 0600, chip->dbg_dir, priv,
&gpio_mockup_debugfs_ops);
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 3/5] gpio: mockup: deprecate the old testing module
2023-09-07 14:52 [PATCH 1/5] gpio: mockup: fix kerneldoc Bartosz Golaszewski
2023-09-07 14:52 ` [PATCH 2/5] gpio: mockup: remove unused field Bartosz Golaszewski
@ 2023-09-07 14:52 ` Bartosz Golaszewski
2023-09-07 14:52 ` [PATCH 4/5] gpio: mockup: simplify code by using cleanup helpers Bartosz Golaszewski
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2023-09-07 14:52 UTC (permalink / raw)
To: Linus Walleij, Andy Shevchenko, Kent Gibson
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
We have a much better alternative to the clunky old gpio-mockup. Don't
remove it just yet (there are tests depending on it out there) but make
Kconfig say that it should no longer be used in new projects.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/Kconfig | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 673bafb8be58..913948876c93 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1790,9 +1790,11 @@ config GPIO_LATCH
connected to other GPIOs.
config GPIO_MOCKUP
- tristate "GPIO Testing Driver"
+ tristate "GPIO Testing Driver (DEPRECATED)"
select IRQ_SIM
help
+ This module is DEPRECATED. Please consider using gpio-sim instead.
+
This enables GPIO Testing driver, which provides a way to test GPIO
subsystem through sysfs (or char device) and debugfs.
User could use it through the script in
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 4/5] gpio: mockup: simplify code by using cleanup helpers
2023-09-07 14:52 [PATCH 1/5] gpio: mockup: fix kerneldoc Bartosz Golaszewski
2023-09-07 14:52 ` [PATCH 2/5] gpio: mockup: remove unused field Bartosz Golaszewski
2023-09-07 14:52 ` [PATCH 3/5] gpio: mockup: deprecate the old testing module Bartosz Golaszewski
@ 2023-09-07 14:52 ` Bartosz Golaszewski
2023-09-07 14:52 ` [PATCH 5/5] gpio: mockup: don't access internal GPIOLIB structures Bartosz Golaszewski
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2023-09-07 14:52 UTC (permalink / raw)
To: Linus Walleij, Andy Shevchenko, Kent Gibson
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Use lock from linux/cleanup.h and simplify locking paths.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/gpio-mockup.c | 45 ++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index ff1a263f1b05..44684ff4462f 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -9,6 +9,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/cleanup.h>
#include <linux/debugfs.h>
#include <linux/gpio/driver.h>
#include <linux/interrupt.h>
@@ -92,9 +93,8 @@ static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset)
struct gpio_mockup_chip *chip = gpiochip_get_data(gc);
int val;
- mutex_lock(&chip->lock);
- val = __gpio_mockup_get(chip, offset);
- mutex_unlock(&chip->lock);
+ scoped_guard(mutex, &chip->lock)
+ val = __gpio_mockup_get(chip, offset);
return val;
}
@@ -105,12 +105,12 @@ static int gpio_mockup_get_multiple(struct gpio_chip *gc,
struct gpio_mockup_chip *chip = gpiochip_get_data(gc);
unsigned int bit, val;
- mutex_lock(&chip->lock);
- for_each_set_bit(bit, mask, gc->ngpio) {
- val = __gpio_mockup_get(chip, bit);
- __assign_bit(bit, bits, val);
+ scoped_guard(mutex, &chip->lock) {
+ for_each_set_bit(bit, mask, gc->ngpio) {
+ val = __gpio_mockup_get(chip, bit);
+ __assign_bit(bit, bits, val);
+ }
}
- mutex_unlock(&chip->lock);
return 0;
}
@@ -126,9 +126,9 @@ static void gpio_mockup_set(struct gpio_chip *gc,
{
struct gpio_mockup_chip *chip = gpiochip_get_data(gc);
- mutex_lock(&chip->lock);
+ guard(mutex)(&chip->lock);
+
__gpio_mockup_set(chip, offset, value);
- mutex_unlock(&chip->lock);
}
static void gpio_mockup_set_multiple(struct gpio_chip *gc,
@@ -137,10 +137,10 @@ static void gpio_mockup_set_multiple(struct gpio_chip *gc,
struct gpio_mockup_chip *chip = gpiochip_get_data(gc);
unsigned int bit;
- mutex_lock(&chip->lock);
+ guard(mutex)(&chip->lock);
+
for_each_set_bit(bit, mask, gc->ngpio)
__gpio_mockup_set(chip, bit, test_bit(bit, bits));
- mutex_unlock(&chip->lock);
}
static int gpio_mockup_apply_pull(struct gpio_mockup_chip *chip,
@@ -150,7 +150,7 @@ static int gpio_mockup_apply_pull(struct gpio_mockup_chip *chip,
struct gpio_desc *desc = gpiochip_get_desc(gc, offset);
int curr, irq, irq_type, ret = 0;
- mutex_lock(&chip->lock);
+ guard(mutex)(&chip->lock);
if (test_bit(FLAG_REQUESTED, &desc->flags) &&
!test_bit(FLAG_IS_OUT, &desc->flags)) {
@@ -187,7 +187,6 @@ static int gpio_mockup_apply_pull(struct gpio_mockup_chip *chip,
out:
chip->lines[offset].pull = value;
- mutex_unlock(&chip->lock);
return ret;
}
@@ -212,10 +211,10 @@ static int gpio_mockup_dirout(struct gpio_chip *gc,
{
struct gpio_mockup_chip *chip = gpiochip_get_data(gc);
- mutex_lock(&chip->lock);
- chip->lines[offset].dir = GPIO_LINE_DIRECTION_OUT;
- __gpio_mockup_set(chip, offset, value);
- mutex_unlock(&chip->lock);
+ scoped_guard(mutex, &chip->lock) {
+ chip->lines[offset].dir = GPIO_LINE_DIRECTION_OUT;
+ __gpio_mockup_set(chip, offset, value);
+ }
return 0;
}
@@ -224,9 +223,8 @@ static int gpio_mockup_dirin(struct gpio_chip *gc, unsigned int offset)
{
struct gpio_mockup_chip *chip = gpiochip_get_data(gc);
- mutex_lock(&chip->lock);
- chip->lines[offset].dir = GPIO_LINE_DIRECTION_IN;
- mutex_unlock(&chip->lock);
+ scoped_guard(mutex, &chip->lock)
+ chip->lines[offset].dir = GPIO_LINE_DIRECTION_IN;
return 0;
}
@@ -236,9 +234,8 @@ static int gpio_mockup_get_direction(struct gpio_chip *gc, unsigned int offset)
struct gpio_mockup_chip *chip = gpiochip_get_data(gc);
int direction;
- mutex_lock(&chip->lock);
- direction = chip->lines[offset].dir;
- mutex_unlock(&chip->lock);
+ scoped_guard(mutex, &chip->lock)
+ direction = chip->lines[offset].dir;
return direction;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 5/5] gpio: mockup: don't access internal GPIOLIB structures
2023-09-07 14:52 [PATCH 1/5] gpio: mockup: fix kerneldoc Bartosz Golaszewski
` (2 preceding siblings ...)
2023-09-07 14:52 ` [PATCH 4/5] gpio: mockup: simplify code by using cleanup helpers Bartosz Golaszewski
@ 2023-09-07 14:52 ` Bartosz Golaszewski
2023-09-07 15:48 ` [PATCH 1/5] gpio: mockup: fix kerneldoc Andy Shevchenko
2023-09-11 8:30 ` Linus Walleij
5 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2023-09-07 14:52 UTC (permalink / raw)
To: Linus Walleij, Andy Shevchenko, Kent Gibson
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Don't include gpiolib.h. Track the request status of lines locally
instead. In order to retrieve the device name use the fact that
gpio-mockup supports only a single GPIO device per platform device and
call device_find_any_child().
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/gpio-mockup.c | 39 +++++++++++++++++++++++++++++---------
1 file changed, 30 insertions(+), 9 deletions(-)
diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index 44684ff4462f..4870e267a402 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -11,6 +11,7 @@
#include <linux/cleanup.h>
#include <linux/debugfs.h>
+#include <linux/device.h>
#include <linux/gpio/driver.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
@@ -25,8 +26,6 @@
#include <linux/string_helpers.h>
#include <linux/uaccess.h>
-#include "gpiolib.h"
-
#define GPIO_MOCKUP_MAX_GC 10
/*
* We're storing two values per chip: the GPIO base and the number
@@ -42,11 +41,13 @@
* @value: Configures status of the gpio as 0(low) or 1(high)
* @pull: Configures the current pull of the GPIO as 0 (pull-down) or
* 1 (pull-up)
+ * @requested: Request status of this GPIO
*/
struct gpio_mockup_line_status {
int dir;
int value;
int pull;
+ bool requested;
};
struct gpio_mockup_chip {
@@ -146,14 +147,12 @@ static void gpio_mockup_set_multiple(struct gpio_chip *gc,
static int gpio_mockup_apply_pull(struct gpio_mockup_chip *chip,
unsigned int offset, int value)
{
- struct gpio_chip *gc = &chip->gc;
- struct gpio_desc *desc = gpiochip_get_desc(gc, offset);
+ struct gpio_mockup_line_status *line = &chip->lines[offset];
int curr, irq, irq_type, ret = 0;
guard(mutex)(&chip->lock);
- if (test_bit(FLAG_REQUESTED, &desc->flags) &&
- !test_bit(FLAG_IS_OUT, &desc->flags)) {
+ if (line->requested && line->dir == GPIO_LINE_DIRECTION_IN) {
curr = __gpio_mockup_get(chip, offset);
if (curr == value)
goto out;
@@ -181,8 +180,7 @@ static int gpio_mockup_apply_pull(struct gpio_mockup_chip *chip,
set_value:
/* Change the value unless we're actively driving the line. */
- if (!test_bit(FLAG_REQUESTED, &desc->flags) ||
- !test_bit(FLAG_IS_OUT, &desc->flags))
+ if (!line->requested || line->dir == GPIO_LINE_DIRECTION_IN)
__gpio_mockup_set(chip, offset, value);
out:
@@ -247,10 +245,23 @@ static int gpio_mockup_to_irq(struct gpio_chip *gc, unsigned int offset)
return irq_create_mapping(chip->irq_sim_domain, offset);
}
+static int gpio_mockup_request(struct gpio_chip *gc, unsigned int offset)
+{
+ struct gpio_mockup_chip *chip = gpiochip_get_data(gc);
+
+ scoped_guard(mutex, &chip->lock)
+ chip->lines[offset].requested = true;
+
+ return 0;
+}
+
static void gpio_mockup_free(struct gpio_chip *gc, unsigned int offset)
{
struct gpio_mockup_chip *chip = gpiochip_get_data(gc);
+ guard(mutex)(&chip->lock);
+
+ chip->lines[offset].requested = false;
__gpio_mockup_set(chip, offset, chip->lines[offset].pull);
}
@@ -343,6 +354,7 @@ static const struct file_operations gpio_mockup_debugfs_ops = {
static void gpio_mockup_debugfs_setup(struct device *dev,
struct gpio_mockup_chip *chip)
{
+ struct device *child __free(put_device) = NULL;
struct gpio_mockup_dbgfs_private *priv;
struct gpio_chip *gc;
const char *devname;
@@ -350,8 +362,16 @@ static void gpio_mockup_debugfs_setup(struct device *dev,
int i;
gc = &chip->gc;
- devname = dev_name(&gc->gpiodev->dev);
+ /*
+ * There can only be a single GPIO device per platform device in
+ * gpio-mockup so using device_find_any_child() is OK.
+ */
+ child = device_find_any_child(dev);
+ if (!child)
+ return;
+
+ devname = dev_name(child);
chip->dbg_dir = debugfs_create_dir(devname, gpio_mockup_dbg_dir);
for (i = 0; i < gc->ngpio; i++) {
@@ -435,6 +455,7 @@ static int gpio_mockup_probe(struct platform_device *pdev)
gc->get_direction = gpio_mockup_get_direction;
gc->set_config = gpio_mockup_set_config;
gc->to_irq = gpio_mockup_to_irq;
+ gc->request = gpio_mockup_request;
gc->free = gpio_mockup_free;
chip->lines = devm_kcalloc(dev, gc->ngpio,
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 1/5] gpio: mockup: fix kerneldoc
2023-09-07 14:52 [PATCH 1/5] gpio: mockup: fix kerneldoc Bartosz Golaszewski
` (3 preceding siblings ...)
2023-09-07 14:52 ` [PATCH 5/5] gpio: mockup: don't access internal GPIOLIB structures Bartosz Golaszewski
@ 2023-09-07 15:48 ` Andy Shevchenko
2023-09-11 8:30 ` Linus Walleij
5 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-09-07 15:48 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Kent Gibson, linux-gpio, linux-kernel,
Bartosz Golaszewski
On Thu, Sep 07, 2023 at 04:52:26PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> The pull field of the line state struct is undocumented. Fix it.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
for the entire series.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 1/5] gpio: mockup: fix kerneldoc
2023-09-07 14:52 [PATCH 1/5] gpio: mockup: fix kerneldoc Bartosz Golaszewski
` (4 preceding siblings ...)
2023-09-07 15:48 ` [PATCH 1/5] gpio: mockup: fix kerneldoc Andy Shevchenko
@ 2023-09-11 8:30 ` Linus Walleij
5 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2023-09-11 8:30 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Andy Shevchenko, Kent Gibson, linux-gpio, linux-kernel,
Bartosz Golaszewski
On Thu, Sep 7, 2023 at 4:52 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> The pull field of the line state struct is undocumented. Fix it.
>
> Fixes: 2a9e27408e12 ("gpio: mockup: rework debugfs interface")
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
For the whole series.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread