OF: gpio: convert DT based gpio handling to new OF API
This creates a Linux OF API compatible counterpart of of_get_named_gpio_flags. Existing of_get_named_gpio is converted to a static inline function, which is in the corresponding of_gpio.h include. While at it, drivers/of/gpio.c is also renamed to drivers/of/of_gpio.c to follow the of_ prefix naming scheme. The new include is also added to existing users of of_get_named_gpio. Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
483424e027
commit
61bb8bfc7c
|
@ -1,5 +1,5 @@
|
|||
obj-y += address.o base.o fdt.o platform.o
|
||||
obj-$(CONFIG_OFTREE_MEM_GENERIC) += mem_generic.o
|
||||
obj-$(CONFIG_GPIOLIB) += gpio.o
|
||||
obj-$(CONFIG_GPIOLIB) += of_gpio.o
|
||||
obj-y += partition.o
|
||||
obj-y += of_net.o
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
#define DEBUG
|
||||
|
||||
#include <common.h>
|
||||
#include <errno.h>
|
||||
#include <of.h>
|
||||
#include <gpio.h>
|
||||
|
||||
int of_get_named_gpio(struct device_node *np,
|
||||
const char *propname, int index)
|
||||
{
|
||||
int ret;
|
||||
struct of_phandle_args out_args;
|
||||
|
||||
ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
|
||||
index, &out_args);
|
||||
if (ret) {
|
||||
pr_debug("%s: can't parse gpios property: %d\n", __func__, ret);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = gpio_get_num(out_args.np->device, out_args.args[0]);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#include <common.h>
|
||||
#include <errno.h>
|
||||
#include <of.h>
|
||||
#include <of_gpio.h>
|
||||
#include <gpio.h>
|
||||
|
||||
/**
|
||||
* of_get_named_gpio_flags() - Get a GPIO number and flags to use with GPIO API
|
||||
* @np: device node to get GPIO from
|
||||
* @propname: property name containing gpio specifier(s)
|
||||
* @index: index of the GPIO
|
||||
* @flags: a flags pointer to fill in
|
||||
*
|
||||
* Returns GPIO number to use with GPIO API, or one of the errno value on the
|
||||
* error condition. If @flags is not NULL the function also fills in flags for
|
||||
* the GPIO.
|
||||
*/
|
||||
int of_get_named_gpio_flags(struct device_node *np, const char *propname,
|
||||
int index, enum of_gpio_flags *flags)
|
||||
{
|
||||
struct of_phandle_args out_args;
|
||||
struct device_d *dev;
|
||||
int ret;
|
||||
|
||||
ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
|
||||
index, &out_args);
|
||||
if (ret) {
|
||||
pr_err("%s: cannot parse %s property: %d\n",
|
||||
__func__, propname, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
dev = of_find_device_by_node(out_args.np);
|
||||
if (!dev) {
|
||||
pr_err("%s: unable to find device of node %s: %d\n",
|
||||
__func__, out_args.np->full_name, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = gpio_get_num(dev, out_args.args[0]);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: unable to get gpio num of device %s: %d\n",
|
||||
__func__, dev_name(dev), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (flags)
|
||||
*flags = out_args.args[1];
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(of_get_named_gpio_flags);
|
|
@ -23,6 +23,7 @@
|
|||
#include <errno.h>
|
||||
#include <malloc.h>
|
||||
#include <gpio.h>
|
||||
#include <of_gpio.h>
|
||||
#include <mach/spi.h>
|
||||
#include <mach/generic.h>
|
||||
#include <linux/clk.h>
|
||||
|
|
|
@ -96,9 +96,6 @@ static inline void of_write_number(void *__cell, u64 val, int size)
|
|||
}
|
||||
}
|
||||
|
||||
int of_get_named_gpio(struct device_node *np,
|
||||
const char *propname, int index);
|
||||
|
||||
void of_print_property(const void *data, int len);
|
||||
void of_print_cmdline(struct device_node *root);
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* OF helpers for the GPIO API
|
||||
*
|
||||
* based on Linux OF_GPIO API
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef __OF_GPIO_H
|
||||
#define __OF_GPIO_H
|
||||
|
||||
/*
|
||||
* This is Linux-specific flags. By default controllers' and Linux' mapping
|
||||
* match, but GPIO controllers are free to translate their own flags to
|
||||
* Linux-specific in their .xlate callback. Though, 1:1 mapping is recommended.
|
||||
*/
|
||||
enum of_gpio_flags {
|
||||
OF_GPIO_ACTIVE_LOW = 0x1,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_OFTREE
|
||||
extern int of_get_named_gpio_flags(struct device_node *np,
|
||||
const char *list_name, int index, enum of_gpio_flags *flags);
|
||||
|
||||
#else /* CONFIG_OFTREE */
|
||||
|
||||
static inline int of_get_named_gpio_flags(struct device_node *np,
|
||||
const char *list_name, int index, enum of_gpio_flags *flags)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_OFTREE */
|
||||
|
||||
static inline int of_get_named_gpio(struct device_node *np,
|
||||
const char *list_name, int index)
|
||||
{
|
||||
return of_get_named_gpio_flags(np, list_name, index, NULL);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue