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