mfd: bd718x7: simplify by cleaning unnecessary device data

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>
This commit is contained in:
Matti Vaittinen 2021-04-05 14:40:44 +03:00 committed by Lee Jones
parent f87c0d2e6c
commit 316d0d92fb
2 changed files with 16 additions and 40 deletions

View File

@ -91,9 +91,9 @@ static const struct regmap_config bd718xx_regmap_config = {
.cache_type = REGCACHE_RBTREE, .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_ms, long_press_ms;
u32 short_press_value, long_press_value; u32 short_press_value, long_press_value;
int ret; int ret;
@ -102,8 +102,7 @@ static int bd718xx_init_press_duration(struct bd718xx *bd718xx)
&short_press_ms); &short_press_ms);
if (!ret) { if (!ret) {
short_press_value = min(15u, (short_press_ms + 250) / 500); short_press_value = min(15u, (short_press_ms + 250) / 500);
ret = regmap_update_bits(bd718xx->chip.regmap, ret = regmap_update_bits(regmap, BD718XX_REG_PWRONCONFIG0,
BD718XX_REG_PWRONCONFIG0,
BD718XX_PWRBTN_PRESS_DURATION_MASK, BD718XX_PWRBTN_PRESS_DURATION_MASK,
short_press_value); short_press_value);
if (ret) { if (ret) {
@ -116,8 +115,7 @@ static int bd718xx_init_press_duration(struct bd718xx *bd718xx)
&long_press_ms); &long_press_ms);
if (!ret) { if (!ret) {
long_press_value = min(15u, (long_press_ms + 500) / 1000); long_press_value = min(15u, (long_press_ms + 500) / 1000);
ret = regmap_update_bits(bd718xx->chip.regmap, ret = regmap_update_bits(regmap, BD718XX_REG_PWRONCONFIG1,
BD718XX_REG_PWRONCONFIG1,
BD718XX_PWRBTN_PRESS_DURATION_MASK, BD718XX_PWRBTN_PRESS_DURATION_MASK,
long_press_value); long_press_value);
if (ret) { if (ret) {
@ -132,7 +130,8 @@ static int bd718xx_init_press_duration(struct bd718xx *bd718xx)
static int bd718xx_i2c_probe(struct i2c_client *i2c, static int bd718xx_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct bd718xx *bd718xx; struct regmap *regmap;
struct regmap_irq_chip_data *irq_data;
int ret; int ret;
unsigned int chip_type; unsigned int chip_type;
struct mfd_cell *mfd; 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"); dev_err(&i2c->dev, "No IRQ configured\n");
return -EINVAL; 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) chip_type = (unsigned int)(uintptr_t)
of_device_get_match_data(&i2c->dev); of_device_get_match_data(&i2c->dev);
switch (chip_type) { switch (chip_type) {
@ -164,29 +156,26 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c,
dev_err(&i2c->dev, "Unknown device type"); dev_err(&i2c->dev, "Unknown device type");
return -EINVAL; return -EINVAL;
} }
bd718xx->chip.dev = &i2c->dev;
dev_set_drvdata(&i2c->dev, bd718xx);
bd718xx->chip.regmap = devm_regmap_init_i2c(i2c, regmap = devm_regmap_init_i2c(i2c, &bd718xx_regmap_config);
&bd718xx_regmap_config); if (IS_ERR(regmap)) {
if (IS_ERR(bd718xx->chip.regmap)) {
dev_err(&i2c->dev, "regmap initialization failed\n"); 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, ret = devm_regmap_add_irq_chip(&i2c->dev, regmap, i2c->irq,
bd718xx->chip_irq, IRQF_ONESHOT, 0, IRQF_ONESHOT, 0, &bd718xx_irq_chip,
&bd718xx_irq_chip, &bd718xx->irq_data); &irq_data);
if (ret) { if (ret) {
dev_err(&i2c->dev, "Failed to add irq_chip\n"); dev_err(&i2c->dev, "Failed to add irq_chip\n");
return ret; return ret;
} }
ret = bd718xx_init_press_duration(bd718xx); ret = bd718xx_init_press_duration(regmap, &i2c->dev);
if (ret) if (ret)
return 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) { if (ret < 0) {
dev_err(&i2c->dev, "Failed to get the IRQ\n"); 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; 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, mfd, cells, NULL, 0,
regmap_irq_get_domain(bd718xx->irq_data)); regmap_irq_get_domain(irq_data));
if (ret) if (ret)
dev_err(&i2c->dev, "Failed to create subdevices\n"); dev_err(&i2c->dev, "Failed to create subdevices\n");

View File

@ -310,17 +310,4 @@ enum {
BD718XX_PWRBTN_LONG_PRESS_15S 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__ */ #endif /* __LINUX_MFD_BD718XX_H__ */