蝙蝠岛资源网 Design By www.hbtsch.com

对于嵌入式设备来说,合适的电源管理,不仅可以延长电池的寿命,而且可以省电,延长设备运行时间,在提高用户体验方面有很大的好处。所以,各个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,电源管理驱动,linux,电源管理,命令,linux,电源管理

蝙蝠岛资源网 Design By www.hbtsch.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
蝙蝠岛资源网 Design By www.hbtsch.com

评论“详解linux电源管理驱动编写”

暂无详解linux电源管理驱动编写的评论...

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。