iio: core: move @id from struct iio_dev to struct iio_dev_opaque
authorJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 26 Apr 2021 17:49:03 +0000 (18:49 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 17 May 2021 12:49:13 +0000 (13:49 +0100)
Continuing from Alexandru Ardelean's introduction of the split between
driver modifiable fields and those that should only be set by the core.

This could have been done in two steps to make the actual move after
introducing iio_device_id() but there seemed limited point to that
given how mechanical the majority of the patch is.

Includes fixup from Alex for missing mxs-lradc-adc conversion.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Link: https://lore.kernel.org/r/20210426174911.397061-2-jic23@kernel.org
51 files changed:
drivers/iio/accel/adxl372.c
drivers/iio/accel/bma180.c
drivers/iio/accel/bmc150-accel-core.c
drivers/iio/accel/kxcjk-1013.c
drivers/iio/accel/mma8452.c
drivers/iio/accel/mxc4005.c
drivers/iio/accel/stk8312.c
drivers/iio/accel/stk8ba50.c
drivers/iio/adc/ad7606.c
drivers/iio/adc/ad7766.c
drivers/iio/adc/ad7768-1.c
drivers/iio/adc/ad_sigma_delta.c
drivers/iio/adc/at91-sama5d2_adc.c
drivers/iio/adc/at91_adc.c
drivers/iio/adc/dln2-adc.c
drivers/iio/adc/ina2xx-adc.c
drivers/iio/adc/mxs-lradc-adc.c
drivers/iio/adc/ti-ads131e08.c
drivers/iio/adc/xilinx-xadc-core.c
drivers/iio/buffer/industrialio-triggered-buffer.c
drivers/iio/chemical/atlas-sensor.c
drivers/iio/chemical/ccs811.c
drivers/iio/chemical/scd30_core.c
drivers/iio/common/hid-sensors/hid-sensor-trigger.c
drivers/iio/gyro/adxrs290.c
drivers/iio/gyro/bmg160_core.c
drivers/iio/gyro/fxas21002c_core.c
drivers/iio/gyro/itg3200_buffer.c
drivers/iio/gyro/mpu3050-core.c
drivers/iio/health/afe4403.c
drivers/iio/health/afe4404.c
drivers/iio/imu/adis_trigger.c
drivers/iio/imu/bmi160/bmi160_core.c
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
drivers/iio/imu/kmx61.c
drivers/iio/industrialio-core.c
drivers/iio/industrialio-triggered-event.c
drivers/iio/light/acpi-als.c
drivers/iio/light/rpr0521.c
drivers/iio/light/si1145.c
drivers/iio/light/vcnl4000.c
drivers/iio/light/vcnl4035.c
drivers/iio/magnetometer/bmc150_magn.c
drivers/iio/magnetometer/rm3100-core.c
drivers/iio/potentiostat/lmp91000.c
drivers/iio/pressure/zpa2326.c
drivers/iio/proximity/as3935.c
drivers/iio/proximity/sx9310.c
drivers/iio/proximity/sx9500.c
include/linux/iio/iio-opaque.h
include/linux/iio/iio.h

index 9c9a896a872a047cecf119c4263cf6c4359906d4..fc9592407717632c2a7df3ce820d8d3436ade207 100644 (file)
@@ -1223,14 +1223,14 @@ int adxl372_probe(struct device *dev, struct regmap *regmap,
                st->dready_trig = devm_iio_trigger_alloc(dev,
                                                         "%s-dev%d",
                                                         indio_dev->name,
-                                                        indio_dev->id);
+                                                        iio_device_id(indio_dev));
                if (st->dready_trig == NULL)
                        return -ENOMEM;
 
                st->peak_datardy_trig = devm_iio_trigger_alloc(dev,
                                                               "%s-dev%d-peak",
                                                               indio_dev->name,
-                                                              indio_dev->id);
+                                                              iio_device_id(indio_dev));
                if (!st->peak_datardy_trig)
                        return -ENOMEM;
 
