diff options
Diffstat (limited to 'drivers/mfd/stpmic1.c')
-rw-r--r-- | drivers/mfd/stpmic1.c | 60 |
1 files changed, 10 insertions, 50 deletions
diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c index ab13ded0ec..9985673aa6 100644 --- a/drivers/mfd/stpmic1.c +++ b/drivers/mfd/stpmic1.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2019 Ahmad Fatoum, Pengutronix */ @@ -8,66 +8,25 @@ #include <errno.h> #include <i2c/i2c.h> #include <init.h> -#include <malloc.h> #include <of.h> -#include <regmap.h> -#include <xfuncs.h> +#include <linux/regmap.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, .max_register = 0xB3, }; -static int __init stpmic1_probe(struct device_d *dev) +static int __init stpmic1_probe(struct device *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) @@ -80,18 +39,19 @@ static int __init stpmic1_probe(struct device_d *dev) } dev_info(dev, "PMIC Chip Version: 0x%x\n", reg); - return of_platform_populate(dev->device_node, NULL, dev); + return of_platform_populate(dev->of_node, NULL, dev); } static __maybe_unused struct of_device_id stpmic1_dt_ids[] = { { .compatible = "st,stpmic1" }, { /* sentinel */ } }; +MODULE_DEVICE_TABLE(of, stpmic1_dt_ids); -static struct driver_d stpmic1_i2c_driver = { +static struct driver stpmic1_i2c_driver = { .name = "stpmic1-i2c", .probe = stpmic1_probe, .of_compatible = DRV_OF_COMPAT(stpmic1_dt_ids), }; -device_i2c_driver(stpmic1_i2c_driver); +coredevice_i2c_driver(stpmic1_i2c_driver); |