[devices]: Add snh60b0-640f device (Tomhawk2) & snh60a0-320fv2 device 32x100G (Tomhawk) (#2129)

* [platform]:add platfrom snh60a0-320fv2 & snh60b0-640f

* [device]:add platfrom snh60a0-320fv2 & snh60b0-640f

* remove minigraph.xml for snh60a0_320fv2-r0 and snh60b0_640f-r0 platform
This commit is contained in:
juntseng62 2018-10-11 09:33:51 +08:00 committed by lguohan
parent 794981f283
commit 96eac8f099
51 changed files with 9032 additions and 1 deletions

View File

@ -0,0 +1,33 @@
# name lanes alias index speed
Ethernet0 33,34,35,36 Ethernet1/0/1 0 100000
Ethernet4 37,38,39,40 Ethernet1/0/5 1 100000
Ethernet8 41,42,43,44 Ethernet1/0/9 2 100000
Ethernet12 45,46,47,48 Ethernet1/0/13 3 100000
Ethernet16 49,50,51,52 Ethernet1/0/17 4 100000
Ethernet20 53,54,55,56 Ethernet1/0/21 5 100000
Ethernet24 57,58,59,60 Ethernet1/0/25 6 100000
Ethernet28 61,62,63,64 Ethernet1/0/29 7 100000
Ethernet32 65,66,67,68 Ethernet1/0/33 8 100000
Ethernet36 69,70,71,72 Ethernet1/0/37 9 100000
Ethernet40 73,74,75,76 Ethernet1/0/41 10 100000
Ethernet44 77,78,79,80 Ethernet1/0/45 11 100000
Ethernet48 81,82,83,84 Ethernet1/0/49 12 100000
Ethernet52 85,86,87,88 Ethernet1/0/53 13 100000
Ethernet56 89,90,91,92 Ethernet1/0/57 14 100000
Ethernet60 93,94,95,96 Ethernet1/0/61 15 100000
Ethernet64 97,98,99,100 Ethernet1/0/65 16 100000
Ethernet68 101,102,103,104 Ethernet1/0/69 17 100000
Ethernet72 105,106,107,108 Ethernet1/0/73 18 100000
Ethernet76 109,110,111,112 Ethernet1/0/77 19 100000
Ethernet80 113,114,115,116 Ethernet1/0/81 20 100000
Ethernet84 117,118,119,120 Ethernet1/0/85 21 100000
Ethernet88 121,122,123,124 Ethernet1/0/89 22 100000
Ethernet92 125,126,127,128 Ethernet1/0/93 23 100000
Ethernet96 1,2,3,4 Ethernet1/0/97 24 100000
Ethernet100 5,6,7,8 Ethernet1/0/101 25 100000
Ethernet104 9,10,11,12 Ethernet1/0/105 26 100000
Ethernet108 13,14,15,16 Ethernet1/0/109 27 100000
Ethernet112 17,18,19,20 Ethernet1/0/113 28 100000
Ethernet116 21,22,23,24 Ethernet1/0/117 29 100000
Ethernet120 25,26,27,28 Ethernet1/0/121 30 100000
Ethernet124 29,30,31,32 Ethernet1/0/125 31 100000

View File

@ -0,0 +1 @@
SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/th-snh60a0-32x100G.config.bcm

View File

@ -0,0 +1,163 @@
# This property file is for ZION-320F 100G mode only.
# Zion-320F uses Tomahawk BCM56960 as its mac. Besides, it is phyless.
# Note: The settings in this file are not verified yet.
# Set stat collection interval in microseconds.
# Setting this to 0 will prevent counters from being started.
bcm_stat_interval.0=1000000
# Linkscan interval in microseconds.
# If non-zero, bcm_init() will start linkscan
bcm_linkscan_interval.0=450000
# BCM56960 : MMU Cell Buffer Allocation Profile to support ASF (cut-thru) Forwarding
# 0: No cut-through support
# 1: Similar speed profile (Default)
# 2: Extreme speed profile
os=unix
# EagleCore ports
#portmap_66=129:10
#portmap_100=131:10
# Loopback ports
portmap_33=132:10
portmap_67=133:10
portmap_101=134:10
portmap_135=135:10
#FalconCore[0 - 7] must map to logical port[1 - 32]
portmap_1=1:100
portmap_2=5:100
portmap_3=9:100
portmap_4=13:100
portmap_5=17:100
portmap_6=21:100
portmap_7=25:100
portmap_8=29:100
#FalconCore[8 - 15] must map to logical port[34 - 65]
portmap_34=33:100
portmap_35=37:100
portmap_36=41:100
portmap_37=45:100
portmap_38=49:100
portmap_39=53:100
portmap_40=57:100
portmap_41=61:100
#FalconCore[16 - 23] must map to logical port[68 - 99]
portmap_68=65:100
portmap_69=69:100
portmap_70=73:100
portmap_71=77:100
portmap_72=81:100
portmap_73=85:100
portmap_74=89:100
portmap_75=93:100
#FalconCore[24 - 31] must map to logical port[102 - 133]
portmap_102=97:100
portmap_103=101:100
portmap_104=105:100
portmap_105=109:100
portmap_106=113:100
portmap_107=117:100
portmap_108=121:100
portmap_109=125:100
pbmp_xport_xe=0x3fd000000ff4000003fc000001fe
pbmp_oversubscribe=0x0000000000000000000000000000000000003fc000000ff0000003fc000001fe
#core-0
xgxs_rx_lane_map_ce0=0x3012
xgxs_rx_lane_map_ce1=0x1230
xgxs_rx_lane_map_ce2=0x3012
xgxs_rx_lane_map_ce3=0x1230
xgxs_rx_lane_map_ce4=0x1230
xgxs_rx_lane_map_ce5=0x1230
xgxs_rx_lane_map_ce6=0x1230
xgxs_rx_lane_map_ce7=0x1230
#core-8
xgxs_rx_lane_map_ce8=0x1032
xgxs_rx_lane_map_ce9=0x1230
xgxs_rx_lane_map_ce10=0x1032
xgxs_rx_lane_map_ce11=0x1230
xgxs_rx_lane_map_ce12=0x1230
xgxs_rx_lane_map_ce13=0x3012
xgxs_rx_lane_map_ce14=0x1230
xgxs_rx_lane_map_ce15=0x3012
#core-16
xgxs_rx_lane_map_ce16=0x3012
xgxs_rx_lane_map_ce17=0x3012
xgxs_rx_lane_map_ce18=0x1230
xgxs_rx_lane_map_ce19=0x3012
xgxs_rx_lane_map_ce20=0x3012
xgxs_rx_lane_map_ce21=0x3012
xgxs_rx_lane_map_ce22=0x3012
xgxs_rx_lane_map_ce23=0x3012
#core-24
xgxs_rx_lane_map_ce24=0x3210
xgxs_rx_lane_map_ce25=0x3012
xgxs_rx_lane_map_ce26=0x3210
xgxs_rx_lane_map_ce27=0x3012
xgxs_rx_lane_map_ce28=0x3012
xgxs_rx_lane_map_ce29=0x1230
xgxs_rx_lane_map_ce30=0x3012
xgxs_rx_lane_map_ce31=0x3012
#
# Remap XGXS tx lanes to desired mapping by hardware provide.
#core-0
xgxs_tx_lane_map_ce0=0x3210
xgxs_tx_lane_map_ce1=0x1032
xgxs_tx_lane_map_ce2=0x3210
xgxs_tx_lane_map_ce3=0x1032
xgxs_tx_lane_map_ce4=0x3210
xgxs_tx_lane_map_ce5=0x3210
xgxs_tx_lane_map_ce6=0x3210
xgxs_tx_lane_map_ce7=0x1230
#core-8
xgxs_tx_lane_map_ce8=0x2301
xgxs_tx_lane_map_ce9=0x3210
xgxs_tx_lane_map_ce10=0x2301
xgxs_tx_lane_map_ce11=0x3210
xgxs_tx_lane_map_ce12=0x0123
xgxs_tx_lane_map_ce13=0x3210
xgxs_tx_lane_map_ce14=0x0123
xgxs_tx_lane_map_ce15=0x3210
#core-16
xgxs_tx_lane_map_ce16=0x2301
xgxs_tx_lane_map_ce17=0x3210
xgxs_tx_lane_map_ce18=0x0123
xgxs_tx_lane_map_ce19=0x1032
xgxs_tx_lane_map_ce20=0x0123
xgxs_tx_lane_map_ce21=0x1032
xgxs_tx_lane_map_ce22=0x0123
xgxs_tx_lane_map_ce23=0x1032
#core-24
xgxs_tx_lane_map_ce24=0x1032
xgxs_tx_lane_map_ce25=0x1032
xgxs_tx_lane_map_ce26=0x1032
xgxs_tx_lane_map_ce27=0x1032
xgxs_tx_lane_map_ce28=0x1032
xgxs_tx_lane_map_ce29=0x1032
xgxs_tx_lane_map_ce30=0x3210
xgxs_tx_lane_map_ce31=0x3210
ptp_ts_pll_fref=25000000
ptp_bs_fref=25000000

View File

@ -0,0 +1 @@
Alphanetworks-SNH60A0-320FV2 t1

View File

@ -0,0 +1,9 @@
INTERVAL=10
FCTEMPS=/sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/4-004d/hwmon/hwmon3/temp1_input
FCFANS=/sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan1_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan2_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan3_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan4_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan5_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan6_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan11_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan12_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan13_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan14_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan15_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan16_input
MINTEMP=/sys/bus/i2c/devices/0-005e/fan_pwm=50
MAXTEMP=/sys/bus/i2c/devices/0-005e/fan_pwm=70
MINSTART=/sys/bus/i2c/devices/0-005e/fan_pwm=100
MINSTOP=/sys/bus/i2c/devices/0-005e/fan_pwm=100
MINPWM=/sys/bus/i2c/devices/0-005e/fan_pwm=100
MAXPWM=/sys/bus/i2c/devices/0-005e/fan_pwm=200

View File

@ -0,0 +1,3 @@
CONSOLE_PORT=0x2f8
CONSOLE_DEV=1
CONSOLE_SPEED=115200

View File

@ -0,0 +1,45 @@
# LED microprocessor initialization for alphanetworks snh60a0-320fv2
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_0_3 REMAP_PORT_0=31 REMAP_PORT_1=30 REMAP_PORT_2=29 REMAP_PORT_3=28
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_4_7 REMAP_PORT_4=27 REMAP_PORT_5=26 REMAP_PORT_6=25 REMAP_PORT_7=24
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_8_11 REMAP_PORT_8=23 REMAP_PORT_9=22 REMAP_PORT_10=21 REMAP_PORT_11=20
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_12_15 REMAP_PORT_12=19 REMAP_PORT_13=18 REMAP_PORT_14=17 REMAP_PORT_15=16
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_16_19 REMAP_PORT_16=15 REMAP_PORT_17=14 REMAP_PORT_18=13 REMAP_PORT_19=12
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_20_23 REMAP_PORT_20=11 REMAP_PORT_21=10 REMAP_PORT_22=9 REMAP_PORT_23=8
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_24_27 REMAP_PORT_24=7 REMAP_PORT_25=6 REMAP_PORT_26=5 REMAP_PORT_27=4
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_28_31 REMAP_PORT_28=3 REMAP_PORT_29=2 REMAP_PORT_30=1 REMAP_PORT_31=0
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_32_35 REMAP_PORT_32=63 REMAP_PORT_33=62 REMAP_PORT_34=61 REMAP_PORT_35=60
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_36_39 REMAP_PORT_36=59 REMAP_PORT_37=58 REMAP_PORT_38=57 REMAP_PORT_39=56
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_40_43 REMAP_PORT_40=55 REMAP_PORT_41=54 REMAP_PORT_42=53 REMAP_PORT_43=52
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_44_47 REMAP_PORT_44=51 REMAP_PORT_45=50 REMAP_PORT_46=49 REMAP_PORT_47=48
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_48_51 REMAP_PORT_48=47 REMAP_PORT_49=46 REMAP_PORT_50=45 REMAP_PORT_51=44
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_52_55 REMAP_PORT_52=43 REMAP_PORT_53=42 REMAP_PORT_54=41 REMAP_PORT_55=40
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_56_59 REMAP_PORT_56=39 REMAP_PORT_57=38 REMAP_PORT_58=37 REMAP_PORT_59=36
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_60_63 REMAP_PORT_60=35 REMAP_PORT_61=34 REMAP_PORT_62=33 REMAP_PORT_63=32
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_0_3 REMAP_PORT_0=3 REMAP_PORT_1=2 REMAP_PORT_2=1 REMAP_PORT_3=0
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_4_7 REMAP_PORT_4=7 REMAP_PORT_5=6 REMAP_PORT_6=5 REMAP_PORT_7=4
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_8_11 REMAP_PORT_8=11 REMAP_PORT_9=10 REMAP_PORT_10=9 REMAP_PORT_11=8
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_12_15 REMAP_PORT_12=15 REMAP_PORT_13=14 REMAP_PORT_14=13 REMAP_PORT_15=12
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_16_19 REMAP_PORT_16=19 REMAP_PORT_17=18 REMAP_PORT_18=17 REMAP_PORT_19=16
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_20_23 REMAP_PORT_20=23 REMAP_PORT_21=22 REMAP_PORT_22=21 REMAP_PORT_23=20
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_24_27 REMAP_PORT_24=27 REMAP_PORT_25=26 REMAP_PORT_26=25 REMAP_PORT_27=24
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_28_31 REMAP_PORT_28=31 REMAP_PORT_29=30 REMAP_PORT_30=29 REMAP_PORT_31=28
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_32_35 REMAP_PORT_32=35 REMAP_PORT_33=34 REMAP_PORT_34=33 REMAP_PORT_35=32
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_36_39 REMAP_PORT_36=39 REMAP_PORT_37=38 REMAP_PORT_38=37 REMAP_PORT_39=36
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_40_43 REMAP_PORT_40=43 REMAP_PORT_41=42 REMAP_PORT_42=41 REMAP_PORT_43=40
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_44_47 REMAP_PORT_44=47 REMAP_PORT_45=46 REMAP_PORT_46=45 REMAP_PORT_47=44
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_48_51 REMAP_PORT_48=51 REMAP_PORT_49=50 REMAP_PORT_50=49 REMAP_PORT_51=48
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_52_55 REMAP_PORT_52=55 REMAP_PORT_53=54 REMAP_PORT_54=53 REMAP_PORT_55=52
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_56_59 REMAP_PORT_56=59 REMAP_PORT_57=58 REMAP_PORT_58=57 REMAP_PORT_59=56
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_60_63 REMAP_PORT_60=63 REMAP_PORT_61=62 REMAP_PORT_62=61 REMAP_PORT_63=60
led 0 stop
led 0 prog 2A 01 86 FF 06 FF C2 7F 60 FF 02 20 60 FE 67 2E 06 FE F2 04 60 FE D2 40 74 0E 70 1C 02 00 60 FE 67 2E 06 FE F2 04 60 FE D2 20 74 20 70 70 02 A0 F6 FE 04 D2 01 70 39 74 5F 06 FE 28 32 00 32 01 B7 97 71 46 75 4E 06 FF C2 04 74 4E 70 5F 67 76 67 72 67 76 67 76 67 76 67 76 67 76 67 76 57 67 76 67 76 67 76 67 76 67 76 67 76 67 76 67 76 57 3A 80 32 0E 87 57 32 0F 87 57
led 0 auto on
led 0 start
led 1 stop
led 1 prog 2A 01 86 FF 06 FF C2 7F 60 FF 02 00 60 FE 67 1C 06 FE F2 04 60 FE D2 40 74 0E 70 5E 02 A0 F6 FE 04 D2 01 70 27 74 4D 06 FE 28 32 00 32 01 B7 97 71 34 75 3C 06 FF C2 04 74 3C 70 4D 67 64 67 60 67 64 67 64 67 64 67 64 67 64 67 64 57 67 64 67 64 67 64 67 64 67 64 67 64 67 64 67 64 57 3A 80 32 0E 87 57 32 0F 87 57
led 1 auto on
led 1 start

View File

@ -0,0 +1,24 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
import warnings
import os
import sys
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom"
#Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

View File

@ -0,0 +1,255 @@
#!/usr/bin/env python
#
# led_control.py
#
# Platform-specific LED control functionality for SONiC
#
# try:
# from sonic_led.led_control_base import LedControlBase
# import swsssdk
# except ImportError, e:
# raise ImportError (str(e) + " - required module not found")
import time
class LedControlBase(object):
# __metaclass__ = abc.ABCMeta
# @abc.abstractmethod
def port_link_state_change(self, port, state):
"""
Called when port link state changes. Update port link state LED here.
:param port: A string, SONiC port name (e.shg., "Ethernet0")
:param state: A string, the port link state (either "up" or "down")
"""
return
### Zion specified ###
read_fan_fault = 0
is_fan_all_OK = 0
read_power_status = 0
is_power_all_OK = 0
is_thermal_high = 0
is_reset_button_push = 0
##########################
def sysled_task():
while True:
system_led_check()
time.sleep(5)
### Zion specified ###
def system_led_check():
global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push
is_fan_all_OK = 1
is_power_all_OK = 0
is_thermal_high = 0
is_reset_button_push = 0
with open("/sys/bus/i2c/devices/1-005e/fan1_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan1_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan2_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan2_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan3_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan3_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan4_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan4_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan5_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan5_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan6_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/psu1_power_good", "r") as f1:
read_power_status = f1.read()
with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11:
if str(read_power_status) == str("1\n"):
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/1-005e/psu1_present", "r") as f1:
read_power_status = f1.read()
with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11:
if str(read_power_status) == str("1\n"):
is_power_all_OK = is_power_all_OK + 1
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/1-005e/psu2_power_good", "r") as f1:
read_power_status = f1.read()
with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11:
if str(read_power_status) == str("1\n"):
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/1-005e/psu2_present", "r") as f1:
read_power_status = f1.read()
with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11:
if str(read_power_status) == str("1\n"):
is_power_all_OK = is_power_all_OK + 1
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/9-005f/swi_ctrl", "r") as f5:
is_reset_button_push = f5.read()
if str(is_reset_button_push) == "1\n":
is_reset_button_push = 1
else:
is_reset_button_push = 0
with open("/sys/bus/i2c/devices/4-004d/hwmon/hwmon3/temp1_input", "r") as f3:
is_thermal_high = f3.read()
if int(is_thermal_high) >= 70000:
is_thermal_high = 1
else:
is_thermal_high = 0
with open("/sys/bus/i2c/devices/9-005f/sys_status", "w") as f2:
if is_reset_button_push == 1:
f2.write("3")
elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1:
f2.write("4")
else:
f2.write("1")
return
##########
class LedControl(LedControlBase):
"""Platform specific LED control class"""
PORT_TABLE_PREFIX = "PORT_TABLE:"
SONIC_PORT_NAME_PREFIX = "Ethernet"
LED_SYSFS_PATH_BREAKOUT_CAPABLE = "/sys/class/leds/qsfp{0}_{1}/brightness"
LED_SYSFS_PATH_NO_BREAKOUT = "/sys/class/leds/qsfp{0}/brightness"
QSFP_BREAKOUT_START_IDX = 1
QSFP_BREAKOUT_END_IDX = 24
QSFP_NO_BREAKOUT_START_IDX = 25
QSFP_NO_BREAKOUT_END_IDX = 32
LED_COLOR_OFF = 0
LED_COLOR_GREEN = 1
LED_COLOR_YELLOW = 2
# Helper method to map SONiC port name to Arista QSFP index
def _port_name_to_qsfp_index(self, port_name):
# Strip "Ethernet" off port name
if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX):
return -1
sonic_port_num = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):])
swss = swsssdk.SonicV2Connector()
swss.connect(swss.APPL_DB)
lanes = swss.get(swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes')
# SONiC port nums are 0-based and increment by 4
# Arista QSFP indices are 1-based and increment by 1
return (((sonic_port_num/4) + 1), sonic_port_num%4, len(lanes.split(',')))
# Concrete implementation of port_link_state_change() method
def port_link_state_change_bk(self, port, state):
qsfp_index, lane_index, lanes = self._port_name_to_qsfp_index(port)
# Ignore invalid QSFP indices
if qsfp_index <= 0 or lanes <= 0 or lanes > 4:
return
# QSFP indices 1-24 are breakout-capable and have four LEDs, and each LED indicate one lane.
# whereas indices 25-32 are not breakout-capable, and only have one
if qsfp_index <= self.QSFP_BREAKOUT_END_IDX:
# assuming 40G, then we need to control four lanes
led_sysfs_paths = [ self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes) ]
else:
led_sysfs_paths = [ self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index) ]
for led_sysfs_path in led_sysfs_paths:
led_file = open(led_sysfs_path, "w")
if state == "up":
led_file.write("%d" % self.LED_COLOR_GREEN)
else:
led_file.write("%d" % self.LED_COLOR_OFF)
led_file.close()
# Constructor
def __init__(self):
# Initialize all front-panel status LEDs to green
with open("/sys/bus/i2c/devices/9-005f/sys_locator", "w") as f:
f.write("0")
with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f:
f.write("1")
with open("/sys/bus/i2c/devices/9-005f/sys_status", "w") as f:
f.write("1")
# Initialize all fan LEDs to green
with open("/sys/bus/i2c/devices/9-005f/fan1_led", "w") as f:
f.write("1")
with open("/sys/bus/i2c/devices/9-005f/fan2_led", "w") as f:
f.write("1")
with open("/sys/bus/i2c/devices/9-005f/fan3_led", "w") as f:
f.write("1")
with open("/sys/bus/i2c/devices/9-005f/fan4_led", "w") as f:
f.write("1")
with open("/sys/bus/i2c/devices/9-005f/fan5_led", "w") as f:
f.write("1")
with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f:
f.write("1")
sysled_task()
# Initialize: Turn all front panel QSFP LEDs off
# # for qsfp_index in range(self.QSFP_BREAKOUT_START_IDX, self.QSFP_BREAKOUT_END_IDX + 1):
# # for lane in range(1, 5):
# # led_sysfs_path = self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, lane)
# # with open(led_sysfs_path, 'w') as led_file:
# # led_file.write("%d" % self.LED_COLOR_OFF)
# # for qsfp_index in range(self.QSFP_NO_BREAKOUT_START_IDX, self.QSFP_NO_BREAKOUT_END_IDX + 1):
# # led_sysfs_path = self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index)
# # with open(led_sysfs_path, 'w') as led_file:
# # led_file.write("%d" % self.LED_COLOR_OFF)

View File

@ -0,0 +1,66 @@
#!/usr/bin/env python
#############################################################################
# Alphanetworks
#
# Module contains an implementation of SONiC PSU Base API and
# provides the PSUs status which are available in the platform
#
#############################################################################
import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""
def __init__(self):
PsuBase.__init__(self)
self.psu_path = "/sys/bus/i2c/devices/"
self.psu_presence = {
1: "/psu1_present",
2: "/psu2_present",
}
self.psu_oper_status = {
1: "/psu1_power_good",
2: "/psu2_power_good",
}
self.psu_mapping = "0-005e"
if not os.path.exists(self.psu_path+self.psu_mapping):
self.psu_mapping = "1-005e"
def get_num_psus(self):
return len(self.psu_presence)
def get_psu_status(self, index):
if index is None:
return False
status = 0
node = self.psu_path + self.psu_mapping+self.psu_oper_status[index]
try:
with open(node, 'r') as power_status:
status = int(power_status.read())
except IOError:
return False
return status == 1
def get_psu_presence(self, index):
if index is None:
return False
status = 0
node = self.psu_path + self.psu_mapping + self.psu_presence[index]
try:
with open(node, 'r') as presence_status:
status = int(presence_status.read())
except IOError:
return False
return status == 1

View File

@ -0,0 +1,116 @@
#!/usr/bin/env python
try:
import time
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
class SfpUtil(SfpUtilBase):
"""Platform specific SfpUtill class"""
first_port = 0
last_port = 31
port_num = 32
port_to_eeprom = {}
port_to_i2cbus_mapping = {
1 : 14,
2 : 15,
3 : 16,
4 : 17,
}
eeprom_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_eeprom"
port_reset_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_port_reset"
present_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_is_present"
_qsfp_ports = range(first_port, port_num + 1)
@property
def port_start(self):
return self.first_port
@property
def port_end(self):
return self.last_port
@property
def qsfp_ports(self):
return range(self.first_port, self.port_num + 1)
@property
def port_to_eeprom_mapping(self):
return self.port_to_eeprom
def get_transceiver_change_event(self):
"""
TODO: This function need to be implemented
when decide to support monitoring SFP(Xcvrd)
on this platform.
"""
raise NotImplementedError
def __init__(self):
path = self.eeprom_path
for x in range(self.first_port, self.last_port + 1):
index = (x % 8)
i2c_index = (x / 8) + 1
self.port_to_eeprom[x] = path.format(self.port_to_i2cbus_mapping[i2c_index], (index + 1))
SfpUtilBase.__init__(self)
def reset(self, port_num):
# Check for invalid port_num
if port_num < self.first_port or port_num > self.last_port:
return False
index = (port_num % 8)
i2c_index = (port_num / 8) + 1
path = self.port_reset_path
port_path = path.format(self.port_to_i2cbus_mapping[i2c_index], (index + 1))
try:
reg_file = open(port_path, 'w')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
# reset
reg_file.write('1')
time.sleep(1)
reg_file.write('0')
reg_file.close()
return True
def set_low_power_mode(self, port_nuM, lpmode):
raise NotImplementedError
def get_low_power_mode(self, port_num):
raise NotImplementedError
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.first_port or port_num > self.last_port:
return False
index = (port_num % 8)
i2c_index = (port_num / 8) + 1
path = self.present_path
port_path = path.format(self.port_to_i2cbus_mapping[i2c_index], (index + 1))
try:
reg_file = open(port_path)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
reg_value = reg_file.readline().rstrip()
if reg_value == '1':
return True
return False

View File

@ -0,0 +1,17 @@
# libsensors configuration file for snh60a0_320f
# ------------------------------------------------
bus "i2c-1" "SMBus I801 adapter at f000"
chip "goreme_power_cpld-*"
label fan1 "Fan tray 1 front"
label fan2 "Fan tray 2 front"
label fan3 "Fan tray 3 front"
label fan4 "Fan tray 4 front"
label fan5 "Fan tray 5 front"
label fan6 "Fan tray 6 front"
label fan11 "Fan tray 1 rear"
label fan12 "Fan tray 2 rear"
label fan13 "Fan tray 3 rear"
label fan14 "Fan tray 4 rear"
label fan15 "Fan tray 5 rear"
label fan16 "Fan tray 6 rear"

View File

@ -0,0 +1,67 @@
# name lanes alias index speed
Ethernet0 5,6,7,8 Ethernet1/0/1 0 100000
Ethernet4 9,10,11,12 Ethernet1/0/5 1 100000
Ethernet8 13,14,15,16 Ethernet1/0/9 2 100000
Ethernet12 1,2,3,4 Ethernet1/0/13 3 100000
Ethernet16 21,22,23,24 Ethernet1/0/17 4 100000
Ethernet20 25,26,27,28 Ethernet1/0/21 5 100000
Ethernet24 29,30,31,32 Ethernet1/0/25 6 100000
Ethernet28 17,18,19,20 Ethernet1/0/29 7 100000
Ethernet32 37,38,39,40 Ethernet1/0/33 8 100000
Ethernet36 41,42,43,44 Ethernet1/0/37 9 100000
Ethernet40 45,46,47,48 Ethernet1/0/41 10 100000
Ethernet44 33,34,35,36 Ethernet1/0/45 11 100000
Ethernet48 53,54,55,56 Ethernet1/0/49 12 100000
Ethernet52 57,58,59,60 Ethernet1/0/53 13 100000
Ethernet56 61,62,63,64 Ethernet1/0/57 14 100000
Ethernet60 49,50,51,52 Ethernet1/0/61 15 100000
Ethernet64 69,70,71,72 Ethernet1/0/65 16 100000
Ethernet68 73,74,75,76 Ethernet1/0/69 17 100000
Ethernet72 77,78,79,80 Ethernet1/0/73 18 100000
Ethernet76 65,66,67,68 Ethernet1/0/77 19 100000
Ethernet80 85,86,87,88 Ethernet1/0/81 20 100000
Ethernet84 89,90,91,92 Ethernet1/0/85 21 100000
Ethernet88 93,94,95,96 Ethernet1/0/89 22 100000
Ethernet92 81,82,83,84 Ethernet1/0/93 23 100000
Ethernet96 101,102,103,104 Ethernet1/0/97 24 100000
Ethernet100 105,106,107,108 Ethernet1/0/101 25 100000
Ethernet104 109,110,111,112 Ethernet1/0/105 26 100000
Ethernet108 97,98,99,100 Ethernet1/0/109 27 100000
Ethernet112 117,118,119,120 Ethernet1/0/113 28 100000
Ethernet116 121,122,123,124 Ethernet1/0/117 29 100000
Ethernet120 125,126,127,128 Ethernet1/0/121 30 100000
Ethernet124 113,114,115,116 Ethernet1/0/125 31 100000
Ethernet128 133,134,135,136 Ethernet1/0/129 32 100000
Ethernet132 137,138,139,140 Ethernet1/0/133 33 100000
Ethernet136 141,142,143,144 Ethernet1/0/137 34 100000
Ethernet140 129,130,131,132 Ethernet1/0/141 35 100000
Ethernet144 149,150,151,152 Ethernet1/0/145 36 100000
Ethernet148 153,154,155,156 Ethernet1/0/149 37 100000
Ethernet152 157,158,159,160 Ethernet1/0/153 38 100000
Ethernet156 145,146,147,148 Ethernet1/0/157 39 100000
Ethernet160 165,166,167,168 Ethernet1/0/161 40 100000
Ethernet164 169,170,171,172 Ethernet1/0/165 41 100000
Ethernet168 173,174,175,176 Ethernet1/0/169 42 100000
Ethernet172 161,162,163,164 Ethernet1/0/173 43 100000
Ethernet176 181,182,183,184 Ethernet1/0/177 44 100000
Ethernet180 185,186,187,188 Ethernet1/0/181 45 100000
Ethernet184 189,190,191,192 Ethernet1/0/185 46 100000
Ethernet188 177,178,179,180 Ethernet1/0/189 47 100000
Ethernet192 197,198,199,200 Ethernet1/0/193 48 100000
Ethernet196 201,202,203,204 Ethernet1/0/197 49 100000
Ethernet200 205,206,207,208 Ethernet1/0/201 50 100000
Ethernet204 193,194,195,196 Ethernet1/0/205 51 100000
Ethernet208 213,214,215,216 Ethernet1/0/209 52 100000
Ethernet212 217,218,219,220 Ethernet1/0/213 53 100000
Ethernet216 221,222,223,224 Ethernet1/0/217 54 100000
Ethernet220 209,210,211,212 Ethernet1/0/221 55 100000
Ethernet224 229,230,231,232 Ethernet1/0/225 56 100000
Ethernet228 233,234,235,236 Ethernet1/0/229 57 100000
Ethernet232 237,238,239,240 Ethernet1/0/233 58 100000
Ethernet236 225,226,227,228 Ethernet1/0/237 59 100000
Ethernet240 245,246,247,248 Ethernet1/0/241 60 100000
Ethernet244 249,250,251,252 Ethernet1/0/245 61 100000
Ethernet248 253,254,255,256 Ethernet1/0/249 62 100000
Ethernet252 241,242,243,244 Ethernet1/0/253 63 100000
Ethernet256 257 Ethernet1/0/257 64 10000
Ethernet260 259 Ethernet1/0/261 65 10000

View File

@ -0,0 +1 @@
SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/th2-snh60b0-64x100G.config.bcm

View File

@ -0,0 +1,535 @@
# This property file is for GOREME-2U 1x100G mode only.
# GOREME-2U uses Tomahawk2 BCM56970 as its mac. Besides, it is phyless.
# Note: The settings in this file are not verified yet.
os=unix
bcm_stat_interval.0=1000000
bcm_linkscan_interval.0=250000
# Tuning MDIO_OUTPUT_DELAY as 0xf based on HW RD suggesstion and DVT result.
mdio_output_delay.0=0xf
# Mode control to select L2 Table DMA mode aka L2MODE_POLL (0) or
# L2MOD_FIFO mechanism aka L2MODE_FIFO (1) for L2 table change notification.
l2xmsg_mode=1
# Memory table size configs
l2_mem_entries=40960
l3_mem_entries=40960
portmap_66=257:10
portmap_100=259:10
# Falcon core - front port
# FalconCore[0 - 15] must map to logical port[1-16], PIPE-0.
portmap_1=5:100
portmap_2=9:100
portmap_3=13:100
portmap_4=1:100
portmap_5=21:100
portmap_6=25:100
portmap_7=29:100
portmap_8=17:100
portmap_9=37:100
portmap_10=41:100
portmap_11=45:100
portmap_12=33:100
portmap_13=53:100
portmap_14=57:100
portmap_15=61:100
portmap_16=49:100
# FalconCore[16 - 31] must map to logical port[34-49], PIPE-1.
portmap_34=69:100
portmap_35=73:100
portmap_36=77:100
portmap_37=65:100
portmap_38=85:100
portmap_39=89:100
portmap_40=93:100
portmap_41=81:100
portmap_42=101:100
portmap_43=105:100
portmap_44=109:100
portmap_45=97:100
portmap_46=117:100
portmap_47=121:100
portmap_48=125:100
portmap_49=113:100
# FalconCore[32 - 47] must map to logical port[68-83], PIPE-2.
portmap_68=133:100
portmap_69=137:100
portmap_70=141:100
portmap_71=129:100
portmap_72=149:100
portmap_73=153:100
portmap_74=157:100
portmap_75=145:100
portmap_76=165:100
portmap_77=169:100
portmap_78=173:100
portmap_79=161:100
portmap_80=181:100
portmap_81=185:100
portmap_82=189:100
portmap_83=177:100
# FalconCore[48 - 63] must map to logical port[102-117], PIPE-3.
portmap_102=197:100
portmap_103=201:100
portmap_104=205:100
portmap_105=193:100
portmap_106=213:100
portmap_107=217:100
portmap_108=221:100
portmap_109=209:100
portmap_110=229:100
portmap_111=233:100
portmap_112=237:100
portmap_113=225:100
portmap_114=245:100
portmap_115=249:100
portmap_116=253:100
portmap_117=241:100
# Configure all front port as CE ports.
pbmp_xport_xe=0x00000000000000000000000000000000003fffd0000ffff40003fffc0001fffe
# Oversubscription mode
#
# Refers to a switch being configured such that the I/O bandwidth is greater than the
# core bandwidth.
# BCM56970 device supports a maximum I/O bandwidth of 6,400 Gbps when the average packet size
# is greater than 250 bytes.
pbmp_oversubscribe=0x00000000000000000000000000000000003fffc0000ffff00003fffc0001fffe
# core-0~7
xgxs_rx_lane_map_ce0=0x0213
xgxs_rx_lane_map_ce1=0x3102
xgxs_rx_lane_map_ce2=0x1032
xgxs_rx_lane_map_ce3=0x2103
xgxs_rx_lane_map_ce4=0x0213
xgxs_rx_lane_map_ce5=0x2103
xgxs_rx_lane_map_ce6=0x1230
xgxs_rx_lane_map_ce7=0x3120
# core-8~15
xgxs_rx_lane_map_ce8=0x0123
xgxs_rx_lane_map_ce9=0x3102
xgxs_rx_lane_map_ce10=0x1230
xgxs_rx_lane_map_ce11=0x0123
xgxs_rx_lane_map_ce12=0x0123
xgxs_rx_lane_map_ce13=0X1230
xgxs_rx_lane_map_ce14=0x1230
xgxs_rx_lane_map_ce15=0x0123
# core-16~23
xgxs_rx_lane_map_ce16=0x0123
xgxs_rx_lane_map_ce17=0x1230
xgxs_rx_lane_map_ce18=0x1230
xgxs_rx_lane_map_ce19=0x0123
xgxs_rx_lane_map_ce20=0x0123
xgxs_rx_lane_map_ce21=0x1230
xgxs_rx_lane_map_ce22=0x1230
xgxs_rx_lane_map_ce23=0x0123
# core-24~31
xgxs_rx_lane_map_ce24=0x0123
xgxs_rx_lane_map_ce25=0x0231
xgxs_rx_lane_map_ce26=0x2130
xgxs_rx_lane_map_ce27=0x2103
xgxs_rx_lane_map_ce28=0x3012
xgxs_rx_lane_map_ce29=0x3102
xgxs_rx_lane_map_ce30=0x1032
xgxs_rx_lane_map_ce31=0x2103
# core-32~39
xgxs_rx_lane_map_ce32=0x3102
xgxs_rx_lane_map_ce33=0x3102
xgxs_rx_lane_map_ce34=0x0132
xgxs_rx_lane_map_ce35=0x3021
xgxs_rx_lane_map_ce36=0x0213
xgxs_rx_lane_map_ce37=0x3012
xgxs_rx_lane_map_ce38=0x2130
xgxs_rx_lane_map_ce39=0x0123
# core-40~47
xgxs_rx_lane_map_ce40=0x0312
xgxs_rx_lane_map_ce41=0x0132
xgxs_rx_lane_map_ce42=0x1230
xgxs_rx_lane_map_ce43=0x0123
xgxs_rx_lane_map_ce44=0x0312
xgxs_rx_lane_map_ce45=0x0132
xgxs_rx_lane_map_ce46=0x1230
xgxs_rx_lane_map_ce47=0x0123
# core-48~55
xgxs_rx_lane_map_ce48=0x0123
xgxs_rx_lane_map_ce49=0x0132
xgxs_rx_lane_map_ce50=0x1230
xgxs_rx_lane_map_ce51=0x0123
xgxs_rx_lane_map_ce52=0x0312
xgxs_rx_lane_map_ce53=0x0132
xgxs_rx_lane_map_ce54=0x1230
xgxs_rx_lane_map_ce55=0x0123
# core-56~63
xgxs_rx_lane_map_ce56=0x0123
xgxs_rx_lane_map_ce57=0x0312
xgxs_rx_lane_map_ce58=0x1032
xgxs_rx_lane_map_ce59=0x2103
xgxs_rx_lane_map_ce60=0x2103
xgxs_rx_lane_map_ce61=0x3120
xgxs_rx_lane_map_ce62=0x1032
xgxs_rx_lane_map_ce63=0x0213
# Remap XGXS tx lanes to desired mapping by hardware provide.
#core-0~7
xgxs_tx_lane_map_ce0=0x2301
xgxs_tx_lane_map_ce1=0x2301
xgxs_tx_lane_map_ce2=0x1302
xgxs_tx_lane_map_ce3=0x3210
xgxs_tx_lane_map_ce4=0x2301
xgxs_tx_lane_map_ce5=0x2301
xgxs_tx_lane_map_ce6=0x0213
xgxs_tx_lane_map_ce7=0x3210
#core-8~15
xgxs_tx_lane_map_ce8=0x1230
xgxs_tx_lane_map_ce9=0x2301
xgxs_tx_lane_map_ce10=0x0231
xgxs_tx_lane_map_ce11=0x1230
xgxs_tx_lane_map_ce12=0x3102
xgxs_tx_lane_map_ce13=0x2301
xgxs_tx_lane_map_ce14=0x0231
xgxs_tx_lane_map_ce15=0x1230
#core-16~23
xgxs_tx_lane_map_ce16=0x3102
xgxs_tx_lane_map_ce17=0x2301
xgxs_tx_lane_map_ce18=0x0231
xgxs_tx_lane_map_ce19=0x1230
xgxs_tx_lane_map_ce20=0x3102
xgxs_tx_lane_map_ce21=0x2301
xgxs_tx_lane_map_ce22=0x0231
xgxs_tx_lane_map_ce23=0x1230
#core-24~31
xgxs_tx_lane_map_ce24=0x3102
xgxs_tx_lane_map_ce25=0x2301
xgxs_tx_lane_map_ce26=0x0321
xgxs_tx_lane_map_ce27=0x3210
xgxs_tx_lane_map_ce28=0x1302
xgxs_tx_lane_map_ce29=0x2031
xgxs_tx_lane_map_ce30=0x3120
xgxs_tx_lane_map_ce31=0x3210
#core-32~39
xgxs_tx_lane_map_ce32=0x2310
xgxs_tx_lane_map_ce33=0x2301
xgxs_tx_lane_map_ce34=0x1203
xgxs_tx_lane_map_ce35=0x1032
xgxs_tx_lane_map_ce36=0x2130
xgxs_tx_lane_map_ce37=0x2301
xgxs_tx_lane_map_ce38=0x1302
xgxs_tx_lane_map_ce39=0x3210
#core-40~47
xgxs_tx_lane_map_ce40=0x3201
xgxs_tx_lane_map_ce41=0x0231
xgxs_tx_lane_map_ce42=0x1203
xgxs_tx_lane_map_ce43=0x1230
xgxs_tx_lane_map_ce44=0x3201
xgxs_tx_lane_map_ce45=0x0231
xgxs_tx_lane_map_ce46=0x1203
xgxs_tx_lane_map_ce47=0x3210
#core-48~55
xgxs_tx_lane_map_ce48=0x3201
xgxs_tx_lane_map_ce49=0x0231
xgxs_tx_lane_map_ce50=0x1203
xgxs_tx_lane_map_ce51=0x3210
xgxs_tx_lane_map_ce52=0x3201
xgxs_tx_lane_map_ce53=0x0231
xgxs_tx_lane_map_ce54=0x1203
xgxs_tx_lane_map_ce55=0x3210
#core-56~63
xgxs_tx_lane_map_ce56=0x1203
xgxs_tx_lane_map_ce57=0x2301
xgxs_tx_lane_map_ce58=0x0213
xgxs_tx_lane_map_ce59=0x3210
xgxs_tx_lane_map_ce60=0x0213
xgxs_tx_lane_map_ce61=0x3021
xgxs_tx_lane_map_ce62=0x3210
xgxs_tx_lane_map_ce63=0x3210
serdes_preemphasis_lane0_ce0=0x0c5800
serdes_preemphasis_lane1_ce0=0x0c5800
serdes_preemphasis_lane2_ce0=0x0c5800
serdes_preemphasis_lane3_ce0=0x0c5800
serdes_preemphasis_lane0_ce1=0x0c5800
serdes_preemphasis_lane1_ce1=0x0c5800
serdes_preemphasis_lane2_ce1=0x0c5800
serdes_preemphasis_lane3_ce1=0x0c5800
serdes_preemphasis_lane0_ce2=0x0c5800
serdes_preemphasis_lane1_ce2=0x0c5800
serdes_preemphasis_lane2_ce2=0x0c5800
serdes_preemphasis_lane3_ce2=0x0c5800
serdes_preemphasis_lane0_ce3=0x0c5800
serdes_preemphasis_lane1_ce3=0x0c5800
serdes_preemphasis_lane2_ce3=0x0c5800
serdes_preemphasis_lane3_ce3=0x0c5800
serdes_preemphasis_lane0_ce4=0x0c5800
serdes_preemphasis_lane1_ce4=0x0c5800
serdes_preemphasis_lane2_ce4=0x0c5800
serdes_preemphasis_lane3_ce4=0x0c5800
serdes_preemphasis_lane0_ce5=0x0c5800
serdes_preemphasis_lane1_ce5=0x0c5800
serdes_preemphasis_lane2_ce5=0x0c5800
serdes_preemphasis_lane3_ce5=0x0c5800
serdes_preemphasis_lane0_ce6=0x0c5800
serdes_preemphasis_lane1_ce6=0x0c5800
serdes_preemphasis_lane2_ce6=0x0c5800
serdes_preemphasis_lane3_ce6=0x0c5800
serdes_preemphasis_lane0_ce7=0x0c5800
serdes_preemphasis_lane1_ce7=0x0c5800
serdes_preemphasis_lane2_ce7=0x0c5800
serdes_preemphasis_lane3_ce7=0x0c5800
serdes_preemphasis_lane0_ce8=0x0c5800
serdes_preemphasis_lane1_ce8=0x0c5800
serdes_preemphasis_lane2_ce8=0x0c5800
serdes_preemphasis_lane3_ce8=0x0c5800
serdes_preemphasis_lane0_ce9=0x0c5800
serdes_preemphasis_lane1_ce9=0x0c5800
serdes_preemphasis_lane2_ce9=0x0c5800
serdes_preemphasis_lane3_ce9=0x0c5800
serdes_preemphasis_lane0_ce10=0x0c5800
serdes_preemphasis_lane1_ce10=0x0c5800
serdes_preemphasis_lane2_ce10=0x0c5800
serdes_preemphasis_lane3_ce10=0x0c5800
serdes_preemphasis_lane0_ce11=0x0c5800
serdes_preemphasis_lane1_ce11=0x0c5800
serdes_preemphasis_lane2_ce11=0x0c5800
serdes_preemphasis_lane3_ce11=0x0c5800
serdes_preemphasis_lane0_ce12=0x0c5800
serdes_preemphasis_lane1_ce12=0x0c5800
serdes_preemphasis_lane2_ce12=0x0c5800
serdes_preemphasis_lane3_ce12=0x0c5800
serdes_preemphasis_lane0_ce13=0x0c5800
serdes_preemphasis_lane1_ce13=0x0c5800
serdes_preemphasis_lane2_ce13=0x0c5800
serdes_preemphasis_lane3_ce13=0x0c5800
serdes_preemphasis_lane0_ce14=0x0c5800
serdes_preemphasis_lane1_ce14=0x0c5800
serdes_preemphasis_lane2_ce14=0x0c5800
serdes_preemphasis_lane3_ce14=0x0c5800
serdes_preemphasis_lane0_ce15=0x0c5800
serdes_preemphasis_lane1_ce15=0x0c5800
serdes_preemphasis_lane2_ce15=0x0c5800
serdes_preemphasis_lane3_ce15=0x0c5800
serdes_preemphasis_lane0_ce16=0x085408
serdes_preemphasis_lane1_ce16=0x085408
serdes_preemphasis_lane2_ce16=0x085408
serdes_preemphasis_lane3_ce16=0x085408
serdes_preemphasis_lane0_ce17=0x085408
serdes_preemphasis_lane1_ce17=0x085408
serdes_preemphasis_lane2_ce17=0x085408
serdes_preemphasis_lane3_ce17=0x085408
serdes_preemphasis_lane0_ce18=0x085408
serdes_preemphasis_lane1_ce18=0x085408
serdes_preemphasis_lane2_ce18=0x085408
serdes_preemphasis_lane3_ce18=0x085408
serdes_preemphasis_lane0_ce19=0x085408
serdes_preemphasis_lane1_ce19=0x085408
serdes_preemphasis_lane2_ce19=0x085408
serdes_preemphasis_lane3_ce19=0x085408
serdes_preemphasis_lane0_ce20=0x085408
serdes_preemphasis_lane1_ce20=0x085408
serdes_preemphasis_lane2_ce20=0x085408
serdes_preemphasis_lane3_ce20=0x085408
serdes_preemphasis_lane0_ce21=0x085408
serdes_preemphasis_lane1_ce21=0x085408
serdes_preemphasis_lane2_ce21=0x085408
serdes_preemphasis_lane3_ce21=0x085408
serdes_preemphasis_lane0_ce22=0x085408
serdes_preemphasis_lane1_ce22=0x085408
serdes_preemphasis_lane2_ce22=0x085408
serdes_preemphasis_lane3_ce22=0x085408
serdes_preemphasis_lane0_ce23=0x085408
serdes_preemphasis_lane1_ce23=0x085408
serdes_preemphasis_lane2_ce23=0x085408
serdes_preemphasis_lane3_ce23=0x085408
serdes_preemphasis_lane0_ce24=0x085408
serdes_preemphasis_lane1_ce24=0x085408
serdes_preemphasis_lane2_ce24=0x085408
serdes_preemphasis_lane3_ce24=0x085408
serdes_preemphasis_lane0_ce25=0x085408
serdes_preemphasis_lane1_ce25=0x085408
serdes_preemphasis_lane2_ce25=0x085408
serdes_preemphasis_lane3_ce25=0x085408
serdes_preemphasis_lane0_ce26=0x0a500a
serdes_preemphasis_lane1_ce26=0x0a500a
serdes_preemphasis_lane2_ce26=0x0a500a
serdes_preemphasis_lane3_ce26=0x0a500a
serdes_preemphasis_lane0_ce27=0x0a500a
serdes_preemphasis_lane1_ce27=0x0a500a
serdes_preemphasis_lane2_ce27=0x0a500a
serdes_preemphasis_lane3_ce27=0x0a500a
serdes_preemphasis_lane0_ce28=0x0a500a
serdes_preemphasis_lane1_ce28=0x0a500a
serdes_preemphasis_lane2_ce28=0x0a500a
serdes_preemphasis_lane3_ce28=0x0a500a
serdes_preemphasis_lane0_ce29=0x0a500a
serdes_preemphasis_lane1_ce29=0x0a500a
serdes_preemphasis_lane2_ce29=0x0a500a
serdes_preemphasis_lane3_ce29=0x0a500a
serdes_preemphasis_lane0_ce30=0x0a500a
serdes_preemphasis_lane1_ce30=0x0a500a
serdes_preemphasis_lane2_ce30=0x0a500a
serdes_preemphasis_lane3_ce30=0x0a500a
serdes_preemphasis_lane0_ce31=0x0a500a
serdes_preemphasis_lane1_ce31=0x0a500a
serdes_preemphasis_lane2_ce31=0x0a500a
serdes_preemphasis_lane3_ce31=0x0a500a
serdes_preemphasis_lane0_ce32=0x0a500a
serdes_preemphasis_lane1_ce32=0x0a500a
serdes_preemphasis_lane2_ce32=0x0a500a
serdes_preemphasis_lane3_ce32=0x0a500a
serdes_preemphasis_lane0_ce33=0x0a500a
serdes_preemphasis_lane1_ce33=0x0a500a
serdes_preemphasis_lane2_ce33=0x0a500a
serdes_preemphasis_lane3_ce33=0x0a500a
serdes_preemphasis_lane0_ce34=0x0a500a
serdes_preemphasis_lane1_ce34=0x0a500a
serdes_preemphasis_lane2_ce34=0x0a500a
serdes_preemphasis_lane3_ce34=0x0a500a
serdes_preemphasis_lane0_ce35=0x0a500a
serdes_preemphasis_lane1_ce35=0x0a500a
serdes_preemphasis_lane2_ce35=0x0a500a
serdes_preemphasis_lane3_ce35=0x0a500a
serdes_preemphasis_lane0_ce36=0x0a500a
serdes_preemphasis_lane1_ce36=0x0a500a
serdes_preemphasis_lane2_ce36=0x0a500a
serdes_preemphasis_lane3_ce36=0x0a500a
serdes_preemphasis_lane0_ce37=0x0a500a
serdes_preemphasis_lane1_ce37=0x0a500a
serdes_preemphasis_lane2_ce37=0x0a500a
serdes_preemphasis_lane3_ce37=0x0a500a
serdes_preemphasis_lane0_ce38=0x0a500a
serdes_preemphasis_lane1_ce38=0x0a500a
serdes_preemphasis_lane2_ce38=0x0a500a
serdes_preemphasis_lane3_ce38=0x0a500a
serdes_preemphasis_lane0_ce39=0x0a500a
serdes_preemphasis_lane1_ce39=0x0a500a
serdes_preemphasis_lane2_ce39=0x0a500a
serdes_preemphasis_lane3_ce39=0x0a500a
serdes_preemphasis_lane0_ce40=0x085408
serdes_preemphasis_lane1_ce40=0x085408
serdes_preemphasis_lane2_ce40=0x085408
serdes_preemphasis_lane3_ce40=0x085408
serdes_preemphasis_lane0_ce41=0x085408
serdes_preemphasis_lane1_ce41=0x085408
serdes_preemphasis_lane2_ce41=0x085408
serdes_preemphasis_lane3_ce41=0x085408
serdes_preemphasis_lane0_ce42=0x085408
serdes_preemphasis_lane1_ce42=0x085408
serdes_preemphasis_lane2_ce42=0x085408
serdes_preemphasis_lane3_ce42=0x085408
serdes_preemphasis_lane0_ce43=0x085408
serdes_preemphasis_lane1_ce43=0x085408
serdes_preemphasis_lane2_ce43=0x085408
serdes_preemphasis_lane3_ce43=0x085408
serdes_preemphasis_lane0_ce44=0x085408
serdes_preemphasis_lane1_ce44=0x085408
serdes_preemphasis_lane2_ce44=0x085408
serdes_preemphasis_lane3_ce44=0x085408
serdes_preemphasis_lane0_ce45=0x085408
serdes_preemphasis_lane1_ce45=0x085408
serdes_preemphasis_lane2_ce45=0x085408
serdes_preemphasis_lane3_ce45=0x085408
serdes_preemphasis_lane0_ce46=0x085408
serdes_preemphasis_lane1_ce46=0x085408
serdes_preemphasis_lane2_ce46=0x085408
serdes_preemphasis_lane3_ce46=0x085408
serdes_preemphasis_lane0_ce47=0x085408
serdes_preemphasis_lane1_ce47=0x085408
serdes_preemphasis_lane2_ce47=0x085408
serdes_preemphasis_lane3_ce47=0x085408
serdes_preemphasis_lane0_ce48=0x085408
serdes_preemphasis_lane1_ce48=0x085408
serdes_preemphasis_lane2_ce48=0x085408
serdes_preemphasis_lane3_ce48=0x085408
serdes_preemphasis_lane0_ce49=0x085408
serdes_preemphasis_lane1_ce49=0x085408
serdes_preemphasis_lane2_ce49=0x085408
serdes_preemphasis_lane3_ce49=0x085408
serdes_preemphasis_lane0_ce50=0x085408
serdes_preemphasis_lane1_ce50=0x085408
serdes_preemphasis_lane2_ce50=0x085408
serdes_preemphasis_lane3_ce50=0x085408
serdes_preemphasis_lane0_ce51=0x085408
serdes_preemphasis_lane1_ce51=0x085408
serdes_preemphasis_lane2_ce51=0x085408
serdes_preemphasis_lane3_ce51=0x085408
serdes_preemphasis_lane0_ce52=0x085408
serdes_preemphasis_lane1_ce52=0x085408
serdes_preemphasis_lane2_ce52=0x085408
serdes_preemphasis_lane3_ce52=0x085408
serdes_preemphasis_lane0_ce53=0x085408
serdes_preemphasis_lane1_ce53=0x085408
serdes_preemphasis_lane2_ce53=0x085408
serdes_preemphasis_lane3_ce53=0x085408
serdes_preemphasis_lane0_ce54=0x085408
serdes_preemphasis_lane1_ce54=0x085408
serdes_preemphasis_lane2_ce54=0x085408
serdes_preemphasis_lane3_ce54=0x085408
serdes_preemphasis_lane0_ce55=0x085408
serdes_preemphasis_lane1_ce55=0x085408
serdes_preemphasis_lane2_ce55=0x085408
serdes_preemphasis_lane3_ce55=0x085408
serdes_preemphasis_lane0_ce56=0x0c5800
serdes_preemphasis_lane1_ce56=0x0c5800
serdes_preemphasis_lane2_ce56=0x0c5800
serdes_preemphasis_lane3_ce56=0x0c5800
serdes_preemphasis_lane0_ce57=0x0c5800
serdes_preemphasis_lane1_ce57=0x0c5800
serdes_preemphasis_lane2_ce57=0x0c5800
serdes_preemphasis_lane3_ce57=0x0c5800
serdes_preemphasis_lane0_ce58=0x0c5800
serdes_preemphasis_lane1_ce58=0x0c5800
serdes_preemphasis_lane2_ce58=0x0c5800
serdes_preemphasis_lane3_ce58=0x0c5800
serdes_preemphasis_lane0_ce59=0x0c5800
serdes_preemphasis_lane1_ce59=0x0c5800
serdes_preemphasis_lane2_ce59=0x0c5800
serdes_preemphasis_lane3_ce59=0x0c5800
serdes_preemphasis_lane0_ce60=0x0c5800
serdes_preemphasis_lane1_ce60=0x0c5800
serdes_preemphasis_lane2_ce60=0x0c5800
serdes_preemphasis_lane3_ce60=0x0c5800
serdes_preemphasis_lane0_ce61=0x0c5800
serdes_preemphasis_lane1_ce61=0x0c5800
serdes_preemphasis_lane2_ce61=0x0c5800
serdes_preemphasis_lane3_ce61=0x0c5800
serdes_preemphasis_lane0_ce62=0x0c5800
serdes_preemphasis_lane1_ce62=0x0c5800
serdes_preemphasis_lane2_ce62=0x0c5800
serdes_preemphasis_lane3_ce62=0x0c5800
serdes_preemphasis_lane0_ce63=0x0c5800
serdes_preemphasis_lane1_ce63=0x0c5800
serdes_preemphasis_lane2_ce63=0x0c5800
serdes_preemphasis_lane3_ce63=0x0c5800
# # The TX and RX polarity flip variable.
# # It is affected by lane swapping, we used to debug for TE QSFP28 transceiver.
# #
# # Used to select the reference clock for Timestamping and BroadSync/10Mhz PLL value.
# # 25MHz LVPECL to BS_PLL0_REFCLK, BS_PLL1_REFCLK, and TS_PLL_REFCLK
# ptp_ts_pll_fref=25000000
# ptp_bs_fref=25000000

