machine.txt 2.6 KB
Newer Older
1 2 3 4
Regulator Machine Driver Interface
===================================

The regulator machine driver interface is intended for board/machine specific
5
initialisation code to configure the regulator subsystem.
6 7 8 9 10 11 12 13 14

Consider the following machine :-

  Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V]
               |
               +-> [Consumer B @ 3.3V]

The drivers for consumers A & B must be mapped to the correct regulator in
order to control their power supply. This mapping can be achieved in machine
15 16 17 18 19 20 21
initialisation code by creating a struct regulator_consumer_supply for
each regulator.

struct regulator_consumer_supply {
	struct device *dev;	/* consumer */
	const char *supply;	/* consumer supply - e.g. "vcc" */
};
22

23
e.g. for the machine above
24

25 26 27 28 29
static struct regulator_consumer_supply regulator1_consumers[] = {
{
	.dev	= &platform_consumerB_device.dev,
	.supply	= "Vcc",
},};
30

31 32 33 34 35
static struct regulator_consumer_supply regulator2_consumers[] = {
{
	.dev	= &platform_consumerA_device.dev,
	.supply	= "Vcc",
},};
36 37 38 39

This maps Regulator-1 to the 'Vcc' supply for Consumer B and maps Regulator-2
to the 'Vcc' supply for Consumer A.

40 41 42 43 44 45 46 47 48 49 50 51 52
Constraints can now be registered by defining a struct regulator_init_data
for each regulator power domain. This structure also maps the consumers
to their supply regulator :-

static struct regulator_init_data regulator1_data = {
	.constraints = {
		.min_uV = 3300000,
		.max_uV = 3300000,
		.valid_modes_mask = REGULATOR_MODE_NORMAL,
	},
	.num_consumer_supplies = ARRAY_SIZE(regulator1_consumers),
	.consumer_supplies = regulator1_consumers,
};
53 54 55

Regulator-1 supplies power to Regulator-2. This relationship must be registered
with the core so that Regulator-1 is also enabled when Consumer A enables it's
56 57 58 59 60 61 62 63 64 65 66 67 68
supply (Regulator-2). The supply regulator is set by the supply_regulator_dev
field below:-

static struct regulator_init_data regulator2_data = {
	.supply_regulator_dev = &platform_regulator1_device.dev,
	.constraints = {
		.min_uV = 1800000,
		.max_uV = 2000000,
		.valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
		.valid_modes_mask = REGULATOR_MODE_NORMAL,
	},
	.num_consumer_supplies = ARRAY_SIZE(regulator2_consumers),
	.consumer_supplies = regulator2_consumers,
69 70
};

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
Finally the regulator devices must be registered in the usual manner.

static struct platform_device regulator_devices[] = {
{
	.name = "regulator",
	.id = DCDC_1,
	.dev = {
		.platform_data = &regulator1_data,
	},
},
{
	.name = "regulator",
	.id = DCDC_2,
	.dev = {
		.platform_data = &regulator2_data,
	},
},
88
};
89
/* register regulator 1 device */
W
Wolfram Sang 已提交
90
platform_device_register(&regulator_devices[0]);
91

92
/* register regulator 2 device */
W
Wolfram Sang 已提交
93
platform_device_register(&regulator_devices[1]);