mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-08 19:11:53 +00:00
dm: gpio: Add better functions to request GPIOs
At present U-Boot sort-of supports the standard way of reading GPIOs from device tree nodes, but the support is incomplete, a bit clunky and only works for GPIO bindings where #gpio-cells is 2. Add new functions to request GPIOs, taking full account of the device tree binding. These permit requesting a GPIO with a simple call like: gpio_request_by_name(dev, "cd-gpios", 0, &desc, GPIOD_IS_IN); This will request the GPIO, looking at the device's node which might be this, for example: cd-gpios = <&gpio TEGRA_GPIO(B, 3) GPIO_ACTIVE_LOW>; The GPIO will be set to input mode in this case and polarity will be honoured by the GPIO calls. It is also possible to request and free a list of GPIOs. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
0dac4d51f5
commit
3669e0e759
5 changed files with 461 additions and 4 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <fdtdec.h>
|
||||
#include <malloc.h>
|
||||
#include <asm/gpio.h>
|
||||
#include <dt-bindings/gpio/gpio.h>
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
|
@ -130,12 +131,31 @@ static int sb_gpio_get_function(struct udevice *dev, unsigned offset)
|
|||
return GPIOF_INPUT;
|
||||
}
|
||||
|
||||
static int sb_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
|
||||
struct fdtdec_phandle_args *args)
|
||||
{
|
||||
desc->offset = args->args[0];
|
||||
if (args->args_count < 2)
|
||||
return 0;
|
||||
if (args->args[1] & GPIO_ACTIVE_LOW)
|
||||
desc->flags |= GPIOD_ACTIVE_LOW;
|
||||
if (args->args[1] & 2)
|
||||
desc->flags |= GPIOD_IS_IN;
|
||||
if (args->args[1] & 4)
|
||||
desc->flags |= GPIOD_IS_OUT;
|
||||
if (args->args[1] & 8)
|
||||
desc->flags |= GPIOD_IS_OUT_ACTIVE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct dm_gpio_ops gpio_sandbox_ops = {
|
||||
.direction_input = sb_gpio_direction_input,
|
||||
.direction_output = sb_gpio_direction_output,
|
||||
.get_value = sb_gpio_get_value,
|
||||
.set_value = sb_gpio_set_value,
|
||||
.get_function = sb_gpio_get_function,
|
||||
.xlate = sb_gpio_xlate,
|
||||
};
|
||||
|
||||
static int sandbox_gpio_ofdata_to_platdata(struct udevice *dev)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue