summaryrefslogtreecommitdiff
path: root/drivers/hwmon/mlxreg-fan.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2021-04-27 00:59:21 +0300
committerLinus Torvalds <torvalds@linux-foundation.org>2021-04-27 00:59:21 +0300
commit47080f2286110c371b9cf75ac7b34a6f2f1cf4ba (patch)
treefdc9cf3da77cffd1add8a9e7c44df988291837c7 /drivers/hwmon/mlxreg-fan.c
parent55ba0fe059a577fa08f23223991b24564962620f (diff)
parent9049572fb145746725b198a19e27fa2671b80448 (diff)
downloadlinux-47080f2286110c371b9cf75ac7b34a6f2f1cf4ba.tar.xz
Merge tag 'hwmon-for-v5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon updates from Guenter Roeck: "The most notable change is the removal of the amd_energy driver. It was rendered all but unusable by making its attributes privileged-only to work around a security issue. A suggested remedy was rejected by AMD, so the only real solution was to remove the driver. For the future, we'll have to make sure that no privileged-access-only drivers are accepted into the hwmon subsystem in the first place. The hwmon ABI document was updated accordingly. Other changes: PMBus drivers: - Added driver for MAX15301 - Added driver for BluTek BPA-RS600 - Added driver for fsp-3y PSUs and PDUs - Added driver for Infineon IR36021 - Added driver for ST STPDDC60 - Added support for TI TPS53676 to tps53679 driver - Introduced PMBUS symbol namespace. This was made necessary by a suggestion to use its exported functions from outside the hwmon subsystem. - Minor improvements and bug fixes New drivers: - Driver for NZXT Kraken X42/X52/X62/X72 Driver enhancements: - Added support for Intel D5005 to intel-m10-bmc-hwmon driver - Added support for NCT6686D to nct6683 driver Other: - Converted sch5627 and amd9240 drivers to hwmon_device_register_with_info() - Added support for fan drawers capability and present registers to mlxreg-fan driver - Added Dell Latitude E7440 to fan control whitelist in dell-smm driver - Replaced snprintf in show functions with sysfs_emit. Done with coccinelle script for all drivers to preempt endless per-driver submissions of the same change. - Use kobj_to_dev(). Another coccinelle based change to preempt endless per-driver submissions of the same change. - Various minor fixes and improvements" * tag 'hwmon-for-v5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (38 commits) hwmon: Remove amd_energy driver hwmon: Clarify scope of attribute access hwmon: (pmbus) Introduce PMBUS symbol namespace hwmon: (pmbus) Add pmbus driver for MAX15301 hwmon: (sch5627) Remove unnecessary error path hwmon: (sch5627) Use devres function hwmon: (pmbus/pxe1610) don't bail out when not all pages are active hwmon: Add driver for fsp-3y PSUs and PDUs hwmon: (intel-m10-bmc-hwmon) add sensor support of Intel D5005 card hwmon: (sch5627) Split sch5627_update_device() hwmon: (sch5627) Convert to hwmon_device_register_with_info() hwmon: (nct6683) remove useless function hwmon: (dell-smm) Add Dell Latitude E7440 to fan control whitelist MAINTAINERS: Add keyword pattern for hwmon registration functions hwmon: (mlxreg-fan) Add support for fan drawers capability and present registers hwmon: (pmbus/tps53679) Add support for TI TPS53676 dt-bindings: Add trivial device entry for TPS53676 hwmon: (ftsteutates) Rudimentary typo fixes hwmon: (pmbus) Add driver for BluTek BPA-RS600 dt-bindings: Add vendor prefix and trivial device for BluTek BPA-RS600 ...
Diffstat (limited to 'drivers/hwmon/mlxreg-fan.c')
-rw-r--r--drivers/hwmon/mlxreg-fan.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/drivers/hwmon/mlxreg-fan.c b/drivers/hwmon/mlxreg-fan.c
index ed8d59d4eecb..116681fde33d 100644
--- a/drivers/hwmon/mlxreg-fan.c
+++ b/drivers/hwmon/mlxreg-fan.c
@@ -67,11 +67,13 @@
* @connected: indicates if tachometer is connected;
* @reg: register offset;
* @mask: fault mask;
+ * @prsnt: present register offset;
*/
struct mlxreg_fan_tacho {
bool connected;
u32 reg;
u32 mask;
+ u32 prsnt;
};
/*
@@ -92,6 +94,7 @@ struct mlxreg_fan_pwm {
* @regmap: register map of parent device;
* @tacho: tachometer data;
* @pwm: PWM data;
+ * @tachos_per_drwr - number of tachometers per drawer;
* @samples: minimum allowed samples per pulse;
* @divider: divider value for tachometer RPM calculation;
* @cooling: cooling device levels;
@@ -103,6 +106,7 @@ struct mlxreg_fan {
struct mlxreg_core_platform_data *pdata;
struct mlxreg_fan_tacho tacho[MLXREG_FAN_MAX_TACHO];
struct mlxreg_fan_pwm pwm;
+ int tachos_per_drwr;
int samples;
int divider;
u8 cooling_levels[MLXREG_FAN_MAX_STATE + 1];
@@ -123,6 +127,26 @@ mlxreg_fan_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
tacho = &fan->tacho[channel];
switch (attr) {
case hwmon_fan_input:
+ /*
+ * Check FAN presence: FAN related bit in presence register is one,
+ * if FAN is physically connected, zero - otherwise.
+ */
+ if (tacho->prsnt && fan->tachos_per_drwr) {
+ err = regmap_read(fan->regmap, tacho->prsnt, &regval);
+ if (err)
+ return err;
+
+ /*
+ * Map channel to presence bit - drawer can be equipped with
+ * one or few FANs, while presence is indicated per drawer.
+ */
+ if (BIT(channel / fan->tachos_per_drwr) & regval) {
+ /* FAN is not connected - return zero for FAN speed. */
+ *val = 0;
+ return 0;
+ }
+ }
+
err = regmap_read(fan->regmap, tacho->reg, &regval);
if (err)
return err;
@@ -389,8 +413,8 @@ static int mlxreg_fan_config(struct mlxreg_fan *fan,
struct mlxreg_core_platform_data *pdata)
{
struct mlxreg_core_data *data = pdata->data;
+ int tacho_num = 0, tacho_avail = 0, i;
bool configured = false;
- int tacho_num = 0, i;
int err;
fan->samples = MLXREG_FAN_TACHO_SAMPLES_PER_PULSE_DEF;
@@ -415,7 +439,9 @@ static int mlxreg_fan_config(struct mlxreg_fan *fan,
fan->tacho[tacho_num].reg = data->reg;
fan->tacho[tacho_num].mask = data->mask;
+ fan->tacho[tacho_num].prsnt = data->reg_prsnt;
fan->tacho[tacho_num++].connected = true;
+ tacho_avail++;
} else if (strnstr(data->label, "pwm", sizeof(data->label))) {
if (fan->pwm.connected) {
dev_err(fan->dev, "duplicate pwm entry: %s\n",
@@ -453,6 +479,29 @@ static int mlxreg_fan_config(struct mlxreg_fan *fan,
}
}
+ if (pdata->capability) {
+ int drwr_avail;
+ u32 regval;
+
+ /* Obtain the number of FAN drawers, supported by system. */
+ err = regmap_read(fan->regmap, pdata->capability, &regval);
+ if (err) {
+ dev_err(fan->dev, "Failed to query capability register 0x%08x\n",
+ pdata->capability);
+ return err;
+ }
+
+ drwr_avail = hweight32(regval);
+ if (!tacho_avail || !drwr_avail || tacho_avail < drwr_avail) {
+ dev_err(fan->dev, "Configuration is invalid: drawers num %d tachos num %d\n",
+ drwr_avail, tacho_avail);
+ return -EINVAL;
+ }
+
+ /* Set the number of tachometers per one drawer. */
+ fan->tachos_per_drwr = tacho_avail / drwr_avail;
+ }
+
/* Init cooling levels per PWM state. */
for (i = 0; i < MLXREG_FAN_SPEED_MIN_LEVEL; i++)
fan->cooling_levels[i] = MLXREG_FAN_SPEED_MIN_LEVEL;