^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * devres.c -- Voltage/Current Regulator framework devres implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2013 Linaro Ltd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static void devm_regulator_release(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) regulator_put(*(struct regulator **)res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static struct regulator *_devm_regulator_get(struct device *dev, const char *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int get_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct regulator **ptr, *regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) regulator = _regulator_get(dev, id, get_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if (!IS_ERR(regulator)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *ptr = regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) devres_add(dev, ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) devres_free(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * devm_regulator_get - Resource managed regulator_get()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * @dev: device to supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @id: supply name or regulator ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * Managed regulator_get(). Regulators returned from this function are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * automatically regulator_put() on driver detach. See regulator_get() for more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct regulator *devm_regulator_get(struct device *dev, const char *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return _devm_regulator_get(dev, id, NORMAL_GET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) EXPORT_SYMBOL_GPL(devm_regulator_get);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * devm_regulator_get_exclusive - Resource managed regulator_get_exclusive()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * @dev: device to supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * @id: supply name or regulator ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * Managed regulator_get_exclusive(). Regulators returned from this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * are automatically regulator_put() on driver detach. See regulator_get() for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * more information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct regulator *devm_regulator_get_exclusive(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) const char *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return _devm_regulator_get(dev, id, EXCLUSIVE_GET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) EXPORT_SYMBOL_GPL(devm_regulator_get_exclusive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * devm_regulator_get_optional - Resource managed regulator_get_optional()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * @dev: device to supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * @id: supply name or regulator ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * Managed regulator_get_optional(). Regulators returned from this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * function are automatically regulator_put() on driver detach. See
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * regulator_get_optional() for more information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct regulator *devm_regulator_get_optional(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) const char *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return _devm_regulator_get(dev, id, OPTIONAL_GET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) EXPORT_SYMBOL_GPL(devm_regulator_get_optional);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static int devm_regulator_match(struct device *dev, void *res, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct regulator **r = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (!r || !*r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) WARN_ON(!r || !*r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return *r == data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * devm_regulator_put - Resource managed regulator_put()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * @regulator: regulator to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * Deallocate a regulator allocated with devm_regulator_get(). Normally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * this function will not need to be called and the resource management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * code will ensure that the resource is freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) void devm_regulator_put(struct regulator *regulator)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) rc = devres_release(regulator->dev, devm_regulator_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) devm_regulator_match, regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) WARN_ON(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) EXPORT_SYMBOL_GPL(devm_regulator_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct regulator_bulk_devres {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct regulator_bulk_data *consumers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int num_consumers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static void devm_regulator_bulk_release(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct regulator_bulk_devres *devres = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) regulator_bulk_free(devres->num_consumers, devres->consumers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * devm_regulator_bulk_get - managed get multiple regulator consumers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * @dev: device to supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * @num_consumers: number of consumers to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * @consumers: configuration of consumers; clients are stored here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * @return 0 on success, an errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * This helper function allows drivers to get several regulator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * consumers in one operation with management, the regulators will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * automatically be freed when the device is unbound. If any of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * regulators cannot be acquired then any regulators that were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * allocated will be freed before returning to the caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int devm_regulator_bulk_get(struct device *dev, int num_consumers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct regulator_bulk_data *consumers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct regulator_bulk_devres *devres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) devres = devres_alloc(devm_regulator_bulk_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) sizeof(*devres), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (!devres)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ret = regulator_bulk_get(dev, num_consumers, consumers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) devres->consumers = consumers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) devres->num_consumers = num_consumers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) devres_add(dev, devres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) devres_free(devres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) EXPORT_SYMBOL_GPL(devm_regulator_bulk_get);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static void devm_rdev_release(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) regulator_unregister(*(struct regulator_dev **)res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * devm_regulator_register - Resource managed regulator_register()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * @dev: device to supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * @regulator_desc: regulator to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * @config: runtime configuration for regulator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * Called by regulator drivers to register a regulator. Returns a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * valid pointer to struct regulator_dev on success or an ERR_PTR() on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * error. The regulator will automatically be released when the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * is unbound.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct regulator_dev *devm_regulator_register(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) const struct regulator_desc *regulator_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) const struct regulator_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct regulator_dev **ptr, *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ptr = devres_alloc(devm_rdev_release, sizeof(*ptr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) rdev = regulator_register(regulator_desc, config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (!IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) *ptr = rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) devres_add(dev, ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) devres_free(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) EXPORT_SYMBOL_GPL(devm_regulator_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static int devm_rdev_match(struct device *dev, void *res, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct regulator_dev **r = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (!r || !*r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) WARN_ON(!r || !*r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return *r == data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * devm_regulator_unregister - Resource managed regulator_unregister()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * @dev: device to supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * @rdev: regulator to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * Unregister a regulator registered with devm_regulator_register().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * Normally this function will not need to be called and the resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * management code will ensure that the resource is freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) rc = devres_release(dev, devm_rdev_release, devm_rdev_match, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) WARN_ON(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) EXPORT_SYMBOL_GPL(devm_regulator_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct regulator_supply_alias_match {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) const char *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int devm_regulator_match_supply_alias(struct device *dev, void *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct regulator_supply_alias_match *match = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct regulator_supply_alias_match *target = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return match->dev == target->dev && strcmp(match->id, target->id) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static void devm_regulator_destroy_supply_alias(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct regulator_supply_alias_match *match = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) regulator_unregister_supply_alias(match->dev, match->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * devm_regulator_register_supply_alias - Resource managed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * regulator_register_supply_alias()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * @dev: device to supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * @id: supply name or regulator ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * @alias_dev: device that should be used to lookup the supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * @alias_id: supply name or regulator ID that should be used to lookup the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * The supply alias will automatically be unregistered when the source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * device is unbound.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) int devm_regulator_register_supply_alias(struct device *dev, const char *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct device *alias_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) const char *alias_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct regulator_supply_alias_match *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) match = devres_alloc(devm_regulator_destroy_supply_alias,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) sizeof(struct regulator_supply_alias_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (!match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) match->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) match->id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ret = regulator_register_supply_alias(dev, id, alias_dev, alias_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) devres_free(match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) devres_add(dev, match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) EXPORT_SYMBOL_GPL(devm_regulator_register_supply_alias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * devm_regulator_unregister_supply_alias - Resource managed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * regulator_unregister_supply_alias()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * @dev: device to supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * @id: supply name or regulator ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * Unregister an alias registered with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * devm_regulator_register_supply_alias(). Normally this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * will not need to be called and the resource management code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * will ensure that the resource is freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) void devm_regulator_unregister_supply_alias(struct device *dev, const char *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct regulator_supply_alias_match match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) match.dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) match.id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) rc = devres_release(dev, devm_regulator_destroy_supply_alias,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) devm_regulator_match_supply_alias, &match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) WARN_ON(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) EXPORT_SYMBOL_GPL(devm_regulator_unregister_supply_alias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * devm_regulator_bulk_register_supply_alias - Managed register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * multiple aliases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * @dev: device to supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * @id: list of supply names or regulator IDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * @alias_dev: device that should be used to lookup the supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * @alias_id: list of supply names or regulator IDs that should be used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * lookup the supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * @num_id: number of aliases to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * @return 0 on success, an errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * This helper function allows drivers to register several supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * aliases in one operation, the aliases will be automatically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) * unregisters when the source device is unbound. If any of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * aliases cannot be registered any aliases that were registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * will be removed before returning to the caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) int devm_regulator_bulk_register_supply_alias(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) const char *const *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct device *alias_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) const char *const *alias_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) int num_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) for (i = 0; i < num_id; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) ret = devm_regulator_register_supply_alias(dev, id[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) alias_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) alias_id[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) "Failed to create supply alias %s,%s -> %s,%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) id[i], dev_name(dev), alias_id[i], dev_name(alias_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) while (--i >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) devm_regulator_unregister_supply_alias(dev, id[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) EXPORT_SYMBOL_GPL(devm_regulator_bulk_register_supply_alias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * devm_regulator_bulk_unregister_supply_alias - Managed unregister
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * multiple aliases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * @dev: device to supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * @id: list of supply names or regulator IDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * @num_id: number of aliases to unregister
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * Unregister aliases registered with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) * devm_regulator_bulk_register_supply_alias(). Normally this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * will not need to be called and the resource management code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * will ensure that the resource is freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) void devm_regulator_bulk_unregister_supply_alias(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) const char *const *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) int num_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) for (i = 0; i < num_id; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) devm_regulator_unregister_supply_alias(dev, id[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) EXPORT_SYMBOL_GPL(devm_regulator_bulk_unregister_supply_alias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct regulator_notifier_match {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct regulator *regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct notifier_block *nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static int devm_regulator_match_notifier(struct device *dev, void *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) struct regulator_notifier_match *match = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct regulator_notifier_match *target = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) return match->regulator == target->regulator && match->nb == target->nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static void devm_regulator_destroy_notifier(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) struct regulator_notifier_match *match = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) regulator_unregister_notifier(match->regulator, match->nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * devm_regulator_register_notifier - Resource managed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) * regulator_register_notifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * @regulator: regulator source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * @nb: notifier block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * The notifier will be registers under the consumer device and be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * automatically be unregistered when the source device is unbound.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) int devm_regulator_register_notifier(struct regulator *regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) struct regulator_notifier_match *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) match = devres_alloc(devm_regulator_destroy_notifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) sizeof(struct regulator_notifier_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (!match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) match->regulator = regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) match->nb = nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) ret = regulator_register_notifier(regulator, nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) devres_free(match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) devres_add(regulator->dev, match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) EXPORT_SYMBOL_GPL(devm_regulator_register_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * devm_regulator_unregister_notifier - Resource managed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * regulator_unregister_notifier()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * @regulator: regulator source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * @nb: notifier block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) * Unregister a notifier registered with devm_regulator_register_notifier().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * Normally this function will not need to be called and the resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * management code will ensure that the resource is freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) void devm_regulator_unregister_notifier(struct regulator *regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct regulator_notifier_match match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) match.regulator = regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) match.nb = nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) rc = devres_release(regulator->dev, devm_regulator_destroy_notifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) devm_regulator_match_notifier, &match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) WARN_ON(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) EXPORT_SYMBOL_GPL(devm_regulator_unregister_notifier);