这篇文章主要为大家展示了“linux中pwm驱动编写的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“linux中pwm驱动编写的示例分析”这篇文章吧。
pwm方波可以用来控制很多的设备,比如它可以被用来控制电机。简单来说,就是单位时间内的方波越多,那么电机的转速就会越快;反之就越慢。通过这个特性,soc就可以轻松地利用pwm对外设进行自动控制。
1、驱动目录
drivers/pwm
2、查看对应目录下的Kconfig
config PWM_SAMSUNG tristate "Samsung PWM support" depends on PLAT_SAMSUNG || ARCH_EXYNOS help Generic PWM framework driver for Samsung. To compile this driver as a module, choose M here: the module will be called pwm-samsung.
3、确认PWM_SAMSUNG只依赖于自己之外,继续看Makefile
obj-$(CONFIG_PWM) += core.o obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.o
4、根据Makefile查阅pwm-samsung.c文件,结构比较清楚
static struct platform_driver pwm_samsung_driver = { .driver = { .name = "samsung-pwm", .pm = &pwm_samsung_pm_ops, .of_match_table = of_match_ptr(samsung_pwm_matches), }, .probe = pwm_samsung_probe, .remove = pwm_samsung_remove, }; module_platform_driver(pwm_samsung_driver);
5、soc设备大多数是platform设备,继续寻找probe函数中的有用信息
ret = pwmchip_add(&chip->chip); if (ret < 0) { dev_err(dev, "failed to register PWM chip\n"); clk_disable_unprepare(chip->base_clk); return ret; }
6、找到注册函数后,接续看看函数接口点在什么地方
static const struct pwm_ops pwm_samsung_ops = { .request = pwm_samsung_request, .free = pwm_samsung_free, .enable = pwm_samsung_enable, .disable = pwm_samsung_disable, .config = pwm_samsung_config, .set_polarity = pwm_samsung_set_polarity, .owner = THIS_MODULE, };
7、pwm设备没有中断函数,一般是立马生效,除此之外,代码中还是有设备树的内容,可以看看
static const struct of_device_id samsung_pwm_matches[] = { { .compatible = "samsung,s3c2410-pwm", .data = &s3c24xx_variant }, { .compatible = "samsung,s3c6400-pwm", .data = &s3c64xx_variant }, { .compatible = "samsung,s5p6440-pwm", .data = &s5p64x0_variant }, { .compatible = "samsung,s5pc100-pwm", .data = &s5pc100_variant }, { .compatible = "samsung,exynos4210-pwm", .data = &s5p64x0_variant }, {}, }; MODULE_DEVICE_TABLE(of, samsung_pwm_matches); static int pwm_samsung_parse_dt(struct samsung_pwm_chip *chip) { struct device_node *np = chip->chip.dev->of_node; const struct of_device_id *match; struct property *prop; const __be32 *cur; u32 val; match = of_match_node(samsung_pwm_matches, np); if (!match) return -ENODEV; memcpy(&chip->variant, match->data, sizeof(chip->variant)); of_property_for_each_u32(np, "samsung,pwm-outputs", prop, cur, val) { if (val >= SAMSUNG_PWM_NUM) { dev_err(chip->chip.dev, "%s: invalid channel index in samsung,pwm-outputs property\n", __func__); continue; } chip->variant.output_mask |= BIT(val); } return 0; }
以上是“linux中pwm驱动编写的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。