About Kernel Documentation Linux Kernel Contact Linux Resources Linux Blog

Documentation / power / regulator / machine.txt


Based on kernel version 4.16.1. Page generated on 2018-04-09 11:53 EST.

1	Regulator Machine Driver Interface
2	===================================
3	
4	The regulator machine driver interface is intended for board/machine specific
5	initialisation code to configure the regulator subsystem.
6	
7	Consider the following machine :-
8	
9	  Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V]
10	               |
11	               +-> [Consumer B @ 3.3V]
12	
13	The drivers for consumers A & B must be mapped to the correct regulator in
14	order to control their power supplies. This mapping can be achieved in machine
15	initialisation code by creating a struct regulator_consumer_supply for
16	each regulator.
17	
18	struct regulator_consumer_supply {
19		const char *dev_name;	/* consumer dev_name() */
20		const char *supply;	/* consumer supply - e.g. "vcc" */
21	};
22	
23	e.g. for the machine above
24	
25	static struct regulator_consumer_supply regulator1_consumers[] = {
26		REGULATOR_SUPPLY("Vcc", "consumer B"),
27	};
28	
29	static struct regulator_consumer_supply regulator2_consumers[] = {
30		REGULATOR_SUPPLY("Vcc", "consumer A"),
31	};
32	
33	This maps Regulator-1 to the 'Vcc' supply for Consumer B and maps Regulator-2
34	to the 'Vcc' supply for Consumer A.
35	
36	Constraints can now be registered by defining a struct regulator_init_data
37	for each regulator power domain. This structure also maps the consumers
38	to their supply regulators :-
39	
40	static struct regulator_init_data regulator1_data = {
41		.constraints = {
42			.name = "Regulator-1",
43			.min_uV = 3300000,
44			.max_uV = 3300000,
45			.valid_modes_mask = REGULATOR_MODE_NORMAL,
46		},
47		.num_consumer_supplies = ARRAY_SIZE(regulator1_consumers),
48		.consumer_supplies = regulator1_consumers,
49	};
50	
51	The name field should be set to something that is usefully descriptive
52	for the board for configuration of supplies for other regulators and
53	for use in logging and other diagnostic output.  Normally the name
54	used for the supply rail in the schematic is a good choice.  If no
55	name is provided then the subsystem will choose one.
56	
57	Regulator-1 supplies power to Regulator-2. This relationship must be registered
58	with the core so that Regulator-1 is also enabled when Consumer A enables its
59	supply (Regulator-2). The supply regulator is set by the supply_regulator
60	field below and co:-
61	
62	static struct regulator_init_data regulator2_data = {
63		.supply_regulator = "Regulator-1",
64		.constraints = {
65			.min_uV = 1800000,
66			.max_uV = 2000000,
67			.valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
68			.valid_modes_mask = REGULATOR_MODE_NORMAL,
69		},
70		.num_consumer_supplies = ARRAY_SIZE(regulator2_consumers),
71		.consumer_supplies = regulator2_consumers,
72	};
73	
74	Finally the regulator devices must be registered in the usual manner.
75	
76	static struct platform_device regulator_devices[] = {
77		{
78			.name = "regulator",
79			.id = DCDC_1,
80			.dev = {
81				.platform_data = &regulator1_data,
82			},
83		},
84		{
85			.name = "regulator",
86			.id = DCDC_2,
87			.dev = {
88				.platform_data = &regulator2_data,
89			},
90		},
91	};
92	/* register regulator 1 device */
93	platform_device_register(&regulator_devices[0]);
94	
95	/* register regulator 2 device */
96	platform_device_register(&regulator_devices[1]);
Hide Line Numbers


About Kernel Documentation Linux Kernel Contact Linux Resources Linux Blog