xen block: remove driver_data direct access of struct device
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / regulator / fixed.c
blobcdc674fb46c3371192c7b2975df97ac9794a3e0d
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 int fixed_voltage_list_voltage(struct regulator_dev *dev,
48 unsigned selector)
50 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
52 if (selector != 0)
53 return -EINVAL;
55 return data->microvolts;
58 static struct regulator_ops fixed_voltage_ops = {
59 .is_enabled = fixed_voltage_is_enabled,
60 .enable = fixed_voltage_enable,
61 .get_voltage = fixed_voltage_get_voltage,
62 .list_voltage = fixed_voltage_list_voltage,
65 static int regulator_fixed_voltage_probe(struct platform_device *pdev)
67 struct fixed_voltage_config *config = pdev->dev.platform_data;
68 struct fixed_voltage_data *drvdata;
69 int ret;
71 drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL);
72 if (drvdata == NULL) {
73 ret = -ENOMEM;
74 goto err;
77 drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL);
78 if (drvdata->desc.name == NULL) {
79 ret = -ENOMEM;
80 goto err;
82 drvdata->desc.type = REGULATOR_VOLTAGE;
83 drvdata->desc.owner = THIS_MODULE;
84 drvdata->desc.ops = &fixed_voltage_ops;
85 drvdata->desc.n_voltages = 1;
87 drvdata->microvolts = config->microvolts;
89 drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev,
90 config->init_data, drvdata);
91 if (IS_ERR(drvdata->dev)) {
92 ret = PTR_ERR(drvdata->dev);
93 goto err_name;
96 platform_set_drvdata(pdev, drvdata);
98 dev_dbg(&pdev->dev, "%s supplying %duV\n", drvdata->desc.name,
99 drvdata->microvolts);
101 return 0;
103 err_name:
104 kfree(drvdata->desc.name);
105 err:
106 kfree(drvdata);
107 return ret;
110 static int regulator_fixed_voltage_remove(struct platform_device *pdev)
112 struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev);
114 regulator_unregister(drvdata->dev);
115 kfree(drvdata->desc.name);
116 kfree(drvdata);
118 return 0;
121 static struct platform_driver regulator_fixed_voltage_driver = {
122 .probe = regulator_fixed_voltage_probe,
123 .remove = regulator_fixed_voltage_remove,
124 .driver = {
125 .name = "reg-fixed-voltage",
129 static int __init regulator_fixed_voltage_init(void)
131 return platform_driver_register(&regulator_fixed_voltage_driver);
133 subsys_initcall(regulator_fixed_voltage_init);
135 static void __exit regulator_fixed_voltage_exit(void)
137 platform_driver_unregister(&regulator_fixed_voltage_driver);
139 module_exit(regulator_fixed_voltage_exit);
141 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
142 MODULE_DESCRIPTION("Fixed voltage regulator");
143 MODULE_LICENSE("GPL");
144 MODULE_ALIAS("platform:reg-fixed-voltage");