_devm_regulator_get/regulator_get

电源管理芯片之 Regulator用法。

2014年12月22日 17:27:02

阅读数:1289

有问题请加:Q群: 241359063  共同走向创业学习之旅。
原创:kylin_zeng  http://blog.chinaunix.net/uid/23795897.html 
转载请注明原创出处,尊重他人的劳动成果。

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

2016年11月05日 15:37:33

阅读数:169

 

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

猜你喜欢

转载自blog.csdn.net/u010388659/article/details/81254255
get