Lines Matching +full:operating +full:- +full:range +full:- +full:celsius
1 // SPDX-License-Identifier: GPL-2.0
3 * R-Car Gen3 THS thermal sensor driver
106 return ioread32(tsc->base + reg); in rcar_gen3_thermal_read()
112 iowrite32(data, tsc->base + reg); in rcar_gen3_thermal_write()
118 * [temp] = ((thadj - [reg]) * a) / b + adj
119 * [reg] = thadj - ([temp] - adj) * b / a
140 priv->tj_t = in rcar_gen3_thermal_shared_coefs()
141 DIV_ROUND_CLOSEST((priv->ptat[1] - priv->ptat[2]) * priv->info->scale, in rcar_gen3_thermal_shared_coefs()
142 priv->ptat[0] - priv->ptat[2]) in rcar_gen3_thermal_shared_coefs()
143 + priv->info->adj_below; in rcar_gen3_thermal_shared_coefs()
148 tsc->coef.below.a = priv->info->scale * (priv->ptat[2] - priv->ptat[1]); in rcar_gen3_thermal_tsc_coefs()
149 tsc->coef.above.a = priv->info->scale * (priv->ptat[0] - priv->ptat[1]); in rcar_gen3_thermal_tsc_coefs()
151 tsc->coef.below.b = (priv->ptat[2] - priv->ptat[0]) * (tsc->thcode[2] - tsc->thcode[1]); in rcar_gen3_thermal_tsc_coefs()
152 tsc->coef.above.b = (priv->ptat[0] - priv->ptat[2]) * (tsc->thcode[1] - tsc->thcode[0]); in rcar_gen3_thermal_tsc_coefs()
158 struct rcar_gen3_thermal_priv *priv = tsc->priv; in rcar_gen3_thermal_get_temp()
162 /* Read register and convert to mili Celsius */ in rcar_gen3_thermal_get_temp()
165 if (reg < tsc->thcode[1]) { in rcar_gen3_thermal_get_temp()
166 adj = priv->info->adj_below; in rcar_gen3_thermal_get_temp()
167 coef = &tsc->coef.below; in rcar_gen3_thermal_get_temp()
168 thcode = tsc->thcode[2]; in rcar_gen3_thermal_get_temp()
170 adj = priv->info->adj_above; in rcar_gen3_thermal_get_temp()
171 coef = &tsc->coef.above; in rcar_gen3_thermal_get_temp()
172 thcode = tsc->thcode[0]; in rcar_gen3_thermal_get_temp()
177 * divisor to convert to decidegree Celsius. If we convert after the in rcar_gen3_thermal_get_temp()
179 * Celsius. in rcar_gen3_thermal_get_temp()
181 decicelsius = DIV_ROUND_CLOSEST(coef->a * (thcode - reg), coef->b / 10); in rcar_gen3_thermal_get_temp()
183 /* Guaranteed operating range is -40C to 125C. */ in rcar_gen3_thermal_get_temp()
185 /* Reporting is done in millidegree Celsius */ in rcar_gen3_thermal_get_temp()
194 struct rcar_gen3_thermal_priv *priv = tsc->priv; in rcar_gen3_thermal_mcelsius_to_temp()
196 int adj, celsius, thcode; in rcar_gen3_thermal_mcelsius_to_temp() local
198 celsius = DIV_ROUND_CLOSEST(mcelsius, 1000); in rcar_gen3_thermal_mcelsius_to_temp()
199 if (celsius < priv->tj_t) { in rcar_gen3_thermal_mcelsius_to_temp()
200 coef = &tsc->coef.below; in rcar_gen3_thermal_mcelsius_to_temp()
201 adj = priv->info->adj_below; in rcar_gen3_thermal_mcelsius_to_temp()
202 thcode = tsc->thcode[2]; in rcar_gen3_thermal_mcelsius_to_temp()
204 coef = &tsc->coef.above; in rcar_gen3_thermal_mcelsius_to_temp()
205 adj = priv->info->adj_above; in rcar_gen3_thermal_mcelsius_to_temp()
206 thcode = tsc->thcode[0]; in rcar_gen3_thermal_mcelsius_to_temp()
209 return thcode - DIV_ROUND_CLOSEST((celsius - adj) * coef->b, coef->a); in rcar_gen3_thermal_mcelsius_to_temp()
217 if (low != -INT_MAX) { in rcar_gen3_thermal_set_trips()
245 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_irq()
246 status = rcar_gen3_thermal_read(priv->tscs[i], REG_GEN3_IRQSTR); in rcar_gen3_thermal_irq()
247 rcar_gen3_thermal_write(priv->tscs[i], REG_GEN3_IRQSTR, 0); in rcar_gen3_thermal_irq()
248 if (status && priv->tscs[i]->zone) in rcar_gen3_thermal_irq()
249 thermal_zone_device_update(priv->tscs[i]->zone, in rcar_gen3_thermal_irq()
265 priv->ptat[0] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT1) & in rcar_gen3_thermal_read_fuses_gen3()
267 priv->ptat[1] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT2) & in rcar_gen3_thermal_read_fuses_gen3()
269 priv->ptat[2] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT3) & in rcar_gen3_thermal_read_fuses_gen3()
272 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_read_fuses_gen3()
273 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_read_fuses_gen3()
275 tsc->thcode[0] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE1) & in rcar_gen3_thermal_read_fuses_gen3()
277 tsc->thcode[1] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE2) & in rcar_gen3_thermal_read_fuses_gen3()
279 tsc->thcode[2] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE3) & in rcar_gen3_thermal_read_fuses_gen3()
293 priv->ptat[0] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN4_THSFMON16) & in rcar_gen3_thermal_read_fuses_gen4()
295 priv->ptat[1] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN4_THSFMON17) & in rcar_gen3_thermal_read_fuses_gen4()
297 priv->ptat[2] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN4_THSFMON15) & in rcar_gen3_thermal_read_fuses_gen4()
300 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_read_fuses_gen4()
301 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_read_fuses_gen4()
303 tsc->thcode[0] = rcar_gen3_thermal_read(tsc, REG_GEN4_THSFMON01) & in rcar_gen3_thermal_read_fuses_gen4()
305 tsc->thcode[1] = rcar_gen3_thermal_read(tsc, REG_GEN4_THSFMON02) & in rcar_gen3_thermal_read_fuses_gen4()
307 tsc->thcode[2] = rcar_gen3_thermal_read(tsc, REG_GEN4_THSFMON00) & in rcar_gen3_thermal_read_fuses_gen4()
318 thscp = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_THSCP); in rcar_gen3_thermal_read_fuses()
319 if (!priv->info->read_fuses || in rcar_gen3_thermal_read_fuses()
330 priv->ptat[0] = 2631; in rcar_gen3_thermal_read_fuses()
331 priv->ptat[1] = 1509; in rcar_gen3_thermal_read_fuses()
332 priv->ptat[2] = 435; in rcar_gen3_thermal_read_fuses()
334 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_read_fuses()
335 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_read_fuses()
337 tsc->thcode[0] = thcodes[i][0]; in rcar_gen3_thermal_read_fuses()
338 tsc->thcode[1] = thcodes[i][1]; in rcar_gen3_thermal_read_fuses()
339 tsc->thcode[2] = thcodes[i][2]; in rcar_gen3_thermal_read_fuses()
345 priv->info->read_fuses(priv); in rcar_gen3_thermal_read_fuses()
362 if (priv->ops.set_trips) in rcar_gen3_thermal_init()
375 .adj_below = -41,
382 .adj_below = -41,
389 .adj_below = -41,
396 .compatible = "renesas,r8a774a1-thermal",
400 .compatible = "renesas,r8a774b1-thermal",
404 .compatible = "renesas,r8a774e1-thermal",
408 .compatible = "renesas,r8a7795-thermal",
412 .compatible = "renesas,r8a7796-thermal",
416 .compatible = "renesas,r8a77961-thermal",
420 .compatible = "renesas,r8a77965-thermal",
424 .compatible = "renesas,r8a77980-thermal",
428 .compatible = "renesas,r8a779a0-thermal",
432 .compatible = "renesas,r8a779f0-thermal",
436 .compatible = "renesas,r8a779g0-thermal",
440 .compatible = "renesas,r8a779h0-thermal",
449 struct device *dev = &pdev->dev; in rcar_gen3_thermal_remove()
465 struct device *dev = &pdev->dev; in rcar_gen3_thermal_request_irqs()
478 return -ENOMEM; in rcar_gen3_thermal_request_irqs()
493 struct device *dev = &pdev->dev; in rcar_gen3_thermal_probe()
501 return -ENOMEM; in rcar_gen3_thermal_probe()
503 priv->ops = rcar_gen3_tz_of_ops; in rcar_gen3_thermal_probe()
505 priv->info = of_device_get_match_data(dev); in rcar_gen3_thermal_probe()
509 priv->ops.set_trips = NULL; in rcar_gen3_thermal_probe()
523 ret = -ENOMEM; in rcar_gen3_thermal_probe()
527 tsc->priv = priv; in rcar_gen3_thermal_probe()
528 tsc->base = devm_ioremap_resource(dev, res); in rcar_gen3_thermal_probe()
529 if (IS_ERR(tsc->base)) { in rcar_gen3_thermal_probe()
530 ret = PTR_ERR(tsc->base); in rcar_gen3_thermal_probe()
534 priv->tscs[i] = tsc; in rcar_gen3_thermal_probe()
537 priv->num_tscs = i; in rcar_gen3_thermal_probe()
544 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_probe()
545 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_probe()
550 zone = devm_thermal_of_zone_register(dev, i, tsc, &priv->ops); in rcar_gen3_thermal_probe()
556 tsc->zone = zone; in rcar_gen3_thermal_probe()
558 ret = thermal_add_hwmon_sysfs(tsc->zone); in rcar_gen3_thermal_probe()
569 if (!priv->num_tscs) { in rcar_gen3_thermal_probe()
570 ret = -ENODEV; in rcar_gen3_thermal_probe()
587 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_resume()
588 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_resume()
611 MODULE_DESCRIPTION("R-Car Gen3 THS thermal sensor driver");
612 MODULE_AUTHOR("Wolfram Sang <wsa+renesas@sang-engineering.com>");