diff --git a/platform/s3ip-sysfs/demo_driver/cpld_device_driver.c b/platform/s3ip-sysfs/demo_driver/cpld_device_driver.c new file mode 100644 index 000000000000..db28c13e1e67 --- /dev/null +++ b/platform/s3ip-sysfs/demo_driver/cpld_device_driver.c @@ -0,0 +1,168 @@ +/* + * cpld_device_driver.c + * + * This module realize /sys/s3ip/cpld attributes read and write functions + * + * History + * [Version] [Date] [Description] + * * v1.0 2021-08-31 S3IP sysfs + */ + +#include + +#include "device_driver_common.h" +#include "cpld_sysfs.h" + +#define CPLD_INFO(fmt, args...) LOG_INFO("cpld: ", fmt, ##args) +#define CPLD_ERR(fmt, args...) LOG_ERR("cpld: ", fmt, ##args) +#define CPLD_DBG(fmt, args...) LOG_DBG("cpld: ", fmt, ##args) + +static int g_loglevel = 0; + +/******************************************CPLD***********************************************/ +static int demo_get_main_board_cpld_number(void) +{ + /* add vendor codes here */ + return 1; +} + +/* + * demo_get_main_board_cpld_alias - Used to identify the location of cpld, + * @cpld_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_cpld_alias(unsigned int cpld_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_cpld_type - Used to get cpld model name + * @cpld_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_cpld_type(unsigned int cpld_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_cpld_firmware_version - Used to get cpld firmware version, + * @cpld_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_cpld_firmware_version(unsigned int cpld_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_cpld_board_version - Used to get cpld board version, + * @cpld_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_cpld_board_version(unsigned int cpld_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_cpld_test_reg - Used to test cpld register read + * filled the value to buf, value is hexadecimal, start with 0x + * @cpld_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_cpld_test_reg(unsigned int cpld_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_main_board_cpld_test_reg - Used to test cpld register write + * @cpld_index: start with 1 + * @value: value write to cpld + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_main_board_cpld_test_reg(unsigned int cpld_index, unsigned int value) +{ + /* add vendor codes here */ + return -ENOSYS; +} +/***************************************end of CPLD*******************************************/ + +static struct s3ip_sysfs_cpld_drivers_s drivers = { + /* + * set ODM CPLD drivers to /sys/s3ip/cpld, + * if not support the function, set corresponding hook to NULL. + */ + .get_main_board_cpld_number = demo_get_main_board_cpld_number, + .get_main_board_cpld_alias = demo_get_main_board_cpld_alias, + .get_main_board_cpld_type = demo_get_main_board_cpld_type, + .get_main_board_cpld_firmware_version = demo_get_main_board_cpld_firmware_version, + .get_main_board_cpld_board_version = demo_get_main_board_cpld_board_version, + .get_main_board_cpld_test_reg = demo_get_main_board_cpld_test_reg, + .set_main_board_cpld_test_reg = demo_set_main_board_cpld_test_reg, +}; + +static int __init cpld_device_driver_init(void) +{ + int ret; + + CPLD_INFO("cpld_init...\n"); + + ret = s3ip_sysfs_cpld_drivers_register(&drivers); + if (ret < 0) { + CPLD_ERR("cpld drivers register err, ret %d.\n", ret); + return ret; + } + + CPLD_INFO("cpld_init success.\n"); + return 0; +} + +static void __exit cpld_device_driver_exit(void) +{ + s3ip_sysfs_cpld_drivers_unregister(); + CPLD_INFO("cpld_exit success.\n"); + return; +} + +module_init(cpld_device_driver_init); +module_exit(cpld_device_driver_exit); +module_param(g_loglevel, int, 0644); +MODULE_PARM_DESC(g_loglevel, "the log level(info=0x1, err=0x2, dbg=0x4, all=0xf).\n"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("sonic S3IP sysfs"); +MODULE_DESCRIPTION("cpld device driver"); diff --git a/platform/s3ip-sysfs/demo_driver/curr_sensor_device_driver.c b/platform/s3ip-sysfs/demo_driver/curr_sensor_device_driver.c new file mode 100644 index 000000000000..f5f7ffa53ef6 --- /dev/null +++ b/platform/s3ip-sysfs/demo_driver/curr_sensor_device_driver.c @@ -0,0 +1,188 @@ +/* + * curr_sensor_device_driver.c + * + * This module realize /sys/s3ip/curr_sensor attributes read and write functions + * + * History + * [Version] [Date] [Description] + * * v1.0 2021-08-31 S3IP sysfs + */ + +#include + +#include "device_driver_common.h" +#include "curr_sensor_sysfs.h" + +#define CURR_SENSOR_INFO(fmt, args...) LOG_INFO("curr_sensor: ", fmt, ##args) +#define CURR_SENSOR_ERR(fmt, args...) LOG_ERR("curr_sensor: ", fmt, ##args) +#define CURR_SENSOR_DBG(fmt, args...) LOG_DBG("curr_sensor: ", fmt, ##args) + +static int g_loglevel = 0; + +/*************************************main board current***************************************/ +static int demo_get_main_board_curr_number(void) +{ + /* add vendor codes here */ + return 1; +} + +/* + * demo_get_main_board_curr_alias - Used to identify the location of the current sensor, + * @curr_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_curr_alias(unsigned int curr_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_curr_type - Used to get the model of current sensor, + * @curr_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_curr_type(unsigned int curr_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_curr_max - Used to get the maximum threshold of current sensor + * filled the value to buf, and the value keep three decimal places + * @curr_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_curr_max(unsigned int curr_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_main_board_curr_max - Used to set the maximum threshold of current sensor + * get value from buf and set it to maximum threshold of current sensor + * @curr_index: start with 1 + * @buf: the buf store the data to be set + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_main_board_curr_max(unsigned int curr_index, const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_curr_min - Used to get the minimum threshold of current sensor + * filled the value to buf, and the value keep three decimal places + * @curr_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_curr_min(unsigned int curr_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_main_board_curr_min - Used to set the minimum threshold of current sensor + * get value from buf and set it to minimum threshold of current sensor + * @curr_index: start with 1 + * @buf: the buf store the data to be set, eg '50.000' + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_main_board_curr_min(unsigned int curr_index, const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_curr_value - Used to get the input value of current sensor + * filled the value to buf, and the value keep three decimal places + * @curr_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_curr_value(unsigned int curr_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} +/*********************************end of main board current************************************/ + +static struct s3ip_sysfs_curr_sensor_drivers_s drivers = { + /* + * set ODM current sensor drivers to /sys/s3ip/curr_sensor, + * if not support the function, set corresponding hook to NULL. + */ + .get_main_board_curr_number = demo_get_main_board_curr_number, + .get_main_board_curr_alias = demo_get_main_board_curr_alias, + .get_main_board_curr_type = demo_get_main_board_curr_type, + .get_main_board_curr_max = demo_get_main_board_curr_max, + .set_main_board_curr_max = demo_set_main_board_curr_max, + .get_main_board_curr_min = demo_get_main_board_curr_min, + .set_main_board_curr_min = demo_set_main_board_curr_min, + .get_main_board_curr_value = demo_get_main_board_curr_value, +}; + +static int __init curr_sensor_dev_drv_init(void) +{ + int ret; + + CURR_SENSOR_INFO("curr_sensor_init...\n"); + + ret = s3ip_sysfs_curr_sensor_drivers_register(&drivers); + if (ret < 0) { + CURR_SENSOR_ERR("curr sensor drivers register err, ret %d.\n", ret); + return ret; + } + + CURR_SENSOR_INFO("curr_sensor_init success.\n"); + return 0; +} + +static void __exit curr_sensor_dev_drv_exit(void) +{ + s3ip_sysfs_curr_sensor_drivers_unregister(); + CURR_SENSOR_INFO("curr_sensor_exit success.\n"); + return; +} + +module_init(curr_sensor_dev_drv_init); +module_exit(curr_sensor_dev_drv_exit); +module_param(g_loglevel, int, 0644); +MODULE_PARM_DESC(g_loglevel, "the log level(info=0x1, err=0x2, dbg=0x4, all=0xf).\n"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("sonic S3IP sysfs"); +MODULE_DESCRIPTION("current sensors device driver"); diff --git a/platform/s3ip-sysfs/demo_driver/fan_device_driver.c b/platform/s3ip-sysfs/demo_driver/fan_device_driver.c new file mode 100755 index 000000000000..17aa26a77f04 --- /dev/null +++ b/platform/s3ip-sysfs/demo_driver/fan_device_driver.c @@ -0,0 +1,372 @@ +/* + * fan_device_driver.c + * + * This module realize /sys/s3ip/fan attributes read and write functions + * + * History + * [Version] [Date] [Description] + * * v1.0 2021-08-31 S3IP sysfs + */ + +#include + +#include "device_driver_common.h" +#include "fan_sysfs.h" + +#define FAN_INFO(fmt, args...) LOG_INFO("fan: ", fmt, ##args) +#define FAN_ERR(fmt, args...) LOG_ERR("fan: ", fmt, ##args) +#define FAN_DBG(fmt, args...) LOG_DBG("fan: ", fmt, ##args) + +static int g_loglevel = 0; + +/********************************************fan**********************************************/ +static int demo_get_fan_number(void) +{ + /* add vendor codes here */ + return 1; +} + +static int demo_get_fan_motor_number(unsigned int fan_index) +{ + /* add vendor codes here */ + return 1; +} + +/* + * demo_get_fan_model_name - Used to get fan model name, + * @fan_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_fan_model_name(unsigned int fan_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_fan_serial_number - Used to get fan serial number, + * @fan_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_fan_serial_number(unsigned int fan_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_fan_part_number - Used to get fan part number, + * @fan_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_fan_part_number(unsigned int fan_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_fan_hardware_version - Used to get fan hardware version, + * @fan_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_fan_hardware_version(unsigned int fan_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_fan_status - Used to get fan status, + * filled the value to buf, fan status define as below: + * 0: ABSENT + * 1: OK + * 2: NOT OK + * + * @fan_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_fan_status(unsigned int fan_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_fan_led_status - Used to get fan led status + * filled the value to buf, led status value define as below: + * 0: dark + * 1: green + * 2: yellow + * 3: red + * 4:blue + * 5: green light flashing + * 6: yellow light flashing + * 7: red light flashing + * 8:blue light flashing + * + * @fan_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_fan_led_status(unsigned int fan_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_fan_led_status - Used to set fan led status + * @fan_index: start with 1 + * @status: led status, led status value define as below: + * 0: dark + * 1: green + * 2: yellow + * 3: red + * 4:blue + * 5: green light flashing + * 6: yellow light flashing + * 7: red light flashing + * 8:blue light flashing + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_fan_led_status(unsigned int fan_index, int status) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_fan_direction - Used to get fan air flow direction, + * filled the value to buf, air flow direction define as below: + * 0: F2B + * 1: B2F + * + * @fan_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_fan_direction(unsigned int fan_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_fan_motor_speed - Used to get fan motor speed + * filled the value to buf + * @fan_index: start with 1 + * @motor_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_fan_motor_speed(unsigned int fan_index, unsigned int motor_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_fan_motor_speed_tolerance - Used to get fan motor speed tolerance + * filled the value to buf + * @fan_index: start with 1 + * @motor_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_fan_motor_speed_tolerance(unsigned int fan_index, unsigned int motor_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_fan_motor_speed_target - Used to get fan motor speed target + * filled the value to buf + * @fan_index: start with 1 + * @motor_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_fan_motor_speed_target(unsigned int fan_index, unsigned int motor_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_fan_motor_speed_max - Used to get the maximum threshold of fan motor + * filled the value to buf + * @fan_index: start with 1 + * @motor_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_fan_motor_speed_max(unsigned int fan_index, unsigned int motor_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_fan_motor_speed_min - Used to get the minimum threshold of fan motor + * filled the value to buf + * @fan_index: start with 1 + * @motor_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_fan_motor_speed_min(unsigned int fan_index, unsigned int motor_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_fan_motor_ratio - Used to get the ratio of fan motor + * filled the value to buf + * @fan_index: start with 1 + * @motor_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_fan_ratio(unsigned int fan_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_fan_motor_ratio - Used to set the ratio of fan motor + * @fan_index: start with 1 + * @motor_index: start with 1 + * @ratio: motor speed ratio, from 0 to 100 + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_fan_ratio(unsigned int fan_index, int ratio) +{ + /* add vendor codes here */ + return -ENOSYS; +} +/****************************************end of fan*******************************************/ + +static struct s3ip_sysfs_fan_drivers_s drivers = { + /* + * set ODM fan drivers to /sys/s3ip/fan, + * if not support the function, set corresponding hook to NULL. + */ + .get_fan_number = demo_get_fan_number, + .get_fan_motor_number = demo_get_fan_motor_number, + .get_fan_model_name = demo_get_fan_model_name, + .get_fan_serial_number = demo_get_fan_serial_number, + .get_fan_part_number = demo_get_fan_part_number, + .get_fan_hardware_version = demo_get_fan_hardware_version, + .get_fan_status = demo_get_fan_status, + .get_fan_led_status = demo_get_fan_led_status, + .set_fan_led_status = demo_set_fan_led_status, + .get_fan_direction = demo_get_fan_direction, + .get_fan_motor_speed = demo_get_fan_motor_speed, + .get_fan_motor_speed_tolerance = demo_get_fan_motor_speed_tolerance, + .get_fan_motor_speed_target = demo_get_fan_motor_speed_target, + .get_fan_motor_speed_max = demo_get_fan_motor_speed_max, + .get_fan_motor_speed_min = demo_get_fan_motor_speed_min, + .get_fan_ratio = demo_get_fan_ratio, + .set_fan_ratio = demo_set_fan_ratio, +}; + +static int __init fan_dev_drv_init(void) +{ + int ret; + + FAN_INFO("fan_init...\n"); + + ret = s3ip_sysfs_fan_drivers_register(&drivers); + if (ret < 0) { + FAN_ERR("fan drivers register err, ret %d.\n", ret); + return ret; + } + + FAN_INFO("fan_init success.\n"); + return 0; +} + +static void __exit fan_dev_drv_exit(void) +{ + s3ip_sysfs_fan_drivers_unregister(); + FAN_INFO("fan_exit success.\n"); + return; +} + +module_init(fan_dev_drv_init); +module_exit(fan_dev_drv_exit); +module_param(g_loglevel, int, 0644); +MODULE_PARM_DESC(g_loglevel, "the log level(info=0x1, err=0x2, dbg=0x4, all=0xf).\n"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("sonic S3IP sysfs"); +MODULE_DESCRIPTION("fan device driver"); diff --git a/platform/s3ip-sysfs/demo_driver/fpga_device_driver.c b/platform/s3ip-sysfs/demo_driver/fpga_device_driver.c new file mode 100644 index 000000000000..819822af486d --- /dev/null +++ b/platform/s3ip-sysfs/demo_driver/fpga_device_driver.c @@ -0,0 +1,167 @@ +/* + * fpga_device_driver.c + * + * This module realize /sys/s3ip/fpga attributes read and write functions + * + * History + * [Version] [Date] [Description] + * * v1.0 2021-08-31 S3IP sysfs + */ + +#include + +#include "device_driver_common.h" +#include "fpga_sysfs.h" + +#define FPGA_INFO(fmt, args...) LOG_INFO("fpga: ", fmt, ##args) +#define FPGA_ERR(fmt, args...) LOG_ERR("fpga: ", fmt, ##args) +#define FPGA_DBG(fmt, args...) LOG_DBG("fpga: ", fmt, ##args) + +static int g_loglevel = 0; + +/******************************************FPGA***********************************************/ +static int demo_get_main_board_fpga_number(void) +{ + /* add vendor codes here */ + return 1; +} + +/* + * demo_get_main_board_fpga_alias - Used to identify the location of fpga, + * @fpga_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_fpga_alias(unsigned int fpga_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_fpga_type - Used to get fpga model name + * @fpga_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_fpga_type(unsigned int fpga_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_fpga_firmware_version - Used to get fpga firmware version, + * @fpga_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_fpga_firmware_version(unsigned int fpga_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_fpga_board_version - Used to get fpga board version, + * @fpga_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_fpga_board_version(unsigned int fpga_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_fpga_test_reg - Used to test fpga register read + * filled the value to buf, value is hexadecimal, start with 0x + * @fpga_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_fpga_test_reg(unsigned int fpga_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_main_board_fpga_test_reg - Used to test fpga register write + * @fpga_index: start with 1 + * @value: value write to fpga + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_main_board_fpga_test_reg(unsigned int fpga_index, unsigned int value) +{ + /* add vendor codes here */ + return -ENOSYS; +} +/***************************************end of FPGA*******************************************/ + +static struct s3ip_sysfs_fpga_drivers_s drivers = { + /* + * set ODM FPGA drivers to /sys/s3ip/fpga, + * if not support the function, set corresponding hook to NULL. + */ + .get_main_board_fpga_number = demo_get_main_board_fpga_number, + .get_main_board_fpga_alias = demo_get_main_board_fpga_alias, + .get_main_board_fpga_type = demo_get_main_board_fpga_type, + .get_main_board_fpga_firmware_version = demo_get_main_board_fpga_firmware_version, + .get_main_board_fpga_board_version = demo_get_main_board_fpga_board_version, + .get_main_board_fpga_test_reg = demo_get_main_board_fpga_test_reg, + .set_main_board_fpga_test_reg = demo_set_main_board_fpga_test_reg, +}; + +static int __init fpga_dev_drv_init(void) +{ + int ret; + + FPGA_INFO("fpga_init...\n"); + + ret = s3ip_sysfs_fpga_drivers_register(&drivers); + if (ret < 0) { + FPGA_ERR("fpga drivers register err, ret %d.\n", ret); + return ret; + } + FPGA_INFO("fpga_init success.\n"); + return 0; +} + +static void __exit fpga_dev_drv_exit(void) +{ + s3ip_sysfs_fpga_drivers_unregister(); + FPGA_INFO("fpga_exit success.\n"); + return; +} + +module_init(fpga_dev_drv_init); +module_exit(fpga_dev_drv_exit); +module_param(g_loglevel, int, 0644); +MODULE_PARM_DESC(g_loglevel, "the log level(info=0x1, err=0x2, dbg=0x4, all=0xf).\n"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("sonic S3IP sysfs"); +MODULE_DESCRIPTION("fpga device driver"); diff --git a/platform/s3ip-sysfs/demo_driver/include/device_driver_common.h b/platform/s3ip-sysfs/demo_driver/include/device_driver_common.h new file mode 100644 index 000000000000..6386d88fafe9 --- /dev/null +++ b/platform/s3ip-sysfs/demo_driver/include/device_driver_common.h @@ -0,0 +1,49 @@ +#ifndef _DEVICE_DRIVER_COMMON_H_ +#define _DEVICE_DRIVER_COMMON_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +enum LOG_LEVEL{ + INFO = 0x1, + ERR = 0x2, + DBG = 0x4, + ALL = 0xf +}; + +#define LOG_INFO(_prefix, fmt, args...) do { \ + if (g_loglevel & INFO) { \ + printk( KERN_INFO _prefix "%s "fmt, __FUNCTION__, ##args); \ + } \ +} while (0) + +#define LOG_ERR(_prefix, fmt, args...) do { \ + if (g_loglevel & ERR) { \ + printk( KERN_ERR _prefix "%s "fmt, __FUNCTION__, ##args); \ + } \ +} while (0) + +#define LOG_DBG(_prefix, fmt, args...) do { \ + if (g_loglevel & DBG) { \ + printk( KERN_DEBUG _prefix "%s "fmt, __FUNCTION__, ##args); \ + } \ +} while (0) + +#define check_pfun(p) do { \ + if (p == NULL) { \ + if (g_loglevel & ERR) { \ + printk( KERN_ERR "%s, %s is NULL.\n", __FUNCTION__, #p); \ + } \ + return -ENOSYS; \ + } \ +} while(0) + +#define check_p(p) check_pfun(p) + +#endif /* _DEVICE_DRIVER_COMMON_H_ */ diff --git a/platform/s3ip-sysfs/demo_driver/psu_device_driver.c b/platform/s3ip-sysfs/demo_driver/psu_device_driver.c new file mode 100644 index 000000000000..2f424b5498c1 --- /dev/null +++ b/platform/s3ip-sysfs/demo_driver/psu_device_driver.c @@ -0,0 +1,587 @@ +/* + * psu_device_driver.c + * + * This module realize /sys/s3ip/psu attributes read and write functions + * + * History + * [Version] [Date] [Description] + * * v1.0 2021-08-31 S3IP sysfs + */ + +#include + +#include "device_driver_common.h" +#include "psu_sysfs.h" + +#define PSU_INFO(fmt, args...) LOG_INFO("psu: ", fmt, ##args) +#define PSU_ERR(fmt, args...) LOG_ERR("psu: ", fmt, ##args) +#define PSU_DBG(fmt, args...) LOG_DBG("psu: ", fmt, ##args) + +static int g_loglevel = 0; + +/********************************************psu**********************************************/ +static int demo_get_psu_number(void) +{ + /* add vendor codes here */ + return 1; +} + +static int demo_get_psu_temp_number(unsigned int psu_index) +{ + /* add vendor codes here */ + return 1; +} + +/* + * demo_get_psu_model_name - Used to get psu model name, + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_model_name(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_serial_number - Used to get psu serial number, + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_serial_number(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_part_number - Used to get psu part number, + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_part_number(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_hardware_version - Used to get psu hardware version, + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_hardware_version(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_type - Used to get the input type of psu + * filled the value to buf, input type value define as below: + * 0: DC + * 1: AC + * + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_type(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_in_curr - Used to get the input current of psu + * filled the value to buf, and the value keep three decimal places + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_in_curr(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_in_vol - Used to get the input voltage of psu + * filled the value to buf, and the value keep three decimal places + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_in_vol(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_in_power - Used to get the input power of psu + * filled the value to buf, and the value keep three decimal places + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_in_power(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_out_curr - Used to get the output current of psu + * filled the value to buf, and the value keep three decimal places + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_out_curr(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_out_vol - Used to get the output voltage of psu + * filled the value to buf, and the value keep three decimal places + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_out_vol(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_out_power - Used to get the output power of psu + * filled the value to buf, and the value keep three decimal places + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_out_power(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_out_max_power - Used to get the output max power of psu + * filled the value to buf, and the value keep three decimal places + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_out_max_power(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_present_status - Used to get psu present status + * filled the value to buf, psu present status define as below: + * 0: ABSENT + * 1: PRESENT + * + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_present_status(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_in_status - Used to get psu input status + * filled the value to buf, psu input status define as below: + * 0: NOT OK + * 1: OK + * + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_in_status(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_out_status - Used to get psu output status + * filled the value to buf, psu output status define as below: + * 0: NOT OK + * 1: OK + * + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_out_status(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_fan_speed - Used to get psu fan speed + * filled the value to buf + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_fan_speed(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_fan_ratio - Used to get the ratio of psu fan + * filled the value to buf + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_fan_ratio(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_psu_fan_ratio - Used to set the ratio of psu fan + * @psu_index: start with 1 + * @ratio: from 0 to 100 + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_psu_fan_ratio(unsigned int psu_index, int ratio) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_fan_direction - Used to get psu air flow direction, + * filled the value to buf, air flow direction define as below: + * 0: F2B + * 1: B2F + * + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_fan_direction(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_led_status - Used to get psu led status + * filled the value to buf, led status value define as below: + * 0: dark + * 1: green + * 2: yellow + * 3: red + * 4:blue + * 5: green light flashing + * 6: yellow light flashing + * 7: red light flashing + * 8:blue light flashing + * + * @psu_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_led_status(unsigned int psu_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_temp_alias - Used to identify the location of the temperature sensor of psu, + * @psu_index: start with 1 + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_temp_alias(unsigned int psu_index, unsigned int temp_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_temp_type - Used to get the model of temperature sensor of psu, + * @psu_index: start with 1 + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_temp_type(unsigned int psu_index, unsigned int temp_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_temp_max - Used to get the maximum threshold of temperature sensor of psu, + * filled the value to buf, and the value keep three decimal places + * @psu_index: start with 1 + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_temp_max(unsigned int psu_index, unsigned int temp_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_psu_temp_max - Used to set the maximum threshold of temperature sensor of psu, + * get value from buf and set it to maximum threshold of psu temperature sensor + * @psu_index: start with 1 + * @temp_index: start with 1 + * @buf: the buf store the data to be set, eg '80.000' + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_psu_temp_max(unsigned int psu_index, unsigned int temp_index, + const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_temp_min - Used to get the minimum threshold of temperature sensor of psu, + * filled the value to buf, and the value keep three decimal places + * @psu_index: start with 1 + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_temp_min(unsigned int psu_index, unsigned int temp_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_psu_temp_min - Used to set the minimum threshold of temperature sensor of psu, + * get value from buf and set it to minimum threshold of psu temperature sensor + * @psu_index: start with 1 + * @temp_index: start with 1 + * @buf: the buf store the data to be set, eg '50.000' + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_psu_temp_min(unsigned int psu_index, unsigned int temp_index, + const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_psu_temp_value - Used to get the input value of temperature sensor of psu + * filled the value to buf, and the value keep three decimal places + * @psu_index: start with 1 + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_psu_temp_value(unsigned int psu_index, unsigned int temp_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} +/****************************************end of psu*******************************************/ + +static struct s3ip_sysfs_psu_drivers_s drivers = { + /* + * set ODM psu drivers to /sys/s3ip/psu, + * if not support the function, set corresponding hook to NULL. + */ + .get_psu_number = demo_get_psu_number, + .get_psu_temp_number = demo_get_psu_temp_number, + .get_psu_model_name = demo_get_psu_model_name, + .get_psu_serial_number = demo_get_psu_serial_number, + .get_psu_part_number = demo_get_psu_part_number, + .get_psu_hardware_version = demo_get_psu_hardware_version, + .get_psu_type = demo_get_psu_type, + .get_psu_in_curr = demo_get_psu_in_curr, + .get_psu_in_vol = demo_get_psu_in_vol, + .get_psu_in_power = demo_get_psu_in_power, + .get_psu_out_curr = demo_get_psu_out_curr, + .get_psu_out_vol = demo_get_psu_out_vol, + .get_psu_out_power = demo_get_psu_out_power, + .get_psu_out_max_power = demo_get_psu_out_max_power, + .get_psu_present_status = demo_get_psu_present_status, + .get_psu_in_status = demo_get_psu_in_status, + .get_psu_out_status = demo_get_psu_out_status, + .get_psu_fan_speed = demo_get_psu_fan_speed, + .get_psu_fan_ratio = demo_get_psu_fan_ratio, + .set_psu_fan_ratio = demo_set_psu_fan_ratio, + .get_psu_fan_direction = demo_get_psu_fan_direction, + .get_psu_led_status = demo_get_psu_led_status, + .get_psu_temp_alias = demo_get_psu_temp_alias, + .get_psu_temp_type = demo_get_psu_temp_type, + .get_psu_temp_max = demo_get_psu_temp_max, + .set_psu_temp_max = demo_set_psu_temp_max, + .get_psu_temp_min = demo_get_psu_temp_min, + .set_psu_temp_min = demo_set_psu_temp_min, + .get_psu_temp_value = demo_get_psu_temp_value, +}; + +static int __init psu_dev_drv_init(void) +{ + int ret; + + PSU_INFO("psu_init...\n"); + + ret = s3ip_sysfs_psu_drivers_register(&drivers); + if (ret < 0) { + PSU_ERR("psu drivers register err, ret %d.\n", ret); + return ret; + } + PSU_INFO("psu_init success.\n"); + return 0; +} + +static void __exit psu_dev_drv_exit(void) +{ + s3ip_sysfs_psu_drivers_unregister(); + PSU_INFO("psu_exit ok.\n"); + + return; +} + +module_init(psu_dev_drv_init); +module_exit(psu_dev_drv_exit); +module_param(g_loglevel, int, 0644); +MODULE_PARM_DESC(g_loglevel, "the log level(info=0x1, err=0x2, dbg=0x4, all=0xf).\n"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("sonic S3IP sysfs"); +MODULE_DESCRIPTION("psu device driver"); diff --git a/platform/s3ip-sysfs/demo_driver/slot_device_driver.c b/platform/s3ip-sysfs/demo_driver/slot_device_driver.c new file mode 100644 index 000000000000..dd924eb30012 --- /dev/null +++ b/platform/s3ip-sysfs/demo_driver/slot_device_driver.c @@ -0,0 +1,918 @@ +/* + * slot_device_driver.c + * + * This module realize /sys/s3ip/slot attributes read and write functions + * + * History + * [Version] [Date] [Description] + * * v1.0 2021-08-31 S3IP sysfs + */ + +#include + +#include "device_driver_common.h" +#include "slot_sysfs.h" + +#define SLOT_INFO(fmt, args...) LOG_INFO("slot: ", fmt, ##args) +#define SLOT_ERR(fmt, args...) LOG_ERR("slot: ", fmt, ##args) +#define SLOT_DBG(fmt, args...) LOG_DBG("slot: ", fmt, ##args) + +static int g_loglevel = 0; + +/******************************************slot***********************************************/ +static int demo_get_slot_number(void) +{ + /* add vendor codes here */ + return 1; +} + +static int demo_get_slot_temp_number(unsigned int slot_index) +{ + /* add vendor codes here */ + return 1; +} + +static int demo_get_slot_vol_number(unsigned int slot_index) +{ + /* add vendor codes here */ + return 1; +} + +static int demo_get_slot_curr_number(unsigned int slot_index) +{ + /* add vendor codes here */ + return 1; +} + +static int demo_get_slot_fpga_number(unsigned int slot_index) +{ + /* add vendor codes here */ + return 1; +} + +static int demo_get_slot_cpld_number(unsigned int slot_index) +{ + /* add vendor codes here */ + return 1; +} + +/* + * demo_get_slot_model_name - Used to get slot model name, + * @slot_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_model_name(unsigned int slot_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_serial_number - Used to get slot serial number, + * @slot_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_serial_number(unsigned int slot_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_part_number - Used to get slot part number, + * @slot_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_part_number(unsigned int slot_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_hardware_version - Used to get slot hardware version, + * @slot_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_hardware_version(unsigned int slot_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_status - Used to get slot status, + * filled the value to buf, slot status define as below: + * 0: ABSENT + * 1: OK + * 2: NOT OK + * + * @slot_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_status(unsigned int slot_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_led_status - Used to get slot led status + * filled the value to buf, led status value define as below: + * 0: dark + * 1: green + * 2: yellow + * 3: red + * 4:blue + * 5: green light flashing + * 6: yellow light flashing + * 7: red light flashing + * 8:blue light flashing + * + * @slot_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_led_status(unsigned int slot_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_slot_led_status - Used to set slot led status + * @slot_index: start with 1 + * @status: led status, led status value define as below: + * 0: dark + * 1: green + * 2: yellow + * 3: red + * 4:blue + * 5: green light flashing + * 6: yellow light flashing + * 7: red light flashing + * 8:blue light flashing + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_slot_led_status(unsigned int slot_index, int status) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_temp_alias - Used to identify the location of the temperature sensor of slot, + * @slot_index: start with 1 + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_temp_alias(unsigned int slot_index, unsigned int temp_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_temp_type - Used to get the model of temperature sensor of slot, + * @slot_index: start with 1 + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_temp_type(unsigned int slot_index, unsigned int temp_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; + +} + +/* + * demo_get_slot_temp_max - Used to get the maximum threshold of temperature sensor of slot, + * filled the value to buf, and the value keep three decimal places + * @slot_index: start with 1 + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_temp_max(unsigned int slot_index, unsigned int temp_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_slot_temp_max - Used to set the maximum threshold of temperature sensor of slot, + * get value from buf and set it to maximum threshold of slot temperature sensor + * @slot_index: start with 1 + * @temp_index: start with 1 + * @buf: the buf store the data to be set, eg '80.000' + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_slot_temp_max(unsigned int slot_index, unsigned int temp_index, + const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_temp_min - Used to get the minimum threshold of temperature sensor of slot, + * filled the value to buf, and the value keep three decimal places + * @slot_index: start with 1 + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_temp_min(unsigned int slot_index, unsigned int temp_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_slot_temp_min - Used to set the minimum threshold of temperature sensor of slot, + * get value from buf and set it to minimum threshold of slot temperature sensor + * @slot_index: start with 1 + * @temp_index: start with 1 + * @buf: the buf store the data to be set, eg '50.000' + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_slot_temp_min(unsigned int slot_index, unsigned int temp_index, + const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_temp_value - Used to get the input value of temperature sensor of slot, + * filled the value to buf, and the value keep three decimal places + * @slot_index: start with 1 + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_temp_value(unsigned int slot_index, unsigned int temp_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_vol_alias - Used to identify the location of the voltage sensor of slot, + * @slot_index: start with 1 + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_vol_alias(unsigned int slot_index, unsigned int vol_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_vol_type - Used to get the model of voltage sensor of slot, + * such as udc90160, tps53622 and so on + * @slot_index: start with 1 + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_vol_type(unsigned int slot_index, unsigned int vol_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; + +} + +/* + * demo_get_slot_vol_max - Used to get the maximum threshold of voltage sensor of slot, + * filled the value to buf, and the value keep three decimal places + * @slot_index: start with 1 + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_vol_max(unsigned int slot_index, unsigned int vol_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_slot_vol_max - Used to set the maximum threshold of volatge sensor of slot, + * get value from buf and set it to maximum threshold of volatge sensor + * @slot_index: start with 1 + * @vol_index: start with 1 + * @buf: the buf store the data to be set, eg '3.567' + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_slot_vol_max(unsigned int slot_index, unsigned int vol_index, + const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_vol_min - Used to get the minimum threshold of voltage sensor of slot, + * filled the value to buf, and the value keep three decimal places + * @slot_index: start with 1 + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_vol_min(unsigned int slot_index, unsigned int vol_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_slot_vol_min - Used to set the minimum threshold of voltage sensor of slot, + * get value from buf and set it to minimum threshold of voltage sensor + * @slot_index: start with 1 + * @temp_index: start with 1 + * @buf: the buf store the data to be set, eg '3.123' + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_slot_vol_min(unsigned int slot_index, unsigned int vol_index, + const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_vol_range - Used to get the output error value of voltage sensor of slot, + * filled the value to buf + * @slot_index: start with 1 + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_vol_range(unsigned int slot_index, unsigned int vol_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_vol_nominal_value - Used to get the nominal value of voltage sensor of slot, + * filled the value to buf + * @slot_index: start with 1 + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_vol_nominal_value(unsigned int slot_index, + unsigned int vol_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_vol_value - Used to get the input value of voltage sensor of slot, + * filled the value to buf, and the value keep three decimal places + * @slot_index: start with 1 + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_vol_value(unsigned int slot_index, unsigned int vol_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_curr_alias - Used to identify the location of the current sensor of slot, + * @slot_index: start with 1 + * @curr_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_curr_alias(unsigned int slot_index, unsigned int curr_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_curr_type - Used to get the model of current sensor of slot, + * @slot_index: start with 1 + * @curr_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_curr_type(unsigned int slot_index, unsigned int curr_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_curr_max - Used to get the maximum threshold of current sensor of slot, + * filled the value to buf, and the value keep three decimal places + * @slot_index: start with 1 + * @curr_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_curr_max(unsigned int slot_index, unsigned int curr_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_slot_curr_max - Used to set the maximum threshold of current sensor of slot, + * get value from buf and set it to maximum threshold of current sensor + * @slot_index: start with 1 + * @curr_index: start with 1 + * @buf: the buf store the data to be set + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_slot_curr_max(unsigned int slot_index, unsigned int curr_index, + const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_curr_min - Used to get the minimum threshold of current sensor of slot, + * filled the value to buf, and the value keep three decimal places + * @slot_index: start with 1 + * @curr_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_curr_min(unsigned int slot_index, unsigned int curr_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_slot_curr_min - Used to set the minimum threshold of current sensor of slot, + * get value from buf and set it to minimum threshold of current sensor + * @slot_index: start with 1 + * @curr_index: start with 1 + * @buf: the buf store the data to be set, eg '50.000' + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_slot_curr_min(unsigned int slot_index, unsigned int curr_index, + const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_curr_value - Used to get the input value of current sensor of slot, + * filled the value to buf, and the value keep three decimal places + * @slot_index: start with 1 + * @curr_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_curr_value(unsigned int slot_index, unsigned int curr_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_fpga_alias - Used to identify the location of slot fpga, + * @slot_index: start with 1 + * @fpga_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_fpga_alias(unsigned int slot_index, unsigned int fpga_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_fpga_type - Used to get slot fpga model name + * @slot_index: start with 1 + * @fpga_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_fpga_type(unsigned int slot_index, unsigned int fpga_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_fpga_firmware_version - Used to get slot fpga firmware version, + * @slot_index: start with 1 + * @fpga_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_fpga_firmware_version(unsigned int slot_index, unsigned int fpga_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_fpga_board_version - Used to get slot fpga board version, + * @slot_index: start with 1 + * @fpga_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_fpga_board_version(unsigned int slot_index, unsigned int fpga_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_fpga_test_reg - Used to test slot fpga register read + * filled the value to buf, value is hexadecimal, start with 0x + * @slot_index: start with 1 + * @fpga_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_fpga_test_reg(unsigned int slot_index, unsigned int fpga_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_slot_fpga_test_reg - Used to test slot fpga register write + * @slot_index: start with 1 + * @fpga_index: start with 1 + * @value: value write to slot fpga + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_slot_fpga_test_reg(unsigned int slot_index, unsigned int fpga_index, + unsigned int value) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_cpld_alias - Used to identify the location of slot cpld, + * @slot_index: start with 1 + * @cpld_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_cpld_alias(unsigned int slot_index, unsigned int cpld_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_cpld_type - Used to get slot cpld model name + * @slot_index: start with 1 + * @cpld_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_cpld_type(unsigned int slot_index, unsigned int cpld_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_cpld_firmware_version - Used to get slot cpld firmware version, + * @slot_index: start with 1 + * @cpld_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_cpld_firmware_version(unsigned int slot_index, unsigned int cpld_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_cpld_board_version - Used to get slot cpld board version, + * @slot_index: start with 1 + * @cpld_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_cpld_board_version(unsigned int slot_index, unsigned int cpld_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_slot_cpld_test_reg - Used to test slot cpld register read + * filled the value to buf, value is hexadecimal, start with 0x + * @slot_index: start with 1 + * @cpld_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_slot_cpld_test_reg(unsigned int slot_index, unsigned int cpld_index, + char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_slot_cpld_test_reg - Used to test slot cpld register write + * @slot_index: start with 1 + * @cpld_index: start with 1 + * @value: value write to slot cpld + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_slot_cpld_test_reg(unsigned int slot_index, unsigned int cpld_index, + unsigned int value) +{ + /* add vendor codes here */ + return -ENOSYS; +} +/***************************************end of slot*******************************************/ + +static struct s3ip_sysfs_slot_drivers_s drivers = { + /* + * set ODM slot drivers to /sys/s3ip/slot, + * if not support the function, set corresponding hook to NULL. + */ + .get_slot_number = demo_get_slot_number, + .get_slot_temp_number = demo_get_slot_temp_number, + .get_slot_vol_number = demo_get_slot_vol_number, + .get_slot_curr_number = demo_get_slot_curr_number, + .get_slot_cpld_number = demo_get_slot_cpld_number, + .get_slot_fpga_number = demo_get_slot_fpga_number, + .get_slot_model_name = demo_get_slot_model_name, + .get_slot_serial_number = demo_get_slot_serial_number, + .get_slot_part_number = demo_get_slot_part_number, + .get_slot_hardware_version = demo_get_slot_hardware_version, + .get_slot_status = demo_get_slot_status, + .get_slot_led_status = demo_get_slot_led_status, + .set_slot_led_status = demo_set_slot_led_status, + .get_slot_temp_alias = demo_get_slot_temp_alias, + .get_slot_temp_type = demo_get_slot_temp_type, + .get_slot_temp_max = demo_get_slot_temp_max, + .set_slot_temp_max = demo_set_slot_temp_max, + .get_slot_temp_min = demo_get_slot_temp_min, + .set_slot_temp_min = demo_set_slot_temp_min, + .get_slot_temp_value = demo_get_slot_temp_value, + .get_slot_vol_alias = demo_get_slot_vol_alias, + .get_slot_vol_type = demo_get_slot_vol_type, + .get_slot_vol_max = demo_get_slot_vol_max, + .set_slot_vol_max = demo_set_slot_vol_max, + .get_slot_vol_min = demo_get_slot_vol_min, + .set_slot_vol_min = demo_set_slot_vol_min, + .get_slot_vol_range = demo_get_slot_vol_range, + .get_slot_vol_nominal_value = demo_get_slot_vol_nominal_value, + .get_slot_vol_value = demo_get_slot_vol_value, + .get_slot_curr_alias = demo_get_slot_curr_alias, + .get_slot_curr_type = demo_get_slot_curr_type, + .get_slot_curr_max = demo_get_slot_curr_max, + .set_slot_curr_max = demo_set_slot_curr_max, + .get_slot_curr_min = demo_get_slot_curr_min, + .set_slot_curr_min = demo_set_slot_curr_min, + .get_slot_curr_value = demo_get_slot_curr_value, + .get_slot_fpga_alias = demo_get_slot_fpga_alias, + .get_slot_fpga_alias = demo_get_slot_fpga_alias, + .get_slot_fpga_type = demo_get_slot_fpga_type, + .get_slot_fpga_firmware_version = demo_get_slot_fpga_firmware_version, + .get_slot_fpga_board_version = demo_get_slot_fpga_board_version, + .get_slot_fpga_test_reg = demo_get_slot_fpga_test_reg, + .set_slot_fpga_test_reg = demo_set_slot_fpga_test_reg, + .get_slot_cpld_alias = demo_get_slot_cpld_alias, + .get_slot_cpld_type = demo_get_slot_cpld_type, + .get_slot_cpld_firmware_version = demo_get_slot_cpld_firmware_version, + .get_slot_cpld_board_version = demo_get_slot_cpld_board_version, + .get_slot_cpld_test_reg = demo_get_slot_cpld_test_reg, + .set_slot_cpld_test_reg = demo_set_slot_cpld_test_reg, +}; + +static int __init slot_dev_drv_init(void) +{ + int ret; + + SLOT_INFO("slot_init...\n"); + + ret = s3ip_sysfs_slot_drivers_register(&drivers); + if (ret < 0) { + SLOT_ERR("slot drivers register err, ret %d.\n", ret); + return ret; + } + SLOT_INFO("slot_init success.\n"); + return 0; +} + +static void __exit slot_dev_drv_exit(void) +{ + s3ip_sysfs_slot_drivers_unregister(); + SLOT_INFO("slot_exit success.\n"); + return; +} + +module_init(slot_dev_drv_init); +module_exit(slot_dev_drv_exit); +module_param(g_loglevel, int, 0644); +MODULE_PARM_DESC(g_loglevel, "the log level(info=0x1, err=0x2, dbg=0x4, all=0xf).\n"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("sonic S3IP sysfs"); +MODULE_DESCRIPTION("slot device driver"); diff --git a/platform/s3ip-sysfs/demo_driver/syseeprom_device_driver.c b/platform/s3ip-sysfs/demo_driver/syseeprom_device_driver.c new file mode 100644 index 000000000000..0ee7c6459a30 --- /dev/null +++ b/platform/s3ip-sysfs/demo_driver/syseeprom_device_driver.c @@ -0,0 +1,106 @@ +/* + * syseeprom_device_driver.c + * + * This module realize /sys/s3ip/syseeprom attributes read and write functions + * + * History + * [Version] [Date] [Description] + * * v1.0 2021-08-31 S3IP sysfs + */ + +#include + +#include "device_driver_common.h" +#include "syseeprom_sysfs.h" + +#define SYSE2_INFO(fmt, args...) LOG_INFO("syseeprom: ", fmt, ##args) +#define SYSE2_ERR(fmt, args...) LOG_ERR("syseeprom: ", fmt, ##args) +#define SYSE2_DBG(fmt, args...) LOG_DBG("syseeprom: ", fmt, ##args) + +static int g_loglevel = 0; + +/*****************************************syseeprom*******************************************/ +/* + * demo_get_syseeprom_size - Used to get syseeprom size + * + * This function returns the size of syseeprom by your switch, + * otherwise it returns a negative value on failed. + */ +static int demo_get_syseeprom_size(void) +{ + /* add vendor codes here */ + return 256; +} + +/* + * demo_read_syseeprom_data - Used to read syseeprom data, + * @buf: Data read buffer + * @offset: offset address to read syseeprom data + * @count: length of buf + * + * This function returns the length of the filled buffer, + * returns 0 means EOF, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_read_syseeprom_data(char *buf, loff_t offset, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_write_syseeprom_data - Used to write syseeprom data + * @buf: Data write buffer + * @offset: offset address to write syseeprom data + * @count: length of buf + * + * This function returns the written length of syseeprom, + * returns 0 means EOF, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_write_syseeprom_data(char *buf, loff_t offset, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} +/*************************************end of syseeprom****************************************/ + +static struct s3ip_sysfs_syseeprom_drivers_s drivers = { + /* + * set ODM syseeprom drivers to /sys/s3ip/syseeprom, + * if not support the function, set corresponding hook to NULL. + */ + .get_syseeprom_size = demo_get_syseeprom_size, + .read_syseeprom_data = demo_read_syseeprom_data, + .write_syseeprom_data = demo_write_syseeprom_data, +}; + +static int __init syseeprom_dev_drv_init(void) +{ + int ret; + + SYSE2_INFO("syseeprom_dev_drv_init...\n"); + + ret = s3ip_sysfs_syseeprom_drivers_register(&drivers); + if (ret < 0) { + SYSE2_ERR("syseeprom drivers register err, ret %d.\n", ret); + return ret; + } + SYSE2_INFO("syseeprom_dev_drv_init success.\n"); + return 0; +} + +static void __exit syseeprom_dev_drv_exit(void) +{ + s3ip_sysfs_syseeprom_drivers_unregister(); + SYSE2_INFO("syseeprom_exit success.\n"); + return; +} + +module_init(syseeprom_dev_drv_init); +module_exit(syseeprom_dev_drv_exit); +module_param(g_loglevel, int, 0644); +MODULE_PARM_DESC(g_loglevel, "the log level(info=0x1, err=0x2, dbg=0x4, all=0xf).\n"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("sonic S3IP sysfs"); +MODULE_DESCRIPTION("syseeprom device driver"); diff --git a/platform/s3ip-sysfs/demo_driver/sysled_device_driver.c b/platform/s3ip-sysfs/demo_driver/sysled_device_driver.c new file mode 100644 index 000000000000..69ae1628f50d --- /dev/null +++ b/platform/s3ip-sysfs/demo_driver/sysled_device_driver.c @@ -0,0 +1,175 @@ +/* + * sysled_device_driver.c + * + * This module realize /sys/s3ip/sysled attributes read and write functions + * + * History + * [Version] [Date] [Description] + * * v1.0 2021-08-31 S3IP sysfs + */ + +#include + +#include "device_driver_common.h" +#include "sysled_sysfs.h" + +#define SYSLED_INFO(fmt, args...) LOG_INFO("sysled: ", fmt, ##args) +#define SYSLED_ERR(fmt, args...) LOG_ERR("sysled: ", fmt, ##args) +#define SYSLED_DBG(fmt, args...) LOG_DBG("sysled: ", fmt, ##args) + +static int g_loglevel = 0; + +/*****************************************sysled**********************************************/ +/* + * demo_get_sys_led_status - Used to get sys led status + * filled the value to buf, led status value define as below: + * 0: dark + * 1: green + * 2: yellow + * 3: red + * 4:blue + * 5: green light flashing + * 6: yellow light flashing + * 7: red light flashing + * 8:blue light flashing + * + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_sys_led_status(char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_sys_led_status - Used to set sys led status + * @status: led status, led status value define as below: + * 0: dark + * 1: green + * 2: yellow + * 3: red + * 4:blue + * 5: green light flashing + * 6: yellow light flashing + * 7: red light flashing + * 8:blue light flashing + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_sys_led_status(int status) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* Similar to demo_get_sys_led_status */ +static ssize_t demo_get_bmc_led_status(char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* Similar to demo_set_sys_led_status */ +static int demo_set_bmc_led_status(int status) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* Similar to demo_get_sys_led_status */ +static ssize_t demo_get_sys_fan_led_status(char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* Similar to demo_set_sys_led_status */ +static int demo_set_sys_fan_led_status(int status) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* Similar to demo_get_sys_led_status */ +static ssize_t demo_get_sys_psu_led_status(char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* Similar to demo_set_sys_led_status */ +static int demo_set_sys_psu_led_status(int status) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* Similar to demo_get_sys_led_status */ +static ssize_t demo_get_id_led_status(char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* Similar to demo_set_sys_led_status */ +static int demo_set_id_led_status(int status) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/**************************************end of sysled******************************************/ + +static struct s3ip_sysfs_sysled_drivers_s drivers = { + /* + * set ODM sysled drivers to /sys/s3ip/sysled, + * if not support the function, set corresponding hook to NULL. + */ + .get_sys_led_status = demo_get_sys_led_status, + .set_sys_led_status = demo_set_sys_led_status, + .get_bmc_led_status = demo_get_bmc_led_status, + .set_bmc_led_status = demo_set_bmc_led_status, + .get_sys_fan_led_status = demo_get_sys_fan_led_status, + .set_sys_fan_led_status = demo_set_sys_fan_led_status, + .get_sys_psu_led_status = demo_get_sys_psu_led_status, + .set_sys_psu_led_status = demo_set_sys_psu_led_status, + .get_id_led_status = demo_get_id_led_status, + .set_id_led_status = demo_set_id_led_status, +}; + +static int __init sysled_init(void) +{ + int ret; + + SYSLED_INFO("sysled_init...\n"); + + ret = s3ip_sysfs_sysled_drivers_register(&drivers); + if (ret < 0) { + SYSLED_ERR("sysled drivers register err, ret %d.\n", ret); + return ret; + } + + SYSLED_INFO("sysled create success.\n"); + return 0; +} + +static void __exit sysled_exit(void) +{ + s3ip_sysfs_sysled_drivers_unregister(); + SYSLED_INFO("sysled_exit ok.\n"); + return; +} + +module_init(sysled_init); +module_exit(sysled_exit); +module_param(g_loglevel, int, 0644); +MODULE_PARM_DESC(g_loglevel, "the log level(info=0x1, err=0x2, dbg=0x4, all=0xf).\n"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("sonic S3IP sysfs"); +MODULE_DESCRIPTION("sysled device driver"); diff --git a/platform/s3ip-sysfs/demo_driver/temp_sensor_device_driver.c b/platform/s3ip-sysfs/demo_driver/temp_sensor_device_driver.c new file mode 100644 index 000000000000..e49887f2ee59 --- /dev/null +++ b/platform/s3ip-sysfs/demo_driver/temp_sensor_device_driver.c @@ -0,0 +1,196 @@ +/* + * temp_sensor_device_driver.c + * + * This module realize /sys/s3ip/temp_sensor attributes read and write functions + * + * History + * [Version] [Date] [Description] + * * v1.0 2021-08-31 S3IP sysfs + */ + +#include + +#include "device_driver_common.h" +#include "temp_sensor_sysfs.h" + +#define TEMP_SENSOR_INFO(fmt, args...) LOG_INFO("temp_sensor: ", fmt, ##args) +#define TEMP_SENSOR_ERR(fmt, args...) LOG_ERR("temp_sensor: ", fmt, ##args) +#define TEMP_SENSOR_DBG(fmt, args...) LOG_DBG("temp_sensor: ", fmt, ##args) + +static int g_loglevel = 0; + +/***************************************main board temp*****************************************/ +/* + * demo_get_main_board_temp_number - Used to get main board temperature sensors number, + * + * This function returns main board temperature sensors by your switch, + * If there is no main board temperature sensors, returns 0, + * otherwise it returns a negative value on failed. + */ +static int demo_get_main_board_temp_number(void) +{ + /* add vendor codes here */ + return 1; +} + +/* + * demo_get_main_board_temp_alias - Used to identify the location of the temperature sensor, + * such as air_inlet, air_outlet and so on. + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_temp_alias(unsigned int temp_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_temp_type - Used to get the model of temperature sensor, + * such as lm75, tmp411 and so on + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_temp_type(unsigned int temp_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_temp_max - Used to get the maximum threshold of temperature sensor + * filled the value to buf, and the value keep three decimal places + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_temp_max(unsigned int temp_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_main_board_temp_max - Used to set the maximum threshold of temperature sensor + * get value from buf and set it to maximum threshold of temperature sensor + * @temp_index: start with 1 + * @buf: the buf store the data to be set, eg '80.000' + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_main_board_temp_max(unsigned int temp_index, const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_temp_min - Used to get the minimum threshold of temperature sensor + * filled the value to buf, and the value keep three decimal places + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_temp_min(unsigned int temp_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_main_board_temp_min - Used to set the minimum threshold of temperature sensor + * get value from buf and set it to minimum threshold of temperature sensor + * @temp_index: start with 1 + * @buf: the buf store the data to be set, eg '50.000' + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_main_board_temp_min(unsigned int temp_index, const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_temp_value - Used to get the input value of temperature sensor + * filled the value to buf, and the value keep three decimal places + * @temp_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_temp_value(unsigned int temp_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} +/***********************************end of main board temp*************************************/ + +static struct s3ip_sysfs_temp_sensor_drivers_s drivers = { + /* + * set ODM temperature sensor drivers to /sys/s3ip/temp_sensor, + * if not support the function, set corresponding hook to NULL. + */ + .get_main_board_temp_number = demo_get_main_board_temp_number, + .get_main_board_temp_alias = demo_get_main_board_temp_alias, + .get_main_board_temp_type = demo_get_main_board_temp_type, + .get_main_board_temp_max = demo_get_main_board_temp_max, + .set_main_board_temp_max = demo_set_main_board_temp_max, + .get_main_board_temp_min = demo_get_main_board_temp_min, + .set_main_board_temp_min = demo_set_main_board_temp_min, + .get_main_board_temp_value = demo_get_main_board_temp_value, +}; + +static int __init temp_sensor_dev_drv_init(void) +{ + int ret; + + TEMP_SENSOR_INFO("temp_sensor_init...\n"); + + ret = s3ip_sysfs_temp_sensor_drivers_register(&drivers); + if (ret < 0) { + TEMP_SENSOR_ERR("temp sensor drivers register err, ret %d.\n", ret); + return ret; + } + TEMP_SENSOR_INFO("temp_sensor_init success.\n"); + return 0; +} + +static void __exit temp_sensor_dev_drv_exit(void) +{ + s3ip_sysfs_temp_sensor_drivers_unregister(); + TEMP_SENSOR_INFO("temp_sensor_exit success.\n"); + return; +} + +module_init(temp_sensor_dev_drv_init); +module_exit(temp_sensor_dev_drv_exit); +module_param(g_loglevel, int, 0644); +MODULE_PARM_DESC(g_loglevel, "the log level(info=0x1, err=0x2, dbg=0x4, all=0xf).\n"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("sonic S3IP sysfs"); +MODULE_DESCRIPTION("temperature sensors device driver"); diff --git a/platform/s3ip-sysfs/demo_driver/transceiver_device_driver.c b/platform/s3ip-sysfs/demo_driver/transceiver_device_driver.c new file mode 100644 index 000000000000..b89e1d7aa5b3 --- /dev/null +++ b/platform/s3ip-sysfs/demo_driver/transceiver_device_driver.c @@ -0,0 +1,335 @@ +/* + * transceiver_device_driver.c + * + * This module realize /sys/s3ip/transceiver attributes read and write functions + * + * History + * [Version] [Date] [Description] + * * v1.0 2021-08-31 S3IP sysfs + */ + +#include + +#include "device_driver_common.h" +#include "transceiver_sysfs.h" + +#define SFF_INFO(fmt, args...) LOG_INFO("sff: ", fmt, ##args) +#define SFF_ERR(fmt, args...) LOG_ERR("sff: ", fmt, ##args) +#define SFF_DBG(fmt, args...) LOG_DBG("sff: ", fmt, ##args) + +static int g_loglevel = 0; + +/****************************************transceiver******************************************/ +static int demo_get_eth_number(void) +{ + /* add vendor codes here */ + return 1; +} + +/* + * demo_get_transceiver_power_on_status - Used to get the whole machine port power on status, + * filled the value to buf, 0: power off, 1: power on + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_transceiver_power_on_status(char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_transceiver_power_on_status - Used to set the whole machine port power on status, + * @status: power on status, 0: power off, 1: power on + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_transceiver_power_on_status(int status) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_eth_power_on_status - Used to get single port power on status, + * filled the value to buf, 0: power off, 1: power on + * @eth_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_eth_power_on_status(unsigned int eth_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_eth_power_on_status - Used to set single port power on status, + * @eth_index: start with 1 + * @status: power on status, 0: power off, 1: power on + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_eth_power_on_status(unsigned int eth_index, int status) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_eth_tx_fault_status - Used to get port tx_fault status, + * filled the value to buf, 0: normal, 1: abnormal + * @eth_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_eth_tx_fault_status(unsigned int eth_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_eth_tx_disable_status - Used to get port tx_disable status, + * filled the value to buf, 0: tx_enable, 1: tx_disable + * @eth_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_eth_tx_disable_status(unsigned int eth_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_eth_tx_disable_status - Used to set port tx_disable status, + * @eth_index: start with 1 + * @status: tx_disable status, 0: tx_enable, 1: tx_disable + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_eth_tx_disable_status(unsigned int eth_index, int status) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_eth_present_status - Used to get port present status, + * filled the value to buf, 1: present, 0: absent + * @eth_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_eth_present_status(unsigned int eth_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_eth_rx_los_status - Used to get port rx_los status, + * filled the value to buf, 0: normal, 1: abnormal + * @eth_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_eth_rx_los_status(unsigned int eth_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_eth_reset_status - Used to get port reset status, + * filled the value to buf, 0: unreset, 1: reset + * @eth_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_eth_reset_status(unsigned int eth_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_eth_reset_status - Used to set port reset status, + * @eth_index: start with 1 + * @status: reset status, 0: unreset, 1: reset + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_eth_reset_status(unsigned int eth_index, int status) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_eth_low_power_mode_status - Used to get port low power mode status, + * filled the value to buf, 0: high power mode, 1: low power mode + * @eth_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_eth_low_power_mode_status(unsigned int eth_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_eth_interrupt_status - Used to get port interruption status, + * filled the value to buf, 0: no interruption, 1: interruption + * @eth_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_eth_interrupt_status(unsigned int eth_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_eth_eeprom_size - Used to get port eeprom size + * + * This function returns the size of port eeprom, + * otherwise it returns a negative value on failed. + */ +static int demo_get_eth_eeprom_size(unsigned int eth_index) +{ + /* add vendor codes here */ + return 0x8180; +} + +/* + * demo_read_eth_eeprom_data - Used to read port eeprom data, + * @buf: Data read buffer + * @offset: offset address to read port eeprom data + * @count: length of buf + * + * This function returns the length of the filled buffer, + * returns 0 means EOF, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_read_eth_eeprom_data(unsigned int eth_index, char *buf, loff_t offset, + size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_write_eth_eeprom_data - Used to write port eeprom data + * @buf: Data write buffer + * @offset: offset address to write port eeprom data + * @count: length of buf + * + * This function returns the written length of port eeprom, + * returns 0 means EOF, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_write_eth_eeprom_data(unsigned int eth_index, char *buf, loff_t offset, + size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} +/************************************end of transceiver***************************************/ + +static struct s3ip_sysfs_transceiver_drivers_s drivers = { + /* + * set ODM transceiver drivers to /sys/s3ip/transceiver, + * if not support the function, set corresponding hook to NULL. + */ + .get_eth_number = demo_get_eth_number, + .get_transceiver_power_on_status = demo_get_transceiver_power_on_status, + .set_transceiver_power_on_status = demo_set_transceiver_power_on_status, + .get_eth_power_on_status = demo_get_eth_power_on_status, + .set_eth_power_on_status = demo_set_eth_power_on_status, + .get_eth_tx_fault_status = demo_get_eth_tx_fault_status, + .get_eth_tx_disable_status = demo_get_eth_tx_disable_status, + .set_eth_tx_disable_status = demo_set_eth_tx_disable_status, + .get_eth_present_status = demo_get_eth_present_status, + .get_eth_rx_los_status = demo_get_eth_rx_los_status, + .get_eth_reset_status = demo_get_eth_reset_status, + .set_eth_reset_status = demo_set_eth_reset_status, + .get_eth_low_power_mode_status = demo_get_eth_low_power_mode_status, + .get_eth_interrupt_status = demo_get_eth_interrupt_status, + .get_eth_eeprom_size = demo_get_eth_eeprom_size, + .read_eth_eeprom_data = demo_read_eth_eeprom_data, + .write_eth_eeprom_data = demo_write_eth_eeprom_data, +}; + +static int __init sff_dev_drv_init(void) +{ + int ret; + + SFF_INFO("sff_init...\n"); + + ret = s3ip_sysfs_sff_drivers_register(&drivers); + if (ret < 0) { + SFF_ERR("transceiver drivers register err, ret %d.\n", ret); + return ret; + } + SFF_INFO("sff_init success.\n"); + return 0; +} + +static void __exit sff_dev_drv_exit(void) +{ + s3ip_sysfs_sff_drivers_unregister(); + SFF_INFO("sff_exit success.\n"); + return; +} + +module_init(sff_dev_drv_init); +module_exit(sff_dev_drv_exit); +module_param(g_loglevel, int, 0644); +MODULE_PARM_DESC(g_loglevel, "the log level(info=0x1, err=0x2, dbg=0x4, all=0xf).\n"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("sonic S3IP sysfs"); +MODULE_DESCRIPTION("transceiver device driver"); diff --git a/platform/s3ip-sysfs/demo_driver/vol_sensor_device_driver.c b/platform/s3ip-sysfs/demo_driver/vol_sensor_device_driver.c new file mode 100644 index 000000000000..1c2b2fa7af59 --- /dev/null +++ b/platform/s3ip-sysfs/demo_driver/vol_sensor_device_driver.c @@ -0,0 +1,224 @@ +/* + * vol_sensor_device_driver.c + * + * This module realize /sys/s3ip/vol_sensor attributes read and write functions + * + * History + * [Version] [Date] [Description] + * * v1.0 2021-08-31 S3IP sysfs + */ + +#include + +#include "device_driver_common.h" +#include "vol_sensor_sysfs.h" + +#define VOL_SENSOR_INFO(fmt, args...) LOG_INFO("vol_sensor: ", fmt, ##args) +#define VOL_SENSOR_ERR(fmt, args...) LOG_ERR("vol_sensor: ", fmt, ##args) +#define VOL_SENSOR_DBG(fmt, args...) LOG_DBG("vol_sensor: ", fmt, ##args) + +static int g_loglevel = 0; + +/*************************************main board voltage***************************************/ +static int demo_get_main_board_vol_number(void) +{ + /* add vendor codes here */ + return 1; +} + +/* + * demo_get_main_board_vol_alias - Used to identify the location of the voltage sensor, + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_vol_alias(unsigned int vol_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_vol_type - Used to get the model of voltage sensor, + * such as udc90160, tps53622 and so on + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_vol_type(unsigned int vol_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_vol_max - Used to get the maximum threshold of voltage sensor + * filled the value to buf, and the value keep three decimal places + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_vol_max(unsigned int vol_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_main_board_vol_max - Used to set the maximum threshold of volatge sensor + * get value from buf and set it to maximum threshold of volatge sensor + * @vol_index: start with 1 + * @buf: the buf store the data to be set, eg '3.567' + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_main_board_vol_max(unsigned int vol_index, const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_vol_min - Used to get the minimum threshold of voltage sensor + * filled the value to buf, and the value keep three decimal places + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_vol_min(unsigned int vol_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_main_board_vol_min - Used to set the minimum threshold of voltage sensor + * get value from buf and set it to minimum threshold of voltage sensor + * @temp_index: start with 1 + * @buf: the buf store the data to be set, eg '3.123' + * @count: length of buf + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_main_board_vol_min(unsigned int vol_index, const char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_vol_range - Used to get the output error value of voltage sensor + * filled the value to buf + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_vol_range(unsigned int vol_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_vol_nominal_value - Used to get the nominal value of voltage sensor + * filled the value to buf + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * if not support this attributes filled "NA" to buf, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_vol_nominal_value(unsigned int vol_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_main_board_vol_value - Used to get the input value of voltage sensor + * filled the value to buf, and the value keep three decimal places + * @vol_index: start with 1 + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_main_board_vol_value(unsigned int vol_index, char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} +/*********************************end of main board voltage************************************/ + +static struct s3ip_sysfs_vol_sensor_drivers_s drivers = { + /* + * set ODM voltage sensor drivers to /sys/s3ip/vol_sensor, + * if not support the function, set corresponding hook to NULL. + */ + .get_main_board_vol_number = demo_get_main_board_vol_number, + .get_main_board_vol_alias = demo_get_main_board_vol_alias, + .get_main_board_vol_type = demo_get_main_board_vol_type, + .get_main_board_vol_max = demo_get_main_board_vol_max, + .set_main_board_vol_max = demo_set_main_board_vol_max, + .get_main_board_vol_min = demo_get_main_board_vol_min, + .set_main_board_vol_min = demo_set_main_board_vol_min, + .get_main_board_vol_range = demo_get_main_board_vol_range, + .get_main_board_vol_nominal_value = demo_get_main_board_vol_nominal_value, + .get_main_board_vol_value = demo_get_main_board_vol_value, +}; + +static int __init vol_sensor_dev_drv_init(void) +{ + int ret; + + VOL_SENSOR_INFO("vol_sensor_init...\n"); + + ret = s3ip_sysfs_vol_sensor_drivers_register(&drivers); + if (ret < 0) { + VOL_SENSOR_ERR("vol sensor drivers register err, ret %d.\n", ret); + return ret; + } + VOL_SENSOR_INFO("vol_sensor_init success.\n"); + return 0; +} + +static void __exit vol_sensor_dev_drv_exit(void) +{ + s3ip_sysfs_vol_sensor_drivers_unregister(); + VOL_SENSOR_INFO("vol_sensor_exit success.\n"); + return; +} + +module_init(vol_sensor_dev_drv_init); +module_exit(vol_sensor_dev_drv_exit); +module_param(g_loglevel, int, 0644); +MODULE_PARM_DESC(g_loglevel, "the log level(info=0x1, err=0x2, dbg=0x4, all=0xf).\n"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("sonic S3IP sysfs"); +MODULE_DESCRIPTION("voltage sensors device driver"); diff --git a/platform/s3ip-sysfs/demo_driver/watchdog_device_driver.c b/platform/s3ip-sysfs/demo_driver/watchdog_device_driver.c new file mode 100755 index 000000000000..2cb5852a9908 --- /dev/null +++ b/platform/s3ip-sysfs/demo_driver/watchdog_device_driver.c @@ -0,0 +1,166 @@ +/* + * watchdog_device_driver.c + * + * This module realize /sys/s3ip/watchdog attributes read and write functions + * + * History + * [Version] [Date] [Description] + * * v1.0 2021-08-31 S3IP sysfs + */ + +#include + +#include "device_driver_common.h" +#include "watchdog_sysfs.h" + +#define WDT_INFO(fmt, args...) LOG_INFO("watchdog: ", fmt, ##args) +#define WDT_ERR(fmt, args...) LOG_ERR("watchdog: ", fmt, ##args) +#define WDT_DBG(fmt, args...) LOG_DBG("watchdog: ", fmt, ##args) + +static int g_loglevel = 0; + +/****************************************watchdog*********************************************/ +/* + * demo_get_watchdog_identify - Used to get watchdog identify, such as iTCO_wdt + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_watchdog_identify(char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_watchdog_timeleft - Used to get watchdog timeleft, + * filled the value to buf + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_watchdog_timeleft(char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_watchdog_timeout - Used to get watchdog timeout, + * filled the value to buf + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_watchdog_timeout(char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_watchdog_timeout - Used to set watchdog timeout, + * @value: timeout value + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_watchdog_timeout(int value) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_watchdog_enable_status - Used to get watchdog enable status, + * filled the value to buf, 0: disable, 1: enable + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * otherwise it returns a negative value on failed. + */ +static ssize_t demo_get_watchdog_enable_status(char *buf, size_t count) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_set_watchdog_enable_status - Used to set watchdog enable status, + * @value: enable status value, 0: disable, 1: enable + * + * This function returns 0 on success, + * otherwise it returns a negative value on failed. + */ +static int demo_set_watchdog_enable_status(int value) +{ + /* add vendor codes here */ + return -ENOSYS; +} + +/* + * demo_get_watchdog_state - Used to get watchdog state, + * filled the value to buf, 0: inactive, 1: active + * @buf: Data receiving buffer + * @count: length of buf + * + * This function returns the length of the filled buffer, + * otherwise it returns a negative value on failed. + */ +static int demo_set_watchdog_reset(int value) +{ + /* add vendor codes here */ + return -ENOSYS; +} +/*************************************end of watchdog*****************************************/ + +static struct s3ip_sysfs_watchdog_drivers_s drivers = { + /* + * set ODM watchdog sensor drivers to /sys/s3ip/watchdog, + * if not support the function, set corresponding hook to NULL. + */ + .get_watchdog_identify = demo_get_watchdog_identify, + .get_watchdog_timeleft = demo_get_watchdog_timeleft, + .get_watchdog_timeout = demo_get_watchdog_timeout, + .set_watchdog_timeout = demo_set_watchdog_timeout, + .get_watchdog_enable_status = demo_get_watchdog_enable_status, + .set_watchdog_enable_status = demo_set_watchdog_enable_status, + .set_watchdog_reset = demo_set_watchdog_reset, +}; + +static int __init watchdog_dev_drv_init(void) +{ + int ret; + + WDT_INFO("watchdog_init...\n"); + + ret = s3ip_sysfs_watchdog_drivers_register(&drivers); + if (ret < 0) { + WDT_ERR("watchdog drivers register err, ret %d.\n", ret); + return ret; + } + WDT_INFO("watchdog create success.\n"); + return 0; +} + +static void __exit watchdog_dev_drv_exit(void) +{ + s3ip_sysfs_watchdog_drivers_unregister(); + WDT_INFO("watchdog_exit success.\n"); + return; +} + +module_init(watchdog_dev_drv_init); +module_exit(watchdog_dev_drv_exit); +module_param(g_loglevel, int, 0644); +MODULE_PARM_DESC(g_loglevel, "the log level(info=0x1, err=0x2, dbg=0x4, all=0xf).\n"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("sonic S3IP sysfs"); +MODULE_DESCRIPTION("watchdog device driver");