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

1、代码目录

drivers/regulator

2、查看目录下的Kconfig文件

  1. menuconfig REGULATOR
  2. bool "Voltage and Current Regulator Support"
  3. help
  4. Generic Voltage and Current Regulator support.
  5.  
  6. This framework is designed to provide a generic interface to voltage
  7. and current regulators within the Linux kernel. It's intended to
  8. provide voltage and current control to client or consumer drivers and
  9. also provide status information to user space applications through a
  10. sysfs interface.
  11.  
  12. The intention is to allow systems to dynamically control regulator
  13. output in order to save power and prolong battery life. This applies
  14. to both voltage regulators (where voltage output is controllable) and
  15. current sinks (where current output is controllable).
  16.  
  17. This framework safely compiles out if not selected so that client
  18. drivers can still be used in systems with no software controllable
  19. regulators.
  20.  
  21. If unsure, say no.

3、阅读文件,得知REGULATOR是最核心的模块macro,那我们可以找一个设备的macro看看

  1. config REGULATOR_STM32_VREFBUF
  2. tristate "STMicroelectronics STM32 VREFBUF"
  3. depends on ARCH_STM32 || COMPILE_TEST
  4. help
  5. This driver supports STMicroelectronics STM32 VREFBUF (voltage
  6. reference buffer) which can be used as voltage reference for
  7. internal ADCs, DACs and also for external components through
  8. dedicated Vref+ pin.
  9.  
  10. This driver can also be built as a module. If so, the module
  11. will be called stm32-vrefbuf.

4、没有找到s3c,可以看一下stm32芯片的依赖属性,接着看Makefile

  1. obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o helpers.o devres.o
  2. obj-$(CONFIG_OF) += of_regulator.o
  3. obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
  4. obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
  5. obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
  6.  
  7. obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o

5、看的出来stm32只依赖于stm32-verfbuf.c文件,继续查看

  1. static const struct of_device_id stm32_vrefbuf_of_match[] = {
  2. { .compatible = "st,stm32-vrefbuf", },
  3. {},
  4. };
  5. MODULE_DEVICE_TABLE(of, stm32_vrefbuf_of_match);
  6.  
  7. static struct platform_driver stm32_vrefbuf_driver = {
  8. .probe = stm32_vrefbuf_probe,
  9. .remove = stm32_vrefbuf_remove,
  10. .driver = {
  11. .name = "stm32-vrefbuf",
  12. .of_match_table = of_match_ptr(stm32_vrefbuf_of_match),
  13. },
  14. };
  15. module_platform_driver(stm32_vrefbuf_driver);

6、确认驱动为platform驱动,寻找regulator特有的数据结构

  1. static const struct regulator_ops stm32_vrefbuf_volt_ops = {
  2. .enable = stm32_vrefbuf_enable,
  3. .disable = stm32_vrefbuf_disable,
  4. .is_enabled = stm32_vrefbuf_is_enabled,
  5. .get_voltage_sel = stm32_vrefbuf_get_voltage_sel,
  6. .set_voltage_sel = stm32_vrefbuf_set_voltage_sel,
  7. .list_voltage = regulator_list_voltage_table,
  8. };
  9.  
  10. static const struct regulator_desc stm32_vrefbuf_regu = {
  11. .name = "vref",
  12. .supply_name = "vdda",
  13. .volt_table = stm32_vrefbuf_voltages,
  14. .n_voltages = ARRAY_SIZE(stm32_vrefbuf_voltages),
  15. .ops = &stm32_vrefbuf_volt_ops,
  16. .type = REGULATOR_VOLTAGE,
  17. .owner = THIS_MODULE,
  18. };

7、由代码得知,regulator_ops和regulator_desc才是特有的regulator数据结构,当然也少不了注册函数

  1. rdev = regulator_register(&stm32_vrefbuf_regu, &config);
  2. if (IS_ERR(rdev)) {
  3. ret = PTR_ERR(rdev);
  4. dev_err(&pdev->dev, "register failed with error %d\n", ret);
  5. goto err_clk_dis;
  6. }
  7. platform_set_drvdata(pdev, rdev);

8、进一步确认of_device_id是不是真实存在,可以在arch/arm/boot/dts/stm32h743.dtsi找到对应内容

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

