Concept: Regulator :
Power chip, such as voltage conversion chip Voltage range Supply : The component that provides power, Regulator is a Supply; Regulator A can supply power to Regulator B, then the Supply of Regulator B is A
The driver of the regulator power chip itself: .enable, .diable, .set_voltage, .set_current
Consumer works in the driver's function that references the regulator
machine (single board): 1. Correspondence between Regulator and Consumer
2. Constraints: board-related conditions, such as voltage range
(For detailed documentation, see overview.txt and other documents in the Documentation/power/regulator directory under the top-level kernel directory)
Write a driver:
1. regulator: (refer to drivers/regulator/tps6105x-regulator.c)
register a platform_driver: allocate, set, register a regulator in its probe function
What to do in "settings": implement the regulator Operations, such as enable, disable, set_voltage
Obtain the private data set on the machine side through dev_get_platdata in the probe function of the
regulator
(eg voltage range)
Set platform_data private data (correspondence between regulator and consumer, constraints) in .dev in platform_device on the machine side. This private data is used by regulator when registering
3. consumer: 使用即可: regulator_get, regulator_enable, regulator_disable, regulator_set_voltage....
regulator_register process analysis:
// allocate regulator_dev
rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
/* set regulator constraints */
set_machine_constraints
add_regulator_attributes
/* add consumers devices */
set_consumer_device_supply
generates a regulator_map in the regulator_map_list list: it contains dev_name (the name of the consumer), supply (the name of the power pin of the consumer)
// 把regulator_dev放入regulator_list
list_add(&rdev->list, ®ulator_list);
编译测试:
1. make menuconfig
Device Drivers --->
[*] Voltage and Current Regulator Support --->
Modify drivers/video/Makefile to remove the original LCD driver
#obj-$(CONFIG_FB_S3C2410) += lcd_4.3.o
make uImage
2. Compile the driver
3. Boot with the new kernel
4. Install the driver: