add sifive reset device
cover add sifive reset device
To enable reset device for SiFive Unmatched board, the patchset starts with a preparetory patch [1/4] to unify the file and function names of current 'sifive_test' reset device.
Then, adding 'gpio-poweroff' DT parsing and a gpio output interface to lib/utils in patch [2/4] and [3/4].
The reset device 'sifive_reset' is added in the last patch [4/4].
'sifive_reset' device uses gpio_direction_output() to do the reset. The entry point for GPIO initialization must be initialized first and is placed at patform/generic/platform.c.
Current GPIO interface is simple and only ouput control callback is available.
Green Wan (4):
lib: utils: reset: unify naming of 'sifive_test' device
lib: utils: add GPIO and poweroff parsing
lib: utils: add gpio generic interface
lib: utils: add sifive reset device
include/sbi/sbi_gpio.h | 23 ++++++++ include/sbi_utils/fdt/fdt_helper.h | 21 ++++++++ include/sbi_utils/gpio/fdt_gpio.h | 32 +++++++++++ include/sbi_utils/sys/sifive_reset.h | 18 +++++++ lib/utils/fdt/fdt_helper.c | 51 +++++++++++++++++- lib/utils/gpio/fdt_gpio.c | 55 +++++++++++++++++++ lib/utils/gpio/objects.mk | 11 ++++ lib/utils/gpio/sifive_gpio.c | 70 +++++++++++++++++++++++++ lib/utils/reset/fdt_reset.c | 2 + lib/utils/reset/fdt_reset_sifive.c | 37 ++++++++----- lib/utils/reset/fdt_reset_sifive_test.c | 36 +++++++++++++ lib/utils/reset/objects.mk | 1 + lib/utils/sys/objects.mk | 1 + lib/utils/sys/sifive_reset.c | 66 +++++++++++++++++++++++ platform/generic/platform.c | 3 ++ 15 files changed, 413 insertions(+), 14 deletions(-) create mode 100644 include/sbi/sbi_gpio.h create mode 100644 include/sbi_utils/gpio/fdt_gpio.h create mode 100644 include/sbi_utils/sys/sifive_reset.h create mode 100644 lib/utils/gpio/fdt_gpio.c create mode 100644 lib/utils/gpio/objects.mk create mode 100644 lib/utils/gpio/sifive_gpio.c create mode 100644 lib/utils/reset/fdt_reset_sifive_test.c create mode 100644 lib/utils/sys/sifive_reset.c
Signature · 1 line
2.17.1
RFC PATCH 1/4 lib: utils: reset: unify naming of 'sifive_test' device
Unify all the file and function names of 'sifive_test' device, to use the same prefix. This is also a preparatory patch for upcoming sifive reset device.
---
lib/utils/reset/fdt_reset.c | 4 ++--
.../reset/{fdt_reset_sifive.c => fdt_reset_sifive_test.c} | 2 +-
lib/utils/reset/objects.mk | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
rename lib/utils/reset/{fdt_reset_sifive.c => fdt_reset_sifive_test.c} (94%)lib/utils/reset/fdt_reset.c +2 -2
@@ -12,12 +12,12 @@#include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/reset/fdt_reset.h> -extern struct fdt_reset fdt_reset_sifive; +extern struct fdt_reset fdt_reset_sifive_test;extern struct fdt_reset fdt_reset_htif;extern struct fdt_reset fdt_reset_thead;static struct fdt_reset *reset_drivers[] = { - &fdt_reset_sifive, + &fdt_reset_sifive_test, &fdt_reset_htif, &fdt_reset_thead, };
lib/utils/reset/fdt_reset_sifive_test.c renamed from lib/utils/reset/fdt_reset_sifive.c +1 -1
@@ -30,7 +30,7 @@ static const struct fdt_match sifive_test_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_sifive = { +struct fdt_reset fdt_reset_sifive_test = { .match_table = sifive_test_reset_match, .init = sifive_test_reset_init, };
lib/utils/reset/objects.mk +1 -1
@@ -9,6 +9,6 @@ libsbiutils-objs-y += reset/fdt_reset.o libsbiutils-objs-y += reset/fdt_reset_htif.o -libsbiutils-objs-y += reset/fdt_reset_sifive.o +libsbiutils-objs-y += reset/fdt_reset_sifive_test.o libsbiutils-objs-y += reset/fdt_reset_thead.o libsbiutils-objs-y += reset/fdt_reset_thead_asm.o
Signature · 1 line
2.17.1
RFC PATCH 1/4 lib: utils: reset: unify naming of 'sifive_test' device
Quoted 5 lines · Green Wan
Unify all the file and function names of '
sifive_test' device, to use the same prefix. This is also a preparatory patch for upcoming sifive reset device.
Quoted 8 lines
Signed-off-by Green Wan <[email protected]>--- lib/utils/reset/fdt_reset.c | 4 ++-- .../reset/{fdt_reset_sifive.c => fdt_reset_sifive_test.c} | 2 +- lib/utils/reset/objects.mk | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename lib/utils/reset/{fdt_reset_sifive.c => fdt_reset_sifive_test.c} (94%)
Anup Patel
AppliedRFC PATCH 1/4 lib: utils: reset: unify naming of 'sifive_test' device
Quoted 16 lines · Bin Meng
Quoted 5 lines · Green Wan
Unify all the file and function names of '
sifive_test' device, to use the same prefix. This is also a preparatory patch for upcoming sifive reset device.Quoted 8 lines
Signed-off-by Green Wan <[email protected]>--- lib/utils/reset/fdt_reset.c | 4 ++-- .../reset/{fdt_reset_sifive.c => fdt_reset_sifive_test.c} | 2 +- lib/utils/reset/objects.mk | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename lib/utils/reset/{fdt_reset_sifive.c => fdt_reset_sifive_test.c} (94%)
Quoted 1 line
Reviewed-by Bin Meng <[email protected]>
Looks good to me as well.
Applied this patch to the riscv/opensbi repo.
Regards,
Anup
RFC PATCH 2/4 lib: utils: add GPIO and poweroff parsing
In reply to Green WanAdd support for GPIO and 'gpio-poweroff' in DT.
--- include/sbi_utils/fdt/fdt_helper.h | 21 ++++++++++++ lib/utils/fdt/fdt_helper.c | 51 +++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-)
include/sbi_utils/fdt/fdt_helper.h +21 -0
@@ -12,6 +12,17 @@#include <sbi/sbi_types.h> +enum gpio_output_type { +GPIO_ACTIVE_HIGH =0 , +GPIO_ACTIVE_LOW , +}; + +struct poweroff_gpio { +unsigned int act_delay;/* in ms */ +int gpio;/* GPIO No */ +enum gpio_output_type output_type;/* output type */ +}; +struct fdt_match {const char *compatible;void *data;
@@ -25,6 +36,10 @@ struct platform_uart_data {unsigned long reg_io_width; }; +struct platform_gpio_data { +unsigned long addr; +}; +const struct fdt_match *fdt_match_node (void *fdt,int nodeoff,const struct fdt_match *match_table);
@@ -67,4 +82,10 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,int fdt_parse_compat_addr (void *fdt,unsigned long *addr,const char *compatible); +int fdt_parse_gpio_pwroff (void *fdt,struct poweroff_gpio *pwroff, +const char *compatible); + +int fdt_parse_gpio_node (void *fdt,int nodeoffset, +struct platform_gpio_data *gpio); +#endif /* __FDT_HELPER_H__ */
lib/utils/fdt/fdt_helper.c +50 -1
60 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 2/4 lib: utils: add GPIO and poweroff parsing
Quoted 82 lines · Green Wan
Add support for GPIO and 'gpio-poweroff' in DT.
Signed-off-by Green Wan <[email protected]>--- include/sbi_utils/fdt/fdt_helper.h | 21 ++++++++++++ lib/utils/fdt/fdt_helper.c | 51 +++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-)include/sbi_utils/fdt/fdt_helper.h +21
-0@@ -12,6 +12,17 @@#include <sbi/sbi_types.h> +enum gpio_output_type { +GPIO_ACTIVE_HIGH =0 , +GPIO_ACTIVE_LOW , +}; + +struct poweroff_gpio { +unsigned int act_delay;/* in ms */ +int gpio;/* GPIO No */ +enum gpio_output_type output_type;/* output type */ +}; +struct fdt_match {const char *compatible;void *data;@@ -25,6 +36,10 @@ struct platform_uart_data {unsigned long reg_io_width; }; +struct platform_gpio_data { +unsigned long addr; +}; +const struct fdt_match *fdt_match_node (void *fdt,int nodeoff,const struct fdt_match *match_table);@@ -67,4 +82,10 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,int fdt_parse_compat_addr (void *fdt,unsigned long *addr,const char *compatible); +int fdt_parse_gpio_pwroff (void *fdt,struct poweroff_gpio *pwroff, +const char *compatible); + +int fdt_parse_gpio_node (void *fdt,int nodeoffset, +struct platform_gpio_data *gpio); +#endif /* __FDT_HELPER_H__ */ lib/utils/fdt/fdt_helper.c +13
-1@@ -5,7 +5,6 @@* * Copyright (C) 2020 Bin Meng <[email protected]> */ -#include <libfdt.h> #include <sbi/riscv_asm.h> #include <sbi/sbi_console.h> @@ -503,3 +502,53 @@ int fdt_parse_compat_addr(void *fdt, unsigned long *addr,return 0 ; } + +int fdt_parse_gpio_pwroff (void *fdt,struct poweroff_gpio *pwroff, +const char *compatible) +{ +int pwroff_offset; + + pwroff_offset =fdt_path_offset (fdt, compatible); +if (pwroff_offset >=0 ) { +int len; +const char *pwroff_cmpt; + + pwroff_cmpt =fdt_getprop (fdt, pwroff_offset,"compatible" , &len); +
lib/utils/fdt/fdt_helper.c int fdt_parse_compat_addr(void *fdt, unsigned long *addr, · line 527
Quoted 10 lines
lib/utils/fdt/fdt_helper.c +10
-0+if (pwroff_cmpt && !sbi_strcmp ("gpio-poweroff" , pwroff_cmpt)) { +const fdt32_t *val; + + val =fdt_getprop (fdt, pwroff_offset, +"active-delay-ms" , &len); +if (val) + pwroff->act_delay =fdt32_to_cpu (*val); + + val =fdt_getprop (fdt, pwroff_offset,"gpios" , &len); +if (val) {
Should check 'len' here.
Quoted 17 lines
lib/utils/fdt/fdt_helper.c +17
-0+ pwroff->gpio =fdt32_to_cpu (val[1 ]); + pwroff->output_type =fdt32_to_cpu (val[2 ]); + +return 0 ; + } + } + } + +return SBI_EINVAL ; +} + +int fdt_parse_gpio_node (void *fdt,int nodeoffset, +struct platform_gpio_data *gpio) +{ +int rc; +unsigned long reg_addr, reg_size; +
lib/utils/fdt/fdt_helper.c int fdt_parse_compat_addr(void *fdt, unsigned long *addr, · line 554
Quoted 10 lines
lib/utils/fdt/fdt_helper.c +10
-0+if (nodeoffset <0 || !gpio || !fdt) +return SBI_ENODEV ; + + rc =fdt_get_node_addr_size (fdt, nodeoffset, ®_addr, ®_size); +if (rc <0 || !reg_addr || !reg_size) +return SBI_ENODEV ; + gpio->addr = reg_addr; + +return 0 ; +}
Regards,
Bin
RFC PATCH 3/4 lib: utils: add gpio generic interface
In reply to Green WanAdd generic interface for GPIO driver and add SiFive GPIO driver as an example. Currently, driver supports gpio output function only.
lib/utils/gpio/fdt_gpio.c:
- contains GPIO generic interfaces.
lib/utils/gpio/sifive_gpio.c:
- contains sifive GPIO driver.
platform/generic/platform.c:
- add entry of gpio init
--- include/sbi/sbi_gpio.h | 23 ++++++++++ include/sbi_utils/gpio/fdt_gpio.h | 32 ++++++++++++++ lib/utils/gpio/fdt_gpio.c | 55 ++++++++++++++++++++++++ lib/utils/gpio/objects.mk | 11 +++++ lib/utils/gpio/sifive_gpio.c | 70 +++++++++++++++++++++++++++++++ platform/generic/platform.c | 3 ++ 6 files changed, 194 insertions(+) create mode 100644 include/sbi/sbi_gpio.h create mode 100644 include/sbi_utils/gpio/fdt_gpio.h create mode 100644 lib/utils/gpio/fdt_gpio.c create mode 100644 lib/utils/gpio/objects.mk create mode 100644 lib/utils/gpio/sifive_gpio.c
include/sbi/sbi_gpio.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* SPDX-License-Identifier: GPL 2.0+ +* +* Copyright (c) 2021 SiFive. +* +* Authors: +* Green Wan <[email protected]> +*/ + +#ifndef __SBI_GPIO_H__ +#define __SBI_GPIO_H__ + +#include <sbi/sbi_types.h> + +struct sbi_scratch ; + +/* Initialize gpio */ +int sbi_gpio_init (struct sbi_scratch *scratch,bool cold_boot); + +/* Exit gpio */ +void sbi_gpio_exit (struct sbi_scratch *scratch); + +#endif
include/sbi_utils/gpio/fdt_gpio.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* SPDX-License-Identifier: GPL 2.0+ +* +* Copyright (c) 2021 SiFive +* +* Authors: +* Green Wan <[email protected]> +*/ + +#ifndef __FDT_GPIO_H__ +#define __FDT_GPIO_H__ + +#include <sbi/sbi_types.h> + +/** +* Make a GPIO an output, and set its value. +* +* @param gpio GPIO number +* @param value GPIO value (0 for low or 1 for high) +* @return 0 if ok, -1 on error +*/ +int gpio_direction_output (unsigned int gpio,unsigned int value); + +struct fdt_gpio { +const struct fdt_match *match_table; +int (*init)(void *fdt,int nodeoff,const struct fdt_match *match); +int (*direction_output)(unsigned int gpio,unsigned int value); +}; + +int fdt_gpio_init (void ); + +#endif
lib/utils/gpio/fdt_gpio.c new file +55 -0
55 lines not on this page · raw message
lib/utils/gpio/objects.mk new file +11 -0
@@ -0,0 +1,11 @@ +# +# SPDX-License-Identifier: GPL 2.0+ +# +# Copyright (c) 2020 SiFive Inc. +# +# Authors: +# Green Wan <[email protected]> +# + +libsbiutils-objs-y += gpio/fdt_gpio.o +libsbiutils-objs-y += gpio/sifive_gpio.o
lib/utils/gpio/sifive_gpio.c new file +70 -0
70 lines not on this page · raw message
platform/generic/platform.c +3 -0
@@ -16,6 +16,7 @@#include <sbi_utils/fdt/fdt_domain.h> #include <sbi_utils/fdt/fdt_fixup.h> #include <sbi_utils/fdt/fdt_helper.h> +#include <sbi_utils/gpio/fdt_gpio.h> #include <sbi_utils/irqchip/fdt_irqchip.h> #include <sbi_utils/serial/fdt_serial.h> #include <sbi_utils/timer/fdt_timer.h>
@@ -128,6 +129,8 @@ static int generic_early_init(bool cold_boot)if (!cold_boot)return 0 ; +fdt_gpio_init (); +return fdt_reset_init (); }
Signature · 1 line
2.17.1
RFC PATCH 3/4 lib: utils: add gpio generic interface
Quoted 199 lines · Green Wan
Add generic interface for GPIO driver and add SiFive GPIO driver as an example. Currently, driver supports gpio output function only.
lib/utils/gpio/fdt_gpio.c:
- contains GPIO generic interfaces.
lib/utils/gpio/sifive_gpio.c:
- contains sifive GPIO driver.
platform/generic/platform.c:
- add entry of gpio initSigned-off-by Green Wan <[email protected]>--- include/sbi/sbi_gpio.h | 23 ++++++++++ include/sbi_utils/gpio/fdt_gpio.h | 32 ++++++++++++++ lib/utils/gpio/fdt_gpio.c | 55 ++++++++++++++++++++++++ lib/utils/gpio/objects.mk | 11 +++++ lib/utils/gpio/sifive_gpio.c | 70 +++++++++++++++++++++++++++++++ platform/generic/platform.c | 3 ++ 6 files changed, 194 insertions(+) create mode 100644 include/sbi/sbi_gpio.h create mode 100644 include/sbi_utils/gpio/fdt_gpio.h create mode 100644 lib/utils/gpio/fdt_gpio.c create mode 100644 lib/utils/gpio/objects.mk create mode 100644 lib/utils/gpio/sifive_gpio.cinclude/sbi/sbi_gpio.h new file +23
-0@@ -0,0 +1,23 @@ +/* +* SPDX-License-Identifier: GPL 2.0+ +* +* Copyright (c) 2021 SiFive. +* +* Authors: +* Green Wan <[email protected]> +*/ + +#ifndef __SBI_GPIO_H__ +#define __SBI_GPIO_H__ + +#include <sbi/sbi_types.h> + +struct sbi_scratch ; + +/* Initialize gpio */ +int sbi_gpio_init (struct sbi_scratch *scratch,bool cold_boot); + +/* Exit gpio */ +void sbi_gpio_exit (struct sbi_scratch *scratch); + +#endif include/sbi_utils/gpio/fdt_gpio.h new file +32
-0@@ -0,0 +1,32 @@ +/* +* SPDX-License-Identifier: GPL 2.0+ +* +* Copyright (c) 2021 SiFive +* +* Authors: +* Green Wan <[email protected]> +*/ + +#ifndef __FDT_GPIO_H__ +#define __FDT_GPIO_H__ + +#include <sbi/sbi_types.h> + +/** +* Make a GPIO an output, and set its value. +* +* @param gpio GPIO number +* @param value GPIO value (0 for low or 1 for high) +* @return 0 if ok, -1 on error +*/ +int gpio_direction_output (unsigned int gpio,unsigned int value); + +struct fdt_gpio { +const struct fdt_match *match_table; +int (*init)(void *fdt,int nodeoff,const struct fdt_match *match); +int (*direction_output)(unsigned int gpio,unsigned int value); +}; + +int fdt_gpio_init (void ); + +#endif lib/utils/gpio/fdt_gpio.c new file +55
-0@@ -0,0 +1,55 @@ +/* +* SPDX-License-Identifier: GPL 2.0+ +* +* Copyright (c) 2021 SiFive +* +* Authors: +* Green Wan <[email protected]> +*/ + +#include <sbi/sbi_scratch.h> +#include <sbi/sbi_console.h> +#include <sbi_utils/fdt/fdt_helper.h> +#include <sbi_utils/gpio/fdt_gpio.h> + +extern struct fdt_gpio sifive_gpio; + +static struct fdt_gpio *gpio_drivers[] = { + &sifive_gpio +}; + +static struct fdt_gpio *current_driver; + +int gpio_direction_output (unsigned int gpio,unsigned int value) +{ +if (current_driver->direction_output) +return current_driver->direction_output (gpio, value); + +return 0 ; +} + +int fdt_gpio_init (void ) +{ +int pos, noff, rc; +struct fdt_gpio *drv; +const struct fdt_match *match; +void *fdt =sbi_scratch_thishart_arg1_ptr (); + +for (pos =0 ; pos <array_size (gpio_drivers); pos++) { + drv = gpio_drivers[pos]; + + noff =-1 ; +while ((noff =fdt_find_match (fdt, noff, + drv->match_table, + &match)) >=0 ) { +if (drv->init) { + rc = drv->init (fdt, noff, match); +if (rc) +return rc; + } + current_driver = drv; + } + } + +return 0 ; +}lib/utils/gpio/objects.mk new file +11
-0@@ -0,0 +1,11 @@ +# +# SPDX-License-Identifier: GPL 2.0+ +# +# Copyright (c) 2020 SiFive Inc. +# +# Authors: +# Green Wan <[email protected]> +# + +libsbiutils-objs-y += gpio/fdt_gpio.o +libsbiutils-objs-y += gpio/sifive_gpio.olib/utils/gpio/sifive_gpio.c new file +19
-0@@ -0,0 +1,70 @@ +/* +* SPDX-License-Identifier: GPL 2.0+ +* +* Copyright (c) 2021 SiFive +* +* Authors: +* Green Wan <[email protected]> +*/ + +#include <sbi/riscv_io.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_console.h> +#include <sbi_utils/fdt/fdt_helper.h> +#include <sbi_utils/gpio/fdt_gpio.h> + +#define GPIO_OUTEN 0x8 +#define GPIO_OUTVAL 0xC +#define GPIO_BIT (b) (1UL << (b)) +
lib/utils/gpio/sifive_gpio.c line 29
Quoted 10 lines
lib/utils/gpio/sifive_gpio.c new file +10
-0+static struct platform_gpio_data gpio_data = { + .addr =0x0 +}; + +static int sifive_gpio_init (void *fdt,int nodeoff, +const struct fdt_match *match) +{ +int rc; + + rc =fdt_parse_gpio_node (fdt, nodeoff, &gpio_data);
This won't work if there are more than 1 gpio controller.
Quoted 54 lines
lib/utils/gpio/sifive_gpio.c new file +41
-0+if (rc) +return rc; + +return 0 ; +} + +static int sifive_gpio_direction_output (unsigned int gpio, +unsigned int out) +{ +if (gpio_data.addr !=0 ) { +unsigned int val; + + val =readl ((volatile void *)(gpio_data.addr +GPIO_OUTEN )); + val |=GPIO_BIT (gpio); +writel (val, (volatile void *)(gpio_data.addr +GPIO_OUTEN )); + + val =readl ((volatile void *)(gpio_data.addr +GPIO_OUTVAL )); + +if (!out) + val &= ~GPIO_BIT (gpio); +else + val |=GPIO_BIT (gpio); + +writel (val, (volatile void *)(gpio_data.addr +GPIO_OUTVAL )); + +return 0 ; + } + +return SBI_EINVAL ; +} + +static const struct fdt_match sifive_gpio_match[] = { + { .compatible ="sifive,gpio0" }, + { }, +}; + +struct fdt_gpio sifive_gpio = { + .match_table = sifive_gpio_match, + .init = sifive_gpio_init, + .direction_output = sifive_gpio_direction_output, +};platform/generic/platform.c +1
-0@@ -16,6 +16,7 @@#include <sbi_utils/fdt/fdt_domain.h> #include <sbi_utils/fdt/fdt_fixup.h> #include <sbi_utils/fdt/fdt_helper.h> +#include <sbi_utils/gpio/fdt_gpio.h> #include <sbi_utils/irqchip/fdt_irqchip.h> #include <sbi_utils/serial/fdt_serial.h> #include <sbi_utils/timer/fdt_timer.h>
platform/generic/platform.c static int generic_early_init(bool cold_boot) · line 136
Quoted 8 lines
platform/generic/platform.c +2
-0@@ -128,6 +129,8 @@ static int generic_early_init(bool cold_boot)if (!cold_boot)return 0 ; +fdt_gpio_init (); +return fdt_reset_init (); }
Regards,
Bin
RFC PATCH 3/4 lib: utils: add gpio generic interface
In reply to Green WanQuoted 35 lines · Green Wan
Add generic interface for GPIO driver and add SiFive GPIO driver as an example. Currently, driver supports gpio output function only.
lib/utils/gpio/fdt_gpio.c:
- contains GPIO generic interfaces.
lib/utils/gpio/sifive_gpio.c:
- contains sifive GPIO driver.
platform/generic/platform.c:
- add entry of gpio initSigned-off-by Green Wan <[email protected]>---
include/sbi/sbi_gpio.h | 23 ++++++++++ include/sbi_utils/gpio/fdt_gpio.h | 32 ++++++++++++++ lib/utils/gpio/fdt_gpio.c | 55 ++++++++++++++++++++++++ lib/utils/gpio/objects.mk | 11 +++++ lib/utils/gpio/sifive_gpio.c | 70 +++++++++++++++++++++++++++++++ platform/generic/platform.c | 3 ++ 6 files changed, 194 insertions(+)create mode 100644
include/sbi/sbi_gpio.hcreate mode 100644include/sbi_utils/gpio/fdt_gpio.hcreate mode 100644lib/utils/gpio/fdt_gpio.ccreate mode 100644lib/utils/gpio/objects.mkcreate mode 100644lib/utils/gpio/sifive_gpio.cinclude/sbi/sbi_gpio.h new file +0
-0
include/sbi/sbi_gpio.h line 2
Quoted 2 lines
include/sbi/sbi_gpio.h new file +2
-0@@ -0,0 +1,23 @@ +/* +* SPDX-License-Identifier: GPL 2.0+
These files being GPL'ed isn?t going to fly.
Jess
RFC PATCH 4/4 lib: utils: add sifive reset device
In reply to Green WanAdd sifive reset device based on DT binding as below.
gpio-poweroff {
compatible = "gpio-poweroff";
gpios = <&gpio 2 GPIO_ACTIVE_LOW>;
};--- include/sbi_utils/sys/sifive_reset.h | 18 ++++++++ lib/utils/reset/fdt_reset.c | 2 + lib/utils/reset/fdt_reset_sifive.c | 47 ++++++++++++++++++++ lib/utils/reset/objects.mk | 1 + lib/utils/sys/objects.mk | 1 + lib/utils/sys/sifive_reset.c | 66 ++++++++++++++++++++++++++++ 6 files changed, 135 insertions(+) create mode 100644 include/sbi_utils/sys/sifive_reset.h create mode 100644 lib/utils/reset/fdt_reset_sifive.c create mode 100644 lib/utils/sys/sifive_reset.c
include/sbi_utils/sys/sifive_reset.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 SiFive +* +* Authors: +* Green Wan <[email protected]> +*/ + +#ifndef __SYS_SIFIVE_RESET_H__ +#define __SYS_SIFIVE_RESET_H__ + +#include <sbi/sbi_types.h> +#include <sbi_utils/fdt/fdt_helper.h> + +int sifive_reset_init_gpio (struct poweroff_gpio *ppwroff); + +#endif
lib/utils/reset/fdt_reset.c +2 -0
@@ -13,11 +13,13 @@#include <sbi_utils/reset/fdt_reset.h> extern struct fdt_reset fdt_reset_sifive_test; +extern struct fdt_reset fdt_reset_sifive;extern struct fdt_reset fdt_reset_htif;extern struct fdt_reset fdt_reset_thead;static struct fdt_reset *reset_drivers[] = { &fdt_reset_sifive_test, + &fdt_reset_sifive, &fdt_reset_htif, &fdt_reset_thead, };
lib/utils/reset/fdt_reset_sifive.c new file +47 -0
47 lines not on this page · raw message
lib/utils/reset/objects.mk +1 -0
@@ -10,5 +10,6 @@ libsbiutils-objs-y += reset/fdt_reset.o libsbiutils-objs-y += reset/fdt_reset_htif.o libsbiutils-objs-y += reset/fdt_reset_sifive_test.o +libsbiutils-objs-y += reset/fdt_reset_sifive.o libsbiutils-objs-y += reset/fdt_reset_thead.o libsbiutils-objs-y += reset/fdt_reset_thead_asm.o
lib/utils/sys/objects.mk +1 -0
@@ -9,3 +9,4 @@ libsbiutils-objs-y += sys/htif.o libsbiutils-objs-y += sys/sifive_test.o +libsbiutils-objs-y += sys/sifive_reset.o
lib/utils/sys/sifive_reset.c new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 4/4 lib: utils: add sifive reset device
lib/utils/reset/fdt_reset_sifive.c
Quoted 68 lines · Green Wan
Add sifive reset device based on DT binding as below.
gpio-poweroff { compatible = "gpio-poweroff"; gpios = <&gpio 2 GPIO_ACTIVE_LOW>; };Signed-off-by Green Wan <[email protected]>--- include/sbi_utils/sys/sifive_reset.h | 18 ++++++++ lib/utils/reset/fdt_reset.c | 2 + lib/utils/reset/fdt_reset_sifive.c | 47 ++++++++++++++++++++ lib/utils/reset/objects.mk | 1 + lib/utils/sys/objects.mk | 1 + lib/utils/sys/sifive_reset.c | 66 ++++++++++++++++++++++++++++ 6 files changed, 135 insertions(+) create mode 100644 include/sbi_utils/sys/sifive_reset.h create mode 100644 lib/utils/reset/fdt_reset_sifive.c create mode 100644 lib/utils/sys/sifive_reset.cinclude/sbi_utils/sys/sifive_reset.h new file +18
-0@@ -0,0 +1,18 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 SiFive +* +* Authors: +* Green Wan <[email protected]> +*/ + +#ifndef __SYS_SIFIVE_RESET_H__ +#define __SYS_SIFIVE_RESET_H__ + +#include <sbi/sbi_types.h> +#include <sbi_utils/fdt/fdt_helper.h> + +int sifive_reset_init_gpio (struct poweroff_gpio *ppwroff); + +#endif lib/utils/reset/fdt_reset.c +2
-0@@ -13,11 +13,13 @@#include <sbi_utils/reset/fdt_reset.h> extern struct fdt_reset fdt_reset_sifive_test; +extern struct fdt_reset fdt_reset_sifive;extern struct fdt_reset fdt_reset_htif;extern struct fdt_reset fdt_reset_thead;static struct fdt_reset *reset_drivers[] = { &fdt_reset_sifive_test, + &fdt_reset_sifive, &fdt_reset_htif, &fdt_reset_thead, };lib/utils/reset/fdt_reset_sifive.c new file +0
-0
I think this file should be renamed to fdt_reset_gpio, and used by any platform that implements /gpio-poweroff or /gpio-restart.
Quoted 131 lines
lib/utils/reset/fdt_reset_sifive.c new file +47
-0@@ -0,0 +1,47 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 SiFive +* +* Authors: +* Green Wan <[email protected]> +*/ + +#include <sbi/sbi_console.h> +#include <sbi/sbi_platform.h> +#include <sbi/sbi_scratch.h> +#include <sbi_utils/fdt/fdt_helper.h> +#include <sbi_utils/gpio/fdt_gpio.h> +#include <sbi_utils/reset/fdt_reset.h> +#include <sbi_utils/sys/sifive_reset.h> + +static struct poweroff_gpio pwroff = { + .act_delay =100 , + .gpio =-1 , + .output_type =GPIO_ACTIVE_LOW , +}; + +static int sifive_reset_init (void *fdt,int nodeoff, +const struct fdt_match *match) +{ +int rc; + + rc =fdt_parse_gpio_pwroff (fdt, &pwroff,"/gpio-poweroff" ); +if (rc) { +sbi_printf ("Warning: no gpio-poweroff definition in DT\n" ); + +return rc; + } + +return sifive_reset_init_gpio (&pwroff); +} + +static const struct fdt_match sifive_reset_match[] = { + { .compatible ="gpio-poweroff" }, + { }, +}; + +struct fdt_reset fdt_reset_sifive = { + .match_table = sifive_reset_match, + .init = sifive_reset_init, +};lib/utils/reset/objects.mk +1
-0@@ -10,5 +10,6 @@ libsbiutils-objs-y += reset/fdt_reset.o libsbiutils-objs-y += reset/fdt_reset_htif.o libsbiutils-objs-y += reset/fdt_reset_sifive_test.o +libsbiutils-objs-y += reset/fdt_reset_sifive.o libsbiutils-objs-y += reset/fdt_reset_thead.o libsbiutils-objs-y += reset/fdt_reset_thead_asm.olib/utils/sys/objects.mk +1
-0@@ -9,3 +9,4 @@ libsbiutils-objs-y += sys/htif.o libsbiutils-objs-y += sys/sifive_test.o +libsbiutils-objs-y += sys/sifive_reset.olib/utils/sys/sifive_reset.c new file +57
-0@@ -0,0 +1,66 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 SiFive +* +* Authors: +* Green Wan <[email protected]> +*/ + +#include <sbi/riscv_io.h> +#include <sbi/sbi_console.h> +#include <sbi/sbi_ecall_interface.h> +#include <sbi/sbi_platform.h> +#include <sbi/sbi_system.h> +#include <sbi_utils/gpio/fdt_gpio.h> +#include <sbi_utils/sys/sifive_reset.h> + +static struct poweroff_gpio *ppwroff; + +static int sifive_system_reset_check (u32 type,u32 reason) +{ +switch (type) { +case SBI_SRST_RESET_TYPE_SHUTDOWN : +case SBI_SRST_RESET_TYPE_COLD_REBOOT : +case SBI_SRST_RESET_TYPE_WARM_REBOOT : +return 1 ; + } + +return 0 ; +} + +static void sifive_system_reset (u32 type,u32 reason) +{ +switch (type) { +case SBI_SRST_RESET_TYPE_SHUTDOWN : +if (!ppwroff || ppwroff->gpio <0 ) +return ; + +if (ppwroff->output_type ==GPIO_ACTIVE_LOW ) +gpio_direction_output (ppwroff->gpio,0 ); +else +gpio_direction_output (ppwroff->gpio,1 ); + +/* if success, power is off now. */ +while (1 ) +wfi (); + +break ; +case SBI_SRST_RESET_TYPE_COLD_REBOOT : +case SBI_SRST_RESET_TYPE_WARM_REBOOT : +break ; + } +} + +static struct sbi_system_reset_device sifive_reset = { + .name ="sifive_reset" , + .system_reset_check = sifive_system_reset_check,
lib/utils/sys/sifive_reset.c
Quoted 10 lines
lib/utils/sys/sifive_reset.c new file +9
-1+ .system_reset = sifive_system_reset +}; + +int sifive_reset_init_gpio (struct poweroff_gpio *gpio) +{ + ppwroff = gpio; +sbi_system_reset_set_device (&sifive_reset); +return 0 ; +} --
Regards,
Bin
cover add sifive reset device
In reply to Green WanHi Green Wan,
Quoted 14 lines · Green Wan
To enable reset device for SiFive Unmatched board, the patchset starts with a preparetory patch [1/4] to unify the file and function names of current '
sifive_test' reset device.Then, adding 'gpio-poweroff' DT parsing and a gpio output interface to lib/utils in patch [2/4] and [3/4].
The reset device '
sifive_reset' is added in the last patch [4/4].'
sifive_reset' device usesgpio_direction_output()to do the reset. The entry point for GPIO initialization must be initialized first and is placed atpatform/generic/platform.c.
Quoted 8 lines
Current GPIO interface is simple and only ouput control callback is available.
Green Wan (4):
lib: utils: reset: unify naming of 'sifive_test' device
lib: utils: add GPIO and poweroff parsing
lib: utils: add gpio generic interface
lib: utils: add sifive reset device
The first patch was trivial so I have merged it.
For remaining three patches, we have following issues:
1) GPL is not compatible with BSD-2-clause so please use BSD-2-clause
2) We can have multiple users of GPIO devices so the probing of GPIO drivers should be on-demand from client driver (such as GPIO based reset driver)
3) If point#2 above is addressed then we will not require any GPIO code in generic SBI library (lib/sbi/ directory)
Let me re-factor your patches (of-course preserving your authorship) and send a v2. You can take-over from v2 series.
The approach we take for GPIO will also serve as guidance for I2C or SPI based reset.
Regards,
Anup
Quoted 34 lines
include/sbi/sbi_gpio.h | 23 ++++++++ include/sbi_utils/fdt/fdt_helper.h | 21 ++++++++ include/sbi_utils/gpio/fdt_gpio.h | 32 +++++++++++ include/sbi_utils/sys/sifive_reset.h | 18 +++++++ lib/utils/fdt/fdt_helper.c | 51 +++++++++++++++++- lib/utils/gpio/fdt_gpio.c | 55 +++++++++++++++++++ lib/utils/gpio/objects.mk | 11 ++++ lib/utils/gpio/sifive_gpio.c | 70 +++++++++++++++++++++++++ lib/utils/reset/fdt_reset.c | 2 + lib/utils/reset/fdt_reset_sifive.c | 37 ++++++++----- lib/utils/reset/fdt_reset_sifive_test.c | 36 +++++++++++++ lib/utils/reset/objects.mk | 1 + lib/utils/sys/objects.mk | 1 + lib/utils/sys/sifive_reset.c | 66 +++++++++++++++++++++++ platform/generic/platform.c | 3 ++ 15 files changed, 413 insertions(+), 14 deletions(-) create mode 100644 include/sbi/sbi_gpio.h create mode 100644 include/sbi_utils/gpio/fdt_gpio.h create mode 100644 include/sbi_utils/sys/sifive_reset.h create mode 100644 lib/utils/gpio/fdt_gpio.c create mode 100644 lib/utils/gpio/objects.mk create mode 100644 lib/utils/gpio/sifive_gpio.c create mode 100644 lib/utils/reset/fdt_reset_sifive_test.c create mode 100644 lib/utils/sys/sifive_reset.c--
2.17.1--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi