diff options
author | Jonathan Zhang <jonzhang@meta.com> | 2022-10-24 17:08:47 -0700 |
---|---|---|
committer | Martin L Roth <gaumless@gmail.com> | 2022-12-22 18:52:00 +0000 |
commit | eacd74f22348f664ffdc3a797511c02e2c623c24 (patch) | |
tree | b0231dfad325a4ddf8e207f0e7d25e860a7ee13b /src/drivers/ocp/vpd | |
parent | fb2ebbced7f64218667d5647f39c3d49d57a3159 (diff) |
drivers/ocp: add VPD processing framework
Add VPD processing framework to be shared by OCP mainboards:
* define VPD configuration items in vpd.h.
* add helper functions:
** get_bool_from_vpd()
** get_int_from_vpd_range()
Change-Id: I705bea348b1611f25ccbd798b77cfee22ec30f0f
Signed-off-by: Johnny Lin <johnny_lin@wiwynn.com>
Signed-off-by: Tim Chu <Tim.Chu@quantatw.com>
Signed-off-by: Marc Jones <marcjones@sysproconsulting.com>
Signed-off-by: Jonathan Zhang <jonzhang@meta.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/68784
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: David Hendricks <david.hendricks@gmail.com>
Diffstat (limited to 'src/drivers/ocp/vpd')
-rw-r--r-- | src/drivers/ocp/vpd/Kconfig | 6 | ||||
-rw-r--r-- | src/drivers/ocp/vpd/Makefile.inc | 2 | ||||
-rw-r--r-- | src/drivers/ocp/vpd/vpd_util.c | 40 |
3 files changed, 48 insertions, 0 deletions
diff --git a/src/drivers/ocp/vpd/Kconfig b/src/drivers/ocp/vpd/Kconfig new file mode 100644 index 0000000000..ebecbe6962 --- /dev/null +++ b/src/drivers/ocp/vpd/Kconfig @@ -0,0 +1,6 @@ +config OCP_VPD + bool + default n + depends on VPD + help + It implements functions that get common VPD variables for OCP projects. diff --git a/src/drivers/ocp/vpd/Makefile.inc b/src/drivers/ocp/vpd/Makefile.inc new file mode 100644 index 0000000000..c34866ff38 --- /dev/null +++ b/src/drivers/ocp/vpd/Makefile.inc @@ -0,0 +1,2 @@ +romstage-$(CONFIG_OCP_VPD) += vpd_util.c +ramstage-$(CONFIG_OCP_VPD) += vpd_util.c diff --git a/src/drivers/ocp/vpd/vpd_util.c b/src/drivers/ocp/vpd/vpd_util.c new file mode 100644 index 0000000000..3a66b884f2 --- /dev/null +++ b/src/drivers/ocp/vpd/vpd_util.c @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <console/console.h> +#include <drivers/vpd/vpd.h> +#include <drivers/ocp/include/vpd.h> + +int get_int_from_vpd_range(const char *const key, const int fallback, const int min, + const int max) +{ + int val = fallback; + + if (!vpd_get_int(key, VPD_RW_THEN_RO, &val)) + printk(BIOS_INFO, "%s: not able to get VPD %s, default set to %d\n", + __func__, key, fallback); + else + printk(BIOS_DEBUG, "%s: VPD %s, got %d\n", __func__, key, val); + + if (val < min || val > max) { + printk(BIOS_INFO, "Invalid VPD %s value, set default value to %d\n", + key, fallback); + val = fallback; + } + + return val; +} + +bool get_bool_from_vpd(const char *const key, const bool fallback) +{ + uint8_t val; + + val = (uint8_t)fallback; + + if (!vpd_get_bool(key, VPD_RW_THEN_RO, &val)) + printk(BIOS_INFO, "%s: not able to get VPD %s, default set to %d\n", + __func__, key, fallback); + else + printk(BIOS_DEBUG, "%s: VPD %s, got %d\n", __func__, key, val); + + return (bool)val; +} |