^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * drivers/extcon/devres.c - EXTCON device's resource management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2016 Samsung Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Chanwoo Choi <cw00.choi@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "extcon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) static int devm_extcon_dev_match(struct device *dev, void *res, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) struct extcon_dev **r = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) if (WARN_ON(!r || !*r))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) return *r == data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static void devm_extcon_dev_release(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) extcon_dev_free(*(struct extcon_dev **)res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static void devm_extcon_dev_unreg(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) extcon_dev_unregister(*(struct extcon_dev **)res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct extcon_dev_notifier_devres {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct extcon_dev *edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct notifier_block *nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static void devm_extcon_dev_notifier_unreg(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct extcon_dev_notifier_devres *this = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) extcon_unregister_notifier(this->edev, this->id, this->nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static void devm_extcon_dev_notifier_all_unreg(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct extcon_dev_notifier_devres *this = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) extcon_unregister_notifier_all(this->edev, this->nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * devm_extcon_dev_allocate - Allocate managed extcon device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * @dev: the device owning the extcon device being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * @supported_cable: the array of the supported external connectors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * ending with EXTCON_NONE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * This function manages automatically the memory of extcon device using device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * resource management and simplify the control of freeing the memory of extcon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * Returns the pointer memory of allocated extcon_dev if success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * or ERR_PTR(err) if fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) const unsigned int *supported_cable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct extcon_dev **ptr, *edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ptr = devres_alloc(devm_extcon_dev_release, sizeof(*ptr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) edev = extcon_dev_allocate(supported_cable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (IS_ERR(edev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) devres_free(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) edev->dev.parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *ptr = edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) devres_add(dev, ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) EXPORT_SYMBOL_GPL(devm_extcon_dev_allocate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * devm_extcon_dev_free() - Resource-managed extcon_dev_unregister()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * @dev: the device owning the extcon device being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * @edev: the extcon device to be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * Free the memory that is allocated with devm_extcon_dev_allocate()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) WARN_ON(devres_release(dev, devm_extcon_dev_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) devm_extcon_dev_match, edev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) EXPORT_SYMBOL_GPL(devm_extcon_dev_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * devm_extcon_dev_register() - Resource-managed extcon_dev_register()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * @dev: the device owning the extcon device being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @edev: the extcon device to be registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * this function, that extcon device is automatically unregistered on driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * detach. Internally this function calls extcon_dev_register() function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * To get more information, refer that function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * If extcon device is registered with this function and the device needs to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * unregistered separately, devm_extcon_dev_unregister() should be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * Returns 0 if success or negaive error number if failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int devm_extcon_dev_register(struct device *dev, struct extcon_dev *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct extcon_dev **ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ptr = devres_alloc(devm_extcon_dev_unreg, sizeof(*ptr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) ret = extcon_dev_register(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) devres_free(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) *ptr = edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) devres_add(dev, ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) EXPORT_SYMBOL_GPL(devm_extcon_dev_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * devm_extcon_dev_unregister() - Resource-managed extcon_dev_unregister()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * @dev: the device owning the extcon device being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * @edev: the extcon device to unregistered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * Unregister extcon device that is registered with devm_extcon_dev_register()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) void devm_extcon_dev_unregister(struct device *dev, struct extcon_dev *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) WARN_ON(devres_release(dev, devm_extcon_dev_unreg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) devm_extcon_dev_match, edev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) EXPORT_SYMBOL_GPL(devm_extcon_dev_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * devm_extcon_register_notifier() - Resource-managed extcon_register_notifier()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * @dev: the device owning the extcon device being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * @edev: the extcon device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * @id: the unique id among the extcon enumeration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * @nb: a notifier block to be registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * This function manages automatically the notifier of extcon device using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * device resource management and simplify the control of unregistering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * the notifier of extcon device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * Note that the second parameter given to the callback of nb (val) is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * "old_state", not the current state. The current state can be retrieved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * by looking at the third pameter (edev pointer)'s state value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * Returns 0 if success or negaive error number if failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int devm_extcon_register_notifier(struct device *dev, struct extcon_dev *edev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) unsigned int id, struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct extcon_dev_notifier_devres *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) ptr = devres_alloc(devm_extcon_dev_notifier_unreg, sizeof(*ptr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) ret = extcon_register_notifier(edev, id, nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) devres_free(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) ptr->edev = edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ptr->id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ptr->nb = nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) devres_add(dev, ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) EXPORT_SYMBOL(devm_extcon_register_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * devm_extcon_unregister_notifier()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * - Resource-managed extcon_unregister_notifier()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * @dev: the device owning the extcon device being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * @edev: the extcon device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * @id: the unique id among the extcon enumeration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * @nb: a notifier block to be registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) void devm_extcon_unregister_notifier(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct extcon_dev *edev, unsigned int id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) WARN_ON(devres_release(dev, devm_extcon_dev_notifier_unreg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) devm_extcon_dev_match, edev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) EXPORT_SYMBOL(devm_extcon_unregister_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * devm_extcon_register_notifier_all()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * - Resource-managed extcon_register_notifier_all()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * @dev: the device owning the extcon device being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * @edev: the extcon device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * @nb: a notifier block to be registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * This function manages automatically the notifier of extcon device using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * device resource management and simplify the control of unregistering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * the notifier of extcon device. To get more information, refer that function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * Returns 0 if success or negaive error number if failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int devm_extcon_register_notifier_all(struct device *dev, struct extcon_dev *edev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct extcon_dev_notifier_devres *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) ptr = devres_alloc(devm_extcon_dev_notifier_all_unreg, sizeof(*ptr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) ret = extcon_register_notifier_all(edev, nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) devres_free(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) ptr->edev = edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) ptr->nb = nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) devres_add(dev, ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) EXPORT_SYMBOL(devm_extcon_register_notifier_all);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * devm_extcon_unregister_notifier_all()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * - Resource-managed extcon_unregister_notifier_all()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * @dev: the device owning the extcon device being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * @edev: the extcon device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * @nb: a notifier block to be registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) void devm_extcon_unregister_notifier_all(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct extcon_dev *edev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) WARN_ON(devres_release(dev, devm_extcon_dev_notifier_all_unreg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) devm_extcon_dev_match, edev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) EXPORT_SYMBOL(devm_extcon_unregister_notifier_all);