hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/thermal/thermal_sysfs.c
....@@ -18,6 +18,7 @@
1818 #include <linux/slab.h>
1919 #include <linux/string.h>
2020 #include <linux/jiffies.h>
21
+#include <trace/hooks/thermal.h>
2122
2223 #include "thermal_core.h"
2324
....@@ -49,18 +50,9 @@
4950 mode_show(struct device *dev, struct device_attribute *attr, char *buf)
5051 {
5152 struct thermal_zone_device *tz = to_thermal_zone(dev);
52
- enum thermal_device_mode mode;
53
- int result;
53
+ int enabled = thermal_zone_device_is_enabled(tz);
5454
55
- if (!tz->ops->get_mode)
56
- return -EPERM;
57
-
58
- result = tz->ops->get_mode(tz, &mode);
59
- if (result)
60
- return result;
61
-
62
- return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled"
63
- : "disabled");
55
+ return sprintf(buf, "%s\n", enabled ? "enabled" : "disabled");
6456 }
6557
6658 static ssize_t
....@@ -70,13 +62,10 @@
7062 struct thermal_zone_device *tz = to_thermal_zone(dev);
7163 int result;
7264
73
- if (!tz->ops->set_mode)
74
- return -EPERM;
75
-
7665 if (!strncmp(buf, "enabled", sizeof("enabled") - 1))
77
- result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED);
66
+ result = thermal_zone_device_enable(tz);
7867 else if (!strncmp(buf, "disabled", sizeof("disabled") - 1))
79
- result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED);
68
+ result = thermal_zone_device_disable(tz);
8069 else
8170 result = -EINVAL;
8271
....@@ -124,7 +113,8 @@
124113 {
125114 struct thermal_zone_device *tz = to_thermal_zone(dev);
126115 int trip, ret;
127
- int temperature;
116
+ int temperature, hyst = 0;
117
+ enum thermal_trip_type type;
128118
129119 if (!tz->ops->set_trip_temp)
130120 return -EPERM;
....@@ -138,6 +128,18 @@
138128 ret = tz->ops->set_trip_temp(tz, trip, temperature);
139129 if (ret)
140130 return ret;
131
+
132
+ if (tz->ops->get_trip_hyst) {
133
+ ret = tz->ops->get_trip_hyst(tz, trip, &hyst);
134
+ if (ret)
135
+ return ret;
136
+ }
137
+
138
+ ret = tz->ops->get_trip_type(tz, trip, &type);
139
+ if (ret)
140
+ return ret;
141
+
142
+ thermal_notify_tz_trip_change(tz->id, trip, type, temperature, hyst);
141143
142144 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
143145
....@@ -428,30 +430,13 @@
428430 .attrs = thermal_zone_dev_attrs,
429431 };
430432
431
-/* We expose mode only if .get_mode is present */
432433 static struct attribute *thermal_zone_mode_attrs[] = {
433434 &dev_attr_mode.attr,
434435 NULL,
435436 };
436437
437
-static umode_t thermal_zone_mode_is_visible(struct kobject *kobj,
438
- struct attribute *attr,
439
- int attrno)
440
-{
441
- struct device *dev = container_of(kobj, struct device, kobj);
442
- struct thermal_zone_device *tz;
443
-
444
- tz = container_of(dev, struct thermal_zone_device, device);
445
-
446
- if (tz->ops->get_mode)
447
- return attr->mode;
448
-
449
- return 0;
450
-}
451
-
452438 static struct attribute_group thermal_zone_mode_attribute_group = {
453439 .attrs = thermal_zone_mode_attrs,
454
- .is_visible = thermal_zone_mode_is_visible,
455440 };
456441
457442 /* We expose passive only if passive trips are present */
....@@ -464,7 +449,7 @@
464449 struct attribute *attr,
465450 int attrno)
466451 {
467
- struct device *dev = container_of(kobj, struct device, kobj);
452
+ struct device *dev = kobj_to_dev(kobj);
468453 struct thermal_zone_device *tz;
469454 enum thermal_trip_type trip_type;
470455 int count, passive = 0;
....@@ -902,19 +887,39 @@
902887 NULL
903888 };
904889
890
+static umode_t cooling_device_stats_is_visible(struct kobject *kobj,
891
+ struct attribute *attr, int attrno)
892
+{
893
+ struct thermal_cooling_device *cdev = to_cooling_device(
894
+ kobj_to_dev(kobj));
895
+
896
+ if (!cdev->stats)
897
+ return 0;
898
+
899
+ return attr->mode;
900
+}
901
+
905902 static const struct attribute_group cooling_device_stats_attr_group = {
906903 .attrs = cooling_device_stats_attrs,
907
- .name = "stats"
904
+ .name = "stats",
905
+ .is_visible = cooling_device_stats_is_visible,
908906 };
909907
910908 static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)
911909 {
910
+ const struct attribute_group *stats_attr_group = NULL;
912911 struct cooling_dev_stats *stats;
913912 unsigned long states;
914913 int var;
914
+ bool disable_cdev_stats = false;
915
+
916
+ trace_android_vh_disable_thermal_cooling_stats(cdev,
917
+ &disable_cdev_stats);
918
+ if (disable_cdev_stats)
919
+ return;
915920
916921 if (cdev->ops->get_max_state(cdev, &states))
917
- return;
922
+ goto out;
918923
919924 states++; /* Total number of states is highest state + 1 */
920925
....@@ -924,7 +929,7 @@
924929
925930 stats = kzalloc(var, GFP_KERNEL);
926931 if (!stats)
927
- return;
932
+ goto out;
928933
929934 stats->time_in_state = (ktime_t *)(stats + 1);
930935 stats->trans_table = (unsigned int *)(stats->time_in_state + states);
....@@ -934,9 +939,12 @@
934939
935940 spin_lock_init(&stats->lock);
936941
942
+ stats_attr_group = &cooling_device_stats_attr_group;
943
+
944
+out:
937945 /* Fill the empty slot left in cooling_device_attr_groups */
938946 var = ARRAY_SIZE(cooling_device_attr_groups) - 2;
939
- cooling_device_attr_groups[var] = &cooling_device_stats_attr_group;
947
+ cooling_device_attr_groups[var] = stats_attr_group;
940948 }
941949
942950 static void cooling_device_stats_destroy(struct thermal_cooling_device *cdev)
....@@ -978,26 +986,6 @@
978986 return sprintf(buf, "-1\n");
979987 else
980988 return sprintf(buf, "%d\n", instance->trip);
981
-}
982
-
983
-ssize_t trip_point_store(struct device *dev, struct device_attribute *attr,
984
- const char *buf, size_t count)
985
-{
986
- struct thermal_instance *instance;
987
- int ret, trip;
988
-
989
- ret = kstrtoint(buf, 0, &trip);
990
- if (ret)
991
- return ret;
992
-
993
- instance = container_of(attr, struct thermal_instance, attr);
994
-
995
- if (trip >= instance->tz->trips || trip < THERMAL_TRIPS_NONE)
996
- return -EINVAL;
997
-
998
- instance->trip = trip;
999
-
1000
- return count;
1001989 }
1002990
1003991 ssize_t