电源管理芯片之 Regulator用法。

1、电源管理 Regulator 分成静态和动态:静态不需要改变电压电流,只需要开光电源,用在bootloader,firmware,kernel board 阶段等。动态,根据需要改变电压电流。

2、获取设备的regulator,dev为驱动对应的设备指针,可以用NULL,Vcc为电源的ID,内核会查表找到电源ID对应的regulator。如:struct regulator *ldo; ldo=regulator_get(NULL,"act_ldo5");

2.1、regulator = regulator_get(dev, "Vcc");//获取设备regulator.

3、regulator_put(regulator);   //释放regulator。

4、int regulator_enable(regulator);//使能电源输出。调用之前也可能已经使能了。所以用下面函数判断。

5、int regulaor_is_enabled(regulator); //判断是否使能,>0 表示已经使能。

6、int regulator_disable(regulator);//关闭电源输出。但是未必立刻关闭,有可以存在电源共享的场景。

7、int regulator_force_disable(regulator);//强制关闭电源。

8、int regulator_set_voltage(regulator,min_uV,max_uV);//调节电压的最小和最大输出。如果接下去调用regulator_enable ,那么这个值马上就生效,如果调用regulator_disable等其他的,要等到下一次调用regulator_enable时才能生效。

9、int regulator_get_voltage(regulator); //通过此接口获取配置的输出电压。

10、例如:
     regulator_set_voltage(ldo_28, 2800000, 2800000); //设置电压。
     regulator_enable(ldo_28); //使能。
     int value=regulator_get_voltage(ldo_28)); //获取电压值。
   
     regulator_put(ldo_28); //释放。

Regulator framework

1 General description

Voltage Regulator & current regulator 电压调节器和电流调节器

在Linux中,regulator framework提供标准的API区控制regulator设备。这样做的目的是动态的调节电源的使用,以达到节能。

1.1 Regulator:

电压或电流调节器,分类

1.2 Power domain:

连接在同一个输出源上的设备在同一个domain里,这个输出源叫做一个power domain。常见的输出源有switch、regulator。

下面的图片中有三个power domain:

Domain1:switch 1 、consumer D 、consumer E

Domain2:switch 2 、consumer B 、consumer C

Domain3:consumer A

它们之间的supply 关系:domain 1--> domain 2--> domain 3

1.3 constraints

Constraint用来定义电压电流的设置来保护设备,分为三个等级:

l regulator level: 限定regulator的电压与电源的使用范围

l Domain level:   限定power domain的电压与电流的使用范围

l Consumer leve: 限定consumer的电压与电流的使用范围

如果有一个LCD backlight driver申请将电流从5ma调至10ma,那么要依次查看下面几个电流的限制,全部通过时才能申请到电流值:

ü Consumer:查找LCD的brightness table,看10ma是否在table中

ü Power Domain:电流的大小是否在power domain的当前状态下的电流限制范围内

ü Regulator:是否超过regulator的参数限制

2 Framework

Regulator framework主要有一下几个部分组成:

l Consumer driver interface:

consumer使用framework提供API来get、put regulator,get、set voltage & current 的limit和mode,enable、disable。通过这下接口,consumer的driver就可以完全控制device所连接的regulator

l Regulator interface:

Regulator driver向core注册regulator即其操作方法

l Machine:

Machine specific code为每个regulator创建voltage/current的domain,并提供电压电流限制来防止过压或过流

l Userspace interface

Framework通过sysfs向userspace提供一些电源使用的情况

2.1 provider device driver

A provider that is usually a PMIC may contain one or more regulators.All of these regulators are defined in a global static match table whose data strcture is of_regulator_match.Example of match table for PF3000:

static struct of_regulator_match pfuze3000_matches[] = {

{ .name = "sw1a",       },

{ .name = "sw1b",       },

{ .name = "sw2",        },

{ .name = "sw3",        },

{ .name = "swbst",      },

{ .name = "vsnvs",      },

{ .name = "vrefddr",    },

{ .name = "vldo1",      },

{ .name = "vldo2",      },

{ .name = "vccsd",      },

{ .name = "v33",        },

{ .name = "vldo3",      },

{ .name = "vldo4",      },

};