View File

@ -0,0 +1 @@
Alphanetworks-SNH60B0-640F t1

View File

@ -0,0 +1,9 @@
INTERVAL=10
FCTEMPS=/sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/3-004d/hwmon/hwmon2/temp1_input
FCFANS=/sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan1_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan2_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan3_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan4_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan11_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan12_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan13_input /sys/bus/i2c/devices/0-005e/fan_pwm=/sys/bus/i2c/devices/0-005e/fan14_input
MINTEMP=/sys/bus/i2c/devices/0-005e/fan_pwm=50
MAXTEMP=/sys/bus/i2c/devices/0-005e/fan_pwm=70
MINSTART=/sys/bus/i2c/devices/0-005e/fan_pwm=100
MINSTOP=/sys/bus/i2c/devices/0-005e/fan_pwm=100
MINPWM=/sys/bus/i2c/devices/0-005e/fan_pwm=100
MAXPWM=/sys/bus/i2c/devices/0-005e/fan_pwm=200

View File

@ -0,0 +1,3 @@
CONSOLE_PORT=0x3f8
CONSOLE_DEV=0
CONSOLE_SPEED=115200

View File

@ -0,0 +1,111 @@
# LED microprocessor initialization for alphanetworks snh60b0-640f
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_0_3 REMAP_PORT_0=0x3f REMAP_PORT_1=0x3e REMAP_PORT_2=0x3d REMAP_PORT_3=0x3c
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_4_7 REMAP_PORT_4=0x3b REMAP_PORT_5=0x3a REMAP_PORT_6=0x39 REMAP_PORT_7=0x38
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_8_11 REMAP_PORT_8=0x37 REMAP_PORT_9=0x36 REMAP_PORT_10=0x35 REMAP_PORT_11=0x34
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_12_15 REMAP_PORT_12=0x33 REMAP_PORT_13=0x32 REMAP_PORT_14=0x31 REMAP_PORT_15=0x30
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_16_19 REMAP_PORT_16=0x2f REMAP_PORT_17=0x2e REMAP_PORT_18=0x2d REMAP_PORT_19=0x2c
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_20_23 REMAP_PORT_20=0x2b REMAP_PORT_21=0x2a REMAP_PORT_22=0x29 REMAP_PORT_23=0x28
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_24_27 REMAP_PORT_24=0x27 REMAP_PORT_25=0x26 REMAP_PORT_26=0x25 REMAP_PORT_27=0x24
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_28_31 REMAP_PORT_28=0x23 REMAP_PORT_29=0x22 REMAP_PORT_30=0x21 REMAP_PORT_31=0x20
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_32_35 REMAP_PORT_32=0x1f REMAP_PORT_33=0x1e REMAP_PORT_34=0x1d REMAP_PORT_35=0x1c
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_36_39 REMAP_PORT_36=0x1b REMAP_PORT_37=0x1a REMAP_PORT_38=0x19 REMAP_PORT_39=0x18
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_40_43 REMAP_PORT_40=0x17 REMAP_PORT_41=0x16 REMAP_PORT_42=0x15 REMAP_PORT_43=0x14
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_44_47 REMAP_PORT_44=0x13 REMAP_PORT_45=0x12 REMAP_PORT_46=0x11 REMAP_PORT_47=0x10
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_48_51 REMAP_PORT_48=0xf REMAP_PORT_49=0xe REMAP_PORT_50=0xd REMAP_PORT_51=0xc
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_52_55 REMAP_PORT_52=0xb REMAP_PORT_53=0xa REMAP_PORT_54=9 REMAP_PORT_55=8
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_56_59 REMAP_PORT_56=7 REMAP_PORT_57=6 REMAP_PORT_58=5 REMAP_PORT_59=4
modreg CMIC_LEDUP0_PORT_ORDER_REMAP_60_63 REMAP_PORT_60=3 REMAP_PORT_61=2 REMAP_PORT_62=1 REMAP_PORT_63=0
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_0_3 REMAP_PORT_0=3 REMAP_PORT_1=2 REMAP_PORT_2=1 REMAP_PORT_3=0
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_4_7 REMAP_PORT_4=7 REMAP_PORT_5=6 REMAP_PORT_6=5 REMAP_PORT_7=4
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_8_11 REMAP_PORT_8=0xb REMAP_PORT_9=0xa REMAP_PORT_10=9 REMAP_PORT_11=8
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_12_15 REMAP_PORT_12=0xf REMAP_PORT_13=0xe REMAP_PORT_14=0xd REMAP_PORT_15=0xc
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_16_19 REMAP_PORT_16=0x13 REMAP_PORT_17=0x12 REMAP_PORT_18=0x11 REMAP_PORT_19=0x10
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_20_23 REMAP_PORT_20=0x17 REMAP_PORT_21=0x16 REMAP_PORT_22=0x15 REMAP_PORT_23=0x14
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_24_27 REMAP_PORT_24=0x1b REMAP_PORT_25=0x1a REMAP_PORT_26=0x19 REMAP_PORT_27=0x18
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_28_31 REMAP_PORT_28=0x1f REMAP_PORT_29=0x1e REMAP_PORT_30=0x1d REMAP_PORT_31=0x1c
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_32_35 REMAP_PORT_32=0x23 REMAP_PORT_33=0x22 REMAP_PORT_34=0x21 REMAP_PORT_35=0x20
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_36_39 REMAP_PORT_36=0x27 REMAP_PORT_37=0x26 REMAP_PORT_38=0x25 REMAP_PORT_39=0x24
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_40_43 REMAP_PORT_40=0x2b REMAP_PORT_41=0x2a REMAP_PORT_42=0x29 REMAP_PORT_43=0x28
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_44_47 REMAP_PORT_44=0x2f REMAP_PORT_45=0x2e REMAP_PORT_46=0x2d REMAP_PORT_47=0x2c
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_48_51 REMAP_PORT_48=0x33 REMAP_PORT_49=0x32 REMAP_PORT_50=0x31 REMAP_PORT_51=0x30
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_52_55 REMAP_PORT_52=0x37 REMAP_PORT_53=0x36 REMAP_PORT_54=0x35 REMAP_PORT_55=0x34
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_56_59 REMAP_PORT_56=0x3b REMAP_PORT_57=0x3a REMAP_PORT_58=0x39 REMAP_PORT_59=0x38
modreg CMIC_LEDUP1_PORT_ORDER_REMAP_60_63 REMAP_PORT_60=0x3f REMAP_PORT_61=0x3e REMAP_PORT_62=0x3d REMAP_PORT_63=0x3c
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_0_3 REMAP_PORT_0=0x3f REMAP_PORT_1=0x3e REMAP_PORT_2=0x3d REMAP_PORT_3=0x3c
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_4_7 REMAP_PORT_4=0x3b REMAP_PORT_5=0x3a REMAP_PORT_6=0x39 REMAP_PORT_7=0x38
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_8_11 REMAP_PORT_8=0x37 REMAP_PORT_9=0x36 REMAP_PORT_10=0x35 REMAP_PORT_11=0x34
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_12_15 REMAP_PORT_12=0x33 REMAP_PORT_13=0x32 REMAP_PORT_14=0x31 REMAP_PORT_15=0x30
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_16_19 REMAP_PORT_16=0x2f REMAP_PORT_17=0x2e REMAP_PORT_18=0x2d REMAP_PORT_19=0x2c
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_20_23 REMAP_PORT_20=0x2b REMAP_PORT_21=0x2a REMAP_PORT_22=0x29 REMAP_PORT_23=0x28
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_24_27 REMAP_PORT_24=0x27 REMAP_PORT_25=0x26 REMAP_PORT_26=0x25 REMAP_PORT_27=0x24
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_28_31 REMAP_PORT_28=0x23 REMAP_PORT_29=0x22 REMAP_PORT_30=0x21 REMAP_PORT_31=0x20
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_32_35 REMAP_PORT_32=0x1f REMAP_PORT_33=0x1e REMAP_PORT_34=0x1d REMAP_PORT_35=0x1c
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_36_39 REMAP_PORT_36=0x1b REMAP_PORT_37=0x1a REMAP_PORT_38=0x19 REMAP_PORT_39=0x18
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_40_43 REMAP_PORT_40=0x17 REMAP_PORT_41=0x16 REMAP_PORT_42=0x15 REMAP_PORT_43=0x14
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_44_47 REMAP_PORT_44=0x13 REMAP_PORT_45=0x12 REMAP_PORT_46=0x11 REMAP_PORT_47=0x10
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_48_51 REMAP_PORT_48=0xf REMAP_PORT_49=0xe REMAP_PORT_50=0xd REMAP_PORT_51=0xc
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_52_55 REMAP_PORT_52=0xb REMAP_PORT_53=0xa REMAP_PORT_54=9 REMAP_PORT_55=8
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_56_59 REMAP_PORT_56=7 REMAP_PORT_57=6 REMAP_PORT_58=5 REMAP_PORT_59=4
modreg CMIC_LEDUP2_PORT_ORDER_REMAP_60_63 REMAP_PORT_60=3 REMAP_PORT_61=2 REMAP_PORT_62=1 REMAP_PORT_63=0
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_0_3 REMAP_PORT_0=3 REMAP_PORT_1=2 REMAP_PORT_2=1 REMAP_PORT_3=0
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_4_7 REMAP_PORT_4=7 REMAP_PORT_5=6 REMAP_PORT_6=5 REMAP_PORT_7=4
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_8_11 REMAP_PORT_8=0xb REMAP_PORT_9=0xa REMAP_PORT_10=9 REMAP_PORT_11=8
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_12_15 REMAP_PORT_12=0xf REMAP_PORT_13=0xe REMAP_PORT_14=0xd REMAP_PORT_15=0xc
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_16_19 REMAP_PORT_16=0x13 REMAP_PORT_17=0x12 REMAP_PORT_18=0x11 REMAP_PORT_19=0x10
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_20_23 REMAP_PORT_20=0x17 REMAP_PORT_21=0x16 REMAP_PORT_22=0x15 REMAP_PORT_23=0x14
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_24_27 REMAP_PORT_24=0x1b REMAP_PORT_25=0x1a REMAP_PORT_26=0x19 REMAP_PORT_27=0x18
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_28_31 REMAP_PORT_28=0x1f REMAP_PORT_29=0x1e REMAP_PORT_30=0x1d REMAP_PORT_31=0x1c
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_32_35 REMAP_PORT_32=0x23 REMAP_PORT_33=0x22 REMAP_PORT_34=0x21 REMAP_PORT_35=0x20
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_36_39 REMAP_PORT_36=0x27 REMAP_PORT_37=0x26 REMAP_PORT_38=0x25 REMAP_PORT_39=0x24
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_40_43 REMAP_PORT_40=0x2b REMAP_PORT_41=0x2a REMAP_PORT_42=0x29 REMAP_PORT_43=0x28
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_44_47 REMAP_PORT_44=0x2f REMAP_PORT_45=0x2e REMAP_PORT_46=0x2d REMAP_PORT_47=0x2c
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_48_51 REMAP_PORT_48=0x33 REMAP_PORT_49=0x32 REMAP_PORT_50=0x31 REMAP_PORT_51=0x30
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_52_55 REMAP_PORT_52=0x37 REMAP_PORT_53=0x36 REMAP_PORT_54=0x35 REMAP_PORT_55=0x34
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_56_59 REMAP_PORT_56=0x3b REMAP_PORT_57=0x3a REMAP_PORT_58=0x39 REMAP_PORT_59=0x38
modreg CMIC_LEDUP3_PORT_ORDER_REMAP_60_63 REMAP_PORT_60=0x3f REMAP_PORT_61=0x3e REMAP_PORT_62=0x3d REMAP_PORT_63=0x3c
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_0_3 REMAP_PORT_0=0x3f REMAP_PORT_1=1 REMAP_PORT_2=0x3f REMAP_PORT_3=0
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_4_7 REMAP_PORT_4=0x3f REMAP_PORT_5=0x3f REMAP_PORT_6=0x3f REMAP_PORT_7=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_8_11 REMAP_PORT_8=0x3f REMAP_PORT_9=0x3f REMAP_PORT_10=0x3f REMAP_PORT_11=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_12_15 REMAP_PORT_12=0x3f REMAP_PORT_13=0x3f REMAP_PORT_14=0x3f REMAP_PORT_15=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_16_19 REMAP_PORT_16=0x3f REMAP_PORT_17=0x3f REMAP_PORT_18=0x3f REMAP_PORT_19=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_20_23 REMAP_PORT_20=0x3f REMAP_PORT_21=0x3f REMAP_PORT_22=0x3f REMAP_PORT_23=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_24_27 REMAP_PORT_24=0x3f REMAP_PORT_25=0x3f REMAP_PORT_26=0x3f REMAP_PORT_27=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_28_31 REMAP_PORT_28=0x3f REMAP_PORT_29=0x3f REMAP_PORT_30=0x3f REMAP_PORT_31=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_32_35 REMAP_PORT_32=0x3f REMAP_PORT_33=0x3f REMAP_PORT_34=0x3f REMAP_PORT_35=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_36_39 REMAP_PORT_36=0x3f REMAP_PORT_37=0x3f REMAP_PORT_38=0x3f REMAP_PORT_39=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_40_43 REMAP_PORT_40=0x3f REMAP_PORT_41=0x3f REMAP_PORT_42=0x3f REMAP_PORT_43=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_44_47 REMAP_PORT_44=0x3f REMAP_PORT_45=0x3f REMAP_PORT_46=0x3f REMAP_PORT_47=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_48_51 REMAP_PORT_48=0x3f REMAP_PORT_49=0x3f REMAP_PORT_50=0x3f REMAP_PORT_51=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_52_55 REMAP_PORT_52=0x3f REMAP_PORT_53=0x3f REMAP_PORT_54=0x3f REMAP_PORT_55=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_56_59 REMAP_PORT_56=0x3f REMAP_PORT_57=0x3f REMAP_PORT_58=0x3f REMAP_PORT_59=0x3f
modreg CMIC_LEDUP4_PORT_ORDER_REMAP_60_63 REMAP_PORT_60=0x3f REMAP_PORT_61=0x3f REMAP_PORT_62=0x3f REMAP_PORT_63=0x3f
led 0 stop
led 0 prog 86 FF 06 FF C2 7F 60 FF 02 41 60 FE 67 1A 06 FE E2 04 60 FE D2 01 74 0C 77 51 02 9F F6 FE E2 04 04 D2 01 70 27 74 48 06 FE E2 04 90 28 32 00 32 01 B7 97 71 37 75 3F 06 FF C2 10 70 48 74 3F 67 57 67 53 67 57 67 57 57 67 57 67 57 67 57 67 57 57 3A 40 32 0E 87 57 32 0F 87 57
led 0 auto on
led 0 start
led 1 stop
led 1 prog 86 FF 06 FF C2 7F 60 FF 02 41 60 FE 67 1A 06 FE E2 04 60 FE D2 01 74 0C 77 51 02 9F F6 FE E2 04 04 D2 01 70 27 74 48 06 FE E2 04 90 28 32 00 32 01 B7 97 71 37 75 3F 06 FF C2 10 70 48 74 3F 67 57 67 53 67 57 67 57 57 67 57 67 57 67 57 67 57 57 3A 40 32 0E 87 57 32 0F 87 57
led 1 auto on
led 1 start
led 2 stop
led 2 prog 86 FF 06 FF C2 7F 60 FF 02 41 60 FE 67 1A 06 FE E2 04 60 FE D2 01 74 0C 77 51 02 9F F6 FE E2 04 04 D2 01 70 27 74 48 06 FE E2 04 90 28 32 00 32 01 B7 97 71 37 75 3F 06 FF C2 10 70 48 74 3F 67 57 67 53 67 57 67 57 57 67 57 67 57 67 57 67 57 57 3A 40 32 0E 87 57 32 0F 87 57
led 2 auto on
led 2 start
led 3 stop
led 3 prog 86 FF 06 FF C2 7F 60 FF 02 41 60 FE 67 1A 06 FE E2 04 60 FE D2 01 74 0C 77 51 02 9F F6 FE E2 04 04 D2 01 70 27 74 48 06 FE E2 04 90 28 32 00 32 01 B7 97 71 37 75 3F 06 FF C2 10 70 48 74 3F 67 57 67 53 67 57 67 57 57 67 57 67 57 67 57 67 57 57 3A 40 32 0E 87 57 32 0F 87 57
led 3 auto on
led 3 start
led 4 stop
led 4 prog 86 FF 06 FF C2 7F 60 FF 02 02 60 FE 67 1A 06 FE E2 01 60 FE D2 00 74 0C 77 6A 02 9F F6 FE 04 D2 01 70 25 74 51 06 FE 90 28 32 03 32 04 97 75 64 97 71 58 75 5E 06 FE 90 28 32 00 32 01 B7 97 71 43 75 4B 06 FF C2 10 70 4E 74 4B 67 6C 57 67 70 57 67 70 67 70 67 70 57 67 6C 67 70 77 35 67 70 67 6C 77 35 67 70 67 70 77 35 3A 06 32 0E 87 57 32 0F 87 57
led 4 auto on
led 4 start

