iio: accel: adxl345: convert probe to device-managed functions
Subsystems (2)
PATCH 1/1 iio: accel: adxl345: convert probe to device-managed functions
This driver has two parts, one for i2c and one for spi, since the chip can operate with both wire protocols.
The core file has a common adxl345_core_remove() function which puts the chip into a powerdown state. This can be implemented with a devm_add_action_or_reset() hook.
Doing that means we can register the IIO device with devm_iio_device_register() and get rid of the adxl345_core_remove() function.
The dev_set_drvdata() call can be removed as there is no other user of this private data anymore.
--- drivers/iio/accel/adxl345.h | 1 - drivers/iio/accel/adxl345_core.c | 29 +++++++++-------------------- drivers/iio/accel/adxl345_i2c.c | 6 ------ drivers/iio/accel/adxl345_spi.c | 6 ------ 4 files changed, 9 insertions(+), 33 deletions(-)
drivers/iio/accel/adxl345.h +0 -1
@@ -15,6 +15,5 @@ enum adxl345_device_type {int adxl345_core_probe (struct device *dev,struct regmap *regmap,enum adxl345_device_type type,const char *name); -int adxl345_core_remove (struct device *dev);#endif /* _ADXL345_H_ */
drivers/iio/accel/adxl345_core.c +9 -20
@@ -208,6 +208,11 @@ static const struct iio_info adxl345_info = { .write_raw_get_fmt = adxl345_write_raw_get_fmt, }; +static void adxl345_powerdown (void *regmap) +{ +regmap_write (regmap,ADXL345_REG_POWER_CTL ,ADXL345_POWER_CTL_STANDBY ); +} +int adxl345_core_probe (struct device *dev,struct regmap *regmap,enum adxl345_device_type type,const char *name) {
@@ -233,7 +238,6 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,return -ENOMEM ; data =iio_priv (indio_dev); -dev_set_drvdata (dev, indio_dev); data->regmap = regmap; data->type = type;/* Enable full-resolution mode */
@@ -260,29 +264,14 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,return ret; } - ret =iio_device_register (indio_dev); -if (ret <0 ) { -dev_err (dev,"iio_device_register failed: %d\n" , ret); -regmap_write (data->regmap,ADXL345_REG_POWER_CTL , -ADXL345_POWER_CTL_STANDBY ); - } + ret =devm_add_action_or_reset (dev, adxl345_powerdown, data->regmap); +if (ret <0 ) +return ret; -return ret; +return devm_iio_device_register (dev, indio_dev); }EXPORT_SYMBOL_GPL (adxl345_core_probe); -int adxl345_core_remove (struct device *dev) -{ -struct iio_dev *indio_dev =dev_get_drvdata (dev); -struct adxl345_data *data =iio_priv (indio_dev); - -iio_device_unregister (indio_dev); - -return regmap_write (data->regmap,ADXL345_REG_POWER_CTL , -ADXL345_POWER_CTL_STANDBY ); -} -EXPORT_SYMBOL_GPL (adxl345_core_remove); -MODULE_AUTHOR ("Eva Rachel Retuya <[email protected]>" );MODULE_DESCRIPTION ("ADXL345 3-Axis Digital Accelerometer core driver" );MODULE_LICENSE ("GPL v2" );
drivers/iio/accel/adxl345_i2c.c +0 -6
@@ -38,11 +38,6 @@ static int adxl345_i2c_probe(struct i2c_client *client, id->name); } -static int adxl345_i2c_remove (struct i2c_client *client) -{ -return adxl345_core_remove (&client->dev); -} -static const struct i2c_device_id adxl345_i2c_id[] = { {"adxl345" ,ADXL345 }, {"adxl375" ,ADXL375 },
@@ -65,7 +60,6 @@ static struct i2c_driver adxl345_i2c_driver = { .of_match_table = adxl345_of_match, }, .probe = adxl345_i2c_probe, - .remove = adxl345_i2c_remove, .id_table = adxl345_i2c_id, };
drivers/iio/accel/adxl345_spi.c +0 -6
@@ -42,11 +42,6 @@ static int adxl345_spi_probe(struct spi_device *spi)return adxl345_core_probe (&spi->dev, regmap, id->driver_data, id->name); } -static int adxl345_spi_remove (struct spi_device *spi) -{ -return adxl345_core_remove (&spi->dev); -} -static const struct spi_device_id adxl345_spi_id[] = { {"adxl345" ,ADXL345 }, {"adxl375" ,ADXL375 },
@@ -69,7 +64,6 @@ static struct spi_driver adxl345_spi_driver = { .of_match_table = adxl345_of_match, }, .probe = adxl345_spi_probe, - .remove = adxl345_spi_remove, .id_table = adxl345_spi_id, };
Signature · 1 line
2.31.1
Jonathan Cameron
maintainerQuoted 7 lines · On Thu, 24 Jun 2021 11:04:40 +0300 Alexandru Ardelean <[email protected]>…
This driver has two parts, one for i2c and one for spi, since the chip can operate with both wire protocols.
The core file has a common
adxl345_core_remove()function which puts the chip into a powerdown state. This can be implemented with adevm_add_action_or_reset()hook.
Quoted 8 lines
Doing that means we can register the IIO device with
devm_iio_device_register()and get rid of theadxl345_core_remove()function.The
dev_set_drvdata()call can be removed as there is no other user of this private data anymore.Signed-off-by Alexandru Ardelean <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing for all the normal reasons.
Thanks,
Jonathan
Quoted 124 lines
--- drivers/iio/accel/adxl345.h | 1 - drivers/iio/accel/adxl345_core.c | 29 +++++++++-------------------- drivers/iio/accel/adxl345_i2c.c | 6 ------ drivers/iio/accel/adxl345_spi.c | 6 ------ 4 files changed, 9 insertions(+), 33 deletions(-)drivers/iio/accel/adxl345.h +0
-1@@ -15,6 +15,5 @@ enum adxl345_device_type {int adxl345_core_probe (struct device *dev,struct regmap *regmap,enum adxl345_device_type type,const char *name); -int adxl345_core_remove (struct device *dev);#endif /* _ADXL345_H_ */ drivers/iio/accel/adxl345_core.c +9
-20@@ -208,6 +208,11 @@ static const struct iio_info adxl345_info = { .write_raw_get_fmt = adxl345_write_raw_get_fmt, }; +static void adxl345_powerdown (void *regmap) +{ +regmap_write (regmap,ADXL345_REG_POWER_CTL ,ADXL345_POWER_CTL_STANDBY ); +} +int adxl345_core_probe (struct device *dev,struct regmap *regmap,enum adxl345_device_type type,const char *name) {@@ -233,7 +238,6 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,return -ENOMEM ; data =iio_priv (indio_dev); -dev_set_drvdata (dev, indio_dev); data->regmap = regmap; data->type = type;/* Enable full-resolution mode */ @@ -260,29 +264,14 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,return ret; } - ret =iio_device_register (indio_dev); -if (ret <0 ) { -dev_err (dev,"iio_device_register failed: %d\n" , ret); -regmap_write (data->regmap,ADXL345_REG_POWER_CTL , -ADXL345_POWER_CTL_STANDBY ); - } + ret =devm_add_action_or_reset (dev, adxl345_powerdown, data->regmap); +if (ret <0 ) +return ret; -return ret; +return devm_iio_device_register (dev, indio_dev); }EXPORT_SYMBOL_GPL (adxl345_core_probe); -int adxl345_core_remove (struct device *dev) -{ -struct iio_dev *indio_dev =dev_get_drvdata (dev); -struct adxl345_data *data =iio_priv (indio_dev); - -iio_device_unregister (indio_dev); - -return regmap_write (data->regmap,ADXL345_REG_POWER_CTL , -ADXL345_POWER_CTL_STANDBY ); -} -EXPORT_SYMBOL_GPL (adxl345_core_remove); -MODULE_AUTHOR ("Eva Rachel Retuya <[email protected]>" );MODULE_DESCRIPTION ("ADXL345 3-Axis Digital Accelerometer core driver" );MODULE_LICENSE ("GPL v2" );drivers/iio/accel/adxl345_i2c.c +0
-6@@ -38,11 +38,6 @@ static int adxl345_i2c_probe(struct i2c_client *client, id->name); } -static int adxl345_i2c_remove (struct i2c_client *client) -{ -return adxl345_core_remove (&client->dev); -} -static const struct i2c_device_id adxl345_i2c_id[] = { {"adxl345" ,ADXL345 }, {"adxl375" ,ADXL375 },@@ -65,7 +60,6 @@ static struct i2c_driver adxl345_i2c_driver = { .of_match_table = adxl345_of_match, }, .probe = adxl345_i2c_probe, - .remove = adxl345_i2c_remove, .id_table = adxl345_i2c_id, };drivers/iio/accel/adxl345_spi.c +0
-6@@ -42,11 +42,6 @@ static int adxl345_spi_probe(struct spi_device *spi)return adxl345_core_probe (&spi->dev, regmap, id->driver_data, id->name); } -static int adxl345_spi_remove (struct spi_device *spi) -{ -return adxl345_core_remove (&spi->dev); -} -static const struct spi_device_id adxl345_spi_id[] = { {"adxl345" ,ADXL345 }, {"adxl375" ,ADXL375 },@@ -69,7 +64,6 @@ static struct spi_driver adxl345_spi_driver = { .of_match_table = adxl345_of_match, }, .probe = adxl345_spi_probe, - .remove = adxl345_spi_remove, .id_table = adxl345_spi_id, };