Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

regulator: devres: Add devm_regulator_bulk_get_exclusive()

We had an exclusive variant of the devm_regulator_get() API, but no
corresponding variant for the bulk API; let's add one now. We add a
generalized version of the existing regulator_bulk_get() function that
additionally takes a get_type parameter and redefine
regulator_bulk_get() in terms of it, then do similarly with
devm_regulator_bulk_get(), and finally add the new
devm_regulator_bulk_get_exclusive().

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Link: https://lore.kernel.org/r/20221031233704.22575-2-zev@bewilderbeest.net
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Zev Weiss and committed by
Mark Brown
fd184506 9abf2313

+76 -36
+24 -18
drivers/regulator/core.c
··· 4778 4778 return blocking_notifier_call_chain(&rdev->notifier, event, data); 4779 4779 } 4780 4780 4781 - /** 4782 - * regulator_bulk_get - get multiple regulator consumers 4783 - * 4784 - * @dev: Device to supply 4785 - * @num_consumers: Number of consumers to register 4786 - * @consumers: Configuration of consumers; clients are stored here. 4787 - * 4788 - * @return 0 on success, an errno on failure. 4789 - * 4790 - * This helper function allows drivers to get several regulator 4791 - * consumers in one operation. If any of the regulators cannot be 4792 - * acquired then any regulators that were allocated will be freed 4793 - * before returning to the caller. 4794 - */ 4795 - int regulator_bulk_get(struct device *dev, int num_consumers, 4796 - struct regulator_bulk_data *consumers) 4781 + int _regulator_bulk_get(struct device *dev, int num_consumers, 4782 + struct regulator_bulk_data *consumers, enum regulator_get_type get_type) 4797 4783 { 4798 4784 int i; 4799 4785 int ret; ··· 4788 4802 consumers[i].consumer = NULL; 4789 4803 4790 4804 for (i = 0; i < num_consumers; i++) { 4791 - consumers[i].consumer = regulator_get(dev, 4792 - consumers[i].supply); 4805 + consumers[i].consumer = _regulator_get(dev, 4806 + consumers[i].supply, get_type); 4793 4807 if (IS_ERR(consumers[i].consumer)) { 4794 4808 ret = dev_err_probe(dev, PTR_ERR(consumers[i].consumer), 4795 4809 "Failed to get supply '%s'", ··· 4815 4829 regulator_put(consumers[i].consumer); 4816 4830 4817 4831 return ret; 4832 + } 4833 + 4834 + /** 4835 + * regulator_bulk_get - get multiple regulator consumers 4836 + * 4837 + * @dev: Device to supply 4838 + * @num_consumers: Number of consumers to register 4839 + * @consumers: Configuration of consumers; clients are stored here. 4840 + * 4841 + * @return 0 on success, an errno on failure. 4842 + * 4843 + * This helper function allows drivers to get several regulator 4844 + * consumers in one operation. If any of the regulators cannot be 4845 + * acquired then any regulators that were allocated will be freed 4846 + * before returning to the caller. 4847 + */ 4848 + int regulator_bulk_get(struct device *dev, int num_consumers, 4849 + struct regulator_bulk_data *consumers) 4850 + { 4851 + return _regulator_bulk_get(dev, num_consumers, consumers, NORMAL_GET); 4818 4852 } 4819 4853 EXPORT_SYMBOL_GPL(regulator_bulk_get); 4820 4854
+48 -18
drivers/regulator/devres.c
··· 186 186 regulator_bulk_free(devres->num_consumers, devres->consumers); 187 187 } 188 188 189 + static int _devm_regulator_bulk_get(struct device *dev, int num_consumers, 190 + struct regulator_bulk_data *consumers, 191 + enum regulator_get_type get_type) 192 + { 193 + struct regulator_bulk_devres *devres; 194 + int ret; 195 + 196 + devres = devres_alloc(devm_regulator_bulk_release, 197 + sizeof(*devres), GFP_KERNEL); 198 + if (!devres) 199 + return -ENOMEM; 200 + 201 + ret = _regulator_bulk_get(dev, num_consumers, consumers, get_type); 202 + if (!ret) { 203 + devres->consumers = consumers; 204 + devres->num_consumers = num_consumers; 205 + devres_add(dev, devres); 206 + } else { 207 + devres_free(devres); 208 + } 209 + 210 + return ret; 211 + } 212 + 189 213 /** 190 214 * devm_regulator_bulk_get - managed get multiple regulator consumers 191 215 * ··· 228 204 int devm_regulator_bulk_get(struct device *dev, int num_consumers, 229 205 struct regulator_bulk_data *consumers) 230 206 { 231 - struct regulator_bulk_devres *devres; 232 - int ret; 233 - 234 - devres = devres_alloc(devm_regulator_bulk_release, 235 - sizeof(*devres), GFP_KERNEL); 236 - if (!devres) 237 - return -ENOMEM; 238 - 239 - ret = regulator_bulk_get(dev, num_consumers, consumers); 240 - if (!ret) { 241 - devres->consumers = consumers; 242 - devres->num_consumers = num_consumers; 243 - devres_add(dev, devres); 244 - } else { 245 - devres_free(devres); 246 - } 247 - 248 - return ret; 207 + return _devm_regulator_bulk_get(dev, num_consumers, consumers, NORMAL_GET); 249 208 } 250 209 EXPORT_SYMBOL_GPL(devm_regulator_bulk_get); 210 + 211 + /** 212 + * devm_regulator_bulk_get_exclusive - managed exclusive get of multiple 213 + * regulator consumers 214 + * 215 + * @dev: device to supply 216 + * @num_consumers: number of consumers to register 217 + * @consumers: configuration of consumers; clients are stored here. 218 + * 219 + * @return 0 on success, an errno on failure. 220 + * 221 + * This helper function allows drivers to exclusively get several 222 + * regulator consumers in one operation with management, the regulators 223 + * will automatically be freed when the device is unbound. If any of 224 + * the regulators cannot be acquired then any regulators that were 225 + * allocated will be freed before returning to the caller. 226 + */ 227 + int devm_regulator_bulk_get_exclusive(struct device *dev, int num_consumers, 228 + struct regulator_bulk_data *consumers) 229 + { 230 + return _devm_regulator_bulk_get(dev, num_consumers, consumers, EXCLUSIVE_GET); 231 + } 232 + EXPORT_SYMBOL_GPL(devm_regulator_bulk_get_exclusive); 251 233 252 234 /** 253 235 * devm_regulator_bulk_get_const - devm_regulator_bulk_get() w/ const data
+2
drivers/regulator/internal.h
··· 122 122 123 123 struct regulator *_regulator_get(struct device *dev, const char *id, 124 124 enum regulator_get_type get_type); 125 + int _regulator_bulk_get(struct device *dev, int num_consumers, 126 + struct regulator_bulk_data *consumers, enum regulator_get_type get_type); 125 127 #endif
+2
include/linux/regulator/consumer.h
··· 247 247 int __must_check devm_regulator_bulk_get(struct device *dev, int num_consumers, 248 248 struct regulator_bulk_data *consumers); 249 249 void devm_regulator_bulk_put(struct regulator_bulk_data *consumers); 250 + int __must_check devm_regulator_bulk_get_exclusive(struct device *dev, int num_consumers, 251 + struct regulator_bulk_data *consumers); 250 252 int __must_check devm_regulator_bulk_get_const( 251 253 struct device *dev, int num_consumers, 252 254 const struct regulator_bulk_data *in_consumers,