Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix read lm75 thermal sensors issue #3285

Merged
merged 15 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ class ThermalUtil(object):
THERMAL_NUM_4_IDX: ['15', '4b'],
}
thermal_sysfspath ={
THERMAL_NUM_1_IDX: ["/sys/bus/i2c/drivers/lm75/15-0048/hwmon/hwmon2/temp1_input"],
THERMAL_NUM_2_IDX: ["/sys/bus/i2c/drivers/lm75/15-0049/hwmon/hwmon3/temp1_input"],
THERMAL_NUM_3_IDX: ["/sys/bus/i2c/drivers/lm75/15-004a/hwmon/hwmon4/temp1_input"],
THERMAL_NUM_4_IDX: ["/sys/bus/i2c/drivers/lm75/15-004b/hwmon/hwmon5/temp1_input"],
THERMAL_NUM_1_IDX: ["/sys/bus/i2c/drivers/lm75/15-0048/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_2_IDX: ["/sys/bus/i2c/drivers/lm75/15-0049/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_3_IDX: ["/sys/bus/i2c/drivers/lm75/15-004a/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_4_IDX: ["/sys/bus/i2c/drivers/lm75/15-004b/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_5_IDX: ["/sys/class/hwmon/hwmon0/temp1_input"],
}

Expand All @@ -89,28 +89,25 @@ def _get_thermal_val(self, thermal_num):
return None

if thermal_num < self.THERMAL_NUM_6_IDX:
device_path = self.get_thermal_to_device_path(thermal_num)
if(os.path.isfile(device_path)):
for filename in glob.glob(device_path):
try:
val_file = open(filename, 'r')
except IOError as e:
logging.error('GET. unable to open file: %s', str(e))
return None
content = val_file.readline().rstrip()
if content == '':
logging.debug('GET. content is NULL. device_path:%s', device_path)
return None
try:
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
device_path = self.get_thermal_to_device_path(thermal_num)

for filename in glob.glob(device_path):
try:
val_file = open(filename, 'r')
except IOError as e:
logging.error('GET. unable to open file: %s', str(e))
return None

content = val_file.readline().rstrip()
if content == '':
logging.debug('GET. content is NULL. device_path:%s', device_path)
return None
try:
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
return int(content)

else:
print "No such device_path=%s"%device_path
return 0

else:
log_os_system(self.BCM_thermal_cmd,0)
Expand All @@ -123,23 +120,13 @@ def _get_thermal_val(self, thermal_num):
return 0
file_str = check_file.read()
search_str="average current temperature is"
print "file_str.find=%s"%file_str.find(search_str)
str_len = len(search_str)
idx=file_str.find(search_str)
if idx==-1:
print "bcm sdk is not ready ,retrun 0"
logging.debug('bcm sdk is not ready ,retrun 0')
return 0
else:
#print "file_str[idx]=%c"%file_str[idx+str_len+1]
#print "file_str[idx]=%c"%file_str[idx+str_len+2]
#print "file_str[idx]=%c"%file_str[idx+str_len+2+1]
#print "file_str[idx]=%c"%file_str[idx+str_len+2+2]
#print "file_str[idx]=%c"%file_str[idx+str_len+2+3]
#print "file_str[idx]=%c"%file_str[idx+str_len+2+4]
#print "file_str[idx]=%c"%file_str[idx+str_len+2+5]
#print "file_str[idx]=%c"%file_str[idx+str_len+2+6]
else:
temp_str=file_str[idx+str_len+1] + file_str[idx+str_len+2] + file_str[idx+str_len+3]+file_str[idx+str_len+4] +file_str[idx+str_len+5]
print "bcm temp_str=%s"%temp_str
check_file.close()
return float(temp_str)*1000

Expand Down Expand Up @@ -168,17 +155,12 @@ def get_thermal_temp(self):

def main():
thermal = ThermalUtil()
print "termal1=%d" %thermal._get_thermal_val(1)
print "termal2=%d" %thermal._get_thermal_val(2)
print "termal3=%d" %thermal._get_thermal_val(3)
print "termal4=%d" %thermal._get_thermal_val(4)
print "termal5=%d" %thermal._get_thermal_val(5)
print "termal6=%d" %thermal._get_thermal_val(6)
#
# print 'get_size_node_map : %d' % thermal.get_size_node_map()
# print 'get_size_path_map : %d' % thermal.get_size_path_map()
# for x in range(thermal.get_idx_thermal_start(), thermal.get_num_thermals()+1):
# print thermal.get_thermal_to_device_path(x)
#
logging.debug('thermal1=%d' ,thermal._get_thermal_val(1))
logging.debug('thermal2=%d' ,thermal._get_thermal_val(2))
logging.debug('thermal3=%d' ,thermal._get_thermal_val(3))
logging.debug('thermal4=%d' ,thermal._get_thermal_val(4))
logging.debug('thermal5=%d' ,thermal._get_thermal_val(5))
logging.debug('thermal6=%d' ,thermal._get_thermal_val(6))

if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ def __init__(self, log_file, log_level):

def get_state_from_fan_policy(self, temp, policy):
state=0

#if temp >= 75000:
# state=LEVEL_TEMP_CRITICAL
# return state
logging.debug('temp=%d', temp)
for i in range(0, len(policy)):
#logging.debug('policy[%d][0]=%d, policy[%d][1]=%d', i,policy[i][0],i, policy[i][1])
Expand Down Expand Up @@ -190,15 +186,13 @@ def manage_fans(self):
temp3 = thermal._get_thermal_val(3)
temp4 = thermal._get_thermal_val(4)
temp5 = thermal._get_thermal_val(5)
#temp6 = thermal._get_thermal_val(6)
temp6=0
else:
temp1 = test_temp_list[0]
temp2 = test_temp_list[1]
temp3 = test_temp_list[2]
temp4 = test_temp_list[3]
temp5 = test_temp_list[4]
#temp6 = test_temp_list[5]
temp6=0
fan_fail=0

Expand All @@ -211,22 +205,17 @@ def manage_fans(self):
else:
temp_get= (temp2 + temp4)/2 # Use (sensor_LM75_49 + Thermal sensor_LM75_CPU_4B) /2
ori_state=fan_policy_state
fan_policy_state=self.get_state_from_fan_policy(temp_get, fan_policy)
print "temp2=%d"%temp2
print "temp4=%d"%temp4
print "temp_get=%d"%temp_get
#print "temp4=%d"%temp4
#print "temp6=%d"%temp6
fan_policy_state=self.get_state_from_fan_policy(temp_get, fan_policy)
logging.debug('lm75_48=%d, lm75_49=%d, lm75_4a=%d, lm_4b=%d, cpu=%d, bcm=%d', temp1,temp2,temp3,temp4,temp5,temp6)
logging.debug('ori_state=%d, fan_policy_state=%d', ori_state, fan_policy_state)
new_pwm = fan_policy_state_pwm_tlb[fan_policy_state][0]
if fan_fail==0:
logging.debug('new_pwm=%d', new_pwm)
logging.debug('new_pwm=%d', new_pwm)

if fan_fail==0:
if new_pwm!=ori_pwm:
fan.set_fan_duty_cycle(new_pwm)
logging.info('Set fan speed from %d to %d', ori_pwm, new_pwm)
if new_pwm!=ori_pwm:
fan.set_fan_duty_cycle(new_pwm)
logging.info('Set fan speed from %d to %d', ori_pwm, new_pwm)

for i in range (fan.FAN_NUM_1_IDX, fan.FAN_NUM_ON_MAIN_BROAD+1):
if fan.get_fan_status(i)==0:
Expand All @@ -237,14 +226,10 @@ def manage_fans(self):
fan.set_fan_duty_cycle(new_pwm)
break
else:
fan_fail=0

#if fan_policy_state == ori_state:
# return True
#else:
new_state = fan_policy_state
fan_fail=0

new_state = fan_policy_state

#logging.warning('Temperature high alarm testing')
if ori_state==LEVEL_FAN_DEF:
if new_state==LEVEL_TEMP_HIGH:
if alarm_state==0:
Expand Down Expand Up @@ -337,4 +322,4 @@ def main(argv):

if __name__ == '__main__':
main(sys.argv[1:])