econet: Fix econet_getname() leak
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / regulator / fixed.c
blob23d554628a76128e6786bb9666a67c0179e4ec32
1 /*
2 * fixed.c
4 * Copyright 2008 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This is useful for systems with mixed controllable and
14 * non-controllable regulators, as well as for allowing testing on
15 * systems with no controllable regulators.
18 #include <linux/err.h>
19 #include <linux/mutex.h>
20 #include <linux/platform_device.h>
21 #include <linux/regulator/driver.h>
22 #include <linux/regulator/fixed.h>
24 struct fixed_voltage_data {
25 struct regulator_desc desc;
26 struct regulator_dev *dev;
27 int microvolts;
30 static int fixed_voltage_is_enabled(struct regulator_dev *dev)
32 return 1;
35 static int fixed_voltage_enable(struct regulator_dev *dev)
37 return 0;
40 static int fixed_voltage_get_voltage(struct regulator_dev *dev)
42 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
44 return data->microvolts;
47 static struct regulator_ops fixed_voltage_ops = {
48 .is_enabled = fixed_voltage_is_enabled,
49 .enable = fixed_voltage_enable,
50 .get_voltage = fixed_voltage_get_voltage,
53 static int regulator_fixed_voltage_probe(struct platform_device *pdev)
55 struct fixed_voltage_config *config = pdev->dev.platform_data;
56 struct fixed_voltage_data *drvdata;
57 int ret;
59 drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL);
60 if (drvdata == NULL) {
61 ret = -ENOMEM;
62 goto err;
65 drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL);
66 if (drvdata->desc.name == NULL) {
67 ret = -ENOMEM;
68 goto err;
70 drvdata->desc.type = REGULATOR_VOLTAGE;
71 drvdata->desc.owner = THIS_MODULE;
72 drvdata->desc.ops = &fixed_voltage_ops,
74 drvdata->microvolts = config->microvolts;
76 drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev,
77 config->init_data, drvdata);
78 if (IS_ERR(drvdata->dev)) {
79 ret = PTR_ERR(drvdata->dev);
80 goto err_name;
83 platform_set_drvdata(pdev, drvdata);
85 dev_dbg(&pdev->dev, "%s supplying %duV\n", drvdata->desc.name,
86 drvdata->microvolts);
88 return 0;
90 err_name:
91 kfree(drvdata->desc.name);
92 err:
93 kfree(drvdata);
94 return ret;
97 static int regulator_fixed_voltage_remove(struct platform_device *pdev)
99 struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev);
101 regulator_unregister(drvdata->dev);
102 kfree(drvdata->desc.name);
103 kfree(drvdata);
105 return 0;
108 static struct platform_driver regulator_fixed_voltage_driver = {
109 .probe = regulator_fixed_voltage_probe,
110 .remove = regulator_fixed_voltage_remove,
111 .driver = {
112 .name = "reg-fixed-voltage",
116 static int __init regulator_fixed_voltage_init(void)
118 return platform_driver_register(&regulator_fixed_voltage_driver);
120 module_init(regulator_fixed_voltage_init);
122 static void __exit regulator_fixed_voltage_exit(void)
124 platform_driver_unregister(&regulator_fixed_voltage_driver);
126 module_exit(regulator_fixed_voltage_exit);
128 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
129 MODULE_DESCRIPTION("Fixed voltage regulator");
130 MODULE_LICENSE("GPL");