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>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [PATCH 6/7] gpio: mockup: implement naming the GPIO lines
Date: Wed, 25 Jan 2017 16:34:20 +0100	[thread overview]
Message-ID: <1485358461-24070-7-git-send-email-bgolaszewski@baylibre.com> (raw)
In-Reply-To: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com>

Implement a new boolean module argument that indicates that the mockup
lines should be named. The names are created by appending the line
offset to the chip label.

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

diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index c5eb530..dabf3ec 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -17,6 +17,7 @@
 #include <linux/platform_device.h>
 #include <linux/debugfs.h>
 #include <linux/uaccess.h>
+#include <linux/slab.h>
 
 #include "gpiolib.h"
 
@@ -48,6 +49,10 @@ static int gpio_mockup_ranges[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 pins_name_start = 'A';
 static struct dentry *dbg_dir;
 
@@ -169,7 +174,8 @@ static int mockup_gpio_add(struct device *dev,
 			   struct mockup_gpio_controller *cntr,
 			   const char *name, int base, int ngpio)
 {
-	int ret;
+	char **names;
+	int ret, i;
 
 	cntr->gc.base = base;
 	cntr->gc.ngpio = ngpio;
@@ -188,6 +194,28 @@ static int mockup_gpio_add(struct device *dev,
 		ret = -ENOMEM;
 		goto err;
 	}
+
+	if (gpio_mockup_named_lines) {
+		names = devm_kzalloc(dev,
+				     sizeof(char *) * cntr->gc.ngpio,
+				     GFP_KERNEL);
+		if (!names) {
+			ret = -ENOMEM;
+			goto err;
+		}
+
+		for (i = 0; i < cntr->gc.ngpio; i++) {
+			names[i] = devm_kasprintf(dev, GFP_KERNEL,
+						  "%s-%d", cntr->gc.label, i);
+			if (!names[i]) {
+				ret = -ENOMEM;
+				goto err;
+			}
+		}
+
+		cntr->gc.names = (const char *const*)names;
+	}
+
 	ret = devm_gpiochip_add_data(dev, &cntr->gc, cntr);
 	if (ret)
 		goto err;
-- 
2.9.3


  parent reply	other threads:[~2017-01-25 15:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-25 15:34 [PATCH 0/7] gpio: mockup: extensions for testing purposes Bartosz Golaszewski
2017-01-25 15:34 ` [PATCH 1/7] gpiolib: clean up includes Bartosz Golaszewski
2017-01-31 13:20   ` Linus Walleij
2017-01-25 15:34 ` [PATCH 2/7] gpiolib: support monitoring mockup devices Bartosz Golaszewski
2017-01-31 13:23   ` Linus Walleij
2017-01-25 15:34 ` [PATCH 3/7] gpio: mockup: set the mockup flag in struct gpio_chip Bartosz Golaszewski
2017-01-25 15:34 ` [PATCH 4/7] gpiolib: allow injecting line events Bartosz Golaszewski
2017-01-31 13:24   ` Linus Walleij
2017-01-25 15:34 ` [PATCH 5/7] gpio: mockup: implement injecting events over debugfs Bartosz Golaszewski
2017-01-25 15:34 ` Bartosz Golaszewski [this message]
2017-01-25 15:34 ` [PATCH 7/7] gpio: mockup: readability tweaks Bartosz Golaszewski
2017-01-31 13:28 ` [PATCH 0/7] gpio: mockup: extensions for testing purposes Linus Walleij
2017-01-31 14:05   ` Bartosz Golaszewski
2017-01-31 14:11     ` Lars-Peter Clausen
2017-01-31 14:21       ` 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=1485358461-24070-7-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 \
    /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).