--- zzzz-none-000/linux-5.4.213/drivers/thermal/of-thermal.c 2022-09-15 10:04:56.000000000 +0000 +++ alder-5690pro-762/linux-5.4.213/drivers/thermal/of-thermal.c 2024-08-14 09:02:08.000000000 +0000 @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include "thermal_core.h" @@ -91,7 +93,7 @@ { struct __thermal_zone *data = tz->devdata; - if (!data->ops || !data->ops->get_temp) + if (!data->ops || !data->ops->get_temp || data->mode == THERMAL_DEVICE_DISABLED) return -EINVAL; return data->ops->get_temp(data->sensor_data, temp); @@ -108,6 +110,17 @@ return data->ops->set_trips(data->sensor_data, low, high); } +static int of_thermal_panic_notify(struct thermal_zone_device *tz) +{ + struct __thermal_zone *data = tz->devdata; + + if (!data->ops || !data->ops->panic_notify + || (data->mode == THERMAL_DEVICE_DISABLED)) + return -EINVAL; + + return data->ops->panic_notify(data->sensor_data); +} + /** * of_thermal_get_ntrips - function to export number of available trip * points. @@ -188,7 +201,7 @@ { struct __thermal_zone *data = tz->devdata; - if (!data->ops || !data->ops->set_emul_temp) + if (!data->ops || !data->ops->set_emul_temp || data->mode == THERMAL_DEVICE_DISABLED) return -EINVAL; return data->ops->set_emul_temp(data->sensor_data, temp); @@ -199,7 +212,7 @@ { struct __thermal_zone *data = tz->devdata; - if (!data->ops || !data->ops->get_trend) + if (!data->ops || !data->ops->get_trend || data->mode == THERMAL_DEVICE_DISABLED) return -EINVAL; return data->ops->get_trend(data->sensor_data, trip, trend); @@ -300,7 +313,9 @@ mutex_unlock(&tz->lock); data->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + if (mode == THERMAL_DEVICE_ENABLED) + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); return 0; } @@ -318,6 +333,31 @@ return 0; } +static int of_thermal_activate_trip_type(struct thermal_zone_device *tz, + int trip, enum thermal_trip_activation_mode mode) +{ + struct __thermal_zone *data = tz->devdata; + + if (trip >= data->ntrips || trip < 0) + return -EDOM; + + /* + * The configurable_hi and configurable_lo trip points can be + * activated and deactivated. + */ + + if (data->ops->set_trip_activate) { + int ret; + + ret = data->ops->set_trip_activate(data->sensor_data, + trip, mode); + if (ret) + return ret; + } + + return 0; +} + static int of_thermal_get_trip_temp(struct thermal_zone_device *tz, int trip, int *temp) { @@ -434,6 +474,7 @@ tz->sensor_data = data; tzd->ops->get_temp = of_thermal_get_temp; + tzd->ops->panic_notify = of_thermal_panic_notify; tzd->ops->get_trend = of_thermal_get_trend; /* @@ -446,11 +487,28 @@ if (ops->set_emul_temp) tzd->ops->set_emul_temp = of_thermal_set_emul_temp; + if (ops->set_trip_activate) + tzd->ops->set_trip_activate = of_thermal_activate_trip_type; + mutex_unlock(&tzd->lock); return tzd; } +#define CONVERT_TO_DEZI_CELSIUS(x) ((x)*10) + +int read_temp_callback(void *avm_power_handle, void *context, int *value) +{ + struct thermal_zone_device *tzd = context; + int ret; + + ret = thermal_zone_get_temp(tzd, value); + if (!ret) + *value = CONVERT_TO_DEZI_CELSIUS(*value); + + return ret; +} + /** * thermal_zone_of_sensor_register - registers a sensor to a DT thermal zone * @dev: a valid struct device pointer of a sensor device. Must contain @@ -537,6 +595,9 @@ of_node_put(sensor_np); of_node_put(np); + if (!IS_ERR(tzd)) + tzd->avm_power_handle = TemperaturSensorRegister(tzd->type, + read_temp_callback, tzd); return tzd; } EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_register); @@ -564,6 +625,9 @@ if (!dev || !tzd || !tzd->devdata) return; + if (tzd->avm_power_handle) + TemperaturSensorDeregister(tzd->avm_power_handle); + tz = tzd->devdata; /* no __thermal_zone, nothing to be done */ @@ -768,7 +832,11 @@ [THERMAL_TRIP_ACTIVE] = "active", [THERMAL_TRIP_PASSIVE] = "passive", [THERMAL_TRIP_HOT] = "hot", - [THERMAL_TRIP_CRITICAL] = "critical", + [THERMAL_TRIP_CRITICAL] = "critical_high", + [THERMAL_TRIP_CONFIGURABLE_HI] = "configurable_hi", + [THERMAL_TRIP_CONFIGURABLE_LOW] = "configurable_lo", + [THERMAL_TRIP_CRITICAL_LOW] = "critical_low", + [THERMAL_TRIP_AVM_HOT] = "avm_hot", }; /**