1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * i5500_temp - Driver for Intel 5500/5520/X58 chipset thermal sensor
8 #include <linux/bitops.h>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/slab.h>
12 #include <linux/jiffies.h>
13 #include <linux/device.h>
14 #include <linux/pci.h>
15 #include <linux/hwmon.h>
16 #include <linux/err.h>
17 #include <linux/mutex.h>
19 /* Register definitions from datasheet */
20 #define REG_TSTHRCATA 0xE2
21 #define REG_TSCTRL 0xE8
22 #define REG_TSTHRRPEX 0xEB
23 #define REG_TSTHRLO 0xEC
24 #define REG_TSTHRHI 0xEE
25 #define REG_CTHINT 0xF0
26 #define REG_TSFSC 0xF3
27 #define REG_CTSTS 0xF4
28 #define REG_TSTHRRQPI 0xF5
29 #define REG_CTCTRL 0xF7
30 #define REG_TSTIMER 0xF8
32 static int i5500_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
35 struct pci_dev *pdev = to_pci_dev(dev->parent);
43 /* Sensor resolution : 0.5 degree C */
44 case hwmon_temp_input:
45 pci_read_config_word(pdev, REG_TSTHRHI, &tsthr);
46 pci_read_config_byte(pdev, REG_TSFSC, &tsfsc);
47 *val = (tsthr - tsfsc) * 500;
50 pci_read_config_word(pdev, REG_TSTHRHI, &tsthr);
53 case hwmon_temp_max_hyst:
54 pci_read_config_word(pdev, REG_TSTHRLO, &tsthr);
58 pci_read_config_word(pdev, REG_TSTHRCATA, &tsthr);
61 case hwmon_temp_max_alarm:
62 pci_read_config_byte(pdev, REG_CTSTS, &ctsts);
63 *val = !!(ctsts & BIT(1));
65 case hwmon_temp_crit_alarm:
66 pci_read_config_byte(pdev, REG_CTSTS, &ctsts);
67 *val = !!(ctsts & BIT(0));
80 static const struct hwmon_ops i5500_ops = {
85 static const struct hwmon_channel_info * const i5500_info[] = {
86 HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ),
87 HWMON_CHANNEL_INFO(temp,
88 HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_CRIT |
89 HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM
94 static const struct hwmon_chip_info i5500_chip_info = {
99 static const struct pci_device_id i5500_temp_ids[] = {
100 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x3438) },
104 MODULE_DEVICE_TABLE(pci, i5500_temp_ids);
106 static int i5500_temp_probe(struct pci_dev *pdev,
107 const struct pci_device_id *id)
110 struct device *hwmon_dev;
114 err = pcim_enable_device(pdev);
116 dev_err(&pdev->dev, "Failed to enable device\n");
120 pci_read_config_byte(pdev, REG_TSFSC, &tsfsc);
121 pci_read_config_dword(pdev, REG_TSTIMER, &tstimer);
122 if (tsfsc == 0x7F && tstimer == 0x07D30D40) {
123 dev_notice(&pdev->dev, "Sensor seems to be disabled\n");
127 hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev, "intel5500", NULL,
128 &i5500_chip_info, NULL);
129 return PTR_ERR_OR_ZERO(hwmon_dev);
132 static struct pci_driver i5500_temp_driver = {
133 .name = "i5500_temp",
134 .id_table = i5500_temp_ids,
135 .probe = i5500_temp_probe,
138 module_pci_driver(i5500_temp_driver);
141 MODULE_DESCRIPTION("Intel 5500/5520/X58 chipset thermal sensor driver");
142 MODULE_LICENSE("GPL");