This table just list all the regulators that a privider can provide,that doesn’t mean all these regulator will be used.

During the procedure of probe for the provider, every component of the match table will be compared with all the regulators that are actually used by name.And all matches will be initialized according to device node. function “of_regulator_match” is respomsible for this process. After this, all the information from device node for regulators actually used are described in match table.

Each regulator registered with the core is described with a struct regulator_desc and regulator_config. Struct regulator_desc contains the non-varing parts of the regulator description and struct regulator_config contains the run time variable parts of the reguletor description.

The regulator_desc structure for every regulator is declared in a static table,but the struct regulator_config for every regulator is initilized at run time,and information in match table will copyed to it.

After registerred, struct regulator_dev defines a registerred regualtor class device.

The defination of these structures are defined in “include/linux/regulator/driver.h”

Normally,a static array of this structure is define,each one describes a reguletor in provide which may be a PMIC. Take PF3000 as an example,all of its regulators are declared in pfuze3000_regulators[].

When you write a regulator driver,you may follow three steps:

Get device node of “regulators”

struct of_regulator_match 对应一个regulator node,kernel中通常以一个静态的table定义provider里所有的regulator node。如,pfuze3000_matches[],这个table用来和DTS中的regulator节点进行match,并将math的node所有信息解析到这个table中的对应record。

Provider(以PMIC为例)通常包括多个regulator,它在DTS表现为regulators节点的一个子节点。其中,regulators节点为’/’节点的子节点。

reg_sensor: regulator@4 {

compatible = "regulator-fixed";

reg = <4>;

regulator-name = "sensor-supply";

regulator-min-microvolt = <3300000>;

regulator-max-microvolt = <3300000>;

gpio = <&gpio2 31 0>;

startup-delay-us = <500>;

enable-active-high;

};

其中,reg_sensor是该regulator的标号,用来被consumer引用。

PMIC,通常以platform device方式注册到内核,它的probe方法必然包括以下几部分:

1) 调用of_regulator_match,初始化match[i]->init_data->constraint的相关域,这起始解释解析regulators下的所有regulator节点

2) 初始化config的相关域,config中的init_data域直接从match_table中获得

3) Descriptors,通常也是静态定义的table

4) 调用struct regulator_dev *devm_regulator_register(struct device *dev,

const struct regulator_desc *regulator_desc,

const struct regulator_config *config)

根据descriptor和config注册regulator

2.2 consumer device driver

1、Regulator consumer在DTS中的描述:

在consumer的node中以xxx-supply=<®ulator-lable>表示其consume的regulator。而这里xxx表示这个regulator的在consumer driver中的id。

(以mag3110为例):

mag3110@0e {

compatible = "fsl,mag3110";

reg = <0x0e>;

position = <2>;

vdd-supply = <®_sensor>;

vddio-supply = <®_sensor>;

interrupt-parent = <&gpio3>;

interrupts = <16 1>;

};

其中id为vdd和vddio的supply都是reg_sensor指向的这个regulator。

2、regulator consumer driver的probe方法:

Regulator consumer的probe过程第一步当然是给device上电了,这就需要使能它所连接的regulator。

vdd = devm_regulator_get(&client->dev, "vdd");

regulator_enable(vdd);

然后在进行consumerdevice自己的probe操作了。

Device register of provider

Consumer get source

电源管理芯片之 Regulator用法 Regulator framework相关推荐

  1. 电源管理芯片之 Regulator用法。

    有问题请加:Q群: 241359063  共同走向创业学习之旅. 原创:kylin_zeng  http://blog.chinaunix.net/uid/23795897.html  转载请注明原创 ...

  2. Regulator子系统

    基本介绍 Regulator指的是稳定器,有电压稳定器及电流稳定器两种,能够自动维持恒定电流或者电压.其中,电压稳定器voltage regulator在电路中比较常见.从设备驱动的角度来看,regu ...

  3. Robot Framework用户指南

    Robot Framework用户指南 版本2.8.6 版权所有©诺基亚解决方案和网络2008-2014 根据知识共享署名3.0 Unported许可授权 目录 1开始 1.1简介 1.2版权和许可 ...

  4. [转]新版.Net开发必备十大工具

    本文转自:http://www.cnblogs.com/zxhoo/archive/2011/04/02/2002905.html 几年前MSDN上的一篇文章<Ten Must-Have Too ...

  5. linux驱动编写(电源管理驱动)

    [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 对于嵌入式设备来说,合适的电源管理,不仅可以延长电池的寿命,而且可以省电,延长设备运行时间,在提 ...

  6. LINUX内核编译选项-5

    Device Drivers  ---> 驱动程序 Generic Driver Options  --->驱动程序通用选项 (/sbin/hotplug) path to uevent ...

  7. .NET 程序员必备工具下载(2)(完结)

    5.Reflector for .NET 相信大名鼎鼎的Reflector for .NET大家都已经用过了,几年前它已经位于.NET开发必备十大工具榜,现在自然也不能例外.它是一个类浏览器和反编译器 ...

  8. Linux电源管理(1)_整体架构 -- wowo

    1. 前言 在这个世界中,任何系统的运转都需要能量.如树木依靠光能生长,如马儿依靠食物奔跑,如计算机系统依靠电能运行.而能量的获取是有成本的,因此如果能在保证系统运转的基础上,尽量节省对能量的消耗,就 ...

  9. <Linux> Linux Power Management Overview

    Overview Generic PM 传统意义上的Power Management,如Power On/Off, Restart, Suspend to RAM/Disk等. Clock Frame ...

  10. 数字变化滚动到指定数字的文字特效

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

最新文章

  1. Django配置celery执行异步任务和定时任务
  2. java 实现约瑟夫环
  3. 单源最短路径-Dijkstra(迪杰斯特拉算法)
  4. Vista 系统C盘(系统盘)越来越小的问题.与解决.
  5. 存储过程能用if not exist_C++核心准则T.48:如果不能用概念,用enable_if
  6. tftp服务器连接开发板下载内核提示:retry count exceeded; starting again
  7. 倒计时1天,BDTC2016最新完整版日程公布
  8. Mysql,Zookeeper,Redis,Mongodb压力测试结果
  9. 【Elasticsearch】十九种Elasticsearch字符串搜索方式
  10. Adobe驳斥Flash过度耗电论 称HTML5更耗电
  11. Spring JMX之二:远程访问MBean(spring通过annotation暴露MBean)
  12. 视频教程-webservice入门到精通(备java基础,xml,javaee框架)-Java
  13. Win10系统下使用Setuna截图自动放大解决办法
  14. java 网吧计费系统_java网吧计费管理系统
  15. 清理redis集群的所有数据
  16. 用html写的意见调查表代码
  17. java视频会议系统 mcu_视频会议系统必须要用MCU吗
  18. 宽带服务器维护查询,网络连接状态查询方法
  19. 二级计算机c语言解题技巧,2010年全国计算机等级考试二级C语言考试题型解题技巧...
  20. zTree实现基本树

热门文章

  1. 网络安全笔记-18-ICMP 协议
  2. 最新小象学院python量化交易项目实战(完整)
  3. js问号点的作用(?.)和问号问号(??)的用法
  4. Pycharm问题:this applicatation failed to start because it could not find or laod the qt plaform plugin
  5. 浅谈stm32的低功耗模式
  6. sdnu oj 1357.Text Reverse 字符串
  7. 一个非常不错的JQ 插件库
  8. 和平精英显示与服务器断开连接,和平精英网络异常怎么办 网络异常解决方法...
  9. 树莓派系统安装和调试 总结整理篇
  10. DAVIS Driving Dataset 2020 (DDD20) 【转载】