Commit ab33da3a authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

Merge branch 'thermal-core'

Merge updates related to the thermal core for 6.11-rc1:

 - Redesign the .set_trip_temp() thermal zone callback to take a trip
   pointer instead of a trip ID and update its users (Rafael Wysocki).

 - Avoid using invalid combinations of polling_delay and passive_delay
   thermal zone parameters (Rafael Wysocki).

 - Update a cooling device registration function to take a const
   argument (Krzysztof Kozlowski).

 - Make the uniphier thermal driver use thermal_zone_for_each_trip() for
   walking trip points (Rafael Wysocki).

* thermal-core:
  thermal: core: Add sanity checks for polling_delay and passive_delay
  thermal: trip: Fold __thermal_zone_get_trip() into its caller
  thermal: trip: Pass trip pointer to .set_trip_temp() thermal zone callback
  thermal: imx: Drop critical trip check from imx_set_trip_temp()
  thermal: trip: Add conversion macros for thermal trip priv field
  thermal: helpers: Introduce thermal_trip_is_bound_to_cdev()
  thermal: core: Change passive_delay and polling_delay data type
  thermal: core: constify 'type' in devm_thermal_of_cooling_device_register()
  thermal: uniphier: Use thermal_zone_for_each_trip() for walking trip points
parents 3fdd8ea3 36697164
...@@ -638,7 +638,7 @@ static int iwl_mvm_tzone_get_temp(struct thermal_zone_device *device, ...@@ -638,7 +638,7 @@ static int iwl_mvm_tzone_get_temp(struct thermal_zone_device *device,
} }
static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device, static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device,
int trip, int temp) const struct thermal_trip *trip, int temp)
{ {
struct iwl_mvm *mvm = thermal_zone_device_priv(device); struct iwl_mvm *mvm = thermal_zone_device_priv(device);
int ret; int ret;
......
...@@ -331,25 +331,16 @@ static int imx_change_mode(struct thermal_zone_device *tz, ...@@ -331,25 +331,16 @@ static int imx_change_mode(struct thermal_zone_device *tz,
return 0; return 0;
} }
static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip_id, static int imx_set_trip_temp(struct thermal_zone_device *tz,
int temp) const struct thermal_trip *trip, int temp)
{ {
struct imx_thermal_data *data = thermal_zone_device_priv(tz); struct imx_thermal_data *data = thermal_zone_device_priv(tz);
struct thermal_trip trip;
int ret; int ret;
ret = pm_runtime_resume_and_get(data->dev); ret = pm_runtime_resume_and_get(data->dev);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = __thermal_zone_get_trip(tz, trip_id, &trip);
if (ret)
return ret;
/* do not allow changing critical threshold */
if (trip.type == THERMAL_TRIP_CRITICAL)
return -EPERM;
/* do not allow passive to be set higher than critical */ /* do not allow passive to be set higher than critical */
if (temp < 0 || temp > trips[IMX_TRIP_CRITICAL].temperature) if (temp < 0 || temp > trips[IMX_TRIP_CRITICAL].temperature)
return -EINVAL; return -EINVAL;
......
...@@ -39,13 +39,14 @@ static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone, ...@@ -39,13 +39,14 @@ static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone,
} }
static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone, static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,
int trip, int temp) const struct thermal_trip *trip, int temp)
{ {
struct int34x_thermal_zone *d = thermal_zone_device_priv(zone); struct int34x_thermal_zone *d = thermal_zone_device_priv(zone);
char name[] = {'P', 'A', 'T', '0' + trip, '\0'}; unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv);
char name[] = {'P', 'A', 'T', '0' + trip_index, '\0'};
acpi_status status; acpi_status status;
if (trip > 9) if (trip_index > 9)
return -EINVAL; return -EINVAL;
status = acpi_execute_simple_method(d->adev->handle, name, status = acpi_execute_simple_method(d->adev->handle, name,
...@@ -62,16 +63,6 @@ static void int340x_thermal_critical(struct thermal_zone_device *zone) ...@@ -62,16 +63,6 @@ static void int340x_thermal_critical(struct thermal_zone_device *zone)
thermal_zone_device_type(zone)); thermal_zone_device_type(zone));
} }
static inline void *int_to_trip_priv(int i)
{
return (void *)(long)i;
}
static inline int trip_priv_to_int(const struct thermal_trip *trip)
{
return (long)trip->priv;
}
static int int340x_thermal_read_trips(struct acpi_device *zone_adev, static int int340x_thermal_read_trips(struct acpi_device *zone_adev,
struct thermal_trip *zone_trips, struct thermal_trip *zone_trips,
int trip_cnt) int trip_cnt)
...@@ -106,7 +97,7 @@ static int int340x_thermal_read_trips(struct acpi_device *zone_adev, ...@@ -106,7 +97,7 @@ static int int340x_thermal_read_trips(struct acpi_device *zone_adev,
break; break;
zone_trips[trip_cnt].type = THERMAL_TRIP_ACTIVE; zone_trips[trip_cnt].type = THERMAL_TRIP_ACTIVE;
zone_trips[trip_cnt].priv = int_to_trip_priv(i); zone_trips[trip_cnt].priv = THERMAL_INT_TO_TRIP_PRIV(i);
trip_cnt++; trip_cnt++;
} }
...@@ -154,6 +145,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, ...@@ -154,6 +145,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
zone_trips[i].type = THERMAL_TRIP_PASSIVE; zone_trips[i].type = THERMAL_TRIP_PASSIVE;
zone_trips[i].temperature = THERMAL_TEMP_INVALID; zone_trips[i].temperature = THERMAL_TEMP_INVALID;
zone_trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP; zone_trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP;
zone_trips[i].priv = THERMAL_INT_TO_TRIP_PRIV(i);
} }
trip_cnt = int340x_thermal_read_trips(adev, zone_trips, trip_cnt); trip_cnt = int340x_thermal_read_trips(adev, zone_trips, trip_cnt);
...@@ -224,7 +216,7 @@ static int int340x_update_one_trip(struct thermal_trip *trip, void *arg) ...@@ -224,7 +216,7 @@ static int int340x_update_one_trip(struct thermal_trip *trip, void *arg)
break; break;
case THERMAL_TRIP_ACTIVE: case THERMAL_TRIP_ACTIVE:
err = thermal_acpi_active_trip_temp(zone_adev, err = thermal_acpi_active_trip_temp(zone_adev,
trip_priv_to_int(trip), THERMAL_TRIP_PRIV_TO_INT(trip->priv),
&temp); &temp);
break; break;
default: default:
......
...@@ -194,7 +194,8 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp) ...@@ -194,7 +194,8 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
return 0; return 0;
} }
static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) static int sys_set_trip_temp(struct thermal_zone_device *tzd,
const struct thermal_trip *trip, int temp)
{ {
struct proc_thermal_pci *pci_info = thermal_zone_device_priv(tzd); struct proc_thermal_pci *pci_info = thermal_zone_device_priv(tzd);
int tjmax, _temp; int tjmax, _temp;
......
...@@ -195,7 +195,7 @@ static int get_trip_temp(int trip) ...@@ -195,7 +195,7 @@ static int get_trip_temp(int trip)
} }
static int update_trip_temp(struct soc_sensor_entry *aux_entry, static int update_trip_temp(struct soc_sensor_entry *aux_entry,
int trip, int temp) int trip_index, int temp)
{ {
u32 out; u32 out;
u32 temp_out; u32 temp_out;
...@@ -230,9 +230,9 @@ static int update_trip_temp(struct soc_sensor_entry *aux_entry, ...@@ -230,9 +230,9 @@ static int update_trip_temp(struct soc_sensor_entry *aux_entry,
*/ */
temp_out = temp + QRK_DTS_TEMP_BASE; temp_out = temp + QRK_DTS_TEMP_BASE;
out = (store_ptps & ~(QRK_DTS_MASK_TP_THRES << out = (store_ptps & ~(QRK_DTS_MASK_TP_THRES <<
(trip * QRK_DTS_SHIFT_TP))); (trip_index * QRK_DTS_SHIFT_TP)));
out |= (temp_out & QRK_DTS_MASK_TP_THRES) << out |= (temp_out & QRK_DTS_MASK_TP_THRES) <<
(trip * QRK_DTS_SHIFT_TP); (trip_index * QRK_DTS_SHIFT_TP);
ret = iosf_mbi_write(QRK_MBI_UNIT_RMU, MBI_REG_WRITE, ret = iosf_mbi_write(QRK_MBI_UNIT_RMU, MBI_REG_WRITE,
QRK_DTS_REG_OFFSET_PTPS, out); QRK_DTS_REG_OFFSET_PTPS, out);
...@@ -242,10 +242,26 @@ static int update_trip_temp(struct soc_sensor_entry *aux_entry, ...@@ -242,10 +242,26 @@ static int update_trip_temp(struct soc_sensor_entry *aux_entry,
return ret; return ret;
} }
static inline int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, static inline int sys_set_trip_temp(struct thermal_zone_device *tzd,
int temp) const struct thermal_trip *trip,
int temp)
{ {
return update_trip_temp(thermal_zone_device_priv(tzd), trip, temp); unsigned int trip_index;
switch (trip->type) {
case THERMAL_TRIP_HOT:
trip_index = QRK_DTS_ID_TP_HOT;
break;
case THERMAL_TRIP_CRITICAL:
trip_index = QRK_DTS_ID_TP_CRITICAL;
break;
default:
return -EINVAL;
}
return update_trip_temp(thermal_zone_device_priv(tzd), trip_index, temp);
} }
static int sys_get_curr_temp(struct thermal_zone_device *tzd, static int sys_get_curr_temp(struct thermal_zone_device *tzd,
......
...@@ -129,18 +129,20 @@ static int update_trip_temp(struct intel_soc_dts_sensors *sensors, ...@@ -129,18 +129,20 @@ static int update_trip_temp(struct intel_soc_dts_sensors *sensors,
return status; return status;
} }
static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, static int sys_set_trip_temp(struct thermal_zone_device *tzd,
const struct thermal_trip *trip,
int temp) int temp)
{ {
struct intel_soc_dts_sensor_entry *dts = thermal_zone_device_priv(tzd); struct intel_soc_dts_sensor_entry *dts = thermal_zone_device_priv(tzd);
struct intel_soc_dts_sensors *sensors = dts->sensors; struct intel_soc_dts_sensors *sensors = dts->sensors;
unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv);
int status; int status;
if (temp > sensors->tj_max) if (temp > sensors->tj_max)
return -EINVAL; return -EINVAL;
mutex_lock(&sensors->dts_update_lock); mutex_lock(&sensors->dts_update_lock);
status = update_trip_temp(sensors, trip, temp); status = update_trip_temp(sensors, trip_index, temp);
mutex_unlock(&sensors->dts_update_lock); mutex_unlock(&sensors->dts_update_lock);
return status; return status;
...@@ -293,11 +295,12 @@ static void dts_trips_reset(struct intel_soc_dts_sensors *sensors, int dts_index ...@@ -293,11 +295,12 @@ static void dts_trips_reset(struct intel_soc_dts_sensors *sensors, int dts_index
} }
static void set_trip(struct thermal_trip *trip, enum thermal_trip_type type, static void set_trip(struct thermal_trip *trip, enum thermal_trip_type type,
u8 flags, int temp) u8 flags, int temp, unsigned int index)
{ {
trip->type = type; trip->type = type;
trip->flags = flags; trip->flags = flags;
trip->temperature = temp; trip->temperature = temp;
trip->priv = THERMAL_INT_TO_TRIP_PRIV(index);
} }
struct intel_soc_dts_sensors * struct intel_soc_dts_sensors *
...@@ -332,7 +335,7 @@ intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type, ...@@ -332,7 +335,7 @@ intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type,
sensors->soc_dts[i].sensors = sensors; sensors->soc_dts[i].sensors = sensors;
set_trip(&trips[i][0], THERMAL_TRIP_PASSIVE, set_trip(&trips[i][0], THERMAL_TRIP_PASSIVE,
THERMAL_TRIP_FLAG_RW_TEMP, 0); THERMAL_TRIP_FLAG_RW_TEMP, 0, 0);
ret = update_trip_temp(sensors, 0, 0); ret = update_trip_temp(sensors, 0, 0);
if (ret) if (ret)
...@@ -340,10 +343,10 @@ intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type, ...@@ -340,10 +343,10 @@ intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type,
if (critical_trip) { if (critical_trip) {
temp = sensors->tj_max - crit_offset; temp = sensors->tj_max - crit_offset;
set_trip(&trips[i][1], THERMAL_TRIP_CRITICAL, 0, temp); set_trip(&trips[i][1], THERMAL_TRIP_CRITICAL, 0, temp, 1);
} else { } else {
set_trip(&trips[i][1], THERMAL_TRIP_PASSIVE, set_trip(&trips[i][1], THERMAL_TRIP_PASSIVE,
THERMAL_TRIP_FLAG_RW_TEMP, 0); THERMAL_TRIP_FLAG_RW_TEMP, 0, 1);
temp = 0; temp = 0;
} }
......
...@@ -119,9 +119,11 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp) ...@@ -119,9 +119,11 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
} }
static int static int
sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) sys_set_trip_temp(struct thermal_zone_device *tzd,
const struct thermal_trip *trip, int temp)
{ {
struct zone_device *zonedev = thermal_zone_device_priv(tzd); struct zone_device *zonedev = thermal_zone_device_priv(tzd);
unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv);
u32 l, h, mask, shift, intr; u32 l, h, mask, shift, intr;
int tj_max, val, ret; int tj_max, val, ret;
...@@ -132,7 +134,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) ...@@ -132,7 +134,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
val = (tj_max - temp)/1000; val = (tj_max - temp)/1000;
if (trip >= MAX_NUMBER_OF_TRIPS || val < 0 || val > 0x7f) if (trip_index >= MAX_NUMBER_OF_TRIPS || val < 0 || val > 0x7f)
return -EINVAL; return -EINVAL;
ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
...@@ -140,7 +142,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) ...@@ -140,7 +142,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
if (ret < 0) if (ret < 0)
return ret; return ret;
if (trip) { if (trip_index) {
mask = THERM_MASK_THRESHOLD1; mask = THERM_MASK_THRESHOLD1;
shift = THERM_SHIFT_THRESHOLD1; shift = THERM_SHIFT_THRESHOLD1;
intr = THERM_INT_THRESHOLD1_ENABLE; intr = THERM_INT_THRESHOLD1_ENABLE;
...@@ -296,6 +298,7 @@ static int pkg_temp_thermal_trips_init(int cpu, int tj_max, ...@@ -296,6 +298,7 @@ static int pkg_temp_thermal_trips_init(int cpu, int tj_max,
trips[i].type = THERMAL_TRIP_PASSIVE; trips[i].type = THERMAL_TRIP_PASSIVE;
trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP; trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP;
trips[i].priv = THERMAL_INT_TO_TRIP_PRIV(i);
pr_debug("%s: cpu=%d, trip=%d, temp=%d\n", pr_debug("%s: cpu=%d, trip=%d, temp=%d\n",
__func__, cpu, i, trips[i].temperature); __func__, cpu, i, trips[i].temperature);
......
...@@ -261,17 +261,13 @@ static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip, ...@@ -261,17 +261,13 @@ static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip,
return qpnp_tm_write(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, reg); return qpnp_tm_write(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, reg);
} }
static int qpnp_tm_set_trip_temp(struct thermal_zone_device *tz, int trip_id, int temp) static int qpnp_tm_set_trip_temp(struct thermal_zone_device *tz,
const struct thermal_trip *trip, int temp)
{ {
struct qpnp_tm_chip *chip = thermal_zone_device_priv(tz); struct qpnp_tm_chip *chip = thermal_zone_device_priv(tz);
struct thermal_trip trip;
int ret; int ret;
ret = __thermal_zone_get_trip(chip->tz_dev, trip_id, &trip); if (trip->type != THERMAL_TRIP_CRITICAL)
if (ret)
return ret;
if (trip.type != THERMAL_TRIP_CRITICAL)
return 0; return 0;
mutex_lock(&chip->lock); mutex_lock(&chip->lock);
......
...@@ -582,23 +582,18 @@ static int tsensor_group_thermtrip_get(struct tegra_soctherm *ts, int id) ...@@ -582,23 +582,18 @@ static int tsensor_group_thermtrip_get(struct tegra_soctherm *ts, int id)
return temp; return temp;
} }
static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int trip_id, int temp) static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz,
const struct thermal_trip *trip, int temp)
{ {
struct tegra_thermctl_zone *zone = thermal_zone_device_priv(tz); struct tegra_thermctl_zone *zone = thermal_zone_device_priv(tz);
struct tegra_soctherm *ts = zone->ts; struct tegra_soctherm *ts = zone->ts;
struct thermal_trip trip;
const struct tegra_tsensor_group *sg = zone->sg; const struct tegra_tsensor_group *sg = zone->sg;
struct device *dev = zone->dev; struct device *dev = zone->dev;
int ret;
if (!tz) if (!tz)
return -EINVAL; return -EINVAL;
ret = __thermal_zone_get_trip(tz, trip_id, &trip); if (trip->type == THERMAL_TRIP_CRITICAL) {
if (ret)
return ret;
if (trip.type == THERMAL_TRIP_CRITICAL) {
/* /*
* If thermtrips property is set in DT, * If thermtrips property is set in DT,
* doesn't need to program critical type trip to HW, * doesn't need to program critical type trip to HW,
...@@ -609,7 +604,7 @@ static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int trip ...@@ -609,7 +604,7 @@ static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int trip
else else
return 0; return 0;
} else if (trip.type == THERMAL_TRIP_HOT) { } else if (trip->type == THERMAL_TRIP_HOT) {
int i; int i;
for (i = 0; i < THROTTLE_SIZE; i++) { for (i = 0; i < THROTTLE_SIZE; i++) {
...@@ -620,7 +615,7 @@ static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int trip ...@@ -620,7 +615,7 @@ static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int trip
continue; continue;
cdev = ts->throt_cfgs[i].cdev; cdev = ts->throt_cfgs[i].cdev;
if (get_thermal_instance(tz, cdev, trip_id)) if (thermal_trip_is_bound_to_cdev(tz, trip, cdev))
stc = find_throttle_cfg_by_name(ts, cdev->type); stc = find_throttle_cfg_by_name(ts, cdev->type);
else else
continue; continue;
......
...@@ -1130,7 +1130,7 @@ static void thermal_cooling_device_release(struct device *dev, void *res) ...@@ -1130,7 +1130,7 @@ static void thermal_cooling_device_release(struct device *dev, void *res)
struct thermal_cooling_device * struct thermal_cooling_device *
devm_thermal_of_cooling_device_register(struct device *dev, devm_thermal_of_cooling_device_register(struct device *dev,
struct device_node *np, struct device_node *np,
char *type, void *devdata, const char *type, void *devdata,
const struct thermal_cooling_device_ops *ops) const struct thermal_cooling_device_ops *ops)
{ {
struct thermal_cooling_device **ptr, *tcd; struct thermal_cooling_device **ptr, *tcd;
...@@ -1357,7 +1357,8 @@ thermal_zone_device_register_with_trips(const char *type, ...@@ -1357,7 +1357,8 @@ thermal_zone_device_register_with_trips(const char *type,
int num_trips, void *devdata, int num_trips, void *devdata,
const struct thermal_zone_device_ops *ops, const struct thermal_zone_device_ops *ops,
const struct thermal_zone_params *tzp, const struct thermal_zone_params *tzp,
int passive_delay, int polling_delay) unsigned int passive_delay,
unsigned int polling_delay)
{ {
const struct thermal_trip *trip = trips; const struct thermal_trip *trip = trips;
struct thermal_zone_device *tz; struct thermal_zone_device *tz;
...@@ -1390,6 +1391,14 @@ thermal_zone_device_register_with_trips(const char *type, ...@@ -1390,6 +1391,14 @@ thermal_zone_device_register_with_trips(const char *type,
if (num_trips > 0 && !trips) if (num_trips > 0 && !trips)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
if (polling_delay) {
if (passive_delay > polling_delay)
return ERR_PTR(-EINVAL);
if (!passive_delay)
passive_delay = polling_delay;
}
if (!thermal_class) if (!thermal_class)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
......
...@@ -39,30 +39,53 @@ int get_tz_trend(struct thermal_zone_device *tz, const struct thermal_trip *trip ...@@ -39,30 +39,53 @@ int get_tz_trend(struct thermal_zone_device *tz, const struct thermal_trip *trip
return trend; return trend;
} }
static struct thermal_instance *get_instance(struct thermal_zone_device *tz,
struct thermal_cooling_device *cdev,
const struct thermal_trip *trip)
{
struct thermal_instance *ti;
list_for_each_entry(ti, &tz->thermal_instances, tz_node) {
if (ti->trip == trip && ti->cdev == cdev)
return ti;
}
return NULL;
}
bool thermal_trip_is_bound_to_cdev(struct thermal_zone_device *tz,
const struct thermal_trip *trip,
struct thermal_cooling_device *cdev)
{
bool ret;
mutex_lock(&tz->lock);
mutex_lock(&cdev->lock);
ret = !!get_instance(tz, cdev, trip);
mutex_unlock(&cdev->lock);
mutex_unlock(&tz->lock);
return ret;
}
EXPORT_SYMBOL_GPL(thermal_trip_is_bound_to_cdev);
struct thermal_instance * struct thermal_instance *
get_thermal_instance(struct thermal_zone_device *tz, get_thermal_instance(struct thermal_zone_device *tz,
struct thermal_cooling_device *cdev, int trip_index) struct thermal_cooling_device *cdev, int trip_index)
{ {
struct thermal_instance *pos = NULL; struct thermal_instance *ti;
struct thermal_instance *target_instance = NULL;
const struct thermal_trip *trip;
mutex_lock(&tz->lock); mutex_lock(&tz->lock);
mutex_lock(&cdev->lock); mutex_lock(&cdev->lock);
trip = &tz->trips[trip_index].trip; ti = get_instance(tz, cdev, &tz->trips[trip_index].trip);
list_for_each_entry(pos, &tz->thermal_instances, tz_node) {
if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
target_instance = pos;
break;
}
}
mutex_unlock(&cdev->lock); mutex_unlock(&cdev->lock);
mutex_unlock(&tz->lock); mutex_unlock(&tz->lock);
return target_instance; return ti;
} }
EXPORT_SYMBOL(get_thermal_instance); EXPORT_SYMBOL(get_thermal_instance);
......
...@@ -113,7 +113,7 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr, ...@@ -113,7 +113,7 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
if (temp != trip->temperature) { if (temp != trip->temperature) {
if (tz->ops.set_trip_temp) { if (tz->ops.set_trip_temp) {
ret = tz->ops.set_trip_temp(tz, trip_id, temp); ret = tz->ops.set_trip_temp(tz, trip, temp);
if (ret) if (ret)
goto unlock; goto unlock;
} }
......
...@@ -114,27 +114,17 @@ void thermal_zone_set_trips(struct thermal_zone_device *tz) ...@@ -114,27 +114,17 @@ void thermal_zone_set_trips(struct thermal_zone_device *tz)
dev_err(&tz->device, "Failed to set trips: %d\n", ret); dev_err(&tz->device, "Failed to set trips: %d\n", ret);
} }
int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id,
struct thermal_trip *trip)
{
if (!tz || trip_id < 0 || trip_id >= tz->num_trips || !trip)
return -EINVAL;
*trip = tz->trips[trip_id].trip;
return 0;
}
EXPORT_SYMBOL_GPL(__thermal_zone_get_trip);
int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id,
struct thermal_trip *trip) struct thermal_trip *trip)
{ {
int ret; if (!tz || !trip || trip_id < 0 || trip_id >= tz->num_trips)
return -EINVAL;
mutex_lock(&tz->lock); mutex_lock(&tz->lock);
ret = __thermal_zone_get_trip(tz, trip_id, trip); *trip = tz->trips[trip_id].trip;
mutex_unlock(&tz->lock); mutex_unlock(&tz->lock);
return ret; return 0;
} }
EXPORT_SYMBOL_GPL(thermal_zone_get_trip); EXPORT_SYMBOL_GPL(thermal_zone_get_trip);
......
...@@ -239,13 +239,34 @@ static irqreturn_t uniphier_tm_alarm_irq_thread(int irq, void *_tdev) ...@@ -239,13 +239,34 @@ static irqreturn_t uniphier_tm_alarm_irq_thread(int irq, void *_tdev)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
struct trip_walk_data {
struct uniphier_tm_dev *tdev;
int crit_temp;
int index;
};
static int uniphier_tm_trip_walk_cb(struct thermal_trip *trip, void *arg)
{
struct trip_walk_data *twd = arg;
if (trip->type == THERMAL_TRIP_CRITICAL &&
trip->temperature < twd->crit_temp)
twd->crit_temp = trip->temperature;
uniphier_tm_set_alert(twd->tdev, twd->index, trip->temperature);
twd->tdev->alert_en[twd->index++] = true;
return 0;
}
static int uniphier_tm_probe(struct platform_device *pdev) static int uniphier_tm_probe(struct platform_device *pdev)
{ {
struct trip_walk_data twd = { .crit_temp = INT_MAX, .index = 0 };
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct regmap *regmap; struct regmap *regmap;
struct device_node *parent; struct device_node *parent;
struct uniphier_tm_dev *tdev; struct uniphier_tm_dev *tdev;
int i, ret, irq, crit_temp = INT_MAX; int ret, irq;
tdev = devm_kzalloc(dev, sizeof(*tdev), GFP_KERNEL); tdev = devm_kzalloc(dev, sizeof(*tdev), GFP_KERNEL);
if (!tdev) if (!tdev)
...@@ -293,20 +314,10 @@ static int uniphier_tm_probe(struct platform_device *pdev) ...@@ -293,20 +314,10 @@ static int uniphier_tm_probe(struct platform_device *pdev)
} }
/* set alert temperatures */ /* set alert temperatures */
for (i = 0; i < thermal_zone_get_num_trips(tdev->tz_dev); i++) { twd.tdev = tdev;
struct thermal_trip trip; thermal_zone_for_each_trip(tdev->tz_dev, uniphier_tm_trip_walk_cb, &twd);
ret = thermal_zone_get_trip(tdev->tz_dev, i, &trip); if (twd.crit_temp > CRITICAL_TEMP_LIMIT) {
if (ret)
return ret;
if (trip.type == THERMAL_TRIP_CRITICAL &&
trip.temperature < crit_temp)
crit_temp = trip.temperature;
uniphier_tm_set_alert(tdev, i, trip.temperature);
tdev->alert_en[i] = true;
}
if (crit_temp > CRITICAL_TEMP_LIMIT) {
dev_err(dev, "critical trip is over limit(>%d), or not set\n", dev_err(dev, "critical trip is over limit(>%d), or not set\n",
CRITICAL_TEMP_LIMIT); CRITICAL_TEMP_LIMIT);
return -EINVAL; return -EINVAL;
......
...@@ -79,6 +79,9 @@ struct thermal_trip { ...@@ -79,6 +79,9 @@ struct thermal_trip {
#define THERMAL_TRIP_FLAG_RW (THERMAL_TRIP_FLAG_RW_TEMP | \ #define THERMAL_TRIP_FLAG_RW (THERMAL_TRIP_FLAG_RW_TEMP | \
THERMAL_TRIP_FLAG_RW_HYST) THERMAL_TRIP_FLAG_RW_HYST)
#define THERMAL_TRIP_PRIV_TO_INT(_val_) (uintptr_t)(_val_)
#define THERMAL_INT_TO_TRIP_PRIV(_val_) (void *)(uintptr_t)(_val_)
struct thermal_zone_device; struct thermal_zone_device;
struct thermal_zone_device_ops { struct thermal_zone_device_ops {
...@@ -90,7 +93,8 @@ struct thermal_zone_device_ops { ...@@ -90,7 +93,8 @@ struct thermal_zone_device_ops {
int (*set_trips) (struct thermal_zone_device *, int, int); int (*set_trips) (struct thermal_zone_device *, int, int);
int (*change_mode) (struct thermal_zone_device *, int (*change_mode) (struct thermal_zone_device *,
enum thermal_device_mode); enum thermal_device_mode);
int (*set_trip_temp) (struct thermal_zone_device *, int, int); int (*set_trip_temp) (struct thermal_zone_device *,
const struct thermal_trip *, int);
int (*get_crit_temp) (struct thermal_zone_device *, int *); int (*get_crit_temp) (struct thermal_zone_device *, int *);
int (*set_emul_temp) (struct thermal_zone_device *, int); int (*set_emul_temp) (struct thermal_zone_device *, int);
int (*get_trend) (struct thermal_zone_device *, int (*get_trend) (struct thermal_zone_device *,
...@@ -198,8 +202,6 @@ static inline void devm_thermal_of_zone_unregister(struct device *dev, ...@@ -198,8 +202,6 @@ static inline void devm_thermal_of_zone_unregister(struct device *dev,
} }
#endif #endif
int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id,
struct thermal_trip *trip);
int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id,
struct thermal_trip *trip); struct thermal_trip *trip);
int for_each_thermal_trip(struct thermal_zone_device *tz, int for_each_thermal_trip(struct thermal_zone_device *tz,
...@@ -221,7 +223,8 @@ struct thermal_zone_device *thermal_zone_device_register_with_trips( ...@@ -221,7 +223,8 @@ struct thermal_zone_device *thermal_zone_device_register_with_trips(
int num_trips, void *devdata, int num_trips, void *devdata,
const struct thermal_zone_device_ops *ops, const struct thermal_zone_device_ops *ops,
const struct thermal_zone_params *tzp, const struct thermal_zone_params *tzp,
int passive_delay, int polling_delay); unsigned int passive_delay,
unsigned int polling_delay);
struct thermal_zone_device *thermal_tripless_zone_device_register( struct thermal_zone_device *thermal_tripless_zone_device_register(
const char *type, const char *type,
...@@ -261,7 +264,7 @@ thermal_of_cooling_device_register(struct device_node *np, const char *, void *, ...@@ -261,7 +264,7 @@ thermal_of_cooling_device_register(struct device_node *np, const char *, void *,
struct thermal_cooling_device * struct thermal_cooling_device *
devm_thermal_of_cooling_device_register(struct device *dev, devm_thermal_of_cooling_device_register(struct device *dev,
struct device_node *np, struct device_node *np,
char *type, void *devdata, const char *type, void *devdata,
const struct thermal_cooling_device_ops *ops); const struct thermal_cooling_device_ops *ops);
void thermal_cooling_device_update(struct thermal_cooling_device *); void thermal_cooling_device_update(struct thermal_cooling_device *);
void thermal_cooling_device_unregister(struct thermal_cooling_device *); void thermal_cooling_device_unregister(struct thermal_cooling_device *);
...@@ -269,6 +272,9 @@ struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name); ...@@ -269,6 +272,9 @@ struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp); int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
int thermal_zone_get_slope(struct thermal_zone_device *tz); int thermal_zone_get_slope(struct thermal_zone_device *tz);
int thermal_zone_get_offset(struct thermal_zone_device *tz); int thermal_zone_get_offset(struct thermal_zone_device *tz);
bool thermal_trip_is_bound_to_cdev(struct thermal_zone_device *tz,
const struct thermal_trip *trip,
struct thermal_cooling_device *cdev);
int thermal_zone_device_enable(struct thermal_zone_device *tz); int thermal_zone_device_enable(struct thermal_zone_device *tz);
int thermal_zone_device_disable(struct thermal_zone_device *tz); int thermal_zone_device_disable(struct thermal_zone_device *tz);
...@@ -305,7 +311,7 @@ thermal_of_cooling_device_register(struct device_node *np, ...@@ -305,7 +311,7 @@ thermal_of_cooling_device_register(struct device_node *np,
static inline struct thermal_cooling_device * static inline struct thermal_cooling_device *
devm_thermal_of_cooling_device_register(struct device *dev, devm_thermal_of_cooling_device_register(struct device *dev,
struct device_node *np, struct device_node *np,
char *type, void *devdata, const char *type, void *devdata,
const struct thermal_cooling_device_ops *ops) const struct thermal_cooling_device_ops *ops)
{ {
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment