Lines Matching +full:r8a7795 +full:- +full:thermal

1 // SPDX-License-Identifier: GPL-2.0
3 * R-Car Gen3 THS thermal sensor driver
17 #include <linux/thermal.h>
68 /* Structure for thermal temperature calculation */
102 return ioread32(tsc->base + reg); in rcar_gen3_thermal_read()
108 iowrite32(data, tsc->base + reg); in rcar_gen3_thermal_write()
114 * [reg] = [temp] * a + b => [temp] = ([reg] - b) / a
137 #define TJ_3 -41
149 tsc->tj_t = (FIXPT_INT((priv->ptat[1] - priv->ptat[2]) * (ths_tj_1 - TJ_3)) in rcar_gen3_thermal_calc_coefs()
150 / (priv->ptat[0] - priv->ptat[2])) + FIXPT_INT(TJ_3); in rcar_gen3_thermal_calc_coefs()
152 tsc->coef.a1 = FIXPT_DIV(FIXPT_INT(tsc->thcode[1] - tsc->thcode[2]), in rcar_gen3_thermal_calc_coefs()
153 tsc->tj_t - FIXPT_INT(TJ_3)); in rcar_gen3_thermal_calc_coefs()
154 tsc->coef.b1 = FIXPT_INT(tsc->thcode[2]) - tsc->coef.a1 * TJ_3; in rcar_gen3_thermal_calc_coefs()
156 tsc->coef.a2 = FIXPT_DIV(FIXPT_INT(tsc->thcode[1] - tsc->thcode[0]), in rcar_gen3_thermal_calc_coefs()
157 tsc->tj_t - FIXPT_INT(ths_tj_1)); in rcar_gen3_thermal_calc_coefs()
158 tsc->coef.b2 = FIXPT_INT(tsc->thcode[0]) - tsc->coef.a2 * ths_tj_1; in rcar_gen3_thermal_calc_coefs()
166 -RCAR3_THERMAL_GRAN / 2; in rcar_gen3_thermal_round()
180 if (reg <= tsc->thcode[1]) in rcar_gen3_thermal_get_temp()
181 val = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b1, in rcar_gen3_thermal_get_temp()
182 tsc->coef.a1); in rcar_gen3_thermal_get_temp()
184 val = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b2, in rcar_gen3_thermal_get_temp()
185 tsc->coef.a2); in rcar_gen3_thermal_get_temp()
188 /* Guaranteed operating range is -40C to 125C. */ in rcar_gen3_thermal_get_temp()
202 if (celsius <= INT_FIXPT(tsc->tj_t)) in rcar_gen3_thermal_mcelsius_to_temp()
203 val = celsius * tsc->coef.a1 + tsc->coef.b1; in rcar_gen3_thermal_mcelsius_to_temp()
205 val = celsius * tsc->coef.a2 + tsc->coef.b2; in rcar_gen3_thermal_mcelsius_to_temp()
215 if (low != -INT_MAX) { in rcar_gen3_thermal_set_trips()
243 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_irq()
244 status = rcar_gen3_thermal_read(priv->tscs[i], REG_GEN3_IRQSTR); in rcar_gen3_thermal_irq()
245 rcar_gen3_thermal_write(priv->tscs[i], REG_GEN3_IRQSTR, 0); in rcar_gen3_thermal_irq()
246 if (status && priv->tscs[i]->zone) in rcar_gen3_thermal_irq()
247 thermal_zone_device_update(priv->tscs[i]->zone, in rcar_gen3_thermal_irq()
263 priv->ptat[0] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT1) & in rcar_gen3_thermal_read_fuses_gen3()
265 priv->ptat[1] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT2) & in rcar_gen3_thermal_read_fuses_gen3()
267 priv->ptat[2] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT3) & in rcar_gen3_thermal_read_fuses_gen3()
270 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_read_fuses_gen3()
271 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_read_fuses_gen3()
273 tsc->thcode[0] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE1) & in rcar_gen3_thermal_read_fuses_gen3()
275 tsc->thcode[1] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE2) & in rcar_gen3_thermal_read_fuses_gen3()
277 tsc->thcode[2] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE3) & in rcar_gen3_thermal_read_fuses_gen3()
291 priv->ptat[0] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN4_THSFMON16) & in rcar_gen3_thermal_read_fuses_gen4()
293 priv->ptat[1] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN4_THSFMON17) & in rcar_gen3_thermal_read_fuses_gen4()
295 priv->ptat[2] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN4_THSFMON15) & in rcar_gen3_thermal_read_fuses_gen4()
298 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_read_fuses_gen4()
299 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_read_fuses_gen4()
301 tsc->thcode[0] = rcar_gen3_thermal_read(tsc, REG_GEN4_THSFMON01) & in rcar_gen3_thermal_read_fuses_gen4()
303 tsc->thcode[1] = rcar_gen3_thermal_read(tsc, REG_GEN4_THSFMON02) & in rcar_gen3_thermal_read_fuses_gen4()
305 tsc->thcode[2] = rcar_gen3_thermal_read(tsc, REG_GEN4_THSFMON00) & in rcar_gen3_thermal_read_fuses_gen4()
316 thscp = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_THSCP); in rcar_gen3_thermal_read_fuses()
317 if (!priv->info->read_fuses || in rcar_gen3_thermal_read_fuses()
328 priv->ptat[0] = 2631; in rcar_gen3_thermal_read_fuses()
329 priv->ptat[1] = 1509; in rcar_gen3_thermal_read_fuses()
330 priv->ptat[2] = 435; in rcar_gen3_thermal_read_fuses()
332 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_read_fuses()
333 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_read_fuses()
335 tsc->thcode[0] = thcodes[i][0]; in rcar_gen3_thermal_read_fuses()
336 tsc->thcode[1] = thcodes[i][1]; in rcar_gen3_thermal_read_fuses()
337 tsc->thcode[2] = thcodes[i][2]; in rcar_gen3_thermal_read_fuses()
343 priv->info->read_fuses(priv); in rcar_gen3_thermal_read_fuses()
360 if (priv->ops.set_trips) in rcar_gen3_thermal_init()
388 .compatible = "renesas,r8a774a1-thermal",
392 .compatible = "renesas,r8a774b1-thermal",
396 .compatible = "renesas,r8a774e1-thermal",
400 .compatible = "renesas,r8a7795-thermal",
404 .compatible = "renesas,r8a7796-thermal",
408 .compatible = "renesas,r8a77961-thermal",
412 .compatible = "renesas,r8a77965-thermal",
416 .compatible = "renesas,r8a77980-thermal",
420 .compatible = "renesas,r8a779a0-thermal",
424 .compatible = "renesas,r8a779f0-thermal",
428 .compatible = "renesas,r8a779g0-thermal",
437 struct device *dev = &pdev->dev; in rcar_gen3_thermal_remove()
455 struct device *dev = &pdev->dev; in rcar_gen3_thermal_request_irqs()
468 return -ENOMEM; in rcar_gen3_thermal_request_irqs()
483 struct device *dev = &pdev->dev; in rcar_gen3_thermal_probe()
491 return -ENOMEM; in rcar_gen3_thermal_probe()
493 priv->ops = rcar_gen3_tz_of_ops; in rcar_gen3_thermal_probe()
495 priv->info = of_device_get_match_data(dev); in rcar_gen3_thermal_probe()
499 priv->ops.set_trips = NULL; in rcar_gen3_thermal_probe()
513 ret = -ENOMEM; in rcar_gen3_thermal_probe()
517 tsc->base = devm_ioremap_resource(dev, res); in rcar_gen3_thermal_probe()
518 if (IS_ERR(tsc->base)) { in rcar_gen3_thermal_probe()
519 ret = PTR_ERR(tsc->base); in rcar_gen3_thermal_probe()
523 priv->tscs[i] = tsc; in rcar_gen3_thermal_probe()
526 priv->num_tscs = i; in rcar_gen3_thermal_probe()
531 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_probe()
532 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_probe()
535 rcar_gen3_thermal_calc_coefs(priv, tsc, priv->info->ths_tj_1); in rcar_gen3_thermal_probe()
537 zone = devm_thermal_of_zone_register(dev, i, tsc, &priv->ops); in rcar_gen3_thermal_probe()
539 dev_err(dev, "Sensor %u: Can't register thermal zone\n", i); in rcar_gen3_thermal_probe()
543 tsc->zone = zone; in rcar_gen3_thermal_probe()
545 ret = thermal_add_hwmon_sysfs(tsc->zone); in rcar_gen3_thermal_probe()
553 ret = thermal_zone_get_num_trips(tsc->zone); in rcar_gen3_thermal_probe()
560 if (!priv->num_tscs) { in rcar_gen3_thermal_probe()
561 ret = -ENODEV; in rcar_gen3_thermal_probe()
578 for (i = 0; i < priv->num_tscs; i++) { in rcar_gen3_thermal_resume()
579 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_resume()
602 MODULE_DESCRIPTION("R-Car Gen3 THS thermal sensor driver");
603 MODULE_AUTHOR("Wolfram Sang <wsa+renesas@sang-engineering.com>");