diff options
-rw-r--r-- | drivers/regulator/Makefile | 2 | ||||
-rw-r--r-- | drivers/regulator/fixed-helper.c | 53 | ||||
-rw-r--r-- | include/linux/regulator/fixed.h | 13 |
3 files changed, 67 insertions, 1 deletions
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 503bac87715..f76deb912d5 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
@@ -3,7 +3,7 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | 5 | ||
6 | obj-$(CONFIG_REGULATOR) += core.o dummy.o | 6 | obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o |
7 | obj-$(CONFIG_OF) += of_regulator.o | 7 | obj-$(CONFIG_OF) += of_regulator.o |
8 | obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o | 8 | obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o |
9 | obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o | 9 | obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o |
diff --git a/drivers/regulator/fixed-helper.c b/drivers/regulator/fixed-helper.c new file mode 100644 index 00000000000..30d0a15b894 --- /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 | } | ||
diff --git a/include/linux/regulator/fixed.h b/include/linux/regulator/fixed.h index ffd7d508e72..936a7d8c11a 100644 --- a/include/linux/regulator/fixed.h +++ b/include/linux/regulator/fixed.h | |||
@@ -48,4 +48,17 @@ struct fixed_voltage_config { | |||
48 | struct regulator_init_data *init_data; | 48 | struct regulator_init_data *init_data; |
49 | }; | 49 | }; |
50 | 50 | ||
51 | struct regulator_consumer_supply; | ||
52 | |||
53 | #if IS_ENABLED(CONFIG_REGULATOR) | ||
54 | struct platform_device *regulator_register_fixed(int id, | ||
55 | struct regulator_consumer_supply *supplies, int num_supplies); | ||
56 | #else | ||
57 | static inline struct platform_device *regulator_register_fixed(int id, | ||
58 | struct regulator_consumer_supply *supplies, int num_supplies) | ||
59 | { | ||
60 | return NULL; | ||
61 | } | ||
62 | #endif | ||
63 | |||
51 | #endif | 64 | #endif |