Lines Matching +full:temp +full:- +full:sensor
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* intel_pch_thermal.c - Intel PCH Thermal driver
28 #define PCH_THERMAL_DID_CNL_H 0xA379 /* CNL-H PCH */
29 #define PCH_THERMAL_DID_CNL_LP 0x02F9 /* CNL-LP PCH */
30 #define PCH_THERMAL_DID_CML_H 0X06F9 /* CML-H PCH */
34 /* Wildcat Point-LP PCH Thermal registers */
36 #define WPT_TSC 0x04 /* Thermal Sensor Control */
37 #define WPT_TSS 0x06 /* Thermal Sensor Status */
38 #define WPT_TSEL 0x08 /* Thermal Sensor Enable and Lock */
39 #define WPT_TSREL 0x0A /* Thermal Sensor Report Enable and Lock */
40 #define WPT_TSMIC 0x0C /* Thermal Sensor SMI Control */
42 #define WPT_TSPM 0x001C /* Thermal Sensor Power Management */
52 /* Wildcat Point-LP PCH Thermal Register bit definitions */
53 #define WPT_TEMP_TSR 0x01ff /* Temp TS Reading */
54 #define WPT_TSC_CPDE 0x01 /* Catastrophic Power-Down Enable */
55 #define WPT_TSS_TSDSS 0x10 /* Thermal Sensor Dynamic Shutdown Status */
58 #define WPT_TSEL_PLDB 0x80 /* TSEL Policy Lock-Down Bit */
63 /* Resolution of 1/2 degree C and an offset of -50C */
64 #define PCH_TEMP_OFFSET (-50)
100 int temp; in pch_wpt_add_acpi_psv_trip() local
102 adev = ACPI_COMPANION(&ptd->pdev->dev); in pch_wpt_add_acpi_psv_trip()
106 if (thermal_acpi_passive_trip_temp(adev, &temp) || temp <= 0) in pch_wpt_add_acpi_psv_trip()
109 trip->type = THERMAL_TRIP_PASSIVE; in pch_wpt_add_acpi_psv_trip()
110 trip->temperature = temp; in pch_wpt_add_acpi_psv_trip()
121 static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp) in pch_thermal_get_temp() argument
125 *temp = GET_WPT_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP)); in pch_thermal_get_temp()
164 enum pch_board_ids board_id = id->driver_data; in intel_pch_thermal_probe()
171 ptd = devm_kzalloc(&pdev->dev, sizeof(*ptd), GFP_KERNEL); in intel_pch_thermal_probe()
173 return -ENOMEM; in intel_pch_thermal_probe()
176 ptd->pdev = pdev; in intel_pch_thermal_probe()
180 dev_err(&pdev->dev, "failed to enable pci device\n"); in intel_pch_thermal_probe()
186 dev_err(&pdev->dev, "failed to request pci region\n"); in intel_pch_thermal_probe()
190 ptd->hw_base = pci_ioremap_bar(pdev, 0); in intel_pch_thermal_probe()
191 if (!ptd->hw_base) { in intel_pch_thermal_probe()
192 err = -ENOMEM; in intel_pch_thermal_probe()
193 dev_err(&pdev->dev, "failed to map mem base\n"); in intel_pch_thermal_probe()
197 /* Check if BIOS has already enabled thermal sensor */ in intel_pch_thermal_probe()
198 if (WPT_TSEL_ETS & readb(ptd->hw_base + WPT_TSEL)) { in intel_pch_thermal_probe()
199 ptd->bios_enabled = true; in intel_pch_thermal_probe()
203 tsel = readb(ptd->hw_base + WPT_TSEL); in intel_pch_thermal_probe()
205 * When TSEL's Policy Lock-Down bit is 1, TSEL become RO. in intel_pch_thermal_probe()
206 * If so, thermal sensor cannot enable. Bail out. in intel_pch_thermal_probe()
209 dev_err(&ptd->pdev->dev, "Sensor can't be enabled\n"); in intel_pch_thermal_probe()
210 err = -ENODEV; in intel_pch_thermal_probe()
214 writeb(tsel|WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL); in intel_pch_thermal_probe()
215 if (!(WPT_TSEL_ETS & readb(ptd->hw_base + WPT_TSEL))) { in intel_pch_thermal_probe()
216 dev_err(&ptd->pdev->dev, "Sensor can't be enabled\n"); in intel_pch_thermal_probe()
217 err = -ENODEV; in intel_pch_thermal_probe()
222 trip_temp = readw(ptd->hw_base + WPT_CTT); in intel_pch_thermal_probe()
229 trip_temp = readw(ptd->hw_base + WPT_PHL); in intel_pch_thermal_probe()
238 ptd->tzd = thermal_zone_device_register_with_trips(board_names[board_id], in intel_pch_thermal_probe()
242 if (IS_ERR(ptd->tzd)) { in intel_pch_thermal_probe()
243 dev_err(&pdev->dev, "Failed to register thermal zone %s\n", in intel_pch_thermal_probe()
245 err = PTR_ERR(ptd->tzd); in intel_pch_thermal_probe()
248 err = thermal_zone_device_enable(ptd->tzd); in intel_pch_thermal_probe()
255 thermal_zone_device_unregister(ptd->tzd); in intel_pch_thermal_probe()
257 iounmap(ptd->hw_base); in intel_pch_thermal_probe()
262 dev_err(&pdev->dev, "pci device failed to probe\n"); in intel_pch_thermal_probe()
270 thermal_zone_device_unregister(ptd->tzd); in intel_pch_thermal_remove()
271 iounmap(ptd->hw_base); in intel_pch_thermal_remove()
284 /* Shutdown the thermal sensor if it is not enabled by BIOS */ in intel_pch_thermal_suspend_noirq()
285 if (!ptd->bios_enabled) { in intel_pch_thermal_suspend_noirq()
286 tsel = readb(ptd->hw_base + WPT_TSEL); in intel_pch_thermal_suspend_noirq()
287 writeb(tsel & 0xFE, ptd->hw_base + WPT_TSEL); in intel_pch_thermal_suspend_noirq()
296 pch_thr_temp = GET_PCH_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TSPM)); in intel_pch_thermal_suspend_noirq()
299 pch_cur_temp = GET_PCH_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP)); in intel_pch_thermal_suspend_noirq()
302 dev_warn(&ptd->pdev->dev, in intel_pch_thermal_suspend_noirq()
303 …"CPU-PCH current temp [%dC] higher than the threshold temp [%dC], S0ix might fail. Start cooling..… in intel_pch_thermal_suspend_noirq()
319 dev_warn(&ptd->pdev->dev, "Wakeup event detected, abort cooling\n"); in intel_pch_thermal_suspend_noirq()
324 dev_dbg(&ptd->pdev->dev, in intel_pch_thermal_suspend_noirq()
325 …"CPU-PCH current temp [%dC] higher than the threshold temp [%dC], sleep %d times for %d ms duratio… in intel_pch_thermal_suspend_noirq()
329 pch_cur_temp = GET_PCH_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP)); in intel_pch_thermal_suspend_noirq()
333 dev_warn(&ptd->pdev->dev, in intel_pch_thermal_suspend_noirq()
334 "CPU-PCH is hot [%dC] after %d ms delay. S0ix might fail\n", in intel_pch_thermal_suspend_noirq()
338 dev_info(&ptd->pdev->dev, in intel_pch_thermal_suspend_noirq()
339 "CPU-PCH is cool [%dC] after %d ms delay\n", in intel_pch_thermal_suspend_noirq()
342 dev_info(&ptd->pdev->dev, in intel_pch_thermal_suspend_noirq()
343 "CPU-PCH is cool [%dC]\n", in intel_pch_thermal_suspend_noirq()
355 if (ptd->bios_enabled) in intel_pch_thermal_resume()
358 tsel = readb(ptd->hw_base + WPT_TSEL); in intel_pch_thermal_resume()
360 writeb(tsel | WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL); in intel_pch_thermal_resume()