regulator_get

regulator_get与devm_regulator_get的5个关键区别:嵌入式开发必知的自动释放机制 本文深入解析了嵌入式Linux驱动开发中regulator_get与devm_regulator_get的五大核心区别,重点阐述了基于devres框架的自动释放机制。通过对比手动管理与自动托管在生命周期绑定、错误处理复杂度及适用场景上的差异,并提供了调试验证方法,旨在帮助开发者避免资源泄漏,编写更健壮、简洁的驱动代码。 阅读详情

kernel-3.10/Documentation/power/regulator/consumer.txt

这里写图片描述

Regulator Consumer Driver Interface

This text describes the regulator interface for consumer device drivers.
Please see overview.txt for a description of the terms used in this text.

1. Consumer Regulator Access (static & dynamic drivers)

A consumer driver can get access to its supply regulator by calling :-

regulator = regulator_get(dev, “Vcc”);

The consumer passes in its struct device pointer and power supply ID. The core
then finds the correct regulator by consulting a machine specific lookup table.
If the lookup is successful then this call will return a pointer to the struct
regulator that supplies this consumer.

To release the regulator the consumer driver should call :-

regulator_put(regulator);

Consumers can be supplied by more than one regulator e.g. codec consumer with
analog and digital supplies :-

digital = regulator_get(dev, “Vcc”); /* digital core */
analog = regulator_get(dev, “Avdd”); /* analog */

The regulator access functions regulator_get() and regulator_put() will
usually be called in your device drivers probe() and remove() respectively.

2. Regulator Output Enable & Disable (static & dynamic drivers)

A consumer can enable its power supply by calling:-

int regulator_enable(regulator);

NOTE: The supply may already be enabled before regulator_enabled() is called.
This may happen if the consumer shares the regulator or the regulator has been
previously enabled by bootloader or kernel board initialization code.

A consumer can determine if a regulator is enabled by calling :-

int regulator_is_enabled(regulator);

This will return > zero when the regulator is enabled.

A consumer can disable its supply when no longer needed by calling :-

int regulator_disable(regulator);

NOTE: This may not disable the supply if it’s shared with other consumers. The
regulator will only be disabled when the enabled reference count is zero.

Finally, a regulator can be forcefully disabled in the case of an emergency :-

int regulator_force_disable(regulator);

NOTE: this will immediately and forcefully shutdown the regulator output. All
consumers will be powered off.

3. Regulator Voltage Control & Status (dynamic drivers)

Some consumer drivers need to be able to dynamically change their supply
voltage to match system operating points. e.g. CPUfreq drivers can scale
voltage along with frequency to save power, SD drivers may need to select the
correct card voltage, etc.

Consumers can control their supply voltage by calling :-

int regulator_set_voltage(regulator, min_uV, max_uV);

Where min_uV and max_uV are the minimum and maximum acceptable voltages in
microvolts.

NOTE: this can be called when the regulator is enabled or disabled. If called
when enabled, then the voltage changes instantly, otherwise the voltage
configuration changes and the voltage is physically set when the regulator is
next enabled.

The regulators configured voltage output can be found by calling :-

int regulator_get_voltage(regulator);

NOTE: get_voltage() will return the configured output voltage whether the
regulator is enabled or disabled and should NOT be used to determine regulator
output state. However this can be used in conjunction with is_enabled() to
determine the regulator physical output voltage.

4. Regulator Current Limit Control & Status (dynamic drivers)

Some consumer drivers need to be able to dynamically change their supply
current limit to match system operating points. e.g. LCD backlight driver can
change the current limit to vary the backlight brightness, USB drivers may want
to set the limit to 500mA when supplying power.

Consumers can control their supply current limit by calling :-

int regulator_set_current_limit(regulator, min_uA, max_uA);

Where min_uA and max_uA are the minimum and maximum acceptable current limit in
microamps.

NOTE: this can be called when the regulator is enabled or disabled. If called
when enabled, then the current limit changes instantly, otherwise the current
limit configuration changes and the current limit is physically set when the
regulator is next enabled.

A regulators current limit can be found by calling :-

int regulator_get_current_limit(regulator);

NOTE: get_current_limit() will return the current limit whether the regulator
is enabled or disabled and should not be used to determine regulator current
load.

5. Regulator Operating Mode Control & Status (dynamic drivers)

Some consumers can further save system power by changing the operating mode of
their supply regulator to be more efficient when the consumers operating state
changes. e.g. consumer driver is idle and subsequently draws less current

Regulator operating mode can be changed indirectly or directly.

Indirect operating mode control.

Consumer drivers can request a change in their supply regulator operating mode
by calling :-

int regulator_set_optimum_mode(struct regulator *regulator, int load_uA);

This will cause the core to recalculate the total load on the regulator (based
on all its consumers) and change operating mode (if necessary and permitted)
to best match the current operating load.

The load_uA value can be determined from the consumers datasheet. e.g.most
datasheets have tables showing the max current consumed in certain situations.

Most consumers will use indirect operating mode control since they have no
knowledge of the regulator or whether the regulator is shared with other
consumers.

Direct operating mode control.

Bespoke or tightly coupled drivers may want to directly control regulator
operating mode depending on their operating point. This can be achieved by
calling :-

int regulator_set_mode(struct regulator *regulator, unsigned int mode);
unsigned int regulator_get_mode(struct regulator *regulator);

Direct mode will only be used by consumers that know about the regulator and
are not sharing the regulator with other consumers.

6. Regulator Events

Regulators can notify consumers of external events. Events could be received by
consumers under regulator stress or failure conditions.

Consumers can register interest in regulator events by calling :-

int regulator_register_notifier(struct regulator *regulator,
struct notifier_block *nb);

Consumers can uregister interest by calling :-

int regulator_unregister_notifier(struct regulator *regulator,
struct notifier_block *nb);

Regulators use the kernel notifier framework to send event to their interested
consumers.

深入解析devm_regulator_get:Linux内核中的资源管理机制 本文深入解析了Linux内核中的`devm_regulator_get`函数,探讨其作为资源管理机制的核心价值与实现原理。通过自动释放电源资源的功能,该函数有效解决了驱动开发中的资源泄漏问题,并结合设备树配置、多电源管理及PM框架整合等实战技巧,展示了其在复杂场景下的应用优势。 阅读详情

相关推荐

Linux设备驱动开发:如何正确使用devm_regulator_get管理电源资源(附常见错误排查)

本文深入探讨了Linux设备驱动开发中如何使用devm_regulator_get高效管理电源资源。文章详细解析了regulator子系统的基础概念、devm_regulator_get的自动资源释放机制,并提供了最佳实践和常见错误排查方法,帮助开发者避免电源管理中的常见陷阱,提升驱动稳定性。

weixin_42531163的博客 170

使用regulator_get时的一个小注意事项

