Lines Matching +full:thermal +full:- +full:calibration

1 // SPDX-License-Identifier: GPL-2.0
3 * R-Car Gen3 THS thermal sensor driver
18 #include <linux/thermal.h>
72 /* Structure for thermal temperature calculation */
98 return ioread32(tsc->base + reg); in rcar_gen3_thermal_read()
104 iowrite32(data, tsc->base + reg); in rcar_gen3_thermal_write()
110 * [reg] = [temp] * a + b => [temp] = ([reg] - b) / a
133 #define TJ_3 -41
145 tsc->tj_t = (FIXPT_INT((priv->ptat[1] - priv->ptat[2]) * (ths_tj_1 - TJ_3)) in rcar_gen3_thermal_calc_coefs()
146 / (priv->ptat[0] - priv->ptat[2])) + FIXPT_INT(TJ_3); in rcar_gen3_thermal_calc_coefs()
148 tsc->coef.a1 = FIXPT_DIV(FIXPT_INT(tsc->thcode[1] - tsc->thcode[2]), in rcar_gen3_thermal_calc_coefs()
149 tsc->tj_t - FIXPT_INT(TJ_3)); in rcar_gen3_thermal_calc_coefs()
150 tsc->coef.b1 = FIXPT_INT(tsc->thcode[2]) - tsc->coef.a1 * TJ_3; in rcar_gen3_thermal_calc_coefs()
152 tsc->coef.a2 = FIXPT_DIV(FIXPT_INT(tsc->thcode[1] - tsc->thcode[0]), in rcar_gen3_thermal_calc_coefs()
153 tsc->tj_t - FIXPT_INT(ths_tj_1)); in rcar_gen3_thermal_calc_coefs()
154 tsc->coef.b2 = FIXPT_INT(tsc->thcode[0]) - tsc->coef.a2 * ths_tj_1; in rcar_gen3_thermal_calc_coefs()
162 -RCAR3_THERMAL_GRAN / 2; in rcar_gen3_thermal_round()
169 struct rcar_gen3_thermal_tsc *tsc = tz->devdata; in rcar_gen3_thermal_get_temp()
176 if (reg <= tsc->thcode[1]) in rcar_gen3_thermal_get_temp()
177 val = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b1, in rcar_gen3_thermal_get_temp()
178 tsc->coef.a1); in rcar_gen3_thermal_get_temp()
180 val = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b2, in rcar_gen3_thermal_get_temp()
181 tsc->coef.a2); in rcar_gen3_thermal_get_temp()
184 /* Guaranteed operating range is -40C to 125C. */ in rcar_gen3_thermal_get_temp()
198 if (celsius <= INT_FIXPT(tsc->tj_t)) in rcar_gen3_thermal_mcelsius_to_temp()
199 val = celsius * tsc->coef.a1 + tsc->coef.b1; in rcar_gen3_thermal_mcelsius_to_temp()
201 val = celsius * tsc->coef.a2 + tsc->coef.b2; in rcar_gen3_thermal_mcelsius_to_temp()
208 struct rcar_gen3_thermal_tsc *tsc = tz->devdata; in rcar_gen3_thermal_set_trips()
211 if (low != -INT_MAX) { in rcar_gen3_thermal_set_trips()
239 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_irq()
240 status = rcar_gen3_thermal_read(priv->tscs[i], REG_GEN3_IRQSTR); in rcar_gen3_thermal_irq()
241 rcar_gen3_thermal_write(priv->tscs[i], REG_GEN3_IRQSTR, 0); in rcar_gen3_thermal_irq()
243 thermal_zone_device_update(priv->tscs[i]->zone, in rcar_gen3_thermal_irq()
261 thscp = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_THSCP); in rcar_gen3_thermal_read_fuses()
272 priv->ptat[0] = 2631; in rcar_gen3_thermal_read_fuses()
273 priv->ptat[1] = 1509; in rcar_gen3_thermal_read_fuses()
274 priv->ptat[2] = 435; in rcar_gen3_thermal_read_fuses()
276 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_read_fuses()
277 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_read_fuses()
279 tsc->thcode[0] = thcodes[i][0]; in rcar_gen3_thermal_read_fuses()
280 tsc->thcode[1] = thcodes[i][1]; in rcar_gen3_thermal_read_fuses()
281 tsc->thcode[2] = thcodes[i][2]; in rcar_gen3_thermal_read_fuses()
288 * Set the pseudo calibration points with fused values. in rcar_gen3_thermal_read_fuses()
292 priv->ptat[0] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT1) & in rcar_gen3_thermal_read_fuses()
294 priv->ptat[1] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT2) & in rcar_gen3_thermal_read_fuses()
296 priv->ptat[2] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT3) & in rcar_gen3_thermal_read_fuses()
299 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_read_fuses()
300 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_read_fuses()
302 tsc->thcode[0] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE1) & in rcar_gen3_thermal_read_fuses()
304 tsc->thcode[1] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE2) & in rcar_gen3_thermal_read_fuses()
306 tsc->thcode[2] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE3) & in rcar_gen3_thermal_read_fuses()
324 if (tsc->zone->ops->set_trips) in rcar_gen3_thermal_init_r8a7795es1()
352 if (tsc->zone->ops->set_trips) in rcar_gen3_thermal_init()
367 .compatible = "renesas,r8a774a1-thermal",
371 .compatible = "renesas,r8a774b1-thermal",
375 .compatible = "renesas,r8a774e1-thermal",
379 .compatible = "renesas,r8a7795-thermal",
383 .compatible = "renesas,r8a7796-thermal",
387 .compatible = "renesas,r8a77961-thermal",
391 .compatible = "renesas,r8a77965-thermal",
395 .compatible = "renesas,r8a77980-thermal",
399 .compatible = "renesas,r8a779a0-thermal",
403 .compatible = "renesas,r8a779f0-thermal",
412 struct device *dev = &pdev->dev; in rcar_gen3_thermal_remove()
430 struct device *dev = &pdev->dev; in rcar_gen3_thermal_request_irqs()
443 return -ENOMEM; in rcar_gen3_thermal_request_irqs()
458 struct device *dev = &pdev->dev; in rcar_gen3_thermal_probe()
467 return -ENOMEM; in rcar_gen3_thermal_probe()
469 priv->thermal_init = rcar_gen3_thermal_init; in rcar_gen3_thermal_probe()
471 priv->thermal_init = rcar_gen3_thermal_init_r8a7795es1; in rcar_gen3_thermal_probe()
490 ret = -ENOMEM; in rcar_gen3_thermal_probe()
494 tsc->base = devm_ioremap_resource(dev, res); in rcar_gen3_thermal_probe()
495 if (IS_ERR(tsc->base)) { in rcar_gen3_thermal_probe()
496 ret = PTR_ERR(tsc->base); in rcar_gen3_thermal_probe()
500 priv->tscs[i] = tsc; in rcar_gen3_thermal_probe()
503 priv->num_tscs = i; in rcar_gen3_thermal_probe()
506 dev_info(dev, "No calibration values fused, fallback to driver values\n"); in rcar_gen3_thermal_probe()
508 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_probe()
509 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_probe()
514 dev_err(dev, "Sensor %u: Can't register thermal zone\n", i); in rcar_gen3_thermal_probe()
518 tsc->zone = zone; in rcar_gen3_thermal_probe()
520 priv->thermal_init(tsc); in rcar_gen3_thermal_probe()
523 tsc->zone->tzp->no_hwmon = false; in rcar_gen3_thermal_probe()
524 ret = thermal_add_hwmon_sysfs(tsc->zone); in rcar_gen3_thermal_probe()
532 ret = of_thermal_get_ntrips(tsc->zone); in rcar_gen3_thermal_probe()
539 if (!priv->num_tscs) { in rcar_gen3_thermal_probe()
540 ret = -ENODEV; in rcar_gen3_thermal_probe()
557 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_resume()
558 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_resume()
559 struct thermal_zone_device *zone = tsc->zone; in rcar_gen3_thermal_resume()
561 priv->thermal_init(tsc); in rcar_gen3_thermal_resume()
562 if (zone->ops->set_trips) in rcar_gen3_thermal_resume()
563 rcar_gen3_thermal_set_trips(zone, zone->prev_low_trip, in rcar_gen3_thermal_resume()
564 zone->prev_high_trip); in rcar_gen3_thermal_resume()
585 MODULE_DESCRIPTION("R-Car Gen3 THS thermal sensor driver");
586 MODULE_AUTHOR("Wolfram Sang <wsa+renesas@sang-engineering.com>");