1ef46d9be378e54e402f9ad8b368776cda89b03a
[openwrt/openwrt.git] / target / linux / ipq40xx / patches-6.1 / 004-v6.7-firmware-qcom_scm-disable-SDI-if-required.patch
1 From ff4aa3bc98258a240b9bbab53fd8d2fb8184c485 Mon Sep 17 00:00:00 2001
2 From: Robert Marko <robimarko@gmail.com>
3 Date: Wed, 16 Aug 2023 18:45:39 +0200
4 Subject: [PATCH] firmware: qcom_scm: disable SDI if required
5
6 IPQ5018 has SDI (Secure Debug Image) enabled by TZ by default, and that
7 means that WDT being asserted or just trying to reboot will hang the board
8 in the debug mode and only pulling the power and repowering will help.
9 Some IPQ4019 boards like Google WiFI have it enabled as well.
10
11 Luckily, SDI can be disabled via an SCM call.
12
13 So, lets use the boolean DT property to identify boards that have SDI
14 enabled by default and use the SCM call to disable SDI during SCM probe.
15 It is important to disable it as soon as possible as we might have a WDT
16 assertion at any time which would then leave the board in debug mode,
17 thus disabling it during SCM removal is not enough.
18
19 Signed-off-by: Robert Marko <robimarko@gmail.com>
20 Reviewed-by: Guru Das Srinagesh <quic_gurus@quicinc.com>
21 Link: https://lore.kernel.org/r/20230816164641.3371878-2-robimarko@gmail.com
22 Signed-off-by: Bjorn Andersson <andersson@kernel.org>
23 ---
24 drivers/firmware/qcom_scm.c | 30 ++++++++++++++++++++++++++++++
25 drivers/firmware/qcom_scm.h | 1 +
26 2 files changed, 31 insertions(+)
27
28 --- a/drivers/firmware/qcom_scm.c
29 +++ b/drivers/firmware/qcom_scm.c
30 @@ -400,6 +400,29 @@ int qcom_scm_set_remote_state(u32 state,
31 }
32 EXPORT_SYMBOL(qcom_scm_set_remote_state);
33
34 +static int qcom_scm_disable_sdi(void)
35 +{
36 + int ret;
37 + struct qcom_scm_desc desc = {
38 + .svc = QCOM_SCM_SVC_BOOT,
39 + .cmd = QCOM_SCM_BOOT_SDI_CONFIG,
40 + .args[0] = 1, /* Disable watchdog debug */
41 + .args[1] = 0, /* Disable SDI */
42 + .arginfo = QCOM_SCM_ARGS(2),
43 + .owner = ARM_SMCCC_OWNER_SIP,
44 + };
45 + struct qcom_scm_res res;
46 +
47 + ret = qcom_scm_clk_enable();
48 + if (ret)
49 + return ret;
50 + ret = qcom_scm_call(__scm->dev, &desc, &res);
51 +
52 + qcom_scm_clk_disable();
53 +
54 + return ret ? : res.result[0];
55 +}
56 +
57 static int __qcom_scm_set_dload_mode(struct device *dev, bool enable)
58 {
59 struct qcom_scm_desc desc = {
60 @@ -1404,6 +1427,13 @@ static int qcom_scm_probe(struct platfor
61
62 __get_convention();
63
64 +
65 + /*
66 + * Disable SDI if indicated by DT that it is enabled by default.
67 + */
68 + if (of_property_read_bool(pdev->dev.of_node, "qcom,sdi-enabled"))
69 + qcom_scm_disable_sdi();
70 +
71 /*
72 * If requested enable "download mode", from this point on warmboot
73 * will cause the boot stages to enter download mode, unless
74 --- a/drivers/firmware/qcom_scm.h
75 +++ b/drivers/firmware/qcom_scm.h
76 @@ -77,6 +77,7 @@ extern int scm_legacy_call(struct device
77 #define QCOM_SCM_SVC_BOOT 0x01
78 #define QCOM_SCM_BOOT_SET_ADDR 0x01
79 #define QCOM_SCM_BOOT_TERMINATE_PC 0x02
80 +#define QCOM_SCM_BOOT_SDI_CONFIG 0x09
81 #define QCOM_SCM_BOOT_SET_DLOAD_MODE 0x10
82 #define QCOM_SCM_BOOT_SET_ADDR_MC 0x11
83 #define QCOM_SCM_BOOT_SET_REMOTE_STATE 0x0a