Lines Matching +full:thermal +full:- +full:idle
1 // SPDX-License-Identifier: GPL-2.0
3 * R-Car THS/TSC thermal sensor driver
20 #include <linux/thermal.h>
101 list_for_each_entry(pos, &common->head, list)
104 #define rcar_zone_to_priv(zone) ((zone)->devdata)
105 #define rcar_priv_to_dev(priv) ((priv)->common->dev)
106 #define rcar_has_irq_support(priv) ((priv)->common->base)
107 #define rcar_id_to_shift(priv) ((priv)->id * 8)
111 .compatible = "renesas,rcar-thermal",
115 .compatible = "renesas,rcar-gen2-thermal",
119 .compatible = "renesas,thermal-r8a774c0",
123 .compatible = "renesas,thermal-r8a77970",
127 .compatible = "renesas,thermal-r8a77990",
131 .compatible = "renesas,thermal-r8a77995",
146 return ioread32(common->base + reg); in _rcar_thermal_common_read()
154 iowrite32(data, common->base + reg); in _rcar_thermal_common_write()
164 val = ioread32(common->base + reg); in _rcar_thermal_common_bset()
167 iowrite32(val, common->base + reg); in _rcar_thermal_common_bset()
173 return ioread32(priv->base + reg); in _rcar_thermal_read()
180 iowrite32(data, priv->base + reg); in _rcar_thermal_write()
189 val = ioread32(priv->base + reg); in _rcar_thermal_bset()
192 iowrite32(val, priv->base + reg); in _rcar_thermal_bset()
201 int old, new, ctemp = -EINVAL; in rcar_thermal_update_temp()
204 mutex_lock(&priv->lock); in rcar_thermal_update_temp()
230 dev_err(dev, "thermal sensor was broken\n"); in rcar_thermal_update_temp()
238 if (priv->chip->has_filonoff) in rcar_thermal_update_temp()
243 rcar_thermal_write(priv, INTCTRL, (((ctemp - 0) << 8) | in rcar_thermal_update_temp()
244 ((ctemp - 1) << 0))); in rcar_thermal_update_temp()
248 mutex_unlock(&priv->lock); in rcar_thermal_update_temp()
262 /* Guaranteed operating range is -45C to 125C. */ in rcar_thermal_get_current_temp()
264 if (priv->chip->ctemp_bands == 1) in rcar_thermal_get_current_temp()
265 *temp = MCELSIUS((ctemp * 5) - 65); in rcar_thermal_get_current_temp()
267 *temp = MCELSIUS(((ctemp * 55) - 720) / 10); in rcar_thermal_get_current_temp()
269 *temp = MCELSIUS((ctemp * 5) - 60); in rcar_thermal_get_current_temp()
301 return -EINVAL; in rcar_thermal_get_trip_type()
320 return -EINVAL; in rcar_thermal_get_trip_temp()
335 dev_warn(dev, "Thermal reached to critical temperature\n"); in rcar_thermal_notify()
362 struct rcar_thermal_common *common = priv->common; in _rcar_thermal_irq_ctrl()
369 spin_lock_irqsave(&common->lock, flags); in _rcar_thermal_irq_ctrl()
373 spin_unlock_irqrestore(&common->lock, flags); in _rcar_thermal_irq_ctrl()
389 thermal_zone_device_update(priv->zone, THERMAL_EVENT_UNSPECIFIED); in rcar_thermal_work()
399 dev_dbg(dev, "thermal%d %s%s\n", in rcar_thermal_had_changed()
400 priv->id, in rcar_thermal_had_changed()
415 spin_lock_irqsave(&common->lock, flags); in rcar_thermal_irq()
421 spin_unlock_irqrestore(&common->lock, flags); in rcar_thermal_irq()
431 queue_delayed_work(system_freezable_wq, &priv->work, in rcar_thermal_irq()
445 struct device *dev = &pdev->dev; in rcar_thermal_remove()
450 cancel_delayed_work_sync(&priv->work); in rcar_thermal_remove()
451 if (priv->chip->use_of_thermal) in rcar_thermal_remove()
452 thermal_remove_hwmon_sysfs(priv->zone); in rcar_thermal_remove()
454 thermal_zone_device_unregister(priv->zone); in rcar_thermal_remove()
467 struct device *dev = &pdev->dev; in rcar_thermal_probe()
472 int ret = -ENODEV; in rcar_thermal_probe()
473 int idle = IDLE_INTERVAL; in rcar_thermal_probe() local
478 return -ENOMEM; in rcar_thermal_probe()
482 INIT_LIST_HEAD(&common->head); in rcar_thermal_probe()
483 spin_lock_init(&common->lock); in rcar_thermal_probe()
484 common->dev = dev; in rcar_thermal_probe()
489 for (i = 0; i < chip->nirqs; i++) { in rcar_thermal_probe()
493 if (!common->base) { in rcar_thermal_probe()
501 common->base = devm_ioremap_resource(dev, res); in rcar_thermal_probe()
502 if (IS_ERR(common->base)) { in rcar_thermal_probe()
503 ret = PTR_ERR(common->base); in rcar_thermal_probe()
507 idle = 0; /* polling delay is not needed */ in rcar_thermal_probe()
510 ret = devm_request_irq(dev, irq->start, rcar_thermal_irq, in rcar_thermal_probe()
518 if (chip->irq_per_ch) in rcar_thermal_probe()
529 ret = -ENOMEM; in rcar_thermal_probe()
533 priv->base = devm_ioremap_resource(dev, res); in rcar_thermal_probe()
534 if (IS_ERR(priv->base)) { in rcar_thermal_probe()
535 ret = PTR_ERR(priv->base); in rcar_thermal_probe()
539 priv->common = common; in rcar_thermal_probe()
540 priv->id = i; in rcar_thermal_probe()
541 priv->chip = chip; in rcar_thermal_probe()
542 mutex_init(&priv->lock); in rcar_thermal_probe()
543 INIT_LIST_HEAD(&priv->list); in rcar_thermal_probe()
544 INIT_DELAYED_WORK(&priv->work, rcar_thermal_work); in rcar_thermal_probe()
549 if (chip->use_of_thermal) { in rcar_thermal_probe()
550 priv->zone = devm_thermal_zone_of_sensor_register( in rcar_thermal_probe()
554 priv->zone = thermal_zone_device_register( in rcar_thermal_probe()
558 idle); in rcar_thermal_probe()
560 ret = thermal_zone_device_enable(priv->zone); in rcar_thermal_probe()
562 thermal_zone_device_unregister(priv->zone); in rcar_thermal_probe()
563 priv->zone = ERR_PTR(ret); in rcar_thermal_probe()
566 if (IS_ERR(priv->zone)) { in rcar_thermal_probe()
567 dev_err(dev, "can't register thermal zone\n"); in rcar_thermal_probe()
568 ret = PTR_ERR(priv->zone); in rcar_thermal_probe()
569 priv->zone = NULL; in rcar_thermal_probe()
573 if (chip->use_of_thermal) { in rcar_thermal_probe()
578 priv->zone->tzp->no_hwmon = false; in rcar_thermal_probe()
579 ret = thermal_add_hwmon_sysfs(priv->zone); in rcar_thermal_probe()
586 list_move_tail(&priv->list, &common->head); in rcar_thermal_probe()
589 if (!chip->irq_per_ch) in rcar_thermal_probe()
593 if (common->base && enr_bits) in rcar_thermal_probe()
610 struct rcar_thermal_priv *priv = list_first_entry(&common->head, in rcar_thermal_suspend()
613 if (priv->chip->needs_suspend_resume) { in rcar_thermal_suspend()
625 struct rcar_thermal_priv *priv = list_first_entry(&common->head, in rcar_thermal_resume()
629 if (priv->chip->needs_suspend_resume) { in rcar_thermal_resume()
656 MODULE_DESCRIPTION("R-Car THS/TSC thermal sensor driver");