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驱动编写(电源管理驱动)的更多相关文章
- linux驱动编写(pwm驱动)【转】
本文转载自:https://blog.csdn.net/feixiaoxing/article/details/79889240 pwm方波可以用来控制很多的设备,比如它可以被用来控制电机.简单来说, ...
- linux驱动程序之电源管理之linux的电源管理架构(3)
设备电源管理 Copyright (c) 2010 Rafael J. Wysocki<rjw@sisk.pl>, Novell Inc. Copyright (c) 2010 Alan ...
- linux驱动程序之电源管理之新版linux系统设备架构中关于电源管理方式的变更
新版linux系统设备架构中关于电源管理方式的变更 based on linux-2.6.32 一.设备模型各数据结构中电源管理的部分 linux的设备模型通过诸多结构体来联合描述,如struct d ...
- linux驱动程序之电源管理 之linux休眠与唤醒(2)
在Linux中,休眠主要分三个主要的步骤:(1)冻结用户态进程和内核态任务:(2)调用注册的设备的suspend的回调函数:(3)按照注册顺序休眠核心设备和使CPU进入休眠态. 冻结进程是 ...
- linux驱动程序之电源管理之标准linux休眠与唤醒机制分析(一)
1. Based on linux2.6.32, only for mem(SDR) 2. 有兴趣请先参考阅读: 电源管理方案APM和ACPI比较.doc Linux系统的休眠与唤醒简介.doc 3 ...
- linux驱动程序之电源管理之Run-time PM 详解(4)
Run-time PM. 每个device或者bus都会向run-time PM core注册3个callback struct dev_pm_ops { ... int (*runtime_su ...
- linux驱动程序之电源管理之regulator机制流程 (1)
电源管理芯片可以为多设备供电,且这些设备电压电流有所同.为这些设备提供的稳压器代码模型即为regulator. 下面通过下面三个过程分析regulartor供电机制: 1.分析regulator结构体 ...
- linux驱动程序之电源管理之标准linux休眠和唤醒机制分析(二)
三.pm_test属性文件读写 int pm_test_level = TEST_NONE; static const char * const pm_tests[__TEST_AFTER_LAST ...
- linux关闭ACPI电源管理模块
一.运行环境 # cat /etc/redhat-release CentOS release 6.2 (Final) # uname -a Linux web-server- -.el6.x86_6 ...
随机推荐
- 循序渐进学.Net Core Web Api开发系列【12】:缓存
系列目录 循序渐进学.Net Core Web Api开发系列目录 本系列涉及到的源码下载地址:https://github.com/seabluescn/Blog_WebApi 一.概述 本篇介绍如 ...
- BZOJ4227 : 城市
首先一遍Dijkstra求出S到每个点的最短路,并建出最短路图. 那么对于一条边,求在这条边不能使用的情况下,到首都S的最短时间会变长的点的数目,等价于求去掉这条边后在最短路图中不能从S出发到达的点的 ...
- 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem C. Equivalent Cards 计算几何
Problem C. Equivalent Cards 题目连接: http://www.codeforces.com/gym/100253 Description Jane is playing a ...
- C#怎么通过一个按钮Button,实现点击这个按钮可以打开一个文件或者文件夹?
string path1 = @"d:\log.txt"; //打开D盘下的log.txt文件 System.Diagnostics.Process.Start(path1); ...
- git 拉取和获取 pull 和 fetch 区别
使用Git 直接提交的话 直接 push 获取最新版本 有两种 拉取 和 获取 pull 和 fetch git pull 从远程拉取最新版本 到本地 自动合并 merge ...
- [Go] sync.Pool 的实现原理 和 适用场景
摘录一: Go 1.3 的 sync 包中加入一个新特性:Pool. 官方文档可以看这里 http://golang.org/pkg/sync/#Pool 这个类设计的目的是用来保存和复用临时对象,以 ...
- 分享下使用 svn,测试服务器代码自动更新、线上服务器代码手动更新的配置经验
分享下使用 svn,测试服务器代码自动更新.线上服务器代码手动更新的配置经验 利用SVN的POST-COMMIT钩子自动部署代码 Linux SVN 命令详解 Linux SVN 命令详解2 使用sv ...
- <table>标签的结构和合并单元格的方法
1.<table>标签的结构 示例代码: <table border="1"> <caption>信息统计表</captio ...
- Revit MEP API连接器类别
连接器的类别,风管不仅有两端,可能在曲线上也有. ; ; ; ; Connector conn = csi.Current ; ...
- .NET开源分布式日志框架ExceptionLess实战演练(公开版)
一.课程介绍 在以前,我们做日志收集大多使用 Log4net,Nlog 等框架,在应用程序变得复杂并且集群的时候,可能传统的方式已经不是很好的适用了,因为收集各个日志并且分析他们将变得麻烦而且浪费时间 ...