服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Linux - 详解linux电源管理驱动编写

详解linux电源管理驱动编写

2022-03-07 16:48feixiaoxing Linux

这篇文章主要介绍了详解linux电源管理驱动编写,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

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

1、代码目录

?
1
drivers/regulator

2、查看目录下的Kconfig文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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看看 

?
1
2
3
4
5
6
7
8
9
10
11
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

?
1
2
3
4
5
6
7
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文件,继续查看

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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特有的数据结构

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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数据结构,当然也少不了注册函数

?
1
2
3
4
5
6
7
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找到对应内容

?
1
2
3
4
5
6
7
8
vrefbuf: regulator@58003C00 {
  compatible = "st,stm32-vrefbuf";
  reg = <0x58003C00 0x8>;
  clocks = <&rcc VREF_CK>;
  regulator-min-microvolt = <1500000>;
  regulator-max-microvolt = <2500000>;
  status = "disabled";
};

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

原文链接:https://blog.csdn.net/feixiaoxing/article/details/79874311

延伸 · 阅读

精彩推荐
  • Linux手把手教您在 Linux 上使用 GPG 加解密文件

    手把手教您在 Linux 上使用 GPG 加解密文件

    在本教程中,我将告诉你如何用 GPG 加密和解密文件。这是一个简单的教程,你可以在你的 Linux 系统上尝试所有的练习。这将帮助你练习 GPG 命令,并在你...

    Linux中国6962021-12-15
  • Linux详解Linux系统下PXE服务器的部署过程

    详解Linux系统下PXE服务器的部署过程

    这篇文章主要介绍了Linux系统下PXE服务器的部署过程,包括对PXE的API架构作了一个基本的简介,需要的朋友可以参考下...

    运维之道9812019-07-04
  • Linux确保Linux系统安全的前提条件 漏洞防护

    确保Linux系统安全的前提条件 漏洞防护

    Linux 作为开放式的操作系统受到很多程序员的喜爱,很多高级程序员都喜欢编写Linux操作系统的相关软件。这使得Linux操作系统有着丰富的软件支持,还有无...

    Linux之家2642020-04-11
  • Linuxlinux中rmdir命令使用详解(删除空目录)

    linux中rmdir命令使用详解(删除空目录)

    今天学习一下linux中命令: rmdir命令。rmdir是常用的命令,该命令的功能是删除空目录,一个目录被删除之前必须是空的 ...

    linux命令大全5372019-11-19
  • LinuxLinux中环境变量配置的步骤详解

    Linux中环境变量配置的步骤详解

    Linux中环境变量包括系统级和用户级,系统级的环境变量是每个登录到系统的用户都要读取的系统变量,而用户级的环境变量则是该用户使用系统时加载的...

    Myths7882022-02-10
  • LinuxLinux lnmp下无法使用mail发邮件的两种解决方法

    Linux lnmp下无法使用mail发邮件的两种解决方法

    在配置了lnmp环境后,出现了mail函数不能发送邮件的问题,其实有两种方法,一是使用sendmail组件,而是使用postfix。下面为大家一一介绍下 ...

    Linux之家4042019-09-17
  • LinuxLinux常用的日志文件和常用命令

    Linux常用的日志文件和常用命令

    成功地管理任何系统的关键之一,是要知道系统中正在发生什么事。 Linux 中提供了异常日志,并且日志的细节是可配置的。Linux 日志都以明文形式存储,所...

    Linux教程网2632020-04-18
  • LinuxLinux上设置用户通过SFTP访问目录的权限的方法

    Linux上设置用户通过SFTP访问目录的权限的方法

    这篇文章主要介绍了Linux上设置用户通过SFTP访问目录的权限的方法,SFTP可以理解为使用SSH协议进行FTP传输的协议,因而同时要对OpenSSH进行相关设置,需要的朋...

    OSChina10022019-06-19