1 // SPDX-License-Identifier: GPL-2.0-only
3 * Industrial I/O - generic interrupt based trigger support
5 * Copyright (c) 2008-2013 Jonathan Cameron
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/interrupt.h>
12 #include <linux/slab.h>
14 #include <linux/iio/iio.h>
15 #include <linux/iio/trigger.h>
18 struct iio_interrupt_trigger_info
{
22 static irqreturn_t
iio_interrupt_trigger_poll(int irq
, void *private)
24 iio_trigger_poll(private);
28 static const struct iio_trigger_ops iio_interrupt_trigger_ops
= {
31 static int iio_interrupt_trigger_probe(struct platform_device
*pdev
)
33 struct iio_interrupt_trigger_info
*trig_info
;
34 struct iio_trigger
*trig
;
35 unsigned long irqflags
;
36 struct resource
*irq_res
;
39 irq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
44 irqflags
= (irq_res
->flags
& IRQF_TRIGGER_MASK
) | IRQF_SHARED
;
48 trig
= iio_trigger_alloc("irqtrig%d", irq
);
54 trig_info
= kzalloc(sizeof(*trig_info
), GFP_KERNEL
);
57 goto error_free_trigger
;
59 iio_trigger_set_drvdata(trig
, trig_info
);
61 trig
->ops
= &iio_interrupt_trigger_ops
;
62 ret
= request_irq(irq
, iio_interrupt_trigger_poll
,
63 irqflags
, trig
->name
, trig
);
66 "request IRQ-%d failed", irq
);
67 goto error_free_trig_info
;
70 ret
= iio_trigger_register(trig
);
72 goto error_release_irq
;
73 platform_set_drvdata(pdev
, trig
);
77 /* First clean up the partly allocated trigger */
83 iio_trigger_free(trig
);
88 static int iio_interrupt_trigger_remove(struct platform_device
*pdev
)
90 struct iio_trigger
*trig
;
91 struct iio_interrupt_trigger_info
*trig_info
;
93 trig
= platform_get_drvdata(pdev
);
94 trig_info
= iio_trigger_get_drvdata(trig
);
95 iio_trigger_unregister(trig
);
96 free_irq(trig_info
->irq
, trig
);
98 iio_trigger_free(trig
);
103 static struct platform_driver iio_interrupt_trigger_driver
= {
104 .probe
= iio_interrupt_trigger_probe
,
105 .remove
= iio_interrupt_trigger_remove
,
107 .name
= "iio_interrupt_trigger",
111 module_platform_driver(iio_interrupt_trigger_driver
);
113 MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>");
114 MODULE_DESCRIPTION("Interrupt trigger for the iio subsystem");
115 MODULE_LICENSE("GPL v2");