Skip to content

Commit d223005

Browse files
committed
Merge tag 'thermal-6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull thermal control updates from Rafael Wysocki: "These mostly continue to rework the thermal core and the thermal zone driver interface to make the code more straightforward and reduce bloat The most significant piece of this work is a change of the code related to binding cooling devices to thermal zones which, among other things, replaces two previously existing thermal zone operations with one allowing driver implementations to be much simpler There is also a new thermal core testing module allowing mock thermal zones to be created and controlled via debugfs in order to exercise the thermal core functionality. It is expected to be used for implementing thermal core self tests in the future Apart from the above, there are assorted thermal driver updates Specifics: - Update some thermal drivers to eliminate thermal_zone_get_trip() calls from them and get rid of that function (Rafael Wysocki) - Update the thermal sysfs code to store trip point attributes in trip descriptors and get to trip points via attribute pointers (Rafael Wysocki) - Move the computation of the low and high boundaries for thermal_zone_set_trips() to __thermal_zone_device_update() (Daniel Lezcano) - Introduce a debugfs-based facility for thermal core testing (Rafael Wysocki) - Replace the thermal zone .bind() and .unbind() callbacks for binding cooling devices to thermal zones with one .should_bind() callback used for deciding whether or not a given cooling devices should be bound to a given trip point in a given thermal zone (Rafael Wysocki) - Eliminate code that has no more users after the other changes, drop some redundant checks from the thermal core and clean it up (Rafael Wysocki) - Fix rounding of delay jiffies in the thermal core (Rafael Wysocki) - Refuse to accept trip point temperature or hysteresis that would lead to an invalid threshold value when setting them via sysfs (Rafael Wysocki) - Adjust states of all uninitialized instances in the .manage() callback of the Bang-bang thermal governor (Rafael Wysocki) - Drop a couple of redundant checks along with the code depending on them from the thermal core (Rafael Wysocki) - Rearrange the thermal core to avoid redundant checks and simplify control flow in a couple of code paths (Rafael Wysocki) - Add power domain DT bindings for new Amlogic SoCs (Georges Stark) - Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() in the ST driver and add a Kconfig dependency on THERMAL_OF subsystem for the STi driver (Raphael Gallais-Pou) - Simplify the error code path in the probe functions in the brcmstb driver with the helo of dev_err_probe() (Yan Zhen) - Make imx_sc_thermal use dev_err_probe() (Alexander Stein) - Remove trailing space after \n newline in the Renesas driver (Colin Ian King) - Add DT binding compatible string for the SA8255p to the tsens thermal driver (Nikunj Kela) - Use the devm_clk_get_enabled() helpers to simplify the init routine in the sprd thermal driver (Huan Yang) - Remove __maybe_unused notations for the functions by using the new RUNTIME_PM_OPS() and SYSTEM_SLEEP_PM_OPS() macros on the IMx and Qoriq drivers (Fabio Estevam) - Remove unused declarations from the ti-soc-thermal driver's header file as the functions in question were removed previously (Zhang Zekun)" * tag 'thermal-6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (48 commits) thermal: core: Drop thermal_zone_device_is_enabled() thermal: core: Check passive delay in monitor_thermal_zone() thermal: core: Drop dead code from monitor_thermal_zone() thermal: core: Drop redundant lockdep_assert_held() thermal: gov_bang_bang: Adjust states of all uninitialized instances thermal: sysfs: Add sanity checks for trip temperature and hysteresis thermal/drivers/imx_sc_thermal: Use dev_err_probe thermal/drivers/ti-soc-thermal: Remove unused declarations thermal/drivers/imx: Remove __maybe_unused notations thermal/drivers/qoriq: Remove __maybe_unused notations thermal/drivers/sprd: Use devm_clk_get_enabled() helpers dt-bindings: thermal: tsens: document support on SA8255p thermal/drivers/renesas: Remove trailing space after \n newline thermal/drivers/brcmstb_thermal: Simplify with dev_err_probe() thermal/drivers/sti: Depend on THERMAL_OF subsystem thermal/drivers/st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() dt-bindings: thermal: amlogic,thermal: add optional power-domains thermal: core: Drop tz field from struct thermal_instance thermal: core: Drop redundant checks from thermal_bind_cdev_to_trip() thermal: core: Rename cdev-to-thermal-zone bind/unbind functions ...
2 parents 02824a5 + 3bc5ed1 commit d223005

36 files changed

+1160
-928
lines changed

Documentation/devicetree/bindings/thermal/amlogic,thermal.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ properties:
3232
clocks:
3333
maxItems: 1
3434

35+
power-domains:
36+
maxItems: 1
37+
3538
amlogic,ao-secure:
3639
description: phandle to the ao-secure syscon
3740
$ref: /schemas/types.yaml#/definitions/phandle

Documentation/devicetree/bindings/thermal/qcom-tsens.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ properties:
5151
- qcom,msm8996-tsens
5252
- qcom,msm8998-tsens
5353
- qcom,qcm2290-tsens
54+
- qcom,sa8255p-tsens
5455
- qcom,sa8775p-tsens
5556
- qcom,sc7180-tsens
5657
- qcom,sc7280-tsens

Documentation/driver-api/thermal/sysfs-api.rst

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ temperature) and throttle appropriate devices.
5858
ops:
5959
thermal zone device call-backs.
6060

61-
.bind:
62-
bind the thermal zone device with a thermal cooling device.
63-
.unbind:
64-
unbind the thermal zone device with a thermal cooling device.
61+
.should_bind:
62+
check whether or not a given cooling device should be bound to
63+
a given trip point in this thermal zone.
6564
.get_temp:
6665
get the current temperature of the thermal zone.
6766
.set_trips:
@@ -246,56 +245,6 @@ temperature) and throttle appropriate devices.
246245
It deletes the corresponding entry from /sys/class/thermal folder and
247246
unbinds itself from all the thermal zone devices using it.
248247

249-
1.3 interface for binding a thermal zone device with a thermal cooling device
250-
-----------------------------------------------------------------------------
251-
252-
::
253-
254-
int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
255-
int trip, struct thermal_cooling_device *cdev,
256-
unsigned long upper, unsigned long lower, unsigned int weight);
257-
258-
This interface function binds a thermal cooling device to a particular trip
259-
point of a thermal zone device.
260-
261-
This function is usually called in the thermal zone device .bind callback.
262-
263-
tz:
264-
the thermal zone device
265-
cdev:
266-
thermal cooling device
267-
trip:
268-
indicates which trip point in this thermal zone the cooling device
269-
is associated with.
270-
upper:
271-
the Maximum cooling state for this trip point.
272-
THERMAL_NO_LIMIT means no upper limit,
273-
and the cooling device can be in max_state.
274-
lower:
275-
the Minimum cooling state can be used for this trip point.
276-
THERMAL_NO_LIMIT means no lower limit,
277-
and the cooling device can be in cooling state 0.
278-
weight:
279-
the influence of this cooling device in this thermal
280-
zone. See 1.4.1 below for more information.
281-
282-
::
283-
284-
int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
285-
int trip, struct thermal_cooling_device *cdev);
286-
287-
This interface function unbinds a thermal cooling device from a particular
288-
trip point of a thermal zone device. This function is usually called in
289-
the thermal zone device .unbind callback.
290-
291-
tz:
292-
the thermal zone device
293-
cdev:
294-
thermal cooling device
295-
trip:
296-
indicates which trip point in this thermal zone the cooling device
297-
is associated with.
298-
299248
1.4 Thermal Zone Parameters
300249
---------------------------
301250

@@ -366,8 +315,6 @@ Thermal cooling device sys I/F, created once it's registered::
366315

367316
Then next two dynamic attributes are created/removed in pairs. They represent
368317
the relationship between a thermal zone and its associated cooling device.
369-
They are created/removed for each successful execution of
370-
thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device.
371318

372319
::
373320

@@ -459,14 +406,7 @@ are supposed to implement the callback. If they don't, the thermal
459406
framework calculated the trend by comparing the previous and the current
460407
temperature values.
461408

462-
4.2. get_thermal_instance
463-
-------------------------
464-
465-
This function returns the thermal_instance corresponding to a given
466-
{thermal_zone, cooling_device, trip_point} combination. Returns NULL
467-
if such an instance does not exist.
468-
469-
4.3. thermal_cdev_update
409+
4.2. thermal_cdev_update
470410
------------------------
471411

472412
This function serves as an arbitrator to set the state of a cooling

drivers/acpi/thermal.c

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -558,77 +558,31 @@ static void acpi_thermal_zone_device_critical(struct thermal_zone_device *therma
558558
thermal_zone_device_critical(thermal);
559559
}
560560

561-
struct acpi_thermal_bind_data {
562-
struct thermal_zone_device *thermal;
563-
struct thermal_cooling_device *cdev;
564-
bool bind;
565-
};
566-
567-
static int bind_unbind_cdev_cb(struct thermal_trip *trip, void *arg)
561+
static bool acpi_thermal_should_bind_cdev(struct thermal_zone_device *thermal,
562+
const struct thermal_trip *trip,
563+
struct thermal_cooling_device *cdev,
564+
struct cooling_spec *c)
568565
{
569566
struct acpi_thermal_trip *acpi_trip = trip->priv;
570-
struct acpi_thermal_bind_data *bd = arg;
571-
struct thermal_zone_device *thermal = bd->thermal;
572-
struct thermal_cooling_device *cdev = bd->cdev;
573567
struct acpi_device *cdev_adev = cdev->devdata;
574568
int i;
575569

576570
/* Skip critical and hot trips. */
577571
if (!acpi_trip)
578-
return 0;
572+
return false;
579573

580574
for (i = 0; i < acpi_trip->devices.count; i++) {
581575
acpi_handle handle = acpi_trip->devices.handles[i];
582-
struct acpi_device *adev = acpi_fetch_acpi_dev(handle);
583-
584-
if (adev != cdev_adev)
585-
continue;
586-
587-
if (bd->bind) {
588-
int ret;
589-
590-
ret = thermal_bind_cdev_to_trip(thermal, trip, cdev,
591-
THERMAL_NO_LIMIT,
592-
THERMAL_NO_LIMIT,
593-
THERMAL_WEIGHT_DEFAULT);
594-
if (ret)
595-
return ret;
596-
} else {
597-
thermal_unbind_cdev_from_trip(thermal, trip, cdev);
598-
}
599-
}
600-
601-
return 0;
602-
}
603576

604-
static int acpi_thermal_bind_unbind_cdev(struct thermal_zone_device *thermal,
605-
struct thermal_cooling_device *cdev,
606-
bool bind)
607-
{
608-
struct acpi_thermal_bind_data bd = {
609-
.thermal = thermal, .cdev = cdev, .bind = bind
610-
};
611-
612-
return for_each_thermal_trip(thermal, bind_unbind_cdev_cb, &bd);
613-
}
614-
615-
static int
616-
acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
617-
struct thermal_cooling_device *cdev)
618-
{
619-
return acpi_thermal_bind_unbind_cdev(thermal, cdev, true);
620-
}
577+
if (acpi_fetch_acpi_dev(handle) == cdev_adev)
578+
return true;
579+
}
621580

622-
static int
623-
acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
624-
struct thermal_cooling_device *cdev)
625-
{
626-
return acpi_thermal_bind_unbind_cdev(thermal, cdev, false);
581+
return false;
627582
}
628583

629584
static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
630-
.bind = acpi_thermal_bind_cooling_device,
631-
.unbind = acpi_thermal_unbind_cooling_device,
585+
.should_bind = acpi_thermal_should_bind_cdev,
632586
.get_temp = thermal_get_temp,
633587
.get_trend = thermal_get_trend,
634588
.hot = acpi_thermal_zone_device_hot,

drivers/net/ethernet/mellanox/mlxsw/core_thermal.c

Lines changed: 31 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -165,52 +165,22 @@ static int mlxsw_get_cooling_device_idx(struct mlxsw_thermal *thermal,
165165
return -ENODEV;
166166
}
167167

168-
static int mlxsw_thermal_bind(struct thermal_zone_device *tzdev,
169-
struct thermal_cooling_device *cdev)
168+
static bool mlxsw_thermal_should_bind(struct thermal_zone_device *tzdev,
169+
const struct thermal_trip *trip,
170+
struct thermal_cooling_device *cdev,
171+
struct cooling_spec *c)
170172
{
171173
struct mlxsw_thermal *thermal = thermal_zone_device_priv(tzdev);
172-
struct device *dev = thermal->bus_info->dev;
173-
int i, err;
174+
const struct mlxsw_cooling_states *state = trip->priv;
174175

175176
/* If the cooling device is one of ours bind it */
176177
if (mlxsw_get_cooling_device_idx(thermal, cdev) < 0)
177-
return 0;
178+
return false;
178179

179-
for (i = 0; i < MLXSW_THERMAL_NUM_TRIPS; i++) {
180-
const struct mlxsw_cooling_states *state = &thermal->cooling_states[i];
180+
c->upper = state->max_state;
181+
c->lower = state->min_state;
181182

182-
err = thermal_zone_bind_cooling_device(tzdev, i, cdev,
183-
state->max_state,
184-
state->min_state,
185-
THERMAL_WEIGHT_DEFAULT);
186-
if (err < 0) {
187-
dev_err(dev, "Failed to bind cooling device to trip %d\n", i);
188-
return err;
189-
}
190-
}
191-
return 0;
192-
}
193-
194-
static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev,
195-
struct thermal_cooling_device *cdev)
196-
{
197-
struct mlxsw_thermal *thermal = thermal_zone_device_priv(tzdev);
198-
struct device *dev = thermal->bus_info->dev;
199-
int i;
200-
int err;
201-
202-
/* If the cooling device is our one unbind it */
203-
if (mlxsw_get_cooling_device_idx(thermal, cdev) < 0)
204-
return 0;
205-
206-
for (i = 0; i < MLXSW_THERMAL_NUM_TRIPS; i++) {
207-
err = thermal_zone_unbind_cooling_device(tzdev, i, cdev);
208-
if (err < 0) {
209-
dev_err(dev, "Failed to unbind cooling device\n");
210-
return err;
211-
}
212-
}
213-
return 0;
183+
return true;
214184
}
215185

216186
static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev,
@@ -240,57 +210,27 @@ static struct thermal_zone_params mlxsw_thermal_params = {
240210
};
241211

242212
static struct thermal_zone_device_ops mlxsw_thermal_ops = {
243-
.bind = mlxsw_thermal_bind,
244-
.unbind = mlxsw_thermal_unbind,
213+
.should_bind = mlxsw_thermal_should_bind,
245214
.get_temp = mlxsw_thermal_get_temp,
246215
};
247216

248-
static int mlxsw_thermal_module_bind(struct thermal_zone_device *tzdev,
249-
struct thermal_cooling_device *cdev)
217+
static bool mlxsw_thermal_module_should_bind(struct thermal_zone_device *tzdev,
218+
const struct thermal_trip *trip,
219+
struct thermal_cooling_device *cdev,
220+
struct cooling_spec *c)
250221
{
251222
struct mlxsw_thermal_module *tz = thermal_zone_device_priv(tzdev);
223+
const struct mlxsw_cooling_states *state = trip->priv;
252224
struct mlxsw_thermal *thermal = tz->parent;
253-
int i, j, err;
254225

255226
/* If the cooling device is one of ours bind it */
256227
if (mlxsw_get_cooling_device_idx(thermal, cdev) < 0)
257-
return 0;
228+
return false;
258229

259-
for (i = 0; i < MLXSW_THERMAL_NUM_TRIPS; i++) {
260-
const struct mlxsw_cooling_states *state = &tz->cooling_states[i];
230+
c->upper = state->max_state;
231+
c->lower = state->min_state;
261232

262-
err = thermal_zone_bind_cooling_device(tzdev, i, cdev,
263-
state->max_state,
264-
state->min_state,
265-
THERMAL_WEIGHT_DEFAULT);
266-
if (err < 0)
267-
goto err_thermal_zone_bind_cooling_device;
268-
}
269-
return 0;
270-
271-
err_thermal_zone_bind_cooling_device:
272-
for (j = i - 1; j >= 0; j--)
273-
thermal_zone_unbind_cooling_device(tzdev, j, cdev);
274-
return err;
275-
}
276-
277-
static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev,
278-
struct thermal_cooling_device *cdev)
279-
{
280-
struct mlxsw_thermal_module *tz = thermal_zone_device_priv(tzdev);
281-
struct mlxsw_thermal *thermal = tz->parent;
282-
int i;
283-
int err;
284-
285-
/* If the cooling device is one of ours unbind it */
286-
if (mlxsw_get_cooling_device_idx(thermal, cdev) < 0)
287-
return 0;
288-
289-
for (i = 0; i < MLXSW_THERMAL_NUM_TRIPS; i++) {
290-
err = thermal_zone_unbind_cooling_device(tzdev, i, cdev);
291-
WARN_ON(err);
292-
}
293-
return err;
233+
return true;
294234
}
295235

296236
static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev,
@@ -313,8 +253,7 @@ static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev,
313253
}
314254

315255
static struct thermal_zone_device_ops mlxsw_thermal_module_ops = {
316-
.bind = mlxsw_thermal_module_bind,
317-
.unbind = mlxsw_thermal_module_unbind,
256+
.should_bind = mlxsw_thermal_module_should_bind,
318257
.get_temp = mlxsw_thermal_module_temp_get,
319258
};
320259

@@ -342,8 +281,7 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev,
342281
}
343282

344283
static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = {
345-
.bind = mlxsw_thermal_module_bind,
346-
.unbind = mlxsw_thermal_module_unbind,
284+
.should_bind = mlxsw_thermal_module_should_bind,
347285
.get_temp = mlxsw_thermal_gearbox_temp_get,
348286
};
349287

@@ -450,6 +388,7 @@ mlxsw_thermal_module_init(struct mlxsw_thermal *thermal,
450388
struct mlxsw_thermal_area *area, u8 module)
451389
{
452390
struct mlxsw_thermal_module *module_tz;
391+
int i;
453392

454393
module_tz = &area->tz_module_arr[module];
455394
module_tz->module = module;
@@ -461,6 +400,8 @@ mlxsw_thermal_module_init(struct mlxsw_thermal *thermal,
461400
sizeof(thermal->trips));
462401
memcpy(module_tz->cooling_states, default_cooling_states,
463402
sizeof(thermal->cooling_states));
403+
for (i = 0; i < MLXSW_THERMAL_NUM_TRIPS; i++)
404+
module_tz->trips[i].priv = &module_tz->cooling_states[i];
464405

465406
return mlxsw_thermal_module_tz_init(module_tz);
466407
}
@@ -566,7 +507,7 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core,
566507
struct mlxsw_thermal_module *gearbox_tz;
567508
char mgpir_pl[MLXSW_REG_MGPIR_LEN];
568509
u8 gbox_num;
569-
int i;
510+
int i, j;
570511
int err;
571512

572513
mlxsw_reg_mgpir_pack(mgpir_pl, area->slot_index);
@@ -593,6 +534,9 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core,
593534
sizeof(thermal->trips));
594535
memcpy(gearbox_tz->cooling_states, default_cooling_states,
595536
sizeof(thermal->cooling_states));
537+
for (j = 0; j < MLXSW_THERMAL_NUM_TRIPS; j++)
538+
gearbox_tz->trips[j].priv = &gearbox_tz->cooling_states[j];
539+
596540
gearbox_tz->module = i;
597541
gearbox_tz->parent = thermal;
598542
gearbox_tz->slot_index = area->slot_index;
@@ -709,6 +653,9 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
709653
thermal->bus_info = bus_info;
710654
memcpy(thermal->trips, default_thermal_trips, sizeof(thermal->trips));
711655
memcpy(thermal->cooling_states, default_cooling_states, sizeof(thermal->cooling_states));
656+
for (i = 0; i < MLXSW_THERMAL_NUM_TRIPS; i++)
657+
thermal->trips[i].priv = &thermal->cooling_states[i];
658+
712659
thermal->line_cards[0].slot_index = 0;
713660

714661
err = mlxsw_reg_query(thermal->core, MLXSW_REG(mfcr), mfcr_pl);

0 commit comments

Comments
 (0)