From cfde82c1d74bf044bf849adaaf44fc3a268ec10f Mon Sep 17 00:00:00 2001 From: Cheng-Yi Chiang Date: Mon, 14 Oct 2019 12:10:51 +0800 Subject: google/chromeos: Add a library to get DSM calibration data On ChromeOS, there will be VPD values for dynamic speaker management (DSM) 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" For now these values are unsigned decimal numbers greater than 0. This library will be used for RT1011 device driver in the patch series. Note that in the future we may encode more values into this VPD field if needed. We retain the flexibility for coreboot device driver or codec driver to decode/parse the VPD values based on the needed use case per-board. BUG=b:140397934 BRANCH=none TEST=On Helios, with patch series, check realtek,r0_calib and realtek,temperature_calib are available to rt1011 codec driver. Signed-off-by: Cheng-Yi Chiang Change-Id: Ib9579a5cc055f8f438cb30a8acaf250a343db19e Reviewed-on: https://review.coreboot.org/c/coreboot/+/36028 Tested-by: build bot (Jenkins) Reviewed-by: Paul Fagerburg Reviewed-by: Furquan Shaikh --- src/vendorcode/google/chromeos/dsm_calib.c | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/vendorcode/google/chromeos/dsm_calib.c (limited to 'src/vendorcode/google/chromeos/dsm_calib.c') diff --git a/src/vendorcode/google/chromeos/dsm_calib.c b/src/vendorcode/google/chromeos/dsm_calib.c new file mode 100644 index 0000000000..d3b14cb03c --- /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 +#include +#include +#include +#include +#include + +#define DSM_BUF_LEN 128 +#define DSM_PREFIX "dsm_calib_" + +enum cb_err get_dsm_calibration_from_key(const char *key, uint64_t *value) +{ + static 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 CB_ERR; + } + + 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 CB_ERR; + } + + value_from_vpd = atol(buf); + if (value_from_vpd <= 0) { + printk(BIOS_ERR, "got invalid dsm_calib from VPD: %ld\n", value_from_vpd); + return CB_ERR; + } + + *value = value_from_vpd; + + return CB_SUCCESS; +} -- cgit v1.2.3