diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2009-10-22 11:31:32 -0400 |
---|---|---|
committer | Liam Girdwood <lrg@slimlogic.co.uk> | 2009-12-17 05:27:24 -0500 |
commit | 1083c39346d482b9001944d05c09191027892226 (patch) | |
tree | 51420f7c6cd81026eca0d6a54881b5d50cfc0988 /drivers/regulator | |
parent | 8f031b48cd2eab5fc3e4dffa06706372e90d63fe (diff) |
regulator: Factor out regulator name pretty printing
Some of the regulator API functions have code to allow the machine
constraints to override the device supplied name for the regulator
in the constraints in order to help tie logging to supplies on the
board and disambiguate when there is more than one regulator chip
in the system. Factor this code out into a new rdev_get_name()
function and use it throughout the regulator API so that we always
use the same name.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/core.c | 83 |
1 files changed, 38 insertions, 45 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index d3be67e18519..7d0c0d7d90ca 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -66,6 +66,16 @@ static unsigned int _regulator_get_mode(struct regulator_dev *rdev); | |||
66 | static void _notifier_call_chain(struct regulator_dev *rdev, | 66 | static void _notifier_call_chain(struct regulator_dev *rdev, |
67 | unsigned long event, void *data); | 67 | unsigned long event, void *data); |
68 | 68 | ||
69 | static const char *rdev_get_name(struct regulator_dev *rdev) | ||
70 | { | ||
71 | if (rdev->constraints && rdev->constraints->name) | ||
72 | return rdev->constraints->name; | ||
73 | else if (rdev->desc->name) | ||
74 | return rdev->desc->name; | ||
75 | else | ||
76 | return ""; | ||
77 | } | ||
78 | |||
69 | /* gets the regulator for a given consumer device */ | 79 | /* gets the regulator for a given consumer device */ |
70 | static struct regulator *get_device_regulator(struct device *dev) | 80 | static struct regulator *get_device_regulator(struct device *dev) |
71 | { | 81 | { |
@@ -96,12 +106,12 @@ static int regulator_check_voltage(struct regulator_dev *rdev, | |||
96 | 106 | ||
97 | if (!rdev->constraints) { | 107 | if (!rdev->constraints) { |
98 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, | 108 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, |
99 | rdev->desc->name); | 109 | rdev_get_name(rdev)); |
100 | return -ENODEV; | 110 | return -ENODEV; |
101 | } | 111 | } |
102 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { | 112 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { |
103 | printk(KERN_ERR "%s: operation not allowed for %s\n", | 113 | printk(KERN_ERR "%s: operation not allowed for %s\n", |
104 | __func__, rdev->desc->name); | 114 | __func__, rdev_get_name(rdev)); |
105 | return -EPERM; | 115 | return -EPERM; |
106 | } | 116 | } |
107 | 117 | ||
@@ -124,12 +134,12 @@ static int regulator_check_current_limit(struct regulator_dev *rdev, | |||
124 | 134 | ||
125 | if (!rdev->constraints) { | 135 | if (!rdev->constraints) { |
126 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, | 136 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, |
127 | rdev->desc->name); | 137 | rdev_get_name(rdev)); |
128 | return -ENODEV; | 138 | return -ENODEV; |
129 | } | 139 | } |
130 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) { | 140 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) { |
131 | printk(KERN_ERR "%s: operation not allowed for %s\n", | 141 | printk(KERN_ERR "%s: operation not allowed for %s\n", |
132 | __func__, rdev->desc->name); | 142 | __func__, rdev_get_name(rdev)); |
133 | return -EPERM; | 143 | return -EPERM; |
134 | } | 144 | } |
135 | 145 | ||
@@ -159,17 +169,17 @@ static int regulator_check_mode(struct regulator_dev *rdev, int mode) | |||
159 | 169 | ||
160 | if (!rdev->constraints) { | 170 | if (!rdev->constraints) { |
161 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, | 171 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, |
162 | rdev->desc->name); | 172 | rdev_get_name(rdev)); |
163 | return -ENODEV; | 173 | return -ENODEV; |
164 | } | 174 | } |
165 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) { | 175 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) { |
166 | printk(KERN_ERR "%s: operation not allowed for %s\n", | 176 | printk(KERN_ERR "%s: operation not allowed for %s\n", |
167 | __func__, rdev->desc->name); | 177 | __func__, rdev_get_name(rdev)); |
168 | return -EPERM; | 178 | return -EPERM; |
169 | } | 179 | } |
170 | if (!(rdev->constraints->valid_modes_mask & mode)) { | 180 | if (!(rdev->constraints->valid_modes_mask & mode)) { |
171 | printk(KERN_ERR "%s: invalid mode %x for %s\n", | 181 | printk(KERN_ERR "%s: invalid mode %x for %s\n", |
172 | __func__, mode, rdev->desc->name); | 182 | __func__, mode, rdev_get_name(rdev)); |
173 | return -EINVAL; | 183 | return -EINVAL; |
174 | } | 184 | } |
175 | return 0; | 185 | return 0; |
@@ -180,12 +190,12 @@ static int regulator_check_drms(struct regulator_dev *rdev) | |||
180 | { | 190 | { |
181 | if (!rdev->constraints) { | 191 | if (!rdev->constraints) { |
182 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, | 192 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, |
183 | rdev->desc->name); | 193 | rdev_get_name(rdev)); |
184 | return -ENODEV; | 194 | return -ENODEV; |
185 | } | 195 | } |
186 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { | 196 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { |
187 | printk(KERN_ERR "%s: operation not allowed for %s\n", | 197 | printk(KERN_ERR "%s: operation not allowed for %s\n", |
188 | __func__, rdev->desc->name); | 198 | __func__, rdev_get_name(rdev)); |
189 | return -EPERM; | 199 | return -EPERM; |
190 | } | 200 | } |
191 | return 0; | 201 | return 0; |
@@ -230,16 +240,8 @@ static ssize_t regulator_name_show(struct device *dev, | |||
230 | struct device_attribute *attr, char *buf) | 240 | struct device_attribute *attr, char *buf) |
231 | { | 241 | { |
232 | struct regulator_dev *rdev = dev_get_drvdata(dev); | 242 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
233 | const char *name; | ||
234 | 243 | ||
235 | if (rdev->constraints && rdev->constraints->name) | 244 | return sprintf(buf, "%s\n", rdev_get_name(rdev)); |
236 | name = rdev->constraints->name; | ||
237 | else if (rdev->desc->name) | ||
238 | name = rdev->desc->name; | ||
239 | else | ||
240 | name = ""; | ||
241 | |||
242 | return sprintf(buf, "%s\n", name); | ||
243 | } | 245 | } |
244 | 246 | ||
245 | static ssize_t regulator_print_opmode(char *buf, int mode) | 247 | static ssize_t regulator_print_opmode(char *buf, int mode) |
@@ -687,13 +689,14 @@ static void print_constraints(struct regulator_dev *rdev) | |||
687 | if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) | 689 | if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) |
688 | count += sprintf(buf + count, "standby"); | 690 | count += sprintf(buf + count, "standby"); |
689 | 691 | ||
690 | printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf); | 692 | printk(KERN_INFO "regulator: %s: %s\n", rdev_get_name(rdev), buf); |
691 | } | 693 | } |
692 | 694 | ||
693 | static int machine_constraints_voltage(struct regulator_dev *rdev, | 695 | static int machine_constraints_voltage(struct regulator_dev *rdev, |
694 | const char *name, struct regulation_constraints *constraints) | 696 | struct regulation_constraints *constraints) |
695 | { | 697 | { |
696 | struct regulator_ops *ops = rdev->desc->ops; | 698 | struct regulator_ops *ops = rdev->desc->ops; |
699 | const char *name = rdev_get_name(rdev); | ||
697 | int ret; | 700 | int ret; |
698 | 701 | ||
699 | /* do we need to apply the constraint voltage */ | 702 | /* do we need to apply the constraint voltage */ |
@@ -800,16 +803,11 @@ static int set_machine_constraints(struct regulator_dev *rdev, | |||
800 | const char *name; | 803 | const char *name; |
801 | struct regulator_ops *ops = rdev->desc->ops; | 804 | struct regulator_ops *ops = rdev->desc->ops; |
802 | 805 | ||
803 | if (constraints->name) | ||
804 | name = constraints->name; | ||
805 | else if (rdev->desc->name) | ||
806 | name = rdev->desc->name; | ||
807 | else | ||
808 | name = "regulator"; | ||
809 | |||
810 | rdev->constraints = constraints; | 806 | rdev->constraints = constraints; |
811 | 807 | ||
812 | ret = machine_constraints_voltage(rdev, name, constraints); | 808 | name = rdev_get_name(rdev); |
809 | |||
810 | ret = machine_constraints_voltage(rdev, constraints); | ||
813 | if (ret != 0) | 811 | if (ret != 0) |
814 | goto out; | 812 | goto out; |
815 | 813 | ||
@@ -932,7 +930,7 @@ static int set_consumer_device_supply(struct regulator_dev *rdev, | |||
932 | dev_name(&node->regulator->dev), | 930 | dev_name(&node->regulator->dev), |
933 | node->regulator->desc->name, | 931 | node->regulator->desc->name, |
934 | supply, | 932 | supply, |
935 | dev_name(&rdev->dev), rdev->desc->name); | 933 | dev_name(&rdev->dev), rdev_get_name(rdev)); |
936 | return -EBUSY; | 934 | return -EBUSY; |
937 | } | 935 | } |
938 | 936 | ||
@@ -1241,7 +1239,7 @@ static int _regulator_enable(struct regulator_dev *rdev) | |||
1241 | ret = _regulator_enable(rdev->supply); | 1239 | ret = _regulator_enable(rdev->supply); |
1242 | if (ret < 0) { | 1240 | if (ret < 0) { |
1243 | printk(KERN_ERR "%s: failed to enable %s: %d\n", | 1241 | printk(KERN_ERR "%s: failed to enable %s: %d\n", |
1244 | __func__, rdev->desc->name, ret); | 1242 | __func__, rdev_get_name(rdev), ret); |
1245 | return ret; | 1243 | return ret; |
1246 | } | 1244 | } |
1247 | } | 1245 | } |
@@ -1267,7 +1265,7 @@ static int _regulator_enable(struct regulator_dev *rdev) | |||
1267 | } | 1265 | } |
1268 | } else if (ret < 0) { | 1266 | } else if (ret < 0) { |
1269 | printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n", | 1267 | printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n", |
1270 | __func__, rdev->desc->name, ret); | 1268 | __func__, rdev_get_name(rdev), ret); |
1271 | return ret; | 1269 | return ret; |
1272 | } | 1270 | } |
1273 | /* Fallthrough on positive return values - already enabled */ | 1271 | /* Fallthrough on positive return values - already enabled */ |
@@ -1308,7 +1306,7 @@ static int _regulator_disable(struct regulator_dev *rdev) | |||
1308 | 1306 | ||
1309 | if (WARN(rdev->use_count <= 0, | 1307 | if (WARN(rdev->use_count <= 0, |
1310 | "unbalanced disables for %s\n", | 1308 | "unbalanced disables for %s\n", |
1311 | rdev->desc->name)) | 1309 | rdev_get_name(rdev))) |
1312 | return -EIO; | 1310 | return -EIO; |
1313 | 1311 | ||
1314 | /* are we the last user and permitted to disable ? */ | 1312 | /* are we the last user and permitted to disable ? */ |
@@ -1321,7 +1319,7 @@ static int _regulator_disable(struct regulator_dev *rdev) | |||
1321 | ret = rdev->desc->ops->disable(rdev); | 1319 | ret = rdev->desc->ops->disable(rdev); |
1322 | if (ret < 0) { | 1320 | if (ret < 0) { |
1323 | printk(KERN_ERR "%s: failed to disable %s\n", | 1321 | printk(KERN_ERR "%s: failed to disable %s\n", |
1324 | __func__, rdev->desc->name); | 1322 | __func__, rdev_get_name(rdev)); |
1325 | return ret; | 1323 | return ret; |
1326 | } | 1324 | } |
1327 | } | 1325 | } |
@@ -1378,7 +1376,7 @@ static int _regulator_force_disable(struct regulator_dev *rdev) | |||
1378 | ret = rdev->desc->ops->disable(rdev); | 1376 | ret = rdev->desc->ops->disable(rdev); |
1379 | if (ret < 0) { | 1377 | if (ret < 0) { |
1380 | printk(KERN_ERR "%s: failed to force disable %s\n", | 1378 | printk(KERN_ERR "%s: failed to force disable %s\n", |
1381 | __func__, rdev->desc->name); | 1379 | __func__, rdev_get_name(rdev)); |
1382 | return ret; | 1380 | return ret; |
1383 | } | 1381 | } |
1384 | /* notify other consumers that power has been forced off */ | 1382 | /* notify other consumers that power has been forced off */ |
@@ -1795,7 +1793,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load) | |||
1795 | output_uV = rdev->desc->ops->get_voltage(rdev); | 1793 | output_uV = rdev->desc->ops->get_voltage(rdev); |
1796 | if (output_uV <= 0) { | 1794 | if (output_uV <= 0) { |
1797 | printk(KERN_ERR "%s: invalid output voltage found for %s\n", | 1795 | printk(KERN_ERR "%s: invalid output voltage found for %s\n", |
1798 | __func__, rdev->desc->name); | 1796 | __func__, rdev_get_name(rdev)); |
1799 | goto out; | 1797 | goto out; |
1800 | } | 1798 | } |
1801 | 1799 | ||
@@ -1806,7 +1804,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load) | |||
1806 | input_uV = rdev->constraints->input_uV; | 1804 | input_uV = rdev->constraints->input_uV; |
1807 | if (input_uV <= 0) { | 1805 | if (input_uV <= 0) { |
1808 | printk(KERN_ERR "%s: invalid input voltage found for %s\n", | 1806 | printk(KERN_ERR "%s: invalid input voltage found for %s\n", |
1809 | __func__, rdev->desc->name); | 1807 | __func__, rdev_get_name(rdev)); |
1810 | goto out; | 1808 | goto out; |
1811 | } | 1809 | } |
1812 | 1810 | ||
@@ -1820,7 +1818,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load) | |||
1820 | ret = regulator_check_mode(rdev, mode); | 1818 | ret = regulator_check_mode(rdev, mode); |
1821 | if (ret < 0) { | 1819 | if (ret < 0) { |
1822 | printk(KERN_ERR "%s: failed to get optimum mode for %s @" | 1820 | printk(KERN_ERR "%s: failed to get optimum mode for %s @" |
1823 | " %d uA %d -> %d uV\n", __func__, rdev->desc->name, | 1821 | " %d uA %d -> %d uV\n", __func__, rdev_get_name(rdev), |
1824 | total_uA_load, input_uV, output_uV); | 1822 | total_uA_load, input_uV, output_uV); |
1825 | goto out; | 1823 | goto out; |
1826 | } | 1824 | } |
@@ -1828,7 +1826,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load) | |||
1828 | ret = rdev->desc->ops->set_mode(rdev, mode); | 1826 | ret = rdev->desc->ops->set_mode(rdev, mode); |
1829 | if (ret < 0) { | 1827 | if (ret < 0) { |
1830 | printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n", | 1828 | printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n", |
1831 | __func__, mode, rdev->desc->name); | 1829 | __func__, mode, rdev_get_name(rdev)); |
1832 | goto out; | 1830 | goto out; |
1833 | } | 1831 | } |
1834 | ret = mode; | 1832 | ret = mode; |
@@ -2346,7 +2344,7 @@ int regulator_suspend_prepare(suspend_state_t state) | |||
2346 | 2344 | ||
2347 | if (ret < 0) { | 2345 | if (ret < 0) { |
2348 | printk(KERN_ERR "%s: failed to prepare %s\n", | 2346 | printk(KERN_ERR "%s: failed to prepare %s\n", |
2349 | __func__, rdev->desc->name); | 2347 | __func__, rdev_get_name(rdev)); |
2350 | goto out; | 2348 | goto out; |
2351 | } | 2349 | } |
2352 | } | 2350 | } |
@@ -2459,12 +2457,7 @@ static int __init regulator_init_complete(void) | |||
2459 | ops = rdev->desc->ops; | 2457 | ops = rdev->desc->ops; |
2460 | c = rdev->constraints; | 2458 | c = rdev->constraints; |
2461 | 2459 | ||
2462 | if (c && c->name) | 2460 | name = rdev_get_name(rdev); |
2463 | name = c->name; | ||
2464 | else if (rdev->desc->name) | ||
2465 | name = rdev->desc->name; | ||
2466 | else | ||
2467 | name = "regulator"; | ||
2468 | 2461 | ||
2469 | if (!ops->disable || (c && c->always_on)) | 2462 | if (!ops->disable || (c && c->always_on)) |
2470 | continue; | 2463 | continue; |