Skip to content

Commit 5a35066

Browse files
andrzejtpdlezcano
authored andcommitted
thermal: Store device mode in struct thermal_zone_device
Prepare for eliminating get_mode(). Signed-off-by: Andrzej Pietrasiewicz <[email protected]> [for acerhdf] Acked-by: Peter Kaestle <[email protected]> Reviewed-by: Bartlomiej Zolnierkiewicz <[email protected]> Reviewed-by: Amit Kucheria <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent cbba1d7 commit 5a35066

File tree

8 files changed

+44
-71
lines changed

8 files changed

+44
-71
lines changed

drivers/acpi/thermal.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ struct acpi_thermal {
172172
struct acpi_thermal_trips trips;
173173
struct acpi_handle_list devices;
174174
struct thermal_zone_device *thermal_zone;
175-
enum thermal_device_mode mode;
176175
int kelvin_offset; /* in millidegrees */
177176
struct work_struct thermal_check_work;
178177
};
@@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data)
500499
{
501500
struct acpi_thermal *tz = data;
502501

503-
if (tz->mode != THERMAL_DEVICE_ENABLED)
502+
if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED)
504503
return;
505504

506505
thermal_zone_device_update(tz->thermal_zone,
@@ -529,12 +528,7 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp)
529528
static int thermal_get_mode(struct thermal_zone_device *thermal,
530529
enum thermal_device_mode *mode)
531530
{
532-
struct acpi_thermal *tz = thermal->devdata;
533-
534-
if (!tz)
535-
return -EINVAL;
536-
537-
*mode = tz->mode;
531+
*mode = thermal->mode;
538532

539533
return 0;
540534
}
@@ -556,11 +550,11 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,
556550
if (mode == THERMAL_DEVICE_DISABLED)
557551
pr_warn("thermal zone will be disabled\n");
558552

559-
if (mode != tz->mode) {
560-
tz->mode = mode;
553+
if (mode != tz->thermal_zone->mode) {
554+
tz->thermal_zone->mode = mode;
561555
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
562556
"%s kernel ACPI thermal control\n",
563-
tz->mode == THERMAL_DEVICE_ENABLED ?
557+
tz->thermal_zone->mode == THERMAL_DEVICE_ENABLED ?
564558
"Enable" : "Disable"));
565559
acpi_thermal_check(tz);
566560
}
@@ -912,7 +906,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
912906
goto remove_dev_link;
913907
}
914908

915-
tz->mode = THERMAL_DEVICE_ENABLED;
909+
tz->thermal_zone->mode = THERMAL_DEVICE_ENABLED;
916910

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

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ struct mlxsw_thermal_module {
9898
struct mlxsw_thermal *parent;
9999
struct thermal_zone_device *tzdev;
100100
struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS];
101-
enum thermal_device_mode mode;
102101
int module; /* Module or gearbox number */
103102
};
104103

@@ -110,7 +109,6 @@ struct mlxsw_thermal {
110109
struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX];
111110
u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1];
112111
struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS];
113-
enum thermal_device_mode mode;
114112
struct mlxsw_thermal_module *tz_module_arr;
115113
u8 tz_module_num;
116114
struct mlxsw_thermal_module *tz_gearbox_arr;
@@ -280,9 +278,7 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev,
280278
static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev,
281279
enum thermal_device_mode *mode)
282280
{
283-
struct mlxsw_thermal *thermal = tzdev->devdata;
284-
285-
*mode = thermal->mode;
281+
*mode = tzdev->mode;
286282

287283
return 0;
288284
}
@@ -299,9 +295,9 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev,
299295
else
300296
tzdev->polling_delay = 0;
301297

298+
tzdev->mode = mode;
302299
mutex_unlock(&tzdev->lock);
303300

304-
thermal->mode = mode;
305301
thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED);
306302

