The humble opinion of Linux regulator "turn"

Source: Internet
Author: User
Tags mutex

transferred from: http://blog.csdn.net/batoom/article/details/17081651 1: Basic concept of the CalibratorThe so-called calibrator is actually under the control of the software input power regulation carefully output.

The regulator module is used to control the voltage/current supply of certain devices in the system. In embedded systems (especially mobile phones), it is important to control the power consumption, which directly affects the battery life. Therefore, if a module in the system temporarily does not need to use, you can turn off its power supply through the regulator, or reduce the voltage, current size provided to the module.

The regulator document is in Kernel/documentation/power/regulator.

2. Several important structures:

Regulator_dev

Regulator_dev represents a regulator device.

struct Regulator_dev {

struct REGULATOR_DESC *desc; Descriptors, including regulator name, ID, Regulator_ops, etc.

int use_count; Usage count

/* Lists We belong to */

struct List_head list; Regulator is linked to the regulator_list linked list through this structure

struct List_head slist; If there is a parent regulator, the linked list that is hung to the parent regulator through this field

/* Lists We own */

struct List_head consumer_list; This regulator is responsible for powering the list of devices

struct List_head supply_list; This regulator is responsible for powering the sub-regulator

struct Blocking_notifier_head notifier; Notifier, the specific value in Consumer.h, such as Regulator_event_fail

struct mutex mutex;

struct module *owner;

struct device dev; Device structure, belonging to class Regulator_class

struct regulation_constraints *constraints; Limits, such as maximum voltage/current, minimum voltage/current

struct Regulator_dev *supply; Pointer to parent regulator

void *reg_data; /* REGULATOR_DEV Data */

};

Regulator_init_data

Regulator_init_data is used during initialization to establish a tree-like structure between a parent-child regulator, a power module, and some basic parameters of regulator.

struct Regulator_init_data {

struct device *supply_regulator_dev; Pointer to parent regulator

struct regulation_constraints constraints;

int num_consumer_supplies;

struct regulator_consumer_supply *consumer_supplies; Array of equipment responsible for power supply

/* Optional Regulator Machine specific init */

Int (*regulator_init) (void *driver_data); initialization function

void *driver_data; /* Core does not touch this */

};

Other structures can see for themselves

struct regulator-------> Equipment Drives direct operation of the structure body

struct regulation_constraints----->regulator limits, and other information is

struct Regulator_init_data, for initialization

struct Regulator_consumer_supply----->consumer Information

struct REGULATOR_DESC-----> This is a lot of attention, there is a true operation device function structure ~

struct REGULATOR_MAP-----> This corresponds to the consumers and regulator table

In general, we need to fill some structure in the board level file, such as struct regulator_init_data, which is called when regulator is initialized, and in general the Power Management PMU is an i²c device, so the struct Regulator_init_data are often transmitted as private data of i²c, and because a PMU module controls more than one module voltage, usually multiple, it requires multiple struct regulator_init_data structures, and is usually defined as a struct regulator_init_data xxxx[] array structure and calls Platform_device_add () to register the device (struct regulator_init_data struct as struct The platformdata in the struct devices in Platform_device).

Regulator_desc

struct regulator_described{

const char* name;

int id;

unsigned n_voltages;

struct Regulator_ops *ops;

int IRQ;

Enum Regulator_type type;

struct module *owner;

}

3, registered regulator

Board level information and REGULATOR_DESC are ready to register.

A regulator_dev is generated by registering with the Regulator_register function.

struct Regulator_dev *regulator_register (struct regulator_desc *regulator_desc, struct device *dev, struct REGULATOR_ Init_data *init_data,void *driver_data)

{

struct Regulator_dev *rdev;

....

fill struct REGULATOR_DEV structure;

Device_register (&rdev->dev); Registering your device

Set the constraints, which may include the initialization of the power state (setting the initial voltage, enable/disable, etc.)

Set_machine_constraints (Rdev, &init_data->constraints);

Add_regulator_attributes (Rdev);

Set up the connection between this regulator and the equipment it is responsible for powering

for (i = 0; i < init_data->num_consumer_supplies; i++)

ret = set_consumer_device_supply (Rdev, Init_data->consumer_supplies[i].dev,

init_data->consumer_supplies[i].supply);

Add regulator to a linked list that contains all the regulator

List_add (&rdev->list, &regulator_list);

.......

}

The Set_consumer_device_supply function is used to register the correspondence between the Regulator_dev and the Comsumer_dev (regulator is responsible for powering the device). For each pair of Regulator_dev-comsumer_dev, there will be a REGULATOR_MAP structure, which will be added to the global linked list regulator_map_list.

4. Regulator Application

When device drivers use regulator to power their drives, it is necessary to first ensure that the matching relationship between the device and the corresponding regulator has been registered in the regulator frame.

The device driver obtains the regulator structure through the Regulator_get function, this function finds the corresponding Regulator_dev by the regulator_map_list described above, and then generates the regulator structure for the user to use.

By regulator_enable/regulator_disable opening and closing regulator, both functions eventually call the corresponding members in the struct regulator_ops.

Besides, there are regualtor_set_voltage/regulator_get_voltage and so on.

Specific code view:/kernel/driver/regulator/core.c

The humble opinion of Linux regulator "turn"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.