Skip to content

Commit da36f7f

Browse files
committed
thermal: intel: int340x: Allow temperature override
JIRA: https://issues.redhat.com/browse/RHEL-85463 commit ea78eed Author: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Date: Fri Jun 13 14:49:23 2025 -0700 thermal: intel: int340x: Allow temperature override Add debugfs interface to override hardware provide temperature. This interface can be used primarily for debug. Alternatively this can be also used to use hardware control loops to manage temperature for virtual sensors. Virtual sensors are soft sensors created by kernel/ user space aggregating other sensors. There are three attributes to override the maximum three instances of platform temperature control. /sys/kernel/debug/platform_temperature_control/ ├── temperature_0 ├── temperature_1 └── temperature_2 These are write only attributes requires admin privilege. Any value greater than 0, will override the temperature. A value of 0 will stop overriding the temperature. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Reviewed-by: Zhang Rui <rui.zhang@intel.com> Link: https://patch.msgid.link/20250613214923.2910397-2-srinivas.pandruvada@linux.intel.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: David Arcari <darcari@redhat.com>
1 parent 7d26cb8 commit da36f7f

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

drivers/thermal/intel/int340x_thermal/platform_temperature_control.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include <linux/kernel.h>
4040
#include <linux/module.h>
41+
#include <linux/debugfs.h>
4142
#include <linux/pci.h>
4243
#include "processor_thermal_device.h"
4344

@@ -53,6 +54,7 @@ struct mmio_reg {
5354

5455
struct ptc_data {
5556
u32 offset;
57+
struct pci_dev *pdev;
5658
struct attribute_group ptc_attr_group;
5759
struct attribute *ptc_attrs[PTC_MAX_ATTRS];
5860
struct device_attribute temperature_target_attr;
@@ -215,6 +217,63 @@ static int ptc_create_groups(struct pci_dev *pdev, int instance, struct ptc_data
215217
}
216218

217219
static struct ptc_data ptc_instance[PTC_MAX_INSTANCES];
220+
static struct dentry *ptc_debugfs;
221+
222+
#define PTC_TEMP_OVERRIDE_ENABLE_INDEX 4
223+
#define PTC_TEMP_OVERRIDE_INDEX 5
224+
225+
static ssize_t ptc_temperature_write(struct file *file, const char __user *data,
226+
size_t count, loff_t *ppos)
227+
{
228+
struct ptc_data *ptc_instance = file->private_data;
229+
struct pci_dev *pdev = ptc_instance->pdev;
230+
char buf[32];
231+
ssize_t len;
232+
u32 value;
233+
234+
len = min(count, sizeof(buf) - 1);
235+
if (copy_from_user(buf, data, len))
236+
return -EFAULT;
237+
238+
buf[len] = '\0';
239+
if (kstrtouint(buf, 0, &value))
240+
return -EINVAL;
241+
242+
if (ptc_mmio_regs[PTC_TEMP_OVERRIDE_INDEX].units)
243+
value /= ptc_mmio_regs[PTC_TEMP_OVERRIDE_INDEX].units;
244+
245+
if (value > ptc_mmio_regs[PTC_TEMP_OVERRIDE_INDEX].mask)
246+
return -EINVAL;
247+
248+
if (!value) {
249+
ptc_mmio_write(pdev, ptc_instance->offset, PTC_TEMP_OVERRIDE_ENABLE_INDEX, 0);
250+
} else {
251+
ptc_mmio_write(pdev, ptc_instance->offset, PTC_TEMP_OVERRIDE_INDEX, value);
252+
ptc_mmio_write(pdev, ptc_instance->offset, PTC_TEMP_OVERRIDE_ENABLE_INDEX, 1);
253+
}
254+
255+
return count;
256+
}
257+
258+
static const struct file_operations ptc_fops = {
259+
.open = simple_open,
260+
.write = ptc_temperature_write,
261+
.llseek = generic_file_llseek,
262+
};
263+
264+
static void ptc_create_debugfs(void)
265+
{
266+
ptc_debugfs = debugfs_create_dir("platform_temperature_control", NULL);
267+
268+
debugfs_create_file("temperature_0", 0200, ptc_debugfs, &ptc_instance[0], &ptc_fops);
269+
debugfs_create_file("temperature_1", 0200, ptc_debugfs, &ptc_instance[1], &ptc_fops);
270+
debugfs_create_file("temperature_2", 0200, ptc_debugfs, &ptc_instance[2], &ptc_fops);
271+
}
272+
273+
static void ptc_delete_debugfs(void)
274+
{
275+
debugfs_remove_recursive(ptc_debugfs);
276+
}
218277

219278
int proc_thermal_ptc_add(struct pci_dev *pdev, struct proc_thermal_device *proc_priv)
220279
{
@@ -223,8 +282,11 @@ int proc_thermal_ptc_add(struct pci_dev *pdev, struct proc_thermal_device *proc_
223282

224283
for (i = 0; i < PTC_MAX_INSTANCES; i++) {
225284
ptc_instance[i].offset = ptc_offsets[i];
285+
ptc_instance[i].pdev = pdev;
226286
ptc_create_groups(pdev, i, &ptc_instance[i]);
227287
}
288+
289+
ptc_create_debugfs();
228290
}
229291

230292
return 0;
@@ -240,6 +302,8 @@ void proc_thermal_ptc_remove(struct pci_dev *pdev)
240302

241303
for (i = 0; i < PTC_MAX_INSTANCES; i++)
242304
sysfs_remove_group(&pdev->dev.kobj, &ptc_instance[i].ptc_attr_group);
305+
306+
ptc_delete_debugfs();
243307
}
244308
}
245309
EXPORT_SYMBOL_GPL(proc_thermal_ptc_remove);

0 commit comments

Comments
 (0)