summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/gpio/gpiolib-of.c23
-rw-r--r--drivers/gpio/gpiolib.c8
-rw-r--r--drivers/pinctrl/devicetree.c4
-rw-r--r--include/asm-generic/gpio.h4
-rw-r--r--include/linux/gpio.h2
-rw-r--r--include/linux/pinctrl/pinctrl.h7
6 files changed, 20 insertions, 28 deletions
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 67403e47e4dc..a40cd84c5c10 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -221,8 +221,8 @@ EXPORT_SYMBOL(of_mm_gpiochip_add);
static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
{
struct device_node *np = chip->of_node;
- struct gpio_pin_range *pin_range;
struct of_phandle_args pinspec;
+ struct pinctrl_dev *pctldev;
int index = 0, ret;
if (!np)
@@ -234,22 +234,17 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
if (ret)
break;
- pin_range = devm_kzalloc(chip->dev, sizeof(*pin_range),
- GFP_KERNEL);
- if (!pin_range) {
- pr_err("%s: GPIO chip: failed to allocate pin ranges\n",
- chip->label);
+ pctldev = of_pinctrl_get(pinspec.np);
+ if (!pctldev)
break;
- }
- pin_range->range.name = chip->label;
- pin_range->range.base = chip->base;
- pin_range->range.pin_base = pinspec.args[0];
- pin_range->range.npins = pinspec.args[1];
- pin_range->pctldev = of_pinctrl_add_gpio_range(pinspec.np,
- &pin_range->range);
+ ret = gpiochip_add_pin_range(chip,
+ pinctrl_dev_get_name(pctldev),
+ pinspec.args[0],
+ pinspec.args[1]);
- list_add_tail(&pin_range->node, &chip->pin_ranges);
+ if (ret)
+ break;
} while (index++);
}
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index bcf9b9914fb7..c5f650095faa 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1187,8 +1187,8 @@ EXPORT_SYMBOL_GPL(gpiochip_find);
#ifdef CONFIG_PINCTRL
-void gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
- unsigned int pin_base, unsigned int npins)
+int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
+ unsigned int pin_base, unsigned int npins)
{
struct gpio_pin_range *pin_range;
@@ -1196,7 +1196,7 @@ void gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
if (!pin_range) {
pr_err("%s: GPIO chip: failed to allocate pin ranges\n",
chip->label);
- return;
+ return -ENOMEM;
}
pin_range->range.name = chip->label;
@@ -1207,6 +1207,8 @@ void gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
&pin_range->range);
list_add_tail(&pin_range->node, &chip->pin_ranges);
+
+ return 0;
}
EXPORT_SYMBOL_GPL(gpiochip_add_pin_range);
diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c
index 6728ec71cb65..fe2d1af7cfa0 100644
--- a/drivers/pinctrl/devicetree.c
+++ b/drivers/pinctrl/devicetree.c
@@ -106,8 +106,7 @@ static struct pinctrl_dev *find_pinctrl_by_of_node(struct device_node *np)
return NULL;
}
-struct pinctrl_dev *of_pinctrl_add_gpio_range(struct device_node *np,
- struct pinctrl_gpio_range *range)
+struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
{
struct pinctrl_dev *pctldev;
@@ -115,7 +114,6 @@ struct pinctrl_dev *of_pinctrl_add_gpio_range(struct device_node *np,
if (!pctldev)
return NULL;
- pinctrl_add_gpio_range(pctldev, range);
return pctldev;
}
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 2e60de4265ac..50d995e7e44a 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -63,8 +63,8 @@ struct gpio_pin_range {
struct pinctrl_gpio_range range;
};
-void gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
- unsigned int pin_base, unsigned int npins);
+int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
+ unsigned int pin_base, unsigned int npins);
void gpiochip_remove_pin_ranges(struct gpio_chip *chip);
#endif
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index 21d28b930dc7..81bbfe5b5de6 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -233,7 +233,7 @@ static inline int irq_to_gpio(unsigned irq)
#ifdef CONFIG_PINCTRL
-static inline void
+static inline int
gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
unsigned int pin_base, unsigned int npins)
{
diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h
index 434e5a94e131..4a58428bc793 100644
--- a/include/linux/pinctrl/pinctrl.h
+++ b/include/linux/pinctrl/pinctrl.h
@@ -141,16 +141,13 @@ extern struct pinctrl_dev *find_pinctrl_and_add_gpio_range(const char *devname,
struct pinctrl_gpio_range *range);
#ifdef CONFIG_OF
-extern struct pinctrl_dev *of_pinctrl_add_gpio_range(struct device_node *np,
- struct pinctrl_gpio_range *range);
+extern struct pinctrl_dev *of_pinctrl_get(struct device_node *np);
#else
static inline
-struct pinctrl_dev *of_pinctrl_add_gpio_range(struct device_node *np,
- struct pinctrl_gpio_range *range)
+struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
{
return NULL;
}
-
#endif /* CONFIG_OF */
extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev);