一、原理图
当前风扇控制支持gpio与pwm控制
二、gpio控制
1、查找gpio号
当前控制风扇通过控制GPIO高低电平来实现,
FAN_CTL接GPIO4_C6
查找gpio号
进入系统,输入命令
cat /sys/kernel/debug/gpio
root@linaro-alip:/# cat /sys/kernel/debug/gpio
GPIOs 0-31, platform/pinctrl, gpio0:
gpio-4 ( |bt_default_wake_host) in lo
gpio-5 ( |GPIO Key Power ) in hi
gpio-9 ( |bt_default_reset ) out hi
gpio-10 ( |reset ) out hi
gpio-11 ( |spk-con-gpio ) out lo
GPIOs 32-63, platform/pinctrl, gpio1:
gpio-33 ( |vcc_lcd ) out hi
gpio-35 ( |vcc_otg_vbus ) out lo
gpio-46 ( |vsel ) out lo
gpio-49 ( |vsel ) out lo
gpio-55 ( |enable ) out lo
GPIOs 64-95, platform/pinctrl, gpio2:
gpio-76 ( |rockchip,pd-gpio ) out hi
gpio-83 ( |bt_default_rts ) out lo
gpio-90 ( |bt_default_wake ) out hi
gpio-92 ( |reset ) out hi
GPIOs 96-127, platform/pinctrl, gpio3:
gpio-111 ( |mdio-reset ) out hi
GPIOs 128-159, platform/pinctrl, gpio4:
gpio-148 ( |sysfs ) in hi
gpio-150 ( |sysfs ) out lo
gpio-153 ( |vcc5v0_host ) out hi
GPIO4_C6对应的gpio号是150
2、GPIO口操作
导出GPIO口
cd /sys/class/gpio
echo 150 >export
查看GPIO文件夹下会多出gpio150文件夹
ls
export gpio150 gpiochip128 gpiochip64 unexport
gpio148 gpiochip0 gpiochip32 gpiochip96
进入文件夹gpio150
cd gpio150
打开文件权限并设置输入模式
chmod 777 direction
chmod 777 value
echo out > direction
修改GPIO口状态
echo 1 > value / echo 0 > value
三、pwm控制
1、dts配置
当前风扇控制引脚接pwm1,我们需配置风扇驱动和pwn1
fan0: pwm-fan {
compatible = "pwm-fan";
pwms = <&pwm1 0 10000 0>;
};
&pwm1 {
pinctrl-names = "active";
pinctrl-0 = <&pwm1_pin>;
status = "okay";
};
2、打开风扇驱动编译
当前风扇驱动在 kernel/drivers/hwmon/pwm-fan.c中,打开编译宏配制
CONFIG_PWM_ROCKCHIP=y
CONFIG_SENSORS_PWM_FAN=y
CONFIG_HWMON=y
3、上层控制
通过修改占空比达到控制风扇转动
echo 100 > /sys/devices/platform/pwm-fan/hwmon/hwmon0/pwm1
占空比的有效操作大致在180-229左右,数据值越大,转速越慢