.. | .. |
---|
18 | 18 | #include <linux/slab.h> |
---|
19 | 19 | #include <linux/string.h> |
---|
20 | 20 | #include <linux/jiffies.h> |
---|
| 21 | +#include <trace/hooks/thermal.h> |
---|
21 | 22 | |
---|
22 | 23 | #include "thermal_core.h" |
---|
23 | 24 | |
---|
.. | .. |
---|
49 | 50 | mode_show(struct device *dev, struct device_attribute *attr, char *buf) |
---|
50 | 51 | { |
---|
51 | 52 | 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); |
---|
54 | 54 | |
---|
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"); |
---|
64 | 56 | } |
---|
65 | 57 | |
---|
66 | 58 | static ssize_t |
---|
.. | .. |
---|
70 | 62 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
---|
71 | 63 | int result; |
---|
72 | 64 | |
---|
73 | | - if (!tz->ops->set_mode) |
---|
74 | | - return -EPERM; |
---|
75 | | - |
---|
76 | 65 | if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) |
---|
77 | | - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); |
---|
| 66 | + result = thermal_zone_device_enable(tz); |
---|
78 | 67 | 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); |
---|
80 | 69 | else |
---|
81 | 70 | result = -EINVAL; |
---|
82 | 71 | |
---|
.. | .. |
---|
124 | 113 | { |
---|
125 | 114 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
---|
126 | 115 | int trip, ret; |
---|
127 | | - int temperature; |
---|
| 116 | + int temperature, hyst = 0; |
---|
| 117 | + enum thermal_trip_type type; |
---|
128 | 118 | |
---|
129 | 119 | if (!tz->ops->set_trip_temp) |
---|
130 | 120 | return -EPERM; |
---|
.. | .. |
---|
138 | 128 | ret = tz->ops->set_trip_temp(tz, trip, temperature); |
---|
139 | 129 | if (ret) |
---|
140 | 130 | 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); |
---|
141 | 143 | |
---|
142 | 144 | thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); |
---|
143 | 145 | |
---|
.. | .. |
---|
428 | 430 | .attrs = thermal_zone_dev_attrs, |
---|
429 | 431 | }; |
---|
430 | 432 | |
---|
431 | | -/* We expose mode only if .get_mode is present */ |
---|
432 | 433 | static struct attribute *thermal_zone_mode_attrs[] = { |
---|
433 | 434 | &dev_attr_mode.attr, |
---|
434 | 435 | NULL, |
---|
435 | 436 | }; |
---|
436 | 437 | |
---|
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 | | - |
---|
452 | 438 | static struct attribute_group thermal_zone_mode_attribute_group = { |
---|
453 | 439 | .attrs = thermal_zone_mode_attrs, |
---|
454 | | - .is_visible = thermal_zone_mode_is_visible, |
---|
455 | 440 | }; |
---|
456 | 441 | |
---|
457 | 442 | /* We expose passive only if passive trips are present */ |
---|
.. | .. |
---|
464 | 449 | struct attribute *attr, |
---|
465 | 450 | int attrno) |
---|
466 | 451 | { |
---|
467 | | - struct device *dev = container_of(kobj, struct device, kobj); |
---|
| 452 | + struct device *dev = kobj_to_dev(kobj); |
---|
468 | 453 | struct thermal_zone_device *tz; |
---|
469 | 454 | enum thermal_trip_type trip_type; |
---|
470 | 455 | int count, passive = 0; |
---|
.. | .. |
---|
902 | 887 | NULL |
---|
903 | 888 | }; |
---|
904 | 889 | |
---|
| 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 | + |
---|
905 | 902 | static const struct attribute_group cooling_device_stats_attr_group = { |
---|
906 | 903 | .attrs = cooling_device_stats_attrs, |
---|
907 | | - .name = "stats" |
---|
| 904 | + .name = "stats", |
---|
| 905 | + .is_visible = cooling_device_stats_is_visible, |
---|
908 | 906 | }; |
---|
909 | 907 | |
---|
910 | 908 | static void cooling_device_stats_setup(struct thermal_cooling_device *cdev) |
---|
911 | 909 | { |
---|
| 910 | + const struct attribute_group *stats_attr_group = NULL; |
---|
912 | 911 | struct cooling_dev_stats *stats; |
---|
913 | 912 | unsigned long states; |
---|
914 | 913 | 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; |
---|
915 | 920 | |
---|
916 | 921 | if (cdev->ops->get_max_state(cdev, &states)) |
---|
917 | | - return; |
---|
| 922 | + goto out; |
---|
918 | 923 | |
---|
919 | 924 | states++; /* Total number of states is highest state + 1 */ |
---|
920 | 925 | |
---|
.. | .. |
---|
924 | 929 | |
---|
925 | 930 | stats = kzalloc(var, GFP_KERNEL); |
---|
926 | 931 | if (!stats) |
---|
927 | | - return; |
---|
| 932 | + goto out; |
---|
928 | 933 | |
---|
929 | 934 | stats->time_in_state = (ktime_t *)(stats + 1); |
---|
930 | 935 | stats->trans_table = (unsigned int *)(stats->time_in_state + states); |
---|
.. | .. |
---|
934 | 939 | |
---|
935 | 940 | spin_lock_init(&stats->lock); |
---|
936 | 941 | |
---|
| 942 | + stats_attr_group = &cooling_device_stats_attr_group; |
---|
| 943 | + |
---|
| 944 | +out: |
---|
937 | 945 | /* Fill the empty slot left in cooling_device_attr_groups */ |
---|
938 | 946 | 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; |
---|
940 | 948 | } |
---|
941 | 949 | |
---|
942 | 950 | static void cooling_device_stats_destroy(struct thermal_cooling_device *cdev) |
---|
.. | .. |
---|
978 | 986 | return sprintf(buf, "-1\n"); |
---|
979 | 987 | else |
---|
980 | 988 | 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; |
---|
1001 | 989 | } |
---|
1002 | 990 | |
---|
1003 | 991 | ssize_t |
---|