From 196fb733e5e6c4f05e208ad31c4155cd525750e9 Mon Sep 17 00:00:00 2001 From: Lothar Rubusch Date: Mon, 1 Apr 2024 19:49:04 +0000 Subject: [PATCH] iio: accel: adxl345: Reorder probe initialization Bring indio_dev, setup() and data initialization to begin of the probe() function to increase readability. Access members through data pointer to assure implicitely the driver's data instance is correctly initialized and functional. Signed-off-by: Lothar Rubusch Link: https://lore.kernel.org/r/20240401194906.56810-7-l.rubusch@gmail.com Signed-off-by: Jonathan Cameron --- drivers/iio/accel/adxl345_core.c | 62 ++++++++++++++++---------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 8d4a66d8c528..5d0f3243ec6c 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -180,37 +180,6 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ADXL345_DATA_FORMAT_SELF_TEST); int ret; - if (setup) { - /* Perform optional initial bus specific configuration */ - ret = setup(dev, regmap); - if (ret) - return ret; - - /* Enable full-resolution mode */ - ret = regmap_update_bits(regmap, ADXL345_REG_DATA_FORMAT, - data_format_mask, - ADXL345_DATA_FORMAT_FULL_RES); - if (ret) - return dev_err_probe(dev, ret, - "Failed to set data range\n"); - - } else { - /* Enable full-resolution mode (init all data_format bits) */ - ret = regmap_write(regmap, ADXL345_REG_DATA_FORMAT, - ADXL345_DATA_FORMAT_FULL_RES); - if (ret) - return dev_err_probe(dev, ret, - "Failed to set data range\n"); - } - - ret = regmap_read(regmap, ADXL345_REG_DEVID, ®val); - if (ret < 0) - return dev_err_probe(dev, ret, "Error reading device ID\n"); - - if (regval != ADXL345_DEVID) - return dev_err_probe(dev, -ENODEV, "Invalid device ID: %x, expected %x\n", - regval, ADXL345_DEVID); - indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; @@ -227,6 +196,37 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, indio_dev->channels = adxl345_channels; indio_dev->num_channels = ARRAY_SIZE(adxl345_channels); + if (setup) { + /* Perform optional initial bus specific configuration */ + ret = setup(dev, data->regmap); + if (ret) + return ret; + + /* Enable full-resolution mode */ + ret = regmap_update_bits(data->regmap, ADXL345_REG_DATA_FORMAT, + data_format_mask, + ADXL345_DATA_FORMAT_FULL_RES); + if (ret) + return dev_err_probe(dev, ret, + "Failed to set data range\n"); + + } else { + /* Enable full-resolution mode (init all data_format bits) */ + ret = regmap_write(data->regmap, ADXL345_REG_DATA_FORMAT, + ADXL345_DATA_FORMAT_FULL_RES); + if (ret) + return dev_err_probe(dev, ret, + "Failed to set data range\n"); + } + + ret = regmap_read(data->regmap, ADXL345_REG_DEVID, ®val); + if (ret < 0) + return dev_err_probe(dev, ret, "Error reading device ID\n"); + + if (regval != ADXL345_DEVID) + return dev_err_probe(dev, -ENODEV, "Invalid device ID: %x, expected %x\n", + regval, ADXL345_DEVID); + /* Enable measurement mode */ ret = adxl345_powerup(data->regmap); if (ret < 0)