307303
return 0;
@@ -468,9 +464,7 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev,
468464
static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev,
469465
enum thermal_device_mode *mode)
470466
{
471-
struct mlxsw_thermal_module *tz = tzdev->devdata;
472-
473-
*mode = tz->mode;
467+
*mode = tzdev->mode;
474468

475469
return 0;
476470
}
@@ -488,9 +482,10 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev,
488482
else
489483
tzdev->polling_delay = 0;
490484

485+
tzdev->mode = mode;
486+
491487
mutex_unlock(&tzdev->lock);
492488

493-
tz->mode = mode;
494489
thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED);
495490

496491
return 0;
@@ -780,7 +775,7 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz)
780775
return err;
781776
}
782777

783-
module_tz->mode = THERMAL_DEVICE_ENABLED;
778+
module_tz->tzdev->mode = THERMAL_DEVICE_ENABLED;
784779
return 0;
785780
}
786781

@@ -896,7 +891,7 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz)
896891
if (IS_ERR(gearbox_tz->tzdev))
897892
return PTR_ERR(gearbox_tz->tzdev);
898893

899-
gearbox_tz->mode = THERMAL_DEVICE_ENABLED;
894+
gearbox_tz->tzdev->mode = THERMAL_DEVICE_ENABLED;
900895
return 0;
901896
}
902897

@@ -1065,7 +1060,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
10651060
if (err)
10661061
goto err_unreg_modules_tzdev;
10671062

1068-
thermal->mode = THERMAL_DEVICE_ENABLED;
1063+
thermal->tzdev->mode = THERMAL_DEVICE_ENABLED;
10691064
*p_thermal = thermal;
10701065
return 0;
10711066

drivers/platform/x86/acerhdf.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ static int kernelmode = 1;
6868
#else
6969
static int kernelmode;
7070
#endif
71-
static enum thermal_device_mode thermal_mode;
7271

7372
static unsigned int interval = 10;
7473
static unsigned int fanon = 60000;
@@ -398,15 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void)
398397
{
399398
acerhdf_change_fanstate(ACERHDF_FAN_AUTO);
400399
kernelmode = 0;
401-
thermal_mode = THERMAL_DEVICE_DISABLED;
402-
if (thz_dev)
400+
if (thz_dev) {
401+
thz_dev->mode = THERMAL_DEVICE_DISABLED;
403402
thz_dev->polling_delay = 0;
403+
}
404404
pr_notice("kernel mode fan control OFF\n");
405405
}
406406
static inline void acerhdf_enable_kernelmode(void)
407407
{
408408
kernelmode = 1;
409-
thermal_mode = THERMAL_DEVICE_ENABLED;
409+
thz_dev->mode = THERMAL_DEVICE_ENABLED;
410410

411411
thz_dev->polling_delay = interval*1000;
412412
thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED);
@@ -419,7 +419,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal,
419419
if (verbose)
420420
pr_notice("kernel mode fan control %d\n", kernelmode);
421421

422-
*mode = thermal_mode;
422+
*mode = thermal->mode;
423423

424424
return 0;
425425
}
@@ -741,15 +741,16 @@ static int __init acerhdf_register_thermal(void)
741741
if (IS_ERR(cl_dev))
742742
return -EINVAL;
743743

744-
thermal_mode = kernelmode ?
745-
THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED;
746744
thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL,
747745
&acerhdf_dev_ops,
748746
&acerhdf_zone_params, 0,
749747
(kernelmode) ? interval*1000 : 0);
750748
if (IS_ERR(thz_dev))
751749
return -EINVAL;
752750

751+
thz_dev->mode = kernelmode ?
752+
THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED;
753+
753754
if (strcmp(thz_dev->governor->name,
754755
acerhdf_zone_params.governor_name)) {
755756
pr_err("Didn't get thermal governor %s, perhaps not compiled into thermal subsystem.\n",

drivers/thermal/da9062-thermal.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ struct da9062_thermal {
4949
struct da9062 *hw;
5050
struct delayed_work work;
5151
struct thermal_zone_device *zone;
52-
enum thermal_device_mode mode;
5352
struct mutex lock; /* protection for da9062_thermal temperature */
5453
int temperature;
5554
int irq;
@@ -124,8 +123,7 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data)
124123
static int da9062_thermal_get_mode(struct thermal_zone_device *z,
125124
enum thermal_device_mode *mode)
126125
{
127-
struct da9062_thermal *thermal = z->devdata;
128-
*mode = thermal->mode;
126+
*mode = z->mode;
129127
return 0;
130128
}
131129

@@ -233,7 +231,6 @@ static int da9062_thermal_probe(struct platform_device *pdev)
233231

234232
thermal->config = match->data;
235233
thermal->hw = chip;
236-
thermal->mode = THERMAL_DEVICE_ENABLED;
237234
thermal->dev = &pdev->dev;
238235

239236
INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on);
@@ -248,6 +245,7 @@ static int da9062_thermal_probe(struct platform_device *pdev)
248245
ret = PTR_ERR(thermal->zone);
249246
goto err;
250247
}
248+
thermal->zone->mode = THERMAL_DEVICE_ENABLED;
251249

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

drivers/thermal/imx_thermal.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ struct imx_thermal_data {
197197
struct cpufreq_policy *policy;
198198
struct thermal_zone_device *tz;
199199
struct thermal_cooling_device *cdev;
200-
enum thermal_device_mode mode;
201200
struct regmap *tempmon;
202201
u32 c1, c2; /* See formula in imx_init_calib() */
203202
int temp_passive;
@@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
256255
bool wait;
257256
u32 val;
258257

259-
if (data->mode == THERMAL_DEVICE_ENABLED) {
258+
if (tz->mode == THERMAL_DEVICE_ENABLED) {
260259
/* Check if a measurement is currently in progress */
261260
regmap_read(map, soc_data->temp_data, &val);
262261
wait = !(val & soc_data->temp_valid_mask);
@@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
283282

284283
regmap_read(map, soc_data->temp_data, &val);
285284

286-
if (data->mode != THERMAL_DEVICE_ENABLED) {
285+
if (tz->mode != THERMAL_DEVICE_ENABLED) {
287286
regmap_write(map, soc_data->sensor_ctrl + REG_CLR,
288287
soc_data->measure_temp_mask);
289288
regmap_write(map, soc_data->sensor_ctrl + REG_SET,
@@ -334,9 +333,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
334333
static int imx_get_mode(struct thermal_zone_device *tz,
335334
enum thermal_device_mode *mode)
336335
{
337-
struct imx_thermal_data *data = tz->devdata;
338-
339-
*mode = data->mode;
336+
*mode = tz->mode;
340337

341338
return 0;
342339
}
@@ -376,7 +373,7 @@ static int imx_set_mode(struct thermal_zone_device *tz,
376373
}
377374
}
378375

379-
data->mode = mode;
376+
tz->mode = mode;
380377
thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
381378

382379
return 0;
@@ -831,7 +828,7 @@ static int imx_thermal_probe(struct platform_device *pdev)
831828
data->socdata->measure_temp_mask);
832829

833830
data->irq_enabled = true;
834-
data->mode = THERMAL_DEVICE_ENABLED;
831+
data->tz->mode = THERMAL_DEVICE_ENABLED;
835832

836833
ret = devm_request_threaded_irq(&pdev->dev, data->irq,
837834
imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread,
@@ -885,7 +882,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev)
885882
data->socdata->measure_temp_mask);
886883
regmap_write(map, data->socdata->sensor_ctrl + REG_SET,
887884
data->socdata->power_down_mask);
888-
data->mode = THERMAL_DEVICE_DISABLED;
885+
data->tz->mode = THERMAL_DEVICE_DISABLED;
889886
clk_disable_unprepare(data->thermal_clk);
890887

891888
return 0;
@@ -905,7 +902,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev)
905902
data->socdata->power_down_mask);
906903
regmap_write(map, data->socdata->sensor_ctrl + REG_SET,
907904
data->socdata->measure_temp_mask);
908-
data->mode = THERMAL_DEVICE_ENABLED;
905+
data->tz->mode = THERMAL_DEVICE_ENABLED;
909906

910907
return 0;
911908
}

