hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/thermal/rcar_thermal.c
....@@ -52,6 +52,7 @@
5252 unsigned int irq_per_ch : 1;
5353 unsigned int needs_suspend_resume : 1;
5454 unsigned int nirqs;
55
+ unsigned int ctemp_bands;
5556 };
5657
5758 static const struct rcar_thermal_chip rcar_thermal = {
....@@ -60,6 +61,7 @@
6061 .irq_per_ch = 0,
6162 .needs_suspend_resume = 0,
6263 .nirqs = 1,
64
+ .ctemp_bands = 1,
6365 };
6466
6567 static const struct rcar_thermal_chip rcar_gen2_thermal = {
....@@ -68,6 +70,7 @@
6870 .irq_per_ch = 0,
6971 .needs_suspend_resume = 0,
7072 .nirqs = 1,
73
+ .ctemp_bands = 1,
7174 };
7275
7376 static const struct rcar_thermal_chip rcar_gen3_thermal = {
....@@ -80,6 +83,7 @@
8083 * interrupts to detect a temperature change, rise or fall.
8184 */
8285 .nirqs = 2,
86
+ .ctemp_bands = 2,
8387 };
8488
8589 struct rcar_thermal_priv {
....@@ -91,7 +95,6 @@
9195 struct mutex lock;
9296 struct list_head list;
9397 int id;
94
- u32 ctemp;
9598 };
9699
97100 #define rcar_thermal_for_each_priv(pos, common) \
....@@ -111,6 +114,18 @@
111114 {
112115 .compatible = "renesas,rcar-gen2-thermal",
113116 .data = &rcar_gen2_thermal,
117
+ },
118
+ {
119
+ .compatible = "renesas,thermal-r8a774c0",
120
+ .data = &rcar_gen3_thermal,
121
+ },
122
+ {
123
+ .compatible = "renesas,thermal-r8a77970",
124
+ .data = &rcar_gen3_thermal,
125
+ },
126
+ {
127
+ .compatible = "renesas,thermal-r8a77990",
128
+ .data = &rcar_gen3_thermal,
114129 },
115130 {
116131 .compatible = "renesas,thermal-r8a77995",
....@@ -183,9 +198,8 @@
183198 static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv)
184199 {
185200 struct device *dev = rcar_priv_to_dev(priv);
186
- int i;
187
- u32 ctemp, old, new;
188
- int ret = -EINVAL;
201
+ int old, new, ctemp = -EINVAL;
202
+ unsigned int i;
189203
190204 mutex_lock(&priv->lock);
191205
....@@ -195,7 +209,6 @@
195209 */
196210 rcar_thermal_bset(priv, THSCR, CPCTL, CPCTL);
197211
198
- ctemp = 0;
199212 old = ~0;
200213 for (i = 0; i < 128; i++) {
201214 /*
....@@ -203,7 +216,7 @@
203216 * to get stable temperature.
204217 * see "Usage Notes" on datasheet
205218 */
206
- udelay(300);
219
+ usleep_range(300, 400);
207220
208221 new = rcar_thermal_read(priv, THSSR) & CTEMP;
209222 if (new == old) {
....@@ -213,7 +226,7 @@
213226 old = new;
214227 }
215228
216
- if (!ctemp) {
229
+ if (ctemp < 0) {
217230 dev_err(dev, "thermal sensor was broken\n");
218231 goto err_out_unlock;
219232 }
....@@ -231,37 +244,29 @@
231244 ((ctemp - 1) << 0)));
232245 }
233246
234
- dev_dbg(dev, "thermal%d %d -> %d\n", priv->id, priv->ctemp, ctemp);
235
-
236
- priv->ctemp = ctemp;
237
- ret = 0;
238247 err_out_unlock:
239248 mutex_unlock(&priv->lock);
240
- return ret;
249
+
250
+ return ctemp;
241251 }
242252
243253 static int rcar_thermal_get_current_temp(struct rcar_thermal_priv *priv,
244254 int *temp)
245255 {
246
- int tmp;
247
- int ret;
256
+ int ctemp;
248257
249
- ret = rcar_thermal_update_temp(priv);
250
- if (ret < 0)
251
- return ret;
258
+ ctemp = rcar_thermal_update_temp(priv);
259
+ if (ctemp < 0)
260
+ return ctemp;
252261
253
- mutex_lock(&priv->lock);
254
- tmp = MCELSIUS((priv->ctemp * 5) - 65);
255
- mutex_unlock(&priv->lock);
262
+ /* Guaranteed operating range is -45C to 125C. */
256263
257
- if ((tmp < MCELSIUS(-45)) || (tmp > MCELSIUS(125))) {
258
- struct device *dev = rcar_priv_to_dev(priv);
259
-
260
- dev_err(dev, "it couldn't measure temperature correctly\n");
261
- return -EIO;
262
- }
263
-
264
- *temp = tmp;
264
+ if (priv->chip->ctemp_bands == 1)
265
+ *temp = MCELSIUS((ctemp * 5) - 65);
266
+ else if (ctemp < 24)
267
+ *temp = MCELSIUS(((ctemp * 55) - 720) / 10);
268
+ else
269
+ *temp = MCELSIUS((ctemp * 5) - 60);
265270
266271 return 0;
267272 }
....@@ -371,14 +376,9 @@
371376 static void rcar_thermal_work(struct work_struct *work)
372377 {
373378 struct rcar_thermal_priv *priv;
374
- int cctemp, nctemp;
375379 int ret;
376380
377381 priv = container_of(work, struct rcar_thermal_priv, work.work);
378
-
379
- ret = rcar_thermal_get_current_temp(priv, &cctemp);
380
- if (ret < 0)
381
- return;
382382
383383 ret = rcar_thermal_update_temp(priv);
384384 if (ret < 0)
....@@ -386,13 +386,7 @@
386386
387387 rcar_thermal_irq_enable(priv);
388388
389
- ret = rcar_thermal_get_current_temp(priv, &nctemp);
390
- if (ret < 0)
391
- return;
392
-
393
- if (nctemp != cctemp)
394
- thermal_zone_device_update(priv->zone,
395
- THERMAL_EVENT_UNSPECIFIED);
389
+ thermal_zone_device_update(priv->zone, THERMAL_EVENT_UNSPECIFIED);
396390 }
397391
398392 static u32 rcar_thermal_had_changed(struct rcar_thermal_priv *priv, u32 status)
....@@ -552,16 +546,23 @@
552546 if (ret < 0)
553547 goto error_unregister;
554548
555
- if (chip->use_of_thermal)
549
+ if (chip->use_of_thermal) {
556550 priv->zone = devm_thermal_zone_of_sensor_register(
557551 dev, i, priv,
558552 &rcar_thermal_zone_of_ops);
559
- else
553
+ } else {
560554 priv->zone = thermal_zone_device_register(
561555 "rcar_thermal",
562556 1, 0, priv,
563557 &rcar_thermal_zone_ops, NULL, 0,
564558 idle);
559
+
560
+ ret = thermal_zone_device_enable(priv->zone);
561
+ if (ret) {
562
+ thermal_zone_device_unregister(priv->zone);
563
+ priv->zone = ERR_PTR(ret);
564
+ }
565
+ }
565566 if (IS_ERR(priv->zone)) {
566567 dev_err(dev, "can't register thermal zone\n");
567568 ret = PTR_ERR(priv->zone);