iio: Move more things from iio_dev to iio_dev_opaque
Subsystems (13)
Jonathan Cameron
maintainercover iio: Move more things from iio_dev to iio_dev_opaque
From: Jonathan Cameron <[email protected]>
Intent here is to clear out the low hanging fruit so we can focus on the more interesting elements.
Hopefully this set are all uncontroversial. Lightly tested only but all fairly mechanical so hopefully I didn't mess up.
As for the others my current thinking is as follows
mlock: Still some instances to clear out of this being used to protect things it should not be used for. Long run we definitely want to move this one.
scan_timestamp: Can easily use a look up function in drivers that access this directly, but that feels like an unwanted level of indirection in iio_push_to_buffers_with_timestamp(). Perhaps worth doing anyway. scan_bytes is also used in this function.
active_scan_mask and masklength: Both used in valid ways inside drivers. Could be wrapped up in access functions, but it does seem a little convoluted.
trig: This is used correctly in lots of drivers, so should stay in struct iio_dev.
Jonathan Cameron (9):
iio: core: move @id from struct iio_dev to struct iio_dev_opaque
iio: avoid shadowing of variable name in to_iio_dev_opaque()
iio: core: move @driver_module from struct iio_dev to struct
iio_dev_opaque
iio: core: move @trig_readonly from struct iio_dev to struct
iio_dev_opaque
iio: core: move @scan_index_timestamp to struct iio_dev_opaque
iio: core: move @info_exist_lock to struct iio_dev_opaque
iio: core: move @chrdev from struct iio_dev to struct iio_dev_opaque
iio: core: move @flags from struct iio_dev to struct iio_dev_opaque
iio: core: move @clock_id from struct iio_dev to struct iio_dev_opaque
drivers/iio/accel/adxl372.c | 4 +- drivers/iio/accel/bma180.c | 2 +- drivers/iio/accel/bmc150-accel-core.c | 4 +- drivers/iio/accel/kxcjk-1013.c | 4 +- drivers/iio/accel/mma8452.c | 2 +- drivers/iio/accel/mxc4005.c | 2 +- drivers/iio/accel/stk8312.c | 2 +- drivers/iio/accel/stk8ba50.c | 2 +- drivers/iio/adc/ad7606.c | 3 +- drivers/iio/adc/ad7766.c | 3 +- drivers/iio/adc/ad7768-1.c | 3 +- drivers/iio/adc/ad_sigma_delta.c | 2 +- drivers/iio/adc/at91_adc.c | 4 +- drivers/iio/adc/dln2-adc.c | 3 +- drivers/iio/adc/ina2xx-adc.c | 3 +- drivers/iio/adc/ti-ads131e08.c | 2 +- drivers/iio/adc/xilinx-xadc-core.c | 2 +- .../buffer/industrialio-triggered-buffer.c | 2 +- drivers/iio/chemical/atlas-sensor.c | 2 +- drivers/iio/chemical/ccs811.c | 2 +- drivers/iio/chemical/scd30_core.c | 3 +- .../common/hid-sensors/hid-sensor-trigger.c | 2 +- drivers/iio/gyro/adxrs290.c | 2 +- drivers/iio/gyro/bmg160_core.c | 4 +- drivers/iio/gyro/fxas21002c_core.c | 2 +- drivers/iio/gyro/itg3200_buffer.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/health/afe4403.c | 2 +- drivers/iio/health/afe4404.c | 2 +- drivers/iio/imu/adis_trigger.c | 3 +- drivers/iio/imu/bmi160/bmi160_core.c | 3 +- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 2 +- drivers/iio/imu/kmx61.c | 2 +- drivers/iio/industrialio-buffer.c | 12 ++- drivers/iio/industrialio-core.c | 76 +++++++++++++------ drivers/iio/industrialio-trigger.c | 19 +++-- drivers/iio/industrialio-triggered-event.c | 2 +- drivers/iio/inkern.c | 46 ++++++----- drivers/iio/light/acpi-als.c | 3 +- drivers/iio/light/rpr0521.c | 2 +- drivers/iio/light/si1145.c | 2 +- drivers/iio/light/vcnl4000.c | 3 +- drivers/iio/light/vcnl4035.c | 2 +- drivers/iio/magnetometer/bmc150_magn.c | 2 +- drivers/iio/magnetometer/rm3100-core.c | 2 +- drivers/iio/potentiostat/lmp91000.c | 3 +- drivers/iio/pressure/zpa2326.c | 3 +- drivers/iio/proximity/as3935.c | 3 +- drivers/iio/proximity/sx9310.c | 2 +- drivers/iio/proximity/sx9500.c | 2 +- include/linux/iio/iio-opaque.h | 22 +++++- include/linux/iio/iio.h | 29 +------ 52 files changed, 188 insertions(+), 131 deletions(-)
Signature · 1 line
2.31.1
Jonathan Cameron
maintainerPATCH 1/9 iio: core: move @id from struct iio_dev to struct iio_dev_opaque
From: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/accel/adxl372.c | 4 ++-- drivers/iio/accel/bma180.c | 2 +- drivers/iio/accel/bmc150-accel-core.c | 4 ++-- drivers/iio/accel/kxcjk-1013.c | 4 ++-- drivers/iio/accel/mma8452.c | 2 +- drivers/iio/accel/mxc4005.c | 2 +- drivers/iio/accel/stk8312.c | 2 +- drivers/iio/accel/stk8ba50.c | 2 +- drivers/iio/adc/ad7606.c | 3 ++- drivers/iio/adc/ad7766.c | 3 ++- drivers/iio/adc/ad7768-1.c | 3 ++- drivers/iio/adc/ad_sigma_delta.c | 2 +- drivers/iio/adc/at91_adc.c | 4 ++-- drivers/iio/adc/dln2-adc.c | 3 ++- drivers/iio/adc/ina2xx-adc.c | 3 ++- drivers/iio/adc/ti-ads131e08.c | 2 +- drivers/iio/adc/xilinx-xadc-core.c | 2 +- .../buffer/industrialio-triggered-buffer.c | 2 +- drivers/iio/chemical/atlas-sensor.c | 2 +- drivers/iio/chemical/ccs811.c | 2 +- drivers/iio/chemical/scd30_core.c | 3 ++- .../common/hid-sensors/hid-sensor-trigger.c | 2 +- drivers/iio/gyro/adxrs290.c | 2 +- drivers/iio/gyro/bmg160_core.c | 4 ++-- drivers/iio/gyro/fxas21002c_core.c | 2 +- drivers/iio/gyro/itg3200_buffer.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/health/afe4403.c | 2 +- drivers/iio/health/afe4404.c | 2 +- drivers/iio/imu/adis_trigger.c | 3 ++- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 2 +- drivers/iio/imu/kmx61.c | 2 +- drivers/iio/industrialio-core.c | 24 +++++++++++++++---- drivers/iio/industrialio-triggered-event.c | 2 +- drivers/iio/light/acpi-als.c | 3 ++- drivers/iio/light/rpr0521.c | 2 +- drivers/iio/light/si1145.c | 2 +- drivers/iio/light/vcnl4000.c | 3 ++- drivers/iio/light/vcnl4035.c | 2 +- drivers/iio/magnetometer/bmc150_magn.c | 2 +- drivers/iio/magnetometer/rm3100-core.c | 2 +- drivers/iio/potentiostat/lmp91000.c | 3 ++- drivers/iio/pressure/zpa2326.c | 3 ++- drivers/iio/proximity/as3935.c | 3 ++- drivers/iio/proximity/sx9310.c | 2 +- drivers/iio/proximity/sx9500.c | 2 +- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 4 ++-- 49 files changed, 87 insertions(+), 58 deletions(-)
drivers/iio/accel/adxl372.c +2 -2
@@ -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 ;
drivers/iio/accel/bma180.c +1 -1
@@ -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;
drivers/iio/accel/bmc150-accel-core.c +2 -2
@@ -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 ;
drivers/iio/accel/kxcjk-1013.c +2 -2
@@ -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;
drivers/iio/accel/mma8452.c +1 -1
@@ -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 ;
drivers/iio/accel/mxc4005.c +1 -1
@@ -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 ;
drivers/iio/accel/stk8312.c +1 -1
@@ -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;
drivers/iio/accel/stk8ba50.c +1 -1
@@ -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;
drivers/iio/adc/ad7606.c +2 -1
@@ -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 ;
drivers/iio/adc/ad7766.c +2 -1
@@ -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 ;
drivers/iio/adc/ad7768-1.c +2 -1
@@ -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 ;
drivers/iio/adc/ad_sigma_delta.c +1 -1
@@ -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;
drivers/iio/adc/at91_adc.c +2 -2
@@ -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 ;
drivers/iio/adc/dln2-adc.c +2 -1
@@ -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 ;
drivers/iio/adc/ina2xx-adc.c +2 -1
@@ -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);
drivers/iio/adc/ti-ads131e08.c +1 -1
@@ -844,7 +844,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 ;
drivers/iio/adc/xilinx-xadc-core.c +1 -1
@@ -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 );
drivers/iio/buffer/industrialio-triggered-buffer.c +1 -1
@@ -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;
drivers/iio/chemical/atlas-sensor.c +1 -1
@@ -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 ;
drivers/iio/chemical/ccs811.c +1 -1
@@ -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;
drivers/iio/chemical/scd30_core.c +2 -1
@@ -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 ;
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +1 -1
@@ -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 ;
drivers/iio/gyro/adxrs290.c +1 -1
@@ -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 ;
drivers/iio/gyro/bmg160_core.c +2 -2
@@ -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 ;
drivers/iio/gyro/fxas21002c_core.c +1 -1
@@ -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 ;
drivers/iio/gyro/itg3200_buffer.c +1 -1
@@ -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 ;
drivers/iio/gyro/mpu3050-core.c +1 -1
@@ -1049,7 +1049,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 ;
drivers/iio/health/afe4403.c +1 -1
@@ -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 ;
drivers/iio/health/afe4404.c +1 -1
@@ -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 ;
drivers/iio/imu/adis_trigger.c +2 -1
@@ -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 ;
drivers/iio/imu/bmi160/bmi160_core.c +2 -1
@@ -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 ;
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +1 -1
@@ -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 ;
drivers/iio/imu/kmx61.c +1 -1
@@ -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 );
drivers/iio/industrialio-core.c +19 -5
@@ -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);
@@ -1892,7 +1906,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; }
drivers/iio/industrialio-triggered-event.c +1 -1
@@ -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 ;
drivers/iio/light/acpi-als.c +2 -1
@@ -206,7 +206,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 ;
drivers/iio/light/rpr0521.c +1 -1
@@ -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;
drivers/iio/light/si1145.c +1 -1
@@ -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 ;
drivers/iio/light/vcnl4000.c +2 -1
@@ -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 ;
drivers/iio/light/vcnl4035.c +1 -1
@@ -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 ;
drivers/iio/magnetometer/bmc150_magn.c +1 -1
@@ -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" );
drivers/iio/magnetometer/rm3100-core.c +1 -1
@@ -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 ;
drivers/iio/potentiostat/lmp91000.c +2 -1
@@ -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 ;
drivers/iio/pressure/zpa2326.c +2 -1
@@ -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 ;
drivers/iio/proximity/as3935.c +2 -1
@@ -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 ;
drivers/iio/proximity/sx9310.c +1 -1
@@ -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 ;
drivers/iio/proximity/sx9500.c +1 -1
@@ -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 ;
include/linux/iio/iio-opaque.h +2 -0
@@ -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;
include/linux/iio/iio.h +2 -2
@@ -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);/**
Signature · 1 line
2.31.1
Jonathan Cameron
maintainerPATCH 2/9 iio: avoid shadowing of variable name in to_iio_dev_opaque()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
indio_dev was both the macro input parameter and the field name in this macro. That causes trouble if the instance of struct iio_dev passed in is not called indio_dev.
Whilst a fix of sorts, no need to backport as it seems we never hit this previously due to some very consistent naming in IIO.
--- include/linux/iio/iio-opaque.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/iio/iio-opaque.h +2 -2
@@ -48,7 +48,7 @@ struct iio_dev_opaque { #endif }; -#define to_iio_dev_opaque (indio_dev) \ - container_of(indio_dev, struct iio_dev_opaque, indio_dev) +#define to_iio_dev_opaque (_indio_dev) \ + container_of((_indio_dev), struct iio_dev_opaque, indio_dev)#endif
Signature · 1 line
2.31.1
Jonathan Cameron
maintainerPATCH 3/9 iio: core: move @driver_module from struct iio_dev to struct iio_dev_opaque
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Continuing move to hide internal elements from drivers, move this structure element over. It's only accessed from iio core files so this one was straight forward and no accessor functions are needed.
--- drivers/iio/industrialio-core.c | 2 +- drivers/iio/industrialio-trigger.c | 9 ++++++--- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 3 --- 4 files changed, 9 insertions(+), 7 deletions(-)
drivers/iio/industrialio-core.c +1 -1
@@ -1859,7 +1859,7 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)if (!indio_dev->info)return -EINVAL ; - indio_dev->driver_module = this_mod; + iio_dev_opaque->driver_module = this_mod;/* If the calling driver did not initialize of_node, do it here */ if (!indio_dev->dev.of_node && indio_dev->dev.parent) indio_dev->dev.of_node = indio_dev->dev.parent->of_node;
drivers/iio/industrialio-trigger.c +6 -3
@@ -13,6 +13,7 @@#include <linux/slab.h> #include <linux/iio/iio.h> +#include <linux/iio/iio-opaque.h> #include <linux/iio/trigger.h> #include "iio_core.h" #include "iio_core_trigger.h"
@@ -240,12 +241,13 @@ static void iio_trigger_put_irq(struct iio_trigger *trig, int irq)int iio_trigger_attach_poll_func (struct iio_trigger *trig,struct iio_poll_func *pf) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (pf->indio_dev);bool notinuse =bitmap_empty (trig->pool,CONFIG_IIO_CONSUMERS_PER_TRIGGER );int ret =0 ;/* Prevent the module from being removed whilst attached to a trigger */ -__module_get (pf->indio_dev->driver_module); +__module_get (iio_dev_opaque->driver_module);/* Get irq number */ pf->irq =iio_trigger_get_irq (trig);
@@ -284,13 +286,14 @@ int iio_trigger_attach_poll_func(struct iio_trigger *trig, out_put_irq:iio_trigger_put_irq (trig, pf->irq); out_put_module: -module_put (pf->indio_dev->driver_module); +module_put (iio_dev_opaque->driver_module);return ret; }int iio_trigger_detach_poll_func (struct iio_trigger *trig,struct iio_poll_func *pf) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (pf->indio_dev);bool no_other_users =bitmap_weight (trig->pool,CONFIG_IIO_CONSUMERS_PER_TRIGGER ) ==1 ;int ret =0 ;
@@ -304,7 +307,7 @@ int iio_trigger_detach_poll_func(struct iio_trigger *trig, trig->attached_own_device = false;iio_trigger_put_irq (trig, pf->irq);free_irq (pf->irq, pf); -module_put (pf->indio_dev->driver_module); +module_put (iio_dev_opaque->driver_module);return ret; }
include/linux/iio/iio-opaque.h +2 -0
@@ -7,6 +7,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 +* @driver_module: used to make it harder to undercut users * @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
@@ -28,6 +29,7 @@struct iio_dev_opaque {struct iio_dev indio_dev;int id; +struct module *driver_module;struct iio_event_interface *event_interface;struct iio_buffer **attached_buffers;unsigned int attached_buffers_cnt;
include/linux/iio/iio.h +0 -3
@@ -488,7 +488,6 @@ struct iio_buffer_setup_ops {/** * struct iio_dev - industrial I/O device -* @driver_module: [INTERN] used to make it harder to undercut users * @modes: [DRIVER] operating modes supported by device * @currentmode: [DRIVER] current operating mode * @dev: [DRIVER] device structure, should be assigned a parent
@@ -522,8 +521,6 @@ struct iio_buffer_setup_ops {* **MUST** be accessed **ONLY** via iio_priv() helper */ struct iio_dev { -struct module *driver_module; -int modes;int currentmode;struct device dev;
Signature · 1 line
2.31.1
Jonathan Cameron
maintainerPATCH 4/9 iio: core: move @trig_readonly from struct iio_dev to struct iio_dev_opaque
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
This is only set via the iio_trig_set_immutable() call and later used by the IIO core so there is no benefit in drivers being able to access it.
--- drivers/iio/industrialio-trigger.c | 10 +++++++--- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 2 -- 3 files changed, 9 insertions(+), 5 deletions(-)
drivers/iio/industrialio-trigger.c +7 -3
@@ -117,14 +117,17 @@ EXPORT_SYMBOL(iio_trigger_unregister);int iio_trigger_set_immutable (struct iio_dev *indio_dev,struct iio_trigger *trig) { +struct iio_dev_opaque *iio_dev_opaque; +if (!indio_dev || !trig)return -EINVAL ; + iio_dev_opaque =to_iio_dev_opaque (indio_dev);mutex_lock (&indio_dev->mlock); -WARN_ON (indio_dev->trig_readonly); +WARN_ON (iio_dev_opaque->trig_readonly); indio_dev->trig =iio_trigger_get (trig); - indio_dev->trig_readonly = true; + iio_dev_opaque->trig_readonly = true;mutex_unlock (&indio_dev->mlock);return 0 ;
@@ -402,6 +405,7 @@ static ssize_t iio_trigger_write_current(struct device *dev, size_t len) {struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev);struct iio_trigger *oldtrig = indio_dev->trig;struct iio_trigger *trig;int ret;
@@ -411,7 +415,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,mutex_unlock (&indio_dev->mlock);return -EBUSY ; } -if (indio_dev->trig_readonly) { +if (iio_dev_opaque->trig_readonly) {mutex_unlock (&indio_dev->mlock);return -EPERM ; }
include/linux/iio/iio-opaque.h +2 -0
@@ -8,6 +8,7 @@* @indio_dev: public industrial I/O device information * @id: used to identify device internally * @driver_module: used to make it harder to undercut users +* @trig_readonly: mark the current trigger immutable * @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
@@ -30,6 +31,7 @@ struct iio_dev_opaque {struct iio_dev indio_dev;int id;struct module *driver_module; +bool trig_readonly;struct iio_event_interface *event_interface;struct iio_buffer **attached_buffers;unsigned int attached_buffers_cnt;
include/linux/iio/iio.h +0 -2
@@ -503,7 +503,6 @@ struct iio_buffer_setup_ops {* @scan_timestamp: [INTERN] set if any buffers have requested timestamp * @scan_index_timestamp:[INTERN] cache of the index to the timestamp * @trig: [INTERN] current device trigger (buffer modes) -* @trig_readonly: [INTERN] mark the current trigger immutable * @pollfunc: [DRIVER] function run on trigger being received * @pollfunc_event: [DRIVER] function run on events trigger being received * @channels: [DRIVER] channel specification structure table
@@ -535,7 +534,6 @@ struct iio_dev {bool scan_timestamp;unsigned scan_index_timestamp;struct iio_trigger *trig; -bool trig_readonly;struct iio_poll_func *pollfunc;struct iio_poll_func *pollfunc_event;
Signature · 1 line
2.31.1
Jonathan Cameron
maintainerPATCH 5/9 iio: core: move @scan_index_timestamp to struct iio_dev_opaque
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
No reason for this cached value to be exposed to drivers so move it to the opaque structure.
--- drivers/iio/industrialio-buffer.c | 7 +++++-- include/linux/iio/iio-opaque.h | 4 ++++ include/linux/iio/iio.h | 2 -- 3 files changed, 9 insertions(+), 4 deletions(-)
drivers/iio/industrialio-buffer.c +5 -2
@@ -601,8 +601,10 @@ static unsigned int iio_storage_bytes_for_si(struct iio_dev *indio_dev,static unsigned int iio_storage_bytes_for_timestamp (struct iio_dev *indio_dev) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev); +return iio_storage_bytes_for_si (indio_dev, - indio_dev->scan_index_timestamp); + iio_dev_opaque->scan_index_timestamp); } static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
@@ -1469,6 +1471,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, struct iio_dev *indio_dev, int index) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev);struct iio_dev_attr *p;struct attribute **attr;int ret, i, attrn, scan_el_attrcount, buffer_attrcount;
@@ -1495,7 +1498,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, goto error_cleanup_dynamic; scan_el_attrcount += ret;if (channels[i].type ==IIO_TIMESTAMP ) - indio_dev->scan_index_timestamp = + iio_dev_opaque->scan_index_timestamp = channels[i].scan_index; }if (indio_dev->masklength && buffer->scan_mask ==NULL ) {
include/linux/iio/iio-opaque.h +4 -0
@@ -22,6 +22,7 @@* @groupcounter: index of next attribute group * @legacy_scan_el_group: attribute group for legacy scan elements attribute group * @legacy_buffer_group: attribute group for legacy buffer attributes group +* @scan_index_timestamp: cache of the index to the timestamp * @debugfs_dentry: device specific debugfs dentry * @cached_reg_addr: cached register address for debugfs reads * @read_buf: read buffer to be used for the initial reg read
@@ -44,6 +45,9 @@ struct iio_dev_opaque {int groupcounter;struct attribute_group legacy_scan_el_group;struct attribute_group legacy_buffer_group; + +unsigned int scan_index_timestamp; +#if defined(CONFIG_DEBUG_FS )struct dentry *debugfs_dentry;unsigned cached_reg_addr;
include/linux/iio/iio.h +0 -2
@@ -501,7 +501,6 @@ struct iio_buffer_setup_ops {* channels * @active_scan_mask: [INTERN] union of all scan masks requested by buffers * @scan_timestamp: [INTERN] set if any buffers have requested timestamp -* @scan_index_timestamp:[INTERN] cache of the index to the timestamp * @trig: [INTERN] current device trigger (buffer modes) * @pollfunc: [DRIVER] function run on trigger being received * @pollfunc_event: [DRIVER] function run on events trigger being received
@@ -532,7 +531,6 @@ struct iio_dev {unsigned masklength;const unsigned long *active_scan_mask;bool scan_timestamp; -unsigned scan_index_timestamp;struct iio_trigger *trig;struct iio_poll_func *pollfunc;struct iio_poll_func *pollfunc_event;
Signature · 1 line
2.31.1
Jonathan Cameron
maintainerPATCH 6/9 iio: core: move @info_exist_lock to struct iio_dev_opaque
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
This lock is only of interest to the IIO core, so make it only visible there.
--- drivers/iio/industrialio-buffer.c | 5 ++-- drivers/iio/industrialio-core.c | 10 +++---- drivers/iio/inkern.c | 46 +++++++++++++++++++------------ include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 2 -- 5 files changed, 38 insertions(+), 27 deletions(-)
drivers/iio/industrialio-buffer.c +3 -2
@@ -1150,12 +1150,13 @@ int iio_update_buffers(struct iio_dev *indio_dev,struct iio_buffer *insert_buffer, struct iio_buffer *remove_buffer) { + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);int ret;if (insert_buffer == remove_buffer)return 0 ; -mutex_lock (&indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);mutex_lock (&indio_dev->mlock);if (insert_buffer &&iio_buffer_is_active (insert_buffer))
@@ -1178,7 +1179,7 @@ int iio_update_buffers(struct iio_dev *indio_dev, out_unlock:mutex_unlock (&indio_dev->mlock); -mutex_unlock (&indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);return ret; }
drivers/iio/industrialio-core.c +5 -5
@@ -1642,7 +1642,7 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)device_initialize (&indio_dev->dev);iio_device_set_drvdata (indio_dev, (void *)indio_dev);mutex_init (&indio_dev->mlock); -mutex_init (&indio_dev->info_exist_lock); +mutex_init (&iio_dev_opaque->info_exist_lock);INIT_LIST_HEAD (&iio_dev_opaque->channel_attr_list); iio_dev_opaque->id =ida_simple_get (&iio_ida,0 ,0 ,GFP_KERNEL );
@@ -1779,7 +1779,7 @@ static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)struct iio_ioctl_handler *h;int ret = -ENODEV ; -mutex_lock (&indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);/** * The NULL check here is required to prevent crashing when a device
@@ -1800,7 +1800,7 @@ static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ret = -EINVAL ; out_unlock: -mutex_unlock (&indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);return ret; }
@@ -1942,7 +1942,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)cdev_device_del (&indio_dev->chrdev, &indio_dev->dev); -mutex_lock (&indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);iio_device_unregister_debugfs (indio_dev);
@@ -1956,7 +1956,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)iio_device_wakeup_eventset (indio_dev);iio_buffer_wakeup_poll (indio_dev); -mutex_unlock (&indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);iio_buffers_free_sysfs_and_mask (indio_dev); }
drivers/iio/inkern.c +28 -18
180 lines not on this page · raw message
include/linux/iio/iio-opaque.h +2 -0
@@ -8,6 +8,7 @@* @indio_dev: public industrial I/O device information * @id: used to identify device internally * @driver_module: used to make it harder to undercut users +* @info_exist_lock: lock to prevent use during removal * @trig_readonly: mark the current trigger immutable * @event_interface: event chrdevs associated with interrupt lines * @attached_buffers: array of buffers statically attached by the driver
@@ -32,6 +33,7 @@ struct iio_dev_opaque {struct iio_dev indio_dev;int id;struct module *driver_module; +struct mutex info_exist_lock;bool trig_readonly;struct iio_event_interface *event_interface;struct iio_buffer **attached_buffers;
include/linux/iio/iio.h +0 -2
@@ -510,7 +510,6 @@ struct iio_buffer_setup_ops {* @label: [DRIVER] unique name to identify which device this is * @info: [DRIVER] callbacks and constant info from driver * @clock_id: [INTERN] timestamping clock posix identifier -* @info_exist_lock: [INTERN] lock to prevent use during removal * @setup_ops: [DRIVER] callbacks to call before and after buffer * enable/disable * @chrdev: [INTERN] associated character device
@@ -542,7 +541,6 @@ struct iio_dev {const char *label;const struct iio_info *info;clockid_t clock_id; -struct mutex info_exist_lock;const struct iio_buffer_setup_ops *setup_ops;struct cdev chrdev;
Signature · 1 line
2.31.1
Jonathan Cameron
maintainerPATCH 7/9 iio: core: move @chrdev from struct iio_dev to struct iio_dev_opaque
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
No reason for this to be exposed to the drivers, so lets move it to the opaque structure.
--- drivers/iio/industrialio-core.c | 20 +++++++++++--------- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 2 -- 3 files changed, 13 insertions(+), 11 deletions(-)
drivers/iio/industrialio-core.c +11 -9
@@ -1715,8 +1715,9 @@ EXPORT_SYMBOL_GPL(devm_iio_device_alloc);**/ static int iio_chrdev_open (struct inode *inode,struct file *filp) { -struct iio_dev *indio_dev =container_of (inode->i_cdev, - struct iio_dev, chrdev); +struct iio_dev_opaque *iio_dev_opaque = + container_of(inode->i_cdev, struct iio_dev_opaque, chrdev); +struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;struct iio_dev_buffer_pair *ib;if (test_and_set_bit (IIO_BUSY_BIT_POS , &indio_dev->flags))
@@ -1749,8 +1750,9 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)static int iio_chrdev_release (struct inode *inode,struct file *filp) {struct iio_dev_buffer_pair *ib = filp->private_data; -struct iio_dev *indio_dev =container_of (inode->i_cdev, - struct iio_dev, chrdev); +struct iio_dev_opaque *iio_dev_opaque = + container_of(inode->i_cdev, struct iio_dev_opaque, chrdev); +struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;kfree (ib);clear_bit (IIO_BUSY_BIT_POS , &indio_dev->flags);iio_device_put (indio_dev);
@@ -1901,19 +1903,19 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) indio_dev->setup_ops = &noop_ring_setup_ops;if (iio_dev_opaque->attached_buffers_cnt) -cdev_init (&indio_dev->chrdev, &iio_buffer_fileops); +cdev_init (&iio_dev_opaque->chrdev, &iio_buffer_fileops);else if (iio_dev_opaque->event_interface) -cdev_init (&indio_dev->chrdev, &iio_event_fileops); +cdev_init (&iio_dev_opaque->chrdev, &iio_event_fileops);if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) { indio_dev->dev.devt =MKDEV (MAJOR (iio_devt), iio_dev_opaque->id); - indio_dev->chrdev.owner = this_mod; + iio_dev_opaque->chrdev.owner = this_mod; }/* assign device groups now; they should be all registered now */ indio_dev->dev.groups = iio_dev_opaque->groups; - ret =cdev_device_add (&indio_dev->chrdev, &indio_dev->dev); + ret =cdev_device_add (&iio_dev_opaque->chrdev, &indio_dev->dev);if (ret <0 ) goto error_unreg_eventset;
@@ -1940,7 +1942,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev);struct iio_ioctl_handler *h, *t; -cdev_device_del (&indio_dev->chrdev, &indio_dev->dev); +cdev_device_del (&iio_dev_opaque->chrdev, &indio_dev->dev);mutex_lock (&iio_dev_opaque->info_exist_lock);
include/linux/iio/iio-opaque.h +2 -0
@@ -24,6 +24,7 @@* @legacy_scan_el_group: attribute group for legacy scan elements attribute group * @legacy_buffer_group: attribute group for legacy buffer attributes group * @scan_index_timestamp: cache of the index to the timestamp +* @chrdev: associated character device * @debugfs_dentry: device specific debugfs dentry * @cached_reg_addr: cached register address for debugfs reads * @read_buf: read buffer to be used for the initial reg read
@@ -49,6 +50,7 @@ struct iio_dev_opaque {struct attribute_group legacy_buffer_group;unsigned int scan_index_timestamp; +struct cdev chrdev;#if defined(CONFIG_DEBUG_FS )struct dentry *debugfs_dentry;
include/linux/iio/iio.h +0 -2
@@ -512,7 +512,6 @@ struct iio_buffer_setup_ops {* @clock_id: [INTERN] timestamping clock posix identifier * @setup_ops: [DRIVER] callbacks to call before and after buffer * enable/disable -* @chrdev: [INTERN] associated character device * @flags: [INTERN] file ops related flags including busy flag. * @priv: [DRIVER] reference to driver's private information * **MUST** be accessed **ONLY** via iio_priv() helper
@@ -542,7 +541,6 @@ struct iio_dev {const struct iio_info *info;clockid_t clock_id;const struct iio_buffer_setup_ops *setup_ops; -struct cdev chrdev;unsigned long flags;void *priv;
Signature · 1 line
2.31.1
Jonathan Cameron
maintainerPATCH 8/9 iio: core: move @flags from struct iio_dev to struct iio_dev_opaque
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
No reason any driver should ever need access to this field, so hide it.
--- drivers/iio/industrialio-core.c | 6 +++--- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 2 -- 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/iio/industrialio-core.c +3 -3
@@ -1720,7 +1720,7 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;struct iio_dev_buffer_pair *ib; -if (test_and_set_bit (IIO_BUSY_BIT_POS , &indio_dev->flags)) +if (test_and_set_bit (IIO_BUSY_BIT_POS , &iio_dev_opaque->flags))return -EBUSY ;iio_device_get (indio_dev);
@@ -1728,7 +1728,7 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp) ib =kmalloc (sizeof (*ib),GFP_KERNEL );if (!ib) {iio_device_put (indio_dev); -clear_bit (IIO_BUSY_BIT_POS , &indio_dev->flags); +clear_bit (IIO_BUSY_BIT_POS , &iio_dev_opaque->flags);return -ENOMEM ; }
@@ -1754,7 +1754,7 @@ static int iio_chrdev_release(struct inode *inode, struct file *filp) container_of(inode->i_cdev, struct iio_dev_opaque, chrdev);struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;kfree (ib); -clear_bit (IIO_BUSY_BIT_POS , &indio_dev->flags); +clear_bit (IIO_BUSY_BIT_POS , &iio_dev_opaque->flags);iio_device_put (indio_dev);return 0 ;
include/linux/iio/iio-opaque.h +2 -0
@@ -25,6 +25,7 @@* @legacy_buffer_group: attribute group for legacy buffer attributes group * @scan_index_timestamp: cache of the index to the timestamp * @chrdev: associated character device +* @flags: file ops related flags including busy flag. * @debugfs_dentry: device specific debugfs dentry * @cached_reg_addr: cached register address for debugfs reads * @read_buf: read buffer to be used for the initial reg read
@@ -51,6 +52,7 @@ struct iio_dev_opaque {unsigned int scan_index_timestamp;struct cdev chrdev; +unsigned long flags;#if defined(CONFIG_DEBUG_FS )struct dentry *debugfs_dentry;
include/linux/iio/iio.h +0 -2
@@ -512,7 +512,6 @@ struct iio_buffer_setup_ops {* @clock_id: [INTERN] timestamping clock posix identifier * @setup_ops: [DRIVER] callbacks to call before and after buffer * enable/disable -* @flags: [INTERN] file ops related flags including busy flag. * @priv: [DRIVER] reference to driver's private information * **MUST** be accessed **ONLY** via iio_priv() helper */
@@ -542,7 +541,6 @@ struct iio_dev {clockid_t clock_id;const struct iio_buffer_setup_ops *setup_ops; -unsigned long flags;void *priv; };
Signature · 1 line
2.31.1
Jonathan Cameron
maintainerPATCH 9/9 iio: core: move @clock_id from struct iio_dev to struct iio_dev_opaque
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
There is already an acessor function used to access it, making this move straight forward.
--- drivers/iio/industrialio-core.c | 14 +++++++++++++- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 12 +----------- 3 files changed, 16 insertions(+), 12 deletions(-)
drivers/iio/industrialio-core.c +13 -1
@@ -271,13 +271,25 @@ int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)mutex_unlock (&indio_dev->mlock);return -EBUSY ; } - indio_dev->clock_id = clock_id; + iio_dev_opaque->clock_id = clock_id;mutex_unlock (&indio_dev->mlock);return 0 ; }EXPORT_SYMBOL (iio_device_set_clock); +/** +* iio_device_get_clock() - Retrieve current timestamping clock for the device +* @indio_dev: IIO device structure containing the device +*/ +clockid_t iio_device_get_clock (const struct iio_dev *indio_dev) +{ +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev); + +return iio_dev_opaque->clock_id; +} +EXPORT_SYMBOL (iio_device_get_clock); +/** * iio_get_time_ns() - utility function to get a time stamp for events etc * @indio_dev: device
include/linux/iio/iio-opaque.h +2 -0
@@ -24,6 +24,7 @@* @legacy_scan_el_group: attribute group for legacy scan elements attribute group * @legacy_buffer_group: attribute group for legacy buffer attributes group * @scan_index_timestamp: cache of the index to the timestamp +* @clock_id: timestamping clock posix identifier * @chrdev: associated character device * @flags: file ops related flags including busy flag. * @debugfs_dentry: device specific debugfs dentry
@@ -51,6 +52,7 @@ struct iio_dev_opaque {struct attribute_group legacy_buffer_group;unsigned int scan_index_timestamp; +clockid_t clock_id;struct cdev chrdev;unsigned long flags;
include/linux/iio/iio.h +1 -11
@@ -509,7 +509,6 @@ struct iio_buffer_setup_ops {* @name: [DRIVER] name of the device. * @label: [DRIVER] unique name to identify which device this is * @info: [DRIVER] callbacks and constant info from driver -* @clock_id: [INTERN] timestamping clock posix identifier * @setup_ops: [DRIVER] callbacks to call before and after buffer * enable/disable * @priv: [DRIVER] reference to driver's private information
@@ -538,7 +537,6 @@ struct iio_dev {const char *name;const char *label;const struct iio_info *info; -clockid_t clock_id;const struct iio_buffer_setup_ops *setup_ops;void *priv;
@@ -589,15 +587,7 @@ static inline void iio_device_put(struct iio_dev *indio_dev)put_device (&indio_dev->dev); } -/** -* iio_device_get_clock() - Retrieve current timestamping clock for the device -* @indio_dev: IIO device structure containing the device -*/ -static inline clockid_t iio_device_get_clock (const struct iio_dev *indio_dev) -{ -return indio_dev->clock_id; -} - +clockid_t iio_device_get_clock (const struct iio_dev *indio_dev);int iio_device_set_clock (struct iio_dev *indio_dev,clockid_t clock_id);/**
Signature · 1 line
2.31.1
Re: [PATCH 1/9] iio: core: move @id from struct iio_dev to struct iio_dev_opaque
In reply to Jonathan CameronQuoted 10 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
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.
The way I was thinking [initially] about moving this, is to somehow try to unify/generalize the {devm_}iio_trigger_alloc() function. It looks like the IIO device ID is needed only there. Maybe there is a good solution for this; maybe if we just provide the fmt string, and have a convention that the IIO device name and ID are filled in.
Though that's tricky.
But this iio_device_id() getter is also a good approach for now.
Quoted 814 lines
Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/accel/adxl372.c | 4 ++-- drivers/iio/accel/bma180.c | 2 +- drivers/iio/accel/bmc150-accel-core.c | 4 ++-- drivers/iio/accel/kxcjk-1013.c | 4 ++-- drivers/iio/accel/mma8452.c | 2 +- drivers/iio/accel/mxc4005.c | 2 +- drivers/iio/accel/stk8312.c | 2 +- drivers/iio/accel/stk8ba50.c | 2 +- drivers/iio/adc/ad7606.c | 3 ++- drivers/iio/adc/ad7766.c | 3 ++- drivers/iio/adc/ad7768-1.c | 3 ++- drivers/iio/adc/ad_sigma_delta.c | 2 +- drivers/iio/adc/at91_adc.c | 4 ++-- drivers/iio/adc/dln2-adc.c | 3 ++- drivers/iio/adc/ina2xx-adc.c | 3 ++- drivers/iio/adc/ti-ads131e08.c | 2 +- drivers/iio/adc/xilinx-xadc-core.c | 2 +- .../buffer/industrialio-triggered-buffer.c | 2 +- drivers/iio/chemical/atlas-sensor.c | 2 +- drivers/iio/chemical/ccs811.c | 2 +- drivers/iio/chemical/scd30_core.c | 3 ++- .../common/hid-sensors/hid-sensor-trigger.c | 2 +- drivers/iio/gyro/adxrs290.c | 2 +- drivers/iio/gyro/bmg160_core.c | 4 ++-- drivers/iio/gyro/fxas21002c_core.c | 2 +- drivers/iio/gyro/itg3200_buffer.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/health/afe4403.c | 2 +- drivers/iio/health/afe4404.c | 2 +- drivers/iio/imu/adis_trigger.c | 3 ++- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 2 +- drivers/iio/imu/kmx61.c | 2 +- drivers/iio/industrialio-core.c | 24 +++++++++++++++---- drivers/iio/industrialio-triggered-event.c | 2 +- drivers/iio/light/acpi-als.c | 3 ++- drivers/iio/light/rpr0521.c | 2 +- drivers/iio/light/si1145.c | 2 +- drivers/iio/light/vcnl4000.c | 3 ++- drivers/iio/light/vcnl4035.c | 2 +- drivers/iio/magnetometer/bmc150_magn.c | 2 +- drivers/iio/magnetometer/rm3100-core.c | 2 +- drivers/iio/potentiostat/lmp91000.c | 3 ++- drivers/iio/pressure/zpa2326.c | 3 ++- drivers/iio/proximity/as3935.c | 3 ++- drivers/iio/proximity/sx9310.c | 2 +- drivers/iio/proximity/sx9500.c | 2 +- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 4 ++-- 49 files changed, 87 insertions(+), 58 deletions(-)drivers/iio/accel/adxl372.c +2
-2@@ -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 ;drivers/iio/accel/bma180.c +1
-1@@ -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;drivers/iio/accel/bmc150-accel-core.c +2
-2@@ -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 ;drivers/iio/accel/kxcjk-1013.c +2
-2@@ -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;drivers/iio/accel/mma8452.c +1
-1@@ -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 ;drivers/iio/accel/mxc4005.c +1
-1@@ -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 ;drivers/iio/accel/stk8312.c +1
-1@@ -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;drivers/iio/accel/stk8ba50.c +1
-1@@ -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;drivers/iio/adc/ad7606.c +2
-1@@ -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 ;drivers/iio/adc/ad7766.c +2
-1@@ -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 ;drivers/iio/adc/ad7768-1.c +2
-1@@ -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 ;drivers/iio/adc/ad_sigma_delta.c +1
-1@@ -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;drivers/iio/adc/at91_adc.c +2
-2@@ -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 ;drivers/iio/adc/dln2-adc.c +2
-1@@ -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 ;drivers/iio/adc/ina2xx-adc.c +2
-1@@ -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);drivers/iio/adc/ti-ads131e08.c +1
-1@@ -844,7 +844,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 ;drivers/iio/adc/xilinx-xadc-core.c +1
-1@@ -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 );drivers/iio/buffer/industrialio-triggered-buffer.c +1
-1@@ -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;drivers/iio/chemical/atlas-sensor.c +1
-1@@ -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 ;drivers/iio/chemical/ccs811.c +1
-1@@ -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;drivers/iio/chemical/scd30_core.c +2
-1@@ -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 ;drivers/iio/common/hid-sensors/hid-sensor-trigger.c +1
-1@@ -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 ;drivers/iio/gyro/adxrs290.c +1
-1@@ -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 ;drivers/iio/gyro/bmg160_core.c +2
-2@@ -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 ;drivers/iio/gyro/fxas21002c_core.c +1
-1@@ -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 ;drivers/iio/gyro/itg3200_buffer.c +1
-1@@ -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 ;drivers/iio/gyro/mpu3050-core.c +1
-1@@ -1049,7 +1049,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 ;drivers/iio/health/afe4403.c +1
-1@@ -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 ;drivers/iio/health/afe4404.c +1
-1@@ -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 ;drivers/iio/imu/adis_trigger.c +2
-1@@ -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 ;drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -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 ;drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +1
-1@@ -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 ;drivers/iio/imu/kmx61.c +1
-1@@ -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 );drivers/iio/industrialio-core.c +19
-5@@ -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);@@ -1892,7 +1906,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; }drivers/iio/industrialio-triggered-event.c +1
-1@@ -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 ;drivers/iio/light/acpi-als.c +2
-1@@ -206,7 +206,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 ;drivers/iio/light/rpr0521.c +1
-1@@ -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;drivers/iio/light/si1145.c +1
-1@@ -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 ;drivers/iio/light/vcnl4000.c +2
-1@@ -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 ;drivers/iio/light/vcnl4035.c +1
-1@@ -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 ;drivers/iio/magnetometer/bmc150_magn.c +1
-1@@ -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" );drivers/iio/magnetometer/rm3100-core.c +1
-1@@ -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 ;drivers/iio/potentiostat/lmp91000.c +2
-1@@ -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 ;drivers/iio/pressure/zpa2326.c +2
-1@@ -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 ;drivers/iio/proximity/as3935.c +2
-1@@ -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 ;drivers/iio/proximity/sx9310.c +1
-1@@ -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 ;drivers/iio/proximity/sx9500.c +1
-1@@ -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 ;include/linux/iio/iio-opaque.h +2
-0@@ -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;include/linux/iio/iio.h +2
-3@@ -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);/** -- 2.31.1
Re: [PATCH 2/9] iio: avoid shadowing of variable name in to_iio_dev_opaque()
In reply to Jonathan CameronQuoted 10 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
indio_devwas both the macro input parameter and the field name in this macro. That causes trouble if the instance of structiio_devpassed in is not calledindio_dev.Whilst a fix of sorts, no need to backport as it seems we never hit this previously due to some very consistent naming in IIO.
Quoted 22 lines
Signed-off-by Jonathan Cameron <[email protected]>--- include/linux/iio/iio-opaque.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/linux/iio/iio-opaque.h +2
-3@@ -48,7 +48,7 @@ struct iio_dev_opaque { #endif }; -#define to_iio_dev_opaque (indio_dev) \ - container_of(indio_dev, struct iio_dev_opaque, indio_dev) +#define to_iio_dev_opaque (_indio_dev) \ + container_of((_indio_dev), struct iio_dev_opaque, indio_dev)#endif --2.31.1
Re: [PATCH 9/9] iio: core: move @clock_id from struct iio_dev to struct iio_dev_opaque
In reply to Jonathan CameronQuoted 5 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
There is already an acessor function used to access it, making this move straight forward.
Right now the iio_device_get_clock() helper is only being used in the Chrome EC core sensor driver.
Maybe later if that can be reworked without this helper, then it could be made private to IIO core.
Though, chances are some other driver may come along later and ask for it to be public again.
Anyway.
Quoted 99 lines
Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/industrialio-core.c | 14 +++++++++++++- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 12 +----------- 3 files changed, 16 insertions(+), 12 deletions(-)drivers/iio/industrialio-core.c +13
-1@@ -271,13 +271,25 @@ int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)mutex_unlock (&indio_dev->mlock);return -EBUSY ; } - indio_dev->clock_id = clock_id; + iio_dev_opaque->clock_id = clock_id;mutex_unlock (&indio_dev->mlock);return 0 ; }EXPORT_SYMBOL (iio_device_set_clock); +/** +* iio_device_get_clock() - Retrieve current timestamping clock for the device +* @indio_dev: IIO device structure containing the device +*/ +clockid_t iio_device_get_clock (const struct iio_dev *indio_dev) +{ +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev); + +return iio_dev_opaque->clock_id; +} +EXPORT_SYMBOL (iio_device_get_clock); +/** * iio_get_time_ns() - utility function to get a time stamp for events etc * @indio_dev: device include/linux/iio/iio-opaque.h +2
-0@@ -24,6 +24,7 @@* @legacy_scan_el_group: attribute group for legacy scan elements attribute group * @legacy_buffer_group: attribute group for legacy buffer attributes group * @scan_index_timestamp: cache of the index to the timestamp +* @clock_id: timestamping clock posix identifier * @chrdev: associated character device * @flags: file ops related flags including busy flag. * @debugfs_dentry: device specific debugfs dentry @@ -51,6 +52,7 @@ struct iio_dev_opaque {struct attribute_group legacy_buffer_group;unsigned int scan_index_timestamp; +clockid_t clock_id;struct cdev chrdev;unsigned long flags;include/linux/iio/iio.h +1
-12@@ -509,7 +509,6 @@ struct iio_buffer_setup_ops {* @name: [DRIVER] name of the device. * @label: [DRIVER] unique name to identify which device this is * @info: [DRIVER] callbacks and constant info from driver -* @clock_id: [INTERN] timestamping clock posix identifier * @setup_ops: [DRIVER] callbacks to call before and after buffer * enable/disable * @priv: [DRIVER] reference to driver's private information @@ -538,7 +537,6 @@ struct iio_dev {const char *name;const char *label;const struct iio_info *info; -clockid_t clock_id;const struct iio_buffer_setup_ops *setup_ops;void *priv;@@ -589,15 +587,7 @@ static inline void iio_device_put(struct iio_dev *indio_dev)put_device (&indio_dev->dev); } -/** -* iio_device_get_clock() - Retrieve current timestamping clock for the device -* @indio_dev: IIO device structure containing the device -*/ -static inline clockid_t iio_device_get_clock (const struct iio_dev *indio_dev) -{ -return indio_dev->clock_id; -} - +clockid_t iio_device_get_clock (const struct iio_dev *indio_dev);int iio_device_set_clock (struct iio_dev *indio_dev,clockid_t clock_id);/** -- 2.31.1
Re: [PATCH 4/9] iio: core: move @trig_readonly from struct iio_dev to struct iio_dev_opaque
In reply to Jonathan CameronQuoted 6 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
This is only set via the
iio_trig_set_immutable()call and later used by the IIO core so there is no benefit in drivers being able to access it.
Quoted 92 lines
Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/industrialio-trigger.c | 10 +++++++--- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 2 -- 3 files changed, 9 insertions(+), 5 deletions(-)drivers/iio/industrialio-trigger.c +7
-3@@ -117,14 +117,17 @@ EXPORT_SYMBOL(iio_trigger_unregister);int iio_trigger_set_immutable (struct iio_dev *indio_dev,struct iio_trigger *trig) { +struct iio_dev_opaque *iio_dev_opaque; +if (!indio_dev || !trig)return -EINVAL ; + iio_dev_opaque =to_iio_dev_opaque (indio_dev);mutex_lock (&indio_dev->mlock); -WARN_ON (indio_dev->trig_readonly); +WARN_ON (iio_dev_opaque->trig_readonly); indio_dev->trig =iio_trigger_get (trig); - indio_dev->trig_readonly = true; + iio_dev_opaque->trig_readonly = true;mutex_unlock (&indio_dev->mlock);return 0 ;@@ -402,6 +405,7 @@ static ssize_t iio_trigger_write_current(struct device *dev, size_t len) {struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev);struct iio_trigger *oldtrig = indio_dev->trig;struct iio_trigger *trig;int ret;@@ -411,7 +415,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,mutex_unlock (&indio_dev->mlock);return -EBUSY ; } -if (indio_dev->trig_readonly) { +if (iio_dev_opaque->trig_readonly) {mutex_unlock (&indio_dev->mlock);return -EPERM ; }include/linux/iio/iio-opaque.h +2
-0@@ -8,6 +8,7 @@* @indio_dev: public industrial I/O device information * @id: used to identify device internally * @driver_module: used to make it harder to undercut users +* @trig_readonly: mark the current trigger immutable * @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 @@ -30,6 +31,7 @@ struct iio_dev_opaque {struct iio_dev indio_dev;int id;struct module *driver_module; +bool trig_readonly;struct iio_event_interface *event_interface;struct iio_buffer **attached_buffers;unsigned int attached_buffers_cnt;include/linux/iio/iio.h +0
-3@@ -503,7 +503,6 @@ struct iio_buffer_setup_ops {* @scan_timestamp: [INTERN] set if any buffers have requested timestamp * @scan_index_timestamp:[INTERN] cache of the index to the timestamp * @trig: [INTERN] current device trigger (buffer modes) -* @trig_readonly: [INTERN] mark the current trigger immutable * @pollfunc: [DRIVER] function run on trigger being received * @pollfunc_event: [DRIVER] function run on events trigger being received * @channels: [DRIVER] channel specification structure table @@ -535,7 +534,6 @@ struct iio_dev {bool scan_timestamp;unsigned scan_index_timestamp;struct iio_trigger *trig; -bool trig_readonly;struct iio_poll_func *pollfunc;struct iio_poll_func *pollfunc_event; --2.31.1
Re: [PATCH 5/9] iio: core: move @scan_index_timestamp to struct iio_dev_opaque
In reply to Jonathan CameronQuoted 6 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
No reason for this cached value to be exposed to drivers so move it to the opaque structure.
Quoted 85 lines
Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/industrialio-buffer.c | 7 +++++-- include/linux/iio/iio-opaque.h | 4 ++++ include/linux/iio/iio.h | 2 -- 3 files changed, 9 insertions(+), 4 deletions(-)drivers/iio/industrialio-buffer.c +5
-2@@ -601,8 +601,10 @@ static unsigned int iio_storage_bytes_for_si(struct iio_dev *indio_dev,static unsigned int iio_storage_bytes_for_timestamp (struct iio_dev *indio_dev) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev); +return iio_storage_bytes_for_si (indio_dev, - indio_dev->scan_index_timestamp); + iio_dev_opaque->scan_index_timestamp); } static int iio_compute_scan_bytes(struct iio_dev *indio_dev,@@ -1469,6 +1471,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, struct iio_dev *indio_dev, int index) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev);struct iio_dev_attr *p;struct attribute **attr;int ret, i, attrn, scan_el_attrcount, buffer_attrcount;@@ -1495,7 +1498,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, goto error_cleanup_dynamic; scan_el_attrcount += ret;if (channels[i].type ==IIO_TIMESTAMP ) - indio_dev->scan_index_timestamp = + iio_dev_opaque->scan_index_timestamp = channels[i].scan_index; }if (indio_dev->masklength && buffer->scan_mask ==NULL ) {include/linux/iio/iio-opaque.h +4
-0@@ -22,6 +22,7 @@* @groupcounter: index of next attribute group * @legacy_scan_el_group: attribute group for legacy scan elements attribute group * @legacy_buffer_group: attribute group for legacy buffer attributes group +* @scan_index_timestamp: cache of the index to the timestamp * @debugfs_dentry: device specific debugfs dentry * @cached_reg_addr: cached register address for debugfs reads * @read_buf: read buffer to be used for the initial reg read @@ -44,6 +45,9 @@ struct iio_dev_opaque {int groupcounter;struct attribute_group legacy_scan_el_group;struct attribute_group legacy_buffer_group; + +unsigned int scan_index_timestamp; +#if defined(CONFIG_DEBUG_FS )struct dentry *debugfs_dentry;unsigned cached_reg_addr;include/linux/iio/iio.h +0
-3@@ -501,7 +501,6 @@ struct iio_buffer_setup_ops {* channels * @active_scan_mask: [INTERN] union of all scan masks requested by buffers * @scan_timestamp: [INTERN] set if any buffers have requested timestamp -* @scan_index_timestamp:[INTERN] cache of the index to the timestamp * @trig: [INTERN] current device trigger (buffer modes) * @pollfunc: [DRIVER] function run on trigger being received * @pollfunc_event: [DRIVER] function run on events trigger being received @@ -532,7 +531,6 @@ struct iio_dev {unsigned masklength;const unsigned long *active_scan_mask;bool scan_timestamp; -unsigned scan_index_timestamp;struct iio_trigger *trig;struct iio_poll_func *pollfunc;struct iio_poll_func *pollfunc_event; --2.31.1
Re: [PATCH 6/9] iio: core: move @info_exist_lock to struct iio_dev_opaque
In reply to Jonathan CameronQuoted 5 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
This lock is only of interest to the IIO core, so make it only visible there.
This was on my list at some point, but I deferred it because it was overlapping with the IIO buffer stuff.
Quoted 333 lines
Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/industrialio-buffer.c | 5 ++-- drivers/iio/industrialio-core.c | 10 +++---- drivers/iio/inkern.c | 46 +++++++++++++++++++------------ include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 2 -- 5 files changed, 38 insertions(+), 27 deletions(-)drivers/iio/industrialio-buffer.c +3
-2@@ -1150,12 +1150,13 @@ int iio_update_buffers(struct iio_dev *indio_dev,struct iio_buffer *insert_buffer, struct iio_buffer *remove_buffer) { + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);int ret;if (insert_buffer == remove_buffer)return 0 ; -mutex_lock (&indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);mutex_lock (&indio_dev->mlock);if (insert_buffer &&iio_buffer_is_active (insert_buffer))@@ -1178,7 +1179,7 @@ int iio_update_buffers(struct iio_dev *indio_dev, out_unlock:mutex_unlock (&indio_dev->mlock); -mutex_unlock (&indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);return ret; }drivers/iio/industrialio-core.c +5
-5@@ -1642,7 +1642,7 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)device_initialize (&indio_dev->dev);iio_device_set_drvdata (indio_dev, (void *)indio_dev);mutex_init (&indio_dev->mlock); -mutex_init (&indio_dev->info_exist_lock); +mutex_init (&iio_dev_opaque->info_exist_lock);INIT_LIST_HEAD (&iio_dev_opaque->channel_attr_list); iio_dev_opaque->id =ida_simple_get (&iio_ida,0 ,0 ,GFP_KERNEL );@@ -1779,7 +1779,7 @@ static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)struct iio_ioctl_handler *h;int ret = -ENODEV ; -mutex_lock (&indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);/** * The NULL check here is required to prevent crashing when a device @@ -1800,7 +1800,7 @@ static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ret = -EINVAL ; out_unlock: -mutex_unlock (&indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);return ret; }@@ -1942,7 +1942,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)cdev_device_del (&indio_dev->chrdev, &indio_dev->dev); -mutex_lock (&indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);iio_device_unregister_debugfs (indio_dev);@@ -1956,7 +1956,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)iio_device_wakeup_eventset (indio_dev);iio_buffer_wakeup_poll (indio_dev); -mutex_unlock (&indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);iio_buffers_free_sysfs_and_mask (indio_dev); }drivers/iio/inkern.c +28
-18@@ -10,6 +10,7 @@#include <linux/of.h> #include <linux/iio/iio.h> +#include <linux/iio/iio-opaque.h> #include "iio_core.h" #include <linux/iio/machine.h> #include <linux/iio/driver.h> @@ -538,9 +539,10 @@ static int iio_channel_read(struct iio_channel *chan, int *val, int *val2,int iio_read_channel_raw (struct iio_channel *chan,int *val) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (chan->indio_dev);int ret; -mutex_lock (&chan->indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);if (chan->indio_dev->info ==NULL ) { ret = -ENODEV ; goto err_unlock;@@ -548,7 +550,7 @@ int iio_read_channel_raw(struct iio_channel *chan, int *val) ret =iio_channel_read (chan, val,NULL ,IIO_CHAN_INFO_RAW ); err_unlock: -mutex_unlock (&chan->indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);return ret; }@@ -556,9 +558,10 @@ EXPORT_SYMBOL_GPL(iio_read_channel_raw);int iio_read_channel_average_raw (struct iio_channel *chan,int *val) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (chan->indio_dev);int ret; -mutex_lock (&chan->indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);if (chan->indio_dev->info ==NULL ) { ret = -ENODEV ; goto err_unlock;@@ -566,7 +569,7 @@ int iio_read_channel_average_raw(struct iio_channel *chan, int *val) ret =iio_channel_read (chan, val,NULL ,IIO_CHAN_INFO_AVERAGE_RAW ); err_unlock: -mutex_unlock (&chan->indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);return ret; }@@ -631,9 +634,10 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,int iio_convert_raw_to_processed (struct iio_channel *chan,int raw,int *processed,unsigned int scale) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (chan->indio_dev);int ret; -mutex_lock (&chan->indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);if (chan->indio_dev->info ==NULL ) { ret = -ENODEV ; goto err_unlock;@@ -642,7 +646,7 @@ int iio_convert_raw_to_processed(struct iio_channel *chan, int raw, ret =iio_convert_raw_to_processed_unlocked (chan, raw, processed, scale); err_unlock: -mutex_unlock (&chan->indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);return ret; }@@ -651,9 +655,10 @@ EXPORT_SYMBOL_GPL(iio_convert_raw_to_processed);int iio_read_channel_attribute (struct iio_channel *chan,int *val,int *val2,enum iio_chan_info_enum attribute) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (chan->indio_dev);int ret; -mutex_lock (&chan->indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);if (chan->indio_dev->info ==NULL ) { ret = -ENODEV ; goto err_unlock;@@ -661,7 +666,7 @@ int iio_read_channel_attribute(struct iio_channel *chan, int *val, int *val2, ret =iio_channel_read (chan, val, val2, attribute); err_unlock: -mutex_unlock (&chan->indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);return ret; }@@ -676,9 +681,10 @@ EXPORT_SYMBOL_GPL(iio_read_channel_offset);int iio_read_channel_processed_scale (struct iio_channel *chan,int *val,unsigned int scale) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (chan->indio_dev);int ret; -mutex_lock (&chan->indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);if (chan->indio_dev->info ==NULL ) { ret = -ENODEV ; goto err_unlock;@@ -699,7 +705,7 @@ int iio_read_channel_processed_scale(struct iio_channel *chan, int *val, } err_unlock: -mutex_unlock (&chan->indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);return ret; }@@ -733,9 +739,10 @@ int iio_read_avail_channel_attribute(struct iio_channel *chan, const int **vals, int *type, int *length, enum iio_chan_info_enum attribute) { + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);int ret; -mutex_lock (&chan->indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);if (!chan->indio_dev->info) { ret = -ENODEV ; goto err_unlock;@@ -743,7 +750,7 @@ int iio_read_avail_channel_attribute(struct iio_channel *chan, ret =iio_channel_read_avail (chan, vals, type, length, attribute); err_unlock: -mutex_unlock (&chan->indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);return ret; }@@ -815,10 +822,11 @@ static int iio_channel_read_max(struct iio_channel *chan,int iio_read_max_channel_raw (struct iio_channel *chan,int *val) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (chan->indio_dev);int ret;int type; -mutex_lock (&chan->indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);if (!chan->indio_dev->info) { ret = -ENODEV ; goto err_unlock;@@ -826,7 +834,7 @@ int iio_read_max_channel_raw(struct iio_channel *chan, int *val) ret =iio_channel_read_max (chan, val,NULL , &type,IIO_CHAN_INFO_RAW ); err_unlock: -mutex_unlock (&chan->indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);return ret; }@@ -834,10 +842,11 @@ EXPORT_SYMBOL_GPL(iio_read_max_channel_raw);int iio_get_channel_type (struct iio_channel *chan,enum iio_chan_type *type) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (chan->indio_dev);int ret =0 ;/* Need to verify underlying driver has not gone away */ -mutex_lock (&chan->indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);if (chan->indio_dev->info ==NULL ) { ret = -ENODEV ; goto err_unlock;@@ -845,7 +854,7 @@ int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type) *type = chan->channel->type; err_unlock: -mutex_unlock (&chan->indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);return ret; }@@ -861,9 +870,10 @@ static int iio_channel_write(struct iio_channel *chan, int val, int val2,int iio_write_channel_attribute (struct iio_channel *chan,int val,int val2,enum iio_chan_info_enum attribute) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (chan->indio_dev);int ret; -mutex_lock (&chan->indio_dev->info_exist_lock); +mutex_lock (&iio_dev_opaque->info_exist_lock);if (chan->indio_dev->info ==NULL ) { ret = -ENODEV ; goto err_unlock;@@ -871,7 +881,7 @@ int iio_write_channel_attribute(struct iio_channel *chan, int val, int val2, ret =iio_channel_write (chan, val, val2, attribute); err_unlock: -mutex_unlock (&chan->indio_dev->info_exist_lock); +mutex_unlock (&iio_dev_opaque->info_exist_lock);return ret; }include/linux/iio/iio-opaque.h +2
-0@@ -8,6 +8,7 @@* @indio_dev: public industrial I/O device information * @id: used to identify device internally * @driver_module: used to make it harder to undercut users +* @info_exist_lock: lock to prevent use during removal * @trig_readonly: mark the current trigger immutable * @event_interface: event chrdevs associated with interrupt lines * @attached_buffers: array of buffers statically attached by the driver @@ -32,6 +33,7 @@ struct iio_dev_opaque {struct iio_dev indio_dev;int id;struct module *driver_module; +struct mutex info_exist_lock;bool trig_readonly;struct iio_event_interface *event_interface;struct iio_buffer **attached_buffers;include/linux/iio/iio.h +0
-3@@ -510,7 +510,6 @@ struct iio_buffer_setup_ops {* @label: [DRIVER] unique name to identify which device this is * @info: [DRIVER] callbacks and constant info from driver * @clock_id: [INTERN] timestamping clock posix identifier -* @info_exist_lock: [INTERN] lock to prevent use during removal * @setup_ops: [DRIVER] callbacks to call before and after buffer * enable/disable * @chrdev: [INTERN] associated character device @@ -542,7 +541,6 @@ struct iio_dev {const char *label;const struct iio_info *info;clockid_t clock_id; -struct mutex info_exist_lock;const struct iio_buffer_setup_ops *setup_ops;struct cdev chrdev; --2.31.1
Re: [PATCH 7/9] iio: core: move @chrdev from struct iio_dev to struct iio_dev_opaque
In reply to Jonathan CameronQuoted 5 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
No reason for this to be exposed to the drivers, so lets move it to the opaque structure.
Even though this looks straightforward, I am paranoid about it. Mostly because of all the chardev juggling that I tried.
Quoted 112 lines
Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/industrialio-core.c | 20 +++++++++++--------- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 2 -- 3 files changed, 13 insertions(+), 11 deletions(-)drivers/iio/industrialio-core.c +11
-9@@ -1715,8 +1715,9 @@ EXPORT_SYMBOL_GPL(devm_iio_device_alloc);**/ static int iio_chrdev_open (struct inode *inode,struct file *filp) { -struct iio_dev *indio_dev =container_of (inode->i_cdev, - struct iio_dev, chrdev); +struct iio_dev_opaque *iio_dev_opaque = + container_of(inode->i_cdev, struct iio_dev_opaque, chrdev); +struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;struct iio_dev_buffer_pair *ib;if (test_and_set_bit (IIO_BUSY_BIT_POS , &indio_dev->flags))@@ -1749,8 +1750,9 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)static int iio_chrdev_release (struct inode *inode,struct file *filp) {struct iio_dev_buffer_pair *ib = filp->private_data; -struct iio_dev *indio_dev =container_of (inode->i_cdev, - struct iio_dev, chrdev); +struct iio_dev_opaque *iio_dev_opaque = + container_of(inode->i_cdev, struct iio_dev_opaque, chrdev); +struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;kfree (ib);clear_bit (IIO_BUSY_BIT_POS , &indio_dev->flags);iio_device_put (indio_dev);@@ -1901,19 +1903,19 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) indio_dev->setup_ops = &noop_ring_setup_ops;if (iio_dev_opaque->attached_buffers_cnt) -cdev_init (&indio_dev->chrdev, &iio_buffer_fileops); +cdev_init (&iio_dev_opaque->chrdev, &iio_buffer_fileops);else if (iio_dev_opaque->event_interface) -cdev_init (&indio_dev->chrdev, &iio_event_fileops); +cdev_init (&iio_dev_opaque->chrdev, &iio_event_fileops);if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) { indio_dev->dev.devt =MKDEV (MAJOR (iio_devt), iio_dev_opaque->id); - indio_dev->chrdev.owner = this_mod; + iio_dev_opaque->chrdev.owner = this_mod; }/* assign device groups now; they should be all registered now */ indio_dev->dev.groups = iio_dev_opaque->groups; - ret =cdev_device_add (&indio_dev->chrdev, &indio_dev->dev); + ret =cdev_device_add (&iio_dev_opaque->chrdev, &indio_dev->dev);if (ret <0 ) goto error_unreg_eventset;@@ -1940,7 +1942,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev);struct iio_ioctl_handler *h, *t; -cdev_device_del (&indio_dev->chrdev, &indio_dev->dev); +cdev_device_del (&iio_dev_opaque->chrdev, &indio_dev->dev);mutex_lock (&iio_dev_opaque->info_exist_lock);include/linux/iio/iio-opaque.h +2
-0@@ -24,6 +24,7 @@* @legacy_scan_el_group: attribute group for legacy scan elements attribute group * @legacy_buffer_group: attribute group for legacy buffer attributes group * @scan_index_timestamp: cache of the index to the timestamp +* @chrdev: associated character device * @debugfs_dentry: device specific debugfs dentry * @cached_reg_addr: cached register address for debugfs reads * @read_buf: read buffer to be used for the initial reg read @@ -49,6 +50,7 @@ struct iio_dev_opaque {struct attribute_group legacy_buffer_group;unsigned int scan_index_timestamp; +struct cdev chrdev;#if defined(CONFIG_DEBUG_FS )struct dentry *debugfs_dentry;include/linux/iio/iio.h +0
-3@@ -512,7 +512,6 @@ struct iio_buffer_setup_ops {* @clock_id: [INTERN] timestamping clock posix identifier * @setup_ops: [DRIVER] callbacks to call before and after buffer * enable/disable -* @chrdev: [INTERN] associated character device * @flags: [INTERN] file ops related flags including busy flag. * @priv: [DRIVER] reference to driver's private information * **MUST** be accessed **ONLY** via iio_priv() helper @@ -542,7 +541,6 @@ struct iio_dev {const struct iio_info *info;clockid_t clock_id;const struct iio_buffer_setup_ops *setup_ops; -struct cdev chrdev;unsigned long flags;void *priv; --2.31.1
Re: [PATCH 8/9] iio: core: move @flags from struct iio_dev to struct iio_dev_opaque
In reply to Jonathan CameronQuoted 5 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
No reason any driver should ever need access to this field, so hide it.
Quoted 81 lines
Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/industrialio-core.c | 6 +++--- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 2 -- 3 files changed, 5 insertions(+), 5 deletions(-)drivers/iio/industrialio-core.c +3
-3@@ -1720,7 +1720,7 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;struct iio_dev_buffer_pair *ib; -if (test_and_set_bit (IIO_BUSY_BIT_POS , &indio_dev->flags)) +if (test_and_set_bit (IIO_BUSY_BIT_POS , &iio_dev_opaque->flags))return -EBUSY ;iio_device_get (indio_dev);@@ -1728,7 +1728,7 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp) ib =kmalloc (sizeof (*ib),GFP_KERNEL );if (!ib) {iio_device_put (indio_dev); -clear_bit (IIO_BUSY_BIT_POS , &indio_dev->flags); +clear_bit (IIO_BUSY_BIT_POS , &iio_dev_opaque->flags);return -ENOMEM ; }@@ -1754,7 +1754,7 @@ static int iio_chrdev_release(struct inode *inode, struct file *filp) container_of(inode->i_cdev, struct iio_dev_opaque, chrdev);struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;kfree (ib); -clear_bit (IIO_BUSY_BIT_POS , &indio_dev->flags); +clear_bit (IIO_BUSY_BIT_POS , &iio_dev_opaque->flags);iio_device_put (indio_dev);return 0 ;include/linux/iio/iio-opaque.h +2
-0@@ -25,6 +25,7 @@* @legacy_buffer_group: attribute group for legacy buffer attributes group * @scan_index_timestamp: cache of the index to the timestamp * @chrdev: associated character device +* @flags: file ops related flags including busy flag. * @debugfs_dentry: device specific debugfs dentry * @cached_reg_addr: cached register address for debugfs reads * @read_buf: read buffer to be used for the initial reg read @@ -51,6 +52,7 @@ struct iio_dev_opaque {unsigned int scan_index_timestamp;struct cdev chrdev; +unsigned long flags;#if defined(CONFIG_DEBUG_FS )struct dentry *debugfs_dentry;include/linux/iio/iio.h +0
-3@@ -512,7 +512,6 @@ struct iio_buffer_setup_ops {* @clock_id: [INTERN] timestamping clock posix identifier * @setup_ops: [DRIVER] callbacks to call before and after buffer * enable/disable -* @flags: [INTERN] file ops related flags including busy flag. * @priv: [DRIVER] reference to driver's private information * **MUST** be accessed **ONLY** via iio_priv() helper */ @@ -542,7 +541,6 @@ struct iio_dev {clockid_t clock_id;const struct iio_buffer_setup_ops *setup_ops; -unsigned long flags;void *priv; }; --2.31.1
Quoted 9 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Intent here is to clear out the low hanging fruit so we can focus on the more interesting elements.
Hopefully this set are all uncontroversial. Lightly tested only but all fairly mechanical so hopefully I didn't mess up.
Series looks good.
Thanks for moving this forward :)
Alex
Quoted 87 lines
As for the others my current thinking is as follows
mlock: Still some instances to clear out of this being used to protect things it should not be used for. Long run we definitely want to move this one.
scan_timestamp: Can easily use a look up function in drivers that access this directly, but that feels like an unwanted level of indirection iniio_push_to_buffers_with_timestamp(). Perhaps worth doing anyway.scan_bytesis also used in this function.
active_scan_maskand masklength: Both used in valid ways inside drivers. Could be wrapped up in access functions, but it does seem a little convoluted.trig: This is used correctly in lots of drivers, so should stay in struct
iio_dev.Jonathan Cameron (9):
iio: core: move @id from structiio_devto structiio_dev_opaque
iio: avoid shadowing of variable name into_iio_dev_opaque()
iio: core: move @driver_module from structiio_devto struct
iio_dev_opaque
iio: core: move @trig_readonly from structiio_devto struct
iio_dev_opaque
iio: core: move @scan_index_timestamp to structiio_dev_opaque
iio: core: move @info_exist_lock to structiio_dev_opaque
iio: core: move @chrdev from structiio_devto structiio_dev_opaque
iio: core: move @flags from structiio_devto structiio_dev_opaque
iio: core: move @clock_id from structiio_devto structiio_dev_opaquedrivers/iio/accel/adxl372.c | 4 +- drivers/iio/accel/bma180.c | 2 +- drivers/iio/accel/bmc150-accel-core.c | 4 +- drivers/iio/accel/kxcjk-1013.c | 4 +- drivers/iio/accel/mma8452.c | 2 +- drivers/iio/accel/mxc4005.c | 2 +- drivers/iio/accel/stk8312.c | 2 +- drivers/iio/accel/stk8ba50.c | 2 +- drivers/iio/adc/ad7606.c | 3 +- drivers/iio/adc/ad7766.c | 3 +- drivers/iio/adc/ad7768-1.c | 3 +- drivers/iio/adc/ad_sigma_delta.c | 2 +- drivers/iio/adc/at91_adc.c | 4 +- drivers/iio/adc/dln2-adc.c | 3 +- drivers/iio/adc/ina2xx-adc.c | 3 +- drivers/iio/adc/ti-ads131e08.c | 2 +- drivers/iio/adc/xilinx-xadc-core.c | 2 +- .../buffer/industrialio-triggered-buffer.c | 2 +- drivers/iio/chemical/atlas-sensor.c | 2 +- drivers/iio/chemical/ccs811.c | 2 +- drivers/iio/chemical/scd30_core.c | 3 +- .../common/hid-sensors/hid-sensor-trigger.c | 2 +- drivers/iio/gyro/adxrs290.c | 2 +- drivers/iio/gyro/bmg160_core.c | 4 +- drivers/iio/gyro/fxas21002c_core.c | 2 +- drivers/iio/gyro/itg3200_buffer.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/health/afe4403.c | 2 +- drivers/iio/health/afe4404.c | 2 +- drivers/iio/imu/adis_trigger.c | 3 +- drivers/iio/imu/bmi160/bmi160_core.c | 3 +- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 2 +- drivers/iio/imu/kmx61.c | 2 +- drivers/iio/industrialio-buffer.c | 12 ++- drivers/iio/industrialio-core.c | 76 +++++++++++++------ drivers/iio/industrialio-trigger.c | 19 +++-- drivers/iio/industrialio-triggered-event.c | 2 +- drivers/iio/inkern.c | 46 ++++++----- drivers/iio/light/acpi-als.c | 3 +- drivers/iio/light/rpr0521.c | 2 +- drivers/iio/light/si1145.c | 2 +- drivers/iio/light/vcnl4000.c | 3 +- drivers/iio/light/vcnl4035.c | 2 +- drivers/iio/magnetometer/bmc150_magn.c | 2 +- drivers/iio/magnetometer/rm3100-core.c | 2 +- drivers/iio/potentiostat/lmp91000.c | 3 +- drivers/iio/pressure/zpa2326.c | 3 +- drivers/iio/proximity/as3935.c | 3 +- drivers/iio/proximity/sx9310.c | 2 +- drivers/iio/proximity/sx9500.c | 2 +- include/linux/iio/iio-opaque.h | 22 +++++- include/linux/iio/iio.h | 29 +------ 52 files changed, 188 insertions(+), 131 deletions(-)--
2.31.1
Jonathan Cameron
maintainerQuoted 7 lines · On Tue, 27 Apr 2021 11:08:52 +0300 Alexandru Ardelean <[email protected]>…
Quoted 6 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Intent here is to clear out the low hanging fruit so we can focus on the more interesting elements.
Quoted 6 lines
Quoted 3 lines
Hopefully this set are all uncontroversial. Lightly tested only but all fairly mechanical so hopefully I didn't mess up.
Series looks good.
Thanks for moving this forward :)
no problem.
One thing. You gave tags for all but it seems patch 3. Fine if I also put your tag on that one?
Quoted 90 lines
Alex
Quoted 87 lines
As for the others my current thinking is as follows
mlock: Still some instances to clear out of this being used to protect things it should not be used for. Long run we definitely want to move this one.
scan_timestamp: Can easily use a look up function in drivers that access this directly, but that feels like an unwanted level of indirection iniio_push_to_buffers_with_timestamp(). Perhaps worth doing anyway.scan_bytesis also used in this function.
active_scan_maskand masklength: Both used in valid ways inside drivers. Could be wrapped up in access functions, but it does seem a little convoluted.trig: This is used correctly in lots of drivers, so should stay in struct
iio_dev.Jonathan Cameron (9):
iio: core: move @id from structiio_devto structiio_dev_opaque
iio: avoid shadowing of variable name into_iio_dev_opaque()
iio: core: move @driver_module from structiio_devto struct
iio_dev_opaque
iio: core: move @trig_readonly from structiio_devto struct
iio_dev_opaque
iio: core: move @scan_index_timestamp to structiio_dev_opaque
iio: core: move @info_exist_lock to structiio_dev_opaque
iio: core: move @chrdev from structiio_devto structiio_dev_opaque
iio: core: move @flags from structiio_devto structiio_dev_opaque
iio: core: move @clock_id from structiio_devto structiio_dev_opaquedrivers/iio/accel/adxl372.c | 4 +- drivers/iio/accel/bma180.c | 2 +- drivers/iio/accel/bmc150-accel-core.c | 4 +- drivers/iio/accel/kxcjk-1013.c | 4 +- drivers/iio/accel/mma8452.c | 2 +- drivers/iio/accel/mxc4005.c | 2 +- drivers/iio/accel/stk8312.c | 2 +- drivers/iio/accel/stk8ba50.c | 2 +- drivers/iio/adc/ad7606.c | 3 +- drivers/iio/adc/ad7766.c | 3 +- drivers/iio/adc/ad7768-1.c | 3 +- drivers/iio/adc/ad_sigma_delta.c | 2 +- drivers/iio/adc/at91_adc.c | 4 +- drivers/iio/adc/dln2-adc.c | 3 +- drivers/iio/adc/ina2xx-adc.c | 3 +- drivers/iio/adc/ti-ads131e08.c | 2 +- drivers/iio/adc/xilinx-xadc-core.c | 2 +- .../buffer/industrialio-triggered-buffer.c | 2 +- drivers/iio/chemical/atlas-sensor.c | 2 +- drivers/iio/chemical/ccs811.c | 2 +- drivers/iio/chemical/scd30_core.c | 3 +- .../common/hid-sensors/hid-sensor-trigger.c | 2 +- drivers/iio/gyro/adxrs290.c | 2 +- drivers/iio/gyro/bmg160_core.c | 4 +- drivers/iio/gyro/fxas21002c_core.c | 2 +- drivers/iio/gyro/itg3200_buffer.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/health/afe4403.c | 2 +- drivers/iio/health/afe4404.c | 2 +- drivers/iio/imu/adis_trigger.c | 3 +- drivers/iio/imu/bmi160/bmi160_core.c | 3 +- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 2 +- drivers/iio/imu/kmx61.c | 2 +- drivers/iio/industrialio-buffer.c | 12 ++- drivers/iio/industrialio-core.c | 76 +++++++++++++------ drivers/iio/industrialio-trigger.c | 19 +++-- drivers/iio/industrialio-triggered-event.c | 2 +- drivers/iio/inkern.c | 46 ++++++----- drivers/iio/light/acpi-als.c | 3 +- drivers/iio/light/rpr0521.c | 2 +- drivers/iio/light/si1145.c | 2 +- drivers/iio/light/vcnl4000.c | 3 +- drivers/iio/light/vcnl4035.c | 2 +- drivers/iio/magnetometer/bmc150_magn.c | 2 +- drivers/iio/magnetometer/rm3100-core.c | 2 +- drivers/iio/potentiostat/lmp91000.c | 3 +- drivers/iio/pressure/zpa2326.c | 3 +- drivers/iio/proximity/as3935.c | 3 +- drivers/iio/proximity/sx9310.c | 2 +- drivers/iio/proximity/sx9500.c | 2 +- include/linux/iio/iio-opaque.h | 22 +++++- include/linux/iio/iio.h | 29 +------ 52 files changed, 188 insertions(+), 131 deletions(-)--
2.31.1
Jonathan Cameron
maintainerRe: [PATCH 1/9] iio: core: move @id from struct iio_dev to struct iio_dev_opaque
In reply to Alexandru ArdeleanQuoted 12 lines · On Tue, 27 Apr 2021 10:44:29 +0300 Alexandru Ardelean <[email protected]>…
Quoted 10 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
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.
Quoted 7 lines
The way I was thinking [initially] about moving this, is to somehow try to unify/generalize the {devm_}iio_trigger_alloc() function. It looks like the IIO device ID is needed only there. Maybe there is a good solution for this; maybe if we just provide the fmt string, and have a convention that the IIO device name and ID are filled in.
Though that's tricky.
With hindsight we should have standardized the IIO trigger naming suffix, but we can't do it now and I think we have cases with multiple elements in their format string so it would be non obvious.
Mostly it's the last element but not in at91-adc where it's in the middle of two other parameters.
Quoted 819 lines
But this
iio_device_id()getter is also a good approach for now.Reviewed-by Alexandru Ardelean <[email protected]>Quoted 814 lines
Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/accel/adxl372.c | 4 ++-- drivers/iio/accel/bma180.c | 2 +- drivers/iio/accel/bmc150-accel-core.c | 4 ++-- drivers/iio/accel/kxcjk-1013.c | 4 ++-- drivers/iio/accel/mma8452.c | 2 +- drivers/iio/accel/mxc4005.c | 2 +- drivers/iio/accel/stk8312.c | 2 +- drivers/iio/accel/stk8ba50.c | 2 +- drivers/iio/adc/ad7606.c | 3 ++- drivers/iio/adc/ad7766.c | 3 ++- drivers/iio/adc/ad7768-1.c | 3 ++- drivers/iio/adc/ad_sigma_delta.c | 2 +- drivers/iio/adc/at91_adc.c | 4 ++-- drivers/iio/adc/dln2-adc.c | 3 ++- drivers/iio/adc/ina2xx-adc.c | 3 ++- drivers/iio/adc/ti-ads131e08.c | 2 +- drivers/iio/adc/xilinx-xadc-core.c | 2 +- .../buffer/industrialio-triggered-buffer.c | 2 +- drivers/iio/chemical/atlas-sensor.c | 2 +- drivers/iio/chemical/ccs811.c | 2 +- drivers/iio/chemical/scd30_core.c | 3 ++- .../common/hid-sensors/hid-sensor-trigger.c | 2 +- drivers/iio/gyro/adxrs290.c | 2 +- drivers/iio/gyro/bmg160_core.c | 4 ++-- drivers/iio/gyro/fxas21002c_core.c | 2 +- drivers/iio/gyro/itg3200_buffer.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/health/afe4403.c | 2 +- drivers/iio/health/afe4404.c | 2 +- drivers/iio/imu/adis_trigger.c | 3 ++- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 2 +- drivers/iio/imu/kmx61.c | 2 +- drivers/iio/industrialio-core.c | 24 +++++++++++++++---- drivers/iio/industrialio-triggered-event.c | 2 +- drivers/iio/light/acpi-als.c | 3 ++- drivers/iio/light/rpr0521.c | 2 +- drivers/iio/light/si1145.c | 2 +- drivers/iio/light/vcnl4000.c | 3 ++- drivers/iio/light/vcnl4035.c | 2 +- drivers/iio/magnetometer/bmc150_magn.c | 2 +- drivers/iio/magnetometer/rm3100-core.c | 2 +- drivers/iio/potentiostat/lmp91000.c | 3 ++- drivers/iio/pressure/zpa2326.c | 3 ++- drivers/iio/proximity/as3935.c | 3 ++- drivers/iio/proximity/sx9310.c | 2 +- drivers/iio/proximity/sx9500.c | 2 +- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 4 ++-- 49 files changed, 87 insertions(+), 58 deletions(-)drivers/iio/accel/adxl372.c +2
-2@@ -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 ;drivers/iio/accel/bma180.c +1
-1@@ -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;drivers/iio/accel/bmc150-accel-core.c +2
-2@@ -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 ;drivers/iio/accel/kxcjk-1013.c +2
-2@@ -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;drivers/iio/accel/mma8452.c +1
-1@@ -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 ;drivers/iio/accel/mxc4005.c +1
-1@@ -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 ;drivers/iio/accel/stk8312.c +1
-1@@ -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;drivers/iio/accel/stk8ba50.c +1
-1@@ -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;drivers/iio/adc/ad7606.c +2
-1@@ -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 ;drivers/iio/adc/ad7766.c +2
-1@@ -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 ;drivers/iio/adc/ad7768-1.c +2
-1@@ -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 ;drivers/iio/adc/ad_sigma_delta.c +1
-1@@ -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;drivers/iio/adc/at91_adc.c +2
-2@@ -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 ;drivers/iio/adc/dln2-adc.c +2
-1@@ -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 ;drivers/iio/adc/ina2xx-adc.c +2
-1@@ -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);drivers/iio/adc/ti-ads131e08.c +1
-1@@ -844,7 +844,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 ;drivers/iio/adc/xilinx-xadc-core.c +1
-1@@ -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 );drivers/iio/buffer/industrialio-triggered-buffer.c +1
-1@@ -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;drivers/iio/chemical/atlas-sensor.c +1
-1@@ -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 ;drivers/iio/chemical/ccs811.c +1
-1@@ -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;drivers/iio/chemical/scd30_core.c +2
-1@@ -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 ;drivers/iio/common/hid-sensors/hid-sensor-trigger.c +1
-1@@ -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 ;drivers/iio/gyro/adxrs290.c +1
-1@@ -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 ;drivers/iio/gyro/bmg160_core.c +2
-2@@ -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 ;drivers/iio/gyro/fxas21002c_core.c +1
-1@@ -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 ;drivers/iio/gyro/itg3200_buffer.c +1
-1@@ -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 ;drivers/iio/gyro/mpu3050-core.c +1
-1@@ -1049,7 +1049,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 ;drivers/iio/health/afe4403.c +1
-1@@ -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 ;drivers/iio/health/afe4404.c +1
-1@@ -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 ;drivers/iio/imu/adis_trigger.c +2
-1@@ -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 ;drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -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 ;drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +1
-1@@ -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 ;drivers/iio/imu/kmx61.c +1
-1@@ -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 );drivers/iio/industrialio-core.c +19
-5@@ -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);@@ -1892,7 +1906,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; }drivers/iio/industrialio-triggered-event.c +1
-1@@ -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 ;drivers/iio/light/acpi-als.c +2
-1@@ -206,7 +206,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 ;drivers/iio/light/rpr0521.c +1
-1@@ -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;drivers/iio/light/si1145.c +1
-1@@ -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 ;drivers/iio/light/vcnl4000.c +2
-1@@ -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 ;drivers/iio/light/vcnl4035.c +1
-1@@ -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 ;drivers/iio/magnetometer/bmc150_magn.c +1
-1@@ -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" );drivers/iio/magnetometer/rm3100-core.c +1
-1@@ -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 ;drivers/iio/potentiostat/lmp91000.c +2
-1@@ -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 ;drivers/iio/pressure/zpa2326.c +2
-1@@ -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 ;drivers/iio/proximity/as3935.c +2
-1@@ -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 ;drivers/iio/proximity/sx9310.c +1
-1@@ -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 ;drivers/iio/proximity/sx9500.c +1
-1@@ -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 ;include/linux/iio/iio-opaque.h +2
-0@@ -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;include/linux/iio/iio.h +2
-3@@ -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);/** -- 2.31.1
Jonathan Cameron
maintainerRe: [PATCH 7/9] iio: core: move @chrdev from struct iio_dev to struct iio_dev_opaque
In reply to Alexandru ArdeleanQuoted 9 lines · On Tue, 27 Apr 2021 11:06:56 +0300 Alexandru Ardelean <[email protected]>…
Quoted 5 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
No reason for this to be exposed to the drivers, so lets move it to the opaque structure.
Even though this looks straightforward, I am paranoid about it. Mostly because of all the chardev juggling that I tried.
Yup. Several of these needed to wait for that work to be in place so could really be done until now (when things are generally somewhat cleaner than they were!)
Jonathan
Quoted 115 lines
Reviewed-by Alexandru Ardelean <[email protected]>Quoted 112 lines
Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/industrialio-core.c | 20 +++++++++++--------- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 2 -- 3 files changed, 13 insertions(+), 11 deletions(-)drivers/iio/industrialio-core.c +11
-9@@ -1715,8 +1715,9 @@ EXPORT_SYMBOL_GPL(devm_iio_device_alloc);**/ static int iio_chrdev_open (struct inode *inode,struct file *filp) { -struct iio_dev *indio_dev =container_of (inode->i_cdev, - struct iio_dev, chrdev); +struct iio_dev_opaque *iio_dev_opaque = + container_of(inode->i_cdev, struct iio_dev_opaque, chrdev); +struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;struct iio_dev_buffer_pair *ib;if (test_and_set_bit (IIO_BUSY_BIT_POS , &indio_dev->flags))@@ -1749,8 +1750,9 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)static int iio_chrdev_release (struct inode *inode,struct file *filp) {struct iio_dev_buffer_pair *ib = filp->private_data; -struct iio_dev *indio_dev =container_of (inode->i_cdev, - struct iio_dev, chrdev); +struct iio_dev_opaque *iio_dev_opaque = + container_of(inode->i_cdev, struct iio_dev_opaque, chrdev); +struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;kfree (ib);clear_bit (IIO_BUSY_BIT_POS , &indio_dev->flags);iio_device_put (indio_dev);@@ -1901,19 +1903,19 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) indio_dev->setup_ops = &noop_ring_setup_ops;if (iio_dev_opaque->attached_buffers_cnt) -cdev_init (&indio_dev->chrdev, &iio_buffer_fileops); +cdev_init (&iio_dev_opaque->chrdev, &iio_buffer_fileops);else if (iio_dev_opaque->event_interface) -cdev_init (&indio_dev->chrdev, &iio_event_fileops); +cdev_init (&iio_dev_opaque->chrdev, &iio_event_fileops);if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) { indio_dev->dev.devt =MKDEV (MAJOR (iio_devt), iio_dev_opaque->id); - indio_dev->chrdev.owner = this_mod; + iio_dev_opaque->chrdev.owner = this_mod; }/* assign device groups now; they should be all registered now */ indio_dev->dev.groups = iio_dev_opaque->groups; - ret =cdev_device_add (&indio_dev->chrdev, &indio_dev->dev); + ret =cdev_device_add (&iio_dev_opaque->chrdev, &indio_dev->dev);if (ret <0 ) goto error_unreg_eventset;@@ -1940,7 +1942,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev);struct iio_ioctl_handler *h, *t; -cdev_device_del (&indio_dev->chrdev, &indio_dev->dev); +cdev_device_del (&iio_dev_opaque->chrdev, &indio_dev->dev);mutex_lock (&iio_dev_opaque->info_exist_lock);include/linux/iio/iio-opaque.h +2
-0@@ -24,6 +24,7 @@* @legacy_scan_el_group: attribute group for legacy scan elements attribute group * @legacy_buffer_group: attribute group for legacy buffer attributes group * @scan_index_timestamp: cache of the index to the timestamp +* @chrdev: associated character device * @debugfs_dentry: device specific debugfs dentry * @cached_reg_addr: cached register address for debugfs reads * @read_buf: read buffer to be used for the initial reg read @@ -49,6 +50,7 @@ struct iio_dev_opaque {struct attribute_group legacy_buffer_group;unsigned int scan_index_timestamp; +struct cdev chrdev;#if defined(CONFIG_DEBUG_FS )struct dentry *debugfs_dentry;include/linux/iio/iio.h +0
-3@@ -512,7 +512,6 @@ struct iio_buffer_setup_ops {* @clock_id: [INTERN] timestamping clock posix identifier * @setup_ops: [DRIVER] callbacks to call before and after buffer * enable/disable -* @chrdev: [INTERN] associated character device * @flags: [INTERN] file ops related flags including busy flag. * @priv: [DRIVER] reference to driver's private information * **MUST** be accessed **ONLY** via iio_priv() helper @@ -542,7 +541,6 @@ struct iio_dev {const struct iio_info *info;clockid_t clock_id;const struct iio_buffer_setup_ops *setup_ops; -struct cdev chrdev;unsigned long flags;void *priv; --2.31.1
Jonathan Cameron
maintainerRe: [PATCH 9/9] iio: core: move @clock_id from struct iio_dev to struct iio_dev_opaque
In reply to Alexandru ArdeleanQuoted 7 lines · On Tue, 27 Apr 2021 11:02:02 +0300 Alexandru Ardelean <[email protected]>…
Quoted 5 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
There is already an acessor function used to access it, making this move straight forward.
Quoted 6 lines
Right now the
iio_device_get_clock()helper is only being used in the Chrome EC core sensor driver.
Maybe later if that can be reworked without this helper, then it could be made private to IIO core.
Though, chances are some other driver may come along later and ask for it to be public again.
Agreed. My gut feeling is this will come up again (largely because some idiot who will remain nameless picked a silly default clock many years ago when he didn't know better).
Jonathan
Quoted 104 lines
Anyway.
Reviewed-by Alexandru Ardelean <[email protected]>Quoted 99 lines
Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/industrialio-core.c | 14 +++++++++++++- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 12 +----------- 3 files changed, 16 insertions(+), 12 deletions(-)drivers/iio/industrialio-core.c +13
-1@@ -271,13 +271,25 @@ int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)mutex_unlock (&indio_dev->mlock);return -EBUSY ; } - indio_dev->clock_id = clock_id; + iio_dev_opaque->clock_id = clock_id;mutex_unlock (&indio_dev->mlock);return 0 ; }EXPORT_SYMBOL (iio_device_set_clock); +/** +* iio_device_get_clock() - Retrieve current timestamping clock for the device +* @indio_dev: IIO device structure containing the device +*/ +clockid_t iio_device_get_clock (const struct iio_dev *indio_dev) +{ +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev); + +return iio_dev_opaque->clock_id; +} +EXPORT_SYMBOL (iio_device_get_clock); +/** * iio_get_time_ns() - utility function to get a time stamp for events etc * @indio_dev: device include/linux/iio/iio-opaque.h +2
-0@@ -24,6 +24,7 @@* @legacy_scan_el_group: attribute group for legacy scan elements attribute group * @legacy_buffer_group: attribute group for legacy buffer attributes group * @scan_index_timestamp: cache of the index to the timestamp +* @clock_id: timestamping clock posix identifier * @chrdev: associated character device * @flags: file ops related flags including busy flag. * @debugfs_dentry: device specific debugfs dentry @@ -51,6 +52,7 @@ struct iio_dev_opaque {struct attribute_group legacy_buffer_group;unsigned int scan_index_timestamp; +clockid_t clock_id;struct cdev chrdev;unsigned long flags;include/linux/iio/iio.h +1
-12@@ -509,7 +509,6 @@ struct iio_buffer_setup_ops {* @name: [DRIVER] name of the device. * @label: [DRIVER] unique name to identify which device this is * @info: [DRIVER] callbacks and constant info from driver -* @clock_id: [INTERN] timestamping clock posix identifier * @setup_ops: [DRIVER] callbacks to call before and after buffer * enable/disable * @priv: [DRIVER] reference to driver's private information @@ -538,7 +537,6 @@ struct iio_dev {const char *name;const char *label;const struct iio_info *info; -clockid_t clock_id;const struct iio_buffer_setup_ops *setup_ops;void *priv;@@ -589,15 +587,7 @@ static inline void iio_device_put(struct iio_dev *indio_dev)put_device (&indio_dev->dev); } -/** -* iio_device_get_clock() - Retrieve current timestamping clock for the device -* @indio_dev: IIO device structure containing the device -*/ -static inline clockid_t iio_device_get_clock (const struct iio_dev *indio_dev) -{ -return indio_dev->clock_id; -} - +clockid_t iio_device_get_clock (const struct iio_dev *indio_dev);int iio_device_set_clock (struct iio_dev *indio_dev,clockid_t clock_id);/** -- 2.31.1
Quoted 15 lines · Jonathan Cameron
Quoted 11 lines · On Tue, 27 Apr 2021 11:08:52 +0300 Alexandru Ardelean <[email protected]>…
Quoted 9 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Intent here is to clear out the low hanging fruit so we can focus on the more interesting elements.
Hopefully this set are all uncontroversial. Lightly tested only but all fairly mechanical so hopefully I didn't mess up.
Quoted 6 lines
Quoted 2 lines
Series looks good.
Thanks for moving this forward :)no problem.
One thing. You gave tags for all but it seems patch 3. Fine if I also put your tag on that one?
Yes.
I may have missed it.
I usually have reviews in the morning before starting some other work and drinking my coffee.
Quoted 92 lines
Quoted 91 lines
Alex
Quoted 87 lines
As for the others my current thinking is as follows
mlock: Still some instances to clear out of this being used to protect things it should not be used for. Long run we definitely want to move this one.
scan_timestamp: Can easily use a look up function in drivers that access this directly, but that feels like an unwanted level of indirection iniio_push_to_buffers_with_timestamp(). Perhaps worth doing anyway.scan_bytesis also used in this function.
active_scan_maskand masklength: Both used in valid ways inside drivers. Could be wrapped up in access functions, but it does seem a little convoluted.trig: This is used correctly in lots of drivers, so should stay in struct
iio_dev.Jonathan Cameron (9):
iio: core: move @id from structiio_devto structiio_dev_opaque
iio: avoid shadowing of variable name into_iio_dev_opaque()
iio: core: move @driver_module from structiio_devto struct
iio_dev_opaque
iio: core: move @trig_readonly from structiio_devto struct
iio_dev_opaque
iio: core: move @scan_index_timestamp to structiio_dev_opaque
iio: core: move @info_exist_lock to structiio_dev_opaque
iio: core: move @chrdev from structiio_devto structiio_dev_opaque
iio: core: move @flags from structiio_devto structiio_dev_opaque
iio: core: move @clock_id from structiio_devto structiio_dev_opaquedrivers/iio/accel/adxl372.c | 4 +- drivers/iio/accel/bma180.c | 2 +- drivers/iio/accel/bmc150-accel-core.c | 4 +- drivers/iio/accel/kxcjk-1013.c | 4 +- drivers/iio/accel/mma8452.c | 2 +- drivers/iio/accel/mxc4005.c | 2 +- drivers/iio/accel/stk8312.c | 2 +- drivers/iio/accel/stk8ba50.c | 2 +- drivers/iio/adc/ad7606.c | 3 +- drivers/iio/adc/ad7766.c | 3 +- drivers/iio/adc/ad7768-1.c | 3 +- drivers/iio/adc/ad_sigma_delta.c | 2 +- drivers/iio/adc/at91_adc.c | 4 +- drivers/iio/adc/dln2-adc.c | 3 +- drivers/iio/adc/ina2xx-adc.c | 3 +- drivers/iio/adc/ti-ads131e08.c | 2 +- drivers/iio/adc/xilinx-xadc-core.c | 2 +- .../buffer/industrialio-triggered-buffer.c | 2 +- drivers/iio/chemical/atlas-sensor.c | 2 +- drivers/iio/chemical/ccs811.c | 2 +- drivers/iio/chemical/scd30_core.c | 3 +- .../common/hid-sensors/hid-sensor-trigger.c | 2 +- drivers/iio/gyro/adxrs290.c | 2 +- drivers/iio/gyro/bmg160_core.c | 4 +- drivers/iio/gyro/fxas21002c_core.c | 2 +- drivers/iio/gyro/itg3200_buffer.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/health/afe4403.c | 2 +- drivers/iio/health/afe4404.c | 2 +- drivers/iio/imu/adis_trigger.c | 3 +- drivers/iio/imu/bmi160/bmi160_core.c | 3 +- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 2 +- drivers/iio/imu/kmx61.c | 2 +- drivers/iio/industrialio-buffer.c | 12 ++- drivers/iio/industrialio-core.c | 76 +++++++++++++------ drivers/iio/industrialio-trigger.c | 19 +++-- drivers/iio/industrialio-triggered-event.c | 2 +- drivers/iio/inkern.c | 46 ++++++----- drivers/iio/light/acpi-als.c | 3 +- drivers/iio/light/rpr0521.c | 2 +- drivers/iio/light/si1145.c | 2 +- drivers/iio/light/vcnl4000.c | 3 +- drivers/iio/light/vcnl4035.c | 2 +- drivers/iio/magnetometer/bmc150_magn.c | 2 +- drivers/iio/magnetometer/rm3100-core.c | 2 +- drivers/iio/potentiostat/lmp91000.c | 3 +- drivers/iio/pressure/zpa2326.c | 3 +- drivers/iio/proximity/as3935.c | 3 +- drivers/iio/proximity/sx9310.c | 2 +- drivers/iio/proximity/sx9500.c | 2 +- include/linux/iio/iio-opaque.h | 22 +++++- include/linux/iio/iio.h | 29 +------ 52 files changed, 188 insertions(+), 131 deletions(-)--
2.31.1
Re: [PATCH 3/9] iio: core: move @driver_module from struct iio_dev to struct iio_dev_opaque
In reply to Jonathan CameronQuoted 7 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Continuing move to hide internal elements from drivers, move this structure element over. It's only accessed from iio core files so this one was straight forward and no accessor functions are needed.
Quoted 117 lines
Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/industrialio-core.c | 2 +- drivers/iio/industrialio-trigger.c | 9 ++++++--- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 3 --- 4 files changed, 9 insertions(+), 7 deletions(-)drivers/iio/industrialio-core.c +1
-1@@ -1859,7 +1859,7 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)if (!indio_dev->info)return -EINVAL ; - indio_dev->driver_module = this_mod; + iio_dev_opaque->driver_module = this_mod;/* If the calling driver did not initialize of_node, do it here */ if (!indio_dev->dev.of_node && indio_dev->dev.parent) indio_dev->dev.of_node = indio_dev->dev.parent->of_node;drivers/iio/industrialio-trigger.c +6
-3@@ -13,6 +13,7 @@#include <linux/slab.h> #include <linux/iio/iio.h> +#include <linux/iio/iio-opaque.h> #include <linux/iio/trigger.h> #include "iio_core.h" #include "iio_core_trigger.h" @@ -240,12 +241,13 @@ static void iio_trigger_put_irq(struct iio_trigger *trig, int irq)int iio_trigger_attach_poll_func (struct iio_trigger *trig,struct iio_poll_func *pf) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (pf->indio_dev);bool notinuse =bitmap_empty (trig->pool,CONFIG_IIO_CONSUMERS_PER_TRIGGER );int ret =0 ;/* Prevent the module from being removed whilst attached to a trigger */ -__module_get (pf->indio_dev->driver_module); +__module_get (iio_dev_opaque->driver_module);/* Get irq number */ pf->irq =iio_trigger_get_irq (trig);@@ -284,13 +286,14 @@ int iio_trigger_attach_poll_func(struct iio_trigger *trig, out_put_irq:iio_trigger_put_irq (trig, pf->irq); out_put_module: -module_put (pf->indio_dev->driver_module); +module_put (iio_dev_opaque->driver_module);return ret; }int iio_trigger_detach_poll_func (struct iio_trigger *trig,struct iio_poll_func *pf) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (pf->indio_dev);bool no_other_users =bitmap_weight (trig->pool,CONFIG_IIO_CONSUMERS_PER_TRIGGER ) ==1 ;int ret =0 ;@@ -304,7 +307,7 @@ int iio_trigger_detach_poll_func(struct iio_trigger *trig, trig->attached_own_device = false;iio_trigger_put_irq (trig, pf->irq);free_irq (pf->irq, pf); -module_put (pf->indio_dev->driver_module); +module_put (iio_dev_opaque->driver_module);return ret; }include/linux/iio/iio-opaque.h +2
-0@@ -7,6 +7,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 +* @driver_module: used to make it harder to undercut users * @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 @@ -28,6 +29,7 @@struct iio_dev_opaque {struct iio_dev indio_dev;int id; +struct module *driver_module;struct iio_event_interface *event_interface;struct iio_buffer **attached_buffers;unsigned int attached_buffers_cnt;include/linux/iio/iio.h +0
-4@@ -488,7 +488,6 @@ struct iio_buffer_setup_ops {/** * struct iio_dev - industrial I/O device -* @driver_module: [INTERN] used to make it harder to undercut users * @modes: [DRIVER] operating modes supported by device * @currentmode: [DRIVER] current operating mode * @dev: [DRIVER] device structure, should be assigned a parent @@ -522,8 +521,6 @@ struct iio_buffer_setup_ops {* **MUST** be accessed **ONLY** via iio_priv() helper */ struct iio_dev { -struct module *driver_module; -int modes;int currentmode;struct device dev; --2.31.1
Jonathan Cameron
maintainerRe: [PATCH 1/9] iio: core: move @id from struct iio_dev to struct iio_dev_opaque
In reply to Jonathan CameronQuoted 10 lines · On Mon, 26 Apr 2021 18:49:03 +0100 Jonathan Cameron <[email protected]> wrote:
From: Jonathan Cameron <[email protected]>
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.Signed-off-by Jonathan Cameron <[email protected]>
This somehow missed at91-sama5d2_adc.c
I've added that one and applied this to the togreg branch of iio.git. Pushed out as testing as I definitely want this series to get some significant build exposure.
Thanks,
Jonathan
Quoted 810 lines
--- drivers/iio/accel/adxl372.c | 4 ++-- drivers/iio/accel/bma180.c | 2 +- drivers/iio/accel/bmc150-accel-core.c | 4 ++-- drivers/iio/accel/kxcjk-1013.c | 4 ++-- drivers/iio/accel/mma8452.c | 2 +- drivers/iio/accel/mxc4005.c | 2 +- drivers/iio/accel/stk8312.c | 2 +- drivers/iio/accel/stk8ba50.c | 2 +- drivers/iio/adc/ad7606.c | 3 ++- drivers/iio/adc/ad7766.c | 3 ++- drivers/iio/adc/ad7768-1.c | 3 ++- drivers/iio/adc/ad_sigma_delta.c | 2 +- drivers/iio/adc/at91_adc.c | 4 ++-- drivers/iio/adc/dln2-adc.c | 3 ++- drivers/iio/adc/ina2xx-adc.c | 3 ++- drivers/iio/adc/ti-ads131e08.c | 2 +- drivers/iio/adc/xilinx-xadc-core.c | 2 +- .../buffer/industrialio-triggered-buffer.c | 2 +- drivers/iio/chemical/atlas-sensor.c | 2 +- drivers/iio/chemical/ccs811.c | 2 +- drivers/iio/chemical/scd30_core.c | 3 ++- .../common/hid-sensors/hid-sensor-trigger.c | 2 +- drivers/iio/gyro/adxrs290.c | 2 +- drivers/iio/gyro/bmg160_core.c | 4 ++-- drivers/iio/gyro/fxas21002c_core.c | 2 +- drivers/iio/gyro/itg3200_buffer.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/health/afe4403.c | 2 +- drivers/iio/health/afe4404.c | 2 +- drivers/iio/imu/adis_trigger.c | 3 ++- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 2 +- drivers/iio/imu/kmx61.c | 2 +- drivers/iio/industrialio-core.c | 24 +++++++++++++++---- drivers/iio/industrialio-triggered-event.c | 2 +- drivers/iio/light/acpi-als.c | 3 ++- drivers/iio/light/rpr0521.c | 2 +- drivers/iio/light/si1145.c | 2 +- drivers/iio/light/vcnl4000.c | 3 ++- drivers/iio/light/vcnl4035.c | 2 +- drivers/iio/magnetometer/bmc150_magn.c | 2 +- drivers/iio/magnetometer/rm3100-core.c | 2 +- drivers/iio/potentiostat/lmp91000.c | 3 ++- drivers/iio/pressure/zpa2326.c | 3 ++- drivers/iio/proximity/as3935.c | 3 ++- drivers/iio/proximity/sx9310.c | 2 +- drivers/iio/proximity/sx9500.c | 2 +- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 4 ++-- 49 files changed, 87 insertions(+), 58 deletions(-)drivers/iio/accel/adxl372.c +2
-2@@ -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 ;drivers/iio/accel/bma180.c +1
-1@@ -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;drivers/iio/accel/bmc150-accel-core.c +2
-2@@ -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 ;drivers/iio/accel/kxcjk-1013.c +2
-2@@ -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;drivers/iio/accel/mma8452.c +1
-1@@ -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 ;drivers/iio/accel/mxc4005.c +1
-1@@ -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 ;drivers/iio/accel/stk8312.c +1
-1@@ -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;drivers/iio/accel/stk8ba50.c +1
-1@@ -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;drivers/iio/adc/ad7606.c +2
-1@@ -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 ;drivers/iio/adc/ad7766.c +2
-1@@ -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 ;drivers/iio/adc/ad7768-1.c +2
-1@@ -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 ;drivers/iio/adc/ad_sigma_delta.c +1
-1@@ -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;drivers/iio/adc/at91_adc.c +2
-2@@ -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 ;drivers/iio/adc/dln2-adc.c +2
-1@@ -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 ;drivers/iio/adc/ina2xx-adc.c +2
-1@@ -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);drivers/iio/adc/ti-ads131e08.c +1
-1@@ -844,7 +844,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 ;drivers/iio/adc/xilinx-xadc-core.c +1
-1@@ -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 );drivers/iio/buffer/industrialio-triggered-buffer.c +1
-1@@ -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;drivers/iio/chemical/atlas-sensor.c +1
-1@@ -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 ;drivers/iio/chemical/ccs811.c +1
-1@@ -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;drivers/iio/chemical/scd30_core.c +2
-1@@ -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 ;drivers/iio/common/hid-sensors/hid-sensor-trigger.c +1
-1@@ -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 ;drivers/iio/gyro/adxrs290.c +1
-1@@ -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 ;drivers/iio/gyro/bmg160_core.c +2
-2@@ -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 ;drivers/iio/gyro/fxas21002c_core.c +1
-1@@ -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 ;drivers/iio/gyro/itg3200_buffer.c +1
-1@@ -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 ;drivers/iio/gyro/mpu3050-core.c +1
-1@@ -1049,7 +1049,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 ;drivers/iio/health/afe4403.c +1
-1@@ -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 ;drivers/iio/health/afe4404.c +1
-1@@ -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 ;drivers/iio/imu/adis_trigger.c +2
-1@@ -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 ;drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -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 ;drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +1
-1@@ -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 ;drivers/iio/imu/kmx61.c +1
-1@@ -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 );drivers/iio/industrialio-core.c +19
-5@@ -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);@@ -1892,7 +1906,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; }drivers/iio/industrialio-triggered-event.c +1
-1@@ -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 ;drivers/iio/light/acpi-als.c +2
-1@@ -206,7 +206,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 ;drivers/iio/light/rpr0521.c +1
-1@@ -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;drivers/iio/light/si1145.c +1
-1@@ -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 ;drivers/iio/light/vcnl4000.c +2
-1@@ -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 ;drivers/iio/light/vcnl4035.c +1
-1@@ -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 ;drivers/iio/magnetometer/bmc150_magn.c +1
-1@@ -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" );drivers/iio/magnetometer/rm3100-core.c +1
-1@@ -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 ;drivers/iio/potentiostat/lmp91000.c +2
-1@@ -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 ;drivers/iio/pressure/zpa2326.c +2
-1@@ -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 ;drivers/iio/proximity/as3935.c +2
-1@@ -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 ;drivers/iio/proximity/sx9310.c +1
-1@@ -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 ;drivers/iio/proximity/sx9500.c +1
-1@@ -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 ;include/linux/iio/iio-opaque.h +2
-0@@ -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;include/linux/iio/iio.h +2
-2@@ -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);/**
Jonathan Cameron
maintainerQuoted 20 lines · On Wed, 28 Apr 2021 09:55:19 +0300 Alexandru Ardelean <[email protected]>…
Quoted 19 lines · Jonathan Cameron
Quoted 7 lines · On Tue, 27 Apr 2021 11:08:52 +0300 Alexandru Ardelean <[email protected]>…
Quoted 6 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Intent here is to clear out the low hanging fruit so we can focus on the more interesting elements.
Quoted 6 lines
Quoted 3 lines
Hopefully this set are all uncontroversial. Lightly tested only but all fairly mechanical so hopefully I didn't mess up.
Series looks good.
Thanks for moving this forward :)no problem.
Quoted 7 lines
Quoted 2 lines
One thing. You gave tags for all but it seems patch 3. Fine if I also put your tag on that one?
Yes.
I may have missed it.
I usually have reviews in the morning before starting some other work and drinking my coffee.
Thanks,
Applied to the togreg branch of iio.git and pushed out as testing to see if I missed any more cases...
Now we just have the 'small' issue of figuring out what to do about the remaining elements!
Thanks,
Jonathan
Quoted 93 lines
Quoted 93 lines
Quoted 92 lines
Alex
Quoted 87 lines
As for the others my current thinking is as follows
mlock: Still some instances to clear out of this being used to protect things it should not be used for. Long run we definitely want to move this one.
scan_timestamp: Can easily use a look up function in drivers that access this directly, but that feels like an unwanted level of indirection iniio_push_to_buffers_with_timestamp(). Perhaps worth doing anyway.scan_bytesis also used in this function.
active_scan_maskand masklength: Both used in valid ways inside drivers. Could be wrapped up in access functions, but it does seem a little convoluted.trig: This is used correctly in lots of drivers, so should stay in struct
iio_dev.Jonathan Cameron (9):
iio: core: move @id from structiio_devto structiio_dev_opaque
iio: avoid shadowing of variable name into_iio_dev_opaque()
iio: core: move @driver_module from structiio_devto struct
iio_dev_opaque
iio: core: move @trig_readonly from structiio_devto struct
iio_dev_opaque
iio: core: move @scan_index_timestamp to structiio_dev_opaque
iio: core: move @info_exist_lock to structiio_dev_opaque
iio: core: move @chrdev from structiio_devto structiio_dev_opaque
iio: core: move @flags from structiio_devto structiio_dev_opaque
iio: core: move @clock_id from structiio_devto structiio_dev_opaquedrivers/iio/accel/adxl372.c | 4 +- drivers/iio/accel/bma180.c | 2 +- drivers/iio/accel/bmc150-accel-core.c | 4 +- drivers/iio/accel/kxcjk-1013.c | 4 +- drivers/iio/accel/mma8452.c | 2 +- drivers/iio/accel/mxc4005.c | 2 +- drivers/iio/accel/stk8312.c | 2 +- drivers/iio/accel/stk8ba50.c | 2 +- drivers/iio/adc/ad7606.c | 3 +- drivers/iio/adc/ad7766.c | 3 +- drivers/iio/adc/ad7768-1.c | 3 +- drivers/iio/adc/ad_sigma_delta.c | 2 +- drivers/iio/adc/at91_adc.c | 4 +- drivers/iio/adc/dln2-adc.c | 3 +- drivers/iio/adc/ina2xx-adc.c | 3 +- drivers/iio/adc/ti-ads131e08.c | 2 +- drivers/iio/adc/xilinx-xadc-core.c | 2 +- .../buffer/industrialio-triggered-buffer.c | 2 +- drivers/iio/chemical/atlas-sensor.c | 2 +- drivers/iio/chemical/ccs811.c | 2 +- drivers/iio/chemical/scd30_core.c | 3 +- .../common/hid-sensors/hid-sensor-trigger.c | 2 +- drivers/iio/gyro/adxrs290.c | 2 +- drivers/iio/gyro/bmg160_core.c | 4 +- drivers/iio/gyro/fxas21002c_core.c | 2 +- drivers/iio/gyro/itg3200_buffer.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/health/afe4403.c | 2 +- drivers/iio/health/afe4404.c | 2 +- drivers/iio/imu/adis_trigger.c | 3 +- drivers/iio/imu/bmi160/bmi160_core.c | 3 +- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 2 +- drivers/iio/imu/kmx61.c | 2 +- drivers/iio/industrialio-buffer.c | 12 ++- drivers/iio/industrialio-core.c | 76 +++++++++++++------ drivers/iio/industrialio-trigger.c | 19 +++-- drivers/iio/industrialio-triggered-event.c | 2 +- drivers/iio/inkern.c | 46 ++++++----- drivers/iio/light/acpi-als.c | 3 +- drivers/iio/light/rpr0521.c | 2 +- drivers/iio/light/si1145.c | 2 +- drivers/iio/light/vcnl4000.c | 3 +- drivers/iio/light/vcnl4035.c | 2 +- drivers/iio/magnetometer/bmc150_magn.c | 2 +- drivers/iio/magnetometer/rm3100-core.c | 2 +- drivers/iio/potentiostat/lmp91000.c | 3 +- drivers/iio/pressure/zpa2326.c | 3 +- drivers/iio/proximity/as3935.c | 3 +- drivers/iio/proximity/sx9310.c | 2 +- drivers/iio/proximity/sx9500.c | 2 +- include/linux/iio/iio-opaque.h | 22 +++++- include/linux/iio/iio.h | 29 +------ 52 files changed, 188 insertions(+), 131 deletions(-)--
2.31.1