diff options
Diffstat (limited to 'drivers/regulator/gpio-regulator.c')
-rw-r--r-- | drivers/regulator/gpio-regulator.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 34b67bee9323..8b5944f2d7d1 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c | |||
@@ -57,16 +57,17 @@ static int gpio_regulator_get_value(struct regulator_dev *dev) | |||
57 | return -EINVAL; | 57 | return -EINVAL; |
58 | } | 58 | } |
59 | 59 | ||
60 | static int gpio_regulator_set_value(struct regulator_dev *dev, | 60 | static int gpio_regulator_set_voltage(struct regulator_dev *dev, |
61 | int min, int max, unsigned *selector) | 61 | int min_uV, int max_uV, |
62 | unsigned *selector) | ||
62 | { | 63 | { |
63 | struct gpio_regulator_data *data = rdev_get_drvdata(dev); | 64 | struct gpio_regulator_data *data = rdev_get_drvdata(dev); |
64 | int ptr, target = 0, state, best_val = INT_MAX; | 65 | int ptr, target = 0, state, best_val = INT_MAX; |
65 | 66 | ||
66 | for (ptr = 0; ptr < data->nr_states; ptr++) | 67 | for (ptr = 0; ptr < data->nr_states; ptr++) |
67 | if (data->states[ptr].value < best_val && | 68 | if (data->states[ptr].value < best_val && |
68 | data->states[ptr].value >= min && | 69 | data->states[ptr].value >= min_uV && |
69 | data->states[ptr].value <= max) { | 70 | data->states[ptr].value <= max_uV) { |
70 | target = data->states[ptr].gpios; | 71 | target = data->states[ptr].gpios; |
71 | best_val = data->states[ptr].value; | 72 | best_val = data->states[ptr].value; |
72 | if (selector) | 73 | if (selector) |
@@ -85,13 +86,6 @@ static int gpio_regulator_set_value(struct regulator_dev *dev, | |||
85 | return 0; | 86 | return 0; |
86 | } | 87 | } |
87 | 88 | ||
88 | static int gpio_regulator_set_voltage(struct regulator_dev *dev, | ||
89 | int min_uV, int max_uV, | ||
90 | unsigned *selector) | ||
91 | { | ||
92 | return gpio_regulator_set_value(dev, min_uV, max_uV, selector); | ||
93 | } | ||
94 | |||
95 | static int gpio_regulator_list_voltage(struct regulator_dev *dev, | 89 | static int gpio_regulator_list_voltage(struct regulator_dev *dev, |
96 | unsigned selector) | 90 | unsigned selector) |
97 | { | 91 | { |
@@ -106,7 +100,27 @@ static int gpio_regulator_list_voltage(struct regulator_dev *dev, | |||
106 | static int gpio_regulator_set_current_limit(struct regulator_dev *dev, | 100 | static int gpio_regulator_set_current_limit(struct regulator_dev *dev, |
107 | int min_uA, int max_uA) | 101 | int min_uA, int max_uA) |
108 | { | 102 | { |
109 | return gpio_regulator_set_value(dev, min_uA, max_uA, NULL); | 103 | struct gpio_regulator_data *data = rdev_get_drvdata(dev); |
104 | int ptr, target = 0, state, best_val = 0; | ||
105 | |||
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) { | ||
110 | target = data->states[ptr].gpios; | ||
111 | best_val = data->states[ptr].value; | ||
112 | } | ||
113 | |||
114 | if (best_val == 0) | ||
115 | return -EINVAL; | ||
116 | |||
117 | for (ptr = 0; ptr < data->nr_gpios; ptr++) { | ||
118 | state = (target & (1 << ptr)) >> ptr; | ||
119 | gpio_set_value(data->gpios[ptr].gpio, state); | ||
120 | } | ||
121 | data->state = target; | ||
122 | |||
123 | return 0; | ||
110 | } | 124 | } |
111 | 125 | ||
112 | static struct regulator_ops gpio_regulator_voltage_ops = { | 126 | static struct regulator_ops gpio_regulator_voltage_ops = { |