diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2021-05-31 09:24:03 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-06-02 08:36:11 +0200 |
commit | 2a2c65fa6fead0daa79bd3d6667b9f63b3b2106b (patch) | |
tree | 2d108aea7a52ce6a7d1ed9a57cdb3893b0427e5a /drivers/mfd | |
parent | d827f61e149b56519fbe85b3030a72c2952aa6b0 (diff) | |
download | barebox-2a2c65fa6fead0daa79bd3d6667b9f63b3b2106b.tar.gz barebox-2a2c65fa6fead0daa79bd3d6667b9f63b3b2106b.tar.xz |
mfd: stpmic1: simplify using regmap_init_i2c
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>
Link: https://lore.barebox.org/20210531072406.5630-3-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mfd')
-rw-r--r-- | drivers/mfd/stpmic1.c | 47 |
1 files changed, 3 insertions, 44 deletions
diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c index d22758bd61..11154e742e 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, ®map_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) |