编写 Linux 标准 PWM 驱动
编写 Linux 标准 PWM 驱动
编写Linux标准的PWM驱动,需要定义一个结构体 struct pwm_device ,实现五个个PWM函数(include/linux/pwm.h),如下所示:
- struct pwm_device;
- /*
- * pwm_request - request a PWM device
- */
- struct pwm_device *pwm_request(int pwm_id, const char *label);
- /*
- * pwm_free - free a PWM device
- */
- void pwm_free(struct pwm_device *pwm);
- /*
- * pwm_config - change a PWM device configuration
- */
- int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns);
- /*
- * pwm_enable - start a PWM output toggling
- */
- int pwm_enable(struct pwm_device *pwm);
- /*
- * pwm_disable - stop a PWM output toggling
- */
- void pwm_disable(struct pwm_device *pwm);
其中, struct pwm_device 必须包含以下的内容:
- struct pwm_device {
- struct list_head list;
- struct platform_device *pdev;
- const char *label;
- unsigned int period_ns;
- unsigned int duty_ns;
- unsigned char running;
- unsigned char use_count;
- unsigned char pwm_id;
- };
代码的实现可以参考下面的文件:
arch/arm/plat-s3c/pwm.c
总结(以arm为例):
1. 编写文件 arch/arm/mach-xxxx/pwm.c
2. 修改 arch/arm/mach-xxxx/Makefile ,在最后一行加入下面的内容
obj-y += pwm.c
3. 修改arch/arm/Kconfig,找到 config ARCH_XXXX ,在下面添加
select HAVE_PWM
评论暂时关闭