Skip to content

Commit 1e11552

Browse files
vadimp-nvidiagroeck
authored andcommitted
hwmon: (mlxreg-fan) Add support for new flavour of capability register
FAN platform data is common across the various systems, while fan driver should be able to apply only the fan instances relevant to specific system. For example, platform data might contain descriptions for fan1, fan2, ..., fan{n}, while some systems equipped with all 'n' fans, others with less. Also, on some systems fan drawer can be equipped with several tachometers and on others only with one. For detection of the real number of equipped drawers and tachometers special capability registers are used. These registers used to indicate presence of drawers and tachometers through the bitmap. For some new big modular systems this register will provide presence data by counter. Use slot parameter to distinct whether capability register contains bitmask or counter. Signed-off-by: Vadim Pasternak <vadimp@nvidia.com> Link: https://lore.kernel.org/r/20250113084859.27064-3-vadimp@nvidia.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent c02e464 commit 1e11552

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

drivers/hwmon/mlxreg-fan.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ struct mlxreg_fan;
6363
* @reg: register offset;
6464
* @mask: fault mask;
6565
* @prsnt: present register offset;
66+
* @shift: tacho presence bit shift;
6667
*/
6768
struct mlxreg_fan_tacho {
6869
bool connected;
6970
u32 reg;
7071
u32 mask;
7172
u32 prsnt;
73+
u32 shift;
7274
};
7375

7476
/*
@@ -143,8 +145,10 @@ mlxreg_fan_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
143145
/*
144146
* Map channel to presence bit - drawer can be equipped with
145147
* one or few FANs, while presence is indicated per drawer.
148+
* Shift channel value if necessary to align with register value.
146149
*/
147-
if (BIT(channel / fan->tachos_per_drwr) & regval) {
150+
if (BIT(rol32(channel, tacho->shift) / fan->tachos_per_drwr) &
151+
regval) {
148152
/* FAN is not connected - return zero for FAN speed. */
149153
*val = 0;
150154
return 0;
@@ -408,7 +412,7 @@ static int mlxreg_fan_connect_verify(struct mlxreg_fan *fan,
408412
return err;
409413
}
410414

411-
return !!(regval & data->bit);
415+
return data->slot ? (data->slot <= regval ? 1 : 0) : !!(regval & data->bit);
412416
}
413417

414418
static int mlxreg_pwm_connect_verify(struct mlxreg_fan *fan,
@@ -545,7 +549,15 @@ static int mlxreg_fan_config(struct mlxreg_fan *fan,
545549
return err;
546550
}
547551

548-
drwr_avail = hweight32(regval);
552+
/*
553+
* The number of drawers could be specified in registers by counters for newer
554+
* systems, or by bitmasks for older systems. In case the data is provided by
555+
* counter, it is indicated through 'version' field.
556+
*/
557+
if (pdata->version)
558+
drwr_avail = regval;
559+
else
560+
drwr_avail = hweight32(regval);
549561
if (!tacho_avail || !drwr_avail || tacho_avail < drwr_avail) {
550562
dev_err(fan->dev, "Configuration is invalid: drawers num %d tachos num %d\n",
551563
drwr_avail, tacho_avail);

0 commit comments

Comments
 (0)