iio: accel: adxl345: Make use of device properties
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 22 Feb 2022 09:00:05 +0000 (11:00 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 26 Feb 2022 19:11:13 +0000 (19:11 +0000)
Convert the module to be property provider agnostic and allow
it to be used on non-OF platforms.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Link: https://lore.kernel.org/r/20220222090009.2060-4-andriy.shevchenko@linux.intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/accel/adxl345.h
drivers/iio/accel/adxl345_core.c
drivers/iio/accel/adxl345_i2c.c
drivers/iio/accel/adxl345_spi.c

index 9b0d4f487c43985d6a56ee115b43dd7239347204..d7e67cb08538324fcca18b0ce85b7fac4e08d298 100644 (file)
@@ -13,6 +13,6 @@ enum adxl345_device_type {
        ADXL375 = 2,
 };
 
-int adxl345_core_probe(struct device *dev, struct regmap *regmap, enum adxl345_device_type type);
+int adxl345_core_probe(struct device *dev, struct regmap *regmap);
 
 #endif /* _ADXL345_H_ */
index 0f34c349aa1ec7c2645ecc1fb952db215263da81..315a408115b3ede54a6c9ba1eba8d408bd96e6e8 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/property.h>
 #include <linux/regmap.h>
 
 #include <linux/iio/iio.h>
@@ -213,14 +214,16 @@ 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)
+int adxl345_core_probe(struct device *dev, struct regmap *regmap)
 {
+       enum adxl345_device_type type;
        struct adxl345_data *data;
        struct iio_dev *indio_dev;
        const char *name;
        u32 regval;
        int ret;
 
+       type = (uintptr_t)device_get_match_data(dev);
        switch (type) {
        case ADXL345:
                name = "adxl345";
index 1e42cf3a2991378414198fcf5b0678ab776553f8..391910df8daaa33ced00562d909560ceef1ca74e 100644 (file)
@@ -19,19 +19,15 @@ static const struct regmap_config adxl345_i2c_regmap_config = {
        .val_bits = 8,
 };
 
-static int adxl345_i2c_probe(struct i2c_client *client,
-                            const struct i2c_device_id *id)
+static int adxl345_i2c_probe(struct i2c_client *client)
 {
        struct regmap *regmap;
 
-       if (!id)
-               return -ENODEV;
-
        regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config);
        if (IS_ERR(regmap))
                return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n");
 
-       return adxl345_core_probe(&client->dev, regmap, id->driver_data);
+       return adxl345_core_probe(&client->dev, regmap);
 }
 
 static const struct i2c_device_id adxl345_i2c_id[] = {
@@ -55,7 +51,7 @@ static struct i2c_driver adxl345_i2c_driver = {
                .name   = "adxl345_i2c",
                .of_match_table = adxl345_of_match,
        },
-       .probe          = adxl345_i2c_probe,
+       .probe_new      = adxl345_i2c_probe,
        .id_table       = adxl345_i2c_id,
 };
 
index 34b7001d519f9b80f2aaeb333ae4688159ddf907..ee4c50c8a95b1ab246379bf7f41eb14f32600001 100644 (file)
@@ -22,7 +22,6 @@ static const struct regmap_config adxl345_spi_regmap_config = {
 
 static int adxl345_spi_probe(struct spi_device *spi)
 {
-       const struct spi_device_id *id = spi_get_device_id(spi);
        struct regmap *regmap;
 
        /* Bail out if max_speed_hz exceeds 5 MHz */
@@ -34,7 +33,7 @@ static int adxl345_spi_probe(struct spi_device *spi)
        if (IS_ERR(regmap))
                return dev_err_probe(&spi->dev, PTR_ERR(regmap), "Error initializing regmap\n");
 
-       return adxl345_core_probe(&spi->dev, regmap, id->driver_data);
+       return adxl345_core_probe(&spi->dev, regmap);
 }
 
 static const struct spi_device_id adxl345_spi_id[] = {