详解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"; 
}; 

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

相关文章

  • 在Linux服务器上安装 memcached的基本操作

    在Linux服务器上安装 memcached的基本操作

    本文分步骤给大家详细介绍了linux服务器上安装memcached的操作方法,非常不错,需要的朋友参考下吧
    2016-12-12
  • Linux下Apache安装/增加mod_rewrite模块的方法

    Linux下Apache安装/增加mod_rewrite模块的方法

    如果你的apache已经安装好了,现在只想编译出mod_rewrite.so模块,在apache中进行加载,下面我们就介绍这个方法。
    2011-04-04
  • linux直接运行py文件的方法

    linux直接运行py文件的方法

    今天小编就为大家分享一篇linux直接运行py文件的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-06-06
  • Linux系统下利用C程序输出某进程的内存占用信息

    Linux系统下利用C程序输出某进程的内存占用信息

    这篇文章主要给大家介绍了关于在Linux系统下利用C程序输出某进程的内存占用信息的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友下面来一起看看吧。
    2017-12-12
  • 安装ubuntu时黑屏的解决办法(3种)

    安装ubuntu时黑屏的解决办法(3种)

    这篇文章主要介绍了安装ubuntu时黑屏的解决办法(3种),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-11-11
  • Ubuntu下安装Docker教程

    Ubuntu下安装Docker教程

    这篇文章主要介绍了Ubuntu下安装Docker教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。
    2017-02-02
  • 树莓派搭建nas服务器的详细过程

    树莓派搭建nas服务器的详细过程

    这篇文章主要介绍了树莓派搭建nas服务器的教程,本文分步骤给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-01-01
  • Linux使用join -a1来合并两个文件

    Linux使用join -a1来合并两个文件

    今天小编就为大家分享一篇关于Linux使用join -a1来合并两个文件,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2019-03-03
  • centos系统搭建本地yum服务器的方法

    centos系统搭建本地yum服务器的方法

    YUM是Yellow dog Updater, Modified的缩写,是由Duke University所发起的计划,目的就是为了解决RPM的依赖关系的问题,方便使用者进行软件的安装、升级等等工作。这篇文章主要给大家介绍了在centos系统搭建本地yum服务器的方法,有需要的朋友们可以参考借鉴。
    2016-12-12
  • linux让$变成#符号的实操方法

    linux让$变成#符号的实操方法

    在本文里我们给大家整理了一篇关于linux让$变成#符号的操作方法和案例,对此有需要的朋友们跟着操作下。
    2019-02-02

最新评论