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