From 6f9acee89b0182b4cd2bbb13c153f25ecde64074 Mon Sep 17 00:00:00 2001 From: Roy Lee Date: Fri, 14 Aug 2020 01:50:31 +0800 Subject: [PATCH] [device][as7816-64x] Update fan speed reading. (#5102) Original converting from register is wrong, it makes the fan speed much higher than it is. Change the way fan speed is calculated from CPLD. Signed-off-by: roy_lee --- .../as7816-64x/modules/x86-64-accton-as7816-64x-fan.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-fan.c b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-fan.c index 3de2c200e1..2cd85c43a9 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-fan.c +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-fan.c @@ -176,7 +176,6 @@ static struct attribute *as7816_64x_fan_attributes[] = { #define FAN_DUTY_CYCLE_REG_MASK 0xF #define FAN_MAX_DUTY_CYCLE 100 -#define FAN_REG_VAL_TO_SPEED_RPM_STEP 100 static int as7816_64x_fan_read_value(struct i2c_client *client, u8 reg) { @@ -220,7 +219,14 @@ static u8 duty_cycle_to_reg_val(u8 duty_cycle) static u32 reg_val_to_speed_rpm(u8 reg_val) { - return (u32)reg_val * FAN_REG_VAL_TO_SPEED_RPM_STEP; + if (reg_val == 0 || reg_val == 255) { + return 0; + } else { + u64 f, dv; + dv = 2 * 2 * 40960 * (u64)(255 - reg_val); + f = 60000000000 / dv; + return (u32)f; + } } static u8 reg_val_to_direction(u8 reg_val, enum fan_id id)