aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2018-04-29 11:08:24 -0400
committerGuenter Roeck <linux@roeck-us.net>2018-04-29 17:21:45 -0400
commit40626a1bf657eef557fcee9e1b8ef5b4f5b56dcd (patch)
tree1737909f99e844f4a09654e589b3975ac0300d34
parent6da6c0db5316275015e8cc2959f12a17584aeb64 (diff)
hwmon: (k10temp) Fix reading critical temperature register
The HTC (Hardware Temperature Control) register has moved for recent chips. Cc: stable@vger.kernel.org # v4.16+ Tested-by: Gabriel Craciunescu <nix.or.die@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/k10temp.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c
index d2cc55e21374..34b5448b00be 100644
--- a/drivers/hwmon/k10temp.c
+++ b/drivers/hwmon/k10temp.c
@@ -63,10 +63,12 @@ static DEFINE_MUTEX(nb_smu_ind_mutex);
63#define NB_CAP_HTC 0x00000400 63#define NB_CAP_HTC 0x00000400
64 64
65/* 65/*
66 * For F15h M60h, functionality of REG_REPORTED_TEMPERATURE 66 * For F15h M60h and M70h, REG_HARDWARE_THERMAL_CONTROL
67 * has been moved to D0F0xBC_xD820_0CA4 [Reported Temperature 67 * and REG_REPORTED_TEMPERATURE have been moved to
68 * Control] 68 * D0F0xBC_xD820_0C64 [Hardware Temperature Control]
69 * D0F0xBC_xD820_0CA4 [Reported Temperature Control]
69 */ 70 */
71#define F15H_M60H_HARDWARE_TEMP_CTRL_OFFSET 0xd8200c64
70#define F15H_M60H_REPORTED_TEMP_CTRL_OFFSET 0xd8200ca4 72#define F15H_M60H_REPORTED_TEMP_CTRL_OFFSET 0xd8200ca4
71 73
72/* F17h M01h Access througn SMN */ 74/* F17h M01h Access througn SMN */
@@ -74,6 +76,7 @@ static DEFINE_MUTEX(nb_smu_ind_mutex);
74 76
75struct k10temp_data { 77struct k10temp_data {
76 struct pci_dev *pdev; 78 struct pci_dev *pdev;
79 void (*read_htcreg)(struct pci_dev *pdev, u32 *regval);
77 void (*read_tempreg)(struct pci_dev *pdev, u32 *regval); 80 void (*read_tempreg)(struct pci_dev *pdev, u32 *regval);
78 int temp_offset; 81 int temp_offset;
79 u32 temp_adjust_mask; 82 u32 temp_adjust_mask;
@@ -98,6 +101,11 @@ static const struct tctl_offset tctl_offset_table[] = {
98 { 0x17, "AMD Ryzen Threadripper 1910", 10000 }, 101 { 0x17, "AMD Ryzen Threadripper 1910", 10000 },
99}; 102};
100 103
104static void read_htcreg_pci(struct pci_dev *pdev, u32 *regval)
105{
106 pci_read_config_dword(pdev, REG_HARDWARE_THERMAL_CONTROL, regval);
107}
108
101static void read_tempreg_pci(struct pci_dev *pdev, u32 *regval) 109static void read_tempreg_pci(struct pci_dev *pdev, u32 *regval)
102{ 110{
103 pci_read_config_dword(pdev, REG_REPORTED_TEMPERATURE, regval); 111 pci_read_config_dword(pdev, REG_REPORTED_TEMPERATURE, regval);
@@ -114,6 +122,12 @@ static void amd_nb_index_read(struct pci_dev *pdev, unsigned int devfn,
114 mutex_unlock(&nb_smu_ind_mutex); 122 mutex_unlock(&nb_smu_ind_mutex);
115} 123}
116 124
125static void read_htcreg_nb_f15(struct pci_dev *pdev, u32 *regval)
126{
127 amd_nb_index_read(pdev, PCI_DEVFN(0, 0), 0xb8,
128 F15H_M60H_HARDWARE_TEMP_CTRL_OFFSET, regval);
129}
130
117static void read_tempreg_nb_f15(struct pci_dev *pdev, u32 *regval) 131static void read_tempreg_nb_f15(struct pci_dev *pdev, u32 *regval)
118{ 132{
119 amd_nb_index_read(pdev, PCI_DEVFN(0, 0), 0xb8, 133 amd_nb_index_read(pdev, PCI_DEVFN(0, 0), 0xb8,
@@ -160,8 +174,7 @@ static ssize_t show_temp_crit(struct device *dev,
160 u32 regval; 174 u32 regval;
161 int value; 175 int value;
162 176
163 pci_read_config_dword(data->pdev, 177 data->read_htcreg(data->pdev, &regval);
164 REG_HARDWARE_THERMAL_CONTROL, &regval);
165 value = ((regval >> 16) & 0x7f) * 500 + 52000; 178 value = ((regval >> 16) & 0x7f) * 500 + 52000;
166 if (show_hyst) 179 if (show_hyst)
167 value -= ((regval >> 24) & 0xf) * 500; 180 value -= ((regval >> 24) & 0xf) * 500;
@@ -181,13 +194,18 @@ static umode_t k10temp_is_visible(struct kobject *kobj,
181 struct pci_dev *pdev = data->pdev; 194 struct pci_dev *pdev = data->pdev;
182 195
183 if (index >= 2) { 196 if (index >= 2) {
184 u32 reg_caps, reg_htc; 197 u32 reg;
198
199 if (!data->read_htcreg)
200 return 0;
185 201
186 pci_read_config_dword(pdev, REG_NORTHBRIDGE_CAPABILITIES, 202 pci_read_config_dword(pdev, REG_NORTHBRIDGE_CAPABILITIES,
187 &reg_caps); 203 &reg);
188 pci_read_config_dword(pdev, REG_HARDWARE_THERMAL_CONTROL, 204 if (!(reg & NB_CAP_HTC))
189 &reg_htc); 205 return 0;
190 if (!(reg_caps & NB_CAP_HTC) || !(reg_htc & HTC_ENABLE)) 206
207 data->read_htcreg(data->pdev, &reg);
208 if (!(reg & HTC_ENABLE))
191 return 0; 209 return 0;
192 } 210 }
193 return attr->mode; 211 return attr->mode;
@@ -268,11 +286,13 @@ static int k10temp_probe(struct pci_dev *pdev,
268 286
269 if (boot_cpu_data.x86 == 0x15 && (boot_cpu_data.x86_model == 0x60 || 287 if (boot_cpu_data.x86 == 0x15 && (boot_cpu_data.x86_model == 0x60 ||
270 boot_cpu_data.x86_model == 0x70)) { 288 boot_cpu_data.x86_model == 0x70)) {
289 data->read_htcreg = read_htcreg_nb_f15;
271 data->read_tempreg = read_tempreg_nb_f15; 290 data->read_tempreg = read_tempreg_nb_f15;
272 } else if (boot_cpu_data.x86 == 0x17) { 291 } else if (boot_cpu_data.x86 == 0x17) {
273 data->temp_adjust_mask = 0x80000; 292 data->temp_adjust_mask = 0x80000;
274 data->read_tempreg = read_tempreg_nb_f17; 293 data->read_tempreg = read_tempreg_nb_f17;
275 } else { 294 } else {
295 data->read_htcreg = read_htcreg_pci;
276 data->read_tempreg = read_tempreg_pci; 296 data->read_tempreg = read_tempreg_pci;
277 } 297 }
278 298