From fcadc03ce54c779fb9d5a737aa6586bcf16f2eeb Mon Sep 17 00:00:00 2001 From: willy_liu Date: Fri, 8 Nov 2024 18:27:54 +0800 Subject: [PATCH] [ACCTON][AS5915-16X] Add new platform CPU: Intel Atom Processor C3308, 1.6GHz sub-system: DDR SDRAM: 8GB x 1 2400MHz with ECC (SO-DIMM) DDR4 SPI Flash (Boot): 16MB x 2 M.2 SSD: 32GB MLC TPM: SLB9670XQ2.0FW7.63 INFINEON Management : UART RS232 console port (RJ45), Out-band Management Ethernet port (RJ45) Timing: GNSS GPS Receiver (SMB reserved), 1PPS IN and 1PPS OUT(SMB), 10MHz IN and 10MHz OUT (SMB), ToD PPS (RJ45) MAC: Broadcom BCM88273, 32Gbps full duplex switching Ethernet Ports: 4x 10GE SFP+, 8x 1GE SFP and 4x 1GE RJ45 CPLD: Altera 5M2210ZF324I5N (FBGA324) FPGA: Altera EP4CGX50CF23I7N (FBGA484) PCB: 18 Layers, TU-863+ for Motherboard 8 Layers, CPU board PSU: Max 180W output, DC to DC, 1+1 redundant load-sharing Signed-off-by: willy_liu --- .../configs/x86_64-all/x86_64-all.config | 357 +++++++++- .../accton/x86-64/as5915-16x/.gitignore | 2 + .../accton/x86-64/as5915-16x/Makefile | 2 + .../accton/x86-64/as5915-16x/modules/Makefile | 2 + .../accton/x86-64/as5915-16x/modules/PKG.yml | 1 + .../x86-64/as5915-16x/modules/builds/Makefile | 7 + .../as5915-16x/modules/builds/src/Makefile | 5 + .../src/x86-64-accton-as5915-16x-cpld.c | 637 ++++++++++++++++++ .../src/x86-64-accton-as5915-16x-fpga.c | 465 +++++++++++++ .../src/x86-64-accton-as5915-16x-leds.c | 397 +++++++++++ .../builds/src/x86-64-accton-as5915-16x-psu.c | 439 ++++++++++++ .../builds/src/x86-64-accton-as5915-16x-sys.c | 177 +++++ .../accton/x86-64/as5915-16x/onlp/Makefile | 2 + .../accton/x86-64/as5915-16x/onlp/PKG.yml | 1 + .../x86-64/as5915-16x/onlp/builds/Makefile | 2 + .../as5915-16x/onlp/builds/lib/Makefile | 3 + .../as5915-16x/onlp/builds/onlpdump/Makefile | 3 + .../builds/x86_64_accton_as5915_16x/.module | 1 + .../builds/x86_64_accton_as5915_16x/Makefile | 9 + .../module/auto/make.mk | 9 + .../module/auto/x86_64_accton_as5915_16x.yml | 50 ++ .../x86_64_accton_as5915_16x.x | 12 + .../x86_64_accton_as5915_16x_config.h | 137 ++++ .../x86_64_accton_as5915_16x_dox.h | 26 + .../x86_64_accton_as5915_16x_porting.h | 107 +++ .../x86_64_accton_as5915_16x/module/make.mk | 10 + .../module/src/Makefile | 9 + .../module/src/debug.c | 68 ++ .../module/src/fani.c | 48 ++ .../module/src/ledi.c | 299 ++++++++ .../module/src/make.mk | 9 + .../module/src/platform_lib.h | 81 +++ .../module/src/psui.c | 217 ++++++ .../module/src/sfpi.c | 352 ++++++++++ .../module/src/sysi.c | 149 ++++ .../module/src/thermali.c | 125 ++++ .../src/x86_64_accton_as5915_16x_config.c | 81 +++ .../src/x86_64_accton_as5915_16x_enums.c | 10 + .../module/src/x86_64_accton_as5915_16x_int.h | 12 + .../module/src/x86_64_accton_as5915_16x_log.c | 17 + .../module/src/x86_64_accton_as5915_16x_log.h | 12 + .../src/x86_64_accton_as5915_16x_module.c | 24 + .../src/x86_64_accton_as5915_16x_ucli.c | 50 ++ .../as5915-16x/platform-config/Makefile | 2 + .../as5915-16x/platform-config/r0/Makefile | 2 + .../as5915-16x/platform-config/r0/PKG.yml | 1 + .../src/lib/x86-64-accton-as5915-16x-r0.yml | 31 + .../x86_64_accton_as5915_16x_r0/__init__.py | 104 +++ 48 files changed, 4560 insertions(+), 6 deletions(-) create mode 100644 packages/platforms/accton/x86-64/as5915-16x/.gitignore create mode 100644 packages/platforms/accton/x86-64/as5915-16x/Makefile create mode 100644 packages/platforms/accton/x86-64/as5915-16x/modules/Makefile create mode 100644 packages/platforms/accton/x86-64/as5915-16x/modules/PKG.yml create mode 100644 packages/platforms/accton/x86-64/as5915-16x/modules/builds/Makefile create mode 100644 packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/Makefile create mode 100644 packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-cpld.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-fpga.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-leds.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-psu.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-sys.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/Makefile create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/PKG.yml create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/Makefile create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/lib/Makefile create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/onlpdump/Makefile create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/.module create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/Makefile create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/auto/make.mk create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/auto/x86_64_accton_as5915_16x.yml create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x.x create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x_config.h create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x_dox.h create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x_porting.h create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/make.mk create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/Makefile create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/debug.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/fani.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/ledi.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/make.mk create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/platform_lib.h create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/psui.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/sfpi.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/sysi.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/thermali.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_config.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_enums.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_int.h create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_log.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_log.h create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_module.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_ucli.c create mode 100644 packages/platforms/accton/x86-64/as5915-16x/platform-config/Makefile create mode 100644 packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/Makefile create mode 100644 packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/PKG.yml create mode 100644 packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/src/lib/x86-64-accton-as5915-16x-r0.yml create mode 100644 packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/src/python/x86_64_accton_as5915_16x_r0/__init__.py diff --git a/packages/base/any/kernels/5.4-lts/configs/x86_64-all/x86_64-all.config b/packages/base/any/kernels/5.4-lts/configs/x86_64-all/x86_64-all.config index 2d76bf62af..2dc9b3f16d 100644 --- a/packages/base/any/kernels/5.4-lts/configs/x86_64-all/x86_64-all.config +++ b/packages/base/any/kernels/5.4-lts/configs/x86_64-all/x86_64-all.config @@ -1344,7 +1344,7 @@ CONFIG_DEBUG_DEVRES=y CONFIG_GENERIC_CPU_AUTOPROBE=y CONFIG_GENERIC_CPU_VULNERABILITIES=y CONFIG_REGMAP=y -CONFIG_REGMAP_I2C=m +CONFIG_REGMAP_I2C=y CONFIG_DMA_SHARED_BUFFER=y # CONFIG_DMA_FENCE_TRACE is not set # end of Generic Driver Options @@ -2108,6 +2108,7 @@ CONFIG_INPUT_EVDEV=y # Input Device Drivers # CONFIG_INPUT_KEYBOARD=y +# CONFIG_KEYBOARD_ADC is not set # CONFIG_KEYBOARD_ADP5588 is not set # CONFIG_KEYBOARD_ADP5589 is not set CONFIG_KEYBOARD_ATKBD=y @@ -2193,6 +2194,7 @@ CONFIG_INPUT_TABLET=y CONFIG_INPUT_TOUCHSCREEN=y CONFIG_TOUCHSCREEN_PROPERTIES=y # CONFIG_TOUCHSCREEN_AD7879 is not set +# CONFIG_TOUCHSCREEN_ADC is not set # CONFIG_TOUCHSCREEN_ATMEL_MXT is not set # CONFIG_TOUCHSCREEN_AUO_PIXCIR is not set # CONFIG_TOUCHSCREEN_BU21013 is not set @@ -2607,6 +2609,7 @@ CONFIG_POWER_SUPPLY=y # CONFIG_POWER_SUPPLY_DEBUG is not set CONFIG_POWER_SUPPLY_HWMON=y # CONFIG_PDA_POWER is not set +# CONFIG_GENERIC_ADC_BATTERY is not set # CONFIG_TEST_POWER is not set # CONFIG_CHARGER_ADP5061 is not set # CONFIG_BATTERY_DS2780 is not set @@ -2628,6 +2631,7 @@ CONFIG_POWER_SUPPLY_HWMON=y # CONFIG_CHARGER_BQ25890 is not set # CONFIG_CHARGER_SMB347 is not set # CONFIG_BATTERY_GAUGE_LTC2941 is not set +# CONFIG_BATTERY_RT5033 is not set # CONFIG_CHARGER_RT9455 is not set CONFIG_HWMON=y # CONFIG_HWMON_DEBUG_CHIP is not set @@ -2675,6 +2679,7 @@ CONFIG_HWMON=y # CONFIG_SENSORS_HIH6130 is not set # CONFIG_SENSORS_IBMAEM is not set # CONFIG_SENSORS_IBMPEX is not set +# CONFIG_SENSORS_IIO_HWMON is not set # CONFIG_SENSORS_I5500 is not set CONFIG_SENSORS_CORETEMP=y # CONFIG_SENSORS_IT87 is not set @@ -2703,7 +2708,7 @@ CONFIG_SENSORS_CORETEMP=y # CONFIG_SENSORS_TC654 is not set # CONFIG_SENSORS_LM63 is not set # CONFIG_SENSORS_LM73 is not set -# CONFIG_SENSORS_LM75 is not set +CONFIG_SENSORS_LM75=y # CONFIG_SENSORS_LM77 is not set # CONFIG_SENSORS_LM78 is not set # CONFIG_SENSORS_LM80 is not set @@ -2725,7 +2730,29 @@ CONFIG_SENSORS_CORETEMP=y # CONFIG_SENSORS_NCT7904 is not set # CONFIG_SENSORS_NPCM7XX is not set # CONFIG_SENSORS_PCF8591 is not set -# CONFIG_PMBUS is not set +CONFIG_PMBUS=y +CONFIG_SENSORS_PMBUS=y +# CONFIG_SENSORS_ADM1275 is not set +# CONFIG_SENSORS_IBM_CFFPS is not set +# CONFIG_SENSORS_INSPUR_IPSPS is not set +# CONFIG_SENSORS_IR35221 is not set +# CONFIG_SENSORS_IR38064 is not set +# CONFIG_SENSORS_IRPS5401 is not set +# CONFIG_SENSORS_ISL68137 is not set +# CONFIG_SENSORS_LM25066 is not set +# CONFIG_SENSORS_LTC2978 is not set +# CONFIG_SENSORS_LTC3815 is not set +# CONFIG_SENSORS_MAX16064 is not set +# CONFIG_SENSORS_MAX20751 is not set +# CONFIG_SENSORS_MAX31785 is not set +# CONFIG_SENSORS_MAX34440 is not set +# CONFIG_SENSORS_MAX8688 is not set +# CONFIG_SENSORS_PXE1610 is not set +# CONFIG_SENSORS_TPS40422 is not set +CONFIG_SENSORS_TPS53679=y +# CONFIG_SENSORS_UCD9000 is not set +# CONFIG_SENSORS_UCD9200 is not set +# CONFIG_SENSORS_ZL6100 is not set # CONFIG_SENSORS_SHT15 is not set # CONFIG_SENSORS_SHT21 is not set # CONFIG_SENSORS_SHT3x is not set @@ -2750,7 +2777,7 @@ CONFIG_SENSORS_CORETEMP=y # CONFIG_SENSORS_INA3221 is not set # CONFIG_SENSORS_TC74 is not set # CONFIG_SENSORS_THMC50 is not set -# CONFIG_SENSORS_TMP102 is not set +CONFIG_SENSORS_TMP102=y # CONFIG_SENSORS_TMP103 is not set # CONFIG_SENSORS_TMP108 is not set # CONFIG_SENSORS_TMP401 is not set @@ -2808,6 +2835,7 @@ CONFIG_X86_PKG_TEMP_THERMAL=m # CONFIG_INTEL_PCH_THERMAL is not set # end of Intel thermal drivers +# CONFIG_GENERIC_ADC_THERMAL is not set CONFIG_WATCHDOG=y # CONFIG_WATCHDOG_CORE is not set # CONFIG_WATCHDOG_NOWAYOUT is not set @@ -3623,7 +3651,7 @@ CONFIG_LEDS_CLASS=y # LED Triggers # CONFIG_LEDS_TRIGGERS=y -# CONFIG_LEDS_TRIGGER_TIMER is not set +CONFIG_LEDS_TRIGGER_TIMER=y # CONFIG_LEDS_TRIGGER_ONESHOT is not set # CONFIG_LEDS_TRIGGER_DISK is not set # CONFIG_LEDS_TRIGGER_HEARTBEAT is not set @@ -3981,7 +4009,323 @@ CONFIG_INTEL_IOMMU_FLOPPY_WA=y # CONFIG_PM_DEVFREQ is not set # CONFIG_EXTCON is not set # CONFIG_MEMORY is not set -# CONFIG_IIO is not set +CONFIG_IIO=y +CONFIG_IIO_BUFFER=y +# CONFIG_IIO_BUFFER_CB is not set +# CONFIG_IIO_BUFFER_HW_CONSUMER is not set +CONFIG_IIO_KFIFO_BUF=y +CONFIG_IIO_TRIGGERED_BUFFER=y +# CONFIG_IIO_CONFIGFS is not set +CONFIG_IIO_TRIGGER=y +CONFIG_IIO_CONSUMERS_PER_TRIGGER=2 +# CONFIG_IIO_SW_DEVICE is not set +# CONFIG_IIO_SW_TRIGGER is not set + +# +# Accelerometers +# +# CONFIG_ADXL345_I2C is not set +# CONFIG_ADXL372_I2C is not set +# CONFIG_BMA180 is not set +# CONFIG_BMC150_ACCEL is not set +# CONFIG_DA280 is not set +# CONFIG_DA311 is not set +# CONFIG_DMARD09 is not set +# CONFIG_DMARD10 is not set +# CONFIG_IIO_ST_ACCEL_3AXIS is not set +# CONFIG_KXSD9 is not set +# CONFIG_KXCJK1013 is not set +# CONFIG_MC3230 is not set +# CONFIG_MMA7455_I2C is not set +# CONFIG_MMA7660 is not set +# CONFIG_MMA8452 is not set +# CONFIG_MMA9551 is not set +# CONFIG_MMA9553 is not set +# CONFIG_MXC4005 is not set +# CONFIG_MXC6255 is not set +# CONFIG_STK8312 is not set +# CONFIG_STK8BA50 is not set +# end of Accelerometers + +# +# Analog to digital converters +# +# CONFIG_AD7291 is not set +# CONFIG_AD7606_IFACE_PARALLEL is not set +# CONFIG_AD799X is not set +# CONFIG_HX711 is not set +# CONFIG_INA2XX_ADC is not set +# CONFIG_LTC2471 is not set +# CONFIG_LTC2485 is not set +# CONFIG_LTC2497 is not set +CONFIG_MAX1363=y +# CONFIG_MAX9611 is not set +# CONFIG_MCP3422 is not set +# CONFIG_NAU7802 is not set +# CONFIG_TI_ADC081C is not set +# CONFIG_TI_ADS1015 is not set +# CONFIG_XILINX_XADC is not set +# end of Analog to digital converters + +# +# Analog to digital and digital to analog converters +# +# end of Analog to digital and digital to analog converters + +# +# Analog Front Ends +# +# end of Analog Front Ends + +# +# Amplifiers +# +# end of Amplifiers + +# +# Chemical Sensors +# +# CONFIG_ATLAS_PH_SENSOR is not set +# CONFIG_BME680 is not set +# CONFIG_CCS811 is not set +# CONFIG_IAQCORE is not set +# CONFIG_SENSIRION_SGP30 is not set +# CONFIG_SPS30 is not set +# CONFIG_VZ89X is not set +# end of Chemical Sensors + +# +# Hid Sensor IIO Common +# +# end of Hid Sensor IIO Common + +# +# SSP Sensor Common +# +# end of SSP Sensor Common + +# +# Digital to analog converters +# +# CONFIG_AD5064 is not set +# CONFIG_AD5380 is not set +# CONFIG_AD5446 is not set +# CONFIG_AD5593R is not set +# CONFIG_AD5696_I2C is not set +# CONFIG_DS4424 is not set +# CONFIG_M62332 is not set +# CONFIG_MAX517 is not set +# CONFIG_MCP4725 is not set +# CONFIG_TI_DAC5571 is not set +# end of Digital to analog converters + +# +# IIO dummy driver +# +# end of IIO dummy driver + +# +# Frequency Synthesizers DDS/PLL +# + +# +# Clock Generator/Distribution +# +# end of Clock Generator/Distribution + +# +# Phase-Locked Loop (PLL) frequency synthesizers +# +# end of Phase-Locked Loop (PLL) frequency synthesizers +# end of Frequency Synthesizers DDS/PLL + +# +# Digital gyroscope sensors +# +# CONFIG_BMG160 is not set +# CONFIG_FXAS21002C is not set +# CONFIG_MPU3050_I2C is not set +# CONFIG_IIO_ST_GYRO_3AXIS is not set +# CONFIG_ITG3200 is not set +# end of Digital gyroscope sensors + +# +# Health Sensors +# + +# +# Heart Rate Monitors +# +# CONFIG_AFE4404 is not set +# CONFIG_MAX30100 is not set +# CONFIG_MAX30102 is not set +# end of Heart Rate Monitors +# end of Health Sensors + +# +# Humidity sensors +# +# CONFIG_AM2315 is not set +# CONFIG_DHT11 is not set +# CONFIG_HDC100X is not set +# CONFIG_HTS221 is not set +# CONFIG_HTU21 is not set +# CONFIG_SI7005 is not set +# CONFIG_SI7020 is not set +# end of Humidity sensors + +# +# Inertial measurement units +# +# CONFIG_BMI160_I2C is not set +# CONFIG_KMX61 is not set +# CONFIG_INV_MPU6050_I2C is not set +# CONFIG_IIO_ST_LSM6DSX is not set +# end of Inertial measurement units + +# +# Light sensors +# +# CONFIG_ACPI_ALS is not set +# CONFIG_ADJD_S311 is not set +# CONFIG_AL3320A is not set +# CONFIG_APDS9300 is not set +# CONFIG_APDS9960 is not set +# CONFIG_BH1750 is not set +# CONFIG_BH1780 is not set +# CONFIG_CM32181 is not set +# CONFIG_CM3232 is not set +# CONFIG_CM3323 is not set +# CONFIG_CM36651 is not set +# CONFIG_GP2AP020A00F is not set +# CONFIG_SENSORS_ISL29018 is not set +# CONFIG_SENSORS_ISL29028 is not set +# CONFIG_ISL29125 is not set +# CONFIG_JSA1212 is not set +# CONFIG_RPR0521 is not set +# CONFIG_LTR501 is not set +# CONFIG_LV0104CS is not set +# CONFIG_MAX44000 is not set +# CONFIG_MAX44009 is not set +# CONFIG_NOA1305 is not set +# CONFIG_OPT3001 is not set +# CONFIG_PA12203001 is not set +# CONFIG_SI1133 is not set +# CONFIG_SI1145 is not set +# CONFIG_STK3310 is not set +# CONFIG_ST_UVIS25 is not set +# CONFIG_TCS3414 is not set +# CONFIG_TCS3472 is not set +# CONFIG_SENSORS_TSL2563 is not set +# CONFIG_TSL2583 is not set +# CONFIG_TSL2772 is not set +# CONFIG_TSL4531 is not set +# CONFIG_US5182D is not set +# CONFIG_VCNL4000 is not set +# CONFIG_VCNL4035 is not set +# CONFIG_VEML6070 is not set +# CONFIG_VL6180 is not set +# CONFIG_ZOPT2201 is not set +# end of Light sensors + +# +# Magnetometer sensors +# +# CONFIG_AK8975 is not set +# CONFIG_AK09911 is not set +# CONFIG_BMC150_MAGN_I2C is not set +# CONFIG_MAG3110 is not set +# CONFIG_MMC35240 is not set +# CONFIG_IIO_ST_MAGN_3AXIS is not set +# CONFIG_SENSORS_HMC5843_I2C is not set +# CONFIG_SENSORS_RM3100_I2C is not set +# end of Magnetometer sensors + +# +# Multiplexers +# +# end of Multiplexers + +# +# Inclinometer sensors +# +# end of Inclinometer sensors + +# +# Triggers - standalone +# +# CONFIG_IIO_INTERRUPT_TRIGGER is not set +# CONFIG_IIO_SYSFS_TRIGGER is not set +# end of Triggers - standalone + +# +# Digital potentiometers +# +# CONFIG_AD5272 is not set +# CONFIG_DS1803 is not set +# CONFIG_MAX5432 is not set +# CONFIG_MCP4018 is not set +# CONFIG_MCP4531 is not set +# CONFIG_TPL0102 is not set +# end of Digital potentiometers + +# +# Digital potentiostats +# +# CONFIG_LMP91000 is not set +# end of Digital potentiostats + +# +# Pressure sensors +# +# CONFIG_ABP060MG is not set +# CONFIG_BMP280 is not set +# CONFIG_DPS310 is not set +# CONFIG_HP03 is not set +# CONFIG_MPL115_I2C is not set +# CONFIG_MPL3115 is not set +# CONFIG_MS5611 is not set +# CONFIG_MS5637 is not set +# CONFIG_IIO_ST_PRESS is not set +# CONFIG_T5403 is not set +# CONFIG_HP206C is not set +# CONFIG_ZPA2326 is not set +# end of Pressure sensors + +# +# Lightning sensors +# +# end of Lightning sensors + +# +# Proximity and distance sensors +# +# CONFIG_ISL29501 is not set +# CONFIG_LIDAR_LITE_V2 is not set +# CONFIG_MB1232 is not set +# CONFIG_RFD77402 is not set +# CONFIG_SRF04 is not set +# CONFIG_SX9500 is not set +# CONFIG_SRF08 is not set +# CONFIG_VL53L0X_I2C is not set +# end of Proximity and distance sensors + +# +# Resolver to digital converters +# +# end of Resolver to digital converters + +# +# Temperature sensors +# +# CONFIG_MLX90614 is not set +# CONFIG_MLX90632 is not set +# CONFIG_TMP006 is not set +# CONFIG_TMP007 is not set +# CONFIG_TSYS01 is not set +# CONFIG_TSYS02D is not set +# end of Temperature sensors + # CONFIG_NTB is not set # CONFIG_VME_BUS is not set # CONFIG_PWM is not set @@ -4001,6 +4345,7 @@ CONFIG_INTEL_IOMMU_FLOPPY_WA=y # CONFIG_BCM_KONA_USB2_PHY is not set # CONFIG_PHY_PXA_28NM_HSIC is not set # CONFIG_PHY_PXA_28NM_USB2 is not set +# CONFIG_PHY_CPCAP_USB is not set # end of PHY Subsystem # CONFIG_POWERCAP is not set diff --git a/packages/platforms/accton/x86-64/as5915-16x/.gitignore b/packages/platforms/accton/x86-64/as5915-16x/.gitignore new file mode 100644 index 0000000000..373c20cfbd --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/.gitignore @@ -0,0 +1,2 @@ +*x86*64*accton*as5915*16x*.mk +onlpdump.mk diff --git a/packages/platforms/accton/x86-64/as5915-16x/Makefile b/packages/platforms/accton/x86-64/as5915-16x/Makefile new file mode 100644 index 0000000000..26aa37e6b4 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/Makefile @@ -0,0 +1,2 @@ +include $(ONL)/make/pkg.mk + diff --git a/packages/platforms/accton/x86-64/as5915-16x/modules/Makefile b/packages/platforms/accton/x86-64/as5915-16x/modules/Makefile new file mode 100644 index 0000000000..26aa37e6b4 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/modules/Makefile @@ -0,0 +1,2 @@ +include $(ONL)/make/pkg.mk + diff --git a/packages/platforms/accton/x86-64/as5915-16x/modules/PKG.yml b/packages/platforms/accton/x86-64/as5915-16x/modules/PKG.yml new file mode 100644 index 0000000000..c0a0c32c43 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/modules/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-modules.yml VENDOR=accton BASENAME=x86-64-accton-as5915-16x ARCH=amd64 KERNELS="onl-kernel-5.4-lts-x86-64-all:amd64" diff --git a/packages/platforms/accton/x86-64/as5915-16x/modules/builds/Makefile b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/Makefile new file mode 100644 index 0000000000..28bed95728 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/Makefile @@ -0,0 +1,7 @@ +KERNELS := onl-kernel-5.4-lts-x86-64-all:amd64 +KMODULES := src +VENDOR := accton +BASENAME := x86-64-accton-as5915-16x +ARCH := x86_64 +include $(ONL)/make/kmodule.mk + diff --git a/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/Makefile b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/Makefile new file mode 100644 index 0000000000..51fc50afa1 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/Makefile @@ -0,0 +1,5 @@ +obj-m += x86-64-accton-as5915-16x-cpld.o +obj-m += x86-64-accton-as5915-16x-fpga.o +obj-m += x86-64-accton-as5915-16x-leds.o +obj-m += x86-64-accton-as5915-16x-psu.o +obj-m += x86-64-accton-as5915-16x-sys.o diff --git a/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-cpld.c b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-cpld.c new file mode 100644 index 0000000000..3f9c9459a6 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-cpld.c @@ -0,0 +1,637 @@ +/* + * 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 as5915_16x 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 { + as5915_16x_cpld +}; + +struct as5915_16x_cpld_data { + enum cpld_type type; + struct device *hwmon_dev; + struct mutex update_lock; +}; + +static const struct i2c_device_id as5915_16x_cpld_id[] = { + { "as5915_16x_cpld", as5915_16x_cpld }, + { } +}; +MODULE_DEVICE_TABLE(i2c, as5915_16x_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 + +enum as5915_16x_cpld_sysfs_attributes { + CPLD_VERSION, + CPLD_SUB_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_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_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_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), +}; + +/* 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_control(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 as5915_16x_cpld_read_internal(struct i2c_client *client, u8 reg); +static int as5915_16x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); + +/* transceiver attributes */ +#define DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index); \ + static SENSOR_DEVICE_ATTR(module_tx_disable_##index, S_IRUGO | S_IWUSR, show_status, set_control, 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_present_##index.dev_attr.attr, \ + &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(sub_version, S_IRUGO, show_version, NULL, CPLD_SUB_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_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); + +static struct attribute *as5915_16x_cpld_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_sub_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_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), + NULL +}; + +static const struct attribute_group as5915_16x_cpld_group = { + .attrs = as5915_16x_cpld_attributes, +}; + +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status; + u8 values[2] = {0}; + u8 regs_cpld[] = {0x10, 0x14}; + u8 *regs[] = { regs_cpld }; + u8 size[] = { ARRAY_SIZE(regs_cpld) }; + struct i2c_client *client = to_i2c_client(dev); + struct as5915_16x_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + for (i = 0; i < size[data->type]; i++) { + status = as5915_16x_cpld_read_internal(client, regs[data->type][i]); + if (status < 0) { + goto exit; + } + + values[i] = ~(u8)status; + } + + mutex_unlock(&data->update_lock); + + /* Return values in order */ + return sprintf(buf, "%.2x %.2x\n", values[0], values[1] & 0x3F); + +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[2] = {0}; + u8 regs_cpld[] = {0x13, 0x17}; + u8 *regs[] = { regs_cpld }; + u8 size[] = { ARRAY_SIZE(regs_cpld) }; + struct i2c_client *client = to_i2c_client(dev); + struct as5915_16x_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + for (i = 0; i < size[data->type]; i++) { + status = as5915_16x_cpld_read_internal(client, regs[data->type][i]); + if (status < 0) { + goto exit; + } + + values[i] = (u8)status; + } + + mutex_unlock(&data->update_lock); + + /* Return values in order */ + return sprintf(buf, "%.2x %.2x\n", values[0], values[1] & 0x3F); + +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 as5915_16x_cpld_data *data = i2c_get_clientdata(client); + int status = 0; + u8 reg = 0, mask = 0, invert = 0; + + switch (attr->index) { + case MODULE_PRESENT_1 ... MODULE_PRESENT_6: + reg = 0x10; + mask = 0x1 << (attr->index - MODULE_PRESENT_1 + 2); + break; + case MODULE_PRESENT_7 ... MODULE_PRESENT_12: + reg = 0x14; + mask = 0x1 << (attr->index - MODULE_PRESENT_7); + break; + case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_6: + reg = 0x12; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_1 + 2); + break; + case MODULE_TXDISABLE_7 ... MODULE_TXDISABLE_12: + reg = 0x16; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_7); + break; + case MODULE_TXFAULT_1 ... MODULE_TXFAULT_6: + reg = 0x11; + mask = 0x1 << (attr->index - MODULE_TXFAULT_1 + 2); + break; + case MODULE_TXFAULT_7 ... MODULE_TXFAULT_12: + reg = 0x15; + mask = 0x1 << (attr->index - MODULE_TXFAULT_7); + break; + case MODULE_RXLOS_1 ... MODULE_RXLOS_6: + reg = 0x13; + mask = 0x1 << (attr->index - MODULE_RXLOS_1 + 2); + break; + case MODULE_RXLOS_7 ... MODULE_RXLOS_12: + reg = 0x17; + mask = 0x1 << (attr->index - MODULE_RXLOS_7); + break; + default: + return 0; + } + + if ((attr->index >= MODULE_PRESENT_1) && + (attr->index <= MODULE_PRESENT_12)) { + invert = 1; + } + + mutex_lock(&data->update_lock); + status = as5915_16x_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + + return sprintf(buf, "%d\n", invert ? !(status & mask) : !!(status & mask)); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t set_control(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 as5915_16x_cpld_data *data = i2c_get_clientdata(client); + long value; + int status; + u8 reg = 0, mask = 0; + + status = kstrtol(buf, 10, &value); + if (status) { + return status; + } + + switch (attr->index) { + case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_6: + reg = 0x12; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_1 + 2); + break; + case MODULE_TXDISABLE_7 ... MODULE_TXDISABLE_12: + reg = 0x16; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_7); + break; + default: + return 0; + } + + /* Read current status */ + mutex_lock(&data->update_lock); + status = as5915_16x_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + + /* Update tx_disable status */ + if (value) { + status |= mask; + } + else { + status &= ~mask; + } + + status = as5915_16x_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 as5915_16x_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 = as5915_16x_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 as5915_16x_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 as5915_16x_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 *da, char *buf) +{ + u8 reg = 0; + int val = 0; + struct i2c_client *client = to_i2c_client(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + + reg = (attr->index == CPLD_VERSION) ? 0x1 : 0x2; // 0x2 for CPLD_SUB_VERSION + val = i2c_smbus_read_byte_data(client, reg); + + if (val < 0) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", client->addr, reg, val); + } + + return sprintf(buf, "%d\n", val); +} + +/* + * I2C init/probing/exit functions + */ +static int as5915_16x_cpld_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); + struct as5915_16x_cpld_data *data; + int ret = -ENODEV; + const struct attribute_group *group = &as5915_16x_cpld_group; + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) + goto exit; + + data = kzalloc(sizeof(struct as5915_16x_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 */ + ret = sysfs_create_group(&client->dev.kobj, group); + if (ret) { + goto exit_free; + } + + as5915_16x_cpld_add_client(client); + return 0; + +exit_free: + kfree(data); +exit: + return ret; +} + +static int as5915_16x_cpld_remove(struct i2c_client *client) +{ + struct as5915_16x_cpld_data *data = i2c_get_clientdata(client); + const struct attribute_group *group = &as5915_16x_cpld_group; + + as5915_16x_cpld_remove_client(client); + + /* Remove sysfs hooks */ + sysfs_remove_group(&client->dev.kobj, group); + kfree(data); + + return 0; +} + +static int as5915_16x_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 as5915_16x_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 as5915_16x_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 = as5915_16x_cpld_read_internal(cpld_node->client, reg); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as5915_16x_cpld_read); + +int as5915_16x_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 = as5915_16x_cpld_write_internal(cpld_node->client, reg, value); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as5915_16x_cpld_write); + +static struct i2c_driver as5915_16x_cpld_driver = { + .driver = { + .name = "as5915_16x_cpld", + .owner = THIS_MODULE, + }, + .probe = as5915_16x_cpld_probe, + .remove = as5915_16x_cpld_remove, + .id_table = as5915_16x_cpld_id, +}; + +static int __init as5915_16x_cpld_init(void) +{ + mutex_init(&list_lock); + return i2c_add_driver(&as5915_16x_cpld_driver); +} + +static void __exit as5915_16x_cpld_exit(void) +{ + i2c_del_driver(&as5915_16x_cpld_driver); +} + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("Accton I2C CPLD driver"); +MODULE_LICENSE("GPL"); + +module_init(as5915_16x_cpld_init); +module_exit(as5915_16x_cpld_exit); + diff --git a/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-fpga.c b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-fpga.c new file mode 100644 index 0000000000..70972a9b26 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-fpga.c @@ -0,0 +1,465 @@ +/* + * An I2C multiplexer dirver for accton as5712 fpga + * + * Copyright (C) 2015 Accton Technology Corporation. + * Brandon Chuang + * + * This module supports the accton fpga that hold the channel select + * mechanism for other i2c slave devices, such as SFP. + * This includes the: + * Accton as5915_16x fpga1/fpga2/fpga3 + * + * 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 +#include + +#define I2C_RW_RETRY_COUNT 10 +#define I2C_RW_RETRY_INTERVAL 60 /* ms */ + +#define NUM_OF_FPGA_CHANS 0x4 +#define FPGA_CHANNEL_SELECT_REG 0x80 +#define FPGA_DESELECT_CHANNEL 0x10 + +static LIST_HEAD(fpga_client_list); +static struct mutex list_lock; + +struct fpga_client_node { + struct i2c_client *client; + struct list_head list; +}; + +enum fpga_mux_type { + as5915_16x_fpga +}; + +struct as5915_16x_fpga_data { + enum fpga_mux_type type; + struct i2c_client *client; + u8 last_chan; /* last register value */ + + struct device *hwmon_dev; + struct mutex update_lock; +}; + +struct chip_desc { + u8 nchans; + u8 deselectChan; +}; + +/* Provide specs for the PCA954x types we know about */ +static const struct chip_desc chips[] = { + [as5915_16x_fpga] = { + .nchans = NUM_OF_FPGA_CHANS, + .deselectChan = FPGA_DESELECT_CHANNEL, + } +}; + +static const struct i2c_device_id as5915_16x_fpga_mux_id[] = { + { "as5915_16x_fpga", as5915_16x_fpga }, + { } +}; +MODULE_DEVICE_TABLE(i2c, as5915_16x_fpga_mux_id); + +enum as5915_16x_fpga_sysfs_attributes { + FPGA_VERSION, + PCB_VERSION, + ACCESS, +}; + +/* sysfs attributes for hwmon + */ +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 as5915_16x_fpga_read_internal(struct i2c_client *client, u8 reg); +static int as5915_16x_fpga_write_internal(struct i2c_client *client, u8 reg, u8 value); + +static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, FPGA_VERSION); +static SENSOR_DEVICE_ATTR(pcb_version, S_IRUGO, show_version, NULL, PCB_VERSION); +static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); + +static struct attribute *as5915_16x_fpga_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_pcb_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + NULL +}; + +static const struct attribute_group as5915_16x_fpga_group = { + .attrs = as5915_16x_fpga_attributes, +}; + +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct i2c_mux_core *muxc = i2c_get_clientdata(client); + struct as5915_16x_fpga_data *data = i2c_mux_priv(muxc); + int status; + u32 addr, val; + + 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 = as5915_16x_fpga_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 as5915_16x_fpga_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, FPGA_CHANNEL_SELECT_REG, + I2C_SMBUS_BYTE_DATA, &data); + if (res != -EAGAIN) + break; + if (time_after(jiffies, + orig_jiffies + adap->timeout)) + break; + } + } + + return res; +} + +static int as5915_16x_fpga_mux_select_chan(struct i2c_mux_core *muxc, + u32 chan) +{ + struct as5915_16x_fpga_data *data = i2c_mux_priv(muxc); + struct i2c_client *client = data->client; + u8 regval; + int ret = 0; + + regval = (chan + 1) << 5; + /* Only select the channel if its different from the last channel */ + if (data->last_chan != regval) { + ret = as5915_16x_fpga_mux_reg_write(muxc->parent, client, regval); + data->last_chan = regval; + } + + return ret; +} + +static int as5915_16x_fpga_mux_deselect_mux(struct i2c_mux_core *muxc, + u32 chan) +{ + struct as5915_16x_fpga_data *data = i2c_mux_priv(muxc); + struct i2c_client *client = data->client; + + /* Deselect active channel */ + data->last_chan = chips[data->type].deselectChan; + + return as5915_16x_fpga_mux_reg_write(muxc->parent, client, data->last_chan); +} + +static void as5915_16x_fpga_add_client(struct i2c_client *client) +{ + struct fpga_client_node *node = kzalloc(sizeof(struct fpga_client_node), GFP_KERNEL); + + if (!node) { + dev_dbg(&client->dev, "Can't allocate fpga_client_node (0x%x)\n", client->addr); + return; + } + + node->client = client; + + mutex_lock(&list_lock); + list_add(&node->list, &fpga_client_list); + mutex_unlock(&list_lock); +} + +static void as5915_16x_fpga_remove_client(struct i2c_client *client) +{ + struct list_head *list_node = NULL; + struct fpga_client_node *fpga_node = NULL; + int found = 0; + + mutex_lock(&list_lock); + + list_for_each(list_node, &fpga_client_list) { + fpga_node = list_entry(list_node, struct fpga_client_node, list); + + if (fpga_node->client == client) { + found = 1; + break; + } + } + + if (found) { + list_del(list_node); + kfree(fpga_node); + } + + mutex_unlock(&list_lock); +} + +static ssize_t show_version(struct device *dev, struct device_attribute *da, char *buf) +{ + u8 reg = 0; + int val = 0; + struct i2c_client *client = to_i2c_client(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + + reg = (attr->index == FPGA_VERSION) ? 0x1 : 0x0; // 0 for PCB_VERSION + val = i2c_smbus_read_byte_data(client, reg); + + if (val < 0) { + dev_dbg(&client->dev, "fpga(0x%x) reg(0x%x) err %d\n", client->addr, reg, val); + } + + return sprintf(buf, "%d\n", val); +} + +/* + * I2C init/probing/exit functions + */ +static int as5915_16x_fpga_mux_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); + int num, force, class; + struct i2c_mux_core *muxc; + struct as5915_16x_fpga_data *data; + int ret = 0; + const struct attribute_group *group = &as5915_16x_fpga_group; + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) + return -ENODEV; + + muxc = i2c_mux_alloc(adap, &client->dev, + chips[id->driver_data].nchans, sizeof(*data), 0, + as5915_16x_fpga_mux_select_chan, as5915_16x_fpga_mux_deselect_mux); + if (!muxc) + return -ENOMEM; + + i2c_set_clientdata(client, muxc); + data = i2c_mux_priv(muxc); + data->client = client; + data->type = id->driver_data; + data->last_chan = chips[data->type].deselectChan; /* force the first selection */ + mutex_init(&data->update_lock); + + /* Now create an adapter for each channel */ + for (num = 0; num < chips[data->type].nchans; num++) { + force = 0; /* dynamic adap number */ + class = 0; /* no class by default */ + + ret = i2c_mux_add_adapter(muxc, force, num, class); + + if (ret) { + dev_err(&client->dev, + "failed to register multiplexed adapter" + " %d as bus %d\n", num, force); + goto add_mux_failed; + } + } + + /* Register sysfs hooks */ + if (group) { + ret = sysfs_create_group(&client->dev.kobj, group); + if (ret) { + goto add_mux_failed; + } + } + + if (chips[data->type].nchans) { + dev_info(&client->dev, + "registered %d multiplexed busses for I2C %s\n", + num, client->name); + } + else { + dev_info(&client->dev, + "device %s registered\n", client->name); + } + + as5915_16x_fpga_add_client(client); + + return 0; + +add_mux_failed: + i2c_mux_del_adapters(muxc); + return ret; +} + +static int as5915_16x_fpga_mux_remove(struct i2c_client *client) +{ + struct i2c_mux_core *muxc = i2c_get_clientdata(client); + const struct attribute_group *group = &as5915_16x_fpga_group; + + as5915_16x_fpga_remove_client(client); + + /* Remove sysfs hooks */ + if (group) { + sysfs_remove_group(&client->dev.kobj, group); + } + + i2c_mux_del_adapters(muxc); + + return 0; +} + +static int as5915_16x_fpga_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 as5915_16x_fpga_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 as5915_16x_fpga_read(unsigned short fpga_addr, u8 reg) +{ + struct list_head *list_node = NULL; + struct fpga_client_node *fpga_node = NULL; + int ret = -EPERM; + + mutex_lock(&list_lock); + + list_for_each(list_node, &fpga_client_list) { + fpga_node = list_entry(list_node, struct fpga_client_node, list); + + if (fpga_node->client->addr == fpga_addr) { + ret = as5915_16x_fpga_read_internal(fpga_node->client, reg); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as5915_16x_fpga_read); + +int as5915_16x_fpga_write(unsigned short fpga_addr, u8 reg, u8 value) +{ + struct list_head *list_node = NULL; + struct fpga_client_node *fpga_node = NULL; + int ret = -EIO; + + mutex_lock(&list_lock); + + list_for_each(list_node, &fpga_client_list) { + fpga_node = list_entry(list_node, struct fpga_client_node, list); + + if (fpga_node->client->addr == fpga_addr) { + ret = as5915_16x_fpga_write_internal(fpga_node->client, reg, value); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as5915_16x_fpga_write); + +static struct i2c_driver as5915_16x_fpga_mux_driver = { + .driver = { + .name = "as5915_16x_fpga", + .owner = THIS_MODULE, + }, + .probe = as5915_16x_fpga_mux_probe, + .remove = as5915_16x_fpga_mux_remove, + .id_table = as5915_16x_fpga_mux_id, +}; + +static int __init as5915_16x_fpga_mux_init(void) +{ + mutex_init(&list_lock); + return i2c_add_driver(&as5915_16x_fpga_mux_driver); +} + +static void __exit as5915_16x_fpga_mux_exit(void) +{ + i2c_del_driver(&as5915_16x_fpga_mux_driver); +} + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("Accton as5915-16x fpga driver"); +MODULE_LICENSE("GPL"); + +module_init(as5915_16x_fpga_mux_init); +module_exit(as5915_16x_fpga_mux_exit); diff --git a/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-leds.c b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-leds.c new file mode 100644 index 0000000000..77fe3b395c --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-leds.c @@ -0,0 +1,397 @@ +/* + * A LED driver for the as5915_16x_led + * + * Copyright (C) 2016 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 + +#define DRVNAME "as5915_16x_led" + +#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 + +extern int as5915_16x_fpga_read(unsigned short cpld_addr, u8 reg); +extern int as5915_16x_fpga_write(unsigned short cpld_addr, u8 reg, u8 value); +extern int as5915_16x_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as5915_16x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); + +struct as5915_16x_led_data { + struct platform_device *pdev; + struct mutex update_lock; + char valid; /* != 0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 reg_val[2]; /* Register value */ +}; + +static struct as5915_16x_led_data *ledctl = NULL; + +#define LED_CNTRLER_FPGA_I2C_ADDRESS (0x64) +#define LED_CNTRLER_CPLD_ADDRESS (0x63) + +#define LED_TYPE_ALARM_REG_MASK (0xC0) +#define LED_MODE_ALARM_GREEN_BLINK_VALUE (0x40) +#define LED_MODE_ALARM_RED_VALUE (0x80) +#define LED_MODE_ALARM_OFF_VALUE (0xC0) + +#define LED_TYPE_DIAG_REG_MASK (0x30) +#define LED_MODE_DIAG_GREEN_BLINK_VALUE (0x00) +#define LED_MODE_DIAG_GREEN_VALUE (0x10) +#define LED_MODE_DIAG_AMBER_VALUE (0x20) +#define LED_MODE_DIAG_OFF_VALUE (0x30) + +#define LED_TYPE_LOC_REG_MASK (0x40) +#define LED_MODE_LOC_OFF_VALUE (0x40) +#define LED_MODE_LOC_BLUE_BLINK_VALUE (0x00) + +static const u8 led_reg[] = { + 0x40, /* LOC LED */ + 0x41, /* ALARM / DIAG LED */ +}; + +enum led_type { + LED_TYPE_ALARM, + LED_TYPE_DIAG, + LED_TYPE_LOC, + LED_TYPE_PSU1, + LED_TYPE_PSU2 +}; + +/* LED mode */ +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; + enum led_light_mode mode; + int type_mask; + int mode_value; +}; + +static struct led_type_mode led_type_mode_data[] = { +{LED_TYPE_ALARM, LED_MODE_GREEN_BLINK, LED_TYPE_ALARM_REG_MASK, LED_MODE_ALARM_GREEN_BLINK_VALUE}, +{LED_TYPE_ALARM, LED_MODE_RED, LED_TYPE_ALARM_REG_MASK, LED_MODE_ALARM_RED_VALUE}, +{LED_TYPE_ALARM, LED_MODE_OFF, LED_TYPE_ALARM_REG_MASK, LED_MODE_ALARM_OFF_VALUE}, +{LED_TYPE_DIAG, LED_MODE_GREEN_BLINK, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_BLINK_VALUE}, +{LED_TYPE_DIAG, LED_MODE_GREEN, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_VALUE}, +{LED_TYPE_DIAG, LED_MODE_AMBER, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_AMBER_VALUE}, +{LED_TYPE_DIAG, LED_MODE_OFF, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_OFF_VALUE}, +{LED_TYPE_LOC, LED_MODE_BLUE_BLINK, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_BLUE_BLINK_VALUE}, +{LED_TYPE_LOC, LED_MODE_OFF, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_OFF_VALUE}, +}; + +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_value) { + 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++) { + int type_mask, mode_value; + + if (type != led_type_mode_data[i].type) + continue; + + if (mode != led_type_mode_data[i].mode) + continue; + + type_mask = led_type_mode_data[i].type_mask; + mode_value = led_type_mode_data[i].mode_value; + reg_val = (reg_val & ~type_mask) | mode_value; + } + + return reg_val; +} + +static int as5915_16x_led_read_value(u8 reg) +{ + return as5915_16x_fpga_read(LED_CNTRLER_FPGA_I2C_ADDRESS, reg); +} + +static int as5915_16x_led_write_value(u8 reg, u8 value) +{ + return as5915_16x_fpga_write(LED_CNTRLER_FPGA_I2C_ADDRESS, reg, value); +} + +static void as5915_16x_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 as5915_16x_led update\n"); + ledctl->valid = 0; + + /* Update LED data + */ + for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { + int status = as5915_16x_led_read_value(led_reg[i]); + + if (status < 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 as5915_16x_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 = as5915_16x_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); + as5915_16x_led_write_value(reg, reg_val); + ledctl->valid = 0; + +exit: + mutex_unlock(&ledctl->update_lock); +} + +static enum led_brightness as5915_16x_led_alarm_get(struct led_classdev *cdev) +{ + as5915_16x_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_ALARM, ledctl->reg_val[1]); +} + +static void as5915_16x_led_alarm_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + as5915_16x_led_set(led_cdev, led_light_mode, led_reg[1], LED_TYPE_ALARM); +} + +static void as5915_16x_led_diag_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + as5915_16x_led_set(led_cdev, led_light_mode, led_reg[1], LED_TYPE_DIAG); +} + +static enum led_brightness as5915_16x_led_diag_get(struct led_classdev *cdev) +{ + as5915_16x_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[1]); +} + +static enum led_brightness as5915_16x_led_loc_get(struct led_classdev *cdev) +{ + as5915_16x_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); +} + +static void as5915_16x_led_loc_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + as5915_16x_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_LOC); +} + +static void as5915_16x_led_auto_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ +} + +static enum led_brightness as5915_16x_led_auto_get(struct led_classdev *cdev) +{ + return LED_MODE_AUTO; +} + +static struct led_classdev as5915_16x_leds[] = { + [LED_TYPE_ALARM] = { + .name = "as5915_16x_led::alarm", + .default_trigger = "unused", + .brightness_set = as5915_16x_led_alarm_set, + .brightness_get = as5915_16x_led_alarm_get, + .max_brightness = LED_MODE_RED, + }, + [LED_TYPE_DIAG] = { + .name = "as5915_16x_led::diag", + .default_trigger = "unused", + .brightness_set = as5915_16x_led_diag_set, + .brightness_get = as5915_16x_led_diag_get, + .max_brightness = LED_MODE_AMBER, + }, + [LED_TYPE_LOC] = { + .name = "as5915_16x_led::loc", + .default_trigger = "unused", + .brightness_set = as5915_16x_led_loc_set, + .brightness_get = as5915_16x_led_loc_get, + .max_brightness = LED_MODE_BLUE_BLINK, + }, + [LED_TYPE_PSU1] = { + .name = "as5915_16x_led::psu1", + .default_trigger = "unused", + .brightness_set = as5915_16x_led_auto_set, + .brightness_get = as5915_16x_led_auto_get, + .max_brightness = LED_MODE_AUTO, + }, + [LED_TYPE_PSU2] = { + .name = "as5915_16x_led::psu2", + .default_trigger = "unused", + .brightness_set = as5915_16x_led_auto_set, + .brightness_get = as5915_16x_led_auto_get, + .max_brightness = LED_MODE_AUTO, + } +}; + +static int as5915_16x_led_probe(struct platform_device *pdev) +{ + int ret, i; + + for (i = 0; i < ARRAY_SIZE(as5915_16x_leds); i++) { + ret = led_classdev_register(&pdev->dev, &as5915_16x_leds[i]); + + if (ret < 0) { + break; + } + } + + /* Check if all LEDs were successfully registered */ + if (i != ARRAY_SIZE(as5915_16x_leds)){ + int j; + + /* only unregister the LEDs that were successfully registered */ + for (j = 0; j < i; j++) { + led_classdev_unregister(&as5915_16x_leds[i]); + } + } + + return ret; +} + +static int as5915_16x_led_remove(struct platform_device *pdev) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(as5915_16x_leds); i++) { + led_classdev_unregister(&as5915_16x_leds[i]); + } + + return 0; +} + +static struct platform_driver as5915_16x_led_driver = { + .probe = as5915_16x_led_probe, + .remove = as5915_16x_led_remove, + .driver = { + .name = DRVNAME, + .owner = THIS_MODULE, + }, +}; + +static int __init as5915_16x_led_init(void) +{ + int ret; + + ret = platform_driver_register(&as5915_16x_led_driver); + if (ret < 0) { + goto exit; + } + + ledctl = kzalloc(sizeof(struct as5915_16x_led_data), GFP_KERNEL); + if (!ledctl) { + ret = -ENOMEM; + goto exit_driver; + } + + 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); + goto exit_free; + } + + return 0; + +exit_free: + kfree(ledctl); +exit_driver: + platform_driver_unregister(&as5915_16x_led_driver); +exit: + return ret; +} + +static void __exit as5915_16x_led_exit(void) +{ + platform_device_unregister(ledctl->pdev); + platform_driver_unregister(&as5915_16x_led_driver); + kfree(ledctl); +} + +late_initcall(as5915_16x_led_init); +module_exit(as5915_16x_led_exit); + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("as5915_16x_led driver"); +MODULE_LICENSE("GPL"); diff --git a/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-psu.c b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-psu.c new file mode 100644 index 0000000000..bf2aad6f3d --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-psu.c @@ -0,0 +1,439 @@ +/* + * An hwmon driver for accton as5915_16x Power Module + * + * Copyright (C) 2019 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 + +#define DRV_NAME "as5915_16x_psu" +#define PSU_STATUS_FPGA_I2C_ADDR 0x64 +#define PSU_STATUS_I2C_REG_OFFSET 0x2 +#define USE_BYTE_ACCESS 0 /*Somehow i2c block access is failed on this platform.*/ +#define UPDATE_PERIOD (HZ*2) +#define MAX_OUTPUT_LENGTH 32 +#define I2C_BURST_LEN 32 + +#define IS_POWER_GOOD(id, value) (!!(value & BIT(id + 2))) +#define IS_PRESENT(id, value) (!(value & BIT(id + 6))) + +/* Addresses scanned + */ +static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; + +/* Each client has this additional data + */ +struct as5915_16x_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 FPGA */ + char eeprom[I2C_BURST_LEN*2]; /* EEPROM*/ +}; + + +enum as5915_16x_psu_sysfs_attributes { + PSU_INDEX, + PSU1_PRESENT, + PSU2_PRESENT, + PSU_MODEL_NAME, + PSU1_POWER_GOOD, + PSU2_POWER_GOOD, + PSU_SERIAL_NUMBER +}; + +enum psu_type { + PSU_BEL_SPAACTN_04, /* AC110V - N/A */ + PSU_TYPE_MAX +}; + +struct model_info { + enum psu_type type; + u8 offset; + char* model_name; + u8 serial_offset; + u8 serial_length; +}; + +struct model_info models[] = { + {PSU_BEL_SPAACTN_04, 0x0A, "SPAACTN-04",0x18, 8}, +}; + +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 ssize_t show_serial_number(struct device *dev, struct device_attribute *da,char *buf); +static int as5915_16x_psu_block_read(struct i2c_client *client, u8 command, u8 *data,int data_len); +static int as5915_16x_psu_model_name_get( + struct device *dev, char *buf); +static int as5915_16x_psu_serial_number_get( + struct device *dev, enum psu_type type, char *out); +static struct as5915_16x_psu_data *as5915_16x_psu_update_device(struct device *dev); +extern int as5915_16x_fpga_read(unsigned short cpld_addr, u8 reg); +extern int as5915_16x_fpga_write(unsigned short cpld_addr, u8 reg, u8 value); +extern int as5915_16x_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as5915_16x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); + +/* sysfs attributes for hwmon + */ +static SENSOR_DEVICE_ATTR(psu_index, S_IRUGO, show_index, NULL, PSU_INDEX); +static SENSOR_DEVICE_ATTR(psu1_present, S_IRUGO, show_status, NULL, PSU1_PRESENT); +static SENSOR_DEVICE_ATTR(psu2_present, S_IRUGO, show_status, NULL, PSU2_PRESENT); +static SENSOR_DEVICE_ATTR(psu_model_name, S_IRUGO, show_model_name,NULL, PSU_MODEL_NAME); +static SENSOR_DEVICE_ATTR(psu_serial, S_IRUGO, show_serial_number, NULL, PSU_SERIAL_NUMBER); +static SENSOR_DEVICE_ATTR(psu1_power_good, S_IRUGO, show_status, NULL, PSU1_POWER_GOOD); +static SENSOR_DEVICE_ATTR(psu2_power_good, S_IRUGO, show_status, NULL, PSU2_POWER_GOOD); + +static struct attribute *as5915_16x_psu_attributes[] = { + &sensor_dev_attr_psu_index.dev_attr.attr, + &sensor_dev_attr_psu1_present.dev_attr.attr, + &sensor_dev_attr_psu2_present.dev_attr.attr, + &sensor_dev_attr_psu_model_name.dev_attr.attr, + &sensor_dev_attr_psu_serial.dev_attr.attr, + &sensor_dev_attr_psu1_power_good.dev_attr.attr, + &sensor_dev_attr_psu2_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 as5915_16x_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 as5915_16x_psu_data *data = as5915_16x_psu_update_device(dev); + u8 status = 0; + + if (!data->valid) { + return sprintf(buf, "0\n"); + } + + if (attr->index == PSU1_PRESENT) { + status = IS_PRESENT(data->index, data->status); + } + else if (attr->index == PSU2_PRESENT) { + status = IS_PRESENT(data->index + 1, data->status); + } + else if (attr->index == PSU1_POWER_GOOD) { /* PSU_POWER_GOOD */ + status = IS_POWER_GOOD(data->index, data->status); + } + else { + status = IS_POWER_GOOD(data->index + 1, data->status); + } + + return sprintf(buf, "%d\n", status); +} + +static ssize_t show_serial_number(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i; + struct as5915_16x_psu_data *data = as5915_16x_psu_update_device(dev); + + if (!data->valid) { + return 0; + } + + if (!IS_PRESENT(data->index, data->status)) { + return 0; + } + + i = as5915_16x_psu_model_name_get(dev, buf); + if ( i < 0) { + return -ENXIO; + } + + if (as5915_16x_psu_serial_number_get(dev, i, buf) < 0) { + return -ENXIO; + } + return sprintf(buf, "%s\n", buf); +} + +static ssize_t show_model_name(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct as5915_16x_psu_data *data = as5915_16x_psu_update_device(dev); + + if (!data->valid) { + return 0; + } + + if (!IS_PRESENT(data->index, data->status)) { + return 0; + } + + if (as5915_16x_psu_model_name_get(dev, buf) < 0) { + return -ENXIO; + } + + return sprintf(buf, "%s\n", buf); +} + +static const struct attribute_group as5915_16x_psu_group = { + .attrs = as5915_16x_psu_attributes, +}; + +static int as5915_16x_psu_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct as5915_16x_psu_data *data; + int status; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { + status = -EIO; + goto exit; + } + + data = kzalloc(sizeof(struct as5915_16x_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, &as5915_16x_psu_group); + if (status) { + goto exit_free; + } + data->hwmon_dev = hwmon_device_register_with_info(&client->dev, + client->name, NULL, NULL, NULL); + 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, &as5915_16x_psu_group); +exit_free: + kfree(data); +exit: + + return status; +} + +static int as5915_16x_psu_remove(struct i2c_client *client) +{ + struct as5915_16x_psu_data *data = i2c_get_clientdata(client); + + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &as5915_16x_psu_group); + kfree(data); + + return 0; +} + +enum psu_index +{ + as5915_16x_psu +}; + +static const struct i2c_device_id as5915_16x_psu_id[] = { + { "as5915_16x_psu", as5915_16x_psu }, + {} +}; +MODULE_DEVICE_TABLE(i2c, as5915_16x_psu_id); + +static struct i2c_driver as5915_16x_psu_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = DRV_NAME, + }, + .probe = as5915_16x_psu_probe, + .remove = as5915_16x_psu_remove, + .id_table = as5915_16x_psu_id, + .address_list = normal_i2c, +}; + +static int as5915_16x_psu_block_read(struct i2c_client *client, + u8 command, u8 *data, int max_len) +{ + int result; + + u8 i, offset; + + if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { + for (i = 0; i < max_len; i += I2C_BURST_LEN) { + offset = i + command ; + result = i2c_smbus_read_i2c_block_data(client, offset, + I2C_BURST_LEN, data + i); + + if (result != I2C_BURST_LEN) { + result = -EIO; + goto abort; + } + } + + } else { + for (i = 0; i < max_len; i += 2) { + int word; + offset = i + command ; + word = i2c_smbus_read_word_data(client, offset); + if (word < 0) { + result = -EIO; + goto abort; + } + data[i] = word & 0xff; + data[i + 1] = word >> 8; + } + } + result = 0; +abort: + return result; +} + +static int as5915_16x_psu_serial_number_get( + struct device *dev, enum psu_type type, char *out) +{ + char *serial; + struct as5915_16x_psu_data *data = as5915_16x_psu_update_device(dev); + + if (type >= PSU_TYPE_MAX) { + return -EINVAL; + } + + if (!data->valid) { + out[0] = '\0'; + return 0; + } + + serial = data->eeprom + models[type].serial_offset; + strncpy(out, serial, models[type].serial_length); + out[models[type].serial_length] = '\0'; + return 0; +} + +static int find_model_name_from_eeprom( char *eeprom) +{ + int i; + char *name; + + for (i = 0; i < ARRAY_SIZE(models); i++) { + name = eeprom + models[i].offset; + if (strncmp(name, models[i].model_name, + strlen(models[i].model_name)) == 0) { + break; + } + } + + return (i == ARRAY_SIZE(models))? -EINVAL: i; +} +static int as5915_16x_psu_model_name_get( + struct device *dev, char *buf) +{ + int i; + struct as5915_16x_psu_data *data = as5915_16x_psu_update_device(dev); + + if (!data->valid) { + return sprintf(buf, "0\n"); + } + + /* Determine if the model name is known, if not, read next index + */ + i = find_model_name_from_eeprom(data->eeprom); + if (i < 0) { + return -ENODATA; + } + + mutex_lock(&data->update_lock); + strncpy(buf, models[i].model_name, MAX_OUTPUT_LENGTH); + mutex_unlock(&data->update_lock); + return i; +} + +static struct as5915_16x_psu_data *as5915_16x_psu_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as5915_16x_psu_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + if (time_after(jiffies, data->last_updated + UPDATE_PERIOD) + || !data->valid) { + int status = -1; + + dev_dbg(&client->dev, "Starting as5915_16x update\n"); + data->valid = 0; + + /* Read psu status */ + status = as5915_16x_fpga_read(PSU_STATUS_FPGA_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET); + if (status < 0) { + dev_dbg(&client->dev, + "fpga reg (0x%x) err %d\n", PSU_STATUS_FPGA_I2C_ADDR, status); + goto exit; + } + else { + data->status = status; + } + + /*Read the eeprom of psu*/ + memset(data->eeprom, 0, sizeof(data->eeprom)); + status = as5915_16x_psu_block_read(client, 0, + data->eeprom, sizeof(data->eeprom)); + + if (status < 0) { + dev_dbg(&client->dev, "unable to read eeprom from (0x%x)\n", + client->addr); + goto exit; + } + data->last_updated = jiffies; + data->valid = 1; + } + +exit: + mutex_unlock(&data->update_lock); + return data; +} + +module_i2c_driver(as5915_16x_psu_driver); + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("accton as5915_16x_psu driver"); +MODULE_LICENSE("GPL"); + diff --git a/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-sys.c b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-sys.c new file mode 100644 index 0000000000..a5d27156a7 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/modules/builds/src/x86-64-accton-as5915-16x-sys.c @@ -0,0 +1,177 @@ +/* + * An hwmon driver for accton as5915_16x 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 EEPROM_SIZE 256 + +/* Addresses scanned + */ +static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; + +/* Each client has this additional data + */ +struct as5915_16x_sys_data { + struct mutex update_lock; + char valid; /* !=0 if registers are valid */ + u8 eeprom[EEPROM_SIZE]; +}; + +static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, + char *buf); + +enum as5915_16x_sys_sysfs_attributes { + SYS_EEPROM +}; + +/* sysfs attributes for hwmon + */ +static SENSOR_DEVICE_ATTR(eeprom, S_IRUGO, show_eeprom, NULL, SYS_EEPROM); + +static struct attribute *as5915_16x_sys_attributes[] = { + &sensor_dev_attr_eeprom.dev_attr.attr, + NULL +}; + +static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as5915_16x_sys_data *data = i2c_get_clientdata(client); + int status = 0; + + mutex_lock(&data->update_lock); + + if (!data->valid) { + int i = 0; + + status = i2c_smbus_write_byte_data(client, 0, 0); + if (unlikely(status < 0)) { + goto exit; + } + + for (i = 0; i < sizeof(data->eeprom); i++) { + status = i2c_smbus_read_byte(client); + if (unlikely(status < 0)) { + goto exit; + } + + data->eeprom[i] = status; + } + + data->valid = 1; + } + + memcpy(buf, data->eeprom, sizeof(data->eeprom)); + mutex_unlock(&data->update_lock); + return 256; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static const struct attribute_group as5915_16x_sys_group = { + .attrs = as5915_16x_sys_attributes, +}; + +static int as5915_16x_sys_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct as5915_16x_sys_data *data; + int status; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) { + status = -EIO; + goto exit; + } + + data = kzalloc(sizeof(struct as5915_16x_sys_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, &as5915_16x_sys_group); + if (status) { + goto exit_free; + } + + return 0; + +exit_free: + kfree(data); +exit: + return status; +} + +static int as5915_16x_sys_remove(struct i2c_client *client) +{ + struct as5915_16x_sys_data *data = i2c_get_clientdata(client); + + sysfs_remove_group(&client->dev.kobj, &as5915_16x_sys_group); + kfree(data); + + return 0; +} + +static const struct i2c_device_id as5915_16x_sys_id[] = { + { "as5915_16x_sys", 0 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, as5915_16x_sys_id); + +static struct i2c_driver as5915_16x_sys_driver = { + .class = 0, + .driver = { + .name = "as5915_16x_sys", + }, + .probe = as5915_16x_sys_probe, + .remove = as5915_16x_sys_remove, + .id_table = as5915_16x_sys_id, + .address_list = normal_i2c, +}; + +module_i2c_driver(as5915_16x_sys_driver); + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("as5915_16x_sys driver"); +MODULE_LICENSE("GPL"); diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/Makefile b/packages/platforms/accton/x86-64/as5915-16x/onlp/Makefile new file mode 100644 index 0000000000..26aa37e6b4 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/Makefile @@ -0,0 +1,2 @@ +include $(ONL)/make/pkg.mk + diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/PKG.yml b/packages/platforms/accton/x86-64/as5915-16x/onlp/PKG.yml new file mode 100644 index 0000000000..4ac81db25a --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=x86-64-accton-as5915-16x ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/Makefile b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/Makefile new file mode 100644 index 0000000000..e7437cb23a --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/Makefile @@ -0,0 +1,2 @@ +FILTER=src +include $(ONL)/make/subdirs.mk diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/lib/Makefile b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/lib/Makefile new file mode 100644 index 0000000000..d288656e9b --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/lib/Makefile @@ -0,0 +1,3 @@ +PLATFORM := x86-64-accton-as5915-16x +include $(ONL)/packages/base/any/onlp/builds/platform/libonlp-platform.mk + diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/onlpdump/Makefile b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/onlpdump/Makefile new file mode 100644 index 0000000000..e43b2bd3f6 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/onlpdump/Makefile @@ -0,0 +1,3 @@ +PLATFORM := x86-64-accton-as5915-16x +include $(ONL)/packages/base/any/onlp/builds/platform/onlps.mk + diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/.module b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/.module new file mode 100644 index 0000000000..f51fce6c25 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/.module @@ -0,0 +1 @@ +name: x86_64_accton_as5915_16x diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/Makefile b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/Makefile new file mode 100644 index 0000000000..4d77bee80c --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### +include $(ONL)/make/config.mk +MODULE := x86_64_accton_as5915_16x +AUTOMODULE := x86_64_accton_as5915_16x +include $(BUILDER)/definemodule.mk diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/auto/make.mk b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/auto/make.mk new file mode 100644 index 0000000000..2f0e6f3655 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/auto/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# x86_64_accton_as5915_16x Autogeneration +# +############################################################################### +x86_64_accton_as5915_16x_AUTO_DEFS := module/auto/x86_64_accton_as5915_16x.yml +x86_64_accton_as5915_16x_AUTO_DIRS := module/inc/x86_64_accton_as5915_16x module/src +include $(BUILDER)/auto.mk + diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/auto/x86_64_accton_as5915_16x.yml b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/auto/x86_64_accton_as5915_16x.yml new file mode 100644 index 0000000000..83deb6a2d5 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/auto/x86_64_accton_as5915_16x.yml @@ -0,0 +1,50 @@ +############################################################################### +# +# x86_64_accton_as5915_16x Autogeneration Definitions +# +############################################################################### + +cdefs: &cdefs +- X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_LOGGING: + doc: "Include or exclude logging." + default: 1 +- X86_64_ACCTON_AS5915_16X_CONFIG_LOG_OPTIONS_DEFAULT: + doc: "Default enabled log options." + default: AIM_LOG_OPTIONS_DEFAULT +- X86_64_ACCTON_AS5915_16X_CONFIG_LOG_BITS_DEFAULT: + doc: "Default enabled log bits." + default: AIM_LOG_BITS_DEFAULT +- X86_64_ACCTON_AS5915_16X_CONFIG_LOG_CUSTOM_BITS_DEFAULT: + doc: "Default enabled custom log bits." + default: 0 +- X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB: + doc: "Default all porting macros to use the C standard libraries." + default: 1 +- X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: + doc: "Include standard library headers for stdlib porting macros." + default: x86_64_accton_as5915_16x_CONFIG_PORTING_STDLIB +- X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_UCLI: + doc: "Include generic uCli support." + default: 0 +- X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION: + doc: "Assume chassis fan direction is the same as the PSU fan direction." + default: 0 + + +definitions: + cdefs: + x86_64_accton_as5915_16x_CONFIG_HEADER: + defs: *cdefs + basename: x86_64_accton_as5915_16x_config + + portingmacro: + x86_64_accton_as5915_16x: + macros: + - malloc + - free + - memset + - memcpy + - strncpy + - vsnprintf + - snprintf + - strlen diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x.x b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x.x new file mode 100644 index 0000000000..e674af5d22 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x.x @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.xmacro(ALL).define> */ +/* */ + +/* <--auto.start.xenum(ALL).define> */ +/* */ diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x_config.h b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x_config.h new file mode 100644 index 0000000000..1f051fc7d3 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x_config.h @@ -0,0 +1,137 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as5915_16x Configuration Header + * + * @addtogroup x86_64_accton_as5915_16x-config + * @{ + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5915_16x_CONFIG_H__ +#define __x86_64_accton_as5915_16x_CONFIG_H__ + +#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG +#include +#endif +#ifdef x86_64_accton_as5915_16x_INCLUDE_CUSTOM_CONFIG +#include +#endif + +/* */ +#include +/** + * X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_LOGGING + * + * Include or exclude logging. */ + + +#ifndef X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_LOGGING +#define X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_LOGGING 1 +#endif + +/** + * X86_64_ACCTON_AS5915_16X_CONFIG_LOG_OPTIONS_DEFAULT + * + * Default enabled log options. */ + + +#ifndef X86_64_ACCTON_AS5915_16X_CONFIG_LOG_OPTIONS_DEFAULT +#define X86_64_ACCTON_AS5915_16X_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#endif + +/** + * X86_64_ACCTON_AS5915_16X_CONFIG_LOG_BITS_DEFAULT + * + * Default enabled log bits. */ + + +#ifndef X86_64_ACCTON_AS5915_16X_CONFIG_LOG_BITS_DEFAULT +#define X86_64_ACCTON_AS5915_16X_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#endif + +/** + * X86_64_ACCTON_AS5915_16X_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * + * Default enabled custom log bits. */ + + +#ifndef X86_64_ACCTON_AS5915_16X_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define X86_64_ACCTON_AS5915_16X_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#endif + +/** + * X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB + * + * Default all porting macros to use the C standard libraries. */ + + +#ifndef X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB +#define X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB 1 +#endif + +/** + * X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * + * Include standard library headers for stdlib porting macros. */ + + +#ifndef X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS x86_64_accton_as5915_16x_CONFIG_PORTING_STDLIB +#endif + +/** + * X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_UCLI + * + * Include generic uCli support. */ + + +#ifndef X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_UCLI +#define X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_UCLI 0 +#endif + +/** + * X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + * + * Assume chassis fan direction is the same as the PSU fan direction. */ + + +#ifndef X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION +#define X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION 0 +#endif + + + +/** + * All compile time options can be queried or displayed + */ + +/** Configuration settings structure. */ +typedef struct x86_64_accton_as5915_16x_config_settings_s { + /** name */ + const char* name; + /** value */ + const char* value; +} x86_64_accton_as5915_16x_config_settings_t; + +/** Configuration settings table. */ +/** x86_64_accton_as5915_16x_config_settings table. */ +extern x86_64_accton_as5915_16x_config_settings_t x86_64_accton_as5915_16x_config_settings[]; + +/** + * @brief Lookup a configuration setting. + * @param setting The name of the configuration option to lookup. + */ +const char* x86_64_accton_as5915_16x_config_lookup(const char* setting); + +/** + * @brief Show the compile-time configuration. + * @param pvs The output stream. + */ +int x86_64_accton_as5915_16x_config_show(struct aim_pvs_s* pvs); + +/* */ + +#include "x86_64_accton_as5915_16x_porting.h" + +#endif /* __x86_64_accton_as5915_16x_CONFIG_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x_dox.h b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x_dox.h new file mode 100644 index 0000000000..631e1eaf78 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x_dox.h @@ -0,0 +1,26 @@ +/**************************************************************************//** + * + * x86_64_accton_as5915_16x Doxygen Header + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5915_16x_DOX_H__ +#define __x86_64_accton_as5915_16x_DOX_H__ + +/** + * @defgroup x86_64_accton_as5915_16x x86_64_accton_as5915_16x - x86_64_accton_as5915_16x Description + * + +The documentation overview for this module should go here. + + * + * @{ + * + * @defgroup x86_64_accton_as5915_16x-x86_64_accton_as5915_16x Public Interface + * @defgroup x86_64_accton_as5915_16x-config Compile Time Configuration + * @defgroup x86_64_accton_as5915_16x-porting Porting Macros + * + * @} + * + */ + +#endif /* __x86_64_accton_as5915_16x_DOX_H__ */ diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x_porting.h b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x_porting.h new file mode 100644 index 0000000000..5b5970c09c --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/inc/x86_64_accton_as5915_16x/x86_64_accton_as5915_16x_porting.h @@ -0,0 +1,107 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as5915_16x Porting Macros. + * + * @addtogroup x86_64_accton_as5915_16x-porting + * @{ + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5915_16x_PORTING_H__ +#define __x86_64_accton_as5915_16x_PORTING_H__ + + +/* */ +#if X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#include +#include +#include +#include +#include +#endif + +#ifndef X86_64_ACCTON_AS5915_16X_MALLOC + #if defined(GLOBAL_MALLOC) + #define X86_64_ACCTON_AS5915_16X_MALLOC GLOBAL_MALLOC + #elif X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS5915_16X_MALLOC malloc + #else + #error The macro X86_64_ACCTON_AS5915_16X_MALLOC is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS5915_16X_FREE + #if defined(GLOBAL_FREE) + #define X86_64_ACCTON_AS5915_16X_FREE GLOBAL_FREE + #elif X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS5915_16X_FREE free + #else + #error The macro X86_64_ACCTON_AS5915_16X_FREE is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS5915_16X_MEMSET + #if defined(GLOBAL_MEMSET) + #define X86_64_ACCTON_AS5915_16X_MEMSET GLOBAL_MEMSET + #elif X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS5915_16X_MEMSET memset + #else + #error The macro X86_64_ACCTON_AS5915_16X_MEMSET is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS5915_16X_MEMCPY + #if defined(GLOBAL_MEMCPY) + #define X86_64_ACCTON_AS5915_16X_MEMCPY GLOBAL_MEMCPY + #elif X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS5915_16X_MEMCPY memcpy + #else + #error The macro X86_64_ACCTON_AS5915_16X_MEMCPY is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS5915_16X_STRNCPY + #if defined(GLOBAL_STRNCPY) + #define X86_64_ACCTON_AS5915_16X_STRNCPY GLOBAL_STRNCPY + #elif X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS5915_16X_STRNCPY strncpy + #else + #error The macro X86_64_ACCTON_AS5915_16X_STRNCPY is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS5915_16X_VSNPRINTF + #if defined(GLOBAL_VSNPRINTF) + #define X86_64_ACCTON_AS5915_16X_VSNPRINTF GLOBAL_VSNPRINTF + #elif X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS5915_16X_VSNPRINTF vsnprintf + #else + #error The macro X86_64_ACCTON_AS5915_16X_VSNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS5915_16X_SNPRINTF + #if defined(GLOBAL_SNPRINTF) + #define X86_64_ACCTON_AS5915_16X_SNPRINTF GLOBAL_SNPRINTF + #elif X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS5915_16X_SNPRINTF snprintf + #else + #error The macro X86_64_ACCTON_AS5915_16X_SNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS5915_16X_STRLEN + #if defined(GLOBAL_STRLEN) + #define X86_64_ACCTON_AS5915_16X_STRLEN GLOBAL_STRLEN + #elif X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS5915_16X_STRLEN strlen + #else + #error The macro X86_64_ACCTON_AS5915_16X_STRLEN is required but cannot be defined. + #endif +#endif + +/* */ + + +#endif /* __x86_64_accton_as5915_16x_PORTING_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/make.mk b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/make.mk new file mode 100644 index 0000000000..8f39144c09 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/make.mk @@ -0,0 +1,10 @@ +############################################################################### +# +# +# +############################################################################### +THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +x86_64_accton_as5915_16x_INCLUDES := -I $(THIS_DIR)inc +x86_64_accton_as5915_16x_INTERNAL_INCLUDES := -I $(THIS_DIR)src +x86_64_accton_as5915_16x_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5915_16x ucli:x86_64_accton_as5915_16x + diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/Makefile b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/Makefile new file mode 100644 index 0000000000..59f2888a25 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# Local source generation targets. +# +############################################################################### + +ucli: + @../../../../tools/uclihandlers.py x86_64_accton_as5915_16x_ucli.c + diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/debug.c b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/debug.c new file mode 100644 index 0000000000..855152ab34 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/debug.c @@ -0,0 +1,68 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include "x86_64_accton_as5915_16x_int.h" + +#if x86_64_accton_as5915_16x_CONFIG_INCLUDE_DEBUG == 1 + +#include + +static char help__[] = + "Usage: debug [options]\n" + " -c CPLD Versions\n" + " -h Help\n" + ; + +int +x86_64_accton_as5915_16x_debug_main(int argc, char* argv[]) +{ + int c = 0; + int help = 0; + int rv = 0; + + while( (c = getopt(argc, argv, "ch")) != -1) { + switch(c) + { + case 'c': c = 1; break; + case 'h': help = 1; rv = 0; break; + default: help = 1; rv = 1; break; + } + + } + + if(help || argc == 1) { + printf("%s", help__); + return rv; + } + + if(c) { + printf("Not implemented.\n"); + } + + + return 0; +} + +#endif diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/fani.c b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/fani.c new file mode 100644 index 0000000000..7bddcc6bc0 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/fani.c @@ -0,0 +1,48 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * Fan Platform Implementation Defaults. + * + ***********************************************************/ +#include +#include +#include "platform_lib.h" + + +/* There is no fan for this platform */ +int +onlp_fani_init(void) +{ + return ONLP_STATUS_OK; +} + +int +onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) +{ + return ONLP_STATUS_OK; +} + +int +onlp_fani_percentage_set(onlp_oid_t id, int p) +{ + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/ledi.c b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/ledi.c new file mode 100644 index 0000000000..27397b3b95 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/ledi.c @@ -0,0 +1,299 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2013 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include "platform_lib.h" + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_LED(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +#define LED_FORMAT "/sys/class/leds/as5915_16x_led::%s/brightness" + +/* LED related data + */ +enum led_light_mode { /*must be the same with the definition @ kernel driver */ + 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 +}; + +typedef struct led_light_mode_map { + enum onlp_led_id id; + enum led_light_mode driver_led_mode; + enum onlp_led_mode_e onlp_led_mode; +} led_light_mode_map_t; + +led_light_mode_map_t led_map[] = { +{LED_LOC, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_LOC, LED_MODE_BLUE_BLINK, ONLP_LED_MODE_BLUE_BLINKING}, +{LED_DIAG, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, +{LED_DIAG, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, +{LED_DIAG, LED_MODE_AMBER, ONLP_LED_MODE_ORANGE}, +{LED_DIAG, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_PSU1, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, +{LED_PSU2, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, +{LED_ALARM, LED_MODE_GREEN_BLINK,ONLP_LED_MODE_GREEN_BLINKING}, +{LED_ALARM, LED_MODE_RED, ONLP_LED_MODE_RED}, +{LED_ALARM, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +}; + +static char *leds[] = /* must map with onlp_led_id */ +{ + NULL, + "loc", + "diag", + "psu1", + "psu2", + "alarm", +}; + +/* + * Get the information for the given LED OID. + */ +static onlp_led_info_t linfo[] = +{ + { }, /* Not used */ + { + { ONLP_LED_ID_CREATE(LED_LOC), "Chassis LED 1 (LOC LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_BLUE_BLINKING, + }, + { + { ONLP_LED_ID_CREATE(LED_DIAG), "Chassis LED 2 (DIAG LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_ORANGE, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU1), "Chassis LED 3 (PSU1 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU2), "Chassis LED 4 (PSU2 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_ALARM), "Chassis LED 5 (ALARM LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_RED, + }, +}; + +static int driver_to_onlp_led_mode(enum onlp_led_id id, enum led_light_mode driver_led_mode) +{ + int i, nsize = sizeof(led_map)/sizeof(led_map[0]); + + for (i = 0; i < nsize; i++) + { + if (id == led_map[i].id && driver_led_mode == led_map[i].driver_led_mode) + { + return led_map[i].onlp_led_mode; + } + } + + return 0; +} + +static int onlp_to_driver_led_mode(enum onlp_led_id id, onlp_led_mode_t onlp_led_mode) +{ + int i, nsize = sizeof(led_map)/sizeof(led_map[0]); + + for(i = 0; i < nsize; i++) + { + if (id == led_map[i].id && onlp_led_mode == led_map[i].onlp_led_mode) + { + return led_map[i].driver_led_mode; + } + } + + return 0; +} + +/* + * This function will be called prior to any other onlp_ledi_* functions. + */ +int +onlp_ledi_init(void) +{ + return ONLP_STATUS_OK; +} + +/* + * Set the character + * Set c as 0 to 9 will set the character accordingly. + * Set c as 10 to 14 will turn off the 7-segment led + * Set c as 15 will turn on the dot led + * */ +int onlp_ledi_char_set(onlp_oid_t id, char c) +{ + int lid; + VALIDATE(id); + + lid = ONLP_OID_ID_GET(id); + + if (!(linfo[lid].caps & ONLP_LED_CAPS_CHAR)) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + switch (c) + { + case '0' ... '9': c -= 48; break; // convert character to number + case '.': c = 15; break; // convert dot '.' to integer + default: c = 10; break; // turn off + } + + if (onlp_file_write_int(c, LED_FORMAT, leds[lid]) != 0) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +/** Get the current character */ +int onlp_ledi_char_get(onlp_oid_t id, char* c) +{ + int lid, value; + VALIDATE(id); + + lid = ONLP_OID_ID_GET(id); + + if (!(linfo[lid].caps & ONLP_LED_CAPS_CHAR)) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + /* Get LED character */ + if (onlp_file_read_int(&value, LED_FORMAT, leds[lid]) < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + switch (value) + { + case 0 ... 9: *c = (value + 48); break; // convert to number character + case 15: *c = 46; break; // convert to dot '.' character + default: *c = 0; break; + } + + return ONLP_STATUS_OK; +} + +int +onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) +{ + int lid, value; + VALIDATE(id); + + lid = ONLP_OID_ID_GET(id); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[ONLP_OID_ID_GET(id)]; + + if (linfo[lid].caps & ONLP_LED_CAPS_CHAR) { + int ret = onlp_ledi_char_get(id, &info->character); + + if (ret != ONLP_STATUS_OK) { + return ret; + } + + if (info->character) { + info->mode = ONLP_LED_MODE_ON; + } + + return ret; + } + + /* Get LED mode */ + if (onlp_file_read_int(&value, LED_FORMAT, leds[lid]) < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + info->mode = driver_to_onlp_led_mode(lid, value); + + /* Set the on/off status */ + if (info->mode != ONLP_LED_MODE_OFF) { + info->status |= ONLP_LED_STATUS_ON; + } + + return ONLP_STATUS_OK; +} + +/* + * Turn an LED on or off. + * + * This function will only be called if the LED OID supports the ONOFF + * capability. + * + * What 'on' means in terms of colors or modes for multimode LEDs is + * up to the platform to decide. This is intended as baseline toggle mechanism. + */ +int +onlp_ledi_set(onlp_oid_t id, int on_or_off) +{ + VALIDATE(id); + + if (!on_or_off) { + return onlp_ledi_mode_set(id, ONLP_LED_MODE_OFF); + } + + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * This function puts the LED into the given mode. It is a more functional + * interface for multimode LEDs. + * + * Only modes reported in the LED's capabilities will be attempted. + */ +int +onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) +{ + int lid; + VALIDATE(id); + + lid = ONLP_OID_ID_GET(id); + + if (linfo[lid].caps & ONLP_LED_CAPS_CHAR) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + if (onlp_file_write_int(onlp_to_driver_led_mode(lid , mode), LED_FORMAT, leds[lid]) != 0) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/make.mk b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/make.mk new file mode 100644 index 0000000000..740a7e3e5c --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### + +LIBRARY := x86_64_accton_as5915_16x +$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(BUILDER)/lib.mk diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/platform_lib.h b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/platform_lib.h new file mode 100644 index 0000000000..1849736b06 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/platform_lib.h @@ -0,0 +1,81 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#ifndef __PLATFORM_LIB_H__ +#define __PLATFORM_LIB_H__ + +#include "x86_64_accton_as5915_16x_log.h" + +#define CHASSIS_FAN_COUNT 4 +#define CHASSIS_THERMAL_COUNT 5 +#define CHASSIS_PSU_COUNT 2 +#define CHASSIS_LED_COUNT 5 + +#define PSU1_ID 1 +#define PSU2_ID 2 + +#define PSU_AC_EEPROM_PREFIX "/sys/bus/i2c/devices/36-0050/" +#define PSU1_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/36-005a/" +#define PSU2_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/36-005b/" +#define PSU_AC_EEPROM_NODE(node) PSU_AC_EEPROM_PREFIX#node +#define PSU1_AC_PMBUS_NODE(node) PSU1_AC_PMBUS_PREFIX#node +#define PSU2_AC_PMBUS_NODE(node) PSU2_AC_PMBUS_PREFIX#node + +#define IDPROM_PATH "/sys/class/i2c-adapter/i2c-1/1-0056/eeprom" +#define BIOS_VER_PATH "/sys/devices/virtual/dmi/id/bios_version" + +enum onlp_thermal_id +{ + THERMAL_RESERVED = 0, + THERMAL_CPU_CORE, + THERMAL_1_ON_MAIN_BROAD, + THERMAL_2_ON_MAIN_BROAD, + THERMAL_3_ON_MAIN_BROAD, + THERMAL_4_ON_MAIN_BROAD, + THERMAL_1_ON_PSU1, + THERMAL_1_ON_PSU2, +}; + +enum onlp_led_id +{ + LED_LOC = 1, + LED_DIAG, + LED_PSU1, + LED_PSU2, + LED_ALARM +}; + +#define AIM_FREE_IF_PTR(p) \ + do \ + { \ + if (p) { \ + aim_free(p); \ + p = NULL; \ + } \ + } while (0) + +#endif /* __PLATFORM_LIB_H__ */ + + diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/psui.c b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/psui.c new file mode 100644 index 0000000000..6edbe9e90d --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/psui.c @@ -0,0 +1,217 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include "platform_lib.h" + +#define PSU_STATUS_POWER_GOOD 1 + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_PSU(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +static int +psu_pmbus_info_get(int id, char *node, int *value) +{ + int ret = 0; + *value = 0; + + if (PSU1_ID == id) { + ret = onlp_file_read_int(value, "%s%s", PSU1_AC_PMBUS_PREFIX, node); + } + else { + ret = onlp_file_read_int(value, "%s%s", PSU2_AC_PMBUS_PREFIX, node); + } + + if (ret < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + return ret; +} + +int get_psu_model(int id, char *model, int model_len) +{ + int len = 0; + char *path = NULL; + char *string = NULL; + + /* Read model name */ + path = (id == PSU1_ID) ? PSU1_AC_PMBUS_NODE(psu_mfr_model) : PSU2_AC_PMBUS_NODE(psu_mfr_model); + + len = onlp_file_read_str(&string, path); + if (!string || !len) { + return ONLP_STATUS_E_INTERNAL; + } + + if (len > model_len) { + aim_free(string); + return ONLP_STATUS_E_INVALID; + } + + strncpy(model, string, len); + aim_free(string); + return ONLP_STATUS_OK; +} + +int get_psu_serial(int id, char *serial, int serial_len) +{ + int len = 0; + char *path = NULL; + char *string = NULL; + + /* Read serial number */ + path = PSU_AC_EEPROM_NODE(psu_serial); + + len = onlp_file_read_str(&string, path); + if (!string || !len) { + return ONLP_STATUS_E_INTERNAL; + } + + if (len > serial_len) { + aim_free(string); + return ONLP_STATUS_E_INVALID; + } + + strncpy(serial, string, len); + aim_free(string); + return ONLP_STATUS_OK; +} + +int +onlp_psui_init(void) +{ + return ONLP_STATUS_OK; +} + +/* + * Get all information about the given PSU oid. + */ +static onlp_psu_info_t pinfo[] = +{ + { }, /* Not used */ + { + { ONLP_PSU_ID_CREATE(PSU1_ID), "PSU-1", 0 }, + }, + { + { ONLP_PSU_ID_CREATE(PSU2_ID), "PSU-2", 0 }, + } +}; + +static int +get_DCorAC_cap(char *model) +{ + const char *ac_models[] = {"SPAACTN-04", NULL }; + int i; + + i = 0; + while(ac_models[i]) { + if (!strncasecmp(model, ac_models[i], strlen(ac_models[i]))) { + return ONLP_PSU_CAPS_AC; + } + i++; + } + return ONLP_PSU_CAPS_DC12; +} + +int +onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) +{ + int val = 0; + int ret = ONLP_STATUS_OK; + int index = ONLP_OID_ID_GET(id); + VALIDATE(id); + + memset(info, 0, sizeof(onlp_psu_info_t)); + *info = pinfo[index]; /* Set the onlp_oid_hdr_t */ + info->status |= ONLP_PSU_STATUS_PRESENT; + + /* Get power good status + */ + if (psu_pmbus_info_get(index, "psu_power_good", &val) != 0) { + printf("Unable to read PSU(%d) node(psu_power_good)\r\n", index); + return ONLP_STATUS_E_INTERNAL; + } + + if (val != PSU_STATUS_POWER_GOOD) { + info->status |= ONLP_PSU_STATUS_FAILED; + return ONLP_STATUS_OK; + } + + /* Set capability + */ + get_psu_model(index, info->model, AIM_ARRAYSIZE(info->model)); + + info->caps |= get_DCorAC_cap(info->model); + + if(info->caps == ONLP_PSU_CAPS_AC) { + get_psu_serial(index, info->serial, AIM_ARRAYSIZE(info->serial)); + } + + if (info->status & ONLP_PSU_STATUS_FAILED) { + return ONLP_STATUS_OK; + } + + /* Set the associated oid_table */ + info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT); + + /* Read voltage, current and power */ + if (psu_pmbus_info_get(index, "psu_v_in", &val) == 0 && val) { + info->mvin = val; + info->caps |= ONLP_PSU_CAPS_VIN; + } + + if (psu_pmbus_info_get(index, "psu_v_out", &val) == 0) { + info->mvout = val; + info->caps |= ONLP_PSU_CAPS_VOUT; + } + + if (psu_pmbus_info_get(index, "psu_i_in", &val) == 0 && val) { + info->miin = val; + info->caps |= ONLP_PSU_CAPS_IIN; + } + + if (psu_pmbus_info_get(index, "psu_i_out", &val) == 0) { + info->miout = val; + info->caps |= ONLP_PSU_CAPS_IOUT; + } + + if (psu_pmbus_info_get(index, "psu_p_in", &val) == 0 && val) { + info->mpin = val; + info->caps |= ONLP_PSU_CAPS_PIN; + } + + if (psu_pmbus_info_get(index, "psu_p_out", &val) == 0) { + info->mpout = val; + info->caps |= ONLP_PSU_CAPS_POUT; + } + + get_psu_model(index, info->model, AIM_ARRAYSIZE(info->model)); + return ret; +} diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/sfpi.c b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/sfpi.c new file mode 100644 index 0000000000..e3da1d9dfe --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/sfpi.c @@ -0,0 +1,352 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2013 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include "x86_64_accton_as5915_16x_int.h" +#include "x86_64_accton_as5915_16x_log.h" + +#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" +#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/32-0063/module_present_%d" +#define MODULE_RXLOS_FORMAT "/sys/bus/i2c/devices/32-0063/module_rx_los_%d" +#define MODULE_TXFAULT_FORMAT "/sys/bus/i2c/devices/32-0063/module_tx_fault_%d" +#define MODULE_TXDISABLE_FORMAT "/sys/bus/i2c/devices/32-0063/module_tx_disable_%d" +#define MODULE_PRESENT_ALL_ATTR "/sys/bus/i2c/devices/32-0063/module_present_all" +#define MODULE_RXLOS_ALL_ATTR_CPLD "/sys/bus/i2c/devices/32-0063/module_rx_los_all" + +#define NUM_OF_SFP_PORT 12 +static const int port_bus_index[NUM_OF_SFP_PORT] = { +12, 13, 14, 15, 18, 19, 20, 21, 22, 23, 24, 25 +}; + +#define PORT_BUS_INDEX(port) (port_bus_index[port]) + +/************************************************************ + * + * SFPI Entry Points + * + ***********************************************************/ +int +onlp_sfpi_init(void) +{ + /* Called at initialization time */ + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) +{ + int p; + + for(p = 0; p < NUM_OF_SFP_PORT; p++) { + AIM_BITMAP_SET(bmap, p); + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_is_present(int port) +{ + /* + * Return 1 if present. + * Return 0 if not present. + * Return < 0 if error. + */ + int present; + + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + return present; +} + +int +onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + uint32_t bytes[2]; + FILE* fp; + + /* Read present status of port 0 ~ 13 */ + int count = 0; + + fp = fopen(MODULE_PRESENT_ALL_ATTR, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD."); + return ONLP_STATUS_E_INTERNAL; + } + + count = fscanf(fp, "%x %x", bytes, bytes+1); + fclose(fp); + + if(count != 2) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD."); + return ONLP_STATUS_E_INTERNAL; + } + + /* Mask out non-existant QSFP ports */ + bytes[1] &= 0x3F; + + + /* Convert to 64 bit integer in port order */ + int i = 0; + uint64_t presence_all = 0 ; + for(i = 1; i >= 0; i--) { + presence_all <<= 8; + presence_all |= bytes[i]; + } + /* ignor bit 0, 1 since port 0 is mapped to bit 2 of low byte register value */ + presence_all = presence_all >> 2; + /* Populate bitmap */ + for(i = 0; presence_all; i++) { + AIM_BITMAP_MOD(dst, i, (presence_all & 1)); + presence_all >>= 1; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + uint32_t bytes[2]; + FILE* fp; + + /* Read rxlos status of port 0 ~ 13 */ + int count = 0; + + fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x63)"); + return ONLP_STATUS_E_INTERNAL; + } + + count = fscanf(fp, "%x %x", bytes, bytes+1); + fclose(fp); + if(count != 2) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x62)"); + return ONLP_STATUS_E_INTERNAL; + } + + /* Mask out non-existant QSFP ports */ + bytes[1] &= 0x3F; + + /* Convert to 32 bit integer in port order */ + AIM_BITMAP_CLR_ALL(dst); + int i = 0; + uint64_t rx_los_all = 0 ; + for(i = 1; i >= 0; i--) { + rx_los_all <<= 8; + rx_los_all |= bytes[i]; + } + + /* ignor bit 0, 1 since port 0 is mapped to bit 2 of low byte register value */ + rx_los_all = rx_los_all >> 2; + /* Populate bitmap */ + for(i = 0; rx_los_all; i++) { + AIM_BITMAP_MOD(dst, i, (rx_los_all & 1)); + rx_los_all >>= 1; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_eeprom_read(int port, uint8_t data[256]) +{ + /* + * Read the SFP eeprom into data[] + * + * Return MISSING if SFP is missing. + * Return OK if eeprom is read + */ + int size = 0; + memset(data, 0, 256); + + if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + if (size != 256) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_dom_read(int port, uint8_t data[256]) +{ + FILE* fp; + char file[64] = {0}; + + sprintf(file, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)); + fp = fopen(file, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + if (fseek(fp, 256, SEEK_CUR) != 0) { + fclose(fp); + AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + int ret = fread(data, 1, 256, fp); + fclose(fp); + if (ret != 256) { + AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) +{ + int bus = PORT_BUS_INDEX(port); + return onlp_i2c_readb(bus, devaddr, addr, ONLP_I2C_F_FORCE); +} + +int +onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) +{ + int bus = PORT_BUS_INDEX(port); + return onlp_i2c_writeb(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); +} + +int +onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) +{ + int bus = PORT_BUS_INDEX(port); + return onlp_i2c_readw(bus, devaddr, addr, ONLP_I2C_F_FORCE); +} + +int +onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value) +{ + int bus = PORT_BUS_INDEX(port); + return onlp_i2c_writew(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); +} + +int +onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) +{ + int rv; + + switch(control) + { + case ONLP_SFP_CONTROL_TX_DISABLE: + { + if (port < 0 || port >= NUM_OF_SFP_PORT) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + default: + rv = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + return rv; +} + +int +onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) +{ + int rv; + + if (port < 0 || port >= NUM_OF_SFP_PORT) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + switch(control) + { + case ONLP_SFP_CONTROL_RX_LOS: + { + if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_TX_FAULT: + { + if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_TX_DISABLE: + { + if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + default: + rv = ONLP_STATUS_E_UNSUPPORTED; + } + + return rv; +} + +int +onlp_sfpi_denit(void) +{ + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/sysi.c b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/sysi.c new file mode 100644 index 0000000000..9f07fa1689 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/sysi.c @@ -0,0 +1,149 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include "platform_lib.h" + +#include "x86_64_accton_as5915_16x_int.h" +#include "x86_64_accton_as5915_16x_log.h" + +#define NUM_OF_CPLD_VER 4 + +static char* cpld_ver_path[] = +{ + "/sys/bus/i2c/devices/31-0064/pcb_version", /* Main FPGA */ + "/sys/bus/i2c/devices/31-0064/version", /* Main FPGA */ + "/sys/bus/i2c/devices/32-0063/version", /* Main CPLD */ + "/sys/bus/i2c/devices/32-0063/sub_version", /* Main CPLD */ +}; + +const char* +onlp_sysi_platform_get(void) +{ + return "x86-64-accton-as5915-16x-r0"; +} + +int +onlp_sysi_onie_data_get(uint8_t** data, int* size) +{ + uint8_t* rdata = aim_zmalloc(256); + if(onlp_file_read(rdata, 256, size, IDPROM_PATH) == ONLP_STATUS_OK) { + if(*size == 256) { + *data = rdata; + return ONLP_STATUS_OK; + } + } + + aim_free(rdata); + *size = 0; + return ONLP_STATUS_E_INTERNAL; +} + +int +onlp_sysi_oids_get(onlp_oid_t* table, int max) +{ + int i; + onlp_oid_t* e = table; + memset(table, 0, max*sizeof(onlp_oid_t)); + + /* 8 Thermal sensors on the chassis */ + for (i = 1; i <= CHASSIS_THERMAL_COUNT; i++) { + *e++ = ONLP_THERMAL_ID_CREATE(i); + } + + /* 5 LEDs on the chassis */ + for (i = 1; i <= CHASSIS_LED_COUNT; i++) { + *e++ = ONLP_LED_ID_CREATE(i); + } + + /* 2 PSUs on the chassis */ + for (i = 1; i <= CHASSIS_PSU_COUNT; i++) { + *e++ = ONLP_PSU_ID_CREATE(i); + } + + return 0; +} + +int +onlp_sysi_platform_info_get(onlp_platform_info_t* pi) +{ + int i, v[NUM_OF_CPLD_VER] = {0}; + onlp_onie_info_t onie; + char *bios_ver = NULL; + uint8_t* rdata = aim_zmalloc(256); + int size = 0; + + /* decode onie version */ + if(onlp_file_read(rdata, 256, &size, IDPROM_PATH) == ONLP_STATUS_OK) { + onlp_onie_decode(&onie, rdata, size); + } + /* get bios version */ + onlp_file_read_str(&bios_ver, BIOS_VER_PATH); + + for (i = 0; i < AIM_ARRAYSIZE(cpld_ver_path); i++) { + v[i] = 0; + + if(onlp_file_read_int(v+i, cpld_ver_path[i]) < 0) { + return ONLP_STATUS_E_INTERNAL; + } + } + + pi->cpld_versions = aim_fstrdup("\r\n\t Main CPLD(0x63): %02X.%02X" + "\r\n\t Main FPGA(0x64): %02X" + "\r\n\t PCB: %02X\r\n", + v[2], v[3], v[1], v[0]); + + pi->other_versions = aim_fstrdup("\r\n\t BIOS: %s\r\n\t ONIE: %s", + bios_ver, onie.onie_version); + + + AIM_FREE_IF_PTR(bios_ver); + AIM_FREE_IF_PTR(rdata); + onlp_onie_info_free(&onie); + + return ONLP_STATUS_OK; +} + +void +onlp_sysi_platform_info_free(onlp_platform_info_t* pi) +{ + aim_free(pi->cpld_versions); + aim_free(pi->other_versions); +} + +int onlp_sysi_platform_manage_leds(void) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +onlp_sysi_platform_manage_fans(void) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/thermali.c b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/thermali.c new file mode 100644 index 0000000000..2890b28115 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/thermali.c @@ -0,0 +1,125 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * Thermal Sensor Platform Implementation. + * + ***********************************************************/ +#include +#include +#include "platform_lib.h" + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_THERMAL(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +static char* devfiles__[] = /* must map with onlp_thermal_id */ +{ + NULL, + NULL, /* CPU_CORE files */ + "/sys/bus/i2c/devices/43-0049*temp1_input", + "/sys/bus/i2c/devices/44-004a*temp1_input", + "/sys/bus/i2c/devices/45-004b*temp1_input", + "/sys/bus/i2c/devices/45-004c*temp1_input", + "/sys/bus/i2c/devices/36-005a*psu_temp1_input", + "/sys/bus/i2c/devices/36-005b*psu_temp1_input", +}; + +static char* cpu_coretemp_files[] = + { + "/sys/devices/platform/coretemp.0*temp1_input", + "/sys/devices/platform/coretemp.0*temp8_input", + "/sys/devices/platform/coretemp.0*temp14_input", + NULL, + }; + +/* Static values */ +static onlp_thermal_info_t tinfo[] = { + { }, /* Not used */ + { { ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE), "CPU Core", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {80000, 100000, 110000} + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), "LM75-49", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {75000, 80000, 85000} + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), "LM75-4A", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {75000, 80000, 85000} + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), "LM75-4B", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {75000, 80000, 85000} + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BROAD), "LM75-4C", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {75000, 80000, 85000} + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU1), "PSU-1 Thermal Sensor 1", ONLP_PSU_ID_CREATE(PSU1_ID)}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {73000, 78000, 83000} + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU2), "PSU-2 Thermal Sensor 1", ONLP_PSU_ID_CREATE(PSU2_ID)}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {73000, 78000, 83000} + } +}; + +/* + * This will be called to intiialize the thermali subsystem. + */ +int +onlp_thermali_init(void) +{ + return ONLP_STATUS_OK; +} + +/* + * Retrieve the information structure for the given thermal OID. + * + * If the OID is invalid, return ONLP_E_STATUS_INVALID. + * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL. + * Otherwise, return ONLP_STATUS_OK with the OID's information. + * + * Note -- it is expected that you fill out the information + * structure even if the sensor described by the OID is not present. + */ +int +onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) +{ + int tid; + VALIDATE(id); + + tid = ONLP_OID_ID_GET(id); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = tinfo[tid]; + + if(tid == THERMAL_CPU_CORE) { + return onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files); + } + + return onlp_file_read_int(&info->mcelsius, devfiles__[tid]); +} diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_config.c b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_config.c new file mode 100644 index 0000000000..bcd2e137f4 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_config.c @@ -0,0 +1,81 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* */ +#define __x86_64_accton_as5915_16x_config_STRINGIFY_NAME(_x) #_x +#define __x86_64_accton_as5915_16x_config_STRINGIFY_VALUE(_x) __x86_64_accton_as5915_16x_config_STRINGIFY_NAME(_x) +x86_64_accton_as5915_16x_config_settings_t x86_64_accton_as5915_16x_config_settings[] = +{ +#ifdef X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_LOGGING + { __x86_64_accton_as5915_16x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_LOGGING), __x86_64_accton_as5915_16x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_LOGGING) }, +#else +{ X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_LOGGING(__x86_64_accton_as5915_16x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5915_16X_CONFIG_LOG_OPTIONS_DEFAULT + { __x86_64_accton_as5915_16x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5915_16X_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_accton_as5915_16x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5915_16X_CONFIG_LOG_OPTIONS_DEFAULT) }, +#else +{ X86_64_ACCTON_AS5915_16X_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_accton_as5915_16x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5915_16X_CONFIG_LOG_BITS_DEFAULT + { __x86_64_accton_as5915_16x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5915_16X_CONFIG_LOG_BITS_DEFAULT), __x86_64_accton_as5915_16x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5915_16X_CONFIG_LOG_BITS_DEFAULT) }, +#else +{ X86_64_ACCTON_AS5915_16X_CONFIG_LOG_BITS_DEFAULT(__x86_64_accton_as5915_16x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5915_16X_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __x86_64_accton_as5915_16x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5915_16X_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_accton_as5915_16x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5915_16X_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#else +{ X86_64_ACCTON_AS5915_16X_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_accton_as5915_16x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB + { __x86_64_accton_as5915_16x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB), __x86_64_accton_as5915_16x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB) }, +#else +{ X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_STDLIB(__x86_64_accton_as5915_16x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __x86_64_accton_as5915_16x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_accton_as5915_16x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#else +{ X86_64_ACCTON_AS5915_16X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_accton_as5915_16x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_UCLI + { __x86_64_accton_as5915_16x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_UCLI), __x86_64_accton_as5915_16x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_UCLI) }, +#else +{ X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_UCLI(__x86_64_accton_as5915_16x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + { __x86_64_accton_as5915_16x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_accton_as5915_16x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) }, +#else +{ X86_64_ACCTON_AS5915_16X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_accton_as5915_16x_config_STRINGIFY_NAME), "__undefined__" }, +#endif + { NULL, NULL } +}; +#undef __x86_64_accton_as5915_16x_config_STRINGIFY_VALUE +#undef __x86_64_accton_as5915_16x_config_STRINGIFY_NAME + +const char* +x86_64_accton_as5915_16x_config_lookup(const char* setting) +{ + int i; + for(i = 0; x86_64_accton_as5915_16x_config_settings[i].name; i++) { + if(!strcmp(x86_64_accton_as5915_16x_config_settings[i].name, setting)) { + return x86_64_accton_as5915_16x_config_settings[i].value; + } + } + return NULL; +} + +int +x86_64_accton_as5915_16x_config_show(struct aim_pvs_s* pvs) +{ + int i; + for(i = 0; x86_64_accton_as5915_16x_config_settings[i].name; i++) { + aim_printf(pvs, "%s = %s\n", x86_64_accton_as5915_16x_config_settings[i].name, x86_64_accton_as5915_16x_config_settings[i].value); + } + return i; +} + +/* */ + diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_enums.c b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_enums.c new file mode 100644 index 0000000000..bb684f0739 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_enums.c @@ -0,0 +1,10 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.enum(ALL).source> */ +/* */ + diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_int.h b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_int.h new file mode 100644 index 0000000000..b61af727b9 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_int.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * x86_64_accton_as5915_16x Internal Header + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5915_16x_INT_H__ +#define __x86_64_accton_as5915_16x_INT_H__ + +#include + + +#endif /* __x86_64_accton_as5915_16x_INT_H__ */ diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_log.c b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_log.c new file mode 100644 index 0000000000..b6eed41581 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_log.c @@ -0,0 +1,17 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as5915_16x_log.h" +/* + * x86_64_accton_as5915_16x log struct. + */ +AIM_LOG_STRUCT_DEFINE( + X86_64_ACCTON_AS5915_16X_CONFIG_LOG_OPTIONS_DEFAULT, + X86_64_ACCTON_AS5915_16X_CONFIG_LOG_BITS_DEFAULT, + NULL, /* Custom log map */ + X86_64_ACCTON_AS5915_16X_CONFIG_LOG_CUSTOM_BITS_DEFAULT + ); diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_log.h b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_log.h new file mode 100644 index 0000000000..4a6792e1db --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_log.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5915_16x_LOG_H__ +#define __x86_64_accton_as5915_16x_LOG_H__ + +#define AIM_LOG_MODULE_NAME x86_64_accton_as5915_16x +#include + +#endif /* __x86_64_accton_as5915_16x_LOG_H__ */ diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_module.c b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_module.c new file mode 100644 index 0000000000..1d5b0fb9f6 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_module.c @@ -0,0 +1,24 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as5915_16x_log.h" + +static int +datatypes_init__(void) +{ +#define x86_64_accton_as5915_16x_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL); +#include + return 0; +} + +void __x86_64_accton_as5915_16x_module_init__(void) +{ + AIM_LOG_STRUCT_REGISTER(); + datatypes_init__(); +} + +int __onlp_platform_version__ = 1; diff --git a/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_ucli.c b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_ucli.c new file mode 100644 index 0000000000..8e6224b497 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/onlp/builds/x86_64_accton_as5915_16x/module/src/x86_64_accton_as5915_16x_ucli.c @@ -0,0 +1,50 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#if x86_64_accton_as5915_16x_CONFIG_INCLUDE_UCLI == 1 + +#include +#include +#include + +static ucli_status_t +x86_64_accton_as5915_16x_ucli_ucli__config__(ucli_context_t* uc) +{ + UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_accton_as5915_16x) +} + +/* */ +/* */ + +static ucli_module_t +x86_64_accton_as5915_16x_ucli_module__ = + { + "x86_64_accton_as5915_16x_ucli", + NULL, + x86_64_accton_as5915_16x_ucli_ucli_handlers__, + NULL, + NULL, + }; + +ucli_node_t* +x86_64_accton_as5915_16x_ucli_node_create(void) +{ + ucli_node_t* n; + ucli_module_init(&x86_64_accton_as5915_16x_ucli_module__); + n = ucli_node_create("x86_64_accton_as5915_16x", NULL, &x86_64_accton_as5915_16x_ucli_module__); + ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_accton_as5915_16x")); + return n; +} + +#else +void* +x86_64_accton_as5915_16x_ucli_node_create(void) +{ + return NULL; +} +#endif + diff --git a/packages/platforms/accton/x86-64/as5915-16x/platform-config/Makefile b/packages/platforms/accton/x86-64/as5915-16x/platform-config/Makefile new file mode 100644 index 0000000000..26aa37e6b4 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/platform-config/Makefile @@ -0,0 +1,2 @@ +include $(ONL)/make/pkg.mk + diff --git a/packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/Makefile b/packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/Makefile new file mode 100644 index 0000000000..26aa37e6b4 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/Makefile @@ -0,0 +1,2 @@ +include $(ONL)/make/pkg.mk + diff --git a/packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/PKG.yml b/packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/PKG.yml new file mode 100644 index 0000000000..ea71a2cad4 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=accton BASENAME=x86-64-accton-as5915-16x REVISION=r0 diff --git a/packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/src/lib/x86-64-accton-as5915-16x-r0.yml b/packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/src/lib/x86-64-accton-as5915-16x-r0.yml new file mode 100644 index 0000000000..cb7f630c82 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/src/lib/x86-64-accton-as5915-16x-r0.yml @@ -0,0 +1,31 @@ +--- + +###################################################################### +# +# platform-config for AS5915 +# +###################################################################### + +x86-64-accton-as5915-16x-r0: + + grub: + + serial: >- + --port=0x3f8 + --speed=115200 + --word=8 + --parity=no + --stop=1 + + kernel: + <<: *kernel-5-4 + + args: >- + console=ttyS0,115200n8 + intel_iommu=off + + ##network + ## interfaces: + ## ma1: + ## name: ~ + ## syspath: pci0000:00/0000:00:14.0 diff --git a/packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/src/python/x86_64_accton_as5915_16x_r0/__init__.py b/packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/src/python/x86_64_accton_as5915_16x_r0/__init__.py new file mode 100644 index 0000000000..ae7b4fccb2 --- /dev/null +++ b/packages/platforms/accton/x86-64/as5915-16x/platform-config/r0/src/python/x86_64_accton_as5915_16x_r0/__init__.py @@ -0,0 +1,104 @@ +from onl.platform.base import * +from onl.platform.accton import * +from time import sleep + +class OnlPlatform_x86_64_accton_as5915_16x_r0(OnlPlatformAccton, + OnlPlatformPortConfig_6x10_8x1_4x1): + PLATFORM='x86-64-accton-as5915-16x-r0' + MODEL="AS5915-16X" + SYS_OBJECT_ID=".5915.16" + + def baseconfig(self): + os.system("modprobe i2c-ismt") + os.system("modprobe pmbus_core") + self.insmod('optoe') + self.insmod("ym2651y") + #os.system("insmod /lib/modules/`uname -r`/kernel/drivers/hwmon/pmbus/ucd9000.ko") + for m in [ 'fpga', 'cpld', 'sys', 'leds' , 'psu' ]: + self.insmod("x86-64-accton-as5915-16x-%s" % m) + + ########### initialize I2C bus 0 ########### + self.new_i2c_devices( + [ + # initialize multiplexer (PCA9548) + ('pca9548', 0x72, 0), # i2c 2-9 + ('pca9548', 0x70, 2), # i2c 10-17 + ('pca9548', 0x71, 3), # i2c 18-25 + ] + ) + + # initialize QSFP devices + for port in range(1, 5): + self.new_i2c_device('optoe2', 0x50, port+11) + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+9), shell=True) + + # initialize SFP devices + for port in range(5, 13): + self.new_i2c_device('optoe2', 0x50, port+13) + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+11), shell=True) + + ########### initialize I2C bus 1 ########### + self.new_i2c_devices( + [ + # initialize multiplexer (PCA9548) + ('pca9548', 0x76, 1), # i2c 26-33 + ('pca9548', 0x74, 27), # i2c 34-41 + + # initialize UCD90160 + ('ucd90160', 0x34, 35), + + # initialize CPLD + ('as5915_16x_fpga', 0x64, 31), # i2c 42-45 + ('as5915_16x_cpld', 0x63, 32), + + # initiate PSU eeprom + ('as5915_16x_psu', 0x50, 36), + + # initiate PSU-1 Power + ('ym2401', 0x5a, 36), + + # initiate PSU-2 Power + ('ym2401', 0x5b, 36), + + # initiate IDPROM + ('as5915_16x_sys', 0x56, 1), + ] + ) + + # sleep for a while to make sure the mux channels of fpga are created + sleep(0.1) + self.new_i2c_devices( + [ + # inititate LM75 + ('lm75', 0x49, 43), + ('lm75', 0x4a, 44), + ('lm75', 0x4b, 45), + ('lm75', 0x4c, 45), + ] + ) + + # Write sensors.conf for ucd90160 + lines = """ + bus "i2c-35" "i2c-27-mux (chan_id 1)" + chip "ucd90160-i2c-*-34" + label in1 "H_VCC12_MON" + label in2 "VCC12_MON" + label in3 "USB_VCC5P0_MON" + label in4 "VCC5P0_MON" + label in5 "VDD3P3_MON" + label in6 "VDD1P8_MON" + label in7 "VDD1P0_MON" + label in8 "SFP_3P3_MON" + label in9 "VDD1P0_ROV_MON" + label in10 "VPP_DDR2P5_MON" + label in11 "VDD1P2_DDR_MON" + label in12 "VDD0P6_MON" + label in13 "Vmonitor_3V3_MON" + label in14 "FPGA_2V5_MON" + label in15 "FPGA_1V2_MON" + label in16 "MANG_2P5_MON" + """ + with open("/etc/sensors.d/sensors.conf1","w+") as f: + f.write(lines) + + return True