Skip to content

Commit c5f4324

Browse files
committed
thermal: intel: intel_pch: Fold suspend and resume routines into their callers
Fold pch_suspend() and pch_resume(), that each have only one caller, into their respective callers to make the code somewhat easier to follow. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Acked-by: Daniel Lezcano <[email protected]> Tested-by: Zhang Rui <[email protected]> Reviewed-by: Zhang Rui <[email protected]>
1 parent 35c87f9 commit c5f4324

File tree

1 file changed

+71
-84
lines changed

1 file changed

+71
-84
lines changed

drivers/thermal/intel/intel_pch_thermal.c

Lines changed: 71 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -117,88 +117,6 @@ static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, int trip)
117117
}
118118
#endif
119119

120-
/* Cool the PCH when it's overheat in .suspend_noirq phase */
121-
static int pch_suspend(struct pch_thermal_device *ptd)
122-
{
123-
u8 tsel;
124-
int pch_delay_cnt = 0;
125-
u16 pch_thr_temp, pch_cur_temp;
126-
127-
/* Shutdown the thermal sensor if it is not enabled by BIOS */
128-
if (!ptd->bios_enabled) {
129-
tsel = readb(ptd->hw_base + WPT_TSEL);
130-
writeb(tsel & 0xFE, ptd->hw_base + WPT_TSEL);
131-
return 0;
132-
}
133-
134-
/* Do not check temperature if it is not s2idle */
135-
if (pm_suspend_via_firmware())
136-
return 0;
137-
138-
/* Get the PCH temperature threshold value */
139-
pch_thr_temp = GET_PCH_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TSPM));
140-
141-
/* Get the PCH current temperature value */
142-
pch_cur_temp = GET_PCH_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP));
143-
144-
/*
145-
* If current PCH temperature is higher than configured PCH threshold
146-
* value, run some delay loop with sleep to let the current temperature
147-
* go down below the threshold value which helps to allow system enter
148-
* lower power S0ix suspend state. Even after delay loop if PCH current
149-
* temperature stays above threshold, notify the warning message
150-
* which helps to indentify the reason why S0ix entry was rejected.
151-
*/
152-
while (pch_delay_cnt < delay_cnt) {
153-
if (pch_cur_temp < pch_thr_temp)
154-
break;
155-
156-
if (pm_wakeup_pending()) {
157-
dev_warn(&ptd->pdev->dev, "Wakeup event detected, abort cooling\n");
158-
return 0;
159-
}
160-
161-
pch_delay_cnt++;
162-
dev_dbg(&ptd->pdev->dev,
163-
"CPU-PCH current temp [%dC] higher than the threshold temp [%dC], sleep %d times for %d ms duration\n",
164-
pch_cur_temp, pch_thr_temp, pch_delay_cnt, delay_timeout);
165-
msleep(delay_timeout);
166-
/* Read the PCH current temperature for next cycle. */
167-
pch_cur_temp = GET_PCH_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP));
168-
}
169-
170-
if (pch_cur_temp >= pch_thr_temp)
171-
dev_warn(&ptd->pdev->dev,
172-
"CPU-PCH is hot [%dC] after %d ms delay. S0ix might fail\n",
173-
pch_cur_temp, pch_delay_cnt * delay_timeout);
174-
else {
175-
if (pch_delay_cnt)
176-
dev_info(&ptd->pdev->dev,
177-
"CPU-PCH is cool [%dC] after %d ms delay\n",
178-
pch_cur_temp, pch_delay_cnt * delay_timeout);
179-
else
180-
dev_info(&ptd->pdev->dev,
181-
"CPU-PCH is cool [%dC]\n",
182-
pch_cur_temp);
183-
}
184-
185-
return 0;
186-
}
187-
188-
static int pch_resume(struct pch_thermal_device *ptd)
189-
{
190-
u8 tsel;
191-
192-
if (ptd->bios_enabled)
193-
return 0;
194-
195-
tsel = readb(ptd->hw_base + WPT_TSEL);
196-
197-
writeb(tsel | WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL);
198-
199-
return 0;
200-
}
201-
202120
static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp)
203121
{
204122
struct pch_thermal_device *ptd = tzd->devdata;
@@ -372,15 +290,84 @@ static void intel_pch_thermal_remove(struct pci_dev *pdev)
372290
static int intel_pch_thermal_suspend_noirq(struct device *device)
373291
{
374292
struct pch_thermal_device *ptd = dev_get_drvdata(device);
293+
u16 pch_thr_temp, pch_cur_temp;
294+
int pch_delay_cnt = 0;
295+
u8 tsel;
296+
297+
/* Shutdown the thermal sensor if it is not enabled by BIOS */
298+
if (!ptd->bios_enabled) {
299+
tsel = readb(ptd->hw_base + WPT_TSEL);
300+
writeb(tsel & 0xFE, ptd->hw_base + WPT_TSEL);
301+
return 0;
302+
}
303+
304+
/* Do not check temperature if it is not s2idle */
305+
if (pm_suspend_via_firmware())
306+
return 0;
307+
308+
/* Get the PCH temperature threshold value */
309+
pch_thr_temp = GET_PCH_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TSPM));
310+
311+
/* Get the PCH current temperature value */
312+
pch_cur_temp = GET_PCH_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP));
375313

