162306a36Sopenharmony_ci================================== 262306a36Sopenharmony_ciRegulator Machine Driver Interface 362306a36Sopenharmony_ci================================== 462306a36Sopenharmony_ci 562306a36Sopenharmony_ciThe regulator machine driver interface is intended for board/machine specific 662306a36Sopenharmony_ciinitialisation code to configure the regulator subsystem. 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciConsider the following machine:: 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V] 1162306a36Sopenharmony_ci | 1262306a36Sopenharmony_ci +-> [Consumer B @ 3.3V] 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ciThe drivers for consumers A & B must be mapped to the correct regulator in 1562306a36Sopenharmony_ciorder to control their power supplies. This mapping can be achieved in machine 1662306a36Sopenharmony_ciinitialisation code by creating a struct regulator_consumer_supply for 1762306a36Sopenharmony_cieach regulator:: 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci struct regulator_consumer_supply { 2062306a36Sopenharmony_ci const char *dev_name; /* consumer dev_name() */ 2162306a36Sopenharmony_ci const char *supply; /* consumer supply - e.g. "vcc" */ 2262306a36Sopenharmony_ci }; 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_cie.g. for the machine above:: 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci static struct regulator_consumer_supply regulator1_consumers[] = { 2762306a36Sopenharmony_ci REGULATOR_SUPPLY("Vcc", "consumer B"), 2862306a36Sopenharmony_ci }; 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci static struct regulator_consumer_supply regulator2_consumers[] = { 3162306a36Sopenharmony_ci REGULATOR_SUPPLY("Vcc", "consumer A"), 3262306a36Sopenharmony_ci }; 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ciThis maps Regulator-1 to the 'Vcc' supply for Consumer B and maps Regulator-2 3562306a36Sopenharmony_cito the 'Vcc' supply for Consumer A. 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ciConstraints can now be registered by defining a struct regulator_init_data 3862306a36Sopenharmony_cifor each regulator power domain. This structure also maps the consumers 3962306a36Sopenharmony_cito their supply regulators:: 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci static struct regulator_init_data regulator1_data = { 4262306a36Sopenharmony_ci .constraints = { 4362306a36Sopenharmony_ci .name = "Regulator-1", 4462306a36Sopenharmony_ci .min_uV = 3300000, 4562306a36Sopenharmony_ci .max_uV = 3300000, 4662306a36Sopenharmony_ci .valid_modes_mask = REGULATOR_MODE_NORMAL, 4762306a36Sopenharmony_ci }, 4862306a36Sopenharmony_ci .num_consumer_supplies = ARRAY_SIZE(regulator1_consumers), 4962306a36Sopenharmony_ci .consumer_supplies = regulator1_consumers, 5062306a36Sopenharmony_ci }; 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ciThe name field should be set to something that is usefully descriptive 5362306a36Sopenharmony_cifor the board for configuration of supplies for other regulators and 5462306a36Sopenharmony_cifor use in logging and other diagnostic output. Normally the name 5562306a36Sopenharmony_ciused for the supply rail in the schematic is a good choice. If no 5662306a36Sopenharmony_ciname is provided then the subsystem will choose one. 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ciRegulator-1 supplies power to Regulator-2. This relationship must be registered 5962306a36Sopenharmony_ciwith the core so that Regulator-1 is also enabled when Consumer A enables its 6062306a36Sopenharmony_cisupply (Regulator-2). The supply regulator is set by the supply_regulator 6162306a36Sopenharmony_cifield below and co:: 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci static struct regulator_init_data regulator2_data = { 6462306a36Sopenharmony_ci .supply_regulator = "Regulator-1", 6562306a36Sopenharmony_ci .constraints = { 6662306a36Sopenharmony_ci .min_uV = 1800000, 6762306a36Sopenharmony_ci .max_uV = 2000000, 6862306a36Sopenharmony_ci .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE, 6962306a36Sopenharmony_ci .valid_modes_mask = REGULATOR_MODE_NORMAL, 7062306a36Sopenharmony_ci }, 7162306a36Sopenharmony_ci .num_consumer_supplies = ARRAY_SIZE(regulator2_consumers), 7262306a36Sopenharmony_ci .consumer_supplies = regulator2_consumers, 7362306a36Sopenharmony_ci }; 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ciFinally the regulator devices must be registered in the usual manner:: 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci static struct platform_device regulator_devices[] = { 7862306a36Sopenharmony_ci { 7962306a36Sopenharmony_ci .name = "regulator", 8062306a36Sopenharmony_ci .id = DCDC_1, 8162306a36Sopenharmony_ci .dev = { 8262306a36Sopenharmony_ci .platform_data = ®ulator1_data, 8362306a36Sopenharmony_ci }, 8462306a36Sopenharmony_ci }, 8562306a36Sopenharmony_ci { 8662306a36Sopenharmony_ci .name = "regulator", 8762306a36Sopenharmony_ci .id = DCDC_2, 8862306a36Sopenharmony_ci .dev = { 8962306a36Sopenharmony_ci .platform_data = ®ulator2_data, 9062306a36Sopenharmony_ci }, 9162306a36Sopenharmony_ci }, 9262306a36Sopenharmony_ci }; 9362306a36Sopenharmony_ci /* register regulator 1 device */ 9462306a36Sopenharmony_ci platform_device_register(®ulator_devices[0]); 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci /* register regulator 2 device */ 9762306a36Sopenharmony_ci platform_device_register(®ulator_devices[1]); 98