Skip to content

Commit 171cad9

Browse files
thermal: qcom: tsens: Add support for IPQ5018 tsens
Refreshing patches accepted upstream for IPQ5332 and IPQ5424. IPQ5018 has tsens V1.0 IP with 5 sensors enabled and 1 interrupt. There is no RPM present in the soc to do tsens early enable. Adding support for the same here. Signed-off-by: George Moussalem <george.moussalem@outlook.com>
1 parent 5caadde commit 171cad9

5 files changed

+178
-125
lines changed

target/linux/qualcommax/patches-6.6/0151-dt-bindings-thermal-qcom-tsens-Add-ipq5018-compatible.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Signed-off-by: Sricharan Ramabadhran <quic_srichara@quicinc.com>
1616
- qcom,msm8956-tsens
1717
- qcom,msm8976-tsens
1818
- qcom,qcs404-tsens
19-
@@ -232,6 +233,7 @@ allOf:
19+
@@ -246,6 +247,7 @@ allOf:
2020
compatible:
2121
contains:
2222
enum:

target/linux/qualcommax/patches-6.6/0152-thermal-qcom-add-new-feat-for-soc-without-rpm.patch

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
From: Sricharan Ramabadhran <quic_srichara@quicinc.com>
2+
Subject: [PATCH] thermal/drivers/tsens: Add support for IPQ5018 tsens
3+
Date: Fri, 22 Sep 2023 17:21:15 +0530
4+
5+
IPQ5018 has tsens IP V1.0, 4 sensors and 1 interrupt.
6+
The soc does not have a RPM, hence tsens has to be reset and
7+
enabled in the driver init. Adding the driver support for same.
8+
9+
Signed-off-by: Sricharan Ramabadhran <quic_srichara@quicinc.com>
10+
---
11+
drivers/thermal/qcom/tsens-v1.c | 60 +++++++++++++++++++++++++++++++++
12+
drivers/thermal/qcom/tsens.c | 3 ++
13+
drivers/thermal/qcom/tsens.h | 2 +-
14+
3 files changed, 64 insertions(+), 1 deletion(-)
15+
16+
--- a/drivers/thermal/qcom/tsens-v1.c
17+
+++ b/drivers/thermal/qcom/tsens-v1.c
18+
@@ -79,6 +79,17 @@ static struct tsens_features tsens_v1_fe
19+
.trip_max_temp = 120000,
20+
};
21+
22+
+static struct tsens_features tsens_v1_no_rpm_feat = {
23+
+ .ver_major = VER_1_X_NO_RPM,
24+
+ .crit_int = 0,
25+
+ .combo_int = 0,
26+
+ .adc = 1,
27+
+ .srot_split = 1,
28+
+ .max_sensors = 11,
29+
+ .trip_min_temp = -40000,
30+
+ .trip_max_temp = 120000,
31+
+};
32+
+
33+
static const struct reg_field tsens_v1_regfields[MAX_REGFIELDS] = {
34+
/* ----- SROT ------ */
35+
/* VERSION */
36+
@@ -150,6 +161,43 @@ static int __init init_8956(struct tsens
37+
return init_common(priv);
38+
}
39+
40+
+static int __init init_tsens_v1_no_rpm(struct tsens_priv *priv)
41+
+{
42+
+ int i, ret;
43+
+ u32 mask = 0;
44+
+
45+
+ ret = init_common(priv);
46+
+ if (ret < 0) {
47+
+ dev_err(priv->dev, "Init common failed %d\n", ret);
48+
+ return ret;
49+
+ }
50+
+
51+
+ ret = regmap_field_write(priv->rf[TSENS_SW_RST], 1);
52+
+ if (ret) {
53+
+ dev_err(priv->dev, "Reset failed\n");
54+
+ return ret;
55+
+ }
56+
+
57+
+ for (i = 0; i < priv->num_sensors; i++)
58+
+ mask |= BIT(priv->sensor[i].hw_id);
59+
+
60+
+ ret = regmap_field_update_bits(priv->rf[SENSOR_EN], mask, mask);
61+
+ if (ret) {
62+
+ dev_err(priv->dev, "Sensor Enable failed\n");
63+
+ return ret;
64+
+ }
65+
+
66+
+ ret = regmap_field_write(priv->rf[TSENS_EN], 1);
67+
+ if (ret) {
68+
+ dev_err(priv->dev, "Enable failed\n");
69+
+ return ret;
70+
+ }
71+
+
72+
+ ret = regmap_field_write(priv->rf[TSENS_SW_RST], 0);
73+
+
74+
+ return ret;
75+
+}
76+
+
77+
static const struct tsens_ops ops_generic_v1 = {
78+
.init = init_common,
79+
.calibrate = calibrate_v1,
80+
--- a/drivers/thermal/qcom/tsens.c
81+
+++ b/drivers/thermal/qcom/tsens.c
82+
@@ -446,7 +446,7 @@ static void tsens_set_interrupt(struct t
83+
dev_dbg(priv->dev, "[%u] %s: %s -> %s\n", hw_id, __func__,
84+
irq_type ? ((irq_type == 1) ? "UP" : "CRITICAL") : "LOW",
85+
enable ? "en" : "dis");
86+
- if (tsens_version(priv) > VER_1_X)
87+
+ if (tsens_version(priv) > VER_1_X_NO_RPM)
88+
tsens_set_interrupt_v2(priv, hw_id, irq_type, enable);
89+
else
90+
tsens_set_interrupt_v1(priv, hw_id, irq_type, enable);
91+
@@ -498,7 +498,7 @@ static int tsens_read_irq_state(struct t
92+
ret = regmap_field_read(priv->rf[LOW_INT_CLEAR_0 + hw_id], &d->low_irq_clear);
93+
if (ret)
94+
return ret;
95+
- if (tsens_version(priv) > VER_1_X) {
96+
+ if (tsens_version(priv) > VER_1_X_NO_RPM) {
97+
ret = regmap_field_read(priv->rf[UP_INT_MASK_0 + hw_id], &d->up_irq_mask);
98+
if (ret)
99+
return ret;
100+
@@ -542,7 +542,7 @@ static int tsens_read_irq_state(struct t
101+
102+
static inline u32 masked_irq(u32 hw_id, u32 mask, enum tsens_ver ver)
103+
{
104+
- if (ver > VER_1_X)
105+
+ if (ver > VER_1_X_NO_RPM)
106+
return mask & (1 << hw_id);
107+
108+
/* v1, v0.1 don't have a irq mask register */
109+
@@ -732,7 +732,7 @@ static int tsens_set_trips(struct therma
110+
static int tsens_enable_irq(struct tsens_priv *priv)
111+
{
112+
int ret;
113+
- int val = tsens_version(priv) > VER_1_X ? 7 : 1;
114+
+ int val = tsens_version(priv) > VER_1_X_NO_RPM ? 7 : 1;
115+
116+
ret = regmap_field_write(priv->rf[INT_EN], val);
117+
if (ret < 0)
118+
@@ -974,10 +974,16 @@ int __init init_common(struct tsens_priv
119+
ret = regmap_field_read(priv->rf[TSENS_EN], &enabled);
120+
if (ret)
121+
goto err_put_device;
122+
- if (!enabled && (tsens_version(priv) != VER_2_X_NO_RPM)) {
123+
- dev_err(dev, "%s: device not enabled\n", __func__);
124+
- ret = -ENODEV;
125+
- goto err_put_device;
126+
+ if (!enabled) {
127+
+ switch (tsens_version(priv)) {
128+
+ case VER_1_X_NO_RPM:
129+
+ case VER_2_X_NO_RPM:
130+
+ break;
131+
+ default:
132+
+ dev_err(dev, "%s: device not enabled\n", __func__);
133+
+ ret = -ENODEV;
134+
+ goto err_put_device;
135+
+ }
136+
}
137+
138+
priv->rf[SENSOR_EN] = devm_regmap_field_alloc(dev, priv->srot_map,
139+
@@ -1039,7 +1045,7 @@ int __init init_common(struct tsens_priv
140+
}
141+
}
142+
143+
- if (tsens_version(priv) > VER_1_X && ver_minor > 2) {
144+
+ if (tsens_version(priv) > VER_1_X_NO_RPM && ver_minor > 2) {
145+
/* Watchdog is present only on v2.3+ */
146+
priv->feat->has_watchdog = 1;
147+
for (i = WDOG_BARK_STATUS; i <= CC_MON_MASK; i++) {
148+
--- a/drivers/thermal/qcom/tsens.h
149+
+++ b/drivers/thermal/qcom/tsens.h
150+
@@ -34,6 +34,7 @@ enum tsens_ver {
151+
VER_0 = 0,
152+
VER_0_1,
153+
VER_1_X,
154+
+ VER_1_X_NO_RPM,
155+
VER_2_X,
156+
VER_2_X_NO_RPM,
157+
};

target/linux/qualcommax/patches-6.6/0153-thermal-qcom-tsens-add-support-for-IPQ5018-tsens.patch

Lines changed: 14 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -15,104 +15,45 @@ Signed-off-by: Sricharan Ramabadhran <quic_srichara@quicinc.com>
1515

1616
--- a/drivers/thermal/qcom/tsens-v1.c
1717
+++ b/drivers/thermal/qcom/tsens-v1.c
18-
@@ -79,6 +79,18 @@ static struct tsens_features tsens_v1_fe
19-
.trip_max_temp = 120000,
20-
};
21-
22-
+static struct tsens_features tsens_v1_ipq5018_feat = {
23-
+ .ver_major = VER_1_X,
24-
+ .crit_int = 0,
25-
+ .combo_int = 0,
26-
+ .adc = 1,
27-
+ .srot_split = 1,
28-
+ .max_sensors = 11,
29-
+ .trip_min_temp = -40000,
30-
+ .trip_max_temp = 120000,
31-
+ .ignore_enable = 1,
32-
+};
33-
+
34-
static const struct reg_field tsens_v1_regfields[MAX_REGFIELDS] = {
35-
/* ----- SROT ------ */
36-
/* VERSION */
37-
@@ -150,6 +162,41 @@ static int __init init_8956(struct tsens
38-
return init_common(priv);
39-
}
40-
41-
+static int __init init_ipq5018(struct tsens_priv *priv)
42-
+{
43-
+ int ret;
44-
+ u32 mask;
45-
+
46-
+ ret = init_common(priv);
47-
+ if (ret < 0) {
48-
+ dev_err(priv->dev, "Init common failed %d\n", ret);
49-
+ return ret;
50-
+ }
51-
+
52-
+ ret = regmap_field_write(priv->rf[TSENS_SW_RST], 1);
53-
+ if (ret) {
54-
+ dev_err(priv->dev, "Reset failed\n");
55-
+ return ret;
56-
+ }
57-
+
58-
+ mask = GENMASK(priv->num_sensors, 0);
59-
+ ret = regmap_field_update_bits(priv->rf[SENSOR_EN], mask, mask);
60-
+ if (ret) {
61-
+ dev_err(priv->dev, "Sensor Enable failed\n");
62-
+ return ret;
63-
+ }
64-
+
65-
+ ret = regmap_field_write(priv->rf[TSENS_EN], 1);
66-
+ if (ret) {
67-
+ dev_err(priv->dev, "Enable failed\n");
68-
+ return ret;
69-
+ }
70-
+
71-
+ ret = regmap_field_write(priv->rf[TSENS_SW_RST], 0);
72-
+
73-
+ return ret;
74-
+}
75-
+
76-
static const struct tsens_ops ops_generic_v1 = {
77-
.init = init_common,
78-
.calibrate = calibrate_v1,
79-
@@ -194,3 +241,16 @@ struct tsens_plat_data data_8976 = {
18+
@@ -242,3 +242,17 @@ struct tsens_plat_data data_8976 = {
8019
.feat = &tsens_v1_feat,
8120
.fields = tsens_v1_regfields,
8221
};
8322
+
8423
+const struct tsens_ops ops_ipq5018 = {
85-
+ .init = init_ipq5018,
24+
+ .init = init_tsens_v1_no_rpm,
8625
+ .calibrate = tsens_calibrate_common,
8726
+ .get_temp = get_temp_tsens_valid,
8827
+};
8928
+
90-
+struct tsens_plat_data data_ipq5018 = {
29+
+const struct tsens_plat_data data_ipq5018 = {
9130
+ .num_sensors = 5,
9231
+ .ops = &ops_ipq5018,
93-
+ .feat = &tsens_v1_ipq5018_feat,
32+
+ .hw_ids = (unsigned int []){0, 1, 2, 3, 4},
33+
+ .feat = &tsens_v1_no_rpm_feat,
9434
+ .fields = tsens_v1_regfields,
9535
+};
9636
--- a/drivers/thermal/qcom/tsens.c
9737
+++ b/drivers/thermal/qcom/tsens.c
98-
@@ -1101,6 +1101,9 @@ static SIMPLE_DEV_PM_OPS(tsens_pm_ops, t
38+
@@ -1107,6 +1107,9 @@ static SIMPLE_DEV_PM_OPS(tsens_pm_ops, t
9939

10040
static const struct of_device_id tsens_table[] = {
10141
{
10242
+ .compatible = "qcom,ipq5018-tsens",
10343
+ .data = &data_ipq5018,
10444
+ }, {
105-
.compatible = "qcom,ipq8064-tsens",
106-
.data = &data_8960,
45+
.compatible = "qcom,ipq5332-tsens",
46+
.data = &data_ipq5332,
10747
}, {
10848
--- a/drivers/thermal/qcom/tsens.h
10949
+++ b/drivers/thermal/qcom/tsens.h
110-
@@ -645,7 +645,7 @@ extern struct tsens_plat_data data_8960;
111-
extern struct tsens_plat_data data_8226, data_8909, data_8916, data_8939, data_8974, data_9607;
112-
50+
@@ -647,6 +647,9 @@ extern struct tsens_plat_data data_8226,
11351
/* TSENS v1 targets */
114-
-extern struct tsens_plat_data data_tsens_v1, data_8937, data_8976, data_8956;
115-
+extern struct tsens_plat_data data_tsens_v1, data_8937, data_8976, data_8956, data_ipq5018;
52+
extern struct tsens_plat_data data_tsens_v1, data_8937, data_8976, data_8956;
11653

54+
+/* TSENS v1 with no RPM targets */
55+
+extern const struct tsens_plat_data data_ipq5018;
56+
+
11757
/* TSENS v2 targets */
11858
extern struct tsens_plat_data data_8996, data_ipq8074, data_tsens_v2;
59+
extern const struct tsens_plat_data data_ipq5332, data_ipq5424;

target/linux/qualcommax/patches-6.6/0154-dts-qcom-IPQ5018-add-tsens-node.patch

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ Signed-off-by: Sricharan Ramabadhran <quic_srichara@quicinc.com>
2121

2222
+ qfprom: qfprom@a0000 {
2323
+ compatible = "qcom,ipq5018-qfprom", "qcom,qfprom";
24-
+ reg = <0xa0000 0x1000>;
24+
+ reg = <0x000a0000 0x1000>;
2525
+ #address-cells = <1>;
2626
+ #size-cells = <1>;
2727
+
2828
+ tsens_mode: mode@249 {
29-
+ reg = <0x249 1>;
29+
+ reg = <0x249 0x1>;
3030
+ bits = <0 3>;
3131
+ };
3232
+
3333
+ tsens_base1: base1@249 {
34-
+ reg = <0x249 2>;
34+
+ reg = <0x249 0x2>;
3535
+ bits = <3 8>;
3636
+ };
3737
+
3838
+ tsens_base2: base2@24a {
39-
+ reg = <0x24a 2>;
39+
+ reg = <0x24a 0x2>;
4040
+ bits = <3 8>;
4141
+ };
4242
+
@@ -93,8 +93,8 @@ Signed-off-by: Sricharan Ramabadhran <quic_srichara@quicinc.com>
9393
+
9494
+ tsens: thermal-sensor@4a9000 {
9595
+ compatible = "qcom,ipq5018-tsens";
96-
+ reg = <0x4a9000 0x1000>, /* TM */
97-
+ <0x4a8000 0x1000>; /* SROT */
96+
+ reg = <0x004a9000 0x1000>, /* TM */
97+
+ <0x004a8000 0x1000>; /* SROT */
9898
+
9999
+ nvmem-cells = <&tsens_mode>,
100100
+ <&tsens_base1>,

0 commit comments

Comments
 (0)