Linux/风扇

来自康健生活

转速

pwm

查看PWM模块是否存在

ls /sys/class/hwmon/hwmon*/
/sys/class/hwmon/hwmon0/:
device  power      temp1_crit   temp2_crit   uevent
name    subsystem  temp1_input  temp2_input

/sys/class/hwmon/hwmon1/:
device            temp2_crit_alarm  temp4_crit_alarm  temp6_crit_alarm
name              temp2_input       temp4_input       temp6_input
power             temp2_label       temp4_label       temp6_label
subsystem         temp2_max         temp4_max         temp6_max
temp1_crit        temp3_crit        temp5_crit        temp7_crit
temp1_crit_alarm  temp3_crit_alarm  temp5_crit_alarm  temp7_crit_alarm
temp1_input       temp3_input       temp5_input       temp7_input
temp1_label       temp3_label       temp5_label       temp7_label
temp1_max         temp3_max         temp5_max         temp7_max
temp2_crit        temp4_crit        temp6_crit        uevent

/sys/class/hwmon/hwmon2/:
device  fan1_input  fan1_label  name  power  pwm1_enable  subsystem  uevent

/sys/class/hwmon/hwmon3/:
device       freq1_input  name            pwm1         temp1_crit_hyst
fan1_enable  freq1_label  power           pwm1_enable  temp1_input
fan1_input   freq2_input  power1_average  pwm1_max     temp1_label
fan1_max     freq2_label  power1_cap      pwm1_min     uevent
fan1_min     in0_input    power1_cap_max  subsystem
fan1_target  in0_label    power1_cap_min  temp1_crit

安装pwm

kernel.org 下载内核源码,再通过 rz 将下载的内核镜像拷贝到linux下的 /usr/src 目录,解压内核源码,通过make ARCH=x86 menuconfig 配置nct6775这个模块(和风扇有关的),再通过source mk.sh编译生成内核镜像ko模块(mk.sh会帮我们将内核镜像关联boot,这样机子在启动的时候就能找到我们最新编译的内核镜像了)

在这个过程中会遇到很多很多的开发环境缺失,需要一个一个百度,yum缺失的开发环境。

重启,能看到自己编译出的内核版本,然后通加载模块

insmod /usr/src/linux-4.16.12/drivers/usb/serial/nct6775.ko

不成功,提示符号表缺失,因为这个模块依赖另一个模块,因此:

modinfo  /usr/src/linux-4.16.12/drivers/hwmon/nct6775.ko | grep depend
depends:        hwmon-vid

找到依赖的模块后,执行:

modprobe hwmon-vid

再次加载模块:

insmod /usr/src/linux-4.16.12/drivers/usb/serial/nct6775.ko

然后查看是否有pwm了:

ls /sys/class/hwmon/hwmon*/

有了之后,调整pwm:

echo 255 > /sys/class/hwmon/hwmon1/pwm1