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