Skip to content

Commit 176b1ec

Browse files
spandruvadazhang-rui
authored andcommitted
thermal: intel_pch_thermal: Add suspend/resume callback
Added suspend/resume callback to disable/enable PCH thermal sensor respectively. If the sensor is enabled by the BIOS, then the sensor status will not be changed during suspend/resume. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
1 parent 29b4817 commit 176b1ec

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

drivers/thermal/intel_pch_thermal.c

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/init.h>
2222
#include <linux/pci.h>
2323
#include <linux/thermal.h>
24+
#include <linux/pm.h>
2425

2526
/* Intel PCH thermal Device IDs */
2627
#define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */
@@ -65,6 +66,7 @@ struct pch_thermal_device {
6566
unsigned long crt_temp;
6667
int hot_trip_id;
6768
unsigned long hot_temp;
69+
bool bios_enabled;
6870
};
6971

7072
static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips)
@@ -75,8 +77,10 @@ static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips)
7577
*nr_trips = 0;
7678

7779
/* Check if BIOS has already enabled thermal sensor */
78-
if (WPT_TSS_TSDSS & readb(ptd->hw_base + WPT_TSS))
80+
if (WPT_TSS_TSDSS & readb(ptd->hw_base + WPT_TSS)) {
81+
ptd->bios_enabled = true;
7982
goto read_trips;
83+
}
8084

8185
tsel = readb(ptd->hw_base + WPT_TSEL);
8286
/*
@@ -130,16 +134,48 @@ static int pch_wpt_get_temp(struct pch_thermal_device *ptd, int *temp)
130134
return 0;
131135
}
132136

137+
static int pch_wpt_suspend(struct pch_thermal_device *ptd)
138+
{
139+
u8 tsel;
140+
141+
if (ptd->bios_enabled)
142+
return 0;
143+
144+
tsel = readb(ptd->hw_base + WPT_TSEL);
145+
146+
writeb(tsel & 0xFE, ptd->hw_base + WPT_TSEL);
147+
148+
return 0;
149+
}
150+
151+
static int pch_wpt_resume(struct pch_thermal_device *ptd)
152+
{
153+
u8 tsel;
154+
155+
if (ptd->bios_enabled)
156+
return 0;
157+
158+
tsel = readb(ptd->hw_base + WPT_TSEL);
159+
160+
writeb(tsel | WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL);
161+
162+
return 0;
163+
}
164+
133165
struct pch_dev_ops {
134166
int (*hw_init)(struct pch_thermal_device *ptd, int *nr_trips);
135167
int (*get_temp)(struct pch_thermal_device *ptd, int *temp);
168+
int (*suspend)(struct pch_thermal_device *ptd);
169+
int (*resume)(struct pch_thermal_device *ptd);
136170
};
137171

138172

139173
/* dev ops for Wildcat Point */
140174
static const struct pch_dev_ops pch_dev_ops_wpt = {
141175
.hw_init = pch_wpt_init,
142176
.get_temp = pch_wpt_get_temp,
177+
.suspend = pch_wpt_suspend,
178+
.resume = pch_wpt_resume,
143179
};
144180

145181
static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp)
@@ -269,18 +305,40 @@ static void intel_pch_thermal_remove(struct pci_dev *pdev)
269305
pci_disable_device(pdev);
270306
}
271307

308+
static int intel_pch_thermal_suspend(struct device *device)
309+
{
310+
struct pci_dev *pdev = to_pci_dev(device);
311+
struct pch_thermal_device *ptd = pci_get_drvdata(pdev);
312+
313+
return ptd->ops->suspend(ptd);
314+
}
315+
316+
static int intel_pch_thermal_resume(struct device *device)
317+
{
318+
struct pci_dev *pdev = to_pci_dev(device);
319+
struct pch_thermal_device *ptd = pci_get_drvdata(pdev);
320+
321+
return ptd->ops->resume(ptd);
322+
}
323+
272324
static struct pci_device_id intel_pch_thermal_id[] = {
273325
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT) },
274326
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL) },
275327
{ 0, },
276328
};
277329
MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id);
278330

331+
static const struct dev_pm_ops intel_pch_pm_ops = {
332+
.suspend = intel_pch_thermal_suspend,
333+
.resume = intel_pch_thermal_resume,
334+
};
335+
279336
static struct pci_driver intel_pch_thermal_driver = {
280337
.name = "intel_pch_thermal",
281338
.id_table = intel_pch_thermal_id,
282339
.probe = intel_pch_thermal_probe,
283340
.remove = intel_pch_thermal_remove,
341+
.driver.pm = &intel_pch_pm_ops,
284342
};
285343

286344
module_pci_driver(intel_pch_thermal_driver);

0 commit comments

Comments
 (0)