summaryrefslogtreecommitdiff
path: root/drivers/core
diff options
context:
space:
mode:
authorJean-Jacques Hiblot <jjhiblot@ti.com>2020-09-24 10:04:10 +0530
committerTom Rini <trini@konsulko.com>2020-09-30 11:55:22 -0400
commitffb22f6b847d21b30831c91294ec21d6a5e80ed4 (patch)
treec47b83505480d280dddb4b2ad2401df7268b11f8 /drivers/core
parent88e6a60e4aeed2fec059e513572d191ce9387b07 (diff)
downloadu-boot-ffb22f6b847d21b30831c91294ec21d6a5e80ed4.tar.gz
u-boot-ffb22f6b847d21b30831c91294ec21d6a5e80ed4.tar.bz2
u-boot-ffb22f6b847d21b30831c91294ec21d6a5e80ed4.zip
regmap: Add devm_regmap_init()
Most of new linux drivers are using managed-API to allocate resources. To ease porting drivers from linux to U-Boot, introduce devm_regmap_init() as a managed API to get a regmap from the device tree. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
Diffstat (limited to 'drivers/core')
-rw-r--r--drivers/core/regmap.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index a67a237b88..74225361fd 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -14,7 +14,10 @@
#include <regmap.h>
#include <asm/io.h>
#include <dm/of_addr.h>
+#include <dm/devres.h>
#include <linux/ioport.h>
+#include <linux/compat.h>
+#include <linux/err.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -228,6 +231,32 @@ err:
return ret;
}
+
+static void devm_regmap_release(struct udevice *dev, void *res)
+{
+ regmap_uninit(*(struct regmap **)res);
+}
+
+struct regmap *devm_regmap_init(struct udevice *dev,
+ const struct regmap_bus *bus,
+ void *bus_context,
+ const struct regmap_config *config)
+{
+ int rc;
+ struct regmap **mapp;
+
+ mapp = devres_alloc(devm_regmap_release, sizeof(struct regmap *),
+ __GFP_ZERO);
+ if (unlikely(!mapp))
+ return ERR_PTR(-ENOMEM);
+
+ rc = regmap_init_mem(dev_ofnode(dev), mapp);
+ if (rc)
+ return ERR_PTR(rc);
+
+ devres_add(dev, mapp);
+ return *mapp;
+}
#endif
void *regmap_get_range(struct regmap *map, unsigned int range_num)