18c2ecf20Sopenharmony_ci==================================
28c2ecf20Sopenharmony_ciRegulator Machine Driver Interface
38c2ecf20Sopenharmony_ci==================================
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciThe regulator machine driver interface is intended for board/machine specific
68c2ecf20Sopenharmony_ciinitialisation code to configure the regulator subsystem.
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciConsider the following machine::
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci  Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V]
118c2ecf20Sopenharmony_ci               |
128c2ecf20Sopenharmony_ci               +-> [Consumer B @ 3.3V]
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciThe drivers for consumers A & B must be mapped to the correct regulator in
158c2ecf20Sopenharmony_ciorder to control their power supplies. This mapping can be achieved in machine
168c2ecf20Sopenharmony_ciinitialisation code by creating a struct regulator_consumer_supply for
178c2ecf20Sopenharmony_cieach regulator::
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci  struct regulator_consumer_supply {
208c2ecf20Sopenharmony_ci	const char *dev_name;	/* consumer dev_name() */
218c2ecf20Sopenharmony_ci	const char *supply;	/* consumer supply - e.g. "vcc" */
228c2ecf20Sopenharmony_ci  };
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cie.g. for the machine above::
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci  static struct regulator_consumer_supply regulator1_consumers[] = {
278c2ecf20Sopenharmony_ci	REGULATOR_SUPPLY("Vcc", "consumer B"),
288c2ecf20Sopenharmony_ci  };
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci  static struct regulator_consumer_supply regulator2_consumers[] = {
318c2ecf20Sopenharmony_ci	REGULATOR_SUPPLY("Vcc", "consumer A"),
328c2ecf20Sopenharmony_ci  };
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciThis maps Regulator-1 to the 'Vcc' supply for Consumer B and maps Regulator-2
358c2ecf20Sopenharmony_cito the 'Vcc' supply for Consumer A.
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ciConstraints can now be registered by defining a struct regulator_init_data
388c2ecf20Sopenharmony_cifor each regulator power domain. This structure also maps the consumers
398c2ecf20Sopenharmony_cito their supply regulators::
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci  static struct regulator_init_data regulator1_data = {
428c2ecf20Sopenharmony_ci	.constraints = {
438c2ecf20Sopenharmony_ci		.name = "Regulator-1",
448c2ecf20Sopenharmony_ci		.min_uV = 3300000,
458c2ecf20Sopenharmony_ci		.max_uV = 3300000,
468c2ecf20Sopenharmony_ci		.valid_modes_mask = REGULATOR_MODE_NORMAL,
478c2ecf20Sopenharmony_ci	},
488c2ecf20Sopenharmony_ci	.num_consumer_supplies = ARRAY_SIZE(regulator1_consumers),
498c2ecf20Sopenharmony_ci	.consumer_supplies = regulator1_consumers,
508c2ecf20Sopenharmony_ci  };
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciThe name field should be set to something that is usefully descriptive
538c2ecf20Sopenharmony_cifor the board for configuration of supplies for other regulators and
548c2ecf20Sopenharmony_cifor use in logging and other diagnostic output.  Normally the name
558c2ecf20Sopenharmony_ciused for the supply rail in the schematic is a good choice.  If no
568c2ecf20Sopenharmony_ciname is provided then the subsystem will choose one.
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciRegulator-1 supplies power to Regulator-2. This relationship must be registered
598c2ecf20Sopenharmony_ciwith the core so that Regulator-1 is also enabled when Consumer A enables its
608c2ecf20Sopenharmony_cisupply (Regulator-2). The supply regulator is set by the supply_regulator
618c2ecf20Sopenharmony_cifield below and co::
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci  static struct regulator_init_data regulator2_data = {
648c2ecf20Sopenharmony_ci	.supply_regulator = "Regulator-1",
658c2ecf20Sopenharmony_ci	.constraints = {
668c2ecf20Sopenharmony_ci		.min_uV = 1800000,
678c2ecf20Sopenharmony_ci		.max_uV = 2000000,
688c2ecf20Sopenharmony_ci		.valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
698c2ecf20Sopenharmony_ci		.valid_modes_mask = REGULATOR_MODE_NORMAL,
708c2ecf20Sopenharmony_ci	},
718c2ecf20Sopenharmony_ci	.num_consumer_supplies = ARRAY_SIZE(regulator2_consumers),
728c2ecf20Sopenharmony_ci	.consumer_supplies = regulator2_consumers,
738c2ecf20Sopenharmony_ci  };
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciFinally the regulator devices must be registered in the usual manner::
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci  static struct platform_device regulator_devices[] = {
788c2ecf20Sopenharmony_ci	{
798c2ecf20Sopenharmony_ci		.name = "regulator",
808c2ecf20Sopenharmony_ci		.id = DCDC_1,
818c2ecf20Sopenharmony_ci		.dev = {
828c2ecf20Sopenharmony_ci			.platform_data = &regulator1_data,
838c2ecf20Sopenharmony_ci		},
848c2ecf20Sopenharmony_ci	},
858c2ecf20Sopenharmony_ci	{
868c2ecf20Sopenharmony_ci		.name = "regulator",
878c2ecf20Sopenharmony_ci		.id = DCDC_2,
888c2ecf20Sopenharmony_ci		.dev = {
898c2ecf20Sopenharmony_ci			.platform_data = &regulator2_data,
908c2ecf20Sopenharmony_ci		},
918c2ecf20Sopenharmony_ci	},
928c2ecf20Sopenharmony_ci  };
938c2ecf20Sopenharmony_ci  /* register regulator 1 device */
948c2ecf20Sopenharmony_ci  platform_device_register(&regulator_devices[0]);
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci  /* register regulator 2 device */
978c2ecf20Sopenharmony_ci  platform_device_register(&regulator_devices[1]);
98