2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-02-15 23:51:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 The Chromium OS Authors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2014-02-26 22:59:25 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <fdtdec.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2014-02-26 22:59:25 +00:00
|
|
|
#include <malloc.h>
|
2020-07-07 19:11:44 +00:00
|
|
|
#include <acpi/acpi_device.h>
|
2012-02-15 23:51:13 +00:00
|
|
|
#include <asm/gpio.h>
|
2020-07-07 19:11:44 +00:00
|
|
|
#include <dm/acpi.h>
|
2020-01-13 10:35:15 +00:00
|
|
|
#include <dm/device_compat.h>
|
2020-01-13 10:35:14 +00:00
|
|
|
#include <dm/lists.h>
|
2017-05-19 02:09:18 +00:00
|
|
|
#include <dm/of.h>
|
2020-01-13 10:35:14 +00:00
|
|
|
#include <dm/pinctrl.h>
|
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>
2015-01-06 03:05:29 +00:00
|
|
|
#include <dt-bindings/gpio/gpio.h>
|
2020-01-13 10:35:13 +00:00
|
|
|
#include <dt-bindings/gpio/sandbox-gpio.h>
|
2012-02-15 23:51:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct gpio_state {
|
|
|
|
const char *label; /* label given by requester */
|
2020-01-13 10:35:14 +00:00
|
|
|
ulong dir_flags; /* dir_flags (GPIOD_...) */
|
2012-02-15 23:51:13 +00:00
|
|
|
};
|
|
|
|
|
2020-01-13 10:35:14 +00:00
|
|
|
/* Access routines for GPIO dir flags */
|
|
|
|
static ulong *get_gpio_dir_flags(struct udevice *dev, unsigned int offset)
|
2012-02-15 23:51:13 +00:00
|
|
|
{
|
2015-03-05 19:25:20 +00:00
|
|
|
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
|
2014-02-26 22:59:25 +00:00
|
|
|
struct gpio_state *state = dev_get_priv(dev);
|
|
|
|
|
|
|
|
if (offset >= uc_priv->gpio_count) {
|
2020-01-13 10:35:14 +00:00
|
|
|
static ulong invalid_dir_flags;
|
2014-02-26 22:59:25 +00:00
|
|
|
printf("sandbox_gpio: error: invalid gpio %u\n", offset);
|
2020-01-13 10:35:14 +00:00
|
|
|
return &invalid_dir_flags;
|
2012-02-15 23:51:13 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 10:35:14 +00:00
|
|
|
return &state[offset].dir_flags;
|
|
|
|
|
2012-02-15 23:51:13 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 10:35:14 +00:00
|
|
|
static int get_gpio_flag(struct udevice *dev, unsigned int offset, ulong flag)
|
2012-02-15 23:51:13 +00:00
|
|
|
{
|
2020-01-13 10:35:14 +00:00
|
|
|
return (*get_gpio_dir_flags(dev, offset) & flag) != 0;
|
2012-02-15 23:51:13 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 10:35:14 +00:00
|
|
|
static int set_gpio_flag(struct udevice *dev, unsigned int offset, ulong flag,
|
2014-02-26 22:59:25 +00:00
|
|
|
int value)
|
2012-02-15 23:51:13 +00:00
|
|
|
{
|
2020-01-13 10:35:14 +00:00
|
|
|
ulong *gpio = get_gpio_dir_flags(dev, offset);
|
2012-02-15 23:51:13 +00:00
|
|
|
|
|
|
|
if (value)
|
|
|
|
*gpio |= flag;
|
|
|
|
else
|
|
|
|
*gpio &= ~flag;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Back-channel sandbox-internal-only access to GPIO state
|
|
|
|
*/
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
int sandbox_gpio_get_value(struct udevice *dev, unsigned offset)
|
2012-02-15 23:51:13 +00:00
|
|
|
{
|
2020-01-13 10:35:14 +00:00
|
|
|
if (get_gpio_flag(dev, offset, GPIOD_IS_OUT))
|
2014-02-26 22:59:25 +00:00
|
|
|
debug("sandbox_gpio: get_value on output gpio %u\n", offset);
|
2020-01-13 10:35:14 +00:00
|
|
|
return get_gpio_flag(dev, offset, GPIOD_IS_OUT_ACTIVE);
|
2012-02-15 23:51:13 +00:00
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
int sandbox_gpio_set_value(struct udevice *dev, unsigned offset, int value)
|
2012-02-15 23:51:13 +00:00
|
|
|
{
|
2020-01-13 10:35:14 +00:00
|
|
|
return set_gpio_flag(dev, offset, GPIOD_IS_OUT_ACTIVE, value);
|
2012-02-15 23:51:13 +00:00
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
int sandbox_gpio_get_direction(struct udevice *dev, unsigned offset)
|
2012-02-15 23:51:13 +00:00
|
|
|
{
|
2020-01-13 10:35:14 +00:00
|
|
|
return get_gpio_flag(dev, offset, GPIOD_IS_OUT);
|
2012-02-15 23:51:13 +00:00
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
int sandbox_gpio_set_direction(struct udevice *dev, unsigned offset, int output)
|
2012-02-15 23:51:13 +00:00
|
|
|
{
|
2020-01-13 10:35:14 +00:00
|
|
|
set_gpio_flag(dev, offset, GPIOD_IS_OUT, output);
|
|
|
|
set_gpio_flag(dev, offset, GPIOD_IS_IN, !(output));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ulong sandbox_gpio_get_dir_flags(struct udevice *dev, unsigned int offset)
|
|
|
|
{
|
|
|
|
return *get_gpio_dir_flags(dev, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sandbox_gpio_set_dir_flags(struct udevice *dev, unsigned int offset,
|
|
|
|
ulong flags)
|
|
|
|
{
|
|
|
|
*get_gpio_dir_flags(dev, offset) = flags;
|
|
|
|
|
|
|
|
return 0;
|
2012-02-15 23:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These functions implement the public interface within U-Boot
|
|
|
|
*/
|
|
|
|
|
2014-02-26 22:59:25 +00:00
|
|
|
/* set GPIO port 'offset' as an input */
|
2014-05-22 10:43:05 +00:00
|
|
|
static int sb_gpio_direction_input(struct udevice *dev, unsigned offset)
|
2012-02-15 23:51:13 +00:00
|
|
|
{
|
2014-02-26 22:59:25 +00:00
|
|
|
debug("%s: offset:%u\n", __func__, offset);
|
2012-02-15 23:51:13 +00:00
|
|
|
|
2014-02-26 22:59:25 +00:00
|
|
|
return sandbox_gpio_set_direction(dev, offset, 0);
|
2012-02-15 23:51:13 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 22:59:25 +00:00
|
|
|
/* set GPIO port 'offset' as an output, with polarity 'value' */
|
2014-05-22 10:43:05 +00:00
|
|
|
static int sb_gpio_direction_output(struct udevice *dev, unsigned offset,
|
2014-02-26 22:59:25 +00:00
|
|
|
int value)
|
2012-02-15 23:51:13 +00:00
|
|
|
{
|
2014-02-26 22:59:25 +00:00
|
|
|
debug("%s: offset:%u, value = %d\n", __func__, offset, value);
|
2012-02-15 23:51:13 +00:00
|
|
|
|
2014-02-26 22:59:25 +00:00
|
|
|
return sandbox_gpio_set_direction(dev, offset, 1) |
|
|
|
|
sandbox_gpio_set_value(dev, offset, value);
|
2012-02-15 23:51:13 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 22:59:25 +00:00
|
|
|
/* read GPIO IN value of port 'offset' */
|
2014-05-22 10:43:05 +00:00
|
|
|
static int sb_gpio_get_value(struct udevice *dev, unsigned offset)
|
2012-02-15 23:51:13 +00:00
|
|
|
{
|
2014-02-26 22:59:25 +00:00
|
|
|
debug("%s: offset:%u\n", __func__, offset);
|
2012-02-15 23:51:13 +00:00
|
|
|
|
2014-02-26 22:59:25 +00:00
|
|
|
return sandbox_gpio_get_value(dev, offset);
|
2012-02-15 23:51:13 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 22:59:25 +00:00
|
|
|
/* write GPIO OUT value to port 'offset' */
|
2014-05-22 10:43:05 +00:00
|
|
|
static int sb_gpio_set_value(struct udevice *dev, unsigned offset, int value)
|
2012-02-15 23:51:13 +00:00
|
|
|
{
|
2014-02-26 22:59:25 +00:00
|
|
|
debug("%s: offset:%u, value = %d\n", __func__, offset, value);
|
2012-02-15 23:51:13 +00:00
|
|
|
|
2014-02-26 22:59:25 +00:00
|
|
|
if (!sandbox_gpio_get_direction(dev, offset)) {
|
|
|
|
printf("sandbox_gpio: error: set_value on input gpio %u\n",
|
|
|
|
offset);
|
2012-02-15 23:51:13 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-02-26 22:59:25 +00:00
|
|
|
return sandbox_gpio_set_value(dev, offset, value);
|
2012-02-15 23:51:13 +00:00
|
|
|
}
|
|
|
|
|
2014-10-04 17:29:45 +00:00
|
|
|
static int sb_gpio_get_function(struct udevice *dev, unsigned offset)
|
|
|
|
{
|
2020-01-13 10:35:14 +00:00
|
|
|
if (get_gpio_flag(dev, offset, GPIOD_IS_OUT))
|
2014-10-04 17:29:45 +00:00
|
|
|
return GPIOF_OUTPUT;
|
2020-01-13 10:35:14 +00:00
|
|
|
if (get_gpio_flag(dev, offset, GPIOD_IS_IN))
|
|
|
|
return GPIOF_INPUT;
|
|
|
|
|
|
|
|
return GPIOF_INPUT; /*GPIO is not configurated */
|
2014-10-04 17:29:45 +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>
2015-01-06 03:05:29 +00:00
|
|
|
static int sb_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
|
2017-05-19 02:09:18 +00:00
|
|
|
struct ofnode_phandle_args *args)
|
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>
2015-01-06 03:05:29 +00:00
|
|
|
{
|
|
|
|
desc->offset = args->args[0];
|
|
|
|
if (args->args_count < 2)
|
|
|
|
return 0;
|
2020-01-13 10:35:13 +00:00
|
|
|
/* treat generic binding with gpio uclass */
|
|
|
|
gpio_xlate_offs_flags(dev, desc, args);
|
|
|
|
|
|
|
|
/* sandbox test specific, not defined in gpio.h */
|
|
|
|
if (args->args[1] & GPIO_IN)
|
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>
2015-01-06 03:05:29 +00:00
|
|
|
desc->flags |= GPIOD_IS_IN;
|
2020-01-13 10:35:14 +00:00
|
|
|
|
2020-01-13 10:35:13 +00:00
|
|
|
if (args->args[1] & GPIO_OUT)
|
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>
2015-01-06 03:05:29 +00:00
|
|
|
desc->flags |= GPIOD_IS_OUT;
|
2020-01-13 10:35:14 +00:00
|
|
|
|
2020-01-13 10:35:13 +00:00
|
|
|
if (args->args[1] & GPIO_OUT_ACTIVE)
|
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>
2015-01-06 03:05:29 +00:00
|
|
|
desc->flags |= GPIOD_IS_OUT_ACTIVE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-13 10:35:14 +00:00
|
|
|
static int sb_gpio_set_dir_flags(struct udevice *dev, unsigned int offset,
|
|
|
|
ulong flags)
|
|
|
|
{
|
|
|
|
ulong *dir_flags;
|
|
|
|
|
|
|
|
debug("%s: offset:%u, dir_flags = %lx\n", __func__, offset, flags);
|
|
|
|
|
|
|
|
dir_flags = get_gpio_dir_flags(dev, offset);
|
|
|
|
|
|
|
|
*dir_flags = flags;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sb_gpio_get_dir_flags(struct udevice *dev, unsigned int offset,
|
|
|
|
ulong *flags)
|
|
|
|
{
|
|
|
|
debug("%s: offset:%u\n", __func__, offset);
|
|
|
|
*flags = *get_gpio_dir_flags(dev, offset);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 19:11:44 +00:00
|
|
|
#if CONFIG_IS_ENABLED(ACPIGEN)
|
|
|
|
static int sb_gpio_get_acpi(const struct gpio_desc *desc,
|
|
|
|
struct acpi_gpio *gpio)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Note that gpio_get_acpi() zeroes *gpio before calling here */
|
|
|
|
gpio->pin_count = 1;
|
|
|
|
gpio->pins[0] = desc->offset;
|
|
|
|
ret = acpi_device_scope(desc->dev, gpio->resource,
|
|
|
|
sizeof(gpio->resource));
|
|
|
|
if (ret)
|
|
|
|
return log_ret(ret);
|
|
|
|
|
|
|
|
/* All of these values are just used for testing */
|
|
|
|
if (desc->flags & GPIOD_ACTIVE_LOW) {
|
|
|
|
gpio->pin0_addr = 0x80012 + desc->offset;
|
|
|
|
gpio->type = ACPI_GPIO_TYPE_INTERRUPT;
|
|
|
|
gpio->pull = ACPI_GPIO_PULL_DOWN;
|
|
|
|
gpio->interrupt_debounce_timeout = 4321;
|
|
|
|
|
|
|
|
/* We use the GpioInt part */
|
|
|
|
gpio->irq.pin = desc->offset;
|
|
|
|
gpio->irq.polarity = ACPI_IRQ_ACTIVE_BOTH;
|
|
|
|
gpio->irq.shared = ACPI_IRQ_SHARED;
|
|
|
|
gpio->irq.wake = ACPI_IRQ_WAKE;
|
|
|
|
|
|
|
|
/* The GpioIo part is only used for testing */
|
|
|
|
gpio->polarity = ACPI_GPIO_ACTIVE_LOW;
|
|
|
|
} else {
|
|
|
|
gpio->pin0_addr = 0xc00dc + desc->offset;
|
|
|
|
gpio->type = ACPI_GPIO_TYPE_IO;
|
|
|
|
gpio->pull = ACPI_GPIO_PULL_UP;
|
|
|
|
gpio->interrupt_debounce_timeout = 0;
|
|
|
|
|
|
|
|
/* The GpioInt part is not used */
|
|
|
|
|
|
|
|
/* We use the GpioIo part */
|
|
|
|
gpio->output_drive_strength = 1234;
|
|
|
|
gpio->io_shared = true;
|
|
|
|
gpio->io_restrict = ACPI_GPIO_IO_RESTRICT_INPUT;
|
|
|
|
gpio->polarity = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sb_gpio_get_name(const struct udevice *dev, char *out_name)
|
|
|
|
{
|
|
|
|
return acpi_copy_name(out_name, "GPIO");
|
|
|
|
}
|
|
|
|
|
|
|
|
struct acpi_ops gpio_sandbox_acpi_ops = {
|
|
|
|
.get_name = sb_gpio_get_name,
|
|
|
|
};
|
|
|
|
#endif /* ACPIGEN */
|
|
|
|
|
2014-02-26 22:59:25 +00:00
|
|
|
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,
|
2014-10-04 17:29:45 +00:00
|
|
|
.get_function = sb_gpio_get_function,
|
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>
2015-01-06 03:05:29 +00:00
|
|
|
.xlate = sb_gpio_xlate,
|
2020-01-13 10:35:14 +00:00
|
|
|
.set_dir_flags = sb_gpio_set_dir_flags,
|
|
|
|
.get_dir_flags = sb_gpio_get_dir_flags,
|
2020-07-07 19:11:44 +00:00
|
|
|
#if CONFIG_IS_ENABLED(ACPIGEN)
|
|
|
|
.get_acpi = sb_gpio_get_acpi,
|
|
|
|
#endif
|
2014-02-26 22:59:25 +00:00
|
|
|
};
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int sandbox_gpio_ofdata_to_platdata(struct udevice *dev)
|
2014-02-26 22:59:25 +00:00
|
|
|
{
|
2015-03-05 19:25:20 +00:00
|
|
|
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
|
2012-02-15 23:51:13 +00:00
|
|
|
|
2018-02-03 17:36:59 +00:00
|
|
|
uc_priv->gpio_count = dev_read_u32_default(dev, "sandbox,gpio-count",
|
|
|
|
0);
|
2017-05-19 02:09:20 +00:00
|
|
|
uc_priv->bank_name = dev_read_string(dev, "gpio-bank-name");
|
2012-02-15 23:51:13 +00:00
|
|
|
|
2014-02-26 22:59:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int gpio_sandbox_probe(struct udevice *dev)
|
2014-02-26 22:59:25 +00:00
|
|
|
{
|
2015-03-05 19:25:20 +00:00
|
|
|
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
|
2014-02-26 22:59:25 +00:00
|
|
|
|
2017-05-19 02:09:20 +00:00
|
|
|
if (!dev_of_valid(dev))
|
2014-02-26 22:59:25 +00:00
|
|
|
/* Tell the uclass how many GPIOs we have */
|
|
|
|
uc_priv->gpio_count = CONFIG_SANDBOX_GPIO_COUNT;
|
|
|
|
|
|
|
|
dev->priv = calloc(sizeof(struct gpio_state), uc_priv->gpio_count);
|
|
|
|
|
|
|
|
return 0;
|
2012-02-15 23:51:13 +00:00
|
|
|
}
|
2014-02-26 22:59:25 +00:00
|
|
|
|
2014-10-04 17:29:46 +00:00
|
|
|
static int gpio_sandbox_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
free(dev->priv);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-12 05:29:45 +00:00
|
|
|
static const struct udevice_id sandbox_gpio_ids[] = {
|
2014-02-26 22:59:25 +00:00
|
|
|
{ .compatible = "sandbox,gpio" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:04 +00:00
|
|
|
U_BOOT_DRIVER(sandbox_gpio) = {
|
|
|
|
.name = "sandbox_gpio",
|
2014-02-26 22:59:25 +00:00
|
|
|
.id = UCLASS_GPIO,
|
|
|
|
.of_match = sandbox_gpio_ids,
|
|
|
|
.ofdata_to_platdata = sandbox_gpio_ofdata_to_platdata,
|
|
|
|
.probe = gpio_sandbox_probe,
|
2014-10-04 17:29:46 +00:00
|
|
|
.remove = gpio_sandbox_remove,
|
2014-02-26 22:59:25 +00:00
|
|
|
.ops = &gpio_sandbox_ops,
|
2020-07-07 19:11:44 +00:00
|
|
|
ACPI_OPS_PTR(&gpio_sandbox_acpi_ops)
|
2014-02-26 22:59:25 +00:00
|
|
|
};
|
2020-01-13 10:35:15 +00:00
|
|
|
|
2020-06-25 04:10:06 +00:00
|
|
|
U_BOOT_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias)
|
|
|
|
|
2020-01-13 10:35:15 +00:00
|
|
|
/* pincontrol: used only to check GPIO pin configuration (pinmux command) */
|
|
|
|
|
|
|
|
struct sb_pinctrl_priv {
|
|
|
|
int pinctrl_ngpios;
|
|
|
|
struct list_head gpio_dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sb_gpio_bank {
|
|
|
|
struct udevice *gpio_dev;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int sb_populate_gpio_dev_list(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct sb_pinctrl_priv *priv = dev_get_priv(dev);
|
|
|
|
struct udevice *gpio_dev;
|
|
|
|
struct udevice *child;
|
|
|
|
struct sb_gpio_bank *gpio_bank;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parse pin-controller sub-nodes (ie gpio bank nodes) and fill
|
|
|
|
* a list with all gpio device reference which belongs to the
|
|
|
|
* current pin-controller. This list is used to find pin_name and
|
|
|
|
* pin muxing
|
|
|
|
*/
|
|
|
|
list_for_each_entry(child, &dev->child_head, sibling_node) {
|
|
|
|
ret = uclass_get_device_by_name(UCLASS_GPIO, child->name,
|
|
|
|
&gpio_dev);
|
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gpio_bank = malloc(sizeof(*gpio_bank));
|
|
|
|
if (!gpio_bank) {
|
|
|
|
dev_err(dev, "Not enough memory\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
gpio_bank->gpio_dev = gpio_dev;
|
|
|
|
list_add_tail(&gpio_bank->list, &priv->gpio_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sb_pinctrl_get_pins_count(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct sb_pinctrl_priv *priv = dev_get_priv(dev);
|
|
|
|
struct gpio_dev_priv *uc_priv;
|
|
|
|
struct sb_gpio_bank *gpio_bank;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if get_pins_count has already been executed once on this
|
|
|
|
* pin-controller, no need to run it again
|
|
|
|
*/
|
|
|
|
if (priv->pinctrl_ngpios)
|
|
|
|
return priv->pinctrl_ngpios;
|
|
|
|
|
|
|
|
if (list_empty(&priv->gpio_dev))
|
|
|
|
sb_populate_gpio_dev_list(dev);
|
|
|
|
/*
|
|
|
|
* walk through all banks to retrieve the pin-controller
|
|
|
|
* pins number
|
|
|
|
*/
|
|
|
|
list_for_each_entry(gpio_bank, &priv->gpio_dev, list) {
|
|
|
|
uc_priv = dev_get_uclass_priv(gpio_bank->gpio_dev);
|
|
|
|
|
|
|
|
priv->pinctrl_ngpios += uc_priv->gpio_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return priv->pinctrl_ngpios;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct udevice *sb_pinctrl_get_gpio_dev(struct udevice *dev,
|
|
|
|
unsigned int selector,
|
|
|
|
unsigned int *idx)
|
|
|
|
{
|
|
|
|
struct sb_pinctrl_priv *priv = dev_get_priv(dev);
|
|
|
|
struct sb_gpio_bank *gpio_bank;
|
|
|
|
struct gpio_dev_priv *uc_priv;
|
|
|
|
int pin_count = 0;
|
|
|
|
|
|
|
|
if (list_empty(&priv->gpio_dev))
|
|
|
|
sb_populate_gpio_dev_list(dev);
|
|
|
|
|
|
|
|
/* look up for the bank which owns the requested pin */
|
|
|
|
list_for_each_entry(gpio_bank, &priv->gpio_dev, list) {
|
|
|
|
uc_priv = dev_get_uclass_priv(gpio_bank->gpio_dev);
|
|
|
|
|
|
|
|
if (selector < (pin_count + uc_priv->gpio_count)) {
|
|
|
|
/*
|
|
|
|
* we found the bank, convert pin selector to
|
|
|
|
* gpio bank index
|
|
|
|
*/
|
|
|
|
*idx = selector - pin_count;
|
|
|
|
|
|
|
|
return gpio_bank->gpio_dev;
|
|
|
|
}
|
|
|
|
pin_count += uc_priv->gpio_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *sb_pinctrl_get_pin_name(struct udevice *dev,
|
|
|
|
unsigned int selector)
|
|
|
|
{
|
|
|
|
struct gpio_dev_priv *uc_priv;
|
|
|
|
struct udevice *gpio_dev;
|
|
|
|
unsigned int gpio_idx;
|
|
|
|
static char pin_name[PINNAME_SIZE];
|
|
|
|
|
|
|
|
/* look up for the bank which owns the requested pin */
|
|
|
|
gpio_dev = sb_pinctrl_get_gpio_dev(dev, selector, &gpio_idx);
|
|
|
|
if (!gpio_dev) {
|
|
|
|
snprintf(pin_name, PINNAME_SIZE, "Error");
|
|
|
|
} else {
|
|
|
|
uc_priv = dev_get_uclass_priv(gpio_dev);
|
|
|
|
|
|
|
|
snprintf(pin_name, PINNAME_SIZE, "%s%d",
|
|
|
|
uc_priv->bank_name,
|
|
|
|
gpio_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pin_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *get_dir_flags_string(ulong flags)
|
|
|
|
{
|
|
|
|
if (flags & GPIOD_OPEN_DRAIN)
|
|
|
|
return "drive-open-drain";
|
|
|
|
if (flags & GPIOD_OPEN_SOURCE)
|
|
|
|
return "drive-open-source";
|
|
|
|
if (flags & GPIOD_PULL_UP)
|
|
|
|
return "bias-pull-up";
|
|
|
|
if (flags & GPIOD_PULL_DOWN)
|
|
|
|
return "bias-pull-down";
|
|
|
|
return ".";
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sb_pinctrl_get_pin_muxing(struct udevice *dev,
|
|
|
|
unsigned int selector,
|
|
|
|
char *buf, int size)
|
|
|
|
{
|
|
|
|
struct udevice *gpio_dev;
|
|
|
|
unsigned int gpio_idx;
|
|
|
|
ulong dir_flags;
|
|
|
|
int function;
|
|
|
|
|
|
|
|
/* look up for the bank which owns the requested pin */
|
|
|
|
gpio_dev = sb_pinctrl_get_gpio_dev(dev, selector, &gpio_idx);
|
|
|
|
if (!gpio_dev) {
|
|
|
|
snprintf(buf, size, "Error");
|
|
|
|
} else {
|
|
|
|
function = sb_gpio_get_function(gpio_dev, gpio_idx);
|
|
|
|
dir_flags = *get_gpio_dir_flags(gpio_dev, gpio_idx);
|
|
|
|
|
|
|
|
snprintf(buf, size, "gpio %s %s",
|
|
|
|
function == GPIOF_OUTPUT ? "output" : "input",
|
|
|
|
get_dir_flags_string(dir_flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 19:11:44 +00:00
|
|
|
#if CONFIG_IS_ENABLED(ACPIGEN)
|
|
|
|
static int sb_pinctrl_get_name(const struct udevice *dev, char *out_name)
|
|
|
|
{
|
|
|
|
return acpi_copy_name(out_name, "PINC");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-01-13 10:35:15 +00:00
|
|
|
static int sandbox_pinctrl_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct sb_pinctrl_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&priv->gpio_dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pinctrl_ops sandbox_pinctrl_gpio_ops = {
|
|
|
|
.get_pin_name = sb_pinctrl_get_pin_name,
|
|
|
|
.get_pins_count = sb_pinctrl_get_pins_count,
|
|
|
|
.get_pin_muxing = sb_pinctrl_get_pin_muxing,
|
|
|
|
};
|
|
|
|
|
2020-07-07 19:11:44 +00:00
|
|
|
#if CONFIG_IS_ENABLED(ACPIGEN)
|
|
|
|
struct acpi_ops pinctrl_sandbox_acpi_ops = {
|
|
|
|
.get_name = sb_pinctrl_get_name,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2020-01-13 10:35:15 +00:00
|
|
|
static const struct udevice_id sandbox_pinctrl_gpio_match[] = {
|
|
|
|
{ .compatible = "sandbox,pinctrl-gpio" },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(sandbox_pinctrl_gpio) = {
|
|
|
|
.name = "sandbox_pinctrl_gpio",
|
|
|
|
.id = UCLASS_PINCTRL,
|
|
|
|
.of_match = sandbox_pinctrl_gpio_match,
|
|
|
|
.ops = &sandbox_pinctrl_gpio_ops,
|
|
|
|
.bind = dm_scan_fdt_dev,
|
|
|
|
.probe = sandbox_pinctrl_probe,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct sb_pinctrl_priv),
|
2020-07-07 19:11:44 +00:00
|
|
|
ACPI_OPS_PTR(&pinctrl_sandbox_acpi_ops)
|
2020-01-13 10:35:15 +00:00
|
|
|
};
|