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

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: mt6577_auxadc: Simplify with device managed function

Add a device managed hook, via devm_add_action_or_reset() and
mt6577_power_off(), to power off on device detach.

Replace iio_device_register() by devm_iio_device_register() and remove
the mt6577_auxadc_remove() function used to unregister the device and
power off the device.

Remove platform_set_drvdata() from the probe function, since
platform_get_drvdata() is not used anymore.

Remove mt6577_auxadc_mod_reg() call from the probe function error path.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Link: https://lore.kernel.org/r/20230826035402.3512033-3-ruanjinjie@huawei.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Jinjie Ruan and committed by
Jonathan Cameron
a2d518fb 8cbba23e

+15 -25
+15 -25
drivers/iio/adc/mt6577_auxadc.c
··· 246 246 return 0; 247 247 } 248 248 249 + static void mt6577_power_off(void *data) 250 + { 251 + struct mt6577_auxadc_device *adc_dev = data; 252 + 253 + mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC, 254 + 0, MT6577_AUXADC_PDN_EN); 255 + } 256 + 249 257 static int mt6577_auxadc_probe(struct platform_device *pdev) 250 258 { 251 259 struct mt6577_auxadc_device *adc_dev; ··· 294 286 MT6577_AUXADC_PDN_EN, 0); 295 287 mdelay(MT6577_AUXADC_POWER_READY_MS); 296 288 297 - platform_set_drvdata(pdev, indio_dev); 289 + ret = devm_add_action_or_reset(&pdev->dev, mt6577_power_off, adc_dev); 290 + if (ret) 291 + return dev_err_probe(&pdev->dev, ret, 292 + "Failed to add action to managed power off\n"); 298 293 299 - ret = iio_device_register(indio_dev); 300 - if (ret < 0) { 301 - dev_err(&pdev->dev, "failed to register iio device\n"); 302 - goto err_power_off; 303 - } 304 - 305 - return 0; 306 - 307 - err_power_off: 308 - mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC, 309 - 0, MT6577_AUXADC_PDN_EN); 310 - return ret; 311 - } 312 - 313 - static int mt6577_auxadc_remove(struct platform_device *pdev) 314 - { 315 - struct iio_dev *indio_dev = platform_get_drvdata(pdev); 316 - struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev); 317 - 318 - iio_device_unregister(indio_dev); 319 - 320 - mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC, 321 - 0, MT6577_AUXADC_PDN_EN); 294 + ret = devm_iio_device_register(&pdev->dev, indio_dev); 295 + if (ret < 0) 296 + return dev_err_probe(&pdev->dev, ret, "failed to register iio device\n"); 322 297 323 298 return 0; 324 299 } ··· 328 337 .pm = pm_sleep_ptr(&mt6577_auxadc_pm_ops), 329 338 }, 330 339 .probe = mt6577_auxadc_probe, 331 - .remove = mt6577_auxadc_remove, 332 340 }; 333 341 module_platform_driver(mt6577_auxadc_driver); 334 342