27 #include <linux/module.h>
33 #include <linux/slab.h>
53 for (ptr = 0; ptr < data->
nr_states; ptr++)
61 int min_uV,
int max_uV,
67 for (ptr = 0; ptr < data->
nr_states; ptr++)
68 if (data->
states[ptr].value < best_val &&
69 data->
states[ptr].value >= min_uV &&
70 data->
states[ptr].value <= max_uV) {
80 for (ptr = 0; ptr < data->
nr_gpios; ptr++) {
89 static int gpio_regulator_list_voltage(
struct regulator_dev *dev,
97 return data->
states[selector].value;
100 static int gpio_regulator_set_current_limit(
struct regulator_dev *dev,
101 int min_uA,
int max_uA)
104 int ptr, target = 0,
state, best_val = 0;
106 for (ptr = 0; ptr < data->
nr_states; ptr++)
107 if (data->
states[ptr].value > best_val &&
108 data->
states[ptr].value >= min_uA &&
109 data->
states[ptr].value <= max_uA) {
117 for (ptr = 0; ptr < data->
nr_gpios; ptr++) {
127 .get_voltage = gpio_regulator_get_value,
128 .set_voltage = gpio_regulator_set_voltage,
129 .list_voltage = gpio_regulator_list_voltage,
133 .get_current_limit = gpio_regulator_get_value,
134 .set_current_limit = gpio_regulator_set_current_limit,
146 if (drvdata ==
NULL) {
147 dev_err(&pdev->
dev,
"Failed to allocate device data\n");
153 dev_err(&pdev->
dev,
"Failed to allocate supply name\n");
162 dev_err(&pdev->
dev,
"Failed to allocate gpio data\n");
172 dev_err(&pdev->
dev,
"Failed to allocate state data\n");
182 switch (config->
type) {
185 drvdata->
desc.ops = &gpio_regulator_voltage_ops;
190 drvdata->
desc.ops = &gpio_regulator_current_ops;
193 dev_err(&pdev->
dev,
"No regulator type set\n");
203 "Could not obtain regulator setting GPIOs: %d\n", ret);
209 for (ptr = 0; ptr < drvdata->
nr_gpios; ptr++) {
235 if (IS_ERR(drvdata->
dev)) {
236 ret = PTR_ERR(drvdata->
dev);
237 dev_err(&pdev->
dev,
"Failed to register regulator: %d\n", ret);
241 platform_set_drvdata(pdev, drvdata);
274 .probe = gpio_regulator_probe,
277 .name =
"gpio-regulator",
282 static int __init gpio_regulator_init(
void)
288 static void __exit gpio_regulator_exit(
void)