2c6e70b14d44d029ec9188f70d30789c96276d74
[openwrt/staging/981213.git] /
1 From e593e834fe8ba9bf314d8215ac05d8787f81efda Mon Sep 17 00:00:00 2001
2 From: Robert Marko <robimarko@gmail.com>
3 Date: Fri, 19 Aug 2022 00:02:42 +0200
4 Subject: [PATCH] thermal/drivers/tsens: Add support for combined interrupt
5
6 Despite using tsens v2.3 IP, IPQ8074 and IPQ6018 only have one IRQ for
7 signaling both up/low and critical trips.
8
9 Signed-off-by: Robert Marko <robimarko@gmail.com>
10 Reviewed-by: Bjorn Andersson <andersson@kernel.org>
11 Link: https://lore.kernel.org/r/20220818220245.338396-2-robimarko@gmail.com
12 Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
13 ---
14 drivers/thermal/qcom/tsens-8960.c | 1 +
15 drivers/thermal/qcom/tsens-v0_1.c | 1 +
16 drivers/thermal/qcom/tsens-v1.c | 1 +
17 drivers/thermal/qcom/tsens-v2.c | 1 +
18 drivers/thermal/qcom/tsens.c | 38 ++++++++++++++++++++++++++-----
19 drivers/thermal/qcom/tsens.h | 2 ++
20 6 files changed, 38 insertions(+), 6 deletions(-)
21
22 --- a/drivers/thermal/qcom/tsens-8960.c
23 +++ b/drivers/thermal/qcom/tsens-8960.c
24 @@ -269,6 +269,7 @@ static const struct tsens_ops ops_8960 =
25 static struct tsens_features tsens_8960_feat = {
26 .ver_major = VER_0,
27 .crit_int = 0,
28 + .combo_int = 0,
29 .adc = 1,
30 .srot_split = 0,
31 .max_sensors = 11,
32 --- a/drivers/thermal/qcom/tsens-v0_1.c
33 +++ b/drivers/thermal/qcom/tsens-v0_1.c
34 @@ -549,6 +549,7 @@ static int __init init_8939(struct tsens
35 static struct tsens_features tsens_v0_1_feat = {
36 .ver_major = VER_0_1,
37 .crit_int = 0,
38 + .combo_int = 0,
39 .adc = 1,
40 .srot_split = 1,
41 .max_sensors = 11,
42 --- a/drivers/thermal/qcom/tsens-v1.c
43 +++ b/drivers/thermal/qcom/tsens-v1.c
44 @@ -273,6 +273,7 @@ static int calibrate_8976(struct tsens_p
45 static struct tsens_features tsens_v1_feat = {
46 .ver_major = VER_1_X,
47 .crit_int = 0,
48 + .combo_int = 0,
49 .adc = 1,
50 .srot_split = 1,
51 .max_sensors = 11,
52 --- a/drivers/thermal/qcom/tsens-v2.c
53 +++ b/drivers/thermal/qcom/tsens-v2.c
54 @@ -31,6 +31,7 @@
55 static struct tsens_features tsens_v2_feat = {
56 .ver_major = VER_2_X,
57 .crit_int = 1,
58 + .combo_int = 0,
59 .adc = 0,
60 .srot_split = 1,
61 .max_sensors = 16,
62 --- a/drivers/thermal/qcom/tsens.c
63 +++ b/drivers/thermal/qcom/tsens.c
64 @@ -531,6 +531,27 @@ static irqreturn_t tsens_irq_thread(int
65 return IRQ_HANDLED;
66 }
67
68 +/**
69 + * tsens_combined_irq_thread() - Threaded interrupt handler for combined interrupts
70 + * @irq: irq number
71 + * @data: tsens controller private data
72 + *
73 + * Handle the combined interrupt as if it were 2 separate interrupts, so call the
74 + * critical handler first and then the up/low one.
75 + *
76 + * Return: IRQ_HANDLED
77 + */
78 +static irqreturn_t tsens_combined_irq_thread(int irq, void *data)
79 +{
80 + irqreturn_t ret;
81 +
82 + ret = tsens_critical_irq_thread(irq, data);
83 + if (ret != IRQ_HANDLED)
84 + return ret;
85 +
86 + return tsens_irq_thread(irq, data);
87 +}
88 +
89 static int tsens_set_trips(void *_sensor, int low, int high)
90 {
91 struct tsens_sensor *s = _sensor;
92 @@ -1081,13 +1102,18 @@ static int tsens_register(struct tsens_p
93 tsens_mC_to_hw(priv->sensor, 0));
94 }
95
96 - ret = tsens_register_irq(priv, "uplow", tsens_irq_thread);
97 - if (ret < 0)
98 - return ret;
99 + if (priv->feat->combo_int) {
100 + ret = tsens_register_irq(priv, "combined",
101 + tsens_combined_irq_thread);
102 + } else {
103 + ret = tsens_register_irq(priv, "uplow", tsens_irq_thread);
104 + if (ret < 0)
105 + return ret;
106
107 - if (priv->feat->crit_int)
108 - ret = tsens_register_irq(priv, "critical",
109 - tsens_critical_irq_thread);
110 + if (priv->feat->crit_int)
111 + ret = tsens_register_irq(priv, "critical",
112 + tsens_critical_irq_thread);
113 + }
114
115 return ret;
116 }
117 --- a/drivers/thermal/qcom/tsens.h
118 +++ b/drivers/thermal/qcom/tsens.h
119 @@ -495,6 +495,7 @@ enum regfield_ids {
120 * struct tsens_features - Features supported by the IP
121 * @ver_major: Major number of IP version
122 * @crit_int: does the IP support critical interrupts?
123 + * @combo_int: does the IP use one IRQ for up, low and critical thresholds?
124 * @adc: do the sensors only output adc code (instead of temperature)?
125 * @srot_split: does the IP neatly splits the register space into SROT and TM,
126 * with SROT only being available to secure boot firmware?
127 @@ -504,6 +505,7 @@ enum regfield_ids {
128 struct tsens_features {
129 unsigned int ver_major;
130 unsigned int crit_int:1;
131 + unsigned int combo_int:1;
132 unsigned int adc:1;
133 unsigned int srot_split:1;
134 unsigned int has_watchdog:1;