index b8a7469cdae4185805d69aebd51a2da47d9e0ba1..68d91a70de03072946400ffc2aaee3bda6f21830 100644 (file)
@@ -1045,7 +1045,7 @@ static int bma180_probe(struct i2c_client *client,
 
        if (client->irq > 0) {
                data->trig = iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
-                       indio_dev->id);
+                                              iio_device_id(indio_dev));
                if (!data->trig) {
                        ret = -ENOMEM;
                        goto err_chip_disable;
index 04d85ce34e9f5703037e67f25b6f5bb3a197467c..62a164a7b85207d4c296452b8af3e52f0bd594df 100644 (file)
@@ -1470,9 +1470,9 @@ static int bmc150_accel_triggers_setup(struct iio_dev *indio_dev,
                struct bmc150_accel_trigger *t = &data->triggers[i];
 
                t->indio_trig = devm_iio_trigger_alloc(dev,
-                                       bmc150_accel_triggers[i].name,
+                                                      bmc150_accel_triggers[i].name,
                                                       indio_dev->name,
-                                                      indio_dev->id);
+                                                      iio_device_id(indio_dev));
                if (!t->indio_trig) {
                        ret = -ENOMEM;
                        break;
index ff724bc17a458a96a7e0743337645421d57b832f..283e6a3feffc94811eb7f018e9e58cccfcc05a9e 100644 (file)
@@ -1404,7 +1404,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
                data->dready_trig = devm_iio_trigger_alloc(&client->dev,
                                                           "%s-dev%d",
                                                           indio_dev->name,
-                                                          indio_dev->id);
+                                                          iio_device_id(indio_dev));
                if (!data->dready_trig) {
                        ret = -ENOMEM;
                        goto err_poweroff;
@@ -1413,7 +1413,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
                data->motion_trig = devm_iio_trigger_alloc(&client->dev,
                                                          "%s-any-motion-dev%d",
                                                          indio_dev->name,
-                                                         indio_dev->id);
+                                                         iio_device_id(indio_dev));
                if (!data->motion_trig) {
                        ret = -ENOMEM;
                        goto err_poweroff;
index 4d307dfb9169c502e972c2d83ec6626a25e501d0..464a6bfe67467853087d2f2cb295f726938ca64f 100644 (file)
@@ -1461,7 +1461,7 @@ static int mma8452_trigger_setup(struct iio_dev *indio_dev)
 
        trig = devm_iio_trigger_alloc(&data->client->dev, "%s-dev%d",
                                      indio_dev->name,
-                                     indio_dev->id);
+                                     iio_device_id(indio_dev));
        if (!trig)
                return -ENOMEM;
 
index fb3cbaa62bd879ace716fb159b375f66f5e9ae20..98c7f5f590119eae78351659d3ab379516e64a6a 100644 (file)
@@ -433,7 +433,7 @@ static int mxc4005_probe(struct i2c_client *client,
                data->dready_trig = devm_iio_trigger_alloc(&client->dev,
                                                           "%s-dev%d",
                                                           indio_dev->name,
-                                                          indio_dev->id);
+                                                          iio_device_id(indio_dev));
                if (!data->dready_trig)
                        return -ENOMEM;
 
index 60aecfa9fd9220c3edf6b874d58c0133c3997207..aeab108c457d8f398951d9a04a76db680538aeb0 100644 (file)
@@ -552,7 +552,7 @@ static int stk8312_probe(struct i2c_client *client,
                data->dready_trig = devm_iio_trigger_alloc(&client->dev,
                                                           "%s-dev%d",
                                                           indio_dev->name,
-                                                          indio_dev->id);
+                                                          iio_device_id(indio_dev));
                if (!data->dready_trig) {
                        ret = -ENOMEM;
                        goto err_power_off;
index 7cf9cb7e86667187d2247c9a2844b6fd08afff8e..3e7cf23be7e1d67879b72a7412fcdf49424138f5 100644 (file)
@@ -448,7 +448,7 @@ static int stk8ba50_probe(struct i2c_client *client,
                data->dready_trig = devm_iio_trigger_alloc(&client->dev,
                                                           "%s-dev%d",
                                                           indio_dev->name,
-                                                          indio_dev->id);
+                                                          iio_device_id(indio_dev));
                if (!data->dready_trig) {
                        ret = -ENOMEM;
                        goto err_power_off;
index 0af0bb4d5a7fed86dde0472b367a45c0e040839e..0a60ecc69d38e12dfcf828a057004cdb8b5294c2 100644 (file)
@@ -663,7 +663,8 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
        }
 
        st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
-                                         indio_dev->name, indio_dev->id);
+                                         indio_dev->name,
+                                         iio_device_id(indio_dev));
        if (!st->trig)
                return -ENOMEM;
 
