From 1e9663c62b32f695af37fec4afc473b59f5ca9b4 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 25 Mar 2013 08:58:00 +0000 Subject: [PATCH 01/12] iio:trigger: Introduce iio_tigger_{set,get}_drvdata Introduce iio_tigger_{set,get}_drvdata which allows to attach driver specific data to a trigger. The functions wrap access to the triggers private_data field and all current users are updated to use iio_tigger_{set,get}_drvdata instead of directly accessing the private_data field. This is the first step towards removing the private_data field from the iio_trigger struct. The following coccinelle script has been used to update the drivers: @@ struct iio_trigger *trigger; expression priv; @@ -trigger->private_data = priv +iio_trigger_set_drv_data(trigger, priv) @@ struct iio_trigger *trigger; @@ -trigger->private_data +iio_trigger_get_drv_data(trigger) Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron --- drivers/iio/accel/st_accel_buffer.c | 2 +- drivers/iio/adc/ad_sigma_delta.c | 2 +- drivers/iio/adc/at91_adc.c | 4 ++-- .../common/hid-sensors/hid-sensor-trigger.c | 4 ++-- .../common/st_sensors/st_sensors_trigger.c | 2 +- drivers/iio/gyro/itg3200_buffer.c | 4 ++-- drivers/iio/gyro/st_gyro_buffer.c | 2 +- drivers/iio/imu/adis_trigger.c | 4 ++-- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 4 ++-- drivers/staging/iio/accel/lis3l02dq_ring.c | 6 ++--- drivers/staging/iio/adc/mxs-lradc.c | 4 ++-- drivers/staging/iio/meter/ade7758_trigger.c | 6 ++--- .../staging/iio/trigger/iio-trig-bfin-timer.c | 8 +++---- drivers/staging/iio/trigger/iio-trig-gpio.c | 6 ++--- .../iio/trigger/iio-trig-periodic-rtc.c | 12 +++++----- drivers/staging/iio/trigger/iio-trig-sysfs.c | 4 ++-- include/linux/iio/trigger.h | 24 +++++++++++++++++++ 17 files changed, 61 insertions(+), 37 deletions(-) diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c index 6bd82c7f769c..d9b350756f90 100644 --- a/drivers/iio/accel/st_accel_buffer.c +++ b/drivers/iio/accel/st_accel_buffer.c @@ -25,7 +25,7 @@ int st_accel_trig_set_state(struct iio_trigger *trig, bool state) { - struct iio_dev *indio_dev = trig->private_data; + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); return st_sensors_set_dataready_irq(indio_dev, state); } diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c index afe6d78c8ff0..f0d6335ae087 100644 --- a/drivers/iio/adc/ad_sigma_delta.c +++ b/drivers/iio/adc/ad_sigma_delta.c @@ -470,7 +470,7 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev) disable_irq_nosync(sigma_delta->spi->irq); } sigma_delta->trig->dev.parent = &sigma_delta->spi->dev; - sigma_delta->trig->private_data = sigma_delta; + iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta); ret = iio_trigger_register(sigma_delta->trig); if (ret) diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c index 92eb6a5b9e72..6fc43c15f028 100644 --- a/drivers/iio/adc/at91_adc.c +++ b/drivers/iio/adc/at91_adc.c @@ -188,7 +188,7 @@ static u8 at91_adc_get_trigger_value_by_name(struct iio_dev *idev, static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) { - struct iio_dev *idev = trig->private_data; + struct iio_dev *idev = iio_trigger_get_drvdata(trig); struct at91_adc_state *st = iio_priv(idev); struct iio_buffer *buffer = idev->buffer; struct at91_adc_reg_desc *reg = st->registers; @@ -254,7 +254,7 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *idev, return NULL; trig->dev.parent = idev->dev.parent; - trig->private_data = idev; + iio_trigger_set_drvdata(trig, idev); trig->ops = &at91_adc_trigger_ops; ret = iio_trigger_register(trig); diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c index 7a525a91105d..87419c41b991 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c @@ -31,7 +31,7 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, bool state) { - struct hid_sensor_common *st = trig->private_data; + struct hid_sensor_common *st = iio_trigger_get_drvdata(trig); int state_val; state_val = state ? 1 : 0; @@ -76,7 +76,7 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, } trig->dev.parent = indio_dev->dev.parent; - trig->private_data = attrb; + iio_trigger_set_drvdata(trig, attrb); trig->ops = &hid_sensor_trigger_ops; ret = iio_trigger_register(trig); diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c index 139ed030abb0..8fc3a97eb266 100644 --- a/drivers/iio/common/st_sensors/st_sensors_trigger.c +++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c @@ -40,7 +40,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev, if (err) goto request_irq_error; - sdata->trig->private_data = indio_dev; + iio_trigger_set_drvdata(sdata->trig, indio_dev); sdata->trig->ops = trigger_ops; sdata->trig->dev.parent = sdata->dev; diff --git a/drivers/iio/gyro/itg3200_buffer.c b/drivers/iio/gyro/itg3200_buffer.c index f667d2c8c00f..6c43af9bb0a4 100644 --- a/drivers/iio/gyro/itg3200_buffer.c +++ b/drivers/iio/gyro/itg3200_buffer.c @@ -81,7 +81,7 @@ void itg3200_buffer_unconfigure(struct iio_dev *indio_dev) static int itg3200_data_rdy_trigger_set_state(struct iio_trigger *trig, bool state) { - struct iio_dev *indio_dev = trig->private_data; + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); int ret; u8 msc; @@ -129,7 +129,7 @@ int itg3200_probe_trigger(struct iio_dev *indio_dev) st->trig->dev.parent = &st->i2c->dev; st->trig->ops = &itg3200_trigger_ops; - st->trig->private_data = indio_dev; + iio_trigger_set_drvdata(st->trig, indio_dev); ret = iio_trigger_register(st->trig); if (ret) goto error_free_irq; diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c index da4d122ec7dc..69017c7ec302 100644 --- a/drivers/iio/gyro/st_gyro_buffer.c +++ b/drivers/iio/gyro/st_gyro_buffer.c @@ -25,7 +25,7 @@ int st_gyro_trig_set_state(struct iio_trigger *trig, bool state) { - struct iio_dev *indio_dev = trig->private_data; + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); return st_sensors_set_dataready_irq(indio_dev, state); } diff --git a/drivers/iio/imu/adis_trigger.c b/drivers/iio/imu/adis_trigger.c index 5a24c9cac343..e0017c22bb9c 100644 --- a/drivers/iio/imu/adis_trigger.c +++ b/drivers/iio/imu/adis_trigger.c @@ -19,7 +19,7 @@ static int adis_data_rdy_trigger_set_state(struct iio_trigger *trig, bool state) { - struct adis *adis = trig->private_data; + struct adis *adis = iio_trigger_get_drvdata(trig); return adis_enable_irq(adis, state); } @@ -57,7 +57,7 @@ int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev) adis->trig->dev.parent = &adis->spi->dev; adis->trig->ops = &adis_trigger_ops; - adis->trig->private_data = adis; + iio_trigger_set_drvdata(adis->trig, adis); ret = iio_trigger_register(adis->trig); indio_dev->trig = adis->trig; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c index e1d0869e0ad1..03b9372c1212 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -103,7 +103,7 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) static int inv_mpu_data_rdy_trigger_set_state(struct iio_trigger *trig, bool state) { - return inv_mpu6050_set_enable(trig->private_data, state); + return inv_mpu6050_set_enable(iio_trigger_get_drvdata(trig), state); } static const struct iio_trigger_ops inv_mpu_trigger_ops = { @@ -130,8 +130,8 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev) if (ret) goto error_free_trig; st->trig->dev.parent = &st->client->dev; - st->trig->private_data = indio_dev; st->trig->ops = &inv_mpu_trigger_ops; + iio_trigger_set_drvdata(st->trig, indio_dev); ret = iio_trigger_register(st->trig); if (ret) goto error_free_irq; diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c index e676403ea3ea..5b8f0f6c9938 100644 --- a/drivers/staging/iio/accel/lis3l02dq_ring.c +++ b/drivers/staging/iio/accel/lis3l02dq_ring.c @@ -228,7 +228,7 @@ __lis3l02dq_write_data_ready_config(struct iio_dev *indio_dev, bool state) static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig, bool state) { - struct iio_dev *indio_dev = trig->private_data; + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); int ret = 0; u8 t; @@ -252,7 +252,7 @@ static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig, */ static int lis3l02dq_trig_try_reen(struct iio_trigger *trig) { - struct iio_dev *indio_dev = trig->private_data; + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); struct lis3l02dq_state *st = iio_priv(indio_dev); int i; @@ -290,7 +290,7 @@ int lis3l02dq_probe_trigger(struct iio_dev *indio_dev) st->trig->dev.parent = &st->us->dev; st->trig->ops = &lis3l02dq_trigger_ops; - st->trig->private_data = indio_dev; + iio_trigger_set_drvdata(st->trig, indio_dev); ret = iio_trigger_register(st->trig); if (ret) goto error_free_trig; diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c index 25a4359a92db..eab975d11bb2 100644 --- a/drivers/staging/iio/adc/mxs-lradc.c +++ b/drivers/staging/iio/adc/mxs-lradc.c @@ -646,7 +646,7 @@ static irqreturn_t mxs_lradc_trigger_handler(int irq, void *p) static int mxs_lradc_configure_trigger(struct iio_trigger *trig, bool state) { - struct iio_dev *iio = trig->private_data; + struct iio_dev *iio = iio_trigger_get_drvdata(trig); struct mxs_lradc *lradc = iio_priv(iio); const uint32_t st = state ? STMP_OFFSET_REG_SET : STMP_OFFSET_REG_CLR; @@ -670,7 +670,7 @@ static int mxs_lradc_trigger_init(struct iio_dev *iio) return -ENOMEM; trig->dev.parent = iio->dev.parent; - trig->private_data = iio; + iio_trigger_set_drvdata(trig, iio); trig->ops = &mxs_lradc_trigger_ops; ret = iio_trigger_register(trig); diff --git a/drivers/staging/iio/meter/ade7758_trigger.c b/drivers/staging/iio/meter/ade7758_trigger.c index f9c6a340092b..7a94ddd42f59 100644 --- a/drivers/staging/iio/meter/ade7758_trigger.c +++ b/drivers/staging/iio/meter/ade7758_trigger.c @@ -32,7 +32,7 @@ static irqreturn_t ade7758_data_rdy_trig_poll(int irq, void *private) static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig, bool state) { - struct iio_dev *indio_dev = trig->private_data; + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); return ade7758_set_irq(&indio_dev->dev, state); @@ -44,7 +44,7 @@ static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig, **/ static int ade7758_trig_try_reen(struct iio_trigger *trig) { - struct iio_dev *indio_dev = trig->private_data; + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); struct ade7758_state *st = iio_priv(indio_dev); enable_irq(st->us->irq); @@ -81,7 +81,7 @@ int ade7758_probe_trigger(struct iio_dev *indio_dev) st->trig->dev.parent = &st->us->dev; st->trig->ops = &ade7758_trigger_ops; - st->trig->private_data = indio_dev; + iio_trigger_set_drvdata(st->trig, indio_dev); ret = iio_trigger_register(st->trig); /* select default trigger */ diff --git a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c index 42798da575c0..38a158b77b1d 100644 --- a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c +++ b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c @@ -65,7 +65,7 @@ struct bfin_tmr_state { static int iio_bfin_tmr_set_state(struct iio_trigger *trig, bool state) { - struct bfin_tmr_state *st = trig->private_data; + struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig); if (get_gptimer_period(st->t->id) == 0) return -EINVAL; @@ -82,7 +82,7 @@ static ssize_t iio_bfin_tmr_frequency_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct iio_trigger *trig = to_iio_trigger(dev); - struct bfin_tmr_state *st = trig->private_data; + struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig); unsigned long val; bool enabled; int ret; @@ -125,7 +125,7 @@ static ssize_t iio_bfin_tmr_frequency_show(struct device *dev, char *buf) { struct iio_trigger *trig = to_iio_trigger(dev); - struct bfin_tmr_state *st = trig->private_data; + struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig); unsigned int period = get_gptimer_period(st->t->id); unsigned long val; @@ -213,9 +213,9 @@ static int iio_bfin_tmr_trigger_probe(struct platform_device *pdev) goto out1; } - st->trig->private_data = st; st->trig->ops = &iio_bfin_tmr_trigger_ops; st->trig->dev.groups = iio_bfin_tmr_trigger_attr_groups; + iio_trigger_set_drvdata(st->trig, st); ret = iio_trigger_register(st->trig); if (ret) goto out2; diff --git a/drivers/staging/iio/trigger/iio-trig-gpio.c b/drivers/staging/iio/trigger/iio-trig-gpio.c index fcc4cb048c9a..7c593d18a910 100644 --- a/drivers/staging/iio/trigger/iio-trig-gpio.c +++ b/drivers/staging/iio/trigger/iio-trig-gpio.c @@ -83,7 +83,7 @@ static int iio_gpio_trigger_probe(struct platform_device *pdev) ret = -ENOMEM; goto error_put_trigger; } - trig->private_data = trig_info; + iio_trigger_set_drvdata(trig, trig_info); trig_info->irq = irq; trig->ops = &iio_gpio_trigger_ops; ret = request_irq(irq, iio_gpio_trigger_poll, @@ -121,7 +121,7 @@ static int iio_gpio_trigger_probe(struct platform_device *pdev) trig2, &iio_gpio_trigger_list, alloc_list) { - trig_info = trig->private_data; + trig_info = iio_trigger_get_drvdata(trig); free_irq(gpio_to_irq(trig_info->irq), trig); kfree(trig_info); iio_trigger_unregister(trig); @@ -140,7 +140,7 @@ static int iio_gpio_trigger_remove(struct platform_device *pdev) trig2, &iio_gpio_trigger_list, alloc_list) { - trig_info = trig->private_data; + trig_info = iio_trigger_get_drvdata(trig); iio_trigger_unregister(trig); free_irq(trig_info->irq, trig); kfree(trig_info); diff --git a/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c b/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c index 9102b1ba2530..79695974b1d4 100644 --- a/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c +++ b/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c @@ -30,7 +30,7 @@ struct iio_prtc_trigger_info { static int iio_trig_periodic_rtc_set_state(struct iio_trigger *trig, bool state) { - struct iio_prtc_trigger_info *trig_info = trig->private_data; + struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig); if (trig_info->frequency == 0) return -EINVAL; printk(KERN_INFO "trigger frequency is %d\n", trig_info->frequency); @@ -42,7 +42,7 @@ static ssize_t iio_trig_periodic_read_freq(struct device *dev, char *buf) { struct iio_trigger *trig = to_iio_trigger(dev); - struct iio_prtc_trigger_info *trig_info = trig->private_data; + struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig); return sprintf(buf, "%u\n", trig_info->frequency); } @@ -52,7 +52,7 @@ static ssize_t iio_trig_periodic_write_freq(struct device *dev, size_t len) { struct iio_trigger *trig = to_iio_trigger(dev); - struct iio_prtc_trigger_info *trig_info = trig->private_data; + struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig); unsigned long val; int ret; @@ -124,7 +124,7 @@ static int iio_trig_periodic_rtc_probe(struct platform_device *dev) ret = -ENOMEM; goto error_put_trigger_and_remove_from_list; } - trig->private_data = trig_info; + iio_trigger_set_drvdata(trig, trig_info); trig->ops = &iio_prtc_trigger_ops; /* RTC access */ trig_info->rtc @@ -158,7 +158,7 @@ static int iio_trig_periodic_rtc_probe(struct platform_device *dev) trig2, &iio_prtc_trigger_list, alloc_list) { - trig_info = trig->private_data; + trig_info = iio_trigger_get_drvdata(trig); rtc_irq_unregister(trig_info->rtc, &trig_info->task); rtc_class_close(trig_info->rtc); kfree(trig_info); @@ -176,7 +176,7 @@ static int iio_trig_periodic_rtc_remove(struct platform_device *dev) trig2, &iio_prtc_trigger_list, alloc_list) { - trig_info = trig->private_data; + trig_info = iio_trigger_get_drvdata(trig); rtc_irq_unregister(trig_info->rtc, &trig_info->task); rtc_class_close(trig_info->rtc); kfree(trig_info); diff --git a/drivers/staging/iio/trigger/iio-trig-sysfs.c b/drivers/staging/iio/trigger/iio-trig-sysfs.c index 3bac97224bf4..b727bde8b7fe 100644 --- a/drivers/staging/iio/trigger/iio-trig-sysfs.c +++ b/drivers/staging/iio/trigger/iio-trig-sysfs.c @@ -103,7 +103,7 @@ static ssize_t iio_sysfs_trigger_poll(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct iio_trigger *trig = to_iio_trigger(dev); - struct iio_sysfs_trig *sysfs_trig = trig->private_data; + struct iio_sysfs_trig *sysfs_trig = iio_trigger_get_drvdata(trig); irq_work_queue(&sysfs_trig->work); @@ -160,7 +160,7 @@ static int iio_sysfs_trigger_probe(int id) t->trig->dev.groups = iio_sysfs_trigger_attr_groups; t->trig->ops = &iio_sysfs_trigger_ops; t->trig->dev.parent = &iio_sysfs_trig_dev; - t->trig->private_data = t; + iio_trigger_set_drvdata(t->trig, t); init_irq_work(&t->work, iio_sysfs_trigger_work); diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h index c66e0a96f6e8..b81948aba1d6 100644 --- a/include/linux/iio/trigger.h +++ b/include/linux/iio/trigger.h @@ -91,6 +91,30 @@ static inline void iio_trigger_get(struct iio_trigger *trig) __module_get(trig->ops->owner); } +/** + * iio_device_set_drvdata() - Set trigger driver data + * @trig: IIO trigger structure + * @data: Driver specific data + * + * Allows to attach an arbitrary pointer to an IIO trigger, which can later be + * retrieved by iio_trigger_get_drvdata(). + */ +static inline void iio_trigger_set_drvdata(struct iio_trigger *trig, void *data) +{ + trig->private_data = data; +} + +/** + * iio_trigger_get_drvdata() - Get trigger driver data + * @trig: IIO trigger structure + * + * Returns the data previously set with iio_trigger_set_drvdata() + */ +static inline void *iio_trigger_get_drvdata(struct iio_trigger *trig) +{ + return trig->private_data; +} + /** * iio_trigger_register() - register a trigger with the IIO core * @trig_info: trigger to be registered From 5034bfc976928b447cb6decd311d35161107a72f Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 25 Mar 2013 08:58:00 +0000 Subject: [PATCH 02/12] iio:trigger: Use dev_{set,get}_drvdata for private data management Use dev_{set,get}_drvdata for managing private data attached to a trigger instead of using a custom field in the iio_trigger struct. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron --- drivers/staging/iio/Documentation/trigger.txt | 3 --- include/linux/iio/trigger.h | 6 ++---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/staging/iio/Documentation/trigger.txt b/drivers/staging/iio/Documentation/trigger.txt index 75cc37ff1ed0..64e2e08fb4d0 100644 --- a/drivers/staging/iio/Documentation/trigger.txt +++ b/drivers/staging/iio/Documentation/trigger.txt @@ -10,9 +10,6 @@ struct iio_trig *trig = iio_trigger_alloc("", ...); allocates a trigger structure. The key elements to then fill in within a driver are: -trig->private_data - Device specific private data. - trig->owner Typically set to THIS_MODULE. Used to ensure correct ownership of core allocated resources. diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h index b81948aba1d6..3869c525b052 100644 --- a/include/linux/iio/trigger.h +++ b/include/linux/iio/trigger.h @@ -44,7 +44,6 @@ struct iio_trigger_ops { * @id: [INTERN] unique id number * @name: [DRIVER] unique name * @dev: [DRIVER] associated device (if relevant) - * @private_data: [DRIVER] device specific data * @list: [INTERN] used in maintenance of global trigger list * @alloc_list: [DRIVER] used for driver specific trigger list * @use_count: use count for the trigger @@ -60,7 +59,6 @@ struct iio_trigger { const char *name; struct device dev; - void *private_data; struct list_head list; struct list_head alloc_list; int use_count; @@ -101,7 +99,7 @@ static inline void iio_trigger_get(struct iio_trigger *trig) */ static inline void iio_trigger_set_drvdata(struct iio_trigger *trig, void *data) { - trig->private_data = data; + dev_set_drvdata(&trig->dev, data); } /** @@ -112,7 +110,7 @@ static inline void iio_trigger_set_drvdata(struct iio_trigger *trig, void *data) */ static inline void *iio_trigger_get_drvdata(struct iio_trigger *trig) { - return trig->private_data; + return dev_get_drvdata(&trig->dev); } /** From 226f4ab6e37c255196a61a3bc85fe95821bbd777 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Tue, 26 Mar 2013 18:42:00 +0000 Subject: [PATCH 03/12] staging:iio:ad799x: Remove unused ad799x_state fields Remove fields from the ad799x_state struct which are not used. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad799x.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h index 3e363c4ba211..9f50f9302789 100644 --- a/drivers/staging/iio/adc/ad799x.h +++ b/drivers/staging/iio/adc/ad799x.h @@ -104,11 +104,9 @@ struct ad799x_chip_info { struct ad799x_state { struct i2c_client *client; const struct ad799x_chip_info *chip_info; - struct iio_trigger *trig; struct regulator *reg; u16 int_vref_mv; unsigned id; - char *name; u16 config; }; From 8c7e862700285be2bfdca215012eb62cc28e9a48 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Tue, 26 Mar 2013 18:43:00 +0000 Subject: [PATCH 04/12] staging:iio:ad799x: Remove internal reference support None of the devices supported by this driver have an internal voltage reference, so remove support for it from the driver. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad799x.h | 2 -- drivers/staging/iio/adc/ad799x_core.c | 16 ++++------------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h index 9f50f9302789..82e83bbb342b 100644 --- a/drivers/staging/iio/adc/ad799x.h +++ b/drivers/staging/iio/adc/ad799x.h @@ -87,7 +87,6 @@ struct ad799x_state; * struct ad799x_chip_info - chip specifc information * @channel: channel specification * @num_channels: number of channels - * @int_vref_mv: the internal reference voltage * @monitor_mode: whether the chip supports monitor interrupts * @default_config: device default configuration * @event_attrs: pointer to the monitor event attribute group @@ -96,7 +95,6 @@ struct ad799x_state; struct ad799x_chip_info { struct iio_chan_spec channel[9]; int num_channels; - u16 int_vref_mv; u16 default_config; const struct iio_info *info; }; diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c index 40cc89abe3c3..d12a4b264891 100644 --- a/drivers/staging/iio/adc/ad799x_core.c +++ b/drivers/staging/iio/adc/ad799x_core.c @@ -498,7 +498,6 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { [4] = IIO_CHAN_SOFT_TIMESTAMP(4), }, .num_channels = 5, - .int_vref_mv = 4096, .info = &ad7991_info, }, [ad7995] = { @@ -538,7 +537,6 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { [4] = IIO_CHAN_SOFT_TIMESTAMP(4), }, .num_channels = 5, - .int_vref_mv = 1024, .info = &ad7991_info, }, [ad7999] = { @@ -578,7 +576,6 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { [4] = IIO_CHAN_SOFT_TIMESTAMP(4), }, .num_channels = 5, - .int_vref_mv = 1024, .info = &ad7991_info, }, [ad7992] = { @@ -604,7 +601,6 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { [2] = IIO_CHAN_SOFT_TIMESTAMP(2), }, .num_channels = 3, - .int_vref_mv = 4096, .default_config = AD7998_ALERT_EN, .info = &ad7992_info, }, @@ -649,7 +645,6 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { [4] = IIO_CHAN_SOFT_TIMESTAMP(4), }, .num_channels = 5, - .int_vref_mv = 1024, .default_config = AD7998_ALERT_EN, .info = &ad7993_4_7_8_info, }, @@ -694,7 +689,6 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { [4] = IIO_CHAN_SOFT_TIMESTAMP(4), }, .num_channels = 5, - .int_vref_mv = 4096, .default_config = AD7998_ALERT_EN, .info = &ad7993_4_7_8_info, }, @@ -771,7 +765,6 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { [8] = IIO_CHAN_SOFT_TIMESTAMP(8), }, .num_channels = 9, - .int_vref_mv = 1024, .default_config = AD7998_ALERT_EN, .info = &ad7993_4_7_8_info, }, @@ -848,7 +841,6 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { [8] = IIO_CHAN_SOFT_TIMESTAMP(8), }, .num_channels = 9, - .int_vref_mv = 4096, .default_config = AD7998_ALERT_EN, .info = &ad7993_4_7_8_info, }, @@ -875,10 +867,10 @@ static int ad799x_probe(struct i2c_client *client, /* TODO: Add pdata options for filtering and bit delay */ - if (pdata) - st->int_vref_mv = pdata->vref_mv; - else - st->int_vref_mv = st->chip_info->int_vref_mv; + if (!pdata) + return -EINVAL; + + st->int_vref_mv = pdata->vref_mv; st->reg = regulator_get(&client->dev, "vcc"); if (!IS_ERR(st->reg)) { From 34244ceccd99fab2a2640a5af7cc5a94d02c91cd Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Tue, 26 Mar 2013 18:43:00 +0000 Subject: [PATCH 05/12] staging:iio:ad799x: Use i2c_smbus_{read,write}_word_data_swapped Use i2c_smbus_{read,write}_word_data_swapped instead of open-coding it. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad799x_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c index d12a4b264891..8d2012cfa59e 100644 --- a/drivers/staging/iio/adc/ad799x_core.c +++ b/drivers/staging/iio/adc/ad799x_core.c @@ -48,13 +48,13 @@ static int ad799x_i2c_read16(struct ad799x_state *st, u8 reg, u16 *data) struct i2c_client *client = st->client; int ret = 0; - ret = i2c_smbus_read_word_data(client, reg); + ret = i2c_smbus_read_word_swapped(client, reg); if (ret < 0) { dev_err(&client->dev, "I2C read error\n"); return ret; } - *data = swab16((u16)ret); + *data = (u16)ret; return 0; } @@ -80,7 +80,7 @@ static int ad799x_i2c_write16(struct ad799x_state *st, u8 reg, u16 data) struct i2c_client *client = st->client; int ret = 0; - ret = i2c_smbus_write_word_data(client, reg, swab16(data)); + ret = i2c_smbus_write_word_swapped(client, reg, data); if (ret < 0) dev_err(&client->dev, "I2C write error\n"); From ae6d648940dbf3f158423865b51a70a6571d872d Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Tue, 26 Mar 2013 18:43:00 +0000 Subject: [PATCH 06/12] staging:iio:ad799x: Add helper macro for channel initialization The ad779x channels all follow the same pattern. Add a helper macro to initialize the channel spec, this allows us to drop quite a few lines. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad799x_core.c | 386 ++++---------------------- 1 file changed, 56 insertions(+), 330 deletions(-) diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c index 8d2012cfa59e..49972e1bc1e4 100644 --- a/drivers/staging/iio/adc/ad799x_core.c +++ b/drivers/staging/iio/adc/ad799x_core.c @@ -460,145 +460,55 @@ static const struct iio_info ad7993_4_7_8_info = { #define AD799X_EV_MASK (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \ IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)) +#define AD799X_CHANNEL(_index, _realbits, _evmask) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = (_index), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .scan_index = (_index), \ + .scan_type = IIO_ST('u', _realbits, 16, 12 - (_realbits)), \ + .event_mask = (_evmask), \ +} + static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { [ad7991] = { .channel = { - [0] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 0, - .scan_type = IIO_ST('u', 12, 16, 0), - }, - [1] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 1, - .scan_type = IIO_ST('u', 12, 16, 0), - }, - [2] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 2, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 2, - .scan_type = IIO_ST('u', 12, 16, 0), - }, - [3] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 3, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 3, - .scan_type = IIO_ST('u', 12, 16, 0), - }, - [4] = IIO_CHAN_SOFT_TIMESTAMP(4), + AD799X_CHANNEL(0, 12, 0), + AD799X_CHANNEL(1, 12, 0), + AD799X_CHANNEL(2, 12, 0), + AD799X_CHANNEL(3, 12, 0), + IIO_CHAN_SOFT_TIMESTAMP(4), }, .num_channels = 5, .info = &ad7991_info, }, [ad7995] = { .channel = { - [0] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 0, - .scan_type = IIO_ST('u', 10, 16, 2), - }, - [1] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 1, - .scan_type = IIO_ST('u', 10, 16, 2), - }, - [2] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 2, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 2, - .scan_type = IIO_ST('u', 10, 16, 2), - }, - [3] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 3, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 3, - .scan_type = IIO_ST('u', 10, 16, 2), - }, - [4] = IIO_CHAN_SOFT_TIMESTAMP(4), + AD799X_CHANNEL(0, 10, 0), + AD799X_CHANNEL(1, 10, 0), + AD799X_CHANNEL(2, 10, 0), + AD799X_CHANNEL(3, 10, 0), + IIO_CHAN_SOFT_TIMESTAMP(4), }, .num_channels = 5, .info = &ad7991_info, }, [ad7999] = { .channel = { - [0] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 0, - .scan_type = IIO_ST('u', 8, 16, 4), - }, - [1] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 1, - .scan_type = IIO_ST('u', 8, 16, 4), - }, - [2] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 2, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 2, - .scan_type = IIO_ST('u', 8, 16, 4), - }, - [3] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 3, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 3, - .scan_type = IIO_ST('u', 8, 16, 4), - }, - [4] = IIO_CHAN_SOFT_TIMESTAMP(4), + AD799X_CHANNEL(0, 8, 0), + AD799X_CHANNEL(1, 8, 0), + AD799X_CHANNEL(2, 8, 0), + AD799X_CHANNEL(3, 8, 0), + IIO_CHAN_SOFT_TIMESTAMP(4), }, .num_channels = 5, .info = &ad7991_info, }, [ad7992] = { .channel = { - [0] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 0, - .scan_type = IIO_ST('u', 12, 16, 0), - .event_mask = AD799X_EV_MASK, - }, - [1] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 1, - .scan_type = IIO_ST('u', 12, 16, 0), - .event_mask = AD799X_EV_MASK, - }, - [2] = IIO_CHAN_SOFT_TIMESTAMP(2), + AD799X_CHANNEL(0, 12, AD799X_EV_MASK), + AD799X_CHANNEL(1, 12, AD799X_EV_MASK), + IIO_CHAN_SOFT_TIMESTAMP(3), }, .num_channels = 3, .default_config = AD7998_ALERT_EN, @@ -606,43 +516,11 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { }, [ad7993] = { .channel = { - [0] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 0, - .scan_type = IIO_ST('u', 10, 16, 2), - .event_mask = AD799X_EV_MASK, - }, - [1] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .scan_index = 1, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_type = IIO_ST('u', 10, 16, 2), - .event_mask = AD799X_EV_MASK, - }, - [2] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 2, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 2, - .scan_type = IIO_ST('u', 10, 16, 2), - .event_mask = AD799X_EV_MASK, - }, - [3] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 3, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 3, - .scan_type = IIO_ST('u', 10, 16, 2), - .event_mask = AD799X_EV_MASK, - }, - [4] = IIO_CHAN_SOFT_TIMESTAMP(4), + AD799X_CHANNEL(0, 10, AD799X_EV_MASK), + AD799X_CHANNEL(1, 10, AD799X_EV_MASK), + AD799X_CHANNEL(2, 10, AD799X_EV_MASK), + AD799X_CHANNEL(3, 10, AD799X_EV_MASK), + IIO_CHAN_SOFT_TIMESTAMP(4), }, .num_channels = 5, .default_config = AD7998_ALERT_EN, @@ -650,43 +528,11 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { }, [ad7994] = { .channel = { - [0] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 0, - .scan_type = IIO_ST('u', 12, 16, 0), - .event_mask = AD799X_EV_MASK, - }, - [1] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 1, - .scan_type = IIO_ST('u', 12, 16, 0), - .event_mask = AD799X_EV_MASK, - }, - [2] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 2, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 2, - .scan_type = IIO_ST('u', 12, 16, 0), - .event_mask = AD799X_EV_MASK, - }, - [3] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 3, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 3, - .scan_type = IIO_ST('u', 12, 16, 0), - .event_mask = AD799X_EV_MASK, - }, - [4] = IIO_CHAN_SOFT_TIMESTAMP(4), + AD799X_CHANNEL(0, 12, AD799X_EV_MASK), + AD799X_CHANNEL(1, 12, AD799X_EV_MASK), + AD799X_CHANNEL(2, 12, AD799X_EV_MASK), + AD799X_CHANNEL(3, 12, AD799X_EV_MASK), + IIO_CHAN_SOFT_TIMESTAMP(4), }, .num_channels = 5, .default_config = AD7998_ALERT_EN, @@ -694,75 +540,15 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { }, [ad7997] = { .channel = { - [0] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 0, - .scan_type = IIO_ST('u', 10, 16, 2), - .event_mask = AD799X_EV_MASK, - }, - [1] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 1, - .scan_type = IIO_ST('u', 10, 16, 2), - .event_mask = AD799X_EV_MASK, - }, - [2] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 2, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 2, - .scan_type = IIO_ST('u', 10, 16, 2), - .event_mask = AD799X_EV_MASK, - }, - [3] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 3, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 3, - .scan_type = IIO_ST('u', 10, 16, 2), - .event_mask = AD799X_EV_MASK, - }, - [4] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 4, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 4, - .scan_type = IIO_ST('u', 10, 16, 2), - }, - [5] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 5, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 5, - .scan_type = IIO_ST('u', 10, 16, 2), - }, - [6] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 6, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 6, - .scan_type = IIO_ST('u', 10, 16, 2), - }, - [7] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 7, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 7, - .scan_type = IIO_ST('u', 10, 16, 2), - }, - [8] = IIO_CHAN_SOFT_TIMESTAMP(8), + AD799X_CHANNEL(0, 10, AD799X_EV_MASK), + AD799X_CHANNEL(1, 10, AD799X_EV_MASK), + AD799X_CHANNEL(2, 10, AD799X_EV_MASK), + AD799X_CHANNEL(3, 10, AD799X_EV_MASK), + AD799X_CHANNEL(4, 10, 0), + AD799X_CHANNEL(5, 10, 0), + AD799X_CHANNEL(6, 10, 0), + AD799X_CHANNEL(7, 10, 0), + IIO_CHAN_SOFT_TIMESTAMP(8), }, .num_channels = 9, .default_config = AD7998_ALERT_EN, @@ -770,75 +556,15 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { }, [ad7998] = { .channel = { - [0] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 0, - .scan_type = IIO_ST('u', 12, 16, 0), - .event_mask = AD799X_EV_MASK, - }, - [1] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 1, - .scan_type = IIO_ST('u', 12, 16, 0), - .event_mask = AD799X_EV_MASK, - }, - [2] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 2, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 2, - .scan_type = IIO_ST('u', 12, 16, 0), - .event_mask = AD799X_EV_MASK, - }, - [3] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 3, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 3, - .scan_type = IIO_ST('u', 12, 16, 0), - .event_mask = AD799X_EV_MASK, - }, - [4] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 4, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 4, - .scan_type = IIO_ST('u', 12, 16, 0), - }, - [5] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 5, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 5, - .scan_type = IIO_ST('u', 12, 16, 0), - }, - [6] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 6, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 6, - .scan_type = IIO_ST('u', 12, 16, 0), - }, - [7] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 7, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .scan_index = 7, - .scan_type = IIO_ST('u', 12, 16, 0), - }, - [8] = IIO_CHAN_SOFT_TIMESTAMP(8), + AD799X_CHANNEL(0, 12, AD799X_EV_MASK), + AD799X_CHANNEL(1, 12, AD799X_EV_MASK), + AD799X_CHANNEL(2, 12, AD799X_EV_MASK), + AD799X_CHANNEL(3, 12, AD799X_EV_MASK), + AD799X_CHANNEL(4, 12, 0), + AD799X_CHANNEL(5, 12, 0), + AD799X_CHANNEL(6, 12, 0), + AD799X_CHANNEL(7, 12, 0), + IIO_CHAN_SOFT_TIMESTAMP(8), }, .num_channels = 9, .default_config = AD7998_ALERT_EN, From d00698df2180ecd78b2892856b310dfedd5f6fe7 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Tue, 26 Mar 2013 18:43:00 +0000 Subject: [PATCH 07/12] staging:iio:ad799x: Set IIO_CHAN_INFO_SCALE mask The driver has support for reporting a channels scale, but none of the channels set the IIO_CHAN_INFO_SCALE mask. Add the IIO_CHAN_INFO_SCALE to all channels to indicate that the drivers supports reporting the scale. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad799x_core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c index 49972e1bc1e4..b7510557d064 100644 --- a/drivers/staging/iio/adc/ad799x_core.c +++ b/drivers/staging/iio/adc/ad799x_core.c @@ -465,6 +465,7 @@ static const struct iio_info ad7993_4_7_8_info = { .indexed = 1, \ .channel = (_index), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ .scan_index = (_index), \ .scan_type = IIO_ST('u', _realbits, 16, 12 - (_realbits)), \ .event_mask = (_evmask), \ From d8dca33027c1fda3318fe8af85456b801ef88e1e Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Tue, 26 Mar 2013 18:43:00 +0000 Subject: [PATCH 08/12] staging:iio:ad799x: Preallocate sample buffer Avoid allocating and freeing the sample buffer for each transfer. Instead allocate it once when we start sampling. Also pre-compute the number of bytes we need to transfer in the same way. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad799x.h | 3 +++ drivers/staging/iio/adc/ad799x_core.c | 8 ++++++++ drivers/staging/iio/adc/ad799x_ring.c | 16 ++++------------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h index 82e83bbb342b..b51680c1c331 100644 --- a/drivers/staging/iio/adc/ad799x.h +++ b/drivers/staging/iio/adc/ad799x.h @@ -106,6 +106,9 @@ struct ad799x_state { u16 int_vref_mv; unsigned id; u16 config; + + u8 *rx_buf; + unsigned int transfer_size; }; /* diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c index b7510557d064..8dc97b36e05a 100644 --- a/drivers/staging/iio/adc/ad799x_core.c +++ b/drivers/staging/iio/adc/ad799x_core.c @@ -104,6 +104,13 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev, { struct ad799x_state *st = iio_priv(indio_dev); + kfree(st->rx_buf); + st->rx_buf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); + if (!st->rx_buf) + return -ENOMEM; + + st->transfer_size = bitmap_weight(scan_mask, indio_dev->masklength) * 2; + switch (st->id) { case ad7997: case ad7998: @@ -665,6 +672,7 @@ static int ad799x_remove(struct i2c_client *client) regulator_disable(st->reg); regulator_put(st->reg); } + kfree(st->rx_buf); iio_device_free(indio_dev); return 0; diff --git a/drivers/staging/iio/adc/ad799x_ring.c b/drivers/staging/iio/adc/ad799x_ring.c index 2c5f38475a8e..c2ebae12ee19 100644 --- a/drivers/staging/iio/adc/ad799x_ring.c +++ b/drivers/staging/iio/adc/ad799x_ring.c @@ -36,14 +36,9 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p) struct iio_dev *indio_dev = pf->indio_dev; struct ad799x_state *st = iio_priv(indio_dev); s64 time_ns; - __u8 *rxbuf; int b_sent; u8 cmd; - rxbuf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); - if (rxbuf == NULL) - goto out; - switch (st->id) { case ad7991: case ad7995: @@ -66,20 +61,17 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p) } b_sent = i2c_smbus_read_i2c_block_data(st->client, - cmd, bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength) * 2, rxbuf); + cmd, st->transfer_size, st->rx_buf); if (b_sent < 0) - goto done; + goto out; time_ns = iio_get_time_ns(); if (indio_dev->scan_timestamp) - memcpy(rxbuf + indio_dev->scan_bytes - sizeof(s64), + memcpy(st->rx_buf + indio_dev->scan_bytes - sizeof(s64), &time_ns, sizeof(time_ns)); - iio_push_to_buffers(indio_dev, rxbuf); -done: - kfree(rxbuf); + iio_push_to_buffers(indio_dev, st->rx_buf); out: iio_trigger_notify_done(indio_dev->trig); From 1ba0686b2b56bf4d59a6796152df0cd6843d3145 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 26 Mar 2013 09:42:00 +0000 Subject: [PATCH 09/12] iio: exynos_adc: Remove redundant of_match_ptr macro exynos_adc is a DT only driver and exynos_adc_match table is always compiled in. Hence remove the macro. Signed-off-by: Sachin Kamat Signed-off-by: Jonathan Cameron --- drivers/iio/adc/exynos_adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c index 4a8a9a34228f..9f3a8ef1fb3e 100644 --- a/drivers/iio/adc/exynos_adc.c +++ b/drivers/iio/adc/exynos_adc.c @@ -440,7 +440,7 @@ static struct platform_driver exynos_adc_driver = { .driver = { .name = "exynos-adc", .owner = THIS_MODULE, - .of_match_table = of_match_ptr(exynos_adc_match), + .of_match_table = exynos_adc_match, .pm = &exynos_adc_pm_ops, }, }; From df4b404b35e3e125b7e6d82f9affc6c704502cb3 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 26 Mar 2013 11:52:00 +0000 Subject: [PATCH 10/12] iio: exynos-adc: Fix typo in DT documentation Fixes some typos in the documentation of exynos-adc.txt. Signed-off-by: Sachin Kamat Signed-off-by: Jonathan Cameron --- Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt b/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt index 05e9d95ede5c..1fc744bd7166 100644 --- a/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt +++ b/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt @@ -1,6 +1,6 @@ Samsung Exynos Analog to Digital Converter bindings -This devicetree binding are for the new adc driver written fori +The devicetree bindings are for the new ADC driver written for Exynos4 and upward SoCs from Samsung. New driver handles the following @@ -49,4 +49,4 @@ adc@12D10000 { }; Note: Does not apply to ADC driver under arch/arm/plat-samsung/ -Note: The child node can be added under the adc node or seperately. +Note: The child node can be added under the adc node or separately. From f6e8a9687b785b4c75d71370681f7a6e9fd89685 Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Thu, 28 Mar 2013 22:04:00 +0000 Subject: [PATCH 11/12] iio: mxs-lradc: Do hardware initialization earlier We need to initialize hardware before registering the touchscreen. Else, we end up setting registers in mxs_lradc_ts_open(), getting called just after registering the touchscreen with input_register_device() and by the end of mxs_lradc_probe(), we reset the LRADC block hence losing the correct configuration. Signed-off-by: Alexandre Belloni Acked-by: Marek Vasut Signed-off-by: Jonathan Cameron Cc: Fabio Estevam --- drivers/staging/iio/adc/mxs-lradc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c index eab975d11bb2..6044e1717b20 100644 --- a/drivers/staging/iio/adc/mxs-lradc.c +++ b/drivers/staging/iio/adc/mxs-lradc.c @@ -983,6 +983,9 @@ static int mxs_lradc_probe(struct platform_device *pdev) if (ret) goto err_trig; + /* Configure the hardware. */ + mxs_lradc_hw_init(lradc); + /* Register the touchscreen input device. */ ret = mxs_lradc_ts_register(lradc); if (ret) @@ -995,9 +998,6 @@ static int mxs_lradc_probe(struct platform_device *pdev) goto err_ts; } - /* Configure the hardware. */ - mxs_lradc_hw_init(lradc); - return 0; err_ts: From 2b684024b59c4b1a1440e8c7499b7060a22d1ec1 Mon Sep 17 00:00:00 2001 From: Doug Anderson Date: Wed, 13 Mar 2013 20:39:00 +0000 Subject: [PATCH 12/12] iio: adc: Document the regulator/clocks for exynos-adc The exynos ADC won't work without a regulator called "vdd" and a clock called "adc". Document this fact in the device tree bindings. Signed-off-by: Doug Anderson Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Jonathan Cameron --- .../devicetree/bindings/arm/samsung/exynos-adc.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt b/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt index 1fc744bd7166..47ada1dff216 100644 --- a/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt +++ b/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt @@ -20,6 +20,9 @@ Required properties: format is being dependent on which interrupt controller the Samsung device uses. - #io-channel-cells = <1>; As ADC has multiple outputs +- clocks From common clock binding: handle to adc clock. +- clock-names From common clock binding: Shall be "adc". +- vdd-supply VDD input supply. Note: child nodes can be added for auto probing from device tree. @@ -31,6 +34,11 @@ adc: adc@12D10000 { interrupts = <0 106 0>; #io-channel-cells = <1>; io-channel-ranges; + + clocks = <&clock 303>; + clock-names = "adc"; + + vdd-supply = <&buck5_reg>; };