d44eb2118130572433d2ab4cab4cd7cae7ee4f9e
[openwrt/staging/noltari.git] /
1 From 15ff10623c83ee2e626d93d16e022b115dcb608f Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali@kernel.org>
3 Date: Sat, 10 Apr 2021 16:56:12 +0200
4 Subject: [PATCH] avs: Validate VDD value from OTP
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 CPU VDD voltage value for 1.2 GHz frequency on some Espressobin boards is
10 not set and raw value 0x00 is returned. In this case init_avs() function
11 calculated CPU VDD voltage value to 0x00 + AVS_VDD_BASE = 0.898 V, which is
12 too low for any operation and Espressobin board immediately crashed
13 init_avs() function set this low value.
14
15 This patch fixes above issue by validating returned VDD value from OTP and
16 using default VDD value when invalid value is in OTP. With this patch
17 init_avs() function does cause CPU crash anymore.
18
19 Signed-off-by: Pali Rohár <pali@kernel.org>
20 Signed-off-by: Marek Behún <marek.behun@nic.cz>
21 ---
22 wtmi/avs.c | 14 ++++++++++----
23 1 file changed, 10 insertions(+), 4 deletions(-)
24
25 diff --git a/wtmi/avs.c b/wtmi/avs.c
26 index 36ca9fa..4624359 100644
27 --- a/wtmi/avs.c
28 +++ b/wtmi/avs.c
29 @@ -140,10 +140,16 @@ int init_avs(u32 speed)
30 }
31
32 if (svc_rev >= SVC_REVISION_2) {
33 - vdd_otp = ((otp_data[OTP_DATA_SVC_SPEED_ID] >> shift) +
34 - AVS_VDD_BASE) & AVS_VDD_MASK;
35 - regval |= (vdd_otp << HIGH_VDD_LIMIT_OFF);
36 - regval |= (vdd_otp << LOW_VDD_LIMIT_OFF);
37 + vdd_otp = (otp_data[OTP_DATA_SVC_SPEED_ID] >> shift) &
38 + AVS_VDD_MASK;
39 + if (!vdd_otp || vdd_otp + AVS_VDD_BASE > AVS_VDD_MASK) {
40 + regval |= (vdd_default << HIGH_VDD_LIMIT_OFF);
41 + regval |= (vdd_default << LOW_VDD_LIMIT_OFF);
42 + } else {
43 + vdd_otp += AVS_VDD_BASE;
44 + regval |= (vdd_otp << HIGH_VDD_LIMIT_OFF);
45 + regval |= (vdd_otp << LOW_VDD_LIMIT_OFF);
46 + }
47 } else {
48 regval |= (vdd_default << HIGH_VDD_LIMIT_OFF);
49 regval |= (vdd_default << LOW_VDD_LIMIT_OFF);
50 --
51 2.30.2
52