index 1e41759f3ee5d52da2c1d0402761cf30ab2dc777..236a455aaa186504b62970e7b9811757a89a2781 100644 (file)
@@ -248,7 +248,8 @@ static int ad7766_probe(struct spi_device *spi)
 
        if (spi->irq > 0) {
                ad7766->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
-                       indio_dev->name, indio_dev->id);
+                                                     indio_dev->name,
+                                                     iio_device_id(indio_dev));
                if (!ad7766->trig)
                        return -ENOMEM;
 
index c945f1349623f7ad7f58069710ed02565f022af5..41752777e96c75a560535578e30ac540aceb9ca8 100644 (file)
@@ -626,7 +626,8 @@ static int ad7768_probe(struct spi_device *spi)
        }
 
        st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
-                                         indio_dev->name, indio_dev->id);
+                                         indio_dev->name,
+                                         iio_device_id(indio_dev));
        if (!st->trig)
                return -ENOMEM;
 
index e777ec718973bae60e5c785d76ffd3f38911b5cd..69b979331ccd534ea6cef79cba7290b5ca81898a 100644 (file)
@@ -477,7 +477,7 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)
 
        sigma_delta->trig = iio_trigger_alloc(&sigma_delta->spi->dev,
                                              "%s-dev%d", indio_dev->name,
-                                             indio_dev->id);
+                                             iio_device_id(indio_dev));
        if (sigma_delta->trig == NULL) {
                ret = -ENOMEM;
                goto error_ret;
index a7826f097b95cd71f4ff1498a87415b25e4f37cd..6e8c28675947f1870e60f58f94b1d3aef473ff11 100644 (file)
@@ -997,7 +997,7 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *indio,
        int ret;
 
        trig = devm_iio_trigger_alloc(&indio->dev, "%s-dev%d-%s", indio->name,
-                                     indio->id, trigger_name);
+                               iio_device_id(indio), trigger_name);
        if (!trig)
                return NULL;
 
index 0b5f0c91d0d734b8a27f8747b9f3e3e27ce88c44..5a7d3a3a5fa82f12a5f18ad7bb36cf9394273ca6 100644 (file)
@@ -547,7 +547,7 @@ static int at91_adc_get_trigger_value_by_name(struct iio_dev *idev,
                char *name = kasprintf(GFP_KERNEL,
                                "%s-dev%d-%s",
                                idev->name,
-                               idev->id,
+                               iio_device_id(idev),
                                triggers[i].name);
                if (!name)
                        return -ENOMEM;
@@ -626,7 +626,7 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *idev,
        int ret;
 
        trig = iio_trigger_alloc(idev->dev.parent, "%s-dev%d-%s", idev->name,
-                                idev->id, trigger->name);
+                                iio_device_id(idev), trigger->name);
        if (trig == NULL)
                return NULL;
 
index 0d53ef18e0459ce204889a8dfb18e360e44b4854..16407664182ce8005642ccd7d09ec15f4958a596 100644 (file)
@@ -649,7 +649,8 @@ static int dln2_adc_probe(struct platform_device *pdev)
        indio_dev->setup_ops = &dln2_adc_buffer_setup_ops;
 
        dln2->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
-                                           indio_dev->name, indio_dev->id);
+                                           indio_dev->name,
+                                           iio_device_id(indio_dev));
        if (!dln2->trig) {
                dev_err(dev, "failed to allocate trigger\n");
                return -ENOMEM;
index 2ae54258b2214860d95f6e6ebddf6b044105a207..a4b2ff9e0dd5e8aa1eeda341c6915ff30235acfe 100644 (file)
@@ -843,7 +843,8 @@ static int ina2xx_buffer_enable(struct iio_dev *indio_dev)
                chip->allow_async_readout);
 
        task = kthread_create(ina2xx_capture_thread, (void *)indio_dev,
-                             "%s:%d-%uus", indio_dev->name, indio_dev->id,
+                             "%s:%d-%uus", indio_dev->name,
+                             iio_device_id(indio_dev),
                              sampling_us);
        if (IS_ERR(task))
                return PTR_ERR(task);
