mfd: bd718x7: simplify by cleaning unnecessary device data
authorMatti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Mon, 5 Apr 2021 11:40:44 +0000 (14:40 +0300)
committerLee Jones <lee.jones@linaro.org>
Wed, 14 Apr 2021 09:17:53 +0000 (10:17 +0100)
Most ROHM PMIC sub-devices only use the regmap pointer from
parent device. They can obtain this by dev_get_regamap so in
most cases the MFD device does not need to allocate and populate
the driver data. Simplify drivers by removing this.

The BD70528 still needs the access to watchdog mutex so keep
rohm_regmap_dev in use on BD70528 RTC and WDG drivers for now.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
drivers/mfd/rohm-bd718x7.c
include/linux/mfd/rohm-bd718x7.h

index c32c1b6c98fa3463db2226547f570f43edca61ec..bfd81f78beaee133de09301916f3dc7500b6f51e 100644 (file)
@@ -91,9 +91,9 @@ static const struct regmap_config bd718xx_regmap_config = {
        .cache_type = REGCACHE_RBTREE,
 };
 
-static int bd718xx_init_press_duration(struct bd718xx *bd718xx)
+static int bd718xx_init_press_duration(struct regmap *regmap,
+                                      struct device *dev)
 {
-       struct device* dev = bd718xx->chip.dev;
        u32 short_press_ms, long_press_ms;
        u32 short_press_value, long_press_value;
        int ret;
@@ -102,8 +102,7 @@ static int bd718xx_init_press_duration(struct bd718xx *bd718xx)
                                   &short_press_ms);
        if (!ret) {
                short_press_value = min(15u, (short_press_ms + 250) / 500);
-               ret = regmap_update_bits(bd718xx->chip.regmap,
-                                        BD718XX_REG_PWRONCONFIG0,
+               ret = regmap_update_bits(regmap, BD718XX_REG_PWRONCONFIG0,
                                         BD718XX_PWRBTN_PRESS_DURATION_MASK,
                                         short_press_value);
                if (ret) {
@@ -116,8 +115,7 @@ static int bd718xx_init_press_duration(struct bd718xx *bd718xx)
                                   &long_press_ms);
        if (!ret) {
                long_press_value = min(15u, (long_press_ms + 500) / 1000);
-               ret = regmap_update_bits(bd718xx->chip.regmap,
-                                        BD718XX_REG_PWRONCONFIG1,
+               ret = regmap_update_bits(regmap, BD718XX_REG_PWRONCONFIG1,
                                         BD718XX_PWRBTN_PRESS_DURATION_MASK,
                                         long_press_value);
                if (ret) {
@@ -132,7 +130,8 @@ static int bd718xx_init_press_duration(struct bd718xx *bd718xx)
 static int bd718xx_i2c_probe(struct i2c_client *i2c,
                            const struct i2c_device_id *id)
 {
-       struct bd718xx *bd718xx;
+       struct regmap *regmap;
+       struct regmap_irq_chip_data *irq_data;
        int ret;
        unsigned int chip_type;
        struct mfd_cell *mfd;
@@ -142,13 +141,6 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c,
                dev_err(&i2c->dev, "No IRQ configured\n");
                return -EINVAL;
        }
-
-       bd718xx = devm_kzalloc(&i2c->dev, sizeof(struct bd718xx), GFP_KERNEL);
-
-       if (!bd718xx)
-               return -ENOMEM;
-
-       bd718xx->chip_irq = i2c->irq;
        chip_type = (unsigned int)(uintptr_t)
                    of_device_get_match_data(&i2c->dev);
        switch (chip_type) {
@@ -164,29 +156,26 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c,
                dev_err(&i2c->dev, "Unknown device type");
                return -EINVAL;
        }
-       bd718xx->chip.dev = &i2c->dev;
-       dev_set_drvdata(&i2c->dev, bd718xx);
 
-       bd718xx->chip.regmap = devm_regmap_init_i2c(i2c,
-                                                   &bd718xx_regmap_config);
-       if (IS_ERR(bd718xx->chip.regmap)) {
+       regmap = devm_regmap_init_i2c(i2c, &bd718xx_regmap_config);
+       if (IS_ERR(regmap)) {
                dev_err(&i2c->dev, "regmap initialization failed\n");
-               return PTR_ERR(bd718xx->chip.regmap);
+               return PTR_ERR(regmap);
        }
 
-       ret = devm_regmap_add_irq_chip(&i2c->dev, bd718xx->chip.regmap,
-                                      bd718xx->chip_irq, IRQF_ONESHOT, 0,
-                                      &bd718xx_irq_chip, &bd718xx->irq_data);
+       ret = devm_regmap_add_irq_chip(&i2c->dev, regmap, i2c->irq,
+                                      IRQF_ONESHOT, 0, &bd718xx_irq_chip,
+                                      &irq_data);
        if (ret) {
                dev_err(&i2c->dev, "Failed to add irq_chip\n");
                return ret;
        }
 
-       ret = bd718xx_init_press_duration(bd718xx);
+       ret = bd718xx_init_press_duration(regmap, &i2c->dev);
        if (ret)
                return ret;
 
-       ret = regmap_irq_get_virq(bd718xx->irq_data, BD718XX_INT_PWRBTN_S);
+       ret = regmap_irq_get_virq(irq_data, BD718XX_INT_PWRBTN_S);
 
        if (ret < 0) {
                dev_err(&i2c->dev, "Failed to get the IRQ\n");
@@ -195,9 +184,9 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c,
 
        button.irq = ret;
 
-       ret = devm_mfd_add_devices(bd718xx->chip.dev, PLATFORM_DEVID_AUTO,
+       ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
                                   mfd, cells, NULL, 0,
-                                  regmap_irq_get_domain(bd718xx->irq_data));
+                                  regmap_irq_get_domain(irq_data));
        if (ret)
                dev_err(&i2c->dev, "Failed to create subdevices\n");
 
index bee2474a8f9fc03bcc3e047c05c8bcb3ddb7c984..df2918198d37179a116e3a2c9ad6b1dea668e71d 100644 (file)
@@ -310,17 +310,4 @@ enum {
        BD718XX_PWRBTN_LONG_PRESS_15S
 };
 
-struct bd718xx {
-       /*
-        * Please keep this as the first member here as some
-        * drivers (clk) supporting more than one chip may only know this
-        * generic struct 'struct rohm_regmap_dev' and assume it is
-        * the first chunk of parent device's private data.
-        */
-       struct rohm_regmap_dev chip;
-
-       int chip_irq;
-       struct regmap_irq_chip_data *irq_data;
-};
-
 #endif /* __LINUX_MFD_BD718XX_H__ */