Skip to content

Commit c4fcf1a

Browse files
atenartdlezcano
authored andcommitted
thermal/drivers/int340x: Improve the tcc offset saving for suspend/resume
When the driver resumes, the tcc offset is set back to its previous value. But this only works if the value was user defined as otherwise the offset isn't saved. This asymmetric logic is harder to maintain and introduced some issues. Improve the logic by saving the tcc offset in a suspend op, so the right value is always restored after a resume. Signed-off-by: Antoine Tenart <[email protected]> Reviewed-by: Srinivas Pandruvada <[email protected]> Tested-by: Srinivas Pandruvada <srinivas.pI [email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Lezcano <[email protected]>
1 parent fb6de59 commit c4fcf1a

File tree

5 files changed

+60
-11
lines changed

5 files changed

+60
-11
lines changed

drivers/thermal/intel/int340x_thermal/int3401_thermal.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,21 @@ static int int3401_remove(struct platform_device *pdev)
4444
}
4545

4646
#ifdef CONFIG_PM_SLEEP
47+
static int int3401_thermal_suspend(struct device *dev)
48+
{
49+
return proc_thermal_suspend(dev);
50+
}
4751
static int int3401_thermal_resume(struct device *dev)
4852
{
4953
return proc_thermal_resume(dev);
5054
}
5155
#else
56+
#define int3401_thermal_suspend NULL
5257
#define int3401_thermal_resume NULL
5358
#endif
5459

55-
static SIMPLE_DEV_PM_OPS(int3401_proc_thermal_pm, NULL, int3401_thermal_resume);
60+
static SIMPLE_DEV_PM_OPS(int3401_proc_thermal_pm, int3401_thermal_suspend,
61+
int3401_thermal_resume);
5662

5763
static struct platform_driver int3401_driver = {
5864
.probe = int3401_add,

drivers/thermal/intel/int340x_thermal/processor_thermal_device.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ static const struct attribute_group power_limit_attribute_group = {
6868
.name = "power_limits"
6969
};
7070

71-
static ssize_t tcc_offset_degree_celsius_show(struct device *dev,
72-
struct device_attribute *attr, char *buf)
71+
static int tcc_get_offset(void)
7372
{
7473
u64 val;
7574
int err;
@@ -78,8 +77,20 @@ static ssize_t tcc_offset_degree_celsius_show(struct device *dev,
7877
if (err)
7978
return err;
8079

81-
val = (val >> 24) & 0x3f;
82-
return sprintf(buf, "%d\n", (int)val);
80+
return (val >> 24) & 0x3f;
81+
}
82+
83+
static ssize_t tcc_offset_degree_celsius_show(struct device *dev,
84+
struct device_attribute *attr,
85+
char *buf)
86+
{
87+
int tcc;
88+
89+
tcc = tcc_get_offset();
90+
if (tcc < 0)
91+
return tcc;
92+
93+
return sprintf(buf, "%d\n", tcc);
8394
}
8495

8596
static int tcc_offset_update(unsigned int tcc)
@@ -107,8 +118,6 @@ static int tcc_offset_update(unsigned int tcc)
107118
return 0;
108119
}
109120

110-
static int tcc_offset_save = -1;
111-
112121
static ssize_t tcc_offset_degree_celsius_store(struct device *dev,
113122
struct device_attribute *attr, const char *buf,
114123
size_t count)
@@ -131,8 +140,6 @@ static ssize_t tcc_offset_degree_celsius_store(struct device *dev,
131140
if (err)
132141
return err;
133142

134-
tcc_offset_save = tcc;
135-
136143
return count;
137144
}
138145

@@ -345,13 +352,26 @@ void proc_thermal_remove(struct proc_thermal_device *proc_priv)
345352
}
346353
EXPORT_SYMBOL_GPL(proc_thermal_remove);
347354

