Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Thermal: int3403: Add CRT and PSV trip

The ACPI object definition can contain passive and critical
trip temperature. Export them via thermal sysfs.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>

authored by

Srinivas Pandruvada and committed by
Zhang Rui
5fcdeb20 a497c3ba

+60 -7
+60 -7
drivers/thermal/int3403_thermal.c
··· 33 33 struct int3403_sensor { 34 34 struct thermal_zone_device *tzone; 35 35 unsigned long *thresholds; 36 + unsigned long crit_temp; 37 + int crit_trip_id; 38 + unsigned long psv_temp; 39 + int psv_trip_id; 36 40 }; 37 41 38 42 static int sys_get_curr_temp(struct thermal_zone_device *tzone, ··· 83 79 struct acpi_device *device = tzone->devdata; 84 80 struct int3403_sensor *obj = acpi_driver_data(device); 85 81 86 - /* 87 - * get_trip_temp is a mandatory callback but 88 - * PATx method doesn't return any value, so return 89 - * cached value, which was last set from user space. 90 - */ 91 - *temp = obj->thresholds[trip]; 82 + if (trip == obj->crit_trip_id) 83 + *temp = obj->crit_temp; 84 + else if (trip == obj->psv_trip_id) 85 + *temp = obj->psv_temp; 86 + else { 87 + /* 88 + * get_trip_temp is a mandatory callback but 89 + * PATx method doesn't return any value, so return 90 + * cached value, which was last set from user space. 91 + */ 92 + *temp = obj->thresholds[trip]; 93 + } 92 94 93 95 return 0; 94 96 } ··· 102 92 static int sys_get_trip_type(struct thermal_zone_device *thermal, 103 93 int trip, enum thermal_trip_type *type) 104 94 { 95 + struct acpi_device *device = thermal->devdata; 96 + struct int3403_sensor *obj = acpi_driver_data(device); 97 + 105 98 /* Mandatory callback, may not mean much here */ 106 - *type = THERMAL_TRIP_PASSIVE; 99 + if (trip == obj->crit_trip_id) 100 + *type = THERMAL_TRIP_CRITICAL; 101 + else 102 + *type = THERMAL_TRIP_PASSIVE; 107 103 108 104 return 0; 109 105 } ··· 171 155 } 172 156 } 173 157 158 + static int sys_get_trip_crt(struct acpi_device *device, unsigned long *temp) 159 + { 160 + unsigned long long crt; 161 + acpi_status status; 162 + 163 + status = acpi_evaluate_integer(device->handle, "_CRT", NULL, &crt); 164 + if (ACPI_FAILURE(status)) 165 + return -EIO; 166 + 167 + *temp = DECI_KELVIN_TO_MILLI_CELSIUS(crt, KELVIN_OFFSET); 168 + 169 + return 0; 170 + } 171 + 172 + static int sys_get_trip_psv(struct acpi_device *device, unsigned long *temp) 173 + { 174 + unsigned long long psv; 175 + acpi_status status; 176 + 177 + status = acpi_evaluate_integer(device->handle, "_PSV", NULL, &psv); 178 + if (ACPI_FAILURE(status)) 179 + return -EIO; 180 + 181 + *temp = DECI_KELVIN_TO_MILLI_CELSIUS(psv, KELVIN_OFFSET); 182 + 183 + return 0; 184 + } 185 + 174 186 static int acpi_int3403_add(struct acpi_device *device) 175 187 { 176 188 int result = 0; ··· 238 194 return -ENOMEM; 239 195 trip_mask = BIT(trip_cnt) - 1; 240 196 } 197 + 198 + obj->psv_trip_id = -1; 199 + if (!sys_get_trip_psv(device, &obj->psv_temp)) 200 + obj->psv_trip_id = trip_cnt++; 201 + 202 + obj->crit_trip_id = -1; 203 + if (!sys_get_trip_crt(device, &obj->crit_temp)) 204 + obj->crit_trip_id = trip_cnt++; 205 + 241 206 obj->tzone = thermal_zone_device_register(acpi_device_bid(device), 242 207 trip_cnt, trip_mask, device, &tzone_ops, 243 208 NULL, 0, 0);