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