Skip to content

Commit

Permalink
Merge pull request #4 from neg2led/minrpm-fix
Browse files Browse the repository at this point in the history
Minimum RPM setting change.
  • Loading branch information
neggles authored Aug 4, 2021
2 parents 4c668b0 + 80f7241 commit 78d3be3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dkms.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PACKAGE_NAME="cm4io-fan"
PACKAGE_VERSION="0.1.0"
PACKAGE_VERSION="0.1.1"
BUILD_EXCLUSIVE_KERNEL="^5.[10-].*"

MAKE="make"
Expand Down
17 changes: 12 additions & 5 deletions emc2301/emc2301.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* number of edges equals (poles * 2 + 1).
*/
#define FAN_RPM_FACTOR 3932160
#define FAN_TACH_MULTIPLIER 1

#define TACH_HIGH_MASK GENMASK(12, 5)
#define TACH_LOW_MASK GENMASK(4, 0)
Expand Down Expand Up @@ -95,7 +96,7 @@ static int emc2301_read_fan_rpm(struct device *dev, int channel, long *val)

channel_tach = emc2301_read_fan_tach(dev, channel);

fan_rpm = (FAN_RPM_FACTOR * 2) / channel_tach;
fan_rpm = (FAN_RPM_FACTOR * FAN_TACH_MULTIPLIER) / channel_tach;
*val = fan_rpm;

return 0;
Expand All @@ -113,7 +114,7 @@ static int emc2301_set_fan_rpm(struct emc2301_data *devdata, int channel, long t

channel_reg = 0x3c + (channel * 10);

target_tach = (FAN_RPM_FACTOR * 2) / target_rpm;
target_tach = (FAN_RPM_FACTOR * FAN_TACH_MULTIPLIER) / target_rpm;
dev_dbg(devdata->dev, "RPM %ld requested, target tach is %ld\n", target_rpm, target_tach);

rpm_high = (target_tach & TACH_HIGH_MASK) >> 5;
Expand Down Expand Up @@ -311,12 +312,18 @@ static int emc2301_enable_rpm_control(struct emc2301_data *data, u16 fan_dev, bo
u8 fan_config_reg_val;
int ret = 0;

// get current fan config reg value
fan_config_reg_addr = 0x32 + (fan_dev * 0x10);

fan_config_reg_val = i2c_smbus_read_byte_data(data->i2c, fan_config_reg_addr);

// update config reg to enable/disable control as requested
if (enable) {
// set ENAx to enable drive
fan_config_reg_val |= (1 << 7);
// clear RNGx to set minRPM=500
fan_config_reg_val &= ~(0b11 << 5);
} else {
// clear ENAx
fan_config_reg_val &= ~(1 << 7);
}

Expand Down Expand Up @@ -435,8 +442,8 @@ static int emc2301_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id
for(i=0; i<data->num_fans; i++) {
channel_reg = EMC230X_REG_MINTACH + (i * 10);
regval = i2c_smbus_read_byte_data(i2c, channel_reg);
min_tach = (FAN_RPM_FACTOR * 2) / (regval << 5);
data->minimum_rpm[i] = (FAN_RPM_FACTOR * 2) / min_tach;
min_tach = (FAN_RPM_FACTOR * FAN_TACH_MULTIPLIER) / (regval << 5);
data->minimum_rpm[i] = (FAN_RPM_FACTOR * FAN_TACH_MULTIPLIER) / min_tach;
dev_info(&i2c->dev, "Channel %d minimum RPM is %d", i, data->minimum_rpm[i]);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ datestamp=`date -I`

# version/name strings
DRV_NAME="cm4io-fan"
DRV_VERSION="0.1.0-2"
DRV_VERSION="0.1.1"
DRV_DIR="/usr/src/${DRV_NAME}-${DRV_VERSION}"

# check kernel arch
Expand Down

0 comments on commit 78d3be3

Please sign in to comment.