1*2025cf9eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 23e8c4d31SAmit Kucheria /* intel_pch_thermal.c - Intel PCH Thermal driver 33e8c4d31SAmit Kucheria * 43e8c4d31SAmit Kucheria * Copyright (c) 2015, Intel Corporation. 53e8c4d31SAmit Kucheria * 63e8c4d31SAmit Kucheria * Authors: 73e8c4d31SAmit Kucheria * Tushar Dave <tushar.n.dave@intel.com> 83e8c4d31SAmit Kucheria */ 93e8c4d31SAmit Kucheria 103e8c4d31SAmit Kucheria #include <linux/module.h> 113e8c4d31SAmit Kucheria #include <linux/types.h> 123e8c4d31SAmit Kucheria #include <linux/init.h> 133e8c4d31SAmit Kucheria #include <linux/pci.h> 143e8c4d31SAmit Kucheria #include <linux/acpi.h> 153e8c4d31SAmit Kucheria #include <linux/thermal.h> 163e8c4d31SAmit Kucheria #include <linux/pm.h> 173e8c4d31SAmit Kucheria 183e8c4d31SAmit Kucheria /* Intel PCH thermal Device IDs */ 193e8c4d31SAmit Kucheria #define PCH_THERMAL_DID_HSW_1 0x9C24 /* Haswell PCH */ 203e8c4d31SAmit Kucheria #define PCH_THERMAL_DID_HSW_2 0x8C24 /* Haswell PCH */ 213e8c4d31SAmit Kucheria #define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */ 223e8c4d31SAmit Kucheria #define PCH_THERMAL_DID_SKL 0x9D31 /* Skylake PCH */ 233e8c4d31SAmit Kucheria #define PCH_THERMAL_DID_SKL_H 0xA131 /* Skylake PCH 100 series */ 243e8c4d31SAmit Kucheria #define PCH_THERMAL_DID_CNL 0x9Df9 /* CNL PCH */ 253e8c4d31SAmit Kucheria #define PCH_THERMAL_DID_CNL_H 0xA379 /* CNL-H PCH */ 263e8c4d31SAmit Kucheria 273e8c4d31SAmit Kucheria /* Wildcat Point-LP PCH Thermal registers */ 283e8c4d31SAmit Kucheria #define WPT_TEMP 0x0000 /* Temperature */ 293e8c4d31SAmit Kucheria #define WPT_TSC 0x04 /* Thermal Sensor Control */ 303e8c4d31SAmit Kucheria #define WPT_TSS 0x06 /* Thermal Sensor Status */ 313e8c4d31SAmit Kucheria #define WPT_TSEL 0x08 /* Thermal Sensor Enable and Lock */ 323e8c4d31SAmit Kucheria #define WPT_TSREL 0x0A /* Thermal Sensor Report Enable and Lock */ 333e8c4d31SAmit Kucheria #define WPT_TSMIC 0x0C /* Thermal Sensor SMI Control */ 343e8c4d31SAmit Kucheria #define WPT_CTT 0x0010 /* Catastrophic Trip Point */ 353e8c4d31SAmit Kucheria #define WPT_TAHV 0x0014 /* Thermal Alert High Value */ 363e8c4d31SAmit Kucheria #define WPT_TALV 0x0018 /* Thermal Alert Low Value */ 373e8c4d31SAmit Kucheria #define WPT_TL 0x00000040 /* Throttle Value */ 383e8c4d31SAmit Kucheria #define WPT_PHL 0x0060 /* PCH Hot Level */ 393e8c4d31SAmit Kucheria #define WPT_PHLC 0x62 /* PHL Control */ 403e8c4d31SAmit Kucheria #define WPT_TAS 0x80 /* Thermal Alert Status */ 413e8c4d31SAmit Kucheria #define WPT_TSPIEN 0x82 /* PCI Interrupt Event Enables */ 423e8c4d31SAmit Kucheria #define WPT_TSGPEN 0x84 /* General Purpose Event Enables */ 433e8c4d31SAmit Kucheria 443e8c4d31SAmit Kucheria /* Wildcat Point-LP PCH Thermal Register bit definitions */ 453e8c4d31SAmit Kucheria #define WPT_TEMP_TSR 0x01ff /* Temp TS Reading */ 463e8c4d31SAmit Kucheria #define WPT_TSC_CPDE 0x01 /* Catastrophic Power-Down Enable */ 473e8c4d31SAmit Kucheria #define WPT_TSS_TSDSS 0x10 /* Thermal Sensor Dynamic Shutdown Status */ 483e8c4d31SAmit Kucheria #define WPT_TSS_GPES 0x08 /* GPE status */ 493e8c4d31SAmit Kucheria #define WPT_TSEL_ETS 0x01 /* Enable TS */ 503e8c4d31SAmit Kucheria #define WPT_TSEL_PLDB 0x80 /* TSEL Policy Lock-Down Bit */ 513e8c4d31SAmit Kucheria #define WPT_TL_TOL 0x000001FF /* T0 Level */ 523e8c4d31SAmit Kucheria #define WPT_TL_T1L 0x1ff00000 /* T1 Level */ 533e8c4d31SAmit Kucheria #define WPT_TL_TTEN 0x20000000 /* TT Enable */ 543e8c4d31SAmit Kucheria 553e8c4d31SAmit Kucheria static char driver_name[] = "Intel PCH thermal driver"; 563e8c4d31SAmit Kucheria 573e8c4d31SAmit Kucheria struct pch_thermal_device { 583e8c4d31SAmit Kucheria void __iomem *hw_base; 593e8c4d31SAmit Kucheria const struct pch_dev_ops *ops; 603e8c4d31SAmit Kucheria struct pci_dev *pdev; 613e8c4d31SAmit Kucheria struct thermal_zone_device *tzd; 623e8c4d31SAmit Kucheria int crt_trip_id; 633e8c4d31SAmit Kucheria unsigned long crt_temp; 643e8c4d31SAmit Kucheria int hot_trip_id; 653e8c4d31SAmit Kucheria unsigned long hot_temp; 663e8c4d31SAmit Kucheria int psv_trip_id; 673e8c4d31SAmit Kucheria unsigned long psv_temp; 683e8c4d31SAmit Kucheria bool bios_enabled; 693e8c4d31SAmit Kucheria }; 703e8c4d31SAmit Kucheria 713e8c4d31SAmit Kucheria #ifdef CONFIG_ACPI 723e8c4d31SAmit Kucheria 733e8c4d31SAmit Kucheria /* 743e8c4d31SAmit Kucheria * On some platforms, there is a companion ACPI device, which adds 753e8c4d31SAmit Kucheria * passive trip temperature using _PSV method. There is no specific 763e8c4d31SAmit Kucheria * passive temperature setting in MMIO interface of this PCI device. 773e8c4d31SAmit Kucheria */ 783e8c4d31SAmit Kucheria static void pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, 793e8c4d31SAmit Kucheria int *nr_trips) 803e8c4d31SAmit Kucheria { 813e8c4d31SAmit Kucheria struct acpi_device *adev; 823e8c4d31SAmit Kucheria 833e8c4d31SAmit Kucheria ptd->psv_trip_id = -1; 843e8c4d31SAmit Kucheria 853e8c4d31SAmit Kucheria adev = ACPI_COMPANION(&ptd->pdev->dev); 863e8c4d31SAmit Kucheria if (adev) { 873e8c4d31SAmit Kucheria unsigned long long r; 883e8c4d31SAmit Kucheria acpi_status status; 893e8c4d31SAmit Kucheria 903e8c4d31SAmit Kucheria status = acpi_evaluate_integer(adev->handle, "_PSV", NULL, 913e8c4d31SAmit Kucheria &r); 923e8c4d31SAmit Kucheria if (ACPI_SUCCESS(status)) { 933e8c4d31SAmit Kucheria unsigned long trip_temp; 943e8c4d31SAmit Kucheria 953e8c4d31SAmit Kucheria trip_temp = DECI_KELVIN_TO_MILLICELSIUS(r); 963e8c4d31SAmit Kucheria if (trip_temp) { 973e8c4d31SAmit Kucheria ptd->psv_temp = trip_temp; 983e8c4d31SAmit Kucheria ptd->psv_trip_id = *nr_trips; 993e8c4d31SAmit Kucheria ++(*nr_trips); 1003e8c4d31SAmit Kucheria } 1013e8c4d31SAmit Kucheria } 1023e8c4d31SAmit Kucheria } 1033e8c4d31SAmit Kucheria } 1043e8c4d31SAmit Kucheria #else 1053e8c4d31SAmit Kucheria static void pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, 1063e8c4d31SAmit Kucheria int *nr_trips) 1073e8c4d31SAmit Kucheria { 1083e8c4d31SAmit Kucheria ptd->psv_trip_id = -1; 1093e8c4d31SAmit Kucheria 1103e8c4d31SAmit Kucheria } 1113e8c4d31SAmit Kucheria #endif 1123e8c4d31SAmit Kucheria 1133e8c4d31SAmit Kucheria static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips) 1143e8c4d31SAmit Kucheria { 1153e8c4d31SAmit Kucheria u8 tsel; 1163e8c4d31SAmit Kucheria u16 trip_temp; 1173e8c4d31SAmit Kucheria 1183e8c4d31SAmit Kucheria *nr_trips = 0; 1193e8c4d31SAmit Kucheria 1203e8c4d31SAmit Kucheria /* Check if BIOS has already enabled thermal sensor */ 1213e8c4d31SAmit Kucheria if (WPT_TSEL_ETS & readb(ptd->hw_base + WPT_TSEL)) { 1223e8c4d31SAmit Kucheria ptd->bios_enabled = true; 1233e8c4d31SAmit Kucheria goto read_trips; 1243e8c4d31SAmit Kucheria } 1253e8c4d31SAmit Kucheria 1263e8c4d31SAmit Kucheria tsel = readb(ptd->hw_base + WPT_TSEL); 1273e8c4d31SAmit Kucheria /* 1283e8c4d31SAmit Kucheria * When TSEL's Policy Lock-Down bit is 1, TSEL become RO. 1293e8c4d31SAmit Kucheria * If so, thermal sensor cannot enable. Bail out. 1303e8c4d31SAmit Kucheria */ 1313e8c4d31SAmit Kucheria if (tsel & WPT_TSEL_PLDB) { 1323e8c4d31SAmit Kucheria dev_err(&ptd->pdev->dev, "Sensor can't be enabled\n"); 1333e8c4d31SAmit Kucheria return -ENODEV; 1343e8c4d31SAmit Kucheria } 1353e8c4d31SAmit Kucheria 1363e8c4d31SAmit Kucheria writeb(tsel|WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL); 1373e8c4d31SAmit Kucheria if (!(WPT_TSEL_ETS & readb(ptd->hw_base + WPT_TSEL))) { 1383e8c4d31SAmit Kucheria dev_err(&ptd->pdev->dev, "Sensor can't be enabled\n"); 1393e8c4d31SAmit Kucheria return -ENODEV; 1403e8c4d31SAmit Kucheria } 1413e8c4d31SAmit Kucheria 1423e8c4d31SAmit Kucheria read_trips: 1433e8c4d31SAmit Kucheria ptd->crt_trip_id = -1; 1443e8c4d31SAmit Kucheria trip_temp = readw(ptd->hw_base + WPT_CTT); 1453e8c4d31SAmit Kucheria trip_temp &= 0x1FF; 1463e8c4d31SAmit Kucheria if (trip_temp) { 1473e8c4d31SAmit Kucheria /* Resolution of 1/2 degree C and an offset of -50C */ 1483e8c4d31SAmit Kucheria ptd->crt_temp = trip_temp * 1000 / 2 - 50000; 1493e8c4d31SAmit Kucheria ptd->crt_trip_id = 0; 1503e8c4d31SAmit Kucheria ++(*nr_trips); 1513e8c4d31SAmit Kucheria } 1523e8c4d31SAmit Kucheria 1533e8c4d31SAmit Kucheria ptd->hot_trip_id = -1; 1543e8c4d31SAmit Kucheria trip_temp = readw(ptd->hw_base + WPT_PHL); 1553e8c4d31SAmit Kucheria trip_temp &= 0x1FF; 1563e8c4d31SAmit Kucheria if (trip_temp) { 1573e8c4d31SAmit Kucheria /* Resolution of 1/2 degree C and an offset of -50C */ 1583e8c4d31SAmit Kucheria ptd->hot_temp = trip_temp * 1000 / 2 - 50000; 1593e8c4d31SAmit Kucheria ptd->hot_trip_id = *nr_trips; 1603e8c4d31SAmit Kucheria ++(*nr_trips); 1613e8c4d31SAmit Kucheria } 1623e8c4d31SAmit Kucheria 1633e8c4d31SAmit Kucheria pch_wpt_add_acpi_psv_trip(ptd, nr_trips); 1643e8c4d31SAmit Kucheria 1653e8c4d31SAmit Kucheria return 0; 1663e8c4d31SAmit Kucheria } 1673e8c4d31SAmit Kucheria 1683e8c4d31SAmit Kucheria static int pch_wpt_get_temp(struct pch_thermal_device *ptd, int *temp) 1693e8c4d31SAmit Kucheria { 1703e8c4d31SAmit Kucheria u16 wpt_temp; 1713e8c4d31SAmit Kucheria 1723e8c4d31SAmit Kucheria wpt_temp = WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP); 1733e8c4d31SAmit Kucheria 1743e8c4d31SAmit Kucheria /* Resolution of 1/2 degree C and an offset of -50C */ 1753e8c4d31SAmit Kucheria *temp = (wpt_temp * 1000 / 2 - 50000); 1763e8c4d31SAmit Kucheria 1773e8c4d31SAmit Kucheria return 0; 1783e8c4d31SAmit Kucheria } 1793e8c4d31SAmit Kucheria 1803e8c4d31SAmit Kucheria static int pch_wpt_suspend(struct pch_thermal_device *ptd) 1813e8c4d31SAmit Kucheria { 1823e8c4d31SAmit Kucheria u8 tsel; 1833e8c4d31SAmit Kucheria 1843e8c4d31SAmit Kucheria if (ptd->bios_enabled) 1853e8c4d31SAmit Kucheria return 0; 1863e8c4d31SAmit Kucheria 1873e8c4d31SAmit Kucheria tsel = readb(ptd->hw_base + WPT_TSEL); 1883e8c4d31SAmit Kucheria 1893e8c4d31SAmit Kucheria writeb(tsel & 0xFE, ptd->hw_base + WPT_TSEL); 1903e8c4d31SAmit Kucheria 1913e8c4d31SAmit Kucheria return 0; 1923e8c4d31SAmit Kucheria } 1933e8c4d31SAmit Kucheria 1943e8c4d31SAmit Kucheria static int pch_wpt_resume(struct pch_thermal_device *ptd) 1953e8c4d31SAmit Kucheria { 1963e8c4d31SAmit Kucheria u8 tsel; 1973e8c4d31SAmit Kucheria 1983e8c4d31SAmit Kucheria if (ptd->bios_enabled) 1993e8c4d31SAmit Kucheria return 0; 2003e8c4d31SAmit Kucheria 2013e8c4d31SAmit Kucheria tsel = readb(ptd->hw_base + WPT_TSEL); 2023e8c4d31SAmit Kucheria 2033e8c4d31SAmit Kucheria writeb(tsel | WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL); 2043e8c4d31SAmit Kucheria 2053e8c4d31SAmit Kucheria return 0; 2063e8c4d31SAmit Kucheria } 2073e8c4d31SAmit Kucheria 2083e8c4d31SAmit Kucheria struct pch_dev_ops { 2093e8c4d31SAmit Kucheria int (*hw_init)(struct pch_thermal_device *ptd, int *nr_trips); 2103e8c4d31SAmit Kucheria int (*get_temp)(struct pch_thermal_device *ptd, int *temp); 2113e8c4d31SAmit Kucheria int (*suspend)(struct pch_thermal_device *ptd); 2123e8c4d31SAmit Kucheria int (*resume)(struct pch_thermal_device *ptd); 2133e8c4d31SAmit Kucheria }; 2143e8c4d31SAmit Kucheria 2153e8c4d31SAmit Kucheria 2163e8c4d31SAmit Kucheria /* dev ops for Wildcat Point */ 2173e8c4d31SAmit Kucheria static const struct pch_dev_ops pch_dev_ops_wpt = { 2183e8c4d31SAmit Kucheria .hw_init = pch_wpt_init, 2193e8c4d31SAmit Kucheria .get_temp = pch_wpt_get_temp, 2203e8c4d31SAmit Kucheria .suspend = pch_wpt_suspend, 2213e8c4d31SAmit Kucheria .resume = pch_wpt_resume, 2223e8c4d31SAmit Kucheria }; 2233e8c4d31SAmit Kucheria 2243e8c4d31SAmit Kucheria static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp) 2253e8c4d31SAmit Kucheria { 2263e8c4d31SAmit Kucheria struct pch_thermal_device *ptd = tzd->devdata; 2273e8c4d31SAmit Kucheria 2283e8c4d31SAmit Kucheria return ptd->ops->get_temp(ptd, temp); 2293e8c4d31SAmit Kucheria } 2303e8c4d31SAmit Kucheria 2313e8c4d31SAmit Kucheria static int pch_get_trip_type(struct thermal_zone_device *tzd, int trip, 2323e8c4d31SAmit Kucheria enum thermal_trip_type *type) 2333e8c4d31SAmit Kucheria { 2343e8c4d31SAmit Kucheria struct pch_thermal_device *ptd = tzd->devdata; 2353e8c4d31SAmit Kucheria 2363e8c4d31SAmit Kucheria if (ptd->crt_trip_id == trip) 2373e8c4d31SAmit Kucheria *type = THERMAL_TRIP_CRITICAL; 2383e8c4d31SAmit Kucheria else if (ptd->hot_trip_id == trip) 2393e8c4d31SAmit Kucheria *type = THERMAL_TRIP_HOT; 2403e8c4d31SAmit Kucheria else if (ptd->psv_trip_id == trip) 2413e8c4d31SAmit Kucheria *type = THERMAL_TRIP_PASSIVE; 2423e8c4d31SAmit Kucheria else 2433e8c4d31SAmit Kucheria return -EINVAL; 2443e8c4d31SAmit Kucheria 2453e8c4d31SAmit Kucheria return 0; 2463e8c4d31SAmit Kucheria } 2473e8c4d31SAmit Kucheria 2483e8c4d31SAmit Kucheria static int pch_get_trip_temp(struct thermal_zone_device *tzd, int trip, int *temp) 2493e8c4d31SAmit Kucheria { 2503e8c4d31SAmit Kucheria struct pch_thermal_device *ptd = tzd->devdata; 2513e8c4d31SAmit Kucheria 2523e8c4d31SAmit Kucheria if (ptd->crt_trip_id == trip) 2533e8c4d31SAmit Kucheria *temp = ptd->crt_temp; 2543e8c4d31SAmit Kucheria else if (ptd->hot_trip_id == trip) 2553e8c4d31SAmit Kucheria *temp = ptd->hot_temp; 2563e8c4d31SAmit Kucheria else if (ptd->psv_trip_id == trip) 2573e8c4d31SAmit Kucheria *temp = ptd->psv_temp; 2583e8c4d31SAmit Kucheria else 2593e8c4d31SAmit Kucheria return -EINVAL; 2603e8c4d31SAmit Kucheria 2613e8c4d31SAmit Kucheria return 0; 2623e8c4d31SAmit Kucheria } 2633e8c4d31SAmit Kucheria 2643e8c4d31SAmit Kucheria static struct thermal_zone_device_ops tzd_ops = { 2653e8c4d31SAmit Kucheria .get_temp = pch_thermal_get_temp, 2663e8c4d31SAmit Kucheria .get_trip_type = pch_get_trip_type, 2673e8c4d31SAmit Kucheria .get_trip_temp = pch_get_trip_temp, 2683e8c4d31SAmit Kucheria }; 2693e8c4d31SAmit Kucheria 2703e8c4d31SAmit Kucheria enum board_ids { 2713e8c4d31SAmit Kucheria board_hsw, 2723e8c4d31SAmit Kucheria board_wpt, 2733e8c4d31SAmit Kucheria board_skl, 2743e8c4d31SAmit Kucheria board_cnl, 2753e8c4d31SAmit Kucheria }; 2763e8c4d31SAmit Kucheria 2773e8c4d31SAmit Kucheria static const struct board_info { 2783e8c4d31SAmit Kucheria const char *name; 2793e8c4d31SAmit Kucheria const struct pch_dev_ops *ops; 2803e8c4d31SAmit Kucheria } board_info[] = { 2813e8c4d31SAmit Kucheria [board_hsw] = { 2823e8c4d31SAmit Kucheria .name = "pch_haswell", 2833e8c4d31SAmit Kucheria .ops = &pch_dev_ops_wpt, 2843e8c4d31SAmit Kucheria }, 2853e8c4d31SAmit Kucheria [board_wpt] = { 2863e8c4d31SAmit Kucheria .name = "pch_wildcat_point", 2873e8c4d31SAmit Kucheria .ops = &pch_dev_ops_wpt, 2883e8c4d31SAmit Kucheria }, 2893e8c4d31SAmit Kucheria [board_skl] = { 2903e8c4d31SAmit Kucheria .name = "pch_skylake", 2913e8c4d31SAmit Kucheria .ops = &pch_dev_ops_wpt, 2923e8c4d31SAmit Kucheria }, 2933e8c4d31SAmit Kucheria [board_cnl] = { 2943e8c4d31SAmit Kucheria .name = "pch_cannonlake", 2953e8c4d31SAmit Kucheria .ops = &pch_dev_ops_wpt, 2963e8c4d31SAmit Kucheria }, 2973e8c4d31SAmit Kucheria }; 2983e8c4d31SAmit Kucheria 2993e8c4d31SAmit Kucheria static int intel_pch_thermal_probe(struct pci_dev *pdev, 3003e8c4d31SAmit Kucheria const struct pci_device_id *id) 3013e8c4d31SAmit Kucheria { 3023e8c4d31SAmit Kucheria enum board_ids board_id = id->driver_data; 3033e8c4d31SAmit Kucheria const struct board_info *bi = &board_info[board_id]; 3043e8c4d31SAmit Kucheria struct pch_thermal_device *ptd; 3053e8c4d31SAmit Kucheria int err; 3063e8c4d31SAmit Kucheria int nr_trips; 3073e8c4d31SAmit Kucheria 3083e8c4d31SAmit Kucheria ptd = devm_kzalloc(&pdev->dev, sizeof(*ptd), GFP_KERNEL); 3093e8c4d31SAmit Kucheria if (!ptd) 3103e8c4d31SAmit Kucheria return -ENOMEM; 3113e8c4d31SAmit Kucheria 3123e8c4d31SAmit Kucheria ptd->ops = bi->ops; 3133e8c4d31SAmit Kucheria 3143e8c4d31SAmit Kucheria pci_set_drvdata(pdev, ptd); 3153e8c4d31SAmit Kucheria ptd->pdev = pdev; 3163e8c4d31SAmit Kucheria 3173e8c4d31SAmit Kucheria err = pci_enable_device(pdev); 3183e8c4d31SAmit Kucheria if (err) { 3193e8c4d31SAmit Kucheria dev_err(&pdev->dev, "failed to enable pci device\n"); 3203e8c4d31SAmit Kucheria return err; 3213e8c4d31SAmit Kucheria } 3223e8c4d31SAmit Kucheria 3233e8c4d31SAmit Kucheria err = pci_request_regions(pdev, driver_name); 3243e8c4d31SAmit Kucheria if (err) { 3253e8c4d31SAmit Kucheria dev_err(&pdev->dev, "failed to request pci region\n"); 3263e8c4d31SAmit Kucheria goto error_disable; 3273e8c4d31SAmit Kucheria } 3283e8c4d31SAmit Kucheria 3293e8c4d31SAmit Kucheria ptd->hw_base = pci_ioremap_bar(pdev, 0); 3303e8c4d31SAmit Kucheria if (!ptd->hw_base) { 3313e8c4d31SAmit Kucheria err = -ENOMEM; 3323e8c4d31SAmit Kucheria dev_err(&pdev->dev, "failed to map mem base\n"); 3333e8c4d31SAmit Kucheria goto error_release; 3343e8c4d31SAmit Kucheria } 3353e8c4d31SAmit Kucheria 3363e8c4d31SAmit Kucheria err = ptd->ops->hw_init(ptd, &nr_trips); 3373e8c4d31SAmit Kucheria if (err) 3383e8c4d31SAmit Kucheria goto error_cleanup; 3393e8c4d31SAmit Kucheria 3403e8c4d31SAmit Kucheria ptd->tzd = thermal_zone_device_register(bi->name, nr_trips, 0, ptd, 3413e8c4d31SAmit Kucheria &tzd_ops, NULL, 0, 0); 3423e8c4d31SAmit Kucheria if (IS_ERR(ptd->tzd)) { 3433e8c4d31SAmit Kucheria dev_err(&pdev->dev, "Failed to register thermal zone %s\n", 3443e8c4d31SAmit Kucheria bi->name); 3453e8c4d31SAmit Kucheria err = PTR_ERR(ptd->tzd); 3463e8c4d31SAmit Kucheria goto error_cleanup; 3473e8c4d31SAmit Kucheria } 3483e8c4d31SAmit Kucheria 3493e8c4d31SAmit Kucheria return 0; 3503e8c4d31SAmit Kucheria 3513e8c4d31SAmit Kucheria error_cleanup: 3523e8c4d31SAmit Kucheria iounmap(ptd->hw_base); 3533e8c4d31SAmit Kucheria error_release: 3543e8c4d31SAmit Kucheria pci_release_regions(pdev); 3553e8c4d31SAmit Kucheria error_disable: 3563e8c4d31SAmit Kucheria pci_disable_device(pdev); 3573e8c4d31SAmit Kucheria dev_err(&pdev->dev, "pci device failed to probe\n"); 3583e8c4d31SAmit Kucheria return err; 3593e8c4d31SAmit Kucheria } 3603e8c4d31SAmit Kucheria 3613e8c4d31SAmit Kucheria static void intel_pch_thermal_remove(struct pci_dev *pdev) 3623e8c4d31SAmit Kucheria { 3633e8c4d31SAmit Kucheria struct pch_thermal_device *ptd = pci_get_drvdata(pdev); 3643e8c4d31SAmit Kucheria 3653e8c4d31SAmit Kucheria thermal_zone_device_unregister(ptd->tzd); 3663e8c4d31SAmit Kucheria iounmap(ptd->hw_base); 3673e8c4d31SAmit Kucheria pci_set_drvdata(pdev, NULL); 3683e8c4d31SAmit Kucheria pci_release_region(pdev, 0); 3693e8c4d31SAmit Kucheria pci_disable_device(pdev); 3703e8c4d31SAmit Kucheria } 3713e8c4d31SAmit Kucheria 3723e8c4d31SAmit Kucheria static int intel_pch_thermal_suspend(struct device *device) 3733e8c4d31SAmit Kucheria { 3743e8c4d31SAmit Kucheria struct pci_dev *pdev = to_pci_dev(device); 3753e8c4d31SAmit Kucheria struct pch_thermal_device *ptd = pci_get_drvdata(pdev); 3763e8c4d31SAmit Kucheria 3773e8c4d31SAmit Kucheria return ptd->ops->suspend(ptd); 3783e8c4d31SAmit Kucheria } 3793e8c4d31SAmit Kucheria 3803e8c4d31SAmit Kucheria static int intel_pch_thermal_resume(struct device *device) 3813e8c4d31SAmit Kucheria { 3823e8c4d31SAmit Kucheria struct pci_dev *pdev = to_pci_dev(device); 3833e8c4d31SAmit Kucheria struct pch_thermal_device *ptd = pci_get_drvdata(pdev); 3843e8c4d31SAmit Kucheria 3853e8c4d31SAmit Kucheria return ptd->ops->resume(ptd); 3863e8c4d31SAmit Kucheria } 3873e8c4d31SAmit Kucheria 3883e8c4d31SAmit Kucheria static const struct pci_device_id intel_pch_thermal_id[] = { 3893e8c4d31SAmit Kucheria { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_HSW_1), 3903e8c4d31SAmit Kucheria .driver_data = board_hsw, }, 3913e8c4d31SAmit Kucheria { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_HSW_2), 3923e8c4d31SAmit Kucheria .driver_data = board_hsw, }, 3933e8c4d31SAmit Kucheria { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT), 3943e8c4d31SAmit Kucheria .driver_data = board_wpt, }, 3953e8c4d31SAmit Kucheria { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL), 3963e8c4d31SAmit Kucheria .driver_data = board_skl, }, 3973e8c4d31SAmit Kucheria { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL_H), 3983e8c4d31SAmit Kucheria .driver_data = board_skl, }, 3993e8c4d31SAmit Kucheria { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_CNL), 4003e8c4d31SAmit Kucheria .driver_data = board_cnl, }, 4013e8c4d31SAmit Kucheria { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_CNL_H), 4023e8c4d31SAmit Kucheria .driver_data = board_cnl, }, 4033e8c4d31SAmit Kucheria { 0, }, 4043e8c4d31SAmit Kucheria }; 4053e8c4d31SAmit Kucheria MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id); 4063e8c4d31SAmit Kucheria 4073e8c4d31SAmit Kucheria static const struct dev_pm_ops intel_pch_pm_ops = { 4083e8c4d31SAmit Kucheria .suspend = intel_pch_thermal_suspend, 4093e8c4d31SAmit Kucheria .resume = intel_pch_thermal_resume, 4103e8c4d31SAmit Kucheria }; 4113e8c4d31SAmit Kucheria 4123e8c4d31SAmit Kucheria static struct pci_driver intel_pch_thermal_driver = { 4133e8c4d31SAmit Kucheria .name = "intel_pch_thermal", 4143e8c4d31SAmit Kucheria .id_table = intel_pch_thermal_id, 4153e8c4d31SAmit Kucheria .probe = intel_pch_thermal_probe, 4163e8c4d31SAmit Kucheria .remove = intel_pch_thermal_remove, 4173e8c4d31SAmit Kucheria .driver.pm = &intel_pch_pm_ops, 4183e8c4d31SAmit Kucheria }; 4193e8c4d31SAmit Kucheria 4203e8c4d31SAmit Kucheria module_pci_driver(intel_pch_thermal_driver); 4213e8c4d31SAmit Kucheria 4223e8c4d31SAmit Kucheria MODULE_LICENSE("GPL v2"); 4233e8c4d31SAmit Kucheria MODULE_DESCRIPTION("Intel PCH Thermal driver"); 424