Skip to content

Commit 35c87f9

Browse files
committed
thermal: intel: intel_pch: Fold two functions into their callers
Fold two functions, pch_hw_init() and pch_get_temp(), 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 86cb100 commit 35c87f9

File tree

1 file changed

+42
-56
lines changed

1 file changed

+42
-56
lines changed

drivers/thermal/intel/intel_pch_thermal.c

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

120-
static int pch_hw_init(struct pch_thermal_device *ptd)
121-
{
122-
int nr_trips = 0;
123-
u16 trip_temp;
124-
u8 tsel;
125-
126-
/* Check if BIOS has already enabled thermal sensor */
127-
if (WPT_TSEL_ETS & readb(ptd->hw_base + WPT_TSEL)) {
128-
ptd->bios_enabled = true;
129-
goto read_trips;
130-
}
131-
132-
tsel = readb(ptd->hw_base + WPT_TSEL);
133-
/*
134-
* When TSEL's Policy Lock-Down bit is 1, TSEL become RO.
135-
* If so, thermal sensor cannot enable. Bail out.
136-
*/
137-
if (tsel & WPT_TSEL_PLDB) {
138-
dev_err(&ptd->pdev->dev, "Sensor can't be enabled\n");
139-
return -ENODEV;
140-
}
141-
142-
writeb(tsel|WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL);
143-
if (!(WPT_TSEL_ETS & readb(ptd->hw_base + WPT_TSEL))) {
144-
dev_err(&ptd->pdev->dev, "Sensor can't be enabled\n");
145-
return -ENODEV;
146-
}
147-
148-
read_trips:
149-
trip_temp = readw(ptd->hw_base + WPT_CTT);
150-
trip_temp &= 0x1FF;
151-
if (trip_temp) {
152-
ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp);
153-
ptd->trips[nr_trips++].type = THERMAL_TRIP_CRITICAL;
154-
}
155-
156-
trip_temp = readw(ptd->hw_base + WPT_PHL);
157-
trip_temp &= 0x1FF;
158-
if (trip_temp) {
159-
ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp);
160-
ptd->trips[nr_trips++].type = THERMAL_TRIP_HOT;
161-
}
162-
163-
return nr_trips + pch_wpt_add_acpi_psv_trip(ptd, nr_trips);
164-
}
165-
166-
static int pch_get_temp(struct pch_thermal_device *ptd)
167-
{
168-
return GET_WPT_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP));
169-
}
170-
171120
/* Cool the PCH when it's overheat in .suspend_noirq phase */
172121
static int pch_suspend(struct pch_thermal_device *ptd)
173122
{
@@ -254,7 +203,7 @@ static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp)
254203
{
255204
struct pch_thermal_device *ptd = tzd->devdata;
256205

257-
*temp = pch_get_temp(ptd);
206+
*temp = GET_WPT_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP));
258207
return 0;
259208
}
260209

@@ -310,8 +259,10 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev,
310259
enum board_ids board_id = id->driver_data;
311260
const struct board_info *bi = &board_info[board_id];
312261
struct pch_thermal_device *ptd;
262+
int nr_trips = 0;
263+
u16 trip_temp;
264+
u8 tsel;
313265
int err;
314-
int nr_trips;
315266

316267
ptd = devm_kzalloc(&pdev->dev, sizeof(*ptd), GFP_KERNEL);
317268
if (!ptd)
@@ -339,12 +290,47 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev,
339290
goto error_release;
340291
}
341292

342-
nr_trips = pch_hw_init(ptd);
343-
if (nr_trips < 0) {
344-
err = nr_trips;
293+
/* Check if BIOS has already enabled thermal sensor */
294+
if (WPT_TSEL_ETS & readb(ptd->hw_base + WPT_TSEL)) {
295+
ptd->bios_enabled = true;
296+
goto read_trips;
297+
}
298+
299+
tsel = readb(ptd->hw_base + WPT_TSEL);
300+
/*
301+
* When TSEL's Policy Lock-Down bit is 1, TSEL become RO.
302+
* If so, thermal sensor cannot enable. Bail out.
303+
*/
304+
if (tsel & WPT_TSEL_PLDB) {
305+
dev_err(&ptd->pdev->dev, "Sensor can't be enabled\n");
306+
err = -ENODEV;
345307
goto error_cleanup;
346308
}
347309

310+
writeb(tsel|WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL);
311+
if (!(WPT_TSEL_ETS & readb(ptd->hw_base + WPT_TSEL))) {
312+
dev_err(&ptd->pdev->dev, "Sensor can't be enabled\n");
313+
err = -ENODEV;
314+
goto error_cleanup;
315+
}
316+
317+
read_trips:
318+
trip_temp = readw(ptd->hw_base + WPT_CTT);
319+
trip_temp &= 0x1FF;
320+
if (trip_temp) {
321+
ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp);
322+
ptd->trips[nr_trips++].type = THERMAL_TRIP_CRITICAL;
323+
}
324+
325+
trip_temp = readw(ptd->hw_base + WPT_PHL);
326+
trip_temp &= 0x1FF;
327+
if (trip_temp) {
328+
ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp);
329+
ptd->trips[nr_trips++].type = THERMAL_TRIP_HOT;
330+
}
331+
332+
nr_trips += pch_wpt_add_acpi_psv_trip(ptd, nr_trips);
333+
348334
ptd->tzd = thermal_zone_device_register_with_trips(bi->name, ptd->trips,
349335
nr_trips, 0, ptd,
350336
&tzd_ops, NULL, 0, 0);

0 commit comments

Comments
 (0)