Lines Matching +full:thermal +full:- +full:sensor
1 // SPDX-License-Identifier: GPL-2.0
3 * of-thermal.c - Generic Thermal Management device tree support.
15 #include <linux/thermal.h>
32 return -EINVAL; in of_find_trip_id()
47 i = -ENXIO; in of_find_trip_id()
55 * It maps 'enum thermal_trip_type' found in include/linux/thermal.h
66 * thermal_of_get_trip_type - Get phy mode for given device_node
91 return -ENODEV; in thermal_of_get_trip_type()
105 trip->temperature = prop; in thermal_of_populate_trip()
112 trip->hysteresis = prop; in thermal_of_populate_trip()
114 ret = thermal_of_get_trip_type(np, &trip->type); in thermal_of_populate_trip()
132 return ERR_PTR(-EINVAL); in thermal_of_trips_init()
138 ret = -EINVAL; in thermal_of_trips_init()
144 ret = -ENOMEM; in thermal_of_trips_init()
170 static struct device_node *of_thermal_zone_find(struct device_node *sensor, int id) in of_thermal_zone_find() argument
175 np = of_find_node_by_name(NULL, "thermal-zones"); in of_thermal_zone_find()
177 pr_debug("No thermal zones description\n"); in of_thermal_zone_find()
178 return ERR_PTR(-ENODEV); in of_thermal_zone_find()
182 * Search for each thermal zone, a defined sensor in of_thermal_zone_find()
189 count = of_count_phandle_with_args(tz, "thermal-sensors", in of_thermal_zone_find()
190 "#thermal-sensor-cells"); in of_thermal_zone_find()
192 pr_err("%pOFn: missing thermal sensor\n", tz); in of_thermal_zone_find()
193 tz = ERR_PTR(-EINVAL); in of_thermal_zone_find()
201 ret = of_parse_phandle_with_args(tz, "thermal-sensors", in of_thermal_zone_find()
202 "#thermal-sensor-cells", in of_thermal_zone_find()
205 pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", tz, ret); in of_thermal_zone_find()
210 if ((sensor == sensor_specs.np) && id == (sensor_specs.args_count ? in of_thermal_zone_find()
212 pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, tz); in of_thermal_zone_find()
217 tz = ERR_PTR(-ENODEV); in of_thermal_zone_find()
227 ret = of_property_read_u32(np, "polling-delay-passive", pdelay); in thermal_of_monitor_init()
229 pr_err("%pOFn: missing polling-delay-passive property\n", np); in thermal_of_monitor_init()
233 ret = of_property_read_u32(np, "polling-delay", delay); in thermal_of_monitor_init()
235 pr_err("%pOFn: missing polling-delay property\n", np); in thermal_of_monitor_init()
249 tzp->no_hwmon = true; in thermal_of_parameters_init()
251 if (!of_property_read_u32(np, "sustainable-power", &prop)) in thermal_of_parameters_init()
252 tzp->sustainable_power = prop; in thermal_of_parameters_init()
255 * For now, the thermal framework supports only one sensor per in thermal_of_parameters_init()
256 * thermal zone. Thus, we are considering only the first two in thermal_of_parameters_init()
265 tzp->slope = coef[0]; in thermal_of_parameters_init()
266 tzp->offset = coef[1]; in thermal_of_parameters_init()
273 np = of_find_node_by_name(NULL, "thermal-zones"); in thermal_of_zone_get_by_name()
275 return ERR_PTR(-ENODEV); in thermal_of_zone_get_by_name()
277 tz_np = of_get_child_by_name(np, tz->type); in thermal_of_zone_get_by_name()
282 return ERR_PTR(-ENODEV); in thermal_of_zone_get_by_name()
293 ret = of_parse_phandle_with_args(map_np, "cooling-device", "#cooling-cells", in __thermal_of_unbind()
297 pr_err("Invalid cooling-device entry\n"); in __thermal_of_unbind()
305 return -EINVAL; in __thermal_of_unbind()
308 if (cooling_spec.np != cdev->np) in __thermal_of_unbind()
313 pr_err("Failed to unbind '%s' with '%s': %d\n", tz->type, cdev->type, ret); in __thermal_of_unbind()
326 ret = of_parse_phandle_with_args(map_np, "cooling-device", "#cooling-cells", in __thermal_of_bind()
330 pr_err("Invalid cooling-device entry\n"); in __thermal_of_bind()
338 return -EINVAL; in __thermal_of_bind()
341 if (cooling_spec.np != cdev->np) in __thermal_of_bind()
348 pr_err("Failed to bind '%s' with '%s': %d\n", tz->type, cdev->type, ret); in __thermal_of_bind()
363 return -ENODEV; in thermal_of_for_each_cooling_device()
369 count = of_count_phandle_with_args(map_np, "cooling-device", "#cooling-cells"); in thermal_of_for_each_cooling_device()
372 return -ENOENT; in thermal_of_for_each_cooling_device()
400 cm_np = of_get_child_by_name(tz_np, "cooling-maps"); in thermal_of_for_each_cooling_maps()
432 * thermal_of_zone_unregister - Cleanup the specific allocated ressources
434 * This function disables the thermal zone and frees the different
435 * ressources allocated specific to the thermal OF.
437 * @tz: a pointer to the thermal zone structure
441 struct thermal_trip *trips = tz->trips; in thermal_of_zone_unregister()
442 struct thermal_zone_device_ops *ops = tz->ops; in thermal_of_zone_unregister()
451 * thermal_of_zone_register - Register a thermal zone with device node
452 * sensor
455 * node sensor and identifier. It searches for the thermal zone
456 * associated to the couple sensor/id and retrieves all the thermal
457 * zone properties and registers new thermal zone with those
460 * @sensor: A device node pointer corresponding to the sensor in the device tree
461 * @id: An integer as sensor identifier
462 * @data: A private data to be stored in the thermal zone dedicated private area
463 * @ops: A set of thermal sensor ops
465 * Return: a valid thermal zone structure pointer on success.
466 * - EINVAL: if the device tree thermal description is malformed
467 * - ENOMEM: if one structure can not be allocated
468 * - Other negative errors are returned by the underlying called functions
470 static struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, int id, voi… in thermal_of_zone_register() argument
485 return ERR_PTR(-ENOMEM); in thermal_of_zone_register()
487 np = of_thermal_zone_find(sensor, id); in thermal_of_zone_register()
489 if (PTR_ERR(np) != -ENODEV) in thermal_of_zone_register()
490 pr_err("Failed to find thermal zone for %pOFn id=%d\n", sensor, id); in thermal_of_zone_register()
497 pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id); in thermal_of_zone_register()
510 of_ops->bind = thermal_of_bind; in thermal_of_zone_register()
511 of_ops->unbind = thermal_of_unbind; in thermal_of_zone_register()
513 mask = GENMASK_ULL((ntrips) - 1, 0); in thermal_of_zone_register()
515 ret = of_property_read_string(np, "critical-action", &action); in thermal_of_zone_register()
517 if (!of_ops->critical && !strcasecmp(action, "reboot")) in thermal_of_zone_register()
518 of_ops->critical = thermal_zone_device_critical_reboot; in thermal_of_zone_register()
520 tz = thermal_zone_device_register_with_trips(np->name, trips, ntrips, in thermal_of_zone_register()
525 pr_err("Failed to register thermal zone %pOFn: %d\n", np, ret); in thermal_of_zone_register()
531 pr_err("Failed to enabled thermal zone '%s', id=%d: %d\n", in thermal_of_zone_register()
532 tz->type, tz->id, ret); in thermal_of_zone_register()
564 * devm_thermal_of_zone_register - register a thermal tied with the sensor life cycle
568 * @dev: a device structure pointer to sensor to be tied with the thermal zone OF life cycle
569 * @sensor_id: the sensor identifier
570 * @data: a pointer to a private data to be stored in the thermal zone 'devdata' field
571 * @ops: a pointer to the ops structure associated with the sensor
581 return ERR_PTR(-ENOMEM); in devm_thermal_of_zone_register()
583 tzd = thermal_of_zone_register(dev->of_node, sensor_id, data, ops); in devm_thermal_of_zone_register()
597 * devm_thermal_of_zone_unregister - Resource managed version of
600 * @tz: a pointer to struct thermal_zone where the sensor is registered.
602 * This function removes the sensor callbacks and private data from the
603 * thermal zone device registered with devm_thermal_zone_of_sensor_register()
605 * thermal zone device callbacks.