[devices]: Add to support as4630-54pe platform (#2895)
* Add to support as4630-54pe platform * Add as4630 monitor psu/fan status
This commit is contained in:
parent
6aad2da475
commit
c1a501e9d5
@ -22,6 +22,7 @@ $(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(DELL_S6000_PLATFORM_MODULE) \
|
||||
$(ACCTON_AS7716_32XB_PLATFORM_MODULE) \
|
||||
$(ACCTON_AS6712_32X_PLATFORM_MODULE) \
|
||||
$(ACCTON_AS7726_32X_PLATFORM_MODULE) \
|
||||
$(ACCTON_AS4630_54PE_PLATFORM_MODULE) \
|
||||
$(ACCTON_MINIPACK_PLATFORM_MODULE) \
|
||||
$(INVENTEC_D7032Q28B_PLATFORM_MODULE) \
|
||||
$(INVENTEC_D7054Q28B_PLATFORM_MODULE) \
|
||||
|
@ -9,6 +9,7 @@ ACCTON_AS7326_56X_PLATFORM_MODULE_VERSION = 1.1
|
||||
ACCTON_AS7716_32XB_PLATFORM_MODULE_VERSION = 1.1
|
||||
ACCTON_AS6712_32X_PLATFORM_MODULE_VERSION = 1.1
|
||||
ACCTON_AS7726_32X_PLATFORM_MODULE_VERSION = 1.1
|
||||
ACCTON_AS4630_54PE_PLATFORM_MODULE_VERSION = 1.1
|
||||
ACCTON_MINIPACK_PLATFORM_MODULE_VERSION = 1.1
|
||||
|
||||
export ACCTON_AS7712_32X_PLATFORM_MODULE_VERSION
|
||||
@ -20,6 +21,7 @@ export ACCTON_AS7326_56X_PLATFORM_MODULE_VERSION
|
||||
export ACCTON_AS7716_32XB_PLATFORM_MODULE_VERSION
|
||||
export ACCTON_AS6712_32X_PLATFORM_MODULE_VERSION
|
||||
export ACCTON_AS7726_32X_PLATFORM_MODULE_VERSION
|
||||
export ACCTON_AS4630_54PE_PLATFORM_MODULE_VERSION
|
||||
export ACCTON_MINIPACK_PLATFORM_MODULE_VERSION
|
||||
|
||||
ACCTON_AS7712_32X_PLATFORM_MODULE = sonic-platform-accton-as7712-32x_$(ACCTON_AS7712_32X_PLATFORM_MODULE_VERSION)_amd64.deb
|
||||
@ -60,6 +62,11 @@ ACCTON_AS7726_32X_PLATFORM_MODULE = sonic-platform-accton-as7726-32x_$(ACCTON_AS
|
||||
$(ACCTON_AS7726_32X_PLATFORM_MODULE)_PLATFORM = x86_64-accton_as7726_32x-r0
|
||||
$(eval $(call add_extra_package,$(ACCTON_AS7712_32X_PLATFORM_MODULE),$(ACCTON_AS7726_32X_PLATFORM_MODULE)))
|
||||
|
||||
ACCTON_AS4630_54PE_PLATFORM_MODULE = sonic-platform-accton-as4630-54pe_$(ACCTON_AS4630_54PE_PLATFORM_MODULE_VERSION)_amd64.deb
|
||||
$(ACCTON_AS4630_54PE_PLATFORM_MODULE)_PLATFORM = x86_64-accton_as4630_54pe-r0
|
||||
$(eval $(call add_extra_package,$(ACCTON_AS7712_32X_PLATFORM_MODULE),$(ACCTON_AS4630_54PE_PLATFORM_MODULE)))
|
||||
|
||||
|
||||
ACCTON_MINIPACK_PLATFORM_MODULE = sonic-platform-accton-minipack_$(ACCTON_MINIPACK_PLATFORM_MODULE_VERSION)_amd64.deb
|
||||
$(ACCTON_MINIPACK_PLATFORM_MODULE)_PLATFORM = x86_64-accton_minipack-r0
|
||||
$(eval $(call add_extra_package,$(ACCTON_AS7712_32X_PLATFORM_MODULE),$(ACCTON_MINIPACK_PLATFORM_MODULE)))
|
||||
|
251
platform/broadcom/sonic-platform-modules-accton/as4630-54pe/classes/fanutil.py
Executable file
251
platform/broadcom/sonic-platform-modules-accton/as4630-54pe/classes/fanutil.py
Executable file
@ -0,0 +1,251 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2017 Accton Technology Corporation
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# HISTORY:
|
||||
# mm/dd/yyyy (A.D.)
|
||||
# 11/13/2017: Polly Hsu, Create
|
||||
# 1/10/2018: Jostar modify for as7716_32
|
||||
# 12/03/2018: Jostar modify for as7726_32
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
try:
|
||||
import time
|
||||
import logging
|
||||
from collections import namedtuple
|
||||
except ImportError as e:
|
||||
raise ImportError('%s - required module not found' % str(e))
|
||||
|
||||
|
||||
class FanUtil(object):
|
||||
"""Platform-specific FanUtil class"""
|
||||
|
||||
FAN_NUM_ON_MAIN_BROAD = 6
|
||||
FAN_NUM_1_IDX = 1
|
||||
FAN_NUM_2_IDX = 2
|
||||
FAN_NUM_3_IDX = 3
|
||||
FAN_NUM_4_IDX = 4
|
||||
FAN_NUM_5_IDX = 5
|
||||
FAN_NUM_6_IDX = 6
|
||||
|
||||
FAN_NODE_NUM_OF_MAP = 2
|
||||
FAN_NODE_FAULT_IDX_OF_MAP = 1
|
||||
FAN_NODE_DIR_IDX_OF_MAP = 2
|
||||
|
||||
BASE_VAL_PATH = '/sys/bus/i2c/devices/54-0066/{0}'
|
||||
FAN_DUTY_PATH = '/sys/bus/i2c/devices/54-0066/fan_duty_cycle_percentage'
|
||||
|
||||
#logfile = ''
|
||||
#loglevel = logging.INFO
|
||||
|
||||
""" Dictionary where
|
||||
key1 = fan id index (integer) starting from 1
|
||||
key2 = fan node index (interger) starting from 1
|
||||
value = path to fan device file (string) """
|
||||
_fan_to_device_path_mapping = {}
|
||||
|
||||
#fan1_direction
|
||||
#fan1_fault
|
||||
#fan1_present
|
||||
|
||||
#(FAN_NUM_2_IDX, FAN_NODE_DUTY_IDX_OF_MAP): 'fan2_duty_cycle_percentage',
|
||||
_fan_to_device_node_mapping = {
|
||||
(FAN_NUM_1_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan1_fault',
|
||||
(FAN_NUM_1_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan1_direction',
|
||||
|
||||
(FAN_NUM_2_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan2_fault',
|
||||
(FAN_NUM_2_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan2_direction',
|
||||
|
||||
(FAN_NUM_3_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan3_fault',
|
||||
(FAN_NUM_3_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan3_direction',
|
||||
|
||||
(FAN_NUM_4_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan4_fault',
|
||||
(FAN_NUM_4_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan4_direction',
|
||||
|
||||
(FAN_NUM_5_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan5_fault',
|
||||
(FAN_NUM_5_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan5_direction',
|
||||
|
||||
(FAN_NUM_6_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan6_fault',
|
||||
(FAN_NUM_6_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan6_direction',
|
||||
}
|
||||
|
||||
def _get_fan_to_device_node(self, fan_num, node_num):
|
||||
return self._fan_to_device_node_mapping[(fan_num, node_num)]
|
||||
|
||||
def _get_fan_node_val(self, fan_num, node_num):
|
||||
if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD:
|
||||
logging.debug('GET. Parameter error. fan_num:%d', fan_num)
|
||||
return None
|
||||
|
||||
if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP:
|
||||
logging.debug('GET. Parameter error. node_num:%d', node_num)
|
||||
return None
|
||||
|
||||
device_path = self.get_fan_to_device_path(fan_num, node_num)
|
||||
|
||||
try:
|
||||
val_file = open(device_path, '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)
|
||||
|
||||
def _set_fan_node_val(self, fan_num, node_num, val):
|
||||
if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD:
|
||||
logging.debug('GET. Parameter error. fan_num:%d', fan_num)
|
||||
return None
|
||||
|
||||
if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP:
|
||||
logging.debug('GET. Parameter error. node_num:%d', node_num)
|
||||
return None
|
||||
|
||||
content = str(val)
|
||||
if content == '':
|
||||
logging.debug('GET. content is NULL. device_path:%s', device_path)
|
||||
return None
|
||||
|
||||
device_path = self.get_fan_to_device_path(fan_num, node_num)
|
||||
try:
|
||||
val_file = open(device_path, 'w')
|
||||
except IOError as e:
|
||||
logging.error('GET. unable to open file: %s', str(e))
|
||||
return None
|
||||
|
||||
val_file.write(content)
|
||||
|
||||
try:
|
||||
val_file.close()
|
||||
except:
|
||||
logging.debug('GET. unable to close file. device_path:%s', device_path)
|
||||
return None
|
||||
|
||||
return True
|
||||
|
||||
def __init__(self):
|
||||
fan_path = self.BASE_VAL_PATH
|
||||
|
||||
for fan_num in range(self.FAN_NUM_1_IDX, self.FAN_NUM_ON_MAIN_BROAD+1):
|
||||
for node_num in range(self.FAN_NODE_FAULT_IDX_OF_MAP, self.FAN_NODE_NUM_OF_MAP+1):
|
||||
self._fan_to_device_path_mapping[(fan_num, node_num)] = fan_path.format(
|
||||
self._fan_to_device_node_mapping[(fan_num, node_num)])
|
||||
|
||||
def get_num_fans(self):
|
||||
return self.FAN_NUM_ON_MAIN_BROAD
|
||||
|
||||
def get_idx_fan_start(self):
|
||||
return self.FAN_NUM_1_IDX
|
||||
|
||||
def get_num_nodes(self):
|
||||
return self.FAN_NODE_NUM_OF_MAP
|
||||
|
||||
def get_idx_node_start(self):
|
||||
return self.FAN_NODE_FAULT_IDX_OF_MAP
|
||||
|
||||
def get_size_node_map(self):
|
||||
return len(self._fan_to_device_node_mapping)
|
||||
|
||||
def get_size_path_map(self):
|
||||
return len(self._fan_to_device_path_mapping)
|
||||
|
||||
def get_fan_to_device_path(self, fan_num, node_num):
|
||||
return self._fan_to_device_path_mapping[(fan_num, node_num)]
|
||||
|
||||
def get_fan_fault(self, fan_num):
|
||||
return self._get_fan_node_val(fan_num, self.FAN_NODE_FAULT_IDX_OF_MAP)
|
||||
|
||||
#def get_fan_speed(self, fan_num):
|
||||
# return self._get_fan_node_val(fan_num, self.FAN_NODE_SPEED_IDX_OF_MAP)
|
||||
|
||||
def get_fan_dir(self, fan_num):
|
||||
return self._get_fan_node_val(fan_num, self.FAN_NODE_DIR_IDX_OF_MAP)
|
||||
|
||||
def get_fan_duty_cycle(self):
|
||||
#duty_path = self.FAN_DUTY_PATH
|
||||
try:
|
||||
val_file = open(self.FAN_DUTY_PATH)
|
||||
except IOError as e:
|
||||
print "Error: unable to open file: %s" % str(e)
|
||||
return False
|
||||
|
||||
content = val_file.readline().rstrip()
|
||||
val_file.close()
|
||||
|
||||
return int(content)
|
||||
#self._get_fan_node_val(fan_num, self.FAN_NODE_DUTY_IDX_OF_MAP)
|
||||
#static u32 reg_val_to_duty_cycle(u8 reg_val)
|
||||
#{
|
||||
# reg_val &= FAN_DUTY_CYCLE_REG_MASK;
|
||||
# return ((u32)(reg_val+1) * 625 + 75)/ 100;
|
||||
#}
|
||||
#
|
||||
def set_fan_duty_cycle(self, val):
|
||||
|
||||
try:
|
||||
fan_file = open(self.FAN_DUTY_PATH, 'r+')
|
||||
except IOError as e:
|
||||
print "Error: unable to open file: %s" % str(e)
|
||||
return False
|
||||
#val = ((val + 1 ) * 625 +75 ) / 100
|
||||
fan_file.write(str(val))
|
||||
fan_file.close()
|
||||
return True
|
||||
|
||||
#def get_fanr_fault(self, fan_num):
|
||||
# return self._get_fan_node_val(fan_num, self.FANR_NODE_FAULT_IDX_OF_MAP)
|
||||
|
||||
def get_fanr_speed(self, fan_num):
|
||||
return self._get_fan_node_val(fan_num, self.FANR_NODE_SPEED_IDX_OF_MAP)
|
||||
|
||||
def get_fan_status(self, fan_num):
|
||||
if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD:
|
||||
logging.debug('GET. Parameter error. fan_num, %d', fan_num)
|
||||
return None
|
||||
|
||||
if self.get_fan_fault(fan_num) is not None and self.get_fan_fault(fan_num) > 0:
|
||||
logging.debug('GET. FAN fault. fan_num, %d', fan_num)
|
||||
return False
|
||||
|
||||
#if self.get_fanr_fault(fan_num) is not None and self.get_fanr_fault(fan_num) > 0:
|
||||
# logging.debug('GET. FANR fault. fan_num, %d', fan_num)
|
||||
# return False
|
||||
|
||||
return True
|
||||
|
||||
#def main():
|
||||
# fan = FanUtil()
|
||||
#
|
||||
# print 'get_size_node_map : %d' % fan.get_size_node_map()
|
||||
# print 'get_size_path_map : %d' % fan.get_size_path_map()
|
||||
# for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1):
|
||||
# for y in range(fan.get_idx_node_start(), fan.get_num_nodes()+1):
|
||||
# print fan.get_fan_to_device_path(x, y)
|
||||
#
|
||||
#if __name__ == '__main__':
|
||||
# main()
|
@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2017 Accton Technology Corporation
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# HISTORY:
|
||||
# mm/dd/yyyy (A.D.)
|
||||
# 11/13/2017: Polly Hsu, Create
|
||||
# 1/10/2018:Jostar modify for as7716_32x
|
||||
# 12/03/2018:Jostar modify for as7726_32x thermal plan
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
try:
|
||||
import os
|
||||
import time
|
||||
import logging
|
||||
import glob
|
||||
import commands
|
||||
from collections import namedtuple
|
||||
except ImportError as e:
|
||||
raise ImportError('%s - required module not found' % str(e))
|
||||
|
||||
class ThermalUtil(object):
|
||||
"""Platform-specific ThermalUtil class"""
|
||||
THERMAL_NUM_MAX = 5
|
||||
THERMAL_NUM_1_IDX = 1 # 1_ON_MAIN_BROAD. LM75
|
||||
THERMAL_NUM_2_IDX = 2 # 2_ON_MAIN_BROAD. LM75
|
||||
THERMAL_NUM_3_IDX = 3 # 3_ON_MAIN_BROAD. LM75
|
||||
THERMAL_NUM_4_IDX = 4 # 4_ON_MAIN_BROAD. LM75
|
||||
THERMAL_NUM_5_IDX = 5 # 5_ON_MAIN_BROAD. LM75
|
||||
|
||||
""" Dictionary where
|
||||
key1 = thermal id index (integer) starting from 1
|
||||
value = path to fan device file (string) """
|
||||
#_thermal_to_device_path_mapping = {}
|
||||
|
||||
_thermal_to_device_node_mapping = {
|
||||
THERMAL_NUM_1_IDX: ['55', '48'],
|
||||
THERMAL_NUM_2_IDX: ['55', '49'],
|
||||
THERMAL_NUM_3_IDX: ['55', '4a'],
|
||||
THERMAL_NUM_4_IDX: ['55', '4b'],
|
||||
THERMAL_NUM_5_IDX: ['54', '4c'],
|
||||
}
|
||||
thermal_sysfspath ={
|
||||
THERMAL_NUM_1_IDX: ["/sys/bus/i2c/devices/55-0048/hwmon/hwmon4/temp1_input"],
|
||||
THERMAL_NUM_2_IDX: ["/sys/bus/i2c/devices/55-0049/hwmon/hwmon5/temp1_input"],
|
||||
THERMAL_NUM_3_IDX: ["/sys/bus/i2c/devices/55-004a/hwmon/hwmon6/temp1_input"],
|
||||
THERMAL_NUM_4_IDX: ["/sys/bus/i2c/devices/55-004b/hwmon/hwmon7/temp1_input"],
|
||||
THERMAL_NUM_5_IDX: ["/sys/bus/i2c/devices/54-004c/hwmon/hwmon3/temp1_input"],
|
||||
}
|
||||
|
||||
#def __init__(self):
|
||||
def _get_thermal_val(self, thermal_num):
|
||||
if thermal_num < self.THERMAL_NUM_1_IDX or thermal_num > self.THERMAL_NUM_MAX:
|
||||
logging.debug('GET. Parameter error. thermal_num, %d', thermal_num)
|
||||
return None
|
||||
|
||||
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
|
||||
return int(content)
|
||||
|
||||
else:
|
||||
print "No such device_path=%s"%device_path
|
||||
return 0
|
||||
|
||||
def get_num_thermals(self):
|
||||
return self.THERMAL_NUM_MAX
|
||||
|
||||
def get_idx_thermal_start(self):
|
||||
return self.THERMAL_NUM_1_IDX
|
||||
|
||||
def get_size_node_map(self):
|
||||
return len(self._thermal_to_device_node_mapping)
|
||||
|
||||
def get_size_path_map(self):
|
||||
return len(self.thermal_sysfspath)
|
||||
|
||||
def get_thermal_to_device_path(self, thermal_num):
|
||||
return self.thermal_sysfspath[thermal_num][0]
|
||||
|
||||
def get_thermal_1_val(self):
|
||||
return self._get_thermal_node_val(self.THERMAL_NUM_1_IDX)
|
||||
|
||||
def get_thermal_2_val(self):
|
||||
return self._get_thermal_node_val(self.THERMAL_NUM_2_IDX)
|
||||
def get_thermal_temp(self):
|
||||
return (self._get_thermal_node_val(self.THERMAL_NUM_1_IDX) + self._get_thermal_node_val(self.THERMAL_NUM_2_IDX) +self._get_thermal_node_val(self.THERMAL_NUM_3_IDX))
|
||||
|
||||
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 '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)
|
||||
#
|
||||
if __name__ == '__main__':
|
||||
main()
|
19
platform/broadcom/sonic-platform-modules-accton/as4630-54pe/modules/Makefile
Executable file
19
platform/broadcom/sonic-platform-modules-accton/as4630-54pe/modules/Makefile
Executable file
@ -0,0 +1,19 @@
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
obj-m:= x86-64-accton-as4630-54pe-cpld.o x86-64-accton-as4630-54pe-psu.o \
|
||||
x86-64-accton-as4630-54pe-leds.o ym2651y.o
|
||||
|
||||
else
|
||||
ifeq (,$(KERNEL_SRC))
|
||||
#$(error KERNEL_SRC is not defined)
|
||||
KVERSION=3.16.0-8-amd64
|
||||
KERNEL_DIR = /usr/src/linux-headers-$(KVERSION)/
|
||||
KERNELDIR:=$(KERNEL_DIR)
|
||||
else
|
||||
KERNELDIR:=$(KERNEL_SRC)
|
||||
endif
|
||||
PWD:=$(shell pwd)
|
||||
default:
|
||||
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
|
||||
clean:
|
||||
rm -rf *.o *.mod.o *.mod.o *.mod.c *.ko .*cmd .tmp_versions Module.markers Module.symvers modules.order
|
||||
endif
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,579 @@
|
||||
/*
|
||||
* A LED driver for the accton_as4630_54pe_led
|
||||
*
|
||||
* Copyright (C) 2014 Accton Technology Corporation.
|
||||
* Brandon Chuang <brandon_chuang@accton.com.tw>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
/*#define DEBUG*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/leds.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/dmi.h>
|
||||
|
||||
extern int as4630_54pe_cpld_read (unsigned short cpld_addr, u8 reg);
|
||||
extern int as4630_54pe_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
|
||||
|
||||
#define DRVNAME "accton_as4630_54pe_led"
|
||||
|
||||
struct accton_as4630_54pe_led_data {
|
||||
struct platform_device *pdev;
|
||||
struct mutex update_lock;
|
||||
char valid; /* != 0 if registers are valid */
|
||||
unsigned long last_updated; /* In jiffies */
|
||||
u8 reg_val[2]; /* only 1 register*/
|
||||
};
|
||||
|
||||
static struct accton_as4630_54pe_led_data *ledctl = NULL;
|
||||
|
||||
/* LED related data
|
||||
*/
|
||||
|
||||
#define LED_CNTRLER_I2C_ADDRESS (0x60)
|
||||
|
||||
#define LED_TYPE_DIAG_REG_MASK (0x20|0x40|0x80)
|
||||
#define LED_MODE_DIAG_GREEN_VALUE (0x20)
|
||||
#define LED_MODE_DIAG_GREEN_BLINK_VALUE (0x60)
|
||||
#define LED_MODE_DIAG_AMBER_VALUE (0x80) /*It's yellow actually. Green+Red=Yellow*/
|
||||
#define LED_MODE_DIAG_OFF_VALUE (0x0)
|
||||
|
||||
#define LED_TYPE_PRI_REG_MASK (0x8|0x4)
|
||||
#define LED_MODE_PRI_GREEN_VALUE 0x4
|
||||
#define LED_MODE_PRI_AMBER_VALUE 0x8
|
||||
#define LED_MODE_PRI_OFF_VALUE 0x0
|
||||
|
||||
#define LED_TYPE_POE_REG_MASK (0x2|0x1)
|
||||
#define LED_MODE_POE_GREEN_VALUE 0x1
|
||||
#define LED_MODE_POE_AMBER_VALUE 0x2
|
||||
#define LED_MODE_POE_OFF_VALUE 0x0
|
||||
|
||||
#define LED_TYPE_STK1_REG_MASK 0x20
|
||||
#define LED_MODE_STK1_GREEN_VALUE 0x0
|
||||
#define LED_MODE_STK1_OFF_VALUE 0x20
|
||||
|
||||
#define LED_TYPE_STK2_REG_MASK 0x10
|
||||
#define LED_MODE_STK2_GREEN_VALUE 0x0
|
||||
#define LED_MODE_STK2_OFF_VALUE 0x10
|
||||
|
||||
#define LED_TYPE_FAN_REG_MASK (0x20|0x10)
|
||||
#define LED_MODE_FAN_AMBER_VALUE 0x20
|
||||
#define LED_MODE_FAN_GREEN_VALUE 0x10
|
||||
#define LED_MODE_FAN_OFF_VALUE (0x0)
|
||||
|
||||
#define LED_TYPE_PSU2_REG_MASK (0x8|0x4)
|
||||
#define LED_MODE_PSU2_AMBER_VALUE 0x8
|
||||
#define LED_MODE_PSU2_GREEN_VALUE 0x4
|
||||
#define LED_MODE_PSU2_OFF_VALUE (0x0)
|
||||
|
||||
#define LED_TYPE_PSU1_REG_MASK (0x2|0x1)
|
||||
#define LED_MODE_PSU1_AMBER_VALUE 0x2
|
||||
#define LED_MODE_PSU1_GREEN_VALUE 0x1
|
||||
#define LED_MODE_PSU1_OFF_VALUE (0x0)
|
||||
|
||||
enum led_type {
|
||||
LED_TYPE_DIAG,
|
||||
LED_TYPE_PRI,
|
||||
LED_TYPE_POE,
|
||||
LED_TYPE_STK1,
|
||||
LED_TYPE_STK2,
|
||||
LED_TYPE_FAN,
|
||||
LED_TYPE_PSU1,
|
||||
LED_TYPE_PSU2
|
||||
};
|
||||
|
||||
struct led_reg {
|
||||
u32 types;
|
||||
u8 reg_addr;
|
||||
};
|
||||
|
||||
static const struct led_reg led_reg_map[] = {
|
||||
{(1<<LED_TYPE_DIAG)| (1<<LED_TYPE_PRI) | (1<<LED_TYPE_PSU2) , 0x30},
|
||||
{(1<<LED_TYPE_PSU1) | (1<<LED_TYPE_FAN) | (1<<LED_TYPE_POE) |(1<<LED_TYPE_STK1) | (1<<LED_TYPE_STK2) , 0x31},
|
||||
};
|
||||
|
||||
|
||||
enum led_light_mode {
|
||||
LED_MODE_OFF = 0,
|
||||
LED_MODE_GREEN,
|
||||
LED_MODE_AMBER,
|
||||
LED_MODE_RED,
|
||||
LED_MODE_BLUE,
|
||||
LED_MODE_GREEN_BLINK,
|
||||
LED_MODE_AMBER_BLINK,
|
||||
LED_MODE_RED_BLINK,
|
||||
LED_MODE_BLUE_BLINK,
|
||||
LED_MODE_AUTO,
|
||||
LED_MODE_UNKNOWN
|
||||
};
|
||||
|
||||
struct led_type_mode {
|
||||
enum led_type type;
|
||||
enum led_light_mode mode;
|
||||
int reg_bit_mask;
|
||||
int mode_value;
|
||||
};
|
||||
|
||||
static struct led_type_mode led_type_mode_data[] = {
|
||||
{LED_TYPE_PRI, LED_MODE_OFF, LED_TYPE_PRI_REG_MASK, LED_MODE_PRI_OFF_VALUE},
|
||||
{LED_TYPE_PRI, LED_MODE_GREEN, LED_TYPE_PRI_REG_MASK, LED_MODE_PRI_GREEN_VALUE},
|
||||
{LED_TYPE_PRI, LED_MODE_AMBER, LED_TYPE_PRI_REG_MASK, LED_MODE_PRI_AMBER_VALUE},
|
||||
|
||||
{LED_TYPE_DIAG,LED_MODE_OFF, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_OFF_VALUE},
|
||||
{LED_TYPE_DIAG,LED_MODE_GREEN, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_VALUE},
|
||||
{LED_TYPE_DIAG,LED_MODE_GREEN_BLINK, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_BLINK_VALUE},
|
||||
{LED_TYPE_DIAG,LED_MODE_AMBER, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_AMBER_VALUE},
|
||||
|
||||
{LED_TYPE_POE,LED_MODE_OFF, LED_TYPE_POE_REG_MASK, LED_MODE_POE_OFF_VALUE},
|
||||
{LED_TYPE_POE,LED_MODE_GREEN, LED_TYPE_POE_REG_MASK, LED_MODE_POE_GREEN_VALUE},
|
||||
{LED_TYPE_POE,LED_MODE_AMBER, LED_TYPE_POE_REG_MASK, LED_MODE_POE_AMBER_VALUE},
|
||||
|
||||
{LED_TYPE_STK1,LED_MODE_OFF, LED_TYPE_STK1_REG_MASK, LED_MODE_STK1_OFF_VALUE},
|
||||
{LED_TYPE_STK1,LED_MODE_GREEN, LED_TYPE_STK1_REG_MASK, LED_MODE_STK1_GREEN_VALUE},
|
||||
|
||||
{LED_TYPE_STK2,LED_MODE_OFF, LED_TYPE_STK2_REG_MASK, LED_MODE_STK2_OFF_VALUE},
|
||||
{LED_TYPE_STK2,LED_MODE_GREEN, LED_TYPE_STK2_REG_MASK, LED_MODE_STK2_GREEN_VALUE},
|
||||
|
||||
{LED_TYPE_FAN,LED_MODE_OFF, LED_TYPE_FAN_REG_MASK, LED_MODE_FAN_OFF_VALUE},
|
||||
{LED_TYPE_FAN,LED_MODE_GREEN, LED_TYPE_FAN_REG_MASK, LED_MODE_FAN_GREEN_VALUE},
|
||||
{LED_TYPE_FAN,LED_MODE_AMBER, LED_TYPE_FAN_REG_MASK, LED_MODE_FAN_AMBER_VALUE},
|
||||
|
||||
{LED_TYPE_PSU1,LED_MODE_OFF, LED_TYPE_PSU1_REG_MASK, LED_MODE_PSU1_OFF_VALUE},
|
||||
{LED_TYPE_PSU1,LED_MODE_GREEN, LED_TYPE_PSU1_REG_MASK, LED_MODE_PSU1_GREEN_VALUE},
|
||||
{LED_TYPE_PSU1,LED_MODE_AMBER, LED_TYPE_PSU1_REG_MASK, LED_MODE_PSU1_AMBER_VALUE},
|
||||
|
||||
{LED_TYPE_PSU2,LED_MODE_OFF, LED_TYPE_PSU2_REG_MASK, LED_MODE_PSU2_OFF_VALUE},
|
||||
{LED_TYPE_PSU2,LED_MODE_GREEN, LED_TYPE_PSU2_REG_MASK, LED_MODE_PSU2_GREEN_VALUE},
|
||||
{LED_TYPE_PSU2,LED_MODE_AMBER, LED_TYPE_PSU2_REG_MASK, LED_MODE_PSU2_AMBER_VALUE},
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void accton_as4630_54pe_led_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode, enum led_type type);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int accton_getLedReg(enum led_type type, u8 *reg)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(led_reg_map); i++) {
|
||||
if(led_reg_map[i].types & (1<<type)) {
|
||||
*reg = led_reg_map[i].reg_addr;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int led_reg_val_to_light_mode(enum led_type type, u8 reg_val) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) {
|
||||
|
||||
if (type != led_type_mode_data[i].type)
|
||||
continue;
|
||||
|
||||
if ((led_type_mode_data[i].reg_bit_mask & reg_val) ==
|
||||
led_type_mode_data[i].mode_value)
|
||||
{
|
||||
return led_type_mode_data[i].mode;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u8 led_light_mode_to_reg_val(enum led_type type,
|
||||
enum led_light_mode mode, u8 reg_val) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) {
|
||||
if (type != led_type_mode_data[i].type)
|
||||
continue;
|
||||
|
||||
if (mode != led_type_mode_data[i].mode)
|
||||
continue;
|
||||
reg_val = led_type_mode_data[i].mode_value |
|
||||
(reg_val & (~led_type_mode_data[i].reg_bit_mask));
|
||||
break;
|
||||
}
|
||||
|
||||
return reg_val;
|
||||
}
|
||||
|
||||
static int accton_as4630_54pe_led_read_value(u8 reg)
|
||||
{
|
||||
return as4630_54pe_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg);
|
||||
}
|
||||
|
||||
static int accton_as4630_54pe_led_write_value(u8 reg, u8 value)
|
||||
{
|
||||
return as4630_54pe_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value);
|
||||
}
|
||||
|
||||
static void accton_as4630_54pe_led_update(void)
|
||||
{
|
||||
mutex_lock(&ledctl->update_lock);
|
||||
|
||||
if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2)
|
||||
|| !ledctl->valid) {
|
||||
int i;
|
||||
|
||||
dev_dbg(&ledctl->pdev->dev, "Starting accton_as4630_54pe_led update\n");
|
||||
|
||||
/* Update LED data
|
||||
*/
|
||||
for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) {
|
||||
int status = accton_as4630_54pe_led_read_value(led_reg_map[i].reg_addr);
|
||||
|
||||
if (status < 0) {
|
||||
ledctl->valid = 0;
|
||||
dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg_map[i].reg_addr, status);
|
||||
goto exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
ledctl->reg_val[i] = status;
|
||||
}
|
||||
}
|
||||
|
||||
ledctl->last_updated = jiffies;
|
||||
ledctl->valid = 1;
|
||||
}
|
||||
|
||||
exit:
|
||||
mutex_unlock(&ledctl->update_lock);
|
||||
}
|
||||
|
||||
static void accton_as4630_54pe_led_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode,
|
||||
enum led_type type)
|
||||
{
|
||||
int reg_val;
|
||||
u8 reg ;
|
||||
mutex_lock(&ledctl->update_lock);
|
||||
|
||||
if( !accton_getLedReg(type, ®))
|
||||
{
|
||||
dev_dbg(&ledctl->pdev->dev, "Not match item for %d.\n", type);
|
||||
}
|
||||
|
||||
|
||||
reg_val = accton_as4630_54pe_led_read_value(reg);
|
||||
if (reg_val < 0) {
|
||||
dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val);
|
||||
goto exit;
|
||||
}
|
||||
reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val);
|
||||
|
||||
accton_as4630_54pe_led_write_value(reg, reg_val);
|
||||
|
||||
/* to prevent the slow-update issue */
|
||||
ledctl->valid = 0;
|
||||
|
||||
exit:
|
||||
mutex_unlock(&ledctl->update_lock);
|
||||
}
|
||||
|
||||
|
||||
static void accton_as4630_54pe_led_diag_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as4630_54pe_led_set(led_cdev, led_light_mode, LED_TYPE_DIAG);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as4630_54pe_led_diag_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as4630_54pe_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]);
|
||||
}
|
||||
|
||||
static void accton_as4630_54pe_led_pri_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as4630_54pe_led_set(led_cdev, led_light_mode, LED_TYPE_PRI);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as4630_54pe_led_pri_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as4630_54pe_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_PRI, ledctl->reg_val[0]);
|
||||
}
|
||||
|
||||
static void accton_as4630_54pe_led_poe_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as4630_54pe_led_set(led_cdev, led_light_mode, LED_TYPE_POE);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as4630_54pe_led_poe_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as4630_54pe_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_POE, ledctl->reg_val[1]);
|
||||
}
|
||||
|
||||
|
||||
static void accton_as4630_54pe_led_stk1_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as4630_54pe_led_set(led_cdev, led_light_mode, LED_TYPE_STK1);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as4630_54pe_led_stk1_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as4630_54pe_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_STK1, ledctl->reg_val[1]);
|
||||
}
|
||||
|
||||
static void accton_as4630_54pe_led_stk2_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as4630_54pe_led_set(led_cdev, led_light_mode, LED_TYPE_STK2);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as4630_54pe_led_stk2_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as4630_54pe_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_STK2, ledctl->reg_val[1]);
|
||||
}
|
||||
|
||||
static void accton_as4630_54pe_led_fan_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as4630_54pe_led_set(led_cdev, led_light_mode, LED_TYPE_FAN);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as4630_54pe_led_fan_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as4630_54pe_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_FAN, ledctl->reg_val[0]);
|
||||
}
|
||||
|
||||
static void accton_as4630_54pe_led_psu1_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as4630_54pe_led_set(led_cdev, led_light_mode, LED_TYPE_PSU1);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as4630_54pe_led_psu1_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as4630_54pe_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_PSU1, ledctl->reg_val[0]);
|
||||
}
|
||||
|
||||
static void accton_as4630_54pe_led_psu2_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness led_light_mode)
|
||||
{
|
||||
accton_as4630_54pe_led_set(led_cdev, led_light_mode, LED_TYPE_PSU2);
|
||||
}
|
||||
|
||||
static enum led_brightness accton_as4630_54pe_led_psu2_get(struct led_classdev *cdev)
|
||||
{
|
||||
accton_as4630_54pe_led_update();
|
||||
return led_reg_val_to_light_mode(LED_TYPE_PSU2, ledctl->reg_val[0]);
|
||||
}
|
||||
|
||||
static struct led_classdev accton_as4630_54pe_leds[] = {
|
||||
[LED_TYPE_DIAG] = {
|
||||
.name = "diag",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as4630_54pe_led_diag_set,
|
||||
.brightness_get = accton_as4630_54pe_led_diag_get,
|
||||
.flags = LED_CORE_SUSPENDRESUME,
|
||||
.max_brightness = LED_MODE_GREEN,
|
||||
},
|
||||
[LED_TYPE_PRI] = {
|
||||
.name = "pri",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as4630_54pe_led_pri_set,
|
||||
.brightness_get = accton_as4630_54pe_led_pri_get,
|
||||
.flags = LED_CORE_SUSPENDRESUME,
|
||||
.max_brightness = LED_MODE_AMBER,
|
||||
},
|
||||
[LED_TYPE_POE] = {
|
||||
.name = "poe",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as4630_54pe_led_poe_set,
|
||||
.brightness_get = accton_as4630_54pe_led_poe_get,
|
||||
.flags = LED_CORE_SUSPENDRESUME,
|
||||
.max_brightness = LED_MODE_AMBER,
|
||||
},
|
||||
[LED_TYPE_STK1] = {
|
||||
.name = "stk1",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as4630_54pe_led_stk1_set,
|
||||
.brightness_get = accton_as4630_54pe_led_stk1_get,
|
||||
.flags = LED_CORE_SUSPENDRESUME,
|
||||
.max_brightness = LED_MODE_GREEN,
|
||||
},
|
||||
[LED_TYPE_STK2] = {
|
||||
.name = "stk2",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as4630_54pe_led_stk2_set,
|
||||
.brightness_get = accton_as4630_54pe_led_stk2_get,
|
||||
.flags = LED_CORE_SUSPENDRESUME,
|
||||
.max_brightness = LED_MODE_GREEN,
|
||||
},
|
||||
[LED_TYPE_FAN] = {
|
||||
.name = "fan",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as4630_54pe_led_fan_set,
|
||||
.brightness_get = accton_as4630_54pe_led_fan_get,
|
||||
.flags = LED_CORE_SUSPENDRESUME,
|
||||
.max_brightness = LED_MODE_AUTO,
|
||||
},
|
||||
[LED_TYPE_PSU1] = {
|
||||
.name = "psu1",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as4630_54pe_led_psu1_set,
|
||||
.brightness_get = accton_as4630_54pe_led_psu1_get,
|
||||
.flags = LED_CORE_SUSPENDRESUME,
|
||||
.max_brightness = LED_MODE_AUTO,
|
||||
},
|
||||
[LED_TYPE_PSU2] = {
|
||||
.name = "psu2",
|
||||
.default_trigger = "unused",
|
||||
.brightness_set = accton_as4630_54pe_led_psu2_set,
|
||||
.brightness_get = accton_as4630_54pe_led_psu2_get,
|
||||
.flags = LED_CORE_SUSPENDRESUME,
|
||||
.max_brightness = LED_MODE_AUTO,
|
||||
},
|
||||
};
|
||||
|
||||
static int accton_as4630_54pe_led_suspend(struct platform_device *dev,
|
||||
pm_message_t state)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(accton_as4630_54pe_leds); i++) {
|
||||
led_classdev_suspend(&accton_as4630_54pe_leds[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int accton_as4630_54pe_led_resume(struct platform_device *dev)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(accton_as4630_54pe_leds); i++) {
|
||||
led_classdev_resume(&accton_as4630_54pe_leds[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int accton_as4630_54pe_led_probe(struct platform_device *pdev)
|
||||
{
|
||||
int ret, i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(accton_as4630_54pe_leds); i++) {
|
||||
ret = led_classdev_register(&pdev->dev, &accton_as4630_54pe_leds[i]);
|
||||
|
||||
if (ret < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check if all LEDs were successfully registered */
|
||||
if (i != ARRAY_SIZE(accton_as4630_54pe_leds)) {
|
||||
int j;
|
||||
|
||||
/* only unregister the LEDs that were successfully registered */
|
||||
for (j = 0; j < i; j++) {
|
||||
led_classdev_unregister(&accton_as4630_54pe_leds[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int accton_as4630_54pe_led_remove(struct platform_device *pdev)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(accton_as4630_54pe_leds); i++) {
|
||||
led_classdev_unregister(&accton_as4630_54pe_leds[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver accton_as4630_54pe_led_driver = {
|
||||
.probe = accton_as4630_54pe_led_probe,
|
||||
.remove = accton_as4630_54pe_led_remove,
|
||||
.suspend = accton_as4630_54pe_led_suspend,
|
||||
.resume = accton_as4630_54pe_led_resume,
|
||||
.driver = {
|
||||
.name = DRVNAME,
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
};
|
||||
|
||||
static int __init accton_as4630_54pe_led_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = platform_driver_register(&accton_as4630_54pe_led_driver);
|
||||
if (ret < 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ledctl = kzalloc(sizeof(struct accton_as4630_54pe_led_data), GFP_KERNEL);
|
||||
if (!ledctl) {
|
||||
ret = -ENOMEM;
|
||||
platform_driver_unregister(&accton_as4630_54pe_led_driver);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mutex_init(&ledctl->update_lock);
|
||||
|
||||
ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
|
||||
if (IS_ERR(ledctl->pdev)) {
|
||||
ret = PTR_ERR(ledctl->pdev);
|
||||
platform_driver_unregister(&accton_as4630_54pe_led_driver);
|
||||
kfree(ledctl);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit accton_as4630_54pe_led_exit(void)
|
||||
{
|
||||
platform_device_unregister(ledctl->pdev);
|
||||
platform_driver_unregister(&accton_as4630_54pe_led_driver);
|
||||
kfree(ledctl);
|
||||
}
|
||||
|
||||
module_init(accton_as4630_54pe_led_init);
|
||||
module_exit(accton_as4630_54pe_led_exit);
|
||||
|
||||
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION("accton_as4630_54pe_led driver");
|
||||
MODULE_LICENSE("GPL");
|
@ -0,0 +1,320 @@
|
||||
/*
|
||||
* An hwmon driver for accton as4630_54pe Power Module
|
||||
*
|
||||
* Copyright (C) 2014 Accton Technology Corporation.
|
||||
* Brandon Chuang <brandon_chuang@accton.com.tw>
|
||||
*
|
||||
* Based on ad7414.c
|
||||
* Copyright 2006 Stefan Roese <sr at denx.de>, DENX Software Engineering
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/hwmon.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/dmi.h>
|
||||
|
||||
#define MAX_MODEL_NAME 20
|
||||
#define MAX_SERIAL_NUMBER 18
|
||||
|
||||
static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static ssize_t show_string(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static int as4630_54pe_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len);
|
||||
extern int as4630_54pe_cpld_read(unsigned short cpld_addr, u8 reg);
|
||||
|
||||
/* Addresses scanned
|
||||
*/
|
||||
static const unsigned short normal_i2c[] = { 0x50, 0x51, I2C_CLIENT_END };
|
||||
|
||||
/* Each client has this additional data
|
||||
*/
|
||||
struct as4630_54pe_psu_data {
|
||||
struct device *hwmon_dev;
|
||||
struct mutex update_lock;
|
||||
char valid; /* !=0 if registers are valid */
|
||||
unsigned long last_updated; /* In jiffies */
|
||||
u8 index; /* PSU index */
|
||||
u8 status; /* Status(present/power_good) register read from CPLD */
|
||||
char model_name[MAX_MODEL_NAME]; /* Model name, read from eeprom */
|
||||
char serial_number[MAX_SERIAL_NUMBER];
|
||||
};
|
||||
|
||||
static struct as4630_54pe_psu_data *as4630_54pe_psu_update_device(struct device *dev);
|
||||
|
||||
enum as4630_54pe_psu_sysfs_attributes {
|
||||
PSU_PRESENT,
|
||||
PSU_MODEL_NAME,
|
||||
PSU_POWER_GOOD,
|
||||
PSU_SERIAL_NUMBER
|
||||
};
|
||||
|
||||
/* sysfs attributes for hwmon
|
||||
*/
|
||||
static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT);
|
||||
static SENSOR_DEVICE_ATTR(psu_model_name, S_IRUGO, show_string, NULL, PSU_MODEL_NAME);
|
||||
static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD);
|
||||
static SENSOR_DEVICE_ATTR(psu_serial_number, S_IRUGO, show_string, NULL, PSU_SERIAL_NUMBER);
|
||||
|
||||
|
||||
static struct attribute *as4630_54pe_psu_attributes[] = {
|
||||
&sensor_dev_attr_psu_present.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_model_name.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_power_good.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_serial_number.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static ssize_t show_status(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct as4630_54pe_psu_data *data = as4630_54pe_psu_update_device(dev);
|
||||
u8 status = 0;
|
||||
|
||||
//printk("data->status=0x%x, attr->index=%d,data->index=%d \n", data->status, attr->index, data->index);
|
||||
if (attr->index == PSU_PRESENT) {
|
||||
if(data->index==0)
|
||||
status = !( (data->status >> 5) & 0x1);
|
||||
else
|
||||
status = !( (data->status >> 1) & 0x1);
|
||||
}
|
||||
else { /* PSU_POWER_GOOD */
|
||||
if(data->index==0)
|
||||
status = ( (data->status >> 6) & 0x1);
|
||||
else
|
||||
status = ( (data->status >> 2) & 0x1);
|
||||
}
|
||||
|
||||
return sprintf(buf, "%d\n", status);
|
||||
}
|
||||
|
||||
static ssize_t show_string(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct as4630_54pe_psu_data *data = as4630_54pe_psu_update_device(dev);
|
||||
char *ptr = NULL;
|
||||
|
||||
if (!data->valid) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
switch (attr->index) {
|
||||
case PSU_MODEL_NAME:
|
||||
ptr = data->model_name;
|
||||
break;
|
||||
case PSU_SERIAL_NUMBER:
|
||||
ptr = data->serial_number;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return sprintf(buf, "%s\n", ptr);
|
||||
}
|
||||
|
||||
static const struct attribute_group as4630_54pe_psu_group = {
|
||||
.attrs = as4630_54pe_psu_attributes,
|
||||
};
|
||||
|
||||
static int as4630_54pe_psu_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *dev_id)
|
||||
{
|
||||
struct as4630_54pe_psu_data *data;
|
||||
int status;
|
||||
|
||||
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) {
|
||||
status = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
data = kzalloc(sizeof(struct as4630_54pe_psu_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
status = -ENOMEM;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
i2c_set_clientdata(client, data);
|
||||
data->valid = 0;
|
||||
data->index = dev_id->driver_data;
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
dev_info(&client->dev, "chip found\n");
|
||||
|
||||
/* Register sysfs hooks */
|
||||
status = sysfs_create_group(&client->dev.kobj, &as4630_54pe_psu_group);
|
||||
if (status) {
|
||||
goto exit_free;
|
||||
}
|
||||
|
||||
data->hwmon_dev = hwmon_device_register(&client->dev);
|
||||
if (IS_ERR(data->hwmon_dev)) {
|
||||
status = PTR_ERR(data->hwmon_dev);
|
||||
goto exit_remove;
|
||||
}
|
||||
|
||||
dev_info(&client->dev, "%s: psu '%s'\n",
|
||||
dev_name(data->hwmon_dev), client->name);
|
||||
|
||||
return 0;
|
||||
|
||||
exit_remove:
|
||||
sysfs_remove_group(&client->dev.kobj, &as4630_54pe_psu_group);
|
||||
exit_free:
|
||||
kfree(data);
|
||||
exit:
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int as4630_54pe_psu_remove(struct i2c_client *client)
|
||||
{
|
||||
struct as4630_54pe_psu_data *data = i2c_get_clientdata(client);
|
||||
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
sysfs_remove_group(&client->dev.kobj, &as4630_54pe_psu_group);
|
||||
kfree(data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum psu_index
|
||||
{
|
||||
as4630_54pe_psu1,
|
||||
as4630_54pe_psu2
|
||||
};
|
||||
|
||||
static const struct i2c_device_id as4630_54pe_psu_id[] = {
|
||||
{ "as4630_54pe_psu1", as4630_54pe_psu1 },
|
||||
{ "as4630_54pe_psu2", as4630_54pe_psu2 },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, as4630_54pe_psu_id);
|
||||
|
||||
static struct i2c_driver as4630_54pe_psu_driver = {
|
||||
.class = I2C_CLASS_HWMON,
|
||||
.driver = {
|
||||
.name = "as4630_54pe_psu",
|
||||
},
|
||||
.probe = as4630_54pe_psu_probe,
|
||||
.remove = as4630_54pe_psu_remove,
|
||||
.id_table = as4630_54pe_psu_id,
|
||||
.address_list = normal_i2c,
|
||||
};
|
||||
|
||||
static int as4630_54pe_psu_read_block(struct i2c_client *client, u8 command, u8 *data,
|
||||
int data_len)
|
||||
{
|
||||
int result = 0;
|
||||
int retry_count = 5;
|
||||
|
||||
while (retry_count) {
|
||||
retry_count--;
|
||||
|
||||
result = i2c_smbus_read_i2c_block_data(client, command, data_len, data);
|
||||
|
||||
if (unlikely(result < 0)) {
|
||||
msleep(10);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unlikely(result != data_len)) {
|
||||
result = -EIO;
|
||||
msleep(10);
|
||||
continue;
|
||||
}
|
||||
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static struct as4630_54pe_psu_data *as4630_54pe_psu_update_device(struct device *dev)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct as4630_54pe_psu_data *data = i2c_get_clientdata(client);
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|
||||
|| !data->valid) {
|
||||
int status;
|
||||
int power_good = 0;
|
||||
|
||||
dev_dbg(&client->dev, "Starting as4630_54pe update\n");
|
||||
|
||||
/* Read psu status */
|
||||
status = as4630_54pe_cpld_read(0x60, 0x22);
|
||||
//printk("status=0x%x in %s\n", status, __FUNCTION__);
|
||||
if (status < 0) {
|
||||
dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status);
|
||||
}
|
||||
else {
|
||||
data->status = status;
|
||||
}
|
||||
|
||||
/* Read model name */
|
||||
memset(data->model_name, 0, sizeof(data->model_name));
|
||||
memset(data->serial_number, 0, sizeof(data->serial_number));
|
||||
power_good = (data->status >> (3-data->index) & 0x1);
|
||||
|
||||
if (power_good) {
|
||||
status = as4630_54pe_psu_read_block(client, 0x20, data->model_name,
|
||||
ARRAY_SIZE(data->model_name)-1);
|
||||
if (status < 0) {
|
||||
data->model_name[0] = '\0';
|
||||
dev_dbg(&client->dev, "unable to read model name from (0x%x)\n", client->addr);
|
||||
printk("unable to read model name from (0x%x)\n", client->addr);
|
||||
}
|
||||
else {
|
||||
data->model_name[ARRAY_SIZE(data->model_name)-1] = '\0';
|
||||
|
||||
}
|
||||
/* Read from offset 0x2e ~ 0x3d (16 bytes) */
|
||||
status = as4630_54pe_psu_read_block(client, 0x35,data->serial_number, MAX_SERIAL_NUMBER);
|
||||
if (status < 0)
|
||||
{
|
||||
data->serial_number[0] = '\0';
|
||||
dev_dbg(&client->dev, "unable to read model name from (0x%x) offset(0x2e)\n", client->addr);
|
||||
printk("unable to read model name from (0x%x) offset(0x2e)\n", client->addr);
|
||||
}
|
||||
data->serial_number[MAX_SERIAL_NUMBER-1]='\0';
|
||||
}
|
||||
|
||||
data->last_updated = jiffies;
|
||||
data->valid = 1;
|
||||
}
|
||||
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
module_i2c_driver(as4630_54pe_psu_driver);
|
||||
|
||||
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
|
||||
MODULE_DESCRIPTION("as4630_54pe_psu driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
@ -0,0 +1 @@
|
||||
../../common/modules/ym2651y.c
|
@ -0,0 +1,16 @@
|
||||
[Unit]
|
||||
Description=Accton AS4630-54PE Platform Monitoring FAN service
|
||||
Before=pmon.service
|
||||
After=as4630-54pe-platform-monitor.service
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/local/bin/accton_as4630_54pe_monitor_fan.py
|
||||
KillSignal=SIGKILL
|
||||
SuccessExitStatus=SIGKILL
|
||||
|
||||
# Resource Limitations
|
||||
LimitCORE=infinity
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -0,0 +1,16 @@
|
||||
[Unit]
|
||||
Description=Accton AS4630-54PE Platform Monitoring PSU service
|
||||
Before=pmon.service
|
||||
After=as4630-54pe-platform-monitor.service
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/local/bin/accton_as4630_54pe_monitor_psu.py
|
||||
KillSignal=SIGKILL
|
||||
SuccessExitStatus=SIGKILL
|
||||
|
||||
# Resource Limitations
|
||||
LimitCORE=infinity
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -0,0 +1,18 @@
|
||||
[Unit]
|
||||
Description=Accton AS4630-54PE Platform Monitoring service
|
||||
Before=pmon.service
|
||||
After=sysinit.target
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/usr/local/bin/accton_as4630_54pe_util.py install
|
||||
ExecStart=/usr/local/bin/accton_as4630_54pe_monitor.py
|
||||
KillSignal=SIGKILL
|
||||
SuccessExitStatus=SIGKILL
|
||||
#StandardOutput=tty
|
||||
|
||||
# Resource Limitations
|
||||
LimitCORE=infinity
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
16
platform/broadcom/sonic-platform-modules-accton/as4630-54pe/setup.py
Executable file
16
platform/broadcom/sonic-platform-modules-accton/as4630-54pe/setup.py
Executable file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
from setuptools import setup
|
||||
os.listdir
|
||||
|
||||
setup(
|
||||
name='as4630_54pe',
|
||||
version='1.0',
|
||||
description='Module to initialize Accton AS4630-54PE platforms',
|
||||
|
||||
packages=['as4630_54pe'],
|
||||
package_dir={'as4630_54pe': 'as4630-54pe/classes'},
|
||||
)
|
||||
|
117
platform/broadcom/sonic-platform-modules-accton/as4630-54pe/utils/README
Executable file
117
platform/broadcom/sonic-platform-modules-accton/as4630-54pe/utils/README
Executable file
@ -0,0 +1,117 @@
|
||||
Copyright (C) 2016 Accton Networks, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
It under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Contents of this package:
|
||||
patch - files under patch/ is for kernel and ONIE installer
|
||||
for the kernel:
|
||||
config-accton-as5712_54x.patch
|
||||
for kernel configuration.
|
||||
driver-i2c-muxes-pca954x-always-deselect.patch
|
||||
for i2c_mux deselects after transaction.
|
||||
driver-patches-for-accton-as5712-fan-psu-cpld.patch
|
||||
for as5712's fan/psu/cpld/led/sfp drivers.
|
||||
for ONIE:
|
||||
onie_installer-accton-AS5712-54X.patch
|
||||
for console port setting and copy util script o rootfs.
|
||||
module - Contains source code of as5712 kernel driver modules.
|
||||
|
||||
The late Sonic building scripts, pushed @Dec 5 2016, will automatically
|
||||
create a docker container and run building process under it.
|
||||
User is not necessary to handle docker environment creation.
|
||||
|
||||
1. Download sonic-buildimage environment.
|
||||
- Run "git clone https://github.com/Azure/sonic-buildimage".
|
||||
- cd to sonic-buildimage and run "git submodule update --init --recursive".
|
||||
2. Build kernel
|
||||
- cd ./src/sonic-linux-kernel
|
||||
- Copy patches and series from patch/kernel of this release to
|
||||
sonic-linux-kernel/patch.
|
||||
- Build kernel by "make".
|
||||
- The built kernel package, linux-image-3.16.0-5-amd64_3.16.51-3+deb8u1_amd64.deb
|
||||
, is generated.
|
||||
3. Build installer
|
||||
- Change directory back to sonic-buildimage/.
|
||||
- Get onie_installer-accton-AS5712-54X.patch" from patch/installer.
|
||||
- Change setting for AS5712-54X by patching build_image.sh.
|
||||
"patch -p1 < onie_installer-accton-AS5712-54X.patch"
|
||||
!!NOTICE, patching onie_installer-accton-AS5712-54X.patch comments out the
|
||||
"git status" checking at build_image.sh.
|
||||
- The account and password of installed OS can be given at rules/config.
|
||||
The default user and password are "admin" & "YourPaSsWoRd" respectively.
|
||||
- Run "make configure PLATFORM=broadcom"
|
||||
- Copy the built kernel debian package to target/debs/.
|
||||
The file is linux-image-3.16.0-5-amd64_*_amd64.deb under directory
|
||||
src/sonic-linux-kernel/.
|
||||
- Run "make target/sonic-generic.bin"
|
||||
- Get the installer, target/sonic-generic.bin, to target machine and install.
|
||||
|
||||
All Linux kernel code is licensed under the GPLv1. All other code is
|
||||
licensed under the GPLv3. Please see the LICENSE file for copies of
|
||||
both licenses.
|
||||
|
||||
The code for integacting with Accton AS5712-54X has 2 parts,
|
||||
kernel drivers and operational script.
|
||||
The kernel drivers of peripherals are under module/ directory.
|
||||
1. These drivers are patched into kernel by
|
||||
driver-patches-for-accton-as5712-fan-psu-cpld.patch
|
||||
Or you can build the driver under module/ by setting environment variable,
|
||||
KERNEL_SRC, to proper linux built directory and run make.
|
||||
It may be sonic-linux-kernel/linux-3.*/debian/build/build_amd64_none_amd64/.
|
||||
2. A operational script, accton_as5712_util.py, for device initializatian and
|
||||
peripheral accessing should be installed at /usr/bin.
|
||||
This script is generated by onie_installer-accton-AS5712-54X.patch.
|
||||
It's done by patching onie_installer-accton-AS5712-54X.patch at build-image.
|
||||
Run "accton_as5712_util.py install" to install drivers.
|
||||
|
||||
To initialize the system, run "accton_as5712_util.py install".
|
||||
To clean up the drivers & devices, run "accton_as5712_util.py clean".
|
||||
To dump information of sensors, run "accton_as5712_util.py show".
|
||||
To dump SFP EEPROM, run "accton_as5712_util.py sff".
|
||||
To set fan speed, run "accton_as5712_util.py set fan".
|
||||
To enable/disable SFP emission, run "accton_as5712_util.py set sfp".
|
||||
To set system LEDs' color, run "accton_as5712_util.py set led"
|
||||
For more information, run "accton_as5712_util.py --help".
|
||||
|
||||
====================================================================
|
||||
Besides applying accton_as5712_util.py to access peripherals, you can
|
||||
access peripherals by sysfs nodes directly after the installation is run.
|
||||
|
||||
System LED:
|
||||
There are 5 system LEDs at the lower-left corner of front panel.
|
||||
They are loc, diag, fan, ps1, and ps2.
|
||||
The sysfs interface color mappings are as follows:
|
||||
Brightness:
|
||||
0 => off
|
||||
1 => green
|
||||
2 => amber
|
||||
3 => red
|
||||
4 => blue
|
||||
But not all colors are available for each LED.
|
||||
|
||||
Fan Control:
|
||||
There are 10 fans inside 5 fan modules.
|
||||
All fans share 1 duty setting, ranged from 0~100.
|
||||
|
||||
Thermal sensers:
|
||||
3 temperature sensors are controlled by the lm75 kernel modules.
|
||||
|
||||
PSUs:
|
||||
There 2 power supplies slot at the left/right side of the back.
|
||||
Once if a PSU is not plugged, the status of it is shown failed.
|
||||
|
||||
There are 48 SFP+ and 6 QSFP modules are equipped.
|
||||
Before operating on PSU and QSFP+, please make sure it is well plugged.
|
||||
Otherwise, operation is going to fail.
|
||||
|
@ -0,0 +1,345 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2017 Accton Technology Corporation
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# HISTORY:
|
||||
# mm/dd/yyyy (A.D.)#
|
||||
# 4/20/2018: Jostar modify for as7726_32x
|
||||
# 12/03/2018:Jostar modify for as7726_32x thermal plan
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
try:
|
||||
import os
|
||||
import sys, getopt
|
||||
import subprocess
|
||||
import click
|
||||
import imp
|
||||
import logging
|
||||
import logging.config
|
||||
import logging.handlers
|
||||
import types
|
||||
import time # this is only being used as part of the example
|
||||
import traceback
|
||||
from tabulate import tabulate
|
||||
from as7726_32x.fanutil import FanUtil
|
||||
from as7726_32x.thermalutil import ThermalUtil
|
||||
except ImportError as e:
|
||||
raise ImportError('%s - required module not found' % str(e))
|
||||
|
||||
# Deafults
|
||||
VERSION = '1.0'
|
||||
FUNCTION_NAME = '/usr/local/bin/accton_as4630_54pe_monitor'
|
||||
|
||||
global log_file
|
||||
global log_level
|
||||
|
||||
|
||||
# Air Flow Front to Back :
|
||||
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 <=38C : Keep 37.5%(0x04) Fan speed
|
||||
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 38C : Change Fan speed from 37.5%(0x04) to 62.5%(0x08)
|
||||
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 46C : Change Fan speed from 62.5%(0x08) to 100%(0x0E)
|
||||
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 58C : Send alarm message
|
||||
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 66C : Shut down system
|
||||
# One Fan fail : Change Fan speed to 100%(0x0E)
|
||||
|
||||
|
||||
# Air Flow Back to Front :
|
||||
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 <=34C : Keep 37.5%(0x04) Fan speed
|
||||
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 34C : Change Fan speed from 37.5%(0x04) to 62.5%(0x08)
|
||||
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 44C : Change Fan speed from 62.5%(0x08) to 100%(0x0E)
|
||||
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 59C : Send alarm message
|
||||
# (Thermal sensor_LM75_4A + Thermal sensor_LM75_CPU) /2 > 67C : Shut down system
|
||||
# One Fan fail: Change Fan speed to 100%(0x0E)
|
||||
# sensor_LM75_CPU == sensor_LM75_4B
|
||||
|
||||
|
||||
class switch(object):
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
self.fall = False
|
||||
|
||||
def __iter__(self):
|
||||
"""Return the match method once, then stop"""
|
||||
yield self.match
|
||||
raise StopIteration
|
||||
|
||||
def match(self, *args):
|
||||
"""Indicate whether or not to enter a case suite"""
|
||||
if self.fall or not args:
|
||||
return True
|
||||
elif self.value in args: # changed for v1.5, see below
|
||||
self.fall = True
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
fan_policy_state=1
|
||||
fan_fail=0
|
||||
alarm_state = 0 #0->default or clear, 1-->alarm detect
|
||||
test_temp = 0
|
||||
test_temp_list = [0, 0, 0, 0, 0, 0]
|
||||
temp_test_data=0
|
||||
# Make a class we can use to capture stdout and sterr in the log
|
||||
class device_monitor(object):
|
||||
# static temp var
|
||||
temp = 0
|
||||
new_pwm = 0
|
||||
pwm=0
|
||||
ori_pwm = 0
|
||||
default_pwm=0x4
|
||||
|
||||
def __init__(self, log_file, log_level):
|
||||
"""Needs a logger and a logger level."""
|
||||
# set up logging to file
|
||||
logging.basicConfig(
|
||||
filename=log_file,
|
||||
filemode='w',
|
||||
level=log_level,
|
||||
format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s',
|
||||
datefmt='%H:%M:%S'
|
||||
)
|
||||
# set up logging to console
|
||||
if log_level == logging.DEBUG:
|
||||
console = logging.StreamHandler()
|
||||
console.setLevel(log_level)
|
||||
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
|
||||
console.setFormatter(formatter)
|
||||
logging.getLogger('').addHandler(console)
|
||||
|
||||
sys_handler = handler = logging.handlers.SysLogHandler(address = '/dev/log')
|
||||
sys_handler.setLevel(logging.WARNING)
|
||||
logging.getLogger('').addHandler(sys_handler)
|
||||
|
||||
#logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level)
|
||||
|
||||
def get_state_from_fan_policy(self, temp, policy):
|
||||
state=0
|
||||
|
||||
logging.debug('temp=%d', temp)
|
||||
for i in range(0, len(policy)):
|
||||
#logging.debug('policy[%d][0]=%d, policy[%d][1]=%d, policy[%d][2]=%d', i,policy[i][0],i, policy[i][1], i, policy[i][2])
|
||||
if temp > policy[i][2]:
|
||||
if temp <= policy[i][3]:
|
||||
state =i
|
||||
logging.debug ('temp=%d >= policy[%d][2]=%d, temp=%d < policy[%d][3]=%d' , temp, i, policy[i][2], temp, i, policy[i][3])
|
||||
logging.debug ('fan_state=%d', state)
|
||||
break
|
||||
|
||||
return state
|
||||
|
||||
|
||||
def manage_fans(self):
|
||||
|
||||
global fan_policy_state
|
||||
global fan_fail
|
||||
global test_temp
|
||||
global test_temp_list
|
||||
global alarm_state
|
||||
global temp_test_data
|
||||
|
||||
LEVEL_FAN_DEF=0
|
||||
LEVEL_FAN_MID=1
|
||||
LEVEL_FAN_MAX=2
|
||||
LEVEL_TEMP_HIGH=3
|
||||
LEVEL_TEMP_CRITICAL=4
|
||||
|
||||
|
||||
fan_policy_f2b = {
|
||||
LEVEL_FAN_DEF: [38, 0x4, 0, 38000],
|
||||
LEVEL_FAN_MID: [63, 0x6, 38000, 46000],
|
||||
LEVEL_FAN_MAX: [100, 0xE, 46000, 58000],
|
||||
LEVEL_TEMP_HIGH: [100, 0xE, 58000, 66000],
|
||||
LEVEL_TEMP_CRITICAL: [100, 0xE, 58000, 200000],
|
||||
}
|
||||
fan_policy_b2f = {
|
||||
LEVEL_FAN_DEF: [38, 0x4, 0, 34000],
|
||||
LEVEL_FAN_MID: [63, 0x8, 34000, 44000],
|
||||
LEVEL_FAN_MAX: [100, 0xE, 44000, 59000],
|
||||
LEVEL_TEMP_HIGH: [100, 0xE, 59000, 67000],
|
||||
LEVEL_TEMP_CRITICAL: [100, 0xE, 59000, 200000],
|
||||
}
|
||||
|
||||
fan_policy = fan_policy_f2b
|
||||
|
||||
thermal = ThermalUtil()
|
||||
fan = FanUtil()
|
||||
fan_dir=fan.get_fan_dir(1)
|
||||
if fan_dir == 1:
|
||||
fan_dri=1 #something wrong, set fan_dir to default val
|
||||
else:
|
||||
fan_policy = fan_policy_b2f
|
||||
|
||||
ori_pwm=fan.get_fan_duty_cycle()
|
||||
new_pwm=0
|
||||
logging.debug('fan_dir=%d, ori_pwm=%d', fan_dir, ori_pwm)
|
||||
logging.debug('test_temp=%d', test_temp)
|
||||
if test_temp==0:
|
||||
temp1 = thermal._get_thermal_val(1)
|
||||
temp2 = thermal._get_thermal_val(2)
|
||||
temp3 = thermal._get_thermal_val(3)
|
||||
temp4 = thermal._get_thermal_val(4)
|
||||
temp5 = thermal._get_thermal_val(5)
|
||||
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]
|
||||
fan_fail=0
|
||||
|
||||
if temp3==0:
|
||||
temp_get=50000 # if one detect sensor is fail or zero, assign temp=50000, let fan to 75%
|
||||
logging.debug('lm75_49 detect fail, so set temp_get=50000, let fan to 75%')
|
||||
elif temp4==0:
|
||||
temp_get=50000 # if one detect sensor is fail or zero, assign temp=50000, let fan to 75%
|
||||
logging.debug('lm75_4b detect fail, so set temp_get=50000, let fan to 75%')
|
||||
else:
|
||||
temp_get= (temp3 + temp4)/2 # Use (sensor_LM75_4a + sensor_LM75_4b) /2
|
||||
ori_state=fan_policy_state
|
||||
|
||||
#temp_test_data=temp_test_data+1000
|
||||
#temp_get = temp_get + temp_test_data
|
||||
#print "Unit test:temp_get=%d"%temp_get
|
||||
|
||||
fan_policy_state=self.get_state_from_fan_policy(temp_get, fan_policy)
|
||||
#print "temp3=%d"%temp3
|
||||
#print "temp4=%d"%temp4
|
||||
#print "temp_get=%d"%temp_get
|
||||
|
||||
logging.debug('lm75_48=%d, lm75_49=%d, lm75_4a=%d, lm_4b=%d, lm_4b=%d', temp1,temp2,temp3,temp4,temp5)
|
||||
logging.debug('ori_state=%d, fan_policy_state=%d', ori_state, fan_policy_state)
|
||||
new_pwm = fan_policy[fan_policy_state][0]
|
||||
if fan_fail==0:
|
||||
logging.debug('new_fan_cycle=%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)
|
||||
|
||||
#Check Fan status
|
||||
for i in range (fan.FAN_NUM_1_IDX, fan.FAN_NUM_ON_MAIN_BROAD+1):
|
||||
if fan.get_fan_status(i)==0:
|
||||
new_pwm=100
|
||||
logging.debug('fan_%d fail, set pwm to 100',i)
|
||||
if test_temp==0:
|
||||
fan_fail=1
|
||||
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
|
||||
|
||||
#logging.warning('Temperature high alarm testing')
|
||||
if ori_state==LEVEL_FAN_DEF:
|
||||
if new_state==LEVEL_TEMP_HIGH:
|
||||
if alarm_state==0:
|
||||
logging.warning('Alarm for temperature high is detected')
|
||||
alarm_state=1
|
||||
if new_state==LEVEL_TEMP_CRITICAL:
|
||||
logging.critical('Alarm for temperature critical is detected, reboot DUT')
|
||||
time.sleep(2)
|
||||
os.system('reboot')
|
||||
if ori_state==LEVEL_FAN_MID:
|
||||
if new_state==LEVEL_TEMP_HIGH:
|
||||
if alarm_state==0:
|
||||
logging.warning('Alarm for temperature high is detected')
|
||||
alarm_state=1
|
||||
if new_state==LEVEL_TEMP_CRITICAL:
|
||||
logging.critical('Alarm for temperature critical is detected')
|
||||
time.sleep(2)
|
||||
os.system('reboot')
|
||||
if ori_state==LEVEL_FAN_MAX:
|
||||
if new_state==LEVEL_TEMP_HIGH:
|
||||
if alarm_state==0:
|
||||
logging.warning('Alarm for temperature high is detected')
|
||||
alarm_state=1
|
||||
if new_state==LEVEL_TEMP_CRITICAL:
|
||||
logging.critical('Alarm for temperature critical is detected')
|
||||
time.sleep(2)
|
||||
os.system('reboot')
|
||||
if alarm_state==1:
|
||||
if temp_get < (fan_policy[3][0] - 5000): #below 65 C, clear alarm
|
||||
logging.warning('Alarm for temperature high is cleared')
|
||||
alarm_state=0
|
||||
if ori_state==LEVEL_TEMP_HIGH:
|
||||
if new_state==LEVEL_TEMP_CRITICAL:
|
||||
logging.critical('Alarm for temperature critical is detected')
|
||||
time.sleep(2)
|
||||
os.system('reboot')
|
||||
if new_state <= LEVEL_FAN_MID:
|
||||
logging.warning('Alarm for temperature high is cleared')
|
||||
alarm_state=0
|
||||
if new_state <= LEVEL_FAN_MAX:
|
||||
if temp_get < (fan_policy[3][0] - 5000): #below 65 C, clear alarm
|
||||
logging.warning('Alarm for temperature high is cleared')
|
||||
alarm_state=0
|
||||
if ori_state==LEVEL_TEMP_CRITICAL:
|
||||
if new_state <= LEVEL_FAN_MAX:
|
||||
logging.warning('Alarm for temperature critical is cleared')
|
||||
|
||||
return True
|
||||
|
||||
def main(argv):
|
||||
log_file = '%s.log' % FUNCTION_NAME
|
||||
log_level = logging.INFO
|
||||
global test_temp
|
||||
if len(sys.argv) != 1:
|
||||
try:
|
||||
opts, args = getopt.getopt(argv,'hdlt:',['lfile='])
|
||||
except getopt.GetoptError:
|
||||
print 'Usage: %s [-d] [-l <log_file>]' % sys.argv[0]
|
||||
return 0
|
||||
for opt, arg in opts:
|
||||
if opt == '-h':
|
||||
print 'Usage: %s [-d] [-l <log_file>]' % sys.argv[0]
|
||||
return 0
|
||||
elif opt in ('-d', '--debug'):
|
||||
log_level = logging.DEBUG
|
||||
elif opt in ('-l', '--lfile'):
|
||||
log_file = arg
|
||||
|
||||
if sys.argv[1]== '-t':
|
||||
if len(sys.argv)!=7:
|
||||
print "temp test, need input six temp"
|
||||
return 0
|
||||
|
||||
i=0
|
||||
for x in range(2, 7):
|
||||
test_temp_list[i]= int(sys.argv[x])*1000
|
||||
i=i+1
|
||||
test_temp = 1
|
||||
log_level = logging.DEBUG
|
||||
print test_temp_list
|
||||
|
||||
fan = FanUtil()
|
||||
fan.set_fan_duty_cycle(38)
|
||||
print "set default fan speed to 37.5%"
|
||||
monitor = device_monitor(log_file, log_level)
|
||||
# Loop forever, doing something useful hopefully:
|
||||
while True:
|
||||
#monitor.manage_fans()
|
||||
time.sleep(5)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv[1:])
|
||||
|
@ -0,0 +1,191 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2018 Accton Technology Corporation
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# HISTORY:
|
||||
# mm/dd/yyyy (A.D.)
|
||||
# 5/15/2019: Jostar create for as4630-54pe
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
try:
|
||||
import os
|
||||
import sys, getopt
|
||||
import subprocess
|
||||
import click
|
||||
import imp
|
||||
import logging
|
||||
import logging.config
|
||||
import logging.handlers
|
||||
import types
|
||||
import time # this is only being used as part of the example
|
||||
import traceback
|
||||
from tabulate import tabulate
|
||||
|
||||
except ImportError as e:
|
||||
raise ImportError('%s - required module not found' % str(e))
|
||||
|
||||
# Deafults
|
||||
VERSION = '1.0'
|
||||
FUNCTION_NAME = '/usr/local/bin/accton_as4630_54pe_monitor_fan'
|
||||
|
||||
global log_file
|
||||
global log_level
|
||||
|
||||
|
||||
class switch(object):
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
self.fall = False
|
||||
|
||||
def __iter__(self):
|
||||
"""Return the match method once, then stop"""
|
||||
yield self.match
|
||||
raise StopIteration
|
||||
|
||||
def match(self, *args):
|
||||
"""Indicate whether or not to enter a case suite"""
|
||||
if self.fall or not args:
|
||||
return True
|
||||
elif self.value in args: # changed for v1.5, see below
|
||||
self.fall = True
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
fan_state=[2, 2, 2, 2] #init state=2, insert=1, remove=0
|
||||
fan_status_state=[2, 2, 2, 2] #init state=2, fault=1, normal=0
|
||||
# Make a class we can use to capture stdout and sterr in the log
|
||||
class device_monitor(object):
|
||||
|
||||
def __init__(self, log_file, log_level):
|
||||
|
||||
self.fan_num = 3
|
||||
self.fan_path = "/sys/bus/i2c/devices/3-0060/"
|
||||
self.present = {
|
||||
0: "fan_present_1",
|
||||
1: "fan_present_2",
|
||||
2: "fan_present_3",
|
||||
}
|
||||
|
||||
self.fault = {
|
||||
0: "fan_fault_1",
|
||||
1: "fan_fault_2",
|
||||
2: "fan_fault_3",
|
||||
}
|
||||
|
||||
|
||||
"""Needs a logger and a logger level."""
|
||||
# set up logging to file
|
||||
logging.basicConfig(
|
||||
filename=log_file,
|
||||
filemode='w',
|
||||
level=log_level,
|
||||
format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s',
|
||||
datefmt='%H:%M:%S'
|
||||
)
|
||||
|
||||
# set up logging to console
|
||||
if log_level == logging.DEBUG:
|
||||
console = logging.StreamHandler()
|
||||
console.setLevel(logging.DEBUG)
|
||||
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
|
||||
console.setFormatter(formatter)
|
||||
logging.getLogger('').addHandler(console)
|
||||
|
||||
sys_handler = logging.handlers.SysLogHandler(address = '/dev/log')
|
||||
#sys_handler.setLevel(logging.WARNING)
|
||||
sys_handler.setLevel(logging.INFO)
|
||||
logging.getLogger('').addHandler(sys_handler)
|
||||
|
||||
|
||||
#logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level)
|
||||
|
||||
def manage_fan(self):
|
||||
|
||||
FAN_STATE_REMOVE = 0
|
||||
FAN_STATE_INSERT = 1
|
||||
|
||||
FAN_STATUS_FAULT = 1
|
||||
FAN_STATUS_NORMAL = 0
|
||||
|
||||
global fan_state
|
||||
global fan_status_state
|
||||
|
||||
for idx in range (0, self.fan_num):
|
||||
node = self.fan_path + self.present[idx]
|
||||
try:
|
||||
val_file = open(node)
|
||||
except IOError as e:
|
||||
print "Error: unable to open file: %s" % str(e)
|
||||
return False
|
||||
content = val_file.readline().rstrip()
|
||||
val_file.close()
|
||||
# content is a string, either "0" or "1"
|
||||
if content == "1":
|
||||
if fan_state[idx]!=1:
|
||||
fan_state[idx]=FAN_STATE_INSERT
|
||||
logging.info("FAN-%d present is detected", idx+1);
|
||||
else:
|
||||
if fan_state[idx]!=0:
|
||||
fan_state[idx]=FAN_STATE_REMOVE
|
||||
logging.warning("Alarm for FAN-%d absent is detected", idx+1)
|
||||
|
||||
for idx in range (0, self.fan_num):
|
||||
node = self.fan_path + self.fault[idx]
|
||||
try:
|
||||
val_file = open(node)
|
||||
except IOError as e:
|
||||
print "Error: unable to open file: %s" % str(e)
|
||||
return False
|
||||
content = val_file.readline().rstrip()
|
||||
val_file.close()
|
||||
# content is a string, either "0" or "1"
|
||||
if content == "1":
|
||||
if fan_status_state[idx]!=FAN_STATUS_FAULT:
|
||||
if fan_state[idx] == FAN_STATE_INSERT:
|
||||
logging.warning("Alarm for FAN-%d failed is detected", idx+1);
|
||||
fan_status_state[idx]=FAN_STATUS_FAULT
|
||||
else:
|
||||
fan_status_state[idx]=FAN_STATUS_NORMAL
|
||||
|
||||
return True
|
||||
|
||||
def main(argv):
|
||||
log_file = '%s.log' % FUNCTION_NAME
|
||||
log_level = logging.INFO
|
||||
if len(sys.argv) != 1:
|
||||
try:
|
||||
opts, args = getopt.getopt(argv,'hdl:',['lfile='])
|
||||
except getopt.GetoptError:
|
||||
print 'Usage: %s [-d] [-l <log_file>]' % sys.argv[0]
|
||||
return 0
|
||||
for opt, arg in opts:
|
||||
if opt == '-h':
|
||||
print 'Usage: %s [-d] [-l <log_file>]' % sys.argv[0]
|
||||
return 0
|
||||
elif opt in ('-d', '--debug'):
|
||||
log_level = logging.DEBUG
|
||||
elif opt in ('-l', '--lfile'):
|
||||
log_file = arg
|
||||
monitor = device_monitor(log_file, log_level)
|
||||
while True:
|
||||
monitor.manage_fan()
|
||||
time.sleep(3)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv[1:])
|
@ -0,0 +1,169 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2018 Accton Technology Corporation
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# HISTORY:
|
||||
# mm/dd/yyyy (A.D.)
|
||||
# 5/15/2019: Jostar create for as4630-54pe
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
try:
|
||||
import os
|
||||
import sys, getopt
|
||||
import subprocess
|
||||
import click
|
||||
import imp
|
||||
import logging
|
||||
import logging.config
|
||||
import logging.handlers
|
||||
import types
|
||||
import time # this is only being used as part of the example
|
||||
import traceback
|
||||
from tabulate import tabulate
|
||||
except ImportError as e:
|
||||
raise ImportError('%s - required module not found' % str(e))
|
||||
|
||||
# Deafults
|
||||
VERSION = '1.0'
|
||||
FUNCTION_NAME = '/usr/local/bin/accton_as4630_54pe_monitor_psu'
|
||||
|
||||
global log_file
|
||||
global log_level
|
||||
|
||||
|
||||
psu_state=[2, 2]
|
||||
psu_status_state=[2, 2]
|
||||
# Make a class we can use to capture stdout and sterr in the log
|
||||
class device_monitor(object):
|
||||
|
||||
def __init__(self, log_file, log_level):
|
||||
|
||||
self.psu_num = 2
|
||||
self.psu_path = "/sys/bus/i2c/devices/"
|
||||
self.presence = "/psu_present"
|
||||
self.oper_status = "/psu_power_good"
|
||||
self.mapping = {
|
||||
0: "10-0050",
|
||||
1: "11-0051",
|
||||
}
|
||||
|
||||
"""Needs a logger and a logger level."""
|
||||
# set up logging to file
|
||||
logging.basicConfig(
|
||||
filename=log_file,
|
||||
filemode='w',
|
||||
level=log_level,
|
||||
format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s',
|
||||
datefmt='%H:%M:%S'
|
||||
)
|
||||
# set up logging to console
|
||||
|
||||
if log_level == logging.DEBUG:
|
||||
console = logging.StreamHandler()
|
||||
console.setLevel(log_level)
|
||||
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
|
||||
console.setFormatter(formatter)
|
||||
logging.getLogger('').addHandler(console)
|
||||
|
||||
sys_handler = logging.handlers.SysLogHandler(address = '/dev/log')
|
||||
#sys_handler.setLevel(logging.WARNING)
|
||||
sys_handler.setLevel(logging.INFO)
|
||||
logging.getLogger('').addHandler(sys_handler)
|
||||
|
||||
#logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level)
|
||||
|
||||
def manage_psu(self):
|
||||
|
||||
PSU_STATE_REMOVE = 0
|
||||
PSU_STATE_INSERT = 1
|
||||
|
||||
PSU_STATUS_NO_POWER = 0
|
||||
PSU_STATUS_POWER_GOOD = 1
|
||||
PSU_STATUS_IDLE =2
|
||||
|
||||
global psu_state
|
||||
|
||||
for idx in range (0, self.psu_num):
|
||||
node = self.psu_path + self.mapping[idx] + self.presence
|
||||
try:
|
||||
val_file = open(node)
|
||||
except IOError as e:
|
||||
print "Error: unable to open file: %s" % str(e)
|
||||
return False
|
||||
content = val_file.readline().rstrip()
|
||||
val_file.close()
|
||||
# content is a string, either "0" or "1"
|
||||
if content == "1":
|
||||
if psu_state[idx]!=1:
|
||||
psu_state[idx]=PSU_STATE_INSERT
|
||||
logging.info("PSU-%d present is detected", idx+1);
|
||||
#psu_status_state[idx]=PSU_STATUS_POWER_GOOD #when insert, assume power is good. If no_power, next code will find it.
|
||||
else:
|
||||
if psu_state[idx]!=0:
|
||||
psu_state[idx]=PSU_STATE_REMOVE
|
||||
logging.warning("Alarm for PSU-%d absent is detected", idx+1);
|
||||
psu_status_state[idx]=PSU_STATUS_IDLE
|
||||
|
||||
for idx in range (0, self.psu_num):
|
||||
node = self.psu_path + self.mapping[idx] + self.oper_status
|
||||
try:
|
||||
val_file = open(node)
|
||||
except IOError as e:
|
||||
print "Error: unable to open file: %s" % str(e)
|
||||
return False
|
||||
content = val_file.readline().rstrip()
|
||||
val_file.close()
|
||||
# content is a string, either "0" or "1"
|
||||
if content == "0":
|
||||
if psu_status_state[idx]!=PSU_STATUS_NO_POWER:
|
||||
if psu_state[idx]==PSU_STATE_INSERT:
|
||||
logging.warning("Alarm for PSU-%d failed is detected", idx+1);
|
||||
psu_status_state[idx]=PSU_STATUS_NO_POWER
|
||||
else:
|
||||
if psu_state[idx]==PSU_STATE_INSERT:
|
||||
if psu_status_state[idx]!=PSU_STATUS_POWER_GOOD:
|
||||
logging.info("PSU-%d power_good is detected", idx+1);
|
||||
psu_status_state[idx]=PSU_STATUS_POWER_GOOD
|
||||
|
||||
|
||||
return True
|
||||
|
||||
def main(argv):
|
||||
log_file = '%s.log' % FUNCTION_NAME
|
||||
log_level = logging.INFO
|
||||
if len(sys.argv) != 1:
|
||||
try:
|
||||
opts, args = getopt.getopt(argv,'hdl:',['lfile='])
|
||||
except getopt.GetoptError:
|
||||
print 'Usage: %s [-d] [-l <log_file>]' % sys.argv[0]
|
||||
return 0
|
||||
for opt, arg in opts:
|
||||
if opt == '-h':
|
||||
print 'Usage: %s [-d] [-l <log_file>]' % sys.argv[0]
|
||||
return 0
|
||||
elif opt in ('-d', '--debug'):
|
||||
log_level = logging.DEBUG
|
||||
elif opt in ('-l', '--lfile'):
|
||||
log_file = arg
|
||||
monitor = device_monitor(log_file, log_level)
|
||||
# Loop forever, doing something useful hopefully:
|
||||
while True:
|
||||
monitor.manage_psu()
|
||||
time.sleep(3)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv[1:])
|
@ -0,0 +1,563 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2016 Accton Networks, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
Usage: %(scriptName)s [options] command object
|
||||
|
||||
options:
|
||||
-h | --help : this help message
|
||||
-d | --debug : run with debug mode
|
||||
-f | --force : ignore error during installation or clean
|
||||
command:
|
||||
install : install drivers and generate related sysfs nodes
|
||||
clean : uninstall drivers and remove related sysfs nodes
|
||||
show : show all systen status
|
||||
sff : dump SFP eeprom
|
||||
set : change board setting with fan|led|sfp
|
||||
"""
|
||||
|
||||
import os
|
||||
import commands
|
||||
import sys, getopt
|
||||
import logging
|
||||
import re
|
||||
import time
|
||||
from collections import namedtuple
|
||||
|
||||
PROJECT_NAME = 'as4630_54pe'
|
||||
version = '0.0.1'
|
||||
verbose = False
|
||||
DEBUG = False
|
||||
args = []
|
||||
ALL_DEVICE = {}
|
||||
DEVICE_NO = {'led':5, 'fan1':1, 'fan2':1,'fan3':1,'fan4':1,'fan5':1,'thermal':3, 'psu':2, 'sfp':54}
|
||||
|
||||
|
||||
led_prefix ='/sys/devices/platform/as4630_54pe_led/leds/accton_'+PROJECT_NAME+'_led::'
|
||||
fan_prefix ='/sys/devices/platform/as4630_54pe_'
|
||||
hwmon_types = {'led': ['diag','fan','loc','psu1','psu2'],
|
||||
'fan1': ['fan'],
|
||||
'fan2': ['fan'],
|
||||
'fan3': ['fan'],
|
||||
'fan4': ['fan'],
|
||||
'fan5': ['fan'],
|
||||
'fan5': ['fan'],
|
||||
}
|
||||
hwmon_nodes = {'led': ['brightness'] ,
|
||||
'fan1': ['fan_duty_cycle_percentage', 'fan1_fault', 'fan1_speed_rpm', 'fan1_direction', 'fanr1_fault', 'fanr1_speed_rpm'],
|
||||
'fan2': ['fan_duty_cycle_percentage','fan2_fault', 'fan2_speed_rpm', 'fan2_direction', 'fanr2_fault', 'fanr2_speed_rpm'],
|
||||
'fan3': ['fan_duty_cycle_percentage','fan3_fault', 'fan3_speed_rpm', 'fan3_direction', 'fanr3_fault', 'fanr3_speed_rpm'],
|
||||
'fan4': ['fan4_duty_cycle_percentage','fan4_fault', 'fan4_speed_rpm', 'fan4_direction', 'fanr4_fault', 'fanr4_speed_rpm'],
|
||||
'fan5': ['fan_duty_cycle_percentage','fan5_fault', 'fan5_speed_rpm', 'fan5_direction', 'fanr5_fault', 'fanr5_speed_rpm'],
|
||||
}
|
||||
hwmon_prefix ={'led': led_prefix,
|
||||
'fan1': fan_prefix,
|
||||
'fan2': fan_prefix,
|
||||
'fan3': fan_prefix,
|
||||
'fan4': fan_prefix,
|
||||
'fan5': fan_prefix,
|
||||
}
|
||||
|
||||
i2c_prefix = '/sys/bus/i2c/devices/'
|
||||
i2c_bus = {'fan': ['54-0066'],
|
||||
'thermal': ['54-004c', '55-0048','55-0049', '55-004a', '55-004b'] ,
|
||||
'psu': ['49-0050','50-0053'],
|
||||
'sfp': ['-0050']}
|
||||
i2c_nodes = {'fan': ['present', 'front_speed_rpm', 'rear_speed_rpm'],
|
||||
'thermal': ['hwmon/hwmon*/temp1_input'] ,
|
||||
'psu': ['psu_present ', 'psu_power_good'] ,
|
||||
'sfp': ['module_present_ ', 'module_tx_disable_']}
|
||||
|
||||
sfp_map = [18, 19, 20, 21, 22, 23]
|
||||
|
||||
mknod =[
|
||||
'echo pca9548 0x77 > /sys/bus/i2c/devices/i2c-1/new_device',
|
||||
'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-2/new_device',
|
||||
'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-3/new_device',
|
||||
|
||||
'echo as4630_54pe_cpld 0x60 > /sys/bus/i2c/devices/i2c-3/new_device',
|
||||
|
||||
'echo lm77 0x48 > /sys/bus/i2c/devices/i2c-14/new_device',
|
||||
'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-25/new_device',
|
||||
'echo lm75 0x4b > /sys/bus/i2c/devices/i2c-24/new_device',
|
||||
|
||||
|
||||
# PSU-1
|
||||
'echo as4630_54pe_psu1 0x50 > /sys/bus/i2c/devices/i2c-10/new_device',
|
||||
'echo ype1200am 0x58 > /sys/bus/i2c/devices/i2c-10/new_device',
|
||||
|
||||
# PSU-2
|
||||
'echo as4630_54pe_psu2 0x51> /sys/bus/i2c/devices/i2c-11/new_device',
|
||||
'echo ype1200am 0x59 > /sys/bus/i2c/devices/i2c-11/new_device',
|
||||
|
||||
#EERPOM
|
||||
'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-1/new_device',
|
||||
]
|
||||
|
||||
|
||||
|
||||
FORCE = 0
|
||||
logging.basicConfig(filename= PROJECT_NAME+'.log', filemode='w',level=logging.DEBUG)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
if DEBUG == True:
|
||||
print sys.argv[0]
|
||||
print 'ARGV :', sys.argv[1:]
|
||||
|
||||
|
||||
def main():
|
||||
global DEBUG
|
||||
global args
|
||||
global FORCE
|
||||
|
||||
if len(sys.argv)<2:
|
||||
show_help()
|
||||
|
||||
options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help',
|
||||
'debug',
|
||||
'force',
|
||||
])
|
||||
if DEBUG == True:
|
||||
print options
|
||||
print args
|
||||
print len(sys.argv)
|
||||
|
||||
for opt, arg in options:
|
||||
if opt in ('-h', '--help'):
|
||||
show_help()
|
||||
elif opt in ('-d', '--debug'):
|
||||
DEBUG = True
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
elif opt in ('-f', '--force'):
|
||||
FORCE = 1
|
||||
else:
|
||||
print "TEST"
|
||||
logging.info('no option')
|
||||
for arg in args:
|
||||
if arg == 'install':
|
||||
do_install()
|
||||
elif arg == 'clean':
|
||||
do_uninstall()
|
||||
elif arg == 'show':
|
||||
device_traversal()
|
||||
elif arg == 'sff':
|
||||
if len(args)!=2:
|
||||
show_eeprom_help()
|
||||
elif int(args[1]) ==0 or int(args[1]) > DEVICE_NO['sfp']:
|
||||
show_eeprom_help()
|
||||
else:
|
||||
show_eeprom(args[1])
|
||||
return
|
||||
elif arg == 'set':
|
||||
if len(args)<3:
|
||||
show_set_help()
|
||||
else:
|
||||
set_device(args[1:])
|
||||
return
|
||||
else:
|
||||
show_help()
|
||||
|
||||
|
||||
return 0
|
||||
|
||||
def show_help():
|
||||
print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]}
|
||||
sys.exit(0)
|
||||
|
||||
def show_set_help():
|
||||
cmd = sys.argv[0].split("/")[-1]+ " " + args[0]
|
||||
print cmd +" [led|sfp|fan]"
|
||||
print " use \""+ cmd + " led 0-4 \" to set led color"
|
||||
print " use \""+ cmd + " fan 0-100\" to set fan duty percetage"
|
||||
print " use \""+ cmd + " sfp 1-32 {0|1}\" to set sfp# tx_disable"
|
||||
sys.exit(0)
|
||||
|
||||
def show_eeprom_help():
|
||||
cmd = sys.argv[0].split("/")[-1]+ " " + args[0]
|
||||
print " use \""+ cmd + " 1-32 \" to dump sfp# eeprom"
|
||||
sys.exit(0)
|
||||
|
||||
def my_log(txt):
|
||||
if DEBUG == True:
|
||||
print "[ACCTON DBG]: "+txt
|
||||
return
|
||||
|
||||
def log_os_system(cmd, show):
|
||||
logging.info('Run :'+cmd)
|
||||
status = 1
|
||||
output = ""
|
||||
status, output = commands.getstatusoutput(cmd)
|
||||
my_log (cmd +"with result:" + str(status))
|
||||
my_log ("cmd:" + cmd)
|
||||
my_log (" output:"+output)
|
||||
if status:
|
||||
logging.info('Failed :'+cmd)
|
||||
if show:
|
||||
print('Failed :'+cmd)
|
||||
return status, output
|
||||
|
||||
def driver_inserted():
|
||||
ret, lsmod = log_os_system("lsmod| grep accton", 0)
|
||||
logging.info('mods:'+lsmod)
|
||||
if len(lsmod) ==0:
|
||||
return False
|
||||
|
||||
#'modprobe cpr_4011_4mxx',
|
||||
|
||||
kos = [
|
||||
'depmod -ae',
|
||||
'modprobe i2c_dev',
|
||||
'modprobe i2c_mux_pca954x force_deselect_on_exit=1',
|
||||
'modprobe ym2651y',
|
||||
'modprobe x86_64_accton_as4630_54pe_cpld',
|
||||
'modprobe x86_64_accton_as4630_54pe_leds',
|
||||
'modprobe x86_64_accton_as4630_54pe_psu',
|
||||
'modprobe optoe']
|
||||
|
||||
def driver_install():
|
||||
global FORCE
|
||||
|
||||
ret=log_os_system("lsmod|grep i2c_ismt",1)
|
||||
my_log("rmmond i2cismt")
|
||||
log_os_system("rmmod i2c_ismt", 1)
|
||||
log_os_system("rmmod i2c_i801", 1)
|
||||
log_os_system("modprobe i2c-i801", 1)
|
||||
time.sleep(1)
|
||||
log_os_system("modprobe i2c-ismt", 1)
|
||||
|
||||
|
||||
|
||||
for i in range(0,len(kos)):
|
||||
status, output = log_os_system(kos[i], 1)
|
||||
if status:
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
return 0
|
||||
|
||||
def driver_uninstall():
|
||||
global FORCE
|
||||
for i in range(0,len(kos)):
|
||||
rm = kos[-(i+1)].replace("modprobe", "modprobe -rq")
|
||||
lst = rm.split(" ")
|
||||
print "lst=%s"%lst
|
||||
if len(lst) > 3:
|
||||
del(lst[3])
|
||||
rm = " ".join(lst)
|
||||
status, output = log_os_system(rm, 1)
|
||||
if status:
|
||||
if FORCE == 0:
|
||||
return status
|
||||
return 0
|
||||
|
||||
def device_install():
|
||||
global FORCE
|
||||
|
||||
for i in range(0,len(mknod)):
|
||||
#for pca954x need times to built new i2c buses
|
||||
if mknod[i].find('pca954') != -1:
|
||||
time.sleep(2)
|
||||
|
||||
status, output = log_os_system(mknod[i], 1)
|
||||
if status:
|
||||
print output
|
||||
if FORCE == 0:
|
||||
return status
|
||||
print("Check SFP")
|
||||
for i in range(0,len(sfp_map)):
|
||||
if(i < 4):
|
||||
opt='optoe2'
|
||||
else:
|
||||
opt='optoe1'
|
||||
status, output =log_os_system("echo " + str(opt) + " 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1)
|
||||
if status:
|
||||
print output
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
status, output =log_os_system("echo port"+str(i+49) + " > /sys/bus/i2c/devices/"+str(sfp_map[i])+"-0050/port_name", 1)
|
||||
if status:
|
||||
print output
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
return
|
||||
|
||||
def device_uninstall():
|
||||
global FORCE
|
||||
|
||||
status, output =log_os_system("ls /sys/bus/i2c/devices/0-0070", 0)
|
||||
if status==0:
|
||||
I2C_ORDER=1
|
||||
else:
|
||||
I2C_ORDER=0
|
||||
|
||||
for i in range(0,len(sfp_map)):
|
||||
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device"
|
||||
status, output =log_os_system("echo 0x50 > "+ target, 1)
|
||||
if status:
|
||||
print output
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
nodelist = mknod
|
||||
|
||||
for i in range(len(nodelist)):
|
||||
target = nodelist[-(i+1)]
|
||||
temp = target.split()
|
||||
del temp[1]
|
||||
temp[-1] = temp[-1].replace('new_device', 'delete_device')
|
||||
status, output = log_os_system(" ".join(temp), 1)
|
||||
if status:
|
||||
print output
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
return
|
||||
|
||||
def system_ready():
|
||||
if driver_inserted() == False:
|
||||
return False
|
||||
if not device_exist():
|
||||
print "not device_exist()"
|
||||
return False
|
||||
return True
|
||||
|
||||
def do_install():
|
||||
if driver_inserted() == False:
|
||||
status = driver_install()
|
||||
if status:
|
||||
if FORCE == 0:
|
||||
return status
|
||||
else:
|
||||
print PROJECT_NAME.upper()+" drivers detected...."
|
||||
if not device_exist():
|
||||
status = device_install()
|
||||
if status:
|
||||
if FORCE == 0:
|
||||
return status
|
||||
else:
|
||||
print PROJECT_NAME.upper()+" devices detected...."
|
||||
return
|
||||
|
||||
def do_uninstall():
|
||||
if not device_exist():
|
||||
print PROJECT_NAME.upper() +" has no device installed...."
|
||||
else:
|
||||
print "Removing device...."
|
||||
status = device_uninstall()
|
||||
if status:
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
if driver_inserted()== False :
|
||||
print PROJECT_NAME.upper() +" has no driver installed...."
|
||||
else:
|
||||
print "Removing installed driver...."
|
||||
status = driver_uninstall()
|
||||
if status:
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
return
|
||||
|
||||
def devices_info():
|
||||
global DEVICE_NO
|
||||
global ALL_DEVICE
|
||||
global i2c_bus, hwmon_types
|
||||
for key in DEVICE_NO:
|
||||
ALL_DEVICE[key]= {}
|
||||
for i in range(0,DEVICE_NO[key]):
|
||||
ALL_DEVICE[key][key+str(i+1)] = []
|
||||
|
||||
for key in i2c_bus:
|
||||
buses = i2c_bus[key]
|
||||
nodes = i2c_nodes[key]
|
||||
for i in range(0,len(buses)):
|
||||
for j in range(0,len(nodes)):
|
||||
if 'fan' == key:
|
||||
for k in range(0,DEVICE_NO[key]):
|
||||
node = key+str(k+1)
|
||||
path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j]
|
||||
my_log(node+": "+ path)
|
||||
ALL_DEVICE[key][node].append(path)
|
||||
elif 'sfp' == key:
|
||||
for k in range(0,DEVICE_NO[key]):
|
||||
node = key+str(k+1)
|
||||
path = i2c_prefix+ str(sfp_map[k])+ buses[i]+"/"+ nodes[j]
|
||||
my_log(node+": "+ path)
|
||||
ALL_DEVICE[key][node].append(path)
|
||||
else:
|
||||
node = key+str(i+1)
|
||||
path = i2c_prefix+ buses[i]+"/"+ nodes[j]
|
||||
my_log(node+": "+ path)
|
||||
ALL_DEVICE[key][node].append(path)
|
||||
|
||||
for key in hwmon_types:
|
||||
itypes = hwmon_types[key]
|
||||
nodes = hwmon_nodes[key]
|
||||
for i in range(0,len(itypes)):
|
||||
for j in range(0,len(nodes)):
|
||||
node = key+"_"+itypes[i]
|
||||
path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j]
|
||||
my_log(node+": "+ path)
|
||||
ALL_DEVICE[key][ key+str(i+1)].append(path)
|
||||
|
||||
#show dict all in the order
|
||||
if DEBUG == True:
|
||||
for i in sorted(ALL_DEVICE.keys()):
|
||||
print(i+": ")
|
||||
for j in sorted(ALL_DEVICE[i].keys()):
|
||||
print(" "+j)
|
||||
for k in (ALL_DEVICE[i][j]):
|
||||
print(" "+" "+k)
|
||||
return
|
||||
|
||||
def show_eeprom(index):
|
||||
if system_ready()==False:
|
||||
print("System's not ready.")
|
||||
print("Please install first!")
|
||||
return
|
||||
|
||||
if len(ALL_DEVICE)==0:
|
||||
devices_info()
|
||||
node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0]
|
||||
node = node.replace(node.split("/")[-1], 'eeprom')
|
||||
# check if got hexdump command in current environment
|
||||
ret, log = log_os_system("which hexdump", 0)
|
||||
ret, log2 = log_os_system("which busybox hexdump", 0)
|
||||
if len(log):
|
||||
hex_cmd = 'hexdump'
|
||||
elif len(log2):
|
||||
hex_cmd = ' busybox hexdump'
|
||||
else:
|
||||
log = 'Failed : no hexdump cmd!!'
|
||||
logging.info(log)
|
||||
print log
|
||||
return 1
|
||||
print "node=%s"%node
|
||||
print node + ":"
|
||||
ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1)
|
||||
if ret==0:
|
||||
print log
|
||||
else:
|
||||
print "**********device no found**********"
|
||||
return
|
||||
|
||||
def set_device(args):
|
||||
global DEVICE_NO
|
||||
global ALL_DEVICE
|
||||
if system_ready()==False:
|
||||
print("System's not ready.")
|
||||
print("Please install first!")
|
||||
return
|
||||
|
||||
if len(ALL_DEVICE)==0:
|
||||
devices_info()
|
||||
|
||||
if args[0]=='led':
|
||||
if int(args[1])>4:
|
||||
show_set_help()
|
||||
return
|
||||
#print ALL_DEVICE['led']
|
||||
for i in range(0,len(ALL_DEVICE['led'])):
|
||||
for k in (ALL_DEVICE['led']['led'+str(i+1)]):
|
||||
ret, log = log_os_system("echo "+args[1]+" >"+k, 1)
|
||||
if ret:
|
||||
return ret
|
||||
elif args[0]=='fan':
|
||||
if int(args[1])>100:
|
||||
show_set_help()
|
||||
return
|
||||
#print ALL_DEVICE['fan']
|
||||
#fan1~6 is all fine, all fan share same setting
|
||||
node = ALL_DEVICE['fan1'] ['fan11'][0]
|
||||
node = node.replace(node.split("/")[-1], 'fan1_duty_cycle_percentage')
|
||||
ret, log = log_os_system("cat "+ node, 1)
|
||||
if ret==0:
|
||||
print ("Previous fan duty: " + log.strip() +"%")
|
||||
ret, log = log_os_system("echo "+args[1]+" >"+node, 1)
|
||||
if ret==0:
|
||||
print ("Current fan duty: " + args[1] +"%")
|
||||
return ret
|
||||
elif args[0]=='sfp':
|
||||
if int(args[1])> DEVICE_NO[args[0]] or int(args[1])==0:
|
||||
show_set_help()
|
||||
return
|
||||
if len(args)<2:
|
||||
show_set_help()
|
||||
return
|
||||
|
||||
if int(args[2])>1:
|
||||
show_set_help()
|
||||
return
|
||||
|
||||
#print ALL_DEVICE[args[0]]
|
||||
for i in range(0,len(ALL_DEVICE[args[0]])):
|
||||
for j in ALL_DEVICE[args[0]][args[0]+str(args[1])]:
|
||||
if j.find('tx_disable')!= -1:
|
||||
ret, log = log_os_system("echo "+args[2]+" >"+ j, 1)
|
||||
if ret:
|
||||
return ret
|
||||
|
||||
return
|
||||
|
||||
#get digits inside a string.
|
||||
#Ex: 31 for "sfp31"
|
||||
def get_value(input):
|
||||
digit = re.findall('\d+', input)
|
||||
return int(digit[0])
|
||||
|
||||
def device_traversal():
|
||||
if system_ready()==False:
|
||||
print("System's not ready.")
|
||||
print("Please install first!")
|
||||
return
|
||||
|
||||
if len(ALL_DEVICE)==0:
|
||||
devices_info()
|
||||
for i in sorted(ALL_DEVICE.keys()):
|
||||
print("============================================")
|
||||
print(i.upper()+": ")
|
||||
print("============================================")
|
||||
|
||||
for j in sorted(ALL_DEVICE[i].keys(), key=get_value):
|
||||
print " "+j+":",
|
||||
for k in (ALL_DEVICE[i][j]):
|
||||
ret, log = log_os_system("cat "+k, 0)
|
||||
func = k.split("/")[-1].strip()
|
||||
func = re.sub(j+'_','',func,1)
|
||||
func = re.sub(i.lower()+'_','',func,1)
|
||||
if ret==0:
|
||||
print func+"="+log+" ",
|
||||
else:
|
||||
print func+"="+"X"+" ",
|
||||
print
|
||||
print("----------------------------------------------------------------")
|
||||
|
||||
|
||||
print
|
||||
return
|
||||
|
||||
def device_exist():
|
||||
ret1, log = log_os_system("ls "+i2c_prefix+"*0077", 0)
|
||||
ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0)
|
||||
return not(ret1 or ret2)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
2
platform/broadcom/sonic-platform-modules-accton/common/modules/ym2651y.c
Normal file → Executable file
2
platform/broadcom/sonic-platform-modules-accton/common/modules/ym2651y.c
Normal file → Executable file
@ -42,6 +42,7 @@ enum chips {
|
||||
YM2651,
|
||||
YM2401,
|
||||
YM2851,
|
||||
YPEB1200AM
|
||||
};
|
||||
|
||||
/* Each client has this additional data
|
||||
@ -438,6 +439,7 @@ static const struct i2c_device_id ym2651y_id[] = {
|
||||
{ "ym2651", YM2651 },
|
||||
{ "ym2401", YM2401 },
|
||||
{ "ym2851", YM2851 },
|
||||
{ "ype1200am", YPEB1200AM },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, ym2651y_id);
|
||||
|
@ -41,6 +41,10 @@ Package: sonic-platform-accton-as7726-32x
|
||||
Architecture: amd64
|
||||
Description: kernel modules for platform devices such as fan, led, sfp
|
||||
|
||||
Package: sonic-platform-accton-as4630-54pe
|
||||
Architecture: amd64
|
||||
Description: kernel modules for platform devices such as fan, led, sfp
|
||||
|
||||
Package: sonic-platform-accton-minipack
|
||||
Architecture: amd64
|
||||
Description: kernel modules for platform devices such as fan, led, sfp
|
||||
|
@ -19,7 +19,7 @@ PACKAGE_PRE_NAME := sonic-platform-accton
|
||||
KVERSION ?= $(shell uname -r)
|
||||
KERNEL_SRC := /lib/modules/$(KVERSION)
|
||||
MOD_SRC_DIR:= $(shell pwd)
|
||||
MODULE_DIRS:= as7712-32x as5712-54x as7816-64x as7716-32x as7716-32xb as7312-54x as7326-56x as6712-32x as7726-32x minipack
|
||||
MODULE_DIRS:= as7712-32x as5712-54x as7816-64x as7716-32x as7716-32xb as7312-54x as7326-56x as6712-32x as7726-32x as4630-54pe minipack
|
||||
MODULE_DIR := modules
|
||||
UTILS_DIR := utils
|
||||
SERVICE_DIR := service
|
||||
|
Loading…
Reference in New Issue
Block a user