Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The demo driver complies with s3ip sysfs specification,which use the … #12895

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions platform/s3ip-sysfs/demo_driver/cpld_device_driver.c
Original file line number Diff line number Diff line change
@@ -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 <linux/slab.h>

#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");
188 changes: 188 additions & 0 deletions platform/s3ip-sysfs/demo_driver/curr_sensor_device_driver.c
Original file line number Diff line number Diff line change
@@ -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 <linux/slab.h>

#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");
Loading