index 30e29f44ebd2ee6bf3ac8bc950a8e043f44ae214..1d99170d33285807545e35257d4fa595cc0fbc8c 100644 (file)
@@ -455,7 +455,7 @@ static int mxs_lradc_adc_trigger_init(struct iio_dev *iio)
        struct mxs_lradc_adc *adc = iio_priv(iio);
 
        trig = devm_iio_trigger_alloc(&iio->dev, "%s-dev%i", iio->name,
-                                     iio->id);
+                                     iio_device_id(iio));
        if (!trig)
                return -ENOMEM;
 
index 2c20dbed8adaa895e54b225529736549987adc89..0c2025a22575054bbb6e4503e3764a2559ffe552 100644 (file)
@@ -849,7 +849,7 @@ static int ads131e08_probe(struct spi_device *spi)
        }
 
        st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
-               indio_dev->name, indio_dev->id);
+               indio_dev->name, iio_device_id(indio_dev));
        if (!st->trig) {
                dev_err(&spi->dev, "failed to allocate IIO trigger\n");
                return -ENOMEM;
index 6914c1900ed0bf3609f5a898062fa58270beb9d1..198d2916266df85e4632d8449622d9c291e5583c 100644 (file)
@@ -743,7 +743,7 @@ static struct iio_trigger *xadc_alloc_trigger(struct iio_dev *indio_dev,
        int ret;
 
        trig = devm_iio_trigger_alloc(dev, "%s%d-%s", indio_dev->name,
-                                     indio_dev->id, name);
+                                     iio_device_id(indio_dev), name);
        if (trig == NULL)
                return ERR_PTR(-ENOMEM);
 
index ebb4520ac291849fcda8a28b7b95f1fc27659697..f77c4538141e7ff71d321ea37d5526964717a601 100644 (file)
@@ -56,7 +56,7 @@ int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev,
                                                 indio_dev,
                                                 "%s_consumer%d",
                                                 indio_dev->name,
-                                                indio_dev->id);
+                                                iio_device_id(indio_dev));
        if (indio_dev->pollfunc == NULL) {
                ret = -ENOMEM;
                goto error_kfifo_free;
index 56ba6c82b501f186f9f34324b9306ff7f464f6f6..d10f921b233a64c45ee2825449ca9bbd97dae328 100644 (file)
@@ -640,7 +640,7 @@ static int atlas_probe(struct i2c_client *client,
        indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE;
 
        trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
-                                     indio_dev->name, indio_dev->id);
+                                     indio_dev->name, iio_device_id(indio_dev));
 
        if (!trig)
                return -ENOMEM;
index 886e96496dbf7eeb79c2fb6147f276883ea6bdff..847194fa1e4645ac9384ef524698026b0bab3f43 100644 (file)
@@ -491,7 +491,7 @@ static int ccs811_probe(struct i2c_client *client,
                data->drdy_trig = devm_iio_trigger_alloc(&client->dev,
                                                         "%s-dev%d",
                                                         indio_dev->name,
-                                                        indio_dev->id);
+                                                        iio_device_id(indio_dev));
                if (!data->drdy_trig) {
                        ret = -ENOMEM;
                        goto err_poweroff;
index d89f117dd0ef30cc525604960f279dbdbe052035..9fe6bbe9ee041b3908187bffe3c94c8b666613b4 100644 (file)
@@ -640,7 +640,8 @@ static int scd30_setup_trigger(struct iio_dev *indio_dev)
        struct iio_trigger *trig;
        int ret;
 
-       trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id);
+       trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
+                                     iio_device_id(indio_dev));
        if (!trig) {
                dev_err(dev, "failed to allocate trigger\n");
                return -ENOMEM;
index 95ddccb44f1c8150ada1aa3a5aa85760677d7258..5a7b3e253e5857e7c808902e5d959ddb76a3c27c 100644 (file)
@@ -256,7 +256,7 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
        }
 
        trig = iio_trigger_alloc(indio_dev->dev.parent,
-                                "%s-dev%d", name, indio_dev->id);
+                                "%s-dev%d", name, iio_device_id(indio_dev));
        if (trig == NULL) {
                dev_err(&indio_dev->dev, "Trigger Allocate Failed\n");
                ret = -ENOMEM;
index cec5e1f17c22a655671eec831ad1e52f9d078741..3e0734ddafe363355c17614a3c14b885ae7164ea 100644 (file)
@@ -589,7 +589,7 @@ static int adxrs290_probe_trigger(struct iio_dev *indio_dev)
 
        st->dready_trig = devm_iio_trigger_alloc(&st->spi->dev, "%s-dev%d",
                                                 indio_dev->name,
-                                                indio_dev->id);
+                                                iio_device_id(indio_dev));
        if (!st->dready_trig)
                return -ENOMEM;
 
