394af16e12afbc8d099f8a31314b7b049aecfda2
[oweals/openwrt.git] / target / linux / ipq806x / patches-5.4 / 0076-watchdog-qcom-wdt-disable-pretimeout-on-timer-platfo.patch
1 From 53ae145a7afa7686e03332d61eed90b7fa7c2529 Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Tue, 4 Feb 2020 19:38:06 +0100
4 Subject: [PATCH v2] watchdog: qcom-wdt: disable pretimeout on timer platform
5
6 Some platform like ipq806x doesn't support pretimeout and define
7 some interrupts used by qcom,msm-timer. Change the driver to check
8 and use pretimeout only on qcom,kpss-wdt as it's the only platform
9 that actually supports it.
10
11 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
12 ---
13  drivers/watchdog/qcom-wdt.c | 31 +++++++++++++++++++++++--------
14  1 file changed, 23 insertions(+), 8 deletions(-)
15
16 diff --git a/drivers/watchdog/qcom-wdt.c b/drivers/watchdog/qcom-wdt.c
17 index a494543d3ae1..d13c75028985 100644
18 --- a/drivers/watchdog/qcom-wdt.c
19 +++ b/drivers/watchdog/qcom-wdt.c
20 @@ -40,6 +40,11 @@ static const u32 reg_offset_data_kpss[] = {
21         [WDT_BITE_TIME] = 0x14,
22  };
23  
24 +struct qcom_wdt_match_data {
25 +       const u32 *offset;
26 +       bool pretimeout;
27 +};
28 +
29  struct qcom_wdt {
30         struct watchdog_device  wdd;
31         unsigned long           rate;
32 @@ -179,19 +184,29 @@ static void qcom_clk_disable_unprepare(void *data)
33         clk_disable_unprepare(data);
34  }
35  
36 +static const struct qcom_wdt_match_data match_data_apcs_tmr = {
37 +       .offset = reg_offset_data_apcs_tmr,
38 +       .pretimeout = false,
39 +};
40 +
41 +static const struct qcom_wdt_match_data match_data_kpss = {
42 +       .offset = reg_offset_data_kpss,
43 +       .pretimeout = true,
44 +};
45 +
46  static int qcom_wdt_probe(struct platform_device *pdev)
47  {
48         struct device *dev = &pdev->dev;
49         struct qcom_wdt *wdt;
50         struct resource *res;
51         struct device_node *np = dev->of_node;
52 -       const u32 *regs;
53 +       const struct qcom_wdt_match_data *data;
54         u32 percpu_offset;
55         int irq, ret;
56         struct clk *clk;
57  
58 -       regs = of_device_get_match_data(dev);
59 -       if (!regs) {
60 +       data = of_device_get_match_data(dev);
61 +       if (!data) {
62                 dev_err(dev, "Unsupported QCOM WDT module\n");
63                 return -ENODEV;
64         }
65 @@ -247,7 +262,7 @@ static int qcom_wdt_probe(struct platform_device *pdev)
66  
67         /* check if there is pretimeout support */
68         irq = platform_get_irq_optional(pdev, 0);
69 -       if (irq > 0) {
70 +       if (data->pretimeout && irq > 0) {
71                 ret = devm_request_irq(dev, irq, qcom_wdt_isr,
72                                        IRQF_TRIGGER_RISING,
73                                        "wdt_bark", &wdt->wdd);
74 @@ -267,7 +282,7 @@ static int qcom_wdt_probe(struct platform_device *pdev)
75         wdt->wdd.min_timeout = 1;
76         wdt->wdd.max_timeout = 0x10000000U / wdt->rate;
77         wdt->wdd.parent = dev;
78 -       wdt->layout = regs;
79 +       wdt->layout = data->offset;
80  
81         if (readl(wdt_addr(wdt, WDT_STS)) & 1)
82                 wdt->wdd.bootstatus = WDIOF_CARDRESET;
83 @@ -311,9 +326,9 @@ static int __maybe_unused qcom_wdt_resume(struct device *dev)
84  static SIMPLE_DEV_PM_OPS(qcom_wdt_pm_ops, qcom_wdt_suspend, qcom_wdt_resume);
85  
86  static const struct of_device_id qcom_wdt_of_table[] = {
87 -       { .compatible = "qcom,kpss-timer", .data = reg_offset_data_apcs_tmr },
88 -       { .compatible = "qcom,scss-timer", .data = reg_offset_data_apcs_tmr },
89 -       { .compatible = "qcom,kpss-wdt", .data = reg_offset_data_kpss },
90 +       { .compatible = "qcom,kpss-timer", .data = &match_data_apcs_tmr },
91 +       { .compatible = "qcom,scss-timer", .data = &match_data_apcs_tmr },
92 +       { .compatible = "qcom,kpss-wdt", .data = &match_data_kpss },
93         { },
94  };
95  MODULE_DEVICE_TABLE(of, qcom_wdt_of_table);
96 -- 
97 2.24.0
98