Skip to content

Commit 2f4effd

Browse files
committed
Merge tag 'hwmon-for-v6.5-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon fixes from Guenter Roeck: - k10temp: Display negative temperatures for industrial processors - pmbus core: Fix deadlock, NULL pointer dereference, and chip enable detection - nct7802: Do not display PECI1 temperature if disabled - nct6775: Fix IN scaling factors and feature detection for NCT6798/6799 - oxp-sensors: Fix race condition during device attribute creation - aquacomputer_d5next: Fix incorrect PWM value readout * tag 'hwmon-for-v6.5-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: hwmon: (k10temp) Enable AMD3255 Proc to show negative temperature hwmon: (pmbus_core) Fix Deadlock in pmbus_regulator_get_status hwmon: (pmbus_core) Fix NULL pointer dereference hwmon: (pmbus_core) Fix pmbus_is_enabled() hwmon: (nct7802) Fix for temp6 (PECI1) processed even if PECI1 disabled hwmon: (nct6775) Fix IN scaling factors for 6798/6799 hwmon: (oxp-sensors) Move tt_toggle attribute to dev_groups hwmon: (aquacomputer_d5next) Fix incorrect PWM value readout hwmon: (nct6775) Fix register for nct6799
2 parents c06f909 + e146503 commit 2f4effd

File tree

8 files changed

+76
-34
lines changed

8 files changed

+76
-34
lines changed

drivers/hwmon/aquacomputer_d5next.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
10271027
if (ret < 0)
10281028
return ret;
10291029

1030-
*val = aqc_percent_to_pwm(ret);
1030+
*val = aqc_percent_to_pwm(*val);
10311031
break;
10321032
}
10331033
break;

drivers/hwmon/k10temp.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ static DEFINE_MUTEX(nb_smu_ind_mutex);
7777
#define ZEN_CUR_TEMP_RANGE_SEL_MASK BIT(19)
7878
#define ZEN_CUR_TEMP_TJ_SEL_MASK GENMASK(17, 16)
7979

