diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2008-04-30 11:27:12 -0400 |
---|---|---|
committer | Liam Girdwood <lg@opensource.wolfsonmicro.com> | 2008-07-30 05:10:21 -0400 |
commit | 4b74ff6512492dedea353f89d9b56cb715df0d7f (patch) | |
tree | 6f39d7624cd0c55116f39e7376240839fc078d92 /drivers | |
parent | 414c70cb91c445ec813b61e16fe4882807e40240 (diff) |
regulator: add support for fixed regulators.
This adds supports for regulator that are not software controlable. It allows
them to coexist in systems with mixed supplies.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Liam Girdwood <lg@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/regulator/fixed.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c new file mode 100644 index 000000000000..d31db3e14913 --- /dev/null +++ b/drivers/regulator/fixed.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | * fixed.c | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
7 | * | ||
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. | ||
12 | * | ||
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. | ||
16 | */ | ||
17 | |||
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> | ||
23 | |||
24 | struct fixed_voltage_data { | ||
25 | struct regulator_desc desc; | ||
26 | struct regulator_dev *dev; | ||
27 | int microvolts; | ||
28 | }; | ||
29 | |||
30 | static int fixed_voltage_is_enabled(struct regulator_dev *dev) | ||
31 | { | ||
32 | return 1; | ||
33 | } | ||
34 | |||
35 | static int fixed_voltage_enable(struct regulator_dev *dev) | ||
36 | { | ||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | static int fixed_voltage_get_voltage(struct regulator_dev *dev) | ||
41 | { | ||
42 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); | ||
43 | |||
44 | return data->microvolts; | ||
45 | } | ||
46 | |||
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, | ||
51 | }; | ||
52 | |||
53 | static int regulator_fixed_voltage_probe(struct platform_device *pdev) | ||
54 | { | ||
55 | struct fixed_voltage_config *config = pdev->dev.platform_data; | ||
56 | struct fixed_voltage_data *drvdata; | ||
57 | int ret; | ||
58 | |||
59 | drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL); | ||
60 | if (drvdata == NULL) { | ||
61 | ret = -ENOMEM; | ||
62 | goto err; | ||
63 | } | ||
64 | |||
65 | drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); | ||
66 | if (drvdata->desc.name == NULL) { | ||
67 | ret = -ENOMEM; | ||
68 | goto err; | ||
69 | } | ||
70 | drvdata->desc.type = REGULATOR_VOLTAGE; | ||
71 | drvdata->desc.owner = THIS_MODULE; | ||
72 | drvdata->desc.ops = &fixed_voltage_ops, | ||
73 | |||
74 | drvdata->microvolts = config->microvolts; | ||
75 | |||
76 | drvdata->dev = regulator_register(&drvdata->desc, drvdata); | ||
77 | if (IS_ERR(drvdata->dev)) { | ||
78 | ret = PTR_ERR(drvdata->dev); | ||
79 | goto err_name; | ||
80 | } | ||
81 | |||
82 | platform_set_drvdata(pdev, drvdata); | ||
83 | |||
84 | dev_dbg(&pdev->dev, "%s supplying %duV\n", drvdata->desc.name, | ||
85 | drvdata->microvolts); | ||
86 | |||
87 | return 0; | ||
88 | |||
89 | err_name: | ||
90 | kfree(drvdata->desc.name); | ||
91 | err: | ||
92 | kfree(drvdata); | ||
93 | return ret; | ||
94 | } | ||
95 | |||
96 | static int regulator_fixed_voltage_remove(struct platform_device *pdev) | ||
97 | { | ||
98 | struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev); | ||
99 | |||
100 | regulator_unregister(drvdata->dev); | ||
101 | kfree(drvdata->desc.name); | ||
102 | kfree(drvdata); | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static struct platform_driver regulator_fixed_voltage_driver = { | ||
108 | .probe = regulator_fixed_voltage_probe, | ||
109 | .remove = regulator_fixed_voltage_remove, | ||
110 | .driver = { | ||
111 | .name = "reg-fixed-voltage", | ||
112 | }, | ||
113 | }; | ||
114 | |||
115 | static int __init regulator_fixed_voltage_init(void) | ||
116 | { | ||
117 | return platform_driver_register(®ulator_fixed_voltage_driver); | ||
118 | } | ||
119 | module_init(regulator_fixed_voltage_init); | ||
120 | |||
121 | static void __exit regulator_fixed_voltage_exit(void) | ||
122 | { | ||
123 | platform_driver_unregister(®ulator_fixed_voltage_driver); | ||
124 | } | ||
125 | module_exit(regulator_fixed_voltage_exit); | ||
126 | |||
127 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
128 | MODULE_DESCRIPTION("Fixed voltage regulator"); | ||
129 | MODULE_LICENSE("GPL"); | ||