linux驱动编写(电源管理驱动)的更多相关文章

  1. linux驱动编写(pwm驱动)【转】

    本文转载自:https://blog.csdn.net/feixiaoxing/article/details/79889240 pwm方波可以用来控制很多的设备,比如它可以被用来控制电机.简单来说, ...

  2. linux驱动程序之电源管理之linux的电源管理架构(3)

    设备电源管理 Copyright (c) 2010 Rafael J. Wysocki<rjw@sisk.pl>, Novell Inc. Copyright (c) 2010 Alan ...

  3. linux驱动程序之电源管理之新版linux系统设备架构中关于电源管理方式的变更

    新版linux系统设备架构中关于电源管理方式的变更 based on linux-2.6.32 一.设备模型各数据结构中电源管理的部分 linux的设备模型通过诸多结构体来联合描述,如struct d ...

  4. linux驱动程序之电源管理 之linux休眠与唤醒(2)

    在Linux中,休眠主要分三个主要的步骤:(1)冻结用户态进程和内核态任务:(2)调用注册的设备的suspend的回调函数:(3)按照注册顺序休眠核心设备和使CPU进入休眠态.       冻结进程是 ...

  5. linux驱动程序之电源管理之标准linux休眠与唤醒机制分析(一)

    1. Based on linux2.6.32,  only for mem(SDR) 2. 有兴趣请先参考阅读: 电源管理方案APM和ACPI比较.doc Linux系统的休眠与唤醒简介.doc 3 ...

  6. linux驱动程序之电源管理之Run-time PM 详解(4)

    Run-time PM. 每个device或者bus都会向run-time PM core注册3个callback   struct dev_pm_ops { ... int (*runtime_su ...

  7. linux驱动程序之电源管理之regulator机制流程 (1)

    电源管理芯片可以为多设备供电,且这些设备电压电流有所同.为这些设备提供的稳压器代码模型即为regulator. 下面通过下面三个过程分析regulartor供电机制: 1.分析regulator结构体 ...

  8. linux驱动程序之电源管理之标准linux休眠和唤醒机制分析(二)

    三.pm_test属性文件读写 int pm_test_level = TEST_NONE; static const char * const  pm_tests[__TEST_AFTER_LAST ...

  9. linux关闭ACPI电源管理模块

    一.运行环境 # cat /etc/redhat-release CentOS release 6.2 (Final) # uname -a Linux web-server- -.el6.x86_6 ...

随机推荐

  1. 容器(Container)Frames和Panels

    Frames 1)是Window的子类 2)具有标题和缩放角 3)从容器继承并以add方式添加组件 4)能以字符串规定的标题来创建不可见框架对象 5)能将BorderLayout当做缺省布局管理器 6 ...

  2. Xamarin iOS教程之添加和定制视图

    Xamarin iOS教程之添加和定制视图 Xamarin iOS用户界面——视图 在iPhone或者iPad中,用户看到的摸到的都是视图.视图是用户界面的重要组成元素.例如,想要让用户实现文本输入时 ...

  3. BZOJ.3994.[SDOI2015]约数个数和(莫比乌斯反演)

    题目链接 \(Description\) 求\[\sum_{i=1}^n\sum_{j=1}^md(ij)\] \(Solution\) 有结论:\[d(nm)=\sum_{i|d}\sum_{j|d ...

  4. node-webkit开发桌面应用

    Node-Webkit能够做什么呢?(打开链接看discuss) github 项目源:https://github.com/rogerwang 导言 node-webkit 是一个很神奇的桌面客户端 ...

  5. 【转载】vc编译exe的体积最小优化

    原文地址:http://www.2cto.com/kf/200908/40970.html vc通过设置参数来自定义编译方式.主要用到的技巧有: 一,使用release版而不用debug版编译 使用d ...

  6. CentOS7忘记mysql的root密码_处理方法.

    1.打开mysql的配置文件: vi /etc/my.cnf 2.在配置文件中添加:skip-grant-tables,然后保存退出, vi常用命令在最后.   如图 3.重启mysql servic ...

  7. 使用Python中的HTMLParser、cookielib抓取和解析网页、从HTML文档中提取链接、图像、文本、Cookies(二)(转)

    对搜索引擎.文件索引.文档转换.数据检索.站点备份或迁移等应用程序来说,经常用到对网页(即HTML文件)的解析处理.事实上,通过 Python语言提供的各种模块,我们无需借助Web服务器或者Web浏览 ...

  8. tesseract-ocr识别中文扫描图片实例讲解

    当我浏览http://code.google.com/p/tesseract-ocr并下载了几个文件下来之后顿时感到一头雾水,不知该如何下手.网上看到有人在linux操作系统下的实现, 如: 利用开源 ...

  9. spring cloud 学习(4) - hystrix 服务熔断处理

    hystrix 是一个专用于服务熔断处理的开源项目,当依赖的服务方出现故障不可用时,hystrix有一个所谓的断路器,一但打开,就会直接拦截掉对故障服务的调用,从而防止故障进一步扩大(类似中电路中的跳 ...

  10. [置顶] 从零开始学C++之STL(二):实现简单容器模板类Vec(vector capacity 增长问题、allocator 内存分配器)

    首先,vector 在VC 2008 中的实现比较复杂,虽然vector 的声明跟VC6.0 是一致的,如下:  C++ Code  1 2   template <  class _Ty,  ...