GPIO reset support
v4 cover GPIO reset support
This series adds generic GPIO reset (poweroff/restart) support which is required by SiFive platforms.
These patches is on top of gpio_reset_v3 branch at:
https://github.com/avpatel/opensbi.git
Changes since v4:
- Added set() implementation
- Adjust mdelay loop count to '100000'
Changes since v3:
- Simplified GPIO reset driver in PATCH5
- Dropped PATCH6
Changes since v2:
- Re-designed the GPIO framework to probe GPIO drivers on demand and avoid touching generic OpenSBI library.
Anup Patel (3):
lib: utils/fdt: Add fdt_parse_phandle_with_args() API
lib: utils/gpio: Add generic GPIO configuration library
lib: utils/gpio: Add simple FDT based GPIO framework
Green Wan (2):
lib: utils/gpio: Add minimal SiFive GPIO driver
lib: utils/reset: Add generic GPIO reset driver
include/sbi_utils/fdt/fdt_helper.h | 11 +++ include/sbi_utils/gpio/fdt_gpio.h | 34 +++++++ include/sbi_utils/gpio/gpio.h | 99 ++++++++++++++++++++ lib/utils/fdt/fdt_helper.c | 47 ++++++++++ lib/utils/gpio/fdt_gpio.c | 135 +++++++++++++++++++++++++++ lib/utils/gpio/fdt_gpio_sifive.c | 105 +++++++++++++++++++++ lib/utils/gpio/gpio.c | 116 ++++++++++++++++++++++++ lib/utils/gpio/objects.mk | 12 +++ lib/utils/reset/fdt_reset.c | 2 + lib/utils/reset/fdt_reset_gpio.c | 141 +++++++++++++++++++++++++++++ lib/utils/reset/objects.mk | 1 + 11 files changed, 703 insertions(+) create mode 100644 include/sbi_utils/gpio/fdt_gpio.h create mode 100644 include/sbi_utils/gpio/gpio.h create mode 100644 lib/utils/gpio/fdt_gpio.c create mode 100644 lib/utils/gpio/fdt_gpio_sifive.c create mode 100644 lib/utils/gpio/gpio.c create mode 100644 lib/utils/gpio/objects.mk create mode 100644 lib/utils/reset/fdt_reset_gpio.c
Signature · 1 line
2.17.1
PATCH v4 1/5 lib: utils/fdt: Add fdt_parse_phandle_with_args() API
From: Anup Patel <[email protected]>
The libfdt project does not have a generic API to parse phandle with args from a DT node so we add fdt_parse_phandle_with_args() for this purpose. This new API will be useful to FDT based drivers.
--- include/sbi_utils/fdt/fdt_helper.h | 11 +++++++ lib/utils/fdt/fdt_helper.c | 47 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+)
include/sbi_utils/fdt/fdt_helper.h +11 -0
@@ -17,6 +17,13 @@ struct fdt_match {void *data; }; +#define FDT_MAX_PHANDLE_ARGS 16 +struct fdt_phandle_args { +int node_offset; +int args_count; +u32 args[FDT_MAX_PHANDLE_ARGS ]; +}; +struct platform_uart_data {unsigned long addr;unsigned long freq;
@@ -32,6 +39,10 @@ int fdt_find_match(void *fdt, int startoff,const struct fdt_match *match_table, const struct fdt_match **out_match); +int fdt_parse_phandle_with_args (void *fdt,int nodeoff, +const char *prop,const char *cells_prop, +int index,struct fdt_phandle_args *out_args); +int fdt_get_node_addr_size (void *fdt,int node,unsigned long *addr,unsigned long *size);
lib/utils/fdt/fdt_helper.c +47 -0
53 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 2/5 lib: utils/gpio: Add generic GPIO configuration library
In reply to Green WanFrom: Anup Patel <[email protected]>
We add generic GPIO configuration library which is independent of hardware description format (FDT or ACPI). The OpenSBI platform support or GPIO drivers can register GPIO chip instances which can be discovered and used by different GPIO clients. Each GPIO chip instance has a unique ID which can be used by GPIO clients to lookup GPIO chip instance.
--- include/sbi_utils/gpio/gpio.h | 99 +++++++++++++++++++++++++++++ lib/utils/gpio/gpio.c | 116 ++++++++++++++++++++++++++++++++++ lib/utils/gpio/objects.mk | 10 +++ 3 files changed, 225 insertions(+) create mode 100644 include/sbi_utils/gpio/gpio.h create mode 100644 lib/utils/gpio/gpio.c create mode 100644 lib/utils/gpio/objects.mk
include/sbi_utils/gpio/gpio.h new file +99 -0
@@ -0,0 +1,99 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#ifndef __GPIO_H__ +#define __GPIO_H__ + +#include <sbi/sbi_types.h> + +#define GPIO_LINE_DIRECTION_IN 1 +#define GPIO_LINE_DIRECTION_OUT 0 + +/** Representation of a GPIO pin */ +struct gpio_pin { +/** Pointer to the GPIO chip */ +struct gpio_chip *chip; +/** Identification of GPIO pin within GPIO chip */ +unsigned int offset; +/** +* Additional configuration flags of the GPIO pin desired +* by GPIO clients. +* +* NOTE: GPIO chip can have custom configuration flags. +*/ +unsigned int flags; +#define GPIO_FLAG_ACTIVE_LOW 0x1 +#define GPIO_FLAG_SINGLE_ENDED 0x2 +#define GPIO_FLAG_OPEN_DRAIN 0x4 +#define GPIO_FLAG_TRANSITORY 0x8 +#define GPIO_FLAG_PULL_UP 0x10 +#define GPIO_FLAG_PULL_DOWN 0x20 +}; + +/** Representation of a GPIO chip */ +struct gpio_chip { +/** Pointer to GPIO driver owning this GPIO chip */ +void *driver; +/** Uniquie ID of the GPIO chip assigned by the driver */ +unsigned int id; +/** Number of GPIOs supported by the GPIO chip */ +unsigned int ngpio; +/** +* Get current direction of GPIO pin +* +* @return 0=output, 1=input, or negative error +*/ +int (*get_direction)(struct gpio_pin *gp); +/** +* Set input direction of GPIO pin +* +* @return 0 on success and negative error code on failure +*/ +int (*direction_input)(struct gpio_pin *gp); +/** +* Set output direction of GPIO pin with given output value +* +* @return 0 on success and negative error code on failure +*/ +int (*direction_output)(struct gpio_pin *gp,int value); +/** +* Get current value of GPIO pin +* +* @return 0=low, 1=high, or negative error +*/ +int (*get)(struct gpio_pin *gp); +/** Set output value for GPIO pin */ +void (*set)(struct gpio_pin *gp,int value); +}; + +/** Find a registered GPIO chip */ +struct gpio_chip *gpio_chip_find (unsigned int id); + +/** Register GPIO chip */ +int gpio_chip_add (struct gpio_chip *gc); + +/** Un-register GPIO chip */ +void gpio_chip_remove (struct gpio_chip *gc); + +/** Get current direction of GPIO pin */ +int gpio_get_direction (struct gpio_pin *gp); + +/** Set input direction of GPIO pin */ +int gpio_direction_input (struct gpio_pin *gp); + +/** Set output direction of GPIO pin */ +int gpio_direction_output (struct gpio_pin *gp,int value); + +/** Get current value of GPIO pin */ +int gpio_get (struct gpio_pin *gp); + +/** Set output value of GPIO pin */ +int gpio_set (struct gpio_pin *gp,int value); + +#endif
lib/utils/gpio/gpio.c new file +116 -0
116 lines not on this page · raw message
lib/utils/gpio/objects.mk new file +10 -0
@@ -0,0 +1,10 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2021 Western Digital Corporation or its affiliates. +# +# Authors: +# Anup Patel <[email protected]> +# + +libsbiutils-objs-y += gpio/gpio.o
Signature · 1 line
2.17.1
PATCH v4 3/5 lib: utils/gpio: Add simple FDT based GPIO framework
In reply to Green WanFrom: Anup Patel <[email protected]>
We add a simple FDT based GPIO framework which is built on top of generic GPIO library. The phandle of FDT GPIO chip DT node is treated as unique GPIO chip ID required by the generic GPIO library. The FDT based GPIO chip drivers will be probed on-demand from fdt_gpio_pin_get() called by the GPIO client drivers.
--- include/sbi_utils/gpio/fdt_gpio.h | 34 ++++++++ lib/utils/gpio/fdt_gpio.c | 132 ++++++++++++++++++++++++++++++ lib/utils/gpio/objects.mk | 1 + 3 files changed, 167 insertions(+) create mode 100644 include/sbi_utils/gpio/fdt_gpio.h create mode 100644 lib/utils/gpio/fdt_gpio.c
include/sbi_utils/gpio/fdt_gpio.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#ifndef __FDT_GPIO_H__ +#define __FDT_GPIO_H__ + +#include <sbi_utils/gpio/gpio.h> + +/** FDT based GPIO driver */ +struct fdt_gpio { +const struct fdt_match *match_table; +int (*xlate)(struct gpio_chip *chip, +const struct fdt_phandle_args *pargs, +struct gpio_pin *out_pin); +int (*init)(void *fdt,int nodeoff,u32 phandle, +const struct fdt_match *match); +}; + +/** Get a GPIO pin using "gpios" DT property of client DT node */ +int fdt_gpio_pin_get (void *fdt,int nodeoff,int index, +struct gpio_pin *out_pin); + +/** Simple xlate function to convert two GPIO FDT cells into GPIO pin */ +int fdt_gpio_simple_xlate (struct gpio_chip *chip, +const struct fdt_phandle_args *pargs, +struct gpio_pin *out_pin); + +#endif
lib/utils/gpio/fdt_gpio.c new file +132 -0
132 lines not on this page · raw message
lib/utils/gpio/objects.mk +1 -0
@@ -7,4 +7,5 @@ # Anup Patel <[email protected]> # +libsbiutils-objs-y += gpio/fdt_gpio.o libsbiutils-objs-y += gpio/gpio.o
Signature · 1 line
2.17.1
PATCH v4 4/5 lib: utils/gpio: Add minimal SiFive GPIO driver
In reply to Green WanWe add a minimal SiFive GPIO driver so that we can do GPIO based system power-off and reset.
--- lib/utils/gpio/fdt_gpio.c | 3 + lib/utils/gpio/fdt_gpio_sifive.c | 105 +++++++++++++++++++++++++++++++ lib/utils/gpio/objects.mk | 1 + 3 files changed, 109 insertions(+) create mode 100644 lib/utils/gpio/fdt_gpio_sifive.c
lib/utils/gpio/fdt_gpio.c +3 -0
@@ -12,7 +12,10 @@#include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/gpio/fdt_gpio.h> +extern struct fdt_gpio fdt_gpio_sifive; +static struct fdt_gpio *gpio_drivers[] = { + &fdt_gpio_sifive };static struct fdt_gpio *fdt_gpio_driver (struct gpio_chip *chip)
lib/utils/gpio/fdt_gpio_sifive.c new file +105 -0
105 lines not on this page · raw message
lib/utils/gpio/objects.mk +1 -0
@@ -8,4 +8,5 @@ # libsbiutils-objs-y += gpio/fdt_gpio.o +libsbiutils-objs-y += gpio/fdt_gpio_sifive.o libsbiutils-objs-y += gpio/gpio.o
Signature · 1 line
2.17.1