index b11ebd9bb7a41839e44f88083036de9cffac07bf..26a9ed5770c6b1c5d8214a58584064280e1aba16 100644 (file)
@@ -1137,14 +1137,14 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
                data->dready_trig = devm_iio_trigger_alloc(dev,
                                                           "%s-dev%d",
                                                           indio_dev->name,
-                                                          indio_dev->id);
+                                                          iio_device_id(indio_dev));
                if (!data->dready_trig)
                        return -ENOMEM;
 
                data->motion_trig = devm_iio_trigger_alloc(dev,
                                                          "%s-any-motion-dev%d",
                                                          indio_dev->name,
-                                                         indio_dev->id);
+                                                         iio_device_id(indio_dev));
                if (!data->motion_trig)
                        return -ENOMEM;
 
index 1a20c6b88e7db5cf3b28665ab25ab17c9c270882..5af7b48ff01a95a2590428684261efbc6d4b9434 100644 (file)
@@ -852,7 +852,7 @@ static int fxas21002c_trigger_probe(struct fxas21002c_data *data)
 
        data->dready_trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
                                                   indio_dev->name,
-                                                  indio_dev->id);
+                                                  iio_device_id(indio_dev));
        if (!data->dready_trig)
                return -ENOMEM;
 
index af0aaa146f0cefdf5bc648119fa3bc2186f1821c..04dd6a7969ea79cf62a3c5bb2e0d6582a83c0e24 100644 (file)
@@ -114,7 +114,7 @@ int itg3200_probe_trigger(struct iio_dev *indio_dev)
        struct itg3200 *st = iio_priv(indio_dev);
 
        st->trig = iio_trigger_alloc(&st->i2c->dev, "%s-dev%d", indio_dev->name,
-                                    indio_dev->id);
+                                    iio_device_id(indio_dev));
        if (!st->trig)
                return -ENOMEM;
 
index f17a9351953523e6070e88855e8bfa4e6696f9c7..2b930c7f4d86743ed4f2fa63dc3e2b3e8f172553 100644 (file)
@@ -1058,7 +1058,7 @@ static int mpu3050_trigger_probe(struct iio_dev *indio_dev, int irq)
        mpu3050->trig = devm_iio_trigger_alloc(&indio_dev->dev,
                                               "%s-dev%d",
                                               indio_dev->name,
-                                              indio_dev->id);
+                                              iio_device_id(indio_dev));
        if (!mpu3050->trig)
                return -ENOMEM;
 
index 1fa8d51d50806d3559c3b618101cd19514b42d99..d4921385aaf7d6c31e6a6d71c814043016ef72f0 100644 (file)
@@ -521,7 +521,7 @@ static int afe4403_probe(struct spi_device *spi)
                afe->trig = devm_iio_trigger_alloc(afe->dev,
                                                   "%s-dev%d",
                                                   indio_dev->name,
-                                                  indio_dev->id);
+                                                  iio_device_id(indio_dev));
                if (!afe->trig) {
                        dev_err(afe->dev, "Unable to allocate IIO trigger\n");
                        ret = -ENOMEM;
index e1476bf79fe2a22a00602bd65f5e5696ddc3bcc7..d8a27dfe074a3f719d6d6f267fbfc80883ee7dd7 100644 (file)
@@ -528,7 +528,7 @@ static int afe4404_probe(struct i2c_client *client,
                afe->trig = devm_iio_trigger_alloc(afe->dev,
                                                   "%s-dev%d",
                                                   indio_dev->name,
-                                                  indio_dev->id);
+                                                  iio_device_id(indio_dev));
                if (!afe->trig) {
                        dev_err(afe->dev, "Unable to allocate IIO trigger\n");
                        ret = -ENOMEM;
index fa5540fabaccdc67b562f39e39cd601f338c0bde..48eedc29b28a89fbacb020ea7a55298a8b1843bc 100644 (file)
@@ -62,7 +62,8 @@ int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
        int ret;
 
        adis->trig = devm_iio_trigger_alloc(&adis->spi->dev, "%s-dev%d",
-                                           indio_dev->name, indio_dev->id);
+                                           indio_dev->name,
+                                           iio_device_id(indio_dev));
        if (!adis->trig)
                return -ENOMEM;
 
index 290b5ef83f77a36513a92bafb037d22f3a925d79..b63bd7e5e5e550ca81a93c16946f9be678478f3b 100644 (file)
@@ -785,7 +785,8 @@ int bmi160_probe_trigger(struct iio_dev *indio_dev, int irq, u32 irq_type)
        int ret;
 
        data->trig = devm_iio_trigger_alloc(&indio_dev->dev, "%s-dev%d",
-                                           indio_dev->name, indio_dev->id);
+                                           indio_dev->name,
+                                           iio_device_id(indio_dev));
 
        if (data->trig == NULL)
                return -ENOMEM;