View File

@ -0,0 +1,24 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
import warnings
import os
import sys
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom"
#Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

View File

@ -0,0 +1,217 @@
#!/usr/bin/env python
#
# led_control.py
#
# Platform-specific LED control functionality for SONiC
#
# try:
# from sonic_led.led_control_base import LedControlBase
# import swsssdk
# except ImportError, e:
# raise ImportError (str(e) + " - required module not found")
import time
class LedControlBase(object):
# __metaclass__ = abc.ABCMeta
# @abc.abstractmethod
def port_link_state_change(self, port, state):
"""
Called when port link state changes. Update port link state LED here.
:param port: A string, SONiC port name (e.g., "Ethernet0")
:param state: A string, the port link state (either "up" or "down")
"""
return
### Goreme specified ###
read_fan_fault = 0
is_fan_all_OK = 0
read_power_status = 0
is_power_all_OK = 0
is_thermal_high = 0
is_reset_button_push = 0
##########################
def sysled_task():
while True:
system_led_check()
time.sleep(5)
########## Goreme System LED checking
def system_led_check():
global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push
is_fan_all_OK = 1
is_power_all_OK = 0
is_thermal_high = 0
is_reset_button_push = 0
with open("/sys/bus/i2c/devices/0-005e/fan1_fault", "r") as f1:
read_fan_fault = f1.read()
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
with open("/sys/bus/i2c/devices/0-005e/fan2_fault", "r") as f1:
read_fan_fault = f1.read()
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
with open("/sys/bus/i2c/devices/0-005e/fan3_fault", "r") as f1:
read_fan_fault = f1.read()
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
with open("/sys/bus/i2c/devices/0-005e/fan4_fault", "r") as f1:
read_fan_fault = f1.read()
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
with open("/sys/bus/i2c/devices/8-005f/fan1_led", "w") as f11:
if int(is_fan_all_OK) == 1:
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/0-005e/psu1_power_good", "r") as f1:
read_power_status = f1.read()
if str(read_power_status) != str("1\n"):
is_power_all_OK = -10
with open("/sys/bus/i2c/devices/0-005e/psu1_present", "r") as f1:
read_power_status = f1.read()
if str(read_power_status) == str("1\n"):
is_power_all_OK = is_power_all_OK + 1
with open("/sys/bus/i2c/devices/0-005e/psu2_power_good", "r") as f1:
read_power_status = f1.read()
if str(read_power_status) != str("1\n"):
is_power_all_OK = -10
with open("/sys/bus/i2c/devices/0-005e/psu2_present", "r") as f1:
read_power_status = f1.read()
if str(read_power_status) == str("1\n"):
is_power_all_OK = is_power_all_OK + 1
with open("/sys/bus/i2c/devices/8-005f/sys_pwr", "w") as f11:
if int(is_power_all_OK) > 0:
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/8-005f/swi_ctrl", "r") as f5:
is_reset_button_push = f5.read()
if str(is_reset_button_push) == "1\n":
is_reset_button_push = 1
else:
is_reset_button_push = 0
with open("/sys/bus/i2c/devices/3-004d/hwmon/hwmon2/temp1_input", "r") as f3:
is_thermal_high = f3.read()
if int(is_thermal_high) >= 70000:
is_thermal_high = 1
else:
is_thermal_high = 0
with open("/sys/bus/i2c/devices/8-005f/sys_status", "w") as f2:
if is_reset_button_push == 1:
f2.write("3")
elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1:
f2.write("4")
else:
f2.write("1")
return
##########
class LedControl(LedControlBase):
"""Platform specific LED control class"""
PORT_TABLE_PREFIX = "PORT_TABLE:"
SONIC_PORT_NAME_PREFIX = "Ethernet"
LED_SYSFS_PATH_BREAKOUT_CAPABLE = "/sys/class/leds/qsfp{0}_{1}/brightness"
LED_SYSFS_PATH_NO_BREAKOUT = "/sys/class/leds/qsfp{0}/brightness"
QSFP_BREAKOUT_START_IDX = 1
QSFP_BREAKOUT_END_IDX = 24
QSFP_NO_BREAKOUT_START_IDX = 25
QSFP_NO_BREAKOUT_END_IDX = 32
LED_COLOR_OFF = 0
LED_COLOR_GREEN = 1
LED_COLOR_YELLOW = 2
# Helper method to map SONiC port name to Arista QSFP index
def _port_name_to_qsfp_index(self, port_name):
# Strip "Ethernet" off port name
if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX):
return -1
sonic_port_num = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):])
swss = swsssdk.SonicV2Connector()
swss.connect(swss.APPL_DB)
lanes = swss.get(swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes')
# SONiC port nums are 0-based and increment by 4
# Arista QSFP indices are 1-based and increment by 1
return (((sonic_port_num/4) + 1), sonic_port_num%4, len(lanes.split(',')))
# Concrete implementation of port_link_state_change() method
def port_link_state_change_bk(self, port, state):
qsfp_index, lane_index, lanes = self._port_name_to_qsfp_index(port)
# Ignore invalid QSFP indices
if qsfp_index <= 0 or lanes <= 0 or lanes > 4:
return
# QSFP indices 0-24 are breakout-capable and have four LEDs, and each LED indicate one lane.
# whereas indices 25-32 are not breakout-capable, and only have one
if qsfp_index <= self.QSFP_BREAKOUT_END_IDX:
# assuming 40G, then we need to control four lanes
led_sysfs_paths = [ self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes) ]
else:
led_sysfs_paths = [ self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index) ]
for led_sysfs_path in led_sysfs_paths:
led_file = open(led_sysfs_path, "w")
if state == "up":
led_file.write("%d" % self.LED_COLOR_GREEN)
else:
led_file.write("%d" % self.LED_COLOR_OFF)
led_file.close()
# Constructor
def __init__(self):
# Initialize all front-panel status LEDs to green
with open("/sys/bus/i2c/devices/8-005f/sys_locator", "w") as f:
f.write("0")
with open("/sys/bus/i2c/devices/8-005f/sys_pwr", "w") as f:
f.write("1")
with open("/sys/bus/i2c/devices/8-005f/sys_status", "w") as f:
f.write("1")
# Initialize all fan LEDs to green
with open("/sys/bus/i2c/devices/8-005f/fan1_led", "w") as f:
f.write("1")
with open("/sys/bus/i2c/devices/8-005f/fan2_led", "w") as f:
f.write("1")
with open("/sys/bus/i2c/devices/8-005f/fan3_led", "w") as f:
f.write("1")
with open("/sys/bus/i2c/devices/8-005f/fan4_led", "w") as f:
f.write("1")
sysled_task()
# Initialize: Turn all front panel QSFP LEDs off
# # for qsfp_index in range(self.QSFP_BREAKOUT_START_IDX, self.QSFP_BREAKOUT_END_IDX + 1):
# # for lane in range(1, 5):
# # led_sysfs_path = self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, lane)
# # with open(led_sysfs_path, 'w') as led_file:
# # led_file.write("%d" % self.LED_COLOR_OFF)
# # for qsfp_index in range(self.QSFP_NO_BREAKOUT_START_IDX, self.QSFP_NO_BREAKOUT_END_IDX + 1):
# # led_sysfs_path = self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index)
# # with open(led_sysfs_path, 'w') as led_file:
# # led_file.write("%d" % self.LED_COLOR_OFF)

View File

@ -0,0 +1,66 @@
#!/usr/bin/env python
#############################################################################
# Alphanetworks
#
# Module contains an implementation of SONiC PSU Base API and
# provides the PSUs status which are available in the platform
#
#############################################################################
import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""
def __init__(self):
PsuBase.__init__(self)
self.psu_path = "/sys/bus/i2c/devices/"
self.psu_presence = {
1: "/psu1_present",
2: "/psu2_present",
}
self.psu_oper_status = {
1: "/psu1_power_good",
2: "/psu2_power_good",
}
self.psu_mapping = "0-005e"
if not os.path.exists(self.psu_path+self.psu_mapping):
self.psu_mapping = "1-005e"
def get_num_psus(self):
return len(self.psu_presence)
def get_psu_status(self, index):
if index is None:
return False
status = 0
node = self.psu_path + self.psu_mapping+self.psu_oper_status[index]
try:
with open(node, 'r') as power_status:
status = int(power_status.read())
except IOError:
return False
return status == 1
def get_psu_presence(self, index):
if index is None:
return False
status = 0
node = self.psu_path + self.psu_mapping + self.psu_presence[index]
try:
with open(node, 'r') as presence_status:
status = int(presence_status.read())
except IOError:
return False
return status == 1

View File

@ -0,0 +1,132 @@
#!/usr/bin/env python
try:
import time
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
class SfpUtil(SfpUtilBase):
"""Platform specific SfpUtill class"""
first_port = 0
last_port = 65
port_num = 63
port_to_eeprom = {}
port_to_i2cbus_mapping = {
1 : 13,
2 : 14,
3 : 15,
4 : 16,
5 : 23,
}
eeprom_path_1 = "/sys/bus/i2c/devices/{0}-0020/sfp{1}_eeprom"
eeprom_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_eeprom"
port_reset_path_1 = "/sys/bus/i2c/devices/{0}-0020/sfp{1}_port_reset"
port_reset_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_port_reset"
present_path_1 = "/sys/bus/i2c/devices/{0}-0020/sfp{1}_is_present"
present_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_is_present"
_qsfp_ports = range(first_port, port_num)
@property
def port_start(self):
return self.first_port
@property
def port_end(self):
return self.last_port
@property
def qsfp_ports(self):
return range(self.first_port, self.port_num + 1)
@property
def port_to_eeprom_mapping(self):
return self.port_to_eeprom
def get_transceiver_change_event(self):
"""
TODO: This function need to be implemented
when decide to support monitoring SFP(Xcvrd)
on this platform.
"""
raise NotImplementedError
def __init__(self):
for x in range(self.first_port, self.last_port + 1):
cpld_index = (x / 16) + 1
index = (x % 16) + 1
if cpld_index == 5:
path = self.eeprom_path_1
else:
path = self.eeprom_path
self.port_to_eeprom[x] = path.format(self.port_to_i2cbus_mapping[cpld_index], index)
SfpUtilBase.__init__(self)
def reset(self, port_num):
# Check for invalid port_num
if port_num < self.first_port or port_num > self.last_port:
return False
cpld_index = (port_num / 16) + 1
index = (port_num % 16) + 1
if cpld_index == 5:
path = self.port_reset_path_1
else:
path = self.port_reset_path
port_path = path.format(self.port_to_i2cbus_mapping[cpld_index], index)
try:
reg_file = open(port_path, 'w')
except IOError as e:
if cpld_index < 5:
print "Error: unable to open file: %s" % str(e)
return False
# reset
reg_file.write('1')
time.sleep(1)
reg_file.write('0')
reg_file.close()
return True
def set_low_power_mode(self, port_nuM, lpmode):
raise NotImplementedError
def get_low_power_mode(self, port_num):
raise NotImplementedError
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.first_port or port_num > self.last_port:
return False
cpld_index = (port_num / 16) + 1
index = (port_num % 16) + 1
if cpld_index == 5:
path = self.present_path_1
else:
path = self.present_path
port_path = path.format(self.port_to_i2cbus_mapping[cpld_index], index)
try:
reg_file = open(port_path)
except IOError as e:
if cpld_index < 5:
print "Error: unable to open file: %s" % str(e)
return False
reg_value = reg_file.readline().rstrip()
if reg_value == '1':
return True
return False

View File

@ -0,0 +1,13 @@
# libsensors configuration file for snh60b0_640f
# ------------------------------------------------
bus "i2c-1" "SMBus I801 adapter at f000"
chip "goreme_power_cpld-*"
label fan1 "Fan tray 1 front"
label fan2 "Fan tray 2 front"
label fan3 "Fan tray 3 front"
label fan4 "Fan tray 4 front"
label fan11 "Fan tray 1 rear"
label fan12 "Fan tray 2 rear"
label fan13 "Fan tray 3 rear"
label fan14 "Fan tray 4 rear"

View File

@ -30,6 +30,8 @@ $(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(DELL_S6000_PLATFORM_MODULE) \
$(DELTA_AG5648_PLATFORM_MODULE) \
$(DELTA_ET6248BRB_PLATFORM_MODULE) \
$(QUANTA_IX1B_32X_PLATFORM_MODULE) \
$(MITAC_LY1200_32X_PLATFORM_MODULE)
$(MITAC_LY1200_32X_PLATFORM_MODULE) \
$(ALPHANETWORKS_SNH60A0_320FV2_PLATFORM_MODULE) \
$(ALPHANETWORKS_SNH60B0_640F_PLATFORM_MODULE)
$(SONIC_ONE_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_IMAGES)
SONIC_INSTALLERS += $(SONIC_ONE_IMAGE)

View File

@ -0,0 +1,21 @@
# Alphanetworks Platform modules
ALPHANETWORKS_SNH60A0_320FV2_PLATFORM_MODULE_VERSION = 1.0
ALPHANETWORKS_SNH60B0_640F_PLATFORM_MODULE_VERSION = 1.0
export ALPHANETWORKS_SNH60A0_320FV2_PLATFORM_MODULE_VERSION
export ALPHANETWORKS_SNH60B0_640F_PLATFORM_MODULE_VERSION
ALPHANETWORKS_SNH60A0_320FV2_PLATFORM_MODULE = sonic-platform-alphanetworks-snh60a0-320fv2_$(ALPHANETWORKS_SNH60A0_320FV2_PLATFORM_MODULE_VERSION)_amd64.deb
$(ALPHANETWORKS_SNH60A0_320FV2_PLATFORM_MODULE)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-alphanetworks
$(ALPHANETWORKS_SNH60A0_320FV2_PLATFORM_MODULE)_DEPENDS += $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON)
$(ALPHANETWORKS_SNH60A0_320FV2_PLATFORM_MODULE)_PLATFORM = x86_64-alphanetworks_snh60a0_320fv2-r0
SONIC_DPKG_DEBS += $(ALPHANETWORKS_SNH60A0_320FV2_PLATFORM_MODULE)
ALPHANETWORKS_SNH60B0_640F_PLATFORM_MODULE = sonic-platform-alphanetworks-snh60b0-640f_$(ALPHANETWORKS_SNH60B0_640F_PLATFORM_MODULE_VERSION)_amd64.deb
$(ALPHANETWORKS_SNH60B0_640F_PLATFORM_MODULE)_PLATFORM = x86_64-alphanetworks_snh60b0_640f-r0
$(eval $(call add_extra_package,$(ALPHANETWORKS_SNH60A0_320FV2_PLATFORM_MODULE),$(ALPHANETWORKS_SNH60B0_640F_PLATFORM_MODULE)))
SONIC_STRETCH_DEBS += $(ALPHANETWORKS_SNH60A0_320FV2_PLATFORM_MODULE)

View File

@ -5,6 +5,7 @@ include $(PLATFORM_PATH)/platform-modules-dell.mk
include $(PLATFORM_PATH)/platform-modules-arista.mk
include $(PLATFORM_PATH)/platform-modules-ingrasys.mk
include $(PLATFORM_PATH)/platform-modules-accton.mk
include $(PLATFORM_PATH)/platform-modules-alphanetworks.mk
include $(PLATFORM_PATH)/platform-modules-inventec.mk
include $(PLATFORM_PATH)/platform-modules-cel.mk
include $(PLATFORM_PATH)/platform-modules-delta.mk

View File

@ -0,0 +1,50 @@
# Object files
*.o
*.ko
*.obj
*.elf
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
# Kernel Module Compile Results
*.mod*
*.cmd
*.o.d
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
# Debian packaging
*.debhelper.log
*.postinst.debhelper
*.postrm.debhelper
*.prerm.debhelper
*.substvars

View File

@ -0,0 +1 @@
platform drivers of Alphanetworks products for the SONiC project

View File

@ -0,0 +1,6 @@
sonic-alphanetworks-platform-modules (1.0) unstable; urgency=low
* Add support for SNH60A0-320FV2 and SNH60B0_640F.
-- Alphanetworks <Jun_Tseng@alphanetworks.com> Tue, 19 Dec 2017 09:35:58 +0800

View File

@ -0,0 +1,17 @@
Source: sonic-alphanetworks-platform-modules
Section: main
Priority: extra
Maintainer: Alphanetworks <Jun_Tseng@alphanetworks.com>, Alphanetworks <Jun_Tseng@alphanetworks.com>
Build-Depends: debhelper (>= 8.0.0), bzip2
Standards-Version: 3.9.3
Package: sonic-platform-alphanetworks-snh60a0-320fv2
Architecture: amd64
Depends: linux-image-4.9.0-7-amd64
Description: kernel modules for platform devices such as fan, led, sfp
Package: sonic-platform-alphanetworks-snh60b0-640f
Architecture: amd64
Depends: linux-image-4.9.0-7-amd64
Description: kernel modules for platform devices such as fan, led, sfp

View File

