2 * Industrial I/O - generic interrupt based trigger support
4 * Copyright (c) 2008-2013 Jonathan Cameron
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/interrupt.h>
15 #include <linux/slab.h>
17 #include <linux/iio/iio.h>
18 #include <linux/iio/trigger.h>
21 struct iio_interrupt_trigger_info
{
25 static irqreturn_t
iio_interrupt_trigger_poll(int irq
, void *private)
27 /* Timestamp not currently provided */
28 iio_trigger_poll(private, 0);
32 static const struct iio_trigger_ops iio_interrupt_trigger_ops
= {
36 static int iio_interrupt_trigger_probe(struct platform_device
*pdev
)
38 struct iio_interrupt_trigger_info
*trig_info
;
39 struct iio_trigger
*trig
;
40 unsigned long irqflags
;
41 struct resource
*irq_res
;
44 irq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
49 irqflags
= (irq_res
->flags
& IRQF_TRIGGER_MASK
) | IRQF_SHARED
;
53 trig
= iio_trigger_alloc("irqtrig%d", irq_res
->start
);
59 trig_info
= kzalloc(sizeof(*trig_info
), GFP_KERNEL
);
62 goto error_put_trigger
;
64 iio_trigger_set_drvdata(trig
, trig_info
);
66 trig
->ops
= &iio_interrupt_trigger_ops
;
67 ret
= request_irq(irq
, iio_interrupt_trigger_poll
,
68 irqflags
, trig
->name
, trig
);
71 "request IRQ-%d failed", irq
);
72 goto error_free_trig_info
;
75 ret
= iio_trigger_register(trig
);
77 goto error_release_irq
;
78 platform_set_drvdata(pdev
, trig
);
82 /* First clean up the partly allocated trigger */
88 iio_trigger_put(trig
);
93 static int iio_interrupt_trigger_remove(struct platform_device
*pdev
)
95 struct iio_trigger
*trig
;
96 struct iio_interrupt_trigger_info
*trig_info
;
98 trig
= platform_get_drvdata(pdev
);
99 trig_info
= iio_trigger_get_drvdata(trig
);
100 iio_trigger_unregister(trig
);
101 free_irq(trig_info
->irq
, trig
);
103 iio_trigger_put(trig
);
108 static struct platform_driver iio_interrupt_trigger_driver
= {
109 .probe
= iio_interrupt_trigger_probe
,
110 .remove
= iio_interrupt_trigger_remove
,
112 .name
= "iio_interrupt_trigger",
113 .owner
= THIS_MODULE
,
117 module_platform_driver(iio_interrupt_trigger_driver
);
119 MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>");
120 MODULE_DESCRIPTION("Interrupt trigger for the iio subsystem");
121 MODULE_LICENSE("GPL v2");