首页 > 系统相关 >linux驱动编写(电源管理驱动)

linux驱动编写(电源管理驱动)

时间:2022-11-23 23:32:05浏览次数:50  
标签:linux regulator vrefbuf driver REGULATOR stm32 voltage 编写 驱动




    对于嵌入式设备来说,合适的电源管理,不仅可以延长电池的寿命,而且可以省电,延长设备运行时间,在提高用户体验方面有很大的好处。所以,各个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,regulator,vrefbuf,driver,REGULATOR,stm32,voltage,编写,驱动
From: https://blog.51cto.com/feixiaoxing/5881994

相关文章

  • linux驱动编写(摄像头驱动)
       对于现代嵌入式设备,特别是手机来说,摄像头是很重要的一个设备。很多同学买手机,一看颜值,第二就看摄像头拍照如何。所以,从某个角度来说,摄像头是各个厂家主打的应用功能......
  • linux驱动编写(nand flash驱动)
      很长一段时间,nandflash都是嵌入式的标配产品。nandflash价格便宜,存储量大,适用于很多的场景。现在很普及的ssd,上面的存储模块其实也是由一块一块nandflash构成的。......
  • 实体类编写时需要注意的细节——为什么字段需要用包装类型而不用基本数据类型
    最近在学习做微服务的项目,总结了一些平常没有注意到的细节,记录于此实体类涉及到的属性如果是int这样的基本数据类型,那么要使用其包装类型,因为包装类型默认为null,而基本......
  • 在Ubuntu Linux上安装Deb文件的三种方法
    https://zhuanlan.zhihu.com/p/339632982?ivk_sa=1024320u方法一:在.deb文件夹下(应该是Downloads文件夹),双击.deb文件方法二:使用Gdebi应用程序来安装deb软件包及其依赖项......
  • 简述linux系统中软件包管理系统
    前几篇文章一一介绍了LINUX进程管理控制命令,详细介绍了静态查看ps命令和动态查看top命令,以及中断、停止命令在实际管理控制过程中的一些实践操作等这篇文章主要简单介绍下......
  • 使用ZLG7289,51单片机驱动的,显示按键号
    1;WritedbyLinXiwei,on2006.06.152;完成功能:等待按键输入,然后将所读到的按键码转换成十进制,送回ZLG显示,同时将前面的显示内容左移,并使当前按键值闪烁34......
  • 使用ZLG7289,51单片机驱动的带有按键功能的时钟小程序
    按键功能说明:KEY0:闪烁显示小时,并修改小时KEY1:闪烁显示分钟,并修改分钟KEY2:闪烁显示秒钟,并修改秒钟KEY12:确认修改,修改结束KEY13:上调时间KEY15:下调时间1......
  • 使用ZLG7289,51单片机驱动的时钟显示小程序
    1;*******ZLG7289PARAMETERS*******2ZLG_BIT_CNTEQU30H;Thenumberofdatasended;循环次数3ZLG_REC_BUFEQU31H;T......
  • Testbench 的编写与应用
    1.Testbench的概念Testbench是一种用任意语言编写的程序或模块,用于在模拟过程中执行和验证硬件模型的功能正确性。Verilog主要用于硬件建模(模拟),该语言包含各种资源,用于......
  • linux命令风格与mysql启动
    Linux三种风格(Unix、BSD、GNU)下的ps的参数说明mysqld_safe是什么使用mysqld_safe启动mysql服务,mysqld_safe为mysqld的守护进程,在BSD风格的unix系统上,常用mysqld_safe脚......