80+
/*
81+
* AMD's Industrial processor 3255 supports temperature from -40 deg to 105 deg Celsius.
82+
* Use the model name to identify 3255 CPUs and set a flag to display negative temperature.
83+
* Do not round off to zero for negative Tctl or Tdie values if the flag is set
84+
*/
85+
#define AMD_I3255_STR "3255"
86+
8087
struct k10temp_data {
8188
struct pci_dev *pdev;
8289
void (*read_htcreg)(struct pci_dev *pdev, u32 *regval);
@@ -86,6 +93,7 @@ struct k10temp_data {
8693
u32 show_temp;
8794
bool is_zen;
8895
u32 ccd_offset;
96+
bool disp_negative;
8997
};
9098

9199
#define TCTL_BIT 0
@@ -204,12 +212,12 @@ static int k10temp_read_temp(struct device *dev, u32 attr, int channel,
204212
switch (channel) {
205213
case 0: /* Tctl */
206214
*val = get_raw_temp(data);
207-
if (*val < 0)
215+
if (*val < 0 && !data->disp_negative)
208216
*val = 0;
209217
break;
210218
case 1: /* Tdie */
211219
*val = get_raw_temp(data) - data->temp_offset;
212-
if (*val < 0)
220+
if (*val < 0 && !data->disp_negative)
213221
*val = 0;
214222
break;
215223
case 2 ... 13: /* Tccd{1-12} */
@@ -405,6 +413,11 @@ static int k10temp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
405413
data->pdev = pdev;
406414
data->show_temp |= BIT(TCTL_BIT); /* Always show Tctl */
407415

416+
if (boot_cpu_data.x86 == 0x17 &&
417+
strstr(boot_cpu_data.x86_model_id, AMD_I3255_STR)) {
418+
data->disp_negative = true;
419+
}
420+
408421
if (boot_cpu_data.x86 == 0x15 &&
409422
((boot_cpu_data.x86_model & 0xf0) == 0x60 ||
410423
(boot_cpu_data.x86_model & 0xf0) == 0x70)) {

drivers/hwmon/nct6775-core.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -955,14 +955,25 @@ static const u16 scale_in[15] = {
955955
800, 800
956956
};
957957

958-
static inline long in_from_reg(u8 reg, u8 nr)
958+
/*
959+
* NCT6798 scaling:
960+
* CPUVC, IN1, AVSB, 3VCC, IN0, IN8, IN4, 3VSB, VBAT, VTT, IN5, IN6, IN2,
961+
* IN3, IN7
962+
* Additional scales to be added later: IN9 (800), VHIF (1600)
963+
*/
964+
static const u16 scale_in_6798[15] = {
965+
800, 800, 1600, 1600, 800, 800, 800, 1600, 1600, 1600, 1600, 1600, 800,
966+
800, 800
967+
};
968+
969+
static inline long in_from_reg(u8 reg, u8 nr, const u16 *scales)
959970
{
960-
return DIV_ROUND_CLOSEST(reg * scale_in[nr], 100);
971+
return DIV_ROUND_CLOSEST(reg * scales[nr], 100);
961972
}
962973

963-
static inline u8 in_to_reg(u32 val, u8 nr)
974+
static inline u8 in_to_reg(u32 val, u8 nr, const u16 *scales)
964975
{
965-
return clamp_val(DIV_ROUND_CLOSEST(val * 100, scale_in[nr]), 0, 255);
976+
return clamp_val(DIV_ROUND_CLOSEST(val * 100, scales[nr]), 0, 255);
966977
}
967978

968979
/* TSI temperatures are in 8.3 format */
@@ -1673,7 +1684,8 @@ show_in_reg(struct device *dev, struct device_attribute *attr, char *buf)
16731684
if (IS_ERR(data))
16741685
return PTR_ERR(data);
16751686

1676-
return sprintf(buf, "%ld\n", in_from_reg(data->in[nr][index], nr));
1687+
return sprintf(buf, "%ld\n",
1688+
in_from_reg(data->in[nr][index], nr, data->scale_in));
16771689
}
16781690

16791691
static ssize_t
@@ -1691,7 +1703,7 @@ store_in_reg(struct device *dev, struct device_attribute *attr, const char *buf,
16911703
if (err < 0)
16921704
return err;
16931705
mutex_lock(&data->update_lock);
1694-
data->in[nr][index] = in_to_reg(val, nr);
1706+
data->in[nr][index] = in_to_reg(val, nr, data->scale_in);
16951707
err = nct6775_write_value(data, data->REG_IN_MINMAX[index - 1][nr], data->in[nr][index]);
16961708
mutex_unlock(&data->update_lock);
16971709
return err ? : count;
@@ -3462,6 +3474,7 @@ int nct6775_probe(struct device *dev, struct nct6775_data *data,
34623474
mutex_init(&data->update_lock);
34633475
data->name = nct6775_device_names[data->kind];
34643476
data->bank = 0xff; /* Force initial bank selection */
3477+
data->scale_in = scale_in;
34653478

34663479
switch (data->kind) {
34673480
case nct6106:
@@ -3977,6 +3990,9 @@ int nct6775_probe(struct device *dev, struct nct6775_data *data,
39773990
break;
39783991
}
39793992

3993+
if (data->kind == nct6798 || data->kind == nct6799)
3994+
data->scale_in = scale_in_6798;
3995+
39803996
reg_temp = NCT6779_REG_TEMP;
39813997
num_reg_temp = ARRAY_SIZE(NCT6779_REG_TEMP);
39823998
if (data->kind == nct6791) {

drivers/hwmon/nct6775-platform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ nct6775_check_fan_inputs(struct nct6775_data *data, struct nct6775_sio_data *sio
586586
int creb;
587587
int cred;
588588

589-
cre6 = sio_data->sio_inb(sio_data, 0xe0);
589+
cre6 = sio_data->sio_inb(sio_data, 0xe6);
590590

591591
sio_data->sio_select(sio_data, NCT6775_LD_12);
592592
cre0 = sio_data->sio_inb(sio_data, 0xe0);

drivers/hwmon/nct6775.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct nct6775_data {
9898
u8 bank; /* current register bank */
9999
u8 in_num; /* number of in inputs we have */
100100
u8 in[15][3]; /* [0]=in, [1]=in_max, [2]=in_min */
101+
const u16 *scale_in; /* internal scaling factors */
101102
unsigned int rpm[NUM_FAN];
102103
u16 fan_min[NUM_FAN];
103104
u8 fan_pulses[NUM_FAN];

drivers/hwmon/nct7802.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ static umode_t nct7802_temp_is_visible(struct kobject *kobj,
725725
if (index >= 38 && index < 46 && !(reg & 0x01)) /* PECI 0 */
726726
return 0;
727727

728-
if (index >= 0x46 && (!(reg & 0x02))) /* PECI 1 */
728+
if (index >= 46 && !(reg & 0x02)) /* PECI 1 */
729729
return 0;
730730

731731
return attr->mode;

drivers/hwmon/oxp-sensors.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,20 @@ static int tt_toggle_disable(void)
220220
}
221221

222222
/* Callbacks for turbo toggle attribute */
223+
static umode_t tt_toggle_is_visible(struct kobject *kobj,
224+
struct attribute *attr, int n)
225+
{
226+
switch (board) {
227+
case aok_zoe_a1:
228+
case oxp_mini_amd_a07:
229+
case oxp_mini_amd_pro:
230+
return attr->mode;
231+
default:
232+
break;
233+
}
234+
return 0;
235+
}
236+
223237
static ssize_t tt_toggle_store(struct device *dev,
224238
struct device_attribute *attr, const char *buf,
225239
size_t count)
@@ -396,7 +410,15 @@ static struct attribute *oxp_ec_attrs[] = {
396410
NULL
397411
};
398412

399-
ATTRIBUTE_GROUPS(oxp_ec);
413+
static struct attribute_group oxp_ec_attribute_group = {
414+
.is_visible = tt_toggle_is_visible,
415+
.attrs = oxp_ec_attrs,
416+
};
417+
418+
static const struct attribute_group *oxp_ec_groups[] = {
419+
&oxp_ec_attribute_group,
420+
NULL
421+
};
400422

401423
static const struct hwmon_ops oxp_ec_hwmon_ops = {
402424
.is_visible = oxp_ec_hwmon_is_visible,
@@ -415,7 +437,6 @@ static int oxp_platform_probe(struct platform_device *pdev)
415437
const struct dmi_system_id *dmi_entry;
416438
struct device *dev = &pdev->dev;
417439
struct device *hwdev;
418-
int ret;
419440

420441
/*
421442
* Have to check for AMD processor here because DMI strings are the
@@ -430,18 +451,6 @@ static int oxp_platform_probe(struct platform_device *pdev)
430451

431452
board = (enum oxp_board)(unsigned long)dmi_entry->driver_data;
432453

433-
switch (board) {
434-
case aok_zoe_a1:
435-
case oxp_mini_amd_a07:
436-
case oxp_mini_amd_pro:
437-
ret = devm_device_add_groups(dev, oxp_ec_groups);
438-
if (ret)
439-
return ret;
440-
break;
441-
default:
442-
break;
443-
}
444-
445454
hwdev = devm_hwmon_device_register_with_info(dev, "oxpec", NULL,
446455
&oxp_ec_chip_info, NULL);
447456

@@ -451,6 +460,7 @@ static int oxp_platform_probe(struct platform_device *pdev)
451460
static struct platform_driver oxp_platform_driver = {
452461
.driver = {
453462
.name = "oxp-platform",
463+
.dev_groups = oxp_ec_groups,
454464
},
455465
.probe = oxp_platform_probe,
456466
};

drivers/hwmon/pmbus/pmbus_core.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,9 +2745,8 @@ static const struct pmbus_status_category __maybe_unused pmbus_status_flag_map[]
27452745
},
27462746
};
27472747

2748-
static int _pmbus_is_enabled(struct device *dev, u8 page)
2748+
static int _pmbus_is_enabled(struct i2c_client *client, u8 page)
27492749
{
2750-
struct i2c_client *client = to_i2c_client(dev->parent);
27512750
int ret;
27522751

27532752
ret = _pmbus_read_byte_data(client, page, PMBUS_OPERATION);
@@ -2758,17 +2757,16 @@ static int _pmbus_is_enabled(struct device *dev, u8 page)
27582757
return !!(ret & PB_OPERATION_CONTROL_ON);
27592758
}
27602759

2761-
static int __maybe_unused pmbus_is_enabled(struct device *dev, u8 page)
2760+
static int __maybe_unused pmbus_is_enabled(struct i2c_client *client, u8 page)
27622761
{
2763-
struct i2c_client *client = to_i2c_client(dev->parent);
27642762
struct pmbus_data *data = i2c_get_clientdata(client);
27652763
int ret;
27662764

27672765
mutex_lock(&data->update_lock);
2768-
ret = _pmbus_is_enabled(dev, page);
2766+
ret = _pmbus_is_enabled(client, page);
27692767
mutex_unlock(&data->update_lock);
27702768

2771-
return !!(ret & PB_OPERATION_CONTROL_ON);
2769+
return ret;
27722770
}
27732771

27742772
#define to_dev_attr(_dev_attr) \
@@ -2844,7 +2842,7 @@ static int _pmbus_get_flags(struct pmbus_data *data, u8 page, unsigned int *flag
28442842
if (status < 0)
28452843
return status;
28462844

2847-
if (_pmbus_is_enabled(dev, page)) {
2845+
if (_pmbus_is_enabled(client, page)) {
28482846
if (status & PB_STATUS_OFF) {
28492847
*flags |= REGULATOR_ERROR_FAIL;
28502848
*event |= REGULATOR_EVENT_FAIL;
@@ -2898,7 +2896,10 @@ static int __maybe_unused pmbus_get_flags(struct pmbus_data *data, u8 page, unsi
28982896
#if IS_ENABLED(CONFIG_REGULATOR)
28992897
static int pmbus_regulator_is_enabled(struct regulator_dev *rdev)
29002898
{
2901-
return pmbus_is_enabled(rdev_get_dev(rdev), rdev_get_id(rdev));
2899+
struct device *dev = rdev_get_dev(rdev);
2900+
struct i2c_client *client = to_i2c_client(dev->parent);
2901+
2902+
return pmbus_is_enabled(client, rdev_get_id(rdev));
29022903
}
29032904

29042905
static int _pmbus_regulator_on_off(struct regulator_dev *rdev, bool enable)
@@ -2945,6 +2946,7 @@ static int pmbus_regulator_get_status(struct regulator_dev *rdev)
29452946
struct pmbus_data *data = i2c_get_clientdata(client);
29462947
u8 page = rdev_get_id(rdev);
29472948
int status, ret;
2949+
int event;
29482950

29492951
mutex_lock(&data->update_lock);
29502952
status = pmbus_get_status(client, page, PMBUS_STATUS_WORD);
@@ -2964,7 +2966,7 @@ static int pmbus_regulator_get_status(struct regulator_dev *rdev)
29642966
goto unlock;
29652967
}
29662968

2967-
ret = pmbus_regulator_get_error_flags(rdev, &status);
2969+
ret = _pmbus_get_flags(data, rdev_get_id(rdev), &status, &event, false);
29682970
if (ret)
29692971
goto unlock;
29702972

0 commit comments

Comments
 (0)