Merge branch '3.4-rc1' into android-tegra-nv-3.3-rebased
[linux-2.6.git] / drivers / regulator / fixed-helper.c
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 }