Linux之PWM风扇驱动
背景
该驱动主要是用于PWM模块去驱动散热风扇,使用通用的PWM接口,只要主控Soc的PWM模块使用的是标准通用的PWM框架,则可以适用于任何主控Soc,与具体的硬件无关。
用户空间接口
驱动程序给用户空间提供了相应hwmon的sysfs接口: /sys/class/hwmon/hwmon-x/,主要是对PWM的读写操作和风扇转速的读操作:
C
static int pwm_fan_write(struct device *dev, enum hwmon_sensor_types type,
			 u32 attr, int channel, long val)
{
    struct pwm_fan_ctx *ctx = dev_get_drvdata(dev);
    int ret;
    if (val < 0 || val > MAX_PWM)
        return -EINVAL;
    ret = __set_pwm(ctx, val);
    if (ret)
        return ret;
    pwm_fan_update_state(ctx, val);
    return 0;
}









