Skip to content

Commit

Permalink
Merge branch 'thermal-core'
Browse files Browse the repository at this point in the history
Merge core thermal control changes for 6.1-rc1:

 - Increase maximum number of trip points in the thermal core (Sumeet
   Pawnikar).

 - Replace strlcpy() with unused retval with strscpy() in the core
   thermal control code (Wolfram Sang).

 - Do not lock thermal zone mutex in the user space governor (Rafael
   Wysocki)

 - Rework the device tree initialization, convert the drivers to the
   new API and remove the old OF code (Daniel Lezcano)

 - Fix return value to -ENODEV when searching for a specific thermal
   zone which does not exist (Daniel Lezcano)

 - Fix the return value inspection in of_thermal_zone_find() (Dan
   Carpenter)

 - Fix kernel panic when KASAN is enabled as it detects use after
   free when unregistering a thermal zone (Daniel Lezcano)

 - Move the set_trip ops inside the therma sysfs code (Daniel Lezcano)

 - Remove unnecessary error message as it is already showed in the
   underlying function (Jiapeng Chong)

 - Rework the monitoring path and move the locks upper in the call
   stack to fix some potentials race windows (Daniel Lezcano)

 - Fix lockdep_assert() warning introduced by the lock rework (Daniel
   Lezcano)

 - Revert the Mellanox 'hotter thermal zone' feature because it is
   already handled in the thermal framework core code (Daniel Lezcano)

* thermal-core: (47 commits)
  thermal: core: Increase maximum number of trip points
  thermal: move from strlcpy() with unused retval to strscpy()
  thermal: gov_user_space: Do not lock thermal zone mutex
  Revert "mlxsw: core: Add the hottest thermal zone detection"
  thermal/core: Fix lockdep_assert() warning
  thermal/core: Move the mutex inside the thermal_zone_device_update() function
  thermal/core: Move the thermal zone lock out of the governors
  thermal/governors: Group the thermal zone lock inside the throttle function
  thermal/core: Rework the monitoring a bit
  thermal/core: Rearm the monitoring only one time
  thermal/drivers/qcom/spmi-adc-tm5: Remove unnecessary print function dev_err()
  thermal/of: Remove old OF code
  thermal/core: Move set_trip_temp ops to the sysfs code
  thermal/drivers/samsung: Switch to new of thermal API
  regulator/drivers/max8976: Switch to new of thermal API
  Input: sun4i-ts - switch to new of thermal API
  iio/drivers/sun4i_gpadc: Switch to new of thermal API
  hwmon/drivers/core: Switch to new of thermal API
  hwmon: pm_bus: core: Switch to new of thermal API
  ata/drivers/ahci_imx: Switch to new of thermal API
  ...
  • Loading branch information
Rafael J. Wysocki committed Oct 3, 2022
2 parents 96f1c52 + 82b1ec7 commit a7ae50f
Show file tree
Hide file tree
Showing 54 changed files with 815 additions and 1,331 deletions.
15 changes: 10 additions & 5 deletions drivers/ata/ahci_imx.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ static int read_adc_sum(void *dev, u16 rtune_ctl_reg, void __iomem * mmio)
}

/* SATA AHCI temperature monitor */
static int sata_ahci_read_temperature(void *dev, int *temp)
static int __sata_ahci_read_temperature(void *dev, int *temp)
{
u16 mpll_test_reg, rtune_ctl_reg, dac_ctl_reg, read_sum;
u32 str1, str2, str3, str4;
Expand Down Expand Up @@ -416,21 +416,26 @@ static int sata_ahci_read_temperature(void *dev, int *temp)
return 0;
}

static int sata_ahci_read_temperature(struct thermal_zone_device *tz, int *temp)
{
return __sata_ahci_read_temperature(tz->devdata, temp);
}

static ssize_t sata_ahci_show_temp(struct device *dev,
struct device_attribute *da,
char *buf)
{
unsigned int temp = 0;
int err;

err = sata_ahci_read_temperature(dev, &temp);
err = __sata_ahci_read_temperature(dev, &temp);
if (err < 0)
return err;

return sprintf(buf, "%u\n", temp);
}

static const struct thermal_zone_of_device_ops fsl_sata_ahci_of_thermal_ops = {
static const struct thermal_zone_device_ops fsl_sata_ahci_of_thermal_ops = {
.get_temp = sata_ahci_read_temperature,
};

Expand Down Expand Up @@ -1131,8 +1136,8 @@ static int imx_ahci_probe(struct platform_device *pdev)
ret = PTR_ERR(hwmon_dev);
goto disable_clk;
}
devm_thermal_zone_of_sensor_register(hwmon_dev, 0, hwmon_dev,
&fsl_sata_ahci_of_thermal_ops);
devm_thermal_of_zone_register(hwmon_dev, 0, hwmon_dev,
&fsl_sata_ahci_of_thermal_ops);
dev_info(dev, "%s: sensor 'sata_ahci'\n", dev_name(hwmon_dev));
}

Expand Down
14 changes: 7 additions & 7 deletions drivers/hwmon/hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ static DEFINE_IDA(hwmon_ida);
* between hwmon and thermal_sys modules.
*/
#ifdef CONFIG_THERMAL_OF
static int hwmon_thermal_get_temp(void *data, int *temp)
static int hwmon_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
struct hwmon_thermal_data *tdata = data;
struct hwmon_thermal_data *tdata = tz->devdata;
struct hwmon_device *hwdev = to_hwmon_device(tdata->dev);
int ret;
long t;
Expand All @@ -168,9 +168,9 @@ static int hwmon_thermal_get_temp(void *data, int *temp)
return 0;
}

static int hwmon_thermal_set_trips(void *data, int low, int high)
static int hwmon_thermal_set_trips(struct thermal_zone_device *tz, int low, int high)
{
struct hwmon_thermal_data *tdata = data;
struct hwmon_thermal_data *tdata = tz->devdata;
struct hwmon_device *hwdev = to_hwmon_device(tdata->dev);
const struct hwmon_chip_info *chip = hwdev->chip;
const struct hwmon_channel_info **info = chip->info;
Expand Down Expand Up @@ -203,7 +203,7 @@ static int hwmon_thermal_set_trips(void *data, int low, int high)
return 0;
}

static const struct thermal_zone_of_device_ops hwmon_thermal_ops = {
static const struct thermal_zone_device_ops hwmon_thermal_ops = {
.get_temp = hwmon_thermal_get_temp,
.set_trips = hwmon_thermal_set_trips,
};
Expand All @@ -227,8 +227,8 @@ static int hwmon_thermal_add_sensor(struct device *dev, int index)
tdata->dev = dev;
tdata->index = index;

tzd = devm_thermal_zone_of_sensor_register(dev, index, tdata,
&hwmon_thermal_ops);
tzd = devm_thermal_of_zone_register(dev, index, tdata,
&hwmon_thermal_ops);
if (IS_ERR(tzd)) {
if (PTR_ERR(tzd) != -ENODEV)
return PTR_ERR(tzd);
Expand Down
10 changes: 5 additions & 5 deletions drivers/hwmon/pmbus/pmbus_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,9 +1270,9 @@ struct pmbus_thermal_data {
struct pmbus_sensor *sensor;
};

static int pmbus_thermal_get_temp(void *data, int *temp)
static int pmbus_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
struct pmbus_thermal_data *tdata = data;
struct pmbus_thermal_data *tdata = tz->devdata;
struct pmbus_sensor *sensor = tdata->sensor;
struct pmbus_data *pmbus_data = tdata->pmbus_data;
struct i2c_client *client = to_i2c_client(pmbus_data->dev);
Expand All @@ -1296,7 +1296,7 @@ static int pmbus_thermal_get_temp(void *data, int *temp)
return ret;
}

static const struct thermal_zone_of_device_ops pmbus_thermal_ops = {
static const struct thermal_zone_device_ops pmbus_thermal_ops = {
.get_temp = pmbus_thermal_get_temp,
};

Expand All @@ -1314,8 +1314,8 @@ static int pmbus_thermal_add_sensor(struct pmbus_data *pmbus_data,
tdata->sensor = sensor;
tdata->pmbus_data = pmbus_data;

tzd = devm_thermal_zone_of_sensor_register(dev, index, tdata,
&pmbus_thermal_ops);
tzd = devm_thermal_of_zone_register(dev, index, tdata,
&pmbus_thermal_ops);
/*
* If CONFIG_THERMAL_OF is disabled, this returns -ENODEV,
* so ignore that error but forward any other error.
Expand Down
14 changes: 7 additions & 7 deletions drivers/hwmon/scpi-hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ static void scpi_scale_reading(u64 *value, struct sensor_data *sensor)
}
}

static int scpi_read_temp(void *dev, int *temp)
static int scpi_read_temp(struct thermal_zone_device *tz, int *temp)
{
struct scpi_thermal_zone *zone = dev;
struct scpi_thermal_zone *zone = tz->devdata;
struct scpi_sensors *scpi_sensors = zone->scpi_sensors;
struct scpi_ops *scpi_ops = scpi_sensors->scpi_ops;
struct sensor_data *sensor = &scpi_sensors->data[zone->sensor_id];
Expand Down Expand Up @@ -121,7 +121,7 @@ scpi_show_label(struct device *dev, struct device_attribute *attr, char *buf)
return sprintf(buf, "%s\n", sensor->info.name);
}

static const struct thermal_zone_of_device_ops scpi_sensor_ops = {
static const struct thermal_zone_device_ops scpi_sensor_ops = {
.get_temp = scpi_read_temp,
};

Expand Down Expand Up @@ -275,10 +275,10 @@ static int scpi_hwmon_probe(struct platform_device *pdev)

zone->sensor_id = i;
zone->scpi_sensors = scpi_sensors;
z = devm_thermal_zone_of_sensor_register(dev,
sensor->info.sensor_id,
zone,
&scpi_sensor_ops);
z = devm_thermal_of_zone_register(dev,
sensor->info.sensor_id,
zone,
&scpi_sensor_ops);
/*
* The call to thermal_zone_of_sensor_register returns
* an error for sensors that are not associated with
Expand Down
14 changes: 6 additions & 8 deletions drivers/iio/adc/sun4i-gpadc-iio.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ static int sun4i_gpadc_runtime_resume(struct device *dev)
return 0;
}

static int sun4i_gpadc_get_temp(void *data, int *temp)
static int sun4i_gpadc_get_temp(struct thermal_zone_device *tz, int *temp)
{
struct sun4i_gpadc_iio *info = data;
struct sun4i_gpadc_iio *info = tz->devdata;
int val, scale, offset;

if (sun4i_gpadc_temp_read(info->indio_dev, &val))
Expand All @@ -428,7 +428,7 @@ static int sun4i_gpadc_get_temp(void *data, int *temp)
return 0;
}

static const struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
static const struct thermal_zone_device_ops sun4i_ts_tz_ops = {
.get_temp = &sun4i_gpadc_get_temp,
};

Expand Down Expand Up @@ -637,9 +637,9 @@ static int sun4i_gpadc_probe(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev);

if (IS_ENABLED(CONFIG_THERMAL_OF)) {
info->tzd = thermal_zone_of_sensor_register(info->sensor_device,
0, info,
&sun4i_ts_tz_ops);
info->tzd = devm_thermal_of_zone_register(info->sensor_device,
0, info,
&sun4i_ts_tz_ops);
/*
* Do not fail driver probing when failing to register in
* thermal because no thermal DT node is found.
Expand Down Expand Up @@ -681,8 +681,6 @@ static int sun4i_gpadc_remove(struct platform_device *pdev)
if (!IS_ENABLED(CONFIG_THERMAL_OF))
return 0;

thermal_zone_of_sensor_unregister(info->sensor_device, info->tzd);

if (!info->no_irq)
iio_map_array_unregister(indio_dev);

Expand Down
10 changes: 5 additions & 5 deletions drivers/input/touchscreen/sun4i-ts.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ static int sun4i_get_temp(const struct sun4i_ts_data *ts, int *temp)
return 0;
}

static int sun4i_get_tz_temp(void *data, int *temp)
static int sun4i_get_tz_temp(struct thermal_zone_device *tz, int *temp)
{
return sun4i_get_temp(data, temp);
return sun4i_get_temp(tz->devdata, temp);
}

static const struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
static const struct thermal_zone_device_ops sun4i_ts_tz_ops = {
.get_temp = sun4i_get_tz_temp,
};

Expand Down Expand Up @@ -356,8 +356,8 @@ static int sun4i_ts_probe(struct platform_device *pdev)
if (IS_ERR(hwmon))
return PTR_ERR(hwmon);

thermal = devm_thermal_zone_of_sensor_register(ts->dev, 0, ts,
&sun4i_ts_tz_ops);
thermal = devm_thermal_of_zone_register(ts->dev, 0, ts,
&sun4i_ts_tz_ops);
if (IS_ERR(thermal))
return PTR_ERR(thermal);

Expand Down
77 changes: 2 additions & 75 deletions drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#define MLXSW_THERMAL_ASIC_TEMP_HOT 105000 /* 105C */
#define MLXSW_THERMAL_HYSTERESIS_TEMP 5000 /* 5C */
#define MLXSW_THERMAL_MODULE_TEMP_SHIFT (MLXSW_THERMAL_HYSTERESIS_TEMP * 2)
#define MLXSW_THERMAL_TEMP_SCORE_MAX GENMASK(31, 0)
#define MLXSW_THERMAL_MAX_STATE 10
#define MLXSW_THERMAL_MIN_STATE 2
#define MLXSW_THERMAL_MAX_DUTY 255
Expand Down Expand Up @@ -101,8 +100,6 @@ struct mlxsw_thermal {
struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX];
u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1];
struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS];
unsigned int tz_highest_score;
struct thermal_zone_device *tz_highest_dev;
struct mlxsw_thermal_area line_cards[];
};

Expand Down Expand Up @@ -193,34 +190,6 @@ mlxsw_thermal_module_trips_update(struct device *dev, struct mlxsw_core *core,
return 0;
}

static void mlxsw_thermal_tz_score_update(struct mlxsw_thermal *thermal,
struct thermal_zone_device *tzdev,
struct mlxsw_thermal_trip *trips,
int temp)
{
struct mlxsw_thermal_trip *trip = trips;
unsigned int score, delta, i, shift = 1;

/* Calculate thermal zone score, if temperature is above the hot
* threshold score is set to MLXSW_THERMAL_TEMP_SCORE_MAX.
*/
score = MLXSW_THERMAL_TEMP_SCORE_MAX;
for (i = MLXSW_THERMAL_TEMP_TRIP_NORM; i < MLXSW_THERMAL_NUM_TRIPS;
i++, trip++) {
if (temp < trip->temp) {
delta = DIV_ROUND_CLOSEST(temp, trip->temp - temp);
score = delta * shift;
break;
}
shift *= 256;
}

if (score > thermal->tz_highest_score) {
thermal->tz_highest_score = score;
thermal->tz_highest_dev = tzdev;
}
}

static int mlxsw_thermal_bind(struct thermal_zone_device *tzdev,
struct thermal_cooling_device *cdev)
{
Expand Down Expand Up @@ -286,9 +255,6 @@ static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev,
return err;
}
mlxsw_reg_mtmp_unpack(mtmp_pl, &temp, NULL, NULL, NULL, NULL);
if (temp > 0)
mlxsw_thermal_tz_score_update(thermal, tzdev, thermal->trips,
temp);

