Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Matti Vaittinen and committed by
Lee Jones
316d0d92 f87c0d2e

+16 -40
+16 -27
drivers/mfd/rohm-bd718x7.c
··· 91 91 .cache_type = REGCACHE_RBTREE, 92 92 }; 93 93 94 - static int bd718xx_init_press_duration(struct bd718xx *bd718xx) 94 + static int bd718xx_init_press_duration(struct regmap *regmap, 95 + struct device *dev) 95 96 { 96 - struct device* dev = bd718xx->chip.dev; 97 97 u32 short_press_ms, long_press_ms; 98 98 u32 short_press_value, long_press_value; 99 99 int ret; ··· 102 102 &short_press_ms); 103 103 if (!ret) { 104 104 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, 107 106 BD718XX_PWRBTN_PRESS_DURATION_MASK, 108 107 short_press_value); 109 108 if (ret) { ··· 115 116 &long_press_ms); 116 117 if (!ret) { 117 118 long_press_value = min(15u, (long_press_ms + 500) / 1000); 118 - ret = regmap_update_bits(bd718xx->chip.regmap, 119 - BD718XX_REG_PWRONCONFIG1, 119 + ret = regmap_update_bits(regmap, BD718XX_REG_PWRONCONFIG1, 120 120 BD718XX_PWRBTN_PRESS_DURATION_MASK, 121 121 long_press_value); 122 122 if (ret) { ··· 130 132 static int bd718xx_i2c_probe(struct i2c_client *i2c, 131 133 const struct i2c_device_id *id) 132 134 { 133 - struct bd718xx *bd718xx; 135 + struct regmap *regmap; 136 + struct regmap_irq_chip_data *irq_data; 134 137 int ret; 135 138 unsigned int chip_type; 136 139 struct mfd_cell *mfd; ··· 141 142 dev_err(&i2c->dev, "No IRQ configured\n"); 142 143 return -EINVAL; 143 144 } 144 - 145 - bd718xx = devm_kzalloc(&i2c->dev, sizeof(struct bd718xx), GFP_KERNEL); 146 - 147 - if (!bd718xx) 148 - return -ENOMEM; 149 - 150 - bd718xx->chip_irq = i2c->irq; 151 145 chip_type = (unsigned int)(uintptr_t) 152 146 of_device_get_match_data(&i2c->dev); 153 147 switch (chip_type) { ··· 156 164 dev_err(&i2c->dev, "Unknown device type"); 157 165 return -EINVAL; 158 166 } 159 - bd718xx->chip.dev = &i2c->dev; 160 - dev_set_drvdata(&i2c->dev, bd718xx); 161 167 162 - bd718xx->chip.regmap = devm_regmap_init_i2c(i2c, 163 - &bd718xx_regmap_config); 164 - if (IS_ERR(bd718xx->chip.regmap)) { 168 + regmap = devm_regmap_init_i2c(i2c, &bd718xx_regmap_config); 169 + if (IS_ERR(regmap)) { 165 170 dev_err(&i2c->dev, "regmap initialization failed\n"); 166 - return PTR_ERR(bd718xx->chip.regmap); 171 + return PTR_ERR(regmap); 167 172 } 168 173 169 - ret = devm_regmap_add_irq_chip(&i2c->dev, bd718xx->chip.regmap, 170 - bd718xx->chip_irq, IRQF_ONESHOT, 0, 171 - &bd718xx_irq_chip, &bd718xx->irq_data); 174 + ret = devm_regmap_add_irq_chip(&i2c->dev, regmap, i2c->irq, 175 + IRQF_ONESHOT, 0, &bd718xx_irq_chip, 176 + &irq_data); 172 177 if (ret) { 173 178 dev_err(&i2c->dev, "Failed to add irq_chip\n"); 174 179 return ret; 175 180 } 176 181 177 - ret = bd718xx_init_press_duration(bd718xx); 182 + ret = bd718xx_init_press_duration(regmap, &i2c->dev); 178 183 if (ret) 179 184 return ret; 180 185 181 - ret = regmap_irq_get_virq(bd718xx->irq_data, BD718XX_INT_PWRBTN_S); 186 + ret = regmap_irq_get_virq(irq_data, BD718XX_INT_PWRBTN_S); 182 187 183 188 if (ret < 0) { 184 189 dev_err(&i2c->dev, "Failed to get the IRQ\n"); ··· 184 195 185 196 button.irq = ret; 186 197 187 - ret = devm_mfd_add_devices(bd718xx->chip.dev, PLATFORM_DEVID_AUTO, 198 + ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO, 188 199 mfd, cells, NULL, 0, 189 - regmap_irq_get_domain(bd718xx->irq_data)); 200 + regmap_irq_get_domain(irq_data)); 190 201 if (ret) 191 202 dev_err(&i2c->dev, "Failed to create subdevices\n"); 192 203
-13
include/linux/mfd/rohm-bd718x7.h
··· 310 310 BD718XX_PWRBTN_LONG_PRESS_15S 311 311 }; 312 312 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 - 326 313 #endif /* __LINUX_MFD_BD718XX_H__ */