Skip to content

Commit 316d0d9

Browse files
M-VaittinenLee Jones
authored andcommitted
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>
1 parent f87c0d2 commit 316d0d9

2 files changed

Lines changed: 16 additions & 40 deletions

File tree

‎drivers/mfd/rohm-bd718x7.c‎

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ static const struct regmap_config bd718xx_regmap_config = {
9191
.cache_type = REGCACHE_RBTREE,
9292
};
9393

94-
static int bd718xx_init_press_duration(struct bd718xx *bd718xx)
94+
static int bd718xx_init_press_duration(struct regmap *regmap,
95+
struct device *dev)
9596
{
96-
struct device* dev = bd718xx->chip.dev;
9797
u32 short_press_ms, long_press_ms;
9898
u32 short_press_value, long_press_value;
9999
int ret;
@@ -102,8 +102,7 @@ static int bd718xx_init_press_duration(struct bd718xx *bd718xx)
102102
&short_press_ms);
103103
if (!ret) {
104104
short_press_value = min(15u, (short_press_ms + 250) / 500);
105-
ret = regmap_update_bits(bd718xx->chip.regmap,
106-
BD718XX_REG_PWRONCONFIG0,
105+
ret = regmap_update_bits(regmap, BD718XX_REG_PWRONCONFIG0,
107106
BD718XX_PWRBTN_PRESS_DURATION_MASK,
108107
short_press_value);
109108
if (ret) {
@@ -116,8 +115,7 @@ static int bd718xx_init_press_duration(struct bd718xx *bd718xx)
116115
&long_press_ms);
117116
if (!ret) {
118117
long_press_value = min(15u, (long_press_ms + 500) / 1000);
119-
ret = regmap_update_bits(bd718xx->chip.regmap,
120-
BD718XX_REG_PWRONCONFIG1,
118+
ret = regmap_update_bits(regmap, BD718XX_REG_PWRONCONFIG1,
121119
BD718XX_PWRBTN_PRESS_DURATION_MASK,
122120
long_press_value);
123121
if (ret) {
@@ -132,7 +130,8 @@ static int bd718xx_init_press_duration(struct bd718xx *bd718xx)
132130
static int bd718xx_i2c_probe(struct i2c_client *i2c,
133131
const struct i2c_device_id *id)
134132
{
135-
struct bd718xx *bd718xx;
133+
struct regmap *regmap;
134+
struct regmap_irq_chip_data *irq_data;
136135
int ret;
137136
unsigned int chip_type;
138137
struct mfd_cell *mfd;
@@ -142,13 +141,6 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c,
142141
dev_err(&i2c->dev, "No IRQ configured\n");
143142
return -EINVAL;
144143
}
145-
146-
bd718xx = devm_kzalloc(&i2c->dev, sizeof(struct bd718xx), GFP_KERNEL);
147-
148-
if (!bd718xx)
149-
return -ENOMEM;
150-
151-
bd718xx->chip_irq = i2c->irq;
152144
chip_type = (unsigned int)(uintptr_t)
153145
of_device_get_match_data(&i2c->dev);
154146
switch (chip_type) {
@@ -164,29 +156,26 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c,
164156
dev_err(&i2c->dev, "Unknown device type");
165157
return -EINVAL;
166158
}
167-
bd718xx->chip.dev = &i2c->dev;
168-
dev_set_drvdata(&i2c->dev, bd718xx);
169159

170-
bd718xx->chip.regmap = devm_regmap_init_i2c(i2c,
171-
&bd718xx_regmap_config);
172-
if (IS_ERR(bd718xx->chip.regmap)) {
160+
regmap = devm_regmap_init_i2c(i2c, &bd718xx_regmap_config);
161+
if (IS_ERR(regmap)) {
173162
dev_err(&i2c->dev, "regmap initialization failed\n");
174-
return PTR_ERR(bd718xx->chip.regmap);
163+
return PTR_ERR(regmap);
175164
}
176165

177-
ret = devm_regmap_add_irq_chip(&i2c->dev, bd718xx->chip.regmap,
178-
bd718xx->chip_irq, IRQF_ONESHOT, 0,
179-
&bd718xx_irq_chip, &bd718xx->irq_data);
166+
ret = devm_regmap_add_irq_chip(&i2c->dev, regmap, i2c->irq,
167+
IRQF_ONESHOT, 0, &bd718xx_irq_chip,
168+
&irq_data);
180169
if (ret) {
181170
dev_err(&i2c->dev, "Failed to add irq_chip\n");
182171
return ret;
183172
}
184173

185-
ret = bd718xx_init_press_duration(bd718xx);
174+
ret = bd718xx_init_press_duration(regmap, &i2c->dev);
186175
if (ret)
187176
return ret;
188177

189-
ret = regmap_irq_get_virq(bd718xx->irq_data, BD718XX_INT_PWRBTN_S);
178+
ret = regmap_irq_get_virq(irq_data, BD718XX_INT_PWRBTN_S);
190179

191180
if (ret < 0) {
192181
dev_err(&i2c->dev, "Failed to get the IRQ\n");
@@ -195,9 +184,9 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c,
195184

196185
button.irq = ret;
197186

198-
ret = devm_mfd_add_devices(bd718xx->chip.dev, PLATFORM_DEVID_AUTO,
187+
ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
199188
mfd, cells, NULL, 0,
200-
regmap_irq_get_domain(bd718xx->irq_data));
189+
regmap_irq_get_domain(irq_data));
201190
if (ret)
202191
dev_err(&i2c->dev, "Failed to create subdevices\n");
203192

‎include/linux/mfd/rohm-bd718x7.h‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,4 @@ enum {
310310
BD718XX_PWRBTN_LONG_PRESS_15S
311311
};
312312

313-
struct bd718xx {
314-
/*
315-
* Please keep this as the first member here as some
316-
* drivers (clk) supporting more than one chip may only know this
317-
* generic struct 'struct rohm_regmap_dev' and assume it is
318-
* the first chunk of parent device's private data.
319-
*/
320-
struct rohm_regmap_dev chip;
321-
322-
int chip_irq;
323-
struct regmap_irq_chip_data *irq_data;
324-
};
325-
326313
#endif /* __LINUX_MFD_BD718XX_H__ */

0 commit comments

Comments
 (0)