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 int iio_interrupt_trigger_probe(struct platform_device
*pdev
)
30 struct iio_interrupt_trigger_info
*trig_info
;
31 struct iio_trigger
*trig
;
32 unsigned long irqflags
;
33 struct resource
*irq_res
;
36 irq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
41 irqflags
= (irq_res
->flags
& IRQF_TRIGGER_MASK
) | IRQF_SHARED
;
45 trig
= iio_trigger_alloc(NULL
, "irqtrig%d", irq
);
51 trig_info
= kzalloc(sizeof(*trig_info
), GFP_KERNEL
);
54 goto error_free_trigger
;
56 iio_trigger_set_drvdata(trig
, trig_info
);
58 ret
= request_irq(irq
, iio_interrupt_trigger_poll
,
59 irqflags
, trig
->name
, trig
);
62 "request IRQ-%d failed", irq
);
63 goto error_free_trig_info
;
66 ret
= iio_trigger_register(trig
);
68 goto error_release_irq
;
69 platform_set_drvdata(pdev
, trig
);
73 /* First clean up the partly allocated trigger */
79 iio_trigger_free(trig
);
84 static void iio_interrupt_trigger_remove(struct platform_device
*pdev
)
86 struct iio_trigger
*trig
;
87 struct iio_interrupt_trigger_info
*trig_info
;
89 trig
= platform_get_drvdata(pdev
);
90 trig_info
= iio_trigger_get_drvdata(trig
);
91 iio_trigger_unregister(trig
);
92 free_irq(trig_info
->irq
, trig
);
94 iio_trigger_free(trig
);
97 static struct platform_driver iio_interrupt_trigger_driver
= {
98 .probe
= iio_interrupt_trigger_probe
,
99 .remove
= iio_interrupt_trigger_remove
,
101 .name
= "iio_interrupt_trigger",
105 module_platform_driver(iio_interrupt_trigger_driver
);
107 MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>");
108 MODULE_DESCRIPTION("Interrupt trigger for the iio subsystem");
109 MODULE_LICENSE("GPL v2");