index de8ed1446d60bac7dbbeb0d44fb218015d7d7551..e21ba778595a1ae8b36261ad76da7aaeea2e6771 100644 (file)
@@ -238,7 +238,7 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev, int irq_type)
        st->trig = devm_iio_trigger_alloc(&indio_dev->dev,
                                          "%s-dev%d",
                                          indio_dev->name,
-                                         indio_dev->id);
+                                         iio_device_id(indio_dev));
        if (!st->trig)
                return -ENOMEM;
 
index fc5a60fcfec054a4eb539517a3291ff4f9530a5d..d3e06ce99c1ee394e15d92fb013857a8d96d6c9b 100644 (file)
@@ -1264,7 +1264,7 @@ static struct iio_trigger *kmx61_trigger_setup(struct kmx61_data *data,
                                      "%s-%s-dev%d",
                                      indio_dev->name,
                                      tag,
-                                     indio_dev->id);
+                                     iio_device_id(indio_dev));
        if (!trig)
                return ERR_PTR(-ENOMEM);
 
index 3fdcf2d4997ac6f88c73ae49a25addc1d0dc792a..ec21341c6322ee86f1003b9d5d437df520d63597 100644 (file)
@@ -169,6 +169,20 @@ static const char * const iio_chan_info_postfix[] = {
        [IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type",
        [IIO_CHAN_INFO_CALIBAMBIENT] = "calibambient",
 };
+/**
+ * iio_device_id() - query the unique ID for the device
+ * @indio_dev:         Device structure whose ID is being queried
+ *
+ * The IIO device ID is a unique index used for example for the naming
+ * of the character device /dev/iio\:device[ID]
+ */
+int iio_device_id(struct iio_dev *indio_dev)
+{
+       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
+
+       return iio_dev_opaque->id;
+}
+EXPORT_SYMBOL_GPL(iio_device_id);
 
 /**
  * iio_sysfs_match_string_with_gaps - matches given string in an array with gaps
@@ -1588,7 +1602,7 @@ static void iio_dev_release(struct device *device)
 
        iio_device_detach_buffers(indio_dev);
 
-       ida_simple_remove(&iio_ida, indio_dev->id);
+       ida_simple_remove(&iio_ida, iio_dev_opaque->id);
        kfree(iio_dev_opaque);
 }
 
@@ -1631,14 +1645,14 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
        mutex_init(&indio_dev->info_exist_lock);
        INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
 
-       indio_dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
-       if (indio_dev->id < 0) {
+       iio_dev_opaque->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
+       if (iio_dev_opaque->id < 0) {
                /* cannot use a dev_err as the name isn't available */
                pr_err("failed to get device id\n");
                kfree(iio_dev_opaque);
                return NULL;
        }
-       dev_set_name(&indio_dev->dev, "iio:device%d", indio_dev->id);
+       dev_set_name(&indio_dev->dev, "iio:device%d", iio_dev_opaque->id);
        INIT_LIST_HEAD(&iio_dev_opaque->buffer_list);
        INIT_LIST_HEAD(&iio_dev_opaque->ioctl_handlers);
 
@@ -1891,7 +1905,7 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
                cdev_init(&indio_dev->chrdev, &iio_event_fileops);
 
        if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) {
-               indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
+               indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), iio_dev_opaque->id);
                indio_dev->chrdev.owner = this_mod;
        }
 
