From 46e3754fff4fdc5362810e261d9cf3466bf1120e Mon Sep 17 00:00:00 2001 From: willy_liu Date: Thu, 26 Sep 2024 11:01:21 +0800 Subject: [PATCH] CPU sub-system CPU: Intel C3558 2.2GHz 4 Core DDR4 SDRAM: 8GB 2133MHz with ECC (SO-DIMM) DDR4 *2 SPI Flash (Boot): 128Mb *2 M.2 SSD: SATA 32GB/64GB SSD (2280) CPLD: Altera MAX V 5M2210 TPM: ST33ZP24AR28PVSP, ST Management UART RS232 console port (RJ45), 88E1512, Marvell, Out-band Management Ethernet port (RJ45) MAC Broadcom Trident3 BCM56370 *1 560Gbs Enterprise switch with Multigigabit Ethernet Ports PHY BCM54998E*5 Octal-Port 2.5GBASE-T/1000BASET/100BASE-TX Transceiver BCM84894 *3 10GBASE-T/5GBASE-T/2.5GBASET/1000BASE-T/100BASE-TX Transceiver PoE STM32F100C8T6BTR*1, PoE MCU BCM59131 *12, PSE Controller SATA CONN M.2 connector Ethernet Ports 36 x 2.5G Base-T + 12 x 10G Base-T + 4 x 25G SFP28+ 2 x 100G QSFP28 Power Supply 1200W/920W PSU, 3Y, 1+1 redundant load-sharing, hot-swappable Cooling F2B fan-tray modules with 3 pcs of 40mmx40mmx56mm 12V fans, hot-swappable Signed-off-by: willy_liu --- .../accton/x86-64/as4630-54npe/.gitignore | 3 + .../accton/x86-64/as4630-54npe/Makefile | 1 + .../x86-64/as4630-54npe/modules/Makefile | 1 + .../x86-64/as4630-54npe/modules/PKG.yml | 1 + .../as4630-54npe/modules/builds/.gitignore | 1 + .../as4630-54npe/modules/builds/Makefile | 6 + .../builds/x86-64-accton-as4630-54npe-cpld.c | 863 ++++++++++++++++++ .../builds/x86-64-accton-as4630-54npe-leds.c | 553 +++++++++++ .../builds/x86-64-accton-as4630-54npe-psu.c | 345 +++++++ .../accton/x86-64/as4630-54npe/onlp/Makefile | 1 + .../accton/x86-64/as4630-54npe/onlp/PKG.yml | 1 + .../x86-64/as4630-54npe/onlp/builds/Makefile | 2 + .../as4630-54npe/onlp/builds/lib/Makefile | 2 + .../onlp/builds/onlpdump/Makefile | 2 + .../x86_64_accton_as4630_54npe/.gitignore | 0 .../builds/x86_64_accton_as4630_54npe/.module | 1 + .../x86_64_accton_as4630_54npe/Makefile | 9 + .../builds/x86_64_accton_as4630_54npe/README | 6 + .../module/auto/make.mk | 8 + .../auto/x86_64_accton_as4630_54npe.yml | 50 + .../x86_64_accton_as4630_54npe.x | 14 + .../x86_64_accton_as4630_54npe_config.h | 137 +++ .../x86_64_accton_as4630_54npe_dox.h | 26 + .../x86_64_accton_as4630_54npe_porting.h | 97 ++ .../x86_64_accton_as4630_54npe/module/make.mk | 10 + .../module/src/Makefile | 9 + .../module/src/fani.c | 326 +++++++ .../module/src/ledi.c | 292 ++++++ .../module/src/make.mk | 9 + .../module/src/platform_lib.c | 224 +++++ .../module/src/platform_lib.h | 92 ++ .../module/src/psui.c | 245 +++++ .../module/src/sfpi.c | 375 ++++++++ .../module/src/sysi.c | 270 ++++++ .../module/src/thermali.c | 162 ++++ .../src/x86_64_accton_as4630_54npe_config.c | 80 ++ .../src/x86_64_accton_as4630_54npe_enums.c | 10 + .../src/x86_64_accton_as4630_54npe_int.h | 12 + .../src/x86_64_accton_as4630_54npe_log.c | 18 + .../src/x86_64_accton_as4630_54npe_log.h | 12 + .../src/x86_64_accton_as4630_54npe_module.c | 24 + .../src/x86_64_accton_as4630_54npe_ucli.c | 50 + .../as4630-54npe/platform-config/Makefile | 1 + .../as4630-54npe/platform-config/r0/Makefile | 1 + .../as4630-54npe/platform-config/r0/PKG.yml | 1 + .../src/lib/x86-64-accton-as4630-54npe-r0.yml | 31 + .../x86_64_accton_as4630_54npe_r0/__init__.py | 56 ++ 47 files changed, 4440 insertions(+) create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/.gitignore create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/Makefile create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/modules/Makefile create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/modules/PKG.yml create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/modules/builds/.gitignore create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/modules/builds/Makefile create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/modules/builds/x86-64-accton-as4630-54npe-cpld.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/modules/builds/x86-64-accton-as4630-54npe-leds.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/modules/builds/x86-64-accton-as4630-54npe-psu.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/Makefile create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/PKG.yml create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/Makefile create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/lib/Makefile create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/onlpdump/Makefile create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/.gitignore create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/.module create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/Makefile create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/README create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/auto/make.mk create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/auto/x86_64_accton_as4630_54npe.yml create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe.x create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe_config.h create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe_dox.h create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe_porting.h create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/make.mk create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/Makefile create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/fani.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/ledi.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/make.mk create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/platform_lib.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/platform_lib.h create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/psui.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/sfpi.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/sysi.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/thermali.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_config.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_enums.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_int.h create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_log.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_log.h create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_module.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_ucli.c create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/platform-config/Makefile create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/Makefile create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/PKG.yml create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/src/lib/x86-64-accton-as4630-54npe-r0.yml create mode 100644 packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/src/python/x86_64_accton_as4630_54npe_r0/__init__.py diff --git a/packages/platforms/accton/x86-64/as4630-54npe/.gitignore b/packages/platforms/accton/x86-64/as4630-54npe/.gitignore new file mode 100644 index 0000000000..ac04bc5a6f --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/.gitignore @@ -0,0 +1,3 @@ +*x86*64*accton*as4630*54npe*.mk +onlpdump.mk + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/Makefile b/packages/platforms/accton/x86-64/as4630-54npe/Makefile new file mode 100644 index 0000000000..003238cf6d --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/as4630-54npe/modules/Makefile b/packages/platforms/accton/x86-64/as4630-54npe/modules/Makefile new file mode 100644 index 0000000000..003238cf6d --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/modules/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/as4630-54npe/modules/PKG.yml b/packages/platforms/accton/x86-64/as4630-54npe/modules/PKG.yml new file mode 100644 index 0000000000..061669cbb8 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/modules/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-modules.yml VENDOR=accton BASENAME=x86-64-accton-as4630-54npe ARCH=amd64 KERNELS="onl-kernel-4.14-lts-x86-64-all:amd64" diff --git a/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/.gitignore b/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/.gitignore new file mode 100644 index 0000000000..a65b41774a --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/.gitignore @@ -0,0 +1 @@ +lib diff --git a/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/Makefile b/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/Makefile new file mode 100644 index 0000000000..0de0b122bd --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/Makefile @@ -0,0 +1,6 @@ +KERNELS := onl-kernel-4.14-lts-x86-64-all:amd64 +KMODULES := $(wildcard *.c) +VENDOR := accton +BASENAME := x86-64-accton-as4630-54npe +ARCH := x86_64 +include $(ONL)/make/kmodule.mk diff --git a/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/x86-64-accton-as4630-54npe-cpld.c b/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/x86-64-accton-as4630-54npe-cpld.c new file mode 100644 index 0000000000..3ebfa34f12 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/x86-64-accton-as4630-54npe-cpld.c @@ -0,0 +1,863 @@ +/* + * Copyright (C) Jostar yang + * + * This module supports the accton cpld that hold the channel select + * mechanism for other i2c slave devices, such as SFP. + * This includes the: + * Accton as4630_54npe CPLD + * + * 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 +#include + +#define I2C_RW_RETRY_COUNT 10 +#define I2C_RW_RETRY_INTERVAL 60 /* ms */ +#define FAN_DUTY_CYCLE_REG_MASK 0x1F +#define FAN_MAX_DUTY_CYCLE 100 +#define FAN_REG_VAL_TO_SPEED_RPM_STEP 114 // R.P.M value = read value x3.79*60/2 + +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 { + as4630_54npe_cpld, +}; +enum fan_id { + FAN1_ID, + FAN2_ID, + FAN3_ID, +}; + +static const u8 fan_reg[] = { + 0x87, /* fan status, fan direction */ + 0x1A, /* fan PWM(for fan1 ,fan2) */ + 0x1B, /* fan PWM(for fan1 ,fan2) */ + 0x88, /* front fan1 speed(rpm) */ + 0x89, /* front fan2 speed(rpm) */ + 0x8A, /* front fan3 speed(rpm) */ + 0x20, /*fan fault*/ +}; + +struct as4630_54npe_cpld_data { + enum cpld_type type; + struct device *hwmon_dev; + struct mutex update_lock; + char valid; /* != 0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 reg_fan_val[ARRAY_SIZE(fan_reg)]; /* Register value */ +}; + + + +static const struct i2c_device_id as4630_54npe_cpld_id[] = { + { "as4630_54npe_cpld", as4630_54npe_cpld}, + { } +}; +MODULE_DEVICE_TABLE(i2c, as4630_54npe_cpld_id); + +#define TRANSCEIVER_RESET_ATTR_ID(index) MODULE_RESET_##index +#define TRANSCEIVER_LPMODE_ATTR_ID(index) MODULE_LPMODE_##index +#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index +#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index +#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index +#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index +#define FAN_SPEED_RPM_ATTR_ID(index) FAN_SPEED_RPM_##index +#define FAN_DIRECTION_ID(index) FAN_DIRECTION_##index +#define FAN_PRESENT_ATTR_ID(index) FAN_PRESENT_##index +#define FAN_FAULT_ATTR_ID(index) FAN_FAULT_##index + +enum as4630_54npe_cpld_sysfs_attributes { + CPLD_VERSION, + ACCESS, + /* transceiver attributes */ + TRANSCEIVER_RXLOS_ATTR_ID(49), + TRANSCEIVER_RXLOS_ATTR_ID(50), + TRANSCEIVER_RXLOS_ATTR_ID(51), + TRANSCEIVER_RXLOS_ATTR_ID(52), + TRANSCEIVER_TXFAULT_ATTR_ID(49), + TRANSCEIVER_TXFAULT_ATTR_ID(50), + TRANSCEIVER_TXFAULT_ATTR_ID(51), + TRANSCEIVER_TXFAULT_ATTR_ID(52), + TRANSCEIVER_PRESENT_ATTR_ID(49), + TRANSCEIVER_PRESENT_ATTR_ID(50), + TRANSCEIVER_PRESENT_ATTR_ID(51), + TRANSCEIVER_PRESENT_ATTR_ID(52), + TRANSCEIVER_PRESENT_ATTR_ID(53), + TRANSCEIVER_PRESENT_ATTR_ID(54), + TRANSCEIVER_RESET_ATTR_ID(53), + TRANSCEIVER_RESET_ATTR_ID(54), + TRANSCEIVER_LPMODE_ATTR_ID(53), + TRANSCEIVER_LPMODE_ATTR_ID(54), + TRANSCEIVER_TXDISABLE_ATTR_ID(49), + TRANSCEIVER_TXDISABLE_ATTR_ID(50), + TRANSCEIVER_TXDISABLE_ATTR_ID(51), + TRANSCEIVER_TXDISABLE_ATTR_ID(52), + FAN_PRESENT_ATTR_ID(1), + FAN_PRESENT_ATTR_ID(2), + FAN_PRESENT_ATTR_ID(3), + FAN_SPEED_RPM_ATTR_ID(1), + FAN_SPEED_RPM_ATTR_ID(2), + FAN_SPEED_RPM_ATTR_ID(3), + FAN_DIRECTION_ID(1), + FAN_DIRECTION_ID(2), + FAN_DIRECTION_ID(3), + FAN_FAULT_ATTR_ID(1), + FAN_FAULT_ATTR_ID(2), + FAN_FAULT_ATTR_ID(3), + FAN_DUTY_CYCLE_PERCENTAGE, +}; + +/* sysfs attributes for hwmon + */ +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t set_qsfp(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 as4630_54npe_cpld_read_internal(struct i2c_client *client, u8 reg); +static int as4630_54npe_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); + +/*fan sysfs*/ +static struct as4630_54npe_cpld_data *as4630_54npe_fan_update_device(struct device *dev); +static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); + +/* 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_tx_disable, MODULE_TXDISABLE_##index); \ + static SENSOR_DEVICE_ATTR(module_rx_los_##index, S_IRUGO, show_status, NULL, MODULE_RXLOS_##index); \ + static SENSOR_DEVICE_ATTR(module_tx_fault_##index, S_IRUGO, show_status, NULL, MODULE_TXFAULT_##index); + +#define DECLARE_SFP_TRANSCEIVER_ATTR(index) \ + &sensor_dev_attr_module_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 + +#define DECLARE_QSFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_lpmode_##index, S_IRUGO | S_IWUSR, show_status, set_qsfp, MODULE_LPMODE_##index); \ + static SENSOR_DEVICE_ATTR(module_reset_##index, S_IRUGO | S_IWUSR, show_status, set_qsfp, MODULE_RESET_##index); \ + static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index); + +#define DECLARE_QSFP_TRANSCEIVER_ATTR(index) \ + &sensor_dev_attr_module_lpmode_##index.dev_attr.attr, \ + &sensor_dev_attr_module_reset_##index.dev_attr.attr, \ + &sensor_dev_attr_module_present_##index.dev_attr.attr + + +#define DECLARE_FAN_SENSOR_DEV_ATTR(index) \ + static SENSOR_DEVICE_ATTR(fan_present_##index, S_IRUGO, fan_show_value, NULL, FAN_PRESENT_##index); \ + static SENSOR_DEVICE_ATTR(fan_fault_##index, S_IRUGO, fan_show_value, NULL, FAN_FAULT_##index); \ + static SENSOR_DEVICE_ATTR(fan_speed_rpm_##index, S_IRUGO, fan_show_value, NULL, FAN_SPEED_RPM_##index); \ + static SENSOR_DEVICE_ATTR(fan_direction_##index, S_IRUGO, fan_show_value, NULL, FAN_DIRECTION_##index); + +#define DECLARE_FAN_ATTR(index) \ + &sensor_dev_attr_fan_present_##index.dev_attr.attr, \ + &sensor_dev_attr_fan_fault_##index.dev_attr.attr, \ + &sensor_dev_attr_fan_speed_rpm_##index.dev_attr.attr, \ + &sensor_dev_attr_fan_direction_##index.dev_attr.attr + +#define DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(index) \ + static SENSOR_DEVICE_ATTR(fan_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, FAN_DUTY_CYCLE_PERCENTAGE); +#define DECLARE_FAN_DUTY_CYCLE_ATTR(index) &sensor_dev_attr_fan_duty_cycle_percentage.dev_attr.attr + + +static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); +static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); + + + +/* transceiver attributes */ +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(49); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(50); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(51); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(52); +DECLARE_QSFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(53); +DECLARE_QSFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(54); +/* fan attributes */ +DECLARE_FAN_SENSOR_DEV_ATTR(1); +DECLARE_FAN_SENSOR_DEV_ATTR(2); +DECLARE_FAN_SENSOR_DEV_ATTR(3); +DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(1); + +static struct attribute *as4630_54npe_cpld_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + DECLARE_SFP_TRANSCEIVER_ATTR(49), + DECLARE_SFP_TRANSCEIVER_ATTR(50), + DECLARE_SFP_TRANSCEIVER_ATTR(51), + DECLARE_SFP_TRANSCEIVER_ATTR(52), + DECLARE_QSFP_TRANSCEIVER_ATTR(53), + DECLARE_QSFP_TRANSCEIVER_ATTR(54), + DECLARE_FAN_ATTR(1), + DECLARE_FAN_ATTR(2), + DECLARE_FAN_ATTR(3), + DECLARE_FAN_DUTY_CYCLE_ATTR(1), + NULL +}; + +static const struct attribute_group as4630_54npe_cpld_group = { + .attrs = as4630_54npe_cpld_attributes, +}; + + +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 as4630_54npe_cpld_data *data = i2c_get_clientdata(client); + int status = 0; + u8 reg = 0, mask = 0, revert = 0; + + switch (attr->index) + { + case MODULE_RXLOS_49 ... MODULE_RXLOS_50: + reg=0x5; + mask = 0x1<< (attr->index==MODULE_RXLOS_49?4:0); + break; + case MODULE_TXFAULT_49 ... MODULE_TXFAULT_50: + reg=0x5; + mask=0x1 << (attr->index==MODULE_TXFAULT_49?5:1); + break; + case MODULE_PRESENT_49 ... MODULE_PRESENT_50: + reg=0x5; + mask=0x1 << (attr->index==MODULE_PRESENT_49?6:2); + break; + case MODULE_TXDISABLE_49 ... MODULE_TXDISABLE_50: + reg=0x5; + mask=0x1 << (attr->index==MODULE_TXDISABLE_49?7:3); + break; + + case MODULE_RXLOS_51 ... MODULE_RXLOS_52: + reg=0x6; + mask = 0x1<< (attr->index==MODULE_RXLOS_51?4:0); + break; + case MODULE_TXFAULT_51 ... MODULE_TXFAULT_52: + reg=0x6; + mask=0x1 << (attr->index==MODULE_TXFAULT_51?5:1); + break; + case MODULE_PRESENT_51 ... MODULE_PRESENT_52: + reg=0x6; + mask=0x1 << (attr->index==MODULE_PRESENT_51?6:2); + break; + case MODULE_TXDISABLE_51 ... MODULE_TXDISABLE_52: + reg=0x6; + mask=0x1 << (attr->index==MODULE_TXDISABLE_51?7:3); + break; + case MODULE_PRESENT_53 ... MODULE_PRESENT_54: + reg=0x21; + mask=0x1 << (attr->index==MODULE_PRESENT_53?0:4); + break; + case MODULE_RESET_53 ... MODULE_RESET_54: + reg=0x21; + mask=0x1 << (attr->index==MODULE_RESET_53?3:7); + revert = 1; + break; + case MODULE_LPMODE_53 ... MODULE_LPMODE_54: + reg = 0x21; + mask = 0x1 << (attr->index==MODULE_LPMODE_53?2:6); + revert = 0; + break; + default: + return 0; + } + + if( attr->index >= MODULE_PRESENT_49 && attr->index <= MODULE_PRESENT_54 ) + { + revert = 1; + } + + mutex_lock(&data->update_lock); + status = as4630_54npe_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + + return sprintf(buf, "%d\n", revert ? !(status & mask) : !!(status & mask)); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t set_qsfp(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 as4630_54npe_cpld_data *data = i2c_get_clientdata(client); + long disable; + int status; + u8 reg = 0, mask = 0, revert = 0; + + status = kstrtol(buf, 10, &disable); + if (status) { + return status; + } + reg = 0x21; + switch (attr->index) + { + case MODULE_RESET_53 ... MODULE_RESET_54: + mask=0x1 << (attr->index==MODULE_RESET_53?3:7); + revert = 1; + break; + case MODULE_LPMODE_53 ... MODULE_LPMODE_54: + mask=0x1 << (attr->index==MODULE_LPMODE_53?2:6); + revert = 0; + break; + default: + return 0; + } + + disable = revert ? disable : !disable; + /* Read current status */ + mutex_lock(&data->update_lock); + status = as4630_54npe_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + if (disable) { + status &= ~mask; + } + else { + status |= mask; + } + status = as4630_54npe_cpld_write_internal(client, reg, status); + if (unlikely(status < 0)) { + goto exit; + } + + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as4630_54npe_cpld_data *data = i2c_get_clientdata(client); + long disable; + int status; + u8 reg = 0, mask = 0; + + status = kstrtol(buf, 10, &disable); + if (status) { + return status; + } + switch (attr->index) + { + case MODULE_TXDISABLE_49 ... MODULE_TXDISABLE_50: + reg=0x5; + mask=0x1 << (attr->index==MODULE_TXDISABLE_49?7:3); + break; + case MODULE_TXDISABLE_51 ... MODULE_TXDISABLE_52: + reg=0x6; + mask=0x1 << (attr->index==MODULE_TXDISABLE_51?7:3); + break; + + default: + return 0; + } + + /* Read current status */ + mutex_lock(&data->update_lock); + status = as4630_54npe_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + /* Update tx_disable status */ + if (disable) { + status |= mask; + } + else { + status &= ~mask; + } + status = as4630_54npe_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 as4630_54npe_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 = as4630_54npe_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 as4630_54npe_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 as4630_54npe_cpld_remove_client(struct i2c_client *client) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int found = 0; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client == client) { + found = 1; + break; + } + } + + if (found) { + list_del(list_node); + kfree(cpld_node); + } + + mutex_unlock(&list_lock); +} + +static ssize_t show_version(struct device *dev, struct device_attribute *attr, char *buf) +{ + int val = 0; + struct i2c_client *client = to_i2c_client(dev); + + val = i2c_smbus_read_byte_data(client, 0x1); + + if (val < 0) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val); + } + + return sprintf(buf, "%d\n", val); +} + +/* fan utility functions + */ +static u32 reg_val_to_duty_cycle(u8 reg_val) +{ + reg_val &= FAN_DUTY_CYCLE_REG_MASK; + return ((u32)(reg_val) * 625)/ 100; +} + +static u8 duty_cycle_to_reg_val(u8 duty_cycle) +{ + return ((u32)duty_cycle * 100 / 625); +} + +static u32 reg_val_to_speed_rpm(u8 reg_val) +{ + return (u32)reg_val * FAN_REG_VAL_TO_SPEED_RPM_STEP; +} + +static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + int error, value; + struct i2c_client *client = to_i2c_client(dev); + + error = kstrtoint(buf, 10, &value); + if (error) + return error; + + if (value < 0 || value > FAN_MAX_DUTY_CYCLE) + return -EINVAL; + + as4630_54npe_cpld_write_internal(client, fan_reg[1], duty_cycle_to_reg_val(value)); + as4630_54npe_cpld_write_internal(client, fan_reg[2], duty_cycle_to_reg_val(value)); + return count; +} + +static u8 reg_val_to_direction(u8 reg_val, enum fan_id id) +{ + u8 mask = (1 << (id+4)); + + reg_val &= mask; + + return reg_val ? 1 : 0; +} + +static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id) +{ + u8 mask = (1 << id); + + reg_val &= mask; + + return reg_val ? 0 : 1; +} + +static u8 is_fan_fault(struct as4630_54npe_cpld_data *data, enum fan_id id) +{ + u8 ret = 1; + + if(id > FAN3_ID) + return 1; + /* Check if the speed of front or rear fan is ZERO, + */ + if (reg_val_to_speed_rpm(data->reg_fan_val[id+3])) + { + + ret = 0; + } + + return ret; +} + +static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, + char *buf) +{ + u32 duty_cycle; + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct as4630_54npe_cpld_data *data = as4630_54npe_fan_update_device(dev); + ssize_t ret = 0; + + if (data->valid) { + switch (attr->index) + { + case FAN_PRESENT_1: + case FAN_PRESENT_2: + case FAN_PRESENT_3: + ret = sprintf(buf, "%d\n", + reg_val_to_is_present(data->reg_fan_val[0], + attr->index - FAN_PRESENT_1)); + break; + case FAN_DUTY_CYCLE_PERCENTAGE: + duty_cycle = reg_val_to_duty_cycle(data->reg_fan_val[1]); + ret = sprintf(buf, "%u\n", duty_cycle); + break; + case FAN_SPEED_RPM_1: + case FAN_SPEED_RPM_2: + case FAN_SPEED_RPM_3: + ret = sprintf(buf, "%u\n", reg_val_to_speed_rpm(data->reg_fan_val[attr->index-FAN_SPEED_RPM_1+3])); + break; + case FAN_FAULT_1: + case FAN_FAULT_2: + case FAN_FAULT_3: + ret = sprintf(buf, "%d\n", is_fan_fault(data, attr->index - FAN_FAULT_1)); + break; + case FAN_DIRECTION_1: + case FAN_DIRECTION_2: + case FAN_DIRECTION_3: + ret = sprintf(buf, "%d\n", + reg_val_to_direction(data->reg_fan_val[0], + attr->index - FAN_DIRECTION_1)); + break; + default: + break; + } + } + + return ret; +} + +static struct as4630_54npe_cpld_data *as4630_54npe_fan_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as4630_54npe_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || + !data->valid) { + int i; + + dev_dbg(&client->dev, "Starting as4630_54npe_fan update\n"); + data->valid = 0; + + /* Update fan data + */ + for (i = 0; i < ARRAY_SIZE(data->reg_fan_val); i++) { + int status = as4630_54npe_cpld_read_internal(client, fan_reg[i]); + if (status < 0) { + data->valid = 0; + mutex_unlock(&data->update_lock); + dev_dbg(&client->dev, "reg 0x%x, err %d\n", fan_reg[i], status); + return data; + } + else { + data->reg_fan_val[i] = status & 0xff; + } + } + + data->last_updated = jiffies; + data->valid = 1; + } + + mutex_unlock(&data->update_lock); + + return data; +} + +/* + * I2C init/probing/exit functions + */ +static int as4630_54npe_cpld_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); + struct as4630_54npe_cpld_data *data; + int ret = -ENODEV; + + const struct attribute_group *group = NULL; + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) + goto exit; + + data = kzalloc(sizeof(struct as4630_54npe_cpld_data), GFP_KERNEL); + if (!data) { + ret = -ENOMEM; + goto exit; + } + + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + data->type = id->driver_data; + + /* Register sysfs hooks */ + switch (data->type) + { + case as4630_54npe_cpld: + group = &as4630_54npe_cpld_group; + break; + default: + break; + } + + if (group) + { + ret = sysfs_create_group(&client->dev.kobj, group); + if (ret) { + goto exit_free; + } + } + + as4630_54npe_cpld_add_client(client); + return 0; + +exit_free: + kfree(data); +exit: + return ret; +} + +static int as4630_54npe_cpld_remove(struct i2c_client *client) +{ + struct as4630_54npe_cpld_data *data = i2c_get_clientdata(client); + const struct attribute_group *group = NULL; + + as4630_54npe_cpld_remove_client(client); + + /* Remove sysfs hooks */ + switch (data->type) + { + case as4630_54npe_cpld: + group = &as4630_54npe_cpld_group; + break; + default: + break; + } + + if (group) { + sysfs_remove_group(&client->dev.kobj, group); + } + + kfree(data); + + return 0; +} + +static int as4630_54npe_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 as4630_54npe_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 as4630_54npe_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 = as4630_54npe_cpld_read_internal(cpld_node->client, reg); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as4630_54npe_cpld_read); + +int as4630_54npe_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 = as4630_54npe_cpld_write_internal(cpld_node->client, reg, value); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as4630_54npe_cpld_write); + +static struct i2c_driver as4630_54npe_cpld_driver = { + .driver = { + .name = "as4630_54npe_cpld", + .owner = THIS_MODULE, + }, + .probe = as4630_54npe_cpld_probe, + .remove = as4630_54npe_cpld_remove, + .id_table = as4630_54npe_cpld_id, +}; + +static int __init as4630_54npe_cpld_init(void) +{ + mutex_init(&list_lock); + return i2c_add_driver(&as4630_54npe_cpld_driver); +} + +static void __exit as4630_54npe_cpld_exit(void) +{ + i2c_del_driver(&as4630_54npe_cpld_driver); +} + +MODULE_AUTHOR("Jostar Yang "); +MODULE_DESCRIPTION("Accton I2C CPLD driver"); +MODULE_LICENSE("GPL"); + +module_init(as4630_54npe_cpld_init); +module_exit(as4630_54npe_cpld_exit); + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/x86-64-accton-as4630-54npe-leds.c b/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/x86-64-accton-as4630-54npe-leds.c new file mode 100644 index 0000000000..c33e59554f --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/x86-64-accton-as4630-54npe-leds.c @@ -0,0 +1,553 @@ +/* + * A LED driver for the accton_as4630_54npe_led + * + * Copyright (C) 2014 Accton Technology Corporation. + * Brandon Chuang + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/*#define DEBUG*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +extern int as4630_54npe_cpld_read (unsigned short cpld_addr, u8 reg); +extern int as4630_54npe_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); + +#define DRVNAME "accton_as4630_54npe_led" + +struct accton_as4630_54npe_led_data { + struct platform_device *pdev; + struct mutex update_lock; + char valid; /* != 0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 reg_val[2]; /* only 1 register*/ +}; + +static struct accton_as4630_54npe_led_data *ledctl = NULL; + +/* LED related data + */ + +#define LED_CNTRLER_I2C_ADDRESS (0x60) + +#define LED_TYPE_DIAG_REG_MASK (0x20|0x40|0x80) +#define LED_MODE_DIAG_GREEN_VALUE (0x20) +#define LED_MODE_DIAG_GREEN_BLINK_VALUE (0x60) +#define LED_MODE_DIAG_AMBER_VALUE (0x80) /*It's yellow actually. Green+Red=Yellow*/ +#define LED_MODE_DIAG_OFF_VALUE (0x0) + +#define LED_TYPE_PRI_REG_MASK (0x8|0x4) +#define LED_MODE_PRI_GREEN_VALUE 0x4 +#define LED_MODE_PRI_AMBER_VALUE 0x8 +#define LED_MODE_PRI_OFF_VALUE 0x0 + +#define LED_TYPE_POE_REG_MASK (0x2|0x1) +#define LED_MODE_POE_GREEN_VALUE 0x1 +#define LED_MODE_POE_AMBER_VALUE 0x2 +#define LED_MODE_POE_OFF_VALUE 0x3 + +#define LED_TYPE_STK1_REG_MASK 0x20 +#define LED_MODE_STK1_GREEN_VALUE 0x0 +#define LED_MODE_STK1_OFF_VALUE 0x20 + +#define LED_TYPE_STK2_REG_MASK 0x10 +#define LED_MODE_STK2_GREEN_VALUE 0x0 +#define LED_MODE_STK2_OFF_VALUE 0x10 + +#define LED_TYPE_FAN_REG_MASK (0x8|0x4) +#define LED_MODE_FAN_AMBER_VALUE 0x8 +#define LED_MODE_FAN_GREEN_VALUE 0x4 +#define LED_MODE_FAN_OFF_VALUE (0xC) + +#define LED_TYPE_PSU2_REG_MASK (0x80|0x40) +#define LED_MODE_PSU2_AMBER_VALUE 0x80 +#define LED_MODE_PSU2_GREEN_VALUE 0x40 +#define LED_MODE_PSU2_OFF_VALUE (0xC0) + +#define LED_TYPE_PSU1_REG_MASK (0x2|0x1) +#define LED_MODE_PSU1_AMBER_VALUE 0x2 +#define LED_MODE_PSU1_GREEN_VALUE 0x1 +#define LED_MODE_PSU1_OFF_VALUE (0x3) + +enum led_type { + LED_TYPE_DIAG, + LED_TYPE_PRI, + LED_TYPE_POE, + LED_TYPE_STK1, + LED_TYPE_STK2, + LED_TYPE_FAN, + LED_TYPE_PSU1, + LED_TYPE_PSU2 +}; + +struct led_reg { + u32 types; + u8 reg_addr; +}; + +static const struct led_reg led_reg_map[] = { + {(1<update_lock); + + if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2) + || !ledctl->valid) { + int i; + + dev_dbg(&ledctl->pdev->dev, "Starting accton_as4630_54npe_led update\n"); + + /* Update LED data + */ + for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { + int status = accton_as4630_54npe_led_read_value(led_reg_map[i].reg_addr); + + if (status < 0) { + ledctl->valid = 0; + dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg_map[i].reg_addr, status); + goto exit; + } + else + { + ledctl->reg_val[i] = status; + } + } + + ledctl->last_updated = jiffies; + ledctl->valid = 1; + } + +exit: + mutex_unlock(&ledctl->update_lock); +} + +static void accton_as4630_54npe_led_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode, + enum led_type type) +{ + int reg_val; + u8 reg ; + mutex_lock(&ledctl->update_lock); + + if( !accton_getLedReg(type, ®)) + { + dev_dbg(&ledctl->pdev->dev, "Not match item for %d.\n", type); + } + + + reg_val = accton_as4630_54npe_led_read_value(reg); + if (reg_val < 0) { + dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val); + goto exit; + } + reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val); + + accton_as4630_54npe_led_write_value(reg, reg_val); + + /* to prevent the slow-update issue */ + ledctl->valid = 0; + +exit: + mutex_unlock(&ledctl->update_lock); +} + + +static void accton_as4630_54npe_led_diag_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + accton_as4630_54npe_led_set(led_cdev, led_light_mode, LED_TYPE_DIAG); +} + +static enum led_brightness accton_as4630_54npe_led_diag_get(struct led_classdev *cdev) +{ + accton_as4630_54npe_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); +} + +static void accton_as4630_54npe_led_pri_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + accton_as4630_54npe_led_set(led_cdev, led_light_mode, LED_TYPE_PRI); +} + +static enum led_brightness accton_as4630_54npe_led_pri_get(struct led_classdev *cdev) +{ + accton_as4630_54npe_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_PRI, ledctl->reg_val[0]); +} + +static void accton_as4630_54npe_led_poe_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + accton_as4630_54npe_led_set(led_cdev, led_light_mode, LED_TYPE_POE); +} + +static enum led_brightness accton_as4630_54npe_led_poe_get(struct led_classdev *cdev) +{ + accton_as4630_54npe_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_POE, ledctl->reg_val[1]); +} + + +static void accton_as4630_54npe_led_stk1_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + accton_as4630_54npe_led_set(led_cdev, led_light_mode, LED_TYPE_STK1); +} + +static enum led_brightness accton_as4630_54npe_led_stk1_get(struct led_classdev *cdev) +{ + accton_as4630_54npe_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_STK1, ledctl->reg_val[1]); +} + +static void accton_as4630_54npe_led_stk2_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + accton_as4630_54npe_led_set(led_cdev, led_light_mode, LED_TYPE_STK2); +} + +static enum led_brightness accton_as4630_54npe_led_stk2_get(struct led_classdev *cdev) +{ + accton_as4630_54npe_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_STK2, ledctl->reg_val[1]); +} + +static void as4630_54npe_led_auto_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ +} + +static enum led_brightness as4630_54npe_led_auto_get(struct led_classdev *cdev) +{ + return LED_MODE_AUTO; +} + +static struct led_classdev accton_as4630_54npe_leds[] = { + [LED_TYPE_DIAG] = { + .name = "diag", + .default_trigger = "unused", + .brightness_set = accton_as4630_54npe_led_diag_set, + .brightness_get = accton_as4630_54npe_led_diag_get, + .flags = LED_CORE_SUSPENDRESUME, + .max_brightness = LED_MODE_GREEN_BLINK, + }, + [LED_TYPE_PRI] = { + .name = "pri", + .default_trigger = "unused", + .brightness_set = accton_as4630_54npe_led_pri_set, + .brightness_get = accton_as4630_54npe_led_pri_get, + .flags = LED_CORE_SUSPENDRESUME, + .max_brightness = LED_MODE_AMBER, + }, + [LED_TYPE_POE] = { + .name = "poe", + .default_trigger = "unused", + .brightness_set = accton_as4630_54npe_led_poe_set, + .brightness_get = accton_as4630_54npe_led_poe_get, + .flags = LED_CORE_SUSPENDRESUME, + .max_brightness = LED_MODE_AMBER, + }, + [LED_TYPE_STK1] = { + .name = "stk1", + .default_trigger = "unused", + .brightness_set = accton_as4630_54npe_led_stk1_set, + .brightness_get = accton_as4630_54npe_led_stk1_get, + .flags = LED_CORE_SUSPENDRESUME, + .max_brightness = LED_MODE_GREEN, + }, + [LED_TYPE_STK2] = { + .name = "stk2", + .default_trigger = "unused", + .brightness_set = accton_as4630_54npe_led_stk2_set, + .brightness_get = accton_as4630_54npe_led_stk2_get, + .flags = LED_CORE_SUSPENDRESUME, + .max_brightness = LED_MODE_GREEN, + }, + [LED_TYPE_FAN] = { + .name = "fan", + .default_trigger = "unused", + .brightness_set = as4630_54npe_led_auto_set, + .brightness_get = as4630_54npe_led_auto_get, + .flags = LED_CORE_SUSPENDRESUME, + .max_brightness = LED_MODE_AUTO, + }, + [LED_TYPE_PSU1] = { + .name = "psu1", + .default_trigger = "unused", + .brightness_set = as4630_54npe_led_auto_set, + .brightness_get = as4630_54npe_led_auto_get, + .flags = LED_CORE_SUSPENDRESUME, + .max_brightness = LED_MODE_AUTO, + }, + [LED_TYPE_PSU2] = { + .name = "psu2", + .default_trigger = "unused", + .brightness_set = as4630_54npe_led_auto_set, + .brightness_get = as4630_54npe_led_auto_get, + .flags = LED_CORE_SUSPENDRESUME, + .max_brightness = LED_MODE_AUTO, + }, +}; + +static int accton_as4630_54npe_led_suspend(struct platform_device *dev, + pm_message_t state) +{ + int i = 0; + + for (i = 0; i < ARRAY_SIZE(accton_as4630_54npe_leds); i++) { + led_classdev_suspend(&accton_as4630_54npe_leds[i]); + } + + return 0; +} + +static int accton_as4630_54npe_led_resume(struct platform_device *dev) +{ + int i = 0; + + for (i = 0; i < ARRAY_SIZE(accton_as4630_54npe_leds); i++) { + led_classdev_resume(&accton_as4630_54npe_leds[i]); + } + + return 0; +} + +static int accton_as4630_54npe_led_probe(struct platform_device *pdev) +{ + int ret, i; + + for (i = 0; i < ARRAY_SIZE(accton_as4630_54npe_leds); i++) { + ret = led_classdev_register(&pdev->dev, &accton_as4630_54npe_leds[i]); + + if (ret < 0) + break; + } + + /* Check if all LEDs were successfully registered */ + if (i != ARRAY_SIZE(accton_as4630_54npe_leds)) { + int j; + + /* only unregister the LEDs that were successfully registered */ + for (j = 0; j < i; j++) { + led_classdev_unregister(&accton_as4630_54npe_leds[i]); + } + } + + return ret; +} + +static int accton_as4630_54npe_led_remove(struct platform_device *pdev) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(accton_as4630_54npe_leds); i++) { + led_classdev_unregister(&accton_as4630_54npe_leds[i]); + } + + return 0; +} + +static struct platform_driver accton_as4630_54npe_led_driver = { + .probe = accton_as4630_54npe_led_probe, + .remove = accton_as4630_54npe_led_remove, + .suspend = accton_as4630_54npe_led_suspend, + .resume = accton_as4630_54npe_led_resume, + .driver = { + .name = DRVNAME, + .owner = THIS_MODULE, + }, +}; + +static int __init accton_as4630_54npe_led_init(void) +{ + int ret; + + ret = platform_driver_register(&accton_as4630_54npe_led_driver); + if (ret < 0) { + goto exit; + } + + ledctl = kzalloc(sizeof(struct accton_as4630_54npe_led_data), GFP_KERNEL); + if (!ledctl) { + ret = -ENOMEM; + platform_driver_unregister(&accton_as4630_54npe_led_driver); + goto exit; + } + + mutex_init(&ledctl->update_lock); + + ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); + if (IS_ERR(ledctl->pdev)) { + ret = PTR_ERR(ledctl->pdev); + platform_driver_unregister(&accton_as4630_54npe_led_driver); + kfree(ledctl); + goto exit; + } + +exit: + return ret; +} + +static void __exit accton_as4630_54npe_led_exit(void) +{ + platform_device_unregister(ledctl->pdev); + platform_driver_unregister(&accton_as4630_54npe_led_driver); + kfree(ledctl); +} + +module_init(accton_as4630_54npe_led_init); +module_exit(accton_as4630_54npe_led_exit); + +MODULE_AUTHOR("Jostar Yang "); +MODULE_DESCRIPTION("accton_as4630_54npe_led driver"); +MODULE_LICENSE("GPL"); diff --git a/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/x86-64-accton-as4630-54npe-psu.c b/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/x86-64-accton-as4630-54npe-psu.c new file mode 100644 index 0000000000..699e86fb1c --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/modules/builds/x86-64-accton-as4630-54npe-psu.c @@ -0,0 +1,345 @@ +/* + * An hwmon driver for accton as4630_54npe Power Module + * + * Copyright (C) 2014 Accton Technology Corporation. + * Brandon Chuang + * + * Based on ad7414.c + * Copyright 2006 Stefan Roese , DENX Software Engineering + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_MODEL_NAME 20 +#define MAX_SERIAL_NUMBER 19 + +static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t show_string(struct device *dev, struct device_attribute *da, char *buf); +static int as4630_54npe_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); +extern int as4630_54npe_cpld_read(unsigned short cpld_addr, u8 reg); + +/* Addresses scanned + */ +static const unsigned short normal_i2c[] = { 0x50, 0x51, I2C_CLIENT_END }; + +/* Each client has this additional data + */ +struct as4630_54npe_psu_data { + struct device *hwmon_dev; + struct mutex update_lock; + char valid; /* !=0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 index; /* PSU index */ + u8 status; /* Status(present/power_good) register read from CPLD */ + char model_name[MAX_MODEL_NAME]; /* Model name, read from eeprom */ + char serial_number[MAX_SERIAL_NUMBER]; +}; + +static struct as4630_54npe_psu_data *as4630_54npe_psu_update_device(struct device *dev); + +enum as4630_54npe_psu_sysfs_attributes { + PSU_PRESENT, + PSU_MODEL_NAME, + PSU_POWER_GOOD, + PSU_SERIAL_NUMBER +}; + +/* sysfs attributes for hwmon + */ +static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT); +static SENSOR_DEVICE_ATTR(psu_model_name, S_IRUGO, show_string, NULL, PSU_MODEL_NAME); +static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD); +static SENSOR_DEVICE_ATTR(psu_serial_number, S_IRUGO, show_string, NULL, PSU_SERIAL_NUMBER); + + +static struct attribute *as4630_54npe_psu_attributes[] = { + &sensor_dev_attr_psu_present.dev_attr.attr, + &sensor_dev_attr_psu_model_name.dev_attr.attr, + &sensor_dev_attr_psu_power_good.dev_attr.attr, + &sensor_dev_attr_psu_serial_number.dev_attr.attr, + NULL +}; + +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as4630_54npe_psu_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + u8 status = 0; + + mutex_lock(&data->update_lock); + data = as4630_54npe_psu_update_device(dev); + + if (attr->index == PSU_PRESENT) { + if(data->index==0) + status = !( (data->status >> 5) & 0x1); + else + status = !( (data->status >> 1) & 0x1); + } + else { /* PSU_POWER_GOOD */ + if(data->index==0) + status = ( (data->status >> 6) & 0x1); + else + status = ( (data->status >> 2) & 0x1); + } + + mutex_unlock(&data->update_lock); + return sprintf(buf, "%d\n", status); +} + +static ssize_t show_string(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as4630_54npe_psu_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + char *ptr = NULL; + + mutex_lock(&data->update_lock); + + data = as4630_54npe_psu_update_device(dev); + if (!data->valid) { + mutex_unlock(&data->update_lock); + return -EIO; + } + + switch (attr->index) { + case PSU_MODEL_NAME: + ptr = data->model_name; + break; + case PSU_SERIAL_NUMBER: + ptr = data->serial_number; + break; + default: + mutex_unlock(&data->update_lock); + return -EINVAL; + } + + mutex_unlock(&data->update_lock); + return sprintf(buf, "%s\n", ptr); +} + +static const struct attribute_group as4630_54npe_psu_group = { + .attrs = as4630_54npe_psu_attributes, +}; + +static int as4630_54npe_psu_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct as4630_54npe_psu_data *data; + int status; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { + status = -EIO; + goto exit; + } + + data = kzalloc(sizeof(struct as4630_54npe_psu_data), GFP_KERNEL); + if (!data) { + status = -ENOMEM; + goto exit; + } + + i2c_set_clientdata(client, data); + data->valid = 0; + data->index = dev_id->driver_data; + mutex_init(&data->update_lock); + + dev_info(&client->dev, "chip found\n"); + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &as4630_54npe_psu_group); + if (status) { + goto exit_free; + } + + data->hwmon_dev = hwmon_device_register(&client->dev); + if (IS_ERR(data->hwmon_dev)) { + status = PTR_ERR(data->hwmon_dev); + goto exit_remove; + } + + dev_info(&client->dev, "%s: psu '%s'\n", + dev_name(data->hwmon_dev), client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &as4630_54npe_psu_group); +exit_free: + kfree(data); +exit: + + return status; +} + +static int as4630_54npe_psu_remove(struct i2c_client *client) +{ + struct as4630_54npe_psu_data *data = i2c_get_clientdata(client); + + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &as4630_54npe_psu_group); + kfree(data); + + return 0; +} + +enum psu_index +{ + as4630_54npe_psu1, + as4630_54npe_psu2 +}; + +static const struct i2c_device_id as4630_54npe_psu_id[] = { + { "as4630_54npe_psu1", as4630_54npe_psu1 }, + { "as4630_54npe_psu2", as4630_54npe_psu2 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, as4630_54npe_psu_id); + +static struct i2c_driver as4630_54npe_psu_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "as4630_54npe_psu", + }, + .probe = as4630_54npe_psu_probe, + .remove = as4630_54npe_psu_remove, + .id_table = as4630_54npe_psu_id, + .address_list = normal_i2c, +}; + +static int as4630_54npe_psu_read_block(struct i2c_client *client, u8 command, u8 *data, + int data_len) +{ + int result = 0; + int retry_count = 5; + + while (retry_count) { + retry_count--; + + result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); + + if (unlikely(result < 0)) { + msleep(10); + continue; + } + + if (unlikely(result != data_len)) { + result = -EIO; + msleep(10); + continue; + } + + result = 0; + break; + } + + return result; +} + +static struct as4630_54npe_psu_data *as4630_54npe_psu_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as4630_54npe_psu_data *data = i2c_get_clientdata(client); + + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) + || !data->valid) { + int status; + int power_good = 0; + + dev_dbg(&client->dev, "Starting as4630_54npe update\n"); + + /* Read psu status */ + status = as4630_54npe_cpld_read(0x60, 0x22); + if (status < 0) { + dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); + } + else { + data->status = status; + } + + /* Read model name */ + memset(data->model_name, 0, sizeof(data->model_name)); + memset(data->serial_number, 0, sizeof(data->serial_number)); + + if(data->index==0) + power_good = ( (data->status >> 6) & 0x1); + else + power_good = ( (data->status >> 2) & 0x1); + + if (power_good) { + status = as4630_54npe_psu_read_block(client, 0x20, data->model_name, + ARRAY_SIZE(data->model_name)-1); + if (status < 0) { + data->model_name[0] = '\0'; + dev_dbg(&client->dev, "unable to read model name from (0x%x)\n", client->addr); + } + else if(!strncmp(data->model_name, "YPEB1200", strlen("YPEB1200"))) + { + if (data->model_name[9]=='A' && data->model_name[10]=='M') + { + data->model_name[8]='A'; + data->model_name[9]='M'; + data->model_name[strlen("YPEB1200AM")]='\0'; + } + else + data->model_name[strlen("YPEB1200")]='\0'; + } + else + { + data->model_name[ARRAY_SIZE(data->model_name)-1] = '\0'; + } + /* Read from offset 0x35 ~ 0x46 (18 bytes) */ + status = as4630_54npe_psu_read_block(client, 0x35,data->serial_number, MAX_SERIAL_NUMBER); + if (status < 0) + { + data->serial_number[0] = '\0'; + dev_dbg(&client->dev, "unable to read model name from (0x%x) offset(0x35)\n", client->addr); + } + if (!strncmp(data->model_name, "YPEB1200AM", strlen("YPEB1200AM"))) /*for YPEB1200AM, SN length=18*/ + { + data->serial_number[MAX_SERIAL_NUMBER-1]='\0'; + } + else + data->serial_number[MAX_SERIAL_NUMBER-2]='\0'; + + } + + data->last_updated = jiffies; + data->valid = 1; + } + + return data; +} + +module_i2c_driver(as4630_54npe_psu_driver); + +MODULE_AUTHOR("Jostar Yang "); +MODULE_DESCRIPTION("as4630_54npe_psu driver"); +MODULE_LICENSE("GPL"); + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/Makefile b/packages/platforms/accton/x86-64/as4630-54npe/onlp/Makefile new file mode 100644 index 0000000000..003238cf6d --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/PKG.yml b/packages/platforms/accton/x86-64/as4630-54npe/onlp/PKG.yml new file mode 100644 index 0000000000..1905bfe53d --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=x86-64-accton-as4630-54npe ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/Makefile b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/Makefile new file mode 100644 index 0000000000..e7437cb23a --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/Makefile @@ -0,0 +1,2 @@ +FILTER=src +include $(ONL)/make/subdirs.mk diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/lib/Makefile b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/lib/Makefile new file mode 100644 index 0000000000..7b097a8c87 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/lib/Makefile @@ -0,0 +1,2 @@ +PLATFORM := x86-64-accton-as4630-54npe +include $(ONL)/packages/base/any/onlp/builds/platform/libonlp-platform.mk diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/onlpdump/Makefile b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/onlpdump/Makefile new file mode 100644 index 0000000000..6020d2373f --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/onlpdump/Makefile @@ -0,0 +1,2 @@ +PLATFORM := x86-64-accton-as4630-54npe +include $(ONL)/packages/base/any/onlp/builds/platform/onlps.mk diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/.gitignore b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/.module b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/.module new file mode 100644 index 0000000000..b3a897f93f --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/.module @@ -0,0 +1 @@ +name: x86_64_accton_as4630_54npe diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/Makefile b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/Makefile new file mode 100644 index 0000000000..6a077c654b --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### +include $(ONL)/make/config.mk +MODULE := x86_64_accton_as4630_54npe +AUTOMODULE := x86_64_accton_as4630_54npe +include $(BUILDER)/definemodule.mk diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/README b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/README new file mode 100644 index 0000000000..3b62ae726c --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/README @@ -0,0 +1,6 @@ +############################################################################### +# +# x86_64_accton_as4630_54npe README +# +############################################################################### + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/auto/make.mk b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/auto/make.mk new file mode 100644 index 0000000000..449ac7fd14 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/auto/make.mk @@ -0,0 +1,8 @@ +############################################################################### +# +# x86_64_accton_as4630_54npe Autogeneration +# +############################################################################### +x86_64_accton_as4630_54npe_AUTO_DEFS := module/auto/x86_64_accton_as4630_54npe.yml +x86_64_accton_as4630_54npe_AUTO_DIRS := module/inc/x86_64_accton_as4630_54npe module/src +include $(BUILDER)/auto.mk diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/auto/x86_64_accton_as4630_54npe.yml b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/auto/x86_64_accton_as4630_54npe.yml new file mode 100644 index 0000000000..b7d1575ff7 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/auto/x86_64_accton_as4630_54npe.yml @@ -0,0 +1,50 @@ +############################################################################### +# +# x86_64_accton_as4630_54npe Autogeneration Definitions. +# +############################################################################### + +cdefs: &cdefs +- X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_LOGGING: + doc: "Include or exclude logging." + default: 1 +- X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_OPTIONS_DEFAULT: + doc: "Default enabled log options." + default: AIM_LOG_OPTIONS_DEFAULT +- X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_BITS_DEFAULT: + doc: "Default enabled log bits." + default: AIM_LOG_BITS_DEFAULT +- X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_CUSTOM_BITS_DEFAULT: + doc: "Default enabled custom log bits." + default: 0 +- X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB: + doc: "Default all porting macros to use the C standard libraries." + default: 1 +- X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: + doc: "Include standard library headers for stdlib porting macros." + default: X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB +- X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_UCLI: + doc: "Include generic uCli support." + default: 0 +- X86_64_ACCTON_AS4630_54NPE_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_AS4630_54NPE_CONFIG_HEADER: + defs: *cdefs + basename: x86_64_accton_as4630_54npe_config + + portingmacro: + x86_64_accton_as4630_54npe: + macros: + - malloc + - free + - memset + - memcpy + + - vsnprintf + - snprintf + - strlen diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe.x b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe.x new file mode 100644 index 0000000000..d8064349ec --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe.x @@ -0,0 +1,14 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.xmacro(ALL).define> */ +/* */ + +/* <--auto.start.xenum(ALL).define> */ +/* */ + + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe_config.h b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe_config.h new file mode 100644 index 0000000000..146fb22219 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe_config.h @@ -0,0 +1,137 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as4630_54npe Configuration Header + * + * @addtogroup x86_64_accton_as4630_54npe-config + * @{ + * + *****************************************************************************/ +#ifndef __X86_64_ACCTON_AS4630_54NPE_CONFIG_H__ +#define __X86_64_ACCTON_AS4630_54NPE_CONFIG_H__ + +#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG +#include +#endif +#ifdef X86_64_ACCTON_AS4630_54NPE_INCLUDE_CUSTOM_CONFIG +#include +#endif + +/* */ +#include +/** + * X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_LOGGING + * + * Include or exclude logging. */ + + +#ifndef X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_LOGGING +#define X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_LOGGING 1 +#endif + +/** + * X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_OPTIONS_DEFAULT + * + * Default enabled log options. */ + + +#ifndef X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_OPTIONS_DEFAULT +#define X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#endif + +/** + * X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_BITS_DEFAULT + * + * Default enabled log bits. */ + + +#ifndef X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_BITS_DEFAULT +#define X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#endif + +/** + * X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * + * Default enabled custom log bits. */ + + +#ifndef X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#endif + +/** + * X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB + * + * Default all porting macros to use the C standard libraries. */ + + +#ifndef X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB +#define X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB 1 +#endif + +/** + * X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * + * Include standard library headers for stdlib porting macros. */ + + +#ifndef X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB +#endif + +/** + * X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_UCLI + * + * Include generic uCli support. */ + + +#ifndef X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_UCLI +#define X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_UCLI 0 +#endif + +/** + * X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + * + * Assume chassis fan direction is the same as the PSU fan direction. */ + + +#ifndef X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION +#define X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION 0 +#endif + + + +/** + * All compile time options can be queried or displayed + */ + +/** Configuration settings structure. */ +typedef struct x86_64_accton_as4630_54npe_config_settings_s { + /** name */ + const char* name; + /** value */ + const char* value; +} x86_64_accton_as4630_54npe_config_settings_t; + +/** Configuration settings table. */ +/** x86_64_accton_as4630_54npe_config_settings table. */ +extern x86_64_accton_as4630_54npe_config_settings_t x86_64_accton_as4630_54npe_config_settings[]; + +/** + * @brief Lookup a configuration setting. + * @param setting The name of the configuration option to lookup. + */ +const char* x86_64_accton_as4630_54npe_config_lookup(const char* setting); + +/** + * @brief Show the compile-time configuration. + * @param pvs The output stream. + */ +int x86_64_accton_as4630_54npe_config_show(struct aim_pvs_s* pvs); + +/* */ + +#include "x86_64_accton_as4630_54npe_porting.h" + +#endif /* __X86_64_ACCTON_AS4630_54NPE_CONFIG_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe_dox.h b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe_dox.h new file mode 100644 index 0000000000..5d2b21614d --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe_dox.h @@ -0,0 +1,26 @@ +/**************************************************************************//** + * + * x86_64_accton_as4630_54npe Doxygen Header + * + *****************************************************************************/ +#ifndef __X86_64_ACCTON_AS4630_54NPE_DOX_H__ +#define __X86_64_ACCTON_AS4630_54NPE_DOX_H__ + +/** + * @defgroup x86_64_accton_as4630_54npe x86_64_accton_as4630_54npe - x86_64_accton_as4630_54npe Description + * + +The documentation overview for this module should go here. + + * + * @{ + * + * @defgroup x86_64_accton_as4630_54npe-x86_64_accton_as4630_54npe Public Interface + * @defgroup x86_64_accton_as4630_54npe-config Compile Time Configuration + * @defgroup x86_64_accton_as4630_54npe-porting Porting Macros + * + * @} + * + */ + +#endif /* __X86_64_ACCTON_AS4630_54NPE_DOX_H__ */ diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe_porting.h b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe_porting.h new file mode 100644 index 0000000000..dd4f9b0987 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/inc/x86_64_accton_as4630_54npe/x86_64_accton_as4630_54npe_porting.h @@ -0,0 +1,97 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as4630_54npe Porting Macros. + * + * @addtogroup x86_64_accton_as4630_54npe-porting + * @{ + * + *****************************************************************************/ +#ifndef __X86_64_ACCTON_AS4630_54NPE_PORTING_H__ +#define __X86_64_ACCTON_AS4630_54NPE_PORTING_H__ + + +/* */ +#if X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#include +#include +#include +#include +#include +#endif + +#ifndef X86_64_ACCTON_AS4630_54NPE_MALLOC + #if defined(GLOBAL_MALLOC) + #define X86_64_ACCTON_AS4630_54NPE_MALLOC GLOBAL_MALLOC + #elif X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS4630_54NPE_MALLOC malloc + #else + #error The macro X86_64_ACCTON_AS4630_54NPE_MALLOC is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS4630_54NPE_FREE + #if defined(GLOBAL_FREE) + #define X86_64_ACCTON_AS4630_54NPE_FREE GLOBAL_FREE + #elif X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS4630_54NPE_FREE free + #else + #error The macro X86_64_ACCTON_AS4630_54NPE_FREE is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS4630_54NPE_MEMSET + #if defined(GLOBAL_MEMSET) + #define X86_64_ACCTON_AS4630_54NPE_MEMSET GLOBAL_MEMSET + #elif X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS4630_54NPE_MEMSET memset + #else + #error The macro X86_64_ACCTON_AS4630_54NPE_MEMSET is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS4630_54NPE_MEMCPY + #if defined(GLOBAL_MEMCPY) + #define X86_64_ACCTON_AS4630_54NPE_MEMCPY GLOBAL_MEMCPY + #elif X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS4630_54NPE_MEMCPY memcpy + #else + #error The macro X86_64_ACCTON_AS4630_54NPE_MEMCPY is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS4630_54NPE_VSNPRINTF + #if defined(GLOBAL_VSNPRINTF) + #define X86_64_ACCTON_AS4630_54NPE_VSNPRINTF GLOBAL_VSNPRINTF + #elif X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS4630_54NPE_VSNPRINTF vsnprintf + #else + #error The macro X86_64_ACCTON_AS4630_54NPE_VSNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS4630_54NPE_SNPRINTF + #if defined(GLOBAL_SNPRINTF) + #define X86_64_ACCTON_AS4630_54NPE_SNPRINTF GLOBAL_SNPRINTF + #elif X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS4630_54NPE_SNPRINTF snprintf + #else + #error The macro X86_64_ACCTON_AS4630_54NPE_SNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS4630_54NPE_STRLEN + #if defined(GLOBAL_STRLEN) + #define X86_64_ACCTON_AS4630_54NPE_STRLEN GLOBAL_STRLEN + #elif X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS4630_54NPE_STRLEN strlen + #else + #error The macro X86_64_ACCTON_AS4630_54NPE_STRLEN is required but cannot be defined. + #endif +#endif + +/* */ + + +#endif /* __X86_64_ACCTON_AS4630_54NPE_PORTING_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/make.mk b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/make.mk new file mode 100644 index 0000000000..a2a1050c9b --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/make.mk @@ -0,0 +1,10 @@ +############################################################################### +# +# +# +############################################################################### +THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +x86_64_accton_as4630_54npe_INCLUDES := -I $(THIS_DIR)inc +x86_64_accton_as4630_54npe_INTERNAL_INCLUDES := -I $(THIS_DIR)src +x86_64_accton_as4630_54npe_DEPENDMODULE_ENTRIES := init:x86_64_accton_as4630_54npe ucli:x86_64_accton_as4630_54npe + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/Makefile b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/Makefile new file mode 100644 index 0000000000..8907fc65d0 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# Local source generation targets. +# +############################################################################### + +ucli: + @../../../../tools/uclihandlers.py x86_64_accton_as4630_54npe_ucli.c + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/fani.c b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/fani.c new file mode 100644 index 0000000000..f8aef08f25 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/fani.c @@ -0,0 +1,326 @@ +/************************************************************ + * + * + * 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 "platform_lib.h" + +#define PSU_PREFIX_PATH "/sys/bus/i2c/devices/" + +#define MAX_FAN_SPEED 25500 +#define MAX_PSU_FAN_SPEED 25500 + +enum fan_id { + FAN_1_ON_FAN_BOARD = 1, + FAN_2_ON_FAN_BOARD, + FAN_3_ON_FAN_BOARD, + FAN_1_ON_PSU_1, + FAN_1_ON_PSU_2, +}; + +#define CHASSIS_FAN_INFO(fid) \ + { \ + { ONLP_FAN_ID_CREATE(FAN_##fid##_ON_FAN_BOARD), "Chassis Fan - "#fid, 0 },\ + 0x0,\ + ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE,\ + 0,\ + 0,\ + ONLP_FAN_MODE_INVALID,\ + } + +#define PSU_FAN_INFO(pid, fid) \ + { \ + { ONLP_FAN_ID_CREATE(FAN_##fid##_ON_PSU_##pid), "PSU "#pid" - Fan "#fid, 0 },\ + 0x0,\ + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE,\ + 0,\ + 0,\ + ONLP_FAN_MODE_INVALID,\ + } + +/* Static fan information */ +onlp_fan_info_t finfo[] = { + { }, /* Not used */ + CHASSIS_FAN_INFO(1), + CHASSIS_FAN_INFO(2), + CHASSIS_FAN_INFO(3), + PSU_FAN_INFO(1,1), + PSU_FAN_INFO(2,1) +}; + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_FAN(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +static int +_onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) +{ + int value; + char path[64] = {0}; + + /* get fan present status + */ + sprintf(path, "%s""fan_present_%d", CPLD_NODE_PATH, fid); + DEBUG_PRINT("Fan(%d), present path = (%s)", fid, path); + + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + if (value == 0) { + return ONLP_STATUS_OK; + } + info->status |= ONLP_FAN_STATUS_PRESENT; + + + /* get fan fault status (turn on when any one fails) + */ + sprintf(path, "%s""fan_fault_%d", CPLD_NODE_PATH, fid); + DEBUG_PRINT("Fan(%d), fault path = (%s)", fid, path); + + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + if (value > 0) { + info->status |= ONLP_FAN_STATUS_FAILED; + } + + + /* get fan direction (both : the same) + */ + sprintf(path, "%s""fan_direction_%d", CPLD_NODE_PATH, fid); + DEBUG_PRINT("Fan(%d), direction path = (%s)", fid, path); + + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + info->status |= value ? ONLP_FAN_STATUS_F2B : ONLP_FAN_STATUS_B2F; + + + /* get front fan speed + */ + sprintf(path, "%s""fan_speed_rpm_%d", CPLD_NODE_PATH, fid); + DEBUG_PRINT("Fan (%d), speed path = (%s)", fid, path); + + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + info->rpm = value; + + /* get pwm percentage + */ + + sprintf(path, "%s""fan_duty_cycle_percentage", CPLD_NODE_PATH); + DEBUG_PRINT("Fan (%d), duty_cycle path = (%s)", fid, path); + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + info->percentage = value; + + return ONLP_STATUS_OK; +} + +static uint32_t +_onlp_get_fan_direction_on_psu(void) +{ + return ONLP_FAN_STATUS_F2B; +} + +static int +_onlp_fani_info_get_fan_on_psu(int pid, onlp_fan_info_t* info) +{ + int val = 0; + + info->status |= ONLP_FAN_STATUS_PRESENT; + + /* get fan direction + */ + info->status |= _onlp_get_fan_direction_on_psu(); + + /* get fan fault status + */ + if (psu_ym2651y_pmbus_info_get(pid, "psu_fan1_fault", &val) == ONLP_STATUS_OK) { + info->status |= (val > 0) ? ONLP_FAN_STATUS_FAILED : 0; + } + + /* get fan speed + */ + if (psu_ym2651y_pmbus_info_get(pid, "psu_fan1_speed_rpm", &val) == ONLP_STATUS_OK) { + info->rpm = val; + info->percentage = (info->rpm * 100) / MAX_PSU_FAN_SPEED; + } + + return ONLP_STATUS_OK; +} + +/* + * This function will be called prior to all of onlp_fani_* functions. + */ +int +onlp_fani_init(void) +{ + return ONLP_STATUS_OK; +} + +int +onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) +{ + int rc = 0; + int fid; + VALIDATE(id); + + fid = ONLP_OID_ID_GET(id); + *info = finfo[fid]; + + switch (fid) + { + case FAN_1_ON_PSU_1: + rc = _onlp_fani_info_get_fan_on_psu(PSU1_ID, info); + break; + case FAN_1_ON_PSU_2: + rc = _onlp_fani_info_get_fan_on_psu(PSU2_ID, info); + break; + case FAN_1_ON_FAN_BOARD: + case FAN_2_ON_FAN_BOARD: + case FAN_3_ON_FAN_BOARD: + rc =_onlp_fani_info_get_fan(fid, info); + break; + default: + rc = ONLP_STATUS_E_INVALID; + break; + } + + return rc; +} + +/* + * This function sets the speed of the given fan in RPM. + * + * This function will only be called if the fan supprots the RPM_SET + * capability. + * + * It is optional if you have no fans at all with this feature. + */ +int +onlp_fani_rpm_set(onlp_oid_t id, int rpm) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * This function sets the fan speed of the given OID as a percentage. + * + * This will only be called if the OID has the PERCENTAGE_SET + * capability. + * + * It is optional if you have no fans at all with this feature. + */ +int +onlp_fani_percentage_set(onlp_oid_t id, int p) +{ + int fid; + char *path = NULL; + + VALIDATE(id); + + fid = ONLP_OID_ID_GET(id); + + /* reject p=0 (p=0, stop fan) */ + if (p == 0){ + return ONLP_STATUS_E_INVALID; + } + + switch (fid) + { + case FAN_1_ON_PSU_1: + return psu_ym2651y_pmbus_info_set(PSU1_ID, "psu_fan_duty_cycle_percentage", p); + case FAN_1_ON_PSU_2: + return psu_ym2651y_pmbus_info_set(PSU2_ID, "psu_fan_duty_cycle_percentage", p); + case FAN_1_ON_FAN_BOARD: + case FAN_2_ON_FAN_BOARD: + case FAN_3_ON_FAN_BOARD: + path = FAN_NODE(fan_duty_cycle_percentage); + break; + default: + return ONLP_STATUS_E_INVALID; + } + + DEBUG_PRINT("Fan path = (%s)", path); + + if (onlp_file_write_integer(path, p) < 0) { + AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + + +/* + * This function sets the fan speed of the given OID as per + * the predefined ONLP fan speed modes: off, slow, normal, fast, max. + * + * Interpretation of these modes is up to the platform. + * + */ +int +onlp_fani_mode_set(onlp_oid_t id, onlp_fan_mode_t mode) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * This function sets the fan direction of the given OID. + * + * This function is only relevant if the fan OID supports both direction + * capabilities. + * + * This function is optional unless the functionality is available. + */ +int +onlp_fani_dir_set(onlp_oid_t id, onlp_fan_dir_t dir) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * Generic fan ioctl. Optional. + */ +int +onlp_fani_ioctl(onlp_oid_t id, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/ledi.c b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/ledi.c new file mode 100644 index 0000000000..aa115a74eb --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/ledi.c @@ -0,0 +1,292 @@ +/************************************************************ + * + * + * 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 + +#include "platform_lib.h" + +#define prefix_path "/sys/class/leds/" +#define filename "brightness" + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_LED(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +/* LED related data + */ +enum onlp_led_id +{ + LED_RESERVED = 0, + LED_DIAG, + LED_PRI, + LED_POE, + LED_STK1, + LED_STK2, + LED_FAN, + LED_PSU1, + LED_PSU2 +}; + +enum led_light_mode { + LED_MODE_OFF = 0, + LED_MODE_GREEN, + LED_MODE_AMBER, + LED_MODE_RED, + LED_MODE_BLUE, + LED_MODE_GREEN_BLINK, + LED_MODE_AMBER_BLINK, + LED_MODE_RED_BLINK, + LED_MODE_BLUE_BLINK, + LED_MODE_AUTO, + LED_MODE_UNKNOWN +}; + +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_DIAG, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_DIAG, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, +{LED_DIAG, LED_MODE_AMBER, ONLP_LED_MODE_ORANGE}, +{LED_DIAG, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, +{LED_PRI, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_PRI, LED_MODE_AMBER, ONLP_LED_MODE_ORANGE}, +{LED_PRI, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, +{LED_POE, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_POE, LED_MODE_AMBER, ONLP_LED_MODE_ORANGE}, +{LED_POE, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, +{LED_STK1, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_STK1, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, +{LED_STK2, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_STK2, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, +{LED_FAN, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, +{LED_PSU1, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, +{LED_PSU2, LED_MODE_AUTO, ONLP_LED_MODE_AUTO} +}; + +static char last_path[][10] = /* must map with onlp_led_id */ +{ + "reserved", + "diag", + "pri", + "poe", + "stk1", + "stk2", + "fan", + "psu1", + "psu2" +}; + +/* + * Get the information for the given LED OID. + */ +static onlp_led_info_t linfo[] = +{ + { }, /* Not used */ + { + { ONLP_LED_ID_CREATE(LED_DIAG), "LED 1 (DIAG LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF |ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN_BLINKING, + }, + { + { ONLP_LED_ID_CREATE(LED_PRI), "LED 2 (PRI LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN, + }, + { + { ONLP_LED_ID_CREATE(LED_PRI), "LED 3 (POE LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN, + }, + { + { ONLP_LED_ID_CREATE(LED_STK1), "LED 4 (STK1 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN, + }, + { + { ONLP_LED_ID_CREATE(LED_STK2), "LED 5 (STK2 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN, + }, + { + { ONLP_LED_ID_CREATE(LED_FAN), "LED 6 (FAN LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU1), "LED 7 (PSU1 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU2), "LED 8 (PSU2 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_AUTO, + }, +}; + +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) +{ + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_DIAG), ONLP_LED_MODE_GREEN); + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_PRI), ONLP_LED_MODE_GREEN); + + return ONLP_STATUS_OK; +} + +int +onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) +{ + int local_id; + char data[2] = {0}; + char fullpath[50] = {0}; + + VALIDATE(id); + + local_id = ONLP_OID_ID_GET(id); + + /* get fullpath */ + sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[ONLP_OID_ID_GET(id)]; + + /* Set LED mode */ + if (onlp_file_read_string(fullpath, data, sizeof(data), 0) != 0) { + DEBUG_PRINT("%s(%d)\r\n", __FUNCTION__, __LINE__); + return ONLP_STATUS_E_INTERNAL; + } + + info->mode = driver_to_onlp_led_mode(local_id, atoi(data)); + + /* 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); + } + else + return onlp_ledi_mode_set(id, ONLP_LED_MODE_GREEN); + + +} + +/* + * 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 local_id; + char fullpath[50] = {0}; + + VALIDATE(id); + + local_id = ONLP_OID_ID_GET(id); + sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename); + + if (onlp_file_write_integer(fullpath, onlp_to_driver_led_mode(local_id, mode)) != 0) + { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +/* + * Generic LED ioctl interface. + */ +int +onlp_ledi_ioctl(onlp_oid_t id, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/make.mk b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/make.mk new file mode 100644 index 0000000000..8450d393fb --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### + +LIBRARY := x86_64_accton_as4630_54npe +$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(BUILDER)/lib.mk diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/platform_lib.c b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/platform_lib.c new file mode 100644 index 0000000000..ec72857ea2 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/platform_lib.c @@ -0,0 +1,224 @@ +#include +#include +#include +#include +#include "platform_lib.h" +#include +#include "x86_64_accton_as4630_54npe_log.h" + + +static int _onlp_file_write(char *filename, char *buffer, int buf_size, int data_len) +{ + int fd; + int len; + + if ((buffer == NULL) || (buf_size < 0)) { + return -1; + } + + if ((fd = open(filename, O_WRONLY, S_IWUSR)) == -1) { + return -1; + } + + if ((len = write(fd, buffer, buf_size)) < 0) { + close(fd); + return -1; + } + + if ((close(fd) == -1)) { + return -1; + } + + if ((len > buf_size) || (data_len != 0 && len != data_len)) { + return -1; + } + + return 0; +} + +int onlp_file_write_integer(char *filename, int value) +{ + char buf[8] = {0}; + sprintf(buf, "%d", value); + + return _onlp_file_write(filename, buf, (int)strlen(buf), 0); +} + +int onlp_file_read_binary(char *filename, char *buffer, int buf_size, int data_len) +{ + int fd; + int len; + + if ((buffer == NULL) || (buf_size < 0)) { + return -1; + } + + if ((fd = open(filename, O_RDONLY)) == -1) { + return -1; + } + + if ((len = read(fd, buffer, buf_size)) < 0) { + close(fd); + return -1; + } + + if ((close(fd) == -1)) { + return -1; + } + + if ((len > buf_size) || (data_len != 0 && len != data_len)) { + return -1; + } + + return 0; +} + +int onlp_file_read_string(char *filename, char *buffer, int buf_size, int data_len) +{ + int ret; + + if (data_len >= buf_size) { + return -1; + } + + ret = onlp_file_read_binary(filename, buffer, buf_size-1, data_len); + + if (ret == 0) { + buffer[buf_size-1] = '\0'; + } + + return ret; +} + +#define I2C_PSU_MODEL_NAME_LEN 11 +#define I2C_PSU_FAN_DIR_LEN 3 + +psu_type_t get_psu_type(int id, char* modelname, int modelname_len) +{ + char *node = NULL; + char model_name[I2C_PSU_MODEL_NAME_LEN + 1] = {0}; + + /* Check model name */ + node = (id == PSU1_ID) ? PSU1_AC_PMBUS_NODE(psu_mfr_model) : PSU2_AC_PMBUS_NODE(psu_mfr_model); + memset(model_name, 0x0, I2C_PSU_MODEL_NAME_LEN + 1); + memset(modelname, 0x0, modelname_len); + if (onlp_file_read_string(node, model_name, sizeof(model_name), 0) != 0) { + + return PSU_TYPE_UNKNOWN; + } + if (!strncmp(model_name, "FSH082", strlen("FSH082"))) + { + if (modelname) + aim_strlcpy(modelname, model_name, strlen("FSH082")<(modelname_len-1)?strlen("FSH082"):(modelname_len-1)); + + return PSU_TYPE_ACBEL; + } + if (!strncmp(model_name, "YM-2651Y", strlen("YM-2651Y"))) + { + if (modelname) + aim_strlcpy(modelname, model_name, modelname_len-1); + return PSU_TYPE_YM2651Y; + } + + if (!strncmp(model_name, "YPEB1200AM", strlen("YPEB1200AM"))) + { + if (modelname) + aim_strlcpy(modelname, model_name, (modelname_len>strlen(model_name))?strlen(model_name):modelname_len-1); + return PSU_TYPE_YPEB1200A; + } + return PSU_TYPE_UNKNOWN; +} +int +psu_pmbus_info_get(int id, char *node, int *value) +{ + int ret = 0; + char path[PSU_NODE_MAX_PATH_LEN] = {0}; + + *value = 0; + + if (PSU1_ID == id) { + sprintf(path, "%s%s", PSU1_AC_PMBUS_PREFIX, node); + } + else { + sprintf(path, "%s%s", PSU2_AC_PMBUS_PREFIX, node); + } + + if (onlp_file_read_int(value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ret; +} + + + +int psu_ym2651y_pmbus_info_get(int id, char *node, int *value) +{ + int ret = 0; + char path[PSU_NODE_MAX_PATH_LEN] = {0}; + + *value = 0; + + if (PSU1_ID == id) { + sprintf(path, "%s%s", PSU1_AC_PMBUS_PREFIX, node); + } + else { + sprintf(path, "%s%s", PSU2_AC_PMBUS_PREFIX, node); + } + + if (onlp_file_read_int(value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ret; +} + +int psu_ym2651y_pmbus_info_set(int id, char *node, int value) +{ + char path[PSU_NODE_MAX_PATH_LEN] = {0}; + + switch (id) { + case PSU1_ID: + sprintf(path, "%s%s", PSU1_AC_PMBUS_PREFIX, node); + break; + case PSU2_ID: + sprintf(path, "%s%s", PSU2_AC_PMBUS_PREFIX, node); + break; + default: + return ONLP_STATUS_E_UNSUPPORTED; + }; + + if (onlp_file_write_integer(path, value) < 0) { + AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +#define PSU_SERIAL_NUMBER_LEN 19 + +int psu_serial_number_get(int id, char *serial, int serial_len) +{ + int size = 0; + int ret = ONLP_STATUS_OK; + char *prefix = NULL; + + if (serial == NULL || serial_len < PSU_SERIAL_NUMBER_LEN) { + return ONLP_STATUS_E_PARAM; + } + + prefix = (id == PSU1_ID) ? PSU1_AC_HWMON_PREFIX : PSU2_AC_HWMON_PREFIX; + + ret = onlp_file_read((uint8_t*)serial, PSU_SERIAL_NUMBER_LEN, &size, "%s%s", prefix, "psu_serial_number"); + if (ret != ONLP_STATUS_OK || size != PSU_SERIAL_NUMBER_LEN) { + return ONLP_STATUS_E_INTERNAL; + + } + serial[PSU_SERIAL_NUMBER_LEN-1] = '\0'; + + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/platform_lib.h b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/platform_lib.h new file mode 100644 index 0000000000..5eac7b2323 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/platform_lib.h @@ -0,0 +1,92 @@ +/************************************************************ + * + * + * 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 +#include "x86_64_accton_as4630_54npe_log.h" + +#define CHASSIS_FAN_COUNT 3 +#define CHASSIS_THERMAL_COUNT 4 +#define CHASSIS_PSU_COUNT 2 +#define CHASSIS_LED_COUNT 8 + +#define PSU1_ID 1 +#define PSU2_ID 2 + +#define PSU_NODE_MAX_INT_LEN 8 +#define PSU_NODE_MAX_PATH_LEN 64 + +#define PSU1_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/10-0058/" +#define PSU2_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/11-0059/" + + +#define PSU1_AC_PMBUS_NODE(node) PSU1_AC_PMBUS_PREFIX#node +#define PSU2_AC_PMBUS_NODE(node) PSU2_AC_PMBUS_PREFIX#node + +#define PSU1_AC_HWMON_PREFIX "/sys/bus/i2c/devices/10-0050/" +#define PSU2_AC_HWMON_PREFIX "/sys/bus/i2c/devices/11-0051/" + + + +#define PSU1_AC_HWMON_NODE(node) PSU1_AC_HWMON_PREFIX#node +#define PSU2_AC_HWMON_NODE(node) PSU2_AC_HWMON_PREFIX#node + +#define CPLD_NODE_PATH "/sys/bus/i2c/devices/i2c-3/3-0060/" +#define FAN_NODE(node) CPLD_NODE_PATH#node + +#define IDPROM_PATH "/sys/bus/i2c/devices/1-0057/eeprom" + +int onlp_file_write_integer(char *filename, int value); +int onlp_file_read_binary(char *filename, char *buffer, int buf_size, int data_len); +int onlp_file_read_string(char *filename, char *buffer, int buf_size, int data_len); + +int psu_pmbus_info_get(int id, char *node, int *value); +int psu_ym2651y_pmbus_info_get(int id, char *node, int *value); +int psu_ym2651y_pmbus_info_set(int id, char *node, int value); + +typedef enum psu_type { + PSU_TYPE_UNKNOWN, + PSU_TYPE_ACBEL, + PSU_TYPE_YM2651Y, + PSU_TYPE_YPEB1200A, + PSU_TYPE_AC_F2B, + PSU_TYPE_AC_B2F +} psu_type_t; + +psu_type_t get_psu_type(int id, char* modelname, int modelname_len); +int psu_serial_number_get(int id, char *serial, int serial_len); + +//#define DEBUG_MODE 1 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(format, ...) printf(format, __VA_ARGS__) +#else + #define DEBUG_PRINT(format, ...) +#endif + +#endif /* __PLATFORM_LIB_H__ */ + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/psui.c b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/psui.c new file mode 100644 index 0000000000..9b08dcba22 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/psui.c @@ -0,0 +1,245 @@ +/************************************************************ + * + * + * 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 "platform_lib.h" + +#define PSU_STATUS_PRESENT 1 +#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_status_info_get(int id, char *node, int *value) +{ + int ret = 0; + char path[PSU_NODE_MAX_PATH_LEN] = {0}; + + *value = 0; + + if (PSU1_ID == id) { + sprintf(path, "%s%s", PSU1_AC_HWMON_PREFIX, node); + } + else if (PSU2_ID == id) { + sprintf(path, "%s%s", PSU2_AC_HWMON_PREFIX, node); + } + if (onlp_file_read_int(value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ret; +} + +int +onlp_psui_init(void) +{ + return ONLP_STATUS_OK; +} + +static int +psu_ym2651y_info_get(onlp_psu_info_t* info) +{ + int val = 0; + int index = ONLP_OID_ID_GET(info->hdr.id); + + /* Set capability + */ + info->caps = ONLP_PSU_CAPS_AC; + + if (info->status & ONLP_PSU_STATUS_FAILED) { + return ONLP_STATUS_OK; + } + + /* Set the associated oid_table */ + info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); + info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT); + + /* Read voltage, current and power */ + if (psu_ym2651y_pmbus_info_get(index, "psu_v_out", &val) == 0) { + info->mvout = val; + info->caps |= ONLP_PSU_CAPS_VOUT; + } + + if (psu_ym2651y_pmbus_info_get(index, "psu_i_out", &val) == 0) { + info->miout = val; + info->caps |= ONLP_PSU_CAPS_IOUT; + } + + if (psu_ym2651y_pmbus_info_get(index, "psu_p_out", &val) == 0) { + info->mpout = val; + info->caps |= ONLP_PSU_CAPS_POUT; + } + + psu_serial_number_get(index, info->serial, sizeof(info->serial)); + + return ONLP_STATUS_OK; +} + + + +static int +psu_data_info_get(onlp_psu_info_t* info) +{ + int val = 0; + int index = ONLP_OID_ID_GET(info->hdr.id); + + /* Set capability + */ + info->caps = ONLP_PSU_CAPS_AC; + + if (info->status & ONLP_PSU_STATUS_FAILED) { + return ONLP_STATUS_OK; + } + + /* Set the associated oid_table */ + info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); + 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_out", &val) == 0) { + info->mvout = val; + info->caps |= ONLP_PSU_CAPS_VOUT; + } + + if (psu_pmbus_info_get(index, "psu_v_in", &val) == 0) { + info->mvin = val; + info->caps |= ONLP_PSU_CAPS_VIN; + } + + 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_i_in", &val) == 0) { + info->miin = val; + info->caps |= ONLP_PSU_CAPS_IIN; + } + + if (psu_pmbus_info_get(index, "psu_p_out", &val) == 0) { + info->mpout = val; + info->caps |= ONLP_PSU_CAPS_POUT; + } + + if (psu_pmbus_info_get(index, "psu_p_in", &val) == 0) { + info->mpin = val; + info->caps |= ONLP_PSU_CAPS_PIN; + } + psu_serial_number_get(index, info->serial, sizeof(info->serial)); + + 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 }, + } +}; + +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); + psu_type_t psu_type; + + VALIDATE(id); + + memset(info, 0, sizeof(onlp_psu_info_t)); + *info = pinfo[index]; /* Set the onlp_oid_hdr_t */ + /* Get the present state */ + if (psu_status_info_get(index, "psu_present", &val) != 0) { + AIM_LOG_ERROR("Unable to read PSU(%d) node(psu_present)\r\n", index); + } + + if (val != PSU_STATUS_PRESENT) { + info->status &= ~ONLP_PSU_STATUS_PRESENT; + return ONLP_STATUS_OK; + } + info->status |= ONLP_PSU_STATUS_PRESENT; + + + /* Get power good status */ + if (psu_status_info_get(index, "psu_power_good", &val) != 0) { + AIM_LOG_ERROR("Unable to read PSU(%d) node(psu_power_good)\r\n", index); + } + + if (val != PSU_STATUS_POWER_GOOD) { + info->status |= ONLP_PSU_STATUS_FAILED; + } + + /* Get PSU type + */ + psu_type = get_psu_type(index, info->model, sizeof(info->model)); + + + switch (psu_type) { + case PSU_TYPE_ACBEL: + ret = psu_data_info_get(info); + break; + case PSU_TYPE_YM2651Y: + case PSU_TYPE_YPEB1200A: + ret = psu_ym2651y_info_get(info); + break; + case PSU_TYPE_UNKNOWN: /* User insert a unknown PSU or unplugged.*/ + info->status |= ONLP_PSU_STATUS_UNPLUGGED; + info->status &= ~ONLP_PSU_STATUS_FAILED; + ret = ONLP_STATUS_OK; + break; + default: + ret = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + return ret; +} + +int +onlp_psui_ioctl(onlp_oid_t pid, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/sfpi.c b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/sfpi.c new file mode 100644 index 0000000000..11d549d109 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/sfpi.c @@ -0,0 +1,375 @@ +/************************************************************ + * + * + * 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_as4630_54npe_int.h" +#include "x86_64_accton_as4630_54npe_log.h" + +#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" +#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_present_%d" +#define MODULE_RXLOS_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_rx_los_%d" +#define MODULE_TXFAULT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_fault_%d" +#define MODULE_TXDISABLE_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_disable_%d" +#define MODULE_RESET_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_reset_%d" +#define MODULE_LPMODE_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_lpmode_%d" + +int sfp_map_bus[] ={18, 19, 20, 21, 22, 23}; + +/************************************************************ + * + * SFPI Entry Points + * + ***********************************************************/ + +int +onlp_sfpi_init(void) +{ + /* Called at initialization time */ + return ONLP_STATUS_OK; +} +int +onlp_sfpi_map_bus_index(int port) +{ + if(port < 0 || port >=54) + return ONLP_STATUS_E_INTERNAL; + return sfp_map_bus[port]; +} + +int +onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) +{ + /* + * Ports {48, 54} + */ + int p; + + for(p = 48; p < 54; 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; + int bus, addr; + + if(port <0 || port > 54) + return ONLP_STATUS_E_INTERNAL; + + if(port < 48) + return ONLP_STATUS_E_UNSUPPORTED; + + addr = 60; + bus = 3; + + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (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) +{ + int port; + int i = 0; + uint64_t presence_all = 0 ; + uint32_t present_bytes[6] = {0}; + + + for(port = 48; port < 54; port++) { + present_bytes[port - 48] = onlp_sfpi_is_present(port); + } + /* Convert to 64 bit integer in port order */ + for (i = 0 ; i < 6 ;i++) + presence_all |= (present_bytes[i] << i); + presence_all <<= 48; + /* 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) +{ + int i = 0; + uint64_t rx_los_all = 0 ; + int addr = 60; + int bus = 3; + int port, rxlos_bytes[4] = {0}; + + for(port = 49; port < 53 ; port++) + { + if (onlp_file_read_int(&rxlos_bytes[port-49], MODULE_RXLOS_FORMAT, bus, addr, port) < 0) + { + AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + } + /* Convert to 64 bit integer in port order */ + for (i = 0; i < 4 ; i++) + rx_los_all = (rx_los_all | ((rxlos_bytes[i]) << i)); + rx_los_all = (rx_los_all << 48); + /* Populate bitmap */ + for(i = 0; i < 64; 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; + if(port <0 || port >= 54) + return ONLP_STATUS_E_INTERNAL; + if(port < 48) + return ONLP_STATUS_E_UNSUPPORTED; + + memset(data, 0, 256); + + if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, onlp_sfpi_map_bus_index(port-48)) != 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}; + + if(port < 48) + return ONLP_STATUS_E_UNSUPPORTED; + sprintf(file, PORT_EEPROM_FORMAT, onlp_sfpi_map_bus_index(port-48)); + 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 = onlp_sfpi_map_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 = onlp_sfpi_map_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 = onlp_sfpi_map_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 = onlp_sfpi_map_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 addr = 60; + int bus = 3; + + switch(control) + { + case ONLP_SFP_CONTROL_TX_DISABLE: + { + if(port>=48 && port<=51) { + if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; + } + return ONLP_STATUS_E_UNSUPPORTED; + } + case ONLP_SFP_CONTROL_RESET: + { + if(port>=52 && port<=53) { + if (onlp_file_write_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; + } + return ONLP_STATUS_E_UNSUPPORTED; + } + case ONLP_SFP_CONTROL_LP_MODE: + { + if(port>=52 && port<=53) { + if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to write lpmode status to port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; + } + return ONLP_STATUS_E_UNSUPPORTED; + } + default: + break; + } + + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) +{ + int addr = 60; + int bus = 3; + + switch(control) + { + case ONLP_SFP_CONTROL_RX_LOS: + { + if(port>=48 && port<=51) { + if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; + } + return ONLP_STATUS_E_UNSUPPORTED; + } + + case ONLP_SFP_CONTROL_TX_FAULT: + { + if(port>=48 && port<=51) { + if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; + } + return ONLP_STATUS_E_UNSUPPORTED; + } + + case ONLP_SFP_CONTROL_TX_DISABLE: + { + if(port>=48 && port<=51) { + if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; + } + return ONLP_STATUS_E_UNSUPPORTED; + } + case ONLP_SFP_CONTROL_RESET: + { + if(port>=52 && port<=53) { + if (onlp_file_read_int(value, MODULE_RESET_FORMAT, bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; + } + return ONLP_STATUS_E_UNSUPPORTED; + + } + + case ONLP_SFP_CONTROL_LP_MODE: + { + if(port>=52 && port<=53) { + if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read lpmode status from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; + } + return ONLP_STATUS_E_UNSUPPORTED; + } + default: + break; + } + + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +onlp_sfpi_denit(void) +{ + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/sysi.c b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/sysi.c new file mode 100644 index 0000000000..7125b635d9 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/sysi.c @@ -0,0 +1,270 @@ +/************************************************************ + * + * + * 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 +#include +#include +#include "platform_lib.h" +#include "x86_64_accton_as4630_54npe_int.h" +#include "x86_64_accton_as4630_54npe_log.h" + + +#define PREFIX_PATH_ON_CPLD_DEV "/sys/bus/i2c/devices/3-0060/" + +#define NUM_OF_CPLD 3 +#define FAN_DUTY_CYCLE_MAX (100) +/* Note, all chassis fans share 1 single duty setting. + * Here use fan 1 to represent global fan duty value.*/ + +const char* +onlp_sysi_platform_get(void) +{ + return "x86-64-accton-as4630-54npe-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)); + + /* 6 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); + } + + /* 6 Fans on the chassis */ + for (i = 1; i <= CHASSIS_FAN_COUNT; i++) { + *e++ = ONLP_FAN_ID_CREATE(i); + } + + return 0; +} + +int +onlp_sysi_platform_info_get(onlp_platform_info_t* pi) +{ + int ver=0; + + if(onlp_file_read_int(&ver, "%s/version", PREFIX_PATH_ON_CPLD_DEV) < 0) + return ONLP_STATUS_E_INTERNAL; + + pi->cpld_versions = aim_fstrdup("%d", ver); + + return 0; +} + +void +onlp_sysi_platform_info_free(onlp_platform_info_t* pi) +{ + aim_free(pi->cpld_versions); +} + +/* Temperature Policy + * If any fan fail , please set fan speed register to 16 + * The max value of fan speed register is 14 + * LM77(48)+LM75(4B)+LM75(4A) > 140, Set 10 + * LM77(48)+LM75(4B)+LM75(4A) > 150, Set 12 + * LM77(48)+LM75(4B)+LM75(4A) > 160, Set 14 + * LM77(48)+LM75(4B)+LM75(4A) < 140, Set 8 + * LM77(48)+LM75(4B)+LM75(4A) < 150, Set 10 + * LM77(48)+LM75(4B)+LM75(4A) < 160, Set 12 + * Reset DUT:LM77(48)>=70C + */ + +typedef struct fan_ctrl_policy { + int duty_cycle; + int pwm; + int temp_down; /* The boundary temperature to down adjust fan speed */ + int temp_up; /* The boundary temperature to up adjust fan speed */ + int state; +} fan_ctrl_policy_t; + +enum +{ + LEVEL_FAN_MIN=0, + LEVEL_FAN_NORMAL, + LEVEL_FAN_MID, + LEVEL_FAN_HIGH, + LEVEL_TEMP_CRITICAL +}; + +fan_ctrl_policy_t fan_thermal_policy[] = { +{50, 8, 0, 140000, LEVEL_FAN_MIN}, +{62, 10, 140000, 150000, LEVEL_FAN_NORMAL}, +{75, 12, 150000, 160000, LEVEL_FAN_MID}, +{88, 14, 160000, 240000, LEVEL_FAN_HIGH}, +{100, 16, 240000, 300000, LEVEL_TEMP_CRITICAL }, +}; + +#define FAN_SPEED_CTRL_PATH "/sys/bus/i2c/devices/3-0060/fan_duty_cycle_percentage" +#define SHUTDOWN_DUT_CMD "i2cset -y -f 3 0x60 0x4 0xE4" + +static int fan_state=LEVEL_FAN_MIN; +static int fan_fail = 0; + +int onlp_sysi_platform_manage_fans(void) + { + int i=0, ori_state=LEVEL_FAN_MIN, current_state=LEVEL_FAN_MIN; + int fd, len; + int cur_duty_cycle, new_duty_cycle, temp=0; + onlp_thermal_info_t thermali[3]; + char buf[10] = {0}; + + /* Get current temperature + */ + for (i=0; i<3; i++) + { + if (onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(i+2), &thermali[i]) != ONLP_STATUS_OK ) + { + AIM_LOG_ERROR("Unable to read thermal status, set fans to 87 %% speed"); + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), fan_thermal_policy[LEVEL_FAN_HIGH].duty_cycle); + return ONLP_STATUS_E_INTERNAL; + } + temp+=thermali[i].mcelsius; + } + + + /* Get current fan pwm percent + */ + fd = open(FAN_SPEED_CTRL_PATH, O_RDONLY); + if (fd == -1){ + AIM_LOG_ERROR("Unable to open fan speed control node (%s)", FAN_SPEED_CTRL_PATH); + return ONLP_STATUS_E_INTERNAL; + } + len = read(fd, buf, sizeof(buf)); + close(fd); + if (len <= 0) { + AIM_LOG_ERROR("Unable to read fan speed from (%s)", FAN_SPEED_CTRL_PATH); + return ONLP_STATUS_E_INTERNAL; + } + cur_duty_cycle = atoi(buf); + ori_state=fan_state; + /* Inpunt temp to get theraml_polyc state and new pwm percent. */ + for(i=0; i < sizeof(fan_thermal_policy)/sizeof(fan_ctrl_policy_t); i++) + { + if (temp > fan_thermal_policy[i].temp_down) + { + if (temp <= fan_thermal_policy[i].temp_up) + { + current_state =i; + } + } + } + if(current_state > LEVEL_TEMP_CRITICAL || current_state < LEVEL_FAN_MIN) + { + AIM_LOG_ERROR("onlp_sysi_platform_manage_fans get error current_state\n"); + return 0; + } + /* Decision 3: Decide new fan pwm percent. + */ + if (fan_fail==0 &&cur_duty_cycle!=fan_thermal_policy[current_state].duty_cycle) + { + new_duty_cycle = fan_thermal_policy[current_state].duty_cycle; + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), new_duty_cycle); + } + /* Get each fan status + */ + for (i = 1; i <= CHASSIS_FAN_COUNT; i++) + { + onlp_fan_info_t fan_info; + if (onlp_fani_info_get(ONLP_FAN_ID_CREATE(i), &fan_info) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("Unable to get fan(%d) status, try to set the other fans as full speed\r\n", i); + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_CYCLE_MAX); + fan_fail=1; + break; + } + else + { + fan_fail = 0; + } + /* Decision 1: Set fan as full speed if any fan is failed. + */ + if (fan_info.status & ONLP_FAN_STATUS_FAILED || !(fan_info.status & ONLP_FAN_STATUS_PRESENT)) + { + AIM_LOG_ERROR("Fan(%d) is not working, set the other fans as full speed\r\n", i); + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_CYCLE_MAX); + fan_fail=1; + break; + } + else + { + fan_fail = 0; + } + } + if(thermali[2].mcelsius >= 70000) /*LM75-48*/ + { + /*critical case*/ + AIM_SYSLOG_CRIT("Temperature critical", "Temperature critical", "Alarm for temperature critical is detected, reset DUT"); + sleep(2); + system(SHUTDOWN_DUT_CMD); + } + if(current_state!=ori_state) + { + fan_state=current_state; + } + + return 0; +} +int +onlp_sysi_platform_manage_leds(void) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/thermali.c b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/thermali.c new file mode 100644 index 0000000000..6aad288f02 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/thermali.c @@ -0,0 +1,162 @@ +/************************************************************ + * + * + * 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 +#include "platform_lib.h" + +#define THERMAL_PATH_FORMAT "/sys/bus/i2c/devices/%s/*temp1_input" +#define PSU_THERMAL_PATH_FORMAT "/sys/bus/i2c/devices/%s/*psu_temp1_input" + + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_THERMAL(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +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_1_ON_PSU1, + THERMAL_1_ON_PSU2, +}; + +static char* directory[] = /* must map with onlp_thermal_id */ +{ + NULL, + NULL, /* CPU_CORE files */ + "24-004b", + "25-004a", + "14-0048", + "10-0058", + "11-0059", +}; + +static char* cpu_coretemp_files[] = + { + "/sys/devices/platform/coretemp.0*temp1_input", + "/sys/devices/platform/coretemp.0*temp4_input", + "/sys/devices/platform/coretemp.0*temp8_input", + "/sys/devices/platform/coretemp.0*temp10_input", + NULL, + }; + +/* Static values */ +static onlp_thermal_info_t linfo[] = { + { }, /* Not used */ + { { ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE), "CPU Core", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), "LM75-1-4B", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), "LM75-2-4A", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), "LM75-3-48", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + + { { 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, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { 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, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + } +}; + +/* + * 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; + char *format = NULL; + char path[64] = {0}; + VALIDATE(id); + + tid = ONLP_OID_ID_GET(id); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[tid]; + if(tid == THERMAL_CPU_CORE) { + return onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files); + } + + switch (tid) { + case THERMAL_1_ON_MAIN_BROAD: + case THERMAL_2_ON_MAIN_BROAD: + case THERMAL_3_ON_MAIN_BROAD: + format = THERMAL_PATH_FORMAT; + break; + case THERMAL_1_ON_PSU1: + case THERMAL_1_ON_PSU2: + format = PSU_THERMAL_PATH_FORMAT; + break; + default: + return ONLP_STATUS_E_INVALID; + }; + + /* get path */ + sprintf(path, format, directory[tid], tid); + if (onlp_file_read_int(&info->mcelsius, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_config.c b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_config.c new file mode 100644 index 0000000000..762f73adea --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_config.c @@ -0,0 +1,80 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* */ +#define __x86_64_accton_as4630_54npe_config_STRINGIFY_NAME(_x) #_x +#define __x86_64_accton_as4630_54npe_config_STRINGIFY_VALUE(_x) __x86_64_accton_as4630_54npe_config_STRINGIFY_NAME(_x) +x86_64_accton_as4630_54npe_config_settings_t x86_64_accton_as4630_54npe_config_settings[] = +{ +#ifdef X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_LOGGING + { __x86_64_accton_as4630_54npe_config_STRINGIFY_NAME(X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_LOGGING), __x86_64_accton_as4630_54npe_config_STRINGIFY_VALUE(X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_LOGGING) }, +#else +{ X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_LOGGING(__x86_64_accton_as4630_54npe_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_OPTIONS_DEFAULT + { __x86_64_accton_as4630_54npe_config_STRINGIFY_NAME(X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_accton_as4630_54npe_config_STRINGIFY_VALUE(X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_OPTIONS_DEFAULT) }, +#else +{ X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_accton_as4630_54npe_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_BITS_DEFAULT + { __x86_64_accton_as4630_54npe_config_STRINGIFY_NAME(X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_BITS_DEFAULT), __x86_64_accton_as4630_54npe_config_STRINGIFY_VALUE(X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_BITS_DEFAULT) }, +#else +{ X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_BITS_DEFAULT(__x86_64_accton_as4630_54npe_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __x86_64_accton_as4630_54npe_config_STRINGIFY_NAME(X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_accton_as4630_54npe_config_STRINGIFY_VALUE(X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#else +{ X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_accton_as4630_54npe_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB + { __x86_64_accton_as4630_54npe_config_STRINGIFY_NAME(X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB), __x86_64_accton_as4630_54npe_config_STRINGIFY_VALUE(X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB) }, +#else +{ X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_STDLIB(__x86_64_accton_as4630_54npe_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __x86_64_accton_as4630_54npe_config_STRINGIFY_NAME(X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_accton_as4630_54npe_config_STRINGIFY_VALUE(X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#else +{ X86_64_ACCTON_AS4630_54NPE_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_accton_as4630_54npe_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_UCLI + { __x86_64_accton_as4630_54npe_config_STRINGIFY_NAME(X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_UCLI), __x86_64_accton_as4630_54npe_config_STRINGIFY_VALUE(X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_UCLI) }, +#else +{ X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_UCLI(__x86_64_accton_as4630_54npe_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + { __x86_64_accton_as4630_54npe_config_STRINGIFY_NAME(X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_accton_as4630_54npe_config_STRINGIFY_VALUE(X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) }, +#else +{ X86_64_ACCTON_AS4630_54NPE_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_accton_as4630_54npe_config_STRINGIFY_NAME), "__undefined__" }, +#endif + { NULL, NULL } +}; +#undef __x86_64_accton_as4630_54npe_config_STRINGIFY_VALUE +#undef __x86_64_accton_as4630_54npe_config_STRINGIFY_NAME + +const char* +x86_64_accton_as4630_54npe_config_lookup(const char* setting) +{ + int i; + for(i = 0; x86_64_accton_as4630_54npe_config_settings[i].name; i++) { + if(!strcmp(x86_64_accton_as4630_54npe_config_settings[i].name, setting)) { + return x86_64_accton_as4630_54npe_config_settings[i].value; + } + } + return NULL; +} + +int +x86_64_accton_as4630_54npe_config_show(struct aim_pvs_s* pvs) +{ + int i; + for(i = 0; x86_64_accton_as4630_54npe_config_settings[i].name; i++) { + aim_printf(pvs, "%s = %s\n", x86_64_accton_as4630_54npe_config_settings[i].name, x86_64_accton_as4630_54npe_config_settings[i].value); + } + return i; +} + +/* */ diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_enums.c b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_enums.c new file mode 100644 index 0000000000..1040493705 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_enums.c @@ -0,0 +1,10 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.enum(ALL).source> */ +/* */ + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_int.h b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_int.h new file mode 100644 index 0000000000..1baaeef1cf --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_int.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * x86_64_accton_as4630_54npe Internal Header + * + *****************************************************************************/ +#ifndef __x86_64_accton_as4630_54npe_INT_H__ +#define __x86_64_accton_as4630_54npe_INT_H__ + +#include + + +#endif /* __x86_64_accton_as4630_54npe_INT_H__ */ diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_log.c b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_log.c new file mode 100644 index 0000000000..4482be4ceb --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_log.c @@ -0,0 +1,18 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as4630_54npe_log.h" +/* + * x86_64_accton_as4630_54npe log struct. + */ +AIM_LOG_STRUCT_DEFINE( + X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_OPTIONS_DEFAULT, + X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_BITS_DEFAULT, + NULL, /* Custom log map */ + X86_64_ACCTON_AS4630_54NPE_CONFIG_LOG_CUSTOM_BITS_DEFAULT + ); + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_log.h b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_log.h new file mode 100644 index 0000000000..dd0c0bae54 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_log.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#ifndef __x86_64_accton_as4630_54npe_LOG_H__ +#define __x86_64_accton_as4630_54npe_LOG_H__ + +#define AIM_LOG_MODULE_NAME x86_64_accton_as4630_54npe +#include + +#endif /* __x86_64_accton_as4630_54npe_LOG_H__ */ diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_module.c b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_module.c new file mode 100644 index 0000000000..afdb49dd43 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_module.c @@ -0,0 +1,24 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as4630_54npe_log.h" + +static int +datatypes_init__(void) +{ +#define x86_64_accton_as4630_54npe_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_as4630_54npe_module_init__(void) +{ + AIM_LOG_STRUCT_REGISTER(); + datatypes_init__(); +} + +int __onlp_platform_version__ = 1; diff --git a/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_ucli.c b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_ucli.c new file mode 100644 index 0000000000..a4ebf159e6 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/onlp/builds/x86_64_accton_as4630_54npe/module/src/x86_64_accton_as4630_54npe_ucli.c @@ -0,0 +1,50 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#if x86_64_accton_as4630_54npe_CONFIG_INCLUDE_UCLI == 1 + +#include +#include +#include + +static ucli_status_t +x86_64_accton_as4630_54npe_ucli_ucli__config__(ucli_context_t* uc) +{ + UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_accton_as4630_54npe) +} + +/* */ +/* */ + +static ucli_module_t +x86_64_accton_as4630_54npe_ucli_module__ = + { + "x86_64_accton_as4630_54npe_ucli", + NULL, + x86_64_accton_as4630_54npe_ucli_ucli_handlers__, + NULL, + NULL, + }; + +ucli_node_t* +x86_64_accton_as4630_54npe_ucli_node_create(void) +{ + ucli_node_t* n; + ucli_module_init(&x86_64_accton_as4630_54npe_ucli_module__); + n = ucli_node_create("x86_64_accton_as4630_54npe", NULL, &x86_64_accton_as4630_54npe_ucli_module__); + ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_accton_as4630_54npe")); + return n; +} + +#else +void* +x86_64_accton_as4630_54npe_ucli_node_create(void) +{ + return NULL; +} +#endif + diff --git a/packages/platforms/accton/x86-64/as4630-54npe/platform-config/Makefile b/packages/platforms/accton/x86-64/as4630-54npe/platform-config/Makefile new file mode 100644 index 0000000000..003238cf6d --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/platform-config/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/Makefile b/packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/Makefile new file mode 100644 index 0000000000..003238cf6d --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/PKG.yml b/packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/PKG.yml new file mode 100644 index 0000000000..8ad17488b0 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=accton BASENAME=x86-64-accton-as4630-54npe REVISION=r0 diff --git a/packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/src/lib/x86-64-accton-as4630-54npe-r0.yml b/packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/src/lib/x86-64-accton-as4630-54npe-r0.yml new file mode 100644 index 0000000000..1da9a5131e --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/src/lib/x86-64-accton-as4630-54npe-r0.yml @@ -0,0 +1,31 @@ +--- + +###################################################################### +# +# platform-config for AS4630 +# +###################################################################### + +x86-64-accton-as4630-54npe-r0: + + grub: + + serial: >- + --port=0x3f8 + --speed=115200 + --word=8 + --parity=no + --stop=1 + + kernel: + <<: *kernel-4-14 + + args: >- + nopat + console=ttyS0,115200n8 + intel_iommu=off + + network: + interfaces: + ma1: + name: eth2 diff --git a/packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/src/python/x86_64_accton_as4630_54npe_r0/__init__.py b/packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/src/python/x86_64_accton_as4630_54npe_r0/__init__.py new file mode 100644 index 0000000000..78d6541c78 --- /dev/null +++ b/packages/platforms/accton/x86-64/as4630-54npe/platform-config/r0/src/python/x86_64_accton_as4630_54npe_r0/__init__.py @@ -0,0 +1,56 @@ +from onl.platform.base import * +from onl.platform.accton import * + +class OnlPlatform_x86_64_accton_as4630_54npe_r0(OnlPlatformAccton, + OnlPlatformPortConfig_48x1_4x25_2x100): + + PLATFORM='x86-64-accton-as4630-54npe-r0' + MODEL="AS4630-54NPE" + SYS_OBJECT_ID=".4630.54" + + def baseconfig(self): + self.insmod('optoe') + self.insmod('ym2651y') + for m in [ 'cpld', 'psu', 'leds' ]: + self.insmod("x86-64-accton-as4630-54npe-%s.ko" % m) + + ########### initialize I2C bus 0 ########### + # initialize multiplexer (PCA9548) + self.new_i2c_device('pca9548', 0x77, 1) + + self.new_i2c_devices([ + # initialize multiplexer (PCA9548) + ('pca9548', 0x71, 2), + ('pca9548', 0x70, 3), + #initiate CPLD + ('as4630_54npe_cpld', 0x60, 3) + ]) + self.new_i2c_devices([ + # inititate LM77 + ('lm77', 0x48, 14), + # inititate LM75 + ('lm75', 0x4a, 25), + ('lm75', 0x4b, 24) + ]) + + self.new_i2c_devices([ + # initiate PSU-1 + ('as4630_54npe_psu1', 0x50, 10), + ('ype1200am', 0x58, 10), + # initiate PSU-2 + ('as4630_54npe_psu2', 0x51, 11), + ('ype1200am', 0x59, 11), + ]) + + # initialize SFP port 49~52 + for port in range(49, 53): + self.new_i2c_device('optoe2', 0x50, port-31) + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port-31), shell=True) + + # initialize SFP port 49~52 + for port in range(53, 55): + self.new_i2c_device('optoe1', 0x50, port-31) + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port-31), shell=True) + + self.new_i2c_device('24c02', 0x57, 1) + return True