@ -0,0 +1,86 @@
#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.
include /usr/share/dpkg/pkg-info.mk
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export INSTALL_MOD_DIR:=extra
PYTHON ?= python2
PACKAGE_PRE_NAME := sonic-platform-alphanetworks
KVERSION ?= $(shell uname -r)
KERNEL_SRC := /lib/modules/$(KVERSION)
MOD_SRC_DIR:= $(shell pwd)
MODULE_DIRS:= snh60a0-320fv2 snh60b0-640f
MODULE_DIR := modules
UTILS_DIR := utils
SERVICE_DIR := service
CLASSES_DIR := classes
CONF_DIR := conf
%:
dh $@ --with systemd,python2,python3 --buildsystem=pybuild
clean:
dh_testdir
dh_testroot
dh_clean
build:
#make modules -C $(KERNEL_SRC)/build M=$(MODULE_SRC)
(for mod in $(MODULE_DIRS); do \
make modules -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules; \
$(PYTHON) $${mod}/setup.py build; \
done)
binary: binary-arch binary-indep
# Nothing to do
binary-arch:
# Nothing to do
#install: build
#dh_testdir
#dh_testroot
#dh_clean -k
#dh_installdirs
binary-indep:
dh_testdir
dh_installdirs
# Custom package commands
(for mod in $(MODULE_DIRS); do \
dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod}/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \
dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod}/usr/local/bin; \
dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod}/lib/systemd/system; \
cp $(MOD_SRC_DIR)/$${mod}/$(MODULE_DIR)/*.ko debian/$(PACKAGE_PRE_NAME)-$${mod}/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \
cp $(MOD_SRC_DIR)/$${mod}/$(UTILS_DIR)/* debian/$(PACKAGE_PRE_NAME)-$${mod}/usr/local/bin/; \
cp $(MOD_SRC_DIR)/$${mod}/$(SERVICE_DIR)/*.service debian/$(PACKAGE_PRE_NAME)-$${mod}/lib/systemd/system/; \
$(PYTHON) $${mod}/setup.py install --root=$(MOD_SRC_DIR)/debian/$(PACKAGE_PRE_NAME)-$${mod} --install-layout=deb; \
done)
# Resuming debhelper scripts
dh_testroot
dh_install
dh_installchangelogs
dh_installdocs
dh_systemd_enable
dh_installinit
dh_systemd_start
dh_link
dh_fixperms
dh_compress
dh_strip
dh_installdeb
dh_gencontrol
dh_md5sums
dh_builddeb
.PHONY: build binary binary-arch binary-indep clean

View File

@ -0,0 +1,8 @@
# obj-m:=accton_as7712_32x_fan.o accton_as7712_32x_sfp.o leds-accton_as7712_32x.o \
# goreme_system_cpld.o ym2651y.o optoe.o
obj-m:=alphanetworks_snh60a0-320fv2_sfp.o snh60a0_system_cpld.o snh60a0_power_cpld.o snh60a0_onie_eeprom.o
# obj-m:=accton_as7712_32x_fan.o accton_as7712_32x_sfp.o leds-accton_as7712_32x.o \
# accton_as7712_32x_psu.o accton_i2c_cpld.o ym2651y.o optoe.o

View File

@ -0,0 +1,268 @@
/*
* A driver for alphanetworks_snh60a0_320fv2 onie eeprom
*
* Copyright (C) 2018 Alphanetworks Technology Corporation.
* Robin Chen <Robin_chen@Alphanetworks.com>
* 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
* 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.
* see <http://www.gnu.org/licenses/>
*
* 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/i2c.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/dmi.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/mutex.h>
#define EEPROM_SIZE 256
#define SYS_LED_REG 0x8
#define FAN12_LED_REG 0x9
#define FAN34_LED_REG 0xA
#define FAN56_LED_REG 0xB
#define SYS_RESET1_REG 0x2
#define SYS_LOCATOR_LED_BITS 0x01
#define SYS_PWR_LED_BITS 0x0E
#define SYS_STATUS_LED_BITS 0x70
#define FAN135_LED_BITS 0x07
#define FAN246_LED_BITS 0x38
extern int alpha_i2c_cpld_read(unsigned short cpld_addr, u8 reg);
extern int alpha_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
static ssize_t onie_read(struct device *dev, struct device_attribute *attr, char *buf);
static ssize_t onie_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static LIST_HEAD(cpld_client_list);
static struct mutex list_lock;
struct cpld_client_node {
struct i2c_client *client;
struct list_head list;
};
/* Addresses scanned for alphanetworks_snh60a0_320fv2_onie_eeprom */
static const unsigned short normal_i2c[] = { 0x56, I2C_CLIENT_END };
enum sysfs_onie_attributes {
ONIE_RW,
};
static SENSOR_DEVICE_ATTR(eeprom, (0660), onie_read, onie_write, ONIE_RW);
static struct attribute *alphanetworks_snh60a0_320fv2_onie_attributes[] = {
&sensor_dev_attr_eeprom.dev_attr.attr,
NULL
};
static const struct attribute_group alphanetworks_snh60a0_320fv2_onie_group = {
.attrs = alphanetworks_snh60a0_320fv2_onie_attributes,
};
static ssize_t onie_read(struct device *dev, struct device_attribute *attr, char *buf)
{
int val = 0, res = 0;
u8 command;
struct i2c_client *client = to_i2c_client(dev);
__u8 read_write;
unsigned short offset = 0;
union i2c_smbus_data temp;
char rbuf[EEPROM_SIZE];
for( offset=0 ; offset < EEPROM_SIZE ; ++offset )
{
read_write = I2C_SMBUS_WRITE;
offset = offset & 0x3fff;
temp.byte = (u8)offset;
res = i2c_smbus_xfer(client->adapter, client->addr, client->flags=0,
read_write, 0, 2, &temp);
res = i2c_smbus_xfer(client->adapter, client->addr, client->flags=0,
read_write, 0, 2, &temp);
read_write = I2C_SMBUS_READ;
temp.byte = 0xaa;
res = i2c_smbus_xfer(client->adapter, client->addr, client->flags=0,
read_write, 0, 1, &temp);
if (!res)
{
res = temp.byte;
rbuf[offset] = (char)temp.byte;
}
read_write = I2C_SMBUS_READ;
temp.byte = 0xbb;
res = i2c_smbus_xfer(client->adapter, client->addr, client->flags=0,
read_write, 0, 1, &temp);
if (!res)
{
res = temp.byte;
}
}
memcpy(buf, rbuf, EEPROM_SIZE);
return EEPROM_SIZE;
}
static ssize_t onie_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
int error, write, command, read;
error = kstrtoint(buf, 10, &write);
if (error)
return error;
if (write < 0 || write > 255)
return -EINVAL;
/* Not support yet */
return count;
}
static void alpha_i2c_cpld_add_client(struct i2c_client *client)
{
struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL);
if (!node) {
dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr);
return;
}
node->client = client;
mutex_lock(&list_lock);
list_add(&node->list, &cpld_client_list);
mutex_unlock(&list_lock);
}
static void alpha_i2c_cpld_remove_client(struct i2c_client *client)
{
struct list_head *list_node = NULL;
struct cpld_client_node *cpld_node = NULL;
int found = 0;
mutex_lock(&list_lock);
list_for_each(list_node, &cpld_client_list)
{
cpld_node = list_entry(list_node, struct cpld_client_node, list);
if (cpld_node->client == client) {
found = 1;
break;
}
}
if (found) {
list_del(list_node);
kfree(cpld_node);
}
mutex_unlock(&list_lock);
}
static int onie_eeprom_probe(struct i2c_client *client,
const struct i2c_device_id *dev_id)
{
int status;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
dev_dbg(&client->dev, "i2c_check_functionality failed (0x%x)\n", client->addr);
status = -EIO;
goto exit;
}
status = sysfs_create_group(&client->dev.kobj, &alphanetworks_snh60a0_320fv2_onie_group);
if (status) {
goto exit;
}
dev_info(&client->dev, "chip found\n");
alpha_i2c_cpld_add_client(client);
return 0;
exit:
return status;
}
static int onie_eeprom_remove(struct i2c_client *client)
{
sysfs_remove_group(&client->dev.kobj, &alphanetworks_snh60a0_320fv2_onie_group);
alpha_i2c_cpld_remove_client(client);
return 0;
}
static const struct i2c_device_id onie_eeprom_id[] = {
{ "snh60a0_onie_eeprom", 0 },
{}
};
MODULE_DEVICE_TABLE(i2c, onie_eeprom_id);
static struct i2c_driver onie_eeprom_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = "snh60a0_onie_eeprom",
},
.probe = onie_eeprom_probe,
.remove = onie_eeprom_remove,
.id_table = onie_eeprom_id,
.address_list = normal_i2c,
};
static int __init onie_eeprom_init(void)
{
mutex_init(&list_lock);
return i2c_add_driver(&onie_eeprom_driver);
}
static void __exit onie_eeprom_exit(void)
{
i2c_del_driver(&onie_eeprom_driver);
}
MODULE_AUTHOR("Alpha-SID6");
MODULE_DESCRIPTION("onie eeprom driver");
MODULE_LICENSE("GPL");
module_init(onie_eeprom_init);
module_exit(onie_eeprom_exit);

View File

@ -0,0 +1,507 @@
/*
* A hwmon driver for the alphanetworks_snh60a0_320fv2_power_cpld
*
* Copyright (C) 2018 Alphanetworks Technology Corporation.
* Robin Chen <Robin_chen@Alphanetworks.com>
* 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
* 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.
* see <http://www.gnu.org/licenses/>
*
* 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/i2c.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/dmi.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/mutex.h>
#define DRIVER_NAME "snh60a0_power_cpld"
#define PSU1_STATUS_REG 0x3
#define PSU2_STATUS_REG 0x4
#define FAN_PWM_REG 0x23
#define PSU_PRESENT_BIT 0x4
#define PSU_POWER_BIT 0x2
#define FAN_PRESENT_BIT 0x2
static ssize_t psu_show_status(struct device *dev, struct device_attribute *attr, char *buf);
static ssize_t fan_pwm_show(struct device *dev, struct device_attribute *attr, char *buf);
static ssize_t set_fan_pwm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static ssize_t fan_show_status(struct device *dev, struct device_attribute *attr, char *buf);
static LIST_HEAD(cpld_client_list);
static struct mutex list_lock;
struct cpld_client_node {
struct i2c_client *client;
struct list_head list;
};
/* Addresses scanned for alphanetworks_snh60a0_320fv2_power_cpld */
static const unsigned short normal_i2c[] = { 0x5E, I2C_CLIENT_END };
struct alphanetworks_snh60a0_320fv2_pwr_cpld_data {
struct device *hwmon_dev;
struct mutex update_lock;
char model_name[9]; /* Model name, read from eeprom */
};
enum sysfs_psu_attributes {
PSU1_PRESENT,
PSU2_PRESENT,
PSU1_POWER_GOOD,
PSU2_POWER_GOOD,
FAN_PWM,
FAN1_FAULT,
FAN2_FAULT,
FAN3_FAULT,
FAN4_FAULT,
FAN5_FAULT,
FAN6_FAULT,
FAN1_PRESENT=0x10,
FAN2_PRESENT,
FAN3_PRESENT,
FAN4_PRESENT,
FAN5_PRESENT,
FAN6_PRESENT,
FAN1_FRONT_SPEED_RPM,
FAN1_REAR_SPEED_RPM,
FAN2_FRONT_SPEED_RPM,
FAN2_REAR_SPEED_RPM,
FAN3_FRONT_SPEED_RPM,
FAN3_REAR_SPEED_RPM,
FAN4_FRONT_SPEED_RPM,
FAN4_REAR_SPEED_RPM,
FAN5_FRONT_SPEED_RPM,
FAN5_REAR_SPEED_RPM,
FAN6_FRONT_SPEED_RPM,
FAN6_REAR_SPEED_RPM,
};
static SENSOR_DEVICE_ATTR(psu1_present, S_IRUGO, psu_show_status, NULL, PSU1_PRESENT);
static SENSOR_DEVICE_ATTR(psu2_present, S_IRUGO, psu_show_status, NULL, PSU2_PRESENT);
static SENSOR_DEVICE_ATTR(psu1_power_good, S_IRUGO, psu_show_status, NULL, PSU1_POWER_GOOD);
static SENSOR_DEVICE_ATTR(psu2_power_good, S_IRUGO, psu_show_status, NULL, PSU2_POWER_GOOD);
static SENSOR_DEVICE_ATTR(fan_pwm, (0660), fan_pwm_show, set_fan_pwm, FAN_PWM);
static SENSOR_DEVICE_ATTR(fan1_present, S_IRUGO, fan_show_status, NULL, FAN1_PRESENT);
static SENSOR_DEVICE_ATTR(fan2_present, S_IRUGO, fan_show_status, NULL, FAN2_PRESENT);
static SENSOR_DEVICE_ATTR(fan3_present, S_IRUGO, fan_show_status, NULL, FAN3_PRESENT);
static SENSOR_DEVICE_ATTR(fan4_present, S_IRUGO, fan_show_status, NULL, FAN4_PRESENT);
static SENSOR_DEVICE_ATTR(fan5_present, S_IRUGO, fan_show_status, NULL, FAN5_PRESENT);
static SENSOR_DEVICE_ATTR(fan6_present, S_IRUGO, fan_show_status, NULL, FAN6_PRESENT);
static SENSOR_DEVICE_ATTR(fan1_front_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN1_FRONT_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan2_front_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN2_FRONT_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan3_front_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN3_FRONT_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan4_front_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN4_FRONT_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan5_front_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN5_FRONT_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan6_front_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN6_FRONT_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan1_rear_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN1_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan2_rear_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN2_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan3_rear_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN3_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan4_rear_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN4_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan5_rear_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN5_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan6_rear_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN6_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan1_fault, S_IRUGO, fan_show_status, NULL, FAN1_FAULT); static SENSOR_DEVICE_ATTR(fan11_fault, S_IRUGO, fan_show_status, NULL, FAN1_FAULT);
static SENSOR_DEVICE_ATTR(fan2_fault, S_IRUGO, fan_show_status, NULL, FAN2_FAULT); static SENSOR_DEVICE_ATTR(fan12_fault, S_IRUGO, fan_show_status, NULL, FAN2_FAULT);
static SENSOR_DEVICE_ATTR(fan3_fault, S_IRUGO, fan_show_status, NULL, FAN3_FAULT); static SENSOR_DEVICE_ATTR(fan13_fault, S_IRUGO, fan_show_status, NULL, FAN3_FAULT);
static SENSOR_DEVICE_ATTR(fan4_fault, S_IRUGO, fan_show_status, NULL, FAN4_FAULT); static SENSOR_DEVICE_ATTR(fan14_fault, S_IRUGO, fan_show_status, NULL, FAN4_FAULT);
static SENSOR_DEVICE_ATTR(fan5_fault, S_IRUGO, fan_show_status, NULL, FAN5_FAULT); static SENSOR_DEVICE_ATTR(fan15_fault, S_IRUGO, fan_show_status, NULL, FAN5_FAULT);
static SENSOR_DEVICE_ATTR(fan6_fault, S_IRUGO, fan_show_status, NULL, FAN6_FAULT); static SENSOR_DEVICE_ATTR(fan16_fault, S_IRUGO, fan_show_status, NULL, FAN6_FAULT);
static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, fan_show_status, NULL, FAN1_FRONT_SPEED_RPM); static SENSOR_DEVICE_ATTR(fan11_input, S_IRUGO, fan_show_status, NULL, FAN1_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, fan_show_status, NULL, FAN2_FRONT_SPEED_RPM); static SENSOR_DEVICE_ATTR(fan12_input, S_IRUGO, fan_show_status, NULL, FAN2_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, fan_show_status, NULL, FAN3_FRONT_SPEED_RPM); static SENSOR_DEVICE_ATTR(fan13_input, S_IRUGO, fan_show_status, NULL, FAN3_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, fan_show_status, NULL, FAN4_FRONT_SPEED_RPM); static SENSOR_DEVICE_ATTR(fan14_input, S_IRUGO, fan_show_status, NULL, FAN4_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, fan_show_status, NULL, FAN5_FRONT_SPEED_RPM); static SENSOR_DEVICE_ATTR(fan15_input, S_IRUGO, fan_show_status, NULL, FAN5_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, fan_show_status, NULL, FAN6_FRONT_SPEED_RPM); static SENSOR_DEVICE_ATTR(fan16_input, S_IRUGO, fan_show_status, NULL, FAN6_REAR_SPEED_RPM);
static struct attribute *alphanetworks_snh60a0_320fv2_psu_attributes[] = {
&sensor_dev_attr_psu1_present.dev_attr.attr,
&sensor_dev_attr_psu2_present.dev_attr.attr,
&sensor_dev_attr_psu1_power_good.dev_attr.attr,
&sensor_dev_attr_psu2_power_good.dev_attr.attr,
&sensor_dev_attr_fan_pwm.dev_attr.attr,
&sensor_dev_attr_fan1_present.dev_attr.attr,
&sensor_dev_attr_fan2_present.dev_attr.attr,
&sensor_dev_attr_fan3_present.dev_attr.attr,
&sensor_dev_attr_fan4_present.dev_attr.attr,
&sensor_dev_attr_fan5_present.dev_attr.attr,
&sensor_dev_attr_fan6_present.dev_attr.attr,
&sensor_dev_attr_fan1_front_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan2_front_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan3_front_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan4_front_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan5_front_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan6_front_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan1_rear_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan2_rear_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan3_rear_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan4_rear_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan5_rear_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan6_rear_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan1_fault.dev_attr.attr, &sensor_dev_attr_fan11_fault.dev_attr.attr,
&sensor_dev_attr_fan2_fault.dev_attr.attr, &sensor_dev_attr_fan12_fault.dev_attr.attr,
&sensor_dev_attr_fan3_fault.dev_attr.attr, &sensor_dev_attr_fan13_fault.dev_attr.attr,
&sensor_dev_attr_fan4_fault.dev_attr.attr, &sensor_dev_attr_fan14_fault.dev_attr.attr,
&sensor_dev_attr_fan5_fault.dev_attr.attr, &sensor_dev_attr_fan15_fault.dev_attr.attr,
&sensor_dev_attr_fan6_fault.dev_attr.attr, &sensor_dev_attr_fan16_fault.dev_attr.attr,
&sensor_dev_attr_fan1_input.dev_attr.attr, &sensor_dev_attr_fan11_input.dev_attr.attr,
&sensor_dev_attr_fan2_input.dev_attr.attr, &sensor_dev_attr_fan12_input.dev_attr.attr,
&sensor_dev_attr_fan3_input.dev_attr.attr, &sensor_dev_attr_fan13_input.dev_attr.attr,
&sensor_dev_attr_fan4_input.dev_attr.attr, &sensor_dev_attr_fan14_input.dev_attr.attr,
&sensor_dev_attr_fan5_input.dev_attr.attr, &sensor_dev_attr_fan15_input.dev_attr.attr,
&sensor_dev_attr_fan6_input.dev_attr.attr, &sensor_dev_attr_fan16_input.dev_attr.attr,
NULL
};
static const struct attribute_group alphanetworks_snh60a0_320fv2_psu_group = {
.attrs = alphanetworks_snh60a0_320fv2_psu_attributes,
};
static ssize_t psu_show_status(struct device *dev, struct device_attribute *attr, char *buf)
{
int val = 0, res = 0;
u8 command;
struct i2c_client *client = to_i2c_client(dev);
struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
switch(sda->index) {
case PSU1_PRESENT:
case PSU1_POWER_GOOD:
command = PSU1_STATUS_REG;
break;
case PSU2_PRESENT:
case PSU2_POWER_GOOD:
command = PSU2_STATUS_REG;
break;
}
val = i2c_smbus_read_byte_data(client, command);
if (val < 0) {
dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val);
}
switch(sda->index) {
case PSU1_PRESENT:
case PSU2_PRESENT:
res = (val & PSU_PRESENT_BIT ? 1 : 0 );
break;
case PSU1_POWER_GOOD:
case PSU2_POWER_GOOD:
res = (val & PSU_POWER_BIT ? 1 : 0 );
break;
}
return sprintf(buf, "%d\n", res);
}
static ssize_t fan_pwm_show(struct device *dev, struct device_attribute *attr, char *buf)
{
int val = 0;
struct i2c_client *client = to_i2c_client(dev);
val = i2c_smbus_read_byte_data(client, FAN_PWM_REG);
if (val < 0) {
dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val);
}
return sprintf(buf, "%d", val);
}
static ssize_t set_fan_pwm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
int error, value;
error = kstrtoint(buf, 10, &value);
if (error)
return error;
if (value < 0 || value > 0xFF)
return -EINVAL;
i2c_smbus_write_byte_data(client, FAN_PWM_REG, value);
return count;
}
static ssize_t fan_show_status(struct device *dev, struct device_attribute *attr, char *buf)
{
struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
struct i2c_client *client = to_i2c_client(dev);
// struct as7712_32x_fan_data *data = as7712_32x_fan_update_device(dev);
ssize_t ret = 0;
int val, val2;
switch (sda->index) {
/* case FAN_DUTY_CYCLE_PERCENTAGE: */
/* { */
/* u32 duty_cycle = reg_val_to_duty_cycle(data->reg_val[FAN_DUTY_CYCLE_PERCENTAGE]); */
/* ret = sprintf(buf, "%u\n", duty_cycle); */
/* break; */
/* } */
case FAN1_FRONT_SPEED_RPM:
case FAN2_FRONT_SPEED_RPM:
case FAN3_FRONT_SPEED_RPM:
case FAN4_FRONT_SPEED_RPM:
case FAN5_FRONT_SPEED_RPM:
case FAN6_FRONT_SPEED_RPM:
case FAN1_REAR_SPEED_RPM:
case FAN2_REAR_SPEED_RPM:
case FAN3_REAR_SPEED_RPM:
case FAN4_REAR_SPEED_RPM:
case FAN5_REAR_SPEED_RPM:
case FAN6_REAR_SPEED_RPM:
val = i2c_smbus_read_byte_data(client, sda->index);
ret = sprintf(buf, "%d\n", val * 150);
break;
case FAN1_PRESENT:
case FAN2_PRESENT:
case FAN3_PRESENT:
case FAN4_PRESENT:
case FAN5_PRESENT:
case FAN6_PRESENT:
val = i2c_smbus_read_byte_data(client, sda->index);
ret = sprintf(buf, "%d\n", (val & FAN_PRESENT_BIT) ? 1 : 0);
break;
case FAN1_FAULT:
case FAN2_FAULT:
case FAN3_FAULT:
case FAN4_FAULT:
case FAN5_FAULT:
case FAN6_FAULT:
val = i2c_smbus_read_byte_data(client, (sda->index - FAN1_FAULT)*2 + FAN1_FRONT_SPEED_RPM);
val2 = i2c_smbus_read_byte_data(client, (sda->index - FAN1_FAULT)*2 + FAN1_REAR_SPEED_RPM);
ret = sprintf(buf, "%d\n", (val|val2) ? 0 : 1);
break;
default:
break;
}
return ret;
}
static void alpha_i2c_cpld_add_client(struct i2c_client *client)
{
struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL);
if (!node) {
dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr);
return;
}
node->client = client;
mutex_lock(&list_lock);
list_add(&node->list, &cpld_client_list);
mutex_unlock(&list_lock);
}
static void alpha_i2c_cpld_remove_client(struct i2c_client *client)
{
struct list_head *list_node = NULL;
struct cpld_client_node *cpld_node = NULL;
int found = 0;
mutex_lock(&list_lock);
list_for_each(list_node, &cpld_client_list)
{
cpld_node = list_entry(list_node, struct cpld_client_node, list);
if (cpld_node->client == client) {
found = 1;
break;
}
}
if (found) {
list_del(list_node);
kfree(cpld_node);
}
mutex_unlock(&list_lock);
}
static int alpha_i2c_cpld_probe(struct i2c_client *client,
const struct i2c_device_id *dev_id)
{
int status;
struct alphanetworks_snh60a0_320fv2_pwr_cpld_data* data;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
dev_dbg(&client->dev, "i2c_check_functionality failed (0x%x)\n", client->addr);
status = -EIO;
goto exit;
}
data = kzalloc(sizeof(struct alphanetworks_snh60a0_320fv2_pwr_cpld_data), GFP_KERNEL);
if (!data) {
status = -ENOMEM;
goto exit;
}
status = sysfs_create_group(&client->dev.kobj, &alphanetworks_snh60a0_320fv2_psu_group);
if (status) {
goto exit;
}
dev_info(&client->dev, "chip found\n");
alpha_i2c_cpld_add_client(client);
data->hwmon_dev = hwmon_device_register(&client->dev);
if (IS_ERR(data->hwmon_dev)) {
status = PTR_ERR(data->hwmon_dev);
goto exit;
}
dev_info(&client->dev, "%s: pwr_cpld '%s'\n",
dev_name(data->hwmon_dev), client->name);
return 0;
exit:
return status;
}
static int alpha_i2c_cpld_remove(struct i2c_client *client)
{
struct alphanetworks_snh60a0_320fv2_pwr_cpld_data *data = i2c_get_clientdata(client);
sysfs_remove_group(&client->dev.kobj, &alphanetworks_snh60a0_320fv2_psu_group);
alpha_i2c_cpld_remove_client(client);
kfree(data);
return 0;
}
static const struct i2c_device_id alpha_i2c_cpld_id[] = {
{ DRIVER_NAME, 0 },
{}
};
MODULE_DEVICE_TABLE(i2c, alpha_i2c_cpld_id);
static struct i2c_driver alpha_i2c_cpld_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = DRIVER_NAME,
},
.probe = alpha_i2c_cpld_probe,
.remove = alpha_i2c_cpld_remove,
.id_table = alpha_i2c_cpld_id,
.address_list = normal_i2c,
};
int alpha_i2c_cpld_read(unsigned short cpld_addr, u8 reg)
{
struct list_head *list_node = NULL;
struct cpld_client_node *cpld_node = NULL;
int ret = -EPERM;
mutex_lock(&list_lock);
list_for_each(list_node, &cpld_client_list)
{
cpld_node = list_entry(list_node, struct cpld_client_node, list);
if (cpld_node->client->addr == cpld_addr) {
ret = i2c_smbus_read_byte_data(cpld_node->client, reg);
break;
}
}
mutex_unlock(&list_lock);
return ret;
}
EXPORT_SYMBOL(alpha_i2c_cpld_read);
int alpha_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value)
{
struct list_head *list_node = NULL;
struct cpld_client_node *cpld_node = NULL;
int ret = -EIO;
mutex_lock(&list_lock);
list_for_each(list_node, &cpld_client_list)
{
cpld_node = list_entry(list_node, struct cpld_client_node, list);
if (cpld_node->client->addr == cpld_addr) {
ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value);
break;
}
}
mutex_unlock(&list_lock);
return ret;
}
EXPORT_SYMBOL(alpha_i2c_cpld_write);
static int __init alpha_i2c_cpld_init(void)
{
mutex_init(&list_lock);
return i2c_add_driver(&alpha_i2c_cpld_driver);
}
static void __exit alpha_i2c_cpld_exit(void)
{
i2c_del_driver(&alpha_i2c_cpld_driver);
}
static struct dmi_system_id alphanetworks_snh60a0_320fv2_dmi_table[] = {
{
.ident = "Alpha Zion",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Alpha"),
DMI_MATCH(DMI_PRODUCT_NAME, "Zion"),
},
}
};
int platform_alphanetworks_snh60a0_320fv2(void)
{
return dmi_check_system(alphanetworks_snh60a0_320fv2_dmi_table);
}
EXPORT_SYMBOL(platform_alphanetworks_snh60a0_320fv2);
MODULE_AUTHOR("Alpha-SID6");
MODULE_DESCRIPTION("alpha_power_cpld driver");
MODULE_LICENSE("GPL");
module_init(alpha_i2c_cpld_init);
module_exit(alpha_i2c_cpld_exit);