index 53da9ab17a62362aa3263fc757e08e8f5866675f..4bedc65c9fe3b046e75c6bab4870dbcd58989132 100644 (file)
@@ -37,7 +37,7 @@ int iio_triggered_event_setup(struct iio_dev *indio_dev,
                                                       indio_dev,
                                                       "%s_consumer%d",
                                                       indio_dev->name,
-                                                      indio_dev->id);
+                                                      iio_device_id(indio_dev));
        if (indio_dev->pollfunc_event == NULL)
                return -ENOMEM;
 
index 0a6ab5761eece0ef9e87e8c483bf0d388214483b..e1ff6f524f4baa3c1cd7732ecfb49cab842a849a 100644 (file)
@@ -204,7 +204,8 @@ static int acpi_als_add(struct acpi_device *device)
        indio_dev->channels = acpi_als_channels;
        indio_dev->num_channels = ARRAY_SIZE(acpi_als_channels);
 
-       als->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id);
+       als->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
+                                          iio_device_id(indio_dev));
        if (!als->trig)
                return -ENOMEM;
 
index 033578f444e4a6f23b924a5fc5fc131a0f13100a..7e332de0e6a53f23fb6c9d4a7a911750e86e04da 100644 (file)
@@ -985,7 +985,7 @@ static int rpr0521_probe(struct i2c_client *client,
                /* Trigger0 producer setup */
                data->drdy_trigger0 = devm_iio_trigger_alloc(
                        indio_dev->dev.parent,
-                       "%s-dev%d", indio_dev->name, indio_dev->id);
+                       "%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
                if (!data->drdy_trigger0) {
                        ret = -ENOMEM;
                        goto err_pm_disable;
index 9b5c99823943a1f050dcdfd507c8c392c82a077e..3fb52402fcc3b88322f169d3012818b646ad746b 100644 (file)
@@ -1243,7 +1243,7 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev)
        int ret;
 
        trig = devm_iio_trigger_alloc(&client->dev,
-                       "%s-dev%d", indio_dev->name, indio_dev->id);
+                       "%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
        if (!trig)
                return -ENOMEM;
 
index 2f7916f95689e873b21bad598138a2c5257deda4..4a61865d01cdcb530bb95e5fdb0ebd9d99b403a0 100644 (file)
@@ -998,7 +998,8 @@ static int vcnl4010_probe_trigger(struct iio_dev *indio_dev)
        struct iio_trigger *trigger;
 
        trigger = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
-                                        indio_dev->name, indio_dev->id);
+                                        indio_dev->name,
+                                        iio_device_id(indio_dev));
        if (!trigger)
                return -ENOMEM;
 
index ae87740d9cef21a4f5f51821c802d8293367a262..691a54b763e156c2db313cf006f5910a1cb12ca3 100644 (file)
@@ -507,7 +507,7 @@ static int vcnl4035_probe_trigger(struct iio_dev *indio_dev)
 
        data->drdy_trigger0 = devm_iio_trigger_alloc(
                        indio_dev->dev.parent,
-                       "%s-dev%d", indio_dev->name, indio_dev->id);
+                       "%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
        if (!data->drdy_trigger0)
                return -ENOMEM;
 
index 00f9766bad5c54bd3b3de8603054356958a68e5d..d75b437a43f2a16f0f2326c7e8ff98ee7f06902c 100644 (file)
@@ -915,7 +915,7 @@ int bmc150_magn_probe(struct device *dev, struct regmap *regmap,
                data->dready_trig = devm_iio_trigger_alloc(dev,
                                                           "%s-dev%d",
                                                           indio_dev->name,
-                                                          indio_dev->id);
+                                                          iio_device_id(indio_dev));
                if (!data->dready_trig) {
                        ret = -ENOMEM;
                        dev_err(dev, "iio trigger alloc failed\n");
index dd811da9cb6dbbae02f67e05ab114d887e5b9416..4df5887fd04c20690ad626d5bef7c8deab1c1ccb 100644 (file)
@@ -575,7 +575,7 @@ int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq)
 
                data->drdy_trig = devm_iio_trigger_alloc(dev, "%s-drdy%d",
                                                         indio_dev->name,
-                                                        indio_dev->id);
+                                                        iio_device_id(indio_dev));
                if (!data->drdy_trig)
                        return -ENOMEM;
 