376-
return pch_suspend(ptd);
314+
/*
315+
* If current PCH temperature is higher than configured PCH threshold
316+
* value, run some delay loop with sleep to let the current temperature
317+
* go down below the threshold value which helps to allow system enter
318+
* lower power S0ix suspend state. Even after delay loop if PCH current
319+
* temperature stays above threshold, notify the warning message
320+
* which helps to indentify the reason why S0ix entry was rejected.
321+
*/
322+
while (pch_delay_cnt < delay_cnt) {
323+
if (pch_cur_temp < pch_thr_temp)
324+
break;
325+
326+
if (pm_wakeup_pending()) {
327+
dev_warn(&ptd->pdev->dev, "Wakeup event detected, abort cooling\n");
328+
return 0;
329+
}
330+
331+
pch_delay_cnt++;
332+
dev_dbg(&ptd->pdev->dev,
333+
"CPU-PCH current temp [%dC] higher than the threshold temp [%dC], sleep %d times for %d ms duration\n",
334+
pch_cur_temp, pch_thr_temp, pch_delay_cnt, delay_timeout);
335+
msleep(delay_timeout);
336+
/* Read the PCH current temperature for next cycle. */
337+
pch_cur_temp = GET_PCH_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP));
338+
}
339+
340+
if (pch_cur_temp >= pch_thr_temp)
341+
dev_warn(&ptd->pdev->dev,
342+
"CPU-PCH is hot [%dC] after %d ms delay. S0ix might fail\n",
343+
pch_cur_temp, pch_delay_cnt * delay_timeout);
344+
else {
345+
if (pch_delay_cnt)
346+
dev_info(&ptd->pdev->dev,
347+
"CPU-PCH is cool [%dC] after %d ms delay\n",
348+
pch_cur_temp, pch_delay_cnt * delay_timeout);
349+
else
350+
dev_info(&ptd->pdev->dev,
351+
"CPU-PCH is cool [%dC]\n",
352+
pch_cur_temp);
353+
}
354+
355+
return 0;
377356
}
378357

379358
static int intel_pch_thermal_resume(struct device *device)
380359
{
381360
struct pch_thermal_device *ptd = dev_get_drvdata(device);
361+
u8 tsel;
382362

383-
return pch_resume(ptd);
363+
if (ptd->bios_enabled)
364+
return 0;
365+
366+
tsel = readb(ptd->hw_base + WPT_TSEL);
367+
368+
writeb(tsel | WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL);
369+
370+
return 0;
384371
}
385372

386373
static const struct pci_device_id intel_pch_thermal_id[] = {

0 commit comments

Comments
 (0)