千家信息网

linux电源管理驱动编写的示例分析

发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,这篇文章给大家分享的是有关linux电源管理驱动编写的示例分析的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。对于嵌入式设备来说,合适的电源管理,不仅可以延长电池的寿命,而且
千家信息网最后更新 2025年12月02日linux电源管理驱动编写的示例分析

这篇文章给大家分享的是有关linux电源管理驱动编写的示例分析的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

对于嵌入式设备来说,合适的电源管理,不仅可以延长电池的寿命,而且可以省电,延长设备运行时间,在提高用户体验方面有很大的好处。所以,各个soc厂家在这方面花了很多的功夫。下面,我们可以看看linux是如何处理电源管理驱动的。

1、代码目录

drivers/regulator

2、查看目录下的Kconfig文件

menuconfig REGULATOR   bool "Voltage and Current Regulator Support"   help    Generic Voltage and Current Regulator support.     This framework is designed to provide a generic interface to voltage    and current regulators within the Linux kernel. It's intended to    provide voltage and current control to client or consumer drivers and    also provide status information to user space applications through a    sysfs interface.     The intention is to allow systems to dynamically control regulator    output in order to save power and prolong battery life. This applies    to both voltage regulators (where voltage output is controllable) and    current sinks (where current output is controllable).     This framework safely compiles out if not selected so that client    drivers can still be used in systems with no software controllable    regulators.     If unsure, say no.

3、阅读文件,得知REGULATOR是最核心的模块macro,那我们可以找一个设备的macro看看

config REGULATOR_STM32_VREFBUF   tristate "STMicroelectronics STM32 VREFBUF"   depends on ARCH_STM32 || COMPILE_TEST   help    This driver supports STMicroelectronics STM32 VREFBUF (voltage    reference buffer) which can be used as voltage reference for    internal ADCs, DACs and also for external components through    dedicated Vref+ pin.     This driver can also be built as a module. If so, the module    will be called stm32-vrefbuf.

4、没有找到s3c,可以看一下stm32芯片的依赖属性,接着看Makefile

obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o helpers.o devres.o obj-$(CONFIG_OF) += of_regulator.o obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o  obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o

5、看的出来stm32只依赖于stm32-verfbuf.c文件,继续查看

static const struct of_device_id stm32_vrefbuf_of_match[] = {   { .compatible = "st,stm32-vrefbuf", },   {}, }; MODULE_DEVICE_TABLE(of, stm32_vrefbuf_of_match);  static struct platform_driver stm32_vrefbuf_driver = {   .probe = stm32_vrefbuf_probe,   .remove = stm32_vrefbuf_remove,   .driver = {     .name = "stm32-vrefbuf",     .of_match_table = of_match_ptr(stm32_vrefbuf_of_match),   }, }; module_platform_driver(stm32_vrefbuf_driver);

6、确认驱动为platform驱动,寻找regulator特有的数据结构

static const struct regulator_ops stm32_vrefbuf_volt_ops = {   .enable   = stm32_vrefbuf_enable,   .disable  = stm32_vrefbuf_disable,   .is_enabled = stm32_vrefbuf_is_enabled,   .get_voltage_sel = stm32_vrefbuf_get_voltage_sel,   .set_voltage_sel = stm32_vrefbuf_set_voltage_sel,   .list_voltage  = regulator_list_voltage_table, };  static const struct regulator_desc stm32_vrefbuf_regu = {   .name = "vref",   .supply_name = "vdda",   .volt_table = stm32_vrefbuf_voltages,   .n_voltages = ARRAY_SIZE(stm32_vrefbuf_voltages),   .ops = &stm32_vrefbuf_volt_ops,   .type = REGULATOR_VOLTAGE,   .owner = THIS_MODULE, };

7、由代码得知,regulator_ops和regulator_desc才是特有的regulator数据结构,当然也少不了注册函数

rdev = regulator_register(&stm32_vrefbuf_regu, &config); if (IS_ERR(rdev)) {   ret = PTR_ERR(rdev);   dev_err(&pdev->dev, "register failed with error %d\n", ret);   goto err_clk_dis; } platform_set_drvdata(pdev, rdev);

8、进一步确认of_device_id是不是真实存在,可以在arch/arm/boot/dts/stm32h743.dtsi找到对应内容

vrefbuf: regulator@58003C00 {   compatible = "st,stm32-vrefbuf";   reg = <0x58003C00 0x8>;   clocks = <&rcc VREF_CK>;   regulator-min-microvolt = <1500000>;   regulator-max-microvolt = <2500000>;   status = "disabled"; };

感谢各位的阅读!关于"linux电源管理驱动编写的示例分析"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

驱动 电源 管理 内容 文件 设备 示例 分析 代码 数据 数据结构 更多 目录 篇文章 结构 不错 合适 实用 很大 少不了 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 软件开发过程中的质量 金山区软件开发公司 oracel数据库中文排序 软件开发及系统集成的英文 文明上网网络安全演讲稿 中山软件开发培训 怎么估算软件开发价格 我的世界服务器装投影 idea读取数据库 app服务器端 开源框架 适合做家庭服务器的主板 系统分析师 与软件开发 参加网络安全大赛 人在网络安全中的重要性 一个数据库有多少主键 加强网络安全地位 海南中和药业公司软件开发 如果要找软件开发简历如何写 深圳软件开发工资为什么那么高 云端服务器是谁发明的 中级软件开发工程师面试题 游侠饥荒云服务器搭建 战地5如何找到外挂少的服务器 软件开发项目中的分工 我的世界有刷怪塔的服务器 日照职业技术学院数据库 嘉定区进口网络技术开发操作 金税盘白盘用什么软件开发票 湛江社交软件开发费用是多少 网络安全法第六十八条
0