aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2013-03-25 04:58:00 -0400
committerJonathan Cameron <jic23@kernel.org>2013-03-25 17:06:09 -0400
commit1e9663c62b32f695af37fec4afc473b59f5ca9b4 (patch)
tree8f1c1c9fbaa89c3f75ad14a04dd8ee20ecb6dba0
parentc5cf4606b6659e711258b6e567415ab83a3b646c (diff)
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: <smpl> @@ 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) </smpl> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/iio/accel/st_accel_buffer.c2
-rw-r--r--drivers/iio/adc/ad_sigma_delta.c2
-rw-r--r--drivers/iio/adc/at91_adc.c4
-rw-r--r--drivers/iio/common/hid-sensors/hid-sensor-trigger.c4
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_trigger.c2
-rw-r--r--drivers/iio/gyro/itg3200_buffer.c4
-rw-r--r--drivers/iio/gyro/st_gyro_buffer.c2
-rw-r--r--drivers/iio/imu/adis_trigger.c4
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c4
-rw-r--r--drivers/staging/iio/accel/lis3l02dq_ring.c6
-rw-r--r--drivers/staging/iio/adc/mxs-lradc.c4
-rw-r--r--drivers/staging/iio/meter/ade7758_trigger.c6
-rw-r--r--drivers/staging/iio/trigger/iio-trig-bfin-timer.c8
-rw-r--r--drivers/staging/iio/trigger/iio-trig-gpio.c6
-rw-r--r--drivers/staging/iio/trigger/iio-trig-periodic-rtc.c12
-rw-r--r--drivers/staging/iio/trigger/iio-trig-sysfs.c4
-rw-r--r--include/linux/iio/trigger.h24
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 @@
25 25
26int st_accel_trig_set_state(struct iio_trigger *trig, bool state) 26int st_accel_trig_set_state(struct iio_trigger *trig, bool state)
27{ 27{
28 struct iio_dev *indio_dev = trig->private_data; 28 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
29 29
30 return st_sensors_set_dataready_irq(indio_dev, state); 30 return st_sensors_set_dataready_irq(indio_dev, state);
31} 31}
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)
470 disable_irq_nosync(sigma_delta->spi->irq); 470 disable_irq_nosync(sigma_delta->spi->irq);
471 } 471 }
472 sigma_delta->trig->dev.parent = &sigma_delta->spi->dev; 472 sigma_delta->trig->dev.parent = &sigma_delta->spi->dev;
473 sigma_delta->trig->private_data = sigma_delta; 473 iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta);
474 474
475 ret = iio_trigger_register(sigma_delta->trig); 475 ret = iio_trigger_register(sigma_delta->trig);
476 if (ret) 476 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,
188 188
189static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) 189static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state)
190{ 190{
191 struct iio_dev *idev = trig->private_data; 191 struct iio_dev *idev = iio_trigger_get_drvdata(trig);
192 struct at91_adc_state *st = iio_priv(idev); 192 struct at91_adc_state *st = iio_priv(idev);
193 struct iio_buffer *buffer = idev->buffer; 193 struct iio_buffer *buffer = idev->buffer;
194 struct at91_adc_reg_desc *reg = st->registers; 194 struct at91_adc_reg_desc *reg = st->registers;
@@ -254,7 +254,7 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *idev,
254 return NULL; 254 return NULL;
255 255
256 trig->dev.parent = idev->dev.parent; 256 trig->dev.parent = idev->dev.parent;
257 trig->private_data = idev; 257 iio_trigger_set_drvdata(trig, idev);
258 trig->ops = &at91_adc_trigger_ops; 258 trig->ops = &at91_adc_trigger_ops;
259 259
260 ret = iio_trigger_register(trig); 260 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 @@
31static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, 31static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
32 bool state) 32 bool state)
33{ 33{
34 struct hid_sensor_common *st = trig->private_data; 34 struct hid_sensor_common *st = iio_trigger_get_drvdata(trig);
35 int state_val; 35 int state_val;
36 36
37 state_val = state ? 1 : 0; 37 state_val = state ? 1 : 0;
@@ -76,7 +76,7 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
76 } 76 }
77 77
78 trig->dev.parent = indio_dev->dev.parent; 78 trig->dev.parent = indio_dev->dev.parent;
79 trig->private_data = attrb; 79 iio_trigger_set_drvdata(trig, attrb);
80 trig->ops = &hid_sensor_trigger_ops; 80 trig->ops = &hid_sensor_trigger_ops;
81 ret = iio_trigger_register(trig); 81 ret = iio_trigger_register(trig);
82 82
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,
40 if (err) 40 if (err)
41 goto request_irq_error; 41 goto request_irq_error;
42 42
43 sdata->trig->private_data = indio_dev; 43 iio_trigger_set_drvdata(sdata->trig, indio_dev);
44 sdata->trig->ops = trigger_ops; 44 sdata->trig->ops = trigger_ops;
45 sdata->trig->dev.parent = sdata->dev; 45 sdata->trig->dev.parent = sdata->dev;
46 46
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)
81static int itg3200_data_rdy_trigger_set_state(struct iio_trigger *trig, 81static int itg3200_data_rdy_trigger_set_state(struct iio_trigger *trig,
82 bool state) 82 bool state)
83{ 83{
84 struct iio_dev *indio_dev = trig->private_data; 84 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
85 int ret; 85 int ret;
86 u8 msc; 86 u8 msc;
87 87
@@ -129,7 +129,7 @@ int itg3200_probe_trigger(struct iio_dev *indio_dev)
129 129
130 st->trig->dev.parent = &st->i2c->dev; 130 st->trig->dev.parent = &st->i2c->dev;
131 st->trig->ops = &itg3200_trigger_ops; 131 st->trig->ops = &itg3200_trigger_ops;
132 st->trig->private_data = indio_dev; 132 iio_trigger_set_drvdata(st->trig, indio_dev);
133 ret = iio_trigger_register(st->trig); 133 ret = iio_trigger_register(st->trig);
134 if (ret) 134 if (ret)
135 goto error_free_irq; 135 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 @@
25 25
26int st_gyro_trig_set_state(struct iio_trigger *trig, bool state) 26int st_gyro_trig_set_state(struct iio_trigger *trig, bool state)
27{ 27{
28 struct iio_dev *indio_dev = trig->private_data; 28 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
29 29
30 return st_sensors_set_dataready_irq(indio_dev, state); 30 return st_sensors_set_dataready_irq(indio_dev, state);
31} 31}
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 @@
19static int adis_data_rdy_trigger_set_state(struct iio_trigger *trig, 19static int adis_data_rdy_trigger_set_state(struct iio_trigger *trig,
20 bool state) 20 bool state)
21{ 21{
22 struct adis *adis = trig->private_data; 22 struct adis *adis = iio_trigger_get_drvdata(trig);
23 23
24 return adis_enable_irq(adis, state); 24 return adis_enable_irq(adis, state);
25} 25}
@@ -57,7 +57,7 @@ int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
57 57
58 adis->trig->dev.parent = &adis->spi->dev; 58 adis->trig->dev.parent = &adis->spi->dev;
59 adis->trig->ops = &adis_trigger_ops; 59 adis->trig->ops = &adis_trigger_ops;
60 adis->trig->private_data = adis; 60 iio_trigger_set_drvdata(adis->trig, adis);
61 ret = iio_trigger_register(adis->trig); 61 ret = iio_trigger_register(adis->trig);
62 62
63 indio_dev->trig = adis->trig; 63 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)
103static int inv_mpu_data_rdy_trigger_set_state(struct iio_trigger *trig, 103static int inv_mpu_data_rdy_trigger_set_state(struct iio_trigger *trig,
104 bool state) 104 bool state)
105{ 105{
106 return inv_mpu6050_set_enable(trig->private_data, state); 106 return inv_mpu6050_set_enable(iio_trigger_get_drvdata(trig), state);
107} 107}
108 108
109static const struct iio_trigger_ops inv_mpu_trigger_ops = { 109static const struct iio_trigger_ops inv_mpu_trigger_ops = {
@@ -130,8 +130,8 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev)
130 if (ret) 130 if (ret)
131 goto error_free_trig; 131 goto error_free_trig;
132 st->trig->dev.parent = &st->client->dev; 132 st->trig->dev.parent = &st->client->dev;
133 st->trig->private_data = indio_dev;
134 st->trig->ops = &inv_mpu_trigger_ops; 133 st->trig->ops = &inv_mpu_trigger_ops;
134 iio_trigger_set_drvdata(st->trig, indio_dev);
135 ret = iio_trigger_register(st->trig); 135 ret = iio_trigger_register(st->trig);
136 if (ret) 136 if (ret)
137 goto error_free_irq; 137 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 @@ error_ret:
228static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig, 228static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig,
229 bool state) 229 bool state)
230{ 230{
231 struct iio_dev *indio_dev = trig->private_data; 231 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
232 int ret = 0; 232 int ret = 0;
233 u8 t; 233 u8 t;
234 234
@@ -252,7 +252,7 @@ static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig,
252 */ 252 */
253static int lis3l02dq_trig_try_reen(struct iio_trigger *trig) 253static int lis3l02dq_trig_try_reen(struct iio_trigger *trig)
254{ 254{
255 struct iio_dev *indio_dev = trig->private_data; 255 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
256 struct lis3l02dq_state *st = iio_priv(indio_dev); 256 struct lis3l02dq_state *st = iio_priv(indio_dev);
257 int i; 257 int i;
258 258
@@ -290,7 +290,7 @@ int lis3l02dq_probe_trigger(struct iio_dev *indio_dev)
290 290
291 st->trig->dev.parent = &st->us->dev; 291 st->trig->dev.parent = &st->us->dev;
292 st->trig->ops = &lis3l02dq_trigger_ops; 292 st->trig->ops = &lis3l02dq_trigger_ops;
293 st->trig->private_data = indio_dev; 293 iio_trigger_set_drvdata(st->trig, indio_dev);
294 ret = iio_trigger_register(st->trig); 294 ret = iio_trigger_register(st->trig);
295 if (ret) 295 if (ret)
296 goto error_free_trig; 296 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)
646 646
647static int mxs_lradc_configure_trigger(struct iio_trigger *trig, bool state) 647static int mxs_lradc_configure_trigger(struct iio_trigger *trig, bool state)
648{ 648{
649 struct iio_dev *iio = trig->private_data; 649 struct iio_dev *iio = iio_trigger_get_drvdata(trig);
650 struct mxs_lradc *lradc = iio_priv(iio); 650 struct mxs_lradc *lradc = iio_priv(iio);
651 const uint32_t st = state ? STMP_OFFSET_REG_SET : STMP_OFFSET_REG_CLR; 651 const uint32_t st = state ? STMP_OFFSET_REG_SET : STMP_OFFSET_REG_CLR;
652 652
@@ -670,7 +670,7 @@ static int mxs_lradc_trigger_init(struct iio_dev *iio)
670 return -ENOMEM; 670 return -ENOMEM;
671 671
672 trig->dev.parent = iio->dev.parent; 672 trig->dev.parent = iio->dev.parent;
673 trig->private_data = iio; 673 iio_trigger_set_drvdata(trig, iio);
674 trig->ops = &mxs_lradc_trigger_ops; 674 trig->ops = &mxs_lradc_trigger_ops;
675 675
676 ret = iio_trigger_register(trig); 676 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)
32static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig, 32static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig,
33 bool state) 33 bool state)
34{ 34{
35 struct iio_dev *indio_dev = trig->private_data; 35 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
36 36
37 dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); 37 dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
38 return ade7758_set_irq(&indio_dev->dev, state); 38 return ade7758_set_irq(&indio_dev->dev, state);
@@ -44,7 +44,7 @@ static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig,
44 **/ 44 **/
45static int ade7758_trig_try_reen(struct iio_trigger *trig) 45static int ade7758_trig_try_reen(struct iio_trigger *trig)
46{ 46{
47 struct iio_dev *indio_dev = trig->private_data; 47 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
48 struct ade7758_state *st = iio_priv(indio_dev); 48 struct ade7758_state *st = iio_priv(indio_dev);
49 49
50 enable_irq(st->us->irq); 50 enable_irq(st->us->irq);
@@ -81,7 +81,7 @@ int ade7758_probe_trigger(struct iio_dev *indio_dev)
81 81
82 st->trig->dev.parent = &st->us->dev; 82 st->trig->dev.parent = &st->us->dev;
83 st->trig->ops = &ade7758_trigger_ops; 83 st->trig->ops = &ade7758_trigger_ops;
84 st->trig->private_data = indio_dev; 84 iio_trigger_set_drvdata(st->trig, indio_dev);
85 ret = iio_trigger_register(st->trig); 85 ret = iio_trigger_register(st->trig);
86 86
87 /* select default trigger */ 87 /* 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 {
65 65
66static int iio_bfin_tmr_set_state(struct iio_trigger *trig, bool state) 66static int iio_bfin_tmr_set_state(struct iio_trigger *trig, bool state)
67{ 67{
68 struct bfin_tmr_state *st = trig->private_data; 68 struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig);
69 69
70 if (get_gptimer_period(st->t->id) == 0) 70 if (get_gptimer_period(st->t->id) == 0)
71 return -EINVAL; 71 return -EINVAL;
@@ -82,7 +82,7 @@ static ssize_t iio_bfin_tmr_frequency_store(struct device *dev,
82 struct device_attribute *attr, const char *buf, size_t count) 82 struct device_attribute *attr, const char *buf, size_t count)
83{ 83{
84 struct iio_trigger *trig = to_iio_trigger(dev); 84 struct iio_trigger *trig = to_iio_trigger(dev);
85 struct bfin_tmr_state *st = trig->private_data; 85 struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig);
86 unsigned long val; 86 unsigned long val;
87 bool enabled; 87 bool enabled;
88 int ret; 88 int ret;
@@ -125,7 +125,7 @@ static ssize_t iio_bfin_tmr_frequency_show(struct device *dev,
125 char *buf) 125 char *buf)
126{ 126{
127 struct iio_trigger *trig = to_iio_trigger(dev); 127 struct iio_trigger *trig = to_iio_trigger(dev);
128 struct bfin_tmr_state *st = trig->private_data; 128 struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig);
129 unsigned int period = get_gptimer_period(st->t->id); 129 unsigned int period = get_gptimer_period(st->t->id);
130 unsigned long val; 130 unsigned long val;
131 131
@@ -213,9 +213,9 @@ static int iio_bfin_tmr_trigger_probe(struct platform_device *pdev)
213 goto out1; 213 goto out1;
214 } 214 }
215 215
216 st->trig->private_data = st;
217 st->trig->ops = &iio_bfin_tmr_trigger_ops; 216 st->trig->ops = &iio_bfin_tmr_trigger_ops;
218 st->trig->dev.groups = iio_bfin_tmr_trigger_attr_groups; 217 st->trig->dev.groups = iio_bfin_tmr_trigger_attr_groups;
218 iio_trigger_set_drvdata(st->trig, st);
219 ret = iio_trigger_register(st->trig); 219 ret = iio_trigger_register(st->trig);
220 if (ret) 220 if (ret)
221 goto out2; 221 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)
83 ret = -ENOMEM; 83 ret = -ENOMEM;
84 goto error_put_trigger; 84 goto error_put_trigger;
85 } 85 }
86 trig->private_data = trig_info; 86 iio_trigger_set_drvdata(trig, trig_info);
87 trig_info->irq = irq; 87 trig_info->irq = irq;
88 trig->ops = &iio_gpio_trigger_ops; 88 trig->ops = &iio_gpio_trigger_ops;
89 ret = request_irq(irq, iio_gpio_trigger_poll, 89 ret = request_irq(irq, iio_gpio_trigger_poll,
@@ -121,7 +121,7 @@ error_free_completed_registrations:
121 trig2, 121 trig2,
122 &iio_gpio_trigger_list, 122 &iio_gpio_trigger_list,
123 alloc_list) { 123 alloc_list) {
124 trig_info = trig->private_data; 124 trig_info = iio_trigger_get_drvdata(trig);
125 free_irq(gpio_to_irq(trig_info->irq), trig); 125 free_irq(gpio_to_irq(trig_info->irq), trig);
126 kfree(trig_info); 126 kfree(trig_info);
127 iio_trigger_unregister(trig); 127 iio_trigger_unregister(trig);
@@ -140,7 +140,7 @@ static int iio_gpio_trigger_remove(struct platform_device *pdev)
140 trig2, 140 trig2,
141 &iio_gpio_trigger_list, 141 &iio_gpio_trigger_list,
142 alloc_list) { 142 alloc_list) {
143 trig_info = trig->private_data; 143 trig_info = iio_trigger_get_drvdata(trig);
144 iio_trigger_unregister(trig); 144 iio_trigger_unregister(trig);
145 free_irq(trig_info->irq, trig); 145 free_irq(trig_info->irq, trig);
146 kfree(trig_info); 146 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 {
30 30
31static int iio_trig_periodic_rtc_set_state(struct iio_trigger *trig, bool state) 31static int iio_trig_periodic_rtc_set_state(struct iio_trigger *trig, bool state)
32{ 32{
33 struct iio_prtc_trigger_info *trig_info = trig->private_data; 33 struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig);
34 if (trig_info->frequency == 0) 34 if (trig_info->frequency == 0)
35 return -EINVAL; 35 return -EINVAL;
36 printk(KERN_INFO "trigger frequency is %d\n", trig_info->frequency); 36 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,
42 char *buf) 42 char *buf)
43{ 43{
44 struct iio_trigger *trig = to_iio_trigger(dev); 44 struct iio_trigger *trig = to_iio_trigger(dev);
45 struct iio_prtc_trigger_info *trig_info = trig->private_data; 45 struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig);
46 return sprintf(buf, "%u\n", trig_info->frequency); 46 return sprintf(buf, "%u\n", trig_info->frequency);
47} 47}
48 48
@@ -52,7 +52,7 @@ static ssize_t iio_trig_periodic_write_freq(struct device *dev,
52 size_t len) 52 size_t len)
53{ 53{
54 struct iio_trigger *trig = to_iio_trigger(dev); 54 struct iio_trigger *trig = to_iio_trigger(dev);
55 struct iio_prtc_trigger_info *trig_info = trig->private_data; 55 struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig);
56 unsigned long val; 56 unsigned long val;
57 int ret; 57 int ret;
58 58
@@ -124,7 +124,7 @@ static int iio_trig_periodic_rtc_probe(struct platform_device *dev)
124 ret = -ENOMEM; 124 ret = -ENOMEM;
125 goto error_put_trigger_and_remove_from_list; 125 goto error_put_trigger_and_remove_from_list;
126 } 126 }
127 trig->private_data = trig_info; 127 iio_trigger_set_drvdata(trig, trig_info);
128 trig->ops = &iio_prtc_trigger_ops; 128 trig->ops = &iio_prtc_trigger_ops;
129 /* RTC access */ 129 /* RTC access */
130 trig_info->rtc 130 trig_info->rtc
@@ -158,7 +158,7 @@ error_free_completed_registrations:
158 trig2, 158 trig2,
159 &iio_prtc_trigger_list, 159 &iio_prtc_trigger_list,
160 alloc_list) { 160 alloc_list) {
161 trig_info = trig->private_data; 161 trig_info = iio_trigger_get_drvdata(trig);
162 rtc_irq_unregister(trig_info->rtc, &trig_info->task); 162 rtc_irq_unregister(trig_info->rtc, &trig_info->task);
163 rtc_class_close(trig_info->rtc); 163 rtc_class_close(trig_info->rtc);
164 kfree(trig_info); 164 kfree(trig_info);
@@ -176,7 +176,7 @@ static int iio_trig_periodic_rtc_remove(struct platform_device *dev)
176 trig2, 176 trig2,
177 &iio_prtc_trigger_list, 177 &iio_prtc_trigger_list,
178 alloc_list) { 178 alloc_list) {
179 trig_info = trig->private_data; 179 trig_info = iio_trigger_get_drvdata(trig);
180 rtc_irq_unregister(trig_info->rtc, &trig_info->task); 180 rtc_irq_unregister(trig_info->rtc, &trig_info->task);
181 rtc_class_close(trig_info->rtc); 181 rtc_class_close(trig_info->rtc);
182 kfree(trig_info); 182 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,
103 struct device_attribute *attr, const char *buf, size_t count) 103 struct device_attribute *attr, const char *buf, size_t count)
104{ 104{
105 struct iio_trigger *trig = to_iio_trigger(dev); 105 struct iio_trigger *trig = to_iio_trigger(dev);
106 struct iio_sysfs_trig *sysfs_trig = trig->private_data; 106 struct iio_sysfs_trig *sysfs_trig = iio_trigger_get_drvdata(trig);
107 107
108 irq_work_queue(&sysfs_trig->work); 108 irq_work_queue(&sysfs_trig->work);
109 109
@@ -160,7 +160,7 @@ static int iio_sysfs_trigger_probe(int id)
160 t->trig->dev.groups = iio_sysfs_trigger_attr_groups; 160 t->trig->dev.groups = iio_sysfs_trigger_attr_groups;
161 t->trig->ops = &iio_sysfs_trigger_ops; 161 t->trig->ops = &iio_sysfs_trigger_ops;
162 t->trig->dev.parent = &iio_sysfs_trig_dev; 162 t->trig->dev.parent = &iio_sysfs_trig_dev;
163 t->trig->private_data = t; 163 iio_trigger_set_drvdata(t->trig, t);
164 164
165 init_irq_work(&t->work, iio_sysfs_trigger_work); 165 init_irq_work(&t->work, iio_sysfs_trigger_work);
166 166
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
@@ -92,6 +92,30 @@ static inline void iio_trigger_get(struct iio_trigger *trig)
92} 92}
93 93
94/** 94/**
95 * iio_device_set_drvdata() - Set trigger driver data
96 * @trig: IIO trigger structure
97 * @data: Driver specific data
98 *
99 * Allows to attach an arbitrary pointer to an IIO trigger, which can later be
100 * retrieved by iio_trigger_get_drvdata().
101 */
102static inline void iio_trigger_set_drvdata(struct iio_trigger *trig, void *data)
103{
104 trig->private_data = data;
105}
106
107/**
108 * iio_trigger_get_drvdata() - Get trigger driver data
109 * @trig: IIO trigger structure
110 *
111 * Returns the data previously set with iio_trigger_set_drvdata()
112 */
113static inline void *iio_trigger_get_drvdata(struct iio_trigger *trig)
114{
115 return trig->private_data;
116}
117
118/**
95 * iio_trigger_register() - register a trigger with the IIO core 119 * iio_trigger_register() - register a trigger with the IIO core
96 * @trig_info: trigger to be registered 120 * @trig_info: trigger to be registered
97 **/ 121 **/