drivers/thermal/intel/int340x_thermal/int3400_thermal.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ struct int3400_thermal_priv {
4848
struct acpi_device *adev;
4949
struct platform_device *pdev;
5050
struct thermal_zone_device *thermal;
51-
enum thermal_device_mode mode;
5251
int art_count;
5352
struct art *arts;
5453
int trt_count;
@@ -381,12 +380,7 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal,
381380
static int int3400_thermal_get_mode(struct thermal_zone_device *thermal,
382381
enum thermal_device_mode *mode)
383382
{
384-
struct int3400_thermal_priv *priv = thermal->devdata;
385-
386-
if (!priv)
387-
return -EINVAL;
388-
389-
*mode = priv->mode;
383+
*mode = thermal->mode;
390384

391385
return 0;
392386
}
@@ -404,8 +398,8 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal,
404398
mode != THERMAL_DEVICE_DISABLED)
405399
return -EINVAL;
406400

407-
if (mode != priv->mode) {
408-
priv->mode = mode;
401+
if (mode != thermal->mode) {
402+
thermal->mode = mode;
409403
result = int3400_thermal_run_osc(priv->adev->handle,
410404
priv->current_uuid_index,
411405
mode == THERMAL_DEVICE_ENABLED);

drivers/thermal/intel/intel_quark_dts_thermal.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ struct soc_sensor_entry {
103103
bool locked;
104104
u32 store_ptps;
105105
u32 store_dts_enable;
106-
enum thermal_device_mode mode;
107106
struct thermal_zone_device *tzone;
108107
};
109108

@@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd)
128127
return ret;
129128

130129
if (out & QRK_DTS_ENABLE_BIT) {
131-
aux_entry->mode = THERMAL_DEVICE_ENABLED;
130+
tzd->mode = THERMAL_DEVICE_ENABLED;
132131
return 0;
133132
}
134133

@@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd)
139138
if (ret)
140139
return ret;
141140

142-
aux_entry->mode = THERMAL_DEVICE_ENABLED;
141+
tzd->mode = THERMAL_DEVICE_ENABLED;
143142
} else {
144-
aux_entry->mode = THERMAL_DEVICE_DISABLED;
143+
tzd->mode = THERMAL_DEVICE_DISABLED;
145144
pr_info("DTS is locked. Cannot enable DTS\n");
146145
ret = -EPERM;
147146
}
@@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd)
161160
return ret;
162161

163162
if (!(out & QRK_DTS_ENABLE_BIT)) {
164-
aux_entry->mode = THERMAL_DEVICE_DISABLED;
163+
tzd->mode = THERMAL_DEVICE_DISABLED;
165164
return 0;
166165
}
167166

@@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd)
173172
if (ret)
174173
return ret;
175174

176-
aux_entry->mode = THERMAL_DEVICE_DISABLED;
175+
tzd->mode = THERMAL_DEVICE_DISABLED;
177176
} else {
178-
aux_entry->mode = THERMAL_DEVICE_ENABLED;
177+
tzd->mode = THERMAL_DEVICE_ENABLED;
179178
pr_info("DTS is locked. Cannot disable DTS\n");
180179
ret = -EPERM;
181180
}
@@ -312,8 +311,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd,
312311
static int sys_get_mode(struct thermal_zone_device *tzd,
313312
enum thermal_device_mode *mode)
314313
{
315-
struct soc_sensor_entry *aux_entry = tzd->devdata;
316-
*mode = aux_entry->mode;
314+
*mode = tzd->mode;
317315
return 0;
318316
}
319317

0 commit comments

Comments
 (0)