Skip to content

Commit 13558a2

Browse files
thekhalifagroeck
authored andcommitted
hwmon: (nct6775) Fix IN scaling factors for 6798/6799
Scaling for VTT/VIN5/VIN6 registers were based on prior chips * Split scaling factors for 6798/6799 and assign at probe() * Pass them through driver data to sysfs functions Tested on nct6799 with old/new input/min/max Fixes: 0599682 ("hwmon: (nct6775) Add support for NCT6798D") Signed-off-by: Ahmad Khalifa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 957961b commit 13558a2

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

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.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];

0 commit comments

Comments
 (0)