10 #include <linux/kernel.h>
13 #include <linux/device.h>
15 #include <linux/list.h>
16 #include <linux/slab.h>
54 static struct attribute *iio_trig_dev_attrs[] = {
60 .attrs = iio_trig_dev_attrs,
73 if (trig_info->
id < 0) {
79 (
unsigned long) trig_info->
id);
83 goto error_unregister_id;
131 for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++)
132 if (trig->
subirqs[i].enabled) {
150 for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++)
151 if (trig->
subirqs[i].enabled) {
162 if (trig->
ops->try_reenable(trig))
169 static int iio_trigger_get_irq(
struct iio_trigger *trig)
174 CONFIG_IIO_CONSUMERS_PER_TRIGGER,
183 static void iio_trigger_put_irq(
struct iio_trigger *trig,
int irq)
197 static int iio_trigger_attach_poll_func(
struct iio_trigger *trig,
202 = bitmap_empty(trig->
pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER);
205 __module_get(pf->
indio_dev->info->driver_module);
206 pf->
irq = iio_trigger_get_irq(trig);
211 module_put(pf->
indio_dev->info->driver_module);
215 if (trig->
ops && trig->
ops->set_trigger_state && notinuse) {
216 ret = trig->
ops->set_trigger_state(trig,
true);
218 module_put(pf->
indio_dev->info->driver_module);
224 static int iio_trigger_detach_poll_func(
struct iio_trigger *trig,
229 = (bitmap_weight(trig->
pool,
230 CONFIG_IIO_CONSUMERS_PER_TRIGGER)
232 if (trig->
ops && trig->
ops->set_trigger_state && no_other_users) {
233 ret = trig->
ops->set_trigger_state(trig,
false);
237 iio_trigger_put_irq(trig, pf->
irq);
239 module_put(pf->
indio_dev->info->driver_module);
300 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
303 return sprintf(buf,
"%s\n", indio_dev->
trig->name);
319 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
331 trig = iio_trigger_find_by_name(buf, len);
335 if (trig && indio_dev->
info->validate_trigger) {
336 ret = indio_dev->
info->validate_trigger(indio_dev, trig);
341 if (trig && trig->
ops && trig->
ops->validate_device) {
342 ret = trig->
ops->validate_device(trig, indio_dev);
347 indio_dev->
trig = trig;
349 if (oldtrig && indio_dev->
trig != oldtrig)
350 iio_trigger_put(oldtrig);
352 iio_trigger_get(indio_dev->
trig);
358 iio_trigger_read_current,
359 iio_trigger_write_current);
361 static struct attribute *iio_trigger_consumer_attrs[] = {
362 &dev_attr_current_trigger.attr,
366 static const struct attribute_group iio_trigger_consumer_attr_group = {
368 .attrs = iio_trigger_consumer_attrs,
377 for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) {
388 CONFIG_IIO_CONSUMERS_PER_TRIGGER);
395 .release = iio_trig_release,
396 .groups = iio_trig_attr_groups,
399 static void iio_trig_subirqmask(
struct irq_data *
d)
408 static void iio_trig_subirqunmask(
struct irq_data *
d)
424 trig->
dev.type = &iio_trig_type;
430 = irq_alloc_descs(-1, 0,
431 CONFIG_IIO_CONSUMERS_PER_TRIGGER,
442 CONFIG_IIO_CONSUMERS_PER_TRIGGER);
448 trig->
subirq_chip.irq_unmask = &iio_trig_subirqunmask;
449 for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) {
474 &iio_trigger_consumer_attr_group;
481 iio_trigger_put(indio_dev->
trig);
486 return iio_trigger_attach_poll_func(indio_dev->
trig,
493 return iio_trigger_detach_poll_func(indio_dev->
trig,