drivers/thermal/intel/int340x_thermal/processor_thermal_soc_slider.c

Source file repositories/reference/linux-study-clean/drivers/thermal/intel/int340x_thermal/processor_thermal_soc_slider.c

File Facts

System
Linux kernel
Corpus path
drivers/thermal/intel/int340x_thermal/processor_thermal_soc_slider.c
Extension
.c
Size
8148 bytes
Lines
291
Domain
Driver Families
Bucket
drivers/thermal
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Processor Thermal Device Interface for Reading and Writing
 * SoC Power Slider Values from User Space.
 *
 * Operation:
 * The SOC_EFFICIENCY_SLIDER_0_0_0_MCHBAR register is accessed
 * using the MMIO (Memory-Mapped I/O) interface with an MMIO offset of 0x5B38.
 * Although this register is 64 bits wide, only bits 7:0 are used,
 * and the other bits remain unchanged.
 *
 * Bit definitions
 *
 * Bits 2:0 (Slider value):
 * The SoC optimizer slider value indicates the system wide energy performance
 * hint. The slider has no specific units and ranges from 0 (highest
 * performance) to 6 (highest energy efficiency). Value of 7 is reserved.
 * Bits 3 : Reserved
 * Bits 6:4 (Offset)
 * Offset allows the SoC to automatically switch slider position in range
 * [slider value (bits 2:0) + offset] to improve power efficiency based on
 * internal SoC algorithms.
 * Bit 7 (Enable):
 * If this bit is set, the SoC Optimization sliders will be processed by the
 * SoC firmware.
 *
 * Copyright (c) 2025, Intel Corporation.
 */

#include <linux/bitfield.h>
#include <linux/pci.h>
#include <linux/platform_profile.h>
#include "processor_thermal_device.h"

#define SOC_POWER_SLIDER_OFFSET	0x5B38

enum power_slider_preference {
	SOC_POWER_SLIDER_PERFORMANCE,
	SOC_POWER_SLIDER_BALANCE,
	SOC_POWER_SLIDER_POWERSAVE,
};

#define SOC_SLIDER_VALUE_MINIMUM	0x00
#define SOC_SLIDER_VALUE_BALANCE	0x03
#define SOC_SLIDER_VALUE_MAXIMUM	0x06

#define SLIDER_MASK		GENMASK_ULL(2, 0)
#define SLIDER_ENABLE_BIT	7

static u8 slider_values[] = {
	[SOC_POWER_SLIDER_PERFORMANCE] = SOC_SLIDER_VALUE_MINIMUM,
	[SOC_POWER_SLIDER_BALANCE] = SOC_SLIDER_VALUE_BALANCE,
	[SOC_POWER_SLIDER_POWERSAVE] = SOC_SLIDER_VALUE_MAXIMUM,
};

/* Lock to protect module param updates */
static DEFINE_MUTEX(slider_param_lock);

static int slider_balanced_param = SOC_SLIDER_VALUE_BALANCE;

static int slider_def_balance_set(const char *arg, const struct kernel_param *kp)
{
	u8 slider_val;
	int ret;

	guard(mutex)(&slider_param_lock);

	ret = kstrtou8(arg, 16, &slider_val);
	if (!ret) {
		if (slider_val <= slider_values[SOC_POWER_SLIDER_PERFORMANCE] ||
		    slider_val >= slider_values[SOC_POWER_SLIDER_POWERSAVE])
			return -EINVAL;

		slider_balanced_param = slider_val;
	}

	return ret;
}

static int slider_def_balance_get(char *buf, const struct kernel_param *kp)
{
	guard(mutex)(&slider_param_lock);
	return sysfs_emit(buf, "%02x\n", slider_values[SOC_POWER_SLIDER_BALANCE]);
}

static const struct kernel_param_ops slider_def_balance_ops = {
	.set = slider_def_balance_set,
	.get = slider_def_balance_get,
};

Annotation

Implementation Notes