Skip to content

Commit

Permalink
[Edgecore][as4224/as4564] Modify fan driver to support sensors command
Browse files Browse the repository at this point in the history
Currently, fan information is not shown with the 'sensors' command.
This patch will migrate the fan folder under 'hwmon',
so that sensors can detect the fan and display its information.

sensors output:
as4224_fan-isa-0000
Adapter: ISA adapter
fan1:        8587 RPM  (min =    0 RPM, max = 20500 RPM)
fan2:        8667 RPM  (min =    0 RPM, max = 20500 RPM)
fan3:        8667 RPM  (min =    0 RPM, max = 20500 RPM)
fan4:        8587 RPM  (min =    0 RPM, max = 20500 RPM)
fan5:        8746 RPM  (min =    0 RPM, max = 20500 RPM)
fan6:        8746 RPM  (min =    0 RPM, max = 20500 RPM)

as4564_fan-isa-0000
Adapter: ISA adapter
fan1:        1470 RPM  (min =    0 RPM, max = 10670 RPM)
fan2:        1510 RPM  (min =    0 RPM, max = 10670 RPM)

Changes are listed below:
- Add min/max fan attributes
- Create sysfs attributes under hwmon folder
- Modify fani.c/sysi.c accordingly

Signed-off-by: Brandon Chuang <[email protected]>
  • Loading branch information
brandonchuang committed Jun 1, 2023
1 parent d97c46b commit 9f33fed
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ onlp_fani_get_fan_attr_int(int fid, char *fmt, int *value)
{
char attr_name[32] = {0};
sprintf(attr_name, fmt, fid);
return onlp_file_read_int(value, "%s%s", FAN_SYSFS_PATH, attr_name);
return onlp_file_read_int(value, "%s*%s", FAN_SYSFS_PATH, attr_name);
}

int
onlp_fani_set_fan_attr_int(int fid, char *fmt, int value)
{
char attr_name[32] = {0};
sprintf(attr_name, fmt, fid);
return onlp_file_write_int(value, "%s%s", FAN_SYSFS_PATH, attr_name);
return onlp_file_write_int(value, "%s*%s", FAN_SYSFS_PATH, attr_name);
}

static int
Expand Down Expand Up @@ -125,7 +125,7 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info)

