/** * @author Wagyourtail * @version 1.0 * @date 2022-01-13 * @license MIT * * Toggles the fan boost bit */ #include #include #include #include int main(int argc, const char * argv[]) { if (getuid() != 0) { printf("You must be root to run this program\n"); return 1; } // modprobe -r ec_sys // modprobe ec_sys write_support=1 system("modprobe -r ec_sys"); system("modprobe ec_sys write_support=1"); // open /sys/kernel/debug/ec/ec0/io to read/write the fan boost bit int fd = open("/sys/kernel/debug/ec/ec0/io", O_RDWR); if (fd < 0) { perror("open"); return 1; } // read the current value of the fan boost bit (40 bit of the 0xF5 byte) char buf[1]; pread(fd, buf, 1, 0xF5); if (buf[0] & 0x40) { printf("Fan boost is currently on\n 0x%02x\n", buf[0]); } else { printf("Fan boost is currently off\n" "0x%02x\n", buf[0]); } printf("Toggling fan boost...\n"); // toggle the fan boost bit buf[0] ^= 0x40; pwrite(fd, buf, 1, 0xF5); // read the current value of the fan boost bit (40 bit of the 0xF5 byte) pread(fd, buf, 1, 0xF5); if (buf[0] & 0x40) { printf("Fan boost is now on\n 0x%02x\n", buf[0]); } else { printf("Fan boost is now off\n" "0x%02x\n", buf[0]); } close(fd); return 0; }