355+
static int tcc_offset_save = -1;
356+
357+
int proc_thermal_suspend(struct device *dev)
358+
{
359+
tcc_offset_save = tcc_get_offset();
360+
if (tcc_offset_save < 0)
361+
dev_warn(dev, "failed to save offset (%d)\n", tcc_offset_save);
362+
363+
return 0;
364+
}
365+
EXPORT_SYMBOL_GPL(proc_thermal_suspend);
366+
348367
int proc_thermal_resume(struct device *dev)
349368
{
350369
struct proc_thermal_device *proc_dev;
351370

352371
proc_dev = dev_get_drvdata(dev);
353372
proc_thermal_read_ppcc(proc_dev);
354373

374+
/* Do not update if saving failed */
355375
if (tcc_offset_save >= 0)
356376
tcc_offset_update(tcc_offset_save);
357377

drivers/thermal/intel/int340x_thermal/processor_thermal_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ void proc_thermal_mbox_remove(struct pci_dev *pdev);
8383
int processor_thermal_send_mbox_cmd(struct pci_dev *pdev, u16 cmd_id, u32 cmd_data, u32 *cmd_resp);
8484
int proc_thermal_add(struct device *dev, struct proc_thermal_device *priv);
8585
void proc_thermal_remove(struct proc_thermal_device *proc_priv);
86+
int proc_thermal_suspend(struct device *dev);
8687
int proc_thermal_resume(struct device *dev);
8788
int proc_thermal_mmio_add(struct pci_dev *pdev,
8889
struct proc_thermal_device *proc_priv,

drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,20 @@ static void proc_thermal_pci_remove(struct pci_dev *pdev)
314314
}
315315

316316
#ifdef CONFIG_PM_SLEEP
317+
static int proc_thermal_pci_suspend(struct device *dev)
318+
{
319+
struct pci_dev *pdev = to_pci_dev(dev);
320+
struct proc_thermal_device *proc_priv;
321+
struct proc_thermal_pci *pci_info;
322+
323+
proc_priv = pci_get_drvdata(pdev);
324+
pci_info = proc_priv->priv_data;
325+
326+
if (!pci_info->no_legacy)
327+
return proc_thermal_suspend(dev);
328+
329+
return 0;
330+
}
317331
static int proc_thermal_pci_resume(struct device *dev)
318332
{
319333
struct pci_dev *pdev = to_pci_dev(dev);
@@ -335,10 +349,12 @@ static int proc_thermal_pci_resume(struct device *dev)
335349
return 0;
336350
}
337351
#else
352+
#define proc_thermal_pci_suspend NULL
338353
#define proc_thermal_pci_resume NULL
339354
#endif
340355

341-
static SIMPLE_DEV_PM_OPS(proc_thermal_pci_pm, NULL, proc_thermal_pci_resume);
356+
static SIMPLE_DEV_PM_OPS(proc_thermal_pci_pm, proc_thermal_pci_suspend,
357+
proc_thermal_pci_resume);
342358

343359
static const struct pci_device_id proc_thermal_pci_ids[] = {
344360
{ PCI_DEVICE_DATA(INTEL, ADL_THERMAL, PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_MBOX) },

drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,21 @@ static void proc_thermal_pci_remove(struct pci_dev *pdev)
107107
}
108108

109109
#ifdef CONFIG_PM_SLEEP
110+
static int proc_thermal_pci_suspend(struct device *dev)
111+
{
112+
return proc_thermal_suspend(dev);
113+
}
110114
static int proc_thermal_pci_resume(struct device *dev)
111115
{
112116
return proc_thermal_resume(dev);
113117
}
114118
#else
119+
#define proc_thermal_pci_suspend NULL
115120
#define proc_thermal_pci_resume NULL
116121
#endif
117122

118-
static SIMPLE_DEV_PM_OPS(proc_thermal_pci_pm, NULL, proc_thermal_pci_resume);
123+
static SIMPLE_DEV_PM_OPS(proc_thermal_pci_pm, proc_thermal_pci_suspend,
124+
proc_thermal_pci_resume);
119125

120126
static const struct pci_device_id proc_thermal_pci_ids[] = {
121127
{ PCI_DEVICE_DATA(INTEL, BDW_THERMAL, 0) },

0 commit comments

Comments
 (0)