Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1 | /* |
| 2 | * core.c -- Voltage/Current Regulator framework. |
| 3 | * |
| 4 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 5 | * Copyright 2008 SlimLogic Ltd. |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 6 | * |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 7 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 20 | #include <linux/err.h> |
| 21 | #include <linux/mutex.h> |
| 22 | #include <linux/suspend.h> |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 23 | #include <linux/delay.h> |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 24 | #include <linux/regulator/consumer.h> |
| 25 | #include <linux/regulator/driver.h> |
| 26 | #include <linux/regulator/machine.h> |
| 27 | |
Mark Brown | 02fa3ec | 2010-11-10 14:38:30 +0000 | [diff] [blame] | 28 | #define CREATE_TRACE_POINTS |
| 29 | #include <trace/events/regulator.h> |
| 30 | |
Mark Brown | 34abbd6 | 2010-02-12 10:18:08 +0000 | [diff] [blame] | 31 | #include "dummy.h" |
| 32 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 33 | #define REGULATOR_VERSION "0.5" |
| 34 | |
| 35 | static DEFINE_MUTEX(regulator_list_mutex); |
| 36 | static LIST_HEAD(regulator_list); |
| 37 | static LIST_HEAD(regulator_map_list); |
Mark Brown | ca72556 | 2009-03-16 19:36:34 +0000 | [diff] [blame] | 38 | static int has_full_constraints; |
Mark Brown | 688fe99 | 2010-10-05 19:18:32 -0700 | [diff] [blame] | 39 | static bool board_wants_dummy_regulator; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 40 | |
Mark Brown | 8dc5390 | 2008-12-31 12:52:40 +0000 | [diff] [blame] | 41 | /* |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 42 | * struct regulator_map |
| 43 | * |
| 44 | * Used to provide symbolic supply names to devices. |
| 45 | */ |
| 46 | struct regulator_map { |
| 47 | struct list_head list; |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 48 | const char *dev_name; /* The dev_name() for the consumer */ |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 49 | const char *supply; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 50 | struct regulator_dev *regulator; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 51 | }; |
| 52 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 53 | /* |
| 54 | * struct regulator |
| 55 | * |
| 56 | * One for each consumer device. |
| 57 | */ |
| 58 | struct regulator { |
| 59 | struct device *dev; |
| 60 | struct list_head list; |
| 61 | int uA_load; |
| 62 | int min_uV; |
| 63 | int max_uV; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 64 | char *supply_name; |
| 65 | struct device_attribute dev_attr; |
| 66 | struct regulator_dev *rdev; |
| 67 | }; |
| 68 | |
| 69 | static int _regulator_is_enabled(struct regulator_dev *rdev); |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 70 | static int _regulator_disable(struct regulator_dev *rdev, |
| 71 | struct regulator_dev **supply_rdev_ptr); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 72 | static int _regulator_get_voltage(struct regulator_dev *rdev); |
| 73 | static int _regulator_get_current_limit(struct regulator_dev *rdev); |
| 74 | static unsigned int _regulator_get_mode(struct regulator_dev *rdev); |
| 75 | static void _notifier_call_chain(struct regulator_dev *rdev, |
| 76 | unsigned long event, void *data); |
| 77 | |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 78 | static const char *rdev_get_name(struct regulator_dev *rdev) |
| 79 | { |
| 80 | if (rdev->constraints && rdev->constraints->name) |
| 81 | return rdev->constraints->name; |
| 82 | else if (rdev->desc->name) |
| 83 | return rdev->desc->name; |
| 84 | else |
| 85 | return ""; |
| 86 | } |
| 87 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 88 | /* gets the regulator for a given consumer device */ |
| 89 | static struct regulator *get_device_regulator(struct device *dev) |
| 90 | { |
| 91 | struct regulator *regulator = NULL; |
| 92 | struct regulator_dev *rdev; |
| 93 | |
| 94 | mutex_lock(®ulator_list_mutex); |
| 95 | list_for_each_entry(rdev, ®ulator_list, list) { |
| 96 | mutex_lock(&rdev->mutex); |
| 97 | list_for_each_entry(regulator, &rdev->consumer_list, list) { |
| 98 | if (regulator->dev == dev) { |
| 99 | mutex_unlock(&rdev->mutex); |
| 100 | mutex_unlock(®ulator_list_mutex); |
| 101 | return regulator; |
| 102 | } |
| 103 | } |
| 104 | mutex_unlock(&rdev->mutex); |
| 105 | } |
| 106 | mutex_unlock(®ulator_list_mutex); |
| 107 | return NULL; |
| 108 | } |
| 109 | |
| 110 | /* Platform voltage constraint check */ |
| 111 | static int regulator_check_voltage(struct regulator_dev *rdev, |
| 112 | int *min_uV, int *max_uV) |
| 113 | { |
| 114 | BUG_ON(*min_uV > *max_uV); |
| 115 | |
| 116 | if (!rdev->constraints) { |
| 117 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 118 | rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 119 | return -ENODEV; |
| 120 | } |
| 121 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { |
| 122 | printk(KERN_ERR "%s: operation not allowed for %s\n", |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 123 | __func__, rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 124 | return -EPERM; |
| 125 | } |
| 126 | |
| 127 | if (*max_uV > rdev->constraints->max_uV) |
| 128 | *max_uV = rdev->constraints->max_uV; |
| 129 | if (*min_uV < rdev->constraints->min_uV) |
| 130 | *min_uV = rdev->constraints->min_uV; |
| 131 | |
| 132 | if (*min_uV > *max_uV) |
| 133 | return -EINVAL; |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | /* current constraint check */ |
| 139 | static int regulator_check_current_limit(struct regulator_dev *rdev, |
| 140 | int *min_uA, int *max_uA) |
| 141 | { |
| 142 | BUG_ON(*min_uA > *max_uA); |
| 143 | |
| 144 | if (!rdev->constraints) { |
| 145 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 146 | rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 147 | return -ENODEV; |
| 148 | } |
| 149 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) { |
| 150 | printk(KERN_ERR "%s: operation not allowed for %s\n", |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 151 | __func__, rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 152 | return -EPERM; |
| 153 | } |
| 154 | |
| 155 | if (*max_uA > rdev->constraints->max_uA) |
| 156 | *max_uA = rdev->constraints->max_uA; |
| 157 | if (*min_uA < rdev->constraints->min_uA) |
| 158 | *min_uA = rdev->constraints->min_uA; |
| 159 | |
| 160 | if (*min_uA > *max_uA) |
| 161 | return -EINVAL; |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | /* operating mode constraint check */ |
| 167 | static int regulator_check_mode(struct regulator_dev *rdev, int mode) |
| 168 | { |
David Brownell | e573520 | 2008-11-16 11:46:56 -0800 | [diff] [blame] | 169 | switch (mode) { |
| 170 | case REGULATOR_MODE_FAST: |
| 171 | case REGULATOR_MODE_NORMAL: |
| 172 | case REGULATOR_MODE_IDLE: |
| 173 | case REGULATOR_MODE_STANDBY: |
| 174 | break; |
| 175 | default: |
| 176 | return -EINVAL; |
| 177 | } |
| 178 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 179 | if (!rdev->constraints) { |
| 180 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 181 | rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 182 | return -ENODEV; |
| 183 | } |
| 184 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) { |
| 185 | printk(KERN_ERR "%s: operation not allowed for %s\n", |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 186 | __func__, rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 187 | return -EPERM; |
| 188 | } |
| 189 | if (!(rdev->constraints->valid_modes_mask & mode)) { |
| 190 | printk(KERN_ERR "%s: invalid mode %x for %s\n", |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 191 | __func__, mode, rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 192 | return -EINVAL; |
| 193 | } |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | /* dynamic regulator mode switching constraint check */ |
| 198 | static int regulator_check_drms(struct regulator_dev *rdev) |
| 199 | { |
| 200 | if (!rdev->constraints) { |
| 201 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 202 | rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 203 | return -ENODEV; |
| 204 | } |
| 205 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { |
| 206 | printk(KERN_ERR "%s: operation not allowed for %s\n", |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 207 | __func__, rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 208 | return -EPERM; |
| 209 | } |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | static ssize_t device_requested_uA_show(struct device *dev, |
| 214 | struct device_attribute *attr, char *buf) |
| 215 | { |
| 216 | struct regulator *regulator; |
| 217 | |
| 218 | regulator = get_device_regulator(dev); |
| 219 | if (regulator == NULL) |
| 220 | return 0; |
| 221 | |
| 222 | return sprintf(buf, "%d\n", regulator->uA_load); |
| 223 | } |
| 224 | |
| 225 | static ssize_t regulator_uV_show(struct device *dev, |
| 226 | struct device_attribute *attr, char *buf) |
| 227 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 228 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 229 | ssize_t ret; |
| 230 | |
| 231 | mutex_lock(&rdev->mutex); |
| 232 | ret = sprintf(buf, "%d\n", _regulator_get_voltage(rdev)); |
| 233 | mutex_unlock(&rdev->mutex); |
| 234 | |
| 235 | return ret; |
| 236 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 237 | static DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 238 | |
| 239 | static ssize_t regulator_uA_show(struct device *dev, |
| 240 | struct device_attribute *attr, char *buf) |
| 241 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 242 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 243 | |
| 244 | return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); |
| 245 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 246 | static DEVICE_ATTR(microamps, 0444, regulator_uA_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 247 | |
Mark Brown | bc558a6 | 2008-10-10 15:33:20 +0100 | [diff] [blame] | 248 | static ssize_t regulator_name_show(struct device *dev, |
| 249 | struct device_attribute *attr, char *buf) |
| 250 | { |
| 251 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Mark Brown | bc558a6 | 2008-10-10 15:33:20 +0100 | [diff] [blame] | 252 | |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 253 | return sprintf(buf, "%s\n", rdev_get_name(rdev)); |
Mark Brown | bc558a6 | 2008-10-10 15:33:20 +0100 | [diff] [blame] | 254 | } |
| 255 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 256 | static ssize_t regulator_print_opmode(char *buf, int mode) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 257 | { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 258 | switch (mode) { |
| 259 | case REGULATOR_MODE_FAST: |
| 260 | return sprintf(buf, "fast\n"); |
| 261 | case REGULATOR_MODE_NORMAL: |
| 262 | return sprintf(buf, "normal\n"); |
| 263 | case REGULATOR_MODE_IDLE: |
| 264 | return sprintf(buf, "idle\n"); |
| 265 | case REGULATOR_MODE_STANDBY: |
| 266 | return sprintf(buf, "standby\n"); |
| 267 | } |
| 268 | return sprintf(buf, "unknown\n"); |
| 269 | } |
| 270 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 271 | static ssize_t regulator_opmode_show(struct device *dev, |
| 272 | struct device_attribute *attr, char *buf) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 273 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 274 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 275 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 276 | return regulator_print_opmode(buf, _regulator_get_mode(rdev)); |
| 277 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 278 | static DEVICE_ATTR(opmode, 0444, regulator_opmode_show, NULL); |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 279 | |
| 280 | static ssize_t regulator_print_state(char *buf, int state) |
| 281 | { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 282 | if (state > 0) |
| 283 | return sprintf(buf, "enabled\n"); |
| 284 | else if (state == 0) |
| 285 | return sprintf(buf, "disabled\n"); |
| 286 | else |
| 287 | return sprintf(buf, "unknown\n"); |
| 288 | } |
| 289 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 290 | static ssize_t regulator_state_show(struct device *dev, |
| 291 | struct device_attribute *attr, char *buf) |
| 292 | { |
| 293 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Mark Brown | 9332546 | 2009-08-03 18:49:56 +0100 | [diff] [blame] | 294 | ssize_t ret; |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 295 | |
Mark Brown | 9332546 | 2009-08-03 18:49:56 +0100 | [diff] [blame] | 296 | mutex_lock(&rdev->mutex); |
| 297 | ret = regulator_print_state(buf, _regulator_is_enabled(rdev)); |
| 298 | mutex_unlock(&rdev->mutex); |
| 299 | |
| 300 | return ret; |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 301 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 302 | static DEVICE_ATTR(state, 0444, regulator_state_show, NULL); |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 303 | |
David Brownell | 853116a | 2009-01-14 23:03:17 -0800 | [diff] [blame] | 304 | static ssize_t regulator_status_show(struct device *dev, |
| 305 | struct device_attribute *attr, char *buf) |
| 306 | { |
| 307 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
| 308 | int status; |
| 309 | char *label; |
| 310 | |
| 311 | status = rdev->desc->ops->get_status(rdev); |
| 312 | if (status < 0) |
| 313 | return status; |
| 314 | |
| 315 | switch (status) { |
| 316 | case REGULATOR_STATUS_OFF: |
| 317 | label = "off"; |
| 318 | break; |
| 319 | case REGULATOR_STATUS_ON: |
| 320 | label = "on"; |
| 321 | break; |
| 322 | case REGULATOR_STATUS_ERROR: |
| 323 | label = "error"; |
| 324 | break; |
| 325 | case REGULATOR_STATUS_FAST: |
| 326 | label = "fast"; |
| 327 | break; |
| 328 | case REGULATOR_STATUS_NORMAL: |
| 329 | label = "normal"; |
| 330 | break; |
| 331 | case REGULATOR_STATUS_IDLE: |
| 332 | label = "idle"; |
| 333 | break; |
| 334 | case REGULATOR_STATUS_STANDBY: |
| 335 | label = "standby"; |
| 336 | break; |
| 337 | default: |
| 338 | return -ERANGE; |
| 339 | } |
| 340 | |
| 341 | return sprintf(buf, "%s\n", label); |
| 342 | } |
| 343 | static DEVICE_ATTR(status, 0444, regulator_status_show, NULL); |
| 344 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 345 | static ssize_t regulator_min_uA_show(struct device *dev, |
| 346 | struct device_attribute *attr, char *buf) |
| 347 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 348 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 349 | |
| 350 | if (!rdev->constraints) |
| 351 | return sprintf(buf, "constraint not defined\n"); |
| 352 | |
| 353 | return sprintf(buf, "%d\n", rdev->constraints->min_uA); |
| 354 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 355 | static DEVICE_ATTR(min_microamps, 0444, regulator_min_uA_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 356 | |
| 357 | static ssize_t regulator_max_uA_show(struct device *dev, |
| 358 | struct device_attribute *attr, char *buf) |
| 359 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 360 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 361 | |
| 362 | if (!rdev->constraints) |
| 363 | return sprintf(buf, "constraint not defined\n"); |
| 364 | |
| 365 | return sprintf(buf, "%d\n", rdev->constraints->max_uA); |
| 366 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 367 | static DEVICE_ATTR(max_microamps, 0444, regulator_max_uA_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 368 | |
| 369 | static ssize_t regulator_min_uV_show(struct device *dev, |
| 370 | struct device_attribute *attr, char *buf) |
| 371 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 372 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 373 | |
| 374 | if (!rdev->constraints) |
| 375 | return sprintf(buf, "constraint not defined\n"); |
| 376 | |
| 377 | return sprintf(buf, "%d\n", rdev->constraints->min_uV); |
| 378 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 379 | static DEVICE_ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 380 | |
| 381 | static ssize_t regulator_max_uV_show(struct device *dev, |
| 382 | struct device_attribute *attr, char *buf) |
| 383 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 384 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 385 | |
| 386 | if (!rdev->constraints) |
| 387 | return sprintf(buf, "constraint not defined\n"); |
| 388 | |
| 389 | return sprintf(buf, "%d\n", rdev->constraints->max_uV); |
| 390 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 391 | static DEVICE_ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 392 | |
| 393 | static ssize_t regulator_total_uA_show(struct device *dev, |
| 394 | struct device_attribute *attr, char *buf) |
| 395 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 396 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 397 | struct regulator *regulator; |
| 398 | int uA = 0; |
| 399 | |
| 400 | mutex_lock(&rdev->mutex); |
| 401 | list_for_each_entry(regulator, &rdev->consumer_list, list) |
Stefan Roese | fa2984d | 2009-11-27 15:56:34 +0100 | [diff] [blame] | 402 | uA += regulator->uA_load; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 403 | mutex_unlock(&rdev->mutex); |
| 404 | return sprintf(buf, "%d\n", uA); |
| 405 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 406 | static DEVICE_ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 407 | |
| 408 | static ssize_t regulator_num_users_show(struct device *dev, |
| 409 | struct device_attribute *attr, char *buf) |
| 410 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 411 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 412 | return sprintf(buf, "%d\n", rdev->use_count); |
| 413 | } |
| 414 | |
| 415 | static ssize_t regulator_type_show(struct device *dev, |
| 416 | struct device_attribute *attr, char *buf) |
| 417 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 418 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 419 | |
| 420 | switch (rdev->desc->type) { |
| 421 | case REGULATOR_VOLTAGE: |
| 422 | return sprintf(buf, "voltage\n"); |
| 423 | case REGULATOR_CURRENT: |
| 424 | return sprintf(buf, "current\n"); |
| 425 | } |
| 426 | return sprintf(buf, "unknown\n"); |
| 427 | } |
| 428 | |
| 429 | static ssize_t regulator_suspend_mem_uV_show(struct device *dev, |
| 430 | struct device_attribute *attr, char *buf) |
| 431 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 432 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 433 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 434 | return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV); |
| 435 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 436 | static DEVICE_ATTR(suspend_mem_microvolts, 0444, |
| 437 | regulator_suspend_mem_uV_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 438 | |
| 439 | static ssize_t regulator_suspend_disk_uV_show(struct device *dev, |
| 440 | struct device_attribute *attr, char *buf) |
| 441 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 442 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 443 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 444 | return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV); |
| 445 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 446 | static DEVICE_ATTR(suspend_disk_microvolts, 0444, |
| 447 | regulator_suspend_disk_uV_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 448 | |
| 449 | static ssize_t regulator_suspend_standby_uV_show(struct device *dev, |
| 450 | struct device_attribute *attr, char *buf) |
| 451 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 452 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 453 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 454 | return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); |
| 455 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 456 | static DEVICE_ATTR(suspend_standby_microvolts, 0444, |
| 457 | regulator_suspend_standby_uV_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 458 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 459 | static ssize_t regulator_suspend_mem_mode_show(struct device *dev, |
| 460 | struct device_attribute *attr, char *buf) |
| 461 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 462 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 463 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 464 | return regulator_print_opmode(buf, |
| 465 | rdev->constraints->state_mem.mode); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 466 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 467 | static DEVICE_ATTR(suspend_mem_mode, 0444, |
| 468 | regulator_suspend_mem_mode_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 469 | |
| 470 | static ssize_t regulator_suspend_disk_mode_show(struct device *dev, |
| 471 | struct device_attribute *attr, char *buf) |
| 472 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 473 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 474 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 475 | return regulator_print_opmode(buf, |
| 476 | rdev->constraints->state_disk.mode); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 477 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 478 | static DEVICE_ATTR(suspend_disk_mode, 0444, |
| 479 | regulator_suspend_disk_mode_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 480 | |
| 481 | static ssize_t regulator_suspend_standby_mode_show(struct device *dev, |
| 482 | struct device_attribute *attr, char *buf) |
| 483 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 484 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 485 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 486 | return regulator_print_opmode(buf, |
| 487 | rdev->constraints->state_standby.mode); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 488 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 489 | static DEVICE_ATTR(suspend_standby_mode, 0444, |
| 490 | regulator_suspend_standby_mode_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 491 | |
| 492 | static ssize_t regulator_suspend_mem_state_show(struct device *dev, |
| 493 | struct device_attribute *attr, char *buf) |
| 494 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 495 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 496 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 497 | return regulator_print_state(buf, |
| 498 | rdev->constraints->state_mem.enabled); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 499 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 500 | static DEVICE_ATTR(suspend_mem_state, 0444, |
| 501 | regulator_suspend_mem_state_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 502 | |
| 503 | static ssize_t regulator_suspend_disk_state_show(struct device *dev, |
| 504 | struct device_attribute *attr, char *buf) |
| 505 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 506 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 507 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 508 | return regulator_print_state(buf, |
| 509 | rdev->constraints->state_disk.enabled); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 510 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 511 | static DEVICE_ATTR(suspend_disk_state, 0444, |
| 512 | regulator_suspend_disk_state_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 513 | |
| 514 | static ssize_t regulator_suspend_standby_state_show(struct device *dev, |
| 515 | struct device_attribute *attr, char *buf) |
| 516 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 517 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 518 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 519 | return regulator_print_state(buf, |
| 520 | rdev->constraints->state_standby.enabled); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 521 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 522 | static DEVICE_ATTR(suspend_standby_state, 0444, |
| 523 | regulator_suspend_standby_state_show, NULL); |
Mark Brown | bc558a6 | 2008-10-10 15:33:20 +0100 | [diff] [blame] | 524 | |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 525 | |
| 526 | /* |
| 527 | * These are the only attributes are present for all regulators. |
| 528 | * Other attributes are a function of regulator functionality. |
| 529 | */ |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 530 | static struct device_attribute regulator_dev_attrs[] = { |
Mark Brown | bc558a6 | 2008-10-10 15:33:20 +0100 | [diff] [blame] | 531 | __ATTR(name, 0444, regulator_name_show, NULL), |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 532 | __ATTR(num_users, 0444, regulator_num_users_show, NULL), |
| 533 | __ATTR(type, 0444, regulator_type_show, NULL), |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 534 | __ATTR_NULL, |
| 535 | }; |
| 536 | |
| 537 | static void regulator_dev_release(struct device *dev) |
| 538 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 539 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 540 | kfree(rdev); |
| 541 | } |
| 542 | |
| 543 | static struct class regulator_class = { |
| 544 | .name = "regulator", |
| 545 | .dev_release = regulator_dev_release, |
| 546 | .dev_attrs = regulator_dev_attrs, |
| 547 | }; |
| 548 | |
| 549 | /* Calculate the new optimum regulator operating mode based on the new total |
| 550 | * consumer load. All locks held by caller */ |
| 551 | static void drms_uA_update(struct regulator_dev *rdev) |
| 552 | { |
| 553 | struct regulator *sibling; |
| 554 | int current_uA = 0, output_uV, input_uV, err; |
| 555 | unsigned int mode; |
| 556 | |
| 557 | err = regulator_check_drms(rdev); |
| 558 | if (err < 0 || !rdev->desc->ops->get_optimum_mode || |
Dan Carpenter | 036de8e | 2009-04-08 13:52:39 +0300 | [diff] [blame] | 559 | !rdev->desc->ops->get_voltage || !rdev->desc->ops->set_mode) |
| 560 | return; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 561 | |
| 562 | /* get output voltage */ |
| 563 | output_uV = rdev->desc->ops->get_voltage(rdev); |
| 564 | if (output_uV <= 0) |
| 565 | return; |
| 566 | |
| 567 | /* get input voltage */ |
| 568 | if (rdev->supply && rdev->supply->desc->ops->get_voltage) |
| 569 | input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply); |
| 570 | else |
| 571 | input_uV = rdev->constraints->input_uV; |
| 572 | if (input_uV <= 0) |
| 573 | return; |
| 574 | |
| 575 | /* calc total requested load */ |
| 576 | list_for_each_entry(sibling, &rdev->consumer_list, list) |
Stefan Roese | fa2984d | 2009-11-27 15:56:34 +0100 | [diff] [blame] | 577 | current_uA += sibling->uA_load; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 578 | |
| 579 | /* now get the optimum mode for our new total regulator load */ |
| 580 | mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV, |
| 581 | output_uV, current_uA); |
| 582 | |
| 583 | /* check the new mode is allowed */ |
| 584 | err = regulator_check_mode(rdev, mode); |
| 585 | if (err == 0) |
| 586 | rdev->desc->ops->set_mode(rdev, mode); |
| 587 | } |
| 588 | |
| 589 | static int suspend_set_state(struct regulator_dev *rdev, |
| 590 | struct regulator_state *rstate) |
| 591 | { |
| 592 | int ret = 0; |
Mark Brown | 638f85c | 2009-10-22 16:31:33 +0100 | [diff] [blame] | 593 | bool can_set_state; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 594 | |
Mark Brown | 638f85c | 2009-10-22 16:31:33 +0100 | [diff] [blame] | 595 | can_set_state = rdev->desc->ops->set_suspend_enable && |
| 596 | rdev->desc->ops->set_suspend_disable; |
| 597 | |
| 598 | /* If we have no suspend mode configration don't set anything; |
| 599 | * only warn if the driver actually makes the suspend mode |
| 600 | * configurable. |
| 601 | */ |
| 602 | if (!rstate->enabled && !rstate->disabled) { |
| 603 | if (can_set_state) |
| 604 | printk(KERN_WARNING "%s: No configuration for %s\n", |
| 605 | __func__, rdev_get_name(rdev)); |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | if (rstate->enabled && rstate->disabled) { |
| 610 | printk(KERN_ERR "%s: invalid configuration for %s\n", |
| 611 | __func__, rdev_get_name(rdev)); |
| 612 | return -EINVAL; |
| 613 | } |
| 614 | |
| 615 | if (!can_set_state) { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 616 | printk(KERN_ERR "%s: no way to set suspend state\n", |
| 617 | __func__); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 618 | return -EINVAL; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 619 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 620 | |
| 621 | if (rstate->enabled) |
| 622 | ret = rdev->desc->ops->set_suspend_enable(rdev); |
| 623 | else |
| 624 | ret = rdev->desc->ops->set_suspend_disable(rdev); |
| 625 | if (ret < 0) { |
| 626 | printk(KERN_ERR "%s: failed to enabled/disable\n", __func__); |
| 627 | return ret; |
| 628 | } |
| 629 | |
| 630 | if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) { |
| 631 | ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV); |
| 632 | if (ret < 0) { |
| 633 | printk(KERN_ERR "%s: failed to set voltage\n", |
| 634 | __func__); |
| 635 | return ret; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) { |
| 640 | ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode); |
| 641 | if (ret < 0) { |
| 642 | printk(KERN_ERR "%s: failed to set mode\n", __func__); |
| 643 | return ret; |
| 644 | } |
| 645 | } |
| 646 | return ret; |
| 647 | } |
| 648 | |
| 649 | /* locks held by caller */ |
| 650 | static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state) |
| 651 | { |
| 652 | if (!rdev->constraints) |
| 653 | return -EINVAL; |
| 654 | |
| 655 | switch (state) { |
| 656 | case PM_SUSPEND_STANDBY: |
| 657 | return suspend_set_state(rdev, |
| 658 | &rdev->constraints->state_standby); |
| 659 | case PM_SUSPEND_MEM: |
| 660 | return suspend_set_state(rdev, |
| 661 | &rdev->constraints->state_mem); |
| 662 | case PM_SUSPEND_MAX: |
| 663 | return suspend_set_state(rdev, |
| 664 | &rdev->constraints->state_disk); |
| 665 | default: |
| 666 | return -EINVAL; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | static void print_constraints(struct regulator_dev *rdev) |
| 671 | { |
| 672 | struct regulation_constraints *constraints = rdev->constraints; |
Mark Brown | 973e9a2 | 2010-02-11 19:20:48 +0000 | [diff] [blame] | 673 | char buf[80] = ""; |
Mark Brown | 8f031b4 | 2009-10-22 16:31:31 +0100 | [diff] [blame] | 674 | int count = 0; |
| 675 | int ret; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 676 | |
Mark Brown | 8f031b4 | 2009-10-22 16:31:31 +0100 | [diff] [blame] | 677 | if (constraints->min_uV && constraints->max_uV) { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 678 | if (constraints->min_uV == constraints->max_uV) |
Mark Brown | 8f031b4 | 2009-10-22 16:31:31 +0100 | [diff] [blame] | 679 | count += sprintf(buf + count, "%d mV ", |
| 680 | constraints->min_uV / 1000); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 681 | else |
Mark Brown | 8f031b4 | 2009-10-22 16:31:31 +0100 | [diff] [blame] | 682 | count += sprintf(buf + count, "%d <--> %d mV ", |
| 683 | constraints->min_uV / 1000, |
| 684 | constraints->max_uV / 1000); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 685 | } |
Mark Brown | 8f031b4 | 2009-10-22 16:31:31 +0100 | [diff] [blame] | 686 | |
| 687 | if (!constraints->min_uV || |
| 688 | constraints->min_uV != constraints->max_uV) { |
| 689 | ret = _regulator_get_voltage(rdev); |
| 690 | if (ret > 0) |
| 691 | count += sprintf(buf + count, "at %d mV ", ret / 1000); |
| 692 | } |
| 693 | |
| 694 | if (constraints->min_uA && constraints->max_uA) { |
| 695 | if (constraints->min_uA == constraints->max_uA) |
| 696 | count += sprintf(buf + count, "%d mA ", |
| 697 | constraints->min_uA / 1000); |
| 698 | else |
| 699 | count += sprintf(buf + count, "%d <--> %d mA ", |
| 700 | constraints->min_uA / 1000, |
| 701 | constraints->max_uA / 1000); |
| 702 | } |
| 703 | |
| 704 | if (!constraints->min_uA || |
| 705 | constraints->min_uA != constraints->max_uA) { |
| 706 | ret = _regulator_get_current_limit(rdev); |
| 707 | if (ret > 0) |
Cyril Chemparathy | e4a6376 | 2010-09-22 12:30:15 -0400 | [diff] [blame] | 708 | count += sprintf(buf + count, "at %d mA ", ret / 1000); |
Mark Brown | 8f031b4 | 2009-10-22 16:31:31 +0100 | [diff] [blame] | 709 | } |
| 710 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 711 | if (constraints->valid_modes_mask & REGULATOR_MODE_FAST) |
| 712 | count += sprintf(buf + count, "fast "); |
| 713 | if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL) |
| 714 | count += sprintf(buf + count, "normal "); |
| 715 | if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE) |
| 716 | count += sprintf(buf + count, "idle "); |
| 717 | if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) |
| 718 | count += sprintf(buf + count, "standby"); |
| 719 | |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 720 | printk(KERN_INFO "regulator: %s: %s\n", rdev_get_name(rdev), buf); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 721 | } |
| 722 | |
Mark Brown | e79055d | 2009-10-19 15:53:50 +0100 | [diff] [blame] | 723 | static int machine_constraints_voltage(struct regulator_dev *rdev, |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 724 | struct regulation_constraints *constraints) |
Mark Brown | e79055d | 2009-10-19 15:53:50 +0100 | [diff] [blame] | 725 | { |
| 726 | struct regulator_ops *ops = rdev->desc->ops; |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 727 | const char *name = rdev_get_name(rdev); |
Mark Brown | af5866c | 2009-10-22 16:31:30 +0100 | [diff] [blame] | 728 | int ret; |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 729 | unsigned selector; |
Mark Brown | af5866c | 2009-10-22 16:31:30 +0100 | [diff] [blame] | 730 | |
| 731 | /* do we need to apply the constraint voltage */ |
| 732 | if (rdev->constraints->apply_uV && |
| 733 | rdev->constraints->min_uV == rdev->constraints->max_uV && |
| 734 | ops->set_voltage) { |
| 735 | ret = ops->set_voltage(rdev, |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 736 | rdev->constraints->min_uV, |
| 737 | rdev->constraints->max_uV, |
| 738 | &selector); |
Mark Brown | af5866c | 2009-10-22 16:31:30 +0100 | [diff] [blame] | 739 | if (ret < 0) { |
| 740 | printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n", |
| 741 | __func__, |
| 742 | rdev->constraints->min_uV, name); |
| 743 | rdev->constraints = NULL; |
| 744 | return ret; |
| 745 | } |
| 746 | } |
Mark Brown | e79055d | 2009-10-19 15:53:50 +0100 | [diff] [blame] | 747 | |
| 748 | /* constrain machine-level voltage specs to fit |
| 749 | * the actual range supported by this regulator. |
| 750 | */ |
| 751 | if (ops->list_voltage && rdev->desc->n_voltages) { |
| 752 | int count = rdev->desc->n_voltages; |
| 753 | int i; |
| 754 | int min_uV = INT_MAX; |
| 755 | int max_uV = INT_MIN; |
| 756 | int cmin = constraints->min_uV; |
| 757 | int cmax = constraints->max_uV; |
| 758 | |
| 759 | /* it's safe to autoconfigure fixed-voltage supplies |
| 760 | and the constraints are used by list_voltage. */ |
| 761 | if (count == 1 && !cmin) { |
| 762 | cmin = 1; |
| 763 | cmax = INT_MAX; |
| 764 | constraints->min_uV = cmin; |
| 765 | constraints->max_uV = cmax; |
| 766 | } |
| 767 | |
| 768 | /* voltage constraints are optional */ |
| 769 | if ((cmin == 0) && (cmax == 0)) |
| 770 | return 0; |
| 771 | |
| 772 | /* else require explicit machine-level constraints */ |
| 773 | if (cmin <= 0 || cmax <= 0 || cmax < cmin) { |
| 774 | pr_err("%s: %s '%s' voltage constraints\n", |
| 775 | __func__, "invalid", name); |
| 776 | return -EINVAL; |
| 777 | } |
| 778 | |
| 779 | /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */ |
| 780 | for (i = 0; i < count; i++) { |
| 781 | int value; |
| 782 | |
| 783 | value = ops->list_voltage(rdev, i); |
| 784 | if (value <= 0) |
| 785 | continue; |
| 786 | |
| 787 | /* maybe adjust [min_uV..max_uV] */ |
| 788 | if (value >= cmin && value < min_uV) |
| 789 | min_uV = value; |
| 790 | if (value <= cmax && value > max_uV) |
| 791 | max_uV = value; |
| 792 | } |
| 793 | |
| 794 | /* final: [min_uV..max_uV] valid iff constraints valid */ |
| 795 | if (max_uV < min_uV) { |
| 796 | pr_err("%s: %s '%s' voltage constraints\n", |
| 797 | __func__, "unsupportable", name); |
| 798 | return -EINVAL; |
| 799 | } |
| 800 | |
| 801 | /* use regulator's subset of machine constraints */ |
| 802 | if (constraints->min_uV < min_uV) { |
| 803 | pr_debug("%s: override '%s' %s, %d -> %d\n", |
| 804 | __func__, name, "min_uV", |
| 805 | constraints->min_uV, min_uV); |
| 806 | constraints->min_uV = min_uV; |
| 807 | } |
| 808 | if (constraints->max_uV > max_uV) { |
| 809 | pr_debug("%s: override '%s' %s, %d -> %d\n", |
| 810 | __func__, name, "max_uV", |
| 811 | constraints->max_uV, max_uV); |
| 812 | constraints->max_uV = max_uV; |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | return 0; |
| 817 | } |
| 818 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 819 | /** |
| 820 | * set_machine_constraints - sets regulator constraints |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 821 | * @rdev: regulator source |
Mark Brown | c8e7e46 | 2008-12-31 12:52:42 +0000 | [diff] [blame] | 822 | * @constraints: constraints to apply |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 823 | * |
| 824 | * Allows platform initialisation code to define and constrain |
| 825 | * regulator circuits e.g. valid voltage/current ranges, etc. NOTE: |
| 826 | * Constraints *must* be set by platform code in order for some |
| 827 | * regulator operations to proceed i.e. set_voltage, set_current_limit, |
| 828 | * set_mode. |
| 829 | */ |
| 830 | static int set_machine_constraints(struct regulator_dev *rdev, |
| 831 | struct regulation_constraints *constraints) |
| 832 | { |
| 833 | int ret = 0; |
Mark Brown | e06f5b4 | 2008-09-09 16:21:19 +0100 | [diff] [blame] | 834 | const char *name; |
Mark Brown | e5fda26 | 2008-09-09 16:21:20 +0100 | [diff] [blame] | 835 | struct regulator_ops *ops = rdev->desc->ops; |
Mark Brown | e06f5b4 | 2008-09-09 16:21:19 +0100 | [diff] [blame] | 836 | |
Mark Brown | af5866c | 2009-10-22 16:31:30 +0100 | [diff] [blame] | 837 | rdev->constraints = constraints; |
| 838 | |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 839 | name = rdev_get_name(rdev); |
| 840 | |
| 841 | ret = machine_constraints_voltage(rdev, constraints); |
Mark Brown | e79055d | 2009-10-19 15:53:50 +0100 | [diff] [blame] | 842 | if (ret != 0) |
| 843 | goto out; |
David Brownell | 4367cfd | 2009-02-26 11:48:36 -0800 | [diff] [blame] | 844 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 845 | /* do we need to setup our suspend state */ |
Mark Brown | e06f5b4 | 2008-09-09 16:21:19 +0100 | [diff] [blame] | 846 | if (constraints->initial_state) { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 847 | ret = suspend_prepare(rdev, constraints->initial_state); |
Mark Brown | e06f5b4 | 2008-09-09 16:21:19 +0100 | [diff] [blame] | 848 | if (ret < 0) { |
| 849 | printk(KERN_ERR "%s: failed to set suspend state for %s\n", |
| 850 | __func__, name); |
| 851 | rdev->constraints = NULL; |
| 852 | goto out; |
| 853 | } |
| 854 | } |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 855 | |
Mark Brown | a308466 | 2009-02-26 19:24:19 +0000 | [diff] [blame] | 856 | if (constraints->initial_mode) { |
| 857 | if (!ops->set_mode) { |
| 858 | printk(KERN_ERR "%s: no set_mode operation for %s\n", |
| 859 | __func__, name); |
| 860 | ret = -EINVAL; |
| 861 | goto out; |
| 862 | } |
| 863 | |
| 864 | ret = ops->set_mode(rdev, constraints->initial_mode); |
| 865 | if (ret < 0) { |
| 866 | printk(KERN_ERR |
| 867 | "%s: failed to set initial mode for %s: %d\n", |
| 868 | __func__, name, ret); |
| 869 | goto out; |
| 870 | } |
| 871 | } |
| 872 | |
Mark Brown | cacf90f | 2009-03-02 16:32:46 +0000 | [diff] [blame] | 873 | /* If the constraints say the regulator should be on at this point |
| 874 | * and we have control then make sure it is enabled. |
| 875 | */ |
| 876 | if ((constraints->always_on || constraints->boot_on) && ops->enable) { |
Mark Brown | e5fda26 | 2008-09-09 16:21:20 +0100 | [diff] [blame] | 877 | ret = ops->enable(rdev); |
| 878 | if (ret < 0) { |
| 879 | printk(KERN_ERR "%s: failed to enable %s\n", |
| 880 | __func__, name); |
| 881 | rdev->constraints = NULL; |
| 882 | goto out; |
| 883 | } |
| 884 | } |
| 885 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 886 | print_constraints(rdev); |
| 887 | out: |
| 888 | return ret; |
| 889 | } |
| 890 | |
| 891 | /** |
| 892 | * set_supply - set regulator supply regulator |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 893 | * @rdev: regulator name |
| 894 | * @supply_rdev: supply regulator name |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 895 | * |
| 896 | * Called by platform initialisation code to set the supply regulator for this |
| 897 | * regulator. This ensures that a regulators supply will also be enabled by the |
| 898 | * core if it's child is enabled. |
| 899 | */ |
| 900 | static int set_supply(struct regulator_dev *rdev, |
| 901 | struct regulator_dev *supply_rdev) |
| 902 | { |
| 903 | int err; |
| 904 | |
| 905 | err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj, |
| 906 | "supply"); |
| 907 | if (err) { |
| 908 | printk(KERN_ERR |
| 909 | "%s: could not add device link %s err %d\n", |
| 910 | __func__, supply_rdev->dev.kobj.name, err); |
| 911 | goto out; |
| 912 | } |
| 913 | rdev->supply = supply_rdev; |
| 914 | list_add(&rdev->slist, &supply_rdev->supply_list); |
| 915 | out: |
| 916 | return err; |
| 917 | } |
| 918 | |
| 919 | /** |
Randy Dunlap | 06c63f9 | 2010-11-18 15:02:26 -0800 | [diff] [blame] | 920 | * set_consumer_device_supply - Bind a regulator to a symbolic supply |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 921 | * @rdev: regulator source |
| 922 | * @consumer_dev: device the supply applies to |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 923 | * @consumer_dev_name: dev_name() string for device supply applies to |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 924 | * @supply: symbolic name for supply |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 925 | * |
| 926 | * Allows platform initialisation code to map physical regulator |
| 927 | * sources to symbolic names for supplies for use by devices. Devices |
| 928 | * should use these symbolic names to request regulators, avoiding the |
| 929 | * need to provide board-specific regulator names as platform data. |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 930 | * |
| 931 | * Only one of consumer_dev and consumer_dev_name may be specified. |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 932 | */ |
| 933 | static int set_consumer_device_supply(struct regulator_dev *rdev, |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 934 | struct device *consumer_dev, const char *consumer_dev_name, |
| 935 | const char *supply) |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 936 | { |
| 937 | struct regulator_map *node; |
Mark Brown | 9ed2099 | 2009-07-21 16:00:26 +0100 | [diff] [blame] | 938 | int has_dev; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 939 | |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 940 | if (consumer_dev && consumer_dev_name) |
| 941 | return -EINVAL; |
| 942 | |
| 943 | if (!consumer_dev_name && consumer_dev) |
| 944 | consumer_dev_name = dev_name(consumer_dev); |
| 945 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 946 | if (supply == NULL) |
| 947 | return -EINVAL; |
| 948 | |
Mark Brown | 9ed2099 | 2009-07-21 16:00:26 +0100 | [diff] [blame] | 949 | if (consumer_dev_name != NULL) |
| 950 | has_dev = 1; |
| 951 | else |
| 952 | has_dev = 0; |
| 953 | |
David Brownell | 6001e13 | 2008-12-31 12:54:19 +0000 | [diff] [blame] | 954 | list_for_each_entry(node, ®ulator_map_list, list) { |
Jani Nikula | 23b5cc2 | 2010-04-29 10:55:09 +0300 | [diff] [blame] | 955 | if (node->dev_name && consumer_dev_name) { |
| 956 | if (strcmp(node->dev_name, consumer_dev_name) != 0) |
| 957 | continue; |
| 958 | } else if (node->dev_name || consumer_dev_name) { |
David Brownell | 6001e13 | 2008-12-31 12:54:19 +0000 | [diff] [blame] | 959 | continue; |
Jani Nikula | 23b5cc2 | 2010-04-29 10:55:09 +0300 | [diff] [blame] | 960 | } |
| 961 | |
David Brownell | 6001e13 | 2008-12-31 12:54:19 +0000 | [diff] [blame] | 962 | if (strcmp(node->supply, supply) != 0) |
| 963 | continue; |
| 964 | |
| 965 | dev_dbg(consumer_dev, "%s/%s is '%s' supply; fail %s/%s\n", |
| 966 | dev_name(&node->regulator->dev), |
| 967 | node->regulator->desc->name, |
| 968 | supply, |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 969 | dev_name(&rdev->dev), rdev_get_name(rdev)); |
David Brownell | 6001e13 | 2008-12-31 12:54:19 +0000 | [diff] [blame] | 970 | return -EBUSY; |
| 971 | } |
| 972 | |
Mark Brown | 9ed2099 | 2009-07-21 16:00:26 +0100 | [diff] [blame] | 973 | node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL); |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 974 | if (node == NULL) |
| 975 | return -ENOMEM; |
| 976 | |
| 977 | node->regulator = rdev; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 978 | node->supply = supply; |
| 979 | |
Mark Brown | 9ed2099 | 2009-07-21 16:00:26 +0100 | [diff] [blame] | 980 | if (has_dev) { |
| 981 | node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL); |
| 982 | if (node->dev_name == NULL) { |
| 983 | kfree(node); |
| 984 | return -ENOMEM; |
| 985 | } |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 986 | } |
| 987 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 988 | list_add(&node->list, ®ulator_map_list); |
| 989 | return 0; |
| 990 | } |
| 991 | |
Mike Rapoport | 0f1d747 | 2009-01-22 16:00:29 +0200 | [diff] [blame] | 992 | static void unset_regulator_supplies(struct regulator_dev *rdev) |
| 993 | { |
| 994 | struct regulator_map *node, *n; |
| 995 | |
| 996 | list_for_each_entry_safe(node, n, ®ulator_map_list, list) { |
| 997 | if (rdev == node->regulator) { |
| 998 | list_del(&node->list); |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 999 | kfree(node->dev_name); |
Mike Rapoport | 0f1d747 | 2009-01-22 16:00:29 +0200 | [diff] [blame] | 1000 | kfree(node); |
Mike Rapoport | 0f1d747 | 2009-01-22 16:00:29 +0200 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1005 | #define REG_STR_SIZE 32 |
| 1006 | |
| 1007 | static struct regulator *create_regulator(struct regulator_dev *rdev, |
| 1008 | struct device *dev, |
| 1009 | const char *supply_name) |
| 1010 | { |
| 1011 | struct regulator *regulator; |
| 1012 | char buf[REG_STR_SIZE]; |
| 1013 | int err, size; |
| 1014 | |
| 1015 | regulator = kzalloc(sizeof(*regulator), GFP_KERNEL); |
| 1016 | if (regulator == NULL) |
| 1017 | return NULL; |
| 1018 | |
| 1019 | mutex_lock(&rdev->mutex); |
| 1020 | regulator->rdev = rdev; |
| 1021 | list_add(®ulator->list, &rdev->consumer_list); |
| 1022 | |
| 1023 | if (dev) { |
| 1024 | /* create a 'requested_microamps_name' sysfs entry */ |
| 1025 | size = scnprintf(buf, REG_STR_SIZE, "microamps_requested_%s", |
| 1026 | supply_name); |
| 1027 | if (size >= REG_STR_SIZE) |
| 1028 | goto overflow_err; |
| 1029 | |
| 1030 | regulator->dev = dev; |
Ameya Palande | 4f26a2a | 2010-03-12 20:09:01 +0200 | [diff] [blame] | 1031 | sysfs_attr_init(®ulator->dev_attr.attr); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1032 | regulator->dev_attr.attr.name = kstrdup(buf, GFP_KERNEL); |
| 1033 | if (regulator->dev_attr.attr.name == NULL) |
| 1034 | goto attr_name_err; |
| 1035 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1036 | regulator->dev_attr.attr.mode = 0444; |
| 1037 | regulator->dev_attr.show = device_requested_uA_show; |
| 1038 | err = device_create_file(dev, ®ulator->dev_attr); |
| 1039 | if (err < 0) { |
| 1040 | printk(KERN_WARNING "%s: could not add regulator_dev" |
| 1041 | " load sysfs\n", __func__); |
| 1042 | goto attr_name_err; |
| 1043 | } |
| 1044 | |
| 1045 | /* also add a link to the device sysfs entry */ |
| 1046 | size = scnprintf(buf, REG_STR_SIZE, "%s-%s", |
| 1047 | dev->kobj.name, supply_name); |
| 1048 | if (size >= REG_STR_SIZE) |
| 1049 | goto attr_err; |
| 1050 | |
| 1051 | regulator->supply_name = kstrdup(buf, GFP_KERNEL); |
| 1052 | if (regulator->supply_name == NULL) |
| 1053 | goto attr_err; |
| 1054 | |
| 1055 | err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj, |
| 1056 | buf); |
| 1057 | if (err) { |
| 1058 | printk(KERN_WARNING |
| 1059 | "%s: could not add device link %s err %d\n", |
| 1060 | __func__, dev->kobj.name, err); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1061 | goto link_name_err; |
| 1062 | } |
| 1063 | } |
| 1064 | mutex_unlock(&rdev->mutex); |
| 1065 | return regulator; |
| 1066 | link_name_err: |
| 1067 | kfree(regulator->supply_name); |
| 1068 | attr_err: |
| 1069 | device_remove_file(regulator->dev, ®ulator->dev_attr); |
| 1070 | attr_name_err: |
| 1071 | kfree(regulator->dev_attr.attr.name); |
| 1072 | overflow_err: |
| 1073 | list_del(®ulator->list); |
| 1074 | kfree(regulator); |
| 1075 | mutex_unlock(&rdev->mutex); |
| 1076 | return NULL; |
| 1077 | } |
| 1078 | |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 1079 | static int _regulator_get_enable_time(struct regulator_dev *rdev) |
| 1080 | { |
| 1081 | if (!rdev->desc->ops->enable_time) |
| 1082 | return 0; |
| 1083 | return rdev->desc->ops->enable_time(rdev); |
| 1084 | } |
| 1085 | |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1086 | /* Internal regulator request function */ |
| 1087 | static struct regulator *_regulator_get(struct device *dev, const char *id, |
| 1088 | int exclusive) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1089 | { |
| 1090 | struct regulator_dev *rdev; |
| 1091 | struct regulator_map *map; |
| 1092 | struct regulator *regulator = ERR_PTR(-ENODEV); |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 1093 | const char *devname = NULL; |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1094 | int ret; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1095 | |
| 1096 | if (id == NULL) { |
| 1097 | printk(KERN_ERR "regulator: get() with no identifier\n"); |
| 1098 | return regulator; |
| 1099 | } |
| 1100 | |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 1101 | if (dev) |
| 1102 | devname = dev_name(dev); |
| 1103 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1104 | mutex_lock(®ulator_list_mutex); |
| 1105 | |
| 1106 | list_for_each_entry(map, ®ulator_map_list, list) { |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 1107 | /* If the mapping has a device set up it must match */ |
| 1108 | if (map->dev_name && |
| 1109 | (!devname || strcmp(map->dev_name, devname))) |
| 1110 | continue; |
| 1111 | |
| 1112 | if (strcmp(map->supply, id) == 0) { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1113 | rdev = map->regulator; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1114 | goto found; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1115 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1116 | } |
Mark Brown | 34abbd6 | 2010-02-12 10:18:08 +0000 | [diff] [blame] | 1117 | |
Mark Brown | 688fe99 | 2010-10-05 19:18:32 -0700 | [diff] [blame] | 1118 | if (board_wants_dummy_regulator) { |
| 1119 | rdev = dummy_regulator_rdev; |
| 1120 | goto found; |
| 1121 | } |
| 1122 | |
Mark Brown | 34abbd6 | 2010-02-12 10:18:08 +0000 | [diff] [blame] | 1123 | #ifdef CONFIG_REGULATOR_DUMMY |
| 1124 | if (!devname) |
| 1125 | devname = "deviceless"; |
| 1126 | |
| 1127 | /* If the board didn't flag that it was fully constrained then |
| 1128 | * substitute in a dummy regulator so consumers can continue. |
| 1129 | */ |
| 1130 | if (!has_full_constraints) { |
| 1131 | pr_warning("%s supply %s not found, using dummy regulator\n", |
| 1132 | devname, id); |
| 1133 | rdev = dummy_regulator_rdev; |
| 1134 | goto found; |
| 1135 | } |
| 1136 | #endif |
| 1137 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1138 | mutex_unlock(®ulator_list_mutex); |
| 1139 | return regulator; |
| 1140 | |
| 1141 | found: |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1142 | if (rdev->exclusive) { |
| 1143 | regulator = ERR_PTR(-EPERM); |
| 1144 | goto out; |
| 1145 | } |
| 1146 | |
| 1147 | if (exclusive && rdev->open_count) { |
| 1148 | regulator = ERR_PTR(-EBUSY); |
| 1149 | goto out; |
| 1150 | } |
| 1151 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1152 | if (!try_module_get(rdev->owner)) |
| 1153 | goto out; |
| 1154 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1155 | regulator = create_regulator(rdev, dev, id); |
| 1156 | if (regulator == NULL) { |
| 1157 | regulator = ERR_PTR(-ENOMEM); |
| 1158 | module_put(rdev->owner); |
| 1159 | } |
| 1160 | |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1161 | rdev->open_count++; |
| 1162 | if (exclusive) { |
| 1163 | rdev->exclusive = 1; |
| 1164 | |
| 1165 | ret = _regulator_is_enabled(rdev); |
| 1166 | if (ret > 0) |
| 1167 | rdev->use_count = 1; |
| 1168 | else |
| 1169 | rdev->use_count = 0; |
| 1170 | } |
| 1171 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1172 | out: |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1173 | mutex_unlock(®ulator_list_mutex); |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1174 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1175 | return regulator; |
| 1176 | } |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1177 | |
| 1178 | /** |
| 1179 | * regulator_get - lookup and obtain a reference to a regulator. |
| 1180 | * @dev: device for regulator "consumer" |
| 1181 | * @id: Supply name or regulator ID. |
| 1182 | * |
| 1183 | * Returns a struct regulator corresponding to the regulator producer, |
| 1184 | * or IS_ERR() condition containing errno. |
| 1185 | * |
| 1186 | * Use of supply names configured via regulator_set_device_supply() is |
| 1187 | * strongly encouraged. It is recommended that the supply name used |
| 1188 | * should match the name used for the supply and/or the relevant |
| 1189 | * device pins in the datasheet. |
| 1190 | */ |
| 1191 | struct regulator *regulator_get(struct device *dev, const char *id) |
| 1192 | { |
| 1193 | return _regulator_get(dev, id, 0); |
| 1194 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1195 | EXPORT_SYMBOL_GPL(regulator_get); |
| 1196 | |
| 1197 | /** |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1198 | * regulator_get_exclusive - obtain exclusive access to a regulator. |
| 1199 | * @dev: device for regulator "consumer" |
| 1200 | * @id: Supply name or regulator ID. |
| 1201 | * |
| 1202 | * Returns a struct regulator corresponding to the regulator producer, |
| 1203 | * or IS_ERR() condition containing errno. Other consumers will be |
| 1204 | * unable to obtain this reference is held and the use count for the |
| 1205 | * regulator will be initialised to reflect the current state of the |
| 1206 | * regulator. |
| 1207 | * |
| 1208 | * This is intended for use by consumers which cannot tolerate shared |
| 1209 | * use of the regulator such as those which need to force the |
| 1210 | * regulator off for correct operation of the hardware they are |
| 1211 | * controlling. |
| 1212 | * |
| 1213 | * Use of supply names configured via regulator_set_device_supply() is |
| 1214 | * strongly encouraged. It is recommended that the supply name used |
| 1215 | * should match the name used for the supply and/or the relevant |
| 1216 | * device pins in the datasheet. |
| 1217 | */ |
| 1218 | struct regulator *regulator_get_exclusive(struct device *dev, const char *id) |
| 1219 | { |
| 1220 | return _regulator_get(dev, id, 1); |
| 1221 | } |
| 1222 | EXPORT_SYMBOL_GPL(regulator_get_exclusive); |
| 1223 | |
| 1224 | /** |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1225 | * regulator_put - "free" the regulator source |
| 1226 | * @regulator: regulator source |
| 1227 | * |
| 1228 | * Note: drivers must ensure that all regulator_enable calls made on this |
| 1229 | * regulator source are balanced by regulator_disable calls prior to calling |
| 1230 | * this function. |
| 1231 | */ |
| 1232 | void regulator_put(struct regulator *regulator) |
| 1233 | { |
| 1234 | struct regulator_dev *rdev; |
| 1235 | |
| 1236 | if (regulator == NULL || IS_ERR(regulator)) |
| 1237 | return; |
| 1238 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1239 | mutex_lock(®ulator_list_mutex); |
| 1240 | rdev = regulator->rdev; |
| 1241 | |
| 1242 | /* remove any sysfs entries */ |
| 1243 | if (regulator->dev) { |
| 1244 | sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); |
| 1245 | kfree(regulator->supply_name); |
| 1246 | device_remove_file(regulator->dev, ®ulator->dev_attr); |
| 1247 | kfree(regulator->dev_attr.attr.name); |
| 1248 | } |
| 1249 | list_del(®ulator->list); |
| 1250 | kfree(regulator); |
| 1251 | |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1252 | rdev->open_count--; |
| 1253 | rdev->exclusive = 0; |
| 1254 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1255 | module_put(rdev->owner); |
| 1256 | mutex_unlock(®ulator_list_mutex); |
| 1257 | } |
| 1258 | EXPORT_SYMBOL_GPL(regulator_put); |
| 1259 | |
Mark Brown | 9a2372f | 2009-08-03 18:49:57 +0100 | [diff] [blame] | 1260 | static int _regulator_can_change_status(struct regulator_dev *rdev) |
| 1261 | { |
| 1262 | if (!rdev->constraints) |
| 1263 | return 0; |
| 1264 | |
| 1265 | if (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_STATUS) |
| 1266 | return 1; |
| 1267 | else |
| 1268 | return 0; |
| 1269 | } |
| 1270 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1271 | /* locks held by regulator_enable() */ |
| 1272 | static int _regulator_enable(struct regulator_dev *rdev) |
| 1273 | { |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 1274 | int ret, delay; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1275 | |
Bengt Jonsson | acaf6ff | 2010-11-10 11:06:22 +0100 | [diff] [blame^] | 1276 | if (rdev->use_count == 0) { |
| 1277 | /* do we need to enable the supply regulator first */ |
| 1278 | if (rdev->supply) { |
| 1279 | mutex_lock(&rdev->supply->mutex); |
| 1280 | ret = _regulator_enable(rdev->supply); |
| 1281 | mutex_unlock(&rdev->supply->mutex); |
| 1282 | if (ret < 0) { |
| 1283 | printk(KERN_ERR "%s: failed to enable %s: %d\n", |
| 1284 | __func__, rdev_get_name(rdev), ret); |
| 1285 | return ret; |
| 1286 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | /* check voltage and requested load before enabling */ |
Mark Brown | 9a2372f | 2009-08-03 18:49:57 +0100 | [diff] [blame] | 1291 | if (rdev->constraints && |
| 1292 | (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) |
| 1293 | drms_uA_update(rdev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1294 | |
Mark Brown | 9a2372f | 2009-08-03 18:49:57 +0100 | [diff] [blame] | 1295 | if (rdev->use_count == 0) { |
| 1296 | /* The regulator may on if it's not switchable or left on */ |
| 1297 | ret = _regulator_is_enabled(rdev); |
| 1298 | if (ret == -EINVAL || ret == 0) { |
| 1299 | if (!_regulator_can_change_status(rdev)) |
| 1300 | return -EPERM; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1301 | |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 1302 | if (!rdev->desc->ops->enable) |
Mark Brown | 9a2372f | 2009-08-03 18:49:57 +0100 | [diff] [blame] | 1303 | return -EINVAL; |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 1304 | |
| 1305 | /* Query before enabling in case configuration |
| 1306 | * dependant. */ |
| 1307 | ret = _regulator_get_enable_time(rdev); |
| 1308 | if (ret >= 0) { |
| 1309 | delay = ret; |
| 1310 | } else { |
| 1311 | printk(KERN_WARNING |
| 1312 | "%s: enable_time() failed for %s: %d\n", |
| 1313 | __func__, rdev_get_name(rdev), |
| 1314 | ret); |
| 1315 | delay = 0; |
Mark Brown | 9a2372f | 2009-08-03 18:49:57 +0100 | [diff] [blame] | 1316 | } |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 1317 | |
Mark Brown | 02fa3ec | 2010-11-10 14:38:30 +0000 | [diff] [blame] | 1318 | trace_regulator_enable(rdev_get_name(rdev)); |
| 1319 | |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 1320 | /* Allow the regulator to ramp; it would be useful |
| 1321 | * to extend this for bulk operations so that the |
| 1322 | * regulators can ramp together. */ |
| 1323 | ret = rdev->desc->ops->enable(rdev); |
| 1324 | if (ret < 0) |
| 1325 | return ret; |
| 1326 | |
Mark Brown | 02fa3ec | 2010-11-10 14:38:30 +0000 | [diff] [blame] | 1327 | trace_regulator_enable_delay(rdev_get_name(rdev)); |
| 1328 | |
Axel Lin | e36c1df | 2010-11-05 21:51:32 +0800 | [diff] [blame] | 1329 | if (delay >= 1000) { |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 1330 | mdelay(delay / 1000); |
Axel Lin | e36c1df | 2010-11-05 21:51:32 +0800 | [diff] [blame] | 1331 | udelay(delay % 1000); |
| 1332 | } else if (delay) { |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 1333 | udelay(delay); |
Axel Lin | e36c1df | 2010-11-05 21:51:32 +0800 | [diff] [blame] | 1334 | } |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 1335 | |
Mark Brown | 02fa3ec | 2010-11-10 14:38:30 +0000 | [diff] [blame] | 1336 | trace_regulator_enable_complete(rdev_get_name(rdev)); |
| 1337 | |
Linus Walleij | a7433cf | 2009-08-26 12:54:04 +0200 | [diff] [blame] | 1338 | } else if (ret < 0) { |
Mark Brown | 9a2372f | 2009-08-03 18:49:57 +0100 | [diff] [blame] | 1339 | printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n", |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 1340 | __func__, rdev_get_name(rdev), ret); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1341 | return ret; |
| 1342 | } |
Linus Walleij | a7433cf | 2009-08-26 12:54:04 +0200 | [diff] [blame] | 1343 | /* Fallthrough on positive return values - already enabled */ |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1344 | } |
| 1345 | |
Mark Brown | 9a2372f | 2009-08-03 18:49:57 +0100 | [diff] [blame] | 1346 | rdev->use_count++; |
| 1347 | |
| 1348 | return 0; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | /** |
| 1352 | * regulator_enable - enable regulator output |
| 1353 | * @regulator: regulator source |
| 1354 | * |
Mark Brown | cf7bbcd | 2008-12-31 12:52:43 +0000 | [diff] [blame] | 1355 | * Request that the regulator be enabled with the regulator output at |
| 1356 | * the predefined voltage or current value. Calls to regulator_enable() |
| 1357 | * must be balanced with calls to regulator_disable(). |
| 1358 | * |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1359 | * NOTE: the output value can be set by other drivers, boot loader or may be |
Mark Brown | cf7bbcd | 2008-12-31 12:52:43 +0000 | [diff] [blame] | 1360 | * hardwired in the regulator. |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1361 | */ |
| 1362 | int regulator_enable(struct regulator *regulator) |
| 1363 | { |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1364 | struct regulator_dev *rdev = regulator->rdev; |
| 1365 | int ret = 0; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1366 | |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1367 | mutex_lock(&rdev->mutex); |
David Brownell | cd94b50 | 2009-03-11 16:43:34 -0800 | [diff] [blame] | 1368 | ret = _regulator_enable(rdev); |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1369 | mutex_unlock(&rdev->mutex); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1370 | return ret; |
| 1371 | } |
| 1372 | EXPORT_SYMBOL_GPL(regulator_enable); |
| 1373 | |
| 1374 | /* locks held by regulator_disable() */ |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1375 | static int _regulator_disable(struct regulator_dev *rdev, |
| 1376 | struct regulator_dev **supply_rdev_ptr) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1377 | { |
| 1378 | int ret = 0; |
Mattias Wallin | b12a1e2 | 2010-11-02 14:55:34 +0100 | [diff] [blame] | 1379 | *supply_rdev_ptr = NULL; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1380 | |
David Brownell | cd94b50 | 2009-03-11 16:43:34 -0800 | [diff] [blame] | 1381 | if (WARN(rdev->use_count <= 0, |
| 1382 | "unbalanced disables for %s\n", |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 1383 | rdev_get_name(rdev))) |
David Brownell | cd94b50 | 2009-03-11 16:43:34 -0800 | [diff] [blame] | 1384 | return -EIO; |
| 1385 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1386 | /* are we the last user and permitted to disable ? */ |
Mark Brown | 60ef66f | 2009-10-13 13:06:50 +0100 | [diff] [blame] | 1387 | if (rdev->use_count == 1 && |
| 1388 | (rdev->constraints && !rdev->constraints->always_on)) { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1389 | |
| 1390 | /* we are last user */ |
Mark Brown | 9a2372f | 2009-08-03 18:49:57 +0100 | [diff] [blame] | 1391 | if (_regulator_can_change_status(rdev) && |
| 1392 | rdev->desc->ops->disable) { |
Mark Brown | 02fa3ec | 2010-11-10 14:38:30 +0000 | [diff] [blame] | 1393 | trace_regulator_disable(rdev_get_name(rdev)); |
| 1394 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1395 | ret = rdev->desc->ops->disable(rdev); |
| 1396 | if (ret < 0) { |
| 1397 | printk(KERN_ERR "%s: failed to disable %s\n", |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 1398 | __func__, rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1399 | return ret; |
| 1400 | } |
Mark Brown | 84b6826 | 2009-12-01 21:12:27 +0000 | [diff] [blame] | 1401 | |
Mark Brown | 02fa3ec | 2010-11-10 14:38:30 +0000 | [diff] [blame] | 1402 | trace_regulator_disable_complete(rdev_get_name(rdev)); |
| 1403 | |
Mark Brown | 84b6826 | 2009-12-01 21:12:27 +0000 | [diff] [blame] | 1404 | _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE, |
| 1405 | NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | /* decrease our supplies ref count and disable if required */ |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1409 | *supply_rdev_ptr = rdev->supply; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1410 | |
| 1411 | rdev->use_count = 0; |
| 1412 | } else if (rdev->use_count > 1) { |
| 1413 | |
| 1414 | if (rdev->constraints && |
| 1415 | (rdev->constraints->valid_ops_mask & |
| 1416 | REGULATOR_CHANGE_DRMS)) |
| 1417 | drms_uA_update(rdev); |
| 1418 | |
| 1419 | rdev->use_count--; |
| 1420 | } |
| 1421 | return ret; |
| 1422 | } |
| 1423 | |
| 1424 | /** |
| 1425 | * regulator_disable - disable regulator output |
| 1426 | * @regulator: regulator source |
| 1427 | * |
Mark Brown | cf7bbcd | 2008-12-31 12:52:43 +0000 | [diff] [blame] | 1428 | * Disable the regulator output voltage or current. Calls to |
| 1429 | * regulator_enable() must be balanced with calls to |
| 1430 | * regulator_disable(). |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 1431 | * |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1432 | * NOTE: this will only disable the regulator output if no other consumer |
Mark Brown | cf7bbcd | 2008-12-31 12:52:43 +0000 | [diff] [blame] | 1433 | * devices have it enabled, the regulator device supports disabling and |
| 1434 | * machine constraints permit this operation. |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1435 | */ |
| 1436 | int regulator_disable(struct regulator *regulator) |
| 1437 | { |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1438 | struct regulator_dev *rdev = regulator->rdev; |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1439 | struct regulator_dev *supply_rdev = NULL; |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1440 | int ret = 0; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1441 | |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1442 | mutex_lock(&rdev->mutex); |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1443 | ret = _regulator_disable(rdev, &supply_rdev); |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1444 | mutex_unlock(&rdev->mutex); |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1445 | |
| 1446 | /* decrease our supplies ref count and disable if required */ |
| 1447 | while (supply_rdev != NULL) { |
| 1448 | rdev = supply_rdev; |
| 1449 | |
| 1450 | mutex_lock(&rdev->mutex); |
| 1451 | _regulator_disable(rdev, &supply_rdev); |
| 1452 | mutex_unlock(&rdev->mutex); |
| 1453 | } |
| 1454 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1455 | return ret; |
| 1456 | } |
| 1457 | EXPORT_SYMBOL_GPL(regulator_disable); |
| 1458 | |
| 1459 | /* locks held by regulator_force_disable() */ |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1460 | static int _regulator_force_disable(struct regulator_dev *rdev, |
| 1461 | struct regulator_dev **supply_rdev_ptr) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1462 | { |
| 1463 | int ret = 0; |
| 1464 | |
| 1465 | /* force disable */ |
| 1466 | if (rdev->desc->ops->disable) { |
| 1467 | /* ah well, who wants to live forever... */ |
| 1468 | ret = rdev->desc->ops->disable(rdev); |
| 1469 | if (ret < 0) { |
| 1470 | printk(KERN_ERR "%s: failed to force disable %s\n", |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 1471 | __func__, rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1472 | return ret; |
| 1473 | } |
| 1474 | /* notify other consumers that power has been forced off */ |
Mark Brown | 84b6826 | 2009-12-01 21:12:27 +0000 | [diff] [blame] | 1475 | _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | |
| 1476 | REGULATOR_EVENT_DISABLE, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | /* decrease our supplies ref count and disable if required */ |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1480 | *supply_rdev_ptr = rdev->supply; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1481 | |
| 1482 | rdev->use_count = 0; |
| 1483 | return ret; |
| 1484 | } |
| 1485 | |
| 1486 | /** |
| 1487 | * regulator_force_disable - force disable regulator output |
| 1488 | * @regulator: regulator source |
| 1489 | * |
| 1490 | * Forcibly disable the regulator output voltage or current. |
| 1491 | * NOTE: this *will* disable the regulator output even if other consumer |
| 1492 | * devices have it enabled. This should be used for situations when device |
| 1493 | * damage will likely occur if the regulator is not disabled (e.g. over temp). |
| 1494 | */ |
| 1495 | int regulator_force_disable(struct regulator *regulator) |
| 1496 | { |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1497 | struct regulator_dev *supply_rdev = NULL; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1498 | int ret; |
| 1499 | |
| 1500 | mutex_lock(®ulator->rdev->mutex); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1501 | regulator->uA_load = 0; |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1502 | ret = _regulator_force_disable(regulator->rdev, &supply_rdev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1503 | mutex_unlock(®ulator->rdev->mutex); |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1504 | |
| 1505 | if (supply_rdev) |
| 1506 | regulator_disable(get_device_regulator(rdev_get_dev(supply_rdev))); |
| 1507 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1508 | return ret; |
| 1509 | } |
| 1510 | EXPORT_SYMBOL_GPL(regulator_force_disable); |
| 1511 | |
| 1512 | static int _regulator_is_enabled(struct regulator_dev *rdev) |
| 1513 | { |
Mark Brown | 9a7f6a4 | 2010-02-11 17:22:45 +0000 | [diff] [blame] | 1514 | /* If we don't know then assume that the regulator is always on */ |
Mark Brown | 9332546 | 2009-08-03 18:49:56 +0100 | [diff] [blame] | 1515 | if (!rdev->desc->ops->is_enabled) |
Mark Brown | 9a7f6a4 | 2010-02-11 17:22:45 +0000 | [diff] [blame] | 1516 | return 1; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1517 | |
Mark Brown | 9332546 | 2009-08-03 18:49:56 +0100 | [diff] [blame] | 1518 | return rdev->desc->ops->is_enabled(rdev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | /** |
| 1522 | * regulator_is_enabled - is the regulator output enabled |
| 1523 | * @regulator: regulator source |
| 1524 | * |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1525 | * Returns positive if the regulator driver backing the source/client |
| 1526 | * has requested that the device be enabled, zero if it hasn't, else a |
| 1527 | * negative errno code. |
| 1528 | * |
| 1529 | * Note that the device backing this regulator handle can have multiple |
| 1530 | * users, so it might be enabled even if regulator_enable() was never |
| 1531 | * called for this particular source. |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1532 | */ |
| 1533 | int regulator_is_enabled(struct regulator *regulator) |
| 1534 | { |
Mark Brown | 9332546 | 2009-08-03 18:49:56 +0100 | [diff] [blame] | 1535 | int ret; |
| 1536 | |
| 1537 | mutex_lock(®ulator->rdev->mutex); |
| 1538 | ret = _regulator_is_enabled(regulator->rdev); |
| 1539 | mutex_unlock(®ulator->rdev->mutex); |
| 1540 | |
| 1541 | return ret; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1542 | } |
| 1543 | EXPORT_SYMBOL_GPL(regulator_is_enabled); |
| 1544 | |
| 1545 | /** |
David Brownell | 4367cfd | 2009-02-26 11:48:36 -0800 | [diff] [blame] | 1546 | * regulator_count_voltages - count regulator_list_voltage() selectors |
| 1547 | * @regulator: regulator source |
| 1548 | * |
| 1549 | * Returns number of selectors, or negative errno. Selectors are |
| 1550 | * numbered starting at zero, and typically correspond to bitfields |
| 1551 | * in hardware registers. |
| 1552 | */ |
| 1553 | int regulator_count_voltages(struct regulator *regulator) |
| 1554 | { |
| 1555 | struct regulator_dev *rdev = regulator->rdev; |
| 1556 | |
| 1557 | return rdev->desc->n_voltages ? : -EINVAL; |
| 1558 | } |
| 1559 | EXPORT_SYMBOL_GPL(regulator_count_voltages); |
| 1560 | |
| 1561 | /** |
| 1562 | * regulator_list_voltage - enumerate supported voltages |
| 1563 | * @regulator: regulator source |
| 1564 | * @selector: identify voltage to list |
| 1565 | * Context: can sleep |
| 1566 | * |
| 1567 | * Returns a voltage that can be passed to @regulator_set_voltage(), |
Thomas Weber | 8839316 | 2010-03-16 11:47:56 +0100 | [diff] [blame] | 1568 | * zero if this selector code can't be used on this system, or a |
David Brownell | 4367cfd | 2009-02-26 11:48:36 -0800 | [diff] [blame] | 1569 | * negative errno. |
| 1570 | */ |
| 1571 | int regulator_list_voltage(struct regulator *regulator, unsigned selector) |
| 1572 | { |
| 1573 | struct regulator_dev *rdev = regulator->rdev; |
| 1574 | struct regulator_ops *ops = rdev->desc->ops; |
| 1575 | int ret; |
| 1576 | |
| 1577 | if (!ops->list_voltage || selector >= rdev->desc->n_voltages) |
| 1578 | return -EINVAL; |
| 1579 | |
| 1580 | mutex_lock(&rdev->mutex); |
| 1581 | ret = ops->list_voltage(rdev, selector); |
| 1582 | mutex_unlock(&rdev->mutex); |
| 1583 | |
| 1584 | if (ret > 0) { |
| 1585 | if (ret < rdev->constraints->min_uV) |
| 1586 | ret = 0; |
| 1587 | else if (ret > rdev->constraints->max_uV) |
| 1588 | ret = 0; |
| 1589 | } |
| 1590 | |
| 1591 | return ret; |
| 1592 | } |
| 1593 | EXPORT_SYMBOL_GPL(regulator_list_voltage); |
| 1594 | |
| 1595 | /** |
Mark Brown | a7a1ad9 | 2009-07-21 16:00:24 +0100 | [diff] [blame] | 1596 | * regulator_is_supported_voltage - check if a voltage range can be supported |
| 1597 | * |
| 1598 | * @regulator: Regulator to check. |
| 1599 | * @min_uV: Minimum required voltage in uV. |
| 1600 | * @max_uV: Maximum required voltage in uV. |
| 1601 | * |
| 1602 | * Returns a boolean or a negative error code. |
| 1603 | */ |
| 1604 | int regulator_is_supported_voltage(struct regulator *regulator, |
| 1605 | int min_uV, int max_uV) |
| 1606 | { |
| 1607 | int i, voltages, ret; |
| 1608 | |
| 1609 | ret = regulator_count_voltages(regulator); |
| 1610 | if (ret < 0) |
| 1611 | return ret; |
| 1612 | voltages = ret; |
| 1613 | |
| 1614 | for (i = 0; i < voltages; i++) { |
| 1615 | ret = regulator_list_voltage(regulator, i); |
| 1616 | |
| 1617 | if (ret >= min_uV && ret <= max_uV) |
| 1618 | return 1; |
| 1619 | } |
| 1620 | |
| 1621 | return 0; |
| 1622 | } |
| 1623 | |
| 1624 | /** |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1625 | * regulator_set_voltage - set regulator output voltage |
| 1626 | * @regulator: regulator source |
| 1627 | * @min_uV: Minimum required voltage in uV |
| 1628 | * @max_uV: Maximum acceptable voltage in uV |
| 1629 | * |
| 1630 | * Sets a voltage regulator to the desired output voltage. This can be set |
| 1631 | * during any regulator state. IOW, regulator can be disabled or enabled. |
| 1632 | * |
| 1633 | * If the regulator is enabled then the voltage will change to the new value |
| 1634 | * immediately otherwise if the regulator is disabled the regulator will |
| 1635 | * output at the new voltage when enabled. |
| 1636 | * |
| 1637 | * NOTE: If the regulator is shared between several devices then the lowest |
| 1638 | * request voltage that meets the system constraints will be used. |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 1639 | * Regulator system constraints must be set for this regulator before |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1640 | * calling this function otherwise this call will fail. |
| 1641 | */ |
| 1642 | int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) |
| 1643 | { |
| 1644 | struct regulator_dev *rdev = regulator->rdev; |
| 1645 | int ret; |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 1646 | unsigned selector; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1647 | |
| 1648 | mutex_lock(&rdev->mutex); |
| 1649 | |
| 1650 | /* sanity check */ |
| 1651 | if (!rdev->desc->ops->set_voltage) { |
| 1652 | ret = -EINVAL; |
| 1653 | goto out; |
| 1654 | } |
| 1655 | |
| 1656 | /* constraints check */ |
| 1657 | ret = regulator_check_voltage(rdev, &min_uV, &max_uV); |
| 1658 | if (ret < 0) |
| 1659 | goto out; |
| 1660 | regulator->min_uV = min_uV; |
| 1661 | regulator->max_uV = max_uV; |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 1662 | |
Mark Brown | 02fa3ec | 2010-11-10 14:38:30 +0000 | [diff] [blame] | 1663 | trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV); |
| 1664 | |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 1665 | ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, &selector); |
| 1666 | |
| 1667 | if (rdev->desc->ops->list_voltage) |
| 1668 | selector = rdev->desc->ops->list_voltage(rdev, selector); |
| 1669 | else |
| 1670 | selector = -1; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1671 | |
Mark Brown | 02fa3ec | 2010-11-10 14:38:30 +0000 | [diff] [blame] | 1672 | trace_regulator_set_voltage_complete(rdev_get_name(rdev), selector); |
| 1673 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1674 | out: |
Jonathan Cameron | b136fb4 | 2009-01-19 18:20:58 +0000 | [diff] [blame] | 1675 | _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1676 | mutex_unlock(&rdev->mutex); |
| 1677 | return ret; |
| 1678 | } |
| 1679 | EXPORT_SYMBOL_GPL(regulator_set_voltage); |
| 1680 | |
| 1681 | static int _regulator_get_voltage(struct regulator_dev *rdev) |
| 1682 | { |
| 1683 | /* sanity check */ |
| 1684 | if (rdev->desc->ops->get_voltage) |
| 1685 | return rdev->desc->ops->get_voltage(rdev); |
| 1686 | else |
| 1687 | return -EINVAL; |
| 1688 | } |
| 1689 | |
| 1690 | /** |
| 1691 | * regulator_get_voltage - get regulator output voltage |
| 1692 | * @regulator: regulator source |
| 1693 | * |
| 1694 | * This returns the current regulator voltage in uV. |
| 1695 | * |
| 1696 | * NOTE: If the regulator is disabled it will return the voltage value. This |
| 1697 | * function should not be used to determine regulator state. |
| 1698 | */ |
| 1699 | int regulator_get_voltage(struct regulator *regulator) |
| 1700 | { |
| 1701 | int ret; |
| 1702 | |
| 1703 | mutex_lock(®ulator->rdev->mutex); |
| 1704 | |
| 1705 | ret = _regulator_get_voltage(regulator->rdev); |
| 1706 | |
| 1707 | mutex_unlock(®ulator->rdev->mutex); |
| 1708 | |
| 1709 | return ret; |
| 1710 | } |
| 1711 | EXPORT_SYMBOL_GPL(regulator_get_voltage); |
| 1712 | |
| 1713 | /** |
| 1714 | * regulator_set_current_limit - set regulator output current limit |
| 1715 | * @regulator: regulator source |
| 1716 | * @min_uA: Minimuum supported current in uA |
| 1717 | * @max_uA: Maximum supported current in uA |
| 1718 | * |
| 1719 | * Sets current sink to the desired output current. This can be set during |
| 1720 | * any regulator state. IOW, regulator can be disabled or enabled. |
| 1721 | * |
| 1722 | * If the regulator is enabled then the current will change to the new value |
| 1723 | * immediately otherwise if the regulator is disabled the regulator will |
| 1724 | * output at the new current when enabled. |
| 1725 | * |
| 1726 | * NOTE: Regulator system constraints must be set for this regulator before |
| 1727 | * calling this function otherwise this call will fail. |
| 1728 | */ |
| 1729 | int regulator_set_current_limit(struct regulator *regulator, |
| 1730 | int min_uA, int max_uA) |
| 1731 | { |
| 1732 | struct regulator_dev *rdev = regulator->rdev; |
| 1733 | int ret; |
| 1734 | |
| 1735 | mutex_lock(&rdev->mutex); |
| 1736 | |
| 1737 | /* sanity check */ |
| 1738 | if (!rdev->desc->ops->set_current_limit) { |
| 1739 | ret = -EINVAL; |
| 1740 | goto out; |
| 1741 | } |
| 1742 | |
| 1743 | /* constraints check */ |
| 1744 | ret = regulator_check_current_limit(rdev, &min_uA, &max_uA); |
| 1745 | if (ret < 0) |
| 1746 | goto out; |
| 1747 | |
| 1748 | ret = rdev->desc->ops->set_current_limit(rdev, min_uA, max_uA); |
| 1749 | out: |
| 1750 | mutex_unlock(&rdev->mutex); |
| 1751 | return ret; |
| 1752 | } |
| 1753 | EXPORT_SYMBOL_GPL(regulator_set_current_limit); |
| 1754 | |
| 1755 | static int _regulator_get_current_limit(struct regulator_dev *rdev) |
| 1756 | { |
| 1757 | int ret; |
| 1758 | |
| 1759 | mutex_lock(&rdev->mutex); |
| 1760 | |
| 1761 | /* sanity check */ |
| 1762 | if (!rdev->desc->ops->get_current_limit) { |
| 1763 | ret = -EINVAL; |
| 1764 | goto out; |
| 1765 | } |
| 1766 | |
| 1767 | ret = rdev->desc->ops->get_current_limit(rdev); |
| 1768 | out: |
| 1769 | mutex_unlock(&rdev->mutex); |
| 1770 | return ret; |
| 1771 | } |
| 1772 | |
| 1773 | /** |
| 1774 | * regulator_get_current_limit - get regulator output current |
| 1775 | * @regulator: regulator source |
| 1776 | * |
| 1777 | * This returns the current supplied by the specified current sink in uA. |
| 1778 | * |
| 1779 | * NOTE: If the regulator is disabled it will return the current value. This |
| 1780 | * function should not be used to determine regulator state. |
| 1781 | */ |
| 1782 | int regulator_get_current_limit(struct regulator *regulator) |
| 1783 | { |
| 1784 | return _regulator_get_current_limit(regulator->rdev); |
| 1785 | } |
| 1786 | EXPORT_SYMBOL_GPL(regulator_get_current_limit); |
| 1787 | |
| 1788 | /** |
| 1789 | * regulator_set_mode - set regulator operating mode |
| 1790 | * @regulator: regulator source |
| 1791 | * @mode: operating mode - one of the REGULATOR_MODE constants |
| 1792 | * |
| 1793 | * Set regulator operating mode to increase regulator efficiency or improve |
| 1794 | * regulation performance. |
| 1795 | * |
| 1796 | * NOTE: Regulator system constraints must be set for this regulator before |
| 1797 | * calling this function otherwise this call will fail. |
| 1798 | */ |
| 1799 | int regulator_set_mode(struct regulator *regulator, unsigned int mode) |
| 1800 | { |
| 1801 | struct regulator_dev *rdev = regulator->rdev; |
| 1802 | int ret; |
Sundar R Iyer | 500b4ac | 2010-05-17 21:24:48 +0530 | [diff] [blame] | 1803 | int regulator_curr_mode; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1804 | |
| 1805 | mutex_lock(&rdev->mutex); |
| 1806 | |
| 1807 | /* sanity check */ |
| 1808 | if (!rdev->desc->ops->set_mode) { |
| 1809 | ret = -EINVAL; |
| 1810 | goto out; |
| 1811 | } |
| 1812 | |
Sundar R Iyer | 500b4ac | 2010-05-17 21:24:48 +0530 | [diff] [blame] | 1813 | /* return if the same mode is requested */ |
| 1814 | if (rdev->desc->ops->get_mode) { |
| 1815 | regulator_curr_mode = rdev->desc->ops->get_mode(rdev); |
| 1816 | if (regulator_curr_mode == mode) { |
| 1817 | ret = 0; |
| 1818 | goto out; |
| 1819 | } |
| 1820 | } |
| 1821 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1822 | /* constraints check */ |
| 1823 | ret = regulator_check_mode(rdev, mode); |
| 1824 | if (ret < 0) |
| 1825 | goto out; |
| 1826 | |
| 1827 | ret = rdev->desc->ops->set_mode(rdev, mode); |
| 1828 | out: |
| 1829 | mutex_unlock(&rdev->mutex); |
| 1830 | return ret; |
| 1831 | } |
| 1832 | EXPORT_SYMBOL_GPL(regulator_set_mode); |
| 1833 | |
| 1834 | static unsigned int _regulator_get_mode(struct regulator_dev *rdev) |
| 1835 | { |
| 1836 | int ret; |
| 1837 | |
| 1838 | mutex_lock(&rdev->mutex); |
| 1839 | |
| 1840 | /* sanity check */ |
| 1841 | if (!rdev->desc->ops->get_mode) { |
| 1842 | ret = -EINVAL; |
| 1843 | goto out; |
| 1844 | } |
| 1845 | |
| 1846 | ret = rdev->desc->ops->get_mode(rdev); |
| 1847 | out: |
| 1848 | mutex_unlock(&rdev->mutex); |
| 1849 | return ret; |
| 1850 | } |
| 1851 | |
| 1852 | /** |
| 1853 | * regulator_get_mode - get regulator operating mode |
| 1854 | * @regulator: regulator source |
| 1855 | * |
| 1856 | * Get the current regulator operating mode. |
| 1857 | */ |
| 1858 | unsigned int regulator_get_mode(struct regulator *regulator) |
| 1859 | { |
| 1860 | return _regulator_get_mode(regulator->rdev); |
| 1861 | } |
| 1862 | EXPORT_SYMBOL_GPL(regulator_get_mode); |
| 1863 | |
| 1864 | /** |
| 1865 | * regulator_set_optimum_mode - set regulator optimum operating mode |
| 1866 | * @regulator: regulator source |
| 1867 | * @uA_load: load current |
| 1868 | * |
| 1869 | * Notifies the regulator core of a new device load. This is then used by |
| 1870 | * DRMS (if enabled by constraints) to set the most efficient regulator |
| 1871 | * operating mode for the new regulator loading. |
| 1872 | * |
| 1873 | * Consumer devices notify their supply regulator of the maximum power |
| 1874 | * they will require (can be taken from device datasheet in the power |
| 1875 | * consumption tables) when they change operational status and hence power |
| 1876 | * state. Examples of operational state changes that can affect power |
| 1877 | * consumption are :- |
| 1878 | * |
| 1879 | * o Device is opened / closed. |
| 1880 | * o Device I/O is about to begin or has just finished. |
| 1881 | * o Device is idling in between work. |
| 1882 | * |
| 1883 | * This information is also exported via sysfs to userspace. |
| 1884 | * |
| 1885 | * DRMS will sum the total requested load on the regulator and change |
| 1886 | * to the most efficient operating mode if platform constraints allow. |
| 1887 | * |
| 1888 | * Returns the new regulator mode or error. |
| 1889 | */ |
| 1890 | int regulator_set_optimum_mode(struct regulator *regulator, int uA_load) |
| 1891 | { |
| 1892 | struct regulator_dev *rdev = regulator->rdev; |
| 1893 | struct regulator *consumer; |
| 1894 | int ret, output_uV, input_uV, total_uA_load = 0; |
| 1895 | unsigned int mode; |
| 1896 | |
| 1897 | mutex_lock(&rdev->mutex); |
| 1898 | |
| 1899 | regulator->uA_load = uA_load; |
| 1900 | ret = regulator_check_drms(rdev); |
| 1901 | if (ret < 0) |
| 1902 | goto out; |
| 1903 | ret = -EINVAL; |
| 1904 | |
| 1905 | /* sanity check */ |
| 1906 | if (!rdev->desc->ops->get_optimum_mode) |
| 1907 | goto out; |
| 1908 | |
| 1909 | /* get output voltage */ |
| 1910 | output_uV = rdev->desc->ops->get_voltage(rdev); |
| 1911 | if (output_uV <= 0) { |
| 1912 | printk(KERN_ERR "%s: invalid output voltage found for %s\n", |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 1913 | __func__, rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1914 | goto out; |
| 1915 | } |
| 1916 | |
| 1917 | /* get input voltage */ |
| 1918 | if (rdev->supply && rdev->supply->desc->ops->get_voltage) |
| 1919 | input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply); |
| 1920 | else |
| 1921 | input_uV = rdev->constraints->input_uV; |
| 1922 | if (input_uV <= 0) { |
| 1923 | printk(KERN_ERR "%s: invalid input voltage found for %s\n", |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 1924 | __func__, rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1925 | goto out; |
| 1926 | } |
| 1927 | |
| 1928 | /* calc total requested load for this regulator */ |
| 1929 | list_for_each_entry(consumer, &rdev->consumer_list, list) |
Stefan Roese | fa2984d | 2009-11-27 15:56:34 +0100 | [diff] [blame] | 1930 | total_uA_load += consumer->uA_load; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1931 | |
| 1932 | mode = rdev->desc->ops->get_optimum_mode(rdev, |
| 1933 | input_uV, output_uV, |
| 1934 | total_uA_load); |
David Brownell | e573520 | 2008-11-16 11:46:56 -0800 | [diff] [blame] | 1935 | ret = regulator_check_mode(rdev, mode); |
| 1936 | if (ret < 0) { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1937 | printk(KERN_ERR "%s: failed to get optimum mode for %s @" |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 1938 | " %d uA %d -> %d uV\n", __func__, rdev_get_name(rdev), |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1939 | total_uA_load, input_uV, output_uV); |
| 1940 | goto out; |
| 1941 | } |
| 1942 | |
| 1943 | ret = rdev->desc->ops->set_mode(rdev, mode); |
David Brownell | e573520 | 2008-11-16 11:46:56 -0800 | [diff] [blame] | 1944 | if (ret < 0) { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1945 | printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n", |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 1946 | __func__, mode, rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1947 | goto out; |
| 1948 | } |
| 1949 | ret = mode; |
| 1950 | out: |
| 1951 | mutex_unlock(&rdev->mutex); |
| 1952 | return ret; |
| 1953 | } |
| 1954 | EXPORT_SYMBOL_GPL(regulator_set_optimum_mode); |
| 1955 | |
| 1956 | /** |
| 1957 | * regulator_register_notifier - register regulator event notifier |
| 1958 | * @regulator: regulator source |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 1959 | * @nb: notifier block |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1960 | * |
| 1961 | * Register notifier block to receive regulator events. |
| 1962 | */ |
| 1963 | int regulator_register_notifier(struct regulator *regulator, |
| 1964 | struct notifier_block *nb) |
| 1965 | { |
| 1966 | return blocking_notifier_chain_register(®ulator->rdev->notifier, |
| 1967 | nb); |
| 1968 | } |
| 1969 | EXPORT_SYMBOL_GPL(regulator_register_notifier); |
| 1970 | |
| 1971 | /** |
| 1972 | * regulator_unregister_notifier - unregister regulator event notifier |
| 1973 | * @regulator: regulator source |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 1974 | * @nb: notifier block |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1975 | * |
| 1976 | * Unregister regulator event notifier block. |
| 1977 | */ |
| 1978 | int regulator_unregister_notifier(struct regulator *regulator, |
| 1979 | struct notifier_block *nb) |
| 1980 | { |
| 1981 | return blocking_notifier_chain_unregister(®ulator->rdev->notifier, |
| 1982 | nb); |
| 1983 | } |
| 1984 | EXPORT_SYMBOL_GPL(regulator_unregister_notifier); |
| 1985 | |
Jonathan Cameron | b136fb4 | 2009-01-19 18:20:58 +0000 | [diff] [blame] | 1986 | /* notify regulator consumers and downstream regulator consumers. |
| 1987 | * Note mutex must be held by caller. |
| 1988 | */ |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1989 | static void _notifier_call_chain(struct regulator_dev *rdev, |
| 1990 | unsigned long event, void *data) |
| 1991 | { |
| 1992 | struct regulator_dev *_rdev; |
| 1993 | |
| 1994 | /* call rdev chain first */ |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1995 | blocking_notifier_call_chain(&rdev->notifier, event, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1996 | |
| 1997 | /* now notify regulator we supply */ |
Jonathan Cameron | b136fb4 | 2009-01-19 18:20:58 +0000 | [diff] [blame] | 1998 | list_for_each_entry(_rdev, &rdev->supply_list, slist) { |
Stefan Roese | fa2984d | 2009-11-27 15:56:34 +0100 | [diff] [blame] | 1999 | mutex_lock(&_rdev->mutex); |
| 2000 | _notifier_call_chain(_rdev, event, data); |
| 2001 | mutex_unlock(&_rdev->mutex); |
Jonathan Cameron | b136fb4 | 2009-01-19 18:20:58 +0000 | [diff] [blame] | 2002 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | /** |
| 2006 | * regulator_bulk_get - get multiple regulator consumers |
| 2007 | * |
| 2008 | * @dev: Device to supply |
| 2009 | * @num_consumers: Number of consumers to register |
| 2010 | * @consumers: Configuration of consumers; clients are stored here. |
| 2011 | * |
| 2012 | * @return 0 on success, an errno on failure. |
| 2013 | * |
| 2014 | * This helper function allows drivers to get several regulator |
| 2015 | * consumers in one operation. If any of the regulators cannot be |
| 2016 | * acquired then any regulators that were allocated will be freed |
| 2017 | * before returning to the caller. |
| 2018 | */ |
| 2019 | int regulator_bulk_get(struct device *dev, int num_consumers, |
| 2020 | struct regulator_bulk_data *consumers) |
| 2021 | { |
| 2022 | int i; |
| 2023 | int ret; |
| 2024 | |
| 2025 | for (i = 0; i < num_consumers; i++) |
| 2026 | consumers[i].consumer = NULL; |
| 2027 | |
| 2028 | for (i = 0; i < num_consumers; i++) { |
| 2029 | consumers[i].consumer = regulator_get(dev, |
| 2030 | consumers[i].supply); |
| 2031 | if (IS_ERR(consumers[i].consumer)) { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2032 | ret = PTR_ERR(consumers[i].consumer); |
Mark Brown | 5b30762 | 2009-10-13 13:06:49 +0100 | [diff] [blame] | 2033 | dev_err(dev, "Failed to get supply '%s': %d\n", |
| 2034 | consumers[i].supply, ret); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2035 | consumers[i].consumer = NULL; |
| 2036 | goto err; |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | return 0; |
| 2041 | |
| 2042 | err: |
| 2043 | for (i = 0; i < num_consumers && consumers[i].consumer; i++) |
| 2044 | regulator_put(consumers[i].consumer); |
| 2045 | |
| 2046 | return ret; |
| 2047 | } |
| 2048 | EXPORT_SYMBOL_GPL(regulator_bulk_get); |
| 2049 | |
| 2050 | /** |
| 2051 | * regulator_bulk_enable - enable multiple regulator consumers |
| 2052 | * |
| 2053 | * @num_consumers: Number of consumers |
| 2054 | * @consumers: Consumer data; clients are stored here. |
| 2055 | * @return 0 on success, an errno on failure |
| 2056 | * |
| 2057 | * This convenience API allows consumers to enable multiple regulator |
| 2058 | * clients in a single API call. If any consumers cannot be enabled |
| 2059 | * then any others that were enabled will be disabled again prior to |
| 2060 | * return. |
| 2061 | */ |
| 2062 | int regulator_bulk_enable(int num_consumers, |
| 2063 | struct regulator_bulk_data *consumers) |
| 2064 | { |
| 2065 | int i; |
| 2066 | int ret; |
| 2067 | |
| 2068 | for (i = 0; i < num_consumers; i++) { |
| 2069 | ret = regulator_enable(consumers[i].consumer); |
| 2070 | if (ret != 0) |
| 2071 | goto err; |
| 2072 | } |
| 2073 | |
| 2074 | return 0; |
| 2075 | |
| 2076 | err: |
Mark Brown | 5b30762 | 2009-10-13 13:06:49 +0100 | [diff] [blame] | 2077 | printk(KERN_ERR "Failed to enable %s: %d\n", consumers[i].supply, ret); |
Lars-Peter Clausen | eb143ac | 2009-12-15 14:30:01 +0100 | [diff] [blame] | 2078 | for (--i; i >= 0; --i) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2079 | regulator_disable(consumers[i].consumer); |
| 2080 | |
| 2081 | return ret; |
| 2082 | } |
| 2083 | EXPORT_SYMBOL_GPL(regulator_bulk_enable); |
| 2084 | |
| 2085 | /** |
| 2086 | * regulator_bulk_disable - disable multiple regulator consumers |
| 2087 | * |
| 2088 | * @num_consumers: Number of consumers |
| 2089 | * @consumers: Consumer data; clients are stored here. |
| 2090 | * @return 0 on success, an errno on failure |
| 2091 | * |
| 2092 | * This convenience API allows consumers to disable multiple regulator |
| 2093 | * clients in a single API call. If any consumers cannot be enabled |
| 2094 | * then any others that were disabled will be disabled again prior to |
| 2095 | * return. |
| 2096 | */ |
| 2097 | int regulator_bulk_disable(int num_consumers, |
| 2098 | struct regulator_bulk_data *consumers) |
| 2099 | { |
| 2100 | int i; |
| 2101 | int ret; |
| 2102 | |
| 2103 | for (i = 0; i < num_consumers; i++) { |
| 2104 | ret = regulator_disable(consumers[i].consumer); |
| 2105 | if (ret != 0) |
| 2106 | goto err; |
| 2107 | } |
| 2108 | |
| 2109 | return 0; |
| 2110 | |
| 2111 | err: |
Mark Brown | 5b30762 | 2009-10-13 13:06:49 +0100 | [diff] [blame] | 2112 | printk(KERN_ERR "Failed to disable %s: %d\n", consumers[i].supply, |
| 2113 | ret); |
Lars-Peter Clausen | eb143ac | 2009-12-15 14:30:01 +0100 | [diff] [blame] | 2114 | for (--i; i >= 0; --i) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2115 | regulator_enable(consumers[i].consumer); |
| 2116 | |
| 2117 | return ret; |
| 2118 | } |
| 2119 | EXPORT_SYMBOL_GPL(regulator_bulk_disable); |
| 2120 | |
| 2121 | /** |
| 2122 | * regulator_bulk_free - free multiple regulator consumers |
| 2123 | * |
| 2124 | * @num_consumers: Number of consumers |
| 2125 | * @consumers: Consumer data; clients are stored here. |
| 2126 | * |
| 2127 | * This convenience API allows consumers to free multiple regulator |
| 2128 | * clients in a single API call. |
| 2129 | */ |
| 2130 | void regulator_bulk_free(int num_consumers, |
| 2131 | struct regulator_bulk_data *consumers) |
| 2132 | { |
| 2133 | int i; |
| 2134 | |
| 2135 | for (i = 0; i < num_consumers; i++) { |
| 2136 | regulator_put(consumers[i].consumer); |
| 2137 | consumers[i].consumer = NULL; |
| 2138 | } |
| 2139 | } |
| 2140 | EXPORT_SYMBOL_GPL(regulator_bulk_free); |
| 2141 | |
| 2142 | /** |
| 2143 | * regulator_notifier_call_chain - call regulator event notifier |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 2144 | * @rdev: regulator source |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2145 | * @event: notifier block |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 2146 | * @data: callback-specific data. |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2147 | * |
| 2148 | * Called by regulator drivers to notify clients a regulator event has |
| 2149 | * occurred. We also notify regulator clients downstream. |
Jonathan Cameron | b136fb4 | 2009-01-19 18:20:58 +0000 | [diff] [blame] | 2150 | * Note lock must be held by caller. |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2151 | */ |
| 2152 | int regulator_notifier_call_chain(struct regulator_dev *rdev, |
| 2153 | unsigned long event, void *data) |
| 2154 | { |
| 2155 | _notifier_call_chain(rdev, event, data); |
| 2156 | return NOTIFY_DONE; |
| 2157 | |
| 2158 | } |
| 2159 | EXPORT_SYMBOL_GPL(regulator_notifier_call_chain); |
| 2160 | |
Mark Brown | be72197 | 2009-08-04 20:09:52 +0200 | [diff] [blame] | 2161 | /** |
| 2162 | * regulator_mode_to_status - convert a regulator mode into a status |
| 2163 | * |
| 2164 | * @mode: Mode to convert |
| 2165 | * |
| 2166 | * Convert a regulator mode into a status. |
| 2167 | */ |
| 2168 | int regulator_mode_to_status(unsigned int mode) |
| 2169 | { |
| 2170 | switch (mode) { |
| 2171 | case REGULATOR_MODE_FAST: |
| 2172 | return REGULATOR_STATUS_FAST; |
| 2173 | case REGULATOR_MODE_NORMAL: |
| 2174 | return REGULATOR_STATUS_NORMAL; |
| 2175 | case REGULATOR_MODE_IDLE: |
| 2176 | return REGULATOR_STATUS_IDLE; |
| 2177 | case REGULATOR_STATUS_STANDBY: |
| 2178 | return REGULATOR_STATUS_STANDBY; |
| 2179 | default: |
| 2180 | return 0; |
| 2181 | } |
| 2182 | } |
| 2183 | EXPORT_SYMBOL_GPL(regulator_mode_to_status); |
| 2184 | |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 2185 | /* |
| 2186 | * To avoid cluttering sysfs (and memory) with useless state, only |
| 2187 | * create attributes that can be meaningfully displayed. |
| 2188 | */ |
| 2189 | static int add_regulator_attributes(struct regulator_dev *rdev) |
| 2190 | { |
| 2191 | struct device *dev = &rdev->dev; |
| 2192 | struct regulator_ops *ops = rdev->desc->ops; |
| 2193 | int status = 0; |
| 2194 | |
| 2195 | /* some attributes need specific methods to be displayed */ |
| 2196 | if (ops->get_voltage) { |
| 2197 | status = device_create_file(dev, &dev_attr_microvolts); |
| 2198 | if (status < 0) |
| 2199 | return status; |
| 2200 | } |
| 2201 | if (ops->get_current_limit) { |
| 2202 | status = device_create_file(dev, &dev_attr_microamps); |
| 2203 | if (status < 0) |
| 2204 | return status; |
| 2205 | } |
| 2206 | if (ops->get_mode) { |
| 2207 | status = device_create_file(dev, &dev_attr_opmode); |
| 2208 | if (status < 0) |
| 2209 | return status; |
| 2210 | } |
| 2211 | if (ops->is_enabled) { |
| 2212 | status = device_create_file(dev, &dev_attr_state); |
| 2213 | if (status < 0) |
| 2214 | return status; |
| 2215 | } |
David Brownell | 853116a | 2009-01-14 23:03:17 -0800 | [diff] [blame] | 2216 | if (ops->get_status) { |
| 2217 | status = device_create_file(dev, &dev_attr_status); |
| 2218 | if (status < 0) |
| 2219 | return status; |
| 2220 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 2221 | |
| 2222 | /* some attributes are type-specific */ |
| 2223 | if (rdev->desc->type == REGULATOR_CURRENT) { |
| 2224 | status = device_create_file(dev, &dev_attr_requested_microamps); |
| 2225 | if (status < 0) |
| 2226 | return status; |
| 2227 | } |
| 2228 | |
| 2229 | /* all the other attributes exist to support constraints; |
| 2230 | * don't show them if there are no constraints, or if the |
| 2231 | * relevant supporting methods are missing. |
| 2232 | */ |
| 2233 | if (!rdev->constraints) |
| 2234 | return status; |
| 2235 | |
| 2236 | /* constraints need specific supporting methods */ |
| 2237 | if (ops->set_voltage) { |
| 2238 | status = device_create_file(dev, &dev_attr_min_microvolts); |
| 2239 | if (status < 0) |
| 2240 | return status; |
| 2241 | status = device_create_file(dev, &dev_attr_max_microvolts); |
| 2242 | if (status < 0) |
| 2243 | return status; |
| 2244 | } |
| 2245 | if (ops->set_current_limit) { |
| 2246 | status = device_create_file(dev, &dev_attr_min_microamps); |
| 2247 | if (status < 0) |
| 2248 | return status; |
| 2249 | status = device_create_file(dev, &dev_attr_max_microamps); |
| 2250 | if (status < 0) |
| 2251 | return status; |
| 2252 | } |
| 2253 | |
| 2254 | /* suspend mode constraints need multiple supporting methods */ |
| 2255 | if (!(ops->set_suspend_enable && ops->set_suspend_disable)) |
| 2256 | return status; |
| 2257 | |
| 2258 | status = device_create_file(dev, &dev_attr_suspend_standby_state); |
| 2259 | if (status < 0) |
| 2260 | return status; |
| 2261 | status = device_create_file(dev, &dev_attr_suspend_mem_state); |
| 2262 | if (status < 0) |
| 2263 | return status; |
| 2264 | status = device_create_file(dev, &dev_attr_suspend_disk_state); |
| 2265 | if (status < 0) |
| 2266 | return status; |
| 2267 | |
| 2268 | if (ops->set_suspend_voltage) { |
| 2269 | status = device_create_file(dev, |
| 2270 | &dev_attr_suspend_standby_microvolts); |
| 2271 | if (status < 0) |
| 2272 | return status; |
| 2273 | status = device_create_file(dev, |
| 2274 | &dev_attr_suspend_mem_microvolts); |
| 2275 | if (status < 0) |
| 2276 | return status; |
| 2277 | status = device_create_file(dev, |
| 2278 | &dev_attr_suspend_disk_microvolts); |
| 2279 | if (status < 0) |
| 2280 | return status; |
| 2281 | } |
| 2282 | |
| 2283 | if (ops->set_suspend_mode) { |
| 2284 | status = device_create_file(dev, |
| 2285 | &dev_attr_suspend_standby_mode); |
| 2286 | if (status < 0) |
| 2287 | return status; |
| 2288 | status = device_create_file(dev, |
| 2289 | &dev_attr_suspend_mem_mode); |
| 2290 | if (status < 0) |
| 2291 | return status; |
| 2292 | status = device_create_file(dev, |
| 2293 | &dev_attr_suspend_disk_mode); |
| 2294 | if (status < 0) |
| 2295 | return status; |
| 2296 | } |
| 2297 | |
| 2298 | return status; |
| 2299 | } |
| 2300 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2301 | /** |
| 2302 | * regulator_register - register regulator |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 2303 | * @regulator_desc: regulator to register |
| 2304 | * @dev: struct device for the regulator |
Mark Brown | 0527100 | 2009-01-19 13:37:02 +0000 | [diff] [blame] | 2305 | * @init_data: platform provided init data, passed through by driver |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 2306 | * @driver_data: private regulator data |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2307 | * |
| 2308 | * Called by regulator drivers to register a regulator. |
| 2309 | * Returns 0 on success. |
| 2310 | */ |
| 2311 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, |
Mark Brown | 0527100 | 2009-01-19 13:37:02 +0000 | [diff] [blame] | 2312 | struct device *dev, struct regulator_init_data *init_data, |
| 2313 | void *driver_data) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2314 | { |
| 2315 | static atomic_t regulator_no = ATOMIC_INIT(0); |
| 2316 | struct regulator_dev *rdev; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2317 | int ret, i; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2318 | |
| 2319 | if (regulator_desc == NULL) |
| 2320 | return ERR_PTR(-EINVAL); |
| 2321 | |
| 2322 | if (regulator_desc->name == NULL || regulator_desc->ops == NULL) |
| 2323 | return ERR_PTR(-EINVAL); |
| 2324 | |
Diego Liziero | cd78dfc | 2009-04-14 03:04:47 +0200 | [diff] [blame] | 2325 | if (regulator_desc->type != REGULATOR_VOLTAGE && |
| 2326 | regulator_desc->type != REGULATOR_CURRENT) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2327 | return ERR_PTR(-EINVAL); |
| 2328 | |
Mark Brown | 46fabe1e | 2008-09-09 16:21:18 +0100 | [diff] [blame] | 2329 | if (!init_data) |
| 2330 | return ERR_PTR(-EINVAL); |
| 2331 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2332 | rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); |
| 2333 | if (rdev == NULL) |
| 2334 | return ERR_PTR(-ENOMEM); |
| 2335 | |
| 2336 | mutex_lock(®ulator_list_mutex); |
| 2337 | |
| 2338 | mutex_init(&rdev->mutex); |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2339 | rdev->reg_data = driver_data; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2340 | rdev->owner = regulator_desc->owner; |
| 2341 | rdev->desc = regulator_desc; |
| 2342 | INIT_LIST_HEAD(&rdev->consumer_list); |
| 2343 | INIT_LIST_HEAD(&rdev->supply_list); |
| 2344 | INIT_LIST_HEAD(&rdev->list); |
| 2345 | INIT_LIST_HEAD(&rdev->slist); |
| 2346 | BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); |
| 2347 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2348 | /* preform any regulator specific init */ |
| 2349 | if (init_data->regulator_init) { |
| 2350 | ret = init_data->regulator_init(rdev->reg_data); |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 2351 | if (ret < 0) |
| 2352 | goto clean; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2353 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2354 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2355 | /* register with sysfs */ |
| 2356 | rdev->dev.class = ®ulator_class; |
| 2357 | rdev->dev.parent = dev; |
Kay Sievers | 812460a | 2008-11-02 03:55:10 +0100 | [diff] [blame] | 2358 | dev_set_name(&rdev->dev, "regulator.%d", |
| 2359 | atomic_inc_return(®ulator_no) - 1); |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2360 | ret = device_register(&rdev->dev); |
Vasiliy Kulikov | ad7725c | 2010-09-19 16:55:01 +0400 | [diff] [blame] | 2361 | if (ret != 0) { |
| 2362 | put_device(&rdev->dev); |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 2363 | goto clean; |
Vasiliy Kulikov | ad7725c | 2010-09-19 16:55:01 +0400 | [diff] [blame] | 2364 | } |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2365 | |
| 2366 | dev_set_drvdata(&rdev->dev, rdev); |
| 2367 | |
Mike Rapoport | 74f544c | 2008-11-25 14:53:53 +0200 | [diff] [blame] | 2368 | /* set regulator constraints */ |
| 2369 | ret = set_machine_constraints(rdev, &init_data->constraints); |
| 2370 | if (ret < 0) |
| 2371 | goto scrub; |
| 2372 | |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 2373 | /* add attributes supported by this regulator */ |
| 2374 | ret = add_regulator_attributes(rdev); |
| 2375 | if (ret < 0) |
| 2376 | goto scrub; |
| 2377 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2378 | /* set supply regulator if it exists */ |
Mark Brown | 0178f3e | 2010-04-26 15:18:14 +0100 | [diff] [blame] | 2379 | if (init_data->supply_regulator && init_data->supply_regulator_dev) { |
| 2380 | dev_err(dev, |
| 2381 | "Supply regulator specified by both name and dev\n"); |
Axel Lin | 7727da2 | 2010-11-05 15:27:17 +0800 | [diff] [blame] | 2382 | ret = -EINVAL; |
Mark Brown | 0178f3e | 2010-04-26 15:18:14 +0100 | [diff] [blame] | 2383 | goto scrub; |
| 2384 | } |
| 2385 | |
| 2386 | if (init_data->supply_regulator) { |
| 2387 | struct regulator_dev *r; |
| 2388 | int found = 0; |
| 2389 | |
| 2390 | list_for_each_entry(r, ®ulator_list, list) { |
| 2391 | if (strcmp(rdev_get_name(r), |
| 2392 | init_data->supply_regulator) == 0) { |
| 2393 | found = 1; |
| 2394 | break; |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | if (!found) { |
| 2399 | dev_err(dev, "Failed to find supply %s\n", |
| 2400 | init_data->supply_regulator); |
Axel Lin | 7727da2 | 2010-11-05 15:27:17 +0800 | [diff] [blame] | 2401 | ret = -ENODEV; |
Mark Brown | 0178f3e | 2010-04-26 15:18:14 +0100 | [diff] [blame] | 2402 | goto scrub; |
| 2403 | } |
| 2404 | |
| 2405 | ret = set_supply(rdev, r); |
| 2406 | if (ret < 0) |
| 2407 | goto scrub; |
| 2408 | } |
| 2409 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2410 | if (init_data->supply_regulator_dev) { |
Mark Brown | 0178f3e | 2010-04-26 15:18:14 +0100 | [diff] [blame] | 2411 | dev_warn(dev, "Uses supply_regulator_dev instead of regulator_supply\n"); |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2412 | ret = set_supply(rdev, |
| 2413 | dev_get_drvdata(init_data->supply_regulator_dev)); |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 2414 | if (ret < 0) |
| 2415 | goto scrub; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | /* add consumers devices */ |
| 2419 | for (i = 0; i < init_data->num_consumer_supplies; i++) { |
| 2420 | ret = set_consumer_device_supply(rdev, |
| 2421 | init_data->consumer_supplies[i].dev, |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 2422 | init_data->consumer_supplies[i].dev_name, |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2423 | init_data->consumer_supplies[i].supply); |
Jani Nikula | d4033b5 | 2010-04-29 10:55:11 +0300 | [diff] [blame] | 2424 | if (ret < 0) |
| 2425 | goto unset_supplies; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | list_add(&rdev->list, ®ulator_list); |
| 2429 | out: |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2430 | mutex_unlock(®ulator_list_mutex); |
| 2431 | return rdev; |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 2432 | |
Jani Nikula | d4033b5 | 2010-04-29 10:55:11 +0300 | [diff] [blame] | 2433 | unset_supplies: |
| 2434 | unset_regulator_supplies(rdev); |
| 2435 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 2436 | scrub: |
| 2437 | device_unregister(&rdev->dev); |
Paul Walmsley | 53032da | 2009-04-25 05:28:36 -0600 | [diff] [blame] | 2438 | /* device core frees rdev */ |
| 2439 | rdev = ERR_PTR(ret); |
| 2440 | goto out; |
| 2441 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 2442 | clean: |
| 2443 | kfree(rdev); |
| 2444 | rdev = ERR_PTR(ret); |
| 2445 | goto out; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2446 | } |
| 2447 | EXPORT_SYMBOL_GPL(regulator_register); |
| 2448 | |
| 2449 | /** |
| 2450 | * regulator_unregister - unregister regulator |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 2451 | * @rdev: regulator to unregister |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2452 | * |
| 2453 | * Called by regulator drivers to unregister a regulator. |
| 2454 | */ |
| 2455 | void regulator_unregister(struct regulator_dev *rdev) |
| 2456 | { |
| 2457 | if (rdev == NULL) |
| 2458 | return; |
| 2459 | |
| 2460 | mutex_lock(®ulator_list_mutex); |
Mark Brown | 6bf87d1 | 2009-07-21 16:00:25 +0100 | [diff] [blame] | 2461 | WARN_ON(rdev->open_count); |
Mike Rapoport | 0f1d747 | 2009-01-22 16:00:29 +0200 | [diff] [blame] | 2462 | unset_regulator_supplies(rdev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2463 | list_del(&rdev->list); |
| 2464 | if (rdev->supply) |
| 2465 | sysfs_remove_link(&rdev->dev.kobj, "supply"); |
| 2466 | device_unregister(&rdev->dev); |
| 2467 | mutex_unlock(®ulator_list_mutex); |
| 2468 | } |
| 2469 | EXPORT_SYMBOL_GPL(regulator_unregister); |
| 2470 | |
| 2471 | /** |
Mark Brown | cf7bbcd | 2008-12-31 12:52:43 +0000 | [diff] [blame] | 2472 | * regulator_suspend_prepare - prepare regulators for system wide suspend |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2473 | * @state: system suspend state |
| 2474 | * |
| 2475 | * Configure each regulator with it's suspend operating parameters for state. |
| 2476 | * This will usually be called by machine suspend code prior to supending. |
| 2477 | */ |
| 2478 | int regulator_suspend_prepare(suspend_state_t state) |
| 2479 | { |
| 2480 | struct regulator_dev *rdev; |
| 2481 | int ret = 0; |
| 2482 | |
| 2483 | /* ON is handled by regulator active state */ |
| 2484 | if (state == PM_SUSPEND_ON) |
| 2485 | return -EINVAL; |
| 2486 | |
| 2487 | mutex_lock(®ulator_list_mutex); |
| 2488 | list_for_each_entry(rdev, ®ulator_list, list) { |
| 2489 | |
| 2490 | mutex_lock(&rdev->mutex); |
| 2491 | ret = suspend_prepare(rdev, state); |
| 2492 | mutex_unlock(&rdev->mutex); |
| 2493 | |
| 2494 | if (ret < 0) { |
| 2495 | printk(KERN_ERR "%s: failed to prepare %s\n", |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 2496 | __func__, rdev_get_name(rdev)); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2497 | goto out; |
| 2498 | } |
| 2499 | } |
| 2500 | out: |
| 2501 | mutex_unlock(®ulator_list_mutex); |
| 2502 | return ret; |
| 2503 | } |
| 2504 | EXPORT_SYMBOL_GPL(regulator_suspend_prepare); |
| 2505 | |
| 2506 | /** |
Mark Brown | ca72556 | 2009-03-16 19:36:34 +0000 | [diff] [blame] | 2507 | * regulator_has_full_constraints - the system has fully specified constraints |
| 2508 | * |
| 2509 | * Calling this function will cause the regulator API to disable all |
| 2510 | * regulators which have a zero use count and don't have an always_on |
| 2511 | * constraint in a late_initcall. |
| 2512 | * |
| 2513 | * The intention is that this will become the default behaviour in a |
| 2514 | * future kernel release so users are encouraged to use this facility |
| 2515 | * now. |
| 2516 | */ |
| 2517 | void regulator_has_full_constraints(void) |
| 2518 | { |
| 2519 | has_full_constraints = 1; |
| 2520 | } |
| 2521 | EXPORT_SYMBOL_GPL(regulator_has_full_constraints); |
| 2522 | |
| 2523 | /** |
Mark Brown | 688fe99 | 2010-10-05 19:18:32 -0700 | [diff] [blame] | 2524 | * regulator_use_dummy_regulator - Provide a dummy regulator when none is found |
| 2525 | * |
| 2526 | * Calling this function will cause the regulator API to provide a |
| 2527 | * dummy regulator to consumers if no physical regulator is found, |
| 2528 | * allowing most consumers to proceed as though a regulator were |
| 2529 | * configured. This allows systems such as those with software |
| 2530 | * controllable regulators for the CPU core only to be brought up more |
| 2531 | * readily. |
| 2532 | */ |
| 2533 | void regulator_use_dummy_regulator(void) |
| 2534 | { |
| 2535 | board_wants_dummy_regulator = true; |
| 2536 | } |
| 2537 | EXPORT_SYMBOL_GPL(regulator_use_dummy_regulator); |
| 2538 | |
| 2539 | /** |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2540 | * rdev_get_drvdata - get rdev regulator driver data |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 2541 | * @rdev: regulator |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2542 | * |
| 2543 | * Get rdev regulator driver private data. This call can be used in the |
| 2544 | * regulator driver context. |
| 2545 | */ |
| 2546 | void *rdev_get_drvdata(struct regulator_dev *rdev) |
| 2547 | { |
| 2548 | return rdev->reg_data; |
| 2549 | } |
| 2550 | EXPORT_SYMBOL_GPL(rdev_get_drvdata); |
| 2551 | |
| 2552 | /** |
| 2553 | * regulator_get_drvdata - get regulator driver data |
| 2554 | * @regulator: regulator |
| 2555 | * |
| 2556 | * Get regulator driver private data. This call can be used in the consumer |
| 2557 | * driver context when non API regulator specific functions need to be called. |
| 2558 | */ |
| 2559 | void *regulator_get_drvdata(struct regulator *regulator) |
| 2560 | { |
| 2561 | return regulator->rdev->reg_data; |
| 2562 | } |
| 2563 | EXPORT_SYMBOL_GPL(regulator_get_drvdata); |
| 2564 | |
| 2565 | /** |
| 2566 | * regulator_set_drvdata - set regulator driver data |
| 2567 | * @regulator: regulator |
| 2568 | * @data: data |
| 2569 | */ |
| 2570 | void regulator_set_drvdata(struct regulator *regulator, void *data) |
| 2571 | { |
| 2572 | regulator->rdev->reg_data = data; |
| 2573 | } |
| 2574 | EXPORT_SYMBOL_GPL(regulator_set_drvdata); |
| 2575 | |
| 2576 | /** |
| 2577 | * regulator_get_id - get regulator ID |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 2578 | * @rdev: regulator |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2579 | */ |
| 2580 | int rdev_get_id(struct regulator_dev *rdev) |
| 2581 | { |
| 2582 | return rdev->desc->id; |
| 2583 | } |
| 2584 | EXPORT_SYMBOL_GPL(rdev_get_id); |
| 2585 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 2586 | struct device *rdev_get_dev(struct regulator_dev *rdev) |
| 2587 | { |
| 2588 | return &rdev->dev; |
| 2589 | } |
| 2590 | EXPORT_SYMBOL_GPL(rdev_get_dev); |
| 2591 | |
| 2592 | void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data) |
| 2593 | { |
| 2594 | return reg_init_data->driver_data; |
| 2595 | } |
| 2596 | EXPORT_SYMBOL_GPL(regulator_get_init_drvdata); |
| 2597 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2598 | static int __init regulator_init(void) |
| 2599 | { |
Mark Brown | 34abbd6 | 2010-02-12 10:18:08 +0000 | [diff] [blame] | 2600 | int ret; |
| 2601 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2602 | printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION); |
Mark Brown | 34abbd6 | 2010-02-12 10:18:08 +0000 | [diff] [blame] | 2603 | |
| 2604 | ret = class_register(®ulator_class); |
| 2605 | |
| 2606 | regulator_dummy_init(); |
| 2607 | |
| 2608 | return ret; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | /* init early to allow our consumers to complete system booting */ |
| 2612 | core_initcall(regulator_init); |
Mark Brown | ca72556 | 2009-03-16 19:36:34 +0000 | [diff] [blame] | 2613 | |
| 2614 | static int __init regulator_init_complete(void) |
| 2615 | { |
| 2616 | struct regulator_dev *rdev; |
| 2617 | struct regulator_ops *ops; |
| 2618 | struct regulation_constraints *c; |
| 2619 | int enabled, ret; |
| 2620 | const char *name; |
| 2621 | |
| 2622 | mutex_lock(®ulator_list_mutex); |
| 2623 | |
| 2624 | /* If we have a full configuration then disable any regulators |
| 2625 | * which are not in use or always_on. This will become the |
| 2626 | * default behaviour in the future. |
| 2627 | */ |
| 2628 | list_for_each_entry(rdev, ®ulator_list, list) { |
| 2629 | ops = rdev->desc->ops; |
| 2630 | c = rdev->constraints; |
| 2631 | |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 2632 | name = rdev_get_name(rdev); |
Mark Brown | ca72556 | 2009-03-16 19:36:34 +0000 | [diff] [blame] | 2633 | |
Mark Brown | f25e0b4 | 2009-08-03 18:49:55 +0100 | [diff] [blame] | 2634 | if (!ops->disable || (c && c->always_on)) |
Mark Brown | ca72556 | 2009-03-16 19:36:34 +0000 | [diff] [blame] | 2635 | continue; |
| 2636 | |
| 2637 | mutex_lock(&rdev->mutex); |
| 2638 | |
| 2639 | if (rdev->use_count) |
| 2640 | goto unlock; |
| 2641 | |
| 2642 | /* If we can't read the status assume it's on. */ |
| 2643 | if (ops->is_enabled) |
| 2644 | enabled = ops->is_enabled(rdev); |
| 2645 | else |
| 2646 | enabled = 1; |
| 2647 | |
| 2648 | if (!enabled) |
| 2649 | goto unlock; |
| 2650 | |
| 2651 | if (has_full_constraints) { |
| 2652 | /* We log since this may kill the system if it |
| 2653 | * goes wrong. */ |
| 2654 | printk(KERN_INFO "%s: disabling %s\n", |
| 2655 | __func__, name); |
| 2656 | ret = ops->disable(rdev); |
| 2657 | if (ret != 0) { |
| 2658 | printk(KERN_ERR |
| 2659 | "%s: couldn't disable %s: %d\n", |
| 2660 | __func__, name, ret); |
| 2661 | } |
| 2662 | } else { |
| 2663 | /* The intention is that in future we will |
| 2664 | * assume that full constraints are provided |
| 2665 | * so warn even if we aren't going to do |
| 2666 | * anything here. |
| 2667 | */ |
| 2668 | printk(KERN_WARNING |
| 2669 | "%s: incomplete constraints, leaving %s on\n", |
| 2670 | __func__, name); |
| 2671 | } |
| 2672 | |
| 2673 | unlock: |
| 2674 | mutex_unlock(&rdev->mutex); |
| 2675 | } |
| 2676 | |
| 2677 | mutex_unlock(®ulator_list_mutex); |
| 2678 | |
| 2679 | return 0; |
| 2680 | } |
| 2681 | late_initcall(regulator_init_complete); |