Skip to content
Open
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
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the asterisk needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the asterisk needed?

The path is migrated under the 'hwmon' folder.
Without the asterisk, opening the file will fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse my ignorance, can you please give an example for the old and the new path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse my ignorance, can you please give an example for the old and the new path?

Old path:
/sys/devices/platform/as4224_fan/

New path:
/sys/devices/platform/as4224_fan/hwmon/hwmon5/

hwmon"5" could represent any other number, such as hwmon1 or hwmon6.
The index starts from 1, and the number is determined by the order in which the driver is attached to hwmon.

}

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_groups(&pdev->dev,
DRVNAME, 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