diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-03-03 06:40:02 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-03-03 11:32:47 -0500 |
commit | 613330a0f73b2698b2210ea89092eb56635fc5d8 (patch) | |
tree | 1f7c5c94bc5c9e28ef54e29c310ae276499ba5e3 /drivers/regulator/fixed-helper.c | |
parent | 6b21d18ed50c7d145220b0724ea7f2613abf0f95 (diff) |
regulator: provide a helper for registering a fixed regulator
Some devices require a regulator to work, but boards may not have
a software controllable regulator for this device. Provide a helper
function to make it simpler for these boards to register a fixed
regulator as a dummy regulator.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/fixed-helper.c')
-rw-r--r-- | drivers/regulator/fixed-helper.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/drivers/regulator/fixed-helper.c b/drivers/regulator/fixed-helper.c new file mode 100644 index 000000000000..30d0a15b8949 --- /dev/null +++ b/drivers/regulator/fixed-helper.c | |||
@@ -0,0 +1,53 @@ | |||
1 | #include <linux/slab.h> | ||
2 | #include <linux/platform_device.h> | ||
3 | #include <linux/regulator/machine.h> | ||
4 | #include <linux/regulator/fixed.h> | ||
5 | |||
6 | struct fixed_regulator_data { | ||
7 | struct fixed_voltage_config cfg; | ||
8 | struct regulator_init_data init_data; | ||
9 | struct platform_device pdev; | ||
10 | }; | ||
11 | |||
12 | static void regulator_fixed_release(struct device *dev) | ||
13 | { | ||
14 | struct fixed_regulator_data *data = container_of(dev, | ||
15 | struct fixed_regulator_data, pdev.dev); | ||
16 | kfree(data); | ||
17 | } | ||
18 | |||
19 | /** | ||
20 | * regulator_register_fixed - register a no-op fixed regulator | ||
21 | * @name: supply name | ||
22 | * @id: platform device id | ||
23 | * @supplies: consumers for this regulator | ||
24 | * @num_supplies: number of consumers | ||
25 | */ | ||
26 | struct platform_device *regulator_register_fixed(int id, | ||
27 | struct regulator_consumer_supply *supplies, int num_supplies) | ||
28 | { | ||
29 | struct fixed_regulator_data *data; | ||
30 | |||
31 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
32 | if (!data) | ||
33 | return NULL; | ||
34 | |||
35 | data->cfg.supply_name = "dummy"; | ||
36 | data->cfg.microvolts = 0; | ||
37 | data->cfg.gpio = -EINVAL; | ||
38 | data->cfg.enabled_at_boot = 1; | ||
39 | data->cfg.init_data = &data->init_data; | ||
40 | |||
41 | data->init_data.constraints.always_on = 1; | ||
42 | data->init_data.consumer_supplies = supplies; | ||
43 | data->init_data.num_consumer_supplies = num_supplies; | ||
44 | |||
45 | data->pdev.name = "reg-fixed-voltage"; | ||
46 | data->pdev.id = id; | ||
47 | data->pdev.dev.platform_data = &data->cfg; | ||
48 | data->pdev.dev.release = regulator_fixed_release; | ||
49 | |||
50 | platform_device_register(&data->pdev); | ||
51 | |||
52 | return &data->pdev; | ||
53 | } | ||