Linux kernel 使用 regulator 框架来管理电源,比如 PMIC 芯片上常见的LDO。使用 regulator的常规流程如以下代码所示: void set_vbus_voltage(struct device *dev) { struct regulator *vbus; ​ vbus = regulator_get(dev, "vbus"); if (IS_ERR(vbus)) { ret = PTR_ERR(vbus); goto reg_put; ..

nidongla的博客 2130

嵌入式系统电源管理实战:从设备树配置到devm_regulator_get调用全流程解析

本文详细解析了嵌入式系统电源管理的全流程,从设备树配置到驱动中devm_regulator_get调用的实现。通过实战案例和最佳实践,帮助开发者掌握Linux内核电源管理子系统的关键技术和调试方法,提升系统稳定性和能效表现。

weixin_30689307的博客 416

Linux驱动之Regulator子系统

该数据结构描述regulator device的约束信息,包括输出电压范围、输出电流范围、regulator device支持的模式(fast、normal、idle、standby等)、regulator device支持的操作模式,包括change volt、change current、change bypass mode等、regulator device支持的suspend 状态下的输出控制(如在suspend to disk状态下的输出控制等)。在这一章中将介绍regulator的内部实现。

Android系统攻城狮 3534

Linux kernel regulator简介

一般情况下在驱动程序中probe函数中调用先调用struct regulator *regulator_get struct device *dev, const char *id,int exclusive函数。通过查表找到设备。 返回一个struct regulator *结构体指针。

Dify 部署与使用

本文介绍了Dify社区版的快速部署指南,涵盖系统架构、环境配置和初始化流程。Dify采用微服务架构,通过Docker Compose一键部署8个核心容器,包括前端、后端、数据库等组件。部署过程包括克隆代码、配置环境变量和启动服务,首次启动需3-10分钟下载镜像。文章详细讲解了.env文件的配置要点,包括服务地址、数据库连接和向量存储设置,并提供了生产环境安全加固建议。最后通过访问/install页面完成管理员账号初始化,即可开始使用Dify构建AI应用。

海兰 585

Touch panel DTS 分析(MSM8994平台,Atmel 芯片)

Touch panel DTS 分析(MSM8994平台,Atmel 芯片) 在MSM8994平台下,Touch panel的DTS节点写在/kernel/arch/arm/boot/dts/qcom/msm8994-mtp.dtsi文件中。具体代码如下: &soc {           i2c@f9924000 {                              

LinuxEngineer的专栏 6079

onnxruntime模型部署(一)-pythonAPI

简单模型的onnx模型的导出,以及onnxruntime推理引擎的模型部署

qq_45983373的博客 4059

【Android驱动】驱动中regulator_get解析和regulator_set_voltage设置电源脚电压的一个问题

背景: 延续上一篇写的从app控制gpio电平,想从app通过framework--jni--driver来控制ldo,也就是pm8909_l8这种电源脚。 代码: diff --git a/kernel/drivers/misc/chaoDriver/gpio_control.c b/kernel/drivers/misc/chaoDriver/gpio_control.c index a93f6c1..df33b71 100755 --- a/kernel/drivers/misc.

John_chaos的博客 4163

STM32电机库(ST-MC-Workbench)实战指南——三电阻电流采样电路参数配置详解

本文详细解析了STM32电机库(ST-MC-Workbench)中三电阻电流采样电路的参数配置方法,涵盖电阻选型、放大增益计算、滤波时间优化等关键步骤。通过实战案例和调试技巧,帮助工程师快速掌握电流采样技术,提升电机控制系统的精度与稳定性。特别针对ST-MC-Workbench界面参数设置提供了详细指导。

weixin_29186249的博客 505

硬件-汽车电子-TBOX/TCAM核心器件选型与系统集成设计指南

本文深入解析汽车电子TBOX/TCAM硬件架构与系统集成设计,涵盖核心器件选型、电源管理、信号完整性优化等关键点。重点分享5G模组选型避坑经验、MCU隐性指标及热设计验证方案,为车载通信系统开发提供实用指南。

weixin_30352645的博客 529

devm_regulator_get

设备树中配置资源结点,然后通过供应商接口调用devm_regulator_get来获取资源 /** * devm_regulator_get - Resource managed regulator_get() * @dev: device for regulator "consumer" * @id: Supply name or regulator ID. * * Managed regulator_get(). Regulators returned from this function a

wangkai6666的博客 7738

北邮LaTeX论文模板避坑指南:从TEX Live安装到完美编译(2024最新版)

本文详细介绍了2024年最新版北邮LaTeX论文模板的使用指南,涵盖TEX Live安装、中文配置、模板优化及常见问题解决方案。针对Windows系统用户,提供TeX Live与CTeX的对比分析,并给出高效排版和终稿检查的实用技巧,帮助研究生快速掌握LaTeX论文写作。

read5的博客 463

了解/linux-5.4.31/drivers/regulator/devres.c中的devm_regulator_get()和devm_regulator_bulk_get()

devm_regulator_get()和devm_regulator_bulk_get()的区别。

weixin_42550185的博客 1589

从零开始解析N-CMAPSS数据集:航空发动机健康管理的入门指南

本文详细解析了N-CMAPSS数据集在航空发动机健康管理中的应用,从数据集的构成、关键变量到实际数据分析方法,为初学者提供了全面的入门指南。通过Python代码示例,展示了如何加载、探索和建模这一复杂数据集,帮助读者掌握航空发动机性能预测的核心技术。

weixin_29063979的博客 319

基于Xilinx Artix7 的FPGA高级应用 (二):千兆以太网通信(实战篇)第一期

本项目是基于Xlinx Artix7 XC7A35T芯片 以太网芯片选用的是RTL8211EG PHY芯片 MAC 和PHY接口标准是GMII 开发工具是vivado 2018.3 我们先来复习一下以太网的基本通信原理: 当我们的计算机需要与局域网中另外的设备进行通信的时候,需要将数据传输到网卡进行编码,然后传输到线上,经过另一个设备的网卡解码成该设备能读取的数据。 关于以太网协议的知识在原理篇中已经讲过,不再重复,下面直接看接收代码: 首先注意我们的MAC和PHY通信选择的是GMII接口标准,发送数据一

工大技术底层人员的博客 4033

深入解析devm_regulator_get:Linux电源管理的自动化资源获取机制

本文深入解析Linux内核中的`devm_regulator_get`函数,探讨其作为自动化电源管理接口的核心机制。通过设备树配置、函数调用栈分析及实战案例,详细说明如何实现电源资源的智能获取与释放,避免内存泄漏,并优化电源管理策略。适用于嵌入式开发中高效、安全的电源控制场景。

weixin_42525264的博客 292

YOLOv8架构革命:通过EfficientViT融合实现精度-速度的帕累托突破

目标检测领域长期存在精度与速度的权衡难题。视觉Transformer(ViT)的引入解决了长距离依赖问题,但其巨大的计算复杂度制约了实时应用。最新研究表明,将轻量级ViT与YOLO架构融合,可在几乎不损失推理速度的前提下,将mAP提升3-8个百分点。这种架构改进方案已在工业检测、自动驾驶、安防监控等多个领域得到验证,在保持实时性的同时显著提升了复杂场景下的检测可靠性。通过模块化设计,可以灵活适配不同规模的YOLOv8模型,为实际应用提供精度-速度的帕累托最优解。

FJN110的博客 148

regulator_get 调用过程【转】

本文转载自:http://blog.youkuaiyun.com/u012719256/article/details/52083961 Touch panel DTS 分析(MSM8994平台,Atmel 芯片) 在MSM8994平台下,Touch panel的DTS节点写在/kernel/arch/arm/boot/dts/qcom/msm8994-mtp.dtsi文件中。具体代码如下...

618

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

regulator_get 调用过程

Touch panel DTS 分析(MSM8994平台,Atmel 芯片) 标签: linux内核parseDTS 2014-10-28 11:29 1986人阅读 评论(0) 收藏 举报 本文章已收录于: 分类: Kernel function(12) 作者同类文章X 驱动程序(5)

☆ 默默地牛逼着 1万+

Linux下的regulator调试

先看regular使用的小demo,如 i2c8{ touchscreen@28 { vddcama-supply = <&xxxxx>; }; } int ret; struct regulator *power; static int ts_probe(struct i2c_client *client,const struct...

Android开发 4520

Linux regulator子系统分析之三 相关的接口说明

在上一章我们介绍了regulator子系统相关的数据结构间的关联以及每一个数据结构的定义。针对数据结构间的关联则需要regulator子系统提供的接口实现。而本章我们就说明这些接口。本章的章节如下: 一、regulator device的注册与注销 二、regulator的注册与注销(regulator device的使用者) 三、regulator子系统提供的接口 一、regulator device的注册与注销 针对regulator dev...

lickylin的专栏 1993

Linux regulator子系统分析2

Linux regulator子系统分析2(基于Linux6.6)---数据结构介绍

ListQ的博客 784
上一篇: mtk打印spi注册log
下一篇: c语言 int与byte[]互相转换
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值