Skip to content

Commit cc66126

Browse files
yghannambp3tk0v
authored andcommitted
hwmon: (k10temp) Define a helper function to read CCD temperature
The CCD temperature register is read in two places. These reads are done using an AMD SMN access, and a number of parameters are needed for the operation. Move the SMN access and parameter gathering into a helper function in order to simplify the code flow. This also has a benefit of centralizing the hardware register access in a single place in case fixes or special decoding is required. Signed-off-by: Yazen Ghannam <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Mario Limonciello <[email protected]> Acked-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent dc52439 commit cc66126

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

drivers/hwmon/k10temp.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ static void read_tempreg_nb_zen(struct pci_dev *pdev, u32 *regval)
158158
*regval = 0;
159159
}
160160

161+
static int read_ccd_temp_reg(struct k10temp_data *data, int ccd, u32 *regval)
162+
{
163+
u16 node_id = amd_pci_dev_to_node_id(data->pdev);
164+
165+
return amd_smn_read(node_id, ZEN_CCD_TEMP(data->ccd_offset, ccd), regval);
166+
}
167+
161168
static long get_raw_temp(struct k10temp_data *data)
162169
{
163170
u32 regval;
@@ -223,9 +230,7 @@ static int k10temp_read_temp(struct device *dev, u32 attr, int channel,
223230
*val = 0;
224231
break;
225232
case 2 ... 13: /* Tccd{1-12} */
226-
ret = amd_smn_read(amd_pci_dev_to_node_id(data->pdev),
227-
ZEN_CCD_TEMP(data->ccd_offset, channel - 2),
228-
&regval);
233+
ret = read_ccd_temp_reg(data, channel - 2, &regval);
229234

230235
if (ret)
231236
return ret;
@@ -397,8 +402,7 @@ static void k10temp_get_ccd_support(struct pci_dev *pdev,
397402
* the register value. And this will incorrectly pass the TEMP_VALID
398403
* bit check.
399404
*/
400-
if (amd_smn_read(amd_pci_dev_to_node_id(pdev),
401-
ZEN_CCD_TEMP(data->ccd_offset, i), &regval))
405+
if (read_ccd_temp_reg(data, i, &regval))
402406
continue;
403407

404408
if (regval & ZEN_CCD_TEMP_VALID)

0 commit comments

Comments
 (0)