View File

@ -0,0 +1,380 @@
/*
* A hwmon driver for the alphanetworks_snh60a0_320fv2_system_cpld
*
* Copyright (C) 2018 Alphanetworks Technology Corporation.
* Robin Chen <Robin_chen@Alphanetworks.com>
* 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
* 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.
* see <http://www.gnu.org/licenses/>
*
* 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/i2c.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/dmi.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/mutex.h>
#define SYS_LED_REG 0x8
#define FAN12_LED_REG 0x9
#define FAN34_LED_REG 0xA
#define FAN56_LED_REG 0xB
#define SYS_RESET1_REG 0x2
#define SWI_CTRL_REG 0x4
#define SYS_LOCATOR_LED_BITS 0x01
#define SYS_PWR_LED_BITS 0x0E
#define SYS_STATUS_LED_BITS 0x70
#define FAN135_LED_BITS 0x07
#define FAN246_LED_BITS 0x38
#define REST_BUTTON_BITS 0x0
extern int alpha_i2c_cpld_read(unsigned short cpld_addr, u8 reg);
extern int alpha_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
static ssize_t sys_led_read(struct device *dev, struct device_attribute *attr, char *buf);
static ssize_t sys_led_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static LIST_HEAD(cpld_client_list);
static struct mutex list_lock;
struct cpld_client_node {
struct i2c_client *client;
struct list_head list;
};
/* Addresses scanned for alphanetworks_snh60a0_320fv2_system_cpld */
static const unsigned short normal_i2c[] = { 0x5F, I2C_CLIENT_END };
enum sysfs_sys_attributes {
SYS_LOCATOR,
SYS_PWR,
SYS_STATUS,
FAN1_LED,
FAN2_LED,
FAN3_LED,
FAN4_LED,
FAN5_LED,
FAN6_LED,
SYS_REST1,
SWI_CTRL,
};
static SENSOR_DEVICE_ATTR(sys_locator, (0660), sys_led_read, sys_led_write, SYS_LOCATOR);
static SENSOR_DEVICE_ATTR(sys_pwr, (0660), sys_led_read, sys_led_write, SYS_PWR);
static SENSOR_DEVICE_ATTR(sys_status, (0600), sys_led_read, sys_led_write, SYS_STATUS);
static SENSOR_DEVICE_ATTR(fan1_led, (0660), sys_led_read, sys_led_write, FAN1_LED);
static SENSOR_DEVICE_ATTR(fan2_led, (0660), sys_led_read, sys_led_write, FAN2_LED);
static SENSOR_DEVICE_ATTR(fan3_led, (0660), sys_led_read, sys_led_write, FAN3_LED);
static SENSOR_DEVICE_ATTR(fan4_led, (0660), sys_led_read, sys_led_write, FAN4_LED);
static SENSOR_DEVICE_ATTR(fan5_led, (0660), sys_led_read, sys_led_write, FAN5_LED);
static SENSOR_DEVICE_ATTR(fan6_led, (0660), sys_led_read, sys_led_write, FAN6_LED);
static SENSOR_DEVICE_ATTR(sys_reset1, (0660), sys_led_read, sys_led_write, SYS_REST1);
static SENSOR_DEVICE_ATTR(swi_ctrl, (0660), sys_led_read, NULL, SWI_CTRL);
static struct attribute *alphanetworks_snh60a0_320fv2_sys_attributes[] = {
&sensor_dev_attr_sys_locator.dev_attr.attr,
&sensor_dev_attr_sys_pwr.dev_attr.attr,
&sensor_dev_attr_sys_status.dev_attr.attr,
&sensor_dev_attr_fan1_led.dev_attr.attr,
&sensor_dev_attr_fan2_led.dev_attr.attr,
&sensor_dev_attr_fan3_led.dev_attr.attr,
&sensor_dev_attr_fan4_led.dev_attr.attr,
&sensor_dev_attr_fan5_led.dev_attr.attr,
&sensor_dev_attr_fan6_led.dev_attr.attr,
&sensor_dev_attr_sys_reset1.dev_attr.attr,
&sensor_dev_attr_swi_ctrl.dev_attr.attr,
NULL
};
static const struct attribute_group alphanetworks_snh60a0_320fv2_sys_group = {
.attrs = alphanetworks_snh60a0_320fv2_sys_attributes,
};
static ssize_t sys_led_read(struct device *dev, struct device_attribute *attr, char *buf)
{
int val = 0, res = 0;
u8 command;
struct i2c_client *client = to_i2c_client(dev);
struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
switch(sda->index) {
case SYS_LOCATOR:
case SYS_PWR:
case SYS_STATUS:
command = SYS_LED_REG;
break;
case FAN1_LED:
case FAN2_LED:
case FAN3_LED:
case FAN4_LED:
case FAN5_LED:
case FAN6_LED:
command = FAN12_LED_REG + (sda->index - FAN1_LED)/2;
break;
case SYS_REST1:
command = SYS_RESET1_REG;
break;
case SWI_CTRL:
command = SWI_CTRL_REG;
break;
}
val = i2c_smbus_read_byte_data(client, command);
if (val < 0) {
dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val);
}
switch(sda->index) {
case SYS_LOCATOR:
res = (val & SYS_LOCATOR_LED_BITS) >> 0;
break;
case SYS_PWR:
res = (val & SYS_PWR_LED_BITS) >> 1;
break;
case SYS_STATUS:
res = (val & SYS_STATUS_LED_BITS) >> 4;
break;
case FAN1_LED:
case FAN3_LED:
case FAN5_LED:
res = (val & FAN135_LED_BITS) >> 0;
break;
case FAN2_LED:
case FAN4_LED:
case FAN6_LED:
res = (val & FAN246_LED_BITS) >> 3;
break;
case SYS_REST1:
res = val;
break;
case SWI_CTRL:
res = (val & REST_BUTTON_BITS) >> 0;
break;
}
return sprintf(buf, "%d\n", res);
}
static ssize_t sys_led_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
int error, write, command, read;
error = kstrtoint(buf, 10, &write);
if (error)
return error;
switch(sda->index) {
case SYS_LOCATOR:
if(write < 0 || write > 2)
return -EINVAL;
case SYS_PWR:
case SYS_STATUS:
if (write < 0 || write > 7)
return -EINVAL;
command = SYS_LED_REG;
break;
case FAN1_LED:
case FAN2_LED:
case FAN3_LED:
case FAN4_LED:
case FAN5_LED:
case FAN6_LED:
if (write < 0 || write > 7)
return -EINVAL;
command = FAN12_LED_REG + (sda->index - FAN1_LED)/2;
break;
case SYS_REST1:
if (write < 0 || write > 15)
return -EINVAL;
command = SYS_RESET1_REG;
break;
}
read = i2c_smbus_read_byte_data(client, command);
if (read < 0) {
dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, read);
}
switch(sda->index) {
case SYS_LOCATOR:
read &= ~SYS_LOCATOR_LED_BITS;
read |= write << 0;
break;
case SYS_PWR:
read &= ~SYS_PWR_LED_BITS;
read |= write << 1;
break;
case SYS_STATUS:
read &= ~SYS_STATUS_LED_BITS;
read |= write << 4;
break;
case FAN1_LED:
case FAN3_LED:
case FAN5_LED:
read &= ~FAN135_LED_BITS;
read |= write << 0;
break;
case FAN2_LED:
case FAN4_LED:
case FAN6_LED:
read &= ~FAN246_LED_BITS;
read |= write << 3;
break;
case SYS_REST1:
read = write;
break;
}
i2c_smbus_write_byte_data(client, command, read);
return count;
}
static void alpha_i2c_cpld_add_client(struct i2c_client *client)
{
struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL);
if (!node) {
dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr);
return;
}
node->client = client;
mutex_lock(&list_lock);
list_add(&node->list, &cpld_client_list);
mutex_unlock(&list_lock);
}
static void alpha_i2c_cpld_remove_client(struct i2c_client *client)
{
struct list_head *list_node = NULL;
struct cpld_client_node *cpld_node = NULL;
int found = 0;
mutex_lock(&list_lock);
list_for_each(list_node, &cpld_client_list)
{
cpld_node = list_entry(list_node, struct cpld_client_node, list);
if (cpld_node->client == client) {
found = 1;
break;
}
}
if (found) {
list_del(list_node);
kfree(cpld_node);
}
mutex_unlock(&list_lock);
}
static int alpha_i2c_cpld_probe(struct i2c_client *client,
const struct i2c_device_id *dev_id)
{
int status;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
dev_dbg(&client->dev, "i2c_check_functionality failed (0x%x)\n", client->addr);
status = -EIO;
goto exit;
}
status = sysfs_create_group(&client->dev.kobj, &alphanetworks_snh60a0_320fv2_sys_group);
if (status) {
goto exit;
}
dev_info(&client->dev, "chip found\n");
alpha_i2c_cpld_add_client(client);
return 0;
exit:
return status;
}
static int alpha_i2c_cpld_remove(struct i2c_client *client)
{
sysfs_remove_group(&client->dev.kobj, &alphanetworks_snh60a0_320fv2_sys_group);
alpha_i2c_cpld_remove_client(client);
return 0;
}
static const struct i2c_device_id alpha_i2c_cpld_id[] = {
{ "snh60a0_system_cpld", 0 },
{}
};
MODULE_DEVICE_TABLE(i2c, alpha_i2c_cpld_id);
static struct i2c_driver alpha_i2c_cpld_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = "snh60a0_system_cpld",
},
.probe = alpha_i2c_cpld_probe,
.remove = alpha_i2c_cpld_remove,
.id_table = alpha_i2c_cpld_id,
.address_list = normal_i2c,
};
static int __init alpha_i2c_cpld_init(void)
{
mutex_init(&list_lock);
return i2c_add_driver(&alpha_i2c_cpld_driver);
}
static void __exit alpha_i2c_cpld_exit(void)
{
i2c_del_driver(&alpha_i2c_cpld_driver);
}
MODULE_AUTHOR("Alpha-SID6");
MODULE_DESCRIPTION("alpha_system_cpld driver");
MODULE_LICENSE("GPL");
module_init(alpha_i2c_cpld_init);
module_exit(alpha_i2c_cpld_exit);

View File

@ -0,0 +1,13 @@
[Unit]
Description=Alphanetworks SNH60A0-320F Platform initialization service
Before=pmon.service
DefaultDependencies=no
[Service]
Type=oneshot
ExecStart=/usr/local/bin/alphanetworks_snh60a0_util.py install
ExecStop=/usr/local/bin/alphanetworks_snh60a0_util.py clean
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,16 @@
#!/usr/bin/env python
import os
import sys
from setuptools import setup
os.listdir
setup(
name='snh60a0_320fv2',
version='1.0',
description='Module to initialize Alphanetworks SNH60A0-320FV2 platforms',
packages=['snh60a0_320fv2'],
package_dir={'snh60a0_320fv2': 'snh60a0-320fv2/classes'},
)

View File

