fdt_pinctrl: Add new methods for gpios

Most of the gpio controller cannot configure or get the configuration
of the pin muxing as it's usually handled in the pinctrl driver.
But they can know what is the pinmuxing driver either because they are
child of it or via the gpio-range property.
Add some new methods to fdt_pinctrl that a pin controller can implement.
Some methods are :
fdt_pinctrl_is_gpio: Use to know if the pin in the gpio mode
fdt_pinctrl_set_flags: Set the flags of the pin (pullup/pulldown etc ...)
fdt_pinctrl_get_flags: Get the flags of the pin (pullup/pulldown etc ...)

The defaults method returns EOPNOTSUPP.

Reviewed by:	ian, bcr (manpages)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D23093
This commit is contained in:
manu 2020-01-16 21:19:27 +00:00
parent 2ebd9abd2c
commit c51fd0618d
2 changed files with 91 additions and 0 deletions

View File

@ -124,6 +124,36 @@ foo_configure_pins(device_t dev, phandle_t cfgxref)
...
}
static int
foo_is_gpio(device_t dev, device_t gpiodev, bool *is_gpio)
{
return (foo_is_pin_func_gpio(is_gpio));
}
static int
foo_set_flags(device_t dev, device_t gpiodev, uint32_t pin, uint32_t flags)
{
int rv;
rv = foo_is_pin_func_gpio(is_gpio);
if (rv != 0)
return (rv);
foo_set_flags(pin, flags);
return (0);
}
static int
foo_get_flags(device_t dev, device_t gpiodev, uint32_t pin, uint32_t *flags)
{
int rv;
rv = foo_is_pin_func_gpio(is_gpio);
if (rv != 0)
return (rv);
foo_get_flags(pin, flags);
return (0);
}
static int
foo_attach(device_t dev)
{
@ -144,6 +174,9 @@ static device_method_t foo_methods[] = {
/* fdt_pinctrl interface */
DEVMETHOD(fdt_pinctrl_configure, foo_configure_pins),
DEVMETHOD(fdt_pinctrl_is_gpio, foo_is_gpio),
DEVMETHOD(fdt_pinctrl_set_flags, foo_set_flags),
DEVMETHOD(fdt_pinctrl_get_flags, foo_get_flags),
/* Terminate method list */
DEVMETHOD_END

View File

@ -36,6 +36,31 @@
INTERFACE fdt_pinctrl;
CODE {
static int
fdt_pinctrl_default_is_gpio(device_t pinctrl, device_t gpio, bool *is_gpio)
{
return (EOPNOTSUPP);
}
static int
fdt_pinctrl_default_set_flags(device_t pinctrl, device_t gpio, uint32_t pin,
uint32_t flags)
{
return (EOPNOTSUPP);
}
static int
fdt_pinctrl_default_get_flags(device_t pinctrl, device_t gpio, uint32_t pin,
uint32_t *flags)
{
return (EOPNOTSUPP);
}
};
# Needed for timestamping device probe/attach calls
HEADER {
#include <sys/tslog.h>
@ -57,3 +82,36 @@ METHOD int configure {
phandle_t cfgxref;
};
#
# Test if the pin is in gpio mode
# Called from a gpio device
#
METHOD int is_gpio {
device_t pinctrl;
device_t gpio;
uint32_t pin;
bool *is_gpio;
} DEFAULT fdt_pinctrl_default_is_gpio;
#
# Set the flags of a pin
# Called from a gpio device
#
METHOD int set_flags {
device_t pinctrl;
device_t gpio;
uint32_t pin;
uint32_t flags;
} DEFAULT fdt_pinctrl_default_set_flags;
#
# Get the flags of a pin
# Called from a gpio device
#
METHOD int get_flags {
device_t pinctrl;
device_t gpio;
uint32_t pin;
uint32_t *flags;
} DEFAULT fdt_pinctrl_default_get_flags;