Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 1 | /* The industrial I/O core, trigger handling functions |
| 2 | * |
| 3 | * Copyright (c) 2008 Jonathan Cameron |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published by |
| 7 | * the Free Software Foundation. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/kernel.h> |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 11 | #include <linux/idr.h> |
| 12 | #include <linux/err.h> |
| 13 | #include <linux/device.h> |
| 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/list.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 17 | |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 18 | #include <linux/iio/iio.h> |
| 19 | #include <linux/iio/trigger.h> |
Jonathan Cameron | df9c1c4 | 2011-08-12 17:56:03 +0100 | [diff] [blame] | 20 | #include "iio_core.h" |
Jonathan Cameron | 6aea1c3 | 2011-08-24 17:28:38 +0100 | [diff] [blame] | 21 | #include "iio_core_trigger.h" |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 22 | #include <linux/iio/trigger_consumer.h> |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 23 | |
| 24 | /* RFC - Question of approach |
| 25 | * Make the common case (single sensor single trigger) |
| 26 | * simple by starting trigger capture from when first sensors |
| 27 | * is added. |
| 28 | * |
| 29 | * Complex simultaneous start requires use of 'hold' functionality |
| 30 | * of the trigger. (not implemented) |
| 31 | * |
| 32 | * Any other suggestions? |
| 33 | */ |
| 34 | |
Jonathan Cameron | 47c24fd | 2011-08-30 12:41:07 +0100 | [diff] [blame] | 35 | static DEFINE_IDA(iio_trigger_ida); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 36 | |
| 37 | /* Single list of all available triggers */ |
| 38 | static LIST_HEAD(iio_trigger_list); |
| 39 | static DEFINE_MUTEX(iio_trigger_list_lock); |
| 40 | |
| 41 | /** |
Jonathan Cameron | 59c85e8 | 2011-05-18 14:42:22 +0100 | [diff] [blame] | 42 | * iio_trigger_read_name() - retrieve useful identifying name |
Cristina Opriceana | 8e563b0 | 2015-08-06 14:56:02 +0300 | [diff] [blame] | 43 | * @dev: device associated with the iio_trigger |
| 44 | * @attr: pointer to the device_attribute structure that is |
| 45 | * being processed |
| 46 | * @buf: buffer to print the name into |
| 47 | * |
| 48 | * Return: a negative number on failure or the number of written |
| 49 | * characters on success. |
| 50 | */ |
Jonathan Cameron | 59c85e8 | 2011-05-18 14:42:22 +0100 | [diff] [blame] | 51 | static ssize_t iio_trigger_read_name(struct device *dev, |
| 52 | struct device_attribute *attr, |
| 53 | char *buf) |
| 54 | { |
Lars-Peter Clausen | 971ff1d | 2012-06-21 19:11:00 +0200 | [diff] [blame] | 55 | struct iio_trigger *trig = to_iio_trigger(dev); |
Jonathan Cameron | 59c85e8 | 2011-05-18 14:42:22 +0100 | [diff] [blame] | 56 | return sprintf(buf, "%s\n", trig->name); |
| 57 | } |
| 58 | |
| 59 | static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL); |
| 60 | |
Lars-Peter Clausen | 6d459aa | 2012-07-05 10:57:06 +0200 | [diff] [blame] | 61 | static struct attribute *iio_trig_dev_attrs[] = { |
| 62 | &dev_attr_name.attr, |
| 63 | NULL, |
| 64 | }; |
Axel Lin | f59c257 | 2013-12-02 02:57:00 +0000 | [diff] [blame] | 65 | ATTRIBUTE_GROUPS(iio_trig_dev); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 66 | |
Crestez Dan Leonard | 3b8e73e | 2016-05-23 21:40:01 +0300 | [diff] [blame] | 67 | static struct iio_trigger *__iio_trigger_find_by_name(const char *name); |
| 68 | |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 69 | int iio_trigger_register(struct iio_trigger *trig_info) |
| 70 | { |
| 71 | int ret; |
| 72 | |
Jonathan Cameron | ef2d71d | 2016-05-14 18:42:08 +0100 | [diff] [blame] | 73 | /* trig_info->ops is required for the module member */ |
| 74 | if (!trig_info->ops) |
| 75 | return -EINVAL; |
| 76 | |
Jonathan Cameron | 47c24fd | 2011-08-30 12:41:07 +0100 | [diff] [blame] | 77 | trig_info->id = ida_simple_get(&iio_trigger_ida, 0, 0, GFP_KERNEL); |
Hartmut Knaack | 92825ff | 2014-02-16 11:53:00 +0000 | [diff] [blame] | 78 | if (trig_info->id < 0) |
| 79 | return trig_info->id; |
| 80 | |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 81 | /* Set the name used for the sysfs directory etc */ |
| 82 | dev_set_name(&trig_info->dev, "trigger%ld", |
| 83 | (unsigned long) trig_info->id); |
| 84 | |
| 85 | ret = device_add(&trig_info->dev); |
| 86 | if (ret) |
| 87 | goto error_unregister_id; |
| 88 | |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 89 | /* Add to list of available triggers held by the IIO core */ |
| 90 | mutex_lock(&iio_trigger_list_lock); |
Crestez Dan Leonard | 3b8e73e | 2016-05-23 21:40:01 +0300 | [diff] [blame] | 91 | if (__iio_trigger_find_by_name(trig_info->name)) { |
| 92 | pr_err("Duplicate trigger name '%s'\n", trig_info->name); |
| 93 | ret = -EEXIST; |
| 94 | goto error_device_del; |
| 95 | } |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 96 | list_add_tail(&trig_info->list, &iio_trigger_list); |
| 97 | mutex_unlock(&iio_trigger_list_lock); |
| 98 | |
| 99 | return 0; |
| 100 | |
Crestez Dan Leonard | 3b8e73e | 2016-05-23 21:40:01 +0300 | [diff] [blame] | 101 | error_device_del: |
| 102 | mutex_unlock(&iio_trigger_list_lock); |
| 103 | device_del(&trig_info->dev); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 104 | error_unregister_id: |
Jonathan Cameron | 47c24fd | 2011-08-30 12:41:07 +0100 | [diff] [blame] | 105 | ida_simple_remove(&iio_trigger_ida, trig_info->id); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 106 | return ret; |
| 107 | } |
| 108 | EXPORT_SYMBOL(iio_trigger_register); |
| 109 | |
| 110 | void iio_trigger_unregister(struct iio_trigger *trig_info) |
| 111 | { |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 112 | mutex_lock(&iio_trigger_list_lock); |
Jonathan Cameron | 582e548 | 2011-04-15 18:55:54 +0100 | [diff] [blame] | 113 | list_del(&trig_info->list); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 114 | mutex_unlock(&iio_trigger_list_lock); |
| 115 | |
Jonathan Cameron | 47c24fd | 2011-08-30 12:41:07 +0100 | [diff] [blame] | 116 | ida_simple_remove(&iio_trigger_ida, trig_info->id); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 117 | /* Possible issue in here */ |
Jonathan Cameron | 8bade40 | 2013-06-22 12:00:04 +0100 | [diff] [blame] | 118 | device_del(&trig_info->dev); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 119 | } |
| 120 | EXPORT_SYMBOL(iio_trigger_unregister); |
| 121 | |
Crestez Dan Leonard | 3b8e73e | 2016-05-23 21:40:01 +0300 | [diff] [blame] | 122 | /* Search for trigger by name, assuming iio_trigger_list_lock held */ |
| 123 | static struct iio_trigger *__iio_trigger_find_by_name(const char *name) |
| 124 | { |
| 125 | struct iio_trigger *iter; |
| 126 | |
| 127 | list_for_each_entry(iter, &iio_trigger_list, list) |
| 128 | if (!strcmp(iter->name, name)) |
| 129 | return iter; |
| 130 | |
| 131 | return NULL; |
| 132 | } |
| 133 | |
Jonathan Cameron | f6517f2 | 2011-04-15 18:55:53 +0100 | [diff] [blame] | 134 | static struct iio_trigger *iio_trigger_find_by_name(const char *name, |
| 135 | size_t len) |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 136 | { |
Jonathan Cameron | f6517f2 | 2011-04-15 18:55:53 +0100 | [diff] [blame] | 137 | struct iio_trigger *trig = NULL, *iter; |
Michael Hennerich | 7c32785 | 2010-04-26 10:49:10 +0200 | [diff] [blame] | 138 | |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 139 | mutex_lock(&iio_trigger_list_lock); |
Jonathan Cameron | f6517f2 | 2011-04-15 18:55:53 +0100 | [diff] [blame] | 140 | list_for_each_entry(iter, &iio_trigger_list, list) |
| 141 | if (sysfs_streq(iter->name, name)) { |
| 142 | trig = iter; |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 143 | break; |
| 144 | } |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 145 | mutex_unlock(&iio_trigger_list_lock); |
| 146 | |
Jonathan Cameron | f6517f2 | 2011-04-15 18:55:53 +0100 | [diff] [blame] | 147 | return trig; |
Jonathan Cameron | 5f87404 | 2010-05-04 22:20:54 +0100 | [diff] [blame] | 148 | } |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 149 | |
Peter Meerwald | 398fd22 | 2014-12-06 06:46:00 +0000 | [diff] [blame] | 150 | void iio_trigger_poll(struct iio_trigger *trig) |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 151 | { |
Jonathan Cameron | d96d133 | 2011-05-18 14:41:18 +0100 | [diff] [blame] | 152 | int i; |
Lars-Peter Clausen | a1a8e1d | 2013-07-16 15:28:00 +0100 | [diff] [blame] | 153 | |
| 154 | if (!atomic_read(&trig->use_count)) { |
| 155 | atomic_set(&trig->use_count, CONFIG_IIO_CONSUMERS_PER_TRIGGER); |
| 156 | |
| 157 | for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { |
| 158 | if (trig->subirqs[i].enabled) |
Jonathan Cameron | d96d133 | 2011-05-18 14:41:18 +0100 | [diff] [blame] | 159 | generic_handle_irq(trig->subirq_base + i); |
Lars-Peter Clausen | a1a8e1d | 2013-07-16 15:28:00 +0100 | [diff] [blame] | 160 | else |
| 161 | iio_trigger_notify_done(trig); |
| 162 | } |
| 163 | } |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 164 | } |
| 165 | EXPORT_SYMBOL(iio_trigger_poll); |
| 166 | |
Jonathan Cameron | 8384d95 | 2011-05-18 14:41:21 +0100 | [diff] [blame] | 167 | irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private) |
| 168 | { |
Peter Meerwald | 398fd22 | 2014-12-06 06:46:00 +0000 | [diff] [blame] | 169 | iio_trigger_poll(private); |
Jonathan Cameron | 8384d95 | 2011-05-18 14:41:21 +0100 | [diff] [blame] | 170 | return IRQ_HANDLED; |
| 171 | } |
| 172 | EXPORT_SYMBOL(iio_trigger_generic_data_rdy_poll); |
| 173 | |
Peter Meerwald | 398fd22 | 2014-12-06 06:46:00 +0000 | [diff] [blame] | 174 | void iio_trigger_poll_chained(struct iio_trigger *trig) |
Jonathan Cameron | 1f78568 | 2011-05-18 14:42:11 +0100 | [diff] [blame] | 175 | { |
| 176 | int i; |
Lars-Peter Clausen | a1a8e1d | 2013-07-16 15:28:00 +0100 | [diff] [blame] | 177 | |
| 178 | if (!atomic_read(&trig->use_count)) { |
| 179 | atomic_set(&trig->use_count, CONFIG_IIO_CONSUMERS_PER_TRIGGER); |
| 180 | |
| 181 | for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { |
| 182 | if (trig->subirqs[i].enabled) |
Jonathan Cameron | 1f78568 | 2011-05-18 14:42:11 +0100 | [diff] [blame] | 183 | handle_nested_irq(trig->subirq_base + i); |
Lars-Peter Clausen | a1a8e1d | 2013-07-16 15:28:00 +0100 | [diff] [blame] | 184 | else |
| 185 | iio_trigger_notify_done(trig); |
| 186 | } |
| 187 | } |
Jonathan Cameron | 1f78568 | 2011-05-18 14:42:11 +0100 | [diff] [blame] | 188 | } |
| 189 | EXPORT_SYMBOL(iio_trigger_poll_chained); |
| 190 | |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 191 | void iio_trigger_notify_done(struct iio_trigger *trig) |
| 192 | { |
Jonathan Cameron | ef2d71d | 2016-05-14 18:42:08 +0100 | [diff] [blame] | 193 | if (atomic_dec_and_test(&trig->use_count) && trig->ops->try_reenable) |
Jonathan Cameron | e69616b | 2011-10-26 17:27:39 +0100 | [diff] [blame] | 194 | if (trig->ops->try_reenable(trig)) |
Peter Meerwald | 860c9c5 | 2013-02-04 11:36:00 +0000 | [diff] [blame] | 195 | /* Missed an interrupt so launch new poll now */ |
Peter Meerwald | 398fd22 | 2014-12-06 06:46:00 +0000 | [diff] [blame] | 196 | iio_trigger_poll(trig); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 197 | } |
| 198 | EXPORT_SYMBOL(iio_trigger_notify_done); |
| 199 | |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 200 | /* Trigger Consumer related functions */ |
Jonathan Cameron | 208b813 | 2011-08-24 17:28:41 +0100 | [diff] [blame] | 201 | static int iio_trigger_get_irq(struct iio_trigger *trig) |
| 202 | { |
| 203 | int ret; |
| 204 | mutex_lock(&trig->pool_lock); |
| 205 | ret = bitmap_find_free_region(trig->pool, |
| 206 | CONFIG_IIO_CONSUMERS_PER_TRIGGER, |
| 207 | ilog2(1)); |
| 208 | mutex_unlock(&trig->pool_lock); |
| 209 | if (ret >= 0) |
| 210 | ret += trig->subirq_base; |
| 211 | |
| 212 | return ret; |
| 213 | } |
| 214 | |
| 215 | static void iio_trigger_put_irq(struct iio_trigger *trig, int irq) |
| 216 | { |
| 217 | mutex_lock(&trig->pool_lock); |
| 218 | clear_bit(irq - trig->subirq_base, trig->pool); |
| 219 | mutex_unlock(&trig->pool_lock); |
| 220 | } |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 221 | |
| 222 | /* Complexity in here. With certain triggers (datardy) an acknowledgement |
| 223 | * may be needed if the pollfuncs do not include the data read for the |
| 224 | * triggering device. |
| 225 | * This is not currently handled. Alternative of not enabling trigger unless |
| 226 | * the relevant function is in there may be the best option. |
| 227 | */ |
Peter Meerwald | 860c9c5 | 2013-02-04 11:36:00 +0000 | [diff] [blame] | 228 | /* Worth protecting against double additions? */ |
Jonathan Cameron | 208b813 | 2011-08-24 17:28:41 +0100 | [diff] [blame] | 229 | static int iio_trigger_attach_poll_func(struct iio_trigger *trig, |
| 230 | struct iio_poll_func *pf) |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 231 | { |
| 232 | int ret = 0; |
Jonathan Cameron | 51c060a | 2011-05-18 14:41:42 +0100 | [diff] [blame] | 233 | bool notinuse |
| 234 | = bitmap_empty(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 235 | |
Peter Meerwald | 860c9c5 | 2013-02-04 11:36:00 +0000 | [diff] [blame] | 236 | /* Prevent the module from being removed whilst attached to a trigger */ |
Jonathan Cameron | f60c4a0 | 2011-08-24 17:28:37 +0100 | [diff] [blame] | 237 | __module_get(pf->indio_dev->info->driver_module); |
Crestez Dan Leonard | 9954382 | 2016-05-03 15:27:09 +0300 | [diff] [blame] | 238 | |
| 239 | /* Get irq number */ |
Jonathan Cameron | 51c060a | 2011-05-18 14:41:42 +0100 | [diff] [blame] | 240 | pf->irq = iio_trigger_get_irq(trig); |
Crestez Dan Leonard | 9954382 | 2016-05-03 15:27:09 +0300 | [diff] [blame] | 241 | if (pf->irq < 0) |
| 242 | goto out_put_module; |
| 243 | |
| 244 | /* Request irq */ |
Jonathan Cameron | 51c060a | 2011-05-18 14:41:42 +0100 | [diff] [blame] | 245 | ret = request_threaded_irq(pf->irq, pf->h, pf->thread, |
| 246 | pf->type, pf->name, |
| 247 | pf); |
Crestez Dan Leonard | 9954382 | 2016-05-03 15:27:09 +0300 | [diff] [blame] | 248 | if (ret < 0) |
| 249 | goto out_put_irq; |
Jonathan Cameron | 5dd72ec | 2011-10-26 17:27:41 +0100 | [diff] [blame] | 250 | |
Crestez Dan Leonard | 9954382 | 2016-05-03 15:27:09 +0300 | [diff] [blame] | 251 | /* Enable trigger in driver */ |
Jonathan Cameron | ef2d71d | 2016-05-14 18:42:08 +0100 | [diff] [blame] | 252 | if (trig->ops->set_trigger_state && notinuse) { |
Jonathan Cameron | d29f73d | 2011-08-12 17:08:38 +0100 | [diff] [blame] | 253 | ret = trig->ops->set_trigger_state(trig, true); |
Jonathan Cameron | 5dd72ec | 2011-10-26 17:27:41 +0100 | [diff] [blame] | 254 | if (ret < 0) |
Crestez Dan Leonard | 9954382 | 2016-05-03 15:27:09 +0300 | [diff] [blame] | 255 | goto out_free_irq; |
Jonathan Cameron | 5dd72ec | 2011-10-26 17:27:41 +0100 | [diff] [blame] | 256 | } |
Jonathan Cameron | d96d133 | 2011-05-18 14:41:18 +0100 | [diff] [blame] | 257 | |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 258 | return ret; |
Crestez Dan Leonard | 9954382 | 2016-05-03 15:27:09 +0300 | [diff] [blame] | 259 | |
| 260 | out_free_irq: |
| 261 | free_irq(pf->irq, pf); |
| 262 | out_put_irq: |
| 263 | iio_trigger_put_irq(trig, pf->irq); |
| 264 | out_put_module: |
| 265 | module_put(pf->indio_dev->info->driver_module); |
| 266 | return ret; |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 267 | } |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 268 | |
Peter Meerwald | 034bd7b | 2012-07-02 23:43:47 +0200 | [diff] [blame] | 269 | static int iio_trigger_detach_poll_func(struct iio_trigger *trig, |
Jonathan Cameron | 208b813 | 2011-08-24 17:28:41 +0100 | [diff] [blame] | 270 | struct iio_poll_func *pf) |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 271 | { |
Jonathan Cameron | 51c060a | 2011-05-18 14:41:42 +0100 | [diff] [blame] | 272 | int ret = 0; |
| 273 | bool no_other_users |
| 274 | = (bitmap_weight(trig->pool, |
| 275 | CONFIG_IIO_CONSUMERS_PER_TRIGGER) |
| 276 | == 1); |
Jonathan Cameron | ef2d71d | 2016-05-14 18:42:08 +0100 | [diff] [blame] | 277 | if (trig->ops->set_trigger_state && no_other_users) { |
Jonathan Cameron | d29f73d | 2011-08-12 17:08:38 +0100 | [diff] [blame] | 278 | ret = trig->ops->set_trigger_state(trig, false); |
Jonathan Cameron | 51c060a | 2011-05-18 14:41:42 +0100 | [diff] [blame] | 279 | if (ret) |
Hartmut Knaack | 92825ff | 2014-02-16 11:53:00 +0000 | [diff] [blame] | 280 | return ret; |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 281 | } |
Jonathan Cameron | 51c060a | 2011-05-18 14:41:42 +0100 | [diff] [blame] | 282 | iio_trigger_put_irq(trig, pf->irq); |
| 283 | free_irq(pf->irq, pf); |
Jonathan Cameron | f60c4a0 | 2011-08-24 17:28:37 +0100 | [diff] [blame] | 284 | module_put(pf->indio_dev->info->driver_module); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 285 | |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 286 | return ret; |
| 287 | } |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 288 | |
Jonathan Cameron | d96d133 | 2011-05-18 14:41:18 +0100 | [diff] [blame] | 289 | irqreturn_t iio_pollfunc_store_time(int irq, void *p) |
| 290 | { |
| 291 | struct iio_poll_func *pf = p; |
Gregor Boirie | bc2b7da | 2016-03-09 19:05:49 +0100 | [diff] [blame] | 292 | pf->timestamp = iio_get_time_ns(pf->indio_dev); |
Jonathan Cameron | d96d133 | 2011-05-18 14:41:18 +0100 | [diff] [blame] | 293 | return IRQ_WAKE_THREAD; |
| 294 | } |
| 295 | EXPORT_SYMBOL(iio_pollfunc_store_time); |
| 296 | |
Jonathan Cameron | 21b185f | 2011-05-18 14:42:32 +0100 | [diff] [blame] | 297 | struct iio_poll_func |
| 298 | *iio_alloc_pollfunc(irqreturn_t (*h)(int irq, void *p), |
| 299 | irqreturn_t (*thread)(int irq, void *p), |
| 300 | int type, |
Jonathan Cameron | e65bc6a | 2011-08-24 17:28:36 +0100 | [diff] [blame] | 301 | struct iio_dev *indio_dev, |
Jonathan Cameron | 21b185f | 2011-05-18 14:42:32 +0100 | [diff] [blame] | 302 | const char *fmt, |
| 303 | ...) |
| 304 | { |
| 305 | va_list vargs; |
| 306 | struct iio_poll_func *pf; |
| 307 | |
| 308 | pf = kmalloc(sizeof *pf, GFP_KERNEL); |
| 309 | if (pf == NULL) |
| 310 | return NULL; |
| 311 | va_start(vargs, fmt); |
| 312 | pf->name = kvasprintf(GFP_KERNEL, fmt, vargs); |
| 313 | va_end(vargs); |
| 314 | if (pf->name == NULL) { |
| 315 | kfree(pf); |
| 316 | return NULL; |
| 317 | } |
| 318 | pf->h = h; |
| 319 | pf->thread = thread; |
| 320 | pf->type = type; |
Jonathan Cameron | e65bc6a | 2011-08-24 17:28:36 +0100 | [diff] [blame] | 321 | pf->indio_dev = indio_dev; |
Jonathan Cameron | 21b185f | 2011-05-18 14:42:32 +0100 | [diff] [blame] | 322 | |
| 323 | return pf; |
| 324 | } |
| 325 | EXPORT_SYMBOL_GPL(iio_alloc_pollfunc); |
| 326 | |
| 327 | void iio_dealloc_pollfunc(struct iio_poll_func *pf) |
| 328 | { |
| 329 | kfree(pf->name); |
| 330 | kfree(pf); |
| 331 | } |
| 332 | EXPORT_SYMBOL_GPL(iio_dealloc_pollfunc); |
| 333 | |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 334 | /** |
Peter Meerwald | 860c9c5 | 2013-02-04 11:36:00 +0000 | [diff] [blame] | 335 | * iio_trigger_read_current() - trigger consumer sysfs query current trigger |
Cristina Opriceana | 8e563b0 | 2015-08-06 14:56:02 +0300 | [diff] [blame] | 336 | * @dev: device associated with an industrial I/O device |
| 337 | * @attr: pointer to the device_attribute structure that |
| 338 | * is being processed |
| 339 | * @buf: buffer where the current trigger name will be printed into |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 340 | * |
| 341 | * For trigger consumers the current_trigger interface allows the trigger |
| 342 | * used by the device to be queried. |
Cristina Opriceana | 8e563b0 | 2015-08-06 14:56:02 +0300 | [diff] [blame] | 343 | * |
| 344 | * Return: a negative number on failure, the number of characters written |
| 345 | * on success or 0 if no trigger is available |
| 346 | */ |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 347 | static ssize_t iio_trigger_read_current(struct device *dev, |
| 348 | struct device_attribute *attr, |
| 349 | char *buf) |
| 350 | { |
Lars-Peter Clausen | e53f5ac | 2012-05-12 15:39:33 +0200 | [diff] [blame] | 351 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Jonathan Cameron | cb6c89a | 2011-08-24 17:28:40 +0100 | [diff] [blame] | 352 | |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 353 | if (indio_dev->trig) |
| 354 | return sprintf(buf, "%s\n", indio_dev->trig->name); |
Jonathan Cameron | cb6c89a | 2011-08-24 17:28:40 +0100 | [diff] [blame] | 355 | return 0; |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | /** |
Peter Meerwald | 860c9c5 | 2013-02-04 11:36:00 +0000 | [diff] [blame] | 359 | * iio_trigger_write_current() - trigger consumer sysfs set current trigger |
Cristina Opriceana | 8e563b0 | 2015-08-06 14:56:02 +0300 | [diff] [blame] | 360 | * @dev: device associated with an industrial I/O device |
| 361 | * @attr: device attribute that is being processed |
| 362 | * @buf: string buffer that holds the name of the trigger |
| 363 | * @len: length of the trigger name held by buf |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 364 | * |
| 365 | * For trigger consumers the current_trigger interface allows the trigger |
Peter Meerwald | 17666ef | 2013-11-12 21:49:00 +0000 | [diff] [blame] | 366 | * used for this device to be specified at run time based on the trigger's |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 367 | * name. |
Cristina Opriceana | 8e563b0 | 2015-08-06 14:56:02 +0300 | [diff] [blame] | 368 | * |
| 369 | * Return: negative error code on failure or length of the buffer |
| 370 | * on success |
| 371 | */ |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 372 | static ssize_t iio_trigger_write_current(struct device *dev, |
| 373 | struct device_attribute *attr, |
| 374 | const char *buf, |
| 375 | size_t len) |
| 376 | { |
Lars-Peter Clausen | e53f5ac | 2012-05-12 15:39:33 +0200 | [diff] [blame] | 377 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 378 | struct iio_trigger *oldtrig = indio_dev->trig; |
Michael Hennerich | 43a4360 | 2011-06-27 13:07:09 +0100 | [diff] [blame] | 379 | struct iio_trigger *trig; |
| 380 | int ret; |
| 381 | |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 382 | mutex_lock(&indio_dev->mlock); |
| 383 | if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { |
| 384 | mutex_unlock(&indio_dev->mlock); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 385 | return -EBUSY; |
| 386 | } |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 387 | mutex_unlock(&indio_dev->mlock); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 388 | |
Michael Hennerich | 43a4360 | 2011-06-27 13:07:09 +0100 | [diff] [blame] | 389 | trig = iio_trigger_find_by_name(buf, len); |
Jonathan Cameron | 5dd72ec | 2011-10-26 17:27:41 +0100 | [diff] [blame] | 390 | if (oldtrig == trig) |
| 391 | return len; |
Michael Hennerich | 43a4360 | 2011-06-27 13:07:09 +0100 | [diff] [blame] | 392 | |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 393 | if (trig && indio_dev->info->validate_trigger) { |
| 394 | ret = indio_dev->info->validate_trigger(indio_dev, trig); |
Michael Hennerich | 43a4360 | 2011-06-27 13:07:09 +0100 | [diff] [blame] | 395 | if (ret) |
| 396 | return ret; |
| 397 | } |
| 398 | |
Jonathan Cameron | ef2d71d | 2016-05-14 18:42:08 +0100 | [diff] [blame] | 399 | if (trig && trig->ops->validate_device) { |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 400 | ret = trig->ops->validate_device(trig, indio_dev); |
Michael Hennerich | 43a4360 | 2011-06-27 13:07:09 +0100 | [diff] [blame] | 401 | if (ret) |
| 402 | return ret; |
| 403 | } |
| 404 | |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 405 | indio_dev->trig = trig; |
Michael Hennerich | 43a4360 | 2011-06-27 13:07:09 +0100 | [diff] [blame] | 406 | |
Vladimir Barinov | 735ad07 | 2015-08-20 22:37:39 +0300 | [diff] [blame] | 407 | if (oldtrig) { |
| 408 | if (indio_dev->modes & INDIO_EVENT_TRIGGERED) |
| 409 | iio_trigger_detach_poll_func(oldtrig, |
| 410 | indio_dev->pollfunc_event); |
Lars-Peter Clausen | 7cbb753 | 2012-04-26 13:35:01 +0200 | [diff] [blame] | 411 | iio_trigger_put(oldtrig); |
Vladimir Barinov | 735ad07 | 2015-08-20 22:37:39 +0300 | [diff] [blame] | 412 | } |
| 413 | if (indio_dev->trig) { |
Lars-Peter Clausen | 7cbb753 | 2012-04-26 13:35:01 +0200 | [diff] [blame] | 414 | iio_trigger_get(indio_dev->trig); |
Vladimir Barinov | 735ad07 | 2015-08-20 22:37:39 +0300 | [diff] [blame] | 415 | if (indio_dev->modes & INDIO_EVENT_TRIGGERED) |
| 416 | iio_trigger_attach_poll_func(indio_dev->trig, |
| 417 | indio_dev->pollfunc_event); |
| 418 | } |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 419 | |
| 420 | return len; |
| 421 | } |
| 422 | |
Greg Kroah-Hartman | 74112d3 | 2010-05-04 22:34:00 -0700 | [diff] [blame] | 423 | static DEVICE_ATTR(current_trigger, S_IRUGO | S_IWUSR, |
| 424 | iio_trigger_read_current, |
| 425 | iio_trigger_write_current); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 426 | |
| 427 | static struct attribute *iio_trigger_consumer_attrs[] = { |
| 428 | &dev_attr_current_trigger.attr, |
| 429 | NULL, |
| 430 | }; |
| 431 | |
| 432 | static const struct attribute_group iio_trigger_consumer_attr_group = { |
| 433 | .name = "trigger", |
| 434 | .attrs = iio_trigger_consumer_attrs, |
| 435 | }; |
| 436 | |
| 437 | static void iio_trig_release(struct device *device) |
| 438 | { |
| 439 | struct iio_trigger *trig = to_iio_trigger(device); |
Jonathan Cameron | d96d133 | 2011-05-18 14:41:18 +0100 | [diff] [blame] | 440 | int i; |
| 441 | |
| 442 | if (trig->subirq_base) { |
| 443 | for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { |
| 444 | irq_modify_status(trig->subirq_base + i, |
| 445 | IRQ_NOAUTOEN, |
| 446 | IRQ_NOREQUEST | IRQ_NOPROBE); |
| 447 | irq_set_chip(trig->subirq_base + i, |
| 448 | NULL); |
| 449 | irq_set_handler(trig->subirq_base + i, |
| 450 | NULL); |
| 451 | } |
| 452 | |
| 453 | irq_free_descs(trig->subirq_base, |
| 454 | CONFIG_IIO_CONSUMERS_PER_TRIGGER); |
| 455 | } |
Jonathan Cameron | 59c85e8 | 2011-05-18 14:42:22 +0100 | [diff] [blame] | 456 | kfree(trig->name); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 457 | kfree(trig); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static struct device_type iio_trig_type = { |
| 461 | .release = iio_trig_release, |
Axel Lin | f59c257 | 2013-12-02 02:57:00 +0000 | [diff] [blame] | 462 | .groups = iio_trig_dev_groups, |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 463 | }; |
| 464 | |
Jonathan Cameron | d96d133 | 2011-05-18 14:41:18 +0100 | [diff] [blame] | 465 | static void iio_trig_subirqmask(struct irq_data *d) |
| 466 | { |
| 467 | struct irq_chip *chip = irq_data_get_irq_chip(d); |
| 468 | struct iio_trigger *trig |
| 469 | = container_of(chip, |
| 470 | struct iio_trigger, subirq_chip); |
| 471 | trig->subirqs[d->irq - trig->subirq_base].enabled = false; |
| 472 | } |
| 473 | |
| 474 | static void iio_trig_subirqunmask(struct irq_data *d) |
| 475 | { |
| 476 | struct irq_chip *chip = irq_data_get_irq_chip(d); |
| 477 | struct iio_trigger *trig |
| 478 | = container_of(chip, |
| 479 | struct iio_trigger, subirq_chip); |
| 480 | trig->subirqs[d->irq - trig->subirq_base].enabled = true; |
| 481 | } |
| 482 | |
Jacek Anaszewski | d536321 | 2013-08-16 14:11:00 +0100 | [diff] [blame] | 483 | static struct iio_trigger *viio_trigger_alloc(const char *fmt, va_list vargs) |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 484 | { |
| 485 | struct iio_trigger *trig; |
| 486 | trig = kzalloc(sizeof *trig, GFP_KERNEL); |
| 487 | if (trig) { |
Jonathan Cameron | d96d133 | 2011-05-18 14:41:18 +0100 | [diff] [blame] | 488 | int i; |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 489 | trig->dev.type = &iio_trig_type; |
Jonathan Cameron | 5aaaeba | 2010-05-04 14:43:00 +0100 | [diff] [blame] | 490 | trig->dev.bus = &iio_bus_type; |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 491 | device_initialize(&trig->dev); |
Jonathan Cameron | d96d133 | 2011-05-18 14:41:18 +0100 | [diff] [blame] | 492 | |
Jonathan Cameron | 59c85e8 | 2011-05-18 14:42:22 +0100 | [diff] [blame] | 493 | mutex_init(&trig->pool_lock); |
| 494 | trig->subirq_base |
| 495 | = irq_alloc_descs(-1, 0, |
| 496 | CONFIG_IIO_CONSUMERS_PER_TRIGGER, |
| 497 | 0); |
| 498 | if (trig->subirq_base < 0) { |
| 499 | kfree(trig); |
| 500 | return NULL; |
| 501 | } |
Jacek Anaszewski | d536321 | 2013-08-16 14:11:00 +0100 | [diff] [blame] | 502 | |
Jonathan Cameron | 59c85e8 | 2011-05-18 14:42:22 +0100 | [diff] [blame] | 503 | trig->name = kvasprintf(GFP_KERNEL, fmt, vargs); |
Jonathan Cameron | 59c85e8 | 2011-05-18 14:42:22 +0100 | [diff] [blame] | 504 | if (trig->name == NULL) { |
| 505 | irq_free_descs(trig->subirq_base, |
| 506 | CONFIG_IIO_CONSUMERS_PER_TRIGGER); |
| 507 | kfree(trig); |
| 508 | return NULL; |
| 509 | } |
| 510 | trig->subirq_chip.name = trig->name; |
| 511 | trig->subirq_chip.irq_mask = &iio_trig_subirqmask; |
| 512 | trig->subirq_chip.irq_unmask = &iio_trig_subirqunmask; |
| 513 | for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { |
| 514 | irq_set_chip(trig->subirq_base + i, |
| 515 | &trig->subirq_chip); |
| 516 | irq_set_handler(trig->subirq_base + i, |
| 517 | &handle_simple_irq); |
| 518 | irq_modify_status(trig->subirq_base + i, |
| 519 | IRQ_NOREQUEST | IRQ_NOAUTOEN, |
| 520 | IRQ_NOPROBE); |
Jonathan Cameron | d96d133 | 2011-05-18 14:41:18 +0100 | [diff] [blame] | 521 | } |
Jonathan Cameron | 5f9c035 | 2011-08-24 17:28:33 +0100 | [diff] [blame] | 522 | get_device(&trig->dev); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 523 | } |
Jacek Anaszewski | d536321 | 2013-08-16 14:11:00 +0100 | [diff] [blame] | 524 | |
| 525 | return trig; |
| 526 | } |
| 527 | |
| 528 | struct iio_trigger *iio_trigger_alloc(const char *fmt, ...) |
| 529 | { |
| 530 | struct iio_trigger *trig; |
| 531 | va_list vargs; |
| 532 | |
| 533 | va_start(vargs, fmt); |
| 534 | trig = viio_trigger_alloc(fmt, vargs); |
| 535 | va_end(vargs); |
| 536 | |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 537 | return trig; |
| 538 | } |
Lars-Peter Clausen | 7cbb753 | 2012-04-26 13:35:01 +0200 | [diff] [blame] | 539 | EXPORT_SYMBOL(iio_trigger_alloc); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 540 | |
Lars-Peter Clausen | 7cbb753 | 2012-04-26 13:35:01 +0200 | [diff] [blame] | 541 | void iio_trigger_free(struct iio_trigger *trig) |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 542 | { |
| 543 | if (trig) |
| 544 | put_device(&trig->dev); |
| 545 | } |
Lars-Peter Clausen | 7cbb753 | 2012-04-26 13:35:01 +0200 | [diff] [blame] | 546 | EXPORT_SYMBOL(iio_trigger_free); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 547 | |
Jacek Anaszewski | d536321 | 2013-08-16 14:11:00 +0100 | [diff] [blame] | 548 | static void devm_iio_trigger_release(struct device *dev, void *res) |
| 549 | { |
| 550 | iio_trigger_free(*(struct iio_trigger **)res); |
| 551 | } |
| 552 | |
| 553 | static int devm_iio_trigger_match(struct device *dev, void *res, void *data) |
| 554 | { |
| 555 | struct iio_trigger **r = res; |
| 556 | |
| 557 | if (!r || !*r) { |
| 558 | WARN_ON(!r || !*r); |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | return *r == data; |
| 563 | } |
| 564 | |
Sachin Kamat | a7e57dc | 2013-10-29 11:39:00 +0000 | [diff] [blame] | 565 | /** |
| 566 | * devm_iio_trigger_alloc - Resource-managed iio_trigger_alloc() |
| 567 | * @dev: Device to allocate iio_trigger for |
| 568 | * @fmt: trigger name format. If it includes format |
| 569 | * specifiers, the additional arguments following |
| 570 | * format are formatted and inserted in the resulting |
| 571 | * string replacing their respective specifiers. |
| 572 | * |
| 573 | * Managed iio_trigger_alloc. iio_trigger allocated with this function is |
| 574 | * automatically freed on driver detach. |
| 575 | * |
| 576 | * If an iio_trigger allocated with this function needs to be freed separately, |
| 577 | * devm_iio_trigger_free() must be used. |
| 578 | * |
| 579 | * RETURNS: |
| 580 | * Pointer to allocated iio_trigger on success, NULL on failure. |
| 581 | */ |
Jacek Anaszewski | d536321 | 2013-08-16 14:11:00 +0100 | [diff] [blame] | 582 | struct iio_trigger *devm_iio_trigger_alloc(struct device *dev, |
| 583 | const char *fmt, ...) |
| 584 | { |
| 585 | struct iio_trigger **ptr, *trig; |
| 586 | va_list vargs; |
| 587 | |
| 588 | ptr = devres_alloc(devm_iio_trigger_release, sizeof(*ptr), |
| 589 | GFP_KERNEL); |
| 590 | if (!ptr) |
| 591 | return NULL; |
| 592 | |
| 593 | /* use raw alloc_dr for kmalloc caller tracing */ |
| 594 | va_start(vargs, fmt); |
| 595 | trig = viio_trigger_alloc(fmt, vargs); |
| 596 | va_end(vargs); |
| 597 | if (trig) { |
| 598 | *ptr = trig; |
| 599 | devres_add(dev, ptr); |
| 600 | } else { |
| 601 | devres_free(ptr); |
| 602 | } |
| 603 | |
| 604 | return trig; |
| 605 | } |
| 606 | EXPORT_SYMBOL_GPL(devm_iio_trigger_alloc); |
| 607 | |
Sachin Kamat | a7e57dc | 2013-10-29 11:39:00 +0000 | [diff] [blame] | 608 | /** |
| 609 | * devm_iio_trigger_free - Resource-managed iio_trigger_free() |
| 610 | * @dev: Device this iio_dev belongs to |
| 611 | * @iio_trig: the iio_trigger associated with the device |
| 612 | * |
| 613 | * Free iio_trigger allocated with devm_iio_trigger_alloc(). |
| 614 | */ |
Jacek Anaszewski | d536321 | 2013-08-16 14:11:00 +0100 | [diff] [blame] | 615 | void devm_iio_trigger_free(struct device *dev, struct iio_trigger *iio_trig) |
| 616 | { |
| 617 | int rc; |
| 618 | |
| 619 | rc = devres_release(dev, devm_iio_trigger_release, |
| 620 | devm_iio_trigger_match, iio_trig); |
| 621 | WARN_ON(rc); |
| 622 | } |
| 623 | EXPORT_SYMBOL_GPL(devm_iio_trigger_free); |
| 624 | |
Jonathan Cameron | 67be8e3 | 2011-10-26 17:27:38 +0100 | [diff] [blame] | 625 | void iio_device_register_trigger_consumer(struct iio_dev *indio_dev) |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 626 | { |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 627 | indio_dev->groups[indio_dev->groupcounter++] = |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 628 | &iio_trigger_consumer_attr_group; |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 629 | } |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 630 | |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 631 | void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev) |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 632 | { |
Peter Meerwald | 860c9c5 | 2013-02-04 11:36:00 +0000 | [diff] [blame] | 633 | /* Clean up an associated but not attached trigger reference */ |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 634 | if (indio_dev->trig) |
Lars-Peter Clausen | 7cbb753 | 2012-04-26 13:35:01 +0200 | [diff] [blame] | 635 | iio_trigger_put(indio_dev->trig); |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 636 | } |
Jonathan Cameron | 1637db4 | 2009-08-18 18:06:26 +0100 | [diff] [blame] | 637 | |
Jonathan Cameron | 3b99fb7 | 2011-09-21 11:15:53 +0100 | [diff] [blame] | 638 | int iio_triggered_buffer_postenable(struct iio_dev *indio_dev) |
Jonathan Cameron | c3db00c | 2010-07-11 16:39:10 +0100 | [diff] [blame] | 639 | { |
Jonathan Cameron | 67be8e3 | 2011-10-26 17:27:38 +0100 | [diff] [blame] | 640 | return iio_trigger_attach_poll_func(indio_dev->trig, |
| 641 | indio_dev->pollfunc); |
Jonathan Cameron | c3db00c | 2010-07-11 16:39:10 +0100 | [diff] [blame] | 642 | } |
Jonathan Cameron | 3b99fb7 | 2011-09-21 11:15:53 +0100 | [diff] [blame] | 643 | EXPORT_SYMBOL(iio_triggered_buffer_postenable); |
Jonathan Cameron | c3db00c | 2010-07-11 16:39:10 +0100 | [diff] [blame] | 644 | |
Jonathan Cameron | 3b99fb7 | 2011-09-21 11:15:53 +0100 | [diff] [blame] | 645 | int iio_triggered_buffer_predisable(struct iio_dev *indio_dev) |
Jonathan Cameron | c3db00c | 2010-07-11 16:39:10 +0100 | [diff] [blame] | 646 | { |
Peter Meerwald | 034bd7b | 2012-07-02 23:43:47 +0200 | [diff] [blame] | 647 | return iio_trigger_detach_poll_func(indio_dev->trig, |
Jonathan Cameron | 67be8e3 | 2011-10-26 17:27:38 +0100 | [diff] [blame] | 648 | indio_dev->pollfunc); |
Jonathan Cameron | c3db00c | 2010-07-11 16:39:10 +0100 | [diff] [blame] | 649 | } |
Jonathan Cameron | 3b99fb7 | 2011-09-21 11:15:53 +0100 | [diff] [blame] | 650 | EXPORT_SYMBOL(iio_triggered_buffer_predisable); |