summaryrefslogtreecommitdiff
path: root/backport/compat
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke@hauke-m.de>2013-10-24 19:57:26 +0200
committerHauke Mehrtens <hauke@hauke-m.de>2013-10-24 21:38:17 +0200
commitb713be73fb5b22cedb7df136af871f17b6941672 (patch)
tree687d70577641e5342f52b05939872a2451430828 /backport/compat
parent66af89a4a44179db5e7e7729bcf12ad474352ba0 (diff)
backports: add devm_regulator_register()
This backports the following commit from mainline: commit b33e46bcdc4e598d738ed12a5a7906be4e11d786 Author: Mark Brown <broonie@linaro.org> Date: Sat Aug 31 11:58:26 2013 +0100 regulator: core: Provide managed regulator registration Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Diffstat (limited to 'backport/compat')
-rw-r--r--backport/compat/Makefile1
-rw-r--r--backport/compat/backport-3.13.c83
2 files changed, 84 insertions, 0 deletions
diff --git a/backport/compat/Makefile b/backport/compat/Makefile
index 44855522..dbf2bffa 100644
--- a/backport/compat/Makefile
+++ b/backport/compat/Makefile
@@ -35,6 +35,7 @@ compat-$(CPTCFG_BACKPORT_KERNEL_3_8) += compat-3.8.o
compat-$(CPTCFG_BACKPORT_KERNEL_3_9) += compat-3.9.o
compat-$(CPTCFG_BACKPORT_KERNEL_3_10) += backport-3.10.o
compat-$(CPTCFG_BACKPORT_KERNEL_3_12) += backport-3.12.o
+compat-$(CPTCFG_BACKPORT_KERNEL_3_13) += backport-3.13.o
compat-$(CPTCFG_BACKPORT_BUILD_KFIFO) += kfifo.o
compat-$(CPTCFG_BACKPORT_BUILD_GENERIC_ATOMIC64) += compat_atomic.o
diff --git a/backport/compat/backport-3.13.c b/backport/compat/backport-3.13.c
new file mode 100644
index 00000000..c99625fa
--- /dev/null
+++ b/backport/compat/backport-3.13.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2013 Hauke Mehrtens <hauke@hauke-m.de>
+ *
+ * Backport functionality introduced in Linux 3.13.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/version.h>
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0))
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/regulator/driver.h>
+#include <linux/device.h>
+
+static void devm_rdev_release(struct device *dev, void *res)
+{
+ regulator_unregister(*(struct regulator_dev **)res);
+}
+
+/**
+ * devm_regulator_register - Resource managed regulator_register()
+ * @regulator_desc: regulator to register
+ * @config: runtime configuration for regulator
+ *
+ * Called by regulator drivers to register a regulator. Returns a
+ * valid pointer to struct regulator_dev on success or an ERR_PTR() on
+ * error. The regulator will automatically be released when the device
+ * is unbound.
+ */
+struct regulator_dev *devm_regulator_register(struct device *dev,
+ const struct regulator_desc *regulator_desc,
+ const struct regulator_config *config)
+{
+ struct regulator_dev **ptr, *rdev;
+
+ ptr = devres_alloc(devm_rdev_release, sizeof(*ptr),
+ GFP_KERNEL);
+ if (!ptr)
+ return ERR_PTR(-ENOMEM);
+
+ rdev = regulator_register(regulator_desc, config);
+ if (!IS_ERR(rdev)) {
+ *ptr = rdev;
+ devres_add(dev, ptr);
+ } else {
+ devres_free(ptr);
+ }
+
+ return rdev;
+}
+EXPORT_SYMBOL_GPL(devm_regulator_register);
+
+static int devm_rdev_match(struct device *dev, void *res, void *data)
+{
+ struct regulator_dev **r = res;
+ if (!r || !*r) {
+ WARN_ON(!r || !*r);
+ return 0;
+ }
+ return *r == data;
+}
+
+/**
+ * devm_regulator_unregister - Resource managed regulator_unregister()
+ * @regulator: regulator to free
+ *
+ * Unregister a regulator registered with devm_regulator_register().
+ * Normally this function will not need to be called and the resource
+ * management code will ensure that the resource is freed.
+ */
+void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev)
+{
+ int rc;
+
+ rc = devres_release(dev, devm_rdev_release, devm_rdev_match, rdev);
+ if (rc != 0)
+ WARN_ON(rc);
+}
+EXPORT_SYMBOL_GPL(devm_regulator_unregister);
+#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)) */