@ -0,0 +1,399 @@
#!/usr/bin/env python
#
# Copyright (C) 2018 Alphanetworks Technology Corporation.
# Robin Chen <Robin_chen@Alphanetworks.com>
# 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
# 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.
# see <http://www.gnu.org/licenses/>
#
# 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
"""
import os
import commands
import sys, getopt
import logging
import re
import time
from collections import namedtuple
PROJECT_NAME = 'snh60a0-320fv2'
device_path = "x86_64-alphanetworks_snh60a0_320fv2-r0"
version = '0.1.0'
verbose = False
DEBUG = False
args = []
FORCE = 0
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:
logging.info('no option')
for arg in args:
if arg == 'install':
do_install()
elif arg == 'clean':
do_uninstall()
else:
show_help()
return 0
def show_help():
print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]}
sys.exit(0)
def show_log(txt):
if DEBUG == True:
print PROJECT_NAME.upper()+": "+txt
return
def log_os_system(cmd, show):
logging.info('Run :'+cmd)
status, output = commands.getstatusoutput(cmd)
show_log (cmd +" with result: " + str(status))
show_log (" output:"+output)
if status:
logging.info('Failed :'+cmd)
if show:
print('Failed :'+cmd)
return status, output
def driver_check():
ret, lsmod = log_os_system("lsmod | grep alphanetworks", 0)
logging.info('mods:'+lsmod)
if len(lsmod) ==0:
return False
return True
kos = [
'modprobe i2c_dev',
'modprobe i2c_mux_pca954x',
'modprobe optoe' ,
'modprobe snh60a0_power_cpld' ,
'modprobe snh60a0_system_cpld' ,
'modprobe snh60a0_onie_eeprom' ,
'modprobe alphanetworks_snh60a0_320fv2_sfp' ]
def driver_install():
global FORCE
status, output = log_os_system("depmod", 1)
for i in range(0,len(kos)):
if kos[i].find('pca954') != -1:
status, output = log_os_system(kos[i]+ " force_deselect_on_exit=1", 1)
else:
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")
rm = rm.replace("insmod", "rmmod")
status, output = log_os_system(rm, 1)
if status:
if FORCE == 0:
return status
return 0
i2c_prefix = '/sys/bus/i2c/devices/'
sfp_map = [14,15,16,17]
mknod =[
'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo pca9545 0x71 > /sys/bus/i2c/devices/i2c-6/new_device',
'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-8/new_device',
'echo pca9545 0x71 > /sys/bus/i2c/devices/i2c-7/new_device',
'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-21/new_device',
'echo 24c02 0x51 > /sys/bus/i2c/devices/i2c-11/new_device',
'echo 24c02 0x51 > /sys/bus/i2c/devices/i2c-12/new_device',
'echo snh60a0_onie_eeprom 0x56 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo snh60a0_power_cpld 0x5e > /sys/bus/i2c/devices/i2c-0/new_device',
'echo snh60a0_system_cpld 0x5f > /sys/bus/i2c/devices/i2c-9/new_device',
'echo lm75 0x4D > /sys/bus/i2c/devices/i2c-4/new_device',
'echo lm75 0x4C > /sys/bus/i2c/devices/i2c-5/new_device',
'echo lm75 0x4F > /sys/bus/i2c/devices/i2c-0/new_device' ]
mknod2 =[
'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo pca9545 0x71 > /sys/bus/i2c/devices/i2c-6/new_device',
'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-8/new_device',
'echo pca9545 0x71 > /sys/bus/i2c/devices/i2c-7/new_device',
'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-21/new_device',
'echo 24c02 0x51 > /sys/bus/i2c/devices/i2c-11/new_device',
'echo 24c02 0x51 > /sys/bus/i2c/devices/i2c-12/new_device',
'echo snh60a0_onie_eeprom 0x56 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo snh60a0_power_cpld 0x5e > /sys/bus/i2c/devices/i2c-1/new_device',
'echo snh60a0_system_cpld 0x5f > /sys/bus/i2c/devices/i2c-9/new_device',
'echo lm75 0x4D > /sys/bus/i2c/devices/i2c-4/new_device',
'echo lm75 0x4C > /sys/bus/i2c/devices/i2c-5/new_device',
'echo lm75 0x4F > /sys/bus/i2c/devices/i2c-1/new_device' ]
def i2c_order_check():
# i2c bus 0 and 1 might be installed in different order.
# Here check if 0x76 is exist @ i2c-0
status, output = log_os_system("i2cdetect -l | grep I801 | grep i2c-0", 0)
if not output:
order = 1
else:
order = 0
if not device_exist():
#order = 1
tmp = "sed -i 's/0-/1-/g' /usr/share/sonic/device/"+device_path+"/fancontrol"
status, output = log_os_system(tmp, 0)
tmp = "sed -i 's/0-/1-/g' /usr/share/sonic/device/"+device_path+"/plugins/led_control.py"
status, output = log_os_system(tmp, 0)
else:
#order = 0
tmp = "sed -i 's/1-/0-/g' /usr/share/sonic/device/"+device_path+"/fancontrol"
status, output = log_os_system(tmp, 0)
tmp = "sed -i 's/1-/0-/g' /usr/share/sonic/device/"+device_path+"/plugins/led_control.py"
status, output = log_os_system(tmp, 0)
return order
def device_install():
global FORCE
order = i2c_order_check()
# if 0x76 is not exist @i2c-0, use reversed bus order
if order:
for i in range(0,len(mknod2)):
#for pca954x need times to built new i2c buses
if mknod2[i].find('pca954') != -1:
time.sleep(1)
if mknod2[i].find('lm75') != -1:
time.sleep(1)
status, output = log_os_system(mknod2[i], 1)
if status:
print output
if FORCE == 0:
return status
else:
for i in range(0,len(mknod)):
#for pca954x need times to built new i2c buses
if mknod[i].find('pca954') != -1:
time.sleep(1)
if mknod[i].find('lm75') != -1:
time.sleep(1)
status, output = log_os_system(mknod[i], 1)
if status:
print output
if FORCE == 0:
return status
status, output =log_os_system("echo 0 > /sys/bus/i2c/devices/9-005f/sys_reset1", 1)
if status:
print output
if FORCE == 0:
return status
for i in range(0, 32):
index = i / 8
port = i % 8
reg_sfp = 0
if port == 0:
reg_sfp = 1
if reg_sfp == 1:
status, output =log_os_system("echo sfpcpld"+str(i+1)+" 0x5f > /sys/bus/i2c/devices/i2c-"+str(sfp_map[index])+"/new_device", 1)
if status:
print output
if FORCE == 0:
return status
status, output =log_os_system("echo sfpcpld"+str(i+1)+" 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[index])+"/new_device", 1)
if status:
print output
if FORCE == 0:
return status
return
def device_uninstall():
global FORCE
status, output = log_os_system("i2cdetect -l | grep I801 | grep i2c-0", 0)
if not output:
I2C_ORDER=1
else:
I2C_ORDER=0
for i in range(0, 32):
index = i / 8
port = i % 8
reg_sfp = 0
if port == 0:
reg_sfp = 1
if reg_sfp == 1:
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[index])+"/delete_device"
status, output =log_os_system("echo 0x5f > "+ target, 1)
if status:
print output
if FORCE == 0:
return status
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[index])+"/delete_device"
status, output =log_os_system("echo 0x50 > "+ target, 1)
if status:
print output
if FORCE == 0:
return status
if I2C_ORDER==0:
nodelist = mknod
else:
nodelist = mknod2
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_check() == False:
return False
if not device_exist():
return False
return True
def do_install():
tmp = "find /var/lib/docker/overlay -iname fancontrol | grep usr/sbin/fancontrol | xargs cat | sed '429d' | sed '428a if \[ $? -ne 1 \]' | sed '425d' | sed '424a return' > /tmp/tmp_fancontrol"
status, output = log_os_system(tmp, 1)
tmp = "fancontrol_tmp=`find /var/lib/docker/overlay -iname fancontrol | grep usr/sbin/fancontrol` ; cp /tmp/tmp_fancontrol $fancontrol_tmp"
status, output = log_os_system(tmp, 1)
print "Checking system...."
if driver_check() == False:
print "No driver, installing...."
status = driver_install()
if status:
if FORCE == 0:
return status
else:
print PROJECT_NAME.upper()+" drivers detected...."
if not device_exist():
print "No device, installing...."
status = device_install()
if status:
if FORCE == 0:
return status
else:
print PROJECT_NAME.upper()+" devices detected...."
return
def do_uninstall():
print "Checking system...."
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_check()== 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 device_exist():
ret1, log = log_os_system("ls "+i2c_prefix+"*0070", 0)
ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0)
return not(ret1 or ret2)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,8 @@
# obj-m:=accton_as7712_32x_fan.o accton_as7712_32x_sfp.o leds-accton_as7712_32x.o \
# goreme_system_cpld.o ym2651y.o optoe.o
obj-m:=alphanetworks_snh60b0-640f_sfp.o snh60b0-640f_system_cpld.o snh60b0-640f_power_cpld.o snh60b0-640f_onie_eeprom.o
# obj-m:=accton_as7712_32x_fan.o accton_as7712_32x_sfp.o leds-accton_as7712_32x.o \
# accton_as7712_32x_psu.o accton_i2c_cpld.o ym2651y.o optoe.o

View File

@ -0,0 +1,268 @@
/*
* A driver for snh60b0-640f onie eeprom
*
* Copyright (C) 2018 Alphanetworks Technology Corporation.
* Robin Chen <Robin_chen@Alphanetworks.com>
* 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
* 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.
* see <http://www.gnu.org/licenses/>
*
* 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/i2c.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/dmi.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/mutex.h>
#define EEPROM_SIZE 256
#define SYS_LED_REG 0x8
#define FAN12_LED_REG 0x9
#define FAN34_LED_REG 0xA
#define FAN56_LED_REG 0xB
#define SYS_RESET1_REG 0x2
#define SYS_LOCATOR_LED_BITS 0x01
#define SYS_PWR_LED_BITS 0x0E
#define SYS_STATUS_LED_BITS 0x70
#define FAN135_LED_BITS 0x07
#define FAN246_LED_BITS 0x38
extern int alpha_i2c_cpld_read(unsigned short cpld_addr, u8 reg);
extern int alpha_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
static ssize_t onie_read(struct device *dev, struct device_attribute *attr, char *buf);
static ssize_t onie_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static LIST_HEAD(cpld_client_list);
static struct mutex list_lock;
struct cpld_client_node {
struct i2c_client *client;
struct list_head list;
};
/* Addresses scanned for snh60b0-640f_onie_eeprom */
static const unsigned short normal_i2c[] = { 0x56, I2C_CLIENT_END };
enum sysfs_onie_attributes {
ONIE_RW,
};
static SENSOR_DEVICE_ATTR(eeprom, (0660), onie_read, onie_write, ONIE_RW);
static struct attribute *snh60b0_onie_attributes[] = {
&sensor_dev_attr_eeprom.dev_attr.attr,
NULL
};
static const struct attribute_group snh60b0_onie_group = {
.attrs = snh60b0_onie_attributes,
};
static ssize_t onie_read(struct device *dev, struct device_attribute *attr, char *buf)
{
int val = 0, res = 0;
u8 command;
struct i2c_client *client = to_i2c_client(dev);
__u8 read_write;
unsigned short offset = 0;
union i2c_smbus_data temp;
char rbuf[EEPROM_SIZE];
for( offset=0 ; offset < EEPROM_SIZE ; ++offset )
{
read_write = I2C_SMBUS_WRITE;
offset = offset & 0x3fff;
temp.byte = (u8)offset;
res = i2c_smbus_xfer(client->adapter, client->addr, client->flags=0,
read_write, 0, 2, &temp);
res = i2c_smbus_xfer(client->adapter, client->addr, client->flags=0,
read_write, 0, 2, &temp);
read_write = I2C_SMBUS_READ;
temp.byte = 0xaa;
res = i2c_smbus_xfer(client->adapter, client->addr, client->flags=0,
read_write, 0, 1, &temp);
if (!res)
{
res = temp.byte;
rbuf[offset] = (char)temp.byte;
}
read_write = I2C_SMBUS_READ;
temp.byte = 0xbb;
res = i2c_smbus_xfer(client->adapter, client->addr, client->flags=0,
read_write, 0, 1, &temp);
if (!res)
{
res = temp.byte;
}
}
memcpy(buf, rbuf, EEPROM_SIZE);
return EEPROM_SIZE;
}
static ssize_t onie_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
int error, write, command, read;
error = kstrtoint(buf, 10, &write);
if (error)
return error;
if (write < 0 || write > 255)
return -EINVAL;
/* Not support yet */
return count;
}
static void alpha_i2c_cpld_add_client(struct i2c_client *client)
{
struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL);
if (!node) {
dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr);
return;
}
node->client = client;
mutex_lock(&list_lock);
list_add(&node->list, &cpld_client_list);
mutex_unlock(&list_lock);
}
static void alpha_i2c_cpld_remove_client(struct i2c_client *client)
{
struct list_head *list_node = NULL;
struct cpld_client_node *cpld_node = NULL;
int found = 0;
mutex_lock(&list_lock);
list_for_each(list_node, &cpld_client_list)
{
cpld_node = list_entry(list_node, struct cpld_client_node, list);
if (cpld_node->client == client) {
found = 1;
break;
}
}
if (found) {
list_del(list_node);
kfree(cpld_node);
}
mutex_unlock(&list_lock);
}
static int onie_eeprom_probe(struct i2c_client *client,
const struct i2c_device_id *dev_id)
{
int status;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
dev_dbg(&client->dev, "i2c_check_functionality failed (0x%x)\n", client->addr);
status = -EIO;
goto exit;
}
status = sysfs_create_group(&client->dev.kobj, &snh60b0_onie_group);
if (status) {
goto exit;
}
dev_info(&client->dev, "chip found\n");
alpha_i2c_cpld_add_client(client);
return 0;
exit:
return status;
}
static int onie_eeprom_remove(struct i2c_client *client)
{
sysfs_remove_group(&client->dev.kobj, &snh60b0_onie_group);
alpha_i2c_cpld_remove_client(client);
return 0;
}
static const struct i2c_device_id onie_eeprom_id[] = {
{ "snh60b0_onie_eeprom", 0 },
{}
};
MODULE_DEVICE_TABLE(i2c, onie_eeprom_id);
static struct i2c_driver onie_eeprom_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = "snh60b0_onie_eeprom",
},
.probe = onie_eeprom_probe,
.remove = onie_eeprom_remove,
.id_table = onie_eeprom_id,
.address_list = normal_i2c,
};
static int __init onie_eeprom_init(void)
{
mutex_init(&list_lock);
return i2c_add_driver(&onie_eeprom_driver);
}
static void __exit onie_eeprom_exit(void)
{
i2c_del_driver(&onie_eeprom_driver);
}
MODULE_AUTHOR("Alpha-SID6");
MODULE_DESCRIPTION("onie eeprom driver");
MODULE_LICENSE("GPL");
module_init(onie_eeprom_init);
module_exit(onie_eeprom_exit);

View File

@ -0,0 +1,501 @@
/*
* A hwmon driver for the snh60b0-640f_power_cpld
*
* Copyright (C) 2018 Alphanetworks Technology Corporation.
* Robin Chen <Robin_chen@Alphanetworks.com>
* 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
* 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.
* see <http://www.gnu.org/licenses/>
*
* 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/i2c.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/dmi.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/mutex.h>
#define DRIVER_NAME "snh60b0_power_cpld"
#define PSU1_STATUS_REG 0x3
#define PSU2_STATUS_REG 0x4
#define FAN_PWM_REG 0x23
#define PSU_PRESENT_BIT 0x4
#define PSU_POWER_BIT 0x2
#define FAN_PRESENT_BIT 0x2
static ssize_t psu_show_status(struct device *dev, struct device_attribute *attr, char *buf);
static ssize_t fan_pwm_show(struct device *dev, struct device_attribute *attr, char *buf);
static ssize_t set_fan_pwm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static ssize_t fan_show_status(struct device *dev, struct device_attribute *attr, char *buf);
static LIST_HEAD(cpld_client_list);
static struct mutex list_lock;
struct cpld_client_node {
struct i2c_client *client;
struct list_head list;
};
/* Addresses scanned for snh60b0-640f_power_cpld */
static const unsigned short normal_i2c[] = { 0x5E, I2C_CLIENT_END };
struct snh60b0_pwr_cpld_data {
struct device *hwmon_dev;
struct mutex update_lock;
char model_name[9]; /* Model name, read from eeprom */
};
enum sysfs_psu_attributes {
PSU1_PRESENT,
PSU2_PRESENT,
PSU1_POWER_GOOD,
PSU2_POWER_GOOD,
FAN_PWM,
FAN1_FAULT,
FAN2_FAULT,
FAN3_FAULT,
FAN4_FAULT,
/* FAN5_FAULT, */
/* FAN6_FAULT, */
FAN1_PRESENT=0x12,
FAN2_PRESENT,
FAN3_PRESENT,
FAN4_PRESENT,
/* FAN5_PRESENT, */
/* FAN6_PRESENT, */
FAN1_FRONT_SPEED_RPM=0x1A,
FAN1_REAR_SPEED_RPM,
FAN2_FRONT_SPEED_RPM,
FAN2_REAR_SPEED_RPM,
FAN3_FRONT_SPEED_RPM,
FAN3_REAR_SPEED_RPM,
FAN4_FRONT_SPEED_RPM,
FAN4_REAR_SPEED_RPM,
/* FAN5_FRONT_SPEED_RPM, */
/* FAN5_REAR_SPEED_RPM, */
/* FAN6_FRONT_SPEED_RPM, */
/* FAN6_REAR_SPEED_RPM, */
};
static SENSOR_DEVICE_ATTR(psu1_present, S_IRUGO, psu_show_status, NULL, PSU1_PRESENT);
static SENSOR_DEVICE_ATTR(psu2_present, S_IRUGO, psu_show_status, NULL, PSU2_PRESENT);
static SENSOR_DEVICE_ATTR(psu1_power_good, S_IRUGO, psu_show_status, NULL, PSU1_POWER_GOOD);
static SENSOR_DEVICE_ATTR(psu2_power_good, S_IRUGO, psu_show_status, NULL, PSU2_POWER_GOOD);
static SENSOR_DEVICE_ATTR(fan_pwm, (0660), fan_pwm_show, set_fan_pwm, FAN_PWM);
static SENSOR_DEVICE_ATTR(fan1_present, S_IRUGO, fan_show_status, NULL, FAN1_PRESENT);
static SENSOR_DEVICE_ATTR(fan2_present, S_IRUGO, fan_show_status, NULL, FAN2_PRESENT);
static SENSOR_DEVICE_ATTR(fan3_present, S_IRUGO, fan_show_status, NULL, FAN3_PRESENT);
static SENSOR_DEVICE_ATTR(fan4_present, S_IRUGO, fan_show_status, NULL, FAN4_PRESENT);
/* static SENSOR_DEVICE_ATTR(fan5_present, S_IRUGO, fan_show_status, NULL, FAN5_PRESENT); */
/* static SENSOR_DEVICE_ATTR(fan6_present, S_IRUGO, fan_show_status, NULL, FAN6_PRESENT); */
static SENSOR_DEVICE_ATTR(fan1_front_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN1_FRONT_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan2_front_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN2_FRONT_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan3_front_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN3_FRONT_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan4_front_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN4_FRONT_SPEED_RPM);
/* static SENSOR_DEVICE_ATTR(fan5_front_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN5_FRONT_SPEED_RPM); */
/* static SENSOR_DEVICE_ATTR(fan6_front_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN6_FRONT_SPEED_RPM); */
static SENSOR_DEVICE_ATTR(fan1_rear_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN1_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan2_rear_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN2_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan3_rear_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN3_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan4_rear_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN4_REAR_SPEED_RPM);
/* static SENSOR_DEVICE_ATTR(fan5_rear_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN5_REAR_SPEED_RPM); */
/* static SENSOR_DEVICE_ATTR(fan6_rear_speed_rpm, S_IRUGO, fan_show_status, NULL, FAN6_REAR_SPEED_RPM); */
static SENSOR_DEVICE_ATTR(fan1_fault, S_IRUGO, fan_show_status, NULL, FAN1_FAULT); static SENSOR_DEVICE_ATTR(fan11_fault, S_IRUGO, fan_show_status, NULL, FAN1_FAULT);
static SENSOR_DEVICE_ATTR(fan2_fault, S_IRUGO, fan_show_status, NULL, FAN2_FAULT); static SENSOR_DEVICE_ATTR(fan12_fault, S_IRUGO, fan_show_status, NULL, FAN2_FAULT);
static SENSOR_DEVICE_ATTR(fan3_fault, S_IRUGO, fan_show_status, NULL, FAN3_FAULT); static SENSOR_DEVICE_ATTR(fan13_fault, S_IRUGO, fan_show_status, NULL, FAN3_FAULT);
static SENSOR_DEVICE_ATTR(fan4_fault, S_IRUGO, fan_show_status, NULL, FAN4_FAULT); static SENSOR_DEVICE_ATTR(fan14_fault, S_IRUGO, fan_show_status, NULL, FAN4_FAULT);
/* static SENSOR_DEVICE_ATTR(fan5_fault, S_IRUGO, fan_show_status, NULL, FAN5_FAULT); static SENSOR_DEVICE_ATTR(fan15_fault, S_IRUGO, fan_show_status, NULL, FAN5_FAULT); */
/* static SENSOR_DEVICE_ATTR(fan6_fault, S_IRUGO, fan_show_status, NULL, FAN6_FAULT); static SENSOR_DEVICE_ATTR(fan16_fault, S_IRUGO, fan_show_status, NULL, FAN6_FAULT); */
static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, fan_show_status, NULL, FAN1_FRONT_SPEED_RPM); static SENSOR_DEVICE_ATTR(fan11_input, S_IRUGO, fan_show_status, NULL, FAN1_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, fan_show_status, NULL, FAN2_FRONT_SPEED_RPM); static SENSOR_DEVICE_ATTR(fan12_input, S_IRUGO, fan_show_status, NULL, FAN2_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, fan_show_status, NULL, FAN3_FRONT_SPEED_RPM); static SENSOR_DEVICE_ATTR(fan13_input, S_IRUGO, fan_show_status, NULL, FAN3_REAR_SPEED_RPM);
static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, fan_show_status, NULL, FAN4_FRONT_SPEED_RPM); static SENSOR_DEVICE_ATTR(fan14_input, S_IRUGO, fan_show_status, NULL, FAN4_REAR_SPEED_RPM);
/* static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, fan_show_status, NULL, FAN5_FRONT_SPEED_RPM); static SENSOR_DEVICE_ATTR(fan15_input, S_IRUGO, fan_show_status, NULL, FAN5_REAR_SPEED_RPM); */
/* static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, fan_show_status, NULL, FAN6_FRONT_SPEED_RPM); static SENSOR_DEVICE_ATTR(fan16_input, S_IRUGO, fan_show_status, NULL, FAN6_REAR_SPEED_RPM); */
static struct attribute *snh60b0_psu_attributes[] = {
&sensor_dev_attr_psu1_present.dev_attr.attr,
&sensor_dev_attr_psu2_present.dev_attr.attr,
&sensor_dev_attr_psu1_power_good.dev_attr.attr,
&sensor_dev_attr_psu2_power_good.dev_attr.attr,
&sensor_dev_attr_fan_pwm.dev_attr.attr,
&sensor_dev_attr_fan1_present.dev_attr.attr,
&sensor_dev_attr_fan2_present.dev_attr.attr,
&sensor_dev_attr_fan3_present.dev_attr.attr,
&sensor_dev_attr_fan4_present.dev_attr.attr,
/* &sensor_dev_attr_fan5_present.dev_attr.attr, */
/* &sensor_dev_attr_fan6_present.dev_attr.attr, */
&sensor_dev_attr_fan1_front_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan2_front_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan3_front_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan4_front_speed_rpm.dev_attr.attr,
/* &sensor_dev_attr_fan5_front_speed_rpm.dev_attr.attr, */
/* &sensor_dev_attr_fan6_front_speed_rpm.dev_attr.attr, */
&sensor_dev_attr_fan1_rear_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan2_rear_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan3_rear_speed_rpm.dev_attr.attr,
&sensor_dev_attr_fan4_rear_speed_rpm.dev_attr.attr,
/* &sensor_dev_attr_fan5_rear_speed_rpm.dev_attr.attr, */
/* &sensor_dev_attr_fan6_rear_speed_rpm.dev_attr.attr, */
&sensor_dev_attr_fan1_fault.dev_attr.attr, &sensor_dev_attr_fan11_fault.dev_attr.attr,
&sensor_dev_attr_fan2_fault.dev_attr.attr, &sensor_dev_attr_fan12_fault.dev_attr.attr,
&sensor_dev_attr_fan3_fault.dev_attr.attr, &sensor_dev_attr_fan13_fault.dev_attr.attr,
&sensor_dev_attr_fan4_fault.dev_attr.attr, &sensor_dev_attr_fan14_fault.dev_attr.attr,
/* &sensor_dev_attr_fan5_fault.dev_attr.attr, &sensor_dev_attr_fan15_fault.dev_attr.attr, */
/* &sensor_dev_attr_fan6_fault.dev_attr.attr, &sensor_dev_attr_fan16_fault.dev_attr.attr, */
&sensor_dev_attr_fan1_input.dev_attr.attr, &sensor_dev_attr_fan11_input.dev_attr.attr,
&sensor_dev_attr_fan2_input.dev_attr.attr, &sensor_dev_attr_fan12_input.dev_attr.attr,
&sensor_dev_attr_fan3_input.dev_attr.attr, &sensor_dev_attr_fan13_input.dev_attr.attr,
&sensor_dev_attr_fan4_input.dev_attr.attr, &sensor_dev_attr_fan14_input.dev_attr.attr,
/* &sensor_dev_attr_fan5_input.dev_attr.attr, &sensor_dev_attr_fan15_input.dev_attr.attr, */
/* &sensor_dev_attr_fan6_input.dev_attr.attr, &sensor_dev_attr_fan16_input.dev_attr.attr, */
NULL
};
static const struct attribute_group snh60b0_psu_group = {
.attrs = snh60b0_psu_attributes,
};
static ssize_t psu_show_status(struct device *dev, struct device_attribute *attr, char *buf)
{
int val = 0, res = 0;
u8 command;
struct i2c_client *client = to_i2c_client(dev);
struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
switch(sda->index) {
case PSU1_PRESENT:
case PSU1_POWER_GOOD:
command = PSU1_STATUS_REG;
break;
case PSU2_PRESENT:
case PSU2_POWER_GOOD:
command = PSU2_STATUS_REG;
break;
}
val = i2c_smbus_read_byte_data(client, command);
if (val < 0) {
dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val);
}
switch(sda->index) {
case PSU1_PRESENT:
case PSU2_PRESENT:
res = (val & PSU_PRESENT_BIT ? 1 : 0 );
break;
case PSU1_POWER_GOOD:
case PSU2_POWER_GOOD:
res = (val & PSU_POWER_BIT ? 1 : 0 );
break;
}
return sprintf(buf, "%d\n", res);
}
static ssize_t fan_pwm_show(struct device *dev, struct device_attribute *attr, char *buf)
{
int val = 0;
struct i2c_client *client = to_i2c_client(dev);
val = i2c_smbus_read_byte_data(client, FAN_PWM_REG);
if (val < 0) {
dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val);
}
return sprintf(buf, "%d", val);
}
static ssize_t set_fan_pwm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
int error, value;
error = kstrtoint(buf, 10, &value);
if (error)
return error;
if (value < 0 || value > 0xFF)
return -EINVAL;
i2c_smbus_write_byte_data(client, FAN_PWM_REG, value);
return count;
}
static ssize_t fan_show_status(struct device *dev, struct device_attribute *attr, char *buf)
{
struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
struct i2c_client *client = to_i2c_client(dev);
// struct as7712_32x_fan_data *data = as7712_32x_fan_update_device(dev);
ssize_t ret = 0;
int val, val2;
switch (sda->index) {
case FAN1_FRONT_SPEED_RPM:
case FAN2_FRONT_SPEED_RPM:
case FAN3_FRONT_SPEED_RPM:
case FAN4_FRONT_SPEED_RPM:
/* case FAN5_FRONT_SPEED_RPM: */
/* case FAN6_FRONT_SPEED_RPM: */
case FAN1_REAR_SPEED_RPM:
case FAN2_REAR_SPEED_RPM:
case FAN3_REAR_SPEED_RPM:
case FAN4_REAR_SPEED_RPM:
/* case FAN5_REAR_SPEED_RPM: */
/* case FAN6_REAR_SPEED_RPM: */
val = i2c_smbus_read_byte_data(client, sda->index);
ret = sprintf(buf, "%d\n", val * 150);
break;
case FAN1_PRESENT:
case FAN2_PRESENT:
case FAN3_PRESENT:
case FAN4_PRESENT:
/* case FAN5_PRESENT: */
/* case FAN6_PRESENT: */
val = i2c_smbus_read_byte_data(client, sda->index);
ret = sprintf(buf, "%d\n", (val & FAN_PRESENT_BIT) ? 1 : 0);
break;
case FAN1_FAULT:
case FAN2_FAULT:
case FAN3_FAULT:
case FAN4_FAULT:
/* case FAN5_FAULT: */
/* case FAN6_FAULT: */
val = i2c_smbus_read_byte_data(client, (sda->index - FAN1_FAULT)*2 + FAN1_FRONT_SPEED_RPM);
val2 = i2c_smbus_read_byte_data(client, (sda->index - FAN1_FAULT)*2 + FAN1_REAR_SPEED_RPM);
ret = sprintf(buf, "%d\n", (val|val2) ? 0 : 1);
break;
default:
break;
}
return ret;
}
static void alpha_i2c_cpld_add_client(struct i2c_client *client)
{
struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL);
if (!node) {
dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr);
return;
}
node->client = client;
mutex_lock(&list_lock);
list_add(&node->list, &cpld_client_list);
mutex_unlock(&list_lock);
}
static void alpha_i2c_cpld_remove_client(struct i2c_client *client)
{
struct list_head *list_node = NULL;
struct cpld_client_node *cpld_node = NULL;
int found = 0;
mutex_lock(&list_lock);
list_for_each(list_node, &cpld_client_list)
{
cpld_node = list_entry(list_node, struct cpld_client_node, list);
if (cpld_node->client == client) {
found = 1;
break;
}
}
if (found) {
list_del(list_node);
kfree(cpld_node);
}
mutex_unlock(&list_lock);
}
static int alpha_i2c_cpld_probe(struct i2c_client *client,
const struct i2c_device_id *dev_id)
{
int status;
struct snh60b0_pwr_cpld_data* data;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
dev_dbg(&client->dev, "i2c_check_functionality failed (0x%x)\n", client->addr);
status = -EIO;
goto exit;
}
data = kzalloc(sizeof(struct snh60b0_pwr_cpld_data), GFP_KERNEL);
if (!data) {
status = -ENOMEM;
goto exit;
}
status = sysfs_create_group(&client->dev.kobj, &snh60b0_psu_group);
if (status) {
goto exit;
}
dev_info(&client->dev, "chip found\n");
alpha_i2c_cpld_add_client(client);
data->hwmon_dev = hwmon_device_register(&client->dev);
if (IS_ERR(data->hwmon_dev)) {
status = PTR_ERR(data->hwmon_dev);
goto exit;
}
dev_info(&client->dev, "%s: pwr_cpld '%s'\n",
dev_name(data->hwmon_dev), client->name);
return 0;
exit:
return status;
}
static int alpha_i2c_cpld_remove(struct i2c_client *client)
{
struct snh60b0_pwr_cpld_data *data = i2c_get_clientdata(client);
sysfs_remove_group(&client->dev.kobj, &snh60b0_psu_group);
alpha_i2c_cpld_remove_client(client);
kfree(data);
return 0;
}
static const struct i2c_device_id alpha_i2c_cpld_id[] = {
{ DRIVER_NAME, 0 },
{}
};
MODULE_DEVICE_TABLE(i2c, alpha_i2c_cpld_id);
static struct i2c_driver alpha_i2c_cpld_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = DRIVER_NAME,
},
.probe = alpha_i2c_cpld_probe,
.remove = alpha_i2c_cpld_remove,
.id_table = alpha_i2c_cpld_id,
.address_list = normal_i2c,
};
int alpha_i2c_cpld_read(unsigned short cpld_addr, u8 reg)
{
struct list_head *list_node = NULL;
struct cpld_client_node *cpld_node = NULL;
int ret = -EPERM;
mutex_lock(&list_lock);
list_for_each(list_node, &cpld_client_list)
{
cpld_node = list_entry(list_node, struct cpld_client_node, list);
if (cpld_node->client->addr == cpld_addr) {
ret = i2c_smbus_read_byte_data(cpld_node->client, reg);
break;
}
}
mutex_unlock(&list_lock);
return ret;
}
EXPORT_SYMBOL(alpha_i2c_cpld_read);
int alpha_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value)
{
struct list_head *list_node = NULL;
struct cpld_client_node *cpld_node = NULL;
int ret = -EIO;
mutex_lock(&list_lock);
list_for_each(list_node, &cpld_client_list)
{
cpld_node = list_entry(list_node, struct cpld_client_node, list);
if (cpld_node->client->addr == cpld_addr) {
ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value);
break;
}
}
mutex_unlock(&list_lock);
return ret;
}
EXPORT_SYMBOL(alpha_i2c_cpld_write);
static int __init alpha_i2c_cpld_init(void)
{
mutex_init(&list_lock);
return i2c_add_driver(&alpha_i2c_cpld_driver);
}
static void __exit alpha_i2c_cpld_exit(void)
{
i2c_del_driver(&alpha_i2c_cpld_driver);
}
static struct dmi_system_id snh60b0_dmi_table[] = {
{
.ident = "Alpha snh60b0-640f",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Alpha"),
DMI_MATCH(DMI_PRODUCT_NAME, "snh60b0-640f"),
},
}
};
int platform_alpha_snh60b0(void)
{
return dmi_check_system(snh60b0_dmi_table);
}
EXPORT_SYMBOL(platform_alpha_snh60b0);
MODULE_AUTHOR("Alpha-SID6");
MODULE_DESCRIPTION("alpha_power_cpld driver");
MODULE_LICENSE("GPL");
module_init(alpha_i2c_cpld_init);
module_exit(alpha_i2c_cpld_exit);

View File

@ -0,0 +1,365 @@
/*
* A hwmon driver for the snh60b0-640f_system_cpld
*
* Copyright (C) 2018 Alphanetworks Technology Corporation.
* Robin Chen <Robin_chen@Alphanetworks.com>
* 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
* 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.
* see <http://www.gnu.org/licenses/>
*
* 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/i2c.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/dmi.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/mutex.h>
#define SYS_LED_REG 0x8
#define FAN12_LED_REG 0x9
#define FAN34_LED_REG 0xA
#define SYS_RESET1_REG 0x2
#define SWI_CTRL_REG 0x4
#define SYS_LOCATOR_LED_BITS 0x01
#define SYS_PWR_LED_BITS 0x0E
#define SYS_STATUS_LED_BITS 0x70
#define FAN135_LED_BITS 0x07
#define FAN246_LED_BITS 0x38
#define REST_BUTTON_BITS 0x0
extern int alpha_i2c_cpld_read(unsigned short cpld_addr, u8 reg);
extern int alpha_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value);
static ssize_t sys_led_read(struct device *dev, struct device_attribute *attr, char *buf);
static ssize_t sys_led_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static LIST_HEAD(cpld_client_list);
static struct mutex list_lock;
struct cpld_client_node {
struct i2c_client *client;
struct list_head list;
};
/* Addresses scanned for snh60b0-640f_system_cpld */
static const unsigned short normal_i2c[] = { 0x5F, I2C_CLIENT_END };
enum sysfs_sys_attributes {
SYS_LOCATOR,
SYS_PWR,
SYS_STATUS,
FAN1_LED,
FAN2_LED,
FAN3_LED,
FAN4_LED,
SYS_REST1,
SWI_CTRL,
};
static SENSOR_DEVICE_ATTR(sys_locator, (0660), sys_led_read, sys_led_write, SYS_LOCATOR);
static SENSOR_DEVICE_ATTR(sys_pwr, (0660), sys_led_read, sys_led_write, SYS_PWR);
static SENSOR_DEVICE_ATTR(sys_status, (0600), sys_led_read, sys_led_write, SYS_STATUS);
static SENSOR_DEVICE_ATTR(fan1_led, (0660), sys_led_read, sys_led_write, FAN1_LED);
static SENSOR_DEVICE_ATTR(fan2_led, (0660), sys_led_read, sys_led_write, FAN2_LED);
static SENSOR_DEVICE_ATTR(fan3_led, (0660), sys_led_read, sys_led_write, FAN3_LED);
static SENSOR_DEVICE_ATTR(fan4_led, (0660), sys_led_read, sys_led_write, FAN4_LED);
static SENSOR_DEVICE_ATTR(sys_reset1, (0660), sys_led_read, sys_led_write, SYS_REST1);
static SENSOR_DEVICE_ATTR(swi_ctrl, (0660), sys_led_read, NULL, SWI_CTRL);
static struct attribute *snh60b0_sys_attributes[] = {
&sensor_dev_attr_sys_locator.dev_attr.attr,
&sensor_dev_attr_sys_pwr.dev_attr.attr,
&sensor_dev_attr_sys_status.dev_attr.attr,
&sensor_dev_attr_fan1_led.dev_attr.attr,
&sensor_dev_attr_fan2_led.dev_attr.attr,
&sensor_dev_attr_fan3_led.dev_attr.attr,
&sensor_dev_attr_fan4_led.dev_attr.attr,
&sensor_dev_attr_sys_reset1.dev_attr.attr,
&sensor_dev_attr_swi_ctrl.dev_attr.attr,
NULL
};
static const struct attribute_group snh60b0_sys_group = {
.attrs = snh60b0_sys_attributes,
};
static ssize_t sys_led_read(struct device *dev, struct device_attribute *attr, char *buf)
{
int val = 0, res = 0;
u8 command;
struct i2c_client *client = to_i2c_client(dev);
struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
switch(sda->index) {
case SYS_LOCATOR:
case SYS_PWR:
case SYS_STATUS:
command = SYS_LED_REG;
break;
case FAN1_LED:
case FAN2_LED:
case FAN3_LED:
case FAN4_LED:
command = FAN12_LED_REG + (sda->index - FAN1_LED)/2;
break;
case SYS_REST1:
command = SYS_RESET1_REG;
break;
case SWI_CTRL:
command = SWI_CTRL_REG;
break;
}
val = i2c_smbus_read_byte_data(client, command);
if (val < 0) {
dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val);
}
switch(sda->index) {
case SYS_LOCATOR:
res = (val & SYS_LOCATOR_LED_BITS) >> 0;
break;
case SYS_PWR:
res = (val & SYS_PWR_LED_BITS) >> 1;
break;
case SYS_STATUS:
res = (val & SYS_STATUS_LED_BITS) >> 4;
break;
case FAN1_LED:
case FAN3_LED:
res = (val & FAN135_LED_BITS) >> 0;
break;
case FAN2_LED:
case FAN4_LED:
res = (val & FAN246_LED_BITS) >> 3;
break;
case SYS_REST1:
res = val;
break;
case SWI_CTRL:
res = (val & REST_BUTTON_BITS) >> 0;
break;
}
return sprintf(buf, "%d\n", res);
}
static ssize_t sys_led_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
int error, write, command, read;
error = kstrtoint(buf, 10, &write);
if (error)
return error;
switch(sda->index) {
case SYS_LOCATOR:
if(write < 0 || write > 2)
return -EINVAL;
case SYS_PWR:
case SYS_STATUS:
if (write < 0 || write > 7)
return -EINVAL;
command = SYS_LED_REG;
break;
case FAN1_LED:
case FAN2_LED:
case FAN3_LED:
case FAN4_LED:
if (write < 0 || write > 7)
return -EINVAL;
command = FAN12_LED_REG + (sda->index - FAN1_LED)/2;
break;
case SYS_REST1:
if (write < 0 || write > 15)
return -EINVAL;
command = SYS_RESET1_REG;
break;
}
read = i2c_smbus_read_byte_data(client, command);
if (read < 0) {
dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, read);
}
switch(sda->index) {
case SYS_LOCATOR:
read &= ~SYS_LOCATOR_LED_BITS;
read |= write << 0;
break;
case SYS_PWR:
read &= ~SYS_PWR_LED_BITS;
read |= write << 1;
break;
case SYS_STATUS:
read &= ~SYS_STATUS_LED_BITS;
read |= write << 4;
break;
case FAN1_LED:
case FAN3_LED:
read &= ~FAN135_LED_BITS;
read |= write << 0;
break;
case FAN2_LED:
case FAN4_LED:
read &= ~FAN246_LED_BITS;
read |= write << 3;
break;
case SYS_REST1:
read = write;
break;
}
i2c_smbus_write_byte_data(client, command, read);
return count;
}
static void alpha_i2c_cpld_add_client(struct i2c_client *client)
{
struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL);
if (!node) {
dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr);
return;
}
node->client = client;
mutex_lock(&list_lock);
list_add(&node->list, &cpld_client_list);
mutex_unlock(&list_lock);
}
static void alpha_i2c_cpld_remove_client(struct i2c_client *client)
{
struct list_head *list_node = NULL;
struct cpld_client_node *cpld_node = NULL;
int found = 0;
mutex_lock(&list_lock);
list_for_each(list_node, &cpld_client_list)
{
cpld_node = list_entry(list_node, struct cpld_client_node, list);
if (cpld_node->client == client) {
found = 1;
break;
}
}
if (found) {
list_del(list_node);
kfree(cpld_node);
}
mutex_unlock(&list_lock);
}
static int alpha_i2c_cpld_probe(struct i2c_client *client,
const struct i2c_device_id *dev_id)
{
int status;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
dev_dbg(&client->dev, "i2c_check_functionality failed (0x%x)\n", client->addr);
status = -EIO;
goto exit;
}
status = sysfs_create_group(&client->dev.kobj, &snh60b0_sys_group);
if (status) {
goto exit;
}
dev_info(&client->dev, "chip found\n");
alpha_i2c_cpld_add_client(client);
return 0;
exit:
return status;
}
static int alpha_i2c_cpld_remove(struct i2c_client *client)
{
sysfs_remove_group(&client->dev.kobj, &snh60b0_sys_group);
alpha_i2c_cpld_remove_client(client);
return 0;
}
static const struct i2c_device_id alpha_i2c_cpld_id[] = {
{ "snh60b0_system_cpld", 0 },
{}
};
MODULE_DEVICE_TABLE(i2c, alpha_i2c_cpld_id);
static struct i2c_driver alpha_i2c_cpld_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = "snh60b0_system_cpld",
},
.probe = alpha_i2c_cpld_probe,
.remove = alpha_i2c_cpld_remove,
.id_table = alpha_i2c_cpld_id,
.address_list = normal_i2c,
};
static int __init alpha_i2c_cpld_init(void)
{
mutex_init(&list_lock);
return i2c_add_driver(&alpha_i2c_cpld_driver);
}
static void __exit alpha_i2c_cpld_exit(void)
{
i2c_del_driver(&alpha_i2c_cpld_driver);
}
MODULE_AUTHOR("Alpha-SID6");
MODULE_DESCRIPTION("alpha_system_cpld driver");
MODULE_LICENSE("GPL");
module_init(alpha_i2c_cpld_init);
module_exit(alpha_i2c_cpld_exit);

View File

@ -0,0 +1,13 @@
[Unit]
Description=Alphanetworks SNH60B0-640F Platform initialization service
Before=pmon.service
DefaultDependencies=no
[Service]
Type=oneshot
ExecStart=/usr/local/bin/alphanetworks_snh60b0_util.py -f install
ExecStop=/usr/local/bin/alphanetworks_snh60b0_util.py clean
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,16 @@
#!/usr/bin/env python
import os
import sys
from setuptools import setup
os.listdir
setup(
name='snh60b0_640f',
version='1.0',
description='Module to initialize Alphanetworks SNH60B0-640F platforms',
packages=['snh60b0_640f'],
package_dir={'snh60b0_640f': 'snh60b0-640f/classes'},
)

View File

@ -0,0 +1,427 @@
#!/usr/bin/env python
#
# Copyright (C) 2018 Alphanetworks Technology Corporation.
# Robin Chen <Robin_chen@Alphanetworks.com>
# 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
# 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.
# see <http://www.gnu.org/licenses/>
#
# 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
"""
import os
import commands
import sys, getopt
import logging
import re
import time
from collections import namedtuple
PROJECT_NAME = 'snh60b0-640f'
device_path = "x86_64-alphanetworks_snh60b0_640f-r0"
version = '0.1.0'
verbose = False
DEBUG = False
args = []
FORCE = 0
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:
logging.info('no option')
for arg in args:
if arg == 'install':
do_install()
elif arg == 'clean':
do_uninstall()
else:
show_help()
return 0
def show_help():
print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]}
sys.exit(0)
def show_log(txt):
if DEBUG == True:
print PROJECT_NAME.upper()+": "+txt
return
def log_os_system(cmd, show):
logging.info('Run :'+cmd)
status, output = commands.getstatusoutput(cmd)
show_log (cmd +" with result: " + str(status))
show_log (" output:"+output)
if status:
logging.info('Failed :'+cmd)
if show:
print('Failed :'+cmd)
return status, output
def driver_check():
ret, lsmod = log_os_system("lsmod| grep alphanetworks", 0)
logging.info('mods:'+lsmod)
if len(lsmod) ==0:
return False
return True
kos = [
'modprobe i2c_dev',
'modprobe i2c_mux_pca954x',
'modprobe optoe' ,
'modprobe snh60b0-640f_power_cpld' ,
'modprobe snh60b0-640f_system_cpld' ,
'modprobe snh60b0-640f_onie_eeprom' ,
'modprobe alphanetworks_snh60b0_640f_sfp' ]
def driver_install():
global FORCE
status, output = log_os_system("depmod", 1)
for i in range(0,len(kos)):
if kos[i].find('pca954') != -1:
status, output = log_os_system(kos[i]+ " force_deselect_on_exit=1", 1)
else:
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")
rm = rm.replace("insmod", "rmmod")
status, output = log_os_system(rm, 1)
if status:
if FORCE == 0:
return status
return 0
i2c_prefix = '/sys/bus/i2c/devices/'
sfp_map = [13,14,15,16,23]
mknod =[
'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo pca9545 0x71 > /sys/bus/i2c/devices/i2c-5/new_device',
'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-7/new_device',
'echo pca9545 0x71 > /sys/bus/i2c/devices/i2c-6/new_device',
'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-20/new_device',
'echo 24c02 0x51 > /sys/bus/i2c/devices/i2c-10/new_device',
'echo 24c02 0x51 > /sys/bus/i2c/devices/i2c-11/new_device',
'echo snh60b0_onie_eeprom 0x56 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo snh60b0_power_cpld 0x5e > /sys/bus/i2c/devices/i2c-0/new_device',
'echo snh60b0_system_cpld 0x5f > /sys/bus/i2c/devices/i2c-8/new_device',
'echo lm75 0x4D > /sys/bus/i2c/devices/i2c-3/new_device',
'echo lm75 0x4C > /sys/bus/i2c/devices/i2c-4/new_device',
'echo lm75 0x4F > /sys/bus/i2c/devices/i2c-0/new_device' ]
mknod2 =[
'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo pca9545 0x71 > /sys/bus/i2c/devices/i2c-6/new_device',
'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-8/new_device',
'echo pca9545 0x71 > /sys/bus/i2c/devices/i2c-7/new_device',
'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-21/new_device',
'echo 24c02 0x51 > /sys/bus/i2c/devices/i2c-11/new_device',
'echo 24c02 0x51 > /sys/bus/i2c/devices/i2c-12/new_device',
'echo snh60b0_onie_eeprom 0x56 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo snh60b0_power_cpld 0x5e > /sys/bus/i2c/devices/i2c-1/new_device',
'echo snh60b0_system_cpld 0x5f > /sys/bus/i2c/devices/i2c-9/new_device',
'echo lm75 0x4D > /sys/bus/i2c/devices/i2c-4/new_device',
'echo lm75 0x4C > /sys/bus/i2c/devices/i2c-5/new_device',
'echo lm75 0x4F > /sys/bus/i2c/devices/i2c-1/new_device' ]
def i2c_order_check():
# i2c bus 0 and 1 might be installed in different order.
# Here check if 0x76 is exist @ i2c-0
tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-0/new_device"
status, output = log_os_system(tmp, 0)
if not device_exist():
order = 1
tmp = "sed -i 's/0-/1-/g' /usr/share/sonic/device/"+device_path+"/fancontrol"
status, output = log_os_system(tmp, 0)
else:
order = 0
tmp = "sed -i 's/1-/0-/g' /usr/share/sonic/device/"+device_path+"/fancontrol"
status, output = log_os_system(tmp, 0)
tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-0/delete_device"
status, output = log_os_system(tmp, 0)
return order
def device_install():
global FORCE
order = i2c_order_check()
# if 0x76 is not exist @i2c-0, use reversed bus order
if order:
for i in range(0,len(mknod2)):
#for pca954x need times to built new i2c buses
if mknod2[i].find('pca954') != -1:
time.sleep(1)
if mknod2[i].find('lm75') != -1:
time.sleep(1)
status, output = log_os_system(mknod2[i], 1)
if status:
print output
if FORCE == 0:
return status
else:
for i in range(0,len(mknod)):
#for pca954x need times to built new i2c buses
if mknod[i].find('pca954') != -1:
time.sleep(1)
if mknod[i].find('lm75') != -1:
time.sleep(1)
status, output = log_os_system(mknod[i], 1)
if status:
print output
if FORCE == 0:
return status
status, output =log_os_system("echo 0 > /sys/bus/i2c/devices/8-005f/sys_reset1", 1)
if status:
print output
if FORCE == 0:
return status
for i in range(0, 66):
index = i / 16
port = i % 16
reg_sfp = 0
if port == 0:
reg_sfp = 1
if reg_sfp == 1:
if i == 64:
status, output =log_os_system("echo sfpcpld"+str(i+1)+" 0x20 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[index])+"/new_device", 1)
if status:
print output
if FORCE == 0:
return status
if i < 64:
status, output =log_os_system("echo sfpcpld"+str(i+1)+" 0x5f > /sys/bus/i2c/devices/i2c-"+str(sfp_map[index])+"/new_device", 1)
if status:
print output
if FORCE == 0:
return status
status, output =log_os_system("echo sfpcpld"+str(i+1)+" 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[index])+"/new_device", 1)
if status:
print output
if FORCE == 0:
return status
if i == 64:
status, output =log_os_system("echo sfpcpld"+str(i+1)+" 0x50 > /sys/bus/i2c/devices/i2c-21/new_device", 1)
if status:
print output
if FORCE == 0:
return status
if i == 65:
status, output =log_os_system("echo sfpcpld"+str(i+1)+" 0x50 > /sys/bus/i2c/devices/i2c-22/new_device", 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/1-0070", 0)
if status==0:
I2C_ORDER=1
else:
I2C_ORDER=0
for i in range(0, 66):
index = i / 16
port = i % 16
reg_sfp = 0
if port == 0:
reg_sfp = 1
if reg_sfp == 1:
if i == 64:
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[index])+"/delete_device"
status, output =log_os_system("echo 0x20 > "+ target, 1)
if status:
print output
if FORCE == 0:
return status
if i < 64:
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[index])+"/delete_device"
status, output =log_os_system("echo 0x5f > "+ target, 1)
if status:
print output
if FORCE == 0:
return status
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[index])+"/delete_device"
status, output =log_os_system("echo 0x50 > "+ target, 1)
if status:
print output
if FORCE == 0:
return status
if i == 64:
status, output =log_os_system("echo 0x50 > /sys/bus/i2c/devices/i2c-21/delete_device", 1)
if status:
print output
if FORCE == 0:
return status
if i == 65:
status, output =log_os_system("echo 0x50 > /sys/bus/i2c/devices/i2c-22/delete_device", 1)
if status:
print output
if FORCE == 0:
return status
if I2C_ORDER==0:
nodelist = mknod
else:
nodelist = mknod2
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_check() == False:
return False
if not device_exist():
return False
return True
def do_install():
tmp = "find /var/lib/docker/overlay -iname fancontrol | grep usr/sbin/fancontrol | xargs cat | sed '429d' | sed '428a if \[ $? -ne 1 \]' | sed '425d' | sed '424a return' > /tmp/tmp_fancontrol"
status, output = log_os_system(tmp, 1)
tmp = "fancontrol_tmp=`find /var/lib/docker/overlay -iname fancontrol | grep usr/sbin/fancontrol` ; cp /tmp/tmp_fancontrol $fancontrol_tmp"
status, output = log_os_system(tmp, 1)
print "Checking system...."
if driver_check() == False:
print "No driver, installing...."
status = driver_install()
if status:
if FORCE == 0:
return status
else:
print PROJECT_NAME.upper()+" drivers detected...."
if not device_exist():
print "No device, installing...."
status = device_install()
if status:
if FORCE == 0:
return status
else:
print PROJECT_NAME.upper()+" devices detected...."
return
def do_uninstall():
print "Checking system...."
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_check()== 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 device_exist():
ret1, log = log_os_system("ls "+i2c_prefix+"*0070", 0)
ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0)
return not(ret1 or ret2)
if __name__ == "__main__":
main()