From a6c8b4becbd12fe6043557ca1e398c1a7c691007 Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Mon, 23 Mar 2020 22:38:08 +0100 Subject: nb/intel/sandybridge: Rewrite get_FRQ The code is just clamping the frequency index to a valid range. Do it with a helper function. Also, add a CPUID check, as Sandy Bridge will eventually use this code. Change-Id: I4c7aa5f7615c6edb1ab62fb004abb126df9d284b Signed-off-by: Angel Pons Reviewed-on: https://review.coreboot.org/c/coreboot/+/39787 Tested-by: build bot (Jenkins) Reviewed-by: Felix Held --- src/commonlib/include/commonlib/clamp.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/commonlib/include/commonlib/clamp.h (limited to 'src/commonlib') diff --git a/src/commonlib/include/commonlib/clamp.h b/src/commonlib/include/commonlib/clamp.h new file mode 100644 index 0000000000..e01a107ed4 --- /dev/null +++ b/src/commonlib/include/commonlib/clamp.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef COMMONLIB_CLAMP_H +#define COMMONLIB_CLAMP_H + +#include + +/* + * Clamp a value, so that it is between a lower and an upper bound. + */ +static inline u32 clamp_u32(const u32 min, const u32 val, const u32 max) +{ + if (val > max) + return max; + + if (val < min) + return min; + + return val; +} + +#endif /* COMMONLIB_CLAMP_H */ -- cgit v1.2.3