Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / thermal / thermal_trip.c
blob4b8238468b5343c6d1d30c3b95caf8af30580914
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2008 Intel Corp
4 * Copyright (C) 2008 Zhang Rui <rui.zhang@intel.com>
5 * Copyright (C) 2008 Sujith Thomas <sujith.thomas@intel.com>
6 * Copyright 2022 Linaro Limited
8 * Thermal trips handling
9 */
10 #include "thermal_core.h"
12 static const char *trip_type_names[] = {
13 [THERMAL_TRIP_ACTIVE] = "active",
14 [THERMAL_TRIP_PASSIVE] = "passive",
15 [THERMAL_TRIP_HOT] = "hot",
16 [THERMAL_TRIP_CRITICAL] = "critical",
19 const char *thermal_trip_type_name(enum thermal_trip_type trip_type)
21 if (trip_type < THERMAL_TRIP_ACTIVE || trip_type > THERMAL_TRIP_CRITICAL)
22 return "unknown";
24 return trip_type_names[trip_type];
27 int for_each_thermal_trip(struct thermal_zone_device *tz,
28 int (*cb)(struct thermal_trip *, void *),
29 void *data)
31 struct thermal_trip_desc *td;
32 int ret;
34 for_each_trip_desc(tz, td) {
35 ret = cb(&td->trip, data);
36 if (ret)
37 return ret;
40 return 0;
42 EXPORT_SYMBOL_GPL(for_each_thermal_trip);
44 int thermal_zone_for_each_trip(struct thermal_zone_device *tz,
45 int (*cb)(struct thermal_trip *, void *),
46 void *data)
48 guard(thermal_zone)(tz);
50 return for_each_thermal_trip(tz, cb, data);
52 EXPORT_SYMBOL_GPL(thermal_zone_for_each_trip);
54 void thermal_zone_set_trips(struct thermal_zone_device *tz, int low, int high)
56 int ret;
58 lockdep_assert_held(&tz->lock);
60 if (!tz->ops.set_trips)
61 return;
63 /* No need to change trip points */
64 if (tz->prev_low_trip == low && tz->prev_high_trip == high)
65 return;
67 tz->prev_low_trip = low;
68 tz->prev_high_trip = high;
70 dev_dbg(&tz->device,
71 "new temperature boundaries: %d < x < %d\n", low, high);
74 * Set a temperature window. When this window is left the driver
75 * must inform the thermal core via thermal_zone_device_update.
77 ret = tz->ops.set_trips(tz, low, high);
78 if (ret)
79 dev_err(&tz->device, "Failed to set trips: %d\n", ret);
82 int thermal_zone_trip_id(const struct thermal_zone_device *tz,
83 const struct thermal_trip *trip)
86 * Assume the trip to be located within the bounds of the thermal
87 * zone's trips[] table.
89 return trip_to_trip_desc(trip) - tz->trips;