public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Pratyush Yadav <p.yadav@ti.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 1/8] regmap: Add devm_regmap_init()
Date: Sat, 6 Jun 2020 02:00:18 +0530	[thread overview]
Message-ID: <20200605203025.15466-2-p.yadav@ti.com> (raw)
In-Reply-To: <20200605203025.15466-1-p.yadav@ti.com>

From: Jean-Jacques Hiblot <jjhiblot@ti.com>

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>
---
 drivers/core/regmap.c | 29 +++++++++++++++++++++++++++++
 include/regmap.h      | 18 ++++++++++++++++++
 2 files changed, 47 insertions(+)

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)
diff --git a/include/regmap.h b/include/regmap.h
index 30183c5e71..c7dd240a74 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -75,6 +75,9 @@ struct regmap_range {
 	ulong size;
 };
 
+struct regmap_bus;
+struct regmap_config;
+
 /**
  * struct regmap - a way of accessing hardware/bus registers
  *
@@ -335,6 +338,21 @@ int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,
 
 int regmap_init_mem_index(ofnode node, struct regmap **mapp, int index);
 
+/**
+ * devm_regmap_init() - Initialise register map (device managed)
+ *
+ * @dev: Device that will be interacted with
+ * @bus: Bus-specific callbacks to use with device (IGNORED)
+ * @bus_context: Data passed to bus-specific callbacks (IGNORED)
+ * @config: Configuration for register map (IGNORED)
+ *
+ * @Return a valid pointer to a struct regmap or a ERR_PTR() on error.
+ * The structure is automatically freed when the device is unbound
+ */
+struct regmap *devm_regmap_init(struct udevice *dev,
+				const struct regmap_bus *bus,
+				void *bus_context,
+				const struct regmap_config *config);
 /**
  * regmap_get_range() - Obtain the base memory address of a regmap range
  *
-- 
2.27.0

  reply	other threads:[~2020-06-05 20:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-05 20:30 [PATCH v2 0/8] regmap: Add managed API, regmap fields, regmap config Pratyush Yadav
2020-06-05 20:30 ` Pratyush Yadav [this message]
2020-06-05 20:30 ` [PATCH v2 2/8] regmap: zero out the regmap on allocation Pratyush Yadav
2020-06-05 20:30 ` [PATCH v2 3/8] regmap: Allow specifying read/write width Pratyush Yadav
2020-06-05 20:30 ` [PATCH v2 4/8] regmap: Allow left shifting register offset before access Pratyush Yadav
2020-06-05 20:30 ` [PATCH v2 5/8] regmap: Add regmap_init_mem_range() Pratyush Yadav
2020-06-05 20:30 ` [PATCH v2 6/8] regmap: Allow devices to specify regmap range start and size in config Pratyush Yadav
2020-06-05 20:30 ` [PATCH v2 7/8] regmap: Add support for regmap fields Pratyush Yadav
2020-06-05 20:30 ` [PATCH v2 8/8] test: dm: Add tests for regmap managed API and " Pratyush Yadav
2020-08-06 14:25   ` Tom Rini
2020-08-05  8:07 ` [PATCH v2 0/8] regmap: Add managed API, regmap fields, regmap config Pratyush Yadav
2020-08-16  3:39   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200605203025.15466-2-p.yadav@ti.com \
    --to=p.yadav@ti.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox