Cheng-Yi Chiang has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/36028 )
Change subject: google/chromeos: Add a library to get DSM calibration data ......................................................................
google/chromeos: Add a library to get DSM calibration data
On ChromeOS, there will be VPD values for DSM (dynamic speaker management) calibration data. They are resistor calibration values and temperature during calibration.
These VPD fields use "dsm_calib," prefix.
Known keys are
"dsm_calib, r0_0" "dsm_calib, r0_1" "dsm_calib, r0_2" "dsm_calib, r0_3" "dsm_calib, temp_0"
The values for unsigned long. This library will be used for RT1011 device driver in the patch series.
Signed-off-by: Cheng-Yi Chiang cychiang@chromium.org Change-Id: Ib9579a5cc055f8f438cb30a8acaf250a343db19e --- A src/include/dsm_calib.h M src/vendorcode/google/chromeos/Kconfig M src/vendorcode/google/chromeos/Makefile.inc A src/vendorcode/google/chromeos/dsm_calib.c 4 files changed, 80 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/28/36028/1
diff --git a/src/include/dsm_calib.h b/src/include/dsm_calib.h new file mode 100644 index 0000000..e398d87 --- /dev/null +++ b/src/include/dsm_calib.h @@ -0,0 +1,23 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2019 Google Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _DSM_CALIB_H_ +#define _DSM_CALIB_H_ + +#include <stdint.h> + +int get_dsm_calibration_from_key(const char *key, uint64_t *value); + +#endif /* _DSM_CALIB_H_ */ diff --git a/src/vendorcode/google/chromeos/Kconfig b/src/vendorcode/google/chromeos/Kconfig index 2ff7ec7..c7d3adf 100644 --- a/src/vendorcode/google/chromeos/Kconfig +++ b/src/vendorcode/google/chromeos/Kconfig @@ -95,5 +95,9 @@ help Use the AP watchdog flag stored in EC.
+config CHROMEOS_DSM_CALIB + bool + default n + endif # CHROMEOS endmenu diff --git a/src/vendorcode/google/chromeos/Makefile.inc b/src/vendorcode/google/chromeos/Makefile.inc index 000d056..05acdee 100644 --- a/src/vendorcode/google/chromeos/Makefile.inc +++ b/src/vendorcode/google/chromeos/Makefile.inc @@ -21,6 +21,7 @@ ramstage-$(CONFIG_CHROMEOS_DISABLE_PLATFORM_HIERARCHY_ON_RESUME) += tpm2.c ramstage-$(CONFIG_HAVE_REGULATORY_DOMAIN) += wrdd.c ramstage-$(CONFIG_USE_SAR) += sar.c +ramstage-$(CONFIG_CHROMEOS_DSM_CALIB) += dsm_calib.c ramstage-$(CONFIG_TPM_CR50) += cr50_enable_update.c ifeq ($(CONFIG_ARCH_MIPS),) bootblock-y += watchdog.c diff --git a/src/vendorcode/google/chromeos/dsm_calib.c b/src/vendorcode/google/chromeos/dsm_calib.c new file mode 100644 index 0000000..a4480bc --- /dev/null +++ b/src/vendorcode/google/chromeos/dsm_calib.c @@ -0,0 +1,52 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2019 Google Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <console/console.h> +#include <drivers/vpd/vpd.h> +#include <dsm_calib.h> +#include <stdint.h> +#include <string.h> + +#define DSM_BUF_LEN 128 +#define DSM_PREFIX "dsm_calib" + +int get_dsm_calibration_from_key(const char* key, uint64_t *value) +{ + char buf[DSM_BUF_LEN]; + char* ret; + long value_from_vpd; + + if (strncmp(key, DSM_PREFIX, strlen(DSM_PREFIX))) { + printk(BIOS_ERR, "@@ got invalid dsm_calib key: %s\n", key); + return -1; + } + + ret = vpd_gets(key, buf, DSM_BUF_LEN, VPD_RO); + if (!ret) { + printk(BIOS_ERR, "@@ failed to find key in VPD: %s\n", key); + return -1; + } + + value_from_vpd = atol(buf); + if (value < 0) { + printk(BIOS_ERR, "@@ got invalid dsm_calib from VPD: %ld\n", + value_from_vpd); + return -1; + } + + *value = value_from_vpd; + + return 0; +}