accel/qaic: Add AIC200 support
[drm/drm-misc.git] / drivers / iio / trigger / iio-trig-interrupt.c
blob21c6b6292a721a49032204b7f30aa5c02b76dd26
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Industrial I/O - generic interrupt based trigger support
5 * Copyright (c) 2008-2013 Jonathan Cameron
6 */
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 {
19 unsigned int irq;
22 static irqreturn_t iio_interrupt_trigger_poll(int irq, void *private)
24 iio_trigger_poll(private);
25 return IRQ_HANDLED;
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;
34 int irq, ret = 0;
36 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
38 if (irq_res == NULL)
39 return -ENODEV;
41 irqflags = (irq_res->flags & IRQF_TRIGGER_MASK) | IRQF_SHARED;
43 irq = irq_res->start;
45 trig = iio_trigger_alloc(NULL, "irqtrig%d", irq);
46 if (!trig) {
47 ret = -ENOMEM;
48 goto error_ret;
51 trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL);
52 if (!trig_info) {
53 ret = -ENOMEM;
54 goto error_free_trigger;
56 iio_trigger_set_drvdata(trig, trig_info);
57 trig_info->irq = irq;
58 ret = request_irq(irq, iio_interrupt_trigger_poll,
59 irqflags, trig->name, trig);
60 if (ret) {
61 dev_err(&pdev->dev,
62 "request IRQ-%d failed", irq);
63 goto error_free_trig_info;
66 ret = iio_trigger_register(trig);
67 if (ret)
68 goto error_release_irq;
69 platform_set_drvdata(pdev, trig);
71 return 0;
73 /* First clean up the partly allocated trigger */
74 error_release_irq:
75 free_irq(irq, trig);
76 error_free_trig_info:
77 kfree(trig_info);
78 error_free_trigger:
79 iio_trigger_free(trig);
80 error_ret:
81 return ret;
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);
93 kfree(trig_info);
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,
100 .driver = {
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");