linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
To: Linus Walleij <linus.walleij@linaro.org>,
	Alexandre Courbot <gnurou@gmail.com>,
	Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [PATCH v2 3/7] gpio: mockup: implement naming the lines
Date: Mon,  6 Feb 2017 13:10:37 +0100	[thread overview]
Message-ID: <1486383041-16758-4-git-send-email-bgolaszewski@baylibre.com> (raw)
In-Reply-To: <1486383041-16758-1-git-send-email-bgolaszewski@baylibre.com>

In order to allow testing line lookup by name from user space, add
a new boolean parameter that indicates whether we want the lines to
be named. The name is created by concatenating the chip name and the
line offset value.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/gpio/gpio-mockup.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index d425601..0ce9acc3 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -15,6 +15,7 @@
 #include <linux/module.h>
 #include <linux/gpio/driver.h>
 #include <linux/platform_device.h>
+#include <linux/slab.h>
 
 #define GPIO_MOCKUP_NAME	"gpio-mockup"
 #define	GPIO_MOCKUP_MAX_GC	10
@@ -43,6 +44,10 @@ static int gpio_mockup_ranges[GPIO_MOCKUP_MAX_GC << 1];
 static int gpio_mockup_params_nr;
 module_param_array(gpio_mockup_ranges, int, &gpio_mockup_params_nr, 0400);
 
+static bool gpio_mockup_named_lines;
+module_param_named(gpio_mockup_named_lines,
+		   gpio_mockup_named_lines, bool, 0400);
+
 static const char gpio_mockup_name_start = 'A';
 
 static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset)
@@ -87,11 +92,35 @@ static int gpio_mockup_get_direction(struct gpio_chip *gc, unsigned int offset)
 	return chip->lines[offset].dir;
 }
 
+static int gpio_mockup_name_lines(struct device *dev,
+				  struct gpio_mockup_chip *chip)
+{
+	struct gpio_chip *gc = &chip->gc;
+	char **names;
+	int i;
+
+	names = devm_kzalloc(dev, sizeof(char *) * gc->ngpio, GFP_KERNEL);
+	if (!names)
+		return -ENOMEM;
+
+	for (i = 0; i < gc->ngpio; i++) {
+		names[i] = devm_kasprintf(dev, GFP_KERNEL,
+					  "%s-%d", gc->label, i);
+		if (!names[i])
+			return -ENOMEM;
+	}
+
+	gc->names = (const char *const *)names;
+
+	return 0;
+}
+
 static int gpio_mockup_add(struct device *dev,
 			   struct gpio_mockup_chip *chip,
 			   const char *name, int base, int ngpio)
 {
 	struct gpio_chip *gc = &chip->gc;
+	int ret;
 
 	gc->base = base;
 	gc->ngpio = ngpio;
@@ -109,6 +138,12 @@ static int gpio_mockup_add(struct device *dev,
 	if (!chip->lines)
 		return -ENOMEM;
 
+	if (gpio_mockup_named_lines) {
+		ret = gpio_mockup_name_lines(dev, chip);
+		if (ret)
+			return ret;
+	}
+
 	return devm_gpiochip_add_data(dev, &chip->gc, chip);
 }
 
-- 
2.9.3

  parent reply	other threads:[~2017-02-06 12:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-06 12:10 [PATCH v2 0/7] gpio: mockup: extensions for testing purposes Bartosz Golaszewski
2017-02-06 12:10 ` [PATCH v2 1/7] gpio: mockup: readability tweaks Bartosz Golaszewski
2017-02-06 13:20   ` Linus Walleij
2017-02-06 12:10 ` [PATCH v2 2/7] gpio: mockup: code shrink Bartosz Golaszewski
2017-02-06 13:21   ` Linus Walleij
2017-02-06 12:10 ` Bartosz Golaszewski [this message]
2017-02-06 13:22   ` [PATCH v2 3/7] gpio: mockup: implement naming the lines Linus Walleij
2017-02-06 12:10 ` [PATCH v2 4/7] irqdesc: add memory managed version of irq_alloc_descs() Bartosz Golaszewski
2017-02-06 13:26   ` Linus Walleij
2017-02-06 12:10 ` [PATCH v2 5/7] gpio: mockup: add a dummy irqchip Bartosz Golaszewski
2017-02-06 13:29   ` Linus Walleij
2017-02-06 13:31     ` Bartosz Golaszewski
2017-02-06 13:41       ` Linus Walleij
2017-02-06 12:10 ` [PATCH v2 6/7] gpiolib: include <gpio/consumer.h> from gpiolib.h Bartosz Golaszewski
2017-02-06 13:30   ` Linus Walleij
2017-02-06 12:10 ` [PATCH v2 7/7] gpio: mockup: implement event injecting over debugfs Bartosz Golaszewski
2017-02-06 12:12 ` [PATCH v2 0/7] gpio: mockup: extensions for testing purposes Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1486383041-16758-4-git-send-email-bgolaszewski@baylibre.com \
    --to=bgolaszewski@baylibre.com \
    --cc=bamvor.zhangjian@linaro.org \
    --cc=gnurou@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).