详解linux电源管理驱动编写

 更新时间:2018年04月13日 09:36:31   作者:feixiaoxing  
这篇文章主要介绍了详解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"; 
}; 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • centos6.5 lamp 环境(使用yum安装方法)

    centos6.5 lamp 环境(使用yum安装方法)

    这篇文章主要介绍了centos6.5下安装lamp环境 使用yum安装方法,需要的朋友可以参考下
    2016-10-10
  • Linux如何使用HTTP进行远程系统监控

    Linux如何使用HTTP进行远程系统监控

    这篇文章主要介绍了Linux如何使用HTTP进行远程系统监控问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-11-11
  • linux在vim中查找和替换方式

    linux在vim中查找和替换方式

    Linux中使用Vim编辑器查找和替换文本的方法非常直观和强大,Vim支持多种查找和替换的命令,包括向前查找、向后查找、查找并替换文本、替换所有匹配项、确认每个替换和在多个文件中进行替换等
    2025-02-02
  • Linux学习教程之redis哨兵集群详解

    Linux学习教程之redis哨兵集群详解

    这篇文章主要给大家介绍了关于Linux学习教程之Redis哨兵集群的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用redis具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2018-07-07
  • Linux如何用grep高效搜索二进制日志并统计匹配结果

    Linux如何用grep高效搜索二进制日志并统计匹配结果

    在日常开发和运维工作中,日志分析是排查问题的重要手段,本文将详细介绍 grep 处理二进制日志的技巧,并给出完整的解决方案,需要的小伙伴可以参考一下
    2025-04-04
  • CentOS7使用dnf安装mysql的方法

    CentOS7使用dnf安装mysql的方法

    本篇文章主要介绍了CentOS7使用dnf安装mysql的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-03-03
  • 2018即将推出的Apache Spark 2.4都有哪些新功能

    2018即将推出的Apache Spark 2.4都有哪些新功能

    即将发布的 Apache Spark 2.4 版本是 2.x 系列的第五个版本。 本文对Apache Spark 2.4 的主要功能和增强功能进行了概述,需要的朋友可以参考下
    2018-09-09
  • 如何确保Apache Flink流处理的数据一致性和可靠性

    如何确保Apache Flink流处理的数据一致性和可靠性

    Apache Flink通过其先进的状态管理、检查点机制、时间语义和容错策略,确保了在流处理中的高数据一致性和可靠性,本文详细介绍了Flink中保证数据一致性和可靠性的机制,感兴趣的朋友一起看看吧
    2024-08-08
  • Linux系统交换空间介绍

    Linux系统交换空间介绍

    今天小编就为大家分享一篇关于Linux系统交换空间介绍的文章,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2018-09-09
  • CentOS7.4下MySQL5.7.28二进制方式安装的方法步骤

    CentOS7.4下MySQL5.7.28二进制方式安装的方法步骤

    这篇文章主要介绍了CentOS7.4下MySQL5.7.28二进制方式安装的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-11-11

最新评论