mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/5] mfd: stpmic1: simplify using regmap_init_i2c
Date: Mon, 31 May 2021 09:24:03 +0200	[thread overview]
Message-ID: <20210531072406.5630-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210531072406.5630-1-a.fatoum@pengutronix.de>

With the new regmap_init_i2c, we can drop opencoding the regmap
accessors for the i2c registers.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mfd/stpmic1.c | 47 +++----------------------------------------
 1 file changed, 3 insertions(+), 44 deletions(-)

diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
index d22758bd6105..11154e742e5d 100644
--- a/drivers/mfd/stpmic1.c
+++ b/drivers/mfd/stpmic1.c
@@ -8,47 +8,10 @@
 #include <errno.h>
 #include <i2c/i2c.h>
 #include <init.h>
-#include <malloc.h>
 #include <of.h>
 #include <regmap.h>
-#include <xfuncs.h>
 #include <linux/mfd/stpmic1.h>
 
-struct stpmic1 {
-	struct device_d		*dev;
-	struct i2c_client	*client;
-};
-
-static int stpmic1_i2c_reg_read(void *ctx, unsigned int reg, unsigned int *val)
-{
-	struct stpmic1 *stpmic1 = ctx;
-	u8 buf[1];
-	int ret;
-
-	ret = i2c_read_reg(stpmic1->client, reg, buf, 1);
-	*val = buf[0];
-
-	return ret == 1 ? 0 : ret;
-}
-
-static int stpmic1_i2c_reg_write(void *ctx, unsigned int reg, unsigned int val)
-{
-	struct stpmic1 *stpmic1 = ctx;
-	u8 buf[] = {
-		val & 0xff,
-	};
-	int ret;
-
-	ret = i2c_write_reg(stpmic1->client, reg, buf, 1);
-
-	return ret == 1 ? 0 : ret;
-}
-
-static struct regmap_bus regmap_stpmic1_i2c_bus = {
-	.reg_write = stpmic1_i2c_reg_write,
-	.reg_read = stpmic1_i2c_reg_read,
-};
-
 static const struct regmap_config stpmic1_regmap_i2c_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
@@ -57,17 +20,13 @@ static const struct regmap_config stpmic1_regmap_i2c_config = {
 
 static int __init stpmic1_probe(struct device_d *dev)
 {
-	struct stpmic1 *stpmic1;
 	struct regmap *regmap;
 	u32 reg;
 	int ret;
 
-	stpmic1 = xzalloc(sizeof(*stpmic1));
-	stpmic1->dev = dev;
-
-	stpmic1->client = to_i2c_client(dev);
-	regmap = regmap_init(dev, &regmap_stpmic1_i2c_bus,
-			     stpmic1, &stpmic1_regmap_i2c_config);
+	regmap = regmap_init_i2c(to_i2c_client(dev), &stpmic1_regmap_i2c_config);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
 
 	ret = regmap_register_cdev(regmap, NULL);
 	if (ret)
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-05-31  7:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-31  7:24 [PATCH 0/5] add regmap helpers for NVMEM and i2c Ahmad Fatoum
2021-05-31  7:24 ` [PATCH 1/5] regmap: implement regmap_init_i2c Ahmad Fatoum
2021-05-31  7:24 ` Ahmad Fatoum [this message]
2021-05-31  7:24 ` [PATCH 3/5] nvmem: provider: align read/write callback prototype with upstream Ahmad Fatoum
2021-05-31  7:24 ` [PATCH 4/5] nvmem: add nvmem_regmap_register helper Ahmad Fatoum
2021-05-31  7:24 ` [PATCH 5/5] nvmem: stm32-bsec: simplify using new nvmem_regmap_register Ahmad Fatoum
2021-06-02  6:36 ` [PATCH 0/5] add regmap helpers for NVMEM and i2c Sascha Hauer

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=20210531072406.5630-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH 2/5] mfd: stpmic1: simplify using regmap_init_i2c' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox