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> |
Mark Brown | 1130e5b | 2010-12-21 23:49:31 +0000 | [diff] [blame] | 18 | #include <linux/debugfs.h> |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 19 | #include <linux/device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Mark Brown | f21e0e8 | 2011-05-24 08:12:40 +0800 | [diff] [blame] | 21 | #include <linux/async.h> |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 22 | #include <linux/err.h> |
| 23 | #include <linux/mutex.h> |
| 24 | #include <linux/suspend.h> |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 25 | #include <linux/delay.h> |
Mark Brown | 65f7350 | 2012-06-27 14:14:38 +0100 | [diff] [blame] | 26 | #include <linux/gpio.h> |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 27 | #include <linux/of.h> |
Mark Brown | 65b19ce | 2012-04-15 11:16:05 +0100 | [diff] [blame] | 28 | #include <linux/regmap.h> |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 29 | #include <linux/regulator/of_regulator.h> |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 30 | #include <linux/regulator/consumer.h> |
| 31 | #include <linux/regulator/driver.h> |
| 32 | #include <linux/regulator/machine.h> |
Paul Gortmaker | 65602c3 | 2011-07-17 16:28:23 -0400 | [diff] [blame] | 33 | #include <linux/module.h> |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 34 | |
Mark Brown | 02fa3ec | 2010-11-10 14:38:30 +0000 | [diff] [blame] | 35 | #define CREATE_TRACE_POINTS |
| 36 | #include <trace/events/regulator.h> |
| 37 | |
Mark Brown | 34abbd6 | 2010-02-12 10:18:08 +0000 | [diff] [blame] | 38 | #include "dummy.h" |
| 39 | |
Mark Brown | 7d51a0d | 2011-06-09 16:06:37 +0100 | [diff] [blame] | 40 | #define rdev_crit(rdev, fmt, ...) \ |
| 41 | pr_crit("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 42 | #define rdev_err(rdev, fmt, ...) \ |
| 43 | pr_err("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) |
| 44 | #define rdev_warn(rdev, fmt, ...) \ |
| 45 | pr_warn("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) |
| 46 | #define rdev_info(rdev, fmt, ...) \ |
| 47 | pr_info("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) |
| 48 | #define rdev_dbg(rdev, fmt, ...) \ |
| 49 | pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) |
| 50 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 51 | static DEFINE_MUTEX(regulator_list_mutex); |
| 52 | static LIST_HEAD(regulator_list); |
| 53 | static LIST_HEAD(regulator_map_list); |
Kim, Milo | f19b00d | 2013-02-18 06:50:39 +0000 | [diff] [blame] | 54 | static LIST_HEAD(regulator_ena_gpio_list); |
Mark Brown | 21cf891 | 2010-12-21 23:30:07 +0000 | [diff] [blame] | 55 | static bool has_full_constraints; |
Mark Brown | 688fe99 | 2010-10-05 19:18:32 -0700 | [diff] [blame] | 56 | static bool board_wants_dummy_regulator; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 57 | |
Mark Brown | 1130e5b | 2010-12-21 23:49:31 +0000 | [diff] [blame] | 58 | static struct dentry *debugfs_root; |
Mark Brown | 1130e5b | 2010-12-21 23:49:31 +0000 | [diff] [blame] | 59 | |
Mark Brown | 8dc5390 | 2008-12-31 12:52:40 +0000 | [diff] [blame] | 60 | /* |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 61 | * struct regulator_map |
| 62 | * |
| 63 | * Used to provide symbolic supply names to devices. |
| 64 | */ |
| 65 | struct regulator_map { |
| 66 | struct list_head list; |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 67 | const char *dev_name; /* The dev_name() for the consumer */ |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 68 | const char *supply; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 69 | struct regulator_dev *regulator; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 70 | }; |
| 71 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 72 | /* |
Kim, Milo | f19b00d | 2013-02-18 06:50:39 +0000 | [diff] [blame] | 73 | * struct regulator_enable_gpio |
| 74 | * |
| 75 | * Management for shared enable GPIO pin |
| 76 | */ |
| 77 | struct regulator_enable_gpio { |
| 78 | struct list_head list; |
| 79 | int gpio; |
| 80 | u32 enable_count; /* a number of enabled shared GPIO */ |
| 81 | u32 request_count; /* a number of requested shared GPIO */ |
| 82 | unsigned int ena_gpio_invert:1; |
| 83 | }; |
| 84 | |
| 85 | /* |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 86 | * struct regulator |
| 87 | * |
| 88 | * One for each consumer device. |
| 89 | */ |
| 90 | struct regulator { |
| 91 | struct device *dev; |
| 92 | struct list_head list; |
Mark Brown | 6492bc1 | 2012-04-19 13:19:07 +0100 | [diff] [blame] | 93 | unsigned int always_on:1; |
Mark Brown | f59c8f9 | 2012-08-31 10:36:37 -0700 | [diff] [blame] | 94 | unsigned int bypass:1; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 95 | int uA_load; |
| 96 | int min_uV; |
| 97 | int max_uV; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 98 | char *supply_name; |
| 99 | struct device_attribute dev_attr; |
| 100 | struct regulator_dev *rdev; |
Mark Brown | 5de7051 | 2011-06-19 13:33:16 +0100 | [diff] [blame] | 101 | struct dentry *debugfs; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | static int _regulator_is_enabled(struct regulator_dev *rdev); |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 105 | static int _regulator_disable(struct regulator_dev *rdev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 106 | static int _regulator_get_voltage(struct regulator_dev *rdev); |
| 107 | static int _regulator_get_current_limit(struct regulator_dev *rdev); |
| 108 | static unsigned int _regulator_get_mode(struct regulator_dev *rdev); |
| 109 | static void _notifier_call_chain(struct regulator_dev *rdev, |
| 110 | unsigned long event, void *data); |
Mark Brown | 7579025 | 2010-12-12 14:25:50 +0000 | [diff] [blame] | 111 | static int _regulator_do_set_voltage(struct regulator_dev *rdev, |
| 112 | int min_uV, int max_uV); |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 113 | static struct regulator *create_regulator(struct regulator_dev *rdev, |
| 114 | struct device *dev, |
| 115 | const char *supply_name); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 116 | |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 117 | static const char *rdev_get_name(struct regulator_dev *rdev) |
| 118 | { |
| 119 | if (rdev->constraints && rdev->constraints->name) |
| 120 | return rdev->constraints->name; |
| 121 | else if (rdev->desc->name) |
| 122 | return rdev->desc->name; |
| 123 | else |
| 124 | return ""; |
| 125 | } |
| 126 | |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 127 | /** |
| 128 | * of_get_regulator - get a regulator device node based on supply name |
| 129 | * @dev: Device pointer for the consumer (of regulator) device |
| 130 | * @supply: regulator supply name |
| 131 | * |
| 132 | * Extract the regulator device node corresponding to the supply name. |
Maxime Ripard | 167d41d | 2013-03-23 11:00:41 +0100 | [diff] [blame] | 133 | * returns the device node corresponding to the regulator if found, else |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 134 | * returns NULL. |
| 135 | */ |
| 136 | static struct device_node *of_get_regulator(struct device *dev, const char *supply) |
| 137 | { |
| 138 | struct device_node *regnode = NULL; |
| 139 | char prop_name[32]; /* 32 is max size of property name */ |
| 140 | |
| 141 | dev_dbg(dev, "Looking up %s-supply from device tree\n", supply); |
| 142 | |
| 143 | snprintf(prop_name, 32, "%s-supply", supply); |
| 144 | regnode = of_parse_phandle(dev->of_node, prop_name, 0); |
| 145 | |
| 146 | if (!regnode) { |
Rajendra Nayak | 16fbcc3 | 2012-03-16 15:50:21 +0530 | [diff] [blame] | 147 | dev_dbg(dev, "Looking up %s property in node %s failed", |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 148 | prop_name, dev->of_node->full_name); |
| 149 | return NULL; |
| 150 | } |
| 151 | return regnode; |
| 152 | } |
| 153 | |
Mark Brown | 6492bc1 | 2012-04-19 13:19:07 +0100 | [diff] [blame] | 154 | static int _regulator_can_change_status(struct regulator_dev *rdev) |
| 155 | { |
| 156 | if (!rdev->constraints) |
| 157 | return 0; |
| 158 | |
| 159 | if (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_STATUS) |
| 160 | return 1; |
| 161 | else |
| 162 | return 0; |
| 163 | } |
| 164 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 165 | /* Platform voltage constraint check */ |
| 166 | static int regulator_check_voltage(struct regulator_dev *rdev, |
| 167 | int *min_uV, int *max_uV) |
| 168 | { |
| 169 | BUG_ON(*min_uV > *max_uV); |
| 170 | |
| 171 | if (!rdev->constraints) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 172 | rdev_err(rdev, "no constraints\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 173 | return -ENODEV; |
| 174 | } |
| 175 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 176 | rdev_err(rdev, "operation not allowed\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 177 | return -EPERM; |
| 178 | } |
| 179 | |
| 180 | if (*max_uV > rdev->constraints->max_uV) |
| 181 | *max_uV = rdev->constraints->max_uV; |
| 182 | if (*min_uV < rdev->constraints->min_uV) |
| 183 | *min_uV = rdev->constraints->min_uV; |
| 184 | |
Mark Brown | 89f425e | 2011-07-12 11:20:37 +0900 | [diff] [blame] | 185 | if (*min_uV > *max_uV) { |
| 186 | rdev_err(rdev, "unsupportable voltage range: %d-%duV\n", |
Mark Brown | 54abd33 | 2011-07-21 15:07:37 +0100 | [diff] [blame] | 187 | *min_uV, *max_uV); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 188 | return -EINVAL; |
Mark Brown | 89f425e | 2011-07-12 11:20:37 +0900 | [diff] [blame] | 189 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
Thomas Petazzoni | 05fda3b1a | 2010-12-03 11:31:07 +0100 | [diff] [blame] | 194 | /* Make sure we select a voltage that suits the needs of all |
| 195 | * regulator consumers |
| 196 | */ |
| 197 | static int regulator_check_consumers(struct regulator_dev *rdev, |
| 198 | int *min_uV, int *max_uV) |
| 199 | { |
| 200 | struct regulator *regulator; |
| 201 | |
| 202 | list_for_each_entry(regulator, &rdev->consumer_list, list) { |
Mark Brown | 4aa922c | 2011-05-14 13:42:34 -0700 | [diff] [blame] | 203 | /* |
| 204 | * Assume consumers that didn't say anything are OK |
| 205 | * with anything in the constraint range. |
| 206 | */ |
| 207 | if (!regulator->min_uV && !regulator->max_uV) |
| 208 | continue; |
| 209 | |
Thomas Petazzoni | 05fda3b1a | 2010-12-03 11:31:07 +0100 | [diff] [blame] | 210 | if (*max_uV > regulator->max_uV) |
| 211 | *max_uV = regulator->max_uV; |
| 212 | if (*min_uV < regulator->min_uV) |
| 213 | *min_uV = regulator->min_uV; |
| 214 | } |
| 215 | |
Mark Brown | dd8004a | 2012-11-28 17:09:27 +0000 | [diff] [blame] | 216 | if (*min_uV > *max_uV) { |
Russ Dill | 9c7b4e8 | 2013-02-14 04:46:33 -0800 | [diff] [blame] | 217 | rdev_err(rdev, "Restricting voltage, %u-%uuV\n", |
| 218 | *min_uV, *max_uV); |
Thomas Petazzoni | 05fda3b1a | 2010-12-03 11:31:07 +0100 | [diff] [blame] | 219 | return -EINVAL; |
Mark Brown | dd8004a | 2012-11-28 17:09:27 +0000 | [diff] [blame] | 220 | } |
Thomas Petazzoni | 05fda3b1a | 2010-12-03 11:31:07 +0100 | [diff] [blame] | 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 225 | /* current constraint check */ |
| 226 | static int regulator_check_current_limit(struct regulator_dev *rdev, |
| 227 | int *min_uA, int *max_uA) |
| 228 | { |
| 229 | BUG_ON(*min_uA > *max_uA); |
| 230 | |
| 231 | if (!rdev->constraints) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 232 | rdev_err(rdev, "no constraints\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 233 | return -ENODEV; |
| 234 | } |
| 235 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 236 | rdev_err(rdev, "operation not allowed\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 237 | return -EPERM; |
| 238 | } |
| 239 | |
| 240 | if (*max_uA > rdev->constraints->max_uA) |
| 241 | *max_uA = rdev->constraints->max_uA; |
| 242 | if (*min_uA < rdev->constraints->min_uA) |
| 243 | *min_uA = rdev->constraints->min_uA; |
| 244 | |
Mark Brown | 89f425e | 2011-07-12 11:20:37 +0900 | [diff] [blame] | 245 | if (*min_uA > *max_uA) { |
| 246 | rdev_err(rdev, "unsupportable current range: %d-%duA\n", |
Mark Brown | 54abd33 | 2011-07-21 15:07:37 +0100 | [diff] [blame] | 247 | *min_uA, *max_uA); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 248 | return -EINVAL; |
Mark Brown | 89f425e | 2011-07-12 11:20:37 +0900 | [diff] [blame] | 249 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | /* operating mode constraint check */ |
Mark Brown | 2c60823 | 2011-03-30 06:29:12 +0900 | [diff] [blame] | 255 | static int regulator_mode_constrain(struct regulator_dev *rdev, int *mode) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 256 | { |
Mark Brown | 2c60823 | 2011-03-30 06:29:12 +0900 | [diff] [blame] | 257 | switch (*mode) { |
David Brownell | e573520 | 2008-11-16 11:46:56 -0800 | [diff] [blame] | 258 | case REGULATOR_MODE_FAST: |
| 259 | case REGULATOR_MODE_NORMAL: |
| 260 | case REGULATOR_MODE_IDLE: |
| 261 | case REGULATOR_MODE_STANDBY: |
| 262 | break; |
| 263 | default: |
Mark Brown | 89f425e | 2011-07-12 11:20:37 +0900 | [diff] [blame] | 264 | rdev_err(rdev, "invalid mode %x specified\n", *mode); |
David Brownell | e573520 | 2008-11-16 11:46:56 -0800 | [diff] [blame] | 265 | return -EINVAL; |
| 266 | } |
| 267 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 268 | if (!rdev->constraints) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 269 | rdev_err(rdev, "no constraints\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 270 | return -ENODEV; |
| 271 | } |
| 272 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 273 | rdev_err(rdev, "operation not allowed\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 274 | return -EPERM; |
| 275 | } |
Mark Brown | 2c60823 | 2011-03-30 06:29:12 +0900 | [diff] [blame] | 276 | |
| 277 | /* The modes are bitmasks, the most power hungry modes having |
| 278 | * the lowest values. If the requested mode isn't supported |
| 279 | * try higher modes. */ |
| 280 | while (*mode) { |
| 281 | if (rdev->constraints->valid_modes_mask & *mode) |
| 282 | return 0; |
| 283 | *mode /= 2; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 284 | } |
Mark Brown | 2c60823 | 2011-03-30 06:29:12 +0900 | [diff] [blame] | 285 | |
| 286 | return -EINVAL; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /* dynamic regulator mode switching constraint check */ |
| 290 | static int regulator_check_drms(struct regulator_dev *rdev) |
| 291 | { |
| 292 | if (!rdev->constraints) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 293 | rdev_err(rdev, "no constraints\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 294 | return -ENODEV; |
| 295 | } |
| 296 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 297 | rdev_err(rdev, "operation not allowed\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 298 | return -EPERM; |
| 299 | } |
| 300 | return 0; |
| 301 | } |
| 302 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 303 | static ssize_t regulator_uV_show(struct device *dev, |
| 304 | struct device_attribute *attr, char *buf) |
| 305 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 306 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 307 | ssize_t ret; |
| 308 | |
| 309 | mutex_lock(&rdev->mutex); |
| 310 | ret = sprintf(buf, "%d\n", _regulator_get_voltage(rdev)); |
| 311 | mutex_unlock(&rdev->mutex); |
| 312 | |
| 313 | return ret; |
| 314 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 315 | static DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 316 | |
| 317 | static ssize_t regulator_uA_show(struct device *dev, |
| 318 | struct device_attribute *attr, char *buf) |
| 319 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 320 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 321 | |
| 322 | return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); |
| 323 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 324 | static DEVICE_ATTR(microamps, 0444, regulator_uA_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 325 | |
Greg Kroah-Hartman | 587cea2 | 2013-07-24 15:05:21 -0700 | [diff] [blame] | 326 | static ssize_t name_show(struct device *dev, struct device_attribute *attr, |
| 327 | char *buf) |
Mark Brown | bc558a6 | 2008-10-10 15:33:20 +0100 | [diff] [blame] | 328 | { |
| 329 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Mark Brown | bc558a6 | 2008-10-10 15:33:20 +0100 | [diff] [blame] | 330 | |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 331 | return sprintf(buf, "%s\n", rdev_get_name(rdev)); |
Mark Brown | bc558a6 | 2008-10-10 15:33:20 +0100 | [diff] [blame] | 332 | } |
Greg Kroah-Hartman | 587cea2 | 2013-07-24 15:05:21 -0700 | [diff] [blame] | 333 | static DEVICE_ATTR_RO(name); |
Mark Brown | bc558a6 | 2008-10-10 15:33:20 +0100 | [diff] [blame] | 334 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 335 | static ssize_t regulator_print_opmode(char *buf, int mode) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 336 | { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 337 | switch (mode) { |
| 338 | case REGULATOR_MODE_FAST: |
| 339 | return sprintf(buf, "fast\n"); |
| 340 | case REGULATOR_MODE_NORMAL: |
| 341 | return sprintf(buf, "normal\n"); |
| 342 | case REGULATOR_MODE_IDLE: |
| 343 | return sprintf(buf, "idle\n"); |
| 344 | case REGULATOR_MODE_STANDBY: |
| 345 | return sprintf(buf, "standby\n"); |
| 346 | } |
| 347 | return sprintf(buf, "unknown\n"); |
| 348 | } |
| 349 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 350 | static ssize_t regulator_opmode_show(struct device *dev, |
| 351 | struct device_attribute *attr, char *buf) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 352 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 353 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 354 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 355 | return regulator_print_opmode(buf, _regulator_get_mode(rdev)); |
| 356 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 357 | static DEVICE_ATTR(opmode, 0444, regulator_opmode_show, NULL); |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 358 | |
| 359 | static ssize_t regulator_print_state(char *buf, int state) |
| 360 | { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 361 | if (state > 0) |
| 362 | return sprintf(buf, "enabled\n"); |
| 363 | else if (state == 0) |
| 364 | return sprintf(buf, "disabled\n"); |
| 365 | else |
| 366 | return sprintf(buf, "unknown\n"); |
| 367 | } |
| 368 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 369 | static ssize_t regulator_state_show(struct device *dev, |
| 370 | struct device_attribute *attr, char *buf) |
| 371 | { |
| 372 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Mark Brown | 9332546 | 2009-08-03 18:49:56 +0100 | [diff] [blame] | 373 | ssize_t ret; |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 374 | |
Mark Brown | 9332546 | 2009-08-03 18:49:56 +0100 | [diff] [blame] | 375 | mutex_lock(&rdev->mutex); |
| 376 | ret = regulator_print_state(buf, _regulator_is_enabled(rdev)); |
| 377 | mutex_unlock(&rdev->mutex); |
| 378 | |
| 379 | return ret; |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 380 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 381 | static DEVICE_ATTR(state, 0444, regulator_state_show, NULL); |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 382 | |
David Brownell | 853116a | 2009-01-14 23:03:17 -0800 | [diff] [blame] | 383 | static ssize_t regulator_status_show(struct device *dev, |
| 384 | struct device_attribute *attr, char *buf) |
| 385 | { |
| 386 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
| 387 | int status; |
| 388 | char *label; |
| 389 | |
| 390 | status = rdev->desc->ops->get_status(rdev); |
| 391 | if (status < 0) |
| 392 | return status; |
| 393 | |
| 394 | switch (status) { |
| 395 | case REGULATOR_STATUS_OFF: |
| 396 | label = "off"; |
| 397 | break; |
| 398 | case REGULATOR_STATUS_ON: |
| 399 | label = "on"; |
| 400 | break; |
| 401 | case REGULATOR_STATUS_ERROR: |
| 402 | label = "error"; |
| 403 | break; |
| 404 | case REGULATOR_STATUS_FAST: |
| 405 | label = "fast"; |
| 406 | break; |
| 407 | case REGULATOR_STATUS_NORMAL: |
| 408 | label = "normal"; |
| 409 | break; |
| 410 | case REGULATOR_STATUS_IDLE: |
| 411 | label = "idle"; |
| 412 | break; |
| 413 | case REGULATOR_STATUS_STANDBY: |
| 414 | label = "standby"; |
| 415 | break; |
Mark Brown | f59c8f9 | 2012-08-31 10:36:37 -0700 | [diff] [blame] | 416 | case REGULATOR_STATUS_BYPASS: |
| 417 | label = "bypass"; |
| 418 | break; |
Krystian Garbaciak | 1beaf76 | 2012-07-12 13:53:35 +0100 | [diff] [blame] | 419 | case REGULATOR_STATUS_UNDEFINED: |
| 420 | label = "undefined"; |
| 421 | break; |
David Brownell | 853116a | 2009-01-14 23:03:17 -0800 | [diff] [blame] | 422 | default: |
| 423 | return -ERANGE; |
| 424 | } |
| 425 | |
| 426 | return sprintf(buf, "%s\n", label); |
| 427 | } |
| 428 | static DEVICE_ATTR(status, 0444, regulator_status_show, NULL); |
| 429 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 430 | static ssize_t regulator_min_uA_show(struct device *dev, |
| 431 | struct device_attribute *attr, char *buf) |
| 432 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 433 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 434 | |
| 435 | if (!rdev->constraints) |
| 436 | return sprintf(buf, "constraint not defined\n"); |
| 437 | |
| 438 | return sprintf(buf, "%d\n", rdev->constraints->min_uA); |
| 439 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 440 | static DEVICE_ATTR(min_microamps, 0444, regulator_min_uA_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 441 | |
| 442 | static ssize_t regulator_max_uA_show(struct device *dev, |
| 443 | struct device_attribute *attr, char *buf) |
| 444 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 445 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 446 | |
| 447 | if (!rdev->constraints) |
| 448 | return sprintf(buf, "constraint not defined\n"); |
| 449 | |
| 450 | return sprintf(buf, "%d\n", rdev->constraints->max_uA); |
| 451 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 452 | static DEVICE_ATTR(max_microamps, 0444, regulator_max_uA_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 453 | |
| 454 | static ssize_t regulator_min_uV_show(struct device *dev, |
| 455 | struct device_attribute *attr, char *buf) |
| 456 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 457 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 458 | |
| 459 | if (!rdev->constraints) |
| 460 | return sprintf(buf, "constraint not defined\n"); |
| 461 | |
| 462 | return sprintf(buf, "%d\n", rdev->constraints->min_uV); |
| 463 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 464 | static DEVICE_ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 465 | |
| 466 | static ssize_t regulator_max_uV_show(struct device *dev, |
| 467 | struct device_attribute *attr, char *buf) |
| 468 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 469 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 470 | |
| 471 | if (!rdev->constraints) |
| 472 | return sprintf(buf, "constraint not defined\n"); |
| 473 | |
| 474 | return sprintf(buf, "%d\n", rdev->constraints->max_uV); |
| 475 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 476 | static DEVICE_ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 477 | |
| 478 | static ssize_t regulator_total_uA_show(struct device *dev, |
| 479 | struct device_attribute *attr, char *buf) |
| 480 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 481 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 482 | struct regulator *regulator; |
| 483 | int uA = 0; |
| 484 | |
| 485 | mutex_lock(&rdev->mutex); |
| 486 | list_for_each_entry(regulator, &rdev->consumer_list, list) |
Stefan Roese | fa2984d | 2009-11-27 15:56:34 +0100 | [diff] [blame] | 487 | uA += regulator->uA_load; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 488 | mutex_unlock(&rdev->mutex); |
| 489 | return sprintf(buf, "%d\n", uA); |
| 490 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 491 | static DEVICE_ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 492 | |
Greg Kroah-Hartman | 587cea2 | 2013-07-24 15:05:21 -0700 | [diff] [blame] | 493 | static ssize_t num_users_show(struct device *dev, struct device_attribute *attr, |
| 494 | char *buf) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 495 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 496 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 497 | return sprintf(buf, "%d\n", rdev->use_count); |
| 498 | } |
Greg Kroah-Hartman | 587cea2 | 2013-07-24 15:05:21 -0700 | [diff] [blame] | 499 | static DEVICE_ATTR_RO(num_users); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 500 | |
Greg Kroah-Hartman | 587cea2 | 2013-07-24 15:05:21 -0700 | [diff] [blame] | 501 | static ssize_t type_show(struct device *dev, struct device_attribute *attr, |
| 502 | char *buf) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 503 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 504 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 505 | |
| 506 | switch (rdev->desc->type) { |
| 507 | case REGULATOR_VOLTAGE: |
| 508 | return sprintf(buf, "voltage\n"); |
| 509 | case REGULATOR_CURRENT: |
| 510 | return sprintf(buf, "current\n"); |
| 511 | } |
| 512 | return sprintf(buf, "unknown\n"); |
| 513 | } |
Greg Kroah-Hartman | 587cea2 | 2013-07-24 15:05:21 -0700 | [diff] [blame] | 514 | static DEVICE_ATTR_RO(type); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 515 | |
| 516 | static ssize_t regulator_suspend_mem_uV_show(struct device *dev, |
| 517 | struct device_attribute *attr, char *buf) |
| 518 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 519 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 520 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 521 | return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV); |
| 522 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 523 | static DEVICE_ATTR(suspend_mem_microvolts, 0444, |
| 524 | regulator_suspend_mem_uV_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 525 | |
| 526 | static ssize_t regulator_suspend_disk_uV_show(struct device *dev, |
| 527 | struct device_attribute *attr, char *buf) |
| 528 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 529 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 530 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 531 | return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV); |
| 532 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 533 | static DEVICE_ATTR(suspend_disk_microvolts, 0444, |
| 534 | regulator_suspend_disk_uV_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 535 | |
| 536 | static ssize_t regulator_suspend_standby_uV_show(struct device *dev, |
| 537 | struct device_attribute *attr, char *buf) |
| 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 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 541 | return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); |
| 542 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 543 | static DEVICE_ATTR(suspend_standby_microvolts, 0444, |
| 544 | regulator_suspend_standby_uV_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 545 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 546 | static ssize_t regulator_suspend_mem_mode_show(struct device *dev, |
| 547 | struct device_attribute *attr, char *buf) |
| 548 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 549 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 550 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 551 | return regulator_print_opmode(buf, |
| 552 | rdev->constraints->state_mem.mode); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 553 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 554 | static DEVICE_ATTR(suspend_mem_mode, 0444, |
| 555 | regulator_suspend_mem_mode_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 556 | |
| 557 | static ssize_t regulator_suspend_disk_mode_show(struct device *dev, |
| 558 | struct device_attribute *attr, char *buf) |
| 559 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 560 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 561 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 562 | return regulator_print_opmode(buf, |
| 563 | rdev->constraints->state_disk.mode); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 564 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 565 | static DEVICE_ATTR(suspend_disk_mode, 0444, |
| 566 | regulator_suspend_disk_mode_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 567 | |
| 568 | static ssize_t regulator_suspend_standby_mode_show(struct device *dev, |
| 569 | struct device_attribute *attr, char *buf) |
| 570 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 571 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 572 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 573 | return regulator_print_opmode(buf, |
| 574 | rdev->constraints->state_standby.mode); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 575 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 576 | static DEVICE_ATTR(suspend_standby_mode, 0444, |
| 577 | regulator_suspend_standby_mode_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 578 | |
| 579 | static ssize_t regulator_suspend_mem_state_show(struct device *dev, |
| 580 | struct device_attribute *attr, char *buf) |
| 581 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 582 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 583 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 584 | return regulator_print_state(buf, |
| 585 | rdev->constraints->state_mem.enabled); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 586 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 587 | static DEVICE_ATTR(suspend_mem_state, 0444, |
| 588 | regulator_suspend_mem_state_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 589 | |
| 590 | static ssize_t regulator_suspend_disk_state_show(struct device *dev, |
| 591 | struct device_attribute *attr, char *buf) |
| 592 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 593 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 594 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 595 | return regulator_print_state(buf, |
| 596 | rdev->constraints->state_disk.enabled); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 597 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 598 | static DEVICE_ATTR(suspend_disk_state, 0444, |
| 599 | regulator_suspend_disk_state_show, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 600 | |
| 601 | static ssize_t regulator_suspend_standby_state_show(struct device *dev, |
| 602 | struct device_attribute *attr, char *buf) |
| 603 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 604 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 605 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 606 | return regulator_print_state(buf, |
| 607 | rdev->constraints->state_standby.enabled); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 608 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 609 | static DEVICE_ATTR(suspend_standby_state, 0444, |
| 610 | regulator_suspend_standby_state_show, NULL); |
Mark Brown | bc558a6 | 2008-10-10 15:33:20 +0100 | [diff] [blame] | 611 | |
Mark Brown | f59c8f9 | 2012-08-31 10:36:37 -0700 | [diff] [blame] | 612 | static ssize_t regulator_bypass_show(struct device *dev, |
| 613 | struct device_attribute *attr, char *buf) |
| 614 | { |
| 615 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
| 616 | const char *report; |
| 617 | bool bypass; |
| 618 | int ret; |
| 619 | |
| 620 | ret = rdev->desc->ops->get_bypass(rdev, &bypass); |
| 621 | |
| 622 | if (ret != 0) |
| 623 | report = "unknown"; |
| 624 | else if (bypass) |
| 625 | report = "enabled"; |
| 626 | else |
| 627 | report = "disabled"; |
| 628 | |
| 629 | return sprintf(buf, "%s\n", report); |
| 630 | } |
| 631 | static DEVICE_ATTR(bypass, 0444, |
| 632 | regulator_bypass_show, NULL); |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 633 | |
| 634 | /* |
| 635 | * These are the only attributes are present for all regulators. |
| 636 | * Other attributes are a function of regulator functionality. |
| 637 | */ |
Greg Kroah-Hartman | 587cea2 | 2013-07-24 15:05:21 -0700 | [diff] [blame] | 638 | static struct attribute *regulator_dev_attrs[] = { |
| 639 | &dev_attr_name.attr, |
| 640 | &dev_attr_num_users.attr, |
| 641 | &dev_attr_type.attr, |
| 642 | NULL, |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 643 | }; |
Greg Kroah-Hartman | 587cea2 | 2013-07-24 15:05:21 -0700 | [diff] [blame] | 644 | ATTRIBUTE_GROUPS(regulator_dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 645 | |
| 646 | static void regulator_dev_release(struct device *dev) |
| 647 | { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 648 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 649 | kfree(rdev); |
| 650 | } |
| 651 | |
| 652 | static struct class regulator_class = { |
| 653 | .name = "regulator", |
| 654 | .dev_release = regulator_dev_release, |
Greg Kroah-Hartman | 587cea2 | 2013-07-24 15:05:21 -0700 | [diff] [blame] | 655 | .dev_groups = regulator_dev_groups, |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 656 | }; |
| 657 | |
| 658 | /* Calculate the new optimum regulator operating mode based on the new total |
| 659 | * consumer load. All locks held by caller */ |
| 660 | static void drms_uA_update(struct regulator_dev *rdev) |
| 661 | { |
| 662 | struct regulator *sibling; |
| 663 | int current_uA = 0, output_uV, input_uV, err; |
| 664 | unsigned int mode; |
| 665 | |
| 666 | err = regulator_check_drms(rdev); |
| 667 | if (err < 0 || !rdev->desc->ops->get_optimum_mode || |
Mark Brown | 476c2d8 | 2010-12-10 17:28:07 +0000 | [diff] [blame] | 668 | (!rdev->desc->ops->get_voltage && |
| 669 | !rdev->desc->ops->get_voltage_sel) || |
| 670 | !rdev->desc->ops->set_mode) |
Dan Carpenter | 036de8e | 2009-04-08 13:52:39 +0300 | [diff] [blame] | 671 | return; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 672 | |
| 673 | /* get output voltage */ |
Mark Brown | 1bf5a1f | 2010-12-10 17:28:06 +0000 | [diff] [blame] | 674 | output_uV = _regulator_get_voltage(rdev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 675 | if (output_uV <= 0) |
| 676 | return; |
| 677 | |
| 678 | /* get input voltage */ |
Mark Brown | 1bf5a1f | 2010-12-10 17:28:06 +0000 | [diff] [blame] | 679 | input_uV = 0; |
| 680 | if (rdev->supply) |
Axel Lin | 3f24f5a | 2012-04-13 21:35:05 +0800 | [diff] [blame] | 681 | input_uV = regulator_get_voltage(rdev->supply); |
Mark Brown | 1bf5a1f | 2010-12-10 17:28:06 +0000 | [diff] [blame] | 682 | if (input_uV <= 0) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 683 | input_uV = rdev->constraints->input_uV; |
| 684 | if (input_uV <= 0) |
| 685 | return; |
| 686 | |
| 687 | /* calc total requested load */ |
| 688 | list_for_each_entry(sibling, &rdev->consumer_list, list) |
Stefan Roese | fa2984d | 2009-11-27 15:56:34 +0100 | [diff] [blame] | 689 | current_uA += sibling->uA_load; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 690 | |
| 691 | /* now get the optimum mode for our new total regulator load */ |
| 692 | mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV, |
| 693 | output_uV, current_uA); |
| 694 | |
| 695 | /* check the new mode is allowed */ |
Mark Brown | 2c60823 | 2011-03-30 06:29:12 +0900 | [diff] [blame] | 696 | err = regulator_mode_constrain(rdev, &mode); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 697 | if (err == 0) |
| 698 | rdev->desc->ops->set_mode(rdev, mode); |
| 699 | } |
| 700 | |
| 701 | static int suspend_set_state(struct regulator_dev *rdev, |
| 702 | struct regulator_state *rstate) |
| 703 | { |
| 704 | int ret = 0; |
Mark Brown | 638f85c | 2009-10-22 16:31:33 +0100 | [diff] [blame] | 705 | |
| 706 | /* If we have no suspend mode configration don't set anything; |
Axel Lin | 8ac0e95 | 2012-04-14 09:14:34 +0800 | [diff] [blame] | 707 | * only warn if the driver implements set_suspend_voltage or |
| 708 | * set_suspend_mode callback. |
Mark Brown | 638f85c | 2009-10-22 16:31:33 +0100 | [diff] [blame] | 709 | */ |
| 710 | if (!rstate->enabled && !rstate->disabled) { |
Axel Lin | 8ac0e95 | 2012-04-14 09:14:34 +0800 | [diff] [blame] | 711 | if (rdev->desc->ops->set_suspend_voltage || |
| 712 | rdev->desc->ops->set_suspend_mode) |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 713 | rdev_warn(rdev, "No configuration\n"); |
Mark Brown | 638f85c | 2009-10-22 16:31:33 +0100 | [diff] [blame] | 714 | return 0; |
| 715 | } |
| 716 | |
| 717 | if (rstate->enabled && rstate->disabled) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 718 | rdev_err(rdev, "invalid configuration\n"); |
Mark Brown | 638f85c | 2009-10-22 16:31:33 +0100 | [diff] [blame] | 719 | return -EINVAL; |
| 720 | } |
| 721 | |
Axel Lin | 8ac0e95 | 2012-04-14 09:14:34 +0800 | [diff] [blame] | 722 | if (rstate->enabled && rdev->desc->ops->set_suspend_enable) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 723 | ret = rdev->desc->ops->set_suspend_enable(rdev); |
Axel Lin | 8ac0e95 | 2012-04-14 09:14:34 +0800 | [diff] [blame] | 724 | else if (rstate->disabled && rdev->desc->ops->set_suspend_disable) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 725 | ret = rdev->desc->ops->set_suspend_disable(rdev); |
Axel Lin | 8ac0e95 | 2012-04-14 09:14:34 +0800 | [diff] [blame] | 726 | else /* OK if set_suspend_enable or set_suspend_disable is NULL */ |
| 727 | ret = 0; |
| 728 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 729 | if (ret < 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 730 | rdev_err(rdev, "failed to enabled/disable\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 731 | return ret; |
| 732 | } |
| 733 | |
| 734 | if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) { |
| 735 | ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV); |
| 736 | if (ret < 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 737 | rdev_err(rdev, "failed to set voltage\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 738 | return ret; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) { |
| 743 | ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode); |
| 744 | if (ret < 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 745 | rdev_err(rdev, "failed to set mode\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 746 | return ret; |
| 747 | } |
| 748 | } |
| 749 | return ret; |
| 750 | } |
| 751 | |
| 752 | /* locks held by caller */ |
| 753 | static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state) |
| 754 | { |
| 755 | if (!rdev->constraints) |
| 756 | return -EINVAL; |
| 757 | |
| 758 | switch (state) { |
| 759 | case PM_SUSPEND_STANDBY: |
| 760 | return suspend_set_state(rdev, |
| 761 | &rdev->constraints->state_standby); |
| 762 | case PM_SUSPEND_MEM: |
| 763 | return suspend_set_state(rdev, |
| 764 | &rdev->constraints->state_mem); |
| 765 | case PM_SUSPEND_MAX: |
| 766 | return suspend_set_state(rdev, |
| 767 | &rdev->constraints->state_disk); |
| 768 | default: |
| 769 | return -EINVAL; |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | static void print_constraints(struct regulator_dev *rdev) |
| 774 | { |
| 775 | struct regulation_constraints *constraints = rdev->constraints; |
Mark Brown | 973e9a2 | 2010-02-11 19:20:48 +0000 | [diff] [blame] | 776 | char buf[80] = ""; |
Mark Brown | 8f031b4 | 2009-10-22 16:31:31 +0100 | [diff] [blame] | 777 | int count = 0; |
| 778 | int ret; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 779 | |
Mark Brown | 8f031b4 | 2009-10-22 16:31:31 +0100 | [diff] [blame] | 780 | if (constraints->min_uV && constraints->max_uV) { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 781 | if (constraints->min_uV == constraints->max_uV) |
Mark Brown | 8f031b4 | 2009-10-22 16:31:31 +0100 | [diff] [blame] | 782 | count += sprintf(buf + count, "%d mV ", |
| 783 | constraints->min_uV / 1000); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 784 | else |
Mark Brown | 8f031b4 | 2009-10-22 16:31:31 +0100 | [diff] [blame] | 785 | count += sprintf(buf + count, "%d <--> %d mV ", |
| 786 | constraints->min_uV / 1000, |
| 787 | constraints->max_uV / 1000); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 788 | } |
Mark Brown | 8f031b4 | 2009-10-22 16:31:31 +0100 | [diff] [blame] | 789 | |
| 790 | if (!constraints->min_uV || |
| 791 | constraints->min_uV != constraints->max_uV) { |
| 792 | ret = _regulator_get_voltage(rdev); |
| 793 | if (ret > 0) |
| 794 | count += sprintf(buf + count, "at %d mV ", ret / 1000); |
| 795 | } |
| 796 | |
Mark Brown | bf5892a | 2011-05-08 22:13:37 +0100 | [diff] [blame] | 797 | if (constraints->uV_offset) |
| 798 | count += sprintf(buf, "%dmV offset ", |
| 799 | constraints->uV_offset / 1000); |
| 800 | |
Mark Brown | 8f031b4 | 2009-10-22 16:31:31 +0100 | [diff] [blame] | 801 | if (constraints->min_uA && constraints->max_uA) { |
| 802 | if (constraints->min_uA == constraints->max_uA) |
| 803 | count += sprintf(buf + count, "%d mA ", |
| 804 | constraints->min_uA / 1000); |
| 805 | else |
| 806 | count += sprintf(buf + count, "%d <--> %d mA ", |
| 807 | constraints->min_uA / 1000, |
| 808 | constraints->max_uA / 1000); |
| 809 | } |
| 810 | |
| 811 | if (!constraints->min_uA || |
| 812 | constraints->min_uA != constraints->max_uA) { |
| 813 | ret = _regulator_get_current_limit(rdev); |
| 814 | if (ret > 0) |
Cyril Chemparathy | e4a6376 | 2010-09-22 12:30:15 -0400 | [diff] [blame] | 815 | count += sprintf(buf + count, "at %d mA ", ret / 1000); |
Mark Brown | 8f031b4 | 2009-10-22 16:31:31 +0100 | [diff] [blame] | 816 | } |
| 817 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 818 | if (constraints->valid_modes_mask & REGULATOR_MODE_FAST) |
| 819 | count += sprintf(buf + count, "fast "); |
| 820 | if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL) |
| 821 | count += sprintf(buf + count, "normal "); |
| 822 | if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE) |
| 823 | count += sprintf(buf + count, "idle "); |
| 824 | if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) |
| 825 | count += sprintf(buf + count, "standby"); |
| 826 | |
Uwe Kleine-König | 215b8b0 | 2012-08-07 21:01:37 +0200 | [diff] [blame] | 827 | if (!count) |
| 828 | sprintf(buf, "no parameters"); |
| 829 | |
Mark Brown | 13ce29f | 2010-12-17 16:04:12 +0000 | [diff] [blame] | 830 | rdev_info(rdev, "%s\n", buf); |
Mark Brown | 4a68292 | 2012-02-09 13:26:13 +0000 | [diff] [blame] | 831 | |
| 832 | if ((constraints->min_uV != constraints->max_uV) && |
| 833 | !(constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) |
| 834 | rdev_warn(rdev, |
| 835 | "Voltage range but no REGULATOR_CHANGE_VOLTAGE\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 836 | } |
| 837 | |
Mark Brown | e79055d | 2009-10-19 15:53:50 +0100 | [diff] [blame] | 838 | static int machine_constraints_voltage(struct regulator_dev *rdev, |
Mark Brown | 1083c39 | 2009-10-22 16:31:32 +0100 | [diff] [blame] | 839 | struct regulation_constraints *constraints) |
Mark Brown | e79055d | 2009-10-19 15:53:50 +0100 | [diff] [blame] | 840 | { |
| 841 | struct regulator_ops *ops = rdev->desc->ops; |
Mark Brown | af5866c | 2009-10-22 16:31:30 +0100 | [diff] [blame] | 842 | int ret; |
| 843 | |
| 844 | /* do we need to apply the constraint voltage */ |
| 845 | if (rdev->constraints->apply_uV && |
Mark Brown | 7579025 | 2010-12-12 14:25:50 +0000 | [diff] [blame] | 846 | rdev->constraints->min_uV == rdev->constraints->max_uV) { |
| 847 | ret = _regulator_do_set_voltage(rdev, |
| 848 | rdev->constraints->min_uV, |
| 849 | rdev->constraints->max_uV); |
| 850 | if (ret < 0) { |
| 851 | rdev_err(rdev, "failed to apply %duV constraint\n", |
| 852 | rdev->constraints->min_uV); |
Mark Brown | 7579025 | 2010-12-12 14:25:50 +0000 | [diff] [blame] | 853 | return ret; |
| 854 | } |
Mark Brown | af5866c | 2009-10-22 16:31:30 +0100 | [diff] [blame] | 855 | } |
Mark Brown | e79055d | 2009-10-19 15:53:50 +0100 | [diff] [blame] | 856 | |
| 857 | /* constrain machine-level voltage specs to fit |
| 858 | * the actual range supported by this regulator. |
| 859 | */ |
| 860 | if (ops->list_voltage && rdev->desc->n_voltages) { |
| 861 | int count = rdev->desc->n_voltages; |
| 862 | int i; |
| 863 | int min_uV = INT_MAX; |
| 864 | int max_uV = INT_MIN; |
| 865 | int cmin = constraints->min_uV; |
| 866 | int cmax = constraints->max_uV; |
| 867 | |
| 868 | /* it's safe to autoconfigure fixed-voltage supplies |
| 869 | and the constraints are used by list_voltage. */ |
| 870 | if (count == 1 && !cmin) { |
| 871 | cmin = 1; |
| 872 | cmax = INT_MAX; |
| 873 | constraints->min_uV = cmin; |
| 874 | constraints->max_uV = cmax; |
| 875 | } |
| 876 | |
| 877 | /* voltage constraints are optional */ |
| 878 | if ((cmin == 0) && (cmax == 0)) |
| 879 | return 0; |
| 880 | |
| 881 | /* else require explicit machine-level constraints */ |
| 882 | if (cmin <= 0 || cmax <= 0 || cmax < cmin) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 883 | rdev_err(rdev, "invalid voltage constraints\n"); |
Mark Brown | e79055d | 2009-10-19 15:53:50 +0100 | [diff] [blame] | 884 | return -EINVAL; |
| 885 | } |
| 886 | |
| 887 | /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */ |
| 888 | for (i = 0; i < count; i++) { |
| 889 | int value; |
| 890 | |
| 891 | value = ops->list_voltage(rdev, i); |
| 892 | if (value <= 0) |
| 893 | continue; |
| 894 | |
| 895 | /* maybe adjust [min_uV..max_uV] */ |
| 896 | if (value >= cmin && value < min_uV) |
| 897 | min_uV = value; |
| 898 | if (value <= cmax && value > max_uV) |
| 899 | max_uV = value; |
| 900 | } |
| 901 | |
| 902 | /* final: [min_uV..max_uV] valid iff constraints valid */ |
| 903 | if (max_uV < min_uV) { |
Mark Brown | fff15be | 2012-11-27 18:48:56 +0000 | [diff] [blame] | 904 | rdev_err(rdev, |
| 905 | "unsupportable voltage constraints %u-%uuV\n", |
| 906 | min_uV, max_uV); |
Mark Brown | e79055d | 2009-10-19 15:53:50 +0100 | [diff] [blame] | 907 | return -EINVAL; |
| 908 | } |
| 909 | |
| 910 | /* use regulator's subset of machine constraints */ |
| 911 | if (constraints->min_uV < min_uV) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 912 | rdev_dbg(rdev, "override min_uV, %d -> %d\n", |
| 913 | constraints->min_uV, min_uV); |
Mark Brown | e79055d | 2009-10-19 15:53:50 +0100 | [diff] [blame] | 914 | constraints->min_uV = min_uV; |
| 915 | } |
| 916 | if (constraints->max_uV > max_uV) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 917 | rdev_dbg(rdev, "override max_uV, %d -> %d\n", |
| 918 | constraints->max_uV, max_uV); |
Mark Brown | e79055d | 2009-10-19 15:53:50 +0100 | [diff] [blame] | 919 | constraints->max_uV = max_uV; |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | return 0; |
| 924 | } |
| 925 | |
Laxman Dewangan | f8c1700 | 2013-09-20 13:13:02 +0530 | [diff] [blame] | 926 | static int machine_constraints_current(struct regulator_dev *rdev, |
| 927 | struct regulation_constraints *constraints) |
| 928 | { |
| 929 | struct regulator_ops *ops = rdev->desc->ops; |
| 930 | int ret; |
| 931 | |
| 932 | if (!constraints->min_uA && !constraints->max_uA) |
| 933 | return 0; |
| 934 | |
| 935 | if (constraints->min_uA > constraints->max_uA) { |
| 936 | rdev_err(rdev, "Invalid current constraints\n"); |
| 937 | return -EINVAL; |
| 938 | } |
| 939 | |
| 940 | if (!ops->set_current_limit || !ops->get_current_limit) { |
| 941 | rdev_warn(rdev, "Operation of current configuration missing\n"); |
| 942 | return 0; |
| 943 | } |
| 944 | |
| 945 | /* Set regulator current in constraints range */ |
| 946 | ret = ops->set_current_limit(rdev, constraints->min_uA, |
| 947 | constraints->max_uA); |
| 948 | if (ret < 0) { |
| 949 | rdev_err(rdev, "Failed to set current constraint, %d\n", ret); |
| 950 | return ret; |
| 951 | } |
| 952 | |
| 953 | return 0; |
| 954 | } |
| 955 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 956 | /** |
| 957 | * set_machine_constraints - sets regulator constraints |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 958 | * @rdev: regulator source |
Mark Brown | c8e7e46 | 2008-12-31 12:52:42 +0000 | [diff] [blame] | 959 | * @constraints: constraints to apply |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 960 | * |
| 961 | * Allows platform initialisation code to define and constrain |
| 962 | * regulator circuits e.g. valid voltage/current ranges, etc. NOTE: |
| 963 | * Constraints *must* be set by platform code in order for some |
| 964 | * regulator operations to proceed i.e. set_voltage, set_current_limit, |
| 965 | * set_mode. |
| 966 | */ |
| 967 | static int set_machine_constraints(struct regulator_dev *rdev, |
Mark Brown | f8c12fe | 2010-11-29 15:55:17 +0000 | [diff] [blame] | 968 | const struct regulation_constraints *constraints) |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 969 | { |
| 970 | int ret = 0; |
Mark Brown | e5fda26 | 2008-09-09 16:21:20 +0100 | [diff] [blame] | 971 | struct regulator_ops *ops = rdev->desc->ops; |
Mark Brown | e06f5b4 | 2008-09-09 16:21:19 +0100 | [diff] [blame] | 972 | |
Mark Brown | 9a8f5e0 | 2011-11-29 18:11:19 +0000 | [diff] [blame] | 973 | if (constraints) |
| 974 | rdev->constraints = kmemdup(constraints, sizeof(*constraints), |
| 975 | GFP_KERNEL); |
| 976 | else |
| 977 | rdev->constraints = kzalloc(sizeof(*constraints), |
| 978 | GFP_KERNEL); |
Mark Brown | f8c12fe | 2010-11-29 15:55:17 +0000 | [diff] [blame] | 979 | if (!rdev->constraints) |
| 980 | return -ENOMEM; |
Mark Brown | af5866c | 2009-10-22 16:31:30 +0100 | [diff] [blame] | 981 | |
Mark Brown | f8c12fe | 2010-11-29 15:55:17 +0000 | [diff] [blame] | 982 | ret = machine_constraints_voltage(rdev, rdev->constraints); |
Mark Brown | e79055d | 2009-10-19 15:53:50 +0100 | [diff] [blame] | 983 | if (ret != 0) |
| 984 | goto out; |
David Brownell | 4367cfd | 2009-02-26 11:48:36 -0800 | [diff] [blame] | 985 | |
Laxman Dewangan | f8c1700 | 2013-09-20 13:13:02 +0530 | [diff] [blame] | 986 | ret = machine_constraints_current(rdev, rdev->constraints); |
| 987 | if (ret != 0) |
| 988 | goto out; |
| 989 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 990 | /* do we need to setup our suspend state */ |
Mark Brown | 9a8f5e0 | 2011-11-29 18:11:19 +0000 | [diff] [blame] | 991 | if (rdev->constraints->initial_state) { |
Mark Brown | f8c12fe | 2010-11-29 15:55:17 +0000 | [diff] [blame] | 992 | ret = suspend_prepare(rdev, rdev->constraints->initial_state); |
Mark Brown | e06f5b4 | 2008-09-09 16:21:19 +0100 | [diff] [blame] | 993 | if (ret < 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 994 | rdev_err(rdev, "failed to set suspend state\n"); |
Mark Brown | e06f5b4 | 2008-09-09 16:21:19 +0100 | [diff] [blame] | 995 | goto out; |
| 996 | } |
| 997 | } |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 998 | |
Mark Brown | 9a8f5e0 | 2011-11-29 18:11:19 +0000 | [diff] [blame] | 999 | if (rdev->constraints->initial_mode) { |
Mark Brown | a308466 | 2009-02-26 19:24:19 +0000 | [diff] [blame] | 1000 | if (!ops->set_mode) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 1001 | rdev_err(rdev, "no set_mode operation\n"); |
Mark Brown | a308466 | 2009-02-26 19:24:19 +0000 | [diff] [blame] | 1002 | ret = -EINVAL; |
| 1003 | goto out; |
| 1004 | } |
| 1005 | |
Mark Brown | f8c12fe | 2010-11-29 15:55:17 +0000 | [diff] [blame] | 1006 | ret = ops->set_mode(rdev, rdev->constraints->initial_mode); |
Mark Brown | a308466 | 2009-02-26 19:24:19 +0000 | [diff] [blame] | 1007 | if (ret < 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 1008 | rdev_err(rdev, "failed to set initial mode: %d\n", ret); |
Mark Brown | a308466 | 2009-02-26 19:24:19 +0000 | [diff] [blame] | 1009 | goto out; |
| 1010 | } |
| 1011 | } |
| 1012 | |
Mark Brown | cacf90f | 2009-03-02 16:32:46 +0000 | [diff] [blame] | 1013 | /* If the constraints say the regulator should be on at this point |
| 1014 | * and we have control then make sure it is enabled. |
| 1015 | */ |
Mark Brown | f8c12fe | 2010-11-29 15:55:17 +0000 | [diff] [blame] | 1016 | if ((rdev->constraints->always_on || rdev->constraints->boot_on) && |
| 1017 | ops->enable) { |
Mark Brown | e5fda26 | 2008-09-09 16:21:20 +0100 | [diff] [blame] | 1018 | ret = ops->enable(rdev); |
| 1019 | if (ret < 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 1020 | rdev_err(rdev, "failed to enable\n"); |
Mark Brown | e5fda26 | 2008-09-09 16:21:20 +0100 | [diff] [blame] | 1021 | goto out; |
| 1022 | } |
| 1023 | } |
| 1024 | |
Yadwinder Singh Brar | 1653ccf | 2013-06-29 18:21:15 +0530 | [diff] [blame] | 1025 | if ((rdev->constraints->ramp_delay || rdev->constraints->ramp_disable) |
| 1026 | && ops->set_ramp_delay) { |
Yadwinder Singh Brar | 6f0b2c6 | 2012-06-11 17:41:08 +0530 | [diff] [blame] | 1027 | ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay); |
| 1028 | if (ret < 0) { |
| 1029 | rdev_err(rdev, "failed to set ramp_delay\n"); |
| 1030 | goto out; |
| 1031 | } |
| 1032 | } |
| 1033 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1034 | print_constraints(rdev); |
Axel Lin | 1a6958e7 | 2011-07-15 10:50:43 +0800 | [diff] [blame] | 1035 | return 0; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1036 | out: |
Axel Lin | 1a6958e7 | 2011-07-15 10:50:43 +0800 | [diff] [blame] | 1037 | kfree(rdev->constraints); |
| 1038 | rdev->constraints = NULL; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1039 | return ret; |
| 1040 | } |
| 1041 | |
| 1042 | /** |
| 1043 | * set_supply - set regulator supply regulator |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 1044 | * @rdev: regulator name |
| 1045 | * @supply_rdev: supply regulator name |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1046 | * |
| 1047 | * Called by platform initialisation code to set the supply regulator for this |
| 1048 | * regulator. This ensures that a regulators supply will also be enabled by the |
| 1049 | * core if it's child is enabled. |
| 1050 | */ |
| 1051 | static int set_supply(struct regulator_dev *rdev, |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1052 | struct regulator_dev *supply_rdev) |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1053 | { |
| 1054 | int err; |
| 1055 | |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1056 | rdev_info(rdev, "supplied by %s\n", rdev_get_name(supply_rdev)); |
| 1057 | |
| 1058 | rdev->supply = create_regulator(supply_rdev, &rdev->dev, "SUPPLY"); |
Axel Lin | 32c78de | 2011-12-29 17:03:20 +0800 | [diff] [blame] | 1059 | if (rdev->supply == NULL) { |
| 1060 | err = -ENOMEM; |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1061 | return err; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1062 | } |
Laxman Dewangan | 57ad526a | 2012-07-23 20:35:46 +0530 | [diff] [blame] | 1063 | supply_rdev->open_count++; |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1064 | |
| 1065 | return 0; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | /** |
Randy Dunlap | 06c63f9 | 2010-11-18 15:02:26 -0800 | [diff] [blame] | 1069 | * set_consumer_device_supply - Bind a regulator to a symbolic supply |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 1070 | * @rdev: regulator source |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 1071 | * @consumer_dev_name: dev_name() string for device supply applies to |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 1072 | * @supply: symbolic name for supply |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1073 | * |
| 1074 | * Allows platform initialisation code to map physical regulator |
| 1075 | * sources to symbolic names for supplies for use by devices. Devices |
| 1076 | * should use these symbolic names to request regulators, avoiding the |
| 1077 | * need to provide board-specific regulator names as platform data. |
| 1078 | */ |
| 1079 | static int set_consumer_device_supply(struct regulator_dev *rdev, |
Mark Brown | 737f360 | 2012-02-02 00:10:51 +0000 | [diff] [blame] | 1080 | const char *consumer_dev_name, |
| 1081 | const char *supply) |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1082 | { |
| 1083 | struct regulator_map *node; |
Mark Brown | 9ed2099 | 2009-07-21 16:00:26 +0100 | [diff] [blame] | 1084 | int has_dev; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1085 | |
| 1086 | if (supply == NULL) |
| 1087 | return -EINVAL; |
| 1088 | |
Mark Brown | 9ed2099 | 2009-07-21 16:00:26 +0100 | [diff] [blame] | 1089 | if (consumer_dev_name != NULL) |
| 1090 | has_dev = 1; |
| 1091 | else |
| 1092 | has_dev = 0; |
| 1093 | |
David Brownell | 6001e13 | 2008-12-31 12:54:19 +0000 | [diff] [blame] | 1094 | list_for_each_entry(node, ®ulator_map_list, list) { |
Jani Nikula | 23b5cc2 | 2010-04-29 10:55:09 +0300 | [diff] [blame] | 1095 | if (node->dev_name && consumer_dev_name) { |
| 1096 | if (strcmp(node->dev_name, consumer_dev_name) != 0) |
| 1097 | continue; |
| 1098 | } else if (node->dev_name || consumer_dev_name) { |
David Brownell | 6001e13 | 2008-12-31 12:54:19 +0000 | [diff] [blame] | 1099 | continue; |
Jani Nikula | 23b5cc2 | 2010-04-29 10:55:09 +0300 | [diff] [blame] | 1100 | } |
| 1101 | |
David Brownell | 6001e13 | 2008-12-31 12:54:19 +0000 | [diff] [blame] | 1102 | if (strcmp(node->supply, supply) != 0) |
| 1103 | continue; |
| 1104 | |
Mark Brown | 737f360 | 2012-02-02 00:10:51 +0000 | [diff] [blame] | 1105 | pr_debug("%s: %s/%s is '%s' supply; fail %s/%s\n", |
| 1106 | consumer_dev_name, |
| 1107 | dev_name(&node->regulator->dev), |
| 1108 | node->regulator->desc->name, |
| 1109 | supply, |
| 1110 | dev_name(&rdev->dev), rdev_get_name(rdev)); |
David Brownell | 6001e13 | 2008-12-31 12:54:19 +0000 | [diff] [blame] | 1111 | return -EBUSY; |
| 1112 | } |
| 1113 | |
Mark Brown | 9ed2099 | 2009-07-21 16:00:26 +0100 | [diff] [blame] | 1114 | node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL); |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1115 | if (node == NULL) |
| 1116 | return -ENOMEM; |
| 1117 | |
| 1118 | node->regulator = rdev; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1119 | node->supply = supply; |
| 1120 | |
Mark Brown | 9ed2099 | 2009-07-21 16:00:26 +0100 | [diff] [blame] | 1121 | if (has_dev) { |
| 1122 | node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL); |
| 1123 | if (node->dev_name == NULL) { |
| 1124 | kfree(node); |
| 1125 | return -ENOMEM; |
| 1126 | } |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 1127 | } |
| 1128 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1129 | list_add(&node->list, ®ulator_map_list); |
| 1130 | return 0; |
| 1131 | } |
| 1132 | |
Mike Rapoport | 0f1d747 | 2009-01-22 16:00:29 +0200 | [diff] [blame] | 1133 | static void unset_regulator_supplies(struct regulator_dev *rdev) |
| 1134 | { |
| 1135 | struct regulator_map *node, *n; |
| 1136 | |
| 1137 | list_for_each_entry_safe(node, n, ®ulator_map_list, list) { |
| 1138 | if (rdev == node->regulator) { |
| 1139 | list_del(&node->list); |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 1140 | kfree(node->dev_name); |
Mike Rapoport | 0f1d747 | 2009-01-22 16:00:29 +0200 | [diff] [blame] | 1141 | kfree(node); |
Mike Rapoport | 0f1d747 | 2009-01-22 16:00:29 +0200 | [diff] [blame] | 1142 | } |
| 1143 | } |
| 1144 | } |
| 1145 | |
Mark Brown | f5726ae | 2011-06-09 16:22:20 +0100 | [diff] [blame] | 1146 | #define REG_STR_SIZE 64 |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1147 | |
| 1148 | static struct regulator *create_regulator(struct regulator_dev *rdev, |
| 1149 | struct device *dev, |
| 1150 | const char *supply_name) |
| 1151 | { |
| 1152 | struct regulator *regulator; |
| 1153 | char buf[REG_STR_SIZE]; |
| 1154 | int err, size; |
| 1155 | |
| 1156 | regulator = kzalloc(sizeof(*regulator), GFP_KERNEL); |
| 1157 | if (regulator == NULL) |
| 1158 | return NULL; |
| 1159 | |
| 1160 | mutex_lock(&rdev->mutex); |
| 1161 | regulator->rdev = rdev; |
| 1162 | list_add(®ulator->list, &rdev->consumer_list); |
| 1163 | |
| 1164 | if (dev) { |
Shawn Guo | e2c98ea | 2012-07-05 14:19:42 +0800 | [diff] [blame] | 1165 | regulator->dev = dev; |
| 1166 | |
Mark Brown | 222cc7b | 2012-06-22 11:39:16 +0100 | [diff] [blame] | 1167 | /* Add a link to the device sysfs entry */ |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1168 | size = scnprintf(buf, REG_STR_SIZE, "%s-%s", |
| 1169 | dev->kobj.name, supply_name); |
| 1170 | if (size >= REG_STR_SIZE) |
Mark Brown | 222cc7b | 2012-06-22 11:39:16 +0100 | [diff] [blame] | 1171 | goto overflow_err; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1172 | |
| 1173 | regulator->supply_name = kstrdup(buf, GFP_KERNEL); |
| 1174 | if (regulator->supply_name == NULL) |
Mark Brown | 222cc7b | 2012-06-22 11:39:16 +0100 | [diff] [blame] | 1175 | goto overflow_err; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1176 | |
| 1177 | err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj, |
| 1178 | buf); |
| 1179 | if (err) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 1180 | rdev_warn(rdev, "could not add device link %s err %d\n", |
| 1181 | dev->kobj.name, err); |
Mark Brown | 222cc7b | 2012-06-22 11:39:16 +0100 | [diff] [blame] | 1182 | /* non-fatal */ |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1183 | } |
Mark Brown | 5de7051 | 2011-06-19 13:33:16 +0100 | [diff] [blame] | 1184 | } else { |
| 1185 | regulator->supply_name = kstrdup(supply_name, GFP_KERNEL); |
| 1186 | if (regulator->supply_name == NULL) |
Mark Brown | 222cc7b | 2012-06-22 11:39:16 +0100 | [diff] [blame] | 1187 | goto overflow_err; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1188 | } |
Mark Brown | 5de7051 | 2011-06-19 13:33:16 +0100 | [diff] [blame] | 1189 | |
Mark Brown | 5de7051 | 2011-06-19 13:33:16 +0100 | [diff] [blame] | 1190 | regulator->debugfs = debugfs_create_dir(regulator->supply_name, |
| 1191 | rdev->debugfs); |
Stephen Boyd | 2475143 | 2012-02-20 22:50:42 -0800 | [diff] [blame] | 1192 | if (!regulator->debugfs) { |
Mark Brown | 5de7051 | 2011-06-19 13:33:16 +0100 | [diff] [blame] | 1193 | rdev_warn(rdev, "Failed to create debugfs directory\n"); |
Mark Brown | 5de7051 | 2011-06-19 13:33:16 +0100 | [diff] [blame] | 1194 | } else { |
| 1195 | debugfs_create_u32("uA_load", 0444, regulator->debugfs, |
| 1196 | ®ulator->uA_load); |
| 1197 | debugfs_create_u32("min_uV", 0444, regulator->debugfs, |
| 1198 | ®ulator->min_uV); |
| 1199 | debugfs_create_u32("max_uV", 0444, regulator->debugfs, |
| 1200 | ®ulator->max_uV); |
| 1201 | } |
Mark Brown | 5de7051 | 2011-06-19 13:33:16 +0100 | [diff] [blame] | 1202 | |
Mark Brown | 6492bc1 | 2012-04-19 13:19:07 +0100 | [diff] [blame] | 1203 | /* |
| 1204 | * Check now if the regulator is an always on regulator - if |
| 1205 | * it is then we don't need to do nearly so much work for |
| 1206 | * enable/disable calls. |
| 1207 | */ |
| 1208 | if (!_regulator_can_change_status(rdev) && |
| 1209 | _regulator_is_enabled(rdev)) |
| 1210 | regulator->always_on = true; |
| 1211 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1212 | mutex_unlock(&rdev->mutex); |
| 1213 | return regulator; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1214 | overflow_err: |
| 1215 | list_del(®ulator->list); |
| 1216 | kfree(regulator); |
| 1217 | mutex_unlock(&rdev->mutex); |
| 1218 | return NULL; |
| 1219 | } |
| 1220 | |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 1221 | static int _regulator_get_enable_time(struct regulator_dev *rdev) |
| 1222 | { |
Laxman Dewangan | 00c877c | 2013-09-18 18:18:02 +0530 | [diff] [blame] | 1223 | if (rdev->constraints && rdev->constraints->enable_time) |
| 1224 | return rdev->constraints->enable_time; |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 1225 | if (!rdev->desc->ops->enable_time) |
Mark Brown | 79511ed | 2012-06-27 14:23:10 +0100 | [diff] [blame] | 1226 | return rdev->desc->enable_time; |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 1227 | return rdev->desc->ops->enable_time(rdev); |
| 1228 | } |
| 1229 | |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 1230 | static struct regulator_dev *regulator_dev_lookup(struct device *dev, |
Mark Brown | 6d191a5 | 2012-03-29 14:19:02 +0100 | [diff] [blame] | 1231 | const char *supply, |
| 1232 | int *ret) |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 1233 | { |
| 1234 | struct regulator_dev *r; |
| 1235 | struct device_node *node; |
Mark Brown | 576ca436 | 2012-03-30 12:24:37 +0100 | [diff] [blame] | 1236 | struct regulator_map *map; |
| 1237 | const char *devname = NULL; |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 1238 | |
| 1239 | /* first do a dt based lookup */ |
| 1240 | if (dev && dev->of_node) { |
| 1241 | node = of_get_regulator(dev, supply); |
Mark Brown | 6d191a5 | 2012-03-29 14:19:02 +0100 | [diff] [blame] | 1242 | if (node) { |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 1243 | list_for_each_entry(r, ®ulator_list, list) |
| 1244 | if (r->dev.parent && |
| 1245 | node == r->dev.of_node) |
| 1246 | return r; |
Mark Brown | 6d191a5 | 2012-03-29 14:19:02 +0100 | [diff] [blame] | 1247 | } else { |
| 1248 | /* |
| 1249 | * If we couldn't even get the node then it's |
| 1250 | * not just that the device didn't register |
| 1251 | * yet, there's no node and we'll never |
| 1252 | * succeed. |
| 1253 | */ |
| 1254 | *ret = -ENODEV; |
| 1255 | } |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | /* if not found, try doing it non-dt way */ |
Mark Brown | 576ca436 | 2012-03-30 12:24:37 +0100 | [diff] [blame] | 1259 | if (dev) |
| 1260 | devname = dev_name(dev); |
| 1261 | |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 1262 | list_for_each_entry(r, ®ulator_list, list) |
| 1263 | if (strcmp(rdev_get_name(r), supply) == 0) |
| 1264 | return r; |
| 1265 | |
Mark Brown | 576ca436 | 2012-03-30 12:24:37 +0100 | [diff] [blame] | 1266 | list_for_each_entry(map, ®ulator_map_list, list) { |
| 1267 | /* If the mapping has a device set up it must match */ |
| 1268 | if (map->dev_name && |
| 1269 | (!devname || strcmp(map->dev_name, devname))) |
| 1270 | continue; |
| 1271 | |
| 1272 | if (strcmp(map->supply, supply) == 0) |
| 1273 | return map->regulator; |
| 1274 | } |
| 1275 | |
| 1276 | |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 1277 | return NULL; |
| 1278 | } |
| 1279 | |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1280 | /* Internal regulator request function */ |
| 1281 | static struct regulator *_regulator_get(struct device *dev, const char *id, |
Mark Brown | 84fcf44 | 2013-08-18 18:03:22 +0100 | [diff] [blame] | 1282 | bool exclusive) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1283 | { |
| 1284 | struct regulator_dev *rdev; |
Mark Brown | 04bf301 | 2012-03-11 13:07:56 +0000 | [diff] [blame] | 1285 | struct regulator *regulator = ERR_PTR(-EPROBE_DEFER); |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 1286 | const char *devname = NULL; |
Nishanth Menon | 1e4b545 | 2013-04-16 16:45:16 -0500 | [diff] [blame] | 1287 | int ret = 0; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1288 | |
| 1289 | if (id == NULL) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 1290 | pr_err("get() with no identifier\n"); |
Mark Brown | 043c998 | 2013-09-20 12:32:18 +0100 | [diff] [blame^] | 1291 | return ERR_PTR(-EINVAL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1292 | } |
| 1293 | |
Mark Brown | 40f9244 | 2009-06-17 17:56:39 +0100 | [diff] [blame] | 1294 | if (dev) |
| 1295 | devname = dev_name(dev); |
| 1296 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1297 | mutex_lock(®ulator_list_mutex); |
| 1298 | |
Mark Brown | 6d191a5 | 2012-03-29 14:19:02 +0100 | [diff] [blame] | 1299 | rdev = regulator_dev_lookup(dev, id, &ret); |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 1300 | if (rdev) |
| 1301 | goto found; |
| 1302 | |
Nishanth Menon | 1e4b545 | 2013-04-16 16:45:16 -0500 | [diff] [blame] | 1303 | /* |
| 1304 | * If we have return value from dev_lookup fail, we do not expect to |
| 1305 | * succeed, so, quit with appropriate error value |
| 1306 | */ |
| 1307 | if (ret) { |
| 1308 | regulator = ERR_PTR(ret); |
| 1309 | goto out; |
| 1310 | } |
| 1311 | |
Mark Brown | 688fe99 | 2010-10-05 19:18:32 -0700 | [diff] [blame] | 1312 | if (board_wants_dummy_regulator) { |
| 1313 | rdev = dummy_regulator_rdev; |
| 1314 | goto found; |
| 1315 | } |
| 1316 | |
Mark Brown | 34abbd6 | 2010-02-12 10:18:08 +0000 | [diff] [blame] | 1317 | #ifdef CONFIG_REGULATOR_DUMMY |
| 1318 | if (!devname) |
| 1319 | devname = "deviceless"; |
| 1320 | |
| 1321 | /* If the board didn't flag that it was fully constrained then |
| 1322 | * substitute in a dummy regulator so consumers can continue. |
| 1323 | */ |
| 1324 | if (!has_full_constraints) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 1325 | pr_warn("%s supply %s not found, using dummy regulator\n", |
| 1326 | devname, id); |
Mark Brown | 34abbd6 | 2010-02-12 10:18:08 +0000 | [diff] [blame] | 1327 | rdev = dummy_regulator_rdev; |
| 1328 | goto found; |
| 1329 | } |
| 1330 | #endif |
| 1331 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1332 | mutex_unlock(®ulator_list_mutex); |
| 1333 | return regulator; |
| 1334 | |
| 1335 | found: |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1336 | if (rdev->exclusive) { |
| 1337 | regulator = ERR_PTR(-EPERM); |
| 1338 | goto out; |
| 1339 | } |
| 1340 | |
| 1341 | if (exclusive && rdev->open_count) { |
| 1342 | regulator = ERR_PTR(-EBUSY); |
| 1343 | goto out; |
| 1344 | } |
| 1345 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1346 | if (!try_module_get(rdev->owner)) |
| 1347 | goto out; |
| 1348 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1349 | regulator = create_regulator(rdev, dev, id); |
| 1350 | if (regulator == NULL) { |
| 1351 | regulator = ERR_PTR(-ENOMEM); |
| 1352 | module_put(rdev->owner); |
Axel Lin | bcda432 | 2011-12-29 17:02:08 +0800 | [diff] [blame] | 1353 | goto out; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1354 | } |
| 1355 | |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1356 | rdev->open_count++; |
| 1357 | if (exclusive) { |
| 1358 | rdev->exclusive = 1; |
| 1359 | |
| 1360 | ret = _regulator_is_enabled(rdev); |
| 1361 | if (ret > 0) |
| 1362 | rdev->use_count = 1; |
| 1363 | else |
| 1364 | rdev->use_count = 0; |
| 1365 | } |
| 1366 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 1367 | out: |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1368 | mutex_unlock(®ulator_list_mutex); |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1369 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1370 | return regulator; |
| 1371 | } |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1372 | |
| 1373 | /** |
| 1374 | * regulator_get - lookup and obtain a reference to a regulator. |
| 1375 | * @dev: device for regulator "consumer" |
| 1376 | * @id: Supply name or regulator ID. |
| 1377 | * |
| 1378 | * Returns a struct regulator corresponding to the regulator producer, |
| 1379 | * or IS_ERR() condition containing errno. |
| 1380 | * |
| 1381 | * Use of supply names configured via regulator_set_device_supply() is |
| 1382 | * strongly encouraged. It is recommended that the supply name used |
| 1383 | * should match the name used for the supply and/or the relevant |
| 1384 | * device pins in the datasheet. |
| 1385 | */ |
| 1386 | struct regulator *regulator_get(struct device *dev, const char *id) |
| 1387 | { |
Mark Brown | 84fcf44 | 2013-08-18 18:03:22 +0100 | [diff] [blame] | 1388 | return _regulator_get(dev, id, false); |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1389 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1390 | EXPORT_SYMBOL_GPL(regulator_get); |
| 1391 | |
Stephen Boyd | 070b907 | 2012-01-16 19:39:58 -0800 | [diff] [blame] | 1392 | static void devm_regulator_release(struct device *dev, void *res) |
| 1393 | { |
| 1394 | regulator_put(*(struct regulator **)res); |
| 1395 | } |
| 1396 | |
| 1397 | /** |
| 1398 | * devm_regulator_get - Resource managed regulator_get() |
| 1399 | * @dev: device for regulator "consumer" |
| 1400 | * @id: Supply name or regulator ID. |
| 1401 | * |
| 1402 | * Managed regulator_get(). Regulators returned from this function are |
| 1403 | * automatically regulator_put() on driver detach. See regulator_get() for more |
| 1404 | * information. |
| 1405 | */ |
| 1406 | struct regulator *devm_regulator_get(struct device *dev, const char *id) |
| 1407 | { |
| 1408 | struct regulator **ptr, *regulator; |
| 1409 | |
| 1410 | ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL); |
| 1411 | if (!ptr) |
| 1412 | return ERR_PTR(-ENOMEM); |
| 1413 | |
| 1414 | regulator = regulator_get(dev, id); |
| 1415 | if (!IS_ERR(regulator)) { |
| 1416 | *ptr = regulator; |
| 1417 | devres_add(dev, ptr); |
| 1418 | } else { |
| 1419 | devres_free(ptr); |
| 1420 | } |
| 1421 | |
| 1422 | return regulator; |
| 1423 | } |
| 1424 | EXPORT_SYMBOL_GPL(devm_regulator_get); |
| 1425 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1426 | /** |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1427 | * regulator_get_exclusive - obtain exclusive access to a regulator. |
| 1428 | * @dev: device for regulator "consumer" |
| 1429 | * @id: Supply name or regulator ID. |
| 1430 | * |
| 1431 | * Returns a struct regulator corresponding to the regulator producer, |
| 1432 | * or IS_ERR() condition containing errno. Other consumers will be |
| 1433 | * unable to obtain this reference is held and the use count for the |
| 1434 | * regulator will be initialised to reflect the current state of the |
| 1435 | * regulator. |
| 1436 | * |
| 1437 | * This is intended for use by consumers which cannot tolerate shared |
| 1438 | * use of the regulator such as those which need to force the |
| 1439 | * regulator off for correct operation of the hardware they are |
| 1440 | * controlling. |
| 1441 | * |
| 1442 | * Use of supply names configured via regulator_set_device_supply() is |
| 1443 | * strongly encouraged. It is recommended that the supply name used |
| 1444 | * should match the name used for the supply and/or the relevant |
| 1445 | * device pins in the datasheet. |
| 1446 | */ |
| 1447 | struct regulator *regulator_get_exclusive(struct device *dev, const char *id) |
| 1448 | { |
Mark Brown | 84fcf44 | 2013-08-18 18:03:22 +0100 | [diff] [blame] | 1449 | return _regulator_get(dev, id, true); |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1450 | } |
| 1451 | EXPORT_SYMBOL_GPL(regulator_get_exclusive); |
| 1452 | |
Mark Brown | de1dd9f | 2013-07-29 21:42:42 +0100 | [diff] [blame] | 1453 | /** |
| 1454 | * regulator_get_optional - obtain optional access to a regulator. |
| 1455 | * @dev: device for regulator "consumer" |
| 1456 | * @id: Supply name or regulator ID. |
| 1457 | * |
| 1458 | * Returns a struct regulator corresponding to the regulator producer, |
| 1459 | * or IS_ERR() condition containing errno. Other consumers will be |
| 1460 | * unable to obtain this reference is held and the use count for the |
| 1461 | * regulator will be initialised to reflect the current state of the |
| 1462 | * regulator. |
| 1463 | * |
| 1464 | * This is intended for use by consumers for devices which can have |
| 1465 | * some supplies unconnected in normal use, such as some MMC devices. |
| 1466 | * It can allow the regulator core to provide stub supplies for other |
| 1467 | * supplies requested using normal regulator_get() calls without |
| 1468 | * disrupting the operation of drivers that can handle absent |
| 1469 | * supplies. |
| 1470 | * |
| 1471 | * Use of supply names configured via regulator_set_device_supply() is |
| 1472 | * strongly encouraged. It is recommended that the supply name used |
| 1473 | * should match the name used for the supply and/or the relevant |
| 1474 | * device pins in the datasheet. |
| 1475 | */ |
| 1476 | struct regulator *regulator_get_optional(struct device *dev, const char *id) |
| 1477 | { |
| 1478 | return _regulator_get(dev, id, 0); |
| 1479 | } |
| 1480 | EXPORT_SYMBOL_GPL(regulator_get_optional); |
| 1481 | |
| 1482 | /** |
| 1483 | * devm_regulator_get_optional - Resource managed regulator_get_optional() |
| 1484 | * @dev: device for regulator "consumer" |
| 1485 | * @id: Supply name or regulator ID. |
| 1486 | * |
| 1487 | * Managed regulator_get_optional(). Regulators returned from this |
| 1488 | * function are automatically regulator_put() on driver detach. See |
| 1489 | * regulator_get_optional() for more information. |
| 1490 | */ |
| 1491 | struct regulator *devm_regulator_get_optional(struct device *dev, |
| 1492 | const char *id) |
| 1493 | { |
| 1494 | struct regulator **ptr, *regulator; |
| 1495 | |
| 1496 | ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL); |
| 1497 | if (!ptr) |
| 1498 | return ERR_PTR(-ENOMEM); |
| 1499 | |
| 1500 | regulator = regulator_get_optional(dev, id); |
| 1501 | if (!IS_ERR(regulator)) { |
| 1502 | *ptr = regulator; |
| 1503 | devres_add(dev, ptr); |
| 1504 | } else { |
| 1505 | devres_free(ptr); |
| 1506 | } |
| 1507 | |
| 1508 | return regulator; |
| 1509 | } |
| 1510 | EXPORT_SYMBOL_GPL(devm_regulator_get_optional); |
| 1511 | |
Charles Keepax | 23ff2f0 | 2012-11-14 09:39:31 +0000 | [diff] [blame] | 1512 | /* Locks held by regulator_put() */ |
| 1513 | static void _regulator_put(struct regulator *regulator) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1514 | { |
| 1515 | struct regulator_dev *rdev; |
| 1516 | |
| 1517 | if (regulator == NULL || IS_ERR(regulator)) |
| 1518 | return; |
| 1519 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1520 | rdev = regulator->rdev; |
| 1521 | |
Mark Brown | 5de7051 | 2011-06-19 13:33:16 +0100 | [diff] [blame] | 1522 | debugfs_remove_recursive(regulator->debugfs); |
Mark Brown | 5de7051 | 2011-06-19 13:33:16 +0100 | [diff] [blame] | 1523 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1524 | /* remove any sysfs entries */ |
Shawn Guo | e2c98ea | 2012-07-05 14:19:42 +0800 | [diff] [blame] | 1525 | if (regulator->dev) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1526 | sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); |
Mark Brown | 5de7051 | 2011-06-19 13:33:16 +0100 | [diff] [blame] | 1527 | kfree(regulator->supply_name); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1528 | list_del(®ulator->list); |
| 1529 | kfree(regulator); |
| 1530 | |
Mark Brown | 5ffbd13 | 2009-07-21 16:00:23 +0100 | [diff] [blame] | 1531 | rdev->open_count--; |
| 1532 | rdev->exclusive = 0; |
| 1533 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1534 | module_put(rdev->owner); |
Charles Keepax | 23ff2f0 | 2012-11-14 09:39:31 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | /** |
Matthias Kaehlcke | 9efdd27 | 2013-08-25 17:54:13 +0200 | [diff] [blame] | 1538 | * devm_regulator_get_exclusive - Resource managed regulator_get_exclusive() |
| 1539 | * @dev: device for regulator "consumer" |
| 1540 | * @id: Supply name or regulator ID. |
| 1541 | * |
| 1542 | * Managed regulator_get_exclusive(). Regulators returned from this function |
| 1543 | * are automatically regulator_put() on driver detach. See regulator_get() for |
| 1544 | * more information. |
| 1545 | */ |
| 1546 | struct regulator *devm_regulator_get_exclusive(struct device *dev, |
| 1547 | const char *id) |
| 1548 | { |
| 1549 | struct regulator **ptr, *regulator; |
| 1550 | |
| 1551 | ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL); |
| 1552 | if (!ptr) |
| 1553 | return ERR_PTR(-ENOMEM); |
| 1554 | |
| 1555 | regulator = _regulator_get(dev, id, 1); |
| 1556 | if (!IS_ERR(regulator)) { |
| 1557 | *ptr = regulator; |
| 1558 | devres_add(dev, ptr); |
| 1559 | } else { |
| 1560 | devres_free(ptr); |
| 1561 | } |
| 1562 | |
| 1563 | return regulator; |
| 1564 | } |
| 1565 | EXPORT_SYMBOL_GPL(devm_regulator_get_exclusive); |
| 1566 | |
| 1567 | /** |
Charles Keepax | 23ff2f0 | 2012-11-14 09:39:31 +0000 | [diff] [blame] | 1568 | * regulator_put - "free" the regulator source |
| 1569 | * @regulator: regulator source |
| 1570 | * |
| 1571 | * Note: drivers must ensure that all regulator_enable calls made on this |
| 1572 | * regulator source are balanced by regulator_disable calls prior to calling |
| 1573 | * this function. |
| 1574 | */ |
| 1575 | void regulator_put(struct regulator *regulator) |
| 1576 | { |
| 1577 | mutex_lock(®ulator_list_mutex); |
| 1578 | _regulator_put(regulator); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1579 | mutex_unlock(®ulator_list_mutex); |
| 1580 | } |
| 1581 | EXPORT_SYMBOL_GPL(regulator_put); |
| 1582 | |
Mark Brown | d5ad34f | 2012-01-20 20:09:18 +0000 | [diff] [blame] | 1583 | static int devm_regulator_match(struct device *dev, void *res, void *data) |
| 1584 | { |
| 1585 | struct regulator **r = res; |
| 1586 | if (!r || !*r) { |
| 1587 | WARN_ON(!r || !*r); |
| 1588 | return 0; |
| 1589 | } |
| 1590 | return *r == data; |
| 1591 | } |
| 1592 | |
| 1593 | /** |
| 1594 | * devm_regulator_put - Resource managed regulator_put() |
| 1595 | * @regulator: regulator to free |
| 1596 | * |
| 1597 | * Deallocate a regulator allocated with devm_regulator_get(). Normally |
| 1598 | * this function will not need to be called and the resource management |
| 1599 | * code will ensure that the resource is freed. |
| 1600 | */ |
| 1601 | void devm_regulator_put(struct regulator *regulator) |
| 1602 | { |
| 1603 | int rc; |
| 1604 | |
Mark Brown | 361ff50 | 2012-05-07 14:14:30 +0100 | [diff] [blame] | 1605 | rc = devres_release(regulator->dev, devm_regulator_release, |
Mark Brown | d5ad34f | 2012-01-20 20:09:18 +0000 | [diff] [blame] | 1606 | devm_regulator_match, regulator); |
Mark Brown | 230a5a1c | 2012-06-15 18:25:08 +0100 | [diff] [blame] | 1607 | if (rc != 0) |
Mark Brown | 968c2c1 | 2012-05-07 11:34:52 +0100 | [diff] [blame] | 1608 | WARN_ON(rc); |
Mark Brown | d5ad34f | 2012-01-20 20:09:18 +0000 | [diff] [blame] | 1609 | } |
| 1610 | EXPORT_SYMBOL_GPL(devm_regulator_put); |
| 1611 | |
Kim, Milo | f19b00d | 2013-02-18 06:50:39 +0000 | [diff] [blame] | 1612 | /* Manage enable GPIO list. Same GPIO pin can be shared among regulators */ |
| 1613 | static int regulator_ena_gpio_request(struct regulator_dev *rdev, |
| 1614 | const struct regulator_config *config) |
| 1615 | { |
| 1616 | struct regulator_enable_gpio *pin; |
| 1617 | int ret; |
| 1618 | |
| 1619 | list_for_each_entry(pin, ®ulator_ena_gpio_list, list) { |
| 1620 | if (pin->gpio == config->ena_gpio) { |
| 1621 | rdev_dbg(rdev, "GPIO %d is already used\n", |
| 1622 | config->ena_gpio); |
| 1623 | goto update_ena_gpio_to_rdev; |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | ret = gpio_request_one(config->ena_gpio, |
| 1628 | GPIOF_DIR_OUT | config->ena_gpio_flags, |
| 1629 | rdev_get_name(rdev)); |
| 1630 | if (ret) |
| 1631 | return ret; |
| 1632 | |
| 1633 | pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL); |
| 1634 | if (pin == NULL) { |
| 1635 | gpio_free(config->ena_gpio); |
| 1636 | return -ENOMEM; |
| 1637 | } |
| 1638 | |
| 1639 | pin->gpio = config->ena_gpio; |
| 1640 | pin->ena_gpio_invert = config->ena_gpio_invert; |
| 1641 | list_add(&pin->list, ®ulator_ena_gpio_list); |
| 1642 | |
| 1643 | update_ena_gpio_to_rdev: |
| 1644 | pin->request_count++; |
| 1645 | rdev->ena_pin = pin; |
| 1646 | return 0; |
| 1647 | } |
| 1648 | |
| 1649 | static void regulator_ena_gpio_free(struct regulator_dev *rdev) |
| 1650 | { |
| 1651 | struct regulator_enable_gpio *pin, *n; |
| 1652 | |
| 1653 | if (!rdev->ena_pin) |
| 1654 | return; |
| 1655 | |
| 1656 | /* Free the GPIO only in case of no use */ |
| 1657 | list_for_each_entry_safe(pin, n, ®ulator_ena_gpio_list, list) { |
| 1658 | if (pin->gpio == rdev->ena_pin->gpio) { |
| 1659 | if (pin->request_count <= 1) { |
| 1660 | pin->request_count = 0; |
| 1661 | gpio_free(pin->gpio); |
| 1662 | list_del(&pin->list); |
| 1663 | kfree(pin); |
| 1664 | } else { |
| 1665 | pin->request_count--; |
| 1666 | } |
| 1667 | } |
| 1668 | } |
| 1669 | } |
| 1670 | |
Kim, Milo | 967cfb1 | 2013-02-18 06:50:48 +0000 | [diff] [blame] | 1671 | /** |
Robert P. J. Day | 31d6eeb | 2013-05-02 10:19:11 -0400 | [diff] [blame] | 1672 | * regulator_ena_gpio_ctrl - balance enable_count of each GPIO and actual GPIO pin control |
| 1673 | * @rdev: regulator_dev structure |
| 1674 | * @enable: enable GPIO at initial use? |
| 1675 | * |
Kim, Milo | 967cfb1 | 2013-02-18 06:50:48 +0000 | [diff] [blame] | 1676 | * GPIO is enabled in case of initial use. (enable_count is 0) |
| 1677 | * GPIO is disabled when it is not shared any more. (enable_count <= 1) |
| 1678 | */ |
| 1679 | static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable) |
| 1680 | { |
| 1681 | struct regulator_enable_gpio *pin = rdev->ena_pin; |
| 1682 | |
| 1683 | if (!pin) |
| 1684 | return -EINVAL; |
| 1685 | |
| 1686 | if (enable) { |
| 1687 | /* Enable GPIO at initial use */ |
| 1688 | if (pin->enable_count == 0) |
| 1689 | gpio_set_value_cansleep(pin->gpio, |
| 1690 | !pin->ena_gpio_invert); |
| 1691 | |
| 1692 | pin->enable_count++; |
| 1693 | } else { |
| 1694 | if (pin->enable_count > 1) { |
| 1695 | pin->enable_count--; |
| 1696 | return 0; |
| 1697 | } |
| 1698 | |
| 1699 | /* Disable GPIO if not used */ |
| 1700 | if (pin->enable_count <= 1) { |
| 1701 | gpio_set_value_cansleep(pin->gpio, |
| 1702 | pin->ena_gpio_invert); |
| 1703 | pin->enable_count = 0; |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | return 0; |
| 1708 | } |
| 1709 | |
Mark Brown | 5c5659d | 2012-06-27 13:21:26 +0100 | [diff] [blame] | 1710 | static int _regulator_do_enable(struct regulator_dev *rdev) |
| 1711 | { |
| 1712 | int ret, delay; |
| 1713 | |
| 1714 | /* Query before enabling in case configuration dependent. */ |
| 1715 | ret = _regulator_get_enable_time(rdev); |
| 1716 | if (ret >= 0) { |
| 1717 | delay = ret; |
| 1718 | } else { |
| 1719 | rdev_warn(rdev, "enable_time() failed: %d\n", ret); |
| 1720 | delay = 0; |
| 1721 | } |
| 1722 | |
| 1723 | trace_regulator_enable(rdev_get_name(rdev)); |
| 1724 | |
Kim, Milo | 967cfb1 | 2013-02-18 06:50:48 +0000 | [diff] [blame] | 1725 | if (rdev->ena_pin) { |
| 1726 | ret = regulator_ena_gpio_ctrl(rdev, true); |
| 1727 | if (ret < 0) |
| 1728 | return ret; |
Mark Brown | 65f7350 | 2012-06-27 14:14:38 +0100 | [diff] [blame] | 1729 | rdev->ena_gpio_state = 1; |
| 1730 | } else if (rdev->desc->ops->enable) { |
Mark Brown | 5c5659d | 2012-06-27 13:21:26 +0100 | [diff] [blame] | 1731 | ret = rdev->desc->ops->enable(rdev); |
| 1732 | if (ret < 0) |
| 1733 | return ret; |
| 1734 | } else { |
| 1735 | return -EINVAL; |
| 1736 | } |
| 1737 | |
| 1738 | /* Allow the regulator to ramp; it would be useful to extend |
| 1739 | * this for bulk operations so that the regulators can ramp |
| 1740 | * together. */ |
| 1741 | trace_regulator_enable_delay(rdev_get_name(rdev)); |
| 1742 | |
| 1743 | if (delay >= 1000) { |
| 1744 | mdelay(delay / 1000); |
| 1745 | udelay(delay % 1000); |
| 1746 | } else if (delay) { |
| 1747 | udelay(delay); |
| 1748 | } |
| 1749 | |
| 1750 | trace_regulator_enable_complete(rdev_get_name(rdev)); |
| 1751 | |
| 1752 | return 0; |
| 1753 | } |
| 1754 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1755 | /* locks held by regulator_enable() */ |
| 1756 | static int _regulator_enable(struct regulator_dev *rdev) |
| 1757 | { |
Mark Brown | 5c5659d | 2012-06-27 13:21:26 +0100 | [diff] [blame] | 1758 | int ret; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1759 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1760 | /* check voltage and requested load before enabling */ |
Mark Brown | 9a2372f | 2009-08-03 18:49:57 +0100 | [diff] [blame] | 1761 | if (rdev->constraints && |
| 1762 | (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) |
| 1763 | drms_uA_update(rdev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1764 | |
Mark Brown | 9a2372f | 2009-08-03 18:49:57 +0100 | [diff] [blame] | 1765 | if (rdev->use_count == 0) { |
| 1766 | /* The regulator may on if it's not switchable or left on */ |
| 1767 | ret = _regulator_is_enabled(rdev); |
| 1768 | if (ret == -EINVAL || ret == 0) { |
| 1769 | if (!_regulator_can_change_status(rdev)) |
| 1770 | return -EPERM; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1771 | |
Mark Brown | 5c5659d | 2012-06-27 13:21:26 +0100 | [diff] [blame] | 1772 | ret = _regulator_do_enable(rdev); |
Mark Brown | 31aae2b | 2009-12-21 12:21:52 +0000 | [diff] [blame] | 1773 | if (ret < 0) |
| 1774 | return ret; |
| 1775 | |
Linus Walleij | a7433cf | 2009-08-26 12:54:04 +0200 | [diff] [blame] | 1776 | } else if (ret < 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 1777 | rdev_err(rdev, "is_enabled() failed: %d\n", ret); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1778 | return ret; |
| 1779 | } |
Linus Walleij | a7433cf | 2009-08-26 12:54:04 +0200 | [diff] [blame] | 1780 | /* Fallthrough on positive return values - already enabled */ |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1781 | } |
| 1782 | |
Mark Brown | 9a2372f | 2009-08-03 18:49:57 +0100 | [diff] [blame] | 1783 | rdev->use_count++; |
| 1784 | |
| 1785 | return 0; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | /** |
| 1789 | * regulator_enable - enable regulator output |
| 1790 | * @regulator: regulator source |
| 1791 | * |
Mark Brown | cf7bbcd | 2008-12-31 12:52:43 +0000 | [diff] [blame] | 1792 | * Request that the regulator be enabled with the regulator output at |
| 1793 | * the predefined voltage or current value. Calls to regulator_enable() |
| 1794 | * must be balanced with calls to regulator_disable(). |
| 1795 | * |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1796 | * 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] | 1797 | * hardwired in the regulator. |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1798 | */ |
| 1799 | int regulator_enable(struct regulator *regulator) |
| 1800 | { |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1801 | struct regulator_dev *rdev = regulator->rdev; |
| 1802 | int ret = 0; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1803 | |
Mark Brown | 6492bc1 | 2012-04-19 13:19:07 +0100 | [diff] [blame] | 1804 | if (regulator->always_on) |
| 1805 | return 0; |
| 1806 | |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1807 | if (rdev->supply) { |
| 1808 | ret = regulator_enable(rdev->supply); |
| 1809 | if (ret != 0) |
| 1810 | return ret; |
| 1811 | } |
| 1812 | |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1813 | mutex_lock(&rdev->mutex); |
David Brownell | cd94b50 | 2009-03-11 16:43:34 -0800 | [diff] [blame] | 1814 | ret = _regulator_enable(rdev); |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1815 | mutex_unlock(&rdev->mutex); |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1816 | |
Heiko Stübner | d1685e4 | 2011-10-14 18:00:29 +0200 | [diff] [blame] | 1817 | if (ret != 0 && rdev->supply) |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1818 | regulator_disable(rdev->supply); |
| 1819 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1820 | return ret; |
| 1821 | } |
| 1822 | EXPORT_SYMBOL_GPL(regulator_enable); |
| 1823 | |
Mark Brown | 5c5659d | 2012-06-27 13:21:26 +0100 | [diff] [blame] | 1824 | static int _regulator_do_disable(struct regulator_dev *rdev) |
| 1825 | { |
| 1826 | int ret; |
| 1827 | |
| 1828 | trace_regulator_disable(rdev_get_name(rdev)); |
| 1829 | |
Kim, Milo | 967cfb1 | 2013-02-18 06:50:48 +0000 | [diff] [blame] | 1830 | if (rdev->ena_pin) { |
| 1831 | ret = regulator_ena_gpio_ctrl(rdev, false); |
| 1832 | if (ret < 0) |
| 1833 | return ret; |
Mark Brown | 5c5659d | 2012-06-27 13:21:26 +0100 | [diff] [blame] | 1834 | rdev->ena_gpio_state = 0; |
| 1835 | |
| 1836 | } else if (rdev->desc->ops->disable) { |
| 1837 | ret = rdev->desc->ops->disable(rdev); |
| 1838 | if (ret != 0) |
| 1839 | return ret; |
| 1840 | } |
| 1841 | |
| 1842 | trace_regulator_disable_complete(rdev_get_name(rdev)); |
| 1843 | |
| 1844 | _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE, |
| 1845 | NULL); |
| 1846 | return 0; |
| 1847 | } |
| 1848 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1849 | /* locks held by regulator_disable() */ |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1850 | static int _regulator_disable(struct regulator_dev *rdev) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1851 | { |
| 1852 | int ret = 0; |
| 1853 | |
David Brownell | cd94b50 | 2009-03-11 16:43:34 -0800 | [diff] [blame] | 1854 | if (WARN(rdev->use_count <= 0, |
Joe Perches | 43e7ee3 | 2010-12-06 14:05:19 -0800 | [diff] [blame] | 1855 | "unbalanced disables for %s\n", rdev_get_name(rdev))) |
David Brownell | cd94b50 | 2009-03-11 16:43:34 -0800 | [diff] [blame] | 1856 | return -EIO; |
| 1857 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1858 | /* are we the last user and permitted to disable ? */ |
Mark Brown | 60ef66f | 2009-10-13 13:06:50 +0100 | [diff] [blame] | 1859 | if (rdev->use_count == 1 && |
| 1860 | (rdev->constraints && !rdev->constraints->always_on)) { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1861 | |
| 1862 | /* we are last user */ |
Mark Brown | 5c5659d | 2012-06-27 13:21:26 +0100 | [diff] [blame] | 1863 | if (_regulator_can_change_status(rdev)) { |
| 1864 | ret = _regulator_do_disable(rdev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1865 | if (ret < 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 1866 | rdev_err(rdev, "failed to disable\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1867 | return ret; |
| 1868 | } |
| 1869 | } |
| 1870 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1871 | rdev->use_count = 0; |
| 1872 | } else if (rdev->use_count > 1) { |
| 1873 | |
| 1874 | if (rdev->constraints && |
| 1875 | (rdev->constraints->valid_ops_mask & |
| 1876 | REGULATOR_CHANGE_DRMS)) |
| 1877 | drms_uA_update(rdev); |
| 1878 | |
| 1879 | rdev->use_count--; |
| 1880 | } |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1881 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1882 | return ret; |
| 1883 | } |
| 1884 | |
| 1885 | /** |
| 1886 | * regulator_disable - disable regulator output |
| 1887 | * @regulator: regulator source |
| 1888 | * |
Mark Brown | cf7bbcd | 2008-12-31 12:52:43 +0000 | [diff] [blame] | 1889 | * Disable the regulator output voltage or current. Calls to |
| 1890 | * regulator_enable() must be balanced with calls to |
| 1891 | * regulator_disable(). |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 1892 | * |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1893 | * NOTE: this will only disable the regulator output if no other consumer |
Mark Brown | cf7bbcd | 2008-12-31 12:52:43 +0000 | [diff] [blame] | 1894 | * devices have it enabled, the regulator device supports disabling and |
| 1895 | * machine constraints permit this operation. |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1896 | */ |
| 1897 | int regulator_disable(struct regulator *regulator) |
| 1898 | { |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1899 | struct regulator_dev *rdev = regulator->rdev; |
| 1900 | int ret = 0; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1901 | |
Mark Brown | 6492bc1 | 2012-04-19 13:19:07 +0100 | [diff] [blame] | 1902 | if (regulator->always_on) |
| 1903 | return 0; |
| 1904 | |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1905 | mutex_lock(&rdev->mutex); |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1906 | ret = _regulator_disable(rdev); |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 1907 | mutex_unlock(&rdev->mutex); |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1908 | |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1909 | if (ret == 0 && rdev->supply) |
| 1910 | regulator_disable(rdev->supply); |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1911 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1912 | return ret; |
| 1913 | } |
| 1914 | EXPORT_SYMBOL_GPL(regulator_disable); |
| 1915 | |
| 1916 | /* locks held by regulator_force_disable() */ |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1917 | static int _regulator_force_disable(struct regulator_dev *rdev) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1918 | { |
| 1919 | int ret = 0; |
| 1920 | |
| 1921 | /* force disable */ |
| 1922 | if (rdev->desc->ops->disable) { |
| 1923 | /* ah well, who wants to live forever... */ |
| 1924 | ret = rdev->desc->ops->disable(rdev); |
| 1925 | if (ret < 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 1926 | rdev_err(rdev, "failed to force disable\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1927 | return ret; |
| 1928 | } |
| 1929 | /* notify other consumers that power has been forced off */ |
Mark Brown | 84b6826 | 2009-12-01 21:12:27 +0000 | [diff] [blame] | 1930 | _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | |
| 1931 | REGULATOR_EVENT_DISABLE, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1932 | } |
| 1933 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1934 | return ret; |
| 1935 | } |
| 1936 | |
| 1937 | /** |
| 1938 | * regulator_force_disable - force disable regulator output |
| 1939 | * @regulator: regulator source |
| 1940 | * |
| 1941 | * Forcibly disable the regulator output voltage or current. |
| 1942 | * NOTE: this *will* disable the regulator output even if other consumer |
| 1943 | * devices have it enabled. This should be used for situations when device |
| 1944 | * damage will likely occur if the regulator is not disabled (e.g. over temp). |
| 1945 | */ |
| 1946 | int regulator_force_disable(struct regulator *regulator) |
| 1947 | { |
Mark Brown | 82d1583 | 2011-05-09 11:41:02 +0200 | [diff] [blame] | 1948 | struct regulator_dev *rdev = regulator->rdev; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1949 | int ret; |
| 1950 | |
Mark Brown | 82d1583 | 2011-05-09 11:41:02 +0200 | [diff] [blame] | 1951 | mutex_lock(&rdev->mutex); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1952 | regulator->uA_load = 0; |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1953 | ret = _regulator_force_disable(regulator->rdev); |
Mark Brown | 82d1583 | 2011-05-09 11:41:02 +0200 | [diff] [blame] | 1954 | mutex_unlock(&rdev->mutex); |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1955 | |
Mark Brown | 3801b86 | 2011-06-09 16:22:22 +0100 | [diff] [blame] | 1956 | if (rdev->supply) |
| 1957 | while (rdev->open_count--) |
| 1958 | regulator_disable(rdev->supply); |
Jeffrey Carlyle | 8cbf811 | 2010-10-08 14:49:19 -0500 | [diff] [blame] | 1959 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 1960 | return ret; |
| 1961 | } |
| 1962 | EXPORT_SYMBOL_GPL(regulator_force_disable); |
| 1963 | |
Mark Brown | da07ecd | 2011-09-11 09:53:50 +0100 | [diff] [blame] | 1964 | static void regulator_disable_work(struct work_struct *work) |
| 1965 | { |
| 1966 | struct regulator_dev *rdev = container_of(work, struct regulator_dev, |
| 1967 | disable_work.work); |
| 1968 | int count, i, ret; |
| 1969 | |
| 1970 | mutex_lock(&rdev->mutex); |
| 1971 | |
| 1972 | BUG_ON(!rdev->deferred_disables); |
| 1973 | |
| 1974 | count = rdev->deferred_disables; |
| 1975 | rdev->deferred_disables = 0; |
| 1976 | |
| 1977 | for (i = 0; i < count; i++) { |
| 1978 | ret = _regulator_disable(rdev); |
| 1979 | if (ret != 0) |
| 1980 | rdev_err(rdev, "Deferred disable failed: %d\n", ret); |
| 1981 | } |
| 1982 | |
| 1983 | mutex_unlock(&rdev->mutex); |
| 1984 | |
| 1985 | if (rdev->supply) { |
| 1986 | for (i = 0; i < count; i++) { |
| 1987 | ret = regulator_disable(rdev->supply); |
| 1988 | if (ret != 0) { |
| 1989 | rdev_err(rdev, |
| 1990 | "Supply disable failed: %d\n", ret); |
| 1991 | } |
| 1992 | } |
| 1993 | } |
| 1994 | } |
| 1995 | |
| 1996 | /** |
| 1997 | * regulator_disable_deferred - disable regulator output with delay |
| 1998 | * @regulator: regulator source |
| 1999 | * @ms: miliseconds until the regulator is disabled |
| 2000 | * |
| 2001 | * Execute regulator_disable() on the regulator after a delay. This |
| 2002 | * is intended for use with devices that require some time to quiesce. |
| 2003 | * |
| 2004 | * NOTE: this will only disable the regulator output if no other consumer |
| 2005 | * devices have it enabled, the regulator device supports disabling and |
| 2006 | * machine constraints permit this operation. |
| 2007 | */ |
| 2008 | int regulator_disable_deferred(struct regulator *regulator, int ms) |
| 2009 | { |
| 2010 | struct regulator_dev *rdev = regulator->rdev; |
Mark Brown | aa59802 | 2011-10-03 22:42:43 +0100 | [diff] [blame] | 2011 | int ret; |
Mark Brown | da07ecd | 2011-09-11 09:53:50 +0100 | [diff] [blame] | 2012 | |
Mark Brown | 6492bc1 | 2012-04-19 13:19:07 +0100 | [diff] [blame] | 2013 | if (regulator->always_on) |
| 2014 | return 0; |
| 2015 | |
Mark Brown | 2b5a24a | 2012-09-07 11:00:53 +0800 | [diff] [blame] | 2016 | if (!ms) |
| 2017 | return regulator_disable(regulator); |
| 2018 | |
Mark Brown | da07ecd | 2011-09-11 09:53:50 +0100 | [diff] [blame] | 2019 | mutex_lock(&rdev->mutex); |
| 2020 | rdev->deferred_disables++; |
| 2021 | mutex_unlock(&rdev->mutex); |
| 2022 | |
Mark Brown | 070260f | 2013-07-18 11:52:04 +0100 | [diff] [blame] | 2023 | ret = queue_delayed_work(system_power_efficient_wq, |
| 2024 | &rdev->disable_work, |
| 2025 | msecs_to_jiffies(ms)); |
Mark Brown | aa59802 | 2011-10-03 22:42:43 +0100 | [diff] [blame] | 2026 | if (ret < 0) |
| 2027 | return ret; |
| 2028 | else |
| 2029 | return 0; |
Mark Brown | da07ecd | 2011-09-11 09:53:50 +0100 | [diff] [blame] | 2030 | } |
| 2031 | EXPORT_SYMBOL_GPL(regulator_disable_deferred); |
| 2032 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2033 | static int _regulator_is_enabled(struct regulator_dev *rdev) |
| 2034 | { |
Mark Brown | 65f7350 | 2012-06-27 14:14:38 +0100 | [diff] [blame] | 2035 | /* A GPIO control always takes precedence */ |
Kim, Milo | 7b74d14 | 2013-02-18 06:50:55 +0000 | [diff] [blame] | 2036 | if (rdev->ena_pin) |
Mark Brown | 65f7350 | 2012-06-27 14:14:38 +0100 | [diff] [blame] | 2037 | return rdev->ena_gpio_state; |
| 2038 | |
Mark Brown | 9a7f6a4 | 2010-02-11 17:22:45 +0000 | [diff] [blame] | 2039 | /* 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] | 2040 | if (!rdev->desc->ops->is_enabled) |
Mark Brown | 9a7f6a4 | 2010-02-11 17:22:45 +0000 | [diff] [blame] | 2041 | return 1; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2042 | |
Mark Brown | 9332546 | 2009-08-03 18:49:56 +0100 | [diff] [blame] | 2043 | return rdev->desc->ops->is_enabled(rdev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | /** |
| 2047 | * regulator_is_enabled - is the regulator output enabled |
| 2048 | * @regulator: regulator source |
| 2049 | * |
David Brownell | 412aec6 | 2008-11-16 11:44:46 -0800 | [diff] [blame] | 2050 | * Returns positive if the regulator driver backing the source/client |
| 2051 | * has requested that the device be enabled, zero if it hasn't, else a |
| 2052 | * negative errno code. |
| 2053 | * |
| 2054 | * Note that the device backing this regulator handle can have multiple |
| 2055 | * users, so it might be enabled even if regulator_enable() was never |
| 2056 | * called for this particular source. |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2057 | */ |
| 2058 | int regulator_is_enabled(struct regulator *regulator) |
| 2059 | { |
Mark Brown | 9332546 | 2009-08-03 18:49:56 +0100 | [diff] [blame] | 2060 | int ret; |
| 2061 | |
Mark Brown | 6492bc1 | 2012-04-19 13:19:07 +0100 | [diff] [blame] | 2062 | if (regulator->always_on) |
| 2063 | return 1; |
| 2064 | |
Mark Brown | 9332546 | 2009-08-03 18:49:56 +0100 | [diff] [blame] | 2065 | mutex_lock(®ulator->rdev->mutex); |
| 2066 | ret = _regulator_is_enabled(regulator->rdev); |
| 2067 | mutex_unlock(®ulator->rdev->mutex); |
| 2068 | |
| 2069 | return ret; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2070 | } |
| 2071 | EXPORT_SYMBOL_GPL(regulator_is_enabled); |
| 2072 | |
| 2073 | /** |
Marek Szyprowski | d1e7de3 | 2012-12-04 15:01:01 +0100 | [diff] [blame] | 2074 | * regulator_can_change_voltage - check if regulator can change voltage |
| 2075 | * @regulator: regulator source |
| 2076 | * |
| 2077 | * Returns positive if the regulator driver backing the source/client |
| 2078 | * can change its voltage, false otherwise. Usefull for detecting fixed |
| 2079 | * or dummy regulators and disabling voltage change logic in the client |
| 2080 | * driver. |
| 2081 | */ |
| 2082 | int regulator_can_change_voltage(struct regulator *regulator) |
| 2083 | { |
| 2084 | struct regulator_dev *rdev = regulator->rdev; |
| 2085 | |
| 2086 | if (rdev->constraints && |
Axel Lin | 19280e4 | 2012-12-12 09:22:46 +0800 | [diff] [blame] | 2087 | (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { |
| 2088 | if (rdev->desc->n_voltages - rdev->desc->linear_min_sel > 1) |
| 2089 | return 1; |
| 2090 | |
| 2091 | if (rdev->desc->continuous_voltage_range && |
| 2092 | rdev->constraints->min_uV && rdev->constraints->max_uV && |
| 2093 | rdev->constraints->min_uV != rdev->constraints->max_uV) |
| 2094 | return 1; |
| 2095 | } |
Marek Szyprowski | d1e7de3 | 2012-12-04 15:01:01 +0100 | [diff] [blame] | 2096 | |
| 2097 | return 0; |
| 2098 | } |
| 2099 | EXPORT_SYMBOL_GPL(regulator_can_change_voltage); |
| 2100 | |
| 2101 | /** |
David Brownell | 4367cfd | 2009-02-26 11:48:36 -0800 | [diff] [blame] | 2102 | * regulator_count_voltages - count regulator_list_voltage() selectors |
| 2103 | * @regulator: regulator source |
| 2104 | * |
| 2105 | * Returns number of selectors, or negative errno. Selectors are |
| 2106 | * numbered starting at zero, and typically correspond to bitfields |
| 2107 | * in hardware registers. |
| 2108 | */ |
| 2109 | int regulator_count_voltages(struct regulator *regulator) |
| 2110 | { |
| 2111 | struct regulator_dev *rdev = regulator->rdev; |
| 2112 | |
| 2113 | return rdev->desc->n_voltages ? : -EINVAL; |
| 2114 | } |
| 2115 | EXPORT_SYMBOL_GPL(regulator_count_voltages); |
| 2116 | |
| 2117 | /** |
| 2118 | * regulator_list_voltage - enumerate supported voltages |
| 2119 | * @regulator: regulator source |
| 2120 | * @selector: identify voltage to list |
| 2121 | * Context: can sleep |
| 2122 | * |
| 2123 | * Returns a voltage that can be passed to @regulator_set_voltage(), |
Thomas Weber | 8839316 | 2010-03-16 11:47:56 +0100 | [diff] [blame] | 2124 | * 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] | 2125 | * negative errno. |
| 2126 | */ |
| 2127 | int regulator_list_voltage(struct regulator *regulator, unsigned selector) |
| 2128 | { |
| 2129 | struct regulator_dev *rdev = regulator->rdev; |
| 2130 | struct regulator_ops *ops = rdev->desc->ops; |
| 2131 | int ret; |
| 2132 | |
| 2133 | if (!ops->list_voltage || selector >= rdev->desc->n_voltages) |
| 2134 | return -EINVAL; |
| 2135 | |
| 2136 | mutex_lock(&rdev->mutex); |
| 2137 | ret = ops->list_voltage(rdev, selector); |
| 2138 | mutex_unlock(&rdev->mutex); |
| 2139 | |
| 2140 | if (ret > 0) { |
| 2141 | if (ret < rdev->constraints->min_uV) |
| 2142 | ret = 0; |
| 2143 | else if (ret > rdev->constraints->max_uV) |
| 2144 | ret = 0; |
| 2145 | } |
| 2146 | |
| 2147 | return ret; |
| 2148 | } |
| 2149 | EXPORT_SYMBOL_GPL(regulator_list_voltage); |
| 2150 | |
| 2151 | /** |
Paul Walmsley | 2a668a8 | 2013-06-07 08:06:56 +0000 | [diff] [blame] | 2152 | * regulator_get_linear_step - return the voltage step size between VSEL values |
| 2153 | * @regulator: regulator source |
| 2154 | * |
| 2155 | * Returns the voltage step size between VSEL values for linear |
| 2156 | * regulators, or return 0 if the regulator isn't a linear regulator. |
| 2157 | */ |
| 2158 | unsigned int regulator_get_linear_step(struct regulator *regulator) |
| 2159 | { |
| 2160 | struct regulator_dev *rdev = regulator->rdev; |
| 2161 | |
| 2162 | return rdev->desc->uV_step; |
| 2163 | } |
| 2164 | EXPORT_SYMBOL_GPL(regulator_get_linear_step); |
| 2165 | |
| 2166 | /** |
Mark Brown | a7a1ad9 | 2009-07-21 16:00:24 +0100 | [diff] [blame] | 2167 | * regulator_is_supported_voltage - check if a voltage range can be supported |
| 2168 | * |
| 2169 | * @regulator: Regulator to check. |
| 2170 | * @min_uV: Minimum required voltage in uV. |
| 2171 | * @max_uV: Maximum required voltage in uV. |
| 2172 | * |
| 2173 | * Returns a boolean or a negative error code. |
| 2174 | */ |
| 2175 | int regulator_is_supported_voltage(struct regulator *regulator, |
| 2176 | int min_uV, int max_uV) |
| 2177 | { |
Mark Brown | c5f3939 | 2012-07-02 15:00:18 +0100 | [diff] [blame] | 2178 | struct regulator_dev *rdev = regulator->rdev; |
Mark Brown | a7a1ad9 | 2009-07-21 16:00:24 +0100 | [diff] [blame] | 2179 | int i, voltages, ret; |
| 2180 | |
Mark Brown | c5f3939 | 2012-07-02 15:00:18 +0100 | [diff] [blame] | 2181 | /* If we can't change voltage check the current voltage */ |
| 2182 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { |
| 2183 | ret = regulator_get_voltage(regulator); |
| 2184 | if (ret >= 0) |
Marek Szyprowski | f0f98b1 | 2012-11-13 09:48:51 +0100 | [diff] [blame] | 2185 | return (min_uV <= ret && ret <= max_uV); |
Mark Brown | c5f3939 | 2012-07-02 15:00:18 +0100 | [diff] [blame] | 2186 | else |
| 2187 | return ret; |
| 2188 | } |
| 2189 | |
Pawel Moll | bd7a2b6 | 2012-09-24 18:56:53 +0100 | [diff] [blame] | 2190 | /* Any voltage within constrains range is fine? */ |
| 2191 | if (rdev->desc->continuous_voltage_range) |
| 2192 | return min_uV >= rdev->constraints->min_uV && |
| 2193 | max_uV <= rdev->constraints->max_uV; |
| 2194 | |
Mark Brown | a7a1ad9 | 2009-07-21 16:00:24 +0100 | [diff] [blame] | 2195 | ret = regulator_count_voltages(regulator); |
| 2196 | if (ret < 0) |
| 2197 | return ret; |
| 2198 | voltages = ret; |
| 2199 | |
| 2200 | for (i = 0; i < voltages; i++) { |
| 2201 | ret = regulator_list_voltage(regulator, i); |
| 2202 | |
| 2203 | if (ret >= min_uV && ret <= max_uV) |
| 2204 | return 1; |
| 2205 | } |
| 2206 | |
| 2207 | return 0; |
| 2208 | } |
Mark Brown | a398eaa | 2011-12-28 12:48:45 +0000 | [diff] [blame] | 2209 | EXPORT_SYMBOL_GPL(regulator_is_supported_voltage); |
Mark Brown | a7a1ad9 | 2009-07-21 16:00:24 +0100 | [diff] [blame] | 2210 | |
Mark Brown | 7579025 | 2010-12-12 14:25:50 +0000 | [diff] [blame] | 2211 | static int _regulator_do_set_voltage(struct regulator_dev *rdev, |
| 2212 | int min_uV, int max_uV) |
| 2213 | { |
| 2214 | int ret; |
Linus Walleij | 77af1b2 | 2011-03-17 13:24:36 +0100 | [diff] [blame] | 2215 | int delay = 0; |
Mark Brown | e113d79 | 2012-06-26 10:57:51 +0100 | [diff] [blame] | 2216 | int best_val = 0; |
Mark Brown | 7579025 | 2010-12-12 14:25:50 +0000 | [diff] [blame] | 2217 | unsigned int selector; |
Axel Lin | eba41a5 | 2012-04-04 10:32:10 +0800 | [diff] [blame] | 2218 | int old_selector = -1; |
Mark Brown | 7579025 | 2010-12-12 14:25:50 +0000 | [diff] [blame] | 2219 | |
| 2220 | trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV); |
| 2221 | |
Mark Brown | bf5892a | 2011-05-08 22:13:37 +0100 | [diff] [blame] | 2222 | min_uV += rdev->constraints->uV_offset; |
| 2223 | max_uV += rdev->constraints->uV_offset; |
| 2224 | |
Axel Lin | eba41a5 | 2012-04-04 10:32:10 +0800 | [diff] [blame] | 2225 | /* |
| 2226 | * If we can't obtain the old selector there is not enough |
| 2227 | * info to call set_voltage_time_sel(). |
| 2228 | */ |
Axel Lin | 8b7485e | 2012-05-21 09:37:52 +0800 | [diff] [blame] | 2229 | if (_regulator_is_enabled(rdev) && |
| 2230 | rdev->desc->ops->set_voltage_time_sel && |
Axel Lin | eba41a5 | 2012-04-04 10:32:10 +0800 | [diff] [blame] | 2231 | rdev->desc->ops->get_voltage_sel) { |
| 2232 | old_selector = rdev->desc->ops->get_voltage_sel(rdev); |
| 2233 | if (old_selector < 0) |
| 2234 | return old_selector; |
| 2235 | } |
| 2236 | |
Mark Brown | 7579025 | 2010-12-12 14:25:50 +0000 | [diff] [blame] | 2237 | if (rdev->desc->ops->set_voltage) { |
| 2238 | ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, |
| 2239 | &selector); |
Mark Brown | e113d79 | 2012-06-26 10:57:51 +0100 | [diff] [blame] | 2240 | |
| 2241 | if (ret >= 0) { |
| 2242 | if (rdev->desc->ops->list_voltage) |
| 2243 | best_val = rdev->desc->ops->list_voltage(rdev, |
| 2244 | selector); |
| 2245 | else |
| 2246 | best_val = _regulator_get_voltage(rdev); |
| 2247 | } |
| 2248 | |
Mark Brown | e8eef82 | 2010-12-12 14:36:17 +0000 | [diff] [blame] | 2249 | } else if (rdev->desc->ops->set_voltage_sel) { |
Axel Lin | 9152c36 | 2012-06-04 09:41:38 +0800 | [diff] [blame] | 2250 | if (rdev->desc->ops->map_voltage) { |
Mark Brown | e843fc4 | 2012-05-09 21:16:06 +0100 | [diff] [blame] | 2251 | ret = rdev->desc->ops->map_voltage(rdev, min_uV, |
| 2252 | max_uV); |
Axel Lin | 9152c36 | 2012-06-04 09:41:38 +0800 | [diff] [blame] | 2253 | } else { |
| 2254 | if (rdev->desc->ops->list_voltage == |
| 2255 | regulator_list_voltage_linear) |
| 2256 | ret = regulator_map_voltage_linear(rdev, |
| 2257 | min_uV, max_uV); |
| 2258 | else |
| 2259 | ret = regulator_map_voltage_iterate(rdev, |
| 2260 | min_uV, max_uV); |
| 2261 | } |
Mark Brown | e8eef82 | 2010-12-12 14:36:17 +0000 | [diff] [blame] | 2262 | |
Mark Brown | e843fc4 | 2012-05-09 21:16:06 +0100 | [diff] [blame] | 2263 | if (ret >= 0) { |
Mark Brown | e113d79 | 2012-06-26 10:57:51 +0100 | [diff] [blame] | 2264 | best_val = rdev->desc->ops->list_voltage(rdev, ret); |
| 2265 | if (min_uV <= best_val && max_uV >= best_val) { |
| 2266 | selector = ret; |
Axel Lin | c66a566 | 2013-02-06 11:09:48 +0800 | [diff] [blame] | 2267 | if (old_selector == selector) |
| 2268 | ret = 0; |
| 2269 | else |
| 2270 | ret = rdev->desc->ops->set_voltage_sel( |
| 2271 | rdev, ret); |
Mark Brown | e113d79 | 2012-06-26 10:57:51 +0100 | [diff] [blame] | 2272 | } else { |
| 2273 | ret = -EINVAL; |
| 2274 | } |
Mark Brown | e8eef82 | 2010-12-12 14:36:17 +0000 | [diff] [blame] | 2275 | } |
Mark Brown | 7579025 | 2010-12-12 14:25:50 +0000 | [diff] [blame] | 2276 | } else { |
| 2277 | ret = -EINVAL; |
| 2278 | } |
| 2279 | |
Axel Lin | eba41a5 | 2012-04-04 10:32:10 +0800 | [diff] [blame] | 2280 | /* Call set_voltage_time_sel if successfully obtained old_selector */ |
Yadwinder Singh Brar | 5b17595 | 2013-06-29 18:21:19 +0530 | [diff] [blame] | 2281 | if (ret == 0 && !rdev->constraints->ramp_disable && old_selector >= 0 |
| 2282 | && old_selector != selector) { |
Axel Lin | eba41a5 | 2012-04-04 10:32:10 +0800 | [diff] [blame] | 2283 | |
| 2284 | delay = rdev->desc->ops->set_voltage_time_sel(rdev, |
| 2285 | old_selector, selector); |
| 2286 | if (delay < 0) { |
| 2287 | rdev_warn(rdev, "set_voltage_time_sel() failed: %d\n", |
| 2288 | delay); |
| 2289 | delay = 0; |
| 2290 | } |
Axel Lin | eba41a5 | 2012-04-04 10:32:10 +0800 | [diff] [blame] | 2291 | |
Philip Rakity | 8b96de3 | 2012-06-14 15:07:56 -0700 | [diff] [blame] | 2292 | /* Insert any necessary delays */ |
| 2293 | if (delay >= 1000) { |
| 2294 | mdelay(delay / 1000); |
| 2295 | udelay(delay % 1000); |
| 2296 | } else if (delay) { |
| 2297 | udelay(delay); |
| 2298 | } |
Linus Walleij | 77af1b2 | 2011-03-17 13:24:36 +0100 | [diff] [blame] | 2299 | } |
| 2300 | |
Axel Lin | 2f6c797 | 2012-08-06 23:44:19 +0800 | [diff] [blame] | 2301 | if (ret == 0 && best_val >= 0) { |
| 2302 | unsigned long data = best_val; |
| 2303 | |
Mark Brown | ded06a5 | 2010-12-16 13:59:10 +0000 | [diff] [blame] | 2304 | _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, |
Axel Lin | 2f6c797 | 2012-08-06 23:44:19 +0800 | [diff] [blame] | 2305 | (void *)data); |
| 2306 | } |
Mark Brown | ded06a5 | 2010-12-16 13:59:10 +0000 | [diff] [blame] | 2307 | |
Axel Lin | eba41a5 | 2012-04-04 10:32:10 +0800 | [diff] [blame] | 2308 | trace_regulator_set_voltage_complete(rdev_get_name(rdev), best_val); |
Mark Brown | 7579025 | 2010-12-12 14:25:50 +0000 | [diff] [blame] | 2309 | |
| 2310 | return ret; |
| 2311 | } |
| 2312 | |
Mark Brown | a7a1ad9 | 2009-07-21 16:00:24 +0100 | [diff] [blame] | 2313 | /** |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2314 | * regulator_set_voltage - set regulator output voltage |
| 2315 | * @regulator: regulator source |
| 2316 | * @min_uV: Minimum required voltage in uV |
| 2317 | * @max_uV: Maximum acceptable voltage in uV |
| 2318 | * |
| 2319 | * Sets a voltage regulator to the desired output voltage. This can be set |
| 2320 | * during any regulator state. IOW, regulator can be disabled or enabled. |
| 2321 | * |
| 2322 | * If the regulator is enabled then the voltage will change to the new value |
| 2323 | * immediately otherwise if the regulator is disabled the regulator will |
| 2324 | * output at the new voltage when enabled. |
| 2325 | * |
| 2326 | * NOTE: If the regulator is shared between several devices then the lowest |
| 2327 | * request voltage that meets the system constraints will be used. |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 2328 | * Regulator system constraints must be set for this regulator before |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2329 | * calling this function otherwise this call will fail. |
| 2330 | */ |
| 2331 | int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) |
| 2332 | { |
| 2333 | struct regulator_dev *rdev = regulator->rdev; |
Mark Brown | 95a3c23 | 2010-12-16 15:49:37 +0000 | [diff] [blame] | 2334 | int ret = 0; |
Paolo Pisati | 92d7a55 | 2012-12-13 10:13:00 +0100 | [diff] [blame] | 2335 | int old_min_uV, old_max_uV; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2336 | |
| 2337 | mutex_lock(&rdev->mutex); |
| 2338 | |
Mark Brown | 95a3c23 | 2010-12-16 15:49:37 +0000 | [diff] [blame] | 2339 | /* If we're setting the same range as last time the change |
| 2340 | * should be a noop (some cpufreq implementations use the same |
| 2341 | * voltage for multiple frequencies, for example). |
| 2342 | */ |
| 2343 | if (regulator->min_uV == min_uV && regulator->max_uV == max_uV) |
| 2344 | goto out; |
| 2345 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2346 | /* sanity check */ |
Mark Brown | e8eef82 | 2010-12-12 14:36:17 +0000 | [diff] [blame] | 2347 | if (!rdev->desc->ops->set_voltage && |
| 2348 | !rdev->desc->ops->set_voltage_sel) { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2349 | ret = -EINVAL; |
| 2350 | goto out; |
| 2351 | } |
| 2352 | |
| 2353 | /* constraints check */ |
| 2354 | ret = regulator_check_voltage(rdev, &min_uV, &max_uV); |
| 2355 | if (ret < 0) |
| 2356 | goto out; |
Paolo Pisati | 92d7a55 | 2012-12-13 10:13:00 +0100 | [diff] [blame] | 2357 | |
| 2358 | /* restore original values in case of error */ |
| 2359 | old_min_uV = regulator->min_uV; |
| 2360 | old_max_uV = regulator->max_uV; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2361 | regulator->min_uV = min_uV; |
| 2362 | regulator->max_uV = max_uV; |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 2363 | |
Thomas Petazzoni | 05fda3b1a | 2010-12-03 11:31:07 +0100 | [diff] [blame] | 2364 | ret = regulator_check_consumers(rdev, &min_uV, &max_uV); |
| 2365 | if (ret < 0) |
Paolo Pisati | 92d7a55 | 2012-12-13 10:13:00 +0100 | [diff] [blame] | 2366 | goto out2; |
Thomas Petazzoni | 05fda3b1a | 2010-12-03 11:31:07 +0100 | [diff] [blame] | 2367 | |
Mark Brown | 7579025 | 2010-12-12 14:25:50 +0000 | [diff] [blame] | 2368 | ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); |
Paolo Pisati | 92d7a55 | 2012-12-13 10:13:00 +0100 | [diff] [blame] | 2369 | if (ret < 0) |
| 2370 | goto out2; |
| 2371 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2372 | out: |
| 2373 | mutex_unlock(&rdev->mutex); |
| 2374 | return ret; |
Paolo Pisati | 92d7a55 | 2012-12-13 10:13:00 +0100 | [diff] [blame] | 2375 | out2: |
| 2376 | regulator->min_uV = old_min_uV; |
| 2377 | regulator->max_uV = old_max_uV; |
| 2378 | mutex_unlock(&rdev->mutex); |
| 2379 | return ret; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2380 | } |
| 2381 | EXPORT_SYMBOL_GPL(regulator_set_voltage); |
| 2382 | |
Mark Brown | 606a256 | 2010-12-16 15:49:36 +0000 | [diff] [blame] | 2383 | /** |
Linus Walleij | 88cd222b | 2011-03-17 13:24:52 +0100 | [diff] [blame] | 2384 | * regulator_set_voltage_time - get raise/fall time |
| 2385 | * @regulator: regulator source |
| 2386 | * @old_uV: starting voltage in microvolts |
| 2387 | * @new_uV: target voltage in microvolts |
| 2388 | * |
| 2389 | * Provided with the starting and ending voltage, this function attempts to |
| 2390 | * calculate the time in microseconds required to rise or fall to this new |
| 2391 | * voltage. |
| 2392 | */ |
| 2393 | int regulator_set_voltage_time(struct regulator *regulator, |
| 2394 | int old_uV, int new_uV) |
| 2395 | { |
| 2396 | struct regulator_dev *rdev = regulator->rdev; |
| 2397 | struct regulator_ops *ops = rdev->desc->ops; |
| 2398 | int old_sel = -1; |
| 2399 | int new_sel = -1; |
| 2400 | int voltage; |
| 2401 | int i; |
| 2402 | |
| 2403 | /* Currently requires operations to do this */ |
| 2404 | if (!ops->list_voltage || !ops->set_voltage_time_sel |
| 2405 | || !rdev->desc->n_voltages) |
| 2406 | return -EINVAL; |
| 2407 | |
| 2408 | for (i = 0; i < rdev->desc->n_voltages; i++) { |
| 2409 | /* We only look for exact voltage matches here */ |
| 2410 | voltage = regulator_list_voltage(regulator, i); |
| 2411 | if (voltage < 0) |
| 2412 | return -EINVAL; |
| 2413 | if (voltage == 0) |
| 2414 | continue; |
| 2415 | if (voltage == old_uV) |
| 2416 | old_sel = i; |
| 2417 | if (voltage == new_uV) |
| 2418 | new_sel = i; |
| 2419 | } |
| 2420 | |
| 2421 | if (old_sel < 0 || new_sel < 0) |
| 2422 | return -EINVAL; |
| 2423 | |
| 2424 | return ops->set_voltage_time_sel(rdev, old_sel, new_sel); |
| 2425 | } |
| 2426 | EXPORT_SYMBOL_GPL(regulator_set_voltage_time); |
| 2427 | |
| 2428 | /** |
Randy Dunlap | 296c656 | 2012-08-18 17:44:14 -0700 | [diff] [blame] | 2429 | * regulator_set_voltage_time_sel - get raise/fall time |
| 2430 | * @rdev: regulator source device |
Yadwinder Singh Brar | 98a175b | 2012-06-09 16:40:38 +0530 | [diff] [blame] | 2431 | * @old_selector: selector for starting voltage |
| 2432 | * @new_selector: selector for target voltage |
| 2433 | * |
| 2434 | * Provided with the starting and target voltage selectors, this function |
| 2435 | * returns time in microseconds required to rise or fall to this new voltage |
| 2436 | * |
Axel Lin | f11d08c | 2012-06-19 09:38:45 +0800 | [diff] [blame] | 2437 | * Drivers providing ramp_delay in regulation_constraints can use this as their |
Axel Lin | 398715a | 2012-06-18 10:11:28 +0800 | [diff] [blame] | 2438 | * set_voltage_time_sel() operation. |
Yadwinder Singh Brar | 98a175b | 2012-06-09 16:40:38 +0530 | [diff] [blame] | 2439 | */ |
| 2440 | int regulator_set_voltage_time_sel(struct regulator_dev *rdev, |
| 2441 | unsigned int old_selector, |
| 2442 | unsigned int new_selector) |
| 2443 | { |
Axel Lin | 398715a | 2012-06-18 10:11:28 +0800 | [diff] [blame] | 2444 | unsigned int ramp_delay = 0; |
Axel Lin | f11d08c | 2012-06-19 09:38:45 +0800 | [diff] [blame] | 2445 | int old_volt, new_volt; |
Axel Lin | 398715a | 2012-06-18 10:11:28 +0800 | [diff] [blame] | 2446 | |
| 2447 | if (rdev->constraints->ramp_delay) |
| 2448 | ramp_delay = rdev->constraints->ramp_delay; |
| 2449 | else if (rdev->desc->ramp_delay) |
| 2450 | ramp_delay = rdev->desc->ramp_delay; |
| 2451 | |
| 2452 | if (ramp_delay == 0) { |
Yadwinder Singh Brar | 6f0b2c6 | 2012-06-11 17:41:08 +0530 | [diff] [blame] | 2453 | rdev_warn(rdev, "ramp_delay not set\n"); |
Axel Lin | 398715a | 2012-06-18 10:11:28 +0800 | [diff] [blame] | 2454 | return 0; |
Yadwinder Singh Brar | 6f0b2c6 | 2012-06-11 17:41:08 +0530 | [diff] [blame] | 2455 | } |
Axel Lin | 398715a | 2012-06-18 10:11:28 +0800 | [diff] [blame] | 2456 | |
Axel Lin | f11d08c | 2012-06-19 09:38:45 +0800 | [diff] [blame] | 2457 | /* sanity check */ |
| 2458 | if (!rdev->desc->ops->list_voltage) |
| 2459 | return -EINVAL; |
Axel Lin | 398715a | 2012-06-18 10:11:28 +0800 | [diff] [blame] | 2460 | |
Axel Lin | f11d08c | 2012-06-19 09:38:45 +0800 | [diff] [blame] | 2461 | old_volt = rdev->desc->ops->list_voltage(rdev, old_selector); |
| 2462 | new_volt = rdev->desc->ops->list_voltage(rdev, new_selector); |
| 2463 | |
| 2464 | return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay); |
Yadwinder Singh Brar | 98a175b | 2012-06-09 16:40:38 +0530 | [diff] [blame] | 2465 | } |
Mark Brown | b19dbf7 | 2012-06-23 11:34:20 +0100 | [diff] [blame] | 2466 | EXPORT_SYMBOL_GPL(regulator_set_voltage_time_sel); |
Yadwinder Singh Brar | 98a175b | 2012-06-09 16:40:38 +0530 | [diff] [blame] | 2467 | |
| 2468 | /** |
Mark Brown | 606a256 | 2010-12-16 15:49:36 +0000 | [diff] [blame] | 2469 | * regulator_sync_voltage - re-apply last regulator output voltage |
| 2470 | * @regulator: regulator source |
| 2471 | * |
| 2472 | * Re-apply the last configured voltage. This is intended to be used |
| 2473 | * where some external control source the consumer is cooperating with |
| 2474 | * has caused the configured voltage to change. |
| 2475 | */ |
| 2476 | int regulator_sync_voltage(struct regulator *regulator) |
| 2477 | { |
| 2478 | struct regulator_dev *rdev = regulator->rdev; |
| 2479 | int ret, min_uV, max_uV; |
| 2480 | |
| 2481 | mutex_lock(&rdev->mutex); |
| 2482 | |
| 2483 | if (!rdev->desc->ops->set_voltage && |
| 2484 | !rdev->desc->ops->set_voltage_sel) { |
| 2485 | ret = -EINVAL; |
| 2486 | goto out; |
| 2487 | } |
| 2488 | |
| 2489 | /* This is only going to work if we've had a voltage configured. */ |
| 2490 | if (!regulator->min_uV && !regulator->max_uV) { |
| 2491 | ret = -EINVAL; |
| 2492 | goto out; |
| 2493 | } |
| 2494 | |
| 2495 | min_uV = regulator->min_uV; |
| 2496 | max_uV = regulator->max_uV; |
| 2497 | |
| 2498 | /* This should be a paranoia check... */ |
| 2499 | ret = regulator_check_voltage(rdev, &min_uV, &max_uV); |
| 2500 | if (ret < 0) |
| 2501 | goto out; |
| 2502 | |
| 2503 | ret = regulator_check_consumers(rdev, &min_uV, &max_uV); |
| 2504 | if (ret < 0) |
| 2505 | goto out; |
| 2506 | |
| 2507 | ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); |
| 2508 | |
| 2509 | out: |
| 2510 | mutex_unlock(&rdev->mutex); |
| 2511 | return ret; |
| 2512 | } |
| 2513 | EXPORT_SYMBOL_GPL(regulator_sync_voltage); |
| 2514 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2515 | static int _regulator_get_voltage(struct regulator_dev *rdev) |
| 2516 | { |
Mark Brown | bf5892a | 2011-05-08 22:13:37 +0100 | [diff] [blame] | 2517 | int sel, ret; |
Mark Brown | 476c2d8 | 2010-12-10 17:28:07 +0000 | [diff] [blame] | 2518 | |
| 2519 | if (rdev->desc->ops->get_voltage_sel) { |
| 2520 | sel = rdev->desc->ops->get_voltage_sel(rdev); |
| 2521 | if (sel < 0) |
| 2522 | return sel; |
Mark Brown | bf5892a | 2011-05-08 22:13:37 +0100 | [diff] [blame] | 2523 | ret = rdev->desc->ops->list_voltage(rdev, sel); |
Axel Lin | cb220d1 | 2011-05-23 20:08:10 +0800 | [diff] [blame] | 2524 | } else if (rdev->desc->ops->get_voltage) { |
Mark Brown | bf5892a | 2011-05-08 22:13:37 +0100 | [diff] [blame] | 2525 | ret = rdev->desc->ops->get_voltage(rdev); |
Mark Brown | f7df20e | 2012-08-09 16:42:19 +0100 | [diff] [blame] | 2526 | } else if (rdev->desc->ops->list_voltage) { |
| 2527 | ret = rdev->desc->ops->list_voltage(rdev, 0); |
Axel Lin | cb220d1 | 2011-05-23 20:08:10 +0800 | [diff] [blame] | 2528 | } else { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2529 | return -EINVAL; |
Axel Lin | cb220d1 | 2011-05-23 20:08:10 +0800 | [diff] [blame] | 2530 | } |
Mark Brown | bf5892a | 2011-05-08 22:13:37 +0100 | [diff] [blame] | 2531 | |
Axel Lin | cb220d1 | 2011-05-23 20:08:10 +0800 | [diff] [blame] | 2532 | if (ret < 0) |
| 2533 | return ret; |
Mark Brown | bf5892a | 2011-05-08 22:13:37 +0100 | [diff] [blame] | 2534 | return ret - rdev->constraints->uV_offset; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | /** |
| 2538 | * regulator_get_voltage - get regulator output voltage |
| 2539 | * @regulator: regulator source |
| 2540 | * |
| 2541 | * This returns the current regulator voltage in uV. |
| 2542 | * |
| 2543 | * NOTE: If the regulator is disabled it will return the voltage value. This |
| 2544 | * function should not be used to determine regulator state. |
| 2545 | */ |
| 2546 | int regulator_get_voltage(struct regulator *regulator) |
| 2547 | { |
| 2548 | int ret; |
| 2549 | |
| 2550 | mutex_lock(®ulator->rdev->mutex); |
| 2551 | |
| 2552 | ret = _regulator_get_voltage(regulator->rdev); |
| 2553 | |
| 2554 | mutex_unlock(®ulator->rdev->mutex); |
| 2555 | |
| 2556 | return ret; |
| 2557 | } |
| 2558 | EXPORT_SYMBOL_GPL(regulator_get_voltage); |
| 2559 | |
| 2560 | /** |
| 2561 | * regulator_set_current_limit - set regulator output current limit |
| 2562 | * @regulator: regulator source |
Charles Keepax | ce0d10f | 2013-05-21 15:04:07 +0100 | [diff] [blame] | 2563 | * @min_uA: Minimum supported current in uA |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2564 | * @max_uA: Maximum supported current in uA |
| 2565 | * |
| 2566 | * Sets current sink to the desired output current. This can be set during |
| 2567 | * any regulator state. IOW, regulator can be disabled or enabled. |
| 2568 | * |
| 2569 | * If the regulator is enabled then the current will change to the new value |
| 2570 | * immediately otherwise if the regulator is disabled the regulator will |
| 2571 | * output at the new current when enabled. |
| 2572 | * |
| 2573 | * NOTE: Regulator system constraints must be set for this regulator before |
| 2574 | * calling this function otherwise this call will fail. |
| 2575 | */ |
| 2576 | int regulator_set_current_limit(struct regulator *regulator, |
| 2577 | int min_uA, int max_uA) |
| 2578 | { |
| 2579 | struct regulator_dev *rdev = regulator->rdev; |
| 2580 | int ret; |
| 2581 | |
| 2582 | mutex_lock(&rdev->mutex); |
| 2583 | |
| 2584 | /* sanity check */ |
| 2585 | if (!rdev->desc->ops->set_current_limit) { |
| 2586 | ret = -EINVAL; |
| 2587 | goto out; |
| 2588 | } |
| 2589 | |
| 2590 | /* constraints check */ |
| 2591 | ret = regulator_check_current_limit(rdev, &min_uA, &max_uA); |
| 2592 | if (ret < 0) |
| 2593 | goto out; |
| 2594 | |
| 2595 | ret = rdev->desc->ops->set_current_limit(rdev, min_uA, max_uA); |
| 2596 | out: |
| 2597 | mutex_unlock(&rdev->mutex); |
| 2598 | return ret; |
| 2599 | } |
| 2600 | EXPORT_SYMBOL_GPL(regulator_set_current_limit); |
| 2601 | |
| 2602 | static int _regulator_get_current_limit(struct regulator_dev *rdev) |
| 2603 | { |
| 2604 | int ret; |
| 2605 | |
| 2606 | mutex_lock(&rdev->mutex); |
| 2607 | |
| 2608 | /* sanity check */ |
| 2609 | if (!rdev->desc->ops->get_current_limit) { |
| 2610 | ret = -EINVAL; |
| 2611 | goto out; |
| 2612 | } |
| 2613 | |
| 2614 | ret = rdev->desc->ops->get_current_limit(rdev); |
| 2615 | out: |
| 2616 | mutex_unlock(&rdev->mutex); |
| 2617 | return ret; |
| 2618 | } |
| 2619 | |
| 2620 | /** |
| 2621 | * regulator_get_current_limit - get regulator output current |
| 2622 | * @regulator: regulator source |
| 2623 | * |
| 2624 | * This returns the current supplied by the specified current sink in uA. |
| 2625 | * |
| 2626 | * NOTE: If the regulator is disabled it will return the current value. This |
| 2627 | * function should not be used to determine regulator state. |
| 2628 | */ |
| 2629 | int regulator_get_current_limit(struct regulator *regulator) |
| 2630 | { |
| 2631 | return _regulator_get_current_limit(regulator->rdev); |
| 2632 | } |
| 2633 | EXPORT_SYMBOL_GPL(regulator_get_current_limit); |
| 2634 | |
| 2635 | /** |
| 2636 | * regulator_set_mode - set regulator operating mode |
| 2637 | * @regulator: regulator source |
| 2638 | * @mode: operating mode - one of the REGULATOR_MODE constants |
| 2639 | * |
| 2640 | * Set regulator operating mode to increase regulator efficiency or improve |
| 2641 | * regulation performance. |
| 2642 | * |
| 2643 | * NOTE: Regulator system constraints must be set for this regulator before |
| 2644 | * calling this function otherwise this call will fail. |
| 2645 | */ |
| 2646 | int regulator_set_mode(struct regulator *regulator, unsigned int mode) |
| 2647 | { |
| 2648 | struct regulator_dev *rdev = regulator->rdev; |
| 2649 | int ret; |
Sundar R Iyer | 500b4ac | 2010-05-17 21:24:48 +0530 | [diff] [blame] | 2650 | int regulator_curr_mode; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2651 | |
| 2652 | mutex_lock(&rdev->mutex); |
| 2653 | |
| 2654 | /* sanity check */ |
| 2655 | if (!rdev->desc->ops->set_mode) { |
| 2656 | ret = -EINVAL; |
| 2657 | goto out; |
| 2658 | } |
| 2659 | |
Sundar R Iyer | 500b4ac | 2010-05-17 21:24:48 +0530 | [diff] [blame] | 2660 | /* return if the same mode is requested */ |
| 2661 | if (rdev->desc->ops->get_mode) { |
| 2662 | regulator_curr_mode = rdev->desc->ops->get_mode(rdev); |
| 2663 | if (regulator_curr_mode == mode) { |
| 2664 | ret = 0; |
| 2665 | goto out; |
| 2666 | } |
| 2667 | } |
| 2668 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2669 | /* constraints check */ |
Axel Lin | 22c51b4 | 2011-04-01 18:25:25 +0800 | [diff] [blame] | 2670 | ret = regulator_mode_constrain(rdev, &mode); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2671 | if (ret < 0) |
| 2672 | goto out; |
| 2673 | |
| 2674 | ret = rdev->desc->ops->set_mode(rdev, mode); |
| 2675 | out: |
| 2676 | mutex_unlock(&rdev->mutex); |
| 2677 | return ret; |
| 2678 | } |
| 2679 | EXPORT_SYMBOL_GPL(regulator_set_mode); |
| 2680 | |
| 2681 | static unsigned int _regulator_get_mode(struct regulator_dev *rdev) |
| 2682 | { |
| 2683 | int ret; |
| 2684 | |
| 2685 | mutex_lock(&rdev->mutex); |
| 2686 | |
| 2687 | /* sanity check */ |
| 2688 | if (!rdev->desc->ops->get_mode) { |
| 2689 | ret = -EINVAL; |
| 2690 | goto out; |
| 2691 | } |
| 2692 | |
| 2693 | ret = rdev->desc->ops->get_mode(rdev); |
| 2694 | out: |
| 2695 | mutex_unlock(&rdev->mutex); |
| 2696 | return ret; |
| 2697 | } |
| 2698 | |
| 2699 | /** |
| 2700 | * regulator_get_mode - get regulator operating mode |
| 2701 | * @regulator: regulator source |
| 2702 | * |
| 2703 | * Get the current regulator operating mode. |
| 2704 | */ |
| 2705 | unsigned int regulator_get_mode(struct regulator *regulator) |
| 2706 | { |
| 2707 | return _regulator_get_mode(regulator->rdev); |
| 2708 | } |
| 2709 | EXPORT_SYMBOL_GPL(regulator_get_mode); |
| 2710 | |
| 2711 | /** |
| 2712 | * regulator_set_optimum_mode - set regulator optimum operating mode |
| 2713 | * @regulator: regulator source |
| 2714 | * @uA_load: load current |
| 2715 | * |
| 2716 | * Notifies the regulator core of a new device load. This is then used by |
| 2717 | * DRMS (if enabled by constraints) to set the most efficient regulator |
| 2718 | * operating mode for the new regulator loading. |
| 2719 | * |
| 2720 | * Consumer devices notify their supply regulator of the maximum power |
| 2721 | * they will require (can be taken from device datasheet in the power |
| 2722 | * consumption tables) when they change operational status and hence power |
| 2723 | * state. Examples of operational state changes that can affect power |
| 2724 | * consumption are :- |
| 2725 | * |
| 2726 | * o Device is opened / closed. |
| 2727 | * o Device I/O is about to begin or has just finished. |
| 2728 | * o Device is idling in between work. |
| 2729 | * |
| 2730 | * This information is also exported via sysfs to userspace. |
| 2731 | * |
| 2732 | * DRMS will sum the total requested load on the regulator and change |
| 2733 | * to the most efficient operating mode if platform constraints allow. |
| 2734 | * |
| 2735 | * Returns the new regulator mode or error. |
| 2736 | */ |
| 2737 | int regulator_set_optimum_mode(struct regulator *regulator, int uA_load) |
| 2738 | { |
| 2739 | struct regulator_dev *rdev = regulator->rdev; |
| 2740 | struct regulator *consumer; |
Stephen Boyd | d92d95b6 | 2012-07-02 19:21:06 -0700 | [diff] [blame] | 2741 | int ret, output_uV, input_uV = 0, total_uA_load = 0; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2742 | unsigned int mode; |
| 2743 | |
Stephen Boyd | d92d95b6 | 2012-07-02 19:21:06 -0700 | [diff] [blame] | 2744 | if (rdev->supply) |
| 2745 | input_uV = regulator_get_voltage(rdev->supply); |
| 2746 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2747 | mutex_lock(&rdev->mutex); |
| 2748 | |
Mark Brown | a4b4148 | 2011-05-14 11:19:45 -0700 | [diff] [blame] | 2749 | /* |
| 2750 | * first check to see if we can set modes at all, otherwise just |
| 2751 | * tell the consumer everything is OK. |
| 2752 | */ |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2753 | regulator->uA_load = uA_load; |
| 2754 | ret = regulator_check_drms(rdev); |
Mark Brown | a4b4148 | 2011-05-14 11:19:45 -0700 | [diff] [blame] | 2755 | if (ret < 0) { |
| 2756 | ret = 0; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2757 | goto out; |
Mark Brown | a4b4148 | 2011-05-14 11:19:45 -0700 | [diff] [blame] | 2758 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2759 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2760 | if (!rdev->desc->ops->get_optimum_mode) |
| 2761 | goto out; |
| 2762 | |
Mark Brown | a4b4148 | 2011-05-14 11:19:45 -0700 | [diff] [blame] | 2763 | /* |
| 2764 | * we can actually do this so any errors are indicators of |
| 2765 | * potential real failure. |
| 2766 | */ |
| 2767 | ret = -EINVAL; |
| 2768 | |
Axel Lin | 854ccba | 2012-04-16 18:44:23 +0800 | [diff] [blame] | 2769 | if (!rdev->desc->ops->set_mode) |
| 2770 | goto out; |
| 2771 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2772 | /* get output voltage */ |
Mark Brown | 1bf5a1f | 2010-12-10 17:28:06 +0000 | [diff] [blame] | 2773 | output_uV = _regulator_get_voltage(rdev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2774 | if (output_uV <= 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 2775 | rdev_err(rdev, "invalid output voltage found\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2776 | goto out; |
| 2777 | } |
| 2778 | |
Stephen Boyd | d92d95b6 | 2012-07-02 19:21:06 -0700 | [diff] [blame] | 2779 | /* No supply? Use constraint voltage */ |
Mark Brown | 1bf5a1f | 2010-12-10 17:28:06 +0000 | [diff] [blame] | 2780 | if (input_uV <= 0) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2781 | input_uV = rdev->constraints->input_uV; |
| 2782 | if (input_uV <= 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 2783 | rdev_err(rdev, "invalid input voltage found\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2784 | goto out; |
| 2785 | } |
| 2786 | |
| 2787 | /* calc total requested load for this regulator */ |
| 2788 | list_for_each_entry(consumer, &rdev->consumer_list, list) |
Stefan Roese | fa2984d | 2009-11-27 15:56:34 +0100 | [diff] [blame] | 2789 | total_uA_load += consumer->uA_load; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2790 | |
| 2791 | mode = rdev->desc->ops->get_optimum_mode(rdev, |
| 2792 | input_uV, output_uV, |
| 2793 | total_uA_load); |
Mark Brown | 2c60823 | 2011-03-30 06:29:12 +0900 | [diff] [blame] | 2794 | ret = regulator_mode_constrain(rdev, &mode); |
David Brownell | e573520 | 2008-11-16 11:46:56 -0800 | [diff] [blame] | 2795 | if (ret < 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 2796 | rdev_err(rdev, "failed to get optimum mode @ %d uA %d -> %d uV\n", |
| 2797 | total_uA_load, input_uV, output_uV); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2798 | goto out; |
| 2799 | } |
| 2800 | |
| 2801 | ret = rdev->desc->ops->set_mode(rdev, mode); |
David Brownell | e573520 | 2008-11-16 11:46:56 -0800 | [diff] [blame] | 2802 | if (ret < 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 2803 | rdev_err(rdev, "failed to set optimum mode %x\n", mode); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2804 | goto out; |
| 2805 | } |
| 2806 | ret = mode; |
| 2807 | out: |
| 2808 | mutex_unlock(&rdev->mutex); |
| 2809 | return ret; |
| 2810 | } |
| 2811 | EXPORT_SYMBOL_GPL(regulator_set_optimum_mode); |
| 2812 | |
| 2813 | /** |
Mark Brown | f59c8f9 | 2012-08-31 10:36:37 -0700 | [diff] [blame] | 2814 | * regulator_allow_bypass - allow the regulator to go into bypass mode |
| 2815 | * |
| 2816 | * @regulator: Regulator to configure |
Nishanth Menon | 9345dfb | 2013-02-28 18:44:54 -0600 | [diff] [blame] | 2817 | * @enable: enable or disable bypass mode |
Mark Brown | f59c8f9 | 2012-08-31 10:36:37 -0700 | [diff] [blame] | 2818 | * |
| 2819 | * Allow the regulator to go into bypass mode if all other consumers |
| 2820 | * for the regulator also enable bypass mode and the machine |
| 2821 | * constraints allow this. Bypass mode means that the regulator is |
| 2822 | * simply passing the input directly to the output with no regulation. |
| 2823 | */ |
| 2824 | int regulator_allow_bypass(struct regulator *regulator, bool enable) |
| 2825 | { |
| 2826 | struct regulator_dev *rdev = regulator->rdev; |
| 2827 | int ret = 0; |
| 2828 | |
| 2829 | if (!rdev->desc->ops->set_bypass) |
| 2830 | return 0; |
| 2831 | |
| 2832 | if (rdev->constraints && |
| 2833 | !(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_BYPASS)) |
| 2834 | return 0; |
| 2835 | |
| 2836 | mutex_lock(&rdev->mutex); |
| 2837 | |
| 2838 | if (enable && !regulator->bypass) { |
| 2839 | rdev->bypass_count++; |
| 2840 | |
| 2841 | if (rdev->bypass_count == rdev->open_count) { |
| 2842 | ret = rdev->desc->ops->set_bypass(rdev, enable); |
| 2843 | if (ret != 0) |
| 2844 | rdev->bypass_count--; |
| 2845 | } |
| 2846 | |
| 2847 | } else if (!enable && regulator->bypass) { |
| 2848 | rdev->bypass_count--; |
| 2849 | |
| 2850 | if (rdev->bypass_count != rdev->open_count) { |
| 2851 | ret = rdev->desc->ops->set_bypass(rdev, enable); |
| 2852 | if (ret != 0) |
| 2853 | rdev->bypass_count++; |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | if (ret == 0) |
| 2858 | regulator->bypass = enable; |
| 2859 | |
| 2860 | mutex_unlock(&rdev->mutex); |
| 2861 | |
| 2862 | return ret; |
| 2863 | } |
| 2864 | EXPORT_SYMBOL_GPL(regulator_allow_bypass); |
| 2865 | |
| 2866 | /** |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2867 | * regulator_register_notifier - register regulator event notifier |
| 2868 | * @regulator: regulator source |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 2869 | * @nb: notifier block |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2870 | * |
| 2871 | * Register notifier block to receive regulator events. |
| 2872 | */ |
| 2873 | int regulator_register_notifier(struct regulator *regulator, |
| 2874 | struct notifier_block *nb) |
| 2875 | { |
| 2876 | return blocking_notifier_chain_register(®ulator->rdev->notifier, |
| 2877 | nb); |
| 2878 | } |
| 2879 | EXPORT_SYMBOL_GPL(regulator_register_notifier); |
| 2880 | |
| 2881 | /** |
| 2882 | * regulator_unregister_notifier - unregister regulator event notifier |
| 2883 | * @regulator: regulator source |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 2884 | * @nb: notifier block |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2885 | * |
| 2886 | * Unregister regulator event notifier block. |
| 2887 | */ |
| 2888 | int regulator_unregister_notifier(struct regulator *regulator, |
| 2889 | struct notifier_block *nb) |
| 2890 | { |
| 2891 | return blocking_notifier_chain_unregister(®ulator->rdev->notifier, |
| 2892 | nb); |
| 2893 | } |
| 2894 | EXPORT_SYMBOL_GPL(regulator_unregister_notifier); |
| 2895 | |
Jonathan Cameron | b136fb4 | 2009-01-19 18:20:58 +0000 | [diff] [blame] | 2896 | /* notify regulator consumers and downstream regulator consumers. |
| 2897 | * Note mutex must be held by caller. |
| 2898 | */ |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2899 | static void _notifier_call_chain(struct regulator_dev *rdev, |
| 2900 | unsigned long event, void *data) |
| 2901 | { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2902 | /* call rdev chain first */ |
Mark Brown | d8493d2 | 2012-06-15 19:09:09 +0100 | [diff] [blame] | 2903 | blocking_notifier_call_chain(&rdev->notifier, event, data); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2904 | } |
| 2905 | |
| 2906 | /** |
| 2907 | * regulator_bulk_get - get multiple regulator consumers |
| 2908 | * |
| 2909 | * @dev: Device to supply |
| 2910 | * @num_consumers: Number of consumers to register |
| 2911 | * @consumers: Configuration of consumers; clients are stored here. |
| 2912 | * |
| 2913 | * @return 0 on success, an errno on failure. |
| 2914 | * |
| 2915 | * This helper function allows drivers to get several regulator |
| 2916 | * consumers in one operation. If any of the regulators cannot be |
| 2917 | * acquired then any regulators that were allocated will be freed |
| 2918 | * before returning to the caller. |
| 2919 | */ |
| 2920 | int regulator_bulk_get(struct device *dev, int num_consumers, |
| 2921 | struct regulator_bulk_data *consumers) |
| 2922 | { |
| 2923 | int i; |
| 2924 | int ret; |
| 2925 | |
| 2926 | for (i = 0; i < num_consumers; i++) |
| 2927 | consumers[i].consumer = NULL; |
| 2928 | |
| 2929 | for (i = 0; i < num_consumers; i++) { |
| 2930 | consumers[i].consumer = regulator_get(dev, |
| 2931 | consumers[i].supply); |
| 2932 | if (IS_ERR(consumers[i].consumer)) { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2933 | ret = PTR_ERR(consumers[i].consumer); |
Mark Brown | 5b30762 | 2009-10-13 13:06:49 +0100 | [diff] [blame] | 2934 | dev_err(dev, "Failed to get supply '%s': %d\n", |
| 2935 | consumers[i].supply, ret); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2936 | consumers[i].consumer = NULL; |
| 2937 | goto err; |
| 2938 | } |
| 2939 | } |
| 2940 | |
| 2941 | return 0; |
| 2942 | |
| 2943 | err: |
Axel Lin | b29c769 | 2012-02-20 10:32:16 +0800 | [diff] [blame] | 2944 | while (--i >= 0) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 2945 | regulator_put(consumers[i].consumer); |
| 2946 | |
| 2947 | return ret; |
| 2948 | } |
| 2949 | EXPORT_SYMBOL_GPL(regulator_bulk_get); |
| 2950 | |
Mark Brown | e6e7403 | 2012-01-20 20:10:08 +0000 | [diff] [blame] | 2951 | /** |
| 2952 | * devm_regulator_bulk_get - managed get multiple regulator consumers |
| 2953 | * |
| 2954 | * @dev: Device to supply |
| 2955 | * @num_consumers: Number of consumers to register |
| 2956 | * @consumers: Configuration of consumers; clients are stored here. |
| 2957 | * |
| 2958 | * @return 0 on success, an errno on failure. |
| 2959 | * |
| 2960 | * This helper function allows drivers to get several regulator |
| 2961 | * consumers in one operation with management, the regulators will |
| 2962 | * automatically be freed when the device is unbound. If any of the |
| 2963 | * regulators cannot be acquired then any regulators that were |
| 2964 | * allocated will be freed before returning to the caller. |
| 2965 | */ |
| 2966 | int devm_regulator_bulk_get(struct device *dev, int num_consumers, |
| 2967 | struct regulator_bulk_data *consumers) |
| 2968 | { |
| 2969 | int i; |
| 2970 | int ret; |
| 2971 | |
| 2972 | for (i = 0; i < num_consumers; i++) |
| 2973 | consumers[i].consumer = NULL; |
| 2974 | |
| 2975 | for (i = 0; i < num_consumers; i++) { |
| 2976 | consumers[i].consumer = devm_regulator_get(dev, |
| 2977 | consumers[i].supply); |
| 2978 | if (IS_ERR(consumers[i].consumer)) { |
| 2979 | ret = PTR_ERR(consumers[i].consumer); |
| 2980 | dev_err(dev, "Failed to get supply '%s': %d\n", |
| 2981 | consumers[i].supply, ret); |
| 2982 | consumers[i].consumer = NULL; |
| 2983 | goto err; |
| 2984 | } |
| 2985 | } |
| 2986 | |
| 2987 | return 0; |
| 2988 | |
| 2989 | err: |
| 2990 | for (i = 0; i < num_consumers && consumers[i].consumer; i++) |
| 2991 | devm_regulator_put(consumers[i].consumer); |
| 2992 | |
| 2993 | return ret; |
| 2994 | } |
| 2995 | EXPORT_SYMBOL_GPL(devm_regulator_bulk_get); |
| 2996 | |
Mark Brown | f21e0e8 | 2011-05-24 08:12:40 +0800 | [diff] [blame] | 2997 | static void regulator_bulk_enable_async(void *data, async_cookie_t cookie) |
| 2998 | { |
| 2999 | struct regulator_bulk_data *bulk = data; |
| 3000 | |
| 3001 | bulk->ret = regulator_enable(bulk->consumer); |
| 3002 | } |
| 3003 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3004 | /** |
| 3005 | * regulator_bulk_enable - enable multiple regulator consumers |
| 3006 | * |
| 3007 | * @num_consumers: Number of consumers |
| 3008 | * @consumers: Consumer data; clients are stored here. |
| 3009 | * @return 0 on success, an errno on failure |
| 3010 | * |
| 3011 | * This convenience API allows consumers to enable multiple regulator |
| 3012 | * clients in a single API call. If any consumers cannot be enabled |
| 3013 | * then any others that were enabled will be disabled again prior to |
| 3014 | * return. |
| 3015 | */ |
| 3016 | int regulator_bulk_enable(int num_consumers, |
| 3017 | struct regulator_bulk_data *consumers) |
| 3018 | { |
Dan Williams | 2955b47 | 2012-07-09 19:33:25 -0700 | [diff] [blame] | 3019 | ASYNC_DOMAIN_EXCLUSIVE(async_domain); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3020 | int i; |
Mark Brown | f21e0e8 | 2011-05-24 08:12:40 +0800 | [diff] [blame] | 3021 | int ret = 0; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3022 | |
Mark Brown | 6492bc1 | 2012-04-19 13:19:07 +0100 | [diff] [blame] | 3023 | for (i = 0; i < num_consumers; i++) { |
| 3024 | if (consumers[i].consumer->always_on) |
| 3025 | consumers[i].ret = 0; |
| 3026 | else |
| 3027 | async_schedule_domain(regulator_bulk_enable_async, |
| 3028 | &consumers[i], &async_domain); |
| 3029 | } |
Mark Brown | f21e0e8 | 2011-05-24 08:12:40 +0800 | [diff] [blame] | 3030 | |
| 3031 | async_synchronize_full_domain(&async_domain); |
| 3032 | |
| 3033 | /* If any consumer failed we need to unwind any that succeeded */ |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3034 | for (i = 0; i < num_consumers; i++) { |
Mark Brown | f21e0e8 | 2011-05-24 08:12:40 +0800 | [diff] [blame] | 3035 | if (consumers[i].ret != 0) { |
| 3036 | ret = consumers[i].ret; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3037 | goto err; |
Mark Brown | f21e0e8 | 2011-05-24 08:12:40 +0800 | [diff] [blame] | 3038 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3039 | } |
| 3040 | |
| 3041 | return 0; |
| 3042 | |
| 3043 | err: |
Andrzej Hajda | fbe3105 | 2013-03-01 12:24:05 +0100 | [diff] [blame] | 3044 | for (i = 0; i < num_consumers; i++) { |
| 3045 | if (consumers[i].ret < 0) |
| 3046 | pr_err("Failed to enable %s: %d\n", consumers[i].supply, |
| 3047 | consumers[i].ret); |
| 3048 | else |
| 3049 | regulator_disable(consumers[i].consumer); |
| 3050 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3051 | |
| 3052 | return ret; |
| 3053 | } |
| 3054 | EXPORT_SYMBOL_GPL(regulator_bulk_enable); |
| 3055 | |
| 3056 | /** |
| 3057 | * regulator_bulk_disable - disable multiple regulator consumers |
| 3058 | * |
| 3059 | * @num_consumers: Number of consumers |
| 3060 | * @consumers: Consumer data; clients are stored here. |
| 3061 | * @return 0 on success, an errno on failure |
| 3062 | * |
| 3063 | * This convenience API allows consumers to disable multiple regulator |
Sylwester Nawrocki | 49e2263 | 2012-01-25 12:35:38 +0100 | [diff] [blame] | 3064 | * clients in a single API call. If any consumers cannot be disabled |
| 3065 | * then any others that were disabled will be enabled again prior to |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3066 | * return. |
| 3067 | */ |
| 3068 | int regulator_bulk_disable(int num_consumers, |
| 3069 | struct regulator_bulk_data *consumers) |
| 3070 | { |
| 3071 | int i; |
Mark Brown | 01e86f4 | 2012-03-28 21:36:38 +0100 | [diff] [blame] | 3072 | int ret, r; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3073 | |
Sylwester Nawrocki | 49e2263 | 2012-01-25 12:35:38 +0100 | [diff] [blame] | 3074 | for (i = num_consumers - 1; i >= 0; --i) { |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3075 | ret = regulator_disable(consumers[i].consumer); |
| 3076 | if (ret != 0) |
| 3077 | goto err; |
| 3078 | } |
| 3079 | |
| 3080 | return 0; |
| 3081 | |
| 3082 | err: |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 3083 | pr_err("Failed to disable %s: %d\n", consumers[i].supply, ret); |
Mark Brown | 01e86f4 | 2012-03-28 21:36:38 +0100 | [diff] [blame] | 3084 | for (++i; i < num_consumers; ++i) { |
| 3085 | r = regulator_enable(consumers[i].consumer); |
| 3086 | if (r != 0) |
| 3087 | pr_err("Failed to reename %s: %d\n", |
| 3088 | consumers[i].supply, r); |
| 3089 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3090 | |
| 3091 | return ret; |
| 3092 | } |
| 3093 | EXPORT_SYMBOL_GPL(regulator_bulk_disable); |
| 3094 | |
| 3095 | /** |
Donggeun Kim | e1de2f4 | 2012-01-03 16:22:03 +0900 | [diff] [blame] | 3096 | * regulator_bulk_force_disable - force disable multiple regulator consumers |
| 3097 | * |
| 3098 | * @num_consumers: Number of consumers |
| 3099 | * @consumers: Consumer data; clients are stored here. |
| 3100 | * @return 0 on success, an errno on failure |
| 3101 | * |
| 3102 | * This convenience API allows consumers to forcibly disable multiple regulator |
| 3103 | * clients in a single API call. |
| 3104 | * NOTE: This should be used for situations when device damage will |
| 3105 | * likely occur if the regulators are not disabled (e.g. over temp). |
| 3106 | * Although regulator_force_disable function call for some consumers can |
| 3107 | * return error numbers, the function is called for all consumers. |
| 3108 | */ |
| 3109 | int regulator_bulk_force_disable(int num_consumers, |
| 3110 | struct regulator_bulk_data *consumers) |
| 3111 | { |
| 3112 | int i; |
| 3113 | int ret; |
| 3114 | |
| 3115 | for (i = 0; i < num_consumers; i++) |
| 3116 | consumers[i].ret = |
| 3117 | regulator_force_disable(consumers[i].consumer); |
| 3118 | |
| 3119 | for (i = 0; i < num_consumers; i++) { |
| 3120 | if (consumers[i].ret != 0) { |
| 3121 | ret = consumers[i].ret; |
| 3122 | goto out; |
| 3123 | } |
| 3124 | } |
| 3125 | |
| 3126 | return 0; |
| 3127 | out: |
| 3128 | return ret; |
| 3129 | } |
| 3130 | EXPORT_SYMBOL_GPL(regulator_bulk_force_disable); |
| 3131 | |
| 3132 | /** |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3133 | * regulator_bulk_free - free multiple regulator consumers |
| 3134 | * |
| 3135 | * @num_consumers: Number of consumers |
| 3136 | * @consumers: Consumer data; clients are stored here. |
| 3137 | * |
| 3138 | * This convenience API allows consumers to free multiple regulator |
| 3139 | * clients in a single API call. |
| 3140 | */ |
| 3141 | void regulator_bulk_free(int num_consumers, |
| 3142 | struct regulator_bulk_data *consumers) |
| 3143 | { |
| 3144 | int i; |
| 3145 | |
| 3146 | for (i = 0; i < num_consumers; i++) { |
| 3147 | regulator_put(consumers[i].consumer); |
| 3148 | consumers[i].consumer = NULL; |
| 3149 | } |
| 3150 | } |
| 3151 | EXPORT_SYMBOL_GPL(regulator_bulk_free); |
| 3152 | |
| 3153 | /** |
| 3154 | * regulator_notifier_call_chain - call regulator event notifier |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 3155 | * @rdev: regulator source |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3156 | * @event: notifier block |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 3157 | * @data: callback-specific data. |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3158 | * |
| 3159 | * Called by regulator drivers to notify clients a regulator event has |
| 3160 | * occurred. We also notify regulator clients downstream. |
Jonathan Cameron | b136fb4 | 2009-01-19 18:20:58 +0000 | [diff] [blame] | 3161 | * Note lock must be held by caller. |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3162 | */ |
| 3163 | int regulator_notifier_call_chain(struct regulator_dev *rdev, |
| 3164 | unsigned long event, void *data) |
| 3165 | { |
| 3166 | _notifier_call_chain(rdev, event, data); |
| 3167 | return NOTIFY_DONE; |
| 3168 | |
| 3169 | } |
| 3170 | EXPORT_SYMBOL_GPL(regulator_notifier_call_chain); |
| 3171 | |
Mark Brown | be72197 | 2009-08-04 20:09:52 +0200 | [diff] [blame] | 3172 | /** |
| 3173 | * regulator_mode_to_status - convert a regulator mode into a status |
| 3174 | * |
| 3175 | * @mode: Mode to convert |
| 3176 | * |
| 3177 | * Convert a regulator mode into a status. |
| 3178 | */ |
| 3179 | int regulator_mode_to_status(unsigned int mode) |
| 3180 | { |
| 3181 | switch (mode) { |
| 3182 | case REGULATOR_MODE_FAST: |
| 3183 | return REGULATOR_STATUS_FAST; |
| 3184 | case REGULATOR_MODE_NORMAL: |
| 3185 | return REGULATOR_STATUS_NORMAL; |
| 3186 | case REGULATOR_MODE_IDLE: |
| 3187 | return REGULATOR_STATUS_IDLE; |
Krystian Garbaciak | 03ffcf3 | 2012-07-12 11:50:38 +0100 | [diff] [blame] | 3188 | case REGULATOR_MODE_STANDBY: |
Mark Brown | be72197 | 2009-08-04 20:09:52 +0200 | [diff] [blame] | 3189 | return REGULATOR_STATUS_STANDBY; |
| 3190 | default: |
Krystian Garbaciak | 1beaf76 | 2012-07-12 13:53:35 +0100 | [diff] [blame] | 3191 | return REGULATOR_STATUS_UNDEFINED; |
Mark Brown | be72197 | 2009-08-04 20:09:52 +0200 | [diff] [blame] | 3192 | } |
| 3193 | } |
| 3194 | EXPORT_SYMBOL_GPL(regulator_mode_to_status); |
| 3195 | |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 3196 | /* |
| 3197 | * To avoid cluttering sysfs (and memory) with useless state, only |
| 3198 | * create attributes that can be meaningfully displayed. |
| 3199 | */ |
| 3200 | static int add_regulator_attributes(struct regulator_dev *rdev) |
| 3201 | { |
| 3202 | struct device *dev = &rdev->dev; |
| 3203 | struct regulator_ops *ops = rdev->desc->ops; |
| 3204 | int status = 0; |
| 3205 | |
| 3206 | /* some attributes need specific methods to be displayed */ |
Mark Brown | 4c78899 | 2011-11-02 11:39:09 +0000 | [diff] [blame] | 3207 | if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) || |
Mark Brown | f2889e6 | 2012-08-27 11:37:04 -0700 | [diff] [blame] | 3208 | (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0) || |
| 3209 | (ops->list_voltage && ops->list_voltage(rdev, 0) >= 0)) { |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 3210 | status = device_create_file(dev, &dev_attr_microvolts); |
| 3211 | if (status < 0) |
| 3212 | return status; |
| 3213 | } |
| 3214 | if (ops->get_current_limit) { |
| 3215 | status = device_create_file(dev, &dev_attr_microamps); |
| 3216 | if (status < 0) |
| 3217 | return status; |
| 3218 | } |
| 3219 | if (ops->get_mode) { |
| 3220 | status = device_create_file(dev, &dev_attr_opmode); |
| 3221 | if (status < 0) |
| 3222 | return status; |
| 3223 | } |
Kim, Milo | 7b74d14 | 2013-02-18 06:50:55 +0000 | [diff] [blame] | 3224 | if (rdev->ena_pin || ops->is_enabled) { |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 3225 | status = device_create_file(dev, &dev_attr_state); |
| 3226 | if (status < 0) |
| 3227 | return status; |
| 3228 | } |
David Brownell | 853116a | 2009-01-14 23:03:17 -0800 | [diff] [blame] | 3229 | if (ops->get_status) { |
| 3230 | status = device_create_file(dev, &dev_attr_status); |
| 3231 | if (status < 0) |
| 3232 | return status; |
| 3233 | } |
Mark Brown | f59c8f9 | 2012-08-31 10:36:37 -0700 | [diff] [blame] | 3234 | if (ops->get_bypass) { |
| 3235 | status = device_create_file(dev, &dev_attr_bypass); |
| 3236 | if (status < 0) |
| 3237 | return status; |
| 3238 | } |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 3239 | |
| 3240 | /* some attributes are type-specific */ |
| 3241 | if (rdev->desc->type == REGULATOR_CURRENT) { |
| 3242 | status = device_create_file(dev, &dev_attr_requested_microamps); |
| 3243 | if (status < 0) |
| 3244 | return status; |
| 3245 | } |
| 3246 | |
| 3247 | /* all the other attributes exist to support constraints; |
| 3248 | * don't show them if there are no constraints, or if the |
| 3249 | * relevant supporting methods are missing. |
| 3250 | */ |
| 3251 | if (!rdev->constraints) |
| 3252 | return status; |
| 3253 | |
| 3254 | /* constraints need specific supporting methods */ |
Mark Brown | e8eef82 | 2010-12-12 14:36:17 +0000 | [diff] [blame] | 3255 | if (ops->set_voltage || ops->set_voltage_sel) { |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 3256 | status = device_create_file(dev, &dev_attr_min_microvolts); |
| 3257 | if (status < 0) |
| 3258 | return status; |
| 3259 | status = device_create_file(dev, &dev_attr_max_microvolts); |
| 3260 | if (status < 0) |
| 3261 | return status; |
| 3262 | } |
| 3263 | if (ops->set_current_limit) { |
| 3264 | status = device_create_file(dev, &dev_attr_min_microamps); |
| 3265 | if (status < 0) |
| 3266 | return status; |
| 3267 | status = device_create_file(dev, &dev_attr_max_microamps); |
| 3268 | if (status < 0) |
| 3269 | return status; |
| 3270 | } |
| 3271 | |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 3272 | status = device_create_file(dev, &dev_attr_suspend_standby_state); |
| 3273 | if (status < 0) |
| 3274 | return status; |
| 3275 | status = device_create_file(dev, &dev_attr_suspend_mem_state); |
| 3276 | if (status < 0) |
| 3277 | return status; |
| 3278 | status = device_create_file(dev, &dev_attr_suspend_disk_state); |
| 3279 | if (status < 0) |
| 3280 | return status; |
| 3281 | |
| 3282 | if (ops->set_suspend_voltage) { |
| 3283 | status = device_create_file(dev, |
| 3284 | &dev_attr_suspend_standby_microvolts); |
| 3285 | if (status < 0) |
| 3286 | return status; |
| 3287 | status = device_create_file(dev, |
| 3288 | &dev_attr_suspend_mem_microvolts); |
| 3289 | if (status < 0) |
| 3290 | return status; |
| 3291 | status = device_create_file(dev, |
| 3292 | &dev_attr_suspend_disk_microvolts); |
| 3293 | if (status < 0) |
| 3294 | return status; |
| 3295 | } |
| 3296 | |
| 3297 | if (ops->set_suspend_mode) { |
| 3298 | status = device_create_file(dev, |
| 3299 | &dev_attr_suspend_standby_mode); |
| 3300 | if (status < 0) |
| 3301 | return status; |
| 3302 | status = device_create_file(dev, |
| 3303 | &dev_attr_suspend_mem_mode); |
| 3304 | if (status < 0) |
| 3305 | return status; |
| 3306 | status = device_create_file(dev, |
| 3307 | &dev_attr_suspend_disk_mode); |
| 3308 | if (status < 0) |
| 3309 | return status; |
| 3310 | } |
| 3311 | |
| 3312 | return status; |
| 3313 | } |
| 3314 | |
Mark Brown | 1130e5b | 2010-12-21 23:49:31 +0000 | [diff] [blame] | 3315 | static void rdev_init_debugfs(struct regulator_dev *rdev) |
| 3316 | { |
Mark Brown | 1130e5b | 2010-12-21 23:49:31 +0000 | [diff] [blame] | 3317 | rdev->debugfs = debugfs_create_dir(rdev_get_name(rdev), debugfs_root); |
Stephen Boyd | 2475143 | 2012-02-20 22:50:42 -0800 | [diff] [blame] | 3318 | if (!rdev->debugfs) { |
Mark Brown | 1130e5b | 2010-12-21 23:49:31 +0000 | [diff] [blame] | 3319 | rdev_warn(rdev, "Failed to create debugfs directory\n"); |
Mark Brown | 1130e5b | 2010-12-21 23:49:31 +0000 | [diff] [blame] | 3320 | return; |
| 3321 | } |
| 3322 | |
| 3323 | debugfs_create_u32("use_count", 0444, rdev->debugfs, |
| 3324 | &rdev->use_count); |
| 3325 | debugfs_create_u32("open_count", 0444, rdev->debugfs, |
| 3326 | &rdev->open_count); |
Mark Brown | f59c8f9 | 2012-08-31 10:36:37 -0700 | [diff] [blame] | 3327 | debugfs_create_u32("bypass_count", 0444, rdev->debugfs, |
| 3328 | &rdev->bypass_count); |
Mark Brown | 1130e5b | 2010-12-21 23:49:31 +0000 | [diff] [blame] | 3329 | } |
| 3330 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3331 | /** |
| 3332 | * regulator_register - register regulator |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 3333 | * @regulator_desc: regulator to register |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 3334 | * @config: runtime configuration for regulator |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3335 | * |
| 3336 | * Called by regulator drivers to register a regulator. |
Axel Lin | 0384618 | 2013-01-03 21:01:47 +0800 | [diff] [blame] | 3337 | * Returns a valid pointer to struct regulator_dev on success |
| 3338 | * or an ERR_PTR() on error. |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3339 | */ |
Mark Brown | 65f2684 | 2012-04-03 20:46:53 +0100 | [diff] [blame] | 3340 | struct regulator_dev * |
| 3341 | regulator_register(const struct regulator_desc *regulator_desc, |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 3342 | const struct regulator_config *config) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3343 | { |
Mark Brown | 9a8f5e0 | 2011-11-29 18:11:19 +0000 | [diff] [blame] | 3344 | const struct regulation_constraints *constraints = NULL; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 3345 | const struct regulator_init_data *init_data; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3346 | static atomic_t regulator_no = ATOMIC_INIT(0); |
| 3347 | struct regulator_dev *rdev; |
Mark Brown | 32c8fad | 2012-04-11 10:19:12 +0100 | [diff] [blame] | 3348 | struct device *dev; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 3349 | int ret, i; |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 3350 | const char *supply = NULL; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3351 | |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 3352 | if (regulator_desc == NULL || config == NULL) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3353 | return ERR_PTR(-EINVAL); |
| 3354 | |
Mark Brown | 32c8fad | 2012-04-11 10:19:12 +0100 | [diff] [blame] | 3355 | dev = config->dev; |
Mark Brown | dcf7011 | 2012-05-08 18:09:12 +0100 | [diff] [blame] | 3356 | WARN_ON(!dev); |
Mark Brown | 32c8fad | 2012-04-11 10:19:12 +0100 | [diff] [blame] | 3357 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3358 | if (regulator_desc->name == NULL || regulator_desc->ops == NULL) |
| 3359 | return ERR_PTR(-EINVAL); |
| 3360 | |
Diego Liziero | cd78dfc | 2009-04-14 03:04:47 +0200 | [diff] [blame] | 3361 | if (regulator_desc->type != REGULATOR_VOLTAGE && |
| 3362 | regulator_desc->type != REGULATOR_CURRENT) |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3363 | return ERR_PTR(-EINVAL); |
| 3364 | |
Mark Brown | 476c2d8 | 2010-12-10 17:28:07 +0000 | [diff] [blame] | 3365 | /* Only one of each should be implemented */ |
| 3366 | WARN_ON(regulator_desc->ops->get_voltage && |
| 3367 | regulator_desc->ops->get_voltage_sel); |
Mark Brown | e8eef82 | 2010-12-12 14:36:17 +0000 | [diff] [blame] | 3368 | WARN_ON(regulator_desc->ops->set_voltage && |
| 3369 | regulator_desc->ops->set_voltage_sel); |
Mark Brown | 476c2d8 | 2010-12-10 17:28:07 +0000 | [diff] [blame] | 3370 | |
| 3371 | /* If we're using selectors we must implement list_voltage. */ |
| 3372 | if (regulator_desc->ops->get_voltage_sel && |
| 3373 | !regulator_desc->ops->list_voltage) { |
| 3374 | return ERR_PTR(-EINVAL); |
| 3375 | } |
Mark Brown | e8eef82 | 2010-12-12 14:36:17 +0000 | [diff] [blame] | 3376 | if (regulator_desc->ops->set_voltage_sel && |
| 3377 | !regulator_desc->ops->list_voltage) { |
| 3378 | return ERR_PTR(-EINVAL); |
| 3379 | } |
Mark Brown | 476c2d8 | 2010-12-10 17:28:07 +0000 | [diff] [blame] | 3380 | |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 3381 | init_data = config->init_data; |
| 3382 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3383 | rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); |
| 3384 | if (rdev == NULL) |
| 3385 | return ERR_PTR(-ENOMEM); |
| 3386 | |
| 3387 | mutex_lock(®ulator_list_mutex); |
| 3388 | |
| 3389 | mutex_init(&rdev->mutex); |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 3390 | rdev->reg_data = config->driver_data; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3391 | rdev->owner = regulator_desc->owner; |
| 3392 | rdev->desc = regulator_desc; |
Mark Brown | 3a4b0a0 | 2012-05-08 18:10:45 +0100 | [diff] [blame] | 3393 | if (config->regmap) |
| 3394 | rdev->regmap = config->regmap; |
AnilKumar Ch | 52b84da | 2012-09-07 20:45:05 +0530 | [diff] [blame] | 3395 | else if (dev_get_regmap(dev, NULL)) |
Mark Brown | 3a4b0a0 | 2012-05-08 18:10:45 +0100 | [diff] [blame] | 3396 | rdev->regmap = dev_get_regmap(dev, NULL); |
AnilKumar Ch | 52b84da | 2012-09-07 20:45:05 +0530 | [diff] [blame] | 3397 | else if (dev->parent) |
| 3398 | rdev->regmap = dev_get_regmap(dev->parent, NULL); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3399 | INIT_LIST_HEAD(&rdev->consumer_list); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3400 | INIT_LIST_HEAD(&rdev->list); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3401 | BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); |
Mark Brown | da07ecd | 2011-09-11 09:53:50 +0100 | [diff] [blame] | 3402 | INIT_DELAYED_WORK(&rdev->disable_work, regulator_disable_work); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3403 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 3404 | /* preform any regulator specific init */ |
Mark Brown | 9a8f5e0 | 2011-11-29 18:11:19 +0000 | [diff] [blame] | 3405 | if (init_data && init_data->regulator_init) { |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 3406 | ret = init_data->regulator_init(rdev->reg_data); |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 3407 | if (ret < 0) |
| 3408 | goto clean; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 3409 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3410 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 3411 | /* register with sysfs */ |
| 3412 | rdev->dev.class = ®ulator_class; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 3413 | rdev->dev.of_node = config->of_node; |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 3414 | rdev->dev.parent = dev; |
Kay Sievers | 812460a | 2008-11-02 03:55:10 +0100 | [diff] [blame] | 3415 | dev_set_name(&rdev->dev, "regulator.%d", |
| 3416 | atomic_inc_return(®ulator_no) - 1); |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 3417 | ret = device_register(&rdev->dev); |
Vasiliy Kulikov | ad7725c | 2010-09-19 16:55:01 +0400 | [diff] [blame] | 3418 | if (ret != 0) { |
| 3419 | put_device(&rdev->dev); |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 3420 | goto clean; |
Vasiliy Kulikov | ad7725c | 2010-09-19 16:55:01 +0400 | [diff] [blame] | 3421 | } |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 3422 | |
| 3423 | dev_set_drvdata(&rdev->dev, rdev); |
| 3424 | |
Marek Szyprowski | b2a1ef4 | 2012-08-09 16:33:00 +0200 | [diff] [blame] | 3425 | if (config->ena_gpio && gpio_is_valid(config->ena_gpio)) { |
Kim, Milo | f19b00d | 2013-02-18 06:50:39 +0000 | [diff] [blame] | 3426 | ret = regulator_ena_gpio_request(rdev, config); |
Mark Brown | 65f7350 | 2012-06-27 14:14:38 +0100 | [diff] [blame] | 3427 | if (ret != 0) { |
| 3428 | rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", |
| 3429 | config->ena_gpio, ret); |
Andrew Lunn | b2da55d | 2012-10-28 16:01:11 +0100 | [diff] [blame] | 3430 | goto wash; |
Mark Brown | 65f7350 | 2012-06-27 14:14:38 +0100 | [diff] [blame] | 3431 | } |
| 3432 | |
Mark Brown | 65f7350 | 2012-06-27 14:14:38 +0100 | [diff] [blame] | 3433 | if (config->ena_gpio_flags & GPIOF_OUT_INIT_HIGH) |
| 3434 | rdev->ena_gpio_state = 1; |
| 3435 | |
Kim, Milo | 7b74d14 | 2013-02-18 06:50:55 +0000 | [diff] [blame] | 3436 | if (config->ena_gpio_invert) |
Mark Brown | 65f7350 | 2012-06-27 14:14:38 +0100 | [diff] [blame] | 3437 | rdev->ena_gpio_state = !rdev->ena_gpio_state; |
| 3438 | } |
| 3439 | |
Mike Rapoport | 74f544c | 2008-11-25 14:53:53 +0200 | [diff] [blame] | 3440 | /* set regulator constraints */ |
Mark Brown | 9a8f5e0 | 2011-11-29 18:11:19 +0000 | [diff] [blame] | 3441 | if (init_data) |
| 3442 | constraints = &init_data->constraints; |
| 3443 | |
| 3444 | ret = set_machine_constraints(rdev, constraints); |
Mike Rapoport | 74f544c | 2008-11-25 14:53:53 +0200 | [diff] [blame] | 3445 | if (ret < 0) |
| 3446 | goto scrub; |
| 3447 | |
David Brownell | 7ad68e2 | 2008-11-11 17:39:02 -0800 | [diff] [blame] | 3448 | /* add attributes supported by this regulator */ |
| 3449 | ret = add_regulator_attributes(rdev); |
| 3450 | if (ret < 0) |
| 3451 | goto scrub; |
| 3452 | |
Mark Brown | 9a8f5e0 | 2011-11-29 18:11:19 +0000 | [diff] [blame] | 3453 | if (init_data && init_data->supply_regulator) |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 3454 | supply = init_data->supply_regulator; |
| 3455 | else if (regulator_desc->supply_name) |
| 3456 | supply = regulator_desc->supply_name; |
| 3457 | |
| 3458 | if (supply) { |
Mark Brown | 0178f3e | 2010-04-26 15:18:14 +0100 | [diff] [blame] | 3459 | struct regulator_dev *r; |
Mark Brown | 0178f3e | 2010-04-26 15:18:14 +0100 | [diff] [blame] | 3460 | |
Mark Brown | 6d191a5 | 2012-03-29 14:19:02 +0100 | [diff] [blame] | 3461 | r = regulator_dev_lookup(dev, supply, &ret); |
Mark Brown | 0178f3e | 2010-04-26 15:18:14 +0100 | [diff] [blame] | 3462 | |
Andrew Bresticker | 0f7b87f | 2013-04-04 15:27:47 -0700 | [diff] [blame] | 3463 | if (ret == -ENODEV) { |
| 3464 | /* |
| 3465 | * No supply was specified for this regulator and |
| 3466 | * there will never be one. |
| 3467 | */ |
| 3468 | ret = 0; |
| 3469 | goto add_dev; |
| 3470 | } else if (!r) { |
Rajendra Nayak | 69511a4 | 2011-11-18 16:47:20 +0530 | [diff] [blame] | 3471 | dev_err(dev, "Failed to find supply %s\n", supply); |
Mark Brown | 04bf301 | 2012-03-11 13:07:56 +0000 | [diff] [blame] | 3472 | ret = -EPROBE_DEFER; |
Mark Brown | 0178f3e | 2010-04-26 15:18:14 +0100 | [diff] [blame] | 3473 | goto scrub; |
| 3474 | } |
| 3475 | |
| 3476 | ret = set_supply(rdev, r); |
| 3477 | if (ret < 0) |
| 3478 | goto scrub; |
Laxman Dewangan | b2296bd | 2012-01-02 13:08:45 +0530 | [diff] [blame] | 3479 | |
| 3480 | /* Enable supply if rail is enabled */ |
Mark Brown | b1a8683 | 2012-05-14 00:40:14 +0100 | [diff] [blame] | 3481 | if (_regulator_is_enabled(rdev)) { |
Laxman Dewangan | b2296bd | 2012-01-02 13:08:45 +0530 | [diff] [blame] | 3482 | ret = regulator_enable(rdev->supply); |
| 3483 | if (ret < 0) |
| 3484 | goto scrub; |
| 3485 | } |
Mark Brown | 0178f3e | 2010-04-26 15:18:14 +0100 | [diff] [blame] | 3486 | } |
| 3487 | |
Andrew Bresticker | 0f7b87f | 2013-04-04 15:27:47 -0700 | [diff] [blame] | 3488 | add_dev: |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 3489 | /* add consumers devices */ |
Mark Brown | 9a8f5e0 | 2011-11-29 18:11:19 +0000 | [diff] [blame] | 3490 | if (init_data) { |
| 3491 | for (i = 0; i < init_data->num_consumer_supplies; i++) { |
| 3492 | ret = set_consumer_device_supply(rdev, |
Mark Brown | 9a8f5e0 | 2011-11-29 18:11:19 +0000 | [diff] [blame] | 3493 | init_data->consumer_supplies[i].dev_name, |
Mark Brown | 23c2f04 | 2011-02-24 17:39:09 +0000 | [diff] [blame] | 3494 | init_data->consumer_supplies[i].supply); |
Mark Brown | 9a8f5e0 | 2011-11-29 18:11:19 +0000 | [diff] [blame] | 3495 | if (ret < 0) { |
| 3496 | dev_err(dev, "Failed to set supply %s\n", |
| 3497 | init_data->consumer_supplies[i].supply); |
| 3498 | goto unset_supplies; |
| 3499 | } |
Mark Brown | 23c2f04 | 2011-02-24 17:39:09 +0000 | [diff] [blame] | 3500 | } |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | list_add(&rdev->list, ®ulator_list); |
Mark Brown | 1130e5b | 2010-12-21 23:49:31 +0000 | [diff] [blame] | 3504 | |
| 3505 | rdev_init_debugfs(rdev); |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 3506 | out: |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3507 | mutex_unlock(®ulator_list_mutex); |
| 3508 | return rdev; |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 3509 | |
Jani Nikula | d4033b5 | 2010-04-29 10:55:11 +0300 | [diff] [blame] | 3510 | unset_supplies: |
| 3511 | unset_regulator_supplies(rdev); |
| 3512 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 3513 | scrub: |
Mark Brown | e81dba85 | 2012-05-13 18:35:56 +0100 | [diff] [blame] | 3514 | if (rdev->supply) |
Charles Keepax | 23ff2f0 | 2012-11-14 09:39:31 +0000 | [diff] [blame] | 3515 | _regulator_put(rdev->supply); |
Kim, Milo | f19b00d | 2013-02-18 06:50:39 +0000 | [diff] [blame] | 3516 | regulator_ena_gpio_free(rdev); |
Axel Lin | 1a6958e7 | 2011-07-15 10:50:43 +0800 | [diff] [blame] | 3517 | kfree(rdev->constraints); |
Andrew Lunn | b2da55d | 2012-10-28 16:01:11 +0100 | [diff] [blame] | 3518 | wash: |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 3519 | device_unregister(&rdev->dev); |
Paul Walmsley | 53032da | 2009-04-25 05:28:36 -0600 | [diff] [blame] | 3520 | /* device core frees rdev */ |
| 3521 | rdev = ERR_PTR(ret); |
| 3522 | goto out; |
| 3523 | |
David Brownell | 4fca954 | 2008-11-11 17:38:53 -0800 | [diff] [blame] | 3524 | clean: |
| 3525 | kfree(rdev); |
| 3526 | rdev = ERR_PTR(ret); |
| 3527 | goto out; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3528 | } |
| 3529 | EXPORT_SYMBOL_GPL(regulator_register); |
| 3530 | |
| 3531 | /** |
| 3532 | * regulator_unregister - unregister regulator |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 3533 | * @rdev: regulator to unregister |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3534 | * |
| 3535 | * Called by regulator drivers to unregister a regulator. |
| 3536 | */ |
| 3537 | void regulator_unregister(struct regulator_dev *rdev) |
| 3538 | { |
| 3539 | if (rdev == NULL) |
| 3540 | return; |
| 3541 | |
Mark Brown | 891636e | 2013-07-08 09:14:45 +0100 | [diff] [blame] | 3542 | if (rdev->supply) { |
| 3543 | while (rdev->use_count--) |
| 3544 | regulator_disable(rdev->supply); |
Mark Brown | e032b37 | 2012-03-28 21:17:55 +0100 | [diff] [blame] | 3545 | regulator_put(rdev->supply); |
Mark Brown | 891636e | 2013-07-08 09:14:45 +0100 | [diff] [blame] | 3546 | } |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3547 | mutex_lock(®ulator_list_mutex); |
Mark Brown | 1130e5b | 2010-12-21 23:49:31 +0000 | [diff] [blame] | 3548 | debugfs_remove_recursive(rdev->debugfs); |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 3549 | flush_work(&rdev->disable_work.work); |
Mark Brown | 6bf87d1 | 2009-07-21 16:00:25 +0100 | [diff] [blame] | 3550 | WARN_ON(rdev->open_count); |
Mike Rapoport | 0f1d747 | 2009-01-22 16:00:29 +0200 | [diff] [blame] | 3551 | unset_regulator_supplies(rdev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3552 | list_del(&rdev->list); |
Mark Brown | f8c12fe | 2010-11-29 15:55:17 +0000 | [diff] [blame] | 3553 | kfree(rdev->constraints); |
Kim, Milo | f19b00d | 2013-02-18 06:50:39 +0000 | [diff] [blame] | 3554 | regulator_ena_gpio_free(rdev); |
Lothar Waßmann | 58fb5cf | 2011-11-28 15:38:37 +0100 | [diff] [blame] | 3555 | device_unregister(&rdev->dev); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3556 | mutex_unlock(®ulator_list_mutex); |
| 3557 | } |
| 3558 | EXPORT_SYMBOL_GPL(regulator_unregister); |
| 3559 | |
| 3560 | /** |
Mark Brown | cf7bbcd | 2008-12-31 12:52:43 +0000 | [diff] [blame] | 3561 | * regulator_suspend_prepare - prepare regulators for system wide suspend |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3562 | * @state: system suspend state |
| 3563 | * |
| 3564 | * Configure each regulator with it's suspend operating parameters for state. |
| 3565 | * This will usually be called by machine suspend code prior to supending. |
| 3566 | */ |
| 3567 | int regulator_suspend_prepare(suspend_state_t state) |
| 3568 | { |
| 3569 | struct regulator_dev *rdev; |
| 3570 | int ret = 0; |
| 3571 | |
| 3572 | /* ON is handled by regulator active state */ |
| 3573 | if (state == PM_SUSPEND_ON) |
| 3574 | return -EINVAL; |
| 3575 | |
| 3576 | mutex_lock(®ulator_list_mutex); |
| 3577 | list_for_each_entry(rdev, ®ulator_list, list) { |
| 3578 | |
| 3579 | mutex_lock(&rdev->mutex); |
| 3580 | ret = suspend_prepare(rdev, state); |
| 3581 | mutex_unlock(&rdev->mutex); |
| 3582 | |
| 3583 | if (ret < 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 3584 | rdev_err(rdev, "failed to prepare\n"); |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3585 | goto out; |
| 3586 | } |
| 3587 | } |
| 3588 | out: |
| 3589 | mutex_unlock(®ulator_list_mutex); |
| 3590 | return ret; |
| 3591 | } |
| 3592 | EXPORT_SYMBOL_GPL(regulator_suspend_prepare); |
| 3593 | |
| 3594 | /** |
MyungJoo Ham | 7a32b58 | 2011-03-11 10:13:59 +0900 | [diff] [blame] | 3595 | * regulator_suspend_finish - resume regulators from system wide suspend |
| 3596 | * |
| 3597 | * Turn on regulators that might be turned off by regulator_suspend_prepare |
| 3598 | * and that should be turned on according to the regulators properties. |
| 3599 | */ |
| 3600 | int regulator_suspend_finish(void) |
| 3601 | { |
| 3602 | struct regulator_dev *rdev; |
| 3603 | int ret = 0, error; |
| 3604 | |
| 3605 | mutex_lock(®ulator_list_mutex); |
| 3606 | list_for_each_entry(rdev, ®ulator_list, list) { |
| 3607 | struct regulator_ops *ops = rdev->desc->ops; |
| 3608 | |
| 3609 | mutex_lock(&rdev->mutex); |
| 3610 | if ((rdev->use_count > 0 || rdev->constraints->always_on) && |
| 3611 | ops->enable) { |
| 3612 | error = ops->enable(rdev); |
| 3613 | if (error) |
| 3614 | ret = error; |
| 3615 | } else { |
| 3616 | if (!has_full_constraints) |
| 3617 | goto unlock; |
| 3618 | if (!ops->disable) |
| 3619 | goto unlock; |
Mark Brown | b1a8683 | 2012-05-14 00:40:14 +0100 | [diff] [blame] | 3620 | if (!_regulator_is_enabled(rdev)) |
MyungJoo Ham | 7a32b58 | 2011-03-11 10:13:59 +0900 | [diff] [blame] | 3621 | goto unlock; |
| 3622 | |
| 3623 | error = ops->disable(rdev); |
| 3624 | if (error) |
| 3625 | ret = error; |
| 3626 | } |
| 3627 | unlock: |
| 3628 | mutex_unlock(&rdev->mutex); |
| 3629 | } |
| 3630 | mutex_unlock(®ulator_list_mutex); |
| 3631 | return ret; |
| 3632 | } |
| 3633 | EXPORT_SYMBOL_GPL(regulator_suspend_finish); |
| 3634 | |
| 3635 | /** |
Mark Brown | ca72556 | 2009-03-16 19:36:34 +0000 | [diff] [blame] | 3636 | * regulator_has_full_constraints - the system has fully specified constraints |
| 3637 | * |
| 3638 | * Calling this function will cause the regulator API to disable all |
| 3639 | * regulators which have a zero use count and don't have an always_on |
| 3640 | * constraint in a late_initcall. |
| 3641 | * |
| 3642 | * The intention is that this will become the default behaviour in a |
| 3643 | * future kernel release so users are encouraged to use this facility |
| 3644 | * now. |
| 3645 | */ |
| 3646 | void regulator_has_full_constraints(void) |
| 3647 | { |
| 3648 | has_full_constraints = 1; |
| 3649 | } |
| 3650 | EXPORT_SYMBOL_GPL(regulator_has_full_constraints); |
| 3651 | |
| 3652 | /** |
Mark Brown | 688fe99 | 2010-10-05 19:18:32 -0700 | [diff] [blame] | 3653 | * regulator_use_dummy_regulator - Provide a dummy regulator when none is found |
| 3654 | * |
| 3655 | * Calling this function will cause the regulator API to provide a |
| 3656 | * dummy regulator to consumers if no physical regulator is found, |
| 3657 | * allowing most consumers to proceed as though a regulator were |
| 3658 | * configured. This allows systems such as those with software |
| 3659 | * controllable regulators for the CPU core only to be brought up more |
| 3660 | * readily. |
| 3661 | */ |
| 3662 | void regulator_use_dummy_regulator(void) |
| 3663 | { |
| 3664 | board_wants_dummy_regulator = true; |
| 3665 | } |
| 3666 | EXPORT_SYMBOL_GPL(regulator_use_dummy_regulator); |
| 3667 | |
| 3668 | /** |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3669 | * rdev_get_drvdata - get rdev regulator driver data |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 3670 | * @rdev: regulator |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3671 | * |
| 3672 | * Get rdev regulator driver private data. This call can be used in the |
| 3673 | * regulator driver context. |
| 3674 | */ |
| 3675 | void *rdev_get_drvdata(struct regulator_dev *rdev) |
| 3676 | { |
| 3677 | return rdev->reg_data; |
| 3678 | } |
| 3679 | EXPORT_SYMBOL_GPL(rdev_get_drvdata); |
| 3680 | |
| 3681 | /** |
| 3682 | * regulator_get_drvdata - get regulator driver data |
| 3683 | * @regulator: regulator |
| 3684 | * |
| 3685 | * Get regulator driver private data. This call can be used in the consumer |
| 3686 | * driver context when non API regulator specific functions need to be called. |
| 3687 | */ |
| 3688 | void *regulator_get_drvdata(struct regulator *regulator) |
| 3689 | { |
| 3690 | return regulator->rdev->reg_data; |
| 3691 | } |
| 3692 | EXPORT_SYMBOL_GPL(regulator_get_drvdata); |
| 3693 | |
| 3694 | /** |
| 3695 | * regulator_set_drvdata - set regulator driver data |
| 3696 | * @regulator: regulator |
| 3697 | * @data: data |
| 3698 | */ |
| 3699 | void regulator_set_drvdata(struct regulator *regulator, void *data) |
| 3700 | { |
| 3701 | regulator->rdev->reg_data = data; |
| 3702 | } |
| 3703 | EXPORT_SYMBOL_GPL(regulator_set_drvdata); |
| 3704 | |
| 3705 | /** |
| 3706 | * regulator_get_id - get regulator ID |
Mark Brown | 69279fb | 2008-12-31 12:52:41 +0000 | [diff] [blame] | 3707 | * @rdev: regulator |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3708 | */ |
| 3709 | int rdev_get_id(struct regulator_dev *rdev) |
| 3710 | { |
| 3711 | return rdev->desc->id; |
| 3712 | } |
| 3713 | EXPORT_SYMBOL_GPL(rdev_get_id); |
| 3714 | |
Liam Girdwood | a5766f1 | 2008-10-10 13:22:20 +0100 | [diff] [blame] | 3715 | struct device *rdev_get_dev(struct regulator_dev *rdev) |
| 3716 | { |
| 3717 | return &rdev->dev; |
| 3718 | } |
| 3719 | EXPORT_SYMBOL_GPL(rdev_get_dev); |
| 3720 | |
| 3721 | void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data) |
| 3722 | { |
| 3723 | return reg_init_data->driver_data; |
| 3724 | } |
| 3725 | EXPORT_SYMBOL_GPL(regulator_get_init_drvdata); |
| 3726 | |
Mark Brown | ba55a97 | 2011-08-23 17:39:10 +0100 | [diff] [blame] | 3727 | #ifdef CONFIG_DEBUG_FS |
| 3728 | static ssize_t supply_map_read_file(struct file *file, char __user *user_buf, |
| 3729 | size_t count, loff_t *ppos) |
| 3730 | { |
| 3731 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 3732 | ssize_t len, ret = 0; |
| 3733 | struct regulator_map *map; |
| 3734 | |
| 3735 | if (!buf) |
| 3736 | return -ENOMEM; |
| 3737 | |
| 3738 | list_for_each_entry(map, ®ulator_map_list, list) { |
| 3739 | len = snprintf(buf + ret, PAGE_SIZE - ret, |
| 3740 | "%s -> %s.%s\n", |
| 3741 | rdev_get_name(map->regulator), map->dev_name, |
| 3742 | map->supply); |
| 3743 | if (len >= 0) |
| 3744 | ret += len; |
| 3745 | if (ret > PAGE_SIZE) { |
| 3746 | ret = PAGE_SIZE; |
| 3747 | break; |
| 3748 | } |
| 3749 | } |
| 3750 | |
| 3751 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 3752 | |
| 3753 | kfree(buf); |
| 3754 | |
| 3755 | return ret; |
| 3756 | } |
Stephen Boyd | 2475143 | 2012-02-20 22:50:42 -0800 | [diff] [blame] | 3757 | #endif |
Mark Brown | ba55a97 | 2011-08-23 17:39:10 +0100 | [diff] [blame] | 3758 | |
| 3759 | static const struct file_operations supply_map_fops = { |
Stephen Boyd | 2475143 | 2012-02-20 22:50:42 -0800 | [diff] [blame] | 3760 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | ba55a97 | 2011-08-23 17:39:10 +0100 | [diff] [blame] | 3761 | .read = supply_map_read_file, |
| 3762 | .llseek = default_llseek, |
Mark Brown | ba55a97 | 2011-08-23 17:39:10 +0100 | [diff] [blame] | 3763 | #endif |
Stephen Boyd | 2475143 | 2012-02-20 22:50:42 -0800 | [diff] [blame] | 3764 | }; |
Mark Brown | ba55a97 | 2011-08-23 17:39:10 +0100 | [diff] [blame] | 3765 | |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3766 | static int __init regulator_init(void) |
| 3767 | { |
Mark Brown | 34abbd6 | 2010-02-12 10:18:08 +0000 | [diff] [blame] | 3768 | int ret; |
| 3769 | |
Mark Brown | 34abbd6 | 2010-02-12 10:18:08 +0000 | [diff] [blame] | 3770 | ret = class_register(®ulator_class); |
| 3771 | |
Mark Brown | 1130e5b | 2010-12-21 23:49:31 +0000 | [diff] [blame] | 3772 | debugfs_root = debugfs_create_dir("regulator", NULL); |
Stephen Boyd | 2475143 | 2012-02-20 22:50:42 -0800 | [diff] [blame] | 3773 | if (!debugfs_root) |
Mark Brown | 1130e5b | 2010-12-21 23:49:31 +0000 | [diff] [blame] | 3774 | pr_warn("regulator: Failed to create debugfs directory\n"); |
Mark Brown | ba55a97 | 2011-08-23 17:39:10 +0100 | [diff] [blame] | 3775 | |
Mark Brown | f4d562c | 2012-02-20 21:01:04 +0000 | [diff] [blame] | 3776 | debugfs_create_file("supply_map", 0444, debugfs_root, NULL, |
| 3777 | &supply_map_fops); |
Mark Brown | 1130e5b | 2010-12-21 23:49:31 +0000 | [diff] [blame] | 3778 | |
Mark Brown | 34abbd6 | 2010-02-12 10:18:08 +0000 | [diff] [blame] | 3779 | regulator_dummy_init(); |
| 3780 | |
| 3781 | return ret; |
Liam Girdwood | 414c70c | 2008-04-30 15:59:04 +0100 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | /* init early to allow our consumers to complete system booting */ |
| 3785 | core_initcall(regulator_init); |
Mark Brown | ca72556 | 2009-03-16 19:36:34 +0000 | [diff] [blame] | 3786 | |
| 3787 | static int __init regulator_init_complete(void) |
| 3788 | { |
| 3789 | struct regulator_dev *rdev; |
| 3790 | struct regulator_ops *ops; |
| 3791 | struct regulation_constraints *c; |
| 3792 | int enabled, ret; |
Mark Brown | ca72556 | 2009-03-16 19:36:34 +0000 | [diff] [blame] | 3793 | |
Mark Brown | 86f5fcf | 2012-07-06 18:19:13 +0100 | [diff] [blame] | 3794 | /* |
| 3795 | * Since DT doesn't provide an idiomatic mechanism for |
| 3796 | * enabling full constraints and since it's much more natural |
| 3797 | * with DT to provide them just assume that a DT enabled |
| 3798 | * system has full constraints. |
| 3799 | */ |
| 3800 | if (of_have_populated_dt()) |
| 3801 | has_full_constraints = true; |
| 3802 | |
Mark Brown | ca72556 | 2009-03-16 19:36:34 +0000 | [diff] [blame] | 3803 | mutex_lock(®ulator_list_mutex); |
| 3804 | |
| 3805 | /* If we have a full configuration then disable any regulators |
| 3806 | * which are not in use or always_on. This will become the |
| 3807 | * default behaviour in the future. |
| 3808 | */ |
| 3809 | list_for_each_entry(rdev, ®ulator_list, list) { |
| 3810 | ops = rdev->desc->ops; |
| 3811 | c = rdev->constraints; |
| 3812 | |
Mark Brown | f25e0b4 | 2009-08-03 18:49:55 +0100 | [diff] [blame] | 3813 | if (!ops->disable || (c && c->always_on)) |
Mark Brown | ca72556 | 2009-03-16 19:36:34 +0000 | [diff] [blame] | 3814 | continue; |
| 3815 | |
| 3816 | mutex_lock(&rdev->mutex); |
| 3817 | |
| 3818 | if (rdev->use_count) |
| 3819 | goto unlock; |
| 3820 | |
| 3821 | /* If we can't read the status assume it's on. */ |
| 3822 | if (ops->is_enabled) |
| 3823 | enabled = ops->is_enabled(rdev); |
| 3824 | else |
| 3825 | enabled = 1; |
| 3826 | |
| 3827 | if (!enabled) |
| 3828 | goto unlock; |
| 3829 | |
| 3830 | if (has_full_constraints) { |
| 3831 | /* We log since this may kill the system if it |
| 3832 | * goes wrong. */ |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 3833 | rdev_info(rdev, "disabling\n"); |
Mark Brown | ca72556 | 2009-03-16 19:36:34 +0000 | [diff] [blame] | 3834 | ret = ops->disable(rdev); |
| 3835 | if (ret != 0) { |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 3836 | rdev_err(rdev, "couldn't disable: %d\n", ret); |
Mark Brown | ca72556 | 2009-03-16 19:36:34 +0000 | [diff] [blame] | 3837 | } |
| 3838 | } else { |
| 3839 | /* The intention is that in future we will |
| 3840 | * assume that full constraints are provided |
| 3841 | * so warn even if we aren't going to do |
| 3842 | * anything here. |
| 3843 | */ |
Joe Perches | 5da84fd | 2010-11-30 05:53:48 -0800 | [diff] [blame] | 3844 | rdev_warn(rdev, "incomplete constraints, leaving on\n"); |
Mark Brown | ca72556 | 2009-03-16 19:36:34 +0000 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | unlock: |
| 3848 | mutex_unlock(&rdev->mutex); |
| 3849 | } |
| 3850 | |
| 3851 | mutex_unlock(®ulator_list_mutex); |
| 3852 | |
| 3853 | return 0; |
| 3854 | } |
| 3855 | late_initcall(regulator_init_complete); |