sysinfo: Add gpio sysinfo driver
v2 cover sysinfo: Add gpio sysinfo driver
This series adds a GPIO sysinfo driver using the dm_gpio_get_values_as_int_base3 function. The board revision is mapped based in devicetree properties. This series is based on Simon's GPIO series [1].
[1] https://patchwork.ozlabs.org/project/uboot/list/?series=228126
Changes in v2:
- Document sysinfo_gpio_priv
- Enforce sysinfo detect ordering in uclass. Users must still call sysinfo_detect beforehand.
- Fix unbalanced brace in sysinfo_gpio_get_int
- Modify sysinfo test to check for detect() ordering.
- Refactor driver to take advantage of the uclass detect ordering guarantee.
- Reorder includes
- Set BOARD_HWVERSION to SYSINFO_ID_REVISION, as they represent the same content.
- Use enums instead of defines for sysinfo ids
Sean Anderson (5):
dm: gpio: Fix gpio_get_list_count failing with livetree
sysinfo: Provide some global/default IDs
sysinfo: Require that sysinfo_detect be called before other methods
sysinfo: Add gpio-sysinfo driver
test: Add gpio-sysinfo test
arch/sandbox/dts/test.dts | 7 + common/spl/spl_fit.c | 4 + .../sysinfo/gpio-sysinfo.txt | 37 +++++ drivers/gpio/gpio-uclass.c | 4 +- drivers/sysinfo/Kconfig | 8 + drivers/sysinfo/Makefile | 1 + drivers/sysinfo/gazerbeam.h | 8 +- drivers/sysinfo/gpio.c | 140 ++++++++++++++++++ drivers/sysinfo/sandbox.h | 2 +- drivers/sysinfo/sysinfo-uclass.c | 25 +++- include/sysinfo.h | 39 +++-- test/dm/Makefile | 1 + test/dm/sysinfo-gpio.c | 69 +++++++++ test/dm/sysinfo.c | 23 +-- 14 files changed, 343 insertions(+), 25 deletions(-) create mode 100644 doc/device-tree-bindings/sysinfo/gpio-sysinfo.txt create mode 100644 drivers/sysinfo/gpio.c create mode 100644 test/dm/sysinfo-gpio.c
Signature · 1 line
2.25.1
PATCH v2 1/5 dm: gpio: Fix gpio_get_list_count failing with livetree
of_parse_phandle_with_args (called by dev_read_phandle_with_args) does not support getting the length of a phandle list by using the index -1. Instead, use dev_count_phandle_with_args which supports exactly this use-case.
---
Changes in v2:
- Change Fixes tag to the most recent commit touching these lines
drivers/gpio/gpio-uclass.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpio-uclass.c +2 -2
@@ -1214,8 +1214,8 @@ int gpio_get_list_count(struct udevice *dev, const char *list_name) {int ret; - ret =dev_read_phandle_with_args (dev, list_name,"#gpio-cells" ,0 ,-1 , -NULL ); + ret =dev_count_phandle_with_args (dev, list_name,"#gpio-cells" , + -ENOENT );if (ret) {debug ("%s: Node '%s', property '%s', GPIO count failed: %d\n" , __func__, dev->name, list_name, ret);
Signature · 1 line
2.25.1
PATCH v2 2/5 sysinfo: Provide some global/default IDs
In reply to Sean AndersonThis adds an ID for a board revision. Existing IDs have been moved above SYSINFO_ID_END to allow for future expansion.
---
Changes in v2:
- Set BOARD_HWVERSION to SYSINFO_ID_REVISION, as they represent the same content.
- Use enums instead of defines for sysinfo ids
drivers/sysinfo/gazerbeam.h | 8 +++++--- drivers/sysinfo/sandbox.h | 2 +- include/sysinfo.h | 13 +++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-)
drivers/sysinfo/gazerbeam.h +5 -3
@@ -5,10 +5,12 @@* */ +#include <sysinfo.h> +enum { -BOARD_MULTICHANNEL , -BOARD_VARIANT , -BOARD_HWVERSION , +BOARD_HWVERSION =SYSINFO_ID_REVISION , +BOARD_MULTICHANNEL =SYSINFO_ID_END +1 , +BOARD_VARIANT };enum {
drivers/sysinfo/sandbox.h +1 -1
@@ -5,7 +5,7 @@*/ enum { -BOOL_CALLED_DETECT , +BOOL_CALLED_DETECT =SYSINFO_ID_END +1 ,INT_TEST1 ,INT_TEST2 ,STR_VACATIONSPOT ,
include/sysinfo.h +13 -0
@@ -32,6 +32,19 @@*/ #if CONFIG_IS_ENABLED (SYSINFO ) +/** +* enum sysinfo_id - IDs which may be passed to sysinfo accessors +*/ +enum sysinfo_id { +/** @SYSINFO_ID_REVISION: Use this ID to access the board revision. */ +SYSINFO_ID_REVISION , +/** +* @SYSINFO_ID_END: The last global sysinfo id. If you need to return +* custom information, use SYSINFO_ID_END+1 as the base offset. +*/ +SYSINFO_ID_END =127 , +}; + struct sysinfo_ops {/** * detect() - Run the hardware info detection procedure for this
Signature · 1 line
2.25.1
PATCH v2 2/5 sysinfo: Provide some global/default IDs
Quoted 12 lines · Sean Anderson
This adds an ID for a board revision. Existing IDs have been moved above
SYSINFO_ID_ENDto allow for future expansion.Signed-off-by Sean Anderson <[email protected]>---
Changes in v2:
- SetBOARD_HWVERSIONtoSYSINFO_ID_REVISION, as they represent the same content.
- Use enums instead of defines for sysinfo ids
Quoted 4 lines
drivers/sysinfo/gazerbeam.h | 8 +++++--- drivers/sysinfo/sandbox.h | 2 +- include/sysinfo.h | 13 +++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-)
PATCH v2 3/5 sysinfo: Require that sysinfo_detect be called before other methods
In reply to Sean AndersonThis has the uclass enforce calling detect() before other methods. This allows drivers to cache information in detect() and perform (cheaper) retrieval in the other accessors. This also modifies the only instance where this sequencing was not followed.
---
Changes in v2:
- Enforce sysinfo detect ordering in uclass. Users must still call sysinfo_detect beforehand.
- Modify sysinfo test to check for detect() ordering.
common/spl/spl_fit.c | 4 ++++ drivers/sysinfo/sysinfo-uclass.c | 25 ++++++++++++++++++++++++- include/sysinfo.h | 26 +++++++++++++++++--------- test/dm/sysinfo.c | 23 ++++++++++++++--------- 4 files changed, 59 insertions(+), 19 deletions(-)
common/spl/spl_fit.c +4 -0
@@ -116,6 +116,10 @@ static int spl_fit_get_image_name(const void *fit, int images,* no string in the property for this index. Check if the * sysinfo-level code can supply one. */ + rc =sysinfo_detect (sysinfo); +if (rc) +return rc; + rc =sysinfo_get_fit_loadable (sysinfo, index - i -1 , type, &str);if (rc && rc != -ENOENT )
drivers/sysinfo/sysinfo-uclass.c +24 -1
@@ -15,19 +15,29 @@ int sysinfo_get(struct udevice **devp)int sysinfo_detect (struct udevice *dev) { +int ret; +bool *detected =dev_get_uclass_priv (dev);struct sysinfo_ops *ops =sysinfo_get_ops (dev);if (!ops->detect)return -ENOSYS ; -return ops->detect (dev); + ret = ops->detect (dev); +if (!ret) + *detected = true; + +return ret; }int sysinfo_get_fit_loadable (struct udevice *dev,int index,const char *type,const char **strp) { +bool *detected =dev_get_uclass_priv (dev);struct sysinfo_ops *ops =sysinfo_get_ops (dev); +if (!*detected) +return -EPERM ; +if (!ops->get_fit_loadable)return -ENOSYS ;
@@ -36,8 +46,12 @@ int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,int sysinfo_get_bool (struct udevice *dev,int id,bool *val) { +bool *detected =dev_get_uclass_priv (dev);struct sysinfo_ops *ops =sysinfo_get_ops (dev); +if (!*detected) +return -EPERM ; +if (!ops->get_bool)return -ENOSYS ;
@@ -46,8 +60,12 @@ int sysinfo_get_bool(struct udevice *dev, int id, bool *val)int sysinfo_get_int (struct udevice *dev,int id,int *val) { +bool *detected =dev_get_uclass_priv (dev);struct sysinfo_ops *ops =sysinfo_get_ops (dev); +if (!*detected) +return -EPERM ; +if (!ops->get_int)return -ENOSYS ;
@@ -56,8 +74,12 @@ int sysinfo_get_int(struct udevice *dev, int id, int *val)int sysinfo_get_str (struct udevice *dev,int id,size_t size,char *val) { +bool *detected =dev_get_uclass_priv (dev);struct sysinfo_ops *ops =sysinfo_get_ops (dev); +if (!*detected) +return -EPERM ; +if (!ops->get_str)return -ENOSYS ;
@@ -68,4 +90,5 @@ UCLASS_DRIVER(sysinfo) = { .id = UCLASS_SYSINFO, .name = "sysinfo", .post_bind = dm_scan_fdt_dev, + .per_device_auto = sizeof(bool), };
include/sysinfo.h +17 -9
@@ -54,7 +54,8 @@ struct sysinfo_ops {* This operation might take a long time (e.g. read from EEPROM, * check the presence of a device on a bus etc.), hence this is not * done in the probe() method, but later during operation in this -* dedicated method. +* dedicated method. This method will be called before any other +* methods. * * Return: 0 if OK, -ve on error. */
@@ -98,7 +99,7 @@ struct sysinfo_ops {* get_fit_loadable - Get the name of an image to load from FIT * This function can be used to provide the image names based on runtime * detection. A classic use-case would when DTBOs are used to describe -* additionnal daughter cards. +* additional daughter cards. * * @dev: The sysinfo instance to gather the data. * @index: Index of the image. Starts at 0 and gets incremented
@@ -120,6 +121,9 @@ struct sysinfo_ops {* * @dev: The device containing the information * +* This function must be called before any other accessor function for this +* device. +* * Return: 0 if OK, -ve on error. */ int sysinfo_detect (struct udevice *dev);
@@ -131,7 +135,8 @@ int sysinfo_detect(struct udevice *dev);* @id: A unique identifier for the bool value to be read. * @val: Pointer to a buffer that receives the value read. * -* Return: 0 if OK, -ve on error. +* Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on +* error. */ int sysinfo_get_bool (struct udevice *dev,int id,bool *val);
@@ -142,7 +147,8 @@ int sysinfo_get_bool(struct udevice *dev, int id, bool *val);* @id: A unique identifier for the int value to be read. * @val: Pointer to a buffer that receives the value read. * -* Return: 0 if OK, -ve on error. +* Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on +* error. */ int sysinfo_get_int (struct udevice *dev,int id,int *val);
@@ -154,7 +160,8 @@ int sysinfo_get_int(struct udevice *dev, int id, int *val);* @size: The size of the buffer to receive the string data. * @val: Pointer to a buffer that receives the value read. * -* Return: 0 if OK, -ve on error. +* Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on +* error. */ int sysinfo_get_str (struct udevice *dev,int id,size_t size,char *val);
@@ -166,7 +173,8 @@ int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);* function that returns the unique device. This is especially useful for use * in sysinfo files. * -* Return: 0 if OK, -ve on error. +* Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on +* error. */ int sysinfo_get (struct udevice **devp);
@@ -174,7 +182,7 @@ int sysinfo_get(struct udevice **devp);* sysinfo_get_fit_loadable - Get the name of an image to load from FIT * This function can be used to provide the image names based on runtime * detection. A classic use-case would when DTBOs are used to describe -* additionnal daughter cards. +* additional daughter cards. * * @dev: The sysinfo instance to gather the data. * @index: Index of the image. Starts at 0 and gets incremented
@@ -183,8 +191,8 @@ int sysinfo_get(struct udevice **devp);* @strp: A pointer to string. Untouched if the function fails * * -* Return: 0 if OK, -ENOENT if no loadable is available else -ve on -* error. +* Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no +* loadable is available else -ve on error. */ int sysinfo_get_fit_loadable (struct udevice *dev,int index,const char *type,const char **strp);
test/dm/sysinfo.c +14 -9
@@ -24,33 +24,38 @@ static int dm_test_sysinfo(struct unit_test_state *uts)ut_assertok (sysinfo_get (&sysinfo));ut_assert (sysinfo); -sysinfo_get_bool (sysinfo,BOOL_CALLED_DETECT , &called_detect); +ut_asserteq (-EPERM ,sysinfo_get_bool (sysinfo,BOOL_CALLED_DETECT , + &called_detect));ut_assert (!called_detect);sysinfo_detect (sysinfo); -sysinfo_get_bool (sysinfo,BOOL_CALLED_DETECT , &called_detect); +ut_assertok (sysinfo_get_bool (sysinfo,BOOL_CALLED_DETECT , + &called_detect));ut_assert (called_detect); -sysinfo_get_str (sysinfo,STR_VACATIONSPOT ,sizeof (str), str); +ut_assertok (sysinfo_get_str (sysinfo,STR_VACATIONSPOT ,sizeof (str), + str));ut_assertok (strcmp (str,"R'lyeh" )); -sysinfo_get_int (sysinfo,INT_TEST1 , &i); +ut_assertok (sysinfo_get_int (sysinfo,INT_TEST1 , &i));ut_asserteq (0 , i); -sysinfo_get_int (sysinfo,INT_TEST2 , &i); +ut_assertok (sysinfo_get_int (sysinfo,INT_TEST2 , &i));ut_asserteq (100 , i); -sysinfo_get_str (sysinfo,STR_VACATIONSPOT ,sizeof (str), str); +ut_assertok (sysinfo_get_str (sysinfo,STR_VACATIONSPOT ,sizeof (str), + str));ut_assertok (strcmp (str,"Carcosa" )); -sysinfo_get_int (sysinfo,INT_TEST1 , &i); +ut_assertok (sysinfo_get_int (sysinfo,INT_TEST1 , &i));ut_asserteq (1 , i); -sysinfo_get_int (sysinfo,INT_TEST2 , &i); +ut_assertok (sysinfo_get_int (sysinfo,INT_TEST2 , &i));ut_asserteq (99 , i); -sysinfo_get_str (sysinfo,STR_VACATIONSPOT ,sizeof (str), str); +ut_assertok (sysinfo_get_str (sysinfo,STR_VACATIONSPOT ,sizeof (str), + str));ut_assertok (strcmp (str,"Yuggoth" ));return 0 ;
Signature · 1 line
2.25.1
PATCH v2 3/5 sysinfo: Require that sysinfo_detect be called before other methods
Quoted 14 lines · Sean Anderson
This has the uclass enforce calling
detect()before other methods. This allows drivers to cache information indetect()and perform (cheaper) retrieval in the other accessors. This also modifies the only instance where this sequencing was not followed.Signed-off-by Sean Anderson <[email protected]>---
Changes in v2:
- Enforce sysinfo detect ordering in uclass. Users must still callsysinfo_detectbeforehand.
- Modify sysinfo test to check fordetect()ordering.
Quoted 5 lines
common/spl/spl_fit.c | 4 ++++ drivers/sysinfo/sysinfo-uclass.c | 25 ++++++++++++++++++++++++- include/sysinfo.h | 26 +++++++++++++++++--------- test/dm/sysinfo.c | 23 ++++++++++++++--------- 4 files changed, 59 insertions(+), 19 deletions(-)
But please see below.
Quoted 21 lines
common/spl/spl_fit.c +4
-0@@ -116,6 +116,10 @@ static int spl_fit_get_image_name(const void *fit, int images,* no string in the property for this index. Check if the * sysinfo-level code can supply one. */ + rc =sysinfo_detect (sysinfo); +if (rc) +return rc; + rc =sysinfo_get_fit_loadable (sysinfo, index - i -1 , type, &str);if (rc && rc != -ENOENT )drivers/sysinfo/sysinfo-uclass.c +0
-0
drivers/sysinfo/sysinfo-uclass.c int sysinfo_get(struct udevice **devp) · line 19
Quoted 5 lines
drivers/sysinfo/sysinfo-uclass.c +2
-0@@ -15,19 +15,29 @@ int sysinfo_get(struct udevice **devp)int sysinfo_detect (struct udevice *dev) { +int ret; +bool *detected =dev_get_uclass_priv (dev);
I would argue for a struct with a bool in it here, instead of a raw bool.
Regards,
Simon
PATCH v2 4/5 sysinfo: Add gpio-sysinfo driver
In reply to Sean AndersonThis uses the newly-added dm_gpio_get_values_as_int_base3 function to implement a sysinfo device. The revision map is stored in the device tree.
---
Changes in v2:
- Document sysinfo_gpio_priv
- Fix unbalanced brace in sysinfo_gpio_get_int
- Refactor driver to take advantage of the uclass detect ordering guarantee.
- Reorder includes
.../sysinfo/gpio-sysinfo.txt | 37 +++++ drivers/sysinfo/Kconfig | 8 + drivers/sysinfo/Makefile | 1 + drivers/sysinfo/gpio.c | 140 ++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 doc/device-tree-bindings/sysinfo/gpio-sysinfo.txt create mode 100644 drivers/sysinfo/gpio.c
doc/device-tree-bindings/sysinfo/gpio-sysinfo.txt new file +37 -0
@@ -0,0 +1,37 @@ +GPIO-based Sysinfo device + +This binding describes several GPIOs which specify a board revision. Each GPIO +forms a digit in a ternary revision number. This revision is then mapped to a +name using the revisions and names properties. + +Each GPIO may be floating, pulled-up, or pulled-down, mapping to digits 2, 1, +and 0, respectively. The first GPIO forms the least-significant digit of the +revision. For example, consider the property + + gpios = <&gpio 0>, <&gpio 1>, <&gpio 2>; + +If GPIO 0 is pulled-up, GPIO 1 is pulled-down, and GPIO 2 is floating, then the +revision would be + + 0t201 = 2*9 + 0*3 + 1*3 = 19 + +If instead GPIO 0 is floating, GPIO 1 is pulled-up, and GPIO 2 is pulled-down, +then the revision would be + + 0t012 = 0*9 + 1*3 + 2*1 = 5 + +Required properties: +- compatible: should be "gpio-sysinfo". +- gpios: should be a list of gpios forming the revision number, + least-significant-digit first +- revisions: a list of known revisions; any revisions not present will have the + name "unknown" +- names: the name of each revision in revisions + +Example: +sysinfo { + compatible = "gpio-sysinfo"; + gpios = <&gpio_a 15>, <&gpio_a 16>, <&gpio_a 17>; + revisions = <19>, <5>; + names = "rev_a", "foo"; +};
drivers/sysinfo/Kconfig +8 -0
@@ -30,4 +30,12 @@ config SYSINFO_SMBIOS one which provides a way to specify this SMBIOS information in the devicetree, without needing any board-specific functionality. +config SYSINFO_GPIO + bool "Enable gpio sysinfo driver" + help + Support querying gpios to determine board revision. This uses gpios to + form a ternary number (when they are pulled-up, -down, or floating). + This ternary number is then mapped to a board revision name using + device tree properties. + endif
drivers/sysinfo/Makefile +1 -0
@@ -4,5 +4,6 @@ # Mario Six, Guntermann & Drunck GmbH, mario.six at gdsys.cc obj-y += sysinfo-uclass.o obj-$(CONFIG_SYSINFO_GAZERBEAM) += gazerbeam.o +obj-$(CONFIG_SYSINFO_GPIO) += gpio.o obj-$(CONFIG_SYSINFO_SANDBOX) += sandbox.o obj-$(CONFIG_SYSINFO_SMBIOS) += smbios.o
drivers/sysinfo/gpio.c new file +140 -0
140 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 5/5 test: Add gpio-sysinfo test
In reply to Sean AndersonThis adds a test for the gpio-sysinfo driver.
---
Changes in v2:
- Reorder includes
arch/sandbox/dts/test.dts | 7 ++++ test/dm/Makefile | 1 + test/dm/sysinfo-gpio.c | 69 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 test/dm/sysinfo-gpio.c
arch/sandbox/dts/test.dts +7 -0
@@ -1340,6 +1340,13 @@ compatible = "sandbox,sysinfo-sandbox"; }; + sysinfo-gpio { + compatible = "gpio-sysinfo"; + gpios = <&gpio_a 15>, <&gpio_a 16>, <&gpio_a 17>; + revisions = <19>, <5>; + names = "rev_a", "foo"; + }; + some_regmapped-bus { #address-cells = <0x1>; #size-cells = <0x1>;
test/dm/Makefile +1 -0
@@ -93,5 +93,6 @@ obj-$(CONFIG_SCMI_FIRMWARE) += scmi.o ifneq ($(CONFIG_PINMUX),) obj-$(CONFIG_PINCONF) += pinmux.o endif +obj-$(CONFIG_SYSINFO_GPIO) += sysinfo-gpio.o endif endif # !SPL
test/dm/sysinfo-gpio.c new file +69 -0
69 lines not on this page · raw message
Signature · 1 line
2.25.1