Commit 8a68ea00 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski Committed by Linus Walleij

gpio: mockup: implement naming the lines

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: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent e4ba07bf
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/gpio/driver.h> #include <linux/gpio/driver.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/slab.h>
#define GPIO_MOCKUP_NAME "gpio-mockup" #define GPIO_MOCKUP_NAME "gpio-mockup"
#define GPIO_MOCKUP_MAX_GC 10 #define GPIO_MOCKUP_MAX_GC 10
...@@ -43,6 +44,10 @@ static int gpio_mockup_ranges[GPIO_MOCKUP_MAX_GC << 1]; ...@@ -43,6 +44,10 @@ static int gpio_mockup_ranges[GPIO_MOCKUP_MAX_GC << 1];
static int gpio_mockup_params_nr; static int gpio_mockup_params_nr;
module_param_array(gpio_mockup_ranges, int, &gpio_mockup_params_nr, 0400); 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 const char gpio_mockup_name_start = 'A';
static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) 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) ...@@ -87,11 +92,35 @@ static int gpio_mockup_get_direction(struct gpio_chip *gc, unsigned int offset)
return chip->lines[offset].dir; 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, static int gpio_mockup_add(struct device *dev,
struct gpio_mockup_chip *chip, struct gpio_mockup_chip *chip,
const char *name, int base, int ngpio) const char *name, int base, int ngpio)
{ {
struct gpio_chip *gc = &chip->gc; struct gpio_chip *gc = &chip->gc;
int ret;
gc->base = base; gc->base = base;
gc->ngpio = ngpio; gc->ngpio = ngpio;
...@@ -109,6 +138,12 @@ static int gpio_mockup_add(struct device *dev, ...@@ -109,6 +138,12 @@ static int gpio_mockup_add(struct device *dev,
if (!chip->lines) if (!chip->lines)
return -ENOMEM; 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); return devm_gpiochip_add_data(dev, &chip->gc, chip);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment