Skip to content

Commit 7f4957b

Browse files
andrzejtpdlezcano
authored andcommitted
thermal: Use mode helpers in drivers
Use thermal_zone_device_{en|dis}able() and thermal_zone_device_is_enabled(). Consequently, all set_mode() implementations in drivers: - can stop modifying tzd's "mode" member, - shall stop taking tzd's lock, as it is taken in the helpers - shall stop calling thermal_zone_device_update() as it is called in the helpers - can assume they are called when the mode truly changes, so checks to verify that can be dropped Not providing set_mode() by a driver no longer prevents the core from being able to set tzd's mode, so the relevant check in mode_store() is removed. Other comments: - acpi/thermal.c: tz->thermal_zone->mode will be updated only after we return from set_mode(), so use function parameter in thermal_set_mode() instead, no need to call acpi_thermal_check() in set_mode() - thermal/imx_thermal.c: regmap writes and mode assignment are done in thermal_zone_device_{en|dis}able() and set_mode() callback - thermal/intel/intel_quark_dts_thermal.c: soc_dts_{en|dis}able() are a part of set_mode() callback, so they don't need to modify tzd->mode, and don't need to fall back to the opposite mode if unsuccessful, as the return value will be propagated to thermal_zone_device_{en|dis}able() and ultimately tzd's member will not be changed in thermal_zone_device_set_mode(). - thermal/of-thermal.c: no need to set zone->mode to DISABLED in of_parse_thermal_zones() as a tzd is kzalloc'ed so mode is DISABLED anyway Signed-off-by: Andrzej Pietrasiewicz <[email protected]> [for acerhdf] Acked-by: Peter Kaestle <[email protected]> Reviewed-by: Amit Kucheria <[email protected]> Reviewed-by: Bartlomiej Zolnierkiewicz <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ac5d9ec commit 7f4957b

File tree

13 files changed

+80
-98
lines changed

13 files changed

+80
-98
lines changed

drivers/acpi/thermal.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ static void acpi_thermal_check(void *data)
499499
{
500500
struct acpi_thermal *tz = data;
501501

502-
if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED)
502+
if (!thermal_zone_device_is_enabled(tz->thermal_zone))
503503
return;
504504

505505
thermal_zone_device_update(tz->thermal_zone,
@@ -542,14 +542,11 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,
542542
if (mode == THERMAL_DEVICE_DISABLED)
543543
pr_warn("thermal zone will be disabled\n");
544544

545-
if (mode != tz->thermal_zone->mode) {
546-
tz->thermal_zone->mode = mode;
547-
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
548-
"%s kernel ACPI thermal control\n",
549-
tz->thermal_zone->mode == THERMAL_DEVICE_ENABLED ?
550-
"Enable" : "Disable"));
551-
acpi_thermal_check(tz);
552-
}
545+
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
546+
"%s kernel ACPI thermal control\n",
547+
mode == THERMAL_DEVICE_ENABLED ?
548+
"Enable" : "Disable"));
549+
553550
return 0;
554551
}
555552

@@ -897,13 +894,17 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
897894
goto remove_dev_link;
898895
}
899896

900-
tz->thermal_zone->mode = THERMAL_DEVICE_ENABLED;
897+
result = thermal_zone_device_enable(tz->thermal_zone);
898+
if (result)
899+
goto acpi_bus_detach;
901900

902901
dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
903902
tz->thermal_zone->id);
904903

905904
return 0;
906905

906+
acpi_bus_detach:
907+
acpi_bus_detach_private_data(tz->device->handle);
907908
remove_dev_link:
908909
sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
909910
remove_tz_link:

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

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,11 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev,
280280
{
281281
struct mlxsw_thermal *thermal = tzdev->devdata;
282282

283-
mutex_lock(&tzdev->lock);
284-
285283
if (mode == THERMAL_DEVICE_ENABLED)
286284
tzdev->polling_delay = thermal->polling_delay;
287285
else
288286
tzdev->polling_delay = 0;
289287

290-
tzdev->mode = mode;
291-
mutex_unlock(&tzdev->lock);
292-
293-
thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED);
294-
295288
return 0;
296289
}
297290

@@ -458,19 +451,11 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev,
458451
struct mlxsw_thermal_module *tz = tzdev->devdata;
459452
struct mlxsw_thermal *thermal = tz->parent;
460453

461-
mutex_lock(&tzdev->lock);
462-
463454
if (mode == THERMAL_DEVICE_ENABLED)
464455
tzdev->polling_delay = thermal->polling_delay;
465456
else
466457
tzdev->polling_delay = 0;
467458

468-
tzdev->mode = mode;
469-
470-
mutex_unlock(&tzdev->lock);
471-
472-
thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED);
473-
474459
return 0;
475460
}
476461

@@ -756,8 +741,11 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz)
756741
return err;
757742
}
758743

759-
module_tz->tzdev->mode = THERMAL_DEVICE_ENABLED;
760-
return 0;
744+
err = thermal_zone_device_enable(module_tz->tzdev);
745+
if (err)
746+
thermal_zone_device_unregister(module_tz->tzdev);
747+
748+
return err;
761749
}
762750

763751
static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev)
@@ -860,6 +848,7 @@ static int
860848
mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz)
861849
{
862850
char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME];
851+
int ret;
863852

864853
snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d",
865854
gearbox_tz->module + 1);
@@ -872,8 +861,11 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz)
872861
if (IS_ERR(gearbox_tz->tzdev))
873862
return PTR_ERR(gearbox_tz->tzdev);
874863

875-
gearbox_tz->tzdev->mode = THERMAL_DEVICE_ENABLED;
876-
return 0;
864+
ret = thermal_zone_device_enable(gearbox_tz->tzdev);
865+
if (ret)
866+
thermal_zone_device_unregister(gearbox_tz->tzdev);
867+
868+
return ret;
877869
}
878870

879871
static void
@@ -1041,10 +1033,15 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
10411033
if (err)
10421034
goto err_unreg_modules_tzdev;
10431035

1044-
thermal->tzdev->mode = THERMAL_DEVICE_ENABLED;
1036+
err = thermal_zone_device_enable(thermal->tzdev);
1037+
if (err)
1038+
goto err_unreg_gearboxes;
1039+
10451040
*p_thermal = thermal;
10461041
return 0;
10471042

1043+
err_unreg_gearboxes:
1044+
mlxsw_thermal_gearboxes_fini(thermal);
10481045
err_unreg_modules_tzdev:
10491046
mlxsw_thermal_modules_fini(thermal);
10501047
err_unreg_tzdev:

drivers/platform/x86/acerhdf.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,19 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void)
397397
{
398398
acerhdf_change_fanstate(ACERHDF_FAN_AUTO);
399399
kernelmode = 0;
400-
if (thz_dev) {
401-
thz_dev->mode = THERMAL_DEVICE_DISABLED;
400+
if (thz_dev)
402401
thz_dev->polling_delay = 0;
403-
}
402+
404403
pr_notice("kernel mode fan control OFF\n");
405404
}
406405
static inline void acerhdf_enable_kernelmode(void)
407406
{
408407
kernelmode = 1;
409-
thz_dev->mode = THERMAL_DEVICE_ENABLED;
410408

411409
thz_dev->polling_delay = interval*1000;
412-
thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED);
413410
pr_notice("kernel mode fan control ON\n");
414411
}
415412

@@ -723,6 +720,8 @@ static void acerhdf_unregister_platform(void)
723720

724721
static int __init acerhdf_register_thermal(void)
725722
{
723+
int ret;
724+
726725
cl_dev = thermal_cooling_device_register("acerhdf-fan", NULL,
727726
&acerhdf_cooling_ops);
728727

@@ -736,8 +735,12 @@ static int __init acerhdf_register_thermal(void)
736735
if (IS_ERR(thz_dev))
737736
return -EINVAL;
738737

739-
thz_dev->mode = kernelmode ?
740-
THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED;
738+
if (kernelmode)
739+
ret = thermal_zone_device_enable(thz_dev);
740+
else
741+
ret = thermal_zone_device_disable(thz_dev);
742+
if (ret)
743+
return ret;
741744

742745
if (strcmp(thz_dev->governor->name,
743746
acerhdf_zone_params.governor_name)) {

drivers/thermal/da9062-thermal.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ static int da9062_thermal_probe(struct platform_device *pdev)
237237
ret = PTR_ERR(thermal->zone);
238238
goto err;
239239
}
240-
thermal->zone->mode = THERMAL_DEVICE_ENABLED;
240+
ret = thermal_zone_device_enable(thermal->zone);
241+
if (ret) {
242+
dev_err(&pdev->dev, "Cannot enable thermal zone device\n");
243+
goto err_zone;
244+
}
241245

242246
dev_dbg(&pdev->dev,
243247
"TJUNC temperature polling period set at %d ms\n",

drivers/thermal/hisi_thermal.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,10 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor,
549549
{
550550
struct thermal_zone_device *tzd = sensor->tzd;
551551

552-
tzd->ops->set_mode(tzd,
553-
on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED);
552+
if (on)
553+
thermal_zone_device_enable(tzd);
554+
else
555+
thermal_zone_device_disable(tzd);
554556
}
555557

556558
static int hisi_thermal_probe(struct platform_device *pdev)

drivers/thermal/imx_thermal.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
255255
bool wait;
256256
u32 val;
257257

258-
if (tz->mode == THERMAL_DEVICE_ENABLED) {
258+
if (thermal_zone_device_is_enabled(tz)) {
259259
/* Check if a measurement is currently in progress */
260260
regmap_read(map, soc_data->temp_data, &val);
261261
wait = !(val & soc_data->temp_valid_mask);
@@ -282,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
282282

283283
regmap_read(map, soc_data->temp_data, &val);
284284

285-
if (tz->mode != THERMAL_DEVICE_ENABLED) {
285+
if (!thermal_zone_device_is_enabled(tz)) {
286286
regmap_write(map, soc_data->sensor_ctrl + REG_CLR,
287287
soc_data->measure_temp_mask);
288288
regmap_write(map, soc_data->sensor_ctrl + REG_SET,
@@ -365,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz,
365365
}
366366
}
367367

368-
tz->mode = mode;
369-
thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
370-
371368
return 0;
372369
}
373370

@@ -819,7 +816,9 @@ static int imx_thermal_probe(struct platform_device *pdev)
819816
data->socdata->measure_temp_mask);
820817

821818
data->irq_enabled = true;
822-
data->tz->mode = THERMAL_DEVICE_ENABLED;
819+
ret = thermal_zone_device_enable(data->tz);
820+
if (ret)
821+
goto thermal_zone_unregister;
823822

824823
ret = devm_request_threaded_irq(&pdev->dev, data->irq,
825824
imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread,
@@ -861,19 +860,18 @@ static int imx_thermal_remove(struct platform_device *pdev)
861860
static int __maybe_unused imx_thermal_suspend(struct device *dev)
862861
{
863862
struct imx_thermal_data *data = dev_get_drvdata(dev);
864-
struct regmap *map = data->tempmon;
863+
int ret;
865864

866865
/*
867866
* Need to disable thermal sensor, otherwise, when thermal core
868867
* try to get temperature before thermal sensor resume, a wrong
869868
* temperature will be read as the thermal sensor is powered
870-
* down.
869+
* down. This is done in set_mode() operation called from
870+
* thermal_zone_device_disable()
871871
*/
872-
regmap_write(map, data->socdata->sensor_ctrl + REG_CLR,
873-
data->socdata->measure_temp_mask);
874-
regmap_write(map, data->socdata->sensor_ctrl + REG_SET,
875-
data->socdata->power_down_mask);
876-
data->tz->mode = THERMAL_DEVICE_DISABLED;
872+
ret = thermal_zone_device_disable(data->tz);
873+
if (ret)
874+
return ret;
877875
clk_disable_unprepare(data->thermal_clk);
878876

879877
return 0;
@@ -882,18 +880,15 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev)
882880
static int __maybe_unused imx_thermal_resume(struct device *dev)
883881
{
884882
struct imx_thermal_data *data = dev_get_drvdata(dev);
885-
struct regmap *map = data->tempmon;
886883
int ret;
887884

888885
ret = clk_prepare_enable(data->thermal_clk);
889886
if (ret)
890887
return ret;
891888
/* Enabled thermal sensor after resume */
892-
regmap_write(map, data->socdata->sensor_ctrl + REG_CLR,
893-
data->socdata->power_down_mask);
894-
regmap_write(map, data->socdata->sensor_ctrl + REG_SET,
895-
data->socdata->measure_temp_mask);
896-
data->tz->mode = THERMAL_DEVICE_ENABLED;
889+
ret = thermal_zone_device_enable(data->tz);
890+
if (ret)
891+
return ret;
897892

898893
return 0;
899894
}

drivers/thermal/intel/int340x_thermal/int3400_thermal.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,11 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal,
390390
mode != THERMAL_DEVICE_DISABLED)
391391
return -EINVAL;
392392

393-
if (mode != thermal->mode) {
394-
thermal->mode = mode;
393+
if (mode != thermal->mode)
395394
result = int3400_thermal_run_osc(priv->adev->handle,
396395
priv->current_uuid_index,
397396
mode == THERMAL_DEVICE_ENABLED);
398-
}
397+
399398

400399
evaluate_odvp(priv);
401400

drivers/thermal/intel/intel_quark_dts_thermal.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,16 @@ static int soc_dts_enable(struct thermal_zone_device *tzd)
126126
if (ret)
127127
return ret;
128128

129-
if (out & QRK_DTS_ENABLE_BIT) {
130-
tzd->mode = THERMAL_DEVICE_ENABLED;
129+
if (out & QRK_DTS_ENABLE_BIT)
131130
return 0;
132-
}
133131

134132
if (!aux_entry->locked) {
135133
out |= QRK_DTS_ENABLE_BIT;
136134
ret = iosf_mbi_write(QRK_MBI_UNIT_RMU, MBI_REG_WRITE,
137135
QRK_DTS_REG_OFFSET_ENABLE, out);
138136
if (ret)
139137
return ret;
140-
141-
tzd->mode = THERMAL_DEVICE_ENABLED;
142138
} else {
143-
tzd->mode = THERMAL_DEVICE_DISABLED;
144139
pr_info("DTS is locked. Cannot enable DTS\n");
145140
ret = -EPERM;
146141
}
@@ -159,10 +154,8 @@ static int soc_dts_disable(struct thermal_zone_device *tzd)
159154
if (ret)
160155
return ret;
161156

162-
if (!(out & QRK_DTS_ENABLE_BIT)) {
163-
tzd->mode = THERMAL_DEVICE_DISABLED;
157+
if (!(out & QRK_DTS_ENABLE_BIT))
164158
return 0;
165-
}
166159

167160
if (!aux_entry->locked) {
168161
out &= ~QRK_DTS_ENABLE_BIT;
@@ -171,10 +164,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd)
171164

172165
if (ret)
173166
return ret;
174-
175-
tzd->mode = THERMAL_DEVICE_DISABLED;
176167
} else {
177-
tzd->mode = THERMAL_DEVICE_ENABLED;
178168
pr_info("DTS is locked. Cannot disable DTS\n");
179169
ret = -EPERM;
180170
}
@@ -404,9 +394,7 @@ static struct soc_sensor_entry *alloc_soc_dts(void)
404394
goto err_ret;
405395
}
406396

407-
mutex_lock(&dts_update_mutex);
408-
err = soc_dts_enable(aux_entry->tzone);
409-
mutex_unlock(&dts_update_mutex);
397+
err = thermal_zone_device_enable(aux_entry->tzone);
410398
if (err)
411399
goto err_aux_status;
412400

drivers/thermal/rockchip_thermal.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,8 +1068,10 @@ rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on)
10681068
{
10691069
struct thermal_zone_device *tzd = sensor->tzd;
10701070

1071-
tzd->ops->set_mode(tzd,
1072-
on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED);
1071+
if (on)
1072+
thermal_zone_device_enable(tzd);
1073+
else
1074+
thermal_zone_device_disable(tzd);
10731075
}
10741076

10751077
static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev)

drivers/thermal/sprd_thermal.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,10 @@ static void sprd_thm_toggle_sensor(struct sprd_thermal_sensor *sen, bool on)
322322
{
323323
struct thermal_zone_device *tzd = sen->tzd;
324324

325-
tzd->ops->set_mode(tzd,
326-
on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED);
325+
if (on)
326+
thermal_zone_device_enable(tzd);
327+
else
328+
thermal_zone_device_disable(tzd);
327329
}
328330

329331
static int sprd_thm_probe(struct platform_device *pdev)

0 commit comments

Comments
 (0)