index 8a9c576616ee509ec22a420cbab446ea81d19ad8..1948e2d22c27ddb4c9f421caad7162b87a5f9f4b 100644 (file)
@@ -323,7 +323,8 @@ static int lmp91000_probe(struct i2c_client *client,
        }
 
        data->trig = devm_iio_trigger_alloc(dev, "%s-mux%d",
-                                           indio_dev->name, indio_dev->id);
+                                           indio_dev->name,
+                                           iio_device_id(indio_dev));
        if (!data->trig) {
                dev_err(dev, "cannot allocate iio trigger.\n");
                return -ENOMEM;
index a93411216aeeeaf0d178feaab209ff1753a14800..89295c90f8018e5ba2163a2ba24b0182f4f3d026 100644 (file)
@@ -1408,7 +1408,8 @@ static int zpa2326_init_managed_trigger(struct device          *parent,
                return 0;
 
        trigger = devm_iio_trigger_alloc(parent, "%s-dev%d",
-                                        indio_dev->name, indio_dev->id);
+                                        indio_dev->name,
+                                        iio_device_id(indio_dev));
        if (!trigger)
                return -ENOMEM;
 
index edc4a35ae66d1851d9acfce5ed1c578d9bf6add8..dc20fe81232ce87ec53e5f23a2f9b1a6993b7e1f 100644 (file)
@@ -404,7 +404,8 @@ static int as3935_probe(struct spi_device *spi)
        indio_dev->info = &as3935_info;
 
        trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
-                                     indio_dev->name, indio_dev->id);
+                                     indio_dev->name,
+                                     iio_device_id(indio_dev));
 
        if (!trig)
                return -ENOMEM;
index 327ebb7ddbb9cfa3ab06017cb2eb5cd81810f0b6..175f3b7c61d77afe8a1411d8d1513907cae73fb8 100644 (file)
@@ -1473,7 +1473,7 @@ static int sx9310_probe(struct i2c_client *client)
 
                data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
                                                    indio_dev->name,
-                                                   indio_dev->id);
+                                                   iio_device_id(indio_dev));
                if (!data->trig)
                        return -ENOMEM;
 
index a87f4a8e43273ac158c071b8f95beb95796c886e..3e4ddb2e8c2bd81245a761d3b852fafe894508d5 100644 (file)
@@ -946,7 +946,7 @@ static int sx9500_probe(struct i2c_client *client,
                        return ret;
 
                data->trig = devm_iio_trigger_alloc(&client->dev,
-                               "%s-dev%d", indio_dev->name, indio_dev->id);
+                               "%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
                if (!data->trig)
                        return -ENOMEM;
 
index 32addd5e790e9e661e07181a9986e4390e27750d..e66b029d99de01b0e0e01d1b4a15dcb48795e098 100644 (file)
@@ -6,6 +6,7 @@
 /**
  * struct iio_dev_opaque - industrial I/O device opaque information
  * @indio_dev:                 public industrial I/O device information
+ * @id:                        used to identify device internally
  * @event_interface:           event chrdevs associated with interrupt lines
  * @attached_buffers:          array of buffers statically attached by the driver
  * @attached_buffers_cnt:      number of buffers in the array of statically attached buffers
@@ -26,6 +27,7 @@
  */
 struct iio_dev_opaque {
        struct iio_dev                  indio_dev;
+       int                             id;
        struct iio_event_interface      *event_interface;
        struct iio_buffer               **attached_buffers;
        unsigned int                    attached_buffers_cnt;
index f2d65e2e88b64a7238da59b03bca7faf3e489360..569861d5887ace0a8c1858eee788234d42869922 100644 (file)
@@ -488,7 +488,6 @@ struct iio_buffer_setup_ops {
 
 /**
  * struct iio_dev - industrial I/O device
- * @id:                        [INTERN] used to identify device internally
  * @driver_module:     [INTERN] used to make it harder to undercut users
  * @modes:             [DRIVER] operating modes supported by device
  * @currentmode:       [DRIVER] current operating mode
@@ -523,7 +522,6 @@ struct iio_buffer_setup_ops {
  *                     **MUST** be accessed **ONLY** via iio_priv() helper
  */
 struct iio_dev {
-       int                             id;
        struct module                   *driver_module;
 
        int                             modes;
@@ -559,6 +557,8 @@ struct iio_dev {
        void                            *priv;
 };
 
+int iio_device_id(struct iio_dev *indio_dev);
+
 const struct iio_chan_spec
 *iio_find_channel_from_si(struct iio_dev *indio_dev, int si);
 /**