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

Add support for alternate applesmc module device path. #236

Merged
merged 1 commit into from
Apr 2, 2023
Merged
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
39 changes: 35 additions & 4 deletions src/mbpfan.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
Expand All @@ -52,6 +53,7 @@

#define CORETEMP_PATH "/sys/devices/platform/coretemp.0"
#define APPLESMC_PATH "/sys/devices/platform/applesmc.768"
#define ALT_APPLESMC_PATH "/sys/bus/acpi/drivers/applesmc"
Copy link
Member

Choose a reason for hiding this comment

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

Is this the new, preferred path, or just some weird quirk of Debian/Ubuntu?

Choose a reason for hiding this comment

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

On the MacBookPro11,3, /sys/devices/platform/applesmc.768 is still being used, and /sys/bus/acpi/drivers/applesmc is empty, but since that is a mid-2014 machine, things may be different for newer macs.

(I will say that the stock mbpfan package available in ubuntu 22.04 was not working to set the fan speed on my MacBookPro11,3 though, whereas building with this patch does set the fan speeds according to my settings in the mbpfan.conf file.)

Choose a reason for hiding this comment

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

(so maybe one of the other changes... or doing a rebuild for 22.04 made the package work.)

Copy link
Member

Choose a reason for hiding this comment

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

I tested my MacBook Air 2014 with 5.16.8-200.fc35.x86_64 and /sys/devices/platform/applesmc.768 has the files that mbpfan needs. Does kernel 5.17 change this path? Can you point me to the Linux commit that changes this? The original PR talks about kernel 5.13 -- what am I missing here?


/* temperature thresholds
* low_temp - temperature below which fan speed will be at minimum
Expand All @@ -74,6 +76,9 @@ int polling_interval = 1;

t_sensors *sensors = NULL;
t_fans *fans = NULL;
char applesmc_path[PATH_MAX];
char applesmc_fan_path[PATH_MAX];


char *smprintf(const char *fmt, ...)
{
Expand Down Expand Up @@ -273,7 +278,7 @@ t_fans *retrieve_fans()
char *path_fan_max = NULL;
char *path_fan_min = NULL;

const char *path_begin = "/sys/devices/platform/applesmc.768/fan";
const char *path_begin = (const char *) &applesmc_fan_path;
const char *path_output_end = "_output";
const char *path_label_end = "_label";
const char *path_man_end = "_manual";
Expand Down Expand Up @@ -553,15 +558,41 @@ void check_requirements(const char *program_path)
}

closedir(dir);
memset(&applesmc_path, 0, PATH_MAX);
memset(&applesmc_fan_path, 0, PATH_MAX);

dir = opendir(APPLESMC_PATH);

if (ENOENT == errno) {
mbp_log(LOG_ERR, "%s needs applesmc support. Please either load it or build it into the kernel. Exiting.", program_path);
exit(EXIT_FAILURE);
if (ENOENT != errno) {
strncpy((char *) &applesmc_path, APPLESMC_PATH, PATH_MAX);
} else {
/**
* Check for alternate ACPI device path for newer macbooks
*/
closedir(dir);
dir = opendir(ALT_APPLESMC_PATH);
if (ENOENT != errno) {
struct dirent *ent;
while ((ent = readdir(dir)) != NULL) {
if (strncmp("APP", (const char *) &ent->d_name, 3) == 0) {
snprintf((char *) &applesmc_path, PATH_MAX, "%s/%s", ALT_APPLESMC_PATH, (char *) &ent->d_name);
break;
}
}
}
}

closedir(dir);

if (strlen(applesmc_path) != 0) {
strncpy((char *) &applesmc_fan_path, (char *) &applesmc_path, PATH_MAX);
strcat((char *) &applesmc_fan_path, "/fan");
if (verbose) mbp_log(LOG_INFO, "applesmc device path: %s", (char *) &applesmc_path);

} else {
mbp_log(LOG_ERR, "%s needs applesmc support. Please either load it or build it into the kernel. Exiting.", program_path);
exit(EXIT_FAILURE);
}
}

int get_max_mhz(void)
Expand Down