/* get speed percentage from rpm
*/
ret = onlp_file_read_int(&value, "%s%s", FAN_SYSFS_PATH, "fan_max_rpm");
ret = onlp_file_read_int(&value, "%s*%s", FAN_SYSFS_PATH, "fan_max_rpm");
if (ret < 0) {
return ONLP_STATUS_E_INTERNAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int platform_fan_count(void)
{
int ret = 0;
int value = 0;
ret = onlp_file_read_int(&value, "%s%s", FAN_SYSFS_PATH, "fan_count");
ret = onlp_file_read_int(&value, "%s*%s", FAN_SYSFS_PATH, "fan_count");
return (ret < 0) ? 0 : value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ sysi_fanctrl_thermal_sensor_policy(onlp_fan_info_t fi[MAX_CHASSIS_FAN_COUNT],

*adjusted = 0;

if (onlp_file_read_int(&fanduty, "%s%s", FAN_SYSFS_PATH, "fan2_duty_cycle_percentage") < 0) {
if (onlp_file_read_int(&fanduty, "%s*%s", FAN_SYSFS_PATH, "fan2_duty_cycle_percentage") < 0) {
*adjusted = 1;
return sysi_fanctrl_fan_set_duty(FAN_DUTY_MAX, num_of_fan);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ enum sysfs_fan_attributes {
FAN5_FAULT,
FAN6_FAULT,
FAN_MAX_RPM,
FAN1_SPEED_MAX,
FAN2_SPEED_MAX,
FAN3_SPEED_MAX,
FAN4_SPEED_MAX,
FAN5_SPEED_MAX,
FAN6_SPEED_MAX,
FAN1_SPEED_MIN,
FAN2_SPEED_MIN,
FAN3_SPEED_MIN,
FAN4_SPEED_MIN,
FAN5_SPEED_MIN,
FAN6_SPEED_MIN,
FAN_COUNT,
WTD_CLOCK,
WTD_COUNTER,
Expand Down Expand Up @@ -151,18 +163,24 @@ static struct attribute *fan_attributes_common[] = {
#define FAN_ATTRS_COMMON() { .attrs = fan_attributes_common }

#define FAN_ATTRS(fid) \
static SENSOR_DEVICE_ATTR(fan##fid##_duty_cycle_percentage, \
S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, \
FAN##fid##_PWM); \
static SENSOR_DEVICE_ATTR(fan##fid##_input, S_IRUGO, fan_show_value, \
NULL, FAN##fid##_SPEED_RPM); \
static SENSOR_DEVICE_ATTR(fan##fid##_fault, S_IRUGO, fan_show_value, \
NULL, FAN##fid##_FAULT); \
static struct attribute *fan_attributes##fid[] = { \
&sensor_dev_attr_fan##fid##_duty_cycle_percentage.dev_attr.attr, \
&sensor_dev_attr_fan##fid##_input.dev_attr.attr, \
&sensor_dev_attr_fan##fid##_fault.dev_attr.attr, \
NULL \
static SENSOR_DEVICE_ATTR(fan##fid##_duty_cycle_percentage, \
S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, \
FAN##fid##_PWM); \
static SENSOR_DEVICE_ATTR(fan##fid##_input, S_IRUGO, fan_show_value, \
NULL, FAN##fid##_SPEED_RPM); \
static SENSOR_DEVICE_ATTR(fan##fid##_fault, S_IRUGO, fan_show_value, \
NULL, FAN##fid##_FAULT); \
static SENSOR_DEVICE_ATTR(fan##fid##_max, S_IRUGO, fan_show_value, \
NULL, FAN##fid##_SPEED_MAX); \
static SENSOR_DEVICE_ATTR(fan##fid##_min, S_IRUGO, fan_show_value, \
NULL, FAN##fid##_SPEED_MIN); \
static struct attribute *fan_attributes##fid[] = { \
&sensor_dev_attr_fan##fid##_duty_cycle_percentage.dev_attr.attr, \
&sensor_dev_attr_fan##fid##_input.dev_attr.attr, \
&sensor_dev_attr_fan##fid##_fault.dev_attr.attr, \
&sensor_dev_attr_fan##fid##_max.dev_attr.attr, \
&sensor_dev_attr_fan##fid##_min.dev_attr.attr, \
NULL \
}

FAN_ATTRS(1);
Expand Down Expand Up @@ -293,8 +311,22 @@ static ssize_t fan_show_value(struct device *dev, struct device_attribute *da,
is_fan_fault(data, attr->index - FAN1_FAULT));
break;
case FAN_MAX_RPM:
case FAN1_SPEED_MAX:
case FAN2_SPEED_MAX:
case FAN3_SPEED_MAX:
case FAN4_SPEED_MAX:
case FAN5_SPEED_MAX:
case FAN6_SPEED_MAX:
ret = sprintf(buf, "%d\n", MAX_FAN_SPEED_RPM);
break;
case FAN1_SPEED_MIN:
case FAN2_SPEED_MIN:
case FAN3_SPEED_MIN:
case FAN4_SPEED_MIN:
case FAN5_SPEED_MIN:
case FAN6_SPEED_MIN:
ret = sprintf(buf, "0\n");
break;
case FAN_COUNT:
ret = sprintf(buf, "%d\n", data->fan_count);
break;
Expand Down Expand Up @@ -510,23 +542,31 @@ static int as4224_fan_probe(struct platform_device *pdev)
int status = -1;
int i = 0;

data->hwmon_dev = hwmon_device_register_with_info(&pdev->dev,
DRVNAME, NULL, NULL, NULL);
if (IS_ERR(data->hwmon_dev)) {
status = PTR_ERR(data->hwmon_dev);
return status;
}

/* Register sysfs hooks */
for (i = 0; i < (data->fan_count + 1); i++) {
/* Register sysfs hooks */
status = sysfs_create_group(&pdev->dev.kobj, &fan_group[i]);
status = sysfs_create_group(&data->hwmon_dev->kobj, &fan_group[i]);
if (status) {
goto exit;
}
}

dev_info(&pdev->dev, "device created\n");

return 0;

exit:
for (--i; i >= 0; i--) {
sysfs_remove_group(&pdev->dev.kobj, &fan_group[i]);
}

hwmon_device_unregister(data->hwmon_dev);
return status;
}

Expand All @@ -538,6 +578,7 @@ static int as4224_fan_remove(struct platform_device *pdev)
sysfs_remove_group(&pdev->dev.kobj, &fan_group[i]);
}

hwmon_device_unregister(data->hwmon_dev);
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ enum sysfs_fan_attributes {
FAN1_FAULT,
FAN2_FAULT,
FAN_MAX_RPM,
FAN1_SPEED_MAX,
FAN2_SPEED_MAX,
FAN1_SPEED_MIN,
FAN2_SPEED_MIN,
WTD_CLOCK,
WTD_COUNTER,
WTD_ENABLE,
Expand Down Expand Up @@ -123,17 +127,23 @@ static struct attribute *fan_attributes_common[] = {
#define FAN_ATTRS_COMMON() { .attrs = fan_attributes_common }

#define FAN_ATTRS(fid) \
static SENSOR_DEVICE_ATTR(fan##fid##_pwm, \
S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, \
FAN##fid##_PWM); \
static SENSOR_DEVICE_ATTR(fan##fid##_input, S_IRUGO, fan_show_value, \
NULL, FAN##fid##_SPEED_RPM); \
static SENSOR_DEVICE_ATTR(fan##fid##_fault, S_IRUGO, fan_show_value, \
NULL, FAN##fid##_FAULT); \
static struct attribute *fan_attributes##fid[] = { \
&sensor_dev_attr_fan##fid##_pwm.dev_attr.attr, \
&sensor_dev_attr_fan##fid##_input.dev_attr.attr, \
&sensor_dev_attr_fan##fid##_fault.dev_attr.attr, \
static SENSOR_DEVICE_ATTR(fan##fid##_pwm, \
S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, \
FAN##fid##_PWM); \
static SENSOR_DEVICE_ATTR(fan##fid##_input, S_IRUGO, fan_show_value, \
NULL, FAN##fid##_SPEED_RPM); \
static SENSOR_DEVICE_ATTR(fan##fid##_fault, S_IRUGO, fan_show_value, \
NULL, FAN##fid##_FAULT); \
static SENSOR_DEVICE_ATTR(fan##fid##_max, S_IRUGO, fan_show_value, \
NULL, FAN##fid##_SPEED_MAX); \
static SENSOR_DEVICE_ATTR(fan##fid##_min, S_IRUGO, fan_show_value, \
NULL, FAN##fid##_SPEED_MIN); \
static struct attribute *fan_attributes##fid[] = { \
&sensor_dev_attr_fan##fid##_pwm.dev_attr.attr, \
&sensor_dev_attr_fan##fid##_input.dev_attr.attr, \
&sensor_dev_attr_fan##fid##_fault.dev_attr.attr, \
&sensor_dev_attr_fan##fid##_max.dev_attr.attr, \
&sensor_dev_attr_fan##fid##_min.dev_attr.attr, \
NULL \
}

Expand Down Expand Up @@ -242,8 +252,14 @@ static ssize_t fan_show_value(struct device *dev, struct device_attribute *da,
is_fan_fault(data, attr->index - FAN1_FAULT));
break;
case FAN_MAX_RPM:
case FAN1_SPEED_MAX:
case FAN2_SPEED_MAX:
ret = sprintf(buf, "%d\n", MAX_FAN_SPEED_RPM);
break;
case FAN1_SPEED_MIN:
case FAN2_SPEED_MIN:
ret = sprintf(buf, "0\n");
break;
default:
break;
}
Expand Down Expand Up @@ -440,23 +456,31 @@ static int as4564_fan_probe(struct platform_device *pdev)
int status = -1;
int i = 0;

data->hwmon_dev = hwmon_device_register_with_info(&pdev->dev,
DRVNAME, NULL, NULL, NULL);
if (IS_ERR(data->hwmon_dev)) {
status = PTR_ERR(data->hwmon_dev);
return status;
}

/* Register sysfs hooks */
for (i = 0; i < ARRAY_SIZE(fan_group); i++) {
/* Register sysfs hooks */
status = sysfs_create_group(&pdev->dev.kobj, &fan_group[i]);
status = sysfs_create_group(&data->hwmon_dev->kobj, &fan_group[i]);
if (status) {
goto exit;
}
}

dev_info(&pdev->dev, "device created\n");

return 0;

exit:
for (--i; i >= 0; i--) {
sysfs_remove_group(&pdev->dev.kobj, &fan_group[i]);
}

hwmon_device_unregister(data->hwmon_dev);
return status;
}

Expand All @@ -468,6 +492,7 @@ static int as4564_fan_remove(struct platform_device *pdev)
sysfs_remove_group(&pdev->dev.kobj, &fan_group[i]);
}

hwmon_device_unregister(data->hwmon_dev);
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ onlp_fani_get_fan_attr_int(int fid, char *fmt, int *value)
{
char attr_name[32] = {0};
sprintf(attr_name, fmt, fid);
return onlp_file_read_int(value, "%s%s", FAN_SYSFS_PATH, attr_name);
return onlp_file_read_int(value, "%s*%s", FAN_SYSFS_PATH, attr_name);
}

int
onlp_fani_set_fan_attr_int(int fid, char *fmt, int value)
{
char attr_name[32] = {0};
sprintf(attr_name, fmt, fid);
return onlp_file_write_int(value, "%s%s", FAN_SYSFS_PATH, attr_name);
return onlp_file_write_int(value, "%s*%s", FAN_SYSFS_PATH, attr_name);
}

static int
Expand Down Expand Up @@ -119,7 +119,7 @@ _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info)

/* get speed percentage from rpm
*/
ret = onlp_file_read_int(&value, "%s%s", FAN_SYSFS_PATH, "fan_max_rpm");
ret = onlp_file_read_int(&value, "%s*%s", FAN_SYSFS_PATH, "fan_max_rpm");
if (ret < 0) {
return ONLP_STATUS_E_INTERNAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ sysi_fanctrl_thermal_sensor_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT],

*adjusted = 0;

if (onlp_file_read_int(&fanduty, "%s%s", FAN_SYSFS_PATH, "fan1_pwm") < 0) {
if (onlp_file_read_int(&fanduty, "%s*%s", FAN_SYSFS_PATH, "fan1_pwm") < 0) {
*adjusted = 1;
return sysi_fanctrl_fan_set_duty(FAN_DUTY_MAX, num_of_fan);
}
Expand Down

0 comments on commit 9f33fed

Please sign in to comment.