Skip to content

Commit 1595d88

Browse files
andrzejtpdlezcano
authored andcommitted
thermal: Store thermal mode in a dedicated enum
Prepare for storing mode in struct thermal_zone_device. Signed-off-by: Andrzej Pietrasiewicz <[email protected]> Reviewed-by: Guenter Roeck <[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 172066c commit 1595d88

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

drivers/acpi/thermal.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ struct acpi_thermal {
172172
struct acpi_thermal_trips trips;
173173
struct acpi_handle_list devices;
174174
struct thermal_zone_device *thermal_zone;
175-
int tz_enabled;
175+
enum thermal_device_mode mode;
176176
int kelvin_offset; /* in millidegrees */
177177
struct work_struct thermal_check_work;
178178
};
@@ -500,7 +500,7 @@ static void acpi_thermal_check(void *data)
500500
{
501501
struct acpi_thermal *tz = data;
502502

503-
if (!tz->tz_enabled)
503+
if (tz->mode != THERMAL_DEVICE_ENABLED)
504504
return;
505505

506506
thermal_zone_device_update(tz->thermal_zone,
@@ -534,8 +534,7 @@ static int thermal_get_mode(struct thermal_zone_device *thermal,
534534
if (!tz)
535535
return -EINVAL;
536536

537-
*mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
538-
THERMAL_DEVICE_DISABLED;
537+
*mode = tz->mode;
539538

540539
return 0;
541540
}
@@ -544,27 +543,25 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,
544543
enum thermal_device_mode mode)
545544
{
546545
struct acpi_thermal *tz = thermal->devdata;
547-
int enable;
548546

549547
if (!tz)
550548
return -EINVAL;
551549

550+
if (mode != THERMAL_DEVICE_DISABLED &&
551+
mode != THERMAL_DEVICE_ENABLED)
552+
return -EINVAL;
552553
/*
553554
* enable/disable thermal management from ACPI thermal driver
554555
*/
555-
if (mode == THERMAL_DEVICE_ENABLED)
556-
enable = 1;
557-
else if (mode == THERMAL_DEVICE_DISABLED) {
558-
enable = 0;
556+
if (mode == THERMAL_DEVICE_DISABLED)
559557
pr_warn("thermal zone will be disabled\n");
560-
} else
561-
return -EINVAL;
562558

563-
if (enable != tz->tz_enabled) {
564-
tz->tz_enabled = enable;
559+
if (mode != tz->mode) {
560+
tz->mode = mode;
565561
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
566562
"%s kernel ACPI thermal control\n",
567-
tz->tz_enabled ? "Enable" : "Disable"));
563+
tz->mode == THERMAL_DEVICE_ENABLED ?
564+
"Enable" : "Disable"));
568565
acpi_thermal_check(tz);
569566
}
570567
return 0;
@@ -915,7 +912,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
915912
goto remove_dev_link;
916913
}
917914

918-
tz->tz_enabled = 1;
915+
tz->mode = THERMAL_DEVICE_ENABLED;
919916

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

drivers/platform/x86/acerhdf.c

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

7273
static unsigned int interval = 10;
7374
static unsigned int fanon = 60000;
@@ -397,13 +398,15 @@ static inline void acerhdf_revert_to_bios_mode(void)
397398
{
398399
acerhdf_change_fanstate(ACERHDF_FAN_AUTO);
399400
kernelmode = 0;
401+
thermal_mode = THERMAL_DEVICE_DISABLED;
400402
if (thz_dev)
401403
thz_dev->polling_delay = 0;
402404
pr_notice("kernel mode fan control OFF\n");
403405
}
404406
static inline void acerhdf_enable_kernelmode(void)
405407
{
406408
kernelmode = 1;
409+
thermal_mode = THERMAL_DEVICE_ENABLED;
407410

408411
thz_dev->polling_delay = interval*1000;
409412
thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED);
@@ -416,8 +419,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal,
416419
if (verbose)
417420
pr_notice("kernel mode fan control %d\n", kernelmode);
418421

419-
*mode = (kernelmode) ? THERMAL_DEVICE_ENABLED
420-
: THERMAL_DEVICE_DISABLED;
422+
*mode = thermal_mode;
421423

422424
return 0;
423425
}
@@ -739,6 +741,8 @@ static int __init acerhdf_register_thermal(void)
739741
if (IS_ERR(cl_dev))
740742
return -EINVAL;
741743

744+
thermal_mode = kernelmode ?
745+
THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED;
742746
thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL,
743747
&acerhdf_dev_ops,
744748
&acerhdf_zone_params, 0,

drivers/thermal/intel/int340x_thermal/int3400_thermal.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct int3400_thermal_priv {
4848
struct acpi_device *adev;
4949
struct platform_device *pdev;
5050
struct thermal_zone_device *thermal;
51-
int mode;
51+
enum thermal_device_mode mode;
5252
int art_count;
5353
struct art *arts;
5454
int trt_count;
@@ -395,24 +395,20 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal,
395395
enum thermal_device_mode mode)
396396
{
397397
struct int3400_thermal_priv *priv = thermal->devdata;
398-
bool enable;
399398
int result = 0;
400399

401400
if (!priv)
402401
return -EINVAL;
403402

404-
if (mode == THERMAL_DEVICE_ENABLED)
405-
enable = true;
406-
else if (mode == THERMAL_DEVICE_DISABLED)
407-
enable = false;
408-
else
403+
if (mode != THERMAL_DEVICE_ENABLED &&
404+
mode != THERMAL_DEVICE_DISABLED)
409405
return -EINVAL;
410406

411-
if (enable != priv->mode) {
412-
priv->mode = enable;
407+
if (mode != priv->mode) {
408+
priv->mode = mode;
413409
result = int3400_thermal_run_osc(priv->adev->handle,
414-
priv->current_uuid_index,
415-
enable);
410+
priv->current_uuid_index,
411+
mode == THERMAL_DEVICE_ENABLED);
416412
}
417413

418414
evaluate_odvp(priv);

0 commit comments

Comments
 (0)