diff --git a/device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/port_config.ini b/device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/port_config.ini new file mode 100755 index 000000000000..fd2022dc2c9d --- /dev/null +++ b/device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/port_config.ini @@ -0,0 +1,33 @@ +# name lanes alias +Ethernet0 49,50,51,52 fortyGigE1 +Ethernet4 53,54,55,56 fortyGigE2 +Ethernet8 57,58,59,60 fortyGigE3 +Ethernet12 61,62,63,64 fortyGigE4 +Ethernet16 65,66,67,68 fortyGigE5 +Ethernet20 69,70,71,72 fortyGigE6 +Ethernet24 73,74,75,76 fortyGigE7 +Ethernet28 77,78,79,80 fortyGigE8 +Ethernet32 33,34,35,36 fortyGigE9 +Ethernet36 37,38,39,40 fortyGigE10 +Ethernet40 41,42,43,44 fortyGigE11 +Ethernet44 45,46,47,48 fortyGigE12 +Ethernet48 81,82,83,84 fortyGigE13 +Ethernet52 85,86,87,88 fortyGigE14 +Ethernet56 89,90,91,92 fortyGigE15 +Ethernet60 93,94,95,96 fortyGigE16 +Ethernet64 97,98,99,100 fortyGigE17 +Ethernet68 101,102,103,104 fortyGigE18 +Ethernet72 105,106,107,108 fortyGigE19 +Ethernet76 109,110,111,112 fortyGigE20 +Ethernet80 17,18,19,20 fortyGigE21 +Ethernet84 21,22,23,24 fortyGigE22 +Ethernet88 25,26,27,28 fortyGigE23 +Ethernet92 29,30,31,32 fortyGigE24 +Ethernet96 113,114,115,116 fortyGigE25 +Ethernet100 117,118,119,120 fortyGigE26 +Ethernet104 121,122,123,124 fortyGigE27 +Ethernet108 125,126,127,128 fortyGigE28 +Ethernet112 1,2,3,4 fortyGigE29 +Ethernet116 5,6,7,8 fortyGigE30 +Ethernet120 9,10,11,12 fortyGigE31 +Ethernet124 13,14,15,16 fortyGigE32 diff --git a/device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/sai.profile b/device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/sai.profile new file mode 100755 index 000000000000..22432e548b4a --- /dev/null +++ b/device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/sai.profile @@ -0,0 +1 @@ +SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/td2-as6712-32x40G.config.bcm diff --git a/device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/td2-as6712-32x40G.config.bcm b/device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/td2-as6712-32x40G.config.bcm new file mode 100755 index 000000000000..a56dba8c5af0 --- /dev/null +++ b/device/accton/x86_64-accton_as6712_32x-r0/Accton-AS6712-32X/td2-as6712-32x40G.config.bcm @@ -0,0 +1,133 @@ +os=unix +bcm_stat_flags=0 +parity_enable=0 +parity_correction=0 + +l2_mem_entries=163840 +l3_mem_entries=81920 +mmu_lossless=0 +lls_num_l2uc=12 +module_64ports=0 + +#SFI +serdes_if_type=9 + +port_init_cl72=0 +phy_an_c73=5 # TSCMOD_CL73_CL37 + +#sdk6.5.5 only supports 156(default) or 125 +#xgxs_lcpll_xtal_refclk=1 +tslam_dma_enable=1 +table_dma_enable=1 + +#for 32x40G ports for breakout mode +pbmp_oversubscribe=0x1fffffffe +pbmp_xport_xe=0x1fffffffe + +rate_ext_mdio_divisor=96 + +#QSFP+ 1 from WC0 +portmap_1=1:40 + +#QSFP+ 2 from WC1 +portmap_2=5:40 + +#QSFP+ 3 from WC2 +portmap_3=9:40 + +#QSFP+ 4 from WC3 +portmap_4=13:40 + +#QSFP+ 5 from WC4 +portmap_5=17:40 + +#QSFP+ 6 from WC5 +portmap_6=21:40 + +#QSFP+ 7 from WC6 +portmap_7=25:40 + +#QSFP+ 8 from WC7 +portmap_8=29:40 + +#QSFP+ 9 from WC8 +portmap_9=33:40 + +#QSFP+ 10 from WC9 +portmap_10=37:40 + +#QSFP+ 11 from WC10 +portmap_11=41:40 + +#QSFP+ 12 from WC11 +portmap_12=45:40 + +#QSFP+ 13 from WC12 +portmap_13=49:40 + +#QSFP+ 14 from WC13 +portmap_14=53:40 + +#QSFP+ 15 from WC14 +portmap_15=57:40 + +#QSFP+ 16 from WC15 +portmap_16=61:40 + +#QSFP+ 17 from WC16 +portmap_17=65:40 + +#QSFP+ 18 from WC17 +portmap_18=69:40 + +#QSFP+ 19 from WC18 +portmap_19=73:40 + +#QSFP+ 20 from WC19 +portmap_20=77:40 + +#QSFP+ 21 from WC20 +portmap_21=81:40 + +#QSFP+ 22 from WC21 +portmap_22=85:40 + +#QSFP+ 23 from WC22 +portmap_23=89:40 + +#QSFP+ 24 from WC23 +portmap_24=93:40 + +#QSFP+ 25 from WC24 +portmap_25=97:40 + +#QSFP+ 26 from WC25 +portmap_26=101:40 + +#QSFP+ 27 from WC26 +portmap_27=105:40 + +#QSFP+ 28 from WC27 +portmap_28=109:40 + +#QSFP+ 29 from WC28 +portmap_29=113:40 + +#QSFP+ 30 from WC29 +portmap_30=117:40 + +#QSFP+ 31 from WC30 +portmap_31=121:40 + +#QSFP+ 32 from WC31 +portmap_32=125:40 + +# L3 ECMP +# - In Trident2, VP LAGs share the same table as ECMP group table. +# The first N entries are reserved for VP LAGs, where N is the value of the +# config property "max_vp_lags". By default this was set to 256 +l3_max_ecmp_mode=1 +max_vp_lags=0 + +stable_size=0x2000000 +scache_filename=/tmp/scache diff --git a/device/accton/x86_64-accton_as6712_32x-r0/installer.conf b/device/accton/x86_64-accton_as6712_32x-r0/installer.conf new file mode 100644 index 000000000000..14404194ef53 --- /dev/null +++ b/device/accton/x86_64-accton_as6712_32x-r0/installer.conf @@ -0,0 +1,3 @@ +CONSOLE_PORT=0x2f8 +CONSOLE_DEV=1 +CONSOLE_SPEED=115200 diff --git a/device/accton/x86_64-accton_as6712_32x-r0/led_proc_init.soc b/device/accton/x86_64-accton_as6712_32x-r0/led_proc_init.soc new file mode 100644 index 000000000000..9e29adf790de --- /dev/null +++ b/device/accton/x86_64-accton_as6712_32x-r0/led_proc_init.soc @@ -0,0 +1,104 @@ +# LED setting for active +# ----------------------------------------------------------------------------- +# for as6712_32x (32 qxg) +# ----------------------------------------------------------------------------- + +s CMIC_LEDUP0_DATA_RAM 0 +s CMIC_LEDUP1_DATA_RAM 0 + +m CMIC_LEDUP0_PORT_ORDER_REMAP_60_63 REMAP_PORT_63=0 +m CMIC_LEDUP0_PORT_ORDER_REMAP_56_59 REMAP_PORT_59=1 +m CMIC_LEDUP0_PORT_ORDER_REMAP_52_55 REMAP_PORT_55=2 +m CMIC_LEDUP0_PORT_ORDER_REMAP_48_51 REMAP_PORT_51=3 +m CMIC_LEDUP0_PORT_ORDER_REMAP_32_35 REMAP_PORT_35=4 +m CMIC_LEDUP0_PORT_ORDER_REMAP_36_39 REMAP_PORT_39=5 +m CMIC_LEDUP0_PORT_ORDER_REMAP_40_43 REMAP_PORT_43=6 +m CMIC_LEDUP0_PORT_ORDER_REMAP_44_47 REMAP_PORT_47=7 + +m CMIC_LEDUP0_PORT_ORDER_REMAP_28_31 REMAP_PORT_31=8 +m CMIC_LEDUP0_PORT_ORDER_REMAP_24_27 REMAP_PORT_27=9 +m CMIC_LEDUP0_PORT_ORDER_REMAP_20_23 REMAP_PORT_23=10 +m CMIC_LEDUP0_PORT_ORDER_REMAP_16_19 REMAP_PORT_19=11 +m CMIC_LEDUP0_PORT_ORDER_REMAP_0_3 REMAP_PORT_3=12 +m CMIC_LEDUP0_PORT_ORDER_REMAP_4_7 REMAP_PORT_7=13 +m CMIC_LEDUP0_PORT_ORDER_REMAP_8_11 REMAP_PORT_11=14 +m CMIC_LEDUP0_PORT_ORDER_REMAP_12_15 REMAP_PORT_15=15 + + +m CMIC_LEDUP0_PORT_ORDER_REMAP_60_63 REMAP_PORT_62=63 +m CMIC_LEDUP0_PORT_ORDER_REMAP_60_63 REMAP_PORT_61=62 +m CMIC_LEDUP0_PORT_ORDER_REMAP_60_63 REMAP_PORT_60=61 +m CMIC_LEDUP0_PORT_ORDER_REMAP_56_59 REMAP_PORT_58=60 +m CMIC_LEDUP0_PORT_ORDER_REMAP_56_59 REMAP_PORT_57=59 +m CMIC_LEDUP0_PORT_ORDER_REMAP_56_59 REMAP_PORT_56=58 +m CMIC_LEDUP0_PORT_ORDER_REMAP_52_55 REMAP_PORT_54=57 +m CMIC_LEDUP0_PORT_ORDER_REMAP_52_55 REMAP_PORT_53=56 +m CMIC_LEDUP0_PORT_ORDER_REMAP_52_55 REMAP_PORT_52=55 +m CMIC_LEDUP0_PORT_ORDER_REMAP_48_51 REMAP_PORT_50=54 +m CMIC_LEDUP0_PORT_ORDER_REMAP_48_51 REMAP_PORT_49=53 +m CMIC_LEDUP0_PORT_ORDER_REMAP_48_51 REMAP_PORT_48=52 +m CMIC_LEDUP0_PORT_ORDER_REMAP_44_47 REMAP_PORT_46=51 +m CMIC_LEDUP0_PORT_ORDER_REMAP_44_47 REMAP_PORT_45=50 +m CMIC_LEDUP0_PORT_ORDER_REMAP_44_47 REMAP_PORT_44=49 +m CMIC_LEDUP0_PORT_ORDER_REMAP_40_43 REMAP_PORT_42=48 +m CMIC_LEDUP0_PORT_ORDER_REMAP_40_43 REMAP_PORT_41=47 +m CMIC_LEDUP0_PORT_ORDER_REMAP_40_43 REMAP_PORT_40=46 +m CMIC_LEDUP0_PORT_ORDER_REMAP_36_39 REMAP_PORT_38=45 +m CMIC_LEDUP0_PORT_ORDER_REMAP_36_39 REMAP_PORT_37=44 +m CMIC_LEDUP0_PORT_ORDER_REMAP_36_39 REMAP_PORT_36=43 +m CMIC_LEDUP0_PORT_ORDER_REMAP_32_35 REMAP_PORT_34=42 +m CMIC_LEDUP0_PORT_ORDER_REMAP_32_35 REMAP_PORT_33=41 +m CMIC_LEDUP0_PORT_ORDER_REMAP_32_35 REMAP_PORT_32=40 +m CMIC_LEDUP0_PORT_ORDER_REMAP_28_31 REMAP_PORT_30=39 +m CMIC_LEDUP0_PORT_ORDER_REMAP_28_31 REMAP_PORT_29=38 +m CMIC_LEDUP0_PORT_ORDER_REMAP_28_31 REMAP_PORT_28=37 +m CMIC_LEDUP0_PORT_ORDER_REMAP_24_27 REMAP_PORT_26=36 +m CMIC_LEDUP0_PORT_ORDER_REMAP_24_27 REMAP_PORT_25=35 +m CMIC_LEDUP0_PORT_ORDER_REMAP_24_27 REMAP_PORT_24=34 +m CMIC_LEDUP0_PORT_ORDER_REMAP_20_23 REMAP_PORT_22=33 +m CMIC_LEDUP0_PORT_ORDER_REMAP_20_23 REMAP_PORT_21=32 +m CMIC_LEDUP0_PORT_ORDER_REMAP_20_23 REMAP_PORT_20=31 +m CMIC_LEDUP0_PORT_ORDER_REMAP_16_19 REMAP_PORT_18=30 +m CMIC_LEDUP0_PORT_ORDER_REMAP_16_19 REMAP_PORT_17=29 +m CMIC_LEDUP0_PORT_ORDER_REMAP_16_19 REMAP_PORT_16=28 +m CMIC_LEDUP0_PORT_ORDER_REMAP_12_15 REMAP_PORT_14=27 +m CMIC_LEDUP0_PORT_ORDER_REMAP_12_15 REMAP_PORT_13=26 +m CMIC_LEDUP0_PORT_ORDER_REMAP_12_15 REMAP_PORT_12=25 +m CMIC_LEDUP0_PORT_ORDER_REMAP_8_11 REMAP_PORT_10=24 +m CMIC_LEDUP0_PORT_ORDER_REMAP_8_11 REMAP_PORT_9=23 +m CMIC_LEDUP0_PORT_ORDER_REMAP_8_11 REMAP_PORT_8=22 +m CMIC_LEDUP0_PORT_ORDER_REMAP_4_7 REMAP_PORT_6=21 +m CMIC_LEDUP0_PORT_ORDER_REMAP_4_7 REMAP_PORT_5=20 +m CMIC_LEDUP0_PORT_ORDER_REMAP_4_7 REMAP_PORT_4=19 +m CMIC_LEDUP0_PORT_ORDER_REMAP_0_3 REMAP_PORT_2=18 +m CMIC_LEDUP0_PORT_ORDER_REMAP_0_3 REMAP_PORT_1=17 +m CMIC_LEDUP0_PORT_ORDER_REMAP_0_3 REMAP_PORT_0=16 + + +led 0 stop +led 0 prog \ + 02 F9 42 80 02 F7 42 00 02 F8 42 00 02 F4 42 90 02 \ + F3 42 10 67 6A 67 6A 67 38 67 6A 67 6A 67 6A 67 6A \ + 67 6A 67 6A 86 F8 06 F3 D6 F8 74 14 86 F0 3E F4 67 \ + 6A 57 67 7E 57 06 F8 88 80 4A 00 27 97 75 35 90 4A \ + 00 27 4A 01 27 B7 97 71 4F 77 32 06 F5 D6 F0 74 62 \ + 02 F5 4A 07 37 4E 07 02 F0 42 00 4E 07 02 F5 4A 07 \ + 71 32 77 35 16 F7 06 F9 17 4D DA 07 74 7B 12 F7 52 \ + 00 86 F9 57 86 F7 57 16 F7 06 F9 07 4D DA 07 74 8F \ + 12 F7 52 00 86 F9 57 86 F7 57 00 00 00 00 00 00 00 \ + 00 00 00 00 00 00 00 +led 0 start + +led 1 stop +led 1 prog \ + 02 F9 42 80 02 F7 42 00 02 F8 42 01 02 F4 42 90 02 \ + F3 42 11 67 6A 67 6A 67 38 67 6A 67 6A 67 6A 67 6A \ + 67 6A 67 6A 86 F8 06 F3 D6 F8 74 14 86 F0 3E F4 67 \ + 6A 57 67 7E 57 06 F8 88 80 4A 00 27 97 75 35 90 4A \ + 00 27 4A 01 27 B7 97 71 4F 77 32 06 F5 D6 F0 74 62 \ + 02 F5 4A 07 37 4E 07 02 F0 42 00 4E 07 02 F5 4A 07 \ + 71 32 77 35 16 F7 06 F9 17 4D DA 07 74 7B 12 F7 52 \ + 00 86 F9 57 86 F7 57 16 F7 06 F9 07 4D DA 07 74 8F \ + 12 F7 52 00 86 F9 57 86 F7 57 00 00 00 00 00 00 00 \ + 00 00 00 00 00 00 00 +led 1 start diff --git a/device/accton/x86_64-accton_as6712_32x-r0/minigraph.xml b/device/accton/x86_64-accton_as6712_32x-r0/minigraph.xml new file mode 100755 index 000000000000..a115ae98e799 --- /dev/null +++ b/device/accton/x86_64-accton_as6712_32x-r0/minigraph.xml @@ -0,0 +1,1074 @@ + + + + + + ARISTA01T0 + 10.0.0.33 + sonic + 10.0.0.32 + 1 + 180 + 60 + + + sonic + 10.0.0.0 + ARISTA01T2 + 10.0.0.1 + 1 + 180 + 60 + + + ARISTA02T0 + 10.0.0.35 + sonic + 10.0.0.34 + 1 + 180 + 60 + + + sonic + 10.0.0.2 + ARISTA02T2 + 10.0.0.3 + 1 + 180 + 60 + + + ARISTA03T0 + 10.0.0.37 + sonic + 10.0.0.36 + 1 + 180 + 60 + + + sonic + 10.0.0.4 + ARISTA03T2 + 10.0.0.5 + 1 + 180 + 60 + + + ARISTA04T0 + 10.0.0.39 + sonic + 10.0.0.38 + 1 + 180 + 60 + + + sonic + 10.0.0.6 + ARISTA04T2 + 10.0.0.7 + 1 + 180 + 60 + + + ARISTA05T0 + 10.0.0.41 + sonic + 10.0.0.40 + 1 + 180 + 60 + + + sonic + 10.0.0.8 + ARISTA05T2 + 10.0.0.9 + 1 + 180 + 60 + + + ARISTA06T0 + 10.0.0.43 + sonic + 10.0.0.42 + 1 + 180 + 60 + + + sonic + 10.0.0.10 + ARISTA06T2 + 10.0.0.11 + 1 + 180 + 60 + + + ARISTA07T0 + 10.0.0.45 + sonic + 10.0.0.44 + 1 + 180 + 60 + + + sonic + 10.0.0.12 + ARISTA07T2 + 10.0.0.13 + 1 + 180 + 60 + + + ARISTA08T0 + 10.0.0.47 + sonic + 10.0.0.46 + 1 + 180 + 60 + + + sonic + 10.0.0.14 + ARISTA08T2 + 10.0.0.15 + 1 + 180 + 60 + + + ARISTA09T0 + 10.0.0.49 + sonic + 10.0.0.48 + 1 + 180 + 60 + + + sonic + 10.0.0.16 + ARISTA09T2 + 10.0.0.17 + 1 + 180 + 60 + + + ARISTA10T0 + 10.0.0.51 + sonic + 10.0.0.50 + 1 + 180 + 60 + + + sonic + 10.0.0.18 + ARISTA10T2 + 10.0.0.19 + 1 + 180 + 60 + + + ARISTA11T0 + 10.0.0.53 + sonic + 10.0.0.52 + 1 + 180 + 60 + + + sonic + 10.0.0.20 + ARISTA11T2 + 10.0.0.21 + 1 + 180 + 60 + + + ARISTA12T0 + 10.0.0.55 + sonic + 10.0.0.54 + 1 + 180 + 60 + + + sonic + 10.0.0.22 + ARISTA12T2 + 10.0.0.23 + 1 + 180 + 60 + + + ARISTA13T0 + 10.0.0.57 + sonic + 10.0.0.56 + 1 + 180 + 60 + + + sonic + 10.0.0.24 + ARISTA13T2 + 10.0.0.25 + 1 + 180 + 60 + + + ARISTA14T0 + 10.0.0.59 + sonic + 10.0.0.58 + 1 + 180 + 60 + + + sonic + 10.0.0.26 + ARISTA14T2 + 10.0.0.27 + 1 + 180 + 60 + + + ARISTA15T0 + 10.0.0.61 + sonic + 10.0.0.60 + 1 + 180 + 60 + + + sonic + 10.0.0.28 + ARISTA15T2 + 10.0.0.29 + 1 + 180 + 60 + + + ARISTA16T0 + 10.0.0.63 + sonic + 10.0.0.62 + 1 + 180 + 60 + + + sonic + 10.0.0.30 + ARISTA16T2 + 10.0.0.31 + 1 + 180 + 60 + + + + + 65100 + sonic + + +
10.0.0.33
+ + +
+ +
10.0.0.1
+ + +
+ +
10.0.0.35
+ + +
+ +
10.0.0.3
+ + +
+ +
10.0.0.37
+ + +
+ +
10.0.0.5
+ + +
+ +
10.0.0.39
+ + +
+ +
10.0.0.7
+ + +
+ +
10.0.0.41
+ + +
+ +
10.0.0.9
+ + +
+ +
10.0.0.43
+ + +
+ +
10.0.0.11
+ + +
+ +
10.0.0.45
+ + +
+ +
10.0.0.13
+ + +
+ +
10.0.0.47
+ + +
+ +
10.0.0.15
+ + +
+ +
10.0.0.49
+ + +
+ +
10.0.0.17
+ + +
+ +
10.0.0.51
+ + +
+ +
10.0.0.19
+ + +
+ +
10.0.0.53
+ + +
+ +
10.0.0.21
+ + +
+ +
10.0.0.55
+ + +
+ +
10.0.0.23
+ + +
+ +
10.0.0.57
+ + +
+ +
10.0.0.25
+ + +
+ +
10.0.0.59
+ + +
+ +
10.0.0.27
+ + +
+ +
10.0.0.61
+ + +
+ +
10.0.0.29
+ + +
+ +
10.0.0.63
+ + +
+ +
10.0.0.31
+ + +
+
+ +
+ + 64001 + ARISTA01T0 + + + + 65200 + ARISTA01T2 + + + + 64002 + ARISTA02T0 + + + + 65200 + ARISTA02T2 + + + + 64003 + ARISTA03T0 + + + + 65200 + ARISTA03T2 + + + + 64004 + ARISTA04T0 + + + + 65200 + ARISTA04T2 + + + + 64005 + ARISTA05T0 + + + + 65200 + ARISTA05T2 + + + + 64006 + ARISTA06T0 + + + + 65200 + ARISTA06T2 + + + + 64007 + ARISTA07T0 + + + + 65200 + ARISTA07T2 + + + + 64008 + ARISTA08T0 + + + + 65200 + ARISTA08T2 + + + + 64009 + ARISTA09T0 + + + + 65200 + ARISTA09T2 + + + + 64010 + ARISTA10T0 + + + + 65200 + ARISTA10T2 + + + + 64011 + ARISTA11T0 + + + + 65200 + ARISTA11T2 + + + + 64012 + ARISTA12T0 + + + + 65200 + ARISTA12T2 + + + + 64013 + ARISTA13T0 + + + + 65200 + ARISTA13T2 + + + + 64014 + ARISTA14T0 + + + + 65200 + ARISTA14T2 + + + + 64015 + ARISTA15T0 + + + + 65200 + ARISTA15T2 + + + + 64016 + ARISTA16T0 + + + + 65200 + ARISTA16T2 + + +
+
+ + + + + + HostIP + Loopback0 + + 10.1.0.32/32 + + 10.1.0.32/32 + + + + + + + + sonic + + + + + + Ethernet0 + 10.0.0.0/31 + + + + Ethernet4 + 10.0.0.2/31 + + + + Ethernet8 + 10.0.0.4/31 + + + + Ethernet12 + 10.0.0.6/31 + + + + Ethernet16 + 10.0.0.8/31 + + + + Ethernet20 + 10.0.0.10/31 + + + + Ethernet24 + 10.0.0.12/31 + + + + Ethernet28 + 10.0.0.14/31 + + + + Ethernet32 + 10.0.0.16/31 + + + + Ethernet36 + 10.0.0.18/31 + + + + Ethernet40 + 10.0.0.20/31 + + + + Ethernet44 + 10.0.0.22/31 + + + + Ethernet48 + 10.0.0.24/31 + + + + Ethernet52 + 10.0.0.26/31 + + + + Ethernet56 + 10.0.0.28/31 + + + + Ethernet60 + 10.0.0.30/31 + + + + Ethernet64 + 10.0.0.32/31 + + + + Ethernet68 + 10.0.0.34/31 + + + + Ethernet72 + 10.0.0.36/31 + + + + Ethernet76 + 10.0.0.38/31 + + + + Ethernet80 + 10.0.0.40/31 + + + + Ethernet84 + 10.0.0.42/31 + + + + Ethernet88 + 10.0.0.44/31 + + + + Ethernet92 + 10.0.0.46/31 + + + + Ethernet96 + 10.0.0.48/31 + + + + Ethernet100 + 10.0.0.50/31 + + + + Ethernet104 + 10.0.0.52/31 + + + + Ethernet108 + 10.0.0.54/31 + + + + Ethernet112 + 10.0.0.56/31 + + + + Ethernet116 + 10.0.0.58/31 + + + + Ethernet120 + 10.0.0.60/31 + + + + Ethernet124 + 10.0.0.62/31 + + + + + + + + + + + + DeviceInterfaceLink + sonic + Ethernet0 + ARISTA01T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet4 + ARISTA02T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet8 + ARISTA03T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet12 + ARISTA04T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet16 + ARISTA05T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet20 + ARISTA06T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet24 + ARISTA07T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet28 + ARISTA08T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet32 + ARISTA09T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet36 + ARISTA10T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet40 + ARISTA11T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet44 + ARISTA12T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet48 + ARISTA13T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet52 + ARISTA14T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet56 + ARISTA15T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet60 + ARISTA16T2 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet64 + ARISTA01T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet68 + ARISTA02T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet72 + ARISTA03T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet76 + ARISTA04T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet80 + ARISTA05T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet84 + ARISTA06T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet88 + ARISTA07T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet92 + ARISTA08T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet96 + ARISTA09T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet100 + ARISTA10T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet104 + ARISTA11T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet108 + ARISTA12T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet112 + ARISTA13T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet116 + ARISTA14T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet120 + ARISTA15T0 + Ethernet1 + + + DeviceInterfaceLink + sonic + Ethernet124 + ARISTA16T0 + Ethernet1 + + + + + sonic + Accton-AS6712-32X + + + + + + + sonic + + + DhcpResources + + + + + NtpResources + + 0.debian.pool.ntp.org;1.debian.pool.ntp.org;2.debian.pool.ntp.org;3.debian.pool.ntp.org + + + SyslogResources + + + + + + + + + sonic + Accton-AS6712-32X +
diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py new file mode 100644 index 000000000000..7681caafeef4 --- /dev/null +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +try: + import exceptions + import binascii + import time + import optparse + import warnings + import os + import sys + from sonic_eeprom import eeprom_base + from sonic_eeprom import eeprom_tlvinfo + import subprocess +except ImportError, e: + raise ImportError (str(e) + "- required module not found") + +class board(eeprom_tlvinfo.TlvInfoDecoder): + _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): + self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" + #Two i2c buses might get flipped order, check them both. + if not os.path.exists(self.eeprom_path): + self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py new file mode 100755 index 000000000000..191654429e6b --- /dev/null +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +############################################################################# +# Accton +# +# Module contains an implementation of SONiC PSU Base API and +# provides the PSUs status which are available in the platform +# +############################################################################# + +import os.path + +try: + from sonic_psu.psu_base import PsuBase +except ImportError as e: + raise ImportError (str(e) + "- required module not found") + +class PsuUtil(PsuBase): + """Platform-specific PSUutil class""" + + def __init__(self): + PsuBase.__init__(self) + + self.psu_path = "/sys/bus/i2c/devices/" + self.psu_presence = "/psu_present" + self.psu_oper_status = "/psu_power_good" + self.psu_mapping = { + 1: "35-0038", + 2: "36-003b", + } + + def get_num_psus(self): + return len(self.psu_mapping) + + def get_psu_status(self, index): + if index is None: + return False + + status = 0 + node = self.psu_path + self.psu_mapping[index]+self.psu_oper_status + try: + with open(node, 'r') as power_status: + status = int(power_status.read()) + except IOError: + return False + + return status == 1 + + def get_psu_presence(self, index): + if index is None: + return False + + status = 0 + node = self.psu_path + self.psu_mapping[index] + self.psu_presence + try: + with open(node, 'r') as presence_status: + status = int(presence_status.read()) + except IOError: + return False + + return status == 1 diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py new file mode 100755 index 000000000000..3893aa651d19 --- /dev/null +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py @@ -0,0 +1,206 @@ +# sfputil.py +# +# Platform-specific SFP transceiver interface for SONiC +# + +try: + import time + import os + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: + raise ImportError("%s - required module not found" % str(e)) + + +class SfpUtil(SfpUtilBase): + """Platform-specific SfpUtil class""" + + PORT_START = 0 + PORT_END = 31 + PORTS_IN_BLOCK = 32 + QSFP_PORT_START = 0 + QSFP_PORT_END = 32 + + I2C_DEV_PATH = "/sys/bus/i2c/devices/" + BASE_VAL_PATH = "/sys/class/i2c-adapter/i2c-{0}/{1}-0050/" + BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" + CPLD_ADDRESS = ['-0062', '-0064'] + + _port_to_is_present = {} + _port_to_lp_mode = {} + + _port_to_eeprom_mapping = {} + _port_to_i2c_mapping = { + 0: [1, 2], + 1: [2, 3], + 2: [3, 4], + 3: [4, 5], + 4: [5, 6], + 5: [6, 7], + 6: [7, 8], + 7: [8, 9], + 8: [9, 10], + 9: [10, 11], + 10: [11, 12], + 11: [12, 13], + 12: [13, 14], + 13: [14, 15], + 14: [15, 16], + 15: [16, 17], + 16: [17, 18], + 17: [18, 19], + 18: [19, 20], + 19: [20, 21], + 20: [21, 22], + 21: [22, 23], + 22: [23, 24], + 23: [24, 25], + 24: [25, 26], + 25: [26, 27], + 26: [27, 28], + 27: [28, 29], + 28: [29, 30], + 29: [30, 31], + 30: [31, 32], + 31: [32, 33], + 32: [33, 34], + 33: [34, 35], + 34: [35, 36], + 35: [36, 37], + 36: [37, 38], + 37: [38, 39], + 38: [39, 40], + 39: [40, 41], + 40: [41, 42], + 41: [42, 43], + 42: [43, 44], + 43: [44, 45], + 44: [45, 46], + 45: [46, 47], + 46: [47, 48], + 47: [48, 49], + 48: [49, 50],#QSFP49 + 49: [49, 50], + 50: [49, 50], + 51: [49, 50], + 52: [50, 52],#QSFP50 + 53: [50, 52], + 54: [50, 52], + 55: [50, 52], + 56: [51, 54],#QSFP51 + 57: [51, 54], + 58: [51, 54], + 59: [51, 54], + 60: [52, 51],#QSFP52 + 61: [52, 51], + 62: [52, 51], + 63: [52, 51], + 64: [53, 53], #QSFP53 + 65: [53, 53], + 66: [53, 53], + 67: [53, 53], + 68: [54, 55],#QSFP54 + 69: [54, 55], + 70: [54, 55], + 71: [54, 55], + } + + @property + def port_start(self): + return self.PORT_START + + @property + def port_end(self): + return self.PORT_END + + @property + def qsfp_port_start(self): + return self.QSFP_PORT_START + + @property + def qsfp_port_end(self): + return self.QSFP_PORT_END + + @property + def qsfp_ports(self): + return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + + @property + def port_to_eeprom_mapping(self): + return self._port_to_eeprom_mapping + + def __init__(self): + eeprom_path = self.BASE_OOM_PATH + "eeprom" + + for x in range(0, self.port_end+1): + self.port_to_eeprom_mapping[x] = eeprom_path.format( + self._port_to_i2c_mapping[x][1] + ) + + SfpUtilBase.__init__(self) + + def get_cpld_dev_path(self, port_num): + if port_num < 16: + cpld_num = 0 + else: + cpld_num = 1 + + #cpld can be at either bus 0 or bus 1. + cpld_path = self.I2C_DEV_PATH + str(0) + self.CPLD_ADDRESS[cpld_num] + if not os.path.exists(cpld_path): + cpld_path = self.I2C_DEV_PATH + str(1) + self.CPLD_ADDRESS[cpld_num] + return cpld_path + + def get_presence(self, port_num): + # Check for invalid port_num + if port_num < self.port_start or port_num > self.port_end: + return False + + cpld_path = self.get_cpld_dev_path(port_num) + present_path = cpld_path + "/module_present_" + present_path += str(self._port_to_i2c_mapping[port_num][0]) + + self.__port_to_is_present = present_path + + try: + val_file = open(self.__port_to_is_present) + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + + content = val_file.readline().rstrip() + val_file.close() + + # content is a string, either "0" or "1" + if content == "1": + return True + + return False + + def get_low_power_mode(self, port_num): + raise NotImplementedError + + def set_low_power_mode(self, port_num, lpmode): + raise NotImplementedError + + def reset(self, port_num): + if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: + return False + + cpld_path = self.get_cpld_dev_path(port_num) + _path = cpld_path + "/module_reset_" + _path += str(self._port_to_i2c_mapping[port_num][0]) + + try: + reg_file = open(_path, 'w') + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + + reg_file.seek(0) + reg_file.write('1') + time.sleep(1) + reg_file.seek(0) + reg_file.write('0') + reg_file.close() + + return True diff --git a/device/accton/x86_64-accton_as6712_32x-r0/sensors.conf b/device/accton/x86_64-accton_as6712_32x-r0/sensors.conf new file mode 100755 index 000000000000..84ee0fd9f333 --- /dev/null +++ b/device/accton/x86_64-accton_as6712_32x-r0/sensors.conf @@ -0,0 +1,23 @@ +# libsensors configuration file for AS6712-32X +# ------------------------------------------------ + +chip "cpr_4011_4mxx-i2c-*-3c" + label in1 "PSU1_VIN" + label in2 "PSU1_VOUT" + label curr1 "PSU1_IIN" + label curr2 "PSU1_IOUT" + label power1 "PSU1_PIN" + label power2 "PSU1_POUT" + label fan1 "PSU1_FAN" + label temp1 "PSU1_TEMP" + +chip "cpr_4011_4mxx-i2c-*-3f" + label in1 "PSU2_VIN" + label in2 "PSU2_VOUT" + label curr1 "PSU2_IIN" + label curr2 "PSU2_IOUT" + label power1 "PSU2_PIN" + label power2 "PSU2_POUT" + label fan1 "PSU2_FAN" + label temp1 "PSU2_TEMP" + diff --git a/platform/broadcom/one-image.mk b/platform/broadcom/one-image.mk index 8b24216d0a9d..1f29b99a506e 100755 --- a/platform/broadcom/one-image.mk +++ b/platform/broadcom/one-image.mk @@ -20,6 +20,7 @@ $(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(DELL_S6000_PLATFORM_MODULE) \ $(ACCTON_AS7312_54X_PLATFORM_MODULE) \ $(ACCTON_AS7326_56X_PLATFORM_MODULE) \ $(ACCTON_AS7716_32XB_PLATFORM_MODULE) \ + $(ACCTON_AS6712_32X_PLATFORM_MODULE) \ $(INVENTEC_D7032Q28B_PLATFORM_MODULE) \ $(INVENTEC_D7054Q28B_PLATFORM_MODULE) \ $(CEL_DX010_PLATFORM_MODULE) \ diff --git a/platform/broadcom/platform-modules-accton.mk b/platform/broadcom/platform-modules-accton.mk index 729e76e3ed1d..72c2453c5359 100755 --- a/platform/broadcom/platform-modules-accton.mk +++ b/platform/broadcom/platform-modules-accton.mk @@ -7,6 +7,7 @@ ACCTON_AS7716_32X_PLATFORM_MODULE_VERSION = 1.1 ACCTON_AS7312_54X_PLATFORM_MODULE_VERSION = 1.1 ACCTON_AS7326_56X_PLATFORM_MODULE_VERSION = 1.1 ACCTON_AS7716_32XB_PLATFORM_MODULE_VERSION = 1.1 +ACCTON_AS6712_32X_PLATFORM_MODULE_VERSION = 1.1 export ACCTON_AS7712_32X_PLATFORM_MODULE_VERSION export ACCTON_AS5712_54X_PLATFORM_MODULE_VERSION @@ -15,6 +16,7 @@ export ACCTON_AS7716_32X_PLATFORM_MODULE_VERSION export ACCTON_AS7312_54X_PLATFORM_MODULE_VERSION export ACCTON_AS7326_56X_PLATFORM_MODULE_VERSION export ACCTON_AS7716_32XB_PLATFORM_MODULE_VERSION +export ACCTON_AS6712_32X_PLATFORM_MODULE_VERSION ACCTON_AS7712_32X_PLATFORM_MODULE = sonic-platform-accton-as7712-32x_$(ACCTON_AS7712_32X_PLATFORM_MODULE_VERSION)_amd64.deb $(ACCTON_AS7712_32X_PLATFORM_MODULE)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-accton @@ -46,4 +48,8 @@ ACCTON_AS7716_32XB_PLATFORM_MODULE = sonic-platform-accton-as7716-32xb_$(ACCTON_ $(ACCTON_AS7716_32XB_PLATFORM_MODULE)_PLATFORM = x86_64-accton_as7716_32xb-r0 $(eval $(call add_extra_package,$(ACCTON_AS7712_32X_PLATFORM_MODULE),$(ACCTON_AS7716_32XB_PLATFORM_MODULE))) +ACCTON_AS6712_32X_PLATFORM_MODULE = sonic-platform-accton-as6712-32x_$(ACCTON_AS6712_32X_PLATFORM_MODULE_VERSION)_amd64.deb +$(ACCTON_AS6712_32X_PLATFORM_MODULE)_PLATFORM = x86_64-accton_as6712_32x-r0 +$(eval $(call add_extra_package,$(ACCTON_AS7712_32X_PLATFORM_MODULE),$(ACCTON_AS6712_32X_PLATFORM_MODULE))) + SONIC_STRETCH_DEBS += $(ACCTON_AS7712_32X_PLATFORM_MODULE) diff --git a/platform/broadcom/sonic-platform-modules-accton b/platform/broadcom/sonic-platform-modules-accton new file mode 160000 index 000000000000..eedb2feb7677 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-accton @@ -0,0 +1 @@ +Subproject commit eedb2feb76779fb822d57d1546236c928bd8e695 diff --git a/platform/broadcom/sonic-platform-modules-accton/.gitignore b/platform/broadcom/sonic-platform-modules-accton/.gitignore deleted file mode 100644 index 7f287d538227..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/.gitignore +++ /dev/null @@ -1,50 +0,0 @@ -# Object files -*.o -*.ko -*.obj -*.elf - -# Precompiled Headers -*.gch -*.pch - -# Libraries -*.lib -*.a -*.la -*.lo - -# Shared objects (inc. Windows DLLs) -*.dll -*.so -*.so.* -*.dylib - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - -# Debug files -*.dSYM/ -*.su - -# Kernel Module Compile Results -*.mod* -*.cmd -*.o.d -.tmp_versions/ -modules.order -Module.symvers -Mkfile.old -dkms.conf - -# Debian packaging -*.debhelper.log -*.postinst.debhelper -*.postrm.debhelper -*.prerm.debhelper -*.substvars diff --git a/platform/broadcom/sonic-platform-modules-accton/LICENSE b/platform/broadcom/sonic-platform-modules-accton/LICENSE deleted file mode 100644 index bc693f7a4c40..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/LICENSE +++ /dev/null @@ -1,16 +0,0 @@ -Copyright (C) 2016 Microsoft, Inc -Copyright (C) 2017 Accton Technology Corporation - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 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. diff --git a/platform/broadcom/sonic-platform-modules-accton/README.md b/platform/broadcom/sonic-platform-modules-accton/README.md deleted file mode 100644 index 0ff20bb2d21b..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/README.md +++ /dev/null @@ -1 +0,0 @@ -platform drivers of Accton products for the SONiC project diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/classes/__init__.py b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/classes/__init__.py deleted file mode 100755 index e69de29bb2d1..000000000000 diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/classes/fanutil.py b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/classes/fanutil.py deleted file mode 100755 index c16771e214e4..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/classes/fanutil.py +++ /dev/null @@ -1,238 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# -# ------------------------------------------------------------------ - -try: - import time - import logging - from collections import namedtuple -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - - -class FanUtil(object): - """Platform-specific FanUtil class""" - - FAN_NUM_ON_MAIN_BROAD = 5 - FAN_NUM_1_IDX = 1 - FAN_NUM_2_IDX = 2 - FAN_NUM_3_IDX = 3 - FAN_NUM_4_IDX = 4 - FAN_NUM_5_IDX = 5 - - FAN_NODE_NUM_OF_MAP = 6 - FAN_NODE_FAULT_IDX_OF_MAP = 1 - FAN_NODE_SPEED_IDX_OF_MAP = 2 - FAN_NODE_DIR_IDX_OF_MAP = 3 - FAN_NODE_DUTY_IDX_OF_MAP = 4 - FANR_NODE_FAULT_IDX_OF_MAP = 5 - FANR_NODE_SPEED_IDX_OF_MAP = 6 - - BASE_VAL_PATH = '/sys/devices/platform/as5712_54x_fan/{0}' - - #logfile = '' - #loglevel = logging.INFO - - """ Dictionary where - key1 = fan id index (integer) starting from 1 - key2 = fan node index (interger) starting from 1 - value = path to fan device file (string) """ - _fan_to_device_path_mapping = {} - - _fan_to_device_node_mapping = { - (FAN_NUM_1_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan1_fault', - (FAN_NUM_1_IDX, FAN_NODE_SPEED_IDX_OF_MAP): 'fan1_speed_rpm', - (FAN_NUM_1_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan1_direction', - (FAN_NUM_1_IDX, FAN_NODE_DUTY_IDX_OF_MAP): 'fan1_duty_cycle_percentage', - (FAN_NUM_1_IDX, FANR_NODE_FAULT_IDX_OF_MAP): 'fanr1_fault', - (FAN_NUM_1_IDX, FANR_NODE_SPEED_IDX_OF_MAP): 'fanr1_speed_rpm', - - (FAN_NUM_2_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan2_fault', - (FAN_NUM_2_IDX, FAN_NODE_SPEED_IDX_OF_MAP): 'fan2_speed_rpm', - (FAN_NUM_2_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan2_direction', - (FAN_NUM_2_IDX, FAN_NODE_DUTY_IDX_OF_MAP): 'fan2_duty_cycle_percentage', - (FAN_NUM_2_IDX, FANR_NODE_FAULT_IDX_OF_MAP): 'fanr2_fault', - (FAN_NUM_2_IDX, FANR_NODE_SPEED_IDX_OF_MAP): 'fanr2_speed_rpm', - - (FAN_NUM_3_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan3_fault', - (FAN_NUM_3_IDX, FAN_NODE_SPEED_IDX_OF_MAP): 'fan3_speed_rpm', - (FAN_NUM_3_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan3_direction', - (FAN_NUM_3_IDX, FAN_NODE_DUTY_IDX_OF_MAP): 'fan3_duty_cycle_percentage', - (FAN_NUM_3_IDX, FANR_NODE_FAULT_IDX_OF_MAP): 'fanr3_fault', - (FAN_NUM_3_IDX, FANR_NODE_SPEED_IDX_OF_MAP): 'fanr3_speed_rpm', - - (FAN_NUM_4_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan4_fault', - (FAN_NUM_4_IDX, FAN_NODE_SPEED_IDX_OF_MAP): 'fan4_speed_rpm', - (FAN_NUM_4_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan4_direction', - (FAN_NUM_4_IDX, FAN_NODE_DUTY_IDX_OF_MAP): 'fan4_duty_cycle_percentage', - (FAN_NUM_4_IDX, FANR_NODE_FAULT_IDX_OF_MAP): 'fanr4_fault', - (FAN_NUM_4_IDX, FANR_NODE_SPEED_IDX_OF_MAP): 'fanr4_speed_rpm', - - (FAN_NUM_5_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan5_fault', - (FAN_NUM_5_IDX, FAN_NODE_SPEED_IDX_OF_MAP): 'fan5_speed_rpm', - (FAN_NUM_5_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan5_direction', - (FAN_NUM_5_IDX, FAN_NODE_DUTY_IDX_OF_MAP): 'fan5_duty_cycle_percentage', - (FAN_NUM_5_IDX, FANR_NODE_FAULT_IDX_OF_MAP): 'fanr5_fault', - (FAN_NUM_5_IDX, FANR_NODE_SPEED_IDX_OF_MAP): 'fanr5_speed_rpm', - } - - def _get_fan_to_device_node(self, fan_num, node_num): - return self._fan_to_device_node_mapping[(fan_num, node_num)] - - def _get_fan_node_val(self, fan_num, node_num): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num:%d', fan_num) - return None - - if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: - logging.debug('GET. Parameter error. node_num:%d', node_num) - return None - - device_path = self.get_fan_to_device_path(fan_num, node_num) - try: - val_file = open(device_path, 'r') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - content = val_file.readline().rstrip() - - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return int(content) - - def _set_fan_node_val(self, fan_num, node_num, val): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num:%d', fan_num) - return None - - if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: - logging.debug('GET. Parameter error. node_num:%d', node_num) - return None - - content = str(val) - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - device_path = self.get_fan_to_device_path(fan_num, node_num) - try: - val_file = open(device_path, 'w') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - val_file.write(content) - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return True - - def __init__(self): - fan_path = self.BASE_VAL_PATH - - for fan_num in range(self.FAN_NUM_1_IDX, self.FAN_NUM_ON_MAIN_BROAD+1): - for node_num in range(self.FAN_NODE_FAULT_IDX_OF_MAP, self.FAN_NODE_NUM_OF_MAP+1): - self._fan_to_device_path_mapping[(fan_num, node_num)] = fan_path.format( - self._fan_to_device_node_mapping[(fan_num, node_num)]) - - def get_num_fans(self): - return self.FAN_NUM_ON_MAIN_BROAD - - def get_idx_fan_start(self): - return self.FAN_NUM_1_IDX - - def get_num_nodes(self): - return self.FAN_NODE_NUM_OF_MAP - - def get_idx_node_start(self): - return self.FAN_NODE_FAULT_IDX_OF_MAP - - def get_size_node_map(self): - return len(self._fan_to_device_node_mapping) - - def get_size_path_map(self): - return len(self._fan_to_device_path_mapping) - - def get_fan_to_device_path(self, fan_num, node_num): - return self._fan_to_device_path_mapping[(fan_num, node_num)] - - def get_fan_fault(self, fan_num): - return self._get_fan_node_val(fan_num, self.FAN_NODE_FAULT_IDX_OF_MAP) - - def get_fan_speed(self, fan_num): - return self._get_fan_node_val(fan_num, self.FAN_NODE_SPEED_IDX_OF_MAP) - - def get_fan_dir(self, fan_num): - return self._get_fan_node_val(fan_num, self.FAN_NODE_DIR_IDX_OF_MAP) - - def get_fan_duty_cycle(self, fan_num): - return self._get_fan_node_val(fan_num, self.FAN_NODE_DUTY_IDX_OF_MAP) - - def set_fan_duty_cycle(self, fan_num, val): - return self._set_fan_node_val(fan_num, self.FAN_NODE_DUTY_IDX_OF_MAP, val) - - def get_fanr_fault(self, fan_num): - return self._get_fan_node_val(fan_num, self.FANR_NODE_FAULT_IDX_OF_MAP) - - def get_fanr_speed(self, fan_num): - return self._get_fan_node_val(fan_num, self.FANR_NODE_SPEED_IDX_OF_MAP) - - def get_fan_status(self, fan_num): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num, %d', fan_num) - return None - - if self.get_fan_fault(fan_num) is not None and self.get_fan_fault(fan_num) > 0: - logging.debug('GET. FAN fault. fan_num, %d', fan_num) - return False - - if self.get_fanr_fault(fan_num) is not None and self.get_fanr_fault(fan_num) > 0: - logging.debug('GET. FANR fault. fan_num, %d', fan_num) - return False - - return True - -#def main(): -# fan = FanUtil() -# -# print 'get_size_node_map : %d' % fan.get_size_node_map() -# print 'get_size_path_map : %d' % fan.get_size_path_map() -# for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1): -# for y in range(fan.get_idx_node_start(), fan.get_num_nodes()+1): -# print fan.get_fan_to_device_path(x, y) -# -#if __name__ == '__main__': -# main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/classes/thermalutil.py b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/classes/thermalutil.py deleted file mode 100755 index 5b8f890e8819..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/classes/thermalutil.py +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# -# ------------------------------------------------------------------ - -try: - import time - import logging - import glob - from collections import namedtuple -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - - -class ThermalUtil(object): - """Platform-specific ThermalUtil class""" - - THERMAL_NUM_ON_MAIN_BROAD = 3 - THERMAL_NUM_1_IDX = 1 # 1_ON_MAIN_BROAD - THERMAL_NUM_2_IDX = 2 # 2_ON_MAIN_BROAD - THERMAL_NUM_3_IDX = 3 # 3_ON_MAIN_BROAD - - BASE_VAL_PATH = '/sys/bus/i2c/devices/{0}-00{1}/hwmon/hwmon*/temp1_input' - - """ Dictionary where - key1 = thermal id index (integer) starting from 1 - value = path to fan device file (string) """ - _thermal_to_device_path_mapping = {} - - _thermal_to_device_node_mapping = { - THERMAL_NUM_1_IDX: ['61', '48'], - THERMAL_NUM_2_IDX: ['62', '49'], - THERMAL_NUM_3_IDX: ['63', '4a'], - } - - def __init__(self): - thermal_path = self.BASE_VAL_PATH - - for x in range(self.THERMAL_NUM_1_IDX, self.THERMAL_NUM_ON_MAIN_BROAD+1): - self._thermal_to_device_path_mapping[x] = thermal_path.format( - self._thermal_to_device_node_mapping[x][0], - self._thermal_to_device_node_mapping[x][1]) - - def _get_thermal_node_val(self, thermal_num): - if thermal_num < self.THERMAL_NUM_1_IDX or thermal_num > self.THERMAL_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. thermal_num, %d', thermal_num) - return None - - device_path = self.get_thermal_to_device_path(thermal_num) - for filename in glob.glob(device_path): - try: - val_file = open(filename, 'r') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - content = val_file.readline().rstrip() - - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return int(content) - - - def get_num_thermals(self): - return self.THERMAL_NUM_ON_MAIN_BROAD - - def get_idx_thermal_start(self): - return self.THERMAL_NUM_1_IDX - - def get_size_node_map(self): - return len(self._thermal_to_device_node_mapping) - - def get_size_path_map(self): - return len(self._thermal_to_device_path_mapping) - - def get_thermal_to_device_path(self, thermal_num): - return self._thermal_to_device_path_mapping[thermal_num] - - def get_thermal_1_val(self): - return self._get_thermal_node_val(self.THERMAL_NUM_1_IDX) - - def get_thermal_2_val(self): - return self._get_thermal_node_val(self.THERMAL_NUM_2_IDX) - -#def main(): -# thermal = ThermalUtil() -# -# print 'get_size_node_map : %d' % thermal.get_size_node_map() -# print 'get_size_path_map : %d' % thermal.get_size_path_map() -# for x in range(thermal.get_idx_thermal_start(), thermal.get_num_thermals()+1): -# print thermal.get_thermal_to_device_path(x) -# -#if __name__ == '__main__': -# main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/Makefile b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/Makefile deleted file mode 100755 index 39fe78bf8cae..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -ifneq ($(KERNELRELEASE),) -obj-m:= i2c-mux-accton_as5712_54x_cpld.o \ - accton_as5712_54x_fan.o leds-accton_as5712_54x.o accton_as5712_54x_psu.o \ - cpr_4011_4mxx.o ym2651y.o - -else -ifeq (,$(KERNEL_SRC)) -$(error KERNEL_SRC is not defined) -else -KERNELDIR:=$(KERNEL_SRC) -endif -PWD:=$(shell pwd) -default: - $(MAKE) -C $(KERNELDIR) M=$(PWD) modules -clean: - rm -rf *.o *.mod.o *.mod.o *.ko .*cmd .tmp_versions Module.markers Module.symvers modules.order -endif diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/accton_as5712_54x_fan.c b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/accton_as5712_54x_fan.c deleted file mode 100755 index db81a1a8ca97..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/accton_as5712_54x_fan.c +++ /dev/null @@ -1,437 +0,0 @@ -/* - * A hwmon driver for the Accton as5710 54x fan contrl - * - * Copyright (C) 2013 Accton Technology Corporation. - * Brandon Chuang - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define FAN_MAX_NUMBER 5 -#define FAN_SPEED_CPLD_TO_RPM_STEP 150 -#define FAN_SPEED_PRECENT_TO_CPLD_STEP 5 -#define FAN_DUTY_CYCLE_MIN 0 /* 10% ??*/ -#define FAN_DUTY_CYCLE_MAX 100 /* 100% */ - -#define CPLD_REG_FAN_STATUS_OFFSET 0xC -#define CPLD_REG_FANR_STATUS_OFFSET 0x1F -#define CPLD_REG_FAN_DIRECTION_OFFSET 0x1E - -#define CPLD_FAN1_REG_SPEED_OFFSET 0x10 -#define CPLD_FAN2_REG_SPEED_OFFSET 0x11 -#define CPLD_FAN3_REG_SPEED_OFFSET 0x12 -#define CPLD_FAN4_REG_SPEED_OFFSET 0x13 -#define CPLD_FAN5_REG_SPEED_OFFSET 0x14 - -#define CPLD_FANR1_REG_SPEED_OFFSET 0x18 -#define CPLD_FANR2_REG_SPEED_OFFSET 0x19 -#define CPLD_FANR3_REG_SPEED_OFFSET 0x1A -#define CPLD_FANR4_REG_SPEED_OFFSET 0x1B -#define CPLD_FANR5_REG_SPEED_OFFSET 0x1C - -#define CPLD_REG_FAN_PWM_CYCLE_OFFSET 0xD - -#define CPLD_FAN1_INFO_BIT_MASK 0x1 -#define CPLD_FAN2_INFO_BIT_MASK 0x2 -#define CPLD_FAN3_INFO_BIT_MASK 0x4 -#define CPLD_FAN4_INFO_BIT_MASK 0x8 -#define CPLD_FAN5_INFO_BIT_MASK 0x10 - -#define PROJECT_NAME - -#define LOCAL_DEBUG 0 - -static struct accton_as5712_54x_fan *fan_data = NULL; - -struct accton_as5712_54x_fan { - struct platform_device *pdev; - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 status[FAN_MAX_NUMBER]; /* inner first fan status */ - u32 speed[FAN_MAX_NUMBER]; /* inner first fan speed */ - u8 direction[FAN_MAX_NUMBER]; /* reconrd the direction of inner first and second fans */ - u32 duty_cycle[FAN_MAX_NUMBER]; /* control the speed of inner first and second fans */ - u8 r_status[FAN_MAX_NUMBER]; /* inner second fan status */ - u32 r_speed[FAN_MAX_NUMBER]; /* inner second fan speed */ -}; - -/*******************/ -#define MAKE_FAN_MASK_OR_REG(name,type) \ - CPLD_FAN##type##1_##name, \ - CPLD_FAN##type##2_##name, \ - CPLD_FAN##type##3_##name, \ - CPLD_FAN##type##4_##name, \ - CPLD_FAN##type##5_##name, - -/* fan related data - */ -static const u8 fan_info_mask[] = { - MAKE_FAN_MASK_OR_REG(INFO_BIT_MASK,) -}; - -static const u8 fan_speed_reg[] = { - MAKE_FAN_MASK_OR_REG(REG_SPEED_OFFSET,) -}; - -static const u8 fanr_speed_reg[] = { - MAKE_FAN_MASK_OR_REG(REG_SPEED_OFFSET,R) -}; - -/*******************/ -#define DEF_FAN_SET(id) \ - FAN##id##_FAULT, \ - FAN##id##_SPEED, \ - FAN##id##_DUTY_CYCLE, \ - FAN##id##_DIRECTION, \ - FANR##id##_FAULT, \ - FANR##id##_SPEED, - -enum sysfs_fan_attributes { - DEF_FAN_SET(1) - DEF_FAN_SET(2) - DEF_FAN_SET(3) - DEF_FAN_SET(4) - DEF_FAN_SET(5) -}; -/*******************/ -static void accton_as5712_54x_fan_update_device(struct device *dev); -static int accton_as5712_54x_fan_read_value(u8 reg); -static int accton_as5712_54x_fan_write_value(u8 reg, u8 value); - -static ssize_t fan_set_duty_cycle(struct device *dev, - struct device_attribute *da,const char *buf, size_t count); -static ssize_t fan_show_value(struct device *dev, - struct device_attribute *da, char *buf); - -extern int as5712_54x_cpld_read(unsigned short cpld_addr, u8 reg); -extern int as5712_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - - -/*******************/ -#define _MAKE_SENSOR_DEVICE_ATTR(prj, id) \ - static SENSOR_DEVICE_ATTR(prj##fan##id##_fault, S_IRUGO, fan_show_value, NULL, FAN##id##_FAULT); \ - static SENSOR_DEVICE_ATTR(prj##fan##id##_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##id##_SPEED); \ - static SENSOR_DEVICE_ATTR(prj##fan##id##_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_show_value, \ - fan_set_duty_cycle, FAN##id##_DUTY_CYCLE); \ - static SENSOR_DEVICE_ATTR(prj##fan##id##_direction, S_IRUGO, fan_show_value, NULL, FAN##id##_DIRECTION); \ - static SENSOR_DEVICE_ATTR(prj##fanr##id##_fault, S_IRUGO, fan_show_value, NULL, FANR##id##_FAULT); \ - static SENSOR_DEVICE_ATTR(prj##fanr##id##_speed_rpm, S_IRUGO, fan_show_value, NULL, FANR##id##_SPEED); - -#define MAKE_SENSOR_DEVICE_ATTR(prj,id) _MAKE_SENSOR_DEVICE_ATTR(prj,id) - -MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 1) -MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 2) -MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 3) -MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 4) -MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 5) -/*******************/ - -#define _MAKE_FAN_ATTR(prj, id) \ - &sensor_dev_attr_##prj##fan##id##_fault.dev_attr.attr, \ - &sensor_dev_attr_##prj##fan##id##_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_##prj##fan##id##_duty_cycle_percentage.dev_attr.attr,\ - &sensor_dev_attr_##prj##fan##id##_direction.dev_attr.attr, \ - &sensor_dev_attr_##prj##fanr##id##_fault.dev_attr.attr, \ - &sensor_dev_attr_##prj##fanr##id##_speed_rpm.dev_attr.attr, - -#define MAKE_FAN_ATTR(prj, id) _MAKE_FAN_ATTR(prj, id) - -static struct attribute *accton_as5712_54x_fan_attributes[] = { - /* fan related attributes */ - MAKE_FAN_ATTR(PROJECT_NAME,1) - MAKE_FAN_ATTR(PROJECT_NAME,2) - MAKE_FAN_ATTR(PROJECT_NAME,3) - MAKE_FAN_ATTR(PROJECT_NAME,4) - MAKE_FAN_ATTR(PROJECT_NAME,5) - NULL -}; -/*******************/ - -/* fan related functions - */ -static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - ssize_t ret = 0; - int data_index, type_index; - - accton_as5712_54x_fan_update_device(dev); - - if (fan_data->valid == 0) { - return ret; - } - - type_index = attr->index%FAN2_FAULT; - data_index = attr->index/FAN2_FAULT; - - switch (type_index) { - case FAN1_FAULT: - ret = sprintf(buf, "%d\n", fan_data->status[data_index]); - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); - break; - case FAN1_SPEED: - ret = sprintf(buf, "%d\n", fan_data->speed[data_index]); - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); - break; - case FAN1_DUTY_CYCLE: - ret = sprintf(buf, "%d\n", fan_data->duty_cycle[data_index]); - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); - break; - case FAN1_DIRECTION: - ret = sprintf(buf, "%d\n", fan_data->direction[data_index]); /* presnet, need to modify*/ - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); - break; - case FANR1_FAULT: - ret = sprintf(buf, "%d\n", fan_data->r_status[data_index]); - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); - break; - case FANR1_SPEED: - ret = sprintf(buf, "%d\n", fan_data->r_speed[data_index]); - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); - break; - default: - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d] \n", __FUNCTION__, __LINE__); - break; - } - - return ret; -} -/*******************/ -static ssize_t fan_set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) { - - int error, value; - - error = kstrtoint(buf, 10, &value); - if (error) - return error; - - if (value < FAN_DUTY_CYCLE_MIN || value > FAN_DUTY_CYCLE_MAX) - return -EINVAL; - - accton_as5712_54x_fan_write_value(CPLD_REG_FAN_PWM_CYCLE_OFFSET, value/FAN_SPEED_PRECENT_TO_CPLD_STEP); - - fan_data->valid = 0; - - return count; -} - -static const struct attribute_group accton_as5712_54x_fan_group = { - .attrs = accton_as5712_54x_fan_attributes, -}; - -static int accton_as5712_54x_fan_read_value(u8 reg) -{ - return as5712_54x_cpld_read(0x60, reg); -} - -static int accton_as5712_54x_fan_write_value(u8 reg, u8 value) -{ - return as5712_54x_cpld_write(0x60, reg, value); -} - -static void accton_as5712_54x_fan_update_device(struct device *dev) -{ - int speed, r_speed, fault, r_fault, ctrl_speed, direction; - int i; - - mutex_lock(&fan_data->update_lock); - - if (LOCAL_DEBUG) - printk ("Starting accton_as5712_54x_fan update \n"); - - if (!(time_after(jiffies, fan_data->last_updated + HZ + HZ / 2) || !fan_data->valid)) { - /* do nothing */ - goto _exit; - } - - fan_data->valid = 0; - - if (LOCAL_DEBUG) - printk ("Starting accton_as5712_54x_fan update 2 \n"); - - fault = accton_as5712_54x_fan_read_value(CPLD_REG_FAN_STATUS_OFFSET); - r_fault = accton_as5712_54x_fan_read_value(CPLD_REG_FANR_STATUS_OFFSET); - direction = accton_as5712_54x_fan_read_value(CPLD_REG_FAN_DIRECTION_OFFSET); - ctrl_speed = accton_as5712_54x_fan_read_value(CPLD_REG_FAN_PWM_CYCLE_OFFSET); - - if ( (fault < 0) || (r_fault < 0) || (direction < 0) || (ctrl_speed < 0) ) - { - if (LOCAL_DEBUG) - printk ("[Error!!][%s][%d] \n", __FUNCTION__, __LINE__); - goto _exit; /* error */ - } - - if (LOCAL_DEBUG) - printk ("[fan:] fault:%d, r_fault=%d, direction=%d, ctrl_speed=%d \n",fault, r_fault, direction, ctrl_speed); - - for (i=0; istatus[i] = (fault & fan_info_mask[i]) >> i; - if (LOCAL_DEBUG) - printk ("[fan%d:] fail=%d \n",i, fan_data->status[i]); - - fan_data->r_status[i] = (r_fault & fan_info_mask[i]) >> i; - fan_data->direction[i] = (direction & fan_info_mask[i]) >> i; - fan_data->duty_cycle[i] = ctrl_speed * FAN_SPEED_PRECENT_TO_CPLD_STEP; - - /* fan speed - */ - speed = accton_as5712_54x_fan_read_value(fan_speed_reg[i]); - r_speed = accton_as5712_54x_fan_read_value(fanr_speed_reg[i]); - if ( (speed < 0) || (r_speed < 0) ) - { - if (LOCAL_DEBUG) - printk ("[Error!!][%s][%d] \n", __FUNCTION__, __LINE__); - goto _exit; /* error */ - } - - if (LOCAL_DEBUG) - printk ("[fan%d:] speed:%d, r_speed=%d \n", i, speed, r_speed); - - fan_data->speed[i] = speed * FAN_SPEED_CPLD_TO_RPM_STEP; - fan_data->r_speed[i] = r_speed * FAN_SPEED_CPLD_TO_RPM_STEP; - } - - /* finish to update */ - fan_data->last_updated = jiffies; - fan_data->valid = 1; - -_exit: - mutex_unlock(&fan_data->update_lock); -} - -static int accton_as5712_54x_fan_probe(struct platform_device *pdev) -{ - int status = -1; - - /* Register sysfs hooks */ - status = sysfs_create_group(&pdev->dev.kobj, &accton_as5712_54x_fan_group); - if (status) { - goto exit; - - } - - fan_data->hwmon_dev = hwmon_device_register(&pdev->dev); - if (IS_ERR(fan_data->hwmon_dev)) { - status = PTR_ERR(fan_data->hwmon_dev); - goto exit_remove; - } - - dev_info(&pdev->dev, "accton_as5712_54x_fan\n"); - - return 0; - -exit_remove: - sysfs_remove_group(&pdev->dev.kobj, &accton_as5712_54x_fan_group); -exit: - return status; -} - -static int accton_as5712_54x_fan_remove(struct platform_device *pdev) -{ - hwmon_device_unregister(fan_data->hwmon_dev); - sysfs_remove_group(&fan_data->pdev->dev.kobj, &accton_as5712_54x_fan_group); - - return 0; -} - -#define DRVNAME "as5712_54x_fan" - -static struct platform_driver accton_as5712_54x_fan_driver = { - .probe = accton_as5712_54x_fan_probe, - .remove = accton_as5712_54x_fan_remove, - .driver = { - .name = DRVNAME, - .owner = THIS_MODULE, - }, -}; - -static int __init accton_as5712_54x_fan_init(void) -{ - int ret; - - ret = platform_driver_register(&accton_as5712_54x_fan_driver); - if (ret < 0) { - goto exit; - } - - fan_data = kzalloc(sizeof(struct accton_as5712_54x_fan), GFP_KERNEL); - if (!fan_data) { - ret = -ENOMEM; - platform_driver_unregister(&accton_as5712_54x_fan_driver); - goto exit; - } - - mutex_init(&fan_data->update_lock); - fan_data->valid = 0; - - fan_data->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); - if (IS_ERR(fan_data->pdev)) { - ret = PTR_ERR(fan_data->pdev); - platform_driver_unregister(&accton_as5712_54x_fan_driver); - kfree(fan_data); - goto exit; - } - -exit: - return ret; -} - -static void __exit accton_as5712_54x_fan_exit(void) -{ - platform_device_unregister(fan_data->pdev); - platform_driver_unregister(&accton_as5712_54x_fan_driver); - kfree(fan_data); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton_as5712_54x_fan driver"); -MODULE_LICENSE("GPL"); - -module_init(accton_as5712_54x_fan_init); -module_exit(accton_as5712_54x_fan_exit); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/accton_as5712_54x_psu.c b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/accton_as5712_54x_psu.c deleted file mode 100755 index 9a0d1dae58ba..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/accton_as5712_54x_psu.c +++ /dev/null @@ -1,371 +0,0 @@ -/* - * An hwmon driver for accton as5712_54x Power Module - * - * Copyright (C) 2015 Accton Technology Corporation. - * Copyright (C) Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#if 0 -#define DEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#define PSU_STATUS_I2C_ADDR 0x60 -#define PSU_STATUS_I2C_REG_OFFSET 0x2 - -#define IS_POWER_GOOD(id, value) (!!(value & BIT(id*4 + 1))) -#define IS_PRESENT(id, value) (!(value & BIT(id*4))) - -static ssize_t show_index(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); -static int as5712_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int as5712_54x_cpld_read(unsigned short cpld_addr, u8 reg); -static int as5712_54x_psu_model_name_get(struct device *dev); - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as5712_54x_psu_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 index; /* PSU index */ - u8 status; /* Status(present/power_good) register read from CPLD */ - char model_name[14]; /* Model name, read from eeprom */ -}; - -static struct as5712_54x_psu_data *as5712_54x_psu_update_device(struct device *dev); - -enum as5712_54x_psu_sysfs_attributes { - PSU_INDEX, - PSU_PRESENT, - PSU_MODEL_NAME, - PSU_POWER_GOOD -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_index, S_IRUGO, show_index, NULL, PSU_INDEX); -static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT); -static SENSOR_DEVICE_ATTR(psu_model_name, S_IRUGO, show_model_name,NULL, PSU_MODEL_NAME); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD); - -static struct attribute *as5712_54x_psu_attributes[] = { - &sensor_dev_attr_psu_index.dev_attr.attr, - &sensor_dev_attr_psu_present.dev_attr.attr, - &sensor_dev_attr_psu_model_name.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - NULL -}; - -static ssize_t show_index(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_psu_data *data = i2c_get_clientdata(client); - - return sprintf(buf, "%d\n", data->index); -} - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as5712_54x_psu_data *data = as5712_54x_psu_update_device(dev); - u8 status = 0; - - if (!data->valid) { - return sprintf(buf, "0\n"); - } - - if (attr->index == PSU_PRESENT) { - status = IS_PRESENT(data->index, data->status); - } - else { /* PSU_POWER_GOOD */ - status = IS_POWER_GOOD(data->index, data->status); - } - - return sprintf(buf, "%d\n", status); -} - -static ssize_t show_model_name(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as5712_54x_psu_data *data = as5712_54x_psu_update_device(dev); - - if (!data->valid) { - return 0; - } - - if (!IS_PRESENT(data->index, data->status)) { - return 0; - } - - if (as5712_54x_psu_model_name_get(dev) < 0) { - return -ENXIO; - } - - return sprintf(buf, "%s\n", data->model_name); -} - -static const struct attribute_group as5712_54x_psu_group = { - .attrs = as5712_54x_psu_attributes, -}; - -static int as5712_54x_psu_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as5712_54x_psu_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as5712_54x_psu_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - data->index = dev_id->driver_data; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as5712_54x_psu_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as5712_54x_psu_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as5712_54x_psu_remove(struct i2c_client *client) -{ - struct as5712_54x_psu_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as5712_54x_psu_group); - kfree(data); - - return 0; -} - -enum psu_index -{ - as5712_54x_psu1, - as5712_54x_psu2 -}; - -static const struct i2c_device_id as5712_54x_psu_id[] = { - { "as5712_54x_psu1", as5712_54x_psu1 }, - { "as5712_54x_psu2", as5712_54x_psu2 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as5712_54x_psu_id); - -static struct i2c_driver as5712_54x_psu_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as5712_54x_psu", - }, - .probe = as5712_54x_psu_probe, - .remove = as5712_54x_psu_remove, - .id_table = as5712_54x_psu_id, - .address_list = normal_i2c, -}; - -static int as5712_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) - goto abort; - if (unlikely(result != data_len)) { - result = -EIO; - goto abort; - } - - result = 0; - -abort: - return result; -} - -enum psu_type { - PSU_YM_2401_JCR, /* AC110V - F2B */ - PSU_YM_2401_JDR, /* AC110V - B2F */ - PSU_CPR_4011_4M11, /* AC110V - F2B */ - PSU_CPR_4011_4M21, /* AC110V - B2F */ - PSU_CPR_6011_2M11, /* AC110V - F2B */ - PSU_CPR_6011_2M21, /* AC110V - B2F */ - PSU_UM400D_01G, /* DC48V - F2B */ - PSU_UM400D01_01G /* DC48V - B2F */ -}; - -struct model_name_info { - enum psu_type type; - u8 offset; - u8 length; - char* model_name; -}; - -struct model_name_info models[] = { -{PSU_YM_2401_JCR, 0x20, 11, "YM-2401JCR"}, -{PSU_YM_2401_JDR, 0x20, 11, "YM-2401JDR"}, -{PSU_CPR_4011_4M11, 0x26, 13, "CPR-4011-4M11"}, -{PSU_CPR_4011_4M21, 0x26, 13, "CPR-4011-4M21"}, -{PSU_CPR_6011_2M11, 0x26, 13, "CPR-6011-2M11"}, -{PSU_CPR_6011_2M21, 0x26, 13, "CPR-6011-2M21"}, -{PSU_UM400D_01G, 0x50, 9, "um400d01G"}, -{PSU_UM400D01_01G, 0x50, 12, "um400d01-01G"}, -}; - -static int as5712_54x_psu_model_name_get(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_psu_data *data = i2c_get_clientdata(client); - int i, status; - - for (i = 0; i < ARRAY_SIZE(models); i++) { - memset(data->model_name, 0, sizeof(data->model_name)); - - status = as5712_54x_psu_read_block(client, models[i].offset, - data->model_name, models[i].length); - if (status < 0) { - data->model_name[0] = '\0'; - dev_dbg(&client->dev, "unable to read model name from (0x%x) offset(0x%x)\n", - client->addr, models[i].offset); - return status; - } - else { - data->model_name[models[i].length] = '\0'; - } - - if (i == PSU_YM_2401_JCR || i == PSU_YM_2401_JDR) { - /* Skip the meaningless data byte 8*/ - data->model_name[8] = data->model_name[9]; - data->model_name[9] = data->model_name[10]; - data->model_name[10] = '\0'; - } - - /* Determine if the model name is known, if not, read next index - */ - if (strncmp(data->model_name, models[i].model_name, models[i].length) == 0) { - return 0; - } - else { - data->model_name[0] = '\0'; - } - } - - return -ENODATA; -} - -static struct as5712_54x_psu_data *as5712_54x_psu_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_psu_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int status = -1; - - dev_dbg(&client->dev, "Starting as5712_54x update\n"); - data->valid = 0; - - - /* Read psu status */ - status = as5712_54x_cpld_read(PSU_STATUS_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET); - - if (status < 0) { - dev_dbg(&client->dev, "cpld reg (0x%x) err %d\n", PSU_STATUS_I2C_ADDR, status); - goto exit; - } - else { - data->status = status; - } - - data->last_updated = jiffies; - data->valid = 1; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init as5712_54x_psu_init(void) -{ - return i2c_add_driver(&as5712_54x_psu_driver); -} - -static void __exit as5712_54x_psu_exit(void) -{ - i2c_del_driver(&as5712_54x_psu_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as5712_54x_psu driver"); -MODULE_LICENSE("GPL"); - -module_init(as5712_54x_psu_init); -module_exit(as5712_54x_psu_exit); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/accton_as5712_54x_sfp.c b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/accton_as5712_54x_sfp.c deleted file mode 100755 index d236057c4e59..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/accton_as5712_54x_sfp.c +++ /dev/null @@ -1,825 +0,0 @@ -/* - * An hwmon driver for accton as5712_54x sfp - * - * Copyright (C) Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#if 0 -#define DEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define NUM_OF_SFF_PORT 54 -#define SFP_PORT_MAX 48 -#define I2C_ADDR_CPLD1 0x60 -#define I2C_ADDR_CPLD2 0x61 -#define I2C_ADDR_CPLD3 0x62 -#define CPLD3_OFFSET_QSFP_MOD_RST 0x15 -#define CPLD3_OFFSET_QSFP_LPMODE 0x16 - - -#define BIT_INDEX(i) (1ULL << (i)) - -#if 0 -static ssize_t show_status(struct device *dev, struct device_attribute *da,char *buf); -static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, char *buf); -static int as5712_54x_sfp_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int as5712_54x_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int as5712_54x_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); -#endif - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x50, I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as5712_54x_sfp_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - int port; /* Front port index */ - char eeprom[256]; /* eeprom data */ - u64 status[4]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => is_present - 1 => tx_fail - 2 => tx_disable - 3 => rx_loss */ -}; - -/* The table maps active port to cpld port. - * Array index 0 is for active port 1, - * index 1 for active port 2, and so on. - * The array content implies cpld port index. - */ -static const u8 cpld_to_front_port_table[] = -{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, - 49, 52, 50, 53, 51, 54}; - -#define CPLD_PORT_TO_FRONT_PORT(port) (cpld_to_front_port_table[port]) - -static struct as5712_54x_sfp_data *as5712_54x_sfp_update_device(struct device *dev, int update_eeprom); -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t get_lp_mode(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t set_lp_mode(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t get_mode_reset(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t set_mode_reset(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -extern int as5712_54x_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int as5712_54x_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -enum as5712_54x_sfp_sysfs_attributes { - SFP_IS_PRESENT, - SFP_TX_FAULT, - SFP_TX_DISABLE, - SFP_RX_LOSS, - SFP_PORT_NUMBER, - SFP_EEPROM, - SFP_RX_LOS_ALL, - SFP_IS_PRESENT_ALL, - SFP_LP_MODE, - SFP_MOD_RST, -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_status, NULL, SFP_IS_PRESENT); -static SENSOR_DEVICE_ATTR(sfp_tx_fault, S_IRUGO, show_status, NULL, SFP_TX_FAULT); -static SENSOR_DEVICE_ATTR(sfp_tx_disable, S_IWUSR | S_IRUGO, show_status, set_tx_disable, SFP_TX_DISABLE); -static SENSOR_DEVICE_ATTR(sfp_rx_loss, S_IRUGO, show_status,NULL, SFP_RX_LOSS); -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, SFP_PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_eeprom, S_IRUGO, show_eeprom, NULL, SFP_EEPROM); -static SENSOR_DEVICE_ATTR(sfp_rx_los_all, S_IRUGO, show_status,NULL, SFP_RX_LOS_ALL); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_status,NULL, SFP_IS_PRESENT_ALL); -static SENSOR_DEVICE_ATTR(sfp_lp_mode, S_IWUSR | S_IRUGO, get_lp_mode, set_lp_mode, SFP_LP_MODE); -static SENSOR_DEVICE_ATTR(sfp_mod_rst, S_IWUSR | S_IRUGO, get_mode_reset, set_mode_reset, SFP_MOD_RST); - -static struct attribute *as5712_54x_sfp_attributes[] = { - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_rx_loss.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - &sensor_dev_attr_sfp_eeprom.dev_attr.attr, - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los_all.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_lp_mode.dev_attr.attr, - &sensor_dev_attr_sfp_mod_rst.dev_attr.attr, - NULL -}; - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_sfp_data *data = i2c_get_clientdata(client); - - return sprintf(buf, "%d\n", CPLD_PORT_TO_FRONT_PORT(data->port)); -} - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as5712_54x_sfp_data *data; - u8 val; - int values[7]; - - /* Error-check the CPLD read results. */ -#define VALIDATED_READ(_buf, _rv, _read_expr, _invert) \ - do { \ - _rv = (_read_expr); \ - if(_rv < 0) { \ - return sprintf(_buf, "READ ERROR\n"); \ - } \ - if(_invert) { \ - _rv = ~_rv; \ - } \ - _rv &= 0xFF; \ - } while(0) - - if(attr->index == SFP_RX_LOS_ALL) { - /* - * Report the RX_LOS status for all ports. - * This does not depend on the currently active SFP selector. - */ - - /* RX_LOS Ports 1-8 */ - VALIDATED_READ(buf, values[0], as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD2, 0x0F), 0); - /* RX_LOS Ports 9-16 */ - VALIDATED_READ(buf, values[1], as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD2, 0x10), 0); - /* RX_LOS Ports 17-24 */ - VALIDATED_READ(buf, values[2], as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD2, 0x11), 0); - /* RX_LOS Ports 25-32 */ - VALIDATED_READ(buf, values[3], as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, 0x0F), 0); - /* RX_LOS Ports 33-40 */ - VALIDATED_READ(buf, values[4], as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, 0x10), 0); - /* RX_LOS Ports 41-48 */ - VALIDATED_READ(buf, values[5], as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, 0x11), 0); - - /** Return values 1 -> 48 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5]); - } - - if(attr->index == SFP_IS_PRESENT_ALL) { - /* - * Report the SFP_PRESENCE status for all ports. - * This does not depend on the currently active SFP selector. - */ - - /* SFP_PRESENT Ports 1-8 */ - VALIDATED_READ(buf, values[0], as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD2, 0x6), 1); - /* SFP_PRESENT Ports 9-16 */ - VALIDATED_READ(buf, values[1], as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD2, 0x7), 1); - /* SFP_PRESENT Ports 17-24 */ - VALIDATED_READ(buf, values[2], as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD2, 0x8), 1); - /* SFP_PRESENT Ports 25-32 */ - VALIDATED_READ(buf, values[3], as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, 0x6), 1); - /* SFP_PRESENT Ports 33-40 */ - VALIDATED_READ(buf, values[4], as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, 0x7), 1); - /* SFP_PRESENT Ports 41-48 */ - VALIDATED_READ(buf, values[5], as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, 0x8), 1); - /* QSFP_PRESENT Ports 49-54 */ - VALIDATED_READ(buf, values[6], as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, 0x14), 1); - - /* Return values 1 -> 54 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5], - values[6] & 0x3F); - } - /* - * The remaining attributes are gathered on a per-selected-sfp basis. - */ - data = as5712_54x_sfp_update_device(dev, 0); - if (attr->index == SFP_IS_PRESENT) { - val = (data->status[attr->index] & BIT_INDEX(data->port)) ? 0 : 1; - } - else { - val = (data->status[attr->index] & BIT_INDEX(data->port)) ? 1 : 0; - } - - return sprintf(buf, "%d", val); -} - -static ssize_t get_lp_mode(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_sfp_data *data = i2c_get_clientdata(client); - u8 cpld_val = 0; - int port_bit; - int status = -EINVAL; - - /* Low power mode is not supported for SFP ports(1-48) */ - if (data->port < SFP_PORT_MAX) { - return -EINVAL; - } - mutex_lock(&data->update_lock); - - port_bit = data->port - SFP_PORT_MAX; - cpld_val = as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, CPLD3_OFFSET_QSFP_LPMODE); - cpld_val = cpld_val & 0x3F; - cpld_val = cpld_val & BIT_INDEX(port_bit); - status = snprintf(buf, PAGE_SIZE - 1, "%d\r\n", cpld_val>>port_bit); - - mutex_unlock(&data->update_lock); - - return status; -} - -static ssize_t set_lp_mode(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_sfp_data *data = i2c_get_clientdata(client); - u8 cpld_val = 0; - long mode; - int error, port_bit; - - /* Tx disable is not supported for QSFP ports(49-54) */ - if (data->port < SFP_PORT_MAX) { - return -EINVAL; - } - port_bit = data->port - SFP_PORT_MAX; - error = kstrtol(buf, 10, &mode); - if (error) { - return error; - } - mutex_lock(&data->update_lock); - - cpld_val = as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, CPLD3_OFFSET_QSFP_LPMODE); - /* Update lp_mode status */ - if (mode) - { - cpld_val |= BIT_INDEX(port_bit); - } - else - { - cpld_val &=~BIT_INDEX(port_bit); - } - as5712_54x_i2c_cpld_write(I2C_ADDR_CPLD3, CPLD3_OFFSET_QSFP_LPMODE, cpld_val); - - mutex_unlock(&data->update_lock); - - return count; -} - - -static ssize_t get_mode_reset(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_sfp_data *data = i2c_get_clientdata(client); - u8 cpld_val = 0; - int port_bit; - int status = -EINVAL; - - /* Low power mode is not supported for SFP ports(1-48) */ - if (data->port < SFP_PORT_MAX) { - return -EINVAL; - } - mutex_lock(&data->update_lock); - - port_bit = data->port - SFP_PORT_MAX; - cpld_val = as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, CPLD3_OFFSET_QSFP_MOD_RST); - cpld_val = cpld_val & 0x3F; - cpld_val = cpld_val & BIT_INDEX(port_bit); - status = snprintf(buf, PAGE_SIZE - 1, "%d\r\n", cpld_val>>port_bit); - - mutex_unlock(&data->update_lock); - - return status; -} - -static ssize_t set_mode_reset(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_sfp_data *data = i2c_get_clientdata(client); - u8 cpld_val = 0; - long reset; - int error, port_bit; - - /* Tx disable is not supported for QSFP ports(49-54) */ - if (data->port < SFP_PORT_MAX) { - return -EINVAL; - } - port_bit = data->port - SFP_PORT_MAX; - error = kstrtol(buf, 10, &reset); - if (error) { - return error; - } - mutex_lock(&data->update_lock); - - cpld_val = as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, CPLD3_OFFSET_QSFP_MOD_RST); - /* Update lp_mode status */ - if (reset) - { - cpld_val |= BIT_INDEX(port_bit); - } - else - { - cpld_val &=~BIT_INDEX(port_bit); - } - as5712_54x_i2c_cpld_write(I2C_ADDR_CPLD3, CPLD3_OFFSET_QSFP_MOD_RST, cpld_val); - - mutex_unlock(&data->update_lock); - - return count; -} - - -static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_sfp_data *data = i2c_get_clientdata(client); - unsigned short cpld_addr = 0; - u8 cpld_reg = 0, cpld_val = 0, cpld_bit = 0; - long disable; - int error; - - /* Tx disable is not supported for QSFP ports(49-54) */ - if (data->port >= SFP_PORT_MAX) { - return -EINVAL; - } - - error = kstrtol(buf, 10, &disable); - if (error) { - return error; - } - - mutex_lock(&data->update_lock); - - if(data->port < 24) { - cpld_addr = I2C_ADDR_CPLD2; - cpld_reg = 0xC + data->port / 8; - cpld_bit = 1 << (data->port % 8); - } - else { - cpld_addr = I2C_ADDR_CPLD3; - cpld_reg = 0xC + (data->port - 24) / 8; - cpld_bit = 1 << (data->port % 8); - } - - cpld_val = as5712_54x_i2c_cpld_read(cpld_addr, cpld_reg); - - /* Update tx_disable status */ - if (disable) { - data->status[SFP_TX_DISABLE] |= BIT_INDEX(data->port); - cpld_val |= cpld_bit; - } - else { - data->status[SFP_TX_DISABLE] &= ~BIT_INDEX(data->port); - cpld_val &= ~cpld_bit; - } - - as5712_54x_i2c_cpld_write(cpld_addr, cpld_reg, cpld_val); - - mutex_unlock(&data->update_lock); - - return count; -} - -static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as5712_54x_sfp_data *data = as5712_54x_sfp_update_device(dev, 1); - - if (!data->valid) { - return 0; - } - - if ((data->status[SFP_IS_PRESENT] & BIT_INDEX(data->port)) != 0) { - return 0; - } - - memcpy(buf, data->eeprom, sizeof(data->eeprom)); - - return sizeof(data->eeprom); -} - -static const struct attribute_group as5712_54x_sfp_group = { - .attrs = as5712_54x_sfp_attributes, -}; - -static int as5712_54x_sfp_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as5712_54x_sfp_data *data; - int status; - - extern int platform_accton_as5712_54x(void); - if(!platform_accton_as5712_54x()) { - return -ENODEV; - } - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as5712_54x_sfp_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - i2c_set_clientdata(client, data); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as5712_54x_sfp_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: sfp '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as5712_54x_sfp_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as5712_54x_sfp_remove(struct i2c_client *client) -{ - struct as5712_54x_sfp_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as5712_54x_sfp_group); - kfree(data); - - return 0; -} - -enum port_numbers { -as5712_54x_sfp1, as5712_54x_sfp2, as5712_54x_sfp3, as5712_54x_sfp4, -as5712_54x_sfp5, as5712_54x_sfp6, as5712_54x_sfp7, as5712_54x_sfp8, -as5712_54x_sfp9, as5712_54x_sfp10, as5712_54x_sfp11,as5712_54x_sfp12, -as5712_54x_sfp13, as5712_54x_sfp14, as5712_54x_sfp15,as5712_54x_sfp16, -as5712_54x_sfp17, as5712_54x_sfp18, as5712_54x_sfp19,as5712_54x_sfp20, -as5712_54x_sfp21, as5712_54x_sfp22, as5712_54x_sfp23,as5712_54x_sfp24, -as5712_54x_sfp25, as5712_54x_sfp26, as5712_54x_sfp27,as5712_54x_sfp28, -as5712_54x_sfp29, as5712_54x_sfp30, as5712_54x_sfp31,as5712_54x_sfp32, -as5712_54x_sfp33, as5712_54x_sfp34, as5712_54x_sfp35,as5712_54x_sfp36, -as5712_54x_sfp37, as5712_54x_sfp38, as5712_54x_sfp39,as5712_54x_sfp40, -as5712_54x_sfp41, as5712_54x_sfp42, as5712_54x_sfp43,as5712_54x_sfp44, -as5712_54x_sfp45, as5712_54x_sfp46, as5712_54x_sfp47,as5712_54x_sfp48, -as5712_54x_sfp49, as5712_54x_sfp52, as5712_54x_sfp50,as5712_54x_sfp53, -as5712_54x_sfp51, as5712_54x_sfp54 -}; - -static const struct i2c_device_id as5712_54x_sfp_id[] = { -{ "as5712_54x_sfp1", as5712_54x_sfp1 }, { "as5712_54x_sfp2", as5712_54x_sfp2 }, -{ "as5712_54x_sfp3", as5712_54x_sfp3 }, { "as5712_54x_sfp4", as5712_54x_sfp4 }, -{ "as5712_54x_sfp5", as5712_54x_sfp5 }, { "as5712_54x_sfp6", as5712_54x_sfp6 }, -{ "as5712_54x_sfp7", as5712_54x_sfp7 }, { "as5712_54x_sfp8", as5712_54x_sfp8 }, -{ "as5712_54x_sfp9", as5712_54x_sfp9 }, { "as5712_54x_sfp10", as5712_54x_sfp10 }, -{ "as5712_54x_sfp11", as5712_54x_sfp11 }, { "as5712_54x_sfp12", as5712_54x_sfp12 }, -{ "as5712_54x_sfp13", as5712_54x_sfp13 }, { "as5712_54x_sfp14", as5712_54x_sfp14 }, -{ "as5712_54x_sfp15", as5712_54x_sfp15 }, { "as5712_54x_sfp16", as5712_54x_sfp16 }, -{ "as5712_54x_sfp17", as5712_54x_sfp17 }, { "as5712_54x_sfp18", as5712_54x_sfp18 }, -{ "as5712_54x_sfp19", as5712_54x_sfp19 }, { "as5712_54x_sfp20", as5712_54x_sfp20 }, -{ "as5712_54x_sfp21", as5712_54x_sfp21 }, { "as5712_54x_sfp22", as5712_54x_sfp22 }, -{ "as5712_54x_sfp23", as5712_54x_sfp23 }, { "as5712_54x_sfp24", as5712_54x_sfp24 }, -{ "as5712_54x_sfp25", as5712_54x_sfp25 }, { "as5712_54x_sfp26", as5712_54x_sfp26 }, -{ "as5712_54x_sfp27", as5712_54x_sfp27 }, { "as5712_54x_sfp28", as5712_54x_sfp28 }, -{ "as5712_54x_sfp29", as5712_54x_sfp29 }, { "as5712_54x_sfp30", as5712_54x_sfp30 }, -{ "as5712_54x_sfp31", as5712_54x_sfp31 }, { "as5712_54x_sfp32", as5712_54x_sfp32 }, -{ "as5712_54x_sfp33", as5712_54x_sfp33 }, { "as5712_54x_sfp34", as5712_54x_sfp34 }, -{ "as5712_54x_sfp35", as5712_54x_sfp35 }, { "as5712_54x_sfp36", as5712_54x_sfp36 }, -{ "as5712_54x_sfp37", as5712_54x_sfp37 }, { "as5712_54x_sfp38", as5712_54x_sfp38 }, -{ "as5712_54x_sfp39", as5712_54x_sfp39 }, { "as5712_54x_sfp40", as5712_54x_sfp40 }, -{ "as5712_54x_sfp41", as5712_54x_sfp41 }, { "as5712_54x_sfp42", as5712_54x_sfp42 }, -{ "as5712_54x_sfp43", as5712_54x_sfp43 }, { "as5712_54x_sfp44", as5712_54x_sfp44 }, -{ "as5712_54x_sfp45", as5712_54x_sfp45 }, { "as5712_54x_sfp46", as5712_54x_sfp46 }, -{ "as5712_54x_sfp47", as5712_54x_sfp47 }, { "as5712_54x_sfp48", as5712_54x_sfp48 }, -{ "as5712_54x_sfp49", as5712_54x_sfp49 }, { "as5712_54x_sfp50", as5712_54x_sfp50 }, -{ "as5712_54x_sfp51", as5712_54x_sfp51 }, { "as5712_54x_sfp52", as5712_54x_sfp52 }, -{ "as5712_54x_sfp53", as5712_54x_sfp53 }, { "as5712_54x_sfp54", as5712_54x_sfp54 }, - -{} -}; -MODULE_DEVICE_TABLE(i2c, as5712_54x_sfp_id); - -static struct i2c_driver as5712_54x_sfp_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as5712_54x_sfp", - }, - .probe = as5712_54x_sfp_probe, - .remove = as5712_54x_sfp_remove, - .id_table = as5712_54x_sfp_id, - .address_list = normal_i2c, -}; - -static int as5712_54x_sfp_read_byte(struct i2c_client *client, u8 command, u8 *data) -{ - int result = i2c_smbus_read_byte_data(client, command); - - if (unlikely(result < 0)) { - dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, result); - goto abort; - } - - *data = (u8)result; - result = 0; - -abort: - return result; -} - -#define ALWAYS_UPDATE_DEVICE 1 - -static struct as5712_54x_sfp_data *as5712_54x_sfp_update_device(struct device *dev, int update_eeprom) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_sfp_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (ALWAYS_UPDATE_DEVICE || time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int status = -1; - int i = 0, j = 0; - - data->valid = 0; - //dev_dbg(&client->dev, "Starting as5712_54x sfp status update\n"); - memset(data->status, 0, sizeof(data->status)); - - /* Read status of port 1~48(SFP port) */ - for (i = 0; i < 2; i++) { - for (j = 0; j < 12; j++) { - status = as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD2+i, 0x6+j); - - if (status < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", I2C_ADDR_CPLD2+i, 0x6+j, status); - goto exit; - } - - data->status[j/3] |= (u64)status << ((i*24) + (j%3)*8); - } - } - - /* - * Bring QSFPs out of reset, - * This is a temporary fix until the QSFP+_MOD_RST register - * can be exposed through the driver. - */ - as5712_54x_i2c_cpld_write(I2C_ADDR_CPLD3, 0x15, 0x3F); - - /* Read present status of port 49-54(QSFP port) */ - status = as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, 0x14); - - if (status < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", I2C_ADDR_CPLD2+i, 0x6+j, status); - } - else { - data->status[SFP_IS_PRESENT] |= (u64)status << 48; - } - - if (update_eeprom) { - /* Read eeprom data based on port number */ - memset(data->eeprom, 0, sizeof(data->eeprom)); - - /* Check if the port is present */ - if ((data->status[SFP_IS_PRESENT] & BIT_INDEX(data->port)) == 0) { - /* read eeprom */ - for (i = 0; i < sizeof(data->eeprom); i++) { - status = as5712_54x_sfp_read_byte(client, i, data->eeprom + i); - - if (status < 0) { - dev_dbg(&client->dev, "unable to read eeprom from port(%d)\n", - CPLD_PORT_TO_FRONT_PORT(data->port)); - goto exit; - } - } - } - } - - data->valid = 1; - data->last_updated = jiffies; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -module_i2c_driver(as5712_54x_sfp_driver); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as5712_54x_sfp driver"); -MODULE_LICENSE("GPL"); - -#if 0 - int i = 0, j = 0; - - data->valid = 0; - //dev_dbg(&client->dev, "Starting as5712_54x sfp update\n"); - memset(data->status, 0, sizeof(data->status)); - - /* Read status of port 1~48(SFP port) */ - for (i = 0; i < 2; i++) { - for (j = 0; j < 12; j++) { - status = as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD2+i, 0x6+j); - - if (status < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", I2C_ADDR_CPLD2+i, 0x6+j, status); - continue; - } - - data->status[j/3] |= (u64)status << ((i*24) + (j%3)*8); - } - } - - /* Read present status of port 49-54(QSFP port) */ - status = as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, 0x14); - - if (status < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", I2C_ADDR_CPLD2+i, 0x6+j, status); - } - else { - data->status[SFP_IS_PRESENT] |= (u64)status << 48; - } -#endif - -/* Reserver to prevent from CPLD port mapping is changed - */ -#if 0 -BIT_INDEX(port_present_index[data->port]) -/* The bit index of is_present field read from CPLD - * Array index 0 is for as5712_54x_sfp1, - * index 1 is for as5712_54x_sfp2, and so on. - */ -static const int port_present_index[] = { - 4, 5, 6, 7, 9, 8, 11, 10, - 0, 1, 2, 3, 12, 13, 14, 15, -16, 17, 18, 19, 28, 29, 30, 31, -20, 21, 22, 23, 24, 25, 26, 27 -}; -#endif - -#if 0 -static struct as5712_54x_sfp_data *as5712_54x_sfp_update_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_sfp_data *data = i2c_get_clientdata(client); - int status = -1; - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->status_last_updated + HZ + HZ / 2) - || !data->status_valid) { - int status = -1; - int i = 0, j = 0; - - data->status_valid = 0; - //dev_dbg(&client->dev, "Starting as5712_54x sfp status update\n"); - memset(data->status, 0, sizeof(data->status)); - - /* Read status of port 1~48(SFP port) */ - for (i = 0; i < 2; i++) { - for (j = 0; j < 12; j++) { - status = as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD2+i, 0x6+j); - - if (status < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", I2C_ADDR_CPLD2+i, 0x6+j, status); - goto exit; - } - - data->status[j/3] |= (u64)status << ((i*24) + (j%3)*8); - } - } - - /* - * Bring QSFPs out of reset, - * This is a temporary fix until the QSFP+_MOD_RST register - * can be exposed through the driver. - */ - as5712_54x_i2c_cpld_write(I2C_ADDR_CPLD3, 0x15, 0x3F); - - /* Read present status of port 49-54(QSFP port) */ - status = as5712_54x_i2c_cpld_read(I2C_ADDR_CPLD3, 0x14); - - if (status < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", I2C_ADDR_CPLD2+i, 0x6+j, status); - } - else { - data->status[SFP_IS_PRESENT] |= (u64)status << 48; - } - - data->status_valid = 1; - data->status_last_updated = jiffies; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -static struct as5712_54x_sfp_data *as5712_54x_sfp_update_eeprom(struct device *dev) -{ - struct as5712_54x_sfp_data *data = NULL; - - data = as5712_54x_sfp_update_status(dev); - - if (data == NULL || data->status_valid == 0) { - data->eeprom_valid = 0; - return data; - } - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->eeprom_last_updated + HZ + HZ / 2) - || !data->eeprom_valid) { - int status = -1; - int i = 0; - - /* Read eeprom data based on port number */ - memset(data->eeprom, 0, sizeof(data->eeprom)); - - /* Check if the port is present */ - if ((data->status[SFP_IS_PRESENT] & BIT_INDEX(data->port)) == 0) { - /* read eeprom */ - for (i = 0; i < sizeof(data->eeprom)/I2C_SMBUS_BLOCK_MAX; i++) { - status = as5712_54x_sfp_read_block(client, i*I2C_SMBUS_BLOCK_MAX, - data->eeprom+(i*I2C_SMBUS_BLOCK_MAX), - I2C_SMBUS_BLOCK_MAX); - if (status < 0) { - dev_dbg(&client->dev, "unable to read eeprom from port(%d)\n", - CPLD_PORT_TO_FRONT_PORT(data->port)); - goto exit; - } - } - } - - data->eeprom_last_updated = jiffies; - data->eeprom_valid = 1; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} -#endif diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/cpr_4011_4mxx.c b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/cpr_4011_4mxx.c deleted file mode 100755 index 30bea914d589..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/cpr_4011_4mxx.c +++ /dev/null @@ -1,400 +0,0 @@ -/* - * An hwmon driver for the CPR-4011-4Mxx Redundant Power Module - * - * Copyright (C) Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#if 0 -#define DEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_FAN_DUTY_CYCLE 100 - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x3c, 0x3d, 0x3e, 0x3f, I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct cpr_4011_4mxx_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 vout_mode; /* Register value */ - u16 v_in; /* Register value */ - u16 v_out; /* Register value */ - u16 i_in; /* Register value */ - u16 i_out; /* Register value */ - u16 p_in; /* Register value */ - u16 p_out; /* Register value */ - u16 temp_input[2]; /* Register value */ - u8 fan_fault; /* Register value */ - u16 fan_duty_cycle[2]; /* Register value */ - u16 fan_speed[2]; /* Register value */ -}; - -static ssize_t show_linear(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_vout(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_fan_duty_cycle(struct device *dev, struct device_attribute *da, const char *buf, size_t count); -static int cpr_4011_4mxx_write_word(struct i2c_client *client, u8 reg, u16 value); -static struct cpr_4011_4mxx_data *cpr_4011_4mxx_update_device(struct device *dev); - -enum cpr_4011_4mxx_sysfs_attributes { - PSU_V_IN, - PSU_V_OUT, - PSU_I_IN, - PSU_I_OUT, - PSU_P_IN, - PSU_P_OUT, - PSU_TEMP1_INPUT, - PSU_FAN1_FAULT, - PSU_FAN1_DUTY_CYCLE, - PSU_FAN1_SPEED, -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_v_in, S_IRUGO, show_linear, NULL, PSU_V_IN); -static SENSOR_DEVICE_ATTR(psu_v_out, S_IRUGO, show_vout, NULL, PSU_V_OUT); -static SENSOR_DEVICE_ATTR(psu_i_in, S_IRUGO, show_linear, NULL, PSU_I_IN); -static SENSOR_DEVICE_ATTR(psu_i_out, S_IRUGO, show_linear, NULL, PSU_I_OUT); -static SENSOR_DEVICE_ATTR(psu_p_in, S_IRUGO, show_linear, NULL, PSU_P_IN); -static SENSOR_DEVICE_ATTR(psu_p_out, S_IRUGO, show_linear, NULL, PSU_P_OUT); -static SENSOR_DEVICE_ATTR(psu_temp1_input, S_IRUGO, show_linear, NULL, PSU_TEMP1_INPUT); -static SENSOR_DEVICE_ATTR(psu_fan1_fault, S_IRUGO, show_fan_fault, NULL, PSU_FAN1_FAULT); -static SENSOR_DEVICE_ATTR(psu_fan1_duty_cycle_percentage, S_IWUSR | S_IRUGO, show_linear, set_fan_duty_cycle, PSU_FAN1_DUTY_CYCLE); -static SENSOR_DEVICE_ATTR(psu_fan1_speed_rpm, S_IRUGO, show_linear, NULL, PSU_FAN1_SPEED); - -static struct attribute *cpr_4011_4mxx_attributes[] = { - &sensor_dev_attr_psu_v_in.dev_attr.attr, - &sensor_dev_attr_psu_v_out.dev_attr.attr, - &sensor_dev_attr_psu_i_in.dev_attr.attr, - &sensor_dev_attr_psu_i_out.dev_attr.attr, - &sensor_dev_attr_psu_p_in.dev_attr.attr, - &sensor_dev_attr_psu_p_out.dev_attr.attr, - &sensor_dev_attr_psu_temp1_input.dev_attr.attr, - &sensor_dev_attr_psu_fan1_fault.dev_attr.attr, - &sensor_dev_attr_psu_fan1_duty_cycle_percentage.dev_attr.attr, - &sensor_dev_attr_psu_fan1_speed_rpm.dev_attr.attr, - NULL -}; - -static int two_complement_to_int(u16 data, u8 valid_bit, int mask) -{ - u16 valid_data = data & mask; - bool is_negative = valid_data >> (valid_bit - 1); - - return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data; -} - -static ssize_t set_fan_duty_cycle(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 cpr_4011_4mxx_data *data = i2c_get_clientdata(client); - int nr = (attr->index == PSU_FAN1_DUTY_CYCLE) ? 0 : 1; - long speed; - int error; - - error = kstrtol(buf, 10, &speed); - if (error) - return error; - - if (speed < 0 || speed > MAX_FAN_DUTY_CYCLE) - return -EINVAL; - - mutex_lock(&data->update_lock); - data->fan_duty_cycle[nr] = speed; - cpr_4011_4mxx_write_word(client, 0x3B + nr, data->fan_duty_cycle[nr]); - mutex_unlock(&data->update_lock); - - return count; -} - -static ssize_t show_linear(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct cpr_4011_4mxx_data *data = cpr_4011_4mxx_update_device(dev); - - u16 value = 0; - int exponent, mantissa; - int multiplier = 1000; - - switch (attr->index) { - case PSU_V_IN: - value = data->v_in; - break; - case PSU_I_IN: - value = data->i_in; - break; - case PSU_I_OUT: - value = data->i_out; - break; - case PSU_P_IN: - value = data->p_in; - break; - case PSU_P_OUT: - value = data->p_out; - break; - case PSU_TEMP1_INPUT: - value = data->temp_input[0]; - break; - case PSU_FAN1_DUTY_CYCLE: - multiplier = 1; - value = data->fan_duty_cycle[0]; - break; - case PSU_FAN1_SPEED: - multiplier = 1; - value = data->fan_speed[0]; - break; - default: - break; - } - - exponent = two_complement_to_int(value >> 11, 5, 0x1f); - mantissa = two_complement_to_int(value & 0x7ff, 11, 0x7ff); - - return (exponent >= 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : - sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); -} - -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct cpr_4011_4mxx_data *data = cpr_4011_4mxx_update_device(dev); - - u8 shift = (attr->index == PSU_FAN1_FAULT) ? 7 : 6; - - return sprintf(buf, "%d\n", data->fan_fault >> shift); -} - -static ssize_t show_vout(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct cpr_4011_4mxx_data *data = cpr_4011_4mxx_update_device(dev); - int exponent, mantissa; - int multiplier = 1000; - - exponent = two_complement_to_int(data->vout_mode, 5, 0x1f); - mantissa = data->v_out; - - return (exponent > 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : - sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); -} - -static const struct attribute_group cpr_4011_4mxx_group = { - .attrs = cpr_4011_4mxx_attributes, -}; - -static int cpr_4011_4mxx_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct cpr_4011_4mxx_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct cpr_4011_4mxx_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &cpr_4011_4mxx_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &cpr_4011_4mxx_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int cpr_4011_4mxx_remove(struct i2c_client *client) -{ - struct cpr_4011_4mxx_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &cpr_4011_4mxx_group); - kfree(data); - - return 0; -} - -static const struct i2c_device_id cpr_4011_4mxx_id[] = { - { "cpr_4011_4mxx", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, cpr_4011_4mxx_id); - -static struct i2c_driver cpr_4011_4mxx_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "cpr_4011_4mxx", - }, - .probe = cpr_4011_4mxx_probe, - .remove = cpr_4011_4mxx_remove, - .id_table = cpr_4011_4mxx_id, - .address_list = normal_i2c, -}; - -static int cpr_4011_4mxx_read_byte(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_byte_data(client, reg); -} - -static int cpr_4011_4mxx_read_word(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_word_data(client, reg); -} - -static int cpr_4011_4mxx_write_word(struct i2c_client *client, u8 reg, u16 value) -{ - return i2c_smbus_write_word_data(client, reg, value); -} - -struct reg_data_byte { - u8 reg; - u8 *value; -}; - -struct reg_data_word { - u8 reg; - u16 *value; -}; - -static struct cpr_4011_4mxx_data *cpr_4011_4mxx_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct cpr_4011_4mxx_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int i, status; - struct reg_data_byte regs_byte[] = { {0x20, &data->vout_mode}, - {0x81, &data->fan_fault}}; - struct reg_data_word regs_word[] = { {0x88, &data->v_in}, - {0x8b, &data->v_out}, - {0x89, &data->i_in}, - {0x8c, &data->i_out}, - {0x96, &data->p_out}, - {0x97, &data->p_in}, - {0x8d, &(data->temp_input[0])}, - {0x8e, &(data->temp_input[1])}, - {0x3b, &(data->fan_duty_cycle[0])}, - {0x3c, &(data->fan_duty_cycle[1])}, - {0x90, &(data->fan_speed[0])}, - {0x91, &(data->fan_speed[1])}}; - - dev_dbg(&client->dev, "Starting cpr_4011_4mxx update\n"); - - /* Read byte data */ - for (i = 0; i < ARRAY_SIZE(regs_byte); i++) { - status = cpr_4011_4mxx_read_byte(client, regs_byte[i].reg); - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_byte[i].reg, status); - } - else { - *(regs_byte[i].value) = status; - } - } - - /* Read word data */ - for (i = 0; i < ARRAY_SIZE(regs_word); i++) { - status = cpr_4011_4mxx_read_word(client, regs_word[i].reg); - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_word[i].reg, status); - } - else { - *(regs_word[i].value) = status; - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init cpr_4011_4mxx_init(void) -{ - return i2c_add_driver(&cpr_4011_4mxx_driver); -} - -static void __exit cpr_4011_4mxx_exit(void) -{ - i2c_del_driver(&cpr_4011_4mxx_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("CPR_4011_4MXX driver"); -MODULE_LICENSE("GPL"); - -module_init(cpr_4011_4mxx_init); -module_exit(cpr_4011_4mxx_exit); diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/i2c-mux-accton_as5712_54x_cpld.c b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/i2c-mux-accton_as5712_54x_cpld.c deleted file mode 100755 index d63cb14b5a67..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/i2c-mux-accton_as5712_54x_cpld.c +++ /dev/null @@ -1,1517 +0,0 @@ -/* - * I2C multiplexer - * - * Copyright (C) Brandon Chuang - * - * This module supports the accton cpld that hold the channel select - * mechanism for other i2c slave devices, such as SFP. - * This includes the: - * Accton as5712_54x CPLD1/CPLD2/CPLD3 - * - * Based on: - * pca954x.c from Kumar Gala - * Copyright (C) 2006 - * - * Based on: - * pca954x.c from Ken Harrenstien - * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) - * - * Based on: - * i2c-virtual_cb.c from Brian Kuschak - * and - * pca9540.c from Jean Delvare . - * - * 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. - */ -#if 0 -#define DEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define I2C_RW_RETRY_COUNT 10 -#define I2C_RW_RETRY_INTERVAL 60 /* ms */ - -#define NUM_OF_CPLD1_CHANS 0x0 -#define NUM_OF_CPLD2_CHANS 0x18 -#define NUM_OF_CPLD3_CHANS 0x1E -#define CPLD_CHANNEL_SELECT_REG 0x2 -#define CPLD_DESELECT_CHANNEL 0xFF - -#if 0 -#define NUM_OF_ALL_CPLD_CHANS (NUM_OF_CPLD2_CHANS + NUM_OF_CPLD3_CHANS) -#endif - -#define ACCTON_I2C_CPLD_MUX_MAX_NCHANS NUM_OF_CPLD3_CHANS - -static LIST_HEAD(cpld_client_list); -static struct mutex list_lock; - -struct cpld_client_node { - struct i2c_client *client; - struct list_head list; -}; - -enum cpld_mux_type { - as5712_54x_cpld2, - as5712_54x_cpld3, - as5712_54x_cpld1 -}; - -struct as5712_54x_cpld_data { - enum cpld_mux_type type; - struct i2c_adapter *virt_adaps[ACCTON_I2C_CPLD_MUX_MAX_NCHANS]; - u8 last_chan; /* last register value */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0) - struct i2c_client *client; - struct i2c_mux_core *muxc; -#endif - struct device *hwmon_dev; - struct mutex update_lock; -}; - -#if 0 -/* The mapping table between mux index and adapter index - array index : the mux index - the content : adapter index - */ -static int mux_adap_map[NUM_OF_ALL_CPLD_CHANS]; -#endif - -struct chip_desc { - u8 nchans; - u8 deselectChan; -}; - -/* Provide specs for the PCA954x types we know about */ -static const struct chip_desc chips[] = { - [as5712_54x_cpld1] = { - .nchans = NUM_OF_CPLD1_CHANS, - .deselectChan = CPLD_DESELECT_CHANNEL, - }, - [as5712_54x_cpld2] = { - .nchans = NUM_OF_CPLD2_CHANS, - .deselectChan = CPLD_DESELECT_CHANNEL, - }, - [as5712_54x_cpld3] = { - .nchans = NUM_OF_CPLD3_CHANS, - .deselectChan = CPLD_DESELECT_CHANNEL, - } -}; - -static const struct i2c_device_id as5712_54x_cpld_mux_id[] = { - { "as5712_54x_cpld1", as5712_54x_cpld1 }, - { "as5712_54x_cpld2", as5712_54x_cpld2 }, - { "as5712_54x_cpld3", as5712_54x_cpld3 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, as5712_54x_cpld_mux_id); - -#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index -#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index -#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index -#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index -#define TRANSCEIVER_LPMODE_ATTR_ID(index) MODULE_LPMODE_##index -#define TRANSCEIVER_RESET_ATTR_ID(index) MODULE_RESET_##index - -enum as5712_54x_cpld1_sysfs_attributes { - CPLD_VERSION, - ACCESS, - MODULE_PRESENT_ALL, - MODULE_RXLOS_ALL, - /* transceiver attributes */ - TRANSCEIVER_PRESENT_ATTR_ID(1), - TRANSCEIVER_PRESENT_ATTR_ID(2), - TRANSCEIVER_PRESENT_ATTR_ID(3), - TRANSCEIVER_PRESENT_ATTR_ID(4), - TRANSCEIVER_PRESENT_ATTR_ID(5), - TRANSCEIVER_PRESENT_ATTR_ID(6), - TRANSCEIVER_PRESENT_ATTR_ID(7), - TRANSCEIVER_PRESENT_ATTR_ID(8), - TRANSCEIVER_PRESENT_ATTR_ID(9), - TRANSCEIVER_PRESENT_ATTR_ID(10), - TRANSCEIVER_PRESENT_ATTR_ID(11), - TRANSCEIVER_PRESENT_ATTR_ID(12), - TRANSCEIVER_PRESENT_ATTR_ID(13), - TRANSCEIVER_PRESENT_ATTR_ID(14), - TRANSCEIVER_PRESENT_ATTR_ID(15), - TRANSCEIVER_PRESENT_ATTR_ID(16), - TRANSCEIVER_PRESENT_ATTR_ID(17), - TRANSCEIVER_PRESENT_ATTR_ID(18), - TRANSCEIVER_PRESENT_ATTR_ID(19), - TRANSCEIVER_PRESENT_ATTR_ID(20), - TRANSCEIVER_PRESENT_ATTR_ID(21), - TRANSCEIVER_PRESENT_ATTR_ID(22), - TRANSCEIVER_PRESENT_ATTR_ID(23), - TRANSCEIVER_PRESENT_ATTR_ID(24), - TRANSCEIVER_PRESENT_ATTR_ID(25), - TRANSCEIVER_PRESENT_ATTR_ID(26), - TRANSCEIVER_PRESENT_ATTR_ID(27), - TRANSCEIVER_PRESENT_ATTR_ID(28), - TRANSCEIVER_PRESENT_ATTR_ID(29), - TRANSCEIVER_PRESENT_ATTR_ID(30), - TRANSCEIVER_PRESENT_ATTR_ID(31), - TRANSCEIVER_PRESENT_ATTR_ID(32), - TRANSCEIVER_PRESENT_ATTR_ID(33), - TRANSCEIVER_PRESENT_ATTR_ID(34), - TRANSCEIVER_PRESENT_ATTR_ID(35), - TRANSCEIVER_PRESENT_ATTR_ID(36), - TRANSCEIVER_PRESENT_ATTR_ID(37), - TRANSCEIVER_PRESENT_ATTR_ID(38), - TRANSCEIVER_PRESENT_ATTR_ID(39), - TRANSCEIVER_PRESENT_ATTR_ID(40), - TRANSCEIVER_PRESENT_ATTR_ID(41), - TRANSCEIVER_PRESENT_ATTR_ID(42), - TRANSCEIVER_PRESENT_ATTR_ID(43), - TRANSCEIVER_PRESENT_ATTR_ID(44), - TRANSCEIVER_PRESENT_ATTR_ID(45), - TRANSCEIVER_PRESENT_ATTR_ID(46), - TRANSCEIVER_PRESENT_ATTR_ID(47), - TRANSCEIVER_PRESENT_ATTR_ID(48), - TRANSCEIVER_PRESENT_ATTR_ID(49), - TRANSCEIVER_PRESENT_ATTR_ID(50), - TRANSCEIVER_PRESENT_ATTR_ID(51), - TRANSCEIVER_PRESENT_ATTR_ID(52), - TRANSCEIVER_PRESENT_ATTR_ID(53), - TRANSCEIVER_PRESENT_ATTR_ID(54), - TRANSCEIVER_TXDISABLE_ATTR_ID(1), - TRANSCEIVER_TXDISABLE_ATTR_ID(2), - TRANSCEIVER_TXDISABLE_ATTR_ID(3), - TRANSCEIVER_TXDISABLE_ATTR_ID(4), - TRANSCEIVER_TXDISABLE_ATTR_ID(5), - TRANSCEIVER_TXDISABLE_ATTR_ID(6), - TRANSCEIVER_TXDISABLE_ATTR_ID(7), - TRANSCEIVER_TXDISABLE_ATTR_ID(8), - TRANSCEIVER_TXDISABLE_ATTR_ID(9), - TRANSCEIVER_TXDISABLE_ATTR_ID(10), - TRANSCEIVER_TXDISABLE_ATTR_ID(11), - TRANSCEIVER_TXDISABLE_ATTR_ID(12), - TRANSCEIVER_TXDISABLE_ATTR_ID(13), - TRANSCEIVER_TXDISABLE_ATTR_ID(14), - TRANSCEIVER_TXDISABLE_ATTR_ID(15), - TRANSCEIVER_TXDISABLE_ATTR_ID(16), - TRANSCEIVER_TXDISABLE_ATTR_ID(17), - TRANSCEIVER_TXDISABLE_ATTR_ID(18), - TRANSCEIVER_TXDISABLE_ATTR_ID(19), - TRANSCEIVER_TXDISABLE_ATTR_ID(20), - TRANSCEIVER_TXDISABLE_ATTR_ID(21), - TRANSCEIVER_TXDISABLE_ATTR_ID(22), - TRANSCEIVER_TXDISABLE_ATTR_ID(23), - TRANSCEIVER_TXDISABLE_ATTR_ID(24), - TRANSCEIVER_TXDISABLE_ATTR_ID(25), - TRANSCEIVER_TXDISABLE_ATTR_ID(26), - TRANSCEIVER_TXDISABLE_ATTR_ID(27), - TRANSCEIVER_TXDISABLE_ATTR_ID(28), - TRANSCEIVER_TXDISABLE_ATTR_ID(29), - TRANSCEIVER_TXDISABLE_ATTR_ID(30), - TRANSCEIVER_TXDISABLE_ATTR_ID(31), - TRANSCEIVER_TXDISABLE_ATTR_ID(32), - TRANSCEIVER_TXDISABLE_ATTR_ID(33), - TRANSCEIVER_TXDISABLE_ATTR_ID(34), - TRANSCEIVER_TXDISABLE_ATTR_ID(35), - TRANSCEIVER_TXDISABLE_ATTR_ID(36), - TRANSCEIVER_TXDISABLE_ATTR_ID(37), - TRANSCEIVER_TXDISABLE_ATTR_ID(38), - TRANSCEIVER_TXDISABLE_ATTR_ID(39), - TRANSCEIVER_TXDISABLE_ATTR_ID(40), - TRANSCEIVER_TXDISABLE_ATTR_ID(41), - TRANSCEIVER_TXDISABLE_ATTR_ID(42), - TRANSCEIVER_TXDISABLE_ATTR_ID(43), - TRANSCEIVER_TXDISABLE_ATTR_ID(44), - TRANSCEIVER_TXDISABLE_ATTR_ID(45), - TRANSCEIVER_TXDISABLE_ATTR_ID(46), - TRANSCEIVER_TXDISABLE_ATTR_ID(47), - TRANSCEIVER_TXDISABLE_ATTR_ID(48), - TRANSCEIVER_RXLOS_ATTR_ID(1), - TRANSCEIVER_RXLOS_ATTR_ID(2), - TRANSCEIVER_RXLOS_ATTR_ID(3), - TRANSCEIVER_RXLOS_ATTR_ID(4), - TRANSCEIVER_RXLOS_ATTR_ID(5), - TRANSCEIVER_RXLOS_ATTR_ID(6), - TRANSCEIVER_RXLOS_ATTR_ID(7), - TRANSCEIVER_RXLOS_ATTR_ID(8), - TRANSCEIVER_RXLOS_ATTR_ID(9), - TRANSCEIVER_RXLOS_ATTR_ID(10), - TRANSCEIVER_RXLOS_ATTR_ID(11), - TRANSCEIVER_RXLOS_ATTR_ID(12), - TRANSCEIVER_RXLOS_ATTR_ID(13), - TRANSCEIVER_RXLOS_ATTR_ID(14), - TRANSCEIVER_RXLOS_ATTR_ID(15), - TRANSCEIVER_RXLOS_ATTR_ID(16), - TRANSCEIVER_RXLOS_ATTR_ID(17), - TRANSCEIVER_RXLOS_ATTR_ID(18), - TRANSCEIVER_RXLOS_ATTR_ID(19), - TRANSCEIVER_RXLOS_ATTR_ID(20), - TRANSCEIVER_RXLOS_ATTR_ID(21), - TRANSCEIVER_RXLOS_ATTR_ID(22), - TRANSCEIVER_RXLOS_ATTR_ID(23), - TRANSCEIVER_RXLOS_ATTR_ID(24), - TRANSCEIVER_RXLOS_ATTR_ID(25), - TRANSCEIVER_RXLOS_ATTR_ID(26), - TRANSCEIVER_RXLOS_ATTR_ID(27), - TRANSCEIVER_RXLOS_ATTR_ID(28), - TRANSCEIVER_RXLOS_ATTR_ID(29), - TRANSCEIVER_RXLOS_ATTR_ID(30), - TRANSCEIVER_RXLOS_ATTR_ID(31), - TRANSCEIVER_RXLOS_ATTR_ID(32), - TRANSCEIVER_RXLOS_ATTR_ID(33), - TRANSCEIVER_RXLOS_ATTR_ID(34), - TRANSCEIVER_RXLOS_ATTR_ID(35), - TRANSCEIVER_RXLOS_ATTR_ID(36), - TRANSCEIVER_RXLOS_ATTR_ID(37), - TRANSCEIVER_RXLOS_ATTR_ID(38), - TRANSCEIVER_RXLOS_ATTR_ID(39), - TRANSCEIVER_RXLOS_ATTR_ID(40), - TRANSCEIVER_RXLOS_ATTR_ID(41), - TRANSCEIVER_RXLOS_ATTR_ID(42), - TRANSCEIVER_RXLOS_ATTR_ID(43), - TRANSCEIVER_RXLOS_ATTR_ID(44), - TRANSCEIVER_RXLOS_ATTR_ID(45), - TRANSCEIVER_RXLOS_ATTR_ID(46), - TRANSCEIVER_RXLOS_ATTR_ID(47), - TRANSCEIVER_RXLOS_ATTR_ID(48), - TRANSCEIVER_TXFAULT_ATTR_ID(1), - TRANSCEIVER_TXFAULT_ATTR_ID(2), - TRANSCEIVER_TXFAULT_ATTR_ID(3), - TRANSCEIVER_TXFAULT_ATTR_ID(4), - TRANSCEIVER_TXFAULT_ATTR_ID(5), - TRANSCEIVER_TXFAULT_ATTR_ID(6), - TRANSCEIVER_TXFAULT_ATTR_ID(7), - TRANSCEIVER_TXFAULT_ATTR_ID(8), - TRANSCEIVER_TXFAULT_ATTR_ID(9), - TRANSCEIVER_TXFAULT_ATTR_ID(10), - TRANSCEIVER_TXFAULT_ATTR_ID(11), - TRANSCEIVER_TXFAULT_ATTR_ID(12), - TRANSCEIVER_TXFAULT_ATTR_ID(13), - TRANSCEIVER_TXFAULT_ATTR_ID(14), - TRANSCEIVER_TXFAULT_ATTR_ID(15), - TRANSCEIVER_TXFAULT_ATTR_ID(16), - TRANSCEIVER_TXFAULT_ATTR_ID(17), - TRANSCEIVER_TXFAULT_ATTR_ID(18), - TRANSCEIVER_TXFAULT_ATTR_ID(19), - TRANSCEIVER_TXFAULT_ATTR_ID(20), - TRANSCEIVER_TXFAULT_ATTR_ID(21), - TRANSCEIVER_TXFAULT_ATTR_ID(22), - TRANSCEIVER_TXFAULT_ATTR_ID(23), - TRANSCEIVER_TXFAULT_ATTR_ID(24), - TRANSCEIVER_TXFAULT_ATTR_ID(25), - TRANSCEIVER_TXFAULT_ATTR_ID(26), - TRANSCEIVER_TXFAULT_ATTR_ID(27), - TRANSCEIVER_TXFAULT_ATTR_ID(28), - TRANSCEIVER_TXFAULT_ATTR_ID(29), - TRANSCEIVER_TXFAULT_ATTR_ID(30), - TRANSCEIVER_TXFAULT_ATTR_ID(31), - TRANSCEIVER_TXFAULT_ATTR_ID(32), - TRANSCEIVER_TXFAULT_ATTR_ID(33), - TRANSCEIVER_TXFAULT_ATTR_ID(34), - TRANSCEIVER_TXFAULT_ATTR_ID(35), - TRANSCEIVER_TXFAULT_ATTR_ID(36), - TRANSCEIVER_TXFAULT_ATTR_ID(37), - TRANSCEIVER_TXFAULT_ATTR_ID(38), - TRANSCEIVER_TXFAULT_ATTR_ID(39), - TRANSCEIVER_TXFAULT_ATTR_ID(40), - TRANSCEIVER_TXFAULT_ATTR_ID(41), - TRANSCEIVER_TXFAULT_ATTR_ID(42), - TRANSCEIVER_TXFAULT_ATTR_ID(43), - TRANSCEIVER_TXFAULT_ATTR_ID(44), - TRANSCEIVER_TXFAULT_ATTR_ID(45), - TRANSCEIVER_TXFAULT_ATTR_ID(46), - TRANSCEIVER_TXFAULT_ATTR_ID(47), - TRANSCEIVER_TXFAULT_ATTR_ID(48), - TRANSCEIVER_LPMODE_ATTR_ID(49), - TRANSCEIVER_LPMODE_ATTR_ID(50), - TRANSCEIVER_LPMODE_ATTR_ID(51), - TRANSCEIVER_LPMODE_ATTR_ID(52), - TRANSCEIVER_LPMODE_ATTR_ID(53), - TRANSCEIVER_LPMODE_ATTR_ID(54), - TRANSCEIVER_RESET_ATTR_ID(49), - TRANSCEIVER_RESET_ATTR_ID(50), - TRANSCEIVER_RESET_ATTR_ID(51), - TRANSCEIVER_RESET_ATTR_ID(52), - TRANSCEIVER_RESET_ATTR_ID(53), - TRANSCEIVER_RESET_ATTR_ID(54), -}; - -/* sysfs attributes for hwmon - */ -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_present_all(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t set_lp_mode(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t set_mode_reset(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t show_version(struct device *dev, struct device_attribute *da, - char *buf); -static int as5712_54x_cpld_read_internal(struct i2c_client *client, u8 reg); -static int as5712_54x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); - -/* transceiver attributes */ -#define DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(index) \ - static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index) -#define DECLARE_TRANSCEIVER_PRESENT_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr - -#define DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ - static SENSOR_DEVICE_ATTR(module_tx_disable_##index, S_IRUGO | S_IWUSR, show_status, set_tx_disable, MODULE_TXDISABLE_##index); \ - static SENSOR_DEVICE_ATTR(module_rx_los_##index, S_IRUGO, show_status, NULL, MODULE_RXLOS_##index); \ - static SENSOR_DEVICE_ATTR(module_tx_fault_##index, S_IRUGO, show_status, NULL, MODULE_TXFAULT_##index) - -#define DECLARE_SFP_TRANSCEIVER_ATTR(index) \ - &sensor_dev_attr_module_tx_disable_##index.dev_attr.attr, \ - &sensor_dev_attr_module_rx_los_##index.dev_attr.attr, \ - &sensor_dev_attr_module_tx_fault_##index.dev_attr.attr - -#define DECLARE_QSFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ - static SENSOR_DEVICE_ATTR(module_lp_mode_##index, S_IRUGO | S_IWUSR, show_status, set_lp_mode, MODULE_LPMODE_##index); \ - static SENSOR_DEVICE_ATTR(module_reset_##index, S_IWUSR | S_IRUGO, show_status, set_mode_reset, MODULE_RESET_##index) - -#define DECLARE_QSFP_TRANSCEIVER_ATTR(index) \ - &sensor_dev_attr_module_lp_mode_##index.dev_attr.attr, \ - &sensor_dev_attr_module_reset_##index.dev_attr.attr - - -static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); -static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); -/* transceiver attributes */ -static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); -static SENSOR_DEVICE_ATTR(module_rx_los_all, S_IRUGO, show_rxlos_all, NULL, MODULE_RXLOS_ALL); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(1); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(2); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(3); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(4); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(5); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(6); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(7); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(8); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(9); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(10); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(11); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(12); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(13); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(14); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(15); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(16); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(17); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(18); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(19); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(20); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(21); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(22); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(23); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(24); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(25); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(26); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(27); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(28); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(29); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(30); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(31); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(32); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(33); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(34); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(35); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(36); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(37); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(38); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(39); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(40); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(41); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(42); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(43); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(44); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(45); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(46); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(47); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(48); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(49); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(50); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(51); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(52); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(53); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(54); - -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(1); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(2); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(3); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(4); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(5); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(6); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(7); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(8); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(9); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(10); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(11); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(12); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(13); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(14); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(15); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(16); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(17); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(18); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(19); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(20); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(21); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(22); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(23); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(24); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(25); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(26); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(27); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(28); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(29); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(30); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(31); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(32); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(33); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(34); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(35); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(36); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(37); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(38); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(39); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(40); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(41); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(42); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(43); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(44); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(45); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(46); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(47); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(48); -DECLARE_QSFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(49); -DECLARE_QSFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(50); -DECLARE_QSFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(51); -DECLARE_QSFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(52); -DECLARE_QSFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(53); -DECLARE_QSFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(54); - -static struct attribute *as5712_54x_cpld1_attributes[] = { - &sensor_dev_attr_version.dev_attr.attr, - &sensor_dev_attr_access.dev_attr.attr, - NULL -}; - -static const struct attribute_group as5712_54x_cpld1_group = { - .attrs = as5712_54x_cpld1_attributes, -}; - -static struct attribute *as5712_54x_cpld2_attributes[] = { - &sensor_dev_attr_version.dev_attr.attr, - &sensor_dev_attr_access.dev_attr.attr, - /* transceiver attributes */ - &sensor_dev_attr_module_present_all.dev_attr.attr, - &sensor_dev_attr_module_rx_los_all.dev_attr.attr, - DECLARE_TRANSCEIVER_PRESENT_ATTR(1), - DECLARE_TRANSCEIVER_PRESENT_ATTR(2), - DECLARE_TRANSCEIVER_PRESENT_ATTR(3), - DECLARE_TRANSCEIVER_PRESENT_ATTR(4), - DECLARE_TRANSCEIVER_PRESENT_ATTR(5), - DECLARE_TRANSCEIVER_PRESENT_ATTR(6), - DECLARE_TRANSCEIVER_PRESENT_ATTR(7), - DECLARE_TRANSCEIVER_PRESENT_ATTR(8), - DECLARE_TRANSCEIVER_PRESENT_ATTR(9), - DECLARE_TRANSCEIVER_PRESENT_ATTR(10), - DECLARE_TRANSCEIVER_PRESENT_ATTR(11), - DECLARE_TRANSCEIVER_PRESENT_ATTR(12), - DECLARE_TRANSCEIVER_PRESENT_ATTR(13), - DECLARE_TRANSCEIVER_PRESENT_ATTR(14), - DECLARE_TRANSCEIVER_PRESENT_ATTR(15), - DECLARE_TRANSCEIVER_PRESENT_ATTR(16), - DECLARE_TRANSCEIVER_PRESENT_ATTR(17), - DECLARE_TRANSCEIVER_PRESENT_ATTR(18), - DECLARE_TRANSCEIVER_PRESENT_ATTR(19), - DECLARE_TRANSCEIVER_PRESENT_ATTR(20), - DECLARE_TRANSCEIVER_PRESENT_ATTR(21), - DECLARE_TRANSCEIVER_PRESENT_ATTR(22), - DECLARE_TRANSCEIVER_PRESENT_ATTR(23), - DECLARE_TRANSCEIVER_PRESENT_ATTR(24), - DECLARE_SFP_TRANSCEIVER_ATTR(1), - DECLARE_SFP_TRANSCEIVER_ATTR(2), - DECLARE_SFP_TRANSCEIVER_ATTR(3), - DECLARE_SFP_TRANSCEIVER_ATTR(4), - DECLARE_SFP_TRANSCEIVER_ATTR(5), - DECLARE_SFP_TRANSCEIVER_ATTR(6), - DECLARE_SFP_TRANSCEIVER_ATTR(7), - DECLARE_SFP_TRANSCEIVER_ATTR(8), - DECLARE_SFP_TRANSCEIVER_ATTR(9), - DECLARE_SFP_TRANSCEIVER_ATTR(10), - DECLARE_SFP_TRANSCEIVER_ATTR(11), - DECLARE_SFP_TRANSCEIVER_ATTR(12), - DECLARE_SFP_TRANSCEIVER_ATTR(13), - DECLARE_SFP_TRANSCEIVER_ATTR(14), - DECLARE_SFP_TRANSCEIVER_ATTR(15), - DECLARE_SFP_TRANSCEIVER_ATTR(16), - DECLARE_SFP_TRANSCEIVER_ATTR(17), - DECLARE_SFP_TRANSCEIVER_ATTR(18), - DECLARE_SFP_TRANSCEIVER_ATTR(19), - DECLARE_SFP_TRANSCEIVER_ATTR(20), - DECLARE_SFP_TRANSCEIVER_ATTR(21), - DECLARE_SFP_TRANSCEIVER_ATTR(22), - DECLARE_SFP_TRANSCEIVER_ATTR(23), - DECLARE_SFP_TRANSCEIVER_ATTR(24), - NULL -}; - -static const struct attribute_group as5712_54x_cpld2_group = { - .attrs = as5712_54x_cpld2_attributes, -}; - -static struct attribute *as5712_54x_cpld3_attributes[] = { - &sensor_dev_attr_version.dev_attr.attr, - &sensor_dev_attr_access.dev_attr.attr, - /* transceiver attributes */ - &sensor_dev_attr_module_present_all.dev_attr.attr, - &sensor_dev_attr_module_rx_los_all.dev_attr.attr, - DECLARE_TRANSCEIVER_PRESENT_ATTR(25), - DECLARE_TRANSCEIVER_PRESENT_ATTR(26), - DECLARE_TRANSCEIVER_PRESENT_ATTR(27), - DECLARE_TRANSCEIVER_PRESENT_ATTR(28), - DECLARE_TRANSCEIVER_PRESENT_ATTR(29), - DECLARE_TRANSCEIVER_PRESENT_ATTR(30), - DECLARE_TRANSCEIVER_PRESENT_ATTR(31), - DECLARE_TRANSCEIVER_PRESENT_ATTR(32), - DECLARE_TRANSCEIVER_PRESENT_ATTR(33), - DECLARE_TRANSCEIVER_PRESENT_ATTR(34), - DECLARE_TRANSCEIVER_PRESENT_ATTR(35), - DECLARE_TRANSCEIVER_PRESENT_ATTR(36), - DECLARE_TRANSCEIVER_PRESENT_ATTR(37), - DECLARE_TRANSCEIVER_PRESENT_ATTR(38), - DECLARE_TRANSCEIVER_PRESENT_ATTR(39), - DECLARE_TRANSCEIVER_PRESENT_ATTR(40), - DECLARE_TRANSCEIVER_PRESENT_ATTR(41), - DECLARE_TRANSCEIVER_PRESENT_ATTR(42), - DECLARE_TRANSCEIVER_PRESENT_ATTR(43), - DECLARE_TRANSCEIVER_PRESENT_ATTR(44), - DECLARE_TRANSCEIVER_PRESENT_ATTR(45), - DECLARE_TRANSCEIVER_PRESENT_ATTR(46), - DECLARE_TRANSCEIVER_PRESENT_ATTR(47), - DECLARE_TRANSCEIVER_PRESENT_ATTR(48), - DECLARE_TRANSCEIVER_PRESENT_ATTR(49), - DECLARE_TRANSCEIVER_PRESENT_ATTR(50), - DECLARE_TRANSCEIVER_PRESENT_ATTR(51), - DECLARE_TRANSCEIVER_PRESENT_ATTR(52), - DECLARE_TRANSCEIVER_PRESENT_ATTR(53), - DECLARE_TRANSCEIVER_PRESENT_ATTR(54), - DECLARE_SFP_TRANSCEIVER_ATTR(25), - DECLARE_SFP_TRANSCEIVER_ATTR(26), - DECLARE_SFP_TRANSCEIVER_ATTR(27), - DECLARE_SFP_TRANSCEIVER_ATTR(28), - DECLARE_SFP_TRANSCEIVER_ATTR(29), - DECLARE_SFP_TRANSCEIVER_ATTR(30), - DECLARE_SFP_TRANSCEIVER_ATTR(31), - DECLARE_SFP_TRANSCEIVER_ATTR(32), - DECLARE_SFP_TRANSCEIVER_ATTR(33), - DECLARE_SFP_TRANSCEIVER_ATTR(34), - DECLARE_SFP_TRANSCEIVER_ATTR(35), - DECLARE_SFP_TRANSCEIVER_ATTR(36), - DECLARE_SFP_TRANSCEIVER_ATTR(37), - DECLARE_SFP_TRANSCEIVER_ATTR(38), - DECLARE_SFP_TRANSCEIVER_ATTR(39), - DECLARE_SFP_TRANSCEIVER_ATTR(40), - DECLARE_SFP_TRANSCEIVER_ATTR(41), - DECLARE_SFP_TRANSCEIVER_ATTR(42), - DECLARE_SFP_TRANSCEIVER_ATTR(43), - DECLARE_SFP_TRANSCEIVER_ATTR(44), - DECLARE_SFP_TRANSCEIVER_ATTR(45), - DECLARE_SFP_TRANSCEIVER_ATTR(46), - DECLARE_SFP_TRANSCEIVER_ATTR(47), - DECLARE_SFP_TRANSCEIVER_ATTR(48), - DECLARE_QSFP_TRANSCEIVER_ATTR(49), - DECLARE_QSFP_TRANSCEIVER_ATTR(50), - DECLARE_QSFP_TRANSCEIVER_ATTR(51), - DECLARE_QSFP_TRANSCEIVER_ATTR(52), - DECLARE_QSFP_TRANSCEIVER_ATTR(53), - DECLARE_QSFP_TRANSCEIVER_ATTR(54), - NULL -}; - -static const struct attribute_group as5712_54x_cpld3_group = { - .attrs = as5712_54x_cpld3_attributes, -}; - -static ssize_t show_present_all(struct device *dev, struct device_attribute *da, - char *buf) -{ - int i, status, num_regs = 0; - u8 values[4] = {0}; - u8 regs[] = {0x6, 0x7, 0x8, 0x14}; - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_cpld_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - num_regs = (data->type == as5712_54x_cpld2) ? 3 : 4; - - for (i = 0; i < num_regs; i++) { - status = as5712_54x_cpld_read_internal(client, regs[i]); - - if (status < 0) { - goto exit; - } - - values[i] = ~(u8)status; - } - - mutex_unlock(&data->update_lock); - - /* Return values 1 -> 54 in order */ - if (data->type == as5712_54x_cpld2) { - status = sprintf(buf, "%.2x %.2x %.2x\n", - values[0], values[1], values[2]); - } - else { /* as5712_54x_cpld3 */ - values[3] &= 0x3F; - status = sprintf(buf, "%.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], values[3]); - } - - return status; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, - char *buf) -{ - int i, status; - u8 values[3] = {0}; - u8 regs[] = {0xF, 0x10, 0x11}; - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_cpld_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - for (i = 0; i < ARRAY_SIZE(regs); i++) { - status = as5712_54x_cpld_read_internal(client, regs[i]); - - if (status < 0) { - goto exit; - } - - values[i] = (u8)status; - } - - mutex_unlock(&data->update_lock); - - /* Return values 1 -> 24 in order */ - return sprintf(buf, "%.2x %.2x %.2x\n", values[0], values[1], values[2]); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_cpld_data *data = i2c_get_clientdata(client); - int status = 0; - u8 reg = 0, mask = 0, revert = 0; - - switch (attr->index) { - case MODULE_PRESENT_1 ... MODULE_PRESENT_8: - reg = 0x6; - mask = 0x1 << (attr->index - MODULE_PRESENT_1); - break; - case MODULE_PRESENT_9 ... MODULE_PRESENT_16: - reg = 0x7; - mask = 0x1 << (attr->index - MODULE_PRESENT_9); - break; - case MODULE_PRESENT_17 ... MODULE_PRESENT_24: - reg = 0x8; - mask = 0x1 << (attr->index - MODULE_PRESENT_17); - break; - case MODULE_PRESENT_25 ... MODULE_PRESENT_32: - reg = 0x6; - mask = 0x1 << (attr->index - MODULE_PRESENT_25); - break; - case MODULE_PRESENT_33 ... MODULE_PRESENT_40: - reg = 0x7; - mask = 0x1 << (attr->index - MODULE_PRESENT_33); - break; - case MODULE_PRESENT_41 ... MODULE_PRESENT_48: - reg = 0x8; - mask = 0x1 << (attr->index - MODULE_PRESENT_41); - break; - case MODULE_PRESENT_49: - reg = 0x14; - mask = 0x1; - break; - case MODULE_PRESENT_50: - reg = 0x14; - mask = 0x4; - break; - case MODULE_PRESENT_51: - reg = 0x14; - mask = 0x10; - break; - case MODULE_PRESENT_52: - reg = 0x14; - mask = 0x2; - break; - case MODULE_PRESENT_53: - reg = 0x14; - mask = 0x8; - break; - case MODULE_PRESENT_54: - reg = 0x14; - mask = 0x20; - break; - case MODULE_TXFAULT_1 ... MODULE_TXFAULT_8: - reg = 0x9; - mask = 0x1 << (attr->index - MODULE_TXFAULT_1); - break; - case MODULE_TXFAULT_9 ... MODULE_TXFAULT_16: - reg = 0xA; - mask = 0x1 << (attr->index - MODULE_TXFAULT_9); - break; - case MODULE_TXFAULT_17 ... MODULE_TXFAULT_24: - reg = 0xB; - mask = 0x1 << (attr->index - MODULE_TXFAULT_17); - break; - case MODULE_TXFAULT_25 ... MODULE_TXFAULT_32: - reg = 0x9; - mask = 0x1 << (attr->index - MODULE_TXFAULT_25); - break; - case MODULE_TXFAULT_33 ... MODULE_TXFAULT_40: - reg = 0xA; - mask = 0x1 << (attr->index - MODULE_TXFAULT_33); - break; - case MODULE_TXFAULT_41 ... MODULE_TXFAULT_48: - reg = 0xB; - mask = 0x1 << (attr->index - MODULE_TXFAULT_41); - break; - case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: - reg = 0xC; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); - break; - case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: - reg = 0xD; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); - break; - case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: - reg = 0xE; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); - break; - case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_32: - reg = 0xC; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); - break; - case MODULE_TXDISABLE_33 ... MODULE_TXDISABLE_40: - reg = 0xD; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_33); - break; - case MODULE_TXDISABLE_41 ... MODULE_TXDISABLE_48: - reg = 0xE; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_41); - break; - case MODULE_RXLOS_1 ... MODULE_RXLOS_8: - reg = 0xF; - mask = 0x1 << (attr->index - MODULE_RXLOS_1); - break; - case MODULE_RXLOS_9 ... MODULE_RXLOS_16: - reg = 0x10; - mask = 0x1 << (attr->index - MODULE_RXLOS_9); - break; - case MODULE_RXLOS_17 ... MODULE_RXLOS_24: - reg = 0x11; - mask = 0x1 << (attr->index - MODULE_RXLOS_17); - break; - case MODULE_RXLOS_25 ... MODULE_RXLOS_32: - reg = 0xF; - mask = 0x1 << (attr->index - MODULE_RXLOS_25); - break; - case MODULE_RXLOS_33 ... MODULE_RXLOS_40: - reg = 0x10; - mask = 0x1 << (attr->index - MODULE_RXLOS_33); - break; - case MODULE_RXLOS_41 ... MODULE_RXLOS_48: - reg = 0x11; - mask = 0x1 << (attr->index - MODULE_RXLOS_41); - break; - case MODULE_LPMODE_49 ... MODULE_LPMODE_54: - reg = 0x16; - mask = 0x1 << (attr->index - MODULE_LPMODE_49); - break; - case MODULE_RESET_49 ... MODULE_RESET_54: - reg = 0x15; - mask = 0x1 << (attr->index - MODULE_RESET_49); - break; - default: - return 0; - } - - if (attr->index >= MODULE_PRESENT_1 && attr->index <= MODULE_PRESENT_54) { - revert = 1; - } - - mutex_lock(&data->update_lock); - status = as5712_54x_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - - return sprintf(buf, "%d\n", revert ? !(status & mask) : !!(status & mask)); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t set_tx_disable(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 as5712_54x_cpld_data *data = i2c_get_clientdata(client); - long disable; - int status; - u8 reg = 0, mask = 0; - - status = kstrtol(buf, 10, &disable); - if (status) { - return status; - } - - switch (attr->index) { - case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: - reg = 0xC; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); - break; - case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: - reg = 0xD; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); - break; - case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: - reg = 0xE; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); - break; - case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_32: - reg = 0xC; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); - break; - case MODULE_TXDISABLE_33 ... MODULE_TXDISABLE_40: - reg = 0xD; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_33); - break; - case MODULE_TXDISABLE_41 ... MODULE_TXDISABLE_48: - reg = 0xE; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_41); - break; - default: - return 0; - } - - /* Read current status */ - mutex_lock(&data->update_lock); - status = as5712_54x_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - - /* Update tx_disable status */ - if (disable) { - status |= mask; - } - else { - status &= ~mask; - } - - status = as5712_54x_cpld_write_internal(client, reg, status); - if (unlikely(status < 0)) { - goto exit; - } - - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t set_lp_mode(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 as5712_54x_cpld_data *data = i2c_get_clientdata(client); - long on; - int status= -ENOENT; - u8 reg = 0x16, mask = 0; - - if(attr->index < MODULE_LPMODE_49 || attr->index > MODULE_LPMODE_54) - return status; - - status = kstrtol(buf, 10, &on); - if (status) { - return status; - } - - /* Read current status */ - mutex_lock(&data->update_lock); - status = as5712_54x_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - - mask = 0x1 << (attr->index - MODULE_LPMODE_49); - - /* Update lp_mode status */ - if (on) { - status |= mask; - } - else { - status &= ~mask; - } - - status = as5712_54x_cpld_write_internal(client, reg, status); - if (unlikely(status < 0)) { - goto exit; - } - - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; - -} - -static ssize_t set_mode_reset(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 as5712_54x_cpld_data *data = i2c_get_clientdata(client); - long on; - int status= -ENOENT; - u8 reg = 0x15, mask = 0; - - if(attr->index < MODULE_RESET_49 || attr->index > MODULE_RESET_54) - return status; - - status = kstrtol(buf, 10, &on); - if (status) { - return status; - } - - /* Read current status */ - mutex_lock(&data->update_lock); - status = as5712_54x_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - - mask = 0x1 << (attr->index - MODULE_RESET_49); - - /* Update tx_disable status */ - if (on) { - status |= mask; - } - else { - status &= ~mask; - } - - status = as5712_54x_cpld_write_internal(client, reg, status); - if (unlikely(status < 0)) { - goto exit; - } - - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; - -} - -static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - int status; - u32 addr, val; - struct i2c_client *client = to_i2c_client(dev); - struct as5712_54x_cpld_data *data = i2c_get_clientdata(client); - - if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { - return -EINVAL; - } - - if (addr > 0xFF || val > 0xFF) { - return -EINVAL; - } - - mutex_lock(&data->update_lock); - status = as5712_54x_cpld_write_internal(client, addr, val); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -/* Write to mux register. Don't use i2c_transfer()/i2c_smbus_xfer() - for this as they will try to lock adapter a second time */ -static int as5712_54x_cpld_mux_reg_write(struct i2c_adapter *adap, - struct i2c_client *client, u8 val) -{ - unsigned long orig_jiffies; - unsigned short flags; - union i2c_smbus_data data; - int try; - s32 res = -EIO; - - data.byte = val; - flags = client->flags; - flags &= I2C_M_TEN | I2C_CLIENT_PEC; - - if (adap->algo->smbus_xfer) { - /* Retry automatically on arbitration loss */ - orig_jiffies = jiffies; - for (res = 0, try = 0; try <= adap->retries; try++) { - res = adap->algo->smbus_xfer(adap, client->addr, flags, - I2C_SMBUS_WRITE, CPLD_CHANNEL_SELECT_REG, - I2C_SMBUS_BYTE_DATA, &data); - if (res != -EAGAIN) - break; - if (time_after(jiffies, - orig_jiffies + adap->timeout)) - break; - } - } - - return res; - -} - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0) -static int as5712_54x_cpld_mux_select_chan(struct i2c_mux_core *muxc, - u32 chan) -{ - struct as5712_54x_cpld_data *data = i2c_mux_priv(muxc); - struct i2c_client *client = data->client; - u8 regval; - int ret = 0; - regval = chan; - - /* Only select the channel if its different from the last channel */ - if (data->last_chan != regval) { - ret = as5712_54x_cpld_mux_reg_write(muxc->parent, client, regval); - data->last_chan = regval; - } - - return ret; -} - -static int as5712_54x_cpld_mux_deselect_mux(struct i2c_mux_core *muxc, - u32 chan) -{ - struct as5712_54x_cpld_data *data = i2c_mux_priv(muxc); - struct i2c_client *client = data->client; - - /* Deselect active channel */ - data->last_chan = chips[data->type].deselectChan; - - return as5712_54x_cpld_mux_reg_write(muxc->parent, client, data->last_chan); -} -#else - -static int as5712_54x_cpld_mux_select_chan(struct i2c_adapter *adap, - void *client, u32 chan) -{ - struct as5712_54x_cpld_data *data = i2c_get_clientdata(client); - u8 regval; - int ret = 0; - regval = chan; - - /* Only select the channel if its different from the last channel */ - if (data->last_chan != regval) { - ret = as5712_54x_cpld_mux_reg_write(adap, client, regval); - data->last_chan = regval; - } - - return ret; -} - -static int as5712_54x_cpld_mux_deselect_mux(struct i2c_adapter *adap, - void *client, u32 chan) -{ - struct as5712_54x_cpld_data *data = i2c_get_clientdata(client); - - /* Deselect active channel */ - data->last_chan = chips[data->type].deselectChan; - - return as5712_54x_cpld_mux_reg_write(adap, client, data->last_chan); -} - -#endif /*#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0)*/ - -static void as5712_54x_cpld_add_client(struct i2c_client *client) -{ - struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); - - if (!node) { - dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); - return; - } - - node->client = client; - - mutex_lock(&list_lock); - list_add(&node->list, &cpld_client_list); - mutex_unlock(&list_lock); -} - -static void as5712_54x_cpld_remove_client(struct i2c_client *client) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int found = 0; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client == client) { - found = 1; - break; - } - } - - if (found) { - list_del(list_node); - kfree(cpld_node); - } - - mutex_unlock(&list_lock); -} - -static ssize_t show_version(struct device *dev, struct device_attribute *attr, char *buf) -{ - int val = 0; - struct i2c_client *client = to_i2c_client(dev); - - val = i2c_smbus_read_byte_data(client, 0x1); - - if (val < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val); -} - - return sprintf(buf, "%d", val); -} - -/* - * I2C init/probing/exit functions - */ -static int as5712_54x_cpld_mux_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); - #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0) - int force, class; - struct i2c_mux_core *muxc; -#endif - - int chan=0; - struct as5712_54x_cpld_data *data; - int ret = -ENODEV; - const struct attribute_group *group = NULL; - - if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) - goto exit; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0) - muxc = i2c_mux_alloc(adap, &client->dev, - chips[id->driver_data].nchans, - sizeof(*data), 0, - accton_i2c_cpld_mux_select_chan, - accton_i2c_cpld_mux_deselect_mux); - if (!muxc) - return -ENOMEM; - - data = i2c_mux_priv(muxc); - i2c_set_clientdata(client, data); - data->muxc = muxc; - data->client = client; -#else - - data = kzalloc(sizeof(struct as5712_54x_cpld_data), GFP_KERNEL); - if (!data) { - ret = -ENOMEM; - goto exit; - } - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); -#endif - data->type = id->driver_data; - if (data->type == as5712_54x_cpld2 || data->type == as5712_54x_cpld3) { - data->last_chan = chips[data->type].deselectChan; /* force the first selection */ - - /* Now create an adapter for each channel */ - for (chan = 0; chan < chips[data->type].nchans; chan++) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0) - force = 0; /* dynamic adap number */ - class = 0; /* no class by default */ - ret = i2c_mux_add_adapter(muxc, force, chan, class); - if (ret) -#else - data->virt_adaps[chan] = i2c_add_mux_adapter(adap, &client->dev, client, 0, chan, - 0, - as5712_54x_cpld_mux_select_chan, - as5712_54x_cpld_mux_deselect_mux); - if (data->virt_adaps[chan] == NULL) -#endif - { - ret = -ENODEV; - dev_err(&client->dev, "failed to register multiplexed adapter %d\n", chan); - goto exit_mux_register; - } - } - - dev_info(&client->dev, "registered %d multiplexed busses for I2C mux %s\n", - chan, client->name); - } - /* Register sysfs hooks */ - switch (data->type) - { - case as5712_54x_cpld1: - group = &as5712_54x_cpld1_group; - break; - case as5712_54x_cpld2: - group = &as5712_54x_cpld2_group; - break; - case as5712_54x_cpld3: - group = &as5712_54x_cpld3_group; - break; - default: - break; - } - - - if (group) { - ret = sysfs_create_group(&client->dev.kobj, group); - if (ret) { - goto exit_mux_register; - } - } - - as5712_54x_cpld_add_client(client); - return 0; - -exit_mux_register: -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0) - i2c_mux_del_adapters(muxc); -#else - for (chan--; chan >= 0; chan--) { - i2c_del_mux_adapter(data->virt_adaps[chan]); - } -#endif - kfree(data); -exit: - return ret; -} - -static int as5712_54x_cpld_mux_remove(struct i2c_client *client) -{ - struct as5712_54x_cpld_data *data = i2c_get_clientdata(client); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0) - struct i2c_mux_core *muxc = data->muxc; - - i2c_mux_del_adapters(muxc); -#else - const struct chip_desc *chip = &chips[data->type]; - int chan; - const struct attribute_group *group = NULL; - - as5712_54x_cpld_remove_client(client); - - /* Remove sysfs hooks */ - switch (data->type) { - case as5712_54x_cpld1: - group = &as5712_54x_cpld1_group; - break; - case as5712_54x_cpld2: - group = &as5712_54x_cpld2_group; - break; - case as5712_54x_cpld3: - group = &as5712_54x_cpld3_group; - break; - default: - break; - } - - if (group) { - sysfs_remove_group(&client->dev.kobj, group); - } - - for (chan = 0; chan < chip->nchans; ++chan) { - if (data->virt_adaps[chan]) { - i2c_del_mux_adapter(data->virt_adaps[chan]); - data->virt_adaps[chan] = NULL; - } - } -#endif - kfree(data); - - return 0; -} - -static int as5712_54x_cpld_read_internal(struct i2c_client *client, u8 reg) -{ - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, reg); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - return status; -} - -static int as5712_54x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value) -{ - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, reg, value); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - return status; -} - -int as5712_54x_cpld_read(unsigned short cpld_addr, u8 reg) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EPERM; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = as5712_54x_cpld_read_internal(cpld_node->client, reg); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(as5712_54x_cpld_read); - -int as5712_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EIO; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = as5712_54x_cpld_write_internal(cpld_node->client, reg, value); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(as5712_54x_cpld_write); - -#if 0 -int accton_i2c_cpld_mux_get_index(int adap_index) -{ - int i; - - for (i = 0; i < NUM_OF_ALL_CPLD_CHANS; i++) { - if (mux_adap_map[i] == adap_index) { - return i; - } - } - - return -EINVAL; -} -EXPORT_SYMBOL(accton_i2c_cpld_mux_get_index); -#endif - -static struct i2c_driver as5712_54x_cpld_mux_driver = { - .driver = { - .name = "as5712_54x_cpld", - .owner = THIS_MODULE, - }, - .probe = as5712_54x_cpld_mux_probe, - .remove = as5712_54x_cpld_mux_remove, - .id_table = as5712_54x_cpld_mux_id, -}; - -static int __init as5712_54x_cpld_mux_init(void) -{ - mutex_init(&list_lock); - return i2c_add_driver(&as5712_54x_cpld_mux_driver); -} - -static void __exit as5712_54x_cpld_mux_exit(void) -{ - i2c_del_driver(&as5712_54x_cpld_mux_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("Accton I2C CPLD mux driver"); -MODULE_LICENSE("GPL"); - -module_init(as5712_54x_cpld_mux_init); -module_exit(as5712_54x_cpld_mux_exit); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/leds-accton_as5712_54x.c b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/leds-accton_as5712_54x.c deleted file mode 100755 index cdea927368ae..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/leds-accton_as5712_54x.c +++ /dev/null @@ -1,594 +0,0 @@ -/* - * A LED driver for the accton_as5712_54x_led - * - * Copyright (C) 2013 Accton Technology Corporation. - * Brandon Chuang - * - * 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. - */ -#if 0 -#define DEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include - -extern int as5712_54x_cpld_read (unsigned short cpld_addr, u8 reg); -extern int as5712_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -extern void led_classdev_unregister(struct led_classdev *led_cdev); -extern int led_classdev_register(struct device *parent, struct led_classdev *led_cdev); -extern void led_classdev_resume(struct led_classdev *led_cdev); -extern void led_classdev_suspend(struct led_classdev *led_cdev); - -#define DRVNAME "as5712_54x_led" - -struct accton_as5712_54x_led_data { - struct platform_device *pdev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[4]; /* Register value, 0 = LOC/DIAG/FAN LED - 1 = PSU1/PSU2 LED - 2 = FAN1-4 LED - 3 = FAN5-6 LED */ -}; - -static struct accton_as5712_54x_led_data *ledctl = NULL; - -/* LED related data - */ -#define LED_TYPE_PSU1_REG_MASK 0x03 -#define LED_MODE_PSU1_GREEN_MASK 0x02 -#define LED_MODE_PSU1_AMBER_MASK 0x01 -#define LED_MODE_PSU1_OFF_MASK 0x03 -#define LED_MODE_PSU1_AUTO_MASK 0x00 - -#define LED_TYPE_PSU2_REG_MASK 0x0C -#define LED_MODE_PSU2_GREEN_MASK 0x08 -#define LED_MODE_PSU2_AMBER_MASK 0x04 -#define LED_MODE_PSU2_OFF_MASK 0x0C -#define LED_MODE_PSU2_AUTO_MASK 0x00 - -#define LED_TYPE_DIAG_REG_MASK 0x0C -#define LED_MODE_DIAG_GREEN_MASK 0x08 -#define LED_MODE_DIAG_AMBER_MASK 0x04 -#define LED_MODE_DIAG_OFF_MASK 0x0C - -#define LED_TYPE_FAN_REG_MASK 0x03 -#define LED_MODE_FAN_GREEN_MASK 0x02 -#define LED_MODE_FAN_AMBER_MASK 0x01 -#define LED_MODE_FAN_OFF_MASK 0x03 -#define LED_MODE_FAN_AUTO_MASK 0x00 - -#define LED_TYPE_FAN1_REG_MASK 0x03 -#define LED_TYPE_FAN2_REG_MASK 0x0C -#define LED_TYPE_FAN3_REG_MASK 0x30 -#define LED_TYPE_FAN4_REG_MASK 0xC0 -#define LED_TYPE_FAN5_REG_MASK 0x03 -#define LED_TYPE_FAN6_REG_MASK 0x0C - -#define LED_MODE_FANX_GREEN_MASK 0x01 -#define LED_MODE_FANX_RED_MASK 0x02 -#define LED_MODE_FANX_OFF_MASK 0x00 - -#define LED_TYPE_LOC_REG_MASK 0x30 -#define LED_MODE_LOC_ON_MASK 0x00 -#define LED_MODE_LOC_OFF_MASK 0x10 -#define LED_MODE_LOC_BLINK_MASK 0x20 - -static const u8 led_reg[] = { - 0xA, /* LOC/DIAG/FAN LED*/ - 0xB, /* PSU1/PSU2 LED */ - 0x16, /* FAN1-4 LED */ - 0x17, /* FAN4-6 LED */ -}; - -enum led_type { - LED_TYPE_PSU1, - LED_TYPE_PSU2, - LED_TYPE_DIAG, - LED_TYPE_FAN, - LED_TYPE_FAN1, - LED_TYPE_FAN2, - LED_TYPE_FAN3, - LED_TYPE_FAN4, - LED_TYPE_FAN5, - LED_TYPE_LOC -}; - -enum led_light_mode { - LED_MODE_OFF = 0, - LED_MODE_GREEN, - LED_MODE_AMBER, - LED_MODE_RED, - LED_MODE_GREEN_BLINK, - LED_MODE_AMBER_BLINK, - LED_MODE_RED_BLINK, - LED_MODE_AUTO, -}; - -struct led_type_mode { - enum led_type type; - int type_mask; - enum led_light_mode mode; - int mode_mask; -}; - -static struct led_type_mode led_type_mode_data[] = { -{LED_TYPE_PSU1, LED_TYPE_PSU1_REG_MASK, LED_MODE_GREEN, LED_MODE_PSU1_GREEN_MASK}, -{LED_TYPE_PSU1, LED_TYPE_PSU1_REG_MASK, LED_MODE_AMBER, LED_MODE_PSU1_AMBER_MASK}, -{LED_TYPE_PSU1, LED_TYPE_PSU1_REG_MASK, LED_MODE_AUTO, LED_MODE_PSU1_AUTO_MASK}, -{LED_TYPE_PSU1, LED_TYPE_PSU1_REG_MASK, LED_MODE_OFF, LED_MODE_PSU1_OFF_MASK}, -{LED_TYPE_PSU2, LED_TYPE_PSU2_REG_MASK, LED_MODE_GREEN, LED_MODE_PSU2_GREEN_MASK}, -{LED_TYPE_PSU2, LED_TYPE_PSU2_REG_MASK, LED_MODE_AMBER, LED_MODE_PSU2_AMBER_MASK}, -{LED_TYPE_PSU2, LED_TYPE_PSU2_REG_MASK, LED_MODE_AUTO, LED_MODE_PSU2_AUTO_MASK}, -{LED_TYPE_PSU2, LED_TYPE_PSU2_REG_MASK, LED_MODE_OFF, LED_MODE_PSU2_OFF_MASK}, -{LED_TYPE_FAN, LED_TYPE_FAN_REG_MASK, LED_MODE_GREEN, LED_MODE_FAN_GREEN_MASK}, -{LED_TYPE_FAN, LED_TYPE_FAN_REG_MASK, LED_MODE_AMBER, LED_MODE_FAN_AMBER_MASK}, -{LED_TYPE_FAN, LED_TYPE_FAN_REG_MASK, LED_MODE_AUTO, LED_MODE_FAN_AUTO_MASK}, -{LED_TYPE_FAN, LED_TYPE_FAN_REG_MASK, LED_MODE_OFF, LED_MODE_FAN_OFF_MASK}, -{LED_TYPE_FAN1, LED_TYPE_FAN1_REG_MASK, LED_MODE_GREEN, LED_MODE_FANX_GREEN_MASK << 0}, -{LED_TYPE_FAN1, LED_TYPE_FAN1_REG_MASK, LED_MODE_RED, LED_MODE_FANX_RED_MASK << 0}, -{LED_TYPE_FAN1, LED_TYPE_FAN1_REG_MASK, LED_MODE_OFF, LED_MODE_FANX_OFF_MASK << 0}, -{LED_TYPE_FAN2, LED_TYPE_FAN2_REG_MASK, LED_MODE_GREEN, LED_MODE_FANX_GREEN_MASK << 2}, -{LED_TYPE_FAN2, LED_TYPE_FAN2_REG_MASK, LED_MODE_RED, LED_MODE_FANX_RED_MASK << 2}, -{LED_TYPE_FAN2, LED_TYPE_FAN2_REG_MASK, LED_MODE_OFF, LED_MODE_FANX_OFF_MASK << 2}, -{LED_TYPE_FAN3, LED_TYPE_FAN3_REG_MASK, LED_MODE_GREEN, LED_MODE_FANX_GREEN_MASK << 4}, -{LED_TYPE_FAN3, LED_TYPE_FAN3_REG_MASK, LED_MODE_RED, LED_MODE_FANX_RED_MASK << 4}, -{LED_TYPE_FAN3, LED_TYPE_FAN3_REG_MASK, LED_MODE_OFF, LED_MODE_FANX_OFF_MASK << 4}, -{LED_TYPE_FAN4, LED_TYPE_FAN4_REG_MASK, LED_MODE_GREEN, LED_MODE_FANX_GREEN_MASK << 6}, -{LED_TYPE_FAN4, LED_TYPE_FAN4_REG_MASK, LED_MODE_RED, LED_MODE_FANX_RED_MASK << 6}, -{LED_TYPE_FAN4, LED_TYPE_FAN4_REG_MASK, LED_MODE_OFF, LED_MODE_FANX_OFF_MASK << 6}, -{LED_TYPE_FAN5, LED_TYPE_FAN5_REG_MASK, LED_MODE_GREEN, LED_MODE_FANX_GREEN_MASK << 0}, -{LED_TYPE_FAN5, LED_TYPE_FAN5_REG_MASK, LED_MODE_RED, LED_MODE_FANX_RED_MASK << 0}, -{LED_TYPE_FAN5, LED_TYPE_FAN5_REG_MASK, LED_MODE_OFF, LED_MODE_FANX_OFF_MASK << 0}, -{LED_TYPE_DIAG, LED_TYPE_DIAG_REG_MASK, LED_MODE_GREEN, LED_MODE_DIAG_GREEN_MASK}, -{LED_TYPE_DIAG, LED_TYPE_DIAG_REG_MASK, LED_MODE_AMBER, LED_MODE_DIAG_AMBER_MASK}, -{LED_TYPE_DIAG, LED_TYPE_DIAG_REG_MASK, LED_MODE_OFF, LED_MODE_DIAG_OFF_MASK}, -{LED_TYPE_LOC, LED_TYPE_LOC_REG_MASK, LED_MODE_AMBER, LED_MODE_LOC_ON_MASK}, -{LED_TYPE_LOC, LED_TYPE_LOC_REG_MASK, LED_MODE_OFF, LED_MODE_LOC_OFF_MASK}, -{LED_TYPE_LOC, LED_TYPE_LOC_REG_MASK, LED_MODE_AMBER_BLINK, LED_MODE_LOC_BLINK_MASK} -}; - - -struct fanx_info_s { - u8 cname; /* device name */ - enum led_type type; - u8 reg_id; /* map to led_reg & reg_val */ -}; - -static struct fanx_info_s fanx_info[] = { - {'1', LED_TYPE_FAN1, 2}, - {'2', LED_TYPE_FAN2, 2}, - {'3', LED_TYPE_FAN3, 2}, - {'4', LED_TYPE_FAN4, 2}, - {'5', LED_TYPE_FAN5, 3} -}; - -static int led_reg_val_to_light_mode(enum led_type type, u8 reg_val) { - int i; - - for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) { - - if (type != led_type_mode_data[i].type) - continue; - - if ((led_type_mode_data[i].type_mask & reg_val) == - led_type_mode_data[i].mode_mask) - { - return led_type_mode_data[i].mode; - } - } - - return 0; -} - -static u8 led_light_mode_to_reg_val(enum led_type type, - enum led_light_mode mode, u8 reg_val) { - int i; - - for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) { - if (type != led_type_mode_data[i].type) - continue; - - if (mode != led_type_mode_data[i].mode) - continue; - - reg_val = led_type_mode_data[i].mode_mask | - (reg_val & (~led_type_mode_data[i].type_mask)); - } - - return reg_val; -} - -static int accton_as5712_54x_led_read_value(u8 reg) -{ - return as5712_54x_cpld_read(0x60, reg); -} - -static int accton_as5712_54x_led_write_value(u8 reg, u8 value) -{ - return as5712_54x_cpld_write(0x60, reg, value); -} - -static void accton_as5712_54x_led_update(void) -{ - mutex_lock(&ledctl->update_lock); - - if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2) - || !ledctl->valid) { - int i; - - dev_dbg(&ledctl->pdev->dev, "Starting accton_as5712_54x_led update\n"); - - /* Update LED data - */ - for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { - int status = accton_as5712_54x_led_read_value(led_reg[i]); - - if (status < 0) { - ledctl->valid = 0; - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg[i], status); - goto exit; - } - else - { - ledctl->reg_val[i] = status; - } - } - - ledctl->last_updated = jiffies; - ledctl->valid = 1; - } - -exit: - mutex_unlock(&ledctl->update_lock); -} - -static void accton_as5712_54x_led_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode, - u8 reg, enum led_type type) -{ - int reg_val; - - mutex_lock(&ledctl->update_lock); - - reg_val = accton_as5712_54x_led_read_value(reg); - - if (reg_val < 0) { - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val); - goto exit; - } - - reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val); - accton_as5712_54x_led_write_value(reg, reg_val); - - /* to prevent the slow-update issue */ - ledctl->valid = 0; - -exit: - mutex_unlock(&ledctl->update_lock); -} - -static void accton_as5712_54x_led_psu_1_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as5712_54x_led_set(led_cdev, led_light_mode, led_reg[1], LED_TYPE_PSU1); -} - -static enum led_brightness accton_as5712_54x_led_psu_1_get(struct led_classdev *cdev) -{ - accton_as5712_54x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_PSU1, ledctl->reg_val[1]); -} - -static void accton_as5712_54x_led_psu_2_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as5712_54x_led_set(led_cdev, led_light_mode, led_reg[1], LED_TYPE_PSU2); -} - -static enum led_brightness accton_as5712_54x_led_psu_2_get(struct led_classdev *cdev) -{ - accton_as5712_54x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_PSU2, ledctl->reg_val[1]); -} - -static void accton_as5712_54x_led_fan_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as5712_54x_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_FAN); -} - -static enum led_brightness accton_as5712_54x_led_fan_get(struct led_classdev *cdev) -{ - accton_as5712_54x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_FAN, ledctl->reg_val[0]); -} - - -static void accton_as5712_54x_led_fanx_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - enum led_type led_type1; - int reg_id; - int i, nsize; - int ncount = sizeof(fanx_info)/sizeof(struct fanx_info_s); - - for(i=0;iname); - - if (led_cdev->name[nsize-1] == fanx_info[i].cname) - { - led_type1 = fanx_info[i].type; - reg_id = fanx_info[i].reg_id; - accton_as5712_54x_led_set(led_cdev, led_light_mode, led_reg[reg_id], led_type1); - return; - } - } -} - - -static enum led_brightness accton_as5712_54x_led_fanx_get(struct led_classdev *cdev) -{ - enum led_type led_type1; - int reg_id; - int i, nsize; - int ncount = sizeof(fanx_info)/sizeof(struct fanx_info_s); - - for(i=0;iname); - - if (cdev->name[nsize-1] == fanx_info[i].cname) - { - led_type1 = fanx_info[i].type; - reg_id = fanx_info[i].reg_id; - accton_as5712_54x_led_update(); - return led_reg_val_to_light_mode(led_type1, ledctl->reg_val[reg_id]); - } - } - - - return led_reg_val_to_light_mode(LED_TYPE_FAN1, ledctl->reg_val[2]); -} - - -static void accton_as5712_54x_led_diag_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as5712_54x_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_DIAG); -} - -static enum led_brightness accton_as5712_54x_led_diag_get(struct led_classdev *cdev) -{ - accton_as5712_54x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); -} - -static void accton_as5712_54x_led_loc_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as5712_54x_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_LOC); -} - -static enum led_brightness accton_as5712_54x_led_loc_get(struct led_classdev *cdev) -{ - accton_as5712_54x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); -} - -static struct led_classdev accton_as5712_54x_leds[] = { - [LED_TYPE_PSU1] = { - .name = "accton_as5712_54x_led::psu1", - .default_trigger = "unused", - .brightness_set = accton_as5712_54x_led_psu_1_set, - .brightness_get = accton_as5712_54x_led_psu_1_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_PSU2] = { - .name = "accton_as5712_54x_led::psu2", - .default_trigger = "unused", - .brightness_set = accton_as5712_54x_led_psu_2_set, - .brightness_get = accton_as5712_54x_led_psu_2_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_FAN] = { - .name = "accton_as5712_54x_led::fan", - .default_trigger = "unused", - .brightness_set = accton_as5712_54x_led_fan_set, - .brightness_get = accton_as5712_54x_led_fan_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_FAN1] = { - .name = "accton_as5712_54x_led::fan1", - .default_trigger = "unused", - .brightness_set = accton_as5712_54x_led_fanx_set, - .brightness_get = accton_as5712_54x_led_fanx_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_FAN2] = { - .name = "accton_as5712_54x_led::fan2", - .default_trigger = "unused", - .brightness_set = accton_as5712_54x_led_fanx_set, - .brightness_get = accton_as5712_54x_led_fanx_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_FAN3] = { - .name = "accton_as5712_54x_led::fan3", - .default_trigger = "unused", - .brightness_set = accton_as5712_54x_led_fanx_set, - .brightness_get = accton_as5712_54x_led_fanx_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_FAN4] = { - .name = "accton_as5712_54x_led::fan4", - .default_trigger = "unused", - .brightness_set = accton_as5712_54x_led_fanx_set, - .brightness_get = accton_as5712_54x_led_fanx_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_FAN5] = { - .name = "accton_as5712_54x_led::fan5", - .default_trigger = "unused", - .brightness_set = accton_as5712_54x_led_fanx_set, - .brightness_get = accton_as5712_54x_led_fanx_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_DIAG] = { - .name = "accton_as5712_54x_led::diag", - .default_trigger = "unused", - .brightness_set = accton_as5712_54x_led_diag_set, - .brightness_get = accton_as5712_54x_led_diag_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_LOC] = { - .name = "accton_as5712_54x_led::loc", - .default_trigger = "unused", - .brightness_set = accton_as5712_54x_led_loc_set, - .brightness_get = accton_as5712_54x_led_loc_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, -}; - -static int accton_as5712_54x_led_suspend(struct platform_device *dev, - pm_message_t state) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(accton_as5712_54x_leds); i++) { - led_classdev_suspend(&accton_as5712_54x_leds[i]); - } - - return 0; -} - -static int accton_as5712_54x_led_resume(struct platform_device *dev) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(accton_as5712_54x_leds); i++) { - led_classdev_resume(&accton_as5712_54x_leds[i]); - } - - return 0; -} - -static int accton_as5712_54x_led_probe(struct platform_device *pdev) -{ - int ret, i; - - for (i = 0; i < ARRAY_SIZE(accton_as5712_54x_leds); i++) { - ret = led_classdev_register(&pdev->dev, &accton_as5712_54x_leds[i]); - - if (ret < 0) - break; - } - - /* Check if all LEDs were successfully registered */ - if (i != ARRAY_SIZE(accton_as5712_54x_leds)){ - int j; - - /* only unregister the LEDs that were successfully registered */ - for (j = 0; j < i; j++) { - led_classdev_unregister(&accton_as5712_54x_leds[i]); - } - } - - return ret; -} - -static int accton_as5712_54x_led_remove(struct platform_device *pdev) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(accton_as5712_54x_leds); i++) { - led_classdev_unregister(&accton_as5712_54x_leds[i]); - } - - return 0; -} - -static struct platform_driver accton_as5712_54x_led_driver = { - .probe = accton_as5712_54x_led_probe, - .remove = accton_as5712_54x_led_remove, - .suspend = accton_as5712_54x_led_suspend, - .resume = accton_as5712_54x_led_resume, - .driver = { - .name = DRVNAME, - .owner = THIS_MODULE, - }, -}; - -static int __init accton_as5712_54x_led_init(void) -{ - int ret; - - ret = platform_driver_register(&accton_as5712_54x_led_driver); - if (ret < 0) { - goto exit; - } - - ledctl = kzalloc(sizeof(struct accton_as5712_54x_led_data), GFP_KERNEL); - if (!ledctl) { - ret = -ENOMEM; - platform_driver_unregister(&accton_as5712_54x_led_driver); - goto exit; - } - - mutex_init(&ledctl->update_lock); - - ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); - if (IS_ERR(ledctl->pdev)) { - ret = PTR_ERR(ledctl->pdev); - platform_driver_unregister(&accton_as5712_54x_led_driver); - kfree(ledctl); - goto exit; - } - -exit: - return ret; -} - -static void __exit accton_as5712_54x_led_exit(void) -{ - platform_device_unregister(ledctl->pdev); - platform_driver_unregister(&accton_as5712_54x_led_driver); - kfree(ledctl); -} - -module_init(accton_as5712_54x_led_init); -module_exit(accton_as5712_54x_led_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton_as5712_54x_led driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/ym2651y.c b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/ym2651y.c deleted file mode 100755 index 519530387e29..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/modules/ym2651y.c +++ /dev/null @@ -1,683 +0,0 @@ -/* - * An hwmon driver for the 3Y Power YM-2651Y Power Module - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#if 0 -#define DEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_FAN_DUTY_CYCLE 100 - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -enum chips { - YM2651, - YM2401, -}; - -/* Each client has this additional data - */ -struct ym2651y_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 chip; /* chip id */ - u8 capability; /* Register value */ - u16 status_word; /* Register value */ - u8 fan_fault; /* Register value */ - u8 over_temp; /* Register value */ - u16 v_out; /* Register value */ - u16 i_out; /* Register value */ - u16 p_out; /* Register value */ - u8 vout_mode; /* Register value */ - u16 temp; /* Register value */ - u16 fan_speed; /* Register value */ - u16 fan_duty_cycle[2]; /* Register value */ - u8 fan_dir[5]; /* Register value */ - u8 pmbus_revision; /* Register value */ - u8 mfr_id[10]; /* Register value */ - u8 mfr_model[16]; /* Register value */ - u8 mfr_revsion[3]; /* Register value */ - u16 mfr_vin_min; /* Register value */ - u16 mfr_vin_max; /* Register value */ - u16 mfr_iin_max; /* Register value */ - u16 mfr_iout_max; /* Register value */ - u16 mfr_pin_max; /* Register value */ - u16 mfr_pout_max; /* Register value */ - u16 mfr_vout_min; /* Register value */ - u16 mfr_vout_max; /* Register value */ -}; - -static ssize_t show_byte(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_word(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_linear(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_vout(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_over_temp(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_ascii(struct device *dev, struct device_attribute *da, - char *buf); -static struct ym2651y_data *ym2651y_update_device(struct device *dev); -static ssize_t set_fan_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static int ym2651y_write_word(struct i2c_client *client, u8 reg, u16 value); - -enum ym2651y_sysfs_attributes { - PSU_POWER_ON = 0, - PSU_TEMP_FAULT, - PSU_POWER_GOOD, - PSU_FAN1_FAULT, - PSU_FAN_DIRECTION, - PSU_OVER_TEMP, - PSU_V_OUT, - PSU_I_OUT, - PSU_P_OUT, - PSU_TEMP1_INPUT, - PSU_FAN1_SPEED, - PSU_FAN1_DUTY_CYCLE, - PSU_PMBUS_REVISION, - PSU_MFR_ID, - PSU_MFR_MODEL, - PSU_MFR_REVISION, - PSU_MFR_VIN_MIN, - PSU_MFR_VIN_MAX, - PSU_MFR_VOUT_MIN, - PSU_MFR_VOUT_MAX, - PSU_MFR_IIN_MAX, - PSU_MFR_IOUT_MAX, - PSU_MFR_PIN_MAX, - PSU_MFR_POUT_MAX -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_power_on, S_IRUGO, show_word, NULL, PSU_POWER_ON); -static SENSOR_DEVICE_ATTR(psu_temp_fault, S_IRUGO, show_word, NULL, PSU_TEMP_FAULT); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_word, NULL, PSU_POWER_GOOD); -static SENSOR_DEVICE_ATTR(psu_fan1_fault, S_IRUGO, show_fan_fault, NULL, PSU_FAN1_FAULT); -static SENSOR_DEVICE_ATTR(psu_over_temp, S_IRUGO, show_over_temp, NULL, PSU_OVER_TEMP); -static SENSOR_DEVICE_ATTR(psu_v_out, S_IRUGO, show_vout, NULL, PSU_V_OUT); -static SENSOR_DEVICE_ATTR(psu_i_out, S_IRUGO, show_linear, NULL, PSU_I_OUT); -static SENSOR_DEVICE_ATTR(psu_p_out, S_IRUGO, show_linear, NULL, PSU_P_OUT); -static SENSOR_DEVICE_ATTR(psu_temp1_input, S_IRUGO, show_linear, NULL, PSU_TEMP1_INPUT); -static SENSOR_DEVICE_ATTR(psu_fan1_speed_rpm, S_IRUGO, show_linear, NULL, PSU_FAN1_SPEED); -static SENSOR_DEVICE_ATTR(psu_fan1_duty_cycle_percentage, S_IWUSR | S_IRUGO, show_linear, set_fan_duty_cycle, PSU_FAN1_DUTY_CYCLE); -static SENSOR_DEVICE_ATTR(psu_fan_dir, S_IRUGO, show_ascii, NULL, PSU_FAN_DIRECTION); -static SENSOR_DEVICE_ATTR(psu_pmbus_revision,S_IRUGO, show_byte, NULL, PSU_PMBUS_REVISION); -static SENSOR_DEVICE_ATTR(psu_mfr_id, S_IRUGO, show_ascii, NULL, PSU_MFR_ID); -static SENSOR_DEVICE_ATTR(psu_mfr_model, S_IRUGO, show_ascii, NULL, PSU_MFR_MODEL); -static SENSOR_DEVICE_ATTR(psu_mfr_revision, S_IRUGO, show_ascii, NULL, PSU_MFR_REVISION); -static SENSOR_DEVICE_ATTR(psu_mfr_vin_min, S_IRUGO, show_linear, NULL, PSU_MFR_VIN_MIN); -static SENSOR_DEVICE_ATTR(psu_mfr_vin_max, S_IRUGO, show_linear, NULL, PSU_MFR_VIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_vout_min, S_IRUGO, show_linear, NULL, PSU_MFR_VOUT_MIN); -static SENSOR_DEVICE_ATTR(psu_mfr_vout_max, S_IRUGO, show_linear, NULL, PSU_MFR_VOUT_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_iin_max, S_IRUGO, show_linear, NULL, PSU_MFR_IIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_iout_max, S_IRUGO, show_linear, NULL, PSU_MFR_IOUT_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_pin_max, S_IRUGO, show_linear, NULL, PSU_MFR_PIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_pout_max, S_IRUGO, show_linear, NULL, PSU_MFR_POUT_MAX); - -static struct attribute *ym2651y_attributes[] = { - &sensor_dev_attr_psu_power_on.dev_attr.attr, - &sensor_dev_attr_psu_temp_fault.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - &sensor_dev_attr_psu_fan1_fault.dev_attr.attr, - &sensor_dev_attr_psu_over_temp.dev_attr.attr, - &sensor_dev_attr_psu_v_out.dev_attr.attr, - &sensor_dev_attr_psu_i_out.dev_attr.attr, - &sensor_dev_attr_psu_p_out.dev_attr.attr, - &sensor_dev_attr_psu_temp1_input.dev_attr.attr, - &sensor_dev_attr_psu_fan1_speed_rpm.dev_attr.attr, - &sensor_dev_attr_psu_fan1_duty_cycle_percentage.dev_attr.attr, - &sensor_dev_attr_psu_fan_dir.dev_attr.attr, - &sensor_dev_attr_psu_pmbus_revision.dev_attr.attr, - &sensor_dev_attr_psu_mfr_id.dev_attr.attr, - &sensor_dev_attr_psu_mfr_model.dev_attr.attr, - &sensor_dev_attr_psu_mfr_revision.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vin_min.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_pout_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_iin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_pin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vout_min.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vout_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_iout_max.dev_attr.attr, - NULL -}; - -static ssize_t show_byte(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - - if (!data->valid) { - return 0; - } - - return (attr->index == PSU_PMBUS_REVISION) ? sprintf(buf, "%d\n", data->pmbus_revision) : - sprintf(buf, "0\n"); -} - -static ssize_t show_word(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - u16 status = 0; - - if (!data->valid) { - return 0; - } - - switch (attr->index) { - case PSU_POWER_ON: /* psu_power_on, low byte bit 6 of status_word, 0=>ON, 1=>OFF */ - status = (data->status_word & 0x40) ? 0 : 1; - break; - case PSU_TEMP_FAULT: /* psu_temp_fault, low byte bit 2 of status_word, 0=>Normal, 1=>temp fault */ - status = (data->status_word & 0x4) >> 2; - break; - case PSU_POWER_GOOD: /* psu_power_good, high byte bit 3 of status_word, 0=>OK, 1=>FAIL */ - status = (data->status_word & 0x800) ? 0 : 1; - break; - } - - return sprintf(buf, "%d\n", status); -} - -static int two_complement_to_int(u16 data, u8 valid_bit, int mask) -{ - u16 valid_data = data & mask; - bool is_negative = valid_data >> (valid_bit - 1); - - return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data; -} - -static ssize_t set_fan_duty_cycle(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 ym2651y_data *data = i2c_get_clientdata(client); - int nr = (attr->index == PSU_FAN1_DUTY_CYCLE) ? 0 : 1; - long speed; - int error; - - error = kstrtol(buf, 10, &speed); - if (error) - return error; - - if (speed < 0 || speed > MAX_FAN_DUTY_CYCLE) - return -EINVAL; - - mutex_lock(&data->update_lock); - data->fan_duty_cycle[nr] = speed; - ym2651y_write_word(client, 0x3B + nr, data->fan_duty_cycle[nr]); - mutex_unlock(&data->update_lock); - - return count; -} - -static ssize_t show_linear(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - - u16 value = 0; - int exponent, mantissa; - int multiplier = 1000; - - if (!data->valid) { - return 0; - } - - switch (attr->index) { - case PSU_V_OUT: - value = data->v_out; - break; - case PSU_I_OUT: - value = data->i_out; - break; - case PSU_P_OUT: - value = data->p_out; - break; - case PSU_TEMP1_INPUT: - value = data->temp; - break; - case PSU_FAN1_SPEED: - value = data->fan_speed; - multiplier = 1; - break; - case PSU_FAN1_DUTY_CYCLE: - value = data->fan_duty_cycle[0]; - multiplier = 1; - break; - case PSU_MFR_VIN_MIN: - value = data->mfr_vin_min; - break; - case PSU_MFR_VIN_MAX: - value = data->mfr_vin_max; - break; - case PSU_MFR_VOUT_MIN: - value = data->mfr_vout_min; - break; - case PSU_MFR_VOUT_MAX: - value = data->mfr_vout_max; - break; - case PSU_MFR_PIN_MAX: - value = data->mfr_pin_max; - break; - case PSU_MFR_POUT_MAX: - value = data->mfr_pout_max; - break; - case PSU_MFR_IOUT_MAX: - value = data->mfr_iout_max; - break; - case PSU_MFR_IIN_MAX: - value = data->mfr_iin_max; - break; - } - - exponent = two_complement_to_int(value >> 11, 5, 0x1f); - mantissa = two_complement_to_int(value & 0x7ff, 11, 0x7ff); - - return (exponent >= 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : - sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); -} - -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - u8 shift; - - if (!data->valid) { - return 0; - } - - shift = (attr->index == PSU_FAN1_FAULT) ? 7 : 6; - - return sprintf(buf, "%d\n", data->fan_fault >> shift); -} - -static ssize_t show_over_temp(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct ym2651y_data *data = ym2651y_update_device(dev); - - if (!data->valid) { - return 0; - } - - return sprintf(buf, "%d\n", data->over_temp >> 7); -} - -static ssize_t show_ascii(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - u8 *ptr = NULL; - - if (!data->valid) { - return 0; - } - - switch (attr->index) { - case PSU_FAN_DIRECTION: /* psu_fan_dir */ - ptr = data->fan_dir + 1; /* Skip the first byte since it is the length of string. */ - break; - case PSU_MFR_ID: /* psu_mfr_id */ - ptr = data->mfr_id + 1; /* The first byte is the count byte of string. */; - break; - case PSU_MFR_MODEL: /* psu_mfr_model */ - ptr = data->mfr_model + 1; /* The first byte is the count byte of string. */ - break; - case PSU_MFR_REVISION: /* psu_mfr_revision */ - ptr = data->mfr_revsion + 1; /* The first byte is the count byte of string. */ - break; - default: - return 0; - } - - return sprintf(buf, "%s\n", ptr); -} - -static ssize_t show_vout_by_mode(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct ym2651y_data *data = ym2651y_update_device(dev); - int exponent, mantissa; - int multiplier = 1000; - - if (!data->valid) { - return 0; - } - - exponent = two_complement_to_int(data->vout_mode, 5, 0x1f); - mantissa = data->v_out; - - return (exponent > 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : - sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); -} - -static ssize_t show_vout(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct ym2651y_data *data = i2c_get_clientdata(client); - - if (data->chip == YM2401) { - return show_vout_by_mode(dev, da, buf); - } - - return show_linear(dev, da, buf); -} - -static const struct attribute_group ym2651y_group = { - .attrs = ym2651y_attributes, -}; - -static int ym2651y_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct ym2651y_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE_DATA | - I2C_FUNC_SMBUS_WORD_DATA | - I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct ym2651y_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->chip = dev_id->driver_data; - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &ym2651y_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &ym2651y_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int ym2651y_remove(struct i2c_client *client) -{ - struct ym2651y_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &ym2651y_group); - kfree(data); - - return 0; -} - -static const struct i2c_device_id ym2651y_id[] = { - { "ym2651", YM2651 }, - { "ym2401", YM2401 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, ym2651y_id); - -static struct i2c_driver ym2651y_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "ym2651", - }, - .probe = ym2651y_probe, - .remove = ym2651y_remove, - .id_table = ym2651y_id, - .address_list = normal_i2c, -}; - -static int ym2651y_read_byte(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_byte_data(client, reg); -} - -static int ym2651y_read_word(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_word_data(client, reg); -} - -static int ym2651y_write_word(struct i2c_client *client, u8 reg, u16 value) -{ - return i2c_smbus_write_word_data(client, reg, value); -} - -static int ym2651y_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) - goto abort; - if (unlikely(result != data_len)) { - result = -EIO; - goto abort; - } - - result = 0; - -abort: - return result; -} - -struct reg_data_byte { - u8 reg; - u8 *value; -}; - -struct reg_data_word { - u8 reg; - u16 *value; -}; - -static struct ym2651y_data *ym2651y_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct ym2651y_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int i, status, length; - u8 command, buf; - struct reg_data_byte regs_byte[] = { {0x19, &data->capability}, - {0x20, &data->vout_mode}, - {0x7d, &data->over_temp}, - {0x81, &data->fan_fault}, - {0x98, &data->pmbus_revision}}; - struct reg_data_word regs_word[] = { {0x79, &data->status_word}, - {0x8b, &data->v_out}, - {0x8c, &data->i_out}, - {0x96, &data->p_out}, - {0x8d, &data->temp}, - {0x3b, &(data->fan_duty_cycle[0])}, - {0x3c, &(data->fan_duty_cycle[1])}, - {0x90, &data->fan_speed}, - {0xa0, &data->mfr_vin_min}, - {0xa1, &data->mfr_vin_max}, - {0xa2, &data->mfr_iin_max}, - {0xa3, &data->mfr_pin_max}, - {0xa4, &data->mfr_vout_min}, - {0xa5, &data->mfr_vout_max}, - {0xa6, &data->mfr_iout_max}, - {0xa7, &data->mfr_pout_max}}; - - dev_dbg(&client->dev, "Starting ym2651 update\n"); - data->valid = 0; - - /* Read byte data */ - for (i = 0; i < ARRAY_SIZE(regs_byte); i++) { - status = ym2651y_read_byte(client, regs_byte[i].reg); - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_byte[i].reg, status); - goto exit; - } - else { - *(regs_byte[i].value) = status; - } - } - - /* Read word data */ - for (i = 0; i < ARRAY_SIZE(regs_word); i++) { - status = ym2651y_read_word(client, regs_word[i].reg); - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_word[i].reg, status); - goto exit; - } - else { - *(regs_word[i].value) = status; - } - } - - /* Read fan_direction */ - command = 0xC3; - status = ym2651y_read_block(client, command, data->fan_dir, - ARRAY_SIZE(data->fan_dir)-1); - data->fan_dir[ARRAY_SIZE(data->fan_dir)-1] = '\0'; - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; - } - - /* Read mfr_id */ - command = 0x99; - status = ym2651y_read_block(client, command, data->mfr_id, - ARRAY_SIZE(data->mfr_id)-1); - data->mfr_id[ARRAY_SIZE(data->mfr_id)-1] = '\0'; - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; - } - - /* Read mfr_model */ - command = 0x9a; - length = 1; - - /* Read first byte to determine the length of data */ - status = ym2651y_read_block(client, command, &buf, length); - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; - } - - status = ym2651y_read_block(client, command, data->mfr_model, buf+1); - data->mfr_model[buf+1] = '\0'; - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; - } - - /* Read mfr_revsion */ - command = 0x9b; - status = ym2651y_read_block(client, command, data->mfr_revsion, - ARRAY_SIZE(data->mfr_revsion)-1); - data->mfr_revsion[ARRAY_SIZE(data->mfr_revsion)-1] = '\0'; - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; - } - - data->last_updated = jiffies; - data->valid = 1; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init ym2651y_init(void) -{ - return i2c_add_driver(&ym2651y_driver); -} - -static void __exit ym2651y_exit(void) -{ - i2c_del_driver(&ym2651y_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("3Y Power YM-2651Y driver"); -MODULE_LICENSE("GPL"); - -module_init(ym2651y_init); -module_exit(ym2651y_exit); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/service/as5712-platform-monitor.service b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/service/as5712-platform-monitor.service deleted file mode 100755 index da5d283a6d61..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/service/as5712-platform-monitor.service +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=Accton AS5712-54X Platform Monitoring service -Before=pmon.service -After=sysinit.target -DefaultDependencies=no - -[Service] -ExecStartPre=/usr/local/bin/accton_as5712_util.py install -ExecStart=/usr/local/bin/accton_as5712_monitor.py -KillSignal=SIGKILL -SuccessExitStatus=SIGKILL - -# Resource Limitations -LimitCORE=infinity - -[Install] -WantedBy=multi-user.target diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/setup.py b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/setup.py deleted file mode 100755 index f4cb5f960a4d..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/setup.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -from setuptools import setup -os.listdir - -setup( - name='as5712_54x', - version='1.0', - description='Module to initialize Accton AS5712-54X platforms', - - packages=['as5712_54x'], - package_dir={'as5712_54x': 'as5712-54x/classes'}, -) - diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/utils/README b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/utils/README deleted file mode 100755 index 44e03cab5f52..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/utils/README +++ /dev/null @@ -1,117 +0,0 @@ -Copyright (C) 2016 Accton Networks, Inc. - -This program is free software: you can redistribute it and/or modify -It under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Contents of this package: - patch - files under patch/ is for kernel and ONIE installer - for the kernel: - config-accton-as5712_54x.patch - for kernel configuration. - driver-i2c-muxes-pca954x-always-deselect.patch - for i2c_mux deselects after transaction. - driver-patches-for-accton-as5712-fan-psu-cpld.patch - for as5712's fan/psu/cpld/led/sfp drivers. - for ONIE: - onie_installer-accton-AS5712-54X.patch - for console port setting and copy util script o rootfs. - module - Contains source code of as5712 kernel driver modules. - -The late Sonic building scripts, pushed @Dec 5 2016, will automatically -create a docker container and run building process under it. -User is not necessary to handle docker environment creation. - -1. Download sonic-buildimage environment. - - Run "git clone https://github.com/Azure/sonic-buildimage". - - cd to sonic-buildimage and run "git submodule update --init --recursive". -2. Build kernel - - cd ./src/sonic-linux-kernel - - Copy patches and series from patch/kernel of this release to - sonic-linux-kernel/patch. - - Build kernel by "make". - - The built kernel package, linux-image-3.16.0-5-amd64_3.16.51-3+deb8u1_amd64.deb - , is generated. -3. Build installer - - Change directory back to sonic-buildimage/. - - Get onie_installer-accton-AS5712-54X.patch" from patch/installer. - - Change setting for AS5712-54X by patching build_image.sh. - "patch -p1 < onie_installer-accton-AS5712-54X.patch" - !!NOTICE, patching onie_installer-accton-AS5712-54X.patch comments out the - "git status" checking at build_image.sh. - - The account and password of installed OS can be given at rules/config. - The default user and password are "admin" & "YourPaSsWoRd" respectively. - - Run "make configure PLATFORM=broadcom" - - Copy the built kernel debian package to target/debs/. - The file is linux-image-3.16.0-5-amd64_*_amd64.deb under directory - src/sonic-linux-kernel/. - - Run "make target/sonic-generic.bin" - - Get the installer, target/sonic-generic.bin, to target machine and install. - -All Linux kernel code is licensed under the GPLv1. All other code is -licensed under the GPLv3. Please see the LICENSE file for copies of -both licenses. - -The code for integacting with Accton AS5712-54X has 2 parts, -kernel drivers and operational script. -The kernel drivers of peripherals are under module/ directory. -1. These drivers are patched into kernel by - driver-patches-for-accton-as5712-fan-psu-cpld.patch - Or you can build the driver under module/ by setting environment variable, - KERNEL_SRC, to proper linux built directory and run make. - It may be sonic-linux-kernel/linux-3.*/debian/build/build_amd64_none_amd64/. -2. A operational script, accton_as5712_util.py, for device initializatian and - peripheral accessing should be installed at /usr/bin. - This script is generated by onie_installer-accton-AS5712-54X.patch. - It's done by patching onie_installer-accton-AS5712-54X.patch at build-image. - Run "accton_as5712_util.py install" to install drivers. - -To initialize the system, run "accton_as5712_util.py install". -To clean up the drivers & devices, run "accton_as5712_util.py clean". -To dump information of sensors, run "accton_as5712_util.py show". -To dump SFP EEPROM, run "accton_as5712_util.py sff". -To set fan speed, run "accton_as5712_util.py set fan". -To enable/disable SFP emission, run "accton_as5712_util.py set sfp". -To set system LEDs' color, run "accton_as5712_util.py set led" -For more information, run "accton_as5712_util.py --help". - -==================================================================== -Besides applying accton_as5712_util.py to access peripherals, you can -access peripherals by sysfs nodes directly after the installation is run. - -System LED: - There are 5 system LEDs at the lower-left corner of front panel. - They are loc, diag, fan, ps1, and ps2. - The sysfs interface color mappings are as follows: - Brightness: - 0 => off - 1 => green - 2 => amber - 3 => red - 4 => blue - But not all colors are available for each LED. - -Fan Control: - There are 10 fans inside 5 fan modules. - All fans share 1 duty setting, ranged from 0~100. - -Thermal sensers: - 3 temperature sensors are controlled by the lm75 kernel modules. - -PSUs: - There 2 power supplies slot at the left/right side of the back. - Once if a PSU is not plugged, the status of it is shown failed. - -There are 48 SFP+ and 6 QSFP modules are equipped. -Before operating on PSU and QSFP+, please make sure it is well plugged. -Otherwise, operation is going to fail. - diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/utils/accton_as5712_monitor.py b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/utils/accton_as5712_monitor.py deleted file mode 100755 index 84ab2d83bab4..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/utils/accton_as5712_monitor.py +++ /dev/null @@ -1,195 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# -# ------------------------------------------------------------------ - -try: - import os - import sys, getopt - import subprocess - import click - import imp - import logging - import logging.config - import types - import time # this is only being used as part of the example - import traceback - from tabulate import tabulate - from as5712_54x.fanutil import FanUtil - from as5712_54x.thermalutil import ThermalUtil -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - -# Deafults -VERSION = '1.0' -FUNCTION_NAME = 'accton_as5712_monitor' - -global log_file -global log_level - -# Make a class we can use to capture stdout and sterr in the log -class accton_as5712_monitor(object): - # static temp var - _ori_temp = 0 - _new_perc = 0 - _ori_perc = 0 - - def __init__(self, log_file, log_level): - """Needs a logger and a logger level.""" - # set up logging to file - logging.basicConfig( - filename=log_file, - filemode='w', - level=log_level, - format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', - datefmt='%H:%M:%S' - ) - - # set up logging to console - if log_level == logging.DEBUG: - console = logging.StreamHandler() - console.setLevel(log_level) - formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') - console.setFormatter(formatter) - logging.getLogger('').addHandler(console) - - logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level) - - def manage_fans(self): - FAN_LEV1_UP_TEMP = 57500 # temperature - FAN_LEV1_DOWN_TEMP = 0 # unused - FAN_LEV1_SPEED_PERC = 100 # percentage*/ - - FAN_LEV2_UP_TEMP = 53000 - FAN_LEV2_DOWN_TEMP = 52700 - FAN_LEV2_SPEED_PERC = 80 - - FAN_LEV3_UP_TEMP = 49500 - FAN_LEV3_DOWN_TEMP = 47700 - FAN_LEV3_SPEED_PERC = 65 - - FAN_LEV4_UP_TEMP = 0 # unused - FAN_LEV4_DOWN_TEMP = 42700 - FAN_LEV4_SPEED_PERC = 40 - - - thermal = ThermalUtil() - fan = FanUtil() - - temp1 = thermal.get_thermal_1_val() - if temp1 is None: - return False - - temp2 = thermal.get_thermal_2_val() - if temp2 is None: - return False - - new_temp = (temp1 + temp2) / 2 - - for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1): - fan_stat = fan.get_fan_status(x) - if fan_stat is None: - return False - if fan_stat is False: - self._new_perc = FAN_LEV1_SPEED_PERC - logging.debug('INFO. SET new_perc to %d (FAN fault. fan_num:%d)', self._new_perc, x) - break - logging.debug('INFO. fan_stat is True (fan_num:%d)', x) - - if fan_stat is not None and fan_stat is not False: - diff = new_temp - self._ori_temp - if diff == 0: - logging.debug('INFO. RETURN. THERMAL temp not changed. %d / %d (new_temp / ori_temp)', new_temp, self._ori_temp) - return True - else: - if diff >= 0: - is_up = True - logging.debug('INFO. THERMAL temp UP %d / %d (new_temp / ori_temp)', new_temp, self._ori_temp) - else: - is_up = False - logging.debug('INFO. THERMAL temp DOWN %d / %d (new_temp / ori_temp)', new_temp, self._ori_temp) - - if is_up is True: - if new_temp >= FAN_LEV1_UP_TEMP: - self._new_perc = FAN_LEV1_SPEED_PERC - elif new_temp >= FAN_LEV2_UP_TEMP: - self._new_perc = FAN_LEV2_SPEED_PERC - elif new_temp >= FAN_LEV3_UP_TEMP: - self._new_perc = FAN_LEV3_SPEED_PERC - else: - self._new_perc = FAN_LEV4_SPEED_PERC - logging.debug('INFO. SET. FAN_SPEED as %d (new THERMAL temp:%d)', self._new_perc, new_temp) - else: - if new_temp <= FAN_LEV4_DOWN_TEMP: - self._new_perc = FAN_LEV4_SPEED_PERC - elif new_temp <= FAN_LEV3_DOWN_TEMP: - self._new_perc = FAN_LEV3_SPEED_PERC - elif new_temp <= FAN_LEV2_DOWN_TEMP: - self._new_perc = FAN_LEV2_SPEED_PERC - else: - self._new_perc = FAN_LEV1_SPEED_PERC - logging.debug('INFO. SET. FAN_SPEED as %d (new THERMAL temp:%d)', self._new_perc, new_temp) - - if self._ori_perc == self._new_perc: - logging.debug('INFO. RETURN. FAN speed not changed. %d / %d (new_perc / ori_perc)', self._new_perc, self._ori_perc) - return True - - set_stat = fan.set_fan_duty_cycle(fan.get_idx_fan_start(), self._new_perc) - if set_stat is True: - logging.debug('INFO: PASS. set_fan_duty_cycle (%d)', self._new_perc) - else: - logging.debug('INFO: FAIL. set_fan_duty_cycle (%d)', self._new_perc) - - logging.debug('INFO: GET. ori_perc is %d. ori_temp is %d', self._ori_perc, self._ori_temp) - self._ori_perc = self._new_perc - self._ori_temp = new_temp - logging.debug('INFO: UPDATE. ori_perc to %d. ori_temp to %d', self._ori_perc, self._ori_temp) - - return True - -def main(argv): - log_file = '%s.log' % FUNCTION_NAME - log_level = logging.INFO - if len(sys.argv) != 1: - try: - opts, args = getopt.getopt(argv,'hdl:',['lfile=']) - except getopt.GetoptError: - print 'Usage: %s [-d] [-l ]' % sys.argv[0] - return 0 - for opt, arg in opts: - if opt == '-h': - print 'Usage: %s [-d] [-l ]' % sys.argv[0] - return 0 - elif opt in ('-d', '--debug'): - log_level = logging.DEBUG - elif opt in ('-l', '--lfile'): - log_file = arg - - monitor = accton_as5712_monitor(log_file, log_level) - - # Loop forever, doing something useful hopefully: - while True: - monitor.manage_fans() - time.sleep(1) - -if __name__ == '__main__': - main(sys.argv[1:]) diff --git a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/utils/accton_as5712_util.py b/platform/broadcom/sonic-platform-modules-accton/as5712-54x/utils/accton_as5712_util.py deleted file mode 100755 index e958cb596862..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5712-54x/utils/accton_as5712_util.py +++ /dev/null @@ -1,602 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2016 Accton Networks, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" -Usage: %(scriptName)s [options] command object - -options: - -h | --help : this help message - -d | --debug : run with debug mode - -f | --force : ignore error during installation or clean -command: - install : install drivers and generate related sysfs nodes - clean : uninstall drivers and remove related sysfs nodes - show : show all systen status - sff : dump SFP eeprom - set : change board setting with fan|led|sfp -""" - -import os -import commands -import sys, getopt -import logging -import re -import time -from collections import namedtuple - -PROJECT_NAME = 'as5712_54x' -version = '0.2.0' -verbose = False -DEBUG = False -args = [] -ALL_DEVICE = {} -DEVICE_NO = {'led':5, 'fan1':1, 'fan2':1,'fan3':1,'fan4':1,'fan5':1,'thermal':3, 'psu':2, 'sfp':54} - - -led_prefix ='/sys/devices/platform/as5712_54x_led/leds/accton_'+PROJECT_NAME+'_led::' -fan_prefix ='/sys/devices/platform/as5712_54x_' -hwmon_types = {'led': ['diag','fan','loc','psu1','psu2'], - 'fan1': ['fan'], - 'fan2': ['fan'], - 'fan3': ['fan'], - 'fan4': ['fan'], - 'fan5': ['fan'], - } -hwmon_nodes = {'led': ['brightness'] , - 'fan1': ['fan1_duty_cycle_percentage', 'fan1_fault', 'fan1_speed_rpm', 'fan1_direction', 'fanr1_fault', 'fanr1_speed_rpm'], - 'fan2': ['fan2_duty_cycle_percentage','fan2_fault', 'fan2_speed_rpm', 'fan2_direction', 'fanr2_fault', 'fanr2_speed_rpm'], - 'fan3': ['fan3_duty_cycle_percentage','fan3_fault', 'fan3_speed_rpm', 'fan3_direction', 'fanr3_fault', 'fanr3_speed_rpm'], - 'fan4': ['fan4_duty_cycle_percentage','fan4_fault', 'fan4_speed_rpm', 'fan4_direction', 'fanr4_fault', 'fanr4_speed_rpm'], - 'fan5': ['fan5_duty_cycle_percentage','fan5_fault', 'fan5_speed_rpm', 'fan5_direction', 'fanr5_fault', 'fanr5_speed_rpm'], - } -hwmon_prefix ={'led': led_prefix, - 'fan1': fan_prefix, - 'fan2': fan_prefix, - 'fan3': fan_prefix, - 'fan4': fan_prefix, - 'fan5': fan_prefix, - } - -i2c_prefix = '/sys/bus/i2c/devices/' -i2c_bus = {'thermal': ['61-0048','62-0049', '63-004a'] , - 'psu': ['57-0050','58-0053'], - 'sfp': ['-0050']} -i2c_nodes = { - 'thermal': ['hwmon/hwmon*/temp1_input'] , - 'psu': ['psu_present ', 'psu_power_good'] , - 'sfp': ['sfp_is_present ', 'sfp_tx_disable']} - -sfp_map = [2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, - 50, 52, 54, 51, 53, 55] -mknod =[ -'echo as5712_54x_cpld1 0x60 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo as5712_54x_cpld2 0x61 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo as5712_54x_cpld3 0x62 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device', - -# PSU-1 -'echo as5712_54x_psu1 0x38 > /sys/bus/i2c/devices/i2c-57/new_device', -'echo cpr_4011_4mxx 0x3c > /sys/bus/i2c/devices/i2c-57/new_device', -'echo as5712_54x_psu1 0x50 > /sys/bus/i2c/devices/i2c-57/new_device', - -# PSU-2 -'echo as5712_54x_psu2 0x3b > /sys/bus/i2c/devices/i2c-58/new_device', -'echo cpr_4011_4mxx 0x3f > /sys/bus/i2c/devices/i2c-58/new_device', -'echo as5712_54x_psu2 0x53 > /sys/bus/i2c/devices/i2c-58/new_device', - -'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-61/new_device', -'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-62/new_device', -'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-63/new_device', - -#EERPOM -'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-1/new_device', -] - -mknod2 =[ -'echo as5712_54x_cpld1 0x60 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo as5712_54x_cpld2 0x61 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo as5712_54x_cpld3 0x62 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-0/new_device', - -# PSU-1 -'echo as5712_54x_psu1 0x38 > /sys/bus/i2c/devices/i2c-57/new_device', -'echo cpr_4011_4mxx 0x3c > /sys/bus/i2c/devices/i2c-57/new_device', -'echo as5712_54x_psu1 0x50 > /sys/bus/i2c/devices/i2c-57/new_device', - -# PSU-2 -'echo as5712_54x_psu2 0x3b > /sys/bus/i2c/devices/i2c-58/new_device', -'echo cpr_4011_4mxx 0x3f > /sys/bus/i2c/devices/i2c-58/new_device', -'echo as5712_54x_psu2 0x53 > /sys/bus/i2c/devices/i2c-58/new_device', - -'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-61/new_device', -'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-62/new_device', -'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-63/new_device', - -#EERPOM -'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-1/new_device', -] - -FORCE = 0 -logging.basicConfig(filename= PROJECT_NAME+'.log', filemode='w',level=logging.DEBUG) -logging.basicConfig(level=logging.INFO) - - -if DEBUG == True: - print sys.argv[0] - print 'ARGV :', sys.argv[1:] - - -def main(): - global DEBUG - global args - global FORCE - - if len(sys.argv)<2: - show_help() - - options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help', - 'debug', - 'force', - ]) - if DEBUG == True: - print options - print args - print len(sys.argv) - - for opt, arg in options: - if opt in ('-h', '--help'): - show_help() - elif opt in ('-d', '--debug'): - DEBUG = True - logging.basicConfig(level=logging.INFO) - elif opt in ('-f', '--force'): - FORCE = 1 - else: - logging.info('no option') - for arg in args: - if arg == 'install': - do_install() - elif arg == 'clean': - do_uninstall() - elif arg == 'show': - device_traversal() - elif arg == 'sff': - if len(args)!=2: - show_eeprom_help() - elif int(args[1]) ==0 or int(args[1]) > DEVICE_NO['sfp']: - show_eeprom_help() - else: - show_eeprom(args[1]) - return - elif arg == 'set': - if len(args)<3: - show_set_help() - else: - set_device(args[1:]) - return - else: - show_help() - - - return 0 - -def show_help(): - print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]} - sys.exit(0) - -def show_set_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print cmd +" [led|sfp|fan]" - print " use \""+ cmd + " led 0-4 \" to set led color" - print " use \""+ cmd + " fan 0-100\" to set fan duty percetage" - print " use \""+ cmd + " sfp 1-54 {0|1}\" to set sfp# tx_disable" - sys.exit(0) - -def show_eeprom_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print " use \""+ cmd + " 1-54 \" to dump sfp# eeprom" - sys.exit(0) - -def my_log(txt): - if DEBUG == True: - print "[ACCTON DBG]: "+txt - return - -def log_os_system(cmd, show): - logging.info('Run :'+cmd) - status = 1 - output = "" - status, output = commands.getstatusoutput(cmd) - my_log (cmd +"with result:" + str(status)) - my_log ("cmd:" + cmd) - my_log (" output:"+output) - if status: - logging.info('Failed :'+cmd) - if show: - print('Failed :'+cmd) - return status, output - -def driver_inserted(): - ret, lsmod = log_os_system("lsmod| grep accton", 0) - logging.info('mods:'+lsmod) - if len(lsmod) ==0: - return False - - - -kos = [ -'depmod -ae', -'modprobe i2c_dev', -'modprobe i2c_mux_pca954x', -'modprobe optoe', -'modprobe i2c-mux-accton_as5712_54x_cpld', -'modprobe cpr_4011_4mxx', -'modprobe ym2651y', -'modprobe accton_as5712_54x_fan', -'modprobe leds-accton_as5712_54x', -'modprobe accton_as5712_54x_psu'] - -def driver_install(): - global FORCE - for i in range(0,len(kos)): - status, output = log_os_system(kos[i], 1) - if status: - if FORCE == 0: - return status - return 0 - -def driver_uninstall(): - global FORCE - for i in range(0,len(kos)): - rm = kos[-(i+1)].replace("modprobe", "modprobe -rq") - rm = rm.replace("insmod", "rmmod") - status, output = log_os_system(rm, 1) - if status: - if FORCE == 0: - return status - return 0 - - - -def i2c_order_check(): - # i2c bus 0 and 1 might be installed in different order. - # Here check if 0x70 is exist @ i2c-0 - tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device" - status, output = log_os_system(tmp, 0) - if not device_exist(): - order = 1 - else: - order = 0 - tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-1/delete_device" - status, output = log_os_system(tmp, 0) - return order - -def device_install(): - global FORCE - - order = i2c_order_check() - # if 0x76 is not exist @i2c-0, use reversed bus order - if order: - for i in range(0,len(mknod2)): - #for pca954x need times to built new i2c buses - if mknod2[i].find('pca954') != -1: - time.sleep(2) - - status, output = log_os_system(mknod2[i], 1) - if status: - print output - if FORCE == 0: - return status - else: - for i in range(0,len(mknod)): - #for pca954x need times to built new i2c buses - if mknod[i].find('pca954') != -1: - time.sleep(2) - - status, output = log_os_system(mknod[i], 1) - if status: - print output - if FORCE == 0: - return status - - for i in range(0,len(sfp_map)): - status, output =log_os_system("echo optoe1 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1) - if status: - print output - if FORCE == 0: - return status - status, output =log_os_system("echo port"+str(i)+" > /sys/bus/i2c/devices/"+str(sfp_map[i])+"-0050/port_name", 1) - if status: - print output - if FORCE == 0: - return status - - return - -def device_uninstall(): - global FORCE - - status, output =log_os_system("ls /sys/bus/i2c/devices/0-0070", 0) - if status==0: - I2C_ORDER=1 - else: - I2C_ORDER=0 - - for i in range(0,len(sfp_map)): - target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device" - status, output =log_os_system("echo 0x50 > "+ target, 1) - if status: - print output - if FORCE == 0: - return status - - if I2C_ORDER==0: - nodelist = mknod - else: - nodelist = mknod2 - - for i in range(len(nodelist)): - target = nodelist[-(i+1)] - temp = target.split() - del temp[1] - temp[-1] = temp[-1].replace('new_device', 'delete_device') - status, output = log_os_system(" ".join(temp), 1) - if status: - print output - if FORCE == 0: - return status - - return - -def system_ready(): - if driver_inserted() == False: - return False - if not device_exist(): - return False - return True - -def do_install(): - print "Checking system...." - if driver_inserted() == False: - print "No driver, installing...." - status = driver_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" drivers detected...." - if not device_exist(): - print "No device, installing...." - status = device_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" devices detected...." - return - -def do_uninstall(): - print "Checking system...." - if not device_exist(): - print PROJECT_NAME.upper() +" has no device installed...." - else: - print "Removing device...." - status = device_uninstall() - if status: - if FORCE == 0: - return status - - if driver_inserted()== False : - print PROJECT_NAME.upper() +" has no driver installed...." - else: - print "Removing installed driver...." - status = driver_uninstall() - if status: - if FORCE == 0: - return status - - return - -def devices_info(): - global DEVICE_NO - global ALL_DEVICE - global i2c_bus, hwmon_types - for key in DEVICE_NO: - ALL_DEVICE[key]= {} - for i in range(0,DEVICE_NO[key]): - ALL_DEVICE[key][key+str(i+1)] = [] - - for key in i2c_bus: - buses = i2c_bus[key] - nodes = i2c_nodes[key] - for i in range(0,len(buses)): - for j in range(0,len(nodes)): - if 'fan' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - elif 'sfp' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ str(sfp_map[k])+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - else: - node = key+str(i+1) - path = i2c_prefix+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - - for key in hwmon_types: - itypes = hwmon_types[key] - nodes = hwmon_nodes[key] - for i in range(0,len(itypes)): - for j in range(0,len(nodes)): - node = key+"_"+itypes[i] - path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][ key+str(i+1)].append(path) - - #show dict all in the order - if DEBUG == True: - for i in sorted(ALL_DEVICE.keys()): - print(i+": ") - for j in sorted(ALL_DEVICE[i].keys()): - print(" "+j) - for k in (ALL_DEVICE[i][j]): - print(" "+" "+k) - return - -def show_eeprom(index): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0] - node = node.replace(node.split("/")[-1], 'sfp_eeprom') - # check if got hexdump command in current environment - ret, log = log_os_system("which hexdump", 0) - ret, log2 = log_os_system("which busybox hexdump", 0) - if len(log): - hex_cmd = 'hexdump' - elif len(log2): - hex_cmd = ' busybox hexdump' - else: - log = 'Failed : no hexdump cmd!!' - logging.info(log) - print log - return 1 - - print node + ":" - ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1) - if ret==0: - print log - else: - print "**********device no found**********" - return - -def set_device(args): - global DEVICE_NO - global ALL_DEVICE - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - - if args[0]=='led': - if int(args[1])>4: - show_set_help() - return - #print ALL_DEVICE['led'] - for i in range(0,len(ALL_DEVICE['led'])): - for k in (ALL_DEVICE['led']['led'+str(i+1)]): - ret, log = log_os_system("echo "+args[1]+" >"+k, 1) - if ret: - return ret - elif args[0]=='fan': - if int(args[1])>100: - show_set_help() - return - #print ALL_DEVICE['fan'] - #fan1~6 is all fine, all fan share same setting - node = ALL_DEVICE['fan1'] ['fan11'][0] - node = node.replace(node.split("/")[-1], 'fan1_duty_cycle_percentage') - ret, log = log_os_system("cat "+ node, 1) - if ret==0: - print ("Previous fan duty: " + log.strip() +"%") - ret, log = log_os_system("echo "+args[1]+" >"+node, 1) - if ret==0: - print ("Current fan duty: " + args[1] +"%") - return ret - elif args[0]=='sfp': - if int(args[1])> DEVICE_NO[args[0]] or int(args[1])==0: - show_set_help() - return - if len(args)<2: - show_set_help() - return - - if int(args[2])>1: - show_set_help() - return - - #print ALL_DEVICE[args[0]] - for i in range(0,len(ALL_DEVICE[args[0]])): - for j in ALL_DEVICE[args[0]][args[0]+str(args[1])]: - if j.find('tx_disable')!= -1: - ret, log = log_os_system("echo "+args[2]+" >"+ j, 1) - if ret: - return ret - - return - -#get digits inside a string. -#Ex: 31 for "sfp31" -def get_value(input): - digit = re.findall('\d+', input) - return int(digit[0]) - -def device_traversal(): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - for i in sorted(ALL_DEVICE.keys()): - print("============================================") - print(i.upper()+": ") - print("============================================") - - for j in sorted(ALL_DEVICE[i].keys(), key=get_value): - print " "+j+":", - for k in (ALL_DEVICE[i][j]): - ret, log = log_os_system("cat "+k, 0) - func = k.split("/")[-1].strip() - func = re.sub(j+'_','',func,1) - func = re.sub(i.lower()+'_','',func,1) - if ret==0: - print func+"="+log+" ", - else: - print func+"="+"X"+" ", - print - print("----------------------------------------------------------------") - - - print - return - -def device_exist(): - ret1, log = log_os_system("ls "+i2c_prefix+"*0070", 0) - ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0) - return not(ret1 or ret2) - -if __name__ == "__main__": - main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/Makefile b/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/Makefile deleted file mode 100644 index 697dcff656c3..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -obj-m:=accton_i2c_cpld.o x86-64-accton-as5812-54t-fan.o \ - x86-64-accton-as5812-54t-leds.o x86-64-accton-as5812-54t-psu.o \ - x86-64-accton-as5812-54t-sfp.o ym2651y.o - diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/accton_i2c_cpld.c b/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/accton_i2c_cpld.c deleted file mode 100644 index c01d6bcca228..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/accton_i2c_cpld.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * A hwmon driver for the accton_i2c_cpld - * - * Copyright (C) 2013 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include - -static LIST_HEAD(cpld_client_list); -static struct mutex list_lock; - -struct cpld_client_node { - struct i2c_client *client; - struct list_head list; -}; - -/* Addresses scanned for accton_i2c_cpld - */ -static const unsigned short normal_i2c[] = { 0x31, 0x35, 0x60, 0x61, 0x62, 0x64, I2C_CLIENT_END }; - -static ssize_t show_cpld_version(struct device *dev, struct device_attribute *attr, char *buf) -{ - int val = 0; - struct i2c_client *client = to_i2c_client(dev); - - val = i2c_smbus_read_byte_data(client, 0x1); - - if (val < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val); - } - - return sprintf(buf, "%d", val); -} - -static struct device_attribute ver = __ATTR(version, 0600, show_cpld_version, NULL); - -static void accton_i2c_cpld_add_client(struct i2c_client *client) -{ - struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); - - if (!node) { - dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); - return; - } - - node->client = client; - - mutex_lock(&list_lock); - list_add(&node->list, &cpld_client_list); - mutex_unlock(&list_lock); -} - -static void accton_i2c_cpld_remove_client(struct i2c_client *client) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int found = 0; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client == client) { - found = 1; - break; - } - } - - if (found) { - list_del(list_node); - kfree(cpld_node); - } - - mutex_unlock(&list_lock); -} - -static int accton_i2c_cpld_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - dev_dbg(&client->dev, "i2c_check_functionality failed (0x%x)\n", client->addr); - status = -EIO; - goto exit; - } - - status = sysfs_create_file(&client->dev.kobj, &ver.attr); - if (status) { - goto exit; - } - - dev_info(&client->dev, "chip found\n"); - accton_i2c_cpld_add_client(client); - - return 0; - -exit: - return status; -} - -static int accton_i2c_cpld_remove(struct i2c_client *client) -{ - sysfs_remove_file(&client->dev.kobj, &ver.attr); - accton_i2c_cpld_remove_client(client); - - return 0; -} - -static const struct i2c_device_id accton_i2c_cpld_id[] = { - { "accton_i2c_cpld", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, accton_i2c_cpld_id); - -static struct i2c_driver accton_i2c_cpld_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "accton_i2c_cpld", - }, - .probe = accton_i2c_cpld_probe, - .remove = accton_i2c_cpld_remove, - .id_table = accton_i2c_cpld_id, - .address_list = normal_i2c, -}; - -int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EPERM; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_read_byte_data(cpld_node->client, reg); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(accton_i2c_cpld_read); - -int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EIO; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(accton_i2c_cpld_write); - -static int __init accton_i2c_cpld_init(void) -{ - mutex_init(&list_lock); - return i2c_add_driver(&accton_i2c_cpld_driver); -} - -static void __exit accton_i2c_cpld_exit(void) -{ - i2c_del_driver(&accton_i2c_cpld_driver); -} - -static struct dmi_system_id as7512_dmi_table[] = { - { - .ident = "Accton AS7512", - .matches = { - DMI_MATCH(DMI_BOARD_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS7512"), - }, - }, - { - .ident = "Accton AS7512", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS7512"), - }, - }, -}; - -int platform_accton_as7512_32x(void) -{ - return dmi_check_system(as7512_dmi_table); -} -EXPORT_SYMBOL(platform_accton_as7512_32x); - -static struct dmi_system_id as7712_dmi_table[] = { - { - .ident = "Accton AS7712", - .matches = { - DMI_MATCH(DMI_BOARD_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS7712"), - }, - }, - { - .ident = "Accton AS7712", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS7712"), - }, - }, -}; - -int platform_accton_as7712_32x(void) -{ - return dmi_check_system(as7712_dmi_table); -} -EXPORT_SYMBOL(platform_accton_as7712_32x); - -static struct dmi_system_id as5812_54t_dmi_table[] = { - { - .ident = "Accton AS5812 54t", - .matches = { - DMI_MATCH(DMI_BOARD_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS5812-54T"), - }, - }, - { - .ident = "Accton AS5812 54t", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS5812-54T"), - }, - }, -}; - -int platform_accton_as5812_54t(void) -{ - return dmi_check_system(as5812_54t_dmi_table); -} -EXPORT_SYMBOL(platform_accton_as5812_54t); - -static struct dmi_system_id as5512_54x_dmi_table[] = { - { - .ident = "Accton AS5512", - .matches = { - DMI_MATCH(DMI_BOARD_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS5512"), - }, - }, - { - .ident = "Accton AS5512", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS5512"), - }, - }, -}; - -int platform_accton_as5512_54x(void) -{ - return dmi_check_system(as5512_54x_dmi_table); -} -EXPORT_SYMBOL(platform_accton_as5512_54x); - -static struct dmi_system_id as7716_dmi_table[] = { - { - .ident = "Accton AS7716", - .matches = { - DMI_MATCH(DMI_BOARD_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS7716"), - }, - }, - { - .ident = "Accton AS7716", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS7716"), - }, - }, -}; - -int platform_accton_as7716_32x(void) -{ - return dmi_check_system(as7716_dmi_table); -} -EXPORT_SYMBOL(platform_accton_as7716_32x); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton_i2c_cpld driver"); -MODULE_LICENSE("GPL"); - -module_init(accton_i2c_cpld_init); -module_exit(accton_i2c_cpld_exit); diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/x86-64-accton-as5812-54t-fan.c b/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/x86-64-accton-as5812-54t-fan.c deleted file mode 100644 index bad9245e93ac..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/x86-64-accton-as5812-54t-fan.c +++ /dev/null @@ -1,442 +0,0 @@ -/* - * A hwmon driver for the Accton as5812 54t fan - * - * Copyright (C) 2015 Accton Technology Corporation. - * Brandon Chuang - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define FAN_MAX_NUMBER 5 -#define FAN_SPEED_CPLD_TO_RPM_STEP 150 -#define FAN_SPEED_PRECENT_TO_CPLD_STEP 5 -#define FAN_DUTY_CYCLE_MIN 0 -#define FAN_DUTY_CYCLE_MAX 100 /* 100% */ - -#define CPLD_REG_FAN_STATUS_OFFSET 0xC -#define CPLD_REG_FANR_STATUS_OFFSET 0x1F -#define CPLD_REG_FAN_DIRECTION_OFFSET 0x1E - -#define CPLD_FAN1_REG_SPEED_OFFSET 0x10 -#define CPLD_FAN2_REG_SPEED_OFFSET 0x11 -#define CPLD_FAN3_REG_SPEED_OFFSET 0x12 -#define CPLD_FAN4_REG_SPEED_OFFSET 0x13 -#define CPLD_FAN5_REG_SPEED_OFFSET 0x14 - -#define CPLD_FANR1_REG_SPEED_OFFSET 0x18 -#define CPLD_FANR2_REG_SPEED_OFFSET 0x19 -#define CPLD_FANR3_REG_SPEED_OFFSET 0x1A -#define CPLD_FANR4_REG_SPEED_OFFSET 0x1B -#define CPLD_FANR5_REG_SPEED_OFFSET 0x1C - -#define CPLD_REG_FAN_PWM_CYCLE_OFFSET 0xD - -#define CPLD_FAN1_INFO_BIT_MASK 0x1 -#define CPLD_FAN2_INFO_BIT_MASK 0x2 -#define CPLD_FAN3_INFO_BIT_MASK 0x4 -#define CPLD_FAN4_INFO_BIT_MASK 0x8 -#define CPLD_FAN5_INFO_BIT_MASK 0x10 - -#define PROJECT_NAME - -#define LOCAL_DEBUG 0 - -static struct accton_as5812_54t_fan *fan_data = NULL; - -struct accton_as5812_54t_fan { - struct platform_device *pdev; - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 status[FAN_MAX_NUMBER]; /* inner first fan status */ - u32 speed[FAN_MAX_NUMBER]; /* inner first fan speed */ - u8 direction[FAN_MAX_NUMBER]; /* reconrd the direction of inner first and second fans */ - u32 duty_cycle[FAN_MAX_NUMBER]; /* control the speed of inner first and second fans */ - u8 r_status[FAN_MAX_NUMBER]; /* inner second fan status */ - u32 r_speed[FAN_MAX_NUMBER]; /* inner second fan speed */ -}; - -/*******************/ -#define MAKE_FAN_MASK_OR_REG(name,type) \ - CPLD_FAN##type##1_##name, \ - CPLD_FAN##type##2_##name, \ - CPLD_FAN##type##3_##name, \ - CPLD_FAN##type##4_##name, \ - CPLD_FAN##type##5_##name, - -/* fan related data - */ -static const u8 fan_info_mask[] = { - MAKE_FAN_MASK_OR_REG(INFO_BIT_MASK,) -}; - -static const u8 fan_speed_reg[] = { - MAKE_FAN_MASK_OR_REG(REG_SPEED_OFFSET,) -}; - -static const u8 fanr_speed_reg[] = { - MAKE_FAN_MASK_OR_REG(REG_SPEED_OFFSET,R) -}; - -/*******************/ -#define DEF_FAN_SET(id) \ - FAN##id##_FAULT, \ - FAN##id##_SPEED, \ - FAN##id##_DUTY_CYCLE, \ - FAN##id##_DIRECTION, \ - FANR##id##_FAULT, \ - FANR##id##_SPEED, - -enum sysfs_fan_attributes { - DEF_FAN_SET(1) - DEF_FAN_SET(2) - DEF_FAN_SET(3) - DEF_FAN_SET(4) - DEF_FAN_SET(5) -}; -/*******************/ -static void accton_as5812_54t_fan_update_device(struct device *dev); -static int accton_as5812_54t_fan_read_value(u8 reg); -static int accton_as5812_54t_fan_write_value(u8 reg, u8 value); - -static ssize_t fan_set_duty_cycle(struct device *dev, - struct device_attribute *da,const char *buf, size_t count); -static ssize_t fan_show_value(struct device *dev, - struct device_attribute *da, char *buf); - -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - - -/*******************/ -#define _MAKE_SENSOR_DEVICE_ATTR(prj, id) \ - static SENSOR_DEVICE_ATTR(prj##fan##id##_fault, S_IRUGO, fan_show_value, NULL, FAN##id##_FAULT); \ - static SENSOR_DEVICE_ATTR(prj##fan##id##_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##id##_SPEED); \ - static SENSOR_DEVICE_ATTR(prj##fan##id##_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_show_value, \ - fan_set_duty_cycle, FAN##id##_DUTY_CYCLE); \ - static SENSOR_DEVICE_ATTR(prj##fan##id##_direction, S_IRUGO, fan_show_value, NULL, FAN##id##_DIRECTION); \ - static SENSOR_DEVICE_ATTR(prj##fanr##id##_fault, S_IRUGO, fan_show_value, NULL, FANR##id##_FAULT); \ - static SENSOR_DEVICE_ATTR(prj##fanr##id##_speed_rpm, S_IRUGO, fan_show_value, NULL, FANR##id##_SPEED); - -#define MAKE_SENSOR_DEVICE_ATTR(prj,id) _MAKE_SENSOR_DEVICE_ATTR(prj,id) - -MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 1) -MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 2) -MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 3) -MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 4) -MAKE_SENSOR_DEVICE_ATTR(PROJECT_NAME, 5) -/*******************/ - -#define _MAKE_FAN_ATTR(prj, id) \ - &sensor_dev_attr_##prj##fan##id##_fault.dev_attr.attr, \ - &sensor_dev_attr_##prj##fan##id##_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_##prj##fan##id##_duty_cycle_percentage.dev_attr.attr,\ - &sensor_dev_attr_##prj##fan##id##_direction.dev_attr.attr, \ - &sensor_dev_attr_##prj##fanr##id##_fault.dev_attr.attr, \ - &sensor_dev_attr_##prj##fanr##id##_speed_rpm.dev_attr.attr, - -#define MAKE_FAN_ATTR(prj, id) _MAKE_FAN_ATTR(prj, id) - -static struct attribute *accton_as5812_54t_fan_attributes[] = { - /* fan related attributes */ - MAKE_FAN_ATTR(PROJECT_NAME,1) - MAKE_FAN_ATTR(PROJECT_NAME,2) - MAKE_FAN_ATTR(PROJECT_NAME,3) - MAKE_FAN_ATTR(PROJECT_NAME,4) - MAKE_FAN_ATTR(PROJECT_NAME,5) - NULL -}; -/*******************/ - -/* fan related functions - */ -static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - ssize_t ret = 0; - int data_index, type_index; - - accton_as5812_54t_fan_update_device(dev); - - if (fan_data->valid == 0) { - return ret; - } - - type_index = attr->index%FAN2_FAULT; - data_index = attr->index/FAN2_FAULT; - - switch (type_index) { - case FAN1_FAULT: - ret = sprintf(buf, "%d\n", fan_data->status[data_index]); - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); - break; - case FAN1_SPEED: - ret = sprintf(buf, "%d\n", fan_data->speed[data_index]); - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); - break; - case FAN1_DUTY_CYCLE: - ret = sprintf(buf, "%d\n", fan_data->duty_cycle[data_index]); - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); - break; - case FAN1_DIRECTION: - ret = sprintf(buf, "%d\n", fan_data->direction[data_index]); /* presnet, need to modify*/ - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); - break; - case FANR1_FAULT: - ret = sprintf(buf, "%d\n", fan_data->r_status[data_index]); - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); - break; - case FANR1_SPEED: - ret = sprintf(buf, "%d\n", fan_data->r_speed[data_index]); - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d][type->index=%d][data->index=%d]\n", __FUNCTION__, __LINE__, type_index, data_index); - break; - default: - if (LOCAL_DEBUG) - printk ("[Check !!][%s][%d] \n", __FUNCTION__, __LINE__); - break; - } - - return ret; -} -/*******************/ -static ssize_t fan_set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) { - - int error, value; - - error = kstrtoint(buf, 10, &value); - if (error) - return error; - - if (value < FAN_DUTY_CYCLE_MIN || value > FAN_DUTY_CYCLE_MAX) - return -EINVAL; - - accton_as5812_54t_fan_write_value(CPLD_REG_FAN_PWM_CYCLE_OFFSET, value/FAN_SPEED_PRECENT_TO_CPLD_STEP); - - fan_data->valid = 0; - - return count; -} - -static const struct attribute_group accton_as5812_54t_fan_group = { - .attrs = accton_as5812_54t_fan_attributes, -}; - -static int accton_as5812_54t_fan_read_value(u8 reg) -{ - return accton_i2c_cpld_read(0x60, reg); -} - -static int accton_as5812_54t_fan_write_value(u8 reg, u8 value) -{ - return accton_i2c_cpld_write(0x60, reg, value); -} - -static void accton_as5812_54t_fan_update_device(struct device *dev) -{ - int speed, r_speed, fault, r_fault, ctrl_speed, direction; - int i; - - mutex_lock(&fan_data->update_lock); - - if (LOCAL_DEBUG) - printk ("Starting accton_as5812_54t_fan update \n"); - - if (!(time_after(jiffies, fan_data->last_updated + HZ + HZ / 2) || !fan_data->valid)) { - /* do nothing */ - goto _exit; - } - - fan_data->valid = 0; - - if (LOCAL_DEBUG) - printk ("Starting accton_as5812_54t_fan update 2 \n"); - - fault = accton_as5812_54t_fan_read_value(CPLD_REG_FAN_STATUS_OFFSET); - r_fault = accton_as5812_54t_fan_read_value(CPLD_REG_FANR_STATUS_OFFSET); - direction = accton_as5812_54t_fan_read_value(CPLD_REG_FAN_DIRECTION_OFFSET); - ctrl_speed = accton_as5812_54t_fan_read_value(CPLD_REG_FAN_PWM_CYCLE_OFFSET); - - if ( (fault < 0) || (r_fault < 0) || (direction < 0) || (ctrl_speed < 0) ) - { - if (LOCAL_DEBUG) - printk ("[Error!!][%s][%d] \n", __FUNCTION__, __LINE__); - goto _exit; /* error */ - } - - if (LOCAL_DEBUG) - printk ("[fan:] fault:%d, r_fault=%d, direction=%d, ctrl_speed=%d \n",fault, r_fault, direction, ctrl_speed); - - for (i=0; istatus[i] = (fault & fan_info_mask[i]) >> i; - if (LOCAL_DEBUG) - printk ("[fan%d:] fail=%d \n",i, fan_data->status[i]); - - fan_data->r_status[i] = (r_fault & fan_info_mask[i]) >> i; - fan_data->direction[i] = (direction & fan_info_mask[i]) >> i; - fan_data->duty_cycle[i] = ctrl_speed * FAN_SPEED_PRECENT_TO_CPLD_STEP; - - /* fan speed - */ - speed = accton_as5812_54t_fan_read_value(fan_speed_reg[i]); - r_speed = accton_as5812_54t_fan_read_value(fanr_speed_reg[i]); - if ( (speed < 0) || (r_speed < 0) ) - { - if (LOCAL_DEBUG) - printk ("[Error!!][%s][%d] \n", __FUNCTION__, __LINE__); - goto _exit; /* error */ - } - - if (LOCAL_DEBUG) - printk ("[fan%d:] speed:%d, r_speed=%d \n", i, speed, r_speed); - - fan_data->speed[i] = speed * FAN_SPEED_CPLD_TO_RPM_STEP; - fan_data->r_speed[i] = r_speed * FAN_SPEED_CPLD_TO_RPM_STEP; - } - - /* finish to update */ - fan_data->last_updated = jiffies; - fan_data->valid = 1; - -_exit: - mutex_unlock(&fan_data->update_lock); -} - -static int accton_as5812_54t_fan_probe(struct platform_device *pdev) -{ - int status = -1; - - /* Register sysfs hooks */ - status = sysfs_create_group(&pdev->dev.kobj, &accton_as5812_54t_fan_group); - if (status) { - goto exit; - - } - - fan_data->hwmon_dev = hwmon_device_register(&pdev->dev); - if (IS_ERR(fan_data->hwmon_dev)) { - status = PTR_ERR(fan_data->hwmon_dev); - goto exit_remove; - } - - dev_info(&pdev->dev, "accton_as5812_54t_fan\n"); - - return 0; - -exit_remove: - sysfs_remove_group(&pdev->dev.kobj, &accton_as5812_54t_fan_group); -exit: - return status; -} - -static int accton_as5812_54t_fan_remove(struct platform_device *pdev) -{ - hwmon_device_unregister(fan_data->hwmon_dev); - sysfs_remove_group(&fan_data->pdev->dev.kobj, &accton_as5812_54t_fan_group); - - return 0; -} - -#define DRVNAME "as5812_54t_fan" - -static struct platform_driver accton_as5812_54t_fan_driver = { - .probe = accton_as5812_54t_fan_probe, - .remove = accton_as5812_54t_fan_remove, - .driver = { - .name = DRVNAME, - .owner = THIS_MODULE, - }, -}; - -static int __init accton_as5812_54t_fan_init(void) -{ - int ret; - - extern int platform_accton_as5812_54t(void); - if (!platform_accton_as5812_54t()) { - return -ENODEV; - } - - ret = platform_driver_register(&accton_as5812_54t_fan_driver); - if (ret < 0) { - goto exit; - } - - fan_data = kzalloc(sizeof(struct accton_as5812_54t_fan), GFP_KERNEL); - if (!fan_data) { - ret = -ENOMEM; - platform_driver_unregister(&accton_as5812_54t_fan_driver); - goto exit; - } - - mutex_init(&fan_data->update_lock); - fan_data->valid = 0; - - fan_data->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); - if (IS_ERR(fan_data->pdev)) { - ret = PTR_ERR(fan_data->pdev); - platform_driver_unregister(&accton_as5812_54t_fan_driver); - kfree(fan_data); - goto exit; - } - -exit: - return ret; -} - -static void __exit accton_as5812_54t_fan_exit(void) -{ - platform_device_unregister(fan_data->pdev); - platform_driver_unregister(&accton_as5812_54t_fan_driver); - kfree(fan_data); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton_as5812_54t_fan driver"); -MODULE_LICENSE("GPL"); - -module_init(accton_as5812_54t_fan_init); -module_exit(accton_as5812_54t_fan_exit); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/x86-64-accton-as5812-54t-leds.c b/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/x86-64-accton-as5812-54t-leds.c deleted file mode 100644 index 011f62e76c06..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/x86-64-accton-as5812-54t-leds.c +++ /dev/null @@ -1,601 +0,0 @@ -/* - * A LED driver for the accton_as5812_54t_led - * - * Copyright (C) 2015 Accton Technology Corporation. - * Brandon Chuang - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/*#define DEBUG*/ - -#include -#include -#include -#include -#include -#include -#include - -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -extern void led_classdev_unregister(struct led_classdev *led_cdev); -extern int led_classdev_register(struct device *parent, struct led_classdev *led_cdev); -extern void led_classdev_resume(struct led_classdev *led_cdev); -extern void led_classdev_suspend(struct led_classdev *led_cdev); - -#define DRVNAME "as5812_54t_led" - -struct accton_as5812_54t_led_data { - struct platform_device *pdev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[4]; /* Register value, 0 = LOC/DIAG/FAN LED - 1 = PSU1/PSU2 LED - 2 = FAN1-4 LED - 3 = FAN5-6 LED */ -}; - -static struct accton_as5812_54t_led_data *ledctl = NULL; - -/* LED related data - */ -#define LED_TYPE_PSU1_REG_MASK 0x03 -#define LED_MODE_PSU1_GREEN_MASK 0x02 -#define LED_MODE_PSU1_AMBER_MASK 0x01 -#define LED_MODE_PSU1_OFF_MASK 0x03 -#define LED_MODE_PSU1_AUTO_MASK 0x00 - -#define LED_TYPE_PSU2_REG_MASK 0x0C -#define LED_MODE_PSU2_GREEN_MASK 0x08 -#define LED_MODE_PSU2_AMBER_MASK 0x04 -#define LED_MODE_PSU2_OFF_MASK 0x0C -#define LED_MODE_PSU2_AUTO_MASK 0x00 - -#define LED_TYPE_DIAG_REG_MASK 0x0C -#define LED_MODE_DIAG_GREEN_MASK 0x08 -#define LED_MODE_DIAG_AMBER_MASK 0x04 -#define LED_MODE_DIAG_OFF_MASK 0x0C - -#define LED_TYPE_FAN_REG_MASK 0x03 -#define LED_MODE_FAN_GREEN_MASK 0x02 -#define LED_MODE_FAN_AMBER_MASK 0x01 -#define LED_MODE_FAN_OFF_MASK 0x03 -#define LED_MODE_FAN_AUTO_MASK 0x00 - -#define LED_TYPE_FAN1_REG_MASK 0x03 -#define LED_TYPE_FAN2_REG_MASK 0x0C -#define LED_TYPE_FAN3_REG_MASK 0x30 -#define LED_TYPE_FAN4_REG_MASK 0xC0 -#define LED_TYPE_FAN5_REG_MASK 0x03 -#define LED_TYPE_FAN6_REG_MASK 0x0C - -#define LED_MODE_FANX_GREEN_MASK 0x01 -#define LED_MODE_FANX_RED_MASK 0x02 -#define LED_MODE_FANX_OFF_MASK 0x00 - -#define LED_TYPE_LOC_REG_MASK 0x30 -#define LED_MODE_LOC_ON_MASK 0x00 -#define LED_MODE_LOC_OFF_MASK 0x10 -#define LED_MODE_LOC_BLINK_MASK 0x20 - -static const u8 led_reg[] = { - 0xA, /* LOC/DIAG/FAN LED*/ - 0xB, /* PSU1/PSU2 LED */ - 0x16, /* FAN1-4 LED */ - 0x17, /* FAN4-6 LED */ -}; - -enum led_type { - LED_TYPE_PSU1, - LED_TYPE_PSU2, - LED_TYPE_DIAG, - LED_TYPE_FAN, - LED_TYPE_FAN1, - LED_TYPE_FAN2, - LED_TYPE_FAN3, - LED_TYPE_FAN4, - LED_TYPE_FAN5, - LED_TYPE_LOC -}; - -enum led_light_mode { - LED_MODE_OFF = 0, - LED_MODE_GREEN, - LED_MODE_GREEN_BLINK, - LED_MODE_AMBER, - LED_MODE_AMBER_BLINK, - LED_MODE_RED, - LED_MODE_RED_BLINK, - LED_MODE_BLUE, - LED_MODE_BLUE_BLINK, - LED_MODE_AUTO, - LED_MODE_UNKNOWN -}; - -struct led_type_mode { - enum led_type type; - int type_mask; - enum led_light_mode mode; - int mode_mask; -}; - -static struct led_type_mode led_type_mode_data[] = { -{LED_TYPE_PSU1, LED_TYPE_PSU1_REG_MASK, LED_MODE_GREEN, LED_MODE_PSU1_GREEN_MASK}, -{LED_TYPE_PSU1, LED_TYPE_PSU1_REG_MASK, LED_MODE_AMBER, LED_MODE_PSU1_AMBER_MASK}, -{LED_TYPE_PSU1, LED_TYPE_PSU1_REG_MASK, LED_MODE_AUTO, LED_MODE_PSU1_AUTO_MASK}, -{LED_TYPE_PSU1, LED_TYPE_PSU1_REG_MASK, LED_MODE_OFF, LED_MODE_PSU1_OFF_MASK}, -{LED_TYPE_PSU2, LED_TYPE_PSU2_REG_MASK, LED_MODE_GREEN, LED_MODE_PSU2_GREEN_MASK}, -{LED_TYPE_PSU2, LED_TYPE_PSU2_REG_MASK, LED_MODE_AMBER, LED_MODE_PSU2_AMBER_MASK}, -{LED_TYPE_PSU2, LED_TYPE_PSU2_REG_MASK, LED_MODE_AUTO, LED_MODE_PSU2_AUTO_MASK}, -{LED_TYPE_PSU2, LED_TYPE_PSU2_REG_MASK, LED_MODE_OFF, LED_MODE_PSU2_OFF_MASK}, -{LED_TYPE_FAN, LED_TYPE_FAN_REG_MASK, LED_MODE_GREEN, LED_MODE_FAN_GREEN_MASK}, -{LED_TYPE_FAN, LED_TYPE_FAN_REG_MASK, LED_MODE_AMBER, LED_MODE_FAN_AMBER_MASK}, -{LED_TYPE_FAN, LED_TYPE_FAN_REG_MASK, LED_MODE_AUTO, LED_MODE_FAN_AUTO_MASK}, -{LED_TYPE_FAN, LED_TYPE_FAN_REG_MASK, LED_MODE_OFF, LED_MODE_FAN_OFF_MASK}, -{LED_TYPE_FAN1, LED_TYPE_FAN1_REG_MASK, LED_MODE_GREEN, LED_MODE_FANX_GREEN_MASK << 0}, -{LED_TYPE_FAN1, LED_TYPE_FAN1_REG_MASK, LED_MODE_RED, LED_MODE_FANX_RED_MASK << 0}, -{LED_TYPE_FAN1, LED_TYPE_FAN1_REG_MASK, LED_MODE_OFF, LED_MODE_FANX_OFF_MASK << 0}, -{LED_TYPE_FAN2, LED_TYPE_FAN2_REG_MASK, LED_MODE_GREEN, LED_MODE_FANX_GREEN_MASK << 2}, -{LED_TYPE_FAN2, LED_TYPE_FAN2_REG_MASK, LED_MODE_RED, LED_MODE_FANX_RED_MASK << 2}, -{LED_TYPE_FAN2, LED_TYPE_FAN2_REG_MASK, LED_MODE_OFF, LED_MODE_FANX_OFF_MASK << 2}, -{LED_TYPE_FAN3, LED_TYPE_FAN3_REG_MASK, LED_MODE_GREEN, LED_MODE_FANX_GREEN_MASK << 4}, -{LED_TYPE_FAN3, LED_TYPE_FAN3_REG_MASK, LED_MODE_RED, LED_MODE_FANX_RED_MASK << 4}, -{LED_TYPE_FAN3, LED_TYPE_FAN3_REG_MASK, LED_MODE_OFF, LED_MODE_FANX_OFF_MASK << 4}, -{LED_TYPE_FAN4, LED_TYPE_FAN4_REG_MASK, LED_MODE_GREEN, LED_MODE_FANX_GREEN_MASK << 6}, -{LED_TYPE_FAN4, LED_TYPE_FAN4_REG_MASK, LED_MODE_RED, LED_MODE_FANX_RED_MASK << 6}, -{LED_TYPE_FAN4, LED_TYPE_FAN4_REG_MASK, LED_MODE_OFF, LED_MODE_FANX_OFF_MASK << 6}, -{LED_TYPE_FAN5, LED_TYPE_FAN5_REG_MASK, LED_MODE_GREEN, LED_MODE_FANX_GREEN_MASK << 0}, -{LED_TYPE_FAN5, LED_TYPE_FAN5_REG_MASK, LED_MODE_RED, LED_MODE_FANX_RED_MASK << 0}, -{LED_TYPE_FAN5, LED_TYPE_FAN5_REG_MASK, LED_MODE_OFF, LED_MODE_FANX_OFF_MASK << 0}, -{LED_TYPE_DIAG, LED_TYPE_DIAG_REG_MASK, LED_MODE_GREEN, LED_MODE_DIAG_GREEN_MASK}, -{LED_TYPE_DIAG, LED_TYPE_DIAG_REG_MASK, LED_MODE_AMBER, LED_MODE_DIAG_AMBER_MASK}, -{LED_TYPE_DIAG, LED_TYPE_DIAG_REG_MASK, LED_MODE_OFF, LED_MODE_DIAG_OFF_MASK}, -{LED_TYPE_LOC, LED_TYPE_LOC_REG_MASK, LED_MODE_AMBER, LED_MODE_LOC_ON_MASK}, -{LED_TYPE_LOC, LED_TYPE_LOC_REG_MASK, LED_MODE_OFF, LED_MODE_LOC_OFF_MASK}, -{LED_TYPE_LOC, LED_TYPE_LOC_REG_MASK, LED_MODE_AMBER_BLINK, LED_MODE_LOC_BLINK_MASK} -}; - - -struct fanx_info_s { - u8 cname; /* device name */ - enum led_type type; - u8 reg_id; /* map to led_reg & reg_val */ -}; - -static struct fanx_info_s fanx_info[] = { - {'1', LED_TYPE_FAN1, 2}, - {'2', LED_TYPE_FAN2, 2}, - {'3', LED_TYPE_FAN3, 2}, - {'4', LED_TYPE_FAN4, 2}, - {'5', LED_TYPE_FAN5, 3} -}; - -static int led_reg_val_to_light_mode(enum led_type type, u8 reg_val) { - int i; - - for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) { - - if (type != led_type_mode_data[i].type) - continue; - - if ((led_type_mode_data[i].type_mask & reg_val) == - led_type_mode_data[i].mode_mask) - { - return led_type_mode_data[i].mode; - } - } - - return LED_MODE_UNKNOWN; -} - -static u8 led_light_mode_to_reg_val(enum led_type type, - enum led_light_mode mode, u8 reg_val) { - int i; - - for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) { - if (type != led_type_mode_data[i].type) - continue; - - if (mode != led_type_mode_data[i].mode) - continue; - - reg_val = led_type_mode_data[i].mode_mask | - (reg_val & (~led_type_mode_data[i].type_mask)); - } - - return reg_val; -} - -static int accton_as5812_54t_led_read_value(u8 reg) -{ - return accton_i2c_cpld_read(0x60, reg); -} - -static int accton_as5812_54t_led_write_value(u8 reg, u8 value) -{ - return accton_i2c_cpld_write(0x60, reg, value); -} - -static void accton_as5812_54t_led_update(void) -{ - mutex_lock(&ledctl->update_lock); - - if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2) - || !ledctl->valid) { - int i; - - dev_dbg(&ledctl->pdev->dev, "Starting accton_as5812_54t_led update\n"); - - /* Update LED data - */ - for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { - int status = accton_as5812_54t_led_read_value(led_reg[i]); - - if (status < 0) { - ledctl->valid = 0; - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg[i], status); - goto exit; - } - else - { - ledctl->reg_val[i] = status; - } - } - - ledctl->last_updated = jiffies; - ledctl->valid = 1; - } - -exit: - mutex_unlock(&ledctl->update_lock); -} - -static void accton_as5812_54t_led_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode, - u8 reg, enum led_type type) -{ - int reg_val; - - mutex_lock(&ledctl->update_lock); - - reg_val = accton_as5812_54t_led_read_value(reg); - - if (reg_val < 0) { - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val); - goto exit; - } - - reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val); - accton_as5812_54t_led_write_value(reg, reg_val); - - /* to prevent the slow-update issue */ - ledctl->valid = 0; - -exit: - mutex_unlock(&ledctl->update_lock); -} - -static void accton_as5812_54t_led_psu_1_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as5812_54t_led_set(led_cdev, led_light_mode, led_reg[1], LED_TYPE_PSU1); -} - -static enum led_brightness accton_as5812_54t_led_psu_1_get(struct led_classdev *cdev) -{ - accton_as5812_54t_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_PSU1, ledctl->reg_val[1]); -} - -static void accton_as5812_54t_led_psu_2_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as5812_54t_led_set(led_cdev, led_light_mode, led_reg[1], LED_TYPE_PSU2); -} - -static enum led_brightness accton_as5812_54t_led_psu_2_get(struct led_classdev *cdev) -{ - accton_as5812_54t_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_PSU2, ledctl->reg_val[1]); -} - -static void accton_as5812_54t_led_fan_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as5812_54t_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_FAN); -} - -static enum led_brightness accton_as5812_54t_led_fan_get(struct led_classdev *cdev) -{ - accton_as5812_54t_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_FAN, ledctl->reg_val[0]); -} - - -static void accton_as5812_54t_led_fanx_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - enum led_type led_type1; - int reg_id; - int i, nsize; - int ncount = sizeof(fanx_info)/sizeof(struct fanx_info_s); - - for(i=0;iname); - - if (led_cdev->name[nsize-1] == fanx_info[i].cname) - { - led_type1 = fanx_info[i].type; - reg_id = fanx_info[i].reg_id; - accton_as5812_54t_led_set(led_cdev, led_light_mode, led_reg[reg_id], led_type1); - return; - } - } -} - - -static enum led_brightness accton_as5812_54t_led_fanx_get(struct led_classdev *cdev) -{ - enum led_type led_type1; - int reg_id; - int i, nsize; - int ncount = sizeof(fanx_info)/sizeof(struct fanx_info_s); - - for(i=0;iname); - - if (cdev->name[nsize-1] == fanx_info[i].cname) - { - led_type1 = fanx_info[i].type; - reg_id = fanx_info[i].reg_id; - accton_as5812_54t_led_update(); - return led_reg_val_to_light_mode(led_type1, ledctl->reg_val[reg_id]); - } - } - - - return led_reg_val_to_light_mode(LED_TYPE_FAN1, ledctl->reg_val[2]); -} - - -static void accton_as5812_54t_led_diag_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as5812_54t_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_DIAG); -} - -static enum led_brightness accton_as5812_54t_led_diag_get(struct led_classdev *cdev) -{ - accton_as5812_54t_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); -} - -static void accton_as5812_54t_led_loc_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as5812_54t_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_LOC); -} - -static enum led_brightness accton_as5812_54t_led_loc_get(struct led_classdev *cdev) -{ - accton_as5812_54t_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); -} - -static struct led_classdev accton_as5812_54t_leds[] = { - [LED_TYPE_PSU1] = { - .name = "accton_as5812_54t_led::psu1", - .default_trigger = "unused", - .brightness_set = accton_as5812_54t_led_psu_1_set, - .brightness_get = accton_as5812_54t_led_psu_1_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_PSU2] = { - .name = "accton_as5812_54t_led::psu2", - .default_trigger = "unused", - .brightness_set = accton_as5812_54t_led_psu_2_set, - .brightness_get = accton_as5812_54t_led_psu_2_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_FAN] = { - .name = "accton_as5812_54t_led::fan", - .default_trigger = "unused", - .brightness_set = accton_as5812_54t_led_fan_set, - .brightness_get = accton_as5812_54t_led_fan_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_FAN1] = { - .name = "accton_as5812_54t_led::fan1", - .default_trigger = "unused", - .brightness_set = accton_as5812_54t_led_fanx_set, - .brightness_get = accton_as5812_54t_led_fanx_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_FAN2] = { - .name = "accton_as5812_54t_led::fan2", - .default_trigger = "unused", - .brightness_set = accton_as5812_54t_led_fanx_set, - .brightness_get = accton_as5812_54t_led_fanx_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_FAN3] = { - .name = "accton_as5812_54t_led::fan3", - .default_trigger = "unused", - .brightness_set = accton_as5812_54t_led_fanx_set, - .brightness_get = accton_as5812_54t_led_fanx_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_FAN4] = { - .name = "accton_as5812_54t_led::fan4", - .default_trigger = "unused", - .brightness_set = accton_as5812_54t_led_fanx_set, - .brightness_get = accton_as5812_54t_led_fanx_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_FAN5] = { - .name = "accton_as5812_54t_led::fan5", - .default_trigger = "unused", - .brightness_set = accton_as5812_54t_led_fanx_set, - .brightness_get = accton_as5812_54t_led_fanx_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_DIAG] = { - .name = "accton_as5812_54t_led::diag", - .default_trigger = "unused", - .brightness_set = accton_as5812_54t_led_diag_set, - .brightness_get = accton_as5812_54t_led_diag_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_LOC] = { - .name = "accton_as5812_54t_led::loc", - .default_trigger = "unused", - .brightness_set = accton_as5812_54t_led_loc_set, - .brightness_get = accton_as5812_54t_led_loc_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, -}; - -static int accton_as5812_54t_led_suspend(struct platform_device *dev, - pm_message_t state) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(accton_as5812_54t_leds); i++) { - led_classdev_suspend(&accton_as5812_54t_leds[i]); - } - - return 0; -} - -static int accton_as5812_54t_led_resume(struct platform_device *dev) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(accton_as5812_54t_leds); i++) { - led_classdev_resume(&accton_as5812_54t_leds[i]); - } - - return 0; -} - -static int accton_as5812_54t_led_probe(struct platform_device *pdev) -{ - int ret, i; - - for (i = 0; i < ARRAY_SIZE(accton_as5812_54t_leds); i++) { - ret = led_classdev_register(&pdev->dev, &accton_as5812_54t_leds[i]); - - if (ret < 0) - break; - } - - /* Check if all LEDs were successfully registered */ - if (i != ARRAY_SIZE(accton_as5812_54t_leds)){ - int j; - - /* only unregister the LEDs that were successfully registered */ - for (j = 0; j < i; j++) { - led_classdev_unregister(&accton_as5812_54t_leds[i]); - } - } - - return ret; -} - -static int accton_as5812_54t_led_remove(struct platform_device *pdev) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(accton_as5812_54t_leds); i++) { - led_classdev_unregister(&accton_as5812_54t_leds[i]); - } - - return 0; -} - -static struct platform_driver accton_as5812_54t_led_driver = { - .probe = accton_as5812_54t_led_probe, - .remove = accton_as5812_54t_led_remove, - .suspend = accton_as5812_54t_led_suspend, - .resume = accton_as5812_54t_led_resume, - .driver = { - .name = DRVNAME, - .owner = THIS_MODULE, - }, -}; - -static int __init accton_as5812_54t_led_init(void) -{ - int ret; - - extern int platform_accton_as5812_54t(void); - if (!platform_accton_as5812_54t()) { - return -ENODEV; - } - - ret = platform_driver_register(&accton_as5812_54t_led_driver); - if (ret < 0) { - goto exit; - } - - ledctl = kzalloc(sizeof(struct accton_as5812_54t_led_data), GFP_KERNEL); - if (!ledctl) { - ret = -ENOMEM; - platform_driver_unregister(&accton_as5812_54t_led_driver); - goto exit; - } - - mutex_init(&ledctl->update_lock); - - ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); - if (IS_ERR(ledctl->pdev)) { - ret = PTR_ERR(ledctl->pdev); - platform_driver_unregister(&accton_as5812_54t_led_driver); - kfree(ledctl); - goto exit; - } - -exit: - return ret; -} - -static void __exit accton_as5812_54t_led_exit(void) -{ - platform_device_unregister(ledctl->pdev); - platform_driver_unregister(&accton_as5812_54t_led_driver); - kfree(ledctl); -} - -module_init(accton_as5812_54t_led_init); -module_exit(accton_as5812_54t_led_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton_as5812_54t_led driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/x86-64-accton-as5812-54t-psu.c b/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/x86-64-accton-as5812-54t-psu.c deleted file mode 100644 index a77014e877ca..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/x86-64-accton-as5812-54t-psu.c +++ /dev/null @@ -1,372 +0,0 @@ -/* - * An hwmon driver for accton as5812_54t Power Module - * - * Copyright (C) 2015 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#define PSU_STATUS_I2C_ADDR 0x60 -#define PSU_STATUS_I2C_REG_OFFSET 0x2 - -#define IS_POWER_GOOD(id, value) (!!(value & BIT(id*4 + 1))) -#define IS_PRESENT(id, value) (!(value & BIT(id*4))) - -static ssize_t show_index(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); -static int as5812_54t_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -static int as5812_54t_psu_model_name_get(struct device *dev); - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as5812_54t_psu_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 index; /* PSU index */ - u8 status; /* Status(present/power_good) register read from CPLD */ - char model_name[14]; /* Model name, read from eeprom */ -}; - -static struct as5812_54t_psu_data *as5812_54t_psu_update_device(struct device *dev); - -enum as5812_54t_psu_sysfs_attributes { - PSU_INDEX, - PSU_PRESENT, - PSU_MODEL_NAME, - PSU_POWER_GOOD -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_index, S_IRUGO, show_index, NULL, PSU_INDEX); -static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT); -static SENSOR_DEVICE_ATTR(psu_model_name, S_IRUGO, show_model_name,NULL, PSU_MODEL_NAME); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD); - -static struct attribute *as5812_54t_psu_attributes[] = { - &sensor_dev_attr_psu_index.dev_attr.attr, - &sensor_dev_attr_psu_present.dev_attr.attr, - &sensor_dev_attr_psu_model_name.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - NULL -}; - -static ssize_t show_index(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5812_54t_psu_data *data = i2c_get_clientdata(client); - - return sprintf(buf, "%d\n", data->index); -} - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as5812_54t_psu_data *data = as5812_54t_psu_update_device(dev); - u8 status = 0; - - if (!data->valid) { - return sprintf(buf, "0\n"); - } - - if (attr->index == PSU_PRESENT) { - status = IS_PRESENT(data->index, data->status); - } - else { /* PSU_POWER_GOOD */ - status = IS_POWER_GOOD(data->index, data->status); - } - - return sprintf(buf, "%d\n", status); -} - -static ssize_t show_model_name(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as5812_54t_psu_data *data = as5812_54t_psu_update_device(dev); - - if (!data->valid) { - return 0; - } - - if (!IS_PRESENT(data->index, data->status)) { - return 0; - } - - if (as5812_54t_psu_model_name_get(dev) < 0) { - return -ENXIO; - } - - return sprintf(buf, "%s\n", data->model_name); -} - -static const struct attribute_group as5812_54t_psu_group = { - .attrs = as5812_54t_psu_attributes, -}; - -static int as5812_54t_psu_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as5812_54t_psu_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as5812_54t_psu_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - data->index = dev_id->driver_data; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as5812_54t_psu_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as5812_54t_psu_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as5812_54t_psu_remove(struct i2c_client *client) -{ - struct as5812_54t_psu_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as5812_54t_psu_group); - kfree(data); - - return 0; -} - -enum psu_index -{ - as5812_54t_psu1, - as5812_54t_psu2 -}; - -static const struct i2c_device_id as5812_54t_psu_id[] = { - { "as5812_54t_psu1", as5812_54t_psu1 }, - { "as5812_54t_psu2", as5812_54t_psu2 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as5812_54t_psu_id); - -static struct i2c_driver as5812_54t_psu_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as5812_54t_psu", - }, - .probe = as5812_54t_psu_probe, - .remove = as5812_54t_psu_remove, - .id_table = as5812_54t_psu_id, - .address_list = normal_i2c, -}; - -static int as5812_54t_psu_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) - goto abort; - if (unlikely(result != data_len)) { - result = -EIO; - goto abort; - } - - result = 0; - -abort: - return result; -} - -enum psu_type { - PSU_YM_2401_JCR, /* AC110V - F2B */ - PSU_YM_2401_JDR, /* AC110V - B2F */ - PSU_CPR_4011_4M11, /* AC110V - F2B */ - PSU_CPR_4011_4M21, /* AC110V - B2F */ - PSU_CPR_6011_2M11, /* AC110V - F2B */ - PSU_CPR_6011_2M21, /* AC110V - B2F */ - PSU_UM400D_01G, /* DC48V - F2B */ - PSU_UM400D01_01G /* DC48V - B2F */ -}; - -struct model_name_info { - enum psu_type type; - u8 offset; - u8 length; - char* model_name; -}; - -struct model_name_info models[] = { -{PSU_YM_2401_JCR, 0x20, 11, "YM-2401JCR"}, -{PSU_YM_2401_JDR, 0x20, 11, "YM-2401JDR"}, -{PSU_CPR_4011_4M11, 0x26, 13, "CPR-4011-4M11"}, -{PSU_CPR_4011_4M21, 0x26, 13, "CPR-4011-4M21"}, -{PSU_CPR_6011_2M11, 0x26, 13, "CPR-6011-2M11"}, -{PSU_CPR_6011_2M21, 0x26, 13, "CPR-6011-2M21"}, -{PSU_UM400D_01G, 0x50, 9, "um400d01G"}, -{PSU_UM400D01_01G, 0x50, 12, "um400d01-01G"}, -}; - -static int as5812_54t_psu_model_name_get(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5812_54t_psu_data *data = i2c_get_clientdata(client); - int i, status; - - for (i = 0; i < ARRAY_SIZE(models); i++) { - memset(data->model_name, 0, sizeof(data->model_name)); - - status = as5812_54t_psu_read_block(client, models[i].offset, - data->model_name, models[i].length); - if (status < 0) { - data->model_name[0] = '\0'; - dev_dbg(&client->dev, "unable to read model name from (0x%x) offset(0x%x)\n", - client->addr, models[i].offset); - return status; - } - else { - data->model_name[models[i].length] = '\0'; - } - - if (i == PSU_YM_2401_JCR || i == PSU_YM_2401_JDR) { - /* Skip the meaningless data byte 8*/ - data->model_name[8] = data->model_name[9]; - data->model_name[9] = data->model_name[10]; - data->model_name[10] = '\0'; - } - - /* Determine if the model name is known, if not, read next index - */ - if (strncmp(data->model_name, models[i].model_name, models[i].length) == 0) { - return 0; - } - else { - data->model_name[0] = '\0'; - } - } - - return -ENODATA; -} - -static struct as5812_54t_psu_data *as5812_54t_psu_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5812_54t_psu_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int status = -1; - - dev_dbg(&client->dev, "Starting as5812_54t update\n"); - data->valid = 0; - - /* Read psu status */ - status = accton_i2c_cpld_read(PSU_STATUS_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET); - - if (status < 0) { - dev_dbg(&client->dev, "cpld reg (0x%x) err %d\n", PSU_STATUS_I2C_ADDR, status); - goto exit; - } - else { - data->status = status; - } - - data->last_updated = jiffies; - data->valid = 1; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init as5812_54t_psu_init(void) -{ - extern int platform_accton_as5812_54t(void); - if (!platform_accton_as5812_54t()) { - return -ENODEV; - } - - return i2c_add_driver(&as5812_54t_psu_driver); -} - -static void __exit as5812_54t_psu_exit(void) -{ - i2c_del_driver(&as5812_54t_psu_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as5812_54t_psu driver"); -MODULE_LICENSE("GPL"); - -module_init(as5812_54t_psu_init); -module_exit(as5812_54t_psu_exit); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/x86-64-accton-as5812-54t-sfp.c b/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/x86-64-accton-as5812-54t-sfp.c deleted file mode 100644 index 88bf552de0f0..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/x86-64-accton-as5812-54t-sfp.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * An hwmon driver for accton as5812_54t sfp - * - * Copyright (C) 2015 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define QSFP_PORT_START_INDEX 49 -#define BIT_INDEX(i) (1ULL << (i)) - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x50, I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as5812_54t_sfp_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - int port; /* Front port index */ - char eeprom[256]; /* eeprom data */ - u8 status; /* bit0:port49, bit1:port50 and so on */ -}; - -static struct as5812_54t_sfp_data *as5812_54t_sfp_update_device(struct device *dev, int update_eeprom); -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, char *buf); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -enum as5812_54t_sfp_sysfs_attributes { - SFP_IS_PRESENT, - SFP_PORT_NUMBER, - SFP_EEPROM, - SFP_IS_PRESENT_ALL, -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_status, NULL, SFP_IS_PRESENT); -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, SFP_PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_eeprom, S_IRUGO, show_eeprom, NULL, SFP_EEPROM); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_status,NULL, SFP_IS_PRESENT_ALL); - -static struct attribute *as5812_54t_sfp_attributes[] = { - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_eeprom.dev_attr.attr, - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - NULL -}; - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5812_54t_sfp_data *data = i2c_get_clientdata(client); - - return sprintf(buf, "%d\n",data->port); -} - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as5812_54t_sfp_data *data = as5812_54t_sfp_update_device(dev, 0); - - if (attr->index == SFP_IS_PRESENT) { - u8 val; - - val = (data->status & BIT_INDEX(data->port - QSFP_PORT_START_INDEX)) ? 0 : 1; - return sprintf(buf, "%d", val); - } - else { /* SFP_IS_PRESENT_ALL */ - return sprintf(buf, "%.2x\n", ~data->status); - } -} - -static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as5812_54t_sfp_data *data = as5812_54t_sfp_update_device(dev, 1); - - if (!data->valid) { - return 0; - } - - if ((data->status & BIT_INDEX(data->port - QSFP_PORT_START_INDEX)) != 0) { - return 0; - } - - memcpy(buf, data->eeprom, sizeof(data->eeprom)); - - return sizeof(data->eeprom); -} - -static const struct attribute_group as5812_54t_sfp_group = { - .attrs = as5812_54t_sfp_attributes, -}; - -static int as5812_54t_sfp_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as5812_54t_sfp_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as5812_54t_sfp_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - i2c_set_clientdata(client, data); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as5812_54t_sfp_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: sfp '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as5812_54t_sfp_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as5812_54t_sfp_remove(struct i2c_client *client) -{ - struct as5812_54t_sfp_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as5812_54t_sfp_group); - kfree(data); - - return 0; -} - -enum port_numbers { -as5812_54t_qsfp49 = 49, -as5812_54t_qsfp50, -as5812_54t_qsfp51, -as5812_54t_qsfp52, -as5812_54t_qsfp53, -as5812_54t_qsfp54 -}; - -static const struct i2c_device_id as5812_54t_sfp_id[] = { -{ "as5812_54t_qsfp49", as5812_54t_qsfp49 }, { "as5812_54t_qsfp50", as5812_54t_qsfp50 }, -{ "as5812_54t_qsfp51", as5812_54t_qsfp51 }, { "as5812_54t_qsfp52", as5812_54t_qsfp52 }, -{ "as5812_54t_qsfp53", as5812_54t_qsfp53 }, { "as5812_54t_qsfp54", as5812_54t_qsfp54 }, -{} -}; -MODULE_DEVICE_TABLE(i2c, as5812_54t_sfp_id); - -static struct i2c_driver as5812_54t_sfp_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as5812_54t_sfp", - }, - .probe = as5812_54t_sfp_probe, - .remove = as5812_54t_sfp_remove, - .id_table = as5812_54t_sfp_id, - .address_list = normal_i2c, -}; - -static int as5812_54t_sfp_read_byte(struct i2c_client *client, u8 command, u8 *data) -{ - int result = i2c_smbus_read_byte_data(client, command); - - if (unlikely(result < 0)) { - dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, result); - goto abort; - } - - *data = (u8)result; - result = 0; - -abort: - return result; -} - -static struct as5812_54t_sfp_data *as5812_54t_sfp_update_device(struct device *dev, int update_eeprom) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5812_54t_sfp_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid || update_eeprom) { - int status = -1; - int i = 0; - - data->valid = 0; - //dev_dbg(&client->dev, "Starting as5812_54t sfp status update\n"); - data->status = 0xFF; - - /* - * Bring QSFPs out of reset, - * This is a temporary fix until the QSFP+_MOD_RST register - * can be exposed through the driver. - */ - accton_i2c_cpld_write(0x60, 0x23, 0x3F); - - /* Read present status of port 49-54(QSFP port) */ - status = accton_i2c_cpld_read(0x60, 0x22); - - if (status < 0) { - dev_dbg(&client->dev, "cpld(0x60) reg(0x22) err %d\n", status); - } - else { - data->status = status & 0x3F; /* (u32)status */ - } - - if (update_eeprom) { - /* Read eeprom data based on port number */ - memset(data->eeprom, 0, sizeof(data->eeprom)); - - /* Check if the port is present */ - if ((data->status & BIT_INDEX(data->port - QSFP_PORT_START_INDEX)) == 0) { - /* read eeprom */ - for (i = 0; i < sizeof(data->eeprom); i++) { - status = as5812_54t_sfp_read_byte(client, i, data->eeprom + i); - - if (status < 0) { - dev_dbg(&client->dev, "unable to read eeprom from port(%d)\n", - data->port); - goto exit; - } - } - } - } - - data->valid = 1; - data->last_updated = jiffies; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init as5812_54t_sfp_init(void) -{ - extern int platform_accton_as5812_54t(void); - if (!platform_accton_as5812_54t()) { - return -ENODEV; - } - - return i2c_add_driver(&as5812_54t_sfp_driver); -} - -static void __exit as5812_54t_sfp_exit(void) -{ - i2c_del_driver(&as5812_54t_sfp_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as5812_54t_sfp driver"); -MODULE_LICENSE("GPL"); - -module_init(as5812_54t_sfp_init); -module_exit(as5812_54t_sfp_exit); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/ym2651y.c b/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/ym2651y.c deleted file mode 100644 index 7101aa411f72..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/modules/ym2651y.c +++ /dev/null @@ -1,680 +0,0 @@ -/* - * An hwmon driver for the 3Y Power YM-2651Y Power Module - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_FAN_DUTY_CYCLE 100 - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -enum chips { - YM2651, - YM2401, -}; - -/* Each client has this additional data - */ -struct ym2651y_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 chip; /* chip id */ - u8 capability; /* Register value */ - u16 status_word; /* Register value */ - u8 fan_fault; /* Register value */ - u8 over_temp; /* Register value */ - u16 v_out; /* Register value */ - u16 i_out; /* Register value */ - u16 p_out; /* Register value */ - u8 vout_mode; /* Register value */ - u16 temp; /* Register value */ - u16 fan_speed; /* Register value */ - u16 fan_duty_cycle[2]; /* Register value */ - u8 fan_dir[5]; /* Register value */ - u8 pmbus_revision; /* Register value */ - u8 mfr_id[10]; /* Register value */ - u8 mfr_model[16]; /* Register value */ - u8 mfr_revsion[3]; /* Register value */ - u16 mfr_vin_min; /* Register value */ - u16 mfr_vin_max; /* Register value */ - u16 mfr_iin_max; /* Register value */ - u16 mfr_iout_max; /* Register value */ - u16 mfr_pin_max; /* Register value */ - u16 mfr_pout_max; /* Register value */ - u16 mfr_vout_min; /* Register value */ - u16 mfr_vout_max; /* Register value */ -}; - -static ssize_t show_byte(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_word(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_linear(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_vout(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_over_temp(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_ascii(struct device *dev, struct device_attribute *da, - char *buf); -static struct ym2651y_data *ym2651y_update_device(struct device *dev); -static ssize_t set_fan_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static int ym2651y_write_word(struct i2c_client *client, u8 reg, u16 value); - -enum ym2651y_sysfs_attributes { - PSU_POWER_ON = 0, - PSU_TEMP_FAULT, - PSU_POWER_GOOD, - PSU_FAN1_FAULT, - PSU_FAN_DIRECTION, - PSU_OVER_TEMP, - PSU_V_OUT, - PSU_I_OUT, - PSU_P_OUT, - PSU_TEMP1_INPUT, - PSU_FAN1_SPEED, - PSU_FAN1_DUTY_CYCLE, - PSU_PMBUS_REVISION, - PSU_MFR_ID, - PSU_MFR_MODEL, - PSU_MFR_REVISION, - PSU_MFR_VIN_MIN, - PSU_MFR_VIN_MAX, - PSU_MFR_VOUT_MIN, - PSU_MFR_VOUT_MAX, - PSU_MFR_IIN_MAX, - PSU_MFR_IOUT_MAX, - PSU_MFR_PIN_MAX, - PSU_MFR_POUT_MAX -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_power_on, S_IRUGO, show_word, NULL, PSU_POWER_ON); -static SENSOR_DEVICE_ATTR(psu_temp_fault, S_IRUGO, show_word, NULL, PSU_TEMP_FAULT); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_word, NULL, PSU_POWER_GOOD); -static SENSOR_DEVICE_ATTR(psu_fan1_fault, S_IRUGO, show_fan_fault, NULL, PSU_FAN1_FAULT); -static SENSOR_DEVICE_ATTR(psu_over_temp, S_IRUGO, show_over_temp, NULL, PSU_OVER_TEMP); -static SENSOR_DEVICE_ATTR(psu_v_out, S_IRUGO, show_vout, NULL, PSU_V_OUT); -static SENSOR_DEVICE_ATTR(psu_i_out, S_IRUGO, show_linear, NULL, PSU_I_OUT); -static SENSOR_DEVICE_ATTR(psu_p_out, S_IRUGO, show_linear, NULL, PSU_P_OUT); -static SENSOR_DEVICE_ATTR(psu_temp1_input, S_IRUGO, show_linear, NULL, PSU_TEMP1_INPUT); -static SENSOR_DEVICE_ATTR(psu_fan1_speed_rpm, S_IRUGO, show_linear, NULL, PSU_FAN1_SPEED); -static SENSOR_DEVICE_ATTR(psu_fan1_duty_cycle_percentage, S_IWUSR | S_IRUGO, show_linear, set_fan_duty_cycle, PSU_FAN1_DUTY_CYCLE); -static SENSOR_DEVICE_ATTR(psu_fan_dir, S_IRUGO, show_ascii, NULL, PSU_FAN_DIRECTION); -static SENSOR_DEVICE_ATTR(psu_pmbus_revision,S_IRUGO, show_byte, NULL, PSU_PMBUS_REVISION); -static SENSOR_DEVICE_ATTR(psu_mfr_id, S_IRUGO, show_ascii, NULL, PSU_MFR_ID); -static SENSOR_DEVICE_ATTR(psu_mfr_model, S_IRUGO, show_ascii, NULL, PSU_MFR_MODEL); -static SENSOR_DEVICE_ATTR(psu_mfr_revision, S_IRUGO, show_ascii, NULL, PSU_MFR_REVISION); -static SENSOR_DEVICE_ATTR(psu_mfr_vin_min, S_IRUGO, show_linear, NULL, PSU_MFR_VIN_MIN); -static SENSOR_DEVICE_ATTR(psu_mfr_vin_max, S_IRUGO, show_linear, NULL, PSU_MFR_VIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_vout_min, S_IRUGO, show_linear, NULL, PSU_MFR_VOUT_MIN); -static SENSOR_DEVICE_ATTR(psu_mfr_vout_max, S_IRUGO, show_linear, NULL, PSU_MFR_VOUT_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_iin_max, S_IRUGO, show_linear, NULL, PSU_MFR_IIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_iout_max, S_IRUGO, show_linear, NULL, PSU_MFR_IOUT_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_pin_max, S_IRUGO, show_linear, NULL, PSU_MFR_PIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_pout_max, S_IRUGO, show_linear, NULL, PSU_MFR_POUT_MAX); - -static struct attribute *ym2651y_attributes[] = { - &sensor_dev_attr_psu_power_on.dev_attr.attr, - &sensor_dev_attr_psu_temp_fault.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - &sensor_dev_attr_psu_fan1_fault.dev_attr.attr, - &sensor_dev_attr_psu_over_temp.dev_attr.attr, - &sensor_dev_attr_psu_v_out.dev_attr.attr, - &sensor_dev_attr_psu_i_out.dev_attr.attr, - &sensor_dev_attr_psu_p_out.dev_attr.attr, - &sensor_dev_attr_psu_temp1_input.dev_attr.attr, - &sensor_dev_attr_psu_fan1_speed_rpm.dev_attr.attr, - &sensor_dev_attr_psu_fan1_duty_cycle_percentage.dev_attr.attr, - &sensor_dev_attr_psu_fan_dir.dev_attr.attr, - &sensor_dev_attr_psu_pmbus_revision.dev_attr.attr, - &sensor_dev_attr_psu_mfr_id.dev_attr.attr, - &sensor_dev_attr_psu_mfr_model.dev_attr.attr, - &sensor_dev_attr_psu_mfr_revision.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vin_min.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_pout_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_iin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_pin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vout_min.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vout_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_iout_max.dev_attr.attr, - NULL -}; - -static ssize_t show_byte(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - - if (!data->valid) { - return 0; - } - - return (attr->index == PSU_PMBUS_REVISION) ? sprintf(buf, "%d\n", data->pmbus_revision) : - sprintf(buf, "0\n"); -} - -static ssize_t show_word(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - u16 status = 0; - - if (!data->valid) { - return 0; - } - - switch (attr->index) { - case PSU_POWER_ON: /* psu_power_on, low byte bit 6 of status_word, 0=>ON, 1=>OFF */ - status = (data->status_word & 0x40) ? 0 : 1; - break; - case PSU_TEMP_FAULT: /* psu_temp_fault, low byte bit 2 of status_word, 0=>Normal, 1=>temp fault */ - status = (data->status_word & 0x4) >> 2; - break; - case PSU_POWER_GOOD: /* psu_power_good, high byte bit 3 of status_word, 0=>OK, 1=>FAIL */ - status = (data->status_word & 0x800) ? 0 : 1; - break; - } - - return sprintf(buf, "%d\n", status); -} - -static int two_complement_to_int(u16 data, u8 valid_bit, int mask) -{ - u16 valid_data = data & mask; - bool is_negative = valid_data >> (valid_bit - 1); - - return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data; -} - -static ssize_t set_fan_duty_cycle(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 ym2651y_data *data = i2c_get_clientdata(client); - int nr = (attr->index == PSU_FAN1_DUTY_CYCLE) ? 0 : 1; - long speed; - int error; - - error = kstrtol(buf, 10, &speed); - if (error) - return error; - - if (speed < 0 || speed > MAX_FAN_DUTY_CYCLE) - return -EINVAL; - - mutex_lock(&data->update_lock); - data->fan_duty_cycle[nr] = speed; - ym2651y_write_word(client, 0x3B + nr, data->fan_duty_cycle[nr]); - mutex_unlock(&data->update_lock); - - return count; -} - -static ssize_t show_linear(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - - u16 value = 0; - int exponent, mantissa; - int multiplier = 1000; - - if (!data->valid) { - return 0; - } - - switch (attr->index) { - case PSU_V_OUT: - value = data->v_out; - break; - case PSU_I_OUT: - value = data->i_out; - break; - case PSU_P_OUT: - value = data->p_out; - break; - case PSU_TEMP1_INPUT: - value = data->temp; - break; - case PSU_FAN1_SPEED: - value = data->fan_speed; - multiplier = 1; - break; - case PSU_FAN1_DUTY_CYCLE: - value = data->fan_duty_cycle[0]; - multiplier = 1; - break; - case PSU_MFR_VIN_MIN: - value = data->mfr_vin_min; - break; - case PSU_MFR_VIN_MAX: - value = data->mfr_vin_max; - break; - case PSU_MFR_VOUT_MIN: - value = data->mfr_vout_min; - break; - case PSU_MFR_VOUT_MAX: - value = data->mfr_vout_max; - break; - case PSU_MFR_PIN_MAX: - value = data->mfr_pin_max; - break; - case PSU_MFR_POUT_MAX: - value = data->mfr_pout_max; - break; - case PSU_MFR_IOUT_MAX: - value = data->mfr_iout_max; - break; - case PSU_MFR_IIN_MAX: - value = data->mfr_iin_max; - break; - } - - exponent = two_complement_to_int(value >> 11, 5, 0x1f); - mantissa = two_complement_to_int(value & 0x7ff, 11, 0x7ff); - - return (exponent >= 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : - sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); -} - -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - u8 shift; - - if (!data->valid) { - return 0; - } - - shift = (attr->index == PSU_FAN1_FAULT) ? 7 : 6; - - return sprintf(buf, "%d\n", data->fan_fault >> shift); -} - -static ssize_t show_over_temp(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct ym2651y_data *data = ym2651y_update_device(dev); - - if (!data->valid) { - return 0; - } - - return sprintf(buf, "%d\n", data->over_temp >> 7); -} - -static ssize_t show_ascii(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - u8 *ptr = NULL; - - if (!data->valid) { - return 0; - } - - switch (attr->index) { - case PSU_FAN_DIRECTION: /* psu_fan_dir */ - ptr = data->fan_dir + 1; /* Skip the first byte since it is the length of string. */ - break; - case PSU_MFR_ID: /* psu_mfr_id */ - ptr = data->mfr_id + 1; /* The first byte is the count byte of string. */; - break; - case PSU_MFR_MODEL: /* psu_mfr_model */ - ptr = data->mfr_model + 1; /* The first byte is the count byte of string. */ - break; - case PSU_MFR_REVISION: /* psu_mfr_revision */ - ptr = data->mfr_revsion + 1; /* The first byte is the count byte of string. */ - break; - default: - return 0; - } - - return sprintf(buf, "%s\n", ptr); -} - -static ssize_t show_vout_by_mode(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct ym2651y_data *data = ym2651y_update_device(dev); - int exponent, mantissa; - int multiplier = 1000; - - if (!data->valid) { - return 0; - } - - exponent = two_complement_to_int(data->vout_mode, 5, 0x1f); - mantissa = data->v_out; - - return (exponent > 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : - sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); -} - -static ssize_t show_vout(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct ym2651y_data *data = i2c_get_clientdata(client); - - if (data->chip == YM2401) { - return show_vout_by_mode(dev, da, buf); - } - - return show_linear(dev, da, buf); -} - -static const struct attribute_group ym2651y_group = { - .attrs = ym2651y_attributes, -}; - -static int ym2651y_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct ym2651y_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE_DATA | - I2C_FUNC_SMBUS_WORD_DATA | - I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct ym2651y_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->chip = dev_id->driver_data; - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &ym2651y_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &ym2651y_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int ym2651y_remove(struct i2c_client *client) -{ - struct ym2651y_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &ym2651y_group); - kfree(data); - - return 0; -} - -static const struct i2c_device_id ym2651y_id[] = { - { "ym2651", YM2651 }, - { "ym2401", YM2401 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, ym2651y_id); - -static struct i2c_driver ym2651y_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "ym2651", - }, - .probe = ym2651y_probe, - .remove = ym2651y_remove, - .id_table = ym2651y_id, - .address_list = normal_i2c, -}; - -static int ym2651y_read_byte(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_byte_data(client, reg); -} - -static int ym2651y_read_word(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_word_data(client, reg); -} - -static int ym2651y_write_word(struct i2c_client *client, u8 reg, u16 value) -{ - return i2c_smbus_write_word_data(client, reg, value); -} - -static int ym2651y_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) - goto abort; - if (unlikely(result != data_len)) { - result = -EIO; - goto abort; - } - - result = 0; - -abort: - return result; -} - -struct reg_data_byte { - u8 reg; - u8 *value; -}; - -struct reg_data_word { - u8 reg; - u16 *value; -}; - -static struct ym2651y_data *ym2651y_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct ym2651y_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int i, status, length; - u8 command, buf; - struct reg_data_byte regs_byte[] = { {0x19, &data->capability}, - {0x20, &data->vout_mode}, - {0x7d, &data->over_temp}, - {0x81, &data->fan_fault}, - {0x98, &data->pmbus_revision}}; - struct reg_data_word regs_word[] = { {0x79, &data->status_word}, - {0x8b, &data->v_out}, - {0x8c, &data->i_out}, - {0x96, &data->p_out}, - {0x8d, &data->temp}, - {0x3b, &(data->fan_duty_cycle[0])}, - {0x3c, &(data->fan_duty_cycle[1])}, - {0x90, &data->fan_speed}, - {0xa0, &data->mfr_vin_min}, - {0xa1, &data->mfr_vin_max}, - {0xa2, &data->mfr_iin_max}, - {0xa3, &data->mfr_pin_max}, - {0xa4, &data->mfr_vout_min}, - {0xa5, &data->mfr_vout_max}, - {0xa6, &data->mfr_iout_max}, - {0xa7, &data->mfr_pout_max}}; - - dev_dbg(&client->dev, "Starting ym2651 update\n"); - data->valid = 0; - - /* Read byte data */ - for (i = 0; i < ARRAY_SIZE(regs_byte); i++) { - status = ym2651y_read_byte(client, regs_byte[i].reg); - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_byte[i].reg, status); - goto exit; - } - else { - *(regs_byte[i].value) = status; - } - } - - /* Read word data */ - for (i = 0; i < ARRAY_SIZE(regs_word); i++) { - status = ym2651y_read_word(client, regs_word[i].reg); - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_word[i].reg, status); - goto exit; - } - else { - *(regs_word[i].value) = status; - } - } - - /* Read fan_direction */ - command = 0xC3; - status = ym2651y_read_block(client, command, data->fan_dir, - ARRAY_SIZE(data->fan_dir)-1); - data->fan_dir[ARRAY_SIZE(data->fan_dir)-1] = '\0'; - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; - } - - /* Read mfr_id */ - command = 0x99; - status = ym2651y_read_block(client, command, data->mfr_id, - ARRAY_SIZE(data->mfr_id)-1); - data->mfr_id[ARRAY_SIZE(data->mfr_id)-1] = '\0'; - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; - } - - /* Read mfr_model */ - command = 0x9a; - length = 1; - - /* Read first byte to determine the length of data */ - status = ym2651y_read_block(client, command, &buf, length); - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; - } - - status = ym2651y_read_block(client, command, data->mfr_model, buf+1); - data->mfr_model[buf+1] = '\0'; - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; - } - - /* Read mfr_revsion */ - command = 0x9b; - status = ym2651y_read_block(client, command, data->mfr_revsion, - ARRAY_SIZE(data->mfr_revsion)-1); - data->mfr_revsion[ARRAY_SIZE(data->mfr_revsion)-1] = '\0'; - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; - } - - data->last_updated = jiffies; - data->valid = 1; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init ym2651y_init(void) -{ - return i2c_add_driver(&ym2651y_driver); -} - -static void __exit ym2651y_exit(void) -{ - i2c_del_driver(&ym2651y_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("3Y Power YM-2651Y driver"); -MODULE_LICENSE("GPL"); - -module_init(ym2651y_init); -module_exit(ym2651y_exit); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/service/as5812-platform-init.service b/platform/broadcom/sonic-platform-modules-accton/as5812-54t/service/as5812-platform-init.service deleted file mode 100755 index 30c1703dc40f..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/service/as5812-platform-init.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Accton AS5712-54T Platform initialization service -Before=pmon.service -DefaultDependencies=no - -[Service] -Type=oneshot -ExecStart=/usr/local/bin/accton_as5812_54t_util.py install -ExecStop=/usr/local/bin/accton_as5812_54t_util.py clean -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/utils/README b/platform/broadcom/sonic-platform-modules-accton/as5812-54t/utils/README deleted file mode 100755 index 2284eb091fcb..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/utils/README +++ /dev/null @@ -1,60 +0,0 @@ -Copyright (C) 2016 Accton Networks, Inc. - -This program is free software: you can redistribute it and/or modify -It under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -To initialize the system, run "accton_as5812_54t_util.py install". -To clean up the drivers & devices, run "accton_as5812_54t_util.py clean". -To dump information of sensors, run "accton_as5812_54t_util.py show". -To dump SFP EEPROM, run "accton_as5812_54t_util.py sff". -To set fan speed, run "accton_as5812_54t_util.py set fan". -To enable/disable SFP emission, run "accton_as5812_54t_util.py set sfp". -To set system LEDs' color, run "accton_as5812_54t_util.py set led" -For more information, run "accton_as5812_54t_util.py --help". - -==================================================================== -Besides applying accton_as5812_54t_util.py to access peripherals, you can -access peripherals by sysfs nodes directly after the installation is run. - -LED controls can be found under /sys/class/leds. The sysfs interface -color mappings are as follows: -Brightness: - 0 => off - 1 => green - 2 => amber - 3 => red - 4 => blue - -There are 5 system LEDs, loc, diag, fan, ps1, and ps2. -They are lit automatically by CPLD, but the loc and diag. -The loc led has only 1 color, blue. -The diag one has 3 colors: red, amber, and green. - -Fan controls can be found in /sys/bus/i2c/devices/2-0066. -There are 12 fans inside 6 fan modules. -All fans share 1 duty setting, ranged from 0~100. - -Three temperature sensors are controlled by the lm75 kernel modules. -They should already be visible under /sys/bus/i2c/drivers/lm75/. - -Two power supplies are controlled by the CPLD. -Here provide their status under -/sys/bus/i2c/devices/10-0050 and /sys/bus/i2c/devices/11-0053. - -There are 32 QSFP+ modules are equipped. -Apply "accton_as5812_54t_util.py show" to get their status. -Apply "accton_as5812_54t_util.py set sfp" to turn on/off light transmission. -Apply "accton_as5812_54t_util.py sff" to dump EEPROM information. -Before operating on that QSFP+, please make sure it is well plugged. -Otherwise, operation is going to fail. - diff --git a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/utils/accton_as5812_54t_util.py b/platform/broadcom/sonic-platform-modules-accton/as5812-54t/utils/accton_as5812_54t_util.py deleted file mode 100755 index 4e9b0795081d..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as5812-54t/utils/accton_as5812_54t_util.py +++ /dev/null @@ -1,565 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2016 Accton Networks, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" -Usage: %(scriptName)s [options] command object - -options: - -h | --help : this help message - -d | --debug : run with debug mode - -f | --force : ignore error during installation or clean -command: - install : install drivers and generate related sysfs nodes - clean : uninstall drivers and remove related sysfs nodes - show : show all systen status - sff : dump SFP eeprom - set : change board setting with fan|led|sfp -""" - -import os -import commands -import sys, getopt -import logging -import re -import time -from collections import namedtuple - - - - -PROJECT_NAME = 'as5812_54t' -version = '0.1.0' -verbose = False -DEBUG = False -args = [] -ALL_DEVICE = {} -DEVICE_NO = {'led':5, 'fan':5,'thermal':3, 'psu':2, 'sfp':6} -FORCE = 0 -logging.basicConfig(filename= PROJECT_NAME+'.log', filemode='w',level=logging.DEBUG) -logging.basicConfig(level=logging.INFO) - - -if DEBUG == True: - print sys.argv[0] - print 'ARGV :', sys.argv[1:] - - -def main(): - global DEBUG - global args - global FORCE - - if len(sys.argv)<2: - show_help() - - options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help', - 'debug', - 'force', - ]) - if DEBUG == True: - print options - print args - print len(sys.argv) - - for opt, arg in options: - if opt in ('-h', '--help'): - show_help() - elif opt in ('-d', '--debug'): - DEBUG = True - logging.basicConfig(level=logging.INFO) - elif opt in ('-f', '--force'): - FORCE = 1 - else: - logging.info('no option') - for arg in args: - if arg == 'install': - do_install() - elif arg == 'clean': - do_uninstall() - elif arg == 'show': - device_traversal() - elif arg == 'sff': - if len(args)!=2: - show_eeprom_help() - elif int(args[1]) ==0 or int(args[1]) > DEVICE_NO['sfp']: - show_eeprom_help() - else: - show_eeprom(args[1]) - return - elif arg == 'set': - if len(args)<3: - show_set_help() - else: - set_device(args[1:]) - return - else: - show_help() - - - return 0 - -def show_help(): - print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]} - sys.exit(0) - -def show_set_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print cmd +" [led|sfp|fan]" - print " use \""+ cmd + " led 0-4 \" to set led color" - print " use \""+ cmd + " fan 0-100\" to set fan duty percetage" - print " use \""+ cmd + " sfp 1-6 {0|1}\" to set sfp# tx_disable" - sys.exit(0) - -def show_eeprom_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print " use \""+ cmd + " 1-32 \" to dump sfp# eeprom" - sys.exit(0) - -def my_log(txt): - if DEBUG == True: - print "[ROY]"+txt - return - -def log_os_system(cmd, show): - logging.info('Run :'+cmd) - status, output = commands.getstatusoutput(cmd) - my_log (cmd +"with result:" + str(status)) - my_log (" output:"+output) - if status: - logging.info('Failed :'+cmd) - if show: - print('Failed :'+cmd) - return status, output - -def driver_check(): - ret, lsmod = log_os_system("lsmod| grep accton", 0) - logging.info('mods:'+lsmod) - if len(lsmod) ==0: - return False - return True - - - self.insmod("accton_i2c_cpld") - self.insmod("cpr_4011_4mxx") - self.insmod("ym2651y") - for m in [ "sfp", "psu", "fan", "leds" ]: - self.insmod("x86-64-accton-as5812-54t-%s" % m) - -kos = [ -'modprobe i2c_dev', -'modprobe i2c_mux_pca954x force_deselect_on_exit=1', -'modprobe accton_i2c_cpld' , -'modprobe cpr_4011_4mxx' , -'modprobe ym2651y' , -'modprobe x86-64-accton-as5812-54t-sfp' , -'modprobe x86-64-accton-as5812-54t-psu' , -'modprobe x86-64-accton-as5812-54t-fan' , -'modprobe x86-64-accton-as5812-54t-leds' ] - -def driver_install(): - global FORCE - for i in range(0,len(kos)): - status, output = log_os_system(kos[i], 1) - if status: - if FORCE == 0: - return status - return 0 - -def driver_uninstall(): - global FORCE - for i in range(0,len(kos)): - rm = kos[-(i+1)].replace("modprobe", "modprobe -rq") - rm = rm.replace("insmod", "rmmod") - status, output = log_os_system(rm, 1) - if status: - if FORCE == 0: - return status - return 0 - -led_prefix ='/sys/class/leds/accton_'+PROJECT_NAME+'_led::' -hwmon_types = {'led': ['diag','fan','loc','psu1','psu2']} -hwmon_nodes = {'led': ['brightness'] } -hwmon_prefix ={'led': led_prefix} - -i2c_prefix = '/sys/bus/i2c/devices/' -i2c_bus = {'fan': ['2-0066'] , - 'thermal': ['15-0048','16-0049', '17-004a'] , - 'psu': ['11-0050','12-0053'], - 'sfp': ['-0050']} -i2c_nodes = {'fan': ['present', 'front_speed_rpm', 'rear_speed_rpm'] , - 'thermal': ['hwmon/hwmon*/temp1_input'] , - 'psu': ['psu_present ', 'psu_power_good'] , - 'sfp': ['sfp_is_present ', 'sfp_tx_disable_all']} - -sfp_map = [4,6,3,5,7,2] - -sfp_1st_index = 48 - -mknod =[ -'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device' , -'echo accton_i2c_cpld 0x60 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-15/new_device', -'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-16/new_device', -'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-17/new_device', -'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo as5812_54t_psu1 0x38 > /sys/bus/i2c/devices/i2c-11/new_device', -'echo cpr_4011_4mxx 0x3c > /sys/bus/i2c/devices/i2c-11/new_device', -'echo as5812_54t_psu1 0x50 > /sys/bus/i2c/devices/i2c-11/new_device', -'echo ym2401 0x58 > /sys/bus/i2c/devices/i2c-11/new_device', -'echo as5812_54t_psu2 0x3b > /sys/bus/i2c/devices/i2c-12/new_device', -'echo cpr_4011_4mxx 0x3f > /sys/bus/i2c/devices/i2c-12/new_device', -'echo as5812_54t_psu2 0x53 > /sys/bus/i2c/devices/i2c-12/new_device', -'echo ym2401 0x5b > /sys/bus/i2c/devices/i2c-12/new_device'] - -mknod2 =[ -'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-0/new_device' , -'echo accton_i2c_cpld 0x60 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-15/new_device', -'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-16/new_device', -'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-17/new_device', -'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo as5812_54t_psu1 0x38 > /sys/bus/i2c/devices/i2c-11/new_device', -'echo cpr_4011_4mxx 0x3c > /sys/bus/i2c/devices/i2c-11/new_device', -'echo as5812_54t_psu1 0x50 > /sys/bus/i2c/devices/i2c-11/new_device', -'echo ym2401 0x58 > /sys/bus/i2c/devices/i2c-11/new_device', -'echo as5812_54t_psu2 0x3b > /sys/bus/i2c/devices/i2c-12/new_device', -'echo cpr_4011_4mxx 0x3f > /sys/bus/i2c/devices/i2c-12/new_device', -'echo as5812_54t_psu2 0x53 > /sys/bus/i2c/devices/i2c-12/new_device', -'echo ym2401 0x5b > /sys/bus/i2c/devices/i2c-12/new_device'] - - - -def i2c_order_check(): - # i2c bus 0 and 1 might be installed in different order. - # Here check if 0x71 is exist @ i2c-0 - tmp = "echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-0/new_device" - status, output = log_os_system(tmp, 0) - if not device_exist(): - order = 1 - else: - order = 0 - tmp = "echo 0x71 > /sys/bus/i2c/devices/i2c-0/delete_device" - status, output = log_os_system(tmp, 0) - return order - -def device_install(): - global FORCE - - order = i2c_order_check() - - # if 0x71 is not exist @i2c-0, use reversed bus order - if order: - for i in range(0,len(mknod2)): - #for pca954x need times to built new i2c buses - if mknod2[i].find('pca954') != -1: - time.sleep(1) - - status, output = log_os_system(mknod2[i], 1) - if status: - print output - if FORCE == 0: - return status - else: - for i in range(0,len(mknod)): - #for pca954x need times to built new i2c buses - if mknod[i].find('pca954') != -1: - time.sleep(1) - - status, output = log_os_system(mknod[i], 1) - if status: - print output - if FORCE == 0: - return status - for i in range(sfp_1st_index,len(sfp_map)): - status, output =log_os_system("echo sfp"+str(i+1)+" 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1) - if status: - print output - if FORCE == 0: - return status - return - -def device_uninstall(): - global FORCE - - status, output =log_os_system("ls /sys/bus/i2c/devices/1-0071", 0) - if status==0: - I2C_ORDER=1 - else: - I2C_ORDER=0 - - for i in range(sfp_1st_index,len(sfp_map)): - target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device" - status, output =log_os_system("echo 0x50 > "+ target, 1) - if status: - print output - if FORCE == 0: - return status - - if I2C_ORDER==0: - nodelist = mknod - else: - nodelist = mknod2 - - for i in range(len(nodelist)): - target = nodelist[-(i+1)] - temp = target.split() - del temp[1] - temp[-1] = temp[-1].replace('new_device', 'delete_device') - status, output = log_os_system(" ".join(temp), 1) - if status: - print output - if FORCE == 0: - return status - - return - -def system_ready(): - if driver_check() == False: - return False - if not device_exist(): - return False - return True - -def do_install(): - print "Checking system...." - if driver_check() == False: - print "No driver, installing...." - status = driver_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" drivers detected...." - if not device_exist(): - print "No device, installing...." - status = device_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" devices detected...." - return - -def do_uninstall(): - print "Checking system...." - if not device_exist(): - print PROJECT_NAME.upper() +" has no device installed...." - else: - print "Removing device...." - status = device_uninstall() - if status: - if FORCE == 0: - return status - - if driver_check()== False : - print PROJECT_NAME.upper() +" has no driver installed...." - else: - print "Removing installed driver...." - status = driver_uninstall() - if status: - if FORCE == 0: - return status - - return - -def devices_info(): - global DEVICE_NO - global ALL_DEVICE - global i2c_bus, hwmon_types - for key in DEVICE_NO: - ALL_DEVICE[key]= {} - for i in range(0,DEVICE_NO[key]): - ALL_DEVICE[key][key+str(i+1)] = [] - - for key in i2c_bus: - buses = i2c_bus[key] - nodes = i2c_nodes[key] - for i in range(0,len(buses)): - for j in range(0,len(nodes)): - if 'fan' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - elif 'sfp' == key: - for k in range(sfp_1st_index,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ str(sfp_map[k])+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - else: - node = key+str(i+1) - path = i2c_prefix+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - - for key in hwmon_types: - itypes = hwmon_types[key] - nodes = hwmon_nodes[key] - for i in range(0,len(itypes)): - for j in range(0,len(nodes)): - node = key+"_"+itypes[i] - path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][ key+str(i+1)].append(path) - - #show dict all in the order - if DEBUG == True: - for i in sorted(ALL_DEVICE.keys()): - print(i+": ") - for j in sorted(ALL_DEVICE[i].keys()): - print(" "+j) - for k in (ALL_DEVICE[i][j]): - print(" "+" "+k) - return - -def show_eeprom(index): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0] - node = node.replace(node.split("/")[-1], 'sfp_eeprom') - # check if got hexdump command in current environment - ret, log = log_os_system("which hexdump", 0) - ret, log2 = log_os_system("which busybox hexdump", 0) - if len(log): - hex_cmd = 'hexdump' - elif len(log2): - hex_cmd = ' busybox hexdump' - else: - log = 'Failed : no hexdump cmd!!' - logging.info(log) - print log - return 1 - - print node + ":" - ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1) - if ret==0: - print log - else: - print "**********device no found**********" - return - -def set_device(args): - global DEVICE_NO - global ALL_DEVICE - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - - if args[0]=='led': - if int(args[1])>4: - show_set_help() - return - #print ALL_DEVICE['led'] - for i in range(0,len(ALL_DEVICE['led'])): - for k in (ALL_DEVICE['led']['led'+str(i+1)]): - ret, log = log_os_system("echo "+args[1]+" >"+k, 1) - if ret: - return ret - elif args[0]=='fan': - if int(args[1])>100: - show_set_help() - return - #print ALL_DEVICE['fan'] - #fan1~6 is all fine, all fan share same setting - node = ALL_DEVICE['fan'] ['fan1'][0] - node = node.replace(node.split("/")[-1], 'fan_duty_cycle_percentage') - ret, log = log_os_system("cat "+ node, 1) - if ret==0: - print ("Previous fan duty: " + log.strip() +"%") - ret, log = log_os_system("echo "+args[1]+" >"+node, 1) - if ret==0: - print ("Current fan duty: " + args[1] +"%") - return ret - elif args[0]=='sfp': - if int(args[1])> DEVICE_NO[args[0]] or int(args[1])==0: - show_set_help() - return - if len(args)<2: - show_set_help() - return - - if int(args[2])>1: - show_set_help() - return - - #print ALL_DEVICE[args[0]] - for i in range(0,len(ALL_DEVICE[args[0]])): - for j in ALL_DEVICE[args[0]][args[0]+str(args[1])]: - if j.find('tx_disable')!= -1: - ret, log = log_os_system("echo "+args[2]+" >"+ j, 1) - if ret: - return ret - - return - -#get digits inside a string. -#Ex: 31 for "sfp31" -def get_value(input): - digit = re.findall('\d+', input) - return int(digit[0]) - -def device_traversal(): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - for i in sorted(ALL_DEVICE.keys()): - print("============================================") - print(i.upper()+": ") - print("============================================") - - for j in sorted(ALL_DEVICE[i].keys(), key=get_value): - print " "+j+":", - for k in (ALL_DEVICE[i][j]): - ret, log = log_os_system("cat "+k, 0) - func = k.split("/")[-1].strip() - func = re.sub(j+'_','',func,1) - func = re.sub(i.lower()+'_','',func,1) - if ret==0: - print func+"="+log+" ", - else: - print func+"="+"X"+" ", - print - print("----------------------------------------------------------------") - - - print - return - -def device_exist(): - ret1, log = log_os_system("ls "+i2c_prefix+"*0071", 0) - ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0) - return not(ret1 or ret2) - -if __name__ == "__main__": - main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/classes/__init__.py b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/classes/__init__.py deleted file mode 100755 index e69de29bb2d1..000000000000 diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/classes/fanutil.py b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/classes/fanutil.py deleted file mode 100755 index 207436c1fc96..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/classes/fanutil.py +++ /dev/null @@ -1,255 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# 1/10/2018: Jostar modify for as7716_32 -# 2/27/2018: Roy Lee modify for as7312_54x -# ------------------------------------------------------------------ - -try: - import time - import logging - from collections import namedtuple -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - - -class FanUtil(object): - """Platform-specific FanUtil class""" - - FAN_NUM_ON_MAIN_BROAD = 6 - FAN_NUM_1_IDX = 1 - FAN_NUM_2_IDX = 2 - FAN_NUM_3_IDX = 3 - FAN_NUM_4_IDX = 4 - FAN_NUM_5_IDX = 5 - FAN_NUM_6_IDX = 6 - - FAN_NODE_NUM_OF_MAP = 2 - FAN_NODE_FAULT_IDX_OF_MAP = 1 - #FAN_NODE_SPEED_IDX_OF_MAP = 2 - FAN_NODE_DIR_IDX_OF_MAP = 2 - #FAN_NODE_DUTY_IDX_OF_MAP = 4 - #FANR_NODE_FAULT_IDX_OF_MAP = 5 - - #BASE_VAL_PATH = '/sys/devices/platform/as5712_54x_fan/{0}' - BASE_VAL_PATH = '/sys/bus/i2c/devices/2-0066/{0}' - FAN_DUTY_PATH = '/sys/bus/i2c/devices/2-0066/fan_duty_cycle_percentage' - - #logfile = '' - #loglevel = logging.INFO - - """ Dictionary where - key1 = fan id index (integer) starting from 1 - key2 = fan node index (interger) starting from 1 - value = path to fan device file (string) """ - _fan_to_device_path_mapping = {} - -#fan1_direction -#fan1_fault -#fan1_present - - #(FAN_NUM_2_IDX, FAN_NODE_DUTY_IDX_OF_MAP): 'fan2_duty_cycle_percentage', - _fan_to_device_node_mapping = { - (FAN_NUM_1_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan1_fault', - (FAN_NUM_1_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan1_direction', - - (FAN_NUM_2_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan2_fault', - (FAN_NUM_2_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan2_direction', - - (FAN_NUM_3_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan3_fault', - (FAN_NUM_3_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan3_direction', - - (FAN_NUM_4_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan4_fault', - (FAN_NUM_4_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan4_direction', - - (FAN_NUM_5_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan5_fault', - (FAN_NUM_5_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan5_direction', - - (FAN_NUM_6_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan6_fault', - (FAN_NUM_6_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan6_direction', - } - - def _get_fan_to_device_node(self, fan_num, node_num): - return self._fan_to_device_node_mapping[(fan_num, node_num)] - - def _get_fan_node_val(self, fan_num, node_num): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num:%d', fan_num) - return None - - if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: - logging.debug('GET. Parameter error. node_num:%d', node_num) - return None - - device_path = self.get_fan_to_device_path(fan_num, node_num) - - try: - val_file = open(device_path, 'r') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - content = val_file.readline().rstrip() - - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return int(content) - - def _set_fan_node_val(self, fan_num, node_num, val): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num:%d', fan_num) - return None - - if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: - logging.debug('GET. Parameter error. node_num:%d', node_num) - return None - - content = str(val) - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - device_path = self.get_fan_to_device_path(fan_num, node_num) - try: - val_file = open(device_path, 'w') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - val_file.write(content) - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return True - - def __init__(self): - fan_path = self.BASE_VAL_PATH - - for fan_num in range(self.FAN_NUM_1_IDX, self.FAN_NUM_ON_MAIN_BROAD+1): - for node_num in range(self.FAN_NODE_FAULT_IDX_OF_MAP, self.FAN_NODE_NUM_OF_MAP+1): - self._fan_to_device_path_mapping[(fan_num, node_num)] = fan_path.format( - self._fan_to_device_node_mapping[(fan_num, node_num)]) - - def get_num_fans(self): - return self.FAN_NUM_ON_MAIN_BROAD - - def get_idx_fan_start(self): - return self.FAN_NUM_1_IDX - - def get_num_nodes(self): - return self.FAN_NODE_NUM_OF_MAP - - def get_idx_node_start(self): - return self.FAN_NODE_FAULT_IDX_OF_MAP - - def get_size_node_map(self): - return len(self._fan_to_device_node_mapping) - - def get_size_path_map(self): - return len(self._fan_to_device_path_mapping) - - def get_fan_to_device_path(self, fan_num, node_num): - return self._fan_to_device_path_mapping[(fan_num, node_num)] - - def get_fan_fault(self, fan_num): - return self._get_fan_node_val(fan_num, self.FAN_NODE_FAULT_IDX_OF_MAP) - - #def get_fan_speed(self, fan_num): - # return self._get_fan_node_val(fan_num, self.FAN_NODE_SPEED_IDX_OF_MAP) - - def get_fan_dir(self, fan_num): - return self._get_fan_node_val(fan_num, self.FAN_NODE_DIR_IDX_OF_MAP) - - def get_fan_duty_cycle(self): - #duty_path = self.FAN_DUTY_PATH - try: - val_file = open(self.FAN_DUTY_PATH) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - return False - - content = val_file.readline().rstrip() - val_file.close() - - return int(content) - #self._get_fan_node_val(fan_num, self.FAN_NODE_DUTY_IDX_OF_MAP) -#static u32 reg_val_to_duty_cycle(u8 reg_val) -#{ -# reg_val &= FAN_DUTY_CYCLE_REG_MASK; -# return ((u32)(reg_val+1) * 625 + 75)/ 100; -#} -# - def set_fan_duty_cycle(self, val): - - try: - fan_file = open(self.FAN_DUTY_PATH, 'r+') - except IOError as e: - print "Error: unable to open file: %s" % str(e) - return False - #val = ((val + 1 ) * 625 +75 ) / 100 - fan_file.write(str(val)) - fan_file.close() - return True - - #def get_fanr_fault(self, fan_num): - # return self._get_fan_node_val(fan_num, self.FANR_NODE_FAULT_IDX_OF_MAP) - - def get_fanr_speed(self, fan_num): - return self._get_fan_node_val(fan_num, self.FANR_NODE_SPEED_IDX_OF_MAP) - - def get_fan_status(self, fan_num): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num, %d', fan_num) - return None - - if self.get_fan_fault(fan_num) is not None and self.get_fan_fault(fan_num) > 0: - logging.debug('GET. FAN fault. fan_num, %d', fan_num) - return False - - #if self.get_fanr_fault(fan_num) is not None and self.get_fanr_fault(fan_num) > 0: - # logging.debug('GET. FANR fault. fan_num, %d', fan_num) - # return False - - return True - -#def main(): -# fan = FanUtil() -# -# print 'get_size_node_map : %d' % fan.get_size_node_map() -# print 'get_size_path_map : %d' % fan.get_size_path_map() -# for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1): -# for y in range(fan.get_idx_node_start(), fan.get_num_nodes()+1): -# print fan.get_fan_to_device_path(x, y) -# -#if __name__ == '__main__': -# main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/classes/thermalutil.py b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/classes/thermalutil.py deleted file mode 100755 index 68f0ef900df6..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/classes/thermalutil.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# 1/10/2018:Jostar modify for as7716_32x -# 2/27/2018: Roy Lee modify for as7312_54x -# ------------------------------------------------------------------ - -try: - import time - import logging - import glob - from collections import namedtuple -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - - -class ThermalUtil(object): - """Platform-specific ThermalUtil class""" - - THERMAL_NUM_ON_MAIN_BROAD = 3 - THERMAL_NUM_1_IDX = 1 # 1_ON_MAIN_BROAD - THERMAL_NUM_2_IDX = 2 # 2_ON_MAIN_BROAD - THERMAL_NUM_3_IDX = 3 # 3_ON_MAIN_BROAD - - BASE_VAL_PATH = '/sys/bus/i2c/devices/{0}-00{1}/hwmon/hwmon*/temp1_input' - - """ Dictionary where - key1 = thermal id index (integer) starting from 1 - value = path to fan device file (string) """ - _thermal_to_device_path_mapping = {} - - _thermal_to_device_node_mapping = { - THERMAL_NUM_1_IDX: ['3', '48'], - THERMAL_NUM_2_IDX: ['3', '49'], - THERMAL_NUM_3_IDX: ['3', '4a'], - } - - def __init__(self): - thermal_path = self.BASE_VAL_PATH - - for x in range(self.THERMAL_NUM_1_IDX, self.THERMAL_NUM_ON_MAIN_BROAD+1): - self._thermal_to_device_path_mapping[x] = thermal_path.format( - self._thermal_to_device_node_mapping[x][0], - self._thermal_to_device_node_mapping[x][1]) - - def _get_thermal_node_val(self, thermal_num): - if thermal_num < self.THERMAL_NUM_1_IDX or thermal_num > self.THERMAL_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. thermal_num, %d', thermal_num) - return None - - device_path = self.get_thermal_to_device_path(thermal_num) - for filename in glob.glob(device_path): - try: - val_file = open(filename, 'r') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - content = val_file.readline().rstrip() - - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return int(content) - - - def get_num_thermals(self): - return self.THERMAL_NUM_ON_MAIN_BROAD - - def get_idx_thermal_start(self): - return self.THERMAL_NUM_1_IDX - - def get_size_node_map(self): - return len(self._thermal_to_device_node_mapping) - - def get_size_path_map(self): - return len(self._thermal_to_device_path_mapping) - - def get_thermal_to_device_path(self, thermal_num): - return self._thermal_to_device_path_mapping[thermal_num] - - def get_thermal_1_val(self): - return self._get_thermal_node_val(self.THERMAL_NUM_1_IDX) - - def get_thermal_2_val(self): - return self._get_thermal_node_val(self.THERMAL_NUM_2_IDX) - def get_thermal_temp(self): - return (self._get_thermal_node_val(self.THERMAL_NUM_1_IDX) + self._get_thermal_node_val(self.THERMAL_NUM_2_IDX) +self._get_thermal_node_val(self.THERMAL_NUM_3_IDX)) - -#def main(): -# thermal = ThermalUtil() -# -# print 'get_size_node_map : %d' % thermal.get_size_node_map() -# print 'get_size_path_map : %d' % thermal.get_size_path_map() -# for x in range(thermal.get_idx_thermal_start(), thermal.get_num_thermals()+1): -# print thermal.get_thermal_to_device_path(x) -# -#if __name__ == '__main__': -# main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/Makefile b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/Makefile deleted file mode 100755 index 488fdb321cac..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -ifneq ($(KERNELRELEASE),) -obj-m:= accton_i2c_cpld.o \ - accton_as7312_54x_fan.o accton_as7312_54x_leds.o \ - accton_as7312_54x_psu.o ym2651y.o - -else -ifeq (,$(KERNEL_SRC)) -$(error KERNEL_SRC is not defined) -else -KERNELDIR:=$(KERNEL_SRC) -endif -PWD:=$(shell pwd) -default: - $(MAKE) -C $(KERNELDIR) M=$(PWD) modules -clean: - rm -rf *.o *.mod.o *.mod.o *.ko .*cmd .tmp_versions Module.markers Module.symvers modules.order -endif diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_as7312_54x_fan.c b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_as7312_54x_fan.c deleted file mode 100755 index 8764ec8a3176..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_as7312_54x_fan.c +++ /dev/null @@ -1,815 +0,0 @@ -/* - * A hwmon driver for the Accton as7312 54x fan - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRVNAME "as7312_54x_fan" - -#define NUM_THERMAL_SENSORS (3) /* Get sum of this number of sensors.*/ -#define THERMAL_SENSORS_DRIVER "lm75" -#define THERMAL_SENSORS_ADDRS {0x48, 0x49, 0x4a} - -#define IN -#define OUT - -static struct as7312_54x_fan_data *as7312_54x_fan_update_device(struct device *dev); -static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t get_enable(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_enable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, char *buf); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -/* fan related data, the index should match sysfs_fan_attributes - */ -static const u8 fan_reg[] = { - 0x0F, /* fan 1-6 present status */ - 0x10, /* fan 1-6 direction(0:F2B 1:B2F) */ - 0x11, /* fan PWM(for all fan) */ - 0x12, /* front fan 1 speed(rpm) */ - 0x13, /* front fan 2 speed(rpm) */ - 0x14, /* front fan 3 speed(rpm) */ - 0x15, /* front fan 4 speed(rpm) */ - 0x16, /* front fan 5 speed(rpm) */ - 0x17, /* front fan 6 speed(rpm) */ - 0x22, /* rear fan 1 speed(rpm) */ - 0x23, /* rear fan 2 speed(rpm) */ - 0x24, /* rear fan 3 speed(rpm) */ - 0x25, /* rear fan 4 speed(rpm) */ - 0x26, /* rear fan 5 speed(rpm) */ - 0x27, /* rear fan 6 speed(rpm) */ -}; - -/* Each client has this additional data */ -struct as7312_54x_fan_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */ - u8 enable; - int system_temp; /*In unit of mini-Celsius*/ - int sensors_found; -}; - -enum fan_id { - FAN1_ID, - FAN2_ID, - FAN3_ID, - FAN4_ID, - FAN5_ID, - FAN6_ID -}; - -enum sysfs_fan_attributes { - FAN_PRESENT_REG, - FAN_DIRECTION_REG, - FAN_DUTY_CYCLE_PERCENTAGE, /* Only one CPLD register to control duty cycle for all fans */ - FAN1_FRONT_SPEED_RPM, - FAN2_FRONT_SPEED_RPM, - FAN3_FRONT_SPEED_RPM, - FAN4_FRONT_SPEED_RPM, - FAN5_FRONT_SPEED_RPM, - FAN6_FRONT_SPEED_RPM, - FAN1_REAR_SPEED_RPM, - FAN2_REAR_SPEED_RPM, - FAN3_REAR_SPEED_RPM, - FAN4_REAR_SPEED_RPM, - FAN5_REAR_SPEED_RPM, - FAN6_REAR_SPEED_RPM, - FAN1_DIRECTION, - FAN2_DIRECTION, - FAN3_DIRECTION, - FAN4_DIRECTION, - FAN5_DIRECTION, - FAN6_DIRECTION, - FAN1_PRESENT, - FAN2_PRESENT, - FAN3_PRESENT, - FAN4_PRESENT, - FAN5_PRESENT, - FAN6_PRESENT, - FAN1_FAULT, - FAN2_FAULT, - FAN3_FAULT, - FAN4_FAULT, - FAN5_FAULT, - FAN6_FAULT -}; - -/* Define attributes - */ -#define DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(index, index2) \ - static SENSOR_DEVICE_ATTR(fan##index##_fault, S_IRUGO, fan_show_value, NULL, FAN##index##_FAULT);\ - static SENSOR_DEVICE_ATTR(fan##index2##_fault, S_IRUGO, fan_show_value, NULL, FAN##index##_FAULT) -#define DECLARE_FAN_FAULT_ATTR(index, index2) &sensor_dev_attr_fan##index##_fault.dev_attr.attr, \ - &sensor_dev_attr_fan##index2##_fault.dev_attr.attr - -#define DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan##index##_direction, S_IRUGO, fan_show_value, NULL, FAN##index##_DIRECTION) -#define DECLARE_FAN_DIRECTION_ATTR(index) &sensor_dev_attr_fan##index##_direction.dev_attr.attr - -#define DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE);\ - static SENSOR_DEVICE_ATTR(pwm##index, S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE);\ - static SENSOR_DEVICE_ATTR(pwm##index##_enable, S_IWUSR | S_IRUGO, get_enable, set_enable, FAN_DUTY_CYCLE_PERCENTAGE) - -#define DECLARE_FAN_DUTY_CYCLE_ATTR(index) &sensor_dev_attr_fan_duty_cycle_percentage.dev_attr.attr, \ - &sensor_dev_attr_pwm##index.dev_attr.attr, \ - &sensor_dev_attr_pwm##index##_enable.dev_attr.attr - -#define DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR() \ - static SENSOR_DEVICE_ATTR(sys_temp, S_IRUGO, get_sys_temp, NULL, FAN_DUTY_CYCLE_PERCENTAGE) - -#define DECLARE_FAN_SYSTEM_TEMP_ATTR() &sensor_dev_attr_sys_temp.dev_attr.attr - - -#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan##index##_present, S_IRUGO, fan_show_value, NULL, FAN##index##_PRESENT) -#define DECLARE_FAN_PRESENT_ATTR(index) &sensor_dev_attr_fan##index##_present.dev_attr.attr - -#define DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(index, index2) \ - static SENSOR_DEVICE_ATTR(fan##index##_front_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_FRONT_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index##_rear_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_REAR_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index##_input, S_IRUGO, fan_show_value, NULL, FAN##index##_FRONT_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index2##_input, S_IRUGO, fan_show_value, NULL, FAN##index##_REAR_SPEED_RPM) -#define DECLARE_FAN_SPEED_RPM_ATTR(index, index2) &sensor_dev_attr_fan##index##_front_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_fan##index##_rear_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_fan##index##_input.dev_attr.attr, \ - &sensor_dev_attr_fan##index2##_input.dev_attr.attr - -/* 6 fan fault attributes in this platform */ -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(1,11); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(2,12); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(3,13); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(4,14); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(5,15); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(6,16); -/* 6 fan speed(rpm) attributes in this platform */ -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(1,11); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(2,12); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(3,13); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(4,14); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(5,15); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(6,16); -/* 6 fan present attributes in this platform */ -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(1); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(2); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(3); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(4); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(5); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(6); -/* 6 fan direction attribute in this platform */ -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(1); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(2); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(3); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(4); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(5); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(6); -/* 1 fan duty cycle attribute in this platform */ -DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(1); -/* System temperature for fancontrol */ -DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR(); - -static struct attribute *as7312_54x_fan_attributes[] = { - /* fan related attributes */ - DECLARE_FAN_FAULT_ATTR(1,11), - DECLARE_FAN_FAULT_ATTR(2,12), - DECLARE_FAN_FAULT_ATTR(3,13), - DECLARE_FAN_FAULT_ATTR(4,14), - DECLARE_FAN_FAULT_ATTR(5,15), - DECLARE_FAN_FAULT_ATTR(6,16), - DECLARE_FAN_SPEED_RPM_ATTR(1,11), - DECLARE_FAN_SPEED_RPM_ATTR(2,12), - DECLARE_FAN_SPEED_RPM_ATTR(3,13), - DECLARE_FAN_SPEED_RPM_ATTR(4,14), - DECLARE_FAN_SPEED_RPM_ATTR(5,15), - DECLARE_FAN_SPEED_RPM_ATTR(6,16), - DECLARE_FAN_PRESENT_ATTR(1), - DECLARE_FAN_PRESENT_ATTR(2), - DECLARE_FAN_PRESENT_ATTR(3), - DECLARE_FAN_PRESENT_ATTR(4), - DECLARE_FAN_PRESENT_ATTR(5), - DECLARE_FAN_PRESENT_ATTR(6), - DECLARE_FAN_DIRECTION_ATTR(1), - DECLARE_FAN_DIRECTION_ATTR(2), - DECLARE_FAN_DIRECTION_ATTR(3), - DECLARE_FAN_DIRECTION_ATTR(4), - DECLARE_FAN_DIRECTION_ATTR(5), - DECLARE_FAN_DIRECTION_ATTR(6), - DECLARE_FAN_DUTY_CYCLE_ATTR(1), - DECLARE_FAN_SYSTEM_TEMP_ATTR(), - NULL -}; - -#define FAN_DUTY_CYCLE_REG_MASK 0xF -#define FAN_MAX_DUTY_CYCLE 100 -#define FAN_REG_VAL_TO_SPEED_RPM_STEP 100 - -static int as7312_54x_fan_read_value(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_byte_data(client, reg); -} - -static int as7312_54x_fan_write_value(struct i2c_client *client, u8 reg, u8 value) -{ - return i2c_smbus_write_byte_data(client, reg, value); -} - -/* fan utility functions - */ -static u32 reg_val_to_duty_cycle(u8 reg_val) -{ - reg_val &= FAN_DUTY_CYCLE_REG_MASK; - return ((u32)(reg_val+1) * 625 + 75)/ 100; -} - -static u8 duty_cycle_to_reg_val(u8 duty_cycle) -{ - return ((u32)duty_cycle * 100 / 625) - 1; -} - -static u32 reg_val_to_speed_rpm(u8 reg_val) -{ - return (u32)reg_val * FAN_REG_VAL_TO_SPEED_RPM_STEP; -} - -static u8 reg_val_to_direction(u8 reg_val, enum fan_id id) -{ - u8 mask = (1 << id); - - reg_val &= mask; - - return reg_val ? 1 : 0; -} -static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id) -{ - u8 mask = (1 << id); - - reg_val &= mask; - - return reg_val ? 0 : 1; -} - -static u8 is_fan_fault(struct as7312_54x_fan_data *data, enum fan_id id) -{ - u8 ret = 1; - int front_fan_index = FAN1_FRONT_SPEED_RPM + id; - int rear_fan_index = FAN1_REAR_SPEED_RPM + id; - - /* Check if the speed of front or rear fan is ZERO, - */ - if (reg_val_to_speed_rpm(data->reg_val[front_fan_index]) && - reg_val_to_speed_rpm(data->reg_val[rear_fan_index])) { - ret = 0; - } - - return ret; -} - -static ssize_t set_enable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct as7312_54x_fan_data *data = as7312_54x_fan_update_device(dev); - int error, value; - - error = kstrtoint(buf, 10, &value); - if (error) - return error; - - if (value < 0 || value > 1) - return -EINVAL; - - data->enable = value; - if (value == 0) - { - return set_duty_cycle(dev, da, buf, FAN_MAX_DUTY_CYCLE); - } - return count; -} - - -static ssize_t get_enable(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as7312_54x_fan_data *data = as7312_54x_fan_update_device(dev); - - return sprintf(buf, "%u\n", data->enable); -} -static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - int error, value; - struct i2c_client *client = to_i2c_client(dev); - - error = kstrtoint(buf, 10, &value); - if (error) - return error; - - if (value < 0) - return -EINVAL; - - value = (value > FAN_MAX_DUTY_CYCLE)? FAN_MAX_DUTY_CYCLE : value; - - as7312_54x_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */ - as7312_54x_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value)); - return count; -} - -/* Due to this struct is declared at lm75.c, it cannot be include - * under Sonic environment. I duplicate it from lm75.c. - */ -struct lm75_data { - struct i2c_client *client; - struct device *hwmon_dev; - struct thermal_zone_device *tz; - struct mutex update_lock; - u8 orig_conf; - u8 resolution; /* In bits, between 9 and 12 */ - u8 resolution_limits; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - unsigned long sample_time; /* In jiffies */ - s16 temp[3]; /* Register values, - 0 = input - 1 = max - 2 = hyst */ -}; - -/*Copied from lm75.c*/ -static inline long lm75_reg_to_mc(s16 temp, u8 resolution) -{ - return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8); -} - -/*Get hwmon_dev from i2c_client, set hwmon_dev = NULL is failed.*/ -static struct device * get_hwmon_dev( - struct i2c_client *client) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - if(data) - { - if( data->valid == 1 && data->hwmon_dev) - { - return data->hwmon_dev; - } - - } - return NULL; -} - -/* To find hwmon index by opening hwmon under that i2c address. - */ -static int find_hwmon_index_by_FileOpen( - int bus_nr, - unsigned short addr, - OUT int *index) -{ -#define MAX_HWMON_DEVICE (10) /* Find hwmon device in 0~10*/ - struct file *sfd; - char client_name[96]; - int i=0; - - do { - snprintf(client_name, sizeof(client_name), - "/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input", - bus_nr, addr, i); - - sfd = filp_open(client_name, O_RDONLY, 0); - i++; - } while( IS_ERR(sfd) && i < MAX_HWMON_DEVICE); - - if (IS_ERR(sfd)) { - pr_err("Failed to open file(%s)#%d\r\n", client_name, __LINE__); - return -ENOENT; - } - filp_close(sfd, 0); - *index = i - 1; - return 0; - -#undef MAX_HWMON_DEVICE -} - -static int get_temp_file_path( - int bus_nr, unsigned short addr, - struct device *hwmon_dev - ,char *path, int max_len) -{ - - if(hwmon_dev && strlen(dev_name(hwmon_dev))) - { - snprintf(path, max_len, - "/sys/bus/i2c/devices/%d-%04x/hwmon/%s/temp1_input", - bus_nr, addr, dev_name(hwmon_dev)); - } - else - { - int i=0; - if(find_hwmon_index_by_FileOpen( bus_nr, addr, &i)) - { - return -EIO; - } - snprintf(path, max_len, - "/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input", - bus_nr, addr, i); - } - return 0; -} - -/*File read the dev file at user space.*/ -static int read_devfile_temp1_input( - struct device *dev, - int bus_nr, - unsigned short addr, - struct device *hwmon_dev, - int *miniCelsius) -{ - struct file *sfd; - char buffer[96]; - char devfile[96]; - int rc, status; - int rdlen, value; - mm_segment_t old_fs; - - rc = 0; - get_temp_file_path(bus_nr, addr, hwmon_dev, devfile, sizeof(devfile)); - sfd = filp_open(devfile, O_RDONLY, 0); - if (IS_ERR(sfd)) { - pr_err("Failed to open file(%s)#%d\r\n", devfile, __LINE__); - return -ENOENT; - } - dev_dbg(dev, "Found device:%s\n",devfile); - - if(!(sfd->f_op) || !(sfd->f_op->read) ) { - pr_err("file %s cann't readable ?\n",devfile); - return -ENOENT; - } - - old_fs = get_fs(); - set_fs(KERNEL_DS); - rdlen = sfd->f_op->read(sfd, buffer, sizeof(buffer), &sfd->f_pos); - if (rdlen == 0) { - pr_err( "File(%s) empty!\n", devfile); - rc = -EIO; - goto exit; - } - status = sscanf(buffer, "%d", &value); - if (status != 1) { - rc = -EIO; - goto exit; - } - *miniCelsius = value; - dev_dbg(dev,"found sensors: %d @i2c %d-%04x\n", value, bus_nr, addr); - -exit: - set_fs(old_fs); - filp_close(sfd, 0); - return rc; -} - -static u8 is_lm75_data_due(struct i2c_client *client) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - if (time_after(jiffies, data->last_updated + data->sample_time)) - { - return 1; - } - return 0; -} -static int get_lm75_temp(struct i2c_client *client, int *miniCelsius) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - *miniCelsius = lm75_reg_to_mc(data->temp[0], data->resolution); - - return 0; -} - -static bool lm75_addr_mached(unsigned short addr) -{ - int i; - unsigned short addrs[] = THERMAL_SENSORS_ADDRS; - - for (i = 0; i < ARRAY_SIZE(addrs); i++) - { - if( addr == addrs[i]) - return 1; - } - return 0; -} - -static int _find_lm75_device(struct device *dev, void *data) -{ - struct device_driver *driver; - struct as7312_54x_fan_data *prv = data; - char *driver_name = THERMAL_SENSORS_DRIVER; - - driver = dev->driver; - if (driver && driver->name && - strcmp(driver->name, driver_name) == 0) - { - struct i2c_client *client; - client = to_i2c_client(dev); - if (client) - { - /*cannot use "struct i2c_adapter *adap = to_i2c_adapter(dev);"*/ - struct i2c_adapter *adap = client->adapter; - int miniCelsius = 0; - - if (! lm75_addr_mached(client->addr)) - { - return 0; - } - - if (!adap) { - return -ENXIO; - } - - /* If the data is not updated, read them from devfile - to drive them updateing data from chip.*/ - if (is_lm75_data_due(client)) - { - struct device *hwmon_dev; - - hwmon_dev = get_hwmon_dev(client); - if(0 == read_devfile_temp1_input(dev, adap->nr, - client->addr, hwmon_dev, &miniCelsius)) - { - prv->system_temp += miniCelsius; - prv->sensors_found++; - } - - } - else - { - get_lm75_temp(client, &miniCelsius); - prv->system_temp += miniCelsius; - prv->sensors_found++; - - } - } - } - return 0; -} - -/*Find all lm75 devices and return sum of temperatures.*/ -static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, - char *buf) -{ - ssize_t ret = 0; - struct as7312_54x_fan_data *data = as7312_54x_fan_update_device(dev); - - data->system_temp=0; - data->sensors_found=0; - i2c_for_each_dev(data, _find_lm75_device); - if (NUM_THERMAL_SENSORS != data->sensors_found) - { - dev_dbg(dev,"only %d of %d temps are found\n", - data->sensors_found, NUM_THERMAL_SENSORS); - data->system_temp = INT_MAX; - } - ret = sprintf(buf, "%d\n",data->system_temp); - return ret; -} - -static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as7312_54x_fan_data *data = as7312_54x_fan_update_device(dev); - ssize_t ret = 0; - - if (data->valid) { - switch (attr->index) { - case FAN_DUTY_CYCLE_PERCENTAGE: - { - u32 duty_cycle = reg_val_to_duty_cycle(data->reg_val[FAN_DUTY_CYCLE_PERCENTAGE]); - ret = sprintf(buf, "%u\n", duty_cycle); - break; - } - case FAN1_FRONT_SPEED_RPM: - case FAN2_FRONT_SPEED_RPM: - case FAN3_FRONT_SPEED_RPM: - case FAN4_FRONT_SPEED_RPM: - case FAN5_FRONT_SPEED_RPM: - case FAN6_FRONT_SPEED_RPM: - case FAN1_REAR_SPEED_RPM: - case FAN2_REAR_SPEED_RPM: - case FAN3_REAR_SPEED_RPM: - case FAN4_REAR_SPEED_RPM: - case FAN5_REAR_SPEED_RPM: - case FAN6_REAR_SPEED_RPM: - ret = sprintf(buf, "%u\n", reg_val_to_speed_rpm(data->reg_val[attr->index])); - break; - case FAN1_PRESENT: - case FAN2_PRESENT: - case FAN3_PRESENT: - case FAN4_PRESENT: - case FAN5_PRESENT: - case FAN6_PRESENT: - ret = sprintf(buf, "%d\n", - reg_val_to_is_present(data->reg_val[FAN_PRESENT_REG], - attr->index - FAN1_PRESENT)); - break; - case FAN1_FAULT: - case FAN2_FAULT: - case FAN3_FAULT: - case FAN4_FAULT: - case FAN5_FAULT: - case FAN6_FAULT: - ret = sprintf(buf, "%d\n", is_fan_fault(data, attr->index - FAN1_FAULT)); - break; - case FAN1_DIRECTION: - case FAN2_DIRECTION: - case FAN3_DIRECTION: - case FAN4_DIRECTION: - case FAN5_DIRECTION: - case FAN6_DIRECTION: - ret = sprintf(buf, "%d\n", - reg_val_to_direction(data->reg_val[FAN_DIRECTION_REG], - attr->index - FAN1_DIRECTION)); - break; - default: - break; - } - } - - return ret; -} - -static const struct attribute_group as7312_54x_fan_group = { - .attrs = as7312_54x_fan_attributes, -}; - -static struct as7312_54x_fan_data *as7312_54x_fan_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7312_54x_fan_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || - !data->valid) { - int i; - - dev_dbg(&client->dev, "Starting as7312_54x_fan update\n"); - data->valid = 0; - - /* Update fan data - */ - for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) { - int status = as7312_54x_fan_read_value(client, fan_reg[i]); - - if (status < 0) { - data->valid = 0; - mutex_unlock(&data->update_lock); - dev_dbg(&client->dev, "reg %d, err %d\n", fan_reg[i], status); - return data; - } - else { - data->reg_val[i] = status; - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -static int as7312_54x_fan_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7312_54x_fan_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7312_54x_fan_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - data->enable = 0; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7312_54x_fan_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: fan '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7312_54x_fan_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7312_54x_fan_remove(struct i2c_client *client) -{ - struct as7312_54x_fan_data *data = i2c_get_clientdata(client); - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7312_54x_fan_group); - - return 0; -} - -/* Addresses to scan */ -static const unsigned short normal_i2c[] = { 0x66, I2C_CLIENT_END }; - -static const struct i2c_device_id as7312_54x_fan_id[] = { - { "as7312_54x_fan", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7312_54x_fan_id); - -static struct i2c_driver as7312_54x_fan_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = DRVNAME, - }, - .probe = as7312_54x_fan_probe, - .remove = as7312_54x_fan_remove, - .id_table = as7312_54x_fan_id, - .address_list = normal_i2c, -}; - -static int __init as7312_54x_fan_init(void) -{ - return i2c_add_driver(&as7312_54x_fan_driver); -} - -static void __exit as7312_54x_fan_exit(void) -{ - i2c_del_driver(&as7312_54x_fan_driver); -} - -module_init(as7312_54x_fan_init); -module_exit(as7312_54x_fan_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7312_54x_fan driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_as7312_54x_leds.c b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_as7312_54x_leds.c deleted file mode 100644 index 1d54517c6243..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_as7312_54x_leds.c +++ /dev/null @@ -1,438 +0,0 @@ -/* - * A LED driver for the accton_as7312_54x_led - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/*#define DEBUG*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -extern int as7312_54x_cpld_read (unsigned short cpld_addr, u8 reg); -extern int as7312_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -extern void led_classdev_unregister(struct led_classdev *led_cdev); -extern int led_classdev_register(struct device *parent, struct led_classdev *led_cdev); -extern void led_classdev_resume(struct led_classdev *led_cdev); -extern void led_classdev_suspend(struct led_classdev *led_cdev); - -#define DRVNAME "accton_as7312_54x_led" - -struct accton_as7312_54x_led_data { - struct platform_device *pdev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[1]; /* only 1 register*/ -}; - -static struct accton_as7312_54x_led_data *ledctl = NULL; - -/* LED related data - */ - -#define LED_CNTRLER_I2C_ADDRESS (0x60) - -#define LED_TYPE_DIAG_REG_MASK (0x3) -#define LED_MODE_DIAG_GREEN_VALUE (0x02) -#define LED_MODE_DIAG_RED_VALUE (0x01) -#define LED_MODE_DIAG_AMBER_VALUE (0x00) /*It's yellow actually. Green+Red=Yellow*/ -#define LED_MODE_DIAG_OFF_VALUE (0x03) - - -#define LED_TYPE_LOC_REG_MASK (0x80) -#define LED_MODE_LOC_ON_VALUE (0) -#define LED_MODE_LOC_OFF_VALUE (0x80) - -enum led_type { - LED_TYPE_DIAG, - LED_TYPE_LOC, - LED_TYPE_FAN, - LED_TYPE_PSU1, - LED_TYPE_PSU2 -}; - -struct led_reg { - u32 types; - u8 reg_addr; -}; - -static const struct led_reg led_reg_map[] = { - {(1<update_lock); - - if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2) - || !ledctl->valid) { - int i; - - dev_dbg(&ledctl->pdev->dev, "Starting accton_as7312_54x_led update\n"); - - /* Update LED data - */ - for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { - int status = accton_as7312_54x_led_read_value(led_reg_map[i].reg_addr); - - if (status < 0) { - ledctl->valid = 0; - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg_map[i].reg_addr, status); - goto exit; - } - else - { - ledctl->reg_val[i] = status; - } - } - - ledctl->last_updated = jiffies; - ledctl->valid = 1; - } - -exit: - mutex_unlock(&ledctl->update_lock); -} - -static void accton_as7312_54x_led_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode, - enum led_type type) -{ - int reg_val; - u8 reg ; - mutex_lock(&ledctl->update_lock); - - if( !accton_getLedReg(type, ®)) - { - dev_dbg(&ledctl->pdev->dev, "Not match item for %d.\n", type); - } - - reg_val = accton_as7312_54x_led_read_value(reg); - - if (reg_val < 0) { - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val); - goto exit; - } - reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val); - accton_as7312_54x_led_write_value(reg, reg_val); - - /* to prevent the slow-update issue */ - ledctl->valid = 0; - -exit: - mutex_unlock(&ledctl->update_lock); -} - - -static void accton_as7312_54x_led_diag_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as7312_54x_led_set(led_cdev, led_light_mode, LED_TYPE_DIAG); -} - -static enum led_brightness accton_as7312_54x_led_diag_get(struct led_classdev *cdev) -{ - accton_as7312_54x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); -} - -static void accton_as7312_54x_led_loc_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as7312_54x_led_set(led_cdev, led_light_mode, LED_TYPE_LOC); -} - -static enum led_brightness accton_as7312_54x_led_loc_get(struct led_classdev *cdev) -{ - accton_as7312_54x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); -} - -static void accton_as7312_54x_led_auto_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ -} - -static enum led_brightness accton_as7312_54x_led_auto_get(struct led_classdev *cdev) -{ - return LED_MODE_AUTO; -} - -static struct led_classdev accton_as7312_54x_leds[] = { - [LED_TYPE_DIAG] = { - .name = "accton_as7312_54x_led::diag", - .default_trigger = "unused", - .brightness_set = accton_as7312_54x_led_diag_set, - .brightness_get = accton_as7312_54x_led_diag_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_RED, - }, - [LED_TYPE_LOC] = { - .name = "accton_as7312_54x_led::loc", - .default_trigger = "unused", - .brightness_set = accton_as7312_54x_led_loc_set, - .brightness_get = accton_as7312_54x_led_loc_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_BLUE, - }, - [LED_TYPE_FAN] = { - .name = "accton_as7312_54x_led::fan", - .default_trigger = "unused", - .brightness_set = accton_as7312_54x_led_auto_set, - .brightness_get = accton_as7312_54x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_PSU1] = { - .name = "accton_as7312_54x_led::psu1", - .default_trigger = "unused", - .brightness_set = accton_as7312_54x_led_auto_set, - .brightness_get = accton_as7312_54x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_PSU2] = { - .name = "accton_as7312_54x_led::psu2", - .default_trigger = "unused", - .brightness_set = accton_as7312_54x_led_auto_set, - .brightness_get = accton_as7312_54x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, -}; - -static int accton_as7312_54x_led_suspend(struct platform_device *dev, - pm_message_t state) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(accton_as7312_54x_leds); i++) { - led_classdev_suspend(&accton_as7312_54x_leds[i]); - } - - return 0; -} - -static int accton_as7312_54x_led_resume(struct platform_device *dev) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(accton_as7312_54x_leds); i++) { - led_classdev_resume(&accton_as7312_54x_leds[i]); - } - - return 0; -} - -static int accton_as7312_54x_led_probe(struct platform_device *pdev) -{ - int ret, i; - - for (i = 0; i < ARRAY_SIZE(accton_as7312_54x_leds); i++) { - ret = led_classdev_register(&pdev->dev, &accton_as7312_54x_leds[i]); - - if (ret < 0) - break; - } - - /* Check if all LEDs were successfully registered */ - if (i != ARRAY_SIZE(accton_as7312_54x_leds)) { - int j; - - /* only unregister the LEDs that were successfully registered */ - for (j = 0; j < i; j++) { - led_classdev_unregister(&accton_as7312_54x_leds[i]); - } - } - - return ret; -} - -static int accton_as7312_54x_led_remove(struct platform_device *pdev) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(accton_as7312_54x_leds); i++) { - led_classdev_unregister(&accton_as7312_54x_leds[i]); - } - - return 0; -} - -static struct platform_driver accton_as7312_54x_led_driver = { - .probe = accton_as7312_54x_led_probe, - .remove = accton_as7312_54x_led_remove, - .suspend = accton_as7312_54x_led_suspend, - .resume = accton_as7312_54x_led_resume, - .driver = { - .name = DRVNAME, - .owner = THIS_MODULE, - }, -}; - -static int __init accton_as7312_54x_led_init(void) -{ - int ret; - - ret = platform_driver_register(&accton_as7312_54x_led_driver); - if (ret < 0) { - goto exit; - } - - ledctl = kzalloc(sizeof(struct accton_as7312_54x_led_data), GFP_KERNEL); - if (!ledctl) { - ret = -ENOMEM; - platform_driver_unregister(&accton_as7312_54x_led_driver); - goto exit; - } - - mutex_init(&ledctl->update_lock); - - ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); - if (IS_ERR(ledctl->pdev)) { - ret = PTR_ERR(ledctl->pdev); - platform_driver_unregister(&accton_as7312_54x_led_driver); - kfree(ledctl); - goto exit; - } - -exit: - return ret; -} - -static void __exit accton_as7312_54x_led_exit(void) -{ - platform_device_unregister(ledctl->pdev); - platform_driver_unregister(&accton_as7312_54x_led_driver); - kfree(ledctl); -} - -module_init(accton_as7312_54x_led_init); -module_exit(accton_as7312_54x_led_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton_as7312_54x_led driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_as7312_54x_psu.c b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_as7312_54x_psu.c deleted file mode 100644 index 4646224ef903..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_as7312_54x_psu.c +++ /dev/null @@ -1,277 +0,0 @@ -/* - * An hwmon driver for accton as7312_54x Power Module - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); -static int as7312_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int as7312_54x_cpld_read(unsigned short cpld_addr, u8 reg); - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x50, 0x53, I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as7312_54x_psu_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 index; /* PSU index */ - u8 status; /* Status(present/power_good) register read from CPLD */ - char model_name[9]; /* Model name, read from eeprom */ -}; - -static struct as7312_54x_psu_data *as7312_54x_psu_update_device(struct device *dev); - -enum as7312_54x_psu_sysfs_attributes { - PSU_PRESENT, - PSU_MODEL_NAME, - PSU_POWER_GOOD -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT); -static SENSOR_DEVICE_ATTR(psu_model_name, S_IRUGO, show_model_name,NULL, PSU_MODEL_NAME); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD); - -static struct attribute *as7312_54x_psu_attributes[] = { - &sensor_dev_attr_psu_present.dev_attr.attr, - &sensor_dev_attr_psu_model_name.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - NULL -}; - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as7312_54x_psu_data *data = as7312_54x_psu_update_device(dev); - u8 status = 0; - - if (attr->index == PSU_PRESENT) { - status = !(data->status >> (1-data->index) & 0x1); - } - else { /* PSU_POWER_GOOD */ - status = (data->status >> (3-data->index) & 0x1); - } - - return sprintf(buf, "%d\n", status); -} - -static ssize_t show_model_name(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as7312_54x_psu_data *data = as7312_54x_psu_update_device(dev); - - return sprintf(buf, "%s\n", data->model_name); -} - -static const struct attribute_group as7312_54x_psu_group = { - .attrs = as7312_54x_psu_attributes, -}; - -static int as7312_54x_psu_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7312_54x_psu_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7312_54x_psu_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - data->index = dev_id->driver_data; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7312_54x_psu_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7312_54x_psu_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7312_54x_psu_remove(struct i2c_client *client) -{ - struct as7312_54x_psu_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7312_54x_psu_group); - kfree(data); - - return 0; -} - -enum psu_index -{ - as7312_54x_psu1, - as7312_54x_psu2 -}; - -static const struct i2c_device_id as7312_54x_psu_id[] = { - { "as7312_54x_psu1", as7312_54x_psu1 }, - { "as7312_54x_psu2", as7312_54x_psu2 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7312_54x_psu_id); - -static struct i2c_driver as7312_54x_psu_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7312_54x_psu", - }, - .probe = as7312_54x_psu_probe, - .remove = as7312_54x_psu_remove, - .id_table = as7312_54x_psu_id, - .address_list = normal_i2c, -}; - -static int as7312_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = 0; - int retry_count = 5; - - while (retry_count) { - retry_count--; - - result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) { - msleep(10); - continue; - } - - if (unlikely(result != data_len)) { - result = -EIO; - msleep(10); - continue; - } - - result = 0; - break; - } - - return result; -} - -static struct as7312_54x_psu_data *as7312_54x_psu_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7312_54x_psu_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int status; - int power_good = 0; - - dev_dbg(&client->dev, "Starting as7312_54x update\n"); - - /* Read psu status */ - status = as7312_54x_cpld_read(0x60, 0x2); - - if (status < 0) { - dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); - } - else { - data->status = status; - } - - /* Read model name */ - memset(data->model_name, 0, sizeof(data->model_name)); - power_good = (data->status >> (3-data->index) & 0x1); - - if (power_good) { - status = as7312_54x_psu_read_block(client, 0x20, data->model_name, - ARRAY_SIZE(data->model_name)-1); - - if (status < 0) { - data->model_name[0] = '\0'; - dev_dbg(&client->dev, "unable to read model name from (0x%x)\n", client->addr); - } - else { - data->model_name[ARRAY_SIZE(data->model_name)-1] = '\0'; - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -module_i2c_driver(as7312_54x_psu_driver); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7312_54x_psu driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_as7312_54x_sfp.c b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_as7312_54x_sfp.c deleted file mode 100644 index 921d9f892cac..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_as7312_54x_sfp.c +++ /dev/null @@ -1,1972 +0,0 @@ -/* - * SFP driver for accton as7312_54x sfp - * - * Copyright (C) Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRIVER_NAME "as7312_54x_sfp" /* Platform dependent */ - -#define DEBUG_MODE 0 - -#if (DEBUG_MODE == 1) -#define DEBUG_PRINT(fmt, args...) \ - printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) -#else -#define DEBUG_PRINT(fmt, args...) -#endif - -#define NUM_OF_PORT 54 -#define SFP_PORT_MAX 48 -#define EEPROM_NAME "sfp_eeprom" -#define EEPROM_SIZE 256 /* 256 byte eeprom */ -#define BIT_INDEX(i) (1ULL << (i)) -#define USE_I2C_BLOCK_READ 1 /* Platform dependent */ -#define I2C_RW_RETRY_COUNT 10 -#define I2C_RW_RETRY_INTERVAL 60 /* ms */ - -#define SFP_EEPROM_A0_I2C_ADDR (0xA0 >> 1) - -#define SFF8024_PHYSICAL_DEVICE_ID_ADDR 0x0 -#define SFF8024_DEVICE_ID_SFP 0x3 -#define SFF8024_DEVICE_ID_QSFP 0xC -#define SFF8024_DEVICE_ID_QSFP_PLUS 0xD -#define SFF8024_DEVICE_ID_QSFP28 0x11 - -#define SFF8472_DIAG_MON_TYPE_ADDR 92 -#define SFF8472_DIAG_MON_TYPE_DDM_MASK 0x40 -#define SFF8436_RX_LOS_ADDR 3 -#define SFF8436_TX_FAULT_ADDR 4 -#define SFF8436_TX_DISABLE_ADDR 86 - -#define MULTIPAGE_SUPPORT 1 - -#if (MULTIPAGE_SUPPORT == 1) -/* fundamental unit of addressing for SFF_8472/SFF_8436 */ -#define SFF_8436_PAGE_SIZE 128 -/* - * The current 8436 (QSFP) spec provides for only 4 supported - * pages (pages 0-3). - * This driver is prepared to support more, but needs a register in the - * EEPROM to indicate how many pages are supported before it is safe - * to implement more pages in the driver. - */ -#define SFF_8436_SPECED_PAGES 4 -#define SFF_8436_EEPROM_SIZE ((1 + SFF_8436_SPECED_PAGES) * SFF_8436_PAGE_SIZE) -#define SFF_8436_EEPROM_UNPAGED_SIZE (2 * SFF_8436_PAGE_SIZE) -/* - * The current 8472 (SFP) spec provides for only 3 supported - * pages (pages 0-2). - * This driver is prepared to support more, but needs a register in the - * EEPROM to indicate how many pages are supported before it is safe - * to implement more pages in the driver. - */ -#define SFF_8472_SPECED_PAGES 3 -#define SFF_8472_EEPROM_SIZE ((3 + SFF_8472_SPECED_PAGES) * SFF_8436_PAGE_SIZE) -#define SFF_8472_EEPROM_UNPAGED_SIZE (4 * SFF_8436_PAGE_SIZE) - -/* a few constants to find our way around the EEPROM */ -#define SFF_8436_PAGE_SELECT_REG 0x7F -#define SFF_8436_PAGEABLE_REG 0x02 -#define SFF_8436_NOT_PAGEABLE (1<<2) -#define SFF_8472_PAGEABLE_REG 0x40 -#define SFF_8472_PAGEABLE (1<<4) - -/* - * This parameter is to help this driver avoid blocking other drivers out - * of I2C for potentially troublesome amounts of time. With a 100 kHz I2C - * clock, one 256 byte read takes about 1/43 second which is excessive; - * but the 1/170 second it takes at 400 kHz may be quite reasonable; and - * at 1 MHz (Fm+) a 1/430 second delay could easily be invisible. - * - * This value is forced to be a power of two so that writes align on pages. - */ -static unsigned io_limit = SFF_8436_PAGE_SIZE; - -/* - * specs often allow 5 msec for a page write, sometimes 20 msec; - * it's important to recover from write timeouts. - */ -static unsigned write_timeout = 25; - -typedef enum qsfp_opcode { - QSFP_READ_OP = 0, - QSFP_WRITE_OP = 1 -} qsfp_opcode_e; -#endif - -/* Platform dependent +++ */ -#define I2C_ADDR_CPLD1 0x60 -#define I2C_ADDR_CPLD2 0x62 -#define I2C_ADDR_CPLD3 0x64 - -#define CPLD3_OFFSET_QSFP_MOD_RST 0x17 -/* Platform dependent --- */ -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_present(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count); -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count);; -static ssize_t sfp_eeprom_read(struct i2c_client *, u8, u8 *,int); -static ssize_t sfp_eeprom_write(struct i2c_client *, u8 , const char *,int); -static ssize_t get_mode_reset(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t set_mode_reset(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); -enum sfp_sysfs_attributes { - PRESENT, - PRESENT_ALL, - PORT_NUMBER, - PORT_TYPE, - DDM_IMPLEMENTED, - TX_FAULT, - TX_FAULT1, - TX_FAULT2, - TX_FAULT3, - TX_FAULT4, - TX_DISABLE, - TX_DISABLE1, - TX_DISABLE2, - TX_DISABLE3, - TX_DISABLE4, - RX_LOS, - RX_LOS1, - RX_LOS2, - RX_LOS3, - RX_LOS4, - RX_LOS_ALL, - SFP_MOD_RST -}; - -/* SFP/QSFP common attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, PRESENT); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, PRESENT_ALL); -static SENSOR_DEVICE_ATTR(sfp_rx_los, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS); -static SENSOR_DEVICE_ATTR(sfp_tx_disable, S_IWUSR | S_IRUGO, sfp_show_tx_rx_status, sfp_set_tx_disable, TX_DISABLE); -static SENSOR_DEVICE_ATTR(sfp_tx_fault, S_IRUGO, sfp_show_tx_rx_status, NULL, TX_FAULT); - -/* QSFP attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_rx_los1, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS1); -static SENSOR_DEVICE_ATTR(sfp_rx_los2, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS2); -static SENSOR_DEVICE_ATTR(sfp_rx_los3, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS3); -static SENSOR_DEVICE_ATTR(sfp_rx_los4, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS4); -static SENSOR_DEVICE_ATTR(sfp_tx_disable1, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE1); -static SENSOR_DEVICE_ATTR(sfp_tx_disable2, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE2); -static SENSOR_DEVICE_ATTR(sfp_tx_disable3, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE3); -static SENSOR_DEVICE_ATTR(sfp_tx_disable4, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE4); -static SENSOR_DEVICE_ATTR(sfp_tx_fault1, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT1); -static SENSOR_DEVICE_ATTR(sfp_tx_fault2, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT2); -static SENSOR_DEVICE_ATTR(sfp_tx_fault3, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT3); -static SENSOR_DEVICE_ATTR(sfp_tx_fault4, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT4); -static SENSOR_DEVICE_ATTR(sfp_mod_rst, S_IWUSR | S_IRUGO, get_mode_reset, set_mode_reset, SFP_MOD_RST); - -static struct attribute *qsfp_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los1.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los2.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los3.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault4.dev_attr.attr, - &sensor_dev_attr_sfp_mod_rst.dev_attr.attr, - NULL -}; - -/* SFP msa attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_rx_los_all, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS_ALL); -static struct attribute *sfp_msa_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los_all.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - NULL -}; - -/* Platform dependent +++ */ -#define CPLD_PORT_TO_FRONT_PORT(port) (port+1) - -enum port_numbers { - as7312_54x_port1, as7312_54x_port2, as7312_54x_port3, as7312_54x_port4, - as7312_54x_port5, as7312_54x_port6, as7312_54x_port7, as7312_54x_port8, - as7312_54x_port9, as7312_54x_port10, as7312_54x_port11, as7312_54x_port12, - as7312_54x_port13, as7312_54x_port14, as7312_54x_port15, as7312_54x_port16, - as7312_54x_port17, as7312_54x_port18, as7312_54x_port19, as7312_54x_port20, - as7312_54x_port21, as7312_54x_port22, as7312_54x_port23, as7312_54x_port24, - as7312_54x_port25, as7312_54x_port26, as7312_54x_port27, as7312_54x_port28, - as7312_54x_port29, as7312_54x_port30, as7312_54x_port31, as7312_54x_port32, - as7312_54x_port33, as7312_54x_port34, as7312_54x_port35, as7312_54x_port36, - as7312_54x_port37, as7312_54x_port38, as7312_54x_port39, as7312_54x_port40, - as7312_54x_port41, as7312_54x_port42, as7312_54x_port43, as7312_54x_port44, - as7312_54x_port45, as7312_54x_port46, as7312_54x_port47, as7312_54x_port48, - as7312_54x_port49, as7312_54x_port52, as7312_54x_port50, as7312_54x_port53, - as7312_54x_port51, as7312_54x_port54 -}; - -#define I2C_DEV_ID(x) { #x, x} - -static const struct i2c_device_id sfp_device_id[] = { - I2C_DEV_ID(as7312_54x_port1), - I2C_DEV_ID(as7312_54x_port2), - I2C_DEV_ID(as7312_54x_port3), - I2C_DEV_ID(as7312_54x_port4), - I2C_DEV_ID(as7312_54x_port5), - I2C_DEV_ID(as7312_54x_port6), - I2C_DEV_ID(as7312_54x_port7), - I2C_DEV_ID(as7312_54x_port8), - I2C_DEV_ID(as7312_54x_port9), - I2C_DEV_ID(as7312_54x_port10), - I2C_DEV_ID(as7312_54x_port11), - I2C_DEV_ID(as7312_54x_port12), - I2C_DEV_ID(as7312_54x_port13), - I2C_DEV_ID(as7312_54x_port14), - I2C_DEV_ID(as7312_54x_port15), - I2C_DEV_ID(as7312_54x_port16), - I2C_DEV_ID(as7312_54x_port17), - I2C_DEV_ID(as7312_54x_port18), - I2C_DEV_ID(as7312_54x_port19), - I2C_DEV_ID(as7312_54x_port20), - I2C_DEV_ID(as7312_54x_port21), - I2C_DEV_ID(as7312_54x_port22), - I2C_DEV_ID(as7312_54x_port23), - I2C_DEV_ID(as7312_54x_port24), - I2C_DEV_ID(as7312_54x_port25), - I2C_DEV_ID(as7312_54x_port26), - I2C_DEV_ID(as7312_54x_port27), - I2C_DEV_ID(as7312_54x_port28), - I2C_DEV_ID(as7312_54x_port29), - I2C_DEV_ID(as7312_54x_port30), - I2C_DEV_ID(as7312_54x_port31), - I2C_DEV_ID(as7312_54x_port32), - I2C_DEV_ID(as7312_54x_port33), - I2C_DEV_ID(as7312_54x_port34), - I2C_DEV_ID(as7312_54x_port35), - I2C_DEV_ID(as7312_54x_port36), - I2C_DEV_ID(as7312_54x_port37), - I2C_DEV_ID(as7312_54x_port38), - I2C_DEV_ID(as7312_54x_port39), - I2C_DEV_ID(as7312_54x_port40), - I2C_DEV_ID(as7312_54x_port41), - I2C_DEV_ID(as7312_54x_port42), - I2C_DEV_ID(as7312_54x_port43), - I2C_DEV_ID(as7312_54x_port44), - I2C_DEV_ID(as7312_54x_port45), - I2C_DEV_ID(as7312_54x_port46), - I2C_DEV_ID(as7312_54x_port47), - I2C_DEV_ID(as7312_54x_port48), - I2C_DEV_ID(as7312_54x_port49), - I2C_DEV_ID(as7312_54x_port50), - I2C_DEV_ID(as7312_54x_port51), - I2C_DEV_ID(as7312_54x_port52), - I2C_DEV_ID(as7312_54x_port53), - I2C_DEV_ID(as7312_54x_port54), - { /* LIST END */ } -}; -MODULE_DEVICE_TABLE(i2c, sfp_device_id); -/* Platform dependent --- */ - -enum driver_type_e { - DRIVER_TYPE_SFP_MSA, - DRIVER_TYPE_QSFP -}; - -/* Each client has this additional data - */ -struct eeprom_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - struct bin_attribute bin; /* eeprom data */ -}; - -struct sfp_msa_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u64 status[6]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss - 3 => device id - 4 => 10G Ethernet Compliance Codes - to distinguish SFP or SFP+ - 5 => DIAGNOSTIC MONITORING TYPE */ - struct eeprom_data eeprom; -#if (MULTIPAGE_SUPPORT == 1) - struct i2c_client *ddm_client; /* dummy client instance for 0xA2 */ -#endif -}; - -struct qsfp_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 status[3]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss */ - - u8 device_id; - struct eeprom_data eeprom; -}; - -struct sfp_port_data { - struct mutex update_lock; - enum driver_type_e driver_type; - int port; /* CPLD port index */ - u64 present; /* present status, bit0:port0, bit1:port1 and so on */ - - struct sfp_msa_data *msa; - struct qsfp_data *qsfp; - - struct i2c_client *client; -#if (MULTIPAGE_SUPPORT == 1) - int use_smbus; - u8 *writebuf; - unsigned write_max; -#endif -}; - -#if (MULTIPAGE_SUPPORT == 1) -static ssize_t sfp_port_read_write(struct sfp_port_data *port_data, - char *buf, loff_t off, size_t len, qsfp_opcode_e opcode); -#endif -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - return sprintf(buf, "%d\n", CPLD_PORT_TO_FRONT_PORT(data->port)); -} - -/* Platform dependent +++ */ -static struct sfp_port_data *sfp_update_present(struct i2c_client *client) -{ - int i = 0, j = 0, status = -1; - u8 reg; - unsigned short cpld_addr; - struct sfp_port_data *data = i2c_get_clientdata(client); - - DEBUG_PRINT("Starting sfp present status update"); - mutex_lock(&data->update_lock); - data->present = 0; - - /* Read present status of port 1~48(SFP port) */ - for (i = 0; i < 2; i++) { - for (j = 0; j < 3; j++) { - cpld_addr = I2C_ADDR_CPLD2 + i*2; - reg = 0x9+j; - status = accton_i2c_cpld_read(cpld_addr, reg); - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); - goto exit; - } - - DEBUG_PRINT("Present status = 0x%lx\r\n", data->present); - data->present |= (u64)status << ((i*24) + (j%3)*8); - } - } - - /* Read present status of port 49-52(QSFP port) */ - cpld_addr = I2C_ADDR_CPLD2; - reg = 0x18; - status = accton_i2c_cpld_read(cpld_addr, reg); - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); - goto exit; - } - else { - data->present |= (u64)(status & 0xF) << SFP_PORT_MAX; - } - - /* Read present status of port 53-54(QSFP port) */ - cpld_addr = I2C_ADDR_CPLD3; - reg = 0x18; - status = accton_i2c_cpld_read(cpld_addr, reg); - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); - goto exit; - } - else { - data->present |= (u64)(status & 0x3) << 52; - } - - DEBUG_PRINT("Present status = 0x%lx", data->present); -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static struct sfp_port_data* sfp_update_tx_rx_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int i = 0, j = 0; - int status = -1; - - if (time_before(jiffies, data->msa->last_updated + HZ + HZ / 2) && data->msa->valid) { - return data; - } - - DEBUG_PRINT("Starting as7312_54x sfp tx rx status update"); - mutex_lock(&data->update_lock); - data->msa->valid = 0; - memset(data->msa->status, 0, sizeof(data->msa->status)); - - /* Read status of port 1~48(SFP port) */ - for (i = 0; i < 2; i++) { - for (j = 0; j < 9; j++) { - u8 reg; - unsigned short cpld_addr; - reg = 0xc+j; - cpld_addr = I2C_ADDR_CPLD2 + i*2; - - status = accton_i2c_cpld_read(cpld_addr, reg); - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); - goto exit; - } - - data->msa->status[j/3] |= (u64)status << ((i*24) + (j%3)*8); - } - } - - data->msa->valid = 1; - data->msa->last_updated = jiffies; - -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - unsigned short cpld_addr = 0; - u8 cpld_reg = 0, cpld_val = 0, cpld_bit = 0; - long disable; - int error; - - if (data->driver_type == DRIVER_TYPE_QSFP) { - return qsfp_set_tx_disable(dev, da, buf, count); - } - - error = kstrtol(buf, 10, &disable); - if (error) { - return error; - } - - mutex_lock(&data->update_lock); - - if(data->port < 24) { - cpld_addr = I2C_ADDR_CPLD2; - cpld_reg = 0xF + data->port / 8; - cpld_bit = 1 << (data->port % 8); - } - else { /* port 24 ~ 48 */ - cpld_addr = I2C_ADDR_CPLD3; - cpld_reg = 0xF + (data->port - 24) / 8; - cpld_bit = 1 << (data->port % 8); - } - - /* Read current status */ - cpld_val = accton_i2c_cpld_read(cpld_addr, cpld_reg); - - /* Update tx_disable status */ - if (disable) { - data->msa->status[1] |= BIT_INDEX(data->port); - cpld_val |= cpld_bit; - } - else { - data->msa->status[1] &= ~BIT_INDEX(data->port); - cpld_val &= ~cpld_bit; - } - - accton_i2c_cpld_write(cpld_addr, cpld_reg, cpld_val); - mutex_unlock(&data->update_lock); - return count; -} - -static int sfp_is_port_present(struct i2c_client *client, int port) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - - data = sfp_update_present(client); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - return (data->present & BIT_INDEX(data->port)) ? 0 : 1; /* Platform dependent */ -} - -/* Platform dependent +++ */ -static ssize_t show_present(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); - - if (PRESENT_ALL == attr->index) { - int i; - u8 values[7] = {0}; - struct sfp_port_data *data = sfp_update_present(client); - - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - for (i = 0; i < ARRAY_SIZE(values); i++) { - values[i] = ~(u8)(data->present >> (i * 8)); - } - - /* Return values 1 -> 54 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5], - values[6] & 0x3F); - } - else { - struct sfp_port_data *data = i2c_get_clientdata(client); - int present = sfp_is_port_present(client, data->port); - - if (IS_ERR_VALUE(present)) { - return present; - } - - /* PRESENT */ - return sprintf(buf, "%d\n", present); - } -} -/* Platform dependent --- */ - -static struct sfp_port_data *qsfp_update_tx_rx_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int i, status = -1; - u8 buf = 0; - u8 reg[] = {SFF8436_TX_FAULT_ADDR, SFF8436_TX_DISABLE_ADDR, SFF8436_RX_LOS_ADDR}; - - if (time_before(jiffies, data->qsfp->last_updated + HZ + HZ / 2) && data->qsfp->valid) { - return data; - } - - DEBUG_PRINT("Starting sfp tx rx status update"); - mutex_lock(&data->update_lock); - data->qsfp->valid = 0; - memset(data->qsfp->status, 0, sizeof(data->qsfp->status)); - - /* Notify device to update tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - } - msleep(200); - - /* Read actual tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - - DEBUG_PRINT("qsfp reg(0x%x) status = (0x%x)", reg[i], data->qsfp->status[i]); - data->qsfp->status[i] = (buf & 0xF); - } - - data->qsfp->valid = 1; - data->qsfp->last_updated = jiffies; - -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static ssize_t get_mode_reset(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - u8 cpld_val = 0; - int port_bit; - int status = -EINVAL; - u8 cpld_addr[] = {I2C_ADDR_CPLD2, I2C_ADDR_CPLD3}; - - /* Low power mode is not supported for SFP ports(1-48) */ - if (data->port < SFP_PORT_MAX) { - return -EINVAL; - } - mutex_lock(&data->update_lock); - - port_bit = data->port - SFP_PORT_MAX; - cpld_val = accton_i2c_cpld_read(cpld_addr[port_bit/4], CPLD3_OFFSET_QSFP_MOD_RST); - - pr_err("[ROY]%s#%d, %x from %x\n", __func__, __LINE__, cpld_val, cpld_addr[port_bit/4]); - - cpld_val = cpld_val & 0x0F; - cpld_val = cpld_val & BIT_INDEX(port_bit%4); - - pr_err("[ROY]%s#%d, %x of bit %d\n", __func__, __LINE__, cpld_val, port_bit); - - status = snprintf(buf, PAGE_SIZE - 1, "%d\r\n", cpld_val>>(port_bit%4)); - - mutex_unlock(&data->update_lock); - - return status; -} - -static ssize_t set_mode_reset(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - u8 cpld_val = 0; - long reset; - int error, port_bit; - u8 cpld_addr[] = {I2C_ADDR_CPLD2, I2C_ADDR_CPLD3}; - - pr_err("[ROY]%s#%d, port:%d\n", __func__, __LINE__, data->port); - - /* Tx disable is not supported for QSFP ports(49-54) */ - if (data->port < SFP_PORT_MAX) { - return -EINVAL; - } - port_bit = data->port - SFP_PORT_MAX; - error = kstrtol(buf, 10, &reset); - - pr_err("[ROY]%s#%d, %s == %d\n", __func__, __LINE__, buf, error); - if (error) { - return error; - } - mutex_lock(&data->update_lock); - - cpld_val = accton_i2c_cpld_read(cpld_addr[port_bit/4], CPLD3_OFFSET_QSFP_MOD_RST); - pr_err("[ROY]%s#%d, %x\n", __func__, __LINE__, cpld_val); - /* Update lp_mode status */ - if (reset) - { - cpld_val |= BIT_INDEX(port_bit%4); - } - else - { - cpld_val &= ~BIT_INDEX(port_bit%4); - } - pr_err("[ROY]%s#%d, %x to %x\n", __func__, __LINE__, cpld_val, cpld_addr[port_bit/4]); - - accton_i2c_cpld_write(cpld_addr[port_bit/4], CPLD3_OFFSET_QSFP_MOD_RST, cpld_val); - - mutex_unlock(&data->update_lock); - - return count; -} -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - int present; - u8 val = 0; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - present = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENXIO; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - switch (attr->index) { - case TX_FAULT: - val = !!(data->qsfp->status[2] & 0xF); - break; - case TX_FAULT1: - case TX_FAULT2: - case TX_FAULT3: - case TX_FAULT4: - val = !!(data->qsfp->status[2] & BIT_INDEX(attr->index - TX_FAULT1)); - break; - case TX_DISABLE: - val = data->qsfp->status[1] & 0xF; - break; - case TX_DISABLE1: - case TX_DISABLE2: - case TX_DISABLE3: - case TX_DISABLE4: - val = !!(data->qsfp->status[1] & BIT_INDEX(attr->index - TX_DISABLE1)); - break; - case RX_LOS: - val = !!(data->qsfp->status[0] & 0xF); - break; - case RX_LOS1: - case RX_LOS2: - case RX_LOS3: - case RX_LOS4: - val = !!(data->qsfp->status[0] & BIT_INDEX(attr->index - RX_LOS1)); - break; - default: - break; - } - - return sprintf(buf, "%d\n", val); -} - -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - long disable; - int status; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - status = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(status)) { - return status; - } - - if (!status) { - /* port is not present */ - return -ENXIO; - } - - status = kstrtol(buf, 10, &disable); - if (status) { - return status; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - mutex_lock(&data->update_lock); - - if (attr->index == TX_DISABLE) { - if (disable) { - data->qsfp->status[1] |= 0xF; - } - else { - data->qsfp->status[1] &= ~0xF; - } - } - else {/* TX_DISABLE1 ~ TX_DISABLE4*/ - if (disable) { - data->qsfp->status[1] |= (1 << (attr->index - TX_DISABLE1)); - } - else { - data->qsfp->status[1] &= ~(1 << (attr->index - TX_DISABLE1)); - } - } - - DEBUG_PRINT("index = (%d), status = (0x%x)", attr->index, data->qsfp->status[1]); - status = sfp_eeprom_write(data->client, SFF8436_TX_DISABLE_ADDR, &data->qsfp->status[1], sizeof(data->qsfp->status[1])); - if (unlikely(status < 0)) { - count = status; - } - - mutex_unlock(&data->update_lock); - return count; -} - -/* Platform dependent +++ */ -static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - u8 val = 0, index = 0; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - if (data->driver_type == DRIVER_TYPE_QSFP) { - return qsfp_show_tx_rx_status(dev, da, buf); - } - - data = sfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - if(attr->index == RX_LOS_ALL) { - int i = 0; - u8 values[6] = {0}; - - for (i = 0; i < ARRAY_SIZE(values); i++) { - values[i] = (u8)(data->msa->status[2] >> (i * 8)); - } - - /** Return values 1 -> 48 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5]); - } - - switch (attr->index) { - case TX_FAULT: - index = 0; - break; - case TX_DISABLE: - index = 1; - break; - case RX_LOS: - index = 2; - break; - default: - return 0; - } - - val = (data->msa->status[index] & BIT_INDEX(data->port)) ? 1 : 0; - return sprintf(buf, "%d\n", val); -} -/* Platform dependent --- */ -static ssize_t sfp_eeprom_write(struct i2c_client *client, u8 command, const char *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_write_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return data_len; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, command, *data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return 1; -#endif - - -} - -#if (MULTIPAGE_SUPPORT == 0) -static ssize_t sfp_port_write(struct sfp_port_data *data, - const char *buf, loff_t off, size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) { - return count; - } - - /* - * Write data to chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_write(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; -} -#endif - -static ssize_t sfp_bin_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("%s(%d) offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - -#if (MULTIPAGE_SUPPORT == 1) - return sfp_port_read_write(data, buf, off, count, QSFP_WRITE_OP); -#else - return sfp_port_write(data, buf, off, count); -#endif -} - -static ssize_t sfp_eeprom_read(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - goto abort; - } - if (unlikely(status != data_len)) { - status = -EIO; - goto abort; - } - - //result = data_len; - -abort: - return status; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, command); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, status); - goto abort; - } - - *data = (u8)status; - status = 1; - -abort: - return status; -#endif -} - -#if (MULTIPAGE_SUPPORT == 1) -/*-------------------------------------------------------------------------*/ -/* - * This routine computes the addressing information to be used for - * a given r/w request. - * - * Task is to calculate the client (0 = i2c addr 50, 1 = i2c addr 51), - * the page, and the offset. - * - * Handles both SFP and QSFP. - * For SFP, offset 0-255 are on client[0], >255 is on client[1] - * Offset 256-383 are on the lower half of client[1] - * Pages are accessible on the upper half of client[1]. - * Offset >383 are in 128 byte pages mapped into the upper half - * - * For QSFP, all offsets are on client[0] - * offset 0-127 are on the lower half of client[0] (no paging) - * Pages are accessible on the upper half of client[1]. - * Offset >127 are in 128 byte pages mapped into the upper half - * - * Callers must not read/write beyond the end of a client or a page - * without recomputing the client/page. Hence offset (within page) - * plus length must be less than or equal to 128. (Note that this - * routine does not have access to the length of the call, hence - * cannot do the validity check.) - * - * Offset within Lower Page 00h and Upper Page 00h are not recomputed - */ -static uint8_t sff_8436_translate_offset(struct sfp_port_data *port_data, - loff_t *offset, struct i2c_client **client) -{ - unsigned page = 0; - - *client = port_data->client; - - /* if SFP style, offset > 255, shift to i2c addr 0x51 */ - if (port_data->driver_type == DRIVER_TYPE_SFP_MSA) { - if (*offset > 255) { - /* like QSFP, but shifted to client[1] */ - *client = port_data->msa->ddm_client; - *offset -= 256; - } - } - - /* - * if offset is in the range 0-128... - * page doesn't matter (using lower half), return 0. - * offset is already correct (don't add 128 to get to paged area) - */ - if (*offset < SFF_8436_PAGE_SIZE) - return page; - - /* note, page will always be positive since *offset >= 128 */ - page = (*offset >> 7)-1; - /* 0x80 places the offset in the top half, offset is last 7 bits */ - *offset = SFF_8436_PAGE_SIZE + (*offset & 0x7f); - - return page; /* note also returning client and offset */ -} - -static ssize_t sff_8436_eeprom_read(struct sfp_port_data *port_data, - struct i2c_client *client, - char *buf, unsigned offset, size_t count) -{ - struct i2c_msg msg[2]; - u8 msgbuf[2]; - unsigned long timeout, read_time; - int status, i; - - memset(msg, 0, sizeof(msg)); - - switch (port_data->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - /*smaller eeproms can work given some SMBus extension calls */ - if (count > I2C_SMBUS_BLOCK_MAX) - count = I2C_SMBUS_BLOCK_MAX; - break; - case I2C_SMBUS_WORD_DATA: - /* Check for odd length transaction */ - count = (count == 1) ? 1 : 2; - break; - case I2C_SMBUS_BYTE_DATA: - count = 1; - break; - default: - /* - * When we have a better choice than SMBus calls, use a - * combined I2C message. Write address; then read up to - * io_limit data bytes. msgbuf is u8 and will cast to our - * needs. - */ - i = 0; - msgbuf[i++] = offset; - - msg[0].addr = client->addr; - msg[0].buf = msgbuf; - msg[0].len = i; - - msg[1].addr = client->addr; - msg[1].flags = I2C_M_RD; - msg[1].buf = buf; - msg[1].len = count; - } - - /* - * Reads fail if the previous write didn't complete yet. We may - * loop a few times until this one succeeds, waiting at least - * long enough for one entire page write to work. - */ - timeout = jiffies + msecs_to_jiffies(write_timeout); - do { - read_time = jiffies; - - switch (port_data->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - status = i2c_smbus_read_i2c_block_data(client, offset, - count, buf); - break; - case I2C_SMBUS_WORD_DATA: - status = i2c_smbus_read_word_data(client, offset); - if (status >= 0) { - buf[0] = status & 0xff; - if (count == 2) - buf[1] = status >> 8; - status = count; - } - break; - case I2C_SMBUS_BYTE_DATA: - status = i2c_smbus_read_byte_data(client, offset); - if (status >= 0) { - buf[0] = status; - status = count; - } - break; - default: - status = i2c_transfer(client->adapter, msg, 2); - if (status == 2) - status = count; - } - - dev_dbg(&client->dev, "eeprom read %zu@%d --> %d (%ld)\n", - count, offset, status, jiffies); - - if (status == count) /* happy path */ - return count; - - if (status == -ENXIO) /* no module present */ - return status; - - /* REVISIT: at HZ=100, this is sloooow */ - msleep(1); - } while (time_before(read_time, timeout)); - - return -ETIMEDOUT; -} - -static ssize_t sff_8436_eeprom_write(struct sfp_port_data *port_data, - struct i2c_client *client, - const char *buf, - unsigned offset, size_t count) -{ - struct i2c_msg msg; - ssize_t status; - unsigned long timeout, write_time; - unsigned next_page_start; - int i = 0; - - /* write max is at most a page - * (In this driver, write_max is actually one byte!) - */ - if (count > port_data->write_max) - count = port_data->write_max; - - /* shorten count if necessary to avoid crossing page boundary */ - next_page_start = roundup(offset + 1, SFF_8436_PAGE_SIZE); - if (offset + count > next_page_start) - count = next_page_start - offset; - - switch (port_data->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - /*smaller eeproms can work given some SMBus extension calls */ - if (count > I2C_SMBUS_BLOCK_MAX) - count = I2C_SMBUS_BLOCK_MAX; - break; - case I2C_SMBUS_WORD_DATA: - /* Check for odd length transaction */ - count = (count == 1) ? 1 : 2; - break; - case I2C_SMBUS_BYTE_DATA: - count = 1; - break; - default: - /* If we'll use I2C calls for I/O, set up the message */ - msg.addr = client->addr; - msg.flags = 0; - - /* msg.buf is u8 and casts will mask the values */ - msg.buf = port_data->writebuf; - - msg.buf[i++] = offset; - memcpy(&msg.buf[i], buf, count); - msg.len = i + count; - break; - } - - /* - * Reads fail if the previous write didn't complete yet. We may - * loop a few times until this one succeeds, waiting at least - * long enough for one entire page write to work. - */ - timeout = jiffies + msecs_to_jiffies(write_timeout); - do { - write_time = jiffies; - - switch (port_data->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - status = i2c_smbus_write_i2c_block_data(client, - offset, count, buf); - if (status == 0) - status = count; - break; - case I2C_SMBUS_WORD_DATA: - if (count == 2) { - status = i2c_smbus_write_word_data(client, - offset, (u16)((buf[0])|(buf[1] << 8))); - } else { - /* count = 1 */ - status = i2c_smbus_write_byte_data(client, - offset, buf[0]); - } - if (status == 0) - status = count; - break; - case I2C_SMBUS_BYTE_DATA: - status = i2c_smbus_write_byte_data(client, offset, - buf[0]); - if (status == 0) - status = count; - break; - default: - status = i2c_transfer(client->adapter, &msg, 1); - if (status == 1) - status = count; - break; - } - - dev_dbg(&client->dev, "eeprom write %zu@%d --> %ld (%lu)\n", - count, offset, (long int) status, jiffies); - - if (status == count) - return count; - - /* REVISIT: at HZ=100, this is sloooow */ - msleep(1); - } while (time_before(write_time, timeout)); - - return -ETIMEDOUT; -} - - -static ssize_t sff_8436_eeprom_update_client(struct sfp_port_data *port_data, - char *buf, loff_t off, - size_t count, qsfp_opcode_e opcode) -{ - struct i2c_client *client; - ssize_t retval = 0; - u8 page = 0; - loff_t phy_offset = off; - int ret = 0; - - page = sff_8436_translate_offset(port_data, &phy_offset, &client); - - dev_dbg(&client->dev, - "sff_8436_eeprom_update_client off %lld page:%d phy_offset:%lld, count:%ld, opcode:%d\n", - off, page, phy_offset, (long int) count, opcode); - if (page > 0) { - ret = sff_8436_eeprom_write(port_data, client, &page, - SFF_8436_PAGE_SELECT_REG, 1); - if (ret < 0) { - dev_dbg(&client->dev, - "Write page register for page %d failed ret:%d!\n", - page, ret); - return ret; - } - } - - while (count) { - ssize_t status; - - if (opcode == QSFP_READ_OP) { - status = sff_8436_eeprom_read(port_data, client, - buf, phy_offset, count); - } else { - status = sff_8436_eeprom_write(port_data, client, - buf, phy_offset, count); - } - if (status <= 0) { - if (retval == 0) - retval = status; - break; - } - buf += status; - phy_offset += status; - count -= status; - retval += status; - } - - - if (page > 0) { - /* return the page register to page 0 (why?) */ - page = 0; - ret = sff_8436_eeprom_write(port_data, client, &page, - SFF_8436_PAGE_SELECT_REG, 1); - if (ret < 0) { - dev_err(&client->dev, - "Restore page register to page %d failed ret:%d!\n", - page, ret); - return ret; - } - } - return retval; -} - - -/* - * Figure out if this access is within the range of supported pages. - * Note this is called on every access because we don't know if the - * module has been replaced since the last call. - * If/when modules support more pages, this is the routine to update - * to validate and allow access to additional pages. - * - * Returns updated len for this access: - * - entire access is legal, original len is returned. - * - access begins legal but is too long, len is truncated to fit. - * - initial offset exceeds supported pages, return -EINVAL - */ -static ssize_t sff_8436_page_legal(struct sfp_port_data *port_data, - loff_t off, size_t len) -{ - struct i2c_client *client = port_data->client; - u8 regval; - int status; - size_t maxlen; - - if (off < 0) return -EINVAL; - if (port_data->driver_type == DRIVER_TYPE_SFP_MSA) { - /* SFP case */ - if ((off + len) <= 256) return len; - /* if no pages needed, we're good */ - //if ((off + len) <= SFF_8472_EEPROM_UNPAGED_SIZE) return len; - /* if offset exceeds possible pages, we're not good */ - if (off >= SFF_8472_EEPROM_SIZE) return -EINVAL; - - /* Check if ddm is supported */ - status = sff_8436_eeprom_read(port_data, client, ®val, - SFF8472_DIAG_MON_TYPE_ADDR, 1); - if (status < 0) return status; /* error out (no module?) */ - if (!(regval & SFF8472_DIAG_MON_TYPE_DDM_MASK)) { - if (off >= 256) return -EINVAL; - maxlen = 256 - off; - } - else { - /* in between, are pages supported? */ - status = sff_8436_eeprom_read(port_data, client, ®val, - SFF_8472_PAGEABLE_REG, 1); - if (status < 0) return status; /* error out (no module?) */ - if (regval & SFF_8472_PAGEABLE) { - /* Pages supported, trim len to the end of pages */ - maxlen = SFF_8472_EEPROM_SIZE - off; - } else { - /* pages not supported, trim len to unpaged size */ - if (off >= SFF_8472_EEPROM_UNPAGED_SIZE) return -EINVAL; - maxlen = SFF_8472_EEPROM_UNPAGED_SIZE - off; - } - } - len = (len > maxlen) ? maxlen : len; - dev_dbg(&client->dev, - "page_legal, SFP, off %lld len %ld\n", - off, (long int) len); - } - else if (port_data->driver_type == DRIVER_TYPE_QSFP) { - /* QSFP case */ - /* if no pages needed, we're good */ - if ((off + len) <= SFF_8436_EEPROM_UNPAGED_SIZE) return len; - /* if offset exceeds possible pages, we're not good */ - if (off >= SFF_8436_EEPROM_SIZE) return -EINVAL; - /* in between, are pages supported? */ - status = sff_8436_eeprom_read(port_data, client, ®val, - SFF_8436_PAGEABLE_REG, 1); - if (status < 0) return status; /* error out (no module?) */ - if (regval & SFF_8436_NOT_PAGEABLE) { - /* pages not supported, trim len to unpaged size */ - if (off >= SFF_8436_EEPROM_UNPAGED_SIZE) return -EINVAL; - maxlen = SFF_8436_EEPROM_UNPAGED_SIZE - off; - } else { - /* Pages supported, trim len to the end of pages */ - maxlen = SFF_8436_EEPROM_SIZE - off; - } - len = (len > maxlen) ? maxlen : len; - dev_dbg(&client->dev, - "page_legal, QSFP, off %lld len %ld\n", - off, (long int) len); - } - else { - return -EINVAL; - } - return len; -} - - -static ssize_t sfp_port_read_write(struct sfp_port_data *port_data, - char *buf, loff_t off, size_t len, qsfp_opcode_e opcode) -{ - struct i2c_client *client = port_data->client; - int chunk; - int status = 0; - ssize_t retval; - size_t pending_len = 0, chunk_len = 0; - loff_t chunk_offset = 0, chunk_start_offset = 0; - - if (unlikely(!len)) - return len; - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&port_data->update_lock); - - /* - * Confirm this access fits within the device suppored addr range - */ - len = sff_8436_page_legal(port_data, off, len); - if (len < 0) { - status = len; - goto err; - } - - /* - * For each (128 byte) chunk involved in this request, issue a - * separate call to sff_eeprom_update_client(), to - * ensure that each access recalculates the client/page - * and writes the page register as needed. - * Note that chunk to page mapping is confusing, is different for - * QSFP and SFP, and never needs to be done. Don't try! - */ - pending_len = len; /* amount remaining to transfer */ - retval = 0; /* amount transferred */ - for (chunk = off >> 7; chunk <= (off + len - 1) >> 7; chunk++) { - - /* - * Compute the offset and number of bytes to be read/write - * - * 1. start at offset 0 (within the chunk), and read/write - * the entire chunk - * 2. start at offset 0 (within the chunk) and read/write less - * than entire chunk - * 3. start at an offset not equal to 0 and read/write the rest - * of the chunk - * 4. start at an offset not equal to 0 and read/write less than - * (end of chunk - offset) - */ - chunk_start_offset = chunk * SFF_8436_PAGE_SIZE; - - if (chunk_start_offset < off) { - chunk_offset = off; - if ((off + pending_len) < (chunk_start_offset + - SFF_8436_PAGE_SIZE)) - chunk_len = pending_len; - else - chunk_len = (chunk+1)*SFF_8436_PAGE_SIZE - off;/*SFF_8436_PAGE_SIZE - off;*/ - } else { - chunk_offset = chunk_start_offset; - if (pending_len > SFF_8436_PAGE_SIZE) - chunk_len = SFF_8436_PAGE_SIZE; - else - chunk_len = pending_len; - } - - dev_dbg(&client->dev, - "sff_r/w: off %lld, len %ld, chunk_start_offset %lld, chunk_offset %lld, chunk_len %ld, pending_len %ld\n", - off, (long int) len, chunk_start_offset, chunk_offset, - (long int) chunk_len, (long int) pending_len); - - /* - * note: chunk_offset is from the start of the EEPROM, - * not the start of the chunk - */ - status = sff_8436_eeprom_update_client(port_data, buf, - chunk_offset, chunk_len, opcode); - if (status != chunk_len) { - /* This is another 'no device present' path */ - dev_dbg(&client->dev, - "sff_8436_update_client for chunk %d chunk_offset %lld chunk_len %ld failed %d!\n", - chunk, chunk_offset, (long int) chunk_len, status); - goto err; - } - buf += status; - pending_len -= status; - retval += status; - } - mutex_unlock(&port_data->update_lock); - - return retval; - -err: - mutex_unlock(&port_data->update_lock); - - return status; -} - -#else -static ssize_t sfp_port_read(struct sfp_port_data *data, - char *buf, loff_t off, size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) { - DEBUG_PRINT("Count = 0, return"); - return count; - } - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_read(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; - -} -#endif - -static ssize_t sfp_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - -#if (MULTIPAGE_SUPPORT == 1) - return sfp_port_read_write(data, buf, off, count, QSFP_READ_OP); -#else - return sfp_port_read(data, buf, off, count); -#endif -} - -#if (MULTIPAGE_SUPPORT == 1) -static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom, size_t size) -#else -static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom) -#endif -{ - int err; - - sysfs_bin_attr_init(eeprom); - eeprom->attr.name = EEPROM_NAME; - eeprom->attr.mode = S_IWUSR | S_IRUGO; - eeprom->read = sfp_bin_read; - eeprom->write = sfp_bin_write; -#if (MULTIPAGE_SUPPORT == 1) - eeprom->size = size; -#else - eeprom->size = EEPROM_SIZE; -#endif - - /* Create eeprom file */ - err = sysfs_create_bin_file(kobj, eeprom); - if (err) { - return err; - } - - return 0; -} - -static int sfp_sysfs_eeprom_cleanup(struct kobject *kobj, struct bin_attribute *eeprom) -{ - sysfs_remove_bin_file(kobj, eeprom); - return 0; -} - - -#if (MULTIPAGE_SUPPORT == 0) -static int sfp_i2c_check_functionality(struct i2c_client *client) -{ -#if USE_I2C_BLOCK_READ - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK); -#else - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA); -#endif -} -#endif - -static const struct attribute_group sfp_msa_group = { - .attrs = sfp_msa_attributes, -}; - -static int sfp_msa_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct sfp_msa_data **data) -{ - int status; - struct sfp_msa_data *msa; - -#if (MULTIPAGE_SUPPORT == 0) - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } -#endif - - msa = kzalloc(sizeof(struct sfp_msa_data), GFP_KERNEL); - if (!msa) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &sfp_msa_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ -#if (MULTIPAGE_SUPPORT == 1) - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &msa->eeprom.bin, SFF_8436_EEPROM_SIZE); -#else - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &msa->eeprom.bin); -#endif - if (status) { - goto exit_remove; - } - -#if (MULTIPAGE_SUPPORT == 1) - msa->ddm_client = i2c_new_dummy(client->adapter, client->addr + 1); - if (!msa->ddm_client) { - dev_err(&client->dev, "address 0x%02x unavailable\n", client->addr + 1); - status = -EADDRINUSE; - goto exit_eeprom; - } -#endif - - *data = msa; - dev_info(&client->dev, "sfp msa '%s'\n", client->name); - - return 0; - -exit_eeprom: - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &msa->eeprom.bin); -exit_remove: - sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); -exit_free: - kfree(msa); -exit: - - return status; -} - -static const struct attribute_group qsfp_group = { - .attrs = qsfp_attributes, -}; - -static int qsfp_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct qsfp_data **data) -{ - int status; - struct qsfp_data *qsfp; - -#if (MULTIPAGE_SUPPORT == 0) - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } -#endif - - qsfp = kzalloc(sizeof(struct qsfp_data), GFP_KERNEL); - if (!qsfp) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &qsfp_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ -#if (MULTIPAGE_SUPPORT == 1) - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin, SFF_8436_EEPROM_SIZE); -#else - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin); -#endif - if (status) { - goto exit_remove; - } - - *data = qsfp; - dev_info(&client->dev, "qsfp '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &qsfp_group); -exit_free: - kfree(qsfp); -exit: - - return status; -} - -/* Platform dependent +++ */ -static int sfp_device_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - int ret = 0; - struct sfp_port_data *data = NULL; - - if (client->addr != SFP_EEPROM_A0_I2C_ADDR) { - return -ENODEV; - } - - if (dev_id->driver_data < as7312_54x_port1 || dev_id->driver_data > as7312_54x_port54) { - return -ENXIO; - } - - data = kzalloc(sizeof(struct sfp_port_data), GFP_KERNEL); - if (!data) { - return -ENOMEM; - } - -#if (MULTIPAGE_SUPPORT == 1) - data->use_smbus = 0; - - /* Use I2C operations unless we're stuck with SMBus extensions. */ - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { - if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { - data->use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_WORD_DATA)) { - data->use_smbus = I2C_SMBUS_WORD_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_BYTE_DATA)) { - data->use_smbus = I2C_SMBUS_BYTE_DATA; - } else { - ret = -EPFNOSUPPORT; - goto exit_kfree; - } - } - - if (!data->use_smbus || - (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) || - i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_WORD_DATA) || - i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) { - /* - * NOTE: AN-2079 - * Finisar recommends that the host implement 1 byte writes - * only since this module only supports 32 byte page boundaries. - * 2 byte writes are acceptable for PE and Vout changes per - * Application Note AN-2071. - */ - unsigned write_max = 1; - - if (write_max > io_limit) - write_max = io_limit; - if (data->use_smbus && write_max > I2C_SMBUS_BLOCK_MAX) - write_max = I2C_SMBUS_BLOCK_MAX; - data->write_max = write_max; - - /* buffer (data + address at the beginning) */ - data->writebuf = kmalloc(write_max + 2, GFP_KERNEL); - if (!data->writebuf) { - ret = -ENOMEM; - goto exit_kfree; - } - } else { - dev_warn(&client->dev, - "cannot write due to controller restrictions."); - } - - if (data->use_smbus == I2C_SMBUS_WORD_DATA || - data->use_smbus == I2C_SMBUS_BYTE_DATA) { - dev_notice(&client->dev, "Falling back to %s reads, " - "performance will suffer\n", data->use_smbus == - I2C_SMBUS_WORD_DATA ? "word" : "byte"); - } -#endif - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - data->client = client; - - if (dev_id->driver_data >= as7312_54x_port1 && dev_id->driver_data <= as7312_54x_port48) { - data->driver_type = DRIVER_TYPE_SFP_MSA; - ret = sfp_msa_probe(client, dev_id, &data->msa); - } - else { /* as7312_54x_portsfp49 ~ as7312_54x_portsfp54 */ - data->driver_type = DRIVER_TYPE_QSFP; - ret = qsfp_probe(client, dev_id, &data->qsfp); - } - - if (ret < 0) { - goto exit_kfree_buf; - } - - - return ret; - -exit_kfree_buf: -#if (MULTIPAGE_SUPPORT == 1) - if (data->writebuf) kfree(data->writebuf); -#endif - -exit_kfree: - kfree(data); - return ret; -} -/* Platform dependent --- */ - -static int sfp_msa_remove(struct i2c_client *client, struct sfp_msa_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); -#if (MULTIPAGE_SUPPORT == 1) - i2c_unregister_device(data->ddm_client); -#endif - sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); - kfree(data); - return 0; -} - -static int qfp_remove(struct i2c_client *client, struct qsfp_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &qsfp_group); - kfree(data); - return 0; -} - -static int sfp_device_remove(struct i2c_client *client) -{ - int ret = 0; - struct sfp_port_data *data = i2c_get_clientdata(client); - - switch (data->driver_type) { - case DRIVER_TYPE_SFP_MSA: - return sfp_msa_remove(client, data->msa); - case DRIVER_TYPE_QSFP: - return qfp_remove(client, data->qsfp); - } - -#if (MULTIPAGE_SUPPORT == 1) - if (data->writebuf) - kfree(data->writebuf); -#endif - kfree(data); - return ret; -} - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -static struct i2c_driver sfp_driver = { - .driver = { - .name = DRIVER_NAME, - }, - .probe = sfp_device_probe, - .remove = sfp_device_remove, - .id_table = sfp_device_id, - .address_list = normal_i2c, -}; - -static int __init sfp_init(void) -{ - return i2c_add_driver(&sfp_driver); -} - -static void __exit sfp_exit(void) -{ - i2c_del_driver(&sfp_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as7312_54x_sfp driver"); -MODULE_LICENSE("GPL"); - -module_init(sfp_init); -module_exit(sfp_exit); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_i2c_cpld.c b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_i2c_cpld.c deleted file mode 100644 index 67ecd8e036a9..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/accton_i2c_cpld.c +++ /dev/null @@ -1,1219 +0,0 @@ -/* - * Copyright (C) Brandon Chuang - * - * This module supports the accton cpld that hold the channel select - * mechanism for other i2c slave devices, such as SFP. - * This includes the: - * Accton as7312_54x CPLD1/CPLD2/CPLD3 - * - * Based on: - * pca954x.c from Kumar Gala - * Copyright (C) 2006 - * - * Based on: - * pca954x.c from Ken Harrenstien - * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) - * - * Based on: - * i2c-virtual_cb.c from Brian Kuschak - * and - * pca9540.c from Jean Delvare . - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include - -#define I2C_RW_RETRY_COUNT 10 -#define I2C_RW_RETRY_INTERVAL 60 /* ms */ - -static LIST_HEAD(cpld_client_list); -static struct mutex list_lock; - -struct cpld_client_node { - struct i2c_client *client; - struct list_head list; -}; - -enum cpld_type { - as7312_54x_cpld1, - as7312_54x_cpld2, - as7312_54x_cpld3 -}; - -struct as7312_54x_cpld_data { - enum cpld_type type; - struct device *hwmon_dev; - struct mutex update_lock; -}; - -static const struct i2c_device_id as7312_54x_cpld_id[] = { - { "as7312_54x_cpld1", as7312_54x_cpld1 }, - { "as7312_54x_cpld2", as7312_54x_cpld2 }, - { "as7312_54x_cpld3", as7312_54x_cpld3 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, as7312_54x_cpld_id); - -#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index -#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index -#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index -#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index -#define TRANSCEIVER_RESET_ATTR_ID(index) MODULE_RESET_##index - -enum as7312_54x_cpld1_sysfs_attributes { - CPLD_VERSION, - ACCESS, - MODULE_PRESENT_ALL, - MODULE_RXLOS_ALL, - /* transceiver attributes */ - TRANSCEIVER_PRESENT_ATTR_ID(1), - TRANSCEIVER_PRESENT_ATTR_ID(2), - TRANSCEIVER_PRESENT_ATTR_ID(3), - TRANSCEIVER_PRESENT_ATTR_ID(4), - TRANSCEIVER_PRESENT_ATTR_ID(5), - TRANSCEIVER_PRESENT_ATTR_ID(6), - TRANSCEIVER_PRESENT_ATTR_ID(7), - TRANSCEIVER_PRESENT_ATTR_ID(8), - TRANSCEIVER_PRESENT_ATTR_ID(9), - TRANSCEIVER_PRESENT_ATTR_ID(10), - TRANSCEIVER_PRESENT_ATTR_ID(11), - TRANSCEIVER_PRESENT_ATTR_ID(12), - TRANSCEIVER_PRESENT_ATTR_ID(13), - TRANSCEIVER_PRESENT_ATTR_ID(14), - TRANSCEIVER_PRESENT_ATTR_ID(15), - TRANSCEIVER_PRESENT_ATTR_ID(16), - TRANSCEIVER_PRESENT_ATTR_ID(17), - TRANSCEIVER_PRESENT_ATTR_ID(18), - TRANSCEIVER_PRESENT_ATTR_ID(19), - TRANSCEIVER_PRESENT_ATTR_ID(20), - TRANSCEIVER_PRESENT_ATTR_ID(21), - TRANSCEIVER_PRESENT_ATTR_ID(22), - TRANSCEIVER_PRESENT_ATTR_ID(23), - TRANSCEIVER_PRESENT_ATTR_ID(24), - TRANSCEIVER_PRESENT_ATTR_ID(25), - TRANSCEIVER_PRESENT_ATTR_ID(26), - TRANSCEIVER_PRESENT_ATTR_ID(27), - TRANSCEIVER_PRESENT_ATTR_ID(28), - TRANSCEIVER_PRESENT_ATTR_ID(29), - TRANSCEIVER_PRESENT_ATTR_ID(30), - TRANSCEIVER_PRESENT_ATTR_ID(31), - TRANSCEIVER_PRESENT_ATTR_ID(32), - TRANSCEIVER_PRESENT_ATTR_ID(33), - TRANSCEIVER_PRESENT_ATTR_ID(34), - TRANSCEIVER_PRESENT_ATTR_ID(35), - TRANSCEIVER_PRESENT_ATTR_ID(36), - TRANSCEIVER_PRESENT_ATTR_ID(37), - TRANSCEIVER_PRESENT_ATTR_ID(38), - TRANSCEIVER_PRESENT_ATTR_ID(39), - TRANSCEIVER_PRESENT_ATTR_ID(40), - TRANSCEIVER_PRESENT_ATTR_ID(41), - TRANSCEIVER_PRESENT_ATTR_ID(42), - TRANSCEIVER_PRESENT_ATTR_ID(43), - TRANSCEIVER_PRESENT_ATTR_ID(44), - TRANSCEIVER_PRESENT_ATTR_ID(45), - TRANSCEIVER_PRESENT_ATTR_ID(46), - TRANSCEIVER_PRESENT_ATTR_ID(47), - TRANSCEIVER_PRESENT_ATTR_ID(48), - TRANSCEIVER_PRESENT_ATTR_ID(49), - TRANSCEIVER_PRESENT_ATTR_ID(50), - TRANSCEIVER_PRESENT_ATTR_ID(51), - TRANSCEIVER_PRESENT_ATTR_ID(52), - TRANSCEIVER_PRESENT_ATTR_ID(53), - TRANSCEIVER_PRESENT_ATTR_ID(54), - TRANSCEIVER_RESET_ATTR_ID(49), - TRANSCEIVER_RESET_ATTR_ID(50), - TRANSCEIVER_RESET_ATTR_ID(51), - TRANSCEIVER_RESET_ATTR_ID(52), - TRANSCEIVER_RESET_ATTR_ID(53), - TRANSCEIVER_RESET_ATTR_ID(54), - TRANSCEIVER_TXDISABLE_ATTR_ID(1), - TRANSCEIVER_TXDISABLE_ATTR_ID(2), - TRANSCEIVER_TXDISABLE_ATTR_ID(3), - TRANSCEIVER_TXDISABLE_ATTR_ID(4), - TRANSCEIVER_TXDISABLE_ATTR_ID(5), - TRANSCEIVER_TXDISABLE_ATTR_ID(6), - TRANSCEIVER_TXDISABLE_ATTR_ID(7), - TRANSCEIVER_TXDISABLE_ATTR_ID(8), - TRANSCEIVER_TXDISABLE_ATTR_ID(9), - TRANSCEIVER_TXDISABLE_ATTR_ID(10), - TRANSCEIVER_TXDISABLE_ATTR_ID(11), - TRANSCEIVER_TXDISABLE_ATTR_ID(12), - TRANSCEIVER_TXDISABLE_ATTR_ID(13), - TRANSCEIVER_TXDISABLE_ATTR_ID(14), - TRANSCEIVER_TXDISABLE_ATTR_ID(15), - TRANSCEIVER_TXDISABLE_ATTR_ID(16), - TRANSCEIVER_TXDISABLE_ATTR_ID(17), - TRANSCEIVER_TXDISABLE_ATTR_ID(18), - TRANSCEIVER_TXDISABLE_ATTR_ID(19), - TRANSCEIVER_TXDISABLE_ATTR_ID(20), - TRANSCEIVER_TXDISABLE_ATTR_ID(21), - TRANSCEIVER_TXDISABLE_ATTR_ID(22), - TRANSCEIVER_TXDISABLE_ATTR_ID(23), - TRANSCEIVER_TXDISABLE_ATTR_ID(24), - TRANSCEIVER_TXDISABLE_ATTR_ID(25), - TRANSCEIVER_TXDISABLE_ATTR_ID(26), - TRANSCEIVER_TXDISABLE_ATTR_ID(27), - TRANSCEIVER_TXDISABLE_ATTR_ID(28), - TRANSCEIVER_TXDISABLE_ATTR_ID(29), - TRANSCEIVER_TXDISABLE_ATTR_ID(30), - TRANSCEIVER_TXDISABLE_ATTR_ID(31), - TRANSCEIVER_TXDISABLE_ATTR_ID(32), - TRANSCEIVER_TXDISABLE_ATTR_ID(33), - TRANSCEIVER_TXDISABLE_ATTR_ID(34), - TRANSCEIVER_TXDISABLE_ATTR_ID(35), - TRANSCEIVER_TXDISABLE_ATTR_ID(36), - TRANSCEIVER_TXDISABLE_ATTR_ID(37), - TRANSCEIVER_TXDISABLE_ATTR_ID(38), - TRANSCEIVER_TXDISABLE_ATTR_ID(39), - TRANSCEIVER_TXDISABLE_ATTR_ID(40), - TRANSCEIVER_TXDISABLE_ATTR_ID(41), - TRANSCEIVER_TXDISABLE_ATTR_ID(42), - TRANSCEIVER_TXDISABLE_ATTR_ID(43), - TRANSCEIVER_TXDISABLE_ATTR_ID(44), - TRANSCEIVER_TXDISABLE_ATTR_ID(45), - TRANSCEIVER_TXDISABLE_ATTR_ID(46), - TRANSCEIVER_TXDISABLE_ATTR_ID(47), - TRANSCEIVER_TXDISABLE_ATTR_ID(48), - TRANSCEIVER_RXLOS_ATTR_ID(1), - TRANSCEIVER_RXLOS_ATTR_ID(2), - TRANSCEIVER_RXLOS_ATTR_ID(3), - TRANSCEIVER_RXLOS_ATTR_ID(4), - TRANSCEIVER_RXLOS_ATTR_ID(5), - TRANSCEIVER_RXLOS_ATTR_ID(6), - TRANSCEIVER_RXLOS_ATTR_ID(7), - TRANSCEIVER_RXLOS_ATTR_ID(8), - TRANSCEIVER_RXLOS_ATTR_ID(9), - TRANSCEIVER_RXLOS_ATTR_ID(10), - TRANSCEIVER_RXLOS_ATTR_ID(11), - TRANSCEIVER_RXLOS_ATTR_ID(12), - TRANSCEIVER_RXLOS_ATTR_ID(13), - TRANSCEIVER_RXLOS_ATTR_ID(14), - TRANSCEIVER_RXLOS_ATTR_ID(15), - TRANSCEIVER_RXLOS_ATTR_ID(16), - TRANSCEIVER_RXLOS_ATTR_ID(17), - TRANSCEIVER_RXLOS_ATTR_ID(18), - TRANSCEIVER_RXLOS_ATTR_ID(19), - TRANSCEIVER_RXLOS_ATTR_ID(20), - TRANSCEIVER_RXLOS_ATTR_ID(21), - TRANSCEIVER_RXLOS_ATTR_ID(22), - TRANSCEIVER_RXLOS_ATTR_ID(23), - TRANSCEIVER_RXLOS_ATTR_ID(24), - TRANSCEIVER_RXLOS_ATTR_ID(25), - TRANSCEIVER_RXLOS_ATTR_ID(26), - TRANSCEIVER_RXLOS_ATTR_ID(27), - TRANSCEIVER_RXLOS_ATTR_ID(28), - TRANSCEIVER_RXLOS_ATTR_ID(29), - TRANSCEIVER_RXLOS_ATTR_ID(30), - TRANSCEIVER_RXLOS_ATTR_ID(31), - TRANSCEIVER_RXLOS_ATTR_ID(32), - TRANSCEIVER_RXLOS_ATTR_ID(33), - TRANSCEIVER_RXLOS_ATTR_ID(34), - TRANSCEIVER_RXLOS_ATTR_ID(35), - TRANSCEIVER_RXLOS_ATTR_ID(36), - TRANSCEIVER_RXLOS_ATTR_ID(37), - TRANSCEIVER_RXLOS_ATTR_ID(38), - TRANSCEIVER_RXLOS_ATTR_ID(39), - TRANSCEIVER_RXLOS_ATTR_ID(40), - TRANSCEIVER_RXLOS_ATTR_ID(41), - TRANSCEIVER_RXLOS_ATTR_ID(42), - TRANSCEIVER_RXLOS_ATTR_ID(43), - TRANSCEIVER_RXLOS_ATTR_ID(44), - TRANSCEIVER_RXLOS_ATTR_ID(45), - TRANSCEIVER_RXLOS_ATTR_ID(46), - TRANSCEIVER_RXLOS_ATTR_ID(47), - TRANSCEIVER_RXLOS_ATTR_ID(48), - TRANSCEIVER_TXFAULT_ATTR_ID(1), - TRANSCEIVER_TXFAULT_ATTR_ID(2), - TRANSCEIVER_TXFAULT_ATTR_ID(3), - TRANSCEIVER_TXFAULT_ATTR_ID(4), - TRANSCEIVER_TXFAULT_ATTR_ID(5), - TRANSCEIVER_TXFAULT_ATTR_ID(6), - TRANSCEIVER_TXFAULT_ATTR_ID(7), - TRANSCEIVER_TXFAULT_ATTR_ID(8), - TRANSCEIVER_TXFAULT_ATTR_ID(9), - TRANSCEIVER_TXFAULT_ATTR_ID(10), - TRANSCEIVER_TXFAULT_ATTR_ID(11), - TRANSCEIVER_TXFAULT_ATTR_ID(12), - TRANSCEIVER_TXFAULT_ATTR_ID(13), - TRANSCEIVER_TXFAULT_ATTR_ID(14), - TRANSCEIVER_TXFAULT_ATTR_ID(15), - TRANSCEIVER_TXFAULT_ATTR_ID(16), - TRANSCEIVER_TXFAULT_ATTR_ID(17), - TRANSCEIVER_TXFAULT_ATTR_ID(18), - TRANSCEIVER_TXFAULT_ATTR_ID(19), - TRANSCEIVER_TXFAULT_ATTR_ID(20), - TRANSCEIVER_TXFAULT_ATTR_ID(21), - TRANSCEIVER_TXFAULT_ATTR_ID(22), - TRANSCEIVER_TXFAULT_ATTR_ID(23), - TRANSCEIVER_TXFAULT_ATTR_ID(24), - TRANSCEIVER_TXFAULT_ATTR_ID(25), - TRANSCEIVER_TXFAULT_ATTR_ID(26), - TRANSCEIVER_TXFAULT_ATTR_ID(27), - TRANSCEIVER_TXFAULT_ATTR_ID(28), - TRANSCEIVER_TXFAULT_ATTR_ID(29), - TRANSCEIVER_TXFAULT_ATTR_ID(30), - TRANSCEIVER_TXFAULT_ATTR_ID(31), - TRANSCEIVER_TXFAULT_ATTR_ID(32), - TRANSCEIVER_TXFAULT_ATTR_ID(33), - TRANSCEIVER_TXFAULT_ATTR_ID(34), - TRANSCEIVER_TXFAULT_ATTR_ID(35), - TRANSCEIVER_TXFAULT_ATTR_ID(36), - TRANSCEIVER_TXFAULT_ATTR_ID(37), - TRANSCEIVER_TXFAULT_ATTR_ID(38), - TRANSCEIVER_TXFAULT_ATTR_ID(39), - TRANSCEIVER_TXFAULT_ATTR_ID(40), - TRANSCEIVER_TXFAULT_ATTR_ID(41), - TRANSCEIVER_TXFAULT_ATTR_ID(42), - TRANSCEIVER_TXFAULT_ATTR_ID(43), - TRANSCEIVER_TXFAULT_ATTR_ID(44), - TRANSCEIVER_TXFAULT_ATTR_ID(45), - TRANSCEIVER_TXFAULT_ATTR_ID(46), - TRANSCEIVER_TXFAULT_ATTR_ID(47), - TRANSCEIVER_TXFAULT_ATTR_ID(48), -}; - -/* sysfs attributes for hwmon - */ -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_present_all(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t set_reset(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t show_version(struct device *dev, struct device_attribute *da, - char *buf); -static int as7312_54x_cpld_read_internal(struct i2c_client *client, u8 reg); -static int as7312_54x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); - -/* transceiver attributes */ -#define DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(index) \ - static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index) -#define DECLARE_TRANSCEIVER_PRESENT_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr - -#define DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(index) \ - static SENSOR_DEVICE_ATTR(module_reset_##index, S_IRUGO | S_IWUSR, show_status, set_reset, MODULE_RESET_##index) -#define DECLARE_TRANSCEIVER_RESET_ATTR(index) &sensor_dev_attr_module_reset_##index.dev_attr.attr - -#define DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ - static SENSOR_DEVICE_ATTR(module_tx_disable_##index, S_IRUGO | S_IWUSR, show_status, set_tx_disable, MODULE_TXDISABLE_##index); \ - static SENSOR_DEVICE_ATTR(module_rx_los_##index, S_IRUGO, show_status, NULL, MODULE_RXLOS_##index); \ - static SENSOR_DEVICE_ATTR(module_tx_fault_##index, S_IRUGO, show_status, NULL, MODULE_TXFAULT_##index) -#define DECLARE_SFP_TRANSCEIVER_ATTR(index) \ - &sensor_dev_attr_module_tx_disable_##index.dev_attr.attr, \ - &sensor_dev_attr_module_rx_los_##index.dev_attr.attr, \ - &sensor_dev_attr_module_tx_fault_##index.dev_attr.attr - -static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); -static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); -/* transceiver attributes */ -static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); -static SENSOR_DEVICE_ATTR(module_rx_los_all, S_IRUGO, show_rxlos_all, NULL, MODULE_RXLOS_ALL); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(1); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(2); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(3); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(4); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(5); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(6); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(7); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(8); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(9); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(10); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(11); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(12); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(13); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(14); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(15); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(16); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(17); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(18); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(19); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(20); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(21); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(22); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(23); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(24); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(25); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(26); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(27); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(28); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(29); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(30); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(31); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(32); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(33); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(34); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(35); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(36); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(37); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(38); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(39); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(40); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(41); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(42); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(43); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(44); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(45); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(46); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(47); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(48); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(49); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(50); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(51); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(52); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(53); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(54); - -DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(49); -DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(50); -DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(51); -DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(52); -DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(53); -DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(54); - -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(1); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(2); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(3); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(4); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(5); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(6); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(7); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(8); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(9); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(10); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(11); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(12); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(13); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(14); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(15); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(16); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(17); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(18); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(19); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(20); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(21); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(22); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(23); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(24); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(25); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(26); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(27); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(28); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(29); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(30); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(31); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(32); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(33); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(34); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(35); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(36); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(37); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(38); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(39); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(40); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(41); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(42); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(43); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(44); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(45); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(46); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(47); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(48); - -static struct attribute *as7312_54x_cpld1_attributes[] = { - &sensor_dev_attr_version.dev_attr.attr, - &sensor_dev_attr_access.dev_attr.attr, - NULL -}; - -static const struct attribute_group as7312_54x_cpld1_group = { - .attrs = as7312_54x_cpld1_attributes, -}; - -static struct attribute *as7312_54x_cpld2_attributes[] = { - &sensor_dev_attr_version.dev_attr.attr, - &sensor_dev_attr_access.dev_attr.attr, - /* transceiver attributes */ - &sensor_dev_attr_module_present_all.dev_attr.attr, - &sensor_dev_attr_module_rx_los_all.dev_attr.attr, - DECLARE_TRANSCEIVER_PRESENT_ATTR(1), - DECLARE_TRANSCEIVER_PRESENT_ATTR(2), - DECLARE_TRANSCEIVER_PRESENT_ATTR(3), - DECLARE_TRANSCEIVER_PRESENT_ATTR(4), - DECLARE_TRANSCEIVER_PRESENT_ATTR(5), - DECLARE_TRANSCEIVER_PRESENT_ATTR(6), - DECLARE_TRANSCEIVER_PRESENT_ATTR(7), - DECLARE_TRANSCEIVER_PRESENT_ATTR(8), - DECLARE_TRANSCEIVER_PRESENT_ATTR(9), - DECLARE_TRANSCEIVER_PRESENT_ATTR(10), - DECLARE_TRANSCEIVER_PRESENT_ATTR(11), - DECLARE_TRANSCEIVER_PRESENT_ATTR(12), - DECLARE_TRANSCEIVER_PRESENT_ATTR(13), - DECLARE_TRANSCEIVER_PRESENT_ATTR(14), - DECLARE_TRANSCEIVER_PRESENT_ATTR(15), - DECLARE_TRANSCEIVER_PRESENT_ATTR(16), - DECLARE_TRANSCEIVER_PRESENT_ATTR(17), - DECLARE_TRANSCEIVER_PRESENT_ATTR(18), - DECLARE_TRANSCEIVER_PRESENT_ATTR(19), - DECLARE_TRANSCEIVER_PRESENT_ATTR(20), - DECLARE_TRANSCEIVER_PRESENT_ATTR(21), - DECLARE_TRANSCEIVER_PRESENT_ATTR(22), - DECLARE_TRANSCEIVER_PRESENT_ATTR(23), - DECLARE_TRANSCEIVER_PRESENT_ATTR(24), - DECLARE_TRANSCEIVER_PRESENT_ATTR(49), - DECLARE_TRANSCEIVER_PRESENT_ATTR(50), - DECLARE_TRANSCEIVER_PRESENT_ATTR(51), - DECLARE_TRANSCEIVER_PRESENT_ATTR(52), - DECLARE_TRANSCEIVER_RESET_ATTR(49), - DECLARE_TRANSCEIVER_RESET_ATTR(50), - DECLARE_TRANSCEIVER_RESET_ATTR(51), - DECLARE_TRANSCEIVER_RESET_ATTR(52), - DECLARE_SFP_TRANSCEIVER_ATTR(1), - DECLARE_SFP_TRANSCEIVER_ATTR(2), - DECLARE_SFP_TRANSCEIVER_ATTR(3), - DECLARE_SFP_TRANSCEIVER_ATTR(4), - DECLARE_SFP_TRANSCEIVER_ATTR(5), - DECLARE_SFP_TRANSCEIVER_ATTR(6), - DECLARE_SFP_TRANSCEIVER_ATTR(7), - DECLARE_SFP_TRANSCEIVER_ATTR(8), - DECLARE_SFP_TRANSCEIVER_ATTR(9), - DECLARE_SFP_TRANSCEIVER_ATTR(10), - DECLARE_SFP_TRANSCEIVER_ATTR(11), - DECLARE_SFP_TRANSCEIVER_ATTR(12), - DECLARE_SFP_TRANSCEIVER_ATTR(13), - DECLARE_SFP_TRANSCEIVER_ATTR(14), - DECLARE_SFP_TRANSCEIVER_ATTR(15), - DECLARE_SFP_TRANSCEIVER_ATTR(16), - DECLARE_SFP_TRANSCEIVER_ATTR(17), - DECLARE_SFP_TRANSCEIVER_ATTR(18), - DECLARE_SFP_TRANSCEIVER_ATTR(19), - DECLARE_SFP_TRANSCEIVER_ATTR(20), - DECLARE_SFP_TRANSCEIVER_ATTR(21), - DECLARE_SFP_TRANSCEIVER_ATTR(22), - DECLARE_SFP_TRANSCEIVER_ATTR(23), - DECLARE_SFP_TRANSCEIVER_ATTR(24), - NULL -}; - -static const struct attribute_group as7312_54x_cpld2_group = { - .attrs = as7312_54x_cpld2_attributes, -}; - -static struct attribute *as7312_54x_cpld3_attributes[] = { - &sensor_dev_attr_version.dev_attr.attr, - &sensor_dev_attr_access.dev_attr.attr, - /* transceiver attributes */ - &sensor_dev_attr_module_present_all.dev_attr.attr, - &sensor_dev_attr_module_rx_los_all.dev_attr.attr, - DECLARE_TRANSCEIVER_PRESENT_ATTR(25), - DECLARE_TRANSCEIVER_PRESENT_ATTR(26), - DECLARE_TRANSCEIVER_PRESENT_ATTR(27), - DECLARE_TRANSCEIVER_PRESENT_ATTR(28), - DECLARE_TRANSCEIVER_PRESENT_ATTR(29), - DECLARE_TRANSCEIVER_PRESENT_ATTR(30), - DECLARE_TRANSCEIVER_PRESENT_ATTR(31), - DECLARE_TRANSCEIVER_PRESENT_ATTR(32), - DECLARE_TRANSCEIVER_PRESENT_ATTR(33), - DECLARE_TRANSCEIVER_PRESENT_ATTR(34), - DECLARE_TRANSCEIVER_PRESENT_ATTR(35), - DECLARE_TRANSCEIVER_PRESENT_ATTR(36), - DECLARE_TRANSCEIVER_PRESENT_ATTR(37), - DECLARE_TRANSCEIVER_PRESENT_ATTR(38), - DECLARE_TRANSCEIVER_PRESENT_ATTR(39), - DECLARE_TRANSCEIVER_PRESENT_ATTR(40), - DECLARE_TRANSCEIVER_PRESENT_ATTR(41), - DECLARE_TRANSCEIVER_PRESENT_ATTR(42), - DECLARE_TRANSCEIVER_PRESENT_ATTR(43), - DECLARE_TRANSCEIVER_PRESENT_ATTR(44), - DECLARE_TRANSCEIVER_PRESENT_ATTR(45), - DECLARE_TRANSCEIVER_PRESENT_ATTR(46), - DECLARE_TRANSCEIVER_PRESENT_ATTR(47), - DECLARE_TRANSCEIVER_PRESENT_ATTR(48), - DECLARE_TRANSCEIVER_PRESENT_ATTR(53), - DECLARE_TRANSCEIVER_PRESENT_ATTR(54), - DECLARE_TRANSCEIVER_RESET_ATTR(53), - DECLARE_TRANSCEIVER_RESET_ATTR(54), - DECLARE_SFP_TRANSCEIVER_ATTR(25), - DECLARE_SFP_TRANSCEIVER_ATTR(26), - DECLARE_SFP_TRANSCEIVER_ATTR(27), - DECLARE_SFP_TRANSCEIVER_ATTR(28), - DECLARE_SFP_TRANSCEIVER_ATTR(29), - DECLARE_SFP_TRANSCEIVER_ATTR(30), - DECLARE_SFP_TRANSCEIVER_ATTR(31), - DECLARE_SFP_TRANSCEIVER_ATTR(32), - DECLARE_SFP_TRANSCEIVER_ATTR(33), - DECLARE_SFP_TRANSCEIVER_ATTR(34), - DECLARE_SFP_TRANSCEIVER_ATTR(35), - DECLARE_SFP_TRANSCEIVER_ATTR(36), - DECLARE_SFP_TRANSCEIVER_ATTR(37), - DECLARE_SFP_TRANSCEIVER_ATTR(38), - DECLARE_SFP_TRANSCEIVER_ATTR(39), - DECLARE_SFP_TRANSCEIVER_ATTR(40), - DECLARE_SFP_TRANSCEIVER_ATTR(41), - DECLARE_SFP_TRANSCEIVER_ATTR(42), - DECLARE_SFP_TRANSCEIVER_ATTR(43), - DECLARE_SFP_TRANSCEIVER_ATTR(44), - DECLARE_SFP_TRANSCEIVER_ATTR(45), - DECLARE_SFP_TRANSCEIVER_ATTR(46), - DECLARE_SFP_TRANSCEIVER_ATTR(47), - DECLARE_SFP_TRANSCEIVER_ATTR(48), - NULL -}; - -static const struct attribute_group as7312_54x_cpld3_group = { - .attrs = as7312_54x_cpld3_attributes, -}; - -static ssize_t show_present_all(struct device *dev, struct device_attribute *da, - char *buf) -{ - int i, status; - u8 values[4] = {0}; - u8 regs[] = {0x9, 0xA, 0xB, 0x18}; - struct i2c_client *client = to_i2c_client(dev); - struct as7312_54x_cpld_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - for (i = 0; i < ARRAY_SIZE(regs); i++) { - status = as7312_54x_cpld_read_internal(client, regs[i]); - - if (status < 0) { - goto exit; - } - - values[i] = ~(u8)status; - } - - mutex_unlock(&data->update_lock); - - /* Return values 1 -> 54 in order */ - if (data->type == as7312_54x_cpld2) { - values[3] &= 0xF; - } - else { /* as7312_54x_cpld3 */ - values[3] &= 0x3; - } - - return sprintf(buf, "%.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], values[3]); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, - char *buf) -{ - int i, status; - u8 values[3] = {0}; - u8 regs[] = {0x12, 0x13, 0x14}; - struct i2c_client *client = to_i2c_client(dev); - struct as7312_54x_cpld_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - for (i = 0; i < ARRAY_SIZE(regs); i++) { - status = as7312_54x_cpld_read_internal(client, regs[i]); - - if (status < 0) { - goto exit; - } - - values[i] = (u8)status; - } - - mutex_unlock(&data->update_lock); - - /* Return values 1 -> 24 in order */ - return sprintf(buf, "%.2x %.2x %.2x\n", values[0], values[1], values[2]); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct as7312_54x_cpld_data *data = i2c_get_clientdata(client); - int status = 0; - u8 reg = 0, mask = 0, revert = 0; - - switch (attr->index) { - case MODULE_PRESENT_1 ... MODULE_PRESENT_8: - reg = 0x9; - mask = 0x1 << (attr->index - MODULE_PRESENT_1); - break; - case MODULE_PRESENT_9 ... MODULE_PRESENT_16: - reg = 0xA; - mask = 0x1 << (attr->index - MODULE_PRESENT_9); - break; - case MODULE_PRESENT_17 ... MODULE_PRESENT_24: - reg = 0xB; - mask = 0x1 << (attr->index - MODULE_PRESENT_17); - break; - case MODULE_PRESENT_25 ... MODULE_PRESENT_32: - reg = 0x9; - mask = 0x1 << (attr->index - MODULE_PRESENT_25); - break; - case MODULE_PRESENT_33 ... MODULE_PRESENT_40: - reg = 0xA; - mask = 0x1 << (attr->index - MODULE_PRESENT_33); - break; - case MODULE_PRESENT_41 ... MODULE_PRESENT_48: - reg = 0xB; - mask = 0x1 << (attr->index - MODULE_PRESENT_41); - break; - case MODULE_PRESENT_49: - reg = 0x18; - mask = 0x1; - break; - case MODULE_PRESENT_50: - reg = 0x18; - mask = 0x2; - break; - case MODULE_PRESENT_51: - reg = 0x18; - mask = 0x4; - break; - case MODULE_PRESENT_52: - reg = 0x18; - mask = 0x8; - break; - case MODULE_PRESENT_53: - reg = 0x18; - mask = 0x1; - break; - case MODULE_PRESENT_54: - reg = 0x18; - mask = 0x2; - break; - - case MODULE_RESET_49 ... MODULE_RESET_54: - reg = 0x17; - mask = 1 << ((attr->index - MODULE_PRESENT_49)%4); - break; - - case MODULE_TXFAULT_1 ... MODULE_TXFAULT_8: - reg = 0xC; - mask = 0x1 << (attr->index - MODULE_TXFAULT_1); - break; - case MODULE_TXFAULT_9 ... MODULE_TXFAULT_16: - reg = 0xD; - mask = 0x1 << (attr->index - MODULE_TXFAULT_9); - break; - case MODULE_TXFAULT_17 ... MODULE_TXFAULT_24: - reg = 0xE; - mask = 0x1 << (attr->index - MODULE_TXFAULT_17); - break; - case MODULE_TXFAULT_25 ... MODULE_TXFAULT_32: - reg = 0xC; - mask = 0x1 << (attr->index - MODULE_TXFAULT_25); - break; - case MODULE_TXFAULT_33 ... MODULE_TXFAULT_40: - reg = 0xD; - mask = 0x1 << (attr->index - MODULE_TXFAULT_33); - break; - case MODULE_TXFAULT_41 ... MODULE_TXFAULT_48: - reg = 0xE; - mask = 0x1 << (attr->index - MODULE_TXFAULT_41); - break; - case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: - reg = 0xF; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); - break; - case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: - reg = 0x10; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); - break; - case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: - reg = 0x11; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); - break; - case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_32: - reg = 0xF; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); - break; - case MODULE_TXDISABLE_33 ... MODULE_TXDISABLE_40: - reg = 0x10; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_33); - break; - case MODULE_TXDISABLE_41 ... MODULE_TXDISABLE_48: - reg = 0x11; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_41); - break; - case MODULE_RXLOS_1 ... MODULE_RXLOS_8: - reg = 0x12; - mask = 0x1 << (attr->index - MODULE_RXLOS_1); - break; - case MODULE_RXLOS_9 ... MODULE_RXLOS_16: - reg = 0x13; - mask = 0x1 << (attr->index - MODULE_RXLOS_9); - break; - case MODULE_RXLOS_17 ... MODULE_RXLOS_24: - reg = 0x14; - mask = 0x1 << (attr->index - MODULE_RXLOS_17); - break; - case MODULE_RXLOS_25 ... MODULE_RXLOS_32: - reg = 0x12; - mask = 0x1 << (attr->index - MODULE_RXLOS_25); - break; - case MODULE_RXLOS_33 ... MODULE_RXLOS_40: - reg = 0x13; - mask = 0x1 << (attr->index - MODULE_RXLOS_33); - break; - case MODULE_RXLOS_41 ... MODULE_RXLOS_48: - reg = 0x14; - mask = 0x1 << (attr->index - MODULE_RXLOS_41); - break; - default: - return 0; - } - - if (attr->index >= MODULE_PRESENT_1 && attr->index <= MODULE_PRESENT_54) { - revert = 1; - } - - mutex_lock(&data->update_lock); - status = as7312_54x_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - - return sprintf(buf, "%d\n", revert ? !(status & mask) : !!(status & mask)); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t set_reset(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 as7312_54x_cpld_data *data = i2c_get_clientdata(client); - long reset; - int status; - u8 reg = 0, mask = 0; - - status = kstrtol(buf, 10, &reset); - if (status) { - return status; - } - - switch (attr->index) { - case MODULE_RESET_49 ... MODULE_RESET_54: - reg = 0x17; - mask = 1 << ((attr->index - MODULE_RESET_49)%4); - break; - default: - return 0; - } - - /* Read current status */ - mutex_lock(&data->update_lock); - status = as7312_54x_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - - /* Update reset status */ - if (reset) { - status |= mask; - } - else { - status &= ~mask; - } - status = as7312_54x_cpld_write_internal(client, reg, status); - if (unlikely(status < 0)) { - goto exit; - } - - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - - - - -static ssize_t set_tx_disable(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 as7312_54x_cpld_data *data = i2c_get_clientdata(client); - long disable; - int status; - u8 reg = 0, mask = 0; - - status = kstrtol(buf, 10, &disable); - if (status) { - return status; - } - - switch (attr->index) { - case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: - reg = 0xF; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); - break; - case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: - reg = 0x10; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); - break; - case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: - reg = 0x11; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); - break; - case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_32: - reg = 0xF; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); - break; - case MODULE_TXDISABLE_33 ... MODULE_TXDISABLE_40: - reg = 0x10; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_33); - break; - case MODULE_TXDISABLE_41 ... MODULE_TXDISABLE_48: - reg = 0x11; - mask = 0x1 << (attr->index - MODULE_TXDISABLE_41); - break; - default: - return 0; - } - - /* Read current status */ - mutex_lock(&data->update_lock); - status = as7312_54x_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - - /* Update tx_disable status */ - if (disable) { - status |= mask; - } - else { - status &= ~mask; - } - - status = as7312_54x_cpld_write_internal(client, reg, status); - if (unlikely(status < 0)) { - goto exit; - } - - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - int status; - u32 addr, val; - struct i2c_client *client = to_i2c_client(dev); - struct as7312_54x_cpld_data *data = i2c_get_clientdata(client); - - if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { - return -EINVAL; - } - - if (addr > 0xFF || val > 0xFF) { - return -EINVAL; - } - - mutex_lock(&data->update_lock); - status = as7312_54x_cpld_write_internal(client, addr, val); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static void as7312_54x_cpld_add_client(struct i2c_client *client) -{ - struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); - - if (!node) { - dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); - return; - } - - node->client = client; - - mutex_lock(&list_lock); - list_add(&node->list, &cpld_client_list); - mutex_unlock(&list_lock); -} - -static void as7312_54x_cpld_remove_client(struct i2c_client *client) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int found = 0; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client == client) { - found = 1; - break; - } - } - - if (found) { - list_del(list_node); - kfree(cpld_node); - } - - mutex_unlock(&list_lock); -} - -static ssize_t show_version(struct device *dev, struct device_attribute *attr, char *buf) -{ - int val = 0; - struct i2c_client *client = to_i2c_client(dev); - - val = i2c_smbus_read_byte_data(client, 0x1); - - if (val < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val); - } - - return sprintf(buf, "%d", val); -} - -/* - * I2C init/probing/exit functions - */ -static int as7312_54x_cpld_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); - struct as7312_54x_cpld_data *data; - int ret = -ENODEV; - const struct attribute_group *group = NULL; - - if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) - goto exit; - - data = kzalloc(sizeof(struct as7312_54x_cpld_data), GFP_KERNEL); - if (!data) { - ret = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->type = id->driver_data; - - /* Register sysfs hooks */ - switch (data->type) { - case as7312_54x_cpld1: - group = &as7312_54x_cpld1_group; - break; - case as7312_54x_cpld2: - group = &as7312_54x_cpld2_group; - break; - case as7312_54x_cpld3: - group = &as7312_54x_cpld3_group; - break; - default: - break; - } - - if (group) { - ret = sysfs_create_group(&client->dev.kobj, group); - if (ret) { - goto exit_free; - } - } - - as7312_54x_cpld_add_client(client); - return 0; - -exit_free: - kfree(data); -exit: - return ret; -} - -static int as7312_54x_cpld_remove(struct i2c_client *client) -{ - struct as7312_54x_cpld_data *data = i2c_get_clientdata(client); - const struct attribute_group *group = NULL; - - as7312_54x_cpld_remove_client(client); - - /* Remove sysfs hooks */ - switch (data->type) { - case as7312_54x_cpld1: - group = &as7312_54x_cpld1_group; - break; - case as7312_54x_cpld2: - group = &as7312_54x_cpld2_group; - break; - case as7312_54x_cpld3: - group = &as7312_54x_cpld3_group; - break; - default: - break; - } - - if (group) { - sysfs_remove_group(&client->dev.kobj, group); - } - - kfree(data); - - return 0; -} - -static int as7312_54x_cpld_read_internal(struct i2c_client *client, u8 reg) -{ - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, reg); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - return status; -} - -static int as7312_54x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value) -{ - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, reg, value); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - return status; -} - -int as7312_54x_cpld_read(unsigned short cpld_addr, u8 reg) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EPERM; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = as7312_54x_cpld_read_internal(cpld_node->client, reg); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(as7312_54x_cpld_read); - -int as7312_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EIO; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = as7312_54x_cpld_write_internal(cpld_node->client, reg, value); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(as7312_54x_cpld_write); - -static struct i2c_driver as7312_54x_cpld_driver = { - .driver = { - .name = "as7312_54x_cpld", - .owner = THIS_MODULE, - }, - .probe = as7312_54x_cpld_probe, - .remove = as7312_54x_cpld_remove, - .id_table = as7312_54x_cpld_id, -}; - -static int __init as7312_54x_cpld_init(void) -{ - mutex_init(&list_lock); - return i2c_add_driver(&as7312_54x_cpld_driver); -} - -static void __exit as7312_54x_cpld_exit(void) -{ - i2c_del_driver(&as7312_54x_cpld_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("Accton I2C CPLD driver"); -MODULE_LICENSE("GPL"); - -module_init(as7312_54x_cpld_init); -module_exit(as7312_54x_cpld_exit); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/ym2651y.c b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/ym2651y.c deleted file mode 120000 index f4d67640ccc3..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/modules/ym2651y.c +++ /dev/null @@ -1 +0,0 @@ -../../common/modules/ym2651y.c \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/service/as7312-platform-monitor.service b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/service/as7312-platform-monitor.service deleted file mode 100755 index b79357665bed..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/service/as7312-platform-monitor.service +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=Accton AS7312-54X Platform Monitoring service -Before=pmon.service -After=sysinit.target -DefaultDependencies=no - -[Service] -ExecStartPre=/usr/local/bin/accton_as7312_util.py install -ExecStart=/usr/local/bin/accton_as7312_monitor.py -KillSignal=SIGKILL -SuccessExitStatus=SIGKILL - -# Resource Limitations -LimitCORE=infinity - -[Install] -WantedBy=multi-user.target diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/setup.py b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/setup.py deleted file mode 100755 index f0518d07689d..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/setup.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env pytho - -import os -import sys -from setuptools import setup -os.listdir - -setup( - name='as7312_54x', - version='1.0', - description='Module to initialize Accton AS7312-54X platforms', - - packages=['as7312_54x'], - package_dir={'as7312_54x': 'as7312-54x/classes'}, -) - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/utils/README b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/utils/README deleted file mode 100755 index 66f31a030423..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/utils/README +++ /dev/null @@ -1,117 +0,0 @@ -Copyright (C) 2016 Accton Networks, Inc. - -This program is free software: you can redistribute it and/or modify -It under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Contents of this package: - patch - files under patch/ is for kernel and ONIE installer - for the kernel: - config-accton-as7312_54x.patch - for kernel configuration. - driver-i2c-muxes-pca954x-always-deselect.patch - for i2c_mux deselects after transaction. - driver-patches-for-accton-as7312-fan-psu-cpld.patch - for as7312's fan/psu/cpld/led/sfp drivers. - for ONIE: - onie_installer-accton-AS7312-54X.patch - for console port setting and copy util script o rootfs. - module - Contains source code of as7312 kernel driver modules. - -The late Sonic building scripts, pushed @Dec 5 2016, will automatically -create a docker container and run building process under it. -User is not necessary to handle docker environment creation. - -1. Download sonic-buildimage environment. - - Run "git clone https://github.com/Azure/sonic-buildimage". - - cd to sonic-buildimage and run "git submodule update --init --recursive". -2. Build kernel - - cd ./src/sonic-linux-kernel - - Copy patches and series from patch/kernel of this release to - sonic-linux-kernel/patch. - - Build kernel by "make". - - The built kernel package, linux-image-3.16.0-5-amd64_3.16.51-3+deb8u1_amd64.deb - , is generated. -3. Build installer - - Change directory back to sonic-buildimage/. - - Get onie_installer-accton-AS7312-54X.patch" from patch/installer. - - Change setting for AS7312-54X by patching build_image.sh. - "patch -p1 < onie_installer-accton-AS7312-54X.patch" - !!NOTICE, patching onie_installer-accton-AS7312-54X.patch comments out the - "git status" checking at build_image.sh. - - The account and password of installed OS can be given at rules/config. - The default user and password are "admin" & "YourPaSsWoRd" respectively. - - Run "make configure PLATFORM=broadcom" - - Copy the built kernel debian package to target/debs/. - The file is linux-image-3.16.0-5-amd64_*_amd64.deb under directory - src/sonic-linux-kernel/. - - Run "make target/sonic-generic.bin" - - Get the installer, target/sonic-generic.bin, to target machine and install. - -All Linux kernel code is licensed under the GPLv1. All other code is -licensed under the GPLv3. Please see the LICENSE file for copies of -both licenses. - -The code for integacting with Accton AS7312-54X has 2 parts, -kernel drivers and operational script. -The kernel drivers of peripherals are under module/ directory. -1. These drivers are patched into kernel by - driver-patches-for-accton-as7312-fan-psu-cpld.patch - Or you can build the driver under module/ by setting environment variable, - KERNEL_SRC, to proper linux built directory and run make. - It may be sonic-linux-kernel/linux-3.*/debian/build/build_amd64_none_amd64/. -2. A operational script, accton_as7312_util.py, for device initializatian and - peripheral accessing should be installed at /usr/bin. - This script is generated by onie_installer-accton-AS7312-54X.patch. - It's done by patching onie_installer-accton-AS7312-54X.patch at build-image. - Run "accton_as7312_util.py install" to install drivers. - -To initialize the system, run "accton_as7312_util.py install". -To clean up the drivers & devices, run "accton_as7312_util.py clean". -To dump information of sensors, run "accton_as7312_util.py show". -To dump SFP EEPROM, run "accton_as7312_util.py sff". -To set fan speed, run "accton_as7312_util.py set fan". -To enable/disable SFP emission, run "accton_as7312_util.py set sfp". -To set system LEDs' color, run "accton_as7312_util.py set led" -For more information, run "accton_as7312_util.py --help". - -==================================================================== -Besides applying accton_as7312_util.py to access peripherals, you can -access peripherals by sysfs nodes directly after the installation is run. - -System LED: - There are 5 system LEDs at the lower-left corner of front panel. - They are loc, diag, fan, ps1, and ps2. - The sysfs interface color mappings are as follows: - Brightness: - 0 => off - 1 => green - 2 => amber - 3 => red - 4 => blue - But not all colors are available for each LED. - -Fan Control: - There are 10 fans inside 5 fan modules. - All fans share 1 duty setting, ranged from 0~100. - -Thermal sensers: - 3 temperature sensors are controlled by the lm75 kernel modules. - -PSUs: - There 2 power supplies slot at the left/right side of the back. - Once if a PSU is not plugged, the status of it is shown failed. - -There are 48 SFP+ and 6 QSFP modules are equipped. -Before operating on PSU and QSFP+, please make sure it is well plugged. -Otherwise, operation is going to fail. - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/utils/accton_as7312_monitor.py b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/utils/accton_as7312_monitor.py deleted file mode 100755 index bdab0d4b8bff..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/utils/accton_as7312_monitor.py +++ /dev/null @@ -1,208 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# 1/10/2018: Jostar modify for as7716_32 -# 2/27/2018: Roy Lee modify for as7312_54x -# ------------------------------------------------------------------ - -try: - import os - import sys, getopt - import subprocess - import click - import imp - import logging - import logging.config - import types - import time # this is only being used as part of the example - import traceback - from tabulate import tabulate - from as7312_54x.fanutil import FanUtil - from as7312_54x.thermalutil import ThermalUtil -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - -# Deafults -VERSION = '1.0' -FUNCTION_NAME = 'accton_as7312_monitor' - -global log_file -global log_level - -# (LM75_1+ LM75_2+ LM75_3) is LM75 at i2c addresses 0x48, 0x49, and 0x4A. -# TMP = (LM75_1+ LM75_2+ LM75_3)/3 -#1. If TMP < 35, All fans run with duty 31.25%. -#2. If TMP>=35 or the temperature of any one of fan is higher than 40, -# All fans run with duty 50% -#3. If TMP >= 40 or the temperature of any one of fan is higher than 45, -# All fans run with duty 62.5%. -#4. If TMP >= 45 or the temperature of any one of fan is higher than 50, -# All fans run with duty 100%. -#5. Any one of 6 fans is fault, set duty = 100%. -#6. Direction factor. If it is B2F direction, duty + 12%. - - # MISC: - # 1.Check single LM75 before applied average. - # 2.If no matched fan speed is found from the policy, - # use FAN_DUTY_CYCLE_MIN as default speed - # Get current temperature - # 4.Decision 3: Decide new fan speed depend on fan direction/current fan speed/temperature - - - - -# Make a class we can use to capture stdout and sterr in the log -class accton_as7312_monitor(object): - # static temp var - _ori_temp = 0 - _new_perc = 0 - _ori_perc = 0 - - def __init__(self, log_file, log_level): - """Needs a logger and a logger level.""" - # set up logging to file - logging.basicConfig( - filename=log_file, - filemode='w', - level=log_level, - format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', - datefmt='%H:%M:%S' - ) - - # set up logging to console - if log_level == logging.DEBUG: - console = logging.StreamHandler() - console.setLevel(log_level) - formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') - console.setFormatter(formatter) - logging.getLogger('').addHandler(console) - - logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level) - - def manage_fans(self): - max_duty = 100 - fan_policy_f2b = { - 0: [32, 0, 105000], - 1: [50, 105000, 120000], - 2: [63, 120000, 135000], - 3: [max_duty, 135000, sys.maxsize], - } - fan_policy_b2f = { - 0: [44, 0, 105000], - 1: [63, 105000, 120000], - 2: [75, 120000, 135000], - 3: [max_duty, 135000, sys.maxsize], - } - fan_policy_single = { - 0: 40000, - 1: 45000, - 2: 50000, - } - - thermal = ThermalUtil() - fan = FanUtil() - for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1): - fan_status = fan.get_fan_status(x) - if fan_status is None: - logging.debug('INFO. SET new_perc to %d (FAN stauts is None. fan_num:%d)', max_duty, x) - return False - if fan_status is False: - logging.debug('INFO. SET new_perc to %d (FAN fault. fan_num:%d)', max_duty, x) - fan.set_fan_duty_cycle(max_duty) - return True - #logging.debug('INFO. fan_status is True (fan_num:%d)', x) - - fan_dir=fan.get_fan_dir(1) - if fan_dir == 1: - fan_policy = fan_policy_f2b - else: - fan_policy = fan_policy_b2f - - #Decide fan duty by if any of sensors > fan_policy_single. - new_duty_cycle = fan_policy[0][0] - for x in range(thermal.get_idx_thermal_start(), thermal.get_num_thermals()+1): - single_thm = thermal._get_thermal_node_val(x) - for y in range(0, len(fan_policy_single)): - if single_thm > fan_policy_single[y]: - if fan_policy[y+1][0] > new_duty_cycle: - new_duty_cycle = fan_policy[y+1][0] - logging.debug('INFO. Single thermal sensor %d with temp %d > %d , new_duty_cycle=%d', - x, single_thm, fan_policy_single[y], new_duty_cycle) - single_result = new_duty_cycle - - - #Find if current duty matched any of define duty. - #If not, set it to highest one. - cur_duty_cycle = fan.get_fan_duty_cycle() - for x in range(0, len(fan_policy)): - if cur_duty_cycle == fan_policy[x][0]: - break - if x == len(fan_policy) : - fan.set_fan_duty_cycle(fan_policy[0][0]) - cur_duty_cycle = max_duty - - #Decide fan duty by if sum of sensors falls into any of fan_policy{} - get_temp = thermal.get_thermal_temp() - new_duty_cycle = cur_duty_cycle - for x in range(0, len(fan_policy)): - y = len(fan_policy) - x -1 #checked from highest - if get_temp > fan_policy[y][1] and get_temp < fan_policy[y][2] : - new_duty_cycle= fan_policy[y][0] - logging.debug('INFO. Sum of temp %d > %d , new_duty_cycle=%d', get_temp, fan_policy[y][1], new_duty_cycle) - - sum_result = new_duty_cycle - if (sum_result>single_result): - new_duty_cycle = sum_result; - else: - new_duty_cycle = single_result - - logging.debug('INFO. Final duty_cycle=%d', new_duty_cycle) - if(new_duty_cycle != cur_duty_cycle): - fan.set_fan_duty_cycle(new_duty_cycle) - return True - -def main(argv): - log_file = '%s.log' % FUNCTION_NAME - log_level = logging.INFO - if len(sys.argv) != 1: - try: - opts, args = getopt.getopt(argv,'hdl:',['lfile=']) - except getopt.GetoptError: - print 'Usage: %s [-d] [-l ]' % sys.argv[0] - return 0 - for opt, arg in opts: - if opt == '-h': - print 'Usage: %s [-d] [-l ]' % sys.argv[0] - return 0 - elif opt in ('-d', '--debug'): - log_level = logging.DEBUG - elif opt in ('-l', '--lfile'): - log_file = arg - - monitor = accton_as7312_monitor(log_file, log_level) - - # Loop forever, doing something useful hopefully: - while True: - monitor.manage_fans() - time.sleep(10) - -if __name__ == '__main__': - main(sys.argv[1:]) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/utils/accton_as7312_util.py b/platform/broadcom/sonic-platform-modules-accton/as7312-54x/utils/accton_as7312_util.py deleted file mode 100755 index b8107c47afea..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7312-54x/utils/accton_as7312_util.py +++ /dev/null @@ -1,588 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2016 Accton Networks, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" -Usage: %(scriptName)s [options] command object - -options: - -h | --help : this help message - -d | --debug : run with debug mode - -f | --force : ignore error during installation or clean -command: - install : install drivers and generate related sysfs nodes - clean : uninstall drivers and remove related sysfs nodes - show : show all systen status - sff : dump SFP eeprom - set : change board setting with fan|led|sfp -""" - -import os -import commands -import sys, getopt -import logging -import re -import time -from collections import namedtuple - - - - -PROJECT_NAME = 'as7312_54x' -version = '0.1.0' -verbose = False -DEBUG = False -args = [] -ALL_DEVICE = {} -DEVICE_NO = {'led':5, 'fan':6,'thermal':4, 'psu':2, 'sfp':54} -FORCE = 0 -#logging.basicConfig(filename= PROJECT_NAME+'.log', filemode='w',level=logging.DEBUG) -#logging.basicConfig(level=logging.INFO) - - -if DEBUG == True: - print sys.argv[0] - print 'ARGV :', sys.argv[1:] - - -def main(): - global DEBUG - global args - global FORCE - - if len(sys.argv)<2: - show_help() - - options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help', - 'debug', - 'force', - ]) - if DEBUG == True: - print options - print args - print len(sys.argv) - - for opt, arg in options: - if opt in ('-h', '--help'): - show_help() - elif opt in ('-d', '--debug'): - DEBUG = True - logging.basicConfig(level=logging.INFO) - elif opt in ('-f', '--force'): - FORCE = 1 - else: - logging.info('no option') - for arg in args: - if arg == 'install': - do_install() - elif arg == 'clean': - do_uninstall() - elif arg == 'show': - device_traversal() - elif arg == 'sff': - if len(args)!=2: - show_eeprom_help() - elif int(args[1]) ==0 or int(args[1]) > DEVICE_NO['sfp']: - show_eeprom_help() - else: - show_eeprom(args[1]) - return - elif arg == 'set': - if len(args)<3: - show_set_help() - else: - set_device(args[1:]) - return - else: - show_help() - - - return 0 - -def show_help(): - print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]} - sys.exit(0) - -def show_set_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print cmd +" [led|sfp|fan]" - print " use \""+ cmd + " led 0-4 \" to set led color" - print " use \""+ cmd + " fan 0-100\" to set fan duty percetage" - print " use \""+ cmd + " sfp 1-54 {0|1}\" to set sfp# tx_disable" - sys.exit(0) - -def show_eeprom_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print " use \""+ cmd + " 1-54 \" to dump sfp# eeprom" - sys.exit(0) - -def my_log(txt): - if DEBUG == True: - print "[ROY]"+txt - return - -def log_os_system(cmd, show): - logging.info('Run :'+cmd) - status, output = commands.getstatusoutput(cmd) - my_log (cmd +"with result:" + str(status)) - my_log (" output:"+output) - if status: - logging.info('Failed :'+cmd) - if show: - print('Failed :'+cmd) - return status, output - -def driver_check(): - ret, lsmod = log_os_system("lsmod| grep accton", 0) - logging.info('mods:'+lsmod) - if len(lsmod) ==0: - return False - return True - - - -kos = [ -'modprobe i2c_dev', -'modprobe i2c_mux_pca954x force_deselect_on_exit=1', -'modprobe accton_i2c_cpld' , -'modprobe ym2651y' , -'modprobe accton_as7312_54x_fan' , -'modprobe optoe' , -'modprobe accton_as7312_54x_leds' , -'modprobe accton_as7312_54x_psu' ] - -def driver_install(): - global FORCE - status, output = log_os_system("depmod", 1) - for i in range(0,len(kos)): - status, output = log_os_system(kos[i], 1) - if status: - if FORCE == 0: - return status - return 0 - -def driver_uninstall(): - global FORCE - for i in range(0,len(kos)): - rm = kos[-(i+1)].replace("modprobe", "modprobe -rq") - rm = rm.replace("insmod", "rmmod") - lst = rm.split(" ") - if len(lst) > 3: - del(lst[3]) - rm = " ".join(lst) - status, output = log_os_system(rm, 1) - if status: - if FORCE == 0: - return status - return 0 - -led_prefix ='/sys/class/leds/accton_'+PROJECT_NAME+'_led::' -hwmon_types = {'led': ['diag','fan','loc','psu1','psu2']} -hwmon_nodes = {'led': ['brightness'] } -hwmon_prefix ={'led': led_prefix} - -i2c_prefix = '/sys/bus/i2c/devices/' -i2c_bus = {'fan': ['2-0066'] , - 'thermal': ['3-0048','3-0049', '3-004a', '3-004b'] , - 'psu': ['10-0051','11-0053'], - 'sfp': ['-0050']} -i2c_nodes = {'fan': ['present', 'front_speed_rpm', 'rear_speed_rpm'] , - 'thermal': ['hwmon/hwmon*/temp1_input'] , - 'psu': ['psu_present ', 'psu_power_good'] , - 'sfp': ['sfp_is_present', 'sfp_tx_disable']} - -sfp_map = [18,19,20,21,22,23,24,25,26,27, - 28,29,30,31,32,33,34,35,36,37, - 38,39,40,41,42,43,44,45,46,47, - 48,49,50,51,52,53,54,55,56,57, - 58,59,60,61,62,63,64,65,66,67, - 68,69,70,71] - -qsfp_start = 48 - -mknod =[ -'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-0/new_device' , -'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-1/new_device' , -'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-1/new_device' , -'echo pca9548 0x74 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x75 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-1/new_device', - -'echo as7312_54x_fan 0x66 > /sys/bus/i2c/devices/i2c-2/new_device ', -'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-3/new_device', -'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-3/new_device', -'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-3/new_device', -'echo lm75 0x4b > /sys/bus/i2c/devices/i2c-3/new_device', -'echo as7312_54x_psu1 0x53 > /sys/bus/i2c/devices/i2c-11/new_device', -'echo ym2651 0x5b > /sys/bus/i2c/devices/i2c-11/new_device', -'echo as7312_54x_psu2 0x50 > /sys/bus/i2c/devices/i2c-10/new_device', -'echo ym2651 0x58 > /sys/bus/i2c/devices/i2c-10/new_device', -'echo as7312_54x_cpld1 0x60 > /sys/bus/i2c/devices/i2c-4/new_device', -'echo as7312_54x_cpld2 0x62 > /sys/bus/i2c/devices/i2c-5/new_device', -'echo as7312_54x_cpld3 0x64 > /sys/bus/i2c/devices/i2c-6/new_device'] - -mknod2 =[ -'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-1/new_device' , -'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-0/new_device' , -'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-0/new_device' , -'echo pca9548 0x74 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo pca9548 0x75 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-0/new_device', - -'echo as7312_54x_fan 0x66 > /sys/bus/i2c/devices/i2c-2/new_device ', -'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-3/new_device', -'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-3/new_device', -'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-3/new_device', -'echo lm75 0x4b > /sys/bus/i2c/devices/i2c-3/new_device', -'echo as7312_54x_psu1 0x53 > /sys/bus/i2c/devices/i2c-11/new_device', -'echo ym2651 0x5b > /sys/bus/i2c/devices/i2c-11/new_device', -'echo as7312_54x_psu2 0x50 > /sys/bus/i2c/devices/i2c-10/new_device', -'echo ym2651 0x58 > /sys/bus/i2c/devices/i2c-10/new_device', -'echo as7312_54x_cpld1 0x60 > /sys/bus/i2c/devices/i2c-4/new_device', -'echo as7312_54x_cpld2 0x62 > /sys/bus/i2c/devices/i2c-5/new_device', -'echo as7312_54x_cpld3 0x64 > /sys/bus/i2c/devices/i2c-6/new_device'] - - - -def i2c_order_check(): - # i2c bus 0 and 1 might be installed in different order. - # Here check if 0x70 is exist @ i2c-1 - tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device" - status, output = log_os_system(tmp, 0) - if not device_exist(): - order = 1 - else: - order = 0 - tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-1/delete_device" - status, output = log_os_system(tmp, 0) - return order - -def device_install(): - global FORCE - - order = i2c_order_check() - - # if 0x70 is not exist @i2c-1, use reversed bus order - if order: - for i in range(0,len(mknod2)): - #for pca954x need times to built new i2c buses - if mknod2[i].find('pca954') != -1: - time.sleep(1) - - status, output = log_os_system(mknod2[i], 1) - if status: - print output - if FORCE == 0: - return status - else: - for i in range(0,len(mknod)): - #for pca954x need times to built new i2c buses - if mknod[i].find('pca954') != -1: - time.sleep(1) - - status, output = log_os_system(mknod[i], 1) - if status: - print output - if FORCE == 0: - return status - for i in range(0,len(sfp_map)): - if i < qsfp_start: - status, output =log_os_system("echo optoe2 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1) - else: - status, output =log_os_system("echo optoe1 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1) - if status: - print output - if FORCE == 0: - return status - return - -def device_uninstall(): - global FORCE - - status, output =log_os_system("ls /sys/bus/i2c/devices/1-0076", 0) - if status==0: - I2C_ORDER=1 - else: - I2C_ORDER=0 - - for i in range(0,len(sfp_map)): - target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device" - status, output =log_os_system("echo 0x50 > "+ target, 1) - if status: - print output - if FORCE == 0: - return status - - if I2C_ORDER==0: - nodelist = mknod - else: - nodelist = mknod2 - - for i in range(len(nodelist)): - target = nodelist[-(i+1)] - temp = target.split() - del temp[1] - temp[-1] = temp[-1].replace('new_device', 'delete_device') - status, output = log_os_system(" ".join(temp), 1) - if status: - print output - if FORCE == 0: - return status - - return - -def system_ready(): - if driver_check() == False: - return False - if not device_exist(): - return False - return True - -def do_install(): - print "Checking system...." - if driver_check() == False: - print "No driver, installing...." - status = driver_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" drivers detected...." - if not device_exist(): - print "No device, installing...." - status = device_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" devices detected...." - return - -def do_uninstall(): - print "Checking system...." - if not device_exist(): - print PROJECT_NAME.upper() +" has no device installed...." - else: - print "Removing device...." - status = device_uninstall() - if status: - if FORCE == 0: - return status - - if driver_check()== False : - print PROJECT_NAME.upper() +" has no driver installed...." - else: - print "Removing installed driver...." - status = driver_uninstall() - if status: - if FORCE == 0: - return status - - return - -def devices_info(): - global DEVICE_NO - global ALL_DEVICE - global i2c_bus, hwmon_types - for key in DEVICE_NO: - ALL_DEVICE[key]= {} - for i in range(0,DEVICE_NO[key]): - ALL_DEVICE[key][key+str(i+1)] = [] - - for key in i2c_bus: - buses = i2c_bus[key] - nodes = i2c_nodes[key] - for i in range(0,len(buses)): - for j in range(0,len(nodes)): - if 'fan' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - elif 'sfp' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ str(sfp_map[k])+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - else: - node = key+str(i+1) - path = i2c_prefix+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - - for key in hwmon_types: - itypes = hwmon_types[key] - nodes = hwmon_nodes[key] - for i in range(0,len(itypes)): - for j in range(0,len(nodes)): - node = key+"_"+itypes[i] - path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][ key+str(i+1)].append(path) - - #show dict all in the order - if DEBUG == True: - for i in sorted(ALL_DEVICE.keys()): - print(i+": ") - for j in sorted(ALL_DEVICE[i].keys()): - print(" "+j) - for k in (ALL_DEVICE[i][j]): - print(" "+" "+k) - return - -def show_eeprom(index): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0] - node = node.replace(node.split("/")[-1], 'sfp_eeprom') - # check if got hexdump command in current environment - ret, log = log_os_system("which hexdump", 0) - ret, log2 = log_os_system("which busybox hexdump", 0) - if len(log): - hex_cmd = 'hexdump' - elif len(log2): - hex_cmd = ' busybox hexdump' - else: - log = 'Failed : no hexdump cmd!!' - logging.info(log) - print log - return 1 - - print node + ":" - ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1) - if ret==0: - print log - else: - print "**********device no found**********" - return - -def set_device(args): - global DEVICE_NO - global ALL_DEVICE - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - - if args[0]=='led': - if int(args[1])>4: - show_set_help() - return - #print ALL_DEVICE['led'] - for i in range(0,len(ALL_DEVICE['led'])): - for k in (ALL_DEVICE['led']['led'+str(i+1)]): - ret, log = log_os_system("echo "+args[1]+" >"+k, 1) - if ret: - return ret - elif args[0]=='fan': - if int(args[1])>100: - show_set_help() - return - #print ALL_DEVICE['fan'] - #fan1~6 is all fine, all fan share same setting - node = ALL_DEVICE['fan'] ['fan1'][0] - node = node.replace(node.split("/")[-1], 'fan_duty_cycle_percentage') - ret, log = log_os_system("cat "+ node, 1) - if ret==0: - print ("Previous fan duty: " + log.strip() +"%") - ret, log = log_os_system("echo "+args[1]+" >"+node, 1) - if ret==0: - print ("Current fan duty: " + args[1] +"%") - return ret - elif args[0]=='sfp': - if int(args[1])> DEVICE_NO[args[0]] or int(args[1])==0: - show_set_help() - return - if len(args)<2: - show_set_help() - return - - if int(args[2])>1: - show_set_help() - return - - #print ALL_DEVICE[args[0]] - for i in range(0,len(ALL_DEVICE[args[0]])): - for j in ALL_DEVICE[args[0]][args[0]+str(args[1])]: - if j.find('tx_disable')!= -1: - ret, log = log_os_system("echo "+args[2]+" >"+ j, 1) - if ret: - return ret - - return - -#get digits inside a string. -#Ex: 31 for "sfp31" -def get_value(input): - digit = re.findall('\d+', input) - return int(digit[0]) - -def device_traversal(): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - for i in sorted(ALL_DEVICE.keys()): - print("============================================") - print(i.upper()+": ") - print("============================================") - - for j in sorted(ALL_DEVICE[i].keys(), key=get_value): - print " "+j+":", - for k in (ALL_DEVICE[i][j]): - ret, log = log_os_system("cat "+k, 0) - func = k.split("/")[-1].strip() - func = re.sub(j+'_','',func,1) - func = re.sub(i.lower()+'_','',func,1) - if ret==0: - print func+"="+log+" ", - else: - print func+"="+"X"+" ", - print - print("----------------------------------------------------------------") - - - print - return - -def device_exist(): - ret1, log = log_os_system("ls "+i2c_prefix+"*0070", 0) - ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0) - return not(ret1 or ret2) - -if __name__ == "__main__": - main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/classes/__init__.py b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/classes/__init__.py deleted file mode 100755 index e69de29bb2d1..000000000000 diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/classes/fanutil.py b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/classes/fanutil.py deleted file mode 100755 index 06ebbb777920..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/classes/fanutil.py +++ /dev/null @@ -1,254 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# 1/10/2018: Jostar modify for as7716_32 -# 3/32/2018: Roy Lee modify for as7326_56x -# ------------------------------------------------------------------ - -try: - import time - import logging - from collections import namedtuple -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - - -class FanUtil(object): - """Platform-specific FanUtil class""" - - FAN_NUM_ON_MAIN_BROAD = 6 - FAN_NUM_1_IDX = 1 - FAN_NUM_2_IDX = 2 - FAN_NUM_3_IDX = 3 - FAN_NUM_4_IDX = 4 - FAN_NUM_5_IDX = 5 - FAN_NUM_6_IDX = 6 - - FAN_NODE_NUM_OF_MAP = 2 - FAN_NODE_FAULT_IDX_OF_MAP = 1 - #FAN_NODE_SPEED_IDX_OF_MAP = 2 - FAN_NODE_DIR_IDX_OF_MAP = 2 - #FAN_NODE_DUTY_IDX_OF_MAP = 4 - #FANR_NODE_FAULT_IDX_OF_MAP = 5 - - BASE_VAL_PATH = '/sys/bus/i2c/devices/11-0066/{0}' - FAN_DUTY_PATH = '/sys/bus/i2c/devices/11-0066/fan_duty_cycle_percentage' - - #logfile = '' - #loglevel = logging.INFO - - """ Dictionary where - key1 = fan id index (integer) starting from 1 - key2 = fan node index (interger) starting from 1 - value = path to fan device file (string) """ - _fan_to_device_path_mapping = {} - -#fan1_direction -#fan1_fault -#fan1_present - - #(FAN_NUM_2_IDX, FAN_NODE_DUTY_IDX_OF_MAP): 'fan2_duty_cycle_percentage', - _fan_to_device_node_mapping = { - (FAN_NUM_1_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan1_fault', - (FAN_NUM_1_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan1_direction', - - (FAN_NUM_2_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan2_fault', - (FAN_NUM_2_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan2_direction', - - (FAN_NUM_3_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan3_fault', - (FAN_NUM_3_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan3_direction', - - (FAN_NUM_4_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan4_fault', - (FAN_NUM_4_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan4_direction', - - (FAN_NUM_5_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan5_fault', - (FAN_NUM_5_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan5_direction', - - (FAN_NUM_6_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan6_fault', - (FAN_NUM_6_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan6_direction', - } - - def _get_fan_to_device_node(self, fan_num, node_num): - return self._fan_to_device_node_mapping[(fan_num, node_num)] - - def _get_fan_node_val(self, fan_num, node_num): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num:%d', fan_num) - return None - - if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: - logging.debug('GET. Parameter error. node_num:%d', node_num) - return None - - device_path = self.get_fan_to_device_path(fan_num, node_num) - - try: - val_file = open(device_path, 'r') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - content = val_file.readline().rstrip() - - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return int(content) - - def _set_fan_node_val(self, fan_num, node_num, val): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num:%d', fan_num) - return None - - if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: - logging.debug('GET. Parameter error. node_num:%d', node_num) - return None - - content = str(val) - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - device_path = self.get_fan_to_device_path(fan_num, node_num) - try: - val_file = open(device_path, 'w') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - val_file.write(content) - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return True - - def __init__(self): - fan_path = self.BASE_VAL_PATH - - for fan_num in range(self.FAN_NUM_1_IDX, self.FAN_NUM_ON_MAIN_BROAD+1): - for node_num in range(self.FAN_NODE_FAULT_IDX_OF_MAP, self.FAN_NODE_NUM_OF_MAP+1): - self._fan_to_device_path_mapping[(fan_num, node_num)] = fan_path.format( - self._fan_to_device_node_mapping[(fan_num, node_num)]) - - def get_num_fans(self): - return self.FAN_NUM_ON_MAIN_BROAD - - def get_idx_fan_start(self): - return self.FAN_NUM_1_IDX - - def get_num_nodes(self): - return self.FAN_NODE_NUM_OF_MAP - - def get_idx_node_start(self): - return self.FAN_NODE_FAULT_IDX_OF_MAP - - def get_size_node_map(self): - return len(self._fan_to_device_node_mapping) - - def get_size_path_map(self): - return len(self._fan_to_device_path_mapping) - - def get_fan_to_device_path(self, fan_num, node_num): - return self._fan_to_device_path_mapping[(fan_num, node_num)] - - def get_fan_fault(self, fan_num): - return self._get_fan_node_val(fan_num, self.FAN_NODE_FAULT_IDX_OF_MAP) - - #def get_fan_speed(self, fan_num): - # return self._get_fan_node_val(fan_num, self.FAN_NODE_SPEED_IDX_OF_MAP) - - def get_fan_dir(self, fan_num): - return self._get_fan_node_val(fan_num, self.FAN_NODE_DIR_IDX_OF_MAP) - - def get_fan_duty_cycle(self): - #duty_path = self.FAN_DUTY_PATH - try: - val_file = open(self.FAN_DUTY_PATH) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - return False - - content = val_file.readline().rstrip() - val_file.close() - - return int(content) - #self._get_fan_node_val(fan_num, self.FAN_NODE_DUTY_IDX_OF_MAP) -#static u32 reg_val_to_duty_cycle(u8 reg_val) -#{ -# reg_val &= FAN_DUTY_CYCLE_REG_MASK; -# return ((u32)(reg_val+1) * 625 + 75)/ 100; -#} -# - def set_fan_duty_cycle(self, val): - - try: - fan_file = open(self.FAN_DUTY_PATH, 'r+') - except IOError as e: - print "Error: unable to open file: %s" % str(e) - return False - #val = ((val + 1 ) * 625 +75 ) / 100 - fan_file.write(str(val)) - fan_file.close() - return True - - #def get_fanr_fault(self, fan_num): - # return self._get_fan_node_val(fan_num, self.FANR_NODE_FAULT_IDX_OF_MAP) - - def get_fanr_speed(self, fan_num): - return self._get_fan_node_val(fan_num, self.FANR_NODE_SPEED_IDX_OF_MAP) - - def get_fan_status(self, fan_num): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num, %d', fan_num) - return None - - if self.get_fan_fault(fan_num) is not None and self.get_fan_fault(fan_num) > 0: - logging.debug('GET. FAN fault. fan_num, %d', fan_num) - return False - - #if self.get_fanr_fault(fan_num) is not None and self.get_fanr_fault(fan_num) > 0: - # logging.debug('GET. FANR fault. fan_num, %d', fan_num) - # return False - - return True - -#def main(): -# fan = FanUtil() -# -# print 'get_size_node_map : %d' % fan.get_size_node_map() -# print 'get_size_path_map : %d' % fan.get_size_path_map() -# for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1): -# for y in range(fan.get_idx_node_start(), fan.get_num_nodes()+1): -# print fan.get_fan_to_device_path(x, y) -# -#if __name__ == '__main__': -# main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/classes/thermalutil.py b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/classes/thermalutil.py deleted file mode 100755 index e4329b8b9783..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/classes/thermalutil.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# 1/10/2018:Jostar modify for as7716_32x -# 3/23/2018: Roy Lee modify for as7326_56x -# ------------------------------------------------------------------ - -try: - import time - import logging - import glob - from collections import namedtuple -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - - -class ThermalUtil(object): - """Platform-specific ThermalUtil class""" - - THERMAL_NUM_ON_MAIN_BROAD = 3 - THERMAL_NUM_1_IDX = 1 # 1_ON_MAIN_BROAD - THERMAL_NUM_2_IDX = 2 # 2_ON_MAIN_BROAD - THERMAL_NUM_3_IDX = 3 # 3_ON_MAIN_BROAD - - BASE_VAL_PATH = '/sys/bus/i2c/devices/{0}-00{1}/hwmon/hwmon*/temp1_input' - - """ Dictionary where - key1 = thermal id index (integer) starting from 1 - value = path to fan device file (string) """ - _thermal_to_device_path_mapping = {} - - _thermal_to_device_node_mapping = { - THERMAL_NUM_1_IDX: ['15', '48'], - THERMAL_NUM_2_IDX: ['15', '49'], - THERMAL_NUM_3_IDX: ['15', '4a'], - } - - def __init__(self): - thermal_path = self.BASE_VAL_PATH - - for x in range(self.THERMAL_NUM_1_IDX, self.THERMAL_NUM_ON_MAIN_BROAD+1): - self._thermal_to_device_path_mapping[x] = thermal_path.format( - self._thermal_to_device_node_mapping[x][0], - self._thermal_to_device_node_mapping[x][1]) - - def _get_thermal_node_val(self, thermal_num): - if thermal_num < self.THERMAL_NUM_1_IDX or thermal_num > self.THERMAL_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. thermal_num, %d', thermal_num) - return None - - device_path = self.get_thermal_to_device_path(thermal_num) - for filename in glob.glob(device_path): - try: - val_file = open(filename, 'r') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - content = val_file.readline().rstrip() - - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return int(content) - - - def get_num_thermals(self): - return self.THERMAL_NUM_ON_MAIN_BROAD - - def get_idx_thermal_start(self): - return self.THERMAL_NUM_1_IDX - - def get_size_node_map(self): - return len(self._thermal_to_device_node_mapping) - - def get_size_path_map(self): - return len(self._thermal_to_device_path_mapping) - - def get_thermal_to_device_path(self, thermal_num): - return self._thermal_to_device_path_mapping[thermal_num] - - def get_thermal_1_val(self): - return self._get_thermal_node_val(self.THERMAL_NUM_1_IDX) - - def get_thermal_2_val(self): - return self._get_thermal_node_val(self.THERMAL_NUM_2_IDX) - def get_thermal_temp(self): - return (self._get_thermal_node_val(self.THERMAL_NUM_1_IDX) + self._get_thermal_node_val(self.THERMAL_NUM_2_IDX) +self._get_thermal_node_val(self.THERMAL_NUM_3_IDX)) - -#def main(): -# thermal = ThermalUtil() -# -# print 'get_size_node_map : %d' % thermal.get_size_node_map() -# print 'get_size_path_map : %d' % thermal.get_size_path_map() -# for x in range(thermal.get_idx_thermal_start(), thermal.get_num_thermals()+1): -# print thermal.get_thermal_to_device_path(x) -# -#if __name__ == '__main__': -# main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/Makefile b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/Makefile deleted file mode 100755 index 85c066571c2f..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -ifneq ($(KERNELRELEASE),) -obj-m:= accton_i2c_cpld.o \ - accton_as7326_56x_fan.o accton_as7326_56x_leds.o \ - accton_as7326_56x_psu.o ym2651y.o - -else -ifeq (,$(KERNEL_SRC)) -$(error KERNEL_SRC is not defined) -else -KERNELDIR:=$(KERNEL_SRC) -endif -PWD:=$(shell pwd) -default: - $(MAKE) -C $(KERNELDIR) M=$(PWD) modules -clean: - rm -rf *.o *.mod.o *.mod.o *.ko .*cmd .tmp_versions Module.markers Module.symvers modules.order -endif diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_as7326_56x_fan.c b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_as7326_56x_fan.c deleted file mode 100755 index 606019f3ea44..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_as7326_56x_fan.c +++ /dev/null @@ -1,815 +0,0 @@ -/* - * A hwmon driver for the Accton as7326 56x fan - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRVNAME "as7326_56x_fan" - -#define NUM_THERMAL_SENSORS (3) /* Get sum of this number of sensors.*/ -#define THERMAL_SENSORS_DRIVER "lm75" -#define THERMAL_SENSORS_ADDRS {0x48, 0x49, 0x4a} - -#define IN -#define OUT - -static struct as7326_56x_fan_data *as7326_56x_fan_update_device(struct device *dev); -static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t get_enable(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_enable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, char *buf); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -/* fan related data, the index should match sysfs_fan_attributes - */ -static const u8 fan_reg[] = { - 0x0F, /* fan 1-6 present status */ - 0x10, /* fan 1-6 direction(0:F2B 1:B2F) */ - 0x11, /* fan PWM(for all fan) */ - 0x12, /* front fan 1 speed(rpm) */ - 0x13, /* front fan 2 speed(rpm) */ - 0x14, /* front fan 3 speed(rpm) */ - 0x15, /* front fan 4 speed(rpm) */ - 0x16, /* front fan 5 speed(rpm) */ - 0x17, /* front fan 6 speed(rpm) */ - 0x22, /* rear fan 1 speed(rpm) */ - 0x23, /* rear fan 2 speed(rpm) */ - 0x24, /* rear fan 3 speed(rpm) */ - 0x25, /* rear fan 4 speed(rpm) */ - 0x26, /* rear fan 5 speed(rpm) */ - 0x27, /* rear fan 6 speed(rpm) */ -}; - -/* Each client has this additional data */ -struct as7326_56x_fan_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */ - u8 enable; - int system_temp; /*In unit of mini-Celsius*/ - int sensors_found; -}; - -enum fan_id { - FAN1_ID, - FAN2_ID, - FAN3_ID, - FAN4_ID, - FAN5_ID, - FAN6_ID -}; - -enum sysfs_fan_attributes { - FAN_PRESENT_REG, - FAN_DIRECTION_REG, - FAN_DUTY_CYCLE_PERCENTAGE, /* Only one CPLD register to control duty cycle for all fans */ - FAN1_FRONT_SPEED_RPM, - FAN2_FRONT_SPEED_RPM, - FAN3_FRONT_SPEED_RPM, - FAN4_FRONT_SPEED_RPM, - FAN5_FRONT_SPEED_RPM, - FAN6_FRONT_SPEED_RPM, - FAN1_REAR_SPEED_RPM, - FAN2_REAR_SPEED_RPM, - FAN3_REAR_SPEED_RPM, - FAN4_REAR_SPEED_RPM, - FAN5_REAR_SPEED_RPM, - FAN6_REAR_SPEED_RPM, - FAN1_DIRECTION, - FAN2_DIRECTION, - FAN3_DIRECTION, - FAN4_DIRECTION, - FAN5_DIRECTION, - FAN6_DIRECTION, - FAN1_PRESENT, - FAN2_PRESENT, - FAN3_PRESENT, - FAN4_PRESENT, - FAN5_PRESENT, - FAN6_PRESENT, - FAN1_FAULT, - FAN2_FAULT, - FAN3_FAULT, - FAN4_FAULT, - FAN5_FAULT, - FAN6_FAULT -}; - -/* Define attributes - */ -#define DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(index, index2) \ - static SENSOR_DEVICE_ATTR(fan##index##_fault, S_IRUGO, fan_show_value, NULL, FAN##index##_FAULT);\ - static SENSOR_DEVICE_ATTR(fan##index2##_fault, S_IRUGO, fan_show_value, NULL, FAN##index##_FAULT) -#define DECLARE_FAN_FAULT_ATTR(index, index2) &sensor_dev_attr_fan##index##_fault.dev_attr.attr, \ - &sensor_dev_attr_fan##index2##_fault.dev_attr.attr - -#define DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan##index##_direction, S_IRUGO, fan_show_value, NULL, FAN##index##_DIRECTION) -#define DECLARE_FAN_DIRECTION_ATTR(index) &sensor_dev_attr_fan##index##_direction.dev_attr.attr - -#define DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE);\ - static SENSOR_DEVICE_ATTR(pwm##index, S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE);\ - static SENSOR_DEVICE_ATTR(pwm##index##_enable, S_IWUSR | S_IRUGO, get_enable, set_enable, FAN_DUTY_CYCLE_PERCENTAGE) - -#define DECLARE_FAN_DUTY_CYCLE_ATTR(index) &sensor_dev_attr_fan_duty_cycle_percentage.dev_attr.attr, \ - &sensor_dev_attr_pwm##index.dev_attr.attr, \ - &sensor_dev_attr_pwm##index##_enable.dev_attr.attr - -#define DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR() \ - static SENSOR_DEVICE_ATTR(sys_temp, S_IRUGO, get_sys_temp, NULL, FAN_DUTY_CYCLE_PERCENTAGE) - -#define DECLARE_FAN_SYSTEM_TEMP_ATTR() &sensor_dev_attr_sys_temp.dev_attr.attr - - -#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan##index##_present, S_IRUGO, fan_show_value, NULL, FAN##index##_PRESENT) -#define DECLARE_FAN_PRESENT_ATTR(index) &sensor_dev_attr_fan##index##_present.dev_attr.attr - -#define DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(index, index2) \ - static SENSOR_DEVICE_ATTR(fan##index##_front_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_FRONT_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index##_rear_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_REAR_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index##_input, S_IRUGO, fan_show_value, NULL, FAN##index##_FRONT_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index2##_input, S_IRUGO, fan_show_value, NULL, FAN##index##_REAR_SPEED_RPM) -#define DECLARE_FAN_SPEED_RPM_ATTR(index, index2) &sensor_dev_attr_fan##index##_front_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_fan##index##_rear_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_fan##index##_input.dev_attr.attr, \ - &sensor_dev_attr_fan##index2##_input.dev_attr.attr - -/* 6 fan fault attributes in this platform */ -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(1,11); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(2,12); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(3,13); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(4,14); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(5,15); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(6,16); -/* 6 fan speed(rpm) attributes in this platform */ -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(1,11); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(2,12); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(3,13); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(4,14); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(5,15); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(6,16); -/* 6 fan present attributes in this platform */ -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(1); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(2); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(3); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(4); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(5); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(6); -/* 6 fan direction attribute in this platform */ -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(1); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(2); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(3); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(4); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(5); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(6); -/* 1 fan duty cycle attribute in this platform */ -DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(1); -/* System temperature for fancontrol */ -DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR(); - -static struct attribute *as7326_56x_fan_attributes[] = { - /* fan related attributes */ - DECLARE_FAN_FAULT_ATTR(1,11), - DECLARE_FAN_FAULT_ATTR(2,12), - DECLARE_FAN_FAULT_ATTR(3,13), - DECLARE_FAN_FAULT_ATTR(4,14), - DECLARE_FAN_FAULT_ATTR(5,15), - DECLARE_FAN_FAULT_ATTR(6,16), - DECLARE_FAN_SPEED_RPM_ATTR(1,11), - DECLARE_FAN_SPEED_RPM_ATTR(2,12), - DECLARE_FAN_SPEED_RPM_ATTR(3,13), - DECLARE_FAN_SPEED_RPM_ATTR(4,14), - DECLARE_FAN_SPEED_RPM_ATTR(5,15), - DECLARE_FAN_SPEED_RPM_ATTR(6,16), - DECLARE_FAN_PRESENT_ATTR(1), - DECLARE_FAN_PRESENT_ATTR(2), - DECLARE_FAN_PRESENT_ATTR(3), - DECLARE_FAN_PRESENT_ATTR(4), - DECLARE_FAN_PRESENT_ATTR(5), - DECLARE_FAN_PRESENT_ATTR(6), - DECLARE_FAN_DIRECTION_ATTR(1), - DECLARE_FAN_DIRECTION_ATTR(2), - DECLARE_FAN_DIRECTION_ATTR(3), - DECLARE_FAN_DIRECTION_ATTR(4), - DECLARE_FAN_DIRECTION_ATTR(5), - DECLARE_FAN_DIRECTION_ATTR(6), - DECLARE_FAN_DUTY_CYCLE_ATTR(1), - DECLARE_FAN_SYSTEM_TEMP_ATTR(), - NULL -}; - -#define FAN_DUTY_CYCLE_REG_MASK 0xF -#define FAN_MAX_DUTY_CYCLE 100 -#define FAN_REG_VAL_TO_SPEED_RPM_STEP 100 - -static int as7326_56x_fan_read_value(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_byte_data(client, reg); -} - -static int as7326_56x_fan_write_value(struct i2c_client *client, u8 reg, u8 value) -{ - return i2c_smbus_write_byte_data(client, reg, value); -} - -/* fan utility functions - */ -static u32 reg_val_to_duty_cycle(u8 reg_val) -{ - reg_val &= FAN_DUTY_CYCLE_REG_MASK; - return ((u32)(reg_val+1) * 625 + 75)/ 100; -} - -static u8 duty_cycle_to_reg_val(u8 duty_cycle) -{ - return ((u32)duty_cycle * 100 / 625) - 1; -} - -static u32 reg_val_to_speed_rpm(u8 reg_val) -{ - return (u32)reg_val * FAN_REG_VAL_TO_SPEED_RPM_STEP; -} - -static u8 reg_val_to_direction(u8 reg_val, enum fan_id id) -{ - u8 mask = (1 << id); - - reg_val &= mask; - - return reg_val ? 1 : 0; -} -static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id) -{ - u8 mask = (1 << id); - - reg_val &= mask; - - return reg_val ? 0 : 1; -} - -static u8 is_fan_fault(struct as7326_56x_fan_data *data, enum fan_id id) -{ - u8 ret = 1; - int front_fan_index = FAN1_FRONT_SPEED_RPM + id; - int rear_fan_index = FAN1_REAR_SPEED_RPM + id; - - /* Check if the speed of front or rear fan is ZERO, - */ - if (reg_val_to_speed_rpm(data->reg_val[front_fan_index]) && - reg_val_to_speed_rpm(data->reg_val[rear_fan_index])) { - ret = 0; - } - - return ret; -} - -static ssize_t set_enable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct as7326_56x_fan_data *data = as7326_56x_fan_update_device(dev); - int error, value; - - error = kstrtoint(buf, 10, &value); - if (error) - return error; - - if (value < 0 || value > 1) - return -EINVAL; - - data->enable = value; - if (value == 0) - { - return set_duty_cycle(dev, da, buf, FAN_MAX_DUTY_CYCLE); - } - return count; -} - - -static ssize_t get_enable(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as7326_56x_fan_data *data = as7326_56x_fan_update_device(dev); - - return sprintf(buf, "%u\n", data->enable); -} -static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - int error, value; - struct i2c_client *client = to_i2c_client(dev); - - error = kstrtoint(buf, 10, &value); - if (error) - return error; - - if (value < 0) - return -EINVAL; - - value = (value > FAN_MAX_DUTY_CYCLE)? FAN_MAX_DUTY_CYCLE : value; - - as7326_56x_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */ - as7326_56x_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value)); - return count; -} - -/* Due to this struct is declared at lm75.c, it cannot be include - * under Sonic environment. I duplicate it from lm75.c. - */ -struct lm75_data { - struct i2c_client *client; - struct device *hwmon_dev; - struct thermal_zone_device *tz; - struct mutex update_lock; - u8 orig_conf; - u8 resolution; /* In bits, between 9 and 12 */ - u8 resolution_limits; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - unsigned long sample_time; /* In jiffies */ - s16 temp[3]; /* Register values, - 0 = input - 1 = max - 2 = hyst */ -}; - -/*Copied from lm75.c*/ -static inline long lm75_reg_to_mc(s16 temp, u8 resolution) -{ - return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8); -} - -/*Get hwmon_dev from i2c_client, set hwmon_dev = NULL is failed.*/ -static struct device * get_hwmon_dev( - struct i2c_client *client) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - if(data) - { - if( data->valid == 1 && data->hwmon_dev) - { - return data->hwmon_dev; - } - - } - return NULL; -} - -/* To find hwmon index by opening hwmon under that i2c address. - */ -static int find_hwmon_index_by_FileOpen( - int bus_nr, - unsigned short addr, - OUT int *index) -{ -#define MAX_HWMON_DEVICE (10) /* Find hwmon device in 0~10*/ - struct file *sfd; - char client_name[96]; - int i=0; - - do { - snprintf(client_name, sizeof(client_name), - "/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input", - bus_nr, addr, i); - - sfd = filp_open(client_name, O_RDONLY, 0); - i++; - } while( IS_ERR(sfd) && i < MAX_HWMON_DEVICE); - - if (IS_ERR(sfd)) { - pr_err("Failed to open file(%s)#%d\r\n", client_name, __LINE__); - return -ENOENT; - } - filp_close(sfd, 0); - *index = i - 1; - return 0; - -#undef MAX_HWMON_DEVICE -} - -static int get_temp_file_path( - int bus_nr, unsigned short addr, - struct device *hwmon_dev - ,char *path, int max_len) -{ - - if(hwmon_dev && strlen(dev_name(hwmon_dev))) - { - snprintf(path, max_len, - "/sys/bus/i2c/devices/%d-%04x/hwmon/%s/temp1_input", - bus_nr, addr, dev_name(hwmon_dev)); - } - else - { - int i=0; - if(find_hwmon_index_by_FileOpen( bus_nr, addr, &i)) - { - return -EIO; - } - snprintf(path, max_len, - "/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input", - bus_nr, addr, i); - } - return 0; -} - -/*File read the dev file at user space.*/ -static int read_devfile_temp1_input( - struct device *dev, - int bus_nr, - unsigned short addr, - struct device *hwmon_dev, - int *miniCelsius) -{ - struct file *sfd; - char buffer[96]; - char devfile[96]; - int rc, status; - int rdlen, value; - mm_segment_t old_fs; - - rc = 0; - get_temp_file_path(bus_nr, addr, hwmon_dev, devfile, sizeof(devfile)); - sfd = filp_open(devfile, O_RDONLY, 0); - if (IS_ERR(sfd)) { - pr_err("Failed to open file(%s)#%d\r\n", devfile, __LINE__); - return -ENOENT; - } - dev_dbg(dev, "Found device:%s\n",devfile); - - if(!(sfd->f_op) || !(sfd->f_op->read) ) { - pr_err("file %s cann't readable ?\n",devfile); - return -ENOENT; - } - - old_fs = get_fs(); - set_fs(KERNEL_DS); - rdlen = sfd->f_op->read(sfd, buffer, sizeof(buffer), &sfd->f_pos); - if (rdlen == 0) { - pr_err( "File(%s) empty!\n", devfile); - rc = -EIO; - goto exit; - } - status = sscanf(buffer, "%d", &value); - if (status != 1) { - rc = -EIO; - goto exit; - } - *miniCelsius = value; - dev_dbg(dev,"found sensors: %d @i2c %d-%04x\n", value, bus_nr, addr); - -exit: - set_fs(old_fs); - filp_close(sfd, 0); - return rc; -} - -static u8 is_lm75_data_due(struct i2c_client *client) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - if (time_after(jiffies, data->last_updated + data->sample_time)) - { - return 1; - } - return 0; -} -static int get_lm75_temp(struct i2c_client *client, int *miniCelsius) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - *miniCelsius = lm75_reg_to_mc(data->temp[0], data->resolution); - - return 0; -} - -static bool lm75_addr_mached(unsigned short addr) -{ - int i; - unsigned short addrs[] = THERMAL_SENSORS_ADDRS; - - for (i = 0; i < ARRAY_SIZE(addrs); i++) - { - if( addr == addrs[i]) - return 1; - } - return 0; -} - -static int _find_lm75_device(struct device *dev, void *data) -{ - struct device_driver *driver; - struct as7326_56x_fan_data *prv = data; - char *driver_name = THERMAL_SENSORS_DRIVER; - - driver = dev->driver; - if (driver && driver->name && - strcmp(driver->name, driver_name) == 0) - { - struct i2c_client *client; - client = to_i2c_client(dev); - if (client) - { - /*cannot use "struct i2c_adapter *adap = to_i2c_adapter(dev);"*/ - struct i2c_adapter *adap = client->adapter; - int miniCelsius = 0; - - if (! lm75_addr_mached(client->addr)) - { - return 0; - } - - if (!adap) { - return -ENXIO; - } - - /* If the data is not updated, read them from devfile - to drive them updateing data from chip.*/ - if (is_lm75_data_due(client)) - { - struct device *hwmon_dev; - - hwmon_dev = get_hwmon_dev(client); - if(0 == read_devfile_temp1_input(dev, adap->nr, - client->addr, hwmon_dev, &miniCelsius)) - { - prv->system_temp += miniCelsius; - prv->sensors_found++; - } - - } - else - { - get_lm75_temp(client, &miniCelsius); - prv->system_temp += miniCelsius; - prv->sensors_found++; - - } - } - } - return 0; -} - -/*Find all lm75 devices and return sum of temperatures.*/ -static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, - char *buf) -{ - ssize_t ret = 0; - struct as7326_56x_fan_data *data = as7326_56x_fan_update_device(dev); - - data->system_temp=0; - data->sensors_found=0; - i2c_for_each_dev(data, _find_lm75_device); - if (NUM_THERMAL_SENSORS != data->sensors_found) - { - dev_dbg(dev,"only %d of %d temps are found\n", - data->sensors_found, NUM_THERMAL_SENSORS); - data->system_temp = INT_MAX; - } - ret = sprintf(buf, "%d\n",data->system_temp); - return ret; -} - -static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as7326_56x_fan_data *data = as7326_56x_fan_update_device(dev); - ssize_t ret = 0; - - if (data->valid) { - switch (attr->index) { - case FAN_DUTY_CYCLE_PERCENTAGE: - { - u32 duty_cycle = reg_val_to_duty_cycle(data->reg_val[FAN_DUTY_CYCLE_PERCENTAGE]); - ret = sprintf(buf, "%u\n", duty_cycle); - break; - } - case FAN1_FRONT_SPEED_RPM: - case FAN2_FRONT_SPEED_RPM: - case FAN3_FRONT_SPEED_RPM: - case FAN4_FRONT_SPEED_RPM: - case FAN5_FRONT_SPEED_RPM: - case FAN6_FRONT_SPEED_RPM: - case FAN1_REAR_SPEED_RPM: - case FAN2_REAR_SPEED_RPM: - case FAN3_REAR_SPEED_RPM: - case FAN4_REAR_SPEED_RPM: - case FAN5_REAR_SPEED_RPM: - case FAN6_REAR_SPEED_RPM: - ret = sprintf(buf, "%u\n", reg_val_to_speed_rpm(data->reg_val[attr->index])); - break; - case FAN1_PRESENT: - case FAN2_PRESENT: - case FAN3_PRESENT: - case FAN4_PRESENT: - case FAN5_PRESENT: - case FAN6_PRESENT: - ret = sprintf(buf, "%d\n", - reg_val_to_is_present(data->reg_val[FAN_PRESENT_REG], - attr->index - FAN1_PRESENT)); - break; - case FAN1_FAULT: - case FAN2_FAULT: - case FAN3_FAULT: - case FAN4_FAULT: - case FAN5_FAULT: - case FAN6_FAULT: - ret = sprintf(buf, "%d\n", is_fan_fault(data, attr->index - FAN1_FAULT)); - break; - case FAN1_DIRECTION: - case FAN2_DIRECTION: - case FAN3_DIRECTION: - case FAN4_DIRECTION: - case FAN5_DIRECTION: - case FAN6_DIRECTION: - ret = sprintf(buf, "%d\n", - reg_val_to_direction(data->reg_val[FAN_DIRECTION_REG], - attr->index - FAN1_DIRECTION)); - break; - default: - break; - } - } - - return ret; -} - -static const struct attribute_group as7326_56x_fan_group = { - .attrs = as7326_56x_fan_attributes, -}; - -static struct as7326_56x_fan_data *as7326_56x_fan_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7326_56x_fan_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || - !data->valid) { - int i; - - dev_dbg(&client->dev, "Starting as7326_56x_fan update\n"); - data->valid = 0; - - /* Update fan data - */ - for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) { - int status = as7326_56x_fan_read_value(client, fan_reg[i]); - - if (status < 0) { - data->valid = 0; - mutex_unlock(&data->update_lock); - dev_dbg(&client->dev, "reg %d, err %d\n", fan_reg[i], status); - return data; - } - else { - data->reg_val[i] = status; - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -static int as7326_56x_fan_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7326_56x_fan_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7326_56x_fan_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - data->enable = 0; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7326_56x_fan_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: fan '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7326_56x_fan_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7326_56x_fan_remove(struct i2c_client *client) -{ - struct as7326_56x_fan_data *data = i2c_get_clientdata(client); - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7326_56x_fan_group); - - return 0; -} - -/* Addresses to scan */ -static const unsigned short normal_i2c[] = { 0x66, I2C_CLIENT_END }; - -static const struct i2c_device_id as7326_56x_fan_id[] = { - { "as7326_56x_fan", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7326_56x_fan_id); - -static struct i2c_driver as7326_56x_fan_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = DRVNAME, - }, - .probe = as7326_56x_fan_probe, - .remove = as7326_56x_fan_remove, - .id_table = as7326_56x_fan_id, - .address_list = normal_i2c, -}; - -static int __init as7326_56x_fan_init(void) -{ - return i2c_add_driver(&as7326_56x_fan_driver); -} - -static void __exit as7326_56x_fan_exit(void) -{ - i2c_del_driver(&as7326_56x_fan_driver); -} - -module_init(as7326_56x_fan_init); -module_exit(as7326_56x_fan_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7326_56x_fan driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_as7326_56x_leds.c b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_as7326_56x_leds.c deleted file mode 100644 index 4cb7f1fa25a5..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_as7326_56x_leds.c +++ /dev/null @@ -1,438 +0,0 @@ -/* - * A LED driver for the accton_as7326_56x_led - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/*#define DEBUG*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -extern int as7326_56x_cpld_read (unsigned short cpld_addr, u8 reg); -extern int as7326_56x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -extern void led_classdev_unregister(struct led_classdev *led_cdev); -extern int led_classdev_register(struct device *parent, struct led_classdev *led_cdev); -extern void led_classdev_resume(struct led_classdev *led_cdev); -extern void led_classdev_suspend(struct led_classdev *led_cdev); - -#define DRVNAME "accton_as7326_56x_led" - -struct accton_as7326_56x_led_data { - struct platform_device *pdev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[1]; /* only 1 register*/ -}; - -static struct accton_as7326_56x_led_data *ledctl = NULL; - -/* LED related data - */ - -#define LED_CNTRLER_I2C_ADDRESS (0x60) - -#define LED_TYPE_DIAG_REG_MASK (0x3) -#define LED_MODE_DIAG_GREEN_VALUE (0x02) -#define LED_MODE_DIAG_RED_VALUE (0x01) -#define LED_MODE_DIAG_AMBER_VALUE (0x00) /*It's yellow actually. Green+Red=Yellow*/ -#define LED_MODE_DIAG_OFF_VALUE (0x03) - - -#define LED_TYPE_LOC_REG_MASK (0x80) -#define LED_MODE_LOC_ON_VALUE (0) -#define LED_MODE_LOC_OFF_VALUE (0x80) - -enum led_type { - LED_TYPE_DIAG, - LED_TYPE_LOC, - LED_TYPE_FAN, - LED_TYPE_PSU1, - LED_TYPE_PSU2 -}; - -struct led_reg { - u32 types; - u8 reg_addr; -}; - -static const struct led_reg led_reg_map[] = { - {(1<update_lock); - - if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2) - || !ledctl->valid) { - int i; - - dev_dbg(&ledctl->pdev->dev, "Starting accton_as7326_56x_led update\n"); - - /* Update LED data - */ - for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { - int status = accton_as7326_56x_led_read_value(led_reg_map[i].reg_addr); - - if (status < 0) { - ledctl->valid = 0; - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg_map[i].reg_addr, status); - goto exit; - } - else - { - ledctl->reg_val[i] = status; - } - } - - ledctl->last_updated = jiffies; - ledctl->valid = 1; - } - -exit: - mutex_unlock(&ledctl->update_lock); -} - -static void accton_as7326_56x_led_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode, - enum led_type type) -{ - int reg_val; - u8 reg ; - mutex_lock(&ledctl->update_lock); - - if( !accton_getLedReg(type, ®)) - { - dev_dbg(&ledctl->pdev->dev, "Not match item for %d.\n", type); - } - - reg_val = accton_as7326_56x_led_read_value(reg); - - if (reg_val < 0) { - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val); - goto exit; - } - reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val); - accton_as7326_56x_led_write_value(reg, reg_val); - - /* to prevent the slow-update issue */ - ledctl->valid = 0; - -exit: - mutex_unlock(&ledctl->update_lock); -} - - -static void accton_as7326_56x_led_diag_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as7326_56x_led_set(led_cdev, led_light_mode, LED_TYPE_DIAG); -} - -static enum led_brightness accton_as7326_56x_led_diag_get(struct led_classdev *cdev) -{ - accton_as7326_56x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); -} - -static void accton_as7326_56x_led_loc_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as7326_56x_led_set(led_cdev, led_light_mode, LED_TYPE_LOC); -} - -static enum led_brightness accton_as7326_56x_led_loc_get(struct led_classdev *cdev) -{ - accton_as7326_56x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); -} - -static void accton_as7326_56x_led_auto_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ -} - -static enum led_brightness accton_as7326_56x_led_auto_get(struct led_classdev *cdev) -{ - return LED_MODE_AUTO; -} - -static struct led_classdev accton_as7326_56x_leds[] = { - [LED_TYPE_DIAG] = { - .name = "accton_as7326_56x_led::diag", - .default_trigger = "unused", - .brightness_set = accton_as7326_56x_led_diag_set, - .brightness_get = accton_as7326_56x_led_diag_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_RED, - }, - [LED_TYPE_LOC] = { - .name = "accton_as7326_56x_led::loc", - .default_trigger = "unused", - .brightness_set = accton_as7326_56x_led_loc_set, - .brightness_get = accton_as7326_56x_led_loc_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_BLUE, - }, - [LED_TYPE_FAN] = { - .name = "accton_as7326_56x_led::fan", - .default_trigger = "unused", - .brightness_set = accton_as7326_56x_led_auto_set, - .brightness_get = accton_as7326_56x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_PSU1] = { - .name = "accton_as7326_56x_led::psu1", - .default_trigger = "unused", - .brightness_set = accton_as7326_56x_led_auto_set, - .brightness_get = accton_as7326_56x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_PSU2] = { - .name = "accton_as7326_56x_led::psu2", - .default_trigger = "unused", - .brightness_set = accton_as7326_56x_led_auto_set, - .brightness_get = accton_as7326_56x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, -}; - -static int accton_as7326_56x_led_suspend(struct platform_device *dev, - pm_message_t state) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(accton_as7326_56x_leds); i++) { - led_classdev_suspend(&accton_as7326_56x_leds[i]); - } - - return 0; -} - -static int accton_as7326_56x_led_resume(struct platform_device *dev) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(accton_as7326_56x_leds); i++) { - led_classdev_resume(&accton_as7326_56x_leds[i]); - } - - return 0; -} - -static int accton_as7326_56x_led_probe(struct platform_device *pdev) -{ - int ret, i; - - for (i = 0; i < ARRAY_SIZE(accton_as7326_56x_leds); i++) { - ret = led_classdev_register(&pdev->dev, &accton_as7326_56x_leds[i]); - - if (ret < 0) - break; - } - - /* Check if all LEDs were successfully registered */ - if (i != ARRAY_SIZE(accton_as7326_56x_leds)) { - int j; - - /* only unregister the LEDs that were successfully registered */ - for (j = 0; j < i; j++) { - led_classdev_unregister(&accton_as7326_56x_leds[i]); - } - } - - return ret; -} - -static int accton_as7326_56x_led_remove(struct platform_device *pdev) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(accton_as7326_56x_leds); i++) { - led_classdev_unregister(&accton_as7326_56x_leds[i]); - } - - return 0; -} - -static struct platform_driver accton_as7326_56x_led_driver = { - .probe = accton_as7326_56x_led_probe, - .remove = accton_as7326_56x_led_remove, - .suspend = accton_as7326_56x_led_suspend, - .resume = accton_as7326_56x_led_resume, - .driver = { - .name = DRVNAME, - .owner = THIS_MODULE, - }, -}; - -static int __init accton_as7326_56x_led_init(void) -{ - int ret; - - ret = platform_driver_register(&accton_as7326_56x_led_driver); - if (ret < 0) { - goto exit; - } - - ledctl = kzalloc(sizeof(struct accton_as7326_56x_led_data), GFP_KERNEL); - if (!ledctl) { - ret = -ENOMEM; - platform_driver_unregister(&accton_as7326_56x_led_driver); - goto exit; - } - - mutex_init(&ledctl->update_lock); - - ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); - if (IS_ERR(ledctl->pdev)) { - ret = PTR_ERR(ledctl->pdev); - platform_driver_unregister(&accton_as7326_56x_led_driver); - kfree(ledctl); - goto exit; - } - -exit: - return ret; -} - -static void __exit accton_as7326_56x_led_exit(void) -{ - platform_device_unregister(ledctl->pdev); - platform_driver_unregister(&accton_as7326_56x_led_driver); - kfree(ledctl); -} - -module_init(accton_as7326_56x_led_init); -module_exit(accton_as7326_56x_led_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton_as7326_56x_led driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_as7326_56x_psu.c b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_as7326_56x_psu.c deleted file mode 100644 index 8c2ece6200fe..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_as7326_56x_psu.c +++ /dev/null @@ -1,277 +0,0 @@ -/* - * An hwmon driver for accton as7326_56x Power Module - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); -static int as7326_56x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int as7326_56x_cpld_read(unsigned short cpld_addr, u8 reg); - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x50, 0x53, I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as7326_56x_psu_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 index; /* PSU index */ - u8 status; /* Status(present/power_good) register read from CPLD */ - char model_name[9]; /* Model name, read from eeprom */ -}; - -static struct as7326_56x_psu_data *as7326_56x_psu_update_device(struct device *dev); - -enum as7326_56x_psu_sysfs_attributes { - PSU_PRESENT, - PSU_MODEL_NAME, - PSU_POWER_GOOD -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT); -static SENSOR_DEVICE_ATTR(psu_model_name, S_IRUGO, show_model_name,NULL, PSU_MODEL_NAME); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD); - -static struct attribute *as7326_56x_psu_attributes[] = { - &sensor_dev_attr_psu_present.dev_attr.attr, - &sensor_dev_attr_psu_model_name.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - NULL -}; - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as7326_56x_psu_data *data = as7326_56x_psu_update_device(dev); - u8 status = 0; - - if (attr->index == PSU_PRESENT) { - status = !(data->status >> (1-data->index) & 0x1); - } - else { /* PSU_POWER_GOOD */ - status = (data->status >> (3-data->index) & 0x1); - } - - return sprintf(buf, "%d\n", status); -} - -static ssize_t show_model_name(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as7326_56x_psu_data *data = as7326_56x_psu_update_device(dev); - - return sprintf(buf, "%s\n", data->model_name); -} - -static const struct attribute_group as7326_56x_psu_group = { - .attrs = as7326_56x_psu_attributes, -}; - -static int as7326_56x_psu_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7326_56x_psu_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7326_56x_psu_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - data->index = dev_id->driver_data; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7326_56x_psu_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7326_56x_psu_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7326_56x_psu_remove(struct i2c_client *client) -{ - struct as7326_56x_psu_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7326_56x_psu_group); - kfree(data); - - return 0; -} - -enum psu_index -{ - as7326_56x_psu1, - as7326_56x_psu2 -}; - -static const struct i2c_device_id as7326_56x_psu_id[] = { - { "as7326_56x_psu1", as7326_56x_psu1 }, - { "as7326_56x_psu2", as7326_56x_psu2 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7326_56x_psu_id); - -static struct i2c_driver as7326_56x_psu_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7326_56x_psu", - }, - .probe = as7326_56x_psu_probe, - .remove = as7326_56x_psu_remove, - .id_table = as7326_56x_psu_id, - .address_list = normal_i2c, -}; - -static int as7326_56x_psu_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = 0; - int retry_count = 5; - - while (retry_count) { - retry_count--; - - result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) { - msleep(10); - continue; - } - - if (unlikely(result != data_len)) { - result = -EIO; - msleep(10); - continue; - } - - result = 0; - break; - } - - return result; -} - -static struct as7326_56x_psu_data *as7326_56x_psu_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7326_56x_psu_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int status; - int power_good = 0; - - dev_dbg(&client->dev, "Starting as7326_56x update\n"); - - /* Read psu status */ - status = as7326_56x_cpld_read(0x60, 0x2); - - if (status < 0) { - dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); - } - else { - data->status = status; - } - - /* Read model name */ - memset(data->model_name, 0, sizeof(data->model_name)); - power_good = (data->status >> (3-data->index) & 0x1); - - if (power_good) { - status = as7326_56x_psu_read_block(client, 0x20, data->model_name, - ARRAY_SIZE(data->model_name)-1); - - if (status < 0) { - data->model_name[0] = '\0'; - dev_dbg(&client->dev, "unable to read model name from (0x%x)\n", client->addr); - } - else { - data->model_name[ARRAY_SIZE(data->model_name)-1] = '\0'; - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -module_i2c_driver(as7326_56x_psu_driver); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7326_56x_psu driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_i2c_cpld.c b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_i2c_cpld.c deleted file mode 100644 index 2274c4a934c0..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_i2c_cpld.c +++ /dev/null @@ -1,1080 +0,0 @@ -/* - * Copyright (C) Brandon Chuang - * - * This module supports the accton cpld that hold the channel select - * mechanism for other i2c slave devices, such as SFP. - * This includes the: - * Accton as7326_56x CPLD1/CPLD2/CPLD3 - * - * Based on: - * pca954x.c from Kumar Gala - * Copyright (C) 2006 - * - * Based on: - * pca954x.c from Ken Harrenstien - * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) - * - * Based on: - * i2c-virtual_cb.c from Brian Kuschak - * and - * pca9540.c from Jean Delvare . - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include - -#define I2C_RW_RETRY_COUNT 10 -#define I2C_RW_RETRY_INTERVAL 60 /* ms */ - -static LIST_HEAD(cpld_client_list); -static struct mutex list_lock; - -struct cpld_client_node { - struct i2c_client *client; - struct list_head list; -}; - -enum cpld_type { - as7326_56x_cpld1, - as7326_56x_cpld2, - as7326_56x_cpld3 -}; - -struct as7326_56x_cpld_data { - enum cpld_type type; - struct device *hwmon_dev; - struct mutex update_lock; -}; - -static const struct i2c_device_id as7326_56x_cpld_id[] = { - { "as7326_56x_cpld1", as7326_56x_cpld1 }, - { "as7326_56x_cpld2", as7326_56x_cpld2 }, - { "as7326_56x_cpld3", as7326_56x_cpld3 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, as7326_56x_cpld_id); - -#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index -#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index -#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index -#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index -#define TRANSCEIVER_RESET_ATTR_ID(index) MODULE_RESET_##index - -enum as7326_56x_cpld_sysfs_attributes { - CPLD_VERSION, - ACCESS, - MODULE_PRESENT_ALL, - MODULE_RXLOS_ALL, - /* transceiver attributes */ - TRANSCEIVER_PRESENT_ATTR_ID(1), - TRANSCEIVER_PRESENT_ATTR_ID(2), - TRANSCEIVER_PRESENT_ATTR_ID(3), - TRANSCEIVER_PRESENT_ATTR_ID(4), - TRANSCEIVER_PRESENT_ATTR_ID(5), - TRANSCEIVER_PRESENT_ATTR_ID(6), - TRANSCEIVER_PRESENT_ATTR_ID(7), - TRANSCEIVER_PRESENT_ATTR_ID(8), - TRANSCEIVER_PRESENT_ATTR_ID(9), - TRANSCEIVER_PRESENT_ATTR_ID(10), - TRANSCEIVER_PRESENT_ATTR_ID(11), - TRANSCEIVER_PRESENT_ATTR_ID(12), - TRANSCEIVER_PRESENT_ATTR_ID(13), - TRANSCEIVER_PRESENT_ATTR_ID(14), - TRANSCEIVER_PRESENT_ATTR_ID(15), - TRANSCEIVER_PRESENT_ATTR_ID(16), - TRANSCEIVER_PRESENT_ATTR_ID(17), - TRANSCEIVER_PRESENT_ATTR_ID(18), - TRANSCEIVER_PRESENT_ATTR_ID(19), - TRANSCEIVER_PRESENT_ATTR_ID(20), - TRANSCEIVER_PRESENT_ATTR_ID(21), - TRANSCEIVER_PRESENT_ATTR_ID(22), - TRANSCEIVER_PRESENT_ATTR_ID(23), - TRANSCEIVER_PRESENT_ATTR_ID(24), - TRANSCEIVER_PRESENT_ATTR_ID(25), - TRANSCEIVER_PRESENT_ATTR_ID(26), - TRANSCEIVER_PRESENT_ATTR_ID(27), - TRANSCEIVER_PRESENT_ATTR_ID(28), - TRANSCEIVER_PRESENT_ATTR_ID(29), - TRANSCEIVER_PRESENT_ATTR_ID(30), - TRANSCEIVER_PRESENT_ATTR_ID(31), - TRANSCEIVER_PRESENT_ATTR_ID(32), - TRANSCEIVER_PRESENT_ATTR_ID(33), - TRANSCEIVER_PRESENT_ATTR_ID(34), - TRANSCEIVER_PRESENT_ATTR_ID(35), - TRANSCEIVER_PRESENT_ATTR_ID(36), - TRANSCEIVER_PRESENT_ATTR_ID(37), - TRANSCEIVER_PRESENT_ATTR_ID(38), - TRANSCEIVER_PRESENT_ATTR_ID(39), - TRANSCEIVER_PRESENT_ATTR_ID(40), - TRANSCEIVER_PRESENT_ATTR_ID(41), - TRANSCEIVER_PRESENT_ATTR_ID(42), - TRANSCEIVER_PRESENT_ATTR_ID(43), - TRANSCEIVER_PRESENT_ATTR_ID(44), - TRANSCEIVER_PRESENT_ATTR_ID(45), - TRANSCEIVER_PRESENT_ATTR_ID(46), - TRANSCEIVER_PRESENT_ATTR_ID(47), - TRANSCEIVER_PRESENT_ATTR_ID(48), - TRANSCEIVER_PRESENT_ATTR_ID(49), - TRANSCEIVER_PRESENT_ATTR_ID(50), - TRANSCEIVER_PRESENT_ATTR_ID(51), - TRANSCEIVER_PRESENT_ATTR_ID(52), - TRANSCEIVER_PRESENT_ATTR_ID(53), - TRANSCEIVER_PRESENT_ATTR_ID(54), - TRANSCEIVER_PRESENT_ATTR_ID(55), - TRANSCEIVER_PRESENT_ATTR_ID(56), - TRANSCEIVER_PRESENT_ATTR_ID(57), - TRANSCEIVER_PRESENT_ATTR_ID(58), - TRANSCEIVER_TXDISABLE_ATTR_ID(1), - TRANSCEIVER_TXDISABLE_ATTR_ID(2), - TRANSCEIVER_TXDISABLE_ATTR_ID(3), - TRANSCEIVER_TXDISABLE_ATTR_ID(4), - TRANSCEIVER_TXDISABLE_ATTR_ID(5), - TRANSCEIVER_TXDISABLE_ATTR_ID(6), - TRANSCEIVER_TXDISABLE_ATTR_ID(7), - TRANSCEIVER_TXDISABLE_ATTR_ID(8), - TRANSCEIVER_TXDISABLE_ATTR_ID(9), - TRANSCEIVER_TXDISABLE_ATTR_ID(10), - TRANSCEIVER_TXDISABLE_ATTR_ID(11), - TRANSCEIVER_TXDISABLE_ATTR_ID(12), - TRANSCEIVER_TXDISABLE_ATTR_ID(13), - TRANSCEIVER_TXDISABLE_ATTR_ID(14), - TRANSCEIVER_TXDISABLE_ATTR_ID(15), - TRANSCEIVER_TXDISABLE_ATTR_ID(16), - TRANSCEIVER_TXDISABLE_ATTR_ID(17), - TRANSCEIVER_TXDISABLE_ATTR_ID(18), - TRANSCEIVER_TXDISABLE_ATTR_ID(19), - TRANSCEIVER_TXDISABLE_ATTR_ID(20), - TRANSCEIVER_TXDISABLE_ATTR_ID(21), - TRANSCEIVER_TXDISABLE_ATTR_ID(22), - TRANSCEIVER_TXDISABLE_ATTR_ID(23), - TRANSCEIVER_TXDISABLE_ATTR_ID(24), - TRANSCEIVER_TXDISABLE_ATTR_ID(25), - TRANSCEIVER_TXDISABLE_ATTR_ID(26), - TRANSCEIVER_TXDISABLE_ATTR_ID(27), - TRANSCEIVER_TXDISABLE_ATTR_ID(28), - TRANSCEIVER_TXDISABLE_ATTR_ID(29), - TRANSCEIVER_TXDISABLE_ATTR_ID(30), - TRANSCEIVER_TXDISABLE_ATTR_ID(31), - TRANSCEIVER_TXDISABLE_ATTR_ID(32), - TRANSCEIVER_TXDISABLE_ATTR_ID(33), - TRANSCEIVER_TXDISABLE_ATTR_ID(34), - TRANSCEIVER_TXDISABLE_ATTR_ID(35), - TRANSCEIVER_TXDISABLE_ATTR_ID(36), - TRANSCEIVER_TXDISABLE_ATTR_ID(37), - TRANSCEIVER_TXDISABLE_ATTR_ID(38), - TRANSCEIVER_TXDISABLE_ATTR_ID(39), - TRANSCEIVER_TXDISABLE_ATTR_ID(40), - TRANSCEIVER_TXDISABLE_ATTR_ID(41), - TRANSCEIVER_TXDISABLE_ATTR_ID(42), - TRANSCEIVER_TXDISABLE_ATTR_ID(43), - TRANSCEIVER_TXDISABLE_ATTR_ID(44), - TRANSCEIVER_TXDISABLE_ATTR_ID(45), - TRANSCEIVER_TXDISABLE_ATTR_ID(46), - TRANSCEIVER_TXDISABLE_ATTR_ID(47), - TRANSCEIVER_TXDISABLE_ATTR_ID(48), - TRANSCEIVER_TXDISABLE_ATTR_ID(57), - TRANSCEIVER_TXDISABLE_ATTR_ID(58), - TRANSCEIVER_RXLOS_ATTR_ID(1), - TRANSCEIVER_RXLOS_ATTR_ID(2), - TRANSCEIVER_RXLOS_ATTR_ID(3), - TRANSCEIVER_RXLOS_ATTR_ID(4), - TRANSCEIVER_RXLOS_ATTR_ID(5), - TRANSCEIVER_RXLOS_ATTR_ID(6), - TRANSCEIVER_RXLOS_ATTR_ID(7), - TRANSCEIVER_RXLOS_ATTR_ID(8), - TRANSCEIVER_RXLOS_ATTR_ID(9), - TRANSCEIVER_RXLOS_ATTR_ID(10), - TRANSCEIVER_RXLOS_ATTR_ID(11), - TRANSCEIVER_RXLOS_ATTR_ID(12), - TRANSCEIVER_RXLOS_ATTR_ID(13), - TRANSCEIVER_RXLOS_ATTR_ID(14), - TRANSCEIVER_RXLOS_ATTR_ID(15), - TRANSCEIVER_RXLOS_ATTR_ID(16), - TRANSCEIVER_RXLOS_ATTR_ID(17), - TRANSCEIVER_RXLOS_ATTR_ID(18), - TRANSCEIVER_RXLOS_ATTR_ID(19), - TRANSCEIVER_RXLOS_ATTR_ID(20), - TRANSCEIVER_RXLOS_ATTR_ID(21), - TRANSCEIVER_RXLOS_ATTR_ID(22), - TRANSCEIVER_RXLOS_ATTR_ID(23), - TRANSCEIVER_RXLOS_ATTR_ID(24), - TRANSCEIVER_RXLOS_ATTR_ID(25), - TRANSCEIVER_RXLOS_ATTR_ID(26), - TRANSCEIVER_RXLOS_ATTR_ID(27), - TRANSCEIVER_RXLOS_ATTR_ID(28), - TRANSCEIVER_RXLOS_ATTR_ID(29), - TRANSCEIVER_RXLOS_ATTR_ID(30), - TRANSCEIVER_RXLOS_ATTR_ID(31), - TRANSCEIVER_RXLOS_ATTR_ID(32), - TRANSCEIVER_RXLOS_ATTR_ID(33), - TRANSCEIVER_RXLOS_ATTR_ID(34), - TRANSCEIVER_RXLOS_ATTR_ID(35), - TRANSCEIVER_RXLOS_ATTR_ID(36), - TRANSCEIVER_RXLOS_ATTR_ID(37), - TRANSCEIVER_RXLOS_ATTR_ID(38), - TRANSCEIVER_RXLOS_ATTR_ID(39), - TRANSCEIVER_RXLOS_ATTR_ID(40), - TRANSCEIVER_RXLOS_ATTR_ID(41), - TRANSCEIVER_RXLOS_ATTR_ID(42), - TRANSCEIVER_RXLOS_ATTR_ID(43), - TRANSCEIVER_RXLOS_ATTR_ID(44), - TRANSCEIVER_RXLOS_ATTR_ID(45), - TRANSCEIVER_RXLOS_ATTR_ID(46), - TRANSCEIVER_RXLOS_ATTR_ID(47), - TRANSCEIVER_RXLOS_ATTR_ID(48), - TRANSCEIVER_RXLOS_ATTR_ID(57), - TRANSCEIVER_RXLOS_ATTR_ID(58), - TRANSCEIVER_TXFAULT_ATTR_ID(1), - TRANSCEIVER_TXFAULT_ATTR_ID(2), - TRANSCEIVER_TXFAULT_ATTR_ID(3), - TRANSCEIVER_TXFAULT_ATTR_ID(4), - TRANSCEIVER_TXFAULT_ATTR_ID(5), - TRANSCEIVER_TXFAULT_ATTR_ID(6), - TRANSCEIVER_TXFAULT_ATTR_ID(7), - TRANSCEIVER_TXFAULT_ATTR_ID(8), - TRANSCEIVER_TXFAULT_ATTR_ID(9), - TRANSCEIVER_TXFAULT_ATTR_ID(10), - TRANSCEIVER_TXFAULT_ATTR_ID(11), - TRANSCEIVER_TXFAULT_ATTR_ID(12), - TRANSCEIVER_TXFAULT_ATTR_ID(13), - TRANSCEIVER_TXFAULT_ATTR_ID(14), - TRANSCEIVER_TXFAULT_ATTR_ID(15), - TRANSCEIVER_TXFAULT_ATTR_ID(16), - TRANSCEIVER_TXFAULT_ATTR_ID(17), - TRANSCEIVER_TXFAULT_ATTR_ID(18), - TRANSCEIVER_TXFAULT_ATTR_ID(19), - TRANSCEIVER_TXFAULT_ATTR_ID(20), - TRANSCEIVER_TXFAULT_ATTR_ID(21), - TRANSCEIVER_TXFAULT_ATTR_ID(22), - TRANSCEIVER_TXFAULT_ATTR_ID(23), - TRANSCEIVER_TXFAULT_ATTR_ID(24), - TRANSCEIVER_TXFAULT_ATTR_ID(25), - TRANSCEIVER_TXFAULT_ATTR_ID(26), - TRANSCEIVER_TXFAULT_ATTR_ID(27), - TRANSCEIVER_TXFAULT_ATTR_ID(28), - TRANSCEIVER_TXFAULT_ATTR_ID(29), - TRANSCEIVER_TXFAULT_ATTR_ID(30), - TRANSCEIVER_TXFAULT_ATTR_ID(31), - TRANSCEIVER_TXFAULT_ATTR_ID(32), - TRANSCEIVER_TXFAULT_ATTR_ID(33), - TRANSCEIVER_TXFAULT_ATTR_ID(34), - TRANSCEIVER_TXFAULT_ATTR_ID(35), - TRANSCEIVER_TXFAULT_ATTR_ID(36), - TRANSCEIVER_TXFAULT_ATTR_ID(37), - TRANSCEIVER_TXFAULT_ATTR_ID(38), - TRANSCEIVER_TXFAULT_ATTR_ID(39), - TRANSCEIVER_TXFAULT_ATTR_ID(40), - TRANSCEIVER_TXFAULT_ATTR_ID(41), - TRANSCEIVER_TXFAULT_ATTR_ID(42), - TRANSCEIVER_TXFAULT_ATTR_ID(43), - TRANSCEIVER_TXFAULT_ATTR_ID(44), - TRANSCEIVER_TXFAULT_ATTR_ID(45), - TRANSCEIVER_TXFAULT_ATTR_ID(46), - TRANSCEIVER_TXFAULT_ATTR_ID(47), - TRANSCEIVER_TXFAULT_ATTR_ID(48), - TRANSCEIVER_TXFAULT_ATTR_ID(57), - TRANSCEIVER_TXFAULT_ATTR_ID(58), -}; - -/* sysfs attributes for hwmon - */ -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_present_all(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t show_version(struct device *dev, struct device_attribute *da, - char *buf); -static int as7326_56x_cpld_read_internal(struct i2c_client *client, u8 reg); -static int as7326_56x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); - -/* transceiver attributes */ -#define DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(index) \ - static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index) -#define DECLARE_TRANSCEIVER_PRESENT_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr - -#define DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(index) \ - static SENSOR_DEVICE_ATTR(module_reset_##index, S_IRUGO | S_IWUSR, show_status, set_reset, MODULE_RESET_##index) -#define DECLARE_TRANSCEIVER_RESET_ATTR(index) &sensor_dev_attr_module_reset_##index.dev_attr.attr - -#define DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ - static SENSOR_DEVICE_ATTR(module_tx_disable_##index, S_IRUGO | S_IWUSR, show_status, set_tx_disable, MODULE_TXDISABLE_##index); \ - static SENSOR_DEVICE_ATTR(module_rx_los_##index, S_IRUGO, show_status, NULL, MODULE_RXLOS_##index); \ - static SENSOR_DEVICE_ATTR(module_tx_fault_##index, S_IRUGO, show_status, NULL, MODULE_TXFAULT_##index) -#define DECLARE_SFP_TRANSCEIVER_ATTR(index) \ - &sensor_dev_attr_module_tx_disable_##index.dev_attr.attr, \ - &sensor_dev_attr_module_rx_los_##index.dev_attr.attr, \ - &sensor_dev_attr_module_tx_fault_##index.dev_attr.attr - -static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); -static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); -/* transceiver attributes */ -static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); -static SENSOR_DEVICE_ATTR(module_rx_los_all, S_IRUGO, show_rxlos_all, NULL, MODULE_RXLOS_ALL); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(1); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(2); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(3); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(4); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(5); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(6); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(7); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(8); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(9); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(10); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(11); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(12); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(13); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(14); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(15); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(16); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(17); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(18); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(19); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(20); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(21); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(22); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(23); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(24); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(25); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(26); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(27); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(28); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(29); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(30); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(31); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(32); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(33); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(34); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(35); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(36); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(37); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(38); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(39); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(40); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(41); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(42); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(43); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(44); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(45); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(46); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(47); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(48); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(49); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(50); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(51); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(52); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(53); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(54); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(55); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(56); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(57); -DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(58); - -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(1); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(2); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(3); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(4); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(5); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(6); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(7); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(8); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(9); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(10); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(11); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(12); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(13); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(14); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(15); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(16); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(17); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(18); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(19); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(20); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(21); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(22); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(23); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(24); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(25); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(26); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(27); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(28); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(29); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(30); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(31); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(32); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(33); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(34); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(35); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(36); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(37); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(38); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(39); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(40); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(41); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(42); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(43); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(44); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(45); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(46); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(47); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(48); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(57); -DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(58); - -static struct attribute *as7326_56x_cpld3_attributes[] = { - &sensor_dev_attr_version.dev_attr.attr, - &sensor_dev_attr_access.dev_attr.attr, - NULL -}; - -static const struct attribute_group as7326_56x_cpld3_group = { - .attrs = as7326_56x_cpld3_attributes, -}; - -static struct attribute *as7326_56x_cpld2_attributes[] = { - &sensor_dev_attr_version.dev_attr.attr, - &sensor_dev_attr_access.dev_attr.attr, - /* transceiver attributes */ - &sensor_dev_attr_module_present_all.dev_attr.attr, - &sensor_dev_attr_module_rx_los_all.dev_attr.attr, - DECLARE_TRANSCEIVER_PRESENT_ATTR(1), - DECLARE_TRANSCEIVER_PRESENT_ATTR(2), - DECLARE_TRANSCEIVER_PRESENT_ATTR(3), - DECLARE_TRANSCEIVER_PRESENT_ATTR(4), - DECLARE_TRANSCEIVER_PRESENT_ATTR(5), - DECLARE_TRANSCEIVER_PRESENT_ATTR(6), - DECLARE_TRANSCEIVER_PRESENT_ATTR(7), - DECLARE_TRANSCEIVER_PRESENT_ATTR(8), - DECLARE_TRANSCEIVER_PRESENT_ATTR(9), - DECLARE_TRANSCEIVER_PRESENT_ATTR(10), - DECLARE_TRANSCEIVER_PRESENT_ATTR(11), - DECLARE_TRANSCEIVER_PRESENT_ATTR(12), - DECLARE_TRANSCEIVER_PRESENT_ATTR(13), - DECLARE_TRANSCEIVER_PRESENT_ATTR(14), - DECLARE_TRANSCEIVER_PRESENT_ATTR(15), - DECLARE_TRANSCEIVER_PRESENT_ATTR(16), - DECLARE_TRANSCEIVER_PRESENT_ATTR(17), - DECLARE_TRANSCEIVER_PRESENT_ATTR(18), - DECLARE_TRANSCEIVER_PRESENT_ATTR(19), - DECLARE_TRANSCEIVER_PRESENT_ATTR(20), - DECLARE_TRANSCEIVER_PRESENT_ATTR(21), - DECLARE_TRANSCEIVER_PRESENT_ATTR(22), - DECLARE_TRANSCEIVER_PRESENT_ATTR(23), - DECLARE_TRANSCEIVER_PRESENT_ATTR(24), - DECLARE_TRANSCEIVER_PRESENT_ATTR(25), - DECLARE_TRANSCEIVER_PRESENT_ATTR(26), - DECLARE_TRANSCEIVER_PRESENT_ATTR(27), - DECLARE_TRANSCEIVER_PRESENT_ATTR(28), - DECLARE_TRANSCEIVER_PRESENT_ATTR(29), - DECLARE_TRANSCEIVER_PRESENT_ATTR(30), - DECLARE_SFP_TRANSCEIVER_ATTR(1), - DECLARE_SFP_TRANSCEIVER_ATTR(2), - DECLARE_SFP_TRANSCEIVER_ATTR(3), - DECLARE_SFP_TRANSCEIVER_ATTR(4), - DECLARE_SFP_TRANSCEIVER_ATTR(5), - DECLARE_SFP_TRANSCEIVER_ATTR(6), - DECLARE_SFP_TRANSCEIVER_ATTR(7), - DECLARE_SFP_TRANSCEIVER_ATTR(8), - DECLARE_SFP_TRANSCEIVER_ATTR(9), - DECLARE_SFP_TRANSCEIVER_ATTR(10), - DECLARE_SFP_TRANSCEIVER_ATTR(11), - DECLARE_SFP_TRANSCEIVER_ATTR(12), - DECLARE_SFP_TRANSCEIVER_ATTR(13), - DECLARE_SFP_TRANSCEIVER_ATTR(14), - DECLARE_SFP_TRANSCEIVER_ATTR(15), - DECLARE_SFP_TRANSCEIVER_ATTR(16), - DECLARE_SFP_TRANSCEIVER_ATTR(17), - DECLARE_SFP_TRANSCEIVER_ATTR(18), - DECLARE_SFP_TRANSCEIVER_ATTR(19), - DECLARE_SFP_TRANSCEIVER_ATTR(20), - DECLARE_SFP_TRANSCEIVER_ATTR(21), - DECLARE_SFP_TRANSCEIVER_ATTR(22), - DECLARE_SFP_TRANSCEIVER_ATTR(23), - DECLARE_SFP_TRANSCEIVER_ATTR(24), - DECLARE_SFP_TRANSCEIVER_ATTR(25), - DECLARE_SFP_TRANSCEIVER_ATTR(26), - DECLARE_SFP_TRANSCEIVER_ATTR(27), - DECLARE_SFP_TRANSCEIVER_ATTR(28), - DECLARE_SFP_TRANSCEIVER_ATTR(29), - DECLARE_SFP_TRANSCEIVER_ATTR(30), - NULL -}; - -static const struct attribute_group as7326_56x_cpld2_group = { - .attrs = as7326_56x_cpld2_attributes, -}; - -static struct attribute *as7326_56x_cpld1_attributes[] = { - &sensor_dev_attr_version.dev_attr.attr, - &sensor_dev_attr_access.dev_attr.attr, - /* transceiver attributes */ - &sensor_dev_attr_module_present_all.dev_attr.attr, - &sensor_dev_attr_module_rx_los_all.dev_attr.attr, - DECLARE_TRANSCEIVER_PRESENT_ATTR(31), - DECLARE_TRANSCEIVER_PRESENT_ATTR(32), - DECLARE_TRANSCEIVER_PRESENT_ATTR(33), - DECLARE_TRANSCEIVER_PRESENT_ATTR(34), - DECLARE_TRANSCEIVER_PRESENT_ATTR(35), - DECLARE_TRANSCEIVER_PRESENT_ATTR(36), - DECLARE_TRANSCEIVER_PRESENT_ATTR(37), - DECLARE_TRANSCEIVER_PRESENT_ATTR(38), - DECLARE_TRANSCEIVER_PRESENT_ATTR(39), - DECLARE_TRANSCEIVER_PRESENT_ATTR(40), - DECLARE_TRANSCEIVER_PRESENT_ATTR(41), - DECLARE_TRANSCEIVER_PRESENT_ATTR(42), - DECLARE_TRANSCEIVER_PRESENT_ATTR(43), - DECLARE_TRANSCEIVER_PRESENT_ATTR(44), - DECLARE_TRANSCEIVER_PRESENT_ATTR(45), - DECLARE_TRANSCEIVER_PRESENT_ATTR(46), - DECLARE_TRANSCEIVER_PRESENT_ATTR(47), - DECLARE_TRANSCEIVER_PRESENT_ATTR(48), - DECLARE_TRANSCEIVER_PRESENT_ATTR(49), - DECLARE_TRANSCEIVER_PRESENT_ATTR(50), - DECLARE_TRANSCEIVER_PRESENT_ATTR(51), - DECLARE_TRANSCEIVER_PRESENT_ATTR(52), - DECLARE_TRANSCEIVER_PRESENT_ATTR(53), - DECLARE_TRANSCEIVER_PRESENT_ATTR(54), - DECLARE_TRANSCEIVER_PRESENT_ATTR(55), - DECLARE_TRANSCEIVER_PRESENT_ATTR(56), - DECLARE_TRANSCEIVER_PRESENT_ATTR(57), - DECLARE_TRANSCEIVER_PRESENT_ATTR(58), - DECLARE_SFP_TRANSCEIVER_ATTR(31), - DECLARE_SFP_TRANSCEIVER_ATTR(32), - DECLARE_SFP_TRANSCEIVER_ATTR(33), - DECLARE_SFP_TRANSCEIVER_ATTR(34), - DECLARE_SFP_TRANSCEIVER_ATTR(35), - DECLARE_SFP_TRANSCEIVER_ATTR(36), - DECLARE_SFP_TRANSCEIVER_ATTR(37), - DECLARE_SFP_TRANSCEIVER_ATTR(38), - DECLARE_SFP_TRANSCEIVER_ATTR(39), - DECLARE_SFP_TRANSCEIVER_ATTR(40), - DECLARE_SFP_TRANSCEIVER_ATTR(41), - DECLARE_SFP_TRANSCEIVER_ATTR(42), - DECLARE_SFP_TRANSCEIVER_ATTR(43), - DECLARE_SFP_TRANSCEIVER_ATTR(44), - DECLARE_SFP_TRANSCEIVER_ATTR(45), - DECLARE_SFP_TRANSCEIVER_ATTR(46), - DECLARE_SFP_TRANSCEIVER_ATTR(47), - DECLARE_SFP_TRANSCEIVER_ATTR(48), - DECLARE_SFP_TRANSCEIVER_ATTR(57), - DECLARE_SFP_TRANSCEIVER_ATTR(58), - NULL -}; - -static const struct attribute_group as7326_56x_cpld1_group = { - .attrs = as7326_56x_cpld1_attributes, -}; - -static ssize_t show_present_all(struct device *dev, struct device_attribute *da, - char *buf) -{ - int i, status; - u8 values[4] = {0}; - u8 regs[] = {0x9, 0xA, 0xB, 0x18}; - struct i2c_client *client = to_i2c_client(dev); - struct as7326_56x_cpld_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - for (i = 0; i < ARRAY_SIZE(regs); i++) { - status = as7326_56x_cpld_read_internal(client, regs[i]); - - if (status < 0) { - goto exit; - } - - values[i] = ~(u8)status; - } - - mutex_unlock(&data->update_lock); - - /* Return values 1 -> 56 in order */ - if (data->type == as7326_56x_cpld2) { - values[3] &= 0xF; - } - else { /* as7326_56x_cpld3 */ - values[3] &= 0x3; - } - - return sprintf(buf, "%.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], values[3]); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, - char *buf) -{ - int i, status; - u8 values[3] = {0}; - u8 regs[] = {0x12, 0x13, 0x14}; - struct i2c_client *client = to_i2c_client(dev); - struct as7326_56x_cpld_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - for (i = 0; i < ARRAY_SIZE(regs); i++) { - status = as7326_56x_cpld_read_internal(client, regs[i]); - - if (status < 0) { - goto exit; - } - - values[i] = (u8)status; - } - - mutex_unlock(&data->update_lock); - - /* Return values 1 -> 24 in order */ - return sprintf(buf, "%.2x %.2x %.2x\n", values[0], values[1], values[2]); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct as7326_56x_cpld_data *data = i2c_get_clientdata(client); - int status = 0; - u8 reg = 0, mask = 0, revert = 0; - - switch (attr->index) { - case MODULE_PRESENT_1 ... MODULE_PRESENT_30: - reg = 0x0f + (attr->index-MODULE_PRESENT_1)/8; - mask = 0x1 << ((attr->index - MODULE_PRESENT_1)%8); - break; - case MODULE_PRESENT_31 ... MODULE_PRESENT_48: - reg = 0x10 + (attr->index-MODULE_PRESENT_31)/8; - mask = 0x1 << ((attr->index - MODULE_PRESENT_31)%8); - break; - case MODULE_PRESENT_57 ... MODULE_PRESENT_58: - reg = 0x12; - mask = 0x1 << (( MODULE_PRESENT_58 - attr->index)+2); - break; - case MODULE_PRESENT_49 ... MODULE_PRESENT_56: /*QSFP*/ - reg = 0x13 ; - mask = 0x1 << ((attr->index - MODULE_PRESENT_49)%8); - break; - case MODULE_TXFAULT_1 ... MODULE_TXFAULT_30: - reg = 0x03 + (attr->index - MODULE_TXFAULT_1)/8; - mask = 0x1 << ((attr->index - MODULE_TXFAULT_1)%8); - break; - case MODULE_TXFAULT_31 ... MODULE_TXFAULT_48: - reg = 0x1a + (attr->index-MODULE_TXFAULT_31)/8; - mask = 0x1 << ((attr->index - MODULE_TXFAULT_31)%8); - break; - case MODULE_TXFAULT_57 ... MODULE_TXFAULT_58: - reg = 0x1c; - mask = 0x1 << (( attr->index - MODULE_TXFAULT_57)+2); - break; - case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_30: - reg = 0x07 + (attr->index - MODULE_TXDISABLE_1)/8; - mask = 0x1 << ((attr->index - MODULE_TXDISABLE_1)%8); - break; - case MODULE_TXDISABLE_31 ... MODULE_TXDISABLE_48: - reg = 0x14 + (attr->index-MODULE_TXDISABLE_31)/8; - mask = 0x1 << ((attr->index - MODULE_TXDISABLE_31)%8); - break; - case MODULE_TXDISABLE_57 ... MODULE_TXDISABLE_58: - reg = 0x16; - mask = 0x1 << ((attr->index - MODULE_TXDISABLE_57)+2); - break; - case MODULE_RXLOS_1 ... MODULE_RXLOS_30: - reg = 0x0b + (attr->index - MODULE_RXLOS_1)/8; - mask = 0x1 << ((attr->index - MODULE_RXLOS_1)%8); - break; - case MODULE_RXLOS_31 ... MODULE_RXLOS_48: - reg = 0x17 + (attr->index-MODULE_RXLOS_31)/8; - mask = 0x1 << ((attr->index - MODULE_RXLOS_31)%8); - break; - case MODULE_RXLOS_57 ... MODULE_RXLOS_58: - reg = 0x19; - mask = 0x1 << (( attr->index - MODULE_RXLOS_57)+2); - break; - default: - return 0; - } - - if (attr->index >= MODULE_PRESENT_1 && attr->index <= MODULE_PRESENT_56) { - revert = 1; - } - - mutex_lock(&data->update_lock); - status = as7326_56x_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - - return sprintf(buf, "%d\n", revert ? !(status & mask) : !!(status & mask)); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t set_tx_disable(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 as7326_56x_cpld_data *data = i2c_get_clientdata(client); - long disable; - int status; - u8 reg = 0, mask = 0; - - status = kstrtol(buf, 10, &disable); - if (status) { - return status; - } - - switch (attr->index) { - case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_30: - reg = 0x07 + (attr->index - MODULE_TXDISABLE_1)/8; - mask = 0x1 << ((attr->index - MODULE_TXDISABLE_1)%8); - break; - case MODULE_TXDISABLE_31 ... MODULE_TXDISABLE_48: - reg = 0x14 + (attr->index - MODULE_TXDISABLE_31)/8; - mask = 0x1 << ((attr->index - MODULE_TXDISABLE_31)%8); - break; - case MODULE_TXDISABLE_57 ... MODULE_TXDISABLE_58: - reg = 0x16; - mask = 0x1 << ((attr->index - MODULE_TXDISABLE_57)+2); - break; - default: - return 0; - } - - /* Read current status */ - mutex_lock(&data->update_lock); - status = as7326_56x_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - - /* Update tx_disable status */ - if (disable) { - status |= mask; - } - else { - status &= ~mask; - } - - status = as7326_56x_cpld_write_internal(client, reg, status); - if (unlikely(status < 0)) { - goto exit; - } - - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - int status; - u32 addr, val; - struct i2c_client *client = to_i2c_client(dev); - struct as7326_56x_cpld_data *data = i2c_get_clientdata(client); - - if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { - return -EINVAL; - } - - if (addr > 0xFF || val > 0xFF) { - return -EINVAL; - } - - mutex_lock(&data->update_lock); - status = as7326_56x_cpld_write_internal(client, addr, val); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static void as7326_56x_cpld_add_client(struct i2c_client *client) -{ - struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); - - if (!node) { - dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); - return; - } - - node->client = client; - - mutex_lock(&list_lock); - list_add(&node->list, &cpld_client_list); - mutex_unlock(&list_lock); -} - -static void as7326_56x_cpld_remove_client(struct i2c_client *client) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int found = 0; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client == client) { - found = 1; - break; - } - } - - if (found) { - list_del(list_node); - kfree(cpld_node); - } - - mutex_unlock(&list_lock); -} - -static ssize_t show_version(struct device *dev, struct device_attribute *attr, char *buf) -{ - int val = 0; - struct i2c_client *client = to_i2c_client(dev); - - val = i2c_smbus_read_byte_data(client, 0x1); - - if (val < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val); - } - - return sprintf(buf, "%d", val); -} - -/* - * I2C init/probing/exit functions - */ -static int as7326_56x_cpld_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); - struct as7326_56x_cpld_data *data; - int ret = -ENODEV; - const struct attribute_group *group = NULL; - - if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) - goto exit; - - data = kzalloc(sizeof(struct as7326_56x_cpld_data), GFP_KERNEL); - if (!data) { - ret = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->type = id->driver_data; - - /* Register sysfs hooks */ - switch (data->type) { - case as7326_56x_cpld1: - group = &as7326_56x_cpld1_group; - break; - case as7326_56x_cpld2: - group = &as7326_56x_cpld2_group; - break; - case as7326_56x_cpld3: - group = &as7326_56x_cpld3_group; - break; - default: - break; - } - - if (group) { - ret = sysfs_create_group(&client->dev.kobj, group); - if (ret) { - goto exit_free; - } - } - - as7326_56x_cpld_add_client(client); - return 0; - -exit_free: - kfree(data); -exit: - return ret; -} - -static int as7326_56x_cpld_remove(struct i2c_client *client) -{ - struct as7326_56x_cpld_data *data = i2c_get_clientdata(client); - const struct attribute_group *group = NULL; - - as7326_56x_cpld_remove_client(client); - - /* Remove sysfs hooks */ - switch (data->type) { - case as7326_56x_cpld1: - group = &as7326_56x_cpld1_group; - break; - case as7326_56x_cpld2: - group = &as7326_56x_cpld2_group; - break; - case as7326_56x_cpld3: - group = &as7326_56x_cpld3_group; - break; - default: - break; - } - - if (group) { - sysfs_remove_group(&client->dev.kobj, group); - } - - kfree(data); - - return 0; -} - -static int as7326_56x_cpld_read_internal(struct i2c_client *client, u8 reg) -{ - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, reg); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - return status; -} - -static int as7326_56x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value) -{ - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, reg, value); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - return status; -} - -int as7326_56x_cpld_read(unsigned short cpld_addr, u8 reg) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EPERM; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = as7326_56x_cpld_read_internal(cpld_node->client, reg); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(as7326_56x_cpld_read); - -int as7326_56x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EIO; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = as7326_56x_cpld_write_internal(cpld_node->client, reg, value); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(as7326_56x_cpld_write); - -static struct i2c_driver as7326_56x_cpld_driver = { - .driver = { - .name = "as7326_56x_cpld", - .owner = THIS_MODULE, - }, - .probe = as7326_56x_cpld_probe, - .remove = as7326_56x_cpld_remove, - .id_table = as7326_56x_cpld_id, -}; - -static int __init as7326_56x_cpld_init(void) -{ - mutex_init(&list_lock); - return i2c_add_driver(&as7326_56x_cpld_driver); -} - -static void __exit as7326_56x_cpld_exit(void) -{ - i2c_del_driver(&as7326_56x_cpld_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("Accton I2C CPLD driver"); -MODULE_LICENSE("GPL"); - -module_init(as7326_56x_cpld_init); -module_exit(as7326_56x_cpld_exit); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/ym2651y.c b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/ym2651y.c deleted file mode 120000 index f4d67640ccc3..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/ym2651y.c +++ /dev/null @@ -1 +0,0 @@ -../../common/modules/ym2651y.c \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/service/as7326-platform-monitor.service b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/service/as7326-platform-monitor.service deleted file mode 100755 index 3af4405fb493..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/service/as7326-platform-monitor.service +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=Accton AS7326-56X Platform Monitoring service -Before=pmon.service -After=sysinit.target -DefaultDependencies=no - -[Service] -ExecStartPre=/usr/local/bin/accton_as7326_util.py install -ExecStart=/usr/local/bin/accton_as7326_monitor.py -KillSignal=SIGKILL -SuccessExitStatus=SIGKILL - -# Resource Limitations -LimitCORE=infinity - -[Install] -WantedBy=multi-user.target diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/setup.py b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/setup.py deleted file mode 100755 index 77114c71285b..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/setup.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env pytho - -import os -import sys -from setuptools import setup -os.listdir - -setup( - name='as7326_56x', - version='1.0', - description='Module to initialize Accton AS7326-56X platforms', - - packages=['as7326_56x'], - package_dir={'as7326_56x': 'as7326-56x/classes'}, -) - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/utils/README b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/utils/README deleted file mode 100755 index ef0d03cf5e45..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/utils/README +++ /dev/null @@ -1,74 +0,0 @@ -Copyright (C) 2016 Accton Networks, Inc. - -This program is free software: you can redistribute it and/or modify -It under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Contents of this package: - module - Contains source code of as7326 kernel driver modules. - util - operational scripts. - -Sonic creates a docker container and run building process under it. -If user tries to built new drivers, please get into that docker and -dpkg-buildpackage for them. - -All Linux kernel code is licensed under the GPLv1. All other code is -licensed under the GPLv3. Please see the LICENSE file for copies of -both licenses. - -The code for integacting with Accton AS7326-56X has 2 parts, -kernel drivers and operational script. -The kernel drivers of peripherals are under module/ directory. -1. These drivers can be built to individual ko during dpkg-buildpackage. -2. A operational script, accton_as7326_util.py, for device initializatian. - Run "accton_as7326_util.py install" to install drivers. - -To initialize the system, run "accton_as7326_util.py install". -To clean up the drivers & devices, run "accton_as7326_util.py clean". -To dump information of sensors, run "accton_as7326_util.py show". -To dump SFP EEPROM, run "accton_as7326_util.py sff". -To set fan speed, run "accton_as7326_util.py set fan". -To enable/disable SFP emission, run "accton_as7326_util.py set sfp". -To set system LEDs' color, run "accton_as7326_util.py set led" -For more information, run "accton_as7326_util.py --help". - -==================================================================== -Besides applying accton_as7326_util.py to access peripherals, you can -access peripherals by sysfs nodes directly after the installation is run. - -System LED: - There are 5 system LEDs at the lower-left corner of front panel. - They are loc, diag, fan, ps1, and ps2. - The sysfs interface color mappings are as follows: - Brightness: - 0 => off - 1 => green - 2 => amber - 3 => red - 4 => blue - But not all colors are available for each LED. - -Fan Control: - There are 10 fans inside 6 fan modules. - All fans share 1 duty setting, ranged from 0~100. - -Thermal sensers: - 3 temperature sensors are controlled by the lm75 kernel modules. - -PSUs: - There 2 power supplies slot at the left/right side of the back. - Once if a PSU is not plugged, the status of it is shown failed. - -There are 48 SFP+ and 8 QSFP modules are equipped. -Before operating on PSU and QSFP+, please make sure it is well plugged. -Otherwise, operation is going to fail. - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/utils/accton_as7326_monitor.py b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/utils/accton_as7326_monitor.py deleted file mode 100755 index 856f194c5e53..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/utils/accton_as7326_monitor.py +++ /dev/null @@ -1,208 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# 1/10/2018: Jostar modify for as7716_32 -# 3/23/2018: Roy Lee modify for as7326_56x -# ------------------------------------------------------------------ - -try: - import os - import sys, getopt - import subprocess - import click - import imp - import logging - import logging.config - import types - import time # this is only being used as part of the example - import traceback - from tabulate import tabulate - from as7326_56x.fanutil import FanUtil - from as7326_56x.thermalutil import ThermalUtil -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - -# Deafults -VERSION = '1.0' -FUNCTION_NAME = 'accton_as7326_monitor' - -global log_file -global log_level - -# (LM75_1+ LM75_2+ LM75_3) is LM75 at i2c addresses 0x48, 0x49, and 0x4A. -# TMP = (LM75_1+ LM75_2+ LM75_3)/3 -#1. If TMP < 35, All fans run with duty 31.25%. -#2. If TMP>=35 or the temperature of any one of fan is higher than 40, -# All fans run with duty 50% -#3. If TMP >= 40 or the temperature of any one of fan is higher than 45, -# All fans run with duty 62.5%. -#4. If TMP >= 45 or the temperature of any one of fan is higher than 50, -# All fans run with duty 100%. -#5. Any one of 6 fans is fault, set duty = 100%. -#6. Direction factor. If it is B2F direction, duty + 12%. - - # MISC: - # 1.Check single LM75 before applied average. - # 2.If no matched fan speed is found from the policy, - # use FAN_DUTY_CYCLE_MIN as default speed - # Get current temperature - # 4.Decision 3: Decide new fan speed depend on fan direction/current fan speed/temperature - - - - -# Make a class we can use to capture stdout and sterr in the log -class accton_as7326_monitor(object): - # static temp var - _ori_temp = 0 - _new_perc = 0 - _ori_perc = 0 - - def __init__(self, log_file, log_level): - """Needs a logger and a logger level.""" - # set up logging to file - logging.basicConfig( - filename=log_file, - filemode='w', - level=log_level, - format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', - datefmt='%H:%M:%S' - ) - - # set up logging to console - if log_level == logging.DEBUG: - console = logging.StreamHandler() - console.setLevel(log_level) - formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') - console.setFormatter(formatter) - logging.getLogger('').addHandler(console) - - logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level) - - def manage_fans(self): - max_duty = 100 - fan_policy_f2b = { - 0: [32, 0, 105000], - 1: [50, 105000, 120000], - 2: [63, 120000, 135000], - 3: [max_duty, 135000, sys.maxsize], - } - fan_policy_b2f = { - 0: [44, 0, 105000], - 1: [63, 105000, 120000], - 2: [75, 120000, 135000], - 3: [max_duty, 135000, sys.maxsize], - } - fan_policy_single = { - 0: 40000, - 1: 45000, - 2: 50000, - } - - thermal = ThermalUtil() - fan = FanUtil() - for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1): - fan_status = fan.get_fan_status(x) - if fan_status is None: - logging.debug('INFO. SET new_perc to %d (FAN stauts is None. fan_num:%d)', max_duty, x) - return False - if fan_status is False: - logging.debug('INFO. SET new_perc to %d (FAN fault. fan_num:%d)', max_duty, x) - fan.set_fan_duty_cycle(max_duty) - return True - #logging.debug('INFO. fan_status is True (fan_num:%d)', x) - - fan_dir=fan.get_fan_dir(1) - if fan_dir == 1: - fan_policy = fan_policy_f2b - else: - fan_policy = fan_policy_b2f - - #Decide fan duty by if any of sensors > fan_policy_single. - new_duty_cycle = fan_policy[0][0] - for x in range(thermal.get_idx_thermal_start(), thermal.get_num_thermals()+1): - single_thm = thermal._get_thermal_node_val(x) - for y in range(0, len(fan_policy_single)): - if single_thm > fan_policy_single[y]: - if fan_policy[y+1][0] > new_duty_cycle: - new_duty_cycle = fan_policy[y+1][0] - logging.debug('INFO. Single thermal sensor %d with temp %d > %d , new_duty_cycle=%d', - x, single_thm, fan_policy_single[y], new_duty_cycle) - single_result = new_duty_cycle - - - #Find if current duty matched any of define duty. - #If not, set it to highest one. - cur_duty_cycle = fan.get_fan_duty_cycle() - for x in range(0, len(fan_policy)): - if cur_duty_cycle == fan_policy[x][0]: - break - if x == len(fan_policy) : - fan.set_fan_duty_cycle(fan_policy[0][0]) - cur_duty_cycle = max_duty - - #Decide fan duty by if sum of sensors falls into any of fan_policy{} - get_temp = thermal.get_thermal_temp() - new_duty_cycle = cur_duty_cycle - for x in range(0, len(fan_policy)): - y = len(fan_policy) - x -1 #checked from highest - if get_temp > fan_policy[y][1] and get_temp < fan_policy[y][2] : - new_duty_cycle= fan_policy[y][0] - logging.debug('INFO. Sum of temp %d > %d , new_duty_cycle=%d', get_temp, fan_policy[y][1], new_duty_cycle) - - sum_result = new_duty_cycle - if (sum_result>single_result): - new_duty_cycle = sum_result; - else: - new_duty_cycle = single_result - - logging.debug('INFO. Final duty_cycle=%d', new_duty_cycle) - if(new_duty_cycle != cur_duty_cycle): - fan.set_fan_duty_cycle(new_duty_cycle) - return True - -def main(argv): - log_file = '%s.log' % FUNCTION_NAME - log_level = logging.INFO - if len(sys.argv) != 1: - try: - opts, args = getopt.getopt(argv,'hdl:',['lfile=']) - except getopt.GetoptError: - print 'Usage: %s [-d] [-l ]' % sys.argv[0] - return 0 - for opt, arg in opts: - if opt == '-h': - print 'Usage: %s [-d] [-l ]' % sys.argv[0] - return 0 - elif opt in ('-d', '--debug'): - log_level = logging.DEBUG - elif opt in ('-l', '--lfile'): - log_file = arg - - monitor = accton_as7326_monitor(log_file, log_level) - - # Loop forever, doing something useful hopefully: - while True: - monitor.manage_fans() - time.sleep(10) - -if __name__ == '__main__': - main(sys.argv[1:]) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/utils/accton_as7326_util.py b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/utils/accton_as7326_util.py deleted file mode 100755 index 900bfa805a21..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/utils/accton_as7326_util.py +++ /dev/null @@ -1,577 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2016 Accton Networks, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# -# Description: -# Due to adoption of optoe drivers, sideband signals of SFPs are moved -# into cpld drivers. Add a new dict, cpld_of_module, for mapping this -# attributes to corresponding cpld nodes. -# - - - -""" -Usage: %(scriptName)s [options] command object - -options: - -h | --help : this help message - -d | --debug : run with debug mode - -f | --force : ignore error during installation or clean -command: - install : install drivers and generate related sysfs nodes - clean : uninstall drivers and remove related sysfs nodes - show : show all systen status - sff : dump SFP eeprom - set : change board setting with fan|led|sfp -""" - -import os -import commands -import sys, getopt -import logging -import re -import time -from collections import namedtuple - - - - -PROJECT_NAME = 'as7326_56x' -version = '0.1.0' -verbose = False -DEBUG = False -args = [] -ALL_DEVICE = {} -DEVICE_NO = {'led':5, 'fan':6,'thermal':4, 'psu':2, 'sfp':58} -FORCE = 0 -#logging.basicConfig(filename= PROJECT_NAME+'.log', filemode='w',level=logging.DEBUG) -#logging.basicConfig(level=logging.INFO) - - -if DEBUG == True: - print sys.argv[0] - print 'ARGV :', sys.argv[1:] - - -def main(): - global DEBUG - global args - global FORCE - - if len(sys.argv)<2: - show_help() - - options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help', - 'debug', - 'force', - ]) - if DEBUG == True: - print options - print args - print len(sys.argv) - - for opt, arg in options: - if opt in ('-h', '--help'): - show_help() - elif opt in ('-d', '--debug'): - DEBUG = True - logging.basicConfig(level=logging.INFO) - elif opt in ('-f', '--force'): - FORCE = 1 - else: - logging.info('no option') - for arg in args: - if arg == 'install': - do_install() - elif arg == 'clean': - do_uninstall() - elif arg == 'show': - device_traversal() - elif arg == 'sff': - if len(args)!=2: - show_eeprom_help() - elif int(args[1]) ==0 or int(args[1]) > DEVICE_NO['sfp']: - show_eeprom_help() - else: - show_eeprom(args[1]) - return - elif arg == 'set': - if len(args)<3: - show_set_help() - else: - set_device(args[1:]) - return - else: - show_help() - - - return 0 - -def show_help(): - print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]} - sys.exit(0) - -def show_set_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print cmd +" [led|sfp|fan]" - print " use \""+ cmd + " led 0-4 \" to set led color" - print " use \""+ cmd + " fan 0-100\" to set fan duty percetage" - print " use \""+ cmd + " sfp 1-56 {0|1}\" to set sfp# tx_disable" - sys.exit(0) - -def show_eeprom_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print " use \""+ cmd + " 1-56 \" to dump sfp# eeprom" - sys.exit(0) - -def my_log(txt): - if DEBUG == True: - print "[ROY]"+txt - return - -def log_os_system(cmd, show): - logging.info('Run :'+cmd) - status, output = commands.getstatusoutput(cmd) - my_log (cmd +"with result:" + str(status)) - my_log (" output:"+output) - if status: - logging.info('Failed :'+cmd) - if show: - print('Failed :'+cmd) - return status, output - -def driver_check(): - ret, lsmod = log_os_system("lsmod| grep accton", 0) - logging.info('mods:'+lsmod) - if len(lsmod) ==0: - return False - return True - - - -kos = [ -'modprobe i2c_dev', -'modprobe i2c_mux_pca954x force_deselect_on_exit=1', -'modprobe accton_i2c_cpld' , -'modprobe ym2651y' , -'modprobe accton_as7326_56x_fan' , -'modprobe optoe' , -'modprobe accton_as7326_56x_leds' , -'modprobe accton_as7326_56x_psu' ] - -def driver_install(): - global FORCE - status, output = log_os_system("depmod", 1) - for i in range(0,len(kos)): - status, output = log_os_system(kos[i], 1) - if status: - if FORCE == 0: - return status - return 0 - -def driver_uninstall(): - global FORCE - for i in range(0,len(kos)): - rm = kos[-(i+1)].replace("modprobe", "modprobe -rq") - rm = rm.replace("insmod", "rmmod") - lst = rm.split(" ") - if len(lst) > 3: - del(lst[3]) - rm = " ".join(lst) - status, output = log_os_system(rm, 1) - if status: - if FORCE == 0: - return status - return 0 - -led_prefix ='/sys/class/leds/accton_'+PROJECT_NAME+'_led::' -hwmon_types = {'led': ['diag','fan','loc','psu1','psu2']} -hwmon_nodes = {'led': ['brightness'] } -hwmon_prefix ={'led': led_prefix} - -i2c_prefix = '/sys/bus/i2c/devices/' -i2c_bus = {'fan': ['11-0066'] , - 'thermal': ['15-0048','15-0049', '15-004a', '15-004b'] , - 'psu': ['17-0051','13-0053'], - 'sfp': ['-0050']} -i2c_nodes = {'fan': ['present', 'front_speed_rpm', 'rear_speed_rpm'] , - 'thermal': ['hwmon/hwmon*/temp1_input'] , - 'psu': ['psu_present ', 'psu_power_good'] , - 'sfp': ['module_present_', 'module_tx_disable_']} - -sfp_map = [ - 42,41,44,43,47,45,46,50, - 48,49,51,52,53,56,55,54, - 58,57,59,60,61,63,62,64, - 66,68,65,67,69,71,72,70, - 74,73,76,75,77,79,78,80, - 81,82,84,85,83,87,88,86, #port 41~48 - 25,26,27,28,29,30,31,32, #port 49~56 QSFP - 22,23] #port 57~58 SFP+ from CPU NIF. -qsfp_start = 48 -qsfp_end = 56 - -#For sideband signals of SFP/QSFP modules. -cpld_of_module = {'12-0062': list(range(0,30)), - '18-0060': list(range(30,58)) } - - -mknod =[ -'echo pca9548 0x77 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device' , -'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-1/new_device' , -'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-24/new_device' , -'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-2/new_device' , -'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-33/new_device', -'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-34/new_device', -'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-35/new_device', -'echo pca9548 0x74 > /sys/bus/i2c/devices/i2c-36/new_device', -'echo pca9548 0x75 > /sys/bus/i2c/devices/i2c-37/new_device', -'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-38/new_device', -'echo 24c04 0x56 > /sys/bus/i2c/devices/i2c-0/new_device', - -'echo as7326_56x_fan 0x66 > /sys/bus/i2c/devices/i2c-11/new_device ', -'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-15/new_device', -'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-15/new_device', -'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-15/new_device', -'echo lm75 0x4b > /sys/bus/i2c/devices/i2c-15/new_device', -'echo as7326_56x_psu1 0x51 > /sys/bus/i2c/devices/i2c-17/new_device', -'echo ym2651 0x59 > /sys/bus/i2c/devices/i2c-17/new_device', -'echo as7326_56x_psu2 0x53 > /sys/bus/i2c/devices/i2c-13/new_device', -'echo ym2651 0x5b > /sys/bus/i2c/devices/i2c-13/new_device', -'echo as7326_56x_cpld1 0x60 > /sys/bus/i2c/devices/i2c-18/new_device', -'echo as7326_56x_cpld2 0x62 > /sys/bus/i2c/devices/i2c-12/new_device', -'echo as7326_56x_cpld3 0x64 > /sys/bus/i2c/devices/i2c-19/new_device'] - -mknod2 =[ -] - - - -def i2c_order_check(): - # This project has only 1 i2c bus. - return 0 - -def device_install(): - global FORCE - - order = i2c_order_check() - - # if 0x70 is not exist @i2c-1, use reversed bus order - if order: - for i in range(0,len(mknod2)): - #for pca954x need times to built new i2c buses - if mknod2[i].find('pca954') != -1: - time.sleep(1) - - status, output = log_os_system(mknod2[i], 1) - if status: - print output - if FORCE == 0: - return status - else: - for i in range(0,len(mknod)): - #for pca954x need times to built new i2c buses - if mknod[i].find('pca954') != -1: - time.sleep(1) - - status, output = log_os_system(mknod[i], 1) - if status: - print output - if FORCE == 0: - return status - for i in range(0,len(sfp_map)): - if i < qsfp_start or i >= qsfp_end: - status, output =log_os_system("echo optoe2 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1) - else: - status, output =log_os_system("echo optoe1 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1) - if status: - print output - if FORCE == 0: - return status - return - -def device_uninstall(): - global FORCE - - status, output =log_os_system("ls /sys/bus/i2c/devices/1-0076", 0) - if status==0: - I2C_ORDER=1 - else: - I2C_ORDER=0 - - for i in range(0,len(sfp_map)): - target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device" - status, output =log_os_system("echo 0x50 > "+ target, 1) - if status: - print output - if FORCE == 0: - return status - - if I2C_ORDER==0: - nodelist = mknod - else: - nodelist = mknod2 - - for i in range(len(nodelist)): - target = nodelist[-(i+1)] - temp = target.split() - del temp[1] - temp[-1] = temp[-1].replace('new_device', 'delete_device') - status, output = log_os_system(" ".join(temp), 1) - if status: - print output - if FORCE == 0: - return status - - return - -def system_ready(): - if driver_check() == False: - return False - if not device_exist(): - return False - return True - -def do_install(): - print "Checking system...." - if driver_check() == False: - print "No driver, installing...." - status = driver_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" drivers detected...." - if not device_exist(): - print "No device, installing...." - status = device_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" devices detected...." - return - -def do_uninstall(): - print "Checking system...." - if not device_exist(): - print PROJECT_NAME.upper() +" has no device installed...." - else: - print "Removing device...." - status = device_uninstall() - if status: - if FORCE == 0: - return status - - if driver_check()== False : - print PROJECT_NAME.upper() +" has no driver installed...." - else: - print "Removing installed driver...." - status = driver_uninstall() - if status: - if FORCE == 0: - return status - - return - -def devices_info(): - global DEVICE_NO - global ALL_DEVICE - global i2c_bus, hwmon_types - for key in DEVICE_NO: - ALL_DEVICE[key]= {} - for i in range(0,DEVICE_NO[key]): - ALL_DEVICE[key][key+str(i+1)] = [] - - for key in i2c_bus: - buses = i2c_bus[key] - nodes = i2c_nodes[key] - for i in range(0,len(buses)): - for j in range(0,len(nodes)): - if 'fan' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - elif 'sfp' == key: - for k in range(0,DEVICE_NO[key]): - for lk in cpld_of_module: - if k in cpld_of_module[lk]: - cpld_str = lk - node = key+str(k+1) - path = i2c_prefix+ lk + "/"+ nodes[j] + str(k+1) - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - else: - node = key+str(i+1) - path = i2c_prefix+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - - for key in hwmon_types: - itypes = hwmon_types[key] - nodes = hwmon_nodes[key] - for i in range(0,len(itypes)): - for j in range(0,len(nodes)): - node = key+"_"+itypes[i] - path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][ key+str(i+1)].append(path) - - #show dict all in the order - if DEBUG == True: - for i in sorted(ALL_DEVICE.keys()): - print(i+": ") - for j in sorted(ALL_DEVICE[i].keys()): - print(" "+j) - for k in (ALL_DEVICE[i][j]): - print(" "+" "+k) - return - -def show_eeprom(index): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0] - node = node.replace(node.split("/")[-1], 'eeprom') - # check if got hexdump command in current environment - ret, log = log_os_system("which hexdump", 0) - ret, log2 = log_os_system("which busybox hexdump", 0) - if len(log): - hex_cmd = 'hexdump' - elif len(log2): - hex_cmd = ' busybox hexdump' - else: - log = 'Failed : no hexdump cmd!!' - logging.info(log) - print log - return 1 - - print node + ":" - ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1) - if ret==0: - print log - else: - print "**********device no found**********" - return - -def set_device(args): - global DEVICE_NO - global ALL_DEVICE - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - - if args[0]=='led': - if int(args[1])>4: - show_set_help() - return - #print ALL_DEVICE['led'] - for i in range(0,len(ALL_DEVICE['led'])): - for k in (ALL_DEVICE['led']['led'+str(i+1)]): - ret, log = log_os_system("echo "+args[1]+" >"+k, 1) - if ret: - return ret - elif args[0]=='fan': - if int(args[1])>100: - show_set_help() - return - #print ALL_DEVICE['fan'] - #fan1~6 is all fine, all fan share same setting - node = ALL_DEVICE['fan'] ['fan1'][0] - node = node.replace(node.split("/")[-1], 'fan_duty_cycle_percentage') - ret, log = log_os_system("cat "+ node, 1) - if ret==0: - print ("Previous fan duty: " + log.strip() +"%") - ret, log = log_os_system("echo "+args[1]+" >"+node, 1) - if ret==0: - print ("Current fan duty: " + args[1] +"%") - return ret - elif args[0]=='sfp': - if int(args[1])> DEVICE_NO[args[0]] or int(args[1])==0: - show_set_help() - return - if len(args)<2: - show_set_help() - return - - if int(args[2])>1: - show_set_help() - return - - #print ALL_DEVICE[args[0]] - for i in range(0,len(ALL_DEVICE[args[0]])): - for j in ALL_DEVICE[args[0]][args[0]+str(args[1])]: - if j.find('tx_disable')!= -1: - ret, log = log_os_system("echo "+args[2]+" >"+ j, 1) - if ret: - return ret - return - -#get digits inside a string. -#Ex: 31 for "sfp31" -def get_value(input): - digit = re.findall('\d+', input) - return int(digit[0]) - -def device_traversal(): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - for i in sorted(ALL_DEVICE.keys()): - print("============================================") - print(i.upper()+": ") - print("============================================") - - for j in sorted(ALL_DEVICE[i].keys(), key=get_value): - print " "+j+":", - for k in (ALL_DEVICE[i][j]): - ret, log = log_os_system("cat "+k, 0) - func = k.split("/")[-1].strip() - func = re.sub(j+'_','',func,1) - func = re.sub(i.lower()+'_','',func,1) - if ret==0: - print func+"="+log+" ", - else: - print func+"="+"X"+" ", - print - print("----------------------------------------------------------------") - - print - return - -def device_exist(): - ret1, log = log_os_system("ls "+i2c_prefix+"*0070", 0) - ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0) - return not(ret1 or ret2) - -if __name__ == "__main__": - main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/classes/__init__.py b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/classes/__init__.py deleted file mode 100755 index e69de29bb2d1..000000000000 diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/Makefile b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/Makefile deleted file mode 100644 index d9566355b849..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -obj-m:=accton_as7712_32x_fan.o accton_as7712_32x_sfp.o leds-accton_as7712_32x.o \ - accton_as7712_32x_psu.o accton_i2c_cpld.o ym2651y.o diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_fan.c b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_fan.c deleted file mode 100644 index 3eae51cbcea7..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_fan.c +++ /dev/null @@ -1,776 +0,0 @@ -/* - * A hwmon driver for the Accton as7712 32x fan - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRVNAME "as7712_32x_fan" - -#define NUM_THERMAL_SENSORS (3) /* Get sum of this number of sensors.*/ -#define THERMAL_SENSORS_DRIVER "lm75" -#define THERMAL_SENSORS_ADDRS {0x48, 0x49, 0x4a} - -#define IN -#define OUT - -static struct as7712_32x_fan_data *as7712_32x_fan_update_device(struct device *dev); -static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t get_enable(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_enable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, char *buf); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -/* fan related data, the index should match sysfs_fan_attributes - */ -static const u8 fan_reg[] = { - 0x0F, /* fan 1-6 present status */ - 0x11, /* fan PWM(for all fan) */ - 0x12, /* front fan 1 speed(rpm) */ - 0x13, /* front fan 2 speed(rpm) */ - 0x14, /* front fan 3 speed(rpm) */ - 0x15, /* front fan 4 speed(rpm) */ - 0x16, /* front fan 5 speed(rpm) */ - 0x17, /* front fan 6 speed(rpm) */ - 0x22, /* rear fan 1 speed(rpm) */ - 0x23, /* rear fan 2 speed(rpm) */ - 0x24, /* rear fan 3 speed(rpm) */ - 0x25, /* rear fan 4 speed(rpm) */ - 0x26, /* rear fan 5 speed(rpm) */ - 0x27, /* rear fan 6 speed(rpm) */ -}; - -/* Each client has this additional data */ -struct as7712_32x_fan_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */ - u8 enable; - int system_temp; /*In unit of mini-Celsius*/ - int sensors_found; -}; - -enum fan_id { - FAN1_ID, - FAN2_ID, - FAN3_ID, - FAN4_ID, - FAN5_ID, - FAN6_ID -}; - -enum sysfs_fan_attributes { - FAN_PRESENT_REG, - FAN_DUTY_CYCLE_PERCENTAGE, /* Only one CPLD register to control duty cycle for all fans */ - FAN1_FRONT_SPEED_RPM, - FAN2_FRONT_SPEED_RPM, - FAN3_FRONT_SPEED_RPM, - FAN4_FRONT_SPEED_RPM, - FAN5_FRONT_SPEED_RPM, - FAN6_FRONT_SPEED_RPM, - FAN1_REAR_SPEED_RPM, - FAN2_REAR_SPEED_RPM, - FAN3_REAR_SPEED_RPM, - FAN4_REAR_SPEED_RPM, - FAN5_REAR_SPEED_RPM, - FAN6_REAR_SPEED_RPM, - FAN1_PRESENT, - FAN2_PRESENT, - FAN3_PRESENT, - FAN4_PRESENT, - FAN5_PRESENT, - FAN6_PRESENT, - FAN1_FAULT, - FAN2_FAULT, - FAN3_FAULT, - FAN4_FAULT, - FAN5_FAULT, - FAN6_FAULT -}; - -/* Define attributes - */ -#define DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(index, index2) \ - static SENSOR_DEVICE_ATTR(fan##index##_fault, S_IRUGO, fan_show_value, NULL, FAN##index##_FAULT);\ - static SENSOR_DEVICE_ATTR(fan##index2##_fault, S_IRUGO, fan_show_value, NULL, FAN##index##_FAULT) -#define DECLARE_FAN_FAULT_ATTR(index, index2) &sensor_dev_attr_fan##index##_fault.dev_attr.attr, \ - &sensor_dev_attr_fan##index2##_fault.dev_attr.attr - -#define DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan##index##_direction, S_IRUGO, fan_show_value, NULL, FAN##index##_DIRECTION) -#define DECLARE_FAN_DIRECTION_ATTR(index) &sensor_dev_attr_fan##index##_direction.dev_attr.attr - -#define DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE);\ - static SENSOR_DEVICE_ATTR(pwm##index, S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE);\ - static SENSOR_DEVICE_ATTR(pwm##index##_enable, S_IWUSR | S_IRUGO, get_enable, set_enable, FAN_DUTY_CYCLE_PERCENTAGE) - -#define DECLARE_FAN_DUTY_CYCLE_ATTR(index) &sensor_dev_attr_fan_duty_cycle_percentage.dev_attr.attr, \ - &sensor_dev_attr_pwm##index.dev_attr.attr, \ - &sensor_dev_attr_pwm##index##_enable.dev_attr.attr - -#define DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR() \ - static SENSOR_DEVICE_ATTR(sys_temp, S_IRUGO, get_sys_temp, NULL, FAN_DUTY_CYCLE_PERCENTAGE) - -#define DECLARE_FAN_SYSTEM_TEMP_ATTR() &sensor_dev_attr_sys_temp.dev_attr.attr - - -#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan##index##_present, S_IRUGO, fan_show_value, NULL, FAN##index##_PRESENT) -#define DECLARE_FAN_PRESENT_ATTR(index) &sensor_dev_attr_fan##index##_present.dev_attr.attr - -#define DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(index, index2) \ - static SENSOR_DEVICE_ATTR(fan##index##_front_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_FRONT_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index##_rear_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_REAR_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index##_input, S_IRUGO, fan_show_value, NULL, FAN##index##_FRONT_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index2##_input, S_IRUGO, fan_show_value, NULL, FAN##index##_REAR_SPEED_RPM) -#define DECLARE_FAN_SPEED_RPM_ATTR(index, index2) &sensor_dev_attr_fan##index##_front_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_fan##index##_rear_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_fan##index##_input.dev_attr.attr, \ - &sensor_dev_attr_fan##index2##_input.dev_attr.attr - -/* 6 fan fault attributes in this platform */ -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(1,11); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(2,12); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(3,13); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(4,14); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(5,15); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(6,16); -/* 6 fan speed(rpm) attributes in this platform */ -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(1,11); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(2,12); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(3,13); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(4,14); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(5,15); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(6,16); -/* 6 fan present attributes in this platform */ -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(1); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(2); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(3); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(4); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(5); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(6); -/* 1 fan duty cycle attribute in this platform */ -DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(1); -/* System temperature for fancontrol */ -DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR(); - -static struct attribute *as7712_32x_fan_attributes[] = { - /* fan related attributes */ - DECLARE_FAN_FAULT_ATTR(1,11), - DECLARE_FAN_FAULT_ATTR(2,12), - DECLARE_FAN_FAULT_ATTR(3,13), - DECLARE_FAN_FAULT_ATTR(4,14), - DECLARE_FAN_FAULT_ATTR(5,15), - DECLARE_FAN_FAULT_ATTR(6,16), - DECLARE_FAN_SPEED_RPM_ATTR(1,11), - DECLARE_FAN_SPEED_RPM_ATTR(2,12), - DECLARE_FAN_SPEED_RPM_ATTR(3,13), - DECLARE_FAN_SPEED_RPM_ATTR(4,14), - DECLARE_FAN_SPEED_RPM_ATTR(5,15), - DECLARE_FAN_SPEED_RPM_ATTR(6,16), - DECLARE_FAN_PRESENT_ATTR(1), - DECLARE_FAN_PRESENT_ATTR(2), - DECLARE_FAN_PRESENT_ATTR(3), - DECLARE_FAN_PRESENT_ATTR(4), - DECLARE_FAN_PRESENT_ATTR(5), - DECLARE_FAN_PRESENT_ATTR(6), - DECLARE_FAN_DUTY_CYCLE_ATTR(1), - DECLARE_FAN_SYSTEM_TEMP_ATTR(), - NULL -}; - -#define FAN_DUTY_CYCLE_REG_MASK 0xF -#define FAN_MAX_DUTY_CYCLE 100 -#define FAN_REG_VAL_TO_SPEED_RPM_STEP 100 - -static int as7712_32x_fan_read_value(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_byte_data(client, reg); -} - -static int as7712_32x_fan_write_value(struct i2c_client *client, u8 reg, u8 value) -{ - return i2c_smbus_write_byte_data(client, reg, value); -} - -/* fan utility functions - */ -static u32 reg_val_to_duty_cycle(u8 reg_val) -{ - reg_val &= FAN_DUTY_CYCLE_REG_MASK; - return ((u32)(reg_val+1) * 625 + 75)/ 100; -} - -static u8 duty_cycle_to_reg_val(u8 duty_cycle) -{ - return ((u32)duty_cycle * 100 / 625) - 1; -} - -static u32 reg_val_to_speed_rpm(u8 reg_val) -{ - return (u32)reg_val * FAN_REG_VAL_TO_SPEED_RPM_STEP; -} - -static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id) -{ - u8 mask = (1 << id); - - reg_val &= mask; - - return reg_val ? 0 : 1; -} - -static u8 is_fan_fault(struct as7712_32x_fan_data *data, enum fan_id id) -{ - u8 ret = 1; - int front_fan_index = FAN1_FRONT_SPEED_RPM + id; - int rear_fan_index = FAN1_REAR_SPEED_RPM + id; - - /* Check if the speed of front or rear fan is ZERO, - */ - if (reg_val_to_speed_rpm(data->reg_val[front_fan_index]) && - reg_val_to_speed_rpm(data->reg_val[rear_fan_index])) { - ret = 0; - } - - return ret; -} - -static ssize_t set_enable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct as7712_32x_fan_data *data = as7712_32x_fan_update_device(dev); - int error, value; - - error = kstrtoint(buf, 10, &value); - if (error) - return error; - - if (value < 0 || value > 1) - return -EINVAL; - - data->enable = value; - if (value == 0) - { - return set_duty_cycle(dev, da, buf, FAN_MAX_DUTY_CYCLE); - } - return count; -} - - -static ssize_t get_enable(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as7712_32x_fan_data *data = as7712_32x_fan_update_device(dev); - - return sprintf(buf, "%u\n", data->enable); -} -static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - int error, value; - struct i2c_client *client = to_i2c_client(dev); - - error = kstrtoint(buf, 10, &value); - if (error) - return error; - - if (value < 0) - return -EINVAL; - - value = (value > FAN_MAX_DUTY_CYCLE)? FAN_MAX_DUTY_CYCLE : value; - - as7712_32x_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */ - as7712_32x_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value)); - return count; -} - -/* Due to this struct is declared at lm75.c, it cannot be include - * under Sonic environment. I duplicate it from lm75.c. - */ -struct lm75_data { - struct i2c_client *client; - struct device *hwmon_dev; - struct thermal_zone_device *tz; - struct mutex update_lock; - u8 orig_conf; - u8 resolution; /* In bits, between 9 and 12 */ - u8 resolution_limits; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - unsigned long sample_time; /* In jiffies */ - s16 temp[3]; /* Register values, - 0 = input - 1 = max - 2 = hyst */ -}; - -/*Copied from lm75.c*/ -static inline long lm75_reg_to_mc(s16 temp, u8 resolution) -{ - return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8); -} - -/*Get hwmon_dev from i2c_client, set hwmon_dev = NULL is failed.*/ -static struct device * get_hwmon_dev( - struct i2c_client *client) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - if(data) - { - if( data->valid == 1 && data->hwmon_dev) - { - return data->hwmon_dev; - } - - } - return NULL; -} - -/* To find hwmon index by opening hwmon under that i2c address. - */ -static int find_hwmon_index_by_FileOpen( - int bus_nr, - unsigned short addr, - OUT int *index) -{ -#define MAX_HWMON_DEVICE (10) /* Find hwmon device in 0~10*/ - struct file *sfd; - char client_name[96]; - int i=0; - - do { - snprintf(client_name, sizeof(client_name), - "/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input", - bus_nr, addr, i); - - sfd = filp_open(client_name, O_RDONLY, 0); - i++; - } while( IS_ERR(sfd) && i < MAX_HWMON_DEVICE); - - if (IS_ERR(sfd)) { - pr_err("Failed to open file(%s)#%d\r\n", client_name, __LINE__); - return -ENOENT; - } - filp_close(sfd, 0); - *index = i - 1; - return 0; - -#undef MAX_HWMON_DEVICE -} - -static int get_temp_file_path( - int bus_nr, unsigned short addr, - struct device *hwmon_dev - ,char *path, int max_len) -{ - - if(hwmon_dev && strlen(dev_name(hwmon_dev))) - { - snprintf(path, max_len, - "/sys/bus/i2c/devices/%d-%04x/hwmon/%s/temp1_input", - bus_nr, addr, dev_name(hwmon_dev)); - } - else - { - int i=0; - if(find_hwmon_index_by_FileOpen( bus_nr, addr, &i)) - { - return -EIO; - } - snprintf(path, max_len, - "/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input", - bus_nr, addr, i); - } - return 0; -} - -/*File read the dev file at user space.*/ -static int read_devfile_temp1_input( - struct device *dev, - int bus_nr, - unsigned short addr, - struct device *hwmon_dev, - int *miniCelsius) -{ - struct file *sfd; - char buffer[96]; - char devfile[96]; - int rc, status; - int rdlen, value; - mm_segment_t old_fs; - - rc = 0; - get_temp_file_path(bus_nr, addr, hwmon_dev, devfile, sizeof(devfile)); - sfd = filp_open(devfile, O_RDONLY, 0); - if (IS_ERR(sfd)) { - pr_err("Failed to open file(%s)#%d\r\n", devfile, __LINE__); - return -ENOENT; - } - dev_dbg(dev, "Found device:%s\n",devfile); - - if(!(sfd->f_op) || !(sfd->f_op->read) ) { - pr_err("file %s cann't readable ?\n",devfile); - return -ENOENT; - } - - old_fs = get_fs(); - set_fs(KERNEL_DS); - rdlen = sfd->f_op->read(sfd, buffer, sizeof(buffer), &sfd->f_pos); - if (rdlen == 0) { - pr_err( "File(%s) empty!\n", devfile); - rc = -EIO; - goto exit; - } - status = sscanf(buffer, "%d", &value); - if (status != 1) { - rc = -EIO; - goto exit; - } - *miniCelsius = value; - dev_dbg(dev,"found sensors: %d @i2c %d-%04x\n", value, bus_nr, addr); - -exit: - set_fs(old_fs); - filp_close(sfd, 0); - return rc; -} - -static u8 is_lm75_data_due(struct i2c_client *client) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - if (time_after(jiffies, data->last_updated + data->sample_time)) - { - return 1; - } - return 0; -} -static int get_lm75_temp(struct i2c_client *client, int *miniCelsius) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - *miniCelsius = lm75_reg_to_mc(data->temp[0], data->resolution); - - return 0; -} - -static bool lm75_addr_mached(unsigned short addr) -{ - int i; - unsigned short addrs[] = THERMAL_SENSORS_ADDRS; - - for (i = 0; i < ARRAY_SIZE(addrs); i++) - { - if( addr == addrs[i]) - return 1; - } - return 0; -} - -static int _find_lm75_device(struct device *dev, void *data) -{ - struct device_driver *driver; - struct as7712_32x_fan_data *prv = data; - char *driver_name = THERMAL_SENSORS_DRIVER; - - driver = dev->driver; - if (driver && driver->name && - strcmp(driver->name, driver_name) == 0) - { - struct i2c_client *client; - client = to_i2c_client(dev); - if (client) - { - /*cannot use "struct i2c_adapter *adap = to_i2c_adapter(dev);"*/ - struct i2c_adapter *adap = client->adapter; - int miniCelsius = 0; - - if (! lm75_addr_mached(client->addr)) - { - return 0; - } - - if (!adap) { - return -ENXIO; - } - - /* If the data is not updated, read them from devfile - to drive them updateing data from chip.*/ - if (is_lm75_data_due(client)) - { - struct device *hwmon_dev; - - hwmon_dev = get_hwmon_dev(client); - if(0 == read_devfile_temp1_input(dev, adap->nr, - client->addr, hwmon_dev, &miniCelsius)) - { - prv->system_temp += miniCelsius; - prv->sensors_found++; - } - - } - else - { - get_lm75_temp(client, &miniCelsius); - prv->system_temp += miniCelsius; - prv->sensors_found++; - - } - } - } - return 0; -} - -/*Find all lm75 devices and return sum of temperatures.*/ -static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, - char *buf) -{ - ssize_t ret = 0; - struct as7712_32x_fan_data *data = as7712_32x_fan_update_device(dev); - - data->system_temp=0; - data->sensors_found=0; - i2c_for_each_dev(data, _find_lm75_device); - if (NUM_THERMAL_SENSORS != data->sensors_found) - { - dev_dbg(dev,"only %d of %d temps are found\n", - data->sensors_found, NUM_THERMAL_SENSORS); - data->system_temp = INT_MAX; - } - ret = sprintf(buf, "%d\n",data->system_temp); - return ret; -} - -static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as7712_32x_fan_data *data = as7712_32x_fan_update_device(dev); - ssize_t ret = 0; - - if (data->valid) { - switch (attr->index) { - case FAN_DUTY_CYCLE_PERCENTAGE: - { - u32 duty_cycle = reg_val_to_duty_cycle(data->reg_val[FAN_DUTY_CYCLE_PERCENTAGE]); - ret = sprintf(buf, "%u\n", duty_cycle); - break; - } - case FAN1_FRONT_SPEED_RPM: - case FAN2_FRONT_SPEED_RPM: - case FAN3_FRONT_SPEED_RPM: - case FAN4_FRONT_SPEED_RPM: - case FAN5_FRONT_SPEED_RPM: - case FAN6_FRONT_SPEED_RPM: - case FAN1_REAR_SPEED_RPM: - case FAN2_REAR_SPEED_RPM: - case FAN3_REAR_SPEED_RPM: - case FAN4_REAR_SPEED_RPM: - case FAN5_REAR_SPEED_RPM: - case FAN6_REAR_SPEED_RPM: - ret = sprintf(buf, "%u\n", reg_val_to_speed_rpm(data->reg_val[attr->index])); - break; - case FAN1_PRESENT: - case FAN2_PRESENT: - case FAN3_PRESENT: - case FAN4_PRESENT: - case FAN5_PRESENT: - case FAN6_PRESENT: - ret = sprintf(buf, "%d\n", - reg_val_to_is_present(data->reg_val[FAN_PRESENT_REG], - attr->index - FAN1_PRESENT)); - break; - case FAN1_FAULT: - case FAN2_FAULT: - case FAN3_FAULT: - case FAN4_FAULT: - case FAN5_FAULT: - case FAN6_FAULT: - ret = sprintf(buf, "%d\n", is_fan_fault(data, attr->index - FAN1_FAULT)); - break; - default: - break; - } - } - - return ret; -} - -static const struct attribute_group as7712_32x_fan_group = { - .attrs = as7712_32x_fan_attributes, -}; - -static struct as7712_32x_fan_data *as7712_32x_fan_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7712_32x_fan_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || - !data->valid) { - int i; - - dev_dbg(&client->dev, "Starting as7712_32x_fan update\n"); - data->valid = 0; - - /* Update fan data - */ - for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) { - int status = as7712_32x_fan_read_value(client, fan_reg[i]); - - if (status < 0) { - data->valid = 0; - mutex_unlock(&data->update_lock); - dev_dbg(&client->dev, "reg %d, err %d\n", fan_reg[i], status); - return data; - } - else { - data->reg_val[i] = status; - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -static int as7712_32x_fan_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7712_32x_fan_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7712_32x_fan_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - data->enable = 0; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7712_32x_fan_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: fan '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7712_32x_fan_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7712_32x_fan_remove(struct i2c_client *client) -{ - struct as7712_32x_fan_data *data = i2c_get_clientdata(client); - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7712_32x_fan_group); - - return 0; -} - -/* Addresses to scan */ -static const unsigned short normal_i2c[] = { 0x66, I2C_CLIENT_END }; - -static const struct i2c_device_id as7712_32x_fan_id[] = { - { "as7712_32x_fan", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7712_32x_fan_id); - -static struct i2c_driver as7712_32x_fan_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = DRVNAME, - }, - .probe = as7712_32x_fan_probe, - .remove = as7712_32x_fan_remove, - .id_table = as7712_32x_fan_id, - .address_list = normal_i2c, -}; - -static int __init as7712_32x_fan_init(void) -{ - return i2c_add_driver(&as7712_32x_fan_driver); -} - -static void __exit as7712_32x_fan_exit(void) -{ - i2c_del_driver(&as7712_32x_fan_driver); -} - -module_init(as7712_32x_fan_init); -module_exit(as7712_32x_fan_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7712_32x_fan driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_psu.c b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_psu.c deleted file mode 100644 index 233aef78e09f..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_psu.c +++ /dev/null @@ -1,288 +0,0 @@ -/* - * An hwmon driver for accton as7712_32x Power Module - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); -static int as7712_32x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x50, 0x53, I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as7712_32x_psu_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 index; /* PSU index */ - u8 status; /* Status(present/power_good) register read from CPLD */ - char model_name[9]; /* Model name, read from eeprom */ -}; - -static struct as7712_32x_psu_data *as7712_32x_psu_update_device(struct device *dev); - -enum as7712_32x_psu_sysfs_attributes { - PSU_PRESENT, - PSU_MODEL_NAME, - PSU_POWER_GOOD -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT); -static SENSOR_DEVICE_ATTR(psu_model_name, S_IRUGO, show_model_name,NULL, PSU_MODEL_NAME); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD); - -static struct attribute *as7712_32x_psu_attributes[] = { - &sensor_dev_attr_psu_present.dev_attr.attr, - &sensor_dev_attr_psu_model_name.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - NULL -}; - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as7712_32x_psu_data *data = as7712_32x_psu_update_device(dev); - u8 status = 0; - - if (attr->index == PSU_PRESENT) { - status = !(data->status >> (1-data->index) & 0x1); - } - else { /* PSU_POWER_GOOD */ - status = (data->status >> (3-data->index) & 0x1); - } - - return sprintf(buf, "%d\n", status); -} - -static ssize_t show_model_name(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as7712_32x_psu_data *data = as7712_32x_psu_update_device(dev); - - return sprintf(buf, "%s\n", data->model_name); -} - -static const struct attribute_group as7712_32x_psu_group = { - .attrs = as7712_32x_psu_attributes, -}; - -static int as7712_32x_psu_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7712_32x_psu_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7712_32x_psu_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - data->index = dev_id->driver_data; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7712_32x_psu_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7712_32x_psu_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7712_32x_psu_remove(struct i2c_client *client) -{ - struct as7712_32x_psu_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7712_32x_psu_group); - kfree(data); - - return 0; -} - -enum psu_index -{ - as7712_32x_psu1, - as7712_32x_psu2 -}; - -static const struct i2c_device_id as7712_32x_psu_id[] = { - { "as7712_32x_psu1", as7712_32x_psu1 }, - { "as7712_32x_psu2", as7712_32x_psu2 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7712_32x_psu_id); - -static struct i2c_driver as7712_32x_psu_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7712_32x_psu", - }, - .probe = as7712_32x_psu_probe, - .remove = as7712_32x_psu_remove, - .id_table = as7712_32x_psu_id, - .address_list = normal_i2c, -}; - -static int as7712_32x_psu_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = 0; - int retry_count = 5; - - while (retry_count) { - retry_count--; - - result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) { - msleep(10); - continue; - } - - if (unlikely(result != data_len)) { - result = -EIO; - msleep(10); - continue; - } - - result = 0; - break; - } - - return result; -} - -static struct as7712_32x_psu_data *as7712_32x_psu_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7712_32x_psu_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int status; - int power_good = 0; - - dev_dbg(&client->dev, "Starting as7712_32x update\n"); - - /* Read psu status */ - status = accton_i2c_cpld_read(0x60, 0x2); - - if (status < 0) { - dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); - } - else { - data->status = status; - } - - /* Read model name */ - memset(data->model_name, 0, sizeof(data->model_name)); - power_good = (data->status >> (3-data->index) & 0x1); - - if (power_good) { - status = as7712_32x_psu_read_block(client, 0x20, data->model_name, - ARRAY_SIZE(data->model_name)-1); - - if (status < 0) { - data->model_name[0] = '\0'; - dev_dbg(&client->dev, "unable to read model name from (0x%x)\n", client->addr); - } - else { - data->model_name[ARRAY_SIZE(data->model_name)-1] = '\0'; - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init as7712_32x_psu_init(void) -{ - return i2c_add_driver(&as7712_32x_psu_driver); -} - -static void __exit as7712_32x_psu_exit(void) -{ - i2c_del_driver(&as7712_32x_psu_driver); -} - -module_init(as7712_32x_psu_init); -module_exit(as7712_32x_psu_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7712_32x_psu driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_sfp.c b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_sfp.c deleted file mode 100644 index 4668f5a7f050..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_as7712_32x_sfp.c +++ /dev/null @@ -1,1171 +0,0 @@ -/* - * SFP driver for accton as7712_32x sfp - * - * Copyright (C) Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRIVER_NAME "as7712_32x_sfp" - -#define DEBUG_MODE 0 - -#if (DEBUG_MODE == 1) - #define DEBUG_PRINT(fmt, args...) \ - printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) -#else - #define DEBUG_PRINT(fmt, args...) -#endif - -#define NUM_OF_SFP_PORT 32 -#define EEPROM_NAME "sfp_eeprom" -#define EEPROM_SIZE 256 /* 256 byte eeprom */ -#define BIT_INDEX(i) (1ULL << (i)) -#define USE_I2C_BLOCK_READ 1 -#define I2C_RW_RETRY_COUNT 3 -#define I2C_RW_RETRY_INTERVAL 100 /* ms */ - -#define SFP_EEPROM_A0_I2C_ADDR (0xA0 >> 1) -#define SFP_EEPROM_A2_I2C_ADDR (0xA2 >> 1) - -#define SFF8024_PHYSICAL_DEVICE_ID_ADDR 0x0 -#define SFF8024_DEVICE_ID_SFP 0x3 -#define SFF8024_DEVICE_ID_QSFP 0xC -#define SFF8024_DEVICE_ID_QSFP_PLUS 0xD -#define SFF8024_DEVICE_ID_QSFP28 0x11 - -#define SFF8472_DIAG_MON_TYPE_ADDR 92 -#define SFF8472_DIAG_MON_TYPE_DDM_MASK 0x40 -#define SFF8472_10G_ETH_COMPLIANCE_ADDR 0x3 -#define SFF8472_10G_BASE_MASK 0xF0 - -#define SFF8436_RX_LOS_ADDR 3 -#define SFF8436_TX_FAULT_ADDR 4 -#define SFF8436_TX_DISABLE_ADDR 86 - -static ssize_t sfp_eeprom_read(struct i2c_client *, u8, u8 *,int); -static ssize_t sfp_eeprom_write(struct i2c_client *, u8 , const char *,int); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { SFP_EEPROM_A0_I2C_ADDR, SFP_EEPROM_A2_I2C_ADDR, I2C_CLIENT_END }; - -#define CPLD_PORT_TO_FRONT_PORT(port) (port+1) - -enum port_numbers { -sfp1, sfp2, sfp3, sfp4, sfp5, sfp6, sfp7, sfp8, -sfp9, sfp10, sfp11, sfp12, sfp13, sfp14, sfp15, sfp16, -sfp17, sfp18, sfp19, sfp20, sfp21, sfp22, sfp23, sfp24, -sfp25, sfp26, sfp27, sfp28, sfp29, sfp30, sfp31, sfp32 -}; - -static const struct i2c_device_id sfp_device_id[] = { -{ "sfp1", sfp1 }, { "sfp2", sfp2 }, { "sfp3", sfp3 }, { "sfp4", sfp4 }, -{ "sfp5", sfp5 }, { "sfp6", sfp6 }, { "sfp7", sfp7 }, { "sfp8", sfp8 }, -{ "sfp9", sfp9 }, { "sfp10", sfp10 }, { "sfp11", sfp11 }, { "sfp12", sfp12 }, -{ "sfp13", sfp13 }, { "sfp14", sfp14 }, { "sfp15", sfp15 }, { "sfp16", sfp16 }, -{ "sfp17", sfp17 }, { "sfp18", sfp18 }, { "sfp19", sfp19 }, { "sfp20", sfp20 }, -{ "sfp21", sfp21 }, { "sfp22", sfp22 }, { "sfp23", sfp23 }, { "sfp24", sfp24 }, -{ "sfp25", sfp25 }, { "sfp26", sfp26 }, { "sfp27", sfp27 }, { "sfp28", sfp28 }, -{ "sfp29", sfp29 }, { "sfp30", sfp30 }, { "sfp31", sfp31 }, { "sfp32", sfp32 }, -{} -}; -MODULE_DEVICE_TABLE(i2c, sfp_device_id); - -/* - * list of valid port types - * note OOM_PORT_TYPE_NOT_PRESENT to indicate no - * module is present in this port - */ -typedef enum oom_driver_port_type_e { - OOM_DRIVER_PORT_TYPE_INVALID, - OOM_DRIVER_PORT_TYPE_NOT_PRESENT, - OOM_DRIVER_PORT_TYPE_SFP, - OOM_DRIVER_PORT_TYPE_SFP_PLUS, - OOM_DRIVER_PORT_TYPE_QSFP, - OOM_DRIVER_PORT_TYPE_QSFP_PLUS, - OOM_DRIVER_PORT_TYPE_QSFP28 -} oom_driver_port_type_t; - -enum driver_type_e { - DRIVER_TYPE_SFP_MSA, - DRIVER_TYPE_SFP_DDM, - DRIVER_TYPE_QSFP -}; - -/* Each client has this additional data - */ -struct eeprom_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - struct bin_attribute bin; /* eeprom data */ -}; - -struct sfp_msa_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u64 status[2]; /* index 0 => device id - 1 => 10G Ethernet Compliance Codes - to distinguish SFP or SFP+ - 2 => DIAGNOSTIC MONITORING TYPE */ - struct eeprom_data eeprom; -}; - -struct sfp_ddm_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u64 status[3]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss */ - struct eeprom_data eeprom; -}; - -struct qsfp_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 status[3]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss */ - - u8 device_id; - struct eeprom_data eeprom; -}; - -struct sfp_port_data { - struct mutex update_lock; - enum driver_type_e driver_type; - int port; /* CPLD port index */ - oom_driver_port_type_t port_type; - u64 present; /* present status, bit0:port0, bit1:port1 and so on */ - u64 port_reset; /* reset status, bit0:port0, bit1:port1 and so on */ - - struct sfp_msa_data *msa; - struct sfp_ddm_data *ddm; - struct qsfp_data *qsfp; - - struct i2c_client *client; -}; - -enum sfp_sysfs_attributes { - PRESENT, - PRESENT_ALL, - PORT_NUMBER, - PORT_TYPE, - DDM_IMPLEMENTED, - TX_FAULT, - TX_FAULT1, - TX_FAULT2, - TX_FAULT3, - TX_FAULT4, - TX_DISABLE, - TX_DISABLE1, - TX_DISABLE2, - TX_DISABLE3, - TX_DISABLE4, - TX_DISABLE_ALL, - RX_LOS, - RX_LOS1, - RX_LOS2, - RX_LOS3, - RX_LOS4, - RX_LOS_ALL, - PORT_RESET -}; - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - return sprintf(buf, "%d\n", CPLD_PORT_TO_FRONT_PORT(data->port)); -} - -static struct sfp_port_data *sfp_update_present(struct i2c_client *client) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - int i = 0; - int status = -1; - u8 regs[] = {0x30, 0x31, 0x32, 0x33}; - - DEBUG_PRINT("Starting sfp present status update"); - mutex_lock(&data->update_lock); - - /* Read present status of port 1~32 */ - data->present = 0; - - for (i = 0; i < ARRAY_SIZE(regs); i++) { - status = accton_i2c_cpld_read(0x60, regs[i]); - - if (status < 0) { - DEBUG_PRINT("cpld(0x60) reg(0x%x) err %d", regs[i], status); - goto exit; - } - - DEBUG_PRINT("Present status = 0x%llx", data->present); - data->present |= (u64)status << (i*8); - } - - DEBUG_PRINT("Present status = 0x%llx", data->present); -exit: - mutex_unlock(&data->update_lock); - return data; -} - -static struct sfp_port_data *sfp_update_tx_rx_status(struct device *dev) -{ - return NULL; -} - -static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - return 0; -} - -static int sfp_is_port_present(struct i2c_client *client, int port) -{ - struct sfp_port_data *data = sfp_update_present(client); - return (data->present & BIT_INDEX(data->port)) ? 0 : 1; -} - -static ssize_t show_present(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 sfp_port_data *data = i2c_get_clientdata(client); - - if (PRESENT_ALL == attr->index) { - - } - - /* PRESENT */ - return sprintf(buf, "%d\n", sfp_is_port_present(client, data->port)); -} - -static struct sfp_port_data *sfp_update_port_type(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - u8 buf = 0; - int status; - - mutex_lock(&data->update_lock); - - switch (data->driver_type) { - case DRIVER_TYPE_SFP_MSA: - { - status = sfp_eeprom_read(data->client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); - if (status < 0) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - if (buf != SFF8024_DEVICE_ID_SFP) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - status = sfp_eeprom_read(data->client, SFF8472_10G_ETH_COMPLIANCE_ADDR, &buf, sizeof(buf)); - if (status < 0) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - DEBUG_PRINT("sfp port type (0x3) data = (0x%x)", buf); - data->port_type = buf & SFF8472_10G_BASE_MASK ? OOM_DRIVER_PORT_TYPE_SFP_PLUS : OOM_DRIVER_PORT_TYPE_SFP; - break; - } - case DRIVER_TYPE_QSFP: - { - status = sfp_eeprom_read(data->client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); - if (status < 0) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - DEBUG_PRINT("qsfp port type (0x0) buf = (0x%x)", buf); - switch (buf) { - case SFF8024_DEVICE_ID_QSFP: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP; - break; - case SFF8024_DEVICE_ID_QSFP_PLUS: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; - break; - case SFF8024_DEVICE_ID_QSFP28: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; - break; - default: - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - break; - } - default: - break; - } - - mutex_unlock(&data->update_lock); - return data; -} - -static ssize_t show_port_type(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - if (!sfp_is_port_present(client, data->port)) { - return sprintf(buf, "%d\n", OOM_DRIVER_PORT_TYPE_NOT_PRESENT); - } - - sfp_update_port_type(dev); - return sprintf(buf, "%d\n", data->port_type); -} - - -static struct sfp_port_data *sfp_update_port_reset(struct i2c_client *client) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - int i = 0; - int status = -1; - u8 regs[] = {0x4, 0x5, 0x6, 0x7}; - - mutex_lock(&data->update_lock); - - /* Read reset status of port 1~32 */ - data->port_reset = 0; - - for (i = 0; i < ARRAY_SIZE(regs); i++) { - status = accton_i2c_cpld_read(0x60, regs[i]); - - if (status < 0) { - DEBUG_PRINT("cpld(0x60) reg(0x%x) err %d", regs[i], status); - goto exit; - } - - DEBUG_PRINT("reset status = 0x%x", status); - data->port_reset |= (u64)status << (i*8); - } - - DEBUG_PRINT("reset status = 0x%llx", data->port_reset); -exit: - mutex_unlock(&data->update_lock); - return data; -} - -static ssize_t show_port_reset(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int is_reset = 0; - - if (!sfp_is_port_present(client, data->port)) { - return sprintf(buf, "%d\n", OOM_DRIVER_PORT_TYPE_NOT_PRESENT); - } - - sfp_update_port_reset(client); - is_reset = (data->port_reset & BIT_INDEX(data->port))? 0 : 1; - - return sprintf(buf, "%d\n", is_reset); -} - -static ssize_t sfp_set_port_reset(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - u8 cpld_reg = 0, cpld_val = 0, cpld_bit = 0; - long is_reset; - int error; - - error = kstrtol(buf, 10, &is_reset); - if (error) { - return error; - } - - mutex_lock(&data->update_lock); - - cpld_reg = 0x4 + data->port / 8; - cpld_bit = 1 << (data->port % 8); - - cpld_val = accton_i2c_cpld_read(0x60, cpld_reg); - DEBUG_PRINT("current cpld reg = 0x%x value = 0x%x", cpld_reg, cpld_val); - - /* Update reset status. CPLD defined 0 is reset state, 1 is normal state. - * is_reset: 0 is not reset. 1 is reset. - */ - if (is_reset == 0) { - data->port_reset |= BIT_INDEX(data->port); - cpld_val |= cpld_bit; - } - else { - data->port_reset &= ~BIT_INDEX(data->port); - cpld_val &= ~cpld_bit; - } - - accton_i2c_cpld_write(0x60, cpld_reg, cpld_val); - DEBUG_PRINT("write cpld reg = 0x%x value = 0x%x cpld_bit = 0x%x", cpld_reg, cpld_val,cpld_bit); - - mutex_unlock(&data->update_lock); - - return count; -} - -static struct sfp_port_data *qsfp_update_tx_rx_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int i, status = -1; - u8 buf = 0; - u8 reg[] = {SFF8436_TX_FAULT_ADDR, SFF8436_TX_DISABLE_ADDR, SFF8436_RX_LOS_ADDR}; - - if (time_before(jiffies, data->qsfp->last_updated + HZ + HZ / 2) && data->qsfp->valid) { - return data; - } - - dev_dbg(dev, "Starting sfp tx rx status update"); - mutex_lock(&data->update_lock); - data->qsfp->valid = 0; - memset(data->qsfp->status, 0, sizeof(data->qsfp->status)); - - /* Notify device to update tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(data->client, reg[i], &buf, sizeof(buf)); - if (status < 0) { - goto exit; - } - } - msleep(200); - - /* Read actual tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(data->client, reg[i], &buf, sizeof(buf)); - if (status < 0) { - goto exit; - } - - DEBUG_PRINT("qsfp reg(0x%x) status = (0x%x)", reg[i], data->qsfp->status[i]); - data->qsfp->status[i] = (buf & 0xF); - } - - data->qsfp->valid = 1; - data->qsfp->last_updated = jiffies; - mutex_unlock(&data->update_lock); - return data; - -exit: - mutex_unlock(&data->update_lock); - return NULL; -} - -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - u8 val = 0; - struct i2c_client *client = to_i2c_client(dev); - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct sfp_port_data *data = i2c_get_clientdata(client); - - if (!sfp_is_port_present(client, data->port)) { - return -ENODEV; - } - - data = qsfp_update_tx_rx_status(dev); - if (!data) { - return -EIO; - } - - switch (attr->index) { - case TX_FAULT1: - case TX_FAULT2: - case TX_FAULT3: - case TX_FAULT4: - val = (data->qsfp->status[2] & BIT_INDEX(attr->index - TX_FAULT1)) ? 1 : 0; - break; - case TX_DISABLE1: - case TX_DISABLE2: - case TX_DISABLE3: - case TX_DISABLE4: - val = (data->qsfp->status[1] & BIT_INDEX(attr->index - TX_DISABLE1)) ? 1 : 0; - break; - case TX_DISABLE_ALL: - val = ((data->qsfp->status[1] & 0xF) == 0xF) ? 1 : 0; - break; - - case RX_LOS1: - case RX_LOS2: - case RX_LOS3: - case RX_LOS4: - val = (data->qsfp->status[0] & BIT_INDEX(attr->index - RX_LOS1)) ? 1 : 0; - break; - default: - break; - } - - return sprintf(buf, "%d\n", val); -} - -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - long disable; - int result; - struct i2c_client *client = to_i2c_client(dev); - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct sfp_port_data *data; - - result = kstrtol(buf, 10, &disable); - if (result) { - return result; - } - - data = qsfp_update_tx_rx_status(dev); - if (!data) { - return -EIO; - } - - mutex_lock(&data->update_lock); - - DEBUG_PRINT ("disable:%ld %d==%d %u\r\n", disable, attr->index, TX_DISABLE_ALL, data->qsfp->status[1]); - - if (attr->index == TX_DISABLE_ALL) - { - data->qsfp->status[1] = disable? 0xF:0; - } - else - { - if (disable) { - data->qsfp->status[1] |= (1 << (attr->index - TX_DISABLE1)); - } - else { - data->qsfp->status[1] &= ~(1 << (attr->index - TX_DISABLE1)); - } - } - DEBUG_PRINT("index = (%d), status = (0x%x)", attr->index, data->qsfp->status[1]); - result = sfp_eeprom_write(client, SFF8436_TX_DISABLE_ADDR, &data->qsfp->status[1], sizeof(data->qsfp->status[1])); - mutex_unlock(&data->update_lock); - return count; -} - -static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, - char *buf) -{ - int status; - char ddm; - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - if (!sfp_is_port_present(client, data->port)) { - return -ENODEV; - } - - status = sfp_eeprom_read(data->client, SFF8472_DIAG_MON_TYPE_ADDR, &ddm, sizeof(ddm)); - if (status < 0) { - return -EIO; - } - - return sprintf(buf, "%d\n", (ddm & SFF8472_DIAG_MON_TYPE_DDM_MASK) ? 1 : 0); -} - -static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - u8 val = 0, index = 0; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct sfp_port_data *data; - - data = sfp_update_tx_rx_status(dev); - if (!data) { - return -EIO; - } - - switch (attr->index) { - case TX_FAULT: - index = 0; - break; - case TX_DISABLE: - index = 1; - break; - case RX_LOS: - index = 2; - break; - default: - break; - } - - val = (data->ddm->status[index] & BIT_INDEX(data->port)) ? 1 : 0; - return sprintf(buf, "%d\n", val); -} - -/* SFP/QSFP common attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, PRESENT); -static SENSOR_DEVICE_ATTR(sfp_port_type, S_IRUGO, show_port_type, NULL, PORT_TYPE); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, PRESENT); -static SENSOR_DEVICE_ATTR(sfp_port_reset, S_IWUSR | S_IRUGO, show_port_reset, sfp_set_port_reset, PORT_RESET); - -/* QSFP attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_rx_los1, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS1); -static SENSOR_DEVICE_ATTR(sfp_rx_los2, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS2); -static SENSOR_DEVICE_ATTR(sfp_rx_los3, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS3); -static SENSOR_DEVICE_ATTR(sfp_rx_los4, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS4); -static SENSOR_DEVICE_ATTR(sfp_tx_disable1, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE1); -static SENSOR_DEVICE_ATTR(sfp_tx_disable2, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE2); -static SENSOR_DEVICE_ATTR(sfp_tx_disable3, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE3); -static SENSOR_DEVICE_ATTR(sfp_tx_disable4, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE4); -static SENSOR_DEVICE_ATTR(sfp_tx_disable_all, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE_ALL); -static SENSOR_DEVICE_ATTR(sfp_tx_fault1, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT1); -static SENSOR_DEVICE_ATTR(sfp_tx_fault2, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT2); -static SENSOR_DEVICE_ATTR(sfp_tx_fault3, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT3); -static SENSOR_DEVICE_ATTR(sfp_tx_fault4, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT4); -static struct attribute *qsfp_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_port_type.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_port_reset.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los1.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los2.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los3.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable_all.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault4.dev_attr.attr, - NULL -}; - -/* SFP msa attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_ddm_implemented, S_IRUGO, sfp_show_ddm_implemented, NULL, DDM_IMPLEMENTED); -static struct attribute *sfp_msa_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_port_type.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_ddm_implemented.dev_attr.attr, - NULL -}; - -/* SFP ddm attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_rx_los, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS); -static SENSOR_DEVICE_ATTR(sfp_tx_disable, S_IWUSR | S_IRUGO, sfp_show_tx_rx_status, sfp_set_tx_disable, TX_DISABLE); -static SENSOR_DEVICE_ATTR(sfp_tx_fault, S_IRUGO, sfp_show_tx_rx_status, NULL, TX_FAULT); -static struct attribute *sfp_ddm_attributes[] = { - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - NULL -}; - -static ssize_t sfp_eeprom_write(struct i2c_client *client, u8 command, const char *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int result, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - result = i2c_smbus_write_i2c_block_data(client, command, data_len, data); - if (result < 0) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(result < 0)) { - return result; - } - - return data_len; -#else - int result, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - result = i2c_smbus_write_byte_data(client, command, *data); - if (result < 0) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(result < 0)) { - return result; - } - - return 1; -#endif - - -} - - -static ssize_t sfp_port_write(struct sfp_port_data *data, - const char *buf, loff_t off, size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) { - return count; - } - - /* - * Write data to chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_write(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; -} - - -static ssize_t sfp_bin_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - struct sfp_port_data *data; - DEBUG_PRINT("offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - return sfp_port_write(data, buf, off, count); -} - -static ssize_t sfp_eeprom_read(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int result, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - if (result < 0) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(result < 0)) - goto abort; - if (unlikely(result != data_len)) { - result = -EIO; - goto abort; - } - - //result = data_len; - -abort: - return result; -#else - int result, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - result = i2c_smbus_read_byte_data(client, command); - if (result < 0) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(result < 0)) { - dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, result); - goto abort; - } - - *data = (u8)result; - result = 1; - -abort: - return result; -#endif -} - -static ssize_t sfp_port_read(struct sfp_port_data *data, - char *buf, loff_t off, size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) { - DEBUG_PRINT("Count = 0, return"); - return count; - } - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_read(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; - -} - -static ssize_t sfp_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - struct sfp_port_data *data; - DEBUG_PRINT("offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - return sfp_port_read(data, buf, off, count); -} - -static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom) -{ - int err; - - sysfs_bin_attr_init(eeprom); - eeprom->attr.name = EEPROM_NAME; - eeprom->attr.mode = S_IWUSR | S_IRUGO; - eeprom->read = sfp_bin_read; - eeprom->write = sfp_bin_write; - eeprom->size = EEPROM_SIZE; - - /* Create eeprom file */ - err = sysfs_create_bin_file(kobj, eeprom); - if (err) { - return err; - } - - return 0; -} - -static int sfp_sysfs_eeprom_cleanup(struct kobject *kobj, struct bin_attribute *eeprom) -{ - sysfs_remove_bin_file(kobj, eeprom); - return 0; -} - -static const struct attribute_group sfp_msa_group = { - .attrs = sfp_msa_attributes, -}; - -static int sfp_i2c_check_functionality(struct i2c_client *client) -{ -#if USE_I2C_BLOCK_READ - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK); -#else - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA); -#endif -} - -static int sfp_msa_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct sfp_msa_data **data) -{ - int status; - struct sfp_msa_data *msa; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - msa = kzalloc(sizeof(struct sfp_msa_data), GFP_KERNEL); - if (!msa) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &sfp_msa_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &msa->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = msa; - dev_info(&client->dev, "sfp msa '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); -exit_free: - kfree(msa); -exit: - - return status; -} - -static const struct attribute_group sfp_ddm_group = { - .attrs = sfp_ddm_attributes, -}; - -static int sfp_ddm_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct sfp_ddm_data **data) -{ - int status; - struct sfp_ddm_data *ddm; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - ddm = kzalloc(sizeof(struct sfp_ddm_data), GFP_KERNEL); - if (!ddm) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &sfp_ddm_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &ddm->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = ddm; - dev_info(&client->dev, "sfp ddm '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); -exit_free: - kfree(ddm); -exit: - - return status; -} - -static const struct attribute_group qsfp_group = { - .attrs = qsfp_attributes, -}; - -static int qsfp_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct qsfp_data **data) -{ - int status; - struct qsfp_data *qsfp; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - qsfp = kzalloc(sizeof(struct qsfp_data), GFP_KERNEL); - if (!qsfp) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &qsfp_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin); - if (status) { - goto exit_remove; - } - - /* Bring QSFPs out of reset - as6712_32x_i2c_cpld_write(0x62, 0x4, 0xFF); - as6712_32x_i2c_cpld_write(0x62, 0x5, 0xFF); - as6712_32x_i2c_cpld_write(0x64, 0x4, 0xFF); - as6712_32x_i2c_cpld_write(0x64, 0x5, 0xFF);*/ - - *data = qsfp; - dev_info(&client->dev, "qsfp '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &qsfp_group); -exit_free: - kfree(qsfp); -exit: - - return status; -} - -static int sfp_device_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct sfp_port_data *data = NULL; - - data = kzalloc(sizeof(struct sfp_port_data), GFP_KERNEL); - if (!data) { - return -ENOMEM; - } - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - data->client = client; - - if (client->addr != SFP_EEPROM_A0_I2C_ADDR) { - return -ENODEV; - } - - data->driver_type = DRIVER_TYPE_QSFP; - return qsfp_probe(client, dev_id, &data->qsfp); -} - -static int sfp_msa_remove(struct i2c_client *client, struct sfp_msa_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); - kfree(data); - return 0; -} - -static int sfp_ddm_remove(struct i2c_client *client, struct sfp_ddm_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); - kfree(data); - return 0; -} - -static int qfp_remove(struct i2c_client *client, struct qsfp_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &qsfp_group); - kfree(data); - return 0; -} - -static int sfp_device_remove(struct i2c_client *client) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - - switch (data->driver_type) { - case DRIVER_TYPE_SFP_MSA: - return sfp_msa_remove(client, data->msa); - case DRIVER_TYPE_SFP_DDM: - return sfp_ddm_remove(client, data->ddm); - case DRIVER_TYPE_QSFP: - return qfp_remove(client, data->qsfp); - } - - return 0; -} - -static struct i2c_driver sfp_driver = { - .driver = { - .name = DRIVER_NAME, - }, - .probe = sfp_device_probe, - .remove = sfp_device_remove, - .id_table = sfp_device_id, - .address_list = normal_i2c, -}; - -static int __init sfp_init(void) -{ - return i2c_add_driver(&sfp_driver); -} - -static void __exit sfp_exit(void) -{ - i2c_del_driver(&sfp_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as7712_32x_sfp driver"); -MODULE_LICENSE("GPL"); - -module_init(sfp_init); -module_exit(sfp_exit); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_i2c_cpld.c b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_i2c_cpld.c deleted file mode 120000 index 39c0826d16fd..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_i2c_cpld.c +++ /dev/null @@ -1 +0,0 @@ -../../common/modules/accton_i2c_cpld.c \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_pmbus_3y.c b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_pmbus_3y.c deleted file mode 120000 index 7504a0556e18..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/accton_pmbus_3y.c +++ /dev/null @@ -1 +0,0 @@ -../../common/modules/accton_pmbus_3y.c \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/leds-accton_as7712_32x.c b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/leds-accton_as7712_32x.c deleted file mode 100644 index 5e1a9282db0e..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/leds-accton_as7712_32x.c +++ /dev/null @@ -1,690 +0,0 @@ -/* - * A LED driver for the accton_as7712_32x_led - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/*#define DEBUG*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -extern int accton_i2c_cpld_read (unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -extern void led_classdev_unregister(struct led_classdev *led_cdev); -extern int led_classdev_register(struct device *parent, struct led_classdev *led_cdev); -extern void led_classdev_resume(struct led_classdev *led_cdev); -extern void led_classdev_suspend(struct led_classdev *led_cdev); - -#define DRVNAME "accton_as7712_32x_led" -#define ENABLE_PORT_LED 1 - -struct accton_as7712_32x_led_data { - struct platform_device *pdev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[1]; /* only 1 register*/ -}; - -static struct accton_as7712_32x_led_data *ledctl = NULL; - -/* LED related data - */ - -#define LED_CNTRLER_I2C_ADDRESS (0x60) - -#define LED_TYPE_DIAG_REG_MASK (0x3) -#define LED_MODE_DIAG_GREEN_VALUE (0x02) -#define LED_MODE_DIAG_RED_VALUE (0x01) -#define LED_MODE_DIAG_AMBER_VALUE (0x00) /*It's yellow actually. Green+Red=Yellow*/ -#define LED_MODE_DIAG_OFF_VALUE (0x03) - -#define LED_TYPE_LOC_REG_MASK (0x80) -#define LED_MODE_LOC_ON_VALUE (0) -#define LED_MODE_LOC_OFF_VALUE (0x80) - -#if (ENABLE_PORT_LED == 1) -#define LED_TYPE_PORT_LED(port) \ - LED_TYPE_PORT##port##_LED0, \ - LED_TYPE_PORT##port##_LED1, \ - LED_TYPE_PORT##port##_LED2, \ - LED_TYPE_PORT##port##_LED3 -#endif - -enum led_type { - LED_TYPE_DIAG, - LED_TYPE_LOC, - LED_TYPE_FAN, - LED_TYPE_PSU1, - LED_TYPE_PSU2, -#if (ENABLE_PORT_LED == 1) - LED_TYPE_PORT_LED(0), - LED_TYPE_PORT_LED(1), - LED_TYPE_PORT_LED(2), - LED_TYPE_PORT_LED(3), - LED_TYPE_PORT_LED(4), - LED_TYPE_PORT_LED(5), - LED_TYPE_PORT_LED(6), - LED_TYPE_PORT_LED(7), - LED_TYPE_PORT_LED(8), - LED_TYPE_PORT_LED(9), - LED_TYPE_PORT_LED(10), - LED_TYPE_PORT_LED(11), - LED_TYPE_PORT_LED(12), - LED_TYPE_PORT_LED(13), - LED_TYPE_PORT_LED(14), - LED_TYPE_PORT_LED(15), - LED_TYPE_PORT_LED(16), - LED_TYPE_PORT_LED(17), - LED_TYPE_PORT_LED(18), - LED_TYPE_PORT_LED(19), - LED_TYPE_PORT_LED(20), - LED_TYPE_PORT_LED(21), - LED_TYPE_PORT_LED(22), - LED_TYPE_PORT_LED(23), - LED_TYPE_PORT_LED(24), - LED_TYPE_PORT_LED(25), - LED_TYPE_PORT_LED(26), - LED_TYPE_PORT_LED(27), - LED_TYPE_PORT_LED(28), - LED_TYPE_PORT_LED(29), - LED_TYPE_PORT_LED(30), - LED_TYPE_PORT_LED(31), -#endif -}; - -struct led_reg { - u32 types; - u8 reg_addr; -}; - -static const struct led_reg led_reg_map[] = { - {(1<update_lock); - - if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2) - || !ledctl->valid) { - int i; - - dev_dbg(&ledctl->pdev->dev, "Starting accton_as7712_32x_led update\n"); - - /* Update LED data - */ - for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { - int status = accton_as7712_32x_led_read_value(led_reg_map[i].reg_addr); - - if (status < 0) { - ledctl->valid = 0; - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg_map[i].reg_addr, status); - goto exit; - } - else - { - ledctl->reg_val[i] = status; - } - } - - ledctl->last_updated = jiffies; - ledctl->valid = 1; - } - -exit: - mutex_unlock(&ledctl->update_lock); -} - -static void accton_as7712_32x_led_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode, - enum led_type type) -{ - int reg_val; - u8 reg ; - mutex_lock(&ledctl->update_lock); - - if( !accton_getLedReg(type, ®)) - { - dev_dbg(&ledctl->pdev->dev, "Not match item for %d.\n", type); - } - - reg_val = accton_as7712_32x_led_read_value(reg); - - if (reg_val < 0) { - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val); - goto exit; - } - reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val); - accton_as7712_32x_led_write_value(reg, reg_val); - - /* to prevent the slow-update issue */ - ledctl->valid = 0; - -exit: - mutex_unlock(&ledctl->update_lock); -} - - -static void accton_as7712_32x_led_diag_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as7712_32x_led_set(led_cdev, led_light_mode, LED_TYPE_DIAG); -} - -static enum led_brightness accton_as7712_32x_led_diag_get(struct led_classdev *cdev) -{ - accton_as7712_32x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); -} - -static void accton_as7712_32x_led_loc_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - accton_as7712_32x_led_set(led_cdev, led_light_mode, LED_TYPE_LOC); -} - -static enum led_brightness accton_as7712_32x_led_loc_get(struct led_classdev *cdev) -{ - accton_as7712_32x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); -} - -static void accton_as7712_32x_led_auto_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ -} - -static enum led_brightness accton_as7712_32x_led_auto_get(struct led_classdev *cdev) -{ - return LED_MODE_AUTO; -} - -#if (ENABLE_PORT_LED == 1) -#define PORT_LED_COLOR_MASK (0x7 << 2) -#define PORT_LED_COLOR1_REG_VAL (0x0 << 2) -#define PORT_LED_COLOR2_REG_VAL (0x1 << 2) -#define PORT_LED_COLOR3_REG_VAL (0x2 << 2) -#define PORT_LED_COLOR4_REG_VAL (0x3 << 2) -#define PORT_LED_COLOR5_REG_VAL (0x4 << 2) -#define PORT_LED_COLOR6_REG_VAL (0x5 << 2) -#define PORT_LED_COLOR7_REG_VAL (0x6 << 2) -#define PORT_LED_COLOR8_REG_VAL (0x7 << 2) - -static int accton_as7712_32x_port_led_read_value(unsigned short cpld_addr, u8 reg) -{ - return accton_i2c_cpld_read(cpld_addr, reg); -} - -static int accton_as7712_32x_port_led_write_value(unsigned short cpld_addr, u8 reg, u8 value) -{ - return accton_i2c_cpld_write(cpld_addr, reg, value); -} - -static int port_led_mode_to_cpld_val(int mode) -{ - u8 color = 0; - u8 blinking = 0; - u8 on = 1 << 0; - - switch (mode) { - case LED_MODE_WHITE_BLINKING: blinking = 1 << 1; /* fall through */ - case LED_MODE_WHITE: color = 0x0 << 2; - break; - case LED_MODE_YELLOW_BLINKING: blinking = 1 << 1; /* fall through */ - case LED_MODE_YELLOW: color = 0x1 << 2; - break; - case LED_MODE_ORANGE_BLINKING: blinking = 1 << 1; /* fall through */ - case LED_MODE_ORANGE: color = 0x2 << 2; - break; - case LED_MODE_PURPLE_BLINKING: blinking = 1 << 1; /* fall through */ - case LED_MODE_PURPLE: color = 0x3 << 2; - break; - case LED_MODE_CYAN_BLINKING: blinking = 1 << 1; /* fall through */ - case LED_MODE_CYAN: color = 0x4 << 2; - break; - case LED_MODE_RED_BLINKING: blinking = 1 << 1; /* fall through */ - case LED_MODE_RED: color = 0x5 << 2; - break; - case LED_MODE_GREEN_BLINKING: blinking = 1 << 1; /* fall through */ - case LED_MODE_GREEN: color = 0x6 << 2; - break; - case LED_MODE_BLUE_BLINKING: blinking = 1 << 1; /* fall through */ - case LED_MODE_BLUE: color = 0x7 << 2; - break; - case LED_MODE_OFF: on = 0 << 0; - break; - default: - return -EINVAL; - } - - return (color | blinking | on); -} - -static int cpld_val_to_port_led_mode(uint8_t value) -{ - int on = (value & 0x1); - int blinking = (value & 0x2); - int color = (value & PORT_LED_COLOR_MASK) ; - - if (!on) { - return LED_MODE_OFF; - } - - switch (color) { - case PORT_LED_COLOR1_REG_VAL: - return blinking ? LED_MODE_WHITE_BLINKING : LED_MODE_WHITE; - case PORT_LED_COLOR2_REG_VAL: - return blinking ? LED_MODE_YELLOW_BLINKING : LED_MODE_YELLOW; - case PORT_LED_COLOR3_REG_VAL: - return blinking ? LED_MODE_ORANGE_BLINKING : LED_MODE_ORANGE; - case PORT_LED_COLOR4_REG_VAL: - return blinking ? LED_MODE_PURPLE_BLINKING : LED_MODE_PURPLE; - case PORT_LED_COLOR5_REG_VAL: - return blinking ? LED_MODE_CYAN_BLINKING : LED_MODE_CYAN; - case PORT_LED_COLOR6_REG_VAL: - return blinking ? LED_MODE_RED_BLINKING : LED_MODE_RED; - case PORT_LED_COLOR7_REG_VAL: - return blinking ? LED_MODE_GREEN_BLINKING : LED_MODE_GREEN; - case PORT_LED_COLOR8_REG_VAL: - return blinking ? LED_MODE_BLUE_BLINKING : LED_MODE_BLUE; - default: - return -EINVAL;; - } -} - - -static void accton_as7712_32x_port_led_set(struct led_classdev *cdev, - enum led_brightness led_light_mode) -{ - unsigned int port, lid; - unsigned short cpld_addr; - u8 reg, value; - sscanf(cdev->name, "accton_as7712_32x_led::port%u_led%u", &port, &lid); - - if (port > 32 || lid > 4) { - dev_dbg(&ledctl->pdev->dev, "Port(%u), Led_id(%u) not match\n", port, lid); - return; - } - - cpld_addr = (port < 16) ? 0x64 : 0x62; - reg = (0x50 + (port % 16) * 4 + lid); - value = port_led_mode_to_cpld_val(led_light_mode); - - if (value < 0) { - dev_dbg(&ledctl->pdev->dev, "Unknow port led mode(%d)\n", led_light_mode); - return; - } - - accton_as7712_32x_port_led_write_value(cpld_addr, reg, value); -} - -static enum led_brightness accton_as7712_32x_port_led_get(struct led_classdev *cdev) -{ - unsigned int port, lid; - unsigned short cpld_addr; - u8 reg, value; - sscanf(cdev->name, "accton_as7712_32x_led::port%u_led%u", &port, &lid); - - if (port > 32 || lid > 4) { - dev_dbg(&ledctl->pdev->dev, "Port(%u), Led_id(%u) not match\n", port, lid); - return -EINVAL; - } - - cpld_addr = (port < 16) ? 0x64 : 0x62; - reg = (0x50 + (port % 16) * 4 + lid); - value = accton_as7712_32x_port_led_read_value(cpld_addr, reg); - - if (value < 0) { - dev_dbg(&ledctl->pdev->dev, "Unable to read reg value from cpld(0x%x), reg(0x%x)\n", cpld_addr, reg); - return value; - } - - return cpld_val_to_port_led_mode(value); -} - -#define _PORT_LED_CLASSDEV(port, lid) \ - [LED_TYPE_PORT##port##_LED##lid] = { \ - .name = "accton_as7712_32x_led::port"#port"_led"#lid,\ - .default_trigger = "unused", \ - .brightness_set = accton_as7712_32x_port_led_set, \ - .brightness_get = accton_as7712_32x_port_led_get, \ - .max_brightness = LED_MODE_CYAN_BLINKING, \ - } - -#define PORT_LED_CLASSDEV(port) \ - _PORT_LED_CLASSDEV(port, 0),\ - _PORT_LED_CLASSDEV(port, 1),\ - _PORT_LED_CLASSDEV(port, 2),\ - _PORT_LED_CLASSDEV(port, 3) -#endif - -static struct led_classdev accton_as7712_32x_leds[] = { - [LED_TYPE_DIAG] = { - .name = "accton_as7712_32x_led::diag", - .default_trigger = "unused", - .brightness_set = accton_as7712_32x_led_diag_set, - .brightness_get = accton_as7712_32x_led_diag_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_RED, - }, - [LED_TYPE_LOC] = { - .name = "accton_as7712_32x_led::loc", - .default_trigger = "unused", - .brightness_set = accton_as7712_32x_led_loc_set, - .brightness_get = accton_as7712_32x_led_loc_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_BLUE, - }, - [LED_TYPE_FAN] = { - .name = "accton_as7712_32x_led::fan", - .default_trigger = "unused", - .brightness_set = accton_as7712_32x_led_auto_set, - .brightness_get = accton_as7712_32x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_PSU1] = { - .name = "accton_as7712_32x_led::psu1", - .default_trigger = "unused", - .brightness_set = accton_as7712_32x_led_auto_set, - .brightness_get = accton_as7712_32x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_PSU2] = { - .name = "accton_as7712_32x_led::psu2", - .default_trigger = "unused", - .brightness_set = accton_as7712_32x_led_auto_set, - .brightness_get = accton_as7712_32x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, -#if (ENABLE_PORT_LED == 1) - PORT_LED_CLASSDEV(0), - PORT_LED_CLASSDEV(1), - PORT_LED_CLASSDEV(2), - PORT_LED_CLASSDEV(3), - PORT_LED_CLASSDEV(4), - PORT_LED_CLASSDEV(5), - PORT_LED_CLASSDEV(6), - PORT_LED_CLASSDEV(7), - PORT_LED_CLASSDEV(8), - PORT_LED_CLASSDEV(9), - PORT_LED_CLASSDEV(10), - PORT_LED_CLASSDEV(11), - PORT_LED_CLASSDEV(12), - PORT_LED_CLASSDEV(13), - PORT_LED_CLASSDEV(14), - PORT_LED_CLASSDEV(15), - PORT_LED_CLASSDEV(16), - PORT_LED_CLASSDEV(17), - PORT_LED_CLASSDEV(18), - PORT_LED_CLASSDEV(19), - PORT_LED_CLASSDEV(20), - PORT_LED_CLASSDEV(21), - PORT_LED_CLASSDEV(22), - PORT_LED_CLASSDEV(23), - PORT_LED_CLASSDEV(24), - PORT_LED_CLASSDEV(25), - PORT_LED_CLASSDEV(26), - PORT_LED_CLASSDEV(27), - PORT_LED_CLASSDEV(28), - PORT_LED_CLASSDEV(29), - PORT_LED_CLASSDEV(30), - PORT_LED_CLASSDEV(31), -#endif -}; - -static int accton_as7712_32x_led_suspend(struct platform_device *dev, - pm_message_t state) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(accton_as7712_32x_leds); i++) { - led_classdev_suspend(&accton_as7712_32x_leds[i]); - } - - return 0; -} - -static int accton_as7712_32x_led_resume(struct platform_device *dev) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(accton_as7712_32x_leds); i++) { - led_classdev_resume(&accton_as7712_32x_leds[i]); - } - - return 0; -} - -static int accton_as7712_32x_led_probe(struct platform_device *pdev) -{ - int ret, i; - - for (i = 0; i < ARRAY_SIZE(accton_as7712_32x_leds); i++) { - ret = led_classdev_register(&pdev->dev, &accton_as7712_32x_leds[i]); - - if (ret < 0) - break; - } - - /* Check if all LEDs were successfully registered */ - if (i != ARRAY_SIZE(accton_as7712_32x_leds)){ - int j; - - /* only unregister the LEDs that were successfully registered */ - for (j = 0; j < i; j++) { - led_classdev_unregister(&accton_as7712_32x_leds[i]); - } - } - - return ret; -} - -static int accton_as7712_32x_led_remove(struct platform_device *pdev) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(accton_as7712_32x_leds); i++) { - led_classdev_unregister(&accton_as7712_32x_leds[i]); - } - - return 0; -} - -static struct platform_driver accton_as7712_32x_led_driver = { - .probe = accton_as7712_32x_led_probe, - .remove = accton_as7712_32x_led_remove, - .suspend = accton_as7712_32x_led_suspend, - .resume = accton_as7712_32x_led_resume, - .driver = { - .name = DRVNAME, - .owner = THIS_MODULE, - }, -}; - -static int __init accton_as7712_32x_led_init(void) -{ - int ret; - - ret = platform_driver_register(&accton_as7712_32x_led_driver); - if (ret < 0) { - goto exit; - } - - ledctl = kzalloc(sizeof(struct accton_as7712_32x_led_data), GFP_KERNEL); - if (!ledctl) { - ret = -ENOMEM; - platform_driver_unregister(&accton_as7712_32x_led_driver); - goto exit; - } - - mutex_init(&ledctl->update_lock); - - ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); - if (IS_ERR(ledctl->pdev)) { - ret = PTR_ERR(ledctl->pdev); - platform_driver_unregister(&accton_as7712_32x_led_driver); - kfree(ledctl); - goto exit; - } - -exit: - return ret; -} - -static void __exit accton_as7712_32x_led_exit(void) -{ - platform_device_unregister(ledctl->pdev); - platform_driver_unregister(&accton_as7712_32x_led_driver); - kfree(ledctl); -} - -module_init(accton_as7712_32x_led_init); -module_exit(accton_as7712_32x_led_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton_as7712_32x_led driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/pmbus.h b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/pmbus.h deleted file mode 120000 index b0e1a57107fd..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/pmbus.h +++ /dev/null @@ -1 +0,0 @@ -../../common/modules/pmbus.h \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/ym2651y.c b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/ym2651y.c deleted file mode 120000 index f4d67640ccc3..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/modules/ym2651y.c +++ /dev/null @@ -1 +0,0 @@ -../../common/modules/ym2651y.c \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/service/as7712-platform-init.service b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/service/as7712-platform-init.service deleted file mode 100755 index d5d25b6cde04..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/service/as7712-platform-init.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Accton AS7712-32X Platform initialization service -Before=pmon.service -DefaultDependencies=no - -[Service] -Type=oneshot -ExecStart=/usr/local/bin/accton_as7712_util.py install -ExecStop=/usr/local/bin/accton_as7712_util.py clean -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/setup.py b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/setup.py deleted file mode 100755 index 09c763c84f01..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/setup.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -from setuptools import setup -os.listdir - -setup( - name='as7712_32x', - version='1.0', - description='Module to initialize Accton AS7712-32X platforms', - - packages=['as7712_32x'], - package_dir={'as7712_32x': 'as7712-32x/classes'}, -) - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/utils/README b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/utils/README deleted file mode 100755 index 0b9fc1633999..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/utils/README +++ /dev/null @@ -1,60 +0,0 @@ -Copyright (C) 2016 Accton Networks, Inc. - -This program is free software: you can redistribute it and/or modify -It under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -To initialize the system, run "accton_as7712_util.py install". -To clean up the drivers & devices, run "accton_as7712_util.py clean". -To dump information of sensors, run "accton_as7712_util.py show". -To dump SFP EEPROM, run "accton_as7712_util.py sff". -To set fan speed, run "accton_as7712_util.py set fan". -To enable/disable SFP emission, run "accton_as7712_util.py set sfp". -To set system LEDs' color, run "accton_as7712_util.py set led" -For more information, run "accton_as7712_util.py --help". - -==================================================================== -Besides applying accton_as7712_util.py to access peripherals, you can -access peripherals by sysfs nodes directly after the installation is run. - -LED controls can be found under /sys/class/leds. The sysfs interface -color mappings are as follows: -Brightness: - 0 => off - 1 => green - 2 => amber - 3 => red - 4 => blue - -There are 5 system LEDs, loc, diag, fan, ps1, and ps2. -They are lit automatically by CPLD, but the loc and diag. -The loc led has only 1 color, blue. -The diag one has 3 colors: red, amber, and green. - -Fan controls can be found in /sys/bus/i2c/devices/2-0066. -There are 12 fans inside 6 fan modules. -All fans share 1 duty setting, ranged from 0~100. - -Three temperature sensors are controlled by the lm75 kernel modules. -They should already be visible under /sys/bus/i2c/drivers/lm75/. - -Two power supplies are controlled by the CPLD. -Here provide their status under -/sys/bus/i2c/devices/10-0050 and /sys/bus/i2c/devices/11-0053. - -There are 32 QSFP+ modules are equipped. -Apply "accton_as7712_util.py show" to get their status. -Apply "accton_as7712_util.py set sfp" to turn on/off light transmission. -Apply "accton_as7712_util.py sff" to dump EEPROM information. -Before operating on that QSFP+, please make sure it is well plugged. -Otherwise, operation is going to fail. - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/utils/accton_as7712_util.py b/platform/broadcom/sonic-platform-modules-accton/as7712-32x/utils/accton_as7712_util.py deleted file mode 100755 index c8b755b85b69..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7712-32x/utils/accton_as7712_util.py +++ /dev/null @@ -1,569 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2016 Accton Networks, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" -Usage: %(scriptName)s [options] command object - -options: - -h | --help : this help message - -d | --debug : run with debug mode - -f | --force : ignore error during installation or clean -command: - install : install drivers and generate related sysfs nodes - clean : uninstall drivers and remove related sysfs nodes - show : show all systen status - sff : dump SFP eeprom - set : change board setting with fan|led|sfp -""" - -import os -import commands -import sys, getopt -import logging -import re -import time -from collections import namedtuple - - - - -PROJECT_NAME = 'as7712_32x' -version = '0.1.0' -verbose = False -DEBUG = False -args = [] -ALL_DEVICE = {} -DEVICE_NO = {'led':5, 'fan':6,'thermal':4, 'psu':2, 'sfp':32} -FORCE = 0 -#logging.basicConfig(filename= PROJECT_NAME+'.log', filemode='w',level=logging.DEBUG) -#logging.basicConfig(level=logging.INFO) - - -if DEBUG == True: - print sys.argv[0] - print 'ARGV :', sys.argv[1:] - - -def main(): - global DEBUG - global args - global FORCE - - if len(sys.argv)<2: - show_help() - - options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help', - 'debug', - 'force', - ]) - if DEBUG == True: - print options - print args - print len(sys.argv) - - for opt, arg in options: - if opt in ('-h', '--help'): - show_help() - elif opt in ('-d', '--debug'): - DEBUG = True - logging.basicConfig(level=logging.INFO) - elif opt in ('-f', '--force'): - FORCE = 1 - else: - logging.info('no option') - for arg in args: - if arg == 'install': - do_install() - elif arg == 'clean': - do_uninstall() - elif arg == 'show': - device_traversal() - elif arg == 'sff': - if len(args)!=2: - show_eeprom_help() - elif int(args[1]) ==0 or int(args[1]) > DEVICE_NO['sfp']: - show_eeprom_help() - else: - show_eeprom(args[1]) - return - elif arg == 'set': - if len(args)<3: - show_set_help() - else: - set_device(args[1:]) - return - else: - show_help() - - - return 0 - -def show_help(): - print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]} - sys.exit(0) - -def show_set_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print cmd +" [led|sfp|fan]" - print " use \""+ cmd + " led 0-4 \" to set led color" - print " use \""+ cmd + " fan 0-100\" to set fan duty percetage" - print " use \""+ cmd + " sfp 1-32 {0|1}\" to set sfp# tx_disable" - sys.exit(0) - -def show_eeprom_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print " use \""+ cmd + " 1-32 \" to dump sfp# eeprom" - sys.exit(0) - -def my_log(txt): - if DEBUG == True: - print "[ROY]"+txt - return - -def log_os_system(cmd, show): - logging.info('Run :'+cmd) - status, output = commands.getstatusoutput(cmd) - my_log (cmd +"with result:" + str(status)) - my_log (" output:"+output) - if status: - logging.info('Failed :'+cmd) - if show: - print('Failed :'+cmd) - return status, output - -def driver_check(): - ret, lsmod = log_os_system("lsmod| grep accton", 0) - logging.info('mods:'+lsmod) - if len(lsmod) ==0: - return False - return True - - - -kos = [ -'modprobe i2c_dev', -'modprobe i2c_mux_pca954x force_deselect_on_exit=1', -'modprobe accton_i2c_cpld' , -'modprobe ym2651y' , -'modprobe accton_as7712_32x_fan' , -'modprobe optoe' , -'modprobe leds-accton_as7712_32x' , -'modprobe accton_as7712_32x_psu' ] - -def driver_install(): - global FORCE - status, output = log_os_system("depmod", 1) - for i in range(0,len(kos)): - status, output = log_os_system(kos[i], 1) - if status: - if FORCE == 0: - return status - return 0 - -def driver_uninstall(): - global FORCE - for i in range(0,len(kos)): - rm = kos[-(i+1)].replace("modprobe", "modprobe -rq") - rm = rm.replace("insmod", "rmmod") - status, output = log_os_system(rm, 1) - if status: - if FORCE == 0: - return status - return 0 - -led_prefix ='/sys/class/leds/accton_'+PROJECT_NAME+'_led::' -hwmon_types = {'led': ['diag','fan','loc','psu1','psu2']} -hwmon_nodes = {'led': ['brightness'] } -hwmon_prefix ={'led': led_prefix} - -i2c_prefix = '/sys/bus/i2c/devices/' -i2c_bus = {'fan': ['2-0066'] , - 'thermal': ['3-0048','3-0049', '3-004a', '3-004b'] , - 'psu': ['10-0050','11-0053'], - 'sfp': ['-0050']} -i2c_nodes = {'fan': ['present', 'front_speed_rpm', 'rear_speed_rpm'] , - 'thermal': ['hwmon/hwmon*/temp1_input'] , - 'psu': ['psu_present ', 'psu_power_good'] , - 'sfp': ['module_present', 'sfp_tx_disable_all']} - -sfp_map = [22,23,24,25,27,26,29,28, - 18,19,20,21,30,31,32,33, - 34,35,36,37,46,47,48,49, - 38,39,40,41,42,43,44,45] -mknod =[ -'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-1/new_device' , -'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-1/new_device' , -'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-1/new_device' , -'echo pca9548 0x74 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x75 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-1/new_device', - -'echo as7712_32x_fan 0x66 > /sys/bus/i2c/devices/i2c-2/new_device ', -'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-3/new_device', -'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-3/new_device', -'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-3/new_device', -'echo lm75 0x4b > /sys/bus/i2c/devices/i2c-3/new_device', -'echo as7712_32x_psu1 0x53 > /sys/bus/i2c/devices/i2c-11/new_device', -'echo ym2651 0x5b > /sys/bus/i2c/devices/i2c-11/new_device', -'echo as7712_32x_psu2 0x50 > /sys/bus/i2c/devices/i2c-10/new_device', -'echo ym2651 0x58 > /sys/bus/i2c/devices/i2c-10/new_device', -'echo cpld_as7712 0x60 > /sys/bus/i2c/devices/i2c-4/new_device', -'echo cpld_plain 0x62 > /sys/bus/i2c/devices/i2c-5/new_device', -'echo cpld_plain 0x64 > /sys/bus/i2c/devices/i2c-6/new_device'] - -mknod2 =[ -'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-0/new_device' , -'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-0/new_device' , -'echo pca9548 0X73 > /sys/bus/i2c/devices/i2c-0/new_device' , -'echo pca9548 0x74 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo pca9548 0x75 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-0/new_device', - -'echo as7712_32x_fan 0x66 > /sys/bus/i2c/devices/i2c-2/new_device ', -'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-3/new_device', -'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-3/new_device', -'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-3/new_device', -'echo lm75 0x4b > /sys/bus/i2c/devices/i2c-3/new_device', -'echo as7712_32x_psu1 0x53 > /sys/bus/i2c/devices/i2c-11/new_device', -'echo ym2651 0x5b > /sys/bus/i2c/devices/i2c-11/new_device', -'echo as7712_32x_psu2 0x50 > /sys/bus/i2c/devices/i2c-10/new_device', -'echo ym2651 0x58 > /sys/bus/i2c/devices/i2c-10/new_device', -'echo cpld_as7712 0x60 > /sys/bus/i2c/devices/i2c-4/new_device', -'echo cpld_plain 0x62 > /sys/bus/i2c/devices/i2c-5/new_device', -'echo cpld_plain 0x64 > /sys/bus/i2c/devices/i2c-6/new_device'] - - -def i2c_order_check(): - # i2c bus 0 and 1 might be installed in different order. - # Here check if 0x76 is exist @ i2c-0 - tmp = "echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-0/new_device" - status, output = log_os_system(tmp, 0) - if not device_exist(): - order = 1 - else: - order = 0 - tmp = "echo 0x76 > /sys/bus/i2c/devices/i2c-0/delete_device" - status, output = log_os_system(tmp, 0) - return order - -def device_install(): - global FORCE - - order = i2c_order_check() - - # if 0x76 is not exist @i2c-0, use reversed bus order - if order: - for i in range(0,len(mknod2)): - #for pca954x need times to built new i2c buses - if mknod2[i].find('pca954') != -1: - time.sleep(1) - - status, output = log_os_system(mknod2[i], 1) - if status: - print output - if FORCE == 0: - return status - else: - for i in range(0,len(mknod)): - #for pca954x need times to built new i2c buses - if mknod[i].find('pca954') != -1: - time.sleep(1) - - status, output = log_os_system(mknod[i], 1) - if status: - print output - if FORCE == 0: - return status - for i in range(0,len(sfp_map)): - status, output =log_os_system("echo optoe1 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1) - if status: - print output - if FORCE == 0: - return status - return - -def device_uninstall(): - global FORCE - - status, output =log_os_system("ls /sys/bus/i2c/devices/1-0076", 0) - if status==0: - I2C_ORDER=1 - else: - I2C_ORDER=0 - - for i in range(0,len(sfp_map)): - target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device" - status, output =log_os_system("echo 0x50 > "+ target, 1) - if status: - print output - if FORCE == 0: - return status - - if I2C_ORDER==0: - nodelist = mknod - else: - nodelist = mknod2 - - for i in range(len(nodelist)): - target = nodelist[-(i+1)] - temp = target.split() - del temp[1] - temp[-1] = temp[-1].replace('new_device', 'delete_device') - status, output = log_os_system(" ".join(temp), 1) - if status: - print output - if FORCE == 0: - return status - - return - -def system_ready(): - if driver_check() == False: - return False - if not device_exist(): - return False - return True - -def do_install(): - print "Checking system...." - if driver_check() == False: - print "No driver, installing...." - status = driver_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" drivers detected...." - if not device_exist(): - print "No device, installing...." - status = device_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" devices detected...." - return - -def do_uninstall(): - print "Checking system...." - if not device_exist(): - print PROJECT_NAME.upper() +" has no device installed...." - else: - print "Removing device...." - status = device_uninstall() - if status: - if FORCE == 0: - return status - - if driver_check()== False : - print PROJECT_NAME.upper() +" has no driver installed...." - else: - print "Removing installed driver...." - status = driver_uninstall() - if status: - if FORCE == 0: - return status - - return - -def devices_info(): - global DEVICE_NO - global ALL_DEVICE - global i2c_bus, hwmon_types - for key in DEVICE_NO: - ALL_DEVICE[key]= {} - for i in range(0,DEVICE_NO[key]): - ALL_DEVICE[key][key+str(i+1)] = [] - - for key in i2c_bus: - buses = i2c_bus[key] - nodes = i2c_nodes[key] - for i in range(0,len(buses)): - for j in range(0,len(nodes)): - if 'fan' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - elif 'sfp' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ str(sfp_map[k])+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - else: - node = key+str(i+1) - path = i2c_prefix+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - - for key in hwmon_types: - itypes = hwmon_types[key] - nodes = hwmon_nodes[key] - for i in range(0,len(itypes)): - for j in range(0,len(nodes)): - node = key+"_"+itypes[i] - path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][ key+str(i+1)].append(path) - - #show dict all in the order - if DEBUG == True: - for i in sorted(ALL_DEVICE.keys()): - print(i+": ") - for j in sorted(ALL_DEVICE[i].keys()): - print(" "+j) - for k in (ALL_DEVICE[i][j]): - print(" "+" "+k) - return - -def show_eeprom(index): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0] - node = node.replace(node.split("/")[-1], 'sfp_eeprom') - # check if got hexdump command in current environment - ret, log = log_os_system("which hexdump", 0) - ret, log2 = log_os_system("which busybox hexdump", 0) - if len(log): - hex_cmd = 'hexdump' - elif len(log2): - hex_cmd = ' busybox hexdump' - else: - log = 'Failed : no hexdump cmd!!' - logging.info(log) - print log - return 1 - - print node + ":" - ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1) - if ret==0: - print log - else: - print "**********device no found**********" - return - -def set_device(args): - global DEVICE_NO - global ALL_DEVICE - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - - if args[0]=='led': - if int(args[1])>4: - show_set_help() - return - #print ALL_DEVICE['led'] - for i in range(0,len(ALL_DEVICE['led'])): - for k in (ALL_DEVICE['led']['led'+str(i+1)]): - ret, log = log_os_system("echo "+args[1]+" >"+k, 1) - if ret: - return ret - elif args[0]=='fan': - if int(args[1])>100: - show_set_help() - return - #print ALL_DEVICE['fan'] - #fan1~6 is all fine, all fan share same setting - node = ALL_DEVICE['fan'] ['fan1'][0] - node = node.replace(node.split("/")[-1], 'fan_duty_cycle_percentage') - ret, log = log_os_system("cat "+ node, 1) - if ret==0: - print ("Previous fan duty: " + log.strip() +"%") - ret, log = log_os_system("echo "+args[1]+" >"+node, 1) - if ret==0: - print ("Current fan duty: " + args[1] +"%") - return ret - elif args[0]=='sfp': - if int(args[1])> DEVICE_NO[args[0]] or int(args[1])==0: - show_set_help() - return - if len(args)<2: - show_set_help() - return - - if int(args[2])>1: - show_set_help() - return - - #print ALL_DEVICE[args[0]] - for i in range(0,len(ALL_DEVICE[args[0]])): - for j in ALL_DEVICE[args[0]][args[0]+str(args[1])]: - if j.find('tx_disable')!= -1: - ret, log = log_os_system("echo "+args[2]+" >"+ j, 1) - if ret: - return ret - - return - -#get digits inside a string. -#Ex: 31 for "sfp31" -def get_value(input): - digit = re.findall('\d+', input) - return int(digit[0]) - -def device_traversal(): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - for i in sorted(ALL_DEVICE.keys()): - print("============================================") - print(i.upper()+": ") - print("============================================") - - for j in sorted(ALL_DEVICE[i].keys(), key=get_value): - print " "+j+":", - for k in (ALL_DEVICE[i][j]): - ret, log = log_os_system("cat "+k, 0) - func = k.split("/")[-1].strip() - func = re.sub(j+'_','',func,1) - func = re.sub(i.lower()+'_','',func,1) - if ret==0: - print func+"="+log+" ", - else: - print func+"="+"X"+" ", - print - print("----------------------------------------------------------------") - - - print - return - -def device_exist(): - ret1, log = log_os_system("ls "+i2c_prefix+"*0076", 0) - ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0) - return not(ret1 or ret2) - -if __name__ == "__main__": - main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/classes/__init__.py b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/classes/__init__.py deleted file mode 100755 index e69de29bb2d1..000000000000 diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/classes/fanutil.py b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/classes/fanutil.py deleted file mode 100755 index 9a69f6e1d537..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/classes/fanutil.py +++ /dev/null @@ -1,254 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# 1/10/2018: Jostar modify for as7716_32 -# ------------------------------------------------------------------ - -try: - import time - import logging - from collections import namedtuple -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - - -class FanUtil(object): - """Platform-specific FanUtil class""" - - FAN_NUM_ON_MAIN_BROAD = 6 - FAN_NUM_1_IDX = 1 - FAN_NUM_2_IDX = 2 - FAN_NUM_3_IDX = 3 - FAN_NUM_4_IDX = 4 - FAN_NUM_5_IDX = 5 - FAN_NUM_6_IDX = 6 - - FAN_NODE_NUM_OF_MAP = 2 - FAN_NODE_FAULT_IDX_OF_MAP = 1 - #FAN_NODE_SPEED_IDX_OF_MAP = 2 - FAN_NODE_DIR_IDX_OF_MAP = 2 - #FAN_NODE_DUTY_IDX_OF_MAP = 4 - #FANR_NODE_FAULT_IDX_OF_MAP = 5 - - #BASE_VAL_PATH = '/sys/devices/platform/as5712_54x_fan/{0}' - BASE_VAL_PATH = '/sys/bus/i2c/devices/9-0066/{0}' - FAN_DUTY_PATH = '/sys/bus/i2c/devices/9-0066/fan_duty_cycle_percentage' - - #logfile = '' - #loglevel = logging.INFO - - """ Dictionary where - key1 = fan id index (integer) starting from 1 - key2 = fan node index (interger) starting from 1 - value = path to fan device file (string) """ - _fan_to_device_path_mapping = {} - -#fan1_direction -#fan1_fault -#fan1_present - - #(FAN_NUM_2_IDX, FAN_NODE_DUTY_IDX_OF_MAP): 'fan2_duty_cycle_percentage', - _fan_to_device_node_mapping = { - (FAN_NUM_1_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan1_fault', - (FAN_NUM_1_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan1_direction', - - (FAN_NUM_2_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan2_fault', - (FAN_NUM_2_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan2_direction', - - (FAN_NUM_3_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan3_fault', - (FAN_NUM_3_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan3_direction', - - (FAN_NUM_4_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan4_fault', - (FAN_NUM_4_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan4_direction', - - (FAN_NUM_5_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan5_fault', - (FAN_NUM_5_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan5_direction', - - (FAN_NUM_6_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan6_fault', - (FAN_NUM_6_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan6_direction', - } - - def _get_fan_to_device_node(self, fan_num, node_num): - return self._fan_to_device_node_mapping[(fan_num, node_num)] - - def _get_fan_node_val(self, fan_num, node_num): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num:%d', fan_num) - return None - - if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: - logging.debug('GET. Parameter error. node_num:%d', node_num) - return None - - device_path = self.get_fan_to_device_path(fan_num, node_num) - - try: - val_file = open(device_path, 'r') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - content = val_file.readline().rstrip() - - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return int(content) - - def _set_fan_node_val(self, fan_num, node_num, val): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num:%d', fan_num) - return None - - if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: - logging.debug('GET. Parameter error. node_num:%d', node_num) - return None - - content = str(val) - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - device_path = self.get_fan_to_device_path(fan_num, node_num) - try: - val_file = open(device_path, 'w') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - val_file.write(content) - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return True - - def __init__(self): - fan_path = self.BASE_VAL_PATH - - for fan_num in range(self.FAN_NUM_1_IDX, self.FAN_NUM_ON_MAIN_BROAD+1): - for node_num in range(self.FAN_NODE_FAULT_IDX_OF_MAP, self.FAN_NODE_NUM_OF_MAP+1): - self._fan_to_device_path_mapping[(fan_num, node_num)] = fan_path.format( - self._fan_to_device_node_mapping[(fan_num, node_num)]) - - def get_num_fans(self): - return self.FAN_NUM_ON_MAIN_BROAD - - def get_idx_fan_start(self): - return self.FAN_NUM_1_IDX - - def get_num_nodes(self): - return self.FAN_NODE_NUM_OF_MAP - - def get_idx_node_start(self): - return self.FAN_NODE_FAULT_IDX_OF_MAP - - def get_size_node_map(self): - return len(self._fan_to_device_node_mapping) - - def get_size_path_map(self): - return len(self._fan_to_device_path_mapping) - - def get_fan_to_device_path(self, fan_num, node_num): - return self._fan_to_device_path_mapping[(fan_num, node_num)] - - def get_fan_fault(self, fan_num): - return self._get_fan_node_val(fan_num, self.FAN_NODE_FAULT_IDX_OF_MAP) - - #def get_fan_speed(self, fan_num): - # return self._get_fan_node_val(fan_num, self.FAN_NODE_SPEED_IDX_OF_MAP) - - def get_fan_dir(self, fan_num): - return self._get_fan_node_val(fan_num, self.FAN_NODE_DIR_IDX_OF_MAP) - - def get_fan_duty_cycle(self): - #duty_path = self.FAN_DUTY_PATH - try: - val_file = open(self.FAN_DUTY_PATH) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - return False - - content = val_file.readline().rstrip() - val_file.close() - - return int(content) - #self._get_fan_node_val(fan_num, self.FAN_NODE_DUTY_IDX_OF_MAP) -#static u32 reg_val_to_duty_cycle(u8 reg_val) -#{ -# reg_val &= FAN_DUTY_CYCLE_REG_MASK; -# return ((u32)(reg_val+1) * 625 + 75)/ 100; -#} -# - def set_fan_duty_cycle(self, val): - - try: - fan_file = open(self.FAN_DUTY_PATH, 'r+') - except IOError as e: - print "Error: unable to open file: %s" % str(e) - return False - #val = ((val + 1 ) * 625 +75 ) / 100 - fan_file.write(str(val)) - fan_file.close() - return True - - #def get_fanr_fault(self, fan_num): - # return self._get_fan_node_val(fan_num, self.FANR_NODE_FAULT_IDX_OF_MAP) - - def get_fanr_speed(self, fan_num): - return self._get_fan_node_val(fan_num, self.FANR_NODE_SPEED_IDX_OF_MAP) - - def get_fan_status(self, fan_num): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num, %d', fan_num) - return None - - if self.get_fan_fault(fan_num) is not None and self.get_fan_fault(fan_num) > 0: - logging.debug('GET. FAN fault. fan_num, %d', fan_num) - return False - - #if self.get_fanr_fault(fan_num) is not None and self.get_fanr_fault(fan_num) > 0: - # logging.debug('GET. FANR fault. fan_num, %d', fan_num) - # return False - - return True - -#def main(): -# fan = FanUtil() -# -# print 'get_size_node_map : %d' % fan.get_size_node_map() -# print 'get_size_path_map : %d' % fan.get_size_path_map() -# for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1): -# for y in range(fan.get_idx_node_start(), fan.get_num_nodes()+1): -# print fan.get_fan_to_device_path(x, y) -# -#if __name__ == '__main__': -# main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/classes/thermalutil.py b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/classes/thermalutil.py deleted file mode 100755 index 50d8c85d94ca..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/classes/thermalutil.py +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# 1/10/2018:Jostar modify for as7716_32x -# ------------------------------------------------------------------ - -try: - import time - import logging - import glob - from collections import namedtuple -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - - -class ThermalUtil(object): - """Platform-specific ThermalUtil class""" - - THERMAL_NUM_ON_MAIN_BROAD = 3 - THERMAL_NUM_1_IDX = 1 # 1_ON_MAIN_BROAD - THERMAL_NUM_2_IDX = 2 # 2_ON_MAIN_BROAD - THERMAL_NUM_3_IDX = 3 # 3_ON_MAIN_BROAD - - BASE_VAL_PATH = '/sys/bus/i2c/devices/{0}-00{1}/hwmon/hwmon*/temp1_input' - - """ Dictionary where - key1 = thermal id index (integer) starting from 1 - value = path to fan device file (string) """ - _thermal_to_device_path_mapping = {} - - _thermal_to_device_node_mapping = { - THERMAL_NUM_1_IDX: ['10', '48'], - THERMAL_NUM_2_IDX: ['10', '49'], - THERMAL_NUM_3_IDX: ['10', '4a'], - } - - def __init__(self): - thermal_path = self.BASE_VAL_PATH - - for x in range(self.THERMAL_NUM_1_IDX, self.THERMAL_NUM_ON_MAIN_BROAD+1): - self._thermal_to_device_path_mapping[x] = thermal_path.format( - self._thermal_to_device_node_mapping[x][0], - self._thermal_to_device_node_mapping[x][1]) - - def _get_thermal_node_val(self, thermal_num): - if thermal_num < self.THERMAL_NUM_1_IDX or thermal_num > self.THERMAL_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. thermal_num, %d', thermal_num) - return None - - device_path = self.get_thermal_to_device_path(thermal_num) - for filename in glob.glob(device_path): - try: - val_file = open(filename, 'r') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - content = val_file.readline().rstrip() - - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return int(content) - - - def get_num_thermals(self): - return self.THERMAL_NUM_ON_MAIN_BROAD - - def get_idx_thermal_start(self): - return self.THERMAL_NUM_1_IDX - - def get_size_node_map(self): - return len(self._thermal_to_device_node_mapping) - - def get_size_path_map(self): - return len(self._thermal_to_device_path_mapping) - - def get_thermal_to_device_path(self, thermal_num): - return self._thermal_to_device_path_mapping[thermal_num] - - def get_thermal_1_val(self): - return self._get_thermal_node_val(self.THERMAL_NUM_1_IDX) - - def get_thermal_2_val(self): - return self._get_thermal_node_val(self.THERMAL_NUM_2_IDX) - def get_thermal_temp(self): - return (self._get_thermal_node_val(self.THERMAL_NUM_1_IDX) + self._get_thermal_node_val(self.THERMAL_NUM_2_IDX) +self._get_thermal_node_val(self.THERMAL_NUM_3_IDX)) - -#def main(): -# thermal = ThermalUtil() -# -# print 'get_size_node_map : %d' % thermal.get_size_node_map() -# print 'get_size_path_map : %d' % thermal.get_size_path_map() -# for x in range(thermal.get_idx_thermal_start(), thermal.get_num_thermals()+1): -# print thermal.get_thermal_to_device_path(x) -# -#if __name__ == '__main__': -# main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/Makefile b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/Makefile deleted file mode 100755 index 4c0942afb97e..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -ifneq ($(KERNELRELEASE),) -obj-m:= accton_as7716_32x_cpld1.o accton_as7716_32x_fan.o \ - accton_as7716_32x_leds.o accton_as7716_32x_psu.o cpr_4011_4mxx.o ym2651y.o \ - optoe.o accton_i2c_cpld.o - -else -ifeq (,$(KERNEL_SRC)) -#$(error KERNEL_SRC is not defined) -KVERSION := $(shell uname -r) -KERNEL_DIR = /usr/src/linux-headers-$(KVERSION)/ -KERNELDIR:=$(KERNEL_DIR) -#export KERNELDIR:=${PWD}/../../../../../src/sonic-linux-kernel/linux-3.16.43/ -else -KERNELDIR:=$(KERNEL_SRC) -endif -PWD:=$(shell pwd) -default: - $(MAKE) -C $(KERNELDIR) M=$(PWD) modules -clean: - rm -rf *.o *.mod.o *.mod.o *.ko .*cmd .tmp_versions Module.markers Module.symvers modules.order -endif diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_cpld1.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_cpld1.c deleted file mode 100755 index cbab013f5860..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_cpld1.c +++ /dev/null @@ -1,781 +0,0 @@ -/* - * A hwmon driver for the as7716_32x_cpld - * - * Copyright (C) 2013 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static LIST_HEAD(cpld_client_list); -static struct mutex list_lock; - -struct cpld_client_node { - struct i2c_client *client; - struct list_head list; -}; - -#define I2C_RW_RETRY_COUNT 10 -#define I2C_RW_RETRY_INTERVAL 60 /* ms */ - -static ssize_t show_present(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_present_all(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t show_version(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t get_mode_reset(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t set_mode_reset(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); - -static int as7716_32x_cpld_read_internal(struct i2c_client *client, u8 reg); -static int as7716_32x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); - -struct as7716_32x_cpld_data { - struct device *hwmon_dev; - struct mutex update_lock; -}; - -/* Addresses scanned for as7716_32x_cpld - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index -#define TRANSCEIVER_RESET_ATTR_ID(index) MODULE_RESET_##index - -enum as7716_32x_cpld_sysfs_attributes { - CPLD_VERSION, - ACCESS, - MODULE_PRESENT_ALL, - /* transceiver attributes */ - TRANSCEIVER_PRESENT_ATTR_ID(1), - TRANSCEIVER_PRESENT_ATTR_ID(2), - TRANSCEIVER_PRESENT_ATTR_ID(3), - TRANSCEIVER_PRESENT_ATTR_ID(4), - TRANSCEIVER_PRESENT_ATTR_ID(5), - TRANSCEIVER_PRESENT_ATTR_ID(6), - TRANSCEIVER_PRESENT_ATTR_ID(7), - TRANSCEIVER_PRESENT_ATTR_ID(8), - TRANSCEIVER_PRESENT_ATTR_ID(9), - TRANSCEIVER_PRESENT_ATTR_ID(10), - TRANSCEIVER_PRESENT_ATTR_ID(11), - TRANSCEIVER_PRESENT_ATTR_ID(12), - TRANSCEIVER_PRESENT_ATTR_ID(13), - TRANSCEIVER_PRESENT_ATTR_ID(14), - TRANSCEIVER_PRESENT_ATTR_ID(15), - TRANSCEIVER_PRESENT_ATTR_ID(16), - TRANSCEIVER_PRESENT_ATTR_ID(17), - TRANSCEIVER_PRESENT_ATTR_ID(18), - TRANSCEIVER_PRESENT_ATTR_ID(19), - TRANSCEIVER_PRESENT_ATTR_ID(20), - TRANSCEIVER_PRESENT_ATTR_ID(21), - TRANSCEIVER_PRESENT_ATTR_ID(22), - TRANSCEIVER_PRESENT_ATTR_ID(23), - TRANSCEIVER_PRESENT_ATTR_ID(24), - TRANSCEIVER_PRESENT_ATTR_ID(25), - TRANSCEIVER_PRESENT_ATTR_ID(26), - TRANSCEIVER_PRESENT_ATTR_ID(27), - TRANSCEIVER_PRESENT_ATTR_ID(28), - TRANSCEIVER_PRESENT_ATTR_ID(29), - TRANSCEIVER_PRESENT_ATTR_ID(30), - TRANSCEIVER_PRESENT_ATTR_ID(31), - TRANSCEIVER_PRESENT_ATTR_ID(32), - TRANSCEIVER_RESET_ATTR_ID(1), - TRANSCEIVER_RESET_ATTR_ID(2), - TRANSCEIVER_RESET_ATTR_ID(3), - TRANSCEIVER_RESET_ATTR_ID(4), - TRANSCEIVER_RESET_ATTR_ID(5), - TRANSCEIVER_RESET_ATTR_ID(6), - TRANSCEIVER_RESET_ATTR_ID(7), - TRANSCEIVER_RESET_ATTR_ID(8), - TRANSCEIVER_RESET_ATTR_ID(9), - TRANSCEIVER_RESET_ATTR_ID(10), - TRANSCEIVER_RESET_ATTR_ID(11), - TRANSCEIVER_RESET_ATTR_ID(12), - TRANSCEIVER_RESET_ATTR_ID(13), - TRANSCEIVER_RESET_ATTR_ID(14), - TRANSCEIVER_RESET_ATTR_ID(15), - TRANSCEIVER_RESET_ATTR_ID(16), - TRANSCEIVER_RESET_ATTR_ID(17), - TRANSCEIVER_RESET_ATTR_ID(18), - TRANSCEIVER_RESET_ATTR_ID(19), - TRANSCEIVER_RESET_ATTR_ID(20), - TRANSCEIVER_RESET_ATTR_ID(21), - TRANSCEIVER_RESET_ATTR_ID(22), - TRANSCEIVER_RESET_ATTR_ID(23), - TRANSCEIVER_RESET_ATTR_ID(24), - TRANSCEIVER_RESET_ATTR_ID(25), - TRANSCEIVER_RESET_ATTR_ID(26), - TRANSCEIVER_RESET_ATTR_ID(27), - TRANSCEIVER_RESET_ATTR_ID(28), - TRANSCEIVER_RESET_ATTR_ID(29), - TRANSCEIVER_RESET_ATTR_ID(30), - TRANSCEIVER_RESET_ATTR_ID(31), - TRANSCEIVER_RESET_ATTR_ID(32), -}; - -/* sysfs attributes for hwmon - */ - -/* transceiver attributes */ -/*present*/ -#define DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ - static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_present, NULL, MODULE_PRESENT_##index) -#define DECLARE_TRANSCEIVER_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr - -/*reset*/ -#define DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(index) \ - static SENSOR_DEVICE_ATTR(module_reset_##index, S_IWUSR | S_IRUGO, get_mode_reset, set_mode_reset, MODULE_RESET_##index) -#define DECLARE_TRANSCEIVER_RESET_ATTR(index) &sensor_dev_attr_module_reset_##index.dev_attr.attr - -static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); -static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); -/* transceiver attributes */ -static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(1); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(2); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(3); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(4); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(5); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(6); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(7); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(8); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(9); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(10); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(11); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(12); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(13); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(14); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(15); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(16); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(17); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(18); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(19); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(20); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(21); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(22); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(23); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(24); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(25); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(26); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(27); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(28); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(29); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(30); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(31); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(32); - -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(1); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(2); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(3); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(4); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(5); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(6); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(7); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(8); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(9); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(10); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(11); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(12); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(13); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(14); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(15); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(16); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(17); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(18); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(19); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(20); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(21); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(22); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(23); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(24); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(25); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(26); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(27); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(28); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(29); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(30); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(31); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(32); - - -static struct attribute *as7716_32x_cpld_attributes[] = { - &sensor_dev_attr_version.dev_attr.attr, - &sensor_dev_attr_access.dev_attr.attr, - /* transceiver attributes */ - &sensor_dev_attr_module_present_all.dev_attr.attr, - DECLARE_TRANSCEIVER_ATTR(1), - DECLARE_TRANSCEIVER_ATTR(2), - DECLARE_TRANSCEIVER_ATTR(3), - DECLARE_TRANSCEIVER_ATTR(4), - DECLARE_TRANSCEIVER_ATTR(5), - DECLARE_TRANSCEIVER_ATTR(6), - DECLARE_TRANSCEIVER_ATTR(7), - DECLARE_TRANSCEIVER_ATTR(8), - DECLARE_TRANSCEIVER_ATTR(9), - DECLARE_TRANSCEIVER_ATTR(10), - DECLARE_TRANSCEIVER_ATTR(11), - DECLARE_TRANSCEIVER_ATTR(12), - DECLARE_TRANSCEIVER_ATTR(13), - DECLARE_TRANSCEIVER_ATTR(14), - DECLARE_TRANSCEIVER_ATTR(15), - DECLARE_TRANSCEIVER_ATTR(16), - DECLARE_TRANSCEIVER_ATTR(17), - DECLARE_TRANSCEIVER_ATTR(18), - DECLARE_TRANSCEIVER_ATTR(19), - DECLARE_TRANSCEIVER_ATTR(20), - DECLARE_TRANSCEIVER_ATTR(21), - DECLARE_TRANSCEIVER_ATTR(22), - DECLARE_TRANSCEIVER_ATTR(23), - DECLARE_TRANSCEIVER_ATTR(24), - DECLARE_TRANSCEIVER_ATTR(25), - DECLARE_TRANSCEIVER_ATTR(26), - DECLARE_TRANSCEIVER_ATTR(27), - DECLARE_TRANSCEIVER_ATTR(28), - DECLARE_TRANSCEIVER_ATTR(29), - DECLARE_TRANSCEIVER_ATTR(30), - DECLARE_TRANSCEIVER_ATTR(31), - DECLARE_TRANSCEIVER_ATTR(32), - DECLARE_TRANSCEIVER_RESET_ATTR(1), - DECLARE_TRANSCEIVER_RESET_ATTR(2), - DECLARE_TRANSCEIVER_RESET_ATTR(3), - DECLARE_TRANSCEIVER_RESET_ATTR(4), - DECLARE_TRANSCEIVER_RESET_ATTR(5), - DECLARE_TRANSCEIVER_RESET_ATTR(6), - DECLARE_TRANSCEIVER_RESET_ATTR(7), - DECLARE_TRANSCEIVER_RESET_ATTR(8), - DECLARE_TRANSCEIVER_RESET_ATTR(9), - DECLARE_TRANSCEIVER_RESET_ATTR(10), - DECLARE_TRANSCEIVER_RESET_ATTR(11), - DECLARE_TRANSCEIVER_RESET_ATTR(12), - DECLARE_TRANSCEIVER_RESET_ATTR(13), - DECLARE_TRANSCEIVER_RESET_ATTR(14), - DECLARE_TRANSCEIVER_RESET_ATTR(15), - DECLARE_TRANSCEIVER_RESET_ATTR(16), - DECLARE_TRANSCEIVER_RESET_ATTR(17), - DECLARE_TRANSCEIVER_RESET_ATTR(18), - DECLARE_TRANSCEIVER_RESET_ATTR(19), - DECLARE_TRANSCEIVER_RESET_ATTR(20), - DECLARE_TRANSCEIVER_RESET_ATTR(21), - DECLARE_TRANSCEIVER_RESET_ATTR(22), - DECLARE_TRANSCEIVER_RESET_ATTR(23), - DECLARE_TRANSCEIVER_RESET_ATTR(24), - DECLARE_TRANSCEIVER_RESET_ATTR(25), - DECLARE_TRANSCEIVER_RESET_ATTR(26), - DECLARE_TRANSCEIVER_RESET_ATTR(27), - DECLARE_TRANSCEIVER_RESET_ATTR(28), - DECLARE_TRANSCEIVER_RESET_ATTR(29), - DECLARE_TRANSCEIVER_RESET_ATTR(30), - DECLARE_TRANSCEIVER_RESET_ATTR(31), - DECLARE_TRANSCEIVER_RESET_ATTR(32), - NULL -}; - -static const struct attribute_group as7716_32x_cpld_group = { - .attrs = as7716_32x_cpld_attributes, -}; - -static ssize_t show_present_all(struct device *dev, struct device_attribute *da, - char *buf) -{ - int i, status; - u8 values[4] = {0}; - u8 regs[] = {0x30, 0x31, 0x32, 0x33}; - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32x_cpld_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - for (i = 0; i < ARRAY_SIZE(regs); i++) { - status = as7716_32x_cpld_read_internal(client, regs[i]); - - if (status < 0) { - goto exit; - } - - values[i] = ~(u8)status; - } - - mutex_unlock(&data->update_lock); - - /* Return values 1 -> 32 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3]); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t show_present(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 as7716_32x_cpld_data *data = i2c_get_clientdata(client); - int status = 0; - u8 reg = 0, mask = 0; - - switch (attr->index) { - case MODULE_PRESENT_1 ... MODULE_PRESENT_8: - reg = 0x30; - mask = 0x1 << (attr->index - MODULE_PRESENT_1); - break; - case MODULE_PRESENT_9 ... MODULE_PRESENT_16: - reg = 0x31; - mask = 0x1 << (attr->index - MODULE_PRESENT_9); - break; - case MODULE_PRESENT_17 ... MODULE_PRESENT_24: - reg = 0x32; - mask = 0x1 << (attr->index - MODULE_PRESENT_17); - break; - case MODULE_PRESENT_25 ... MODULE_PRESENT_32: - reg = 0x33; - mask = 0x1 << (attr->index - MODULE_PRESENT_25); - break; - default: - return 0; - } - - - mutex_lock(&data->update_lock); - status = as7716_32x_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - - return sprintf(buf, "%d\n", !(status & mask)); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t show_version(struct device *dev, struct device_attribute *da, - char *buf) -{ - u8 reg = 0, mask = 0; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32x_cpld_data *data = i2c_get_clientdata(client); - int status = 0; - - switch (attr->index) { - case CPLD_VERSION: - reg = 0x1; - mask = 0xFF; - break; - default: - break; - } - - mutex_lock(&data->update_lock); - status = as7716_32x_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return sprintf(buf, "%d\n", (status & mask)); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - int status; - u32 addr, val; - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32x_cpld_data *data = i2c_get_clientdata(client); - - if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { - return -EINVAL; - } - - if (addr > 0xFF || val > 0xFF) { - return -EINVAL; - } - - mutex_lock(&data->update_lock); - status = as7716_32x_cpld_write_internal(client, addr, val); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static int as7716_32x_cpld_read_internal(struct i2c_client *client, u8 reg) -{ - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, reg); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - return status; -} - -static int as7716_32x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value) -{ - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, reg, value); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - return status; -} - -static void as7716_32x_cpld_add_client(struct i2c_client *client) -{ - struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); - - if (!node) { - dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); - return; - } - - node->client = client; - - mutex_lock(&list_lock); - list_add(&node->list, &cpld_client_list); - mutex_unlock(&list_lock); -} - -static void as7716_32x_cpld_remove_client(struct i2c_client *client) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int found = 0; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client == client) { - found = 1; - break; - } - } - - if (found) { - list_del(list_node); - kfree(cpld_node); - } - - mutex_unlock(&list_lock); -} - -static int as7716_32x_cpld_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - int status; - struct as7716_32x_cpld_data *data = NULL; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - dev_dbg(&client->dev, "i2c_check_functionality failed (0x%x)\n", client->addr); - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7716_32x_cpld_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7716_32x_cpld_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - as7716_32x_cpld_add_client(client); - - dev_info(&client->dev, "%s: cpld '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7716_32x_cpld_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7716_32x_cpld_remove(struct i2c_client *client) -{ - struct as7716_32x_cpld_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7716_32x_cpld_group); - kfree(data); - as7716_32x_cpld_remove_client(client); - - return 0; -} - -int as7716_32x_cpld_read(unsigned short cpld_addr, u8 reg) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EPERM; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_read_byte_data(cpld_node->client, reg); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(as7716_32x_cpld_read); - -int as7716_32x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EIO; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(as7716_32x_cpld_write); - -static ssize_t get_mode_reset(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 as7716_32x_cpld_data *data = i2c_get_clientdata(client); - int status = 0; - u8 reg = 0, mask = 0; - - switch (attr->index) { - case MODULE_RESET_1 ... MODULE_RESET_8: - reg = 0x04; - mask = 0x1 << (attr->index - MODULE_RESET_1); - break; - case MODULE_RESET_9 ... MODULE_RESET_16: - reg = 0x05; - mask = 0x1 << (attr->index - MODULE_RESET_9); - break; - case MODULE_RESET_17 ... MODULE_RESET_24: - reg = 0x06; - mask = 0x1 << (attr->index - MODULE_RESET_17); - break; - case MODULE_RESET_25 ... MODULE_RESET_32: - reg = 0x07; - mask = 0x1 << (attr->index - MODULE_RESET_25); - break; - default: - return 0; - } - - - mutex_lock(&data->update_lock); - status = as7716_32x_cpld_read_internal(client, reg); - - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - - return sprintf(buf, "%d\r\n", !(status & mask)); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t set_mode_reset(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 as7716_32x_cpld_data *data = i2c_get_clientdata(client); - long reset; - int status=0, val, error; - u8 reg = 0, mask = 0; - - - error = kstrtol(buf, 10, &reset); - if (error) { - return error; - } - - switch (attr->index) { - case MODULE_RESET_1 ... MODULE_RESET_8: - reg = 0x04; - mask = 0x1 << (attr->index - MODULE_RESET_1); - break; - case MODULE_RESET_9 ... MODULE_RESET_16: - reg = 0x05; - mask = 0x1 << (attr->index - MODULE_RESET_9); - break; - case MODULE_RESET_17 ... MODULE_RESET_24: - reg = 0x06; - mask = 0x1 << (attr->index - MODULE_RESET_17); - break; - case MODULE_RESET_25 ... MODULE_RESET_32: - reg = 0x07; - mask = 0x1 << (attr->index - MODULE_RESET_25); - break; - default: - return 0; - } - mutex_lock(&data->update_lock); - - status = as7716_32x_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - - /* Update lp_mode status */ - if (reset) - { - val = status&(~mask); - } - else - { - val =status | (mask); - } - - status = as7716_32x_cpld_write_internal(client, reg, val); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - - - -static const struct i2c_device_id as7716_32x_cpld_id[] = { - { "as7716_32x_cpld1", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7716_32x_cpld_id); - -static struct i2c_driver as7716_32x_cpld_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7716_32x_cpld1", - }, - .probe = as7716_32x_cpld_probe, - .remove = as7716_32x_cpld_remove, - .id_table = as7716_32x_cpld_id, - .address_list = normal_i2c, -}; - -static int __init as7716_32x_cpld_init(void) -{ - mutex_init(&list_lock); - return i2c_add_driver(&as7716_32x_cpld_driver); -} - -static void __exit as7716_32x_cpld_exit(void) -{ - i2c_del_driver(&as7716_32x_cpld_driver); -} - -module_init(as7716_32x_cpld_init); -module_exit(as7716_32x_cpld_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7716_32x_cpld driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_fan.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_fan.c deleted file mode 100755 index 83b7bceeb99e..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_fan.c +++ /dev/null @@ -1,794 +0,0 @@ -/* - * A hwmon driver for the Accton as7716 32x fan - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRVNAME "as7716_32x_fan" - -#define NUM_THERMAL_SENSORS (3) /* Get sum of this number of sensors.*/ -#define THERMAL_SENSORS_DRIVER "lm75" - -#define IN -#define OUT - -static struct as7716_32x_fan_data *as7716_32x_fan_update_device(struct device *dev); -static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t get_enable(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_enable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, char *buf); -extern int as7716_32x_cpld_read(unsigned short cpld_addr, u8 reg); -extern int as7716_32x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -/* fan related data, the index should match sysfs_fan_attributes - */ -static const u8 fan_reg[] = { - 0x0F, /* fan 1-6 present status */ - 0x10, /* fan 1-6 direction(0:B2F 1:F2B) */ - 0x11, /* fan PWM(for all fan) */ - 0x12, /* front fan 1 speed(rpm) */ - 0x13, /* front fan 2 speed(rpm) */ - 0x14, /* front fan 3 speed(rpm) */ - 0x15, /* front fan 4 speed(rpm) */ - 0x16, /* front fan 5 speed(rpm) */ - 0x17, /* front fan 6 speed(rpm) */ - 0x22, /* rear fan 1 speed(rpm) */ - 0x23, /* rear fan 2 speed(rpm) */ - 0x24, /* rear fan 3 speed(rpm) */ - 0x25, /* rear fan 4 speed(rpm) */ - 0x26, /* rear fan 5 speed(rpm) */ - 0x27, /* rear fan 6 speed(rpm) */ -}; - -/* Each client has this additional data */ -struct as7716_32x_fan_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */ - u8 enable; - int system_temp; /*In unit of mini-Celsius*/ - int sensors_found; -}; - -enum fan_id { - FAN1_ID, - FAN2_ID, - FAN3_ID, - FAN4_ID, - FAN5_ID, - FAN6_ID -}; - -enum sysfs_fan_attributes { - FAN_PRESENT_REG, - FAN_DIRECTION_REG, - FAN_DUTY_CYCLE_PERCENTAGE, /* Only one CPLD register to control duty cycle for all fans */ - FAN1_FRONT_SPEED_RPM, - FAN2_FRONT_SPEED_RPM, - FAN3_FRONT_SPEED_RPM, - FAN4_FRONT_SPEED_RPM, - FAN5_FRONT_SPEED_RPM, - FAN6_FRONT_SPEED_RPM, - FAN1_REAR_SPEED_RPM, - FAN2_REAR_SPEED_RPM, - FAN3_REAR_SPEED_RPM, - FAN4_REAR_SPEED_RPM, - FAN5_REAR_SPEED_RPM, - FAN6_REAR_SPEED_RPM, - FAN1_DIRECTION, - FAN2_DIRECTION, - FAN3_DIRECTION, - FAN4_DIRECTION, - FAN5_DIRECTION, - FAN6_DIRECTION, - FAN1_PRESENT, - FAN2_PRESENT, - FAN3_PRESENT, - FAN4_PRESENT, - FAN5_PRESENT, - FAN6_PRESENT, - FAN1_FAULT, - FAN2_FAULT, - FAN3_FAULT, - FAN4_FAULT, - FAN5_FAULT, - FAN6_FAULT -}; - -/* Define attributes - */ -#define DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(index, index2) \ - static SENSOR_DEVICE_ATTR(fan##index##_fault, S_IRUGO, fan_show_value, NULL, FAN##index##_FAULT);\ - static SENSOR_DEVICE_ATTR(fan##index2##_fault, S_IRUGO, fan_show_value, NULL, FAN##index##_FAULT) -#define DECLARE_FAN_FAULT_ATTR(index, index2) &sensor_dev_attr_fan##index##_fault.dev_attr.attr, \ - &sensor_dev_attr_fan##index2##_fault.dev_attr.attr - -#define DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan##index##_direction, S_IRUGO, fan_show_value, NULL, FAN##index##_DIRECTION) -#define DECLARE_FAN_DIRECTION_ATTR(index) &sensor_dev_attr_fan##index##_direction.dev_attr.attr - -#define DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE);\ - static SENSOR_DEVICE_ATTR(pwm##index, S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE);\ - static SENSOR_DEVICE_ATTR(pwm##index##_enable, S_IWUSR | S_IRUGO, get_enable, set_enable, FAN_DUTY_CYCLE_PERCENTAGE) - -#define DECLARE_FAN_DUTY_CYCLE_ATTR(index) &sensor_dev_attr_fan_duty_cycle_percentage.dev_attr.attr, \ - &sensor_dev_attr_pwm##index.dev_attr.attr, \ - &sensor_dev_attr_pwm##index##_enable.dev_attr.attr - -#define DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR() \ - static SENSOR_DEVICE_ATTR(sys_temp, S_IRUGO, get_sys_temp, NULL, FAN_DUTY_CYCLE_PERCENTAGE) - -#define DECLARE_FAN_SYSTEM_TEMP_ATTR() &sensor_dev_attr_sys_temp.dev_attr.attr - - -#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan##index##_present, S_IRUGO, fan_show_value, NULL, FAN##index##_PRESENT) -#define DECLARE_FAN_PRESENT_ATTR(index) &sensor_dev_attr_fan##index##_present.dev_attr.attr - -#define DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(index, index2) \ - static SENSOR_DEVICE_ATTR(fan##index##_front_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_FRONT_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index##_rear_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_REAR_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index##_input, S_IRUGO, fan_show_value, NULL, FAN##index##_FRONT_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index2##_input, S_IRUGO, fan_show_value, NULL, FAN##index##_REAR_SPEED_RPM) -#define DECLARE_FAN_SPEED_RPM_ATTR(index, index2) &sensor_dev_attr_fan##index##_front_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_fan##index##_rear_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_fan##index##_input.dev_attr.attr, \ - &sensor_dev_attr_fan##index2##_input.dev_attr.attr - -/* 6 fan fault attributes in this platform */ -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(1,11); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(2,12); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(3,13); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(4,14); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(5,15); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(6,16); -/* 6 fan speed(rpm) attributes in this platform */ -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(1,11); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(2,12); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(3,13); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(4,14); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(5,15); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(6,16); -/* 6 fan present attributes in this platform */ -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(1); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(2); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(3); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(4); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(5); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(6); - -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(1); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(2); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(3); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(4); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(5); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(6); - -/* 1 fan duty cycle attribute in this platform */ -DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(1); -/* System temperature for fancontrol */ -DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR(); - -static struct attribute *as7716_32x_fan_attributes[] = { - /* fan related attributes */ - DECLARE_FAN_FAULT_ATTR(1,11), - DECLARE_FAN_FAULT_ATTR(2,12), - DECLARE_FAN_FAULT_ATTR(3,13), - DECLARE_FAN_FAULT_ATTR(4,14), - DECLARE_FAN_FAULT_ATTR(5,15), - DECLARE_FAN_FAULT_ATTR(6,16), - DECLARE_FAN_SPEED_RPM_ATTR(1,11), - DECLARE_FAN_SPEED_RPM_ATTR(2,12), - DECLARE_FAN_SPEED_RPM_ATTR(3,13), - DECLARE_FAN_SPEED_RPM_ATTR(4,14), - DECLARE_FAN_SPEED_RPM_ATTR(5,15), - DECLARE_FAN_SPEED_RPM_ATTR(6,16), - DECLARE_FAN_PRESENT_ATTR(1), - DECLARE_FAN_PRESENT_ATTR(2), - DECLARE_FAN_PRESENT_ATTR(3), - DECLARE_FAN_PRESENT_ATTR(4), - DECLARE_FAN_PRESENT_ATTR(5), - DECLARE_FAN_PRESENT_ATTR(6), - DECLARE_FAN_DIRECTION_ATTR(1), - DECLARE_FAN_DIRECTION_ATTR(2), - DECLARE_FAN_DIRECTION_ATTR(3), - DECLARE_FAN_DIRECTION_ATTR(4), - DECLARE_FAN_DIRECTION_ATTR(5), - DECLARE_FAN_DIRECTION_ATTR(6), - DECLARE_FAN_DUTY_CYCLE_ATTR(1), - DECLARE_FAN_SYSTEM_TEMP_ATTR(), - NULL -}; - -#define FAN_DUTY_CYCLE_REG_MASK 0xF -#define FAN_MAX_DUTY_CYCLE 100 -#define FAN_REG_VAL_TO_SPEED_RPM_STEP 100 - -static int as7716_32x_fan_read_value(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_byte_data(client, reg); -} - -static int as7716_32x_fan_write_value(struct i2c_client *client, u8 reg, u8 value) -{ - return i2c_smbus_write_byte_data(client, reg, value); -} - -/* fan utility functions - */ -static u32 reg_val_to_duty_cycle(u8 reg_val) -{ - reg_val &= FAN_DUTY_CYCLE_REG_MASK; - return ((u32)(reg_val+1) * 625 + 75)/ 100; -} - -static u8 duty_cycle_to_reg_val(u8 duty_cycle) -{ - return ((u32)duty_cycle * 100 / 625) - 1; -} - -static u32 reg_val_to_speed_rpm(u8 reg_val) -{ - return (u32)reg_val * FAN_REG_VAL_TO_SPEED_RPM_STEP; -} - -static u8 reg_val_to_direction(u8 reg_val, enum fan_id id) -{ - u8 mask = (1 << id); - - reg_val &= mask; - - return reg_val ? 1 : 0; -} -static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id) -{ - u8 mask = (1 << id); - - reg_val &= mask; - - return reg_val ? 0 : 1; -} - -static u8 is_fan_fault(struct as7716_32x_fan_data *data, enum fan_id id) -{ - u8 ret = 1; - int front_fan_index = FAN1_FRONT_SPEED_RPM + id; - int rear_fan_index = FAN1_REAR_SPEED_RPM + id; - - /* Check if the speed of front or rear fan is ZERO, - */ - if (reg_val_to_speed_rpm(data->reg_val[front_fan_index]) && - reg_val_to_speed_rpm(data->reg_val[rear_fan_index])) { - ret = 0; - } - - return ret; -} - -static ssize_t set_enable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct as7716_32x_fan_data *data = as7716_32x_fan_update_device(dev); - int error, value; - - error = kstrtoint(buf, 10, &value); - if (error) - return error; - - if (value < 0 || value > 1) - return -EINVAL; - - data->enable = value; - if (value == 0) - { - return set_duty_cycle(dev, da, buf, FAN_MAX_DUTY_CYCLE); - } - return count; -} - - -static ssize_t get_enable(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as7716_32x_fan_data *data = as7716_32x_fan_update_device(dev); - - return sprintf(buf, "%u\n", data->enable); -} -static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - int error, value; - struct i2c_client *client = to_i2c_client(dev); - - error = kstrtoint(buf, 10, &value); - if (error) - return error; - - if (value < 0 || value > FAN_MAX_DUTY_CYCLE) - return -EINVAL; - - as7716_32x_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */ - as7716_32x_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value)); - return count; -} - -/* Due to this struct is declared at lm75.c, it cannot be include - * under Sonic environment. I duplicate it from lm75.c. - */ -struct lm75_data { - struct i2c_client *client; - struct device *hwmon_dev; - struct thermal_zone_device *tz; - struct mutex update_lock; - u8 orig_conf; - u8 resolution; /* In bits, between 9 and 12 */ - u8 resolution_limits; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - unsigned long sample_time; /* In jiffies */ - s16 temp[3]; /* Register values, - 0 = input - 1 = max - 2 = hyst */ -}; - -/*Copied from lm75.c*/ -static inline long lm75_reg_to_mc(s16 temp, u8 resolution) -{ - return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8); -} - -/*Get hwmon_dev from i2c_client, set hwmon_dev = NULL is failed.*/ -static struct device * get_hwmon_dev( - struct i2c_client *client) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - if(data) - { - if( data->valid == 1 && data->hwmon_dev) - { - return data->hwmon_dev; - } - - } - return NULL; -} - -/* To find hwmon index by opening hwmon under that i2c address. - */ -static int find_hwmon_index_by_FileOpen( - int bus_nr, - unsigned short addr, - OUT int *index) -{ -#define MAX_HWMON_DEVICE (10) /* Find hwmon device in 0~10*/ - struct file *sfd; - char client_name[96]; - int i=0; - - do { - snprintf(client_name, sizeof(client_name), - "/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input", - bus_nr, addr, i); - - sfd = filp_open(client_name, O_RDONLY, 0); - i++; - } while( IS_ERR(sfd) && i < MAX_HWMON_DEVICE); - - if (IS_ERR(sfd)) { - pr_err("Failed to open file(%s)#%d\r\n", client_name, __LINE__); - return -ENOENT; - } - filp_close(sfd, 0); - *index = i - 1; - return 0; - -#undef MAX_HWMON_DEVICE -} - -static int get_temp_file_path( - int bus_nr, unsigned short addr, - struct device *hwmon_dev - ,char *path, int max_len) -{ - - if(hwmon_dev && strlen(dev_name(hwmon_dev))) - { - snprintf(path, max_len, - "/sys/bus/i2c/devices/%d-%04x/hwmon/%s/temp1_input", - bus_nr, addr, dev_name(hwmon_dev)); - } - else - { - int i=0; - if(find_hwmon_index_by_FileOpen( bus_nr, addr, &i)) - { - return -EIO; - } - snprintf(path, max_len, - "/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input", - bus_nr, addr, i); - } - return 0; -} - -/*File read the dev file at user space.*/ -static int read_devfile_temp1_input( - struct device *dev, - int bus_nr, - unsigned short addr, - struct device *hwmon_dev, - int *miniCelsius) -{ - struct file *sfd; - char buffer[96]; - char devfile[96]; - int rc, status; - int rdlen, value; - mm_segment_t old_fs; - - rc = 0; - get_temp_file_path(bus_nr, addr, hwmon_dev, devfile, sizeof(devfile)); - sfd = filp_open(devfile, O_RDONLY, 0); - if (IS_ERR(sfd)) { - pr_err("Failed to open file(%s)#%d\r\n", devfile, __LINE__); - return -ENOENT; - } - dev_dbg(dev, "Found device:%s\n",devfile); - - if(!(sfd->f_op) || !(sfd->f_op->read) ) { - pr_err("file %s cann't readable ?\n",devfile); - return -ENOENT; - } - - old_fs = get_fs(); - set_fs(KERNEL_DS); - rdlen = sfd->f_op->read(sfd, buffer, sizeof(buffer), &sfd->f_pos); - if (rdlen == 0) { - pr_err( "File(%s) empty!\n", devfile); - rc = -EIO; - goto exit; - } - status = sscanf(buffer, "%d", &value); - if (status != 1) { - rc = -EIO; - goto exit; - } - *miniCelsius = value; - dev_dbg(dev,"found sensors: %d @i2c %d-%04x\n", value, bus_nr, addr); - -exit: - set_fs(old_fs); - filp_close(sfd, 0); - return rc; -} - -static u8 is_lm75_data_due(struct i2c_client *client) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - if (time_after(jiffies, data->last_updated + data->sample_time)) - { - return 1; - } - return 0; -} -static int get_lm75_temp(struct i2c_client *client, int *miniCelsius) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - *miniCelsius = lm75_reg_to_mc(data->temp[0], data->resolution); - - return 0; -} - -static int _find_lm75_device(struct device *dev, void *data) -{ - struct device_driver *driver; - struct as7716_32x_fan_data *prv = data; - char *driver_name = THERMAL_SENSORS_DRIVER; - - driver = dev->driver; - if (driver && driver->name && - strcmp(driver->name, driver_name) == 0) - { - struct i2c_client *client; - client = to_i2c_client(dev); - if (client) - { - /*cannot use "struct i2c_adapter *adap = to_i2c_adapter(dev);"*/ - struct i2c_adapter *adap = client->adapter; - int miniCelsius = 0; - - - if (!adap) { - return -ENXIO; - } - - /* If the data is not updated, read them from devfile - to drive them updateing data from chip.*/ - if (is_lm75_data_due(client)) - { - struct device *hwmon_dev; - - hwmon_dev = get_hwmon_dev(client); - if(0 == read_devfile_temp1_input(dev, adap->nr, - client->addr, hwmon_dev, &miniCelsius)) - { - prv->system_temp += miniCelsius; - prv->sensors_found++; - } - - } - else - { - get_lm75_temp(client, &miniCelsius); - prv->system_temp += miniCelsius; - prv->sensors_found++; - - } - } - } - return 0; -} - -/*Find all lm75 devices and return sum of temperatures.*/ -static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, - char *buf) -{ - ssize_t ret = 0; - struct as7716_32x_fan_data *data = as7716_32x_fan_update_device(dev); - - data->system_temp=0; - data->sensors_found=0; - i2c_for_each_dev(data, _find_lm75_device); - if (NUM_THERMAL_SENSORS != data->sensors_found) - { - dev_dbg(dev,"only %d of %d temps are found\n", - data->sensors_found, NUM_THERMAL_SENSORS); - data->system_temp = 0; - } - ret = sprintf(buf, "%d\n",data->system_temp); - return ret; -} -static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as7716_32x_fan_data *data = as7716_32x_fan_update_device(dev); - ssize_t ret = 0; - - if (data->valid) { - switch (attr->index) { - case FAN_DUTY_CYCLE_PERCENTAGE: - { - u32 duty_cycle = reg_val_to_duty_cycle(data->reg_val[FAN_DUTY_CYCLE_PERCENTAGE]); - ret = sprintf(buf, "%u\n", duty_cycle); - break; - } - case FAN1_FRONT_SPEED_RPM: - case FAN2_FRONT_SPEED_RPM: - case FAN3_FRONT_SPEED_RPM: - case FAN4_FRONT_SPEED_RPM: - case FAN5_FRONT_SPEED_RPM: - case FAN6_FRONT_SPEED_RPM: - case FAN1_REAR_SPEED_RPM: - case FAN2_REAR_SPEED_RPM: - case FAN3_REAR_SPEED_RPM: - case FAN4_REAR_SPEED_RPM: - case FAN5_REAR_SPEED_RPM: - case FAN6_REAR_SPEED_RPM: - ret = sprintf(buf, "%u\n", reg_val_to_speed_rpm(data->reg_val[attr->index])); - break; - case FAN1_PRESENT: - case FAN2_PRESENT: - case FAN3_PRESENT: - case FAN4_PRESENT: - case FAN5_PRESENT: - case FAN6_PRESENT: - ret = sprintf(buf, "%d\n", - reg_val_to_is_present(data->reg_val[FAN_PRESENT_REG], - attr->index - FAN1_PRESENT)); - break; - case FAN1_FAULT: - case FAN2_FAULT: - case FAN3_FAULT: - case FAN4_FAULT: - case FAN5_FAULT: - case FAN6_FAULT: - ret = sprintf(buf, "%d\n", is_fan_fault(data, attr->index - FAN1_FAULT)); - break; - case FAN1_DIRECTION: - case FAN2_DIRECTION: - case FAN3_DIRECTION: - case FAN4_DIRECTION: - case FAN5_DIRECTION: - case FAN6_DIRECTION: - ret = sprintf(buf, "%d\n", - reg_val_to_direction(data->reg_val[FAN_DIRECTION_REG], - attr->index - FAN1_DIRECTION)); - break; - default: - break; - } - } - - return ret; -} - -static const struct attribute_group as7716_32x_fan_group = { - .attrs = as7716_32x_fan_attributes, -}; - -static struct as7716_32x_fan_data *as7716_32x_fan_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32x_fan_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || - !data->valid) { - int i; - - dev_dbg(&client->dev, "Starting as7716_32x_fan update\n"); - data->valid = 0; - - /* Update fan data - */ - for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) { - int status = as7716_32x_fan_read_value(client, fan_reg[i]); - - if (status < 0) { - data->valid = 0; - mutex_unlock(&data->update_lock); - dev_dbg(&client->dev, "reg %d, err %d\n", fan_reg[i], status); - return data; - } - else { - data->reg_val[i] = status; - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -static int as7716_32x_fan_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7716_32x_fan_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7716_32x_fan_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7716_32x_fan_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: fan '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7716_32x_fan_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7716_32x_fan_remove(struct i2c_client *client) -{ - struct as7716_32x_fan_data *data = i2c_get_clientdata(client); - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7716_32x_fan_group); - - return 0; -} - -/* Addresses to scan */ -static const unsigned short normal_i2c[] = { 0x66, I2C_CLIENT_END }; - -static const struct i2c_device_id as7716_32x_fan_id[] = { - { "as7716_32x_fan", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7716_32x_fan_id); - -static struct i2c_driver as7716_32x_fan_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = DRVNAME, - }, - .probe = as7716_32x_fan_probe, - .remove = as7716_32x_fan_remove, - .id_table = as7716_32x_fan_id, - .address_list = normal_i2c, -}; - -static int __init as7716_32x_fan_init(void) -{ - return i2c_add_driver(&as7716_32x_fan_driver); -} - -static void __exit as7716_32x_fan_exit(void) -{ - i2c_del_driver(&as7716_32x_fan_driver); -} - -module_init(as7716_32x_fan_init); -module_exit(as7716_32x_fan_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7716_32x_fan driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_leds.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_leds.c deleted file mode 100755 index da3d9442035f..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_leds.c +++ /dev/null @@ -1,442 +0,0 @@ -/* - * A LED driver for the as7716_32x_led - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/*#define DEBUG*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -extern int as7716_32x_cpld_read (unsigned short cpld_addr, u8 reg); -extern int as7716_32x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -extern void led_classdev_unregister(struct led_classdev *led_cdev); -extern int led_classdev_register(struct device *parent, struct led_classdev *led_cdev); -extern void led_classdev_resume(struct led_classdev *led_cdev); -extern void led_classdev_suspend(struct led_classdev *led_cdev); - -#define DRVNAME "as7716_32x_led" - -struct as7716_32x_led_data { - struct platform_device *pdev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[1]; /* only 1 register*/ -}; - -static struct as7716_32x_led_data *ledctl = NULL; - -/* LED related data - */ - -#define LED_CNTRLER_I2C_ADDRESS (0x60) - -#define LED_TYPE_DIAG_REG_MASK (0x3) -#define LED_MODE_DIAG_GREEN_VALUE (0x02) -#define LED_MODE_DIAG_RED_VALUE (0x01) -#define LED_MODE_DIAG_AMBER_VALUE (0x00) /*It's yellow actually. Green+Red=Yellow*/ -#define LED_MODE_DIAG_OFF_VALUE (0x03) - - -#define LED_TYPE_LOC_REG_MASK (0x80) -#define LED_MODE_LOC_ON_VALUE (0) -#define LED_MODE_LOC_OFF_VALUE (0x80) - -enum led_type { - LED_TYPE_DIAG, - LED_TYPE_LOC, - LED_TYPE_FAN, - LED_TYPE_PSU1, - LED_TYPE_PSU2 -}; - -struct led_reg { - u32 types; - u8 reg_addr; -}; - -static const struct led_reg led_reg_map[] = { - {(1<update_lock); - - if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2) - || !ledctl->valid) { - int i; - - dev_dbg(&ledctl->pdev->dev, "Starting as7716_32x_led update\n"); - - /* Update LED data - */ - for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { - int status = as7716_32x_led_read_value(led_reg_map[i].reg_addr); - - if (status < 0) { - ledctl->valid = 0; - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg_map[i].reg_addr, status); - goto exit; - } - else - { - ledctl->reg_val[i] = status; - } - } - - ledctl->last_updated = jiffies; - ledctl->valid = 1; - } - -exit: - mutex_unlock(&ledctl->update_lock); -} - -static void as7716_32x_led_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode, - enum led_type type) -{ - int reg_val; - u8 reg ; - mutex_lock(&ledctl->update_lock); - - if( !getLedReg(type, ®)) - { - dev_dbg(&ledctl->pdev->dev, "Not match item for %d.\n", type); - } - - reg_val = as7716_32x_led_read_value(reg); - - if (reg_val < 0) { - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val); - goto exit; - } - reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val); - as7716_32x_led_write_value(reg, reg_val); - - /* to prevent the slow-update issue */ - ledctl->valid = 0; - -exit: - mutex_unlock(&ledctl->update_lock); -} - - -static void as7716_32x_led_diag_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - as7716_32x_led_set(led_cdev, led_light_mode, LED_TYPE_DIAG); -} - -static enum led_brightness as7716_32x_led_diag_get(struct led_classdev *cdev) -{ - as7716_32x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); -} - -static void as7716_32x_led_loc_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - as7716_32x_led_set(led_cdev, led_light_mode, LED_TYPE_LOC); -} - -static enum led_brightness as7716_32x_led_loc_get(struct led_classdev *cdev) -{ - as7716_32x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); -} - -static void as7716_32x_led_auto_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ -} - -static enum led_brightness as7716_32x_led_auto_get(struct led_classdev *cdev) -{ - return LED_MODE_AUTO; -} - -static struct led_classdev as7716_32x_leds[] = { - [LED_TYPE_DIAG] = { - .name = "as7716_32x_led::diag", - .default_trigger = "unused", - .brightness_set = as7716_32x_led_diag_set, - .brightness_get = as7716_32x_led_diag_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_RED, - }, - [LED_TYPE_LOC] = { - .name = "as7716_32x_led::loc", - .default_trigger = "unused", - .brightness_set = as7716_32x_led_loc_set, - .brightness_get = as7716_32x_led_loc_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_BLUE, - }, - [LED_TYPE_FAN] = { - .name = "as7716_32x_led::fan", - .default_trigger = "unused", - .brightness_set = as7716_32x_led_auto_set, - .brightness_get = as7716_32x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_PSU1] = { - .name = "as7716_32x_led::psu1", - .default_trigger = "unused", - .brightness_set = as7716_32x_led_auto_set, - .brightness_get = as7716_32x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_PSU2] = { - .name = "as7716_32x_led::psu2", - .default_trigger = "unused", - .brightness_set = as7716_32x_led_auto_set, - .brightness_get = as7716_32x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, -}; - -static int as7716_32x_led_suspend(struct platform_device *dev, - pm_message_t state) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(as7716_32x_leds); i++) { - led_classdev_suspend(&as7716_32x_leds[i]); - } - - return 0; -} - -static int as7716_32x_led_resume(struct platform_device *dev) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(as7716_32x_leds); i++) { - led_classdev_resume(&as7716_32x_leds[i]); - } - - return 0; -} - -static int as7716_32x_led_probe(struct platform_device *pdev) -{ - int ret, i; - - for (i = 0; i < ARRAY_SIZE(as7716_32x_leds); i++) { - ret = led_classdev_register(&pdev->dev, &as7716_32x_leds[i]); - - if (ret < 0) - { - break; - } - } - - /* Check if all LEDs were successfully registered */ - if (i != ARRAY_SIZE(as7716_32x_leds)){ - int j; - - /* only unregister the LEDs that were successfully registered */ - for (j = 0; j < i; j++) { - led_classdev_unregister(&as7716_32x_leds[i]); - } - } - - return 0; -} - -static int as7716_32x_led_remove(struct platform_device *pdev) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(as7716_32x_leds); i++) { - led_classdev_unregister(&as7716_32x_leds[i]); - } - - return 0; -} - -static struct platform_driver as7716_32x_led_driver = { - .probe = as7716_32x_led_probe, - .remove = as7716_32x_led_remove, - .suspend = as7716_32x_led_suspend, - .resume = as7716_32x_led_resume, - .driver = { - .name = DRVNAME, - .owner = THIS_MODULE, - }, -}; - -static int __init as7716_32x_led_init(void) -{ - int ret; - - - ret = platform_driver_register(&as7716_32x_led_driver); - if (ret < 0) { - - goto exit; - } - - ledctl = kzalloc(sizeof(struct as7716_32x_led_data), GFP_KERNEL); - if (!ledctl) { - ret = -ENOMEM; - platform_driver_unregister(&as7716_32x_led_driver); - goto exit; - } - - mutex_init(&ledctl->update_lock); - - ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); - if (IS_ERR(ledctl->pdev)) { - ret = PTR_ERR(ledctl->pdev); - platform_driver_unregister(&as7716_32x_led_driver); - kfree(ledctl); - goto exit; - } - -exit: - return 0; -} - -static void __exit as7716_32x_led_exit(void) -{ - platform_device_unregister(ledctl->pdev); - platform_driver_unregister(&as7716_32x_led_driver); - kfree(ledctl); -} - -module_init(as7716_32x_led_init); -module_exit(as7716_32x_led_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7716_32x_led driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_psu.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_psu.c deleted file mode 100755 index 78a58b820b2a..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_psu.c +++ /dev/null @@ -1,381 +0,0 @@ -/* - * An hwmon driver for accton as7716_32x Power Module - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_MODEL_NAME 16 - -#define DC12V_FAN_DIR_OFFSET 0x34 -#define DC12V_FAN_DIR_LEN 3 - -static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_string(struct device *dev, struct device_attribute *da, char *buf); -static int as7716_32x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int as7716_32x_cpld_read (unsigned short cpld_addr, u8 reg); - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as7716_32x_psu_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 index; /* PSU index */ - u8 status; /* Status(present/power_good) register read from CPLD */ - char model_name[MAX_MODEL_NAME+1]; /* Model name, read from eeprom */ - char fan_dir[DC12V_FAN_DIR_LEN+1]; /* DC12V fan direction */ -}; - -static struct as7716_32x_psu_data *as7716_32x_psu_update_device(struct device *dev); - -enum as7716_32x_psu_sysfs_attributes { - PSU_PRESENT, - PSU_MODEL_NAME, - PSU_POWER_GOOD, - PSU_FAN_DIR /* For DC12V only */ -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT); -static SENSOR_DEVICE_ATTR(psu_model_name, S_IRUGO, show_string, NULL, PSU_MODEL_NAME); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD); -static SENSOR_DEVICE_ATTR(psu_fan_dir, S_IRUGO, show_string, NULL, PSU_FAN_DIR); - -static struct attribute *as7716_32x_psu_attributes[] = { - &sensor_dev_attr_psu_present.dev_attr.attr, - &sensor_dev_attr_psu_model_name.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - &sensor_dev_attr_psu_fan_dir.dev_attr.attr, - NULL -}; - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as7716_32x_psu_data *data = as7716_32x_psu_update_device(dev); - u8 status = 0; - - if (!data->valid) { - return -EIO; - } - - if (attr->index == PSU_PRESENT) { - status = !(data->status >> (1-data->index) & 0x1); - } - else { /* PSU_POWER_GOOD */ - status = (data->status >> (3-data->index) & 0x1); - } - - return sprintf(buf, "%d\n", status); -} - -static ssize_t show_string(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as7716_32x_psu_data *data = as7716_32x_psu_update_device(dev); - char *ptr = NULL; - - if (!data->valid) { - return -EIO; - } - - if (attr->index == PSU_MODEL_NAME) { - ptr = data->model_name; - } - else { /* PSU_FAN_DIR */ - ptr = data->fan_dir; - } - - return sprintf(buf, "%s\n", ptr); -} - -static const struct attribute_group as7716_32x_psu_group = { - .attrs = as7716_32x_psu_attributes, -}; - -static int as7716_32x_psu_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7716_32x_psu_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7716_32x_psu_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - data->index = dev_id->driver_data; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7716_32x_psu_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7716_32x_psu_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7716_32x_psu_remove(struct i2c_client *client) -{ - struct as7716_32x_psu_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7716_32x_psu_group); - kfree(data); - - return 0; -} - -enum psu_index -{ - as7716_32x_psu1, - as7716_32x_psu2 -}; - -static const struct i2c_device_id as7716_32x_psu_id[] = { - { "as7716_32x_psu1", as7716_32x_psu1 }, - { "as7716_32x_psu2", as7716_32x_psu2 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7716_32x_psu_id); - -static struct i2c_driver as7716_32x_psu_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7716_32x_psu", - }, - .probe = as7716_32x_psu_probe, - .remove = as7716_32x_psu_remove, - .id_table = as7716_32x_psu_id, - .address_list = normal_i2c, -}; - -static int as7716_32x_psu_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = 0; - int retry_count = 5; - - while (retry_count) { - retry_count--; - - result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) { - msleep(10); - continue; - } - - if (unlikely(result != data_len)) { - result = -EIO; - msleep(10); - continue; - } - - result = 0; - break; - } - - return result; -} - -enum psu_type { - PSU_TYPE_AC_110V, - PSU_TYPE_DC_48V, - PSU_TYPE_DC_12V -}; - -struct model_name_info { - enum psu_type type; - u8 offset; - u8 length; - char* model_name; -}; - -struct model_name_info models[] = { -{PSU_TYPE_AC_110V, 0x20, 8, "YM-2651Y"}, -{PSU_TYPE_DC_48V, 0x20, 8, "YM-2651V"}, -{PSU_TYPE_DC_12V, 0x00, 11, "PSU-12V-750"}, -}; - -static int as7716_32x_psu_model_name_get(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32x_psu_data *data = i2c_get_clientdata(client); - int i, status; - - for (i = 0; i < ARRAY_SIZE(models); i++) { - memset(data->model_name, 0, sizeof(data->model_name)); - - status = as7716_32x_psu_read_block(client, models[i].offset, - data->model_name, models[i].length); - if (status < 0) { - data->model_name[0] = '\0'; - dev_dbg(&client->dev, "unable to read model name from (0x%x) offset(0x%x)\n", - client->addr, models[i].offset); - return status; - } - else { - data->model_name[models[i].length] = '\0'; - } - - /* Determine if the model name is known, if not, read next index - */ - if (strncmp(data->model_name, models[i].model_name, models[i].length) == 0) { - return 0; - } - else { - data->model_name[0] = '\0'; - } - } - - return -ENODATA; -} - -static struct as7716_32x_psu_data *as7716_32x_psu_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32x_psu_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int status; - int power_good = 0; - - data->valid = 0; - dev_dbg(&client->dev, "Starting as7716_32x update\n"); - - /* Read psu status */ - status = as7716_32x_cpld_read(0x60, 0x2); - - if (status < 0) { - dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); - goto exit; - } - else { - data->status = status; - } - - /* Read model name */ - memset(data->model_name, 0, sizeof(data->model_name)); - memset(data->fan_dir, 0, sizeof(data->fan_dir)); - power_good = (data->status >> (3-data->index) & 0x1); - - if (power_good) { - if (as7716_32x_psu_model_name_get(dev) < 0) { - goto exit; - } - - if (strncmp(data->model_name, - models[PSU_TYPE_DC_12V].model_name, - models[PSU_TYPE_DC_12V].length) == 0) - { - /* Read fan direction */ - - status = as7716_32x_psu_read_block(client, DC12V_FAN_DIR_OFFSET, - data->fan_dir, DC12V_FAN_DIR_LEN); - - if (status < 0) { - data->fan_dir[0] = '\0'; - dev_dbg(&client->dev, "unable to read fan direction from (0x%x) offset(0x%x)\n", - client->addr, DC12V_FAN_DIR_OFFSET); - goto exit; - } - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init as7716_32x_psu_init(void) -{ - return i2c_add_driver(&as7716_32x_psu_driver); -} - -static void __exit as7716_32x_psu_exit(void) -{ - i2c_del_driver(&as7716_32x_psu_driver); -} - -module_init(as7716_32x_psu_init); -module_exit(as7716_32x_psu_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7716_32x_psu driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_sfp.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_sfp.c deleted file mode 100755 index 9c7a05632154..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_as7716_32x_sfp.c +++ /dev/null @@ -1,365 +0,0 @@ -/* - * An hwmon driver for accton as7716_32x sfp - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BIT_INDEX(i) (1UL << (i)) -#define I2C_ADDR_CPLD1 0x60 -#define I2C_ADDR_CPLD2 0x62 -#define I2C_ADDR_CPLD3 0x64 -#define CPLD1_OFFSET_QSFP_PRESET1 0x30 -#define CPLD1_OFFSET_QSFP_PRESET2 0x31 -#define CPLD1_OFFSET_QSFP_PRESET3 0x32 -#define CPLD1_OFFSET_QSFP_PRESET4 0x33 - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x50, I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as7716_32x_sfp_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - int port; /* Front port index */ - char eeprom[256]; /* eeprom data */ - u32 is_present; /* present status */ -}; - -static struct as7716_32x_sfp_data *as7716_32x_sfp_update_device(struct device *dev); -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_present(struct device *dev, struct device_attribute *da,char *buf); -static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, char *buf); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -enum as7716_32x_sfp_sysfs_attributes { - SFP_PORT_NUMBER, - SFP_IS_PRESENT, - SFP_IS_PRESENT_ALL, - SFP_EEPROM -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, SFP_PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, SFP_IS_PRESENT); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, SFP_IS_PRESENT_ALL); -static SENSOR_DEVICE_ATTR(sfp_eeprom, S_IRUGO, show_eeprom, NULL, SFP_EEPROM); - -static struct attribute *as7716_32x_sfp_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_eeprom.dev_attr.attr, - NULL -}; - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32x_sfp_data *data = i2c_get_clientdata(client); - - return sprintf(buf, "%d\n", data->port+1); -} - -/* Error-check the CPLD read results. */ -#define VALIDATED_READ(_buf, _rv, _read_expr, _invert) \ -do { \ - _rv = (_read_expr); \ - if(_rv < 0) { \ - return sprintf(_buf, "READ ERROR\n"); \ - } \ - if(_invert) { \ - _rv = ~_rv; \ - } \ - _rv &= 0xFF; \ -} while(0) - -static ssize_t show_present(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - - if(attr->index == SFP_IS_PRESENT_ALL) { - int values[4]; - /* - * Report the SFP_PRESENCE status for all ports. - */ - - /* QSFP_PRESENT Ports 1-8 */ - //VALIDATED_READ(buf, values[0], accton_i2c_cpld_read(0x62, 0x9), 1); - VALIDATED_READ(buf, values[0], accton_i2c_cpld_read(I2C_ADDR_CPLD1, CPLD1_OFFSET_QSFP_PRESET1), 1); - /* QSFP_PRESENT Ports 9-16 */ - VALIDATED_READ(buf, values[1], accton_i2c_cpld_read(I2C_ADDR_CPLD1, CPLD1_OFFSET_QSFP_PRESET2), 1); - /* QSFP_PRESENT Ports 17-24 */ - VALIDATED_READ(buf, values[2], accton_i2c_cpld_read(I2C_ADDR_CPLD1, CPLD1_OFFSET_QSFP_PRESET3), 1); - /* QSFP_PRESENT Ports 25-32 */ - VALIDATED_READ(buf, values[3], accton_i2c_cpld_read(I2C_ADDR_CPLD1, CPLD1_OFFSET_QSFP_PRESET4), 1); - - /* Return values 1 -> 32 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], values[3]); - } - else { /* SFP_IS_PRESENT */ - struct as7716_32x_sfp_data *data = as7716_32x_sfp_update_device(dev); - - if (!data->valid) { - printk("return -EIO\n"); - return -EIO; - } - - return sprintf(buf, "%d\n", data->is_present); - } -} - -static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as7716_32x_sfp_data *data = as7716_32x_sfp_update_device(dev); - - if (!data->valid) { - return 0; - } - - if (!data->is_present) { - return 0; - } - - memcpy(buf, data->eeprom, sizeof(data->eeprom)); - - return sizeof(data->eeprom); -} - -static const struct attribute_group as7716_32x_sfp_group = { - .attrs = as7716_32x_sfp_attributes, -}; - -static int as7716_32x_sfp_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7716_32x_sfp_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7716_32x_sfp_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - i2c_set_clientdata(client, data); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7716_32x_sfp_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: sfp '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7716_32x_sfp_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7716_32x_sfp_remove(struct i2c_client *client) -{ - struct as7716_32x_sfp_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7716_32x_sfp_group); - kfree(data); - - return 0; -} - -enum port_numbers { -as7716_32x_sfp1, as7716_32x_sfp2, as7716_32x_sfp3, as7716_32x_sfp4, -as7716_32x_sfp5, as7716_32x_sfp6, as7716_32x_sfp7, as7716_32x_sfp8, -as7716_32x_sfp9, as7716_32x_sfp10,as7716_32x_sfp11,as7716_32x_sfp12, -as7716_32x_sfp13,as7716_32x_sfp14,as7716_32x_sfp15,as7716_32x_sfp16, -as7716_32x_sfp17,as7716_32x_sfp18,as7716_32x_sfp19,as7716_32x_sfp20, -as7716_32x_sfp21,as7716_32x_sfp22,as7716_32x_sfp23,as7716_32x_sfp24, -as7716_32x_sfp25,as7716_32x_sfp26,as7716_32x_sfp27,as7716_32x_sfp28, -as7716_32x_sfp29,as7716_32x_sfp30,as7716_32x_sfp31,as7716_32x_sfp32 -}; - -static const struct i2c_device_id as7716_32x_sfp_id[] = { -{ "as7716_32x_sfp1", as7716_32x_sfp1 }, { "as7716_32x_sfp2", as7716_32x_sfp2 }, -{ "as7716_32x_sfp3", as7716_32x_sfp3 }, { "as7716_32x_sfp4", as7716_32x_sfp4 }, -{ "as7716_32x_sfp5", as7716_32x_sfp5 }, { "as7716_32x_sfp6", as7716_32x_sfp6 }, -{ "as7716_32x_sfp7", as7716_32x_sfp7 }, { "as7716_32x_sfp8", as7716_32x_sfp8 }, -{ "as7716_32x_sfp9", as7716_32x_sfp9 }, { "as7716_32x_sfp10", as7716_32x_sfp10 }, -{ "as7716_32x_sfp11", as7716_32x_sfp11 }, { "as7716_32x_sfp12", as7716_32x_sfp12 }, -{ "as7716_32x_sfp13", as7716_32x_sfp13 }, { "as7716_32x_sfp14", as7716_32x_sfp14 }, -{ "as7716_32x_sfp15", as7716_32x_sfp15 }, { "as7716_32x_sfp16", as7716_32x_sfp16 }, -{ "as7716_32x_sfp17", as7716_32x_sfp17 }, { "as7716_32x_sfp18", as7716_32x_sfp18 }, -{ "as7716_32x_sfp19", as7716_32x_sfp19 }, { "as7716_32x_sfp20", as7716_32x_sfp20 }, -{ "as7716_32x_sfp21", as7716_32x_sfp21 }, { "as7716_32x_sfp22", as7716_32x_sfp22 }, -{ "as7716_32x_sfp23", as7716_32x_sfp23 }, { "as7716_32x_sfp24", as7716_32x_sfp24 }, -{ "as7716_32x_sfp25", as7716_32x_sfp25 }, { "as7716_32x_sfp26", as7716_32x_sfp26 }, -{ "as7716_32x_sfp27", as7716_32x_sfp27 }, { "as7716_32x_sfp28", as7716_32x_sfp28 }, -{ "as7716_32x_sfp29", as7716_32x_sfp29 }, { "as7716_32x_sfp30", as7716_32x_sfp30 }, -{ "as7716_32x_sfp31", as7716_32x_sfp31 }, { "as7716_32x_sfp32", as7716_32x_sfp32 }, -{} -}; -MODULE_DEVICE_TABLE(i2c, as7716_32x_sfp_id); - -static struct i2c_driver as7716_32x_sfp_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7716_32x_sfp", - }, - .probe = as7716_32x_sfp_probe, - .remove = as7716_32x_sfp_remove, - .id_table = as7716_32x_sfp_id, - .address_list = normal_i2c, -}; - -static int as7716_32x_sfp_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) - goto abort; - if (unlikely(result != data_len)) { - result = -EIO; - goto abort; - } - - result = 0; - -abort: - return result; -} - -static struct as7716_32x_sfp_data *as7716_32x_sfp_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32x_sfp_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int status = -1; - int i = 0; - u8 cpld_reg = 0x30 + (data->port/8); - - data->valid = 0; - - /* Read present status of the specified port number */ - data->is_present = 0; - status = accton_i2c_cpld_read(I2C_ADDR_CPLD1, cpld_reg); - - if (status < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", I2C_ADDR_CPLD1, cpld_reg, status); - goto exit; - } - - data->is_present = (status & (1 << (data->port % 8))) ? 0 : 1; - printk("data->is_present=%d, data->port=%d, status=0x%x\n",data->is_present, data->port, status); - /* Read eeprom data based on port number */ - memset(data->eeprom, 0, sizeof(data->eeprom)); - - /* Check if the port is present */ - if (data->is_present) { - /* read eeprom */ - for (i = 0; i < sizeof(data->eeprom)/I2C_SMBUS_BLOCK_MAX; i++) { - status = as7716_32x_sfp_read_block(client, i*I2C_SMBUS_BLOCK_MAX, - data->eeprom+(i*I2C_SMBUS_BLOCK_MAX), - I2C_SMBUS_BLOCK_MAX); - if (status < 0) { - printk("unable to read eeprom from port(%d)\n", data->port); - dev_dbg(&client->dev, "unable to read eeprom from port(%d)\n", data->port); - goto exit; - } - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init as7716_32x_sfp_init(void) -{ - //extern int platform_accton_as7716_32x(void); - //if (!platform_accton_as7716_32x()) { -// return -ENODEV; - //} - - return i2c_add_driver(&as7716_32x_sfp_driver); -} - -static void __exit as7716_32x_sfp_exit(void) -{ - i2c_del_driver(&as7716_32x_sfp_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as7716_32x_sfp driver"); -MODULE_LICENSE("GPL"); - -module_init(as7716_32x_sfp_init); -module_exit(as7716_32x_sfp_exit); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_i2c_cpld.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_i2c_cpld.c deleted file mode 100755 index 46d1e2773287..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/accton_i2c_cpld.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - * A hwmon driver for the accton_i2c_cpld - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define CPLD_VERSION_REG 0x1 - -enum as5712_54x_cpld_sysfs_attributes { - CPLD_READ_VERSION, - CPLD_BYTE_ACCESS, - CPLD_DUMP_ALL, -}; - -static ssize_t read_cpld_version(struct device *dev, struct device_attribute *da, - char *buf); -int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); - - -static LIST_HEAD(cpld_client_list); -static struct mutex list_lock; - -struct cpld_client_node { - struct i2c_client *client; - struct list_head list; -}; - -/* Addresses scanned for accton_i2c_cpld - */ -static const unsigned short normal_i2c[] = { 0x31, 0x35, 0x60, 0x61, 0x62, I2C_CLIENT_END }; - -static SENSOR_DEVICE_ATTR(cpld_get_version, S_IRUGO, read_cpld_version, NULL, CPLD_READ_VERSION); - -static struct attribute *as5712_54x_cpld_attributes[] = { - &sensor_dev_attr_cpld_get_version.dev_attr.attr, - NULL -}; - -static const struct attribute_group as5712_54x_cpld_group = { - .attrs = as5712_54x_cpld_attributes, -}; - -static ssize_t read_cpld_version(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); - unsigned short cpld_reg = CPLD_VERSION_REG; - u8 reg; - - if(attr->index == CPLD_READ_VERSION) { - reg = accton_i2c_cpld_read(client->addr, cpld_reg); - return sprintf(buf, "%02x\n",reg); - } - return -1 ; -} - - -static void accton_i2c_cpld_add_client(struct i2c_client *client) -{ - struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); - - if (!node) { - dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); - return; - } - - node->client = client; - - mutex_lock(&list_lock); - list_add(&node->list, &cpld_client_list); - mutex_unlock(&list_lock); -} - -static void accton_i2c_cpld_remove_client(struct i2c_client *client) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int found = 0; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client == client) { - found = 1; - break; - } - } - - if (found) { - list_del(list_node); - kfree(cpld_node); - } - - mutex_unlock(&list_lock); -} - -static int accton_i2c_cpld_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - dev_dbg(&client->dev, "i2c_check_functionality failed (0x%x)\n", client->addr); - status = -EIO; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as5712_54x_cpld_group); - if (status) { - goto exit; - } - - dev_info(&client->dev, "chip found\n"); - accton_i2c_cpld_add_client(client); - - return 0; -exit: - return status; -} - -static int accton_i2c_cpld_remove(struct i2c_client *client) -{ - sysfs_remove_group(&client->dev.kobj, &as5712_54x_cpld_group); - - accton_i2c_cpld_remove_client(client); - return 0; -} - -static const struct i2c_device_id accton_i2c_cpld_id[] = { - { "accton_i2c_cpld", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, accton_i2c_cpld_id); - -static struct i2c_driver accton_i2c_cpld_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "accton_i2c_cpld", - }, - .probe = accton_i2c_cpld_probe, - .remove = accton_i2c_cpld_remove, - .id_table = accton_i2c_cpld_id, - .address_list = normal_i2c, -}; - -int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EPERM; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_read_byte_data(cpld_node->client, reg); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(accton_i2c_cpld_read); - -int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EIO; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(accton_i2c_cpld_write); - -static int __init accton_i2c_cpld_init(void) -{ - mutex_init(&list_lock); - return i2c_add_driver(&accton_i2c_cpld_driver); -} - -static void __exit accton_i2c_cpld_exit(void) -{ - i2c_del_driver(&accton_i2c_cpld_driver); -} -/* -static struct dmi_system_id as7712_dmi_table[] = { - { - .ident = "Accton AS7712", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS7712"), - }, - } -}; - -int platform_accton_as7712_32x(void) -{ - return dmi_check_system(as7712_dmi_table); -} -EXPORT_SYMBOL(platform_accton_as7712_32x); -*/ -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton_i2c_cpld driver"); -MODULE_LICENSE("GPL"); - -module_init(accton_i2c_cpld_init); -module_exit(accton_i2c_cpld_exit); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/cpr_4011_4mxx.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/cpr_4011_4mxx.c deleted file mode 100755 index 30bea914d589..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/cpr_4011_4mxx.c +++ /dev/null @@ -1,400 +0,0 @@ -/* - * An hwmon driver for the CPR-4011-4Mxx Redundant Power Module - * - * Copyright (C) Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#if 0 -#define DEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_FAN_DUTY_CYCLE 100 - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x3c, 0x3d, 0x3e, 0x3f, I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct cpr_4011_4mxx_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 vout_mode; /* Register value */ - u16 v_in; /* Register value */ - u16 v_out; /* Register value */ - u16 i_in; /* Register value */ - u16 i_out; /* Register value */ - u16 p_in; /* Register value */ - u16 p_out; /* Register value */ - u16 temp_input[2]; /* Register value */ - u8 fan_fault; /* Register value */ - u16 fan_duty_cycle[2]; /* Register value */ - u16 fan_speed[2]; /* Register value */ -}; - -static ssize_t show_linear(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_vout(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_fan_duty_cycle(struct device *dev, struct device_attribute *da, const char *buf, size_t count); -static int cpr_4011_4mxx_write_word(struct i2c_client *client, u8 reg, u16 value); -static struct cpr_4011_4mxx_data *cpr_4011_4mxx_update_device(struct device *dev); - -enum cpr_4011_4mxx_sysfs_attributes { - PSU_V_IN, - PSU_V_OUT, - PSU_I_IN, - PSU_I_OUT, - PSU_P_IN, - PSU_P_OUT, - PSU_TEMP1_INPUT, - PSU_FAN1_FAULT, - PSU_FAN1_DUTY_CYCLE, - PSU_FAN1_SPEED, -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_v_in, S_IRUGO, show_linear, NULL, PSU_V_IN); -static SENSOR_DEVICE_ATTR(psu_v_out, S_IRUGO, show_vout, NULL, PSU_V_OUT); -static SENSOR_DEVICE_ATTR(psu_i_in, S_IRUGO, show_linear, NULL, PSU_I_IN); -static SENSOR_DEVICE_ATTR(psu_i_out, S_IRUGO, show_linear, NULL, PSU_I_OUT); -static SENSOR_DEVICE_ATTR(psu_p_in, S_IRUGO, show_linear, NULL, PSU_P_IN); -static SENSOR_DEVICE_ATTR(psu_p_out, S_IRUGO, show_linear, NULL, PSU_P_OUT); -static SENSOR_DEVICE_ATTR(psu_temp1_input, S_IRUGO, show_linear, NULL, PSU_TEMP1_INPUT); -static SENSOR_DEVICE_ATTR(psu_fan1_fault, S_IRUGO, show_fan_fault, NULL, PSU_FAN1_FAULT); -static SENSOR_DEVICE_ATTR(psu_fan1_duty_cycle_percentage, S_IWUSR | S_IRUGO, show_linear, set_fan_duty_cycle, PSU_FAN1_DUTY_CYCLE); -static SENSOR_DEVICE_ATTR(psu_fan1_speed_rpm, S_IRUGO, show_linear, NULL, PSU_FAN1_SPEED); - -static struct attribute *cpr_4011_4mxx_attributes[] = { - &sensor_dev_attr_psu_v_in.dev_attr.attr, - &sensor_dev_attr_psu_v_out.dev_attr.attr, - &sensor_dev_attr_psu_i_in.dev_attr.attr, - &sensor_dev_attr_psu_i_out.dev_attr.attr, - &sensor_dev_attr_psu_p_in.dev_attr.attr, - &sensor_dev_attr_psu_p_out.dev_attr.attr, - &sensor_dev_attr_psu_temp1_input.dev_attr.attr, - &sensor_dev_attr_psu_fan1_fault.dev_attr.attr, - &sensor_dev_attr_psu_fan1_duty_cycle_percentage.dev_attr.attr, - &sensor_dev_attr_psu_fan1_speed_rpm.dev_attr.attr, - NULL -}; - -static int two_complement_to_int(u16 data, u8 valid_bit, int mask) -{ - u16 valid_data = data & mask; - bool is_negative = valid_data >> (valid_bit - 1); - - return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data; -} - -static ssize_t set_fan_duty_cycle(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 cpr_4011_4mxx_data *data = i2c_get_clientdata(client); - int nr = (attr->index == PSU_FAN1_DUTY_CYCLE) ? 0 : 1; - long speed; - int error; - - error = kstrtol(buf, 10, &speed); - if (error) - return error; - - if (speed < 0 || speed > MAX_FAN_DUTY_CYCLE) - return -EINVAL; - - mutex_lock(&data->update_lock); - data->fan_duty_cycle[nr] = speed; - cpr_4011_4mxx_write_word(client, 0x3B + nr, data->fan_duty_cycle[nr]); - mutex_unlock(&data->update_lock); - - return count; -} - -static ssize_t show_linear(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct cpr_4011_4mxx_data *data = cpr_4011_4mxx_update_device(dev); - - u16 value = 0; - int exponent, mantissa; - int multiplier = 1000; - - switch (attr->index) { - case PSU_V_IN: - value = data->v_in; - break; - case PSU_I_IN: - value = data->i_in; - break; - case PSU_I_OUT: - value = data->i_out; - break; - case PSU_P_IN: - value = data->p_in; - break; - case PSU_P_OUT: - value = data->p_out; - break; - case PSU_TEMP1_INPUT: - value = data->temp_input[0]; - break; - case PSU_FAN1_DUTY_CYCLE: - multiplier = 1; - value = data->fan_duty_cycle[0]; - break; - case PSU_FAN1_SPEED: - multiplier = 1; - value = data->fan_speed[0]; - break; - default: - break; - } - - exponent = two_complement_to_int(value >> 11, 5, 0x1f); - mantissa = two_complement_to_int(value & 0x7ff, 11, 0x7ff); - - return (exponent >= 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : - sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); -} - -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct cpr_4011_4mxx_data *data = cpr_4011_4mxx_update_device(dev); - - u8 shift = (attr->index == PSU_FAN1_FAULT) ? 7 : 6; - - return sprintf(buf, "%d\n", data->fan_fault >> shift); -} - -static ssize_t show_vout(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct cpr_4011_4mxx_data *data = cpr_4011_4mxx_update_device(dev); - int exponent, mantissa; - int multiplier = 1000; - - exponent = two_complement_to_int(data->vout_mode, 5, 0x1f); - mantissa = data->v_out; - - return (exponent > 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : - sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); -} - -static const struct attribute_group cpr_4011_4mxx_group = { - .attrs = cpr_4011_4mxx_attributes, -}; - -static int cpr_4011_4mxx_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct cpr_4011_4mxx_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct cpr_4011_4mxx_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &cpr_4011_4mxx_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &cpr_4011_4mxx_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int cpr_4011_4mxx_remove(struct i2c_client *client) -{ - struct cpr_4011_4mxx_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &cpr_4011_4mxx_group); - kfree(data); - - return 0; -} - -static const struct i2c_device_id cpr_4011_4mxx_id[] = { - { "cpr_4011_4mxx", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, cpr_4011_4mxx_id); - -static struct i2c_driver cpr_4011_4mxx_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "cpr_4011_4mxx", - }, - .probe = cpr_4011_4mxx_probe, - .remove = cpr_4011_4mxx_remove, - .id_table = cpr_4011_4mxx_id, - .address_list = normal_i2c, -}; - -static int cpr_4011_4mxx_read_byte(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_byte_data(client, reg); -} - -static int cpr_4011_4mxx_read_word(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_word_data(client, reg); -} - -static int cpr_4011_4mxx_write_word(struct i2c_client *client, u8 reg, u16 value) -{ - return i2c_smbus_write_word_data(client, reg, value); -} - -struct reg_data_byte { - u8 reg; - u8 *value; -}; - -struct reg_data_word { - u8 reg; - u16 *value; -}; - -static struct cpr_4011_4mxx_data *cpr_4011_4mxx_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct cpr_4011_4mxx_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int i, status; - struct reg_data_byte regs_byte[] = { {0x20, &data->vout_mode}, - {0x81, &data->fan_fault}}; - struct reg_data_word regs_word[] = { {0x88, &data->v_in}, - {0x8b, &data->v_out}, - {0x89, &data->i_in}, - {0x8c, &data->i_out}, - {0x96, &data->p_out}, - {0x97, &data->p_in}, - {0x8d, &(data->temp_input[0])}, - {0x8e, &(data->temp_input[1])}, - {0x3b, &(data->fan_duty_cycle[0])}, - {0x3c, &(data->fan_duty_cycle[1])}, - {0x90, &(data->fan_speed[0])}, - {0x91, &(data->fan_speed[1])}}; - - dev_dbg(&client->dev, "Starting cpr_4011_4mxx update\n"); - - /* Read byte data */ - for (i = 0; i < ARRAY_SIZE(regs_byte); i++) { - status = cpr_4011_4mxx_read_byte(client, regs_byte[i].reg); - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_byte[i].reg, status); - } - else { - *(regs_byte[i].value) = status; - } - } - - /* Read word data */ - for (i = 0; i < ARRAY_SIZE(regs_word); i++) { - status = cpr_4011_4mxx_read_word(client, regs_word[i].reg); - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_word[i].reg, status); - } - else { - *(regs_word[i].value) = status; - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init cpr_4011_4mxx_init(void) -{ - return i2c_add_driver(&cpr_4011_4mxx_driver); -} - -static void __exit cpr_4011_4mxx_exit(void) -{ - i2c_del_driver(&cpr_4011_4mxx_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("CPR_4011_4MXX driver"); -MODULE_LICENSE("GPL"); - -module_init(cpr_4011_4mxx_init); -module_exit(cpr_4011_4mxx_exit); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/optoe.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/optoe.c deleted file mode 100755 index 16be2fef89b1..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/optoe.c +++ /dev/null @@ -1,1148 +0,0 @@ -/* - * optoe.c - A driver to read and write the EEPROM on optical transceivers - * (SFP, QSFP and similar I2C based devices) - * - * Copyright (C) 2014 Cumulus networks Inc. - * Copyright (C) 2017 Finisar Corp. - * - * 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 Freeoftware Foundation; either version 2 of the License, or - * (at your option) any later version. - */ - -/* - * Description: - * a) Optical transceiver EEPROM read/write transactions are just like - * the at24 eeproms managed by the at24.c i2c driver - * b) The register/memory layout is up to 256 128 byte pages defined by - * a "pages valid" register and switched via a "page select" - * register as explained in below diagram. - * c) 256 bytes are mapped at a time. 'Lower page 00h' is the first 128 - * bytes of address space, and always references the same - * location, independent of the page select register. - * All mapped pages are mapped into the upper 128 bytes - * (offset 128-255) of the i2c address. - * d) Devices with one I2C address (eg QSFP) use I2C address 0x50 - * (A0h in the spec), and map all pages in the upper 128 bytes - * of that address. - * e) Devices with two I2C addresses (eg SFP) have 256 bytes of data - * at I2C address 0x50, and 256 bytes of data at I2C address - * 0x51 (A2h in the spec). Page selection and paged access - * only apply to this second I2C address (0x51). - * e) The address space is presented, by the driver, as a linear - * address space. For devices with one I2C client at address - * 0x50 (eg QSFP), offset 0-127 are in the lower - * half of address 50/A0h/client[0]. Offset 128-255 are in - * page 0, 256-383 are page 1, etc. More generally, offset - * 'n' resides in page (n/128)-1. ('page -1' is the lower - * half, offset 0-127). - * f) For devices with two I2C clients at address 0x50 and 0x51 (eg SFP), - * the address space places offset 0-127 in the lower - * half of 50/A0/client[0], offset 128-255 in the upper - * half. Offset 256-383 is in the lower half of 51/A2/client[1]. - * Offset 384-511 is in page 0, in the upper half of 51/A2/... - * Offset 512-639 is in page 1, in the upper half of 51/A2/... - * Offset 'n' is in page (n/128)-3 (for n > 383) - * - * One I2c addressed (eg QSFP) Memory Map - * - * 2-Wire Serial Address: 1010000x - * - * Lower Page 00h (128 bytes) - * ===================== - * | | - * | | - * | | - * | | - * | | - * | | - * | | - * | | - * | | - * | | - * |Page Select Byte(127)| - * ===================== - * | - * | - * | - * | - * V - * ------------------------------------------------------------ - * | | | | - * | | | | - * | | | | - * | | | | - * | | | | - * | | | | - * | | | | - * | | | | - * | | | | - * V V V V - * ------------ -------------- --------------- -------------- - * | | | | | | | | - * | Upper | | Upper | | Upper | | Upper | - * | Page 00h | | Page 01h | | Page 02h | | Page 03h | - * | | | (Optional) | | (Optional) | | (Optional | - * | | | | | | | for Cable | - * | | | | | | | Assemblies) | - * | ID | | AST | | User | | | - * | Fields | | Table | | EEPROM Data | | | - * | | | | | | | | - * | | | | | | | | - * | | | | | | | | - * ------------ -------------- --------------- -------------- - * - * The SFF 8436 (QSFP) spec only defines the 4 pages described above. - * In anticipation of future applications and devices, this driver - * supports access to the full architected range, 256 pages. - * - **/ - -/* #define DEBUG 1 */ - -#undef EEPROM_CLASS -#ifdef CONFIG_EEPROM_CLASS -#define EEPROM_CLASS -#endif -#ifdef CONFIG_EEPROM_CLASS_MODULE -#define EEPROM_CLASS -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * The optoe driver is for read/write access to the EEPROM on standard - * I2C based optical transceivers (SFP, QSFP, etc) - * - * While based on the at24 driver, it eliminates code that supports other - * types of I2C EEPROMs, and adds support for pages accessed through the - * page-select register at offset 127. - */ - -struct optoe_platform_data { - u32 byte_len; /* size (sum of all addr) */ - u16 page_size; /* for writes */ - u8 flags; - - void (*setup)(struct memory_accessor *, void *context); - void *context; -#ifdef EEPROM_CLASS - struct eeprom_platform_data *eeprom_data; /* extra data for the eeprom_class */ -#endif -}; - -#ifdef EEPROM_CLASS -#include -#endif - -#include - -/* fundamental unit of addressing for EEPROM */ -#define OPTOE_PAGE_SIZE 128 -/* - * Single address devices (eg QSFP) have 256 pages, plus the unpaged - * low 128 bytes. If the device does not support paging, it is - * only 2 'pages' long. - */ -#define OPTOE_ARCH_PAGES 256 -#define ONE_ADDR_EEPROM_SIZE ((1 + OPTOE_ARCH_PAGES) * OPTOE_PAGE_SIZE) -#define ONE_ADDR_EEPROM_UNPAGED_SIZE (2 * OPTOE_PAGE_SIZE) -/* - * Dual address devices (eg SFP) have 256 pages, plus the unpaged - * low 128 bytes, plus 256 bytes at 0x50. If the device does not - * support paging, it is 4 'pages' long. - */ -#define TWO_ADDR_EEPROM_SIZE ((3 + OPTOE_ARCH_PAGES) * OPTOE_PAGE_SIZE) -#define TWO_ADDR_EEPROM_UNPAGED_SIZE (4 * OPTOE_PAGE_SIZE) - -/* a few constants to find our way around the EEPROM */ -#define OPTOE_PAGE_SELECT_REG 0x7F -#define ONE_ADDR_PAGEABLE_REG 0x02 -#define ONE_ADDR_NOT_PAGEABLE (1<<2) -#define TWO_ADDR_PAGEABLE_REG 0x40 -#define TWO_ADDR_PAGEABLE (1<<4) -#define OPTOE_ID_REG 0 - -/* The maximum length of a port name */ -#define MAX_PORT_NAME_LEN 20 -struct optoe_data { - struct optoe_platform_data chip; - struct memory_accessor macc; - int use_smbus; - char port_name[MAX_PORT_NAME_LEN]; - - /* - * Lock protects against activities from other Linux tasks, - * but not from changes by other I2C masters. - */ - struct mutex lock; - struct bin_attribute bin; - struct attribute_group attr_group; - - u8 *writebuf; - unsigned write_max; - - unsigned num_addresses; - -#ifdef EEPROM_CLASS - struct eeprom_device *eeprom_dev; -#endif - - /* dev_class: ONE_ADDR (QSFP) or TWO_ADDR (SFP) */ - int dev_class; - - struct i2c_client *client[]; -}; - -typedef enum optoe_opcode { - OPTOE_READ_OP = 0, - OPTOE_WRITE_OP = 1 -} optoe_opcode_e; - -/* - * This parameter is to help this driver avoid blocking other drivers out - * of I2C for potentially troublesome amounts of time. With a 100 kHz I2C - * clock, one 256 byte read takes about 1/43 second which is excessive; - * but the 1/170 second it takes at 400 kHz may be quite reasonable; and - * at 1 MHz (Fm+) a 1/430 second delay could easily be invisible. - * - * This value is forced to be a power of two so that writes align on pages. - */ -static unsigned io_limit = OPTOE_PAGE_SIZE; - -/* - * specs often allow 5 msec for a page write, sometimes 20 msec; - * it's important to recover from write timeouts. - */ -static unsigned write_timeout = 25; - -/* - * flags to distinguish one-address (QSFP family) from two-address (SFP family) - * If the family is not known, figure it out when the device is accessed - */ -#define ONE_ADDR 1 -#define TWO_ADDR 2 - -static const struct i2c_device_id optoe_ids[] = { - { "optoe1", ONE_ADDR }, - { "optoe2", TWO_ADDR }, - { "sff8436", ONE_ADDR }, - { "24c04", TWO_ADDR }, - { /* END OF LIST */ } -}; -MODULE_DEVICE_TABLE(i2c, optoe_ids); - -/*-------------------------------------------------------------------------*/ -/* - * This routine computes the addressing information to be used for - * a given r/w request. - * - * Task is to calculate the client (0 = i2c addr 50, 1 = i2c addr 51), - * the page, and the offset. - * - * Handles both single address (eg QSFP) and two address (eg SFP). - * For SFP, offset 0-255 are on client[0], >255 is on client[1] - * Offset 256-383 are on the lower half of client[1] - * Pages are accessible on the upper half of client[1]. - * Offset >383 are in 128 byte pages mapped into the upper half - * - * For QSFP, all offsets are on client[0] - * offset 0-127 are on the lower half of client[0] (no paging) - * Pages are accessible on the upper half of client[1]. - * Offset >127 are in 128 byte pages mapped into the upper half - * - * Callers must not read/write beyond the end of a client or a page - * without recomputing the client/page. Hence offset (within page) - * plus length must be less than or equal to 128. (Note that this - * routine does not have access to the length of the call, hence - * cannot do the validity check.) - * - * Offset within Lower Page 00h and Upper Page 00h are not recomputed - */ - -static uint8_t optoe_translate_offset(struct optoe_data *optoe, - loff_t *offset, struct i2c_client **client) -{ - unsigned page = 0; - - *client = optoe->client[0]; - - /* if SFP style, offset > 255, shift to i2c addr 0x51 */ - if (optoe->dev_class == TWO_ADDR) { - if (*offset > 255) { - /* like QSFP, but shifted to client[1] */ - *client = optoe->client[1]; - *offset -= 256; - } - } - - /* - * if offset is in the range 0-128... - * page doesn't matter (using lower half), return 0. - * offset is already correct (don't add 128 to get to paged area) - */ - if (*offset < OPTOE_PAGE_SIZE) - return page; - - /* note, page will always be positive since *offset >= 128 */ - page = (*offset >> 7)-1; - /* 0x80 places the offset in the top half, offset is last 7 bits */ - *offset = OPTOE_PAGE_SIZE + (*offset & 0x7f); - - return page; /* note also returning client and offset */ -} - -static ssize_t optoe_eeprom_read(struct optoe_data *optoe, - struct i2c_client *client, - char *buf, unsigned offset, size_t count) -{ - struct i2c_msg msg[2]; - u8 msgbuf[2]; - unsigned long timeout, read_time; - int status, i; - - memset(msg, 0, sizeof(msg)); - - switch (optoe->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - /*smaller eeproms can work given some SMBus extension calls */ - if (count > I2C_SMBUS_BLOCK_MAX) - count = I2C_SMBUS_BLOCK_MAX; - break; - case I2C_SMBUS_WORD_DATA: - /* Check for odd length transaction */ - count = (count == 1) ? 1 : 2; - break; - case I2C_SMBUS_BYTE_DATA: - count = 1; - break; - default: - /* - * When we have a better choice than SMBus calls, use a - * combined I2C message. Write address; then read up to - * io_limit data bytes. msgbuf is u8 and will cast to our - * needs. - */ - i = 0; - msgbuf[i++] = offset; - - msg[0].addr = client->addr; - msg[0].buf = msgbuf; - msg[0].len = i; - - msg[1].addr = client->addr; - msg[1].flags = I2C_M_RD; - msg[1].buf = buf; - msg[1].len = count; - } - - /* - * Reads fail if the previous write didn't complete yet. We may - * loop a few times until this one succeeds, waiting at least - * long enough for one entire page write to work. - */ - timeout = jiffies + msecs_to_jiffies(write_timeout); - do { - read_time = jiffies; - - switch (optoe->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - status = i2c_smbus_read_i2c_block_data(client, offset, - count, buf); - break; - case I2C_SMBUS_WORD_DATA: - status = i2c_smbus_read_word_data(client, offset); - if (status >= 0) { - buf[0] = status & 0xff; - if (count == 2) - buf[1] = status >> 8; - status = count; - } - break; - case I2C_SMBUS_BYTE_DATA: - status = i2c_smbus_read_byte_data(client, offset); - if (status >= 0) { - buf[0] = status; - status = count; - } - break; - default: - status = i2c_transfer(client->adapter, msg, 2); - if (status == 2) - status = count; - } - - dev_dbg(&client->dev, "eeprom read %zu@%d --> %d (%ld)\n", - count, offset, status, jiffies); - - if (status == count) /* happy path */ - return count; - - if (status == -ENXIO) /* no module present */ - return status; - - /* REVISIT: at HZ=100, this is sloooow */ - msleep(1); - } while (time_before(read_time, timeout)); - - return -ETIMEDOUT; -} - -static ssize_t optoe_eeprom_write(struct optoe_data *optoe, - struct i2c_client *client, - const char *buf, - unsigned offset, size_t count) -{ - struct i2c_msg msg; - ssize_t status; - unsigned long timeout, write_time; - unsigned next_page_start; - int i = 0; - - /* write max is at most a page - * (In this driver, write_max is actually one byte!) - */ - if (count > optoe->write_max) - count = optoe->write_max; - - /* shorten count if necessary to avoid crossing page boundary */ - next_page_start = roundup(offset + 1, OPTOE_PAGE_SIZE); - if (offset + count > next_page_start) - count = next_page_start - offset; - - switch (optoe->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - /*smaller eeproms can work given some SMBus extension calls */ - if (count > I2C_SMBUS_BLOCK_MAX) - count = I2C_SMBUS_BLOCK_MAX; - break; - case I2C_SMBUS_WORD_DATA: - /* Check for odd length transaction */ - count = (count == 1) ? 1 : 2; - break; - case I2C_SMBUS_BYTE_DATA: - count = 1; - break; - default: - /* If we'll use I2C calls for I/O, set up the message */ - msg.addr = client->addr; - msg.flags = 0; - - /* msg.buf is u8 and casts will mask the values */ - msg.buf = optoe->writebuf; - - msg.buf[i++] = offset; - memcpy(&msg.buf[i], buf, count); - msg.len = i + count; - break; - } - - /* - * Reads fail if the previous write didn't complete yet. We may - * loop a few times until this one succeeds, waiting at least - * long enough for one entire page write to work. - */ - timeout = jiffies + msecs_to_jiffies(write_timeout); - do { - write_time = jiffies; - - switch (optoe->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - status = i2c_smbus_write_i2c_block_data(client, - offset, count, buf); - if (status == 0) - status = count; - break; - case I2C_SMBUS_WORD_DATA: - if (count == 2) { - status = i2c_smbus_write_word_data(client, - offset, (u16)((buf[0])|(buf[1] << 8))); - } else { - /* count = 1 */ - status = i2c_smbus_write_byte_data(client, - offset, buf[0]); - } - if (status == 0) - status = count; - break; - case I2C_SMBUS_BYTE_DATA: - status = i2c_smbus_write_byte_data(client, offset, - buf[0]); - if (status == 0) - status = count; - break; - default: - status = i2c_transfer(client->adapter, &msg, 1); - if (status == 1) - status = count; - break; - } - - dev_dbg(&client->dev, "eeprom write %zu@%d --> %ld (%lu)\n", - count, offset, (long int) status, jiffies); - - if (status == count) - return count; - - /* REVISIT: at HZ=100, this is sloooow */ - msleep(1); - } while (time_before(write_time, timeout)); - - return -ETIMEDOUT; -} - - -static ssize_t optoe_eeprom_update_client(struct optoe_data *optoe, - char *buf, loff_t off, - size_t count, optoe_opcode_e opcode) -{ - struct i2c_client *client; - ssize_t retval = 0; - uint8_t page = 0; - loff_t phy_offset = off; - int ret = 0; - - page = optoe_translate_offset(optoe, &phy_offset, &client); - dev_dbg(&client->dev, - "optoe_eeprom_update_client off %lld page:%d phy_offset:%lld, count:%ld, opcode:%d\n", - off, page, phy_offset, (long int) count, opcode); - if (page > 0) { - ret = optoe_eeprom_write(optoe, client, &page, - OPTOE_PAGE_SELECT_REG, 1); - if (ret < 0) { - dev_dbg(&client->dev, - "Write page register for page %d failed ret:%d!\n", - page, ret); - return ret; - } - } - - while (count) { - ssize_t status; - - if (opcode == OPTOE_READ_OP) { - status = optoe_eeprom_read(optoe, client, - buf, phy_offset, count); - } else { - status = optoe_eeprom_write(optoe, client, - buf, phy_offset, count); - } - if (status <= 0) { - if (retval == 0) - retval = status; - break; - } - buf += status; - phy_offset += status; - count -= status; - retval += status; - } - - - if (page > 0) { - /* return the page register to page 0 (why?) */ - page = 0; - ret = optoe_eeprom_write(optoe, client, &page, - OPTOE_PAGE_SELECT_REG, 1); - if (ret < 0) { - dev_err(&client->dev, - "Restore page register to 0 failed:%d!\n", ret); - /* error only if nothing has been transferred */ - if (retval == 0) retval = ret; - } - } - return retval; -} - -/* - * Figure out if this access is within the range of supported pages. - * Note this is called on every access because we don't know if the - * module has been replaced since the last call. - * If/when modules support more pages, this is the routine to update - * to validate and allow access to additional pages. - * - * Returns updated len for this access: - * - entire access is legal, original len is returned. - * - access begins legal but is too long, len is truncated to fit. - * - initial offset exceeds supported pages, return -EINVAL - */ -static ssize_t optoe_page_legal(struct optoe_data *optoe, - loff_t off, size_t len) -{ - struct i2c_client *client = optoe->client[0]; - u8 regval; - int status; - size_t maxlen; - - if (off < 0) return -EINVAL; - if (optoe->dev_class == TWO_ADDR) { - /* SFP case */ - /* if no pages needed, we're good */ - if ((off + len) <= TWO_ADDR_EEPROM_UNPAGED_SIZE) return len; - /* if offset exceeds possible pages, we're not good */ - if (off >= TWO_ADDR_EEPROM_SIZE) return -EINVAL; - /* in between, are pages supported? */ - status = optoe_eeprom_read(optoe, client, ®val, - TWO_ADDR_PAGEABLE_REG, 1); - if (status < 0) return status; /* error out (no module?) */ - if (regval & TWO_ADDR_PAGEABLE) { - /* Pages supported, trim len to the end of pages */ - maxlen = TWO_ADDR_EEPROM_SIZE - off; - } else { - /* pages not supported, trim len to unpaged size */ - if (off >= TWO_ADDR_EEPROM_UNPAGED_SIZE) return -EINVAL; - maxlen = TWO_ADDR_EEPROM_UNPAGED_SIZE - off; - } - len = (len > maxlen) ? maxlen : len; - dev_dbg(&client->dev, - "page_legal, SFP, off %lld len %ld\n", - off, (long int) len); - } else { - /* QSFP case */ - /* if no pages needed, we're good */ - if ((off + len) <= ONE_ADDR_EEPROM_UNPAGED_SIZE) return len; - /* if offset exceeds possible pages, we're not good */ - if (off >= ONE_ADDR_EEPROM_SIZE) return -EINVAL; - /* in between, are pages supported? */ - status = optoe_eeprom_read(optoe, client, ®val, - ONE_ADDR_PAGEABLE_REG, 1); - if (status < 0) return status; /* error out (no module?) */ - if (regval & ONE_ADDR_NOT_PAGEABLE) { - /* pages not supported, trim len to unpaged size */ - if (off >= ONE_ADDR_EEPROM_UNPAGED_SIZE) return -EINVAL; - maxlen = ONE_ADDR_EEPROM_UNPAGED_SIZE - off; - } else { - /* Pages supported, trim len to the end of pages */ - maxlen = ONE_ADDR_EEPROM_SIZE - off; - } - len = (len > maxlen) ? maxlen : len; - dev_dbg(&client->dev, - "page_legal, QSFP, off %lld len %ld\n", - off, (long int) len); - } - return len; -} - -static ssize_t optoe_read_write(struct optoe_data *optoe, - char *buf, loff_t off, size_t len, optoe_opcode_e opcode) -{ - struct i2c_client *client = optoe->client[0]; - int chunk; - int status = 0; - ssize_t retval; - size_t pending_len = 0, chunk_len = 0; - loff_t chunk_offset = 0, chunk_start_offset = 0; - - dev_dbg(&client->dev, - "optoe_read_write: off %lld len:%ld, opcode:%s\n", - off, (long int) len, (opcode == OPTOE_READ_OP) ? "r": "w"); - if (unlikely(!len)) - return len; - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&optoe->lock); - - /* - * Confirm this access fits within the device suppored addr range - */ - status = optoe_page_legal(optoe, off, len); - if (status < 0) { - goto err; - } - len = status; - - /* - * For each (128 byte) chunk involved in this request, issue a - * separate call to sff_eeprom_update_client(), to - * ensure that each access recalculates the client/page - * and writes the page register as needed. - * Note that chunk to page mapping is confusing, is different for - * QSFP and SFP, and never needs to be done. Don't try! - */ - pending_len = len; /* amount remaining to transfer */ - retval = 0; /* amount transferred */ - for (chunk = off >> 7; chunk <= (off + len - 1) >> 7; chunk++) { - - /* - * Compute the offset and number of bytes to be read/write - * - * 1. start at offset 0 (within the chunk), and read/write - * the entire chunk - * 2. start at offset 0 (within the chunk) and read/write less - * than entire chunk - * 3. start at an offset not equal to 0 and read/write the rest - * of the chunk - * 4. start at an offset not equal to 0 and read/write less than - * (end of chunk - offset) - */ - chunk_start_offset = chunk * OPTOE_PAGE_SIZE; - - if (chunk_start_offset < off) { - chunk_offset = off; - if ((off + pending_len) < (chunk_start_offset + - OPTOE_PAGE_SIZE)) - chunk_len = pending_len; - else - chunk_len = OPTOE_PAGE_SIZE - off; - } else { - chunk_offset = chunk_start_offset; - if (pending_len > OPTOE_PAGE_SIZE) - chunk_len = OPTOE_PAGE_SIZE; - else - chunk_len = pending_len; - } - - dev_dbg(&client->dev, - "sff_r/w: off %lld, len %ld, chunk_start_offset %lld, chunk_offset %lld, chunk_len %ld, pending_len %ld\n", - off, (long int) len, chunk_start_offset, chunk_offset, - (long int) chunk_len, (long int) pending_len); - - /* - * note: chunk_offset is from the start of the EEPROM, - * not the start of the chunk - */ - status = optoe_eeprom_update_client(optoe, buf, - chunk_offset, chunk_len, opcode); - if (status != chunk_len) { - /* This is another 'no device present' path */ - dev_dbg(&client->dev, - "optoe_update_client for chunk %d chunk_offset %lld chunk_len %ld failed %d!\n", - chunk, chunk_offset, (long int) chunk_len, status); - goto err; - } - buf += status; - pending_len -= status; - retval += status; - } - mutex_unlock(&optoe->lock); - - return retval; - -err: - mutex_unlock(&optoe->lock); - - return status; -} - -static ssize_t optoe_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - struct i2c_client *client = to_i2c_client(container_of(kobj, - struct device, kobj)); - struct optoe_data *optoe = i2c_get_clientdata(client); - - return optoe_read_write(optoe, buf, off, count, OPTOE_READ_OP); -} - - -static ssize_t optoe_bin_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - struct i2c_client *client = to_i2c_client(container_of(kobj, - struct device, kobj)); - struct optoe_data *optoe = i2c_get_clientdata(client); - - return optoe_read_write(optoe, buf, off, count, OPTOE_WRITE_OP); -} -/*-------------------------------------------------------------------------*/ - -/* - * This lets other kernel code access the eeprom data. For example, it - * might hold a board's Ethernet address, or board-specific calibration - * data generated on the manufacturing floor. - */ - -static ssize_t optoe_macc_read(struct memory_accessor *macc, - char *buf, off_t offset, size_t count) -{ - struct optoe_data *optoe = container_of(macc, - struct optoe_data, macc); - - return optoe_read_write(optoe, buf, offset, count, OPTOE_READ_OP); -} - -static ssize_t optoe_macc_write(struct memory_accessor *macc, - const char *buf, off_t offset, size_t count) -{ - struct optoe_data *optoe = container_of(macc, - struct optoe_data, macc); - - return optoe_read_write(optoe, (char *) buf, offset, - count, OPTOE_WRITE_OP); -} - -/*-------------------------------------------------------------------------*/ - -static int optoe_remove(struct i2c_client *client) -{ - struct optoe_data *optoe; - int i; - - optoe = i2c_get_clientdata(client); - sysfs_remove_group(&client->dev.kobj, &optoe->attr_group); - sysfs_remove_bin_file(&client->dev.kobj, &optoe->bin); - - for (i = 1; i < optoe->num_addresses; i++) - i2c_unregister_device(optoe->client[i]); - -#ifdef EEPROM_CLASS - eeprom_device_unregister(optoe->eeprom_dev); -#endif - - kfree(optoe->writebuf); - kfree(optoe); - return 0; -} - -static ssize_t show_port_name(struct device *dev, - struct device_attribute *dattr, char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct optoe_data *optoe = i2c_get_clientdata(client); - ssize_t count; - - mutex_lock(&optoe->lock); - count = sprintf(buf, "%s\n", optoe->port_name); - mutex_unlock(&optoe->lock); - - return count; -} - -static ssize_t set_port_name(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct optoe_data *optoe = i2c_get_clientdata(client); - char port_name[MAX_PORT_NAME_LEN]; - - /* no checking, this value is not used except by show_port_name */ - - if (sscanf(buf, "%19s", port_name) != 1) - return -EINVAL; - - mutex_lock(&optoe->lock); - strcpy(optoe->port_name, port_name); - mutex_unlock(&optoe->lock); - - return count; -} - -static DEVICE_ATTR(port_name, S_IRUGO | S_IWUSR, - show_port_name, set_port_name); - -static ssize_t show_dev_class(struct device *dev, - struct device_attribute *dattr, char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct optoe_data *optoe = i2c_get_clientdata(client); - ssize_t count; - - mutex_lock(&optoe->lock); - count = sprintf(buf, "%d\n", optoe->dev_class); - mutex_unlock(&optoe->lock); - - return count; -} - -static ssize_t set_dev_class(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct optoe_data *optoe = i2c_get_clientdata(client); - int dev_class; - - /* - * dev_class is actually the number of sfp ports used, thus - * legal values are "1" (QSFP class) and "2" (SFP class) - */ - if (sscanf(buf, "%d", &dev_class) != 1 || - dev_class < 1 || dev_class > 2) - return -EINVAL; - - mutex_lock(&optoe->lock); - optoe->dev_class = dev_class; - mutex_unlock(&optoe->lock); - - return count; -} - -static DEVICE_ATTR(dev_class, S_IRUGO | S_IWUSR, - show_dev_class, set_dev_class); - -static struct attribute *optoe_attrs[] = { - &dev_attr_port_name.attr, - &dev_attr_dev_class.attr, - NULL, -}; - -static struct attribute_group optoe_attr_group = { - .attrs = optoe_attrs, -}; - -static int optoe_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - int err; - int use_smbus = 0; - struct optoe_platform_data chip; - struct optoe_data *optoe; - int num_addresses = 0; - int i = 0; - - if (client->addr != 0x50) { - dev_dbg(&client->dev, "probe, bad i2c addr: 0x%x\n", - client->addr); - err = -EINVAL; - goto exit; - } - - if (client->dev.platform_data) { - chip = *(struct optoe_platform_data *)client->dev.platform_data; - dev_dbg(&client->dev, "probe, chip provided, flags:0x%x; name: %s\n", chip.flags, client->name); - } else { - if (!id->driver_data) { - err = -ENODEV; - goto exit; - } - dev_dbg(&client->dev, "probe, building chip\n"); - chip.flags = 0; - chip.setup = NULL; - chip.context = NULL; -#ifdef EEPROM_CLASS - chip.eeprom_data = NULL; -#endif - } - - /* Use I2C operations unless we're stuck with SMBus extensions. */ - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { - if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { - use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_WORD_DATA)) { - use_smbus = I2C_SMBUS_WORD_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_BYTE_DATA)) { - use_smbus = I2C_SMBUS_BYTE_DATA; - } else { - err = -EPFNOSUPPORT; - goto exit; - } - } - - - /* - * Make room for two i2c clients - */ - num_addresses = 2; - - optoe = kzalloc(sizeof(struct optoe_data) + - num_addresses * sizeof(struct i2c_client *), - GFP_KERNEL); - if (!optoe) { - err = -ENOMEM; - goto exit; - } - - mutex_init(&optoe->lock); - - /* determine whether this is a one-address or two-address module */ - if ((strcmp(client->name, "optoe1") == 0) || - (strcmp(client->name, "sff8436") == 0)) { - /* one-address (eg QSFP) family */ - optoe->dev_class = ONE_ADDR; - chip.byte_len = ONE_ADDR_EEPROM_SIZE; - num_addresses = 1; - } else if ((strcmp(client->name, "optoe2") == 0) || - (strcmp(client->name, "24c04") == 0)) { - /* SFP family */ - optoe->dev_class = TWO_ADDR; - chip.byte_len = TWO_ADDR_EEPROM_SIZE; - } else { /* those were the only two choices */ - err = -EINVAL; - goto exit; - } - - dev_dbg(&client->dev, "dev_class: %d\n", optoe->dev_class); - optoe->use_smbus = use_smbus; - optoe->chip = chip; - optoe->num_addresses = num_addresses; - strcpy(optoe->port_name, "unitialized"); - - /* - * Export the EEPROM bytes through sysfs, since that's convenient. - * By default, only root should see the data (maybe passwords etc) - */ - sysfs_bin_attr_init(&optoe->bin); - optoe->bin.attr.name = "eeprom"; - optoe->bin.attr.mode = S_IRUGO; - optoe->bin.read = optoe_bin_read; - optoe->bin.size = chip.byte_len; - - optoe->macc.read = optoe_macc_read; - - if (!use_smbus || - (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) || - i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_WORD_DATA) || - i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) { - /* - * NOTE: AN-2079 - * Finisar recommends that the host implement 1 byte writes - * only since this module only supports 32 byte page boundaries. - * 2 byte writes are acceptable for PE and Vout changes per - * Application Note AN-2071. - */ - unsigned write_max = 1; - - optoe->macc.write = optoe_macc_write; - - optoe->bin.write = optoe_bin_write; - optoe->bin.attr.mode |= S_IWUSR; - - if (write_max > io_limit) - write_max = io_limit; - if (use_smbus && write_max > I2C_SMBUS_BLOCK_MAX) - write_max = I2C_SMBUS_BLOCK_MAX; - optoe->write_max = write_max; - - /* buffer (data + address at the beginning) */ - optoe->writebuf = kmalloc(write_max + 2, GFP_KERNEL); - if (!optoe->writebuf) { - err = -ENOMEM; - goto exit_kfree; - } - } else { - dev_warn(&client->dev, - "cannot write due to controller restrictions."); - } - - optoe->client[0] = client; - - /* use a dummy I2C device for two-address chips */ - for (i = 1; i < num_addresses; i++) { - optoe->client[i] = i2c_new_dummy(client->adapter, - client->addr + i); - if (!optoe->client[i]) { - dev_err(&client->dev, "address 0x%02x unavailable\n", - client->addr + i); - err = -EADDRINUSE; - goto err_struct; - } - } - - /* create the sysfs eeprom file */ - err = sysfs_create_bin_file(&client->dev.kobj, &optoe->bin); - if (err) - goto err_struct; - - optoe->attr_group = optoe_attr_group; - - err = sysfs_create_group(&client->dev.kobj, &optoe->attr_group); - if (err) { - dev_err(&client->dev, "failed to create sysfs attribute group.\n"); - goto err_struct; - } -#ifdef EEPROM_CLASS - optoe->eeprom_dev = eeprom_device_register(&client->dev, - chip.eeprom_data); - if (IS_ERR(optoe->eeprom_dev)) { - dev_err(&client->dev, "error registering eeprom device.\n"); - err = PTR_ERR(optoe->eeprom_dev); - goto err_sysfs_cleanup; - } -#endif - - i2c_set_clientdata(client, optoe); - - dev_info(&client->dev, "%zu byte %s EEPROM, %s\n", - optoe->bin.size, client->name, - optoe->bin.write ? "read/write" : "read-only"); - - if (use_smbus == I2C_SMBUS_WORD_DATA || - use_smbus == I2C_SMBUS_BYTE_DATA) { - dev_notice(&client->dev, "Falling back to %s reads, " - "performance will suffer\n", use_smbus == - I2C_SMBUS_WORD_DATA ? "word" : "byte"); - } - - if (chip.setup) - chip.setup(&optoe->macc, chip.context); - - return 0; - -#ifdef EEPROM_CLASS -err_sysfs_cleanup: - sysfs_remove_group(&client->dev.kobj, &optoe->attr_group); - sysfs_remove_bin_file(&client->dev.kobj, &optoe->bin); -#endif - -err_struct: - for (i = 1; i < num_addresses; i++) { - if (optoe->client[i]) - i2c_unregister_device(optoe->client[i]); - } - - kfree(optoe->writebuf); -exit_kfree: - kfree(optoe); -exit: - dev_dbg(&client->dev, "probe error %d\n", err); - - return err; -} - -/*-------------------------------------------------------------------------*/ - -static struct i2c_driver optoe_driver = { - .driver = { - .name = "optoe", - .owner = THIS_MODULE, - }, - .probe = optoe_probe, - .remove = optoe_remove, - .id_table = optoe_ids, -}; - -static int __init optoe_init(void) -{ - - if (!io_limit) { - pr_err("optoe: io_limit must not be 0!\n"); - return -EINVAL; - } - - io_limit = rounddown_pow_of_two(io_limit); - return i2c_add_driver(&optoe_driver); -} -module_init(optoe_init); - -static void __exit optoe_exit(void) -{ - i2c_del_driver(&optoe_driver); -} -module_exit(optoe_exit); - -MODULE_DESCRIPTION("Driver for optical transceiver (SFP, QSFP, ...) EEPROMs"); -MODULE_AUTHOR("DON BOLLINGER "); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/ym2651y.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/ym2651y.c deleted file mode 100755 index 8e76c56b54fc..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/modules/ym2651y.c +++ /dev/null @@ -1,603 +0,0 @@ -/* - * An hwmon driver for the 3Y Power YM-2651Y Power Module - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_FAN_DUTY_CYCLE 100 - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x58, 0x5b, I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct ym2651y_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 capability; /* Register value */ - u16 status_word; /* Register value */ - u8 fan_fault; /* Register value */ - u8 over_temp; /* Register value */ - u16 v_out; /* Register value */ - u16 i_out; /* Register value */ - u16 p_out; /* Register value */ - u16 temp; /* Register value */ - u16 fan_speed; /* Register value */ - u16 fan_duty_cycle[2]; /* Register value */ - u8 fan_dir[4]; /* Register value */ - u8 pmbus_revision; /* Register value */ - u8 mfr_id[10]; /* Register value */ - u8 mfr_model[10]; /* Register value */ - u8 mfr_revsion[3]; /* Register value */ - u16 mfr_vin_min; /* Register value */ - u16 mfr_vin_max; /* Register value */ - u16 mfr_iin_max; /* Register value */ - u16 mfr_iout_max; /* Register value */ - u16 mfr_pin_max; /* Register value */ - u16 mfr_pout_max; /* Register value */ - u16 mfr_vout_min; /* Register value */ - u16 mfr_vout_max; /* Register value */ -}; - -static ssize_t show_byte(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_word(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_linear(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_over_temp(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_ascii(struct device *dev, struct device_attribute *da, - char *buf); -static struct ym2651y_data *ym2651y_update_device(struct device *dev); -static ssize_t set_fan_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static int ym2651y_write_word(struct i2c_client *client, u8 reg, u16 value); - -enum ym2651y_sysfs_attributes { - PSU_POWER_ON = 0, - PSU_TEMP_FAULT, - PSU_POWER_GOOD, - PSU_FAN1_FAULT, - PSU_FAN_DIRECTION, - PSU_OVER_TEMP, - PSU_V_OUT, - PSU_I_OUT, - PSU_P_OUT, - PSU_P_OUT_UV, /*In Unit of microVolt, instead of mini.*/ - PSU_TEMP1_INPUT, - PSU_FAN1_SPEED, - PSU_FAN1_DUTY_CYCLE, - PSU_PMBUS_REVISION, - PSU_MFR_ID, - PSU_MFR_MODEL, - PSU_MFR_REVISION, - PSU_MFR_VIN_MIN, - PSU_MFR_VIN_MAX, - PSU_MFR_VOUT_MIN, - PSU_MFR_VOUT_MAX, - PSU_MFR_IIN_MAX, - PSU_MFR_IOUT_MAX, - PSU_MFR_PIN_MAX, - PSU_MFR_POUT_MAX -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_power_on, S_IRUGO, show_word, NULL, PSU_POWER_ON); -static SENSOR_DEVICE_ATTR(psu_temp_fault, S_IRUGO, show_word, NULL, PSU_TEMP_FAULT); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_word, NULL, PSU_POWER_GOOD); -static SENSOR_DEVICE_ATTR(psu_fan1_fault, S_IRUGO, show_fan_fault, NULL, PSU_FAN1_FAULT); -static SENSOR_DEVICE_ATTR(psu_over_temp, S_IRUGO, show_over_temp, NULL, PSU_OVER_TEMP); -static SENSOR_DEVICE_ATTR(psu_v_out, S_IRUGO, show_linear, NULL, PSU_V_OUT); -static SENSOR_DEVICE_ATTR(psu_i_out, S_IRUGO, show_linear, NULL, PSU_I_OUT); -static SENSOR_DEVICE_ATTR(psu_p_out, S_IRUGO, show_linear, NULL, PSU_P_OUT); -static SENSOR_DEVICE_ATTR(psu_temp1_input, S_IRUGO, show_linear, NULL, PSU_TEMP1_INPUT); -static SENSOR_DEVICE_ATTR(psu_fan1_speed_rpm, S_IRUGO, show_linear, NULL, PSU_FAN1_SPEED); -static SENSOR_DEVICE_ATTR(psu_fan1_duty_cycle_percentage, S_IWUSR | S_IRUGO, show_linear, set_fan_duty_cycle, PSU_FAN1_DUTY_CYCLE); -static SENSOR_DEVICE_ATTR(psu_fan_dir, S_IRUGO, show_ascii, NULL, PSU_FAN_DIRECTION); -static SENSOR_DEVICE_ATTR(psu_pmbus_revision, S_IRUGO, show_byte, NULL, PSU_PMBUS_REVISION); -static SENSOR_DEVICE_ATTR(psu_mfr_id, S_IRUGO, show_ascii, NULL, PSU_MFR_ID); -static SENSOR_DEVICE_ATTR(psu_mfr_model, S_IRUGO, show_ascii, NULL, PSU_MFR_MODEL); -static SENSOR_DEVICE_ATTR(psu_mfr_revision, S_IRUGO, show_ascii, NULL, PSU_MFR_REVISION); -static SENSOR_DEVICE_ATTR(psu_mfr_vin_min, S_IRUGO, show_linear, NULL, PSU_MFR_VIN_MIN); -static SENSOR_DEVICE_ATTR(psu_mfr_vin_max, S_IRUGO, show_linear, NULL, PSU_MFR_VIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_vout_min, S_IRUGO, show_linear, NULL, PSU_MFR_VOUT_MIN); -static SENSOR_DEVICE_ATTR(psu_mfr_vout_max, S_IRUGO, show_linear, NULL, PSU_MFR_VOUT_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_iin_max, S_IRUGO, show_linear, NULL, PSU_MFR_IIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_iout_max, S_IRUGO, show_linear, NULL, PSU_MFR_IOUT_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_pin_max, S_IRUGO, show_linear, NULL, PSU_MFR_PIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_pout_max, S_IRUGO, show_linear, NULL, PSU_MFR_POUT_MAX); - -/*Duplicate nodes for lm-sensors.*/ -static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, show_linear, NULL, PSU_P_OUT_UV); -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_linear, NULL, PSU_TEMP1_INPUT); -static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_linear, NULL, PSU_FAN1_SPEED); -static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_word, NULL, PSU_TEMP_FAULT); - -static struct attribute *ym2651y_attributes[] = { - &sensor_dev_attr_psu_power_on.dev_attr.attr, - &sensor_dev_attr_psu_temp_fault.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - &sensor_dev_attr_psu_fan1_fault.dev_attr.attr, - &sensor_dev_attr_psu_over_temp.dev_attr.attr, - &sensor_dev_attr_psu_v_out.dev_attr.attr, - &sensor_dev_attr_psu_i_out.dev_attr.attr, - &sensor_dev_attr_psu_p_out.dev_attr.attr, - &sensor_dev_attr_psu_temp1_input.dev_attr.attr, - &sensor_dev_attr_psu_fan1_speed_rpm.dev_attr.attr, - &sensor_dev_attr_psu_fan1_duty_cycle_percentage.dev_attr.attr, - &sensor_dev_attr_psu_fan_dir.dev_attr.attr, - &sensor_dev_attr_psu_pmbus_revision.dev_attr.attr, - &sensor_dev_attr_psu_mfr_id.dev_attr.attr, - &sensor_dev_attr_psu_mfr_model.dev_attr.attr, - &sensor_dev_attr_psu_mfr_revision.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vin_min.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_pout_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_iin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_pin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vout_min.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vout_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_iout_max.dev_attr.attr, - /*Duplicate nodes for lm-sensors.*/ - &sensor_dev_attr_power1_input.dev_attr.attr, - &sensor_dev_attr_temp1_input.dev_attr.attr, - &sensor_dev_attr_fan1_input.dev_attr.attr, - &sensor_dev_attr_temp1_fault.dev_attr.attr, - NULL -}; - -static ssize_t show_byte(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - - return (attr->index == PSU_PMBUS_REVISION) ? sprintf(buf, "%d\n", data->pmbus_revision) : - sprintf(buf, "0\n"); -} - -static ssize_t show_word(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - u16 status = 0; - - switch (attr->index) { - case PSU_POWER_ON: /* psu_power_on, low byte bit 6 of status_word, 0=>ON, 1=>OFF */ - status = (data->status_word & 0x40) ? 0 : 1; - break; - case PSU_TEMP_FAULT: /* psu_temp_fault, low byte bit 2 of status_word, 0=>Normal, 1=>temp fault */ - status = (data->status_word & 0x4) >> 2; - break; - case PSU_POWER_GOOD: /* psu_power_good, high byte bit 3 of status_word, 0=>OK, 1=>FAIL */ - status = (data->status_word & 0x800) ? 0 : 1; - break; - } - - return sprintf(buf, "%d\n", status); -} - -static int two_complement_to_int(u16 data, u8 valid_bit, int mask) -{ - u16 valid_data = data & mask; - bool is_negative = valid_data >> (valid_bit - 1); - - return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data; -} - -static ssize_t set_fan_duty_cycle(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 ym2651y_data *data = i2c_get_clientdata(client); - int nr = (attr->index == PSU_FAN1_DUTY_CYCLE) ? 0 : 1; - long speed; - int error; - - error = kstrtol(buf, 10, &speed); - if (error) - return error; - - if (speed < 0 || speed > MAX_FAN_DUTY_CYCLE) - return -EINVAL; - - mutex_lock(&data->update_lock); - data->fan_duty_cycle[nr] = speed; - ym2651y_write_word(client, 0x3B + nr, data->fan_duty_cycle[nr]); - mutex_unlock(&data->update_lock); - - return count; -} - -static ssize_t show_linear(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - - u16 value = 0; - int exponent, mantissa; - int multiplier = 1000; - - switch (attr->index) { - case PSU_V_OUT: - value = data->v_out; - break; - case PSU_I_OUT: - value = data->i_out; - break; - case PSU_P_OUT_UV: - multiplier = 1000000; /*For lm-sensors, unit is micro-Volt.*/ - /*Passing through*/ - case PSU_P_OUT: - value = data->p_out; - break; - case PSU_TEMP1_INPUT: - value = data->temp; - break; - case PSU_FAN1_SPEED: - value = data->fan_speed; - multiplier = 1; - break; - case PSU_FAN1_DUTY_CYCLE: - value = data->fan_duty_cycle[0]; - multiplier = 1; - break; - case PSU_MFR_VIN_MIN: - value = data->mfr_vin_min; - break; - case PSU_MFR_VIN_MAX: - value = data->mfr_vin_max; - break; - case PSU_MFR_VOUT_MIN: - value = data->mfr_vout_min; - break; - case PSU_MFR_VOUT_MAX: - value = data->mfr_vout_max; - break; - case PSU_MFR_PIN_MAX: - value = data->mfr_pin_max; - break; - case PSU_MFR_POUT_MAX: - value = data->mfr_pout_max; - break; - case PSU_MFR_IOUT_MAX: - value = data->mfr_iout_max; - break; - case PSU_MFR_IIN_MAX: - value = data->mfr_iin_max; - break; - } - - exponent = two_complement_to_int(value >> 11, 5, 0x1f); - mantissa = two_complement_to_int(value & 0x7ff, 11, 0x7ff); - return (exponent >= 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : - sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); -} - -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - - u8 shift = (attr->index == PSU_FAN1_FAULT) ? 7 : 6; - - return sprintf(buf, "%d\n", data->fan_fault >> shift); -} - -static ssize_t show_over_temp(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct ym2651y_data *data = ym2651y_update_device(dev); - - return sprintf(buf, "%d\n", data->over_temp >> 7); -} - -static ssize_t show_ascii(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - u8 *ptr = NULL; - - switch (attr->index) { - case PSU_FAN_DIRECTION: /* psu_fan_dir */ - ptr = data->fan_dir; - break; - case PSU_MFR_ID: /* psu_mfr_id */ - ptr = data->mfr_id; - break; - case PSU_MFR_MODEL: /* psu_mfr_model */ - ptr = data->mfr_model; - break; - case PSU_MFR_REVISION: /* psu_mfr_revision */ - ptr = data->mfr_revsion; - break; - default: - return 0; - } - - return sprintf(buf, "%s\n", ptr); -} - -static const struct attribute_group ym2651y_group = { - .attrs = ym2651y_attributes, -}; - -static int ym2651y_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct ym2651y_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE_DATA | - I2C_FUNC_SMBUS_WORD_DATA | - I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct ym2651y_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &ym2651y_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &ym2651y_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int ym2651y_remove(struct i2c_client *client) -{ - struct ym2651y_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &ym2651y_group); - kfree(data); - - return 0; -} - -static const struct i2c_device_id ym2651y_id[] = { - { "ym2651", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, ym2651y_id); - -static struct i2c_driver ym2651y_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "ym2651", - }, - .probe = ym2651y_probe, - .remove = ym2651y_remove, - .id_table = ym2651y_id, - .address_list = normal_i2c, -}; - -static int ym2651y_read_byte(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_byte_data(client, reg); -} - -static int ym2651y_read_word(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_word_data(client, reg); -} - -static int ym2651y_write_word(struct i2c_client *client, u8 reg, u16 value) -{ - return i2c_smbus_write_word_data(client, reg, value); -} - -static int ym2651y_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) - goto abort; - if (unlikely(result != data_len)) { - result = -EIO; - goto abort; - } - - result = 0; - -abort: - return result; -} - -struct reg_data_byte { - u8 reg; - u8 *value; -}; - -struct reg_data_word { - u8 reg; - u16 *value; -}; - -static struct ym2651y_data *ym2651y_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct ym2651y_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int i, status; - u8 command; - u8 fan_dir[5] = {0}; - struct reg_data_byte regs_byte[] = { {0x19, &data->capability}, - {0x7d, &data->over_temp}, - {0x81, &data->fan_fault}, - {0x98, &data->pmbus_revision}}; - struct reg_data_word regs_word[] = { {0x79, &data->status_word}, - {0x8b, &data->v_out}, - {0x8c, &data->i_out}, - {0x96, &data->p_out}, - {0x8d, &data->temp}, - {0x3b, &(data->fan_duty_cycle[0])}, - {0x3c, &(data->fan_duty_cycle[1])}, - {0x90, &data->fan_speed}, - {0xa0, &data->mfr_vin_min}, - {0xa1, &data->mfr_vin_max}, - {0xa2, &data->mfr_iin_max}, - {0xa3, &data->mfr_pin_max}, - {0xa4, &data->mfr_vout_min}, - {0xa5, &data->mfr_vout_max}, - {0xa6, &data->mfr_iout_max}, - {0xa7, &data->mfr_pout_max}}; - - dev_dbg(&client->dev, "Starting ym2651 update\n"); - - /* Read byte data */ - for (i = 0; i < ARRAY_SIZE(regs_byte); i++) { - status = ym2651y_read_byte(client, regs_byte[i].reg); - - if (status < 0) - { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_byte[i].reg, status); - } - else { - *(regs_byte[i].value) = status; - } - } - - /* Read word data */ - for (i = 0; i < ARRAY_SIZE(regs_word); i++) { - status = ym2651y_read_word(client, regs_word[i].reg); - - if (status < 0) - { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_word[i].reg, status); - } - else { - *(regs_word[i].value) = status; - } - } - - /* Read fan_direction */ - command = 0xC3; - status = ym2651y_read_block(client, command, fan_dir, ARRAY_SIZE(fan_dir)-1); - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - } - - strncpy(data->fan_dir, fan_dir+1, ARRAY_SIZE(data->fan_dir)-1); - data->fan_dir[ARRAY_SIZE(data->fan_dir)-1] = '\0'; - - /* Read mfr_id */ - command = 0x99; - status = ym2651y_read_block(client, command, data->mfr_id, - ARRAY_SIZE(data->mfr_id)-1); - data->mfr_id[ARRAY_SIZE(data->mfr_id)-1] = '\0'; - - if (status < 0) - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - - /* Read mfr_model */ - command = 0x9a; - status = ym2651y_read_block(client, command, data->mfr_model, - ARRAY_SIZE(data->mfr_model)-1); - data->mfr_model[ARRAY_SIZE(data->mfr_model)-1] = '\0'; - - if (status < 0) - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - - /* Read mfr_revsion */ - command = 0x9b; - status = ym2651y_read_block(client, command, data->mfr_revsion, - ARRAY_SIZE(data->mfr_revsion)-1); - data->mfr_revsion[ARRAY_SIZE(data->mfr_revsion)-1] = '\0'; - - if (status < 0) - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -module_i2c_driver(ym2651y_driver); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("3Y Power YM-2651Y driver"); -MODULE_LICENSE("GPL"); - - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/service/as7716-platform-monitor.service b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/service/as7716-platform-monitor.service deleted file mode 100755 index b1428d7844f8..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/service/as7716-platform-monitor.service +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=Accton AS7716-32X Platform Monitoring service -Before=pmon.service -After=sysinit.target -DefaultDependencies=no - -[Service] -ExecStartPre=/usr/local/bin/accton_as7716_util.py install -ExecStart=/usr/local/bin/accton_as7716_monitor.py -KillSignal=SIGKILL -SuccessExitStatus=SIGKILL - -# Resource Limitations -LimitCORE=infinity - -[Install] -WantedBy=multi-user.target diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/setup.py b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/setup.py deleted file mode 100755 index 7a3d784d326e..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/setup.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -from setuptools import setup -os.listdir - -setup( - name='as7716_32x', - version='1.0', - description='Module to initialize Accton AS7716-32X platforms', - - packages=['as7716_32x'], - package_dir={'as7716_32x': 'as7716-32x/classes'}, -) - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/utils/README b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/utils/README deleted file mode 100755 index 44e03cab5f52..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/utils/README +++ /dev/null @@ -1,117 +0,0 @@ -Copyright (C) 2016 Accton Networks, Inc. - -This program is free software: you can redistribute it and/or modify -It under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Contents of this package: - patch - files under patch/ is for kernel and ONIE installer - for the kernel: - config-accton-as5712_54x.patch - for kernel configuration. - driver-i2c-muxes-pca954x-always-deselect.patch - for i2c_mux deselects after transaction. - driver-patches-for-accton-as5712-fan-psu-cpld.patch - for as5712's fan/psu/cpld/led/sfp drivers. - for ONIE: - onie_installer-accton-AS5712-54X.patch - for console port setting and copy util script o rootfs. - module - Contains source code of as5712 kernel driver modules. - -The late Sonic building scripts, pushed @Dec 5 2016, will automatically -create a docker container and run building process under it. -User is not necessary to handle docker environment creation. - -1. Download sonic-buildimage environment. - - Run "git clone https://github.com/Azure/sonic-buildimage". - - cd to sonic-buildimage and run "git submodule update --init --recursive". -2. Build kernel - - cd ./src/sonic-linux-kernel - - Copy patches and series from patch/kernel of this release to - sonic-linux-kernel/patch. - - Build kernel by "make". - - The built kernel package, linux-image-3.16.0-5-amd64_3.16.51-3+deb8u1_amd64.deb - , is generated. -3. Build installer - - Change directory back to sonic-buildimage/. - - Get onie_installer-accton-AS5712-54X.patch" from patch/installer. - - Change setting for AS5712-54X by patching build_image.sh. - "patch -p1 < onie_installer-accton-AS5712-54X.patch" - !!NOTICE, patching onie_installer-accton-AS5712-54X.patch comments out the - "git status" checking at build_image.sh. - - The account and password of installed OS can be given at rules/config. - The default user and password are "admin" & "YourPaSsWoRd" respectively. - - Run "make configure PLATFORM=broadcom" - - Copy the built kernel debian package to target/debs/. - The file is linux-image-3.16.0-5-amd64_*_amd64.deb under directory - src/sonic-linux-kernel/. - - Run "make target/sonic-generic.bin" - - Get the installer, target/sonic-generic.bin, to target machine and install. - -All Linux kernel code is licensed under the GPLv1. All other code is -licensed under the GPLv3. Please see the LICENSE file for copies of -both licenses. - -The code for integacting with Accton AS5712-54X has 2 parts, -kernel drivers and operational script. -The kernel drivers of peripherals are under module/ directory. -1. These drivers are patched into kernel by - driver-patches-for-accton-as5712-fan-psu-cpld.patch - Or you can build the driver under module/ by setting environment variable, - KERNEL_SRC, to proper linux built directory and run make. - It may be sonic-linux-kernel/linux-3.*/debian/build/build_amd64_none_amd64/. -2. A operational script, accton_as5712_util.py, for device initializatian and - peripheral accessing should be installed at /usr/bin. - This script is generated by onie_installer-accton-AS5712-54X.patch. - It's done by patching onie_installer-accton-AS5712-54X.patch at build-image. - Run "accton_as5712_util.py install" to install drivers. - -To initialize the system, run "accton_as5712_util.py install". -To clean up the drivers & devices, run "accton_as5712_util.py clean". -To dump information of sensors, run "accton_as5712_util.py show". -To dump SFP EEPROM, run "accton_as5712_util.py sff". -To set fan speed, run "accton_as5712_util.py set fan". -To enable/disable SFP emission, run "accton_as5712_util.py set sfp". -To set system LEDs' color, run "accton_as5712_util.py set led" -For more information, run "accton_as5712_util.py --help". - -==================================================================== -Besides applying accton_as5712_util.py to access peripherals, you can -access peripherals by sysfs nodes directly after the installation is run. - -System LED: - There are 5 system LEDs at the lower-left corner of front panel. - They are loc, diag, fan, ps1, and ps2. - The sysfs interface color mappings are as follows: - Brightness: - 0 => off - 1 => green - 2 => amber - 3 => red - 4 => blue - But not all colors are available for each LED. - -Fan Control: - There are 10 fans inside 5 fan modules. - All fans share 1 duty setting, ranged from 0~100. - -Thermal sensers: - 3 temperature sensors are controlled by the lm75 kernel modules. - -PSUs: - There 2 power supplies slot at the left/right side of the back. - Once if a PSU is not plugged, the status of it is shown failed. - -There are 48 SFP+ and 6 QSFP modules are equipped. -Before operating on PSU and QSFP+, please make sure it is well plugged. -Otherwise, operation is going to fail. - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/utils/accton_as7716_monitor.py b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/utils/accton_as7716_monitor.py deleted file mode 100755 index 63f26d5d2ef6..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/utils/accton_as7716_monitor.py +++ /dev/null @@ -1,207 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# 1/10/2018: Jostar modify for as7716_32 -# ------------------------------------------------------------------ - -try: - import os - import sys, getopt - import subprocess - import click - import imp - import logging - import logging.config - import types - import time # this is only being used as part of the example - import traceback - from tabulate import tabulate - from as7716_32x.fanutil import FanUtil - from as7716_32x.thermalutil import ThermalUtil -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - -# Deafults -VERSION = '1.0' -FUNCTION_NAME = 'accton_as7716_monitor' - -global log_file -global log_level - - # For AC power Front to Back : - # If any fan fail, please fan speed register to 15 - # The max value of Fan speed register is 9 - # [LM75(48) + LM75(49) + LM75(4A)] > 174 => set Fan speed value from 4 to 5 - # [LM75(48) + LM75(49) + LM75(4A)] > 182 => set Fan speed value from 5 to 7 - # [LM75(48) + LM75(49) + LM75(4A)] > 190 => set Fan speed value from 7 to 9 - # - # [LM75(48) + LM75(49) + LM75(4A)] < 170 => set Fan speed value from 5 to 4 - # [LM75(48) + LM75(49) + LM75(4A)] < 178 => set Fan speed value from 7 to 5 - # [LM75(48) + LM75(49) + LM75(4A)] < 186 => set Fan speed value from 9 to 7 - # - # - # For AC power Back to Front : - # If any fan fail, please fan speed register to 15 - # The max value of Fan speed register is 10 - # [LM75(48) + LM75(49) + LM75(4A)] > 140 => set Fan speed value from 4 to 5 - # [LM75(48) + LM75(49) + LM75(4A)] > 150 => set Fan speed value from 5 to 7 - # [LM75(48) + LM75(49) + LM75(4A)] > 160 => set Fan speed value from 7 to 10 - # - # [LM75(48) + LM75(49) + LM75(4A)] < 135 => set Fan speed value from 5 to 4 - # [LM75(48) + LM75(49) + LM75(4A)] < 145 => set Fan speed value from 7 to 5 - # [LM75(48) + LM75(49) + LM75(4A)] < 155 => set Fan speed value from 10 to 7 - # - - - # 2.If no matched fan speed is found from the policy, - # use FAN_DUTY_CYCLE_MIN as default speed - # Get current temperature - # 4.Decision 3: Decide new fan speed depend on fan direction/current fan speed/temperature - - - - -# Make a class we can use to capture stdout and sterr in the log -class accton_as7716_monitor(object): - # static temp var - _ori_temp = 0 - _new_perc = 0 - _ori_perc = 0 - - def __init__(self, log_file, log_level): - """Needs a logger and a logger level.""" - # set up logging to file - logging.basicConfig( - filename=log_file, - filemode='w', - level=log_level, - format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', - datefmt='%H:%M:%S' - ) - - # set up logging to console - if log_level == logging.DEBUG: - console = logging.StreamHandler() - console.setLevel(log_level) - formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') - console.setFormatter(formatter) - logging.getLogger('').addHandler(console) - - logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level) - - def manage_fans(self): - - fan_policy_f2b = { - 0: [32, 0, 174000], - 1: [38, 170000, 182000], - 2: [50, 178000, 190000], - 3: [63, 186000, 0], - } - fan_policy_b2f = { - 0: [32, 0, 140000], - 1: [38, 135000, 150000], - 2: [50, 145000, 160000], - 3: [69, 15500, 0], - } - - thermal = ThermalUtil() - fan = FanUtil() - get_temp = thermal.get_thermal_temp() - - cur_duty_cycle = fan.get_fan_duty_cycle() - - for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1): - fan_status = fan.get_fan_status(x) - if fan_status is None: - logging.debug('INFO. SET new_perc to %d (FAN stauts is None. fan_num:%d)', 100, x) - return False - if fan_status is False: - logging.debug('INFO. SET new_perc to %d (FAN fault. fan_num:%d)', 100, x) - fan.set_fan_duty_cycle(45) - return True - logging.debug('INFO. fan_status is True (fan_num:%d)', x) - - if fan_status is not None and fan_status is not False: - fan_dir=fan.get_fan_dir(1) - for x in range(0, 4): - if cur_duty_cycle == fan_policy_f2b[x][0]: - break - - if fan_dir == 1: - if x == 4 : - fan.set_fan_duty_cycle(fan_policy_f2b[0][0]) - new_duty_cycle=cur_duty_cycle - # if temp > up_levle, else if temp < down_level - if get_temp > fan_policy_f2b[x][2] and x != 3 : - new_duty_cycle= fan_policy_f2b[x+1][0] - logging.debug('INFO. THERMAL temp UP, temp %d > %d , new_duty_cycle=%d', get_temp, fan_policy_f2b[x][2], new_duty_cycle) - elif get_temp < fan_policy_f2b[x][1] : - new_duty_cycle= fan_policy_f2b[x-1][0] - logging.debug('INFO. THERMAL temp down, temp %d < %d , new_duty_cycle=%d', get_temp, fan_policy_f2b[x][1], new_duty_cycle) - if new_duty_cycle == cur_duty_cycle : - return True - else: - if x == 4 : - fan.set_fan_duty_cycle(fan_policy_b2f[0][0]) - new_duty_cycle=cur_duty_cycle - # if temp > up_levle, else if temp < down_level - if get_temp > fan_policy_b2f[x][1] and x != 3 : - new_duty_cycle= fan_policy_b2f[x+1][0] - logging.debug('INFO. THERMAL temp UP, temp %d > %d , new_duty_cycle=%d', get_temp, fan_policy_b2f[x][2], new_duty_cycle) - elif get_temp < fan_policy_b2f[x][0] and x != 0 : - new_duty_cycle= fan_policy_b2f[x-1][0] - logging.debug('INFO. THERMAL temp down, temp %d < %d , new_duty_cycle=%d', get_temp, fan_policy_b2f[x][1], new_duty_cycle) - if new_duty_cycle == cur_duty_cycle : - return True - - fan.set_fan_duty_cycle(new_duty_cycle) - - return True - - - -def main(argv): - log_file = '%s.log' % FUNCTION_NAME - log_level = logging.INFO - if len(sys.argv) != 1: - try: - opts, args = getopt.getopt(argv,'hdl:',['lfile=']) - except getopt.GetoptError: - print 'Usage: %s [-d] [-l ]' % sys.argv[0] - return 0 - for opt, arg in opts: - if opt == '-h': - print 'Usage: %s [-d] [-l ]' % sys.argv[0] - return 0 - elif opt in ('-d', '--debug'): - log_level = logging.DEBUG - elif opt in ('-l', '--lfile'): - log_file = arg - - monitor = accton_as7716_monitor(log_file, log_level) - - # Loop forever, doing something useful hopefully: - while True: - monitor.manage_fans() - time.sleep(1) - -if __name__ == '__main__': - main(sys.argv[1:]) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/utils/accton_as7716_util.py b/platform/broadcom/sonic-platform-modules-accton/as7716-32x/utils/accton_as7716_util.py deleted file mode 100755 index cd35b50d200e..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32x/utils/accton_as7716_util.py +++ /dev/null @@ -1,595 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2016 Accton Networks, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" -Usage: %(scriptName)s [options] command object - -options: - -h | --help : this help message - -d | --debug : run with debug mode - -f | --force : ignore error during installation or clean -command: - install : install drivers and generate related sysfs nodes - clean : uninstall drivers and remove related sysfs nodes - show : show all systen status - sff : dump SFP eeprom - set : change board setting with fan|led|sfp -""" - -import os -import commands -import sys, getopt -import logging -import re -import time -from collections import namedtuple - -PROJECT_NAME = 'as7716_32x' -version = '0.0.1' -verbose = False -DEBUG = False -args = [] -ALL_DEVICE = {} -DEVICE_NO = {'led':5, 'fan1':1, 'fan2':1,'fan3':1,'fan4':1,'fan5':1,'thermal':3, 'psu':2, 'sfp':54} - - -led_prefix ='/sys/devices/platform/as7716_32x_led/leds/accton_'+PROJECT_NAME+'_led::' -fan_prefix ='/sys/devices/platform/as7716_32x_' -hwmon_types = {'led': ['diag','fan','loc','psu1','psu2'], - 'fan1': ['fan'], - 'fan2': ['fan'], - 'fan3': ['fan'], - 'fan4': ['fan'], - 'fan5': ['fan'], - 'fan5': ['fan'], - } -hwmon_nodes = {'led': ['brightness'] , - 'fan1': ['fan_duty_cycle_percentage', 'fan1_fault', 'fan1_speed_rpm', 'fan1_direction', 'fanr1_fault', 'fanr1_speed_rpm'], - 'fan2': ['fan_duty_cycle_percentage','fan2_fault', 'fan2_speed_rpm', 'fan2_direction', 'fanr2_fault', 'fanr2_speed_rpm'], - 'fan3': ['fan_duty_cycle_percentage','fan3_fault', 'fan3_speed_rpm', 'fan3_direction', 'fanr3_fault', 'fanr3_speed_rpm'], - 'fan4': ['fan4_duty_cycle_percentage','fan4_fault', 'fan4_speed_rpm', 'fan4_direction', 'fanr4_fault', 'fanr4_speed_rpm'], - 'fan5': ['fan_duty_cycle_percentage','fan5_fault', 'fan5_speed_rpm', 'fan5_direction', 'fanr5_fault', 'fanr5_speed_rpm'], - } -hwmon_prefix ={'led': led_prefix, - 'fan1': fan_prefix, - 'fan2': fan_prefix, - 'fan3': fan_prefix, - 'fan4': fan_prefix, - 'fan5': fan_prefix, - } - -i2c_prefix = '/sys/bus/i2c/devices/' -i2c_bus = {'thermal': ['10-0048','10-0049', '10-004a'] , - 'psu': ['17-0050','18-0053'], - 'sfp': ['-0050']} -i2c_nodes = { - 'thermal': ['hwmon/hwmon*/temp1_input'] , - 'psu': ['psu_present ', 'psu_power_good'] , - 'sfp': ['sfp_is_present ', 'sfp_tx_disable']} - -sfp_map = [29, 30, 31, 32, 34, 33, 36, 35, - 25, 26, 27, 28, 37, 38, 39, 40, - 41, 42, 43, 44, 53, 54, 55, 56, - 45, 46, 47, 48, 49, 50, 51, 52] - -mknod =[ -'echo pca9548 0x77 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo as7716_32x_fan 0x66 > /sys/bus/i2c/devices/i2c-9/new_device', - -'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-10/new_device', -'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-10/new_device', -'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-10/new_device', - -'echo as7716_32x_cpld1 0x60 > /sys/bus/i2c/devices/i2c-11/new_device', -'echo accton_i2c_cpld 0x62 > /sys/bus/i2c/devices/i2c-12/new_device', -'echo accton_i2c_cpld 0x64 > /sys/bus/i2c/devices/i2c-13/new_device', - -'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-2/new_device', -'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-2/new_device', -'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-2/new_device', -'echo pca9548 0x74 > /sys/bus/i2c/devices/i2c-2/new_device', -'echo pca9548 0x75 > /sys/bus/i2c/devices/i2c-2/new_device', - -# PSU-1 -'echo as7716_32x_psu1 0x53 > /sys/bus/i2c/devices/i2c-18/new_device', -'echo ym2651 0x5b > /sys/bus/i2c/devices/i2c-18/new_device', - -# PSU-2 -'echo as7716_32x_psu2 0x50> /sys/bus/i2c/devices/i2c-17/new_device', -'echo ym2651 0x58 > /sys/bus/i2c/devices/i2c-17/new_device', - - - -#EERPOM -'echo 24c02 0x56 > /sys/bus/i2c/devices/i2c-1/new_device', -] - -mknod2 =[ -'echo as7716_32x_cpld1 0x60 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo accton_i2c_cpld 0x61 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo accton_i2c_cpld 0x62 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-0/new_device', - -# PSU-1 -'echo as7716_32x_psu1 0x38 > /sys/bus/i2c/devices/i2c-57/new_device', -'echo cpr_4011_4mxx 0x3c > /sys/bus/i2c/devices/i2c-57/new_device', -'echo as7716_32x_psu1 0x50 > /sys/bus/i2c/devices/i2c-57/new_device', -'echo ym2401 0x58 > /sys/bus/i2c/devices/i2c-57/new_device', - -# PSU-2 -'echo as7716_32x_psu2 0x3b > /sys/bus/i2c/devices/i2c-58/new_device', -'echo cpr_4011_4mxx 0x3f > /sys/bus/i2c/devices/i2c-58/new_device', -'echo as7716_32x_psu2 0x53 > /sys/bus/i2c/devices/i2c-58/new_device', -'echo ym2401 0x5b > /sys/bus/i2c/devices/i2c-58/new_device', - -'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-61/new_device', -'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-62/new_device', -'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-63/new_device', - -#EERPOM -'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-1/new_device', -] - -FORCE = 0 -logging.basicConfig(filename= PROJECT_NAME+'.log', filemode='w',level=logging.DEBUG) -logging.basicConfig(level=logging.INFO) - - -if DEBUG == True: - print sys.argv[0] - print 'ARGV :', sys.argv[1:] - - -def main(): - global DEBUG - global args - global FORCE - - if len(sys.argv)<2: - show_help() - - options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help', - 'debug', - 'force', - ]) - if DEBUG == True: - print options - print args - print len(sys.argv) - - for opt, arg in options: - if opt in ('-h', '--help'): - show_help() - elif opt in ('-d', '--debug'): - DEBUG = True - logging.basicConfig(level=logging.INFO) - elif opt in ('-f', '--force'): - FORCE = 1 - else: - logging.info('no option') - for arg in args: - if arg == 'install': - do_install() - elif arg == 'clean': - do_uninstall() - elif arg == 'show': - device_traversal() - elif arg == 'sff': - if len(args)!=2: - show_eeprom_help() - elif int(args[1]) ==0 or int(args[1]) > DEVICE_NO['sfp']: - show_eeprom_help() - else: - show_eeprom(args[1]) - return - elif arg == 'set': - if len(args)<3: - show_set_help() - else: - set_device(args[1:]) - return - else: - show_help() - - - return 0 - -def show_help(): - print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]} - sys.exit(0) - -def show_set_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print cmd +" [led|sfp|fan]" - print " use \""+ cmd + " led 0-4 \" to set led color" - print " use \""+ cmd + " fan 0-100\" to set fan duty percetage" - print " use \""+ cmd + " sfp 1-32 {0|1}\" to set sfp# tx_disable" - sys.exit(0) - -def show_eeprom_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print " use \""+ cmd + " 1-32 \" to dump sfp# eeprom" - sys.exit(0) - -def my_log(txt): - if DEBUG == True: - print "[ACCTON DBG]: "+txt - return - -def log_os_system(cmd, show): - logging.info('Run :'+cmd) - status = 1 - output = "" - status, output = commands.getstatusoutput(cmd) - my_log (cmd +"with result:" + str(status)) - my_log ("cmd:" + cmd) - my_log (" output:"+output) - if status: - logging.info('Failed :'+cmd) - if show: - print('Failed :'+cmd) - return status, output - -def driver_inserted(): - ret, lsmod = log_os_system("lsmod| grep accton", 0) - logging.info('mods:'+lsmod) - if len(lsmod) ==0: - return False - -#'modprobe cpr_4011_4mxx', - -kos = [ -'depmod -ae', -'modprobe i2c_dev', -'modprobe i2c_mux_pca954x', -'modprobe accton_i2c_cpld', -'modprobe cpr_4011_4mxx', -'modprobe ym2651y', -'modprobe accton_as7716_32x_cpld1', -'modprobe accton_as7716_32x_fan', -'modprobe accton_as7716_32x_leds', -'modprobe accton_as7716_32x_psu'] - -def driver_install(): - global FORCE - for i in range(0,len(kos)): - status, output = log_os_system(kos[i], 1) - if status: - if FORCE == 0: - return status - return 0 - -def driver_uninstall(): - global FORCE - for i in range(0,len(kos)): - rm = kos[-(i+1)].replace("modprobe", "modprobe -rq") - rm = rm.replace("insmod", "rmmod") - status, output = log_os_system(rm, 1) - if status: - if FORCE == 0: - return status - return 0 - - - -def i2c_order_check(): - # i2c bus 0 and 1 might be installed in different order. - # Here check if 0x76 is exist @ i2c-0 - tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device" - status, output = log_os_system(tmp, 0) - if not device_exist(): - order = 1 - else: - order = 0 - tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-1/delete_device" - status, output = log_os_system(tmp, 0) - return order - -def device_install(): - global FORCE - - for i in range(0,len(mknod)): - #for pca932x need times to built new i2c buses - if mknod[i].find('pca954') != -1: - time.sleep(2) - - status, output = log_os_system(mknod[i], 1) - if status: - print output - if FORCE == 0: - return status - - for i in range(0,len(sfp_map)): - status, output =log_os_system("echo optoe1 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1) - if status: - print output - if FORCE == 0: - return status - status, output =log_os_system("echo port"+str(i)+" > /sys/bus/i2c/devices/"+str(sfp_map[i])+"-0050/port_name", 1) - if status: - print output - if FORCE == 0: - return status - return - -def device_uninstall(): - global FORCE - - status, output =log_os_system("ls /sys/bus/i2c/devices/0-0070", 0) - if status==0: - I2C_ORDER=1 - else: - I2C_ORDER=0 - - for i in range(0,len(sfp_map)): - target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device" - status, output =log_os_system("echo 0x50 > "+ target, 1) - if status: - print output - if FORCE == 0: - return status - - if I2C_ORDER==0: - nodelist = mknod - else: - nodelist = mknod2 - - for i in range(len(nodelist)): - target = nodelist[-(i+1)] - temp = target.split() - del temp[1] - temp[-1] = temp[-1].replace('new_device', 'delete_device') - status, output = log_os_system(" ".join(temp), 1) - if status: - print output - if FORCE == 0: - return status - - return - -def system_ready(): - if driver_inserted() == False: - return False - if not device_exist(): - print "not device_exist()" - return False - return True - -def do_install(): - if driver_inserted() == False: - status = driver_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" drivers detected...." - if not device_exist(): - status = device_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" devices detected...." - return - -def do_uninstall(): - if not device_exist(): - print PROJECT_NAME.upper() +" has no device installed...." - else: - print "Removing device...." - status = device_uninstall() - if status: - if FORCE == 0: - return status - - if driver_inserted()== False : - print PROJECT_NAME.upper() +" has no driver installed...." - else: - print "Removing installed driver...." - status = driver_uninstall() - if status: - if FORCE == 0: - return status - - return - -def devices_info(): - global DEVICE_NO - global ALL_DEVICE - global i2c_bus, hwmon_types - for key in DEVICE_NO: - ALL_DEVICE[key]= {} - for i in range(0,DEVICE_NO[key]): - ALL_DEVICE[key][key+str(i+1)] = [] - - for key in i2c_bus: - buses = i2c_bus[key] - nodes = i2c_nodes[key] - for i in range(0,len(buses)): - for j in range(0,len(nodes)): - if 'fan' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - elif 'sfp' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ str(sfp_map[k])+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - else: - node = key+str(i+1) - path = i2c_prefix+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - - for key in hwmon_types: - itypes = hwmon_types[key] - nodes = hwmon_nodes[key] - for i in range(0,len(itypes)): - for j in range(0,len(nodes)): - node = key+"_"+itypes[i] - path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][ key+str(i+1)].append(path) - - #show dict all in the order - if DEBUG == True: - for i in sorted(ALL_DEVICE.keys()): - print(i+": ") - for j in sorted(ALL_DEVICE[i].keys()): - print(" "+j) - for k in (ALL_DEVICE[i][j]): - print(" "+" "+k) - return - -def show_eeprom(index): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0] - node = node.replace(node.split("/")[-1], 'sfp_eeprom') - # check if got hexdump command in current environment - ret, log = log_os_system("which hexdump", 0) - ret, log2 = log_os_system("which busybox hexdump", 0) - if len(log): - hex_cmd = 'hexdump' - elif len(log2): - hex_cmd = ' busybox hexdump' - else: - log = 'Failed : no hexdump cmd!!' - logging.info(log) - print log - return 1 - - print node + ":" - ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1) - if ret==0: - print log - else: - print "**********device no found**********" - return - -def set_device(args): - global DEVICE_NO - global ALL_DEVICE - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - - if args[0]=='led': - if int(args[1])>4: - show_set_help() - return - #print ALL_DEVICE['led'] - for i in range(0,len(ALL_DEVICE['led'])): - for k in (ALL_DEVICE['led']['led'+str(i+1)]): - ret, log = log_os_system("echo "+args[1]+" >"+k, 1) - if ret: - return ret - elif args[0]=='fan': - if int(args[1])>100: - show_set_help() - return - #print ALL_DEVICE['fan'] - #fan1~6 is all fine, all fan share same setting - node = ALL_DEVICE['fan1'] ['fan11'][0] - node = node.replace(node.split("/")[-1], 'fan1_duty_cycle_percentage') - ret, log = log_os_system("cat "+ node, 1) - if ret==0: - print ("Previous fan duty: " + log.strip() +"%") - ret, log = log_os_system("echo "+args[1]+" >"+node, 1) - if ret==0: - print ("Current fan duty: " + args[1] +"%") - return ret - elif args[0]=='sfp': - if int(args[1])> DEVICE_NO[args[0]] or int(args[1])==0: - show_set_help() - return - if len(args)<2: - show_set_help() - return - - if int(args[2])>1: - show_set_help() - return - - #print ALL_DEVICE[args[0]] - for i in range(0,len(ALL_DEVICE[args[0]])): - for j in ALL_DEVICE[args[0]][args[0]+str(args[1])]: - if j.find('tx_disable')!= -1: - ret, log = log_os_system("echo "+args[2]+" >"+ j, 1) - if ret: - return ret - - return - -#get digits inside a string. -#Ex: 31 for "sfp31" -def get_value(input): - digit = re.findall('\d+', input) - return int(digit[0]) - -def device_traversal(): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - for i in sorted(ALL_DEVICE.keys()): - print("============================================") - print(i.upper()+": ") - print("============================================") - - for j in sorted(ALL_DEVICE[i].keys(), key=get_value): - print " "+j+":", - for k in (ALL_DEVICE[i][j]): - ret, log = log_os_system("cat "+k, 0) - func = k.split("/")[-1].strip() - func = re.sub(j+'_','',func,1) - func = re.sub(i.lower()+'_','',func,1) - if ret==0: - print func+"="+log+" ", - else: - print func+"="+"X"+" ", - print - print("----------------------------------------------------------------") - - - print - return - -def device_exist(): - ret1, log = log_os_system("ls "+i2c_prefix+"*0077", 0) - ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0) - return not(ret1 or ret2) - -if __name__ == "__main__": - main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/classes/__init__.py b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/classes/__init__.py deleted file mode 100755 index e69de29bb2d1..000000000000 diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/classes/fanutil.py b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/classes/fanutil.py deleted file mode 100755 index e001e94092c7..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/classes/fanutil.py +++ /dev/null @@ -1,263 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# 1/10/2018: Jostar modify for as7716_32 -# ------------------------------------------------------------------ - -try: - import time - import logging - from collections import namedtuple -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - - -class FanUtil(object): - """Platform-specific FanUtil class""" - - FAN_NUM_ON_MAIN_BROAD = 6 - FAN_NUM_1_IDX = 1 - FAN_NUM_2_IDX = 2 - FAN_NUM_3_IDX = 3 - FAN_NUM_4_IDX = 4 - FAN_NUM_5_IDX = 5 - FAN_NUM_6_IDX = 6 - - FAN_NODE_NUM_OF_MAP = 2 - FAN_NODE_FAULT_IDX_OF_MAP = 1 - #FAN_NODE_SPEED_IDX_OF_MAP = 2 - FAN_NODE_DIR_IDX_OF_MAP = 2 - #FAN_NODE_DUTY_IDX_OF_MAP = 4 - #FANR_NODE_FAULT_IDX_OF_MAP = 5 - - #BASE_VAL_PATH = '/sys/devices/platform/as5712_54x_fan/{0}' - BASE_VAL_PATH = '/sys/bus/i2c/devices/9-0066/{0}' - FAN_DUTY_PATH = '/sys/bus/i2c/devices/9-0066/fan_duty_cycle_percentage' - - #logfile = '' - #loglevel = logging.INFO - - """ Dictionary where - key1 = fan id index (integer) starting from 1 - key2 = fan node index (interger) starting from 1 - value = path to fan device file (string) """ - _fan_to_device_path_mapping = {} - -#fan1_direction -#fan1_fault -#fan1_present - - #(FAN_NUM_2_IDX, FAN_NODE_DUTY_IDX_OF_MAP): 'fan2_duty_cycle_percentage', - _fan_to_device_node_mapping = { - (FAN_NUM_1_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan1_fault', - (FAN_NUM_1_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan1_direction', - - (FAN_NUM_2_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan2_fault', - (FAN_NUM_2_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan2_direction', - - (FAN_NUM_3_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan3_fault', - (FAN_NUM_3_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan3_direction', - - (FAN_NUM_4_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan4_fault', - (FAN_NUM_4_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan4_direction', - - (FAN_NUM_5_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan5_fault', - (FAN_NUM_5_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan5_direction', - - (FAN_NUM_6_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan6_fault', - (FAN_NUM_6_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan6_direction', - } - - def _get_fan_to_device_node(self, fan_num, node_num): - return self._fan_to_device_node_mapping[(fan_num, node_num)] - - def _get_fan_node_val(self, fan_num, node_num): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num:%d', fan_num) - return None - - if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: - logging.debug('GET. Parameter error. node_num:%d', node_num) - return None - - device_path = self.get_fan_to_device_path(fan_num, node_num) - - try: - val_file = open(device_path, 'r') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - content = val_file.readline().rstrip() - #print "fan_num=%d" %fan_num - #print "node_num=%d" %node_num - #print "device_path=%s" %device_path - #print "content=%s" %content - - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return int(content) - - def _set_fan_node_val(self, fan_num, node_num, val): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num:%d', fan_num) - return None - - if node_num < self.FAN_NODE_FAULT_IDX_OF_MAP or node_num > self.FAN_NODE_NUM_OF_MAP: - logging.debug('GET. Parameter error. node_num:%d', node_num) - return None - - content = str(val) - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - device_path = self.get_fan_to_device_path(fan_num, node_num) - try: - val_file = open(device_path, 'w') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - val_file.write(content) - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return True - - def __init__(self): - fan_path = self.BASE_VAL_PATH - - for fan_num in range(self.FAN_NUM_1_IDX, self.FAN_NUM_ON_MAIN_BROAD+1): - for node_num in range(self.FAN_NODE_FAULT_IDX_OF_MAP, self.FAN_NODE_NUM_OF_MAP+1): - self._fan_to_device_path_mapping[(fan_num, node_num)] = fan_path.format( - self._fan_to_device_node_mapping[(fan_num, node_num)]) - #self._fan_to_device_path_mapping[(fan_num, node_num)] = fan_path + self._fan_to_device_node_mapping[(fan_num, node_num)]) - #print "fan_num=%d" %fan_num - #print "node_num=%d" %node_num - #print "self._fan_to_device_path_mapping[(fan_num, node_num)]=%s" %self._fan_to_device_path_mapping[(fan_num, node_num)] - - def get_num_fans(self): - return self.FAN_NUM_ON_MAIN_BROAD - - def get_idx_fan_start(self): - return self.FAN_NUM_1_IDX - - def get_num_nodes(self): - return self.FAN_NODE_NUM_OF_MAP - - def get_idx_node_start(self): - return self.FAN_NODE_FAULT_IDX_OF_MAP - - def get_size_node_map(self): - return len(self._fan_to_device_node_mapping) - - def get_size_path_map(self): - return len(self._fan_to_device_path_mapping) - - def get_fan_to_device_path(self, fan_num, node_num): - return self._fan_to_device_path_mapping[(fan_num, node_num)] - - def get_fan_fault(self, fan_num): - return self._get_fan_node_val(fan_num, self.FAN_NODE_FAULT_IDX_OF_MAP) - - #def get_fan_speed(self, fan_num): - # return self._get_fan_node_val(fan_num, self.FAN_NODE_SPEED_IDX_OF_MAP) - - def get_fan_dir(self, fan_num): - return self._get_fan_node_val(fan_num, self.FAN_NODE_DIR_IDX_OF_MAP) - - def get_fan_duty_cycle(self): - #duty_path = self.FAN_DUTY_PATH - try: - val_file = open(self.FAN_DUTY_PATH) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - return False - - content = val_file.readline().rstrip() - val_file.close() - - return int(content) - #self._get_fan_node_val(fan_num, self.FAN_NODE_DUTY_IDX_OF_MAP) -#static u32 reg_val_to_duty_cycle(u8 reg_val) -#{ -# reg_val &= FAN_DUTY_CYCLE_REG_MASK; -# return ((u32)(reg_val+1) * 625 + 75)/ 100; -#} -# - def set_fan_duty_cycle(self, val): - - try: - fan_file = open(self.FAN_DUTY_PATH, 'r+') - except IOError as e: - print "Error: unable to open file: %s" % str(e) - return False - #val = ((val + 1 ) * 625 +75 ) / 100 - fan_file.write(str(val)) - fan_file.close() - return True - - #def get_fanr_fault(self, fan_num): - # return self._get_fan_node_val(fan_num, self.FANR_NODE_FAULT_IDX_OF_MAP) - - def get_fanr_speed(self, fan_num): - return self._get_fan_node_val(fan_num, self.FANR_NODE_SPEED_IDX_OF_MAP) - - def get_fan_status(self, fan_num): - if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. fan_num, %d', fan_num) - print "fan %d return none" %fan_num - return None - - if self.get_fan_fault(fan_num) is not None and self.get_fan_fault(fan_num) > 0: - logging.debug('GET. FAN fault. fan_num, %d', fan_num) - return False - - #if self.get_fanr_fault(fan_num) is not None and self.get_fanr_fault(fan_num) > 0: - # logging.debug('GET. FANR fault. fan_num, %d', fan_num) - # return False - - return True - -#def main(): -# fan = FanUtil() -# -# print 'get_size_node_map : %d' % fan.get_size_node_map() -# print 'get_size_path_map : %d' % fan.get_size_path_map() -# for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1): -# for y in range(fan.get_idx_node_start(), fan.get_num_nodes()+1): -# print fan.get_fan_to_device_path(x, y) -# -#if __name__ == '__main__': -# main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/classes/thermalutil.py b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/classes/thermalutil.py deleted file mode 100755 index d3feda8faad9..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/classes/thermalutil.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# 1/10/2018:Jostar modify for as7716_32x -# ------------------------------------------------------------------ - -try: - import time - import logging - import glob - from collections import namedtuple -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - - -class ThermalUtil(object): - """Platform-specific ThermalUtil class""" - - THERMAL_NUM_ON_MAIN_BROAD = 3 - THERMAL_NUM_1_IDX = 1 # 1_ON_MAIN_BROAD - THERMAL_NUM_2_IDX = 2 # 2_ON_MAIN_BROAD - THERMAL_NUM_3_IDX = 3 # 3_ON_MAIN_BROAD - - BASE_VAL_PATH = '/sys/bus/i2c/devices/{0}-00{1}/hwmon/hwmon*/temp1_input' - - """ Dictionary where - key1 = thermal id index (integer) starting from 1 - value = path to fan device file (string) """ - _thermal_to_device_path_mapping = {} - - _thermal_to_device_node_mapping = { - THERMAL_NUM_1_IDX: ['10', '48'], - THERMAL_NUM_2_IDX: ['10', '49'], - THERMAL_NUM_3_IDX: ['10', '4a'], - } - - def __init__(self): - thermal_path = self.BASE_VAL_PATH - - for x in range(self.THERMAL_NUM_1_IDX, self.THERMAL_NUM_ON_MAIN_BROAD+1): - self._thermal_to_device_path_mapping[x] = thermal_path.format( - self._thermal_to_device_node_mapping[x][0], - self._thermal_to_device_node_mapping[x][1]) - #print "self._thermal_to_device_path_mapping[x]=%s" %self._thermal_to_device_path_mapping[x] - - def _get_thermal_node_val(self, thermal_num): - if thermal_num < self.THERMAL_NUM_1_IDX or thermal_num > self.THERMAL_NUM_ON_MAIN_BROAD: - logging.debug('GET. Parameter error. thermal_num, %d', thermal_num) - return None - - device_path = self.get_thermal_to_device_path(thermal_num) - for filename in glob.glob(device_path): - try: - val_file = open(filename, 'r') - except IOError as e: - logging.error('GET. unable to open file: %s', str(e)) - return None - - content = val_file.readline().rstrip() - - if content == '': - logging.debug('GET. content is NULL. device_path:%s', device_path) - return None - - try: - val_file.close() - except: - logging.debug('GET. unable to close file. device_path:%s', device_path) - return None - - return int(content) - - - def get_num_thermals(self): - return self.THERMAL_NUM_ON_MAIN_BROAD - - def get_idx_thermal_start(self): - return self.THERMAL_NUM_1_IDX - - def get_size_node_map(self): - return len(self._thermal_to_device_node_mapping) - - def get_size_path_map(self): - return len(self._thermal_to_device_path_mapping) - - def get_thermal_to_device_path(self, thermal_num): - return self._thermal_to_device_path_mapping[thermal_num] - - def get_thermal_1_val(self): - return self._get_thermal_node_val(self.THERMAL_NUM_1_IDX) - - def get_thermal_2_val(self): - return self._get_thermal_node_val(self.THERMAL_NUM_2_IDX) - def get_thermal_temp(self): - return (self._get_thermal_node_val(self.THERMAL_NUM_1_IDX) + self._get_thermal_node_val(self.THERMAL_NUM_2_IDX) +self._get_thermal_node_val(self.THERMAL_NUM_3_IDX)) - -#def main(): -# thermal = ThermalUtil() -# -# print 'get_size_node_map : %d' % thermal.get_size_node_map() -# print 'get_size_path_map : %d' % thermal.get_size_path_map() -# for x in range(thermal.get_idx_thermal_start(), thermal.get_num_thermals()+1): -# print thermal.get_thermal_to_device_path(x) -# -#if __name__ == '__main__': -# main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/Makefile b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/Makefile deleted file mode 100755 index 3dfb021a7aaf..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -ifneq ($(KERNELRELEASE),) -obj-m:= accton_as7716_32xb_cpld1.o accton_as7716_32xb_fan.o \ - accton_as7716_32xb_leds.o accton_as7716_32xb_psu.o \ - accton_as7716_32xb_thermal.o accton_as7716_32xb_oom.o accton_as7716_32xb_pmbus.o\ - accton_as7716_32xb_sys.o accton_i2c_cpld.o -else -ifeq (,$(KERNEL_SRC)) -$(error KERNEL_SRC is not defined) -else -KERNELDIR:=$(KERNEL_SRC) -endif -PWD:=$(shell pwd) -default: - $(MAKE) -C $(KERNELDIR) M=$(PWD) modules -clean: - rm -rf *.o *.mod.o *.mod.o *.ko .*cmd .tmp_versions Module.markers Module.symvers modules.order -endif diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_cpld1.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_cpld1.c deleted file mode 100755 index d2db4fb1f484..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_cpld1.c +++ /dev/null @@ -1,1021 +0,0 @@ -/* - * A hwmon driver for the as7716_32xbb_cpld - * - * Copyright (C) 2013 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static LIST_HEAD(cpld_client_list); -static struct mutex list_lock; - -struct cpld_client_node { - struct i2c_client *client; - struct list_head list; -}; - -#define I2C_RW_RETRY_COUNT 10 -#define I2C_RW_RETRY_INTERVAL 60 /* ms */ -#define STRING_TO_DEC_VALUE 10 - -static ssize_t show_present(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_present_all(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t show_version(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t get_mode_reset(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t set_mode_reset(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); - -static int as7716_32xb_cpld_read_internal(struct i2c_client *client, u8 reg); -static int as7716_32xb_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); - -static ssize_t sfp_value_show(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t sfp_value_store(struct device *dev, struct device_attribute *da, - char *buf, size_t size); - - -#define PORT_NUM_MAX 32 - -struct as7716_32xb_cpld_data { - struct device *hwmon_dev; - struct mutex update_lock; - unsigned int present[PORT_NUM_MAX]; - unsigned int reset[PORT_NUM_MAX]; -}; -enum port_id { - PORT1_ID, - PORT2_ID, - PORT3_ID, - PORT4_ID, - PORT5_ID, - PORT6_ID, - PORT7_ID, - PORT8_ID, - PORT9_ID, - PORT10_ID, - PORT11_ID, - PORT12_ID, - PORT13_ID, - PORT14_ID, - PORT15_ID, - PORT16_ID, - PORT17_ID, - PORT18_ID, - PORT19_ID, - PORT20_ID, - PORT21_ID, - PORT22_ID, - PORT23_ID, - PORT24_ID, - PORT25_ID, - PORT26_ID, - PORT27_ID, - PORT28_ID, - PORT29_ID, - PORT30_ID, - PORT31_ID, - PORT32_ID -}; - -/* Addresses scanned for as7716_32xbb_cpld - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index -#define TRANSCEIVER_RESET_ATTR_ID(index) MODULE_RESET_##index - -enum as7716_32xb_cpld_sysfs_attributes { - CPLD_VERSION, - ACCESS, - MODULE_PRESENT_ALL, - /* transceiver attributes */ - TRANSCEIVER_PRESENT_ATTR_ID(1), - TRANSCEIVER_PRESENT_ATTR_ID(2), - TRANSCEIVER_PRESENT_ATTR_ID(3), - TRANSCEIVER_PRESENT_ATTR_ID(4), - TRANSCEIVER_PRESENT_ATTR_ID(5), - TRANSCEIVER_PRESENT_ATTR_ID(6), - TRANSCEIVER_PRESENT_ATTR_ID(7), - TRANSCEIVER_PRESENT_ATTR_ID(8), - TRANSCEIVER_PRESENT_ATTR_ID(9), - TRANSCEIVER_PRESENT_ATTR_ID(10), - TRANSCEIVER_PRESENT_ATTR_ID(11), - TRANSCEIVER_PRESENT_ATTR_ID(12), - TRANSCEIVER_PRESENT_ATTR_ID(13), - TRANSCEIVER_PRESENT_ATTR_ID(14), - TRANSCEIVER_PRESENT_ATTR_ID(15), - TRANSCEIVER_PRESENT_ATTR_ID(16), - TRANSCEIVER_PRESENT_ATTR_ID(17), - TRANSCEIVER_PRESENT_ATTR_ID(18), - TRANSCEIVER_PRESENT_ATTR_ID(19), - TRANSCEIVER_PRESENT_ATTR_ID(20), - TRANSCEIVER_PRESENT_ATTR_ID(21), - TRANSCEIVER_PRESENT_ATTR_ID(22), - TRANSCEIVER_PRESENT_ATTR_ID(23), - TRANSCEIVER_PRESENT_ATTR_ID(24), - TRANSCEIVER_PRESENT_ATTR_ID(25), - TRANSCEIVER_PRESENT_ATTR_ID(26), - TRANSCEIVER_PRESENT_ATTR_ID(27), - TRANSCEIVER_PRESENT_ATTR_ID(28), - TRANSCEIVER_PRESENT_ATTR_ID(29), - TRANSCEIVER_PRESENT_ATTR_ID(30), - TRANSCEIVER_PRESENT_ATTR_ID(31), - TRANSCEIVER_PRESENT_ATTR_ID(32), - TRANSCEIVER_RESET_ATTR_ID(1), - TRANSCEIVER_RESET_ATTR_ID(2), - TRANSCEIVER_RESET_ATTR_ID(3), - TRANSCEIVER_RESET_ATTR_ID(4), - TRANSCEIVER_RESET_ATTR_ID(5), - TRANSCEIVER_RESET_ATTR_ID(6), - TRANSCEIVER_RESET_ATTR_ID(7), - TRANSCEIVER_RESET_ATTR_ID(8), - TRANSCEIVER_RESET_ATTR_ID(9), - TRANSCEIVER_RESET_ATTR_ID(10), - TRANSCEIVER_RESET_ATTR_ID(11), - TRANSCEIVER_RESET_ATTR_ID(12), - TRANSCEIVER_RESET_ATTR_ID(13), - TRANSCEIVER_RESET_ATTR_ID(14), - TRANSCEIVER_RESET_ATTR_ID(15), - TRANSCEIVER_RESET_ATTR_ID(16), - TRANSCEIVER_RESET_ATTR_ID(17), - TRANSCEIVER_RESET_ATTR_ID(18), - TRANSCEIVER_RESET_ATTR_ID(19), - TRANSCEIVER_RESET_ATTR_ID(20), - TRANSCEIVER_RESET_ATTR_ID(21), - TRANSCEIVER_RESET_ATTR_ID(22), - TRANSCEIVER_RESET_ATTR_ID(23), - TRANSCEIVER_RESET_ATTR_ID(24), - TRANSCEIVER_RESET_ATTR_ID(25), - TRANSCEIVER_RESET_ATTR_ID(26), - TRANSCEIVER_RESET_ATTR_ID(27), - TRANSCEIVER_RESET_ATTR_ID(28), - TRANSCEIVER_RESET_ATTR_ID(29), - TRANSCEIVER_RESET_ATTR_ID(30), - TRANSCEIVER_RESET_ATTR_ID(31), - TRANSCEIVER_RESET_ATTR_ID(32), -}; - -/* sysfs attributes for hwmon - */ - -/* transceiver attributes */ -/*present*/ -#define DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ - static SENSOR_DEVICE_ATTR(module_present_##index, S_IWUSR|S_IRUGO, sfp_value_show, sfp_value_store, MODULE_PRESENT_##index) -#define DECLARE_TRANSCEIVER_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr - -/*reset*/ -//#define DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(index) \ -// static SENSOR_DEVICE_ATTR(module_reset_##index, S_IWUSR | S_IRUGO, get_mode_reset, set_mode_reset, MODULE_RESET_##index) -//#define DECLARE_TRANSCEIVER_RESET_ATTR(index) &sensor_dev_attr_module_reset_##index.dev_attr.attr -#define DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(index) \ - static SENSOR_DEVICE_ATTR(module_reset_##index, S_IWUSR | S_IRUGO, sfp_value_show, sfp_value_store, MODULE_RESET_##index) -#define DECLARE_TRANSCEIVER_RESET_ATTR(index) &sensor_dev_attr_module_reset_##index.dev_attr.attr - - - - -static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); -static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); -/* transceiver attributes */ -static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(1); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(2); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(3); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(4); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(5); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(6); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(7); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(8); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(9); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(10); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(11); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(12); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(13); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(14); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(15); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(16); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(17); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(18); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(19); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(20); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(21); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(22); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(23); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(24); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(25); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(26); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(27); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(28); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(29); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(30); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(31); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(32); - -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(1); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(2); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(3); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(4); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(5); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(6); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(7); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(8); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(9); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(10); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(11); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(12); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(13); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(14); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(15); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(16); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(17); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(18); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(19); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(20); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(21); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(22); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(23); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(24); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(25); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(26); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(27); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(28); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(29); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(30); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(31); -DECLARE_TRANSCEIVER_SENSOR_DEVICE_RESET_ATTR(32); - - -static struct attribute *as7716_32xb_cpld_attributes[] = { - &sensor_dev_attr_version.dev_attr.attr, - &sensor_dev_attr_access.dev_attr.attr, - /* transceiver attributes */ - &sensor_dev_attr_module_present_all.dev_attr.attr, - DECLARE_TRANSCEIVER_ATTR(1), - DECLARE_TRANSCEIVER_ATTR(2), - DECLARE_TRANSCEIVER_ATTR(3), - DECLARE_TRANSCEIVER_ATTR(4), - DECLARE_TRANSCEIVER_ATTR(5), - DECLARE_TRANSCEIVER_ATTR(6), - DECLARE_TRANSCEIVER_ATTR(7), - DECLARE_TRANSCEIVER_ATTR(8), - DECLARE_TRANSCEIVER_ATTR(9), - DECLARE_TRANSCEIVER_ATTR(10), - DECLARE_TRANSCEIVER_ATTR(11), - DECLARE_TRANSCEIVER_ATTR(12), - DECLARE_TRANSCEIVER_ATTR(13), - DECLARE_TRANSCEIVER_ATTR(14), - DECLARE_TRANSCEIVER_ATTR(15), - DECLARE_TRANSCEIVER_ATTR(16), - DECLARE_TRANSCEIVER_ATTR(17), - DECLARE_TRANSCEIVER_ATTR(18), - DECLARE_TRANSCEIVER_ATTR(19), - DECLARE_TRANSCEIVER_ATTR(20), - DECLARE_TRANSCEIVER_ATTR(21), - DECLARE_TRANSCEIVER_ATTR(22), - DECLARE_TRANSCEIVER_ATTR(23), - DECLARE_TRANSCEIVER_ATTR(24), - DECLARE_TRANSCEIVER_ATTR(25), - DECLARE_TRANSCEIVER_ATTR(26), - DECLARE_TRANSCEIVER_ATTR(27), - DECLARE_TRANSCEIVER_ATTR(28), - DECLARE_TRANSCEIVER_ATTR(29), - DECLARE_TRANSCEIVER_ATTR(30), - DECLARE_TRANSCEIVER_ATTR(31), - DECLARE_TRANSCEIVER_ATTR(32), - DECLARE_TRANSCEIVER_RESET_ATTR(1), - DECLARE_TRANSCEIVER_RESET_ATTR(2), - DECLARE_TRANSCEIVER_RESET_ATTR(3), - DECLARE_TRANSCEIVER_RESET_ATTR(4), - DECLARE_TRANSCEIVER_RESET_ATTR(5), - DECLARE_TRANSCEIVER_RESET_ATTR(6), - DECLARE_TRANSCEIVER_RESET_ATTR(7), - DECLARE_TRANSCEIVER_RESET_ATTR(8), - DECLARE_TRANSCEIVER_RESET_ATTR(9), - DECLARE_TRANSCEIVER_RESET_ATTR(10), - DECLARE_TRANSCEIVER_RESET_ATTR(11), - DECLARE_TRANSCEIVER_RESET_ATTR(12), - DECLARE_TRANSCEIVER_RESET_ATTR(13), - DECLARE_TRANSCEIVER_RESET_ATTR(14), - DECLARE_TRANSCEIVER_RESET_ATTR(15), - DECLARE_TRANSCEIVER_RESET_ATTR(16), - DECLARE_TRANSCEIVER_RESET_ATTR(17), - DECLARE_TRANSCEIVER_RESET_ATTR(18), - DECLARE_TRANSCEIVER_RESET_ATTR(19), - DECLARE_TRANSCEIVER_RESET_ATTR(20), - DECLARE_TRANSCEIVER_RESET_ATTR(21), - DECLARE_TRANSCEIVER_RESET_ATTR(22), - DECLARE_TRANSCEIVER_RESET_ATTR(23), - DECLARE_TRANSCEIVER_RESET_ATTR(24), - DECLARE_TRANSCEIVER_RESET_ATTR(25), - DECLARE_TRANSCEIVER_RESET_ATTR(26), - DECLARE_TRANSCEIVER_RESET_ATTR(27), - DECLARE_TRANSCEIVER_RESET_ATTR(28), - DECLARE_TRANSCEIVER_RESET_ATTR(29), - DECLARE_TRANSCEIVER_RESET_ATTR(30), - DECLARE_TRANSCEIVER_RESET_ATTR(31), - DECLARE_TRANSCEIVER_RESET_ATTR(32), - NULL -}; - -static const struct attribute_group as7716_32xb_cpld_group = { - .attrs = as7716_32xb_cpld_attributes, -}; - -static ssize_t show_present_all(struct device *dev, struct device_attribute *da, - char *buf) -{ - int i, status; - u8 values[4] = {0}; - u8 regs[] = {0x30, 0x31, 0x32, 0x33}; - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - for (i = 0; i < ARRAY_SIZE(regs); i++) { - status = as7716_32xb_cpld_read_internal(client, regs[i]); - - if (status < 0) { - goto exit; - } - - values[i] = ~(u8)status; - } - - mutex_unlock(&data->update_lock); - - /* Return values 1 -> 32 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3]); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static int sfp_array_index_get(int attr_idx) -{ - switch(attr_idx) - { - case TRANSCEIVER_PRESENT_ATTR_ID(1): - case TRANSCEIVER_RESET_ATTR_ID(1): - return PORT1_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(2): - case TRANSCEIVER_RESET_ATTR_ID(2): - return PORT2_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(3): - case TRANSCEIVER_RESET_ATTR_ID(3): - return PORT3_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(4): - case TRANSCEIVER_RESET_ATTR_ID(4): - return PORT4_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(5): - case TRANSCEIVER_RESET_ATTR_ID(5): - return PORT5_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(6): - case TRANSCEIVER_RESET_ATTR_ID(6): - return PORT6_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(7): - case TRANSCEIVER_RESET_ATTR_ID(7): - return PORT7_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(8): - case TRANSCEIVER_RESET_ATTR_ID(8): - return PORT8_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(9): - case TRANSCEIVER_RESET_ATTR_ID(9): - return PORT9_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(10): - case TRANSCEIVER_RESET_ATTR_ID(10): - return PORT10_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(11): - case TRANSCEIVER_RESET_ATTR_ID(11): - return PORT11_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(12): - case TRANSCEIVER_RESET_ATTR_ID(12): - return PORT12_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(13): - case TRANSCEIVER_RESET_ATTR_ID(13): - return PORT13_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(14): - case TRANSCEIVER_RESET_ATTR_ID(14): - return PORT14_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(15): - case TRANSCEIVER_RESET_ATTR_ID(15): - return PORT15_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(16): - case TRANSCEIVER_RESET_ATTR_ID(16): - return PORT16_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(17): - case TRANSCEIVER_RESET_ATTR_ID(17): - return PORT17_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(18): - case TRANSCEIVER_RESET_ATTR_ID(18): - return PORT18_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(19): - case TRANSCEIVER_RESET_ATTR_ID(19): - return PORT19_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(20): - case TRANSCEIVER_RESET_ATTR_ID(20): - return PORT20_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(21): - case TRANSCEIVER_RESET_ATTR_ID(21): - return PORT21_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(22): - case TRANSCEIVER_RESET_ATTR_ID(22): - return PORT22_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(23): - case TRANSCEIVER_RESET_ATTR_ID(23): - return PORT23_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(24): - case TRANSCEIVER_RESET_ATTR_ID(24): - return PORT24_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(25): - case TRANSCEIVER_RESET_ATTR_ID(25): - return PORT25_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(26): - case TRANSCEIVER_RESET_ATTR_ID(26): - return PORT26_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(27): - case TRANSCEIVER_RESET_ATTR_ID(27): - return PORT27_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(28): - case TRANSCEIVER_RESET_ATTR_ID(28): - return PORT28_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(29): - case TRANSCEIVER_RESET_ATTR_ID(29): - return PORT29_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(30): - case TRANSCEIVER_RESET_ATTR_ID(30): - return PORT30_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(31): - case TRANSCEIVER_RESET_ATTR_ID(31): - return PORT31_ID; - case TRANSCEIVER_PRESENT_ATTR_ID(32): - case TRANSCEIVER_RESET_ATTR_ID(32): - return PORT32_ID; - default : - return -1; - } -} - - -static ssize_t sfp_value_store(struct device *dev, struct device_attribute *da, - char *buf, size_t size) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - int status = -EINVAL; - int index; - long keyin = 0; - - //printk("sfp_value_store\n"); - //printk("attr->index=%d\n", attr->index); - mutex_lock(&data->update_lock); - switch (attr->index) - { - case MODULE_PRESENT_1 ... MODULE_PRESENT_8: - case MODULE_PRESENT_9 ... MODULE_PRESENT_16: - case MODULE_PRESENT_17 ... MODULE_PRESENT_24: - case MODULE_PRESENT_25 ... MODULE_PRESENT_32: - index=sfp_array_index_get(attr->index); - if(index < 0 || index > PORT_NUM_MAX -1) - break; - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - if(keyin < 0 || keyin > 1) - break; - data->present[index]=keyin; - break; - case MODULE_RESET_1 ... MODULE_RESET_8: - case MODULE_RESET_9 ... MODULE_RESET_16: - case MODULE_RESET_17 ... MODULE_RESET_24: - case MODULE_RESET_25 ... MODULE_RESET_32: - index=sfp_array_index_get(attr->index); - if(index < 0 || index > PORT_NUM_MAX -1) - break; - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - if(keyin < 0 || keyin > 1) - break; - data->reset[index]=keyin; - break; - default : - break; - } - mutex_unlock(&data->update_lock); - return size; -} -static ssize_t sfp_value_show(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 as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - ssize_t ret = 0; - int index; - int status = -EINVAL; - - //printk("sfp_value_show, attr->index=%d\n", attr->index); - //printk("TRANSCEIVER_PRESENT_ATTR_ID(1)=%d, TRANSCEIVER_RESET_ATTR_ID(1)=%d\n", TRANSCEIVER_PRESENT_ATTR_ID(1), TRANSCEIVER_RESET_ATTR_ID(1)); - mutex_lock(&data->update_lock); - switch (attr->index) - { - case MODULE_PRESENT_1 ... MODULE_PRESENT_8: - case MODULE_PRESENT_9 ... MODULE_PRESENT_16: - case MODULE_PRESENT_17 ... MODULE_PRESENT_24: - case MODULE_PRESENT_25 ... MODULE_PRESENT_32: - index=sfp_array_index_get(attr->index); - if(index < 0 || index > PORT_NUM_MAX -1) - break; - status = sprintf(buf, "%u\n", data->present[index]); - break; - case MODULE_RESET_1 ... MODULE_RESET_8: - case MODULE_RESET_9 ... MODULE_RESET_16: - case MODULE_RESET_17 ... MODULE_RESET_24: - case MODULE_RESET_25 ... MODULE_RESET_32: - index=sfp_array_index_get(attr->index); - //printk("rst:attr->index=%d, index=%d\n",attr->index, index); - if(index < 0 || index > PORT_NUM_MAX -1) - break; - status = sprintf(buf, "%u\n", data->reset[index]); - break; - default : - break; - } - - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t show_present(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 as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - int status = 0; - u8 reg = 0, mask = 0; - - switch (attr->index) { - case MODULE_PRESENT_1 ... MODULE_PRESENT_8: - reg = 0x30; - mask = 0x1 << (attr->index - MODULE_PRESENT_1); - break; - case MODULE_PRESENT_9 ... MODULE_PRESENT_16: - reg = 0x31; - mask = 0x1 << (attr->index - MODULE_PRESENT_9); - break; - case MODULE_PRESENT_17 ... MODULE_PRESENT_24: - reg = 0x32; - mask = 0x1 << (attr->index - MODULE_PRESENT_17); - break; - case MODULE_PRESENT_25 ... MODULE_PRESENT_32: - reg = 0x33; - mask = 0x1 << (attr->index - MODULE_PRESENT_25); - break; - default: - return 0; - } - - - mutex_lock(&data->update_lock); - status = as7716_32xb_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - - return sprintf(buf, "%d\n", !(status & mask)); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t show_version(struct device *dev, struct device_attribute *da, - char *buf) -{ - u8 reg = 0, mask = 0; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - int status = 0; - - switch (attr->index) { - case CPLD_VERSION: - reg = 0x1; - mask = 0xFF; - break; - default: - break; - } - - mutex_lock(&data->update_lock); - status = as7716_32xb_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return sprintf(buf, "%d\n", (status & mask)); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - int status; - u32 addr, val; - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - - if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { - return -EINVAL; - } - - if (addr > 0xFF || val > 0xFF) { - return -EINVAL; - } - - mutex_lock(&data->update_lock); - status = as7716_32xb_cpld_write_internal(client, addr, val); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static int as7716_32xb_cpld_read_internal(struct i2c_client *client, u8 reg) -{ - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, reg); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - return status; -} - -static int as7716_32xb_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value) -{ - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, reg, value); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - return status; -} - -static void as7716_32xb_cpld_add_client(struct i2c_client *client) -{ - struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); - - if (!node) { - dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); - return; - } - - node->client = client; - - mutex_lock(&list_lock); - list_add(&node->list, &cpld_client_list); - mutex_unlock(&list_lock); -} - -static void as7716_32xb_cpld_remove_client(struct i2c_client *client) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int found = 0; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client == client) { - found = 1; - break; - } - } - - if (found) { - list_del(list_node); - kfree(cpld_node); - } - - mutex_unlock(&list_lock); -} - -static int as7716_32xb_cpld_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - int status; - struct as7716_32xb_cpld_data *data = NULL; - - data = kzalloc(sizeof(struct as7716_32xb_cpld_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7716_32xb_cpld_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - as7716_32xb_cpld_add_client(client); - - dev_info(&client->dev, "%s: cpld '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_cpld_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7716_32xb_cpld_remove(struct i2c_client *client) -{ - struct as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_cpld_group); - kfree(data); - as7716_32xb_cpld_remove_client(client); - - return 0; -} - -int as7716_32xb_cpld_read(unsigned short cpld_addr, u8 reg) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EPERM; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_read_byte_data(cpld_node->client, reg); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(as7716_32xb_cpld_read); - -int as7716_32xb_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EIO; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(as7716_32xb_cpld_write); - -static ssize_t get_mode_reset(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 as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - int status = 0; - u8 reg = 0, mask = 0; - - switch (attr->index) { - case MODULE_RESET_1 ... MODULE_RESET_8: - reg = 0x04; - mask = 0x1 << (attr->index - MODULE_RESET_1); - break; - case MODULE_RESET_9 ... MODULE_RESET_16: - reg = 0x05; - mask = 0x1 << (attr->index - MODULE_RESET_9); - break; - case MODULE_RESET_17 ... MODULE_RESET_24: - reg = 0x06; - mask = 0x1 << (attr->index - MODULE_RESET_17); - break; - case MODULE_RESET_25 ... MODULE_RESET_32: - reg = 0x07; - mask = 0x1 << (attr->index - MODULE_RESET_25); - break; - default: - return 0; - } - - - mutex_lock(&data->update_lock); - status = as7716_32xb_cpld_read_internal(client, reg); - - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - - return sprintf(buf, "%d\r\n", !(status & mask)); - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t set_mode_reset(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 as7716_32xb_cpld_data *data = i2c_get_clientdata(client); - long reset; - int status=0, val, error; - u8 reg = 0, mask = 0; - - - error = kstrtol(buf, 10, &reset); - if (error) { - return error; - } - //printk("set_mode_reset:attr->index=%d\n",attr->index); - switch (attr->index) { - case MODULE_RESET_1 ... MODULE_RESET_8: - reg = 0x04; - mask = 0x1 << (attr->index - MODULE_RESET_1); - break; - case MODULE_RESET_9 ... MODULE_RESET_16: - reg = 0x05; - mask = 0x1 << (attr->index - MODULE_RESET_9); - break; - case MODULE_RESET_17 ... MODULE_RESET_24: - reg = 0x06; - mask = 0x1 << (attr->index - MODULE_RESET_17); - break; - case MODULE_RESET_25 ... MODULE_RESET_32: - reg = 0x07; - mask = 0x1 << (attr->index - MODULE_RESET_25); - break; - default: - return 0; - } - mutex_lock(&data->update_lock); - - status = as7716_32xb_cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - //printk("set_mode_reset:reset=%d, reg=0x%x, mask=0x%x, ori_val=0x%x\n", reset, reg, mask, status); - /* Update lp_mode status */ - if (reset) - { - val = status&(~mask); - //printk("1:new val=0x%x\n", val); - } - else - { - val =status | (mask); - //printk("0:new val=0x%x\n", val); - } - - status = as7716_32xb_cpld_write_internal(client, reg, val); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - - - -static const struct i2c_device_id as7716_32xb_cpld_id[] = { - { "as7716_32xb_cpld1", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7716_32xb_cpld_id); - -static struct i2c_driver as7716_32xb_cpld_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7716_32xb_cpld1", - }, - .probe = as7716_32xb_cpld_probe, - .remove = as7716_32xb_cpld_remove, - .id_table = as7716_32xb_cpld_id, - .address_list = normal_i2c, -}; - -static int __init as7716_32xb_cpld_init(void) -{ - mutex_init(&list_lock); - return i2c_add_driver(&as7716_32xb_cpld_driver); -} - -static void __exit as7716_32xb_cpld_exit(void) -{ - i2c_del_driver(&as7716_32xb_cpld_driver); -} - -module_init(as7716_32xb_cpld_init); -module_exit(as7716_32xb_cpld_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7716_32xb_cpld driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_fan.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_fan.c deleted file mode 100755 index 5c1c3016c3a1..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_fan.c +++ /dev/null @@ -1,969 +0,0 @@ -/* - * A hwmon driver for the Accton as7716 32x fan - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRVNAME "as7716_32xb_fan" - -#define NUM_THERMAL_SENSORS (3) /* Get sum of this number of sensors.*/ -#define THERMAL_SENSORS_DRIVER "lm75" -#define STRING_TO_DEC_VALUE 10 - -#define IN -#define OUT - -static struct as7716_32xb_fan_data *as7716_32xb_fan_update_device(struct device *dev); -static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t get_enable(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_enable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, char *buf); - - -static ssize_t fan_value_show(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t fan_value_store(struct device *dev, struct device_attribute *da, - char *buf, size_t size); - -/* fan related data, the index should match sysfs_fan_attributes - */ -static const u8 fan_reg[] = { - 0x0F, /* fan 1-6 present status */ - 0x10, /* fan 1-6 direction(0:B2F 1:F2B) */ - 0x11, /* fan PWM(for all fan) */ - 0x12, /* front fan 1 speed(rpm) */ - 0x13, /* front fan 2 speed(rpm) */ - 0x14, /* front fan 3 speed(rpm) */ - 0x15, /* front fan 4 speed(rpm) */ - 0x16, /* front fan 5 speed(rpm) */ - 0x17, /* front fan 6 speed(rpm) */ - 0x22, /* rear fan 1 speed(rpm) */ - 0x23, /* rear fan 2 speed(rpm) */ - 0x24, /* rear fan 3 speed(rpm) */ - 0x25, /* rear fan 4 speed(rpm) */ - 0x26, /* rear fan 5 speed(rpm) */ - 0x27, /* rear fan 6 speed(rpm) */ -}; - -#define FAN_NUM_MAX 6 -/* Each client has this additional data */ -struct as7716_32xb_fan_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */ - u8 enable; - u8 duty_cycle; - int system_temp; /*In unit of mini-Celsius*/ - int sensors_found; - unsigned int present[FAN_NUM_MAX]; - unsigned int front_speed_rpm[FAN_NUM_MAX]; - unsigned int rear_speed_rpm[FAN_NUM_MAX]; - unsigned int direction[FAN_NUM_MAX]; - unsigned int fault[FAN_NUM_MAX]; - unsigned int input[FAN_NUM_MAX]; -}; - -enum FAN_ID { - FAN1_ID, - FAN2_ID, - FAN3_ID, - FAN4_ID, - FAN5_ID, - FAN6_ID -}; - -enum sysfs_fan_attributes { - FAN_PRESENT_REG, - FAN_DIRECTION_REG, - FAN_DUTY_CYCLE_PERCENTAGE, /* Only one CPLD register to control duty cycle for all fans */ - FAN1_FRONT_SPEED_RPM, - FAN2_FRONT_SPEED_RPM, - FAN3_FRONT_SPEED_RPM, - FAN4_FRONT_SPEED_RPM, - FAN5_FRONT_SPEED_RPM, - FAN6_FRONT_SPEED_RPM, - FAN1_REAR_SPEED_RPM, - FAN2_REAR_SPEED_RPM, - FAN3_REAR_SPEED_RPM, - FAN4_REAR_SPEED_RPM, - FAN5_REAR_SPEED_RPM, - FAN6_REAR_SPEED_RPM, - FAN1_DIRECTION, - FAN2_DIRECTION, - FAN3_DIRECTION, - FAN4_DIRECTION, - FAN5_DIRECTION, - FAN6_DIRECTION, - FAN1_PRESENT, - FAN2_PRESENT, - FAN3_PRESENT, - FAN4_PRESENT, - FAN5_PRESENT, - FAN6_PRESENT, - FAN1_FAULT, - FAN2_FAULT, - FAN3_FAULT, - FAN4_FAULT, - FAN5_FAULT, - FAN6_FAULT -}; - -/* Define attributes - */ -#define DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(index, index2) \ - static SENSOR_DEVICE_ATTR(fan##index##_fault, S_IRUGO|S_IWUSR, fan_value_show, fan_value_store, FAN##index##_FAULT);\ - static SENSOR_DEVICE_ATTR(fan##index2##_fault, S_IRUGO|S_IWUSR, fan_value_show, fan_value_store, FAN##index##_FAULT) -#define DECLARE_FAN_FAULT_ATTR(index, index2) &sensor_dev_attr_fan##index##_fault.dev_attr.attr, \ - &sensor_dev_attr_fan##index2##_fault.dev_attr.attr - -#define DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan##index##_direction, S_IRUGO|S_IWUSR, fan_value_show, fan_value_store, FAN##index##_DIRECTION) -#define DECLARE_FAN_DIRECTION_ATTR(index) &sensor_dev_attr_fan##index##_direction.dev_attr.attr - - -#define DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_value_show, fan_value_store, FAN_DUTY_CYCLE_PERCENTAGE);\ - static SENSOR_DEVICE_ATTR(pwm##index, S_IWUSR | S_IRUGO, fan_value_show, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE);\ - static SENSOR_DEVICE_ATTR(pwm##index##_enable, S_IWUSR | S_IRUGO, get_enable, set_enable, FAN_DUTY_CYCLE_PERCENTAGE) - -#define DECLARE_FAN_DUTY_CYCLE_ATTR(index) &sensor_dev_attr_fan_duty_cycle_percentage.dev_attr.attr, \ - &sensor_dev_attr_pwm##index.dev_attr.attr, \ - &sensor_dev_attr_pwm##index##_enable.dev_attr.attr - -#define DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR() \ - static SENSOR_DEVICE_ATTR(sys_temp, S_IWUSR|S_IRUGO, get_sys_temp, NULL, FAN_DUTY_CYCLE_PERCENTAGE) - -#define DECLARE_FAN_SYSTEM_TEMP_ATTR() &sensor_dev_attr_sys_temp.dev_attr.attr - - - -#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan##index##_present, S_IWUSR|S_IRUGO, fan_value_show, fan_value_store, FAN##index##_PRESENT) -#define DECLARE_FAN_PRESENT_ATTR(index) &sensor_dev_attr_fan##index##_present.dev_attr.attr - - -#define DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(index, index2) \ - static SENSOR_DEVICE_ATTR(fan##index##_front_speed_rpm, S_IWUSR|S_IRUGO, fan_value_show, fan_value_store, FAN##index##_FRONT_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index##_rear_speed_rpm, S_IWUSR|S_IRUGO, fan_value_show, fan_value_store, FAN##index##_REAR_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index##_input, S_IWUSR|S_IRUGO, fan_value_show, fan_value_store, FAN##index##_FRONT_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index2##_input, S_IWUSR|S_IRUGO, fan_value_show, fan_value_store, FAN##index##_REAR_SPEED_RPM) -#define DECLARE_FAN_SPEED_RPM_ATTR(index, index2) &sensor_dev_attr_fan##index##_front_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_fan##index##_rear_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_fan##index##_input.dev_attr.attr, \ - &sensor_dev_attr_fan##index2##_input.dev_attr.attr - -/* 6 fan fault attributes in this platform */ -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(1,11); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(2,12); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(3,13); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(4,14); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(5,15); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(6,16); -/* 6 fan speed(rpm) attributes in this platform */ -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(1,11); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(2,12); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(3,13); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(4,14); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(5,15); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(6,16); -/* 6 fan present attributes in this platform */ -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(1); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(2); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(3); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(4); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(5); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(6); - -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(1); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(2); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(3); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(4); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(5); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(6); - -/* 1 fan duty cycle attribute in this platform */ -DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(1); -/* System temperature for fancontrol */ -DECLARE_FAN_SYSTEM_TEMP_SENSOR_DEV_ATTR(); - -static struct attribute *as7716_32xb_fan_attributes[] = { - /* fan related attributes */ - DECLARE_FAN_FAULT_ATTR(1,11), - DECLARE_FAN_FAULT_ATTR(2,12), - DECLARE_FAN_FAULT_ATTR(3,13), - DECLARE_FAN_FAULT_ATTR(4,14), - DECLARE_FAN_FAULT_ATTR(5,15), - DECLARE_FAN_FAULT_ATTR(6,16), - DECLARE_FAN_SPEED_RPM_ATTR(1,11), - DECLARE_FAN_SPEED_RPM_ATTR(2,12), - DECLARE_FAN_SPEED_RPM_ATTR(3,13), - DECLARE_FAN_SPEED_RPM_ATTR(4,14), - DECLARE_FAN_SPEED_RPM_ATTR(5,15), - DECLARE_FAN_SPEED_RPM_ATTR(6,16), - DECLARE_FAN_PRESENT_ATTR(1), - DECLARE_FAN_PRESENT_ATTR(2), - DECLARE_FAN_PRESENT_ATTR(3), - DECLARE_FAN_PRESENT_ATTR(4), - DECLARE_FAN_PRESENT_ATTR(5), - DECLARE_FAN_PRESENT_ATTR(6), - DECLARE_FAN_DIRECTION_ATTR(1), - DECLARE_FAN_DIRECTION_ATTR(2), - DECLARE_FAN_DIRECTION_ATTR(3), - DECLARE_FAN_DIRECTION_ATTR(4), - DECLARE_FAN_DIRECTION_ATTR(5), - DECLARE_FAN_DIRECTION_ATTR(6), - DECLARE_FAN_DUTY_CYCLE_ATTR(1), - DECLARE_FAN_SYSTEM_TEMP_ATTR(), - NULL -}; - -#define FAN_DUTY_CYCLE_REG_MASK 0xF -#define FAN_MAX_DUTY_CYCLE 100 -#define FAN_REG_VAL_TO_SPEED_RPM_STEP 100 - -static int as7716_32xb_fan_read_value(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_byte_data(client, reg); -} - -static int as7716_32xb_fan_write_value(struct i2c_client *client, u8 reg, u8 value) -{ - return i2c_smbus_write_byte_data(client, reg, value); -} - -/* fan utility functions - */ -static u32 reg_val_to_duty_cycle(u8 reg_val) -{ - reg_val &= FAN_DUTY_CYCLE_REG_MASK; - return ((u32)(reg_val+1) * 625 + 75)/ 100; -} - -static u8 duty_cycle_to_reg_val(u8 duty_cycle) -{ - return ((u32)duty_cycle * 100 / 625) - 1; -} - -static u32 reg_val_to_speed_rpm(u8 reg_val) -{ - return (u32)reg_val * FAN_REG_VAL_TO_SPEED_RPM_STEP; -} - -static u8 reg_val_to_direction(u8 reg_val, enum FAN_ID id) -{ - u8 mask = (1 << id); - - reg_val &= mask; - - return reg_val ? 1 : 0; -} -static u8 reg_val_to_is_present(u8 reg_val, enum FAN_ID id) -{ - u8 mask = (1 << id); - - reg_val &= mask; - - return reg_val ? 0 : 1; -} - -static u8 is_fan_fault(struct as7716_32xb_fan_data *data, enum FAN_ID id) -{ - u8 ret = 0; - - /* Check if the speed of front or rear fan is ZERO, - */ - if (!data->front_speed_rpm[id] && - !data->rear_speed_rpm[id] ) - { - ret = 1; - } - - return ret; -} - - -static ssize_t set_enable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct as7716_32xb_fan_data *data = as7716_32xb_fan_update_device(dev); - int error, value; - - error = kstrtoint(buf, 10, &value); - if (error) - return error; - - if (value < 0 || value > 1) - return -EINVAL; - - data->enable = value; - if (value == 0) - { - return set_duty_cycle(dev, da, buf, FAN_MAX_DUTY_CYCLE); - } - return count; -} - - - -static ssize_t get_enable(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as7716_32xb_fan_data *data = as7716_32xb_fan_update_device(dev); - - return sprintf(buf, "%u\n", data->enable); -} - -static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - int error, value; - struct i2c_client *client = to_i2c_client(dev); - - error = kstrtoint(buf, 10, &value); - if (error) - return error; - - if (value < 0 || value > FAN_MAX_DUTY_CYCLE) - return -EINVAL; - - as7716_32xb_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */ - as7716_32xb_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value)); - return count; -} - -/* Due to this struct is declared at lm75.c, it cannot be include - * under Sonic environment. I duplicate it from lm75.c. - */ -struct lm75_data { - struct i2c_client *client; - struct device *hwmon_dev; - struct thermal_zone_device *tz; - struct mutex update_lock; - u8 orig_conf; - u8 resolution; /* In bits, between 9 and 12 */ - u8 resolution_limits; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - unsigned long sample_time; /* In jiffies */ - s16 temp[3]; /* Register values, - 0 = input - 1 = max - 2 = hyst */ -}; - -/*Copied from lm75.c*/ -static inline long lm75_reg_to_mc(s16 temp, u8 resolution) -{ - return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8); -} - -/*Get hwmon_dev from i2c_client, set hwmon_dev = NULL is failed.*/ -static struct device * get_hwmon_dev( - struct i2c_client *client) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - if(data) - { - if( data->valid == 1 && data->hwmon_dev) - { - return data->hwmon_dev; - } - - } - return NULL; -} - -/* To find hwmon index by opening hwmon under that i2c address. - */ -static int find_hwmon_index_by_FileOpen( - int bus_nr, - unsigned short addr, - OUT int *index) -{ -#define MAX_HWMON_DEVICE (10) /* Find hwmon device in 0~10*/ - struct file *sfd; - char client_name[96]; - int i=0; - - do { - snprintf(client_name, sizeof(client_name), - "/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input", - bus_nr, addr, i); - - sfd = filp_open(client_name, O_RDONLY, 0); - i++; - } while( IS_ERR(sfd) && i < MAX_HWMON_DEVICE); - - if (IS_ERR(sfd)) { - pr_err("Failed to open file(%s)#%d\r\n", client_name, __LINE__); - return -ENOENT; - } - filp_close(sfd, 0); - *index = i - 1; - return 0; - -#undef MAX_HWMON_DEVICE -} - -static int get_temp_file_path( - int bus_nr, unsigned short addr, - struct device *hwmon_dev - ,char *path, int max_len) -{ - - if(hwmon_dev && strlen(dev_name(hwmon_dev))) - { - snprintf(path, max_len, - "/sys/bus/i2c/devices/%d-%04x/hwmon/%s/temp1_input", - bus_nr, addr, dev_name(hwmon_dev)); - } - else - { - int i=0; - if(find_hwmon_index_by_FileOpen( bus_nr, addr, &i)) - { - return -EIO; - } - snprintf(path, max_len, - "/sys/bus/i2c/devices/%d-%04x/hwmon/hwmon%d/temp1_input", - bus_nr, addr, i); - } - return 0; -} - -/*File read the dev file at user space.*/ -static int read_devfile_temp1_input( - struct device *dev, - int bus_nr, - unsigned short addr, - struct device *hwmon_dev, - int *miniCelsius) -{ - struct file *sfd; - char buffer[96]; - char devfile[96]; - int rc, status; - int rdlen, value; - mm_segment_t old_fs; - - rc = 0; - get_temp_file_path(bus_nr, addr, hwmon_dev, devfile, sizeof(devfile)); - sfd = filp_open(devfile, O_RDONLY, 0); - if (IS_ERR(sfd)) { - pr_err("Failed to open file(%s)#%d\r\n", devfile, __LINE__); - return -ENOENT; - } - dev_dbg(dev, "Found device:%s\n",devfile); - - if(!(sfd->f_op) || !(sfd->f_op->read) ) { - pr_err("file %s cann't readable ?\n",devfile); - return -ENOENT; - } - - old_fs = get_fs(); - set_fs(KERNEL_DS); - rdlen = sfd->f_op->read(sfd, buffer, sizeof(buffer), &sfd->f_pos); - if (rdlen == 0) { - pr_err( "File(%s) empty!\n", devfile); - rc = -EIO; - goto exit; - } - status = sscanf(buffer, "%d", &value); - if (status != 1) { - rc = -EIO; - goto exit; - } - *miniCelsius = value; - dev_dbg(dev,"found sensors: %d @i2c %d-%04x\n", value, bus_nr, addr); - -exit: - set_fs(old_fs); - filp_close(sfd, 0); - return rc; -} - -static u8 is_lm75_data_due(struct i2c_client *client) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - if (time_after(jiffies, data->last_updated + data->sample_time)) - { - return 1; - } - return 0; -} -static int get_lm75_temp(struct i2c_client *client, int *miniCelsius) -{ - struct lm75_data *data = NULL; - - data = i2c_get_clientdata(client); - *miniCelsius = lm75_reg_to_mc(data->temp[0], data->resolution); - - return 0; -} - -static int _find_lm75_device(struct device *dev, void *data) -{ - struct device_driver *driver; - struct as7716_32xb_fan_data *prv = data; - char *driver_name = THERMAL_SENSORS_DRIVER; - - driver = dev->driver; - if (driver && driver->name && - strcmp(driver->name, driver_name) == 0) - { - struct i2c_client *client; - client = to_i2c_client(dev); - if (client) - { - /*cannot use "struct i2c_adapter *adap = to_i2c_adapter(dev);"*/ - struct i2c_adapter *adap = client->adapter; - int miniCelsius = 0; - - - if (!adap) { - return -ENXIO; - } - - /* If the data is not updated, read them from devfile - to drive them updateing data from chip.*/ - if (is_lm75_data_due(client)) - { - struct device *hwmon_dev; - - hwmon_dev = get_hwmon_dev(client); - if(0 == read_devfile_temp1_input(dev, adap->nr, - client->addr, hwmon_dev, &miniCelsius)) - { - prv->system_temp += miniCelsius; - prv->sensors_found++; - } - - } - else - { - get_lm75_temp(client, &miniCelsius); - prv->system_temp += miniCelsius; - prv->sensors_found++; - - } - } - } - return 0; -} - -/*Find all lm75 devices and return sum of temperatures.*/ -static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, - char *buf) -{ - ssize_t ret = 0; - struct as7716_32xb_fan_data *data = as7716_32xb_fan_update_device(dev); - - data->system_temp=0; - data->sensors_found=0; - i2c_for_each_dev(data, _find_lm75_device); - if (NUM_THERMAL_SENSORS != data->sensors_found) - { - dev_dbg(dev,"only %d of %d temps are found\n", - data->sensors_found, NUM_THERMAL_SENSORS); - data->system_temp = 0; - } - ret = sprintf(buf, "%d\n",data->system_temp); - return ret; -} - - -static int fan_array_index_get(int attr_idx) -{ - switch(attr_idx) - { - case FAN1_PRESENT: - case FAN1_FRONT_SPEED_RPM: - case FAN1_REAR_SPEED_RPM: - case FAN1_FAULT: - case FAN1_DIRECTION: - return FAN1_ID; - case FAN2_PRESENT: - case FAN2_FRONT_SPEED_RPM: - case FAN2_REAR_SPEED_RPM: - case FAN2_FAULT: - case FAN2_DIRECTION: - return FAN2_ID; - case FAN3_PRESENT: - case FAN3_FRONT_SPEED_RPM: - case FAN3_REAR_SPEED_RPM: - case FAN3_FAULT: - case FAN3_DIRECTION: - return FAN3_ID; - case FAN4_PRESENT: - case FAN4_FRONT_SPEED_RPM: - case FAN4_REAR_SPEED_RPM: - case FAN4_FAULT: - case FAN4_DIRECTION: - return FAN4_ID; - case FAN5_PRESENT: - case FAN5_FRONT_SPEED_RPM: - case FAN5_REAR_SPEED_RPM: - case FAN5_FAULT: - case FAN5_DIRECTION: - return FAN5_ID; - case FAN6_PRESENT: - case FAN6_FRONT_SPEED_RPM: - case FAN6_REAR_SPEED_RPM: - case FAN6_FAULT: - case FAN6_DIRECTION: - return FAN6_ID; - default : - return -1; - } -} - -static ssize_t fan_value_store(struct device *dev, struct device_attribute *da, - char *buf, size_t size) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_fan_data *data = i2c_get_clientdata(client); - int status = -EINVAL; - int index; - long keyin = 0; - //printk("fan_value_store\n"); - //printk("attr->index=%d\n", attr->index); - mutex_lock(&data->update_lock); - switch (attr->index) - { - case FAN_DUTY_CYCLE_PERCENTAGE: - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - if (status) - break; - if (keyin > 1 || keyin < 0) - break; - data->duty_cycle=keyin; - break; - case FAN1_FRONT_SPEED_RPM: - case FAN2_FRONT_SPEED_RPM: - case FAN3_FRONT_SPEED_RPM: - case FAN4_FRONT_SPEED_RPM: - case FAN5_FRONT_SPEED_RPM: - case FAN6_FRONT_SPEED_RPM: - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - if (status) - break; - index=fan_array_index_get(attr->index); - if(index < 0 || index > (FAN_NUM_MAX-1)) - break; - data->front_speed_rpm[index]=keyin; - break; - case FAN1_REAR_SPEED_RPM: - case FAN2_REAR_SPEED_RPM: - case FAN3_REAR_SPEED_RPM: - case FAN4_REAR_SPEED_RPM: - case FAN5_REAR_SPEED_RPM: - case FAN6_REAR_SPEED_RPM: - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - if (status) - break; - index=fan_array_index_get(attr->index); - if(index < 0 || index > (FAN_NUM_MAX-1)) - break; - data->rear_speed_rpm[index]=keyin; - case FAN1_PRESENT: - case FAN2_PRESENT: - case FAN3_PRESENT: - case FAN4_PRESENT: - case FAN5_PRESENT: - case FAN6_PRESENT: - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - if (status) - break; - index=fan_array_index_get(attr->index); - if(index < 0 || index > (FAN_NUM_MAX-1)) - break; - if(keyin < 0 || keyin > 1) - break; - data->present[index]=keyin; - break; - case FAN1_FAULT: - case FAN2_FAULT: - case FAN3_FAULT: - case FAN4_FAULT: - case FAN5_FAULT: - case FAN6_FAULT: - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - if (status) - break; - index=fan_array_index_get(attr->index); - if(index < 0 || index > (FAN_NUM_MAX-1)) - break; - if(keyin < 0 || keyin > 1) - break; - data->fault[index]=keyin; - break; - case FAN1_DIRECTION: - case FAN2_DIRECTION: - case FAN3_DIRECTION: - case FAN4_DIRECTION: - case FAN5_DIRECTION: - case FAN6_DIRECTION: - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - if (status) - break; - index=fan_array_index_get(attr->index); - if(index < 0 || index > (FAN_NUM_MAX-1)) - break; - if(keyin < 0 || keyin > 1) - break; - data->direction[index]=keyin; - break; - default: - break; - } - mutex_unlock(&data->update_lock); - return size; -} -static ssize_t fan_value_show(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 as7716_32xb_fan_data *data = i2c_get_clientdata(client); - int status = -EINVAL; - int index=0; - //printk("ffan_value_show\n"); - //printk("attr->index=%d\n", attr->index); - mutex_lock(&data->update_lock); - switch (attr->index) - { - case FAN_DUTY_CYCLE_PERCENTAGE: - status = sprintf(buf, "%u\n", data->duty_cycle); - break; - case FAN1_FRONT_SPEED_RPM: - case FAN2_FRONT_SPEED_RPM: - case FAN3_FRONT_SPEED_RPM: - case FAN4_FRONT_SPEED_RPM: - case FAN5_FRONT_SPEED_RPM: - case FAN6_FRONT_SPEED_RPM: - index=fan_array_index_get(attr->index); - if(index < 0 || index > (FAN_NUM_MAX-1)) - break; - status = sprintf(buf, "%u\n", data->front_speed_rpm[index]); - break; - case FAN1_REAR_SPEED_RPM: - case FAN2_REAR_SPEED_RPM: - case FAN3_REAR_SPEED_RPM: - case FAN4_REAR_SPEED_RPM: - case FAN5_REAR_SPEED_RPM: - case FAN6_REAR_SPEED_RPM: - index=fan_array_index_get(attr->index); - if(index < 0 || index > (FAN_NUM_MAX-1)) - break; - status = sprintf(buf, "%u\n", data->rear_speed_rpm[index]); - break; - case FAN1_PRESENT: - case FAN2_PRESENT: - case FAN3_PRESENT: - case FAN4_PRESENT: - case FAN5_PRESENT: - case FAN6_PRESENT: - index=fan_array_index_get(attr->index); - if(index < 0 || index > (FAN_NUM_MAX-1)) - break; - status = sprintf(buf, "%d\n", data->present[index]); - break; - case FAN1_FAULT: - case FAN2_FAULT: - case FAN3_FAULT: - case FAN4_FAULT: - case FAN5_FAULT: - case FAN6_FAULT: - index=fan_array_index_get(attr->index); - if(index < 0 || index > (FAN_NUM_MAX-1)) - break; - status = sprintf(buf, "%d\n", is_fan_fault(data, index)); - break; - case FAN1_DIRECTION: - case FAN2_DIRECTION: - case FAN3_DIRECTION: - case FAN4_DIRECTION: - case FAN5_DIRECTION: - case FAN6_DIRECTION: - index=fan_array_index_get(attr->index);; - if(index < 0 || index > (FAN_NUM_MAX-1)) - break; - status = sprintf(buf, "%d\n", data->direction[index]); - break; - default: - break; - } - mutex_unlock(&data->update_lock); - return status; -} - -static const struct attribute_group as7716_32xb_fan_group = { - .attrs = as7716_32xb_fan_attributes, -}; - -static struct as7716_32xb_fan_data *as7716_32xb_fan_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_fan_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || - !data->valid) { - int i; - - dev_dbg(&client->dev, "Starting as7716_32xb_fan update\n"); - data->valid = 0; - - /* Update fan data - */ - for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) { - int status = as7716_32xb_fan_read_value(client, fan_reg[i]); - - if (status < 0) { - data->valid = 0; - mutex_unlock(&data->update_lock); - dev_dbg(&client->dev, "reg %d, err %d\n", fan_reg[i], status); - return data; - } - else { - data->reg_val[i] = status; - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -static int as7716_32xb_fan_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7716_32xb_fan_data *data; - int status; - - data = kzalloc(sizeof(struct as7716_32xb_fan_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7716_32xb_fan_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: fan '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_fan_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7716_32xb_fan_remove(struct i2c_client *client) -{ - struct as7716_32xb_fan_data *data = i2c_get_clientdata(client); - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_fan_group); - - return 0; -} - -/* Addresses to scan */ -static const unsigned short normal_i2c[] = { 0x66, I2C_CLIENT_END }; - -static const struct i2c_device_id as7716_32xb_fan_id[] = { - { "as7716_32xb_fan", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7716_32xb_fan_id); - -static struct i2c_driver as7716_32xb_fan_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = DRVNAME, - }, - .probe = as7716_32xb_fan_probe, - .remove = as7716_32xb_fan_remove, - .id_table = as7716_32xb_fan_id, - .address_list = normal_i2c, -}; - -static int __init as7716_32xb_fan_init(void) -{ - return i2c_add_driver(&as7716_32xb_fan_driver); -} - -static void __exit as7716_32xb_fan_exit(void) -{ - i2c_del_driver(&as7716_32xb_fan_driver); -} - -module_init(as7716_32xb_fan_init); -module_exit(as7716_32xb_fan_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7716_32xb_fan driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_leds.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_leds.c deleted file mode 100755 index 2fa3fd722cb1..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_leds.c +++ /dev/null @@ -1,443 +0,0 @@ -/* - * A LED driver for the as7716_32xb_led - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/*#define DEBUG*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -extern void led_classdev_unregister(struct led_classdev *led_cdev); -extern int led_classdev_register(struct device *parent, struct led_classdev *led_cdev); -extern void led_classdev_resume(struct led_classdev *led_cdev); -extern void led_classdev_suspend(struct led_classdev *led_cdev); - -#define DRVNAME "as7716_32x_led" - -struct as7716_32x_led_data { - struct platform_device *pdev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[1]; /* only 1 register*/ -}; - -static struct as7716_32x_led_data *ledctl = NULL; - -/* LED related data - */ - -#define LED_CNTRLER_I2C_ADDRESS (0x60) - -#define LED_TYPE_DIAG_REG_MASK (0x3) -#define LED_MODE_DIAG_GREEN_VALUE (0x02) -#define LED_MODE_DIAG_RED_VALUE (0x01) -#define LED_MODE_DIAG_AMBER_VALUE (0x00) /*It's yellow actually. Green+Red=Yellow*/ -#define LED_MODE_DIAG_OFF_VALUE (0x03) - - -#define LED_TYPE_LOC_REG_MASK (0x80) -#define LED_MODE_LOC_ON_VALUE (0) -#define LED_MODE_LOC_OFF_VALUE (0x80) - -enum led_type { - LED_TYPE_DIAG, - LED_TYPE_LOC, - LED_TYPE_FAN, - LED_TYPE_PSU1, - LED_TYPE_PSU2 -}; - -struct led_reg { - u32 types; - u8 reg_addr; -}; - -static const struct led_reg led_reg_map[] = { - {(1<update_lock); - - if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2) - || !ledctl->valid) { - int i; - - dev_dbg(&ledctl->pdev->dev, "Starting as7716_32x_led update\n"); - - /* Update LED data - */ - for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { - int status = as7716_32x_led_read_value(led_reg_map[i].reg_addr); - - if (status < 0) { - ledctl->valid = 0; - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg_map[i].reg_addr, status); - goto exit; - } - else - { - ledctl->reg_val[i] = status; - } - } - - ledctl->last_updated = jiffies; - ledctl->valid = 1; - } - -exit: - mutex_unlock(&ledctl->update_lock); -} - -static void as7716_32x_led_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode, - enum led_type type) -{ - int reg_val; - u8 reg ; - mutex_lock(&ledctl->update_lock); - - if( !getLedReg(type, ®)) - { - dev_dbg(&ledctl->pdev->dev, "Not match item for %d.\n", type); - } - - reg_val = as7716_32x_led_read_value(reg); - - if (reg_val < 0) { - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val); - goto exit; - } - reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val); - as7716_32x_led_write_value(reg, reg_val); - - /* to prevent the slow-update issue */ - ledctl->valid = 0; - -exit: - mutex_unlock(&ledctl->update_lock); -} - - -static void as7716_32x_led_diag_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - as7716_32x_led_set(led_cdev, led_light_mode, LED_TYPE_DIAG); -} - -static enum led_brightness as7716_32x_led_diag_get(struct led_classdev *cdev) -{ - as7716_32x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); -} - -static void as7716_32x_led_loc_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - as7716_32x_led_set(led_cdev, led_light_mode, LED_TYPE_LOC); -} - -static enum led_brightness as7716_32x_led_loc_get(struct led_classdev *cdev) -{ - as7716_32x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); -} - -static void as7716_32x_led_auto_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ -} - -static enum led_brightness as7716_32x_led_auto_get(struct led_classdev *cdev) -{ - return LED_MODE_AUTO; -} - -static struct led_classdev as7716_32x_leds[] = { - [LED_TYPE_DIAG] = { - .name = "as7716_32x_led::diag", - .default_trigger = "unused", - .brightness_set = as7716_32x_led_diag_set, - .brightness_get = as7716_32x_led_diag_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_RED, - }, - [LED_TYPE_LOC] = { - .name = "as7716_32x_led::loc", - .default_trigger = "unused", - .brightness_set = as7716_32x_led_loc_set, - .brightness_get = as7716_32x_led_loc_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_BLUE, - }, - [LED_TYPE_FAN] = { - .name = "as7716_32x_led::fan", - .default_trigger = "unused", - .brightness_set = as7716_32x_led_auto_set, - .brightness_get = as7716_32x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_PSU1] = { - .name = "as7716_32x_led::psu1", - .default_trigger = "unused", - .brightness_set = as7716_32x_led_auto_set, - .brightness_get = as7716_32x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_PSU2] = { - .name = "as7716_32x_led::psu2", - .default_trigger = "unused", - .brightness_set = as7716_32x_led_auto_set, - .brightness_get = as7716_32x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, -}; - -static int as7716_32x_led_suspend(struct platform_device *dev, - pm_message_t state) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(as7716_32x_leds); i++) { - led_classdev_suspend(&as7716_32x_leds[i]); - } - - return 0; -} - -static int as7716_32x_led_resume(struct platform_device *dev) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(as7716_32x_leds); i++) { - led_classdev_resume(&as7716_32x_leds[i]); - } - - return 0; -} - -static int as7716_32x_led_probe(struct platform_device *pdev) -{ - int ret, i; - - printk("as7716_32x_led_probe 1\n"); - for (i = 0; i < ARRAY_SIZE(as7716_32x_leds); i++) { - ret = led_classdev_register(&pdev->dev, &as7716_32x_leds[i]); - - if (ret < 0) - { - printk("ret < 0, i=%d\n", i); - break; - } - } - printk("as7716_32x_led_probe 2\n"); - /* Check if all LEDs were successfully registered */ - if (i != ARRAY_SIZE(as7716_32x_leds)){ - int j; - - /* only unregister the LEDs that were successfully registered */ - for (j = 0; j < i; j++) { - led_classdev_unregister(&as7716_32x_leds[i]); - } - } - - printk("as7716_32x_led_probe 3\n"); - return 0; -} - -static int as7716_32x_led_remove(struct platform_device *pdev) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(as7716_32x_leds); i++) { - led_classdev_unregister(&as7716_32x_leds[i]); - } - - return 0; -} - -static struct platform_driver as7716_32x_led_driver = { - .probe = as7716_32x_led_probe, - .remove = as7716_32x_led_remove, - .suspend = as7716_32x_led_suspend, - .resume = as7716_32x_led_resume, - .driver = { - .name = DRVNAME, - .owner = THIS_MODULE, - }, -}; - -static int __init as7716_32x_led_init(void) -{ - int ret; - - printk("leds:1\n"); - ret = platform_driver_register(&as7716_32x_led_driver); - if (ret < 0) { - printk("leds:fail platform_driver_register\n"); - goto exit; - } - printk("leds:2\n"); - ledctl = kzalloc(sizeof(struct as7716_32x_led_data), GFP_KERNEL); - if (!ledctl) { - ret = -ENOMEM; - platform_driver_unregister(&as7716_32x_led_driver); - goto exit; - } - - mutex_init(&ledctl->update_lock); - printk("leds:3\n"); - ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); - if (IS_ERR(ledctl->pdev)) { - printk("leds:fail platform_device_register_simple\n"); - ret = PTR_ERR(ledctl->pdev); - platform_driver_unregister(&as7716_32x_led_driver); - kfree(ledctl); - goto exit; - } - -exit: - return 0; -} - -static void __exit as7716_32x_led_exit(void) -{ - platform_device_unregister(ledctl->pdev); - platform_driver_unregister(&as7716_32x_led_driver); - kfree(ledctl); -} - -module_init(as7716_32x_led_init); -module_exit(as7716_32x_led_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7716_32x_led driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_oom.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_oom.c deleted file mode 100755 index 5e88d9efad5d..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_oom.c +++ /dev/null @@ -1,267 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define STRING_TO_DEC_VALUE 10 -#define EEPROM_DATA_SIZE 512 - - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; -#define MAX_PORT_NAME_LEN 20 -/* Each client has this additional data - */ -struct as7716_32xb_oom_data { - struct device *hwmon_dev; - struct mutex lock; - u8 index; - unsigned char eeprom[EEPROM_DATA_SIZE]; - char port_name[MAX_PORT_NAME_LEN]; - -}; - - - -enum as7716_32xb_oom_sysfs_attributes { - TEMP1_INPUT, - TEMP1_MAX_HYST, - TEMP1_MAX -}; - -/* sysfs attributes for hwmon - */ - -static ssize_t oom_info_store(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t oom_info_show(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_port_name(struct device *dev, - struct device_attribute *dattr, char *buf); -static ssize_t set_port_name(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count); -static SENSOR_DEVICE_ATTR(eeprom, S_IWUSR|S_IRUGO, oom_info_show, oom_info_store, 0); -static SENSOR_DEVICE_ATTR(port_name, S_IRUGO | S_IWUSR, show_port_name, set_port_name, 1); - - -static struct attribute *as7716_32xb_oom_attributes[] = { - &sensor_dev_attr_eeprom.dev_attr.attr, - &sensor_dev_attr_port_name.dev_attr.attr, - NULL -}; - - -static ssize_t oom_info_show(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_oom_data *data = i2c_get_clientdata(client); - int i; - - mutex_lock(&data->lock); - memcpy(buf, data->eeprom, EEPROM_DATA_SIZE); - //for(i=0; i < EEPROM_DATA_SIZE ; i++) - //{ - // buf[i]=data->eeprom[i]; - // printk("buf[%d]=0x%x ",i, buf[i]); - //} - //status = EEPROM_DATA_SIZE+1; - - - memcpy(buf, data->eeprom, 256); - mutex_unlock(&data->lock); - - return 256; -} - -static ssize_t oom_info_store(struct device *dev, struct device_attribute *da, - const char *buf, size_t size) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_oom_data *data = i2c_get_clientdata(client); - int i=0, j=0, k=0; - unsigned char str[3]; - unsigned int val; - - // printk("strlen(buf)=%d\n",strlen(buf)); - k=0; - mutex_lock(&data->lock); - memset(data->eeprom, 0xFF, EEPROM_DATA_SIZE); - memset(str, 0x0, 3); - if(strlen(buf) >= 256 ) - { - for(i=0; i < strlen(buf) ; i++) - { - // printk("i=%d ", i); - for(j=0;j<2; j++) - { - str[j]=buf[i+j]; - } - sscanf(str, "%x", &val); - //printk("str=%s val=0x%x ", str, val); - i=j+i-1; - if(k>=EEPROM_DATA_SIZE) - { - break; - } - data->eeprom[k]=(unsigned char)val; - //printk("data->eeprom[%d]=0x%x\n",k, data->eeprom[k]); - k++; - } - } - //printk("buf=\n"); - //for(i=0; i < strlen(buf) ; i++) - //{ - // printk("%c%c ", buf[i], buf[i+1]); - // if((i % 31)==0) - // printk("\n"); - //} - //printk("\n"); - - - mutex_unlock(&data->lock); - return size; - -} - -static ssize_t show_port_name(struct device *dev, - struct device_attribute *dattr, char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_oom_data *data = i2c_get_clientdata(client); - ssize_t count; - - mutex_lock(&data->lock); - count = sprintf(buf, "%s\n", data->port_name); - mutex_unlock(&data->lock); - - return count; -} - -static ssize_t set_port_name(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_oom_data *data = i2c_get_clientdata(client); - char port_name[MAX_PORT_NAME_LEN]; - - /* no checking, this value is not used except by show_port_name */ - - if (sscanf(buf, "%19s", port_name) != 1) - return -EINVAL; - - mutex_lock(&data->lock); - strcpy(data->port_name, port_name); - mutex_unlock(&data->lock); - - return count; -} - - -static const struct attribute_group as7716_32xb_oom_group = { - .attrs = as7716_32xb_oom_attributes, -}; - -static int as7716_32xb_oom_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7716_32xb_oom_data *data; - int status; - - data = kzalloc(sizeof(struct as7716_32xb_oom_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - i2c_set_clientdata(client, data); - data->index = dev_id->driver_data; - mutex_init(&data->lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7716_32xb_oom_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: oom '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_oom_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7716_32xb_oom_remove(struct i2c_client *client) -{ - struct as7716_32xb_oom_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_oom_group); - kfree(data); - - return 0; -} - - -static const struct i2c_device_id as7716_32xb_oom_id[] = { - { "as7716_32xb_oom", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7716_32xb_oom_id); - -static struct i2c_driver as7716_32xb_oom_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7716_32xb_oom", - }, - .probe = as7716_32xb_oom_probe, - .remove = as7716_32xb_oom_remove, - .id_table = as7716_32xb_oom_id, - .address_list = normal_i2c, -}; - - - - - - -static int __init as7716_32xb_oom_init(void) -{ - return i2c_add_driver(&as7716_32xb_oom_driver); -} - -static void __exit as7716_32xb_oom_exit(void) -{ - i2c_del_driver(&as7716_32xb_oom_driver); -} - -module_init(as7716_32xb_oom_init); -module_exit(as7716_32xb_oom_exit); - -MODULE_AUTHOR("Jostar yang "); -MODULE_DESCRIPTION("as7716_32xb_oom driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_pmbus.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_pmbus.c deleted file mode 100755 index 3f4dba90d1aa..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_pmbus.c +++ /dev/null @@ -1,444 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define STRING_TO_DEC_VALUE 10 - - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as7716_32xb_pmbus_data { - struct device *hwmon_dev; - struct mutex update_lock; - u8 index; - u8 capability; - u16 status_word; - u8 fan_fault; - u8 over_temp; - u16 v_out; - u16 i_out; - u16 p_out; - u16 temp; - u16 fan_speed; - u16 fan_duty_cycle; - u8 fan_dir[4]; - u8 pmbus_revision; - u8 mfr_id[10]; - u8 mfr_model[10]; - u8 mfr_revision[3]; - u16 mfr_vin_min; - u16 mfr_vin_max; - u16 mfr_iin_max; - u16 mfr_iout_max; - u16 mfr_pin_max; - u16 mfr_pout_max; - u16 mfr_vout_min; - u16 mfr_vout_max; - u16 power_on; - u16 temp_fault; - u16 power_good; -}; - - - -enum as7716_32xb_pmbus_sysfs_attributes { - PSU_POWER_ON = 0, - PSU_TEMP_FAULT, - PSU_POWER_GOOD, - PSU_FAN1_FAULT, - PSU_FAN_DIRECTION, - PSU_OVER_TEMP, - PSU_V_OUT, - PSU_I_OUT, - PSU_P_OUT, - PSU_P_OUT_UV, /*In Unit of microVolt, instead of mini.*/ - PSU_TEMP1_INPUT, - PSU_FAN1_SPEED, - PSU_FAN1_DUTY_CYCLE, - PSU_PMBUS_REVISION, - PSU_MFR_ID, - PSU_MFR_MODEL, - PSU_MFR_REVISION, - PSU_MFR_VIN_MIN, - PSU_MFR_VIN_MAX, - PSU_MFR_VOUT_MIN, - PSU_MFR_VOUT_MAX, - PSU_MFR_IIN_MAX, - PSU_MFR_IOUT_MAX, - PSU_MFR_PIN_MAX, - PSU_MFR_POUT_MAX -}; - -/* sysfs attributes for hwmon - */ -static ssize_t pmbus_info_show(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t pmbus_info_store(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static SENSOR_DEVICE_ATTR(psu_power_on, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_POWER_ON); -static SENSOR_DEVICE_ATTR(psu_temp_fault, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_TEMP_FAULT); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_POWER_GOOD); -static SENSOR_DEVICE_ATTR(psu_fan1_fault, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_FAN1_FAULT); -static SENSOR_DEVICE_ATTR(psu_over_temp, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_OVER_TEMP); -static SENSOR_DEVICE_ATTR(psu_v_out, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_V_OUT); -static SENSOR_DEVICE_ATTR(psu_i_out, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_I_OUT); -static SENSOR_DEVICE_ATTR(psu_p_out, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_P_OUT); -static SENSOR_DEVICE_ATTR(psu_temp1_input,S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_TEMP1_INPUT); -static SENSOR_DEVICE_ATTR(psu_fan1_speed_rpm,S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_FAN1_SPEED); -static SENSOR_DEVICE_ATTR(psu_fan1_duty_cycle_percentage, S_IWUSR | S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_FAN1_DUTY_CYCLE); -static SENSOR_DEVICE_ATTR(psu_fan_dir, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_FAN_DIRECTION); -static SENSOR_DEVICE_ATTR(psu_pmbus_revision,S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_PMBUS_REVISION); -static SENSOR_DEVICE_ATTR(psu_mfr_id, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_MFR_ID); -static SENSOR_DEVICE_ATTR(psu_mfr_model, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_MFR_MODEL); -static SENSOR_DEVICE_ATTR(psu_mfr_revision, S_IWUSR| S_IRUGO, pmbus_info_show,pmbus_info_store, PSU_MFR_REVISION); -static SENSOR_DEVICE_ATTR(psu_mfr_vin_min, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_MFR_VIN_MIN); -static SENSOR_DEVICE_ATTR(psu_mfr_vin_max, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_MFR_VIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_vout_min, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_MFR_VOUT_MIN); -static SENSOR_DEVICE_ATTR(psu_mfr_vout_max, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_MFR_VOUT_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_iin_max, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_MFR_IIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_iout_max, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_MFR_IOUT_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_pin_max, S_IWUSR|S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_MFR_PIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_pout_max, S_IWUSR| S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_MFR_POUT_MAX); - -/*Duplicate nodes for lm-sensors.*/ -static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_P_OUT_UV); -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_TEMP1_INPUT); -static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_FAN1_SPEED); -static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, pmbus_info_show, pmbus_info_store, PSU_TEMP_FAULT); - - -static struct attribute *as7716_32xb_pmbus_attributes[] = { - &sensor_dev_attr_psu_power_on.dev_attr.attr, - &sensor_dev_attr_psu_temp_fault.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - &sensor_dev_attr_psu_fan1_fault.dev_attr.attr, - &sensor_dev_attr_psu_over_temp.dev_attr.attr, - &sensor_dev_attr_psu_v_out.dev_attr.attr, - &sensor_dev_attr_psu_i_out.dev_attr.attr, - &sensor_dev_attr_psu_p_out.dev_attr.attr, - &sensor_dev_attr_psu_temp1_input.dev_attr.attr, - &sensor_dev_attr_psu_fan1_speed_rpm.dev_attr.attr, - &sensor_dev_attr_psu_fan1_duty_cycle_percentage.dev_attr.attr, - &sensor_dev_attr_psu_fan_dir.dev_attr.attr, - &sensor_dev_attr_psu_pmbus_revision.dev_attr.attr, - &sensor_dev_attr_psu_mfr_id.dev_attr.attr, - &sensor_dev_attr_psu_mfr_model.dev_attr.attr, - &sensor_dev_attr_psu_mfr_revision.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vin_min.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_pout_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_iin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_pin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vout_min.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vout_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_iout_max.dev_attr.attr, - /*Duplicate nodes for lm-sensors.*/ - &sensor_dev_attr_power1_input.dev_attr.attr, - &sensor_dev_attr_temp1_input.dev_attr.attr, - &sensor_dev_attr_fan1_input.dev_attr.attr, - &sensor_dev_attr_temp1_fault.dev_attr.attr, - NULL -}; - - -static ssize_t pmbus_info_show(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 as7716_32xb_pmbus_data *data = i2c_get_clientdata(client); - int status = -EINVAL; - //printk("pmbus_info_show\n"); - printk("attr->index=%d\n", attr->index); - mutex_lock(&data->update_lock); - switch (attr->index) - { - case PSU_POWER_ON: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->power_on); - break; - case PSU_TEMP_FAULT: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->temp_fault); - break; - case PSU_POWER_GOOD: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->power_good); - break; - case PSU_FAN1_FAULT: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->fan_fault); - break; - case PSU_FAN_DIRECTION: - status=snprintf(buf, PAGE_SIZE-1, "%s\r\n", data->fan_dir); - break; - case PSU_OVER_TEMP: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->over_temp); - break; - case PSU_V_OUT: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->v_out); - break; - case PSU_I_OUT: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->i_out); - break; - case PSU_P_OUT: - printk("read PSU_P_OUT\n"); - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->p_out); - break; - case PSU_P_OUT_UV: - printk("read PSU_P_OUT_UV\n"); - status=snprintf(buf, PAGE_SIZE-1, "%ld\r\n", data->p_out * 1000000); - break; - case PSU_TEMP1_INPUT: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->temp); - break; - case PSU_FAN1_SPEED: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->fan_speed); - break; - case PSU_FAN1_DUTY_CYCLE: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->fan_duty_cycle); - break; - case PSU_PMBUS_REVISION: - break; - case PSU_MFR_ID: - status=snprintf(buf, PAGE_SIZE-1, "%s\r\n", data->mfr_id); - break; - case PSU_MFR_MODEL: - status=snprintf(buf, PAGE_SIZE-1, "%s\r\n", data->mfr_model); - break; - case PSU_MFR_REVISION: - status=snprintf(buf, PAGE_SIZE-1, "%s\r\n", data->mfr_revision); - break; - case PSU_MFR_VIN_MIN: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->mfr_vin_min); - break; - case PSU_MFR_VIN_MAX: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->mfr_vin_max); - break; - case PSU_MFR_VOUT_MIN: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->mfr_vin_max); - break; - case PSU_MFR_VOUT_MAX: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->mfr_vout_max); - break; - case PSU_MFR_IIN_MAX: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->mfr_iin_max); - break; - case PSU_MFR_IOUT_MAX: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->mfr_iout_max); - break; - case PSU_MFR_PIN_MAX: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->mfr_pin_max); - break; - case PSU_MFR_POUT_MAX: - status=snprintf(buf, PAGE_SIZE-1, "%d\r\n", data->mfr_pout_max); - break; - default : - break; - } - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t pmbus_info_store(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 as7716_32xb_pmbus_data *data = i2c_get_clientdata(client); - long keyin = 0; - int status = -EINVAL; - //printk("pmbus_info_store\n"); - //printk("attr->index=%d\n", attr->index); - mutex_lock(&data->update_lock); - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - switch (attr->index) - { - case PSU_POWER_ON: - data->power_on=keyin; - break; - case PSU_TEMP_FAULT: - data->temp_fault=keyin; - break; - case PSU_POWER_GOOD: - data->power_good=keyin; - break; - case PSU_FAN1_FAULT: - break; - case PSU_FAN_DIRECTION: - memcpy(data->fan_dir, buf, sizeof(data->fan_dir)); - break; - case PSU_OVER_TEMP: - data->over_temp=keyin; - break; - case PSU_V_OUT: - data->v_out=keyin; - break; - case PSU_I_OUT: - data->i_out=keyin; - break; - case PSU_P_OUT: - printk("data->p_out=%d\n", data->p_out); - data->p_out=keyin; - break; - case PSU_P_OUT_UV: - //multiplier = 1000000; /*For lm-sensors, unit is micro-Volt.*/ - - break; - case PSU_TEMP1_INPUT: - data->temp=keyin; - break; - case PSU_FAN1_SPEED: - data->fan_speed=keyin; - break; - case PSU_FAN1_DUTY_CYCLE: - break; - case PSU_PMBUS_REVISION: - data->pmbus_revision=keyin; - break; - case PSU_MFR_ID: - memcpy(data->mfr_id, buf, sizeof(data->mfr_id)); - break; - case PSU_MFR_MODEL: - memcpy(data->mfr_model, buf, sizeof(data->mfr_model)); - break; - case PSU_MFR_REVISION: - memcpy(data->mfr_revision, buf, sizeof(data->mfr_revision)); - break; - case PSU_MFR_VIN_MIN: - data->mfr_vin_min=keyin; - break; - case PSU_MFR_VIN_MAX: - data->mfr_vin_max=keyin; - break; - case PSU_MFR_VOUT_MIN: - data->mfr_vout_min=keyin; - break; - case PSU_MFR_VOUT_MAX: - data->mfr_vout_max=keyin; - break; - case PSU_MFR_IIN_MAX: - data->mfr_iin_max=keyin; - break; - case PSU_MFR_IOUT_MAX: - data->mfr_iout_max=keyin; - break; - case PSU_MFR_PIN_MAX: - data->mfr_pin_max=keyin; - break; - case PSU_MFR_POUT_MAX: - data->mfr_pout_max=keyin; - break; - default : - break; - } - mutex_unlock(&data->update_lock); - return count; -} - - -static const struct attribute_group as7716_32xb_pmbus_group = { - .attrs = as7716_32xb_pmbus_attributes, -}; - -static int as7716_32xb_pmbus_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7716_32xb_pmbus_data *data; - int status; - - data = kzalloc(sizeof(struct as7716_32xb_pmbus_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - i2c_set_clientdata(client, data); - data->index = dev_id->driver_data; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7716_32xb_pmbus_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: pmbus '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_pmbus_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7716_32xb_pmbus_remove(struct i2c_client *client) -{ - struct as7716_32xb_pmbus_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_pmbus_group); - kfree(data); - - return 0; -} - - -static const struct i2c_device_id as7716_32xb_pmbus_id[] = { - { "as7716_32xb_pmbus", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7716_32xb_pmbus_id); - -static struct i2c_driver as7716_32xb_pmbus_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7716_32xb_pmbus", - }, - .probe = as7716_32xb_pmbus_probe, - .remove = as7716_32xb_pmbus_remove, - .id_table = as7716_32xb_pmbus_id, - .address_list = normal_i2c, -}; - - - - - - -static int __init as7716_32xb_pmbus_init(void) -{ - return i2c_add_driver(&as7716_32xb_pmbus_driver); -} - -static void __exit as7716_32xb_pmbus_exit(void) -{ - i2c_del_driver(&as7716_32xb_pmbus_driver); -} - -module_init(as7716_32xb_pmbus_init); -module_exit(as7716_32xb_pmbus_exit); - -MODULE_AUTHOR("Jostar yang "); -MODULE_DESCRIPTION("as7716_32xb_pmbus driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_psu.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_psu.c deleted file mode 100755 index 01756e8596eb..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_psu.c +++ /dev/null @@ -1,355 +0,0 @@ -/* - * An hwmon driver for accton as7716_32xbb Power Module - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_MODEL_NAME 16 -#define DC12V_FAN_DIR_OFFSET 0x34 -#define DC12V_FAN_DIR_LEN 3 -#define STRING_TO_DEC_VALUE 10 - -//static ssize_t show_string(struct device *dev, struct device_attribute *da, char *buf); -static int as7716_32xb_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int as7716_32xb_cpld_read (unsigned short cpld_addr, u8 reg); - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as7716_32xb_psu_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 index; /* PSU index */ - u8 status; /* Status(present/power_good) register read from CPLD */ - u8 present; - u8 power_good; - char model_name[MAX_MODEL_NAME+1]; /* Model name, read from eeprom */ - char fan_dir[DC12V_FAN_DIR_LEN+1]; /* DC12V fan direction */ -}; - -enum as7716_32xb_psu_sysfs_attributes { - PSU_PRESENT, - PSU_MODEL_NAME, - PSU_POWER_GOOD, - PSU_FAN_DIR /* For DC12V only */ -}; - -/* sysfs attributes for hwmon - */ -static ssize_t psu_info_store(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t psu_info_show(struct device *dev, struct device_attribute *da, - char *buf); -static SENSOR_DEVICE_ATTR(psu_present, S_IWUSR|S_IRUGO, psu_info_show, psu_info_store, PSU_PRESENT); -static SENSOR_DEVICE_ATTR(psu_model_name, S_IWUSR|S_IRUGO, psu_info_show, psu_info_store, PSU_MODEL_NAME); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IWUSR|S_IRUGO, psu_info_show, psu_info_store, PSU_POWER_GOOD); -static SENSOR_DEVICE_ATTR(psu_fan_dir, S_IWUSR|S_IRUGO, psu_info_show, psu_info_store, PSU_FAN_DIR); - - -static struct attribute *as7716_32xb_psu_attributes[] = { - &sensor_dev_attr_psu_present.dev_attr.attr, - &sensor_dev_attr_psu_model_name.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - &sensor_dev_attr_psu_fan_dir.dev_attr.attr, - NULL -}; - -static ssize_t psu_info_show(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 as7716_32xb_psu_data *data = i2c_get_clientdata(client); - int status = -EINVAL; - //printk("psu_info_show\n"); - // printk("attr->index=%d\n", attr->index); - mutex_lock(&data->update_lock); - switch (attr->index) - { - case PSU_PRESENT: - //printk("data->present=%d\n",data->present); - status = snprintf(buf, PAGE_SIZE - 1, "%d\r\n", data->present); - break; - case PSU_MODEL_NAME: - //printk("data->model_name=%s\n",data->model_name); - status = snprintf(buf, PAGE_SIZE - 1, "%s\r\n", data->model_name); - break; - case PSU_POWER_GOOD: - // printk("data->present=%d\n",data->power_good); - status = snprintf(buf, PAGE_SIZE - 1, "%d\r\n", data->power_good); - break; - case PSU_FAN_DIR: - //printk("data->fan_dir=%s\n",data->fan_dir); - status = snprintf(buf, PAGE_SIZE - 1, "%s\r\n", data->fan_dir); - break; - default : - break; - } - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t psu_info_store(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 as7716_32xb_psu_data *data = i2c_get_clientdata(client); - long keyin = 0; - int status = -EINVAL; - //printk("psu_info_store\n"); - //printk("attr->index=%d\n", attr->index); - mutex_lock(&data->update_lock); - switch (attr->index) - { - case PSU_PRESENT: - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - if (status) - goto fail_exit; - if (keyin > 1 || keyin < 0) - goto fail_exit; - data->present=keyin; - break; - case PSU_MODEL_NAME: - memcpy(data->model_name, buf, MAX_MODEL_NAME); - break; - case PSU_POWER_GOOD: - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - if (status) - goto fail_exit; - if (keyin > 1 || keyin < 0) - goto fail_exit; - data->power_good=keyin; - break; - case PSU_FAN_DIR: - memcpy(data->fan_dir, buf, DC12V_FAN_DIR_LEN); - break; - default : - goto fail_exit; - } - mutex_unlock(&data->update_lock); - return count; - -fail_exit: - mutex_unlock(&data->update_lock); - return -EINVAL; -} - -static const struct attribute_group as7716_32xb_psu_group = { - .attrs = as7716_32xb_psu_attributes, -}; - -static int as7716_32xb_psu_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7716_32xb_psu_data *data; - int status; - - data = kzalloc(sizeof(struct as7716_32xb_psu_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - data->index = dev_id->driver_data; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7716_32xb_psu_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_psu_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7716_32xb_psu_remove(struct i2c_client *client) -{ - struct as7716_32xb_psu_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_psu_group); - kfree(data); - - return 0; -} - -enum psu_index -{ - as7716_32xb_psu1, - as7716_32xb_psu2 -}; - -static const struct i2c_device_id as7716_32xb_psu_id[] = { - { "as7716_32xb_psu1", as7716_32xb_psu1 }, - { "as7716_32xb_psu2", as7716_32xb_psu2 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7716_32xb_psu_id); - -static struct i2c_driver as7716_32xb_psu_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7716_32xb_psu", - }, - .probe = as7716_32xb_psu_probe, - .remove = as7716_32xb_psu_remove, - .id_table = as7716_32xb_psu_id, - .address_list = normal_i2c, -}; - -static int as7716_32xb_psu_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = 0; - int retry_count = 5; - - while (retry_count) { - retry_count--; - - result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) { - msleep(10); - continue; - } - - if (unlikely(result != data_len)) { - result = -EIO; - msleep(10); - continue; - } - - result = 0; - break; - } - - return result; -} - -enum psu_type { - PSU_TYPE_AC_110V, - PSU_TYPE_DC_48V, - PSU_TYPE_DC_12V -}; - -struct model_name_info { - enum psu_type type; - u8 offset; - u8 length; - char* model_name; -}; - -struct model_name_info models[] = { -{PSU_TYPE_AC_110V, 0x20, 8, "YM-2651Y"}, -{PSU_TYPE_DC_48V, 0x20, 8, "YM-2651V"}, -{PSU_TYPE_DC_12V, 0x00, 11, "PSU-12V-750"}, -}; - -static int as7716_32xb_psu_model_name_get(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_psu_data *data = i2c_get_clientdata(client); - int i, status; - - for (i = 0; i < ARRAY_SIZE(models); i++) { - memset(data->model_name, 0, sizeof(data->model_name)); - - status = as7716_32xb_psu_read_block(client, models[i].offset, - data->model_name, models[i].length); - if (status < 0) { - data->model_name[0] = '\0'; - dev_dbg(&client->dev, "unable to read model name from (0x%x) offset(0x%x)\n", - client->addr, models[i].offset); - return status; - } - else { - data->model_name[models[i].length] = '\0'; - } - - /* Determine if the model name is known, if not, read next index - */ - if (strncmp(data->model_name, models[i].model_name, models[i].length) == 0) { - return 0; - } - else { - data->model_name[0] = '\0'; - } - } - - return -ENODATA; -} - -static int __init as7716_32xb_psu_init(void) -{ - return i2c_add_driver(&as7716_32xb_psu_driver); -} - -static void __exit as7716_32xb_psu_exit(void) -{ - i2c_del_driver(&as7716_32xb_psu_driver); -} - -module_init(as7716_32xb_psu_init); -module_exit(as7716_32xb_psu_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7716_32xb_psu driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_sfp.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_sfp.c deleted file mode 100755 index 9c7a05632154..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_sfp.c +++ /dev/null @@ -1,365 +0,0 @@ -/* - * An hwmon driver for accton as7716_32x sfp - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BIT_INDEX(i) (1UL << (i)) -#define I2C_ADDR_CPLD1 0x60 -#define I2C_ADDR_CPLD2 0x62 -#define I2C_ADDR_CPLD3 0x64 -#define CPLD1_OFFSET_QSFP_PRESET1 0x30 -#define CPLD1_OFFSET_QSFP_PRESET2 0x31 -#define CPLD1_OFFSET_QSFP_PRESET3 0x32 -#define CPLD1_OFFSET_QSFP_PRESET4 0x33 - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x50, I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as7716_32x_sfp_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - int port; /* Front port index */ - char eeprom[256]; /* eeprom data */ - u32 is_present; /* present status */ -}; - -static struct as7716_32x_sfp_data *as7716_32x_sfp_update_device(struct device *dev); -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_present(struct device *dev, struct device_attribute *da,char *buf); -static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, char *buf); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -enum as7716_32x_sfp_sysfs_attributes { - SFP_PORT_NUMBER, - SFP_IS_PRESENT, - SFP_IS_PRESENT_ALL, - SFP_EEPROM -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, SFP_PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, SFP_IS_PRESENT); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, SFP_IS_PRESENT_ALL); -static SENSOR_DEVICE_ATTR(sfp_eeprom, S_IRUGO, show_eeprom, NULL, SFP_EEPROM); - -static struct attribute *as7716_32x_sfp_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_eeprom.dev_attr.attr, - NULL -}; - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32x_sfp_data *data = i2c_get_clientdata(client); - - return sprintf(buf, "%d\n", data->port+1); -} - -/* Error-check the CPLD read results. */ -#define VALIDATED_READ(_buf, _rv, _read_expr, _invert) \ -do { \ - _rv = (_read_expr); \ - if(_rv < 0) { \ - return sprintf(_buf, "READ ERROR\n"); \ - } \ - if(_invert) { \ - _rv = ~_rv; \ - } \ - _rv &= 0xFF; \ -} while(0) - -static ssize_t show_present(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - - if(attr->index == SFP_IS_PRESENT_ALL) { - int values[4]; - /* - * Report the SFP_PRESENCE status for all ports. - */ - - /* QSFP_PRESENT Ports 1-8 */ - //VALIDATED_READ(buf, values[0], accton_i2c_cpld_read(0x62, 0x9), 1); - VALIDATED_READ(buf, values[0], accton_i2c_cpld_read(I2C_ADDR_CPLD1, CPLD1_OFFSET_QSFP_PRESET1), 1); - /* QSFP_PRESENT Ports 9-16 */ - VALIDATED_READ(buf, values[1], accton_i2c_cpld_read(I2C_ADDR_CPLD1, CPLD1_OFFSET_QSFP_PRESET2), 1); - /* QSFP_PRESENT Ports 17-24 */ - VALIDATED_READ(buf, values[2], accton_i2c_cpld_read(I2C_ADDR_CPLD1, CPLD1_OFFSET_QSFP_PRESET3), 1); - /* QSFP_PRESENT Ports 25-32 */ - VALIDATED_READ(buf, values[3], accton_i2c_cpld_read(I2C_ADDR_CPLD1, CPLD1_OFFSET_QSFP_PRESET4), 1); - - /* Return values 1 -> 32 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], values[3]); - } - else { /* SFP_IS_PRESENT */ - struct as7716_32x_sfp_data *data = as7716_32x_sfp_update_device(dev); - - if (!data->valid) { - printk("return -EIO\n"); - return -EIO; - } - - return sprintf(buf, "%d\n", data->is_present); - } -} - -static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as7716_32x_sfp_data *data = as7716_32x_sfp_update_device(dev); - - if (!data->valid) { - return 0; - } - - if (!data->is_present) { - return 0; - } - - memcpy(buf, data->eeprom, sizeof(data->eeprom)); - - return sizeof(data->eeprom); -} - -static const struct attribute_group as7716_32x_sfp_group = { - .attrs = as7716_32x_sfp_attributes, -}; - -static int as7716_32x_sfp_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7716_32x_sfp_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7716_32x_sfp_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - i2c_set_clientdata(client, data); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7716_32x_sfp_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: sfp '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7716_32x_sfp_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7716_32x_sfp_remove(struct i2c_client *client) -{ - struct as7716_32x_sfp_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7716_32x_sfp_group); - kfree(data); - - return 0; -} - -enum port_numbers { -as7716_32x_sfp1, as7716_32x_sfp2, as7716_32x_sfp3, as7716_32x_sfp4, -as7716_32x_sfp5, as7716_32x_sfp6, as7716_32x_sfp7, as7716_32x_sfp8, -as7716_32x_sfp9, as7716_32x_sfp10,as7716_32x_sfp11,as7716_32x_sfp12, -as7716_32x_sfp13,as7716_32x_sfp14,as7716_32x_sfp15,as7716_32x_sfp16, -as7716_32x_sfp17,as7716_32x_sfp18,as7716_32x_sfp19,as7716_32x_sfp20, -as7716_32x_sfp21,as7716_32x_sfp22,as7716_32x_sfp23,as7716_32x_sfp24, -as7716_32x_sfp25,as7716_32x_sfp26,as7716_32x_sfp27,as7716_32x_sfp28, -as7716_32x_sfp29,as7716_32x_sfp30,as7716_32x_sfp31,as7716_32x_sfp32 -}; - -static const struct i2c_device_id as7716_32x_sfp_id[] = { -{ "as7716_32x_sfp1", as7716_32x_sfp1 }, { "as7716_32x_sfp2", as7716_32x_sfp2 }, -{ "as7716_32x_sfp3", as7716_32x_sfp3 }, { "as7716_32x_sfp4", as7716_32x_sfp4 }, -{ "as7716_32x_sfp5", as7716_32x_sfp5 }, { "as7716_32x_sfp6", as7716_32x_sfp6 }, -{ "as7716_32x_sfp7", as7716_32x_sfp7 }, { "as7716_32x_sfp8", as7716_32x_sfp8 }, -{ "as7716_32x_sfp9", as7716_32x_sfp9 }, { "as7716_32x_sfp10", as7716_32x_sfp10 }, -{ "as7716_32x_sfp11", as7716_32x_sfp11 }, { "as7716_32x_sfp12", as7716_32x_sfp12 }, -{ "as7716_32x_sfp13", as7716_32x_sfp13 }, { "as7716_32x_sfp14", as7716_32x_sfp14 }, -{ "as7716_32x_sfp15", as7716_32x_sfp15 }, { "as7716_32x_sfp16", as7716_32x_sfp16 }, -{ "as7716_32x_sfp17", as7716_32x_sfp17 }, { "as7716_32x_sfp18", as7716_32x_sfp18 }, -{ "as7716_32x_sfp19", as7716_32x_sfp19 }, { "as7716_32x_sfp20", as7716_32x_sfp20 }, -{ "as7716_32x_sfp21", as7716_32x_sfp21 }, { "as7716_32x_sfp22", as7716_32x_sfp22 }, -{ "as7716_32x_sfp23", as7716_32x_sfp23 }, { "as7716_32x_sfp24", as7716_32x_sfp24 }, -{ "as7716_32x_sfp25", as7716_32x_sfp25 }, { "as7716_32x_sfp26", as7716_32x_sfp26 }, -{ "as7716_32x_sfp27", as7716_32x_sfp27 }, { "as7716_32x_sfp28", as7716_32x_sfp28 }, -{ "as7716_32x_sfp29", as7716_32x_sfp29 }, { "as7716_32x_sfp30", as7716_32x_sfp30 }, -{ "as7716_32x_sfp31", as7716_32x_sfp31 }, { "as7716_32x_sfp32", as7716_32x_sfp32 }, -{} -}; -MODULE_DEVICE_TABLE(i2c, as7716_32x_sfp_id); - -static struct i2c_driver as7716_32x_sfp_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7716_32x_sfp", - }, - .probe = as7716_32x_sfp_probe, - .remove = as7716_32x_sfp_remove, - .id_table = as7716_32x_sfp_id, - .address_list = normal_i2c, -}; - -static int as7716_32x_sfp_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) - goto abort; - if (unlikely(result != data_len)) { - result = -EIO; - goto abort; - } - - result = 0; - -abort: - return result; -} - -static struct as7716_32x_sfp_data *as7716_32x_sfp_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32x_sfp_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int status = -1; - int i = 0; - u8 cpld_reg = 0x30 + (data->port/8); - - data->valid = 0; - - /* Read present status of the specified port number */ - data->is_present = 0; - status = accton_i2c_cpld_read(I2C_ADDR_CPLD1, cpld_reg); - - if (status < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", I2C_ADDR_CPLD1, cpld_reg, status); - goto exit; - } - - data->is_present = (status & (1 << (data->port % 8))) ? 0 : 1; - printk("data->is_present=%d, data->port=%d, status=0x%x\n",data->is_present, data->port, status); - /* Read eeprom data based on port number */ - memset(data->eeprom, 0, sizeof(data->eeprom)); - - /* Check if the port is present */ - if (data->is_present) { - /* read eeprom */ - for (i = 0; i < sizeof(data->eeprom)/I2C_SMBUS_BLOCK_MAX; i++) { - status = as7716_32x_sfp_read_block(client, i*I2C_SMBUS_BLOCK_MAX, - data->eeprom+(i*I2C_SMBUS_BLOCK_MAX), - I2C_SMBUS_BLOCK_MAX); - if (status < 0) { - printk("unable to read eeprom from port(%d)\n", data->port); - dev_dbg(&client->dev, "unable to read eeprom from port(%d)\n", data->port); - goto exit; - } - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init as7716_32x_sfp_init(void) -{ - //extern int platform_accton_as7716_32x(void); - //if (!platform_accton_as7716_32x()) { -// return -ENODEV; - //} - - return i2c_add_driver(&as7716_32x_sfp_driver); -} - -static void __exit as7716_32x_sfp_exit(void) -{ - i2c_del_driver(&as7716_32x_sfp_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as7716_32x_sfp driver"); -MODULE_LICENSE("GPL"); - -module_init(as7716_32x_sfp_init); -module_exit(as7716_32x_sfp_exit); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_sys.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_sys.c deleted file mode 100755 index f0a8125139cc..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_sys.c +++ /dev/null @@ -1,243 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define STRING_TO_DEC_VALUE 10 -#define EEPROM_DATA_SIZE 256 - - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; -#define MAX_PORT_NAME_LEN 20 -/* Each client has this additional data - */ -struct as7716_32xb_sys_data { - struct device *hwmon_dev; - struct mutex lock; - u8 index; - unsigned char eeprom[EEPROM_DATA_SIZE]; -}; - - -/* sysfs attributes for hwmon - */ - -static ssize_t sys_info_store(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t sys_info_show(struct device *dev, struct device_attribute *da, - char *buf); - -static SENSOR_DEVICE_ATTR(eeprom, S_IWUSR|S_IRUGO, sys_info_show, sys_info_store, 0); - - - -static struct attribute *as7716_32xb_sys_attributes[] = { - &sensor_dev_attr_eeprom.dev_attr.attr, - NULL -}; - - -static ssize_t sys_info_show(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 as7716_32xb_sys_data *data = i2c_get_clientdata(client); -// int status = -EINVAL; - int i; - - //printk("sys_info_show\n"); - // printk("attr->index=%d\n", attr->index); - mutex_lock(&data->lock); - //for(i=0; i<8; i++) - // printk("data->eeprom[%d]=0x%x ",i, data->eeprom[i]); - //printk("\n"); - memcpy(buf, data->eeprom, EEPROM_DATA_SIZE); - //for(i=0; i < EEPROM_DATA_SIZE ; i++) - //{ - // buf[i]=data->eeprom[i]; - // printk("buf[%d]=0x%x ",i, buf[i]); - //} - //status = EEPROM_DATA_SIZE+1; - - //printk("\n"); - //status = sprintf(buf, "%x", 0xA); - //data->eeprom[0]=0x0d; - //data->eeprom[1]=0x0; - //data->eeprom[2]=0x06; - // buf[3]=0xFF; - - // for(i=0; i< 16; i++) - // printk("buf[%d]=0x%x ",i, buf[i]); - //printk("\n"); - - memcpy(buf, data->eeprom, 256); - - - mutex_unlock(&data->lock); - - return 256; -} - -static ssize_t sys_info_store(struct device *dev, struct device_attribute *da, - const char *buf, size_t size) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_sys_data *data = i2c_get_clientdata(client); - int i=0, j=0, k=0; - unsigned char str[3]; - unsigned int val; - - //printk("sys_info_store\n"); - //printk("attr->index=%d\n", attr->index); - //printk("buf[0]=0x%x, buf[1]=0x%x, buf[2]=0x%x, buf[3]=0x%x\n", buf[0], buf[1], buf[2], buf[3]); - - // printk("strlen(buf)=%d\n",strlen(buf)); - k=0; - mutex_lock(&data->lock); - memset(data->eeprom, 0xFF, EEPROM_DATA_SIZE); - memset(str, 0x0, 3); - if(strlen(buf) >= 256 ) - { - for(i=0; i < strlen(buf) ; i++) - { - // printk("i=%d ", i); - for(j=0;j<2; j++) - { - str[j]=buf[i+j]; - } - sscanf(str, "%x", &val); - // printk("str=%s val=0x%x ", str, val); - i=j+i-1; - if(k>=EEPROM_DATA_SIZE) - { - break; - } - data->eeprom[k]=(unsigned char)val; - // printk("data->eeprom[%d]=0x%x\n",k, data->eeprom[k]); - k++; - } - } - //printk("buf=\n"); - //for(i=0; i < strlen(buf) ; i++) - //{ - // printk("%c%c ", buf[i], buf[i+1]); - // if((i % 31)==0) - // printk("\n"); - //} - //printk("\n"); - - //printk("eeprom[0]=0x%x, eeprom[1]=0x%x, eeprom[2]=0x%x, eeprom[3]=0x%x\n", - // data->eeprom[0], data->eeprom[1], data->eeprom[2], data->eeprom[3]); - - mutex_unlock(&data->lock); - return size; - -} - -static const struct attribute_group as7716_32xb_sys_group = { - .attrs = as7716_32xb_sys_attributes, -}; - -static int as7716_32xb_sys_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7716_32xb_sys_data *data; - int status; - - data = kzalloc(sizeof(struct as7716_32xb_sys_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - i2c_set_clientdata(client, data); - data->index = dev_id->driver_data; - mutex_init(&data->lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7716_32xb_sys_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: sys '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_sys_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7716_32xb_sys_remove(struct i2c_client *client) -{ - struct as7716_32xb_sys_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_sys_group); - kfree(data); - - return 0; -} - - -static const struct i2c_device_id as7716_32xb_sys_id[] = { - { "as7716_32xb_sys", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7716_32xb_sys_id); - -static struct i2c_driver as7716_32xb_sys_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7716_32xb_sys", - }, - .probe = as7716_32xb_sys_probe, - .remove = as7716_32xb_sys_remove, - .id_table = as7716_32xb_sys_id, - .address_list = normal_i2c, -}; - - - - - - -static int __init as7716_32xb_sys_init(void) -{ - return i2c_add_driver(&as7716_32xb_sys_driver); -} - -static void __exit as7716_32xb_sys_exit(void) -{ - i2c_del_driver(&as7716_32xb_sys_driver); -} - -module_init(as7716_32xb_sys_init); -module_exit(as7716_32xb_sys_exit); - -MODULE_AUTHOR("Jostar yang "); -MODULE_DESCRIPTION("as7716_32xb_sys driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_thermal.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_thermal.c deleted file mode 100755 index d42341bb181a..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_as7716_32xb_thermal.c +++ /dev/null @@ -1,214 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define STRING_TO_DEC_VALUE 10 -#define STRING_TO_HEX_VALUE 16 - -#define TEMP1_MAX_HYST_DEFAULT 75000 -#define TEMP1_MAX_DEFAULT 80000 -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as7716_32xb_thermal_data { - struct device *hwmon_dev; - struct mutex update_lock; - u8 index; - unsigned int temp1_input; - unsigned int temp1_max_hyst; - unsigned int temp1_max; -}; - - - -enum as7716_32xb_thermal_sysfs_attributes { - TEMP1_INPUT, - TEMP1_MAX_HYST, - TEMP1_MAX -}; - -/* sysfs attributes for hwmon - */ - -static ssize_t temp_info_store(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t temp_info_show(struct device *dev, struct device_attribute *da, - char *buf); -static SENSOR_DEVICE_ATTR(temp1_input, S_IWUSR|S_IRUGO, temp_info_show, temp_info_store, TEMP1_INPUT); -static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR|S_IRUGO, temp_info_show, temp_info_store, TEMP1_MAX_HYST); -static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR|S_IRUGO, temp_info_show, temp_info_store, TEMP1_MAX); - - -static struct attribute *as7716_32xb_thermal_attributes[] = { - &sensor_dev_attr_temp1_input.dev_attr.attr, - &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, - &sensor_dev_attr_temp1_max.dev_attr.attr, - NULL -}; - - -static ssize_t temp_info_show(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 as7716_32xb_thermal_data *data = i2c_get_clientdata(client); - int status = -EINVAL; - - mutex_lock(&data->update_lock); - switch (attr->index) - { - case TEMP1_INPUT: - status = snprintf(buf, PAGE_SIZE - 1, "%d\r\n", data->temp1_input); - break; - case TEMP1_MAX_HYST: - status = snprintf(buf, PAGE_SIZE - 1, "%d\r\n", TEMP1_MAX_HYST_DEFAULT); - break; - case TEMP1_MAX: - status = snprintf(buf, PAGE_SIZE - 1, "%d\r\n", TEMP1_MAX_DEFAULT); - break; - default : - break; - } - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t temp_info_store(struct device *dev, struct device_attribute *da, - const char *buf, size_t size) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct as7716_32xb_thermal_data *data = i2c_get_clientdata(client); - long keyin = 0; - int status = -EINVAL; - - mutex_lock(&data->update_lock); - status = kstrtol(buf, STRING_TO_DEC_VALUE, &keyin); - switch (attr->index) - { - case TEMP1_INPUT: - data->temp1_input=keyin; - break; - case TEMP1_MAX_HYST: - data->temp1_max_hyst=keyin; - break; - case TEMP1_MAX: - data->temp1_max=keyin; - break; - default : - break; - } - mutex_unlock(&data->update_lock); - return size; - -} - -static const struct attribute_group as7716_32xb_thermal_group = { - .attrs = as7716_32xb_thermal_attributes, -}; - -static int as7716_32xb_thermal_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7716_32xb_thermal_data *data; - int status; - - data = kzalloc(sizeof(struct as7716_32xb_thermal_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - i2c_set_clientdata(client, data); - data->index = dev_id->driver_data; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7716_32xb_thermal_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: thermal '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_thermal_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7716_32xb_thermal_remove(struct i2c_client *client) -{ - struct as7716_32xb_thermal_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7716_32xb_thermal_group); - kfree(data); - - return 0; -} - - -static const struct i2c_device_id as7716_32xb_thermal_id[] = { - { "as7716_32xb_thermal", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7716_32xb_thermal_id); - -static struct i2c_driver as7716_32xb_thermal_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7716_32xb_thermal", - }, - .probe = as7716_32xb_thermal_probe, - .remove = as7716_32xb_thermal_remove, - .id_table = as7716_32xb_thermal_id, - .address_list = normal_i2c, -}; - - - - - - -static int __init as7716_32xb_thermal_init(void) -{ - return i2c_add_driver(&as7716_32xb_thermal_driver); -} - -static void __exit as7716_32xb_thermal_exit(void) -{ - i2c_del_driver(&as7716_32xb_thermal_driver); -} - -module_init(as7716_32xb_thermal_init); -module_exit(as7716_32xb_thermal_exit); - -MODULE_AUTHOR("Jostar yang "); -MODULE_DESCRIPTION("as7716_32xb_thermal driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_i2c_cpld.c b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_i2c_cpld.c deleted file mode 100755 index 46d1e2773287..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/modules/accton_i2c_cpld.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - * A hwmon driver for the accton_i2c_cpld - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define CPLD_VERSION_REG 0x1 - -enum as5712_54x_cpld_sysfs_attributes { - CPLD_READ_VERSION, - CPLD_BYTE_ACCESS, - CPLD_DUMP_ALL, -}; - -static ssize_t read_cpld_version(struct device *dev, struct device_attribute *da, - char *buf); -int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); - - -static LIST_HEAD(cpld_client_list); -static struct mutex list_lock; - -struct cpld_client_node { - struct i2c_client *client; - struct list_head list; -}; - -/* Addresses scanned for accton_i2c_cpld - */ -static const unsigned short normal_i2c[] = { 0x31, 0x35, 0x60, 0x61, 0x62, I2C_CLIENT_END }; - -static SENSOR_DEVICE_ATTR(cpld_get_version, S_IRUGO, read_cpld_version, NULL, CPLD_READ_VERSION); - -static struct attribute *as5712_54x_cpld_attributes[] = { - &sensor_dev_attr_cpld_get_version.dev_attr.attr, - NULL -}; - -static const struct attribute_group as5712_54x_cpld_group = { - .attrs = as5712_54x_cpld_attributes, -}; - -static ssize_t read_cpld_version(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); - unsigned short cpld_reg = CPLD_VERSION_REG; - u8 reg; - - if(attr->index == CPLD_READ_VERSION) { - reg = accton_i2c_cpld_read(client->addr, cpld_reg); - return sprintf(buf, "%02x\n",reg); - } - return -1 ; -} - - -static void accton_i2c_cpld_add_client(struct i2c_client *client) -{ - struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); - - if (!node) { - dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); - return; - } - - node->client = client; - - mutex_lock(&list_lock); - list_add(&node->list, &cpld_client_list); - mutex_unlock(&list_lock); -} - -static void accton_i2c_cpld_remove_client(struct i2c_client *client) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int found = 0; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client == client) { - found = 1; - break; - } - } - - if (found) { - list_del(list_node); - kfree(cpld_node); - } - - mutex_unlock(&list_lock); -} - -static int accton_i2c_cpld_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - dev_dbg(&client->dev, "i2c_check_functionality failed (0x%x)\n", client->addr); - status = -EIO; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as5712_54x_cpld_group); - if (status) { - goto exit; - } - - dev_info(&client->dev, "chip found\n"); - accton_i2c_cpld_add_client(client); - - return 0; -exit: - return status; -} - -static int accton_i2c_cpld_remove(struct i2c_client *client) -{ - sysfs_remove_group(&client->dev.kobj, &as5712_54x_cpld_group); - - accton_i2c_cpld_remove_client(client); - return 0; -} - -static const struct i2c_device_id accton_i2c_cpld_id[] = { - { "accton_i2c_cpld", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, accton_i2c_cpld_id); - -static struct i2c_driver accton_i2c_cpld_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "accton_i2c_cpld", - }, - .probe = accton_i2c_cpld_probe, - .remove = accton_i2c_cpld_remove, - .id_table = accton_i2c_cpld_id, - .address_list = normal_i2c, -}; - -int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EPERM; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_read_byte_data(cpld_node->client, reg); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(accton_i2c_cpld_read); - -int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EIO; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(accton_i2c_cpld_write); - -static int __init accton_i2c_cpld_init(void) -{ - mutex_init(&list_lock); - return i2c_add_driver(&accton_i2c_cpld_driver); -} - -static void __exit accton_i2c_cpld_exit(void) -{ - i2c_del_driver(&accton_i2c_cpld_driver); -} -/* -static struct dmi_system_id as7712_dmi_table[] = { - { - .ident = "Accton AS7712", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS7712"), - }, - } -}; - -int platform_accton_as7712_32x(void) -{ - return dmi_check_system(as7712_dmi_table); -} -EXPORT_SYMBOL(platform_accton_as7712_32x); -*/ -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton_i2c_cpld driver"); -MODULE_LICENSE("GPL"); - -module_init(accton_i2c_cpld_init); -module_exit(accton_i2c_cpld_exit); diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/service/as7716_32xb-platform-monitor.service b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/service/as7716_32xb-platform-monitor.service deleted file mode 100755 index 05a5d93c48b9..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/service/as7716_32xb-platform-monitor.service +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=Accton AS7716-32XB Platform Monitoring service -Before=pmon.service -After=sysinit.target -DefaultDependencies=no - -[Service] -ExecStartPre=/usr/local/bin/accton_as7716_32xb_util.py install -ExecStart=/usr/local/bin/accton_as7716_32xb_drv_handler.py -KillSignal=SIGKILL -SuccessExitStatus=SIGKILL - -# Resource Limitations -LimitCORE=infinity - -[Install] -WantedBy=multi-user.target diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/setup.py b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/setup.py deleted file mode 100755 index 3edfc29b3817..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/setup.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -from setuptools import setup -os.listdir - -setup( - name='as7716_32xb', - version='1.0', - description='Module to initialize Accton AS7716-32XB platforms', - - packages=['as7716_32xb'], - package_dir={'as7716_32xb': 'as7716-32xb/classes'}, -) - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/utils/README b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/utils/README deleted file mode 100755 index c602d753301e..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/utils/README +++ /dev/null @@ -1,117 +0,0 @@ -Copyright (C) 2016 Accton Networks, Inc. - -This program is free software: you can redistribute it and/or modify -It under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Contents of this package: - patch - files under patch/ is for kernel and ONIE installer - for the kernel: - config-accton-as5712_54x.patch - for kernel configuration. - driver-i2c-muxes-pca954x-always-deselect.patch - for i2c_mux deselects after transaction. - driver-patches-for-accton-as5712-fan-psu-cpld.patch - for as5712's fan/psu/cpld/led/sfp drivers. - for ONIE: - onie_installer-accton-AS5712-54X.patch - for console port setting and copy util script o rootfs. - module - Contains source code of as5712 kernel driver modules. - -The late Sonic building scripts, pushed @Dec 5 2016, will automatically -create a docker container and run building process under it. -User is not necessary to handle docker environment creation. - -1. Download sonic-buildimage environment. - - Run "git clone https://github.com/Azure/sonic-buildimage". - - cd to sonic-buildimage and run "git submodule update --init --recursive". -2. Build kernel - - cd ./src/sonic-linux-kernel - - Copy patches and series from patch/kernel of this release to - sonic-linux-kernel/patch. - - Build kernel by "make". - - The built kernel package, linux-image-3.16.0-4-amd64_3.16.36-1+deb8u2_amd64.deb - , is generated. -3. Build installer - - Change directory back to sonic-buildimage/. - - Get onie_installer-accton-AS5712-54X.patch" from patch/installer. - - Change setting for AS5712-54X by patching build_image.sh. - "patch -p1 < onie_installer-accton-AS5712-54X.patch" - !!NOTICE, patching onie_installer-accton-AS5712-54X.patch comments out the - "git status" checking at build_image.sh. - - The account and password of installed OS can be given at rules/config. - The default user and password are "admin" & "YourPaSsWoRd" respectively. - - Run "make configure PLATFORM=broadcom" - - Copy the built kernel debian package to target/debs/. - The file is linux-image-3.16.0-4-amd64_*_amd64.deb under directory - src/sonic-linux-kernel/. - - Run "make target/sonic-generic.bin" - - Get the installer, target/sonic-generic.bin, to target machine and install. - -All Linux kernel code is licensed under the GPLv1. All other code is -licensed under the GPLv3. Please see the LICENSE file for copies of -both licenses. - -The code for integacting with Accton AS5712-54X has 2 parts, -kernel drivers and operational script. -The kernel drivers of peripherals are under module/ directory. -1. These drivers are patched into kernel by - driver-patches-for-accton-as5712-fan-psu-cpld.patch - Or you can build the driver under module/ by setting environment variable, - KERNEL_SRC, to proper linux built directory and run make. - It may be sonic-linux-kernel/linux-3.*/debian/build/build_amd64_none_amd64/. -2. A operational script, accton_as5712_util.py, for device initializatian and - peripheral accessing should be installed at /usr/bin. - This script is generated by onie_installer-accton-AS5712-54X.patch. - It's done by patching onie_installer-accton-AS5712-54X.patch at build-image. - Run "accton_as5712_util.py install" to install drivers. - -To initialize the system, run "accton_as5712_util.py install". -To clean up the drivers & devices, run "accton_as5712_util.py clean". -To dump information of sensors, run "accton_as5712_util.py show". -To dump SFP EEPROM, run "accton_as5712_util.py sff". -To set fan speed, run "accton_as5712_util.py set fan". -To enable/disable SFP emission, run "accton_as5712_util.py set sfp". -To set system LEDs' color, run "accton_as5712_util.py set led" -For more information, run "accton_as5712_util.py --help". - -==================================================================== -Besides applying accton_as5712_util.py to access peripherals, you can -access peripherals by sysfs nodes directly after the installation is run. - -System LED: - There are 5 system LEDs at the lower-left corner of front panel. - They are loc, diag, fan, ps1, and ps2. - The sysfs interface color mappings are as follows: - Brightness: - 0 => off - 1 => green - 2 => amber - 3 => red - 4 => blue - But not all colors are available for each LED. - -Fan Control: - There are 10 fans inside 5 fan modules. - All fans share 1 duty setting, ranged from 0~100. - -Thermal sensers: - 3 temperature sensors are controlled by the lm75 kernel modules. - -PSUs: - There 2 power supplies slot at the left/right side of the back. - Once if a PSU is not plugged, the status of it is shown failed. - -There are 48 SFP+ and 6 QSFP modules are equipped. -Before operating on PSU and QSFP+, please make sure it is well plugged. -Otherwise, operation is going to fail. - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/utils/accton_as7716_32xb_drv_handler.py b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/utils/accton_as7716_32xb_drv_handler.py deleted file mode 100755 index c08a82c7dc45..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/utils/accton_as7716_32xb_drv_handler.py +++ /dev/null @@ -1,443 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 1/18/2018: Jostar create for as7716_32xb -# ------------------------------------------------------------------ - -try: - import os - import sys, getopt - import subprocess - import click - import imp - import logging - import logging.config - import types - import time # this is only being used as part of the example - import traceback - import commands - from tabulate import tabulate -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - -# Deafults -VERSION = '1.0' -FUNCTION_NAME = 'as7716_32xb_drv_handler' -DEBUG = False - -global log_file -global log_level - -def my_log(txt): - if DEBUG == True: - print "[ACCTON DBG]: "+txt - return - -def log_os_system(cmd, show): - logging.info('Run :'+cmd) - status = 1 - output = "" - status, output = commands.getstatusoutput(cmd) - if DEBUG == True: - my_log (cmd +" , result:" + str(status)) - else: - if show: - print "ACC: " + str(cmd) + " , result:"+ str(status) - #my_log ("cmd:" + cmd) - #my_log (" output:"+output) - if status: - logging.info('Failed :'+cmd) - if show: - print('Failed :'+cmd) - return status, output - - -# Make a class we can use to capture stdout and sterr in the log -class accton_as7716xb_drv_handler(object): - - QSFP_PORT_START = 1 - QSFP_PORT_END = 32 - BASE_PATH = "/usr/local/bin/" - BASE_I2C_PATH="/sys/bus/i2c/devices/" - QSFP_PRESENT_PATH = "/sys/bus/i2c/devices/0-0060/module_present_" - QSFP_RESET_PATH = "/sys/bus/i2c/devices/0-0060/module_reset_" - QSFP_PRESENT_FILE = "/tmp/ipmi_qsfp_pres" - QSFP_EEPROM_FILE = "/tmp/ipmi_qsfp_ee_" - THERMAL_FILE = "/tmp/ipmi_thermal" - IPMI_CMD_QSFP = "ipmitool raw 0x34 0x10 " - IPMI_CMD_THERMAL = "ipmitool raw 0x34 0x12 " - IPMI_CMD_FAN = "ipmitool raw 0x34 0x14 " - IPMI_CMD_PSU ="ipmitool raw 0x34 0x16 " - IPMI_CMD_SYS_EEPROM_1 ="ipmitool raw 0x34 0x18 0x0 0x80" - IPMI_CMD_SYS_EEPROM_2 ="ipmitool raw 0x34 0x18 0x80 0x80" - FAN_ID_START = 1 - FAN_ID_END = 6 - FAN_FILE = "/tmp/ipmi_fan" - FAN_PATH = "/sys/bus/i2c/devices/0-0066/fan" - PSU_ID_START = 1 - PSU_ID_END = 2 - PSU1_PATH = "/sys/bus/i2c/devices/0-0053/" - PSU2_PATH = "/sys/bus/i2c/devices/0-0050/" - PSU1_PMBUS_PATH = "/sys/bus/i2c/devices/0-005b/" - PSU2_PMBUS_PATH = "/sys/bus/i2c/devices/0-0058/" - PSU_FILE = "/tmp/ipmi_psu_" - SYS_EEPROM_FILE_1 = "/tmp/ipmi_sys_eeprom_1" - SYS_EEPROM_FILE_2 = "/tmp/ipmi_sys_eeprom_2" - SYS_EEPROM_PATH = "/sys/bus/i2c/devices/0-0056/eeprom" - - - def __init__(self, log_file, log_level): - """Needs a logger and a logger level.""" - # set up logging to file - logging.basicConfig( - filename=log_file, - filemode='w', - level=log_level, - format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', - datefmt='%H:%M:%S' - ) - - # set up logging to console - if log_level == logging.DEBUG: - console = logging.StreamHandler() - console.setLevel(log_level) - formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') - console.setFormatter(formatter) - logging.getLogger('').addHandler(console) - - logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level) - - def manage_ipmi_qsfp(self): - logging.debug ("drv hanlder-manage_ipmi_qsfp") - print "drv hanlder" - #Handle QSFP case - ipmi_cmd = self.IPMI_CMD_QSFP + " 0x10 > " +self.QSFP_PRESENT_FILE - log_os_system(ipmi_cmd, 0) - file_path = self.QSFP_PRESENT_FILE - check_file = open(file_path) - try: - check_file = open(file_path) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - line = check_file.readline() - pres_line= line.rstrip().replace(" ","") - while line: - line = check_file.readline() - pres_line+=line.rstrip().replace(" ","") - check_file.close() - - - for i in range(self.QSFP_PORT_START, self.QSFP_PORT_END+1, 1): - if i>1: - k=(i-1)*2 +1 - else: - k=1; - if pres_line[k] == '1': - #Set QSFP present - #print "port-%d present" %i - set_drv_cmd = "echo 1 > " + self.QSFP_PRESENT_PATH + str(i) - log_os_system(set_drv_cmd, 0) - #Read QSFP EEPROM - ipmi_cmd = self.IPMI_CMD_QSFP +str(i)+ " 0x00 > " +self.QSFP_EEPROM_FILE + str(i) + "_1" - log_os_system(ipmi_cmd, 0) - ipmi_cmd = self.IPMI_CMD_QSFP +str(i)+ " 0x01 > " +self.QSFP_EEPROM_FILE + str(i) + "_2" - log_os_system(ipmi_cmd, 0) - file_path = self.QSFP_EEPROM_FILE + str(i) + "_1" - check_file = open(file_path) - try: - check_file = open(file_path) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - line = check_file.readline() - str_line= line.rstrip().replace(" ","") - while line: - line = check_file.readline() - str_line+=line.rstrip().replace(" ","") - check_file.close() - file_path = self.QSFP_EEPROM_FILE + str(i) + "_2" - check_file = open(file_path) - try: - check_file = open(file_path) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - line = check_file.readline() - str_line+= line.rstrip().replace(" ","") - - while line: - line = check_file.readline() - str_line+=line.rstrip().replace(" ","") - check_file.close() - #Set QSFP EEPROM - if(i < 10): - set_drv_cmd = "echo " + str_line+ " > " + self.BASE_I2C_PATH + "0-000"+str(i) +"/eeprom" - else: - set_drv_cmd = "echo " + str_line+ " > " + self.BASE_I2C_PATH + "0-00"+str(i) +"/eeprom" - #print(set_drv_cmd) - log_os_system(set_drv_cmd, 0) - else: - ipmi_cmd = "echo 0 > " + self.QSFP_PRESENT_PATH + str(i) - log_os_system(ipmi_cmd, 0) - if(i < 10): - set_drv_cmd = "echo 0 > " + self.BASE_I2C_PATH + "0-000"+str(i) +"/eeprom" - else: - set_drv_cmd = "echo 0 > " + self.BASE_I2C_PATH + "0-00"+str(i) +"/eeprom" - #print(set_drv_cmd) - log_os_system(set_drv_cmd, 0) - - time.sleep(0.01) - return True - - def manage_ipmi_thermal(self): - logging.debug ("drv hanlder-manage_ipmi_thermal") - #Handle thermal case - #ipmitool raw 0x34 0x12 - ipmi_cmd = self.IPMI_CMD_THERMAL + " > " +self.THERMAL_FILE - log_os_system(ipmi_cmd, 0) - file_path = self.THERMAL_FILE - check_file = open(file_path) - try: - check_file = open(file_path) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - line = check_file.readline() - str_line= line.rstrip().replace(" ","") - while line: - line = check_file.readline() - str_line+=line.rstrip().replace(" ","") - check_file.close() - val_str= "0x" + str(str_line[4])+str(str_line[5]) - val_int=int(val_str, 16)*1000 - check_file.close() - set_drv_cmd = "echo "+str(val_int) + " > " + self.BASE_I2C_PATH + "0-0048/temp1_input" - log_os_system(set_drv_cmd,0) - val_str= "0x" + str(str_line[10])+str(str_line[11]) - val_int=int(val_str, 16) * 1000 - set_drv_cmd = "echo "+str(val_int) + " > " + self.BASE_I2C_PATH + "0-0049/temp1_input" - log_os_system(set_drv_cmd,0) - val_str= "0x" + str(str_line[16])+str(str_line[17]) - val_int=int(val_str, 16) * 1000 - set_drv_cmd = "echo "+str(val_int) + " > " + self.BASE_I2C_PATH + "0-004a/temp1_input" - log_os_system(set_drv_cmd, 0) - - return True - - def manage_ipmi_fan(self): - logging.debug ("drv hanlder-manage_ipmi_fan") - #Handle fan case - #ipmitool raw 0x34 0x14 - ipmi_cmd = self.IPMI_CMD_FAN + " > " +self.FAN_FILE - log_os_system(ipmi_cmd, 0) - file_path = self.FAN_FILE - #print(file_path) - check_file = open(file_path) - try: - check_file = open(file_path) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - line = check_file.readline() - str_line= line.rstrip().replace(" ","") - while line: - line = check_file.readline() - str_line+=line.rstrip().replace(" ","") - check_file.close() - #print (str_line) - k=0 - for i in range(self.FAN_ID_START, self.FAN_ID_END+1, 1): - #print "k=%d"%k - if str_line[k+1]=='0': - set_drv_cmd = "echo 1 > " + self.FAN_PATH + str(i) + "_present" - else: - set_drv_cmd = "echo 0 > " + self.FAN_PATH + str(i) + "_present" - log_os_system(set_drv_cmd, 0) - - val_str= "0x" + str(str_line[k+6])+str(str_line[k+7]) + str(str_line[k+4])+str(str_line[k+5]) - val_int=int(val_str, 16) - set_drv_cmd = "echo " + str(val_int) + " > " + self.FAN_PATH + str(i) + "_front_speed_rpm" - log_os_system(set_drv_cmd, 0) - val_str= "0x" + str(str_line[k+54])+str(str_line[k+55]) + str(str_line[k+52])+str(str_line[k+53]) - val_int=int(val_str, 16) - set_drv_cmd = "echo " + str(val_int) + " > " + self.FAN_PATH + str(i) + "_rear_speed_rpm" - log_os_system(set_drv_cmd, 0) - k+=8; - return True - - - def manage_ipmi_psu(self): - logging.debug ("drv hanlder-manage_ipmi_psu") - #Handle psu case - #present: ipmitool raw 0x34 0x16 '0x1' . Param-1 is psu id(id_1:0x1, id_2:0x2) - - #cpld access psu - for i in range(self.PSU_ID_START, self.PSU_ID_END+1, 1): - #present case - ipmi_cmd = self.IPMI_CMD_PSU + str(i) + " > " +self.PSU_FILE + str(i) - log_os_system(ipmi_cmd, 0) - if i==1: - psu_sysfs_path = self.PSU1_PATH - else: - psu_sysfs_path = self.PSU2_PATH - file_path = self.PSU_FILE + str(i) - #print(file_path) - check_file = open(file_path) - try: - check_file = open(file_path) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - line = check_file.readline() - str_line= line.rstrip().replace(" ","") - while line: - line = check_file.readline() - str_line+=line.rstrip().replace(" ","") - check_file.close() - #print (line) - if str_line[1]=='0': - int_val=1 #psu insert - #print "psu_%d present"%i - set_drv_cmd = "echo " +str(int_val) + " > " + psu_sysfs_path + "psu_present" - log_os_system(set_drv_cmd, 0) - set_drv_cmd = "echo " + str(str_line[5]) + " > " + psu_sysfs_path + "psu_power_good" - log_os_system(set_drv_cmd, 0) - else: - int_val=0 - set_drv_cmd = "echo " +str(int_val) + " > " + psu_sysfs_path + "psu_present" - log_os_system(set_drv_cmd, 0) - set_drv_cmd = "echo " + str(int_val) + " > " + psu_sysfs_path + "psu_power_good" - log_os_system(set_drv_cmd, 0) - - #pmbus - if i==1: - psu_sysfs_path = self.PSU1_PMBUS_PATH - else: - psu_sysfs_path = self.PSU2_PMBUS_PATH - - if str_line[5]=='1': #power_on - val_str= "0x" + str(str_line[28])+str(str_line[29]) + str(str_line[26])+str(str_line[27]) - val_int=int(val_str, 16) * 1000 - set_drv_cmd = "echo " + str(val_int) + " > " + psu_sysfs_path + "psu_temp1_input" - log_os_system(set_drv_cmd, 0) - #print "val_int=%d"%val_int - val_str= "0x" + str(str_line[32])+str(str_line[33]) + str(str_line[30])+str(str_line[31]) - val_int=int(val_str, 16) - #print "fan:val_int=%d"%val_int - set_drv_cmd = "echo " + str(val_int) + " > " + psu_sysfs_path + "psu_fan1_speed_rpm" - log_os_system(set_drv_cmd, 0) - val_str= "0x" + str(str_line[36])+str(str_line[37]) + str(str_line[34])+str(str_line[35]) - val_int=int(val_str, 16) - #print "pout val_int=%d"%val_int - set_drv_cmd = "echo " + str(val_int) + " > " + psu_sysfs_path + "psu_p_out" - log_os_system(set_drv_cmd, 0) - else: #power_off - val_int=0 - set_drv_cmd = "echo " + str(val_int) + " > " + psu_sysfs_path + "psu_temp1_input" - log_os_system(set_drv_cmd, 0) - set_drv_cmd = "echo " + str(val_int) + " > " + psu_sysfs_path + "psu_fan1_speed_rpm" - log_os_system(set_drv_cmd, 0) - set_drv_cmd = "echo " + str(val_int) + " > " + psu_sysfs_path + "psu_p_out" - log_os_system(set_drv_cmd, 0) - - time.sleep(2) - return True - - def manage_ipmi_sys(self): - logging.debug ("drv hanlder-manage_ipmi_sys") - #Handle sys case - #ipmitool -raw 0x34 0x18 0x00 0x80 - #ipmitool -raw 0x34 0x18 0x80 0x80 - - ipmi_cmd = self.IPMI_CMD_SYS_EEPROM_1 + " > " + self.SYS_EEPROM_FILE_1 - log_os_system(ipmi_cmd, 0) - ipmi_cmd = self.IPMI_CMD_SYS_EEPROM_2 + " > " + self.SYS_EEPROM_FILE_2 - log_os_system(ipmi_cmd, 0) - - #Read SYS EEPROM - file_path = self.SYS_EEPROM_FILE_1 - check_file = open(file_path) - try: - check_file = open(file_path) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - line = check_file.readline() - str_line= line.rstrip().replace(" ","") - while line: - line = check_file.readline() - str_line+=line.rstrip().replace(" ","") - check_file.close() - - file_path = self.SYS_EEPROM_FILE_2 - check_file = open(file_path) - try: - check_file = open(file_path) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - line = check_file.readline() - str_line+= line.rstrip().replace(" ","") - while line: - line = check_file.readline() - str_line+=line.rstrip().replace(" ","") - check_file.close() - #print(len(str_line)) - #print(str_line) - set_drv_cmd = "echo " + str_line+ " > " + self.SYS_EEPROM_PATH - #print(set_drv_cmd) - log_os_system(set_drv_cmd, 0) - - return True - -def main(argv): - log_file = '%s.log' % FUNCTION_NAME - log_level = logging.WARNING - if len(sys.argv) != 1: - try: - opts, args = getopt.getopt(argv,'hdl:',['lfile=']) - except getopt.GetoptError: - print 'Usage: %s [-d] [-l ]' % sys.argv[0] - return 0 - for opt, arg in opts: - if opt == '-h': - print 'Usage: %s [-d] [-l ]' % sys.argv[0] - return 0 - elif opt in ('-d', '--debug'): - log_level = logging.DEBUG - elif opt in ('-l', '--lfile'): - log_file = arg - - set_drv_cmd = "echo 100 > /sys/module/ipmi_si/parameters/kipmid_max_busy_us" - log_os_system(set_drv_cmd, 0) - monitor = accton_as7716xb_drv_handler(log_file, log_level) - - set_sys_eeprom=0 - thermal_chk_time=0 - psu_chk_time=0 - # Loop forever, doing something useful hopefully: - while True: - logging.debug ("monitor.manage_ipmi") - if set_sys_eeprom==0: - monitor.manage_ipmi_sys() - set_sys_eeprom=1 - monitor.manage_ipmi_qsfp() - time.sleep(0.1) - monitor.manage_ipmi_thermal() - monitor.manage_ipmi_psu() - time.sleep(0.1) - monitor.manage_ipmi_fan() - time.sleep(0.05) - -if __name__ == '__main__': - main(sys.argv[1:]) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/utils/accton_as7716_32xb_monitor.py b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/utils/accton_as7716_32xb_monitor.py deleted file mode 100755 index 2568312b0955..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/utils/accton_as7716_32xb_monitor.py +++ /dev/null @@ -1,227 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 Accton Technology Corporation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# ------------------------------------------------------------------ -# HISTORY: -# mm/dd/yyyy (A.D.) -# 11/13/2017: Polly Hsu, Create -# 1/10/2018: Jostar modify for as7716_32 -# ------------------------------------------------------------------ - -try: - import os - import sys, getopt - import subprocess - import click - import imp - import logging - import logging.config - import types - import time # this is only being used as part of the example - import traceback - from tabulate import tabulate - from as7716_32x.fanutil import FanUtil - from as7716_32x.thermalutil import ThermalUtil -except ImportError as e: - raise ImportError('%s - required module not found' % str(e)) - -# Deafults -VERSION = '1.0' -FUNCTION_NAME = 'accton_as7716_monitor' - -global log_file -global log_level - - # For AC power Front to Back : - # If any fan fail, please fan speed register to 15 - # The max value of Fan speed register is 9 - # [LM75(48) + LM75(49) + LM75(4A)] > 174 => set Fan speed value from 4 to 5 - # [LM75(48) + LM75(49) + LM75(4A)] > 182 => set Fan speed value from 5 to 7 - # [LM75(48) + LM75(49) + LM75(4A)] > 190 => set Fan speed value from 7 to 9 - # - # [LM75(48) + LM75(49) + LM75(4A)] < 170 => set Fan speed value from 5 to 4 - # [LM75(48) + LM75(49) + LM75(4A)] < 178 => set Fan speed value from 7 to 5 - # [LM75(48) + LM75(49) + LM75(4A)] < 186 => set Fan speed value from 9 to 7 - # - # - # For AC power Back to Front : - # If any fan fail, please fan speed register to 15 - # The max value of Fan speed register is 10 - # [LM75(48) + LM75(49) + LM75(4A)] > 140 => set Fan speed value from 4 to 5 - # [LM75(48) + LM75(49) + LM75(4A)] > 150 => set Fan speed value from 5 to 7 - # [LM75(48) + LM75(49) + LM75(4A)] > 160 => set Fan speed value from 7 to 10 - # - # [LM75(48) + LM75(49) + LM75(4A)] < 135 => set Fan speed value from 5 to 4 - # [LM75(48) + LM75(49) + LM75(4A)] < 145 => set Fan speed value from 7 to 5 - # [LM75(48) + LM75(49) + LM75(4A)] < 155 => set Fan speed value from 10 to 7 - # - - - # 2.If no matched fan speed is found from the policy, - # use FAN_DUTY_CYCLE_MIN as default speed - # Get current temperature - # 4.Decision 3: Decide new fan speed depend on fan direction/current fan speed/temperature - - - - -# Make a class we can use to capture stdout and sterr in the log -class accton_as7716_monitor(object): - # static temp var - _ori_temp = 0 - _new_perc = 0 - _ori_perc = 0 - - def __init__(self, log_file, log_level): - """Needs a logger and a logger level.""" - # set up logging to file - logging.basicConfig( - filename=log_file, - filemode='w', - level=log_level, - format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', - datefmt='%H:%M:%S' - ) - - # set up logging to console - if log_level == logging.DEBUG: - console = logging.StreamHandler() - console.setLevel(log_level) - formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') - console.setFormatter(formatter) - logging.getLogger('').addHandler(console) - - logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level) - - def manage_fans(self): - - fan_policy_f2b = { - 0: [32, 0, 174000], - 1: [38, 170000, 182000], - 2: [50, 178000, 190000], - 3: [63, 186000, 0], - } - fan_policy_b2f = { - 0: [32, 0, 140000], - 1: [38, 135000, 150000], - 2: [50, 145000, 160000], - 3: [69, 15500, 0], - } - - thermal = ThermalUtil() - fan = FanUtil() - get_temp = thermal.get_thermal_temp() - # 1. Get each fan status, one not presented, set speed to full - # Get fan direction (Only get the first one since all fan direction are the same) - # Get current fan duty cycle - cur_duty_cycle = fan.get_fan_duty_cycle() - #print "cur_duty_cycle=%d" %cur_duty_cycle - #print "get_temp=%d" %get_temp - - for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1): - fan_status = fan.get_fan_status(x) - if fan_status is None: - #print "fan_status is None" - logging.debug('INFO. SET new_perc to %d (FAN stauts is None. fan_num:%d)', 100, x) - return False - if fan_status is False: - #self._new_perc = FAN_LEV1_SPEED_PERC - #print "fan_%d status=false, set 45 duty_cycle" %x - logging.debug('INFO. SET new_perc to %d (FAN fault. fan_num:%d)', 100, x) - fan.set_fan_duty_cycle(45) - return True - logging.debug('INFO. fan_status is True (fan_num:%d)', x) - - if fan_status is not None and fan_status is not False: - fan_dir=fan.get_fan_dir(1) - for x in range(0, 4): - if cur_duty_cycle == fan_policy_f2b[x][0]: - break - #print "x=%d" %x - #print "fan_dir=%d" %fan_dir - #print "fan_policy_f2b[x][0]=%d" %fan_policy_f2b[x][0] - #print "cur_duty_cycle=%d" %cur_duty_cycle - - if fan_dir == 1: - if x == 4 : - fan.set_fan_duty_cycle(fan_policy_f2b[0][0]) - new_duty_cycle=cur_duty_cycle - # if temp > up_levle, else if temp < down_level - if get_temp > fan_policy_f2b[x][2] and x != 3 : - new_duty_cycle= fan_policy_f2b[x+1][0] - #print "new_duty_cycle= fan_policy_f2b[x+1][0]=%d" %new_duty_cycle - #print "Becasue get_temp > fan_policy_f2b[x][2]=%d" %fan_policy_f2b[x][2] - logging.debug('INFO. THERMAL temp UP, temp %d > %d , new_duty_cycle=%d', get_temp, fan_policy_f2b[x][2], new_duty_cycle) - #else get_temp < fan_policy_f2b[x][1] and x != 0 : - elif get_temp < fan_policy_f2b[x][1] : - new_duty_cycle= fan_policy_f2b[x-1][0] - #print "new_duty_cycle= fan_policy_f2b[x-1][0]=%d" %new_duty_cycle - #print "Becasue get_temp < fan_policy_f2b[x][1]=%d" %fan_policy_f2b[x][1] - logging.debug('INFO. THERMAL temp down, temp %d < %d , new_duty_cycle=%d', get_temp, fan_policy_f2b[x][1], new_duty_cycle) - if new_duty_cycle == cur_duty_cycle : - #print "new_duty_cycle == cur_duty_cycle case, so return True" - return True - else: - if x == 4 : - fan.set_fan_duty_cycle(fan_policy_b2f[0][0]) - new_duty_cycle=cur_duty_cycle - # if temp > up_levle, else if temp < down_level - if get_temp > fan_policy_b2f[x][1] and x != 3 : - new_duty_cycle= fan_policy_b2f[x+1][0] - logging.debug('INFO. THERMAL temp UP, temp %d > %d , new_duty_cycle=%d', get_temp, fan_policy_b2f[x][2], new_duty_cycle) - elif get_temp < fan_policy_b2f[x][0] and x != 0 : - #elif get_temp < fan_policy_b2f[x][0] - new_duty_cycle= fan_policy_b2f[x-1][0] - logging.debug('INFO. THERMAL temp down, temp %d < %d , new_duty_cycle=%d', get_temp, fan_policy_b2f[x][1], new_duty_cycle) - if new_duty_cycle == cur_duty_cycle : - return True - - fan.set_fan_duty_cycle(new_duty_cycle) - #print "set new_duty_cycle=%d" %new_duty_cycle - #print "old_duty_cycle=%d" %cur_duty_cycle - - return True - - - -def main(argv): - log_file = '%s.log' % FUNCTION_NAME - log_level = logging.INFO - if len(sys.argv) != 1: - try: - opts, args = getopt.getopt(argv,'hdl:',['lfile=']) - except getopt.GetoptError: - print 'Usage: %s [-d] [-l ]' % sys.argv[0] - return 0 - for opt, arg in opts: - if opt == '-h': - print 'Usage: %s [-d] [-l ]' % sys.argv[0] - return 0 - elif opt in ('-d', '--debug'): - log_level = logging.DEBUG - elif opt in ('-l', '--lfile'): - log_file = arg - - monitor = accton_as7716_monitor(log_file, log_level) - - # Loop forever, doing something useful hopefully: - while True: - monitor.manage_fans() - time.sleep(1) - -if __name__ == '__main__': - main(sys.argv[1:]) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/utils/accton_as7716_32xb_util.py b/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/utils/accton_as7716_32xb_util.py deleted file mode 100755 index ffddfb338506..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7716-32xb/utils/accton_as7716_32xb_util.py +++ /dev/null @@ -1,616 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2016 Accton Networks, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" -Usage: %(scriptName)s [options] command object - -options: - -h | --help : this help message - -d | --debug : run with debug mode - -f | --force : ignore error during installation or clean -command: - install : install drivers and generate related sysfs nodes - clean : uninstall drivers and remove related sysfs nodes - show : show all systen status - sff : dump SFP eeprom - set : change board setting with fan|led|sfp -""" - -import os -import commands -import sys, getopt -import logging -import re -import time -from collections import namedtuple - -PROJECT_NAME = 'as7716_32xb' -version = '0.0.1' -verbose = False -DEBUG = False -args = [] -ALL_DEVICE = {} -DEVICE_NO = {'led':5, 'fan1':1, 'fan2':1,'fan3':1,'fan4':1,'fan5':1,'thermal':3, 'psu':2, 'sfp':54} - - -led_prefix ='/sys/devices/platform/as7716_32xb_led/leds/accton_'+PROJECT_NAME+'_led::' -fan_prefix ='/sys/devices/platform/as7716_32xb_' -hwmon_types = {'led': ['diag','fan','loc','psu1','psu2'], - 'fan1': ['fan'], - 'fan2': ['fan'], - 'fan3': ['fan'], - 'fan4': ['fan'], - 'fan5': ['fan'], - 'fan5': ['fan'], - } -hwmon_nodes = {'led': ['brightness'] , - 'fan1': ['fan_duty_cycle_percentage', 'fan1_fault', 'fan1_speed_rpm', 'fan1_direction', 'fanr1_fault', 'fanr1_speed_rpm'], - 'fan2': ['fan_duty_cycle_percentage','fan2_fault', 'fan2_speed_rpm', 'fan2_direction', 'fanr2_fault', 'fanr2_speed_rpm'], - 'fan3': ['fan_duty_cycle_percentage','fan3_fault', 'fan3_speed_rpm', 'fan3_direction', 'fanr3_fault', 'fanr3_speed_rpm'], - 'fan4': ['fan4_duty_cycle_percentage','fan4_fault', 'fan4_speed_rpm', 'fan4_direction', 'fanr4_fault', 'fanr4_speed_rpm'], - 'fan5': ['fan_duty_cycle_percentage','fan5_fault', 'fan5_speed_rpm', 'fan5_direction', 'fanr5_fault', 'fanr5_speed_rpm'], - } -hwmon_prefix ={'led': led_prefix, - 'fan1': fan_prefix, - 'fan2': fan_prefix, - 'fan3': fan_prefix, - 'fan4': fan_prefix, - 'fan5': fan_prefix, - } - -i2c_prefix = '/sys/bus/i2c/devices/' -i2c_drv_prefix = '/sys/bus/i2c/devices/' -i2c_bus = {'thermal': ['10-0048','10-0049', '10-004a'] , - 'psu': ['17-0050','18-0053'], - 'sfp': ['-0050']} -i2c_nodes = { - 'thermal': ['hwmon/hwmon*/temp1_input'] , - 'psu': ['psu_present ', 'psu_power_good'] , - 'sfp': ['sfp_is_present ', 'sfp_tx_disable']} - -sfp_map = [1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32] - -mknod =[ -'echo as7716_32xb_cpld1 0x60 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo accton_i2c_cpld 0x62 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo accton_i2c_cpld 0x64 > /sys/bus/i2c/devices/i2c-0/new_device', - -] - -mknod_xb =[ -'echo as7716_32xb_cpld1 0x60 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo accton_i2c_cpld 0x62 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo accton_i2c_cpld 0x64 > /sys/bus/i2c/devices/i2c-0/new_device', -#Thermal -'echo as7716_32xb_thermal 0x48 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo as7716_32xb_thermal 0x49 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo as7716_32xb_thermal 0x4a > /sys/bus/i2c/devices/i2c-0/new_device', -#Fan -'echo as7716_32xb_fan 0x66 > /sys/bus/i2c/devices/i2c-0/new_device', -# PSU-1 -'echo as7716_32xb_psu1 0x53 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo as7716_32xb_psu2 0x50> /sys/bus/i2c/devices/i2c-0/new_device', -# PSU-2 -'echo as7716_32xb_pmbus 0x5b > /sys/bus/i2c/devices/i2c-0/new_device', -'echo as7716_32xb_pmbus 0x58 > /sys/bus/i2c/devices/i2c-0/new_device', -#EERPOM -'echo as7716_32xb_sys 0x56 > /sys/bus/i2c/devices/i2c-0/new_device', -] - - - -mknod2 =[ -'echo as7716_32xb_cpld1 0x60 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo accton_i2c_cpld 0x61 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo accton_i2c_cpld 0x62 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-0/new_device', - -# PSU-1 -'echo as7716_32xb_psu1 0x38 > /sys/bus/i2c/devices/i2c-57/new_device', -'echo cpr_4011_4mxx 0x3c > /sys/bus/i2c/devices/i2c-57/new_device', -'echo as7716_32xb_psu1 0x50 > /sys/bus/i2c/devices/i2c-57/new_device', -'echo ym2401 0x58 > /sys/bus/i2c/devices/i2c-57/new_device', - -# PSU-2 -'echo as7716_32xb_psu2 0x3b > /sys/bus/i2c/devices/i2c-58/new_device', -'echo cpr_4011_4mxx 0x3f > /sys/bus/i2c/devices/i2c-58/new_device', -'echo as7716_32xb_psu2 0x53 > /sys/bus/i2c/devices/i2c-58/new_device', -'echo ym2401 0x5b > /sys/bus/i2c/devices/i2c-58/new_device', - -'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-61/new_device', -'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-62/new_device', -'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-63/new_device', - -#EERPOM -#'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-1/new_device', -] - -FORCE = 0 -logging.basicConfig(filename= PROJECT_NAME+'.log', filemode='w',level=logging.DEBUG) -logging.basicConfig(level=logging.INFO) - - -if DEBUG == True: - print sys.argv[0] - print 'ARGV :', sys.argv[1:] - - -def main(): - global DEBUG - global args - global FORCE - - if len(sys.argv)<2: - show_help() - - options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help', - 'debug', - 'force', - ]) - if DEBUG == True: - print options - print args - print len(sys.argv) - - for opt, arg in options: - if opt in ('-h', '--help'): - show_help() - elif opt in ('-d', '--debug'): - DEBUG = True - logging.basicConfig(level=logging.INFO) - elif opt in ('-f', '--force'): - FORCE = 1 - else: - logging.info('no option') - for arg in args: - if arg == 'install': - do_install() - elif arg == 'clean': - do_uninstall() - elif arg == 'show': - device_traversal() - elif arg == 'sff': - if len(args)!=2: - show_eeprom_help() - elif int(args[1]) ==0 or int(args[1]) > DEVICE_NO['sfp']: - show_eeprom_help() - else: - show_eeprom(args[1]) - return - elif arg == 'set': - if len(args)<3: - show_set_help() - else: - set_device(args[1:]) - return - else: - show_help() - - - return 0 - -def show_help(): - print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]} - sys.exit(0) - -def show_set_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print cmd +" [led|sfp|fan]" - print " use \""+ cmd + " led 0-4 \" to set led color" - print " use \""+ cmd + " fan 0-100\" to set fan duty percetage" - print " use \""+ cmd + " sfp 1-32 {0|1}\" to set sfp# tx_disable" - sys.exit(0) - -def show_eeprom_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print " use \""+ cmd + " 1-32 \" to dump sfp# eeprom" - sys.exit(0) - -def my_log(txt): - if DEBUG == True: - print "[ACCTON DBG]: "+txt - return - -def log_os_system(cmd, show): - logging.info('Run :'+cmd) - status = 1 - output = "" - status, output = commands.getstatusoutput(cmd) - my_log (cmd +"with result:" + str(status)) - my_log ("cmd:" + cmd) - my_log (" output:"+output) - if status: - logging.info('Failed :'+cmd) - if show: - print('Failed :'+cmd) - return status, output - -def driver_inserted(): - ret, lsmod = log_os_system("lsmod| grep accton", 0) - logging.info('mods:'+lsmod) - if len(lsmod) ==0: - return False - - -kos = [ -'depmod -ae', -'modprobe ipmi_msghandler', -'modprobe ipmi_si', -'modprobe ipmi_devintf', -'modprobe i2c_dev', -'modprobe accton_i2c_cpld', -'modprobe accton_as7716_32xb_cpld1', -'modprobe accton_as7716_32xb_fan', -'modprobe accton_as7716_32xb_leds', -'modprobe accton_as7716_32xb_psu', -'modprobe accton_as7716_32xb_oom', -'modprobe accton_as7716_32xb_thermal', -'modprobe accton_as7716_32xb_pmbus', -'modprobe accton_as7716_32xb_sys'] - -def driver_install(): - global FORCE - for i in range(0,len(kos)): - status, output = log_os_system(kos[i], 1) - if status: - if FORCE == 0: - return status - return 0 - -def driver_uninstall(): - global FORCE - for i in range(0,len(kos)): - rm = kos[-(i+1)].replace("modprobe", "modprobe -rq") - rm = rm.replace("insmod", "rmmod") - status, output = log_os_system(rm, 1) - if status: - if FORCE == 0: - return status - return 0 - - - -def i2c_order_check(): - # i2c bus 0 and 1 might be installed in different order. - # Here check if 0x76 is exist @ i2c-0 - tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device" - status, output = log_os_system(tmp, 0) - if not device_exist(): - order = 1 - else: - order = 0 - tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-1/delete_device" - status, output = log_os_system(tmp, 0) - return order - -def device_install(): - global FORCE - - #order = i2c_order_check() - # if 0x76 is not exist @i2c-0, use reversed bus order - #if order: - # for i in range(0,len(mknod2)): - # #for pca932x need times to built new i2c buses - # if mknod2[i].find('pca954') != -1: - # time.sleep(2) - - # status, output = log_os_system(mknod2[i], 1) - # if status: - # print output - # if FORCE == 0: - # return status - #else: - print "Prepar to create instance.............." - for i in range(0,len(mknod_xb)): - print "Beginn to create instance.............." - status, output = log_os_system(mknod_xb[i], 1) - print "status=%s" %status - print "output=%s" %output - if status: - print output - if FORCE == 0: - return status - #time.sleep (50.0 / 1000.0) - print "Create sfp instance.............." - for i in range(0,len(sfp_map)): - status, output =log_os_system("echo as7716_32xb_oom 0x"+str(sfp_map[i])+ " > /sys/bus/i2c/devices/i2c-0/new_device", 1) - if status: - print output - if FORCE == 0: - return status - #status, output =log_os_system("echo port"+str(i)+" > /sys/bus/i2c/devices/0-000"+str(sfp_map[i])+"/port_name", 1) - #if status: - # print output - # if FORCE == 0: - # return status - return - -def device_uninstall(): - global FORCE - - for i in range(0,len(sfp_map)): - target = "echo 0x"+str(sfp_map[i])+ " > /sys/bus/i2c/devices/i2c-0/delete_device" - print(target) - status, output =log_os_system(target, 1) - if status: - print output - if FORCE == 0: - return status - - nodelist = mknod_xb - - for i in range(len(nodelist)): - target = nodelist[-(i+1)] - temp = target.split() - del temp[1] - temp[-1] = temp[-1].replace('new_device', 'delete_device') - status, output = log_os_system(" ".join(temp), 1) - if status: - print output - if FORCE == 0: - return status - - return - -def system_ready(): - if driver_inserted() == False: - print "driver_inserted() == False" - return False - if not device_exist(): - print "not device_exist()" - return False - return True - -def do_install(): - print "Checking system...." - if driver_inserted() == False: - print "No driver, installing.1..." - status = driver_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" drivers detected...." - if not device_exist(): - print "No device, installing..2.." - status = device_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" devices detected...." - return - -def do_uninstall(): - print "Checking systemm...." - if not device_exist(): - print PROJECT_NAME.upper() +" has no device installed...." - else: - print "Removing device...." - status = device_uninstall() - if status: - if FORCE == 0: - return status - - if driver_inserted()== False : - print PROJECT_NAME.upper() +" has no driver installed...." - else: - print "Removing installed driver...." - status = driver_uninstall() - if status: - if FORCE == 0: - return status - - return - -def devices_info(): - global DEVICE_NO - global ALL_DEVICE - global i2c_bus, hwmon_types - for key in DEVICE_NO: - ALL_DEVICE[key]= {} - for i in range(0,DEVICE_NO[key]): - ALL_DEVICE[key][key+str(i+1)] = [] - - for key in i2c_bus: - buses = i2c_bus[key] - nodes = i2c_nodes[key] - for i in range(0,len(buses)): - for j in range(0,len(nodes)): - if 'fan' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - elif 'sfp' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ str(sfp_map[k])+ buses[i]+"/"+ nodes[j] - print "path= %s" %path - print "i=%d" %i - print "k=%d" %k - print "j= %d" %j - print "sfp_map[k]=%s" %sfp_map[k] - print " buses[i]=%s" %buses[i] - print "nodes[j]=%s" %nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - else: - node = key+str(i+1) - path = i2c_prefix+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - - for key in hwmon_types: - itypes = hwmon_types[key] - nodes = hwmon_nodes[key] - for i in range(0,len(itypes)): - for j in range(0,len(nodes)): - node = key+"_"+itypes[i] - path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][ key+str(i+1)].append(path) - - #show dict all in the order - if DEBUG == True: - for i in sorted(ALL_DEVICE.keys()): - print(i+": ") - for j in sorted(ALL_DEVICE[i].keys()): - print(" "+j) - for k in (ALL_DEVICE[i][j]): - print(" "+" "+k) - return - -def show_eeprom(index): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0] - node = node.replace(node.split("/")[-1], 'sfp_eeprom') - # check if got hexdump command in current environment - ret, log = log_os_system("which hexdump", 0) - ret, log2 = log_os_system("which busybox hexdump", 0) - if len(log): - hex_cmd = 'hexdump' - elif len(log2): - hex_cmd = ' busybox hexdump' - else: - log = 'Failed : no hexdump cmd!!' - logging.info(log) - print log - return 1 - - print node + ":" - ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1) - if ret==0: - print log - else: - print "**********device no found**********" - return - -def set_device(args): - global DEVICE_NO - global ALL_DEVICE - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - - if args[0]=='led': - if int(args[1])>4: - show_set_help() - return - #print ALL_DEVICE['led'] - for i in range(0,len(ALL_DEVICE['led'])): - for k in (ALL_DEVICE['led']['led'+str(i+1)]): - ret, log = log_os_system("echo "+args[1]+" >"+k, 1) - if ret: - return ret - elif args[0]=='fan': - if int(args[1])>100: - show_set_help() - return - #print ALL_DEVICE['fan'] - #fan1~6 is all fine, all fan share same setting - node = ALL_DEVICE['fan1'] ['fan11'][0] - node = node.replace(node.split("/")[-1], 'fan1_duty_cycle_percentage') - ret, log = log_os_system("cat "+ node, 1) - if ret==0: - print ("Previous fan duty: " + log.strip() +"%") - ret, log = log_os_system("echo "+args[1]+" >"+node, 1) - if ret==0: - print ("Current fan duty: " + args[1] +"%") - return ret - elif args[0]=='sfp': - if int(args[1])> DEVICE_NO[args[0]] or int(args[1])==0: - show_set_help() - return - if len(args)<2: - show_set_help() - return - - if int(args[2])>1: - show_set_help() - return - - #print ALL_DEVICE[args[0]] - for i in range(0,len(ALL_DEVICE[args[0]])): - for j in ALL_DEVICE[args[0]][args[0]+str(args[1])]: - if j.find('tx_disable')!= -1: - ret, log = log_os_system("echo "+args[2]+" >"+ j, 1) - if ret: - return ret - - return - -#get digits inside a string. -#Ex: 31 for "sfp31" -def get_value(input): - digit = re.findall('\d+', input) - return int(digit[0]) - -def device_traversal(): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - for i in sorted(ALL_DEVICE.keys()): - print("============================================") - print(i.upper()+": ") - print("============================================") - - for j in sorted(ALL_DEVICE[i].keys(), key=get_value): - print " "+j+":", - for k in (ALL_DEVICE[i][j]): - ret, log = log_os_system("cat "+k, 0) - func = k.split("/")[-1].strip() - func = re.sub(j+'_','',func,1) - func = re.sub(i.lower()+'_','',func,1) - if ret==0: - print func+"="+log+" ", - else: - print func+"="+"X"+" ", - print - print("----------------------------------------------------------------") - - - print - return - -def device_exist(): - ret1, log = log_os_system("ls "+i2c_prefix+"*0060", 0) - ret2, log = log_os_system("ls "+i2c_prefix+"i2c-0", 0) - print(ret1) - print(ret2) - return not(ret1 or ret2) - -if __name__ == "__main__": - main() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/classes/__init__.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/classes/__init__.py deleted file mode 100755 index e69de29bb2d1..000000000000 diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/classes/fanutil.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/classes/fanutil.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/classes/thermalutil.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/classes/thermalutil.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/Makefile b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/Makefile deleted file mode 100644 index 1b3477b0b771..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -obj-m:=x86-64-accton-as7816-64x-fan.o x86-64-accton-as7816-64x-sfp.o x86-64-accton-as7816-64x-leds.o \ - x86-64-accton-as7816-64x-psu.o accton_i2c_cpld.o ym2651y.o diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/accton_i2c_cpld.c b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/accton_i2c_cpld.c deleted file mode 120000 index 39c0826d16fd..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/accton_i2c_cpld.c +++ /dev/null @@ -1 +0,0 @@ -../../common/modules/accton_i2c_cpld.c \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-fan.c b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-fan.c deleted file mode 100644 index 3de2c200e1e1..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-fan.c +++ /dev/null @@ -1,466 +0,0 @@ -/* - * A hwmon driver for the Accton as7816-64x fan - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRVNAME "as7816_64x_fan" - -static struct as7816_64x_fan_data *as7816_64x_fan_update_device(struct device *dev); -static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); - -/* fan related data, the index should match sysfs_fan_attributes - */ -static const u8 fan_reg[] = { - 0x80, /* fan 1-4 present status */ - 0x81, /* fan 1-4 direction(0:F2B 1:B2F) */ - 0x87, /* fan PWM(for all fan) */ - 0x90, /* front fan 1 speed(rpm) */ - 0x91, /* front fan 2 speed(rpm) */ - 0x92, /* front fan 3 speed(rpm) */ - 0x93, /* front fan 4 speed(rpm) */ - 0x98, /* rear fan 1 speed(rpm) */ - 0x99, /* rear fan 2 speed(rpm) */ - 0x9A, /* rear fan 3 speed(rpm) */ - 0x9B, /* rear fan 4 speed(rpm) */ -}; - -/* Each client has this additional data */ -struct as7816_64x_fan_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */ -}; - -enum fan_id { - FAN1_ID, - FAN2_ID, - FAN3_ID, - FAN4_ID -}; - -enum sysfs_fan_attributes { - FAN_PRESENT_REG, - FAN_DIRECTION_REG, - FAN_DUTY_CYCLE_PERCENTAGE, /* Only one CPLD register to control duty cycle for all fans */ - FAN1_FRONT_SPEED_RPM, - FAN2_FRONT_SPEED_RPM, - FAN3_FRONT_SPEED_RPM, - FAN4_FRONT_SPEED_RPM, - FAN1_REAR_SPEED_RPM, - FAN2_REAR_SPEED_RPM, - FAN3_REAR_SPEED_RPM, - FAN4_REAR_SPEED_RPM, - FAN1_DIRECTION, - FAN2_DIRECTION, - FAN3_DIRECTION, - FAN4_DIRECTION, - FAN1_PRESENT, - FAN2_PRESENT, - FAN3_PRESENT, - FAN4_PRESENT, - FAN1_FAULT, - FAN2_FAULT, - FAN3_FAULT, - FAN4_FAULT -}; - -/* Define attributes - */ -#define DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(index, index2) \ - static SENSOR_DEVICE_ATTR(fan##index##_fault, S_IRUGO, fan_show_value, NULL, FAN##index##_FAULT);\ - static SENSOR_DEVICE_ATTR(fan##index2##_fault, S_IRUGO, fan_show_value, NULL, FAN##index##_FAULT) -#define DECLARE_FAN_FAULT_ATTR(index, index2) &sensor_dev_attr_fan##index##_fault.dev_attr.attr, \ - &sensor_dev_attr_fan##index2##_fault.dev_attr.attr - -#define DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan##index##_direction, S_IRUGO, fan_show_value, NULL, FAN##index##_DIRECTION) -#define DECLARE_FAN_DIRECTION_ATTR(index) &sensor_dev_attr_fan##index##_direction.dev_attr.attr - -#define DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE);\ - static SENSOR_DEVICE_ATTR(pwm##index, S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE) - -#define DECLARE_FAN_DUTY_CYCLE_ATTR(index) &sensor_dev_attr_fan_duty_cycle_percentage.dev_attr.attr, \ - &sensor_dev_attr_pwm##index.dev_attr.attr - - -#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \ - static SENSOR_DEVICE_ATTR(fan##index##_present, S_IRUGO, fan_show_value, NULL, FAN##index##_PRESENT) -#define DECLARE_FAN_PRESENT_ATTR(index) &sensor_dev_attr_fan##index##_present.dev_attr.attr - -#define DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(index, index2) \ - static SENSOR_DEVICE_ATTR(fan##index##_front_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_FRONT_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index##_rear_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_REAR_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index##_input, S_IRUGO, fan_show_value, NULL, FAN##index##_FRONT_SPEED_RPM);\ - static SENSOR_DEVICE_ATTR(fan##index2##_input, S_IRUGO, fan_show_value, NULL, FAN##index##_REAR_SPEED_RPM) -#define DECLARE_FAN_SPEED_RPM_ATTR(index, index2) &sensor_dev_attr_fan##index##_front_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_fan##index##_rear_speed_rpm.dev_attr.attr, \ - &sensor_dev_attr_fan##index##_input.dev_attr.attr, \ - &sensor_dev_attr_fan##index2##_input.dev_attr.attr - -/* 6 fan fault attributes in this platform */ -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(1,11); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(2,12); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(3,13); -DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(4,14); -/* 6 fan speed(rpm) attributes in this platform */ -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(1,11); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(2,12); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(3,13); -DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(4,14); -/* 6 fan present attributes in this platform */ -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(1); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(2); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(3); -DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(4); -/* 6 fan direction attribute in this platform */ -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(1); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(2); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(3); -DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(4); -/* 1 fan duty cycle attribute in this platform */ -DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(1); - -static struct attribute *as7816_64x_fan_attributes[] = { - /* fan related attributes */ - DECLARE_FAN_FAULT_ATTR(1,11), - DECLARE_FAN_FAULT_ATTR(2,12), - DECLARE_FAN_FAULT_ATTR(3,13), - DECLARE_FAN_FAULT_ATTR(4,14), - DECLARE_FAN_SPEED_RPM_ATTR(1,11), - DECLARE_FAN_SPEED_RPM_ATTR(2,12), - DECLARE_FAN_SPEED_RPM_ATTR(3,13), - DECLARE_FAN_SPEED_RPM_ATTR(4,14), - DECLARE_FAN_PRESENT_ATTR(1), - DECLARE_FAN_PRESENT_ATTR(2), - DECLARE_FAN_PRESENT_ATTR(3), - DECLARE_FAN_PRESENT_ATTR(4), - DECLARE_FAN_DIRECTION_ATTR(1), - DECLARE_FAN_DIRECTION_ATTR(2), - DECLARE_FAN_DIRECTION_ATTR(3), - DECLARE_FAN_DIRECTION_ATTR(4), - DECLARE_FAN_DUTY_CYCLE_ATTR(1), - NULL -}; - -#define FAN_DUTY_CYCLE_REG_MASK 0xF -#define FAN_MAX_DUTY_CYCLE 100 -#define FAN_REG_VAL_TO_SPEED_RPM_STEP 100 - -static int as7816_64x_fan_read_value(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_byte_data(client, reg); -} - -static int as7816_64x_fan_write_value(struct i2c_client *client, u8 reg, u8 value) -{ - return i2c_smbus_write_byte_data(client, reg, value); -} - -/* fan utility functions - */ -static u32 reg_val_to_duty_cycle(u8 reg_val) -{ - reg_val &= FAN_DUTY_CYCLE_REG_MASK; - - if (!reg_val) { - return 0; - } - - if (reg_val == 0xF) { - return FAN_MAX_DUTY_CYCLE; - } - - return (reg_val * 6) + 10; -} - -static u8 duty_cycle_to_reg_val(u8 duty_cycle) -{ - if (duty_cycle < 16) { - return 0; - } - - if (duty_cycle >= 100) { - return 0xF; - } - - return (duty_cycle - 10) / 6; -} - -static u32 reg_val_to_speed_rpm(u8 reg_val) -{ - return (u32)reg_val * FAN_REG_VAL_TO_SPEED_RPM_STEP; -} - -static u8 reg_val_to_direction(u8 reg_val, enum fan_id id) -{ - u8 mask = (1 << id); - return !!(reg_val & mask); -} - -static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id) -{ - u8 mask = (1 << id); - return !(reg_val & mask); -} - -static u8 is_fan_fault(struct as7816_64x_fan_data *data, enum fan_id id) -{ - u8 ret = 1; - int front_fan_index = FAN1_FRONT_SPEED_RPM + id; - int rear_fan_index = FAN1_REAR_SPEED_RPM + id; - - /* Check if the speed of front or rear fan is ZERO, - */ - if (reg_val_to_speed_rpm(data->reg_val[front_fan_index]) && - reg_val_to_speed_rpm(data->reg_val[rear_fan_index])) { - ret = 0; - } - - return ret; -} - -static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - int error, value; - struct i2c_client *client = to_i2c_client(dev); - - error = kstrtoint(buf, 10, &value); - if (error) - return error; - - if (value < 0 || value > FAN_MAX_DUTY_CYCLE) - return -EINVAL; - - as7816_64x_fan_write_value(client, 0x28, 0); /* Disable fan speed watch dog */ - as7816_64x_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value)); - return count; -} - -static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as7816_64x_fan_data *data = as7816_64x_fan_update_device(dev); - ssize_t ret = 0; - - if (data->valid) { - switch (attr->index) { - case FAN_DUTY_CYCLE_PERCENTAGE: - { - u32 duty_cycle = reg_val_to_duty_cycle(data->reg_val[FAN_DUTY_CYCLE_PERCENTAGE]); - ret = sprintf(buf, "%u\n", duty_cycle); - break; - } - case FAN1_FRONT_SPEED_RPM: - case FAN2_FRONT_SPEED_RPM: - case FAN3_FRONT_SPEED_RPM: - case FAN4_FRONT_SPEED_RPM: - case FAN1_REAR_SPEED_RPM: - case FAN2_REAR_SPEED_RPM: - case FAN3_REAR_SPEED_RPM: - case FAN4_REAR_SPEED_RPM: - { - ret = sprintf(buf, "%u\n", reg_val_to_speed_rpm(data->reg_val[attr->index])); - break; - } - case FAN1_PRESENT: - case FAN2_PRESENT: - case FAN3_PRESENT: - case FAN4_PRESENT: - ret = sprintf(buf, "%d\n", - reg_val_to_is_present(data->reg_val[FAN_PRESENT_REG], - attr->index - FAN1_PRESENT)); - break; - case FAN1_FAULT: - case FAN2_FAULT: - case FAN3_FAULT: - case FAN4_FAULT: - ret = sprintf(buf, "%d\n", is_fan_fault(data, attr->index - FAN1_FAULT)); - break; - case FAN1_DIRECTION: - case FAN2_DIRECTION: - case FAN3_DIRECTION: - case FAN4_DIRECTION: - ret = sprintf(buf, "%d\n", - reg_val_to_direction(data->reg_val[FAN_DIRECTION_REG], - attr->index - FAN1_DIRECTION)); - break; - default: - break; - } - } - - return ret; -} - -static const struct attribute_group as7816_64x_fan_group = { - .attrs = as7816_64x_fan_attributes, -}; - -static struct as7816_64x_fan_data *as7816_64x_fan_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7816_64x_fan_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || - !data->valid) { - int i; - - dev_dbg(&client->dev, "Starting as7816_64x_fan update\n"); - data->valid = 0; - - /* Update fan data - */ - for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) { - int status = as7816_64x_fan_read_value(client, fan_reg[i]); - - if (status < 0) { - data->valid = 0; - mutex_unlock(&data->update_lock); - dev_dbg(&client->dev, "reg %d, err %d\n", fan_reg[i], status); - return data; - } - else { - data->reg_val[i] = status; - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -static int as7816_64x_fan_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7816_64x_fan_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7816_64x_fan_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7816_64x_fan_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: fan '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7816_64x_fan_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7816_64x_fan_remove(struct i2c_client *client) -{ - struct as7816_64x_fan_data *data = i2c_get_clientdata(client); - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7816_64x_fan_group); - - return 0; -} - -/* Addresses to scan */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -static const struct i2c_device_id as7816_64x_fan_id[] = { - { "as7816_64x_fan", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7816_64x_fan_id); - -static struct i2c_driver as7816_64x_fan_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = DRVNAME, - }, - .probe = as7816_64x_fan_probe, - .remove = as7816_64x_fan_remove, - .id_table = as7816_64x_fan_id, - .address_list = normal_i2c, -}; - -static int __init as7816_64x_fan_init(void) -{ - return i2c_add_driver(&as7816_64x_fan_driver); -} - -static void __exit as7816_64x_fan_exit(void) -{ - i2c_del_driver(&as7816_64x_fan_driver); -} - -module_init(as7816_64x_fan_init); -module_exit(as7816_64x_fan_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7816_64x_fan driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-leds.c b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-leds.c deleted file mode 100644 index 025f87d692a3..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-leds.c +++ /dev/null @@ -1,460 +0,0 @@ -/* - * A LED driver for the as7816_64x_led - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/*#define DEBUG*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -extern int accton_i2c_cpld_read (u8 cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -extern void led_classdev_unregister(struct led_classdev *led_cdev); -extern int led_classdev_register(struct device *parent, struct led_classdev *led_cdev); -extern void led_classdev_resume(struct led_classdev *led_cdev); -extern void led_classdev_suspend(struct led_classdev *led_cdev); - -#define DRVNAME "as7816_64x_led" - -struct as7816_64x_led_data { - struct platform_device *pdev; - struct mutex update_lock; - char valid; /* != 0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 reg_val[1]; /* only 1 register*/ -}; - -static struct as7816_64x_led_data *ledctl = NULL; - -/* LED related data - */ - -#define LED_CNTRLER_I2C_ADDRESS (0x60) - -#define LED_TYPE_DIAG_REG_MASK (0x03) -#define LED_MODE_DIAG_YELLOW_VALUE (0x00) -#define LED_MODE_DIAG_RED_VALUE (0x01) -#define LED_MODE_DIAG_GREEN_VALUE (0x02) -#define LED_MODE_DIAG_OFF_VALUE (0x03) - -#define LED_TYPE_LOC_REG_MASK (0x10) -#define LED_MODE_LOC_ORANGE_VALUE (0x00) -#define LED_MODE_LOC_OFF_VALUE (0x10) - -#define LED_TYPE_FAN_REG_MASK (0x0C) -#define LED_MODE_FAN_ORANGE_VALUE (0x04) -#define LED_MODE_FAN_GREEN_VALUE_1 (0x00) -#define LED_MODE_FAN_GREEN_VALUE_2 (0x08) -#define LED_MODE_FAN_OFF_VALUE (0x0C) - -enum led_type { - LED_TYPE_DIAG, - LED_TYPE_LOC, - LED_TYPE_FAN, - LED_TYPE_PSU1, - LED_TYPE_PSU2 -}; - -struct led_reg { - u32 types; - u8 reg_addr; -}; - -static const struct led_reg led_reg_map[] = { - {(1 << LED_TYPE_LOC) | (1 << LED_TYPE_DIAG) | (1 << LED_TYPE_FAN), 0x30}, -}; - -enum led_light_mode { - LED_MODE_OFF, - LED_MODE_RED = 10, - LED_MODE_RED_BLINKING = 11, - LED_MODE_ORANGE = 12, - LED_MODE_ORANGE_BLINKING = 13, - LED_MODE_YELLOW = 14, - LED_MODE_YELLOW_BLINKING = 15, - LED_MODE_GREEN = 16, - LED_MODE_GREEN_BLINKING = 17, - LED_MODE_BLUE = 18, - LED_MODE_BLUE_BLINKING = 19, - LED_MODE_PURPLE = 20, - LED_MODE_PURPLE_BLINKING = 21, - LED_MODE_AUTO = 22, - LED_MODE_AUTO_BLINKING = 23, - LED_MODE_WHITE = 24, - LED_MODE_WHITE_BLINKING = 25, - LED_MODE_CYAN = 26, - LED_MODE_CYAN_BLINKING = 27, - LED_MODE_UNKNOWN = 99 -}; - -struct led_type_mode { - enum led_type type; - enum led_light_mode mode; - int reg_bit_mask; - int mode_value; -}; - -static struct led_type_mode led_type_mode_data[] = { -{LED_TYPE_LOC, LED_MODE_OFF, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_OFF_VALUE}, -{LED_TYPE_LOC, LED_MODE_ORANGE,LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_ORANGE_VALUE}, -{LED_TYPE_DIAG, LED_MODE_OFF, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_OFF_VALUE}, -{LED_TYPE_DIAG, LED_MODE_GREEN, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_VALUE}, -{LED_TYPE_DIAG, LED_MODE_RED, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_RED_VALUE}, -{LED_TYPE_DIAG, LED_MODE_YELLOW,LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_YELLOW_VALUE}, -{LED_TYPE_FAN, LED_MODE_OFF, LED_TYPE_FAN_REG_MASK, LED_MODE_FAN_OFF_VALUE}, -{LED_TYPE_FAN, LED_MODE_GREEN, LED_TYPE_FAN_REG_MASK, LED_MODE_FAN_GREEN_VALUE_1}, -{LED_TYPE_FAN, LED_MODE_GREEN, LED_TYPE_FAN_REG_MASK, LED_MODE_FAN_GREEN_VALUE_2}, -{LED_TYPE_FAN, LED_MODE_ORANGE,LED_TYPE_FAN_REG_MASK, LED_MODE_FAN_ORANGE_VALUE} -}; - -static int get_led_reg(enum led_type type, u8 *reg) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(led_reg_map); i++) { - if(led_reg_map[i].types & (1 << type)) { - *reg = led_reg_map[i].reg_addr; - return 0; - } - } - - return 1; -} - -static int led_reg_val_to_light_mode(enum led_type type, u8 reg_val) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) { - - if (type != led_type_mode_data[i].type) - continue; - - if ((led_type_mode_data[i].reg_bit_mask & reg_val) == - led_type_mode_data[i].mode_value) - { - return led_type_mode_data[i].mode; - } - } - - return 0; -} - -static u8 led_light_mode_to_reg_val(enum led_type type, - enum led_light_mode mode, u8 reg_val) { - int i; - - for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) { - if (type != led_type_mode_data[i].type) - continue; - - if (mode != led_type_mode_data[i].mode) - continue; - - reg_val = led_type_mode_data[i].mode_value | - (reg_val & (~led_type_mode_data[i].reg_bit_mask)); - break; - } - - return reg_val; -} - -static int as7816_64x_led_read_value(u8 reg) -{ - return accton_i2c_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); -} - -static int as7816_64x_led_write_value(u8 reg, u8 value) -{ - return accton_i2c_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); -} - -static void as7816_64x_led_update(void) -{ - mutex_lock(&ledctl->update_lock); - - if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2) - || !ledctl->valid) { - int i; - - dev_dbg(&ledctl->pdev->dev, "Starting as7816_64x_led update\n"); - - /* Update LED data - */ - for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { - int status = as7816_64x_led_read_value(led_reg_map[i].reg_addr); - - if (status < 0) { - ledctl->valid = 0; - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg_map[i].reg_addr, status); - goto exit; - } - else - { - ledctl->reg_val[i] = status; - } - } - - ledctl->last_updated = jiffies; - ledctl->valid = 1; - } - -exit: - mutex_unlock(&ledctl->update_lock); -} - -static void as7816_64x_led_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode, - enum led_type type) -{ - int reg_val; - u8 reg ; - mutex_lock(&ledctl->update_lock); - - if( !get_led_reg(type, ®)) { - dev_dbg(&ledctl->pdev->dev, "Not match register for %d.\n", type); - } - - reg_val = as7816_64x_led_read_value(reg); - if (reg_val < 0) { - dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val); - goto exit; - } - - reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val); - as7816_64x_led_write_value(reg, reg_val); - - /* to prevent the slow-update issue */ - ledctl->valid = 0; - -exit: - mutex_unlock(&ledctl->update_lock); -} - - -static void as7816_64x_led_diag_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - as7816_64x_led_set(led_cdev, led_light_mode, LED_TYPE_DIAG); -} - -static enum led_brightness as7816_64x_led_diag_get(struct led_classdev *cdev) -{ - as7816_64x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); -} - -static void as7816_64x_led_loc_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - as7816_64x_led_set(led_cdev, led_light_mode, LED_TYPE_LOC); -} - -static enum led_brightness as7816_64x_led_loc_get(struct led_classdev *cdev) -{ - as7816_64x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); -} - -static void as7816_64x_led_fan_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ - as7816_64x_led_set(led_cdev, led_light_mode, LED_TYPE_FAN); -} - -static enum led_brightness as7816_64x_led_fan_get(struct led_classdev *cdev) -{ - as7816_64x_led_update(); - return led_reg_val_to_light_mode(LED_TYPE_FAN, ledctl->reg_val[0]); -} - -static void as7816_64x_led_auto_set(struct led_classdev *led_cdev, - enum led_brightness led_light_mode) -{ -} - -static enum led_brightness as7816_64x_led_auto_get(struct led_classdev *cdev) -{ - return LED_MODE_AUTO; -} - -static struct led_classdev as7816_64x_leds[] = { - [LED_TYPE_DIAG] = { - .name = "as7816_64x_led::diag", - .default_trigger = "unused", - .brightness_set = as7816_64x_led_diag_set, - .brightness_get = as7816_64x_led_diag_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_GREEN, - }, - [LED_TYPE_LOC] = { - .name = "as7816_64x_led::loc", - .default_trigger = "unused", - .brightness_set = as7816_64x_led_loc_set, - .brightness_get = as7816_64x_led_loc_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_ORANGE, - }, - [LED_TYPE_FAN] = { - .name = "as7816_64x_led::fan", - .default_trigger = "unused", - .brightness_set = as7816_64x_led_fan_set, - .brightness_get = as7816_64x_led_fan_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_GREEN, - }, - [LED_TYPE_PSU1] = { - .name = "as7816_64x_led::psu1", - .default_trigger = "unused", - .brightness_set = as7816_64x_led_auto_set, - .brightness_get = as7816_64x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, - [LED_TYPE_PSU2] = { - .name = "as7816_64x_led::psu2", - .default_trigger = "unused", - .brightness_set = as7816_64x_led_auto_set, - .brightness_get = as7816_64x_led_auto_get, - .flags = LED_CORE_SUSPENDRESUME, - .max_brightness = LED_MODE_AUTO, - }, -}; - -static int as7816_64x_led_suspend(struct platform_device *dev, - pm_message_t state) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(as7816_64x_leds); i++) { - led_classdev_suspend(&as7816_64x_leds[i]); - } - - return 0; -} - -static int as7816_64x_led_resume(struct platform_device *dev) -{ - int i = 0; - - for (i = 0; i < ARRAY_SIZE(as7816_64x_leds); i++) { - led_classdev_resume(&as7816_64x_leds[i]); - } - - return 0; -} - -static int as7816_64x_led_probe(struct platform_device *pdev) -{ - int ret, i; - - for (i = 0; i < ARRAY_SIZE(as7816_64x_leds); i++) { - ret = led_classdev_register(&pdev->dev, &as7816_64x_leds[i]); - - if (ret < 0) - break; - } - - /* Check if all LEDs were successfully registered */ - if (i != ARRAY_SIZE(as7816_64x_leds)){ - int j; - - /* only unregister the LEDs that were successfully registered */ - for (j = 0; j < i; j++) { - led_classdev_unregister(&as7816_64x_leds[i]); - } - } - - return ret; -} - -static int as7816_64x_led_remove(struct platform_device *pdev) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(as7816_64x_leds); i++) { - led_classdev_unregister(&as7816_64x_leds[i]); - } - - return 0; -} - -static struct platform_driver as7816_64x_led_driver = { - .probe = as7816_64x_led_probe, - .remove = as7816_64x_led_remove, - .suspend = as7816_64x_led_suspend, - .resume = as7816_64x_led_resume, - .driver = { - .name = DRVNAME, - .owner = THIS_MODULE, - }, -}; - -static int __init as7816_64x_led_init(void) -{ - int ret; - - ret = platform_driver_register(&as7816_64x_led_driver); - if (ret < 0) { - goto exit; - } - - ledctl = kzalloc(sizeof(struct as7816_64x_led_data), GFP_KERNEL); - if (!ledctl) { - ret = -ENOMEM; - platform_driver_unregister(&as7816_64x_led_driver); - goto exit; - } - - mutex_init(&ledctl->update_lock); - - ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); - if (IS_ERR(ledctl->pdev)) { - ret = PTR_ERR(ledctl->pdev); - platform_driver_unregister(&as7816_64x_led_driver); - kfree(ledctl); - goto exit; - } - -exit: - return ret; -} - -static void __exit as7816_64x_led_exit(void) -{ - platform_device_unregister(ledctl->pdev); - platform_driver_unregister(&as7816_64x_led_driver); - kfree(ledctl); -} - -module_init(as7816_64x_led_init); -module_exit(as7816_64x_led_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7816_64x_led driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-psu.c b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-psu.c deleted file mode 100644 index cdc535347dc0..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-psu.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * An hwmon driver for accton as7816_64x Power Module - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define PSU_STATUS_I2C_ADDR 0x60 -#define PSU_STATUS_I2C_REG_OFFSET 0x03 - -#define IS_POWER_GOOD(id, value) (!!(value & BIT(2+id))) -#define IS_PRESENT(id, value) (!(value & BIT(id))) - -static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); -static struct as7816_64x_psu_data *as7816_64x_psu_update_device(struct device *dev); -extern int accton_i2c_cpld_read (u8 cpld_addr, u8 reg); - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as7816_64x_psu_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 index; /* PSU index */ - u8 status; /* Status(present/power_good) register read from CPLD */ -}; - -enum as7816_64x_psu_sysfs_attributes { - PSU_PRESENT, - PSU_POWER_GOOD -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD); - -static struct attribute *as7816_64x_psu_attributes[] = { - &sensor_dev_attr_psu_present.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - NULL -}; - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as7816_64x_psu_data *data = as7816_64x_psu_update_device(dev); - u8 status = 0; - - if (!data->valid) { - return -EIO; - } - - if (attr->index == PSU_PRESENT) { - status = IS_PRESENT(data->index, data->status); - } - else { /* PSU_POWER_GOOD */ - status = IS_POWER_GOOD(data->index, data->status); - } - - return sprintf(buf, "%d\n", status); -} - -static const struct attribute_group as7816_64x_psu_group = { - .attrs = as7816_64x_psu_attributes, -}; - -static int as7816_64x_psu_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7816_64x_psu_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7816_64x_psu_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - data->index = dev_id->driver_data; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7816_64x_psu_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7816_64x_psu_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7816_64x_psu_remove(struct i2c_client *client) -{ - struct as7816_64x_psu_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7816_64x_psu_group); - kfree(data); - - return 0; -} - -enum psu_index -{ - as7816_64x_psu1, - as7816_64x_psu2 -}; - -static const struct i2c_device_id as7816_64x_psu_id[] = { - { "as7816_64x_psu1", as7816_64x_psu1 }, - { "as7816_64x_psu2", as7816_64x_psu2 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7816_64x_psu_id); - -static struct i2c_driver as7816_64x_psu_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7816_64x_psu", - }, - .probe = as7816_64x_psu_probe, - .remove = as7816_64x_psu_remove, - .id_table = as7816_64x_psu_id, - .address_list = normal_i2c, -}; - -static struct as7816_64x_psu_data *as7816_64x_psu_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7816_64x_psu_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int status; - - data->valid = 0; - dev_dbg(&client->dev, "Starting as7816_64x update\n"); - - /* Read psu status */ - status = accton_i2c_cpld_read(PSU_STATUS_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET); - - if (status < 0) { - dev_dbg(&client->dev, "cpld reg (0x%x) err %d\n", PSU_STATUS_I2C_ADDR, status); - goto exit; - } - else { - data->status = status; - } - - data->last_updated = jiffies; - data->valid = 1; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init as7816_64x_psu_init(void) -{ - return i2c_add_driver(&as7816_64x_psu_driver); -} - -static void __exit as7816_64x_psu_exit(void) -{ - i2c_del_driver(&as7816_64x_psu_driver); -} - -module_init(as7816_64x_psu_init); -module_exit(as7816_64x_psu_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7816_64x_psu driver"); -MODULE_LICENSE("GPL"); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-sfp.c b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-sfp.c deleted file mode 100644 index 76444ebbafcb..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/x86-64-accton-as7816-64x-sfp.c +++ /dev/null @@ -1,1576 +0,0 @@ -/* - * SFP driver for accton as7816_64x sfp - * - * Copyright (C) Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRIVER_NAME "as7816_64x_sfp" /* Platform dependent */ - -#define DEBUG_MODE 0 - -#if (DEBUG_MODE == 1) - #define DEBUG_PRINT(fmt, args...) \ - printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) -#else - #define DEBUG_PRINT(fmt, args...) -#endif - -#define NUM_OF_SFP_PORT 24 -#define EEPROM_NAME "sfp_eeprom" -#define EEPROM_SIZE 256 /* 256 byte eeprom */ -#define BIT_INDEX(i) (1ULL << (i)) -#define USE_I2C_BLOCK_READ 1 /* Platform dependent */ -#define I2C_RW_RETRY_COUNT 10 -#define I2C_RW_RETRY_INTERVAL 60 /* ms */ - -#define SFP_EEPROM_A0_I2C_ADDR (0xA0 >> 1) - -#define SFF8024_PHYSICAL_DEVICE_ID_ADDR 0x0 -#define SFF8024_DEVICE_ID_SFP 0x3 -#define SFF8024_DEVICE_ID_QSFP 0xC -#define SFF8024_DEVICE_ID_QSFP_PLUS 0xD -#define SFF8024_DEVICE_ID_QSFP28 0x11 - -#define SFF8436_RX_LOS_ADDR 3 -#define SFF8436_TX_FAULT_ADDR 4 -#define SFF8436_TX_DISABLE_ADDR 86 - -#define MULTIPAGE_SUPPORT 1 - -#if (MULTIPAGE_SUPPORT == 1) -/* fundamental unit of addressing for SFF_8472/SFF_8436 */ -#define SFF_8436_PAGE_SIZE 128 -/* - * The current 8436 (QSFP) spec provides for only 4 supported - * pages (pages 0-3). - * This driver is prepared to support more, but needs a register in the - * EEPROM to indicate how many pages are supported before it is safe - * to implement more pages in the driver. - */ -#define SFF_8436_SPECED_PAGES 4 -#define SFF_8436_EEPROM_SIZE ((1 + SFF_8436_SPECED_PAGES) * SFF_8436_PAGE_SIZE) -#define SFF_8436_EEPROM_UNPAGED_SIZE (2 * SFF_8436_PAGE_SIZE) -/* - * The current 8472 (SFP) spec provides for only 3 supported - * pages (pages 0-2). - * This driver is prepared to support more, but needs a register in the - * EEPROM to indicate how many pages are supported before it is safe - * to implement more pages in the driver. - */ -#define SFF_8472_SPECED_PAGES 3 -#define SFF_8472_EEPROM_SIZE ((3 + SFF_8472_SPECED_PAGES) * SFF_8436_PAGE_SIZE) -#define SFF_8472_EEPROM_UNPAGED_SIZE (4 * SFF_8436_PAGE_SIZE) - -/* a few constants to find our way around the EEPROM */ -#define SFF_8436_PAGE_SELECT_REG 0x7F -#define SFF_8436_PAGEABLE_REG 0x02 -#define SFF_8436_NOT_PAGEABLE (1<<2) -#define SFF_8472_PAGEABLE_REG 0x40 -#define SFF_8472_PAGEABLE (1<<4) - -/* - * This parameter is to help this driver avoid blocking other drivers out - * of I2C for potentially troublesome amounts of time. With a 100 kHz I2C - * clock, one 256 byte read takes about 1/43 second which is excessive; - * but the 1/170 second it takes at 400 kHz may be quite reasonable; and - * at 1 MHz (Fm+) a 1/430 second delay could easily be invisible. - * - * This value is forced to be a power of two so that writes align on pages. - */ -static unsigned io_limit = SFF_8436_PAGE_SIZE; - -/* - * specs often allow 5 msec for a page write, sometimes 20 msec; - * it's important to recover from write timeouts. - */ -static unsigned write_timeout = 25; - -typedef enum qsfp_opcode { - QSFP_READ_OP = 0, - QSFP_WRITE_OP = 1 -} qsfp_opcode_e; -#endif - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_present(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count);; -static ssize_t sfp_eeprom_read(struct i2c_client *, u8, u8 *,int); -static ssize_t sfp_eeprom_write(struct i2c_client *, u8 , const char *,int); -extern int accton_i2c_cpld_read (u8 cpld_addr, u8 reg); - -enum sfp_sysfs_attributes { - PRESENT, - PRESENT_ALL, - PORT_NUMBER, - PORT_TYPE, - DDM_IMPLEMENTED, - TX_FAULT, - TX_FAULT1, - TX_FAULT2, - TX_FAULT3, - TX_FAULT4, - TX_DISABLE, - TX_DISABLE1, - TX_DISABLE2, - TX_DISABLE3, - TX_DISABLE4, - RX_LOS, - RX_LOS1, - RX_LOS2, - RX_LOS3, - RX_LOS4, - RX_LOS_ALL -}; - -/* SFP/QSFP common attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, PRESENT); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, PRESENT_ALL); -static SENSOR_DEVICE_ATTR(sfp_tx_disable, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE); -static SENSOR_DEVICE_ATTR(sfp_tx_fault, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT); - -/* QSFP attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_rx_los, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS); -static SENSOR_DEVICE_ATTR(sfp_rx_los1, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS1); -static SENSOR_DEVICE_ATTR(sfp_rx_los2, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS2); -static SENSOR_DEVICE_ATTR(sfp_rx_los3, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS3); -static SENSOR_DEVICE_ATTR(sfp_rx_los4, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS4); -static SENSOR_DEVICE_ATTR(sfp_tx_disable1, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE1); -static SENSOR_DEVICE_ATTR(sfp_tx_disable2, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE2); -static SENSOR_DEVICE_ATTR(sfp_tx_disable3, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE3); -static SENSOR_DEVICE_ATTR(sfp_tx_disable4, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE4); -static SENSOR_DEVICE_ATTR(sfp_tx_fault1, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT1); -static SENSOR_DEVICE_ATTR(sfp_tx_fault2, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT2); -static SENSOR_DEVICE_ATTR(sfp_tx_fault3, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT3); -static SENSOR_DEVICE_ATTR(sfp_tx_fault4, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT4); -static struct attribute *qsfp_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los1.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los2.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los3.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault4.dev_attr.attr, - NULL -}; - -/* Platform dependent +++ */ -#define CPLD_PORT_TO_FRONT_PORT(port) (port+1) - -enum port_numbers { -as7816_64x_port1, as7816_64x_port2, as7816_64x_port3, as7816_64x_port4, -as7816_64x_port5, as7816_64x_port6, as7816_64x_port7, as7816_64x_port8, -as7816_64x_port9, as7816_64x_port10, as7816_64x_port11, as7816_64x_port12, -as7816_64x_port13, as7816_64x_port14, as7816_64x_port15, as7816_64x_port16, -as7816_64x_port17, as7816_64x_port18, as7816_64x_port19, as7816_64x_port20, -as7816_64x_port21, as7816_64x_port22, as7816_64x_port23, as7816_64x_port24, -as7816_64x_port25, as7816_64x_port26, as7816_64x_port27, as7816_64x_port28, -as7816_64x_port29, as7816_64x_port30, as7816_64x_port31, as7816_64x_port32, -as7816_64x_port33, as7816_64x_port34, as7816_64x_port35, as7816_64x_port36, -as7816_64x_port37, as7816_64x_port38, as7816_64x_port39, as7816_64x_port40, -as7816_64x_port41, as7816_64x_port42, as7816_64x_port43, as7816_64x_port44, -as7816_64x_port45, as7816_64x_port46, as7816_64x_port47, as7816_64x_port48, -as7816_64x_port49, as7816_64x_port50, as7816_64x_port51, as7816_64x_port52, -as7816_64x_port53, as7816_64x_port54, as7816_64x_port55, as7816_64x_port56, -as7816_64x_port57, as7816_64x_port58, as7816_64x_port59, as7816_64x_port60, -as7816_64x_port61, as7816_64x_port62, as7816_64x_port63, as7816_64x_port64 -}; - -#define I2C_DEV_ID(x) { #x, x} - -static const struct i2c_device_id sfp_device_id[] = { -I2C_DEV_ID(as7816_64x_port1), -I2C_DEV_ID(as7816_64x_port2), -I2C_DEV_ID(as7816_64x_port3), -I2C_DEV_ID(as7816_64x_port4), -I2C_DEV_ID(as7816_64x_port5), -I2C_DEV_ID(as7816_64x_port6), -I2C_DEV_ID(as7816_64x_port7), -I2C_DEV_ID(as7816_64x_port8), -I2C_DEV_ID(as7816_64x_port9), -I2C_DEV_ID(as7816_64x_port10), -I2C_DEV_ID(as7816_64x_port11), -I2C_DEV_ID(as7816_64x_port12), -I2C_DEV_ID(as7816_64x_port13), -I2C_DEV_ID(as7816_64x_port14), -I2C_DEV_ID(as7816_64x_port15), -I2C_DEV_ID(as7816_64x_port16), -I2C_DEV_ID(as7816_64x_port17), -I2C_DEV_ID(as7816_64x_port18), -I2C_DEV_ID(as7816_64x_port19), -I2C_DEV_ID(as7816_64x_port20), -I2C_DEV_ID(as7816_64x_port21), -I2C_DEV_ID(as7816_64x_port22), -I2C_DEV_ID(as7816_64x_port23), -I2C_DEV_ID(as7816_64x_port24), -I2C_DEV_ID(as7816_64x_port25), -I2C_DEV_ID(as7816_64x_port26), -I2C_DEV_ID(as7816_64x_port27), -I2C_DEV_ID(as7816_64x_port28), -I2C_DEV_ID(as7816_64x_port29), -I2C_DEV_ID(as7816_64x_port30), -I2C_DEV_ID(as7816_64x_port31), -I2C_DEV_ID(as7816_64x_port32), -I2C_DEV_ID(as7816_64x_port33), -I2C_DEV_ID(as7816_64x_port34), -I2C_DEV_ID(as7816_64x_port35), -I2C_DEV_ID(as7816_64x_port36), -I2C_DEV_ID(as7816_64x_port37), -I2C_DEV_ID(as7816_64x_port38), -I2C_DEV_ID(as7816_64x_port39), -I2C_DEV_ID(as7816_64x_port40), -I2C_DEV_ID(as7816_64x_port41), -I2C_DEV_ID(as7816_64x_port42), -I2C_DEV_ID(as7816_64x_port43), -I2C_DEV_ID(as7816_64x_port44), -I2C_DEV_ID(as7816_64x_port45), -I2C_DEV_ID(as7816_64x_port46), -I2C_DEV_ID(as7816_64x_port47), -I2C_DEV_ID(as7816_64x_port48), -I2C_DEV_ID(as7816_64x_port49), -I2C_DEV_ID(as7816_64x_port50), -I2C_DEV_ID(as7816_64x_port51), -I2C_DEV_ID(as7816_64x_port52), -I2C_DEV_ID(as7816_64x_port53), -I2C_DEV_ID(as7816_64x_port54), -I2C_DEV_ID(as7816_64x_port55), -I2C_DEV_ID(as7816_64x_port56), -I2C_DEV_ID(as7816_64x_port57), -I2C_DEV_ID(as7816_64x_port58), -I2C_DEV_ID(as7816_64x_port59), -I2C_DEV_ID(as7816_64x_port60), -I2C_DEV_ID(as7816_64x_port61), -I2C_DEV_ID(as7816_64x_port62), -I2C_DEV_ID(as7816_64x_port63), -I2C_DEV_ID(as7816_64x_port64), -{ /* LIST END */ } -}; -MODULE_DEVICE_TABLE(i2c, sfp_device_id); -/* Platform dependent --- */ - -enum driver_type_e { - DRIVER_TYPE_SFP_MSA, - DRIVER_TYPE_SFP_DDM, - DRIVER_TYPE_QSFP, - DRIVER_TYPE_XFP -}; - -/* Each client has this additional data - */ -struct eeprom_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - struct bin_attribute bin; /* eeprom data */ -}; - -struct qsfp_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 status[3]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss */ - u8 device_id; - struct eeprom_data eeprom; -}; - -struct sfp_port_data { - struct mutex update_lock; - enum driver_type_e driver_type; - int port; /* CPLD port index */ - u64 present; /* present status, bit0:port0, bit1:port1 and so on */ - - struct qsfp_data *qsfp; - - struct i2c_client *client; -#if (MULTIPAGE_SUPPORT == 1) - int use_smbus; - u8 *writebuf; - unsigned write_max; -#endif -}; - -#if (MULTIPAGE_SUPPORT == 1) -static ssize_t sfp_port_read_write(struct sfp_port_data *port_data, - char *buf, loff_t off, size_t len, qsfp_opcode_e opcode); -#endif -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - return sprintf(buf, "%d\n", CPLD_PORT_TO_FRONT_PORT(data->port)); -} - -/* Platform dependent +++ */ -static struct sfp_port_data *sfp_update_present(struct i2c_client *client) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - int i = 0; - int status = -1; - u8 regs[] = {0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77}; - - DEBUG_PRINT("Starting sfp present status update"); - mutex_lock(&data->update_lock); - - /* Read present status of port 1~64 */ - data->present = 0; - - for (i = 0; i < ARRAY_SIZE(regs); i++) { - status = accton_i2c_cpld_read(0x60, regs[i]); - - if (status < 0) { - DEBUG_PRINT("cpld(0x60) reg(0x%x) err %d", regs[i], status); - goto exit; - } - - DEBUG_PRINT("Present status = 0x%lx", data->present); - data->present |= (u64)status << (i*8); - } - - DEBUG_PRINT("Present status = 0x%lx", data->present); -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -/* Platform dependent --- */ - -static int sfp_is_port_present(struct i2c_client *client, int port) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - - data = sfp_update_present(client); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - return (data->present & BIT_INDEX(data->port)) ? 0 : 1; /* Platform dependent */ -} - -/* Platform dependent +++ */ -static ssize_t show_present(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); - - if (PRESENT_ALL == attr->index) { - int i; - u8 values[8] = {0}; - struct sfp_port_data *data = sfp_update_present(client); - - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - for (i = 0; i < ARRAY_SIZE(values); i++) { - values[i] = ~(u8)(data->present >> (i * 8)); - } - - /* Return values 1 -> 64 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], values[3], - values[4], values[5], values[6], values[7]); - } - else { - struct sfp_port_data *data = i2c_get_clientdata(client); - int present = sfp_is_port_present(client, data->port); - - if (IS_ERR_VALUE(present)) { - return present; - } - - /* PRESENT */ - return sprintf(buf, "%d\n", present); - } -} -/* Platform dependent --- */ - -static struct sfp_port_data *qsfp_update_tx_rx_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int i, status = -1; - u8 buf = 0; - u8 reg[] = {SFF8436_TX_FAULT_ADDR, SFF8436_TX_DISABLE_ADDR, SFF8436_RX_LOS_ADDR}; - - if (time_before(jiffies, data->qsfp->last_updated + HZ + HZ / 2) && data->qsfp->valid) { - return data; - } - - DEBUG_PRINT("Starting sfp tx rx status update"); - mutex_lock(&data->update_lock); - data->qsfp->valid = 0; - memset(data->qsfp->status, 0, sizeof(data->qsfp->status)); - - /* Notify device to update tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - } - msleep(200); - - /* Read actual tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - - DEBUG_PRINT("qsfp reg(0x%x) status = (0x%x)", reg[i], data->qsfp->status[i]); - data->qsfp->status[i] = (buf & 0xF); - } - - data->qsfp->valid = 1; - data->qsfp->last_updated = jiffies; - -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - int present; - u8 val = 0; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - present = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENXIO; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - switch (attr->index) { - case TX_FAULT: - val = !!(data->qsfp->status[2] & 0xF); - break; - case TX_FAULT1: - case TX_FAULT2: - case TX_FAULT3: - case TX_FAULT4: - val = !!(data->qsfp->status[2] & BIT_INDEX(attr->index - TX_FAULT1)); - break; - case TX_DISABLE: - val = data->qsfp->status[1] & 0xF; - break; - case TX_DISABLE1: - case TX_DISABLE2: - case TX_DISABLE3: - case TX_DISABLE4: - val = !!(data->qsfp->status[1] & BIT_INDEX(attr->index - TX_DISABLE1)); - break; - case RX_LOS: - val = !!(data->qsfp->status[0] & 0xF); - break; - case RX_LOS1: - case RX_LOS2: - case RX_LOS3: - case RX_LOS4: - val = !!(data->qsfp->status[0] & BIT_INDEX(attr->index - RX_LOS1)); - break; - default: - break; - } - - return sprintf(buf, "%d\n", val); -} - -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - long disable; - int status; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - status = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(status)) { - return status; - } - - if (!status) { - /* port is not present */ - return -ENXIO; - } - - status = kstrtol(buf, 10, &disable); - if (status) { - return status; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - mutex_lock(&data->update_lock); - - if (attr->index == TX_DISABLE) { - if (disable) { - data->qsfp->status[1] |= 0xF; - } - else { - data->qsfp->status[1] &= ~0xF; - } - } - else {/* TX_DISABLE1 ~ TX_DISABLE4*/ - if (disable) { - data->qsfp->status[1] |= (1 << (attr->index - TX_DISABLE1)); - } - else { - data->qsfp->status[1] &= ~(1 << (attr->index - TX_DISABLE1)); - } - } - - DEBUG_PRINT("index = (%d), status = (0x%x)", attr->index, data->qsfp->status[1]); - status = sfp_eeprom_write(data->client, SFF8436_TX_DISABLE_ADDR, &data->qsfp->status[1], sizeof(data->qsfp->status[1])); - if (unlikely(status < 0)) { - count = status; - } - - mutex_unlock(&data->update_lock); - return count; -} - -static ssize_t sfp_eeprom_write(struct i2c_client *client, u8 command, const char *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_write_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return data_len; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, command, *data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return 1; -#endif - - -} - -#if (MULTIPAGE_SUPPORT == 0) -static ssize_t sfp_port_write(struct sfp_port_data *data, - const char *buf, loff_t off, size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) { - return count; - } - - /* - * Write data to chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_write(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; -} -#endif - -static ssize_t sfp_bin_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("%s(%d) offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - -#if (MULTIPAGE_SUPPORT == 1) - return sfp_port_read_write(data, buf, off, count, QSFP_WRITE_OP); -#else - return sfp_port_write(data, buf, off, count); -#endif -} - -static ssize_t sfp_eeprom_read(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - goto abort; - } - if (unlikely(status != data_len)) { - status = -EIO; - goto abort; - } - - //result = data_len; - -abort: - return status; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, command); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, status); - goto abort; - } - - *data = (u8)status; - status = 1; - -abort: - return status; -#endif -} - -#if (MULTIPAGE_SUPPORT == 1) -/*-------------------------------------------------------------------------*/ -/* - * This routine computes the addressing information to be used for - * a given r/w request. - * - * Task is to calculate the client (0 = i2c addr 50, 1 = i2c addr 51), - * the page, and the offset. - * - * Handles both SFP and QSFP. - * For SFP, offset 0-255 are on client[0], >255 is on client[1] - * Offset 256-383 are on the lower half of client[1] - * Pages are accessible on the upper half of client[1]. - * Offset >383 are in 128 byte pages mapped into the upper half - * - * For QSFP, all offsets are on client[0] - * offset 0-127 are on the lower half of client[0] (no paging) - * Pages are accessible on the upper half of client[1]. - * Offset >127 are in 128 byte pages mapped into the upper half - * - * Callers must not read/write beyond the end of a client or a page - * without recomputing the client/page. Hence offset (within page) - * plus length must be less than or equal to 128. (Note that this - * routine does not have access to the length of the call, hence - * cannot do the validity check.) - * - * Offset within Lower Page 00h and Upper Page 00h are not recomputed - */ -static uint8_t sff_8436_translate_offset(struct sfp_port_data *port_data, - loff_t *offset, struct i2c_client **client) -{ - unsigned page = 0; - - *client = port_data->client; - - /* - * if offset is in the range 0-128... - * page doesn't matter (using lower half), return 0. - * offset is already correct (don't add 128 to get to paged area) - */ - if (*offset < SFF_8436_PAGE_SIZE) - return page; - - /* note, page will always be positive since *offset >= 128 */ - page = (*offset >> 7)-1; - /* 0x80 places the offset in the top half, offset is last 7 bits */ - *offset = SFF_8436_PAGE_SIZE + (*offset & 0x7f); - - return page; /* note also returning client and offset */ -} - -static ssize_t sff_8436_eeprom_read(struct sfp_port_data *port_data, - struct i2c_client *client, - char *buf, unsigned offset, size_t count) -{ - struct i2c_msg msg[2]; - u8 msgbuf[2]; - unsigned long timeout, read_time; - int status, i; - - memset(msg, 0, sizeof(msg)); - - switch (port_data->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - /*smaller eeproms can work given some SMBus extension calls */ - if (count > I2C_SMBUS_BLOCK_MAX) - count = I2C_SMBUS_BLOCK_MAX; - break; - case I2C_SMBUS_WORD_DATA: - /* Check for odd length transaction */ - count = (count == 1) ? 1 : 2; - break; - case I2C_SMBUS_BYTE_DATA: - count = 1; - break; - default: - /* - * When we have a better choice than SMBus calls, use a - * combined I2C message. Write address; then read up to - * io_limit data bytes. msgbuf is u8 and will cast to our - * needs. - */ - i = 0; - msgbuf[i++] = offset; - - msg[0].addr = client->addr; - msg[0].buf = msgbuf; - msg[0].len = i; - - msg[1].addr = client->addr; - msg[1].flags = I2C_M_RD; - msg[1].buf = buf; - msg[1].len = count; - } - - /* - * Reads fail if the previous write didn't complete yet. We may - * loop a few times until this one succeeds, waiting at least - * long enough for one entire page write to work. - */ - timeout = jiffies + msecs_to_jiffies(write_timeout); - do { - read_time = jiffies; - - switch (port_data->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - status = i2c_smbus_read_i2c_block_data(client, offset, - count, buf); - break; - case I2C_SMBUS_WORD_DATA: - status = i2c_smbus_read_word_data(client, offset); - if (status >= 0) { - buf[0] = status & 0xff; - if (count == 2) - buf[1] = status >> 8; - status = count; - } - break; - case I2C_SMBUS_BYTE_DATA: - status = i2c_smbus_read_byte_data(client, offset); - if (status >= 0) { - buf[0] = status; - status = count; - } - break; - default: - status = i2c_transfer(client->adapter, msg, 2); - if (status == 2) - status = count; - } - - dev_dbg(&client->dev, "eeprom read %zu@%d --> %d (%ld)\n", - count, offset, status, jiffies); - - if (status == count) /* happy path */ - return count; - - if (status == -ENXIO) /* no module present */ - return status; - - /* REVISIT: at HZ=100, this is sloooow */ - msleep(1); - } while (time_before(read_time, timeout)); - - return -ETIMEDOUT; -} - -static ssize_t sff_8436_eeprom_write(struct sfp_port_data *port_data, - struct i2c_client *client, - const char *buf, - unsigned offset, size_t count) -{ - struct i2c_msg msg; - ssize_t status; - unsigned long timeout, write_time; - unsigned next_page_start; - int i = 0; - - /* write max is at most a page - * (In this driver, write_max is actually one byte!) - */ - if (count > port_data->write_max) - count = port_data->write_max; - - /* shorten count if necessary to avoid crossing page boundary */ - next_page_start = roundup(offset + 1, SFF_8436_PAGE_SIZE); - if (offset + count > next_page_start) - count = next_page_start - offset; - - switch (port_data->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - /*smaller eeproms can work given some SMBus extension calls */ - if (count > I2C_SMBUS_BLOCK_MAX) - count = I2C_SMBUS_BLOCK_MAX; - break; - case I2C_SMBUS_WORD_DATA: - /* Check for odd length transaction */ - count = (count == 1) ? 1 : 2; - break; - case I2C_SMBUS_BYTE_DATA: - count = 1; - break; - default: - /* If we'll use I2C calls for I/O, set up the message */ - msg.addr = client->addr; - msg.flags = 0; - - /* msg.buf is u8 and casts will mask the values */ - msg.buf = port_data->writebuf; - - msg.buf[i++] = offset; - memcpy(&msg.buf[i], buf, count); - msg.len = i + count; - break; - } - - /* - * Reads fail if the previous write didn't complete yet. We may - * loop a few times until this one succeeds, waiting at least - * long enough for one entire page write to work. - */ - timeout = jiffies + msecs_to_jiffies(write_timeout); - do { - write_time = jiffies; - - switch (port_data->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - status = i2c_smbus_write_i2c_block_data(client, - offset, count, buf); - if (status == 0) - status = count; - break; - case I2C_SMBUS_WORD_DATA: - if (count == 2) { - status = i2c_smbus_write_word_data(client, - offset, (u16)((buf[0])|(buf[1] << 8))); - } else { - /* count = 1 */ - status = i2c_smbus_write_byte_data(client, - offset, buf[0]); - } - if (status == 0) - status = count; - break; - case I2C_SMBUS_BYTE_DATA: - status = i2c_smbus_write_byte_data(client, offset, - buf[0]); - if (status == 0) - status = count; - break; - default: - status = i2c_transfer(client->adapter, &msg, 1); - if (status == 1) - status = count; - break; - } - - dev_dbg(&client->dev, "eeprom write %zu@%d --> %ld (%lu)\n", - count, offset, (long int) status, jiffies); - - if (status == count) - return count; - - /* REVISIT: at HZ=100, this is sloooow */ - msleep(1); - } while (time_before(write_time, timeout)); - - return -ETIMEDOUT; -} - - -static ssize_t sff_8436_eeprom_update_client(struct sfp_port_data *port_data, - char *buf, loff_t off, - size_t count, qsfp_opcode_e opcode) -{ - struct i2c_client *client; - ssize_t retval = 0; - u8 page = 0; - loff_t phy_offset = off; - int ret = 0; - - page = sff_8436_translate_offset(port_data, &phy_offset, &client); - - dev_dbg(&client->dev, - "sff_8436_eeprom_update_client off %lld page:%d phy_offset:%lld, count:%ld, opcode:%d\n", - off, page, phy_offset, (long int) count, opcode); - if (page > 0) { - ret = sff_8436_eeprom_write(port_data, client, &page, - SFF_8436_PAGE_SELECT_REG, 1); - if (ret < 0) { - dev_dbg(&client->dev, - "Write page register for page %d failed ret:%d!\n", - page, ret); - return ret; - } - } - - while (count) { - ssize_t status; - - if (opcode == QSFP_READ_OP) { - status = sff_8436_eeprom_read(port_data, client, - buf, phy_offset, count); - } else { - status = sff_8436_eeprom_write(port_data, client, - buf, phy_offset, count); - } - if (status <= 0) { - if (retval == 0) - retval = status; - break; - } - buf += status; - phy_offset += status; - count -= status; - retval += status; - } - - - if (page > 0) { - /* return the page register to page 0 (why?) */ - page = 0; - ret = sff_8436_eeprom_write(port_data, client, &page, - SFF_8436_PAGE_SELECT_REG, 1); - if (ret < 0) { - dev_err(&client->dev, - "Restore page register to page %d failed ret:%d!\n", - page, ret); - return ret; - } - } - return retval; -} - - -/* - * Figure out if this access is within the range of supported pages. - * Note this is called on every access because we don't know if the - * module has been replaced since the last call. - * If/when modules support more pages, this is the routine to update - * to validate and allow access to additional pages. - * - * Returns updated len for this access: - * - entire access is legal, original len is returned. - * - access begins legal but is too long, len is truncated to fit. - * - initial offset exceeds supported pages, return -EINVAL - */ -static ssize_t sff_8436_page_legal(struct sfp_port_data *port_data, - loff_t off, size_t len) -{ - struct i2c_client *client = port_data->client; - u8 regval; - int status; - size_t maxlen; - - if (off < 0) return -EINVAL; - if (port_data->driver_type == DRIVER_TYPE_SFP_MSA) { - /* SFP case */ - /* if no pages needed, we're good */ - if ((off + len) <= SFF_8472_EEPROM_UNPAGED_SIZE) return len; - /* if offset exceeds possible pages, we're not good */ - if (off >= SFF_8472_EEPROM_SIZE) return -EINVAL; - /* in between, are pages supported? */ - status = sff_8436_eeprom_read(port_data, client, ®val, - SFF_8472_PAGEABLE_REG, 1); - if (status < 0) return status; /* error out (no module?) */ - if (regval & SFF_8472_PAGEABLE) { - /* Pages supported, trim len to the end of pages */ - maxlen = SFF_8472_EEPROM_SIZE - off; - } else { - /* pages not supported, trim len to unpaged size */ - maxlen = SFF_8472_EEPROM_UNPAGED_SIZE - off; - } - len = (len > maxlen) ? maxlen : len; - dev_dbg(&client->dev, - "page_legal, SFP, off %lld len %ld\n", - off, (long int) len); - } - else if (port_data->driver_type == DRIVER_TYPE_QSFP || - port_data->driver_type == DRIVER_TYPE_XFP) { - /* QSFP case */ - /* if no pages needed, we're good */ - if ((off + len) <= SFF_8436_EEPROM_UNPAGED_SIZE) return len; - /* if offset exceeds possible pages, we're not good */ - if (off >= SFF_8436_EEPROM_SIZE) return -EINVAL; - /* in between, are pages supported? */ - status = sff_8436_eeprom_read(port_data, client, ®val, - SFF_8436_PAGEABLE_REG, 1); - if (status < 0) return status; /* error out (no module?) */ - if (regval & SFF_8436_NOT_PAGEABLE) { - /* pages not supported, trim len to unpaged size */ - maxlen = SFF_8436_EEPROM_UNPAGED_SIZE - off; - } else { - /* Pages supported, trim len to the end of pages */ - maxlen = SFF_8436_EEPROM_SIZE - off; - } - len = (len > maxlen) ? maxlen : len; - dev_dbg(&client->dev, - "page_legal, QSFP, off %lld len %ld\n", - off, (long int) len); - } - else { - return -EINVAL; - } - return len; -} - - -static ssize_t sfp_port_read_write(struct sfp_port_data *port_data, - char *buf, loff_t off, size_t len, qsfp_opcode_e opcode) -{ - struct i2c_client *client = port_data->client; - int chunk; - int status = 0; - ssize_t retval; - size_t pending_len = 0, chunk_len = 0; - loff_t chunk_offset = 0, chunk_start_offset = 0; - - if (unlikely(!len)) - return len; - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&port_data->update_lock); - - /* - * Confirm this access fits within the device suppored addr range - */ - len = sff_8436_page_legal(port_data, off, len); - if (len < 0) { - status = len; - goto err; - } - - /* - * For each (128 byte) chunk involved in this request, issue a - * separate call to sff_eeprom_update_client(), to - * ensure that each access recalculates the client/page - * and writes the page register as needed. - * Note that chunk to page mapping is confusing, is different for - * QSFP and SFP, and never needs to be done. Don't try! - */ - pending_len = len; /* amount remaining to transfer */ - retval = 0; /* amount transferred */ - for (chunk = off >> 7; chunk <= (off + len - 1) >> 7; chunk++) { - - /* - * Compute the offset and number of bytes to be read/write - * - * 1. start at offset 0 (within the chunk), and read/write - * the entire chunk - * 2. start at offset 0 (within the chunk) and read/write less - * than entire chunk - * 3. start at an offset not equal to 0 and read/write the rest - * of the chunk - * 4. start at an offset not equal to 0 and read/write less than - * (end of chunk - offset) - */ - chunk_start_offset = chunk * SFF_8436_PAGE_SIZE; - - if (chunk_start_offset < off) { - chunk_offset = off; - if ((off + pending_len) < (chunk_start_offset + - SFF_8436_PAGE_SIZE)) - chunk_len = pending_len; - else - chunk_len = (chunk+1)*SFF_8436_PAGE_SIZE - off;/*SFF_8436_PAGE_SIZE - off;*/ - } else { - chunk_offset = chunk_start_offset; - if (pending_len > SFF_8436_PAGE_SIZE) - chunk_len = SFF_8436_PAGE_SIZE; - else - chunk_len = pending_len; - } - - dev_dbg(&client->dev, - "sff_r/w: off %lld, len %ld, chunk_start_offset %lld, chunk_offset %lld, chunk_len %ld, pending_len %ld\n", - off, (long int) len, chunk_start_offset, chunk_offset, - (long int) chunk_len, (long int) pending_len); - - /* - * note: chunk_offset is from the start of the EEPROM, - * not the start of the chunk - */ - status = sff_8436_eeprom_update_client(port_data, buf, - chunk_offset, chunk_len, opcode); - if (status != chunk_len) { - /* This is another 'no device present' path */ - dev_dbg(&client->dev, - "sff_8436_update_client for chunk %d chunk_offset %lld chunk_len %ld failed %d!\n", - chunk, chunk_offset, (long int) chunk_len, status); - goto err; - } - buf += status; - pending_len -= status; - retval += status; - } - mutex_unlock(&port_data->update_lock); - - return retval; - -err: - mutex_unlock(&port_data->update_lock); - - return status; -} - -#else -static ssize_t sfp_port_read(struct sfp_port_data *data, - char *buf, loff_t off, size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) { - DEBUG_PRINT("Count = 0, return"); - return count; - } - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_read(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; - -} -#endif - -static ssize_t sfp_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("offset = (%d), count = (%d)", off, count); - - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - -#if (MULTIPAGE_SUPPORT == 1) - return sfp_port_read_write(data, buf, off, count, QSFP_READ_OP); -#else - return sfp_port_read(data, buf, off, count); -#endif -} - -#if (MULTIPAGE_SUPPORT == 1) -static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom, size_t size) -#else -static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom) -#endif -{ - int err; - - sysfs_bin_attr_init(eeprom); - eeprom->attr.name = EEPROM_NAME; - eeprom->attr.mode = S_IWUSR | S_IRUGO; - eeprom->read = sfp_bin_read; - eeprom->write = sfp_bin_write; -#if (MULTIPAGE_SUPPORT == 1) - eeprom->size = size; -#else - eeprom->size = EEPROM_SIZE; -#endif - - /* Create eeprom file */ - err = sysfs_create_bin_file(kobj, eeprom); - if (err) { - return err; - } - - return 0; -} - -static int sfp_sysfs_eeprom_cleanup(struct kobject *kobj, struct bin_attribute *eeprom) -{ - sysfs_remove_bin_file(kobj, eeprom); - return 0; -} - - -#if (MULTIPAGE_SUPPORT == 0) -static int sfp_i2c_check_functionality(struct i2c_client *client) -{ -#if USE_I2C_BLOCK_READ - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK); -#else - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA); -#endif -} -#endif - - -static const struct attribute_group qsfp_group = { - .attrs = qsfp_attributes, -}; - -static int qsfp_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct qsfp_data **data) -{ - int status; - struct qsfp_data *qsfp; - -#if (MULTIPAGE_SUPPORT == 0) - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } -#endif - - qsfp = kzalloc(sizeof(struct qsfp_data), GFP_KERNEL); - if (!qsfp) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &qsfp_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ -#if (MULTIPAGE_SUPPORT == 1) - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin, SFF_8436_EEPROM_SIZE); -#else - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin); -#endif - if (status) { - goto exit_remove; - } - - *data = qsfp; - dev_info(&client->dev, "qsfp '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &qsfp_group); -exit_free: - kfree(qsfp); -exit: - - return status; -} - -/* Platform dependent +++ */ -static int sfp_device_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - int ret = 0; - struct sfp_port_data *data = NULL; - - if (client->addr != SFP_EEPROM_A0_I2C_ADDR) { - return -ENODEV; - } - - if (dev_id->driver_data < as7816_64x_port1 || dev_id->driver_data > as7816_64x_port64) { - return -ENXIO; - } - - data = kzalloc(sizeof(struct sfp_port_data), GFP_KERNEL); - if (!data) { - return -ENOMEM; - } - -#if (MULTIPAGE_SUPPORT == 1) - data->use_smbus = 0; - - /* Use I2C operations unless we're stuck with SMBus extensions. */ - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { - if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { - data->use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_WORD_DATA)) { - data->use_smbus = I2C_SMBUS_WORD_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_BYTE_DATA)) { - data->use_smbus = I2C_SMBUS_BYTE_DATA; - } else { - ret = -EPFNOSUPPORT; - goto exit_kfree; - } - } - - if (!data->use_smbus || - (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) || - i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_WORD_DATA) || - i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) { - /* - * NOTE: AN-2079 - * Finisar recommends that the host implement 1 byte writes - * only since this module only supports 32 byte page boundaries. - * 2 byte writes are acceptable for PE and Vout changes per - * Application Note AN-2071. - */ - unsigned write_max = 1; - - if (write_max > io_limit) - write_max = io_limit; - if (data->use_smbus && write_max > I2C_SMBUS_BLOCK_MAX) - write_max = I2C_SMBUS_BLOCK_MAX; - data->write_max = write_max; - - /* buffer (data + address at the beginning) */ - data->writebuf = kmalloc(write_max + 2, GFP_KERNEL); - if (!data->writebuf) { - ret = -ENOMEM; - goto exit_kfree; - } - } else { - dev_warn(&client->dev, - "cannot write due to controller restrictions."); - } - - if (data->use_smbus == I2C_SMBUS_WORD_DATA || - data->use_smbus == I2C_SMBUS_BYTE_DATA) { - dev_notice(&client->dev, "Falling back to %s reads, " - "performance will suffer\n", data->use_smbus == - I2C_SMBUS_WORD_DATA ? "word" : "byte"); - } -#endif - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - data->client = client; - data->driver_type = DRIVER_TYPE_QSFP; - - ret = qsfp_probe(client, dev_id, &data->qsfp); - if (ret < 0) { - goto exit_kfree_buf; - } - - return ret; - -exit_kfree_buf: -#if (MULTIPAGE_SUPPORT == 1) - if (data->writebuf) kfree(data->writebuf); -#endif - -exit_kfree: - kfree(data); - return ret; -} -/* Platform dependent --- */ - -static int qsfp_remove(struct i2c_client *client, struct qsfp_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &qsfp_group); - kfree(data); - return 0; -} - -static int sfp_device_remove(struct i2c_client *client) -{ - int ret = 0; - struct sfp_port_data *data = i2c_get_clientdata(client); - - if (data->driver_type == DRIVER_TYPE_QSFP) { - ret = qsfp_remove(client, data->qsfp); - } - - kfree(data); - return ret; -} - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -static struct i2c_driver sfp_driver = { - .driver = { - .name = DRIVER_NAME, - }, - .probe = sfp_device_probe, - .remove = sfp_device_remove, - .id_table = sfp_device_id, - .address_list = normal_i2c, -}; - -static int __init sfp_init(void) -{ - return i2c_add_driver(&sfp_driver); -} - -static void __exit sfp_exit(void) -{ - i2c_del_driver(&sfp_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as7816_64x_sfp driver"); -MODULE_LICENSE("GPL"); - -module_init(sfp_init); -module_exit(sfp_exit); - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/ym2651y.c b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/ym2651y.c deleted file mode 120000 index f4d67640ccc3..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/ym2651y.c +++ /dev/null @@ -1 +0,0 @@ -../../common/modules/ym2651y.c \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/service/as7816-platform-init.service b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/service/as7816-platform-init.service deleted file mode 100755 index c1ba30092f1d..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/service/as7816-platform-init.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Accton AS7816-64X Platform initialization service -Before=pmon.service -DefaultDependencies=no - -[Service] -Type=oneshot -ExecStart=/usr/local/bin/accton_as7816_util.py install -ExecStop=/usr/local/bin/accton_as7816_util.py clean -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/setup.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/setup.py deleted file mode 100755 index 6633b9438b86..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/setup.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -from setuptools import setup -os.listdir - -setup( - name='as7816_64x', - version='1.0', - description='Module to initialize Accton AS7816-64X platforms', - - packages=['as7816_64x'], - package_dir={'as7816_64x': 'as7816-64x/classes'}, -) - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/README b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/README deleted file mode 100755 index 0b9fc1633999..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/README +++ /dev/null @@ -1,60 +0,0 @@ -Copyright (C) 2016 Accton Networks, Inc. - -This program is free software: you can redistribute it and/or modify -It under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -To initialize the system, run "accton_as7712_util.py install". -To clean up the drivers & devices, run "accton_as7712_util.py clean". -To dump information of sensors, run "accton_as7712_util.py show". -To dump SFP EEPROM, run "accton_as7712_util.py sff". -To set fan speed, run "accton_as7712_util.py set fan". -To enable/disable SFP emission, run "accton_as7712_util.py set sfp". -To set system LEDs' color, run "accton_as7712_util.py set led" -For more information, run "accton_as7712_util.py --help". - -==================================================================== -Besides applying accton_as7712_util.py to access peripherals, you can -access peripherals by sysfs nodes directly after the installation is run. - -LED controls can be found under /sys/class/leds. The sysfs interface -color mappings are as follows: -Brightness: - 0 => off - 1 => green - 2 => amber - 3 => red - 4 => blue - -There are 5 system LEDs, loc, diag, fan, ps1, and ps2. -They are lit automatically by CPLD, but the loc and diag. -The loc led has only 1 color, blue. -The diag one has 3 colors: red, amber, and green. - -Fan controls can be found in /sys/bus/i2c/devices/2-0066. -There are 12 fans inside 6 fan modules. -All fans share 1 duty setting, ranged from 0~100. - -Three temperature sensors are controlled by the lm75 kernel modules. -They should already be visible under /sys/bus/i2c/drivers/lm75/. - -Two power supplies are controlled by the CPLD. -Here provide their status under -/sys/bus/i2c/devices/10-0050 and /sys/bus/i2c/devices/11-0053. - -There are 32 QSFP+ modules are equipped. -Apply "accton_as7712_util.py show" to get their status. -Apply "accton_as7712_util.py set sfp" to turn on/off light transmission. -Apply "accton_as7712_util.py sff" to dump EEPROM information. -Before operating on that QSFP+, please make sure it is well plugged. -Otherwise, operation is going to fail. - diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_util.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_util.py deleted file mode 100755 index 44c4486a2d59..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_util.py +++ /dev/null @@ -1,523 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2016 Accton Networks, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" -Usage: %(scriptName)s [options] command object - -options: - -h | --help : this help message - -d | --debug : run with debug mode - -f | --force : ignore error during installation or clean -command: - install : install drivers and generate related sysfs nodes - clean : uninstall drivers and remove related sysfs nodes - show : show all systen status - sff : dump SFP eeprom - set : change board setting with fan|led|sfp -""" - -import os -import commands -import sys, getopt -import logging -import re -import time -from collections import namedtuple - - - - -PROJECT_NAME = 'as7816_64x' -version = '0.1.0' -verbose = False -DEBUG = False -args = [] -ALL_DEVICE = {} -DEVICE_NO = {'led':5, 'fan':4,'thermal':6, 'psu':2, 'sfp':64} -FORCE = 0 -#logging.basicConfig(filename= PROJECT_NAME+'.log', filemode='w',level=logging.DEBUG) -#logging.basicConfig(level=logging.INFO) - - -if DEBUG == True: - print sys.argv[0] - print 'ARGV :', sys.argv[1:] - - -def main(): - global DEBUG - global args - global FORCE - - if len(sys.argv)<2: - show_help() - - options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help', - 'debug', - 'force', - ]) - if DEBUG == True: - print options - print args - print len(sys.argv) - - for opt, arg in options: - if opt in ('-h', '--help'): - show_help() - elif opt in ('-d', '--debug'): - DEBUG = True - logging.basicConfig(level=logging.INFO) - elif opt in ('-f', '--force'): - FORCE = 1 - else: - logging.info('no option') - for arg in args: - if arg == 'install': - do_install() - elif arg == 'clean': - do_uninstall() - elif arg == 'show': - device_traversal() - elif arg == 'sff': - if len(args)!=2: - show_eeprom_help() - elif int(args[1]) ==0 or int(args[1]) > DEVICE_NO['sfp']: - show_eeprom_help() - else: - show_eeprom(args[1]) - return - elif arg == 'set': - if len(args)<3: - show_set_help() - else: - set_device(args[1:]) - return - else: - show_help() - - - return 0 - -def show_help(): - print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]} - sys.exit(0) - -def show_set_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print cmd +" [led|sfp|fan]" - print " use \""+ cmd + " led 0-4 \" to set led color" - print " use \""+ cmd + " fan 0-100\" to set fan duty percetage" - print " use \""+ cmd + " sfp 1-32 {0|1}\" to set sfp# tx_disable" - sys.exit(0) - -def show_eeprom_help(): - cmd = sys.argv[0].split("/")[-1]+ " " + args[0] - print " use \""+ cmd + " 1-32 \" to dump sfp# eeprom" - sys.exit(0) - -def my_log(txt): - if DEBUG == True: - print "[ROY]"+txt - return - -def log_os_system(cmd, show): - logging.info('Run :'+cmd) - status, output = commands.getstatusoutput(cmd) - my_log (cmd +"with result:" + str(status)) - my_log (" output:"+output) - if status: - logging.info('Failed :'+cmd) - if show: - print('Failed :'+cmd) - return status, output - -def driver_check(): - ret, lsmod = log_os_system("lsmod| grep accton", 0) - logging.info('mods:'+lsmod) - if len(lsmod) ==0: - return False - return True - - - -kos = [ -'modprobe i2c_dev', -'modprobe i2c_mux_pca954x', -'modprobe accton_i2c_cpld' , -'modprobe ym2651y' , -'modprobe x86-64-accton-as7816-64x-fan' , -'modprobe x86-64-accton-as7816-64x-sfp' , -'modprobe x86-64-accton-as7816-64x-leds' , -'modprobe x86-64-accton-as7816-64x-psu' ] - -def driver_install(): - global FORCE - status, output = log_os_system("depmod", 1) - for i in range(0,len(kos)): - status, output = log_os_system(kos[i], 1) - if status: - if FORCE == 0: - return status - return 0 - -def driver_uninstall(): - global FORCE - for i in range(0,len(kos)): - rm = kos[-(i+1)].replace("modprobe", "modprobe -rq") - rm = rm.replace("insmod", "rmmod") - status, output = log_os_system(rm, 1) - if status: - if FORCE == 0: - return status - return 0 - -led_prefix ='/sys/class/leds/'+PROJECT_NAME+'_led::' -hwmon_types = {'led': ['diag','fan','loc','psu1','psu2']} -hwmon_nodes = {'led': ['brightness'] } -hwmon_prefix ={'led': led_prefix} - -i2c_prefix = '/sys/bus/i2c/devices/' -i2c_bus = {'fan': ['17-0068'] , - 'thermal': ['18-0048','18-0049', '18-004a' , '18-004b', '17-004d', '17-004e'] , - 'psu': ['10-0053','9-0050'], - 'sfp': ['-0050']} -i2c_nodes = {'fan': ['present', 'front_speed_rpm', 'rear_speed_rpm'] , - 'thermal': ['hwmon/hwmon*/temp1_input'] , - 'psu': ['psu_present ', 'psu_power_good'] , - 'sfp': ['sfp_is_present ', 'sfp_tx_disable']} - -sfp_map = [37,38,39,40,42,41,44,43,33,34,35,36,45,46,47,48,49,50,51,52, - 61,62,63,64,53,54,55,56,57,58,59,60,69,70,71,72,77,78,79,80,65, - 66,67,68,73,74,75,76,85,86,87,88,31,32,29,30,81,82,83,84,25,26, - 27,28] - -mknod =[ -'echo pca9548 0x77 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-1/new_device', -'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-2/new_device', -'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-2/new_device', -'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-2/new_device', -'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-2/new_device', -'echo pca9548 0x74 > /sys/bus/i2c/devices/i2c-2/new_device', -'echo pca9548 0x75 > /sys/bus/i2c/devices/i2c-2/new_device', -'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-2/new_device', -'echo 24c02 0x56 > /sys/bus/i2c/devices/i2c-0/new_device', -'echo as7816_64x_psu1 0x53 > /sys/bus/i2c/devices/i2c-10/new_device', -'echo ym2851 0x5b > /sys/bus/i2c/devices/i2c-10/new_device', -'echo as7816_64x_psu2 0x50 > /sys/bus/i2c/devices/i2c-9/new_device', -'echo ym2851 0x58 > /sys/bus/i2c/devices/i2c-9/new_device', -'echo as7816_64x_fan 0x68 > /sys/bus/i2c/devices/i2c-17/new_device', -'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-18/new_device', -'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-18/new_device', -'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-18/new_device', -'echo lm75 0x4b > /sys/bus/i2c/devices/i2c-18/new_device', -'echo lm75 0x4d > /sys/bus/i2c/devices/i2c-17/new_device', -'echo lm75 0x4e > /sys/bus/i2c/devices/i2c-17/new_device', -'echo cpld_as7816 0x60 > /sys/bus/i2c/devices/i2c-19/new_device', -'echo cpld_plain 0x62 > /sys/bus/i2c/devices/i2c-20/new_device', -'echo cpld_plain 0x64 > /sys/bus/i2c/devices/i2c-21/new_device', -'echo cpld_plain 0x66 > /sys/bus/i2c/devices/i2c-22/new_device'] - -def i2c_order_check(): - return 0 - -def device_install(): - global FORCE - - for i in range(0,len(mknod)): - #for pca954x need times to built new i2c buses - if mknod[i].find('pca954') != -1: - time.sleep(1) - - status, output = log_os_system(mknod[i], 1) - if status: - print output - if FORCE == 0: - return status - - for i in range(0,len(sfp_map)): - status, output =log_os_system("echo as7816_64x_port"+str(i+1)+" 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1) - if status: - print output - if FORCE == 0: - return status - return - -def device_uninstall(): - global FORCE - - status, output =log_os_system("ls /sys/bus/i2c/devices/1-0076", 0) - - for i in range(0,len(sfp_map)): - target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device" - status, output =log_os_system("echo 0x50 > "+ target, 1) - if status: - print output - if FORCE == 0: - return status - - nodelist = mknod - - for i in range(len(nodelist)): - target = nodelist[-(i+1)] - temp = target.split() - del temp[1] - temp[-1] = temp[-1].replace('new_device', 'delete_device') - status, output = log_os_system(" ".join(temp), 1) - if status: - print output - if FORCE == 0: - return status - - return - -def system_ready(): - if driver_check() == False: - return False - if not device_exist(): - return False - return True - -def do_install(): - print "Checking system...." - if driver_check() == False: - print "No driver, installing...." - status = driver_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" drivers detected...." - if not device_exist(): - print "No device, installing...." - status = device_install() - if status: - if FORCE == 0: - return status - else: - print PROJECT_NAME.upper()+" devices detected...." - return - -def do_uninstall(): - print "Checking system...." - if not device_exist(): - print PROJECT_NAME.upper() +" has no device installed...." - else: - print "Removing device...." - status = device_uninstall() - if status: - if FORCE == 0: - return status - - if driver_check()== False : - print PROJECT_NAME.upper() +" has no driver installed...." - else: - print "Removing installed driver...." - status = driver_uninstall() - if status: - if FORCE == 0: - return status - - return - -def devices_info(): - global DEVICE_NO - global ALL_DEVICE - global i2c_bus, hwmon_types - for key in DEVICE_NO: - ALL_DEVICE[key]= {} - for i in range(0,DEVICE_NO[key]): - ALL_DEVICE[key][key+str(i+1)] = [] - - for key in i2c_bus: - buses = i2c_bus[key] - nodes = i2c_nodes[key] - for i in range(0,len(buses)): - for j in range(0,len(nodes)): - if 'fan' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - elif 'sfp' == key: - for k in range(0,DEVICE_NO[key]): - node = key+str(k+1) - path = i2c_prefix+ str(sfp_map[k])+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - else: - node = key+str(i+1) - path = i2c_prefix+ buses[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][node].append(path) - - for key in hwmon_types: - itypes = hwmon_types[key] - nodes = hwmon_nodes[key] - for i in range(0,len(itypes)): - for j in range(0,len(nodes)): - node = key+"_"+itypes[i] - path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j] - my_log(node+": "+ path) - ALL_DEVICE[key][ key+str(i+1)].append(path) - - #show dict all in the order - if DEBUG == True: - for i in sorted(ALL_DEVICE.keys()): - print(i+": ") - for j in sorted(ALL_DEVICE[i].keys()): - print(" "+j) - for k in (ALL_DEVICE[i][j]): - print(" "+" "+k) - return - -def show_eeprom(index): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0] - node = node.replace(node.split("/")[-1], 'sfp_eeprom') - # check if got hexdump command in current environment - ret, log = log_os_system("which hexdump", 0) - ret, log2 = log_os_system("which busybox hexdump", 0) - if len(log): - hex_cmd = 'hexdump' - elif len(log2): - hex_cmd = ' busybox hexdump' - else: - log = 'Failed : no hexdump cmd!!' - logging.info(log) - print log - return 1 - - print node + ":" - ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1) - if ret==0: - print log - else: - print "**********device no found**********" - return - -def set_device(args): - global DEVICE_NO - global ALL_DEVICE - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - - if args[0]=='led': - if int(args[1])>4: - show_set_help() - return - #print ALL_DEVICE['led'] - for i in range(0,len(ALL_DEVICE['led'])): - for k in (ALL_DEVICE['led']['led'+str(i+1)]): - ret, log = log_os_system("echo "+args[1]+" >"+k, 1) - if ret: - return ret - elif args[0]=='fan': - if int(args[1])>100: - show_set_help() - return - #print ALL_DEVICE['fan'] - #fan1~6 is all fine, all fan share same setting - node = ALL_DEVICE['fan'] ['fan1'][0] - node = node.replace(node.split("/")[-1], 'fan_duty_cycle_percentage') - ret, log = log_os_system("cat "+ node, 1) - if ret==0: - print ("Previous fan duty: " + log.strip() +"%") - ret, log = log_os_system("echo "+args[1]+" >"+node, 1) - if ret==0: - print ("Current fan duty: " + args[1] +"%") - return ret - elif args[0]=='sfp': - if int(args[1])> DEVICE_NO[args[0]] or int(args[1])==0: - show_set_help() - return - if len(args)<2: - show_set_help() - return - - if int(args[2])>1: - show_set_help() - return - - #print ALL_DEVICE[args[0]] - for i in range(0,len(ALL_DEVICE[args[0]])): - for j in ALL_DEVICE[args[0]][args[0]+str(args[1])]: - if j.find('tx_disable')!= -1: - ret, log = log_os_system("echo "+args[2]+" >"+ j, 1) - if ret: - return ret - - return - -#get digits inside a string. -#Ex: 31 for "sfp31" -def get_value(input): - digit = re.findall('\d+', input) - return int(digit[0]) - -def device_traversal(): - if system_ready()==False: - print("System's not ready.") - print("Please install first!") - return - - if len(ALL_DEVICE)==0: - devices_info() - for i in sorted(ALL_DEVICE.keys()): - print("============================================") - print(i.upper()+": ") - print("============================================") - - for j in sorted(ALL_DEVICE[i].keys(), key=get_value): - print " "+j+":", - for k in (ALL_DEVICE[i][j]): - ret, log = log_os_system("cat "+k, 0) - func = k.split("/")[-1].strip() - func = re.sub(j+'_','',func,1) - func = re.sub(i.lower()+'_','',func,1) - if ret==0: - print func+"="+log+" ", - else: - print func+"="+"X"+" ", - print - print("----------------------------------------------------------------") - - - print - return - -def device_exist(): - ret1, log = log_os_system("ls "+i2c_prefix+"*0076", 0) - ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0) - return not(ret1 or ret2) - -if __name__ == "__main__": - main() diff --git a/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_i2c_cpld.c b/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_i2c_cpld.c deleted file mode 100644 index aae4e5538b63..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_i2c_cpld.c +++ /dev/null @@ -1,887 +0,0 @@ -/* - * A hwmon driver for the accton_i2c_cpld - * - * Copyright (C) 2013 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#define MAX_PORT_NUM 64 -#define I2C_RW_RETRY_COUNT 10 -#define I2C_RW_RETRY_INTERVAL 60 /* ms */ - -#define I2C_ADDR_CPLD1 0x60 -#define I2C_ADDR_CPLD2 0x62 -#define I2C_ADDR_CPLD3 0x64 -#define CPLD_ADDRS {I2C_ADDR_CPLD1, I2C_ADDR_CPLD2, I2C_ADDR_CPLD3} - - -/* - * Number of additional attribute pointers to allocate - * with each call to krealloc - */ -#define ATTR_ALLOC_SIZE 1 /*For last attribute which is NUll.*/ - -#define NAME_SIZE 24 -#define MAX_RESP_LENGTH 48 - -typedef ssize_t (*show_func)( struct device *dev, - struct device_attribute *attr, - char *buf); -typedef ssize_t (*store_func)(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count); - -enum models { - AS7712_32X, - AS7716_32X, - AS7816_64X, - AS7312_54X, - PLAIN_CPLD, /*No attribute but add i2c addr to the list.*/ - NUM_MODEL -}; - -enum sfp_func { - HAS_SFP = 1<<0 , - HAS_QSFP = 1<<1 , -}; - -enum common_attrs { - CMN_VERSION, - CMN_ACCESS, - CMN_PRESENT_ALL, - NUM_COMMON_ATTR -}; - -enum sfp_attrs { - SFP_PRESENT, - SFP_RESET, - SFP_LP_MODE, - NUM_SFP_ATTR -}; - -struct cpld_sensor { - struct cpld_sensor *next; - char name[NAME_SIZE+1]; /* sysfs sensor name */ - struct device_attribute attribute; - bool update; /* runtime sensor update needed */ - int data; /* Sensor data. Negative if there was a read error */ - - u8 reg; /* register */ - u8 mask; /* bit mask */ - bool invert; /* inverted value*/ - -}; - -#define to_cpld_sensor(_attr) \ - container_of(_attr, struct cpld_sensor, attribute) - -struct cpld_data { - struct device *dev; - struct device *hwmon_dev; - - int num_attributes; - struct attribute_group group; - - enum models model; - struct cpld_sensor *sensors; - struct mutex update_lock; - bool valid; - unsigned long last_updated; /* in jiffies */ - - int attr_index; - u16 sfp_num; - u8 sfp_types; - struct model_attrs *cmn_attr; -}; - -struct cpld_client_node { - struct i2c_client *client; - struct list_head list; -}; - - -struct base_attrs { - const char *name; - umode_t mode; - show_func get; - store_func set; -}; - -struct attrs { - int reg; - bool invert; - struct base_attrs *base; -}; - -struct model_attrs { - struct attrs **cmn; - struct attrs **portly; -}; - - -static ssize_t show_bit(struct device *dev, - struct device_attribute *devattr, char *buf); -static ssize_t show_presnet_all(struct device *dev, - struct device_attribute *devattr, char *buf); -static ssize_t set_1bit(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t set_byte(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); - -int accton_i2c_cpld_read(u8 cpld_addr, u8 reg); -int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - - -struct base_attrs common_attrs[NUM_COMMON_ATTR] = -{ - [CMN_VERSION] = {"version", S_IRUGO, show_bit, NULL}, - [CMN_ACCESS] = {"access", S_IWUSR, NULL, set_byte}, - [CMN_PRESENT_ALL] = {"module_present_all", S_IRUGO, show_presnet_all, NULL}, -}; - -struct attrs as7712_common[] = { - [CMN_VERSION] = {0x01, false, &common_attrs[CMN_VERSION]}, - [CMN_ACCESS] = {0x00, false, &common_attrs[CMN_ACCESS]}, - [CMN_PRESENT_ALL] = {0x30, false, &common_attrs[CMN_PRESENT_ALL]}, -}; -struct attrs as7816_common[] = { - [CMN_VERSION] = {0x01, false, &common_attrs[CMN_VERSION]}, - [CMN_ACCESS] = {0x00, false, &common_attrs[CMN_ACCESS]}, - [CMN_PRESENT_ALL] = {0x30, false, &common_attrs[CMN_PRESENT_ALL]}, -}; -struct attrs as7312_common[] = { - [CMN_VERSION] = {0x01, false, &common_attrs[CMN_VERSION]}, - [CMN_ACCESS] = {0x00, false, &common_attrs[CMN_ACCESS]}, - [CMN_PRESENT_ALL] = {-1, false, &common_attrs[CMN_PRESENT_ALL]}, -}; -struct attrs plain_common[] = { - [CMN_VERSION] = {0x01, false, &common_attrs[CMN_VERSION]}, -}; - -struct base_attrs portly_attrs[] = -{ - [SFP_PRESENT] = {"module_present", S_IRUGO, show_bit, NULL}, - [SFP_RESET] = {"module_reset", S_IRUGO|S_IWUGO, show_bit, set_1bit}, -}; - -struct attrs as7712_port[] = { - {0x30, true, &portly_attrs[SFP_PRESENT]}, - {0x04, true, &portly_attrs[SFP_RESET]}, -}; - -struct attrs as7816_port[] = { - {0x70, true, &portly_attrs[SFP_PRESENT]}, - {0x40, true, &portly_attrs[SFP_RESET]}, -}; - -struct attrs *as7712_cmn_list[] = { - &as7712_common[CMN_VERSION], - &as7712_common[CMN_ACCESS], - &as7712_common[CMN_PRESENT_ALL], - NULL -}; - -struct attrs *as7816_cmn_list[] = { - &as7816_common[CMN_VERSION], - &as7816_common[CMN_ACCESS], - &as7816_common[CMN_PRESENT_ALL], - NULL -}; - -struct attrs *as7312_cmn_list[] = { - &as7312_common[CMN_VERSION], - &as7312_common[CMN_ACCESS], - &as7312_common[CMN_PRESENT_ALL], - NULL -}; - -struct attrs *plain_cmn_list[] = { - &plain_common[CMN_VERSION], - NULL -}; - -struct attrs *as7712_port_list[] = { - &as7712_port[SFP_PRESENT], - &as7712_port[SFP_RESET], - NULL -}; -struct attrs *as7816_port_list[] = { - &as7816_port[SFP_PRESENT], - &as7816_port[SFP_RESET], - NULL -}; - -struct model_attrs models_attr[NUM_MODEL] = { - {.cmn = as7712_cmn_list, .portly=as7712_port_list}, - {.cmn = as7712_cmn_list, .portly=as7712_port_list}, /*7716's as 7712*/ - {.cmn = as7816_cmn_list, .portly=as7816_port_list}, - {.cmn = as7312_cmn_list, .portly=as7816_port_list}, - {.cmn = plain_cmn_list, .portly=NULL}, -}; - -static LIST_HEAD(cpld_client_list); -static struct mutex list_lock; -/* Addresses scanned for accton_i2c_cpld - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -static int get_sfp_spec(int model, u16 *num, u8 *types) -{ - switch (model) { - case AS7712_32X: - case AS7716_32X: - *num = 32; - *types = HAS_QSFP; - break; - case AS7816_64X: - *num = 64; - *types = HAS_QSFP; - break; - case AS7312_54X: - *num = 54; - *types = HAS_QSFP|HAS_SFP; - default: - *types = 0; - *num = 0; - break; - } - - return 0; -} - -static int get_present_reg(int model, u8 port, u8 *cpld_addr, u8 *reg, u8 *num) -{ - u8 cpld_address[] = CPLD_ADDRS; - - switch (model) { - case AS7312_54X: - if (port < 48) { - *cpld_addr = cpld_address[1 + port/24]; - *reg = 0x09 + (port%24)/8; - *num = 8; - } - else - { - *reg = 0x18; - *num = 4; - *cpld_addr = ( port < 52)? cpld_address[1]: cpld_address[2]; - } - break; - default: - return -EINVAL; - } -} - - -/*Assume the bits for ports are listed in-a-row.*/ -static int get_reg_bit(u8 reg_start, int port, - u8 *reg ,u8 *mask) -{ - *reg = reg_start + ((port)/8); - *mask = 1 << ((port)%8); - - return 0; -} - -static int cpld_write_internal( - struct i2c_client *client, u8 reg, u8 value) -{ - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, reg, value); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - return status; -} - -static int cpld_read_internal(struct i2c_client *client, u8 reg) -{ - int status = 0, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, reg); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - return status; -} - - -/*Turn a numberic array into string with " " between each element. - * e.g., {0x11, 0x33, 0xff, 0xf1} => "11 33 ff f1" - */ -static ssize_t array_stringify(char *buf, u8 *input, size_t size) { - - int i; - char t[MAX_RESP_LENGTH+1]; - - buf[0] = '\0'; - for (i = 0; i < size; i++) { - snprintf(t, MAX_RESP_LENGTH, "%x ", input[i]); - strncat(buf, t, MAX_RESP_LENGTH); - } - - if (strlen(buf) > 0) - buf[strlen(buf)-1] = '\0'; /*Remove tailing blank*/ - - return snprintf(buf, MAX_RESP_LENGTH, "%s\n", buf); -} - -static ssize_t show_presnet_all_distinct(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - u8 i, value, reg; - u8 cpld_addr, num; - u8 _value[8]; - u64 *values = (u64 *)_value; - - values = 0; - mutex_lock(&data->update_lock); - while(i < data->sfp_num) - { - get_present_reg(data->model, i, &cpld_addr, ®, &num); - if(cpld_addr == client->addr) - value = cpld_read_internal(client, reg); - else - value = accton_i2c_cpld_read(cpld_addr, reg); - - if (unlikely(value < 0)) { - goto exit; - } - - *values |= (value&((1<<(num))-1)) << i; - i += num; - } - mutex_unlock(&data->update_lock); - - *values = cpu_to_le64(*values); - return array_stringify(buf, _value, i); -exit: - mutex_unlock(&data->update_lock); - return value; -} - -static ssize_t show_presnet_all(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - struct cpld_sensor *sensor = to_cpld_sensor(devattr); - u8 i, values[MAX_RESP_LENGTH/8]; - - if (sensor->reg < 0) { - return show_presnet_all_distinct(dev, devattr, buf); - } - - mutex_lock(&data->update_lock); - for (i = 0; i < ((data->sfp_num+7)/8); i++) { - values[i] = cpld_read_internal(client, sensor->reg + i); - if (unlikely(values[i] < 0)) { - goto exit; - } - } - mutex_unlock(&data->update_lock); - return array_stringify(buf, values, i); - -exit: - mutex_unlock(&data->update_lock); - return values[i]; -} - -static ssize_t show_bit(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - int value; - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - struct cpld_sensor *sensor = to_cpld_sensor(devattr); - - mutex_lock(&data->update_lock); - value = cpld_read_internal(client, sensor->reg); - value = value & sensor->mask; - if (sensor->invert) - value = !value; - mutex_unlock(&data->update_lock); - - return snprintf(buf, PAGE_SIZE, "%x\n", value); -} - -static ssize_t set_1bit(struct device *dev, struct device_attribute *devattr, - const char *buf, size_t count) -{ - long is_reset; - int value, status; - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - struct cpld_sensor *sensor = to_cpld_sensor(devattr); - u8 cpld_bit, reg; - - status = kstrtol(buf, 10, &is_reset); - if (status) { - return status; - } - reg = sensor->reg; - cpld_bit = sensor->mask; - mutex_lock(&data->update_lock); - value = cpld_read_internal(client, reg); - if (unlikely(status < 0)) { - goto exit; - } - - if (sensor->invert) - is_reset = !is_reset; - - if (is_reset) { - value |= cpld_bit; - } - else { - value &= ~cpld_bit; - } - - status = cpld_write_internal(client, reg, value); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static ssize_t set_byte(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - return access(dev, da, buf, count); -} - -static ssize_t access(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - int status; - u32 addr, val; - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - - if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { - return -EINVAL; - } - - if (addr > 0xFF || val > 0xFF) { - return -EINVAL; - } - - mutex_lock(&data->update_lock); - status = cpld_write_internal(client, addr, val); - if (unlikely(status < 0)) { - goto exit; - } - mutex_unlock(&data->update_lock); - return count; - -exit: - mutex_unlock(&data->update_lock); - return status; -} - -static void accton_i2c_cpld_add_client(struct i2c_client *client) -{ - struct cpld_client_node *node = - kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); - - if (!node) { - dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", - client->addr); - return; - } - node->client = client; - - mutex_lock(&list_lock); - list_add(&node->list, &cpld_client_list); - mutex_unlock(&list_lock); -} - -static void accton_i2c_cpld_remove_client(struct i2c_client *client) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int found = 0; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client == client) { - found = 1; - break; - } - } - - if (found) { - list_del(list_node); - kfree(cpld_node); - } - - mutex_unlock(&list_lock); -} - -static int cpld_add_attribute(struct cpld_data *data, struct attribute *attr) -{ - int new_max_attrs = ++data->num_attributes + ATTR_ALLOC_SIZE; - void *new_attrs = krealloc(data->group.attrs, - new_max_attrs * sizeof(void *), - GFP_KERNEL); - if (!new_attrs) - return -ENOMEM; - data->group.attrs = new_attrs; - - - data->group.attrs[data->num_attributes-1] = attr; - data->group.attrs[data->num_attributes] = NULL; - - return 0; -} - -static void cpld_dev_attr_init(struct device_attribute *dev_attr, - const char *name, umode_t mode, - show_func show, store_func store) -{ - sysfs_attr_init(&dev_attr->attr); - dev_attr->attr.name = name; - dev_attr->attr.mode = mode; - dev_attr->show = show; - dev_attr->store = store; -} - -static struct cpld_sensor * add_sensor(struct cpld_data *data, - const char *name, - u8 reg, u8 mask, bool invert, - bool update, umode_t mode, - show_func get, store_func set) -{ - struct cpld_sensor *sensor; - struct device_attribute *a; - - sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL); - if (!sensor) - return NULL; - a = &sensor->attribute; - - snprintf(sensor->name, sizeof(sensor->name), name); - sensor->reg = reg; - sensor->mask = mask; - sensor->update = update; - sensor->invert = invert; - cpld_dev_attr_init(a, sensor->name, - mode, - get, set); - - if (cpld_add_attribute(data, &a->attr)) - return NULL; - - sensor->next = data->sensors; - data->sensors = sensor; - - return sensor; -} - -static int add_attributes_cmn(struct cpld_data *data, struct attrs **cmn) -{ - u8 reg, i ; - bool invert; - struct attrs *a; - struct base_attrs *b; - - if (NULL == cmn) - return -1; - - for (i = 0; cmn[i]; i++) - { - a = cmn[i]; - - reg = a->reg; - invert = a->invert; - - b = a->base; - if (NULL == b) - break; - - if (add_sensor(data, b->name, - reg, 0xff, invert, - true, b->mode, - b->get, b->set) == NULL) - { - return -ENOMEM; - } - } - return 0; -} - -static int add_attributes_portly(struct cpld_data *data, struct attrs **pa) -{ - char name[NAME_SIZE+1]; - int i, j; - u8 reg, mask, invert; - struct attrs *a; - struct base_attrs *b; - - if (NULL == pa) - return -1; - - - for (i = 0; pa[i]; i++) { - a = pa[i]; - - invert = a->invert; - b = a->base; - if (b == NULL) - break; - - for (j = 0; j < data->sfp_num; j++) - { - snprintf(name, NAME_SIZE, "%s_%d", b->name, j+1); - get_reg_bit(a->reg, j, ®, &mask); - - if (add_sensor(data, name, reg, mask, invert, - true, b->mode, b->get, b->set) == NULL) - { - return -ENOMEM; - } - } - } - return 0; -} - -static int add_attributes(struct i2c_client *client, - struct cpld_data *data) -{ - struct model_attrs *m = data->cmn_attr; - - if (m == NULL) - return -EINVAL; - - /* Common attributes.*/ - add_attributes_cmn(data, m->cmn); - - /* Port-wise attributes.*/ - add_attributes_portly(data, m->portly); - - return 0; -} - -static int accton_i2c_cpld_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - int status; - struct cpld_data *data = NULL; - struct device *dev = &client->dev; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - dev_dbg(dev, "i2c_check_functionality failed (0x%x)\n", client->addr); - return -EIO; - } - - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); - if (!data) { - return -ENOMEM; - } - - data->model = dev_id->driver_data; - data->cmn_attr = &models_attr[data->model]; - get_sfp_spec(data->model, &data->sfp_num, &data->sfp_types); - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->dev = dev; - dev_info(dev, "chip found\n"); - - status = add_attributes(client, data); - if (status) - goto out_kfree; - - /* - * If there are no attributes, something is wrong. - * Bail out instead of trying to register nothing. - */ - if (!data->num_attributes) { - dev_err(dev, "No attributes found\n"); - status = -ENODEV; - goto out_kfree; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &data->group); - if (status) { - goto out_kfree; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - accton_i2c_cpld_add_client(client); - dev_info(dev, "%s: cpld '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; -exit_remove: - sysfs_remove_group(&client->dev.kobj, &data->group); -out_kfree: - kfree(data->group.attrs); - return status; - -} - -static int accton_i2c_cpld_remove(struct i2c_client *client) -{ - struct cpld_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &data->group); - kfree(data->group.attrs); - accton_i2c_cpld_remove_client(client); - return 0; -} - -int accton_i2c_cpld_read(u8 cpld_addr, u8 reg) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EPERM; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_read_byte_data(cpld_node->client, reg); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(accton_i2c_cpld_read); - -int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EIO; - - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value); - break; - } - } - - mutex_unlock(&list_lock); - - return ret; -} -EXPORT_SYMBOL(accton_i2c_cpld_write); - - -static const struct i2c_device_id accton_i2c_cpld_id[] = { - { "cpld_as7712", AS7712_32X}, - { "cpld_as7716", AS7716_32X}, - { "cpld_as7816", AS7816_64X}, - { "cpld_as7312", AS7312_54X}, - { "cpld_plain", PLAIN_CPLD}, - { }, -}; -MODULE_DEVICE_TABLE(i2c, accton_i2c_cpld_id); - -static struct i2c_driver accton_i2c_cpld_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "accton_i2c_cpld", - }, - .probe = accton_i2c_cpld_probe, - .remove = accton_i2c_cpld_remove, - .id_table = accton_i2c_cpld_id, - .address_list = normal_i2c, -}; - - -static int __init accton_i2c_cpld_init(void) -{ - mutex_init(&list_lock); - return i2c_add_driver(&accton_i2c_cpld_driver); -} - -static void __exit accton_i2c_cpld_exit(void) -{ - i2c_del_driver(&accton_i2c_cpld_driver); -} - -module_init(accton_i2c_cpld_init); -module_exit(accton_i2c_cpld_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton_i2c_cpld driver"); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_pmbus_3y.c b/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_pmbus_3y.c deleted file mode 100644 index ed176189cdcd..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_pmbus_3y.c +++ /dev/null @@ -1,1978 +0,0 @@ -/* - * Hardware monitoring driver for 3Y power devices. - * - * Copyright (C) 2018 Accton Technology Corporation. - * Roy Lee - * - * Based on pmbus.c, pmbus.h and pmbus_core.c. - * Copyright 2012 Guenter Roeck/Ericsson AB. - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "pmbus.h" - - -enum chips { - YM2651, - YM2401, - YM2851, - LIMITED_CHIPS, -}; - - -/* - * Number of additional attribute pointers to allocate - * with each call to krealloc - */ -#define PMBUS_ATTR_ALLOC_SIZE 32 - -/* - * Index into status register array, per status register group - */ -#define PB_STATUS_BASE 0 -#define PB_STATUS_VOUT_BASE (PB_STATUS_BASE + PMBUS_PAGES) -#define PB_STATUS_IOUT_BASE (PB_STATUS_VOUT_BASE + PMBUS_PAGES) -#define PB_STATUS_FAN_BASE (PB_STATUS_IOUT_BASE + PMBUS_PAGES) -#define PB_STATUS_FAN34_BASE (PB_STATUS_FAN_BASE + PMBUS_PAGES) -#define PB_STATUS_TEMP_BASE (PB_STATUS_FAN34_BASE + PMBUS_PAGES) -#define PB_STATUS_INPUT_BASE (PB_STATUS_TEMP_BASE + PMBUS_PAGES) -#define PB_STATUS_VMON_BASE (PB_STATUS_INPUT_BASE + 1) - -#define PB_NUM_STATUS_REG (PB_STATUS_VMON_BASE + 1) - -#define PMBUS_NAME_SIZE 24 - -struct pmbus_sensor { - struct pmbus_sensor *next; - char name[PMBUS_NAME_SIZE]; /* sysfs sensor name */ - struct device_attribute attribute; - u8 page; /* page number */ - u16 reg; /* register */ - enum pmbus_sensor_classes class; /* sensor class */ - bool update; /* runtime sensor update needed */ - int data; /* Sensor data. - Negative if there was a read error */ -}; -#define to_pmbus_sensor(_attr) \ - container_of(_attr, struct pmbus_sensor, attribute) - -struct pmbus_boolean { - char name[PMBUS_NAME_SIZE]; /* sysfs boolean name */ - struct sensor_device_attribute attribute; - struct pmbus_sensor *s1; - struct pmbus_sensor *s2; -}; -#define to_pmbus_boolean(_attr) \ - container_of(_attr, struct pmbus_boolean, attribute) - -struct pmbus_label { - char name[PMBUS_NAME_SIZE]; /* sysfs label name */ - struct device_attribute attribute; - char label[PMBUS_NAME_SIZE]; /* label */ -}; -#define to_pmbus_label(_attr) \ - container_of(_attr, struct pmbus_label, attribute) - -struct pmbus_data { - struct device *dev; - struct device *hwmon_dev; - - u32 flags; /* from platform data */ - - int exponent[PMBUS_PAGES]; - /* linear mode: exponent for output voltages */ - - const struct pmbus_driver_info *info; - - int max_attributes; - int num_attributes; - struct attribute_group group; - const struct attribute_group *groups[2]; - - struct pmbus_sensor *sensors; - - struct mutex update_lock; - bool valid; - unsigned long last_updated; /* in jiffies */ - - /* - * A single status register covers multiple attributes, - * so we keep them all together. - */ - u8 status[PB_NUM_STATUS_REG]; - u8 status_register; - - u8 currpage; - bool linear_16; -}; - - -static int limited_models(const struct i2c_device_id *id); - -int _pmbus_set_page(struct i2c_client *client, u8 page) -{ - struct pmbus_data *data = i2c_get_clientdata(client); - int rv = 0; - int newpage; - - if (page != data->currpage) { - rv = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page); - newpage = i2c_smbus_read_byte_data(client, PMBUS_PAGE); - if (newpage != page) - rv = -EIO; - else - data->currpage = page; - } - return 0; -} - -/* - * _pmbus_write_byte() is similar to pmbus_write_byte(), but checks if - * a device specific mapping function exists and calls it if necessary. - */ -static int _pmbus_write_byte(struct i2c_client *client, int page, u8 value) -{ - struct pmbus_data *data = i2c_get_clientdata(client); - const struct pmbus_driver_info *info = data->info; - int status; - - if (info->write_byte) { - status = info->write_byte(client, page, value); - if (status != -ENODATA) - return status; - } - /*Ignore page*/ - return i2c_smbus_write_byte(client, value);; -} - -/* - * _pmbus_write_word_data() is similar to pmbus_write_word_data(), but checks if - * a device specific mapping function exists and calls it if necessary. - */ -static int _pmbus_write_word_data(struct i2c_client *client, int page, int reg, - u16 word) -{ - if (reg >= PMBUS_VIRT_BASE) - return -ENXIO; - /*Ignore page*/ - return i2c_smbus_write_word_data(client, reg, word); -} - -/* - * _pmbus_read_word_data() is similar to pmbus_read_word_data(), but checks if - * a device specific mapping function exists and calls it if necessary. - */ -static int _pmbus_read_word_data(struct i2c_client *client, int page, int reg) -{ - /*Ignore page*/ - return i2c_smbus_read_word_data(client, reg);; -} - -/* - * _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if - * a device specific mapping function exists and calls it if necessary. - */ -static int _pmbus_read_byte_data(struct i2c_client *client, int page, int reg) -{ - if (reg >= PMBUS_VIRT_BASE) - return -ENXIO; - - /*Ignore page*/ - return i2c_smbus_read_byte_data(client, reg); -} - -static void pmbus_clear_fault_page(struct i2c_client *client, int page) -{ - _pmbus_write_byte(client, page, PMBUS_CLEAR_FAULTS); -} - - -static int pmbus_check_status_cml(struct i2c_client *client) -{ - struct pmbus_data *data = i2c_get_clientdata(client); - int status, status2; - - status = _pmbus_read_byte_data(client, -1, data->status_register); - if (status < 0 || (status & PB_STATUS_CML)) { - status2 = _pmbus_read_byte_data(client, -1, PMBUS_STATUS_CML); - if (status2 < 0 || (status2 & PB_CML_FAULT_INVALID_COMMAND)) - return -EIO; - } - return 0; -} - -static bool pmbus_check_register(struct i2c_client *client, - int (*func)(struct i2c_client *client, - int page, int reg), - int page, int reg) -{ - int rv; - struct pmbus_data *data = i2c_get_clientdata(client); - - if((data->flags & PMBUS_SKIP_STATUS_CHECK)) - return 1; - - rv = func(client, page, reg); - if (rv >= 0) - rv = pmbus_check_status_cml(client); - pmbus_clear_fault_page(client, -1); - return rv >= 0; -} - -static struct _pmbus_status { - u32 func; - u16 base; - u16 reg; -} pmbus_status[] = { - { PMBUS_HAVE_STATUS_VOUT, PB_STATUS_VOUT_BASE, PMBUS_STATUS_VOUT }, - { PMBUS_HAVE_STATUS_IOUT, PB_STATUS_IOUT_BASE, PMBUS_STATUS_IOUT }, - { PMBUS_HAVE_STATUS_TEMP, PB_STATUS_TEMP_BASE, - PMBUS_STATUS_TEMPERATURE - }, - { PMBUS_HAVE_STATUS_FAN12, PB_STATUS_FAN_BASE, PMBUS_STATUS_FAN_12 }, - { PMBUS_HAVE_STATUS_FAN34, PB_STATUS_FAN34_BASE, PMBUS_STATUS_FAN_34 }, -}; - -void _pmbus_clear_faults(struct i2c_client *client) -{ - struct pmbus_data *data = i2c_get_clientdata(client); - int i; - - for (i = 0; i < data->info->pages; i++) - pmbus_clear_fault_page(client, i); -} -static struct pmbus_data *pmbus_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev->parent); - struct pmbus_data *data = i2c_get_clientdata(client); - const struct pmbus_driver_info *info = data->info; - struct pmbus_sensor *sensor; - - mutex_lock(&data->update_lock); - if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { - int i, j; - - for (i = 0; i < info->pages; i++) { - data->status[PB_STATUS_BASE + i] - = _pmbus_read_byte_data(client, i, - data->status_register); - for (j = 0; j < ARRAY_SIZE(pmbus_status); j++) { - struct _pmbus_status *s = &pmbus_status[j]; - - if (!(info->func[i] & s->func)) - continue; - data->status[s->base + i] - = _pmbus_read_byte_data(client, i, - s->reg); - } - } - - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) - data->status[PB_STATUS_INPUT_BASE] - = _pmbus_read_byte_data(client, 0, - PMBUS_STATUS_INPUT); - - if (info->func[0] & PMBUS_HAVE_STATUS_VMON) - data->status[PB_STATUS_VMON_BASE] - = _pmbus_read_byte_data(client, 0, - PMBUS_VIRT_STATUS_VMON); - - for (sensor = data->sensors; sensor; sensor = sensor->next) { - if (!data->valid || sensor->update) - sensor->data - = _pmbus_read_word_data(client, - sensor->page, - sensor->reg); - } - _pmbus_clear_faults(client); - data->last_updated = jiffies; - data->valid = 1; - } - mutex_unlock(&data->update_lock); - return data; -} - -/* - * Convert linear sensor values to milli- or micro-units - * depending on sensor type. - */ -static long pmbus_reg2data_linear(struct pmbus_data *data, - struct pmbus_sensor *sensor) -{ - s16 exponent; - s32 mantissa; - long val; - - /* LINEAR16 */ - if ( data->linear_16 && - sensor->class == PSC_VOLTAGE_OUT) { - exponent = data->exponent[sensor->page]; - mantissa = (u16) sensor->data; - } else - { /* LINEAR11 */ - exponent = ((s16)sensor->data) >> 11; - mantissa = ((s16)((sensor->data & 0x7ff) << 5)) >> 5; - } - - val = mantissa; - - /* scale result to milli-units for all sensors except fans */ - if (sensor->class != PSC_FAN) - val = val * 1000L; - - /* scale result to micro-units for power sensors */ - if (sensor->class == PSC_POWER) - val = val * 1000L; - - if (exponent >= 0) - val <<= exponent; - else - val >>= -exponent; - - return val; -} - -/* - * Convert direct sensor values to milli- or micro-units - * depending on sensor type. - */ -static long pmbus_reg2data_direct(struct pmbus_data *data, - struct pmbus_sensor *sensor) -{ - long val = (s16) sensor->data; - long m, b, R; - - m = data->info->m[sensor->class]; - b = data->info->b[sensor->class]; - R = data->info->R[sensor->class]; - - if (m == 0) - return 0; - - /* X = 1/m * (Y * 10^-R - b) */ - R = -R; - /* scale result to milli-units for everything but fans */ - if (sensor->class != PSC_FAN) { - R += 3; - b *= 1000; - } - - /* scale result to micro-units for power sensors */ - if (sensor->class == PSC_POWER) { - R += 3; - b *= 1000; - } - - while (R > 0) { - val *= 10; - R--; - } - while (R < 0) { - val = DIV_ROUND_CLOSEST(val, 10); - R++; - } - - return (val - b) / m; -} - -/* - * Convert VID sensor values to milli- or micro-units - * depending on sensor type. - * We currently only support VR11. - */ -static long pmbus_reg2data_vid(struct pmbus_data *data, - struct pmbus_sensor *sensor) -{ - long val = sensor->data; - - if (val < 0x02 || val > 0xb2) - return 0; - return DIV_ROUND_CLOSEST(160000 - (val - 2) * 625, 100); -} - -static long pmbus_reg2data(struct pmbus_data *data, struct pmbus_sensor *sensor) -{ - long val; - - switch (data->info->format[sensor->class]) { - case direct: - val = pmbus_reg2data_direct(data, sensor); - break; - case vid: - val = pmbus_reg2data_vid(data, sensor); - break; - case linear: - default: - val = pmbus_reg2data_linear(data, sensor); - break; - } - return val; -} - -#define MAX_MANTISSA (1023 * 1000) -#define MIN_MANTISSA (511 * 1000) - -static u16 pmbus_data2reg_linear(struct pmbus_data *data, - struct pmbus_sensor *sensor, long val) -{ - s16 exponent = 0, mantissa; - bool negative = false; - - /* simple case */ - if (val == 0) - return 0; - - if (data->linear_16 && - sensor->class == PSC_VOLTAGE_OUT) { - /* LINEAR16 does not support negative voltages */ - if (val < 0) - return 0; - - /* - * For a static exponents, we don't have a choice - * but to adjust the value to it. - */ - if (data->exponent[sensor->page] < 0) - val <<= -data->exponent[sensor->page]; - else - val >>= data->exponent[sensor->page]; - val = DIV_ROUND_CLOSEST(val, 1000); - return val & 0xffff; - } - - if (val < 0) { - negative = true; - val = -val; - } - - /* Power is in uW. Convert to mW before converting. */ - if (sensor->class == PSC_POWER) - val = DIV_ROUND_CLOSEST(val, 1000L); - - /* - * For simplicity, convert fan data to milli-units - * before calculating the exponent. - */ - if (sensor->class == PSC_FAN) - val = val * 1000; - - /* Reduce large mantissa until it fits into 10 bit */ - while (val >= MAX_MANTISSA && exponent < 15) { - exponent++; - val >>= 1; - } - /* Increase small mantissa to improve precision */ - while (val < MIN_MANTISSA && exponent > -15) { - exponent--; - val <<= 1; - } - - /* Convert mantissa from milli-units to units */ - mantissa = DIV_ROUND_CLOSEST(val, 1000); - - /* Ensure that resulting number is within range */ - if (mantissa > 0x3ff) - mantissa = 0x3ff; - - /* restore sign */ - if (negative) - mantissa = -mantissa; - - /* Convert to 5 bit exponent, 11 bit mantissa */ - return (mantissa & 0x7ff) | ((exponent << 11) & 0xf800); -} - -static u16 pmbus_data2reg_direct(struct pmbus_data *data, - struct pmbus_sensor *sensor, long val) -{ - long m, b, R; - - m = data->info->m[sensor->class]; - b = data->info->b[sensor->class]; - R = data->info->R[sensor->class]; - - /* Power is in uW. Adjust R and b. */ - if (sensor->class == PSC_POWER) { - R -= 3; - b *= 1000; - } - - /* Calculate Y = (m * X + b) * 10^R */ - if (sensor->class != PSC_FAN) { - R -= 3; /* Adjust R and b for data in milli-units */ - b *= 1000; - } - val = val * m + b; - - while (R > 0) { - val *= 10; - R--; - } - while (R < 0) { - val = DIV_ROUND_CLOSEST(val, 10); - R++; - } - - return val; -} - -static u16 pmbus_data2reg_vid(struct pmbus_data *data, - struct pmbus_sensor *sensor, long val) -{ - val = clamp_val(val, 500, 1600); - - return 2 + DIV_ROUND_CLOSEST((1600 - val) * 100, 625); -} - -static u16 pmbus_data2reg(struct pmbus_data *data, - struct pmbus_sensor *sensor, long val) -{ - u16 regval; - - switch (data->info->format[sensor->class]) { - case direct: - regval = pmbus_data2reg_direct(data, sensor, val); - break; - case vid: - regval = pmbus_data2reg_vid(data, sensor, val); - break; - case linear: - default: - regval = pmbus_data2reg_linear(data, sensor, val); - break; - } - return regval; -} - -/* - * Return boolean calculated from converted data. - * defines a status register index and mask. - * The mask is in the lower 8 bits, the register index is in bits 8..23. - * - * The associated pmbus_boolean structure contains optional pointers to two - * sensor attributes. If specified, those attributes are compared against each - * other to determine if a limit has been exceeded. - * - * If the sensor attribute pointers are NULL, the function returns true if - * (status[reg] & mask) is true. - * - * If sensor attribute pointers are provided, a comparison against a specified - * limit has to be performed to determine the boolean result. - * In this case, the function returns true if v1 >= v2 (where v1 and v2 are - * sensor values referenced by sensor attribute pointers s1 and s2). - * - * To determine if an object exceeds upper limits, specify = . - * To determine if an object exceeds lower limits, specify = . - * - * If a negative value is stored in any of the referenced registers, this value - * reflects an error code which will be returned. - */ -static int pmbus_get_boolean(struct pmbus_data *data, struct pmbus_boolean *b, - int index) -{ - struct pmbus_sensor *s1 = b->s1; - struct pmbus_sensor *s2 = b->s2; - u16 reg = (index >> 8) & 0xffff; - u8 mask = index & 0xff; - int ret, status; - u8 regval; - - status = data->status[reg]; - if (status < 0) - return status; - - regval = status & mask; - if (!s1 && !s2) { - ret = !!regval; - } else if (!s1 || !s2) { - WARN(1, "Bad boolean descriptor %p: s1=%p, s2=%p\n", b, s1, s2); - return 0; - } else { - long v1, v2; - - if (s1->data < 0) - return s1->data; - if (s2->data < 0) - return s2->data; - - v1 = pmbus_reg2data(data, s1); - v2 = pmbus_reg2data(data, s2); - ret = !!(regval && v1 >= v2); - } - return ret; -} - -static ssize_t pmbus_show_boolean(struct device *dev, - struct device_attribute *da, char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct pmbus_boolean *boolean = to_pmbus_boolean(attr); - struct pmbus_data *data = pmbus_update_device(dev); - int val; - - val = pmbus_get_boolean(data, boolean, attr->index); - if (val < 0) { - return snprintf(buf, PAGE_SIZE, "%d\n", 1); - } - return snprintf(buf, PAGE_SIZE, "%d\n", val); -} - -static ssize_t pmbus_show_sensor(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct pmbus_data *data = pmbus_update_device(dev); - struct pmbus_sensor *sensor = to_pmbus_sensor(devattr); - - - if (sensor->data < 0) { - return snprintf(buf, PAGE_SIZE, "%d\n", 0); - } - - - return snprintf(buf, PAGE_SIZE, "%ld\n", pmbus_reg2data(data, sensor)); -} - -static ssize_t pmbus_set_sensor(struct device *dev, - struct device_attribute *devattr, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev->parent); - struct pmbus_data *data = i2c_get_clientdata(client); - struct pmbus_sensor *sensor = to_pmbus_sensor(devattr); - ssize_t rv = count; - long val = 0; - int ret; - u16 regval; - - if (kstrtol(buf, 10, &val) < 0) - return -EINVAL; - - mutex_lock(&data->update_lock); - regval = pmbus_data2reg(data, sensor, val); - ret = _pmbus_write_word_data(client, sensor->page, sensor->reg, regval); - if (ret < 0) - rv = ret; - else - sensor->data = regval; - mutex_unlock(&data->update_lock); - return rv; -} - -static ssize_t pmbus_show_label(struct device *dev, - struct device_attribute *da, char *buf) -{ - struct pmbus_label *label = to_pmbus_label(da); - - return snprintf(buf, PAGE_SIZE, "%s\n", label->label); -} - -static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr) -{ - if (data->num_attributes >= data->max_attributes - 1) { - int new_max_attrs = data->max_attributes + PMBUS_ATTR_ALLOC_SIZE; - void *new_attrs = krealloc(data->group.attrs, - new_max_attrs * sizeof(void *), - GFP_KERNEL); - if (!new_attrs) - return -ENOMEM; - data->group.attrs = new_attrs; - data->max_attributes = new_max_attrs; - } - - - - data->group.attrs[data->num_attributes++] = attr; - data->group.attrs[data->num_attributes] = NULL; - return 0; -} - -static void pmbus_dev_attr_init(struct device_attribute *dev_attr, - const char *name, - umode_t mode, - ssize_t (*show)(struct device *dev, - struct device_attribute *attr, - char *buf), - ssize_t (*store)(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count)) -{ - sysfs_attr_init(&dev_attr->attr); - dev_attr->attr.name = name; - dev_attr->attr.mode = mode; - dev_attr->show = show; - dev_attr->store = store; -} - -static void pmbus_attr_init(struct sensor_device_attribute *a, - const char *name, - umode_t mode, - ssize_t (*show)(struct device *dev, - struct device_attribute *attr, - char *buf), - ssize_t (*store)(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count), - int idx) -{ - pmbus_dev_attr_init(&a->dev_attr, name, mode, show, store); - a->index = idx; -} - -static int pmbus_add_boolean(struct pmbus_data *data, - const char *name, const char *type, int seq, - struct pmbus_sensor *s1, - struct pmbus_sensor *s2, - u16 reg, u8 mask) -{ - struct pmbus_boolean *boolean; - struct sensor_device_attribute *a; - - boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL); - if (!boolean) - return -ENOMEM; - - a = &boolean->attribute; - - snprintf(boolean->name, sizeof(boolean->name), "%s%d_%s", - name, seq, type); - boolean->s1 = s1; - boolean->s2 = s2; - pmbus_attr_init(a, boolean->name, S_IRUGO, pmbus_show_boolean, NULL, - (reg << 8) | mask); - - return pmbus_add_attribute(data, &a->dev_attr.attr); -} - -static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data, - const char *name, const char *type, - int seq, int page, int reg, - enum pmbus_sensor_classes class, - bool update, bool readonly) -{ - struct pmbus_sensor *sensor; - struct device_attribute *a; - - sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL); - if (!sensor) - return NULL; - a = &sensor->attribute; - - snprintf(sensor->name, sizeof(sensor->name), "%s%d_%s", - name, seq, type); - sensor->page = page; - sensor->reg = reg; - sensor->class = class; - sensor->update = update; - pmbus_dev_attr_init(a, sensor->name, - readonly ? S_IRUGO : S_IRUGO | S_IWUSR, - pmbus_show_sensor, pmbus_set_sensor); - - if (pmbus_add_attribute(data, &a->attr)) - return NULL; - - sensor->next = data->sensors; - data->sensors = sensor; - - return sensor; -} - -static int pmbus_add_label(struct pmbus_data *data, - const char *name, int seq, - const char *lstring, int index) -{ - struct pmbus_label *label; - struct device_attribute *a; - - label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL); - if (!label) - return -ENOMEM; - - a = &label->attribute; - - snprintf(label->name, sizeof(label->name), "%s%d_label", name, seq); - if (!index) - strncpy(label->label, lstring, sizeof(label->label) - 1); - else - snprintf(label->label, sizeof(label->label), "%s%d", lstring, - index); - - pmbus_dev_attr_init(a, label->name, S_IRUGO, pmbus_show_label, NULL); - return pmbus_add_attribute(data, &a->attr); -} - -/* - * Search for attributes. Allocate sensors, booleans, and labels as needed. - */ - -/* - * The pmbus_limit_attr structure describes a single limit attribute - * and its associated alarm attribute. - */ -struct pmbus_limit_attr { - u16 reg; /* Limit register */ - u16 sbit; /* Alarm attribute status bit */ - bool update; /* True if register needs updates */ - bool low; /* True if low limit; for limits with compare - functions only */ - const char *attr; /* Attribute name */ - const char *alarm; /* Alarm attribute name */ -}; - -/* - * The pmbus_sensor_attr structure describes one sensor attribute. This - * description includes a reference to the associated limit attributes. - */ -struct pmbus_sensor_attr { - u16 reg; /* sensor register */ - u8 gbit; /* generic status bit */ - u8 nlimit; /* # of limit registers */ - enum pmbus_sensor_classes class;/* sensor class */ - const char *label; /* sensor label */ - bool paged; /* true if paged sensor */ - bool update; /* true if update needed */ - bool compare; /* true if compare function needed */ - u32 func; /* sensor mask */ - u32 sfunc; /* sensor status mask */ - int sbase; /* status base register */ - const struct pmbus_limit_attr *limit;/* limit registers */ -}; - -/* - * Add a set of limit attributes and, if supported, the associated - * alarm attributes. - * returns 0 if no alarm register found, 1 if an alarm register was found, - * < 0 on errors. - */ -static int pmbus_add_limit_attrs(struct i2c_client *client, - struct pmbus_data *data, - const struct pmbus_driver_info *info, - const char *name, int index, int page, - struct pmbus_sensor *base, - const struct pmbus_sensor_attr *attr) -{ - const struct pmbus_limit_attr *l = attr->limit; - int nlimit = attr->nlimit; - int have_alarm = 0; - int i, ret; - struct pmbus_sensor *curr; - - for (i = 0; i < nlimit; i++) { - if (_pmbus_check_word_register(client, page, l->reg)) - { - curr = pmbus_add_sensor(data, name, l->attr, index, - page, l->reg, attr->class, - attr->update || l->update, - false); - if (!curr) - return -ENOMEM; - if (l->sbit && (info->func[page] & attr->sfunc)) { - ret = pmbus_add_boolean(data, name, - l->alarm, index, - attr->compare ? l->low ? curr : base - : NULL, - attr->compare ? l->low ? base : curr - : NULL, - attr->sbase + page, l->sbit); - if (ret) - return ret; - have_alarm = 1; - } - } - l++; - } - return have_alarm; -} - -bool _pmbus_check_byte_register(struct i2c_client *client, int page, int reg) -{ - return pmbus_check_register(client, _pmbus_read_byte_data, page, reg); -} - - -bool _pmbus_check_word_register(struct i2c_client *client, int page, int reg) -{ - return pmbus_check_register(client, _pmbus_read_word_data, page, reg); -} - -static int pmbus_add_sensor_attrs_one(struct i2c_client *client, - struct pmbus_data *data, - const struct pmbus_driver_info *info, - const char *name, - int index, int page, - const struct pmbus_sensor_attr *attr) -{ - struct pmbus_sensor *base; - int ret; - - if (attr->label) { - ret = pmbus_add_label(data, name, index, attr->label, - attr->paged ? page + 1 : 0); - if (ret) - return ret; - } - base = pmbus_add_sensor(data, name, "input", index, page, attr->reg, - attr->class, true, true); - - - if (!base) - return -ENOMEM; - - if (attr->sfunc) { - ret = pmbus_add_limit_attrs(client, data, info, name, - index, page, base, attr); - if (ret < 0) - return ret; - /* - * Add generic alarm attribute only if there are no individual - * alarm attributes, if there is a global alarm bit, and if - * the generic status register for this page is accessible. - */ - if (!ret && attr->gbit && - _pmbus_check_byte_register(client, page, - data->status_register)) { - ret = pmbus_add_boolean(data, name, "alarm", index, - NULL, NULL, - PB_STATUS_BASE + page, - attr->gbit); - if (ret) - return ret; - } - } - return 0; -} - -static int pmbus_add_sensor_attrs(struct i2c_client *client, - struct pmbus_data *data, - const char *name, - const struct pmbus_sensor_attr *attrs, - int nattrs) -{ - const struct pmbus_driver_info *info = data->info; - int index, i; - int ret; - - index = 1; - for (i = 0; i < nattrs; i++) { - int page, pages; - - pages = attrs->paged ? info->pages : 1; - for (page = 0; page < pages; page++) { - if (!(info->func[page] & attrs->func)) - continue; - ret = pmbus_add_sensor_attrs_one(client, data, info, - name, index, page, - attrs); - if (ret) - return ret; - index++; - } - attrs++; - } - return 0; -} - -static const struct pmbus_limit_attr vin_limit_attrs[] = { - { - .reg = PMBUS_VIN_UV_WARN_LIMIT, - .attr = "min", - .alarm = "min_alarm", - .sbit = PB_VOLTAGE_UV_WARNING, - }, { - .reg = PMBUS_VIN_UV_FAULT_LIMIT, - .attr = "lcrit", - .alarm = "lcrit_alarm", - .sbit = PB_VOLTAGE_UV_FAULT, - }, { - .reg = PMBUS_VIN_OV_WARN_LIMIT, - .attr = "max", - .alarm = "max_alarm", - .sbit = PB_VOLTAGE_OV_WARNING, - }, { - .reg = PMBUS_VIN_OV_FAULT_LIMIT, - .attr = "crit", - .alarm = "crit_alarm", - .sbit = PB_VOLTAGE_OV_FAULT, - }, { - .reg = PMBUS_VIRT_READ_VIN_AVG, - .update = true, - .attr = "average", - }, { - .reg = PMBUS_VIRT_READ_VIN_MIN, - .update = true, - .attr = "lowest", - }, { - .reg = PMBUS_VIRT_READ_VIN_MAX, - .update = true, - .attr = "highest", - }, { - .reg = PMBUS_VIRT_RESET_VIN_HISTORY, - .attr = "reset_history", - }, -}; - -static const struct pmbus_limit_attr vmon_limit_attrs[] = { - { - .reg = PMBUS_VIRT_VMON_UV_WARN_LIMIT, - .attr = "min", - .alarm = "min_alarm", - .sbit = PB_VOLTAGE_UV_WARNING, - }, { - .reg = PMBUS_VIRT_VMON_UV_FAULT_LIMIT, - .attr = "lcrit", - .alarm = "lcrit_alarm", - .sbit = PB_VOLTAGE_UV_FAULT, - }, { - .reg = PMBUS_VIRT_VMON_OV_WARN_LIMIT, - .attr = "max", - .alarm = "max_alarm", - .sbit = PB_VOLTAGE_OV_WARNING, - }, { - .reg = PMBUS_VIRT_VMON_OV_FAULT_LIMIT, - .attr = "crit", - .alarm = "crit_alarm", - .sbit = PB_VOLTAGE_OV_FAULT, - } -}; - -static const struct pmbus_limit_attr vout_limit_attrs[] = { - { - .reg = PMBUS_VOUT_UV_WARN_LIMIT, - .attr = "min", - .alarm = "min_alarm", - .sbit = PB_VOLTAGE_UV_WARNING, - }, { - .reg = PMBUS_VOUT_UV_FAULT_LIMIT, - .attr = "lcrit", - .alarm = "lcrit_alarm", - .sbit = PB_VOLTAGE_UV_FAULT, - }, { - .reg = PMBUS_VOUT_OV_WARN_LIMIT, - .attr = "max", - .alarm = "max_alarm", - .sbit = PB_VOLTAGE_OV_WARNING, - }, { - .reg = PMBUS_VOUT_OV_FAULT_LIMIT, - .attr = "crit", - .alarm = "crit_alarm", - .sbit = PB_VOLTAGE_OV_FAULT, - }, { - .reg = PMBUS_VIRT_READ_VOUT_AVG, - .update = true, - .attr = "average", - }, { - .reg = PMBUS_VIRT_READ_VOUT_MIN, - .update = true, - .attr = "lowest", - }, { - .reg = PMBUS_VIRT_READ_VOUT_MAX, - .update = true, - .attr = "highest", - }, { - .reg = PMBUS_VIRT_RESET_VOUT_HISTORY, - .attr = "reset_history", - } -}; - -static const struct pmbus_sensor_attr voltage_attributes[] = { - { - .reg = PMBUS_READ_VIN, - .class = PSC_VOLTAGE_IN, - .label = "vin", - .func = PMBUS_HAVE_VIN, - .sfunc = PMBUS_HAVE_STATUS_INPUT, - .sbase = PB_STATUS_INPUT_BASE, - .gbit = PB_STATUS_VIN_UV, - .limit = vin_limit_attrs, - .nlimit = ARRAY_SIZE(vin_limit_attrs), - }, { - .reg = PMBUS_VIRT_READ_VMON, - .class = PSC_VOLTAGE_IN, - .label = "vmon", - .func = PMBUS_HAVE_VMON, - .sfunc = PMBUS_HAVE_STATUS_VMON, - .sbase = PB_STATUS_VMON_BASE, - .limit = vmon_limit_attrs, - .nlimit = ARRAY_SIZE(vmon_limit_attrs), - }, { - .reg = PMBUS_READ_VCAP, - .class = PSC_VOLTAGE_IN, - .label = "vcap", - .func = PMBUS_HAVE_VCAP, - }, { - .reg = PMBUS_READ_VOUT, - .class = PSC_VOLTAGE_OUT, - .label = "vout", - .paged = true, - .func = PMBUS_HAVE_VOUT, - .sfunc = PMBUS_HAVE_STATUS_VOUT, - .sbase = PB_STATUS_VOUT_BASE, - .gbit = PB_STATUS_VOUT_OV, - .limit = vout_limit_attrs, - .nlimit = ARRAY_SIZE(vout_limit_attrs), - } -}; - -/* Current attributes */ - -static const struct pmbus_limit_attr iin_limit_attrs[] = { - { - .reg = PMBUS_IIN_OC_WARN_LIMIT, - .attr = "max", - .alarm = "max_alarm", - .sbit = PB_IIN_OC_WARNING, - }, { - .reg = PMBUS_IIN_OC_FAULT_LIMIT, - .attr = "crit", - .alarm = "crit_alarm", - .sbit = PB_IIN_OC_FAULT, - }, { - .reg = PMBUS_VIRT_READ_IIN_AVG, - .update = true, - .attr = "average", - }, { - .reg = PMBUS_VIRT_READ_IIN_MIN, - .update = true, - .attr = "lowest", - }, { - .reg = PMBUS_VIRT_READ_IIN_MAX, - .update = true, - .attr = "highest", - }, { - .reg = PMBUS_VIRT_RESET_IIN_HISTORY, - .attr = "reset_history", - } -}; - -static const struct pmbus_limit_attr iout_limit_attrs[] = { - { - .reg = PMBUS_IOUT_OC_WARN_LIMIT, - .attr = "max", - .alarm = "max_alarm", - .sbit = PB_IOUT_OC_WARNING, - }, { - .reg = PMBUS_IOUT_UC_FAULT_LIMIT, - .attr = "lcrit", - .alarm = "lcrit_alarm", - .sbit = PB_IOUT_UC_FAULT, - }, { - .reg = PMBUS_IOUT_OC_FAULT_LIMIT, - .attr = "crit", - .alarm = "crit_alarm", - .sbit = PB_IOUT_OC_FAULT, - }, { - .reg = PMBUS_VIRT_READ_IOUT_AVG, - .update = true, - .attr = "average", - }, { - .reg = PMBUS_VIRT_READ_IOUT_MIN, - .update = true, - .attr = "lowest", - }, { - .reg = PMBUS_VIRT_READ_IOUT_MAX, - .update = true, - .attr = "highest", - }, { - .reg = PMBUS_VIRT_RESET_IOUT_HISTORY, - .attr = "reset_history", - } -}; - -static const struct pmbus_sensor_attr current_attributes[] = { - { - .reg = PMBUS_READ_IIN, - .class = PSC_CURRENT_IN, - .label = "iin", - .func = PMBUS_HAVE_IIN, - .sfunc = PMBUS_HAVE_STATUS_INPUT, - .sbase = PB_STATUS_INPUT_BASE, - .limit = iin_limit_attrs, - .nlimit = ARRAY_SIZE(iin_limit_attrs), - }, { - .reg = PMBUS_READ_IOUT, - .class = PSC_CURRENT_OUT, - .label = "iout", - .paged = true, - .func = PMBUS_HAVE_IOUT, - .sfunc = PMBUS_HAVE_STATUS_IOUT, - .sbase = PB_STATUS_IOUT_BASE, - .gbit = PB_STATUS_IOUT_OC, - .limit = iout_limit_attrs, - .nlimit = ARRAY_SIZE(iout_limit_attrs), - } -}; - -/* Power attributes */ - -static const struct pmbus_limit_attr pin_limit_attrs[] = { - { - .reg = PMBUS_PIN_OP_WARN_LIMIT, - .attr = "max", - .alarm = "alarm", - .sbit = PB_PIN_OP_WARNING, - }, { - .reg = PMBUS_VIRT_READ_PIN_AVG, - .update = true, - .attr = "average", - }, { - .reg = PMBUS_VIRT_READ_PIN_MAX, - .update = true, - .attr = "input_highest", - }, { - .reg = PMBUS_VIRT_RESET_PIN_HISTORY, - .attr = "reset_history", - } -}; - -static const struct pmbus_limit_attr pout_limit_attrs[] = { - { - .reg = PMBUS_POUT_MAX, - .attr = "cap", - .alarm = "cap_alarm", - .sbit = PB_POWER_LIMITING, - }, { - .reg = PMBUS_POUT_OP_WARN_LIMIT, - .attr = "max", - .alarm = "max_alarm", - .sbit = PB_POUT_OP_WARNING, - }, { - .reg = PMBUS_POUT_OP_FAULT_LIMIT, - .attr = "crit", - .alarm = "crit_alarm", - .sbit = PB_POUT_OP_FAULT, - }, { - .reg = PMBUS_VIRT_READ_POUT_AVG, - .update = true, - .attr = "average", - }, { - .reg = PMBUS_VIRT_READ_POUT_MAX, - .update = true, - .attr = "input_highest", - }, { - .reg = PMBUS_VIRT_RESET_POUT_HISTORY, - .attr = "reset_history", - } -}; - -static const struct pmbus_sensor_attr power_attributes[] = { - { - .reg = PMBUS_READ_PIN, - .class = PSC_POWER, - .label = "pin", - .func = PMBUS_HAVE_PIN, - .sfunc = PMBUS_HAVE_STATUS_INPUT, - .sbase = PB_STATUS_INPUT_BASE, - .limit = pin_limit_attrs, - .nlimit = ARRAY_SIZE(pin_limit_attrs), - }, { - .reg = PMBUS_READ_POUT, - .class = PSC_POWER, - .label = "pout", - .paged = true, - .func = PMBUS_HAVE_POUT, - .sfunc = PMBUS_HAVE_STATUS_IOUT, - .sbase = PB_STATUS_IOUT_BASE, - .limit = pout_limit_attrs, - .nlimit = ARRAY_SIZE(pout_limit_attrs), - } -}; - -/* Temperature atributes */ - -static const struct pmbus_limit_attr temp_limit_attrs[] = { - { - .reg = PMBUS_UT_WARN_LIMIT, - .low = true, - .attr = "min", - .alarm = "min_alarm", - .sbit = PB_TEMP_UT_WARNING, - }, { - .reg = PMBUS_UT_FAULT_LIMIT, - .low = true, - .attr = "lcrit", - .alarm = "lcrit_alarm", - .sbit = PB_TEMP_UT_FAULT, - }, { - .reg = PMBUS_OT_WARN_LIMIT, - .attr = "max", - .alarm = "max_alarm", - .sbit = PB_TEMP_OT_WARNING, - }, { - .reg = PMBUS_OT_FAULT_LIMIT, - .attr = "crit", - .alarm = "crit_alarm", - .sbit = PB_TEMP_OT_FAULT, - }, { - .reg = PMBUS_VIRT_READ_TEMP_MIN, - .attr = "lowest", - }, { - .reg = PMBUS_VIRT_READ_TEMP_AVG, - .attr = "average", - }, { - .reg = PMBUS_VIRT_READ_TEMP_MAX, - .attr = "highest", - }, { - .reg = PMBUS_VIRT_RESET_TEMP_HISTORY, - .attr = "reset_history", - } -}; - -static const struct pmbus_limit_attr temp_limit_attrs2[] = { - { - .reg = PMBUS_UT_WARN_LIMIT, - .low = true, - .attr = "min", - .alarm = "min_alarm", - .sbit = PB_TEMP_UT_WARNING, - }, { - .reg = PMBUS_UT_FAULT_LIMIT, - .low = true, - .attr = "lcrit", - .alarm = "lcrit_alarm", - .sbit = PB_TEMP_UT_FAULT, - }, { - .reg = PMBUS_OT_WARN_LIMIT, - .attr = "max", - .alarm = "max_alarm", - .sbit = PB_TEMP_OT_WARNING, - }, { - .reg = PMBUS_OT_FAULT_LIMIT, - .attr = "crit", - .alarm = "crit_alarm", - .sbit = PB_TEMP_OT_FAULT, - }, { - .reg = PMBUS_VIRT_READ_TEMP2_MIN, - .attr = "lowest", - }, { - .reg = PMBUS_VIRT_READ_TEMP2_AVG, - .attr = "average", - }, { - .reg = PMBUS_VIRT_READ_TEMP2_MAX, - .attr = "highest", - }, { - .reg = PMBUS_VIRT_RESET_TEMP2_HISTORY, - .attr = "reset_history", - } -}; - -static const struct pmbus_limit_attr temp_limit_attrs3[] = { - { - .reg = PMBUS_UT_WARN_LIMIT, - .low = true, - .attr = "min", - .alarm = "min_alarm", - .sbit = PB_TEMP_UT_WARNING, - }, { - .reg = PMBUS_UT_FAULT_LIMIT, - .low = true, - .attr = "lcrit", - .alarm = "lcrit_alarm", - .sbit = PB_TEMP_UT_FAULT, - }, { - .reg = PMBUS_OT_WARN_LIMIT, - .attr = "max", - .alarm = "max_alarm", - .sbit = PB_TEMP_OT_WARNING, - }, { - .reg = PMBUS_OT_FAULT_LIMIT, - .attr = "crit", - .alarm = "crit_alarm", - .sbit = PB_TEMP_OT_FAULT, - } -}; - -static const struct pmbus_sensor_attr temp_attributes[] = { - { - .reg = PMBUS_READ_TEMPERATURE_1, - .class = PSC_TEMPERATURE, - .paged = true, - .update = true, - .compare = true, - .func = PMBUS_HAVE_TEMP, - .sfunc = PMBUS_HAVE_STATUS_TEMP, - .sbase = PB_STATUS_TEMP_BASE, - .gbit = PB_STATUS_TEMPERATURE, - .limit = temp_limit_attrs, - .nlimit = ARRAY_SIZE(temp_limit_attrs), - }, { - .reg = PMBUS_READ_TEMPERATURE_2, - .class = PSC_TEMPERATURE, - .paged = true, - .update = true, - .compare = true, - .func = PMBUS_HAVE_TEMP2, - .sfunc = PMBUS_HAVE_STATUS_TEMP, - .sbase = PB_STATUS_TEMP_BASE, - .gbit = PB_STATUS_TEMPERATURE, - .limit = temp_limit_attrs2, - .nlimit = ARRAY_SIZE(temp_limit_attrs2), - }, { - .reg = PMBUS_READ_TEMPERATURE_3, - .class = PSC_TEMPERATURE, - .paged = true, - .update = true, - .compare = true, - .func = PMBUS_HAVE_TEMP3, - .sfunc = PMBUS_HAVE_STATUS_TEMP, - .sbase = PB_STATUS_TEMP_BASE, - .gbit = PB_STATUS_TEMPERATURE, - .limit = temp_limit_attrs3, - .nlimit = ARRAY_SIZE(temp_limit_attrs3), - } -}; - -static const int pmbus_fan_registers[] = { - PMBUS_READ_FAN_SPEED_1, - PMBUS_READ_FAN_SPEED_2, - PMBUS_READ_FAN_SPEED_3, - PMBUS_READ_FAN_SPEED_4 -}; - -static const int pmbus_fan_config_registers[] = { - PMBUS_FAN_CONFIG_12, - PMBUS_FAN_CONFIG_12, - PMBUS_FAN_CONFIG_34, - PMBUS_FAN_CONFIG_34 -}; - -static const int pmbus_fan_status_registers[] = { - PMBUS_STATUS_FAN_12, - PMBUS_STATUS_FAN_12, - PMBUS_STATUS_FAN_34, - PMBUS_STATUS_FAN_34 -}; - -static const u32 pmbus_fan_flags[] = { - PMBUS_HAVE_FAN12, - PMBUS_HAVE_FAN12, - PMBUS_HAVE_FAN34, - PMBUS_HAVE_FAN34 -}; - -static const u32 pmbus_fan_status_flags[] = { - PMBUS_HAVE_STATUS_FAN12, - PMBUS_HAVE_STATUS_FAN12, - PMBUS_HAVE_STATUS_FAN34, - PMBUS_HAVE_STATUS_FAN34 -}; - -/* Fans */ -static int pmbus_add_fan_attributes(struct i2c_client *client, - struct pmbus_data *data) -{ - const struct pmbus_driver_info *info = data->info; - int index = 1; - int page; - int ret; - - for (page = 0; page < info->pages; page++) { - int f; - - for (f = 0; f < ARRAY_SIZE(pmbus_fan_registers); f++) { - int regval; - - if (f >= info->fan_num) - break; - - if (!(info->func[page] & pmbus_fan_flags[f])) - break; - - if (!_pmbus_check_word_register(client, page, - pmbus_fan_registers[f])) - break; - - /* - * Skip fan if not installed. - * Each fan configuration register covers multiple fans, - * so we have to do some magic. - */ - regval = _pmbus_read_byte_data(client, page, - pmbus_fan_config_registers[f]); - if (regval < 0 || - (!(regval & (PB_FAN_1_INSTALLED >> ((f & 1) * 4))))) - continue; - - if (pmbus_add_sensor(data, "fan", "input", index, - page, pmbus_fan_registers[f], - PSC_FAN, true, true) == NULL) - return -ENOMEM; - - /* - * Each fan status register covers multiple fans, - * so we have to do some magic. - */ - if ((info->func[page] & pmbus_fan_status_flags[f]) && - _pmbus_check_byte_register(client, - page, pmbus_fan_status_registers[f])) { - int base; - - if (f > 1) /* fan 3, 4 */ - base = PB_STATUS_FAN34_BASE + page; - else - base = PB_STATUS_FAN_BASE + page; - ret = pmbus_add_boolean(data, "fan", - "alarm", index, NULL, NULL, base, - PB_FAN_FAN1_WARNING >> (f & 1)); - if (ret) - return ret; - ret = pmbus_add_boolean(data, "fan", - "fault", index, NULL, NULL, base, - PB_FAN_FAN1_FAULT >> (f & 1)); - if (ret) - return ret; - } - index++; - } - } - return 0; -} - -static int pmbus_find_attributes(struct i2c_client *client, - struct pmbus_data *data) -{ - int ret; - - /* Voltage sensors */ - ret = pmbus_add_sensor_attrs(client, data, "in", voltage_attributes, - ARRAY_SIZE(voltage_attributes)); - if (ret) - return ret; - - /* Current sensors */ - ret = pmbus_add_sensor_attrs(client, data, "curr", current_attributes, - ARRAY_SIZE(current_attributes)); - if (ret) - return ret; - - /* Power sensors */ - ret = pmbus_add_sensor_attrs(client, data, "power", power_attributes, - ARRAY_SIZE(power_attributes)); - if (ret) - return ret; - - /* Temperature sensors */ - ret = pmbus_add_sensor_attrs(client, data, "temp", temp_attributes, - ARRAY_SIZE(temp_attributes)); - if (ret) - return ret; - - /* Fans */ - ret = pmbus_add_fan_attributes(client, data); - return ret; -} - -/* - * Identify chip parameters. - * This function is called for all chips. - */ -static int pmbus_identify_common(struct i2c_client *client, - struct pmbus_data *data, int page) -{ - int vout_mode = -1; - - if (_pmbus_check_byte_register(client, page, PMBUS_VOUT_MODE)) - { - vout_mode = _pmbus_read_byte_data(client, page, - PMBUS_VOUT_MODE); - } - - if (vout_mode >= 0 && vout_mode != 0xff) { - /* - * Not all chips support the VOUT_MODE command, - * so a failure to read it is not an error. - */ - switch (vout_mode >> 5) { - case 0: /* linear mode */ - if (data->info->format[PSC_VOLTAGE_OUT] != linear) - return -ENODEV; - - data->exponent[page] = ((s8)(vout_mode << 3)) >> 3; - break; - case 1: /* VID mode */ - if (data->info->format[PSC_VOLTAGE_OUT] != vid) - return -ENODEV; - break; - case 2: /* direct mode */ - if (data->info->format[PSC_VOLTAGE_OUT] != direct) - return -ENODEV; - break; - default: - return -ENODEV; - } - } - - pmbus_clear_fault_page(client, page); - return 0; -} - -static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, - struct pmbus_driver_info *info) -{ - struct device *dev = &client->dev; - int page, ret; - - /* - * Some PMBus chips don't support PMBUS_STATUS_BYTE, so try - * to use PMBUS_STATUS_WORD instead if that is the case. - * Bail out if both registers are not supported. - */ - if(0) { /*Skip this for the i2c access may fail if PSU is not powered.*/ - data->status_register = PMBUS_STATUS_BYTE; - ret = i2c_smbus_read_byte_data(client, PMBUS_STATUS_BYTE); - if (ret < 0 || ret == 0xff) { - data->status_register = PMBUS_STATUS_WORD; - ret = i2c_smbus_read_word_data(client, PMBUS_STATUS_WORD); - if (ret < 0 || ret == 0xffff) { - dev_err(dev, "PMBus status register not found\n"); - return -ENODEV; - } - } - } - _pmbus_clear_faults(client); - - if (info->identify) { - ret = (*info->identify)(client, info); - if (ret < 0) { - dev_err(dev, "Chip identification failed\n"); - return ret; - } - } - - if (info->pages <= 0 || info->pages > PMBUS_PAGES) { - dev_err(dev, "Bad number of PMBus pages: %d\n", info->pages); - return -ENODEV; - } - - for (page = 0; page < info->pages; page++) { - ret = pmbus_identify_common(client, data, page); - if (ret < 0) { - dev_err(dev, "Failed to identify chip capabilities\n"); - return ret; - } - } - return 0; -} - -int _pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, - struct pmbus_driver_info *info) -{ - struct device *dev = &client->dev; - struct pmbus_data *data; - int ret; - - if (!info) - return -ENODEV; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_BYTE - | I2C_FUNC_SMBUS_BYTE_DATA - | I2C_FUNC_SMBUS_WORD_DATA)) - return -ENODEV; - - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); - if (!data) - return -ENOMEM; - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->dev = dev; - - if (limited_models(id)) - { - data->flags |= PMBUS_SKIP_STATUS_CHECK; - info->pages = 1; - info->fan_num = 1; - data->linear_16 = 0; - } - else - { - info->pages = id->driver_data; - info->fan_num = 4; - data->linear_16 = 1; - - } - - data->info = info; - - ret = pmbus_init_common(client, data, info); - if (ret < 0) - return ret; - - ret = pmbus_find_attributes(client, data); - if (ret) - goto out_kfree; - - /* - * If there are no attributes, something is wrong. - * Bail out instead of trying to register nothing. - */ - if (!data->num_attributes) { - dev_err(dev, "No attributes found\n"); - ret = -ENODEV; - goto out_kfree; - } - - data->groups[0] = &data->group; - data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name, - data, data->groups); - if (IS_ERR(data->hwmon_dev)) { - ret = PTR_ERR(data->hwmon_dev); - dev_err(dev, "Failed to register hwmon device\n"); - goto out_kfree; - } - return 0; - -out_kfree: - kfree(data->group.attrs); - return ret; -} - -/* - * 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; - - /* For i2c might not available when this driver installing, - turn on all attributes but VMON and FAN34.*/ - info->func[0] |= 0x1feff; - return ; - - - /* 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_VCAP)) - info->func[0] |= PMBUS_HAVE_VCAP; - 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 (info->fan_num > 0) - { - 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 (info->fan_num > 2) - { - if (_pmbus_check_byte_register(client, 0, PMBUS_FAN_CONFIG_34) && - _pmbus_check_word_register(client, 0, PMBUS_READ_FAN_SPEED_3)) { - info->func[0] |= PMBUS_HAVE_FAN34; - if (_pmbus_check_byte_register(client, 0, PMBUS_STATUS_FAN_34)) - info->func[0] |= PMBUS_HAVE_STATUS_FAN34; - } - } - - 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; -} - -/* - * Use driver_data to set the number of pages supported by the chip. - */ -static const struct i2c_device_id pmbus_id[] = { - { "accton_ym2651", YM2651 }, - { "accton_ym2401", YM2401 }, - { "accton_ym2851", YM2851 }, - {} -}; - -static int limited_models(const struct i2c_device_id *id) -{ - int j; - - if (!id->name) - return 0; - - for (j = 0; j < ARRAY_SIZE(pmbus_id); j++) { - if (!pmbus_id[j].name) - continue; - - if (!strcmp(id->name, pmbus_id[j].name)) - { - if(id->driver_data < LIMITED_CHIPS) - { - return 1; - } - else - { - return 0; - } - } - - } - - return 0; -} - -static int pmbus_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct pmbus_driver_info *info; - - info = devm_kzalloc(&client->dev, sizeof(struct pmbus_driver_info), - GFP_KERNEL); - if (!info) - return -ENOMEM; - - info->identify = pmbus_identify; - - return _pmbus_do_probe(client, id, info); -} - -int _pmbus_do_remove(struct i2c_client *client) -{ - struct pmbus_data *data = i2c_get_clientdata(client); - hwmon_device_unregister(data->hwmon_dev); - kfree(data->group.attrs); - return 0; -} - -MODULE_DEVICE_TABLE(i2c, pmbus_id); - -/* This is the driver that will be inserted */ -static struct i2c_driver pmbus_driver = { - .driver = { - .name = "accton_pmbus_3y", - }, - .probe = pmbus_probe, - .remove = _pmbus_do_remove, - .id_table = pmbus_id, -}; - -module_i2c_driver(pmbus_driver); - -MODULE_AUTHOR("Roy Lee"); -MODULE_DESCRIPTION("Accton PMBus driver for 3Y Power YM-2651Y."); -MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-accton/common/modules/cpr_4011_4mxx.c b/platform/broadcom/sonic-platform-modules-accton/common/modules/cpr_4011_4mxx.c deleted file mode 100644 index 2cea5f5e39f9..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/common/modules/cpr_4011_4mxx.c +++ /dev/null @@ -1,402 +0,0 @@ -/* - * An hwmon driver for the CPR-4011-4Mxx Redundant Power Module - * - * Copyright (C) Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#if 0 -#define DEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_FAN_DUTY_CYCLE 100 - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x3c, 0x3d, 0x3e, 0x3f, I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct cpr_4011_4mxx_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 vout_mode; /* Register value */ - u16 v_in; /* Register value */ - u16 v_out; /* Register value */ - u16 i_in; /* Register value */ - u16 i_out; /* Register value */ - u16 p_in; /* Register value */ - u16 p_out; /* Register value */ - u16 temp_input[2]; /* Register value */ - u8 fan_fault; /* Register value */ - u16 fan_duty_cycle[2]; /* Register value */ - u16 fan_speed[2]; /* Register value */ -}; - -static ssize_t show_linear(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_vout(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_fan_duty_cycle(struct device *dev, struct device_attribute *da, const char *buf, size_t count); -static int cpr_4011_4mxx_write_word(struct i2c_client *client, u8 reg, u16 value); -static struct cpr_4011_4mxx_data *cpr_4011_4mxx_update_device(struct device *dev); - -enum cpr_4011_4mxx_sysfs_attributes { - PSU_V_IN, - PSU_V_OUT, - PSU_I_IN, - PSU_I_OUT, - PSU_P_IN, - PSU_P_OUT, - PSU_TEMP1_INPUT, - PSU_FAN1_FAULT, - PSU_FAN1_DUTY_CYCLE, - PSU_FAN1_SPEED, -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_v_in, S_IRUGO, show_linear, NULL, PSU_V_IN); -static SENSOR_DEVICE_ATTR(psu_v_out, S_IRUGO, show_vout, NULL, PSU_V_OUT); -static SENSOR_DEVICE_ATTR(psu_i_in, S_IRUGO, show_linear, NULL, PSU_I_IN); -static SENSOR_DEVICE_ATTR(psu_i_out, S_IRUGO, show_linear, NULL, PSU_I_OUT); -static SENSOR_DEVICE_ATTR(psu_p_in, S_IRUGO, show_linear, NULL, PSU_P_IN); -static SENSOR_DEVICE_ATTR(psu_p_out, S_IRUGO, show_linear, NULL, PSU_P_OUT); -static SENSOR_DEVICE_ATTR(psu_temp1_input, S_IRUGO, show_linear, NULL, PSU_TEMP1_INPUT); -static SENSOR_DEVICE_ATTR(psu_fan1_fault, S_IRUGO, show_fan_fault, NULL, PSU_FAN1_FAULT); -static SENSOR_DEVICE_ATTR(psu_fan1_duty_cycle_percentage, S_IWUSR | S_IRUGO, show_linear, set_fan_duty_cycle, PSU_FAN1_DUTY_CYCLE); -static SENSOR_DEVICE_ATTR(psu_fan1_speed_rpm, S_IRUGO, show_linear, NULL, PSU_FAN1_SPEED); - -static struct attribute *cpr_4011_4mxx_attributes[] = { - &sensor_dev_attr_psu_v_in.dev_attr.attr, - &sensor_dev_attr_psu_v_out.dev_attr.attr, - &sensor_dev_attr_psu_i_in.dev_attr.attr, - &sensor_dev_attr_psu_i_out.dev_attr.attr, - &sensor_dev_attr_psu_p_in.dev_attr.attr, - &sensor_dev_attr_psu_p_out.dev_attr.attr, - &sensor_dev_attr_psu_temp1_input.dev_attr.attr, - &sensor_dev_attr_psu_fan1_fault.dev_attr.attr, - &sensor_dev_attr_psu_fan1_duty_cycle_percentage.dev_attr.attr, - &sensor_dev_attr_psu_fan1_speed_rpm.dev_attr.attr, - NULL -}; - -static int two_complement_to_int(u16 data, u8 valid_bit, int mask) -{ - u16 valid_data = data & mask; - bool is_negative = valid_data >> (valid_bit - 1); - - return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data; -} - -static ssize_t set_fan_duty_cycle(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 cpr_4011_4mxx_data *data = i2c_get_clientdata(client); - int nr = (attr->index == PSU_FAN1_DUTY_CYCLE) ? 0 : 1; - long speed; - int error; - - error = kstrtol(buf, 10, &speed); - if (error) - return error; - - if (speed < 0 || speed > MAX_FAN_DUTY_CYCLE) - return -EINVAL; - - mutex_lock(&data->update_lock); - data->fan_duty_cycle[nr] = speed; - cpr_4011_4mxx_write_word(client, 0x3B + nr, data->fan_duty_cycle[nr]); - mutex_unlock(&data->update_lock); - - return count; -} - -static ssize_t show_linear(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct cpr_4011_4mxx_data *data = cpr_4011_4mxx_update_device(dev); - - u16 value = 0; - int exponent, mantissa; - int multiplier = 1000; - - switch (attr->index) { - case PSU_V_IN: - value = data->v_in; - break; - case PSU_I_IN: - value = data->i_in; - break; - case PSU_I_OUT: - value = data->i_out; - break; - case PSU_P_IN: - value = data->p_in; - break; - case PSU_P_OUT: - value = data->p_out; - break; - case PSU_TEMP1_INPUT: - value = data->temp_input[0]; - break; - case PSU_FAN1_DUTY_CYCLE: - multiplier = 1; - value = data->fan_duty_cycle[0]; - break; - case PSU_FAN1_SPEED: - multiplier = 1; - value = data->fan_speed[0]; - break; - default: - break; - } - - exponent = two_complement_to_int(value >> 11, 5, 0x1f); - mantissa = two_complement_to_int(value & 0x7ff, 11, 0x7ff); - - return (exponent >= 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : - sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); -} - -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct cpr_4011_4mxx_data *data = cpr_4011_4mxx_update_device(dev); - - u8 shift = (attr->index == PSU_FAN1_FAULT) ? 7 : 6; - - return sprintf(buf, "%d\n", data->fan_fault >> shift); -} - -static ssize_t show_vout(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct cpr_4011_4mxx_data *data = cpr_4011_4mxx_update_device(dev); - int exponent, mantissa; - int multiplier = 1000; - - exponent = two_complement_to_int(data->vout_mode, 5, 0x1f); - mantissa = data->v_out; - - return (exponent > 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : - sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); -} - -static const struct attribute_group cpr_4011_4mxx_group = { - .attrs = cpr_4011_4mxx_attributes, -}; - -static int cpr_4011_4mxx_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct cpr_4011_4mxx_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct cpr_4011_4mxx_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &cpr_4011_4mxx_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &cpr_4011_4mxx_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int cpr_4011_4mxx_remove(struct i2c_client *client) -{ - struct cpr_4011_4mxx_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &cpr_4011_4mxx_group); - kfree(data); - - return 0; -} - -static const struct i2c_device_id cpr_4011_4mxx_id[] = { - { "cpr_4011_4mxx", 0 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, cpr_4011_4mxx_id); - -static struct i2c_driver cpr_4011_4mxx_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "cpr_4011_4mxx", - }, - .probe = cpr_4011_4mxx_probe, - .remove = cpr_4011_4mxx_remove, - .id_table = cpr_4011_4mxx_id, - .address_list = normal_i2c, -}; - -static int cpr_4011_4mxx_read_byte(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_byte_data(client, reg); -} - -static int cpr_4011_4mxx_read_word(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_word_data(client, reg); -} - -static int cpr_4011_4mxx_write_word(struct i2c_client *client, u8 reg, u16 value) -{ - return i2c_smbus_write_word_data(client, reg, value); -} - -struct reg_data_byte { - u8 reg; - u8 *value; -}; - -struct reg_data_word { - u8 reg; - u16 *value; -}; - -static struct cpr_4011_4mxx_data *cpr_4011_4mxx_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct cpr_4011_4mxx_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int i, status; - struct reg_data_byte regs_byte[] = { {0x20, &data->vout_mode}, - {0x81, &data->fan_fault} - }; - struct reg_data_word regs_word[] = { {0x88, &data->v_in}, - {0x8b, &data->v_out}, - {0x89, &data->i_in}, - {0x8c, &data->i_out}, - {0x96, &data->p_out}, - {0x97, &data->p_in}, - {0x8d, &(data->temp_input[0])}, - {0x8e, &(data->temp_input[1])}, - {0x3b, &(data->fan_duty_cycle[0])}, - {0x3c, &(data->fan_duty_cycle[1])}, - {0x90, &(data->fan_speed[0])}, - {0x91, &(data->fan_speed[1])} - }; - - dev_dbg(&client->dev, "Starting cpr_4011_4mxx update\n"); - - /* Read byte data */ - for (i = 0; i < ARRAY_SIZE(regs_byte); i++) { - status = cpr_4011_4mxx_read_byte(client, regs_byte[i].reg); - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_byte[i].reg, status); - } - else { - *(regs_byte[i].value) = status; - } - } - - /* Read word data */ - for (i = 0; i < ARRAY_SIZE(regs_word); i++) { - status = cpr_4011_4mxx_read_word(client, regs_word[i].reg); - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_word[i].reg, status); - } - else { - *(regs_word[i].value) = status; - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init cpr_4011_4mxx_init(void) -{ - return i2c_add_driver(&cpr_4011_4mxx_driver); -} - -static void __exit cpr_4011_4mxx_exit(void) -{ - i2c_del_driver(&cpr_4011_4mxx_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("CPR_4011_4MXX driver"); -MODULE_LICENSE("GPL"); - -module_init(cpr_4011_4mxx_init); -module_exit(cpr_4011_4mxx_exit); diff --git a/platform/broadcom/sonic-platform-modules-accton/common/modules/pmbus.h b/platform/broadcom/sonic-platform-modules-accton/common/modules/pmbus.h deleted file mode 100644 index cb6dbc34d87c..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/common/modules/pmbus.h +++ /dev/null @@ -1,389 +0,0 @@ -/* - * 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 - -/* - * Registers - */ -#define PMBUS_PAGE 0x00 -#define PMBUS_OPERATION 0x01 -#define PMBUS_ON_OFF_CONFIG 0x02 -#define PMBUS_CLEAR_FAULTS 0x03 -#define PMBUS_PHASE 0x04 - -#define PMBUS_CAPABILITY 0x19 -#define PMBUS_QUERY 0x1A - -#define PMBUS_VOUT_MODE 0x20 -#define PMBUS_VOUT_COMMAND 0x21 -#define PMBUS_VOUT_TRIM 0x22 -#define PMBUS_VOUT_CAL_OFFSET 0x23 -#define PMBUS_VOUT_MAX 0x24 -#define PMBUS_VOUT_MARGIN_HIGH 0x25 -#define PMBUS_VOUT_MARGIN_LOW 0x26 -#define PMBUS_VOUT_TRANSITION_RATE 0x27 -#define PMBUS_VOUT_DROOP 0x28 -#define PMBUS_VOUT_SCALE_LOOP 0x29 -#define PMBUS_VOUT_SCALE_MONITOR 0x2A - -#define PMBUS_COEFFICIENTS 0x30 -#define PMBUS_POUT_MAX 0x31 - -#define PMBUS_FAN_CONFIG_12 0x3A -#define PMBUS_FAN_COMMAND_1 0x3B -#define PMBUS_FAN_COMMAND_2 0x3C -#define PMBUS_FAN_CONFIG_34 0x3D -#define PMBUS_FAN_COMMAND_3 0x3E -#define PMBUS_FAN_COMMAND_4 0x3F - -#define PMBUS_VOUT_OV_FAULT_LIMIT 0x40 -#define PMBUS_VOUT_OV_FAULT_RESPONSE 0x41 -#define PMBUS_VOUT_OV_WARN_LIMIT 0x42 -#define PMBUS_VOUT_UV_WARN_LIMIT 0x43 -#define PMBUS_VOUT_UV_FAULT_LIMIT 0x44 -#define PMBUS_VOUT_UV_FAULT_RESPONSE 0x45 -#define PMBUS_IOUT_OC_FAULT_LIMIT 0x46 -#define PMBUS_IOUT_OC_FAULT_RESPONSE 0x47 -#define PMBUS_IOUT_OC_LV_FAULT_LIMIT 0x48 -#define PMBUS_IOUT_OC_LV_FAULT_RESPONSE 0x49 -#define PMBUS_IOUT_OC_WARN_LIMIT 0x4A -#define PMBUS_IOUT_UC_FAULT_LIMIT 0x4B -#define PMBUS_IOUT_UC_FAULT_RESPONSE 0x4C - -#define PMBUS_OT_FAULT_LIMIT 0x4F -#define PMBUS_OT_FAULT_RESPONSE 0x50 -#define PMBUS_OT_WARN_LIMIT 0x51 -#define PMBUS_UT_WARN_LIMIT 0x52 -#define PMBUS_UT_FAULT_LIMIT 0x53 -#define PMBUS_UT_FAULT_RESPONSE 0x54 -#define PMBUS_VIN_OV_FAULT_LIMIT 0x55 -#define PMBUS_VIN_OV_FAULT_RESPONSE 0x56 -#define PMBUS_VIN_OV_WARN_LIMIT 0x57 -#define PMBUS_VIN_UV_WARN_LIMIT 0x58 -#define PMBUS_VIN_UV_FAULT_LIMIT 0x59 - -#define PMBUS_IIN_OC_FAULT_LIMIT 0x5B -#define PMBUS_IIN_OC_WARN_LIMIT 0x5D - -#define PMBUS_POUT_OP_FAULT_LIMIT 0x68 -#define PMBUS_POUT_OP_WARN_LIMIT 0x6A -#define PMBUS_PIN_OP_WARN_LIMIT 0x6B - -#define PMBUS_STATUS_BYTE 0x78 -#define PMBUS_STATUS_WORD 0x79 -#define PMBUS_STATUS_VOUT 0x7A -#define PMBUS_STATUS_IOUT 0x7B -#define PMBUS_STATUS_INPUT 0x7C -#define PMBUS_STATUS_TEMPERATURE 0x7D -#define PMBUS_STATUS_CML 0x7E -#define PMBUS_STATUS_OTHER 0x7F -#define PMBUS_STATUS_MFR_SPECIFIC 0x80 -#define PMBUS_STATUS_FAN_12 0x81 -#define PMBUS_STATUS_FAN_34 0x82 - -#define PMBUS_READ_VIN 0x88 -#define PMBUS_READ_IIN 0x89 -#define PMBUS_READ_VCAP 0x8A -#define PMBUS_READ_VOUT 0x8B -#define PMBUS_READ_IOUT 0x8C -#define PMBUS_READ_TEMPERATURE_1 0x8D -#define PMBUS_READ_TEMPERATURE_2 0x8E -#define PMBUS_READ_TEMPERATURE_3 0x8F -#define PMBUS_READ_FAN_SPEED_1 0x90 -#define PMBUS_READ_FAN_SPEED_2 0x91 -#define PMBUS_READ_FAN_SPEED_3 0x92 -#define PMBUS_READ_FAN_SPEED_4 0x93 -#define PMBUS_READ_DUTY_CYCLE 0x94 -#define PMBUS_READ_FREQUENCY 0x95 -#define PMBUS_READ_POUT 0x96 -#define PMBUS_READ_PIN 0x97 - -#define PMBUS_REVISION 0x98 -#define PMBUS_MFR_ID 0x99 -#define PMBUS_MFR_MODEL 0x9A -#define PMBUS_MFR_REVISION 0x9B -#define PMBUS_MFR_LOCATION 0x9C -#define PMBUS_MFR_DATE 0x9D -#define 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. - */ -#define PMBUS_VIRT_BASE 0x100 -#define PMBUS_VIRT_READ_TEMP_AVG (PMBUS_VIRT_BASE + 0) -#define PMBUS_VIRT_READ_TEMP_MIN (PMBUS_VIRT_BASE + 1) -#define PMBUS_VIRT_READ_TEMP_MAX (PMBUS_VIRT_BASE + 2) -#define PMBUS_VIRT_RESET_TEMP_HISTORY (PMBUS_VIRT_BASE + 3) -#define PMBUS_VIRT_READ_VIN_AVG (PMBUS_VIRT_BASE + 4) -#define PMBUS_VIRT_READ_VIN_MIN (PMBUS_VIRT_BASE + 5) -#define PMBUS_VIRT_READ_VIN_MAX (PMBUS_VIRT_BASE + 6) -#define PMBUS_VIRT_RESET_VIN_HISTORY (PMBUS_VIRT_BASE + 7) -#define PMBUS_VIRT_READ_IIN_AVG (PMBUS_VIRT_BASE + 8) -#define PMBUS_VIRT_READ_IIN_MIN (PMBUS_VIRT_BASE + 9) -#define PMBUS_VIRT_READ_IIN_MAX (PMBUS_VIRT_BASE + 10) -#define PMBUS_VIRT_RESET_IIN_HISTORY (PMBUS_VIRT_BASE + 11) -#define PMBUS_VIRT_READ_PIN_AVG (PMBUS_VIRT_BASE + 12) -#define PMBUS_VIRT_READ_PIN_MAX (PMBUS_VIRT_BASE + 13) -#define PMBUS_VIRT_RESET_PIN_HISTORY (PMBUS_VIRT_BASE + 14) -#define PMBUS_VIRT_READ_POUT_AVG (PMBUS_VIRT_BASE + 15) -#define PMBUS_VIRT_READ_POUT_MAX (PMBUS_VIRT_BASE + 16) -#define PMBUS_VIRT_RESET_POUT_HISTORY (PMBUS_VIRT_BASE + 17) -#define PMBUS_VIRT_READ_VOUT_AVG (PMBUS_VIRT_BASE + 18) -#define PMBUS_VIRT_READ_VOUT_MIN (PMBUS_VIRT_BASE + 19) -#define PMBUS_VIRT_READ_VOUT_MAX (PMBUS_VIRT_BASE + 20) -#define PMBUS_VIRT_RESET_VOUT_HISTORY (PMBUS_VIRT_BASE + 21) -#define PMBUS_VIRT_READ_IOUT_AVG (PMBUS_VIRT_BASE + 22) -#define PMBUS_VIRT_READ_IOUT_MIN (PMBUS_VIRT_BASE + 23) -#define PMBUS_VIRT_READ_IOUT_MAX (PMBUS_VIRT_BASE + 24) -#define PMBUS_VIRT_RESET_IOUT_HISTORY (PMBUS_VIRT_BASE + 25) -#define PMBUS_VIRT_READ_TEMP2_AVG (PMBUS_VIRT_BASE + 26) -#define PMBUS_VIRT_READ_TEMP2_MIN (PMBUS_VIRT_BASE + 27) -#define PMBUS_VIRT_READ_TEMP2_MAX (PMBUS_VIRT_BASE + 28) -#define PMBUS_VIRT_RESET_TEMP2_HISTORY (PMBUS_VIRT_BASE + 29) - -#define PMBUS_VIRT_READ_VMON (PMBUS_VIRT_BASE + 30) -#define PMBUS_VIRT_VMON_UV_WARN_LIMIT (PMBUS_VIRT_BASE + 31) -#define PMBUS_VIRT_VMON_OV_WARN_LIMIT (PMBUS_VIRT_BASE + 32) -#define PMBUS_VIRT_VMON_UV_FAULT_LIMIT (PMBUS_VIRT_BASE + 33) -#define PMBUS_VIRT_VMON_OV_FAULT_LIMIT (PMBUS_VIRT_BASE + 34) -#define PMBUS_VIRT_STATUS_VMON (PMBUS_VIRT_BASE + 35) - -/* - * CAPABILITY - */ -#define PB_CAPABILITY_SMBALERT (1<<4) -#define PB_CAPABILITY_ERROR_CHECK (1<<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 ((1 << 0) | (1 << 1)) -#define PB_FAN_2_RPM (1 << 2) -#define PB_FAN_2_INSTALLED (1 << 3) -#define PB_FAN_1_PULSE_MASK ((1 << 4) | (1 << 5)) -#define PB_FAN_1_RPM (1 << 6) -#define PB_FAN_1_INSTALLED (1 << 7) - -/* - * STATUS_BYTE, STATUS_WORD (lower) - */ -#define PB_STATUS_NONE_ABOVE (1<<0) -#define PB_STATUS_CML (1<<1) -#define PB_STATUS_TEMPERATURE (1<<2) -#define PB_STATUS_VIN_UV (1<<3) -#define PB_STATUS_IOUT_OC (1<<4) -#define PB_STATUS_VOUT_OV (1<<5) -#define PB_STATUS_OFF (1<<6) -#define PB_STATUS_BUSY (1<<7) - -/* - * STATUS_WORD (upper) - */ -#define PB_STATUS_UNKNOWN (1<<8) -#define PB_STATUS_OTHER (1<<9) -#define PB_STATUS_FANS (1<<10) -#define PB_STATUS_POWER_GOOD_N (1<<11) -#define PB_STATUS_WORD_MFR (1<<12) -#define PB_STATUS_INPUT (1<<13) -#define PB_STATUS_IOUT_POUT (1<<14) -#define PB_STATUS_VOUT (1<<15) - -/* - * STATUS_IOUT - */ -#define PB_POUT_OP_WARNING (1<<0) -#define PB_POUT_OP_FAULT (1<<1) -#define PB_POWER_LIMITING (1<<2) -#define PB_CURRENT_SHARE_FAULT (1<<3) -#define PB_IOUT_UC_FAULT (1<<4) -#define PB_IOUT_OC_WARNING (1<<5) -#define PB_IOUT_OC_LV_FAULT (1<<6) -#define PB_IOUT_OC_FAULT (1<<7) - -/* - * STATUS_VOUT, STATUS_INPUT - */ -#define PB_VOLTAGE_UV_FAULT (1<<4) -#define PB_VOLTAGE_UV_WARNING (1<<5) -#define PB_VOLTAGE_OV_WARNING (1<<6) -#define PB_VOLTAGE_OV_FAULT (1<<7) - -/* - * STATUS_INPUT - */ -#define PB_PIN_OP_WARNING (1<<0) -#define PB_IIN_OC_WARNING (1<<1) -#define PB_IIN_OC_FAULT (1<<2) - -/* - * STATUS_TEMPERATURE - */ -#define PB_TEMP_UT_FAULT (1<<4) -#define PB_TEMP_UT_WARNING (1<<5) -#define PB_TEMP_OT_WARNING (1<<6) -#define PB_TEMP_OT_FAULT (1<<7) - -/* - * STATUS_FAN - */ -#define PB_FAN_AIRFLOW_WARNING (1<<0) -#define PB_FAN_AIRFLOW_FAULT (1<<1) -#define PB_FAN_FAN2_SPEED_OVERRIDE (1<<2) -#define PB_FAN_FAN1_SPEED_OVERRIDE (1<<3) -#define PB_FAN_FAN2_WARNING (1<<4) -#define PB_FAN_FAN1_WARNING (1<<5) -#define PB_FAN_FAN2_FAULT (1<<6) -#define PB_FAN_FAN1_FAULT (1<<7) - -/* - * CML_FAULT_STATUS - */ -#define PB_CML_FAULT_OTHER_MEM_LOGIC (1<<0) -#define PB_CML_FAULT_OTHER_COMM (1<<1) -#define PB_CML_FAULT_PROCESSOR (1<<3) -#define PB_CML_FAULT_MEMORY (1<<4) -#define PB_CML_FAULT_PACKET_ERROR (1<<5) -#define PB_CML_FAULT_INVALID_DATA (1<<6) -#define PB_CML_FAULT_INVALID_COMMAND (1<<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 (1 << 0) -#define PMBUS_HAVE_VCAP (1 << 1) -#define PMBUS_HAVE_VOUT (1 << 2) -#define PMBUS_HAVE_IIN (1 << 3) -#define PMBUS_HAVE_IOUT (1 << 4) -#define PMBUS_HAVE_PIN (1 << 5) -#define PMBUS_HAVE_POUT (1 << 6) -#define PMBUS_HAVE_FAN12 (1 << 7) -#define PMBUS_HAVE_FAN34 (1 << 8) -#define PMBUS_HAVE_TEMP (1 << 9) -#define PMBUS_HAVE_TEMP2 (1 << 10) -#define PMBUS_HAVE_TEMP3 (1 << 11) -#define PMBUS_HAVE_STATUS_VOUT (1 << 12) -#define PMBUS_HAVE_STATUS_IOUT (1 << 13) -#define PMBUS_HAVE_STATUS_INPUT (1 << 14) -#define PMBUS_HAVE_STATUS_TEMP (1 << 15) -#define PMBUS_HAVE_STATUS_FAN12 (1 << 16) -#define PMBUS_HAVE_STATUS_FAN34 (1 << 17) -#define PMBUS_HAVE_VMON (1 << 18) -#define PMBUS_HAVE_STATUS_VMON (1 << 19) - -enum pmbus_data_format { linear = 0, direct, vid }; - -struct pmbus_driver_info { - int pages; /* Total number of pages */ - enum pmbus_data_format format[PSC_NUM_CLASSES]; - /* - * 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); - - int fan_num; -}; - -/* 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); -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 */ diff --git a/platform/broadcom/sonic-platform-modules-accton/common/modules/ym2651y.c b/platform/broadcom/sonic-platform-modules-accton/common/modules/ym2651y.c deleted file mode 100644 index 47e6a1d06bc5..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/common/modules/ym2651y.c +++ /dev/null @@ -1,619 +0,0 @@ -/* - * An hwmon driver for the 3Y Power YM-2651Y Power Module - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_FAN_DUTY_CYCLE 100 - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x58, 0x5b, I2C_CLIENT_END }; - -enum chips { - YM2651, - YM2401, - YM2851, -}; - -/* Each client has this additional data - */ -struct ym2651y_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 capability; /* Register value */ - u16 status_word; /* Register value */ - u8 fan_fault; /* Register value */ - u8 over_temp; /* Register value */ - u16 v_out; /* Register value */ - u16 i_out; /* Register value */ - u16 p_out; /* Register value */ - u16 temp; /* Register value */ - u16 fan_speed; /* Register value */ - u16 fan_duty_cycle[2]; /* Register value */ - u8 fan_dir[4]; /* Register value */ - u8 pmbus_revision; /* Register value */ - u8 mfr_id[10]; /* Register value */ - u8 mfr_model[10]; /* Register value */ - u8 mfr_revsion[3]; /* Register value */ - u16 mfr_vin_min; /* Register value */ - u16 mfr_vin_max; /* Register value */ - u16 mfr_iin_max; /* Register value */ - u16 mfr_iout_max; /* Register value */ - u16 mfr_pin_max; /* Register value */ - u16 mfr_pout_max; /* Register value */ - u16 mfr_vout_min; /* Register value */ - u16 mfr_vout_max; /* Register value */ -}; - -static ssize_t show_byte(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_word(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_linear(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_over_temp(struct device *dev, struct device_attribute *da, - char *buf); -static ssize_t show_ascii(struct device *dev, struct device_attribute *da, - char *buf); -static struct ym2651y_data *ym2651y_update_device(struct device *dev); -static ssize_t set_fan_duty_cycle(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -static int ym2651y_write_word(struct i2c_client *client, u8 reg, u16 value); - -enum ym2651y_sysfs_attributes { - PSU_POWER_ON = 0, - PSU_TEMP_FAULT, - PSU_POWER_GOOD, - PSU_FAN1_FAULT, - PSU_FAN_DIRECTION, - PSU_OVER_TEMP, - PSU_V_OUT, - PSU_I_OUT, - PSU_P_OUT, - PSU_P_OUT_UV, /*In Unit of microVolt, instead of mini.*/ - PSU_TEMP1_INPUT, - PSU_FAN1_SPEED, - PSU_FAN1_DUTY_CYCLE, - PSU_PMBUS_REVISION, - PSU_MFR_ID, - PSU_MFR_MODEL, - PSU_MFR_REVISION, - PSU_MFR_VIN_MIN, - PSU_MFR_VIN_MAX, - PSU_MFR_VOUT_MIN, - PSU_MFR_VOUT_MAX, - PSU_MFR_IIN_MAX, - PSU_MFR_IOUT_MAX, - PSU_MFR_PIN_MAX, - PSU_MFR_POUT_MAX -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_power_on, S_IRUGO, show_word, NULL, PSU_POWER_ON); -static SENSOR_DEVICE_ATTR(psu_temp_fault, S_IRUGO, show_word, NULL, PSU_TEMP_FAULT); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_word, NULL, PSU_POWER_GOOD); -static SENSOR_DEVICE_ATTR(psu_fan1_fault, S_IRUGO, show_fan_fault, NULL, PSU_FAN1_FAULT); -static SENSOR_DEVICE_ATTR(psu_over_temp, S_IRUGO, show_over_temp, NULL, PSU_OVER_TEMP); -static SENSOR_DEVICE_ATTR(psu_v_out, S_IRUGO, show_linear, NULL, PSU_V_OUT); -static SENSOR_DEVICE_ATTR(psu_i_out, S_IRUGO, show_linear, NULL, PSU_I_OUT); -static SENSOR_DEVICE_ATTR(psu_p_out, S_IRUGO, show_linear, NULL, PSU_P_OUT); -static SENSOR_DEVICE_ATTR(psu_temp1_input, S_IRUGO, show_linear, NULL, PSU_TEMP1_INPUT); -static SENSOR_DEVICE_ATTR(psu_fan1_speed_rpm, S_IRUGO, show_linear, NULL, PSU_FAN1_SPEED); -static SENSOR_DEVICE_ATTR(psu_fan1_duty_cycle_percentage, S_IWUSR | S_IRUGO, show_linear, set_fan_duty_cycle, PSU_FAN1_DUTY_CYCLE); -static SENSOR_DEVICE_ATTR(psu_fan_dir, S_IRUGO, show_ascii, NULL, PSU_FAN_DIRECTION); -static SENSOR_DEVICE_ATTR(psu_pmbus_revision, S_IRUGO, show_byte, NULL, PSU_PMBUS_REVISION); -static SENSOR_DEVICE_ATTR(psu_mfr_id, S_IRUGO, show_ascii, NULL, PSU_MFR_ID); -static SENSOR_DEVICE_ATTR(psu_mfr_model, S_IRUGO, show_ascii, NULL, PSU_MFR_MODEL); -static SENSOR_DEVICE_ATTR(psu_mfr_revision, S_IRUGO, show_ascii, NULL, PSU_MFR_REVISION); -static SENSOR_DEVICE_ATTR(psu_mfr_vin_min, S_IRUGO, show_linear, NULL, PSU_MFR_VIN_MIN); -static SENSOR_DEVICE_ATTR(psu_mfr_vin_max, S_IRUGO, show_linear, NULL, PSU_MFR_VIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_vout_min, S_IRUGO, show_linear, NULL, PSU_MFR_VOUT_MIN); -static SENSOR_DEVICE_ATTR(psu_mfr_vout_max, S_IRUGO, show_linear, NULL, PSU_MFR_VOUT_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_iin_max, S_IRUGO, show_linear, NULL, PSU_MFR_IIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_iout_max, S_IRUGO, show_linear, NULL, PSU_MFR_IOUT_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_pin_max, S_IRUGO, show_linear, NULL, PSU_MFR_PIN_MAX); -static SENSOR_DEVICE_ATTR(psu_mfr_pout_max, S_IRUGO, show_linear, NULL, PSU_MFR_POUT_MAX); - -/*Duplicate nodes for lm-sensors.*/ -static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_linear, NULL, PSU_V_OUT); -static SENSOR_DEVICE_ATTR(curr2_input, S_IRUGO, show_linear, NULL, PSU_I_OUT); -static SENSOR_DEVICE_ATTR(power2_input, S_IRUGO, show_linear, NULL, PSU_P_OUT_UV); -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_linear, NULL, PSU_TEMP1_INPUT); -static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_linear, NULL, PSU_FAN1_SPEED); -static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_word, NULL, PSU_TEMP_FAULT); - -static struct attribute *ym2651y_attributes[] = { - &sensor_dev_attr_psu_power_on.dev_attr.attr, - &sensor_dev_attr_psu_temp_fault.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - &sensor_dev_attr_psu_fan1_fault.dev_attr.attr, - &sensor_dev_attr_psu_over_temp.dev_attr.attr, - &sensor_dev_attr_psu_v_out.dev_attr.attr, - &sensor_dev_attr_psu_i_out.dev_attr.attr, - &sensor_dev_attr_psu_p_out.dev_attr.attr, - &sensor_dev_attr_psu_temp1_input.dev_attr.attr, - &sensor_dev_attr_psu_fan1_speed_rpm.dev_attr.attr, - &sensor_dev_attr_psu_fan1_duty_cycle_percentage.dev_attr.attr, - &sensor_dev_attr_psu_fan_dir.dev_attr.attr, - &sensor_dev_attr_psu_pmbus_revision.dev_attr.attr, - &sensor_dev_attr_psu_mfr_id.dev_attr.attr, - &sensor_dev_attr_psu_mfr_model.dev_attr.attr, - &sensor_dev_attr_psu_mfr_revision.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vin_min.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_pout_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_iin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_pin_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vout_min.dev_attr.attr, - &sensor_dev_attr_psu_mfr_vout_max.dev_attr.attr, - &sensor_dev_attr_psu_mfr_iout_max.dev_attr.attr, - /*Duplicate nodes for lm-sensors.*/ - &sensor_dev_attr_curr2_input.dev_attr.attr, - &sensor_dev_attr_in3_input.dev_attr.attr, - &sensor_dev_attr_power2_input.dev_attr.attr, - &sensor_dev_attr_temp1_input.dev_attr.attr, - &sensor_dev_attr_fan1_input.dev_attr.attr, - &sensor_dev_attr_temp1_fault.dev_attr.attr, - NULL -}; - -static ssize_t show_byte(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - - return (attr->index == PSU_PMBUS_REVISION) ? sprintf(buf, "%d\n", data->pmbus_revision) : - sprintf(buf, "0\n"); -} - -static ssize_t show_word(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - u16 status = 0; - - switch (attr->index) { - case PSU_POWER_ON: /* psu_power_on, low byte bit 6 of status_word, 0=>ON, 1=>OFF */ - status = (data->status_word & 0x40) ? 0 : 1; - break; - case PSU_TEMP_FAULT: /* psu_temp_fault, low byte bit 2 of status_word, 0=>Normal, 1=>temp fault */ - status = (data->status_word & 0x4) >> 2; - break; - case PSU_POWER_GOOD: /* psu_power_good, high byte bit 3 of status_word, 0=>OK, 1=>FAIL */ - status = (data->status_word & 0x800) ? 0 : 1; - break; - } - - return sprintf(buf, "%d\n", status); -} - -static int two_complement_to_int(u16 data, u8 valid_bit, int mask) -{ - u16 valid_data = data & mask; - bool is_negative = valid_data >> (valid_bit - 1); - - return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data; -} - -static ssize_t set_fan_duty_cycle(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 ym2651y_data *data = i2c_get_clientdata(client); - int nr = (attr->index == PSU_FAN1_DUTY_CYCLE) ? 0 : 1; - long speed; - int error; - - error = kstrtol(buf, 10, &speed); - if (error) - return error; - - if (speed < 0 || speed > MAX_FAN_DUTY_CYCLE) - return -EINVAL; - - mutex_lock(&data->update_lock); - data->fan_duty_cycle[nr] = speed; - ym2651y_write_word(client, 0x3B + nr, data->fan_duty_cycle[nr]); - mutex_unlock(&data->update_lock); - - return count; -} - -static ssize_t show_linear(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - - u16 value = 0; - int exponent, mantissa; - int multiplier = 1000; - - switch (attr->index) { - case PSU_V_OUT: - value = data->v_out; - break; - case PSU_I_OUT: - value = data->i_out; - break; - case PSU_P_OUT_UV: - multiplier = 1000000; /*For lm-sensors, unit is micro-Volt.*/ - /*Passing through*/ - case PSU_P_OUT: - value = data->p_out; - break; - case PSU_TEMP1_INPUT: - value = data->temp; - break; - case PSU_FAN1_SPEED: - value = data->fan_speed; - multiplier = 1; - break; - case PSU_FAN1_DUTY_CYCLE: - value = data->fan_duty_cycle[0]; - multiplier = 1; - break; - case PSU_MFR_VIN_MIN: - value = data->mfr_vin_min; - break; - case PSU_MFR_VIN_MAX: - value = data->mfr_vin_max; - break; - case PSU_MFR_VOUT_MIN: - value = data->mfr_vout_min; - break; - case PSU_MFR_VOUT_MAX: - value = data->mfr_vout_max; - break; - case PSU_MFR_PIN_MAX: - value = data->mfr_pin_max; - break; - case PSU_MFR_POUT_MAX: - value = data->mfr_pout_max; - break; - case PSU_MFR_IOUT_MAX: - value = data->mfr_iout_max; - break; - case PSU_MFR_IIN_MAX: - value = data->mfr_iin_max; - break; - } - - exponent = two_complement_to_int(value >> 11, 5, 0x1f); - mantissa = two_complement_to_int(value & 0x7ff, 11, 0x7ff); - return (exponent >= 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : - sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); -} - -static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - - u8 shift = (attr->index == PSU_FAN1_FAULT) ? 7 : 6; - - return sprintf(buf, "%d\n", data->fan_fault >> shift); -} - -static ssize_t show_over_temp(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct ym2651y_data *data = ym2651y_update_device(dev); - - return sprintf(buf, "%d\n", data->over_temp >> 7); -} - -static ssize_t show_ascii(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - u8 *ptr = NULL; - - switch (attr->index) { - case PSU_FAN_DIRECTION: /* psu_fan_dir */ - ptr = data->fan_dir; - break; - case PSU_MFR_ID: /* psu_mfr_id */ - ptr = data->mfr_id; - break; - case PSU_MFR_MODEL: /* psu_mfr_model */ - ptr = data->mfr_model; - break; - case PSU_MFR_REVISION: /* psu_mfr_revision */ - ptr = data->mfr_revsion; - break; - default: - return 0; - } - - return sprintf(buf, "%s\n", ptr); -} - -static const struct attribute_group ym2651y_group = { - .attrs = ym2651y_attributes, -}; - -static int ym2651y_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct ym2651y_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE_DATA | - I2C_FUNC_SMBUS_WORD_DATA | - I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct ym2651y_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &ym2651y_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &ym2651y_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int ym2651y_remove(struct i2c_client *client) -{ - struct ym2651y_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &ym2651y_group); - kfree(data); - - return 0; -} - -static const struct i2c_device_id ym2651y_id[] = { - { "ym2651", YM2651 }, - { "ym2401", YM2401 }, - { "ym2851", YM2851 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, ym2651y_id); - -static struct i2c_driver ym2651y_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "ym2651", - }, - .probe = ym2651y_probe, - .remove = ym2651y_remove, - .id_table = ym2651y_id, - .address_list = normal_i2c, -}; - -static int ym2651y_read_byte(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_byte_data(client, reg); -} - -static int ym2651y_read_word(struct i2c_client *client, u8 reg) -{ - return i2c_smbus_read_word_data(client, reg); -} - -static int ym2651y_write_word(struct i2c_client *client, u8 reg, u16 value) -{ - return i2c_smbus_write_word_data(client, reg, value); -} - -static int ym2651y_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) - goto abort; - if (unlikely(result != data_len)) { - result = -EIO; - goto abort; - } - - result = 0; - -abort: - return result; -} - -struct reg_data_byte { - u8 reg; - u8 *value; -}; - -struct reg_data_word { - u8 reg; - u16 *value; -}; - -static struct ym2651y_data *ym2651y_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct ym2651y_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int i, status; - u8 command; - u8 fan_dir[5] = {0}; - struct reg_data_byte regs_byte[] = { {0x19, &data->capability}, - {0x7d, &data->over_temp}, - {0x81, &data->fan_fault}, - {0x98, &data->pmbus_revision} - }; - struct reg_data_word regs_word[] = { {0x79, &data->status_word}, - {0x8b, &data->v_out}, - {0x8c, &data->i_out}, - {0x96, &data->p_out}, - {0x8d, &data->temp}, - {0x3b, &(data->fan_duty_cycle[0])}, - {0x3c, &(data->fan_duty_cycle[1])}, - {0x90, &data->fan_speed}, - {0xa0, &data->mfr_vin_min}, - {0xa1, &data->mfr_vin_max}, - {0xa2, &data->mfr_iin_max}, - {0xa3, &data->mfr_pin_max}, - {0xa4, &data->mfr_vout_min}, - {0xa5, &data->mfr_vout_max}, - {0xa6, &data->mfr_iout_max}, - {0xa7, &data->mfr_pout_max} - }; - - dev_dbg(&client->dev, "Starting ym2651 update\n"); - - /* Read byte data */ - for (i = 0; i < ARRAY_SIZE(regs_byte); i++) { - status = ym2651y_read_byte(client, regs_byte[i].reg); - - if (status < 0) - { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_byte[i].reg, status); - *(regs_byte[i].value) = 0; - } - else { - *(regs_byte[i].value) = status; - } - } - - /* Read word data */ - for (i = 0; i < ARRAY_SIZE(regs_word); i++) { - status = ym2651y_read_word(client, regs_word[i].reg); - - if (status < 0) - { - dev_dbg(&client->dev, "reg %d, err %d\n", - regs_word[i].reg, status); - *(regs_word[i].value) = 0; - } - else { - *(regs_word[i].value) = status; - } - } - - /* Read fan_direction */ - command = 0xC3; - status = ym2651y_read_block(client, command, fan_dir, ARRAY_SIZE(fan_dir)-1); - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - } - - strncpy(data->fan_dir, fan_dir+1, ARRAY_SIZE(data->fan_dir)-1); - data->fan_dir[ARRAY_SIZE(data->fan_dir)-1] = '\0'; - - /* Read mfr_id */ - command = 0x99; - status = ym2651y_read_block(client, command, data->mfr_id, - ARRAY_SIZE(data->mfr_id)-1); - data->mfr_id[ARRAY_SIZE(data->mfr_id)-1] = '\0'; - - if (status < 0) - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - - /* Read mfr_model */ - command = 0x9a; - status = ym2651y_read_block(client, command, data->mfr_model, - ARRAY_SIZE(data->mfr_model)-1); - data->mfr_model[ARRAY_SIZE(data->mfr_model)-1] = '\0'; - - if (status < 0) - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - - /* Read mfr_revsion */ - command = 0x9b; - status = ym2651y_read_block(client, command, data->mfr_revsion, - ARRAY_SIZE(data->mfr_revsion)-1); - data->mfr_revsion[ARRAY_SIZE(data->mfr_revsion)-1] = '\0'; - - if (status < 0) - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - - data->last_updated = jiffies; - data->valid = 1; - } - - mutex_unlock(&data->update_lock); - - return data; -} - -module_i2c_driver(ym2651y_driver); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("3Y Power YM-2651Y driver"); -MODULE_LICENSE("GPL"); - - diff --git a/platform/broadcom/sonic-platform-modules-accton/debian/changelog b/platform/broadcom/sonic-platform-modules-accton/debian/changelog deleted file mode 100755 index 2b08b12c206a..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/debian/changelog +++ /dev/null @@ -1,18 +0,0 @@ -sonic-accton-platform-modules (1.1) unstable; urgency=low - - * Add support for AS7816-64X. - - -- Accton Network Tue, 19 Dec 2017 09:35:58 +0800 - -sonic-accton-platform-modules (1.1) unstable; urgency=low - - * Add support for Accton AS5712-54X - - -- Accton Network Wed, 11 Oct 2017 14:21:45 +0800 - -sonic-accton-platform-modules (1.0) unstable; urgency=low - - * Add support for Accton AS7712-32X - * Initial release - - -- Accton Network Thu, 01 Jun 2017 14:06:38 +0800 diff --git a/platform/broadcom/sonic-platform-modules-accton/debian/compat b/platform/broadcom/sonic-platform-modules-accton/debian/compat deleted file mode 100644 index ec635144f600..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/debian/compat +++ /dev/null @@ -1 +0,0 @@ -9 diff --git a/platform/broadcom/sonic-platform-modules-accton/debian/control b/platform/broadcom/sonic-platform-modules-accton/debian/control deleted file mode 100755 index 22faf6d202b8..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/debian/control +++ /dev/null @@ -1,41 +0,0 @@ -Source: sonic-accton-platform-modules -Section: main -Priority: extra -Maintainer: Accton network , Accton Network -Build-Depends: debhelper (>= 8.0.0), bzip2 -Standards-Version: 3.9.3 - -Package: sonic-platform-accton-as7712-32x -Architecture: amd64 -Depends: linux-image-3.16.0-5-amd64 -Description: kernel modules for platform devices such as fan, led, sfp - -Package: sonic-platform-accton-as5712-54x -Architecture: amd64 -Depends: linux-image-3.16.0-5-amd64 -Description: kernel modules for platform devices such as fan, led, sfp - -Package: sonic-platform-accton-as7816-64x -Architecture: amd64 -Depends: linux-image-3.16.0-5-amd64 -Description: kernel modules for platform devices such as fan, led, sfp - -Package: sonic-platform-accton-as7716-32x -Architecture: amd64 -Depends: linux-image-3.16.0-5-amd64 -Description: kernel modules for platform devices such as fan, led, sfp - -Package: sonic-platform-accton-as7716-32xb -Architecture: amd64 -Depends: linux-image-3.16.0-5-amd64 -Description: kernel modules for platform devices such as fan, led, sfp - -Package: sonic-platform-accton-as7312-54x -Architecture: amd64 -Depends: linux-image-3.16.0-5-amd64 -Description: kernel modules for platform devices such as fan, led, sfp - -Package: sonic-platform-accton-as7326-56x -Architecture: amd64 -Depends: linux-image-3.16.0-5-amd64 -Description: kernel modules for platform devices such as fan, led, sfp diff --git a/platform/broadcom/sonic-platform-modules-accton/debian/rules b/platform/broadcom/sonic-platform-modules-accton/debian/rules deleted file mode 100755 index 8274607f27b5..000000000000 --- a/platform/broadcom/sonic-platform-modules-accton/debian/rules +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/make -f -# -*- makefile -*- -# Sample debian/rules that uses debhelper. -# This file was originally written by Joey Hess and Craig Small. -# As a special exception, when this file is copied by dh-make into a -# dh-make output file, you may use that output file without restriction. -# This special exception was added by Craig Small in version 0.37 of dh-make. - -include /usr/share/dpkg/pkg-info.mk - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - -export INSTALL_MOD_DIR:=extra - -PYTHON ?= python2 - -PACKAGE_PRE_NAME := sonic-platform-accton -KVERSION ?= $(shell uname -r) -KERNEL_SRC := /lib/modules/$(KVERSION) -MOD_SRC_DIR:= $(shell pwd) -MODULE_DIRS:= as7712-32x as5712-54x as7816-64x as7716-32x as7716-32xb as7312-54x as7326-56x -MODULE_DIR := modules -UTILS_DIR := utils -SERVICE_DIR := service -CLASSES_DIR := classes -CONF_DIR := conf - -%: - dh $@ --with systemd,python2,python3 --buildsystem=pybuild - -clean: - dh_testdir - dh_testroot - dh_clean - -build: - #make modules -C $(KERNEL_SRC)/build M=$(MODULE_SRC) - (for mod in $(MODULE_DIRS); do \ - make modules -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules; \ - $(PYTHON) $${mod}/setup.py build; \ - done) - -binary: binary-arch binary-indep - # Nothing to do - -binary-arch: - # Nothing to do - -#install: build - #dh_testdir - #dh_testroot - #dh_clean -k - #dh_installdirs - -binary-indep: - dh_testdir - dh_installdirs - - # Custom package commands - (for mod in $(MODULE_DIRS); do \ - dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod}/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ - dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod}/usr/local/bin; \ - dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod}/lib/systemd/system; \ - cp $(MOD_SRC_DIR)/$${mod}/$(MODULE_DIR)/*.ko debian/$(PACKAGE_PRE_NAME)-$${mod}/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ - cp $(MOD_SRC_DIR)/$${mod}/$(UTILS_DIR)/* debian/$(PACKAGE_PRE_NAME)-$${mod}/usr/local/bin/; \ - cp $(MOD_SRC_DIR)/$${mod}/$(SERVICE_DIR)/*.service debian/$(PACKAGE_PRE_NAME)-$${mod}/lib/systemd/system/; \ - $(PYTHON) $${mod}/setup.py install --root=$(MOD_SRC_DIR)/debian/$(PACKAGE_PRE_NAME)-$${mod} --install-layout=deb; \ - done) - # Resuming debhelper scripts - dh_testroot - dh_install - dh_installchangelogs - dh_installdocs - dh_systemd_enable - dh_installinit - dh_systemd_start - dh_link - dh_fixperms - dh_compress - dh_strip - dh_installdeb - dh_gencontrol - dh_md5sums - dh_builddeb -.PHONY: build binary binary-arch binary-indep clean