[Platform/Ragile] Support RA-B6510-48v8c platform (#7620)
Add new platform x86_64-ragile_ra-b6510-48v8c-r0 ASIC Vendor: Broadcom Switch ASIC: Trident 3 Port Config: 48x25G+8x100G Signed-off-by: pettershao-ragilenetworks <pettershao@ragilenetworks.com>
This commit is contained in:
parent
6931a45ecf
commit
b30cf44b93
57
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/RA-B6510-48V8C/port_config.ini
Executable file
57
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/RA-B6510-48V8C/port_config.ini
Executable file
@ -0,0 +1,57 @@
|
||||
# name lanes alias index speed admin_status
|
||||
Ethernet1 1 twentyfiveGigE0/1 0 25000 up
|
||||
Ethernet2 2 twentyfiveGigE0/2 1 25000 up
|
||||
Ethernet3 3 twentyfiveGigE0/3 2 25000 up
|
||||
Ethernet4 4 twentyfiveGigE0/4 3 25000 up
|
||||
Ethernet5 5 twentyfiveGigE0/5 4 25000 up
|
||||
Ethernet6 6 twentyfiveGigE0/6 5 25000 up
|
||||
Ethernet7 7 twentyfiveGigE0/7 6 25000 up
|
||||
Ethernet8 8 twentyfiveGigE0/8 7 25000 up
|
||||
Ethernet9 13 twentyfiveGigE0/9 8 25000 up
|
||||
Ethernet10 14 twentyfiveGigE0/10 9 25000 up
|
||||
Ethernet11 15 twentyfiveGigE0/11 10 25000 up
|
||||
Ethernet12 16 twentyfiveGigE0/12 11 25000 up
|
||||
Ethernet13 21 twentyfiveGigE0/13 12 25000 up
|
||||
Ethernet14 22 twentyfiveGigE0/14 13 25000 up
|
||||
Ethernet15 23 twentyfiveGigE0/15 14 25000 up
|
||||
Ethernet16 24 twentyfiveGigE0/16 15 25000 up
|
||||
Ethernet17 29 twentyfiveGigE0/17 16 25000 up
|
||||
Ethernet18 30 twentyfiveGigE0/18 17 25000 up
|
||||
Ethernet19 31 twentyfiveGigE0/19 18 25000 up
|
||||
Ethernet20 32 twentyfiveGigE0/20 19 25000 up
|
||||
Ethernet21 33 twentyfiveGigE0/21 20 25000 up
|
||||
Ethernet22 34 twentyfiveGigE0/22 21 25000 up
|
||||
Ethernet23 35 twentyfiveGigE0/23 22 25000 up
|
||||
Ethernet24 36 twentyfiveGigE0/24 23 25000 up
|
||||
Ethernet25 41 twentyfiveGigE0/25 24 25000 up
|
||||
Ethernet26 42 twentyfiveGigE0/26 25 25000 up
|
||||
Ethernet27 43 twentyfiveGigE0/27 26 25000 up
|
||||
Ethernet28 44 twentyfiveGigE0/28 27 25000 up
|
||||
Ethernet29 49 twentyfiveGigE0/29 28 25000 up
|
||||
Ethernet30 50 twentyfiveGigE0/30 29 25000 up
|
||||
Ethernet31 51 twentyfiveGigE0/31 30 25000 up
|
||||
Ethernet32 52 twentyfiveGigE0/32 31 25000 up
|
||||
Ethernet33 57 twentyfiveGigE0/33 32 25000 up
|
||||
Ethernet34 58 twentyfiveGigE0/34 33 25000 up
|
||||
Ethernet35 59 twentyfiveGigE0/35 34 25000 up
|
||||
Ethernet36 60 twentyfiveGigE0/36 35 25000 up
|
||||
Ethernet37 61 twentyfiveGigE0/37 36 25000 up
|
||||
Ethernet38 62 twentyfiveGigE0/38 37 25000 up
|
||||
Ethernet39 63 twentyfiveGigE0/39 38 25000 up
|
||||
Ethernet40 64 twentyfiveGigE0/40 39 25000 up
|
||||
Ethernet41 65 twentyfiveGigE0/41 40 25000 up
|
||||
Ethernet42 66 twentyfiveGigE0/42 41 25000 up
|
||||
Ethernet43 67 twentyfiveGigE0/43 42 25000 up
|
||||
Ethernet44 68 twentyfiveGigE0/44 43 25000 up
|
||||
Ethernet45 69 twentyfiveGigE0/45 44 25000 up
|
||||
Ethernet46 70 twentyfiveGigE0/46 45 25000 up
|
||||
Ethernet47 71 twentyfiveGigE0/47 46 25000 up
|
||||
Ethernet48 72 twentyfiveGigE0/48 47 25000 up
|
||||
Ethernet49 85,86,87,88 hundredGigE0/1 48 100000 up
|
||||
Ethernet50 77,78,79,80 hundredGigE0/2 49 100000 up
|
||||
Ethernet51 97,98,99,100 hundredGigE0/3 50 100000 up
|
||||
Ethernet52 93,94,95,96 hundredGigE0/4 51 100000 up
|
||||
Ethernet53 113,114,115,116 hundredGigE0/5 52 100000 up
|
||||
Ethernet54 105,106,107,108 hundredGigE0/6 53 100000 up
|
||||
Ethernet55 121,122,123,124 hundredGigE0/7 54 100000 up
|
||||
Ethernet56 125,126,127,128 hundredGigE0/8 55 100000 up
|
1
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/RA-B6510-48V8C/sai.profile
Executable file
1
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/RA-B6510-48V8C/sai.profile
Executable file
@ -0,0 +1 @@
|
||||
SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/td3-b6510-48vs8cq-48x25G+8x100G.config.bcm
|
@ -0,0 +1,569 @@
|
||||
l2_mem_entries=32768
|
||||
l2xmsg_mode=0
|
||||
l3_max_ecmp_mode=1
|
||||
l3_mem_entries=49152
|
||||
l3_alpm_enable=0
|
||||
bcm_num_cos=8
|
||||
bcm_stat_interval=2000000
|
||||
cdma_timeout_usec=3000000
|
||||
core_clock_frequency=1525
|
||||
dpp_clock_ratio=2:3
|
||||
help_cli_enable=1
|
||||
ifp_inports_support_enable=1
|
||||
ipv6_lpm_128b_enable=0x1
|
||||
#lpm_scaling_enable=1
|
||||
max_vp_lags=0
|
||||
mem_cache_enable=0
|
||||
memlist_enable=1
|
||||
miim_intr_enable=0
|
||||
module_64ports=1
|
||||
oversubscribe_mode=1
|
||||
parity_enable=1
|
||||
pbmp_gport_stack.0=0x0000000000000000000000000000000000000000000000000000000000000000
|
||||
#pbmp_xport_xe.0=0x00000000000000000000000000000000888ffffffffffff9fffffffffffffffe
|
||||
pbmp_xport_xe=0x488080808808087f9fe1e1e1fe1e1e1fe
|
||||
phy_chain_rx_lane_map_physical{1.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{1.0}=0x0123
|
||||
phy_chain_rx_lane_map_physical{5.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{5.0}=0x0123
|
||||
phy_chain_rx_lane_map_physical{13.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{13.0}=0x0123
|
||||
phy_chain_rx_lane_map_physical{21.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{21.0}=0x0123
|
||||
phy_chain_rx_lane_map_physical{29.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{29.0}=0x0123
|
||||
phy_chain_rx_lane_map_physical{33.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{33.0}=0x0123
|
||||
phy_chain_rx_lane_map_physical{41.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{41.0}=0x0123
|
||||
phy_chain_rx_lane_map_physical{49.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{49.0}=0x0123
|
||||
phy_chain_rx_lane_map_physical{57.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{57.0}=0x0123
|
||||
phy_chain_rx_lane_map_physical{61.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{61.0}=0x0123
|
||||
phy_chain_rx_lane_map_physical{65.0}=0x2301
|
||||
phy_chain_tx_lane_map_physical{65.0}=0x3210
|
||||
phy_chain_rx_lane_map_physical{69.0}=0x2301
|
||||
phy_chain_tx_lane_map_physical{69.0}=0x3210
|
||||
phy_chain_rx_lane_map_physical{77.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{77.0}=0x3210
|
||||
phy_chain_rx_lane_map_physical{85.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{85.0}=0x3210
|
||||
phy_chain_rx_lane_map_physical{93.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{93.0}=0x3210
|
||||
phy_chain_rx_lane_map_physical{97.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{97.0}=0x3210
|
||||
phy_chain_rx_lane_map_physical{105.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{105.0}=0x3210
|
||||
phy_chain_rx_lane_map_physical{113.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{113.0}=0x3210
|
||||
phy_chain_rx_lane_map_physical{121.0}=0x2031
|
||||
phy_chain_tx_lane_map_physical{121.0}=0x3210
|
||||
phy_chain_rx_lane_map_physical{125.0}=0x1032
|
||||
phy_chain_tx_lane_map_physical{125.0}=0x1203
|
||||
phy_chain_tx_polarity_flip_physical{1.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{1.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{2.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{2.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{3.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{3.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{4.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{4.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{5.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{5.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{6.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{6.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{7.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{7.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{8.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{8.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{13.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{13.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{14.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{14.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{15.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{15.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{16.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{16.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{21.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{21.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{22.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{22.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{23.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{23.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{24.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{24.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{29.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{29.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{30.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{30.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{31.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{31.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{32.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{32.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{33.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{33.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{34.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{34.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{35.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{35.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{36.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{36.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{41.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{41.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{42.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{42.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{43.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{43.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{44.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{44.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{49.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{49.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{50.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{50.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{51.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{51.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{52.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{52.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{57.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{57.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{58.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{58.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{59.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{59.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{60.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{60.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{61.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{61.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{62.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{62.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{63.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{63.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{64.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{64.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{65.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{65.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{66.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{66.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{67.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{67.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{68.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{68.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{69.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{69.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{70.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{70.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{71.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{71.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{72.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{72.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{85.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{85.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{86.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{86.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{87.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{87.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{88.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{88.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{77.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{77.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{78.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{78.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{79.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{79.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{80.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{80.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{97.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{97.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{98.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{98.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{99.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{99.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{100.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{100.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{93.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{93.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{94.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{94.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{95.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{95.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{96.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{96.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{113.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{113.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{114.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{114.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{115.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{115.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{116.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{116.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{105.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{105.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{106.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{106.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{107.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{107.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{108.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{108.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{121.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{121.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{122.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{122.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{123.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{123.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{124.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{124.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{125.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{125.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{126.0}=0x1
|
||||
phy_chain_rx_polarity_flip_physical{126.0}=0x1
|
||||
phy_chain_tx_polarity_flip_physical{127.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{127.0}=0x0
|
||||
phy_chain_tx_polarity_flip_physical{128.0}=0x0
|
||||
phy_chain_rx_polarity_flip_physical{128.0}=0x0
|
||||
port_flex_enable=1
|
||||
portmap_1=1:25
|
||||
portmap_2=2:25
|
||||
portmap_3=3:25
|
||||
portmap_4=4:25
|
||||
portmap_5=5:25
|
||||
portmap_6=6:25
|
||||
portmap_7=7:25
|
||||
portmap_8=8:25
|
||||
portmap_13=13:25
|
||||
portmap_14=14:25
|
||||
portmap_15=15:25
|
||||
portmap_16=16:25
|
||||
portmap_21=21:25
|
||||
portmap_22=22:25
|
||||
portmap_23=23:25
|
||||
portmap_24=24:25
|
||||
portmap_29=29:25
|
||||
portmap_30=30:25
|
||||
portmap_31=31:25
|
||||
portmap_32=32:25
|
||||
portmap_33=33:25
|
||||
portmap_34=34:25
|
||||
portmap_35=35:25
|
||||
portmap_36=36:25
|
||||
portmap_41=41:25
|
||||
portmap_42=42:25
|
||||
portmap_43=43:25
|
||||
portmap_44=44:25
|
||||
portmap_49=49:25
|
||||
portmap_50=50:25
|
||||
portmap_51=51:25
|
||||
portmap_52=52:25
|
||||
portmap_57=57:25
|
||||
portmap_58=58:25
|
||||
portmap_59=59:25
|
||||
portmap_60=60:25
|
||||
portmap_61=61:25
|
||||
portmap_62=62:25
|
||||
portmap_63=63:25
|
||||
portmap_64=64:25
|
||||
portmap_67=65:25
|
||||
portmap_68=66:25
|
||||
portmap_69=67:25
|
||||
portmap_70=68:25
|
||||
portmap_71=69:25
|
||||
portmap_72=70:25
|
||||
portmap_73=71:25
|
||||
portmap_74=72:25
|
||||
portmap_79=77:100
|
||||
portmap_87=85:100
|
||||
portmap_95=93:100
|
||||
portmap_99=97:100
|
||||
portmap_107=105:100
|
||||
portmap_115=113:100
|
||||
portmap_123=121:100
|
||||
portmap_127=125:100
|
||||
|
||||
dport_map_port_1=1
|
||||
dport_map_port_2=2
|
||||
dport_map_port_3=3
|
||||
dport_map_port_4=4
|
||||
dport_map_port_5=5
|
||||
dport_map_port_6=6
|
||||
dport_map_port_7=7
|
||||
dport_map_port_8=8
|
||||
dport_map_port_13=9
|
||||
dport_map_port_14=10
|
||||
dport_map_port_15=11
|
||||
dport_map_port_16=12
|
||||
dport_map_port_21=13
|
||||
dport_map_port_22=14
|
||||
dport_map_port_23=15
|
||||
dport_map_port_24=16
|
||||
dport_map_port_29=17
|
||||
dport_map_port_30=18
|
||||
dport_map_port_31=19
|
||||
dport_map_port_32=20
|
||||
dport_map_port_33=21
|
||||
dport_map_port_34=22
|
||||
dport_map_port_35=23
|
||||
dport_map_port_36=24
|
||||
dport_map_port_41=25
|
||||
dport_map_port_42=26
|
||||
dport_map_port_43=27
|
||||
dport_map_port_44=28
|
||||
dport_map_port_49=29
|
||||
dport_map_port_50=30
|
||||
dport_map_port_51=31
|
||||
dport_map_port_52=32
|
||||
dport_map_port_57=33
|
||||
dport_map_port_58=34
|
||||
dport_map_port_59=35
|
||||
dport_map_port_60=36
|
||||
dport_map_port_61=37
|
||||
dport_map_port_62=38
|
||||
dport_map_port_63=39
|
||||
dport_map_port_64=40
|
||||
dport_map_port_67=41
|
||||
dport_map_port_68=42
|
||||
dport_map_port_69=43
|
||||
dport_map_port_70=44
|
||||
dport_map_port_71=45
|
||||
dport_map_port_72=46
|
||||
dport_map_port_73=47
|
||||
dport_map_port_74=48
|
||||
dport_map_port_87=49
|
||||
dport_map_port_79=50
|
||||
dport_map_port_99=51
|
||||
dport_map_port_95=52
|
||||
dport_map_port_115=53
|
||||
dport_map_port_107=54
|
||||
dport_map_port_123=55
|
||||
dport_map_port_127=56
|
||||
|
||||
serdes_preemphasis_lane0_1=0x0f480d
|
||||
serdes_preemphasis_lane1_1=0x0f480d
|
||||
serdes_preemphasis_lane2_1=0x0f480d
|
||||
serdes_preemphasis_lane3_1=0x0f480d
|
||||
serdes_preemphasis_lane0_2=0x0f480d
|
||||
serdes_preemphasis_lane1_2=0x0f480d
|
||||
serdes_preemphasis_lane2_2=0x0f480d
|
||||
serdes_preemphasis_lane3_2=0x0f480d
|
||||
serdes_preemphasis_lane0_3=0x0f480d
|
||||
serdes_preemphasis_lane1_3=0x0f480d
|
||||
serdes_preemphasis_lane2_3=0x0f480d
|
||||
serdes_preemphasis_lane3_3=0x0f480d
|
||||
serdes_preemphasis_lane0_4=0x0f480d
|
||||
serdes_preemphasis_lane1_4=0x0f480d
|
||||
serdes_preemphasis_lane2_4=0x0f480d
|
||||
serdes_preemphasis_lane3_4=0x0f480d
|
||||
serdes_preemphasis_lane0_5=0x0f480d
|
||||
serdes_preemphasis_lane1_5=0x0f480d
|
||||
serdes_preemphasis_lane2_5=0x0f480d
|
||||
serdes_preemphasis_lane3_5=0x0f480d
|
||||
serdes_preemphasis_lane0_6=0x0f480d
|
||||
serdes_preemphasis_lane1_6=0x0f480d
|
||||
serdes_preemphasis_lane2_6=0x0f480d
|
||||
serdes_preemphasis_lane3_6=0x0f480d
|
||||
serdes_preemphasis_lane0_7=0x0d4b0c
|
||||
serdes_preemphasis_lane1_7=0x0d4b0c
|
||||
serdes_preemphasis_lane2_7=0x0d4b0c
|
||||
serdes_preemphasis_lane3_7=0x0d4b0c
|
||||
serdes_preemphasis_lane0_8=0x0d4b0c
|
||||
serdes_preemphasis_lane1_8=0x0d4b0c
|
||||
serdes_preemphasis_lane2_8=0x0d4b0c
|
||||
serdes_preemphasis_lane3_8=0x0d4b0c
|
||||
serdes_preemphasis_lane0_13=0x0d4b0c
|
||||
serdes_preemphasis_lane1_13=0x0d4b0c
|
||||
serdes_preemphasis_lane2_13=0x0d4b0c
|
||||
serdes_preemphasis_lane3_13=0x0d4b0c
|
||||
serdes_preemphasis_lane0_14=0x0d4b0c
|
||||
serdes_preemphasis_lane1_14=0x0d4b0c
|
||||
serdes_preemphasis_lane2_14=0x0d4b0c
|
||||
serdes_preemphasis_lane3_14=0x0d4b0c
|
||||
serdes_preemphasis_lane0_15=0x0d4b0c
|
||||
serdes_preemphasis_lane1_15=0x0d4b0c
|
||||
serdes_preemphasis_lane2_15=0x0d4b0c
|
||||
serdes_preemphasis_lane3_15=0x0d4b0c
|
||||
serdes_preemphasis_lane0_16=0x0d4b0c
|
||||
serdes_preemphasis_lane1_16=0x0d4b0c
|
||||
serdes_preemphasis_lane2_16=0x0d4b0c
|
||||
serdes_preemphasis_lane3_16=0x0d4b0c
|
||||
serdes_preemphasis_lane0_21=0x0d4b0c
|
||||
serdes_preemphasis_lane1_21=0x0d4b0c
|
||||
serdes_preemphasis_lane2_21=0x0d4b0c
|
||||
serdes_preemphasis_lane3_21=0x0d4b0c
|
||||
serdes_preemphasis_lane0_22=0x0d4b0c
|
||||
serdes_preemphasis_lane1_22=0x0d4b0c
|
||||
serdes_preemphasis_lane2_22=0x0d4b0c
|
||||
serdes_preemphasis_lane3_22=0x0d4b0c
|
||||
serdes_preemphasis_lane0_23=0x0d4b0c
|
||||
serdes_preemphasis_lane1_23=0x0d4b0c
|
||||
serdes_preemphasis_lane2_23=0x0d4b0c
|
||||
serdes_preemphasis_lane3_23=0x0d4b0c
|
||||
serdes_preemphasis_lane0_24=0x0d4b0c
|
||||
serdes_preemphasis_lane1_24=0x0d4b0c
|
||||
serdes_preemphasis_lane2_24=0x0d4b0c
|
||||
serdes_preemphasis_lane3_24=0x0d4b0c
|
||||
serdes_preemphasis_lane0_29=0x0d4b0c
|
||||
serdes_preemphasis_lane1_29=0x0d4b0c
|
||||
serdes_preemphasis_lane2_29=0x0d4b0c
|
||||
serdes_preemphasis_lane3_29=0x0d4b0c
|
||||
serdes_preemphasis_lane0_30=0x0d4b0c
|
||||
serdes_preemphasis_lane1_30=0x0d4b0c
|
||||
serdes_preemphasis_lane2_30=0x0d4b0c
|
||||
serdes_preemphasis_lane3_30=0x0d4b0c
|
||||
serdes_preemphasis_lane0_31=0x0d4b0c
|
||||
serdes_preemphasis_lane1_31=0x0d4b0c
|
||||
serdes_preemphasis_lane2_31=0x0d4b0c
|
||||
serdes_preemphasis_lane3_31=0x0d4b0c
|
||||
serdes_preemphasis_lane0_32=0x0d4b0c
|
||||
serdes_preemphasis_lane1_32=0x0d4b0c
|
||||
serdes_preemphasis_lane2_32=0x0d4b0c
|
||||
serdes_preemphasis_lane3_32=0x0d4b0c
|
||||
serdes_preemphasis_lane0_33=0x0d4b0c
|
||||
serdes_preemphasis_lane1_33=0x0d4b0c
|
||||
serdes_preemphasis_lane2_33=0x0d4b0c
|
||||
serdes_preemphasis_lane3_33=0x0d4b0c
|
||||
serdes_preemphasis_lane0_34=0x0d4b0c
|
||||
serdes_preemphasis_lane1_34=0x0d4b0c
|
||||
serdes_preemphasis_lane2_34=0x0d4b0c
|
||||
serdes_preemphasis_lane3_34=0x0d4b0c
|
||||
serdes_preemphasis_lane0_35=0x0d4b0c
|
||||
serdes_preemphasis_lane1_35=0x0d4b0c
|
||||
serdes_preemphasis_lane2_35=0x0d4b0c
|
||||
serdes_preemphasis_lane3_35=0x0d4b0c
|
||||
serdes_preemphasis_lane0_36=0x0d4b0c
|
||||
serdes_preemphasis_lane1_36=0x0d4b0c
|
||||
serdes_preemphasis_lane2_36=0x0d4b0c
|
||||
serdes_preemphasis_lane3_36=0x0d4b0c
|
||||
serdes_preemphasis_lane0_41=0x0d4b0c
|
||||
serdes_preemphasis_lane1_41=0x0d4b0c
|
||||
serdes_preemphasis_lane2_41=0x0d4b0c
|
||||
serdes_preemphasis_lane3_41=0x0d4b0c
|
||||
serdes_preemphasis_lane0_42=0x0d4b0c
|
||||
serdes_preemphasis_lane1_42=0x0d4b0c
|
||||
serdes_preemphasis_lane2_42=0x0d4b0c
|
||||
serdes_preemphasis_lane3_42=0x0d4b0c
|
||||
serdes_preemphasis_lane0_43=0x0d4b0c
|
||||
serdes_preemphasis_lane1_43=0x0d4b0c
|
||||
serdes_preemphasis_lane2_43=0x0d4b0c
|
||||
serdes_preemphasis_lane3_43=0x0d4b0c
|
||||
serdes_preemphasis_lane0_44=0x0d4b0c
|
||||
serdes_preemphasis_lane1_44=0x0d4b0c
|
||||
serdes_preemphasis_lane2_44=0x0d4b0c
|
||||
serdes_preemphasis_lane3_44=0x0d4b0c
|
||||
serdes_preemphasis_lane0_49=0x0d4b0c
|
||||
serdes_preemphasis_lane1_49=0x0d4b0c
|
||||
serdes_preemphasis_lane2_49=0x0d4b0c
|
||||
serdes_preemphasis_lane3_49=0x0d4b0c
|
||||
serdes_preemphasis_lane0_50=0x0d4b0c
|
||||
serdes_preemphasis_lane1_50=0x0d4b0c
|
||||
serdes_preemphasis_lane2_50=0x0d4b0c
|
||||
serdes_preemphasis_lane3_50=0x0d4b0c
|
||||
serdes_preemphasis_lane0_51=0x0d4b0c
|
||||
serdes_preemphasis_lane1_51=0x0d4b0c
|
||||
serdes_preemphasis_lane2_51=0x0d4b0c
|
||||
serdes_preemphasis_lane3_51=0x0d4b0c
|
||||
serdes_preemphasis_lane0_52=0x0d4b0c
|
||||
serdes_preemphasis_lane1_52=0x0d4b0c
|
||||
serdes_preemphasis_lane2_52=0x0d4b0c
|
||||
serdes_preemphasis_lane3_52=0x0d4b0c
|
||||
serdes_preemphasis_lane0_57=0x0d4b0c
|
||||
serdes_preemphasis_lane1_57=0x0d4b0c
|
||||
serdes_preemphasis_lane2_57=0x0d4b0c
|
||||
serdes_preemphasis_lane3_57=0x0d4b0c
|
||||
serdes_preemphasis_lane0_58=0x0d4b0c
|
||||
serdes_preemphasis_lane1_58=0x0d4b0c
|
||||
serdes_preemphasis_lane2_58=0x0d4b0c
|
||||
serdes_preemphasis_lane3_58=0x0d4b0c
|
||||
serdes_preemphasis_lane0_59=0x0d4b0c
|
||||
serdes_preemphasis_lane1_59=0x0d4b0c
|
||||
serdes_preemphasis_lane2_59=0x0d4b0c
|
||||
serdes_preemphasis_lane3_59=0x0d4b0c
|
||||
serdes_preemphasis_lane0_60=0x0d4b0c
|
||||
serdes_preemphasis_lane1_60=0x0d4b0c
|
||||
serdes_preemphasis_lane2_60=0x0d4b0c
|
||||
serdes_preemphasis_lane3_60=0x0d4b0c
|
||||
serdes_preemphasis_lane0_61=0x0d4b0c
|
||||
serdes_preemphasis_lane1_61=0x0d4b0c
|
||||
serdes_preemphasis_lane2_61=0x0d4b0c
|
||||
serdes_preemphasis_lane3_61=0x0d4b0c
|
||||
serdes_preemphasis_lane0_62=0x0d4b0c
|
||||
serdes_preemphasis_lane1_62=0x0d4b0c
|
||||
serdes_preemphasis_lane2_62=0x0d4b0c
|
||||
serdes_preemphasis_lane3_62=0x0d4b0c
|
||||
serdes_preemphasis_lane0_63=0x0d4b0c
|
||||
serdes_preemphasis_lane1_63=0x0d4b0c
|
||||
serdes_preemphasis_lane2_63=0x0d4b0c
|
||||
serdes_preemphasis_lane3_63=0x0d4b0c
|
||||
serdes_preemphasis_lane0_64=0x0d4b0c
|
||||
serdes_preemphasis_lane1_64=0x0d4b0c
|
||||
serdes_preemphasis_lane2_64=0x0d4b0c
|
||||
serdes_preemphasis_lane3_64=0x0d4b0c
|
||||
serdes_preemphasis_lane0_67=0x0d4b0c
|
||||
serdes_preemphasis_lane1_67=0x0d4b0c
|
||||
serdes_preemphasis_lane2_67=0x0d4b0c
|
||||
serdes_preemphasis_lane3_67=0x0d4b0c
|
||||
serdes_preemphasis_lane0_68=0x0d4b0c
|
||||
serdes_preemphasis_lane1_68=0x0d4b0c
|
||||
serdes_preemphasis_lane2_68=0x0d4b0c
|
||||
serdes_preemphasis_lane3_68=0x0d4b0c
|
||||
serdes_preemphasis_lane0_69=0x0d4b0c
|
||||
serdes_preemphasis_lane1_69=0x0d4b0c
|
||||
serdes_preemphasis_lane2_69=0x0d4b0c
|
||||
serdes_preemphasis_lane3_69=0x0d4b0c
|
||||
serdes_preemphasis_lane0_70=0x0d4b0c
|
||||
serdes_preemphasis_lane1_70=0x0d4b0c
|
||||
serdes_preemphasis_lane2_70=0x0d4b0c
|
||||
serdes_preemphasis_lane3_70=0x0d4b0c
|
||||
serdes_preemphasis_lane0_71=0x0d4b0c
|
||||
serdes_preemphasis_lane1_71=0x0d4b0c
|
||||
serdes_preemphasis_lane2_71=0x0d4b0c
|
||||
serdes_preemphasis_lane3_71=0x0d4b0c
|
||||
serdes_preemphasis_lane0_72=0x0d4b0c
|
||||
serdes_preemphasis_lane1_72=0x0d4b0c
|
||||
serdes_preemphasis_lane2_72=0x0d4b0c
|
||||
serdes_preemphasis_lane3_72=0x0d4b0c
|
||||
serdes_preemphasis_lane0_73=0x0d4b0c
|
||||
serdes_preemphasis_lane1_73=0x0d4b0c
|
||||
serdes_preemphasis_lane2_73=0x0d4b0c
|
||||
serdes_preemphasis_lane3_73=0x0d4b0c
|
||||
serdes_preemphasis_lane0_74=0x0d4b0c
|
||||
serdes_preemphasis_lane1_74=0x0d4b0c
|
||||
serdes_preemphasis_lane2_74=0x0d4b0c
|
||||
serdes_preemphasis_lane3_74=0x0d4b0c
|
||||
serdes_preemphasis_lane0_87=0x0d4b0c
|
||||
serdes_preemphasis_lane1_87=0x0d4b0c
|
||||
serdes_preemphasis_lane2_87=0x0d4b0c
|
||||
serdes_preemphasis_lane3_87=0x0d4b0c
|
||||
serdes_preemphasis_lane0_79=0x0d4b0c
|
||||
serdes_preemphasis_lane1_79=0x0d4b0c
|
||||
serdes_preemphasis_lane2_79=0x0d4b0c
|
||||
serdes_preemphasis_lane3_79=0x0d4b0c
|
||||
serdes_preemphasis_lane0_99=0x0d4b0c
|
||||
serdes_preemphasis_lane1_99=0x0d4b0c
|
||||
serdes_preemphasis_lane2_99=0x0d4b0c
|
||||
serdes_preemphasis_lane3_99=0x0d4b0c
|
||||
serdes_preemphasis_lane0_95=0x0d4b0c
|
||||
serdes_preemphasis_lane1_95=0x0d4b0c
|
||||
serdes_preemphasis_lane2_95=0x0d4b0c
|
||||
serdes_preemphasis_lane3_95=0x0d4b0c
|
||||
serdes_preemphasis_lane0_115=0x0f480d
|
||||
serdes_preemphasis_lane1_115=0x0f480d
|
||||
serdes_preemphasis_lane2_115=0x0f480d
|
||||
serdes_preemphasis_lane3_115=0x0f480d
|
||||
serdes_preemphasis_lane0_107=0x0f480d
|
||||
serdes_preemphasis_lane1_107=0x0f480d
|
||||
serdes_preemphasis_lane2_107=0x0f480d
|
||||
serdes_preemphasis_lane3_107=0x0f480d
|
||||
serdes_preemphasis_lane0_123=0x0f480d
|
||||
serdes_preemphasis_lane1_123=0x0f480d
|
||||
serdes_preemphasis_lane2_123=0x0f480d
|
||||
serdes_preemphasis_lane3_123=0x0f480d
|
||||
serdes_preemphasis_lane0_127=0x0f480d
|
||||
serdes_preemphasis_lane1_127=0x0f480d
|
||||
serdes_preemphasis_lane2_127=0x0f480d
|
||||
serdes_preemphasis_lane3_127=0x0f480d
|
||||
|
||||
reglist_enable=1
|
||||
scache_filename=/tmp/scache
|
||||
schan_intr_enable=0
|
||||
stable_size=0x5500000
|
||||
tdma_timeout_usec=3000000
|
BIN
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/custom_led.bin
Normal file
BIN
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/custom_led.bin
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
||||
B6510-48VS8CQ t1
|
122
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/dev.xml
Executable file
122
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/dev.xml
Executable file
@ -0,0 +1,122 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
### type 1 result/1000
|
||||
type 2 result/100
|
||||
type 3 read bit
|
||||
### property need check must add int front
|
||||
-->
|
||||
<catalog>
|
||||
<fans>
|
||||
<fan id="fan1" >
|
||||
<property name="present" location="2-0037/fan_present" type="3" bit="0" decode="fanpresent" default="0"/>
|
||||
<property name="status" location="2-0037/fan_status" type="3" bit="0" decode="fanstatus" default="1"/>
|
||||
<property name="hw_version" location="3-0053/fan_hw_version" type="0" bit="0"/>
|
||||
<property name="fan_type" location="3-0053/fan_type"/>
|
||||
<property name="sn" location="3-0053/fan_sn"/>
|
||||
<property name="Speed" location="2-0037/hwmon/*/fan1_input"/>
|
||||
</fan>
|
||||
<fan id="fan2" >
|
||||
<property name="present" location="2-0037/fan_present" type="3" bit="1" decode="fanpresent" default="0" />
|
||||
<property name="status" location="2-0037/fan_status" type="3" bit="1" decode="fanstatus" default="1"/>
|
||||
<property name="hw_version" location="4-0053/fan_hw_version" type="0" bit="0"/>
|
||||
<property name="fan_type" location="4-0053/fan_type"/>
|
||||
<property name="sn" location="4-0053/fan_sn"/>
|
||||
<property name="Speed" location="2-0037/hwmon/*/fan2_input"/>
|
||||
</fan>
|
||||
<fan id="fan3" >
|
||||
<property name="present" location="2-0037/fan_present" type="3" bit="2" decode="fanpresent" default="0"/>
|
||||
<property name="status" location="2-0037/fan_status" type="3" bit="2" decode="fanstatus" default="1"/>
|
||||
<property name="hw_version" location="5-0053/fan_hw_version" type="0" bit="0"/>
|
||||
<property name="fan_type" location="5-0053/fan_type"/>
|
||||
<property name="sn" location="5-0053/fan_sn"/>
|
||||
<property name="Speed" location="2-0037/hwmon/*/fan3_input"/>
|
||||
</fan>
|
||||
<fan id="fan4" >
|
||||
<property name="present" location="2-0037/fan_present" type="3" bit="3" decode="fanpresent" default="0"/>
|
||||
<property name="status" location="2-0037/fan_status" type="3" bit="3" decode="fanstatus" default="1"/>
|
||||
<property name="hw_version" location="6-0053/fan_hw_version" type="0" bit="0"/>
|
||||
<property name="fan_type" location="6-0053/fan_type"/>
|
||||
<property name="sn" location="6-0053/fan_sn"/>
|
||||
<property name="Speed" location="2-0037/hwmon/*/fan4_input"/>
|
||||
</fan>
|
||||
</fans>
|
||||
<temps>
|
||||
<temp id="air_inlet" >
|
||||
<property name="temp1_input" location="/2-0048/hwmon/*/temp1_input" type="1"/>
|
||||
<property name="temp1_max" location="/2-0048/hwmon/*/temp1_max" type="1" />
|
||||
<property name="temp1_max_hyst" location="/2-0048/hwmon/*/temp1_max_hyst" type="1" />
|
||||
</temp>
|
||||
<temp id="air_outlet" >
|
||||
<property name="temp1_input" location="/2-0049/hwmon/*/temp1_input" type="1" />
|
||||
<property name="temp1_max" location="/2-0049/hwmon/*/temp1_max" type="1" />
|
||||
<property name="temp1_max_hyst" location="/2-0049/hwmon/*/temp1_max_hyst" type="1" />
|
||||
</temp>
|
||||
<temp id="air_hotlet" >
|
||||
<property name="temp1_input" location="/2-004a/hwmon/*/temp1_input" type="1"/>
|
||||
<property name="temp1_max" location="/2-004a/hwmon/*/temp1_max" type="1"/>
|
||||
<property name="temp1_max_hyst" location="/2-004a/hwmon/*/temp1_max_hyst" type="1"/>
|
||||
</temp>
|
||||
</temps>
|
||||
<psus>
|
||||
<psu id="psu1" >
|
||||
<property name="present" location="2-0037/psu_status" type="3" bit="0" decode="psucheck" default="0"/>
|
||||
<property name="status" location="2-0037/psu_status" type="3" bit="1" decode="psustatus" default="1"/>
|
||||
<property name="sn" location="7-0050/psu_sn" />
|
||||
<property name="in_current" location="7-0058/hwmon/*/curr1_input" type="1" />
|
||||
<property name="in_voltage" location="7-0058/hwmon/*/in1_input" type="1"/>
|
||||
<property name="out_voltage" location="7-0058/hwmon/*/in2_input" type="1" />
|
||||
<property name="out_current" location="7-0058/hwmon/*/curr2_input" type="1" />
|
||||
<property name="temp" location="7-0058/hwmon/*/temp1_input" type="1"/>
|
||||
<property name="hw" location="7-0050/psu_hw" />
|
||||
<property name="type1" location="7-0050/psu_type" decode="psutype"/>
|
||||
<property name="fan_speed" location="7-0058/hwmon/*/fan1_input" />
|
||||
<property name="in_power" location="7-0058/hwmon/*/power1_input" type="5"/>
|
||||
<property name="out_power" location="7-0058/hwmon/*/power2_input" type="5"/>
|
||||
</psu>
|
||||
<psu id="psu2" >
|
||||
<property name="present" location="2-0037/psu_status" type="3" bit="4" decode="psucheck" default="0"/>
|
||||
<property name="status" location="2-0037/psu_status" type="3" bit="5" decode="psustatus" default="1"/>
|
||||
<property name="sn" location="8-0053/psu_sn" />
|
||||
<property name="in_current" location="8-005b/hwmon/*/curr1_input" type="1" />
|
||||
<property name="in_voltage" location="8-005b/hwmon/*/in1_input" type="1"/>
|
||||
<property name="out_voltage" location="8-005b/hwmon/*/in2_input" type="1" />
|
||||
<property name="out_current" location="8-005b/hwmon/*/curr2_input" type="1" />
|
||||
<property name="temp" location="8-005b/hwmon/*/temp1_input" type="1"/>
|
||||
<property name="hw" location="8-0053/psu_hw" />
|
||||
<property name="type1" location="8-0053/psu_type" decode="psutype"/>
|
||||
<property name="fan_speed" location="8-005b/hwmon/*/fan1_input" />
|
||||
<property name="in_power" location="8-005b/hwmon/*/power1_input" type="5"/>
|
||||
<property name="out_power" location="8-005b/hwmon/*/power2_input" type="5"/>
|
||||
</psu>
|
||||
</psus>
|
||||
<cpus location="/sys/class/hwmon/hwmon0"/>
|
||||
<ports_rx>
|
||||
<mgmt_rx id="mgmt" sender="eth0" >
|
||||
<property name="mgmt" location="/eth0/statistics/rx_packets" type="4"/>
|
||||
</mgmt_rx>
|
||||
</ports_rx>
|
||||
<decode>
|
||||
<fanpresent>
|
||||
<code key="1" value="ABSENT"/>
|
||||
<code key="0" value="PRESENT"/>
|
||||
</fanpresent>
|
||||
<fanstatus>
|
||||
<code key="1" value="OK"/>
|
||||
<code key="0" value="NOT OK"/>
|
||||
</fanstatus>
|
||||
<psucheck>
|
||||
<code key="1" value="ABSENT"/>
|
||||
<code key="0" value="PRESENT"/>
|
||||
</psucheck>
|
||||
<psustatus>
|
||||
<code key="1" value="OK"/>
|
||||
<code key="0" value="NOT OK"/>
|
||||
</psustatus>
|
||||
|
||||
<psutype>
|
||||
<code key="CSU550AP-3-300" value="RG-PA550I-F"/>
|
||||
<code key="DPS-550AB-39 A" value="RG-PA550I-F"/>
|
||||
</psutype>
|
||||
</decode>
|
||||
</catalog>
|
||||
|
1
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/installer.conf
Executable file
1
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/installer.conf
Executable file
@ -0,0 +1 @@
|
||||
CONSOLE_SPEED=115200
|
7
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/led_proc_init.soc
Executable file
7
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/led_proc_init.soc
Executable file
@ -0,0 +1,7 @@
|
||||
m0 load 0 0x3800 /usr/share/sonic/platform/custom_led.bin
|
||||
|
||||
led auto on
|
||||
|
||||
led start
|
||||
|
||||
linkscan SwPortBitMap=xe,ce
|
244
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/monitor.py
Executable file
244
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/monitor.py
Executable file
@ -0,0 +1,244 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
"""
|
||||
* onboard temperature sensors
|
||||
* FAN trays
|
||||
* PSU
|
||||
"""
|
||||
import os
|
||||
import xml.etree.ElementTree as ET
|
||||
import glob
|
||||
|
||||
MAILBOX_DIR = "/sys/bus/i2c/devices/"
|
||||
PORTS_DIR = "/sys/class/net/"
|
||||
CONFIG_NAME = "dev.xml"
|
||||
|
||||
|
||||
def getPMCreg(location):
|
||||
retval = "ERR"
|
||||
if not os.path.isfile(location):
|
||||
return "%s %s notfound" % (retval, location)
|
||||
try:
|
||||
with open(location, "r") as fd:
|
||||
retval = fd.read()
|
||||
except Exception:
|
||||
pass
|
||||
# logging.error("Unable to open ", location, "file !")
|
||||
|
||||
retval = retval.rstrip("\r\n")
|
||||
retval = retval.lstrip(" ")
|
||||
return retval
|
||||
|
||||
|
||||
# Get a mailbox register
|
||||
def get_pmc_register(reg_name):
|
||||
retval = "ERR"
|
||||
if reg_name[0:4] == "/rif" or reg_name[0:4] == "/ma1" or reg_name[0:4] == "/eth":
|
||||
mb_reg_file = PORTS_DIR + reg_name
|
||||
else:
|
||||
mb_reg_file = MAILBOX_DIR + reg_name
|
||||
filepath = glob.glob(mb_reg_file)
|
||||
if len(filepath) == 0:
|
||||
return "%s %s notfound" % (retval, mb_reg_file)
|
||||
mb_reg_file = filepath[0] # use first found patch
|
||||
if not os.path.isfile(mb_reg_file):
|
||||
return "%s %s notfound" % (retval, mb_reg_file)
|
||||
try:
|
||||
with open(mb_reg_file, "r") as fd:
|
||||
retval = fd.read()
|
||||
except Exception:
|
||||
pass
|
||||
# logging.error("Unable to open ", mb_reg_file, "file !")
|
||||
|
||||
retval = retval.rstrip("\r\n")
|
||||
retval = retval.lstrip(" ")
|
||||
return retval
|
||||
|
||||
|
||||
class checktype:
|
||||
def __init__(self, test1):
|
||||
self.test1 = test1
|
||||
|
||||
@staticmethod
|
||||
def check(name, location, bit, value, tips, err1):
|
||||
psu_status = int(get_pmc_register(location), 16)
|
||||
val = (psu_status & (1 << bit)) >> bit
|
||||
if val != value:
|
||||
err1["errmsg"] = tips
|
||||
err1["code"] = -1
|
||||
return -1
|
||||
else:
|
||||
err1["errmsg"] = "none"
|
||||
err1["code"] = 0
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def getValue(location, bit, type):
|
||||
value_t = get_pmc_register(location)
|
||||
if value_t.startswith("ERR"):
|
||||
return value_t
|
||||
if type == 1:
|
||||
return float(value_t) / 1000
|
||||
elif type == 2:
|
||||
return float(value_t) / 100
|
||||
elif type == 3:
|
||||
psu_status = int(value_t, 16)
|
||||
return (psu_status & (1 << bit)) >> bit
|
||||
elif type == 4:
|
||||
return int(value_t, 10)
|
||||
else:
|
||||
return value_t
|
||||
|
||||
# temperature
|
||||
@staticmethod
|
||||
def getTemp(self, name, location, ret_t):
|
||||
ret2 = self.getValue(location + "temp1_input", " ", 1)
|
||||
ret3 = self.getValue(location + "temp1_max", " ", 1)
|
||||
ret4 = self.getValue(location + "temp1_max_hyst", " ", 1)
|
||||
ret_t["temp1_input"] = ret2
|
||||
ret_t["temp1_max"] = ret3
|
||||
ret_t["temp1_max_hyst"] = ret4
|
||||
|
||||
@staticmethod
|
||||
def getLM75(name, location, result):
|
||||
c1 = checktype
|
||||
r1 = {}
|
||||
c1.getTemp(c1, name, location, r1)
|
||||
result[name] = r1
|
||||
|
||||
|
||||
class status:
|
||||
def __init__(self, productname):
|
||||
self.productname = productname
|
||||
|
||||
@staticmethod
|
||||
def getETroot(filename):
|
||||
tree = ET.parse(filename)
|
||||
root = tree.getroot()
|
||||
return root
|
||||
|
||||
@staticmethod
|
||||
def getDecodValue(collection, decode):
|
||||
decodes = collection.find("decode")
|
||||
testdecode = decodes.find(decode)
|
||||
test = {}
|
||||
for neighbor in testdecode.iter("code"):
|
||||
test[neighbor.attrib["key"]] = neighbor.attrib["value"]
|
||||
return test
|
||||
|
||||
@staticmethod
|
||||
def getfileValue(location):
|
||||
return checktype.getValue(location, " ", " ")
|
||||
|
||||
@staticmethod
|
||||
def getETValue(a, filename, tagname):
|
||||
root = status.getETroot(filename)
|
||||
for neighbor in root.iter(tagname):
|
||||
prob_t = {}
|
||||
prob_t = neighbor.attrib
|
||||
prob_t["errcode"] = 0
|
||||
prob_t["errmsg"] = ""
|
||||
for pros in neighbor.iter("property"):
|
||||
ret = dict(neighbor.attrib.items() + pros.attrib.items())
|
||||
if "type" not in ret.keys():
|
||||
val = "0"
|
||||
else:
|
||||
val = ret["type"]
|
||||
if "bit" not in ret.keys():
|
||||
bit = "0"
|
||||
else:
|
||||
bit = ret["bit"]
|
||||
s = checktype.getValue(ret["location"], int(bit), int(val))
|
||||
if isinstance(s, str) and s.startswith("ERR"):
|
||||
prob_t["errcode"] = -1
|
||||
prob_t["errmsg"] = s
|
||||
if "default" in ret.keys():
|
||||
rt = status.getDecodValue(root, ret["decode"])
|
||||
prob_t["errmsg"] = rt[str(s)]
|
||||
if str(s) != ret["default"]:
|
||||
prob_t["errcode"] = -1
|
||||
break
|
||||
else:
|
||||
if "decode" in ret.keys():
|
||||
rt = status.getDecodValue(root, ret["decode"])
|
||||
if (
|
||||
ret["decode"] == "psutype"
|
||||
and s.replace("\x00", "").rstrip() not in rt.keys()
|
||||
): # PSU type detect
|
||||
prob_t["errcode"] = -1
|
||||
prob_t["errmsg"] = "%s" % ("The power type does not match, please check whether the power is correct!")
|
||||
else:
|
||||
s = rt[str(s).replace("\x00", "").rstrip()]
|
||||
name = ret["name"]
|
||||
prob_t[name] = str(s)
|
||||
a.append(prob_t)
|
||||
|
||||
@staticmethod
|
||||
def getCPUValue(a, filename, tagname):
|
||||
root = status.getETroot(filename)
|
||||
for neighbor in root.iter(tagname):
|
||||
location = neighbor.attrib["location"]
|
||||
L = []
|
||||
for dirpath, dirnames, filenames in os.walk(location):
|
||||
for file in filenames:
|
||||
if file.endswith("input"):
|
||||
L.append(os.path.join(dirpath, file))
|
||||
L = sorted(L, reverse=False)
|
||||
for i in range(len(L)):
|
||||
prob_t = {}
|
||||
prob_t["name"] = getPMCreg("%s/temp%d_label" % (location, i + 1))
|
||||
prob_t["temp"] = (
|
||||
float(getPMCreg("%s/temp%d_input" % (location, i + 1))) / 1000
|
||||
)
|
||||
prob_t["alarm"] = (
|
||||
float(getPMCreg("%s/temp%d_crit_alarm" % (location, i + 1))) / 1000
|
||||
)
|
||||
prob_t["crit"] = (
|
||||
float(getPMCreg("%s/temp%d_crit" % (location, i + 1))) / 1000
|
||||
)
|
||||
prob_t["max"] = float(getPMCreg("%s/temp%d_max" % (location, i + 1))) / 1000
|
||||
a.append(prob_t)
|
||||
|
||||
@staticmethod
|
||||
def getFileName():
|
||||
return os.path.dirname(os.path.realpath(__file__)) + "/" + CONFIG_NAME
|
||||
|
||||
@staticmethod
|
||||
def getFan(ret):
|
||||
_filename = status.getFileName()
|
||||
_tagname = "fan"
|
||||
status.getvalue(ret, _filename, _tagname)
|
||||
|
||||
@staticmethod
|
||||
def checkFan(ret):
|
||||
_filename = status.getFileName()
|
||||
# _filename = "/usr/local/bin/" + status.getFileName()
|
||||
_tagname = "fan"
|
||||
status.getETValue(ret, _filename, _tagname)
|
||||
|
||||
@staticmethod
|
||||
def getTemp(ret):
|
||||
_filename = status.getFileName()
|
||||
# _filename = "/usr/local/bin/" + status.getFileName()
|
||||
_tagname = "temp"
|
||||
status.getETValue(ret, _filename, _tagname)
|
||||
|
||||
@staticmethod
|
||||
def getPsu(ret):
|
||||
_filename = status.getFileName()
|
||||
# _filename = "/usr/local/bin/" + status.getFileName()
|
||||
_tagname = "psu"
|
||||
status.getETValue(ret, _filename, _tagname)
|
||||
|
||||
@staticmethod
|
||||
def getcputemp(ret):
|
||||
_filename = status.getFileName()
|
||||
_tagname = "cpus"
|
||||
status.getCPUValue(ret, _filename, _tagname)
|
||||
|
||||
@staticmethod
|
||||
def getMgmtRx(ret):
|
||||
_filename = status.getFileName()
|
||||
# _filename = "/usr/local/bin/" + status.getFileName()
|
||||
_tagname = "mgmt_rx"
|
||||
status.getETValue(ret, _filename, _tagname)
|
429
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pcie.yaml
Normal file
429
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pcie.yaml
Normal file
@ -0,0 +1,429 @@
|
||||
- bus: '00'
|
||||
dev: '00'
|
||||
fn: '0'
|
||||
id: 6f00
|
||||
name: 'Host bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D DMI2
|
||||
(rev 03)'
|
||||
- bus: '00'
|
||||
dev: '01'
|
||||
fn: '0'
|
||||
id: 6f02
|
||||
name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI
|
||||
Express Root Port 1 (rev 03)'
|
||||
- bus: '00'
|
||||
dev: '01'
|
||||
fn: '1'
|
||||
id: 6f03
|
||||
name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI
|
||||
Express Root Port 1 (rev 03)'
|
||||
- bus: '00'
|
||||
dev: '02'
|
||||
fn: '0'
|
||||
id: 6f04
|
||||
name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI
|
||||
Express Root Port 2 (rev 03)'
|
||||
- bus: '00'
|
||||
dev: '02'
|
||||
fn: '2'
|
||||
id: 6f06
|
||||
name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI
|
||||
Express Root Port 2 (rev 03)'
|
||||
- bus: '00'
|
||||
dev: '03'
|
||||
fn: '0'
|
||||
id: 6f08
|
||||
name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI
|
||||
Express Root Port 3 (rev 03)'
|
||||
- bus: '00'
|
||||
dev: '05'
|
||||
fn: '0'
|
||||
id: 6f28
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Map/VTd_Misc/System Management (rev 03)'
|
||||
- bus: '00'
|
||||
dev: '05'
|
||||
fn: '1'
|
||||
id: 6f29
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D IIO Hot Plug (rev 03)'
|
||||
- bus: '00'
|
||||
dev: '05'
|
||||
fn: '2'
|
||||
id: 6f2a
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D IIO RAS/Control Status/Global Errors (rev 03)'
|
||||
- bus: '00'
|
||||
dev: '05'
|
||||
fn: '4'
|
||||
id: 6f2c
|
||||
name: 'PIC: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D I/O APIC (rev
|
||||
03)'
|
||||
- bus: '00'
|
||||
dev: '14'
|
||||
fn: '0'
|
||||
id: 8c31
|
||||
name: 'USB controller: Intel Corporation 8 Series/C220 Series Chipset Family USB
|
||||
xHCI (rev 05)'
|
||||
- bus: '00'
|
||||
dev: '16'
|
||||
fn: '0'
|
||||
id: 8c3a
|
||||
name: 'Communication controller: Intel Corporation 8 Series/C220 Series Chipset
|
||||
Family MEI Controller #1 (rev 04)'
|
||||
- bus: '00'
|
||||
dev: '16'
|
||||
fn: '1'
|
||||
id: 8c3b
|
||||
name: 'Communication controller: Intel Corporation 8 Series/C220 Series Chipset
|
||||
Family MEI Controller #2 (rev 04)'
|
||||
- bus: '00'
|
||||
dev: 1c
|
||||
fn: '0'
|
||||
id: 8c10
|
||||
name: 'PCI bridge: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express
|
||||
Root Port #1 (rev d5)'
|
||||
- bus: '00'
|
||||
dev: 1d
|
||||
fn: '0'
|
||||
id: 8c26
|
||||
name: 'USB controller: Intel Corporation 8 Series/C220 Series Chipset Family USB
|
||||
EHCI #1 (rev 05)'
|
||||
- bus: '00'
|
||||
dev: 1f
|
||||
fn: '0'
|
||||
id: 8c54
|
||||
name: 'ISA bridge: Intel Corporation C224 Series Chipset Family Server Standard
|
||||
SKU LPC Controller (rev 05)'
|
||||
- bus: '00'
|
||||
dev: 1f
|
||||
fn: '2'
|
||||
id: 8c02
|
||||
name: 'SATA controller: Intel Corporation 8 Series/C220 Series Chipset Family 6-port
|
||||
SATA Controller 1 [AHCI mode] (rev 05)'
|
||||
- bus: '00'
|
||||
dev: 1f
|
||||
fn: '3'
|
||||
id: 8c22
|
||||
name: 'SMBus: Intel Corporation 8 Series/C220 Series Chipset Family SMBus Controller
|
||||
(rev 05)'
|
||||
- bus: '01'
|
||||
dev: '00'
|
||||
fn: '0'
|
||||
id: '1533'
|
||||
name: 'Ethernet controller: Intel Corporation I210 Gigabit Network Connection (rev
|
||||
03)'
|
||||
- bus: '03'
|
||||
dev: '00'
|
||||
fn: '0'
|
||||
id: 6f50
|
||||
name: 'System peripheral: Intel Corporation Xeon Processor D Family QuickData Technology
|
||||
Register DMA Channel 0'
|
||||
- bus: '03'
|
||||
dev: '00'
|
||||
fn: '1'
|
||||
id: 6f51
|
||||
name: 'System peripheral: Intel Corporation Xeon Processor D Family QuickData Technology
|
||||
Register DMA Channel 1'
|
||||
- bus: '03'
|
||||
dev: '00'
|
||||
fn: '2'
|
||||
id: 6f52
|
||||
name: 'System peripheral: Intel Corporation Xeon Processor D Family QuickData Technology
|
||||
Register DMA Channel 2'
|
||||
- bus: '03'
|
||||
dev: '00'
|
||||
fn: '3'
|
||||
id: 6f53
|
||||
name: 'System peripheral: Intel Corporation Xeon Processor D Family QuickData Technology
|
||||
Register DMA Channel 3'
|
||||
- bus: '04'
|
||||
dev: '00'
|
||||
fn: '0'
|
||||
id: 15ab
|
||||
name: 'Ethernet controller: Intel Corporation Ethernet Connection X552 10 GbE Backplane'
|
||||
- bus: '04'
|
||||
dev: '00'
|
||||
fn: '1'
|
||||
id: 15ab
|
||||
name: 'Ethernet controller: Intel Corporation Ethernet Connection X552 10 GbE Backplane'
|
||||
- bus: '07'
|
||||
dev: '00'
|
||||
fn: '0'
|
||||
id: b873
|
||||
name: 'Ethernet controller: Broadcom Limited Device b873 (rev 01)'
|
||||
- bus: ff
|
||||
dev: 0b
|
||||
fn: '0'
|
||||
id: 6f81
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D R3 QPI Link 0/1 (rev 03)'
|
||||
- bus: ff
|
||||
dev: 0b
|
||||
fn: '1'
|
||||
id: 6f36
|
||||
name: 'Performance counters: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D R3 QPI Link 0/1 (rev 03)'
|
||||
- bus: ff
|
||||
dev: 0b
|
||||
fn: '2'
|
||||
id: 6f37
|
||||
name: 'Performance counters: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D R3 QPI Link 0/1 (rev 03)'
|
||||
- bus: ff
|
||||
dev: 0b
|
||||
fn: '3'
|
||||
id: 6f76
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D R3 QPI Link Debug (rev 03)'
|
||||
- bus: ff
|
||||
dev: 0c
|
||||
fn: '0'
|
||||
id: 6fe0
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Caching Agent (rev 03)'
|
||||
- bus: ff
|
||||
dev: 0c
|
||||
fn: '1'
|
||||
id: 6fe1
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Caching Agent (rev 03)'
|
||||
- bus: ff
|
||||
dev: 0c
|
||||
fn: '2'
|
||||
id: 6fe2
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Caching Agent (rev 03)'
|
||||
- bus: ff
|
||||
dev: 0c
|
||||
fn: '3'
|
||||
id: 6fe3
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Caching Agent (rev 03)'
|
||||
- bus: ff
|
||||
dev: 0f
|
||||
fn: '0'
|
||||
id: 6ff8
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Caching Agent (rev 03)'
|
||||
- bus: ff
|
||||
dev: 0f
|
||||
fn: '4'
|
||||
id: 6ffc
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Caching Agent (rev 03)'
|
||||
- bus: ff
|
||||
dev: 0f
|
||||
fn: '5'
|
||||
id: 6ffd
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Caching Agent (rev 03)'
|
||||
- bus: ff
|
||||
dev: 0f
|
||||
fn: '6'
|
||||
id: 6ffe
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Caching Agent (rev 03)'
|
||||
- bus: ff
|
||||
dev: '10'
|
||||
fn: '0'
|
||||
id: 6f1d
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D R2PCIe Agent (rev 03)'
|
||||
- bus: ff
|
||||
dev: '10'
|
||||
fn: '1'
|
||||
id: 6f34
|
||||
name: 'Performance counters: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D R2PCIe Agent (rev 03)'
|
||||
- bus: ff
|
||||
dev: '10'
|
||||
fn: '5'
|
||||
id: 6f1e
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Ubox (rev 03)'
|
||||
- bus: ff
|
||||
dev: '10'
|
||||
fn: '6'
|
||||
id: 6f7d
|
||||
name: 'Performance counters: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Ubox (rev 03)'
|
||||
- bus: ff
|
||||
dev: '10'
|
||||
fn: '7'
|
||||
id: 6f1f
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Ubox (rev 03)'
|
||||
- bus: ff
|
||||
dev: '12'
|
||||
fn: '0'
|
||||
id: 6fa0
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Home Agent 0 (rev 03)'
|
||||
- bus: ff
|
||||
dev: '12'
|
||||
fn: '1'
|
||||
id: 6f30
|
||||
name: 'Performance counters: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Home Agent 0 (rev 03)'
|
||||
- bus: ff
|
||||
dev: '13'
|
||||
fn: '0'
|
||||
id: 6fa8
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Target Address/Thermal/RAS (rev 03)'
|
||||
- bus: ff
|
||||
dev: '13'
|
||||
fn: '1'
|
||||
id: 6f71
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Target Address/Thermal/RAS (rev 03)'
|
||||
- bus: ff
|
||||
dev: '13'
|
||||
fn: '2'
|
||||
id: 6faa
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Channel Target Address Decoder (rev 03)'
|
||||
- bus: ff
|
||||
dev: '13'
|
||||
fn: '3'
|
||||
id: 6fab
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Channel Target Address Decoder (rev 03)'
|
||||
- bus: ff
|
||||
dev: '13'
|
||||
fn: '4'
|
||||
id: 6fac
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Channel Target Address Decoder (rev 03)'
|
||||
- bus: ff
|
||||
dev: '13'
|
||||
fn: '5'
|
||||
id: 6fad
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Channel Target Address Decoder (rev 03)'
|
||||
- bus: ff
|
||||
dev: '13'
|
||||
fn: '6'
|
||||
id: 6fae
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D DDRIO Channel 0/1 Broadcast (rev 03)'
|
||||
- bus: ff
|
||||
dev: '13'
|
||||
fn: '7'
|
||||
id: 6faf
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D DDRIO Global Broadcast (rev 03)'
|
||||
- bus: ff
|
||||
dev: '14'
|
||||
fn: '0'
|
||||
id: 6fb0
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Channel 0 Thermal Control (rev 03)'
|
||||
- bus: ff
|
||||
dev: '14'
|
||||
fn: '1'
|
||||
id: 6fb1
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Channel 1 Thermal Control (rev 03)'
|
||||
- bus: ff
|
||||
dev: '14'
|
||||
fn: '2'
|
||||
id: 6fb2
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Channel 0 Error (rev 03)'
|
||||
- bus: ff
|
||||
dev: '14'
|
||||
fn: '3'
|
||||
id: 6fb3
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Channel 1 Error (rev 03)'
|
||||
- bus: ff
|
||||
dev: '14'
|
||||
fn: '4'
|
||||
id: 6fbc
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D DDRIO Channel 0/1 Interface (rev 03)'
|
||||
- bus: ff
|
||||
dev: '14'
|
||||
fn: '5'
|
||||
id: 6fbd
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D DDRIO Channel 0/1 Interface (rev 03)'
|
||||
- bus: ff
|
||||
dev: '14'
|
||||
fn: '6'
|
||||
id: 6fbe
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D DDRIO Channel 0/1 Interface (rev 03)'
|
||||
- bus: ff
|
||||
dev: '14'
|
||||
fn: '7'
|
||||
id: 6fbf
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D DDRIO Channel 0/1 Interface (rev 03)'
|
||||
- bus: ff
|
||||
dev: '15'
|
||||
fn: '0'
|
||||
id: 6fb4
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Channel 2 Thermal Control (rev 03)'
|
||||
- bus: ff
|
||||
dev: '15'
|
||||
fn: '1'
|
||||
id: 6fb5
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Channel 3 Thermal Control (rev 03)'
|
||||
- bus: ff
|
||||
dev: '15'
|
||||
fn: '2'
|
||||
id: 6fb6
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Channel 2 Error (rev 03)'
|
||||
- bus: ff
|
||||
dev: '15'
|
||||
fn: '3'
|
||||
id: 6fb7
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Memory Controller 0 - Channel 3 Error (rev 03)'
|
||||
- bus: ff
|
||||
dev: 1e
|
||||
fn: '0'
|
||||
id: 6f98
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Power Control Unit (rev 03)'
|
||||
- bus: ff
|
||||
dev: 1e
|
||||
fn: '1'
|
||||
id: 6f99
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Power Control Unit (rev 03)'
|
||||
- bus: ff
|
||||
dev: 1e
|
||||
fn: '2'
|
||||
id: 6f9a
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Power Control Unit (rev 03)'
|
||||
- bus: ff
|
||||
dev: 1e
|
||||
fn: '3'
|
||||
id: 6fc0
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Power Control Unit (rev 03)'
|
||||
- bus: ff
|
||||
dev: 1e
|
||||
fn: '4'
|
||||
id: 6f9c
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Power Control Unit (rev 03)'
|
||||
- bus: ff
|
||||
dev: 1f
|
||||
fn: '0'
|
||||
id: 6f88
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Power Control Unit (rev 03)'
|
||||
- bus: ff
|
||||
dev: 1f
|
||||
fn: '2'
|
||||
id: 6f8a
|
||||
name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon
|
||||
D Power Control Unit (rev 03)'
|
@ -0,0 +1,67 @@
|
||||
{
|
||||
"XCVR": {
|
||||
"xcvr_present": {
|
||||
"i2c": {
|
||||
"valmap-SFP28": {
|
||||
"1": true,
|
||||
"0": false
|
||||
},
|
||||
"valmap-QSFP28": {
|
||||
"1": true,
|
||||
"0": false
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"PSU": {
|
||||
"psu_present": {
|
||||
"i2c": {
|
||||
"valmap": {
|
||||
"1": true,
|
||||
"0": false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"psu_power_good": {
|
||||
"i2c": {
|
||||
"valmap": {
|
||||
"1": true,
|
||||
"0": false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"psu_fan_dir": {
|
||||
"i2c": {
|
||||
"valmap": {
|
||||
"F2B": "EXHAUST",
|
||||
"B2F": "INTAKE"
|
||||
}
|
||||
}
|
||||
},
|
||||
"PSU_FAN_MAX_SPEED": "18000"
|
||||
},
|
||||
|
||||
"FAN": {
|
||||
"direction": {
|
||||
"i2c": {
|
||||
"valmap": {
|
||||
"1": "INTAKE",
|
||||
"0": "EXHAUST"
|
||||
}
|
||||
}
|
||||
},
|
||||
"present": {
|
||||
"i2c": {
|
||||
"valmap": {
|
||||
"1": true,
|
||||
"0": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"duty_cycle_to_pwm": "lambda dc: dc*255/100",
|
||||
"pwm_to_duty_cycle": "lambda pwm: pwm*100/255"
|
||||
}
|
||||
}
|
6332
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pddf/pddf-device.json
Normal file
6332
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pddf/pddf-device.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,5 @@
|
||||
{
|
||||
"skip_ledd": true,
|
||||
"skip_xcvrd": false,
|
||||
"skip_psud": false
|
||||
}
|
21
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sensors.conf
Executable file
21
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sensors.conf
Executable file
@ -0,0 +1,21 @@
|
||||
# libsensors configuration file
|
||||
# ----------------------------------------------
|
||||
#
|
||||
|
||||
bus "i2c-2" "i2c-0-mux (chan_id 0)"
|
||||
|
||||
chip "lm75-i2c-2-48"
|
||||
label temp1 "LM75_0 air_inlet"
|
||||
set temp1_max 80
|
||||
set temp1_max_hyst 75
|
||||
|
||||
chip "lm75-i2c-2-49"
|
||||
label temp1 "LM75_1 air_outlet"
|
||||
set temp1_max 80
|
||||
set temp1_max_hyst 75
|
||||
|
||||
chip "lm75-i2c-2-4a"
|
||||
label temp1 "LM75_2 hottest"
|
||||
set temp1_max 80
|
||||
set temp1_max_hyst 75
|
||||
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"eeprom": {"bus": 2, "loc": "0057"}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"name": "CPLD1 (MAC Board A)",
|
||||
"firmware_version": {
|
||||
"bus": 2,
|
||||
"addr": 51,
|
||||
"offset": 0,
|
||||
"size": 4,
|
||||
"way": 1,
|
||||
"format": 7,
|
||||
"sep": "/"
|
||||
},
|
||||
"desc": "Used for managing IO modules, SFP+ modules and system LEDs",
|
||||
"slot": 0
|
||||
},
|
||||
{
|
||||
"name": "CPLD2 (MAC Board B)",
|
||||
"firmware_version": {
|
||||
"bus": 2,
|
||||
"addr": 53,
|
||||
"offset": 0,
|
||||
"size": 4,
|
||||
"way": 1,
|
||||
"format": 7,
|
||||
"sep": "/"
|
||||
},
|
||||
"desc": "Used for managing IO modules, SFP+ modules and system LEDs",
|
||||
"slot": 0
|
||||
},
|
||||
{
|
||||
"name": "CPLD3 (CONNECT Board A)",
|
||||
"firmware_version": {
|
||||
"bus": 2,
|
||||
"addr": 55,
|
||||
"offset": 0,
|
||||
"size": 4,
|
||||
"way": 1,
|
||||
"format": 7,
|
||||
"sep": "/"
|
||||
},
|
||||
"desc": "Used for managing IO modules, SFP+ modules and system LEDs",
|
||||
"slot": 0
|
||||
},
|
||||
{
|
||||
"name": "CPLD4 (CPU Board)",
|
||||
"firmware_version": {
|
||||
"bus": 0,
|
||||
"addr": 13,
|
||||
"offset": 0,
|
||||
"size": 4,
|
||||
"way": 1,
|
||||
"format": 7,
|
||||
"sep": "/"
|
||||
},
|
||||
"desc": "Used for managing IO modules, SFP+ modules and system LEDs",
|
||||
"slot": 1
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
{
|
||||
"fans": [
|
||||
{
|
||||
"name": "fan1",
|
||||
"e2loc": {"bus": 3, "addr": 83, "way": "i2c", "size": "256"},
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_present",
|
||||
"format": 2,
|
||||
"bit": 0
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_status",
|
||||
"format": 2,
|
||||
"bit": 0
|
||||
},
|
||||
"hw_version": {"loc": "/sys/bus/i2c/devices/3-0053/fan_hw_version"},
|
||||
"sn": {"loc": "/sys/bus/i2c/devices/3-0053/fan_sn"},
|
||||
"led": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan0_led",
|
||||
"format": 6,
|
||||
"mask": 11
|
||||
},
|
||||
"led_colors": {
|
||||
"green": 9,
|
||||
"red": 10,
|
||||
"amber": 3
|
||||
},
|
||||
"rotors": [
|
||||
{
|
||||
"speed_getter": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/hwmon/*/fan1_input"
|
||||
},
|
||||
"speed_setter": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan_speed_set"
|
||||
},
|
||||
"speed_max": 23000
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "fan2",
|
||||
"e2loc": {"bus": 4, "addr": 83, "way": "i2c", "size": "256"},
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_present",
|
||||
"format": 2,
|
||||
"bit": 1
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_status",
|
||||
"format": 2,
|
||||
"bit": 1
|
||||
},
|
||||
"hw_version": {"loc": "/sys/bus/i2c/devices/4-0053/fan_hw_version"},
|
||||
"sn": {"loc": "/sys/bus/i2c/devices/4-0053/fan_sn"},
|
||||
"led": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan1_led",
|
||||
"format": 6,
|
||||
"mask": 11
|
||||
},
|
||||
"led_colors": {
|
||||
"green": 9,
|
||||
"red": 10,
|
||||
"amber": 3
|
||||
},
|
||||
"rotors": [
|
||||
{
|
||||
"speed_getter": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/hwmon/*/fan2_input"
|
||||
},
|
||||
"speed_setter": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan_speed_set"
|
||||
},
|
||||
"speed_max": 23000
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "fan3",
|
||||
"e2loc": {"bus": 3, "addr": 83, "way": "i2c", "size": "256"},
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_present",
|
||||
"format": 2,
|
||||
"bit": 2
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_status",
|
||||
"format": 2,
|
||||
"bit": 2
|
||||
},
|
||||
"hw_version": {"loc": "/sys/bus/i2c/devices/5-0053/fan_hw_version"},
|
||||
"sn": {"loc": "/sys/bus/i2c/devices/5-0053/fan_sn"},
|
||||
"led": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan2_led",
|
||||
"format": 6,
|
||||
"mask": 11
|
||||
},
|
||||
"led_colors": {
|
||||
"green": 9,
|
||||
"red": 10,
|
||||
"amber": 3
|
||||
},
|
||||
"rotors": [
|
||||
{
|
||||
"speed_getter": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/hwmon/*/fan3_input"
|
||||
},
|
||||
"speed_setter": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan_speed_set"
|
||||
},
|
||||
"speed_max": 23000
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "fan4",
|
||||
"e2loc": {"bus": 3, "addr": 83, "way": "i2c", "size": "256"},
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_present",
|
||||
"format": 2,
|
||||
"bit": 3
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_status",
|
||||
"format": 2,
|
||||
"bit": 3
|
||||
},
|
||||
"hw_version": {"loc": "/sys/bus/i2c/devices/6-0053/fan_hw_version"},
|
||||
"sn": {"loc": "/sys/bus/i2c/devices/6-0053/fan_sn"},
|
||||
"led": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan3_led",
|
||||
"format": 6,
|
||||
"mask": 11
|
||||
},
|
||||
"led_colors":{
|
||||
"green": 9,
|
||||
"red": 10,
|
||||
"amber": 3
|
||||
},
|
||||
"rotors": [
|
||||
{
|
||||
"speed_getter": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/hwmon/*/fan4_input"
|
||||
},
|
||||
"speed_setter": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan_speed_set"
|
||||
},
|
||||
"speed_max": 23000
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
{
|
||||
"psus": [
|
||||
{
|
||||
"name": "psu1",
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
|
||||
"format": 2,
|
||||
"bit": 0
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
|
||||
"format": 2,
|
||||
"bit": 1
|
||||
},
|
||||
"sn": {"loc": "/sys/bus/i2c/devices/7-0050/psu_sn"},
|
||||
"in_current": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/curr1_input",
|
||||
"format": 4
|
||||
},
|
||||
"in_voltage": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/in1_input",
|
||||
"format": 4
|
||||
},
|
||||
"out_voltage": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/in2_input",
|
||||
"format": 4
|
||||
},
|
||||
"out_current": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/curr2_input",
|
||||
"format": 4
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/temp1_input",
|
||||
"format": 4
|
||||
},
|
||||
"hw_version": {"loc": "/sys/bus/i2c/devices/7-0050/psu_hw"},
|
||||
"psu_type": {"loc": "/sys/bus/i2c/devices/7-0050/psu_type"},
|
||||
"fans": [
|
||||
{
|
||||
"name": "psu_fan1",
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/fan1_fault"
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
|
||||
"format": 2,
|
||||
"bit": 1
|
||||
},
|
||||
"rotors": [
|
||||
{
|
||||
"speed_getter": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/fan1_input"
|
||||
},
|
||||
"speed_max": 28000
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"in_power": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/power1_input",
|
||||
"format": 5
|
||||
},
|
||||
"out_power": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/power2_input",
|
||||
"format": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "psu2",
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
|
||||
"format": 2,
|
||||
"bit": 4
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
|
||||
"format": 2,
|
||||
"bit": 5
|
||||
},
|
||||
"sn": {"loc": "/sys/bus/i2c/devices/8-0053/psu_sn"},
|
||||
"in_current": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/curr1_input",
|
||||
"format": 4
|
||||
},
|
||||
"in_voltage": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/in1_input",
|
||||
"format": 4
|
||||
},
|
||||
"out_voltage": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/in2_input",
|
||||
"format": 4
|
||||
},
|
||||
"out_current": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/curr2_input",
|
||||
"format": 4
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/temp1_input",
|
||||
"format": 4
|
||||
},
|
||||
"hw_version": {"loc": "/sys/bus/i2c/devices/8-0053/psu_hw"},
|
||||
"psu_type": {"loc": "/sys/bus/i2c/devices/8-0053/psu_type"},
|
||||
"fans": [
|
||||
{
|
||||
"name": "psu_fan1",
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/fan1_fault"
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
|
||||
"format": 2,
|
||||
"bit": 5
|
||||
},
|
||||
"rotors": [
|
||||
{
|
||||
"speed_getter": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/fan1_input"
|
||||
},
|
||||
"speed_max": 28000
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"in_power": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/power1_input",
|
||||
"format": 5
|
||||
},
|
||||
"out_power": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/power2_input",
|
||||
"format": 5
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
{"thermals": [
|
||||
{
|
||||
"name": "INLET TEMP",
|
||||
"high": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0048/hwmon/*/temp1_max",
|
||||
"format": 4
|
||||
},
|
||||
"low": null,
|
||||
"crit_low": null,
|
||||
"crit_high": null,
|
||||
"temperature": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0048/hwmon/*/temp1_input",
|
||||
"format": 4
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "OUTLET TEMP",
|
||||
"high": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0049/hwmon/*/temp1_max",
|
||||
"format": 4
|
||||
},
|
||||
"low": null,
|
||||
"crit_low": null,
|
||||
"crit_high": null,
|
||||
"temperature": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0049/hwmon/*/temp1_input",
|
||||
"format": 4
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "BOARD TEMP",
|
||||
"high": {
|
||||
"loc": "/sys/bus/i2c/devices/2-004a/hwmon/*/temp1_max",
|
||||
"format": 4
|
||||
},
|
||||
"low": null,
|
||||
"crit_low": null,
|
||||
"crit_high": null,
|
||||
"temperature": {
|
||||
"loc": "/sys/bus/i2c/devices/2-004a/hwmon/*/temp1_input",
|
||||
"format": 4
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "PHYSICAL ID 0",
|
||||
"high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp1_max",
|
||||
"format": 4
|
||||
},
|
||||
"low": null,
|
||||
"crit_low": null,
|
||||
"crit_high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp1_crit",
|
||||
"format": 4
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp1_input",
|
||||
"format": 4
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "CPU CORE 0",
|
||||
"high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp2_max",
|
||||
"format": 4
|
||||
},
|
||||
"low": null,
|
||||
"crit_low": null,
|
||||
"crit_high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp2_crit",
|
||||
"format": 4
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp2_input",
|
||||
"format": 4
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "CPU CORE 1",
|
||||
"high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp3_max",
|
||||
"format": 4
|
||||
},
|
||||
"low": null,
|
||||
"crit_low": null,
|
||||
"crit_high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp3_crit",
|
||||
"format": 4
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp3_input",
|
||||
"format": 4
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "CPU CORE 2",
|
||||
"high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp4_max",
|
||||
"format": 4
|
||||
},
|
||||
"low": null,
|
||||
"crit_low": null,
|
||||
"crit_high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp4_crit",
|
||||
"format": 4
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp4_input",
|
||||
"format": 4
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "CPU CORE 3",
|
||||
"high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp5_max",
|
||||
"format": 4
|
||||
},
|
||||
"low": null,
|
||||
"crit_low": null,
|
||||
"crit_high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp5_crit",
|
||||
"format": 4
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp5_input",
|
||||
"format": 4
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
43
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/systest.py
Normal file
43
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/systest.py
Normal file
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
"""
|
||||
* onboard temperature sensors
|
||||
* FAN trays
|
||||
* PSU
|
||||
"""
|
||||
import time
|
||||
import datetime
|
||||
from monitor import status
|
||||
|
||||
def doWork():
|
||||
a=[];
|
||||
'''
|
||||
return: [{'status': '1', 'hw_version': '1.00', 'errcode': 0, 'fan_type': 'M6510-FAN-F', 'errmsg': 'OK', 'Speed': '9778', 'id': 'fan1', 'present': '0', 'sn': '1000000000014'},
|
||||
{'id': 'fan2', 'errmsg': 'not present', 'errcode': -1},
|
||||
{'id': 'fan3', 'errmsg': 'not present', 'errcode': -1},
|
||||
{'id': 'fan4', 'errmsg': 'not present', 'errcode': -1}
|
||||
]
|
||||
description: 1.get id
|
||||
2.errcode equal 0 : dev normal
|
||||
not equal 0 : get errmsg
|
||||
3.other message add when all check success
|
||||
'''
|
||||
status.checkFan(a)
|
||||
#status.getTemp(a)
|
||||
#status.getPsu(a)
|
||||
|
||||
nowTime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
print(nowTime)
|
||||
print(a)
|
||||
def run(interval):
|
||||
while True:
|
||||
try:
|
||||
time_remaining = interval - time.time()%interval
|
||||
time.sleep(time_remaining)
|
||||
doWork()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
if __name__ == '__main__':
|
||||
interval = 1
|
||||
run(interval)
|
@ -65,7 +65,8 @@ $(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(DELL_S6000_PLATFORM_MODULE) \
|
||||
$(CEL_SILVERSTONE_PLATFORM_MODULE) \
|
||||
$(JUNIPER_QFX5200_PLATFORM_MODULE) \
|
||||
$(DELTA_AGC032_PLATFORM_MODULE) \
|
||||
$(RUIJIE_B6510_48VS8CQ_PLATFORM_MODULE)
|
||||
$(RUIJIE_B6510_48VS8CQ_PLATFORM_MODULE) \
|
||||
$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE)
|
||||
ifeq ($(INSTALL_DEBUG_TOOLS),y)
|
||||
$(SONIC_ONE_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_DBG_IMAGES)
|
||||
$(SONIC_ONE_IMAGE)_DOCKERS += $(filter-out $(patsubst %-$(DBG_IMAGE_MARK).gz,%.gz, $(SONIC_INSTALL_DOCKER_DBG_IMAGES)), $(SONIC_INSTALL_DOCKER_IMAGES))
|
||||
|
9
platform/broadcom/platform-modules-ragile.dep
Normal file
9
platform/broadcom/platform-modules-ragile.dep
Normal file
@ -0,0 +1,9 @@
|
||||
MPATH := $($(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE)_SRC_PATH)
|
||||
DEP_FILES := $(SONIC_COMMON_FILES_LIST) platform/broadcom/platform-modules-ragile.mk platform/broadcom/platform-modules-ragile.dep
|
||||
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
|
||||
DEP_FILES += $(shell git ls-files $(MPATH))
|
||||
|
||||
|
||||
$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE)_CACHE_MODE := GIT_CONTENT_SHA
|
||||
$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
|
||||
$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE)_DEP_FILES := $(DEP_FILES)
|
10
platform/broadcom/platform-modules-ragile.mk
Normal file
10
platform/broadcom/platform-modules-ragile.mk
Normal file
@ -0,0 +1,10 @@
|
||||
## RA-B6510-48V8C
|
||||
RAGILE_RA_B6510_48V8C_PLATFORM_MODULE_VERSION = 1.0
|
||||
export RAGILE_RA_B6510_48V8C_PLATFORM_MODULE_VERSION
|
||||
|
||||
RAGILE_RA_B6510_48V8C_PLATFORM_MODULE = platform-modules-ragile-ra-b6510-48v8c_$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE_VERSION)_amd64.deb
|
||||
$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-ragile
|
||||
$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE)_DEPENDS += $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON)
|
||||
$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE)_PLATFORM = x86_64-ragile_ra-b6510-48v8c-r0
|
||||
SONIC_DPKG_DEBS += $(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE)
|
||||
SONIC_STRETCH_DEBS += $(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE)
|
@ -13,6 +13,7 @@ include $(PLATFORM_PATH)/platform-modules-quanta.mk
|
||||
include $(PLATFORM_PATH)/platform-modules-juniper.mk
|
||||
include $(PLATFORM_PATH)/platform-modules-brcm-xlr-gts.mk
|
||||
include $(PLATFORM_PATH)/platform-modules-ruijie.mk
|
||||
include $(PLATFORM_PATH)/platform-modules-ragile.mk
|
||||
include $(PLATFORM_PATH)/docker-syncd-brcm.mk
|
||||
include $(PLATFORM_PATH)/docker-syncd-brcm-rpc.mk
|
||||
include $(PLATFORM_PATH)/docker-saiserver-brcm.mk
|
||||
|
15
platform/broadcom/sonic-platform-modules-ragile/LICENSE
Executable file
15
platform/broadcom/sonic-platform-modules-ragile/LICENSE
Executable file
@ -0,0 +1,15 @@
|
||||
Copyright (C) 2016 Microsoft, Inc
|
||||
Copyright (C) 2018 Ragile Network Corporation
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
41
platform/broadcom/sonic-platform-modules-ragile/common/Makefile
Executable file
41
platform/broadcom/sonic-platform-modules-ragile/common/Makefile
Executable file
@ -0,0 +1,41 @@
|
||||
PWD = $(shell pwd)
|
||||
CC ?=gcc
|
||||
INSTALL_MOD_DIR ?=extra
|
||||
KVERSION ?= $(shell uname -r)
|
||||
KERNEL_SRC ?= /lib/modules/$(KVERSION)
|
||||
EXTRA_CFLAGS:= -I$(M)/include
|
||||
EXTRA_CFLAGS+= -Wall
|
||||
SUB_BUILD_DIR = $(PWD)/build
|
||||
DIR_KERNEL_SRC = $(PWD)/modules
|
||||
SCRIPT_DIR = $(PWD)/script
|
||||
SERVICE_DIR = $(PWD)/service
|
||||
DEPMOD_CONF_DIR = $(PWD)/depmod_conf
|
||||
|
||||
KBUILD_EXTRA_SYMBOLS += $(DIR_KERNEL_SRC)/Module.symvers
|
||||
export KBUILD_EXTRA_SYMBOLS
|
||||
|
||||
INSTALL_MODULE_DIR = $(SUB_BUILD_DIR)/$(KERNEL_SRC)/$(INSTALL_MOD_DIR)
|
||||
INSTALL_SCRIPT_DIR = $(SUB_BUILD_DIR)/usr/local/bin
|
||||
INSTALL_SERVICE_DIR = $(SUB_BUILD_DIR)/lib/systemd/system
|
||||
INSTALL_LIB_DIR = $(SUB_BUILD_DIR)/usr/lib/python3.7/dist-packages
|
||||
INSTALL_DEPMOD_CONF = $(SUB_BUILD_DIR)/etc/depmod.d
|
||||
|
||||
all:
|
||||
$(MAKE) -C $(KERNEL_SRC)/build M=$(DIR_KERNEL_SRC) modules
|
||||
@if [ ! -d ${INSTALL_MODULE_DIR} ]; then mkdir -p ${INSTALL_MODULE_DIR} ;fi
|
||||
@if [ ! -d ${INSTALL_SCRIPT_DIR} ]; then mkdir -p ${INSTALL_SCRIPT_DIR} ;fi
|
||||
@if [ ! -d ${INSTALL_SERVICE_DIR} ]; then mkdir -p ${INSTALL_SERVICE_DIR} ;fi
|
||||
@if [ ! -d ${INSTALL_LIB_DIR} ]; then mkdir -p ${INSTALL_LIB_DIR} ;fi
|
||||
@if [ -d $(PWD)/lib/ ]; then cp -r $(PWD)/lib/* ${INSTALL_LIB_DIR} ;fi
|
||||
@if [ -d $(PWD)/lib/ ]; then cp -r $(PWD)/lib/* ${INSTALL_LIB_DIR2} ;fi
|
||||
@if [ ! -d ${INSTALL_DEPMOD_CONF} ]; then mkdir -p ${INSTALL_DEPMOD_CONF} ;fi
|
||||
cp -r $(DEPMOD_CONF_DIR)/* $(INSTALL_DEPMOD_CONF)
|
||||
cp -r $(DIR_KERNEL_SRC)/*.ko $(INSTALL_MODULE_DIR)
|
||||
cp -r $(SCRIPT_DIR)/* $(INSTALL_SCRIPT_DIR)
|
||||
cp -r $(SERVICE_DIR)/* $(INSTALL_SERVICE_DIR)
|
||||
@if [ -d $(INSTALL_SCRIPT_DIR) ]; then chmod +x $(INSTALL_SCRIPT_DIR)/* ;fi
|
||||
clean:
|
||||
rm -f ${DIR_KERNEL_SRC}/*.o ${DIR_KERNEL_SRC}/*.ko ${DIR_KERNEL_SRC}/*.mod.c ${DIR_KERNEL_SRC}/.*.cmd
|
||||
rm -f ${DIR_KERNEL_SRC}/Module.markers ${DIR_KERNEL_SRC}/Module.symvers ${DIR_KERNEL_SRC}/modules.order
|
||||
rm -rf ${DIR_KERNEL_SRC}/.tmp_versions
|
||||
rm -rf $(SUB_BUILD_DIR)
|
@ -0,0 +1,4 @@
|
||||
# depmod.conf
|
||||
#
|
||||
# override default search ordering for kmod packaging
|
||||
search updates extra external built-in weak-updates
|
@ -0,0 +1,212 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
class FantlvException(Exception):
|
||||
def __init__(self, message='fantlverror', code=-100):
|
||||
err = 'errcode: {0} message:{1}'.format(code, message)
|
||||
Exception.__init__(self, err)
|
||||
self.code = code
|
||||
self.message = message
|
||||
|
||||
class fan_tlv(object):
|
||||
HEAD_INFO = "\x01\x7e\x01\xf1"
|
||||
VERSION = 0x01 # E2PROM file init version is 0x01
|
||||
FLAG = 0x7E #new version E2PROM mark as 0x7E
|
||||
HW_VER = 0X01 # consists of master version and revised version
|
||||
TYPE = 0xf1 # hardware type define
|
||||
TLV_LEN = 00 # vaild data length(16bit)
|
||||
_FAN_TLV_HDR_LEN = 6
|
||||
_FAN_TLV_CRC_LEN = 2
|
||||
|
||||
_FAN_TLV_TYPE_NAME = 0x02
|
||||
_FAN_TLV_TYPE_SN = 0x03
|
||||
_FAN_TLV_TYPE_HW_INFO = 0x05
|
||||
_FAN_TLV_TYPE_DEV_TYPE = 0x06
|
||||
|
||||
_fandecodetime = 0
|
||||
|
||||
@property
|
||||
def dstatus(self):
|
||||
return self._dstatus
|
||||
|
||||
@property
|
||||
def typename(self):
|
||||
return self._typename
|
||||
|
||||
@property
|
||||
def typesn(self):
|
||||
return self._typesn
|
||||
|
||||
@property
|
||||
def typehwinfo(self):
|
||||
return self._typehwinfo
|
||||
|
||||
@property
|
||||
def typedevtype(self):
|
||||
return self._typedevtype
|
||||
|
||||
@property
|
||||
def fanbus(self):
|
||||
return self._fanbus
|
||||
|
||||
@property
|
||||
def fanloc(self):
|
||||
return self._fanloc
|
||||
|
||||
@property
|
||||
def fandecodetime(self):
|
||||
return self._fandecodetime
|
||||
|
||||
def __init__(self):
|
||||
self._typename = ""
|
||||
self._typesn = ""
|
||||
self._typehwinfo = ""
|
||||
self._typedevtype = ""
|
||||
self._dstatus = 0
|
||||
|
||||
def strtoarr(self, str):
|
||||
s = []
|
||||
if str is not None:
|
||||
for index in range(len(str)):
|
||||
s.append(str[index])
|
||||
return s
|
||||
|
||||
def str_to_hex(self,rest_v):
|
||||
value = 0
|
||||
for index in range(len(rest_v)):
|
||||
value |= ord(rest_v[index]) << ((len(rest_v) - index - 1) * 8)
|
||||
return value
|
||||
|
||||
def hex_to_str(self,s):
|
||||
len_t = len(s)
|
||||
if len_t % 2 != 0:
|
||||
return 0
|
||||
ret = ""
|
||||
for t in range(0, int(len_t / 2)):
|
||||
ret += chr(int(s[2 * t:2 * t + 2], 16))
|
||||
return ret
|
||||
|
||||
def generate_fan_value(self):
|
||||
bin_buffer = [chr(0xff)] * 256
|
||||
bin_buffer[0] = chr(self.VERSION)
|
||||
bin_buffer[1] = chr(self.FLAG)
|
||||
bin_buffer[2] = chr(self.HW_VER)
|
||||
bin_buffer[3] = chr(self.TYPE)
|
||||
|
||||
temp_t = "%08x" % self.typedevtype # handle devtype first
|
||||
typedevtype_t = self.hex_to_str(temp_t)
|
||||
total_len = len(self.typename) + len(self.typesn) + \
|
||||
len(self.typehwinfo) + len(typedevtype_t) + 8
|
||||
|
||||
bin_buffer[4] = chr(total_len >> 8)
|
||||
bin_buffer[5] = chr(total_len & 0x00FF)
|
||||
|
||||
index_start = 6
|
||||
bin_buffer[index_start] = chr(self._FAN_TLV_TYPE_NAME)
|
||||
bin_buffer[index_start + 1] = chr(len(self.typename))
|
||||
bin_buffer[index_start + 2: index_start + 2 +
|
||||
len(self.typename)] = self.strtoarr(self.typename)
|
||||
index_start = index_start + 2 + len(self.typename)
|
||||
|
||||
bin_buffer[index_start] = chr(self._FAN_TLV_TYPE_SN)
|
||||
bin_buffer[index_start + 1] = chr(len(self.typesn))
|
||||
bin_buffer[index_start + 2:index_start + 2 +
|
||||
len(self.typesn)] = self.strtoarr(self.typesn)
|
||||
index_start = index_start + 2 + len(self.typesn)
|
||||
|
||||
bin_buffer[index_start] = chr(self._FAN_TLV_TYPE_HW_INFO)
|
||||
bin_buffer[index_start + 1] = chr(len(self.typehwinfo))
|
||||
bin_buffer[index_start + 2:index_start + 2 +
|
||||
len(self.typehwinfo)] = self.strtoarr(self.typehwinfo)
|
||||
index_start = index_start + 2 + len(self.typehwinfo)
|
||||
|
||||
bin_buffer[index_start] = chr(self._FAN_TLV_TYPE_DEV_TYPE)
|
||||
bin_buffer[index_start + 1] = chr(len(typedevtype_t))
|
||||
bin_buffer[index_start + 2:index_start + 2 +
|
||||
len(typedevtype_t)] = self.strtoarr(typedevtype_t)
|
||||
index_start = index_start + 2 + len(typedevtype_t)
|
||||
|
||||
crcs = fan_tlv.fancrc(''.join(bin_buffer[0:index_start])) # 2bytes checking
|
||||
bin_buffer[index_start] = chr(crcs >> 8)
|
||||
bin_buffer[index_start + 1] = chr(crcs & 0x00ff)
|
||||
# printvalue(bin_buffer)
|
||||
return bin_buffer
|
||||
|
||||
def decode(self, e2):
|
||||
if e2[0:4] != self.HEAD_INFO:
|
||||
raise FantlvException("Fan tlv head info error,not fan tlv type", -10)
|
||||
ret = []
|
||||
self.VERSION = ord(e2[0])
|
||||
self.FLAG = ord(e2[1])
|
||||
self.HW_VER = ord(e2[2])
|
||||
self.TYPE = ord(e2[3])
|
||||
self.TLV_LEN = (ord(e2[4]) << 8) | ord(e2[5])
|
||||
|
||||
tlv_index = self._FAN_TLV_HDR_LEN
|
||||
tlv_end = self._FAN_TLV_HDR_LEN + self.TLV_LEN
|
||||
|
||||
# check sum
|
||||
if len(e2) < self._FAN_TLV_HDR_LEN + self.TLV_LEN + 2:
|
||||
raise FantlvException("Fan tlv eeprom len error!", -2)
|
||||
sumcrc = fan_tlv.fancrc(e2[0:self._FAN_TLV_HDR_LEN + self.TLV_LEN])
|
||||
readcrc = ord(e2[self._FAN_TLV_HDR_LEN + self.TLV_LEN]
|
||||
) << 8 | ord(e2[self._FAN_TLV_HDR_LEN + self.TLV_LEN + 1])
|
||||
if sumcrc != readcrc:
|
||||
raise FantlvException("Fan tlv eeprom checksum error!", -1)
|
||||
else:
|
||||
self._dstatus = 0
|
||||
while (tlv_index + 2) < len(e2) and tlv_index < tlv_end:
|
||||
s = self.decoder(
|
||||
e2[tlv_index:tlv_index + 2 + ord(e2[tlv_index + 1])])
|
||||
tlv_index += ord(e2[tlv_index + 1]) + 2
|
||||
ret.append(s)
|
||||
|
||||
return ret
|
||||
|
||||
@staticmethod
|
||||
def fancrc(t):
|
||||
sum = 0
|
||||
for index in range(len(t)):
|
||||
sum += ord(t[index])
|
||||
return sum
|
||||
|
||||
def decoder(self, t):
|
||||
try:
|
||||
name = ""
|
||||
value = ""
|
||||
if ord(t[0]) == self._FAN_TLV_TYPE_NAME:
|
||||
name = "Product Name"
|
||||
_len = ord(t[1])
|
||||
value = t[2:2 + ord(t[1])]
|
||||
self._typename = value
|
||||
elif ord(t[0]) == self._FAN_TLV_TYPE_SN:
|
||||
name = "serial Number"
|
||||
_len = ord(t[1])
|
||||
value = t[2:2 + ord(t[1])]
|
||||
self._typesn = value
|
||||
elif ord(t[0]) == self._FAN_TLV_TYPE_HW_INFO:
|
||||
name = "hardware info"
|
||||
_len = ord(t[1])
|
||||
value = t[2:2 + ord(t[1])]
|
||||
self._typehwinfo = value
|
||||
elif ord(t[0]) == self._FAN_TLV_TYPE_DEV_TYPE:
|
||||
name = "dev type"
|
||||
_len = ord(t[1])
|
||||
value = "0x"
|
||||
for c in t[2:2 + ord(t[1])]:
|
||||
value += "%02X" % (ord(c),)
|
||||
self._typedevtype = int(value,16)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return {"name": name, "code": ord(t[0]), "value": value,"lens": _len}
|
||||
|
||||
def __str__(self):
|
||||
formatstr = "VERSION : 0x%02x \n" \
|
||||
" FLAG : 0x%02x \n" \
|
||||
" HW_VER : 0x%02x \n" \
|
||||
" TYPE : 0x%02x \n" \
|
||||
"typename : %s \n" \
|
||||
"typesn : %s \n" \
|
||||
"typehwinfo : %s \n"
|
||||
return formatstr % (self.VERSION, self.FLAG, self.HW_VER, self.TYPE, self.typename, self.typesn, self.typehwinfo)
|
||||
|
||||
|
@ -0,0 +1,954 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import collections
|
||||
from bitarray import bitarray
|
||||
from datetime import datetime, timedelta
|
||||
import sys
|
||||
|
||||
__all__ = ["FruException", "FruUtil", "BaseArea", "BoardInfoArea", "ProductInfoArea",
|
||||
"MultiRecordArea", "Field", "ipmifru"]
|
||||
|
||||
__DEBUG__ = "N"
|
||||
|
||||
|
||||
class FruException(Exception):
|
||||
def __init__(self, message='fruerror', code=-100):
|
||||
err = 'errcode: {0} message:{1}'.format(code, message)
|
||||
Exception.__init__(self, err)
|
||||
self.code = code
|
||||
self.message = message
|
||||
|
||||
|
||||
def e_print(err):
|
||||
print("ERROR: " + err)
|
||||
|
||||
|
||||
def d_print(debug_info):
|
||||
if(__DEBUG__ == "Y"):
|
||||
print(debug_info)
|
||||
|
||||
|
||||
class FruUtil():
|
||||
@staticmethod
|
||||
def decodeLength(value):
|
||||
a = bitarray(8)
|
||||
a.setall(True)
|
||||
a[0:1] = 0
|
||||
a[1:2] = 0
|
||||
x = ord(a.tobytes())
|
||||
return x & ord(value)
|
||||
|
||||
@staticmethod
|
||||
def minToData():
|
||||
starttime = datetime(1996, 1, 1, 0, 0, 0)
|
||||
endtime = datetime.now()
|
||||
seconds = (endtime - starttime).total_seconds()
|
||||
mins = seconds / 60
|
||||
m = int(round(mins))
|
||||
return m
|
||||
|
||||
@staticmethod
|
||||
def getTimeFormat():
|
||||
return datetime.now().strftime('%Y-%m-%d')
|
||||
|
||||
@staticmethod
|
||||
def getTypeLength(value):
|
||||
if value is None:
|
||||
return 0
|
||||
a = bitarray(8)
|
||||
a.setall(False)
|
||||
a[0:1] = 1
|
||||
a[1:2] = 1
|
||||
x = ord(a.tobytes())
|
||||
return x | len(value)
|
||||
|
||||
@staticmethod
|
||||
def checksum(b):
|
||||
result = 0
|
||||
for i in range(len(b)):
|
||||
result += ord(b[i])
|
||||
return (0x100 - (result & 0xff)) & 0xff
|
||||
|
||||
|
||||
class BaseArea(object):
|
||||
SUGGESTED_SIZE_COMMON_HEADER = 8
|
||||
SUGGESTED_SIZE_INTERNAL_USE_AREA = 72
|
||||
SUGGESTED_SIZE_CHASSIS_INFO_AREA = 32
|
||||
SUGGESTED_SIZE_BOARD_INFO_AREA = 80
|
||||
SUGGESTED_SIZE_PRODUCT_INFO_AREA = 80
|
||||
|
||||
INITVALUE = b'\x00'
|
||||
resultvalue = INITVALUE * 256
|
||||
COMMON_HEAD_VERSION = b'\x01'
|
||||
__childList = None
|
||||
|
||||
def __init__(self, name="", size=0, offset=0):
|
||||
self.__childList = []
|
||||
self._offset = offset
|
||||
self.name = name
|
||||
self._size = size
|
||||
self._isPresent = False
|
||||
self._data = b'\x00' * size
|
||||
self.__dataoffset = 0
|
||||
|
||||
@property
|
||||
def childList(self):
|
||||
return self.__childList
|
||||
|
||||
@childList.setter
|
||||
def childList(self, value):
|
||||
self.__childList = value
|
||||
|
||||
@property
|
||||
def offset(self):
|
||||
return self._offset
|
||||
|
||||
@offset.setter
|
||||
def offset(self, value):
|
||||
self._offset = value
|
||||
|
||||
@property
|
||||
def size(self):
|
||||
return self._size
|
||||
|
||||
@size.setter
|
||||
def size(self, value):
|
||||
self._size = value
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return self._data
|
||||
|
||||
@data.setter
|
||||
def data(self, value):
|
||||
self._data = value
|
||||
|
||||
@property
|
||||
def isPresent(self):
|
||||
return self._isPresent
|
||||
|
||||
@isPresent.setter
|
||||
def isPresent(self, value):
|
||||
self._isPresent = value
|
||||
|
||||
|
||||
class InternalUseArea(BaseArea):
|
||||
pass
|
||||
|
||||
|
||||
class ChassisInfoArea(BaseArea):
|
||||
pass
|
||||
|
||||
|
||||
class BoardInfoArea(BaseArea):
|
||||
_boardTime = None
|
||||
_fields = None
|
||||
_mfg_date = None
|
||||
|
||||
def __str__(self):
|
||||
formatstr = "version : %x\n" \
|
||||
"length : %d \n" \
|
||||
"language : %x \n" \
|
||||
"mfg_date : %s \n" \
|
||||
"boardManufacturer : %s \n" \
|
||||
"boardProductName : %s \n" \
|
||||
"boardSerialNumber : %s \n" \
|
||||
"boardPartNumber : %s \n" \
|
||||
"fruFileId : %s \n"
|
||||
|
||||
tmpstr = formatstr % (ord(self.boardversion), self.size,
|
||||
self.language, self.getMfgRealData(),
|
||||
self.boardManufacturer, self.boardProductName,
|
||||
self.boardSerialNumber, self.boardPartNumber,
|
||||
self.fruFileId)
|
||||
for i in range(1, 11):
|
||||
valtmp = "boardextra%d" % i
|
||||
if hasattr(self, valtmp):
|
||||
valtmpval = getattr(self, valtmp)
|
||||
tmpstr += "boardextra%d : %s \n" % (i, valtmpval)
|
||||
else:
|
||||
break
|
||||
|
||||
return tmpstr
|
||||
|
||||
def todict(self):
|
||||
dic = collections.OrderedDict()
|
||||
dic["boardversion"] = ord(self.boardversion)
|
||||
dic["boardlength"] = self.size
|
||||
dic["boardlanguage"] = self.language
|
||||
dic["boardmfg_date"] = self.getMfgRealData()
|
||||
dic["boardManufacturer"] = self.boardManufacturer
|
||||
dic["boardProductName"] = self.boardProductName
|
||||
dic["boardSerialNumber"] = self.boardSerialNumber
|
||||
dic["boardPartNumber"] = self.boardPartNumber
|
||||
dic["boardfruFileId"] = self.fruFileId
|
||||
for i in range(1, 11):
|
||||
valtmp = "boardextra%d" % i
|
||||
if hasattr(self, valtmp):
|
||||
valtmpval = getattr(self, valtmp)
|
||||
dic[valtmp] = valtmpval
|
||||
else:
|
||||
break
|
||||
return dic
|
||||
|
||||
def decodedata(self):
|
||||
index = 0
|
||||
self.areaversion = self.data[index]
|
||||
index += 1
|
||||
d_print("decode length :%d class size:%d" %
|
||||
((ord(self.data[index]) * 8), self.size))
|
||||
index += 2
|
||||
|
||||
timetmp = self.data[index: index + 3]
|
||||
self.mfg_date = ord(timetmp[0]) | (
|
||||
ord(timetmp[1]) << 8) | (ord(timetmp[2]) << 16)
|
||||
d_print("decode getMfgRealData :%s" % self.getMfgRealData())
|
||||
index += 3
|
||||
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
self.boardManufacturer = self.data[index + 1: index + templen + 1]
|
||||
index += templen + 1
|
||||
d_print("decode boardManufacturer:%s" % self.boardManufacturer)
|
||||
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
self.boardProductName = self.data[index + 1: index + templen + 1]
|
||||
index += templen + 1
|
||||
d_print("decode boardProductName:%s" % self.boardProductName)
|
||||
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
self.boardSerialNumber = self.data[index + 1: index + templen + 1]
|
||||
index += templen + 1
|
||||
d_print("decode boardSerialNumber:%s" % self.boardSerialNumber)
|
||||
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
self.boardPartNumber = self.data[index + 1: index + templen + 1]
|
||||
index += templen + 1
|
||||
d_print("decode boardPartNumber:%s" % self.boardPartNumber)
|
||||
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
self.fruFileId = self.data[index + 1: index + templen + 1]
|
||||
index += templen + 1
|
||||
d_print("decode fruFileId:%s" % self.fruFileId)
|
||||
|
||||
|
||||
for i in range(1, 11):
|
||||
valtmp = "boardextra%d" % i
|
||||
if self.data[index] != chr(0xc1):
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
tmpval = self.data[index + 1: index + templen + 1]
|
||||
setattr(self, valtmp, tmpval)
|
||||
index += templen + 1
|
||||
d_print("decode boardextra%d:%s" % (i, tmpval))
|
||||
else:
|
||||
break
|
||||
|
||||
def recalcute(self):
|
||||
d_print("boardInfoArea version:%x" % ord(self.boardversion))
|
||||
d_print("boardInfoArea length:%d" % self.size)
|
||||
d_print("boardInfoArea language:%x" % self.language)
|
||||
self.mfg_date = FruUtil.minToData()
|
||||
d_print("boardInfoArea mfg_date:%x" % self.mfg_date)
|
||||
|
||||
self.data = chr(ord(self.boardversion)) + \
|
||||
chr(self.size / 8) + chr(self.language)
|
||||
|
||||
self.data += chr(self.mfg_date & 0xFF)
|
||||
self.data += chr((self.mfg_date >> 8) & 0xFF)
|
||||
self.data += chr((self.mfg_date >> 16) & 0xFF)
|
||||
|
||||
d_print("boardInfoArea boardManufacturer:%s" % self.boardManufacturer)
|
||||
typelength = FruUtil.getTypeLength(self.boardManufacturer)
|
||||
self.data += chr(typelength)
|
||||
self.data += self.boardManufacturer
|
||||
|
||||
d_print("boardInfoArea boardProductName:%s" % self.boardProductName)
|
||||
self.data += chr(FruUtil.getTypeLength(self.boardProductName))
|
||||
self.data += self.boardProductName
|
||||
|
||||
d_print("boardInfoArea boardSerialNumber:%s" % self.boardSerialNumber)
|
||||
self.data += chr(FruUtil.getTypeLength(self.boardSerialNumber))
|
||||
self.data += self.boardSerialNumber
|
||||
|
||||
d_print("boardInfoArea boardPartNumber:%s" % self.boardPartNumber)
|
||||
self.data += chr(FruUtil.getTypeLength(self.boardPartNumber))
|
||||
self.data += self.boardPartNumber
|
||||
|
||||
d_print("boardInfoArea fruFileId:%s" % self.fruFileId)
|
||||
self.data += chr(FruUtil.getTypeLength(self.fruFileId))
|
||||
self.data += self.fruFileId
|
||||
|
||||
for i in range(1, 11):
|
||||
valtmp = "boardextra%d" % i
|
||||
if hasattr(self, valtmp):
|
||||
valtmpval = getattr(self, valtmp)
|
||||
d_print("boardInfoArea boardextra%d:%s" % (i, valtmpval))
|
||||
self.data += chr(FruUtil.getTypeLength(valtmpval))
|
||||
if valtmpval is None:
|
||||
pass
|
||||
else:
|
||||
self.data += valtmpval
|
||||
else:
|
||||
break
|
||||
|
||||
self.data += chr(0xc1)
|
||||
|
||||
if len(self.data) > (self.size - 1):
|
||||
incr = (len(self.data) - self.size) / 8 + 1
|
||||
self.size += incr * 8
|
||||
|
||||
self.data = self.data[0:1] + chr(self.size / 8) + self.data[2:]
|
||||
d_print("self data:%d" % len(self.data))
|
||||
d_print("self size:%d" % self.size)
|
||||
d_print("adjust size:%d" % (self.size - len(self.data) - 1))
|
||||
self.data = self.data.ljust((self.size - 1), self.INITVALUE)
|
||||
|
||||
# checksum
|
||||
checksum = FruUtil.checksum(self.data)
|
||||
d_print("board info checksum:%x" % checksum)
|
||||
self.data += chr(checksum)
|
||||
|
||||
def getMfgRealData(self):
|
||||
starttime = datetime(1996, 1, 1, 0, 0, 0)
|
||||
mactime = starttime + timedelta(minutes=self.mfg_date)
|
||||
return mactime
|
||||
|
||||
@property
|
||||
def language(self):
|
||||
self._language = 25
|
||||
return self._language
|
||||
|
||||
@property
|
||||
def mfg_date(self):
|
||||
return self._mfg_date
|
||||
|
||||
@mfg_date.setter
|
||||
def mfg_date(self, val):
|
||||
self._mfg_date = val
|
||||
|
||||
@property
|
||||
def boardversion(self):
|
||||
self._boardversion = self.COMMON_HEAD_VERSION
|
||||
return self._boardversion
|
||||
|
||||
@property
|
||||
def fruFileId(self):
|
||||
return self._FRUFileID
|
||||
|
||||
@fruFileId.setter
|
||||
def fruFileId(self, val):
|
||||
self._FRUFileID = val
|
||||
|
||||
@property
|
||||
def boardPartNumber(self):
|
||||
return self._boardPartNumber
|
||||
|
||||
@boardPartNumber.setter
|
||||
def boardPartNumber(self, val):
|
||||
self._boardPartNumber = val
|
||||
|
||||
@property
|
||||
def boardSerialNumber(self):
|
||||
return self._boardSerialNumber
|
||||
|
||||
@boardSerialNumber.setter
|
||||
def boardSerialNumber(self, val):
|
||||
self._boardSerialNumber = val
|
||||
|
||||
@property
|
||||
def boardProductName(self):
|
||||
return self._boradProductName
|
||||
|
||||
@boardProductName.setter
|
||||
def boardProductName(self, val):
|
||||
self._boradProductName = val
|
||||
|
||||
@property
|
||||
def boardManufacturer(self):
|
||||
return self._boardManufacturer
|
||||
|
||||
@boardManufacturer.setter
|
||||
def boardManufacturer(self, val):
|
||||
self._boardManufacturer = val
|
||||
|
||||
@property
|
||||
def boardTime(self):
|
||||
return self._boardTime
|
||||
|
||||
@boardTime.setter
|
||||
def boardTime(self, val):
|
||||
self._boardTime = val
|
||||
|
||||
@property
|
||||
def fields(self):
|
||||
return self._fields
|
||||
|
||||
@fields.setter
|
||||
def fields(self, val):
|
||||
self._fields = val
|
||||
|
||||
|
||||
class ProductInfoArea(BaseArea):
|
||||
_productManufacturer = None
|
||||
_productAssetTag = None
|
||||
_FRUFileID = None
|
||||
|
||||
def __str__(self):
|
||||
formatstr = "version : %x\n" \
|
||||
"length : %d \n" \
|
||||
"language : %x \n" \
|
||||
"productManufacturer : %s \n" \
|
||||
"productName : %s \n" \
|
||||
"productPartModelName: %s \n" \
|
||||
"productVersion : %s \n" \
|
||||
"productSerialNumber : %s \n" \
|
||||
"productAssetTag : %s \n" \
|
||||
"fruFileId : %s \n"
|
||||
|
||||
tmpstr = formatstr % (ord(self.areaversion), self.size,
|
||||
self.language, self.productManufacturer,
|
||||
self.productName, self.productPartModelName,
|
||||
self.productVersion, self.productSerialNumber,
|
||||
self.productAssetTag, self.fruFileId)
|
||||
|
||||
for i in range(1, 11):
|
||||
valtmp = "productextra%d" % i
|
||||
if hasattr(self, valtmp):
|
||||
valtmpval = getattr(self, valtmp)
|
||||
tmpstr += "productextra%d : %s \n" % (i, valtmpval)
|
||||
else:
|
||||
break
|
||||
|
||||
return tmpstr
|
||||
|
||||
def todict(self):
|
||||
dic = collections.OrderedDict()
|
||||
dic["productversion"] = ord(self.areaversion)
|
||||
dic["productlength"] = self.size
|
||||
dic["productlanguage"] = self.language
|
||||
dic["productManufacturer"] = self.productManufacturer
|
||||
dic["productName"] = self.productName
|
||||
dic["productPartModelName"] = self.productPartModelName
|
||||
dic["productVersion"] = int(self.productVersion, 16)
|
||||
dic["productSerialNumber"] = self.productSerialNumber
|
||||
dic["productAssetTag"] = self.productAssetTag
|
||||
dic["productfruFileId"] = self.fruFileId
|
||||
for i in range(1, 11):
|
||||
valtmp = "productextra%d" % i
|
||||
if hasattr(self, valtmp):
|
||||
valtmpval = getattr(self, valtmp)
|
||||
dic[valtmp] = valtmpval
|
||||
else:
|
||||
break
|
||||
return dic
|
||||
|
||||
def decodedata(self):
|
||||
index = 0
|
||||
self.areaversion = self.data[index] # 0
|
||||
index += 1
|
||||
d_print("decode length %d" % (ord(self.data[index]) * 8))
|
||||
d_print("class size %d" % self.size)
|
||||
index += 2
|
||||
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
self.productManufacturer = self.data[index + 1: index + templen + 1]
|
||||
index += templen + 1
|
||||
d_print("decode productManufacturer:%s" % self.productManufacturer)
|
||||
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
self.productName = self.data[index + 1: index + templen + 1]
|
||||
index += templen + 1
|
||||
d_print("decode productName:%s" % self.productName)
|
||||
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
self.productPartModelName = self.data[index + 1: index + templen + 1]
|
||||
index += templen + 1
|
||||
d_print("decode productPartModelName:%s" % self.productPartModelName)
|
||||
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
self.productVersion = self.data[index + 1: index + templen + 1]
|
||||
index += templen + 1
|
||||
d_print("decode productVersion:%s" % self.productVersion)
|
||||
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
self.productSerialNumber = self.data[index + 1: index + templen + 1]
|
||||
index += templen + 1
|
||||
d_print("decode productSerialNumber:%s" % self.productSerialNumber)
|
||||
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
self.productAssetTag = self.data[index + 1: index + templen + 1]
|
||||
index += templen + 1
|
||||
d_print("decode productAssetTag:%s" % self.productAssetTag)
|
||||
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
self.fruFileId = self.data[index + 1: index + templen + 1]
|
||||
index += templen + 1
|
||||
d_print("decode fruFileId:%s" % self.fruFileId)
|
||||
|
||||
for i in range(1, 11):
|
||||
valtmp = "productextra%d" % i
|
||||
if self.data[index] != chr(0xc1) and index < self.size - 1:
|
||||
templen = FruUtil.decodeLength(self.data[index])
|
||||
if templen == 0:
|
||||
break
|
||||
tmpval = self.data[index + 1: index + templen + 1]
|
||||
d_print("decode boardextra%d:%s" % (i, tmpval))
|
||||
setattr(self, valtmp, tmpval)
|
||||
index += templen + 1
|
||||
else:
|
||||
break
|
||||
|
||||
@property
|
||||
def productVersion(self):
|
||||
return self._productVersion
|
||||
|
||||
@productVersion.setter
|
||||
def productVersion(self, name):
|
||||
self._productVersion = name
|
||||
|
||||
@property
|
||||
def areaversion(self):
|
||||
self._areaversion = self.COMMON_HEAD_VERSION
|
||||
return self._areaversion
|
||||
|
||||
@areaversion.setter
|
||||
def areaversion(self, name):
|
||||
self._areaversion = name
|
||||
|
||||
@property
|
||||
def language(self):
|
||||
self._language = 25
|
||||
return self._language
|
||||
|
||||
@property
|
||||
def productManufacturer(self):
|
||||
return self._productManufacturer
|
||||
|
||||
@productManufacturer.setter
|
||||
def productManufacturer(self, name):
|
||||
self._productManufacturer = name
|
||||
|
||||
@property
|
||||
def productName(self):
|
||||
return self._productName
|
||||
|
||||
@productName.setter
|
||||
def productName(self, name):
|
||||
self._productName = name
|
||||
|
||||
@property
|
||||
def productPartModelName(self):
|
||||
return self._productPartModelName
|
||||
|
||||
@productPartModelName.setter
|
||||
def productPartModelName(self, name):
|
||||
self._productPartModelName = name
|
||||
|
||||
@property
|
||||
def productSerialNumber(self):
|
||||
return self._productSerialNumber
|
||||
|
||||
@productSerialNumber.setter
|
||||
def productSerialNumber(self, name):
|
||||
self._productSerialNumber = name
|
||||
|
||||
@property
|
||||
def productAssetTag(self):
|
||||
return self._productAssetTag
|
||||
|
||||
@productAssetTag.setter
|
||||
def productAssetTag(self, name):
|
||||
self._productAssetTag = name
|
||||
|
||||
@property
|
||||
def fruFileId(self):
|
||||
return self._FRUFileID
|
||||
|
||||
@fruFileId.setter
|
||||
def fruFileId(self, name):
|
||||
self._FRUFileID = name
|
||||
|
||||
def recalcute(self):
|
||||
d_print("product version:%x" % ord(self.areaversion))
|
||||
d_print("product length:%d" % self.size)
|
||||
d_print("product language:%x" % self.language)
|
||||
self.data = chr(ord(self.areaversion)) + \
|
||||
chr(self.size / 8) + chr(self.language)
|
||||
|
||||
typelength = FruUtil.getTypeLength(self.productManufacturer)
|
||||
self.data += chr(typelength)
|
||||
self.data += self.productManufacturer
|
||||
|
||||
self.data += chr(FruUtil.getTypeLength(self.productName))
|
||||
self.data += self.productName
|
||||
|
||||
self.data += chr(FruUtil.getTypeLength(self.productPartModelName))
|
||||
self.data += self.productPartModelName
|
||||
|
||||
self.data += chr(FruUtil.getTypeLength(self.productVersion))
|
||||
self.data += self.productVersion
|
||||
|
||||
self.data += chr(FruUtil.getTypeLength(self.productSerialNumber))
|
||||
self.data += self.productSerialNumber
|
||||
|
||||
self.data += chr(FruUtil.getTypeLength(self.productAssetTag))
|
||||
if self.productAssetTag is not None:
|
||||
self.data += self.productAssetTag
|
||||
|
||||
self.data += chr(FruUtil.getTypeLength(self.fruFileId))
|
||||
self.data += self.fruFileId
|
||||
|
||||
# whether the extended field exists or not
|
||||
for i in range(1, 11):
|
||||
valtmp = "productextra%d" % i
|
||||
if hasattr(self, valtmp):
|
||||
valtmpval = getattr(self, valtmp)
|
||||
d_print("boardInfoArea productextra%d:%s" % (i, valtmpval))
|
||||
self.data += chr(FruUtil.getTypeLength(valtmpval))
|
||||
if valtmpval is None:
|
||||
pass
|
||||
else:
|
||||
self.data += valtmpval
|
||||
else:
|
||||
break
|
||||
|
||||
self.data += chr(0xc1)
|
||||
if len(self.data) > (self.size - 1):
|
||||
incr = (len(self.data) - self.size) / 8 + 1
|
||||
self.size += incr * 8
|
||||
d_print("self.data:%d" % len(self.data))
|
||||
d_print("self.size:%d" % self.size)
|
||||
|
||||
self.data = self.data[0:1] + chr(self.size / 8) + self.data[2:]
|
||||
self.data = self.data.ljust((self.size - 1), self.INITVALUE)
|
||||
checksum = FruUtil.checksum(self.data)
|
||||
d_print("board info checksum:%x" % checksum)
|
||||
self.data += chr(checksum)
|
||||
|
||||
|
||||
class MultiRecordArea(BaseArea):
|
||||
pass
|
||||
|
||||
|
||||
class Field(object):
|
||||
|
||||
def __init__(self, fieldType="ASCII", fieldData=""):
|
||||
self.fieldData = fieldData
|
||||
self.fieldType = fieldType
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return self._data
|
||||
|
||||
@property
|
||||
def fieldType(self):
|
||||
return self._fieldType
|
||||
|
||||
@property
|
||||
def fieldData(self):
|
||||
return self._fieldData
|
||||
|
||||
|
||||
class ipmifru(BaseArea):
|
||||
_BoardInfoArea = None
|
||||
_ProductInfoArea = None
|
||||
_InternalUseArea = None
|
||||
_ChassisInfoArea = None
|
||||
_multiRecordArea = None
|
||||
_productinfoAreaOffset = BaseArea.INITVALUE
|
||||
_boardInfoAreaOffset = BaseArea.INITVALUE
|
||||
_internalUserAreaOffset = BaseArea.INITVALUE
|
||||
_chassicInfoAreaOffset = BaseArea.INITVALUE
|
||||
_multiRecordAreaOffset = BaseArea.INITVALUE
|
||||
_bindata = None
|
||||
_bodybin = None
|
||||
_version = BaseArea.COMMON_HEAD_VERSION
|
||||
_zeroCheckSum = None
|
||||
|
||||
def __str__(self):
|
||||
tmpstr = ""
|
||||
if self.boardInfoArea.isPresent:
|
||||
tmpstr += "\nboardinfoarea: \n"
|
||||
tmpstr += self.boardInfoArea.__str__()
|
||||
if self.productInfoArea.isPresent:
|
||||
tmpstr += "\nproductinfoarea: \n"
|
||||
tmpstr += self.productInfoArea.__str__()
|
||||
return tmpstr
|
||||
|
||||
def decodeBin(self, eeprom):
|
||||
commonHead = eeprom[0:8]
|
||||
d_print("decode version %x" % ord(commonHead[0]))
|
||||
if self.COMMON_HEAD_VERSION != commonHead[0]:
|
||||
raise FruException("HEAD VERSION error,not Fru format!", -10)
|
||||
if FruUtil.checksum(commonHead[0:7]) != ord(commonHead[7]):
|
||||
strtemp = "check header checksum error [cal:%02x data:%02x]" % (
|
||||
FruUtil.checksum(commonHead[0:7]), ord(commonHead[7]))
|
||||
raise FruException(strtemp, -3)
|
||||
if commonHead[1] != self.INITVALUE:
|
||||
d_print("Internal Use Area is present")
|
||||
self.internalUseArea = InternalUseArea(
|
||||
name="Internal Use Area", size=self.SUGGESTED_SIZE_INTERNAL_USE_AREA)
|
||||
self.internalUseArea.isPresent = True
|
||||
self.internalUserAreaOffset = ord(commonHead[1])
|
||||
self.internalUseArea.data = eeprom[self.internalUserAreaOffset * 8: (
|
||||
self.internalUserAreaOffset * 8 + self.internalUseArea.size)]
|
||||
if commonHead[2] != self.INITVALUE:
|
||||
d_print("Chassis Info Area is present")
|
||||
self.chassisInfoArea = ChassisInfoArea(
|
||||
name="Chassis Info Area", size=self.SUGGESTED_SIZE_CHASSIS_INFO_AREA)
|
||||
self.chassisInfoArea.isPresent = True
|
||||
self.chassicInfoAreaOffset = ord(commonHead[2])
|
||||
self.chassisInfoArea.data = eeprom[self.chassicInfoAreaOffset * 8: (
|
||||
self.chassicInfoAreaOffset * 8 + self.chassisInfoArea.size)]
|
||||
if commonHead[3] != self.INITVALUE:
|
||||
self.boardInfoArea = BoardInfoArea(
|
||||
name="Board Info Area", size=self.SUGGESTED_SIZE_BOARD_INFO_AREA)
|
||||
self.boardInfoArea.isPresent = True
|
||||
self.boardInfoAreaOffset = ord(commonHead[3])
|
||||
self.boardInfoArea.size = ord(
|
||||
eeprom[self.boardInfoAreaOffset * 8 + 1]) * 8
|
||||
d_print("Board Info Area is present size:%d" %
|
||||
(self.boardInfoArea.size))
|
||||
self.boardInfoArea.data = eeprom[self.boardInfoAreaOffset * 8: (
|
||||
self.boardInfoAreaOffset * 8 + self.boardInfoArea.size)]
|
||||
if FruUtil.checksum(self.boardInfoArea.data[:-1]) != ord(self.boardInfoArea.data[-1:]):
|
||||
print("check boardInfoArea checksum error[cal:%02x data:%02x]" % \
|
||||
(FruUtil.checksum(
|
||||
self.boardInfoArea.data[:-1]), ord(self.boardInfoArea.data[-1:])))
|
||||
sys.exit(-1)
|
||||
self.boardInfoArea.decodedata()
|
||||
if commonHead[4] != self.INITVALUE:
|
||||
d_print("Product Info Area is present")
|
||||
self.productInfoArea = ProductInfoArea(
|
||||
name="Product Info Area ", size=self.SUGGESTED_SIZE_PRODUCT_INFO_AREA)
|
||||
self.productInfoArea.isPresent = True
|
||||
self.productinfoAreaOffset = ord(commonHead[4])
|
||||
d_print("length offset value: %02x" %
|
||||
ord(eeprom[self.productinfoAreaOffset * 8 + 1]))
|
||||
self.productInfoArea.size = ord(
|
||||
eeprom[self.productinfoAreaOffset * 8 + 1]) * 8
|
||||
d_print("Product Info Area is present size:%d" %
|
||||
(self.productInfoArea.size))
|
||||
|
||||
self.productInfoArea.data = eeprom[self.productinfoAreaOffset * 8: (
|
||||
self.productinfoAreaOffset * 8 + self.productInfoArea.size)]
|
||||
if FruUtil.checksum(self.productInfoArea.data[:-1]) != ord(self.productInfoArea.data[-1:]):
|
||||
strtmp = "check productInfoArea checksum error [cal:%02x data:%02x]" % (
|
||||
FruUtil.checksum(self.productInfoArea.data[:-1]), ord(self.productInfoArea.data[-1:]))
|
||||
raise FruException(strtmp, -3)
|
||||
self.productInfoArea.decodedata()
|
||||
if commonHead[5] != self.INITVALUE:
|
||||
self.multiRecordArea = MultiRecordArea(
|
||||
name="MultiRecord record Area ")
|
||||
d_print("MultiRecord record present")
|
||||
self.multiRecordArea.isPresent = True
|
||||
self.multiRecordAreaOffset = ord(commonHead[5])
|
||||
self.multiRecordArea.data = eeprom[self.multiRecordAreaOffset * 8: (
|
||||
self.multiRecordAreaOffset * 8 + self.multiRecordArea.size)]
|
||||
|
||||
def initDefault(self):
|
||||
self.version = self.COMMON_HEAD_VERSION
|
||||
self.internalUserAreaOffset = self.INITVALUE
|
||||
self.chassicInfoAreaOffset = self.INITVALUE
|
||||
self.boardInfoAreaOffset = self.INITVALUE
|
||||
self.productinfoAreaOffset = self.INITVALUE
|
||||
self.multiRecordAreaOffset = self.INITVALUE
|
||||
self.PAD = self.INITVALUE
|
||||
self.zeroCheckSum = self.INITVALUE
|
||||
self.offset = self.SUGGESTED_SIZE_COMMON_HEADER
|
||||
self.productInfoArea = None
|
||||
self.internalUseArea = None
|
||||
self.boardInfoArea = None
|
||||
self.chassisInfoArea = None
|
||||
self.multiRecordArea = None
|
||||
# self.recalcute()
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
return self._version
|
||||
|
||||
@version.setter
|
||||
def version(self, name):
|
||||
self._version = name
|
||||
|
||||
@property
|
||||
def internalUserAreaOffset(self):
|
||||
return self._internalUserAreaOffset
|
||||
|
||||
@internalUserAreaOffset.setter
|
||||
def internalUserAreaOffset(self, obj):
|
||||
self._internalUserAreaOffset = obj
|
||||
|
||||
@property
|
||||
def chassicInfoAreaOffset(self):
|
||||
return self._chassicInfoAreaOffset
|
||||
|
||||
@chassicInfoAreaOffset.setter
|
||||
def chassicInfoAreaOffset(self, obj):
|
||||
self._chassicInfoAreaOffset = obj
|
||||
|
||||
@property
|
||||
def productinfoAreaOffset(self):
|
||||
return self._productinfoAreaOffset
|
||||
|
||||
@productinfoAreaOffset.setter
|
||||
def productinfoAreaOffset(self, obj):
|
||||
self._productinfoAreaOffset = obj
|
||||
|
||||
@property
|
||||
def boardInfoAreaOffset(self):
|
||||
return self._boardInfoAreaOffset
|
||||
|
||||
@boardInfoAreaOffset.setter
|
||||
def boardInfoAreaOffset(self, obj):
|
||||
self._boardInfoAreaOffset = obj
|
||||
|
||||
@property
|
||||
def multiRecordAreaOffset(self):
|
||||
return self._multiRecordAreaOffset
|
||||
|
||||
@multiRecordAreaOffset.setter
|
||||
def multiRecordAreaOffset(self, obj):
|
||||
self._multiRecordAreaOffset = obj
|
||||
|
||||
@property
|
||||
def zeroCheckSum(self):
|
||||
return self._zeroCheckSum
|
||||
|
||||
@zeroCheckSum.setter
|
||||
def zeroCheckSum(self, obj):
|
||||
self._zeroCheckSum = obj
|
||||
|
||||
@property
|
||||
def productInfoArea(self):
|
||||
return self._ProductInfoArea
|
||||
|
||||
@productInfoArea.setter
|
||||
def productInfoArea(self, obj):
|
||||
self._ProductInfoArea = obj
|
||||
|
||||
@property
|
||||
def internalUseArea(self):
|
||||
return self._InternalUseArea
|
||||
|
||||
@internalUseArea.setter
|
||||
def internalUseArea(self, obj):
|
||||
self.internalUseArea = obj
|
||||
|
||||
@property
|
||||
def boardInfoArea(self):
|
||||
return self._BoardInfoArea
|
||||
|
||||
@boardInfoArea.setter
|
||||
def boardInfoArea(self, obj):
|
||||
self._BoardInfoArea = obj
|
||||
|
||||
@property
|
||||
def chassisInfoArea(self):
|
||||
return self._ChassisInfoArea
|
||||
|
||||
@chassisInfoArea.setter
|
||||
def chassisInfoArea(self, obj):
|
||||
self._ChassisInfoArea = obj
|
||||
|
||||
@property
|
||||
def multiRecordArea(self):
|
||||
return self._multiRecordArea
|
||||
|
||||
@multiRecordArea.setter
|
||||
def multiRecordArea(self, obj):
|
||||
self._multiRecordArea = obj
|
||||
|
||||
@property
|
||||
def bindata(self):
|
||||
return self._bindata
|
||||
|
||||
@bindata.setter
|
||||
def bindata(self, obj):
|
||||
self._bindata = obj
|
||||
|
||||
@property
|
||||
def bodybin(self):
|
||||
return self._bodybin
|
||||
|
||||
@bodybin.setter
|
||||
def bodybin(self, obj):
|
||||
self._bodybin = obj
|
||||
|
||||
def recalcuteCommonHead(self):
|
||||
self.bindata = ""
|
||||
self.offset = self.SUGGESTED_SIZE_COMMON_HEADER
|
||||
d_print("common Header %d" % self.offset)
|
||||
if self.internalUseArea is not None and self.internalUseArea.isPresent:
|
||||
self.internalUserAreaOffset = self.offset / 8
|
||||
self.offset += self.internalUseArea.size
|
||||
d_print("internalUseArea is present offset:%d" % self.offset)
|
||||
|
||||
if self.chassisInfoArea is not None and self.chassisInfoArea.isPresent:
|
||||
self.chassicInfoAreaOffset = self.offset / 8
|
||||
self.offset += self.chassisInfoArea.size
|
||||
d_print("chassisInfoArea is present offset:%d" % self.offset)
|
||||
|
||||
if self.boardInfoArea is not None and self.boardInfoArea.isPresent:
|
||||
self.boardInfoAreaOffset = self.offset / 8
|
||||
self.offset += self.boardInfoArea.size
|
||||
d_print("boardInfoArea is present offset:%d" % self.offset)
|
||||
d_print("boardInfoArea is present size:%d" %
|
||||
self.boardInfoArea.size)
|
||||
|
||||
if self.productInfoArea is not None and self.productInfoArea.isPresent:
|
||||
self.productinfoAreaOffset = self.offset / 8
|
||||
self.offset += self.productInfoArea.size
|
||||
d_print("productInfoArea is present offset:%d" % self.offset)
|
||||
|
||||
if self.multiRecordArea is not None and self.multiRecordArea.isPresent:
|
||||
self.multiRecordAreaOffset = self.offset / 8
|
||||
d_print("multiRecordArea is present offset:%d" % self.offset)
|
||||
|
||||
if self.internalUserAreaOffset == self.INITVALUE:
|
||||
self.internalUserAreaOffset = 0
|
||||
if self.productinfoAreaOffset == self.INITVALUE:
|
||||
self.productinfoAreaOffset = 0
|
||||
if self.chassicInfoAreaOffset == self.INITVALUE:
|
||||
self.chassicInfoAreaOffset = 0
|
||||
if self.boardInfoAreaOffset == self.INITVALUE:
|
||||
self.boardInfoAreaOffset = 0
|
||||
if self.multiRecordAreaOffset == self.INITVALUE:
|
||||
self.multiRecordAreaOffset = 0
|
||||
|
||||
self.zeroCheckSum = (0x100 - ord(self.version) - self.internalUserAreaOffset - self.chassicInfoAreaOffset - self.productinfoAreaOffset
|
||||
- self.boardInfoAreaOffset - self.multiRecordAreaOffset) & 0xff
|
||||
d_print("zerochecksum:%x" % self.zeroCheckSum)
|
||||
self.data = self.version + chr(self.internalUserAreaOffset) + chr(self.chassicInfoAreaOffset) + chr(
|
||||
self.boardInfoAreaOffset) + chr(self.productinfoAreaOffset) + chr(self.multiRecordAreaOffset) + self.INITVALUE + chr(self.zeroCheckSum)
|
||||
|
||||
self.bindata = self.data + self.bodybin
|
||||
totallen = len(self.bindata)
|
||||
d_print("totallen %d" % totallen)
|
||||
if (totallen < 256):
|
||||
self.bindata = self.bindata.ljust(256, self.INITVALUE)
|
||||
else:
|
||||
raise FruException('bin data more than 256', -2)
|
||||
|
||||
def recalcutebin(self):
|
||||
self.bodybin = ""
|
||||
if self.internalUseArea is not None and self.internalUseArea.isPresent:
|
||||
d_print("internalUseArea present")
|
||||
self.bodybin += self.internalUseArea.data
|
||||
if self.chassisInfoArea is not None and self.chassisInfoArea.isPresent:
|
||||
d_print("chassisInfoArea present")
|
||||
self.bodybin += self.chassisInfoArea.data
|
||||
if self.boardInfoArea is not None and self.boardInfoArea.isPresent:
|
||||
d_print("boardInfoArea present")
|
||||
self.boardInfoArea.recalcute()
|
||||
self.bodybin += self.boardInfoArea.data
|
||||
if self.productInfoArea is not None and self.productInfoArea.isPresent:
|
||||
d_print("productInfoAreapresent")
|
||||
self.productInfoArea.recalcute()
|
||||
self.bodybin += self.productInfoArea.data
|
||||
if self.multiRecordArea is not None and self.multiRecordArea.isPresent:
|
||||
d_print("multiRecordArea present")
|
||||
self.bodybin += self.productInfoArea.data
|
||||
|
||||
def recalcute(self):
|
||||
self.recalcutebin()
|
||||
self.recalcuteCommonHead()
|
@ -0,0 +1,23 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
import os
|
||||
|
||||
def get_machine_info():
|
||||
if not os.path.isfile('/host/machine.conf'):
|
||||
return None
|
||||
machine_vars = {}
|
||||
with open('/host/machine.conf') as machine_file:
|
||||
for line in machine_file:
|
||||
tokens = line.split('=')
|
||||
if len(tokens) < 2:
|
||||
continue
|
||||
machine_vars[tokens[0]] = tokens[1].strip()
|
||||
return machine_vars
|
||||
|
||||
def get_platform_info(machine_info):
|
||||
if machine_info != None:
|
||||
if 'onie_platform' in machine_info:
|
||||
return machine_info['onie_platform']
|
||||
elif 'aboot_platform' in machine_info:
|
||||
return machine_info['aboot_platform']
|
||||
return None
|
||||
|
@ -0,0 +1,67 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import logging
|
||||
from syslog import (
|
||||
syslog,
|
||||
openlog,
|
||||
LOG_WARNING,
|
||||
LOG_CRIT,
|
||||
LOG_DEBUG,
|
||||
LOG_ERR,
|
||||
LOG_PID,
|
||||
LOG_INFO,
|
||||
)
|
||||
|
||||
class Logger():
|
||||
def __init__(self, prefix, filepath=None, syslog=False, dbg_mask=0x0):
|
||||
self.logger = None
|
||||
if syslog is False:
|
||||
if filepath is None:
|
||||
raise AttributeError("filepath needed")
|
||||
|
||||
# init logging
|
||||
formatter = logging.Formatter( "%(asctime)s %(levelname)s %(filename)s[%(funcName)s][%(lineno)s]: %(message)s")
|
||||
handler = logging.FileHandler(self.filepath)
|
||||
handler.setFormatter(formatter)
|
||||
self.logger = logging.getLogger(__name__)
|
||||
self.logger.setLevel(logging.DEBUG)
|
||||
self.logger.addHandler(handler)
|
||||
|
||||
self.prefix = prefix
|
||||
self.use_syslog = syslog
|
||||
self.dbg_mask = dbg_mask
|
||||
|
||||
def info(self, s):
|
||||
if self.use_syslog:
|
||||
self._syslog(s, LOG_INFO)
|
||||
else:
|
||||
self.logger.info(s)
|
||||
|
||||
def debug(self, dbg_lvl, s):
|
||||
if dbg_lvl & self.dbg_mask:
|
||||
if self.use_syslog:
|
||||
self._syslog(s, LOG_DEBUG)
|
||||
else:
|
||||
self.logger.debug(s)
|
||||
|
||||
def warn(self, s):
|
||||
if self.use_syslog:
|
||||
self._syslog(s, LOG_WARNING)
|
||||
else:
|
||||
self.logger.warning(s)
|
||||
|
||||
def error(self, s):
|
||||
if self.use_syslog:
|
||||
self._syslog(s, LOG_ERR)
|
||||
else:
|
||||
self.logger.error(s)
|
||||
|
||||
def crit(self, s):
|
||||
if self.use_syslog:
|
||||
self._syslog(s, LOG_CRIT)
|
||||
else:
|
||||
self.logger.critical(s)
|
||||
|
||||
def _syslog(self, s, t):
|
||||
openlog(self.prefix, LOG_PID)
|
||||
syslog(t, s)
|
@ -0,0 +1,705 @@
|
||||
"""smbus2 - A drop-in replacement for smbus-cffi/smbus-python"""
|
||||
# The MIT License (MIT)
|
||||
# Copyright (c) 2017 Karl-Petter Lindegaard
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
import os
|
||||
import sys
|
||||
from fcntl import ioctl
|
||||
from ctypes import c_uint32, c_uint8, c_uint16, c_char, POINTER, Structure, Array, Union, create_string_buffer, string_at
|
||||
|
||||
|
||||
# Commands from uapi/linux/i2c-dev.h
|
||||
I2C_SLAVE = 0x0703 # Use this slave address
|
||||
I2C_SLAVE_FORCE = 0x0706 # Use this slave address, even if it is already in use by a driver!
|
||||
I2C_FUNCS = 0x0705 # Get the adapter functionality mask
|
||||
I2C_RDWR = 0x0707 # Combined R/W transfer (one STOP only)
|
||||
I2C_SMBUS = 0x0720 # SMBus transfer. Takes pointer to i2c_smbus_ioctl_data
|
||||
|
||||
# SMBus transfer read or write markers from uapi/linux/i2c.h
|
||||
I2C_SMBUS_WRITE = 0
|
||||
I2C_SMBUS_READ = 1
|
||||
|
||||
# Size identifiers uapi/linux/i2c.h
|
||||
I2C_SMBUS_QUICK = 0
|
||||
I2C_SMBUS_BYTE = 1
|
||||
I2C_SMBUS_BYTE_DATA = 2
|
||||
I2C_SMBUS_WORD_DATA = 3
|
||||
I2C_SMBUS_PROC_CALL = 4
|
||||
I2C_SMBUS_BLOCK_DATA = 5 # This isn't supported by Pure-I2C drivers with SMBUS emulation, like those in RaspberryPi, OrangePi, etc :(
|
||||
I2C_SMBUS_BLOCK_PROC_CALL = 7 # Like I2C_SMBUS_BLOCK_DATA, it isn't supported by Pure-I2C drivers either.
|
||||
I2C_SMBUS_I2C_BLOCK_DATA = 8
|
||||
I2C_SMBUS_BLOCK_MAX = 32
|
||||
|
||||
# To determine what functionality is present (uapi/linux/i2c.h)
|
||||
try:
|
||||
from enum import IntFlag
|
||||
except ImportError:
|
||||
IntFlag = int
|
||||
|
||||
|
||||
class I2cFunc(IntFlag):
|
||||
"""
|
||||
These flags identify the operations supported by an I2C/SMBus device.
|
||||
|
||||
You can test these flags on your `smbus.funcs`
|
||||
|
||||
On newer python versions, I2cFunc is an IntFlag enum, but it
|
||||
falls back to class with a bunch of int constants on older releases.
|
||||
"""
|
||||
I2C = 0x00000001
|
||||
ADDR_10BIT = 0x00000002
|
||||
PROTOCOL_MANGLING = 0x00000004 # I2C_M_IGNORE_NAK etc.
|
||||
SMBUS_PEC = 0x00000008
|
||||
NOSTART = 0x00000010 # I2C_M_NOSTART
|
||||
SLAVE = 0x00000020
|
||||
SMBUS_BLOCK_PROC_CALL = 0x00008000 # SMBus 2.0
|
||||
SMBUS_QUICK = 0x00010000
|
||||
SMBUS_READ_BYTE = 0x00020000
|
||||
SMBUS_WRITE_BYTE = 0x00040000
|
||||
SMBUS_READ_BYTE_DATA = 0x00080000
|
||||
SMBUS_WRITE_BYTE_DATA = 0x00100000
|
||||
SMBUS_READ_WORD_DATA = 0x00200000
|
||||
SMBUS_WRITE_WORD_DATA = 0x00400000
|
||||
SMBUS_PROC_CALL = 0x00800000
|
||||
SMBUS_READ_BLOCK_DATA = 0x01000000
|
||||
SMBUS_WRITE_BLOCK_DATA = 0x02000000
|
||||
SMBUS_READ_I2C_BLOCK = 0x04000000 # I2C-like block xfer
|
||||
SMBUS_WRITE_I2C_BLOCK = 0x08000000 # w/ 1-byte reg. addr.
|
||||
SMBUS_HOST_NOTIFY = 0x10000000
|
||||
|
||||
SMBUS_BYTE = 0x00060000
|
||||
SMBUS_BYTE_DATA = 0x00180000
|
||||
SMBUS_WORD_DATA = 0x00600000
|
||||
SMBUS_BLOCK_DATA = 0x03000000
|
||||
SMBUS_I2C_BLOCK = 0x0c000000
|
||||
SMBUS_EMUL = 0x0eff0008
|
||||
|
||||
|
||||
# i2c_msg flags from uapi/linux/i2c.h
|
||||
I2C_M_RD = 0x0001
|
||||
|
||||
# Pointer definitions
|
||||
LP_c_uint8 = POINTER(c_uint8)
|
||||
LP_c_uint16 = POINTER(c_uint16)
|
||||
LP_c_uint32 = POINTER(c_uint32)
|
||||
|
||||
|
||||
#############################################################
|
||||
# Type definitions as in i2c.h
|
||||
|
||||
|
||||
class i2c_smbus_data(Array):
|
||||
"""
|
||||
Adaptation of the i2c_smbus_data union in ``i2c.h``.
|
||||
|
||||
Data for SMBus messages.
|
||||
"""
|
||||
_length_ = I2C_SMBUS_BLOCK_MAX + 2
|
||||
_type_ = c_uint8
|
||||
|
||||
|
||||
class union_i2c_smbus_data(Union):
|
||||
_fields_ = [
|
||||
("byte", c_uint8),
|
||||
("word", c_uint16),
|
||||
("block", i2c_smbus_data)
|
||||
]
|
||||
|
||||
|
||||
union_pointer_type = POINTER(union_i2c_smbus_data)
|
||||
|
||||
|
||||
class i2c_smbus_ioctl_data(Structure):
|
||||
"""
|
||||
As defined in ``i2c-dev.h``.
|
||||
"""
|
||||
_fields_ = [
|
||||
('read_write', c_uint8),
|
||||
('command', c_uint8),
|
||||
('size', c_uint32),
|
||||
('data', union_pointer_type)]
|
||||
__slots__ = [name for name, type in _fields_]
|
||||
|
||||
@staticmethod
|
||||
def create(read_write=I2C_SMBUS_READ, command=0, size=I2C_SMBUS_BYTE_DATA):
|
||||
u = union_i2c_smbus_data()
|
||||
return i2c_smbus_ioctl_data(
|
||||
read_write=read_write, command=command, size=size,
|
||||
data=union_pointer_type(u))
|
||||
|
||||
|
||||
#############################################################
|
||||
# Type definitions for i2c_rdwr combined transactions
|
||||
|
||||
|
||||
class i2c_msg(Structure):
|
||||
"""
|
||||
As defined in ``i2c.h``.
|
||||
"""
|
||||
_fields_ = [
|
||||
('addr', c_uint16),
|
||||
('flags', c_uint16),
|
||||
('len', c_uint16),
|
||||
('buf', POINTER(c_char))]
|
||||
|
||||
def __iter__(self):
|
||||
""" Iterator / Generator
|
||||
|
||||
:return: iterates over :py:attr:`buf`
|
||||
:rtype: :py:class:`generator` which returns int values
|
||||
"""
|
||||
idx = 0
|
||||
while idx < self.len:
|
||||
yield ord(self.buf[idx])
|
||||
idx += 1
|
||||
|
||||
def __len__(self):
|
||||
return self.len
|
||||
|
||||
def __bytes__(self):
|
||||
return string_at(self.buf, self.len)
|
||||
|
||||
def __repr__(self):
|
||||
return 'i2c_msg(%d,%d,%r)' % (self.addr, self.flags, self.__bytes__())
|
||||
|
||||
def __str__(self):
|
||||
s = self.__bytes__()
|
||||
if sys.version_info.major >= 3:
|
||||
s = ''.join(map(chr, s))
|
||||
return s
|
||||
|
||||
@staticmethod
|
||||
def read(address, length):
|
||||
"""
|
||||
Prepares an i2c read transaction.
|
||||
|
||||
:param address: Slave address.
|
||||
:type: address: int
|
||||
:param length: Number of bytes to read.
|
||||
:type: length: int
|
||||
:return: New :py:class:`i2c_msg` instance for read operation.
|
||||
:rtype: :py:class:`i2c_msg`
|
||||
"""
|
||||
arr = create_string_buffer(length)
|
||||
return i2c_msg(
|
||||
addr=address, flags=I2C_M_RD, len=length,
|
||||
buf=arr)
|
||||
|
||||
@staticmethod
|
||||
def write(address, buf):
|
||||
"""
|
||||
Prepares an i2c write transaction.
|
||||
|
||||
:param address: Slave address.
|
||||
:type address: int
|
||||
:param buf: Bytes to write. Either list of values or str.
|
||||
:type buf: list
|
||||
:return: New :py:class:`i2c_msg` instance for write operation.
|
||||
:rtype: :py:class:`i2c_msg`
|
||||
"""
|
||||
if sys.version_info.major >= 3:
|
||||
if type(buf) is str:
|
||||
buf = bytes(map(ord, buf))
|
||||
else:
|
||||
buf = bytes(buf)
|
||||
else:
|
||||
if type(buf) is not str:
|
||||
buf = ''.join([chr(x) for x in buf])
|
||||
arr = create_string_buffer(buf, len(buf))
|
||||
return i2c_msg(
|
||||
addr=address, flags=0, len=len(arr),
|
||||
buf=arr)
|
||||
|
||||
|
||||
class i2c_rdwr_ioctl_data(Structure):
|
||||
"""
|
||||
As defined in ``i2c-dev.h``.
|
||||
"""
|
||||
_fields_ = [
|
||||
('msgs', POINTER(i2c_msg)),
|
||||
('nmsgs', c_uint32)
|
||||
]
|
||||
__slots__ = [name for name, type in _fields_]
|
||||
|
||||
@staticmethod
|
||||
def create(*i2c_msg_instances):
|
||||
"""
|
||||
Factory method for creating a i2c_rdwr_ioctl_data struct that can
|
||||
be called with ``ioctl(fd, I2C_RDWR, data)``.
|
||||
|
||||
:param i2c_msg_instances: Up to 42 i2c_msg instances
|
||||
:rtype: i2c_rdwr_ioctl_data
|
||||
"""
|
||||
n_msg = len(i2c_msg_instances)
|
||||
msg_array = (i2c_msg * n_msg)(*i2c_msg_instances)
|
||||
return i2c_rdwr_ioctl_data(
|
||||
msgs=msg_array,
|
||||
nmsgs=n_msg
|
||||
)
|
||||
|
||||
|
||||
#############################################################
|
||||
|
||||
|
||||
class SMBus(object):
|
||||
|
||||
def __init__(self, bus=None, force=False):
|
||||
"""
|
||||
Initialize and (optionally) open an i2c bus connection.
|
||||
|
||||
:param bus: i2c bus number (e.g. 0 or 1)
|
||||
or an absolute file path (e.g. `/dev/i2c-42`).
|
||||
If not given, a subsequent call to ``open()`` is required.
|
||||
:type bus: int or str
|
||||
:param force: force using the slave address even when driver is
|
||||
already using it.
|
||||
:type force: boolean
|
||||
"""
|
||||
self.fd = None
|
||||
self.funcs = I2cFunc(0)
|
||||
if bus is not None:
|
||||
self.open(bus)
|
||||
self.address = None
|
||||
self.force = force
|
||||
self._force_last = None
|
||||
|
||||
def __enter__(self):
|
||||
"""Enter handler."""
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
"""Exit handler."""
|
||||
self.close()
|
||||
|
||||
def open(self, bus):
|
||||
"""
|
||||
Open a given i2c bus.
|
||||
|
||||
:param bus: i2c bus number (e.g. 0 or 1)
|
||||
or an absolute file path (e.g. '/dev/i2c-42').
|
||||
:type bus: int or str
|
||||
:raise TypeError: if type(bus) is not in (int, str)
|
||||
"""
|
||||
if isinstance(bus, int):
|
||||
filepath = "/dev/i2c-{}".format(bus)
|
||||
elif isinstance(bus, str):
|
||||
filepath = bus
|
||||
else:
|
||||
raise TypeError("Unexpected type(bus)={}".format(type(bus)))
|
||||
|
||||
self.fd = os.open(filepath, os.O_RDWR)
|
||||
self.funcs = self._get_funcs()
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
Close the i2c connection.
|
||||
"""
|
||||
if self.fd:
|
||||
os.close(self.fd)
|
||||
self.fd = None
|
||||
|
||||
def _set_address(self, address, force=None):
|
||||
"""
|
||||
Set i2c slave address to use for subsequent calls.
|
||||
|
||||
:param address:
|
||||
:type address: int
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
"""
|
||||
force = force if force is not None else self.force
|
||||
if self.address != address or self._force_last != force:
|
||||
if force is True:
|
||||
ioctl(self.fd, I2C_SLAVE_FORCE, address)
|
||||
else:
|
||||
ioctl(self.fd, I2C_SLAVE, address)
|
||||
self.address = address
|
||||
self._force_last = force
|
||||
|
||||
def _get_funcs(self):
|
||||
"""
|
||||
Returns a 32-bit value stating supported I2C functions.
|
||||
|
||||
:rtype: int
|
||||
"""
|
||||
f = c_uint32()
|
||||
ioctl(self.fd, I2C_FUNCS, f)
|
||||
return f.value
|
||||
|
||||
def write_quick(self, i2c_addr, force=None):
|
||||
"""
|
||||
Perform quick transaction. Throws IOError if unsuccessful.
|
||||
:param i2c_addr: i2c address
|
||||
:type i2c_addr: int
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
"""
|
||||
self._set_address(i2c_addr, force=force)
|
||||
msg = i2c_smbus_ioctl_data.create(
|
||||
read_write=I2C_SMBUS_WRITE, command=0, size=I2C_SMBUS_QUICK)
|
||||
ioctl(self.fd, I2C_SMBUS, msg)
|
||||
|
||||
def read_byte(self, i2c_addr, force=None):
|
||||
"""
|
||||
Read a single byte from a device.
|
||||
|
||||
:rtype: int
|
||||
:param i2c_addr: i2c address
|
||||
:type i2c_addr: int
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
:return: Read byte value
|
||||
"""
|
||||
self._set_address(i2c_addr, force=force)
|
||||
msg = i2c_smbus_ioctl_data.create(
|
||||
read_write=I2C_SMBUS_READ, command=0, size=I2C_SMBUS_BYTE
|
||||
)
|
||||
ioctl(self.fd, I2C_SMBUS, msg)
|
||||
return msg.data.contents.byte
|
||||
|
||||
def write_byte(self, i2c_addr, value, force=None):
|
||||
"""
|
||||
Write a single byte to a device.
|
||||
|
||||
:param i2c_addr: i2c address
|
||||
:type i2c_addr: int
|
||||
:param value: value to write
|
||||
:type value: int
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
"""
|
||||
self._set_address(i2c_addr, force=force)
|
||||
msg = i2c_smbus_ioctl_data.create(
|
||||
read_write=I2C_SMBUS_WRITE, command=value, size=I2C_SMBUS_BYTE
|
||||
)
|
||||
ioctl(self.fd, I2C_SMBUS, msg)
|
||||
|
||||
def read_byte_data(self, i2c_addr, register, force=None):
|
||||
"""
|
||||
Read a single byte from a designated register.
|
||||
|
||||
:param i2c_addr: i2c address
|
||||
:type i2c_addr: int
|
||||
:param register: Register to read
|
||||
:type register: int
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
:return: Read byte value
|
||||
:rtype: int
|
||||
"""
|
||||
val_t = -1
|
||||
returnmsg=""
|
||||
try:
|
||||
self._set_address(i2c_addr, force=force)
|
||||
msg = i2c_smbus_ioctl_data.create(
|
||||
read_write=I2C_SMBUS_READ, command=register, size=I2C_SMBUS_BYTE_DATA
|
||||
)
|
||||
val_t = ioctl(self.fd, I2C_SMBUS, msg)
|
||||
except Exception as e:
|
||||
self.close()
|
||||
returnmsg = str(e)
|
||||
if val_t < 0:
|
||||
return False, returnmsg
|
||||
else:
|
||||
return True, msg.data.contents.byte
|
||||
|
||||
def write_byte_data(self, i2c_addr, register, value, force=None):
|
||||
"""
|
||||
Write a byte to a given register.
|
||||
|
||||
:param i2c_addr: i2c address
|
||||
:type i2c_addr: int
|
||||
:param register: Register to write to
|
||||
:type register: int
|
||||
:param value: Byte value to transmit
|
||||
:type value: int
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
:rtype: None
|
||||
"""
|
||||
val_t = -1
|
||||
returnmsg = ""
|
||||
try:
|
||||
self._set_address(i2c_addr, force=force)
|
||||
msg = i2c_smbus_ioctl_data.create(
|
||||
read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_BYTE_DATA
|
||||
)
|
||||
msg.data.contents.byte = value
|
||||
val_t = ioctl(self.fd, I2C_SMBUS, msg)
|
||||
except Exception as e:
|
||||
returnmsg = str(e)
|
||||
self.close()
|
||||
if val_t < 0:
|
||||
return False, returnmsg or ""
|
||||
else:
|
||||
return True, ""
|
||||
|
||||
def read_word_data(self, i2c_addr, register, force=None):
|
||||
"""
|
||||
Read a single word (2 bytes) from a given register.
|
||||
|
||||
:param i2c_addr: i2c address
|
||||
:type i2c_addr: int
|
||||
:param register: Register to read
|
||||
:type register: int
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
:return: 2-byte word
|
||||
:rtype: int
|
||||
"""
|
||||
val_t = -1
|
||||
returnmsg = ""
|
||||
try:
|
||||
self._set_address(i2c_addr, force=force)
|
||||
msg = i2c_smbus_ioctl_data.create(
|
||||
read_write=I2C_SMBUS_READ, command=register, size=I2C_SMBUS_WORD_DATA
|
||||
)
|
||||
val_t = ioctl(self.fd, I2C_SMBUS, msg)
|
||||
except Exception as e:
|
||||
returnmsg = str(e)
|
||||
self.close()
|
||||
if val_t < 0:
|
||||
return False, returnmsg or ""
|
||||
else:
|
||||
return True, msg.data.contents.word
|
||||
|
||||
def write_word_data(self, i2c_addr, register, value, force=None):
|
||||
"""
|
||||
Write a byte to a given register.
|
||||
|
||||
:param i2c_addr: i2c address
|
||||
:type i2c_addr: int
|
||||
:param register: Register to write to
|
||||
:type register: int
|
||||
:param value: Word value to transmit
|
||||
:type value: int
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
:rtype: None
|
||||
"""
|
||||
val_t = -1
|
||||
returnmsg = ""
|
||||
try:
|
||||
self._set_address(i2c_addr, force=force)
|
||||
msg = i2c_smbus_ioctl_data.create(
|
||||
read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_WORD_DATA
|
||||
)
|
||||
msg.data.contents.word = value
|
||||
val_t = ioctl(self.fd, I2C_SMBUS, msg)
|
||||
except Exception as e:
|
||||
returnmsg = str(e)
|
||||
self.close()
|
||||
if val_t < 0:
|
||||
return False, returnmsg or ""
|
||||
else:
|
||||
return True, ""
|
||||
|
||||
def process_call(self, i2c_addr, register, value, force=None):
|
||||
"""
|
||||
Executes a SMBus Process Call, sending a 16-bit value and receiving a 16-bit response
|
||||
|
||||
:param i2c_addr: i2c address
|
||||
:type i2c_addr: int
|
||||
:param register: Register to read/write to
|
||||
:type register: int
|
||||
:param value: Word value to transmit
|
||||
:type value: int
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
:rtype: int
|
||||
"""
|
||||
self._set_address(i2c_addr, force=force)
|
||||
msg = i2c_smbus_ioctl_data.create(
|
||||
read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_PROC_CALL
|
||||
)
|
||||
msg.data.contents.word = value
|
||||
ioctl(self.fd, I2C_SMBUS, msg)
|
||||
return msg.data.contents.word
|
||||
|
||||
def read_block_data(self, i2c_addr, register, force=None):
|
||||
"""
|
||||
Read a block of up to 32-bytes from a given register.
|
||||
|
||||
:param i2c_addr: i2c address
|
||||
:type i2c_addr: int
|
||||
:param register: Start register
|
||||
:type register: int
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
:return: List of bytes
|
||||
:rtype: list
|
||||
"""
|
||||
self._set_address(i2c_addr, force=force)
|
||||
msg = i2c_smbus_ioctl_data.create(
|
||||
read_write=I2C_SMBUS_READ, command=register, size=I2C_SMBUS_BLOCK_DATA
|
||||
)
|
||||
ioctl(self.fd, I2C_SMBUS, msg)
|
||||
length = msg.data.contents.block[0]
|
||||
return msg.data.contents.block[1:length + 1]
|
||||
|
||||
def write_block_data(self, i2c_addr, register, data, force=None):
|
||||
"""
|
||||
Write a block of byte data to a given register.
|
||||
|
||||
:param i2c_addr: i2c address
|
||||
:type i2c_addr: int
|
||||
:param register: Start register
|
||||
:type register: int
|
||||
:param data: List of bytes
|
||||
:type data: list
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
:rtype: None
|
||||
"""
|
||||
length = len(data)
|
||||
if length > I2C_SMBUS_BLOCK_MAX:
|
||||
raise ValueError("Data length cannot exceed %d bytes" % I2C_SMBUS_BLOCK_MAX)
|
||||
self._set_address(i2c_addr, force=force)
|
||||
msg = i2c_smbus_ioctl_data.create(
|
||||
read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_BLOCK_DATA
|
||||
)
|
||||
msg.data.contents.block[0] = length
|
||||
msg.data.contents.block[1:length + 1] = data
|
||||
ioctl(self.fd, I2C_SMBUS, msg)
|
||||
|
||||
def block_process_call(self, i2c_addr, register, data, force=None):
|
||||
"""
|
||||
Executes a SMBus Block Process Call, sending a variable-size data
|
||||
block and receiving another variable-size response
|
||||
|
||||
:param i2c_addr: i2c address
|
||||
:type i2c_addr: int
|
||||
:param register: Register to read/write to
|
||||
:type register: int
|
||||
:param data: List of bytes
|
||||
:type data: list
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
:return: List of bytes
|
||||
:rtype: list
|
||||
"""
|
||||
length = len(data)
|
||||
if length > I2C_SMBUS_BLOCK_MAX:
|
||||
raise ValueError("Data length cannot exceed %d bytes" % I2C_SMBUS_BLOCK_MAX)
|
||||
self._set_address(i2c_addr, force=force)
|
||||
msg = i2c_smbus_ioctl_data.create(
|
||||
read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_BLOCK_PROC_CALL
|
||||
)
|
||||
msg.data.contents.block[0] = length
|
||||
msg.data.contents.block[1:length + 1] = data
|
||||
ioctl(self.fd, I2C_SMBUS, msg)
|
||||
length = msg.data.contents.block[0]
|
||||
return msg.data.contents.block[1:length + 1]
|
||||
|
||||
def read_i2c_block_data(self, i2c_addr, register, length, force=None):
|
||||
"""
|
||||
Read a block of byte data from a given register.
|
||||
|
||||
:param i2c_addr: i2c address
|
||||
:type i2c_addr: int
|
||||
:param register: Start register
|
||||
:type register: int
|
||||
:param length: Desired block length
|
||||
:type length: int
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
:return: List of bytes
|
||||
:rtype: list
|
||||
"""
|
||||
if length > I2C_SMBUS_BLOCK_MAX:
|
||||
raise ValueError("Desired block length over %d bytes" % I2C_SMBUS_BLOCK_MAX)
|
||||
self._set_address(i2c_addr, force=force)
|
||||
msg = i2c_smbus_ioctl_data.create(
|
||||
read_write=I2C_SMBUS_READ, command=register, size=I2C_SMBUS_I2C_BLOCK_DATA
|
||||
)
|
||||
msg.data.contents.byte = length
|
||||
ioctl(self.fd, I2C_SMBUS, msg)
|
||||
return msg.data.contents.block[1:length + 1]
|
||||
|
||||
def write_i2c_block_data(self, i2c_addr, register, data, force=None):
|
||||
"""
|
||||
Write a block of byte data to a given register.
|
||||
|
||||
:param i2c_addr: i2c address
|
||||
:type i2c_addr: int
|
||||
:param register: Start register
|
||||
:type register: int
|
||||
:param data: List of bytes
|
||||
:type data: list
|
||||
:param force:
|
||||
:type force: Boolean
|
||||
:rtype: None
|
||||
"""
|
||||
length = len(data)
|
||||
if length > I2C_SMBUS_BLOCK_MAX:
|
||||
raise ValueError("Data length cannot exceed %d bytes" % I2C_SMBUS_BLOCK_MAX)
|
||||
self._set_address(i2c_addr, force=force)
|
||||
msg = i2c_smbus_ioctl_data.create(
|
||||
read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_I2C_BLOCK_DATA
|
||||
)
|
||||
msg.data.contents.block[0] = length
|
||||
msg.data.contents.block[1:length + 1] = data
|
||||
ioctl(self.fd, I2C_SMBUS, msg)
|
||||
|
||||
def i2c_rdwr(self, *i2c_msgs):
|
||||
"""
|
||||
Combine a series of i2c read and write operations in a single
|
||||
transaction (with repeated start bits but no stop bits in between).
|
||||
|
||||
This method takes i2c_msg instances as input, which must be created
|
||||
first with :py:meth:`i2c_msg.read` or :py:meth:`i2c_msg.write`.
|
||||
|
||||
:param i2c_msgs: One or more i2c_msg class instances.
|
||||
:type i2c_msgs: i2c_msg
|
||||
:rtype: None
|
||||
"""
|
||||
ioctl_data = i2c_rdwr_ioctl_data.create(*i2c_msgs)
|
||||
ioctl(self.fd, I2C_RDWR, ioctl_data)
|
||||
|
||||
|
||||
class SMBusWrapper:
|
||||
"""
|
||||
Wrapper class around the SMBus.
|
||||
Deprecated as of version 0.3.0. Please replace with :py:class:`SMBus`.
|
||||
|
||||
Enables the user to wrap access to the :py:class:`SMBus` class in a
|
||||
"with" statement. If auto_cleanup is True (default), the
|
||||
:py:class:`SMBus` handle will be automatically closed
|
||||
upon exit of the ``with`` block.
|
||||
"""
|
||||
def __init__(self, bus_number=0, auto_cleanup=True, force=False):
|
||||
"""
|
||||
:param auto_cleanup: Close bus when leaving scope.
|
||||
:type auto_cleanup: Boolean
|
||||
:param force: Force using the slave address even when driver is already using it.
|
||||
:type force: Boolean
|
||||
"""
|
||||
self.bus_number = bus_number
|
||||
self.auto_cleanup = auto_cleanup
|
||||
self.force = force
|
||||
|
||||
def __enter__(self):
|
||||
self.bus = SMBus(bus=self.bus_number, force=self.force)
|
||||
return self.bus
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
if self.auto_cleanup:
|
||||
self.bus.close()
|
7
platform/broadcom/sonic-platform-modules-ragile/common/modules/Makefile
Executable file
7
platform/broadcom/sonic-platform-modules-ragile/common/modules/Makefile
Executable file
@ -0,0 +1,7 @@
|
||||
obj-m := rg-gpio-xeon.o
|
||||
obj-m += rg_fan.o
|
||||
obj-m += rg_psu.o
|
||||
obj-m += ragile_platform.o
|
||||
obj-m += i2c-mux-pca9641.o
|
||||
obj-m += i2c-mux-pca954x.o
|
||||
obj-m += csu550.o
|
209
platform/broadcom/sonic-platform-modules-ragile/common/modules/csu550.c
Executable file
209
platform/broadcom/sonic-platform-modules-ragile/common/modules/csu550.c
Executable file
@ -0,0 +1,209 @@
|
||||
/*
|
||||
* csu550.c - A driver for pmbus
|
||||
*
|
||||
* Copyright (c) 2010, 2011 Ericsson AB.
|
||||
* Copyright (c) 2019 <support@ragile.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 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/init.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/hwmon.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/pmbus.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/mutex.h>
|
||||
#include "pmbus.h"
|
||||
|
||||
|
||||
/*
|
||||
* Find sensor groups and status registers on each page.
|
||||
*/
|
||||
static void pmbus_find_sensor_groups(struct i2c_client *client,
|
||||
struct pmbus_driver_info *info)
|
||||
{
|
||||
int page;
|
||||
|
||||
/* Sensors detected on page 0 only */
|
||||
if (pmbus_check_word_register(client, 0, PMBUS_READ_VIN))
|
||||
info->func[0] |= PMBUS_HAVE_VIN;
|
||||
if (pmbus_check_word_register(client, 0, PMBUS_READ_IIN))
|
||||
info->func[0] |= PMBUS_HAVE_IIN;
|
||||
if (pmbus_check_word_register(client, 0, PMBUS_READ_PIN))
|
||||
info->func[0] |= PMBUS_HAVE_PIN;
|
||||
if (info->func[0] && pmbus_check_byte_register(client, 0, PMBUS_STATUS_INPUT))
|
||||
info->func[0] |= PMBUS_HAVE_STATUS_INPUT;
|
||||
if (pmbus_check_byte_register(client, 0, PMBUS_FAN_CONFIG_12) &&
|
||||
pmbus_check_word_register(client, 0, PMBUS_READ_FAN_SPEED_1)) {
|
||||
info->func[0] |= PMBUS_HAVE_FAN12;
|
||||
if (pmbus_check_byte_register(client, 0, PMBUS_STATUS_FAN_12))
|
||||
info->func[0] |= PMBUS_HAVE_STATUS_FAN12;
|
||||
}
|
||||
if (pmbus_check_word_register(client, 0, PMBUS_READ_TEMPERATURE_1))
|
||||
info->func[0] |= PMBUS_HAVE_TEMP;
|
||||
if (pmbus_check_word_register(client, 0, PMBUS_READ_TEMPERATURE_2))
|
||||
info->func[0] |= PMBUS_HAVE_TEMP2;
|
||||
if (pmbus_check_word_register(client, 0, PMBUS_READ_TEMPERATURE_3))
|
||||
info->func[0] |= PMBUS_HAVE_TEMP3;
|
||||
if (info->func[0] & (PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_TEMP3)
|
||||
&& pmbus_check_byte_register(client, 0, PMBUS_STATUS_TEMPERATURE))
|
||||
info->func[0] |= PMBUS_HAVE_STATUS_TEMP;
|
||||
|
||||
/* Sensors detected on all pages */
|
||||
for (page = 0; page < info->pages; page++) {
|
||||
if (pmbus_check_word_register(client, page, PMBUS_READ_VOUT)) {
|
||||
info->func[page] |= PMBUS_HAVE_VOUT;
|
||||
if (pmbus_check_byte_register(client, page,
|
||||
PMBUS_STATUS_VOUT))
|
||||
info->func[page] |= PMBUS_HAVE_STATUS_VOUT;
|
||||
}
|
||||
if (pmbus_check_word_register(client, page, PMBUS_READ_IOUT)) {
|
||||
info->func[page] |= PMBUS_HAVE_IOUT;
|
||||
if (pmbus_check_byte_register(client, 0,
|
||||
PMBUS_STATUS_IOUT))
|
||||
info->func[page] |= PMBUS_HAVE_STATUS_IOUT;
|
||||
}
|
||||
if (pmbus_check_word_register(client, page, PMBUS_READ_POUT))
|
||||
info->func[page] |= PMBUS_HAVE_POUT;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Identify chip parameters.
|
||||
*/
|
||||
static int pmbus_identify(struct i2c_client *client,
|
||||
struct pmbus_driver_info *info)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (!info->pages) {
|
||||
/*
|
||||
* Check if the PAGE command is supported. If it is,
|
||||
* keep setting the page number until it fails or until the
|
||||
* maximum number of pages has been reached. Assume that
|
||||
* this is the number of pages supported by the chip.
|
||||
*/
|
||||
if (pmbus_check_byte_register(client, 0, PMBUS_PAGE)) {
|
||||
int page;
|
||||
|
||||
for (page = 1; page < PMBUS_PAGES; page++) {
|
||||
if (pmbus_set_page(client, page) < 0)
|
||||
break;
|
||||
}
|
||||
pmbus_set_page(client, 0);
|
||||
info->pages = page;
|
||||
} else {
|
||||
info->pages = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pmbus_check_byte_register(client, 0, PMBUS_VOUT_MODE)) {
|
||||
int vout_mode;
|
||||
|
||||
vout_mode = pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE);
|
||||
if (vout_mode >= 0 && vout_mode != 0xff) {
|
||||
switch (vout_mode >> 5) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
info->format[PSC_VOLTAGE_OUT] = vid;
|
||||
break;
|
||||
case 2:
|
||||
info->format[PSC_VOLTAGE_OUT] = direct;
|
||||
break;
|
||||
default:
|
||||
ret = -ENODEV;
|
||||
goto abort;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We should check if the COEFFICIENTS register is supported.
|
||||
* If it is, and the chip is configured for direct mode, we can read
|
||||
* the coefficients from the chip, one set per group of sensor
|
||||
* registers.
|
||||
*
|
||||
* To do this, we will need access to a chip which actually supports the
|
||||
* COEFFICIENTS command, since the command is too complex to implement
|
||||
* without testing it. Until then, abort if a chip configured for direct
|
||||
* mode was detected.
|
||||
*/
|
||||
if (info->format[PSC_VOLTAGE_OUT] == direct) {
|
||||
ret = -ENODEV;
|
||||
goto abort;
|
||||
}
|
||||
|
||||
/* Try to find sensor groups */
|
||||
pmbus_find_sensor_groups(client, info);
|
||||
abort:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int pmbus_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
{
|
||||
struct pmbus_driver_info *info;
|
||||
struct pmbus_platform_data *pdata = NULL;
|
||||
struct device *dev = &client->dev;
|
||||
|
||||
info = devm_kzalloc(&client->dev, sizeof(struct pmbus_driver_info), GFP_KERNEL);
|
||||
if (!info)
|
||||
return -ENOMEM;
|
||||
|
||||
if (!strncmp(id->name, "dps460", sizeof("dps460")) ||
|
||||
!strncmp(id->name, "fsp1200", sizeof("fsp1200")) || !strncmp(id->name, "dps550", sizeof("dps550"))) {
|
||||
pdata = kzalloc(sizeof(struct pmbus_platform_data), GFP_KERNEL);
|
||||
if (!pdata) {
|
||||
kfree(info);
|
||||
return -ENOMEM;
|
||||
}
|
||||
pdata->flags = PMBUS_SKIP_STATUS_CHECK;
|
||||
}
|
||||
|
||||
info->pages = id->driver_data;
|
||||
info->identify = pmbus_identify;
|
||||
dev->platform_data = pdata;
|
||||
|
||||
return pmbus_do_probe(client, id, info);
|
||||
}
|
||||
|
||||
static const struct i2c_device_id pmbus_id[] = {
|
||||
{"csu550", 0},
|
||||
{"csu800", 1},
|
||||
{"fsp1200", 1},
|
||||
{"dps550", 1},
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, pmbus_id);
|
||||
|
||||
/* This is the driver that will be inserted */
|
||||
static struct i2c_driver pmbus_driver = {
|
||||
.probe = pmbus_probe,
|
||||
.remove = pmbus_do_remove,
|
||||
.id_table = pmbus_id,
|
||||
.driver = {
|
||||
.name = "pmbus",
|
||||
},
|
||||
};
|
||||
|
||||
module_i2c_driver(pmbus_driver);
|
||||
|
||||
MODULE_AUTHOR("support <support@ragile.com>");
|
||||
MODULE_DESCRIPTION("ragile psupmbus driver");
|
||||
MODULE_LICENSE("GPL");
|
1749
platform/broadcom/sonic-platform-modules-ragile/common/modules/i2c-mux-pca954x.c
Executable file
1749
platform/broadcom/sonic-platform-modules-ragile/common/modules/i2c-mux-pca954x.c
Executable file
File diff suppressed because it is too large
Load Diff
643
platform/broadcom/sonic-platform-modules-ragile/common/modules/i2c-mux-pca9641.c
Executable file
643
platform/broadcom/sonic-platform-modules-ragile/common/modules/i2c-mux-pca9641.c
Executable file
@ -0,0 +1,643 @@
|
||||
/*
|
||||
* I2C multiplexer driver for PCA9541 bus master selector
|
||||
*
|
||||
* Copyright (c) 2010 Ericsson AB.
|
||||
* Copyright (c) 2019 <support@ragile.com>
|
||||
* Author: Guenter Roeck <linux@roeck-us.net>
|
||||
*
|
||||
* Derived from:
|
||||
* pca954x.c
|
||||
*
|
||||
* Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it>
|
||||
* Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it>
|
||||
*
|
||||
* This file is licensed under the terms of the GNU General Public
|
||||
* License version 2. This program is licensed "as is" without any
|
||||
* warranty of any kind, whether express or implied.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/i2c-mux.h>
|
||||
#include <linux/platform_data/pca954x.h>
|
||||
|
||||
/*
|
||||
* The PCA9541 is a bus master selector. It supports two I2C masters connected
|
||||
* to a single slave bus.
|
||||
*
|
||||
* Before each bus transaction, a master has to acquire bus ownership. After the
|
||||
* transaction is complete, bus ownership has to be released. This fits well
|
||||
* into the I2C multiplexer framework, which provides select and release
|
||||
* functions for this purpose. For this reason, this driver is modeled as
|
||||
* single-channel I2C bus multiplexer.
|
||||
*
|
||||
* This driver assumes that the two bus masters are controlled by two different
|
||||
* hosts. If a single host controls both masters, platform code has to ensure
|
||||
* that only one of the masters is instantiated at any given time.
|
||||
*/
|
||||
|
||||
#define PCA9541_CONTROL 0x01
|
||||
#define PCA9541_ISTAT 0x02
|
||||
|
||||
#define PCA9541_CTL_MYBUS (1 << 0)
|
||||
#define PCA9541_CTL_NMYBUS (1 << 1)
|
||||
#define PCA9541_CTL_BUSON (1 << 2)
|
||||
#define PCA9541_CTL_NBUSON (1 << 3)
|
||||
#define PCA9541_CTL_BUSINIT (1 << 4)
|
||||
#define PCA9541_CTL_TESTON (1 << 6)
|
||||
#define PCA9541_CTL_NTESTON (1 << 7)
|
||||
#define PCA9541_ISTAT_INTIN (1 << 0)
|
||||
#define PCA9541_ISTAT_BUSINIT (1 << 1)
|
||||
#define PCA9541_ISTAT_BUSOK (1 << 2)
|
||||
#define PCA9541_ISTAT_BUSLOST (1 << 3)
|
||||
#define PCA9541_ISTAT_MYTEST (1 << 6)
|
||||
#define PCA9541_ISTAT_NMYTEST (1 << 7)
|
||||
#define PCA9641_ID 0x00
|
||||
#define PCA9641_ID_MAGIC 0x38
|
||||
#define PCA9641_CONTROL 0x01
|
||||
#define PCA9641_STATUS 0x02
|
||||
#define PCA9641_TIME 0x03
|
||||
#define PCA9641_CTL_LOCK_REQ BIT(0)
|
||||
#define PCA9641_CTL_LOCK_GRANT BIT(1)
|
||||
#define PCA9641_CTL_BUS_CONNECT BIT(2)
|
||||
#define PCA9641_CTL_BUS_INIT BIT(3)
|
||||
#define PCA9641_CTL_SMBUS_SWRST BIT(4)
|
||||
#define PCA9641_CTL_IDLE_TIMER_DIS BIT(5)
|
||||
#define PCA9641_CTL_SMBUS_DIS BIT(6)
|
||||
#define PCA9641_CTL_PRIORITY BIT(7)
|
||||
#define PCA9641_STS_OTHER_LOCK BIT(0)
|
||||
#define PCA9641_STS_BUS_INIT_FAIL BIT(1)
|
||||
#define PCA9641_STS_BUS_HUNG BIT(2)
|
||||
#define PCA9641_STS_MBOX_EMPTY BIT(3)
|
||||
#define PCA9641_STS_MBOX_FULL BIT(4)
|
||||
#define PCA9641_STS_TEST_INT BIT(5)
|
||||
#define PCA9641_STS_SCL_IO BIT(6)
|
||||
#define PCA9641_STS_SDA_IO BIT(7)
|
||||
#define PCA9641_RES_TIME 0x03
|
||||
#define BUSON (PCA9541_CTL_BUSON | PCA9541_CTL_NBUSON)
|
||||
#define MYBUS (PCA9541_CTL_MYBUS | PCA9541_CTL_NMYBUS)
|
||||
#define mybus(x) (!((x) & MYBUS) || ((x) & MYBUS) == MYBUS)
|
||||
#define busoff(x) (!((x) & BUSON) || ((x) & BUSON) == BUSON)
|
||||
#define BUSOFF(x, y) (!((x) & PCA9641_CTL_LOCK_GRANT) && \
|
||||
!((y) & PCA9641_STS_OTHER_LOCK))
|
||||
#define other_lock(x) ((x) & PCA9641_STS_OTHER_LOCK)
|
||||
#define lock_grant(x) ((x) & PCA9641_CTL_LOCK_GRANT)
|
||||
|
||||
#define PCA9641_RETRY_TIME 8
|
||||
|
||||
typedef struct i2c_muxs_struct_flag
|
||||
{
|
||||
int nr;
|
||||
char name[48];
|
||||
struct mutex update_lock;
|
||||
int flag;
|
||||
}i2c_mux_flag;
|
||||
|
||||
i2c_mux_flag pca_flag = {
|
||||
.flag = -1,
|
||||
};
|
||||
|
||||
int pca9641_setmuxflag(int nr, int flag)
|
||||
{
|
||||
if (pca_flag.nr == nr) {
|
||||
pca_flag.flag = flag;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(pca9641_setmuxflag);
|
||||
|
||||
int g_debug = 0;
|
||||
module_param(g_debug, int, S_IRUGO | S_IWUSR);
|
||||
|
||||
#define PCA_DEBUG(fmt, args...) do { \
|
||||
if (g_debug) { \
|
||||
printk(KERN_ERR "[pca9641][VER][func:%s line:%d]\r\n"fmt, __func__, __LINE__, ## args); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* arbitration timeouts, in jiffies */
|
||||
#define ARB_TIMEOUT (HZ / 8) /* 125 ms until forcing bus ownership */
|
||||
#define ARB2_TIMEOUT (HZ / 4) /* 250 ms until acquisition failure */
|
||||
|
||||
/* arbitration retry delays, in us */
|
||||
#define SELECT_DELAY_SHORT 50
|
||||
#define SELECT_DELAY_LONG 1000
|
||||
|
||||
struct pca9541 {
|
||||
struct i2c_client *client;
|
||||
unsigned long select_timeout;
|
||||
unsigned long arb_timeout;
|
||||
};
|
||||
|
||||
static const struct i2c_device_id pca9541_id[] = {
|
||||
{"pca9541", 0},
|
||||
{"pca9641", 1},
|
||||
{}
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(i2c, pca9541_id);
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
static const struct of_device_id pca9541_of_match[] = {
|
||||
{ .compatible = "nxp,pca9541" },
|
||||
{ .compatible = "nxp,pca9641" },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, pca9541_of_match);
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Write to chip register. Don't use i2c_transfer()/i2c_smbus_xfer()
|
||||
* as they will try to lock the adapter a second time.
|
||||
*/
|
||||
static int pca9541_reg_write(struct i2c_client *client, u8 command, u8 val)
|
||||
{
|
||||
struct i2c_adapter *adap = client->adapter;
|
||||
int ret;
|
||||
|
||||
if (adap->algo->master_xfer) {
|
||||
struct i2c_msg msg;
|
||||
char buf[2];
|
||||
|
||||
msg.addr = client->addr;
|
||||
msg.flags = 0;
|
||||
msg.len = 2;
|
||||
buf[0] = command;
|
||||
buf[1] = val;
|
||||
msg.buf = buf;
|
||||
ret = __i2c_transfer(adap, &msg, 1);
|
||||
} else {
|
||||
union i2c_smbus_data data;
|
||||
|
||||
data.byte = val;
|
||||
ret = adap->algo->smbus_xfer(adap, client->addr,
|
||||
client->flags,
|
||||
I2C_SMBUS_WRITE,
|
||||
command,
|
||||
I2C_SMBUS_BYTE_DATA, &data);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read from chip register. Don't use i2c_transfer()/i2c_smbus_xfer()
|
||||
* as they will try to lock adapter a second time.
|
||||
*/
|
||||
static int pca9541_reg_read(struct i2c_client *client, u8 command)
|
||||
{
|
||||
struct i2c_adapter *adap = client->adapter;
|
||||
int ret;
|
||||
u8 val;
|
||||
|
||||
if (adap->algo->master_xfer) {
|
||||
struct i2c_msg msg[2] = {
|
||||
{
|
||||
.addr = client->addr,
|
||||
.flags = 0,
|
||||
.len = 1,
|
||||
.buf = &command
|
||||
},
|
||||
{
|
||||
.addr = client->addr,
|
||||
.flags = I2C_M_RD,
|
||||
.len = 1,
|
||||
.buf = &val
|
||||
}
|
||||
};
|
||||
ret = __i2c_transfer(adap, msg, 2);
|
||||
if (ret == 2)
|
||||
ret = val;
|
||||
else if (ret >= 0)
|
||||
ret = -EIO;
|
||||
} else {
|
||||
union i2c_smbus_data data;
|
||||
|
||||
ret = adap->algo->smbus_xfer(adap, client->addr,
|
||||
client->flags,
|
||||
I2C_SMBUS_READ,
|
||||
command,
|
||||
I2C_SMBUS_BYTE_DATA, &data);
|
||||
if (!ret)
|
||||
ret = data.byte;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Arbitration management functions
|
||||
*/
|
||||
|
||||
/* Release bus. Also reset NTESTON and BUSINIT if it was set. */
|
||||
static void pca9541_release_bus(struct i2c_client *client)
|
||||
{
|
||||
int reg;
|
||||
|
||||
reg = pca9541_reg_read(client, PCA9541_CONTROL);
|
||||
if (reg >= 0 && !busoff(reg) && mybus(reg))
|
||||
pca9541_reg_write(client, PCA9541_CONTROL,
|
||||
(reg & PCA9541_CTL_NBUSON) >> 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Arbitration is defined as a two-step process. A bus master can only activate
|
||||
* the slave bus if it owns it; otherwise it has to request ownership first.
|
||||
* This multi-step process ensures that access contention is resolved
|
||||
* gracefully.
|
||||
*
|
||||
* Bus Ownership Other master Action
|
||||
* state requested access
|
||||
* ----------------------------------------------------
|
||||
* off - yes wait for arbitration timeout or
|
||||
* for other master to drop request
|
||||
* off no no take ownership
|
||||
* off yes no turn on bus
|
||||
* on yes - done
|
||||
* on no - wait for arbitration timeout or
|
||||
* for other master to release bus
|
||||
*
|
||||
* The main contention point occurs if the slave bus is off and both masters
|
||||
* request ownership at the same time. In this case, one master will turn on
|
||||
* the slave bus, believing that it owns it. The other master will request
|
||||
* bus ownership. Result is that the bus is turned on, and master which did
|
||||
* _not_ own the slave bus before ends up owning it.
|
||||
*/
|
||||
|
||||
/* Control commands per PCA9541 datasheet */
|
||||
static const u8 pca9541_control[16] = {
|
||||
4, 0, 1, 5, 4, 4, 5, 5, 0, 0, 1, 1, 0, 4, 5, 1
|
||||
};
|
||||
|
||||
/*
|
||||
* Channel arbitration
|
||||
*
|
||||
* Return values:
|
||||
* <0: error
|
||||
* 0 : bus not acquired
|
||||
* 1 : bus acquired
|
||||
*/
|
||||
static int pca9541_arbitrate(struct i2c_client *client)
|
||||
{
|
||||
struct i2c_mux_core *muxc = i2c_get_clientdata(client);
|
||||
struct pca9541 *data = i2c_mux_priv(muxc);
|
||||
int reg;
|
||||
|
||||
reg = pca9541_reg_read(client, PCA9541_CONTROL);
|
||||
if (reg < 0)
|
||||
return reg;
|
||||
|
||||
if (busoff(reg)) {
|
||||
int istat;
|
||||
/*
|
||||
* Bus is off. Request ownership or turn it on unless
|
||||
* other master requested ownership.
|
||||
*/
|
||||
istat = pca9541_reg_read(client, PCA9541_ISTAT);
|
||||
if (!(istat & PCA9541_ISTAT_NMYTEST)
|
||||
|| time_is_before_eq_jiffies(data->arb_timeout)) {
|
||||
/*
|
||||
* Other master did not request ownership,
|
||||
* or arbitration timeout expired. Take the bus.
|
||||
*/
|
||||
pca9541_reg_write(client,
|
||||
PCA9541_CONTROL,
|
||||
pca9541_control[reg & 0x0f]
|
||||
| PCA9541_CTL_NTESTON);
|
||||
data->select_timeout = SELECT_DELAY_SHORT;
|
||||
} else {
|
||||
/*
|
||||
* Other master requested ownership.
|
||||
* Set extra long timeout to give it time to acquire it.
|
||||
*/
|
||||
data->select_timeout = SELECT_DELAY_LONG * 2;
|
||||
}
|
||||
} else if (mybus(reg)) {
|
||||
/*
|
||||
* Bus is on, and we own it. We are done with acquisition.
|
||||
* Reset NTESTON and BUSINIT, then return success.
|
||||
*/
|
||||
if (reg & (PCA9541_CTL_NTESTON | PCA9541_CTL_BUSINIT))
|
||||
pca9541_reg_write(client,
|
||||
PCA9541_CONTROL,
|
||||
reg & ~(PCA9541_CTL_NTESTON
|
||||
| PCA9541_CTL_BUSINIT));
|
||||
return 1;
|
||||
} else {
|
||||
/*
|
||||
* Other master owns the bus.
|
||||
* If arbitration timeout has expired, force ownership.
|
||||
* Otherwise request it.
|
||||
*/
|
||||
data->select_timeout = SELECT_DELAY_LONG;
|
||||
if (time_is_before_eq_jiffies(data->arb_timeout)) {
|
||||
/* Time is up, take the bus and reset it. */
|
||||
pca9541_reg_write(client,
|
||||
PCA9541_CONTROL,
|
||||
pca9541_control[reg & 0x0f]
|
||||
| PCA9541_CTL_BUSINIT
|
||||
| PCA9541_CTL_NTESTON);
|
||||
} else {
|
||||
/* Request bus ownership if needed */
|
||||
if (!(reg & PCA9541_CTL_NTESTON))
|
||||
pca9541_reg_write(client,
|
||||
PCA9541_CONTROL,
|
||||
reg | PCA9541_CTL_NTESTON);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pca9541_select_chan(struct i2c_mux_core *muxc, u32 chan)
|
||||
{
|
||||
struct pca9541 *data = i2c_mux_priv(muxc);
|
||||
struct i2c_client *client = data->client;
|
||||
int ret;
|
||||
unsigned long timeout = jiffies + ARB2_TIMEOUT;
|
||||
/* give up after this time */
|
||||
|
||||
data->arb_timeout = jiffies + ARB_TIMEOUT;
|
||||
/* force bus ownership after this time */
|
||||
|
||||
do {
|
||||
ret = pca9541_arbitrate(client);
|
||||
if (ret)
|
||||
return ret < 0 ? ret : 0;
|
||||
|
||||
if (data->select_timeout == SELECT_DELAY_SHORT)
|
||||
udelay(data->select_timeout);
|
||||
else
|
||||
msleep(data->select_timeout / 1000);
|
||||
} while (time_is_after_eq_jiffies(timeout));
|
||||
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
static int pca9541_release_chan(struct i2c_mux_core *muxc, u32 chan)
|
||||
{
|
||||
struct pca9541 *data = i2c_mux_priv(muxc);
|
||||
struct i2c_client *client = data->client;
|
||||
pca9541_release_bus(client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Arbitration management functions
|
||||
*/
|
||||
static void pca9641_release_bus(struct i2c_client *client)
|
||||
{
|
||||
pca9541_reg_write(client, PCA9641_CONTROL, 0x80); //master 0x80
|
||||
}
|
||||
|
||||
/*
|
||||
* Channel arbitration
|
||||
*
|
||||
* Return values:
|
||||
* <0: error
|
||||
* 0 : bus not acquired
|
||||
* 1 : bus acquired
|
||||
*/
|
||||
static int pca9641_arbitrate(struct i2c_client *client)
|
||||
{
|
||||
struct i2c_mux_core *muxc = i2c_get_clientdata(client);
|
||||
struct pca9541 *data = i2c_mux_priv(muxc);
|
||||
int reg_ctl, reg_sts;
|
||||
|
||||
reg_ctl = pca9541_reg_read(client, PCA9641_CONTROL);
|
||||
if (reg_ctl < 0)
|
||||
return reg_ctl;
|
||||
reg_sts = pca9541_reg_read(client, PCA9641_STATUS);
|
||||
|
||||
if (BUSOFF(reg_ctl, reg_sts)) {
|
||||
/*
|
||||
* Bus is off. Request ownership or turn it on unless
|
||||
* other master requested ownership.
|
||||
*/
|
||||
reg_ctl |= PCA9641_CTL_LOCK_REQ;
|
||||
pca9541_reg_write(client, PCA9641_CONTROL, reg_ctl);
|
||||
reg_ctl = pca9541_reg_read(client, PCA9641_CONTROL);
|
||||
|
||||
if (lock_grant(reg_ctl)) {
|
||||
/*
|
||||
* Other master did not request ownership,
|
||||
* or arbitration timeout expired. Take the bus.
|
||||
*/
|
||||
reg_ctl |= PCA9641_CTL_BUS_CONNECT
|
||||
| PCA9641_CTL_LOCK_REQ;
|
||||
pca9541_reg_write(client, PCA9641_CONTROL, reg_ctl);
|
||||
data->select_timeout = SELECT_DELAY_SHORT;
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
/*
|
||||
* Other master requested ownership.
|
||||
* Set extra long timeout to give it time to acquire it.
|
||||
*/
|
||||
data->select_timeout = SELECT_DELAY_LONG * 2;
|
||||
}
|
||||
} else if (lock_grant(reg_ctl)) {
|
||||
/*
|
||||
* Bus is on, and we own it. We are done with acquisition.
|
||||
*/
|
||||
reg_ctl |= PCA9641_CTL_BUS_CONNECT | PCA9641_CTL_LOCK_REQ;
|
||||
pca9541_reg_write(client, PCA9641_CONTROL, reg_ctl);
|
||||
|
||||
return 1;
|
||||
} else if (other_lock(reg_sts)) {
|
||||
/*
|
||||
* Other master owns the bus.
|
||||
* If arbitration timeout has expired, force ownership.
|
||||
* Otherwise request it.
|
||||
*/
|
||||
data->select_timeout = SELECT_DELAY_LONG;
|
||||
reg_ctl |= PCA9641_CTL_LOCK_REQ;
|
||||
pca9541_reg_write(client, PCA9641_CONTROL, reg_ctl);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int pca9641_select_chan(struct i2c_mux_core *muxc, u32 chan)
|
||||
{
|
||||
struct pca9541 *data = i2c_mux_priv(muxc);
|
||||
struct i2c_client *client = data->client;
|
||||
int ret;
|
||||
int result;
|
||||
unsigned long timeout = jiffies + ARB2_TIMEOUT;
|
||||
/* give up after this time */
|
||||
data->arb_timeout = jiffies + ARB_TIMEOUT;
|
||||
/* force bus ownership after this time */
|
||||
for (result = 0 ; result < PCA9641_RETRY_TIME ; result ++) {
|
||||
do {
|
||||
ret = pca9641_arbitrate(client);
|
||||
if (ret == 1) {
|
||||
return 0;
|
||||
}
|
||||
if (data->select_timeout == SELECT_DELAY_SHORT)
|
||||
udelay(data->select_timeout);
|
||||
else
|
||||
msleep(data->select_timeout / 1000);
|
||||
} while (time_is_after_eq_jiffies(timeout));
|
||||
timeout = jiffies + ARB2_TIMEOUT;
|
||||
}
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
EXPORT_SYMBOL(pca9641_select_chan);
|
||||
|
||||
static int pca9641_release_chan(struct i2c_mux_core *muxc, u32 chan)
|
||||
{
|
||||
struct pca9541 *data = i2c_mux_priv(muxc);
|
||||
struct i2c_client *client = data->client;
|
||||
if (pca_flag.flag) {
|
||||
pca9641_release_bus(client);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pca9641_detect_id(struct i2c_client *client)
|
||||
{
|
||||
int reg;
|
||||
|
||||
reg = pca9541_reg_read(client, PCA9641_ID);
|
||||
if (reg == PCA9641_ID_MAGIC)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int pca9641_recordflag(struct i2c_adapter *adap) {
|
||||
if (pca_flag.flag != -1) {
|
||||
pr_err(" %s %d has init already!!!", __func__, __LINE__);
|
||||
return -1 ;
|
||||
}
|
||||
pca_flag.nr = adap->nr;
|
||||
PCA_DEBUG(" adap->nr:%d\n", adap->nr);
|
||||
snprintf(pca_flag.name, sizeof(pca_flag.name),adap->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void i2c_lock_adapter(struct i2c_adapter *adapter){
|
||||
struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
|
||||
if (parent)
|
||||
i2c_lock_adapter(parent);
|
||||
else
|
||||
rt_mutex_lock(&adapter->bus_lock);
|
||||
}
|
||||
|
||||
void i2c_unlock_adapter(struct i2c_adapter *adapter)
|
||||
{
|
||||
struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
|
||||
|
||||
if (parent)
|
||||
i2c_unlock_adapter(parent);
|
||||
else
|
||||
rt_mutex_unlock(&adapter->bus_lock);
|
||||
}
|
||||
/*
|
||||
* I2C init/probing/exit functions
|
||||
*/
|
||||
static int pca9541_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *id)
|
||||
{
|
||||
struct i2c_adapter *adap = client->adapter;
|
||||
struct pca954x_platform_data *pdata = dev_get_platdata(&client->dev);
|
||||
struct i2c_mux_core *muxc;
|
||||
struct pca9541 *data;
|
||||
int force;
|
||||
int ret = -ENODEV;
|
||||
int detect_id;
|
||||
|
||||
if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE_DATA))
|
||||
return -ENODEV;
|
||||
|
||||
detect_id = pca9641_detect_id(client);
|
||||
|
||||
/*
|
||||
* I2C accesses are unprotected here.
|
||||
* We have to lock the adapter before releasing the bus.
|
||||
*/
|
||||
if (detect_id == 0) {
|
||||
i2c_lock_adapter(adap);
|
||||
pca9541_release_bus(client);
|
||||
i2c_unlock_adapter(adap);
|
||||
} else {
|
||||
i2c_lock_adapter(adap);
|
||||
pca9641_release_bus(client);
|
||||
i2c_unlock_adapter(adap);
|
||||
}
|
||||
|
||||
/* Create mux adapter */
|
||||
|
||||
force = 0;
|
||||
if (pdata)
|
||||
force = pdata->modes[0].adap_id;
|
||||
|
||||
if (detect_id == 0) {
|
||||
muxc = i2c_mux_alloc(adap, &client->dev, 1, sizeof(*data),
|
||||
I2C_MUX_ARBITRATOR,
|
||||
pca9541_select_chan, pca9541_release_chan);
|
||||
if (!muxc)
|
||||
return -ENOMEM;
|
||||
|
||||
data = i2c_mux_priv(muxc);
|
||||
data->client = client;
|
||||
|
||||
i2c_set_clientdata(client, muxc);
|
||||
|
||||
ret = i2c_mux_add_adapter(muxc, force, 0, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
} else {
|
||||
muxc = i2c_mux_alloc(adap, &client->dev, 1, sizeof(*data),
|
||||
I2C_MUX_ARBITRATOR,
|
||||
pca9641_select_chan, pca9641_release_chan);
|
||||
if (!muxc)
|
||||
return -ENOMEM;
|
||||
|
||||
data = i2c_mux_priv(muxc);
|
||||
data->client = client;
|
||||
|
||||
i2c_set_clientdata(client, muxc);
|
||||
|
||||
ret = i2c_mux_add_adapter(muxc, force, 0, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
pca9641_recordflag(muxc->adapter[0]);
|
||||
|
||||
dev_info(&client->dev, "registered master selector for I2C %s\n",
|
||||
client->name);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int pca9541_remove(struct i2c_client *client)
|
||||
{
|
||||
struct i2c_mux_core *muxc = i2c_get_clientdata(client);
|
||||
|
||||
i2c_mux_del_adapters(muxc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct i2c_driver pca9641_driver = {
|
||||
.driver = {
|
||||
.name = "pca9641",
|
||||
.of_match_table = of_match_ptr(pca9541_of_match),
|
||||
},
|
||||
.probe = pca9541_probe,
|
||||
.remove = pca9541_remove,
|
||||
.id_table = pca9541_id,
|
||||
};
|
||||
|
||||
module_i2c_driver(pca9641_driver);
|
||||
|
||||
MODULE_AUTHOR("support support@ragile.com");
|
||||
MODULE_DESCRIPTION("PCA9541 I2C master selector driver");
|
||||
MODULE_LICENSE("GPL v2");
|
424
platform/broadcom/sonic-platform-modules-ragile/common/modules/pmbus.h
Executable file
424
platform/broadcom/sonic-platform-modules-ragile/common/modules/pmbus.h
Executable file
@ -0,0 +1,424 @@
|
||||
/*
|
||||
* pmbus.h - Common defines and structures for PMBus devices
|
||||
*
|
||||
* Copyright (c) 2010, 2011 Ericsson AB.
|
||||
* Copyright (c) 2012 Guenter Roeck
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef PMBUS_H
|
||||
#define PMBUS_H
|
||||
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/regulator/driver.h>
|
||||
|
||||
/*
|
||||
* Registers
|
||||
*/
|
||||
enum pmbus_regs {
|
||||
PMBUS_PAGE = 0x00,
|
||||
PMBUS_OPERATION = 0x01,
|
||||
PMBUS_ON_OFF_CONFIG = 0x02,
|
||||
PMBUS_CLEAR_FAULTS = 0x03,
|
||||
PMBUS_PHASE = 0x04,
|
||||
|
||||
PMBUS_CAPABILITY = 0x19,
|
||||
PMBUS_QUERY = 0x1A,
|
||||
|
||||
PMBUS_VOUT_MODE = 0x20,
|
||||
PMBUS_VOUT_COMMAND = 0x21,
|
||||
PMBUS_VOUT_TRIM = 0x22,
|
||||
PMBUS_VOUT_CAL_OFFSET = 0x23,
|
||||
PMBUS_VOUT_MAX = 0x24,
|
||||
PMBUS_VOUT_MARGIN_HIGH = 0x25,
|
||||
PMBUS_VOUT_MARGIN_LOW = 0x26,
|
||||
PMBUS_VOUT_TRANSITION_RATE = 0x27,
|
||||
PMBUS_VOUT_DROOP = 0x28,
|
||||
PMBUS_VOUT_SCALE_LOOP = 0x29,
|
||||
PMBUS_VOUT_SCALE_MONITOR = 0x2A,
|
||||
|
||||
PMBUS_COEFFICIENTS = 0x30,
|
||||
PMBUS_POUT_MAX = 0x31,
|
||||
|
||||
PMBUS_FAN_CONFIG_12 = 0x3A,
|
||||
PMBUS_FAN_COMMAND_1 = 0x3B,
|
||||
PMBUS_FAN_COMMAND_2 = 0x3C,
|
||||
PMBUS_FAN_CONFIG_34 = 0x3D,
|
||||
PMBUS_FAN_COMMAND_3 = 0x3E,
|
||||
PMBUS_FAN_COMMAND_4 = 0x3F,
|
||||
|
||||
PMBUS_VOUT_OV_FAULT_LIMIT = 0x40,
|
||||
PMBUS_VOUT_OV_FAULT_RESPONSE = 0x41,
|
||||
PMBUS_VOUT_OV_WARN_LIMIT = 0x42,
|
||||
PMBUS_VOUT_UV_WARN_LIMIT = 0x43,
|
||||
PMBUS_VOUT_UV_FAULT_LIMIT = 0x44,
|
||||
PMBUS_VOUT_UV_FAULT_RESPONSE = 0x45,
|
||||
PMBUS_IOUT_OC_FAULT_LIMIT = 0x46,
|
||||
PMBUS_IOUT_OC_FAULT_RESPONSE = 0x47,
|
||||
PMBUS_IOUT_OC_LV_FAULT_LIMIT = 0x48,
|
||||
PMBUS_IOUT_OC_LV_FAULT_RESPONSE = 0x49,
|
||||
PMBUS_IOUT_OC_WARN_LIMIT = 0x4A,
|
||||
PMBUS_IOUT_UC_FAULT_LIMIT = 0x4B,
|
||||
PMBUS_IOUT_UC_FAULT_RESPONSE = 0x4C,
|
||||
|
||||
PMBUS_OT_FAULT_LIMIT = 0x4F,
|
||||
PMBUS_OT_FAULT_RESPONSE = 0x50,
|
||||
PMBUS_OT_WARN_LIMIT = 0x51,
|
||||
PMBUS_UT_WARN_LIMIT = 0x52,
|
||||
PMBUS_UT_FAULT_LIMIT = 0x53,
|
||||
PMBUS_UT_FAULT_RESPONSE = 0x54,
|
||||
PMBUS_VIN_OV_FAULT_LIMIT = 0x55,
|
||||
PMBUS_VIN_OV_FAULT_RESPONSE = 0x56,
|
||||
PMBUS_VIN_OV_WARN_LIMIT = 0x57,
|
||||
PMBUS_VIN_UV_WARN_LIMIT = 0x58,
|
||||
PMBUS_VIN_UV_FAULT_LIMIT = 0x59,
|
||||
|
||||
PMBUS_IIN_OC_FAULT_LIMIT = 0x5B,
|
||||
PMBUS_IIN_OC_WARN_LIMIT = 0x5D,
|
||||
|
||||
PMBUS_POUT_OP_FAULT_LIMIT = 0x68,
|
||||
PMBUS_POUT_OP_WARN_LIMIT = 0x6A,
|
||||
PMBUS_PIN_OP_WARN_LIMIT = 0x6B,
|
||||
|
||||
PMBUS_STATUS_BYTE = 0x78,
|
||||
PMBUS_STATUS_WORD = 0x79,
|
||||
PMBUS_STATUS_VOUT = 0x7A,
|
||||
PMBUS_STATUS_IOUT = 0x7B,
|
||||
PMBUS_STATUS_INPUT = 0x7C,
|
||||
PMBUS_STATUS_TEMPERATURE = 0x7D,
|
||||
PMBUS_STATUS_CML = 0x7E,
|
||||
PMBUS_STATUS_OTHER = 0x7F,
|
||||
PMBUS_STATUS_MFR_SPECIFIC = 0x80,
|
||||
PMBUS_STATUS_FAN_12 = 0x81,
|
||||
PMBUS_STATUS_FAN_34 = 0x82,
|
||||
|
||||
PMBUS_READ_VIN = 0x88,
|
||||
PMBUS_READ_IIN = 0x89,
|
||||
PMBUS_READ_VCAP = 0x8A,
|
||||
PMBUS_READ_VOUT = 0x8B,
|
||||
PMBUS_READ_IOUT = 0x8C,
|
||||
PMBUS_READ_TEMPERATURE_1 = 0x8D,
|
||||
PMBUS_READ_TEMPERATURE_2 = 0x8E,
|
||||
PMBUS_READ_TEMPERATURE_3 = 0x8F,
|
||||
PMBUS_READ_FAN_SPEED_1 = 0x90,
|
||||
PMBUS_READ_FAN_SPEED_2 = 0x91,
|
||||
PMBUS_READ_FAN_SPEED_3 = 0x92,
|
||||
PMBUS_READ_FAN_SPEED_4 = 0x93,
|
||||
PMBUS_READ_DUTY_CYCLE = 0x94,
|
||||
PMBUS_READ_FREQUENCY = 0x95,
|
||||
PMBUS_READ_POUT = 0x96,
|
||||
PMBUS_READ_PIN = 0x97,
|
||||
|
||||
PMBUS_REVISION = 0x98,
|
||||
PMBUS_MFR_ID = 0x99,
|
||||
PMBUS_MFR_MODEL = 0x9A,
|
||||
PMBUS_MFR_REVISION = 0x9B,
|
||||
PMBUS_MFR_LOCATION = 0x9C,
|
||||
PMBUS_MFR_DATE = 0x9D,
|
||||
PMBUS_MFR_SERIAL = 0x9E,
|
||||
|
||||
/*
|
||||
* Virtual registers.
|
||||
* Useful to support attributes which are not supported by standard PMBus
|
||||
* registers but exist as manufacturer specific registers on individual chips.
|
||||
* Must be mapped to real registers in device specific code.
|
||||
*
|
||||
* Semantics:
|
||||
* Virtual registers are all word size.
|
||||
* READ registers are read-only; writes are either ignored or return an error.
|
||||
* RESET registers are read/write. Reading reset registers returns zero
|
||||
* (used for detection), writing any value causes the associated history to be
|
||||
* reset.
|
||||
* Virtual registers have to be handled in device specific driver code. Chip
|
||||
* driver code returns non-negative register values if a virtual register is
|
||||
* supported, or a negative error code if not. The chip driver may return
|
||||
* -ENODATA or any other error code in this case, though an error code other
|
||||
* than -ENODATA is handled more efficiently and thus preferred. Either case,
|
||||
* the calling PMBus core code will abort if the chip driver returns an error
|
||||
* code when reading or writing virtual registers.
|
||||
*/
|
||||
PMBUS_VIRT_BASE = 0x100,
|
||||
PMBUS_VIRT_READ_TEMP_AVG,
|
||||
PMBUS_VIRT_READ_TEMP_MIN,
|
||||
PMBUS_VIRT_READ_TEMP_MAX,
|
||||
PMBUS_VIRT_RESET_TEMP_HISTORY,
|
||||
PMBUS_VIRT_READ_VIN_AVG,
|
||||
PMBUS_VIRT_READ_VIN_MIN,
|
||||
PMBUS_VIRT_READ_VIN_MAX,
|
||||
PMBUS_VIRT_RESET_VIN_HISTORY,
|
||||
PMBUS_VIRT_READ_IIN_AVG,
|
||||
PMBUS_VIRT_READ_IIN_MIN,
|
||||
PMBUS_VIRT_READ_IIN_MAX,
|
||||
PMBUS_VIRT_RESET_IIN_HISTORY,
|
||||
PMBUS_VIRT_READ_PIN_AVG,
|
||||
PMBUS_VIRT_READ_PIN_MIN,
|
||||
PMBUS_VIRT_READ_PIN_MAX,
|
||||
PMBUS_VIRT_RESET_PIN_HISTORY,
|
||||
PMBUS_VIRT_READ_POUT_AVG,
|
||||
PMBUS_VIRT_READ_POUT_MIN,
|
||||
PMBUS_VIRT_READ_POUT_MAX,
|
||||
PMBUS_VIRT_RESET_POUT_HISTORY,
|
||||
PMBUS_VIRT_READ_VOUT_AVG,
|
||||
PMBUS_VIRT_READ_VOUT_MIN,
|
||||
PMBUS_VIRT_READ_VOUT_MAX,
|
||||
PMBUS_VIRT_RESET_VOUT_HISTORY,
|
||||
PMBUS_VIRT_READ_IOUT_AVG,
|
||||
PMBUS_VIRT_READ_IOUT_MIN,
|
||||
PMBUS_VIRT_READ_IOUT_MAX,
|
||||
PMBUS_VIRT_RESET_IOUT_HISTORY,
|
||||
PMBUS_VIRT_READ_TEMP2_AVG,
|
||||
PMBUS_VIRT_READ_TEMP2_MIN,
|
||||
PMBUS_VIRT_READ_TEMP2_MAX,
|
||||
PMBUS_VIRT_RESET_TEMP2_HISTORY,
|
||||
|
||||
PMBUS_VIRT_READ_VMON,
|
||||
PMBUS_VIRT_VMON_UV_WARN_LIMIT,
|
||||
PMBUS_VIRT_VMON_OV_WARN_LIMIT,
|
||||
PMBUS_VIRT_VMON_UV_FAULT_LIMIT,
|
||||
PMBUS_VIRT_VMON_OV_FAULT_LIMIT,
|
||||
PMBUS_VIRT_STATUS_VMON,
|
||||
};
|
||||
|
||||
/*
|
||||
* OPERATION
|
||||
*/
|
||||
#define PB_OPERATION_CONTROL_ON BIT(7)
|
||||
|
||||
/*
|
||||
* CAPABILITY
|
||||
*/
|
||||
#define PB_CAPABILITY_SMBALERT BIT(4)
|
||||
#define PB_CAPABILITY_ERROR_CHECK BIT(7)
|
||||
|
||||
/*
|
||||
* VOUT_MODE
|
||||
*/
|
||||
#define PB_VOUT_MODE_MODE_MASK 0xe0
|
||||
#define PB_VOUT_MODE_PARAM_MASK 0x1f
|
||||
|
||||
#define PB_VOUT_MODE_LINEAR 0x00
|
||||
#define PB_VOUT_MODE_VID 0x20
|
||||
#define PB_VOUT_MODE_DIRECT 0x40
|
||||
|
||||
/*
|
||||
* Fan configuration
|
||||
*/
|
||||
#define PB_FAN_2_PULSE_MASK (BIT(0) | BIT(1))
|
||||
#define PB_FAN_2_RPM BIT(2)
|
||||
#define PB_FAN_2_INSTALLED BIT(3)
|
||||
#define PB_FAN_1_PULSE_MASK (BIT(4) | BIT(5))
|
||||
#define PB_FAN_1_RPM BIT(6)
|
||||
#define PB_FAN_1_INSTALLED BIT(7)
|
||||
|
||||
/*
|
||||
* STATUS_BYTE, STATUS_WORD (lower)
|
||||
*/
|
||||
#define PB_STATUS_NONE_ABOVE BIT(0)
|
||||
#define PB_STATUS_CML BIT(1)
|
||||
#define PB_STATUS_TEMPERATURE BIT(2)
|
||||
#define PB_STATUS_VIN_UV BIT(3)
|
||||
#define PB_STATUS_IOUT_OC BIT(4)
|
||||
#define PB_STATUS_VOUT_OV BIT(5)
|
||||
#define PB_STATUS_OFF BIT(6)
|
||||
#define PB_STATUS_BUSY BIT(7)
|
||||
|
||||
/*
|
||||
* STATUS_WORD (upper)
|
||||
*/
|
||||
#define PB_STATUS_UNKNOWN BIT(8)
|
||||
#define PB_STATUS_OTHER BIT(9)
|
||||
#define PB_STATUS_FANS BIT(10)
|
||||
#define PB_STATUS_POWER_GOOD_N BIT(11)
|
||||
#define PB_STATUS_WORD_MFR BIT(12)
|
||||
#define PB_STATUS_INPUT BIT(13)
|
||||
#define PB_STATUS_IOUT_POUT BIT(14)
|
||||
#define PB_STATUS_VOUT BIT(15)
|
||||
|
||||
/*
|
||||
* STATUS_IOUT
|
||||
*/
|
||||
#define PB_POUT_OP_WARNING BIT(0)
|
||||
#define PB_POUT_OP_FAULT BIT(1)
|
||||
#define PB_POWER_LIMITING BIT(2)
|
||||
#define PB_CURRENT_SHARE_FAULT BIT(3)
|
||||
#define PB_IOUT_UC_FAULT BIT(4)
|
||||
#define PB_IOUT_OC_WARNING BIT(5)
|
||||
#define PB_IOUT_OC_LV_FAULT BIT(6)
|
||||
#define PB_IOUT_OC_FAULT BIT(7)
|
||||
|
||||
/*
|
||||
* STATUS_VOUT, STATUS_INPUT
|
||||
*/
|
||||
#define PB_VOLTAGE_UV_FAULT BIT(4)
|
||||
#define PB_VOLTAGE_UV_WARNING BIT(5)
|
||||
#define PB_VOLTAGE_OV_WARNING BIT(6)
|
||||
#define PB_VOLTAGE_OV_FAULT BIT(7)
|
||||
|
||||
/*
|
||||
* STATUS_INPUT
|
||||
*/
|
||||
#define PB_PIN_OP_WARNING BIT(0)
|
||||
#define PB_IIN_OC_WARNING BIT(1)
|
||||
#define PB_IIN_OC_FAULT BIT(2)
|
||||
|
||||
/*
|
||||
* STATUS_TEMPERATURE
|
||||
*/
|
||||
#define PB_TEMP_UT_FAULT BIT(4)
|
||||
#define PB_TEMP_UT_WARNING BIT(5)
|
||||
#define PB_TEMP_OT_WARNING BIT(6)
|
||||
#define PB_TEMP_OT_FAULT BIT(7)
|
||||
|
||||
/*
|
||||
* STATUS_FAN
|
||||
*/
|
||||
#define PB_FAN_AIRFLOW_WARNING BIT(0)
|
||||
#define PB_FAN_AIRFLOW_FAULT BIT(1)
|
||||
#define PB_FAN_FAN2_SPEED_OVERRIDE BIT(2)
|
||||
#define PB_FAN_FAN1_SPEED_OVERRIDE BIT(3)
|
||||
#define PB_FAN_FAN2_WARNING BIT(4)
|
||||
#define PB_FAN_FAN1_WARNING BIT(5)
|
||||
#define PB_FAN_FAN2_FAULT BIT(6)
|
||||
#define PB_FAN_FAN1_FAULT BIT(7)
|
||||
|
||||
/*
|
||||
* CML_FAULT_STATUS
|
||||
*/
|
||||
#define PB_CML_FAULT_OTHER_MEM_LOGIC BIT(0)
|
||||
#define PB_CML_FAULT_OTHER_COMM BIT(1)
|
||||
#define PB_CML_FAULT_PROCESSOR BIT(3)
|
||||
#define PB_CML_FAULT_MEMORY BIT(4)
|
||||
#define PB_CML_FAULT_PACKET_ERROR BIT(5)
|
||||
#define PB_CML_FAULT_INVALID_DATA BIT(6)
|
||||
#define PB_CML_FAULT_INVALID_COMMAND BIT(7)
|
||||
|
||||
enum pmbus_sensor_classes {
|
||||
PSC_VOLTAGE_IN = 0,
|
||||
PSC_VOLTAGE_OUT,
|
||||
PSC_CURRENT_IN,
|
||||
PSC_CURRENT_OUT,
|
||||
PSC_POWER,
|
||||
PSC_TEMPERATURE,
|
||||
PSC_FAN,
|
||||
PSC_NUM_CLASSES /* Number of power sensor classes */
|
||||
};
|
||||
|
||||
#define PMBUS_PAGES 32 /* Per PMBus specification */
|
||||
|
||||
/* Functionality bit mask */
|
||||
#define PMBUS_HAVE_VIN BIT(0)
|
||||
#define PMBUS_HAVE_VCAP BIT(1)
|
||||
#define PMBUS_HAVE_VOUT BIT(2)
|
||||
#define PMBUS_HAVE_IIN BIT(3)
|
||||
#define PMBUS_HAVE_IOUT BIT(4)
|
||||
#define PMBUS_HAVE_PIN BIT(5)
|
||||
#define PMBUS_HAVE_POUT BIT(6)
|
||||
#define PMBUS_HAVE_FAN12 BIT(7)
|
||||
#define PMBUS_HAVE_FAN34 BIT(8)
|
||||
#define PMBUS_HAVE_TEMP BIT(9)
|
||||
#define PMBUS_HAVE_TEMP2 BIT(10)
|
||||
#define PMBUS_HAVE_TEMP3 BIT(11)
|
||||
#define PMBUS_HAVE_STATUS_VOUT BIT(12)
|
||||
#define PMBUS_HAVE_STATUS_IOUT BIT(13)
|
||||
#define PMBUS_HAVE_STATUS_INPUT BIT(14)
|
||||
#define PMBUS_HAVE_STATUS_TEMP BIT(15)
|
||||
#define PMBUS_HAVE_STATUS_FAN12 BIT(16)
|
||||
#define PMBUS_HAVE_STATUS_FAN34 BIT(17)
|
||||
#define PMBUS_HAVE_VMON BIT(18)
|
||||
#define PMBUS_HAVE_STATUS_VMON BIT(19)
|
||||
|
||||
enum pmbus_data_format { linear = 0, direct, vid };
|
||||
enum vrm_version { vr11 = 0, vr12, vr13 };
|
||||
|
||||
struct pmbus_driver_info {
|
||||
int pages; /* Total number of pages */
|
||||
enum pmbus_data_format format[PSC_NUM_CLASSES];
|
||||
enum vrm_version vrm_version[PMBUS_PAGES];
|
||||
/*
|
||||
* Support one set of coefficients for each sensor type
|
||||
* Used for chips providing data in direct mode.
|
||||
*/
|
||||
int m[PSC_NUM_CLASSES]; /* mantissa for direct data format */
|
||||
int b[PSC_NUM_CLASSES]; /* offset */
|
||||
int R[PSC_NUM_CLASSES]; /* exponent */
|
||||
|
||||
u32 func[PMBUS_PAGES]; /* Functionality, per page */
|
||||
/*
|
||||
* The following functions map manufacturing specific register values
|
||||
* to PMBus standard register values. Specify only if mapping is
|
||||
* necessary.
|
||||
* Functions return the register value (read) or zero (write) if
|
||||
* successful. A return value of -ENODATA indicates that there is no
|
||||
* manufacturer specific register, but that a standard PMBus register
|
||||
* may exist. Any other negative return value indicates that the
|
||||
* register does not exist, and that no attempt should be made to read
|
||||
* the standard register.
|
||||
*/
|
||||
int (*read_byte_data)(struct i2c_client *client, int page, int reg);
|
||||
int (*read_word_data)(struct i2c_client *client, int page, int reg);
|
||||
int (*write_word_data)(struct i2c_client *client, int page, int reg,
|
||||
u16 word);
|
||||
int (*write_byte)(struct i2c_client *client, int page, u8 value);
|
||||
/*
|
||||
* The identify function determines supported PMBus functionality.
|
||||
* This function is only necessary if a chip driver supports multiple
|
||||
* chips, and the chip functionality is not pre-determined.
|
||||
*/
|
||||
int (*identify)(struct i2c_client *client,
|
||||
struct pmbus_driver_info *info);
|
||||
|
||||
/* Regulator functionality, if supported by this chip driver. */
|
||||
int num_regulators;
|
||||
const struct regulator_desc *reg_desc;
|
||||
};
|
||||
|
||||
/* Regulator ops */
|
||||
|
||||
extern const struct regulator_ops pmbus_regulator_ops;
|
||||
|
||||
/* Macro for filling in array of struct regulator_desc */
|
||||
#define PMBUS_REGULATOR(_name, _id) \
|
||||
[_id] = { \
|
||||
.name = (_name # _id), \
|
||||
.id = (_id), \
|
||||
.of_match = of_match_ptr(_name # _id), \
|
||||
.regulators_node = of_match_ptr("regulators"), \
|
||||
.ops = &pmbus_regulator_ops, \
|
||||
.type = REGULATOR_VOLTAGE, \
|
||||
.owner = THIS_MODULE, \
|
||||
}
|
||||
|
||||
/* Function declarations */
|
||||
|
||||
void pmbus_clear_cache(struct i2c_client *client);
|
||||
int pmbus_set_page(struct i2c_client *client, u8 page);
|
||||
int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg);
|
||||
int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, u16 word);
|
||||
int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg);
|
||||
int pmbus_write_byte(struct i2c_client *client, int page, u8 value);
|
||||
int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg,
|
||||
u8 value);
|
||||
int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
|
||||
u8 mask, u8 value);
|
||||
void pmbus_clear_faults(struct i2c_client *client);
|
||||
bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg);
|
||||
bool pmbus_check_word_register(struct i2c_client *client, int page, int reg);
|
||||
int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
|
||||
struct pmbus_driver_info *info);
|
||||
int pmbus_do_remove(struct i2c_client *client);
|
||||
const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client
|
||||
*client);
|
||||
#endif /* PMBUS_H */
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* ragile_platform.c - A driver for ragile platform module
|
||||
*
|
||||
* Copyright (c) 2019 <support@ragile.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 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/kernel.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/i2c-mux.h>
|
||||
#include <linux/platform_data/i2c-gpio.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/i2c-smbus.h>
|
||||
#include <linux/string.h>
|
||||
|
||||
#define PLATFORM_I2C_RETRY_TIMES (3)
|
||||
|
||||
s32 platform_i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command)
|
||||
{
|
||||
int try;
|
||||
s32 ret;
|
||||
|
||||
ret = -1;
|
||||
for (try = 0; try < PLATFORM_I2C_RETRY_TIMES; try ++) {
|
||||
if ((ret = i2c_smbus_read_byte_data(client, command)) >= 0)
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(platform_i2c_smbus_read_byte_data);
|
||||
|
||||
s32 platform_i2c_smbus_read_i2c_block_data(const struct i2c_client *client,
|
||||
u8 command, u8 length, u8 *values)
|
||||
{
|
||||
int try ;
|
||||
s32 ret;
|
||||
|
||||
ret = -1;
|
||||
for (try = 0; try < PLATFORM_I2C_RETRY_TIMES; try ++) {
|
||||
if ((ret = i2c_smbus_read_i2c_block_data(client, command, length, values)) >= 0)
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(platform_i2c_smbus_read_i2c_block_data);
|
||||
|
||||
s32 platform_i2c_smbus_read_word_data(const struct i2c_client *client, u8 command)
|
||||
{
|
||||
int try;
|
||||
s32 ret;
|
||||
|
||||
ret = -1;
|
||||
for (try = 0; try < PLATFORM_I2C_RETRY_TIMES; try ++) {
|
||||
if ((ret = i2c_smbus_read_word_data(client, command)) >= 0)
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(platform_i2c_smbus_read_word_data);
|
||||
|
||||
static int __init ragile_platform_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit ragile_platform_exit(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
module_init(ragile_platform_init);
|
||||
module_exit(ragile_platform_exit);
|
||||
|
||||
MODULE_DESCRIPTION("ragile Platform Support");
|
||||
MODULE_AUTHOR("support <support@ragile.com>");
|
||||
MODULE_LICENSE("GPL");
|
357
platform/broadcom/sonic-platform-modules-ragile/common/modules/rg-gpio-xeon.c
Executable file
357
platform/broadcom/sonic-platform-modules-ragile/common/modules/rg-gpio-xeon.c
Executable file
@ -0,0 +1,357 @@
|
||||
/*
|
||||
* GPIO interface for XEON Super I/O chip
|
||||
*
|
||||
* Author: support <support@ragile.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License 2 as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* 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; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/platform_data/i2c-gpio.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/delay.h>
|
||||
#include <asm/delay.h>
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/gpio/machine.h>
|
||||
|
||||
#define GPIO_NAME "xeon-gpio"
|
||||
#define GPIO_IOSIZE 7
|
||||
#define GPIO_BASE 0x500
|
||||
|
||||
#define GPIO_USE_SEL GPIO_BASE
|
||||
#define GP_IO_SEL (GPIO_BASE+0x4)
|
||||
#define GP_LVL (GPIO_BASE+0xC)
|
||||
|
||||
#define GPIO_USE_SEL2 (GPIO_BASE+0x30)
|
||||
#define GP_IO_SEL2 (GPIO_BASE+0x34)
|
||||
#define GP_LVL2 (GPIO_BASE+0x38)
|
||||
|
||||
#define GPIO_USE_SEL3 (GPIO_BASE+0x40)
|
||||
#define GP_IO_SEL3 (GPIO_BASE+0x44)
|
||||
#define GP_LVL3 (GPIO_BASE+0x48)
|
||||
|
||||
|
||||
#define GPIO_BASE_ID 0
|
||||
#define BANKSIZE 32
|
||||
|
||||
#define GPIO_SDA 17
|
||||
#define GPIO_SCL 1
|
||||
|
||||
#define GPIO_XEON_SPIN_LOCK(lock, flags) spin_lock_irqsave(&(lock), (flags))
|
||||
#define GPIO_XEON_SPIN_UNLOCK(lock, flags) spin_unlock_irqrestore(&(lock), (flags))
|
||||
static DEFINE_SPINLOCK(sio_lock);
|
||||
|
||||
/****************** i2c adapter with gpio ***********************/
|
||||
|
||||
static struct i2c_gpio_platform_data i2c_pdata = {
|
||||
.timeout = 200,
|
||||
.udelay = 10,
|
||||
.scl_is_output_only = 0,
|
||||
.sda_is_open_drain = 0,
|
||||
.scl_is_open_drain = 0,
|
||||
};
|
||||
|
||||
static struct gpiod_lookup_table rg_gpio_lookup_table = {
|
||||
.dev_id = "i2c-gpio",
|
||||
.table = {
|
||||
GPIO_LOOKUP(GPIO_NAME, GPIO_SDA, "sda",
|
||||
GPIO_ACTIVE_HIGH),
|
||||
GPIO_LOOKUP(GPIO_NAME, GPIO_SCL, "scl",
|
||||
GPIO_ACTIVE_HIGH),
|
||||
},
|
||||
};
|
||||
|
||||
static void i2c_gpio_release(struct device *dev)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static struct platform_device i2c_gpio = {
|
||||
.name = "i2c-gpio",
|
||||
.num_resources = 0,
|
||||
.id = -1,
|
||||
|
||||
.dev = {
|
||||
.platform_data = &i2c_pdata,
|
||||
.release = i2c_gpio_release,
|
||||
}
|
||||
};
|
||||
|
||||
static int xeon_gpio_get(struct gpio_chip *gc, unsigned gpio_num)
|
||||
{
|
||||
unsigned int data;
|
||||
unsigned int bank, offset;
|
||||
unsigned long flags;
|
||||
|
||||
data = 0;
|
||||
bank = gpio_num / BANKSIZE;
|
||||
offset = gpio_num % BANKSIZE;
|
||||
|
||||
GPIO_XEON_SPIN_LOCK(sio_lock, flags);
|
||||
if (bank == 0) {
|
||||
data = inl(GP_LVL) & (1 << offset);
|
||||
if (data) {
|
||||
data = 1;
|
||||
}
|
||||
} else if (bank == 1) {
|
||||
data = inl(GP_LVL2) & (1 << offset);
|
||||
if (data) {
|
||||
data = 1;
|
||||
}
|
||||
} else if (bank == 2) {
|
||||
data = inl(GP_LVL3) & (1 << offset);
|
||||
if (data) {
|
||||
data = 1;
|
||||
}
|
||||
}
|
||||
GPIO_XEON_SPIN_UNLOCK(sio_lock, flags);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static int xeon_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num)
|
||||
{
|
||||
unsigned int data;
|
||||
unsigned int bank, offset;
|
||||
unsigned long flags;
|
||||
|
||||
bank = gpio_num / BANKSIZE;
|
||||
offset = gpio_num % BANKSIZE;
|
||||
|
||||
GPIO_XEON_SPIN_LOCK(sio_lock, flags);
|
||||
if (bank == 0) {
|
||||
data = inl(GP_IO_SEL);
|
||||
data = data | (1 << offset);
|
||||
outl(data, GP_IO_SEL);
|
||||
} else if (bank == 1) {
|
||||
data = inl(GP_IO_SEL2);
|
||||
data = data | (1 << offset);
|
||||
outl(data, GP_IO_SEL2);
|
||||
} else if (bank == 2) {
|
||||
data = inl(GP_IO_SEL3);
|
||||
data = data | (1 << offset);
|
||||
outl(data, GP_IO_SEL3);
|
||||
}
|
||||
GPIO_XEON_SPIN_UNLOCK(sio_lock, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void xeon_gpio_set(struct gpio_chip *gc,
|
||||
unsigned gpio_num, int val)
|
||||
{
|
||||
unsigned int data;
|
||||
unsigned int bank, offset;
|
||||
unsigned long flags;
|
||||
|
||||
bank = gpio_num / BANKSIZE;
|
||||
offset = gpio_num % BANKSIZE;
|
||||
|
||||
GPIO_XEON_SPIN_LOCK(sio_lock, flags);
|
||||
if (bank == 0) {
|
||||
data = inl(GP_LVL);
|
||||
if (val) {
|
||||
data = data | (1 << offset);
|
||||
} else {
|
||||
data = data & ~(1 << offset);
|
||||
}
|
||||
outl(data, GP_LVL);
|
||||
} else if (bank == 1) {
|
||||
data = inl(GP_LVL2);
|
||||
if (val) {
|
||||
data = data | (1 << offset);
|
||||
} else {
|
||||
data = data & ~(1 << offset);
|
||||
}
|
||||
outl(data, GP_LVL2);
|
||||
} else if (bank == 2) {
|
||||
data = inl(GP_LVL3);
|
||||
if (val) {
|
||||
data = data | (1 << offset);
|
||||
} else {
|
||||
data = data & ~(1 << offset);
|
||||
}
|
||||
outl(data, GP_LVL3);
|
||||
}
|
||||
GPIO_XEON_SPIN_UNLOCK(sio_lock, flags);
|
||||
}
|
||||
|
||||
static int xeon_gpio_direction_out(struct gpio_chip *gc,
|
||||
unsigned gpio_num, int val)
|
||||
{
|
||||
unsigned int data;
|
||||
unsigned int bank, offset;
|
||||
unsigned long flags;
|
||||
|
||||
bank = gpio_num / BANKSIZE;
|
||||
offset = gpio_num % BANKSIZE;
|
||||
|
||||
GPIO_XEON_SPIN_LOCK(sio_lock, flags);
|
||||
if (bank == 0) {
|
||||
data = inl(GP_IO_SEL);
|
||||
data = data & ~(1 << offset);
|
||||
outl(data, GP_IO_SEL);
|
||||
|
||||
data = inl(GP_LVL);
|
||||
if (val) {
|
||||
data = data | (1 << offset);
|
||||
} else {
|
||||
data = data & ~(1 << offset);
|
||||
}
|
||||
outl(data, GP_LVL);
|
||||
} else if (bank == 1) {
|
||||
data = inl(GP_IO_SEL2);
|
||||
data = data & ~(1 << offset);
|
||||
outl(data, GP_IO_SEL2);
|
||||
|
||||
data = inl(GP_LVL2);
|
||||
if (val) {
|
||||
data = data | (1 << offset);
|
||||
} else {
|
||||
data = data & ~(1 << offset);
|
||||
}
|
||||
outl(data, GP_LVL2);
|
||||
} else if (bank == 2) {
|
||||
data = inl(GP_IO_SEL3);
|
||||
data = data & ~(1 << offset);
|
||||
outl(data, GP_IO_SEL3);
|
||||
|
||||
data = inl(GP_LVL3);
|
||||
if (val) {
|
||||
data = data | (1 << offset);
|
||||
} else {
|
||||
data = data & ~(1 << offset);
|
||||
}
|
||||
outl(data, GP_LVL3);
|
||||
}
|
||||
GPIO_XEON_SPIN_UNLOCK(sio_lock, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xeon_gpio_request(struct gpio_chip *chip, unsigned int offset)
|
||||
{
|
||||
unsigned int data;
|
||||
unsigned int bank, tmp_offset;
|
||||
unsigned long flags;
|
||||
|
||||
bank = offset / BANKSIZE;
|
||||
tmp_offset = offset % BANKSIZE;
|
||||
|
||||
GPIO_XEON_SPIN_LOCK(sio_lock, flags);
|
||||
if (bank == 0) {
|
||||
data = inl(GPIO_USE_SEL);
|
||||
data = data | (1 << tmp_offset);
|
||||
outl(data, GPIO_USE_SEL);
|
||||
} else if (bank == 1) {
|
||||
data = inl(GPIO_USE_SEL2);
|
||||
data = data | (1 << tmp_offset);
|
||||
outl(data, GPIO_USE_SEL2);
|
||||
} else if (bank == 2) {
|
||||
data = inl(GPIO_USE_SEL3);
|
||||
data = data | (1 << tmp_offset);
|
||||
outl(data, GPIO_USE_SEL3);
|
||||
}
|
||||
GPIO_XEON_SPIN_UNLOCK(sio_lock, flags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void xeon_gpio_free(struct gpio_chip *chip, unsigned int offset)
|
||||
{
|
||||
unsigned int data;
|
||||
unsigned int bank, tmp_offset;
|
||||
unsigned long flags;
|
||||
|
||||
bank = offset / BANKSIZE;
|
||||
tmp_offset = offset % BANKSIZE;
|
||||
|
||||
GPIO_XEON_SPIN_LOCK(sio_lock, flags);
|
||||
if (bank == 0) {
|
||||
data = inl(GPIO_USE_SEL);
|
||||
data = data & ~(1 << tmp_offset);
|
||||
outl(data, GPIO_USE_SEL);
|
||||
} else if (bank == 1) {
|
||||
data = inl(GPIO_USE_SEL2);
|
||||
data = data & ~(1 << tmp_offset);
|
||||
outl(data, GPIO_USE_SEL2);
|
||||
} else if (bank == 2) {
|
||||
data = inl(GPIO_USE_SEL3);
|
||||
data = data & ~(1 << tmp_offset);
|
||||
outl(data, GPIO_USE_SEL3);
|
||||
}
|
||||
GPIO_XEON_SPIN_UNLOCK(sio_lock, flags);
|
||||
}
|
||||
|
||||
static struct gpio_chip xeon_gpio_chip = {
|
||||
.label = GPIO_NAME,
|
||||
.owner = THIS_MODULE,
|
||||
.get = xeon_gpio_get,
|
||||
.direction_input = xeon_gpio_direction_in,
|
||||
.set = xeon_gpio_set,
|
||||
.direction_output = xeon_gpio_direction_out,
|
||||
.request = xeon_gpio_request,
|
||||
.free = xeon_gpio_free,
|
||||
};
|
||||
|
||||
static int __init xeon_gpio_init(void)
|
||||
{
|
||||
int err;
|
||||
if (!request_region(GPIO_BASE, GPIO_IOSIZE, GPIO_NAME))
|
||||
return -EBUSY;
|
||||
|
||||
xeon_gpio_chip.base = GPIO_BASE_ID;
|
||||
xeon_gpio_chip.ngpio = 96;
|
||||
|
||||
err = gpiochip_add_data(&xeon_gpio_chip, NULL);
|
||||
if (err < 0)
|
||||
goto gpiochip_add_err;
|
||||
gpiod_add_lookup_table(&rg_gpio_lookup_table);
|
||||
err = platform_device_register(&i2c_gpio);
|
||||
if (err < 0) {
|
||||
goto i2c_get_adapter_err;
|
||||
}
|
||||
return 0;
|
||||
|
||||
i2c_get_adapter_err:
|
||||
gpiod_remove_lookup_table(&rg_gpio_lookup_table);
|
||||
platform_device_unregister(&i2c_gpio);
|
||||
gpiochip_remove(&xeon_gpio_chip);
|
||||
|
||||
gpiochip_add_err:
|
||||
release_region(GPIO_BASE, GPIO_IOSIZE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void __exit xeon_gpio_exit(void)
|
||||
{
|
||||
gpiod_remove_lookup_table(&rg_gpio_lookup_table);
|
||||
platform_device_unregister(&i2c_gpio);
|
||||
mdelay(100);
|
||||
gpiochip_remove(&xeon_gpio_chip);
|
||||
release_region(GPIO_BASE, GPIO_IOSIZE);
|
||||
}
|
||||
|
||||
module_init(xeon_gpio_init);
|
||||
module_exit(xeon_gpio_exit);
|
||||
|
||||
MODULE_AUTHOR("support <support@ragile.com>");
|
||||
MODULE_DESCRIPTION("GPIO interface for XEON Super I/O chip");
|
||||
MODULE_LICENSE("GPL");
|
266
platform/broadcom/sonic-platform-modules-ragile/common/modules/rg_fan.c
Executable file
266
platform/broadcom/sonic-platform-modules-ragile/common/modules/rg_fan.c
Executable file
@ -0,0 +1,266 @@
|
||||
/*
|
||||
* rg_fan.c - A driver for control rg_fan base on rg_fan.c
|
||||
*
|
||||
* Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
|
||||
* Copyright (c) 2019 <support@ragile.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 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/init.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/hwmon.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/mutex.h>
|
||||
|
||||
#define FAN_SIZE (256)
|
||||
#define SYS_FAN_BUF_LEN (64)
|
||||
|
||||
typedef enum {
|
||||
DBG_START,
|
||||
DBG_VERBOSE,
|
||||
DBG_KEY,
|
||||
DBG_WARN,
|
||||
DBG_ERROR,
|
||||
DBG_END,
|
||||
} dbg_level_t;
|
||||
|
||||
static int debuglevel = 0;
|
||||
|
||||
#define DBG_DEBUG(fmt, arg...) \
|
||||
do { \
|
||||
if (debuglevel > DBG_START && debuglevel < DBG_ERROR) { \
|
||||
printk(KERN_INFO "[DEBUG]:<%s, %d>:" fmt, \
|
||||
__FUNCTION__, __LINE__, ##arg); \
|
||||
} else if (debuglevel >= DBG_ERROR) { \
|
||||
printk(KERN_ERR "[DEBUG]:<%s, %d>:" fmt, __FUNCTION__, \
|
||||
__LINE__, ##arg); \
|
||||
} else { \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define DBG_ERROR(fmt, arg...) \
|
||||
do { \
|
||||
if (debuglevel > DBG_START) { \
|
||||
printk(KERN_ERR "[ERROR]:<%s, %d>:" fmt, __FUNCTION__, \
|
||||
__LINE__, ##arg); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
extern s32 platform_i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command);
|
||||
extern s32 platform_i2c_smbus_read_i2c_block_data(
|
||||
const struct i2c_client *client, u8 command, u8 length, u8 *values);
|
||||
extern s32 platform_i2c_smbus_read_word_data(const struct i2c_client *client, u8 command);
|
||||
|
||||
typedef enum dfd_dev_info_type_e {
|
||||
DFD_DEV_INFO_TYPE_MAC = 1,
|
||||
DFD_DEV_INFO_TYPE_NAME = 2,
|
||||
DFD_DEV_INFO_TYPE_SN = 3,
|
||||
DFD_DEV_INFO_TYPE_PWR_CONS = 4,
|
||||
DFD_DEV_INFO_TYPE_HW_INFO = 5,
|
||||
DFD_DEV_INFO_TYPE_DEV_TYPE = 6,
|
||||
} dfd_dev_tlv_type_t;
|
||||
|
||||
typedef struct dfd_dev_head_info_s {
|
||||
uint8_t ver; /* define E2PROM version,default is 0x01 */
|
||||
uint8_t flag; /* flag is 0x7E in new version E2PROM */
|
||||
uint8_t hw_ver; /* consists of main version and revise version */
|
||||
uint8_t type; /* HW type */
|
||||
int16_t tlv_len; /* 16 bits */
|
||||
} dfd_dev_head_info_t;
|
||||
|
||||
typedef struct dfd_dev_tlv_info_s {
|
||||
uint8_t type;
|
||||
uint8_t len;
|
||||
uint8_t data[0];
|
||||
} dfd_dev_tlv_info_t;
|
||||
|
||||
struct fan_data {
|
||||
struct i2c_client *client;
|
||||
struct mutex update_lock;
|
||||
char valid; /* !=0 if registers are valid */
|
||||
unsigned long last_updated[8]; /* In jiffies */
|
||||
u8 data[FAN_SIZE]; /* Register value */
|
||||
};
|
||||
|
||||
static ssize_t show_fan_sysfs_tlv_value(struct device *dev,
|
||||
struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct fan_data *data = i2c_get_clientdata(client);
|
||||
|
||||
dfd_dev_head_info_t info;
|
||||
uint8_t tmp_tlv_len[sizeof(uint16_t)];
|
||||
uint8_t *tlv_data;
|
||||
dfd_dev_tlv_info_t *tlv;
|
||||
int type;
|
||||
int buf_len = SYS_FAN_BUF_LEN - 1;
|
||||
u8 sysfs_buf[SYS_FAN_BUF_LEN];
|
||||
int i;
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
memset(sysfs_buf, 0, SYS_FAN_BUF_LEN);
|
||||
ret = platform_i2c_smbus_read_i2c_block_data(
|
||||
client, 0, sizeof(dfd_dev_head_info_t), (uint8_t *)&info);
|
||||
if (ret != sizeof(dfd_dev_head_info_t)) {
|
||||
DBG_ERROR("fan maybe not set mac or not present0");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* transform TLV_LEN */
|
||||
memcpy(tmp_tlv_len, (uint8_t *)&info.tlv_len, sizeof(int16_t));
|
||||
info.tlv_len = (tmp_tlv_len[0] << 8) + tmp_tlv_len[1];
|
||||
|
||||
if ((info.tlv_len <= 0) || (info.tlv_len > 0xFF)) {
|
||||
DBG_ERROR("fan maybe not set mac or not present1");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
type = attr->index;
|
||||
tlv_data = (uint8_t *)kmalloc(info.tlv_len, GFP_KERNEL);
|
||||
memset(tlv_data, 0, info.tlv_len);
|
||||
|
||||
if (i2c_check_functionality(client->adapter,
|
||||
I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
|
||||
for (i = 0; i < info.tlv_len; i += 32)
|
||||
if (platform_i2c_smbus_read_i2c_block_data(client,
|
||||
sizeof(dfd_dev_head_info_t) + i,
|
||||
32, tlv_data + i) != 32)
|
||||
break;
|
||||
}
|
||||
|
||||
DBG_DEBUG("TLV Len:%d\n", (int)sizeof(dfd_dev_tlv_info_t));
|
||||
for (tlv = (dfd_dev_tlv_info_t *)tlv_data;
|
||||
(ulong)tlv < (ulong)tlv_data + info.tlv_len;) {
|
||||
DBG_DEBUG(
|
||||
"tlv: %p, tlv->type: 0x%x, tlv->len: 0x%x info->tlv_len: 0x%x\n",
|
||||
tlv, tlv->type, tlv->len, info.tlv_len);
|
||||
if (tlv->type == type && buf_len >= tlv->len) {
|
||||
memcpy((uint8_t *)sysfs_buf, (uint8_t *)tlv->data,
|
||||
tlv->len);
|
||||
buf_len = (uint32_t)tlv->len;
|
||||
break;
|
||||
}
|
||||
tlv = (dfd_dev_tlv_info_t *)((uint8_t *)tlv +
|
||||
sizeof(dfd_dev_tlv_info_t) +
|
||||
tlv->len);
|
||||
}
|
||||
|
||||
kfree(tlv_data);
|
||||
DBG_DEBUG("value: %s \n", sysfs_buf);
|
||||
exit:
|
||||
mutex_unlock(&data->update_lock);
|
||||
return sprintf(buf, "%s\n", sysfs_buf);
|
||||
}
|
||||
|
||||
static ssize_t show_fan_value(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct fan_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
int i;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
if (i2c_check_functionality(client->adapter,
|
||||
I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
|
||||
for (i = 0; i < FAN_SIZE; i += 32) {
|
||||
if (platform_i2c_smbus_read_i2c_block_data(
|
||||
client, i, 32, data->data + i) != 32)
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < FAN_SIZE; i += 2) {
|
||||
int word = platform_i2c_smbus_read_word_data(client, i);
|
||||
if (word < 0)
|
||||
goto exit;
|
||||
data->data[i] = word & 0xff;
|
||||
data->data[i + 1] = word >> 8;
|
||||
}
|
||||
}
|
||||
memcpy(buf, &data->data[0], FAN_SIZE);
|
||||
exit:
|
||||
mutex_unlock(&data->update_lock);
|
||||
return FAN_SIZE;
|
||||
}
|
||||
|
||||
static SENSOR_DEVICE_ATTR(fan_hw_version, S_IRUGO, show_fan_sysfs_tlv_value, NULL, DFD_DEV_INFO_TYPE_HW_INFO);
|
||||
static SENSOR_DEVICE_ATTR(fan_sn, S_IRUGO, show_fan_sysfs_tlv_value, NULL, DFD_DEV_INFO_TYPE_SN);
|
||||
static SENSOR_DEVICE_ATTR(fan_type, S_IRUGO, show_fan_sysfs_tlv_value, NULL, DFD_DEV_INFO_TYPE_NAME);
|
||||
static SENSOR_DEVICE_ATTR(fan, S_IRUGO, show_fan_value, NULL, 0);
|
||||
|
||||
static struct attribute *fan_sysfs_attrs[] = {
|
||||
&sensor_dev_attr_fan_hw_version.dev_attr.attr,
|
||||
&sensor_dev_attr_fan_sn.dev_attr.attr,
|
||||
&sensor_dev_attr_fan_type.dev_attr.attr,
|
||||
&sensor_dev_attr_fan.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct attribute_group fan_sysfs_group = {
|
||||
.attrs = fan_sysfs_attrs,
|
||||
};
|
||||
|
||||
static int fan_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
{
|
||||
struct fan_data *data;
|
||||
int status;
|
||||
|
||||
status = -1;
|
||||
DBG_DEBUG("fan_probe(0x%02x)\n", client->addr);
|
||||
data = devm_kzalloc(&client->dev, sizeof(struct fan_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
data->client = client;
|
||||
i2c_set_clientdata(client, data);
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
status = sysfs_create_group(&client->dev.kobj, &fan_sysfs_group);
|
||||
if (status != 0) {
|
||||
DBG_ERROR(" sysfs_create_group err\n");
|
||||
return status;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fan_remove(struct i2c_client *client)
|
||||
{
|
||||
sysfs_remove_group(&client->dev.kobj, &fan_sysfs_group);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct i2c_device_id fan_id[] = { { "rg_fan", 0 }, {} };
|
||||
MODULE_DEVICE_TABLE(i2c, fan_id);
|
||||
|
||||
static struct i2c_driver rg_fan_driver = {
|
||||
.driver = {
|
||||
.name = "rg_fan",
|
||||
},
|
||||
.probe = fan_probe,
|
||||
.remove = fan_remove,
|
||||
.id_table = fan_id,
|
||||
};
|
||||
|
||||
module_i2c_driver(rg_fan_driver);
|
||||
MODULE_AUTHOR("support <support@ragile.com>");
|
||||
MODULE_DESCRIPTION("ragile fan driver");
|
||||
MODULE_LICENSE("GPL");
|
340
platform/broadcom/sonic-platform-modules-ragile/common/modules/rg_psu.c
Executable file
340
platform/broadcom/sonic-platform-modules-ragile/common/modules/rg_psu.c
Executable file
@ -0,0 +1,340 @@
|
||||
/*
|
||||
* rg_cpld.c - A driver for pmbus psu
|
||||
*
|
||||
* Copyright (c) 2019 <support@ragile.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 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/init.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/hwmon.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/mutex.h>
|
||||
|
||||
#define MAGIC_PSU_RATE (0xA7)
|
||||
#define MAGIC_PSU_OUT_CURRENT (0x8C)
|
||||
#define MAGIC_PSU_OUT_VOLTAGE (0x8B)
|
||||
#define MAGIC_PSU_IN_VOLTAGE (0x88)
|
||||
#define MAGIC_PSU_IN_CURRENT (0x89)
|
||||
#define MAGIC_PSU_TEMP (0x8D)
|
||||
#define MAGIC_PSU_TYPE (0x25)
|
||||
#define MAGIC_PSU_SN (0x38)
|
||||
#define MAGIC_PSU_HW (0x35)
|
||||
#define PSU_SIZE (256)
|
||||
|
||||
typedef enum {
|
||||
DBG_START,
|
||||
DBG_VERBOSE,
|
||||
DBG_KEY,
|
||||
DBG_WARN,
|
||||
DBG_ERROR,
|
||||
DBG_END,
|
||||
} dbg_level_t;
|
||||
|
||||
static int debuglevel = 0;
|
||||
|
||||
#define DBG_DEBUG(fmt, arg...) \
|
||||
do { \
|
||||
if (debuglevel > DBG_START && debuglevel < DBG_ERROR) { \
|
||||
printk(KERN_INFO "[DEBUG]:<%s, %d>:" fmt, \
|
||||
__FUNCTION__, __LINE__, ##arg); \
|
||||
} else if (debuglevel >= DBG_ERROR) { \
|
||||
printk(KERN_ERR "[DEBUG]:<%s, %d>:" fmt, __FUNCTION__, \
|
||||
__LINE__, ##arg); \
|
||||
} else { \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define DBG_INFO(fmt, arg...) \
|
||||
do { \
|
||||
if (debuglevel > DBG_KEY) { \
|
||||
printk(KERN_INFO "[INFO]:<%s, %d>:" fmt, __FUNCTION__, \
|
||||
__LINE__, ##arg); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define DBG_ERROR(fmt, arg...) \
|
||||
do { \
|
||||
if (debuglevel > DBG_START) { \
|
||||
printk(KERN_ERR "[ERROR]:<%s, %d>:" fmt, __FUNCTION__, \
|
||||
__LINE__, ##arg); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static const unsigned short rg_i2c_psu[] = { 0x50, 0x53, 0x58, 0x5b, I2C_CLIENT_END };
|
||||
|
||||
extern s32 platform_i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command);
|
||||
extern s32 platform_i2c_smbus_read_i2c_block_data(const struct i2c_client *client,
|
||||
u8 command, u8 length, u8 *values);
|
||||
|
||||
struct psu_data {
|
||||
struct i2c_client *client;
|
||||
struct device *hwmon_dev;
|
||||
struct mutex update_lock;
|
||||
char valid; /* !=0 if registers are valid */
|
||||
unsigned long last_updated; /* In jiffies */
|
||||
u8 data[PSU_SIZE]; /* Register value */
|
||||
};
|
||||
|
||||
static ssize_t show_psu_sysfs_value(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static ssize_t show_sysfs_15_value(struct device *dev, struct device_attribute *da, char *buf);
|
||||
static ssize_t show_psu_value(struct device *dev, struct device_attribute *da, char *buf);
|
||||
|
||||
static SENSOR_DEVICE_ATTR(psu_rate, S_IRUGO, show_psu_sysfs_value, NULL, MAGIC_PSU_RATE);
|
||||
static SENSOR_DEVICE_ATTR(psu_out_current, S_IRUGO, show_psu_sysfs_value, NULL, MAGIC_PSU_OUT_CURRENT);
|
||||
static SENSOR_DEVICE_ATTR(psu_out_voltage, S_IRUGO, show_psu_sysfs_value, NULL, MAGIC_PSU_OUT_VOLTAGE);
|
||||
static SENSOR_DEVICE_ATTR(psu_in_voltage, S_IRUGO, show_psu_sysfs_value, NULL, MAGIC_PSU_IN_VOLTAGE);
|
||||
static SENSOR_DEVICE_ATTR(psu_in_current, S_IRUGO, show_psu_sysfs_value, NULL, MAGIC_PSU_IN_CURRENT);
|
||||
static SENSOR_DEVICE_ATTR(psu_temp, S_IRUGO, show_psu_sysfs_value, NULL, MAGIC_PSU_TEMP);
|
||||
static SENSOR_DEVICE_ATTR(psu_type, S_IRUGO, show_sysfs_15_value, NULL, MAGIC_PSU_TYPE);
|
||||
static SENSOR_DEVICE_ATTR(psu_sn, S_IRUGO, show_sysfs_15_value, NULL, MAGIC_PSU_SN);
|
||||
static SENSOR_DEVICE_ATTR(psu_hw, S_IRUGO, show_psu_value, NULL, MAGIC_PSU_HW);
|
||||
|
||||
static struct attribute *psu_pmbus_sysfs_attrs[] = {
|
||||
&sensor_dev_attr_psu_rate.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_out_current.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_out_voltage.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_in_voltage.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_in_current.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_temp.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct attribute *psu_fru_sysfs_attrs[] = {
|
||||
&sensor_dev_attr_psu_type.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_sn.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_hw.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct attribute_group psu_pmbus_sysfs_attrs_group = {
|
||||
.attrs = psu_pmbus_sysfs_attrs,
|
||||
};
|
||||
|
||||
static const struct attribute_group psu_fru_sysfs_attrs_group = {
|
||||
.attrs = psu_fru_sysfs_attrs,
|
||||
};
|
||||
|
||||
static ssize_t show_psu_value(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct psu_data *data = i2c_get_clientdata(client);
|
||||
int ret;
|
||||
char psu_buf[PSU_SIZE];
|
||||
memset(psu_buf, 0, PSU_SIZE);
|
||||
mutex_lock(&data->update_lock);
|
||||
ret = platform_i2c_smbus_read_i2c_block_data(client, attr->index, 2, psu_buf);
|
||||
if (ret < 0) {
|
||||
DBG_ERROR("Failed to read psu\n");
|
||||
}
|
||||
DBG_DEBUG("cpld reg pos:0x%x value:0x%02x\n", attr->index, data->data[0]);
|
||||
mutex_unlock(&data->update_lock);
|
||||
return snprintf(buf, 3, "%s\n", psu_buf);
|
||||
}
|
||||
|
||||
static int linear_to_value(short reg, bool v_out)
|
||||
{
|
||||
short exponent;
|
||||
int mantissa;
|
||||
long val;
|
||||
|
||||
if (v_out) {
|
||||
exponent = -9;
|
||||
mantissa = reg;
|
||||
} else {
|
||||
exponent = reg >> 11;
|
||||
mantissa = (((reg & 0x7ff) << 5)) >> 5;
|
||||
}
|
||||
val = mantissa;
|
||||
val = val * 1000L;
|
||||
if (exponent >= 0) {
|
||||
val <<= exponent;
|
||||
} else {
|
||||
val >>= -exponent;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static ssize_t show_psu_sysfs_value(struct device *dev,
|
||||
struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct psu_data *data = i2c_get_clientdata(client);
|
||||
int ret;
|
||||
u8 smbud_buf[PSU_SIZE];
|
||||
uint16_t value;
|
||||
int result;
|
||||
|
||||
ret = -1;
|
||||
memset(smbud_buf, 0, PSU_SIZE);
|
||||
mutex_lock(&data->update_lock);
|
||||
DBG_DEBUG("ret:%d", ret);
|
||||
ret = platform_i2c_smbus_read_i2c_block_data(client, attr->index, 2, smbud_buf);
|
||||
if (ret < 0) {
|
||||
DBG_ERROR("Failed to read psu \n");
|
||||
}
|
||||
value = smbud_buf[1];
|
||||
value = value << 8;
|
||||
value |= smbud_buf[0];
|
||||
|
||||
if (attr->index == 0x8b) {
|
||||
result = linear_to_value(value, true);
|
||||
} else {
|
||||
result = linear_to_value(value, false);
|
||||
}
|
||||
mutex_unlock(&data->update_lock);
|
||||
return snprintf(buf, PSU_SIZE, "%d\n", result);
|
||||
}
|
||||
|
||||
static ssize_t show_sysfs_15_value(struct device *dev,
|
||||
struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct psu_data *data = i2c_get_clientdata(client);
|
||||
int ret;
|
||||
u8 smbud_buf[PSU_SIZE];
|
||||
|
||||
memset(smbud_buf, 0, PSU_SIZE);
|
||||
mutex_lock(&data->update_lock);
|
||||
ret = platform_i2c_smbus_read_i2c_block_data(client, attr->index, 15, smbud_buf);
|
||||
if (ret < 0) {
|
||||
DBG_ERROR("Failed to read psu\n");
|
||||
}
|
||||
mutex_unlock(&data->update_lock);
|
||||
return snprintf(buf, PSU_SIZE, "%s\n", smbud_buf);
|
||||
}
|
||||
|
||||
static ssize_t show_sysfs_13_value(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct psu_data *data = i2c_get_clientdata(client);
|
||||
int ret;
|
||||
u8 smbud_buf[PSU_SIZE];
|
||||
|
||||
memset(smbud_buf, 0, PSU_SIZE);
|
||||
mutex_lock(&data->update_lock);
|
||||
ret = platform_i2c_smbus_read_i2c_block_data(client, attr->index, 13, smbud_buf);
|
||||
if (ret < 0) {
|
||||
DBG_ERROR("Failed to read psu \n");
|
||||
}
|
||||
mutex_unlock(&data->update_lock);
|
||||
return snprintf(buf, PSU_SIZE, "%s\n", smbud_buf);
|
||||
}
|
||||
|
||||
static int psu_detect(struct i2c_client *new_client,
|
||||
struct i2c_board_info *info)
|
||||
{
|
||||
struct i2c_adapter *adapter = new_client->adapter;
|
||||
int conf;
|
||||
|
||||
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
|
||||
I2C_FUNC_SMBUS_WORD_DATA))
|
||||
return -ENODEV;
|
||||
conf = platform_i2c_smbus_read_byte_data(new_client, 0);
|
||||
if (!conf)
|
||||
return -ENODEV;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int psu_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
{
|
||||
struct psu_data *data;
|
||||
int status;
|
||||
|
||||
status = -1;
|
||||
data = devm_kzalloc(&client->dev, sizeof(struct psu_data), GFP_KERNEL);
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
|
||||
data->client = client;
|
||||
i2c_set_clientdata(client, data);
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
switch (client->addr) {
|
||||
case 0x50:
|
||||
case 0x53:
|
||||
status = sysfs_create_group(&client->dev.kobj,
|
||||
&psu_fru_sysfs_attrs_group);
|
||||
if (status != 0) {
|
||||
DBG_ERROR("%s %d sysfs_create_group err\n", __func__, __LINE__);
|
||||
}
|
||||
break;
|
||||
case 0x58:
|
||||
case 0x5b:
|
||||
status = sysfs_create_group(&client->dev.kobj,
|
||||
&psu_pmbus_sysfs_attrs_group);
|
||||
if (status != 0) {
|
||||
DBG_ERROR("%s %d sysfs_create_group err\n", __func__, __LINE__);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int psu_remove(struct i2c_client *client)
|
||||
{
|
||||
switch (client->addr) {
|
||||
case 0x50:
|
||||
case 0x53:
|
||||
sysfs_remove_group(&client->dev.kobj, &psu_fru_sysfs_attrs_group);
|
||||
break;
|
||||
case 0x58:
|
||||
case 0x5b:
|
||||
sysfs_remove_group(&client->dev.kobj, &psu_pmbus_sysfs_attrs_group);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct i2c_device_id psu_id[] = {
|
||||
{ "rg_psu", 0 },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, psu_id);
|
||||
|
||||
static struct i2c_driver rg_psu_driver = {
|
||||
.class = I2C_CLASS_HWMON,
|
||||
.driver = {
|
||||
.name = "rg_psu",
|
||||
},
|
||||
.probe = psu_probe,
|
||||
.remove = psu_remove,
|
||||
.id_table = psu_id,
|
||||
.detect = psu_detect,
|
||||
.address_list = rg_i2c_psu,
|
||||
};
|
||||
|
||||
module_i2c_driver(rg_psu_driver);
|
||||
|
||||
MODULE_AUTHOR("support <support@ragile.com>");
|
||||
MODULE_DESCRIPTION("ragile pmbus psu driver");
|
||||
MODULE_LICENSE("GPL");
|
91
platform/broadcom/sonic-platform-modules-ragile/common/script/avscontrol.py
Executable file
91
platform/broadcom/sonic-platform-modules-ragile/common/script/avscontrol.py
Executable file
@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
import click
|
||||
import time
|
||||
import traceback
|
||||
from ragileutil import wait_docker, STARTMODULE, AVSUTIL
|
||||
from rgutil.logutil import Logger
|
||||
|
||||
try:
|
||||
from rest.rest import BMCMessage
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
|
||||
logger = Logger("AVSCONTROL", syslog=True)
|
||||
|
||||
|
||||
class AliasedGroup(click.Group):
|
||||
def get_command(self, ctx, cmd_name):
|
||||
rv = click.Group.get_command(self, ctx, cmd_name)
|
||||
if rv is not None:
|
||||
return rv
|
||||
matches = [x for x in self.list_commands(ctx) if x.startswith(cmd_name)]
|
||||
if not matches:
|
||||
return None
|
||||
elif len(matches) == 1:
|
||||
return click.Group.get_command(self, ctx, matches[0])
|
||||
ctx.fail("Too many matches: %s" % ", ".join(sorted(matches)))
|
||||
|
||||
|
||||
def do_avs_ctrl():
|
||||
index = 0
|
||||
url = "/xyz/openbmc_project/hostchannel/attr/MacRov"
|
||||
while True:
|
||||
if (
|
||||
"avscontrol_restful" in STARTMODULE
|
||||
and STARTMODULE["avscontrol_restful"] == 1
|
||||
):
|
||||
try:
|
||||
# for alibmc rest.py has define get_macrov_value function
|
||||
get_macrov_value = getattr(BMCMessage(), "get_macrov_value", None)
|
||||
if callable(get_macrov_value):
|
||||
macrov_value = int(get_macrov_value())
|
||||
else:
|
||||
macrov_value = int(BMCMessage().getBmcValue(url))
|
||||
if macrov_value >= 0:
|
||||
break
|
||||
except Exception as e:
|
||||
time.sleep(2)
|
||||
continue
|
||||
else:
|
||||
if AVSUTIL.mac_adj():
|
||||
break
|
||||
|
||||
index += 1
|
||||
if index >= 10:
|
||||
logger.error("%%DEV_MONITOR-AVS: MAC Voltage adjust failed.")
|
||||
exit(-1)
|
||||
logger.info("%%AVSCONTROL success")
|
||||
exit(0)
|
||||
|
||||
|
||||
def run(interval):
|
||||
while True:
|
||||
try:
|
||||
if wait_docker(timeout=0) == True:
|
||||
time.sleep(10) # w10s
|
||||
do_avs_ctrl()
|
||||
time.sleep(interval)
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
print(e)
|
||||
|
||||
|
||||
@click.group(cls=AliasedGroup, context_settings=CONTEXT_SETTINGS)
|
||||
def main():
|
||||
"""device operator"""
|
||||
pass
|
||||
|
||||
|
||||
@main.command()
|
||||
def start():
|
||||
"""start AVS control"""
|
||||
logger.info("%%AVSCONTROL start")
|
||||
interval = 5
|
||||
run(interval)
|
||||
|
||||
|
||||
##device_i2c operation
|
||||
if __name__ == "__main__":
|
||||
main()
|
342
platform/broadcom/sonic-platform-modules-ragile/common/script/device_i2c.py
Executable file
342
platform/broadcom/sonic-platform-modules-ragile/common/script/device_i2c.py
Executable file
@ -0,0 +1,342 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import click
|
||||
import os
|
||||
import time
|
||||
from ragileconfig import GLOBALCONFIG, GLOBALINITPARAM, GLOBALINITCOMMAND, MAC_LED_RESET, STARTMODULE, i2ccheck_params
|
||||
from ragileutil import rgpciwr, os_system, rgi2cset
|
||||
|
||||
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
|
||||
|
||||
class AliasedGroup(click.Group):
|
||||
def get_command(self, ctx, cmd_name):
|
||||
rv = click.Group.get_command(self, ctx, cmd_name)
|
||||
if rv is not None:
|
||||
return rv
|
||||
matches = [x for x in self.list_commands(ctx)
|
||||
if x.startswith(cmd_name)]
|
||||
if not matches:
|
||||
return None
|
||||
elif len(matches) == 1:
|
||||
return click.Group.get_command(self, ctx, matches[0])
|
||||
ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))
|
||||
|
||||
def log_os_system(cmd):
|
||||
u'''execute shell command'''
|
||||
status, output = os_system(cmd)
|
||||
if status:
|
||||
print(output)
|
||||
return status, output
|
||||
|
||||
def write_sysfs_value(reg_name, value):
|
||||
u'''write sysfs file'''
|
||||
mb_reg_file = "/sys/bus/i2c/devices/" + reg_name
|
||||
if (not os.path.isfile(mb_reg_file)):
|
||||
print(mb_reg_file, 'not found !')
|
||||
return False
|
||||
try:
|
||||
with open(mb_reg_file, 'w') as fd:
|
||||
fd.write(value)
|
||||
except Exception as error:
|
||||
return False
|
||||
return True
|
||||
|
||||
def check_driver():
|
||||
u'''whether there is driver start with rg'''
|
||||
status, output = log_os_system("lsmod | grep rg | wc -l")
|
||||
#System execution error
|
||||
if status:
|
||||
return False
|
||||
if output.isdigit() and int(output) > 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def get_pid(name):
|
||||
ret = []
|
||||
for dirname in os.listdir('/proc'):
|
||||
if dirname == 'curproc':
|
||||
continue
|
||||
try:
|
||||
with open('/proc/{}/cmdline'.format(dirname), mode='r') as fd:
|
||||
content = fd.read()
|
||||
except Exception:
|
||||
continue
|
||||
if name in content:
|
||||
ret.append(dirname)
|
||||
return ret
|
||||
|
||||
def start_avs_ctrl():
|
||||
cmd = "nohup avscontrol.py start >/dev/null 2>&1 &"
|
||||
rets = get_pid("avscontrol.py")
|
||||
if len(rets) == 0:
|
||||
os.system(cmd)
|
||||
|
||||
def start_fan_ctrl():
|
||||
if STARTMODULE['fancontrol'] == 1:
|
||||
cmd = "nohup fancontrol.py start >/dev/null 2>&1 &"
|
||||
rets = get_pid("fancontrol.py")
|
||||
if len(rets) == 0:
|
||||
os.system(cmd)
|
||||
|
||||
def starthal_fanctrl():
|
||||
if STARTMODULE.get('hal_fanctrl',0) == 1:
|
||||
cmd = "nohup hal_fanctrl.py start >/dev/null 2>&1 &"
|
||||
rets = get_pid("hal_fanctrl.py")
|
||||
if len(rets) == 0:
|
||||
os.system(cmd)
|
||||
|
||||
def starthal_ledctrl():
|
||||
if STARTMODULE.get('hal_ledctrl',0) == 1:
|
||||
cmd = "nohup hal_ledctrl.py start >/dev/null 2>&1 &"
|
||||
rets = get_pid("hal_ledctrl.py")
|
||||
if len(rets) == 0:
|
||||
os.system(cmd)
|
||||
|
||||
def start_dev_monitor():
|
||||
if STARTMODULE.get('dev_monitor',0) == 1:
|
||||
cmd = "nohup dev_monitor.py start >/dev/null 2>&1 &"
|
||||
rets = get_pid("dev_monitor.py")
|
||||
if len(rets) == 0:
|
||||
os.system(cmd)
|
||||
|
||||
def start_slot_monitor():
|
||||
if STARTMODULE.get('slot_monitor',0) == 1:
|
||||
cmd = "nohup slot_monitor.py start >/dev/null 2>&1 &"
|
||||
rets = get_pid("slot_monitor.py")
|
||||
if len(rets) == 0:
|
||||
os.system(cmd)
|
||||
|
||||
def stop_fan_ctrl():
|
||||
u'''disable fan timer service'''
|
||||
if STARTMODULE['fancontrol'] == 1:
|
||||
rets = get_pid("fancontrol.py") #
|
||||
for ret in rets:
|
||||
cmd = "kill "+ ret
|
||||
os.system(cmd)
|
||||
return True
|
||||
|
||||
def stophal_ledctrl():
|
||||
if STARTMODULE.get('hal_ledctrl',0) == 1:
|
||||
rets = get_pid("hal_ledctrl.py")
|
||||
for ret in rets:
|
||||
cmd = "kill "+ ret
|
||||
os.system(cmd)
|
||||
return True
|
||||
|
||||
|
||||
def stop_dev_monitor():
|
||||
u'''disable the fan timer service'''
|
||||
if STARTMODULE.get('dev_monitor',0) == 1:
|
||||
rets = get_pid("dev_monitor.py") #
|
||||
for ret in rets:
|
||||
cmd = "kill "+ ret
|
||||
os.system(cmd)
|
||||
return True
|
||||
|
||||
def stop_slot_monitor():
|
||||
u'''disable slot timer service'''
|
||||
if STARTMODULE.get('slot_monitor',0) == 1:
|
||||
rets = get_pid("slot_monitor.py") #
|
||||
for ret in rets:
|
||||
cmd = "kill "+ ret
|
||||
os.system(cmd)
|
||||
return True
|
||||
|
||||
def rm_dev(bus, loc):
|
||||
cmd = "echo 0x%02x > /sys/bus/i2c/devices/i2c-%d/delete_device" % (loc, bus)
|
||||
devpath = "/sys/bus/i2c/devices/%d-%04x"%(bus, loc)
|
||||
if os.path.exists(devpath):
|
||||
log_os_system(cmd)
|
||||
|
||||
def add_dev(name, bus, loc):
|
||||
if name == "lm75":
|
||||
time.sleep(0.1)
|
||||
pdevpath = "/sys/bus/i2c/devices/i2c-%d/" % (bus)
|
||||
for i in range(1, 100):#wait for mother-bus generation, maximum wait time is 10s
|
||||
if os.path.exists(pdevpath) == True:
|
||||
break
|
||||
time.sleep(0.1)
|
||||
if i % 10 == 0:
|
||||
click.echo("%%DEVICE_I2C-INIT: %s not found, wait 0.1 second ! i %d " % (pdevpath,i))
|
||||
|
||||
cmd = "echo %s 0x%02x > /sys/bus/i2c/devices/i2c-%d/new_device" % (name, loc, bus)
|
||||
devpath = "/sys/bus/i2c/devices/%d-%04x"%(bus, loc)
|
||||
if os.path.exists(devpath) == False:
|
||||
os.system(cmd)
|
||||
|
||||
def removedevs():
|
||||
devs = GLOBALCONFIG["DEVS"]
|
||||
for index in range(len(devs)-1, -1, -1 ):
|
||||
rm_dev(devs[index]["bus"] , devs[index]["loc"])
|
||||
|
||||
def adddevs():
|
||||
devs = GLOBALCONFIG["DEVS"]
|
||||
for dev in range(0, devs.__len__()):
|
||||
add_dev(devs[dev]["name"], devs[dev]["bus"] , devs[dev]["loc"])
|
||||
|
||||
def checksignaldriver(name):
|
||||
modisexistcmd = "lsmod | grep %s | wc -l" % name
|
||||
status, output = log_os_system(modisexistcmd)
|
||||
#System execution error
|
||||
if status:
|
||||
return False
|
||||
if output.isdigit() and int(output) > 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def adddriver(name, delay):
|
||||
cmd = "modprobe %s" % name
|
||||
if delay != 0:
|
||||
time.sleep(delay)
|
||||
if checksignaldriver(name) != True:
|
||||
log_os_system(cmd)
|
||||
|
||||
def removedriver(name, delay):
|
||||
realname = name.lstrip().split(" ")[0];
|
||||
cmd = "rmmod -f %s" % realname
|
||||
if checksignaldriver(realname):
|
||||
log_os_system(cmd)
|
||||
|
||||
def removedrivers():
|
||||
u'''remove all drivers'''
|
||||
if GLOBALCONFIG is None:
|
||||
click.echo("%%DEVICE_I2C-INIT: load global config failed.")
|
||||
return
|
||||
drivers = GLOBALCONFIG.get("DRIVERLISTS", None)
|
||||
if drivers is None:
|
||||
click.echo("%%DEVICE_I2C-INIT: load driver list failed.")
|
||||
return
|
||||
for index in range(len(drivers)-1, -1, -1 ):
|
||||
delay = 0
|
||||
name = ""
|
||||
if type(drivers[index]) == dict and "delay" in drivers[index]:
|
||||
name = drivers[index].get("name")
|
||||
delay = drivers[index]["delay"]
|
||||
else:
|
||||
name = drivers[index]
|
||||
removedriver(name, delay)
|
||||
|
||||
def adddrivers():
|
||||
u'''add drivers'''
|
||||
if GLOBALCONFIG is None:
|
||||
click.echo("%%DEVICE_I2C-INIT: load global config failed.")
|
||||
return
|
||||
drivers = GLOBALCONFIG.get("DRIVERLISTS", None)
|
||||
if drivers is None:
|
||||
click.echo("%%DEVICE_I2C-INIT: load driver list failed.")
|
||||
return
|
||||
for index in range(0 ,len(drivers)):
|
||||
delay = 0
|
||||
name = ""
|
||||
if type(drivers[index]) == dict and "delay" in drivers[index]:
|
||||
name = drivers[index].get("name")
|
||||
delay = drivers[index]["delay"]
|
||||
else:
|
||||
name = drivers[index]
|
||||
adddriver(name, delay)
|
||||
|
||||
def otherinit():
|
||||
for index in GLOBALINITPARAM:
|
||||
# write_sysfs_value(index["loc"], index["value"])
|
||||
ret, _ = rgi2cset(
|
||||
index.get("bus"),
|
||||
index.get("devaddr"),
|
||||
index.get("offset"),
|
||||
index.get("val")
|
||||
)
|
||||
if not ret:
|
||||
click.echo("%%DEVICE_I2C-INIT: init param %s failed." % index.get("name"))
|
||||
|
||||
for index in GLOBALINITCOMMAND:
|
||||
log_os_system(index)
|
||||
|
||||
def unload_driver():
|
||||
u'''remove devices and drivers'''
|
||||
stop_dev_monitor() # disable removable device driver monitors
|
||||
stop_fan_ctrl() # disable fan-control service
|
||||
removedevs() # remove other devices
|
||||
removedrivers() # remove drivers
|
||||
|
||||
def reload_driver():
|
||||
u'''reload devices and drivers'''
|
||||
removedevs() # remove other devices
|
||||
removedrivers() # remove drivers
|
||||
time.sleep(1)
|
||||
adddrivers()
|
||||
adddevs()
|
||||
|
||||
|
||||
def i2c_check(bus,retrytime = 6):
|
||||
try:
|
||||
i2cpath = "/sys/bus/i2c/devices/" + bus
|
||||
while retrytime and not os.path.exists(i2cpath):
|
||||
click.echo("%%DEVICE_I2C-HA: i2c bus abnormal, last bus %s is not exist." % i2cpath)
|
||||
reload_driver()
|
||||
retrytime -= 1
|
||||
time.sleep(1)
|
||||
except Exception as e:
|
||||
click.echo("%%DEVICE_I2C-HA: %s" % str(e))
|
||||
return
|
||||
|
||||
def set_mac_leds(data):
|
||||
'''write pci register'''
|
||||
pcibus = MAC_LED_RESET.get("pcibus")
|
||||
slot = MAC_LED_RESET.get("slot")
|
||||
fn = MAC_LED_RESET.get("fn")
|
||||
bar = MAC_LED_RESET.get("bar")
|
||||
offset = MAC_LED_RESET.get("offset")
|
||||
val = MAC_LED_RESET.get(data, None)
|
||||
if val is None:
|
||||
click.echo("%%DEVICE_I2C-INIT: set_mac_leds wrong input")
|
||||
return
|
||||
rgpciwr(pcibus, slot, fn, bar, offset, val)
|
||||
|
||||
def load_driver():
|
||||
u'''load devices and drivers'''
|
||||
adddrivers()
|
||||
adddevs()
|
||||
if STARTMODULE.get("i2ccheck",0) == 1: #i2c HA
|
||||
busend = i2ccheck_params.get("busend")
|
||||
retrytime = i2ccheck_params.get("retrytime")
|
||||
i2c_check(busend,retrytime)
|
||||
start_fan_ctrl() # enable fan
|
||||
starthal_fanctrl() # enable fan control
|
||||
starthal_ledctrl() # enable LED control
|
||||
if STARTMODULE['avscontrol'] == 1:
|
||||
start_avs_ctrl() # avs voltage-adjustment
|
||||
start_dev_monitor() # enable removable device driver monitors
|
||||
start_slot_monitor() # slot insertion and removal initialization monitor
|
||||
otherinit(); # other initialization, QSFP initialization
|
||||
if STARTMODULE.get("macledreset", 0) == 1:
|
||||
set_mac_leds("reset")
|
||||
|
||||
@click.group(cls=AliasedGroup, context_settings=CONTEXT_SETTINGS)
|
||||
def main():
|
||||
'''device operator'''
|
||||
pass
|
||||
|
||||
|
||||
@main.command()
|
||||
def start():
|
||||
'''load device '''
|
||||
if check_driver():
|
||||
unload_driver()
|
||||
load_driver()
|
||||
|
||||
@main.command()
|
||||
def stop():
|
||||
'''stop device '''
|
||||
unload_driver()
|
||||
|
||||
@main.command()
|
||||
def restart():
|
||||
'''restart device'''
|
||||
unload_driver()
|
||||
load_driver()
|
||||
|
||||
if __name__ == '__main__':
|
||||
u'''device_i2c operation'''
|
||||
main()
|
991
platform/broadcom/sonic-platform-modules-ragile/common/script/fancontrol.py
Executable file
991
platform/broadcom/sonic-platform-modules-ragile/common/script/fancontrol.py
Executable file
@ -0,0 +1,991 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
import click
|
||||
import os
|
||||
import time
|
||||
import traceback
|
||||
import glob
|
||||
from rgutil.logutil import Logger
|
||||
from ragileutil import wait_docker
|
||||
|
||||
from ragileconfig import (
|
||||
MONITOR_CONST,
|
||||
FANCTROLDEBUG,
|
||||
MONITOR_FANS_LED,
|
||||
DEV_LEDS,
|
||||
MONITOR_PSU_STATUS,
|
||||
MONITOR_SYS_PSU_LED,
|
||||
MONITOR_DEV_STATUS,
|
||||
MONITOR_FAN_STATUS,
|
||||
MONITOR_DEV_STATUS_DECODE,
|
||||
MONITOR_SYS_FAN_LED,
|
||||
MONITOR_SYS_LED,
|
||||
fanloc,
|
||||
)
|
||||
|
||||
from ragileutil import (
|
||||
rgi2cget,
|
||||
get_mac_temp_sysfs,
|
||||
get_mac_temp,
|
||||
write_sysfs_value,
|
||||
get_sysfs_value,
|
||||
strtoint,
|
||||
rgi2cset,
|
||||
)
|
||||
|
||||
|
||||
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
|
||||
|
||||
DEBUG_COMMON = 0x01
|
||||
DEBUG_LEDCONTROL = 0x02
|
||||
DEBUG_FANCONTROL = 0x04
|
||||
|
||||
LOG_PREFIX = "FANCONTROL"
|
||||
logger = Logger(LOG_PREFIX, syslog=True, dbg_mask=FANCTROLDEBUG)
|
||||
|
||||
|
||||
class AliasedGroup(click.Group):
|
||||
def get_command(self, ctx, cmd_name):
|
||||
rv = click.Group.get_command(self, ctx, cmd_name)
|
||||
if rv is not None:
|
||||
return rv
|
||||
matches = [x for x in self.list_commands(ctx) if x.startswith(cmd_name)]
|
||||
if not matches:
|
||||
return None
|
||||
elif len(matches) == 1:
|
||||
return click.Group.get_command(self, ctx, matches[0])
|
||||
ctx.fail("Too many matches: %s" % ", ".join(sorted(matches)))
|
||||
|
||||
|
||||
class FanControl(object):
|
||||
critnum = 0
|
||||
|
||||
def __init__(self):
|
||||
self._normal_fans = 0
|
||||
self._normal_psus = 0
|
||||
self._intemp = -100.0
|
||||
self._mac_aver = -100.0
|
||||
self._mac_max = -100.0
|
||||
# previous temperature
|
||||
self._pre_intemp = -100
|
||||
self._outtemp = -100
|
||||
self._boardtemp = -100
|
||||
self._cputemp = -1000
|
||||
|
||||
@property
|
||||
def normal_fans(self):
|
||||
return self._normal_fans
|
||||
|
||||
@property
|
||||
def normal_psus(self):
|
||||
return self._normal_psus
|
||||
|
||||
@property
|
||||
def cputemp(self):
|
||||
return self._cputemp
|
||||
|
||||
@property
|
||||
def intemp(self):
|
||||
return self._intemp
|
||||
|
||||
@property
|
||||
def outtemp(self):
|
||||
return self._outtemp
|
||||
|
||||
@property
|
||||
def boardtemp(self):
|
||||
return self._boardtemp
|
||||
|
||||
@property
|
||||
def mac_aver(self):
|
||||
return self._mac_aver
|
||||
|
||||
@property
|
||||
def preIntemp(self):
|
||||
return self._pre_intemp
|
||||
|
||||
@property
|
||||
def mac_max(self):
|
||||
return self._mac_max
|
||||
|
||||
def sortCallback(self, element):
|
||||
return element["id"]
|
||||
|
||||
def gettemp(self, ret):
|
||||
u"""get inlet, outlet, hot-point and cpu temperature"""
|
||||
temp_conf = MONITOR_DEV_STATUS.get("temperature", None)
|
||||
|
||||
if temp_conf is None:
|
||||
logger.error("gettemp: config error")
|
||||
return False
|
||||
for item_temp in temp_conf:
|
||||
try:
|
||||
retval = ""
|
||||
rval = None
|
||||
name = item_temp.get("name")
|
||||
location = item_temp.get("location")
|
||||
if name == "cpu":
|
||||
L = []
|
||||
for dirpath, dirnames, filenames in os.walk(location):
|
||||
for file in filenames:
|
||||
if file.endswith("input"):
|
||||
L.append(os.path.join(dirpath, file))
|
||||
L = sorted(L, reverse=False)
|
||||
for i in range(len(L)):
|
||||
nameloc = "%s/temp%d_label" % (location, i + 1)
|
||||
valloc = "%s/temp%d_input" % (location, i + 1)
|
||||
with open(nameloc, "r") as fd1:
|
||||
retval2 = fd1.read()
|
||||
with open(valloc, "r") as fd2:
|
||||
retval3 = fd2.read()
|
||||
ret_t = {}
|
||||
ret_t["name"] = retval2.strip()
|
||||
ret_t["value"] = float(retval3) / 1000
|
||||
ret.append(ret_t)
|
||||
logger.debug(
|
||||
DEBUG_COMMON,
|
||||
"gettemp %s : %f" % (ret_t["name"], ret_t["value"]),
|
||||
)
|
||||
else:
|
||||
locations = glob.glob(location)
|
||||
with open(locations[0], "r") as fd1:
|
||||
retval = fd1.read()
|
||||
rval = float(retval) / 1000
|
||||
ret_t = {}
|
||||
ret_t["name"] = name
|
||||
ret_t["value"] = rval
|
||||
ret.append(ret_t)
|
||||
logger.debug(
|
||||
DEBUG_COMMON,
|
||||
"gettemp %s : %f" % (ret_t["name"], ret_t["value"]),
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error("gettemp error:name:%s" % name)
|
||||
logger.error(str(e))
|
||||
return True
|
||||
|
||||
def checkslot(self, ret):
|
||||
u"""get slot present status"""
|
||||
slots_conf = MONITOR_DEV_STATUS.get("slots", None)
|
||||
slotpresent = MONITOR_DEV_STATUS_DECODE.get("slotpresent", None)
|
||||
|
||||
if slots_conf is None or slotpresent is None:
|
||||
return False
|
||||
for item_slot in slots_conf:
|
||||
totalerr = 0
|
||||
try:
|
||||
ret_t = {}
|
||||
ret_t["id"] = item_slot.get("name")
|
||||
ret_t["status"] = ""
|
||||
gettype = item_slot.get("gettype")
|
||||
presentbit = item_slot.get("presentbit")
|
||||
if gettype == "io":
|
||||
io_addr = item_slot.get("io_addr")
|
||||
val = io_rd(io_addr)
|
||||
if val is not None:
|
||||
retval = val
|
||||
else:
|
||||
totalerr -= 1
|
||||
logger.error(
|
||||
" %s %s" % (item_slot.get("name"), "lpc read failed"),
|
||||
)
|
||||
else:
|
||||
bus = item_slot.get("bus")
|
||||
loc = item_slot.get("loc")
|
||||
offset = item_slot.get("offset")
|
||||
ind, val = rgi2cget(bus, loc, offset)
|
||||
if ind == True:
|
||||
retval = val
|
||||
else:
|
||||
totalerr -= 1
|
||||
logger.error(
|
||||
" %s %s" % (item_slot.get("name"), "i2c read failed"),
|
||||
)
|
||||
if totalerr < 0:
|
||||
ret_t["status"] = "NOT OK"
|
||||
ret.append(ret_t)
|
||||
continue
|
||||
val_t = (int(retval, 16) & (1 << presentbit)) >> presentbit
|
||||
logger.debug(
|
||||
DEBUG_COMMON,
|
||||
"%s present:%s" % (item_slot.get("name"), slotpresent.get(val_t)),
|
||||
)
|
||||
if val_t != slotpresent.get("okval"):
|
||||
ret_t["status"] = "ABSENT"
|
||||
else:
|
||||
ret_t["status"] = "PRESENT"
|
||||
except Exception as e:
|
||||
ret_t["status"] = "NOT OK"
|
||||
totalerr -= 1
|
||||
logger.error("checkslot error")
|
||||
logger.error(str(e))
|
||||
ret.append(ret_t)
|
||||
return True
|
||||
|
||||
def checkpsu(self, ret):
|
||||
u"""get psu status present, output and warning"""
|
||||
psus_conf = MONITOR_DEV_STATUS.get("psus", None)
|
||||
psupresent = MONITOR_DEV_STATUS_DECODE.get("psupresent", None)
|
||||
psuoutput = MONITOR_DEV_STATUS_DECODE.get("psuoutput", None)
|
||||
psualert = MONITOR_DEV_STATUS_DECODE.get("psualert", None)
|
||||
|
||||
if psus_conf is None or psupresent is None or psuoutput is None:
|
||||
logger.error("checkpsu: config error")
|
||||
return False
|
||||
for item_psu in psus_conf:
|
||||
totalerr = 0
|
||||
try:
|
||||
ret_t = {}
|
||||
ret_t["id"] = item_psu.get("name")
|
||||
ret_t["status"] = ""
|
||||
gettype = item_psu.get("gettype")
|
||||
presentbit = item_psu.get("presentbit")
|
||||
statusbit = item_psu.get("statusbit")
|
||||
alertbit = item_psu.get("alertbit")
|
||||
if gettype == "io":
|
||||
io_addr = item_psu.get("io_addr")
|
||||
val = io_rd(io_addr)
|
||||
if val is not None:
|
||||
retval = val
|
||||
else:
|
||||
totalerr -= 1
|
||||
logger.error(
|
||||
" %s %s" % (item_psu.get("name"), "lpc read failed"),
|
||||
)
|
||||
else:
|
||||
bus = item_psu.get("bus")
|
||||
loc = item_psu.get("loc")
|
||||
offset = item_psu.get("offset")
|
||||
ind, val = rgi2cget(bus, loc, offset)
|
||||
if ind == True:
|
||||
retval = val
|
||||
else:
|
||||
totalerr -= 1
|
||||
logger.error(
|
||||
" %s %s" % (item_psu.get("name"), "i2c read failed"),
|
||||
)
|
||||
if totalerr < 0:
|
||||
ret_t["status"] = "NOT OK"
|
||||
ret.append(ret_t)
|
||||
continue
|
||||
val_t = (int(retval, 16) & (1 << presentbit)) >> presentbit
|
||||
val_status = (int(retval, 16) & (1 << statusbit)) >> statusbit
|
||||
val_alert = (int(retval, 16) & (1 << alertbit)) >> alertbit
|
||||
logger.debug(
|
||||
DEBUG_COMMON,
|
||||
"%s present:%s output:%s alert:%s"
|
||||
% (
|
||||
item_psu.get("name"),
|
||||
psupresent.get(val_t),
|
||||
psuoutput.get(val_status),
|
||||
psualert.get(val_alert),
|
||||
),
|
||||
)
|
||||
if (
|
||||
val_t != psupresent.get("okval")
|
||||
or val_status != psuoutput.get("okval")
|
||||
or val_alert != psualert.get("okval")
|
||||
):
|
||||
totalerr -= 1
|
||||
except Exception as e:
|
||||
totalerr -= 1
|
||||
logger.error("checkpsu error")
|
||||
logger.error(str(e))
|
||||
if totalerr < 0:
|
||||
ret_t["status"] = "NOT OK"
|
||||
else:
|
||||
ret_t["status"] = "OK"
|
||||
ret.append(ret_t)
|
||||
return True
|
||||
|
||||
def checkfan(self, ret):
|
||||
u"""get fan status present and roll"""
|
||||
fans_conf = MONITOR_DEV_STATUS.get("fans", None)
|
||||
fanpresent = MONITOR_DEV_STATUS_DECODE.get("fanpresent", None)
|
||||
fanroll = MONITOR_DEV_STATUS_DECODE.get("fanroll", None)
|
||||
|
||||
if fans_conf is None or fanpresent is None or fanroll is None:
|
||||
logger.error("checkfan: config error")
|
||||
return False
|
||||
for item_fan in fans_conf:
|
||||
totalerr = 0
|
||||
try:
|
||||
ret_t = {}
|
||||
ret_t["id"] = item_fan.get("name")
|
||||
ret_t["status"] = ""
|
||||
presentstatus = item_fan.get("presentstatus")
|
||||
presentbus = presentstatus.get("bus")
|
||||
presentloc = presentstatus.get("loc")
|
||||
presentaddr = presentstatus.get("offset")
|
||||
presentbit = presentstatus.get("bit")
|
||||
ind, val = rgi2cget(presentbus, presentloc, presentaddr)
|
||||
if ind == True:
|
||||
val_t = (int(val, 16) & (1 << presentbit)) >> presentbit
|
||||
logger.debug(
|
||||
DEBUG_COMMON,
|
||||
"checkfan:%s present status:%s"
|
||||
% (item_fan.get("name"), fanpresent.get(val_t)),
|
||||
)
|
||||
if val_t != fanpresent.get("okval"):
|
||||
ret_t["status"] = "ABSENT"
|
||||
ret.append(ret_t)
|
||||
continue
|
||||
else:
|
||||
logger.error(
|
||||
"checkfan: %s get present status error." % item_fan.get("name"),
|
||||
)
|
||||
motors = item_fan.get("rollstatus")
|
||||
for motor in motors:
|
||||
statusbus = motor.get("bus", None)
|
||||
statusloc = motor.get("loc", None)
|
||||
statusaddr = motor.get("offset", None)
|
||||
statusbit = motor.get("bit", None)
|
||||
ind, val = rgi2cget(statusbus, statusloc, statusaddr)
|
||||
if ind == True:
|
||||
val_t = (int(val, 16) & (1 << statusbit)) >> statusbit
|
||||
logger.debug(
|
||||
DEBUG_COMMON,
|
||||
"checkfan:%s roll status:%s"
|
||||
% (motor.get("name"), fanroll.get(val_t)),
|
||||
)
|
||||
if val_t != fanroll.get("okval"):
|
||||
totalerr -= 1
|
||||
else:
|
||||
totalerr -= 1
|
||||
logger.error("checkfan: %s " % item_fan.get("name"))
|
||||
logger.error("get %s status error." % motor["name"])
|
||||
except Exception as e:
|
||||
totalerr -= 1
|
||||
logger.error("checkfan error")
|
||||
logger.error(str(e))
|
||||
if totalerr < 0:
|
||||
ret_t["status"] = "NOT OK"
|
||||
else:
|
||||
ret_t["status"] = "OK"
|
||||
ret.append(ret_t)
|
||||
return True
|
||||
|
||||
def get_curr_speed(self):
|
||||
try:
|
||||
loc = fanloc[0].get("location", "")
|
||||
sped = get_sysfs_value(loc)
|
||||
value = strtoint(sped)
|
||||
return value
|
||||
except Exception as e:
|
||||
logger.error("%%policy: get current speedlevel error")
|
||||
logger.error(str(e))
|
||||
return None
|
||||
|
||||
# guarantee the speed is lowest when speed lower than lowest value after speed-adjustment
|
||||
def check_curr_speed(self):
|
||||
logger.debug(
|
||||
DEBUG_FANCONTROL,
|
||||
"%%policy: guarantee the lowest speed after speed-adjustment",
|
||||
)
|
||||
value = self.get_curr_speed()
|
||||
if value is None or value == 0:
|
||||
raise Exception("%%policy: get_curr_speed None")
|
||||
elif value < MONITOR_CONST.MIN_SPEED:
|
||||
self.set_fan_speed(MONITOR_CONST.MIN_SPEED)
|
||||
|
||||
def set_fan_speed(self, level):
|
||||
if level >= MONITOR_CONST.MAX_SPEED:
|
||||
level = MONITOR_CONST.MAX_SPEED
|
||||
for item in fanloc:
|
||||
try:
|
||||
loc = item.get("location", "")
|
||||
# write_sysfs_value(loc, "0x%02x" % level)
|
||||
# pddf support dicimal number
|
||||
write_sysfs_value(loc, "%d" % level)
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
logger.error("%%policy: config fan runlevel error")
|
||||
self.check_curr_speed() # guaranteed minimum
|
||||
|
||||
def set_fan_max_speed(self):
|
||||
try:
|
||||
self.set_fan_speed(MONITOR_CONST.MAX_SPEED)
|
||||
except Exception as e:
|
||||
logger.error("%%policy:set_fan_max_speed failed")
|
||||
logger.error(str(e))
|
||||
|
||||
def detect_fan_status(self):
|
||||
"""
|
||||
fan status check , max speed if fan error
|
||||
"""
|
||||
if self.normal_fans < MONITOR_CONST.FAN_TOTAL_NUM:
|
||||
logger.warn(
|
||||
"%%DEV_MONITOR-FAN: Normal fan number: %d" % (self.normal_fans),
|
||||
)
|
||||
self.set_fan_max_speed()
|
||||
return False
|
||||
return True
|
||||
|
||||
def set_fan_attr(self, val):
|
||||
u"""set status of each fan"""
|
||||
for item in val:
|
||||
fanid = item.get("id")
|
||||
fanattr = fanid + "status"
|
||||
fanstatus = item.get("status")
|
||||
setattr(FanControl, fanattr, fanstatus)
|
||||
logger.debug(
|
||||
DEBUG_COMMON, "fanattr:%s,fanstatus:%s" % (fanattr, fanstatus),
|
||||
)
|
||||
|
||||
def fan_present_num(self, cur_fan_status):
|
||||
fanoknum = 0
|
||||
for item in cur_fan_status:
|
||||
if item["status"] == "OK":
|
||||
fanoknum += 1
|
||||
self._normal_fans = fanoknum
|
||||
logger.debug(DEBUG_COMMON, "normal_fans = %d" % self._normal_fans)
|
||||
|
||||
def get_fan_status(self):
|
||||
try:
|
||||
cur_fan_status = []
|
||||
ret = self.checkfan(cur_fan_status)
|
||||
if ret == True:
|
||||
self.set_fan_attr(cur_fan_status)
|
||||
self.fan_present_num(cur_fan_status)
|
||||
logger.debug(DEBUG_COMMON, "%%policy:get_fan_status success")
|
||||
return 0
|
||||
except AttributeError as e:
|
||||
logger.error(str(e))
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
return -1
|
||||
|
||||
def normal_psu_num(self, curPsuStatus):
|
||||
psuoknum = 0
|
||||
for item in curPsuStatus:
|
||||
if item.get("status") == "OK":
|
||||
psuoknum += 1
|
||||
self._normal_psus = psuoknum
|
||||
logger.debug(DEBUG_COMMON, "normal_psus = %d" % self._normal_psus)
|
||||
|
||||
def get_psu_status(self):
|
||||
try:
|
||||
curPsuStatus = []
|
||||
ret = self.checkpsu(curPsuStatus)
|
||||
if ret == True:
|
||||
self.normal_psu_num(curPsuStatus)
|
||||
logger.debug(DEBUG_COMMON, "%%policy:get_psu_status success")
|
||||
return 0
|
||||
except AttributeError as e:
|
||||
logger.error(str(e))
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
return -1
|
||||
|
||||
def get_monitor_temp(self, temp):
|
||||
for item in temp:
|
||||
if item.get("name") == "lm75in":
|
||||
self._intemp = item.get("value", self._intemp)
|
||||
if item.get("name") == "lm75out":
|
||||
self._outtemp = item.get("value", self._outtemp)
|
||||
if item.get("name") == "lm75hot":
|
||||
self._boardtemp = item.get("value", self._boardtemp)
|
||||
if item.get("name") == "Physical id 0":
|
||||
self._cputemp = item.get("value", self._cputemp)
|
||||
logger.debug(
|
||||
DEBUG_COMMON,
|
||||
"intemp:%f, outtemp:%f, boadrtemp:%f, cputemp:%f"
|
||||
% (self._intemp, self._outtemp, self._boardtemp, self._cputemp),
|
||||
)
|
||||
|
||||
def get_temp_status(self):
|
||||
try:
|
||||
monitortemp = []
|
||||
ret = self.gettemp(monitortemp)
|
||||
if ret == True:
|
||||
self.get_monitor_temp(monitortemp)
|
||||
logger.debug(DEBUG_COMMON, "%%policy:get_temp_status success")
|
||||
return 0
|
||||
except AttributeError as e:
|
||||
logger.error(str(e))
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
return -1
|
||||
|
||||
def get_mac_status_bcmcmd(self):
|
||||
try:
|
||||
if wait_docker(timeout=0) == True:
|
||||
sta, ret = get_mac_temp()
|
||||
if sta == True:
|
||||
self._mac_aver = float(ret.get("average", self._mac_aver))
|
||||
self._mac_max = float(ret.get("maximum", self._mac_max))
|
||||
logger.debug(
|
||||
DEBUG_COMMON,
|
||||
"mac_aver:%f, mac_max:%f" % (self.mac_aver, self._mac_max),
|
||||
)
|
||||
else:
|
||||
logger.debug(DEBUG_COMMON, "%%policy:get_mac_status_bcmcmd failed")
|
||||
else:
|
||||
logger.debug(DEBUG_COMMON, "%%policy:get_mac_status_bcmcmd SDK not OK")
|
||||
return 0
|
||||
except AttributeError as e:
|
||||
logger.error(str(e))
|
||||
return -1
|
||||
|
||||
def get_mac_status_sysfs(self, conf):
|
||||
try:
|
||||
sta, ret = get_mac_temp_sysfs(conf)
|
||||
if sta == True:
|
||||
self._mac_aver = float(ret) / 1000
|
||||
self._mac_max = float(ret) / 1000
|
||||
logger.debug(
|
||||
DEBUG_COMMON,
|
||||
"mac_aver:%f, mac_max:%f" % (self.mac_aver, self._mac_max),
|
||||
)
|
||||
elif conf.get("try_bcmcmd", 0) == 1:
|
||||
logger.debug(
|
||||
DEBUG_COMMON, "get sysfs mac temp failed.try to use bcmcmd",
|
||||
)
|
||||
self.get_mac_status_bcmcmd()
|
||||
else:
|
||||
logger.debug(DEBUG_COMMON, "%%policy:get_mac_status_sysfs failed")
|
||||
return 0
|
||||
except AttributeError as e:
|
||||
logger.error(str(e))
|
||||
return -1
|
||||
|
||||
def get_mac_status(self):
|
||||
try:
|
||||
mactempconf = MONITOR_DEV_STATUS.get("mac_temp", None)
|
||||
if mactempconf is not None:
|
||||
self.get_mac_status_sysfs(mactempconf)
|
||||
else:
|
||||
self.get_mac_status_bcmcmd()
|
||||
return 0
|
||||
except AttributeError as e:
|
||||
logger.error(str(e))
|
||||
return -1
|
||||
|
||||
def set_slot_attr(self, val):
|
||||
u"""set each slot present status attribute"""
|
||||
for item in val:
|
||||
slotid = item.get("id")
|
||||
slotattr = slotid + "status"
|
||||
slotstatus = item.get("status")
|
||||
setattr(FanControl, slotattr, slotstatus)
|
||||
logger.debug(
|
||||
DEBUG_COMMON, "slotattr:%s,slotstatus:%s" % (slotattr, slotstatus),
|
||||
)
|
||||
|
||||
def get_slot_status(self):
|
||||
try:
|
||||
curSlotStatus = []
|
||||
ret = self.checkslot(curSlotStatus)
|
||||
if ret == True:
|
||||
self.set_slot_attr(curSlotStatus)
|
||||
logger.debug(DEBUG_COMMON, "%%policy:get_slot_status success")
|
||||
except AttributeError as e:
|
||||
logger.error(str(e))
|
||||
return 0
|
||||
|
||||
def fanctrol(self): # fan speed-adjustment
|
||||
try:
|
||||
if self.preIntemp <= -1000:
|
||||
self.preIntemp = self.intemp
|
||||
logger.debug(
|
||||
DEBUG_FANCONTROL,
|
||||
"%%policy:previous temperature[%.2f] , current temperature[%.2f]"
|
||||
% (self.preIntemp, self.intemp),
|
||||
)
|
||||
if self.intemp < MONITOR_CONST.TEMP_MIN:
|
||||
logger.debug(
|
||||
DEBUG_FANCONTROL,
|
||||
"%%policy:inlet %.2f minimum temperature: %.2f"
|
||||
% (self.intemp, MONITOR_CONST.TEMP_MIN),
|
||||
)
|
||||
self.set_fan_speed(MONITOR_CONST.DEFAULT_SPEED) # default level
|
||||
elif self.intemp >= MONITOR_CONST.TEMP_MIN and self.intemp > self.preIntemp:
|
||||
logger.debug(DEBUG_FANCONTROL, "%%policy:increase temperature")
|
||||
self.policy_speed(self.intemp)
|
||||
elif (
|
||||
self.intemp >= MONITOR_CONST.TEMP_MIN
|
||||
and (self.preIntemp - self.intemp) > MONITOR_CONST.MONITOR_FALL_TEMP
|
||||
):
|
||||
logger.debug(
|
||||
DEBUG_FANCONTROL,
|
||||
"%%policy:temperature reduce over %d degree"
|
||||
% MONITOR_CONST.MONITOR_FALL_TEMP,
|
||||
)
|
||||
self.policy_speed(self.intemp)
|
||||
else:
|
||||
speed = (
|
||||
self.get_curr_speed()
|
||||
) # set according to current speed, prevent fan watch-dog
|
||||
if speed is not None:
|
||||
self.set_fan_speed(speed)
|
||||
logger.debug(DEBUG_FANCONTROL, "%%policy:change nothing")
|
||||
except Exception as e:
|
||||
logger.error("%%policy: fancontrol error")
|
||||
|
||||
def start_fan_ctrl(self):
|
||||
"""
|
||||
start speed-adjustment
|
||||
"""
|
||||
self.check_crit()
|
||||
if (
|
||||
self.critnum == 0
|
||||
and self.check_warn() == False
|
||||
and self.detect_fan_status() == True
|
||||
):
|
||||
self.fanctrol()
|
||||
self.check_dev_err()
|
||||
logger.debug(
|
||||
DEBUG_FANCONTROL,
|
||||
"%%policy: speed after speed-adjustment is %0x" % (self.get_curr_speed()),
|
||||
)
|
||||
|
||||
def policy_speed(self, temp): # fan speed-adjustment algorithm
|
||||
logger.debug(DEBUG_FANCONTROL, "%%policy:fan speed-adjustment algorithm")
|
||||
sped_level = MONITOR_CONST.DEFAULT_SPEED + MONITOR_CONST.K * (
|
||||
temp - MONITOR_CONST.TEMP_MIN
|
||||
)
|
||||
self.set_fan_speed(sped_level)
|
||||
self.preIntemp = self.intemp
|
||||
|
||||
def board_moni_msg(self, ledcontrol=False):
|
||||
ret_t = 0
|
||||
try:
|
||||
ret_t += (
|
||||
self.get_fan_status()
|
||||
) # get fan status, get number of fan which status is OK
|
||||
ret_t += (
|
||||
self.get_temp_status()
|
||||
) # get inlet, outlet, hot-point temperature, CPU temperature
|
||||
ret_t += self.get_mac_status() # get MAC highest and average temperature
|
||||
if ledcontrol == True:
|
||||
ret_t += self.get_slot_status() # get slot present status
|
||||
ret_t += self.get_psu_status() # get psu status
|
||||
if ret_t == 0:
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
return False
|
||||
|
||||
# device error algorithm Tmac-Tin >= 50, or Tmac-Tin <= -50
|
||||
def check_dev_err(self):
|
||||
try:
|
||||
if (self.mac_aver - self.intemp) >= MONITOR_CONST.MAC_UP_TEMP or (
|
||||
self.mac_aver - self.intemp
|
||||
) <= MONITOR_CONST.MAC_LOWER_TEMP:
|
||||
logger.debug(
|
||||
DEBUG_FANCONTROL, "%%DEV_MONITOR-TEMP: MAC temp get failed.",
|
||||
)
|
||||
value = self.get_curr_speed()
|
||||
if MONITOR_CONST.MAC_ERROR_SPEED >= value:
|
||||
self.set_fan_speed(MONITOR_CONST.MAC_ERROR_SPEED)
|
||||
else:
|
||||
self.set_fan_max_speed()
|
||||
else:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error("%%policy:check_dev_err failed")
|
||||
logger.error(str(e))
|
||||
|
||||
def check_temp_warn(self):
|
||||
u"""check whether temperature above the normal alarm value"""
|
||||
try:
|
||||
if (
|
||||
self._mac_aver >= MONITOR_CONST.MAC_WARNING_THRESHOLD
|
||||
or self._outtemp >= MONITOR_CONST.OUTTEMP_WARNING_THRESHOLD
|
||||
or self._boardtemp >= MONITOR_CONST.BOARDTEMP_WARNING_THRESHOLD
|
||||
or self._cputemp >= MONITOR_CONST.CPUTEMP_WARNING_THRESHOLD
|
||||
or self._intemp >= MONITOR_CONST.INTEMP_WARNING_THRESHOLD
|
||||
):
|
||||
logger.debug(
|
||||
DEBUG_COMMON,
|
||||
"check whether temperature above the normal alarm value",
|
||||
)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error("%%policy: check_temp_warn failed")
|
||||
logger.error(str(e))
|
||||
return False
|
||||
|
||||
def check_temp_crit(self):
|
||||
u"""check whether temperature above the critical alarm value"""
|
||||
try:
|
||||
if self._mac_aver >= MONITOR_CONST.MAC_CRITICAL_THRESHOLD or (
|
||||
self._outtemp >= MONITOR_CONST.OUTTEMP_CRITICAL_THRESHOLD
|
||||
and self._boardtemp >= MONITOR_CONST.BOARDTEMP_CRITICAL_THRESHOLD
|
||||
and self._cputemp >= MONITOR_CONST.CPUTEMP_CRITICAL_THRESHOLD
|
||||
and self._intemp >= MONITOR_CONST.INTEMP_CRITICAL_THRESHOLD
|
||||
):
|
||||
logger.debug(
|
||||
DEBUG_COMMON, "temperature above the critical alarm value",
|
||||
)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error("%%policy: check_temp_crit failed")
|
||||
logger.error(str(e))
|
||||
return False
|
||||
|
||||
def check_fan_status(self):
|
||||
u"""check fan status"""
|
||||
for item in MONITOR_FAN_STATUS:
|
||||
maxoknum = item.get("maxOkNum")
|
||||
minoknum = item.get("minOkNum")
|
||||
status = item.get("status")
|
||||
if self.normal_fans >= minoknum and self.normal_fans <= maxoknum:
|
||||
logger.debug(
|
||||
DEBUG_COMMON,
|
||||
"check_fan_status:normal_fans:%d,status:%s"
|
||||
% (self.normal_fans, status),
|
||||
)
|
||||
return status
|
||||
logger.debug(
|
||||
DEBUG_COMMON, "check_fan_status Error:normal_fans:%d" % (self.normal_fans),
|
||||
)
|
||||
return None
|
||||
|
||||
def check_psu_status(self):
|
||||
u"""check psu status"""
|
||||
for item in MONITOR_PSU_STATUS:
|
||||
maxoknum = item.get("maxOkNum")
|
||||
minoknum = item.get("minOkNum")
|
||||
status = item.get("status")
|
||||
if self.normal_psus >= minoknum and self.normal_psus <= maxoknum:
|
||||
logger.debug(
|
||||
DEBUG_COMMON,
|
||||
"check_psu_status:normal_psus:%d,status:%s"
|
||||
% (self.normal_psus, status),
|
||||
)
|
||||
return status
|
||||
logger.debug(
|
||||
DEBUG_COMMON, "check_psu_status Error:normal_psus:%d" % (self.normal_psus),
|
||||
)
|
||||
return None
|
||||
|
||||
def deal_sys_led_status(self):
|
||||
u"""set up SYSLED according to temperature, fan and psu status"""
|
||||
try:
|
||||
fanstatus = self.check_fan_status()
|
||||
psustatus = self.check_psu_status()
|
||||
if (
|
||||
self.check_temp_crit() == True
|
||||
or fanstatus == "red"
|
||||
or psustatus == "red"
|
||||
):
|
||||
status = "red"
|
||||
elif (
|
||||
self.check_temp_warn() == True
|
||||
or fanstatus == "yellow"
|
||||
or psustatus == "yellow"
|
||||
):
|
||||
status = "yellow"
|
||||
else:
|
||||
status = "green"
|
||||
self.set_sys_leds(status)
|
||||
logger.debug(
|
||||
DEBUG_LEDCONTROL,
|
||||
"%%ledcontrol:deal_sys_led_status success, status:%s," % status,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
|
||||
def deal_sys_fan_led_status(self):
|
||||
u"""light panel fan led according to status"""
|
||||
try:
|
||||
status = self.check_fan_status()
|
||||
if status is not None:
|
||||
self.set_sys_fan_leds(status)
|
||||
logger.debug(
|
||||
DEBUG_LEDCONTROL,
|
||||
"%%ledcontrol:deal_sys_fan_led_status success, status:%s," % status,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error("%%ledcontrol:deal_sys_led_status error")
|
||||
logger.error(str(e))
|
||||
|
||||
def deal_psu_led_status(self):
|
||||
u"""set up PSU-LED according to psu status"""
|
||||
try:
|
||||
status = self.check_psu_status()
|
||||
if status is not None:
|
||||
self.set_sys_psu_leds(status)
|
||||
logger.debug(
|
||||
DEBUG_LEDCONTROL,
|
||||
"%%ledcontrol:deal_psu_led_status success, status:%s," % status,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error("%%ledcontrol:deal_psu_led_status error")
|
||||
logger.error(str(e))
|
||||
|
||||
def deal_fan_led_status(self):
|
||||
u"""light fan led according to fan status"""
|
||||
for item in MONITOR_FANS_LED:
|
||||
try:
|
||||
index = MONITOR_FANS_LED.index(item) + 1
|
||||
fanattr = "fan%dstatus" % index
|
||||
val_t = getattr(FanControl, fanattr, None)
|
||||
if val_t == "NOT OK":
|
||||
rgi2cset(item["bus"], item["devno"], item["addr"], item["red"])
|
||||
elif val_t == "OK":
|
||||
rgi2cset(item["bus"], item["devno"], item["addr"], item["green"])
|
||||
else:
|
||||
pass
|
||||
logger.debug(
|
||||
DEBUG_LEDCONTROL,
|
||||
"%%ledcontrol:dealLocFanLed success.fanattr:%s, status:%s"
|
||||
% (fanattr, val_t),
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error("%%ledcontrol:deal_fan_led_status error")
|
||||
logger.error(str(e))
|
||||
|
||||
def dealSlotLedStatus(self):
|
||||
u"""light slot status led according to slot present status"""
|
||||
slotLedList = DEV_LEDS.get("SLOTLED", [])
|
||||
for item in slotLedList:
|
||||
try:
|
||||
index = slotLedList.index(item) + 1
|
||||
slotattr = "slot%dstatus" % index
|
||||
val_t = getattr(FanControl, slotattr, None)
|
||||
if val_t == "PRESENT":
|
||||
rgi2cset(item["bus"], item["devno"], item["addr"], item["green"])
|
||||
logger.debug(
|
||||
DEBUG_LEDCONTROL,
|
||||
"%%ledcontrol:dealSlotLedStatus success.slotattr:%s, status:%s"
|
||||
% (slotattr, val_t),
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error("%%ledcontrol:dealSlotLedStatus error")
|
||||
logger.error(str(e))
|
||||
|
||||
def setled(self, item, color):
|
||||
if item.get("type", "i2c") == "sysfs":
|
||||
rgsysset(item["cmdstr"], item.get(color))
|
||||
else:
|
||||
mask = item.get("mask", 0xFF)
|
||||
ind, val = rgi2cget(item["bus"], item["devno"], item["addr"])
|
||||
if ind == True:
|
||||
setval = (int(val, 16) & ~mask) | item.get(color)
|
||||
rgi2cset(item["bus"], item["devno"], item["addr"], setval)
|
||||
else:
|
||||
logger.error("led %s" % "i2c read failed")
|
||||
|
||||
def set_sys_leds(self, color):
|
||||
for item in MONITOR_SYS_LED:
|
||||
self.setled(item, color)
|
||||
|
||||
def set_sys_fan_leds(self, color):
|
||||
for item in MONITOR_SYS_FAN_LED:
|
||||
self.setled(item, color)
|
||||
|
||||
def set_sys_psu_leds(self, color):
|
||||
for item in MONITOR_SYS_PSU_LED:
|
||||
self.setled(item, color)
|
||||
|
||||
def check_warn(self):
|
||||
try:
|
||||
if self.check_temp_warn() == True:
|
||||
logger.debug(DEBUG_FANCONTROL, "anti-shake start")
|
||||
time.sleep(MONITOR_CONST.SHAKE_TIME)
|
||||
logger.debug(DEBUG_FANCONTROL, "anti-shake end")
|
||||
self.board_moni_msg() # re-read
|
||||
if self.check_temp_warn() == True:
|
||||
logger.warn("%%DEV_MONITOR-TEMP:The temperature of device is over warning value.")
|
||||
self.set_fan_max_speed() # fan full speed
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error("%%policy: check_warn failed")
|
||||
logger.error(str(e))
|
||||
return False
|
||||
|
||||
def check_crit(self):
|
||||
try:
|
||||
if self.check_temp_crit() == True:
|
||||
logger.debug(DEBUG_FANCONTROL, "anti-shake start")
|
||||
time.sleep(MONITOR_CONST.SHAKE_TIME)
|
||||
logger.debug(DEBUG_FANCONTROL, "anti-shake end")
|
||||
self.board_moni_msg() # re-read
|
||||
if self.check_temp_crit() == True:
|
||||
logger.crit(
|
||||
"%%DEV_MONITOR-TEMP:The temperature of device is over critical value.",
|
||||
)
|
||||
self.set_fan_max_speed() # fan full speed
|
||||
self.critnum += 1 # anti-shake
|
||||
if self.critnum >= MONITOR_CONST.CRITICAL_NUM:
|
||||
os.system("reboot")
|
||||
logger.debug(DEBUG_FANCONTROL, "crit times:%d" % self.critnum)
|
||||
else:
|
||||
self.critnum = 0
|
||||
else:
|
||||
self.critnum = 0
|
||||
except Exception as e:
|
||||
logger.error("%%policy: check_crit failed")
|
||||
logger.error(str(e))
|
||||
|
||||
|
||||
def callback():
|
||||
pass
|
||||
|
||||
|
||||
def do_fan_ctrl(fanctrl):
|
||||
ret = fanctrl.board_moni_msg()
|
||||
if ret == True:
|
||||
logger.debug(DEBUG_FANCONTROL, "%%policy:start_fan_ctrl")
|
||||
fanctrl.start_fan_ctrl()
|
||||
else:
|
||||
fanctrl.set_fan_max_speed()
|
||||
logger.debug(DEBUG_FANCONTROL, "%%policy:board_moni_msg error")
|
||||
|
||||
|
||||
def do_led_ctrl(fanctrl):
|
||||
fanctrl.board_moni_msg(ledcontrol=True) # get status
|
||||
fanctrl.deal_sys_led_status() # light system led
|
||||
fanctrl.deal_sys_fan_led_status() # light panel fan led
|
||||
fanctrl.deal_fan_led_status() # light fan led
|
||||
fanctrl.deal_psu_led_status() # light psu led
|
||||
fanctrl.dealSlotLedStatus() # light slot status led
|
||||
logger.debug(DEBUG_LEDCONTROL, "%%ledcontrol:do_led_ctrl success")
|
||||
|
||||
|
||||
def run(interval, fanctrl):
|
||||
loop = 0
|
||||
# waitForDocker()
|
||||
while True:
|
||||
try:
|
||||
if loop % MONITOR_CONST.MONITOR_INTERVAL == 0: # fan speed-adjustment
|
||||
logger.debug(DEBUG_FANCONTROL, "%%policy:fanctrl")
|
||||
do_fan_ctrl(fanctrl)
|
||||
else:
|
||||
logger.debug(
|
||||
DEBUG_LEDCONTROL, "%%ledcontrol:start ledctrol"
|
||||
) # LED control
|
||||
do_led_ctrl(fanctrl)
|
||||
time.sleep(interval)
|
||||
loop += interval
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
logger.error(str(e))
|
||||
|
||||
|
||||
@click.group(cls=AliasedGroup, context_settings=CONTEXT_SETTINGS)
|
||||
def main():
|
||||
"""device operator"""
|
||||
pass
|
||||
|
||||
|
||||
@main.command()
|
||||
def start():
|
||||
"""start fan control"""
|
||||
logger.info("FAN CTRL START")
|
||||
fanctrl = FanControl()
|
||||
interval = MONITOR_CONST.MONITOR_INTERVAL / 30
|
||||
run(interval, fanctrl)
|
||||
|
||||
|
||||
@main.command()
|
||||
def stop():
|
||||
"""stop fan control """
|
||||
logger.info("FAN CTRL STOP")
|
||||
|
||||
|
||||
##device_i2c operation
|
||||
if __name__ == "__main__":
|
||||
main()
|
1363
platform/broadcom/sonic-platform-modules-ragile/common/script/ragilecommon.py
Executable file
1363
platform/broadcom/sonic-platform-modules-ragile/common/script/ragilecommon.py
Executable file
File diff suppressed because it is too large
Load Diff
225
platform/broadcom/sonic-platform-modules-ragile/common/script/ragileconfig.py
Executable file
225
platform/broadcom/sonic-platform-modules-ragile/common/script/ragileconfig.py
Executable file
@ -0,0 +1,225 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
# -------------------------------------------------------------------------------
|
||||
# Name: ragileconfig.py
|
||||
# Purpose: block the difference between various product/onie version for other module
|
||||
#
|
||||
# Author: rd
|
||||
#
|
||||
# Created: 02/07/2018
|
||||
# Copyright: (c) rd 2018
|
||||
# -------------------------------------------------------------------------------
|
||||
import sys
|
||||
import os
|
||||
from rgutil.baseutil import get_machine_info
|
||||
from rgutil.baseutil import get_platform_info
|
||||
|
||||
__all__ = [
|
||||
"getdeviceplatform",
|
||||
"get_rjconfig_info",
|
||||
"MONITOR_CONST",
|
||||
"MAILBOX_DIR",
|
||||
"DEVICE",
|
||||
"GLOBALCONFIG",
|
||||
"GLOBALINITPARAM",
|
||||
"GLOBALINITCOMMAND",
|
||||
"MAC_LED_RESET",
|
||||
"STARTMODULE",
|
||||
"fanloc",
|
||||
"RAGILE_CARDID",
|
||||
"RAGILE_PRODUCTNAME",
|
||||
"RAGILE_PART_NUMBER",
|
||||
"RAGILE_LABEL_REVISION",
|
||||
"RAGILE_MAC_SIZE",
|
||||
"RAGILE_MANUF_NAME",
|
||||
"RAGILE_MANUF_COUNTRY",
|
||||
"RAGILE_VENDOR_NAME",
|
||||
"RAGILE_DIAG_VERSION",
|
||||
"RAGILE_SERVICE_TAG",
|
||||
"E2_PROTECT",
|
||||
"E2_LOC",
|
||||
"FAN_PROTECT",
|
||||
"FANS_DEF",
|
||||
"MONITOR_FANS_LED",
|
||||
"MONITOR_SYS_FAN_LED",
|
||||
"MONITOR_SYS_PSU_LED",
|
||||
"MONITOR_FAN_STATUS",
|
||||
"MONITOR_PSU_STATUS",
|
||||
"MONITOR_DEV_STATUS",
|
||||
"MONITOR_DEV_STATUS_DECODE",
|
||||
"DEV_LEDS",
|
||||
"MAC_AVS_PARAM",
|
||||
"MAC_DEFAULT_PARAM",
|
||||
"FRULISTS",
|
||||
"rg_eeprom",
|
||||
"i2ccheck_params",
|
||||
"FANCTROLDEBUG",
|
||||
"DEVMONITORDEBUG",
|
||||
]
|
||||
|
||||
|
||||
def getdeviceplatform():
|
||||
x = get_platform_info(get_machine_info())
|
||||
if x != None:
|
||||
filepath = "/usr/share/sonic/device/" + x
|
||||
return filepath
|
||||
|
||||
|
||||
platform = get_platform_info(get_machine_info())
|
||||
platformpath = getdeviceplatform()
|
||||
MAILBOX_DIR = "/sys/bus/i2c/devices/"
|
||||
grtd_productfile = (platform + "_config").replace("-", "_")
|
||||
common_productfile = "ragilecommon"
|
||||
configfile_pre = "/usr/local/bin/"
|
||||
|
||||
sys.path.append(platformpath)
|
||||
sys.path.append(configfile_pre)
|
||||
|
||||
|
||||
def get_rjconfig_info(attr_key):
|
||||
rjconf_filename = platformpath + "/plugins" + "/rj.conf"
|
||||
if not os.path.isfile(rjconf_filename):
|
||||
return None
|
||||
with open(rjconf_filename) as rjconf_file:
|
||||
for line in rjconf_file:
|
||||
tokens = line.split("=")
|
||||
if len(tokens) < 2:
|
||||
continue
|
||||
if tokens[0] == attr_key:
|
||||
return tokens[1].strip()
|
||||
return None
|
||||
|
||||
|
||||
#####BMC-Password###
|
||||
OPENBMC_PASSWORD = get_rjconfig_info("OPENBMC_PASSWORD")
|
||||
OPENBMC_PASSWORD = OPENBMC_PASSWORD if (OPENBMC_PASSWORD != None) else "0penBmc"
|
||||
|
||||
############################################################################################
|
||||
## if there is no specific file, use common file
|
||||
module_product = None
|
||||
if os.path.exists(configfile_pre + grtd_productfile + ".py"):
|
||||
module_product = __import__(grtd_productfile, globals(), locals(), [], 0)
|
||||
elif os.path.exists(configfile_pre + common_productfile + ".py"):
|
||||
module_product = __import__(common_productfile, globals(), locals(), [], 0)
|
||||
else:
|
||||
print("No Configuration existed, quit")
|
||||
exit(-1)
|
||||
############################################################################################
|
||||
|
||||
DEVICE = module_product.DEVICE
|
||||
|
||||
##########Driver loading needs parameters
|
||||
# get different product configuration
|
||||
RAGILE_GLOBALCONFIG = {
|
||||
"DRIVERLISTS": module_product.DRIVERLISTS,
|
||||
"QSFP": {
|
||||
"startbus": module_product.PCA9548START,
|
||||
"endbus": module_product.PCA9548BUSEND,
|
||||
},
|
||||
"DEVS": DEVICE,
|
||||
}
|
||||
GLOBALCONFIG = RAGILE_GLOBALCONFIG
|
||||
GLOBALINITPARAM = module_product.INIT_PARAM
|
||||
GLOBALINITCOMMAND = module_product.INIT_COMMAND
|
||||
|
||||
fancontrol_loc = module_product.fancontrol_loc
|
||||
fancontrol_config_loc = module_product.fancontrol_config_loc
|
||||
MAC_LED_RESET = module_product.MAC_LED_RESET
|
||||
###########Stat-up module parameters
|
||||
STARTMODULE = module_product.STARTMODULE
|
||||
FIRMWARE_TOOLS = module_product.FIRMWARE_TOOLS
|
||||
|
||||
|
||||
##########Manufacturing-Test need parameters
|
||||
FACTESTMODULE = module_product.FACTESTMODULE
|
||||
TESTCASE = module_product.TESTCASE
|
||||
menuList = module_product.menuList
|
||||
alltest = module_product.alltest
|
||||
diagtestall = module_product.diagtestall
|
||||
looptest = module_product.looptest
|
||||
fanloc = module_product.fanloc
|
||||
fanlevel = module_product.fanlevel # fan adjustment level
|
||||
TEMPIDCHANGE = module_product.TEMPIDCHANGE
|
||||
CPLDVERSIONS = module_product.CPLDVERSIONS
|
||||
RAGILE_CARDID = module_product.RAGILE_CARDID
|
||||
RAGILE_PRODUCTNAME = module_product.RAGILE_PRODUCTNAME
|
||||
|
||||
RAGILE_PART_NUMBER = module_product.RAGILE_PART_NUMBER
|
||||
RAGILE_LABEL_REVISION = module_product.RAGILE_LABEL_REVISION
|
||||
RAGILE_ONIE_VERSION = module_product.RAGILE_ONIE_VERSION
|
||||
RAGILE_MAC_SIZE = module_product.RAGILE_MAC_SIZE
|
||||
RAGILE_MANUF_NAME = module_product.RAGILE_MANUF_NAME
|
||||
RAGILE_MANUF_COUNTRY = module_product.RAGILE_MANUF_COUNTRY
|
||||
RAGILE_VENDOR_NAME = module_product.RAGILE_VENDOR_NAME
|
||||
RAGILE_DIAG_VERSION = module_product.RAGILE_DIAG_VERSION
|
||||
RAGILE_SERVICE_TAG = module_product.RAGILE_SERVICE_TAG
|
||||
|
||||
E2_PROTECT = module_product.E2_PROTECT
|
||||
E2_LOC = module_product.E2_LOC
|
||||
FAN_PROTECT = module_product.FAN_PROTECT
|
||||
|
||||
FANS_DEF = module_product.FANS_DEF
|
||||
MONITOR_SYS_LED = module_product.MONITOR_SYS_LED
|
||||
MONITOR_FANS_LED = module_product.MONITOR_FANS_LED
|
||||
MONITOR_SYS_FAN_LED = module_product.MONITOR_SYS_FAN_LED
|
||||
MONITOR_SYS_PSU_LED = module_product.MONITOR_SYS_PSU_LED
|
||||
MONITOR_FAN_STATUS = module_product.MONITOR_FAN_STATUS
|
||||
MONITOR_PSU_STATUS = module_product.MONITOR_PSU_STATUS
|
||||
MONITOR_DEV_STATUS = module_product.MONITOR_DEV_STATUS
|
||||
MONITOR_DEV_STATUS_DECODE = module_product.MONITOR_DEV_STATUS_DECODE
|
||||
DEV_MONITOR_PARAM = module_product.DEV_MONITOR_PARAM
|
||||
SLOT_MONITOR_PARAM = module_product.SLOT_MONITOR_PARAM
|
||||
|
||||
|
||||
DEV_LEDS = module_product.DEV_LEDS
|
||||
MEM_SLOTS = module_product.MEM_SLOTS
|
||||
|
||||
MAC_AVS_PARAM = module_product.MAC_AVS_PARAM
|
||||
MAC_DEFAULT_PARAM = module_product.MAC_DEFAULT_PARAM
|
||||
E2TYPE = module_product.E2TYPE
|
||||
FRULISTS = module_product.FRULISTS
|
||||
rg_eeprom = "%d-%04x/eeprom" % (E2_LOC["bus"], E2_LOC["devno"])
|
||||
factest_module = module_product.factest_module
|
||||
|
||||
LOCAL_LED_CONTROL = module_product.LOCAL_LED_CONTROL
|
||||
|
||||
PCIe_DEV_LIST = module_product.PCIe_DEV_LIST
|
||||
PCIe_SPEED_ITEM = module_product.PCIe_SPEED_ITEM
|
||||
i2ccheck_params = module_product.i2ccheck_params
|
||||
|
||||
|
||||
class MONITOR_CONST:
|
||||
TEMP_MIN = module_product.MONITOR_TEMP_MIN
|
||||
K = module_product.MONITOR_K
|
||||
MAC_IN = module_product.MONITOR_MAC_IN
|
||||
DEFAULT_SPEED = module_product.MONITOR_DEFAULT_SPEED
|
||||
MAX_SPEED = module_product.MONITOR_MAX_SPEED
|
||||
MIN_SPEED = module_product.MONITOR_MIN_SPEED
|
||||
MAC_ERROR_SPEED = module_product.MONITOR_MAC_ERROR_SPEED
|
||||
FAN_TOTAL_NUM = module_product.MONITOR_FAN_TOTAL_NUM
|
||||
MAC_UP_TEMP = module_product.MONITOR_MAC_UP_TEMP
|
||||
MAC_LOWER_TEMP = module_product.MONITOR_MAC_LOWER_TEMP
|
||||
MAC_MAX_TEMP = module_product.MONITOR_MAC_MAX_TEMP
|
||||
|
||||
MAC_WARNING_THRESHOLD = module_product.MONITOR_MAC_WARNING_THRESHOLD
|
||||
OUTTEMP_WARNING_THRESHOLD = module_product.MONITOR_OUTTEMP_WARNING_THRESHOLD
|
||||
BOARDTEMP_WARNING_THRESHOLD = module_product.MONITOR_BOARDTEMP_WARNING_THRESHOLD
|
||||
CPUTEMP_WARNING_THRESHOLD = module_product.MONITOR_CPUTEMP_WARNING_THRESHOLD
|
||||
INTEMP_WARNING_THRESHOLD = module_product.MONITOR_INTEMP_WARNING_THRESHOLD
|
||||
|
||||
MAC_CRITICAL_THRESHOLD = module_product.MONITOR_MAC_CRITICAL_THRESHOLD
|
||||
OUTTEMP_CRITICAL_THRESHOLD = module_product.MONITOR_OUTTEMP_CRITICAL_THRESHOLD
|
||||
BOARDTEMP_CRITICAL_THRESHOLD = module_product.MONITOR_BOARDTEMP_CRITICAL_THRESHOLD
|
||||
CPUTEMP_CRITICAL_THRESHOLD = module_product.MONITOR_CPUTEMP_CRITICAL_THRESHOLD
|
||||
INTEMP_CRITICAL_THRESHOLD = module_product.MONITOR_INTEMP_CRITICAL_THRESHOLD
|
||||
CRITICAL_NUM = module_product.MONITOR_CRITICAL_NUM
|
||||
SHAKE_TIME = module_product.MONITOR_SHAKE_TIME
|
||||
MONITOR_INTERVAL = module_product.MONITOR_INTERVAL
|
||||
MONITOR_FALL_TEMP = module_product.MONITOR_FALL_TEMP
|
||||
|
||||
MONITOR_MAC_SOURCE_SYSFS = module_product.MONITOR_MAC_SOURCE_SYSFS
|
||||
MONITOR_MAC_SOURCE_PATH = module_product.MONITOR_MAC_SOURCE_PATH
|
||||
|
||||
|
||||
FANCTROLDEBUG = 0 # 1 means enable
|
||||
DEVMONITORDEBUG = 0 # 1 means enable
|
2101
platform/broadcom/sonic-platform-modules-ragile/common/script/ragileutil.py
Executable file
2101
platform/broadcom/sonic-platform-modules-ragile/common/script/ragileutil.py
Executable file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description= ragile Global Initialize I2c drivers.
|
||||
After=pddf-platform-init.service
|
||||
Before=pmon.service
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/bin/device_i2c.py start
|
||||
ExecStop=/usr/local/bin/device_i2c.py stop
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
5
platform/broadcom/sonic-platform-modules-ragile/debian/changelog
Executable file
5
platform/broadcom/sonic-platform-modules-ragile/debian/changelog
Executable file
@ -0,0 +1,5 @@
|
||||
sonic-ragile-platform-modules (1.0) unstable; urgency=low
|
||||
|
||||
* Initial release
|
||||
|
||||
-- support <support@ragile.com> Fri, 21 APR 2017 11:11:11 -0800
|
1
platform/broadcom/sonic-platform-modules-ragile/debian/compat
Executable file
1
platform/broadcom/sonic-platform-modules-ragile/debian/compat
Executable file
@ -0,0 +1 @@
|
||||
8
|
9
platform/broadcom/sonic-platform-modules-ragile/debian/control
Executable file
9
platform/broadcom/sonic-platform-modules-ragile/debian/control
Executable file
@ -0,0 +1,9 @@
|
||||
Source: sonic-ragile-platform-modules
|
||||
Section: main
|
||||
Priority: extra
|
||||
Maintainer: support <support@ragile.com>
|
||||
Standards-Version: 3.9.3
|
||||
|
||||
Package: platform-modules-ragile-ra-b6510-48v8c
|
||||
Architecture: amd64
|
||||
Description: kernel modules for platform devices such as fan, led, sfp
|
16
platform/broadcom/sonic-platform-modules-ragile/debian/copyright
Executable file
16
platform/broadcom/sonic-platform-modules-ragile/debian/copyright
Executable file
@ -0,0 +1,16 @@
|
||||
Copyright (C) 2016 Microsoft, Inc
|
||||
Copyright (C) 2018 Ragile Network Corporation
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
@ -0,0 +1 @@
|
||||
ra-b6510-48v8c/scripts/pddf_post_driver_install.sh /usr/local/bin
|
@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
# postinst
|
||||
|
||||
kernel_version=$(uname -r)
|
||||
|
||||
if [ -e /boot/System.map-${kernel_version} ]; then
|
||||
depmod -a -F /boot/System.map-${kernel_version} ${kernel_version} || true
|
||||
fi
|
||||
|
||||
# enable platform-service
|
||||
depmod -a
|
||||
# systemctl enable platform-modules-ra-b6510-48v8c.service
|
||||
# systemctl start platform-modules-ra-b6510-48v8c.service
|
||||
systemctl enable pddf-platform-init.service
|
||||
systemctl start pddf-platform-init.service
|
||||
|
||||
#DEBHELPER#
|
5
platform/broadcom/sonic-platform-modules-ragile/debian/rule-ragile.mk
Executable file
5
platform/broadcom/sonic-platform-modules-ragile/debian/rule-ragile.mk
Executable file
@ -0,0 +1,5 @@
|
||||
currentdir = $(shell pwd)
|
||||
|
||||
MODULE_DIRS := ra-b6510-48v8c
|
||||
|
||||
export MODULE_DIRS
|
95
platform/broadcom/sonic-platform-modules-ragile/debian/rules
Executable file
95
platform/broadcom/sonic-platform-modules-ragile/debian/rules
Executable file
@ -0,0 +1,95 @@
|
||||
#!/usr/bin/make -f
|
||||
CC=gcc
|
||||
INSTALL_MOD_DIR:=extra
|
||||
KVERSION ?= $(shell uname -r)
|
||||
KERNEL_SRC := /lib/modules/$(KVERSION)
|
||||
MOD_SRC_DIR:= $(shell pwd)
|
||||
KBUILD_OUTPUT=$(KERNEL_SRC)/build
|
||||
|
||||
LIB_DIR = usr/lib/python3.7/dist-packages
|
||||
CUSTOM_RULES_DIR := $(shell pwd)/debian
|
||||
|
||||
PLATFORM_PREFIX = "x86_64-ragile"
|
||||
PLATFORM_VER = "r0"
|
||||
BDIST_DIR = "dist"
|
||||
BDIST_TARGET = "bdist_t"
|
||||
|
||||
export INSTALL_MOD_DIR top_srcdir KVERSION KERNEL_SRC CC KBUILD_OUTPUT
|
||||
|
||||
include $(CUSTOM_RULES_DIR)/rule-ragile.mk
|
||||
|
||||
#all product need common
|
||||
COMPILE_DIRS = $(MODULE_DIRS)
|
||||
|
||||
clean_dirs = $(MODULE_DIRS)
|
||||
clean_dirs += common
|
||||
|
||||
custom_clean_dirs := $(addprefix _clean_,$(clean_dirs) )
|
||||
|
||||
|
||||
%:
|
||||
dh $@
|
||||
build: $(COMPILE_DIRS)
|
||||
@echo "build success"
|
||||
|
||||
$(custom_clean_dirs):
|
||||
$(MAKE) -C $(patsubst _clean_%,%,$@) clean
|
||||
|
||||
common_build :
|
||||
$(MAKE) -C $(MOD_SRC_DIR)/common
|
||||
|
||||
$(COMPILE_DIRS): common_build
|
||||
$(MAKE) -C $(MOD_SRC_DIR)/$@
|
||||
dh_testdir
|
||||
dh_installdirs
|
||||
#
|
||||
# wheel pcakage
|
||||
@cp -r \
|
||||
$(MOD_SRC_DIR)/common/lib/rgutil \
|
||||
$(MOD_SRC_DIR)/common/lib/eepromutil \
|
||||
$(MOD_SRC_DIR)/$@/; \
|
||||
cd $(MOD_SRC_DIR)/$@; \
|
||||
python3 setup.py bdist_wheel --bdist-dir $(BDIST_DIR) -d $(BDIST_TARGET); \
|
||||
mkdir -p build/usr/share/sonic/device/$(PLATFORM_PREFIX)_$@-$(PLATFORM_VER); \
|
||||
mkdir -p build/usr/share/sonic/device/$(PLATFORM_PREFIX)_$@-$(PLATFORM_VER)/pddf; \
|
||||
cp $(BDIST_TARGET)/*.whl build/usr/share/sonic/device/$(PLATFORM_PREFIX)_$@-$(PLATFORM_VER); \
|
||||
cp $(BDIST_TARGET)/*.whl build/usr/share/sonic/device/$(PLATFORM_PREFIX)_$@-$(PLATFORM_VER)/pddf/; \
|
||||
cd $(MOD_SRC_DIR); \
|
||||
rm -rf \
|
||||
$(MOD_SRC_DIR)/$@/rgutil \
|
||||
$(MOD_SRC_DIR)/$@/eepromutil \
|
||||
$(MOD_SRC_DIR)/$@/$(BDIST_TARGET)
|
||||
|
||||
cp -r $(MOD_SRC_DIR)/common/build/* debian/platform-modules-ragile-$@/
|
||||
cp -r $(MOD_SRC_DIR)/$@/build/* debian/platform-modules-ragile-$@/
|
||||
|
||||
binary: binary-indep
|
||||
@echo "======================================================="
|
||||
|
||||
binary-indep:
|
||||
# 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
|
||||
override_dh_usrlocal:
|
||||
|
||||
override_dh_pysupport:
|
||||
|
||||
clean: $(custom_clean_dirs)
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_clean
|
||||
|
||||
.PHONY: build $(COMPILE_DIRS) binary binary-arch binary-indep clean
|
15
platform/broadcom/sonic-platform-modules-ragile/ra-b6510-48v8c/LICENSE
Executable file
15
platform/broadcom/sonic-platform-modules-ragile/ra-b6510-48v8c/LICENSE
Executable file
@ -0,0 +1,15 @@
|
||||
Copyright (C) 2016 Microsoft, Inc
|
||||
Copyright (C) 2018 Ragile Network Corporation
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
@ -0,0 +1,5 @@
|
||||
# See the SONiC project governance document for more information
|
||||
|
||||
Name = "support"
|
||||
Email = "support@ragile.com"
|
||||
Mailinglist = sonicproject@googlegroups.com
|
25
platform/broadcom/sonic-platform-modules-ragile/ra-b6510-48v8c/Makefile
Executable file
25
platform/broadcom/sonic-platform-modules-ragile/ra-b6510-48v8c/Makefile
Executable file
@ -0,0 +1,25 @@
|
||||
PWD = $(shell pwd)
|
||||
DIR_KERNEL_SRC = $(PWD)/modules/driver
|
||||
EXTRA_CFLAGS:= -I$(M)/include
|
||||
EXTRA_CFLAGS+= -Wall
|
||||
SUB_BUILD_DIR = $(PWD)/build
|
||||
INSTALL_DIR = $(SUB_BUILD_DIR)/$(KERNEL_SRC)/$(INSTALL_MOD_DIR)
|
||||
INSTALL_SCRIPT_DIR = $(SUB_BUILD_DIR)/usr/local/bin
|
||||
INSTALL_SERVICE_DIR = $(SUB_BUILD_DIR)/lib/systemd/system/
|
||||
|
||||
KBUILD_EXTRA_SYMBOLS += $(DIR_KERNEL_SRC)/Module.symvers
|
||||
export KBUILD_EXTRA_SYMBOLS
|
||||
|
||||
all:
|
||||
$(MAKE) -C $(KBUILD_OUTPUT) M=$(DIR_KERNEL_SRC) modules
|
||||
@if [ ! -d ${INSTALL_DIR} ]; then mkdir -p ${INSTALL_DIR} ;fi
|
||||
cp -r $(DIR_KERNEL_SRC)/*.ko $(INSTALL_DIR)
|
||||
@if [ ! -d ${INSTALL_SCRIPT_DIR} ]; then mkdir -p ${INSTALL_SCRIPT_DIR} ;fi
|
||||
cp -r $(PWD)/config/* $(INSTALL_SCRIPT_DIR)
|
||||
@if [ ! -d ${INSTALL_SERVICE_DIR} ]; then mkdir -p ${INSTALL_SERVICE_DIR} ;fi
|
||||
cp $(PWD)/systemd/*.service $(INSTALL_SERVICE_DIR)
|
||||
clean:
|
||||
rm -f ${DIR_KERNEL_SRC}/*.o ${DIR_KERNEL_SRC}/*.ko ${DIR_KERNEL_SRC}/*.mod.c ${DIR_KERNEL_SRC}/.*.cmd
|
||||
rm -f ${DIR_KERNEL_SRC}/Module.markers ${DIR_KERNEL_SRC}/Module.symvers ${DIR_KERNEL_SRC}/modules.order
|
||||
rm -rf ${DIR_KERNEL_SRC}/.tmp_versions
|
||||
rm -rf $(SUB_BUILD_DIR)
|
1
platform/broadcom/sonic-platform-modules-ragile/ra-b6510-48v8c/README.md
Executable file
1
platform/broadcom/sonic-platform-modules-ragile/ra-b6510-48v8c/README.md
Executable file
@ -0,0 +1 @@
|
||||
Device drivers for support of ragile platform for the SONiC project
|
@ -0,0 +1,484 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8 -*-
|
||||
from ragilecommon import *
|
||||
PCA9548START = -1
|
||||
PCA9548BUSEND = -2
|
||||
|
||||
|
||||
RAGILE_CARDID = 0x0000404a
|
||||
RAGILE_PRODUCTNAME = "RA-B6510-48V8C"
|
||||
|
||||
STARTMODULE = {
|
||||
"fancontrol":1,
|
||||
"avscontrol":1,
|
||||
"dev_monitor":1
|
||||
}
|
||||
|
||||
i2ccheck_params = {"busend":"i2c-66","retrytime":6}
|
||||
|
||||
DEV_MONITOR_PARAM = {
|
||||
"polling_time": 10,
|
||||
"psus": [
|
||||
{
|
||||
"name": "psu1",
|
||||
"present": {
|
||||
"gettype": "i2c",
|
||||
"bus": 2,
|
||||
"loc": 0x37,
|
||||
"offset": 0x51,
|
||||
"presentbit": 0,
|
||||
"okval": 0,
|
||||
},
|
||||
"device": [
|
||||
{
|
||||
"id": "psu1pmbus",
|
||||
"name": "dps550",
|
||||
"bus": 7,
|
||||
"loc": 0x58,
|
||||
"attr": "hwmon",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "psu2",
|
||||
"present": {
|
||||
"gettype": "i2c",
|
||||
"bus": 2,
|
||||
"loc": 0x37,
|
||||
"offset": 0x51,
|
||||
"presentbit": 4,
|
||||
"okval": 0,
|
||||
},
|
||||
"device": [
|
||||
{
|
||||
"id": "psu2pmbus",
|
||||
"name": "dps550",
|
||||
"bus": 8,
|
||||
"loc": 0x5B,
|
||||
"attr": "hwmon",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
fanlevel = {
|
||||
"tips":["LOW","MEDIUM","HIGH"],
|
||||
"level":[51,150,255],
|
||||
"low_speed":[500,7500,17000],
|
||||
"high_speed":[11000,22500,28500]
|
||||
}
|
||||
|
||||
# fit with pddf
|
||||
fanloc = [
|
||||
{
|
||||
"name": "FAN1/FAN2/FAN3/FAN4",
|
||||
"location": "2-0066/fan1_pwm",
|
||||
"childfans": [
|
||||
{"name": "FAN1", "location": "2-0066/fan1_input"},
|
||||
{"name": "FAN2", "location": "2-0066/fan2_input"},
|
||||
{"name": "FAN3", "location": "2-0066/fan3_input"},
|
||||
{"name": "FAN4", "location": "2-0066/fan4_input"},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
|
||||
MONITOR_TEMP_MIN = 38
|
||||
MONITOR_K = 11
|
||||
MONITOR_MAC_IN = 35
|
||||
MONITOR_DEFAULT_SPEED = 0x60
|
||||
MONITOR_MAX_SPEED = 0xFF
|
||||
MONITOR_MIN_SPEED = 0x33
|
||||
MONITOR_MAC_ERROR_SPEED = 0XBB
|
||||
MONITOR_FAN_TOTAL_NUM = 4
|
||||
MONITOR_MAC_UP_TEMP = 50
|
||||
MONITOR_MAC_LOWER_TEMP = -50
|
||||
MONITOR_MAC_MAX_TEMP = 100
|
||||
|
||||
MONITOR_FALL_TEMP = 4
|
||||
MONITOR_MAC_WARNING_THRESHOLD = 100
|
||||
MONITOR_OUTTEMP_WARNING_THRESHOLD = 85
|
||||
MONITOR_BOARDTEMP_WARNING_THRESHOLD = 85
|
||||
MONITOR_CPUTEMP_WARNING_THRESHOLD = 85
|
||||
MONITOR_INTEMP_WARNING_THRESHOLD = 70
|
||||
|
||||
MONITOR_MAC_CRITICAL_THRESHOLD = 105
|
||||
MONITOR_OUTTEMP_CRITICAL_THRESHOLD = 90
|
||||
MONITOR_BOARDTEMP_CRITICAL_THRESHOLD = 90
|
||||
MONITOR_CPUTEMP_CRITICAL_THRESHOLD = 100
|
||||
MONITOR_INTEMP_CRITICAL_THRESHOLD = 80
|
||||
MONITOR_CRITICAL_NUM = 3
|
||||
MONITOR_SHAKE_TIME = 20
|
||||
MONITOR_INTERVAL = 60
|
||||
|
||||
MONITOR_SYS_LED = [
|
||||
{"bus":2,"devno":0x33, "addr":0xb2, "yellow":0x03, "red":0x02,"green":0x01},
|
||||
{"bus":2,"devno":0x37, "addr":0xb2, "yellow":0x03, "red":0x02,"green":0x01}]
|
||||
|
||||
MONITOR_SYS_FAN_LED =[
|
||||
{"bus":2,"devno":0x33, "addr":0xb4, "yellow":0x06, "red":0x02,"green":0x04},
|
||||
]
|
||||
MONITOR_FANS_LED = [
|
||||
{"bus":2,"devno":0x32, "addr":0x23, "green":0x09, "red":0x0a},
|
||||
{"bus":2,"devno":0x32, "addr":0x24, "green":0x09, "red":0x0a},
|
||||
{"bus":2,"devno":0x32, "addr":0x25, "green":0x09, "red":0x0a},
|
||||
{"bus":2,"devno":0x32, "addr":0x26, "green":0x09, "red":0x0a}]
|
||||
|
||||
|
||||
CPLDVERSIONS = [
|
||||
{"bus":2, "devno":0x33, "name":"MAC BOARD CPLD-A"},
|
||||
{"bus":2, "devno":0x35, "name":"MAC BOARD CPLD-B"},
|
||||
{"bus":2, "devno":0x37, "name":"CONNECT BOARD CPLD-A"},
|
||||
{"bus":0, "devno":0x0d, "name":"CPU BOARD CPLD"},
|
||||
]
|
||||
|
||||
MONITOR_SYS_PSU_LED =[
|
||||
{"bus":2,"devno":0x33, "addr":0xb3, "yellow":0x06, "red":0x02,"green":0x04},
|
||||
]
|
||||
|
||||
MONITOR_FAN_STATUS = [
|
||||
{'status':'green' , 'minOkNum':4,'maxOkNum':4},
|
||||
{'status':'yellow', 'minOkNum':3,'maxOkNum':3},
|
||||
{'status':'red' , 'minOkNum':0,'maxOkNum':2},
|
||||
]
|
||||
|
||||
MONITOR_PSU_STATUS = [
|
||||
{'status':'green' , 'minOkNum':2,'maxOkNum':2},
|
||||
{'status':'yellow', 'minOkNum':1,'maxOkNum':1},
|
||||
{'status':'red' , 'minOkNum':0,'maxOkNum':0},
|
||||
]
|
||||
|
||||
|
||||
MONITOR_DEV_STATUS = {
|
||||
"temperature": [
|
||||
{"name":"lm75in", "location":"/sys/bus/i2c/devices/2-0048/hwmon/*/temp1_input"},
|
||||
{"name":"lm75out", "location":"/sys/bus/i2c/devices/2-0049/hwmon/*/temp1_input"},
|
||||
{"name":"lm75hot", "location":"/sys/bus/i2c/devices/2-004a/hwmon/*/temp1_input"},
|
||||
{"name":"cpu", "location":"/sys/class/hwmon/hwmon0"},
|
||||
],
|
||||
"fans": [
|
||||
{
|
||||
"name":"fan1",
|
||||
"presentstatus":{"bus":2, "loc":0x37, "offset":0x30, 'bit':0},
|
||||
"rollstatus": [
|
||||
{"name":"motor1","bus":2, "loc":0x37, "offset":0x31, 'bit':0},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name":"fan2",
|
||||
"presentstatus":{"bus":2, "loc":0x37, "offset":0x30, 'bit':1},
|
||||
"rollstatus":[
|
||||
{"name":"motor1","bus":2, "loc":0x37, "offset":0x31, 'bit':1},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name":"fan3",
|
||||
"presentstatus":{"bus":2, "loc":0x37, "offset":0x30, 'bit':2},
|
||||
"rollstatus":[
|
||||
{"name":"motor1","bus":2, "loc":0x37, "offset":0x31, 'bit':2},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name":"fan4",
|
||||
"presentstatus":{"bus":2, "loc":0x37, "offset":0x30, 'bit':3},
|
||||
"rollstatus":[
|
||||
{"name":"motor1","bus":2, "loc":0x37, "offset":0x31, 'bit':3},
|
||||
]
|
||||
},
|
||||
],
|
||||
"psus": [
|
||||
{"name":"psu1", "bus":2, "loc":0x37, "offset":0x51, "gettype":"i2c", 'presentbit': 0, 'statusbit':1,'alertbit':2},
|
||||
{"name":"psu2", "bus":2, "loc":0x37, "offset":0x51, "gettype":"i2c", 'presentbit': 4, 'statusbit':5,'alertbit':6},
|
||||
],
|
||||
"mac_temp" : {
|
||||
"flag" : {"bus":2, "loc":0x33, "offset":0xd4, "gettype":"i2c", 'okbit': 0, 'okval':1},
|
||||
"loc" : [
|
||||
"2-0035/mac_temp_input",
|
||||
],
|
||||
"try_bcmcmd" : 0,
|
||||
},
|
||||
}
|
||||
|
||||
MONITOR_DEV_STATUS_DECODE = {
|
||||
'fanpresent': {0:'PRESENT', 1:'ABSENT', 'okval':0},
|
||||
'fanroll' : {0:'STALL' , 1:'ROLL', 'okval':1},
|
||||
'psupresent': {0:'PRESENT', 1:'ABSENT', 'okval':0},
|
||||
'psuoutput' : {0:'FAULT' , 1:'NORMAL', 'okval':1},
|
||||
'psualert' : {0:'FAULT' , 1:'NORMAL', 'okval':1},
|
||||
}
|
||||
###################################################################
|
||||
|
||||
|
||||
|
||||
MAC_AVS_PARAM ={
|
||||
0x72:0x0384,
|
||||
0x73:0x037e,
|
||||
0x74:0x0378,
|
||||
0x75:0x0372,
|
||||
0x76:0x036b,
|
||||
0x77:0x0365,
|
||||
0x78:0x035f,
|
||||
0x79:0x0359,
|
||||
0x7a:0x0352,
|
||||
0x7b:0x034c,
|
||||
0x7c:0x0346,
|
||||
0x7d:0x0340,
|
||||
0x7e:0x0339,
|
||||
0x7f:0x0333,
|
||||
0x80:0x032d,
|
||||
0x81:0x0327,
|
||||
0x82:0x0320,
|
||||
0x83:0x031a,
|
||||
0x84:0x0314,
|
||||
0x85:0x030e,
|
||||
0x86:0x0307,
|
||||
0x87:0x0301,
|
||||
0x88:0x02fb,
|
||||
0x89:0x02f5,
|
||||
0x8A:0x02ee
|
||||
}
|
||||
|
||||
MAC_DEFAULT_PARAM = {
|
||||
"type": 1,
|
||||
"default":0x74,
|
||||
"loopaddr":0x00,
|
||||
"loop":0x00,
|
||||
"open":0x00,
|
||||
"close":0x40,
|
||||
"bus":2,
|
||||
"devno":0x60,
|
||||
"addr":0x21,
|
||||
"protectaddr":0x10,
|
||||
"sdkreg":"TOP_AVS_SEL_REG",
|
||||
"sdkcmd": "scdcmd",
|
||||
"sdkcmdargs": ["-t", 5],
|
||||
"sdktype": 0,
|
||||
"macregloc":24 ,
|
||||
"mask": 0xff
|
||||
}
|
||||
|
||||
|
||||
|
||||
DEVICE = []
|
||||
DRIVERLISTS = []
|
||||
|
||||
"""
|
||||
##
|
||||
DRIVERLISTS = [
|
||||
{"name":"i2c_dev", "delay":0},
|
||||
{"name":"i2c_algo_bit","delay":0},
|
||||
{"name":"i2c_gpio", "delay":0},
|
||||
{"name":"i2c_mux", "delay":0},
|
||||
{"name":"i2c_mux_pca9641", "delay":0},
|
||||
{"name":"i2c_mux_pca954x force_create_bus=1", "delay":0},# force_deselect_on_exit=1
|
||||
{"name":"lm75", "delay":0},
|
||||
{"name":"optoe", "delay":0},
|
||||
{"name":"at24", "delay":0},
|
||||
{"name":"rg_sff", "delay":0},
|
||||
{"name":"ragile_b6510_platform", "delay":0},
|
||||
{"name":"ragile_platform", "delay":0},
|
||||
{"name":"rg_avs", "delay":0},
|
||||
{"name":"rg_cpld", "delay":0},
|
||||
{"name":"rg_fan", "delay":0},
|
||||
{"name":"rg_psu", "delay":0},
|
||||
{"name":"pmbus_core", "delay":0},
|
||||
{"name":"csu550", "delay":0},
|
||||
{"name":"rg_gpio_xeon", "delay":0},
|
||||
{"name":"firmware_driver", "delay":0},
|
||||
{"name":"firmware_bin", "delay":0},
|
||||
{"name":"ragile_b6510_sfputil", "delay":0},
|
||||
{"name":"ragile_common dfd_my_type=0x404a", "delay":0},
|
||||
{"name":"lpc_dbg", "delay":0},
|
||||
]
|
||||
|
||||
DEVICE = [
|
||||
{"name":"pca9641","bus":0 ,"loc":0x10 },
|
||||
{"name":"pca9548","bus":2 ,"loc":0x70 },
|
||||
{"name":"lm75","bus": 2, "loc":0x48 },
|
||||
{"name":"lm75","bus": 2, "loc":0x49 },
|
||||
{"name":"lm75","bus": 2, "loc":0x4a },
|
||||
{"name":"24c02","bus":2 , "loc":0x57 },
|
||||
{"name":"rg_cpld","bus":0 ,"loc":0x32 },
|
||||
{"name":"rg_cpld","bus":1 ,"loc":0x34 },
|
||||
{"name":"rg_cpld","bus":1 ,"loc":0x36 },
|
||||
{"name":"rg_cpld","bus":2 ,"loc":0x33 },
|
||||
{"name":"rg_cpld","bus":2 ,"loc":0x35 },
|
||||
{"name":"rg_cpld","bus":2 ,"loc":0x37 },
|
||||
{"name":"rg_avs","bus": 2 ,"loc":0x60 },
|
||||
{"name":"pca9548","bus":1,"loc":0x70 },
|
||||
{"name":"pca9548","bus":1,"loc":0x71 },
|
||||
{"name":"pca9548","bus":1,"loc":0x72 },
|
||||
{"name":"pca9548","bus":1,"loc":0x73 },
|
||||
{"name":"pca9548","bus":1,"loc":0x74 },
|
||||
{"name":"pca9548","bus":1,"loc":0x75 },
|
||||
{"name":"pca9548","bus":1,"loc":0x76 },
|
||||
{"name":"rg_fan","bus":3,"loc":0x53 },
|
||||
{"name":"rg_fan","bus":4,"loc":0x53 },
|
||||
{"name":"rg_fan","bus":5,"loc":0x53 },
|
||||
{"name":"rg_fan","bus":6,"loc":0x53 },
|
||||
{"name":"rg_psu","bus":7 ,"loc":0x50 },
|
||||
{"name":"dps550","bus":7 ,"loc":0x58 },
|
||||
{"name":"rg_psu","bus":8 ,"loc":0x53 },
|
||||
{"name":"dps550","bus":8 ,"loc":0x5b },
|
||||
{"name": "optoe2", "bus": 11, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 12, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 13, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 14, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 15, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 16, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 17, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 18, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 19, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 20, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 21, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 22, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 23, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 24, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 25, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 26, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 27, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 28, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 29, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 30, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 31, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 32, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 33, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 34, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 35, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 36, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 37, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 38, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 39, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 40, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 41, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 42, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 43, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 44, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 45, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 46, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 47, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 48, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 49, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 50, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 51, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 52, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 53, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 54, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 55, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 56, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 57, "loc": 0x50},
|
||||
{"name": "optoe2", "bus": 58, "loc": 0x50},
|
||||
{"name": "optoe1", "bus": 59, "loc": 0x50},
|
||||
{"name": "optoe1", "bus": 60, "loc": 0x50},
|
||||
{"name": "optoe1", "bus": 61, "loc": 0x50},
|
||||
{"name": "optoe1", "bus": 62, "loc": 0x50},
|
||||
{"name": "optoe1", "bus": 63, "loc": 0x50},
|
||||
{"name": "optoe1", "bus": 64, "loc": 0x50},
|
||||
{"name": "optoe1", "bus": 65, "loc": 0x50},
|
||||
{"name": "optoe1", "bus": 66, "loc": 0x50},
|
||||
]
|
||||
|
||||
INIT_PARAM = [
|
||||
{"loc":"1-0034/sfp_enable","value": "01"},
|
||||
{"loc":"2-0035/sfp_enable2","value":"ff"},
|
||||
{"loc":"2-0033/mac_led", "value":"ff"},
|
||||
{"loc":"1-0034/sfp_txdis1","value":"00"},
|
||||
{"loc":"1-0034/sfp_txdis2","value":"00"},
|
||||
{"loc":"1-0034/sfp_txdis3","value":"00"},
|
||||
{"loc":"1-0036/sfp_txdis4","value":"00"},
|
||||
{"loc":"1-0036/sfp_txdis5","value":"00"},
|
||||
{"loc":"1-0036/sfp_txdis6","value":"00"},
|
||||
{"loc":fanloc[0]["location"], "value":"80"},
|
||||
{"loc":"2-0033/sfp_led1_yellow","value":"ad"},
|
||||
{"loc":"2-0035/sfp_led2_yellow","value":"ad"},
|
||||
]
|
||||
"""
|
||||
|
||||
INIT_PARAM = [
|
||||
{
|
||||
"name": "sfp_enable",
|
||||
"bus": 1,
|
||||
"devaddr": 0x34,
|
||||
"offset": 0xa1,
|
||||
"val": 0x01,
|
||||
},
|
||||
{
|
||||
"name": "sfp_eanble2",
|
||||
"bus": 2,
|
||||
"devaddr": 0x35,
|
||||
"offset": 0xa0,
|
||||
"val": 0xff,
|
||||
},
|
||||
{
|
||||
"name": "mac_led",
|
||||
"bus": 2,
|
||||
"devaddr": 0x33,
|
||||
"offset": 0xa0,
|
||||
"val": 0xff,
|
||||
},
|
||||
{
|
||||
"name": "sfp_txdis1",
|
||||
"bus": 1,
|
||||
"devaddr": 0x34,
|
||||
"offset": 0x60,
|
||||
"val": 0x00,
|
||||
},
|
||||
{
|
||||
"name": "sfp_txdis2",
|
||||
"bus": 1,
|
||||
"devaddr": 0x34,
|
||||
"offset": 0x61,
|
||||
"val": 0x00,
|
||||
},
|
||||
{
|
||||
"name": "sfp_txdis3",
|
||||
"bus": 1,
|
||||
"devaddr": 0x34,
|
||||
"offset": 0x62,
|
||||
"val": 0x00,
|
||||
},
|
||||
{
|
||||
"name": "sfp_txdis4",
|
||||
"bus": 1,
|
||||
"devaddr": 0x36,
|
||||
"offset": 0x60,
|
||||
"val": 0x00,
|
||||
},
|
||||
{
|
||||
"name": "sfp_txdis5",
|
||||
"bus": 1,
|
||||
"devaddr": 0x36,
|
||||
"offset": 0x61,
|
||||
"val": 0x00,
|
||||
},
|
||||
{
|
||||
"name": "sfp_txdis6",
|
||||
"bus": 1,
|
||||
"devaddr": 0x36,
|
||||
"offset": 0x62,
|
||||
"val": 0x00,
|
||||
},
|
||||
{
|
||||
"name": "sfp_led1_yellow",
|
||||
"bus": 2,
|
||||
"devaddr": 0x33,
|
||||
"offset": 0xad,
|
||||
"val": 0xad,
|
||||
},
|
||||
{
|
||||
"name": "sfp_led2_yellow",
|
||||
"bus": 2,
|
||||
"devaddr": 0x35,
|
||||
"offset": 0xad,
|
||||
"val": 0xad,
|
||||
},
|
||||
{
|
||||
"name": "fan_speed_set",
|
||||
"bus": 0,
|
||||
"devaddr": 0x32,
|
||||
"offset": 0x15,
|
||||
"val": 0x80,
|
||||
},
|
||||
]
|
@ -0,0 +1 @@
|
||||
obj-m := rg_cpld.o
|
@ -0,0 +1,602 @@
|
||||
/*
|
||||
* rg_cpld.c - A driver for cpld
|
||||
*
|
||||
* Copyright (c) 2019 <support@ragile.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 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/init.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/hwmon.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
|
||||
/* debug level */
|
||||
typedef enum {
|
||||
DBG_START,
|
||||
DBG_VERBOSE,
|
||||
DBG_KEY,
|
||||
DBG_WARN,
|
||||
DBG_ERROR,
|
||||
DBG_END,
|
||||
} dbg_level_t;
|
||||
|
||||
static int debuglevel = 0;
|
||||
module_param(debuglevel, int, S_IRUGO);
|
||||
|
||||
#define DBG_DEBUG(fmt, arg...) do { \
|
||||
if ( debuglevel > DBG_START && debuglevel < DBG_ERROR) { \
|
||||
printk(KERN_INFO "[DEBUG]:<%s, %d>:"fmt, __FUNCTION__, __LINE__, ##arg); \
|
||||
} else if ( debuglevel >= DBG_ERROR ) { \
|
||||
printk(KERN_ERR "[DEBUG]:<%s, %d>:"fmt, __FUNCTION__, __LINE__, ##arg); \
|
||||
} else { } \
|
||||
} while (0)
|
||||
|
||||
#define DBG_ERROR(fmt, arg...) do { \
|
||||
if ( debuglevel > DBG_START) { \
|
||||
printk(KERN_ERR "[ERROR]:<%s, %d>:"fmt, __FUNCTION__, __LINE__, ##arg); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static const unsigned short rg_i2c_cpld[] = { 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, I2C_CLIENT_END };
|
||||
|
||||
#define CPLD_SIZE 256
|
||||
#define CPLD_I2C_RETRY_TIMES 3
|
||||
#define READ_TEMP_FAIL 1000000
|
||||
|
||||
struct cpld_data {
|
||||
struct i2c_client *client;
|
||||
struct device *hwmon_dev;
|
||||
struct mutex update_lock;
|
||||
char valid; /* !=0 if registers are valid */
|
||||
unsigned long last_updated; /* In jiffies */
|
||||
u8 data[CPLD_SIZE]; /* Register value */
|
||||
};
|
||||
|
||||
static s32 cpld_i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command)
|
||||
{
|
||||
int try;
|
||||
s32 ret;
|
||||
|
||||
ret = -1;
|
||||
for (try = 0; try < CPLD_I2C_RETRY_TIMES; try++) {
|
||||
if ((ret = i2c_smbus_read_byte_data(client, command) ) >= 0 )
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static s32 cpld_i2c_smbus_read_i2c_block_data(const struct i2c_client *client,
|
||||
u8 command, u8 length, u8 *values)
|
||||
{
|
||||
int try;
|
||||
s32 ret;
|
||||
|
||||
ret = -1;
|
||||
for (try = 0; try < CPLD_I2C_RETRY_TIMES; try++) {
|
||||
if ((ret = i2c_smbus_read_i2c_block_data(client, command, length, values) ) >= 0 )
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t show_fan_rpm_value(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct cpld_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
int index = to_sensor_dev_attr_2(da)->index;
|
||||
uint8_t size;
|
||||
s32 status;
|
||||
s32 ret_t;
|
||||
|
||||
ret_t = 0;
|
||||
status = -1;
|
||||
size = 0;
|
||||
mutex_lock(&data->update_lock);
|
||||
status = cpld_i2c_smbus_read_byte_data(client, index);
|
||||
if (status < 0) {
|
||||
mutex_unlock(&data->update_lock);
|
||||
return 0;
|
||||
}
|
||||
data->data[0] = status;
|
||||
status = cpld_i2c_smbus_read_byte_data(client, index + 1);
|
||||
if (status < 0) {
|
||||
mutex_unlock(&data->update_lock);
|
||||
return 0;
|
||||
}
|
||||
data->data[1] = status;
|
||||
DBG_DEBUG("cpld reg pos:0x%x value:0x%x\n", index, data->data[0]);
|
||||
DBG_DEBUG("cpld reg pos:0x%x value:0x%x\n", index + 1, data->data[1]);
|
||||
ret_t = (data->data[1] << 8) + data->data[0] ;
|
||||
if (ret_t == 0 ) {
|
||||
size = snprintf(buf, CPLD_SIZE, "%d\n", ret_t);
|
||||
} else if (ret_t == 0xffff) {
|
||||
size = snprintf(buf, CPLD_SIZE, "%d\n", 0);
|
||||
} else {
|
||||
size = snprintf(buf, CPLD_SIZE, "%d\n", 15000000 / ret_t);
|
||||
}
|
||||
mutex_unlock(&data->update_lock);
|
||||
return size;
|
||||
}
|
||||
|
||||
static ssize_t set_cpld_sysfs_value(struct device *dev, struct device_attribute *da, const char *buf, size_t
|
||||
count)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct cpld_data *data = i2c_get_clientdata(client);
|
||||
unsigned long val;
|
||||
int err;
|
||||
|
||||
err = kstrtoul(buf, 16, &val);
|
||||
if (err)
|
||||
return err;
|
||||
if ((val < 0) || (val > 0xff)) {
|
||||
DBG_ERROR("please enter 0x00 ~ 0xff\n");
|
||||
return -1;
|
||||
}
|
||||
mutex_lock(&data->update_lock);
|
||||
data->data[0] = (u8)val;
|
||||
DBG_DEBUG("pos: 0x%02x count = %ld, data = 0x%02x\n", attr->index, count, data->data[0]);
|
||||
i2c_smbus_write_byte_data(client, attr->index, data->data[0]);
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t show_cpld_version(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct cpld_data *data = i2c_get_clientdata(client);
|
||||
s32 status;
|
||||
|
||||
status = -1;
|
||||
mutex_lock(&data->update_lock);
|
||||
status = cpld_i2c_smbus_read_i2c_block_data(client, 0, 4, data->data);
|
||||
if (status < 0) {
|
||||
mutex_unlock(&data->update_lock);
|
||||
return 0;
|
||||
}
|
||||
mutex_unlock(&data->update_lock);
|
||||
return sprintf(buf, "%02x %02x %02x %02x \n", data->data[0], data->data[1], data->data[2],
|
||||
data->data[3]);
|
||||
}
|
||||
|
||||
static ssize_t show_cpld_sysfs_value(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct cpld_data *data = i2c_get_clientdata(client);
|
||||
s32 status;
|
||||
|
||||
status = -1;
|
||||
mutex_lock(&data->update_lock);
|
||||
status = cpld_i2c_smbus_read_byte_data(client, attr->index);
|
||||
if (status < 0) {
|
||||
mutex_unlock(&data->update_lock);
|
||||
return 0;
|
||||
}
|
||||
data->data[0] = status;
|
||||
DBG_DEBUG("cpld reg pos:0x%x value:0x%02x\n", attr->index, data->data[0]);
|
||||
mutex_unlock(&data->update_lock);
|
||||
return sprintf(buf, "%02x\n", data->data[0]);
|
||||
}
|
||||
|
||||
static ssize_t show_mac_temp_value(struct device *dev, struct device_attribute *da, char *buf)
|
||||
{
|
||||
struct cpld_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
int index = to_sensor_dev_attr_2(da)->index;
|
||||
int tmp_value, value;
|
||||
s32 status;
|
||||
|
||||
status = -1;
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
status = cpld_i2c_smbus_read_byte_data(client, index);
|
||||
if (status < 0) {
|
||||
mutex_unlock(&data->update_lock);
|
||||
return snprintf(buf, CPLD_SIZE, "%d\n", -READ_TEMP_FAIL);
|
||||
}
|
||||
data->data[0] = status;
|
||||
status = cpld_i2c_smbus_read_byte_data(client, index + 1);
|
||||
if (status < 0) {
|
||||
mutex_unlock(&data->update_lock);
|
||||
return snprintf(buf, CPLD_SIZE, "%d\n", -READ_TEMP_FAIL);
|
||||
}
|
||||
data->data[1] = status;
|
||||
DBG_DEBUG("cpld reg pos:0x%x value:0x%x\n", index, data->data[0]);
|
||||
DBG_DEBUG("cpld reg pos:0x%x value:0x%x\n", index + 1, data->data[1]);
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
tmp_value = (data->data[1] << 8) + data->data[0];
|
||||
if (tmp_value == 0) {
|
||||
DBG_ERROR("invalid cpld value : %d.\n", tmp_value);
|
||||
return snprintf(buf, CPLD_SIZE, "%d\n", -READ_TEMP_FAIL);
|
||||
}
|
||||
|
||||
DBG_DEBUG("tmp_value = 0x%x\n", tmp_value);
|
||||
value = 434100 - (12500000 / (tmp_value * 100 - 1) *535);
|
||||
if ((value / 1000 < -70) || (value / 1000 > 200)) {
|
||||
return snprintf(buf, CPLD_SIZE, "%d\n", -READ_TEMP_FAIL);
|
||||
}
|
||||
|
||||
return snprintf(buf, CPLD_SIZE, "%d\n", value);
|
||||
|
||||
}
|
||||
|
||||
/* common */
|
||||
static SENSOR_DEVICE_ATTR(cpld_version, S_IRUGO | S_IWUSR, show_cpld_version, NULL, 0);
|
||||
|
||||
/*0x37 hwmon*/
|
||||
static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO | S_IWUSR ,show_fan_rpm_value, NULL, 0x1B);
|
||||
static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO | S_IWUSR ,show_fan_rpm_value, NULL, 0x1D);
|
||||
static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO | S_IWUSR ,show_fan_rpm_value, NULL, 0x1F);
|
||||
static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO | S_IWUSR ,show_fan_rpm_value, NULL, 0x21);
|
||||
|
||||
/* 0x32 */
|
||||
static SENSOR_DEVICE_ATTR(fan_speed_set, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x15);
|
||||
static SENSOR_DEVICE_ATTR(fan0_led, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x23);
|
||||
static SENSOR_DEVICE_ATTR(fan1_led, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x24);
|
||||
static SENSOR_DEVICE_ATTR(fan2_led, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x25);
|
||||
static SENSOR_DEVICE_ATTR(fan3_led, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x26);
|
||||
|
||||
/* 0x37 */
|
||||
static SENSOR_DEVICE_ATTR(fan_present, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, NULL, 0x30);
|
||||
static SENSOR_DEVICE_ATTR(fan_status, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, NULL, 0x31);
|
||||
static SENSOR_DEVICE_ATTR(psu_status, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, NULL, 0x51);
|
||||
static SENSOR_DEVICE_ATTR(broad_back_lct, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x2a);
|
||||
static SENSOR_DEVICE_ATTR(broad_back_sys, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xb2);
|
||||
|
||||
/* 0x33 */
|
||||
static SENSOR_DEVICE_ATTR(mac_led, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa0);
|
||||
static SENSOR_DEVICE_ATTR(broad_front_lct, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x2a);
|
||||
static SENSOR_DEVICE_ATTR(broad_front_bmc, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xb1);
|
||||
static SENSOR_DEVICE_ATTR(broad_front_cpu, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xb2);
|
||||
static SENSOR_DEVICE_ATTR(broad_front_pwr, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xb3);
|
||||
static SENSOR_DEVICE_ATTR(broad_front_fan, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xb4);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led1_yellow, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xad);
|
||||
static SENSOR_DEVICE_ATTR(mac_temp_flag, S_IRUGO, show_cpld_sysfs_value, NULL, 0xd4);
|
||||
|
||||
/* 0x34 */
|
||||
static SENSOR_DEVICE_ATTR(sfp_presence1, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, NULL, 0x30);
|
||||
static SENSOR_DEVICE_ATTR(sfp_presence2, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, NULL, 0x31);
|
||||
static SENSOR_DEVICE_ATTR(sfp_presence3, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, NULL, 0x32);
|
||||
|
||||
static SENSOR_DEVICE_ATTR(sfp_enable, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa1);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led1, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa2);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led2, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa3);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led3, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa4);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led_flash1, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa5);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led_flash2, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa6);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led_flash3, S_IRUGO | S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa7);
|
||||
static SENSOR_DEVICE_ATTR(sfp_txdis1, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x60);
|
||||
static SENSOR_DEVICE_ATTR(sfp_txdis2, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x61);
|
||||
static SENSOR_DEVICE_ATTR(sfp_txdis3, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0x62);
|
||||
|
||||
static SENSOR_DEVICE_ATTR(port_speed1, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc0);
|
||||
static SENSOR_DEVICE_ATTR(port_speed2, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc1);
|
||||
static SENSOR_DEVICE_ATTR(port_speed3, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc2);
|
||||
static SENSOR_DEVICE_ATTR(port_speed4, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc3);
|
||||
static SENSOR_DEVICE_ATTR(port_speed5, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc4);
|
||||
static SENSOR_DEVICE_ATTR(port_speed6, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc5);
|
||||
|
||||
/* 0x35 */
|
||||
static SENSOR_DEVICE_ATTR(sfp_enable2, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa0);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led2_yellow, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xad);
|
||||
static SENSOR_DEVICE_ATTR(mac_temp_input, S_IRUGO, show_mac_temp_value, NULL, 0xca);
|
||||
|
||||
/* 0x36 */
|
||||
static SENSOR_DEVICE_ATTR(sfp_presence4, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, NULL, 0x30);
|
||||
static SENSOR_DEVICE_ATTR(sfp_presence5, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, NULL, 0x31);
|
||||
static SENSOR_DEVICE_ATTR(sfp_presence6, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, NULL, 0x32);
|
||||
static SENSOR_DEVICE_ATTR(sfp_presence7, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, NULL, 0x33);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led4, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa2);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led5, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa3);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led6, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa4);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led7, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa5);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led_flash4, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa6);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led_flash5, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa7);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led_flash6, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa8);
|
||||
static SENSOR_DEVICE_ATTR(sfp_led_flash7, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, set_cpld_sysfs_value, 0xa9);
|
||||
|
||||
static SENSOR_DEVICE_ATTR(sfp_txdis4, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, set_cpld_sysfs_value, 0x60);
|
||||
static SENSOR_DEVICE_ATTR(sfp_txdis5, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, set_cpld_sysfs_value, 0x61);
|
||||
static SENSOR_DEVICE_ATTR(sfp_txdis6, S_IRUGO | S_IWUSR ,show_cpld_sysfs_value, set_cpld_sysfs_value, 0x62);
|
||||
|
||||
static SENSOR_DEVICE_ATTR(port_speed7, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc0);
|
||||
static SENSOR_DEVICE_ATTR(port_speed8, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc1);
|
||||
static SENSOR_DEVICE_ATTR(port_speed9, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc2);
|
||||
static SENSOR_DEVICE_ATTR(port_speed10, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc3);
|
||||
static SENSOR_DEVICE_ATTR(port_speed11, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc4);
|
||||
static SENSOR_DEVICE_ATTR(port_speed12, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc5);
|
||||
static SENSOR_DEVICE_ATTR(port_speed13, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc6);
|
||||
static SENSOR_DEVICE_ATTR(port_speed14, S_IRUGO| S_IWUSR, show_cpld_sysfs_value, set_cpld_sysfs_value, 0xc7);
|
||||
|
||||
static struct attribute *cpld32_sysfs_attrs[] = {
|
||||
&sensor_dev_attr_fan_speed_set.dev_attr.attr,
|
||||
&sensor_dev_attr_fan0_led.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,
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct attribute *cpld37_sysfs_attrs[] = {
|
||||
&sensor_dev_attr_fan_present.dev_attr.attr,
|
||||
&sensor_dev_attr_fan_status.dev_attr.attr,
|
||||
&sensor_dev_attr_psu_status.dev_attr.attr,
|
||||
&sensor_dev_attr_broad_back_lct.dev_attr.attr,
|
||||
&sensor_dev_attr_broad_back_sys.dev_attr.attr,
|
||||
&sensor_dev_attr_cpld_version.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct attribute *cpld33_sysfs_attrs[] = {
|
||||
&sensor_dev_attr_mac_led.dev_attr.attr,
|
||||
&sensor_dev_attr_broad_front_lct.dev_attr.attr,
|
||||
&sensor_dev_attr_broad_front_bmc.dev_attr.attr,
|
||||
&sensor_dev_attr_broad_front_cpu.dev_attr.attr,
|
||||
&sensor_dev_attr_broad_front_pwr.dev_attr.attr,
|
||||
&sensor_dev_attr_broad_front_fan.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led1_yellow.dev_attr.attr,
|
||||
&sensor_dev_attr_mac_temp_flag.dev_attr.attr,
|
||||
&sensor_dev_attr_cpld_version.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct attribute *cpld34_sysfs_attrs[] = {
|
||||
&sensor_dev_attr_sfp_presence1.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_presence2.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_presence3.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_enable.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led1.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led2.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led3.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led_flash1.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led_flash2.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led_flash3.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_txdis1.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_txdis2.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_txdis3.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed1.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed2.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed3.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed4.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed5.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed6.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct attribute *cpld36_sysfs_attrs[] = {
|
||||
&sensor_dev_attr_sfp_presence4.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_presence5.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_presence6.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_presence7.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led4.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led5.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led6.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led7.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led_flash4.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led_flash5.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led_flash6.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led_flash7.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_txdis4.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_txdis5.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_txdis6.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed7.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed8.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed9.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed10.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed11.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed12.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed13.dev_attr.attr,
|
||||
&sensor_dev_attr_port_speed14.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct attribute *cpld35_sysfs_attrs[] = {
|
||||
&sensor_dev_attr_sfp_enable2.dev_attr.attr,
|
||||
&sensor_dev_attr_broad_front_lct.dev_attr.attr,
|
||||
&sensor_dev_attr_broad_front_bmc.dev_attr.attr,
|
||||
&sensor_dev_attr_broad_front_cpu.dev_attr.attr,
|
||||
&sensor_dev_attr_broad_front_pwr.dev_attr.attr,
|
||||
&sensor_dev_attr_broad_front_fan.dev_attr.attr,
|
||||
&sensor_dev_attr_sfp_led2_yellow.dev_attr.attr,
|
||||
&sensor_dev_attr_mac_temp_input.dev_attr.attr,
|
||||
&sensor_dev_attr_cpld_version.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct attribute_group cpld32_sysfs_group = {
|
||||
.attrs = cpld32_sysfs_attrs,
|
||||
};
|
||||
|
||||
static const struct attribute_group cpld37_sysfs_group = {
|
||||
.attrs = cpld37_sysfs_attrs,
|
||||
};
|
||||
|
||||
static const struct attribute_group cpld33_sysfs_group = {
|
||||
.attrs = cpld33_sysfs_attrs,
|
||||
};
|
||||
|
||||
static const struct attribute_group cpld34_sysfs_group = {
|
||||
.attrs = cpld34_sysfs_attrs,
|
||||
};
|
||||
|
||||
static const struct attribute_group cpld36_sysfs_group = {
|
||||
.attrs = cpld36_sysfs_attrs,
|
||||
};
|
||||
|
||||
static const struct attribute_group cpld35_sysfs_group = {
|
||||
.attrs = cpld35_sysfs_attrs,
|
||||
};
|
||||
|
||||
static struct attribute *cpld_hwmon_attrs[] = {
|
||||
&sensor_dev_attr_fan1_input.dev_attr.attr,
|
||||
&sensor_dev_attr_fan2_input.dev_attr.attr,
|
||||
&sensor_dev_attr_fan3_input.dev_attr.attr,
|
||||
&sensor_dev_attr_fan4_input.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
ATTRIBUTE_GROUPS(cpld_hwmon);
|
||||
|
||||
struct cpld_attr_match_group {
|
||||
int bus_nr; /* I2C BUS */
|
||||
unsigned short addr; /* slave addr*/
|
||||
const struct attribute_group *attr_group_ptr;
|
||||
const struct attribute_group *attr_hwmon_ptr;
|
||||
};
|
||||
|
||||
static struct cpld_attr_match_group g_cpld_attr_match[] = {
|
||||
{0, 0x32, &cpld32_sysfs_group, NULL},
|
||||
{2, 0x37, &cpld37_sysfs_group, (struct attribute_group *)cpld_hwmon_groups},
|
||||
{2, 0x33, &cpld33_sysfs_group, NULL},
|
||||
{1, 0x34, &cpld34_sysfs_group, NULL},
|
||||
{1, 0x36, &cpld36_sysfs_group, NULL},
|
||||
{2, 0x35, &cpld35_sysfs_group, NULL},
|
||||
};
|
||||
|
||||
static const struct attribute_group *cpld_get_attr_group(struct i2c_client *client, int is_hwmon)
|
||||
{
|
||||
int i;
|
||||
struct cpld_attr_match_group *group;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(g_cpld_attr_match); i++) {
|
||||
group = &g_cpld_attr_match[i];
|
||||
DBG_DEBUG("is_hwmon %d i %d client(nr:%d,addr:0x%x), group(nr:%d,addr:0x0%x).\n", is_hwmon,
|
||||
i, client->adapter->nr, client->addr, group->bus_nr, group->addr);
|
||||
if ((client->addr == group->addr) && (client->adapter->nr == group->bus_nr)) {
|
||||
DBG_DEBUG("is_hwmon %d i %d nr %d addr %d .\n", is_hwmon, i, client->adapter->nr, client->addr);
|
||||
return (is_hwmon) ? (group->attr_hwmon_ptr) : (group->attr_group_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
DBG_DEBUG("is_hwmon %d nr %d addr %d dismatch, return NULL.\n", is_hwmon, client->adapter->nr, client->addr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int cpld_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
{
|
||||
struct cpld_data *data;
|
||||
int status;
|
||||
const struct attribute_group *sysfs_group, *hwmon_group;
|
||||
|
||||
status = -1;
|
||||
DBG_DEBUG("=========cpld_probe(addr:0x%x, nr:%d)===========\n", client->addr, client->adapter->nr);
|
||||
data = devm_kzalloc(&client->dev, sizeof(struct cpld_data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
data->client = client;
|
||||
i2c_set_clientdata(client, data);
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
sysfs_group = NULL;
|
||||
sysfs_group = cpld_get_attr_group(client, 0);
|
||||
if (sysfs_group) {
|
||||
status = sysfs_create_group(&client->dev.kobj, sysfs_group);
|
||||
DBG_DEBUG("=========(addr:0x%x, nr:%d) sysfs_create_group status %d===========\n", client->addr, client->adapter->nr, status);
|
||||
if (status != 0) {
|
||||
DBG_ERROR("sysfs_create_group status %d.\n", status);
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
DBG_DEBUG("=========(addr:0x%x, nr:%d) no sysfs_create_group \n", client->addr, client->adapter->nr);
|
||||
}
|
||||
|
||||
hwmon_group = NULL;
|
||||
hwmon_group = cpld_get_attr_group(client, 1);
|
||||
if (hwmon_group) {
|
||||
data->hwmon_dev = hwmon_device_register_with_groups(&client->dev, client->name, data, (const struct attribute_group **)hwmon_group);
|
||||
if (IS_ERR(data->hwmon_dev)) {
|
||||
sysfs_remove_group(&client->dev.kobj, (const struct attribute_group *)sysfs_group);
|
||||
DBG_ERROR("hwmon_device_register_with_groups failed ret %ld.\n", PTR_ERR(data->hwmon_dev));
|
||||
return PTR_ERR(data->hwmon_dev);
|
||||
}
|
||||
DBG_DEBUG("=========(addr:0x%x, nr:%d) hwmon_device_register_with_groups success===========\n", client->addr, client->adapter->nr);
|
||||
if (status != 0) {
|
||||
DBG_ERROR("sysfs_create_group status %d.\n", status);
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
DBG_DEBUG("=========(addr:0x%x, nr:%d) no hwmon_device_register_with_groups \n", client->addr, client->adapter->nr);
|
||||
}
|
||||
|
||||
error:
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
static int cpld_remove(struct i2c_client *client)
|
||||
{
|
||||
struct cpld_data *data = i2c_get_clientdata(client);
|
||||
const struct attribute_group *sysfs_group, *hwmon_group;
|
||||
|
||||
DBG_DEBUG("=========cpld_remove(addr:0x%x, nr:%d)===========\n", client->addr, client->adapter->nr);
|
||||
|
||||
sysfs_group = NULL;
|
||||
sysfs_group = cpld_get_attr_group(client, 0);
|
||||
if (sysfs_group) {
|
||||
DBG_DEBUG("=========(addr:0x%x, nr:%d) do sysfs_remove_group \n", client->addr, client->adapter->nr);
|
||||
sysfs_remove_group(&client->dev.kobj, (const struct attribute_group *)sysfs_group);
|
||||
} else {
|
||||
DBG_DEBUG("=========(addr:0x%x, nr:%d) no sysfs_remove_group \n", client->addr, client->adapter->nr);
|
||||
}
|
||||
|
||||
hwmon_group = NULL;
|
||||
hwmon_group = cpld_get_attr_group(client, 1);
|
||||
if (hwmon_group) {
|
||||
DBG_DEBUG("=========(addr:0x%x, nr:%d) do hwmon_device_unregister \n", client->addr, client->adapter->nr);
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
} else {
|
||||
DBG_DEBUG("=========(addr:0x%x, nr:%d) no hwmon_device_unregister \n", client->addr, client->adapter->nr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const struct i2c_device_id cpld_id[] = {
|
||||
{ "rg_cpld", 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(i2c, cpld_id);
|
||||
|
||||
static struct i2c_driver rg_cpld_driver = {
|
||||
.class = I2C_CLASS_HWMON,
|
||||
.driver = {
|
||||
.name = "rg_cpld",
|
||||
},
|
||||
.probe = cpld_probe,
|
||||
.remove = cpld_remove,
|
||||
.id_table = cpld_id,
|
||||
};
|
||||
|
||||
module_i2c_driver(rg_cpld_driver);
|
||||
|
||||
MODULE_AUTHOR("support <support@ragile.com>");
|
||||
MODULE_DESCRIPTION("ragile CPLD driver");
|
||||
MODULE_LICENSE("GPL");
|
@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
count=10
|
||||
while [ $count -gt 0 ]
|
||||
do
|
||||
lsmod | grep 9641 >/dev/null 2>&1
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
break
|
||||
fi
|
||||
count=$(( count - 1 ))
|
||||
sleep 1
|
||||
done
|
||||
|
||||
if [ $count -eq 0 ]
|
||||
then
|
||||
# mod not loaded
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d "/sys/bus/i2c/devices/i2c-2" ]
|
||||
then
|
||||
echo pca9541 0x10 > /sys/bus/i2c/devices/i2c-0/new_device
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
@ -0,0 +1,33 @@
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='sonic-platform',
|
||||
version='1.0',
|
||||
description='SONiC platform API implementation on RAGILE Platforms',
|
||||
license='Apache 2.0',
|
||||
author='SONiC Team',
|
||||
author_email='support@ragile.com',
|
||||
url='',
|
||||
maintainer='RAGILE SUPPORT TEAM',
|
||||
maintainer_email='',
|
||||
packages=[
|
||||
'sonic_platform',
|
||||
'rgutil',
|
||||
'eepromutil',
|
||||
'sonic_pcie',
|
||||
],
|
||||
classifiers=[
|
||||
'Development Status :: 3 - Alpha',
|
||||
'Environment :: Plugins',
|
||||
'Intended Audience :: Developers',
|
||||
'Intended Audience :: Information Technology',
|
||||
'Intended Audience :: System Administrators',
|
||||
'License :: OSI Approved :: Apache Software License',
|
||||
'Natural Language :: English',
|
||||
'Operating System :: POSIX :: Linux',
|
||||
'Programming Language :: Python :: 3.7',
|
||||
'Topic :: Utilities',
|
||||
],
|
||||
keywords='sonic SONiC platform PLATFORM',
|
||||
)
|
||||
|
@ -0,0 +1 @@
|
||||
__all__ = ["pcie_common"]
|
@ -0,0 +1,107 @@
|
||||
# pcie_common.py
|
||||
# Common PCIE check interfaces for SONIC
|
||||
#
|
||||
|
||||
import os
|
||||
import yaml
|
||||
import subprocess
|
||||
import re
|
||||
import sys
|
||||
from copy import deepcopy
|
||||
try:
|
||||
from .pcie import PcieBase
|
||||
except ImportError as e:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
|
||||
class PcieUtil(PcieBase):
|
||||
"""Platform-specific PCIEutil class"""
|
||||
# got the config file path
|
||||
def __init__(self, path):
|
||||
self.config_path = path
|
||||
|
||||
# load the config file
|
||||
def load_config_file(self):
|
||||
config_file = self.config_path + "/" + "pcie.yaml"
|
||||
try:
|
||||
with open(config_file) as conf_file:
|
||||
self.confInfo = yaml.load(conf_file)
|
||||
except IOError as e:
|
||||
print("Error: {}".format(str(e)))
|
||||
print("Not found config file, please add a config file manually, or generate it by running [pcieutil pcie_generate]")
|
||||
sys.exit()
|
||||
|
||||
# load current PCIe device
|
||||
def get_pcie_device(self):
|
||||
pciDict = {}
|
||||
pciList = []
|
||||
p1 = "^(\w+):(\w+)\.(\w)\s(.*)\s*\(*.*\)*"
|
||||
p2 = "^.*:.*:.*:(\w+)\s*\(*.*\)*"
|
||||
command1 = "sudo lspci"
|
||||
command2 = "sudo lspci -n"
|
||||
# run command 1
|
||||
proc1 = subprocess.Popen(command1, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
|
||||
output1 = proc1.stdout.readlines()
|
||||
proc1.communicate()
|
||||
# run command 2
|
||||
proc2 = subprocess.Popen(command2, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
|
||||
output2 = proc2.stdout.readlines()
|
||||
proc2.communicate()
|
||||
|
||||
if proc1.returncode > 0:
|
||||
for line1 in output1:
|
||||
print(line1.strip())
|
||||
return
|
||||
elif proc2.returncode > 0:
|
||||
for line2 in output2:
|
||||
print(line2.strip())
|
||||
return
|
||||
else:
|
||||
for (line1, line2) in zip(output1, output2):
|
||||
pciDict.clear()
|
||||
match1 = re.search(p1, line1.strip())
|
||||
match2 = re.search(p2, line2.strip())
|
||||
if match1 and match2:
|
||||
Bus = match1.group(1)
|
||||
Dev = match1.group(2)
|
||||
Fn = match1.group(3)
|
||||
Name = match1.group(4)
|
||||
Id = match2.group(1)
|
||||
pciDict["name"] = Name
|
||||
pciDict["bus"] = Bus
|
||||
pciDict["dev"] = Dev
|
||||
pciDict["fn"] = Fn
|
||||
pciDict["id"] = Id
|
||||
pciList.append(pciDict)
|
||||
pciDict = deepcopy(pciDict)
|
||||
else:
|
||||
print("CAN NOT MATCH PCIe DEVICE")
|
||||
return pciList
|
||||
|
||||
# check the sysfs tree for each PCIe device
|
||||
def check_pcie_sysfs(self, domain=0, bus=0, device=0, func=0):
|
||||
dev_path = os.path.join('/sys/bus/pci/devices', '%04x:%02x:%02x.%d' % (domain, bus, device, func))
|
||||
if os.path.exists(dev_path):
|
||||
return True
|
||||
return False
|
||||
|
||||
# check the current PCIe device with config file and return the result
|
||||
def get_pcie_check(self):
|
||||
self.load_config_file()
|
||||
for item_conf in self.confInfo:
|
||||
bus_conf = item_conf["bus"]
|
||||
dev_conf = item_conf["dev"]
|
||||
fn_conf = item_conf["fn"]
|
||||
if self.check_pcie_sysfs(bus=int(bus_conf, base=16), device=int(dev_conf, base=16), func=int(fn_conf, base=16)):
|
||||
item_conf["result"] = "Passed"
|
||||
else:
|
||||
item_conf["result"] = "Failed"
|
||||
return self.confInfo
|
||||
|
||||
# generate the config file with current pci device
|
||||
def dump_conf_yaml(self):
|
||||
curInfo = self.get_pcie_device()
|
||||
with open(self.config_path + "/" + "pcie.yaml", "w") as conf_file:
|
||||
yaml.dump(curInfo, conf_file, default_flow_style=False)
|
||||
return
|
||||
|
@ -0,0 +1,4 @@
|
||||
# All the derived classes for PDDF
|
||||
__all__ = ["platform", "chassis", "sfp", "psu", "thermal", "fan"]
|
||||
from . import platform
|
||||
|
@ -0,0 +1,135 @@
|
||||
#############################################################################
|
||||
# PDDF
|
||||
# Module contains an implementation of SONiC Chassis API
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
try:
|
||||
import time
|
||||
import subprocess
|
||||
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
|
||||
from rgutil.logutil import Logger
|
||||
except ImportError as e:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
PORT_START = 0
|
||||
PORT_END = 55
|
||||
PORTS_IN_BLOCK = 56
|
||||
|
||||
logger = Logger("CHASSIS", syslog=True)
|
||||
|
||||
class Chassis(PddfChassis):
|
||||
"""
|
||||
PDDF Platform-specific Chassis class
|
||||
"""
|
||||
|
||||
SFP_STATUS_INSERTED = "1"
|
||||
SFP_STATUS_REMOVED = "0"
|
||||
port_dict = {}
|
||||
|
||||
def __init__(self, pddf_data=None, pddf_plugin_data=None):
|
||||
PddfChassis.__init__(self, pddf_data, pddf_plugin_data)
|
||||
|
||||
self.enable_read = "i2cset -f -y 2 0x35 0x2a 0x01"
|
||||
self.disable_read = "i2cset -f -y 2 0x35 0x2a 0x00"
|
||||
self.enable_write = "i2cset -f -y 2 0x35 0x2b 0x00"
|
||||
self.disable_write = "i2cset -f -y 2 0x35 0x2b 0x01"
|
||||
self.enable_erase = "i2cset -f -y 2 0x35 0x2c 0x01"
|
||||
self.disable_erase = "i2cset -f -y 2 0x35 0x2c 0x00"
|
||||
self.read_value = "i2cget -f -y 2 0x35 0x25"
|
||||
self.write_value = "i2cset -f -y 2 0x35 0x21 0x0a"
|
||||
|
||||
def get_reboot_cause(self):
|
||||
"""
|
||||
Retrieves the cause of the previous reboot
|
||||
Returns:
|
||||
A tuple (string, string) where the first element is a string
|
||||
containing the cause of the previous reboot. This string must be
|
||||
one of the predefined strings in this class. If the first string
|
||||
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
|
||||
to pass a description of the reboot cause.
|
||||
"""
|
||||
try:
|
||||
is_power_loss = False
|
||||
# enable read
|
||||
subprocess.getstatusoutput(self.disable_write)
|
||||
subprocess.getstatusoutput(self.enable_read)
|
||||
ret, log = subprocess.getstatusoutput(self.read_value)
|
||||
if ret == 0 and "0x0a" in log:
|
||||
is_power_loss = True
|
||||
|
||||
# erase i2c and e2
|
||||
subprocess.getstatusoutput(self.enable_erase)
|
||||
time.sleep(1)
|
||||
subprocess.getstatusoutput(self.disable_erase)
|
||||
# clear data
|
||||
subprocess.getstatusoutput(self.enable_write)
|
||||
subprocess.getstatusoutput(self.disable_read)
|
||||
subprocess.getstatusoutput(self.disable_write)
|
||||
subprocess.getstatusoutput(self.enable_read)
|
||||
# enable write and set data
|
||||
subprocess.getstatusoutput(self.enable_write)
|
||||
subprocess.getstatusoutput(self.disable_read)
|
||||
subprocess.getstatusoutput(self.write_value)
|
||||
if is_power_loss:
|
||||
return(self.REBOOT_CAUSE_POWER_LOSS, None)
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
|
||||
return (self.REBOOT_CAUSE_NON_HARDWARE, None)
|
||||
|
||||
def get_change_event(self, timeout=0):
|
||||
change_event_dict = {"fan": {}, "sfp": {}}
|
||||
sfp_status, sfp_change_dict = self.get_transceiver_change_event(timeout)
|
||||
change_event_dict["sfp"] = sfp_change_dict
|
||||
if sfp_status is True:
|
||||
return True, change_event_dict
|
||||
|
||||
return False, {}
|
||||
|
||||
def get_transceiver_change_event(self, timeout=0):
|
||||
start_time = time.time()
|
||||
currernt_port_dict = {}
|
||||
forever = False
|
||||
|
||||
if timeout == 0:
|
||||
forever = True
|
||||
elif timeout > 0:
|
||||
timeout = timeout / float(1000) # Convert to secs
|
||||
else:
|
||||
print("get_transceiver_change_event:Invalid timeout value", timeout)
|
||||
return False, {}
|
||||
|
||||
end_time = start_time + timeout
|
||||
if start_time > end_time:
|
||||
print(
|
||||
"get_transceiver_change_event:" "time wrap / invalid timeout value",
|
||||
timeout,
|
||||
)
|
||||
return False, {} # Time wrap or possibly incorrect timeout
|
||||
|
||||
while timeout >= 0:
|
||||
# Check for OIR events and return updated port_dict
|
||||
for index in range(PORT_START, PORTS_IN_BLOCK):
|
||||
if self._sfp_list[index].get_presence():
|
||||
currernt_port_dict[index] = self.SFP_STATUS_INSERTED
|
||||
else:
|
||||
currernt_port_dict[index] = self.SFP_STATUS_REMOVED
|
||||
if currernt_port_dict == self.port_dict:
|
||||
if forever:
|
||||
time.sleep(1)
|
||||
else:
|
||||
timeout = end_time - time.time()
|
||||
if timeout >= 1:
|
||||
time.sleep(1) # We poll at 1 second granularity
|
||||
else:
|
||||
if timeout > 0:
|
||||
time.sleep(timeout)
|
||||
return True, {}
|
||||
else:
|
||||
# Update reg value
|
||||
self.port_dict = currernt_port_dict
|
||||
print(self.port_dict)
|
||||
return True, self.port_dict
|
||||
print("get_transceiver_change_event: Should not reach here.")
|
||||
return False, {}
|
@ -0,0 +1,44 @@
|
||||
import os
|
||||
import yaml
|
||||
|
||||
from sonic_py_common import device_info
|
||||
|
||||
|
||||
class Common:
|
||||
|
||||
DEVICE_PATH = '/usr/share/sonic/device/'
|
||||
PMON_PLATFORM_PATH = '/usr/share/sonic/platform/'
|
||||
CONFIG_DIR = 'sonic_platform_config'
|
||||
|
||||
HOST_CHK_CMD = "docker > /dev/null 2>&1"
|
||||
|
||||
def __init__(self):
|
||||
(self.platform, self.hwsku) = device_info.get_platform_and_hwsku()
|
||||
|
||||
def is_host(self):
|
||||
return os.system(self.HOST_CHK_CMD) == 0
|
||||
|
||||
def load_json_file(self, path):
|
||||
"""
|
||||
Retrieves the json object from json file path
|
||||
|
||||
Returns:
|
||||
A json object
|
||||
"""
|
||||
with open(path, 'r') as f:
|
||||
json_data = yaml.safe_load(f)
|
||||
|
||||
return json_data
|
||||
|
||||
def get_config_path(self, config_name):
|
||||
"""
|
||||
Retrieves the path to platform api config directory
|
||||
|
||||
Args:
|
||||
config_name: A string containing the name of config file.
|
||||
|
||||
Returns:
|
||||
A string containing the path to json file
|
||||
"""
|
||||
return os.path.join(self.DEVICE_PATH, self.platform, self.CONFIG_DIR, config_name) if self.is_host() else os.path.join(self.PMON_PLATFORM_PATH, self.CONFIG_DIR, config_name)
|
||||
|
@ -0,0 +1,85 @@
|
||||
########################################################################
|
||||
# Ragile RA-B6510-48v8c
|
||||
#
|
||||
# Module contains an implementation of SONiC Platform Base API and
|
||||
# provides the Components' (e.g., BIOS, CPLD, FPGA, etc.) available in
|
||||
# the platform
|
||||
#
|
||||
########################################################################
|
||||
|
||||
try:
|
||||
import subprocess
|
||||
from sonic_platform_base.component_base import ComponentBase
|
||||
from sonic_platform.regutil import Reg
|
||||
from sonic_platform.logger import logger
|
||||
except ImportError as e:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
|
||||
class Component(ComponentBase):
|
||||
""" Ragile Platform-specific Component class"""
|
||||
|
||||
def __init__(self, index, config=None):
|
||||
self.index = index
|
||||
self.name = config.get("name")
|
||||
self._reg_fm_ver = Reg(config.get("firmware_version"))
|
||||
self.description = config.get("desc")
|
||||
self.slot = config.get("slot")
|
||||
|
||||
def get_name(self):
|
||||
"""
|
||||
Retrieves the name of the component
|
||||
|
||||
Returns:
|
||||
A string containing the name of the component
|
||||
"""
|
||||
return self.name
|
||||
|
||||
def get_description(self):
|
||||
"""
|
||||
Retrieves the description of the component
|
||||
|
||||
Returns:
|
||||
A string containing the description of the component
|
||||
"""
|
||||
return self.description
|
||||
|
||||
def get_firmware_version(self):
|
||||
"""
|
||||
Retrieves the firmware version of the component
|
||||
|
||||
Returns:
|
||||
A string containing the firmware version of the component
|
||||
"""
|
||||
try:
|
||||
return self._reg_fm_ver.decode()
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
|
||||
return ""
|
||||
|
||||
def install_firmware(self, image_path):
|
||||
"""
|
||||
Installs firmware to the component
|
||||
|
||||
Args:
|
||||
image_path: A string, path to firmware image
|
||||
|
||||
Returns:
|
||||
A boolean, True if install was successful, False if not
|
||||
"""
|
||||
try:
|
||||
successtips = "CPLD Upgrade succeeded!"
|
||||
status, output = subprocess.getstatusoutput("which firmware_upgrade")
|
||||
if status or len(output) <= 0:
|
||||
logger.error("no upgrade tool.")
|
||||
return False
|
||||
cmdstr = "%s %s cpld %d cpld"%(output,image_path,self.slot)
|
||||
ret, log = subprocess.getstatusoutput(cmdstr)
|
||||
if ret == 0 and successtips in log:
|
||||
return True
|
||||
logger.error("upgrade failed. ret:%d, log:\n%s" % (ret, log))
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
return False
|
||||
|
@ -0,0 +1,558 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
PSU_FAN_AIRFLOW = {
|
||||
"CSU550AP-3-300": "F2B",
|
||||
"AS-40FAN-01-F-RJ": "F2B",
|
||||
"CSU550AP-3-500": "F2B",
|
||||
"DPS-550AB-39 A": "F2B",
|
||||
"DPS-1300AB-6 S": "F2B",
|
||||
"FSP1200-20ERM": "F2B",
|
||||
"CSU800AP-3-300": "F2B",
|
||||
"CSU550AP-3-501": "B2F",
|
||||
"DPS-550AB-40 A": "B2F",
|
||||
}
|
||||
|
||||
FAN_AIRFLOW = {
|
||||
"AS-80FAN-01-F-RJ": "F2B",
|
||||
"AS-40FAN-01-F-RJ": "F2B",
|
||||
"AS-80FAN-01-R-RJ": "B2F",
|
||||
"AS-40FAN-01-R-RJ": "B2F",
|
||||
}
|
||||
|
||||
psutypedecode = {
|
||||
0x00: "N/A",
|
||||
0x01: "AC",
|
||||
0x02: "DC",
|
||||
}
|
||||
|
||||
|
||||
class Unit:
|
||||
Temperature = "C"
|
||||
Voltage = "V"
|
||||
Current = "A"
|
||||
Power = "W"
|
||||
Speed = "RPM"
|
||||
|
||||
|
||||
class Threshold:
|
||||
PSU_TEMP_MIN = -10 * 1000
|
||||
PSU_TEMP_MAX = 60 * 1000
|
||||
|
||||
PSU_FAN_SPEED_MIN = 2000
|
||||
PSU_FAN_SPEED_MAX = 28000
|
||||
|
||||
PSU_OUTPUT_VOLTAGE_MIN = 11 * 1000
|
||||
PSU_OUTPUT_VOLTAGE_MAX = 14 * 1000
|
||||
|
||||
PSU_AC_INPUT_VOLTAGE_MIN = 200 * 1000
|
||||
PSU_AC_INPUT_VOLTAGE_MAX = 240 * 1000
|
||||
|
||||
PSU_DC_INPUT_VOLTAGE_MIN = 190 * 1000
|
||||
PSU_DC_INPUT_VOLTAGE_MAX = 290 * 1000
|
||||
|
||||
ERR_VALUE = -9999999
|
||||
|
||||
PSU_OUTPUT_POWER_MIN = 10 * 1000
|
||||
PSU_OUTPUT_POWER_MAX = 1300 * 1000
|
||||
|
||||
PSU_INPUT_POWER_MIN = 10 * 1000
|
||||
PSU_INPUT_POWER_MAX = 1444 * 1000
|
||||
|
||||
PSU_OUTPUT_CURRENT_MIN = 2 * 1000
|
||||
PSU_OUTPUT_CURRENT_MAX = 107 * 1000
|
||||
|
||||
PSU_INPUT_CURRENT_MIN = 0.2 * 1000
|
||||
PSU_INPUT_CURRENT_MAX = 7 * 1000
|
||||
|
||||
FAN_SPEED_MAX = 23000
|
||||
FAN_SPEED_MIN = 500
|
||||
|
||||
|
||||
class DecodeFormat:
|
||||
TEXT = 0
|
||||
DECIMAL = 1
|
||||
ONE_BIT_HEX = 2
|
||||
HUNDREDTH = 3
|
||||
THOUSANDTH = 4
|
||||
MILLIONTH = 5
|
||||
AND = 6
|
||||
JOIN = 7
|
||||
|
||||
|
||||
class DecodeMethod:
|
||||
SYSFS = 0
|
||||
I2C = 1
|
||||
I2C_WORD = 2
|
||||
DEVMEM = 3
|
||||
SDK = 4
|
||||
|
||||
|
||||
class Description:
|
||||
CPLD = "Used for managing IO modules, SFP+ modules and system LEDs"
|
||||
BIOS = "Performs initialization of hardware components during booting"
|
||||
FPGA = "Platform management controller for on-board temperature monitoring, in-chassis power, Fan and LED control"
|
||||
|
||||
|
||||
FAN_LED_COLORS = {
|
||||
"green": 0b1001,
|
||||
"red": 0b1010,
|
||||
"amber": 0b0011,
|
||||
}
|
||||
|
||||
|
||||
DEVICE_CONF = {
|
||||
"eeprom": {"bus": 2, "loc": "0057"},
|
||||
"components": [
|
||||
{
|
||||
"name": "CPLD1 (MAC Board A)",
|
||||
"firmware_version": {
|
||||
"bus": 2,
|
||||
"addr": 0x33,
|
||||
"offset": 0,
|
||||
"size": 4,
|
||||
"way": DecodeMethod.I2C,
|
||||
"format": DecodeFormat.JOIN,
|
||||
"sep": "/",
|
||||
},
|
||||
"desc": Description.CPLD,
|
||||
"slot": 0,
|
||||
},
|
||||
{
|
||||
"name": "CPLD2 (MAC Board B)",
|
||||
"firmware_version": {
|
||||
"bus": 2,
|
||||
"addr": 0x35,
|
||||
"offset": 0,
|
||||
"size": 4,
|
||||
"way": DecodeMethod.I2C,
|
||||
"format": DecodeFormat.JOIN,
|
||||
"sep": "/",
|
||||
},
|
||||
"desc": Description.CPLD,
|
||||
"slot": 0,
|
||||
},
|
||||
{
|
||||
"name": "CPLD3 (CONNECT Board A)",
|
||||
"firmware_version": {
|
||||
"bus": 2,
|
||||
"addr": 0x37,
|
||||
"offset": 0,
|
||||
"size": 4,
|
||||
"way": DecodeMethod.I2C,
|
||||
"format": DecodeFormat.JOIN,
|
||||
"sep": "/",
|
||||
},
|
||||
"desc": Description.CPLD,
|
||||
"slot": 0,
|
||||
},
|
||||
{
|
||||
"name": "CPLD4 (CPU Board)",
|
||||
"firmware_version": {
|
||||
"bus": 0,
|
||||
"addr": 0x0D,
|
||||
"offset": 0,
|
||||
"size": 4,
|
||||
"way": DecodeMethod.I2C,
|
||||
"format": DecodeFormat.JOIN,
|
||||
"sep": "/",
|
||||
},
|
||||
"desc": Description.CPLD,
|
||||
"slot": 1,
|
||||
},
|
||||
],
|
||||
"thermals": [
|
||||
{
|
||||
"name": "INLET TEMP",
|
||||
"high": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0048/hwmon/*/temp1_max",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"low": None,
|
||||
"crit_low": None,
|
||||
"crit_high": None,
|
||||
"temperature": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0048/hwmon/*/temp1_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "OUTLET TEMP",
|
||||
"high": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0049/hwmon/*/temp1_max",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"low": None,
|
||||
"crit_low": None,
|
||||
"crit_high": None,
|
||||
"temperature": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0049/hwmon/*/temp1_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "BOARD TEMP",
|
||||
"high": {
|
||||
"loc": "/sys/bus/i2c/devices/2-004a/hwmon/*/temp1_max",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"low": None,
|
||||
"crit_low": None,
|
||||
"crit_high": None,
|
||||
"temperature": {
|
||||
"loc": "/sys/bus/i2c/devices/2-004a/hwmon/*/temp1_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "PHYSICAL ID 0",
|
||||
"high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp1_max",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"low": None,
|
||||
"crit_low": None,
|
||||
"crit_high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp1_crit",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp1_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "CPU CORE 0",
|
||||
"high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp2_max",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"low": None,
|
||||
"crit_low": None,
|
||||
"crit_high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp2_crit",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp2_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "CPU CORE 1",
|
||||
"high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp3_max",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"low": None,
|
||||
"crit_low": None,
|
||||
"crit_high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp3_crit",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp3_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "CPU CORE 2",
|
||||
"high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp4_max",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"low": None,
|
||||
"crit_low": None,
|
||||
"crit_high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp4_crit",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp4_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "CPU CORE 3",
|
||||
"high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp5_max",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"low": None,
|
||||
"crit_low": None,
|
||||
"crit_high": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp5_crit",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/class/hwmon/hwmon0/temp5_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
},
|
||||
],
|
||||
"fans": [
|
||||
{
|
||||
"name": "fan1",
|
||||
"e2loc": {"bus": 3, "addr": 0x53, "way": "i2c", "size": "256"},
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_present",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 0,
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_status",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 0,
|
||||
},
|
||||
"hw_version": {"loc": "/sys/bus/i2c/devices/3-0053/fan_hw_version"},
|
||||
"sn": {"loc": "/sys/bus/i2c/devices/3-0053/fan_sn"},
|
||||
"led": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan0_led",
|
||||
"format": DecodeFormat.AND,
|
||||
"mask": 0b1011,
|
||||
},
|
||||
"led_colors": FAN_LED_COLORS,
|
||||
"rotors": [
|
||||
{
|
||||
"speed_getter": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/hwmon/*/fan1_input"
|
||||
},
|
||||
"speed_setter": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan_speed_set"
|
||||
},
|
||||
"speed_max": Threshold.FAN_SPEED_MAX,
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "fan2",
|
||||
"e2loc": {"bus": 4, "addr": 0x53, "way": "i2c", "size": "256"},
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_present",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 1,
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_status",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 1,
|
||||
},
|
||||
"hw_version": {"loc": "/sys/bus/i2c/devices/4-0053/fan_hw_version"},
|
||||
"sn": {"loc": "/sys/bus/i2c/devices/4-0053/fan_sn"},
|
||||
"led": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan1_led",
|
||||
"format": DecodeFormat.AND,
|
||||
"mask": 0b1011,
|
||||
},
|
||||
"led_colors": FAN_LED_COLORS,
|
||||
"rotors": [
|
||||
{
|
||||
"speed_getter": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/hwmon/*/fan2_input"
|
||||
},
|
||||
"speed_setter": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan_speed_set"
|
||||
},
|
||||
"speed_max": Threshold.FAN_SPEED_MAX,
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "fan3",
|
||||
"e2loc": {"bus": 3, "addr": 0x53, "way": "i2c", "size": "256"},
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_present",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 2,
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_status",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 2,
|
||||
},
|
||||
"hw_version": {"loc": "/sys/bus/i2c/devices/5-0053/fan_hw_version"},
|
||||
"sn": {"loc": "/sys/bus/i2c/devices/5-0053/fan_sn"},
|
||||
"led": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan2_led",
|
||||
"format": DecodeFormat.AND,
|
||||
"mask": 0b1011,
|
||||
},
|
||||
"led_colors": FAN_LED_COLORS,
|
||||
"rotors": [
|
||||
{
|
||||
"speed_getter": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/hwmon/*/fan3_input"
|
||||
},
|
||||
"speed_setter": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan_speed_set"
|
||||
},
|
||||
"speed_max": Threshold.FAN_SPEED_MAX,
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "fan4",
|
||||
"e2loc": {"bus": 3, "addr": 0x53, "way": "i2c", "size": "256"},
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_present",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 3,
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/fan_status",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 3,
|
||||
},
|
||||
"hw_version": {"loc": "/sys/bus/i2c/devices/6-0053/fan_hw_version"},
|
||||
"sn": {"loc": "/sys/bus/i2c/devices/6-0053/fan_sn"},
|
||||
"led": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan3_led",
|
||||
"format": DecodeFormat.AND,
|
||||
"mask": 0b1011,
|
||||
},
|
||||
"led_colors": FAN_LED_COLORS,
|
||||
"rotors": [
|
||||
{
|
||||
"speed_getter": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/hwmon/*/fan4_input"
|
||||
},
|
||||
"speed_setter": {
|
||||
"loc": "/sys/bus/i2c/devices/0-0032/fan_speed_set"
|
||||
},
|
||||
"speed_max": Threshold.FAN_SPEED_MAX,
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
"psus": [
|
||||
{
|
||||
"name": "psu1",
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 0,
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 1,
|
||||
},
|
||||
"sn": {"loc": "/sys/bus/i2c/devices/7-0050/psu_sn"},
|
||||
"in_current": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/curr1_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"in_voltage": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/in1_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"out_voltage": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/in2_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"out_current": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/curr2_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/temp1_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"hw_version": {"loc": "/sys/bus/i2c/devices/7-0050/psu_hw"},
|
||||
"psu_type": {"loc": "/sys/bus/i2c/devices/7-0050/psu_type"},
|
||||
"fans": [
|
||||
{
|
||||
"name": "psu_fan1",
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/fan1_fault",
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 1,
|
||||
},
|
||||
"rotors": [
|
||||
{
|
||||
"speed_getter": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/fan1_input"
|
||||
},
|
||||
"speed_max": Threshold.PSU_FAN_SPEED_MAX,
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
"in_power": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/power1_input",
|
||||
"format": DecodeFormat.MILLIONTH,
|
||||
},
|
||||
"out_power": {
|
||||
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/power2_input",
|
||||
"format": DecodeFormat.MILLIONTH,
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "psu2",
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 4,
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 5,
|
||||
},
|
||||
"sn": {"loc": "/sys/bus/i2c/devices/8-0053/psu_sn"},
|
||||
"in_current": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/curr1_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"in_voltage": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/in1_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"out_voltage": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/in2_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"out_current": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/curr2_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"temperature": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/temp1_input",
|
||||
"format": DecodeFormat.THOUSANDTH,
|
||||
},
|
||||
"hw_version": {"loc": "/sys/bus/i2c/devices/8-0053/psu_hw"},
|
||||
"psu_type": {"loc": "/sys/bus/i2c/devices/8-0053/psu_type"},
|
||||
"fans": [
|
||||
{
|
||||
"name": "psu_fan1",
|
||||
"present": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/fan1_fault",
|
||||
},
|
||||
"status": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
|
||||
"format": DecodeFormat.ONE_BIT_HEX,
|
||||
"bit": 5,
|
||||
},
|
||||
"rotors": [
|
||||
{
|
||||
"speed_getter": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/fan1_input"
|
||||
},
|
||||
"speed_max": Threshold.PSU_FAN_SPEED_MAX,
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
"in_power": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/power1_input",
|
||||
"format": DecodeFormat.MILLIONTH,
|
||||
},
|
||||
"out_power": {
|
||||
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/power2_input",
|
||||
"format": DecodeFormat.MILLIONTH,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
try:
|
||||
from sonic_platform_pddf_base.pddf_eeprom import PddfEeprom
|
||||
except ImportError as e:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
|
||||
class Eeprom(PddfEeprom):
|
||||
|
||||
def __init__(self, pddf_data=None, pddf_plugin_data=None):
|
||||
PddfEeprom.__init__(self, pddf_data, pddf_plugin_data)
|
||||
|
||||
# Provide the functions/variables below for which implementation is to be overwritten
|
@ -0,0 +1,36 @@
|
||||
try:
|
||||
from sonic_platform_pddf_base.pddf_fan import PddfFan
|
||||
except ImportError as e:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
|
||||
class Fan(PddfFan):
|
||||
"""PDDF Platform-Specific Fan class"""
|
||||
|
||||
def __init__(self, tray_idx, fan_idx=0, pddf_data=None, pddf_plugin_data=None, is_psu_fan=False, psu_index=0):
|
||||
# idx is 0-based
|
||||
PddfFan.__init__(self, tray_idx, fan_idx, pddf_data, pddf_plugin_data, is_psu_fan, psu_index)
|
||||
|
||||
# Provide the functions/variables below for which implementation is to be overwritten
|
||||
# Since psu_fan airflow direction cant be read from sysfs, it is fixed as 'F2B' or 'intake'
|
||||
def get_direction(self):
|
||||
"""
|
||||
Retrieves the direction of fan
|
||||
|
||||
Returns:
|
||||
A string, either FAN_DIRECTION_INTAKE or FAN_DIRECTION_EXHAUST
|
||||
depending on fan direction
|
||||
"""
|
||||
return self.FAN_DIRECTION_EXHAUST
|
||||
|
||||
def get_speed_rpm(self):
|
||||
if self.is_psu_fan:
|
||||
return super().get_speed_rpm()
|
||||
else:
|
||||
divisor = 15000000
|
||||
mask_low = 0xff
|
||||
ret = super().get_speed_rpm()
|
||||
# revert ret
|
||||
ret = (ret >> 8) + ((ret & mask_low) << 8)
|
||||
return int(divisor/ret)
|
||||
|
@ -0,0 +1,71 @@
|
||||
#
|
||||
# fan_drawer_base.py
|
||||
#
|
||||
# Abstract base class for implementing a platform-specific class with which
|
||||
# to interact with a fan drawer module in SONiC
|
||||
#
|
||||
|
||||
try:
|
||||
from sonic_platform_base.fan_drawer_base import FanDrawerBase
|
||||
except ImportError as e:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
|
||||
class FanDrawer(FanDrawerBase):
|
||||
"""
|
||||
Abstract base class for interfacing with a fan drawer
|
||||
"""
|
||||
# Device type definition. Note, this is a constant.
|
||||
DEVICE_TYPE = "fan_drawer"
|
||||
|
||||
def __init__(self, index, fan_list):
|
||||
FanDrawerBase.__init__(self)
|
||||
|
||||
self._fan_list = fan_list
|
||||
self._index = index
|
||||
|
||||
def get_name(self):
|
||||
"""
|
||||
Retrieves the name of the device
|
||||
Returns:
|
||||
string: The name of the device
|
||||
"""
|
||||
|
||||
return "fan {}".format(self._index)
|
||||
|
||||
def get_num_fans(self):
|
||||
"""
|
||||
Retrieves the number of fans available on this fan drawer
|
||||
Returns:
|
||||
An integer, the number of fan modules available on this fan drawer
|
||||
"""
|
||||
return len(self._fan_list)
|
||||
|
||||
def get_all_fans(self):
|
||||
"""
|
||||
Retrieves all fan modules available on this fan drawer
|
||||
Returns:
|
||||
A list of objects derived from FanBase representing all fan
|
||||
modules available on this fan drawer
|
||||
"""
|
||||
return self._fan_list
|
||||
|
||||
def set_status_led(self, color):
|
||||
"""
|
||||
Sets the state of the fan drawer status LED
|
||||
Args:
|
||||
color: A string representing the color with which to set the
|
||||
fan drawer status LED
|
||||
Returns:
|
||||
bool: True if status LED state is set successfully, False if not
|
||||
"""
|
||||
return self._fan_list[self._index].set_status_led(color)
|
||||
|
||||
def get_status_led(self, color):
|
||||
"""
|
||||
Gets the state of the fan drawer LED
|
||||
Returns:
|
||||
A string, one of the predefined STATUS_LED_COLOR_* strings above
|
||||
"""
|
||||
return self._fan_list[self._index].get_status_led(color)
|
||||
|
@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
def _init_logger():
|
||||
formatter = logging.Formatter(
|
||||
"%(asctime)s %(levelname)s %(filename)s[%(funcName)s][%(lineno)s]: %(message)s"
|
||||
)
|
||||
handler = logging.FileHandler("/var/log/syslog")
|
||||
handler.setFormatter(formatter)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(handler)
|
||||
return logger
|
||||
|
||||
|
||||
logger = _init_logger()
|
@ -0,0 +1,43 @@
|
||||
#
|
||||
# pcie_base.py
|
||||
#
|
||||
# Abstract base class for implementing platform-specific
|
||||
# PCIE functionality for SONiC
|
||||
#
|
||||
|
||||
try:
|
||||
import abc
|
||||
from sonic_pcie import PcieUtil
|
||||
except ImportError as e:
|
||||
raise ImportError (str(e) + " - required module not found")
|
||||
|
||||
class PcieBase(object):
|
||||
def __init__(self, path):
|
||||
"""
|
||||
Constructor
|
||||
Args:
|
||||
pcieutil file and config file path
|
||||
"""
|
||||
self.pcie_util = PcieUtil(path)
|
||||
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_pcie_device(self):
|
||||
"""
|
||||
get current device pcie info
|
||||
|
||||
Returns:
|
||||
A list including pcie device info
|
||||
"""
|
||||
return self.pcie_util.get_pcie_device()
|
||||
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_pcie_check(self):
|
||||
"""
|
||||
Check Pcie device with config file
|
||||
Returns:
|
||||
A list including pcie device and test result info
|
||||
"""
|
||||
return self.pcie_util.get_pcie_check()
|
||||
|
@ -0,0 +1,23 @@
|
||||
#############################################################################
|
||||
# PDDF
|
||||
# Module contains an implementation of SONiC Platform Base API and
|
||||
# provides the platform information
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
|
||||
try:
|
||||
from sonic_platform_pddf_base.pddf_platform import PddfPlatform
|
||||
except ImportError as e:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
|
||||
class Platform(PddfPlatform):
|
||||
"""
|
||||
PDDF Platform-Specific Platform Class
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
PddfPlatform.__init__(self)
|
||||
|
||||
# Provide the functions/variables below for which implementation is to be overwritten
|
@ -0,0 +1,32 @@
|
||||
try:
|
||||
from sonic_platform_pddf_base.pddf_psu import PddfPsu
|
||||
except ImportError as e:
|
||||
raise ImportError (str(e) + "- required module not found")
|
||||
|
||||
|
||||
class Psu(PddfPsu):
|
||||
"""PDDF Platform-Specific PSU class"""
|
||||
|
||||
PLATFORM_PSU_CAPACITY = 1200
|
||||
|
||||
def __init__(self, index, pddf_data=None, pddf_plugin_data=None):
|
||||
PddfPsu.__init__(self, index, pddf_data, pddf_plugin_data)
|
||||
|
||||
# Provide the functions/variables below for which implementation is to be overwritten
|
||||
def get_maximum_supplied_power(self):
|
||||
"""
|
||||
Retrieves the maximum supplied power by PSU (or PSU capacity)
|
||||
Returns:
|
||||
A float number, the maximum power output in Watts.
|
||||
e.g. 1200.1
|
||||
"""
|
||||
return float(self.PLATFORM_PSU_CAPACITY)
|
||||
|
||||
def get_type(self):
|
||||
"""
|
||||
Gets the type of the PSU
|
||||
Returns:
|
||||
A string, the type of PSU (AC/DC)
|
||||
"""
|
||||
return "DC"
|
||||
|
@ -0,0 +1,245 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from glob import glob
|
||||
from plat_hal.osutil import osutil
|
||||
|
||||
try:
|
||||
from sonic_platform.config import DecodeFormat, DecodeMethod
|
||||
|
||||
DECODE_FORMAT = DecodeFormat
|
||||
DECODE_METHOD = DecodeMethod
|
||||
except ImportError:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
ERR_CODE = "ERR"
|
||||
|
||||
|
||||
class Reg(object):
|
||||
"""
|
||||
"e2loc": {"bus": 3, "addr": 0x53, "way": "i2c"}
|
||||
"value": {
|
||||
"loc": "/sys/bus/i2c/devices/2-0048/hwmon/hwmon*/temp1_input",
|
||||
"way": "sysfs",
|
||||
|
||||
"InputsStatus": {
|
||||
"bus": 8,
|
||||
"addr": 0x5B,
|
||||
"offset": 0x79,
|
||||
"way": "i2cword",
|
||||
"mask": 0x0200,
|
||||
},
|
||||
"""
|
||||
|
||||
def __new__(cls, *args):
|
||||
if args[0] is None or not isinstance(args[0], dict):
|
||||
return None
|
||||
return super(Reg, cls).__new__(cls)
|
||||
|
||||
def __init__(self, data):
|
||||
|
||||
self.loc = None
|
||||
self.way = DECODE_METHOD.SYSFS
|
||||
self.addr = None
|
||||
self.bus = None
|
||||
self.offset = None
|
||||
self.size = 1
|
||||
self.bit = None
|
||||
self.mask = None
|
||||
self.digit = None
|
||||
self.sdk_type = None
|
||||
self.sep = None
|
||||
self.format = DECODE_FORMAT.TEXT
|
||||
self.__dict__.update(data)
|
||||
|
||||
def _read_reg_val(self):
|
||||
ret = None
|
||||
try:
|
||||
if self.way == DECODE_METHOD.SYSFS:
|
||||
ret = self.get_sysfs()
|
||||
elif self.way == DECODE_METHOD.I2C:
|
||||
ret = self.get_i2c()
|
||||
elif self.way == DECODE_METHOD.I2C_WORD:
|
||||
ret = self.get_i2cword()
|
||||
elif self.way == DECODE_METHOD.DEVMEM:
|
||||
ret = self.get_devmem()
|
||||
elif self.way == DECODE_METHOD.SDK:
|
||||
# TODO
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
return ret
|
||||
|
||||
def _write_reg_val(self, val):
|
||||
try:
|
||||
if self.way == DECODE_METHOD.SYSFS:
|
||||
return self._write_sysfs(val)
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
return False
|
||||
|
||||
def _write_sysfs(self, val):
|
||||
try:
|
||||
with open(glob(self.loc)[0], "w") as f:
|
||||
f.write(val)
|
||||
f.flush()
|
||||
return True
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
def _format_val(self, val):
|
||||
try:
|
||||
if isinstance(val, str):
|
||||
val = val.strip()
|
||||
if self.format == DECODE_FORMAT.THOUSANDTH:
|
||||
return float("%.1f" % (float(val) / 1000))
|
||||
elif self.format == DECODE_FORMAT.HUNDREDTH:
|
||||
return float("%.1f" % (float(val) / 100))
|
||||
elif self.format == DECODE_FORMAT.ONE_BIT_HEX:
|
||||
return (int(val, 16) & (1 << self.bit)) >> self.bit
|
||||
elif self.format == DECODE_FORMAT.DECIMAL:
|
||||
return int(val, 10)
|
||||
elif self.format == DECODE_FORMAT.MILLIONTH:
|
||||
return float("%.1f" % (float(val) / 1000 / 1000))
|
||||
elif self.format == DECODE_FORMAT.AND:
|
||||
return (int(val, 16)) & self.mask
|
||||
elif isinstance(val, list):
|
||||
if self.format == DECODE_FORMAT.JOIN:
|
||||
return self.sep.join(val)
|
||||
except Exception as e:
|
||||
raise e
|
||||
else:
|
||||
return val
|
||||
|
||||
def decode(self):
|
||||
"""
|
||||
get value by config way
|
||||
way i2c/sysfs/lpc
|
||||
"""
|
||||
if self.way is None:
|
||||
raise ValueError("cannot found way to deal")
|
||||
|
||||
ret = self._read_reg_val()
|
||||
|
||||
ret = self._format_val(ret)
|
||||
return ret
|
||||
|
||||
def encode(self, val):
|
||||
if self.way is None:
|
||||
raise ValueError("cannot found way to deal")
|
||||
|
||||
return self._write_reg_val(val)
|
||||
|
||||
def get_sdk(self):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
def get_sysfs(self):
|
||||
if self.loc is None:
|
||||
raise ValueError("Not Enough Attr: loc: {}".format(self.loc))
|
||||
|
||||
ret, val = osutil.readsysfs(self.loc)
|
||||
|
||||
if not ret:
|
||||
raise IOError(val)
|
||||
|
||||
return val
|
||||
|
||||
def get_devmem(self):
|
||||
if self.addr is None or self.digit is None or self.mask is None:
|
||||
raise ValueError(
|
||||
"Not Enough Attr: addr: {}, digit: {}, mask: {}".format(
|
||||
self.addr, self.digit, self.mask
|
||||
)
|
||||
)
|
||||
|
||||
ret, val = osutil.getdevmem(self.addr, self.digit, self.mask)
|
||||
|
||||
if not ret:
|
||||
raise IOError(val)
|
||||
|
||||
return val
|
||||
|
||||
def get_i2cword(self):
|
||||
if self.bus is None or self.addr is None or self.offset is None:
|
||||
raise ValueError(
|
||||
"Not Enough Attr: bus: {}, addr: {}, offset: {}".format(
|
||||
self.bus, self.addr, self.offset
|
||||
)
|
||||
)
|
||||
|
||||
ret, val = osutil.geti2cword(self.bus, self.addr, self.offset)
|
||||
|
||||
if not ret:
|
||||
raise IOError(val)
|
||||
|
||||
return val
|
||||
|
||||
def get_i2c(self):
|
||||
if (
|
||||
self.bus is None
|
||||
or self.addr is None
|
||||
or self.offset is None
|
||||
or self.size is None
|
||||
):
|
||||
raise ValueError(
|
||||
"Not Enough Attr: bus: {}, addr: {}, offset: {}".format(
|
||||
self.bus, self.addr, self.offset
|
||||
)
|
||||
)
|
||||
|
||||
value = []
|
||||
for i in range(self.size):
|
||||
ofs = self.offset + i
|
||||
ret, val = osutil.rji2cget(self.bus, self.addr, ofs)
|
||||
|
||||
if not ret:
|
||||
raise IOError(val)
|
||||
else:
|
||||
value.append(repr(chr(val)).translate(None, r"\\x").replace("'", ""))
|
||||
|
||||
return value
|
||||
|
||||
def set_i2cword(self, bus, addr, offset, byte):
|
||||
return self.seti2cword(bus, addr, offset, byte)
|
||||
|
||||
def seti2cword(self, bus, addr, offset, byte):
|
||||
return osutil.seti2cword(bus, addr, offset, byte)
|
||||
|
||||
def set_i2c(self, bus, addr, offset, byte):
|
||||
return self.seti2c(bus, addr, offset, byte)
|
||||
|
||||
def seti2c(self, bus, addr, offset, byte):
|
||||
ret, val = osutil.rji2cset(bus, addr, offset, byte)
|
||||
return ret, val
|
||||
|
||||
def getbcmtemp(self):
|
||||
try:
|
||||
sta, ret = osutil.getmactemp()
|
||||
if sta == True:
|
||||
mac_aver = float(ret.get("average", self.__error_ret))
|
||||
#mac_max = float(ret.get("maximum", self.__error_ret))
|
||||
mac_aver = mac_aver * 1000
|
||||
#mac_max = mac_max * 1000
|
||||
else:
|
||||
return False, ret
|
||||
except AttributeError as e:
|
||||
return False, str(e)
|
||||
return True, mac_aver
|
||||
|
||||
def getbcmreg(self, reg):
|
||||
ret, val = osutil.getsdkreg(reg)
|
||||
return ret, val
|
||||
|
||||
def logger_debug(self, msg):
|
||||
baseutil.logger_debug(msg)
|
||||
|
||||
def command(self, cmd):
|
||||
ret, output = osutil.command(cmd)
|
||||
return ret, output
|
||||
|
||||
def set_val(self, val):
|
||||
# TODO
|
||||
pass
|
@ -0,0 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
try:
|
||||
from sonic_platform.regutil import Reg
|
||||
from sonic_platform.logger import logger
|
||||
except ImportError:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
class Rotor:
|
||||
def __init__(self, config):
|
||||
if config is not None and isinstance(config, dict):
|
||||
self.__reg_speed_getter = Reg(config.get("speed_getter"))
|
||||
self.__reg_speed_setter = Reg(config.get("speed_setter"))
|
||||
self.__speed_max = config.get("speed_max")
|
||||
else:
|
||||
raise ValueError("init rotor Error: {}".format(config))
|
||||
|
||||
def get_speed(self):
|
||||
try:
|
||||
return int(self.__reg_speed_getter.decode())
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
|
||||
return 0
|
||||
|
||||
def set_speed(self, speed):
|
||||
try:
|
||||
return self.__reg_speed_setter.encode(speed)
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
|
||||
return False
|
||||
|
||||
def get_speed_percentage(self):
|
||||
try:
|
||||
speed = self.get_speed()
|
||||
return (100 * speed) / self.__speed_max
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
|
||||
return 0
|
@ -0,0 +1,15 @@
|
||||
try:
|
||||
from sonic_platform_pddf_base.pddf_sfp import PddfSfp
|
||||
except ImportError as e:
|
||||
raise ImportError (str(e) + "- required module not found")
|
||||
|
||||
|
||||
class Sfp(PddfSfp):
|
||||
"""
|
||||
PDDF Platform-Specific Sfp class
|
||||
"""
|
||||
|
||||
def __init__(self, index, pddf_data=None, pddf_plugin_data=None):
|
||||
PddfSfp.__init__(self, index, pddf_data, pddf_plugin_data)
|
||||
|
||||
# Provide the functions/variables below for which implementation is to be overwritten
|
@ -0,0 +1,14 @@
|
||||
try:
|
||||
from sonic_platform_pddf_base.pddf_thermal import PddfThermal
|
||||
except ImportError as e:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
|
||||
|
||||
class Thermal(PddfThermal):
|
||||
"""PDDF Platform-Specific Thermal class"""
|
||||
|
||||
def __init__(self, index, pddf_data=None, pddf_plugin_data=None):
|
||||
PddfThermal.__init__(self, index, pddf_data, pddf_plugin_data)
|
||||
|
||||
# Provide the functions/variables below for which implementation is to be overwritten
|
@ -0,0 +1,21 @@
|
||||
#############################################################################
|
||||
#
|
||||
# Module contains an implementation of platform specific watchdog API's
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
try:
|
||||
from sonic_platform_pddf_base.pddf_watchdog import PddfWatchdog
|
||||
except ImportError as e:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
class Watchdog(PddfWatchdog):
|
||||
"""
|
||||
PDDF Platform-specific Chassis class
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
PddfWatchdog.__init__(self)
|
||||
self.timeout= 180
|
||||
|
||||
# Provide the functions/variables below for which implementation is to be overwritten
|
@ -0,0 +1 @@
|
||||
../../../../pddf/i2c/service/pddf-platform-init.service
|
Loading…
Reference in New Issue
Block a user