*p_temp = temp;
return 0;
Expand Down Expand Up @@ -349,21 +315,6 @@ static int mlxsw_thermal_set_trip_hyst(struct thermal_zone_device *tzdev,
return 0;
}

static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev,
int trip, enum thermal_trend *trend)
{
struct mlxsw_thermal *thermal = tzdev->devdata;

if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS)
return -EINVAL;

if (tzdev == thermal->tz_highest_dev)
return 1;

*trend = THERMAL_TREND_STABLE;
return 0;
}

static struct thermal_zone_params mlxsw_thermal_params = {
.no_hwmon = true,
};
Expand All @@ -377,7 +328,6 @@ static struct thermal_zone_device_ops mlxsw_thermal_ops = {
.set_trip_temp = mlxsw_thermal_set_trip_temp,
.get_trip_hyst = mlxsw_thermal_get_trip_hyst,
.set_trip_hyst = mlxsw_thermal_set_trip_hyst,
.get_trend = mlxsw_thermal_trend_get,
};

static int mlxsw_thermal_module_bind(struct thermal_zone_device *tzdev,
Expand Down Expand Up @@ -463,7 +413,6 @@ static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev,
int temp, crit_temp, emerg_temp;
struct device *dev;
u16 sensor_index;
int err;

dev = thermal->bus_info->dev;
sensor_index = MLXSW_REG_MTMP_MODULE_INDEX_MIN + tz->module;
Expand All @@ -479,10 +428,8 @@ static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev,
return 0;

/* Update trip points. */
err = mlxsw_thermal_module_trips_update(dev, thermal->core, tz,
crit_temp, emerg_temp);
if (!err && temp > 0)
mlxsw_thermal_tz_score_update(thermal, tzdev, tz->trips, temp);
mlxsw_thermal_module_trips_update(dev, thermal->core, tz,
crit_temp, emerg_temp);

return 0;
}
Expand Down Expand Up @@ -546,22 +493,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip,
return 0;
}

static int mlxsw_thermal_module_trend_get(struct thermal_zone_device *tzdev,
int trip, enum thermal_trend *trend)
{
struct mlxsw_thermal_module *tz = tzdev->devdata;
struct mlxsw_thermal *thermal = tz->parent;

if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS)
return -EINVAL;

if (tzdev == thermal->tz_highest_dev)
return 1;

*trend = THERMAL_TREND_STABLE;
return 0;
}

static struct thermal_zone_device_ops mlxsw_thermal_module_ops = {
.bind = mlxsw_thermal_module_bind,
.unbind = mlxsw_thermal_module_unbind,
Expand All @@ -571,7 +502,6 @@ static struct thermal_zone_device_ops mlxsw_thermal_module_ops = {
.set_trip_temp = mlxsw_thermal_module_trip_temp_set,
.get_trip_hyst = mlxsw_thermal_module_trip_hyst_get,
.set_trip_hyst = mlxsw_thermal_module_trip_hyst_set,
.get_trend = mlxsw_thermal_module_trend_get,
};

static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev,
Expand All @@ -592,8 +522,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev,
return err;

mlxsw_reg_mtmp_unpack(mtmp_pl, &temp, NULL, NULL, NULL, NULL);
if (temp > 0)
mlxsw_thermal_tz_score_update(thermal, tzdev, tz->trips, temp);

*p_temp = temp;
return 0;
Expand All @@ -608,7 +536,6 @@ static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = {
.set_trip_temp = mlxsw_thermal_module_trip_temp_set,
.get_trip_hyst = mlxsw_thermal_module_trip_hyst_get,
.set_trip_hyst = mlxsw_thermal_module_trip_hyst_set,
.get_trend = mlxsw_thermal_module_trend_get,
};

static int mlxsw_thermal_get_max_state(struct thermal_cooling_device *cdev,
Expand Down
Loading

0 comments on commit a7ae50f

Please sign in to comment.