Lines Matching +full:thermal +full:- +full:sensor
1 // SPDX-License-Identifier: GPL-2.0
3 * of-thermal.c - Generic Thermal Management device tree support.
16 #include <linux/thermal.h>
23 * of_thermal_get_ntrips - function to export number of available trip
25 * @tz: pointer to a thermal zone
30 * Return: number of available trip points, -ENODEV when data not available
34 return tz->num_trips; in of_thermal_get_ntrips()
39 * of_thermal_is_trip_valid - function to check if trip point is valid
41 * @tz: pointer to a thermal zone
50 if (trip >= tz->num_trips || trip < 0) in of_thermal_is_trip_valid()
58 * of_thermal_get_trip_points - function to get access to a globally exported
61 * @tz: pointer to a thermal zone
70 return tz->trips; in of_thermal_get_trip_points()
77 if (trip >= tz->num_trips || trip < 0) in of_thermal_get_trip_type()
78 return -EDOM; in of_thermal_get_trip_type()
80 *type = tz->trips[trip].type; in of_thermal_get_trip_type()
88 if (trip >= tz->num_trips || trip < 0) in of_thermal_get_trip_temp()
89 return -EDOM; in of_thermal_get_trip_temp()
91 *temp = tz->trips[trip].temperature; in of_thermal_get_trip_temp()
99 if (trip >= tz->num_trips || trip < 0) in of_thermal_get_trip_hyst()
100 return -EDOM; in of_thermal_get_trip_hyst()
102 *hyst = tz->trips[trip].hysteresis; in of_thermal_get_trip_hyst()
110 if (trip >= tz->num_trips || trip < 0) in of_thermal_set_trip_hyst()
111 return -EDOM; in of_thermal_set_trip_hyst()
113 /* thermal framework should take care of data->mask & (1 << trip) */ in of_thermal_set_trip_hyst()
114 tz->trips[trip].hysteresis = hyst; in of_thermal_set_trip_hyst()
124 for (i = 0; i < tz->num_trips; i++) in of_thermal_get_crit_temp()
125 if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) { in of_thermal_get_crit_temp()
126 *temp = tz->trips[i].temperature; in of_thermal_get_crit_temp()
130 return -EINVAL; in of_thermal_get_crit_temp()
144 return -EINVAL; in of_find_trip_id()
157 i = -ENXIO; in of_find_trip_id()
165 * It maps 'enum thermal_trip_type' found in include/linux/thermal.h
176 * thermal_of_get_trip_type - Get phy mode for given device_node
201 return -ENODEV; in thermal_of_get_trip_type()
215 trip->temperature = prop; in thermal_of_populate_trip()
222 trip->hysteresis = prop; in thermal_of_populate_trip()
224 ret = thermal_of_get_trip_type(np, &trip->type); in thermal_of_populate_trip()
242 return ERR_PTR(-EINVAL); in thermal_of_trips_init()
248 ret = -EINVAL; in thermal_of_trips_init()
254 ret = -ENOMEM; in thermal_of_trips_init()
280 static struct device_node *of_thermal_zone_find(struct device_node *sensor, int id) in of_thermal_zone_find() argument
285 np = of_find_node_by_name(NULL, "thermal-zones"); in of_thermal_zone_find()
287 pr_debug("No thermal zones description\n"); in of_thermal_zone_find()
288 return ERR_PTR(-ENODEV); in of_thermal_zone_find()
292 * Search for each thermal zone, a defined sensor in of_thermal_zone_find()
299 count = of_count_phandle_with_args(tz, "thermal-sensors", in of_thermal_zone_find()
300 "#thermal-sensor-cells"); in of_thermal_zone_find()
302 pr_err("%pOFn: missing thermal sensor\n", tz); in of_thermal_zone_find()
303 tz = ERR_PTR(-EINVAL); in of_thermal_zone_find()
311 ret = of_parse_phandle_with_args(tz, "thermal-sensors", in of_thermal_zone_find()
312 "#thermal-sensor-cells", in of_thermal_zone_find()
315 pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", tz, ret); in of_thermal_zone_find()
320 if ((sensor == sensor_specs.np) && id == (sensor_specs.args_count ? in of_thermal_zone_find()
322 pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, tz); in of_thermal_zone_find()
327 tz = ERR_PTR(-ENODEV); in of_thermal_zone_find()
337 ret = of_property_read_u32(np, "polling-delay-passive", pdelay); in thermal_of_monitor_init()
339 pr_err("%pOFn: missing polling-delay-passive property\n", np); in thermal_of_monitor_init()
343 ret = of_property_read_u32(np, "polling-delay", delay); in thermal_of_monitor_init()
345 pr_err("%pOFn: missing polling-delay property\n", np); in thermal_of_monitor_init()
361 return ERR_PTR(-ENOMEM); in thermal_of_parameters_init()
363 tzp->no_hwmon = true; in thermal_of_parameters_init()
365 if (!of_property_read_u32(np, "sustainable-power", &prop)) in thermal_of_parameters_init()
366 tzp->sustainable_power = prop; in thermal_of_parameters_init()
369 * For now, the thermal framework supports only one sensor per in thermal_of_parameters_init()
370 * thermal zone. Thus, we are considering only the first two in thermal_of_parameters_init()
379 tzp->slope = coef[0]; in thermal_of_parameters_init()
380 tzp->offset = coef[1]; in thermal_of_parameters_init()
389 np = of_find_node_by_name(NULL, "thermal-zones"); in thermal_of_zone_get_by_name()
391 return ERR_PTR(-ENODEV); in thermal_of_zone_get_by_name()
393 tz_np = of_get_child_by_name(np, tz->type); in thermal_of_zone_get_by_name()
398 return ERR_PTR(-ENODEV); in thermal_of_zone_get_by_name()
409 ret = of_parse_phandle_with_args(map_np, "cooling-device", "#cooling-cells", in __thermal_of_unbind()
415 pr_err("Invalid cooling-device entry\n"); in __thermal_of_unbind()
421 return -EINVAL; in __thermal_of_unbind()
424 if (cooling_spec.np != cdev->np) in __thermal_of_unbind()
429 pr_err("Failed to unbind '%s' with '%s': %d\n", tz->type, cdev->type, ret); in __thermal_of_unbind()
442 ret = of_parse_phandle_with_args(map_np, "cooling-device", "#cooling-cells", in __thermal_of_bind()
448 pr_err("Invalid cooling-device entry\n"); in __thermal_of_bind()
454 return -EINVAL; in __thermal_of_bind()
457 if (cooling_spec.np != cdev->np) in __thermal_of_bind()
464 pr_err("Failed to bind '%s' with '%s': %d\n", tz->type, cdev->type, ret); in __thermal_of_bind()
479 return -ENODEV; in thermal_of_for_each_cooling_device()
485 count = of_count_phandle_with_args(map_np, "cooling-device", "#cooling-cells"); in thermal_of_for_each_cooling_device()
488 return -ENOENT; in thermal_of_for_each_cooling_device()
516 cm_np = of_get_child_by_name(tz_np, "cooling-maps"); in thermal_of_for_each_cooling_maps()
546 * thermal_of_zone_unregister - Cleanup the specific allocated ressources
548 * This function disables the thermal zone and frees the different
549 * ressources allocated specific to the thermal OF.
551 * @tz: a pointer to the thermal zone structure
555 struct thermal_trip *trips = tz->trips; in thermal_of_zone_unregister()
556 struct thermal_zone_params *tzp = tz->tzp; in thermal_of_zone_unregister()
557 struct thermal_zone_device_ops *ops = tz->ops; in thermal_of_zone_unregister()
568 * thermal_of_zone_register - Register a thermal zone with device node
569 * sensor
572 * node sensor and identifier. It searches for the thermal zone
573 * associated to the couple sensor/id and retrieves all the thermal
574 * zone properties and registers new thermal zone with those
577 * @sensor: A device node pointer corresponding to the sensor in the device tree
578 * @id: An integer as sensor identifier
579 * @data: A private data to be stored in the thermal zone dedicated private area
580 * @ops: A set of thermal sensor ops
582 * Return: a valid thermal zone structure pointer on success.
583 * - EINVAL: if the device tree thermal description is malformed
584 * - ENOMEM: if one structure can not be allocated
585 * - Other negative errors are returned by the underlying called functions
587 struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, int id, void *data, in thermal_of_zone_register() argument
601 return ERR_PTR(-ENOMEM); in thermal_of_zone_register()
603 np = of_thermal_zone_find(sensor, id); in thermal_of_zone_register()
605 if (PTR_ERR(np) != -ENODEV) in thermal_of_zone_register()
606 pr_err("Failed to find thermal zone for %pOFn id=%d\n", sensor, id); in thermal_of_zone_register()
612 pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id); in thermal_of_zone_register()
629 of_ops->get_trip_type = of_ops->get_trip_type ? : of_thermal_get_trip_type; in thermal_of_zone_register()
630 of_ops->get_trip_temp = of_ops->get_trip_temp ? : of_thermal_get_trip_temp; in thermal_of_zone_register()
631 of_ops->get_trip_hyst = of_ops->get_trip_hyst ? : of_thermal_get_trip_hyst; in thermal_of_zone_register()
632 of_ops->set_trip_hyst = of_ops->set_trip_hyst ? : of_thermal_set_trip_hyst; in thermal_of_zone_register()
633 of_ops->get_crit_temp = of_ops->get_crit_temp ? : of_thermal_get_crit_temp; in thermal_of_zone_register()
634 of_ops->bind = thermal_of_bind; in thermal_of_zone_register()
635 of_ops->unbind = thermal_of_unbind; in thermal_of_zone_register()
637 mask = GENMASK_ULL((ntrips) - 1, 0); in thermal_of_zone_register()
639 tz = thermal_zone_device_register_with_trips(np->name, trips, ntrips, in thermal_of_zone_register()
644 pr_err("Failed to register thermal zone %pOFn: %d\n", np, ret); in thermal_of_zone_register()
650 pr_err("Failed to enabled thermal zone '%s', id=%d: %d\n", in thermal_of_zone_register()
651 tz->type, tz->id, ret); in thermal_of_zone_register()
684 * devm_thermal_of_zone_register - register a thermal tied with the sensor life cycle
688 * @dev: a device structure pointer to sensor to be tied with the thermal zone OF life cycle
689 * @sensor_id: the sensor identifier
690 * @data: a pointer to a private data to be stored in the thermal zone 'devdata' field
691 * @ops: a pointer to the ops structure associated with the sensor
701 return ERR_PTR(-ENOMEM); in devm_thermal_of_zone_register()
703 tzd = thermal_of_zone_register(dev->of_node, sensor_id, data, ops); in devm_thermal_of_zone_register()
717 * devm_thermal_of_zone_unregister - Resource managed version of
720 * @tz: a pointer to struct thermal_zone where the sensor is registered.
722 * This function removes the sensor callbacks and private data from the
723 * thermal zone device registered with devm_thermal_zone_of_sensor_register()
725 * thermal zone device callbacks.